From 5eef464cf336bd7d245e2472c54819296b1e258a Mon Sep 17 00:00:00 2001 From: markjcrane Date: Sat, 26 Mar 2016 12:22:15 -0600 Subject: [PATCH] Additional work to improve the install, template and the menu. --- core/install/install.php | 76 ++++++------ resources/classes/menu.php | 226 +++++++++++++++++++----------------- resources/footer.php | 2 +- resources/header.php | 2 +- themes/default/template.php | 2 +- 5 files changed, 157 insertions(+), 151 deletions(-) diff --git a/core/install/install.php b/core/install/install.php index 8e0b850b42..745a370051 100644 --- a/core/install/install.php +++ b/core/install/install.php @@ -124,12 +124,6 @@ $language = new text; $text = $language->get(); -//set a default template - $default_template = 'default'; - if (isset($_SESSION['domain']['template']['name']) and strlen($_SESSION['domain']['template']['name']) != 0) { - $default_template = $_SESSION['domain']['template']['name']; - } - //set a default enviroment if first_time //initialize some varibles to cut down on warnings $_SESSION['message'] = ''; @@ -138,9 +132,6 @@ $default_login = 0; $onload = ''; -//get the contents of the template and save it to the template variable - $template = file_get_contents($_SERVER["DOCUMENT_ROOT"].PROJECT_PATH.'/themes/'.$default_template.'/template.php'); - //buffer the content ob_end_clean(); //clean the buffer ob_start(); @@ -215,7 +206,7 @@ echo " \n"; echo " \n"; echo "
\n"; - echo " \n"; + echo " \n"; echo "
\n"; echo "\n"; } elseif($install_step == 'detect_config'){ @@ -232,14 +223,14 @@ echo " \n"; echo " \n"; echo "
\n"; - echo " \n"; - echo " \n"; + echo " \n"; + echo " \n"; echo "
\n"; echo "\n"; } else { echo "
\n"; echo "
\n"; - echo " \n"; + echo " \n"; echo "
\n"; echo "
\n"; } @@ -329,8 +320,8 @@ }else { echo "
\n"; echo "
\n"; - echo " \n"; - echo " \n"; + echo " \n"; + echo " \n"; echo "
\n"; echo "
\n"; } @@ -340,44 +331,47 @@ echo "

Unkown install_step '$install_step'

