[geeklog-cvs] geeklog: If content from an Autotag produces another Autotag it ...

geeklog-cvs at lists.geeklog.net geeklog-cvs at lists.geeklog.net
Thu Sep 23 14:07:01 EDT 2010


changeset 7978:05414881d63e
url:  http://project.geeklog.net/cgi-bin/hgwebdir.cgi/geeklog/rev/05414881d63e
user: Tom <websitemaster at cogeco.net>
date: Thu Sep 23 14:05:58 2010 -0400
description:
If content from an Autotag produces another Autotag it will be executed (to a maximum of 5 times)

diffstat:

 public_html/docs/history |    2 +
 system/lib-plugins.php   |  193 +++++++++++++++++++++++-----------------------
 2 files changed, 100 insertions(+), 95 deletions(-)

diffs (232 lines):

diff -r 355ee96c5796 -r 05414881d63e public_html/docs/history
--- a/public_html/docs/history	Sat Sep 18 14:05:32 2010 -0400
+++ b/public_html/docs/history	Thu Sep 23 14:05:58 2010 -0400
@@ -3,6 +3,8 @@
 Sep 1?, 2010 (1.7.1rc1)
 ------------
 
+- If content from an Autotag produces another Autotag it will be executed (to a
+  maximum of 5 times) [Tom]
 - Themes can now have their own display funtions for the start and end of
   Blocks. (Feature #0001188) [Tom]
 - Reverted a change in 1.7.0 that would send a Content-Type header when calling
diff -r 355ee96c5796 -r 05414881d63e system/lib-plugins.php
--- a/system/lib-plugins.php	Sat Sep 18 14:05:32 2010 -0400
+++ b/system/lib-plugins.php	Thu Sep 23 14:05:58 2010 -0400
@@ -1559,118 +1559,121 @@
 
     $autolinkModules = PLG_collectTags();
 
-    // For each supported module, scan the content looking for any AutoLink tags
-    $tags = array();
-    $contentlen = MBYTE_strlen($content);
-    $content_lower = MBYTE_strtolower($content);
-    foreach ($autolinkModules as $moduletag => $module) {
-        $autotag_prefix = '['. $moduletag . ':';
-        $offset = 0;
-        $prev_offset = 0;
-        while ($offset < $contentlen) {
-            $start_pos = MBYTE_strpos($content_lower, $autotag_prefix,
-                                      $offset);
-            if ($start_pos === false) {
-                break;
-            } else {
-                $end_pos  = MBYTE_strpos($content_lower, ']', $start_pos);
-                $next_tag = MBYTE_strpos($content_lower, '[', $start_pos + 1);
-                if (($end_pos > $start_pos) AND
-                        (($next_tag === false) OR ($end_pos < $next_tag))) {
-                    $taglength = $end_pos - $start_pos + 1;
-                    $tag = MBYTE_substr($content, $start_pos, $taglength);
-                    $parms = explode(' ', $tag);
-
-                    // Extra test to see if autotag was entered with a space
-                    // after the module name
-                    if (MBYTE_substr($parms[0], -1) == ':') {
-                        $startpos = MBYTE_strlen($parms[0]) + MBYTE_strlen($parms[1]) + 2;
-                        $label = str_replace(']', '', MBYTE_substr($tag, $startpos));
-                        $tagid = $parms[1];
+    for ($i = 1; $i <= 5; $i++) {
+        // For each supported module, scan the content looking for any AutoLink tags
+        $tags = array();
+        $contentlen = MBYTE_strlen($content);
+        $content_lower = MBYTE_strtolower($content);
+        foreach ($autolinkModules as $moduletag => $module) {
+            $autotag_prefix = '['. $moduletag . ':';
+            $offset = 0;
+            $prev_offset = 0;
+            while ($offset < $contentlen) {
+                $start_pos = MBYTE_strpos($content_lower, $autotag_prefix,
+                                          $offset);
+                if ($start_pos === false) {
+                    break;
+                } else {
+                    $end_pos  = MBYTE_strpos($content_lower, ']', $start_pos);
+                    $next_tag = MBYTE_strpos($content_lower, '[', $start_pos + 1);
+                    if (($end_pos > $start_pos) AND
+                            (($next_tag === false) OR ($end_pos < $next_tag))) {
+                        $taglength = $end_pos - $start_pos + 1;
+                        $tag = MBYTE_substr($content, $start_pos, $taglength);
+                        $parms = explode(' ', $tag);
+    
+                        // Extra test to see if autotag was entered with a space
+                        // after the module name
+                        if (MBYTE_substr($parms[0], -1) == ':') {
+                            $startpos = MBYTE_strlen($parms[0]) + MBYTE_strlen($parms[1]) + 2;
+                            $label = str_replace(']', '', MBYTE_substr($tag, $startpos));
+                            $tagid = $parms[1];
+                        } else {
+                            $label = str_replace(']', '', MBYTE_substr($tag,
+                                                    MBYTE_strlen($parms[0]) + 1));
+                            $parms = explode(':', $parms[0]);
+                            if (count($parms) > 2) {
+                                // whoops, there was a ':' in the tag id ...
+                                array_shift($parms);
+                                $tagid = implode(':', $parms);
+                            } else {
+                                $tagid = $parms[1];
+                            }
+                        }
+    
+                        $newtag = array(
+                            'module'    => $module,
+                            'tag'       => $moduletag,
+                            'tagstr'    => $tag,
+                            'startpos'  => $start_pos,
+                            'length'    => $taglength,
+                            'parm1'     => str_replace(']', '', $tagid),
+                            'parm2'     => $label
+                        );
+                        $tags[] = $newtag;
                     } else {
-                        $label = str_replace(']', '', MBYTE_substr($tag,
-                                                MBYTE_strlen($parms[0]) + 1));
-                        $parms = explode(':', $parms[0]);
-                        if (count($parms) > 2) {
-                            // whoops, there was a ':' in the tag id ...
-                            array_shift($parms);
-                            $tagid = implode(':', $parms);
-                        } else {
-                            $tagid = $parms[1];
-                        }
+                        // Error: tags do not match - return with no changes
+                        return $content . $LANG32[32];
                     }
-
-                    $newtag = array(
-                        'module'    => $module,
-                        'tag'       => $moduletag,
-                        'tagstr'    => $tag,
-                        'startpos'  => $start_pos,
-                        'length'    => $taglength,
-                        'parm1'     => str_replace(']', '', $tagid),
-                        'parm2'     => $label
-                    );
-                    $tags[] = $newtag;
-                } else {
-                    // Error: tags do not match - return with no changes
-                    return $content . $LANG32[32];
+                    $prev_offset = $offset;
+                    $offset = $end_pos;
                 }
-                $prev_offset = $offset;
-                $offset = $end_pos;
             }
         }
-    }
-
-    // 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'] == 'geeklog') AND
-                    (empty($plugin) OR ($plugin == 'geeklog'))) {
-                $url = '';
-                $linktext = $autotag['parm2'];
-                if ($autotag['tag'] == 'story') {
-                    $autotag['parm1'] = COM_applyFilter($autotag['parm1']);
-                    if (! empty($autotag['parm1'])) {
-                        $url = COM_buildUrl($_CONF['site_url']
-                             . '/article.php?story=' . $autotag['parm1']);
-                        if (empty($linktext)) {
-                            $linktext = stripslashes(DB_getItem($_TABLES['stories'], 'title', "sid = '{$autotag['parm1']}'"));
-                        }
-                    }
-                }
-
-                if ($autotag['tag'] == 'user') {
-                    $autotag['parm1'] = COM_applyFilter($autotag['parm1']);
-                    if (! empty($autotag['parm1'])) {
-                        $uname = addslashes($autotag['parm1']);
-                        $sql = "SELECT uid, fullname FROM {$_TABLES['users']} WHERE username = '$uname'";
-                        $result = DB_query($sql);
-                        if (DB_numRows($result) == 1) {
-                            $A = DB_fetchArray($result);
-                            $url = $_CONF['site_url'] . '/users.php?mode=profile&uid=' . $A['uid'];
+    
+        // 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'] == 'geeklog') AND
+                        (empty($plugin) OR ($plugin == 'geeklog'))) {
+                    $url = '';
+                    $linktext = $autotag['parm2'];
+                    if ($autotag['tag'] == 'story') {
+                        $autotag['parm1'] = COM_applyFilter($autotag['parm1']);
+                        if (! empty($autotag['parm1'])) {
+                            $url = COM_buildUrl($_CONF['site_url']
+                                 . '/article.php?story=' . $autotag['parm1']);
                             if (empty($linktext)) {
-                                $linktext = COM_getDisplayName($A['uid'], $autotag['parm1'], $A['fullname']);
+                                $linktext = stripslashes(DB_getItem($_TABLES['stories'], 'title', "sid = '{$autotag['parm1']}'"));
                             }
                         }
                     }
+    
+                    if ($autotag['tag'] == 'user') {
+                        $autotag['parm1'] = COM_applyFilter($autotag['parm1']);
+                        if (! empty($autotag['parm1'])) {
+                            $uname = addslashes($autotag['parm1']);
+                            $sql = "SELECT uid, fullname FROM {$_TABLES['users']} WHERE username = '$uname'";
+                            $result = DB_query($sql);
+                            if (DB_numRows($result) == 1) {
+                                $A = DB_fetchArray($result);
+                                $url = $_CONF['site_url'] . '/users.php?mode=profile&uid=' . $A['uid'];
+                                if (empty($linktext)) {
+                                    $linktext = COM_getDisplayName($A['uid'], $autotag['parm1'], $A['fullname']);
+                                }
+                            }
+                        }
+                    }
+    
+                    if (!empty($url)) {
+                        $filelink = COM_createLink($linktext, $url);
+                        $content = str_replace($autotag['tagstr'], $filelink,
+                                               $content);
+                    }
+                } elseif (function_exists($function) AND
+                        (empty($plugin) OR ($plugin == $autotag['module']))) {
+                    $content = $function('parse', $content, $autotag);
                 }
-
-                if (!empty($url)) {
-                    $filelink = COM_createLink($linktext, $url);
-                    $content = str_replace($autotag['tagstr'], $filelink,
-                                           $content);
-                }
-            } elseif (function_exists($function) AND
-                    (empty($plugin) OR ($plugin == $autotag['module']))) {
-                $content = $function('parse', $content, $autotag);
             }
+        } else {
+            break;     
         }
     }
 
     return $content;
 }
 
-
 /**
 * Prepare a list of all plugins that support feeds. To do this, we re-use
 * plugin_getfeednames_<plugin name> and only keep the names of those plugins



More information about the geeklog-cvs mailing list