mirror of
https://github.com/Oreolek/ifhub.club.git
synced 2024-06-29 04:55:02 +03:00
Поддержка плагина "sitemap" в плагине "page"
This commit is contained in:
parent
5101909984
commit
48818e4bb4
|
@ -19,10 +19,17 @@
|
|||
* Запрещаем напрямую через браузер обращение к этому файлу.
|
||||
*/
|
||||
if (!class_exists('Plugin')) {
|
||||
die('Hacking attemp!');
|
||||
die('Hacking attempt!');
|
||||
}
|
||||
|
||||
class PluginPage extends Plugin {
|
||||
|
||||
protected $aInherits = array(
|
||||
'module' => array(
|
||||
'PluginSitemap_ModuleSitemap' => 'PluginPage_ModuleSitemap',
|
||||
),
|
||||
);
|
||||
|
||||
|
||||
/**
|
||||
* Активация плагина "Статические страницы".
|
||||
|
|
40
plugins/page/classes/hooks/HookSitemap.class.php
Normal file
40
plugins/page/classes/hooks/HookSitemap.class.php
Normal file
|
@ -0,0 +1,40 @@
|
|||
<?php
|
||||
|
||||
/* -------------------------------------------------------
|
||||
*
|
||||
* LiveStreet Engine Social Networking
|
||||
* Copyright © 2008 Mzhelskiy Maxim
|
||||
*
|
||||
* --------------------------------------------------------
|
||||
*
|
||||
* Official site: www.livestreet.ru
|
||||
* Contact e-mail: rus.engine@gmail.com
|
||||
*
|
||||
* GNU General Public License, version 2:
|
||||
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
||||
*
|
||||
* ---------------------------------------------------------
|
||||
*/
|
||||
|
||||
class PluginPage_HookSitemap extends Hook {
|
||||
|
||||
/**
|
||||
* Цепляем обработчики на хуки
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function RegisterHook() {
|
||||
$this->AddHook('sitemap_index_counters', 'SitemapIndex');
|
||||
}
|
||||
|
||||
/**
|
||||
* Добавляем ссылку на Sitemap страниц в Sitemap Index
|
||||
*
|
||||
* @param array $aCounters
|
||||
* @return void
|
||||
*/
|
||||
public function SitemapIndex($aCounters) {
|
||||
$aCounters['pages'] = ceil($this->PluginSitemap_Page_GetActivePagesCount() / Config::Get('plugin.sitemap.objects_per_page'));
|
||||
}
|
||||
|
||||
}
|
|
@ -204,5 +204,27 @@ class PluginPage_ModulePage extends Module {
|
|||
public function GetMaxSortByPid($sPid) {
|
||||
return $this->oMapper->GetMaxSortByPid($sPid);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get count of pages
|
||||
*
|
||||
* @return integer
|
||||
*/
|
||||
public function getCountOfActivePages() {
|
||||
return (int)$this->oMapper->getCountOfActivePages();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get list of active pages
|
||||
*
|
||||
* @param integer $iCount
|
||||
* @param integer $iCurrPage
|
||||
* @param integer $iPerPage
|
||||
* @return array
|
||||
*/
|
||||
public function getListOfActivePages(&$iCount, $iCurrPage, $iPerPage) {
|
||||
return $this->oMapper->getListOfActivePages($iCount, $iCurrPage, Config::Get('plugin.sitemap.objects_per_page'));
|
||||
}
|
||||
|
||||
}
|
||||
?>
|
|
@ -183,5 +183,53 @@ class PluginPage_ModulePage_MapperPage extends Mapper {
|
|||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* List of active pages
|
||||
*
|
||||
* @param integer $iCount
|
||||
* @param integer $iCurrPage
|
||||
* @param integer $iPerPage
|
||||
* @return array
|
||||
*/
|
||||
public function getListOfActivePages(&$iCount, $iCurrPage, $iPerPage) {
|
||||
$sql = 'SELECT
|
||||
`page`.*
|
||||
FROM
|
||||
`' . Config::Get('plugin.page.table.page') . '` AS `page`
|
||||
WHERE
|
||||
`page`.`page_active` = 1
|
||||
ORDER BY
|
||||
`page`.`page_id` ASC
|
||||
LIMIT
|
||||
?d, ?d
|
||||
';
|
||||
$aPages = array();
|
||||
if ($aRows = $this->oDb->selectPage($iCount, $sql, ($iCurrPage - 1) * $iPerPage, $iPerPage)) {
|
||||
foreach ($aRows as $aPage) {
|
||||
$aPages[] = Engine::GetEntity('PluginPage_Page', $aPage);
|
||||
}
|
||||
}
|
||||
return $aPages;
|
||||
}
|
||||
|
||||
/**
|
||||
* Count of active pages
|
||||
*
|
||||
* @return integer
|
||||
*/
|
||||
public function getCountOfActivePages() {
|
||||
$sql = 'SELECT
|
||||
COUNT(`page`.`page_id`)
|
||||
FROM
|
||||
`' . Config::Get('plugin.page.table.page') . '` AS `page`
|
||||
WHERE
|
||||
`page`.`page_active` = 1
|
||||
';
|
||||
|
||||
return $this->oDb->selectCell($sql);
|
||||
}
|
||||
|
||||
}
|
||||
?>
|
64
plugins/page/classes/modules/sitemap/Sitemap.class.php
Normal file
64
plugins/page/classes/modules/sitemap/Sitemap.class.php
Normal file
|
@ -0,0 +1,64 @@
|
|||
<?php
|
||||
/*-------------------------------------------------------
|
||||
*
|
||||
* LiveStreet Engine Social Networking
|
||||
* Copyright © 2008 Mzhelskiy Maxim
|
||||
*
|
||||
*--------------------------------------------------------
|
||||
*
|
||||
* Official site: www.livestreet.ru
|
||||
* Contact e-mail: rus.engine@gmail.com
|
||||
*
|
||||
* GNU General Public License, version 2:
|
||||
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
||||
*
|
||||
---------------------------------------------------------
|
||||
*/
|
||||
|
||||
/**
|
||||
* Module for plugin Sitemap
|
||||
*/
|
||||
class PluginPage_ModuleSitemap extends PluginPage_Inherit_PluginSitemap_ModuleSitemap {
|
||||
|
||||
/**
|
||||
* Change data for Sitemap Index
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getExternalCounters() {
|
||||
$aCounters = parent::getExternalCounters();
|
||||
$aCounters['pages'] = ceil($this->PluginPage_Page_GetCountOfActivePages() / Config::Get('plugin.sitemap.objects_per_page'));
|
||||
|
||||
return $aCounters;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get data for static pages Sitemap
|
||||
*
|
||||
* @param integer $iCurrPage
|
||||
* @return array
|
||||
*/
|
||||
public function getDataForPages($iCurrPage) {
|
||||
$iPerPage = Config::Get('plugin.sitemap.objects_per_page');
|
||||
$sCacheKey = "sitemap_pages_{$iCurrPage}_" . $iPerPage;
|
||||
|
||||
if (false === ($aData = $this->Cache_Get($sCacheKey))) {
|
||||
$iCount = 0;
|
||||
$aPages = $this->PluginPage_Page_GetListOfActivePages($iCount, $iCurrPage, $iPerPage);
|
||||
|
||||
$aData = array();
|
||||
foreach ($aPages as $oPage) {
|
||||
$aData[] = $this->PluginSitemap_Sitemap_GetDataForSitemapRow(
|
||||
Router::GetPath('page') . $oPage->getUrlFull(),
|
||||
$oPage->getDateLastMod(),
|
||||
Config::Get('plugin.page.sitemap.sitemap_priority'),
|
||||
Config::Get('plugin.page.sitemap.sitemap_changefreq')
|
||||
);
|
||||
}
|
||||
|
||||
$this->Cache_Set($aData, $sCacheKey, array('page_change'), Config::Get('plugin.page.sitemap.cache_lifetime'));
|
||||
}
|
||||
|
||||
return $aData;
|
||||
}
|
||||
}
|
|
@ -14,9 +14,18 @@
|
|||
*
|
||||
---------------------------------------------------------
|
||||
*/
|
||||
$config=array();
|
||||
|
||||
$config['table']['page'] = '___db.table.prefix___page';
|
||||
|
||||
Config::Set('router.page.page', 'PluginPage_ActionPage');
|
||||
|
||||
// Settings for plugin Sitemap
|
||||
$config['sitemap'] = array (
|
||||
'cache_lifetime' => 60 * 60 * 24, // 24 hours
|
||||
'sitemap_priority' => '0.8',
|
||||
'sitemap_changefreq' => 'monthly'
|
||||
);
|
||||
|
||||
return $config;
|
||||
?>
|
|
@ -8,7 +8,7 @@
|
|||
</author>
|
||||
<homepage>http://livestreet.ru</homepage>
|
||||
<settings>{page}admin/</settings>
|
||||
<version>1.3.1</version>
|
||||
<version>1.3.2</version>
|
||||
<requires>
|
||||
<livestreet>0.4.2</livestreet>
|
||||
<plugins>
|
||||
|
|
Loading…
Reference in a new issue