[pLog-svn] r4148 - in plugins/branches/lifetype-1.1: .
templatefilter
oscar at devel.lifetype.net
oscar at devel.lifetype.net
Sat Oct 21 21:42:00 GMT 2006
Author: oscar
Date: 2006-10-21 21:41:59 +0000 (Sat, 21 Oct 2006)
New Revision: 4148
Added:
plugins/branches/lifetype-1.1/templatefilter/
plugins/branches/lifetype-1.1/templatefilter/plugintemplatefilter.class.php
plugins/branches/lifetype-1.1/templatefilter/readme.txt
Log:
added the 'templatefilter' plugin
Added: plugins/branches/lifetype-1.1/templatefilter/plugintemplatefilter.class.php
===================================================================
--- plugins/branches/lifetype-1.1/templatefilter/plugintemplatefilter.class.php 2006-10-21 21:41:32 UTC (rev 4147)
+++ plugins/branches/lifetype-1.1/templatefilter/plugintemplatefilter.class.php 2006-10-21 21:41:59 UTC (rev 4148)
@@ -0,0 +1,251 @@
+<?php
+
+/*
+ * Plugin: Template Filter Prototype (for Life Type 1.1)
+ * Version: 1.0
+ * Author: Pan Ying(http://www.pactofshadow.com/lifetype/~nest)
+ * Contact: panying2000 at gmail.com
+ * Release: 2006.10.4
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ */
+
+ include_once( PLOG_CLASS_PATH."class/plugin/pluginbase.class.php" );
+ //include_once( PLOG_CLASS_PATH."class/template/menu/menu.class.php" );
+
+ //var $arrayPluginTemplateFilterSmartyPostFilter;
+ //var $arrayPluginTemplateFilterSmartyPreFilter;
+
+
+ class PluginTemplateFilter extends PluginBase
+ {
+
+ function PluginTemplateFilter()
+ {
+
+ global $arrayPluginTemplateFilterSmartyPostFilter;
+ global $arrayPluginTemplateFilterSmartyPreFilter;
+
+ $this->PluginBase();
+
+ $this->id = "templatefilter";
+ $this->author = "EagleKing";
+
+ //no menu now ...
+
+ if (!isset($arrayPluginTemplateFilterSmartyPostFilter))
+ $arrayPluginTemplateFilterSmartyPostFilter = array();
+
+ //this is after compile
+
+ //test only , for test the plugin is work or not
+ $arrayPluginTemplateFilterSmartyPostFilter[] = Array(
+ "pattern" => "'</head>'",
+ "replace" => "</head>PluginTemplateFilterSmartyPostFilter Apllyed here",
+ "templatename" => "all",
+ "group" => 0 ,
+ "onlymatch" => false,
+ "disabled" => true
+ );
+
+ //add text before document end , could add Google Analytics here
+ $arrayPluginTemplateFilterSmartyPostFilter[] = Array(
+ "pattern" => "/<\/body>/i",
+ "replace" => "<script src=\"http://www.google-analytics.com/urchin.js\" type=\"text/javascript\">
+</script>
+<script type=\"text/javascript\">
+_uacct = \"type your own code\";
+urchinTracker();
+</script></body>",
+ "templatename" => "footer.template",
+ "group" => 0,
+ "onlymatch" => false ,
+ "disabled" => false
+ );
+
+ if (!isset($arrayPluginTemplateFilterSmartyPreFilter))
+ $arrayPluginTemplateFilterSmartyPreFilter = array();
+
+ //this is before complie
+
+ //replace <!-- \[authImage plugin\] --> to AuthImage
+ $arrayPluginTemplateFilterSmartyPreFilter[] = Array(
+ "pattern" => "'<!-- \[authImage plugin\] -->'",
+ "replace" => "{if \$authimage->isEnabled()}
+<div><label for=\"authImage\">authImage</label><input type=\"text\" name=\"authImage\" id=\"authImage\" value=\"\" /> {\$authimage->show()}</div>
+{/if}",
+ "templatename" => "commentform.template",
+ "group" => 5 ,
+ "onlymatch" => false,
+ "disabled" => false
+ );
+
+ //has install authImage in template ?
+ $arrayPluginTemplateFilterSmartyPreFilter[] = Array(
+ "pattern" => "/authImage/i",
+ "replace" => "",
+ "templatename" => "commentform.template",
+ "group" => 5,
+ "onlymatch" => true,
+ "disabled" => false
+ );
+
+ //try to find a correct postion to put AuthImage anyway
+ $arrayPluginTemplateFilterSmartyPreFilter[] = Array(
+ "pattern" => "/<\/form>/i",
+ "replace" => "{if \$authimage->isEnabled()}
+<div><label for=\"authImage\">authImage</label><input type=\"text\" name=\"authImage\" id=\"authImage\" value=\"\" /> {\$authimage->show()}</div>
+{/if}
+</form>",
+ "templatename" => "commentform.template",
+ "group" => 5 ,
+ "onlymatch" => false,
+ "disabled" => false
+ );
+
+ }
+ }
+
+ function PluginTemplateFilterSmartyPostFilter($tpl_output, &$smarty)
+ {
+ global $arrayPluginTemplateFilterSmartyPostFilter;
+
+ //echo "PluginTemplateFilterSmartyPostFilter call here".$smarty->_current_file;
+
+ if (!is_array($arrayPluginTemplateFilterSmartyPostFilter))
+ return $tpl_output;
+
+ $patharray = explode ('/', $smarty->_current_file);
+ if (count($patharray)<=0)
+ $templatename = "";
+ else
+ $templatename = $patharray[count($patharray)-1];
+
+ if (count($patharray)<=1)
+ $templatedir = "";
+ else
+ $templatedir = $patharray[count($patharray)-2];
+
+ if ($templatedir == "wizard" ||
+ $templatedir == "admin" ||
+ $templatedir == "rss")
+ return $tpl_output;
+
+ $proccessedgroup = Array();
+
+ foreach ($arrayPluginTemplateFilterSmartyPostFilter as $filter)
+ {
+
+ //var_dump($filter);
+
+ if ( $filter["group"] != 0
+ && isset($proccessedgroup[$filter["group"]])
+ && $proccessedgroup[$filter["group"]] == "1")
+ continue;
+
+ if ($filter["disabled"])
+ continue;
+
+ if ($filter["templatename"] == "all" ||
+ $filter["templatename"] == $templatename)
+ {
+
+ if ($filter["onlymatch"])
+ {
+ if (preg_match($filter["pattern"],$tpl_output) >0)
+ $proccessedgroup[$filter["group"]] = "1";
+ }
+ else
+ {
+ $tpl_output_after =
+ preg_replace($filter["pattern"],
+ $filter["replace"], $tpl_output);
+
+ if ($filter["group"] == 0 || $tpl_output_after != $tpl_output)
+ {
+
+ $tpl_output = $tpl_output_after;
+ $proccessedgroup[$filter["group"]] = "1";
+ }
+ }
+
+ }
+ }
+
+
+ return $tpl_output;
+ }
+
+ function PluginTemplateFilterSmartyPreFilter($tpl_output, &$smarty)
+ {
+ global $arrayPluginTemplateFilterSmartyPreFilter;
+
+ //echo "PluginTemplateFilterSmartyPreFilter call here".$smarty->_current_file;
+
+ if (!is_array($arrayPluginTemplateFilterSmartyPreFilter))
+ return $tpl_output;
+
+ $patharray = explode ('/', $smarty->_current_file);
+ if (count($patharray)<=0)
+ $templatename = "";
+ else
+ $templatename = $patharray[count($patharray)-1];
+
+ if (count($patharray)<=1)
+ $templatedir = "";
+ else
+ $templatedir = $patharray[count($patharray)-2];
+
+ if ($templatedir == "wizard" ||
+ $templatedir == "admin" ||
+ $templatedir == "rss")
+ return $tpl_output;
+
+ $proccessedgroup = Array();
+
+ foreach ($arrayPluginTemplateFilterSmartyPreFilter as $filter)
+ {
+
+ //var_dump($filter);
+
+ if ( $filter["group"] != 0
+ && isset($proccessedgroup[$filter["group"]])
+ && $proccessedgroup[$filter["group"]] == "1")
+ continue;
+
+ if ($filter["disabled"])
+ continue;
+
+ if ($filter["templatename"] == "all" ||
+ $filter["templatename"] == $templatename)
+ {
+
+ if ($filter["onlymatch"])
+ {
+ if (preg_match($filter["pattern"],$tpl_output) >0)
+ $proccessedgroup[$filter["group"]] = "1";
+ }
+ else
+ {
+ $tpl_output_after =
+ preg_replace($filter["pattern"],
+ $filter["replace"], $tpl_output);
+
+ if ($filter["group"] == 0 || $tpl_output_after != $tpl_output)
+ {
+
+ $tpl_output = $tpl_output_after;
+ $proccessedgroup[$filter["group"]] = "1";
+ }
+ }
+
+ }
+ }
+
+
+
+ return $tpl_output;
+ }
+
+?>
\ No newline at end of file
Added: plugins/branches/lifetype-1.1/templatefilter/readme.txt
===================================================================
--- plugins/branches/lifetype-1.1/templatefilter/readme.txt 2006-10-21 21:41:32 UTC (rev 4147)
+++ plugins/branches/lifetype-1.1/templatefilter/readme.txt 2006-10-21 21:41:59 UTC (rev 4148)
@@ -0,0 +1,17 @@
+Plugin: Template Filter(Prototype Version)
+Author: Pan Ying(panying2000 at gmail.com)
+Version: 1.0
+Release Date: 2006/10/04
+Chinese Note: http://www.pactofshadow.com/lifetype/2/articleperma/15.html
+
+
+This plugin provide a globe method to insernt code in every template before their render.
+
+Setup:
+1.Insernt these code inside <lifetype>\class\template\template.class.php after line 95:
+
+include_once( PLOG_CLASS_PATH."plugins/templatefilter/plugintemplatefilter.class.php" );
+Smarty::register_postfilter('PluginTemplateFilterSmartyPostFilter');
+Smarty::register_prefilter('PluginTemplateFilterSmartyPreFilter');
+
+2.Copy the file in the zip to <lifetype>\plugins\templatefilter\
\ No newline at end of file
More information about the pLog-svn
mailing list