1
0
Fork 0
mirror of https://github.com/Oreolek/ifhub.club.git synced 2024-06-17 07:10:48 +03:00

Попытка из модуля "page" сделать плагин "Статические страницы"

This commit is contained in:
Mzhelskiy Maxim 2010-04-25 19:17:38 +00:00
parent 73b511bfc9
commit 544492df96
12 changed files with 86 additions and 62 deletions

View file

@ -36,7 +36,7 @@ abstract class ActionPlugin extends Action {
*/
public function __construct(Engine $oEngine, $sAction) {
parent::__construct($oEngine, $sAction);
$this->Viewer_Assign('sTemplateActionPath',$this->getTemplatePathPlugin());
$this->Viewer_Assign('sTemplatePathPlugin',rtrim($this->getTemplatePathPlugin(),'/'));
}
/**

View file

@ -15,16 +15,21 @@
---------------------------------------------------------
*/
/**
* Настройки роутинга страниц модуля "page"
* Определяет какой экшен должен запускаться при определенном УРЛе
*/
//define("ROUTE_PAGE_PAGE",'page');
return array(
'page' => array(
'page' => 'ActionPage',
),
);
class PluginPage extends Plugin {
/**
* Активация плагина "Статические страницы".
* Создание таблицы в базе данных при ее отсутствии.
*/
public function Activate() {
return true;
}
/**
* Инициализация плагина
*/
public function Init() {
}
}
?>

View file

@ -15,11 +15,7 @@
---------------------------------------------------------
*/
/**
* Обработка статических страниц
*
*/
class ActionPage extends Action {
class PluginPage_ActionPage extends ActionPlugin {
protected $sUserLogin=null;
protected $aBadPageUrl=array('admin');
@ -64,7 +60,7 @@ class ActionPage extends Action {
/**
* Ищем страничку в БД
*/
if (!($oPage=$this->Page_GetPageByUrlFull($sUrlFull,1))) {
if (!($oPage=$this->PluginPage_Page_GetPageByUrlFull($sUrlFull,1))) {
return $this->EventNotFound();
}
/**
@ -111,7 +107,7 @@ class ActionPage extends Action {
* Обработка показа странички для редактирования
*/
if ($this->GetParam(0)=='edit') {
if ($oPageEdit=$this->Page_GetPageById($this->GetParam(1))) {
if ($oPageEdit=$this->PluginPage_Page_GetPageById($this->GetParam(1))) {
if (!isPost('submit_page_save')) {
$_REQUEST['page_title']=$oPageEdit->getTitle();
$_REQUEST['page_pid']=$oPageEdit->getPid();
@ -139,7 +135,7 @@ class ActionPage extends Action {
*/
if ($this->GetParam(0)=='delete') {
$this->Security_ValidateSendForm();
if ($this->Page_deletePageById($this->GetParam(1))) {
if ($this->PluginPage_Page_deletePageById($this->GetParam(1))) {
$this->Message_AddNotice($this->Lang_Get('page_admin_action_delete_ok'));
} else {
$this->Message_AddError($this->Lang_Get('page_admin_action_delete_error'),$this->Lang_Get('error'));
@ -148,10 +144,10 @@ class ActionPage extends Action {
/**
* Получаем и загружаем список всех страниц
*/
$aPages=$this->Page_GetPages();
if (count($aPages)==0 and $this->Page_GetCountPage()) {
$this->Page_SetPagesPidToNull();
$aPages=$this->Page_GetPages();
$aPages=$this->PluginPage_Page_GetPages();
if (count($aPages)==0 and $this->PluginPage_Page_GetCountPage()) {
$this->PluginPage_Page_SetPagesPidToNull();
$aPages=$this->PluginPage_Page_GetPages();
}
$this->Viewer_Assign('aPages',$aPages);
}
@ -182,7 +178,7 @@ class ActionPage extends Action {
$oPageEdit->setPid(null);
} else {
$oPageEdit->setPid(getRequest('page_pid'));
$oPageParent=$this->Page_GetPageById(getRequest('page_pid'));
$oPageParent=$this->PluginPage_Page_GetPageById(getRequest('page_pid'));
$oPageEdit->setUrlFull($oPageParent->getUrlFull().'/'.getRequest('page_url'));
}
$oPageEdit->setSeoDescription(getRequest('page_seo_description'));
@ -193,8 +189,8 @@ class ActionPage extends Action {
/**
* Обновляем страницу
*/
if ($this->Page_UpdatePage($oPageEdit)) {
$this->Page_RebuildUrlFull($oPageEdit);
if ($this->PluginPage_Page_UpdatePage($oPageEdit)) {
$this->PluginPage_Page_RebuildUrlFull($oPageEdit);
$this->Message_AddNotice($this->Lang_Get('page_edit_submit_save_ok'));
$this->SetParam(0,null);
$this->SetParam(1,null);
@ -224,7 +220,7 @@ class ActionPage extends Action {
$oPage->setPid(null);
} else {
$oPage->setPid(getRequest('page_pid'));
$oPageParent=$this->Page_GetPageById(getRequest('page_pid'));
$oPageParent=$this->PluginPage_Page_GetPageById(getRequest('page_pid'));
$oPage->setUrlFull($oPageParent->getUrlFull().'/'.getRequest('page_url'));
}
$oPage->setSeoDescription(getRequest('page_seo_description'));
@ -235,7 +231,7 @@ class ActionPage extends Action {
/**
* Добавляем страницу
*/
if ($this->Page_AddPage($oPage)) {
if ($this->PluginPage_Page_AddPage($oPage)) {
$this->Message_AddNotice($this->Lang_Get('page_create_submit_save_ok'));
$this->SetParam(0,null);
} else {
@ -284,7 +280,7 @@ class ActionPage extends Action {
/**
* Проверяем страницу в которую хотим вложить
*/
if (getRequest('page_pid')!=0 and !($oPageParent=$this->Page_GetPageById(getRequest('page_pid')))) {
if (getRequest('page_pid')!=0 and !($oPageParent=$this->PluginPage_Page_GetPageById(getRequest('page_pid')))) {
$this->Message_AddError($this->Lang_Get('page_create_parent_page_error'),$this->Lang_Get('error'));
$bOk=false;
}
@ -296,4 +292,4 @@ class ActionPage extends Action {
return $bOk;
}
}
?>
?>

View file

@ -22,7 +22,7 @@ require_once('mapper/Page.mapper.class.php');
* Модуль статических страниц
*
*/
class LsPage extends Module {
class PluginPage_Page extends Module {
protected $oMapper;
protected $aRebuildIds=array();
@ -31,7 +31,7 @@ class LsPage extends Module {
*
*/
public function Init() {
$this->oMapper=new Mapper_Page($this->Database_GetConnect());
$this->oMapper=new PluginPage_Mapper_Page($this->Database_GetConnect());
}
/**
* Добавляет страницу
@ -39,7 +39,7 @@ class LsPage extends Module {
* @param PageEntity_Page $oPage
* @return unknown
*/
public function AddPage(PageEntity_Page $oPage) {
public function AddPage(PluginPage_PageEntity_Page $oPage) {
if ($sId=$this->oMapper->AddPage($oPage)) {
$oPage->setId($sId);
//чистим зависимые кеши
@ -54,7 +54,7 @@ class LsPage extends Module {
* @param PageEntity_Page $oPage
* @return unknown
*/
public function UpdatePage(PageEntity_Page $oPage) {
public function UpdatePage(PluginPage_PageEntity_Page $oPage) {
if ($this->oMapper->UpdatePage($oPage)) {
//чистим зависимые кеши
$this->Cache_Clean(Zend_Cache::CLEANING_MODE_MATCHING_TAG,array('page_change',"page_change_{$oPage->getId()}","page_change_urlfull_{$oPage->getUrlFull()}"));
@ -118,7 +118,7 @@ class LsPage extends Module {
$aTemp=$aPage;
$aTemp['level']=$iLevel;
unset($aTemp['childNodes']);
$aResultPages[]=Engine::GetEntity('Page',$aTemp);
$aResultPages[]=Engine::GetEntity('PluginPage_Page',$aTemp);
if (isset($aPage['childNodes']) and count($aPage['childNodes'])>0) {
$iLevel++;
$this->BuildPagesRecursive($aPage['childNodes'],false);

View file

@ -15,7 +15,7 @@
---------------------------------------------------------
*/
class PageEntity_Page extends Entity
class PluginPage_PageEntity_Page extends Entity
{
public function getId() {
return $this->_aData['page_id'];
@ -91,6 +91,5 @@ class PageEntity_Page extends Entity
public function setActive($data) {
$this->_aData['page_active']=$data;
}
}
?>

View file

@ -15,10 +15,10 @@
---------------------------------------------------------
*/
class Mapper_Page extends Mapper {
class PluginPage_Mapper_Page extends Mapper {
public function AddPage(PageEntity_Page $oPage) {
$sql = "INSERT INTO ".Config::Get('db.table.page')."
public function AddPage(PluginPage_PageEntity_Page $oPage) {
$sql = "INSERT INTO ".Config::Get('plugin.page.table.page')."
(page_pid,
page_url,
page_url_full,
@ -38,8 +38,8 @@ class Mapper_Page extends Mapper {
return false;
}
public function UpdatePage(PageEntity_Page $oPage) {
$sql = "UPDATE ".Config::Get('db.table.page')."
public function UpdatePage(PluginPage_PageEntity_Page $oPage) {
$sql = "UPDATE ".Config::Get('plugin.page.table.page')."
SET page_pid = ? ,
page_url = ? ,
page_url_full = ? ,
@ -59,7 +59,7 @@ class Mapper_Page extends Mapper {
}
public function SetPagesPidToNull() {
$sql = "UPDATE ".Config::Get('db.table.page')."
$sql = "UPDATE ".Config::Get('plugin.page.table.page')."
SET
page_pid = null,
page_url_full = page_url
@ -72,23 +72,23 @@ class Mapper_Page extends Mapper {
}
public function GetPageByUrlFull($sUrlFull,$iActive) {
$sql = "SELECT * FROM ".Config::Get('db.table.page')." WHERE page_url_full = ? and page_active = ?d ";
$sql = "SELECT * FROM ".Config::Get('plugin.page.table.page')." WHERE page_url_full = ? and page_active = ?d ";
if ($aRow=$this->oDb->selectRow($sql,$sUrlFull,$iActive)) {
return Engine::GetEntity('Page',$aRow);
return Engine::GetEntity('PluginPage_Page',$aRow);
}
return null;
}
public function GetPageById($sId) {
$sql = "SELECT * FROM ".Config::Get('db.table.page')." WHERE page_id = ? ";
$sql = "SELECT * FROM ".Config::Get('plugin.page.table.page')." WHERE page_id = ? ";
if ($aRow=$this->oDb->selectRow($sql,$sId)) {
return Engine::GetEntity('Page',$aRow);
return Engine::GetEntity('PluginPage_Page',$aRow);
}
return null;
}
public function deletePageById($sId) {
$sql = "DELETE FROM ".Config::Get('db.table.page')." WHERE page_id = ? ";
$sql = "DELETE FROM ".Config::Get('plugin.page.table.page')." WHERE page_id = ? ";
if ($aRow=$this->oDb->selectRow($sql,$sId)) {
return true;
}
@ -101,7 +101,7 @@ class Mapper_Page extends Mapper {
page_id as ARRAY_KEY,
page_pid as PARENT_KEY
FROM
".Config::Get('db.table.page')."
".Config::Get('plugin.page.table.page')."
ORDER by page_title asc;
";
if ($aRows=$this->oDb->select($sql)) {
@ -111,7 +111,7 @@ class Mapper_Page extends Mapper {
}
public function GetCountPage() {
$sql = "SELECT count(*) as count FROM ".Config::Get('db.table.page')." ";
$sql = "SELECT count(*) as count FROM ".Config::Get('plugin.page.table.page')." ";
if ($aRow=$this->oDb->selectRow($sql)) {
return $aRow['count'];
}
@ -122,17 +122,16 @@ class Mapper_Page extends Mapper {
$sql = "SELECT
*
FROM
".Config::Get('db.table.page')."
".Config::Get('plugin.page.table.page')."
WHERE
page_pid = ? ";
$aResult=array();
if ($aRows=$this->oDb->select($sql,$sPid)) {
foreach ($aRows as $aRow) {
$aResult[]=Engine::GetEntity('Page',$aRow);
$aResult[]=Engine::GetEntity('PluginPage_Page',$aRow);
}
}
return $aResult;
}
}
?>

View file

@ -14,10 +14,9 @@
*
---------------------------------------------------------
*/
$config['table']['page'] = '___db.table.prefix___page';
/**
* Конфиг модуля "page" - управление статическими страницами
*/
Config::Set('router.page.page', 'PluginPage_ActionPage');
return $config;
?>

26
plugins/page/plugin.xml Normal file
View file

@ -0,0 +1,26 @@
<?xml version="1.0" encoding="UTF-8"?>
<plugin>
<name>
<lang name="default">Static page</lang>
</name>
<author>
<lang name="default">LiveStreet Developers Team</lang>
</author>
<homepage>http://livestreet.ru</homepage>
<version>1.0.0</version>
<requires>
<livestreet>0.4.0</livestreet>
<plugins>
</plugins>
</requires>
<description>
<lang name="default">Managing static pages</lang>
<lang name="russian">Управление статическими страницами.</lang>
</description>
<delegate>
<module></module>
<action></action>
<template></template>
<entity></entity>
</delegate>
</plugin>

View file

@ -16,7 +16,7 @@
*/
/**
* Русский языковой файл для модуля "page"
* Русский языковой файл для плагина "Статические страницы"
*/
return array(
/**

View file

@ -7,10 +7,10 @@
<br>
{if $aParams.0=='new'}
<h4>{$aLang.page_create}</h4>
{include file='actions/ActionPage/add.tpl'}
{include file="$sTemplatePathPlugin/actions/ActionPage/add.tpl"}
{elseif $aParams.0=='edit'}
<h4>{$aLang.page_edit} «{$oPageEdit->getTitle()}»</h4>
{include file='actions/ActionPage/add.tpl'}
{include file="$sTemplatePathPlugin/actions/ActionPage/add.tpl"}
{else}
<a href="{router page='page'}admin/new/">{$aLang.page_new}</a>
{/if}