[geeklog-hg] geeklog: Topic icon for articles now displays correctly in all c...

geeklog-cvs at lists.geeklog.net geeklog-cvs at lists.geeklog.net
Fri Jan 18 10:27:56 EST 2013


changeset 8918:6f72c779b74f
url:  http://project.geeklog.net/cgi-bin/hgwebdir.cgi/geeklog/rev/6f72c779b74f
user: Tom <websitemaster at cogeco.net>
date: Fri Jan 18 10:23:22 2013 -0500
description:
Topic icon for articles now displays correctly in all cases when topicis viewed. When you click on an article title you will now view the article in the correct topic. (bug #0001509)

diffstat:

 public_html/index.php |  74 ++++++++++++++++++++++++++++++++++++++++++++------
 system/lib-topic.php  |  30 ++++++++++++++------
 2 files changed, 85 insertions(+), 19 deletions(-)

diffs (195 lines):

diff -r 1e8d62d0021f -r 6f72c779b74f public_html/index.php
--- a/public_html/index.php	Tue Jan 15 11:16:47 2013 -0500
+++ b/public_html/index.php	Fri Jan 18 10:23:22 2013 -0500
@@ -35,6 +35,54 @@
 require_once 'lib-common.php';
 require_once $_CONF['path_system'] . 'lib-story.php';
 
+/**
+* Update array if need be with correct topic. 
+*
+* @param    array   A           Array of articles from db
+* @param    string  tid_list    List of child topics of current topic
+*
+*/
+function fixTopic(&$A, $tid_list)
+{
+    global $_TABLES, $topic;
+    
+    if (!empty($topic)) {
+        // This case may happen if a article belongs to the current topic but the default topic for the article is a child  of the current topic.
+        $sql = "SELECT t.topic, t.imageurl
+            FROM {$_TABLES['topics']} t, {$_TABLES['topic_assignments']} ta 
+            WHERE t.tid = ta.tid  
+            AND ta.type = 'article' AND ta.id = '{$A['sid']}' AND ta.tid = '$topic'
+            " . COM_getLangSQL('tid', 'AND', 't') . COM_getPermSQL('AND', 0, 2, 't');
+           
+        $result = DB_query($sql);
+        $nrows = DB_numRows($result);
+        if ($nrows > 0) {
+            $B = DB_fetchArray($result);
+            $A['topic'] = $B['topic'];
+            $A['imageurl'] = $B['imageurl']; 
+        } else {
+            // Does not belong to current topic so check inherited
+            
+            // Make sure sort order the same as in TOPIC_getTopic or articles with multiple topics might not display in the right topic when clicked
+            $sql = "SELECT t.topic, t.imageurl
+                FROM {$_TABLES['topics']} t, {$_TABLES['topic_assignments']} ta 
+                WHERE t.tid = ta.tid  
+                AND ta.type = 'article' AND ta.id = '{$A['sid']}' 
+                AND (ta.tid IN({$tid_list}) AND (ta.inherit = 1 OR (ta.inherit = 0 AND ta.tid = '{$topic}'))) 
+                " . COM_getLangSQL('tid', 'AND', 't') . COM_getPermSQL('AND', 0, 2, 't') . " 
+                ORDER BY ta.tdefault DESC, ta.tid ASC";
+                
+            $result = DB_query($sql);
+            $nrows = DB_numRows($result);
+            if ($nrows > 0) {
+                $B = DB_fetchArray($result);
+                $A['topic'] = $B['topic'];
+                $A['imageurl'] = $B['imageurl']; 
+            }
+        }
+    }
+}
+
 $newstories = false;
 $displayall = false;
 if (isset ($_GET['display'])) {
@@ -176,6 +224,7 @@
 }
 
 // if a topic was provided only select those stories.
+$tid_list = '';
 if (!empty($topic)) {
     // Retrieve list of inherited topics
     $tid_list = TOPIC_getChildList($topic);
@@ -184,7 +233,6 @@
     if (empty($tid_list)) {
         $tid_list = "'" . $topic . "'";
     }
-    // Get list of blocks to display (except for dynamic). This includes blocks for all topics, and child blocks that are inherited
     $sql .= " AND (ta.tid IN({$tid_list}) AND (ta.inherit = 1 OR (ta.inherit = 0 AND ta.tid = '{$topic}')))";
 } elseif (!$newstories) {
     $sql .= " AND frontpage = 1 AND ta.tdefault = 1";
@@ -229,31 +277,35 @@
     }
 }
 
