本文整理汇总了PHP中ArticleModel::findByIdOrAlias方法的典型用法代码示例。如果您正苦于以下问题:PHP ArticleModel::findByIdOrAlias方法的具体用法?PHP ArticleModel::findByIdOrAlias怎么用?PHP ArticleModel::findByIdOrAlias使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ArticleModel
的用法示例。
在下文中一共展示了ArticleModel::findByIdOrAlias方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: compile
/**
* Generate the module
*/
protected function compile()
{
global $objPage;
$type = null;
$pageId = $objPage->id;
$pages = array($objPage->row());
$items = array();
// Get all pages up to the root page
$objPages = \PageModel::findParentsById($objPage->pid);
if ($objPages !== null) {
while ($objPages->next() && $pageId > 0 && $type != 'root') {
$type = $objPages->type;
$pageId = $objPages->pid;
$pages[] = $objPages->row();
}
}
// Get the first active regular page and display it instead of the root page
if ($type == 'root') {
$objFirstPage = \PageModel::findFirstPublishedByPid($objPages->id);
$items[] = array('isRoot' => true, 'isActive' => false, 'href' => $objFirstPage !== null ? $this->generateFrontendUrl($objFirstPage->row()) : \Environment::get('base'), 'title' => specialchars($objPages->pageTitle ?: $objPages->title, true), 'link' => $objPages->title, 'data' => $objFirstPage->row(), 'class' => '');
array_pop($pages);
}
// Build the breadcrumb menu
for ($i = count($pages) - 1; $i > 0; $i--) {
if ($pages[$i]['hide'] && !$this->showHidden || !$pages[$i]['published'] && !BE_USER_LOGGED_IN) {
continue;
}
// Get href
switch ($pages[$i]['type']) {
case 'redirect':
$href = $pages[$i]['url'];
if (strncasecmp($href, 'mailto:', 7) === 0) {
$href = \String::encodeEmail($href);
}
break;
case 'forward':
$objNext = \PageModel::findPublishedById($pages[$i]['jumpTo']);
if ($objNext !== null) {
$href = $this->generateFrontendUrl($objNext->row());
break;
}
// DO NOT ADD A break; STATEMENT
// DO NOT ADD A break; STATEMENT
default:
$href = $this->generateFrontendUrl($pages[$i]);
break;
}
$items[] = array('isRoot' => false, 'isActive' => false, 'href' => $href, 'title' => specialchars($pages[$i]['pageTitle'] ?: $pages[$i]['title'], true), 'link' => $pages[$i]['title'], 'data' => $pages[$i], 'class' => '');
}
// Active article
if (isset($_GET['articles'])) {
$items[] = array('isRoot' => false, 'isActive' => false, 'href' => $this->generateFrontendUrl($pages[0]), 'title' => specialchars($pages[0]['pageTitle'] ?: $pages[0]['title'], true), 'link' => $pages[0]['title'], 'data' => $pages[0], 'class' => '');
list($strSection, $strArticle) = explode(':', \Input::get('articles'));
if ($strArticle === null) {
$strArticle = $strSection;
}
// Get the article title
$objArticle = \ArticleModel::findByIdOrAlias($strArticle);
if ($objArticle !== null) {
$items[] = array('isRoot' => false, 'isActive' => true, 'title' => specialchars($objArticle->title, true), 'link' => $objArticle->title, 'data' => $objArticle->row(), 'class' => '');
}
} else {
$items[] = array('isRoot' => false, 'isActive' => true, 'title' => specialchars($pages[0]['pageTitle'] ?: $pages[0]['title']), 'link' => $pages[0]['title'], 'data' => $pages[0], 'class' => '');
}
// Mark the first element (see #4833)
$items[0]['class'] = 'first';
// HOOK: add custom logic
if (isset($GLOBALS['TL_HOOKS']['generateBreadcrumb']) && is_array($GLOBALS['TL_HOOKS']['generateBreadcrumb'])) {
foreach ($GLOBALS['TL_HOOKS']['generateBreadcrumb'] as $callback) {
$this->import($callback[0]);
$items = $this->{$callback}[0]->{$callback}[1]($items, $this);
}
}
$this->Template->items = $items;
}
示例2: doReplace
//.........这里部分代码省略.........
}
break;
// Link
// Link
case 'link':
case 'link_open':
case 'link_url':
case 'link_title':
case 'link_target':
case 'link_name':
$strTarget = null;
// Back link
if ($elements[1] == 'back') {
$strUrl = 'javascript:history.go(-1)';
$strTitle = $GLOBALS['TL_LANG']['MSC']['goBack'];
// No language files if the page is cached
if (!strlen($strTitle)) {
$strTitle = 'Go back';
}
$strName = $strTitle;
} elseif (strncmp($elements[1], 'http://', 7) === 0 || strncmp($elements[1], 'https://', 8) === 0) {
$strUrl = $elements[1];
$strTitle = $elements[1];
$strName = str_replace(array('http://', 'https://'), '', $elements[1]);
} else {
// User login page
if ($elements[1] == 'login') {
if (!FE_USER_LOGGED_IN) {
break;
}
$this->import('FrontendUser', 'User');
$elements[1] = $this->User->loginPage;
}
$objNextPage = \PageModel::findByIdOrAlias($elements[1]);
if ($objNextPage === null) {
break;
}
// Page type specific settings (thanks to Andreas Schempp)
switch ($objNextPage->type) {
case 'redirect':
$strUrl = $objNextPage->url;
if (strncasecmp($strUrl, 'mailto:', 7) === 0) {
$strUrl = \StringUtil::encodeEmail($strUrl);
}
break;
case 'forward':
if ($objNextPage->jumpTo) {
/** @var PageModel $objNext */
$objNext = $objNextPage->getRelated('jumpTo');
} else {
$objNext = \PageModel::findFirstPublishedRegularByPid($objNextPage->id);
}
if ($objNext instanceof PageModel) {
$strUrl = $objNext->getFrontendUrl();
break;
}
// DO NOT ADD A break; STATEMENT
// DO NOT ADD A break; STATEMENT
default:
$strUrl = $objNextPage->getFrontendUrl();
break;
}
$strName = $objNextPage->title;
$strTarget = $objNextPage->target ? ' target="_blank"' : '';
$strTitle = $objNextPage->pageTitle ?: $objNextPage->title;
}
示例3: compile
/**
* Generate the module
*/
protected function compile()
{
/** @var \PageModel $objPage */
global $objPage;
$type = null;
$pageId = $objPage->id;
$pages = array($objPage);
$items = array();
// Get all pages up to the root page
$objPages = \PageModel::findParentsById($objPage->pid);
if ($objPages !== null) {
while ($pageId > 0 && $type != 'root' && $objPages->next()) {
$type = $objPages->type;
$pageId = $objPages->pid;
$pages[] = $objPages->current();
}
}
// Get the first active regular page and display it instead of the root page
if ($type == 'root') {
$objFirstPage = \PageModel::findFirstPublishedByPid($objPages->id);
$items[] = array('isRoot' => true, 'isActive' => false, 'href' => $objFirstPage !== null ? $objFirstPage->getFrontendUrl() : \Environment::get('base'), 'title' => specialchars($objPages->pageTitle ?: $objPages->title, true), 'link' => $objPages->title, 'data' => $objFirstPage->row(), 'class' => '');
array_pop($pages);
}
/** @var \PageModel[] $pages */
for ($i = count($pages) - 1; $i > 0; $i--) {
if ($pages[$i]->hide && !$this->showHidden || !$pages[$i]->published && !BE_USER_LOGGED_IN) {
continue;
}
// Get href
switch ($pages[$i]->type) {
case 'redirect':
$href = $pages[$i]->url;
if (strncasecmp($href, 'mailto:', 7) === 0) {
$href = \StringUtil::encodeEmail($href);
}
break;
case 'forward':
if (($objNext = $pages[$i]->getRelated('jumpTo')) !== null || ($objNext = \PageModel::findFirstPublishedRegularByPid($pages[$i]->id)) !== null) {
/** @var \PageModel $objNext */
$href = $objNext->getFrontendUrl();
break;
}
// DO NOT ADD A break; STATEMENT
// DO NOT ADD A break; STATEMENT
default:
$href = $pages[$i]->getFrontendUrl();
break;
}
$items[] = array('isRoot' => false, 'isActive' => false, 'href' => $href, 'title' => specialchars($pages[$i]->pageTitle ?: $pages[$i]->title, true), 'link' => $pages[$i]->title, 'data' => $pages[$i]->row(), 'class' => '');
}
// Active article
if (isset($_GET['articles'])) {
$items[] = array('isRoot' => false, 'isActive' => false, 'href' => $pages[0]->getFrontendUrl(), 'title' => specialchars($pages[0]->pageTitle ?: $pages[0]->title, true), 'link' => $pages[0]->title, 'data' => $pages[0]->row(), 'class' => '');
list($strSection, $strArticle) = explode(':', \Input::get('articles'));
if ($strArticle === null) {
$strArticle = $strSection;
}
$objArticle = \ArticleModel::findByIdOrAlias($strArticle);
$strAlias = $objArticle->alias != '' && !\Config::get('disableAlias') ? $objArticle->alias : $objArticle->id;
if ($objArticle->inColumn != 'main') {
$strAlias = $objArticle->inColumn . ':' . $strAlias;
}
if ($objArticle !== null) {
$items[] = array('isRoot' => false, 'isActive' => true, 'href' => $pages[0]->getFrontendUrl('/articles/' . $strAlias), 'title' => specialchars($objArticle->title, true), 'link' => $objArticle->title, 'data' => $objArticle->row(), 'class' => '');
}
} else {
$items[] = array('isRoot' => false, 'isActive' => true, 'href' => $pages[0]->getFrontendUrl(), 'title' => specialchars($pages[0]->pageTitle ?: $pages[0]->title), 'link' => $pages[0]->title, 'data' => $pages[0]->row(), 'class' => '');
}
// Mark the first element (see #4833)
$items[0]['class'] = 'first';
// HOOK: add custom logic
if (isset($GLOBALS['TL_HOOKS']['generateBreadcrumb']) && is_array($GLOBALS['TL_HOOKS']['generateBreadcrumb'])) {
foreach ($GLOBALS['TL_HOOKS']['generateBreadcrumb'] as $callback) {
$this->import($callback[0]);
$items = $this->{$callback[0]}->{$callback[1]}($items, $this);
}
}
$this->Template->items = $items;
}
示例4: createEntry
private function createEntry($row)
{
$arrEntry = $row;
if (($objArticle = \ArticleModel::findByIdOrAlias($row['id'])) !== null && ($objPid = $objArticle->getRelated('pid')) !== null) {
$arrEntry['href'] = $this->generateFrontendUrl($objPid->row(), '/articles/' . (!\Config::get('disableAlias') && strlen($row['alias']) ? $row['alias'] : $row['id']));
}
if ($row['addImage'] === '1' && strlen($row['singleSRC']) > 0) {
$objFile = \FilesModel::findByUuid($row['singleSRC']);
if ($objFile !== null) {
$objTemp = new \stdClass();
$arr = ['singleSRC' => $objFile->path];
if ($this->imgSize != '') {
$size = deserialize($this->imgSize);
if ($size[0] > 0 || $size[1] > 0 || is_numeric($size[2])) {
$arr['size'] = $this->imgSize;
}
}
$this->addImageToTemplate($objTemp, $arr);
$arrEntry['imagePath'] = $objFile->path;
$arrEntry['picture'] = $objTemp->picture;
}
}
return $arrEntry;
}
示例5: replaceInsertTags
//.........这里部分代码省略.........
}
// Convert special characters (see #1890)
$arrCache[$strTag] = specialchars($arrCache[$strTag]);
}
break;
// Link
// Link
case 'link':
case 'link_open':
case 'link_url':
case 'link_title':
// Back link
if ($elements[1] == 'back') {
$strUrl = 'javascript:history.go(-1)';
$strTitle = $GLOBALS['TL_LANG']['MSC']['goBack'];
// No language files if the page is cached
if (!strlen($strTitle)) {
$strTitle = 'Go back';
}
$strName = $strTitle;
} elseif (strncmp($elements[1], 'http://', 7) === 0 || strncmp($elements[1], 'https://', 8) === 0) {
$strUrl = $elements[1];
$strTitle = $elements[1];
$strName = str_replace(array('http://', 'https://'), '', $elements[1]);
} else {
// User login page
if ($elements[1] == 'login') {
if (!FE_USER_LOGGED_IN) {
break;
}
$this->import('FrontendUser', 'User');
$elements[1] = $this->User->loginPage;
}
$objNextPage = \PageModel::findByIdOrAlias($elements[1]);
if ($objNextPage === null) {
break;
}
// Page type specific settings (thanks to Andreas Schempp)
switch ($objNextPage->type) {
case 'redirect':
$strUrl = $objNextPage->url;
if (strncasecmp($strUrl, 'mailto:', 7) === 0) {
$strUrl = \String::encodeEmail($strUrl);
}
break;
case 'forward':
if (($objTarget = $objNextPage->getRelated('jumpTo')) !== null) {
$strUrl = $this->generateFrontendUrl($objTarget->row());
break;
} elseif (($objTarget = \PageModel::findFirstPublishedRegularByPid($objNextPage->id)) !== null) {
if ($GLOBALS['TL_CONFIG']['addLanguageToUrl']) {
$objTarget = $this->getPageDetails($objTarget);
// see #3983
$strUrl = $this->generateFrontendUrl($objTarget->row(), null, $objTarget->language);
} else {
$strUrl = $this->generateFrontendUrl($objTarget->row());
}
break;
}
// DO NOT ADD A break; STATEMENT
// DO NOT ADD A break; STATEMENT
default:
if ($GLOBALS['TL_CONFIG']['addLanguageToUrl']) {
$objNextPage = $this->getPageDetails($objNextPage);
// see #3983
$strUrl = $this->generateFrontendUrl($objNextPage->row(), null, $objNextPage->language);
示例6: replaceInsertTags
//.........这里部分代码省略.........
// Convert special characters (see #1890)
$arrCache[$strTag] = specialchars($arrCache[$strTag]);
}
break;
// Link
// Link
case 'link':
case 'link_open':
case 'link_url':
case 'link_title':
$strTarget = null;
// Back link
if ($elements[1] == 'back') {
$strUrl = 'javascript:history.go(-1)';
$strTitle = $GLOBALS['TL_LANG']['MSC']['goBack'];
// No language files if the page is cached
if (!strlen($strTitle)) {
$strTitle = 'Go back';
}
$strName = $strTitle;
} elseif (strncmp($elements[1], 'http://', 7) === 0 || strncmp($elements[1], 'https://', 8) === 0) {
$strUrl = $elements[1];
$strTitle = $elements[1];
$strName = str_replace(array('http://', 'https://'), '', $elements[1]);
} else {
// User login page
if ($elements[1] == 'login') {
if (!FE_USER_LOGGED_IN) {
break;
}
$this->import('FrontendUser', 'User');
$elements[1] = $this->User->loginPage;
}
$objNextPage = \PageModel::findByIdOrAlias($elements[1]);
if ($objNextPage === null) {
break;
}
// Page type specific settings (thanks to Andreas Schempp)
switch ($objNextPage->type) {
case 'redirect':
$strUrl = $this->replaceInsertTags($objNextPage->url);
// see #6765
if (strncasecmp($strUrl, 'mailto:', 7) === 0) {
$strUrl = \String::encodeEmail($strUrl);
}
break;
case 'forward':
if ($objNextPage->jumpTo) {
$objNext = $objNextPage->getRelated('jumpTo');
} else {
$objNext = \PageModel::findFirstPublishedRegularByPid($objNextPage->id);
}
if ($objNext !== null) {
$strForceLang = null;
$objNext->loadDetails();
// Check the target page language (see #4706)
if (\Config::get('addLanguageToUrl')) {
$strForceLang = $objNext->language;
}
$strUrl = $this->generateFrontendUrl($objNext->row(), null, $strForceLang, true);
break;
}
// DO NOT ADD A break; STATEMENT
// DO NOT ADD A break; STATEMENT
default:
$strForceLang = null;
示例7: parseCustomizeFrontendTemplate
/**
* Edit the Frontend Template
*/
public function parseCustomizeFrontendTemplate($strContent, $strTemplate)
{
global $objPage;
$isFullpage = $this->isFullPageEnabled($objPage);
if ($strTemplate == "mod_article") {
$sectionHeaderID = 3;
// TODO: verwaltbar machen!!!
$sectionFooterID = 4;
$objArticle = NULL;
$articleClass = array();
$articlePattern = '/<div([A-Za-z0-9\\s\\-_=;",:\\.\\(\\)\'#\\/%]{0,})class="mod_article([A-Za-z0-9\\s\\-_]{0,})"([A-Za-z0-9\\s\\-_=;",:\\.\\(\\)\'#\\/%]{0,})>/';
preg_match_all('/id="([A-Za-z0-9\\-_]{0,})"/', $strContent, $idMatches);
if (is_array($idMatches) && count($idMatches[0]) > 0) {
$objArticle = \ArticleModel::findByIdOrAlias($idMatches[1][0]);
}
if ($isFullpage) {
if ($objArticle) {
if ($objArticle->enableSectionHeader) {
$sectionHeaderID = $objArticle->sectionHeaderModule;
$strContent = preg_replace($articlePattern, '<div$1class="mod_article$2"$3><div class="header section-header">{{insert_module::' . $sectionHeaderID . '}}</div>', $strContent);
}
if ($objArticle->enableSectionFooter) {
$sectionFooterID = $objArticle->sectionFooterModule;
$strContent = preg_replace('/<\\/div>$/', '<div class="footer section-footer">{{insert_module::' . $sectionFooterID . '}}</div></div>', $strContent);
}
if ($objArticle->enableOverlay) {
$strOverlayContent = '';
if ($objArticle->showTitleInOverlay) {
$strArticleTitle = $objArticle->title;
if (strlen($objArticle->alt_title)) {
$strArticleTitle = $objArticle->alt_title;
}
$strOverlayContent = '<div class="overlay-title"><div class="title-inner">' . $strArticleTitle . '</div></div>';
}
$strClass = "";
if ($objArticle->overlayTransparent) {
$strClass = " overlay-trans";
}
$strOverlayTags = '<div class="show-overlay"></div><div class="overlay article-overlay' . $strClass . ' shown"><div class="close"></div>' . $strOverlayContent . '</div>';
$strContent = preg_replace($articlePattern, '<div$1class="mod_article has-overlay$2"$3>', $strContent);
$strContent = preg_replace('/<\\/div>$/', $strOverlayTags . '</div>', $strContent);
}
if ($objArticle->enableFullpageNavigation) {
$navNext = "";
$navPrev = "";
if ($objPage->fullpageDirection == "horizontal") {
// TODO NAVI RIGHT UND LEFT!!
} else {
$navNext = '<div class="navigation-top" onClick="DPS.Fullpage.sectionBack(this);"></div>';
$navPrev = '<div class="navigation-bottom" onClick="DPS.Fullpage.sectionForward(this);"></div>';
}
$navigationTags = '<div class="fullpage-navigation">' . $navNext . $navPrev . '</div>';
// $strContent = preg_replace($articlePattern, '', $strContent);
$strContent = preg_replace('/<\\/div>$/', $navigationTags . '</div>', $strContent);
}
}
if ($objPage->fullpageDirection == "horizontal") {
$articleClass[] = 'slide';
} else {
$articleClass[] = 'section';
}
// $strContent = preg_replace('/<div([A-Za-z0-9\s\-_=;",:\\.\(\)\'#\/%]{0,})class="mod_article([A-Za-z0-9\s\-_]{0,})"([A-Za-z0-9\s\-_=;",:\\.\(\)\'#\/%]{0,})>/', '<div$1class="mod_article$2"$3><div class="article-inner">', $strContent);
// $strContent = $strContent . '</div>';
}
if ($objArticle) {
if ($objArticle->enableBackgroundImage && $objArticle->singleSRC != "") {
$objFile = \FilesModel::findByUuid($objArticle->singleSRC);
if ($objFile === null && !\Validator::isUuid($objArticle->singleSRC)) {
$strContent = '<p class="error">' . $GLOBALS['TL_LANG']['ERR']['version2format'] . '</p>' . $strContent;
}
if ($objFile && is_file(TL_ROOT . '/' . $objFile->path)) {
preg_match_all($articlePattern, $strContent, $arrArticleMatches);
if (is_array($arrArticleMatches[0]) && count($arrArticleMatches[0]) > 0) {
$bgPosition = str_replace('_', ' ', $objArticle->backgroundImagePosition);
if (!$bgPosition) {
$bgPosition = "center center";
}
if (preg_match('/style="/', $arrArticleMatches[0][0])) {
$styles = 'background-image:url(\'' . $objFile->path . '\');background-position:' . $bgPosition . ';';
$replStyles = '';
if (preg_match('/style="/', $arrArticleMatches[1][0])) {
$replStyles = str_replace('style="', 'style="' . $styles, $arrArticleMatches[1][0]);
} elseif (preg_match('/style="/', $arrArticleMatches[3][0])) {
$replStyles = str_replace('style="', 'style="' . $styles, $arrArticleMatches[3][0]);
}
$strContent = preg_replace($articlePattern, '<div' . $replStyles . 'class="mod_article$2"$3>', $strContent);
} else {
$strContent = preg_replace($articlePattern, '<div$1class="mod_article$2" style="background-image:url(\'' . $objFile->path . '\');background-position:' . $bgPosition . ';"$3>', $strContent);
}
$strContent = preg_replace($articlePattern, '<div$1class="mod_article has-background-image bg-fixed bg-image bg-cover$2"$3">', $strContent);
}
}
}
if ($objArticle->enableNavigation) {
$articleNavigationTag = '<div class="navigation-container">';
$objAllArticles = \ArticleModel::findBy(array("pid=?", "inColumn=?", "published=?"), array($objArticle->pid, "main", "1"), array("order" => "sorting"));
$nextArticle = false;
//.........这里部分代码省略.........