mirror of
https://github.com/Lastorder-DC/rhymix.git
synced 2026-01-05 09:41:40 +09:00
Add getTags() and getHashtags() to document item
This commit is contained in:
parent
e4fb4e1dbf
commit
fb73a0d410
2 changed files with 19 additions and 7 deletions
|
|
@ -526,19 +526,19 @@ class HTMLDisplayHandler
|
|||
// Add tags and hashtags for articles.
|
||||
if ($page_type === 'article')
|
||||
{
|
||||
$tags = array_unique(array_map('utf8_trim', explode(',', $oDocument->get('tags'))));
|
||||
$tags = $oDocument->getTags();
|
||||
foreach ($tags as $tag)
|
||||
{
|
||||
if ($tag !== '')
|
||||
{
|
||||
Context::addOpenGraphData('og:article:tag', escape($tag, false));
|
||||
Context::addOpenGraphData('og:article:tag', $tag, false);
|
||||
}
|
||||
}
|
||||
|
||||
if (config('seo.og_extract_hashtags'))
|
||||
{
|
||||
preg_match_all('/#([\pL\pN_]+)/u', strip_tags($oDocument->get('content')), $hashtags);
|
||||
foreach ($hashtags[1] as $hashtag)
|
||||
$hashtags = $oDocument->getHashtags();
|
||||
foreach ($hashtags as $hashtag)
|
||||
{
|
||||
if (!in_array($hashtag, $tags))
|
||||
{
|
||||
|
|
|
|||
|
|
@ -148,9 +148,7 @@ class documentItem extends BaseObject
|
|||
// Tags
|
||||
if($this->get('tags'))
|
||||
{
|
||||
$tag_list = explode(',', $this->get('tags'));
|
||||
$tag_list = array_map('utf8_trim', $tag_list);
|
||||
$this->add('tag_list', $tag_list);
|
||||
$this->add('tag_list', $this->getTags());
|
||||
}
|
||||
|
||||
if($load_extra_vars)
|
||||
|
|
@ -774,6 +772,20 @@ class documentItem extends BaseObject
|
|||
}
|
||||
}
|
||||
|
||||
public function getTags()
|
||||
{
|
||||
$tag_list = array_map(function($str) { return escape(utf8_trim($str), false); }, explode(',', $this->get('tags')));
|
||||
$tag_list = array_filter($tag_list, function($str) { return $str !== ''; });
|
||||
return array_unique($tag_list);
|
||||
}
|
||||
|
||||
public function getHashtags()
|
||||
{
|
||||
preg_match_all('/(?<!&)#([\pL\pN_]+)/u', strip_tags($this->get('content')), $hashtags);
|
||||
$hashtags[1] = array_map(function($str) { return escape($str, false); }, $hashtags[1]);
|
||||
return array_unique($hashtags[1]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update readed count
|
||||
* @return void
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue