Pārlūkot izejas kodu

basic theme structure

Billy Barrow 2 gadi atpakaļ
vecāks
revīzija
264aadaab8

+ 1 - 0
config.php

@@ -8,5 +8,6 @@ define("PUBLICATION_DIR", "ppubs");
 define("PUBLICATION_NAME", "Post");
 define("DATE_FORMAT", "l d F Y, H:i");
 define("USE_PPIX", false);
+define("THEME", "classic");
 
 ?>

+ 18 - 12
index.php

@@ -1,6 +1,7 @@
 <?php
 include("config.php");
 include("ppub.php");
+include("theme.php");
 
 define("INDEX_TYPE_MAIN", 0);
 define("INDEX_TYPE_TAG", 1);
@@ -77,13 +78,20 @@ if($asset == '' and $_SERVER['REQUEST_URI'][-1] != '/') {
 
 
 if($file == "" or $file == "/" or $file == "feed.rss") {
+    $start = "index_start";
+    $no_content = "index_no_content";
+    $listing = "index_listing";
+    $end = "index_end";
+
     if($file == "feed.rss") {
         header("content-type: application/rss+xml");
-        include("rss_template.php");
+        $start = "rss_start";
+        $listing = "rss_listing";
+        $no_content = "rss_no_content";
+        $end = "rss_end";
     }
     else {
         header("content-type: text/html");
-        include("index_template.php");
     }
 
     $index_type = INDEX_TYPE_MAIN;
@@ -103,20 +111,20 @@ if($file == "" or $file == "/" or $file == "feed.rss") {
         $index_arg = get_tag_list();
     }
     
-    index_start($index_type, $index_arg);
+    $start($index_type, $index_arg);
     $list = get_ppub_file_list();
     
     foreach ($list as $file) {
         $ppub = new Ppub();
         $ppub->read_file(PUBLICATION_DIR . "/".$file);
-        index_listing($ppub, $file);
+        $listing($ppub, $file);
     }
 
     if(count($list) == 0) {
-        index_no_content($index_type, $index_arg);
+        $no_content($index_type, $index_arg);
     }
 
-    index_end();
+    $end();
     exit();
 }
 
@@ -160,7 +168,6 @@ header("Cache-Control: public, max-age=604800");
 
 if(strpos($accepts, "text/html") !== false && $asset->mimetype == "text/markdown" && !isset($_GET["raw"])) {
     header("content-type: text/html");
-    include("content_template.php");
     include("Parsedown.php");
     $pd = new Parsedown();
     content_start($ppub, $file_name);
@@ -175,16 +182,15 @@ else if(strpos($accepts, "text/html") !== false && $asset->mimetype == "applicat
     $video = new Ppvm();
     $video->from_string($ppub->read_asset($asset));
     
+    include("video_player.php");
     if(isset($_GET["embed"])) {
-        include("video_player.php");
         ppvm_player($ppub, $file_name, $video);
     }
     else {
-        include("video_template.php");
-        content_start($ppub, $file_name, $video);
+        video_start($ppub, $file_name, $video);
         $description = $ppub->asset_index[$video->metadata["description"]];
-        content_html($pd->text($ppub->read_asset($description)));
-        content_end($ppub);
+        video_html($pd->text($ppub->read_asset($description)));
+        video_end($ppub);
     }
 }
 else {

+ 110 - 0
theme.php

@@ -0,0 +1,110 @@
+<?php
+
+include("themes/_base/theme.php");
+include("themes/" . THEME . "/theme.php");
+
+function index_start($index_type, $arg) {
+    $fun = THEME . "_index_start";
+    if(!function_exists($fun)) {
+        return base_index_start($index_type, $arg);
+    }
+    return $fun($index_type, $arg);
+}
+
+function index_no_content($index_type, $arg) {
+    $fun = THEME . "_index_no_content";
+    if(!function_exists($fun)) {
+        return base_index_no_content($index_type, $arg);
+    }
+    return $fun($index_type, $arg);
+}
+
+function index_listing($ppub, $url) {
+    $fun = THEME . "_index_listing";
+    if(!function_exists($fun)) {
+        return base_index_listing($ppub, $url);
+    }
+    return $fun($ppub, $url);
+}
+
+function index_end() {
+    $fun = THEME . "_index_end";
+    if(!function_exists($fun)) {
+        return base_index_end();
+    }
+    return $fun();
+}
+
+function rss_start($index_type, $arg) {
+    $fun = THEME . "_rss_start";
+    if(!function_exists($fun)) {
+        return base_rss_start($index_type, $arg);
+    }
+    return $fun($index_type, $arg);
+}
+
+function rss_listing($ppub, $url) {
+    $fun = THEME . "_rss_listing";
+    if(!function_exists($fun)) {
+        return base_rss_listing($ppub, $url);
+    }
+    return $fun($ppub, $url);
+}
+
+function rss_end() {
+    $fun = THEME . "_rss_end";
+    if(!function_exists($fun)) {
+        return base_rss_end();
+    }
+    return $fun();
+}
+
+function content_start($ppub, $path) {
+    $fun = THEME . "_content_start";
+    if(!function_exists($fun)) {
+        return base_content_start($ppub, $path);
+    }
+    return $fun($ppub, $path);
+}
+
+function content_html($content) {
+    $fun = THEME . "_content_html";
+    if(!function_exists($fun)) {
+        return base_content_html($content);
+    }
+    return $fun($content);
+}
+
+function content_end($ppub, $path) {
+    $fun = THEME . "_content_end";
+    if(!function_exists($fun)) {
+        return base_content_end($ppub, $path);
+    }
+    return $fun($ppub, $path);
+}
+
+function video_start($ppub, $path, $video) {
+    $fun = THEME . "_video_start";
+    if(!function_exists($fun)) {
+        return base_video_start($ppub, $path, $video);
+    }
+    return $fun($ppub, $path);
+}
+
+function video_html($content) {
+    $fun = THEME . "_video_html";
+    if(!function_exists($fun)) {
+        return base_video_html($content);
+    }
+    return $fun($content);
+}
+
+function video_end($ppub, $path) {
+    $fun = THEME . "_video_end";
+    if(!function_exists($fun)) {
+        return base_video_end($ppub, $path);
+    }
+    return $fun($ppub, $path);
+}
+
+?>

+ 3 - 3
content_template.php → themes/_base/content_template.php

@@ -1,6 +1,6 @@
 <?php
 
-function content_start($ppub, $path) {
+function base_content_start($ppub, $path) {
     $metadata = $ppub->metadata;
     ?>
 
@@ -26,11 +26,11 @@ function content_start($ppub, $path) {
     <?php
 }
 
-function content_html($content) {
+function base_content_html($content) {
     echo $content;
 }
 
-function content_end($ppub) {
+function base_content_end($ppub) {
     ?>
     <footer>
         <hr>

+ 4 - 4
index_template.php → themes/_base/index_template.php

@@ -1,6 +1,6 @@
 <?php
 
-function index_start($index_type, $arg) {
+function base_index_start($index_type, $arg) {
 
     ?>
 
@@ -107,13 +107,13 @@ function index_start($index_type, $arg) {
     <?php
 }
 
-function index_no_content($index_type, $arg) {
+function base_index_no_content($index_type, $arg) {
     if($index_type == INDEX_TYPE_SEARCH) {
         echo("<p>Nothing found for search query &quot;" . htmlentities($arg) . "&quot.</p>");
     }
 }
 
-function index_listing($ppub, $url) {
+function base_index_listing($ppub, $url) {
     ?>
             <dt><a href="<?php echo($url);?>"><?php echo(htmlentities($ppub->metadata["title"]));?></a></dt>
             <dd>
@@ -127,7 +127,7 @@ function index_listing($ppub, $url) {
     <?php
 }
 
-function index_end() {
+function base_index_end() {
     ?>
     </dl>
     <footer>

+ 3 - 3
rss_template.php → themes/_base/rss_template.php

@@ -1,6 +1,6 @@
 <?php
 
-function index_start($type, $arg) {
+function base_rss_start($type, $arg) {
 ?>
 <?xml version='1.0' encoding='UTF-8'?>
 <rss version='2.0'>
@@ -14,7 +14,7 @@ function index_start($type, $arg) {
 <?php
 }
 
-function index_listing($ppub, $url) {
+function base_rss_listing($ppub, $url) {
 ?>
         <item>
             <title><?php echo(htmlentities($ppub->metadata["title"]));?></title>
@@ -27,7 +27,7 @@ function index_listing($ppub, $url) {
 <?php
 }
 
-function index_end() {
+function base_rss_end() {
 ?>
     </channel>
 </rss>

+ 6 - 0
themes/_base/theme.php

@@ -0,0 +1,6 @@
+<?php
+include("index_template.php");
+include("rss_template.php");
+include("content_template.php");
+include("video_template.php");
+?>

+ 4 - 5
video_template.php → themes/_base/video_template.php

@@ -1,6 +1,6 @@
 <?php
 
-function content_start($ppub, $path, $video) {
+function base_video_start($ppub, $path, $video) {
     $metadata = $ppub->metadata;
     ?>
 
@@ -38,16 +38,15 @@ function content_start($ppub, $path, $video) {
     </header>
 
     <?php
-
-    include("video_player.php");
+    
     generate_embed($path, $video);
 }
 
-function content_html($content) {
+function base_video_html($content) {
     echo $content;
 }
 
-function content_end($ppub) {
+function base_video_end($ppub) {
     ?>
     <footer>
         <hr>

+ 5 - 0
themes/classic/theme.php

@@ -0,0 +1,5 @@
+<?php
+
+# Intentially blank, uses all base functions
+
+?>