Warning: chmod(): Operation not permitted in /var/www/hopeinstoughton_www/wp-content/plugins/simple-universal-google-analytics/main.php on line 8 [0] in function chmod in /var/www/hopeinstoughton_www/wp-content/plugins/simple-universal-google-analytics/main.php on line 8 [1] in function include_once in /var/www/hopeinstoughton_www/wp-settings.php on line 560 [2] in function require_once in /var/www/hopeinstoughton_www/wp-config.php on line 85 [3] in function require_once in /var/www/hopeinstoughton_www/wp-load.php on line 50 [4] in function require_once in /var/www/hopeinstoughton_www/wp-blog-header.php on line 13 [5] in function require in /var/www/hopeinstoughton_www/index.php on line 17
| Server IP : 94.177.8.99 / Your IP : 216.73.217.165 Web Server : Apache/2.4.58 (Ubuntu) System : Linux aries 6.8.0-134-generic #134-Ubuntu SMP PREEMPT_DYNAMIC Fri Jun 26 18:43:11 UTC 2026 x86_64 User : www-data ( 33) PHP Version : 8.1.34 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : OFF Directory : /var/www/theyoungdesigners_com/modules/pageFooter/model/ |
Upload File : |
<?php
// menu editor - drag and drop items
class MenuEdit_Model extends Database_Model {
var $MENUS = [ 'menu1' => 'Top Menu',
// 'menu2' => 'Footer Line',
'menu3' => 'Footer Widgets',
'menu4' => 'Mobile Menu' ];
const MENUFLAG = 0;
const MENUFLAG_SEPARATOR = 1; // menu item is a menu separator (not currently implemented)
const MENUFLAG_OVERRIDE = 2; // menu caption has been overridden from the default
const MENUFLAG_PUBLIC = 4; // is a public function in a controller (as opposed to a CMS page)
const MENUFLAG_CUSTOM = 8; // custom item (text, email, phonenumber, etc) from the database
public function LoadMenus($dynamic) {
$pagelist = $dynamic;
$sep = ['c' => 'Home', 'l' => '/', 's' => self::MENUFLAG_OVERRIDE];
array_unshift($pagelist, $sep);
// $sep = ['c' => '----------', 'l' => FALSE, 's' => self::MENUFLAG_SEPARATOR];
// array_unshift($pagelist, $sep);
// $pagelist[] = $sep;
// add static pages in alpha order to pagelist
// add special "links" - email address, copyright, etc
$this->_AppendCustomMenus($pagelist);
// add custom menuoptions to the list of available options
$pagelist = hook_execute('menu.addoption', $pagelist);
foreach($pagelist as &$item) {
$title = $item['v'] ?? $item['c'];
if (isset($item['l'])) $title .= " [{$item['l']}]";
$item['h'] = $title;
}
$result = ['source' => $pagelist];
// add current menu items
$menus = $this->SettingGet('menus', []);
foreach($this->MENUS as $name => $caption) {
if (isset($menus[$name])) {
$items = $menus[$name];
$this->_AddDynamicContent($items);
} else {
$items = [];
}
$result[$name] = ['caption' => $caption, 'items' => $items];
}
return $result;
}
private function _AppendCustomMenus(&$pagelist) {
$data = $this->Query('select mc_id,mc_caption from menu_custom')
->OrderBy('mc_id desc')
->Get();
foreach($data as $data_item) {
$pagelist[] = [ 'c' => $data_item->mc_caption,
'v' => ExpandMacro($data_item->mc_caption, FALSE),
// 'l' => '', // these do not have links (links calcuated later, based on caption text)
's' => self::MENUFLAG_OVERRIDE | self::MENUFLAG_CUSTOM,
'id' => $data_item->mc_id ];
}
}
public function SaveMenus($post, $page) {
unset($post['auth']);
// remove unused stuff
foreach($post as $key => &$menuitems) {
foreach($menuitems as &$item) {
if ($item['cls'] != '') {
$item['class'] = $item['cls'];
}
unset($item['cls']);
}
}
$this->SettingSet('menus', $post);
$this->__CONFIG->Save(); // .htconfig
}
public function RetrieveMenu($menu_id) {
$menus = $this->SettingGet('menus', []);
$output = [];
$c = isset($menus[$menu_id]) ? count($menus[$menu_id]) : 0;
if ($c) {
$menuitems = $menus[$menu_id];
$position = 0;
$this->ProcessMenu($output, $menuitems, $position, $c);
}
$output = hook_execute('menu.retrieve', $output, $menu_id);
return $output;
}
private function ProcessMenu(&$output, $menuitems, &$position, $c) {
$indent = $menuitems[$position]['i'];
while ($position < $c && $menuitems[$position]['i'] == $indent) {
$x = $menuitems[$position];
$menuflags = intval($x['s']);
$className = isset($x['class']) ? $x['class'] : '';
$caption = ExpandMacro($x['c']);
$node = ['class' => $className, 'href' => $x['l'], 'caption' => $caption, 's' => $menuflags ];
$position++;
if ($position < $c && $menuitems[$position]['i'] > $indent) {
$node['menu'] = [];
$this->processMenu($node['menu'], $menuitems, $position, $c);
}
if (!($menuflags & self::MENUFLAG_SEPARATOR)) $output[] = $node;
if ($position < $c && $menuitems[$position]['i'] < $indent) break;
}
}
public function getEditPopup($result, $param, $dynamic) {
// get the default title
$default_value = '';
if (!($param['flags'] & self::MENUFLAG_PUBLIC)) {
foreach($dynamic as $item) {
if ($item['l'] == $param['href']) {
$default_value = $item['c'];
break;
}
}
}
$isDefault = $param['flags'] & self::MENUFLAG_OVERRIDE ? 0 : 1;
$isCustom = $param['flags'] & self::MENUFLAG_CUSTOM ? 1 : 0;
$title = 'Edit Menu Item';
if ($isCustom && empty($param['id'])) $title = 'New Menu Item';
$node = [
'popup' => [
'title' => $title,
'template' => 'menuedit_detail',
'modal' => true,
'width' => 500,
'caption' => $param['caption'],
'default' => $isDefault,
'custom' => $isCustom,
'link' => $param['href'],
'active' => $param['active'],
'idx' => $param['idx'],
'id' => $param['id'],
'initial' => $default_value,
'page' => $param['page'],
'auth' => hook_execute('nonce.create', FALSE, 'menuedit', $param['active'] . ':' . $param['idx'], 15 * 60),
],
'execute' => 'menuedit.disableCaption',
];
if (!$isCustom) {
$node['popup']['footer'] = 'Menus must be saved for any<br>changes here to take effect';
}
return $node;
}
public function MenuItem_UpdateTitle($path, $newtitle) {
$changed = FALSE;
// Change titles where the caption has not been overridden
$menus = $this->SettingGet('menus', []);
foreach($menus as &$menu) {
foreach($menu as &$menu_item) {
if ($menu_item['l'] == $path && !($menu_item['s'] & self::MENUFLAG_OVERRIDE)) {
$changed = TRUE;
$menu_item['c'] = $newtitle;
}
}
}
if ($changed) {
$this->SettingSet('menus', $menus);
$this->__CONFIG->Save();
}
}
function _AddDynamicContent(&$menu) {
foreach($menu as &$menu_item) {
// if ($menu_item['s'] & self::MENUFLAG_CUSTOM) {
//$menu_item['v'] = $this->AsVisible($menu_item['c'], FALSE);
// }
}
}
//to do: add authorization
public function UpdateCustomMenu($id, $caption) {
$id = intval($id);
$key = $id ? $id : NULL;
$data = $this->TableName('menu_custom')
->AutoInc('mc_id')
->InsertOrUpdate([
'mc_id' => $key,
],[
'mc_caption' => $caption,
]);
$id = (int) $data->mc_id;
return array('id' => $id,
'v' => ExpandMacro($caption, FALSE));
}
//to do: add authorization
public function RemoveCustomMenu($id) {
$this->Query('delete from menu_custom')
->where('mc_id=%d', $id)
->Get();
return [
'id' => '0',
'status' => 'ok',
];
}
public function AddDynamicContent(&$navigation) {
$this->_scanMenu($navigation);
}
private function _scanMenu(&$menu) {
foreach($menu as &$menu_item) {
$s = empty($menu_item['s']) ? 0 : $menu_item['s'];
if ($s & self::MENUFLAG_CUSTOM) {
$menu_item['caption'] = ExpandMacro($menu_item['caption'], TRUE);
}
if (isset($menu_item['menu'])) {
$this->_scanMenu($menu_item['menu']);
}
}
}
private function _menuitem($x) {
$class = empty($x['class']) ? '' : $x['class'];
if ($x['href'] == '' || $x['href'] == 'false') {
if ($class == '') $class = 'plaintext';
$class = empty($class) ? '' : " class=\"{$class}\"";
return "<span$class>{$x['caption']}</span>";
} else {
$class = empty($class) ? '' : " class=\"{$class}\"";
return "<a$class href=\"{$x['href']}\">{$x['caption']}</a>";
}
}
private function _GenerateSubmenu_footer($menu) {
$output = '';
foreach($menu as $menu_item) {
if ($menu_item['caption'] == '[social]') {
$link = $this->_GenerateSubmenu_social($menu_item['menu']);
} else {
$link = $this->_menuitem($menu_item);
if (isset($menu_item['menu'])) {
$link .= $this->_GenerateSubmenu_footer($menu_item['menu']);
}
}
$output .= "<li class=\"list-icon\">$link</li>";
}
return "<ul class=\"list-unstyled\">$output</ul>";
}
private function _GenerateSubmenu_social($icons) {
$output = '';
foreach($icons as $icon) {
$link = $this->_menuitem($icon);
$output .= "<li>" . $link . "</li>";
}
return <<<BLOCK
<ul class="list-unstyled d-flex d-inline-flex list-social-icons">
$output
</ul>
BLOCK;
return '';
}
function GenerateMenu_footer($navigation) {
$output = '';
foreach((array)$navigation as $top_level) {
if (isset($top_level['menu'])) {
$submenu = $this->_GenerateSubmenu_footer($top_level['menu']);
$output .= <<<BLOCK
<div class="col-lg-3 col-md-3">
<div class="footer-contact">
<h3>{$top_level['caption']}</h3>
{$submenu}
</div>
</div>
BLOCK;
} else {
$item = $this->_menuitem($top_level);
$output .= <<<BLOCK
<div class="col-lg-3 col-md-3">
<div class="footer-contact">
<h3>{$item}</h3>
</div>
</div>
BLOCK;
}
}
return $output;
}
public function generateFooter($menuname, $settings) {
// the default menu (normally just login/logout) is ignored, and completely replaced by the admin/menuedit
[$key, $subkey] = explode('.', $menuname);
$info = $this->RetrieveMenu($subkey);
$menu2 = $this->GenerateMenu_footer($info);
$bg = $settings['bgcolor'] ?? '';
$fg = $settings['color'] ?? '';
if ($bg != '') $bg = "background-color:{$bg};";
if ($fg != '') $fg = "color:{$fg};";
return <<<BLOCK
<footer class="footer-section" style="{$bg}{$fg}">
<div class="container">
<div class="footer-wrap">
<div class="row">{$menu2}</div>
</div>
</div>
</footer>
BLOCK;
}
/*
$class = empty($x['class']) ? '' : " class=\"{$x['class']}\"";
return "<a$class href=\"{$x['href']}\">{$x['caption']}</a>";
*/
}