1
0
mirror of https://github.com/e107inc/e107.git synced 2025-01-17 12:48:24 +01:00

Change method of using 'up' and 'down' arrows to reorder lists so it works in all browsers (as sitelinks). Synchronise V1.0 and V2.0 code where practicable

This commit is contained in:
e107steved 2012-01-21 16:42:40 +00:00
parent 61845b499c
commit 8982d293c4
2 changed files with 251 additions and 190 deletions

View File

@ -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,84 +58,96 @@ 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']."'");
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))
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');
@ -134,110 +155,106 @@ if (isset($delete) && ($delete == 'main') && $del_id)
$admin_log->log_event('LINKS_02','ID: '.$del_id,E_LOG_INFORMATIVE,'');
$lc->show_message($msg);
}
}
break;
//delete category
if (isset($delete) && ($delete == 'category') && $del_id)
{
case 'category' : //delete category
//check if links are present for this category
if($sql->db_Select("links_page", "*", "link_category=".$del_id ))
if($sql->db_Select('links_page', '*', 'link_category='.$del_id))
{
$lc->show_message(LCLAN_ADMIN_12." #".$del_id." ".LAN_DELETED_FAILED."<br />".LCLAN_ADMIN_15);
//no? then we can safely remove this category
}
else
{
if ($sql->db_Delete("links_page_cat", "link_category_id=".$del_id))
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;
//delete submitted link
if (isset($delete) && ($delete == 'sn') && $del_id)
{
if ($sql->db_Delete("tmp", "tmp_time=".$del_id))
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);
}
}
}
//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
case 'cat' :
if (isset($qs[1]))
{
//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 'link' :
if (isset($qs[1]))
{
switch ($qs[1])
{
case 'view' :
if (isset($qs[2]) && (is_numeric($qs[2]) || $qs[2] == "all") )
{
$lc->show_links();
$gotVal = TRUE;
}
break;
case 'edit' : //edit link
case 'edit' : // Edit link
if (isset($qs[2]) && is_numeric($qs[2]))
{
$lc->show_link_create();
$gotVal = TRUE;
}
break;
case 'create' : //create link
case 'create' : // Create link
if (!isset($qs[2]) )
{
$lc->show_link_create();
$gotVal = TRUE;
}
break;
case 'sn' : //post submitted
case 'sn' : // Post submitted
if (isset($qs[2]) && is_numeric($qs[2]) )
{
$lc->show_link_create();
$gotVal = TRUE;
}
break;
default :
}
if (!$gotVal)
}
else
{
$lc->show_categories("link");
$lc->show_categories('link'); //view categories (link select cat)
}
break;
case 'sn' : //view submitted links
$lc->show_submitted();
break;
case 'opt' : // Options
$lc->show_pref_options();
break;
}
}
//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();

View File

@ -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";
@ -124,7 +126,7 @@ class linkclass
}
else
{
$row = $sql -> db_Fetch(MYSQL_ASSOC);
$row = $sql->db_Fetch(MYSQL_ASSOC);
$oldPref = $eArrayStorage->ReadArray($row['e107_value']);
unset($row);
}
@ -455,7 +457,7 @@ 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);
}
@ -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);
@ -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 = "&nbsp;&nbsp;&nbsp;";
}else{
$up = "<input type='image' src='".LINK_ICON_ORDER_UP_BASE."' value='".$linkid.".".$row['link_order'].".".$row['link_category']."' name='inc' />";
}
if($row['link_order'] == $link_total){
else
{
//$up = "<input type='image' src='".LINK_ICON_ORDER_UP_BASE."' value='".$linkid.".".$row['link_order'].".".$row['link_category']."' name='inc' />";
$up = "<input type='image' src='".LINK_ICON_ORDER_UP_BASE."' name='inc".$name_suffix."' />";
}
if($row['link_order'] == $link_total)
{
$down = "&nbsp;&nbsp;&nbsp;";
}else{
$down = "<input type='image' src='".LINK_ICON_ORDER_DOWN_BASE."' value='".$linkid.".".$row['link_order'].".".$row['link_category']."' name='dec' />";
}
else
{
//$down = "<input type='image' src='".LINK_ICON_ORDER_DOWN_BASE."' value='".$linkid.".".$row['link_order'].".".$row['link_category']."' name='dec' />";
$down = "<input type='image' src='".LINK_ICON_ORDER_DOWN_BASE."' name='dec".$name_suffix."' />";
}
$text .= "
<tr>
@ -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 .= "
</tr>";
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'], "/") ? "<img src='".e_BASE.$row['link_category_icon']."' alt='' style='vertical-align:middle' />" : "<img src='".e_PLUGIN_ABS."links_page/cat_images/".$row['link_category_icon']."' alt='' style='vertical-align:middle' />");
} else {
}
else
{
$img = "&nbsp;";
}
$text .= "
@ -1071,16 +1101,26 @@ class linkclass
<a href='".e_PLUGIN_ABS."links_page/links.php?cat.".$linkcatid."' rel='external'>".LINK_ICON_LINK."</a>
".$row['link_category_name']."<br /><span class='smalltext'>".$row['link_category_description']."</span>
</td>";
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 = "&nbsp;&nbsp;&nbsp;";
}else{
$up = "<input type='image' src='".LINK_ICON_ORDER_UP_BASE."' value='".$linkcatid.".".$row['link_category_order']."' name='inc' />";
}
if($row['link_category_order'] == $category_total){
else
{
//$up = "<input type='image' src='".LINK_ICON_ORDER_UP_BASE."' value='".$linkcatid.".".$row['link_category_order']."' name='inc' />";
$up = "<input type='image' src='".LINK_ICON_ORDER_UP_BASE."' name='inc".$name_suffix."' />";
}
if($row['link_category_order'] == $category_total)
{
$down = "&nbsp;&nbsp;&nbsp;";
}else{
$down = "<input type='image' src='".LINK_ICON_ORDER_DOWN_BASE."' value='".$linkcatid.".".$row['link_category_order']."' name='dec' />";
}
else
{
//$down = "<input type='image' src='".LINK_ICON_ORDER_DOWN_BASE."' value='".$linkcatid.".".$row['link_category_order']."' name='dec' />";
$down = "<input type='image' src='".LINK_ICON_ORDER_DOWN_BASE."' name='dec".$name_suffix."' />";
}
$text .= "
<td style='width:10%; text-align:center; white-space: nowrap' class='forumheader3'>
@ -1093,19 +1133,23 @@ class linkclass
</td>
<td style='width:10%; text-align:center' class='forumheader3'>
<select name='link_category_order[]' class='tbox'>";
for($a = 1; $a <= $category_total; $a++) {
for($a = 1; $a <= $category_total; $a++)
{
$text .= $rs -> form_option($a, ($row['link_category_order'] == $a ? "1" : "0"), $linkcatid.".".$a, "");
}
$text .= $rs -> form_select_close()."
</td>";
}else{
}
else
{
$text .= "<td style='width:10%; text-align:center; white-space: nowrap' class='forumheader3'>
<a href='".e_SELF."?link.view.".$linkcatid."' title='".LCLAN_CAT_9."'>".LINK_ICON_EDIT."</a></td>";
}
$text .= "
</tr>\n";
}
if($mode == "cat"){
if($mode == "cat")
{
$text .= "
<tr>
<td class='forumheader' colspan='4'>&nbsp;</td>