Created
September 14, 2013 14:06
-
-
Save jackiewu/6562317 to your computer and use it in GitHub Desktop.
[pyrocms] Breadcrumbs 使用 Navigation `Header` 的架構為主來呈現。
This file contains 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
private function _build_breadcumbs() | |
{ | |
$old_breadcrumbs = $this->_breadcrumbs; | |
$this->_breadcrumbs = array(); | |
$this->_override_breadcrumbs = array(); | |
$this->_ci->load->model('navigation/navigation_m'); | |
$this->_ci->load->model('settings/settings_m'); | |
$site_name = $this->_ci->settings_m->get('site_name'); | |
$navs = $this->_ci->navigation_m->get_link_tree('header'); | |
$parent = array(); | |
$curr = current_url(); | |
$break = false; | |
foreach ($navs as $key => $nav) { | |
foreach ($nav['children'] as $c_key => $c_nav) { | |
foreach ($c_nav['children'] as $c_c_key => $c_c_nav) { | |
if ($break OR preg_match('@' . $c_c_nav['url'] . '@', $curr)) | |
{ | |
$parent['c_c_parent'] = $c_c_key; | |
$break = true; | |
break; | |
} | |
} | |
if ($break OR preg_match('@' . $c_nav['url'] . '@', $curr)) | |
{ | |
$parent['c_parent'] = $c_key; | |
$break = true; | |
break; | |
} | |
} | |
if ($break OR preg_match('@' . $nav['url'] . '@', $curr)) | |
{ | |
$parent['parent'] = $key; | |
$break = true; | |
break; | |
} | |
} | |
if (isset($parent['parent'])) | |
{ | |
if (isset($parent['c_parent'])) | |
{ | |
if (isset($parent['c_c_parent'])) | |
{ | |
$this->_breadcrumbs[] = array('name' => $site_name->value, 'uri' => site_url()); | |
$this->_breadcrumbs[] = array('name' => $navs[$parent['parent']]['title'], 'uri' => $navs[$parent['parent']]['url']); | |
$this->_breadcrumbs[] = array('name' => $navs[$parent['parent']]['children'][$parent['c_parent']]['title'], 'uri' => $navs[$parent['parent']]['children'][$parent['c_parent']]['url']); | |
$this->_breadcrumbs[] = array('name' => $navs[$parent['parent']]['children'][$parent['c_parent']]['children'][$parent['c_c_parent']]['title']); | |
} | |
else | |
{ | |
$this->_breadcrumbs[] = array('name' => $site_name->value, 'uri' => site_url()); | |
$this->_breadcrumbs[] = array('name' => $navs[$parent['parent']]['title'], 'uri' => $navs[$parent['parent']]['url']); | |
$this->_breadcrumbs[] = array('name' => $navs[$parent['parent']]['children'][$parent['c_parent']]['title']); | |
} | |
} | |
else | |
{ | |
$this->_breadcrumbs[] = array('name' => $site_name->value, 'uri' => site_url()); | |
$this->_breadcrumbs[] = array('name' => $navs[$parent['parent']]['title']); | |
} | |
} | |
else | |
{ | |
$this->_breadcrumbs[] = array('name' => $site_name->value); | |
} | |
if (count($old_breadcrumbs) > 0) | |
{ | |
foreach ($old_breadcrumbs as $key => $old_breadcrumb) { | |
if (preg_match('@' . $old_breadcrumb['uri'] . '@', $curr)) | |
{ | |
array_splice($old_breadcrumbs, $key, 1); | |
if (count($old_breadcrumbs) > 0) | |
{ | |
$this->_breadcrumbs[count($this->_breadcrumbs) - 1]['uri'] = site_url($old_breadcrumb['uri']); | |
} | |
break; | |
} | |
} | |
$this->_breadcrumbs = array_merge($this->_breadcrumbs, $old_breadcrumbs); | |
} | |
return $this->_breadcrumbs; | |
} | |
public function build($view, $data = array(), $return = false, $IE_cache = true, $pre_parsed_view = false, $template = array()) | |
{ | |
//... | |
// Setup Breadcrumbs | |
if ( ! $template) | |
{ | |
$this->_build_breadcumbs(); | |
} | |
else | |
{ | |
$template['breadcrumbs'] = $this->_build_breadcumbs(); | |
} | |
//... | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment