[pLog-svn] r5274 - plugins/branches/lifetype-1.2/cssnaked
reto at devel.lifetype.net
reto at devel.lifetype.net
Wed Apr 4 17:12:32 EDT 2007
Author: reto
Date: 2007-04-04 17:12:32 -0400 (Wed, 04 Apr 2007)
New Revision: 5274
Modified:
plugins/branches/lifetype-1.2/cssnaked/plugincssnaked.class.php
Log:
Oscar, thank you so much for adding this wonderful logging framework. I will never ever again use echo statements to debug. ever. ;-)
oh, and the ouput filter works great, I should just have taken more attentions to what I get as parameters to the process class. Most of the plugins do getValue('config') stuff, but I guess it would be better to do this in the process method, right? register should only be used to check if we need to 'install' something...
Modified: plugins/branches/lifetype-1.2/cssnaked/plugincssnaked.class.php
===================================================================
--- plugins/branches/lifetype-1.2/cssnaked/plugincssnaked.class.php 2007-04-04 16:50:13 UTC (rev 5273)
+++ plugins/branches/lifetype-1.2/cssnaked/plugincssnaked.class.php 2007-04-04 21:12:32 UTC (rev 5274)
@@ -1,7 +1,8 @@
<?php
lt_include( PLOG_CLASS_PATH."class/plugin/pluginbase.class.php" );
-
+ //lt_include( PLOG_CLASS_PATH."class/logger/loggermanager.class.php" );
+
class PluginCssNaked extends PluginBase
{
@@ -10,12 +11,15 @@
var $_endDate;
var $_timeFrame = 48;
var $_addNotice;
- var $_notice;
+ var $_l;
function PluginCssNaked ( $source = '' )
{
$this->PluginBase( $source );
+ // only used for logging
+ //$this->_l =& LoggerManager::getLogger( "naked" );
+
$this->id = "cssnaked";
$this->version = "20070403";
$this->author = "Reto Hugi";
@@ -45,20 +49,7 @@
function register()
{
- $config =& Config::getConfig();
-
- $blogSettings = $this->blogInfo->getSettings();
- $this->_pluginEnabled = $blogSettings->getValue( "plugin_cssnaked_enabled" );
- $this->_startDate = $blogSettings->getValue( "plugin_cssnaked_startDate" );
- $this->_endDate = $blogSettings->getValue( "plugin_cssnaked_endDate" );
- $this->_addNotice = $blogSettings->getValue( "plugin_cssnaked_addNotice" );
-
- //get the notice from the locale
- $locale =& $this->blogInfo->getLocale();
- $this->_notice = $locale->tr('cssnaked_notice');
-
- //TODO
- //$this->_timeFrame = $blogSettings->getValue( "plugin_cssnaked_timeFrame" );
+ //$this->_l->debug( "----- START REGISTER() ---------" );
}
function getPluginConfigurationKeys()
@@ -70,28 +61,56 @@
function process( $event, $params )
{
-
+ //$this->_l->debug( "----- START PROCESS() ---------" );
+ //$this->_l->debug( $params['blogInfo'] );
+ //$this->_l->debug( $params['userInfo'] );
+
+ // load the settings needed
+ $blogSettings =& $params['blogInfo']->getSettings();
+ $this->_pluginEnabled = $blogSettings->getValue( "plugin_cssnaked_enabled" );
+ $this->_startDate = $blogSettings->getValue( "plugin_cssnaked_startDate" );
+ $this->_endDate = $blogSettings->getValue( "plugin_cssnaked_endDate" );
+ $this->_addNotice = $blogSettings->getValue( "plugin_cssnaked_addNotice" );
+
+ //TODO
+ //$this->_timeFrame = $blogSettings->getValue( "plugin_cssnaked_timeFrame" );
+
+ /*
+ $this->_l->debug( "Enabled: ".$this->_pluginEnabled
+ ."\nStart Date: ".$this->_startDate
+ ."\nEnd Date: ".$this->_endDate
+ ."\nadd Notice: ".$this->_addNotice
+ );
+ */
+
// check if the plugin is enabled and do nothing if not.
if (!$this->_pluginEnabled) { return true; }
-
+ //$this->_l->debug( "[info] Plugin Enabled" );
+
// check if today is a naked day ;)
if ( !$this->isNakedDay() ) { return true; }
-
+ //$this->_l->debug( "[info] is Naked Day" );
+
// all checks passed, so let's get naked!
$content = $params["content"];
- $content = $this->_strip($content);
+ $content =& $this->_strip($content);
// check if we want to add a notice at the top
if ($this->_addNotice) {
- $content =& $this->_addNotice($content);
+
+ // get the notice we want to display from the locale
+ $locale =& $this->blogInfo->getLocale();
+ $content =& $this->_addNotice( $content, $locale->tr('cssnaked_notice') );
}
-
+
// write the naked content back to send the content to the browser
$params["content"] = $content;
}
// parts of this method where inspired by http://www.ajalapus.com
function isNakedDay() {
+
+ //$this->_l->debug( "----- START isNakedDay() ---------" );
if ($this->_timeFrame === 48) {
@@ -102,11 +121,12 @@
}
else {
//TODO: other time frame than 48h and taking the blogs time offset into account
-
}
$ntime = time(); // Time now
-echo $stime.'-'.$etime.'-'.$ntime;
+
+ //$this->_l->debug( "Start Time:$stime, End Time:$etime, Now:$ntime" );
+
if ($ntime >= $stime && $ntime <= $etime) {
return true;
}
@@ -117,7 +137,7 @@
// parts of this method where inspired by http://www.ajalapus.com
function _strip(&$content) {
-
+
$pattern = array(
'/<\?xml-stylesheet.*\?>/sU', // x(ht)ml stylesheet directive
'/<link.*rel\s*=\s*["\'].*stylesheet.*>/sU', // (x)html stylesheet reference
@@ -130,11 +150,11 @@
}
- function _addNotice(&$content) {
-
+ function _addNotice(&$content, &$notice) {
+
$pattern = '/<body(.*)>/U';
- return preg_replace($pattern, $this->_notice, $content);
+ return preg_replace($pattern, $notice, $content);
}
}
?>
More information about the pLog-svn
mailing list