1
0
mirror of https://github.com/monstra-cms/monstra.git synced 2025-08-03 11:47:51 +02:00

Sitemap Plugin: general refactoring and seo improvements

This commit is contained in:
Awilum
2012-11-13 19:47:09 +02:00
parent 7072a8eb89
commit d1689f4774

View File

@@ -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 = '<?xml version="1.0" encoding="UTF-8"?>'."\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);
}
}