forked from modxcms/revolution
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Jens Külzer
authored and
Ivan Klimchuk
committed
Aug 23, 2018
1 parent
abfc454
commit 2fe310a
Showing
9 changed files
with
2,405 additions
and
0 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.trashrow { | ||
background-color: silver !important; | ||
} |
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 |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php | ||
/** | ||
* Trash English lexicon topic | ||
* | ||
* @language en | ||
* @package modx | ||
* @subpackage lexicon | ||
*/ | ||
|
||
$_lang['trash_menu'] = 'Trash'; | ||
$_lang['trash_menu_desc'] = 'Manage deleted resources.'; | ||
|
||
$_lang['trash.page_title'] = 'Trash - Deleted Resources Manager'; | ||
|
||
$_lang['trash.tab_title'] = 'Trash Bin'; | ||
$_lang['trash.intro_msg'] = ' | ||
Manage the deleted resources here. <br> | ||
<i>Before you restore any resource, check the publishing state</i> - you can unpublish resources here directly from the grid with a double-click on the published-cell of the resource.'; | ||
|
||
$_lang['trash.manage_recycle_bin_tooltip'] = "Go to the trash bin manager"; | ||
|
||
$_lang['trash.deletedon_title'] = 'Deleted on'; | ||
$_lang['trash.deletedbyUser_title'] = 'Deleted by User'; | ||
|
||
$_lang['trash.context_title'] = 'Context'; | ||
|
||
$_lang['trash.purge_all'] = 'Purge all'; | ||
$_lang['trash.restore_all'] = 'Restore all'; | ||
|
||
$_lang['trash.selected_purge'] = 'Purge selected resources'; | ||
$_lang['trash.selected_restore'] = 'Restore selected resources'; | ||
|
||
$_lang['trash.purge'] = 'Purge resource'; | ||
$_lang['trash.purge_confirm_title'] = 'Purge resource(s)?'; | ||
$_lang['trash.purge_confirm_message'] = 'Do you really want to finally delete the following resource(s)? This cannot be undone.<hr/>[[+list]]'; | ||
$_lang['trash.purgeall_confirm_message'] = 'Do you really want to finally delete the listed [[+count]] resource(s)? This cannot be undone, and affects also resources on further pages not shown here.'; | ||
$_lang['trash.purgeall_empty_status'] = '[[+count]] resources have been finally deleted.'; | ||
|
||
$_lang['trash.purge_err_delete'] = '[[+count]] resources have not been purged due to errors: [[+list]]'; | ||
$_lang['trash.purge_err_nothing'] = 'Nothing was purged, no errors occured.'; | ||
$_lang['trash.purge_success_delete'] = '[[+count]] resources successfully purged permanently.'; | ||
|
||
$_lang['trash.restore'] = 'Restore resource'; | ||
$_lang['trash.restore_confirm_title'] = 'Restore resource(s)?'; | ||
$_lang['trash.restore_confirm_message'] = 'Do you want to restore the following resource(s)?<hr/>[[+list]]'; | ||
$_lang['trash.restore_confirm_message_with_publish'] = 'Do you want to restore the following resource(s)?<br/><br/><strong>Be aware that this will re-publish previously published resources!</strong><hr/>[[+list]]'; |
139 changes: 139 additions & 0 deletions
139
core/model/modx/processors/resource/trash/getlist.class.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 |
---|---|---|
@@ -0,0 +1,139 @@ | ||
<?php | ||
|
||
/** | ||
* Gets a list of resources. | ||
* | ||
* @param integer $start (optional) The record to start at. Defaults to 0. | ||
* @param integer $limit (optional) The number of records to limit to. Defaults | ||
* to 10. | ||
* @param string $sort (optional) The column to sort by. Defaults to name. | ||
* @param string $dir (optional) The direction of the sort. Defaults to ASC. | ||
* | ||
* @return array An array of modResources | ||
* @package modx | ||
* @subpackage processors.resource | ||
*/ | ||
class modResourceTrashGetListProcessor extends modObjectGetListProcessor { | ||
|
||
public $classKey = 'modResource'; | ||
public $languageTopics = array('resource'); | ||
public $defaultSortField = 'pagetitle'; | ||
public $permission = 'view'; | ||
|
||
/** | ||
* @param xPDOQuery $c | ||
* | ||
* @return xPDOQuery | ||
*/ | ||
public function prepareQueryBeforeCount(xPDOQuery $c) { | ||
$query = $this->getProperty('query'); | ||
$c->select([ | ||
$this->modx->getSelectColumns('modResource', 'modResource', 'modResource_'), | ||
'modResource_deletedbyUser' => 'User.username', | ||
'modResource_context_name' => 'Context.name', | ||
]); | ||
$c->leftJoin('modUser', 'User', 'modResource.deletedby = User.id'); | ||
$c->leftJoin('modContext', 'Context', 'modResource.context_key = Context.key'); | ||
|
||
// TODO add only resources if we have the save permission here (on the context!!) | ||
// we need the following permissions: | ||
// undelete_document - to restore the document | ||
// delete_document - thats perhaps not necessary, because all documents are already deleted | ||
// but we need the purge_deleted permission - for every single file | ||
|
||
if (!empty($query)) { | ||
$c->where(array('modResource.pagetitle:LIKE' => '%' . $query . '%')); | ||
$c->orCondition(array('modResource.longtitle:LIKE' => '%' . $query . '%')); | ||
} | ||
$c->where(array( | ||
'modResource.deleted' => true, | ||
)); | ||
// $c->prepare(); | ||
// $this->modx->log(1,"Query: ".$c->toSQL()); | ||
return $c; | ||
} | ||
|
||
public function prepareRow(xPDOObject $object) { | ||
// quick exit if we don't have access to the context | ||
// this is a strange workaround: obviously we can access the resources even if we don't have access to the context! Check that | ||
// TODO check if that is the same for resource groups | ||
$context = $this->modx->getContext($object->get('context_key')); | ||
if (!$context) return []; | ||
|
||
$charset = $this->modx->getOption('modx_charset', null, 'UTF-8'); | ||
$objectArray = $object->toArray(); | ||
$objectArray['pagetitle'] = htmlentities($objectArray['pagetitle'], ENT_COMPAT, $charset); | ||
|
||
// to enable a better detection of the resource's location, we also construct the | ||
// parent-child path to the resource | ||
|
||
$parents = array(); | ||
$parent = $objectArray['parent']; | ||
|
||
while ($parent!=0) { | ||
$parents[] = $this->modx->getObject('modResource', $parent); | ||
$parent = end($parents)->get('parent'); | ||
} | ||
|
||
$parentPath = ""; | ||
foreach ($parents as $parent) { | ||
$parentPath = $parent->get('pagetitle') . " (".$parent->get('id') . ") > " . $parentPath; | ||
} | ||
$objectArray['parentPath'] = "[" . $objectArray['context_key'] . "] " . $parentPath; | ||
|
||
// TODO implement permission checks for every resource and return only resources user is allowed to see | ||
|
||
// show the permissions for the context | ||
$canView = $this->modx->hasPermission('view'); | ||
$canPurge = $this->modx->hasPermission('purge_deleted'); | ||
$canUndelete = $this->modx->hasPermission('undelete_document'); | ||
$canPublish = $this->modx->hasPermission('publish'); | ||
$canSave = $this->modx->hasPermission('save'); | ||
$canEdit = $this->modx->hasPermission('edit'); | ||
$canList = $this->modx->hasPermission('list'); | ||
$canLoad = $this->modx->hasPermission('load'); | ||
|
||
$objectArray['iconCls'] = $this->modx->getOption('mgr_source_icon', null, 'icon-folder-open-o'); | ||
|
||
$cls = array(); | ||
$cls[] = 'restore'; | ||
$cls[] = 'purge'; | ||
$cls[] = 'undelete_document'; | ||
|
||
$cls = array(); | ||
if ($object->checkPolicy('purge_deleted') && $canSave && $canEdit && $canPurge) { | ||
$cls[] = 'trashpurge'; | ||
} | ||
if ($object->checkPolicy('undelete_document') && $canSave && $canEdit) { | ||
$cls[] = 'trashundelete'; | ||
} | ||
if ($object->checkPolicy('save') && $canSave && $canEdit) { | ||
$cls[] = 'trashsave'; | ||
} | ||
if ($object->checkPolicy('edit') && $canSave && $canEdit) { | ||
$cls[] = 'trashedit'; | ||
} | ||
$cls[] = 'trashrow'; | ||
|
||
|
||
$debug = array('id'=>$object->get('id'), 'pagetitle'=>$object->get('pagetitle')); | ||
$this->modx->log(1,"array: ".print_r($debug,true)); | ||
$this->modx->log(1,"Can list: ".$canList.", list:".$object->checkPolicy('list')); | ||
$this->modx->log(1,"Can load: ".$canLoad.", load: ".$object->checkPolicy('load')); | ||
$this->modx->log(1,"Can view: ".$canView.", view_doc:".$object->checkPolicy('view_document').", view: ".$object->checkPolicy('view')); | ||
$this->modx->log(1,"Can save: ".$canSave.", save_doc:".$object->checkPolicy('save_document').", save: ".$object->checkPolicy('save')); | ||
$this->modx->log(1,"Can edit: ".$canEdit.", edit_doco:".$object->checkPolicy('edit_document').", edit: ".$object->checkPolicy('edit')); | ||
$this->modx->log(1,"Can purge: ".$canPurge.", purge_deleted:".$object->checkPolicy('purge_deleted')); | ||
|
||
$this->modx->log(1,"context: ".$object->get('context_key')); | ||
|
||
$objectArray['cls'] = implode(' ', $cls); | ||
|
||
return $objectArray; | ||
|
||
|
||
} | ||
} | ||
|
||
return 'modResourceTrashGetListProcessor'; | ||
|
Oops, something went wrong.