Last active
April 18, 2016 17:43
-
-
Save litzinger/11673718cffdde4add236ddc22f94143 to your computer and use it in GitHub Desktop.
Structure Improvements
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| function get_site_pages($cache_bust=false, $override_slash=false) | |
| { | |
| $cache_key = '/structure/get_site_pages'; | |
| if (!$cache_bust && ($cached_pages = ee()->cache->get($cache_key))) { | |
| return $cached_pages; | |
| } | |
| $settings = $this->get_settings(); | |
| $trailing_slash = $override_slash === false && isset($settings['add_trailing_slash']) && $settings['add_trailing_slash'] === 'y'; | |
| $blank_pages = array( | |
| 'url' => '', | |
| 'uris' => array(), | |
| 'templates' => array() | |
| ); | |
| if ($cache_bust === true) { | |
| $sql = "SELECT site_pages FROM exp_sites WHERE site_id = $this->site_id"; | |
| $pages_array = $this->EE->sql_helper->row($sql); | |
| $all_pages = unserialize(base64_decode($pages_array['site_pages'])); | |
| } else { | |
| $all_pages = $this->EE->config->item('site_pages'); | |
| } | |
| if (is_array($all_pages) && isset($all_pages[$this->site_id]) && is_array($all_pages[$this->site_id])) { | |
| $site_pages = array_merge($blank_pages, $all_pages[$this->site_id]); | |
| } else { | |
| $site_pages = $blank_pages; | |
| } | |
| if ($trailing_slash) { | |
| foreach ($site_pages['uris'] as $key => $uri) { | |
| $site_pages['uris'][$key] = Structure_Helper::remove_double_slashes($uri.'/'); | |
| } | |
| } else { | |
| foreach ($site_pages['uris'] as $key => $uri) { | |
| if ($site_pages['uris'][$key] !== '/') { | |
| $site_pages['uris'][$key] = rtrim($uri, '/'); | |
| } | |
| } | |
| } | |
| ee()->cache->save($cache_key, $site_pages); | |
| return $site_pages; | |
| } | |
| function get_settings() | |
| { | |
| $cache_key = '/structure/get_settings'; | |
| if (!$cached_settings = ee()->cache->get($cache_key)) { | |
| return $cached_settings; | |
| } | |
| static $settings = NULL; | |
| if (is_array($settings) || ! $this->module_is_installed()) { | |
| return $settings; | |
| } | |
| $site_id = '0,'.$this->site_id; | |
| $sql = "SELECT var_value, var FROM exp_structure_settings WHERE site_id IN ({$site_id})"; | |
| $result = $this->EE->db->query($sql); | |
| $settings = array( | |
| 'show_picker' => 'y', | |
| 'show_view_page' => 'y', | |
| 'show_status' => 'y', | |
| 'show_page_type' => 'y', | |
| 'show_global_add_page' => 'y', | |
| 'redirect_on_login' => 'n', | |
| 'redirect_on_publish' => 'n', | |
| 'add_trailing_slash' => 'y' | |
| ); | |
| if ($result->num_rows() > 0) | |
| { | |
| foreach ($result->result_array() as $row) | |
| { | |
| if ($row['var_value'] != '') | |
| { | |
| $settings[$row['var']] = $row['var_value']; | |
| } | |
| } | |
| } | |
| ee()->cache->save($cache_key, $settings); | |
| return $settings; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment