[geeklog-cvs] geeklog-1.3/plugins/staticpages config.php,1.2,1.3 functions.inc,1.17,1.18

dhaun at geeklog.net dhaun at geeklog.net
Sun Mar 9 06:47:24 EST 2003


Update of /usr/cvs/geeklog/geeklog-1.3/plugins/staticpages
In directory internal.geeklog.net:/tmp/cvs-serv30721/plugins/staticpages

Modified Files:
	config.php functions.inc 
Log Message:
Integrated Static Pages 1.3


Index: config.php
===================================================================
RCS file: /usr/cvs/geeklog/geeklog-1.3/plugins/staticpages/config.php,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** config.php	23 Jul 2002 10:12:35 -0000	1.2
--- config.php	9 Mar 2003 11:47:22 -0000	1.3
***************
*** 1,15 ****
  <?php
  
! $_SP_CONF['version'] = '1.1';
  
  // If you experience timeout issues, you may need to set both of the
  // following values to 0 as they are intensive
  
! //NOTE: using filter_html will render any blank pages useless
  $_SP_CONF['filter_html'] = 0;
  $_SP_CONF['censor'] = 1;
  
  // set to 1 if static pages should be wrapped in a block
! $_SP_CONF['in_block'] = 0;
  
  ?>
--- 1,15 ----
  <?php
  
! $_SP_CONF['version'] = '1.3';
  
  // If you experience timeout issues, you may need to set both of the
  // following values to 0 as they are intensive
  
! // NOTE: using filter_html will render any blank pages useless
  $_SP_CONF['filter_html'] = 0;
  $_SP_CONF['censor'] = 1;
  
  // set to 1 if static pages should be wrapped in a block
! $_SP_CONF['in_block'] = 1;
  
  ?>

Index: functions.inc
===================================================================
RCS file: /usr/cvs/geeklog/geeklog-1.3/plugins/staticpages/functions.inc,v
retrieving revision 1.17
retrieving revision 1.18
diff -C2 -d -r1.17 -r1.18
*** functions.inc	30 Nov 2002 20:42:42 -0000	1.17
--- functions.inc	9 Mar 2003 11:47:22 -0000	1.18
***************
*** 3,17 ****
  /* Reminder: always indent with 4 spaces (no tabs). */
  // +---------------------------------------------------------------------------+
! // | Static Pages Plugin 0.1 for Geeklog - The Ultimate Weblog                 |
  // +---------------------------------------------------------------------------+
  // | functions.inc                                                             |
  // | This file does two things: 1) it implements the necessary Geeklog Plugin  |
  // | API method and 2) implements all the common code needed by the Static     |
  // | Pages' PHP files.                                                         |
- // |                                                                           |
  // +---------------------------------------------------------------------------+
! // | Copyright (C) 2000,2001 by the following authors:                         |
  // |                                                                           |
  // | Authors: Tony Bibbs       - tony at tonybibbs.com                            |
  // +---------------------------------------------------------------------------+
  // |                                                                           |
--- 3,19 ----
  /* Reminder: always indent with 4 spaces (no tabs). */
  // +---------------------------------------------------------------------------+
! // | Static Pages Plugin 1.3 for Geeklog - The Ultimate Weblog                 |
  // +---------------------------------------------------------------------------+
  // | functions.inc                                                             |
+ // |                                                                           |
  // | This file does two things: 1) it implements the necessary Geeklog Plugin  |
  // | API method and 2) implements all the common code needed by the Static     |
  // | Pages' PHP files.                                                         |
  // +---------------------------------------------------------------------------+
! // | Copyright (C) 2000-2003 by the following authors:                         |
  // |                                                                           |
  // | Authors: Tony Bibbs       - tony at tonybibbs.com                            |
+ // |          Tom Willett      - twillett at users.sourceforge.net                |
+ // |          Blaine Lang      - langmail at sympatico.ca                         |
  // +---------------------------------------------------------------------------+
  // |                                                                           |
***************
*** 36,49 ****
  $langfile = $_CONF['path'] . 'plugins/staticpages/language/' . $_CONF['language'] . '.php';
  
