[ Index ]
 

Code source de GeekLog 1.4.1

Accédez au Source d'autres logiciels libres

title

Body

[fermer]

/public_html/links/ -> index.php (source)

   1  <?php
   2  
   3  /* Reminder: always indent with 4 spaces (no tabs). */
   4  // +---------------------------------------------------------------------------+
   5  // | Links Plugin 1.0                                                          |
   6  // +---------------------------------------------------------------------------+
   7  // | index.php                                                                 |
   8  // |                                                                           |
   9  // | This is the main page for the Geeklog Links Plugin                        |
  10  // +---------------------------------------------------------------------------+
  11  // | Copyright (C) 2000-2006 by the following authors:                         |
  12  // |                                                                           |
  13  // | Authors: Tony Bibbs        - tony AT tonybibbs DOT com                    |
  14  // |          Mark Limburg      - mlimburg AT users DOT sourceforge DOT net    |
  15  // |          Jason Whittenburg - jwhitten AT securitygeeks DOT com            |
  16  // |          Tom Willett       - tomw AT pigstye DOT net                      |
  17  // |          Trinity Bays      - trinity AT steubentech DOT com               |
  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  /** 
  38   * This is the links page   
  39   * 
  40   * @package Links
  41   * @subpackage public_html
  42   * @filesource
  43   * @version 1.0
  44   * @since GL 1.4.0
  45   * @copyright Copyright &copy; 2005-2006
  46   * @license http://opensource.org/licenses/gpl-license.php GNU Public License 
  47   * @author Tony Bibbs <tony AT tonybibbs DOT com>
  48   * @author Mark Limburg <mlimburg AT users DOT sourceforge DOT net>
  49   * @author Jason Whittenburg <jwhitten AT securitygeeks DOT com>
  50   * @author Tom Willett <tomw AT pigstye DOT net>
  51   * @author Trinity Bays <trinity AT steubentech DOT com>
  52   * @author Dirk Haun <dirk AT haun-online DOT de>
  53   * 
  54   */
  55  // $Id: index.php,v 1.10 2006/11/12 22:45:38 blaine Exp $
  56  
  57  require_once  ('../lib-common.php');
  58  
  59  /**
  60  * Prepare a link item for rendering
  61  *
  62  * @param    array   $A          link details
  63  * @param    ref     $template   reference of the links template
  64  *
  65  */
  66  function prepare_link_item ($A, &$template)
  67  {
  68      global $_CONF, $LANG_ADMIN, $_IMAGE_TYPE;
  69  
  70      $url = COM_buildUrl ($_CONF['site_url']
  71                   . '/links/portal.php?what=link&amp;item=' . $A['lid']);
  72      $template->set_var ('link_url', $url);
  73      $template->set_var ('link_actual_url', $A['url']);
  74      $template->set_var ('link_name', stripslashes ($A['title']));
  75      $template->set_var ('link_hits', COM_numberFormat ($A['hits']));
  76      $template->set_var ('link_description',
  77                          nl2br (stripslashes ($A['description'])));
  78  
  79      if ((SEC_hasAccess ($A['owner_id'], $A['group_id'], $A['perm_owner'],
  80              $A['perm_group'], $A['perm_members'], $A['perm_anon']) == 3) &&
  81              SEC_hasRights ('links.edit')) {
  82          $editurl = $_CONF['site_admin_url']
  83                   . '/plugins/links/index.php?mode=edit&amp;lid=' . $A['lid'];
  84          $template->set_var ('link_edit', '<a href="' . $editurl . '">'
  85                   . $LANG_ADMIN['edit'] . '</a>');
  86          $template->set_var ('edit_icon', '<a href="' . $editurl . '"><img src="'
  87                   . $_CONF['layout_url'] . '/images/edit.' . $_IMAGE_TYPE
  88                   . '" alt="' . $LANG_ADMIN['edit'] . '" title="'
  89                   . $LANG_ADMIN['edit'] . '" border="0"></a>');
  90      } else {
  91          $template->set_var ('link_edit', '');
  92          $template->set_var ('edit_icon', '');
  93      }
  94  }
  95  
  96  
  97  // MAIN
  98  
  99  $display = '';
 100  
 101  if (empty ($_USER['username']) &&
 102      (($_CONF['loginrequired'] == 1) || ($_LI_CONF['linksloginrequired'] == 1))) {
 103      $display .= COM_siteHeader ('menu', $LANG_LINKS[114]);
 104      $display .= COM_startBlock ($LANG_LOGIN[1], '',
 105                                  COM_getBlockTemplate ('_msg_block', 'header'));
 106      $login = new Template ($_CONF['path_layout'] . 'submit');
 107      $login->set_file (array ('login' => 'submitloginrequired.thtml'));
 108      $login->set_var ('login_message', $LANG_LOGIN[2]);
 109      $login->set_var ('site_url', $_CONF['site_url']);
 110      $login->set_var ('lang_login', $LANG_LOGIN[3]);
 111      $login->set_var ('lang_newuser', $LANG_LOGIN[4]);
 112      $login->parse ('output', 'login');
 113      $display .= $login->finish ($login->get_var ('output'));
 114      $display .= COM_endBlock (COM_getBlockTemplate ('_msg_block', 'footer'));
 115  } else {
 116      $category = '';
 117      if (isset ($_GET['category'])) {
 118          $category = strip_tags (COM_stripslashes ($_GET['category']));
 119      }
 120      $page = 0;
 121      if (isset ($_GET['page'])) {
 122          $page = COM_applyFilter ($_GET['page'], true);
 123      }
 124      if ($page == 0) {
 125          $page = 1;
 126      }
 127  
 128      if (empty ($category)) {
 129          if ($page > 1) {
 130              $page_title = sprintf ($LANG_LINKS[114] . ' (%d)', $page);
 131          } else {
 132              $page_title = $LANG_LINKS[114];
 133          }
 134      } else {
 135          if ($page > 1) {
 136              $page_title = sprintf ($LANG_LINKS[114] . ': %s (%d)', $category,
 137                                                                     $page);
 138          } else {
 139              $page_title = sprintf ($LANG_LINKS[114] . ': %s', $category);
 140          }
 141      }
 142      $display .= COM_siteHeader ('menu', $page_title);
 143  
 144      $linklist = new Template ($_CONF['path'] . 'plugins/links/templates/');
 145      $linklist->set_file (array ('linklist' => 'links.thtml',
 146                                  'catlinks' => 'categorylinks.thtml',
 147                                  'link'     => 'linkdetails.thtml',
 148                                  'catnav'   => 'categorynavigation.thtml',
 149                                  'catrow'   => 'categoryrow.thtml',
 150                                  'catcol'   => 'categorycol.thtml',
 151                                  'actcol'   => 'categoryactivecol.thtml',
 152                                  'pagenav'  => 'pagenavigation.thtml'));
 153      $linklist->set_var ('blockheader',COM_startBlock($LANG_LINKS[114]));
 154      $linklist->set_var ('layout_url',$_CONF['layout_url']);
 155  
 156      if ($_LI_CONF['linkcols'] > 0) {
 157          $result = DB_query ("SELECT DISTINCT category FROM {$_TABLES['links']}" . COM_getPermSQL () . " ORDER BY category");
 158          $nrows  = DB_numRows ($result);
 159          if ($nrows > 0) {
 160              $linklist->set_var ('lang_categories', $LANG_LINKS_ADMIN[14]);
 161              for ($i = 1; $i <= $nrows; $i++) {
 162                  $C = DB_fetchArray ($result);
 163                  $cat = addslashes ($C['category']);
 164                  $result1 = DB_query ("SELECT COUNT(*) AS count FROM {$_TABLES['links']} WHERE category = '{$cat}'" . COM_getPermSQL ('AND'));
 165                  $D = DB_fetchArray ($result1);
 166                  if (empty ($C['category'])) {
 167                      $linklist->set_var ('category_name', $LANG_LINKS_ADMIN[7]);
 168                  } else {
 169                      $linklist->set_var ('category_name', $C['category']);
 170                  }
 171                  $linklist->set_var ('category_link', $_CONF['site_url'] .
 172                      '/links/index.php?category=' . urlencode ($C['category']));
 173                  $linklist->set_var ('category_count',
 174                                      COM_numberFormat ($D['count']));
 175                  $linklist->set_var ('width', floor (100 / $_LI_CONF['linkcols']));
 176                  if (!empty ($category) && ($category == $C['category'])) {
 177                      $linklist->parse ('category_col', 'actcol', true);
 178                  } else {
 179                      $linklist->parse ('category_col', 'catcol', true);
 180                  }
 181                  if ($i % $_LI_CONF['linkcols'] == 0) {
 182                      $linklist->parse ('category_row', 'catrow', true);
 183                      $linklist->set_var ('category_col', '');
 184                  }
 185              }
 186              if ($nrows % $_LI_CONF['linkcols'] != 0) {
 187                  $linklist->parse ('category_row', 'catrow', true);
 188              }
 189              $linklist->parse ('category_navigation', 'catnav', true);
 190          } else {
 191              $linklist->set_var ('category_navigation', '');
 192          }
 193      } else {
 194          $linklist->set_var ('category_navigation', '');
 195      }
 196  
 197      $linklist->set_var ('site_url', $_CONF['site_url']);
 198      $linklist->set_var ('lang_addalink', $LANG_LINKS[116]);
 199  
 200      $sql = 'SELECT lid,category,url,description,title,hits,owner_id,group_id,perm_owner,perm_group,perm_members,perm_anon';
 201      $from_where = " FROM {$_TABLES['links']}";
 202      if ($_LI_CONF['linkcols'] > 0) {
 203          if (!empty ($category)) {
 204              $from_where .= " WHERE category = '" . addslashes ($category) . "'";
 205          } else {
 206              $from_where .= " WHERE category = ''";
 207          }
 208          $from_where .= COM_getPermSQL ('AND');
 209      } else {
 210          $from_where .= COM_getPermSQL ();
 211      }
 212      $order = ' ORDER BY category ASC,title';
 213      $limit = '';
 214      if ($_LI_CONF['linksperpage'] > 0) {
 215          if ($page < 1) {
 216              $start = 0;
 217          } else {
 218              $start = ($page - 1) * $_LI_CONF['linksperpage'];
 219          }
 220          $limit = ' LIMIT ' . $start . ',' . $_LI_CONF['linksperpage'];
 221      }
 222      $result = DB_query ($sql . $from_where . $order . $limit);
 223      $nrows = DB_numRows ($result);
 224      if ($nrows == 0) {
 225          if (empty ($category) && ($page <= 1) && $_LI_CONF['show_top10']) {
 226              $result = DB_query ("SELECT lid,url,title,description,hits,owner_id,group_id,perm_owner,perm_group,perm_members,perm_anon FROM {$_TABLES['links']} WHERE (hits > 0)" . COM_getPermSQL ('AND') . " ORDER BY hits DESC LIMIT 10");
 227              $nrows  = DB_numRows ($result);
 228              if ($nrows > 0) {
 229                  $linklist->set_var ('link_details', '');
 230                  $linklist->set_var ('link_category',
 231                                      $LANG_LINKS_STATS['stats_headline']);
 232                  for ($i = 0; $i < $nrows; $i++) {
 233                      $A = DB_fetchArray ($result);
 234                      prepare_link_item ($A, $linklist);
 235                      $linklist->parse ('link_details', 'link', true);
 236                  }
 237                  $linklist->parse ('category_links', 'catlinks', true);
 238              }
 239          }
 240          $linklist->set_var ('page_navigation', '');
 241      } else {
 242          $currentcategory = '';
 243          for ($i = 0; $i < $nrows; $i++) {
 244              $A = DB_fetchArray ($result);
 245              if (strcasecmp ($A['category'], $currentcategory) != 0) {
 246                  // print the category and link
 247                  if ($i > 0) {
 248                      $linklist->parse ('category_links', 'catlinks', true);
 249                      $linklist->set_var ('link_details', '');
 250                  }
 251                  $currentcategory = $A['category'];
 252                  $linklist->set_var ('link_category', $currentcategory);
 253              }
 254  
 255              prepare_link_item ($A, $linklist);
 256              $linklist->parse ('link_details', 'link', true);
 257          }
 258          $linklist->parse ('category_links', 'catlinks', true);
 259  
 260          $result = DB_query ('SELECT COUNT(*) AS count ' . $from_where);
 261          list($numlinks) = DB_fetchArray ($result);
 262          $pages = 0;
 263          if ($_LI_CONF['linksperpage'] > 0) {
 264              $pages = (int) ($numlinks / $_LI_CONF['linksperpage']);
 265              if (($numlinks % $_LI_CONF['linksperpage']) > 0 ) {
 266                  $pages++;
 267              }
 268          }
 269          if ($pages > 0) {
 270              if (($_LI_CONF['linkcols'] > 0) && isset ($currentcategory)) {
 271                  $catlink = '?category=' . urlencode ($currentcategory);
 272              } else {
 273                  $catlink = '';
 274              }
 275              $linklist->set_var ('page_navigation',
 276                      COM_printPageNavigation ($_CONF['site_url']
 277                          . '/links/index.php' .  $catlink, $page, $pages));
 278          } else {
 279              $linklist->set_var ('page_navigation', '');
 280          }
 281      }
 282      $linklist->set_var ('blockfooter',COM_endBlock());
 283      $linklist->parse ('output', 'linklist');
 284      $display .= $linklist->finish ($linklist->get_var ('output'));
 285  
 286  }
 287  
 288  $display .= COM_siteFooter ();
 289  
 290  echo $display;
 291  
 292  ?>


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