本文整理汇总了PHP中NewsModel::findPublishedByParentAndIdOrAlias方法的典型用法代码示例。如果您正苦于以下问题:PHP NewsModel::findPublishedByParentAndIdOrAlias方法的具体用法?PHP NewsModel::findPublishedByParentAndIdOrAlias怎么用?PHP NewsModel::findPublishedByParentAndIdOrAlias使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NewsModel
的用法示例。
在下文中一共展示了NewsModel::findPublishedByParentAndIdOrAlias方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: generate
/**
* Display a wildcard in the back end
* @return string
*/
public function generate()
{
if (TL_MODE == 'BE') {
$objTemplate = new \BackendTemplate('be_wildcard');
$objTemplate->wildcard = '### NEWS CATEGORIES MENU ###';
$objTemplate->title = $this->headline;
$objTemplate->id = $this->id;
$objTemplate->link = $this->name;
$objTemplate->href = 'contao/main.php?do=themes&table=tl_module&act=edit&id=' . $this->id;
return $objTemplate->parse();
}
$this->news_archives = $this->sortOutProtected(deserialize($this->news_archives));
// Return if there are no archives
if (!is_array($this->news_archives) || empty($this->news_archives)) {
return '';
}
$param = 'items';
// Use the auto_item parameter if enabled
if (!isset($_GET['items']) && $GLOBALS['TL_CONFIG']['useAutoItem'] && isset($_GET['auto_item'])) {
$param = 'auto_item';
}
$newsModel = \NewsModel::findPublishedByParentAndIdOrAlias(\Input::get($param), $this->news_archives);
// Get the category IDs of the active news item
if ($newsModel !== null) {
$this->activeNewsCategories = deserialize($newsModel->categories, true);
}
return parent::generate();
}
示例2: generateRelated
/**
* Generate the list in related categories mode
*
* Use the categories of the current news item. The module must be
* on the same page as news reader module.
*
* @return string
*/
protected function generateRelated()
{
// Set the item from the auto_item parameter
if (!isset($_GET['items']) && $GLOBALS['TL_CONFIG']['useAutoItem'] && isset($_GET['auto_item'])) {
\Input::setGet('items', \Input::get('auto_item'));
}
// Return if there is no item specified
if (!\Input::get('items')) {
return '';
}
$this->news_archives = $this->sortOutProtected(deserialize($this->news_archives));
// Return if there are no archives
if (!is_array($this->news_archives) || empty($this->news_archives)) {
return '';
}
$news = \NewsModel::findPublishedByParentAndIdOrAlias(\Input::get('items'), $this->news_archives);
// Return if the news item was not found
if ($news === null) {
return '';
}
$GLOBALS['NEWS_FILTER_CATEGORIES'] = false;
$GLOBALS['NEWS_FILTER_DEFAULT'] = deserialize($news->categories, true);
$GLOBALS['NEWS_FILTER_EXCLUDE'] = array($news->id);
return parent::generate();
}
示例3: compile
/**
* Generate the module
*/
protected function compile()
{
global $objPage;
$this->Template->articles = '';
$this->Template->referer = 'javascript:history.go(-1)';
$this->Template->back = $GLOBALS['TL_LANG']['MSC']['goBack'];
// Get the news item
$objArticle = \NewsModel::findPublishedByParentAndIdOrAlias(\Input::get('items'), $this->news_archives);
if ($objArticle === null) {
// Do not index or cache the page
$objPage->noSearch = 1;
$objPage->cache = 0;
// Send a 404 header
header('HTTP/1.1 404 Not Found');
$this->Template->articles = '<p class="error">' . sprintf($GLOBALS['TL_LANG']['MSC']['invalidPage'], \Input::get('items')) . '</p>';
return;
}
$arrArticle = $this->parseArticle($objArticle);
$this->Template->articles = $arrArticle;
// Overwrite the page title
if ($objArticle->headline != '') {
$objPage->pageTitle = strip_insert_tags($objArticle->headline);
}
// Overwrite the page description
if ($objArticle->teaser != '') {
$objPage->description = $this->prepareMetaDescription($objArticle->teaser);
}
// HOOK: comments extension required
if ($objArticle->noComments || !in_array('comments', $this->Config->getActiveModules())) {
$this->Template->allowComments = false;
return;
}
$objArchive = $objArticle->getRelated('pid');
$this->Template->allowComments = $objArchive->allowComments;
// Adjust the comments headline level
$intHl = min(intval(str_replace('h', '', $this->hl)), 5);
$this->Template->hlc = 'h' . ($intHl + 1);
$this->import('Comments');
$arrNotifies = array();
// Notify the system administrator
if ($objArchive->notify != 'notify_author') {
$arrNotifies[] = $GLOBALS['TL_ADMIN_EMAIL'];
}
// Notify the author
if ($objArchive->notify != 'notify_admin') {
if (($objAuthor = $objArticle->getRelated('author')) !== null && $objAuthor->email != '') {
$arrNotifies[] = $objAuthor->email;
}
}
$objConfig = new \stdClass();
$objConfig->perPage = $objArchive->perPage;
$objConfig->order = $objArchive->sortOrder;
$objConfig->template = $this->com_template;
$objConfig->requireLogin = $objArchive->requireLogin;
$objConfig->disableCaptcha = $objArchive->disableCaptcha;
$objConfig->bbcode = $objArchive->bbcode;
$objConfig->moderate = $objArchive->moderate;
$this->Comments->addCommentsToTemplate($this->Template, $objConfig, 'tl_news', $objArticle->id, $arrNotifies);
}
示例4: compile
protected function compile()
{
$objArticle = \NewsModel::findPublishedByParentAndIdOrAlias(\Input::get('items'), $this->news_archives);
$objAuthor = \UserModel::findById($objArticle->author);
if ($objAuthor->addImage) {
$objFile = \FilesModel::findByUuid($objAuthor->userSRC);
$this->addImageToTemplate($this->Template, array('singleSRC' => $objFile->path, 'alt' => 'Screenshot of Music Academy', 'size' => $this->imgSize));
}
foreach ($objAuthor->row() as $k => $v) {
$this->Template->{$k} = $v;
}
}
示例5: compile
/**
* Generate the module
*/
protected function compile()
{
/** @var \PageModel $objPage */
global $objPage;
$this->Template->articles = '';
$this->Template->referer = 'javascript:history.go(-1)';
$this->Template->back = $GLOBALS['TL_LANG']['MSC']['goBack'];
// Get the news item
$objArticle = \NewsModel::findPublishedByParentAndIdOrAlias(\Input::get('items'), $this->news_archives);
if (null === $objArticle) {
/** @var \PageError404 $objHandler */
$objHandler = new $GLOBALS['TL_PTY']['error_404']();
$objHandler->generate($objPage->id);
}
$arrArticle = $this->parseArticle($objArticle);
$this->Template->articles = $arrArticle;
// Overwrite the page title (see #2853 and #4955)
if ($objArticle->headline != '') {
$objPage->pageTitle = strip_tags(strip_insert_tags($objArticle->headline));
}
// Overwrite the page description
if ($objArticle->teaser != '') {
$objPage->description = $this->prepareMetaDescription($objArticle->teaser);
}
// HOOK: comments extension required
if ($objArticle->noComments || !in_array('comments', \ModuleLoader::getActive())) {
$this->Template->allowComments = false;
return;
}
/** @var \NewsArchiveModel $objArchive */
$objArchive = $objArticle->getRelated('pid');
$this->Template->allowComments = $objArchive->allowComments;
// Comments are not allowed
if (!$objArchive->allowComments) {
return;
}
// Adjust the comments headline level
$intHl = min(intval(str_replace('h', '', $this->hl)), 5);
$this->Template->hlc = 'h' . ($intHl + 1);
$this->import('Comments');
$arrNotifies = array();
// Notify the system administrator
if ($objArchive->notify != 'notify_author') {
$arrNotifies[] = $GLOBALS['TL_ADMIN_EMAIL'];
}
// Notify the author
if ($objArchive->notify != 'notify_admin') {
/** @var \UserModel $objAuthor */
if (($objAuthor = $objArticle->getRelated('author')) !== null && $objAuthor->email != '') {
$arrNotifies[] = $objAuthor->email;
}
}
$objConfig = new \stdClass();
$objConfig->perPage = $objArchive->perPage;
$objConfig->order = $objArchive->sortOrder;
$objConfig->template = $this->com_template;
$objConfig->requireLogin = $objArchive->requireLogin;
$objConfig->disableCaptcha = $objArchive->disableCaptcha;
$objConfig->bbcode = $objArchive->bbcode;
$objConfig->moderate = $objArchive->moderate;
$this->Comments->addCommentsToTemplate($this->Template, $objConfig, 'tl_news', $objArticle->id, $arrNotifies);
}
示例6: findRelatedNewsEntity
public static function findRelatedNewsEntity($varId, array $arrRelation, \ModuleModel $objModule = null)
{
if (!isset($arrRelation['table'])) {
return null;
}
$strModelClass = \Model::getClassFromTable($arrRelation['table']);
if (!class_exists($strModelClass)) {
return null;
}
if ($objModule === null) {
return \NewsModel::findByPk($varId);
}
return \NewsModel::findPublishedByParentAndIdOrAlias($varId, deserialize($objModule->news_archives));
}
示例7: getContentFromArticle
protected function getContentFromArticle($id, $type = "")
{
$tmpContent = "";
$thumb = "";
$sharelink = "";
$retArr = array();
$time = time();
$base = \Environment::get('base');
$table = "";
if ($type == 'news') {
$table = "tl_news";
} else {
if ($table == 'event') {
$table = "tl_calendar_events";
} else {
$table = "tl_article";
}
}
$openComment = $type == 'news' ? "open" : "closed";
$commentCount = 0;
$result = "";
$query = "SELECT * FROM `{$table}` WHERE `id` = '" . $id . "' ";
$articleRes = \Database::getInstance()->query($query)->fetchAssoc();
if ($type == "news") {
switch ($articleRes['source']) {
case 'external':
$sharelink = $articleRes['url'];
break;
case 'article':
$sharelink = $base . \Controller::replaceInsertTags("{{article_url::" . $articleRes['articleId'] . "}}");
break;
case 'internal':
$sharelink = $base . \Controller::replaceInsertTags("{{link_url::" . $articleRes['jumpTo'] . "}}");
break;
default:
$sharelink = $base . \Controller::replaceInsertTags("{{news_url::" . $articleRes['id'] . "}}");
break;
}
$newsModel = \NewsModel::findPublishedByParentAndIdOrAlias($id, array(0 => $articleRes['pid']));
$result = $this->parseNews($newsModel);
} else {
if ($type == "event") {
$objEvent = \CalendarEventsModel::findPublishedByParentAndIdOrAlias($id, array($this->settings['calendar']));
$objTemplate = new \FrontendTemplate("event_full");
$objTemplate->setData($objEvent->row());
$objTemplate->date = $date;
$objTemplate->start = $intStartTime;
$objTemplate->end = $intEndTime;
$objTemplate->class = $objEvent->cssClass != '' ? ' ' . $objEvent->cssClass : '';
$objTemplate->recurring = $recurring;
$objTemplate->until = $until;
$objTemplate->locationLabel = $GLOBALS['TL_LANG']['MSC']['location'];
$objTemplate->details = '';
$objElement = \ContentModel::findPublishedByPidAndTable($objEvent->id, 'tl_calendar_events');
if ($objElement !== null) {
while ($objElement->next()) {
$objTemplate->details .= $this->getContentElement($objElement->id);
}
}
$objTemplate->addImage = false;
if ($objEvent->addImage && $objEvent->singleSRC != '') {
$objModel = \FilesModel::findByUuid($objEvent->singleSRC);
if (is_file(TL_ROOT . '/' . $objModel->path)) {
$arrEvent = $objEvent->row();
$arrEvent['singleSRC'] = $objModel->path;
$this->addImageToTemplate($objTemplate, $arrEvent);
}
}
$objTemplate->enclosure = array();
if ($objEvent->addEnclosure) {
$this->addEnclosuresToTemplate($objTemplate, $objEvent->row());
}
$result = $objTemplate->parse();
} else {
$result = \ArticleModel::findByIdOrAliasAndPid($id, $articleRes['pid']);
}
}
$sharelink = $sharelink == "" ? $base . \Controller::replaceInsertTags("{{link_url::" . $articleRes['pid'] . "}}") : $sharelink;
if ($result != "") {
if ($type != "news" && $type != "event") {
$pageTitleRes = \Controller::getPageDetails($articleRes['pid']);
$objArticle = new \ModuleArticle($result);
$tmpContent = $objArticle->generate(true);
} else {
$tmpContent = $result;
}
$tmpContent = \Controller::replaceInsertTags($tmpContent);
$tmpContent = str_replace('src="files/', 'src="' . $base . 'files/', $tmpContent);
$tmpContent = str_replace('src="assets/', 'src="' . $base . 'assets/', $tmpContent);
$tmpContent = str_replace('href="index.php/', 'href="' . $base . 'index.php/', $tmpContent);
if ($pageTitleRes->thumb) {
$thumb = $this->getFilePath($pageTitleRes->thumb);
}
if ($openComment == "open") {
$commentCount = \CommentsModel::countPublishedBySourceAndParent("tl_news", $id);
}
$retArr['tstamp'] = time();
$retArr['img']['src'] = "";
$retArr['img']['thumb'] = $thumb;
$retArr['pid'] = $id;
//.........这里部分代码省略.........
示例8: handleNews
/**
* Render a news.
*
* @param GetNewsEvent $event The event.
*
* @param string $eventName The event name.
*
* @param EventDispatcherInterface $eventDispatcher The event dispatcher.
*
* @return void
*
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
* @SuppressWarnings(PHPMD.NPathComplexity)
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
* @SuppressWarnings(PHPMD.Superglobals)
* @SuppressWarnings(PHPMD.CamelCaseVariableName)
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function handleNews(GetNewsEvent $event, $eventName, EventDispatcherInterface $eventDispatcher)
{
if ($event->getNewsHtml()) {
return;
}
$newsArchiveCollection = \NewsArchiveModel::findAll();
$newsArchiveIds = $newsArchiveCollection ? $newsArchiveCollection->fetchEach('id') : array();
$newsModel = \NewsModel::findPublishedByParentAndIdOrAlias($event->getNewsId(), $newsArchiveIds);
if (!$newsModel) {
return;
}
$newsModel = $newsModel->current();
$newsArchiveModel = $newsModel->getRelated('pid');
$objPage = \PageModel::findWithDetails($newsArchiveModel->jumpTo);
$objTemplate = new \FrontendTemplate($event->getTemplate());
$objTemplate->setData($newsModel->row());
$objTemplate->class = $newsModel->cssClass != '' ? ' ' . $newsModel->cssClass : '';
$objTemplate->newsHeadline = $newsModel->headline;
$objTemplate->subHeadline = $newsModel->subheadline;
$objTemplate->hasSubHeadline = $newsModel->subheadline ? true : false;
$objTemplate->linkHeadline = $this->generateLink($eventDispatcher, $newsModel->headline, $newsModel);
$objTemplate->more = $this->generateLink($eventDispatcher, $GLOBALS['TL_LANG']['MSC']['more'], $newsModel, false, true);
$objTemplate->link = $this->generateNewsUrl($eventDispatcher, $newsModel);
$objTemplate->archive = $newsModel->getRelated('pid');
$objTemplate->count = 0;
$objTemplate->text = '';
// Clean the RTE output.
if ($newsModel->teaser != '') {
if ($objPage->outputFormat == 'xhtml') {
$objTemplate->teaser = \String::toXhtml($newsModel->teaser);
} else {
$objTemplate->teaser = \String::toHtml5($newsModel->teaser);
}
$objTemplate->teaser = \String::encodeEmail($objTemplate->teaser);
}
// Display the "read more" button for external/article links.
if ($newsModel->source != 'default') {
$objTemplate->text = true;
} else {
// Compile the news text.
$objElement = \ContentModel::findPublishedByPidAndTable($newsModel->id, 'tl_news');
if ($objElement !== null) {
while ($objElement->next()) {
$getContentElementEvent = new GetContentElementEvent($objElement->id);
$eventDispatcher->dispatch(ContaoEvents::CONTROLLER_GET_CONTENT_ELEMENT, $getContentElementEvent);
$objTemplate->text .= $getContentElementEvent->getContentElementHtml();
}
}
}
$arrMeta = $this->getMetaFields($newsModel);
// Add the meta information.
$objTemplate->date = $arrMeta['date'];
$objTemplate->hasMetaFields = !empty($arrMeta);
$objTemplate->numberOfComments = $arrMeta['ccount'];
$objTemplate->commentCount = $arrMeta['comments'];
$objTemplate->timestamp = $newsModel->date;
$objTemplate->author = $arrMeta['author'];
$objTemplate->datetime = date('Y-m-d\\TH:i:sP', $newsModel->date);
$objTemplate->addImage = false;
// Add an image.
if ($newsModel->addImage && $newsModel->singleSRC != '') {
$objModel = \FilesModel::findByUuid($newsModel->singleSRC);
if ($objModel === null) {
if (!\Validator::isUuid($newsModel->singleSRC)) {
$objTemplate->text = '<p class="error">' . $GLOBALS['TL_LANG']['ERR']['version2format'] . '</p>';
}
} elseif (is_file(TL_ROOT . '/' . $objModel->path)) {
// Do not override the field now that we have a model registry (see #6303).
$arrArticle = $newsModel->row();
// Override the default image size.
// This is always false!
if ($this->imgSize != '') {
$size = deserialize($this->imgSize);
if ($size[0] > 0 || $size[1] > 0) {
$arrArticle['size'] = $this->imgSize;
}
}
$arrArticle['singleSRC'] = $objModel->path;
$addImageToTemplateEvent = new AddImageToTemplateEvent($arrArticle, $objTemplate);
$eventDispatcher->dispatch(ContaoEvents::CONTROLLER_ADD_IMAGE_TO_TEMPLATE, $addImageToTemplateEvent);
}
}
//.........这里部分代码省略.........