/** * Return the Page's label text, whether that originates from the Page's name, headline, title, etc. * * @param Page $page * @return string * */ public function ___getPageLabel(Page $page) { $value = ''; $icon = $page->getIcon(); if (strpos($this->pageLabelField, '!') === 0) { // exclamation forces this one to be used, rather than template-specific one $pageLabelField = ltrim($this->pageLabelField, '!'); } else { // if the page's template specifies a pageLabelField, use that, if pageLabelField doesn't start with "!" as override $pageLabelField = trim($page->template->pageLabelField); } // otherwise use the one specified with this instance if (!strlen($pageLabelField)) { $pageLabelField = $this->pageLabelField; } $bracket1 = strpos($pageLabelField, '{'); if ($bracket1 !== false && $bracket1 < strpos($pageLabelField, '}')) { // predefined format string if ($icon) { $pageLabelField = str_replace(array("fa-{$icon}", "icon-{$icon}", " "), array('', '', ' '), $pageLabelField); } $value = $page->getMarkup($pageLabelField); // adjust string so that it'll work on a single line, without the markup in it if (strpos($value, '</li>')) { $value = preg_replace('!</li>\\s*<li[^>]*>!', ', ', $value); } $value = trim($this->wire('sanitizer')->entities1(strip_tags($value))); } else { // CSV or space-separated field or fields // convert to array if (strpos($pageLabelField, ' ')) { $fields = explode(' ', $pageLabelField); } else { $fields = array($pageLabelField); } foreach ($fields as $field) { if (strpos($field, ".")) { list($field, $subfield) = explode(".", $field); } else { if (strpos($field, 'icon-') === 0 || strpos($field, 'fa-') === 0) { // skip over icons, which we now pull directly from page continue; } else { $subfield = ''; } } $v = $page->get($field); if ($subfield && is_object($v)) { if ($v instanceof WireArray && count($v)) { $v = $v->first(); } if ($v instanceof Page) { $v = $v->getFormatted($subfield); // @esrch PR #965 } else { if ($v instanceof Template && $subfield == 'label') { $v = $v->getLabel(); } else { if ($v instanceof Wire) { $v = $v->{$subfield}; } else { // unknown $v = (string) $v; } } } } else { if (($field == 'created' || $field == 'modified' || $field == 'published') && ctype_digit("{$v}")) { $v = date($this->wire('config')->dateFormat, (int) $v); } } if (!strlen("{$v}")) { continue; } $value .= "<span class='label_{$field}'>" . htmlspecialchars(strip_tags("{$v}"), ENT_QUOTES, "UTF-8", false) . "</span>"; } } $icon = $page->getIcon(); if ($icon) { $icon = $this->wire('sanitizer')->name($icon); $icon = "<i class='icon fa fa-fw fa-{$icon}'></i>"; } if (!strlen($value)) { $value = $page->get("title|name"); } return $icon . trim($value); }