\n"; } -//get the default theme - $set_session_theme = 1; - $domains_processed = 1; - include "themes/".$default_template."/template.php"; - unset($set_session_theme, $domains_processed); //initialize some defaults so we can be 'logged in' //$_SESSION['username'] = 'install_enabled'; //$_SESSION['permissions'][]['permission_name'] = 'superadmin'; //$_SESSION['menu'] = ''; +//show errors + ini_set('display_errors', '1'); + //error_reporting (E_ALL); // Report everything + //error_reporting (E_ALL ^ E_NOTICE); // Report everything + error_reporting(E_ALL ^ E_NOTICE ^ E_WARNING ); //hide notices and warnings + //add the content to the template and then send output $body = ob_get_contents(); //get the output from the buffer ob_end_clean(); //clean the buffer - //replace known used constants - $body = str_replace ("", PROJECT_PATH, $body); //defined in /resources/menu.php +//set a default template + $default_template = 'default'; + $_SESSION['domain']['template']['name'] = $default_template; +//set the default template path + $template_path = $_SERVER["DOCUMENT_ROOT"].PROJECT_PATH.'/themes/'.$default_template.'/template.php'; + +//get the content of the template + $template_content = file_get_contents($template_path); + +//replace the variables in the template + $template_content = str_replace ("", $document['title'], $template_content); // defined in each individual page + $template_content = str_replace ("", '', $template_content); // defined in each individual page + //$template_content = str_replace ("", $_SESSION["menu"], $template_content); //included in the theme + $template_content = str_replace ("", $body, $template_content); //defined in /themes/default/template.php + $template_content = str_replace ("", PROJECT_PATH, $template_content); //defined in /themes/default/template.php + +//get the contents of the template and save it to the template variable ob_start(); - eval('?>' . $template . '' . $template_content . '", $document['title'], $template); // defined in each individual page - $output = str_replace ("", $custom_head, $output); // defined in each individual page - $output = str_replace ("", $_SESSION["menu"], $output); //defined in /resources/menu.php - $output = str_replace ("", PROJECT_PATH, $output); //defined in /resources/menu.php - - $pos = strrpos($output, ""); - if ($pos === false) { - $output = $body; //if tag not found just show the body - } - else { - //replace the body - $output = str_replace ("", $body, $output); - } - - echo $output; - unset($output); +//send the content to the browser and then clear the variable + echo $content; ?> \ No newline at end of file diff --git a/resources/classes/menu.php b/resources/classes/menu.php index bf0d8f74bb..5f202789ab 100644 --- a/resources/classes/menu.php +++ b/resources/classes/menu.php @@ -386,24 +386,102 @@ //create the menu array function menu_array($sql, $menu_item_level) { - $db = $this->db; + //get the database connnection return immediately if it doesn't exist + if ($this->db) { + $db = $this->db; + }else { + return; + } - if (!isset($_SESSION['groups'])) { - $_SESSION['groups'][0]['group_name'] = 'public'; - } + //if there are no groups then set the public group + if (!isset($_SESSION['groups'])) { + $_SESSION['groups'][0]['group_name'] = 'public'; + } - if (strlen($sql) == 0) { //default sql for base of the menu + //get the menu from the database + if (strlen($sql) == 0) { //default sql for base of the menu + $sql = "select i.menu_item_link, l.menu_item_title as menu_language_title, i.menu_item_title, i.menu_item_protected, i.menu_item_category, i.menu_item_uuid, i.menu_item_parent_uuid "; + $sql .= "from v_menu_items as i, v_menu_languages as l "; + $sql .= "where i.menu_item_uuid = l.menu_item_uuid "; + $sql .= "and l.menu_language = '".$_SESSION['domain']['language']['code']."' "; + $sql .= "and l.menu_uuid = '".$this->menu_uuid."' "; + $sql .= "and i.menu_uuid = '".$this->menu_uuid."' "; + $sql .= "and i.menu_item_parent_uuid is null "; + $sql .= "and i.menu_item_uuid in "; + $sql .= "(select menu_item_uuid from v_menu_item_groups where menu_uuid = '".$this->menu_uuid."' "; + $sql .= "and ( "; + if (!isset($_SESSION['groups'])) { + $sql .= "group_name = 'public' "; + } + else { + $x = 0; + foreach($_SESSION['groups'] as $row) { + if ($x == 0) { + $sql .= "group_name = '".$row['group_name']."' "; + } + else { + $sql .= "or group_name = '".$row['group_name']."' "; + } + $x++; + } + } + $sql .= ") "; + $sql .= "and menu_item_uuid is not null "; + $sql .= ") "; + $sql .= "order by i.menu_item_order asc "; + } + $prep_statement = $db->prepare(check_sql($sql)); + $prep_statement->execute(); + $result = $prep_statement->fetchAll(PDO::FETCH_NAMED); + + //save the menu into an array + $x = 0; + foreach($result as $row) { + //add the row to the array + $a[$x] = $row; + + //add the sub menus to the array + $menu_item_level = 0; + if (strlen($row['menu_item_uuid']) > 0) { + $a[$x]['menu_items'] = $this->menu_child_array($menu_item_level, $row['menu_item_uuid']); + } + + //increment the row number + $x++; + } //end for each + + //unset the variables + unset($prep_statement, $sql, $result); + + //return the array + return $a; + } + + //create the sub menus + function menu_child_array($menu_item_level, $menu_item_uuid) { + + //get the database connnection return immediately if it doesn't exist + if ($this->db) { + $db = $this->db; + }else { + return; + } + + //set the level + $menu_item_level = $menu_item_level+1; + + //get the child menu from the database $sql = "select i.menu_item_link, l.menu_item_title as menu_language_title, i.menu_item_title, i.menu_item_protected, i.menu_item_category, i.menu_item_uuid, i.menu_item_parent_uuid "; $sql .= "from v_menu_items as i, v_menu_languages as l "; $sql .= "where i.menu_item_uuid = l.menu_item_uuid "; $sql .= "and l.menu_language = '".$_SESSION['domain']['language']['code']."' "; $sql .= "and l.menu_uuid = '".$this->menu_uuid."' "; $sql .= "and i.menu_uuid = '".$this->menu_uuid."' "; - $sql .= "and i.menu_item_parent_uuid is null "; + $sql .= "and i.menu_item_parent_uuid = '$menu_item_uuid' "; $sql .= "and i.menu_item_uuid in "; $sql .= "(select menu_item_uuid from v_menu_item_groups where menu_uuid = '".$this->menu_uuid."' "; $sql .= "and ( "; - if (!isset($_SESSION['groups'])) { + if (count($_SESSION['groups']) == 0) { $sql .= "group_name = 'public' "; } else { @@ -419,111 +497,45 @@ } } $sql .= ") "; - $sql .= "and menu_item_uuid is not null "; $sql .= ") "; - $sql .= "order by i.menu_item_order asc "; - } - try { - $prep_statement = $db->prepare(check_sql($sql)); - $prep_statement->execute(); - $result = $prep_statement->fetchAll(PDO::FETCH_NAMED); - } - catch (Exception $e) { - //menu is not available - } + $sql .= "order by l.menu_item_title, i.menu_item_order asc "; + $sub_prep_statement = $db->prepare($sql); + $sub_prep_statement->execute(); + $sub_result = $prep_statement_2->fetchAll(PDO::FETCH_NAMED); - $x = 0; - foreach($result as $row) { - //add the row to the array - $a[$x] = $row; + //save the child menu into an array + if (count($sub_result) > 0) { + foreach($sub_result as $row) { + //set the variables + $menu_item_link = $row['menu_item_link']; + $menu_item_category = $row['menu_item_category']; + $menu_item_uuid = $row['menu_item_uuid']; + $menu_item_parent_uuid = $row['menu_item_parent_uuid']; - //add the sub menus to the array - $menu_item_level = 0; - if (strlen($row['menu_item_uuid']) > 0) { - $a[$x]['menu_items'] = $this->menu_child_array($menu_item_level, $row['menu_item_uuid']); + //add the row to the array + $a[$x] = $row; + + //prepare the protected menus + if ($row['menu_item_protected'] == "true") { + $a[$x]['menu_item_title'] = $row['menu_item_title']; + } + else { + $a[$x]['menu_item_title'] = $row['menu_language_title']; + } + + //get sub menu for children + if (strlen($menu_item_uuid) > 0) { + $a[$x]['menu_items'] = $this->menu_child_array($menu_item_level, $menu_item_uuid); + //$str_child_menu = + } + + //increment the row + $x++; } - - //increment the row number - $x++; - } //end for each - - unset($prep_statement, $sql, $result); - return $a; - } - - //create the sub menus - function menu_child_array($menu_item_level, $menu_item_uuid) { - - $db = $this->db; - $menu_item_level = $menu_item_level+1; - - if (count($_SESSION['groups']) == 0) { - $_SESSION['groups'][0]['group_name'] = 'public'; - } - - $sql = "select i.menu_item_link, l.menu_item_title as menu_language_title, i.menu_item_title, i.menu_item_protected, i.menu_item_category, i.menu_item_uuid, i.menu_item_parent_uuid "; - $sql .= "from v_menu_items as i, v_menu_languages as l "; - $sql .= "where i.menu_item_uuid = l.menu_item_uuid "; - $sql .= "and l.menu_language = '".$_SESSION['domain']['language']['code']."' "; - $sql .= "and l.menu_uuid = '".$this->menu_uuid."' "; - $sql .= "and i.menu_uuid = '".$this->menu_uuid."' "; - $sql .= "and i.menu_item_parent_uuid = '$menu_item_uuid' "; - $sql .= "and i.menu_item_uuid in "; - $sql .= "(select menu_item_uuid from v_menu_item_groups where menu_uuid = '".$this->menu_uuid."' "; - $sql .= "and ( "; - if (count($_SESSION['groups']) == 0) { - $sql .= "group_name = 'public' "; - } - else { - $x = 0; - foreach($_SESSION['groups'] as $row) { - if ($x == 0) { - $sql .= "group_name = '".$row['group_name']."' "; - } - else { - $sql .= "or group_name = '".$row['group_name']."' "; - } - $x++; + unset($sql, $sub_result); + return $a; } - } - $sql .= ") "; - $sql .= ") "; - $sql .= "order by l.menu_item_title, i.menu_item_order asc "; - $prep_statement_2 = $db->prepare($sql); - $prep_statement_2->execute(); - $result_2 = $prep_statement_2->fetchAll(PDO::FETCH_NAMED); - if (count($result_2) > 0) { - foreach($result_2 as $row) { - //set the variables - $menu_item_link = $row['menu_item_link']; - $menu_item_category = $row['menu_item_category']; - $menu_item_uuid = $row['menu_item_uuid']; - $menu_item_parent_uuid = $row['menu_item_parent_uuid']; - - //add the row to the array - $a[$x] = $row; - - //prepare the protected menus - if ($row['menu_item_protected'] == "true") { - $a[$x]['menu_item_title'] = $row['menu_item_title']; - } - else { - $a[$x]['menu_item_title'] = $row['menu_language_title']; - } - - //get sub menu for children - if (strlen($menu_item_uuid) > 0) { - $a[$x]['menu_items'] = $this->menu_child_array($menu_item_level, $menu_item_uuid); - //$str_child_menu = - } - - //increment the row - $x++; - } - unset($sql, $result_2); - return $a; - } - unset($prep_statement_2, $sql); + unset($sub_prep_statement, $sql); } } diff --git a/resources/footer.php b/resources/footer.php index f2ef68d44d..f6df5296a9 100644 --- a/resources/footer.php +++ b/resources/footer.php @@ -61,7 +61,7 @@ require_once "resources/require.php"; } } -//start the output buffer +//get the template ob_start(); $template = $_SESSION["template_content"]; eval('?>' . $template . ' - Portions created by the Initial Developer are Copyright (C) 2008-2012 + Portions created by the Initial Developer are Copyright (C) 2008-2016 the Initial Developer. All Rights Reserved. Contributor(s): diff --git a/themes/default/template.php b/themes/default/template.php index 7d92308098..f8f1f08654 100644 --- a/themes/default/template.php +++ b/themes/default/template.php @@ -1717,7 +1717,7 @@