Dotclear

source: plugins/breadcrumb/_public.php @ 3731:3770620079d4

Revision 3731:3770620079d4, 7.0 KB checked in by franck <carnet.franck.paul@…>, 8 years ago (diff)

Simplify licence block at the beginning of each file

  • Property exe set to *
RevLine 
[3009]1<?php
[3731]2/**
3 * @brief breadcrumb, a plugin for Dotclear 2
4 *
5 * @package Dotclear
6 * @subpackage Plugins
7 *
8 * @copyright Olivier Meunier & Association Dotclear
9 * @copyright GPL-2.0-only
10 */
[3009]11
[3730]12if (!defined('DC_RC_PATH')) {return;}
[3009]13
14# Breadcrumb template functions
[3730]15$core->tpl->addValue('Breadcrumb', array('tplBreadcrumb', 'breadcrumb'));
[3009]16
17class tplBreadcrumb
18{
[3730]19    # Template function
20    public static function breadcrumb($attr)
21    {
22        $separator = isset($attr['separator']) ? $attr['separator'] : '';
[3009]23
[3730]24        return '<?php echo tplBreadcrumb::displayBreadcrumb(' .
25        "'" . addslashes($separator) . "'" .
26            '); ?>';
27    }
[3009]28
[3730]29    public static function displayBreadcrumb($separator)
30    {
31        global $core, $_ctx;
[3009]32
[3730]33        $ret = '';
[3009]34
[3730]35        # Check if breadcrumb enabled for the current blog
36        $core->blog->settings->addNameSpace('breadcrumb');
37        if (!$core->blog->settings->breadcrumb->breadcrumb_enabled) {
38            return $ret;
39        }
[3009]40
[3730]41        if ($separator == '') {
42            $separator = ' &rsaquo; ';
43        }
[3009]44
[3730]45        // Get current page if set
46        $page = isset($GLOBALS['_page_number']) ? (integer) $GLOBALS['_page_number'] : 0;
[3009]47
[3730]48        switch ($core->url->type) {
[3009]49
[3730]50            case 'default':
51                // Home (first page only)
52                $ret = '<span id="bc-home">' . __('Home') . '</span>';
53                break;
[3009]54
[3730]55            case 'default-page':
56                // Home`(page 2 to n)
57                $ret = '<a id="bc-home" href="' . $core->blog->url . '">' . __('Home') . '</a>';
58                $ret .= $separator . sprintf(__('page %d'), $page);
59                break;
[3009]60
[3730]61            case 'category':
62                // Category
63                $ret        = '<a id="bc-home" href="' . $core->blog->url . '">' . __('Home') . '</a>';
64                $categories = $core->blog->getCategoryParents($_ctx->categories->cat_id);
65                while ($categories->fetch()) {
66                    $ret .= $separator . '<a href="' . $core->blog->url . $core->url->getURLFor('category', $categories->cat_url) . '">' . $categories->cat_title . '</a>';
67                }
68                if ($page == 0) {
69                    $ret .= $separator . $_ctx->categories->cat_title;
70                } else {
71                    $ret .= $separator . '<a href="' . $core->blog->url . $core->url->getURLFor('category', $_ctx->categories->cat_url) . '">' . $_ctx->categories->cat_title . '</a>';
72                    $ret .= $separator . sprintf(__('page %d'), $page);
73                }
74                break;
[3009]75
[3730]76            case 'post':
77                // Post
78                $ret = '<a id="bc-home" href="' . $core->blog->url . '">' . __('Home') . '</a>';
79                if ($_ctx->posts->cat_id) {
80                    // Parents cats of post's cat
81                    $categories = $core->blog->getCategoryParents($_ctx->posts->cat_id);
82                    while ($categories->fetch()) {
83                        $ret .= $separator . '<a href="' . $core->blog->url . $core->url->getURLFor('category', $categories->cat_url) . '">' . $categories->cat_title . '</a>';
84                    }
85                    // Post's cat
86                    $categories = $core->blog->getCategory($_ctx->posts->cat_id);
87                    $ret .= $separator . '<a href="' . $core->blog->url . $core->url->getURLFor('category', $categories->cat_url) . '">' . $categories->cat_title . '</a>';
88                }
89                $ret .= $separator . $_ctx->posts->post_title;
90                break;
[3009]91
[3730]92            case 'lang':
93                // Lang
94                $ret   = '<a id="bc-home" href="' . $core->blog->url . '">' . __('Home') . '</a>';
95                $langs = l10n::getISOCodes();
96                $ret .= $separator . (isset($langs[$_ctx->cur_lang]) ? $langs[$_ctx->cur_lang] : $_ctx->cur_lang);
97                break;
[3009]98
[3730]99            case 'archive':
100                // Archives
101                $ret = '<a id="bc-home" href="' . $core->blog->url . '">' . __('Home') . '</a>';
102                if (!$_ctx->archives) {
103                    // Global archives
104                    $ret .= $separator . __('Archives');
105                } else {
106                    // Month archive
107                    $ret .= $separator . '<a href="' . $core->blog->url . $core->url->getURLFor("archive") . '">' . __('Archives') . '</a>';
108                    $ret .= $separator . dt::dt2str('%B %Y', $_ctx->archives->dt);
109                }
110                break;
[3009]111
[3730]112            case 'pages':
113                // Page
114                $ret = '<a id="bc-home" href="' . $core->blog->url . '">' . __('Home') . '</a>';
115                $ret .= $separator . $_ctx->posts->post_title;
116                break;
[3009]117
[3730]118            case 'tags':
119                // All tags
120                $ret = '<a id="bc-home" href="' . $core->blog->url . '">' . __('Home') . '</a>';
121                $ret .= $separator . __('All tags');
122                break;
[3009]123
[3730]124            case 'tag':
125                // Tag
126                $ret = '<a id="bc-home" href="' . $core->blog->url . '">' . __('Home') . '</a>';
127                $ret .= $separator . '<a href="' . $core->blog->url . $core->url->getURLFor("tags") . '">' . __('All tags') . '</a>';
128                if ($page == 0) {
129                    $ret .= $separator . $_ctx->meta->meta_id;
130                } else {
131                    $ret .= $separator . '<a href="' . $core->blog->url . $core->url->getURLFor("tag", rawurlencode($_ctx->meta->meta_id)) . '">' . $_ctx->meta->meta_id . '</a>';
132                    $ret .= $separator . sprintf(__('page %d'), $page);
133                }
134                break;
[3009]135
[3730]136            case 'search':
137                // Search
138                $ret = '<a id="bc-home" href="' . $core->blog->url . '">' . __('Home') . '</a>';
139                if ($page == 0) {
140                    $ret .= $separator . __('Search:') . ' ' . $GLOBALS['_search'];
141                } else {
142                    $ret .= $separator . '<a href="' . $core->blog->url . '?q=' . rawurlencode($GLOBALS['_search']) . '">' . __('Search:') . ' ' . $GLOBALS['_search'] . '</a>';
143                    $ret .= $separator . sprintf(__('page %d'), $page);
144                }
145                break;
[3009]146
[3730]147            case '404':
148                // 404
149                $ret = '<a id="bc-home" href="' . $core->blog->url . '">' . __('Home') . '</a>';
150                $ret .= $separator . __('404');
151                break;
[3009]152
[3730]153            default:
154                $ret = '<a id="bc-home" href="' . $core->blog->url . '">' . __('Home') . '</a>';
155                # --BEHAVIOR-- publicBreadcrumb
156                # Should specific breadcrumb if any, will be added after home page url
157                $special = $core->callBehavior('publicBreadcrumb', $core->url->type, $separator);
158                if ($special) {
159                    $ret .= $separator . $special;
160                }
161                break;
162        }
[3009]163
[3730]164        # Encapsulate breadcrumb in <p>…</p>
165        if (!$core->blog->settings->breadcrumb->breadcrumb_alone) {
166            $ret = '<p id="breadcrumb">' . $ret . '</p>';
167        }
[3009]168
[3730]169        return $ret;
170    }
[3009]171}
Note: See TracBrowser for help on using the repository browser.

Sites map