[geeklog-cvs] geeklog: Moved handling of the [story:] and [user:] autotags to ...

geeklog-cvs at lists.geeklog.net geeklog-cvs at lists.geeklog.net
Mon Nov 1 07:48:32 EDT 2010


changeset 8003:c466378e52a6
url:  http://project.geeklog.net/cgi-bin/hgwebdir.cgi/geeklog/rev/c466378e52a6
user: Dirk Haun <dirk at haun-online.de>
date: Mon Nov 01 11:44:24 2010 +0100
description:
Moved handling of the [story:] and [user:] autotags to lib-story.php and lib-user.php, respectively (preparations for feature request #0001115)

diffstat:

 system/lib-plugins.php |  50 ++++++--------------------------------------------
 system/lib-story.php   |  40 +++++++++++++++++++++++++++++++++++++++-
 system/lib-user.php    |  44 +++++++++++++++++++++++++++++++++++++++++++-
 3 files changed, 88 insertions(+), 46 deletions(-)

diffs (200 lines):

diff -r 882ccc8683cc -r c466378e52a6 system/lib-plugins.php
--- a/system/lib-plugins.php	Sun Oct 31 10:27:50 2010 +0100
+++ b/system/lib-plugins.php	Mon Nov 01 11:44:24 2010 +0100
@@ -2,7 +2,7 @@
 
 /* Reminder: always indent with 4 spaces (no tabs). */
 // +---------------------------------------------------------------------------+
-// | Geeklog 1.7                                                               |
+// | Geeklog 1.8                                                               |
 // +---------------------------------------------------------------------------+
 // | lib-plugins.php                                                           |
 // |                                                                           |
@@ -1517,14 +1517,12 @@
 
     // Determine which Core Modules and Plugins support AutoLinks
     //                        'tag'   => 'module'
-    $autolinkModules = array(
-        'story' => 'geeklog', 'user' => 'geeklog'
-    );
+    $all_plugins = array_merge($_PLUGINS, array('story', 'user'));
 
-    foreach ($_PLUGINS as $pi_name) {
+    foreach ($all_plugins as $pi_name) {
         $function = 'plugin_autotags_' . $pi_name;
         if (function_exists($function)) {
-            $autotag = $function ('tagname');
+            $autotag = $function('tagname');
             if (is_array($autotag)) {
                 foreach ($autotag as $tag) {
                     $autolinkModules[$tag] = $pi_name;
@@ -1565,7 +1563,7 @@
         $contentlen = MBYTE_strlen($content);
         $content_lower = MBYTE_strtolower($content);
         foreach ($autolinkModules as $moduletag => $module) {
-            $autotag_prefix = '['. $moduletag . ':';
+            $autotag_prefix = '[' . $moduletag . ':';
             $offset = 0;
             $prev_offset = 0;
             while ($offset < $contentlen) {
@@ -1625,43 +1623,7 @@
         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 (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
+                if (function_exists($function) AND
                         (empty($plugin) OR ($plugin == $autotag['module']))) {
                     $content = $function('parse', $content, $autotag);
                 }
diff -r 882ccc8683cc -r c466378e52a6 system/lib-story.php
--- a/system/lib-story.php	Sun Oct 31 10:27:50 2010 +0100
+++ b/system/lib-story.php	Mon Nov 01 11:44:24 2010 +0100
@@ -2,7 +2,7 @@
 
 /* Reminder: always indent with 4 spaces (no tabs). */
 // +---------------------------------------------------------------------------+
-// | Geeklog 1.7                                                               |
+// | Geeklog 1.8                                                               |
 // +---------------------------------------------------------------------------+
 // | lib-story.php                                                             |
 // |                                                                           |
@@ -1124,6 +1124,44 @@
     COM_olderStuff();
 }
 
+/**
+* Implements the [story:] autotag.
+*
+* @param    string  $op         operation to perform
+* @param    string  $content    item (e.g. story text), including the autotag
+* @param    array   $autotag    parameters used in the autotag
+* @param    mixed               tag names (for $op='tagname') or formatted content
+*
+*/
+function plugin_autotags_story($op, $content = '', $autotag = '')
+{
+    global $_CONF, $_TABLES;
+
+    if ($op == 'tagname' ) {
+        return 'story';
+    } else {
+        $sid = COM_applyFilter($autotag['parm1']);
+        if (! empty($sid)) {
+            $result = DB_query("SELECT COUNT(*) AS count FROM {$_TABLES['stories']} WHERE sid = '$sid'" . COM_getPermSql('AND'));
+            $A = DB_fetchArray($result);
+            if ($A['count'] > 0) {
+
+                $url = COM_buildUrl($_CONF['site_url'] . '/article.php?story='
+                                    . $sid);
+                $linktext = $autotag['parm2'];
+                if (empty($linktext)) {
+                    $linktext = stripslashes(DB_getItem($_TABLES['stories'],
+                                                'title', "sid = '$sid'"));
+                }
+                $link = COM_createLink($linktext, $url);
+                $content = str_replace($autotag['tagstr'], $link, $content);
+            }
+        }
+
+        return $content;
+    }
+}
+
 
 /*
  * START SERVICES SECTION
diff -r 882ccc8683cc -r c466378e52a6 system/lib-user.php
--- a/system/lib-user.php	Sun Oct 31 10:27:50 2010 +0100
+++ b/system/lib-user.php	Mon Nov 01 11:44:24 2010 +0100
@@ -2,7 +2,7 @@
 
 /* Reminder: always indent with 4 spaces (no tabs). */
 // +---------------------------------------------------------------------------+
-// | Geeklog 1.6                                                               |
+// | Geeklog 1.8                                                               |
 // +---------------------------------------------------------------------------+
 // | lib-user.php                                                              |
 // |                                                                           |
@@ -1104,4 +1104,46 @@
     return $retval;
 }
 
+/**
+* Implements the [user:] autotag.
+*
+* @param    string  $op         operation to perform
+* @param    string  $content    item (e.g. story text), including the autotag
+* @param    array   $autotag    parameters used in the autotag
+* @param    mixed               tag names (for $op='tagname') or formatted content
+*
+*/
+function plugin_autotags_user($op, $content = '', $autotag = '')
+{
+    global $_CONF, $_TABLES, $LANG28;
+
+    if ($op == 'tagname' ) {
+        return 'user';
+    } else if ($op == 'parse') {
+        $uname = COM_applyFilter($autotag['parm1']);
+        $uname = addslashes($uname);
+        $sql = "SELECT uid, username, fullname, status 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'];
+            $linktext = $autotag['parm2'];
+            if (empty($linktext)) {
+                $linktext = COM_getDisplayName($A['uid'], $A['username'], $A['fullname']);
+                if ($A['status'] == USER_ACCOUNT_DISABLED) {
+                    $linktext = sprintf('<s title="%s">%s</s>', $LANG28[42],
+                                        $linktext);
+                }
+            }
+
+            $link = COM_createLink($linktext, $url);
+            $content = str_replace($autotag['tagstr'], $link, $content);
+
+        }
+
+        return $content;
+    }
+}
+
 ?>



More information about the geeklog-cvs mailing list