From 4540fef3964b85ac3dcf5f4e084c479cd3aad006 Mon Sep 17 00:00:00 2001 From: Kamil Kuzminski Date: Thu, 4 Aug 2016 15:31:07 +0200 Subject: [PATCH] Allow to exclude news archives from analysis --- dca/tl_news_archive.php | 28 +++++++++++++++++++ languages/en/tl_news_archive.php | 25 +++++++++++++++++ .../SeoSerpPreview/PreviewModule.php | 4 ++- .../SeoSerpPreview/StatusManager.php | 12 +++++++- .../TestsHandler/NewsHandler.php | 24 ++++++++++++++++ 5 files changed, 91 insertions(+), 2 deletions(-) create mode 100644 dca/tl_news_archive.php create mode 100644 languages/en/tl_news_archive.php diff --git a/dca/tl_news_archive.php b/dca/tl_news_archive.php new file mode 100644 index 0000000..68e7c3f --- /dev/null +++ b/dca/tl_news_archive.php @@ -0,0 +1,28 @@ + + * @author Codefog + * @author Kamil Kuzminski + * @license LGPL + */ + +/** + * Extend palettes + */ +$GLOBALS['TL_DCA']['tl_news_archive']['palettes']['default'] .= ';{seo_serp_legend},seo_serp_ignore'; + +/** + * Add fields + */ +$GLOBALS['TL_DCA']['tl_news_archive']['fields']['seo_serp_ignore'] = [ + 'label' => &$GLOBALS['TL_LANG']['tl_news_archive']['seo_serp_ignore'], + 'exclude' => true, + 'inputType' => 'checkbox', + 'eval' => ['tl_class' => 'clr'], + 'sql' => "char(1) NOT NULL default ''", +]; \ No newline at end of file diff --git a/languages/en/tl_news_archive.php b/languages/en/tl_news_archive.php new file mode 100644 index 0000000..783b0ad --- /dev/null +++ b/languages/en/tl_news_archive.php @@ -0,0 +1,25 @@ + + * @author Codefog + * @author Kamil Kuzminski + * @license LGPL + */ + +/** + * Fields + */ +$GLOBALS['TL_LANG']['tl_news_archive']['seo_serp_ignore'] = [ + 'Ignore this archive', + 'Ignore this archive during SEO SERP analysis.', +]; + +/** + * Legends + */ +$GLOBALS['TL_LANG']['tl_news_archive']['seo_serp_legend'] = 'SEO SERP settings'; \ No newline at end of file diff --git a/src/Derhaeuptling/SeoSerpPreview/PreviewModule.php b/src/Derhaeuptling/SeoSerpPreview/PreviewModule.php index 60cd726..f9fd0a4 100644 --- a/src/Derhaeuptling/SeoSerpPreview/PreviewModule.php +++ b/src/Derhaeuptling/SeoSerpPreview/PreviewModule.php @@ -194,7 +194,9 @@ protected function runTestsForTable($module, $table) break; case 'tl_news': - $archives = $db->execute("SELECT id, title FROM tl_news_archive ORDER BY title"); + $archives = $db->execute( + "SELECT id, title FROM tl_news_archive WHERE seo_serp_ignore='' ORDER BY title" + ); while ($archives->next()) { $test = $this->runTests( diff --git a/src/Derhaeuptling/SeoSerpPreview/StatusManager.php b/src/Derhaeuptling/SeoSerpPreview/StatusManager.php index 8050898..b306a48 100644 --- a/src/Derhaeuptling/SeoSerpPreview/StatusManager.php +++ b/src/Derhaeuptling/SeoSerpPreview/StatusManager.php @@ -49,7 +49,17 @@ public function rebuildCache() public function getStatus() { foreach ($this->tables as $table) { - $records = Database::getInstance()->execute("SELECT * FROM ".$table); + switch ($table) { + case 'tl_news': + $records = Database::getInstance()->execute( + "SELECT * FROM tl_news WHERE pid IN (SELECT id FROM tl_news_archive WHERE seo_serp_ignore='')" + ); + break; + + default: + $records = Database::getInstance()->execute("SELECT * FROM ".$table); + break; + } while ($records->next()) { try { diff --git a/src/Derhaeuptling/SeoSerpPreview/TestsHandler/NewsHandler.php b/src/Derhaeuptling/SeoSerpPreview/TestsHandler/NewsHandler.php index baf3070..09b63d9 100644 --- a/src/Derhaeuptling/SeoSerpPreview/TestsHandler/NewsHandler.php +++ b/src/Derhaeuptling/SeoSerpPreview/TestsHandler/NewsHandler.php @@ -14,9 +14,33 @@ namespace Derhaeuptling\SeoSerpPreview\TestsHandler; use Contao\Database; +use Contao\DataContainer; class NewsHandler extends AbstractHandler { + /** + * Initialize the tests handler + * + * @param DataContainer|null $dc + */ + public function initialize(DataContainer $dc = null) + { + if (CURRENT_ID) { + $archive = Database::getInstance()->prepare("SELECT seo_serp_ignore FROM tl_news_archive WHERE id=?") + ->limit(1) + ->execute(CURRENT_ID); + + // Do not initialize handler if archive is ignored + if ($archive->seo_serp_ignore) { + unset($GLOBALS['TL_DCA']['tl_news']['fields']['seo_serp_preview']); + + return; + } + } + + parent::initialize($dc); + } + /** * Get the table name *