/html/AppCode/expressionengine/third_party/structure/mod.structure.php
PHP | 3653 lines | 3190 code | 262 blank | 201 comment | 250 complexity | 035d48e9d548e1b2fa2c013355fec5a0 MD5 | raw file
Possible License(s): AGPL-3.0
Large files files are truncated, but you can click here to view the full file
- <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
- error_reporting(0);
- ini_set('display_errors', FALSE);
- /**
- * Control Panel (MCP) File for Structure
- *
- * This file must be in your /system/third_party/structure directory of your ExpressionEngine installation
- *
- * @package Structure 2 for EE2 (Build 20100824)
- * @author Jack McDade (jack@jackmcdade.com)
- * @author Travis Schmeisser (travis@rockthenroll.com)
- * @copyright Copyright (c) 2010 Travis Schmeisser
- * @version Release: 2.1.5
- * @link http://buildwithstructure.com
- */
- // Thanks also to Tom Jaeger, Jeremy Messenger, Brian Litzinger and Adam Leder for their code contributions.
- require('libraries/nestedset/structure_nestedset.php');
- require('libraries/nestedset/structure_nestedset_adapter_ee.php');
- class Structure
- {
- var $nset;
- var $channel_type = '';
- function Structure()
- {
-
- $this->EE =& get_instance();
- $adapter = new Structure_Nestedset_Adapter_Ee('exp_structure', 'lft', 'rgt', 'entry_id');
- $this->nset = new Structure_Nestedset($adapter);
-
- }
-
-
- /** -------------------------------------
- /** Tag: nav_main
- /** -------------------------------------*/
-
- function nav_main()
- {
- $html = "";
-
- $site_id = $this->EE->config->item('site_id');
- // get current uri path
- $uri = $this->EE->uri->uri_string;
- $separator = $this->EE->config->item('word_separator') != 'dash' ? '_' : '-';
-
- $css_id = $this->EE->TMPL->fetch_param('css_id');
- // Set unique id prefix
- if ($css_id == NULL)
- $unique_prefix = 'nav';
- else
- $unique_prefix = $css_id;
- // Remove the id tag if set to "none"
- if ($css_id == "")
- $css_id = ' id="nav"';
- elseif ($css_id == "none")
- $css_id = NULL;
- else
- $css_id = ' id="'.$css_id.'"';
-
- $add_unique_id = $this->EE->TMPL->fetch_param('add_unique_id');
- $add_unique_id = $add_unique_id ? strtolower($add_unique_id) : 'no';
- $add_unique_to = ($this->EE->TMPL->fetch_param('add_unique_to')) ? $this->EE->TMPL->fetch_param('nav_class') : 'li';
- $current_class = ($this->EE->TMPL->fetch_param('current_class')) ? $this->EE->TMPL->fetch_param('current_class') : 'here';
- $include_ul = ($this->EE->TMPL->fetch_param('include_ul')) ? $this->EE->TMPL->fetch_param('include_ul') : 'yes';
- $add_span = ($this->EE->TMPL->fetch_param('add_span')) ? $this->EE->TMPL->fetch_param('add_span') : 'no';
-
- // CSS class
- $css_class = $this->EE->TMPL->fetch_param('css_class');
- $css_class = $css_class ? $css_class : '';
- // exclude and include entry_ids
- $exclude = explode("|", $this->EE->TMPL->fetch_param('exclude'));
- $include = ($this->EE->TMPL->fetch_param('include')) ? " AND `node`.`entry_id` IN(".str_replace("|", ",", $this->EE->TMPL->fetch_param('include')).") " : "";
-
- // DEPRECIATED SUPPORT for exclude_status and include_status
- $include_status = strtolower($this->EE->TMPL->fetch_param('include_status'));
- $exclude_status = strtolower($this->EE->TMPL->fetch_param('exclude_status'));
- // New, native EE status mode
- $status = $this->EE->TMPL->fetch_param('status');
- $status = $status == '' ? array() : explode('|', $status);
- $status = array_map('strtolower', $status); // match MySQL's case-insensitivity
- $status_state = 'positive';
- // Check for "not "
- if (substr($status[0], 0, 4) == 'not ')
- {
- $status_state = 'negative';
- $status[0] = trim(substr($status[0], 3));
- $status[] = 'closed';
- }
- else
- {
- $status[] = 'open';
- }
-
- $include_status_list = explode('|', $include_status);
- $exclude_status_list = explode('|', $exclude_status);
-
- // Remove the default "open" status if explicitely set
- if (in_array('open', $exclude_status_list))
- $status = array_filter($status, create_function('$v', 'return $v != "open";'));
-
- if ($status_state == 'positive')
- $status = array_merge($status, $include_status_list);
- elseif ($status_state == 'negative')
- $status = array_merge($status, $exclude_status_list);
-
- // get site pages data
- $site_pages = $this->get_site_pages();
- // get structure data from DB
- $sql = "SELECT node.*, expt.title, expt.status
- FROM exp_structure AS node
- INNER JOIN exp_channel_titles AS expt
- ON node.entry_id = expt.entry_id
- WHERE node.parent_id = 0
- AND node.site_id = $site_id {$include}
- GROUP BY node.entry_id
- ORDER BY node.lft";
- $result = $this->EE->db->query($sql);
- // Remove anything to be excluded from the results array
- foreach ($result->result_array() as $key => $entry_data)
- {
- if ($status_state == 'negative' && in_array(strtolower($entry_data['status']), $status)
- || ($status_state == 'positive' && ! in_array(strtolower($entry_data['status']), $status))
- || in_array($entry_data['entry_id'], $exclude))
- {
- unset($result->result_array[$key]);
- }
- }
- // Make sure array indices are incremental (0..X)
- // $result->result_array() = array_values($result->result_array());
- $segment_1 = $this->EE->uri->segment('1');
- if (count($result->num_rows()) > 0)
- {
- foreach ($result->result_array() as $entry_data)
- {
- // out entry uri of this loop instance
- $euri = $site_pages['uris'][$entry_data['entry_id']];
- $slug = $this->page_slug($entry_data['entry_id']);
- if ($slug == '')
- $slug = 'home';
- if ($separator == '_')
- {
- $slug = str_replace('-', $separator, $slug);
- }
- elseif ($separator == '-')
- {
- $slug = str_replace('_', $separator, $slug);
- }
- $a_class = '';
- $li_class = '';
- $list_item_id = '';
- // if we are adding the unique slug to the anchor
- // *!*!*!*!*!*!* Possibly Remove This
- if ($add_unique_to == 'a')
- {
- $a_class .= 'nav' . $separator . $slug;
- }
- // else
- else
- {
- // $li_class .= 'nav' . $separator . $slug;
- }
- if ($uri === $euri OR ($uri == '' && $euri == '/') OR $segment_1 === trim($euri, '/'))
- {
- $here = TRUE;
- $current_entry = $entry_data['entry_id'];
- $li_class .= ' ' . $current_class;
- }
- if ($entry_data == end($result->result_array()))
- {
- $li_class .= ' last';
- }
- $li_class = empty($li_class) ? '' : " class=\"".trim($li_class)."\"";
- $a_class = empty($a_class) ? "" : " class=\"".trim($a_class)."\"";
- // Make sure we have the site_url path in case we're operating in a subdirectory
- // If site_index is set then add it to URIs, otherwise leave it blank
- $site_url = $this->EE->functions->fetch_site_index();
-
- $the_uri = parse_url($this->EE->db->escape_str($site_url));
- $root_uri = $the_uri['path'];
- $index_uri = $site_url;
- $home = trim($this->EE->functions->fetch_site_index(0, 0), '/');
- $item_uri = $this->EE->functions->remove_double_slashes($home . $euri);
- if ($add_unique_id == 'yes')
- {
- $list_item_id = ' id="'. $unique_prefix . $separator . $slug .'"';
- }
- $title = htmlspecialchars($entry_data['title']);
- // Add a <span> wrapper inside the <a> tags
- if ($add_span == 'yes')
- {
- $html .= "\n<li{$li_class}{$list_item_id}><a href=\"" . $item_uri . "\"{$a_class}><span>" . $title."</span></a></li>";
- }
- else
- {
- $html .= "\n<li{$li_class}{$list_item_id}><a href=\"" . $item_uri . "\"{$a_class}>" . $title."</a></li>";
- }
- }
- $css_class = ($this->EE->TMPL->fetch_param('css_class')) ? " class=\"" . $this->EE->TMPL->fetch_param('css_class') . "\"" : "";
- // Add or remove the <ul> wrapper
- if ($include_ul == 'yes')
- {
- $html = "<ul{$css_id}{$css_class}>" . $html . "\n</ul>";
- }
- }
- return $html;
- }
-
-
- /** -------------------------------------
- /** Tag: nav_sub
- /** -------------------------------------*/
- function nav_sub()
- {
- $html = '';
-
- // get site pages data
- $site_pages = $this->get_site_pages();
- if ( ! $site_pages) return FALSE;
- /** -------------------------------------
- /** The Parameters
- /** -------------------------------------*/
- $separator = $this->EE->config->item('word_separator') != 'dash' ? '_' : '-';
- $exclude = explode('|', $this->EE->TMPL->fetch_param('exclude'));
- // DEPRECIATED SUPPORT for exclude_status and include_status
- $include_status = strtolower($this->EE->TMPL->fetch_param('include_status'));
- $exclude_status = strtolower($this->EE->TMPL->fetch_param('exclude_status'));
- // New, native EE status mode
- $status = $this->EE->TMPL->fetch_param('status');
- $status = $status == '' ? array() : explode('|', $status);
- $status = array_map('strtolower', $status); // match MySQL's case-insensitivity
- $status_state = 'positive';
- // Check for "not "
- if (substr($status[0], 0, 4) == 'not ')
- {
- $status_state = 'negative';
- $status[0] = trim(substr($status[0], 3));
- $status[] = 'closed';
- }
- else
- {
- $status[] = 'open';
- }
- $include_status_list = explode('|', $include_status);
- $exclude_status_list = explode('|', $exclude_status);
- // Remove the default "open" status if explicitely set
- if (in_array('open', $exclude_status_list))
- $status = array_filter($status, create_function('$v', 'return $v != "open";'));
- if ($status_state == 'positive')
- $status = array_merge($status, $include_status_list);
- elseif ($status_state == 'negative')
- $status = array_merge($status, $exclude_status_list);
-
- $include_ul = ($this->EE->TMPL->fetch_param('include_ul')) ? $this->EE->TMPL->fetch_param('include_ul') : 'yes';
- $add_span = ($this->EE->TMPL->fetch_param('add_span')) ? $this->EE->TMPL->fetch_param('add_span') : 'no';
- $css_id = $this->EE->TMPL->fetch_param('css_id') ? $this->EE->TMPL->fetch_param('css_id') : '';
- if ($css_id == '')
- {
- $css_id = 'nav'.$separator.'sub';
- }
- elseif ($css_id == 'none')
- {
- $css_id = NULL;
- }
- else
- {
- $css_id = $css_id;
- }
- // CSS class
- $css_class = $this->EE->TMPL->fetch_param('css_class');
- $css_class = $css_class ? $css_class : '';
- // Current CSS class
- $current_class = ($this->EE->TMPL->fetch_param('current_class')) ? $this->EE->TMPL->fetch_param('current_class') : 'here';
- // show_level_classes
- $show_level_classes = $this->EE->TMPL->fetch_param('show_level_classes');
- $show_level_classes = $show_level_classes ? strtolower($show_level_classes) : 'yes';
- // show_overview_link
- $show_overview_link = $this->EE->TMPL->fetch_param('show_overview_link');
- $show_overview_link = $show_overview_link ? strtolower($show_overview_link) : 'no';
- // Custom View Text
- $overview_text_title = $this->EE->TMPL->fetch_param('show_overview_link');
- $overview_text_title = $overview_text_title ? strtolower($overview_text_title) : 'no';
- // Rename Overview parameter
- $overview_link_text = $this->EE->TMPL->fetch_param('rename_overview');
- $overview_link_text = $overview_link_text ? $overview_link_text : 'Overview';
- // Add CSS ids based on the URI to all <li> elements
- $add_unique_id = $this->EE->TMPL->fetch_param('add_unique_id');
- $add_unique_id = $add_unique_id ? strtolower($add_unique_id) : 'no';
- // Add CSS ids based on the entry_id to all <li> elements
- $add_unique_entry_id = $this->EE->TMPL->fetch_param('add_unique_entry_id');
- $add_unique_entry_id = $add_unique_entry_id ? strtolower($add_unique_entry_id) : 'no';
- $wrap_start = $this->EE->TMPL->fetch_param('wrap_start');
- $wrap_start = $wrap_start ? $wrap_start : 'no';
- $wrap_end = $this->EE->TMPL->fetch_param('wrap_end');
- $wrap_end = $wrap_end ? $wrap_end : 'no';
- // Hide the entire sub nav if there are no children of the current page
- $hide_if_no_children = ($this->EE->TMPL->fetch_param('hide_if_no_children')) ? $this->EE->TMPL->fetch_param('hide_if_no_children') : 'no';
- $initiate_children_hiding = 'no';
- // depth to limit, never expand past this depth
- $depth_limit = $this->EE->TMPL->fetch_param('limit_depth');
- $depth_limit = $depth_limit ? $depth_limit : '';
- // depth to show, show all of tree up to specified depth
- $show_n_deep = $this->EE->TMPL->fetch_param('show_depth');
- $show_n_deep = ($show_n_deep != '') ? $show_n_deep : '';
- // special case to make the math work, if passing 0 then calculate based on -1
- if ($show_n_deep <= 0 && $show_n_deep != '')
- {
- $show_n_deep = -1;
- }
- // Retrieve start_from URL
- $start_from = $this->EE->TMPL->fetch_param('start_from');
- $start_from = $start_from ? $start_from : '';
- /** -------------------------------------
- /** The Logic
- /** -------------------------------------*/
- $fixed = false;
- if ($start_from != '')
- {
- $start_from = html_entity_decode($start_from);
- // Make sure passed URL starts with a '/'
- if (substr($start_from, 0, 1) != '/')
- {
- $start_from = '/' . $start_from;
- }
- // Make sure passed URL ends with a '/'
- if (substr($start_from, -1, 1) != '/')
- {
- $start_from .= '/';
- }
- $fixed = true;
- }
- $uri = '/'.$this->EE->uri->uri_string().'/';
- // get entry id + node of the start entry
- $entry_id = $start_from ? array_search($start_from, $site_pages['uris']) : array_search($uri, $site_pages['uris']);
- $node = $entry_id ? $this->nset->getNode($entry_id) : false;
-
- // get entry id + node of the current entry
- $current_entry_id = array_search($uri, $site_pages['uris']);
- $current_node = $current_entry_id ? $this->nset->getNode($current_entry_id) : false;
- // if current_node is a leaf then current_node should be parent
- if ($current_node == '' && $current_entry_id)
- {
- // get entry's parent id
- $pid = $this->get_pid_for_listing_entry($current_entry_id);
- $current_node = $this->nset->getNode($pid);
- }
- // If current location is a leaf then use parent as starting point for top + current
- if ($node['isLeaf'])
- {
- $leaf_node = $current_node;
- $node = $this->nset->getNode($node['parent_id']);
- $current_node = $this->nset->getNode($current_node['parent_id']);
- if ($hide_if_no_children == 'yes')
- {
- $initiate_children_hiding = 'yes';
- }
- elseif ($hide_if_no_children == 'conditional')
- {
- $initiate_children_hiding = 'conditional';
- }
- }
- // if start_from + show_depth then make sure top is treated as current
- if ($show_n_deep != '')
- {
- $actual_current = $current_node;
- $current_node = $node;
- }
- // get all pages/tree
- $pages = $this->get_data();
- // Get current parent's URI
- if (isset($site_pages['uris'][$node['id']]))
- {
- $top_uri = $site_pages['uris'][$node['id']];
- }
- else
- {
- $top_uri = '';
- }
- // Get current page URI
- if (isset($site_pages['uris'][$current_node['id']]))
- {
- $current_page_uri = $site_pages['uris'][$current_node['id']];
- }
- else
- {
- $current_page_uri = '';
- }
- $current_top_uri = $top_uri;
-
- // trim tree of uneeded branches + leaves
- foreach ($pages as $key => $entry_data)
- {
- // If not top level && not child of current
- if ($entry_data['parent_id'] != $node['id'] && $entry_data['parent_id'] != 0)
- {
- // Does entry's URI start with our current top URI
- if (preg_match("~^" . $current_top_uri . "~", $site_pages['uris'][$entry_data['entry_id']]))
- {
- // Only show immediate children
- // if the entry has depth greater than the current entry and it's parent isn't the current entry then we don't want it
- // if show_depth then check that items to be included are left alone
-
- if (($show_n_deep != '' && (($entry_data['depth'] - $current_node['depth']) > ($show_n_deep + 1)) && $entry_data['parent_id'] != $current_node['id'])
- || ($show_n_deep == '' && $entry_data['depth'] > ($current_node['depth']) && $entry_data['parent_id'] != $current_node['id'])
- || ($entry_data['depth'] == ($current_node['depth']) && $entry_data['parent_id'] != $current_node['parent_id']))
- {
- // Hide pages in the same branch group but at same depth. This only really applies to leaves on the end.
- unset($pages[$key]);
- }
- }
- elseif ($entry_data['parent_id'] != $current_node['parent_id'])
- {
- unset($pages[$key]);
- }
- elseif ($entry_data['parent_id'] != $current_node['id'])
- {
- // Possibly thowing errors, one way or the other. Keep flagged.
- unset($pages[$key]);
- }
- }
- elseif ($entry_data['parent_id'] == 0)
- {
- unset($pages[$key]);
- }
- $adjust_depth = $fixed ? 1 : 0;
- if (isset($pages[$key]) && array_key_exists('entry_id', $pages[$key]))
- {
- $pages[$key]['depth'] -= ($node['depth'] + $adjust_depth);
- }
- }
- // Discover the tree of the current page
- // Clean up items that aren't part of the current branch
- $tree = array();
- if ($fixed && $current_node['parent_id'] != 0)
- {
- $next_id = $current_node['id'];
- for($x = 0; $x < $current_node['depth']; $x++)
- {
- // Build the tree for the branch
- foreach ($pages as $key => $page)
- {
- if ($page['entry_id'] == $next_id)
- {
- $tree[] = $page['entry_id'];
- $next_id = $page['parent_id'];
- }
- }
- }
- // Remove the items that aren't part of the branch
- // If the items parent isn't part of the tree, and the item itself isn't part of the tree, and the items parent isn't the root of the tree
- foreach ($pages as $key => $page)
- {
- if (($page['depth'] < 0)
- || ( ! in_array($page['parent_id'], $tree
- && ! in_array($page['entry_id'], $tree)
- && $page['parent_id'] != $node['id'])))
- {
- unset($pages[$key]);
- }
- }
- }
- $closed_parents = array();
- // Remove anything to be excluded from the results array
- foreach ($pages as $key => $entry_data)
- {
- if ($status_state == 'negative' && in_array(strtolower($entry_data['status']), $status)
- || ($status_state == 'positive' && ! in_array(strtolower($entry_data['status']), $status))
- || in_array($entry_data['parent_id'], $closed_parents)
- || in_array($entry_data['entry_id'], $exclude))
- {
- $closed_parents[] = $entry_data['entry_id'];
- unset($pages[$key]);
- }
- }
-
- // Make sure array indices are incremental (0..X)
- $pages = array_values($pages);
- // If our first item is not depth 0 bring everything down accordingly
- if (isset($pages[0]['depth']) && $pages[0]['depth'] > 0)
- {
- $adjust_depth = $pages[0]['depth'] - $node['depth'];
- foreach ($pages as $key => $page)
- {
- $pages[$key]['depth'] -= $adjust_depth;
- }
- }
- // Clean up if we have a depth parameter, remove anything deeper than the requested depth
- if ($depth_limit != '')
- {
- foreach ($pages as $key => $page)
- {
- if ($page['depth'] > $depth_limit)
- {
- unset($pages[$key]);
- }
- }
- }
- // Make sure array indices are incremental (0..X)
- $pages = array_values($pages);
- // If show_overview_link is true then
- // check if parent is top level, if true then show overview link
- // Get the parent of the first page. Allows us to check if it's parent is top level for the Overview link
- if ( ! $fixed)
- {
- $parent_node = $this->nset->getNode(@$pages[0]['parent_id']);
- }
- else
- {
- $parent_node = array('parent_id' => '');
- }
- if ($show_overview_link == "yes" && ($node['parent_id'] == 0 OR $parent_node['parent_id'] == 0))
- {
- $overview_data = ($parent_node['parent_id'] != '') ? $parent_node : $node;
- // Apply custom Overview title if set
- if ($overview_link_text)
- {
- $overview_data['title'] = $overview_link_text;
- }
- elseif ($overview_text_title)
- {
- $parent_id = $overview_data['id'];
- $sql = "SELECT title
- FROM exp_channel_titles
- WHERE entry_id = '".$parent_id."'";
- $result = $this->EE->db->query($sql);
- $overview_data['title'] = $result->result_array[0]['title'];
- }
- $overview_data['entry_id'] = $overview_data['id'];
- $overview_data['depth'] = 0;
- $overview_data['overview'] = "yes";
- array_unshift($pages, $overview_data);
- }
- // If show_depth then set the current_node back to what it should be (actual_current)
- if ($show_n_deep != '')
- {
- $current_node = $actual_current;
- }
- $ul_open = false;
- $last_page_depth = 0;
- $last = "";
- // Begin building out the tree
- foreach ($pages as $page)
- {
- //@@@ PHP Notice: Triggered from (assuming) empty array key. [Undefined index: 0]
- @$page_uri = $site_pages['uris'][$page['entry_id']];
- //Create unique CSS ID based on the URIs
- $css_uri = substr_replace(str_replace("/", "_", $page_uri) ,"",-1);
- $home = trim($this->EE->functions->fetch_site_index(0, 0), '/');
- $item_uri = $this->EE->functions->remove_double_slashes($home . $page_uri);
- $page['class'] = "";
- // Start a sub nav
- if ($page['depth'] > $last_page_depth)
- {
- $html = substr($html, 0, -6);
- $html .= "\n<ul>\n";
- $ul_open = true;
- }
- // Close a sub nav
- if ($page['depth'] < $last_page_depth)
- {
- // Calculate how many levels back I need to go
- $back_to = $last_page_depth - $page['depth'];
- $html .= str_repeat("</ul>\n</li>\n", $back_to);
- $ul_open = false;
- }
- $here = '';
- // CURRENT CLASS DETECTION
-
- // If current location/leaf is within the left/right limits of the item then this is a "here" parent item
- if (($current_node['left'] > @$page['lft'] && $current_node['right'] < @$page['rgt']) OR (@$leaf_node['left'] > @$page['lft'] && @$leaf_node['right'] < @$page['rgt']))
- {
- $page['class'] .= ' parent' . $separator . $current_class;
- }
- elseif ($current_node['left'] == @$page['lft'] && $current_node['right'] == @$page['rgt'] && $page['entry_id'] != $current_entry_id && $page['entry_id'] != @$leaf_node['id'])
- {
- $page['class'] .= " ".$current_class;
- }
- elseif ($page['entry_id'] == $current_entry_id OR $page['entry_id'] == @$leaf_node['id'])
- {
- $page['class'] .= " ".$current_class;
- }
- // LAST CLASS DETECTION
- // Grab parent item's data
- $upper_node = $this->nset->getNode($page['parent_id']);
- // If an entry's RIGHT is one less than the parent's RIGHT, is the last item in a <ul>.
- if ((@$page['rgt']+1) == $upper_node['right'])
- {
- $page['class'] .= " last";
- }
- // elseif ($page == end($pages))
- // {
- // $last = 'last';
- // }
- // If show_level_classes then build level class name
- $level = "";
- if ($show_level_classes == 'yes')
- {
- $page['class'] .= ' sub' . $separator . 'level' . $separator . $page['depth'];
- }
- if (isset($page['overview']) && strtolower($page['overview']) == 'yes')
- {
- $page['class'] .= ' overview';
- }
- // Build classes string
- $classes = array($level, $here, $last);
- $classes_string = '';
- $classes_string = trim($page['class']);
- $list_item_class = '';
- // Set current class (Don't pass an empty class)
- if ($classes_string != '')
- {
- $list_item_class = " class=\"$classes_string\"";
- }
- $list_item_id = "";
- // Add unique id to <li> elements
- if ($add_unique_entry_id == "yes")
- {
- $list_item_id .= ' id="'.$css_id.$separator.$page['entry_id'].'"';
- }
- if ($add_unique_id == "yes")
- {
- $list_id_contents = explode ("/", $page_uri);
- array_pop($list_id_contents);
- array_shift($list_id_contents);
- $seg_1 = reset($list_id_contents);
- $seg_2 = end($list_id_contents);
- $list_item_id .= ' id="'.$seg_1.$separator.$seg_2.'"';
- }
- // The IDs and Classes
- $li_contents = $list_item_id.''.$list_item_class;
- $page_title = htmlspecialchars($page['title']);
- if ($add_span == "yes")
- {
- $page_title = "<span>".$page_title."</span>";
- }
- // THE BIG LIST OUTPUT
- $list_item = '<li'.$li_contents.'><a href="'.$item_uri.'">'.$page_title.'</a></li>'."\n";
- $html .= $list_item;
- $last_page_depth = $page['depth'];
- }
- // Close any open UL + LI combos
- if ($ul_open)
- {
- $html .= str_repeat("</ul></li>\n", $last_page_depth);
- $ul_open = false;
- $last_page_depth--;
- }
- // Make sure all the ULs are closed
- if ($last_page_depth > 0)
- {
- //$html .= str_repeat("</ul>\n", $last_page_depth + 1);
- $html .= "</ul>\n";
- }
- elseif ($include_ul == "no")
- {
- $html .= $ul_open ? "</ul>\n</li>\n" : "\n";
- }
- else
- {
- $html .= $ul_open ? "</ul>\n</li>\n</ul>" : "</ul>\n";
- }
- // Assign classes
- $css_class = ($this->EE->TMPL->fetch_param('css_class')) ? " class=\"" . $this->EE->TMPL->fetch_param('css_class') . "\"" : "";
- // Turn on or off the <ul>
- if ($include_ul == "yes")
- {
- if($css_id && $css_class)
- {
- $html = "\n<ul id=\"$css_id\"{$css_class}>\n" . $html;
- }
- else if($css_id)
- {
- $html = "\n<ul id=\"$css_id\"{$css_class}>\n" . $html;
- }
- else
- {
- $html = "\n<ul{$css_class}>\n" . $html;
- }
- }
- if ($initiate_children_hiding == "yes")
- {
- $html = NULL;
- }
- elseif ($initiate_children_hiding == "conditional")
- {
- $html = "empty";
- }
- if ($html != "" && $wrap_start != "no" && $wrap_end != "no")
- {
- $html = $wrap_start.$html.$wrap_end;
- }
-
- return $html;
- }
-
-
-
- /** -------------------------------------
- /** Tag: nav_full
- /** -------------------------------------*/
-
- function nav_full()
- {
- $html = '';
-
- /** -------------------------------------
- /** PARAMETERS: HTML/CSS Based
- /** -------------------------------------*/
- $separator = $this->EE->config->item('word_separator') != 'dash' ? '_' : '-';
- $css_id = ($this->EE->TMPL->fetch_param('css_id')) ? "".$this->EE->TMPL->fetch_param('css_id')."" : "";
- $css_class = ($this->EE->TMPL->fetch_param('css_class')) ? " class=\"" . $this->EE->TMPL->fetch_param('css_class') . "\"" : "";
- $current_class = ($this->EE->TMPL->fetch_param('current_class')) ? $this->EE->TMPL->fetch_param('current_class') : "here";
- $add_span = ($this->EE->TMPL->fetch_param('add_span')) ? $this->EE->TMPL->fetch_param('add_span') : "no";
- $add_unique_id = $this->EE->TMPL->fetch_param('add_unique_id');
- $add_unique_id = $add_unique_id ? strtolower($add_unique_id) : 'no';
- /** -------------------------------------
- /** PARAMETERS: Output and Behavior
- /** -------------------------------------*/
- // DEPRECIATED SUPPORT for exclude_status and include_status
- $include_status = strtolower($this->EE->TMPL->fetch_param('include_status'));
- $exclude_status = strtolower($this->EE->TMPL->fetch_param('exclude_status'));
- // New, native EE status mode
- $status = $this->EE->TMPL->fetch_param('status');
- $status = $status == '' ? array() : explode('|', $status);
- $status = array_map('strtolower', $status); // match MySQL's case-insensitivity
- $status_state = 'positive';
- // Check for "not "
- if (substr($status[0], 0, 4) == 'not ')
- {
- $status_state = 'negative';
- $status[0] = trim(substr($status[0], 3));
- $status[] = 'closed';
- }
- else
- {
- $status[] = 'open';
- }
-
- $include_status_list = explode('|', $include_status);
- $exclude_status_list = explode('|', $exclude_status);
-
- // Remove the default "open" status if explicitely set
- if (in_array('open', $exclude_status_list))
- $status = array_filter($status, create_function('$v', 'return $v != "open";'));
-
- if ($status_state == 'positive')
- $status = array_merge($status, $include_status_list);
- elseif ($status_state == 'negative')
- $status = array_merge($status, $exclude_status_list);
-
- // Retrieve entry_ids to exclude
- $exclude = explode('|', $this->EE->TMPL->fetch_param('exclude'));
- // get site pages data
- $site_pages = $this->get_site_pages();
- $segment_1 = $this->EE->uri->segment('1');
- $segment_2 = $this->EE->uri->segment('2');
- /** -------------------------------------
- /** Function Logic
- /** -------------------------------------*/
- // get all pages
- $pages = $this->get_data();
- // Remove anything to be excluded from the results array
- $closed_parents = array();
- foreach ($pages as $key => $entry_data)
- {
- if ($status_state == 'negative' && in_array(strtolower($entry_data['status']), $status)
- || ($status_state == 'positive' && ! in_array(strtolower($entry_data['status']), $status))
- || in_array($entry_data['parent_id'], $closed_parents)
- || in_array($entry_data['entry_id'], $exclude))
- {
- $closed_parents[] = $entry_data['entry_id'];
- unset($pages[$key]);
- }
- }
- // Make sure array indices are incremental (0..X)
- $pages = array_values($pages);
-
- if ($css_id == "")
- {
- $css_id = ' id="nav"';
- }
- elseif (strtolower($css_id) == 'none')
- {
- $css_id = NULL;
- }
- else
- {
- $css_id = ' id="'.$css_id.'"';
- }
- // Start building the navigation
- $html = "<ul{$css_id}{$css_class}>\n";
- $ul_open = false;
- $last_page_depth = 0;
- foreach ($pages as $page)
- {
- $page_uri = $site_pages['uris'][$page['entry_id']];
- $uri = $this->EE->functions->fetch_current_uri();
- // Make sure we have the site_url path in case we're operating in a subdirectory
- $home = trim($this->EE->functions->fetch_site_index(0, 0), '/');
- $item_uri = $this->EE->functions->remove_double_slashes($home . $page_uri);
- // Start a sub nav
- if ($page['depth'] > $last_page_depth)
- {
- $html = substr($html, 0, -6);
- $html .= "\n<ul>\n";
- $ul_open = true;
- }
- // Close a sub nav
- if ($page['depth'] < $last_page_depth)
- {
- // Calculate how many levels back to go
- $back_to = $last_page_depth - $page['depth'];
- $html .= str_repeat("</ul>\n</li>\n", $back_to);
- $ul_open = false;
- }
- // if ($page == end($pages))
- // {
- // $back_to = $last_page_depth - $page['depth'];
- // $html .= str_repeat("</ul>\n</li>\n", $back_to);
- // }
- // get entry id + node of the start entry
- $uri = '/'.$this->EE->uri->uri_string().'/';
- $entry_id = array_search($uri, $site_pages['uris']);
- $node = $entry_id ? $this->nset->getNode($entry_id) : false;
- // get entry id + node of the current entry
- $current_entry_id = array_search($uri, $site_pages['uris']);
- $current_node = $current_entry_id ? $this->nset->getNode($current_entry_id) : false;
- // if current_node is a leaf then current_node should be parent
- if ($current_node == '' && $current_entry_id)
- {
- // get entry's parent id
- $pid = $this->get_pid_for_listing_entry($current_entry_id);
- $current_node = $this->nset->getNode($pid);
- }
- $li_class = '';
-
- // if (($current_node['left'] > $page['lft'] && $current_node['right'] < $page['rgt']) OR (@$leaf_node['left'] > $page['lft'] && @$leaf_node['right'] < $page['rgt']))
- if (($current_node['left'] > $page['lft'] && $current_node['right'] < $page['rgt']))
- {
- $li_class .= 'parent' . $separator . $current_class;
- }
- elseif ($uri === $page_uri OR ($uri == '' && $page_uri == '/') OR $segment_1 == trim($page_uri, '/') && $segment_2 == "")
- {
- $here = TRUE;
- $current_entry = $entry_data['entry_id'];
- $li_class .= " ".$current_class;
- }
- /** -------------------------------------
- /** Last class detection
- /** -------------------------------------*/
- $upper_node = $this->nset->getNode($page['parent_id']);
- $last = "";
- // If an entry's RIGHT is one less than the parent's, is the last in a <ul>.
- if (($page['rgt']+1) == $upper_node['right'])
- {
- $last = ' last';
- }
- $li_class .= $last;
- // Check if the class is empty.
- if (empty($li_class))
- {
- $li_class = "";
- }
- else
- {
- $li_class=' class="'.trim($li_class).'"';
- }
- $page_title = ($page['title']);
- if ($add_span == "yes")
- {
- $page_title = "<span>".$page_title."</span>";
- }
- /** -------------------------------------
- /** Add Unique ID
- /** -------------------------------------*/
- $unique_prefix = "nav";
- $list_item_id = "";
- $slug = str_replace("/", $separator, $page_uri);
- $slug = substr($slug,1,-1);
- if ($separator == "_")
- {
- $slug = str_replace("-", $separator, $slug);
- }
- elseif ($separator == "-")
- {
- $slug = str_replace("_", $separator, $slug);
- }
- if ($slug == "")
- {
- $slug = "home";
- }
- if ($add_unique_id == "yes")
- {
- $list_item_id = ' id="'. $unique_prefix . $separator . $slug .'"';
- }
- // THE BIG LIST OUTPUT
- $list_item = '<li'.$li_class.''.$list_item_id.'><a href="'.$item_uri.'">'.$page_title.'</a></li>'."\n";
- // $list_item = '<li'.$li_class.''.$list_item_id.'><a href="'.$item_uri.'">'.$page_title.'</a> - Page Depth:'.$page['depth'].' ///// Last Page Depth: '.$last_page_depth.'</li>'."\n";
- // $list_item = '<li'.$li_class.''.$list_item_id.'><a href="'.$item_uri.'">'.$page_title.'</a> - Page Left:'.$page['lft'].' ///// Node Left:: '.$current_node['left'].'</li>'."\n";
- $html .= $list_item;
- $last_page_depth = $page['depth'];
- }
- // Make sure all the ULs are closed
- // This WAS > 0, didn't close properly. >1 looks like it solves it.
- if ($last_page_depth > 1)
- {
- $html .= "</ul>\n";
- $html .= str_repeat("</li>\n</ul>\n", $last_page_depth);
- }
- else
- {
- $html .= $ul_open ? "</ul>\n</li>\n</ul>" : "</ul>\n";
- }
- return $html;
- }
-
-
-
- /** -------------------------------------
- /** Tag: sitemap
- /**
- /** Returns a full tree of all site
- /** pages in <ul>, <xml> or text format.
- /** -------------------------------------*/
- function sitemap()
- {
- $html = "";
- $css_id = $this->EE->TMPL->fetch_param('css_id');
- $css_id = $css_id ? strtolower($css_id) : "sitemap";
- if ($css_id == "none")
- {
- $css_id = '';
- }
- $css_class = $this->EE->TMPL->fetch_param('css_class');
- $css_class = $css_class ? strtolower($css_class) : '';
- // DEPRECIATED SUPPORT for exclude_status and include_status
- $include_status = strtolower($this->EE->TMPL->fetch_param('include_status'));
- $exclude_status = strtolower($this->EE->TMPL->fetch_param('exclude_status'));
- // New, native EE status mode
- $status = $this->EE->TMPL->fetch_param('status');
- $status = $status == '' ? array() : explode('|', $status);
- $status = array_map('strtolower', $status); // match MySQL's case-insensitivity
- $status_state = 'positive';
- // Check for "not "
- if (substr($status[0], 0, 4) == 'not ')
- {
- $status_state = 'negative';
- $status[0] = trim(substr($status[0], 3));
- $status[] = 'closed';
- }
- else
- {
- $status[] = 'open';
- }
-
- $include_status_list = explode('|', $include_status);
- $exclude_status_list = explode('|', $exclude_status);
-
- // Remove the default "open" status if explicitely set
- if (in_array('open', $exclude_status_list))
- $status = array_filter($status, create_function('$v', 'return $v != "open";'));
-
- if ($status_state == 'positive')
- $status = array_merge($status, $include_status_list);
- elseif ($status_state == 'negative')
- $status = array_merge($status, $exclude_status_list);
- // Retrieve entry_ids to exclude
- $exclude = explode("|", $this->EE->TMPL->fetch_param('exclude'));
- // Sitemap mode -- Completely alternate output
- $mode = strtolower($this->EE->TMPL->fetch_param('mode'));
- if ($mode == "")
- {
- $mode = "html";
- }
- // Get site pages data
- $site_pages = $this->get_site_pages();
- // Get all pages
- $pages = $this->get_data();
- // Remove anything to be excluded from the results array
- $closed_parents = array();
-
- foreach ($pages as $key => $entry_data)
- {
- if ($status_state == 'negative' && in_array(strtolower($entry_data['status']), $status)
- || ($status_state == 'positive' && ! in_array(strtolower($entry_data['status']), $status))
- || in_array($entry_data['parent_id'], $closed_parents)
- || in_array($entry_data['entry_id'], $exclude))
- {
- $closed_parents[] = $entry_data['entry_id'];
- unset($pages[$key]);
- }
- }
- // Make sure array indices are incremental (0..X)
- $pages = array_values($pages);
- $home = $this->EE->functions->fetch_site_index(0,0);
- /** --------------------------------
- /** XML Sitemap Output
- /** --------------------------------*/
- if ($mode == "xml")
- {
- $html .= '<?xml version="1.0" encoding="UTF-8"?>'."\n".'<urlset'."\n\t".'xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"'."\n\t".'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"'."\n\t".'xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd">'."\n".'<!-- Created with Structure for ExpressionEngine (http://buildwithstructure.com) -->'."\n";
- foreach ($pages as $page)
- {
- $page_uri = $site_pages['uris'][$page['entry_id']];
- $item_uri = $this->EE->functions->remove_double_slashes($home . $page_uri);
- $xml_item = '<url>'."\n\t".'<loc>'.$item_uri.'</loc>'."\n\t".'<priority>1.00</priority>'."\n".'</url>'."\n";
- $html .= $xml_item;
- }
- $html .= '</urlset>';
- }
- elseif ($mode == "text")
- {
- foreach ($pages as $page)
- {
- $page_uri = $site_pages['uris'][$page['entry_id']];
- $item_uri = $this->EE->functions->remove_double_slashes($home.$page_uri);
- $xml_item = $item_uri."\n";
- $html .= $xml_item;
- }
- }
- /** --------------------------------
- /** HTML Sitemap Output
- /** --------------------------------*/
- else
- {
- $html .= "<ul id=\"$css_id\"" . ($css_class != '' ? " class=\"$css_class\"" : '') . ">\n";
- $ul_open = false;
- $last_page_depth = 0;
- foreach ($pages as $page)
- {
- $page_uri = $site_pages['uris'][$page['entry_id']];
- $item_uri = $this->EE->functions->remove_double_slashes($home . $page_uri);
- // Start a sub nav
- if ($page['depth'] > $last_page_depth)
- {
- $html = substr($html, 0, -6);
- $html .= "\n<ul>\n";
- $ul_open = true;
- }
- // Close a sub nav
- if ($page['depth'] < $last_page_depth)
- {
- // Finds the previous entry
- preg_match("~\<li( class=\".+?\"){0,1}>(\<.+?\</.+?>)~", $list_item, $matches);
- // Creates the new class entry
- if ($matches[1])
- {
- $last_item_class = substr($matches[1], 0, -1) . " last\"";
- }
- else
- {
- $last_item_class = " class=\"last\"";
- }
- // Stores the inner of the <li>
- $last_item_inner = $matches[2];
- // Replace the string
- $html = str_replace($list_item, "<li$last_item_class>$last_item_inner</li>\n", $html);
- // Calculate how many levels back I need to go
- $back_to = $last_page_depth - $page['depth'];
- $html .= str_repeat("</ul>\n</li>\n", $back_to);
- $ul_open = false;
- }
- // Is this the last in the list?
- $classes = '';
- $page_title = "";
- if ($page == end($pages))
- {
- $classes = ' class="last"';
- }
- if ($this->EE->config->item('auto_convert_high_ascii') != 'n')
- {
- $page_title = $page['title'];
- }
- else
- {
- $page_title = htmlspecialchars($page['title']);
- }
- $list_item = "<li$classes><a href='$item_uri'>".$page_title."</a></li>\n";
- $html .= $list_item;
- $last_page_depth = $page['depth'];
- }
- // Make sure all the ULs are closed
- if ($last_page_depth > 1)
- {
- $html .= "</ul>\n";
- $html .= str_repeat("</li>\n</ul>\n", $last_page_depth);
- }
- else
- {
- $html .= $ul_open ? "</ul>\n</li>\n</ul>" : "</ul>\n";
- }
- }
- return $html;
- }
-
-
-
- /** -------------------------------------
- /** Create a Breadcrumb Trail
- /** -------------------------------------*/
- function breadcrumb()
- {
-
- $site_pages = $this->get_site_pages();
- if ( ! $site_pages) return FALSE;
-
- // Get parameters
- $separator = $this->EE->TMPL->fetch_param('separator');
- $separator = $separator ? $separator : '»';
- $inc_separator = $this->EE->TMPL->fetch_param('inc_separator');
- $separator = $inc_separator === 'no' ? '' : $separator;
- $inc_home = $this->EE->TMPL->fetch_param('inc_home');
- $inc_home = $inc_home === 'no' ? false : true;
- $inc_here = $this->EE->TMPL->fetch_param('inc_here');
- $inc_here = $inc_here === 'no' ? false : true;
- $here_as_title = $this->EE->TMPL->fetch_param('here_as_title');
- $here_as_title = $here_as_title === 'yes' ? true : false;
- $wrap_each = $this->EE->TMPL->fetch_param('wrap_each');
- $wrap_each = $wrap_each ? $wrap_each : '';
- $wrap_here = $this->EE->TMPL->fetch_param('wrap_here');
- $wrap_here = $wrap_here ? $wrap_here : '';
- $wrap_separator = $this->EE->TMPL->fetch_param('wrap_separator');
- $wrap_separator = $wrap_separator ? $wrap_separator : '';
- $separator = $wrap_separator ? "<{$wrap_separator}>{$separator}</{$wrap_separator}>" : $separator;
- // Are we passed a URI to work from? If not use current URI
- $uri = $this->EE->TMPL->fetch_param('uri');
- $uri = $uri ? $uri : '/'.$this->EE->uri->uri_string().'/';
- $uri = html_entity_decode($uri);
- // get current entry id
- $entry_id = array_search($uri, $site_pages['uris']);
-
- // get node of the current entry
- $node = $entry_id ? $this->nset->getNode($entry_id) : false;
-
- // node does not have any structure data we return nothing to prevent errors
- if ($node === false && ! $entry_id)
- {
- return '';
- }
- // if we have an entry id but no node, we have listing entry
- if ($entry_id && ! $node)
- {
- // get entry's parent id
- $pid = $this->get_pid_for_listing_entry($entry_id);
- // get node of parent entry
- $node = $this->nset->getNode($pid);
- }
- $right = $node['right'];
- $inc_current = isset($pid) ? '=' : '';
- $sql = "SELECT node.*, expt.title
- FROM exp_structure AS node
- INNER JOIN exp_channel_titles AS expt
- ON node.entry_id = expt.entry_id
- WHERE node.lft > 1
- AND node.lft < $right
- AND node.rgt >$inc_current $right
- ORDER BY node.lft";
- $result = $this->EE->db->query($sql);
-
- $home = trim($this->EE->functions->fetch_site_index(0, 0), '/');
- $crumbs = array();
- if ($inc_home)
- {
- $crumbs[] = '<a href="' . $home . '">Home</a>';
- }
- foreach ($result->result_array() as $entry)
- {
- $crumbs[] = '<a href="' . $home . $site_pages['uris'][$entry['entry_id']] . '">' . $entry['title'] . '</a>';
- }
- // If inc_here param is yes/true then show the here name
- if ($inc_here)
- {
- // If here_as_title is yes/true then show here as page title
- if ($here_as_title)
- {
- $sql2 = "SELECT title
- FROM exp_channel_titles
- WHERE entry_id = $entry_id";
- $result2 = $this->EE->db->query($sql2);
- $result2 = $result2->result_array();
- $crumbs[] = !empty($wrap_here) ? "<{$wrap_here}>{$result2[0]['title']}</{$wrap_here}>" : $result2[0]['title'];
- }
- else
- {
- $crumbs[] = !empty($wrap_here) ? "<{$wrap_here}>Here</{$wrap_here}>" : "Here";
- }
- }
- for ($i=0, $count=count($crumbs); $i < $count; $i++)
- {
- if ( ! empty( $separator) && $i != ($count-1))
- {
- $crumbs[$i] = "{$crumbs[$i]} {$separator} ";
- }
- if ( ! empty($wrap_each))
- {
- $crumbs[$i] = "<{$wrap_each}>{$crumbs[$i]}</{$wrap_each}>";
- }
- }
- return implode('', $crumbs);
- }
-
-
- /** -------------------------------------
- /** Tag: titletrail
- /** -------------------------------------*/
-
- function titletrail()
- {
- // get site pages data
- $site_pages = $this->get_site_pages();
- if (!$site_pages) return FALSE;
- // get current uri path
- $uri = '/'.$this->EE->uri->uri_string().'/';
- // get current entry id
- $entry_id = array_search($uri, $site_pages['uris']);
- // get node of the current entry
- $node = $entry_id ? $this->nset->getNode($entry_id) : false;
- // node does not have any structure data we return site_name to prevent errors
- if ($node === false && !$entry_id)
- {
- return stripslashes($this->EE->config->item('site_name'));
- }
- // if we have an entry id but no node, we have listing entry
- if ($entry_id && ! $node)
- {
- // get entry's parent id
- $pid = $this->get_pid_for_listing_entry($entry_id);
- // get node of parent entry
- // because we will be showing nav sub from its view point
- $node = $this->nset->getNode($pid);
- }
- // Fetch params
- $separator = $this->EE->TMPL->fetch_param('separator');
- $separator = $separator ? " " . $separator . " " : ' | ';
- $reverse = $this->EE->TMPL->fetch_param('reverse');
- $reverse = ($reverse == 'yes') ? true : false;
- $right = $node['right'];
- $inc_current = isset($pid) ? '=' : '';
- $sql = "SELECT node.*, expt.title
- FROM exp_structure AS node
- INNER JOIN exp_channel_titles AS expt
- ON node.entry_id = expt.entry_id
- WHERE node.lft > 1
- AND node.lft < $right
- AND node.rgt >$inc_current $right
- ORDER BY node.lft DESC";
- $result = $this->EE->db->query($sql);
- $sql2 = "SELECT title
- FROM exp_channel_titles
- WHERE entry_id = $entry_id";
- $result2 = $this->EE->db->query($sql2);
- // Create an array of the page titles and site name
- // If reverse param is true then flip it prior to output
-
- $title_row = $result2->result_array();
- $title_row = $title_row[0]['title'];
- $title_array = array();
- $title_array[] = $title_row;
- foreach ($result->result_array() as $entry)
- {
- $title_array[] = $entry['title'];
- }
- $title_array[] = stripslashes($this->EE->config->item('site_name'));
- if ($reverse === true)
- {
- $title_array = array_reverse($title_array);
- }
- $html = implode($separator, $title_array);
- return $html;
- }
-
- /** -------------------------------------
- /** Tag: top_level_title
- /** Outputs the first segment's title
- /** -------------------------------------*/
-
- function top_level_title()
- {
- $site_pages = $this->get_site_pages(); // get site pages data
- if ( ! $site_pages)
- return FALSE;
- $seg1 = '/'.$this->EE->uri->segment(1).'/'; // get segment 1 value
- $top_id = array_search($seg1, $site_pages['uris']);
- if ($top_id)
- {
- $this->EE->db->where('entry_id', $top_id);
- $this->EE->db->limit(1);
-
- $query=$this->EE->db->get('exp_channel_titles');
- if ($query->num_rows() == 1)
- {
- $row = $query->row();
- return $row->title;
- }
- }
- return '';
- }
-
-
-
- /** -------------------------------------
- /** Tag: parent_title
- /** -------------------------------------*/
- function parent_title($entry_id = NULL)
- {
- $html = "";
- // get site pages data
- $site_pages = $this->get_site_pages();
- if (!$site_pages) return FALSE;
- // get current uri path
- $uri = '/'.$this->EE->uri->uri_string().'/';
- // get current entry id
- $entry_id = $entry_id ? $entry_id : array_search($uri, $site_pages['uris']);
- // get node of the current entry
- $node = $entry_id ? $this->nset->getNode($entry_id) : false;
- // node does not have any structure data we return site_name to prevent errors
- if ($node === false && ! $entry_id)
- {
- return stripslashes($this->EE->config->item('site_name'));
- }
- // if we have an entry id but no node, we have listing entry
- if ($entry_id && ! $node)
- {
- // get entry's parent id
- $pid = $this->get_pid_for_listing_entry($entry_id);
- // get node of parent entry
- // because we will be showing nav sub from its view point
- $node = $this->nset->getNode($pid);
- }
- $right = $node['right'];
- $inc_current = isset($pid) ? '=' : '';
- $sql = "SELECT node.*, expt.title
- FROM exp_structure AS node
- INNER JOIN exp_channel_titles AS expt
- ON node.entry_id = expt.entry_id
- WHERE node.lft > 1
- AND node.lft < $right
- AND node.rgt >$inc_current $right
- ORDER BY node.lft DESC";
- $result = $this->EE->db->query($sql);
- $html = $result->result_array();
- $html = @$html[0]['title'];
- return $html;
- }
- /** -------------------------------------
- /** Tag: page_slug
- /** -------------------------------------*/
- function page_slug($entry_id = NULL)
- {
- $slug = "";
- $uri = "";
- // get site pages data
- $site_pages = $this->get_site_pages();
- if (!$site_pages) return FALSE;
- $uri = '/'.$this->EE->uri->uri_string().'/';
- if ($entry_id == NULL)
- {
- // get current entry id
- $current_page_entry_id = array_search($uri, $site_pages['uris']);
- // Fetch params
- $entry_id = $this->EE->TMPL->fetch_param('entry_id');
- $entry_id = $entry_id ? $entry_id : $current_page_entry_id;
- }
-
- // get page uri slug without parents
- @$uri = $site_pages['uris'][$entry_id];
-
- // if there are no / then we have a root slug already, else get the end
- $slug .= trim($uri, '/');
- if (strpos($slug, '/'))
- {
- $slug = substr(strrchr($slug, '/'), 1);
- }
- return $slug;
- }
-
-
- /** -------------------------------------
- /** Tag: page_id
- /** -------------------------------------*/
- function page_id($entry_uri = NULL)
- {
- $slug = "";
- // get site pages data
- $site_pages = $this->get_site_pages();
- if ( ! $site_pages) return FALSE;
- // Fetch params
- $entry_uri = $this->EE->TMPL->fetch_param('entry_uri');
-
- // echo $entry_uri;
- if ($entry_uri == NULL || $entry_uri == '')
- {
- $entry_uri = '/'.$this->EE->uri->uri_string().'/';
- }
- // get current entry id
- $current_page_entry_id = array_search($entry_uri, $site_pages['uris']);
-
- return $current_page_entry_id;
- }
-
-
-
-
- // --------------------------------------------------------------------
- // Child IDs function
- // Returns a string of IDs for a given parent
- function child_ids()
- {
- $site_pages = $this->get_site_pages();
- if (!$site_pages) return FALSE;
-
- // Fetch our parent ID, or if none default to the current page
- $parent = $this->EE->TMPL->fetch_param('entry_id');
- $start_from = $this->EE->TMPL->fetch_param('start_from') ? $this->EE->TMPL->fetch_param('start_from') : false;
-
- // Only do an automatic lookup if we're not requiring a parent ID, and no entry_id was defined.
- if ( ! $parent AND ! $start_from)
- {
- // Find the parent in the site pages array using URL
- $current_uri = implode('/', $this->EE->uri->segment_array());
- $parent = array_search("/$current_uri/", $site_pages['uris']);
- }
- elseif($start_from)
- {
- $start_from = trim($start_from, '/');
- $parent = array_search("/$start_from/", $site_pages['uris']);
- }
-
- /…
Large files files are truncated, but you can click here to view the full file