Skip to content

Commit e79be1b

Browse files
committed
[#4] Fixed a bug with HTML entities in the resource pagetitle
1 parent 704eb83 commit e79be1b

4 files changed

Lines changed: 43 additions & 25 deletions

File tree

assets/components/fileman/js/mgr/widgets/files.grid.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -395,8 +395,10 @@ Ext.extend(FileMan.grid.Files, MODx.grid.Grid, {
395395
if (!FileMan.config.resource_id)
396396
columns.push({
397397
header: _('resource'),
398-
dataIndex: 'pagetitle',
399-
sortable: true
398+
dataIndex: 'resource_pagetitle',
399+
sortable: true,
400+
xtype: 'templatecolumn',
401+
tpl: '<a href="?a=resource/update&id={resource_id}" target="_blank">{resource_pagetitle}</a>'
400402
}, {
401403
header: _('user'),
402404
dataIndex: 'username',

core/components/fileman/src/FileMan.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public function __construct(modX $modx, array $config = [])
6161
* */
6262
public function getFileFields()
6363
{
64-
return array_merge(array_keys($this->modx->getFields(File::class)), array('pagetitle', 'username'));
64+
return array_merge(array_keys($this->modx->getFields(File::class)), array('resource_pagetitle', 'username'));
6565
}
6666

6767
/**

core/components/fileman/src/Processors/File/GetList.php

Lines changed: 32 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@
33
namespace FileMan\Processors\File;
44

55
use FileMan\Model\File;
6+
use MODX\Revolution\modResource;
67
use MODX\Revolution\modUser;
78
use MODX\Revolution\Processors\Model\GetListProcessor;
9+
use xPDO\Om\xPDOObject;
810
use xPDO\Om\xPDOQuery;
911

1012
class GetList extends GetListProcessor
@@ -54,36 +56,50 @@ public function beforeQuery()
5456
public function prepareQueryBeforeCount(xPDOQuery $c)
5557
{
5658
$resourceId = (int) $this->getProperty('resource_id');
57-
$user = trim($this->getProperty('user'));
58-
$query = trim($this->getProperty('query'));
59+
$user = trim($this->getProperty('user'));
60+
$query = trim($this->getProperty('query'));
5961

6062
$c->select($this->modx->getSelectColumns(File::class, 'File'));
6163

62-
if ($query){
63-
$c->where(array(
64+
if ($query){
65+
$c->where(array(
6466
'name:LIKE' => "%{$query}%",
6567
'OR:title:LIKE' => "%{$query}%",
6668
'OR:description:LIKE' => "%{$query}%",
6769
'OR:group:LIKE' => "%{$query}%"
6870
));
6971
}
7072

71-
if ($user || ($resourceId == 0)) {
72-
$c->select('User.username');
73-
$c->leftJoin(modUser::class, 'User', 'User.id=File.user_id');
74-
}
73+
if ($user || ($resourceId == 0)) {
74+
$c->select('User.username');
75+
$c->leftJoin(modUser::class, 'User', 'User.id=File.user_id');
76+
}
7577

76-
if ($user)
77-
$c->where(array('User.username:LIKE' => "%$user%"));
78+
if ($user)
79+
$c->where(array('User.username:LIKE' => "%$user%"));
7880

79-
if ($resourceId > 0)
80-
$c->where(array('resource_id' => $resourceId));
81-
else {
82-
$c->select('Resource.pagetitle');
83-
$c->leftJoin('modResource', 'Resource', 'Resource.id=File.resource_id');
84-
}
81+
if ($resourceId > 0)
82+
$c->where(array('resource_id' => $resourceId));
83+
else {
84+
$c->leftJoin('modResource', 'Resource', 'Resource.id=File.resource_id');
85+
$c->select($this->modx->getSelectColumns(modResource::class, 'Resource', 'resource_', ['pagetitle']));
86+
}
8587

8688
return $c;
8789
}
8890

91+
/**
92+
* Prepare the row for iteration
93+
*
94+
* @param xPDOObject $object
95+
*
96+
* @return array
97+
*/
98+
public function prepareRow(xPDOObject $object)
99+
{
100+
$array = $object->toArray();
101+
$array['resource_pagetitle'] = strip_tags($array['resource_pagetitle']);
102+
return $array;
103+
}
104+
89105
}

core/components/fileman/src/Processors/Resource/Combo.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class Combo extends GetListProcessor
2020
public $contextKeys = array();
2121

2222
/** @var string $charset */
23-
public $charset = 'UTF-8';
23+
public $charset = 'UTF-8';
2424

2525
public function beforeQuery()
2626
{
@@ -50,9 +50,9 @@ public function getContextKeys()
5050
}
5151

5252
public function beforeIteration(array $list) {
53-
$this->charset = $this->modx->getOption('modx_charset',null,'UTF-8');
54-
return $list;
55-
}
53+
$this->charset = $this->modx->getOption('modx_charset',null,'UTF-8');
54+
return $list;
55+
}
5656

5757
public function prepareQueryBeforeCount(xPDOQuery $c)
5858
{
@@ -83,8 +83,8 @@ public function prepareRow(xPDOObject $object)
8383
{
8484
$objectArray = $object->toArray();
8585

86-
$objectArray['pagetitle'] = htmlentities($objectArray['pagetitle'], ENT_COMPAT, $this->charset);
87-
$objectArray['description'] = htmlentities($objectArray['description'], ENT_COMPAT, $this->charset);
86+
$objectArray['pagetitle'] = html_entity_decode($objectArray['pagetitle'], ENT_COMPAT, $this->charset);
87+
$objectArray['description'] = html_entity_decode($objectArray['description'], ENT_COMPAT, $this->charset);
8888

8989
return array(
9090
'id' => $objectArray['id'],

0 commit comments

Comments
 (0)