本文整理汇总了PHP中NewsModel::getRelated方法的典型用法代码示例。如果您正苦于以下问题:PHP NewsModel::getRelated方法的具体用法?PHP NewsModel::getRelated怎么用?PHP NewsModel::getRelated使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NewsModel
的用法示例。
在下文中一共展示了NewsModel::getRelated方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getLink
/**
* Return the link of a news article
*
* @param \NewsModel $objItem
* @param string $strUrl
* @param string $strBase
*
* @return string
*/
protected function getLink($objItem, $strUrl, $strBase = '')
{
switch ($objItem->source) {
// Link to an external page
case 'external':
return $objItem->url;
break;
// Link to an internal page
// Link to an internal page
case 'internal':
if (($objTarget = $objItem->getRelated('jumpTo')) !== null) {
/** @var \PageModel $objTarget */
return $strBase . $objTarget->getFrontendUrl();
}
break;
// Link to an article
// Link to an article
case 'article':
if (($objArticle = \ArticleModel::findByPk($objItem->articleId, array('eager' => true))) !== null && ($objPid = $objArticle->getRelated('pid')) !== null) {
/** @var \PageModel $objPid */
return $strBase . ampersand($objPid->getFrontendUrl('/articles/' . (!\Config::get('disableAlias') && $objArticle->alias != '' ? $objArticle->alias : $objArticle->id)));
}
break;
}
// Link to the default page
return $strBase . sprintf($strUrl, $objItem->alias != '' && !\Config::get('disableAlias') ? $objItem->alias : $objItem->id);
}
示例2: generateNewsUrl
/**
* Generate a URL and return it as string
*
* @param \NewsModel $objItem
* @param boolean $blnAddArchive
*
* @return string
*/
protected function generateNewsUrl($objItem, $blnAddArchive = false)
{
$strCacheKey = 'id_' . $objItem->id;
// Load the URL from cache
if (isset(self::$arrUrlCache[$strCacheKey])) {
return self::$arrUrlCache[$strCacheKey];
}
// Initialize the cache
self::$arrUrlCache[$strCacheKey] = null;
switch ($objItem->source) {
// Link to an external page
case 'external':
if (substr($objItem->url, 0, 7) == 'mailto:') {
self::$arrUrlCache[$strCacheKey] = \StringUtil::encodeEmail($objItem->url);
} else {
self::$arrUrlCache[$strCacheKey] = ampersand($objItem->url);
}
break;
// Link to an internal page
// Link to an internal page
case 'internal':
if (($objTarget = $objItem->getRelated('jumpTo')) !== null) {
self::$arrUrlCache[$strCacheKey] = ampersand($this->generateFrontendUrl($objTarget->row()));
}
break;
// Link to an article
// Link to an article
case 'article':
if (($objArticle = \ArticleModel::findByPk($objItem->articleId, array('eager' => true))) !== null && ($objPid = $objArticle->getRelated('pid')) !== null) {
self::$arrUrlCache[$strCacheKey] = ampersand($this->generateFrontendUrl($objPid->row(), '/articles/' . (!\Config::get('disableAlias') && $objArticle->alias != '' ? $objArticle->alias : $objArticle->id)));
}
break;
}
// Link to the default page
if (self::$arrUrlCache[$strCacheKey] === null) {
$objPage = \PageModel::findByPk($objItem->getRelated('pid')->jumpTo);
if ($objPage === null) {
self::$arrUrlCache[$strCacheKey] = ampersand(\Environment::get('request'), true);
} else {
self::$arrUrlCache[$strCacheKey] = ampersand($this->generateFrontendUrl($objPage->row(), (\Config::get('useAutoItem') && !\Config::get('disableAlias') ? '/' : '/items/') . (!\Config::get('disableAlias') && $objItem->alias != '' ? $objItem->alias : $objItem->id)));
}
// Add the current archive parameter (news archive)
if ($blnAddArchive && \Input::get('month') != '') {
self::$arrUrlCache[$strCacheKey] .= (\Config::get('disableAlias') ? '&' : '?') . 'month=' . \Input::get('month');
}
}
return self::$arrUrlCache[$strCacheKey];
}
示例3: getMetaFields
/**
* Return the meta fields of a news article as array
*
* @param NewsModel $objArticle
*
* @return array
*/
protected function getMetaFields($objArticle)
{
$meta = \StringUtil::deserialize($this->news_metaFields);
if (!is_array($meta)) {
return array();
}
/** @var PageModel $objPage */
global $objPage;
$return = array();
foreach ($meta as $field) {
switch ($field) {
case 'date':
$return['date'] = \Date::parse($objPage->datimFormat, $objArticle->date);
break;
case 'author':
/** @var UserModel $objAuthor */
if (($objAuthor = $objArticle->getRelated('author')) instanceof UserModel) {
$return['author'] = $GLOBALS['TL_LANG']['MSC']['by'] . ' ' . $objAuthor->name;
}
break;
case 'comments':
if ($objArticle->noComments || !in_array('comments', \ModuleLoader::getActive()) || $objArticle->source != 'default') {
break;
}
$intTotal = \CommentsModel::countPublishedBySourceAndParent('tl_news', $objArticle->id);
$return['ccount'] = $intTotal;
$return['comments'] = sprintf($GLOBALS['TL_LANG']['MSC']['commentCount'], $intTotal);
break;
}
}
return $return;
}
示例4: getLink
/**
* Return the link of a news article
*
* @param NewsModel $objItem
* @param string $strUrl
* @param string $strBase
*
* @return string
*/
protected function getLink($objItem, $strUrl, $strBase = '')
{
switch ($objItem->source) {
// Link to an external page
case 'external':
return $objItem->url;
break;
// Link to an internal page
// Link to an internal page
case 'internal':
if (($objTarget = $objItem->getRelated('jumpTo')) !== null) {
return $strBase . $this->generateFrontendUrl($objTarget->row());
}
break;
// Link to an article
// Link to an article
case 'article':
if (($objArticle = \ArticleModel::findByPk($objItem->articleId, array('eager' => true))) !== null && ($objPid = $objArticle->getRelated('pid')) !== null) {
return $strBase . ampersand($this->generateFrontendUrl($objPid->row(), '/articles/' . ($objArticle->alias ?: $objArticle->id)));
}
break;
}
// Link to the default page
return $strBase . sprintf($strUrl, $objItem->alias ?: $objItem->id);
}
示例5: getLink
/**
* Return the link of a news article
*
* @param NewsModel $objItem
* @param string $strUrl
* @param string $strBase
*
* @return string
*/
protected function getLink($objItem, $strUrl, $strBase = '')
{
switch ($objItem->source) {
// Link to an external page
case 'external':
return $objItem->url;
break;
// Link to an internal page
// Link to an internal page
case 'internal':
if (($objTarget = $objItem->getRelated('jumpTo')) instanceof PageModel) {
/** @var PageModel $objTarget */
return $objTarget->getAbsoluteUrl();
}
break;
// Link to an article
// Link to an article
case 'article':
if (($objArticle = \ArticleModel::findByPk($objItem->articleId, array('eager' => true))) !== null && ($objPid = $objArticle->getRelated('pid')) instanceof PageModel) {
/** @var PageModel $objPid */
return ampersand($objPid->getAbsoluteUrl('/articles/' . ($objArticle->alias ?: $objArticle->id)));
}
break;
}
// Backwards compatibility (see #8329)
if ($strBase != '' && !preg_match('#^https?://#', $strUrl)) {
$strUrl = $strBase . $strUrl;
}
// Link to the default page
return sprintf($strUrl, $objItem->alias ?: $objItem->id);
}
示例6: generateNewsUrl
/**
* Generate a URL and return it as string.
*
* @param EventDispatcherInterface $eventDispatcher The event dispatcher.
*
* @param \NewsModel $objItem The news model.
*
* @param boolean $blnAddArchive Add the current archive parameter (news archive) (default: false).
*
* @return string
*
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
* @SuppressWarnings(PHPMD.NPathComplexity)
* @SuppressWarnings(PHPMD.Superglobals)
* @SuppressWarnings(PHPMD.CamelCaseVariableName)
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
protected function generateNewsUrl(EventDispatcherInterface $eventDispatcher, \NewsModel $objItem, $blnAddArchive = false)
{
$url = null;
switch ($objItem->source) {
// Link to an external page.
case 'external':
if (substr($objItem->url, 0, 7) == 'mailto:') {
$url = \String::encodeEmail($objItem->url);
} else {
$url = ampersand($objItem->url);
}
break;
// Link to an internal page.
// Link to an internal page.
case 'internal':
if (($objTarget = $objItem->getRelated('jumpTo')) !== null) {
$generateFrontendUrlEvent = new GenerateFrontendUrlEvent($objTarget->row());
$eventDispatcher->dispatch(ContaoEvents::CONTROLLER_GENERATE_FRONTEND_URL, $generateFrontendUrlEvent);
$url = $generateFrontendUrlEvent->getUrl();
}
break;
// Link to an article.
// Link to an article.
case 'article':
if (($objArticle = \ArticleModel::findByPk($objItem->articleId, array('eager' => true))) !== null && ($objPid = $objArticle->getRelated('pid')) !== null) {
$generateFrontendUrlEvent = new GenerateFrontendUrlEvent($objPid->row(), '/articles/' . (!$GLOBALS['TL_CONFIG']['disableAlias'] && $objArticle->alias != '' ? $objArticle->alias : $objArticle->id));
$eventDispatcher->dispatch(ContaoEvents::CONTROLLER_GENERATE_FRONTEND_URL, $generateFrontendUrlEvent);
$url = $generateFrontendUrlEvent->getUrl();
}
break;
default:
}
// Link to the default page.
if ($url === null) {
$objPage = \PageModel::findByPk($objItem->getRelated('pid')->jumpTo);
if ($objPage === null) {
$url = ampersand(\Environment::get('request'), true);
} else {
$generateFrontendUrlEvent = new GenerateFrontendUrlEvent($objPage->row(), ($GLOBALS['TL_CONFIG']['useAutoItem'] && !$GLOBALS['TL_CONFIG']['disableAlias'] ? '/' : '/items/') . (!$GLOBALS['TL_CONFIG']['disableAlias'] && $objItem->alias != '' ? $objItem->alias : $objItem->id));
$eventDispatcher->dispatch(ContaoEvents::CONTROLLER_GENERATE_FRONTEND_URL, $generateFrontendUrlEvent);
$url = $generateFrontendUrlEvent->getUrl();
}
// Add the current archive parameter (news archive).
if ($blnAddArchive && \Input::get('month') != '') {
$url .= ($GLOBALS['TL_CONFIG']['disableAlias'] ? '&' : '?') . 'month=' . \Input::get('month');
}
}
return $url;
}