[geeklog-cvs] geeklog: Added tracking of current topic via a session variable ...

geeklog-cvs at lists.geeklog.net geeklog-cvs at lists.geeklog.net
Fri Dec 23 15:44:49 EST 2011


changeset 8460:9090774b8663
url:  http://project.geeklog.net/cgi-bin/hgwebdir.cgi/geeklog/rev/9090774b8663
user: Tom <websitemaster at cogeco.net>
date: Fri Dec 23 13:10:43 2011 -0500
description:
Added tracking of current topic via a session variable stored in the db.

diffstat:

 public_html/lib-common.php           |   33 ++++++-----
 sql/mssql_tableanddata.php           |    3 +-
 sql/mysql_tableanddata.php           |    1 +
 sql/pgsql_tableanddata.php           |    1 +
 sql/updates/mssql_1.8.1_to_1.9.0.php |    1 +
 sql/updates/mysql_1.8.1_to_1.9.0.php |    1 +
 sql/updates/pgsql_1.8.1_to_1.9.0.php |    1 +
 system/lib-sessions.php              |   51 +++++++++++++++++
 system/lib-topic.php                 |  101 +++++++++++++++++++++++++++++++---
 9 files changed, 166 insertions(+), 27 deletions(-)

diffs (truncated from 345 to 300 lines):

diff -r facd0f22388b -r 9090774b8663 public_html/lib-common.php
--- a/public_html/lib-common.php	Wed Dec 14 15:16:08 2011 -0500
+++ b/public_html/lib-common.php	Fri Dec 23 13:10:43 2011 -0500
@@ -220,6 +220,19 @@
 require_once( $_CONF['path_system'] . 'lib-topic.php' );
 
 /**
+* Retrieve new topic or get last topic.
+*
+*/
+
+if (isset($_GET['topic'])) {
+    $topic = COM_applyFilter( $_GET['topic'] );
+} elseif (isset( $_POST['topic'])) {
+    $topic = COM_applyFilter( $_POST['topic'] );
+} else {
+    $topic = '';
+}
+
+/**
 * This is the block library used to manage blocks.
 *
 */
@@ -450,19 +463,6 @@
 
 $_RIGHTS = explode( ',', SEC_getUserPermissions() );
 
