mirror of
https://github.com/Lastorder-DC/rhymix.git
synced 2026-01-03 08:41:39 +09:00
Allow third-party resources to customize the SEO image
Context::addMetaImage() 메소드를 사용하여 특정 페이지 공유시 SNS에 표시되는 이미지를 좀더 세부적으로 커스터마이징할 수 있습니다.
This commit is contained in:
parent
00d17ec8fc
commit
48f5190445
2 changed files with 42 additions and 1 deletions
|
|
@ -73,6 +73,7 @@ class Context
|
|||
* @var array
|
||||
*/
|
||||
public $meta_tags = array();
|
||||
public $meta_images = array();
|
||||
|
||||
/**
|
||||
* OpenGraph metadata
|
||||
|
|
@ -2631,6 +2632,42 @@ class Context
|
|||
self::$_instance->meta_tags[$name] = array('is_http_equiv' => (bool)$is_http_equiv, 'content' => $content);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get meta images
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getMetaImages()
|
||||
{
|
||||
return self::$_instance->meta_images;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add meta image
|
||||
*
|
||||
* @param string $filename
|
||||
* @param int $width
|
||||
* @param int $height
|
||||
* @return void
|
||||
*/
|
||||
public static function addMetaImage($filename, $width = 0, $height = 0)
|
||||
{
|
||||
$filename = preg_replace('/^[.\\\\\\/]+/', '', $filename);
|
||||
if (!file_exists(\RX_BASEDIR . $filename))
|
||||
{
|
||||
return;
|
||||
}
|
||||
if ($width == 0 || $height == 0)
|
||||
{
|
||||
list($width, $height) = getimagesize(\RX_BASEDIR . $filename);
|
||||
}
|
||||
self::$_instance->meta_images[] = array(
|
||||
'filepath' => $filename . '?' . date('YmdHis', filemtime(\RX_BASEDIR . $filename)),
|
||||
'width' => $width,
|
||||
'height' => $height,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get OpenGraph metadata
|
||||
*
|
||||
|
|
|
|||
|
|
@ -500,7 +500,11 @@ class HTMLDisplayHandler
|
|||
}
|
||||
|
||||
// Add image.
|
||||
if ($page_type === 'article' && $permitted && config('seo.og_extract_images'))
|
||||
if ($document_images = Context::getMetaImages())
|
||||
{
|
||||
// pass
|
||||
}
|
||||
elseif ($page_type === 'article' && $permitted && config('seo.og_extract_images'))
|
||||
{
|
||||
if (($document_images = Rhymix\Framework\Cache::get("seo:document_images:$document_srl")) === null)
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue