From d1689f4774dd00175ff166346ae77a5a05ea0223 Mon Sep 17 00:00:00 2001 From: Awilum Date: Tue, 13 Nov 2012 19:47:09 +0200 Subject: [PATCH] Sitemap Plugin: general refactoring and seo improvements --- plugins/box/sitemap/sitemap.plugin.php | 119 ++++++++++++++----------- 1 file changed, 69 insertions(+), 50 deletions(-) diff --git a/plugins/box/sitemap/sitemap.plugin.php b/plugins/box/sitemap/sitemap.plugin.php index 83c9858..8b93d1e 100644 --- a/plugins/box/sitemap/sitemap.plugin.php +++ b/plugins/box/sitemap/sitemap.plugin.php @@ -22,15 +22,27 @@ 'sitemap', 'box'); - + // Add actions Action::add('admin_pages_action_add', 'Sitemap::create'); Action::add('admin_pages_action_edit', 'Sitemap::create'); Action::add('admin_pages_action_clone', 'Sitemap::create'); Action::add('admin_pages_action_delete', 'Sitemap::create'); + + /** + * Sitemap + */ class Sitemap extends Frontend { + /** + * Forbidden components + * + * @var array + */ + public static $forbidden_components = array('pages', 'sitemap'); + + /** * Sitemap Title * @@ -54,52 +66,9 @@ */ public static function content() { - // Init vars - $pages_array = array(); - $count = 0; - - // Get pages table - $pages = new Table('pages'); - - // Get Pages List - $pages_list = $pages->select('[slug!="error404" and status="published"]'); - - foreach ($pages_list as $page) { - - $pages_array[$count]['title'] = Html::toText($page['title']); - $pages_array[$count]['parent'] = $page['parent']; - $pages_array[$count]['date'] = $page['date']; - $pages_array[$count]['author'] = $page['author']; - $pages_array[$count]['slug'] = $page['slug']; - - if (isset($page['parent'])) { - $c_p = $page['parent']; - } else { - $c_p = ''; - } - - if ($c_p != '') { - $_page = $pages->select('[slug="'.$page['parent'].'"]', null); - - if (isset($_page['title'])) { - $_title = $_page['title']; - } else { - $_title = ''; - } - $pages_array[$count]['sort'] = $_title . ' ' . $page['title']; - } else { - $pages_array[$count]['sort'] = $page['title']; - } - $_title = ''; - $count++; - } - - // Sort pages - $_pages_list = Arr::subvalSort($pages_array, 'sort'); - // Display view return View::factory('box/sitemap/views/frontend/index') - ->assign('pages_list', $_pages_list) + ->assign('pages_list', Sitemap::getPages()) ->assign('components', Sitemap::getComponents()) ->render(); } @@ -110,11 +79,8 @@ */ public static function create() { - // Get pages table - $pages = new Table('pages'); - // Get pages list - $pages_list = $pages->select('[slug!="error404" and status="published"]'); + $pages_list = Sitemap::getPages(); // Create sitemap content $map = ''."\n"; @@ -142,6 +108,59 @@ } + /** + * Get pages + */ + protected static function getPages() { + + // Init vars + $pages_array = array(); + $count = 0; + + // Get pages table + $pages = new Table('pages'); + + // Get Pages List + $pages_list = $pages->select('[slug!="error404" and status="published"]'); + + foreach ($pages_list as $page) { + + $pages_array[$count]['title'] = Html::toText($page['title']); + $pages_array[$count]['parent'] = $page['parent']; + $pages_array[$count]['date'] = $page['date']; + $pages_array[$count]['author'] = $page['author']; + $pages_array[$count]['slug'] = ($page['slug'] == Option::get('defaultpage')) ? '' : $page['slug'] ; + + if (isset($page['parent'])) { + $c_p = $page['parent']; + } else { + $c_p = ''; + } + + if ($c_p != '') { + $_page = $pages->select('[slug="'.$page['parent'].'"]', null); + + if (isset($_page['title'])) { + $_title = $_page['title']; + } else { + $_title = ''; + } + $pages_array[$count]['sort'] = $_title . ' ' . $page['title']; + } else { + $pages_array[$count]['sort'] = $page['title']; + } + $_title = ''; + $count++; + } + + // Sort pages + $_pages_list = Arr::subvalSort($pages_array, 'sort'); + + // return + return $_pages_list; + } + + /** * Get components */ @@ -151,7 +170,7 @@ if (count(Plugin::$components) > 0) { foreach (Plugin::$components as $component) { - if ($component !== 'pages' && $component !== 'sitemap') $components[] = __(ucfirst($component), $component); + if ( ! in_array($component, Sitemap::$forbidden_components)) $components[] = __(ucfirst($component), $component); } }