-if( isset( $_GET['topic'] ))
-{
-    $topic = COM_applyFilter( $_GET['topic'] );
-}
-else if( isset( $_POST['topic'] ))
-{
-    $topic = COM_applyFilter( $_POST['topic'] );
-}
-else
-{
-    $topic = '';
-}
-
 /**
 * Build global array of Topics current user has access to
 *
@@ -1249,6 +1249,9 @@
             $header->parse( 'right_blocks', 'rightblocks', true );
         }
     }
+    
+    // Set last topic session variable
+    SESS_setVariable('topic', $topic);
 
     // Call any plugin that may want to include extra Meta tags
     // or Javascript functions
@@ -3610,9 +3613,9 @@
         $commonsql .= " AND (ta.tid IN({$tid_list}) AND (ta.inherit = 1 OR (ta.inherit = 0 AND ta.tid = '{$topic}')) OR ta.tid = 'all')";
     } else {
         if( COM_onFrontpage() ) {
-            $commonsql .= " AND (ta.tid = 'homeonly' OR ta.tid = 'all')";
+            $commonsql .= " AND (ta.tid = '" . TOPIC_HOMEONLY_OPTION . "' OR ta.tid = '" . TOPIC_ALL_OPTION . "')";
         } else {
-            $commonsql .= " AND (ta.tid = 'all')";
+            $commonsql .= " AND (ta.tid = '" . TOPIC_ALL_OPTION . "')";
         }
     }
 
diff -r facd0f22388b -r 9090774b8663 sql/mssql_tableanddata.php
--- a/sql/mssql_tableanddata.php	Wed Dec 14 15:16:08 2011 -0500
+++ b/sql/mssql_tableanddata.php	Fri Dec 23 13:10:43 2011 -0500
@@ -262,7 +262,8 @@
     [remote_ip] [varchar] (39) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
     [uid] [int] NOT NULL ,
     [md5_sess_id] [varchar] (128) COLLATE SQL_Latin1_General_CP1_CI_AS NULL, 
-    [whos_online] [tinyint] NOT NULL
+    [whos_online] [tinyint] NOT NULL, 
+    [topic] [varchar] (20) NOT NULL
 ) ON [PRIMARY]
 ";
 
diff -r facd0f22388b -r 9090774b8663 sql/mysql_tableanddata.php
--- a/sql/mysql_tableanddata.php	Wed Dec 14 15:16:08 2011 -0500
+++ b/sql/mysql_tableanddata.php	Fri Dec 23 13:10:43 2011 -0500
@@ -259,6 +259,7 @@
   uid mediumint(8) NOT NULL default '1',
   md5_sess_id varchar(128) default NULL,
   whos_online tinyint(1) NOT NULL default '1',
+  topic varchar(20) NOT NULL default '',
   PRIMARY KEY  (sess_id),
   KEY sess_id (sess_id),
   KEY start_time (start_time),
diff -r facd0f22388b -r 9090774b8663 sql/pgsql_tableanddata.php
--- a/sql/pgsql_tableanddata.php	Wed Dec 14 15:16:08 2011 -0500
+++ b/sql/pgsql_tableanddata.php	Fri Dec 23 13:10:43 2011 -0500
@@ -258,6 +258,7 @@
   uid smallint NOT NULL default '1',
   md5_sess_id varchar(128) default NULL,
   whos_online smallint NOT NULL default '1',
+  topic varchar(20) NOT NULL default '',
   PRIMARY KEY (sess_id)
 );
   CREATE INDEX {$_TABLES['sessions']}_start_time ON {$_TABLES['sessions']} (start_time);
diff -r facd0f22388b -r 9090774b8663 sql/updates/mssql_1.8.1_to_1.9.0.php
--- a/sql/updates/mssql_1.8.1_to_1.9.0.php	Wed Dec 14 15:16:08 2011 -0500
+++ b/sql/updates/mssql_1.8.1_to_1.9.0.php	Fri Dec 23 13:10:43 2011 -0500
@@ -18,6 +18,7 @@
 
 // Update Session Table
 $_SQL[] = "ALTER TABLE {$_TABLES['sessions']} ADD [whos_online] [tinyint] NOT NULL AFTER [md5_sess_id]";
+$_SQL[] = "ALTER TABLE {$_TABLES['sessions']} ADD [topic] [varchar] (20) NOT NULL AFTER [whos_online]";
 
 /**
  * Create Story and Submission Topic assignments
diff -r facd0f22388b -r 9090774b8663 sql/updates/mysql_1.8.1_to_1.9.0.php
--- a/sql/updates/mysql_1.8.1_to_1.9.0.php	Wed Dec 14 15:16:08 2011 -0500
+++ b/sql/updates/mysql_1.8.1_to_1.9.0.php	Fri Dec 23 13:10:43 2011 -0500
@@ -18,6 +18,7 @@
 
 // Update Session Table
 $_SQL[] = "ALTER TABLE {$_TABLES['sessions']} ADD whos_online tinyint(1) NOT NULL default '1' AFTER md5_sess_id";
+$_SQL[] = "ALTER TABLE {$_TABLES['sessions']} ADD topic varchar(20) NOT NULL default '' AFTER whos_online";
 
 /**
  * Create Story and Submission Topic assignments
diff -r facd0f22388b -r 9090774b8663 sql/updates/pgsql_1.8.1_to_1.9.0.php
--- a/sql/updates/pgsql_1.8.1_to_1.9.0.php	Wed Dec 14 15:16:08 2011 -0500
+++ b/sql/updates/pgsql_1.8.1_to_1.9.0.php	Fri Dec 23 13:10:43 2011 -0500
@@ -19,6 +19,7 @@
 
 // Update Session Table
 $_SQL[] = "ALTER TABLE {$_TABLES['sessions']} ADD COLUMN whos_online smallint NOT NULL default '1' AFTER md5_sess_id";
+$_SQL[] = "ALTER TABLE {$_TABLES['sessions']} ADD COLUMN topic varchar(20) NOT NULL default '' AFTER whos_online";
 
 /**
  * Create Story and Submission Topic assignments
diff -r facd0f22388b -r 9090774b8663 system/lib-sessions.php
--- a/system/lib-sessions.php	Wed Dec 14 15:16:08 2011 -0500
+++ b/system/lib-sessions.php	Fri Dec 23 13:10:43 2011 -0500
@@ -240,6 +240,8 @@
         COM_errorLog("***Leaving SESS_sessionCheck***",1);
     }
 
+    $_USER['session_id'] = $sessid;
+    
     // Ensure $_USER is set to avoid warnings (path exposure...)
     if (isset($_USER)) {
         return $_USER;
@@ -520,4 +522,53 @@
     return $myrow;
 }
 
+/**
+* Retrieves a session variable from the db
+*
+* @param        string      $variable   Variable name to retrieve
+* @return       string     data from variable
+*
+*/
+function SESS_getVariable($variable)
+{
+    global $_TABLES, $_CONF, $_USER;
+    
+    $session_id = $_USER['session_id'];
+
+    if ( $_CONF['cookie_ip'] == 1) { // $md5_based  Indicates if sessid is MD5 hash
+        $sql_where = "md5_sess_id = '$session_id'";
+    } else {
+        $sql_where = "sess_id = '$session_id'";
+    }
+
+    $retval = DB_getItem($_TABLES['sessions'], $variable, $sql_where);
+
+    return $retval;
+}
+
+/**
+* Updates a session variable from the db
+*
+* @param        string      $variable   Variable name to update
+* @param        string      $value      Value of variable
+* @return       boolean     always true for some reason
+*
+*/
+function SESS_setVariable($variable, $value)
+{
+    global $_TABLES, $_CONF, $_USER;
+    
+    $session_id = $_USER['session_id'];
+
+    if ( $_CONF['cookie_ip'] == 1) { // $md5_based  Indicates if sessid is MD5 hash
+        $sql = "UPDATE {$_TABLES['sessions']} SET $variable = '$value' WHERE (md5_sess_id = '$session_id')";
+    } else {
+        $sql = "UPDATE {$_TABLES['sessions']} SET $variable = '$value' WHERE (sess_id = '$session_id')";
+    }
+
+    $result = DB_query($sql);
+
+    return 1;
+}
+
 ?>