! if (file_exists ($langfile)) 
! {
      include ($langfile);
! }
! else 
! {
      include ($_CONF['path'] . 'plugins/staticpages/language/english.php');
  }
  
! include($_CONF['path'] . 'plugins/staticpages/config.php');
  
  // +---------------------------------------------------------------------------+
--- 38,48 ----
  $langfile = $_CONF['path'] . 'plugins/staticpages/language/' . $_CONF['language'] . '.php';
  
! if (file_exists ($langfile)) {
      include ($langfile);
! } else {
      include ($_CONF['path'] . 'plugins/staticpages/language/english.php');
  }
  
! include ($_CONF['path'] . 'plugins/staticpages/config.php');
  
  // +---------------------------------------------------------------------------+
***************
*** 62,71 ****
      global $_CONF, $_TABLES;
  
!     $result = DB_query("SELECT sp_id, sp_label FROM {$_TABLES['staticpage']} WHERE sp_onmenu = 1 ORDER BY sp_label");
!     $nrows = DB_numRows($result);
!     $menuitems = array();
      for ($i = 1; $i <= $nrows; $i++) {
!         $A = DB_fetchArray($result);
!         $menuitems[$A['sp_label']] = COM_buildURL ($_CONF['site_url'] . "/staticpages/index.php?page={$A['sp_id']}");
      }
      return $menuitems;
--- 61,72 ----
      global $_CONF, $_TABLES;
  
!     $result = DB_query ('SELECT sp_id, sp_label, group_id, owner_id, perm_owner, perm_group, perm_members, perm_anon FROM ' . $_TABLES['staticpage'] . ' WHERE sp_onmenu = 1');
!     $nrows = DB_numRows ($result);
!     $menuitems = array ();
      for ($i = 1; $i <= $nrows; $i++) {
!         $A = DB_fetchArray ($result);
!         if (SEC_hasAccess ($A['owner_id'], $A['group_id'], $A['perm_owner'], $A['perm_group'], $A['perm_members'], $A['perm_anon'])) {
!             $menuitems[$A['sp_label']] = COM_buildURL ($_CONF['site_url'] . "/staticpages/index.php?page={$A['sp_id']}");
!     	}
      }
      return $menuitems;