-$msql = array(); 
-$msql['mysql']="SELECT s.*, ta.tid, UNIX_TIMESTAMP(s.date) AS unixdate, "
+$msql = array();
+
+// The incorrect t.topic, t.imageurl will most likely be return ... will fix later in fixtopic function. 
+// Could not fix in sql since 2 many variables to contend with plus speed of sql statement probably an issue
+$msql['mysql'] = "SELECT s.*, ta.tid, UNIX_TIMESTAMP(s.date) AS unixdate, "         
          . 'UNIX_TIMESTAMP(s.expire) as expireunix, '
          . $userfields . ", t.topic, t.imageurl "
          . "FROM {$_TABLES['stories']} AS s, {$_TABLES['topic_assignments']} AS ta,{$_TABLES['users']} AS u, "
          . "{$_TABLES['topics']} AS t WHERE (s.uid = u.uid) AND (ta.tid = t.tid) AND"
          . " ta.type = 'article' AND ta.id = s.sid AND"
-         . $sql . " GROUP BY s.sid ORDER BY featured DESC, date DESC LIMIT $offset, $limit";
+         . $sql . " GROUP BY s.sid ORDER BY featured DESC, date DESC LIMIT $offset, $limit";     
 
-$msql['mssql']="SELECT s.sid, s.uid, s.draft_flag, ta.tid, s.date, s.title, cast(s.introtext as text) as introtext, cast(s.bodytext as text) as bodytext, s.hits, s.numemails, s.comments, s.trackbacks, s.related, s.featured, s.show_topic_icon, s.commentcode, s.trackbackcode, s.statuscode, s.expire, s.postmode, s.frontpage, s.owner_id, s.group_id, s.perm_owner, s.perm_group, s.perm_members, s.perm_anon, s.advanced_editor_mode, "
+$msql['mssql'] = "SELECT s.sid, s.uid, s.draft_flag, ta.tid, s.date, s.title, cast(s.introtext as text) as introtext, cast(s.bodytext as text) as bodytext, s.hits, s.numemails, s.comments, s.trackbacks, s.related, s.featured, s.show_topic_icon, s.commentcode, s.trackbackcode, s.statuscode, s.expire, s.postmode, s.frontpage, s.owner_id, s.group_id, s.perm_owner, s.perm_group, s.perm_members, s.perm_anon, s.advanced_editor_mode, "
          . " UNIX_TIMESTAMP(s.date) AS unixdate, "
          . 'UNIX_TIMESTAMP(s.expire) as expireunix, '
          . $userfields . ", t.topic, t.imageurl "
          . "FROM {$_TABLES['stories']} AS s, {$_TABLES['topic_assignments']} AS ta, {$_TABLES['users']} AS u, "
          . "{$_TABLES['topics']} AS t WHERE (s.uid = u.uid) AND (ta.tid = t.tid) AND"
          . " ta.type = 'article' AND ta.id = s.sid AND"
-         . $sql . " GROUP BY s.sid ORDER BY featured DESC, date DESC LIMIT $offset, $limit";
-$msql['pgsql']="SELECT s.*, ta.tid, UNIX_TIMESTAMP(s.date) AS unixdate,
+         . $sql . " GROUP BY s.sid ORDER BY featured DESC, date DESC LIMIT $offset, $limit";   
+         
+$msql['pgsql'] = "SELECT s.*, ta.tid, UNIX_TIMESTAMP(s.date) AS unixdate,
             UNIX_TIMESTAMP(s.expire) as expireunix,
             {$userfields}, t.topic, t.imageurl
             FROM {$_TABLES['stories']} AS s, {$_TABLES['topic_assignments']} AS ta, {$_TABLES['users']} AS u,
             {$_TABLES['topics']} AS t WHERE (s.uid = u.uid) AND (ta.tid = t.tid) AND 
