本文整理汇总了PHP中EasyBlogHelper::getFirstImage方法的典型用法代码示例。如果您正苦于以下问题:PHP EasyBlogHelper::getFirstImage方法的具体用法?PHP EasyBlogHelper::getFirstImage怎么用?PHP EasyBlogHelper::getFirstImage使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类EasyBlogHelper
的用法示例。
在下文中一共展示了EasyBlogHelper::getFirstImage方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: googleone
public function googleone()
{
$config = EasyBlogHelper::getConfig();
$document = JFactory::getDocument();
$frontpage = $this->isFrontend;
$pos = $this->position;
$googleone = !$frontpage && $config->get('main_googleone') || $frontpage && $config->get('main_googleone_frontpage', $config->get('social_show_frontpage')) && $config->get('main_googleone');
$socialFrontEnd = $config->get('main_googleone_frontpage', 0);
$html = '';
if ($googleone) {
$size = $config->get('main_googleone_layout');
$dataURL = $this->_getDataURL();
$dataTitle = $this->_getDataTitle();
$buttonSize = 'social-button-';
switch ($size) {
case 'tall':
$buttonSize .= 'large';
break;
case 'medium':
default:
$buttonSize .= 'small';
break;
}
// Add snippet info into headers
$document = JFactory::getDocument();
$meta = EasyBlogHelper::getTable('Meta', 'Table');
$meta->loadByType(META_TYPE_POST, $this->blog->id);
$document->addCustomTag('<meta itemprop="name" content="' . $this->blog->title . '" />');
if (!empty($meta->description)) {
$meta->description = EasyBlogStringHelper::escape($meta->description);
// Remove JFBConnect codes.
$pattern = '/\\{JFBCLike(.*)\\}/i';
$meta->description = preg_replace($pattern, '', $meta->description);
$document->addCustomTag('<meta itemprop="description" content="' . $meta->description . '" />');
} else {
$maxContentLen = 350;
$text = strip_tags($this->blog->intro . $this->blog->content);
$text = JString::strlen($text) > $maxContentLen ? JString::substr($text, 0, $maxContentLen) . '...' : $text;
// Remove JFBConnect codes.
$pattern = '/\\{JFBCLike(.*)\\}/i';
$text = preg_replace($pattern, '', $text);
$text = EasyBlogStringHelper::escape($text);
$document->addCustomTag('<meta itemprop="description" content="' . $text . '" />');
}
$image = EasyBlogHelper::getFirstImage($this->blog->intro . $this->blog->content);
if ($image !== false) {
$document->addCustomTag('<meta itemprop="image" content="' . $image . '" />');
}
$placeholder = 'sb-' . rand();
$html .= '<div class="social-button ' . $buttonSize . ' google-plusone"><span id="' . $placeholder . '"></span></div>';
// TODO: Verify $socialFrontEnd, what is it used for.
// if( ! $socialFrontEnd )
// $googleHTML .= '<script type="text/javascript" src="https://apis.google.com/js/plusone.js"></script>';
// $googleHTML .= '<g:plusone size="' . $size . '" href="' . $dataURL . '"></g:plusone>';
if ($this->isBottom) {
$html = '<div class="socialbutton-vertical align' . $pos . '">' . $html . '</div>';
}
$html .= EasyBlogHelper::addScriptDeclarationBookmarklet('$("#' . $placeholder . '").bookmarklet("googlePlusOne", {
href: "' . $dataURL . '",
size: "' . $size . '"
});');
}
return $html;
}
示例2: getHTML
public function getHTML($frontpage, $position, $blog, $teamIdLink)
{
$config = EasyBlogHelper::getConfig();
$enabled = !$frontpage && $config->get('main_pinit_button') || $frontpage && $config->get('main_pinit_button_frontpage', $config->get('social_show_frontpage')) && $config->get('main_pinit_button');
if (!$enabled) {
return false;
}
$style = $config->get('main_pinit_button_style');
$url = EasyBlogRouter::getRoutedURL('index.php?option=com_easyblog&view=entry&id=' . $blog->id, false, true);
// @task: Test for blog image first.
$image = '';
if ($blog->getImage()) {
$image = $blog->getImage()->getSource('frontpage');
}
if (empty($image)) {
// Fetch the first image of the blog post
$image = EasyBlogHelper::getFirstImage($blog->intro . $blog->content);
// @rule: Test if there's any ->images
if (isset($blog->images) && $blog->images) {
$image = $blog->images[0];
}
}
// @rule: If post doesn't contain any images, do not show button.
if (!$image) {
return false;
}
$buttonSize = 'social-button-';
switch ($style) {
case 'vertical':
$buttonSize .= 'large';
break;
case 'horizontal':
$buttonSize .= 'small';
break;
default:
$buttonSize .= 'plain';
break;
}
// @TODO: Configurable maximum length
$contentLength = 350;
$text = $blog->intro . $blog->content;
$text = nl2br($text);
$text = strip_tags($text);
$text = trim(preg_replace('/\\s+/', ' ', $text));
$text = JString::strlen($text) > $contentLength ? JString::substr($text, 0, $contentLength) . '...' : $text;
$theme = new CodeThemes();
$title = $blog->title;
// Urlencode all the necessary properties.
$url = urlencode($url);
$text = urlencode($text);
$image = urlencode($image);
$placeholder = 'sb-' . rand();
$output = '<div class="social-button ' . $buttonSize . ' pinterest"><span id="' . $placeholder . '"></span></div>';
$output .= EasyBlogHelper::addScriptDeclarationBookmarklet('$("#' . $placeholder . '").bookmarklet("pinterest", {
url: "' . $url . '",
style: "' . $style . '",
media: "' . $image . '",
title: "' . $title . '",
description: "' . $text . '"
});');
return $output;
}