Page 1 of 2

breadcrumbs for CMSimple

Posted: Thu Apr 23, 2015 11:52 am
by Termin
Hi,

please help to integrate breadcrumbs for CMSimple_XH

Code: Select all

function breadcrumbs($separator = ' » ', $home = 'Home') {
    
    $path = array_filter(explode('/', parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH)));
    $base_url = ($_SERVER['HTTPS'] ? 'https' : 'http') . '://' . $_SERVER['HTTP_HOST'] . '/';
    $breadcrumbs = array("<a href=\"$base_url\">$home</a>");
 
    $last = end(array_keys($path));
 
    foreach ($path AS $x => $crumb) {
        $title = ucwords(str_replace(array('.php', '_'), Array('', ' '), $crumb));
        if ($x != $last){
            $breadcrumbs[] = '<a href="$base_url$crumb">$title</a>';
        }else{
            $breadcrumbs[] = $title;
        }
    }
 
    return implode($separator, $breadcrumbs);
}  

Re: breadcrumbs for CMSimple

Posted: Thu Apr 23, 2015 12:01 pm
by cmb
Termin wrote:please help to integrate breadcrumbs for CMSimple_XH
There is already locator() which is supposed to show a breadcrumb navigation. In the template:

Code: Select all

<php echo locator()?>

Re: breadcrumbs for CMSimple

Posted: Thu Apr 23, 2015 10:35 pm
by Termin
Hi cmb,
There is already locator() which is supposed to show a breadcrumb navigation. In the template:
no matter in a the locator to integrate Breadcrumbs:

https://developers.google.com/structure ... hl=de&rd=1
http://www.mediawiki.org/wiki/Extension ... readcrumbs
http://schema.org/docs/schema_org_rdfa.html

Re: breadcrumbs for CMSimple

Posted: Thu Apr 23, 2015 11:09 pm
by cmb
Ah, now I understand! I was not aware that there are Microdata and RDFa markup standards for breadcrumbs -- thanks for the info. Seems to be quite useful.

I'll have a closer look at the issue tomorrow.

Re: breadcrumbs for CMSimple

Posted: Sat Apr 25, 2015 5:14 pm
by cmb
As a first step I have refactored the locator() function. It works exactly as it did before, but now it should be easy to adapt the generated HTML so that it conforms to whatever "breadcrumb" specification. Simply modify breadcrumbs() as desired. The code:

Code: Select all

<?php

/**
 * Returns the locator (breadcrumb navigation).
 *
 * @return string HTML
 */
function breadcrumbs()
{
    $html = '';
    $breadcrumbs = XH_getLocatorModel();
    $last = count($breadcrumbs) - 1;
    foreach ($breadcrumbs as $i => $breadcrumb) {
        list($title, $url) = $breadcrumb;
        if ($i > 0) {
            $html .= ' > ';
        }
        if (isset($url) && $i < $last) {
            $html .= '<a href="' . $url . '">' . $title . '</a>';
        } else {
            $html .= $title;
        }
    }
    return $html;
}

/**
 * Returns the locator (breadcrumb navigation) model.
 *
 * The locator model is an ordered list of breadcrumb items, where each item is
 * an array of the title and the URL. If there is no appropriate URL, the
 * element is null.
 *
 * @return array
 *
 * @global string The title of the page.
 * @global array  The headings of the pages.
 * @global int    The index of the current page.
 * @global string The requested special function.
 * @global array  The menu levels of the pages.
 * @global array  The localization of the core.
 * @global array  The configuration of the core.
 * @global int    The index of the first published page.
 *
 * @since 1.7
 */
function XH_getLocatorModel()
{
    global $title, $h, $s, $f, $l, $tx, $cf, $_XH_firstPublishedPage;

    if (hide($s) && $cf['show_hidden']['path_locator'] != 'true') {
        return array(array($h[$s], XH_getPageURL($s)));
    }
    if ($s == $_XH_firstPublishedPage) {
        return array(array($h[$s], XH_getPageURL($s)));
    } elseif ($title != '' && (!isset($h[$s]) || $h[$s] != $title)) {
        $res = array(array($title, null));
    } elseif ($f != '') {
        return array(array(ucfirst($f), null));
    } elseif ($s > $_XH_firstPublishedPage) {
        $res = array();
        $tl = $l[$s];
        if ($tl > 1) {
            for ($i = $s - 1; $i >= $_XH_firstPublishedPage; $i--) {
                if ($l[$i] < $tl) {
                    array_unshift($res, array($h[$i], XH_getPageURL($i)));
                    $tl--;
                }
                if ($tl < 2) {
                    break;
                }
            }
        }
    } else {
        return array(array('&nbsp;', null));
    }
    if ($cf['locator']['show_homepage'] == 'true') {
        array_unshift(
            $res,
            array($tx['locator']['home'], XH_getPageURL($_XH_firstPublishedPage))
        );
        if ($s > $_XH_firstPublishedPage && $h[$s] == $title) {
            $res[] = array($h[$s], XH_getPageURL($s));
        }
        return $res;
    } else {
        if ($s > $_XH_firstPublishedPage && $h[$s] == $title) {
            $res[] = array($h[$s], XH_getPageURL($s));
        }
        return $res;
    }
}

/**
 * Returns the full URL of a page.
 *
 * @param int $index A valid page index.
 *
 * @return string
 *
 * @global string The script name.
 * @global array  The page URLs.
 *
 * @since 1.7
 */
function XH_getPageURL($index)
{
    global $sn, $u;

    return $sn . '?' . $u[$index];
} 
Call <?php echo breadcrumbs()?> instead of <?php locator()?> in the template.

Does that work for you?

Re: breadcrumbs for CMSimple

Posted: Mon Apr 27, 2015 12:59 pm
by Termin
Hi cmb

thank you, everything works correctly

HTML

Code: Select all

<div class="breadcrumb" prefix="v: http://rdf.data-vocabulary.org/#"><?php echo breadcrumbs();?></div>
PHP

Code: Select all

function breadcrumbs()
{
    $html = '';
    $breadcrumbs = XH_getLocatorModel();
    $last = count($breadcrumbs) - 1;
    foreach ($breadcrumbs as $i => $breadcrumb) {
        list($title, $url) = $breadcrumb;
        if ($i > 0) {
            $html .= ' > ';
        }
        if (isset($url) && $i < $last) {
            $html .= '<span typeof="v:Breadcrumb"><a rel="v:url" property="v:title" href="' . $url . '">' . $title . '</a></span>';
        } else {
            $html .= $title;
        }
    }
    return $html;
}

Code: Select all

Does that work for you?
This is all you need, I did on the website http://www.mapsky.ru/

Re: breadcrumbs for CMSimple

Posted: Tue Apr 28, 2015 11:43 pm
by cmb
Termin wrote:This is all you need
Thanks, Termin.

I propose to put that up for voting for sprint #4. The most basic improvement would be the refactoring, which is available as feature branch. Adding the RDF markup might be done as well, but I'm not really sure about that, because it seems there are several competing (draft) specifications.

Thoughts?

Re: breadcrumbs for CMSimple

Posted: Thu Apr 30, 2015 4:44 pm
by Termin
Hi cmb
Thoughts?
I don't understand the question

Re: breadcrumbs for CMSimple

Posted: Thu Apr 30, 2015 4:57 pm
by cmb
Termin wrote:I don't understand the question
I was asking for the opinion of others on that issue.

Re: breadcrumbs for CMSimple

Posted: Wed May 13, 2015 11:49 pm
by cmb
I propose to merge r1580 from the "breadcrumbs" branch.