]> git.mjollnir.org Git - s9y.git/commitdiff
Add experimental XML engine support
authorgarvinhicking <garvinhicking>
Tue, 20 Jun 2006 07:44:43 +0000 (07:44 +0000)
committergarvinhicking <garvinhicking>
Tue, 20 Jun 2006 07:44:43 +0000 (07:44 +0000)
docs/NEWS
include/plugin_internal.inc.php
include/template_api.inc.php
templates/default-xml/index.tpl [new file with mode: 0644]
templates/default-xml/info.txt [new file with mode: 0644]
templates/default-xml/preview.png [new file with mode: 0644]
templates/default-xml/template.inc.php [new file with mode: 0644]

index 5182ff65d78ae0cc74006ad926e94dbec9484a69..8d23c07c5d990e913da7680692027f18d7377d30 100644 (file)
--- a/docs/NEWS
+++ b/docs/NEWS
@@ -3,6 +3,9 @@
 Version 1.1-alpha7()
 ------------------------------------------------------------------------
 
+    * Added experimental XML-engine, for XSLT templating support
+      (garvinhicking)
+
     * Added experimental PHP-engine templating support, bypassing
       Smarty. Work in progress, mostly proof-of-concept. Might
       be changed completely. Read instructions in the 
index 79fbf19980cdf1a6cf0cce5c4804abfaf809e295..aaa2b5e23a55b4378791042a8f1277ccbdd8c614 100644 (file)
@@ -1410,6 +1410,9 @@ class serendipity_categories_plugin extends serendipity_plugin {
         $is_form = serendipity_db_bool($this->get_config('allow_select'));
         if ($which_category === "login") {
             $which_category = (int)$serendipity['authorid'];
+            if ($which_category === 0) {
+                $which_category = -1; // Set to -1 for anonymous authors to get a proper match.
+            }
         }
 
         $categories = serendipity_fetchCategories(empty($which_category) ? 'all' : $which_category, '', $sort);
index 50ab843fb2c4448efb791e472e67c1d79a2c9cef..f9983b573ee9a457203b8ba86ffcd33e3db305e2 100644 (file)
@@ -175,3 +175,87 @@ class serendipity_smarty_emulator {
     }
 }
 
+/*
+ *@author Garvin Hicking
+ *@state EXPERIMENTAL
+ *
+ * XML Engine
+ */
+
+class serendipity_smarty_emulator_xml extends serendipity_smarty_emulator {
+    /**
+     * Parses a template file into another.
+     *
+     * @access public
+     * @return null
+     */
+    function fetch() {
+        return true;
+    }
+
+    /**
+     * Outputs a smarty template.
+     *
+     * @access public
+     * @return null
+     */
+    function display() {
+        echo "</serendipity>\n";
+        return true;
+    }
+
+    function __construct() {
+        header('Content-Type: text/xml; charset=' . LANG_CHARSET);
+        echo '<?xml version="1.0" encoding="' . LANG_CHARSET . '" ?>' . "\n";
+        /*
+        echo '<?xml-stylesheet href="' . serendipity_getTemplateFile('xml.css') . '" type="text/css" ?>' . "\n";
+        */
+        echo "<serendipity>\n";
+        ob_end_flush(); // This ends the started ob from index.php!
+    }
+    
+    function serendipity_smarty_emulator_xml() {
+        $this->__construct();
+    }
+
+    /**
+     * Assign one or multiple template variable
+     * @TODO: Why can't this function accept references. This sucks.
+     *
+     * @param   mixed       Either a variable name, or an array of variables
+     * @param   mixed       Either null or the variable content.
+     * @access public
+     * @return null
+     */
+    function assign($tpl_var, $value = null, $level = 0) {
+        if (is_array($tpl_var)) {
+            foreach ($tpl_var as $key => $val) {
+                if ($key != '') {
+                    $this->createXML($level, $key, $val);
+                }
+            }
+        } else {
+            $this->createXML($level, $tpl_var, $value);
+        }
+
+        return true;
+    }
+    
+    function createXML(&$level, &$key, &$val) {
+        if (is_numeric($key)) {
+            $openkey  = 'item index="' . $key . '"';
+            $closekey = 'item';
+        } else {
+            $openkey = $closekey = $key;
+        }
+
+        if (is_array($val)) {
+            echo str_repeat("\t", $level) . "<$openkey>\n";
+            $this->assign($val, null, $level + 1);
+            echo str_repeat("\t", $level) . "</$closekey>\n";
+        } else {
+            echo str_repeat("\t", $level) . "<$openkey>" . htmlspecialchars($val) . "</$closekey>\n";
+        }
+    }
+}
+
diff --git a/templates/default-xml/index.tpl b/templates/default-xml/index.tpl
new file mode 100644 (file)
index 0000000..2922023
--- /dev/null
@@ -0,0 +1 @@
+<!-- RAW XML OUTPUT! -->
diff --git a/templates/default-xml/info.txt b/templates/default-xml/info.txt
new file mode 100644 (file)
index 0000000..21b03d8
--- /dev/null
@@ -0,0 +1,4 @@
+Name: XML Engine. EXPERIMENTAL. (Developers only)
+Author: Garvin Hicking
+Date: 06.06.2006
+Require Serendipity: 1.1
diff --git a/templates/default-xml/preview.png b/templates/default-xml/preview.png
new file mode 100644 (file)
index 0000000..4bad5ac
Binary files /dev/null and b/templates/default-xml/preview.png differ
diff --git a/templates/default-xml/template.inc.php b/templates/default-xml/template.inc.php
new file mode 100644 (file)
index 0000000..264cf99
--- /dev/null
@@ -0,0 +1,7 @@
+<?php 
+// THIS FILE IS WORK-IN-PROGRESS. Mostly proof-of-code.
+// Proceed at your own risk. Read the "template_api.inc.php
+// instructions.
+include_once S9Y_INCLUDE_PATH . 'include/template_api.inc.php'; 
+$GLOBALS['template'] = new serendipity_smarty_emulator_xml(); 
+$GLOBALS['serendipity']['smarty'] =& $GLOBALS['template'];