/** * @author goFrendiAsgard * @param string view_url * @param string data * @param string navigation_name * @param array config * @param bool return_as_string * @return string or null * @desc replace $this->load->view. This method will also load header, menu etc except there is _only_content parameter via GET or POST */ protected function view($view_url, $data = NULL, $navigation_name = NULL, $config = NULL, $return_as_string = FALSE) { $this->load->library('template'); $result = NULL; $view_url = $this->cms_parse_keyword($view_url); /** * PREPARE PARAMETERS ********************************************************************************************* */ // get dynamic widget status // (this is necessary since sometime the function called directly without run the constructor, i.e: when using Modules::run) if (isset($_REQUEST['__cms_dynamic_widget'])) { $this->__cms_dynamic_widget = TRUE; } /** * PREPARE PARAMETERS ********************************************************************************************* */ // this method can be called as $this->view('view_path', $data, true); // or $this->view('view_path', $data, $navigation_name, true); if (is_bool($navigation_name) && count($config) == 0) { $return_as_string = $navigation_name; $navigation_name = NULL; $config = NULL; } else { if (is_bool($config)) { $return_as_string = $config; $config = NULL; } } if (!isset($return_as_string)) { $return_as_string = FALSE; } if (!isset($config)) { $config = array(); } $privilege_required = isset($config['privileges']) ? $config['privileges'] : array(); $custom_theme = isset($config['theme']) ? $config['theme'] : NULL; $custom_layout = isset($config['layout']) ? $config['layout'] : NULL; $custom_title = isset($config['title']) ? $config['title'] : NULL; $custom_metadata = isset($config['metadata']) ? $config['metadata'] : array(); $custom_partial = isset($config['partials']) ? $config['partials'] : NULL; $custom_keyword = isset($config['keyword']) ? $config['keyword'] : NULL; $custom_description = isset($config['description']) ? $config['description'] : NULL; $custom_author = isset($config['author']) ? $config['author'] : NULL; $only_content = isset($config['only_content']) ? $config['only_content'] : FALSE; $always_allow = isset($config['always_allow']) ? $config['always_allow'] : FALSE; $layout_suffix = isset($config['layout_suffix']) ? $config['layout_suffix'] : ''; $custom_css = isset($config['css']) ? $config['css'] : ''; $custom_js = isset($config['js']) ? $config['js'] : ''; /** * GUESS $navigation_name THROUGH ITS URL *********************************************************************** */ $navigation_name_provided = TRUE; if (!isset($navigation_name) && !$this->__cms_dynamic_widget) { $navigation_name = $this->cms_navigation_name(); if (!$navigation_name) { $navigation_name_provided = FALSE; } } /** * CHECK IF THE CURRENT NAVIGATION IS ACCESSIBLE ***************************************************************** */ if (!$always_allow) { $this->cms_guard_page($navigation_name, $privilege_required); } // privilege is absolute $this->cms_guard_page(NULL, $privilege_required); /** * CHECK IF THE PAGE IS STATIC ********************************************************************************** */ $data = (array) $data; $row_navigation = NULL; if ($navigation_name != NULL) { $query = $this->db->select('navigation_id, title, page_title, page_keyword, description, default_theme, default_layout, only_content, is_static, static_content')->from(cms_table_name('main_navigation'))->where(array('navigation_name' => $navigation_name))->get(); if ($query->num_rows() > 0) { $row_navigation = $query->row(); } } if ($navigation_name_provided && !isset($data['_content']) && $row_navigation != NULL) { if ($row_navigation->is_static == 1) { $static_content = $row_navigation->static_content; // static_content should contains string if (!$static_content) { $static_content = ''; } if ($this->cms_editing_mode() && $this->cms_allow_navigate('main_navigation_management')) { $static_content = '<div class="row" style="padding-top:10px; padding-bottom:10px;"><a class="btn btn-primary pull-right" href="{{ SITE_URL }}main/navigation/edit/' . $row_navigation->navigation_id . '">' . '<i class="glyphicon glyphicon-pencil"></i> Edit Page' . '</a></div>' . $static_content; } $data['cms_content'] = $static_content; $view_url = 'CMS_View'; } } /** * SHOW THE PAGE IF IT IS ACCESSIBLE ***************************************************************************** */ // GET THE THEME, TITLE & ONLY_CONTENT FROM DATABASE $theme = ''; $title = ''; $keyword = ''; $default_theme = NULL; $default_layout = NULL; $page_title = NULL; $page_keyword = NULL; $page_description = NULL; $page_author = NULL; if ($navigation_name_provided && $row_navigation != NULL) { $default_theme = $row_navigation->default_theme; $default_layout = $row_navigation->default_layout; // title if (isset($row_navigation->page_title) && $row_navigation->page_title !== NULL && $row_navigation->page_title != '') { $page_title = $row_navigation->page_title; } else { if (isset($row_navigation->title) && $row_navigation->title !== NULL && $row_navigation->title != '') { $page_title = $row_navigation->title; } } $page_title = isset($page_title) && $page_title !== NULL ? $page_title : ''; // keyword $page_keyword = isset($row_navigation->page_keyword) && $row_navigation->page_keyword !== NULL ? $row_navigation->page_keyword : ''; // keyword $page_description = isset($row_navigation->description) && $row_navigation->description !== NULL ? $row_navigation->description : ''; // only content if (!isset($only_content)) { $only_content = $row_navigation->only_content == 1; } } // ASSIGN THEME if (isset($custom_theme) && $custom_theme !== NULL && $custom_theme != '') { $theme = $custom_theme; } else { if (isset($default_theme) && $default_theme != NULL && $default_theme != '') { $themes = $this->cms_get_theme_list(); $theme_path = array(); foreach ($themes as $theme) { $theme_path[] = $theme['path']; } if (in_array($default_theme, $theme_path)) { $theme = $default_theme; } } else { $theme = $this->cms_get_config('site_theme'); } } // ASSIGN TITLE $title = ''; if (isset($custom_title) && $custom_title !== NULL && $custom_title != '') { $title = $this->cms_get_config('site_name') . ' - ' . $custom_title; } else { if (isset($page_title) && $page_title !== NULL && $page_title != '') { $title = $this->cms_get_config('site_name') . ' - ' . $page_title; } else { $title = $this->cms_get_config('site_name'); } } // ASSIGN KEYWORD if (isset($custom_keyword) && $custom_keyword != NULL && $custom_keyword != '') { $keyword = $custom_keyword; } else { if (isset($page_keyword) && $page_keyword !== NULL && $page_keyword != '') { $keyword = $page_keyword; if ($custom_keyword != '') { $keyword .= ', ' . $custom_keyword; } } else { $keyword = ''; } } // ASSIGN DESCRIPTION if (isset($custom_description) && $custom_description != NULL && $custom_description != '') { $description = $custom_description; } else { if (isset($page_description) && $page_description !== NULL && $page_description != '') { $description = $page_description; if ($custom_description != '') { $description .= ', ' . $custom_description; } } else { $description = ''; } } // ASSIGN AUTHOR if (isset($custom_author) && $custom_author != NULL && $custom_author != '') { $author = $custom_author; } else { $author = $this->{$this->__cms_base_model_name}->cms_get_super_admin()->real_name; } // GET THE LAYOUT if (isset($custom_layout)) { $layout = $custom_layout; } else { if (isset($default_layout) && $default_layout != '') { $layout = $default_layout; } else { $this->load->library('user_agent'); $layout = $this->agent->is_mobile() ? 'mobile' : $this->cms_get_config('site_layout'); } } // ADJUST THEME AND LAYOUT if (!$this->cms_layout_exists($theme, $layout)) { // ASSIGN LAYOUT if (!file_exists(FCPATH . 'themes/' . $theme) || !is_dir(FCPATH . 'themes/' . $theme)) { $theme = 'neutral'; } if (!file_exists(FCPATH . 'themes/' . $theme . '/views/layouts/' . $layout . '.php')) { $layout = 'default'; if (!file_exists(FCPATH . 'themes/' . $theme . '/views/layouts/default.php')) { $theme = 'neutral'; } } } // save used_theme $this->session->set_userdata('__cms_used_theme', $theme); // ADD AUTHENTICATED SUFFIX (in case of user has logged in) $cms_user_id = $this->cms_user_id(); if ($layout_suffix == '' && isset($cms_user_id) && $cms_user_id) { $layout_suffix = 'authenticated'; } if ($this->cms_layout_exists($theme, $layout . '_' . $layout_suffix)) { $layout = $layout . '_' . $layout_suffix; } $data['__is_bootstrap_cdn_connected'] = FALSE; // IT'S SHOW TIME if ($only_content || $this->__cms_dynamic_widget || isset($_REQUEST['_only_content']) || $this->input->is_ajax_request()) { $result = $this->load->view($view_url, $data, TRUE); $result = $custom_css . $custom_js . $result; } else { // save navigation name $this->cms_ci_session('__cms_navigation_name', $navigation_name); // set theme, layout and title $this->template->title($title); $this->template->set_theme($theme); $this->template->set_layout($layout); // set keyword metadata if ($keyword != '') { $keyword_metadata = '<meta name="keyword" content="' . $keyword . '">'; $this->template->append_metadata($keyword_metadata); } // set description metadata if ($description != '') { $description_metadata = '<meta name="description" content="' . $description . '">'; $this->template->append_metadata($description_metadata); } // set author metadata if ($author != '') { $author_metadata = '<meta name="author" content="' . $author . '">'; $this->template->append_metadata($author_metadata); } // add IE compatibility $this->template->append_metadata('<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">'); // add width $this->template->append_metadata('<meta name="viewport" content="width=device-width, initial-scale=1.0">'); $asset = new Cms_asset(); $asset->add_js(base_url('assets/grocery_crud/js/jquery-1.10.2.min.js')); // ckeditor adjustment thing $asset->add_internal_js($this->cms_ck_adjust_script()); // add javascript base_url for ckeditor $asset->add_internal_js('var __cms_base_url = "' . base_url() . '";'); // check login status //$login_code = '<script type="text/javascript">'; $login_code = ''; if ($this->cms_user_id() > 0) { $login_code .= 'var __cms_is_login = true;'; } else { $login_code .= 'var __cms_is_login = false;'; } $login_code .= 'setInterval(function(){ $.ajax({ url : "{{ site_url }}main/json_login_info", dataType: "json", success: function(response){ if(response.is_login != __cms_is_login){ window.location = $(location).attr("href"); } } }); },300000);'; $asset->add_internal_js($login_code); // google analytic $analytic_property_id = $this->cms_get_config('cms_google_analytic_property_id'); if (trim($analytic_property_id) != '') { if ($this->cms_is_connect('google-analytics.com')) { // create analytic code $analytic_code = ''; $analytic_code .= 'var _gaq = _gaq || []; '; $analytic_code .= '_gaq.push([\'_setAccount\', \'' . $analytic_property_id . '\']); '; $analytic_code .= '_gaq.push([\'_trackPageview\']); '; $analytic_code .= '(function() { '; $analytic_code .= 'var ga = document.createElement(\'script\'); ga.type = \'text/javascript\'; ga.async = true; '; $analytic_code .= 'ga.src = (\'https:\' == document.location.protocol ? \'https://ssl\' : \'http://www\') + \'.google-analytics.com/ga.js\'; '; $analytic_code .= 'var s = document.getElementsByTagName(\'script\')[0]; s.parentNode.insertBefore(ga, s); '; $analytic_code .= '})(); '; $asset->add_internal_js($analytic_code); } } // add hack if exists if (!isset($_SESSION)) { session_start(); } if (isset($_SESSION['__cms_flash_metadata'])) { $this->template->append_metadata($_SESSION['__cms_flash_metadata']); unset($_SESSION['__cms_flash_metadata']); } // config metadata foreach ($custom_metadata as $metadata) { $this->template->append_metadata($metadata); } // append custom css & js $this->template->append_js($asset->compile_js()); $this->template->append_css($asset->compile_css()); $this->template->append_js($custom_js); $this->template->append_css($custom_css); $this->load->helper('directory'); $partial_path = BASEPATH . '../themes/' . $theme . '/views/partials/' . $layout . '/'; if (is_dir($partial_path)) { $partials = directory_map($partial_path, 1); foreach ($partials as $partial) { // if is directory or is not php, then ignore it if (is_dir($partial)) { continue; } $partial_extension = pathinfo($partial_path . $partial, PATHINFO_EXTENSION); if (strtoupper($partial_extension) != 'PHP') { continue; } // add partial to template $partial_name = pathinfo($partial_path . $partial, PATHINFO_FILENAME); if (isset($custom_partial[$partial_name])) { $this->template->inject_partial($partial_name, $custom_partial[$partial_name]); } else { $this->template->set_partial($partial_name, 'partials/' . $layout . '/' . $partial, $data); } } } $result = $this->template->build($view_url, $data, TRUE); } // parse keyword $result = $this->cms_parse_keyword($result); // parse widgets used_theme & navigation_path $result = $this->__cms_parse_widget_theme_path($result, $theme, $layout, $navigation_name); $this->load->library('cms_asset'); $asset = new Cms_asset(); $result = $asset->minify($result); if ($return_as_string) { return $result; } else { $this->cms_show_html($result); } }