Changeset 682 for trunk/lib


Ignore:
Timestamp:
May 19, 2019 10:50:51 PM (5 years ago)
Author:
anonymous
Message:

Add argument to getBreadcrumbs* methods, which enables use of app->ohref(). Fix assumed bugs - hopefully will not cause a regression

File:
1 edited

Legend:

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

    r590 r682  
    258258     * @return  string   Breadcrumbs or empty string if breadcrumbs param not set.
    259259     */
    260     public function getBreadcrumbsArray()
     260    public function getBreadcrumbsArray($carry_args=null)
    261261    {
    262262        $app =& App::getInstance();
     
    270270                    break;
    271271                }
     272                if (!is_null($carry_args)) {
     273                    // If this function is called with $carry_args, employ the ohref() method.
     274                    $url = $app->ohref($page['url'], $carry_args);
     275                } else {
     276                    // Otherwise let the URL pass through as-is (the wise developer must have provided the correct URL when calling $nav->add(
)).
     277                    $url = $page['url'];
     278                }
    272279                if ($crumb_count <= 1) {
    273280                    // The last crumb.
    274281                    if ('' == trim($page['url']) || $crumb_count <= $this->getParam('chop_breadcrumb_links')) {
    275                         // A crumb with no link.
     282                        // A last crumb with no link.
    276283                        $breadcrumbs[] = array(
    277                             'url' => $_SERVER['REQUEST_URI'],
     284                            'url' => false,
    278285                            'title' => sprintf($this->getParam('last_crumb_format'), $page['title']),
    279286                            'class' => 'current'
    280287                        );
    281288                    } else if ($crumb_count > $this->getParam('chop_breadcrumb_links')) {
    282                         // A normal linked crumb.
     289                        // A last linked crumb.
    283290                        $breadcrumbs[] = array(
    284                             'url' => $page['url'],
     291                            'url' => $url,
    285292                            'title' => sprintf($this->getParam('last_crumb_format'), $page['title']),
    286293                            'class' => '',
     
    298305                        // A normal linked crumb.
    299306                        $breadcrumbs[] = array(
    300                             'url' => $page['url'],
     307                            'url' => $url,
    301308                            'title' => $page['title'],
    302309                            'class' => '',
     
    319326     * @return  string   Breadcrumbs or empty string if breadcrumbs param not set.
    320327     */
    321     public function getBreadcrumbs()
     328    public function getBreadcrumbs($carry_args=null)
    322329    {
    323330        $app =& App::getInstance();
     
    332339                    break;
    333340                }
     341                if (!is_null($carry_args)) {
     342                    // If this function is called with $carry_args, employ the ohref() method.
     343                    $url = $app->ohref($page['url'], $carry_args);
     344                } else {
     345                    // Otherwise let the URL pass through as-is (the wise developer must have provided the correct URL when calling $nav->add(
)).
     346                    $url = $page['url'];
     347                }
    334348                if ($crumb_count <= 1) {
    335349                    // The last crumb.
    336350                    if ('' == trim($page['url']) || $crumb_count <= $this->getParam('chop_breadcrumb_links')) {
    337                         // A crumb with no link.
     351                        // A last crumb with no link.
    338352                        $breadcrumbs[] =  sprintf($this->getParam('last_crumb_format'), oTxt($page['title'], true));
    339353                    } else if ($crumb_count > $this->getParam('chop_breadcrumb_links')) {
    340                         // A normal linked crumb.
    341                         $breadcrumbs[] =  '<a href="' . $page['url'] . '">' . sprintf($this->getParam('last_crumb_format'), oTxt($page['title'], true)) . '</a>';
     354                        // A last linked crumb.
     355                        $breadcrumbs[] =  '<a href="' . $url . '">' . sprintf($this->getParam('last_crumb_format'), oTxt($page['title'], true)) . '</a>';
    342356                    }
    343357                } else {
     
    347361                    } else {
    348362                        // A normal linked crumb.
    349                         $breadcrumbs[] = '<a href="' . $page['url'] . '">' . oTxt($page['title'], true) . '</a>';
     363                        $breadcrumbs[] = '<a href="' . $url . '">' . oTxt($page['title'], true) . '</a>';
    350364                    }
    351365                }
     
    369383    * @since    07 Sep 2014 12:22:19
    370384    */
    371     public function getBreadcrumbsUL()
    372     {
     385    public function getBreadcrumbsUL($carry_args=null, $ul_open_tag='<ul class="breadcrumbs">')
     386    {
     387        $app =& App::getInstance();
     388
    373389        $out = '';
    374         $breadcrumbs = $this->getBreadcrumbsArray();
     390        $breadcrumbs = $this->getBreadcrumbsArray($carry_args);
    375391        if (!empty($breadcrumbs)) {
    376             $out = '<ul class="breadcrumbs">';
     392            $out = $ul_open_tag;
    377393            foreach ($breadcrumbs as $b) {
    378394                $printclass = '' != $b['class'] ? sprintf(' class="%s"', $b['class']) : '';
    379                 $out .= sprintf('<li%s><a href="%s">%s</a></li>', $printclass, $b['url'], $b['title']);
     395                if ('' == trim($b['url'])) {
     396                    // A crumb with no link.
     397                    $out .= sprintf('<li%s>%s</li>', $printclass, $b['title']);
     398                } else {
     399                    // A normal linked crumb.
     400                    $out .= sprintf('<li%s><a href="%s">%s</a></li>', $printclass, $b['url'], $b['title']);
     401                }
    380402            }
    381403            $out .= '</ul>';
Note: See TracChangeset for help on using the changeset viewer.