Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions core/lexicon/en/resource.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@
$_lang['resource_err_nfs'] = 'Resource with ID [[+id]] not found';
$_lang['resource_err_ns'] = 'Resource not specified.';
$_lang['resource_err_own_parent'] = 'The resource cannot be its own parent.';
$_lang['resource_err_preview_no_zero_id'] = 'This Resource (id = [[+source_id]]) is a link to another Resource, but its preview URL can not be created because the target Resource id ([[+target_id]]) is 0 or begins with 0.';
$_lang['resource_err_preview_self_deleted'] = 'Can not create a preview URL for this Resource (id = [[+target_id]]) because it has been marked as deleted.';
$_lang['resource_err_preview_self_not_found'] = 'Can not create a preview URL for this Resource (id = [[+target_id]]) because it does not exist.';
$_lang['resource_err_preview_target_deleted'] = 'This Resource (id = [[+source_id]]) is a link to another Resource, but its preview URL can not be created because the target Resource (id = [[+target_id]]) has been marked as deleted.';
$_lang['resource_err_preview_target_not_found'] = 'This Resource (id = [[+source_id]]) is a link to another Resource, but its preview URL can not be created because the target Resource (id = [[+target_id]]) does not exist.';
$_lang['resource_err_publish'] = 'An error occurred while trying to publish the resource.';
$_lang['resource_err_new_parent_nf'] = 'New parent resource with id [[+id]] not found.';
$_lang['resource_err_remove'] = 'An error occurred while trying to delete the resource.';
Expand All @@ -86,6 +91,7 @@
$_lang['resource_err_unpublish_errorpage_dates'] = 'The resource is linked to the error_page variable and cannot have publish or unpublish dates set!';
$_lang['resource_err_unpublish_siteunavailable'] = 'The resource is linked to the site_unavailable_page variable and cannot be unpublished!';
$_lang['resource_err_unpublish_siteunavailable_dates'] = 'The resource is linked to the site_unavailable_page variable and cannot have publish or unpublish dates set!';
$_lang['resource_err_weblink_invalid'] = 'The weblink content “[[+content]]” provided in Resource id [[+id]] is invalid.';
$_lang['resource_err_weblink_target_nf'] = 'You cannot set a weblink to a resource that does not exist.';
$_lang['resource_err_weblink_target_self'] = 'You cannot set a weblink to itself.';
$_lang['resource_folder'] = 'Container';
Expand Down
16 changes: 12 additions & 4 deletions core/src/Revolution/Processors/Resource/Delete.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/*
* This file is part of MODX Revolution.
*
Expand Down Expand Up @@ -49,13 +50,19 @@ public function getLanguageTopics(): array
public function initialize()
{
$id = $this->getProperty('id', false);
if (empty($id)) return $this->modx->lexicon('resource_err_ns');
if (empty($id)) {
return $this->modx->lexicon('resource_err_ns');
}
$this->resource = $this->modx->getObject(modResource::class, $id);
if (empty($this->resource)) return $this->modx->lexicon('resource_err_nfs', ['id' => $id]);
if (empty($this->resource)) {
return $this->modx->lexicon('resource_err_nfs', ['id' => $id]);
}

/* validate resource can be deleted */
if (!$this->checkActionPermission($this->resource->get('class_key'), 'delete')
|| !$this->resource->checkPolicy(['save' => true, 'delete' => true])) {
if (
!$this->checkActionPermission($this->resource->get('class_key'), 'delete')
|| !$this->resource->checkPolicy(['save' => true, 'delete' => true])
) {
return $this->modx->lexicon('permission_denied');
}
$this->deletedTime = time();
Expand Down Expand Up @@ -121,6 +128,7 @@ public function process()
]);

$outputArray['deletedCount'] = $deletedCount;
$outputArray['preview_url'] = $this->resource->getPreviewUrl();

