[geeklog-hg] geeklog: Unified the behaviour of the autotag to leave the autot...

geeklog-cvs at lists.geeklog.net geeklog-cvs at lists.geeklog.net
Sat May 18 21:41:50 EDT 2013


changeset 9069:0c45d68795cb
url:  http://project.geeklog.net/cgi-bin/hgwebdir.cgi/geeklog/rev/0c45d68795cb
user: dengen
date: Sun May 19 10:40:41 2013 +0900
description:
Unified the behaviour of the autotag to leave the autotag text unchanged if the ID is not valid (feature request #0001115)

diffstat:

 plugins/calendar/functions.inc    |  22 +++++---
 plugins/links/functions.inc       |  44 ++++++++++-------
 plugins/polls/functions.inc       |  95 ++++++++++++++++++++------------------
 plugins/staticpages/functions.inc |  48 ++++++++++++-------
 4 files changed, 120 insertions(+), 89 deletions(-)

diffs (261 lines):

diff -r b4addb5d3f56 -r 0c45d68795cb plugins/calendar/functions.inc
--- a/plugins/calendar/functions.inc	Sat May 18 21:15:07 2013 +0900
+++ b/plugins/calendar/functions.inc	Sun May 19 10:40:41 2013 +0900
@@ -1187,15 +1187,21 @@
     } else if ($op == 'parse') {
         $eid = COM_applyFilter($autotag['parm1']);
         if (! empty($eid)) {
-            $url = $_CONF['site_url'] . '/calendar/event.php?eid=' . $eid;
-            if (empty ($autotag['parm2'])) {
-                $linktext = stripslashes (DB_getItem ($_TABLES['events'],
-                                          'title', "eid = '$eid'"));
-            } else {
-                $linktext = $autotag['parm2'];
+            $result = DB_query("SELECT COUNT(*) AS count "
+                . "FROM {$_TABLES['events']} "
+                . "WHERE eid = '$eid'" . COM_getPermSql('AND'));
+            $A = DB_fetchArray($result);
+            if ($A['count'] > 0) {
+                $url = $_CONF['site_url'] . '/calendar/event.php?eid=' . $eid;
+                if (empty ($autotag['parm2'])) {
+                    $linktext = stripslashes (DB_getItem ($_TABLES['events'],
+                                              'title', "eid = '$eid'"));
+                } else {
+                    $linktext = $autotag['parm2'];
+                }
+                $link = COM_createLink($linktext, $url);
+                $content = str_replace ($autotag['tagstr'], $link, $content);
             }
-            $link = COM_createLink($linktext, $url);
-            $content = str_replace ($autotag['tagstr'], $link, $content);
         }
 
         return $content;
diff -r b4addb5d3f56 -r 0c45d68795cb plugins/links/functions.inc
--- a/plugins/links/functions.inc	Sat May 18 21:15:07 2013 +0900
+++ b/plugins/links/functions.inc	Sun May 19 10:40:41 2013 +0900
@@ -216,26 +216,32 @@
     } else if ($op == 'parse') {
         $lid = COM_applyFilter($autotag['parm1']);
         if (! empty($lid)) {
-            $url = COM_buildUrl($_CONF['site_url']
-                            . '/links/portal.php?what=link&item=' . $lid);
-            if (empty($autotag['parm2'])) {
-                $result = DB_query("SELECT url, title FROM {$_TABLES['links']} WHERE lid = '$lid'");
-                list($siteurl, $linktext) = DB_fetchArray($result);
-                $linktext = stripslashes($linktext);
-            } else {
-                $linktext = $autotag['parm2'];
-                $siteurl = DB_getItem($_TABLES['links'], 'url', "lid = '$lid'");
+            $result = DB_query("SELECT COUNT(*) AS count "
+                . "FROM {$_TABLES['links']} "
+                . "WHERE lid = '$lid'" . COM_getPermSql('AND'));
+            $A = DB_fetchArray($result);
+            if ($A['count'] > 0) {
+                $url = COM_buildUrl($_CONF['site_url']
+                                . '/links/portal.php?what=link&item=' . $lid);
+                if (empty($autotag['parm2'])) {
+                    $result = DB_query("SELECT url, title FROM {$_TABLES['links']} WHERE lid = '$lid'");
+                    list($siteurl, $linktext) = DB_fetchArray($result);
+                    $linktext = stripslashes($linktext);
+                } else {
+                    $linktext = $autotag['parm2'];
+                    $siteurl = DB_getItem($_TABLES['links'], 'url', "lid = '$lid'");
+                }
+                $class = 'ext-link';
+                if ((!empty($LANG_DIRECTION)) && ($LANG_DIRECTION == 'rtl')) {
+                    $class .= '-rtl';
+                }
+                $attr = array(
+                            'title' => $siteurl,
+                            'class' => $class
+                             );
+                $link = COM_createLink($linktext, $url, $attr);
+                $content = str_replace($autotag['tagstr'], $link, $content);
             }
-            $class = 'ext-link';
-            if ((!empty($LANG_DIRECTION)) && ($LANG_DIRECTION == 'rtl')) {
-                $class .= '-rtl';
-            }
-            $attr = array(
-                        'title' => $siteurl,
-                        'class' => $class
-                         );
-            $link = COM_createLink($linktext, $url, $attr);
-            $content = str_replace($autotag['tagstr'], $link, $content);
         }
 
         return $content;
diff -r b4addb5d3f56 -r 0c45d68795cb plugins/polls/functions.inc
--- a/plugins/polls/functions.inc	Sat May 18 21:15:07 2013 +0900
+++ b/plugins/polls/functions.inc	Sun May 19 10:40:41 2013 +0900
@@ -1566,53 +1566,60 @@
             );
     } elseif ($op == 'parse') {
         $pid = COM_applyFilter($autotag['parm1']);
-        $showall = false;
+        if (! empty($pid)) {
+            $result = DB_query("SELECT COUNT(*) AS count "
+                . "FROM {$_TABLES['polltopics']} "
+                . "WHERE pid = '$pid'" . COM_getPermSql('AND'));
+            $A = DB_fetchArray($result);
+            if ($A['count'] > 0) {
+                switch ($autotag['tag']) {
+                case 'poll':
+                    if (!empty($autotag['parm2'])) {
+                        $title = COM_applyFilter($autotag['parm2']);
+                    } else {
+                        $title = DB_getItem($_TABLES['polltopics'], 'topic',
+                                            "pid = '$pid'");
+                    }
 
-        switch ($autotag['tag']) {
-        case 'poll':
-            if (!empty($autotag['parm2'])) {
-                $title = COM_applyFilter($autotag['parm2']);
-            } else {
-                $title = DB_getItem($_TABLES['polltopics'], 'topic',
-                                    "pid = '$pid'");
+                    $retval = COM_createLink($title, $_CONF['site_url']
+                                    . '/polls/index.php?pid=' . $pid . '&aid=-1');
+                    break;
+
+                case 'poll_vote':
+                case 'poll_result':
+                    $showall = false;
+                    $px = explode(' ', trim($autotag['parm2']));
+                    $css_class = "poll-autotag";
+
+                    if (is_array($px)) {
+                        foreach ($px as $part) {
+                            if (substr($part, 0, 6) == 'class:') {
+                                $a = explode(':', $part);
+                                $css_class = $a[1];
+                            } elseif (substr($part, 0, 8) == 'showall:') {
+                                $a = explode(':', $part);
+                                $val = $a[1];
+                                if ($val == 1) {
+                                    $showall = true;
+                                }
+                            } else {
+                                break;
+                            }
+                        }
+                    }
+
+                    if ($autotag['tag'] == 'poll_vote') {
+                        $retval = POLLS_showPoll(0, $pid, $showall, 2);
+                    } else {
+                        $retval = POLLS_pollResults($pid, 0,'', '', 1, 2);
+                    }
+                    $retval = '<div class="' . $css_class . '">' . $retval . '</div>';
+                    break;
+                }
+
+                $content = str_replace($autotag['tagstr'], $retval, $content);
             }
-
-            $retval = COM_createLink($title, $_CONF['site_url']
-                            . '/polls/index.php?pid=' . $pid . '&aid=-1');
-            break;
-
-        case 'poll_vote':
-        case 'poll_result':
-            $px = explode(' ', trim($autotag['parm2']));
-            $css_class = "poll-autotag";
-
-            if (is_array($px)) {
-                foreach ($px as $part) {
-                    if (substr($part, 0, 6) == 'class:') {
-                        $a = explode(':', $part);
-                        $css_class = $a[1];
-                    } elseif (substr($part, 0, 8) == 'showall:') {
-                        $a = explode(':', $part);
-                        $val = $a[1];
-                        if ($val == 1) {
-                            $showall = true;
-                        }
-                    } else {
-                        break;
-                    }
-                }
-            }
-
-            if ($autotag['tag'] == 'poll_vote') {
-                $retval = POLLS_showPoll(0, $pid, $showall, 2);
-            } else {
-                $retval = POLLS_pollResults($pid, 0,'', '', 1, 2);
-            }
-            $retval = '<div class="' . $css_class . '">' . $retval . '</div>';
-            break;
         }
-
-        $content = str_replace($autotag['tagstr'], $retval, $content);
     }
 
     return $content;
diff -r b4addb5d3f56 -r 0c45d68795cb plugins/staticpages/functions.inc
--- a/plugins/staticpages/functions.inc	Sat May 18 21:15:07 2013 +0900
+++ b/plugins/staticpages/functions.inc	Sun May 19 10:40:41 2013 +0900
@@ -1255,31 +1255,43 @@
             'staticpage_content' => $LANG_STATIC['autotag_desc_staticpage_content']
             );        
     } elseif ($op == 'parse') {
-        if ($autotag['tag'] == 'staticpage' ) {
+        if ($autotag['tag'] == 'staticpage') {
             $sp_id = COM_applyFilter($autotag['parm1']);
             if (! empty($sp_id)) {
-                $url = COM_buildUrl($_CONF['site_url']
-                                . '/staticpages/index.php?page=' . $sp_id);
-                if (empty($autotag['parm2'])) {
-                    $linktext = stripslashes(DB_getItem($_TABLES['staticpage'],
-                                             'sp_title', "sp_id = '$sp_id'"));
-                } else {
-                    $linktext = $autotag['parm2'];
+                $result = DB_query("SELECT COUNT(*) AS count "
+                    . "FROM {$_TABLES['staticpage']} "
+                    . "WHERE sp_id = '$sp_id'" . COM_getPermSql('AND'));
+                $A = DB_fetchArray($result);
+                if ($A['count'] > 0) {
+                    $url = COM_buildUrl($_CONF['site_url']
+                                    . '/staticpages/index.php?page=' . $sp_id);
+                    if (empty($autotag['parm2'])) {
+                        $linktext = stripslashes(DB_getItem($_TABLES['staticpage'],
+                                                 'sp_title', "sp_id = '$sp_id'"));
+                    } else {
+                        $linktext = $autotag['parm2'];
+                    }
+                    $link = COM_createLink($linktext, $url);
+                    $content = str_replace($autotag['tagstr'], $link, $content);
                 }
-                $link = COM_createLink($linktext, $url);
-                $content = str_replace($autotag['tagstr'], $link, $content);
             }
         } elseif ($autotag['tag'] == 'staticpage_content') {
             $sp_id = COM_applyFilter($autotag['parm1']);
             if (! empty($sp_id)) {
-                if (isset($recursive[$sp_id])) {
-                    $content = '';
-                } else {
-                    $recursive[$sp_id] = true;
-                    $sp_content = SP_returnStaticpage($sp_id, 'autotag');
-                    $content = str_replace($autotag['tagstr'], $sp_content,
-                                           $content);
-                    unset($recursive[$sp_id]);
+                $result = DB_query("SELECT COUNT(*) AS count "
+                    . "FROM {$_TABLES['staticpage']} "
+                    . "WHERE sp_id = '$sp_id'" . COM_getPermSql('AND'));
+                $A = DB_fetchArray($result);
+                if ($A['count'] > 0) {
+                    if (isset($recursive[$sp_id])) {
+                        $content = '';
+                    } else {
+                        $recursive[$sp_id] = true;
+                        $sp_content = SP_returnStaticpage($sp_id, 'autotag');
+                        $content = str_replace($autotag['tagstr'], $sp_content,
+                                               $content);
+                        unset($recursive[$sp_id]);
+                    }
                 }
             }
         }



More information about the geeklog-cvs mailing list