DEV: изменим вид ссылок (Parsedown)

This commit is contained in:
Evg 2022-04-02 19:28:04 +03:00
parent df41f2b752
commit 400dea16d3
7 changed files with 69 additions and 175 deletions

View file

@ -25,10 +25,13 @@ class MyParsedown extends Parsedown
$server_host = isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : null;
$href_host = isset($Element['attributes']['href']) ? parse_url($Element['attributes']['href'], PHP_URL_HOST) : null;
// Add a list of allowed urls to the config?
if ($server_host != $href_host) {
$Element['attributes']['target'] = '_blank';
$Element['attributes']['rel'] = 'noopener nofollow ugc';
if($href_host) {
// Add a list of allowed urls to the config?
if ($server_host != $href_host) {
$Element['attributes']['target'] = '_blank';
$Element['attributes']['class'] = 'external-url';
$Element['attributes']['rel'] = 'noopener nofollow ugc';
}
}
}

View file

@ -67,6 +67,7 @@ class UserAreaModel extends \Hleb\Scheme\App\Models\MainModel
item_content,
item_title_soft,
item_domain,
item_date,
item_github_url,
item_user_id,
item_votes,

View file

@ -1,166 +0,0 @@
<?php
namespace Modules\Catalog\App;
use Hleb\Constructor\Handlers\Request;
use Modules\Catalog\App\Models\{WebModel, FacetModel, UserAreaModel};
use App\Models\PostModel;
use Content, Translate, UserData, Breadcrumbs, Meta, Html;
class Catalog
{
private $user;
protected $limit = 25;
public function __construct()
{
$this->user = UserData::get();
}
// List of sites by topic (sites by "category")
// Лист сайтов по темам (сайты по "категориям")
public function index($sheet, $type)
{
$page = Request::getInt('page');
$page = $page == 0 ? 1 : $page;
$os = ['cat', 'github', 'wap'];
if (!in_array($screening = \Request::get('cat'), $os)) {
Html::pageError404([]);
}
$category = FacetModel::get(\Request::get('slug'), 'slug', $this->user['trust_level']);
Html::pageError404($category);
// We will get children
$childrens = FacetModel::getChildrens($category['facet_id'], $screening);
$items = WebModel::feedItem($page, $this->limit, $childrens, $this->user, $category['facet_id'], $sheet, $screening);
$pagesCount = WebModel::feedItemCount($childrens, $category['facet_id'], $screening);
$m = [
'og' => false,
'url' => getUrlByName('web.dir', ['cat' => 'cat', 'slug' => $category['facet_slug']]),
];
$title = sprintf(Translate::get($sheet . '.cat.title'), $category['facet_title']);
$desc = sprintf(Translate::get($sheet . '.cat.desc'), $category['facet_title'], $category['facet_description']);
$count_site = ($this->user['trust_level'] == UserData::REGISTERED_ADMIN) ? 0 : UserAreaModel::getUserSitesCount($this->user['id']);
$parent = FacetModel::breadcrumb($category['facet_id']);
return view(
'/view/default/sites',
[
'meta' => Meta::get($m, $title, $desc),
'user' => $this->user,
'data' => [
'screening' => $screening,
'sheet' => $sheet,
'type' => $type,
'count' => $pagesCount,
'pagesCount' => ceil($pagesCount / $this->limit),
'pNum' => $page,
'items' => $items,
'category' => $category,
'childrens' => $childrens,
'user_count_site' => $count_site,
'breadcrumb' => self::breadcrumb($parent, $category, $screening),
// 'low_topics' => FacetModel::getLowLevelList($category['facet_id']),
'low_matching' => FacetModel::getLowMatching($category['facet_id']),
]
]
);
}
// Bread crumbs
public static function breadcrumb($parent, $category, $screening)
{
$breadcrumb = (new Breadcrumbs())->base(getUrlByName('web'), Translate::get('websites'));
$facet_id = $parent['facet_id'] ?? 0;
if ($parent_two = FacetModel::breadcrumb($facet_id)) {
$breadcrumb->addCrumb($parent_two['facet_title'], $screening . DIRECTORY_SEPARATOR . $parent_two['facet_slug'])
->addCrumb($parent['facet_title'], $screening . DIRECTORY_SEPARATOR . $parent['facet_slug']);
} elseif ($parent) {
$breadcrumb->addCrumb($parent['facet_title'], $screening . DIRECTORY_SEPARATOR . $parent['facet_slug']);
}
$breadcrumb->addCrumb($category['facet_title'], $screening . DIRECTORY_SEPARATOR . $category['facet_slug']);
return $breadcrumb->render('breadcrumbs');
}
// Detailed site page
// Детальная страница сайта
public function website($sheet)
{
$slug = Request::get('slug');
$item = WebModel::getItemOne($slug, $this->user['id']);
Html::pageError404($item);
if ($item['item_published'] == 0) {
Html::pageError404([]);
}
if ($item['item_content_soft']) {
$item['item_content_soft'] = Content::text($item['item_content_soft'], 'text');
}
if ($this->user['id'] > 0) {
Request::getResources()->addBottomStyles('/assets/js/editor/easymde.min.css');
Request::getResources()->addBottomScript('/assets/js/editor/easymde.min.js');
}
$content_img = PATH_THUMBS . 'default.png';
if (file_exists(HLEB_PUBLIC_DIR . PATH_THUMBS . $item['item_domain'] . '.png')) {
$content_img = PATH_THUMBS . $item['item_domain'] . '.png';
}
$m = [
'og' => true,
'imgurl' => $content_img,
'url' => getUrlByName('web.website', ['slug' => $item['item_domain']]),
];
$desc = $item['item_title'] . '. ' . $item['item_content'];
if ($item['item_post_related']) {
$related_posts = PostModel::postRelated($item['item_post_related']);
}
return view(
'/view/default/website',
[
'meta' => Meta::get($m, Translate::get('website') . ': ' . $item['item_title'], $desc),
'user' => $this->user,
'data' => [
'sheet' => $sheet,
'type' => 'web',
'item' => $item,
'similar' => WebModel::itemSimilar($item['item_id'], 3),
'related_posts' => $related_posts ?? [],
]
]
);
}
public function getItemId($id)
{
return WebModel::getItemId($id);
}
// Click-throughs
// Переходы
public function cleek()
{
$id = Request::getPostInt('id');
$item = WebModel::getItemId($id);
Html::pageError404($item);
WebModel::setCleek($item['item_id']);
return true;
}
}