***************
*** 73,80 ****
  
  /**
! * Geeklog is checking to see if this plugin supports comments, tell it no!
! * NOTE: to support comments you must use the same date/time based ID for your
  * widget.  In other words, to make primary keys for your plugin you should call
! * makesid().  Comments are keyed off of that...it is a limitation on how geeklog
  * does comments.
  *
--- 74,82 ----
  
  /**
! * Geeklog is checking to see if this plugin supports comments, tell it no.
! *
! * NOTE: to support comments you must used the same date/time based ID for your
  * widget.  In other words, to make primary keys for your plugin you should call
! * makesid().  Comments are keyed off of that...it is a limitation on how Geeklog
  * does comments.
  *
***************
*** 87,93 ****
  
  /**
! * Shows the statistics for the static pages plugin on stats.php.  If
! * $showsitestats is 1 then we are to only print the overall stats in the 'site
! * statistics' box otherwise we show the detailed stats for the static pages
  *
  * @showsitestate        int         Flag to let us know which stats to get
--- 89,95 ----
  
  /**
! * Shows the statistics for the Static Pages plugin on stats.php.
! * If $showsitestats is 1 then we are to only print the overall stats in the
! * 'site statistics box' otherwise we show the detailed stats
  *
  * @showsitestate        int         Flag to let us know which stats to get
***************
*** 95,99 ****
  function plugin_showstats_staticpages($showsitestats) 
  {
!     // Code to come later
  }
  
--- 97,134 ----
  function plugin_showstats_staticpages($showsitestats) 
  {
!     global $LANG_STATIC, $_CONF, $_TABLES;
! 
!     $stat_templates = new Template ($_CONF['path_layout'] . 'stats');
!     $stat_templates->set_file (array ('itemstats'=>'itemstatistics.thtml',
!                                       'statrow'=>'singlestat.thtml'));
!     if ($showsitestats == 1) {
!         $result = DB_query ("SELECT count(*) AS cnt FROM {$_TABLES['staticpage']} WHERE " . SP_getPerms ());
!         $A = DB_fetchArray ($result);
!         $total_pages = $A['cnt'];
!         $retval = '<table border="0" width="100%" cellspacing="0" cellpadding="0">';
!         $retval .= '<tr><td>' . $LANG_STATIC['staticpages'] . '</td>';
!         $retval .= '<td align="right">' . $total_pages . '  </td></tr></table>';
!     } else {
!         $result = DB_query ("SELECT sp_id,sp_title,sp_hits FROM {$_TABLES['staticpage']} WHERE sp_hits > 0 AND" . SP_getPerms() . ' ORDER BY sp_hits DESC LIMIT 10');
!         $nrows  = DB_numRows ($result);
!         $retval .= COM_startBlock ($LANG_STATIC['stats_headline']);
!         if ($nrows > 0) {
!             $stat_templates->set_var ('item_label', $LANG_STATIC['stats_page_title']);
!             $stat_templates->set_var ('stat_name', $LANG_STATIC['stats_hits']);
!             for ($i = 0; $i < $nrows; $i++) {
!                 $A = DB_fetchArray ($result);
!                 $stat_templates->set_var ('item_url', COM_buildURL ($_CONF['site_url'] . '/staticpages/index.php?page=' . $A['sp_id']));
!                 $stat_templates->set_var ('item_text', stripslashes ($A['sp_title']));
!                 $stat_templates->set_var ('item_stat', $A['sp_hits']);
!                 $stat_templates->parse ('stat_row','statrow',true); 
!             }
!             $stat_templates->parse ('output','itemstats');
!             $retval .= $stat_templates->finish ($stat_templates->get_var ('output'));
!         } else {
!             $retval .= $LANG_STATIC['stats_no_hits'];
!         }	
!         $retval .= COM_endBlock();
!     }
!     return $retval;
  }
  
***************
*** 108,114 ****
--- 143,151 ----
  
      $tmp['staticpages'] = $LANG_STATIC['staticpages'];
+ 
      return $tmp;
  }
  
+ 
  /**
  * this searches for static pages matching the user query and returns an array of
***************
*** 123,135 ****
  * @author           string          Get all results by this author
  *
  */
  function plugin_dopluginsearch_staticpages($query, $datestart, $dateend, $topic, $type, $author) 
  {
! 	global $_TABLES, $_CONF, $LANG_STATIC;
  
      if (empty($type)) {
          $type = 'all';
      }
!     
      // Bail if we aren't supppose to do our search
      if ($type <> 'all' AND $type <> 'staticpages') {
--- 160,173 ----
  * @author           string          Get all results by this author
  *
+ * Oct 05/2002: Blaine Lang, Corrected bug with SQL Search string. 
  */
  function plugin_dopluginsearch_staticpages($query, $datestart, $dateend, $topic, $type, $author) 
  {
!     global $_TABLES, $_CONF, $LANG_STATIC;
  
      if (empty($type)) {
          $type = 'all';
      }
! 
      // Bail if we aren't supppose to do our search
      if ($type <> 'all' AND $type <> 'staticpages') {
***************
*** 140,194 ****
      }
  
!     // Build search SQL
! 	$sql = "SELECT sp_id,sp_content,sp_title,sp_hits,sp_uid,UNIX_TIMESTAMP(sp_date) as day FROM {$_TABLES['staticpage']} WHERE ";
      $sql .= "((sp_content like '%$query%' OR sp_content like '$query%' OR sp_content like '%$query') ";
!     $sql .= "OR (sp_title like '%$query%' OR sp_title like '$query%' OR sp_title like '%$query')) ";
  
!     if (!empty($datestart) && !empty($dateend)) {
!         $delim = substr($datestart, 4, 1);
!         $DS = explode($delim,$datestart);
!         $DE = explode($delim,$dateend);
!         $startdate = mktime(0,0,0,$DS[1],$DS[2],$DS[0]);
!         $enddate = mktime(0,0,0,$DE[1],$DE[2],$DE[0]) + 3600;
!         $sql .= "AND (UNIX_TIMESTAMP(sp_date) BETWEEN '$startdate' AND '$enddate') ";
      }
  
!     if (!empty($author)) {
          $sql .= "AND (sp_uid = '$author') ";
      }
!     $sql    .= "ORDER BY sp_date desc";
  
      // Perform search
!     $result = DB_query($sql);
!     
!     // OK, now return coma delimited string of table header labels
      require_once($_CONF['path_system'] . 'classes/plugin.class.php');
      $plugin_results = new Plugin();
      $plugin_results->plugin_name = 'staticpages';
      $plugin_results->searchlabel = $LANG_STATIC['results'];
!     $plugin_results->addSearchHeading($LANG_STATIC['title']);
!     $plugin_results->addSearchHeading($LANG_STATIC['date']);
!     $plugin_results->addSearchHeading($LANG_STATIC['author']);
!     $plugin_results->addSearchHeading($LANG_STATIC['hits']);
!     $plugin_results->num_searchresults = DB_numRows($result);
  
      // NOTE if any of your data items need to be links then add them here! 
      // make sure data elements are in an array and in the same order as your
      // headings above!
! 	for ($i = 1; $i <= $plugin_results->num_searchresults; $i++) {
!         $A = DB_fetchArray($result);
!         $thetime = COM_getUserDateTimeFormat($A['day']);
!         $A['sp_title'] = stripslashes ($A['sp_title']);
!         $row = array('<a href="' . COM_buildURL ($_CONF['site_url'] . '/staticpages/index.php?page=' . $A['sp_id']) . '">' . $A['sp_title'] . '</a>',
                      $thetime[0],
!                     DB_getItem($_TABLES['users'],'username',"uid = '{$A["sp_uid"]}'"),
                      $A['sp_hits']);
!         $plugin_results->addSearchResult($row);
! 	}
!     $plugin_results->num_itemssearched = DB_count($_TABLES['staticpage']);
  
      return $plugin_results;
  }
  
  /**
  * This will put an option for static pages in the command and control block on
--- 178,238 ----
      }
  
!     // Build search SQL - Modified to exclude static PHP pages from search.
!     $sql = "SELECT *,UNIX_TIMESTAMP(sp_date) as day FROM " . $_TABLES['staticpage'] . " WHERE (sp_php != '1' AND";
      $sql .= "((sp_content like '%$query%' OR sp_content like '$query%' OR sp_content like '%$query') ";
!     $sql .= "OR (sp_title like '%$query%' OR sp_title like '$query%' OR sp_title like '%$query'))";
  
!     if (!empty ($datestart) && !empty ($dateend)) {
!         $delim = substr ($datestart, 4, 1);
!         $DS = explode ($delim, $datestart);
!         $DE = explode ($delim, $dateend);
!         $startdate = mktime (0, 0, 0, $DS[1], $DS[2], $DS[0]);
!         $enddate = mktime (23, 59, 59, $DE[1], $DE[2], $DE[0]);
!         $sql .= " AND (UNIX_TIMESTAMP(sp_date) BETWEEN '$startdate' AND '$enddate')";
      }
  
!     if (!empty ($author)) {
          $sql .= "AND (sp_uid = '$author') ";
      }
!     $sql    .= ") ORDER BY sp_date desc";
  
      // Perform search
!     $result = DB_query ($sql);
! 
!     // OK, now return coma delmited string of table header labels
      require_once($_CONF['path_system'] . 'classes/plugin.class.php');
      $plugin_results = new Plugin();
      $plugin_results->plugin_name = 'staticpages';
      $plugin_results->searchlabel = $LANG_STATIC['results'];
!     $plugin_results->addSearchHeading ($LANG_STATIC['title']);
!     $plugin_results->addSearchHeading ($LANG_STATIC['date']);
!     $plugin_results->addSearchHeading ($LANG_STATIC['author']);
!     $plugin_results->addSearchHeading ($LANG_STATIC['hits']);
!     $mycount = DB_numRows ($result);
  
      // NOTE if any of your data items need to be links then add them here! 
      // make sure data elements are in an array and in the same order as your
      // headings above!
!     for ($i = 1; $i <= $mycount; $i++) {
!         $A = DB_fetchArray ($result);
! 
!         if (SEC_hasAccess ($A['owner_id'], $A['group_id'], $A['perm_owner'], $A['perm_group'], $A['perm_members'], $A['perm_anon'])) {
!             $rcnt++;
!             $thetime = COM_getUserDateTimeFormat ($A['day']);
!             $A['sp_title'] = stripslashes ($A['sp_title']);
!             $row = array ('<a href="' . COM_buildURL ($_CONF['site_url'] . '/staticpages/index.php?page=' . $A['sp_id']) . '">' . $A['sp_title'] . '</a>',
                      $thetime[0],
!                     '<a href="' . $_CONF['site_url'] . '/users.php?mode=profile&uid=' . $A['sp_uid'] . '">' . DB_getItem ($_TABLES['users'], 'username', "uid = '{$A['sp_uid']}'") . '</a>',
                      $A['sp_hits']);
!             $plugin_results->addSearchResult ($row);
!         }
!     }
!     $plugin_results->num_searchresults = $rcnt;
!     $plugin_results->num_itemssearched = DB_count ($_TABLES['staticpage']);
  
      return $plugin_results;
  }
  
+ 
  /**
  * This will put an option for static pages in the command and control block on
***************
*** 200,208 ****
      global $LANG_STATIC, $_CONF;
  
!     if (SEC_hasRights('staticpages.edit,staticpages.delete','OR')) {
!         return array($LANG_STATIC['staticpages'],$_CONF['site_admin_url'] . '/plugins/staticpages/index.php',$_CONF['site_url'] . '/staticpages/images/staticpages.gif');
      }
  
!     return (false);
  }
  
--- 244,254 ----
      global $LANG_STATIC, $_CONF;
  
!     if (SEC_hasRights ('staticpages.edit,staticpages.delete', 'OR')) {
!         return array ($LANG_STATIC['staticpages'],
!                 $_CONF['site_admin_url'] . '/plugins/staticpages/index.php',
!                 $_CONF['site_url'] . '/staticpages/images/staticpages.gif');
      }
  
!     return false;
  }
  
***************
*** 215,224 ****
      global $_CONF, $LANG_STATIC, $_TABLES;
  
!     if (SEC_hasRights('staticpages.edit,staticpages.delete','OR')) {
!         return array($LANG_STATIC[staticpages], $_CONF['site_admin_url'] . '/plugins/staticpages/index.php', DB_count($_TABLES['staticpage']));
      }	
  }
  
  /**
  * Removes the datastructures for this plugin from the Geeklog database
  *
--- 261,317 ----
      global $_CONF, $LANG_STATIC, $_TABLES;
  
!     if (SEC_hasRights ('staticpages.edit,staticpages.delete', 'OR')) {
!         $result = DB_query ("SELECT count(*) AS cnt FROM {$_TABLES['staticpage']} WHERE " . SP_getPerms ('','3'));
!         $A = DB_fetchArray ($result);
!         $total_pages = $A['cnt'];
!         return array ($LANG_STATIC[staticpages], $_CONF['site_admin_url'] . '/plugins/staticpages/index.php', $total_pages);
      }	
  }
  
  /**
+ * Return SQL where statement with appropriate permissions
+ *
+ * Takes User id and permission and returns SQL where clause which will return the appropriate objects.
+ * This assumes that the table has the following security structure:
+ * owner_id        | mediumint(8)          
+ * group_id        | mediumint(8)          
+ * perm_owner      | tinyint(1) unsigned   
+ * perm_group      | tinyint(1) unsigned   
+ * perm_members    | tinyint(1) unsigned  
+ * perm_anon       | tinyint(1) unsigned  
+ * This will work with the standard GL tables
+ *
+ * @table	str	Table name (used in joins)
+ * @access	int	Access if blank read access  2 = read 3 = read/edit
+ * @u_id int     User ID if blank current user
+ *
+ * @return string	Where clause of sql statement
+ *
+ */
+ function SP_getPerms($table='',$access='2',$u_id='')
+ {
+ 	global $_USER, $_GROUPS;
+ 	
+ 	if ($table != '') { $table .= '.'; }
+ 	if ($u_id == '') {
+ 		$uid = $_USER['uid'];
+ 		$GROUPS = $_GROUPS;
+ 	} else {
+ 		$uid = $u_id;
+ 		$GROUPS = SEC_getUserGroups($uid);
+ 	}
+ 	$where = "((" . $table . "perm_anon >= $access)";
+ 	// check to see if anonymous user
+ 	if ($uid > 1) {
+ 		$where .= " OR (" . $table . "perm_members >= $access)";
+ 		foreach ($GROUPS as $group) {
+ 			$where .= " OR ((" . $table . "group_id = $group) AND (" . $table . "perm_group >= $access))";
+ 		}
+ 		$where .= " OR ((" . $table . "owner_id = $uid) AND (" . $table . "perm_owner >= $access))";
+ 	}
+ 	return $where . ")"; 
+ }
+ 
+ /**
  * Removes the datastructures for this plugin from the Geeklog database
  *
***************
*** 245,249 ****
  
      // Remove the static page admin group
!     $grp_id = DB_getItem($_TABLES['vars'], 'value', "name = 'sp_group_id'");
  
      if (empty($steps) OR $steps['insertgroup'] == 1) {
--- 338,342 ----
  
      // Remove the static page admin group
!     $grp_id = DB_getItem($_TABLES['groups'], 'grp_id', "grp_name = 'Static Page Admin'");
  
      if (empty($steps) OR $steps['insertgroup'] == 1) {
***************
*** 256,259 ****
--- 349,353 ----
      $edit_id = DB_getItem($_TABLES['features'], 'ft_id', "ft_name = 'staticpages.edit'");
      $delete_id = DB_getItem($_TABLES['features'], 'ft_id', "ft_name = 'staticpages.delete'");
+     $php_id = DB_getItem($_TABLES['features'], 'ft_id', "ft_name = 'staticpages.PHP'");
  
      if (empty($steps) OR $steps['addededittogroup'] == 1) {
***************
*** 271,274 ****
--- 365,375 ----
      }
  
+     if (empty($steps) OR $steps['addedphptogroup'] == 1) {
+         // Remove access to those features 
+         COM_errorLog('Attempting to remove rights to staticpage.PHP from all groups',1);
+         DB_query("DELETE FROM {$_TABLES['access']} WHERE acc_ft_id = $php_id");
+         COM_errorLog('...success',1);
+     }
+ 
      if (empty($steps) OR $steps['addedrootuserstogroup'] == 1) {
          // Remove root users from the group
***************
*** 290,297 ****
      }
  
!     if (empty($steps) OR $steps['savedgroupid']) {
!         COM_errorLog('Attempting to remove the group id from the vars table',1);
!         DB_query("DELETE FROM {$_TABLES['vars']} WHERE name = 'sp_group_id'");
!         COM_errorLog('success',1);
      }
  
--- 391,398 ----
      }
  
!     if (empty($steps) OR $steps['insertedphpfeature'] == 1) {
!         COM_errorLog('Attempting to remove the staticpage.PHP feature',1);
!         DB_query("DELETE FROM {$_TABLES['features']} WHERE ft_id = $php_id");
!         COM_errorLog('...success',1);
      }
  
***************
*** 301,305 ****
      COM_errorLog('Attempting to unregister the plugin from Geeklog',1);
      DB_query("DELETE FROM {$_TABLES['plugins']} WHERE pi_name = 'staticpages'");
-     DB_query("DELETE FROM {$_TABLES['vars']} WHERE name = 'staticpages'");
      COM_errorLog('...success',1);
  
--- 402,405 ----





More information about the geeklog-cvs mailing list