[ Index ]
 

Code source de GeekLog 1.4.1

Accédez au Source d'autres logiciels libres

title

Body

[fermer]

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

   1  <?php
   2  
   3  // Reminder: always indent with 4 spaces (no tabs).
   4  // +---------------------------------------------------------------------------+
   5  // | Links Plugin 1.0.1  functions.inc                                         |
   6  // +---------------------------------------------------------------------------+
   7  // |                                                                           |
   8  // | This program is free software; you can redistribute it and/or             |
   9  // | modify it under the terms of the GNU General Public License               |
  10  // | as published by the Free Software Foundation; either version 2            |
  11  // | of the License, or (at your option) any later version.                    |
  12  // |                                                                           |
  13  // | This program is distributed in the hope that it will be useful,           |
  14  // | but WITHOUT ANY WARRANTY; without even the implied warranty of            |
  15  // | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the             |
  16  // | GNU General Public License for more details.                              |
  17  // |                                                                           |
  18  // | You should have received a copy of the GNU General Public License         |
  19  // | along with this program; if not, write to the Free Software Foundation,   |
  20  // | Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.           |
  21  // |                                                                           |
  22  // +---------------------------------------------------------------------------+
  23  //
  24  // $Id: functions.inc,v 1.71 2006/12/18 06:45:37 ospiess Exp $
  25  
  26  
  27  /**
  28   * This file does two things: 1) it implements the necessary Geeklog Plugin
  29   * API method and 2) implements all the common code needed by the links
  30   * Plugins' PHP files.
  31   *
  32   * @package Links
  33   * @filesource
  34   * @version 1.0.1
  35   * @since GL 1.4.0
  36   * @copyright Copyright &copy; 2005-2006
  37   * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  38   * @author Trinity Bays <trinity93 AT steubentech DOT com>
  39   * @author Tony Bibbs <tony AT tonybibbs DOT com>
  40   * @author Tom Willett <tom AT pigstye DOT net>
  41   * @author Blaine Lang <langmail AT sympatico DOT ca>
  42   * @author Dirk Haun <dirk AT haun-online DOT de>
  43   *
  44   */
  45  
  46  
  47  if (strpos ($_SERVER['PHP_SELF'], 'functions.inc') !== false) {
  48      die ('This file can not be used on its own.');
  49  }
  50  
  51  $langfile = $_CONF['path'] . 'plugins/links/language/'
  52            . $_CONF['language'] . '.php';
  53  
  54  if (file_exists ($langfile)) {
  55      require_once ($langfile);
  56  } else {
  57      require_once ($_CONF['path'] . 'plugins/links/language/english.php');
  58  }
  59  
  60  require_once ($_CONF['path'] . 'plugins/links/config.php');
  61  
  62  // +---------------------------------------------------------------------------+
  63  // | Geeklog Plugin API Implementation                                         |
  64  // +---------------------------------------------------------------------------+
  65  
  66  /**
  67  * Returns the items for this plugin that should appear on the main menu
  68  *
  69  * NOTE: this MUST return the url/value pairs in the following format
  70  * $<arrayname>[<label>] = <url>
  71  *
  72  * @return   mixed   menu entry, or boolean false if disabled / hidden
  73  *
  74  */
  75  function plugin_getmenuitems_links()
  76  {
  77      global $_CONF, $_USER, $_LI_CONF, $LANG_LINKS;
  78  
  79      $anon = (empty ($_USER['uid']) || ($_USER['uid'] <= 1)) ? true : false;
  80      if (($_LI_CONF['hidelinksmenu'] == 1) || ($anon &&
  81                  ($_CONF['loginrequired'] || $_LI_CONF['linksloginrequired']))) {
  82          return false;
  83      }
  84  
  85      $menuitems[$LANG_LINKS[114]] = $_CONF['site_url'] . '/links/index.php';
  86  
  87      return $menuitems;
  88  }
  89  
  90  /**
  91  * Return headlines for New Links section in the What's New block, if enabled
  92  *
  93  * @return   mixed       array(headline, byline), or boolean false is disabled
  94  *
  95  */
  96  function plugin_whatsnewsupported_links()
  97  {
  98      global $_TABLES, $_LI_CONF, $LANG_LINKS, $LANG_WHATSNEW;
  99  
 100      if ( $_LI_CONF['hidenewlinks'] == 0 ) {
 101          $retval = array( $LANG_LINKS[84],
 102                           COM_formatTimeString( $LANG_WHATSNEW['new_last'],
 103                                                 $_LI_CONF['newlinksinterval'] )
 104                         );
 105      } else {
 106          $retval = false;
 107      }
 108  
 109      return $retval;
 110  }
 111  
 112  /**
 113  * Return new links for the What's New block
 114  *
 115  * @return   string  HTML list of new links
 116  *
 117  */
 118  function plugin_getwhatsnew_links()
 119  {
 120      global $_CONF, $_TABLES, $_USER, $_LI_CONF, $LANG_LINKS;
 121  
 122      $retval = '';
 123  
 124      // Get newest links
 125      $sql = "SELECT lid,title FROM {$_TABLES['links']} WHERE (date >= (DATE_SUB(NOW(), INTERVAL {$_LI_CONF['newlinksinterval']} SECOND)))" . COM_getPermSQL( 'AND' ) . ' ORDER BY date DESC LIMIT 15';
 126      $result = DB_query( $sql );
 127      $nrows = DB_numRows( $result );
 128  
 129      if( $nrows > 0 )
 130      {
 131          $newlinks = array();
 132          for( $x = 0; $x < $nrows; $x++ )
 133          {
 134              $A = DB_fetchArray( $result );
 135              $A['title'] = stripslashes( $A['title'] );
 136  
 137              // redirect link via portal.php so we can count the clicks
 138              $lcount = COM_buildUrl( $_CONF['site_url']
 139                      . '/links/portal.php?what=link&amp;item=' . $A['lid'] );
 140  
 141              $title = COM_truncate( $A['title'], $_CONF['title_trim_length'],
 142                                     '...' );
 143              if( $title != $A['title'] )
 144              {
 145                  $newlinks[] = '<a href="' . $lcount . '" title="'
 146                              . $A['title'] . '">' . $title . '</a>' . LB;
 147              }
 148              else
 149              {
 150                  $newlinks[] = '<a href="' . $lcount . '">' . $A['title']
 151                              . '</a>' . LB;
 152              }
 153          }
 154  
 155          $retval .= COM_makeList( $newlinks, 'list-new-plugins' );
 156      }
 157      else
 158      {
 159          $retval .= $LANG_LINKS[88] . '<br>' . LB;
 160      }
 161  
 162      return $retval;
 163  }
 164  
 165  /**
 166  * Implements the [link:] autotag.
 167  *
 168  * @param    string  $op         operation to perform
 169  * @param    string  $content    item (e.g. story text), including the autotag
 170  * @param    array   $autotag    parameters used in the autotag
 171  * @param    mixed               tag names (for $op='tagname') or formatted content
 172  *
 173  */
 174  function plugin_autotags_links ($op, $content = '', $autotag = '')
 175  {
 176      global $_CONF, $_TABLES;
 177  
 178      if ($op == 'tagname' ) {
 179          return 'link';
 180      } else if ($op == 'parse') {
 181          $lid = COM_applyFilter ($autotag['parm1']);
 182          $url = COM_buildUrl ($_CONF['site_url']
 183                               . '/links/portal.php?what=link&item=' . $lid);
 184          if (empty ($autotag['parm2'])) {
 185              $linktext = stripslashes (DB_getItem ($_TABLES['links'],
 186                                        'title', "lid = '$lid'"));
 187          } else {
 188              $linktext = $autotag['parm2'];
 189          }
 190          $link = '<a href="' . $url . '">' . $linktext . '</a>';
 191          $content = str_replace ($autotag['tagstr'], $link, $content);
 192  
 193          return $content;
 194      }
 195  }
 196  
 197  /**
 198  * Called by the plugin Editor to display the current plugin code version
 199  * This may be different than the version installed and registered currently.
 200  * If newer then you may want to run the update
 201  *
 202  * @return   string  version number
 203  *
 204  */
 205  function plugin_chkVersion_links ()
 206  {
 207      global $_LI_CONF;
 208  
 209      return $_LI_CONF['version'];
 210  }
 211  
 212  /**
 213  * Helper function: count number of links and total number of clicks
 214  *
 215  * @return   array(number of links, number of clicks);
 216  *
 217  */
 218  function LINKS_countLinksAndClicks ()
 219  {
 220      global $_TABLES;
 221  
 222      $result = DB_query ("SELECT COUNT(*) AS count,SUM(hits) AS clicks FROM {$_TABLES['links']}" . COM_getPermSQL ());
 223      $A = DB_fetchArray ($result);
 224      $total_links = $A['count'];
 225      $total_clicks = $A['clicks'];
 226      if (empty ($total_clicks)) {
 227          $total_clicks = 0;
 228      }
 229  
 230      return array ($total_links, $total_clicks);
 231  }
 232  
 233  /**
 234  * Shows the statistics for the links plugin on stats.php.
 235  * If $showsitestats is 1 then we are to only print the overall stats in the
 236  * 'site statistics box' otherwise we show the detailed stats
 237  *
 238  * @param    int     $showsitestate  Flag to let us know which stats to get
 239  * @param    string                  HTML for the stats section
 240  *
 241  */
 242  function plugin_showstats_links ($showsitestats)
 243  {
 244      global $_CONF, $_TABLES, $LANG_LINKS_STATS;
 245  
 246      require_once ($_CONF['path_system'] . 'lib-admin.php');
 247  
 248      $retval = '';
 249  
 250      $result = DB_query ("SELECT lid,url,title,hits FROM {$_TABLES['links']} WHERE (hits > 0)" . COM_getPermSQL ('AND') . " ORDER BY hits DESC LIMIT 10");
 251      $nrows  = DB_numRows ($result);
 252      if ($nrows > 0) {
 253          $header_arr = array(
 254              array('text'         => $LANG_LINKS_STATS['stats_page_title'],
 255                    'field'        => 'sid',
 256                    'header_class' => 'stats-header-title'
 257              ),
 258              array('text'         => $LANG_LINKS_STATS['stats_hits'],
 259                    'field'        => 'hits',
 260                    'header_class' => 'stats-header-count',
 261                    'field_class'  => 'stats-list-count'
 262              )
 263          );
 264          $data_arr = array();
 265          $text_arr = array('has_menu' => false,
 266                            'title'    => $LANG_LINKS_STATS['stats_headline'],
 267          );
 268          for ($i = 0; $i < $nrows; $i++) {
 269              $A = DB_fetchArray ($result);
 270              $title = stripslashes (str_replace ('$', '&#36;', $A['title']));
 271              $url = COM_buildUrl ($_CONF['site_url']
 272                          . '/links/portal.php?what=link&amp;item=' . $A['lid']);
 273              $sid = '<a href="' . $url . '" title="' . $A['url'] . '">' . $title
 274                   . '</a>';
 275              $hits = COM_numberFormat ($A['hits']);
 276              $data_arr[] = array('title' => $title,
 277                                  'sid' => $sid,
 278                                  'hits' => $hits
 279                            );
 280          }
 281          $retval .= ADMIN_simpleList ('', $header_arr, $text_arr, $data_arr);
 282      } else {
 283          $retval .= COM_startBlock ($LANG_LINKS_STATS['stats_headline']);
 284          $retval .= $LANG_LINKS_STATS['stats_no_hits'];
 285          $retval .= COM_endBlock ();
 286      }
 287  
 288      return $retval;
 289  }
 290  
 291  /**
 292  * New stats plugin API function for proper integration with the site stats
 293  *
 294  * @return   array(item text, item count);
 295  *
 296  */
 297  function plugin_statssummary_links ()
 298  {
 299      global $LANG_LINKS_STATS;
 300  
 301      list($total_links, $total_clicks) = LINKS_countLinksAndClicks ();
 302  
 303      $item_count = COM_NumberFormat ($total_links)
 304                  . ' (' . COM_NumberFormat ($total_clicks) . ')';
 305  
 306  
 307      return array ($LANG_LINKS_STATS['links'], $item_count);
 308  }
 309  
 310  /**
 311  * Geeklog is asking us to provide any items that show up in the type
 312  * drop-down on search.php.  Let's users search for links.
 313  *
 314  * @return   array   (plugin name/entry title) pair for the dropdown
 315  *
 316  */
 317  function plugin_searchtypes_links()
 318  {
 319      global $LANG_LINKS;
 320  
 321      $tmp['links'] = $LANG_LINKS[14];
 322  
 323      return $tmp;
 324  }
 325  
 326  
 327  /**
 328  * This searches for links matching the user query and returns an array for the
 329  * header and table rows back to search.php where it will be formated and printed
 330  *
 331  * @param    string  $query      Keywords user is looking for
 332  * @param    date    $datestart  Start date to get results for
 333  * @param    date    $dateend    End date to get results for
 334  * @param    string  $topic      The topic they were searching in
 335  * @param    string  $type       Type of items they are searching, or 'all'
 336  * @param    int     $author     Get all results by this author
 337  * @param    string  $keyType    search key type: 'all', 'phrase', 'any'
 338  * @param    int     $page       page number of current search
 339  * @param    int     $perpage    number of results per page
 340  * @return   object              search result object
 341  *
 342  */
 343  function plugin_dopluginsearch_links($query, $datestart, $dateend, $topic, $type, $author, $keyType, $page, $perpage)
 344  {
 345      global $_CONF, $_TABLES, $LANG_LINKS_SEARCH;
 346  
 347      if (empty ($type)) {
 348          $type = 'all';
 349      }
 350  
 351      // Bail if we aren't supppose to do our search
 352      if ($type <> 'all' AND $type <> 'links') {
 353          $plugin_results = new Plugin();
 354          $plugin_results->plugin_name = 'links';
 355          $plugin_results->searchlabel = $LANG_LINKS_SEARCH['results'];
 356  
 357          return $plugin_results;
 358      }
 359  
 360      $select = 'SELECT lid,title,url,owner_id,hits,UNIX_TIMESTAMP(date) AS day';
 361      $sql = " FROM {$_TABLES['links']} WHERE date <> 1 ";
 362  
 363      if (!empty ($query)) {
 364          if ($keyType == 'phrase') {
 365              $mysearchterm = addslashes ($query);
 366              $sql .= " AND (description LIKE '%$mysearchterm%')"
 367                   . " OR (title LIKE '%$mysearchterm%')";
 368          } else if ($keyType == 'all') {
 369              $mywords = explode (' ', $query);
 370              $sql .= ' AND (';
 371              $tmp = '';
 372              foreach ($mywords AS $mysearchterm) {
 373                  $mysearchterm = addslashes (trim ($mysearchterm));
 374                  if (!empty ($mysearchterm)) {
 375                      $tmp .= "(description LIKE '%$mysearchterm%')"
 376                           . " OR (title LIKE '%$mysearchterm%') AND ";
 377                  }
 378              }
 379              $tmp = substr ($tmp, 0, strlen ($tmp) - 5);
 380              $sql .= $tmp . ')';
 381          } else if ($keyType == 'any') {
 382              $mywords = explode (' ', $query);
 383              $sql .= ' AND (';
 384              $tmp = '';
 385              foreach ($mywords AS $mysearchterm) {
 386                  $mysearchterm = addslashes (trim ($mysearchterm));
 387                  if (!empty ($mysearchterm)) {
 388                      $tmp .= "(description LIKE '%$mysearchterm%')"
 389                           . " OR (title LIKE '%$mysearchterm%') OR ";
 390                  }
 391              }
 392              $tmp = substr ($tmp, 0, strlen ($tmp) - 4);
 393              $sql .= $tmp . ')';
 394          } else {  // quick search
 395              $mysearchterm = addslashes ($query);
 396              $sql .= " AND (description LIKE '%$mysearchterm%')"
 397                   . " OR (title LIKE '%$mysearchterm%')";
 398          }
 399      }
 400  
 401      if (!empty ($datestart) && !empty ($dateend)) {
 402          $delim = substr ($datestart, 4, 1);
 403          if (!empty($delim)) {
 404              $DS = explode ($delim, $datestart);
 405              $DE = explode ($delim, $dateend);
 406              $startdate = mktime (0, 0, 0, $DS[1], $DS[2], $DS[0]);
 407              $enddate = mktime (23, 59, 59, $DE[1], $DE[2], $DE[0]);
 408              $sql .= " AND (UNIX_TIMESTAMP(date) BETWEEN '$startdate' AND '$enddate')";
 409          }
 410      }
 411  
 412      if (!empty ($author)) {
 413          $sql .= "AND (owner_id = '$author')";
 414      }
 415      $sql .= COM_getPermSQL ('AND');
 416      $sql .= ' GROUP BY date, lid, category, url, description, title, hits, owner_id, group_id, perm_owner, perm_group, perm_members, perm_anon ORDER BY date DESC';
 417      $l = ($perpage * $page) - $perpage;
 418      $sql .= ' LIMIT ' . $l . ',' . $perpage;
 419  
 420      // Perform search
 421      $result = DB_query ($select . $sql);
 422      $mycount = DB_numRows ($result);
 423      $result_count = DB_query ('SELECT COUNT(*)' . $sql);
 424      $B = DB_fetchArray ($result_count, true);
 425  
 426      $plugin_results = new Plugin();
 427      $plugin_results->plugin_name = 'links';
 428      $plugin_results->searchlabel = $LANG_LINKS_SEARCH['results'];
 429      $plugin_results->addSearchHeading ($LANG_LINKS_SEARCH['title']);
 430      $plugin_results->addSearchHeading ($LANG_LINKS_SEARCH['date']);
 431      $plugin_results->addSearchHeading ($LANG_LINKS_SEARCH['author']);
 432      $plugin_results->addSearchHeading ($LANG_LINKS_SEARCH['hits']);
 433      $plugin_results->num_searchresults = 0;
 434      $plugin_results->num_itemssearched = $B[0];
 435      $plugin_results->supports_paging = true;
 436  
 437      // NOTE if any of your data items need to be links then add them here!
 438      // make sure data elements are in an array and in the same order as your
 439      // headings above!
 440      for ($i = 0; $i < $mycount; $i++) {
 441          $A = DB_fetchArray ($result);
 442  
 443          $thetime = COM_getUserDateTimeFormat ($A['day']);
 444          $A['title'] = stripslashes ($A['title']);
 445          $submitter = COM_getDisplayName ($A['owner_id']);
 446          if ($A['owner_id'] > 1) {
 447              $profile = '<a href="' . $_CONF['site_url']
 448                       . '/users.php?mode=profile&amp;uid=' . $A['owner_id']
 449                       . '">' . $submitter . '</a>';
 450          } else {
 451              $profile = $submitter;
 452          }
 453          $linkUrl = COM_buildURL ($_CONF['site_url']
 454                                   . '/links/portal.php?what=link&amp;item='
 455                                   . $A['lid']);
 456          $anchor = '<a href="' . $linkUrl . '" title="' . $A['url'] . '">';
 457          $row = array ($anchor . $A['title'] . '</a>', $thetime[0], $profile,
 458                        COM_NumberFormat ($A['hits']));
 459          $plugin_results->addSearchResult ($row);
 460          $plugin_results->num_searchresults++;
 461      }
 462  
 463      return $plugin_results;
 464  }
 465  
 466  
 467  /**
 468  * This will put an option for links in the command and control block on
 469  * moderation.php
 470  *
 471  * @return   mixed   array(title, url, icon), or boolean false when not allowed
 472  *
 473  */
 474  function plugin_cclabel_links()
 475  {
 476      global $_CONF, $LANG_LINKS;
 477  
 478      if (SEC_hasRights ('links.edit')) {
 479          return array ($LANG_LINKS[14],
 480                        $_CONF['site_admin_url'] . '/plugins/links/index.php',
 481                        plugin_geticon_links ());
 482      }
 483  
 484      return false;
 485  }
 486  
 487  /**
 488  * returns the administrative option for this plugin
 489  *
 490  * @return   mixed   array(title, url, num. links), or void when not allowed
 491  *
 492  */
 493  function plugin_getadminoption_links()
 494  {
 495      global $_CONF, $_TABLES, $LANG_LINKS;
 496  
 497      if (SEC_hasRights ('links.edit,links.delete', 'OR')) {
 498          $total_links = DB_getItem ($_TABLES['links'], 'COUNT(*)',
 499                                     COM_getPermSql (''));
 500  
 501          return array ($LANG_LINKS[14],
 502                        $_CONF['site_admin_url'] . '/plugins/links/index.php',
 503                        $total_links);
 504      }
 505  }
 506  
 507  /**
 508  * A user is about to be deleted. Update ownership of any links owned
 509  * by that user or delete them.
 510  *
 511  * @param    int     $uid    User id of deleted user
 512  * @return   void
 513  *
 514  */
 515  function plugin_user_delete_links ($uid)
 516  {
 517      global $_TABLES, $_LI_CONF;
 518  
 519      if (DB_count ($_TABLES['links'], 'owner_id', $uid) == 0) {
 520          return;
 521      }
 522  
 523      if ($_LI_CONF['delete_links'] == 1) {
 524          // delete the links
 525          DB_query ("DELETE FROM {$_TABLES['links']} WHERE owner_id = $uid");
 526      } else {
 527          // assign ownership to a user from the Root group
 528          $rootgroup = DB_getItem ($_TABLES['groups'], 'grp_id',
 529                                   "grp_name = 'Root'");
 530          $result = DB_query ("SELECT DISTINCT ug_uid FROM {$_TABLES['group_assignments']} WHERE ug_main_grp_id = $rootgroup ORDER BY ug_uid LIMIT 1");
 531          $A = DB_fetchArray ($result);
 532          $rootuser = $A['ug_uid'];
 533          DB_query ("UPDATE {$_TABLES['links']} SET owner_id = $rootuser WHERE owner_id = $uid");
 534      }
 535  }
 536  
 537  /**
 538  * Do we support feeds?
 539  *
 540  * @return   array   id/name pairs of all supported feeds
 541  *
 542  */
 543  function plugin_getfeednames_links()
 544  {
 545      global $_TABLES;
 546  
 547      $feeds = array ();
 548  
 549      $result = DB_query ("SELECT category FROM {$_TABLES['links']} GROUP BY category ORDER BY category ASC");
 550      $num = DB_numRows ($result);
 551  
 552      if ($num > 0) {
 553          $feeds[] = array ('id' => 'all', 'name' => 'all categories');
 554  
 555          for ($i = 0; $i < $num; $i++) {
 556              $A = DB_fetchArray ($result);
 557              $feeds[] = array ('id' => $A['category'], 'name' => $A['category']);
 558          }
 559      }
 560  
 561      return $feeds;
 562  }
 563  
 564  /**
 565  * Provide feed data
 566  *
 567  * @param    int     $feed       feed ID
 568  * @param    ref     $link
 569  * @param    ref     $update
 570  * @return   array               feed entries
 571  *
 572  */
 573  function plugin_getfeedcontent_links ($feed, &$link, &$update)
 574  {
 575      global $_CONF, $_TABLES;
 576  
 577      $result = DB_query( "SELECT topic,limits,content_length FROM {$_TABLES['syndication']} WHERE fid = '$feed'" );
 578      $S = DB_fetchArray( $result );
 579  
 580      $result = DB_query( "SELECT lid,owner_id,title,description,UNIX_TIMESTAMP(date) AS modified FROM " . $_TABLES['links'] . links_buildSql ($S['topic'], $S['limits']) );
 581  
 582      $content = array();
 583      $lids = array();
 584      $nrows = DB_numRows( $result );
 585  
 586      for( $i = 0; $i < $nrows; $i++ )
 587      {
 588          $row = DB_fetchArray( $result );
 589          $lids[] = $row['lid'];
 590  
 591          $linktitle = stripslashes( $row['title'] );
 592          $linkdesc = stripslashes( $row['description'] );
 593  
 594          $linklink = COM_buildUrl( $_CONF['site_url']
 595                    . '/links/portal.php?what=link&item=' . $row['lid'] );
 596  
 597          $content[] = array( 'title'   => $linktitle,
 598                              'summary' => $linkdesc,
 599                              'link'    => $linklink,
 600                              'uid'     => $row['owner_id'],
 601                              'author'  => COM_getDisplayName( $row['owner_id'] ),
 602                              'date'    => $row['modified'],
 603                              'format'  => 'plaintext'
 604                            );
 605      }
 606  
 607      $link = $_CONF['site_url'] . '/links/index.php';
 608      $update = implode( ',', $lids );
 609  
 610      return $content;
 611  }
 612  
 613  /**
 614  * Helper function: Build part of an SQL request
 615  *
 616  * @param    string  $category   category name
 617  * @param    string  $limits     limit (number of entries or number of hours)
 618  * @return   string              part of an SQL request
 619  *
 620  */
 621  function links_buildSql ($category, $limits)
 622  {
 623      $where = '';
 624      if ($category != 'all') {
 625          $where = "category='" . $category . "'";
 626      }
 627  
 628      $limitsql = '';
 629      if (!empty ($limits)) {
 630          if (substr ($limits, -1) == 'h') { // last xx hours
 631              $limitsql = '';
 632              $hours = substr ($limits, 0, -1);
 633              if (!empty ($where)) {
 634                  $where .= ' AND ';
 635              }
 636              $where .= "date >= DATE_SUB(NOW(),INTERVAL $hours HOUR)";
 637          } else {
 638              $limitsql = ' LIMIT ' . $limits;
 639          }
 640      }
 641      else
 642      {
 643          $limitsql = ' LIMIT 10';
 644      }
 645  
 646      if (!empty ($where)) {
 647          $where = ' WHERE ' . $where;
 648      }
 649  
 650      $sql = $where . ' ORDER BY date DESC' . $limitsql;
 651  
 652      return $sql;
 653  }
 654  
 655  /**
 656  * Checking if links feeds are up to date
 657  *
 658  * @param    int     $feed           id of feed to be checked
 659  * @param    string  $topic          topic (actually: category)
 660  * @param    string  $update_data    data describing current feed contents
 661  * @param    string  $limit          number of entries or number of hours
 662  * @param    string  $updated_type   (optional) type of feed to be updated
 663  * @param    string  $updated_topic  (optional) feed's "topic" to be updated
 664  * @param    string  $updated_id     (optional) id of entry that has changed
 665  * @return   boolean                 true: feed data is up to date; false: isn't
 666  *
 667  */
 668  function plugin_feedupdatecheck_links ($feed, $topic, $update_data, $limit, $updated_type = '', $updated_topic = '', $updated_id = '')
 669  {
 670      global $_TABLES;
 671  
 672      $is_current = true;
 673  
 674      if ($updated_type != 'links') {
 675          // we're not interested
 676          $updated_type = '';
 677          $updated_topic = '';
 678          $updated_id = '';
 679      }
 680  
 681      $sql = "SELECT lid FROM {$_TABLES['links']}" . links_buildSql ($topic, $limit);
 682      $result = DB_query ($sql);
 683      $num = DB_numRows ($result);
 684  
 685      $lids = array ();
 686      for ($i = 0; $i < $num; $i++) {
 687          $A = DB_fetchArray ($result);
 688  
 689          if ($A['lid'] == $updated_id) {
 690              // this feed has to be updated - no further checks needed
 691              return false;
 692          }
 693  
 694          $lids[] = $A['lid'];
 695      }
 696      $current = implode (',', $lids);
 697  
 698      return ($current != $update_data) ? false : true;
 699  }
 700  
 701  /**
 702  * Update the Links plugin
 703  *
 704  * @return   int     Number of message to display (true = generic success msg)
 705  *
 706  */
 707  function plugin_upgrade_links ()
 708  {
 709      global $_TABLES, $_LI_CONF;
 710  
 711      // the plugin needs these functions so complain when they doesn't exist
 712      if (!function_exists ('COM_truncate') ||
 713          !function_exists ('MBYTE_strpos')) {
 714          return 3002;
 715      }
 716  
 717      // no db changes - just update the version numbers
 718      DB_query ("UPDATE {$_TABLES['plugins']} SET pi_version = '{$_LI_CONF['version']}', pi_gl_version = '" . VERSION . "' WHERE pi_name = 'links'");
 719  
 720      return true;
 721  }
 722  
 723  /**
 724  * Geeklog informs us that we're about to be enabled or disabled
 725  *
 726  * @param    boolean     $enable     true = we're being enabled, false = disabled
 727  * @return   void
 728  *
 729  */
 730  function plugin_enablestatechange_links ($enable)
 731  {
 732      global $_TABLES;
 733  
 734      $is_enabled = $enable ? 1 : 0;
 735  
 736      // toggle links feeds
 737      DB_query ("UPDATE {$_TABLES['syndication']} SET is_enabled = $is_enabled WHERE type = 'links'");
 738  }
 739  
 740  /**
 741  * Removes the datastructures for this plugin from the Geeklog database
 742  *
 743  * This may get called by the install routine to undo anything done to this
 744  * point.
 745  *
 746  * @return   boolean     true: uninstalled successfully
 747  *
 748  */
 749  function plugin_uninstall_links ()
 750  {
 751      global $_CONF, $_TABLES;
 752  
 753      // Uninstalls the links plugin
 754  
 755      // Remove the linksubmisssion table
 756      COM_errorLog ('Dropping linksubmission table', 1);
 757      DB_query ("DROP TABLE {$_TABLES['linksubmission']}");
 758      COM_errorLog ('...success', 1);
 759  
 760      // Remove the links table
 761      COM_errorLog ('Dropping links table', 1);
 762      DB_query ("DROP TABLE {$_TABLES['links']}");
 763      COM_errorLog ('...success', 1);
 764  
 765      // Remove feed files
 766      COM_errorLog ('removing links feed files', 1);
 767      $sql = "SELECT filename FROM {$_TABLES['syndication']} WHERE type = 'links';";
 768      $result = DB_query( $sql );
 769      $nrows = DB_numRows( $result );
 770      COM_errorLog ($nrows. ' files stored in table.', 1);
 771      if ( $nrows > 0 ) {
 772          for ( $i = 0; $i < $nrows; $i++ ) {
 773              $fcount = $i + 1;
 774              $A = DB_fetchArray( $result );
 775              $fullpath = SYND_getFeedPath( $A[0] );
 776              if ( file_exists( $fullpath ) ) {
 777                  unlink ($fullpath);
 778                  COM_errorLog ("removed file $fcount of $nrows: $fullpath", 1);
 779              } else {
 780                  COM_errorLog ("cannot remove file $fcount of $nrows, it does not exist! ($fullpath)", 1);
 781              }
 782          }
 783      }
 784      COM_errorLog ('...success', 1);
 785  
 786      // Remove Links Feeds from syndiaction table
 787      COM_errorLog ('removing links feeds from table', 1);
 788      DB_query ("DELETE FROM {$_TABLES['syndication']} WHERE type = 'links'");
 789      COM_errorLog ('...success', 1);
 790  
 791      // Remove security for this plugin
 792  
 793      // Remove the links admin group
 794      $grp_id = DB_getItem ($_TABLES['groups'], 'grp_id',
 795                            "grp_name = 'Links Admin'");
 796  
 797      if (!empty ($grp_id)) {
 798          COM_errorLog ('Attempting to remove the Links Admin group', 1);
 799          DB_query ("DELETE FROM {$_TABLES['groups']} WHERE grp_id = $grp_id");
 800          COM_errorLog ('...success', 1);
 801      }
 802  
 803      // Remove related features
 804      $edit_id = DB_getItem ($_TABLES['features'], 'ft_id',
 805                             "ft_name = 'links.edit'");
 806      $moderate_id = DB_getItem ($_TABLES['features'], 'ft_id',
 807                                 "ft_name = 'links.moderate'");
 808      $submit_id = DB_getItem ($_TABLES['features'], 'ft_id',
 809                               "ft_name = 'links.submit'");
 810  
 811      // Remove access to those features
 812      if (!empty ($edit_id)) {
 813          COM_errorLog ('Attempting to remove links.edit rights from all groups' ,1);
 814          DB_query ("DELETE FROM {$_TABLES['access']} WHERE acc_ft_id = $edit_id");
 815          COM_errorLog ('...success', 1);
 816      }
 817  
 818      if (!empty ($moderate_id)) {
 819          COM_errorLog ('Attempting to remove links.moderate rights from all groups', 1);
 820          DB_query ("DELETE FROM {$_TABLES['access']} WHERE acc_ft_id = $moderate_id");
 821          COM_errorLog ('...success', 1);
 822      }
 823  
 824      if (!empty ($submit_id)) {
 825          COM_errorLog ('Attempting to remove links.submit rights from all groups', 1);
 826          DB_query ("DELETE FROM {$_TABLES['access']} WHERE acc_ft_id = $submit_id");
 827          COM_errorLog ('...success', 1);
 828      }
 829  
 830      // Remove Links Admin group from all other groups
 831      if (!empty ($grp_id)) {
 832          COM_errorLog ('Attempting to Links Admin group from all groups.', 1);
 833          DB_query("DELETE FROM {$_TABLES['group_assignments']} WHERE ug_main_grp_id = $grp_id");
 834          COM_errorLog ('...success', 1);
 835      }
 836  
 837      // remove features
 838      if (!empty ($edit_id)) {
 839          COM_errorLog ('Attempting to remove the links.edit feature', 1);
 840          DB_query ("DELETE FROM {$_TABLES['features']} WHERE ft_id = $edit_id");
 841          COM_errorLog ('...success', 1);
 842      }
 843  
 844      if (!empty ($moderate_id)) {
 845          COM_errorLog ('Attempting to remove the links.moderate feature', 1);
 846          DB_query ("DELETE FROM {$_TABLES['features']} WHERE ft_id = $moderate_id");
 847          COM_errorLog ('...success', 1);
 848      }
 849  
 850      if (!empty ($submit_id)) {
 851          COM_errorLog ('Attempting to remove the links.submit feature', 1);
 852          DB_query ("DELETE FROM {$_TABLES['features']} WHERE ft_id = $submit_id");
 853          COM_errorLog ('...success', 1);
 854      }
 855  
 856      // Unregister the plugin with Geeklog
 857      // Always attempt to remove these entries or lib-common.php would still
 858      // try and read our functions.inc file ...
 859      COM_errorLog ('Attempting to unregister the plugin from Geeklog', 1);
 860      DB_query ("DELETE FROM {$_TABLES['plugins']} WHERE pi_name = 'links'");
 861      COM_errorLog ('...success',1);
 862  
 863      COM_errorLog ('Finished uninstalling the Links plugin.', 1);
 864  
 865      return true;
 866  }
 867  
 868  /**
 869  * Counts the items that are submitted
 870  *
 871  * @return   int     number of items in submission queue
 872  *
 873  */
 874  function plugin_submissioncount_links()
 875  {
 876      global $_TABLES;
 877  
 878      $retval = 0;
 879  
 880      if (plugin_ismoderator_links ()) {
 881          $retval = DB_count ($_TABLES['linksubmission']);
 882      }
 883  
 884      return $retval;
 885  }
 886  
 887  /**
 888  * Checks that the current user has the rights to moderate the
 889  * plugin, returns true if this is the case, false otherwise
 890  *
 891  * @return        boolean       Returns true if moderator
 892  *
 893  */
 894  function plugin_ismoderator_links()
 895  {
 896      return SEC_hasRights ('links.moderate');
 897  }
 898  
 899  
 900  /**
 901  * Returns SQL & Language texts to moderation.php
 902  *
 903  * @return   mixed   plugin object or void if not allowed
 904  *
 905  */
 906  function plugin_itemlist_links()
 907  {
 908      global $_TABLES, $LANG_LINKS_SUBMIT;
 909  
 910      if (plugin_ismoderator_links()) {
 911          $plugin = new Plugin();
 912          $plugin->submissionlabel = $LANG_LINKS_SUBMIT[11];
 913          $plugin->submissionhelpfile = 'cclinksubmission.html';
 914          $plugin->getsubmissionssql = "SELECT lid AS id,title,category,url FROM {$_TABLES['linksubmission']} ORDER BY title ASC";
 915          $plugin->addSubmissionHeading($LANG_LINKS_SUBMIT[8]);
 916          $plugin->addSubmissionHeading($LANG_LINKS_SUBMIT[10]);
 917          $plugin->addSubmissionHeading($LANG_LINKS_SUBMIT[9]);
 918  
 919          return $plugin;
 920      }
 921  }
 922  
 923  /**
 924  * returns list of moderation values
 925  *
 926  * The array returned contains (in order): the row 'id' label, main plugin
 927  * table, moderation fields (comma seperated), and plugin submission table
 928  *
 929  * @return       array        Returns array of useful moderation values
 930  *
 931  */
 932  function plugin_moderationvalues_links()
 933  {
 934      global $_TABLES;
 935  
 936      return array ('lid',
 937                    $_TABLES['links'],
 938                    'lid,category,url,description,title,date',
 939                    $_TABLES['linksubmission']);
 940  }
 941  
 942  
 943  /**
 944  * Performs plugin exclusive work for items approved by moderation
 945  *
 946  * While moderation.php handles the actual move from linkssubmission
 947  * to links tables, within the function we handle all other approval
 948  * relate tasks
 949  *
 950  * @param    string  $id     Identifying string
 951  * @return   string          Any wanted HTML output
 952  *
 953  */
 954  function plugin_moderationapprove_links ($id)
 955  {
 956      global $_TABLES, $_USER, $_GROUPS, $_LI_CONF;
 957  
 958      $A = array ();
 959      SEC_setDefaultPermissions ($A, $_LI_CONF['default_permissions']);
 960  
 961      // Since the linksubmission table does not contain fields for the owner
 962      // and group, we set those to the current user. Also set the default
 963      // permissions as specified in the plugin's config.php
 964      if (isset ($_GROUPS['Links Admin'])) {
 965          $group_id = $_GROUPS['Links Admin'];
 966      } else {
 967          $group_id = SEC_getFeatureGroup ('links.moderate');
 968      }
 969      DB_query ("UPDATE {$_TABLES['links']} SET owner_id = '{$_USER['uid']}', group_id = '$group_id', perm_owner = '{$A['perm_owner']}', perm_group = '{$A['perm_group']}', perm_members = '{$A['perm_members']}', perm_anon = '{$A['perm_anon']}' WHERE lid = '$id'");
 970  
 971      return '';
 972  }
 973  
 974  /**
 975  * Performs plugin exclusive work for items deleted by moderation
 976  *
 977  * While moderation.php handles the actual removal from <plugin>submission
 978  * table, within this function we handle all other deletion
 979  * related tasks
 980  *
 981  * @param    string  $id     Identifying string
 982  * @return   string          Any wanted HTML output
 983  *
 984  */
 985  function plugin_moderationdelete_links($id)
 986  {
 987      global $_TABLES;
 988  
 989      // these tables should not contain any rows with ml_id = $id
 990      // this is done 'just in case'
 991      DB_delete ($_TABLES['linksubmission'], 'lid', $id);
 992  
 993      return '';
 994  }
 995  
 996  /**
 997  * Check submission form values and save if OK. Else show form again
 998  *
 999  * @param    array   $A  The link record
1000  * @return   string      Any wanted HTML output
1001  *
1002  */
1003  function plugin_savesubmission_links($A)
1004  {
1005      global $LANG12;
1006  
1007      $retval = '';
1008  
1009      if (!empty ($A['title']) && !empty ($A['description']) &&
1010                  !empty ($A['url'])) {
1011          $retval = plugin_save_submit_links ($A);
1012      } else {
1013          $retval .= COM_siteHeader()
1014              . COM_startBlock ($LANG12[22], '',
1015                             COM_getBlockTemplate ('_msg_block', 'header'))
1016              . $LANG12[23]
1017              . COM_endBlock (COM_getBlockTemplate ('_msg_block', 'footer'))
1018              . submissionform('links')
1019              . COM_siteFooter ();
1020      }
1021  
1022      return $retval;
1023  }
1024  
1025  /**
1026  * Shows link submission form
1027  *
1028  * @return   string  HTML for the link submission form
1029  *
1030  */
1031  function plugin_submit_links()
1032  {
1033      global $_CONF, $LANG_LINKS_SUBMIT, $LANG12;
1034  
1035      $retval = COM_startBlock ($LANG_LINKS_SUBMIT[1], 'submitlink.html');
1036  
1037      $linkform = new Template($_CONF['path'] . '/plugins/links/templates');
1038      $linkform->set_file('linkform', 'submitlink.thtml');
1039      $linkform->set_var('site_url', $_CONF['site_url']);
1040      $linkform->set_var('layout_url', $_CONF['layout_url']);
1041      $linkform->set_var('lang_title', $LANG12[10]);
1042      $linkform->set_var('lang_link', $LANG_LINKS_SUBMIT[2]);
1043      $linkform->set_var('lang_category', $LANG_LINKS_SUBMIT[3]);
1044      $dummycategory = '';
1045      $linkform->set_var('link_category_options',
1046                         links_getCategoryList ($dummycategory));
1047      $linkform->set_var('lang_other', $LANG_LINKS_SUBMIT[4]);
1048      $linkform->set_var('lang_ifother', $LANG_LINKS_SUBMIT[5]);
1049      $linkform->set_var('lang_description', $LANG12[15]);
1050      $linkform->set_var('lang_htmlnotallowed', $LANG12[35]);
1051      $linkform->set_var('lang_submit', $LANG12[8]);
1052      $linkform->set_var('max_url_length', 255);
1053      $linkform->parse('theform', 'linkform');
1054      $retval .= $linkform->finish($linkform->get_var('theform'));
1055      $retval .= COM_endBlock();
1056  
1057      return $retval;
1058  }
1059  
1060  /**
1061  * Saves a link submission
1062  *
1063  * @param    array   $A  Data for that submission
1064  * @return   string      HTML redirect
1065  *
1066  */
1067  function plugin_save_submit_links ($A)
1068  {
1069      global $_CONF, $_TABLES, $_USER, $_LI_CONF, $LANG_LINKS_SUBMIT;
1070  
1071      $retval = '';
1072  
1073      $A['category'] = strip_tags (COM_stripslashes ($A['category']));
1074      $A['categorydd'] = strip_tags (COM_stripslashes ($A['categorydd']));
1075      if ($A['categorydd'] != $LANG_LINKS_SUBMIT[4] && !empty ($A['categorydd'])) {
1076          $A['category'] = $A['categorydd'];
1077      } else if ($A['categorydd'] != $LANG_LINKS_SUBMIT[4]) {
1078          $retval .= COM_startBlock ($LANG_LINKS_SUBMIT[6], '',
1079                         COM_getBlockTemplate ('_msg_block', 'header'))
1080                  . $LANG_LINKS_SUBMIT[7]
1081                  . COM_endBlock (COM_getBlockTemplate ('_msg_block', 'footer'))
1082                  . submissionform ('links')
1083                  . COM_siteFooter ();
1084  
1085          return $retval;
1086      }
1087  
1088      // pseudo-formatted link description for the spam check
1089      $spamcheck = '<p><a href="' . $A['url'] . '">' . $A['title'] . '</a> ('
1090                 . $A['category'] . ', ' . $A['categorydd'] . ')<br>'
1091                 . $A['description'] . '</p>';
1092      $result = PLG_checkforSpam ($spamcheck, $_CONF['spamx']);
1093      if ($result > 0) {
1094          COM_updateSpeedlimit ('submit');
1095          COM_displayMessageAndAbort ($result, 'spamx', 403, 'Forbidden');
1096      }
1097  
1098      $A['category'] = addslashes ($A['category']);
1099      $A['description'] = addslashes (htmlspecialchars (COM_checkWords ($A['description'])));
1100      $A['title'] = addslashes (strip_tags (COM_checkWords ($A['title'])));
1101      $A['url'] = addslashes (COM_sanitizeUrl ($A['url']));
1102      $A['lid'] = addslashes (COM_makeSid ());
1103      COM_updateSpeedlimit ('submit');
1104  
1105      if (($_LI_CONF['linksubmission'] == 1) && !SEC_hasRights ('links.submit')) {
1106          $result = DB_save ($_TABLES['linksubmission'],
1107                      'lid,category,url,description,title,date',
1108                      "{$A['lid']},'{$A['category']}','{$A['url']}','{$A['description']}','{$A['title']}',NOW()");
1109  
1110          if (isset ($_LI_CONF['notification']) && ($_LI_CONF['notification']==1)) {
1111              LINKS_sendNotification ($_TABLES['linksubmission'], $A);
1112          }
1113  
1114          $retval = COM_refresh ($_CONF['site_url'] . '/index.php?msg=1&plugin=links');
1115      } else { // add link directly
1116          if (isset ($_USER['uid']) && ($_USER['uid'] > 1)) {
1117              $owner_id = $_USER['uid'];
1118          } else {
1119              $owner_id = 1; // anonymous user
1120          }
1121          $result = DB_save ($_TABLES['links'], 'lid,category,url,description,title,date,owner_id', "{$A['lid']},'{$A['category']}','{$A['url']}','{$A['description']}','{$A['title']}',NOW(),$owner_id");
1122          if (isset ($_LI_CONF['notification']) && ($_LI_CONF['notification']==1)) {
1123              LINKS_sendNotification ($_TABLES['links'], $A);
1124          }
1125          COM_rdfUpToDateCheck ();
1126  
1127          $retval = COM_refresh ($_CONF['site_url'] . '/index.php?msg=4&plugin=links');
1128      }
1129  
1130      return $retval;
1131  }
1132  
1133  /**
1134  * Send an email notification for a new submission.
1135  *
1136  * @param    string  $table  Table where the new submission can be found
1137  * @param    array   $A      submission data
1138  *
1139  */
1140  function LINKS_sendNotification ($table, $A)
1141  {
1142      global $_CONF, $_TABLES, $LANG_LINKS, $LANG_LINKS_SUBMIT, $LANG08;
1143  
1144      $title = stripslashes ($A['title']);
1145      $description = stripslashes ($A['description']);
1146  
1147      $mailbody = "$LANG_LINKS_SUBMIT[8]: $title\n"
1148                . "$LANG_LINKS_SUBMIT[9]: <{$A['url']}>\n"
1149                . "$LANG_LINKS_SUBMIT[3]: {$A['category']}\n\n"
1150                . $description . "\n\n";
1151      if ($table == $_TABLES['linksubmission']) {
1152          $mailbody .= "$LANG_LINKS[10] <{$_CONF['site_admin_url']}/moderation.php>\n\n";
1153      } else {
1154          $mailbody .= "$LANG_LINKS[114] <{$_CONF['site_url']}/links/index.php?category=" . urlencode ($A['category']) . ">\n\n";
1155      }
1156      $mailsubject = $_CONF['site_name'] . ' ' . $LANG_LINKS_SUBMIT[11];
1157  
1158      $mailbody .= "\n------------------------------\n";
1159      $mailbody .= "\n$LANG08[34]\n";
1160      $mailbody .= "\n------------------------------\n";
1161  
1162      COM_mail ($_CONF['site_mail'], $mailsubject, $mailbody);
1163  }
1164  
1165  /**
1166  * Returns the URL of the plugin's icon
1167  *
1168  * @return   string      URL of the icon
1169  *
1170  */
1171  function plugin_geticon_links ()
1172  {
1173      global $_CONF;
1174  
1175      return $_CONF['site_url'] . '/links/images/links.png';
1176  }
1177  
1178  function plugin_getListField_links($fieldname, $fieldvalue, $A, $icon_arr)
1179  {
1180      global $_CONF, $LANG_ACCESS;
1181  
1182      $retval = '';
1183  
1184      $access = SEC_hasAccess($A['owner_id'],$A['group_id'],$A['perm_owner'],$A['perm_group'],$A['perm_members'],$A['perm_anon']);
1185      if ($access > 0) {
1186          switch($fieldname) {
1187              case 'edit':
1188                  if ($access == 3) {
1189                      $retval = "<a href=\"{$_CONF['site_admin_url']}/plugins/links/index.php?mode=edit&amp;lid={$A['lid']}\">{$icon_arr['edit']}</a>";
1190                  }
1191                  break;
1192              case 'access':
1193                  if ($access == 3) {
1194                     $retval = $LANG_ACCESS['edit'];
1195                  } else {
1196                     $retval = $LANG_ACCESS['readonly'];
1197                  }
1198                  break;
1199              case 'title':
1200                  $title = stripslashes($A['title']);
1201                  $retval = "<a href=\"{$A['url']}\">$title</a>";
1202                  break;
1203              default:
1204                  $retval = $fieldvalue;
1205                  break;
1206          }
1207      }
1208  
1209      return $retval;
1210  }
1211  
1212  /**
1213  * Return a list of all link categories
1214  *
1215  * @param    ref     $current_category   currently selected category
1216  * @return   string                      <option> list containing all categories
1217  *
1218  * Note: $current_category will be returned as an empty string when found in the
1219  *       current list of categories and left untouched when it's a new category,
1220  *       i.e. the user selected "Other". This is needed for moderating link
1221  *       submissions.
1222  *
1223  */
1224  function links_getCategoryList (&$current_category)
1225  {
1226      global $_TABLES, $LANG_LINKS_ADMIN;
1227  
1228      $retval = '';
1229  
1230      $result = DB_query("SELECT DISTINCT category FROM {$_TABLES['links']}" . COM_getPermSQL () . " GROUP BY category");
1231      $nrows = DB_numRows($result);
1232  
1233      $retval = '<option value="' . $LANG_LINKS_ADMIN[7] . '">'
1234              . $LANG_LINKS_ADMIN[7] . '</option>';
1235      for ($i = 0; $i < $nrows; $i++) {
1236          $A = DB_fetchArray ($result);
1237          $category = $A['category'];
1238          $retval .= '<option value="' . $category . '"';
1239          if ($category == $current_category) {
1240              $retval .= ' selected="selected"';
1241              $current_category = '';
1242          }
1243          $retval .= '>' . $category . '</option>';
1244      }
1245  
1246      return $retval;
1247  }
1248  
1249  /**
1250  * Set template variables
1251  *
1252  * @param    string  $templatename   name of template, e.g. 'header'
1253  * @param    ref     $template       reference of actual template
1254  * @return   void
1255  *
1256  * Note: A plugin should use its name as a prefix for the names of its
1257  * template variables, e.g. 'links_xxx' and 'lang_links_xxx'.
1258  * 'button_links' is an exception, as such a variable existed for header.thtml
1259  * in Geeklog 1.3.11 and earlier, where the Links section was an integral part
1260  * of Geeklog. It is added here for backward-compatibility.
1261  *
1262  */
1263  function plugin_templatesetvars_links ($templatename, &$template)
1264  {
1265      global $LANG_LINKS;
1266  
1267      if ($templatename == 'header') {
1268          $template->set_var ('button_links', $LANG_LINKS[14]);
1269      }
1270  }
1271  
1272  ?>


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