Ignore:
Timestamp:
Aug 14, 2014 8:29:47 AM (10 years ago)
Author:
anonymous
Message:

Small bugs fixed while doing SBImedia

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/Navigation.inc.php

    r484 r485  
    198198
    199199    /**
     200     * Returns the path from root up to the current page as an array.
     201     *
     202     * @access  public
     203     * @param   string   $key   Which value to use in the path (usually head_title or body_title or just title).
     204     * @return  mixed           Path (string) or false if path param is not set.
     205     */
     206    public function getPathArray($key='title')
     207    {
     208        $path = array();
     209        if ($this->getParam('path')) {
     210            foreach ($this->pages as $page) {
     211                $path[] = strip_tags($page[$key]);
     212            }
     213        }
     214        return $path;
     215    }
     216
     217    /**
    200218     * Returns the text path from root up to the current page, separated by the
    201219     * path_delimiter.
     
    207225    public function getPath($key='title')
    208226    {
    209         if ($this->getParam('path')) {
    210             $path = '';
    211             $pathmark = '';
     227
     228        $path = $this->getPathArray();
     229        return empty($path) ? '' : join(oTxt($this->getParam('path_delimiter'), true), $path);
     230    }
     231
     232    /**
     233     * Returns the breadcrumbs from the root page to the current page.
     234     * Breadcrumbs are the text path with pages titles linked to that page.
     235     *
     236     * @access  public
     237     * @return  string   Breadcrumbs or empty string if breadcrumbs param not set.
     238     */
     239    public function getBreadcrumbsArray()
     240    {
     241        $app =& App::getInstance();
     242
     243        if ($this->getParam('breadcrumbs')) {
     244            $breadcrumbs = array();
     245            $crumb_count = sizeof($this->pages);
    212246            foreach ($this->pages as $page) {
    213                 $path .= oTxt($pathmark . strip_tags($page[$key]), true);
    214                 $pathmark = $this->getParam('path_delimiter');
    215             }
    216             return $path;
     247                if ($crumb_count <= $this->getParam('chop_breadcrumbs')) {
     248                    // Stop gathering crumbs.
     249                    break;
     250                }
     251                if ($crumb_count <= 1) {
     252                    // The last crumb.
     253                    if ('' == trim($page['url']) || $crumb_count <= $this->getParam('chop_breadcrumb_links')) {
     254                        // A crumb with no link.
     255                        $breadcrumbs[] = array(
     256                            'url' => false,
     257                            'title' => sprintf($this->getParam('last_crumb_format'), $page['title'])
     258                        );
     259                    } else if ($crumb_count > $this->getParam('chop_breadcrumb_links')) {
     260                        // A normal linked crumb.
     261                        $breadcrumbs[] = array(
     262                            'url' => $page['url'],
     263                            'title' => sprintf($this->getParam('last_crumb_format'), $page['title'])
     264                        );
     265                    }
     266                } else {
     267                    if ('' == trim($page['url'])) {
     268                        // A crumb with no link.
     269                        $breadcrumbs[] = array(
     270                            'url' => false,
     271                            'title' => $page['title']
     272                        );
     273                    } else {
     274                        // A normal linked crumb.
     275                        $breadcrumbs[] = array(
     276                            'url' => $page['url'],
     277                            'title' => $page['title']
     278                        );
     279                    }
     280                }
     281                $crumb_count--;
     282            }
     283            return $breadcrumbs;
    217284        } else {
    218             return false;
     285            return array();
    219286        }
    220287    }
     
    247314                    } else if ($crumb_count > $this->getParam('chop_breadcrumb_links')) {
    248315                        // A normal linked crumb.
    249                         $breadcrumbs[] =  '<a href="' . $app->oHREF($page['url']) . '">' . sprintf($this->getParam('last_crumb_format'), oTxt($page['title'], true)) . '</a>';
     316                        $breadcrumbs[] =  '<a href="' . $page['url'] . '">' . sprintf($this->getParam('last_crumb_format'), oTxt($page['title'], true)) . '</a>';
    250317                    }
    251318                } else {
     
    255322                    } else {
    256323                        // A normal linked crumb.
    257                         $breadcrumbs[] = '<a href="' . $app->oHREF($page['url']) . '">' . oTxt($page['title'], true) . '</a>';
     324                        $breadcrumbs[] = '<a href="' . $page['url'] . '">' . oTxt($page['title'], true) . '</a>';
    258325                    }
    259326                }
Note: See TracChangeset for help on using the changeset viewer.