PageRenderTime 56ms CodeModel.GetById 15ms RepoModel.GetById 1ms app.codeStats 0ms

/e107_handlers/menumanager_class.php

https://github.com/CasperGemini/e107
PHP | 1633 lines | 1201 code | 311 blank | 121 comment | 151 complexity | 81e3dd15cdd74dfa6cb247dd934128c7 MD5 | raw file
Possible License(s): GPL-2.0
  1. <?php
  2. /*
  3. * e107 website system
  4. *
  5. * Copyright (C) 2008-2013 e107 Inc (e107.org)
  6. * Released under the terms and conditions of the
  7. * GNU General Public License (http://www.gnu.org/licenses/gpl.txt)
  8. *
  9. */
  10. if (!defined('e107_INIT')) { exit; }
  11. require_once(e_HANDLER."form_handler.php");
  12. class e_menuManager {
  13. var $menu_areas = array();
  14. var $curLayout;
  15. var $menuId;
  16. var $menuNewLoc;
  17. var $dragDrop;
  18. var $menuActivateLoc;
  19. var $menuActivateIds;
  20. var $debug;
  21. var $menuMessage;
  22. var $style = 'default';
  23. function __construct($dragdrop=FALSE)
  24. {
  25. global $HEADER,$FOOTER, $NEWSHEADER;
  26. $pref = e107::getPref();
  27. $this->debug = FALSE;
  28. $this->dragDrop = $dragdrop;
  29. if($this->dragDrop)
  30. {
  31. $this->debug = TRUE;
  32. }
  33. if ($NEWSHEADER)
  34. {
  35. $HEADER .= $NEWSHEADER;
  36. }
  37. if(isset($_POST['custom_select']))
  38. {
  39. $this->curLayout = $_POST['custom_select'];
  40. }
  41. elseif(isset($_GET['lay']))
  42. {
  43. $this->curLayout = $_GET['lay'];
  44. }
  45. else
  46. {
  47. $this->curLayout = varsettrue($_GET['configure'], $pref['sitetheme_deflayout']);
  48. }
  49. $this->dbLayout = ($this->curLayout != $pref['sitetheme_deflayout']) ? $this->curLayout : ""; //menu_layout is left blank when it's default.
  50. if(isset($_POST['menu_id']) || vartrue($_GET['id']))
  51. {
  52. $this->menuId = (isset($_POST['menu_id'])) ? intval($_POST['menu_id']) : intval($_GET['id']);
  53. }
  54. if (/*$menu_act == "sv" || */isset($_POST['class_submit']))
  55. {
  56. $this->menuSaveVisibility();
  57. }
  58. elseif(isset($_POST['parms_submit']))
  59. {
  60. $this->menuSaveParameters();
  61. }
  62. if (vartrue($_GET['mode']) == "deac")
  63. {
  64. $this->menuDeactivate();
  65. }
  66. if ($_GET['mode'] == "conf")
  67. {
  68. $this->menuGoConfig();
  69. }
  70. $this->menuGrabLayout();
  71. $menu_array = $this->parseheader($HEADER.$FOOTER, 'check');
  72. if($menu_array)
  73. {
  74. sort($menu_array, SORT_NUMERIC);
  75. $menu_check = 'set';
  76. foreach ($menu_array as $menu_value)
  77. {
  78. if ($menu_value != $menu_check)
  79. {
  80. $this->menu_areas[] = $menu_value;
  81. }
  82. $menu_check = $menu_value;
  83. }
  84. }
  85. $this->menuModify();
  86. if(vartrue($_POST['menuActivate']))
  87. {
  88. $this->menuActivateLoc = key($_POST['menuActivate']);
  89. $this->menuActivateIds = $_POST['menuselect'];
  90. $this->menuActivate();
  91. }
  92. if(vartrue($_POST['menuSetCustomPages']))
  93. {
  94. $this->menuSetCustomPages($_POST['custompages']);
  95. }
  96. if(isset($_POST['menuUsePreset']) && $_POST['curLayout'])
  97. {
  98. $this->menuSetPreset();
  99. }
  100. $this->menuSetConfigList(); // Update Active MenuConfig List.
  101. }
  102. // -------------------------------------------------------------------------
  103. function menuRenderIframe($url='')
  104. {
  105. $ns = e107::getRender();
  106. $sql = e107::getDb();
  107. if(!$url)
  108. {
  109. $url = e_SELF."?configure=".$this->curLayout;
  110. }
  111. // $cnt = $sql->select("menus", "*", "menu_location > 0 AND menu_layout = '$curLayout' ORDER BY menu_name "); // calculate height to remove vertical scroll-bar.
  112. // $text = "<object class='well' type='text/html' id='menu_iframe' data='".$url."' width='100%' style='overflow:auto;width: 100%; height: ".(($cnt*90)+600)."px; border: 0px' ></object>";
  113. $text = "<iframe class='well' id='menu_iframe' src='".$url."' width='100%' scrolling='no' style='width: 100%; height: 800px; border: 0px' ></iframe>";
  114. return $text;
  115. }
  116. function menuRenderMessage()
  117. {
  118. // return $this->menuMessage;
  119. $text = e107::getMessage()->render('menuUi');
  120. // $text .= "ID = ".$this->menuId;
  121. return $text;
  122. }
  123. function menuAddMessage($message, $type = E_MESSAGE_INFO, $session = false)
  124. {
  125. e107::getMessage()->add(array($message, 'menuUi'), $type, $session);
  126. }
  127. // -------------------------------------------------------------------------
  128. function menuGrabLayout()
  129. {
  130. global $HEADER,$FOOTER,$CUSTOMHEADER,$CUSTOMFOOTER,$LAYOUT;
  131. if(isset($LAYOUT) && is_array($LAYOUT)) // $LAYOUT is a combined $HEADER,$FOOTER.
  132. {
  133. foreach($LAYOUT as $key=>$template)
  134. {
  135. list($hd,$ft) = explode("{---}",$template);
  136. $HEADER[$key] = isset($LAYOUT['_header_']) ? $LAYOUT['_header_'] . $hd : $hd;
  137. $FOOTER[$key] = isset($LAYOUT['_footer_']) ? $ft . $LAYOUT['_footer_'] : $ft ;
  138. }
  139. unset($hd,$ft);
  140. }
  141. if(($this->curLayout == 'legacyCustom' || $this->curLayout=='legacyDefault') && (isset($CUSTOMHEADER) || isset($CUSTOMFOOTER)) ) // 0.6 themes.
  142. {
  143. if($this->curLayout == 'legacyCustom')
  144. {
  145. $HEADER = ($CUSTOMHEADER) ? $CUSTOMHEADER : $HEADER;
  146. $FOOTER = ($CUSTOMFOOTER) ? $CUSTOMFOOTER : $FOOTER;
  147. }
  148. }
  149. elseif($this->curLayout && $this->curLayout != "legacyCustom" && (isset($CUSTOMHEADER[$this->curLayout]) || isset($CUSTOMFOOTER[$this->curLayout]))) // 0.7 themes
  150. {
  151. // echo " MODE 0.7 ".$this->curLayout;
  152. $HEADER = ($CUSTOMHEADER[$this->curLayout]) ? $CUSTOMHEADER[$this->curLayout] : $HEADER;
  153. $FOOTER = ($CUSTOMFOOTER[$this->curLayout]) ? $CUSTOMFOOTER[$this->curLayout] : $FOOTER;
  154. }
  155. elseif($this->curLayout && is_array($HEADER) && isset($HEADER[$this->curLayout]) && isset($FOOTER[$this->curLayout])) // 0.8 themes - we use only $HEADER and $FOOTER arrays.
  156. {
  157. // echo " MODE 0.8 ".$this->curLayout;
  158. $HEADER = $HEADER[$this->curLayout];
  159. $FOOTER = $FOOTER[$this->curLayout];
  160. }
  161. // Almost the same code as found in templates/header_default.php ---------
  162. }
  163. function menuGoConfig()
  164. {
  165. if(!$_GET['path'] || ($_GET['mode'] != "conf"))
  166. {
  167. return;
  168. }
  169. $file = urldecode($_GET['path']).".php";
  170. $newurl = e_PLUGIN_ABS.$file."?id=".$_GET['id'];
  171. /*
  172. return "<object type='text/html' id='menu_iframe' data='".$newurl."' width='100%' style='overflow:auto;width: 100%; border: 0px' ></object>";
  173. */
  174. header("Location: ".$newurl);
  175. exit;
  176. // echo "URL = ".$newurl;
  177. // $newurl = $PLUGINS_DIRECTORY.$location."/{$position}{$this->menuNewLoc}.php";
  178. // $newurl = SITEURL.str_replace("//", "/", $newurl);
  179. // echo "<script type='text/javascript'>alert($newurl); top.location.href = '{$newurl}'; </script> ";
  180. // exit;
  181. }
  182. // -----------------------------------------------------------------------------
  183. function menuModify()
  184. {
  185. global $admin_log;
  186. $pref = e107::getPref();
  187. $sql = e107::getDb();
  188. $ns = e107::getRender();
  189. $menu_act = "";
  190. if (isset($_POST['menuAct']))
  191. {
  192. foreach ($_POST['menuAct'] as $k => $v)
  193. {
  194. if (trim($v))
  195. {
  196. $this->menuId = intval($k);
  197. list($menu_act, $location, $position, $this->menuNewLoc) = explode(".", $_POST['menuAct'][$k]);
  198. }
  199. }
  200. }
  201. if ($menu_act == "move")
  202. {
  203. $this->menuMove();
  204. }
  205. if ($menu_act == "bot")
  206. {
  207. $menu_count = $sql->count("menus", "(*)", " WHERE menu_location='{$location}' AND menu_layout = '".$this->dbLayout."' ");
  208. $sql->db_Update("menus", "menu_order=".($menu_count+1)." WHERE menu_order='{$position}' AND menu_location='{$location}' AND menu_layout = '$this->dbLayout' ");
  209. $sql->db_Update("menus", "menu_order=menu_order-1 WHERE menu_location='{$location}' AND menu_order > {$position} AND menu_layout = '".$this->dbLayout."' ");
  210. $admin_log->log_event('MENU_06',$location.'[!br!]'.$position.'[!br!]'.$this->menuId,E_LOG_INFORMATIVE,'');
  211. }
  212. if ($menu_act == "top")
  213. {
  214. $sql->db_Update("menus", "menu_order=menu_order+1 WHERE menu_location='{$location}' AND menu_order < {$position} AND menu_layout = '".$this->dbLayout."' ",$this->debug);
  215. $sql->db_Update("menus", "menu_order=1 WHERE menu_id='{$this->menuId}' ");
  216. $admin_log->log_event('MENU_05',$location.'[!br!]'.$position.'[!br!]'.$this->menuId,E_LOG_INFORMATIVE,'');
  217. }
  218. if ($menu_act == "dec")
  219. {
  220. $sql->db_Update("menus", "menu_order=menu_order-1 WHERE menu_order='".($position+1)."' AND menu_location='{$location}' AND menu_layout = '".$this->dbLayout."' ",$this->debug);
  221. $sql->db_Update("menus", "menu_order=menu_order+1 WHERE menu_id='{$this->menuId}' AND menu_location='{$location}' AND menu_layout = '".$this->dbLayout."' ");
  222. $admin_log->log_event('MENU_08',$location.'[!br!]'.$position.'[!br!]'.$this->menuId,E_LOG_INFORMATIVE,'');
  223. }
  224. if ($menu_act == "inc")
  225. {
  226. $sql->db_Update("menus", "menu_order=menu_order+1 WHERE menu_order='".($position-1)."' AND menu_location='{$location}' AND menu_layout = '".$this->dbLayout."' ",$this->debug);
  227. $sql->db_Update("menus", "menu_order=menu_order-1 WHERE menu_id='{$this->menuId}' AND menu_location='{$location}' AND menu_layout = '".$this->dbLayout."' ");
  228. $admin_log->log_event('MENU_07',$location.'[!br!]'.$position.'[!br!]'.$this->menuId,E_LOG_INFORMATIVE,'');
  229. }
  230. if (!isset($_GET['configure']))
  231. { // Scan plugin directories to see if menus to add
  232. $this->menuScanMenus();
  233. }
  234. }
  235. // ----------------------------------------------------------------------------
  236. function menuSetPreset()
  237. {
  238. global $location,$admin_log;
  239. $pref = e107::getPref();
  240. $sql = e107::getDb();
  241. if(!$menuAreas = $this->getMenuPreset())
  242. {
  243. e107::getMessage()->addDebug("No Menu Preset Found");
  244. return FALSE;
  245. }
  246. $sql->db_Update("menus", "menu_location='0' WHERE menu_layout = '".$this->dbLayout."' "); // Clear All existing.
  247. foreach($menuAreas as $val)
  248. {
  249. if($sql->select("menus", 'menu_name, menu_path' , "menu_name = '".$val['menu_name']."' LIMIT 1"))
  250. {
  251. $row=$sql->fetch();
  252. if(!$sql->db_Update('menus', "menu_order='{$val['menu_order']}', menu_location = ".$val['menu_location'].", menu_class= ".$val['menu_class']." WHERE menu_name='".$val['menu_name']."' AND menu_layout = '".$this->dbLayout."' LIMIT 1 "))
  253. {
  254. $insert = array(
  255. 'menu_id' => 0,
  256. 'menu_name' => $val['menu_name'],
  257. 'menu_location' => $val['menu_location'],
  258. 'menu_order' => $val['menu_order'],
  259. 'menu_class' => $val['menu_class'],
  260. 'menu_pages' => '',
  261. 'menu_path' => $row['menu_path'],
  262. 'menu_layout' => $this->dbLayout,
  263. 'menu_parms' => ''
  264. );
  265. $sql->db_Insert("menus",$insert);
  266. $admin_log->log_event('MENU_01',$row['menu_name'].'[!br!]'.$location.'[!br!]'.$menu_count.'[!br!]'.$row['menu_path'],E_LOG_INFORMATIVE,'');
  267. }
  268. }
  269. }
  270. return $menuAreas;
  271. }
  272. // ----------------------------------------------------------------------------
  273. function menuScanMenus()
  274. {
  275. global $sql2;
  276. $sql = e107::getDb();
  277. $efile = new e_file;
  278. $efile->dirFilter = array('/', 'CVS', '.svn', 'languages');
  279. $fileList = $efile->get_files(e_PLUGIN,"_menu\.php$",'standard',2);
  280. foreach($fileList as $file)
  281. {
  282. list($parent_dir) = explode('/',str_replace(e_PLUGIN,"",$file['path']));
  283. $file['path'] = str_replace(e_PLUGIN,"",$file['path']);
  284. $file['fname'] = str_replace(".php","",$file['fname']);
  285. $valid_menu = FALSE;
  286. $existing_menu = $sql->count("menus", "(*)", "WHERE menu_name='{$file['fname']}'");
  287. if (file_exists(e_PLUGIN.$parent_dir.'/plugin.xml') || file_exists(e_PLUGIN.$parent_dir.'/plugin.php'))
  288. {
  289. if (e107::isInstalled($parent_dir))
  290. { // Its a 'new style' plugin with a plugin.php file, or an even newer one with plugin.xml file - only include if plugin installed
  291. $valid_menu = TRUE; // Whether new or existing, include in list
  292. // echo "Include {$parent_dir}:{$file['fname']}<br />";
  293. }
  294. }
  295. else // Just add the menu anyway
  296. {
  297. $valid_menu = TRUE;
  298. // echo "Default Include {$parent_dir}:{$file['fname']}<br />";
  299. }
  300. if ($valid_menu)
  301. {
  302. $menustr .= "&".str_replace(".php", "", $file['fname']);
  303. if (!$existing_menu) // New menu to add to list
  304. {
  305. $insert = array(
  306. 'menu_id' => 0,
  307. 'menu_name' => $file['fname'],
  308. 'menu_location' => 0,
  309. 'menu_order' => 0,
  310. 'menu_class' => 0,
  311. 'menu_pages' => '',
  312. 'menu_path' => $file['path'],
  313. 'menu_layout' => '',
  314. 'menu_parms' => ''
  315. );
  316. if($sql->db_Insert("menus",$insert))
  317. {
  318. // Could do admin logging here - but probably not needed
  319. $message .= MENLAN_10." - ".$file['fname']."<br />"; //FIXME
  320. }
  321. }
  322. }
  323. }
  324. //Reorder all menus into 1...x order
  325. if (!is_object($sql2)) $sql2 = new db; // Shouldn't be needed
  326. if (!is_object($sql3)) $sql3 = new db;
  327. $location_count = $sql3->select("menus", "menu_location", "menu_location>0 GROUP BY menu_location");
  328. while ($location_count)
  329. {
  330. if ($sql->select("menus", "menu_id", "menu_location={$location_count} ORDER BY menu_order ASC"))
  331. {
  332. $c = 1;
  333. while ($row = $sql->fetch())
  334. {
  335. $sql2->db_Update("menus", "menu_order={$c} WHERE menu_id=".$row['menu_id']);
  336. $c++;
  337. }
  338. }
  339. $location_count--;
  340. }
  341. $sql->select("menus", "*", "menu_path NOT REGEXP('[0-9]+') ");
  342. while (list($menu_id, $menu_name, $menu_location, $menu_order) = $sql->fetch(MYSQL_NUM))
  343. {
  344. if (stristr($menustr, $menu_name) === FALSE)
  345. {
  346. $sql2->db_Delete("menus", "menu_name='$menu_name'");
  347. $message .= MENLAN_11." - ".$menu_name."<br />"; // FIXME
  348. }
  349. }
  350. $this->menuAddMessage(vartrue($message), E_MESSAGE_INFO); //FIXME
  351. }
  352. // ---------------------------------------------------------------------------
  353. function menuPresetPerms($val)
  354. {
  355. $link_class = strtolower(trim($val));
  356. $menu_perm['everyone'] = e_UC_PUBLIC;
  357. $menu_perm['guest'] = e_UC_GUEST;
  358. $menu_perm['member'] = e_UC_MEMBER;
  359. $menu_perm['mainadmin'] = e_UC_MAINADMIN;
  360. $menu_perm['admin'] = e_UC_ADMIN;
  361. $menu_perm['nobody'] = e_UC_NOBODY;
  362. $link_class = ($menu_perm[$link_class]) ? $menu_perm[$link_class] : e_UC_PUBLIC;
  363. return $link_class;
  364. }
  365. /**
  366. * This one will be greatly extended, allowing menus to offer UI and us
  367. * settings per instance later ($parm variable available for menus - same as shortcode's $parm)
  368. */
  369. function menuInstanceParameters()
  370. {
  371. if(!vartrue($_GET['parmsId'])) return;
  372. $id = intval($_GET['parmsId']);
  373. $frm = e107::getForm();
  374. $sql = e107::getDb();
  375. if(!$sql->select("menus", "*", "menu_id=".$id))
  376. {
  377. $this->menuAddMessage("Couldn't Load Menu",E_MESSAGE_ERROR);
  378. return;
  379. };
  380. $row = $sql->fetch();
  381. // TODO lan
  382. $text = "<div style='text-align:center;'>
  383. <form id='e-save-form' method='post' action='".e_SELF."?lay=".$this->curLayout."'>
  384. <fieldset id='core-menus-parametersform'>
  385. <legend>Menu parameters ".$row['menu_name']."</legend>
  386. <table class='table adminform'>
  387. <tr>
  388. <td>
  389. Parameters (query string format):
  390. ".$frm->text('menu_parms', $row['menu_parms'], 900, 'class=e-save span7')."
  391. </td>
  392. </tr>
  393. </table>";
  394. /*
  395. $text .= "
  396. <div class='buttons-bar center'>";
  397. $text .= $frm->admin_button('parms_submit', LAN_SAVE, 'update');
  398. $text .= "<input type='hidden' name='menu_id' value='".$id."' />
  399. </div>";
  400. */
  401. $text .= $frm->hidden('mode','parms');
  402. $text .= $frm->hidden('menu_id',$id);
  403. $text .= "
  404. </fieldset>
  405. </form>
  406. </div>";
  407. return $text;
  408. }
  409. function menuVisibilityOptions()
  410. {
  411. if(!vartrue($_GET['vis'])) return;
  412. $sql = e107::getDb();
  413. $ns = e107::getRender();
  414. $frm = e107::getForm();
  415. require_once(e_HANDLER."userclass_class.php");
  416. if(!$sql->select("menus", "*", "menu_id=".intval($_GET['vis'])))
  417. {
  418. $this->menuAddMessage("Couldn't Load Menu",E_MESSAGE_ERROR);
  419. return;
  420. }
  421. $row = $sql->fetch();
  422. $listtype = substr($row['menu_pages'], 0, 1);
  423. $menu_pages = substr($row['menu_pages'], 2);
  424. $menu_pages = str_replace("|", "\n", $menu_pages);
  425. $text = "<div>
  426. <form class='form-horizontal' id='e-save-form' method='post' action='".e_SELF."?lay=".$this->curLayout."&amp;iframe=1'>
  427. <fieldset>
  428. <legend>". MENLAN_7." ".$row['menu_name']."</legend>
  429. <table class='table adminform'>
  430. <tr>
  431. <td>
  432. <input type='hidden' name='menuAct[{$row['menu_id']}]' value='sv.{$row['menu_id']}' />
  433. ".MENLAN_4." ".
  434. r_userclass('menu_class', $row['menu_class'], "off", "public,member,guest,admin,main,classes,nobody")."
  435. </td>
  436. </tr>
  437. <tr><td><div class='radio'>
  438. ";
  439. $checked = ($listtype == 1) ? " checked='checked' " : "";
  440. $text .= $frm->radio('listtype', 1, $checked, array('label'=>MENLAN_26, 'class'=> 'e-save'));
  441. $text .= "<br />";
  442. // $text .= "<input type='radio' class='e-save' {$checked} name='listtype' value='1' /> ".MENLAN_26."<br />";
  443. $checked = ($listtype == 2) ? " checked='checked' " : "";
  444. $text .= $frm->radio('listtype', 2, $checked, array('label'=>MENLAN_27, 'class'=> 'e-save'));
  445. // $text .= "<input type='radio' class='e-save' {$checked} name='listtype' value='2' /> ".MENLAN_27."<br />";
  446. $text .= "</div>
  447. <div class='row' style='padding:10px'>
  448. <div class='pull-left span3' >
  449. <textarea name='pagelist' class='e-save span3' cols='60' rows='8' class='tbox'>$menu_pages</textarea>
  450. </div>
  451. <div class=' span4'><small>".MENLAN_28."</small></div>
  452. </div></td></tr>
  453. </table>";
  454. $text .= $frm->hidden('mode','visibility');
  455. $text .= $frm->hidden('menu_id',intval($_GET['vis'])); // "<input type='hidden' name='menu_id' value='".intval($_GET['vis'])."' />";
  456. /*
  457. $text .= "
  458. <div class='buttons-bar center'>";
  459. $text .= $frm->admin_button('class_submit', MENLAN_6, 'update');
  460. </div>";
  461. */
  462. $text .= "
  463. </fieldset>
  464. </form>
  465. </div>";
  466. return $text;
  467. //$caption = MENLAN_7." ".$row['menu_name'];
  468. //$ns->tablerender($caption, $text);
  469. //echo $text;
  470. }
  471. // -----------------------------------------------------------------------------
  472. function menuActivate() // Activate Multiple Menus.
  473. {
  474. global $admin_log;
  475. $pref = e107::getPref();
  476. $sql = e107::getDb();
  477. $location = $this->menuActivateLoc;
  478. $menu_count = $sql->count("menus", "(*)", " WHERE menu_location=".$location." AND menu_layout = '".$this->dbLayout."' ");
  479. $menu_count++; // Need to add 1 to create NEW order number.
  480. foreach($this->menuActivateIds as $sel_mens)
  481. {
  482. //Get info from menu being activated
  483. if($sql->select("menus", 'menu_name, menu_path' , "menu_id = ".intval($sel_mens)." "))
  484. {
  485. $row=$sql->fetch();
  486. //If menu is not already activated in that area, add the record.
  487. //$query = "SELECT menu_name,menu_path FROM #menus WHERE menu_name='".$row['menu_name']."' AND menu_layout = '".$this->dbLayout."' AND menu_location = ".$location." LIMIT 1 ";
  488. //if(!$sql->gen($query, $this->debug))
  489. {
  490. $insert = array(
  491. 'menu_id' => 0,
  492. 'menu_name' => $row['menu_name'],
  493. 'menu_location' => $location,
  494. 'menu_order' => $menu_count,
  495. 'menu_class' => $row['menu_class'],
  496. 'menu_pages' => '',
  497. 'menu_path' => $row['menu_path'],
  498. 'menu_layout' => $this->dbLayout,
  499. 'menu_parms' => ''
  500. );
  501. $sql->db_Insert("menus",$insert, $this->debug);
  502. $admin_log->log_event('MENU_01',$row['menu_name'].'[!br!]'.$location.'[!br!]'.$menu_count.'[!br!]'.$row['menu_path'],E_LOG_INFORMATIVE,'');
  503. $menu_count++;
  504. }
  505. }
  506. }
  507. }
  508. // -----------------------------------------------------------------------------
  509. function menuSetCustomPages($array)
  510. {
  511. $pref = e107::getPref();
  512. $key = key($array);
  513. $pref['sitetheme_custompages'][$key] = array_filter(explode(" ",$array[$key]));
  514. save_prefs();
  515. }
  516. // ------------------------------------------------------------------------------
  517. function getMenuPreset()
  518. {
  519. $pref = e107::getPref();
  520. $layout = $this->curLayout;
  521. if(!isset($pref['sitetheme_layouts'][$layout]['menuPresets']))
  522. {
  523. e107::getMessage()->addDebug(print_a($pref['sitetheme_layouts'],true));
  524. return FALSE;
  525. }
  526. $temp = $pref['sitetheme_layouts'][$layout]['menuPresets']['area'];
  527. // print_a($temp);
  528. $multiple = isset($temp['menu'][1]);
  529. foreach($temp as $key=>$val)
  530. {
  531. if($val['id'])
  532. {
  533. $iD = $val['id'];
  534. }
  535. // $iD = $val['id'];
  536. if($key == 'menu')
  537. {
  538. if($multiple) // More than one menu item under <area> in theme.xml.
  539. {
  540. foreach($val as $k=>$v)
  541. {
  542. // $uclass = (defined(trim($v['@attributes']['perm']))) ? constant(trim($v['@attributes']['userclass'])) : 0;
  543. $menuArea[] = array(
  544. 'menu_location' => $iD,
  545. 'menu_order' => $k,
  546. 'menu_name' => $v['@attributes']['name']."_menu",
  547. 'menu_class' => $this->menuPresetPerms($v['@attributes']['perm'])
  548. );
  549. }
  550. }
  551. else // Only one menu item under <area> in theme.xml.
  552. {
  553. // $uclass = (defined(trim($val['menu']['@attributes']['userclass']))) ? constant(trim($val['menu']['@attributes']['userclass'])) : 0;
  554. $menuArea[] = array(
  555. 'menu_location' => $iD,
  556. 'menu_order' => 0,
  557. 'menu_name' => $val['menu']['@attributes']['name']."_menu",
  558. 'menu_class' => $this->menuPresetPerms($v['@attributes']['perm'])
  559. );
  560. }
  561. }
  562. }
  563. // print_a($menuArea);
  564. return $menuArea;
  565. }
  566. // ------------------------------------------------------------------------------
  567. function checkMenuPreset($array,$name)
  568. {
  569. if(!is_array($array))
  570. {
  571. return;
  572. }
  573. foreach($array as $key=>$val)
  574. {
  575. if($val['menu_name']==$name)
  576. {
  577. return $val['menu_location'];
  578. }
  579. }
  580. return FALSE;
  581. }
  582. // --------------------------------------------------------------------------
  583. function menuSaveParameters()
  584. {
  585. $sql = e107::getDb();
  586. $parms = $sql->escape(strip_tags($_POST['menu_parms']));
  587. $check = $sql->db_Update("menus", "menu_parms='".$parms."' WHERE menu_id=".intval($_POST['menu_id'])."");
  588. if($check)
  589. {
  590. return array('msg'=>'All Okay','error'=>false);
  591. // FIXME - menu log
  592. //$admin_log->log_event('MENU_02',$_POST['menu_parms'].'[!br!]'.$parms.'[!br!]'.$this->menuId,E_LOG_INFORMATIVE,'');
  593. // $this->menuAddMessage(LAN_SAVED,E_MESSAGE_SUCCESS);
  594. }
  595. elseif(false === $check)
  596. {
  597. return array('msg'=>LAN_UPDATED_FAILED,'error'=>true);
  598. }
  599. else
  600. {
  601. return array('msg'=>'No Changes Made','error'=>false); // $this->menuAddMessage(LAN_NOCHANGE_NOTSAVED,E_MESSAGE_INFO);
  602. }
  603. }
  604. // --------------------------------------------------------------------------
  605. function menuSaveVisibility() // Used by Ajax
  606. {
  607. global $admin_log;
  608. $sql = e107::getDb();
  609. $pagelist = explode("\r\n", $_POST['pagelist']);
  610. for ($i = 0 ; $i < count($pagelist) ; $i++)
  611. {
  612. $pagelist[$i] = trim($pagelist[$i]);
  613. }
  614. $plist = implode("|", $pagelist);
  615. $pageparms = $_POST['listtype'].'-'.$plist;
  616. $pageparms = preg_replace("#\|$#", "", $pageparms);
  617. $pageparms = (trim($_POST['pagelist']) == '') ? '' : $pageparms;
  618. if($sql->db_Update("menus", "menu_class='".intval($_POST['menu_class'])."', menu_pages='{$pageparms}' WHERE menu_id=".intval($_POST['menu_id'])))
  619. {
  620. $admin_log->log_event('MENU_02',$_POST['menu_class'].'[!br!]'.$pageparms.'[!br!]'.$this->menuId,E_LOG_INFORMATIVE,'');
  621. return array('msg'=>LAN_UPDATED, 'error'=> false);
  622. //$this->menuAddMessage($message,E_MESSAGE_SUCCESS);
  623. }
  624. else
  625. {
  626. return array('msg'=>LAN_UPDATED_FAILED, 'error'=> true, 'posted'=>$_POST);
  627. // $this->menuAddMessage($message,E_MESSAGE_ERROR);
  628. }
  629. }
  630. function setMenuId($id)
  631. {
  632. $this->menuId = intval($id);
  633. }
  634. // -----------------------------------------------------------------------
  635. function menuDeactivate()
  636. { // Get current menu name
  637. global $admin_log;
  638. $sql = e107::getDb();
  639. $sql2 = e107::getDb();
  640. //echo "FOUND= ".$this->menuId;
  641. $error = false;
  642. if($sql->gen('SELECT menu_name, menu_location, menu_order FROM #menus WHERE menu_id = '.$this->menuId.' LIMIT 1'))
  643. {
  644. $row = $sql->fetch();
  645. //Check to see if there is already a menu with location = 0 (to maintain BC)
  646. if($sql2->select('menus', 'menu_id', "menu_name='{$row['menu_name']}' AND menu_location = 0 AND menu_layout ='".$this->dbLayout."' LIMIT 1"))
  647. {
  648. //menu_location=0 already exists, we can just delete this record
  649. if(!$sql2->db_Delete('menus', 'menu_id='.$this->menuId))
  650. {
  651. $message = "Deletion Failed";
  652. $error = true;
  653. }
  654. }
  655. else
  656. {
  657. //menu_location=0 does NOT exist, let's just convert this to it
  658. if(!$sql2->db_Update("menus", "menu_location=0, menu_order=0, menu_class=0, menu_pages='' WHERE menu_id=".$this->menuId))
  659. {
  660. $message = "FAILED";
  661. $error = true;
  662. }
  663. }
  664. //Move all menus up (reduces order number) that have a higher menu order number than one deactivated, in the selected location.
  665. $sql->db_Update("menus", "menu_order=menu_order-1 WHERE menu_location={$row['menu_location']} AND menu_order > {$row['menu_order']} AND menu_layout = '".$this->dbLayout."' ");
  666. $admin_log->log_event('MENU_04',$row['menu_name'].'[!br!]'.$row['menu_location'].'[!br!]'.$row['menu_order'].'[!br!]'.$this->menuId,E_LOG_INFORMATIVE,'');
  667. }
  668. else
  669. {
  670. $message = "NO CHANGES MADE : ".$this->menuId;
  671. $error = true;
  672. }
  673. return array('msg'=>$message,'error'=>$error);
  674. }
  675. // ----------------------------------------------------------------------
  676. function menuMove()
  677. {// Get current menu name
  678. global $admin_log,$sql;
  679. if($sql->select('menus', 'menu_name', 'menu_id='.$this->menuId, 'default'))
  680. {
  681. $row = $sql->fetch();
  682. //Check to see if menu is already active in the new area, if not then move it
  683. if(!$sql->select('menus', 'menu_id', "menu_name='{$row['menu_name']}' AND menu_location = ".$this->menuNewLoc." AND menu_layout='".$this->dbLayout ."' LIMIT 1"))
  684. {
  685. $menu_count = $sql->count("menus", "(*)", " WHERE menu_location=".$this->menuNewLoc);
  686. $sql->db_Update("menus", "menu_location='{$this->menuNewLoc}', menu_order=".($menu_count+1)." WHERE menu_id=".$this->menuId);
  687. $sql->db_Update("menus", "menu_order=menu_order-1 WHERE menu_location='{$location}' AND menu_order > {$position} AND menu_layout='".$this->dbLayout ."' ");
  688. }
  689. $admin_log->log_event('MENU_03',$row['menu_name'].'[!br!]'.$this->menuNewLoc.'[!br!]'.$this->menuId,E_LOG_INFORMATIVE,'');
  690. }
  691. }
  692. // =-----------------------------------------------------------------------------
  693. function renderOptionRow($row)
  694. {
  695. $sql = e107::getDb();
  696. $tp = e107::getParser();
  697. $ns = e107::getRender();
  698. $frm = e107::getForm();
  699. $text = "";
  700. $pdeta = "";
  701. $color = ($color == "white") ? "#DDDDDD" : "white";
  702. if($row['menu_pages'] == "dbcustom")
  703. {
  704. $pdeta = MENLAN_42;
  705. }
  706. else
  707. {
  708. $row['menu_name'] = preg_replace("#_menu$#i", "", $row['menu_name']);
  709. if($pnum = $this->checkMenuPreset($menuPreset,$row['menu_name'].'_menu'))
  710. {
  711. $pdeta = MENLAN_39." {$pnum}";
  712. }
  713. }
  714. if(!$this->dragDrop)
  715. {
  716. $menuInf = (!is_numeric($row['menu_path'])) ? ' ('.substr($row['menu_path'],0,-1).')' : " ( #".$row['menu_path']." )";
  717. // $menuInf = $row['menu_path'];
  718. $text .= "<tr style='background-color:$color;color:black'>
  719. <td style='text-align:left; color:black;' class='checkbox'>";
  720. // $text .= "
  721. //// <input type='checkbox' id='menuselect-{$row['menu_id']}' name='menuselect[]' value='{$row['menu_id']}' />
  722. // <label class='selection-row' for='menuselect-{$row['menu_id']}'>".$row['menu_name'].$menuInf."</label>";
  723. $text .= $frm->checkbox('menuselect[]',$row['menu_id'],'',array('label'=>$row['menu_name'].$menuInf));
  724. $text .= "
  725. </td>
  726. <td style='color:black'>&nbsp; ".$pdeta."&nbsp;</td>
  727. </tr>\n";
  728. }
  729. else
  730. {
  731. // Menu Choices box.
  732. $text .= "<div class='portlet block block-archive' id='block-".$row['menu_id']."' style='border:1px outset black;text-align:left;color:black'>";
  733. $text .= $this->menuRenderMenu($row, $menu_count,true);
  734. $text .= "</div>\n";
  735. }
  736. return $text;
  737. }
  738. function menuRenderPage()
  739. {
  740. global $HEADER, $FOOTER, $rs;
  741. $pref = e107::getPref();
  742. $sql = e107::getDb();
  743. $tp = e107::getParser();
  744. $ns = e107::getRender();
  745. $frm = e107::getForm();
  746. //FIXME - XHTML cleanup, front-end standards (elist, forms etc)
  747. echo "<div id='portal'>";
  748. $this->parseheader($HEADER); // $layouts_str;
  749. $layout = ($this->curLayout);
  750. $menuPreset = $this->getMenuPreset($layout);
  751. echo "<div style='text-align:center'>";
  752. echo $rs->form_open("post", e_SELF."?configure=".$this->curLayout, "menuActivation");
  753. $text = "<table style='width:100%;margin-left:auto;margin-right:auto'>";
  754. $text .= "<tr><td style='color:#2F2F2F;width:65%;text-align:center;padding-bottom:8px'>".MENLAN_36."...</td>
  755. <td style='color:#2F2F2F;width:50%;padding-bottom:8px;text-align:center'>...".MENLAN_37."</td></tr>";
  756. $text .= "<tr><td style='width:35%;vertical-align:top;text-align:center'>";
  757. if(!$this->dragDrop)
  758. {
  759. $text .= "<div class='column' id='portal-column-block-list' style='border:1px inset black;height:250px;display:block;overflow:auto;margin-bottom:20px'>";
  760. $text .= "<table class='table table-striped core-menumanager-main' id='core-menumanager-main' >
  761. <tbody>\n";
  762. }
  763. else
  764. {
  765. // $text .= "<div class='column' id='remove' style='border:1px solid silver'>\n";
  766. }
  767. $color = "";
  768. $pageMenu = array();
  769. $pluginMenu = array();
  770. $sql->select("menus", "menu_name, menu_id, menu_pages, menu_path", "1 GROUP BY menu_name ORDER BY menu_name ASC");
  771. while ($row = $sql->fetch())
  772. {
  773. if(is_numeric($row['menu_path']))
  774. {
  775. $pageMenu[] = $row;
  776. }
  777. else
  778. {
  779. $pluginMenu[] = $row;
  780. }
  781. }
  782. $text .= "<tr><th colspan='2'>Your Menus</th></tr>";
  783. foreach($pageMenu as $row)
  784. {
  785. $text .= $this->renderOptionRow($row);
  786. }
  787. $text .= "<tr><th colspan='2' >Plugin Menus</th></tr>";
  788. foreach($pluginMenu as $row)
  789. {
  790. $text .= $this->renderOptionRow($row);
  791. }
  792. $text .= (!$this->dragDrop) ? "</tbody></table>" : "";
  793. $text .= "</div>";
  794. $text .= "</td><td id='menu-manage-actions' ><br />";
  795. foreach ($this->menu_areas as $menu_act)
  796. {
  797. $text .= "<input type='submit' class='menu-btn' id='menuActivate_".trim($menu_act)."' name='menuActivate[".trim($menu_act)."]' value='".MENLAN_13." ".trim($menu_act)."' /><br /><br />\n";
  798. }
  799. if($layout)
  800. {
  801. if(isset($pref['sitetheme_layouts'][$layout]['menuPresets']))
  802. {
  803. $text .= "<input type='submit' class='menu-btn' name='menuUsePreset' value=\"".MENLAN_40."\" onclick=\"return jsconfirm('".$tp->toJS(MENLAN_41)."')\" /><br /><br />\n"; // Use Menu Presets
  804. $text .= "<input type='hidden' name='menuPreset' value='".$layout."' />";
  805. }
  806. $text .= "<input type='hidden' name='curLayout' value='".$layout."' />";
  807. }
  808. $text .= "<input type='hidden' id='dbLayout' value='".$this->dbLayout."' />";
  809. $text .= "</td>";
  810. $text .= "</tr></table>";
  811. if(!count($this->menu_areas))
  812. {
  813. $text = "<div class='alert alert-block alert-warning text-left'>";
  814. $text .= "This layout does NOT contain any dynamic {MENU} areas.<br />";
  815. if(count($this->customMenu))
  816. {
  817. $text .= "<p>It DOES contain the following custom menus: <ul ><li>".implode("</li><li>",$this->customMenu)."</li></ul></p>";
  818. $text .= "<p><a href='".e_ADMIN."cpage.php?mode=menu&action=list&tab=2' class='button btn btn-primary'>Go to Custom-Menu area</a></p>";
  819. }
  820. $text .= "</div>";
  821. }
  822. // $ns -> tablerender(MENLAN_22.'blabla', $text);
  823. echo $this->renderPanel(MENLAN_22, $text);
  824. echo $rs->form_close();
  825. echo "</div>";
  826. $this->parseheader($FOOTER);
  827. if($this->debug)
  828. {
  829. echo "<div id='debug' style='margin-left:0px;border:1px solid silver; overflow:scroll;height:250px'> &nbsp;</div>";
  830. }
  831. echo "</div>";
  832. }
  833. //------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------//
  834. function menuSelectLayout()
  835. {
  836. global $rs;
  837. $pref = e107::getPref();
  838. // onchange=\"urljump(this.options[selectedIndex].value);\"
  839. $text = "<form class='form-inline' method='post' action='".e_SELF."?configure=".$this->curLayout."'>";
  840. $text .= "<div class='buttons-bar'>Theme Layout: ";
  841. $text .= "<select name='custom_select' style='width:auto' id='menuManagerSelect' >\n"; //tbox class will break links. // window.frames['menu_iframe'].location=this.options[selectedIndex].value ???
  842. $search = array("_","legacyDefault","legacyCustom");
  843. $replace = array(" ",MENLAN_31,MENLAN_33);
  844. foreach($pref['sitetheme_layouts'] as $key=>$val)
  845. {
  846. $url = "";
  847. $layoutName = str_replace($search,$replace,$key);
  848. $layoutName .=($key==$pref['sitetheme_deflayout']) ? " (".MENLAN_31.")" : "";
  849. $selected = ($this->curLayout == $key || ($key==$pref['sitetheme_deflayout'] && $this->curLayout=='')) ? "selected='selected'" : FALSE;
  850. // $url = e_SELF."?lay=".$key;
  851. $url = e_SELF."?configure=".$key;
  852. $text .= "<option value='".$url."' {$selected}>".$layoutName."</option>";
  853. }
  854. $text .= "</select>
  855. <div class='field-help'>".MENLAN_30."</div>
  856. </div></form>";
  857. // $text .= "<div id='visibility'>Something here</div>";
  858. return $text;
  859. }
  860. //------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------//
  861. function parseheader($LAYOUT, $check = FALSE)
  862. {
  863. // $tmp = explode("\n", $LAYOUT);
  864. // Split up using the same function as the shortcode handler
  865. $tmp = preg_split('#(\{\S[^\x02]*?\S\})#', $LAYOUT, -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE);
  866. $str = array();
  867. for($c = 0; $c < count($tmp); $c++)
  868. {
  869. if(preg_match("/[\{|\}]/", $tmp[$c]))
  870. {
  871. if($check)
  872. {
  873. if(strstr($tmp[$c], "{MENU="))
  874. {
  875. $matches = array();
  876. // Match all menu areas, menu number is limited to tinyint(3)
  877. preg_match_all("/\{MENU=([\d]{1,3})(:[\w\d]*)?\}/", $tmp[$c], $matches);
  878. $this->menuSetCode($matches, $str);
  879. }
  880. }
  881. else
  882. {
  883. $this->checklayout($tmp[$c]);
  884. }
  885. }
  886. else
  887. {
  888. if(!$check)
  889. {
  890. echo $tmp[$c];
  891. }
  892. }
  893. }
  894. if($check)
  895. {
  896. return $str;
  897. }
  898. }
  899. function menuSetCode($matches, &$ret)
  900. {
  901. if(!$matches || !varsettrue($matches[1]))
  902. {
  903. return;
  904. }
  905. foreach ($matches[1] as $match)
  906. {
  907. $ret[] = $match;
  908. }
  909. }
  910. function renderPanel($caption,$text)
  911. {
  912. $plugtext = "<div class='menu-panel'>";
  913. $plugtext .= "<div class='menu-panel-header' title=\"".MENLAN_34."\">".$caption."</div>";
  914. $plugtext .= $text;
  915. $plugtext .= "</div>";
  916. return $plugtext;
  917. }
  918. function checklayout($str)
  919. { // Displays a basic representation of the theme
  920. global $PLUGINS_DIRECTORY, $rs, $sc_style, $menu_order, $style; // global $style required.
  921. $PLUGINS_DIRECTORY = e107::getFolder('PLUGINS');
  922. $pref = e107::getPref();
  923. $tp = e107::getParser();
  924. $ns = e107::getRender();
  925. $menuLayout = ($this->curLayout != $pref['sitetheme_deflayout']) ? $this->curLayout : "";
  926. if(strstr($str, "LOGO"))
  927. {
  928. echo $tp->parseTemplate("{LOGO}");
  929. }
  930. elseif(strstr($str, "SITENAME"))
  931. {
  932. echo "[SiteName]";
  933. }
  934. elseif(strstr($str, "SITETAG"))
  935. {
  936. echo "<div style='padding: 2px'>[SiteTag]</div>";
  937. }
  938. elseif(strstr($str, "SITELINKS"))
  939. {
  940. echo "[SiteLinks]";
  941. }
  942. elseif(strstr($str, "NAVIGATION"))
  943. {
  944. echo "[Navigation Area]";
  945. }
  946. elseif(strstr($str, "LANGUAGELINKS"))
  947. {
  948. echo "<div class=text style='padding: 2px; text-align: center'>[Language]</div>";
  949. }
  950. elseif(strstr($str, "CUSTOM"))
  951. {
  952. $cust = preg_replace("/\W*\{CUSTOM=(.*?)(\+.*)?\}\W*/si", "\\1", $str);
  953. echo "<div style='padding: 2px'>[" . $cust . "]</div>";
  954. }
  955. elseif(strstr($str, "CMENU"))
  956. {
  957. $cust = preg_replace("/\W*\{CMENU=(.*?)(\+.*)?\}\W*/si", "\\1", $str);
  958. $this->customMenu[] = $cust;
  959. echo $tp->parseTemplate("{CMENU=".$cust."}",true);
  960. // echo $this->renderPanel('Embedded Custom Menu',$cust);
  961. }
  962. elseif(strstr($str, "SETIMAGE"))
  963. {
  964. $cust = preg_replace("/\W*\{SETIMAGE(.*?)(\+.*)?\}\W*/si", "\\1", $str);
  965. echo $tp->parseTemplate("{SETIMAGE".$cust."}",true);
  966. // echo $this->renderPanel('Embedded Custom Menu',$cust);
  967. }
  968. elseif(strstr($str, "{WMESSAGE"))
  969. {
  970. echo "<div class=text style='padding: 30px; text-align: center'>[Welcome Message Area]</div>";
  971. // echo $this->renderPanel('Embedded Custom Menu',$cust);
  972. }
  973. elseif(strstr($str, "{FEATUREBOX"))
  974. {
  975. echo "<div class=text style='padding: 80px; text-align: center'>[Featurebox Area]</div>";
  976. // echo $this->renderPanel('Embedded Custom Menu',$cust);
  977. }
  978. // Display embedded Plugin information.
  979. else if(strstr($str, "PLUGIN"))
  980. {
  981. $plug = preg_replace("/\{PLUGIN=(.*?)\}/si", "\\1", $str);
  982. $plug = trim($plug);
  983. if(file_exists((e_PLUGIN . "{$plug}/{$plug}_config.php")))
  984. {
  985. $link = e_PLUGIN . "{$plug}/{$plug}_config.php";
  986. }
  987. if(file_exists((e_PLUGIN . $plug . "/config.php")))
  988. {
  989. $link = e_PLUGIN . $plug . "/config.php";
  990. }
  991. // $plugtext = "<div class='menu-panel'>";
  992. // $plugtext .= "<div class='menu-panel-header' title=\"".MENLAN_34."\">".$plug."</div>";
  993. $plugtext = ($link) ? "(" . MENLAN_34 . ":<a href='$link btn-menu' title='" . LAN_CONFIGURE . "'>" . LAN_CONFIGURE . "</a>)" : "";
  994. // $plugtext .= "</div>";
  995. echo "<br />";
  996. echo $this->renderPanel($plug, $plugtext);
  997. // $ns->tablerender($plug, $plugtext);
  998. }
  999. else if(strstr($str, "MENU"))
  1000. {
  1001. $matches = array();
  1002. if(preg_match_all("/\{MENU=([\d]{1,3})(:[\w\d]*)?\}/", $str, $matches))
  1003. {
  1004. $menuText = "";
  1005. foreach($matches[1] as $menu)
  1006. {
  1007. $menu = preg_replace("/\{MENU=(.*?)(:.*?)?\}/si", "\\1", $str);
  1008. if(isset($sc_style['MENU']['pre']) && strpos($str, 'ret') !== false)
  1009. {
  1010. $menuText .= $sc_style['MENU']['pre'];
  1011. }
  1012. // ---------------
  1013. $menuText .= "\n\n<!-- START AREA ".$menu." -->";
  1014. $menuText .= "<div id='start-area-".$menu."' class='menu-panel'>";
  1015. $menuText .= "<div class='menu-panel-header' >" . MENLAN_14 . " " . $menu . "</div>\n\n";
  1016. $sql9 = new db();
  1017. // $sql9 = e107::getDb('sql9');
  1018. if($sql9->count("menus", "(*)", " WHERE menu_location='$menu' AND menu_layout = '" . $this->dbLayout . "' "))
  1019. {
  1020. unset($text);
  1021. $menuText .= $rs->form_open("post", e_SELF . "?configure=" . $this->curLayout, "frm_menu_" . intval($menu));
  1022. $MODE = 1;
  1023. $sql9->select("menus", "*", "menu_location='$menu' AND menu_layout='" . $this->dbLayout . "' ORDER BY menu_order");
  1024. $menu_count = $sql9->db_Rows();
  1025. $cl = ($this->dragDrop) ? "'portlet" : "regularMenu";
  1026. $menuText .= "\n<div class='column' id='area-".$menu."'>\n\n";
  1027. while($row = $sql9->fetch(MYSQL_ASSOC))
  1028. {
  1029. $menuText .= "\n\n\n <!-- Menu Start ".$row['menu_name']. "-->\n";
  1030. $menuText .= "<div class='{$cl}' id='block-".$row['menu_id']."-".$menu."'>\n";
  1031. // echo "<div class='ggportal'>";
  1032. // $menuText .= "hi there";
  1033. $menuText .= $this->menuRenderMenu($row, $menu_count);
  1034. // echo "\n</div>";
  1035. $menuText .= "\n</div>\n";
  1036. $menuText .= "<!-- Menu end -->\n\n\n";
  1037. // echo "<div><br /></div>";
  1038. }
  1039. $menuText .= "\n\n</div>\n\n"; // End Column
  1040. $menuText .= $rs->form_close();
  1041. }
  1042. else
  1043. { // placeholder
  1044. $menuText .= "<div class='column' id='area-" . $menu . "'><!-- --></div>";
  1045. }
  1046. $menuText .= "</div><!-- END OF AREA -->\n\n";
  1047. // ---------------
  1048. if(isset($sc_style['MENU']['post']) && strpos($str, 'ret') !== false)
  1049. {
  1050. $menuText .= $sc_style['MENU']['post'];
  1051. }
  1052. }
  1053. }
  1054. echo $menuText;
  1055. }
  1056. else if(strstr($str, "SETSTYLE"))
  1057. {
  1058. $tmp = explode("=", $str);
  1059. $style = preg_replace("/\{SETSTYLE=(.*?)\}/si", "\\1", $str);
  1060. $this->style = $style;
  1061. }
  1062. else if(strstr($str, "SITEDISCLAIMER"))
  1063. {
  1064. echo "[Sitedisclaimer]";
  1065. }
  1066. }
  1067. //------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------//
  1068. function menuRenderMenu($row,$menu_count,$rep = FALSE)
  1069. {
  1070. global $rs,$menu,$menu_info,$menu_act, $style;
  1071. $ns = e107::getRender();
  1072. $style = $this->style;
  1073. // $menu_count is empty in here
  1074. //FIXME extract
  1075. extract($row);
  1076. if(!$menu_id){ return; }
  1077. $menu_name = preg_replace("#_menu#i", "", $menu_name);
  1078. //TODO we need a CSS class for this
  1079. $vis = ($menu_class || strlen($menu_pages) > 1) ? " <span class='required'><i class='icon-search'></i></span> " : "";
  1080. //DEBUG div not allowed in final tags $caption = "<div style='text-align:center'>{$menu_name}{$vis}</div>";
  1081. // use theme render style instead
  1082. // Undocumented special parameter 'admin_title'
  1083. $menuParms = array();
  1084. if(!empty($row['menu_parms'])) parse_str($row['menu_parms'], $menuParms);
  1085. if(isset($menuParms['admin_title']) && $menuParms['admin_title'])
  1086. {
  1087. $caption = deftrue($menuParms['admin_title'], $menuParms['admin_title']).$vis;
  1088. }
  1089. elseif(isset($menuParms['title']) && $menuParms['title'])
  1090. {
  1091. $caption = deftrue($menuParms['title'], $menuParms['title']).$vis;
  1092. }
  1093. else $caption = $menu_name.$vis;
  1094. $menu_info = "{$menu_location}.{$menu_order}";
  1095. $text = "";
  1096. $conf = '';
  1097. if (file_exists(e_PLUGIN.$menu_path.$menu_name.'_menu_config.php'))
  1098. {
  1099. $conf = $menu_path.$menu_name.'_menu_config';
  1100. }
  1101. if($conf == '' && file_exists(e_PLUGIN."{$menu_path}config.php"))
  1102. {
  1103. $conf = "{$menu_path}config";
  1104. }
  1105. //
  1106. // $text = "<div style='white-space:nowrap'>";
  1107. $text .= '<div class="menuOptions">';
  1108. if(!$this->dragDrop)
  1109. {
  1110. $text .= "<select id='menuAct_".$menu_id."' name='menuAct[$menu_id]' class='menu-btn' onchange='this.form.submit()' >";
  1111. $text .= $rs->form_option(MENLAN_25, TRUE, " ");
  1112. // $text .= $rs->form_option(MENLAN_15, "", "deac.{$menu_info}");
  1113. if ($conf)
  1114. {
  1115. // $text .= $rs->form_option("Configure", "", $conf); // TODO Check LAN availability
  1116. }
  1117. if ($menu_order != 1)
  1118. {
  1119. $text .= $rs->form_option(MENLAN_17, "", "inc.{$menu_info}");
  1120. $text .= $rs->form_option(MENLAN_24, "", "top.{$menu_info}");
  1121. }
  1122. if ($menu_count != $menu_order)
  1123. {
  1124. $text .= $rs->form_option(MENLAN_18, "", "dec.{$menu_info}");
  1125. $text .= $rs->form_option(MENLAN_23, "", "bot.{$menu_info}");
  1126. }
  1127. foreach ($this->menu_areas as $menu_act)
  1128. {
  1129. if ($menu != $menu_act)
  1130. {
  1131. $text .= $rs->form_option(MENLAN_19." ".$menu_act, "", "move.{$menu_info}.".$menu_act);
  1132. }
  1133. }
  1134. // Visibility is an action icon now
  1135. //$text .= $rs->form_option(MENLAN_20, "", "adv.{$menu_info}");
  1136. $text .= $rs->form_select_close();
  1137. }
  1138. if($rep == true)
  1139. {
  1140. $text .= "<div id='check-".$menu_id."'><input type='checkbox' name='menuselect[]' value='{$menu_id}' />".$menu_id." {$pdeta}</div>
  1141. <div id='option-".$menu_id."' style='display:none'>";
  1142. }
  1143. //DEBUG remove inline style, switch to simple quoted string for title text value
  1144. //TODO hardcoded text
  1145. // $visibilityLink = e_SELF.'?'.urlencode('lay='.$this->curLayout.'&amp;vis='.$menu_id.'&amp;iframe=1');
  1146. $visibilityLink = e_SELF."?enc=".base64_encode('lay='.$this->curLayout.'&vis='.$menu_id.'&iframe=1');
  1147. $text .= '<span class="menu-options-buttons">
  1148. <a class="e-menumanager-option menu-btn" data-modal-caption="'.MENLAN_20.'" href="'.$visibilityLink.'" title="'.MENLAN_20.'"><i class="S16 e-search-16"></i></a>';
  1149. if($conf)
  1150. {
  1151. $text .= '<a class="menu-btn" target="_top" href="'.e_SELF.'?lay='.$this->curLayout.'&amp;mode=conf&amp;path='.urlencode($conf).'&amp;id='.$menu_id.'"
  1152. title="Configure menu"><i class="S16 e-configure-16"></i></a>';
  1153. }
  1154. $editLink = e_SELF."?enc=".base64_encode('lay='.$this->curLayout.'&parmsId='.$menu_id.'&iframe=1');
  1155. $text .= '<a data-modal-caption="Configure parameters" class="e-menumanager-option menu-btn e-tip" target="_top" href="'.$editLink.'" title="Configure parameters"><i class="S16 e-edit-16" ></i></a>';
  1156. $text .= '<a title="'.LAN_DELETE.'" id="remove-'.$menu_id.'-'.$menu_location.'" class="e-tip delete e-menumanager-delete menu-btn" href="'.e_SELF.'?configure='.$this->curLayout.'&amp;mode=deac&amp;id='.$menu_id.'"><i class="S16 e-delete-16"></i></a>
  1157. <span id="status-'.$menu_id.'" style="display:none">'.($rep == true ? "" : "insert").'</span>
  1158. </span></div>';
  1159. $text .= ($rep == true) ? "</div>" : "";
  1160. // $text .= "</div>";
  1161. if(!$this->dragDrop)
  1162. {
  1163. return "<b class='muted' style='color:#2F2F2F;text-align:left'>".$caption."</b><br />". $text;
  1164. // return;
  1165. // return $ns->tablerender($caption, $text,'', true); Theme style too unpredictable.
  1166. }
  1167. else
  1168. {
  1169. return "
  1170. <div class='portlet-header'>".$caption."</div>
  1171. <div class='portlet-content' >".$text."</div>";
  1172. }
  1173. }
  1174. function menuSaveAjax($mode = null)
  1175. {
  1176. if($mode == 'visibility')
  1177. {
  1178. $ret = $this->menuSaveVisibility();
  1179. // echo json_encode($ret);
  1180. return;
  1181. }
  1182. if($mode == 'delete')
  1183. {
  1184. list($tmp,$area) = explode("-",$_POST['area']);
  1185. if($_POST['area'] == 'remove')
  1186. {
  1187. list($tmp,$deleteID) = explode("-",$_POST['removeid']);
  1188. $this->menuId = $deleteID;
  1189. $ret = $this->menuDeactivate();
  1190. // echo json_encode($ret);
  1191. return;
  1192. }
  1193. }
  1194. if($mode == 'parms')
  1195. {
  1196. $ret = $this->menuSaveParameters();
  1197. // echo json_encode($ret);
  1198. return;
  1199. }
  1200. // print_r($_POST);
  1201. return;
  1202. $this->debug = TRUE;
  1203. $sql = e107::getDb();
  1204. // Allow deletion by ajax, but not the rest when drag/drop disabled.
  1205. if(!$this->dragDrop){ return; }
  1206. $this -> dbLayout = $_POST['layout'];
  1207. list($tmp,$insertID) = explode("-",$_POST['insert']);
  1208. $insert[] = $insertID;
  1209. if($_POST['mode'] == 'insert' && count($insert) && $area) // clear out everything before rewriting everything to db.
  1210. {
  1211. $this->menuActivateLoc = $area; // location
  1212. $this->menuActivateIds = $insert; // array of ids, in order.
  1213. $this->menuActivate();
  1214. }
  1215. elseif($_POST['mode'] == 'update')
  1216. {
  1217. $sql->db_Update("menus","menu_location = ".intval($area)." WHERE menu_id = ".intval($insertID)."",$this->debug);
  1218. }
  1219. $c = 0;
  1220. if(count($_POST['list'])<2)
  1221. {
  1222. return;
  1223. }
  1224. // resort the menus in this 'Area"
  1225. foreach($_POST['list'] as $val)
  1226. {
  1227. list($b,$id) = explode("-",$val);
  1228. $order[] = $id;
  1229. $sql->db_Update("menus","menu_order = ".$c." WHERE menu_id = ".intval($id)."",$this->debug);
  1230. $c++;
  1231. }
  1232. // same for delete etc.
  1233. // echo "<hr />";
  1234. }
  1235. function menuSetConfigList()
  1236. {
  1237. $sql = e107::getDb();
  1238. $pref = e107::getPref();
  1239. $sql -> select("menus", "*", "menu_location != 0 ORDER BY menu_path,menu_name");
  1240. while($row = $sql-> fetch())
  1241. {
  1242. $link = "";
  1243. extract($row);
  1244. $id = substr($menu_path,0,-1);
  1245. if (file_exists(e_PLUGIN."{$menu_path}{$menu_name}_menu_config.php"))
  1246. {
  1247. $link = "{$menu_path}{$menu_name}_menu_config.php";
  1248. }
  1249. if(file_exists(e_PLUGIN."{$menu_path}config.php"))
  1250. {
  1251. $link = "{$menu_path}config.php";
  1252. }
  1253. if($link)
  1254. {
  1255. $tmp[$id]['name'] = ucwords(str_replace("_menu","",$menu_name));
  1256. if(vartrue($prev) == $id && ($tmp[$id]['name']!=$prev_name))
  1257. {
  1258. $tmp[$id]['name'] .= ":".$prev_name;
  1259. }
  1260. $tmp[$id]['link'] = $link;
  1261. $prev = $id;
  1262. $prev_name = $tmp[$id]['name'];
  1263. }
  1264. }
  1265. $pref['menuconfig_list'] = vartrue($tmp);
  1266. e107::getConfig()->setPref($pref)->save(false,true,false);
  1267. // save_prefs();
  1268. }
  1269. } // end of Class.