diff --git a/e107_plugins/links_page/admin_linkspage_config.php b/e107_plugins/links_page/admin_linkspage_config.php index 27825bd7e..7d69fd6d6 100644 --- a/e107_plugins/links_page/admin_linkspage_config.php +++ b/e107_plugins/links_page/admin_linkspage_config.php @@ -2,23 +2,31 @@ /* * e107 website system * - * Copyright (C) 2008-2009 e107 Inc (e107.org) + * Copyright (C) 2008-2012 e107 Inc (e107.org) * Released under the terms and conditions of the * GNU General Public License (http://www.gnu.org/licenses/gpl.txt) * + * Links plugin * - * - * $Source: /cvs_backup/e107_0.8/e107_plugins/links_page/admin_linkspage_config.php,v $ + * $URL$ * $Revision$ * $Date$ * $Author$ */ -require_once("../../class2.php"); -if (!getperms("P") || !plugInstalled('links_page')) +/** + * e107 Links plugin + * + * @package e107_plugins + * @subpackage links + * @version $Id$; + */ + +require_once('../../class2.php'); +if (!getperms('P') || !plugInstalled('links_page')) { - header("location:".e_BASE."index.php"); - exit; + header('location:'.e_BASE.'index.php'); + exit(); } require_once(e_PLUGIN.'links_page/link_shortcodes.php'); require_once(e_PLUGIN.'links_page/link_defines.php'); @@ -33,15 +41,16 @@ $eArrayStorage = new ArrayData(); require_once(e_PLUGIN.'links_page/link_class.php'); $lc = new linkclass; -include_lan($plugindir."languages/".e_LANGUAGE."_admin_links_page.php"); +include_lan(e_PLUGIN.'links_page/languages/'.e_LANGUAGE.'.php'); -$linkspage_pref = $lc -> getLinksPagePref(); +$linkspage_pref = $lc->getLinksPagePref(); + +//$deltest = array_flip($_POST); // Not used any more -$deltest = array_flip($_POST); if(e_QUERY) { - $qs = explode(".", e_QUERY); + $qs = explode('.', e_QUERY); if(is_numeric($qs[0])) { @@ -49,195 +58,203 @@ if(e_QUERY) } else { - $from = "0"; + $from = '0'; } } -if(isset($_POST['delete'])) + + + + +$incdec_action = ''; +foreach($_POST as $k => $v) +{ + if ((preg_match("#^(inc|dec)".URL_SEPARATOR."(\d+)".URL_SEPARATOR."(\d+)".URL_SEPARATOR."(\d+){0,1}_[x|y]#", $k, $matches))) + { + $incdec_action = $matches[1]; // (inc|dec) + $linkid = intval($matches[2]); + $link_order = intval($matches[3]); + $link_location = intval(varset($matches[4], '')); + break; + } +} + +switch ($incdec_action) +{ + case 'inc' : + $lc->dbOrderUpdateInc($linkid, $link_order, $link_location); + break; + case 'dec' : + $lc->dbOrderUpdateDec($linkid, $link_order, $link_location); + break; +} + + +if (isset($_POST['delete'])) { $tmp = array_pop($tmp = array_flip($_POST['delete'])); list($delete, $del_id) = explode("_", $tmp); $del_id = intval($del_id); } - -if (isset($_POST['create_category'])) +elseif (isset($_POST['create_category'])) { $lc -> dbCategoryCreate(); } - -if (isset($_POST['update_category'])) +elseif (isset($_POST['update_category'])) { $lc -> dbCategoryUpdate(); } - -if (isset($_POST['updateoptions'])) +elseif (isset($_POST['updateoptions'])) { $linkspage_pref = $lc -> UpdateLinksPagePref(); $lc -> show_message(LCLAN_ADMIN_6); } - -if (isset($_POST['add_link'])) +elseif (isset($_POST['add_link'])) { $lc -> dbLinkCreate(); } - //upload link icon -if(isset($_POST['uploadlinkicon'])) +elseif(isset($_POST['uploadlinkicon'])) { $lc -> uploadLinkIcon(); } - //upload category icon -if(isset($_POST['uploadcatlinkicon'])) +elseif(isset($_POST['uploadcatlinkicon'])) { $lc -> uploadCatLinkIcon(); } - //update link order -if (isset($_POST['update_order'])) +elseif (isset($_POST['update_order'])) { $lc -> dbOrderUpdate($_POST['link_order']); } - //update link category order -if (isset($_POST['update_category_order'])) +elseif (isset($_POST['update_category_order'])) { $lc -> dbOrderCatUpdate($_POST['link_category_order']); } -if (isset($_POST['inc'])) -{ - $lc -> dbOrderUpdateInc($_POST['inc']); -} - -if (isset($_POST['dec'])) -{ - $lc -> dbOrderUpdateDec($_POST['dec']); -} - //delete link -if (isset($delete) && ($delete == 'main') && $del_id) +if (isset($delete) && $del_id) { - $sql->db_Select("links_page", "link_order", "link_id=".$del_id); - $row = $sql->db_Fetch(); - $sql2 = new db; - $sql->db_Select("links_page", "link_id", "link_order>'".$row['link_order']."' && link_category=".intval($row['link_category'])); - while ($row = $sql->db_Fetch()) + switch ($delete) { - $sql2->db_Update("links_page", "link_order=link_order-1 WHERE link_id='".$row['link_id']."'"); - } - if ($sql->db_Delete("links_page", "link_id=".$del_id)) - { - $msg = LCLAN_ADMIN_10." #".$del_id." ".LCLAN_ADMIN_11; - $data = array('method'=>'delete', 'table'=>'links_page', 'id'=>$del_id, 'plugin'=>'links_page', 'function'=>'delete'); - $msg .= $e_event->triggerHook($data); - $admin_log->log_event('LINKS_02','ID: '.$del_id,E_LOG_INFORMATIVE,''); - $lc->show_message($msg); + case 'main' : // Delete link + $sql->db_Select('links_page', 'link_order', 'link_id='.$del_id); + $row = $sql->db_Fetch(); + $sql2 = e107::getDb('sql2'); + $sql->db_Select("links_page", "link_id", "link_order>'".$row['link_order']."' && link_category='".$id."'"); + while ($row = $sql->db_Fetch()) { + $sql2->db_Update('links_page', "link_order=link_order-1 WHERE link_id='".$row['link_id']."'"); + } + if ($sql->db_Delete('links_page', 'link_id='.$del_id)) + { + $msg = LCLAN_ADMIN_10." #".$del_id." ".LCLAN_ADMIN_11; + $data = array('method'=>'delete', 'table'=>'links_page', 'id'=>$del_id, 'plugin'=>'links_page', 'function'=>'delete'); + $msg .= $e_event->triggerHook($data); + $admin_log->log_event('LINKS_02','ID: '.$del_id,E_LOG_INFORMATIVE,''); + $lc->show_message($msg); + } + break; + + case 'category' : //delete category + //check if links are present for this category + if($sql->db_Select('links_page', '*', 'link_category='.$del_id)) + { + $lc->show_message(LCLAN_ADMIN_12." #".$del_id." ".LAN_DELETED_FAILED."
".LCLAN_ADMIN_15); + //no? then we can safely remove this category + } + else + { + if ($sql->db_Delete('links_page_cat', 'link_category_id='.$del_id)) + { + $admin_log->log_event('LINKS_03','ID: '.$del_id,E_LOG_INFORMATIVE,''); + $lc->show_message(LCLAN_ADMIN_12." #".$del_id." ".LCLAN_ADMIN_11); + unset($id); + } + } + break; + + case 'sn' : //delete submitted link + if ($sql->db_Delete('tmp', 'tmp_time='.$del_id)) + { + $admin_log->log_event('LINKS_04','ID: '.$del_id,E_LOG_INFORMATIVE,''); + $lc->show_message(LCLAN_ADMIN_13); + } } } -//delete category -if (isset($delete) && ($delete == 'category') && $del_id) -{ - //check if links are present for this category - if($sql->db_Select("links_page", "*", "link_category=".$del_id )) - { - $lc->show_message(LCLAN_ADMIN_12." #".$del_id." ".LAN_DELETED_FAILED."
".LCLAN_ADMIN_15); - //no? then we can safely remove this category - } - else - { - if ($sql->db_Delete("links_page_cat", "link_category_id=".$del_id)) - { - $admin_log->log_event('LINKS_03','ID: '.$del_id,E_LOG_INFORMATIVE,''); - $lc->show_message(LCLAN_ADMIN_12." #".$del_id." ".LCLAN_ADMIN_11); - unset($id); - } - } -} - -//delete submitted link -if (isset($delete) && ($delete == 'sn') && $del_id) -{ - if ($sql->db_Delete("tmp", "tmp_time=".$del_id)) - { - $admin_log->log_event('LINKS_04','ID: '.$del_id,E_LOG_INFORMATIVE,''); - $lc->show_message(LCLAN_ADMIN_13); - } -} //show link categories (cat edit) if (!e_QUERY) { - $lc->show_categories("cat"); + $lc->show_categories('cat'); } - - -//show cat edit form -if (isset($qs[0]) && $qs[0] == 'cat' && isset($qs[1]) && $qs[1] == 'edit' && isset($qs[2]) && is_numeric($qs[2])) +elseif (isset($qs[0])) { - $lc->show_cat_create(); -} - -//show cat create form -if (isset($qs[0]) && $qs[0] == 'cat' && isset($qs[1]) && $qs[1] == 'create' && !isset($qs[2]) ) -{ - $lc->show_cat_create(); -} - -if (isset($qs[0]) && $qs[0] == 'link') -{ - $gotVal = FALSE; - switch(varset($qs[1],'')) + switch ($qs[0]) { - case 'view' : //view links in cat - if (isset($qs[2]) && (is_numeric($qs[2]) || $qs[2] == "all") ) + case 'cat' : + if (isset($qs[1])) { - $lc->show_links(); - $gotVal = TRUE; + //show cat edit form + if (($qs[1] == 'edit') && isset($qs[2]) && is_numeric($qs[2])) + { + $lc->show_cat_create(); + } + //show cat create form + elseif (($qs[1] == 'create') && !isset($qs[2]) ) + { + $lc->show_cat_create(); + } } break; - case 'edit' : //edit link - if (isset($qs[2]) && is_numeric($qs[2])) + case 'link' : + if (isset($qs[1])) { - $lc->show_link_create(); - $gotVal = TRUE; + switch ($qs[1]) + { + case 'view' : + if (isset($qs[2]) && (is_numeric($qs[2]) || $qs[2] == "all") ) + { + $lc->show_links(); + } + break; + case 'edit' : // Edit link + if (isset($qs[2]) && is_numeric($qs[2])) + { + $lc->show_link_create(); + } + break; + case 'create' : // Create link + if (!isset($qs[2]) ) + { + $lc->show_link_create(); + } + break; + case 'sn' : // Post submitted + if (isset($qs[2]) && is_numeric($qs[2]) ) + { + $lc->show_link_create(); + } + break; + } + } + else + { + $lc->show_categories('link'); //view categories (link select cat) } break; - case 'create' : //create link - if (!isset($qs[2]) ) - { - $lc->show_link_create(); - $gotVal = TRUE; - } + case 'sn' : //view submitted links + $lc->show_submitted(); break; - case 'sn' : //post submitted - if (isset($qs[2]) && is_numeric($qs[2]) ) - { - $lc->show_link_create(); - $gotVal = TRUE; - } + case 'opt' : // Options + $lc->show_pref_options(); break; - default : - } - if (!$gotVal) - { - $lc->show_categories("link"); } } -//view submitted links -if (isset($qs[0]) && $qs[0] == 'sn') -{ - $lc->show_submitted(); -} - -//options -if (isset($qs[0]) && $qs[0] == 'opt') -{ - $lc->show_pref_options(); -} // ##### Display options -------------------------------------------------------------------------- function admin_linkspage_config_adminmenu() @@ -246,17 +263,17 @@ function admin_linkspage_config_adminmenu() $act = varset($qs[0],'cat'); if($act == 'cat' && isset($qs[1])) { - if($qs[1] == "create") + if($qs[1] == 'create') { - $act .= ".create"; + $act .= '.create'; } - elseif ($qs[1] == "edit") + elseif ($qs[1] == 'edit') { - $act .= ""; + $act .= ''; } - elseif ($qs[1] == "view") + elseif ($qs[1] == 'view') { - $act .= ""; + $act .= ''; } } @@ -283,7 +300,7 @@ function admin_linkspage_config_adminmenu() show_admin_menu(LCLAN_ADMINMENU_1, $act, $var); - if($qs[0] != "opt") + if($qs[0] != 'opt') { unset($var); $var=array(); diff --git a/e107_plugins/links_page/link_class.php b/e107_plugins/links_page/link_class.php index fe5e8def6..866873fa3 100644 --- a/e107_plugins/links_page/link_class.php +++ b/e107_plugins/links_page/link_class.php @@ -8,7 +8,7 @@ * * * - * $Source: /cvs_backup/e107_0.8/e107_plugins/links_page/link_class.php,v $ + * $URL$ * $Revision$ * $Date$ * $Author$ @@ -16,9 +16,11 @@ if (!defined('e107_INIT')) { exit; } + +define('URL_SEPARATOR','X'); // Used in names of 'inc' and 'dec' fields + class linkclass { - function LinkPageDefaultPrefs() { $linkspage_pref['link_page_categories'] = "0"; @@ -117,14 +119,14 @@ class linkclass global $sql, $eArrayStorage, $tp, $admin_log; $num_rows = $sql -> db_Select("core", "*", "e107_name='links_page' "); - if ($num_rows == 0) + if ($num_rows == 0) { $sql -> db_Insert("core", "'links_page', '' "); // Create dummy entry if none present $oldPref = array(); } else { - $row = $sql -> db_Fetch(MYSQL_ASSOC); + $row = $sql->db_Fetch(MYSQL_ASSOC); $oldPref = $eArrayStorage->ReadArray($row['e107_value']); unset($row); } @@ -331,7 +333,7 @@ class linkclass return $orderby." ".(substr($orderstring,5,1) == "a" ? "ASC" : "DESC")." ".$orderby2; } - function parseOrderLink($orderstring) + function parseOrderLink($orderstring) { if(substr($orderstring,6) == "heading"){ $orderby = "link_name"; @@ -356,7 +358,7 @@ class linkclass return $orderby." ".(substr($orderstring,5,1) == "a" ? "ASC" : "DESC")." ".$orderby2; } - function getOrder($mode='') + function getOrder($mode='') { global $qs, $linkspage_pref; @@ -421,7 +423,7 @@ class linkclass $this -> show_message($msg); } - function uploadCatLinkIcon() + function uploadCatLinkIcon() { global $ns, $pref; $pref['upload_storagetype'] = "1"; @@ -455,13 +457,13 @@ class linkclass $linkData['link_category_order'] = $link_t+1; $linkData['link_category_class'] = $tp -> toDB($_POST['link_category_class']); $linkData['link_category_datestamp'] = time(); - $sql->db_Insert("links_page_cat", $linkData); + $sql->db_Insert('links_page_cat', $linkData); $admin_log->logArrayAll('LINKS_05',$linkData); $this->show_message(LCLAN_ADMIN_4); } - function dbCategoryUpdate() + function dbCategoryUpdate() { global $sql, $tp, $admin_log; global $sql, $tp; @@ -482,7 +484,7 @@ class linkclass function dbOrderUpdate($order) { global $sql, $admin_log; - foreach ($order as $order_id) + foreach ($order as $order_id) { $tmp = explode(".", $order_id); $sql->db_Update("links_page", "link_order=".intval($tmp[1])." WHERE link_id=".intval($tmp[0])); @@ -492,10 +494,10 @@ class linkclass } - function dbOrderCatUpdate($order) + function dbOrderCatUpdate($order) { global $sql, $admin_log; - foreach ($order as $order_id) + foreach ($order as $order_id) { $tmp = explode(".", $order_id); $sql->db_Update("links_page_cat", "link_category_order=".intval($tmp[1])." WHERE link_category_id=".intval($tmp[0])); @@ -505,15 +507,15 @@ class linkclass } - function dbOrderUpdateInc($inc) + function dbOrderUpdateInc($linkid, $link_order, $location) { global $sql, $admin_log; - $tmp = explode(".", $inc); - $linkid = intval($tmp[0]); - $link_order = intval($tmp[1]); - if(isset($tmp[2])) + //$tmp = explode(".", $inc); + //$linkid = intval($tmp[0]); + //$link_order = intval($tmp[1]); + //$location = $tmp[2]; + if($location) { - $location = intval($tmp[2]); $sql->db_Update("links_page", "link_order=link_order+1 WHERE link_order='".($link_order-1)."' AND link_category=".$location); $sql->db_Update("links_page", "link_order=link_order-1 WHERE link_id='{$linkid}' AND link_category=".$location); $admin_log->log_event('LINKS_09','ID: '.$location.' -inc- '.$link_order,E_LOG_INFORMATIVE,''); @@ -526,16 +528,16 @@ class linkclass } } - function dbOrderUpdateDec($dec) + function dbOrderUpdateDec($linkid, $link_order, $location) { global $sql, $admin_log; - $tmp = explode(".", $dec); - $linkid = intval($tmp[0]); - $link_order = intval($tmp[1]); - if(isset($tmp[2])) + //$tmp = explode(".", $dec); + //$linkid = intval($tmp[0]); + //$link_order = intval($tmp[1]); + //$location = $tmp[2]; + if($location) { - $location = intval($tmp[2]); - $sql->db_Update("links_page", "link_order=link_order-1 WHERE link_order='".($link_order+1)."' AND link_category=".$location); + $sql->db_Update("links_page", "link_order=link_order-1 WHERE link_order=".($link_order+1)." AND link_category=".$location); $sql->db_Update("links_page", "link_order=link_order+1 WHERE link_id='{$linkid}' AND link_category=".$location); $admin_log->log_event('LINKS_11','ID: '.$location.' -dec- '.$link_order,E_LOG_INFORMATIVE,''); } @@ -555,6 +557,7 @@ class linkclass { $row = $sql->db_Fetch(); } + if(varset($row['link_author']) != USERID) { js_location(SITEURL); @@ -645,7 +648,7 @@ class linkclass } } - function show_link_create() + function show_link_create() { global $sql, $rs, $qs, $ns, $fl, $linkspage_pref, $e_event; @@ -838,6 +841,11 @@ class linkclass $ns->tablerender(LCLAN_PAGETITLE_1, $text); } + + + /** + * Display list of links within a particular category + */ function show_links() { global $sql, $qs, $rs, $ns, $tp, $from; @@ -898,15 +906,25 @@ class linkclass } } } - if($row['link_order'] == "1"){ + + $name_suffix = URL_SEPARATOR.$linkid.URL_SEPARATOR.$row['link_order'].URL_SEPARATOR.$row['link_category']; + if($row['link_order'] == "1") + { $up = "   "; - }else{ - $up = ""; } - if($row['link_order'] == $link_total){ + else + { + //$up = ""; + $up = ""; + } + if($row['link_order'] == $link_total) + { $down = "   "; - }else{ - $down = ""; + } + else + { + //$down = ""; + $down = ""; } $text .= " @@ -1038,7 +1056,15 @@ class linkclass unset($row['link_category_name'], $row['link_category_description'], $row['link_category_icon']); } - function show_categories($mode) { + + + /** + * Show a list of categories + * + * @param string $mode = (cat) + */ + function show_categories($mode) + { global $sql, $rs, $ns, $tp, $fl; if ($category_total = $sql->db_Select("links_page_cat", "*", "ORDER BY link_category_order ASC", "mode=no_where")) { @@ -1057,11 +1083,15 @@ class linkclass } $text .= " "; - while ($row = $sql->db_Fetch()) { + while ($row = $sql->db_Fetch()) + { $linkcatid = $row['link_category_id']; - if ($row['link_category_icon']) { + if ($row['link_category_icon']) + { $img = (strstr($row['link_category_icon'], "/") ? "" : ""); - } else { + } + else + { $img = " "; } $text .= " @@ -1071,16 +1101,26 @@ class linkclass ".LINK_ICON_LINK." ".$row['link_category_name']."
".$row['link_category_description']." "; - if($mode == "cat"){ - if($row['link_category_order'] == "1"){ + if($mode == "cat") + { + $name_suffix = URL_SEPARATOR.$linkcatid.URL_SEPARATOR.$row['link_category_order'].URL_SEPARATOR; + if($row['link_category_order'] == "1") + { $up = "   "; - }else{ - $up = ""; } - if($row['link_category_order'] == $category_total){ + else + { + //$up = ""; + $up = ""; + } + if($row['link_category_order'] == $category_total) + { $down = "   "; - }else{ - $down = ""; + } + else + { + //$down = ""; + $down = ""; } $text .= " @@ -1093,19 +1133,23 @@ class linkclass