forked from anahitasocial/anahita
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
make revision listing, add & edit pages to show 404 error (instead of empty page or 500 error); fix view revision header margin;
- Loading branch information
Showing
9 changed files
with
233 additions
and
294 deletions.
There are no files selected for viewing
103 changes: 54 additions & 49 deletions
103
packages/Pages/src/site/components/com_pages/controllers/revision.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,74 +1,79 @@ | ||
<?php | ||
|
||
/** | ||
* LICENSE: ##LICENSE## | ||
* | ||
* @category Anahita | ||
* @package Com_Pages | ||
* @subpackage Controller | ||
* @author Arash Sanieyan <ash@anahitapolis.com> | ||
* @author Rastin Mehr <rastin@anahitapolis.com> | ||
* @copyright 2008 - 2010 rmdStudio Inc./Peerglobe Technology Inc | ||
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl-3.0.html> | ||
* @version SVN: $Id: resource.php 11985 2012-01-12 10:53:20Z asanieyan $ | ||
* @link http://www.anahitapolis.com | ||
*/ | ||
|
||
/** | ||
* Revision Controller | ||
* | ||
* | ||
* @category Anahita | ||
* @package Com_pages | ||
* @subpackage Controller | ||
* @author Arash Sanieyan <ash@anahitapolis.com> | ||
* @author Rastin Mehr <rastin@anahitapolis.com> | ||
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl-3.0.html> | ||
* @link http://www.anahitapolis.com | ||
* @copyright 2008 - 2010 rmdStudio Inc./Peerglobe Technology Inc | ||
*/ | ||
class ComPagesControllerRevision extends ComMediumControllerDefault | ||
{ | ||
/** | ||
* Initializes the options for the object | ||
* | ||
* | ||
* Called from {@link __construct()} as a first step of object instantiation. | ||
* | ||
* @param object An optional KConfig object with configuration options. | ||
* @return void | ||
* | ||
* @param object An optional KConfig object with configuration options. | ||
* @return void | ||
*/ | ||
protected function _initialize(KConfig $config) | ||
{ | ||
$config->append(array( | ||
'behaviors' => array('parentable') | ||
)); | ||
|
||
parent::_initialize($config); | ||
} | ||
|
||
/** | ||
* {@inheritdoc}} | ||
*/ | ||
protected function _actionBrowse($context) | ||
{ | ||
// revision listing is not allowed | ||
throw new KHttpException('Not Found', KHttpResponse::NOT_FOUND); | ||
} | ||
|
||
/** | ||
* {@inheritdoc}} | ||
*/ | ||
protected function _actionRead($context) | ||
{ | ||
if ($context->request->layout) { | ||
// only default revision view is allowed (i.e. forbid edit/add form access) | ||
throw new KHttpException('Not Found', KHttpResponse::NOT_FOUND); | ||
} | ||
|
||
return parent::_actionRead($context); | ||
} | ||
|
||
/** | ||
* Restores a page back to a revision | ||
* | ||
* @param KCommandContext $context Context paramter | ||
* @return void | ||
*/ | ||
protected function _actionRestore($context) | ||
{ | ||
$revision = $this->getItem(); | ||
$page = $revision->page; | ||
$page->restore($revision); | ||
|
||
/** | ||
* Restores a page back to a revision | ||
* | ||
* @param KCommandContext $context Context paramter | ||
* | ||
* @return void | ||
*/ | ||
protected function _actionRestore($context) | ||
{ | ||
$revision = $this->getItem(); | ||
$page = $revision->page; | ||
$page->restore($revision); | ||
|
||
$msg = JText::sprintf('COM-PAGES-PAGE-REVISIONS-RESTORATION-CONFIRMATION', $revision->revisionNum); | ||
$context->response->setRedirect($page->getURL().'&layout=edit', $msg); | ||
} | ||
|
||
/** | ||
* Prevents deletion of a revision | ||
* | ||
* @return boolean | ||
*/ | ||
public function canDelete() | ||
{ | ||
return false; | ||
} | ||
} | ||
$msg = JText::sprintf('COM-PAGES-PAGE-REVISIONS-RESTORATION-CONFIRMATION', $revision->revisionNum); | ||
$context->response->setRedirect($page->getURL().'&layout=edit', $msg); | ||
} | ||
|
||
/** | ||
* Prevents deletion of a revision | ||
* | ||
* @return boolean | ||
*/ | ||
public function canDelete() | ||
{ | ||
return false; | ||
} | ||
} |
215 changes: 98 additions & 117 deletions
215
packages/Pages/src/site/components/com_pages/domains/entities/page.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,135 +1,116 @@ | ||
<?php | ||
|
||
/** | ||
* LICENSE: ##LICENSE## | ||
* | ||
* @category Anahita | ||
* @package Com_Pages | ||
* @subpackage Domain_Entity | ||
* @author Arash Sanieyan <ash@anahitapolis.com> | ||
* @author Rastin Mehr <rastin@anahitapolis.com> | ||
* @copyright 2008 - 2010 rmdStudio Inc./Peerglobe Technology Inc | ||
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl-3.0.html> | ||
* @version SVN: $Id: resource.php 11985 2012-01-12 10:53:20Z asanieyan $ | ||
* @link http://www.anahitapolis.com | ||
*/ | ||
|
||
/** | ||
* Page Entity | ||
* | ||
* | ||
* @category Anahita | ||
* @package Com_pages | ||
* @subpackage Domain_Entity | ||
* @author Arash Sanieyan <ash@anahitapolis.com> | ||
* @author Rastin Mehr <rastin@anahitapolis.com> | ||
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl-3.0.html> | ||
* @link http://www.anahitapolis.com | ||
* @copyright 2008 - 2010 rmdStudio Inc./Peerglobe Technology Inc | ||
*/ | ||
class ComPagesDomainEntityPage extends ComMediumDomainEntityMedium | ||
{ | ||
/** | ||
* Initializes the default configuration for the object | ||
* | ||
* Called from {@link __construct()} as a first step of object instantiation. | ||
* | ||
* @param KConfig $config An optional KConfig object with configuration options. | ||
* | ||
* @return void | ||
*/ | ||
protected function _initialize(KConfig $config) | ||
{ | ||
$config->append(array( | ||
'behaviors' => array( | ||
'enableable' | ||
), | ||
|
||
'attributes' => array( | ||
'name' => array('required'=>true), | ||
'excerpt' => array('required'=>true,'format'=>'string') | ||
), | ||
|
||
'relationships' => array( | ||
'revisions' | ||
), | ||
'aliases' => array( | ||
'published' => 'enabled', | ||
'title' => 'name' | ||
) | ||
)); | ||
|
||
{ | ||
/** | ||
* Initializes the default configuration for the object | ||
* | ||
* Called from {@link __construct()} as a first step of object instantiation. | ||
* | ||
* @param KConfig $config An optional KConfig object with configuration options. | ||
* @return void | ||
*/ | ||
protected function _initialize(KConfig $config) | ||
{ | ||
$config->append(array( | ||
'behaviors' => array( | ||
'enableable' | ||
), | ||
|
||
'attributes' => array( | ||
'name' => array('required' => true), | ||
'excerpt' => array('required' => true, 'format' => 'string') | ||
), | ||
|
||
'relationships' => array( | ||
'revisions' | ||
), | ||
'aliases' => array( | ||
'published' => 'enabled', | ||
'title' => 'name', | ||
) | ||
)); | ||
|
||
$config->append(array( | ||
'behaviors' => array( | ||
'modifiable' => array( | ||
'modifiable_properties' => array('excerpt','name','body') | ||
'modifiable_properties' => array('excerpt', 'name', 'body') | ||
), | ||
//h2-h6 not allowed in the comments | ||
'commentable' => array('comment'=>array('format'=>'com://site/medium.filter.post')) | ||
) | ||
'commentable' => array('comment' => array('format' => 'com://site/medium.filter.post')) | ||
) | ||
)); | ||
|
||
parent::_initialize($config); | ||
} | ||
|
||
/** | ||
* Creates a new revision before updating | ||
* | ||
* @return void | ||
*/ | ||
protected function _beforeEntityUpdate(KCommandContext $context) | ||
{ | ||
$modifications = $this->getModifiedData(); | ||
|
||
if ( isset($this->__restored) ) | ||
return; | ||
|
||
if ( $modifications->name || $modifications->body || $modifications->excerpt ) | ||
{ | ||
$revision = $this->addNewRevision(); | ||
|
||
foreach($modifications as $property => $change) { | ||
$revision->$property = $change->old; | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* Restore a page back to one of it's revision num | ||
* | ||
* @param int $revision | ||
* @return void | ||
*/ | ||
public function restore($revision) | ||
{ | ||
$revision = $this->revisions->find(array('revisionNum'=>$revision->revisionNum)); | ||
|
||
if ( $revision ) | ||
{ | ||
$this->__restored = true; | ||
$this->setData(array( | ||
'name' => $revision->title, | ||
'body' => $revision->description, | ||
'exceprt' => $revision->excerpt | ||
), AnDomain::ACCESS_PROTECTED); | ||
} | ||
} | ||
|
||
/** | ||
* Creates new revision | ||
* | ||
* @return ComPagesDomainEntityRevision | ||
*/ | ||
public function addNewRevision() | ||
{ | ||
return $this->revisions->addNew(array( | ||
'component' => $this->component, | ||
'author' => get_viewer(), | ||
'owner' => $this->owner, | ||
'title' => $this->title, | ||
'description' => $this->description, | ||
'excerpt' => $this->excerpt, | ||
'revisionNum' => (int)$this->revisions->fetchValue('MAX(@col(revisionNum))') + 1 | ||
)); | ||
} | ||
|
||
//end class | ||
} | ||
parent::_initialize($config); | ||
} | ||
|
||
/** | ||
* Creates a new revision before updating | ||
* | ||
* @return void | ||
*/ | ||
protected function _beforeEntityUpdate(KCommandContext $context) | ||
{ | ||
$modifications = $this->getModifiedData(); | ||
|
||
if (isset($this->__restored)) { | ||
return; | ||
} | ||
|
||
if ($modifications->name || $modifications->body || $modifications->excerpt) { | ||
$revision = $this->addNewRevision(); | ||
|
||
foreach ($modifications as $property => $change) { | ||
$revision->$property = $change->old; | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* Restore a page back to one of it's revision num | ||
* | ||
* @param int $revision | ||
* @return void | ||
*/ | ||
public function restore($revision) | ||
{ | ||
$revision = $this->revisions->find(array('revisionNum' => $revision->revisionNum)); | ||
|
||
if ($revision) { | ||
$this->__restored = true; | ||
$this->setData(array( | ||
'name' => $revision->title, | ||
'body' => $revision->description, | ||
'exceprt' => $revision->excerpt | ||
), AnDomain::ACCESS_PROTECTED); | ||
} | ||
} | ||
|
||
/** | ||
* Creates new revision | ||
* | ||
* @return ComPagesDomainEntityRevision | ||
*/ | ||
public function addNewRevision() | ||
{ | ||
return $this->revisions->addNew(array( | ||
'component' => $this->component, | ||
'author' => get_viewer(), | ||
'owner' => $this->owner, | ||
'title' => $this->title, | ||
'description' => $this->description, | ||
'excerpt' => $this->excerpt, | ||
'revisionNum' => (int)$this->revisions->fetchValue('MAX(@col(revisionNum))') + 1, | ||
)); | ||
} | ||
} |
Oops, something went wrong.