diff -r facd0f22388b -r 9090774b8663 system/lib-topic.php
--- a/system/lib-topic.php	Wed Dec 14 15:16:08 2011 -0500
+++ b/system/lib-topic.php	Fri Dec 23 13:10:43 2011 -0500
@@ -42,11 +42,6 @@
 define("TOPIC_SELECTED_OPTION", 'selectedtopics');
 define("TOPIC_ROOT", 'root');
 
-
-
-
-
-
 /**
 * Return the topic tree structure in an array.
 *
@@ -569,7 +564,7 @@
 * (need to handle 'all' and 'homeonly' as special cases)
 *
 * @param    string          $type   Type of object to find topic access about. If 'topic' then will check post array for topic selection control 
-* @param    string/array    $id     ID of block or topic to check if block topic access
+* @param    string/array    $id     ID of object to check topic access for
 * @return   int                     returns 3 for read/edit 2 for read only 0 for no access
 *
 */
@@ -846,7 +841,7 @@
     if (!$from_db) {    
         TOPIC_getDataTopicSelectionControl($topic_option, $tids, $inherit_tids, $default_tid);
     } else {        
-        $sql['mysql'] = "SELECT * FROM {$_TABLES['topic_assignments']} WHERE type = '$type' AND id ='$id'";
+        $sql = "SELECT * FROM {$_TABLES['topic_assignments']} WHERE type = '$type' AND id ='$id'";
     
         $result = DB_query($sql);
         $B = DB_fetchArray($result);
@@ -1068,6 +1063,25 @@
 }
 
 /**
+* Add Topic Assignments for a specfic object  
+*
+* @param    string          $type   Type of object to find topic access about.  
+* @param    string/array    $id     ID of object
+* @return   nothing
+*
+*/
+function TOPIC_addTopicAssignments($type, $id, $tid = '')
+{
+    global $_TABLES;
+    
+    if ($tid == '') {
+        $tid = TOPIC_ALL_OPTION;
+    }
+    
+    DB_save ($_TABLES['topic_assignments'], 'tid,type,id,inherit,tdefault', "'$tid', '$type', '$id', 0 , 0");
+}
+
+/**
 * Return Topic list for Admin list Topic Column 
 * (need to handle 'all' and 'homeonly' as special cases)
 *
@@ -1082,10 +1096,8 @@
     
     $retval = '';
     
-    // Retrieve Topic options
-    $sql['mysql'] = "SELECT * FROM {$_TABLES['topic_assignments']} WHERE type = '$type' AND id = '$id'";
-    $sql['mssql'] = "SELECT ta.tid, t.topic FROM {$_TABLES['topics']} t, {$_TABLES['topic_assignments']} ta WHERE ta.type = 'block' AND ta.id ='$id' AND t.tid = ta.tid";
-    $sql['pgsql'] = "SELECT ta.tid, t.topic FROM {$_TABLES['topics']} t, {$_TABLES['topic_assignments']} ta WHERE ta.type = 'block' AND ta.id ='$id' AND t.tid = ta.tid";
+    // Retrieve topic assignments
+    $sql = "SELECT * FROM {$_TABLES['topic_assignments']} WHERE type = '$type' AND id = '$id'";
 
     $result = DB_query($sql);
     $A = DB_fetchArray($result);
@@ -1108,6 +1120,73 @@
 }
 
 /**
+* 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.
+*
+* @param    string          $type   Type of object to find topic access about.  
+* @param    string/array    $id     ID of object
+* @return   void
+*
+*/
+function TOPIC_getTopic($type, $id)
+{
+    global $_TABLES, $topic;
+    
+    $find_another = false;
+    
+    // Double check
+    $topic = COM_applyFilter($topic);
+    
+    // Check Previous topic
+    if ($topic == '') {
+        // Blank could mean all topics or that we do not know topic
+        // retrieve previous topic
+        $last_topic = SESS_getVariable('topic');
+    } else {
+        $last_topic = $topic;



More information about the geeklog-cvs mailing list