return $this->success('', $outputArray);
}
Expand Down
63 changes: 41 additions & 22 deletions core/src/Revolution/Processors/Resource/GetNodes.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/*
* This file is part of MODX Revolution.
*
Expand Down Expand Up @@ -89,7 +90,6 @@ public function process()
if ($this->getProperty('stringLiterals', false)) {
return $this->modx->toJSON($this->items);
}

return $this->toJSON($this->items);
} catch (xPDOException $e) {
$this->modx->log(modX::LOG_LEVEL_ERROR, 'Failed to encode JSON. ' . $e->getMessage());
Expand Down Expand Up @@ -129,7 +129,6 @@ public function prepare()
'new_weblink' => $this->modx->hasPermission('new_weblink') ? 'pnew pnew_modWebLink' : '',
'new_document' => $this->modx->hasPermission('new_document') ? 'pnew pnew_modDocument' : '',
];

}

/**
Expand Down Expand Up @@ -414,26 +413,52 @@ public function prepareResourceNode(modResource $resource)

$class = array_merge($class, $resource->getStatusClasses());

if (!empty($this->permissions['save_document'])) $class[] = $this->permissions['save_document'];
if (!empty($this->permissions['view_document'])) $class[] = $this->permissions['view_document'];
if (!empty($this->permissions['edit_document'])) $class[] = $this->permissions['edit_document'];
if (!empty($this->permissions['save_document'])) {
$class[] = $this->permissions['save_document'];
}
if (!empty($this->permissions['view_document'])) {
$class[] = $this->permissions['view_document'];
}
if (!empty($this->permissions['edit_document'])) {
$class[] = $this->permissions['edit_document'];
}
if (!empty($this->permissions['resource_duplicate'])) {
if ($resource->parent != $this->defaultRootId || $this->modx->hasPermission('new_document_in_root')) {
$class[] = $this->permissions['resource_duplicate'];
}
}
if ($resource->allowChildrenResources && !$resource->deleted) {
if (!empty($this->permissions['new_document'])) $class[] = $this->permissions['new_document'];
if (!empty($this->permissions['new_symlink'])) $class[] = $this->permissions['new_symlink'];
if (!empty($this->permissions['new_weblink'])) $class[] = $this->permissions['new_weblink'];
if (!empty($this->permissions['new_static_resource'])) $class[] = $this->permissions['new_static_resource'];
if (!empty($this->permissions['resource_quick_create'])) $class[] = $this->permissions['resource_quick_create'];
if (!empty($this->permissions['new_document'])) {
$class[] = $this->permissions['new_document'];
}
if (!empty($this->permissions['new_symlink'])) {
$class[] = $this->permissions['new_symlink'];
}
if (!empty($this->permissions['new_weblink'])) {
$class[] = $this->permissions['new_weblink'];
}
if (!empty($this->permissions['new_static_resource'])) {
$class[] = $this->permissions['new_static_resource'];
}
if (!empty($this->permissions['resource_quick_create'])) {
$class[] = $this->permissions['resource_quick_create'];
}
}
if (!empty($this->permissions['resource_quick_update'])) {
$class[] = $this->permissions['resource_quick_update'];
}
if (!empty($this->permissions['delete_document'])) {
$class[] = $this->permissions['delete_document'];
}
if (!empty($this->permissions['undelete_document'])) {
$class[] = $this->permissions['undelete_document'];
}
if (!empty($this->permissions['publish_document'])) {
$class[] = $this->permissions['publish_document'];
}
if (!empty($this->permissions['unpublish_document'])) {
$class[] = $this->permissions['unpublish_document'];
}
if (!empty($this->permissions['resource_quick_update'])) $class[] = $this->permissions['resource_quick_update'];
if (!empty($this->permissions['delete_document'])) $class[] = $this->permissions['delete_document'];
if (!empty($this->permissions['undelete_document'])) $class[] = $this->permissions['undelete_document'];
if (!empty($this->permissions['publish_document'])) $class[] = $this->permissions['publish_document'];
if (!empty($this->permissions['unpublish_document'])) $class[] = $this->permissions['unpublish_document'];

$active = false;
if ($this->getProperty('currentResource') == $resource->id && $this->getProperty('currentAction') === 'resource/update') {
Expand Down Expand Up @@ -469,12 +494,6 @@ public function prepareResourceNode(modResource $resource)
// Add the ID to the item text if the user has the permission
$idNote = $this->modx->hasPermission('tree_show_resource_ids') ? ' <span dir="ltr">(' . $resource->id . ')</span>' : '';

// Used in the preview_url, if sessions are disabled on the resource context we add an extra url param
$sessionEnabled = '';
if ($ctxSetting = $this->modx->getObject(modContextSetting::class, ['context_key' => $resource->get('context_key'), 'key' => 'session_enabled'])) {
$sessionEnabled = $ctxSetting->get('value') == 0 ? ['preview' => 'true'] : '';
}

$text = $resource->get($nodeField);
if (empty($text)) {
$text = $resource->get($nodeFieldFallback);
Expand All @@ -495,7 +514,7 @@ public function prepareResourceNode(modResource $resource)
'hasChildren' => $hasChildren,
'hide_children_in_tree' => $resource->hide_children_in_tree,
'qtip' => $qtip,
'preview_url' => (!$resource->get('deleted')) ? $this->modx->makeUrl($resource->get('id'), $resource->get('context_key'), $sessionEnabled, 'full', ['xhtml_urls' => false]) : '',
'preview_url' => $resource->getPreviewUrl(),
'page' => empty($noHref) ? '?a=' . (!empty($this->permissions['edit_document']) ? 'resource/update' : 'resource/data') . '&id=' . $resource->id : '',
'allowDrop' => true,
];
Expand Down
10 changes: 8 additions & 2 deletions core/src/Revolution/Processors/Resource/Undelete.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/*
* This file is part of MODX Revolution.
*
Expand Down Expand Up @@ -40,9 +41,13 @@ public function getLanguageTopics()
public function initialize()
{
$id = $this->getProperty('id', false);
if (empty($id)) return $this->modx->lexicon('resource_err_ns');
if (empty($id)) {
return $this->modx->lexicon('resource_err_ns');
}
$this->resource = $this->modx->getObject(modResource::class, $id);
if (empty($this->resource)) return $this->modx->lexicon('resource_err_nfs', ['id' => $id]);
if (empty($this->resource)) {
return $this->modx->lexicon('resource_err_nfs', ['id' => $id]);
}

/* check permissions on the resource */
if (!$this->resource->checkPolicy(['save' => 1, 'undelete' => 1])) {
Expand Down Expand Up @@ -83,6 +88,7 @@ public function process()
$outputArray = $this->resource->get(['id']);

$outputArray['deletedCount'] = $deletedCount;
$outputArray['preview_url'] = $this->resource->getPreviewUrl();

return $this->modx->error->success('', $outputArray);
}
Expand Down
5 changes: 1 addition & 4 deletions core/src/Revolution/Processors/Resource/Update.php
Original file line number Diff line number Diff line change
Expand Up @@ -935,10 +935,7 @@ public function cleanup()
$this->modx->reloadContext($this->workingContext->key);
}

$returnArray['preview_url'] = '';
if (!$this->object->get('deleted')) {
$returnArray['preview_url'] = $this->modx->makeUrl($this->object->get('id'), $this->object->get('context_key'), '', 'full');
}
$returnArray['preview_url'] = $this->object->getPreviewUrl();

return $this->success('', $returnArray);
}
Expand Down
Loading