[pLog-svn] r1913 - plugins/trunk/plogeshi
oscar at devel.plogworld.net
oscar at devel.plogworld.net
Fri Apr 29 06:57:53 GMT 2005
Author: oscar
Date: 2005-04-29 06:57:52 +0000 (Fri, 29 Apr 2005)
New Revision: 1913
Modified:
plugins/trunk/plogeshi/pluginplogeshi.class.php
Log:
fixed issue 453 (http://bugs.plogworld.net/view.php?id=453)
Modified: plugins/trunk/plogeshi/pluginplogeshi.class.php
===================================================================
--- plugins/trunk/plogeshi/pluginplogeshi.class.php 2005-04-28 14:39:00 UTC (rev 1912)
+++ plugins/trunk/plogeshi/pluginplogeshi.class.php 2005-04-29 06:57:52 UTC (rev 1913)
@@ -1,109 +1,131 @@
<?php
- include_once( PLOG_CLASS_PATH."class/plugin/pluginbase.class.php" );
- include_once( PLOG_CLASS_PATH."plugins/plogeshi/class/plogeshi/plogeshi.class.php" );
+ include_once( PLOG_CLASS_PATH."class/plugin/pluginbase.class.php" );
+ include_once( PLOG_CLASS_PATH."plugins/plogeshi/class/plogeshi/plogeshi.class.php" );
- define( "PLOGESHI_PATH", PLOG_CLASS_PATH . "plugins/plogeshi/" );
- define( "PLOGESHI_GESHI_PATH", PLOGESHI_PATH ."inc/" );
-
- class PluginPloGeSHi extends PluginBase
- {
- var $_pluginEnabled;
- var $_ploGeshi;
+ define( "PLOGESHI_PATH", PLOG_CLASS_PATH . "plugins/plogeshi/" );
+ define( "PLOGESHI_GESHI_PATH", PLOGESHI_PATH ."inc/" );
+
+ class PluginPloGeSHi extends PluginBase
+ {
+ var $_pluginEnabled;
+ var $_ploGeshi;
- function PluginPloGeSHi()
- {
- // ---
- // set some information
- // ---
- $this->id = "plogeshi";
- $this->author = "Rodrigo Pérez (bilson)";
- $this->desc = "This plugin allows to color bits of code using GeSHi. Please use the following syntax
- anywhere in your posts:<br/><br/>
- <code php><br/>
- // place here your PHP code here<br/>
- ...<br/>
- </code>
- <br/><br/>
- Other common formats supported by <a href=\"http://qbnz.com/highlighter/\">GeSHi</a>
- include: <b>Actionscript, ASM, ASP, Bash, C,
- C#, C++, CSS, Delphi, HTML, Java, Javascript, Lisp,
- Objective C,
- Pascal, Perl, PHP, Python, Smarty, SQL, VB.NET, Visual BASIC, XML</b>.<br/><br/>
- Simply enclose your code within <code <i>code-identifier</i>>...</code>
- and use any of the languages above as the value for <i>code-identifier</i>.";
-
- $this->locales = Array( 'es_ES', 'en_UK' );
-
- $this->_ploGeshi = new PloGeSHi();
-
-
- $this->init();
- }
+ function PluginPloGeSHi()
+ {
+ // ---
+ // set some information
+ // ---
+ $this->id = "plogeshi";
+ $this->author = "Rodrigo Pérez (bilson)";
+ $this->desc = "This plugin allows to color bits of code using GeSHi. Please use the following syntax
+ anywhere in your posts:<br/><br/>
+ <code php><br/>
+ // place here your PHP code here<br/>
+ ...<br/>
+ </code>
+ <br/><br/>
+ Other common formats supported by <a href=\"http://qbnz.com/highlighter/\">GeSHi</a>
+ include: <b>Actionscript, ASM, ASP, Bash, C,
+ C#, C++, CSS, Delphi, HTML, Java, Javascript, Lisp,
+ Objective C,
+ Pascal, Perl, PHP, Python, Smarty, SQL, VB.NET, Visual BASIC, XML</b>.<br/><br/>
+ Simply enclose your code within <code <i>code-identifier</i>>...</code>
+ and use any of the languages above as the value for <i>code-identifier</i>.";
+
+ $this->locales = Array( 'es_ES', 'en_UK' );
+
+ $this->_ploGeshi = new PloGeSHi();
+
+
+ $this->init();
+ }
- function init()
- {
- // ---
- // register actions for this plugin plus an option in the menu
- // ---
- $this->registerAdminAction( "PloGeSHiConfig", "PluginPloGeSHiConfigAction" );
- $this->registerAdminAction( "updatePloGeSHiConfig", "PluginPloGeSHiUpdateConfigAction" );
-
- // ---
- // register actions for this plugin plus an option in the menu
- // ---
- $menu =& Menu::getMenu();
- $this->addMenuEntry( "/menu/Manage/managePosts", "PloGeSHi", "admin.php?op=PloGeSHiConfig", "" );
-
- // ---
- // register the event we are going to need
- $this->registerNotification( EVENT_TEXT_FILTER );
- }
+ function init()
+ {
+ // ---
+ // register actions for this plugin plus an option in the menu
+ // ---
+ $this->registerAdminAction( "PloGeSHiConfig", "PluginPloGeSHiConfigAction" );
+ $this->registerAdminAction( "updatePloGeSHiConfig", "PluginPloGeSHiUpdateConfigAction" );
+
+ // ---
+ // register actions for this plugin plus an option in the menu
+ // ---
+ $menu =& Menu::getMenu();
+ $this->addMenuEntry( "/menu/Manage/managePosts", "PloGeSHi", "admin.php?op=PloGeSHiConfig", "" );
+
+ // ---
+ // register the event we are going to need
+ $this->registerNotification( EVENT_TEXT_FILTER );
+ }
- function register()
- {
- $blogSettings = $this->blogInfo->getSettings();
- $this->_pluginEnabled = $blogSettings->getValue( "plugin_plogeshi_enabled" );
- }
+ function register()
+ {
+ $blogSettings = $this->blogInfo->getSettings();
+ $this->_pluginEnabled = $blogSettings->getValue( "plugin_plogeshi_enabled" );
+ }
- function isEnabled()
- {
- return $this->_pluginEnabled;
- }
+ function isEnabled()
+ {
+ return $this->_pluginEnabled;
+ }
-
-
- function _colorText( $post )
- {
- // modify the text...
- return $this->_ploGeshi->colorText( $post );
- }
-
- /**
- * Receives and processes events
- *
- * @param eventType
- * @param params
- */
- function process( $eventType, $params )
- {
- // if the plugin is diabled, return
- $settings = $this->blogInfo->getSettings();
- if( !$settings->getValue( "plugin_plogeshi_enabled" ))
- return true;
+
+
+ function _colorText( $post )
+ {
+ // modify the text...
+ return $this->_ploGeshi->colorText( $post );
+ }
+
+ function FShouldColorText( $post )
+ {
+ // This is currently only checking to see if this post has some
+ // visible text
+ //
+ // This logic matches the logic in Article::hasExtendedText()
+
+ // This code really should be looking at the text for the
+ // <code > tag
+
+ $postText = trim($post);
+ if($postText == "<br />" || $postText == "<br/>" ||
+ $postText == "<p/>" || $postText == "<p />")
+ return false;
+ else
+ return( strlen($postText) > 0 );
+ }
+
+ /**
+ * Receives and processes events
+ *
+ * @param eventType
+ * @param params
+ */
+ function process( $eventType, $params )
+ {
+ // if the plugin is diabled, return
+ $settings = $this->blogInfo->getSettings();
+ if( !$settings->getValue( "plugin_plogeshi_enabled" ))
+ return true;
- // prevent other events
- if( $eventType != EVENT_TEXT_FILTER ) {
- throw( new Exception( "PloGeshi only receive EVENT_TEXT_RENDER events" ));
- die();
- }
+ // prevent other events
+ if( $eventType != EVENT_TEXT_FILTER ) {
+ throw( new Exception( "PloGeshi only receive EVENT_TEXT_RENDER events" ));
+ die();
+ }
- $rg =& $this->blogInfo->getBlogRequestGenerator();
- $baseUrl = $rg->getBaseUrl();
- $cssUrl = $baseUrl."/plugins/plogeshi/styles/plogeshi.css";
-
- $css = '<link rel="stylesheet" type="text/css" href="' . $cssUrl . '" />';
- $params[ "text" ] = $css . $this->_colorText( $params[ "text" ] );
- }
- }
+ if( $this->FShouldColorText( $params[ "text" ] ) )
+ {
+ // Only bother modifying the text if there is a potential that there is a <code> tag
+ $rg =& $this->blogInfo->getBlogRequestGenerator();
+ $baseUrl = $rg->getBaseUrl();
+ $cssUrl = $baseUrl."/plugins/plogeshi/styles/plogeshi.css";
+
+ $css = '<link rel="stylesheet" type="text/css" href="' . $cssUrl . '" />';
+ $params[ "text" ] = $css . $this->_colorText( $params[ "text" ] );
+ }
+ }
+ }
?>
\ No newline at end of file
More information about the pLog-svn
mailing list