Links
[ class tree: Links ] [ index: Links ] [ all elements ]

Source for file index.php

Documentation is available at index.php

  1. <?php
  2.  
  3. /* Reminder: always indent with 4 spaces (no tabs). */
  4. // +---------------------------------------------------------------------------+
  5. // | Links Plugin 2.1                                                          |
  6. // +---------------------------------------------------------------------------+
  7. // | index.php                                                                 |
  8. // |                                                                           |
  9. // | This is the main page for the Geeklog Links Plugin                        |
  10. // +---------------------------------------------------------------------------+
  11. // | Copyright (C) 2000-2010 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      - trinity93 AT gmail 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 2.1
  44.  * @since GL 1.4.0
  45.  * @copyright Copyright &copy; 2005-2010
  46.  * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
  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, trinity93 AT gmail DOT com
  52.  * @author Dirk Haun, dirk AT haun-online DOT de
  53.  *
  54.  */
  55.  
  56. /** 
  57. * Geeklog common function library
  58. */
  59. require_once '../lib-common.php';
  60.  
  61. if (!in_array('links'$_PLUGINS)) {
  62.     echo COM_refresh($_CONF['site_url''/index.php');
  63.     exit;
  64. }
  65.  
  66. /**
  67. * Create the links list depending on the category given
  68. *
  69. @param    array   $message    message(s) to display
  70. @return   string              the links page
  71. *
  72. */
  73. function links_list($message)
  74. {
  75.     global $_CONF$_TABLES$_LI_CONF$LANG_LINKS_ADMIN$LANG_LINKS,
  76.            $LANG_LINKS_STATS;
  77.  
  78.     $cid $_LI_CONF['root'];
  79.     $display '';
  80.     if (isset($_GET['category'])) {
  81.         $cid strip_tags(COM_stripslashes($_GET['category']));
  82.     elseif (isset($_POST['category'])) {
  83.         $cid strip_tags(COM_stripslashes($_POST['category']));
  84.     }
  85.     $cat addslashes($cid);
  86.     $page 0;
  87.     if (isset ($_GET['page'])) {
  88.         $page COM_applyFilter ($_GET['page']true);
  89.     }
  90.     if ($page == 0{
  91.         $page 1;
  92.     }
  93.  
  94.     if (empty($cid)) {
  95.         if ($page 1{
  96.             $page_title sprintf ($LANG_LINKS[114' (%d)'$page);
  97.         else {
  98.             $page_title $LANG_LINKS[114];
  99.         }
  100.     else {
  101.         if ($cid == $_LI_CONF['root']{
  102.             $category $LANG_LINKS['root'];
  103.         else {
  104.             $category DB_getItem($_TABLES['linkcategories']'category',
  105.                                    "cid = '{$cat}'");
  106.         }
  107.         if ($page 1{
  108.             $page_title sprintf ($LANG_LINKS[114': %s (%d)'$category,
  109.                                                                    $page);
  110.         else {
  111.             $page_title sprintf ($LANG_LINKS[114': %s'$category);
  112.         }
  113.     }
  114.     
  115.     // Check has access and existent to this category
  116.     if ($cid != $_LI_CONF['root']{
  117.         $result DB_query("SELECT owner_id,group_id,perm_owner,perm_group,perm_members,perm_anon FROM {$_TABLES['linkcategories']} WHERE cid='{$cat}'");
  118.         $A DB_fetchArray($result);
  119.         if (SEC_hasAccess ($A['owner_id']$A['group_id']$A['perm_owner']$A['perm_group']$A['perm_members']$A['perm_anon']2{
  120.             $display .= COM_siteHeader ('menu'$page_title);
  121.             $display .= COM_showMessage (5'links');
  122.             $display .= COM_siteFooter ();
  123.             COM_output($display);
  124.             exit;
  125.         }
  126.         
  127.         // check existent
  128.         if !isset($A['owner_id']) ) {
  129.             $display .= COM_siteHeader ('menu'$page_title);
  130.             $display .= COM_showMessage (16'links');
  131.             $display .= COM_siteFooter ();
  132.             COM_output($display);
  133.             exit;
  134.         }
  135.     }
  136.  
  137.     $display .= COM_siteHeader ('menu'$page_title);
  138.  
  139.     if (is_array($message&& !empty($message[0])) {
  140.         $display .= COM_startBlock($message[0]'',
  141.                                  COM_getBlockTemplate('_msg_block''header'));
  142.         $display .= $message[1];
  143.         $display .= COM_endBlock(COM_getBlockTemplate('_msg_block''footer'));
  144.     else if (isset($_REQUEST['msg'])) {
  145.         $msg COM_applyFilter($_REQUEST['msg']true);
  146.         if ($msg 0{
  147.             $display .= COM_showMessage($msg'links');
  148.         }
  149.     }
  150.  
  151.     $linklist COM_newTemplate($_CONF['path''plugins/links/templates/');
  152.     $linklist->set_file (array ('linklist' => 'links.thtml',
  153.                                 'catlinks' => 'categorylinks.thtml',
  154.                                 'link'     => 'linkdetails.thtml',
  155.                                 'catnav'   => 'categorynavigation.thtml',
  156.                                 'catrow'   => 'categoryrow.thtml',
  157.                                 'catcol'   => 'categorycol.thtml',
  158.                                 'actcol'   => 'categoryactivecol.thtml',
  159.                                 'pagenav'  => 'pagenavigation.thtml',
  160.                                 'catdrop'  => 'categorydropdown.thtml'));
  161.     $linklist->set_var('blockheader'COM_startBlock($LANG_LINKS[114]));
  162.  
  163.     if ($_LI_CONF['linkcols'0{
  164.         // Create breadcrumb trail
  165.         $linklist->set_var('breadcrumbs',
  166.                            links_breadcrumbs($_LI_CONF['root']$cid));
  167.  
  168.         // Set dropdown for category jump
  169.         $linklist->set_var('lang_go'$LANG_LINKS[124]);
  170.         $linklist->set_var('link_dropdown'links_select_box(2$cid));
  171.  
  172.         // Show categories
  173.         $sql "SELECT cid,pid,category,description FROM {$_TABLES['linkcategories']} WHERE pid='{$cat}'";
  174.         $sql .= COM_getLangSQL('cid''AND');
  175.         $sql .= COM_getPermSQL('AND'" ORDER BY category";
  176.         $result DB_query($sql);
  177.         $nrows  DB_numRows ($result);
  178.         if ($nrows 0{
  179.             $linklist->set_var ('lang_categories'$LANG_LINKS_ADMIN[14]);
  180.             for ($i 1$i <= $nrows$i++{
  181.                 $C DB_fetchArray($result);
  182.                 // Get number of child links user can see in this category
  183.                 $ccid addslashes($C['cid']);
  184.                 $result1 DB_query("SELECT COUNT(*) AS count FROM {$_TABLES['links']} WHERE cid='{$ccid}'COM_getPermSQL('AND'));
  185.                 $D DB_fetchArray($result1);
  186.  
  187.                 // Get number of child categories user can see in this category
  188.                 $result2 DB_query("SELECT COUNT(*) AS count FROM {$_TABLES['linkcategories']} WHERE pid='{$ccid}'COM_getPermSQL('AND'));
  189.                 $E DB_fetchArray($result2);
  190.  
  191.                 // Format numbers for display
  192.                 $display_count '';
  193.                 // don't show zeroes
  194.                 if ($E['count']>0{
  195.                     $display_count COM_numberFormat ($E['count']);
  196.                 }
  197.                 if (($E['count']>0&& ($D['count']>0)) {
  198.                     $display_count .= ', ';
  199.                 }
  200.                 if ($D['count']>0{
  201.                     $display_count .= COM_numberFormat ($D['count']);
  202.                 }
  203.                 // add brackets if child items exist
  204.                 if ($display_count<>''{
  205.                     $display_count '('.$display_count.')';
  206.                 }
  207.  
  208.                 $linklist->set_var ('category_name'$C['category']);
  209.                 if ($_LI_CONF['show_category_descriptions']{
  210.                     $linklist->set_var ('category_description'PLG_replaceTags$C['description'));
  211.                 else {
  212.                     $linklist->set_var ('category_description''');
  213.                 }
  214.                 $linklist->set_var ('category_link'$_CONF['site_url'.
  215.                     '/links/index.php?category=' rawurlencode ($C['cid']));
  216.                 $linklist->set_var ('category_count'$display_count);
  217.                 $linklist->set_var ('width'floor (100 $_LI_CONF['linkcols']));
  218.                 if (!empty($cid&& ($cid == $C['cid'])) {
  219.                     $linklist->parse ('category_col''actcol'true);
  220.                 else {
  221.                     $linklist->parse ('category_col''catcol'true);
  222.                 }
  223.                 if ($i $_LI_CONF['linkcols'== 0{
  224.                     $linklist->parse ('category_row''catrow'true);
  225.                     $linklist->set_var ('category_col''');
  226.                 }
  227.             }
  228.             if ($nrows $_LI_CONF['linkcols'!= 0{
  229.                 $linklist->parse ('category_row''catrow'true);
  230.             }
  231.             $linklist->parse ('category_navigation''catnav'true);
  232.         else {
  233.             $linklist->set_var ('category_navigation''');
  234.         }
  235.     else {
  236.         $linklist->set_var ('category_navigation''');
  237.     }
  238.     if ($_LI_CONF['linkcols'== 0{
  239.         $linklist->set_var('category_dropdown''');
  240.     else {
  241.         $linklist->parse('category_dropdown''catdrop'true);
  242.     }
  243.  
  244.     $linklist->set_var('cid'$cid);
  245.     $linklist->set_var('cid_plain'$cid);
  246.     $linklist->set_var('cid_encoded'rawurlencode($cid));
  247.     $linklist->set_var('lang_addalink'$LANG_LINKS[116]);
  248.  
  249.     // Build SQL for links
  250.     $sql 'SELECT lid,cid,url,description,title,hits,owner_id,group_id,perm_owner,perm_group,perm_members,perm_anon';
  251.     $from_where " FROM {$_TABLES['links']}";
  252.     if ($_LI_CONF['linkcols'0{
  253.         if (!empty($cid)) {
  254.             $from_where .= " WHERE cid='" addslashes($cid"'";
  255.         else {
  256.             $from_where .= " WHERE cid=''";
  257.         }
  258.         $from_where .= COM_getPermSQL ('AND');
  259.     else {
  260.         $from_where .= COM_getPermSQL ();
  261.     }
  262.     $order ' ORDER BY cid ASC,title';
  263.     $limit '';
  264.     if ($_LI_CONF['linksperpage'0{
  265.         if ($page 1{
  266.             $start 0;
  267.         else {
  268.             $start ($page 1$_LI_CONF['linksperpage'];
  269.         }
  270.         $limit ' LIMIT ' $start ',' $_LI_CONF['linksperpage'];
  271.     }
  272.     $result DB_query ($sql $from_where $order $limit);
  273.     $nrows DB_numRows ($result);
  274.  
  275.     if ($nrows == 0{
  276.         if (($cid == $_LI_CONF['root']&& ($page <= 1&& $_LI_CONF['show_top10']{
  277.             $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'LINKS_getCategorySQL('AND'" ORDER BY hits DESC LIMIT 10");
  278.             $nrows  DB_numRows ($result);
  279.             if ($nrows 0{
  280.                 $linklist->set_var ('link_details''');
  281.                 $linklist->set_var ('link_category',
  282.                                     $LANG_LINKS_STATS['stats_headline']);
  283.                 for ($i 0$i $nrows$i++{
  284.                     $A DB_fetchArray ($result);
  285.                     prepare_link_item ($A$linklist);
  286.                     $linklist->parse ('link_details''link'true);
  287.                 }
  288.                 $linklist->parse ('category_links''catlinks'true);
  289.             }
  290.         }
  291.         $linklist->set_var ('page_navigation''');
  292.     else {
  293.         $currentcid '';
  294.         for ($i 0$i $nrows$i++{
  295.             $A DB_fetchArray($result);
  296.             if (strcasecmp ($A['cid']$currentcid!= 0{
  297.                 // print the category and link
  298.                 if ($i 0{
  299.                     $linklist->parse('category_links''catlinks'true);
  300.                     $linklist->set_var('link_details''');
  301.                 }
  302.                 $currentcid $A['cid'];
  303.                 $currentcategory DB_getItem($_TABLES['linkcategories'],
  304.                         'category'"cid = '" addslashes($currentcid"'");
  305.                 if ($A['cid'== $_LI_CONF['root']{
  306.                     $linklist->set_var('link_category'$LANG_LINKS['root']);
  307.                 else {
  308.                     $linklist->set_var('link_category'$currentcategory);
  309.                 }
  310.             }
  311.  
  312.             prepare_link_item($A$linklist);
  313.             $linklist->parse('link_details''link'true);
  314.         }
  315.         $linklist->parse('category_links''catlinks'true);
  316.  
  317.         $result DB_query ('SELECT COUNT(*) AS count ' $from_where);
  318.         list($numlinksDB_fetchArray ($result);
  319.         $pages 0;
  320.         if ($_LI_CONF['linksperpage'0{
  321.             $pages = (int) ($numlinks $_LI_CONF['linksperpage']);
  322.             if (($numlinks $_LI_CONF['linksperpage']{
  323.                 $pages++;
  324.             }
  325.         }
  326.         if ($pages 0{
  327.             if (($_LI_CONF['linkcols'0&& !empty($currentcid)) {
  328.                 $catlink '?category=' rawurlencode($currentcid);
  329.             else {
  330.                 $catlink '';
  331.             }
  332.             $linklist->set_var('page_navigation',
  333.                     COM_printPageNavigation($_CONF['site_url']
  334.                         . '/links/index.php' $catlink$page$pages));
  335.         else {
  336.             $linklist->set_var ('page_navigation''');
  337.         }
  338.     }
  339.     $linklist->set_var ('blockfooter',COM_endBlock());
  340.     $linklist->parse ('output''linklist');
  341.     $display .= $linklist->finish ($linklist->get_var ('output'));
  342.  
  343.     return $display;
  344. }
  345.  
  346.  
  347. /**
  348. * Prepare a link item for rendering
  349. *
  350. @param    array   $A          link details
  351. @param    ref     $template   reference of the links template
  352. *
  353. */
  354. function prepare_link_item($A&$template)
  355. {
  356.     global $_CONF$_LI_CONF$LANG_ADMIN$LANG_LINKS$LANG_DIRECTION,
  357.            $_IMAGE_TYPE;
  358.  
  359.     $url COM_buildUrl($_CONF['site_url']
  360.                         . '/links/portal.php?what=link&amp;item=' $A['lid']);
  361.     $actualUrl stripslashes($A['url']);
  362.     $title stripslashes($A['title']);
  363.  
  364.     $template->set_var('link_url'$url);
  365.     $template->set_var('link_actual_url'$actualUrl);
  366.     $template->set_var('link_actual_url_encoded'rawurlencode($actualUrl));
  367.     $template->set_var('link_name'$title);
  368.     $template->set_var('link_name_encoded'rawurlencode($title));
  369.     $template->set_var('link_hits'COM_numberFormat($A['hits']));
  370.     $template->set_var('link_description',
  371.                        PLG_replaceTagsnl2br(stripslashes($A['description'])) ));
  372.  
  373.     $attr array('title' => $actualUrl);
  374.     if (substr($actualUrl0strlen($_CONF['site_url'])) != $_CONF['site_url']{
  375.         $class 'ext-link';
  376.         if ((!empty($LANG_DIRECTION)) && ($LANG_DIRECTION == 'rtl')) {
  377.             $class .= '-rtl';
  378.         }
  379.         $attr['class'$class;
  380.         if ($_LI_CONF['new_window']{
  381.             $attr['target''_blank';
  382.         }
  383.     }
  384.     $html COM_createLink($title$url$attr);
  385.     $template->set_var('link_html'$html);
  386.  
  387.     if (!COM_isAnonUser(&& !SEC_hasRights('links.edit')) {
  388.         $reporturl $_CONF['site_url']
  389.                    . '/links/index.php?mode=report&amp;lid=' $A['lid'];
  390.         $template->set_var('link_broken',
  391.                 COM_createLink($LANG_LINKS[117]$reporturl,
  392.                                array('class' => 'pluginSmallText',
  393.                                      'rel'   => 'nofollow'))
  394.         );
  395.     else {
  396.         $template->set_var('link_broken''');
  397.     }
  398.  
  399.     if ((SEC_hasAccess($A['owner_id']$A['group_id']$A['perm_owner'],
  400.             $A['perm_group']$A['perm_members']$A['perm_anon']== 3&&
  401.             SEC_hasRights('links.edit')) {
  402.         $editurl $_CONF['site_admin_url']
  403.                  . '/plugins/links/index.php?mode=edit&amp;lid=' $A['lid'];
  404.         $template->set_var('link_edit',
  405.                            COM_createLink($LANG_ADMIN['edit']$editurl));
  406.         $edit_icon "<img src=\"{$_CONF['layout_url']}/images/edit.$_IMAGE_TYPE\" "
  407.             . "alt=\"{$LANG_ADMIN['edit']}\" title=\"{$LANG_ADMIN['edit']}\"XHTML ">";
  408.         $template->set_var('edit_icon'COM_createLink($edit_icon$editurl));
  409.     else {
  410.         $template->set_var('link_edit''');
  411.         $template->set_var('edit_icon''');
  412.     }
  413. }
  414.  
  415.  
  416. // MAIN
  417.  
  418. $display '';
  419. $mode '';
  420. $root $_LI_CONF['root'];
  421. if (isset ($_REQUEST['mode'])) {
  422.     $mode $_REQUEST['mode'];
  423. }
  424.  
  425. $message array();
  426. if (($mode == 'report'&& !COM_isAnonUser()) {
  427.     if (isset ($_GET['lid'])) {
  428.         $lid COM_applyFilter($_GET['lid']);
  429.     }
  430.     if (!empty($lid)) {
  431.         $lidsl addslashes($lid);
  432.         $result DB_query("SELECT url, title FROM {$_TABLES['links']} WHERE lid = '$lidsl'");
  433.         list($url$titleDB_fetchArray($result);
  434.  
  435.         $editurl $_CONF['site_admin_url']
  436.                  . '/plugins/links/index.php?mode=edit&lid=' $lid;
  437.         $msg $LANG_LINKS[119LB LB "$title, <$url>"LB LB
  438.              .  $LANG_LINKS[120LB '<' $editurl '>' LB LB
  439.              .  $LANG_LINKS[121$_USER['username'', IP: '
  440.              . $_SERVER['REMOTE_ADDR'];
  441.         COM_mail($_CONF['site_mail']$LANG_LINKS[118]$msg);
  442.         $message array($LANG_LINKS[123]$LANG_LINKS[122]);
  443.     }
  444. }
  445.  
  446. if (COM_isAnonUser(&&
  447.     (($_CONF['loginrequired'== 1|| ($_LI_CONF['linksloginrequired'== 1))) {
  448.     $display .= COM_siteHeader('menu'$LANG_LINKS[114]);
  449.     $display .= SEC_loginRequiredForm();
  450. else {
  451.     $display .= links_list($message);
  452. }
  453.  
  454. $display .= COM_siteFooter ();
  455.  
  456. COM_output($display);
  457.  
  458. ?>

Documentation generated on Fri, 25 May 2012 02:08:47 -0400 by phpDocumentor 1.4.3