Skip to content
This repository has been archived by the owner on Nov 6, 2019. It is now read-only.

Commit

Permalink
Merge branch 'hotfix/4.4.3'
Browse files Browse the repository at this point in the history
  • Loading branch information
leofeyer committed Aug 16, 2017
2 parents dcc9f33 + 925eeee commit f4e0559
Show file tree
Hide file tree
Showing 10 changed files with 225 additions and 524 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"require": {
"php": "^5.6|^7.0",
"symfony/framework-bundle": "^3.3",
"contao/core-bundle": "^4.4"
"contao/core-bundle": "^4.4.2"
},
"require-dev": {
"contao/manager-plugin": "^2.0",
Expand Down
1 change: 0 additions & 1 deletion phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/5.0/phpunit.xsd"
backupGlobals="false"
colors="true"
processIsolation="false"
bootstrap="tests/bootstrap.php"
>
<php>
Expand Down
2 changes: 1 addition & 1 deletion src/EventListener/GeneratePageListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public function onGeneratePage(PageModel $objPage, LayoutModel $objLayout)
/** @var NewsFeedModel $adapter */
$adapter = $this->framework->getAdapter(NewsFeedModel::class);

if (!(($feeds = $adapter->findByIds($newsfeeds)) instanceof Collection)) {
if (!($feeds = $adapter->findByIds($newsfeeds)) instanceof Collection) {
return;
}

Expand Down
98 changes: 7 additions & 91 deletions src/EventListener/InsertTagsListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,10 @@

namespace Contao\NewsBundle\EventListener;

use Contao\ArticleModel;
use Contao\Config;
use Contao\CoreBundle\Framework\ContaoFrameworkInterface;
use Contao\NewsArchiveModel;
use Contao\News;
use Contao\NewsFeedModel;
use Contao\NewsModel;
use Contao\PageModel;
use Contao\StringUtil;

/**
Expand Down Expand Up @@ -118,90 +115,6 @@ private function replaceNewsInsertTags($insertTag, $idOrAlias)
return $this->generateReplacement($news, $insertTag);
}

/**
* Generates a news URL.
*
* @param NewsModel $news
*
* @return string
*/
private function generateNewsUrl(NewsModel $news)
{
if ('external' === $news->source) {
return $news->url;
}

if ('internal' === $news->source) {
return $this->generatePageUrl($news);
}

if ('article' === $news->source) {
return $this->generateArticleUrl($news);
}

return $this->generateNewsReaderUrl($news);
}

/**
* Generates the URL to a page.
*
* @param NewsModel $news
*
* @return string
*/
private function generatePageUrl(NewsModel $news)
{
/** @var PageModel $targetPage */
if (!(($targetPage = $news->getRelated('jumpTo')) instanceof PageModel)) {
return '';
}

return $targetPage->getFrontendUrl();
}

/**
* Generates the URL to an article.
*
* @param NewsModel $news
*
* @return string
*/
private function generateArticleUrl(NewsModel $news)
{
/** @var PageModel $targetPage */
if (!(($article = $news->getRelated('articleId')) instanceof ArticleModel)
|| !(($targetPage = $article->getRelated('pid')) instanceof PageModel)
) {
return '';
}

return $targetPage->getFrontendUrl('/articles/'.($article->alias ?: $article->id));
}

/**
* Generates URL to a news item.
*
* @param NewsModel $news
*
* @return string
*/
private function generateNewsReaderUrl(NewsModel $news)
{
/** @var PageModel $targetPage */
if (!(($archive = $news->getRelated('pid')) instanceof NewsArchiveModel)
|| !(($targetPage = $archive->getRelated('jumpTo')) instanceof PageModel)
) {
return '';
}

/** @var Config $config */
$config = $this->framework->getAdapter(Config::class);

return $targetPage->getFrontendUrl(
($config->get('useAutoItem') ? '/' : '/items/').($news->alias ?: $news->id)
);
}

/**
* Generates the replacement string.
*
Expand All @@ -212,24 +125,27 @@ private function generateNewsReaderUrl(NewsModel $news)
*/
private function generateReplacement(NewsModel $news, $insertTag)
{
/** @var News $adapter */
$adapter = $this->framework->getAdapter(News::class);

switch ($insertTag) {
case 'news':
return sprintf(
'<a href="%s" title="%s">%s</a>',
$this->generateNewsUrl($news),
$adapter->generateNewsUrl($news),
StringUtil::specialchars($news->headline),
$news->headline
);

case 'news_open':
return sprintf(
'<a href="%s" title="%s">',
$this->generateNewsUrl($news),
$adapter->generateNewsUrl($news),
StringUtil::specialchars($news->headline)
);

case 'news_url':
return $this->generateNewsUrl($news);
return $adapter->generateNewsUrl($news);

case 'news_title':
return StringUtil::specialchars($news->headline);
Expand Down
4 changes: 2 additions & 2 deletions src/Picker/NewsPickerProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,11 @@ private function getNewsArchiveId($id)
/** @var NewsModel $newsAdapter */
$newsAdapter = $this->framework->getAdapter(NewsModel::class);

if (!(($newsModel = $newsAdapter->findById($id)) instanceof NewsModel)) {
if (!($newsModel = $newsAdapter->findById($id)) instanceof NewsModel) {
return null;
}

if (!(($newsArchive = $newsModel->getRelated('pid')) instanceof NewsArchiveModel)) {
if (!($newsArchive = $newsModel->getRelated('pid')) instanceof NewsArchiveModel) {
return null;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Resources/contao/classes/News.php
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ public static function generateNewsUrl($objItem, $blnAddArchive=false)
{
$objPage = \PageModel::findByPk($objItem->getRelated('pid')->jumpTo);

if (!($objPage instanceof PageModel))
if (!$objPage instanceof PageModel)
{
self::$arrUrlCache[$strCacheKey] = ampersand(\Environment::get('request'), true);
}
Expand Down
94 changes: 47 additions & 47 deletions src/Resources/contao/models/NewsArchiveModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,55 +29,55 @@
* @property boolean $requireLogin
* @property boolean $disableCaptcha
*
* @method static NewsArchiveModel|null findById($id, $opt=array())
* @method static NewsArchiveModel|null findByPk($id, $opt=array())
* @method static NewsArchiveModel|null findByIdOrAlias($val, $opt=array())
* @method static NewsArchiveModel|null findOneBy($col, $val, $opt=array())
* @method static NewsArchiveModel|null findOneByTstamp($val, $opt=array())
* @method static NewsArchiveModel|null findOneByTitle($val, $opt=array())
* @method static NewsArchiveModel|null findOneByJumpTo($val, $opt=array())
* @method static NewsArchiveModel|null findOneByProtected($val, $opt=array())
* @method static NewsArchiveModel|null findOneByGroups($val, $opt=array())
* @method static NewsArchiveModel|null findOneByAllowComments($val, $opt=array())
* @method static NewsArchiveModel|null findOneByNotify($val, $opt=array())
* @method static NewsArchiveModel|null findOneBySortOrder($val, $opt=array())
* @method static NewsArchiveModel|null findOneByPerPage($val, $opt=array())
* @method static NewsArchiveModel|null findOneByModerate($val, $opt=array())
* @method static NewsArchiveModel|null findOneByBbcode($val, $opt=array())
* @method static NewsArchiveModel|null findOneByRequireLogin($val, $opt=array())
* @method static NewsArchiveModel|null findOneByDisableCaptcha($val, $opt=array())
* @method static NewsArchiveModel|null findById($id, array $opt=array())
* @method static NewsArchiveModel|null findByPk($id, array $opt=array())
* @method static NewsArchiveModel|null findByIdOrAlias($val, array $opt=array())
* @method static NewsArchiveModel|null findOneBy($col, $val, array $opt=array())
* @method static NewsArchiveModel|null findOneByTstamp($val, array $opt=array())
* @method static NewsArchiveModel|null findOneByTitle($val, array $opt=array())
* @method static NewsArchiveModel|null findOneByJumpTo($val, array $opt=array())
* @method static NewsArchiveModel|null findOneByProtected($val, array $opt=array())
* @method static NewsArchiveModel|null findOneByGroups($val, array $opt=array())
* @method static NewsArchiveModel|null findOneByAllowComments($val, array $opt=array())
* @method static NewsArchiveModel|null findOneByNotify($val, array $opt=array())
* @method static NewsArchiveModel|null findOneBySortOrder($val, array $opt=array())
* @method static NewsArchiveModel|null findOneByPerPage($val, array $opt=array())
* @method static NewsArchiveModel|null findOneByModerate($val, array $opt=array())
* @method static NewsArchiveModel|null findOneByBbcode($val, array $opt=array())
* @method static NewsArchiveModel|null findOneByRequireLogin($val, array $opt=array())
* @method static NewsArchiveModel|null findOneByDisableCaptcha($val, array $opt=array())
*
* @method static Model\Collection|NewsArchiveModel[]|NewsArchiveModel|null findByTstamp($val, $opt=array())
* @method static Model\Collection|NewsArchiveModel[]|NewsArchiveModel|null findByTitle($val, $opt=array())
* @method static Model\Collection|NewsArchiveModel[]|NewsArchiveModel|null findByJumpTo($val, $opt=array())
* @method static Model\Collection|NewsArchiveModel[]|NewsArchiveModel|null findByProtected($val, $opt=array())
* @method static Model\Collection|NewsArchiveModel[]|NewsArchiveModel|null findByGroups($val, $opt=array())
* @method static Model\Collection|NewsArchiveModel[]|NewsArchiveModel|null findByAllowComments($val, $opt=array())
* @method static Model\Collection|NewsArchiveModel[]|NewsArchiveModel|null findByNotify($val, $opt=array())
* @method static Model\Collection|NewsArchiveModel[]|NewsArchiveModel|null findBySortOrder($val, $opt=array())
* @method static Model\Collection|NewsArchiveModel[]|NewsArchiveModel|null findByPerPage($val, $opt=array())
* @method static Model\Collection|NewsArchiveModel[]|NewsArchiveModel|null findByModerate($val, $opt=array())
* @method static Model\Collection|NewsArchiveModel[]|NewsArchiveModel|null findByBbcode($val, $opt=array())
* @method static Model\Collection|NewsArchiveModel[]|NewsArchiveModel|null findByRequireLogin($val, $opt=array())
* @method static Model\Collection|NewsArchiveModel[]|NewsArchiveModel|null findByDisableCaptcha($val, $opt=array())
* @method static Model\Collection|NewsArchiveModel[]|NewsArchiveModel|null findMultipleByIds($val, $opt=array())
* @method static Model\Collection|NewsArchiveModel[]|NewsArchiveModel|null findBy($col, $val, $opt=array())
* @method static Model\Collection|NewsArchiveModel[]|NewsArchiveModel|null findAll($opt=array())
* @method static Model\Collection|NewsArchiveModel[]|NewsArchiveModel|null findByTstamp($val, array $opt=array())
* @method static Model\Collection|NewsArchiveModel[]|NewsArchiveModel|null findByTitle($val, array $opt=array())
* @method static Model\Collection|NewsArchiveModel[]|NewsArchiveModel|null findByJumpTo($val, array $opt=array())
* @method static Model\Collection|NewsArchiveModel[]|NewsArchiveModel|null findByProtected($val, array $opt=array())
* @method static Model\Collection|NewsArchiveModel[]|NewsArchiveModel|null findByGroups($val, array $opt=array())
* @method static Model\Collection|NewsArchiveModel[]|NewsArchiveModel|null findByAllowComments($val, array $opt=array())
* @method static Model\Collection|NewsArchiveModel[]|NewsArchiveModel|null findByNotify($val, array $opt=array())
* @method static Model\Collection|NewsArchiveModel[]|NewsArchiveModel|null findBySortOrder($val, array $opt=array())
* @method static Model\Collection|NewsArchiveModel[]|NewsArchiveModel|null findByPerPage($val, array $opt=array())
* @method static Model\Collection|NewsArchiveModel[]|NewsArchiveModel|null findByModerate($val, array $opt=array())
* @method static Model\Collection|NewsArchiveModel[]|NewsArchiveModel|null findByBbcode($val, array $opt=array())
* @method static Model\Collection|NewsArchiveModel[]|NewsArchiveModel|null findByRequireLogin($val, array $opt=array())
* @method static Model\Collection|NewsArchiveModel[]|NewsArchiveModel|null findByDisableCaptcha($val, array $opt=array())
* @method static Model\Collection|NewsArchiveModel[]|NewsArchiveModel|null findMultipleByIds($val, array $opt=array())
* @method static Model\Collection|NewsArchiveModel[]|NewsArchiveModel|null findBy($col, $val, array $opt=array())
* @method static Model\Collection|NewsArchiveModel[]|NewsArchiveModel|null findAll(array $opt=array())
*
* @method static integer countById($id, $opt=array())
* @method static integer countByTstamp($val, $opt=array())
* @method static integer countByTitle($val, $opt=array())
* @method static integer countByJumpTo($val, $opt=array())
* @method static integer countByProtected($val, $opt=array())
* @method static integer countByGroups($val, $opt=array())
* @method static integer countByAllowComments($val, $opt=array())
* @method static integer countByNotify($val, $opt=array())
* @method static integer countBySortOrder($val, $opt=array())
* @method static integer countByPerPage($val, $opt=array())
* @method static integer countByModerate($val, $opt=array())
* @method static integer countByBbcode($val, $opt=array())
* @method static integer countByRequireLogin($val, $opt=array())
* @method static integer countByDisableCaptcha($val, $opt=array())
* @method static integer countById($id, array $opt=array())
* @method static integer countByTstamp($val, array $opt=array())
* @method static integer countByTitle($val, array $opt=array())
* @method static integer countByJumpTo($val, array $opt=array())
* @method static integer countByProtected($val, array $opt=array())
* @method static integer countByGroups($val, array $opt=array())
* @method static integer countByAllowComments($val, array $opt=array())
* @method static integer countByNotify($val, array $opt=array())
* @method static integer countBySortOrder($val, array $opt=array())
* @method static integer countByPerPage($val, array $opt=array())
* @method static integer countByModerate($val, array $opt=array())
* @method static integer countByBbcode($val, array $opt=array())
* @method static integer countByRequireLogin($val, array $opt=array())
* @method static integer countByDisableCaptcha($val, array $opt=array())
*
* @author Leo Feyer <https://github.com/leofeyer>
*/
Expand Down
Loading

0 comments on commit f4e0559

Please sign in to comment.