| 1 | <?php |
|---|
| 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 | */ |
|---|
| 11 | |
|---|
| 12 | if (!defined('DC_RC_PATH')) {return;} |
|---|
| 13 | |
|---|
| 14 | # Breadcrumb template functions |
|---|
| 15 | $core->tpl->addValue('Breadcrumb', ['tplBreadcrumb', 'breadcrumb']); |
|---|
| 16 | |
|---|
| 17 | class tplBreadcrumb |
|---|
| 18 | { |
|---|
| 19 | # Template function |
|---|
| 20 | public static function breadcrumb($attr) |
|---|
| 21 | { |
|---|
| 22 | $separator = isset($attr['separator']) ? $attr['separator'] : ''; |
|---|
| 23 | |
|---|
| 24 | return '<?php echo tplBreadcrumb::displayBreadcrumb(' . |
|---|
| 25 | "'" . addslashes($separator) . "'" . |
|---|
| 26 | '); ?>'; |
|---|
| 27 | } |
|---|
| 28 | |
|---|
| 29 | public static function displayBreadcrumb($separator) |
|---|
| 30 | { |
|---|
| 31 | global $core, $_ctx; |
|---|
| 32 | |
|---|
| 33 | $ret = ''; |
|---|
| 34 | |
|---|
| 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 | } |
|---|
| 40 | |
|---|
| 41 | if ($separator == '') { |
|---|
| 42 | $separator = ' › '; |
|---|
| 43 | } |
|---|
| 44 | |
|---|
| 45 | // Get current page if set |
|---|
| 46 | $page = isset($GLOBALS['_page_number']) ? (integer) $GLOBALS['_page_number'] : 0; |
|---|
| 47 | |
|---|
| 48 | switch ($core->url->type) { |
|---|
| 49 | |
|---|
| 50 | case 'default': |
|---|
| 51 | // Home (first page only) |
|---|
| 52 | $ret = '<span id="bc-home">' . __('Home') . '</span>'; |
|---|
| 53 | break; |
|---|
| 54 | |
|---|
| 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; |
|---|
| 60 | |
|---|
| 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; |
|---|
| 75 | |
|---|
| 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; |
|---|
| 91 | |
|---|
| 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; |
|---|
| 98 | |
|---|
| 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; |
|---|
| 111 | |
|---|
| 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; |
|---|
| 117 | |
|---|
| 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; |
|---|
| 123 | |
|---|
| 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; |
|---|
| 135 | |
|---|
| 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; |
|---|
| 146 | |
|---|
| 147 | case '404': |
|---|
| 148 | // 404 |
|---|
| 149 | $ret = '<a id="bc-home" href="' . $core->blog->url . '">' . __('Home') . '</a>'; |
|---|
| 150 | $ret .= $separator . __('404'); |
|---|
| 151 | break; |
|---|
| 152 | |
|---|
| 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 | } |
|---|
| 163 | |
|---|
| 164 | # Encapsulate breadcrumb in <p>…</p> |
|---|
| 165 | if (!$core->blog->settings->breadcrumb->breadcrumb_alone) { |
|---|
| 166 | $ret = '<p id="breadcrumb">' . $ret . '</p>'; |
|---|
| 167 | } |
|---|
| 168 | |
|---|
| 169 | return $ret; |
|---|
| 170 | } |
|---|
| 171 | } |
|---|