[ Index ]
 

Code source de GeekLog 1.4.1

Accédez au Source d'autres logiciels libres

title

Body

[fermer]

/plugins/staticpages/ -> functions.inc (source)

   1  <?php
   2  
   3  /* Reminder: always indent with 4 spaces (no tabs). */
   4  // +---------------------------------------------------------------------------+
   5  // | Static Pages Plugin 1.4.3                                                 |
   6  // +---------------------------------------------------------------------------+
   7  // | functions.inc                                                             |
   8  // |                                                                           |
   9  // | This file does two things: 1) it implements the necessary Geeklog Plugin  |
  10  // | API method and 2) implements all the common code needed by the Static     |
  11  // | Pages' PHP files.                                                         |
  12  // +---------------------------------------------------------------------------+
  13  // | Copyright (C) 2000-2006 by the following authors:                         |
  14  // |                                                                           |
  15  // | Authors: Tony Bibbs       - tony AT tonybibbs DOT com                     |
  16  // |          Tom Willett      - twillett AT users DOT sourceforge DOT net     |
  17  // |          Blaine Lang      - langmail AT sympatico DOT ca                  |
  18  // |          Dirk Haun        - dirk AT haun-online DOT de                    |
  19  // +---------------------------------------------------------------------------+
  20  // |                                                                           |
  21  // | This program is free software; you can redistribute it and/or             |
  22  // | modify it under the terms of the GNU General Public License               |
  23  // | as published by the Free Software Foundation; either version 2            |
  24  // | of the License, or (at your option) any later version.                    |
  25  // |                                                                           |
  26  // | This program is distributed in the hope that it will be useful,           |
  27  // | but WITHOUT ANY WARRANTY; without even the implied warranty of            |
  28  // | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the             |
  29  // | GNU General Public License for more details.                              |
  30  // |                                                                           |
  31  // | You should have received a copy of the GNU General Public License         |
  32  // | along with this program; if not, write to the Free Software Foundation,   |
  33  // | Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.           |
  34  // |                                                                           |
  35  // +---------------------------------------------------------------------------+
  36  //
  37  // $Id: functions.inc,v 1.79 2006/11/04 17:54:44 dhaun Exp $
  38  
  39  if (strpos ($_SERVER['PHP_SELF'], 'functions.inc') !== false) {
  40      die ('This file can not be used on its own.');
  41  }
  42  
  43  $langfile = $_CONF['path'] . 'plugins/staticpages/language/'
  44            . $_CONF['language'] . '.php';
  45  
  46  if (file_exists ($langfile)) {
  47      include ($langfile);
  48  } else {
  49      include ($_CONF['path'] . 'plugins/staticpages/language/english.php');
  50  }
  51  
  52  include ($_CONF['path'] . 'plugins/staticpages/config.php');
  53  
  54  // +---------------------------------------------------------------------------+
  55  // | Geeklog Plugin API Implementations                                        |
  56  // +---------------------------------------------------------------------------+
  57  
  58  /**
  59  * Returns the items for this plugin that should appear on the main menu
  60  *
  61  * NOTE: this MUST return the url/value pairs in the following format
  62  * $<arrayname>[<label>] = <url>
  63  *
  64  */
  65  function plugin_getmenuitems_staticpages()
  66  {
  67      global $_CONF, $_TABLES, $_SP_CONF;
  68  
  69      $order = '';
  70      if (!empty ($_SP_CONF['sort_menu_by'])) {
  71          $order = ' ORDER BY ';
  72          if ($_SP_CONF['sort_menu_by'] == 'date') {
  73              $order .= 'sp_date DESC';
  74          } else if ($_SP_CONF['sort_menu_by'] == 'label') {
  75              $order .= 'sp_label';
  76          } else if ($_SP_CONF['sort_menu_by'] == 'title') {
  77              $order .= 'sp_title';
  78          } else { // default to "sort by id"
  79              $order .= 'sp_id';
  80          }
  81      }
  82  
  83      $result = DB_query ('SELECT sp_id, sp_label FROM ' . $_TABLES['staticpage'] . ' WHERE sp_onmenu = 1' . COM_getPermSql ('AND') . $order);
  84      $nrows = DB_numRows ($result);
  85      $menuitems = array ();
  86      for ($i = 0; $i < $nrows; $i++) {
  87          $A = DB_fetchArray ($result);
  88          $menuitems[$A['sp_label']] = COM_buildURL ($_CONF['site_url'] . '/staticpages/index.php?page=' . $A['sp_id']);
  89      }
  90  
  91      return $menuitems;
  92  }
  93  
  94  /**
  95  * Geeklog is checking to see if this plugin supports comments, tell it no.
  96  *
  97  * NOTE: to support comments you must used the same date/time based ID for your
  98  * widget.  In other words, to make primary keys for your plugin you should call
  99  * makesid().  Comments are keyed off of that...it is a limitation on how Geeklog
 100  * does comments.
 101  *
 102  */
 103  function plugin_commentsupport_staticpages()
 104  {
 105      // Static Pages will not use comments
 106      return false;
 107  }
 108  
 109  /**
 110  * Helper function: Count static pages visible to the current user
 111  *
 112  * @return   int     number of pages
 113  *
 114  */
 115  function SP_countVisiblePages ()
 116  {
 117      global $_TABLES;
 118  
 119      $perms = SP_getPerms ();
 120      if (!empty ($perms)) {
 121          $perms = ' WHERE ' . $perms;
 122      }
 123      $result = DB_query ("SELECT COUNT(*) AS cnt FROM {$_TABLES['staticpage']}" . $perms);
 124      $A = DB_fetchArray ($result);
 125  
 126      return $A['cnt'];
 127  }
 128  
 129  /**
 130  * Shows the statistics for the Static Pages plugin on stats.php.
 131  * If $showsitestats is 1 then we are to only print the overall stats in the
 132  * 'site statistics box' otherwise we show the detailed stats
 133  *
 134  * @param    int     showsitestate   Flag to let us know which stats to get
 135  */
 136  function plugin_showstats_staticpages($showsitestats)
 137  {
 138      global $_CONF, $_TABLES, $LANG_STATIC;
 139      $retval = '';
 140  
 141      $perms = SP_getPerms ();
 142      if (!empty ($perms)) {
 143          $perms = ' AND ' . $perms;
 144      }
 145      $result = DB_query ("SELECT sp_id,sp_title,sp_hits FROM {$_TABLES['staticpage']} WHERE sp_hits > 0" . $perms . ' ORDER BY sp_hits DESC LIMIT 10');
 146      $nrows  = DB_numRows ($result);
 147      if ($nrows > 0) {
 148          require_once( $_CONF['path_system'] . 'lib-admin.php' );
 149          $header_arr = array(
 150              array('text' => $LANG_STATIC['stats_page_title'], 'field' => 'sid', 'header_class' => 'stats-header-title'),
 151              array('text' => $LANG_STATIC['stats_hits'], 'field' => 'sp_hits', 'header_class' => 'stats-header-count', 'field_class' => 'stats-list-count'),
 152          );
 153          $data_arr = array();
 154          $text_arr = array('has_menu'     => false,
 155                            'title'        => $LANG_STATIC['stats_headline'],
 156          );
 157          for ($i = 0; $i < $nrows; $i++) {
 158              $A = DB_fetchArray ($result);
 159              $A['sp_title'] = stripslashes ($A['sp_title']);
 160              $A['sid'] = "<a href=\"" . COM_buildUrl ($_CONF['site_url']
 161                        . "/staticpages/index.php?page={$A['sp_id']}"). "\">{$A['sp_title']}</a>";
 162              $A['sp_hits'] = COM_NumberFormat ($A['sp_hits']);
 163              $data_arr[$i] = $A;
 164          }
 165          $retval .= ADMIN_simpleList("", $header_arr, $text_arr, $data_arr);
 166      } else {
 167          $retval .= COM_startBlock ($LANG_STATIC['stats_headline']);
 168          $retval .= $LANG_STATIC['stats_no_hits'];
 169          $retval .= COM_endBlock();
 170      }
 171  
 172      return $retval;
 173  }
 174  
 175  /**
 176  * New stats plugin API function for proper integration with the site stats
 177  *
 178  * @return   array(item text, item count);
 179  *
 180  */
 181  function plugin_statssummary_staticpages ()
 182  {
 183      global $_TABLES, $LANG_STATIC;
 184  
 185      $total_pages = SP_countVisiblePages ();
 186  
 187      return array ($LANG_STATIC['staticpages'], COM_numberFormat ($total_pages));
 188  }
 189  
 190  /**
 191  * Geeklog is asking us to provide any new items that show up in the type
 192  * drop-down on search.php.  Let's let users search static pages!
 193  *
 194  */
 195  function plugin_searchtypes_staticpages()
 196  {
 197      global $LANG_STATIC;
 198  
 199      $tmp['staticpages'] = $LANG_STATIC['staticpages'];
 200  
 201      return $tmp;
 202  }
 203  
 204  
 205  /**
 206  * this searches for static pages matching the user query and returns an array of
 207  * for the header and table rows back to search.php where it will be formated and
 208  * printed
 209  *
 210  * @param    string  $query      Keywords user is looking for
 211  * @param    date    $datestart  Start date to get results for
 212  * @param    date    $dateend    End date to get results for
 213  * @param    string  $topic      The topic they were searching in
 214  * @param    string  $type       Type of items they are searching, or 'all'
 215  * @param    int     $author     Get all results by this author
 216  * @param    string  $keyType    search key type: 'all', 'phrase', 'any'
 217  * @param    int     $page       page number of current search
 218  * @param    int     $perpage    number of results per page
 219  *
 220  */
 221  function plugin_dopluginsearch_staticpages($query, $datestart, $dateend, $topic, $type, $author, $keyType, $page, $perpage)
 222  {
 223      global $_CONF, $_TABLES, $LANG_STATIC;
 224  
 225      if (empty ($type)) {
 226          $type = 'all';
 227      }
 228  
 229      // Bail if we aren't supppose to do our search
 230      if ($type <> 'all' AND $type <> 'staticpages') {
 231          $plugin_results = new Plugin();
 232          $plugin_results->plugin_name = 'staticpages';
 233          $plugin_results->searchlabel = $LANG_STATIC['results'];
 234  
 235          return $plugin_results;
 236      }
 237  
 238      // Build search SQL - exclude static PHP pages from search.
 239      $select = "SELECT u.username,u.fullname,sp.sp_id,sp.sp_title,sp.sp_hits,sp.sp_uid,UNIX_TIMESTAMP(sp.sp_date) AS day";
 240      $sql = " FROM {$_TABLES['staticpage']} AS sp,{$_TABLES['users']} AS u WHERE (sp.sp_uid = u.uid) AND (sp_php <> 1)" . COM_getPermSQL ('AND') . COM_getLangSql ('sp_id', 'AND', 'sp');
 241  
 242      if (!empty ($query)) {
 243          if ($keyType == 'phrase') {
 244              $mysearchterm = addslashes ($query);
 245              $sql .= " AND ((sp_content LIKE '%$mysearchterm%')"
 246                   . " OR (sp_title LIKE '%$mysearchterm%'))";
 247          } else if ($keyType == 'all') {
 248              $mywords = explode (' ', $query);
 249              $sql .= ' AND (';
 250              $tmp = '';
 251              foreach ($mywords AS $mysearchterm) {
 252                  $mysearchterm = addslashes (trim ($mysearchterm));
 253                  if (!empty ($mysearchterm)) {
 254                      $tmp .= "(sp_content LIKE '%$mysearchterm%')"
 255                           . " OR (sp_title LIKE '%$mysearchterm%') AND ";
 256                  }
 257              }
 258              $tmp = substr ($tmp, 0, strlen ($tmp) - 5);
 259              $sql .= $tmp . ')';
 260          } else if ($keyType == 'any') {
 261              $mywords = explode (' ', $query);
 262              $sql .= ' AND (';
 263              $tmp = '';
 264              foreach ($mywords AS $mysearchterm) {
 265                  $mysearchterm = addslashes (trim ($mysearchterm));
 266                  if (!empty ($mysearchterm)) {
 267                      $tmp .= "(sp_content LIKE '%$mysearchterm%')"
 268                           . " OR (sp_title LIKE '%$mysearchterm%') OR ";
 269                  }
 270              }
 271              $tmp = substr ($tmp, 0, strlen ($tmp) - 4);
 272              $sql .= $tmp . ')';
 273          } else {
 274              $mysearchterm = addslashes ($query);
 275              $sql .= " AND ((sp_content LIKE '%$mysearchterm%')"
 276                   . " OR (sp_title LIKE '%$mysearchterm%'))";
 277          }
 278      }
 279  
 280      if (!empty ($datestart) && !empty ($dateend)) {
 281          $delim = substr ($datestart, 4, 1);
 282          if (!empty($delim)) {
 283              $DS = explode ($delim, $datestart);
 284              $DE = explode ($delim, $dateend);
 285              $startdate = mktime (0, 0, 0, $DS[1], $DS[2], $DS[0]);
 286              $enddate = mktime (23, 59, 59, $DE[1], $DE[2], $DE[0]);
 287              $sql .= " AND (UNIX_TIMESTAMP(sp_date) BETWEEN '$startdate' AND '$enddate')";
 288          }
 289      }
 290  
 291      if (!empty ($author)) {
 292          $sql .= "AND (sp_uid = '$author')";
 293      }
 294      $sql    .= " GROUP BY sp_date, u.username, u.fullname, sp.sp_id, sp.sp_title, sp.sp_hits, sp.sp_uid ORDER BY sp_date DESC ";
 295      $l = ($perpage * $page) - $perpage;
 296      $sql .= 'LIMIT ' . $l . ',' . $perpage;
 297  
 298      // Perform search
 299      $result = DB_query ($select . $sql);
 300      $mycount = DB_numRows ($result);
 301      $result_count = DB_query ('SELECT COUNT(*)' . $sql);
 302      $B = DB_fetchArray ($result_count, true);
 303  
 304      // OK, now return table header labels
 305      $plugin_results = new Plugin();
 306      $plugin_results->plugin_name = 'staticpages';
 307      $plugin_results->searchlabel = $LANG_STATIC['results'];
 308      $plugin_results->addSearchHeading ($LANG_STATIC['title']);
 309      $plugin_results->addSearchHeading ($LANG_STATIC['date']);
 310      $plugin_results->addSearchHeading ($LANG_STATIC['author']);
 311      $plugin_results->addSearchHeading ($LANG_STATIC['hits']);
 312      $plugin_results->num_searchresults = 0;
 313      $plugin_results->num_itemssearched = $B[0];
 314      $plugin_results->supports_paging = true;
 315  
 316      // NOTE if any of your data items need to be links then add them here!
 317      // make sure data elements are in an array and in the same order as your
 318      // headings above!
 319      for ($i = 0; $i < $mycount; $i++) {
 320          $A = DB_fetchArray ($result);
 321  
 322          $thetime = COM_getUserDateTimeFormat ($A['day']);
 323          $A['sp_title'] = stripslashes ($A['sp_title']);
 324          $pageurl = COM_buildURL ($_CONF['site_url']
 325                          . '/staticpages/index.php?page=' . $A['sp_id']);
 326          if (isset ($_CONF['show_fullname']) && ($_CONF['show_fullname'] == 1) &&
 327                  !empty ($A['fullname'])) {
 328              $author = $A['fullname'];
 329          } else {
 330              $author = $A['username'];
 331          }
 332          $profile = $_CONF['site_url'] . '/users.php?mode=profile&amp;uid='
 333                   . $A['sp_uid'];
 334          $row = array ('<a href="' . $pageurl . '">' . $A['sp_title'] . '</a>',
 335                        $thetime[0],
 336                        '<a href="' . $profile . '">' . $author . '</a>',
 337                        COM_NumberFormat ($A['sp_hits']));
 338          $plugin_results->addSearchResult ($row);
 339          $plugin_results->num_searchresults++;
 340      }
 341  
 342      return $plugin_results;
 343  }
 344  
 345  
 346  /**
 347  * This will put an option for static pages in the command and control block on
 348  * moderation.php
 349  *
 350  */
 351  function plugin_cclabel_staticpages()
 352  {
 353      global $LANG_STATIC, $_CONF;
 354  
 355      if (SEC_hasRights ('staticpages.edit,staticpages.delete', 'OR')) {
 356          return array ($LANG_STATIC['staticpages'],
 357                  $_CONF['site_admin_url'] . '/plugins/staticpages/index.php',
 358                  plugin_geticon_staticpages ());
 359      }
 360  
 361      return false;
 362  }
 363  
 364  /**
 365  * returns the administrative option for this plugin
 366  *
 367  */
 368  function plugin_getadminoption_staticpages()
 369  {
 370      global $_CONF, $_TABLES, $LANG_STATIC;
 371  
 372      if (SEC_hasRights ('staticpages.edit,staticpages.delete', 'OR')) {
 373          $result = DB_query ("SELECT count(*) AS cnt FROM {$_TABLES['staticpage']}" . COM_getPermSQL ('WHERE', 0, 3));
 374          $A = DB_fetchArray ($result);
 375          $total_pages = $A['cnt'];
 376          return array ($LANG_STATIC['staticpages'], $_CONF['site_admin_url'] . '/plugins/staticpages/index.php', $total_pages);
 377      }
 378  }
 379  
 380  /**
 381  * Return SQL where statement with appropriate permissions
 382  *
 383  * Takes User id and permission and returns SQL where clause which will return
 384  * the appropriate objects.
 385  * This assumes that the table has the following security structure:
 386  * owner_id        | mediumint(8)
 387  * group_id        | mediumint(8)
 388  * perm_owner      | tinyint(1) unsigned
 389  * perm_group      | tinyint(1) unsigned
 390  * perm_members    | tinyint(1) unsigned
 391  * perm_anon       | tinyint(1) unsigned
 392  * This will work with the standard GL tables
 393  *
 394  * @param    string  $table  Table name (used in joins)
 395  * @param    int     $access Access if blank read access  2 = read 3 = read/edit
 396  * @param    int     $u_id   User ID if blank current user
 397  * @return   string          Where clause of sql statement
 398  *
 399  */
 400  function SP_getPerms ($table = '', $access = '2', $u_id = '')
 401  {
 402      global $_USER, $_GROUPS;
 403  
 404      if ($table != '') { $table .= '.'; }
 405  
 406      if ($u_id == '') {
 407          if (isset ($_USER['uid'])) {
 408              $uid = $_USER['uid'];
 409          } else {
 410              $uid = 1;
 411          }
 412          $GROUPS = $_GROUPS;
 413      } else {
 414          $uid = $u_id;
 415          $GROUPS = SEC_getUserGroups ($uid);
 416      }
 417  
 418      $sql = '(';
 419  
 420      if ($uid > 1) {
 421          $sql .= "((owner_id = '{$uid}') AND (perm_owner >= $access)) OR ";
 422  
 423          $sql .= "((group_id IN (" . implode (',', $GROUPS) . ")) "
 424               . "AND (perm_group >= $access)) OR (perm_members >= $access)";
 425      } else {
 426          $sql .= "perm_anon >= $access";
 427      }
 428  
 429      $sql .= ')';
 430  
 431      return $sql;
 432  }
 433  
 434  /**
 435  * Display static pages in the center block.
 436  *
 437  * @param   where   int      where the static page will be displayed (0..3)
 438  * @param   page    int      page number
 439  * @param   topic   string   topic ID
 440  * @return          string   HTML for the static page (can be empty)
 441  */
 442  function plugin_centerblock_staticpages ($where = 1, $page = 1, $topic ='')
 443  {
 444      global $_CONF, $_TABLES, $_SP_CONF, $LANG_STATIC;
 445  
 446      $retval = '';
 447  
 448      if ($page > 1) {
 449          return $retval; // we only support page 1 at the moment ...
 450      }
 451  
 452      $moresql = "(sp_where = $where) AND ";
 453      $displayFeatured = false;
 454  
 455      // If there are no featured stories, we won't be called with $where == 2.
 456      // So, if asked to display pages for the top of the page, check if we
 457      // have pages to be displayed after the featured story and if there is
 458      // no featured story, display those pages as well.
 459      if (($where == 1) && ($_CONF['showfirstasfeatured'] == 0)) {
 460          if (DB_count ($_TABLES['stories'], 'featured', 1) == 0) {
 461              // no featured story found - redefine $moresql
 462              $moresql = "(sp_where = 1 OR sp_where = 2) AND ";
 463              $displayFeatured = true;
 464          }
 465      }
 466  
 467      if (empty ($topic)) {
 468          $moresql .= "((sp_tid = 'none') OR (sp_tid = 'all'))";
 469      } else {
 470          $moresql .= "((sp_tid = '{$topic}') OR (sp_tid = 'all'))";
 471      }
 472  
 473      if ($_SP_CONF['sort_by'] == 'date') {
 474          $sort = 'sp_date DESC';
 475      } else if ($_SP_CONF['sort_by'] == 'title') {
 476          $sort = 'sp_title';
 477      } else { // default to "sort by id"
 478          $sort = 'sp_id';
 479      }
 480      if ($displayFeatured) {
 481          $sort = 'sp_where,' . $sort;
 482      }
 483  
 484      $perms = SP_getPerms ();
 485      if (!empty ($perms)) {
 486          $perms = ' AND ' . $perms;
 487      }
 488      $spsql = "SELECT sp_id,sp_title,sp_content,sp_format,owner_id,group_id,perm_owner,perm_group,perm_members,perm_anon,sp_php,sp_inblock,sp_help FROM {$_TABLES['staticpage']} WHERE (sp_centerblock = 1)" . COM_getLangSql ('sp_id', 'AND') . ' AND ' . $moresql . $perms . " ORDER BY " . $sort;
 489      $result = DB_query ($spsql);
 490  
 491      $pages = DB_numRows ($result);
 492      if ($pages > 0) {
 493          for ($i = 0; $i < $pages; $i++) {
 494              $spresult = DB_fetchArray ($result);
 495  
 496              if ($where == 0) {
 497                  switch ($spresult['sp_format']) {
 498                      case 'noblocks':
 499                          $retval .= COM_siteHeader ('none');
 500                          break;
 501                      case 'allblocks':
 502                      case 'leftblocks':
 503                          $retval .= COM_siteHeader ('menu');
 504                          break;
 505                  }
 506                  $retval .= COM_showMessage ($_GET['msg']);
 507              }
 508  
 509              if (($spresult['sp_inblock'] == 1) && !empty ($spresult['sp_title'])
 510                  && (($where != 0) || ($spresult['sp_format'] != 'blankpage'))) {
 511                  $retval .= COM_startBlock ($spresult['sp_title'], $spresult['sp_help'],
 512                      COM_getBlockTemplate ('_staticpages_centerblock', 'header'));
 513              }
 514  
 515              $retval .= SP_render_content (stripslashes ($spresult['sp_content']), $spresult['sp_php']);
 516  
 517              if ((SEC_hasAccess ($spresult['owner_id'], $spresult['group_id'], $spresult['perm_owner'],
 518                  $spresult['perm_group'], $spresult['perm_members'], $spresult['perm_anon']) == 3) &&
 519                  SEC_hasRights ('staticpages.edit')) {
 520                  $retval .= '<p align="center"><a href="' . $_CONF['site_admin_url']
 521                          . '/plugins/staticpages/index.php?mode=edit&amp;sp_id='
 522                          . $spresult['sp_id'] . '">';
 523                  $retval .= $LANG_STATIC['edit'] . '</a></p>';
 524              }
 525  
 526              if (($spresult['sp_inblock'] == 1) && !empty ($spresult['sp_title'])
 527                  && (($where != 0) || ($spresult['sp_format'] != 'blankpage'))) {
 528                  $retval .= COM_endBlock (COM_getBlockTemplate ('_staticpages_centerblock', 'footer'));
 529              }
 530  
 531              if ($where == 0) {
 532                  if ($spresult['sp_format'] == 'allblocks') {
 533                      $retval .= COM_siteFooter (true);
 534                  } else if ($spresult['sp_format'] != 'blankpage') {
 535                      $retval .= COM_siteFooter ();
 536                  }
 537              }
 538  
 539              // increment hit counter for page
 540              DB_query ("UPDATE {$_TABLES['staticpage']} SET sp_hits = sp_hits + 1 WHERE sp_id = '{$spresult['sp_id']}'");
 541          }
 542      }
 543  
 544      return $retval;
 545  }
 546  
 547  /**
 548  * A user is about to be deleted. Update ownership of any static pages owned
 549  * by that user or delete them.
 550  *
 551  * @param   uid   int   User id of deleted user
 552  *
 553  */
 554  function plugin_user_delete_staticpages($uid)
 555  {
 556      global $_TABLES, $_SP_CONF;
 557  
 558      if (DB_count ($_TABLES['staticpage'], 'sp_uid', $uid) +
 559              DB_count ($_TABLES['staticpage'], 'owner_id', $uid) == 0) {
 560          return;
 561      }
 562  
 563      if ($_SP_CONF['delete_pages'] == 1) {
 564          // delete the pages
 565          DB_query ("DELETE FROM {$_TABLES['staticpage']} WHERE (sp_uid = $uid) OR (owner_id = $uid)");
 566      } else {
 567          // assign ownership to a user from the Root group
 568          $rootgroup = DB_getItem ($_TABLES['groups'], 'grp_id',
 569                                   "grp_name = 'Root'");
 570          $result = DB_query ("SELECT DISTINCT ug_uid FROM {$_TABLES['group_assignments']} WHERE ug_main_grp_id = $rootgroup ORDER BY ug_uid LIMIT 1");
 571          $A = DB_fetchArray ($result);
 572          $rootuser = $A['ug_uid'];
 573  
 574          DB_query ("UPDATE {$_TABLES['staticpage']} SET sp_uid = $rootuser WHERE sp_uid = $uid");
 575          DB_query ("UPDATE {$_TABLES['staticpage']} SET owner_id = $rootuser WHERE owner_id = $uid");
 576      }
 577  }
 578  
 579  
 580  /**
 581  * Return the current version of code.
 582  * Used in the Plugin Editor to show the registered version and code version
 583  */
 584  function plugin_chkVersion_staticpages()
 585  {
 586      global $_SP_CONF;
 587  
 588      return $_SP_CONF['version'];
 589  }
 590  
 591  /**
 592  * Implements the [staticpage:] autotag.
 593  *
 594  */
 595  function plugin_autotags_staticpages ($op, $content = '', $autotag = '')
 596  {
 597      global $_CONF, $_TABLES;
 598  
 599      if ($op == 'tagname' ) {
 600          return 'staticpage';
 601      } else if ($op == 'parse') {
 602          $sp_id = COM_applyFilter ($autotag['parm1']);
 603          $url = COM_buildUrl ($_CONF['site_url'] . '/staticpages/index.php?page='
 604                               . $sp_id);
 605          if (empty ($autotag['parm2'])) {
 606              $linktext = stripslashes (DB_getItem ($_TABLES['staticpage'],
 607                                        'sp_title', "sp_id = '$sp_id'"));
 608          } else {
 609              $linktext = $autotag['parm2'];
 610          }
 611          $link = '<a href="' . $url . '">' . $linktext . '</a>';
 612          $content = str_replace ($autotag['tagstr'], $link, $content);
 613  
 614          return $content;
 615      }
 616  }
 617  
 618  /**
 619  * Returns the URL of the plugin's icon
 620  *
 621  * @return   string      URL of the icon
 622  *
 623  */
 624  function plugin_geticon_staticpages ()
 625  {
 626      global $_CONF;
 627  
 628      return $_CONF['site_url'] . '/staticpages/images/staticpages.png';
 629  }
 630  
 631  /**
 632  * Update the Static Pages plugin
 633  *
 634  * @return   int     Number of message to display (true = generic success msg)
 635  *
 636  */
 637  function plugin_upgrade_staticpages ()
 638  {
 639      global $_TABLES, $_SP_CONF;
 640  
 641      // the plugin needs this function so complain when it doesn't exist
 642      if (!function_exists ('SEC_getGroupDropdown')) {
 643          return 3002;
 644      }
 645  
 646      // no db changes - just update the version number
 647      DB_query ("UPDATE {$_TABLES['plugins']} SET pi_version = '{$_SP_CONF['version']}' WHERE pi_name = 'staticpages'");
 648  
 649      return true;
 650  }
 651  
 652  /**
 653  * Removes the data structures for this plugin from the Geeklog database
 654  *
 655  * This may get called by the install routine to undo anything done to this
 656  * point.  To do that, $steps will have a list of steps to undo
 657  *
 658  * @steps   Array    Holds all the steps that have been completed by the install
 659  *
 660  */
 661  function plugin_uninstall_staticpages($steps = '')
 662  {
 663      global $_TABLES;
 664  
 665      // Uninstalls the static pages plugin
 666  
 667      if (empty($steps) OR $steps['createtable'] == 1) {
 668          // Remove the staticpage table
 669          COM_errorLog('Dropping staticpage table',1);
 670          DB_query("DROP TABLE {$_TABLES['staticpage']}");
 671          COM_errorLog('...success',1);
 672      }
 673  
 674      // Remove security for this plugin
 675  
 676      // Remove the static page admin group
 677      $grp_id = DB_getItem($_TABLES['groups'], 'grp_id', "grp_name = 'Static Page Admin'");
 678  
 679      if (empty($steps) OR $steps['insertgroup'] == 1) {
 680          COM_errorLog('Attempting to remove the Static Page Admin Group', 1);
 681          DB_query("DELETE FROM {$_TABLES['groups']} WHERE grp_id = $grp_id");
 682          COM_errorLog('...success',1);
 683      }
 684  
 685      // Remove related features
 686      $edit_id = DB_getItem($_TABLES['features'], 'ft_id', "ft_name = 'staticpages.edit'");
 687      $delete_id = DB_getItem($_TABLES['features'], 'ft_id', "ft_name = 'staticpages.delete'");
 688      $php_id = DB_getItem($_TABLES['features'], 'ft_id', "ft_name = 'staticpages.PHP'");
 689  
 690      if (empty($steps) OR $steps['addededittogroup'] == 1) {
 691          // Remove access to those features
 692          COM_errorLog('Attempting to remove rights to staticpage.edit from all groups',1);
 693          DB_query("DELETE FROM {$_TABLES['access']} WHERE acc_ft_id = $edit_id");
 694          COM_errorLog('...success',1);
 695      }
 696  
 697      if (empty($steps) OR $steps['addeddeletetogroup'] == 1) {
 698          // Remove access to those features
 699          COM_errorLog('Attempting to remove rights to staticpage.delete from all groups',1);
 700          DB_query("DELETE FROM {$_TABLES['access']} WHERE acc_ft_id = $delete_id");
 701          COM_errorLog('...success',1);
 702      }
 703  
 704      if (empty($steps) OR $steps['addedphptogroup'] == 1) {
 705          // Remove access to those features
 706          COM_errorLog('Attempting to remove rights to staticpage.PHP from all groups',1);
 707          DB_query("DELETE FROM {$_TABLES['access']} WHERE acc_ft_id = $php_id");
 708          COM_errorLog('...success',1);
 709      }
 710  
 711      if (empty($steps) OR $steps['addedrootuserstogroup'] == 1) {
 712          // Remove root users from the group
 713          COM_errorLog('Attempting to remove root users from admin of static pages');
 714          DB_query("DELETE FROM {$_TABLES['group_assignments']} WHERE ug_main_grp_id = $grp_id");
 715          COM_errorLog('...success',1);
 716      }
 717  
 718      if (empty($steps) OR $steps['insertedfeatureedit'] == 1) {
 719          COM_errorLog('Attempting to remove the staticpage.edit feature',1);
 720          DB_query("DELETE FROM {$_TABLES['features']} WHERE ft_id = $edit_id");
 721          COM_errorLog('...success',1);
 722      }
 723  
 724      if (empty($steps) OR $steps['insertedfeaturedelete'] == 1) {
 725          COM_errorLog('Attempting to remove the staticpage.delete feature',1);
 726          DB_query("DELETE FROM {$_TABLES['features']} WHERE ft_id = $delete_id");
 727          COM_errorLog('...success',1);
 728      }
 729  
 730      if (empty($steps) OR $steps['insertedphpfeature'] == 1) {
 731          COM_errorLog('Attempting to remove the staticpage.PHP feature',1);
 732          DB_query("DELETE FROM {$_TABLES['features']} WHERE ft_id = $php_id");
 733          COM_errorLog('...success',1);
 734      }
 735  
 736      // Unregister the plugin with Geeklog
 737      // Always attempt to remove these entries or lib-common.php would still
 738      // try and read our functions.inc file ...
 739      COM_errorLog('Attempting to unregister the plugin from Geeklog',1);
 740      DB_query("DELETE FROM {$_TABLES['plugins']} WHERE pi_name = 'staticpages'");
 741      COM_errorLog('...success',1);
 742  
 743      COM_errorLog('leaving plugin_uninstall_staticpages',1);
 744  
 745      return true;
 746  }
 747  
 748  /**
 749  * Get path for the template files.
 750  *
 751  * @param    string  $path   subdirectory within the base template path
 752  * @return   string          full path to template directory
 753  *
 754  */
 755  function staticpages_templatePath ($path = '')
 756  {
 757      global $_CONF;
 758  
 759      if (empty ($path)) {
 760          $layout_path = $_CONF['path_layout'] . 'staticpages';
 761      } else {
 762          $layout_path = $_CONF['path_layout'] . 'staticpages/' . $path;
 763      }
 764  
 765      if (is_dir ($layout_path)) {
 766          $retval = $layout_path;
 767      } else {
 768          $retval = $_CONF['path'] . 'plugins/staticpages/templates';
 769          if (!empty ($path)) {
 770              $retval .= '/' . $path;
 771          }
 772      }
 773  
 774      return $retval;
 775  }
 776  
 777  function plugin_getListField_staticpages($fieldname, $fieldvalue, $A, $icon_arr)
 778  {
 779      global $_CONF, $LANG_ADMIN, $LANG_STATIC, $_TABLES;
 780  
 781      switch($fieldname) {
 782          case "edit":
 783              $retval = "<a href=\"{$_CONF['site_admin_url']}/plugins/staticpages/index.php?mode=edit&amp;sp_id={$A['sp_id']}\">{$icon_arr['edit']}</a>";
 784              break;
 785          case "copy":
 786              $retval = "<a href=\"{$_CONF['site_admin_url']}/plugins/staticpages/index.php?mode=clone&amp;sp_id={$A['sp_id']}\">{$icon_arr['copy']}</a>";
 787              break;
 788          case "sp_title":
 789              $sp_title = stripslashes ($A['sp_title']);
 790              $url = COM_buildUrl ($_CONF['site_url'] .
 791                                   '/staticpages/index.php?page=' . $A['sp_id']);
 792              $retval = '<a href="' . $url . '" title="'
 793                      . $LANG_STATIC['title_display'] . '">' . $sp_title . '</a>';
 794              break;
 795          case "sp_uid":
 796              $retval = COM_getDisplayName ($A['sp_uid']);
 797              break;
 798          case "sp_centerblock":
 799              if ($A['sp_centerblock']) {
 800                  switch ($A['sp_where']) {
 801                      case '1': $where = $LANG_STATIC['centerblock_top']; break;
 802                      case '2': $where = $LANG_STATIC['centerblock_feat']; break;
 803                      case '3': $where = $LANG_STATIC['centerblock_bottom']; break;
 804                      default:  $where = $LANG_STATIC['centerblock_entire']; break;
 805                  }
 806                  $retval = $where;
 807              } else {
 808                  $retval = $LANG_STATIC['centerblock_no'];
 809              }
 810              break;
 811          case "unixdate":
 812              $retval = strftime ($_CONF['daytime'], $A['unixdate']);
 813              break;
 814          default:
 815              $retval = $fieldvalue;
 816              break;
 817      }
 818      return $retval;
 819  }
 820  
 821  /**
 822  * Render the actual content of a static page (without any surrounding blocks)
 823  *
 824  * @param    string  $sp_content the content (HTML or PHP source)
 825  * @param    int     $sp_php     flag: 1 = content is PHP source, 0 = is HTML
 826  * @return   string              rendered content (HTML)
 827  *
 828  */
 829  function SP_render_content ($sp_content, $sp_php)
 830  {
 831      global $_SP_CONF, $LANG_STATIC;
 832  
 833      $retval = '';
 834  
 835      if ($_SP_CONF['allow_php'] == 1) {
 836          // Check for type (ie html or php)
 837          if ($sp_php == 1) {
 838              $retval .= eval ($sp_content);
 839          } else if ($sp_php == 2) {
 840              ob_start ();
 841              eval ($sp_content);
 842              $retval .= ob_get_contents ();
 843              ob_end_clean ();
 844          } else {
 845              $retval .= PLG_replacetags ($sp_content);
 846          }
 847      } else {
 848          if ($sp_php != 0) {
 849              COM_errorLog ("PHP in static pages is disabled. Can not display page '$page'.", 1);
 850              $retval .= $LANG_STATIC['deny_msg'];
 851          } else {
 852              $retval .= PLG_replacetags ($sp_content);
 853          }
 854      }
 855  
 856      return $retval;
 857  }
 858  
 859  ?>


Généré le : Wed Nov 21 12:27:40 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics