mirror of
https://github.com/monstra-cms/monstra.git
synced 2025-08-10 15:14:30 +02:00
Add Monstra from HG Commit 683dcb70c4cc
This commit is contained in:
11
plugins/box/sitemap/install/sitemap.manifest.xml
Normal file
11
plugins/box/sitemap/install/sitemap.manifest.xml
Normal file
@@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<root>
|
||||
<plugin_location>plugins/box/sitemap/sitemap.plugin.php</plugin_location>
|
||||
<plugin_status>active</plugin_status>
|
||||
<plugin_priority>10</plugin_priority>
|
||||
<plugin_name>Sitemap</plugin_name>
|
||||
<plugin_description>Show sitemap</plugin_description>
|
||||
<plugin_version>1.0.0</plugin_version>
|
||||
<plugin_author>Awilum</plugin_author>
|
||||
<plugin_author_uri>http://awilum.webdevart.ru/</plugin_author_uri>
|
||||
</root>
|
7
plugins/box/sitemap/languages/en.lang.php
Normal file
7
plugins/box/sitemap/languages/en.lang.php
Normal file
@@ -0,0 +1,7 @@
|
||||
<?php
|
||||
|
||||
return array(
|
||||
'sitemap' => array(
|
||||
'Sitemap' => 'Sitemap',
|
||||
)
|
||||
);
|
7
plugins/box/sitemap/languages/ru.lang.php
Normal file
7
plugins/box/sitemap/languages/ru.lang.php
Normal file
@@ -0,0 +1,7 @@
|
||||
<?php
|
||||
|
||||
return array(
|
||||
'sitemap' => array(
|
||||
'Sitemap' => 'Карта сайта',
|
||||
)
|
||||
);
|
160
plugins/box/sitemap/sitemap.plugin.php
Normal file
160
plugins/box/sitemap/sitemap.plugin.php
Normal file
@@ -0,0 +1,160 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Sitemap plugin
|
||||
*
|
||||
* @package Monstra
|
||||
* @subpackage Plugins
|
||||
* @author Romanenko Sergey / Awilum
|
||||
* @copyright 2012 Romanenko Sergey / Awilum
|
||||
* @version 1.0.0
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
// Register plugin
|
||||
Plugin::register( __FILE__,
|
||||
__('Sitemap', 'sitemap'),
|
||||
__('Sitemap plugin', 'sitemap'),
|
||||
'1.0.0',
|
||||
'Awilum',
|
||||
'http://monstra.org/',
|
||||
'sitemap',
|
||||
'box');
|
||||
|
||||
|
||||
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');
|
||||
|
||||
class Sitemap extends Frontend {
|
||||
|
||||
|
||||
/**
|
||||
* Sitemap Title
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function title() {
|
||||
return __('Sitemap', 'sitemap');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sitemap template
|
||||
*/
|
||||
public static function template() {
|
||||
return 'index';
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get sitemap content
|
||||
*/
|
||||
public static function content() {
|
||||
|
||||
// Get pages table
|
||||
$pages = new Table('pages');
|
||||
|
||||
$pages_list = $pages->select('[slug!="error404" and status="published"]');
|
||||
|
||||
$pages_array = array();
|
||||
|
||||
$count = 0;
|
||||
|
||||
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('components', Sitemap::getComponents())
|
||||
->render();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create sitemap
|
||||
*/
|
||||
public static function create() {
|
||||
|
||||
// Get pages table
|
||||
$pages = new Table('pages');
|
||||
|
||||
// Get pages list
|
||||
$pages_list = $pages->select('[slug!="error404" and status="published"]');
|
||||
|
||||
// Create sitemap content
|
||||
$map = '<?xml version="1.0" encoding="UTF-8"?>'."\n";
|
||||
$map .= '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">'."\n";
|
||||
foreach ($pages_list as $page) {
|
||||
if ($page['parent'] != '') { $parent = $page['parent'].'/'; } else { $parent = ''; }
|
||||
$map .= "\t".'<url>'."\n\t\t".'<loc>'.Option::get('siteurl').$parent.$page['slug'].'</loc>'."\n\t\t".'<lastmod>'.date("Y-m-d", (int)$page['date']).'</lastmod>'."\n\t\t".'<changefreq>weekly</changefreq>'."\n\t\t".'<priority>1.0</priority>'."\n\t".'</url>'."\n";
|
||||
}
|
||||
|
||||
// Get list of components
|
||||
$components = Sitemap::getComponents();
|
||||
|
||||
// Add components to sitemap
|
||||
if (count($components) > 0) {
|
||||
foreach ($components as $component) {
|
||||
$map .= "\t".'<url>'."\n\t\t".'<loc>'.Option::get('siteurl').Text::lowercase($component).'</loc>'."\n\t\t".'<lastmod>'.date("Y-m-d", time()).'</lastmod>'."\n\t\t".'<changefreq>weekly</changefreq>'."\n\t\t".'<priority>1.0</priority>'."\n\t".'</url>'."\n";
|
||||
}
|
||||
}
|
||||
|
||||
// Close sitemap
|
||||
$map .= '</urlset>';
|
||||
|
||||
// Save sitemap
|
||||
return File::setContent(ROOT . DS . 'sitemap.xml', $map);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get components
|
||||
*/
|
||||
protected static function getComponents() {
|
||||
|
||||
$components = array();
|
||||
|
||||
if (count(Plugin::$components) > 0) {
|
||||
foreach (Plugin::$components as $component) {
|
||||
if ($component !== 'pages' && $component !== 'sitemap') $components[] = ucfirst($component);
|
||||
}
|
||||
}
|
||||
|
||||
return $components;
|
||||
}
|
||||
|
||||
}
|
28
plugins/box/sitemap/views/frontend/index.view.php
Normal file
28
plugins/box/sitemap/views/frontend/index.view.php
Normal file
@@ -0,0 +1,28 @@
|
||||
<h3><?php echo __('Sitemap', 'sitemap'); ?></h3>
|
||||
<br />
|
||||
<ul>
|
||||
<?php
|
||||
|
||||
// Display pages
|
||||
if (count($pages_list) > 0) {
|
||||
foreach ($pages_list as $page) {
|
||||
if (trim($page['parent']) !== '') $parent = $page['parent'].'/'; else $parent = '';
|
||||
if (trim($page['parent']) !== '') { echo '<ul>'; }
|
||||
echo '<li><a href="'.Option::get('siteurl').$parent.$page['slug'].'" target="_blank">'.$page['title'].'</a></li>';
|
||||
if (trim($page['parent']) !== '') { echo '</ul>'; }
|
||||
}
|
||||
if (count($components) == 0) { echo '<ul>'; }
|
||||
}
|
||||
|
||||
// Display components
|
||||
if (count($components) > 0) {
|
||||
if (count($pages_list) == 0) { echo '<ul>'; }
|
||||
foreach ($components as $component) {
|
||||
echo '<li><a href="'.Option::get('siteurl').Text::lowercase($component).'" target="_blank">'.__($component).'</a></li>';
|
||||
}
|
||||
echo '</ul>';
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
</ul>
|
Reference in New Issue
Block a user