File diff suppressed because one or more lines are too long

View file

@ -1,5 +1,3 @@
/* PrismJS 1.25.0
https://prismjs.com/download.html#themes=prism&languages=markup+css+clike+javascript+java+kotlin+markup-templating+php+sql&plugins=line-numbers+unescaped-markup+normalize-whitespace */
code[class*=language-],pre[class*=language-]{color:#000;background:0 0;text-shadow:0 1px #fff;font-family:Consolas,Monaco,'Andale Mono','Ubuntu Mono',monospace;font-size:1em;text-align:left;white-space:pre;word-spacing:normal;word-break:normal;word-wrap:normal;line-height:1.5;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-hyphens:none;-moz-hyphens:none;-ms-hyphens:none;hyphens:none}code[class*=language-] ::-moz-selection,code[class*=language-]::-moz-selection,pre[class*=language-] ::-moz-selection,pre[class*=language-]::-moz-selection{text-shadow:none;background:#b3d4fc}code[class*=language-] ::selection,code[class*=language-]::selection,pre[class*=language-] ::selection,pre[class*=language-]::selection{text-shadow:none;background:#b3d4fc}@media print{code[class*=language-],pre[class*=language-]{text-shadow:none}}pre[class*=language-]{padding:1em;margin:.5em 0;overflow:auto}:not(pre)>code[class*=language-],pre[class*=language-]{background:#f5f2f0}:not(pre)>code[class*=language-]{padding:.1em;border-radius:.3em;white-space:normal}.token.cdata,.token.comment,.token.doctype,.token.prolog{color:#708090}.token.punctuation{color:#999}.token.namespace{opacity:.7}.token.boolean,.token.constant,.token.deleted,.token.number,.token.property,.token.symbol,.token.tag{color:#905}.token.attr-name,.token.builtin,.token.char,.token.inserted,.token.selector,.token.string{color:#690}.language-css .token.string,.style .token.string,.token.entity,.token.operator,.token.url{color:#9a6e3a;background:hsla(0,0%,100%,.5)}.token.atrule,.token.attr-value,.token.keyword{color:#07a}.token.class-name,.token.function{color:#dd4a68}.token.important,.token.regex,.token.variable{color:#e90}.token.bold,.token.important{font-weight:700}.token.italic{font-style:italic}.token.entity{cursor:help}
code[class*=language-],pre[class*=language-]{color:#000;background:0 0;text-shadow:0 1px #fff;font-family:Consolas,Monaco,'Andale Mono','Ubuntu Mono',monospace;font-size:1em;text-align:left;white-space:pre;word-spacing:normal;word-break:normal;word-wrap:normal;line-height:1.5;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-hyphens:none;-moz-hyphens:none;-ms-hyphens:none;padding:0;hyphens:none}code[class*=language-] ::-moz-selection,code[class*=language-]::-moz-selection,pre[class*=language-] ::-moz-selection,pre[class*=language-]::-moz-selection{text-shadow:none;background:#b3d4fc}code[class*=language-] ::selection,code[class*=language-]::selection,pre[class*=language-] ::selection,pre[class*=language-]::selection{text-shadow:none;background:#b3d4fc}@media print{code[class*=language-],pre[class*=language-]{text-shadow:none}}pre[class*=language-]{padding:1em;margin:.5em 0;overflow:auto}:not(pre)>code[class*=language-],pre[class*=language-]{background:#f5f2f0}:not(pre)>code[class*=language-]{padding:.1em;border-radius:.3em;white-space:normal}.token.cdata,.token.comment,.token.doctype,.token.prolog{color:#708090}.token.punctuation{color:#999}.token.namespace{opacity:.7}.token.boolean,.token.constant,.token.deleted,.token.number,.token.property,.token.symbol,.token.tag{color:#905}.token.attr-name,.token.builtin,.token.char,.token.inserted,.token.selector,.token.string{color:#690}.language-css .token.string,.style .token.string,.token.entity,.token.operator,.token.url{color:#9a6e3a;background:hsla(0,0%,100%,.5)}.token.atrule,.token.attr-value,.token.keyword{color:#07a}.token.class-name,.token.function{color:#dd4a68}.token.important,.token.regex,.token.variable{color:#e90}.token.bold,.token.important{font-weight:700}.token.italic{font-style:italic}.token.entity{cursor:help}
pre[class*=language-].line-numbers{position:relative;padding-left:3.8em;counter-reset:linenumber}pre[class*=language-].line-numbers>code{position:relative;white-space:inherit}.line-numbers .line-numbers-rows{position:absolute;pointer-events:none;top:0;font-size:100%;left:-3.8em;width:3em;letter-spacing:-1px;border-right:1px solid #999;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none}.line-numbers-rows>span{display:block;counter-increment:linenumber}.line-numbers-rows>span:before{content:counter(linenumber);color:#999;display:block;padding-right:.8em;text-align:right}
[class*=lang-] script[type='text/plain'],[class*=language-] script[type='text/plain'],script[type='text/plain'][class*=lang-],script[type='text/plain'][class*=language-]{display:block;font:100% Consolas,Monaco,monospace;white-space:pre;overflow:auto}

View file

@ -0,0 +1,51 @@
<?php // Let's add something for the test
$list = [
[
'name' => 'Name',
'link' => '/one'
], [
'name' => 'Name 2',
'link' => '/two'
], [
'name' => 'Name 3',
'link' => '/three'
],
];
?>
<ul itemscope itemtype="https://schema.org/BreadcrumbList" class="breadcrumbs">
<?php
// Найдем последний элемент
end($list);
$last_item_key = key($list);
// Сделаем ссылку
$show_last = true;
foreach ($list as $key => $item) :
if ($key != $last_item_key) :
// Покажем все элементы, кроме последнего
?>
<li itemprop="itemListElement" itemscope itemtype="https://schema.org/ListItem">
<?php if (!empty($item['link'])) : ?>
<a itemprop="item" href="<?= $item['link']; ?>"><span itemprop="name"><?= $item['name']; ?></span></a>
<?php else : ?>
<span itemprop="name">
<?= $item['name']; ?>
</span>
<?php endif; ?>
<meta itemprop="position" content="<?= $key + 1; ?>">
</li>
<?php elseif ($show_last) :
// Отобразим последний элемент
?>
<li itemprop="itemListElement" itemscope itemtype="https://schema.org/ListItem" class="active">
<span itemprop="name">
<?= $item['name']; ?>
</span>
<meta itemprop="position" content="<?= $key + 1; ?>">
</li>
<?php endif;
endforeach; ?>
</ul>

View file

@ -346,4 +346,11 @@ a:hover > img { opacity: 0.8; }
height: 48px;
width: 54px;
text-align: center;
}
}
.external-url:after {
content: "\f470";
font-family: bootstrap-icons;
color: var(--gray-600);
vertical-align: middle;
}