diff --git a/resources/classes/menu.php b/resources/classes/menu.php index cfcf9e028d..3b65a2d2d4 100644 --- a/resources/classes/menu.php +++ b/resources/classes/menu.php @@ -78,18 +78,20 @@ if (!class_exists('menu')) { //get the $apps array from the installed apps from the core and mod directories $config_list = glob($_SERVER["DOCUMENT_ROOT"].PROJECT_PATH."/*/*/app_menu.php"); $x = 0; - foreach ($config_list as &$config_path) { - $app_path = dirname($config_path); - $app_path = preg_replace('/\A.*(\/.*\/.*)\z/', '$1', $app_path); - $y = 0; - try { - //echo "[".$x ."] ".$config_path."\n"; - include($config_path); - $x++; - } - catch (Exception $e) { - echo 'exception caught: ' . $e->getMessage() . "\n"; - exit; + if (is_array($config_list)) { + foreach ($config_list as &$config_path) { + $app_path = dirname($config_path); + $app_path = preg_replace('/\A.*(\/.*\/.*)\z/', '$1', $app_path); + $y = 0; + try { + //echo "[".$x ."] ".$config_path."\n"; + include($config_path); + $x++; + } + catch (Exception $e) { + echo 'exception caught: ' . $e->getMessage() . "\n"; + exit; + } } } @@ -102,111 +104,115 @@ if (!class_exists('menu')) { $language = new text; //use the app array to restore the default menu - foreach ($apps as $row) { - foreach ($row['menu'] as $menu) { - //set the variables - if (strlen($menu['title'][$this->menu_language]) > 0) { - $menu_item_title = $menu['title'][$this->menu_language]; - } - else { - $menu_item_title = $menu['title']['en-us']; - } - $menu_item_uuid = $menu['uuid']; - $menu_item_parent_uuid = $menu['parent_uuid']; - $menu_item_category = $menu['category']; - $menu_item_icon = $menu['icon']; - $menu_item_path = $menu['path']; - $menu_item_order = $menu['order']; - $menu_item_description = $menu['desc']; - - //menu found set the default - $menu_item_exists = true; - - //if the item uuid is not currently in the db then add it - $sql = "select * from v_menu_items "; - $sql .= "where menu_uuid = '".$this->menu_uuid."' "; - $sql .= "and menu_item_uuid = '".$menu_item_uuid."' "; - $prep_statement = $db->prepare(check_sql($sql)); - if ($prep_statement) { - $prep_statement->execute(); - $result = $prep_statement->fetchAll(PDO::FETCH_ASSOC); - if (count($result) == 0) { - - //menu found the menu - $menu_item_exists = false; - - //insert the default menu into the database - $sql = "insert into v_menu_items "; - $sql .= "("; - $sql .= "menu_item_uuid, "; - $sql .= "menu_uuid, "; - $sql .= "menu_item_title, "; - $sql .= "menu_item_link, "; - $sql .= "menu_item_category, "; - $sql .= "menu_item_icon, "; - if (strlen($menu_item_order) > 0) { - $sql .= "menu_item_order, "; - } - if (strlen($menu_item_parent_uuid) > 0) { - $sql .= "menu_item_parent_uuid, "; - } - $sql .= "menu_item_description "; - $sql .= ") "; - $sql .= "values "; - $sql .= "("; - $sql .= "'".$menu_item_uuid."', "; - $sql .= "'".$this->menu_uuid."', "; - $sql .= "'".check_str($menu_item_title)."', "; - $sql .= "'$menu_item_path', "; - $sql .= "'$menu_item_category', "; - $sql .= "'$menu_item_icon', "; - if (strlen($menu_item_order) > 0) { - $sql .= "'$menu_item_order', "; - } - if (strlen($menu_item_parent_uuid) > 0) { - $sql .= "'$menu_item_parent_uuid', "; - } - $sql .= "'$menu_item_description' "; - $sql .= ")"; - if ($menu_item_uuid == $menu_item_parent_uuid) { - //echo $sql."
\n"; - } - else { - $db->exec(check_sql($sql)); - } - unset($sql); - } - } - - //set the menu languages - if (!$menu_item_exists) { - foreach ($language->languages as $menu_language) { - $menu_item_title = $menu["title"][$menu_language]; - if(strlen($menu_item_title) == 0) { - $menu_item_title = $menu["title"]['en-us']; + if (is_array($apps)) { + foreach ($apps as $row) { + if (is_array($row['menu'])) { + foreach ($row['menu'] as $menu) { + //set the variables + if (strlen($menu['title'][$this->menu_language]) > 0) { + $menu_item_title = $menu['title'][$this->menu_language]; } - $menu_language_uuid = uuid(); - $sql = "insert into v_menu_languages "; - $sql .= "("; - $sql .= "menu_language_uuid, "; - $sql .= "menu_item_uuid, "; - $sql .= "menu_uuid, "; - $sql .= "menu_language, "; - $sql .= "menu_item_title "; - $sql .= ") "; - $sql .= "values "; - $sql .= "("; - $sql .= "'".$menu_language_uuid."', "; - $sql .= "'".$menu_item_uuid."', "; - $sql .= "'".$this->menu_uuid."', "; - $sql .= "'".$menu_language."', "; - $sql .= "'".check_str($menu_item_title)."' "; - $sql .= ")"; - $db->exec(check_sql($sql)); - unset($sql); - } - } + else { + $menu_item_title = $menu['title']['en-us']; + } + $menu_item_uuid = $menu['uuid']; + $menu_item_parent_uuid = $menu['parent_uuid']; + $menu_item_category = $menu['category']; + $menu_item_icon = $menu['icon']; + $menu_item_path = $menu['path']; + $menu_item_order = $menu['order']; + $menu_item_description = $menu['desc']; + //menu found set the default + $menu_item_exists = true; + + //if the item uuid is not currently in the db then add it + $sql = "select * from v_menu_items "; + $sql .= "where menu_uuid = '".$this->menu_uuid."' "; + $sql .= "and menu_item_uuid = '".$menu_item_uuid."' "; + $prep_statement = $db->prepare(check_sql($sql)); + if ($prep_statement) { + $prep_statement->execute(); + $result = $prep_statement->fetchAll(PDO::FETCH_ASSOC); + if (count($result) == 0) { + + //menu found the menu + $menu_item_exists = false; + + //insert the default menu into the database + $sql = "insert into v_menu_items "; + $sql .= "("; + $sql .= "menu_item_uuid, "; + $sql .= "menu_uuid, "; + $sql .= "menu_item_title, "; + $sql .= "menu_item_link, "; + $sql .= "menu_item_category, "; + $sql .= "menu_item_icon, "; + if (strlen($menu_item_order) > 0) { + $sql .= "menu_item_order, "; + } + if (strlen($menu_item_parent_uuid) > 0) { + $sql .= "menu_item_parent_uuid, "; + } + $sql .= "menu_item_description "; + $sql .= ") "; + $sql .= "values "; + $sql .= "("; + $sql .= "'".$menu_item_uuid."', "; + $sql .= "'".$this->menu_uuid."', "; + $sql .= "'".check_str($menu_item_title)."', "; + $sql .= "'$menu_item_path', "; + $sql .= "'$menu_item_category', "; + $sql .= "'$menu_item_icon', "; + if (strlen($menu_item_order) > 0) { + $sql .= "'$menu_item_order', "; + } + if (strlen($menu_item_parent_uuid) > 0) { + $sql .= "'$menu_item_parent_uuid', "; + } + $sql .= "'$menu_item_description' "; + $sql .= ")"; + if ($menu_item_uuid == $menu_item_parent_uuid) { + //echo $sql."
\n"; + } + else { + $db->exec(check_sql($sql)); + } + unset($sql); + } + } + + //set the menu languages + if (!$menu_item_exists and is_array($language->languages)) { + foreach ($language->languages as $menu_language) { + $menu_item_title = $menu["title"][$menu_language]; + if(strlen($menu_item_title) == 0) { + $menu_item_title = $menu["title"]['en-us']; + } + $menu_language_uuid = uuid(); + $sql = "insert into v_menu_languages "; + $sql .= "("; + $sql .= "menu_language_uuid, "; + $sql .= "menu_item_uuid, "; + $sql .= "menu_uuid, "; + $sql .= "menu_language, "; + $sql .= "menu_item_title "; + $sql .= ") "; + $sql .= "values "; + $sql .= "("; + $sql .= "'".$menu_language_uuid."', "; + $sql .= "'".$menu_item_uuid."', "; + $sql .= "'".$this->menu_uuid."', "; + $sql .= "'".$menu_language."', "; + $sql .= "'".check_str($menu_item_title)."' "; + $sql .= ")"; + $db->exec(check_sql($sql)); + unset($sql); + } + } + + } + } } } @@ -227,46 +233,52 @@ if (!class_exists('menu')) { $prep_statement = $db->prepare(check_sql($sql)); $prep_statement->execute(); $result = $prep_statement->fetchAll(PDO::FETCH_ASSOC); - foreach ($result as $row) { - $group_uuids[$row['group_name']] = $row['group_uuid']; + if (is_array($result)) { + foreach ($result as $row) { + $group_uuids[$row['group_name']] = $row['group_uuid']; + } } unset($sql, $prep_statement, $result); //if there are no groups listed in v_menu_item_groups under menu_item_uuid then add the default groups - foreach($apps as $app) { - foreach ($app['menu'] as $sub_row) { - if (isset($sub_row['groups'])) foreach ($sub_row['groups'] as $group) { - $sql = "select count(*) as count from v_menu_item_groups "; - $sql .= "where menu_item_uuid = '".$sub_row['uuid']."' "; - $sql .= "and menu_uuid = '".$this->menu_uuid."' "; - $sql .= "and group_name = '".$group."' "; - $sql .= "and group_uuid = '".$group_uuids[$group]."' "; - //echo $sql."
"; - $prep_statement = $db->prepare($sql); - $prep_statement->execute(); - $sub_result = $prep_statement->fetch(PDO::FETCH_ASSOC); - unset ($prep_statement); - if ($sub_result['count'] == 0) { - //no menu item groups found add the defaults - $sql = "insert into v_menu_item_groups "; - $sql .= "( "; - $sql .= "menu_item_group_uuid, "; - $sql .= "menu_uuid, "; - $sql .= "menu_item_uuid, "; - $sql .= "group_name, "; - $sql .= "group_uuid "; - $sql .= ") "; - $sql .= "values "; - $sql .= "( "; - $sql .= "'".uuid()."', "; - $sql .= "'".$this->menu_uuid."', "; - $sql .= "'".$sub_row['uuid']."', "; - $sql .= "'".$group."', "; - $sql .= "'".$group_uuids[$group]."' "; - $sql .= ") "; - //echo $sql."
"; - $db->exec(check_sql($sql)); - unset($sql); + if (is_array($apps)) { + foreach($apps as $app) { + if (is_array($apps)) { + foreach ($app['menu'] as $sub_row) { + if (isset($sub_row['groups'])) foreach ($sub_row['groups'] as $group) { + $sql = "select count(*) as count from v_menu_item_groups "; + $sql .= "where menu_item_uuid = '".$sub_row['uuid']."' "; + $sql .= "and menu_uuid = '".$this->menu_uuid."' "; + $sql .= "and group_name = '".$group."' "; + $sql .= "and group_uuid = '".$group_uuids[$group]."' "; + //echo $sql."
"; + $prep_statement = $db->prepare($sql); + $prep_statement->execute(); + $sub_result = $prep_statement->fetch(PDO::FETCH_ASSOC); + unset ($prep_statement); + if ($sub_result['count'] == 0) { + //no menu item groups found add the defaults + $sql = "insert into v_menu_item_groups "; + $sql .= "( "; + $sql .= "menu_item_group_uuid, "; + $sql .= "menu_uuid, "; + $sql .= "menu_item_uuid, "; + $sql .= "group_name, "; + $sql .= "group_uuid "; + $sql .= ") "; + $sql .= "values "; + $sql .= "( "; + $sql .= "'".uuid()."', "; + $sql .= "'".$this->menu_uuid."', "; + $sql .= "'".$sub_row['uuid']."', "; + $sql .= "'".$group."', "; + $sql .= "'".$group_uuids[$group]."' "; + $sql .= ") "; + //echo $sql."
"; + $db->exec(check_sql($sql)); + unset($sql); + } + } } } } @@ -291,16 +303,17 @@ if (!class_exists('menu')) { $_SESSION['groups'][0]['group_name'] = 'public'; } - foreach($menu_array as $menu_field) { - //set the variables + if (is_array($menu_array)) { + foreach($menu_array as $menu_field) { + //set the variables $menu_item_link = $menu_field['menu_item_link']; $menu_item_category = $menu_field['menu_item_category']; $menu_items = $menu_field['menu_items']; - - //prepare the protected menus + + //prepare the protected menus $menu_item_title = ($menu_field['menu_item_protected'] == "true") ? $menu_field['menu_item_title'] : $menu_field['menu_language_title']; - - //prepare the menu_tags according to the category + + //prepare the menu_tags according to the category $menu_tags = ''; switch ($menu_item_category) { case "internal": @@ -317,41 +330,42 @@ if (!class_exists('menu')) { break; } - if ($menu_item_level == 0) { - $menu_html = "\n\n"; + } - $menu_html_full .= $menu_html; - } //end for each + $menu_html_full .= $menu_html; + } //end for each + } return $menu_html_full; } //end function @@ -366,7 +380,7 @@ if (!class_exists('menu')) { $_SESSION['groups'][0]['group_name'] = 'public'; } - if (count($submenu_array) > 0) { + if (is_array($submenu_array)) { //child menu found $submenu_html = "