diff --git a/plugins/page/PluginPage.class.php b/plugins/page/PluginPage.class.php index 6443bd4e..44c612e9 100644 --- a/plugins/page/PluginPage.class.php +++ b/plugins/page/PluginPage.class.php @@ -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', + ), + ); + /** * Активация плагина "Статические страницы". diff --git a/plugins/page/classes/hooks/HookSitemap.class.php b/plugins/page/classes/hooks/HookSitemap.class.php new file mode 100644 index 00000000..6890c5e2 --- /dev/null +++ b/plugins/page/classes/hooks/HookSitemap.class.php @@ -0,0 +1,40 @@ +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')); + } + +} \ No newline at end of file diff --git a/plugins/page/classes/modules/page/Page.class.php b/plugins/page/classes/modules/page/Page.class.php index 704e0b8d..b11cb4c5 100644 --- a/plugins/page/classes/modules/page/Page.class.php +++ b/plugins/page/classes/modules/page/Page.class.php @@ -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')); + } + } ?> \ No newline at end of file diff --git a/plugins/page/classes/modules/page/mapper/Page.mapper.class.php b/plugins/page/classes/modules/page/mapper/Page.mapper.class.php index 4f864a13..b983323b 100644 --- a/plugins/page/classes/modules/page/mapper/Page.mapper.class.php +++ b/plugins/page/classes/modules/page/mapper/Page.mapper.class.php @@ -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); + } + } ?> \ No newline at end of file diff --git a/plugins/page/classes/modules/sitemap/Sitemap.class.php b/plugins/page/classes/modules/sitemap/Sitemap.class.php new file mode 100644 index 00000000..008d9d48 --- /dev/null +++ b/plugins/page/classes/modules/sitemap/Sitemap.class.php @@ -0,0 +1,64 @@ +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; + } +} diff --git a/plugins/page/config/config.php b/plugins/page/config/config.php index 495e72d4..4a1a4a11 100644 --- a/plugins/page/config/config.php +++ b/plugins/page/config/config.php @@ -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; ?> \ No newline at end of file diff --git a/plugins/page/plugin.xml b/plugins/page/plugin.xml index 561c2642..e7d2491b 100644 --- a/plugins/page/plugin.xml +++ b/plugins/page/plugin.xml @@ -8,7 +8,7 @@ http://livestreet.ru {page}admin/ - 1.3.1 + 1.3.2 0.4.2