mirror of
https://github.com/monstra-cms/monstra.git
synced 2025-08-04 20:27:40 +02:00
Monstra Library: basic core improvments
This commit is contained in:
@@ -8,4 +8,4 @@
|
||||
<plugin_version>1.0.0</plugin_version>
|
||||
<plugin_author>Awilum</plugin_author>
|
||||
<plugin_author_uri>http://monstra.org/</plugin_author_uri>
|
||||
</root>
|
||||
</root>
|
||||
|
@@ -1,7 +1,7 @@
|
||||
<?php
|
||||
|
||||
return array(
|
||||
'sitemap' => array(
|
||||
'Sitemap' => 'Sitemap',
|
||||
)
|
||||
);
|
||||
<?php
|
||||
|
||||
return array(
|
||||
'sitemap' => array(
|
||||
'Sitemap' => 'Sitemap',
|
||||
)
|
||||
);
|
||||
|
@@ -1,7 +1,7 @@
|
||||
<?php
|
||||
|
||||
|
||||
return array(
|
||||
'sitemap' => array(
|
||||
'Sitemap' => 'Sitemap',
|
||||
)
|
||||
);
|
||||
);
|
||||
|
@@ -1,7 +1,7 @@
|
||||
<?php
|
||||
|
||||
|
||||
return array(
|
||||
'sitemap' => array(
|
||||
'Sitemap' => 'Sitemap',
|
||||
)
|
||||
);
|
||||
);
|
||||
|
@@ -1,7 +1,7 @@
|
||||
<?php
|
||||
|
||||
|
||||
return array(
|
||||
'sitemap' => array(
|
||||
'Sitemap' => 'Sitemap',
|
||||
)
|
||||
);
|
||||
);
|
||||
|
@@ -1,7 +1,7 @@
|
||||
<?php
|
||||
|
||||
|
||||
return array(
|
||||
'sitemap' => array(
|
||||
'Sitemap' => 'Mapa do site',
|
||||
)
|
||||
);
|
||||
);
|
||||
|
@@ -1,7 +1,7 @@
|
||||
<?php
|
||||
|
||||
|
||||
return array(
|
||||
'sitemap' => array(
|
||||
'Sitemap' => 'Карта сайта',
|
||||
)
|
||||
);
|
||||
);
|
||||
|
@@ -1,7 +1,7 @@
|
||||
<?php
|
||||
|
||||
|
||||
return array(
|
||||
'sitemap' => array(
|
||||
'Sitemap' => 'Карта сайту',
|
||||
)
|
||||
);
|
||||
);
|
||||
|
@@ -1,180 +1,173 @@
|
||||
<?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');
|
||||
|
||||
// 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
|
||||
*/
|
||||
class Sitemap extends Frontend
|
||||
{
|
||||
/**
|
||||
* Sitemap plugin
|
||||
*
|
||||
* @package Monstra
|
||||
* @subpackage Plugins
|
||||
* @author Romanenko Sergey / Awilum
|
||||
* @copyright 2012 Romanenko Sergey / Awilum
|
||||
* @version 1.0.0
|
||||
* Forbidden components
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
|
||||
|
||||
// Register plugin
|
||||
Plugin::register( __FILE__,
|
||||
__('Sitemap', 'sitemap'),
|
||||
__('Sitemap plugin', 'sitemap'),
|
||||
'1.0.0',
|
||||
'Awilum',
|
||||
'http://monstra.org/',
|
||||
'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');
|
||||
|
||||
public static $forbidden_components = array('pages', 'sitemap');
|
||||
|
||||
/**
|
||||
* Sitemap class
|
||||
* Sitemap Title
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
class Sitemap extends Frontend {
|
||||
public static function title()
|
||||
{
|
||||
return __('Sitemap', 'sitemap');
|
||||
}
|
||||
|
||||
/**
|
||||
* Sitemap template
|
||||
*/
|
||||
public static function template()
|
||||
{
|
||||
return 'index';
|
||||
}
|
||||
|
||||
/**
|
||||
* Forbidden components
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $forbidden_components = array('pages', 'sitemap');
|
||||
/**
|
||||
* Get sitemap content
|
||||
*/
|
||||
public static function content()
|
||||
{
|
||||
// Display view
|
||||
return View::factory('box/sitemap/views/frontend/index')
|
||||
->assign('pages_list', Sitemap::getPages())
|
||||
->assign('components', Sitemap::getComponents())
|
||||
->render();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create sitemap
|
||||
*/
|
||||
public static function create()
|
||||
{
|
||||
// Get pages list
|
||||
$pages_list = Sitemap::getPages();
|
||||
|
||||
/**
|
||||
* Sitemap Title
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function title() {
|
||||
return __('Sitemap', 'sitemap');
|
||||
// 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'].'/'; $priority = '0.5'; } else { $parent = ''; $priority = '1.0'; }
|
||||
$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>'.$priority.'</priority>'."\n\t".'</url>'."\n";
|
||||
}
|
||||
|
||||
// Get list of components
|
||||
$components = Sitemap::getComponents();
|
||||
|
||||
/**
|
||||
* Sitemap template
|
||||
*/
|
||||
public static function template() {
|
||||
return 'index';
|
||||
// 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>';
|
||||
|
||||
/**
|
||||
* Get sitemap content
|
||||
*/
|
||||
public static function content() {
|
||||
// Save sitemap
|
||||
return File::setContent(ROOT . DS . 'sitemap.xml', $map);
|
||||
}
|
||||
|
||||
// Display view
|
||||
return View::factory('box/sitemap/views/frontend/index')
|
||||
->assign('pages_list', Sitemap::getPages())
|
||||
->assign('components', Sitemap::getComponents())
|
||||
->render();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get pages
|
||||
*/
|
||||
protected static function getPages()
|
||||
{
|
||||
// Init vars
|
||||
$pages_array = array();
|
||||
$count = 0;
|
||||
|
||||
/**
|
||||
* Create sitemap
|
||||
*/
|
||||
public static function create() {
|
||||
// Get pages table
|
||||
$pages = new Table('pages');
|
||||
|
||||
// Get pages list
|
||||
$pages_list = Sitemap::getPages();
|
||||
|
||||
// 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'].'/'; $priority = '0.5'; } else { $parent = ''; $priority = '1.0'; }
|
||||
$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>'.$priority.'</priority>'."\n\t".'</url>'."\n";
|
||||
// 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 = '';
|
||||
}
|
||||
|
||||
// Get list of components
|
||||
$components = Sitemap::getComponents();
|
||||
if ($c_p != '') {
|
||||
$_page = $pages->select('[slug="'.$page['parent'].'"]', null);
|
||||
|
||||
// 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 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'];
|
||||
if (isset($_page['title'])) {
|
||||
$_title = $_page['title'];
|
||||
} else {
|
||||
$c_p = '';
|
||||
$_title = '';
|
||||
}
|
||||
|
||||
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++;
|
||||
$pages_array[$count]['sort'] = $_title . ' ' . $page['title'];
|
||||
} else {
|
||||
$pages_array[$count]['sort'] = $page['title'];
|
||||
}
|
||||
|
||||
// Sort pages
|
||||
$_pages_list = Arr::subvalSort($pages_array, 'sort');
|
||||
|
||||
// return
|
||||
return $_pages_list;
|
||||
$_title = '';
|
||||
$count++;
|
||||
}
|
||||
|
||||
// Sort pages
|
||||
$_pages_list = Arr::subvalSort($pages_array, 'sort');
|
||||
|
||||
/**
|
||||
* Get components
|
||||
*/
|
||||
protected static function getComponents() {
|
||||
// return
|
||||
return $_pages_list;
|
||||
}
|
||||
|
||||
$components = array();
|
||||
|
||||
if (count(Plugin::$components) > 0) {
|
||||
foreach (Plugin::$components as $component) {
|
||||
if ( ! in_array($component, Sitemap::$forbidden_components)) $components[] = Text::lowercase($component);
|
||||
}
|
||||
/**
|
||||
* Get components
|
||||
*/
|
||||
protected static function getComponents()
|
||||
{
|
||||
$components = array();
|
||||
|
||||
if (count(Plugin::$components) > 0) {
|
||||
foreach (Plugin::$components as $component) {
|
||||
if ( ! in_array($component, Sitemap::$forbidden_components)) $components[] = Text::lowercase($component);
|
||||
}
|
||||
|
||||
return $components;
|
||||
}
|
||||
|
||||
}
|
||||
return $components;
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -1,21 +1,21 @@
|
||||
<h3><?php echo __('Sitemap', 'sitemap'); ?></h3>
|
||||
<hr>
|
||||
<ul>
|
||||
<?php
|
||||
<?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'].'">'.$page['title'].'</a></li>';
|
||||
if (trim($page['parent']) !== '') { echo '</ul>'; }
|
||||
}
|
||||
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'].'">'.$page['title'].'</a></li>';
|
||||
if (trim($page['parent']) !== '') { echo '</ul>'; }
|
||||
}
|
||||
if (count($components) == 0) { echo '<ul>'; }
|
||||
}
|
||||
|
||||
// Display components
|
||||
if (count($components) > 0) {
|
||||
if (count($components) > 0) {
|
||||
if (count($pages_list) == 0) { echo '<ul>'; }
|
||||
foreach ($components as $component) {
|
||||
echo '<li><a href="'.Option::get('siteurl').$component.'">'.__(ucfirst($component), $component).'</a></li>';
|
||||
|
Reference in New Issue
Block a user