-            ta.type = 'article' AND ta.id = s.sid AND 
-            {$sql} GROUP BY s.sid,ta.tid,u.uid,t.topic,t.imageurl ORDER BY featured DESC, date DESC LIMIT {$limit} OFFSET {$offset}";
-
+            ta.type = 'article' AND ta.id = s.sid AND
+            {$sql} GROUP BY s.sid ORDER BY featured DESC, date DESC LIMIT {$offset}, {$limit}";   
+         
 $result = DB_query ($msql);
 
 $nrows = DB_numRows ($result);
@@ -265,6 +317,7 @@
 $breadcrumbs = '';
 
 if ( $A = DB_fetchArray( $result ) ) {
+    fixTopic($A, $tid_list);
     $story = new Story();
     $story->loadFromArray($A);
     if ( $_CONF['showfirstasfeatured'] == 1 ) {
@@ -290,6 +343,7 @@
 
     // get remaining stories
     while ($A = DB_fetchArray ($result)) {
+        fixTopic($A, $tid_list);
         $story = new Story();
         $story->loadFromArray($A);
         $display .= STORY_renderArticle ($story, 'y');
diff -r 1e8d62d0021f -r 6f72c779b74f system/lib-topic.php
--- a/system/lib-topic.php	Tue Jan 15 11:16:47 2013 -0500
+++ b/system/lib-topic.php	Fri Jan 18 10:23:22 2013 -0500
@@ -1144,9 +1144,9 @@
 
 /**
 * Figure out the current topic for a plugin. If permissions or language wrong 
-* will find default else end with a '' topic (which is all). Needs to be run after 
-* lib-common.php so it can grab topic in url if need be. Also if pass blank $type
-* and $id then return just last topic
+* will find default else end with a '' topic (which is all). Needs to be run  
+* on page that is affected by the topic after lib-common.php so it can grab 
+* topic in url if need be. Also if pass blank $type and $id then return just last topic
 *
 * @param    string          $type   Type of object to find topic access about.  
 * @param    string/array    $id     ID of object
@@ -1163,7 +1163,7 @@
     // Double check
     $topic = COM_applyFilter($topic);
     
-    // Check Previous topic
+    // Check and return Previous topic
     if ($topic == '') {
         // Blank could mean all topics or that we do not know topic
         // retrieve previous topic
@@ -1208,17 +1208,29 @@
     
     if (!$found) {
         if ($last_topic != '') {    
-            // see if object belongs to topic
-            $sql = "SELECT ta.* 
+            // see if object belongs to topic or any child inherited topics
+            $tid_list = TOPIC_getChildList($last_topic);
+            
+            $sql = "SELECT ta.tid 
                 FROM {$_TABLES['topics']} t, {$_TABLES['topic_assignments']} ta 
                 WHERE t.tid = ta.tid  
-                AND ta.type = '$type' AND ta.id = '$id' AND ta.tid = '$last_topic' 
-                " . COM_getLangSQL('tid', 'AND', 't') . COM_getPermSQL('AND', 0, 2, 't');
+                AND ta.type = '$type' AND ta.id = '$id' 
+                AND (ta.tid IN({$tid_list}) AND (ta.inherit = 1 OR (ta.inherit = 0 AND ta.tid = '{$last_topic}')))
+                " . COM_getLangSQL('tid', 'AND', 't') . COM_getPermSQL('AND', 0, 2, 't')
+                . " ORDER BY tdefault DESC, tid ASC"; // Order by default first and then tid alphabetically since no defined sort order of topics. This needs to be the same as when topics are displayed (index.php)
         
             $result = DB_query($sql);
             $nrows = DB_numRows($result);
             if ($nrows > 0) {
-                $topic = $last_topic;
+                $A = DB_fetchArray($result);
+                $topic = $A['tid']; // Default topic if returned else first topic in order by tid
+                
+                // Need to check if topic assignment exists for last topic if so make that the topic instead
+                while ($A = DB_fetchArray($result)) {
+                    if ($last_topic == $A['tid']) {
+                        $topic = $A['tid'];
+                    }
+                } 
             } else {
                 $find_another = true;
             }



More information about the geeklog-cvs mailing list