[geeklog-cvs] geeklog-1.3/system lib-plugins.php,1.34,1.35

blaine at iowaoutdoors.org blaine at iowaoutdoors.org
Sun Sep 5 20:49:13 EDT 2004


Update of /var/cvs/geeklog-1.3/system
In directory www:/tmp/cvs-serv21020/system

Modified Files:
	lib-plugins.php 
Log Message:
Updated new AutoTags Plugin Function to simplify the required plugin function requried. The Plugin now builds an array of all autotags in the content for the supported plugins that have the autotag function. Also it includes the logic to parse the story autolink tags.

Added two new language variables 1: used to format the autolink and 2: Error if missing tag or possible bad formatted autotag detected.

Index: lib-plugins.php
===================================================================
RCS file: /var/cvs/geeklog-1.3/system/lib-plugins.php,v
retrieving revision 1.34
retrieving revision 1.35
diff -C2 -d -r1.34 -r1.35
*** lib-plugins.php	3 Sep 2004 19:59:56 -0000	1.34
--- lib-plugins.php	6 Sep 2004 00:49:11 -0000	1.35
***************
*** 801,808 ****
  function PLG_templateSetVars ($templatename, &$template)
  {
!     global $_TABLES;
  
!     $query = DB_query("SELECT pi_name FROM {$_TABLES['plugins']} WHERE pi_enabled = 1");
!     while (list ($pi_name) = DB_fetchArray($query)) {
          $function = 'plugin_templatesetvars_' . $pi_name;
          if (function_exists($function)) {
--- 801,807 ----
  function PLG_templateSetVars ($templatename, &$template)
  {
!     global $_TABLES, $_PLUGINS;
  
!     foreach ($_PLUGINS as $pi_name) {
          $function = 'plugin_templatesetvars_' . $pi_name;
          if (function_exists($function)) {
***************
*** 844,861 ****
  */
  function PLG_replacetags($content) {
!     global $_TABLES;
  
!     $result = DB_query("SELECT pi_name FROM {$_TABLES['plugins']} WHERE pi_enabled = 1");
!     $nrows = DB_numRows($result);
!     for ($i = 1; $i <= $nrows; $i++) {
!         $A = DB_fetchArray($result);
!         $function = 'plugin_replacetags_' . $A['pi_name'];
          if (function_exists($function)) {
!             $content = $function($content);
          }
      }
!     /* Now check if GL Core Story API exists */
!     if (function_exists('plugin_replacetags_story')) {
!         $content = plugin_replacetags_story($content);
      }
  
--- 843,912 ----
  */
  function PLG_replacetags($content) {
!     global $_TABLES, $_PLUGINS, $LANG32;
  
!     // Determine which Core Modules and Plugins support AutoLinks
!     $autolinkModules = array('story' => 'story');
!     foreach ($_PLUGINS as $pi_name) {
!         $function = 'plugin_autotags_' . $pi_name;
          if (function_exists($function)) {
!             $autotag = $function('tagname');
!             $autolinkModules[$pi_name]  = $autotag;
          }
      }
! 
!     // For each supported module - scan the content looking for any AutoLink tags
!     $tags = array();
!     foreach ($autolinkModules as $module => $moduletag) {
!         $autotag_prefix = '['. $moduletag;
!         $offset = $prev_offset = 0;
!         $strlen = strlen($content);
!         while ($offset < $strlen) {
!             $start_pos = strpos( strtolower( $content ), $autotag_prefix, $offset );
!             if( $start_pos !== FALSE ) {
!                $end_pos = strpos( strtolower( $content ), ']', $start_pos );
!                $next_tag = strpos( strtolower( $content ), '[', $start_pos +1);
!                if( $end_pos > $start_pos AND (($end_pos < $next_tag OR $next_tag == FALSE)) ) {
!                     $taglength = $end_pos - $start_pos + 1;
!                     $tag = substr($content,$start_pos,$taglength);
!                     $parms = explode(' ',$tag);
!                     // $LANG32['32'] used to format Address link - default add brackets like [ here ]
!                     $label = sprintf( $LANG32['33'] ,str_replace(']','',substr($tag,strlen($parms[0])+1)) );
!                     $parms = explode(':',$parms[0]);
!                     $fileid = $parms['1'];
!                     $newtag = array (
!                         'module'    => $module,
!                         'tagstr'    => $tag,
!                         'startpos'  => $start_pos,
!                         'length'    => $taglength,
!                         'parm1'     => $fileid,
!                         'parm2'     => $label
!                     );
!                     $tags[] = $newtag;
! 
!                 } else {
!                     /* Error tags do not match - return with no changes */
!                     return $content . $LANG32['32'];
!                 }
!                 $prev_offset = $offset;
!                 $offset = $end_pos;
!             } else {
!                 $prev_offset = $end_pos;
!                 $end_pos = $strlen;
!                 $offset = $strlen;
!             }
!         }
!     }
! 
!     // If we have found 1 or more AutoLink tag
!     if (count($tags) > 0) {       // Found the [tag] - Now process them all
!         foreach ($tags as $autotag) {
!             $function = 'plugin_autotags_' . $autotag['module'];
!             if ($autotag['module'] == 'story') {
!                 $filelink = '<a href="'.$_CONF['site_url'].'/article.php?story='.$autotag['parm1'].'">'.$autotag['parm2'].'</a>';
!                 $content = str_replace($autotag['tagstr'],$filelink,$content);
!             } elseif (function_exists($function)) {
!                 $content = $function('parse',$content,$autotag);
!             }
!         }
      }
  




More information about the geeklog-cvs mailing list