Skip to content
This repository has been archived by the owner on Sep 19, 2020. It is now read-only.

Commit

Permalink
Allow to exclude news archives from analysis
Browse files Browse the repository at this point in the history
  • Loading branch information
qzminski committed Aug 4, 2016
1 parent 98c1911 commit 4540fef
Show file tree
Hide file tree
Showing 5 changed files with 91 additions and 2 deletions.
28 changes: 28 additions & 0 deletions dca/tl_news_archive.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

/**
* seo_serp_preview extension for Contao Open Source CMS
*
* Copyright (C) 2016 derhaeuptling
*
* @author derhaeuptling <https://derhaeuptling.com>
* @author Codefog <http://codefog.pl>
* @author Kamil Kuzminski <[email protected]>
* @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 ''",
];
25 changes: 25 additions & 0 deletions languages/en/tl_news_archive.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

/**
* seo_serp_preview extension for Contao Open Source CMS
*
* Copyright (C) 2016 derhaeuptling
*
* @author derhaeuptling <https://derhaeuptling.com>
* @author Codefog <http://codefog.pl>
* @author Kamil Kuzminski <[email protected]>
* @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';
4 changes: 3 additions & 1 deletion src/Derhaeuptling/SeoSerpPreview/PreviewModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
12 changes: 11 additions & 1 deletion src/Derhaeuptling/SeoSerpPreview/StatusManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
24 changes: 24 additions & 0 deletions src/Derhaeuptling/SeoSerpPreview/TestsHandler/NewsHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down

0 comments on commit 4540fef

Please sign in to comment.