diff --git a/e107_admin/links.php b/e107_admin/links.php index e72e06817..7d1c383bb 100644 --- a/e107_admin/links.php +++ b/e107_admin/links.php @@ -1,250 +1,231 @@ form = "linkform"; $pst->page = "links.php?create"; $pst->id = "admin_links"; -require_once('auth.php'); +require_once ('auth.php'); // -------------------- $pst->save_preset(); -require_once(e_HANDLER.'userclass_class.php'); -require_once(e_HANDLER.'form_handler.php'); -require_once(e_HANDLER."ren_help.php"); +require_once (e_HANDLER.'userclass_class.php'); +require_once (e_HANDLER.'form_handler.php'); +require_once(e_HANDLER."message_handler.php"); +require_once (e_HANDLER."ren_help.php"); -$rs = new form; -$linkpost = new links; +$rs = new form(); +$linkpost = new links(); +$emessage = &eMessage::getInstance(); $action = ''; -if (e_QUERY) +if(e_QUERY) { - $tmp = explode('.', e_QUERY); - $action = $tmp[0]; - $sub_action = varset($tmp[1],''); - $id = varset($tmp[2],''); - unset($tmp); + $tmp = explode('.', e_QUERY); + $action = $tmp[0]; + $sub_action = varset($tmp[1], ''); + $id = varset($tmp[2], ''); + unset($tmp); } -define("URL_SEPARATOR",'X'); // Used in names of 'inc' and 'dec' fields +define("URL_SEPARATOR", 'X'); // Used in names of 'inc' and 'dec' fields + $incdec_action = ''; foreach(array_keys($_POST) as $k) { - if (preg_match("#(.*?)_delete_(\d+)(.*)#", $k, $matches)) - { - $delete = $matches[1]; - $del_id = $matches[2]; - } - elseif (!$incdec_action && (preg_match("#^(inc|dec)".URL_SEPARATOR."(\d+)".URL_SEPARATOR."(\d+)_[x|y]#", $k, $matches))) - { - $incdec_action = $matches[1]; - $linkid = intval($matches[2]); - $link_order = intval($matches[3]); - } + if(preg_match("#(.*?)_delete_(\d+)(.*)#", $k, $matches)) + { + $delete = $matches[1]; + $del_id = $matches[2]; + } elseif(!$incdec_action && (preg_match("#^(inc|dec)".URL_SEPARATOR."(\d+)".URL_SEPARATOR."(\d+)_[x|y]#", $k, $matches))) + { + $incdec_action = $matches[1]; + $linkid = intval($matches[2]); + $link_order = intval($matches[3]); + } } - - -if(isset($_POST['generate_sublinks']) && isset($_POST['sublink_type']) && $_POST['sublink_parent'] !="" ) +if(isset($_POST['generate_sublinks']) && isset($_POST['sublink_type']) && $_POST['sublink_parent'] != "") { $subtype = $_POST['sublink_type']; $sublink = $linkpost->sublink_list($subtype); - if(!is_object($sql2)) + if(!is_object($sql2)) { - $sql2 = new db; + $sql2 = new db(); } - - $sql -> db_Select("links", "*", "link_id = '".$_POST['sublink_parent']."'"); - $par = $sql-> db_Fetch(); + + $sql->db_Select("links", "*", "link_id = '".$_POST['sublink_parent']."'"); + $par = $sql->db_Fetch(); extract($par); - - $sql -> db_Select($sublink['table'], "*", $sublink['query']); + + $sql->db_Select($sublink['table'], "*", $sublink['query']); $count = 1; - while($row = $sql-> db_Fetch()) + while($row = $sql->db_Fetch()) { $subcat = $row[($sublink['fieldid'])]; $name = $row[($sublink['fieldname'])]; - $subname = $name; // eliminate old embedded hierarchy from names. (e.g. 'submenu.TopName.name') - $suburl = str_replace("#",$subcat,$sublink['url']); + $subname = $name; // eliminate old embedded hierarchy from names. (e.g. 'submenu.TopName.name') + $suburl = str_replace("#", $subcat, $sublink['url']); $subicon = ($sublink['fieldicon']) ? $row[($sublink['fieldicon'])] : $link_button; $subdiz = ($sublink['fielddiz']) ? $row[($sublink['fielddiz'])] : $link_description; $subparent = $_POST['sublink_parent']; - + if($sql2->db_Insert("links", "0, '$subname', '$suburl', '$subdiz', '$subicon', '$link_category', '$count', '$subparent', '$link_open', '$link_class' ")) { - $message .= LAN_CREATED. " ({$name})
"; - } - else + $message .= LAN_CREATED." ({$name})[!br!]"; + $emessage->add(LAN_CREATED." ({$name})", E_MESSAGE_SUCCESS); + } else { - $message .= LAN_CREATED_FAILED. " ({$name})
"; + $message .= LAN_CREATED_FAILED." ({$name})[!br!]"; + $emessage->add(LAN_CREATED_FAILED." ({$name})", E_MESSAGE_ERROR); } $count++; } - - if($message) + + if($message) { - $ns -> tablerender(LAN_CREATED, $message); - sitelinks_adminlog('01', str_replace('
','[!br!]',$message)); // 'Sublinks generated' + sitelinks_adminlog('01', $message); // 'Sublinks generated' } } - - -if ($incdec_action == 'inc') +if($incdec_action == 'inc') { - $sql->db_Update("links", "link_order=link_order+1 WHERE link_order='".intval($link_order-1)."'"); + $sql->db_Update("links", "link_order=link_order+1 WHERE link_order='".intval($link_order - 1)."'"); $sql->db_Update("links", "link_order=link_order-1 WHERE link_id='".intval($linkid)."'"); sitelinks_adminlog('02', 'Id: '.$linkid); -} -elseif ($incdec_action =='dec') +} +elseif($incdec_action == 'dec') { - $sql->db_Update("links", "link_order=link_order-1 WHERE link_order='".intval($link_order+1)."'"); + $sql->db_Update("links", "link_order=link_order-1 WHERE link_order='".intval($link_order + 1)."'"); $sql->db_Update("links", "link_order=link_order+1 WHERE link_id='".intval($linkid)."'"); sitelinks_adminlog('03', 'Id: '.$linkid); } - - -if (isset($_POST['update'])) +if(isset($_POST['update'])) { - foreach ($_POST['link_order'] as $loid) + foreach($_POST['link_order'] as $loid) { - $tmp = explode(".", $loid); - $sql->db_Update("links", "link_order=".intval($tmp[1])." WHERE link_id=".intval($tmp[0])); + $tmp = explode(".", $loid); + $sql->db_Update("links", "link_order=".intval($tmp[1])." WHERE link_id=".intval($tmp[0])); } - foreach ($_POST['link_class'] as $lckey => $lcid) + foreach($_POST['link_class'] as $lckey => $lcid) { - $sql->db_Update("links", "link_class='".$lcid."' WHERE link_id=".intval($lckey)); + $sql->db_Update("links", "link_class='".$lcid."' WHERE link_id=".intval($lckey)); } $e107cache->clear("sitelinks"); - $linkpost->show_message(LAN_UPDATED); + $emessage->add(LAN_UPDATED, E_MESSAGE_SUCCESS); sitelinks_adminlog('04', ''); } - - -if (isset($_POST['updateoptions'])) +if(isset($_POST['updateoptions'])) { $changed = FALSE; - foreach (array('linkpage_screentip','sitelinks_expandsub') as $opt) + foreach(array('linkpage_screentip', 'sitelinks_expandsub') as $opt) { $temp = intval($_POST[$opt]); - if ($temp != $pref[$opt]) + if($temp != $pref[$opt]) { $pref[$opt] = $temp; $changed = TRUE; } } - if ($changed) + if($changed) { save_prefs(); $e107cache->clear("sitelinks"); sitelinks_adminlog('05', $pref['linkpage_screentip'].','.$pref['sitelinks_expandsub']); - $linkpost->show_message(LCLAN_1); - } + $emessage->add(LCLAN_1, E_MESSAGE_SUCCESS); + } else { - $linkpost->show_message(LINKLAN_11); // 'Nothing changed + // Nothing changed + $emessage->add(LINKLAN_11); } } - -if ($delete == 'main') +if($delete == 'main') { - if ($sql->db_Select("links", "link_id, link_name, link_order, link_parent", "link_id=".intval($del_id))) + if($sql->db_Select("links", "link_id, link_name, link_order, link_parent", "link_id=".intval($del_id))) { $row = $sql->db_Fetch(); - $msg = $linkpost->delete_link($row); // Admin logging in class routine - - if ($msg) - { - $e107cache->clear("sitelinks"); - $linkpost->show_message($msg); - } + $linkpost->delete_link($row); // Admin logging in class routine } } - - - -if (isset($_POST['add_link'])) +if(isset($_POST['add_link'])) { $linkpost->submit_link($sub_action, $_POST['link_id']); unset($id); } - - $linkArray = $linkpost->getLinks(); -if ($action == 'create') +if($action == 'create') { $linkpost->create_link($sub_action, $id); } -if (!e_QUERY || $action == 'main') +if(!e_QUERY || $action == 'main') { $linkpost->show_existing_items(); } -if ($action == 'debug') +if($action == 'debug') { - $linkpost->show_existing_items(TRUE); + $linkpost->show_existing_items(TRUE); } -if ($action == 'opt') +if($action == 'opt') { $linkpost->show_pref_options(); } if($action == "sublinks") { - $linkpost->show_sublink_generator(); + $linkpost->show_sublink_generator(); } -require_once('footer.php'); -exit; +require_once ('footer.php'); +exit(); // End --------------------------------------------------------------------------------------------------------------------------------------------------------------------- + class links { var $link_total; var $aIdOptPrep, $aIdOptData, $aIdOptTest; var $debug_dis = FALSE; - + function getLinks() { global $sql; @@ -257,444 +238,511 @@ class links } return $ret; } - - + function linkName($text) { // This function is ONLY needed for link databases that have been upgraded from // before 0.7+ -- all new link collections make use of link_parent instead // of hierarchy embedded in the link_name. (Unfortunately, the upgraded // data still includes embedded coding.) + if(substr($text, 0, 8) == "submenu.") // for backwards compatibility only. { - $tmp = explode(".",$text); - switch (count($tmp)) { - case 3: // submenu.parent.node - $tmp = $tmp[2]; break; - case 5: // submenu.parent.midlev.child.node - $tmp = $tmp[4]; break; - case 2: // submenu.parent (invalid?) - default: - $parentLen = strlen($tmp[1]); - $tmp = substr($text,8+$parentLen+1); // Skip submenu.parent. + $tmp = explode(".", $text); + switch(count($tmp)) + { + case 3: // submenu.parent.node + $tmp = $tmp[2]; + break; + case 5: // submenu.parent.midlev.child.node + $tmp = $tmp[4]; + break; + case 2: // submenu.parent (invalid?) + default: + $parentLen = strlen($tmp[1]); + $tmp = substr($text, 8 + $parentLen + 1); // Skip submenu.parent. } return $tmp; - } + } else { return $text; } } - - function dropdown($curval="", $lid=0, $indent=0) - { // Drop-down list using on the parent_id. :) - global $linkArray,$id,$sub_action; - - if(0 == $indent) {$ret = "\n";} + + function dropdown($curval = "", $lid = 0, $indent = 0) + { // Drop-down list using on the parent_id. :) + global $linkArray, $id, $sub_action; + + if(0 == $indent) + { + $ret = "\n"; + } foreach($linkArray[$lid] as $l) { - $s = ($l['link_id'] == $curval ? " selected='selected' " : "" ); + $s = ($l['link_id'] == $curval ? " selected='selected' " : ""); $thename = $this->linkName($l['link_name']); - // prevent making self the parent. - if ($l['link_id'] == $id) { $thename = "(".$thename.")"; } + // prevent making self the parent. + if($l['link_id'] == $id) + { + $thename = "(".$thename.")"; + } if($sub_action == "sub") { - $thelink = ($l['link_id'] != $lid) ? $l['link_id'] : $l['link_parent'] ; - } + $thelink = ($l['link_id'] != $lid) ? $l['link_id'] : $l['link_parent']; + } else { - $thelink = ($l['link_id'] != $id) ? $l['link_id'] : $l['link_parent'] ; + $thelink = ($l['link_id'] != $id) ? $l['link_id'] : $l['link_parent']; } - $ret .= "\n"; - + $ret .= "\n"; + if(array_key_exists($l['link_id'], $linkArray)) { - $ret .= $this->dropdown($curval, $l['link_id'], $indent+1); + $ret .= $this->dropdown($curval, $l['link_id'], $indent + 1); } } return $ret; } - - - function existing($id=0, $level=0) + + function existing($id = 0, $level = 0) { global $linkArray; $ret = ""; foreach($linkArray[$id] as $l) { - $s = ($l['link_parent'] == $curval ? " selected='selected' " : "" ); + $s = ($l['link_parent'] == $curval ? " selected='selected' " : ""); $ret .= $this->display_row($l, $level); if(array_key_exists($l['link_id'], $linkArray)) { - $ret .= $this->existing($l['link_id'], $level+1); + $ret .= $this->existing($l['link_id'], $level + 1); } } return $ret; } - - function show_existing_items($dbg_display=FALSE) + + function show_existing_items($dbg_display = FALSE) { - global $sql, $rs, $ns, $tp, $linkArray; + global $sql, $rs, $e107, $tp, $linkArray, $emessage; $this->debug_dis = $dbg_display; - if (count($linkArray)) + if(count($linkArray)) { - + $this->prepIdOpts(); // Prepare the options list for all links $text = $rs->form_open("post", e_SELF, "myform_{$link_id}", "", ""); - $text .= "
- - - - - - - - - - - - - - - - - "; - $text .= $this->existing(0); - - $text .= " - - "; - $text .= "
".LCLAN_89."".LCLAN_15."".LAN_OPTIONS."".LCLAN_95."".LCLAN_91."".LAN_ORDER."
"; + $text .= " + + + "; $text .= $rs->form_close(); - } else { + } + else + { $text .= "
".LCLAN_61."
"; } - $ns->tablerender(LCLAN_8, $text); + $e107->ns->tablerender(LCLAN_8, $emessage->render().$text); } - - function prepIdOpts() { - for($a = 1; $a <= $this->link_total; $a++) { + + function prepIdOpts() + { + for($a = 1; $a <= $this->link_total; $a++) + { $sTxt = "".$a; - $this->aIdOptData[] = array('val'=>'|||.'.$a, 'txt'=>$sTxt); // Later, ||| becomes Id + $this->aIdOptData[] = array('val' => '|||.'.$a, 'txt' => $sTxt); // Later, ||| becomes Id $this->aIdOptTest[] = $sTxt; } $this->aIdOptPrep = $this->prepOpts($this->aIdOptData); } - - function display_row($row2, $indent = FALSE) + + function display_row($row2, $indent = FALSE) { - global $sql, $rs, $ns, $tp, $linkArray, $previous_cat, $imode; + global $sql, $rs, $tp, $linkArray, $previous_cat, $imode; extract($row2); - + if($link_category > 1 && $link_category != $previous_cat) { - $text .= " + $text .= " + + + + + + "; + $e107->ns->tablerender(LCLAN_29, $emessage->render().$text); + } + + function submit_link($sub_action, $id) + { + global $sql, $e107cache, $tp, $emessage; + if(!is_object($tp)) + { + $tp = new e_parse(); + } + $id = intval($id); $parent_id = ($_POST['link_parent']) ? intval($_POST['link_parent']) : 0; - + $link_name = $tp->toDB($_POST['link_name']); $link_url = $tp->createConstants($_POST['link_url']); - $link_url = str_replace("&","&",$link_url); // xhtml compliant links. + $link_url = str_replace("&", "&", $link_url); // xhtml compliant links. + $link_description = $tp->toDB($_POST['link_description']); $link_button = $tp->toDB($_POST['link_button']); $link_render = intval($_POST['linkrender']); $link_open = intval($_POST['linkopentype']); $link_class = $tp->toDB($_POST['link_class']); - - $message = implode('[!br!]',array($link_name,$link_url,$link_class)); // Probably enough to log + + $message = implode('[!br!]', array($link_name, $link_url, $link_class)); // Probably enough to log $link_t = $sql->db_Count("links", "(*)"); - if ($id) + if($id) { $sql->db_Update("links", "link_parent='{$parent_id}', link_name='{$link_name}', link_url='{$link_url}', link_description='{$link_description}', link_button= '{$link_button}', link_category='{$link_render}', link_open='{$link_open}', link_class='{$link_class}' WHERE link_id='{$id}'"); //rename all sublinks to eliminate old embedded 'submenu' etc hierarchy. - // this is for upgrade compatibility only. Current hierarchy uses link_parent. + // this is for upgrade compatibility only. Current hierarchy uses link_parent. $e107cache->clear("sitelinks"); - sitelinks_adminlog('08',$message); - $this->show_message(LCLAN_3); + sitelinks_adminlog('08', $message); + $emessage->add(LCLAN_3, E_MESSAGE_SUCCESS); } - else - { // New link - $sql->db_Insert("links", "0, '$link_name', '$link_url', '$link_description', '$link_button', ".$link_render.", ".($link_t+1).", ".$parent_id.", ".$link_open.", ".$link_class); + else + { // New link + $sql->db_Insert("links", "0, '$link_name', '$link_url', '$link_description', '$link_button', ".$link_render.", ".($link_t + 1).", ".$parent_id.", ".$link_open.", ".$link_class); $e107cache->clear("sitelinks"); - sitelinks_adminlog('07',$message); - $this->show_message(LCLAN_2); + sitelinks_adminlog('07', $message); + $emessage->add(LCLAN_2, E_MESSAGE_SUCCESS); } } - - - - function show_pref_options() + + function show_pref_options() { - global $pref, $ns; - $text = "
-
\n - - - - - - - - - - - - - - - - - -
- ".LCLAN_78."
- ".LCLAN_79." -
". ($pref['linkpage_screentip'] ? "" : "")." -
- ".LCLAN_80."
- ".LCLAN_81." -
". ($pref['sitelinks_expandsub'] ? "" : "")." -
- -
-
-
"; - $ns->tablerender(LCLAN_88, $text); + global $pref, $e107, $emessage; + $text = " +
+ +
+ + + "; + $e107->ns->tablerender(LCLAN_88, $emessage->render().$text); } - - - + // Delete link // We need to update the 'order' number of other links with the same parentage - may be top level or a sub-level - function delete_link($linkInfo) + function delete_link($linkInfo) { - global $sql; - - if ($sql->db_Select("links", "link_id", "link_order > '{$linkInfo['link_order']}' AND `link_parent`={$linkInfo['link_parent']} ")) + global $sql, $emessage, $e107cache; + + if($sql->db_Select("links", "link_id", "link_order > '{$linkInfo['link_order']}' AND `link_parent`={$linkInfo['link_parent']} ")) { $linkList = $sql->db_getList(); foreach($linkList as $l) @@ -702,221 +750,244 @@ class links $sql->db_Update("links", "link_order = link_order -1 WHERE link_id = '{$l['link_id']}'"); } } - - - if ($sql->db_Delete("links", "link_id='".$linkInfo['link_id']."'")) + + if($sql->db_Delete("links", "link_id='".$linkInfo['link_id']."'")) { // Update orphaned sublinks - just hide them, and make them top level. And delete any obsolete naming while we're there $sql->db_Update("links", "link_name = SUBSTRING_INDEX(link_name, '.', -1) , link_parent = '0', link_class='255' WHERE link_parent= '".$linkInfo['link_id']."'"); - + $message = LCLAN_53." #".$linkInfo['link_id']." ".LCLAN_54; - sitelinks_adminlog('06',$message.'[!br!]'.$linkInfo['link_name']); - return $message."
"; - } - else + $emessage->add($message, E_MESSAGE_SUCCESS); + sitelinks_adminlog('06', $message.'[!br!]'.$linkInfo['link_name']); + $e107cache->clear("sitelinks"); + } else { - return DELETED_FAILED; + $emessage->add($message, E_MESSAGE_ERROR); } - - + } + + // -------------------------- Sub links generator -------------> + -// -------------------------- Sub links generator -------------> - -function show_sublink_generator() -{ - global $ns,$sql; - - $sublinks = $this->sublink_list(); - - $text = "
-
\n - - - - - - - - - - - - - - - - -
- ".LINKLAN_6."
-
- \n -
- ".LINKLAN_7."
-
- \n -
- -
-
-
"; - $ns->tablerender(LINKLAN_4, $text); -} - - - -function sublink_list($name="") -{ - global $sql,$PLUGINS_DIRECTORY; - $sublink_type['news']['title'] = LINKLAN_8; // "News Categories"; - $sublink_type['news']['table'] = "news_category"; - $sublink_type['news']['query'] = "category_id !='-2' ORDER BY category_name ASC"; - $sublink_type['news']['url'] = "news.php?cat.#"; - $sublink_type['news']['fieldid'] = "category_id"; - $sublink_type['news']['fieldname'] = "category_name"; - $sublink_type['news']['fieldicon'] = "category_icon"; - - $sublink_type['downloads']['title'] = LINKLAN_9; //"Download Categories"; - $sublink_type['downloads']['table'] = "download_category"; - $sublink_type['downloads']['query'] = "download_category_parent ='0' ORDER BY download_category_name ASC"; - $sublink_type['downloads']['url'] = "download.php?list.#"; - $sublink_type['downloads']['fieldid'] = "download_category_id"; - $sublink_type['downloads']['fieldname'] = "download_category_name"; - $sublink_type['downloads']['fieldicon'] = "download_category_icon"; - - - if ($sql -> db_Select("plugin", "plugin_path", "plugin_installflag = '1'")) + function show_sublink_generator() { - while ($row = $sql -> db_Fetch()) + global $e107, $sql, $emessage; + + $sublinks = $this->sublink_list(); + + $text = " +
+ +
+ "; + $e107->ns->tablerender(LINKLAN_4, $emessage->render().$text); } - if($name){ - return $sublink_type[$name]; - } - - return $sublink_type; - -} - -function prepOpts($aData) -{ -// -// Prepare an array that can rapidly (no looping) -// generate an HTML option string, with one item possibly selected. -// prepOpts returns a prepared array containing the possible values in this form: -// -// -// -// $aData is an array containing value/text pairs: -// each entry is array( 'val'=>value, 'txt'=>text ) -// - - $i=0; - foreach($aData as $aVal) + + function sublink_list($name = "") { - $sVal = $aVal['val']; - $sTxt = $aVal['txt']; - $sOut=""; - - if ($i) $sOut = '>'.$sTxtPrev.''; - $sOut .= ''; - } - - return $aPrep; -} - -function genOpts($aPrep, $aTest,$sSelected, $sId) -{ -// -// Generate an HTML option string, with one item possibly selected. -// aGen is a prepared array containing the possible values in this form. -// if sSelected matches an aTest entry, that entry is selected. -// aTest can be any array that matches one-for-one with the options -// -// if $sId is nonblank, a global search/replace is done to change all "|||" to $sId. - - $iKey = array_search( $sSelected, $aTest); - if ($iKey !== FALSE) + + function prepOpts($aData) { - $aNew = $aPrep; - $aNew[$iKey] .= " selected='selected'"; - $sOut = implode($aNew); + // + // Prepare an array that can rapidly (no looping) + // generate an HTML option string, with one item possibly selected. + // prepOpts returns a prepared array containing the possible values in this form: + // + // + // + // $aData is an array containing value/text pairs: + // each entry is array( 'val'=>value, 'txt'=>text ) + // + + + $i = 0; + foreach($aData as $aVal) + { + $sVal = $aVal['val']; + $sTxt = $aVal['txt']; + $sOut = ""; + + if($i) + $sOut = '>'.$sTxtPrev.''; + $sOut .= '