'
+ ,'
'
+ ,'
'
,''
,''+_('gallery.active')+''
,''+_('gallery.inactive')+''
@@ -232,7 +236,7 @@ Ext.extend(GAL.view.AlbumItems,MODx.DataView,{
,plain: true
,items: [{
id: 'gal-item-ss'
- ,html: ''
+ ,html: ''
}]
,buttons: [{
text: _('close')
@@ -286,4 +290,3 @@ Ext.extend(GAL.view.AlbumItems,MODx.DataView,{
});
Ext.reg('gal-view-album-items',GAL.view.AlbumItems);
-
diff --git a/assets/components/gallery/js/mgr/widgets/album/album.panel.js b/assets/components/gallery/js/mgr/widgets/album/album.panel.js
index d9c0e0a..f10ef9a 100644
--- a/assets/components/gallery/js/mgr/widgets/album/album.panel.js
+++ b/assets/components/gallery/js/mgr/widgets/album/album.panel.js
@@ -70,17 +70,18 @@ GAL.panel.Album = function(config) {
,columnWidth: .6
},{
xtype:'hidden'
- ,'name':'cover_filename_url'
+ ,name:'cover_filename_url'
,id:'cover_filename_url'
},{
xtype:'button'
,text: _('gallery.upload_cover')
- ,height: 39
+ ,cls: 'primary-button'
+ // ,height: 39
,handler: this.updateCover
},{
xtype:'button'
,text: _('gallery.delete_cover')
- ,height: 39
+ // ,height: 39
,handler:function() {
var panel=Ext.getCmp('gal-panel-album').getForm();
panel.findField('cover_filename').setValue('');
@@ -318,9 +319,9 @@ GAL.panel.AlbumItems = function(config) {
,region: 'east'
,split: true
,autoScroll: true
- ,width: '20%'
+ ,width: '25%'
,minWidth: 150
- ,maxWidth: 250
+ // ,maxWidth: 250
,height: 450
,border: false
}]
diff --git a/assets/components/gallery/js/mgr/widgets/album/album.tree.js b/assets/components/gallery/js/mgr/widgets/album/album.tree.js
index 0cdb245..ca29059 100644
--- a/assets/components/gallery/js/mgr/widgets/album/album.tree.js
+++ b/assets/components/gallery/js/mgr/widgets/album/album.tree.js
@@ -7,6 +7,7 @@ GAL.tree.Album = function(config) {
,action: 'mgr/album/getNodes'
,tbar: [{
text: _('gallery.album_create')
+ ,cls: 'primary-button'
,handler: function(btn,e) { this.createAlbum(btn,e,true); }
,scope: this
},'-',{
diff --git a/assets/components/gallery/js/mgr/widgets/album/albums.grid.js b/assets/components/gallery/js/mgr/widgets/album/albums.grid.js
index d71a942..ecb98a8 100644
--- a/assets/components/gallery/js/mgr/widgets/album/albums.grid.js
+++ b/assets/components/gallery/js/mgr/widgets/album/albums.grid.js
@@ -30,6 +30,7 @@ GAL.grid.Albums = function(config) {
}]
,tbar: [{
text: _('gallery.album_create')
+ ,cls: 'primary-button'
,handler: this.createAlbum
,scope: this
}]
@@ -85,8 +86,8 @@ GAL.window.CreateAlbum = function(config) {
Ext.applyIf(config,{
title: _('gallery.album_create')
,id: this.ident
- ,height: 150
- ,width: 475
+ // ,height: 150
+ // ,width: 475
,url: GAL.config.connector_url
,action: 'mgr/album/create'
,fields: [{
@@ -101,6 +102,12 @@ GAL.window.CreateAlbum = function(config) {
,name: 'description'
,id: 'gal-'+this.ident+'-description'
,width: 300
+ },{
+ xtype: 'textfield'
+ ,fieldLabel: _('gallery.year')
+ ,name: 'year'
+ ,anchor: '100%'
+ ,allowBlank: true
},{
xtype: 'checkbox'
,fieldLabel: _('gallery.active')
diff --git a/core/components/gallery/controllers/album/update.class.php b/core/components/gallery/controllers/album/update.class.php
index ffa23bc..24d8458 100644
--- a/core/components/gallery/controllers/album/update.class.php
+++ b/core/components/gallery/controllers/album/update.class.php
@@ -37,9 +37,9 @@ public function loadCustomCssJs() {
$this->addJavascript($this->gallery->config['jsUrl'].'mgr/widgets/album/album.panel.js');
$this->addLastJavascript($this->gallery->config['jsUrl'].'mgr/sections/album/update.js');
$this->addCss($this->gallery->config['cssUrl'].'fileuploader.css');
-
+ $this->addHtml("");
+
$this->checkForTinyMCE();
-
}
public function getTemplateFile() { return $this->gallery->config['templatesPath'].'album/update.tpl'; }
diff --git a/core/components/gallery/controllers/home.class.php b/core/components/gallery/controllers/home.class.php
index afe16ff..c8a6df4 100644
--- a/core/components/gallery/controllers/home.class.php
+++ b/core/components/gallery/controllers/home.class.php
@@ -31,6 +31,7 @@ public function loadCustomCssJs() {
$this->addJavascript($this->gallery->config['jsUrl'].'mgr/widgets/album/album.tree.js');
$this->addJavascript($this->gallery->config['jsUrl'].'mgr/widgets/home.panel.js');
$this->addLastJavascript($this->gallery->config['jsUrl'].'mgr/sections/home.js');
+ $this->addHtml("");
}
public function getTemplateFile() { return $this->gallery->config['templatesPath'].'home.tpl'; }
}
\ No newline at end of file
diff --git a/core/components/gallery/docs/changelog.txt b/core/components/gallery/docs/changelog.txt
index b4d704e..2f0b723 100755
--- a/core/components/gallery/docs/changelog.txt
+++ b/core/components/gallery/docs/changelog.txt
@@ -1,5 +1,47 @@
Changelog for Gallery.
+Gallery 1.7.1
+====================================
+- Fixed critical vulnerability in phpthumb processor
+- Fixed namespace paths
+
+Gallery 1.7.0
+====================================
+- Fixed showAll parameter in galAlbum
+- Fixed album tree icon
+- Fixed undefined index: Year
+- Updated phpthumb-processor
+- Add browser caching support to phpthumb processor
+- Move Ext.onReady into controllers
+- Add support for &thumbTpl_N tpl in Gallery snippet
+- More 2.3 Fixes
+- Modx 2.3 Compatibility Fixes
+
+Gallery 1.6.1
+====================================
+ - [#13][#12] Backwards Compatibility Fix
+
+Gallery 1.6.0
+====================================
+- [#271] [GalleryAlbums] Added image_absolute placeholder
+- [#270] [GalleryAlbums] Added containerTpl (with navigation placeholders) and totalVar placeholder
+- [#266] Add support for selection of album cover.
+- [#259] Do not cache in getList() when $sort = RAND()
+- [#252] Database Optimization
+- [#248] Fix getPage support in Gallery snippet
+- [#246] Batch import sorts by filename.
+- [#235] show all childs and subchilds of selected parent album by new TV option
+- [#233] Fix property itemCls from being assigned activeCls's value
+- [#226] German localization
+- [#151] Needed to show links to next/prev albums
+- [#91] Allow false boolean
+- [#258] Bug fix with random sorting when cached
+- Bug fixes
+
+Gallery 1.5.3
+====================================
+- [#9] Fixes Access Denied issue when using Manager / Gallery
+
Gallery 1.5.2
====================================
- [#219] Ensure that GalleryAlbums custom TV marks resource edit form dirty and enables save button
diff --git a/core/components/gallery/elements/snippets/snippet.gallery.php b/core/components/gallery/elements/snippets/snippet.gallery.php
index 33dc490..9e84ebf 100644
--- a/core/components/gallery/elements/snippets/snippet.gallery.php
+++ b/core/components/gallery/elements/snippets/snippet.gallery.php
@@ -99,10 +99,23 @@
$linkToImage = $modx->getOption('linkToImage',$scriptProperties,false);
$activeCls = $modx->getOption('activeCls',$scriptProperties,'gal-item-active');
$highlightItem = $modx->getOption($imageGetParam,$_REQUEST,false);
+$defaultThumbTpl = $modx->getOption('thumbTpl',$scriptProperties,'galItemThumb');
+
/** @var galItem $item */
if (!is_array($data)) return '';
+// prep for &thumbTpl_N
+$keys = array_keys($scriptProperties);
+$nthTpls = array();
+foreach($keys as $key) {
+ $keyBits = $gallery->explodeAndClean($key, '_');
+ if (isset($keyBits[0]) && $keyBits[0] === 'thumbTpl') {
+ if ($i = (int) $keyBits[1]) $nthTpls[$i] = $scriptProperties[$key];
+ }
+}
+ksort($nthTpls);
+
foreach ($data['items'] as $item) {
$itemArray = $item->toArray();
$itemArray['idx'] = $idx;
@@ -111,7 +124,7 @@
$itemArray['cls'] .= ' '.$activeCls;
}
$itemArray['filename'] = basename($item->get('filename'));
- $itemArray['image_absolute'] = $filesUrl.$item->get('filename');
+ $itemArray['image_absolute'] = $item->get('base_url').$filesUrl.$item->get('filename');
$itemArray['fileurl'] = $itemArray['image_absolute'];
$itemArray['filepath'] = $filesPath.$item->get('filename');
$itemArray['filesize'] = $item->get('filesize');
@@ -131,7 +144,17 @@
$plugin->renderItem($itemArray);
}
- $output[] = $gallery->getChunk($modx->getOption('thumbTpl',$scriptProperties,'galItemThumb'),$itemArray);
+ $thumbTpl = $defaultThumbTpl;
+ if (isset($nthTpls[$idx])) {
+ $thumbTpl = $nthTpls[$idx];
+ } else {
+ foreach ($nthTpls as $int => $tpl) {
+ if ( ($idx % $int) === 0 ) $thumbTpl = $tpl;
+ }
+ }
+
+ $output[] = $gallery->getChunk($thumbTpl,$itemArray);
+
$idx++;
}
$output = implode("\n",$output);
@@ -143,7 +166,7 @@
'thumbnails' => $output,
'album_name' => $data['album']['name'],
'album_description' => $data['album']['description'],
- 'album_year' => $data['album']['year'],
+ 'album_year' => isset($data['album']['year']) ? $data['album']['year'] : '',
'albumRequestVar' => $albumRequestVar,
'albumId' => $data['album']['id'],
));
@@ -157,7 +180,7 @@
$toPlaceholder => $output,
$toPlaceholder.'.id' => $data['album']['id'],
$toPlaceholder.'.name' => $data['album']['name'],
- $toPlaceholder.'.year' => $data['album']['year'],
+ $toPlaceholder.'.year' => isset($data['album']['year']) ? $data['album']['year'] : '',
$toPlaceholder.'.description' => $data['album']['description'],
$toPlaceholder.'.total' => $data['total'],
$toPlaceholder.'.next' => $data['album']['id'] + 1,
@@ -168,7 +191,7 @@
$modx->toPlaceholders(array(
$placeholderPrefix.'id' => $data['album']['id'],
$placeholderPrefix.'name' => $data['album']['name'],
- $placeholderPrefix.'year' => $data['album']['year'],
+ $placeholderPrefix.'year' => isset($data['album']['year']) ? $data['album']['year'] : '',
$placeholderPrefix.'description' => $data['album']['description'],
$placeholderPrefix.'total' => $data['total'],
$placeholderPrefix.'next' => $data['album']['id'] + 1,
diff --git a/core/components/gallery/lexicon/cs/default.inc.php b/core/components/gallery/lexicon/cs/default.inc.php
index e0940f4..387c109 100644
--- a/core/components/gallery/lexicon/cs/default.inc.php
+++ b/core/components/gallery/lexicon/cs/default.inc.php
@@ -93,7 +93,7 @@
$_lang['gallery.clearsuccessful'] = 'Vymazat úspěšně nahrané';
// $_lang['gallery.clearfailure'] = 'Clear Failed Uploads';
-$_lang['gallery.clearfailure'] = 'Vymazat neúspešně nahrané';
+$_lang['gallery.clearfailure'] = 'Vymazat neúspěšně nahrané';
// $_lang['gallery.directory'] = 'Directory';
$_lang['gallery.directory'] = 'Složka';
diff --git a/core/components/gallery/lexicon/cs/properties.inc.php b/core/components/gallery/lexicon/cs/properties.inc.php
index 6adeec3..4a67238 100644
--- a/core/components/gallery/lexicon/cs/properties.inc.php
+++ b/core/components/gallery/lexicon/cs/properties.inc.php
@@ -58,7 +58,7 @@
$_lang['gallery.thumbtpl_desc'] = 'The Chunk to use as a tpl for each thumbnail.';
$_lang['gallery.thumbwidth_desc'] = 'The width of the generated thumbnails, in pixels.';
$_lang['gallery.thumbzoomcrop_desc'] = 'Whether or not the thumbnail will be zoom-cropped.';
-$_lang['gallery.usecss_desc'];
+$_lang['gallery.usecss_desc'] = 'Whether or not to use the pre-provided CSS for the snippet.';
/* GalleryAlbums Snippet */
$_lang['galleryalbums.albumrequestvar_desc'] = 'If checkForRequestAlbumVar is set to true, will look for a REQUEST var with this name to select the album.';
diff --git a/core/components/gallery/model/gallery/galalbum.class.php b/core/components/gallery/model/gallery/galalbum.class.php
index 4625f41..32be371 100644
--- a/core/components/gallery/model/gallery/galalbum.class.php
+++ b/core/components/gallery/model/gallery/galalbum.class.php
@@ -195,36 +195,44 @@ public function ensurePathExists() {
return $exists;
}
- public function uploadItem(galItem $item,$filePath,$name) {
+ public function uploadItem(galItem $item,$filePath,$name,$mediaSource) {
$fileName = false;
$albumDir = $this->getPath(false);
- $targetDir = $this->getPath();
+ $targetDir = str_ireplace(MODX_BASE_PATH, '', $this->getPath());
/* if directory doesnt exist, create it */
- if (!$this->ensurePathExists()) {
- $this->xpdo->log(xPDO::LOG_LEVEL_ERROR,'[Gallery] Could not create directory: '.$targetDir);
- return $fileName;
- }
- if (!$this->isPathWritable()) {
- $this->xpdo->log(xPDO::LOG_LEVEL_ERROR,'[Gallery] Could not write to directory: '.$targetDir);
- return $fileName;
+ if (!$mediaSource->createContainer($targetDir,'/')) {
+ $this->xpdo->log(xPDO::LOG_LEVEL_ERROR,'[Gallery] Could not create directory (possibly already exists?): '.$targetDir);
}
/* upload the file */
+
$extension = pathinfo($name,PATHINFO_EXTENSION);
$shortName = $item->get('id').'.'.$extension;
$relativePath = $albumDir.$shortName;
$absolutePath = $targetDir.$shortName;
- if (@file_exists($absolutePath)) {
- @unlink($absolutePath);
- }
- if (!@move_uploaded_file($filePath,$absolutePath)) {
- $this->xpdo->log(xPDO::LOG_LEVEL_ERROR,'[Gallery] An error occurred while trying to upload the file: '.$filePath.' to '.$absolutePath);
+ $fileName = str_replace(' ','',$relativePath);
+
+ $file = array("name" => $shortName, "tmp_name" => $filePath,"error" => "0"); // emulate a $_FILES object
+
+ $success = true;
+ // modFileMediaSource class uses move_uploaded_file - because we create a local file - we cannot use this function and we use streams instead
+ if(!is_uploaded_file($filePath) && get_class($mediaSource) == 'modFileMediaSource_mysql') {
+ $input = fopen($filePath, "r");
+ $target = fopen($this->getPath(true).$shortName, "w");
+ $bytes = stream_copy_to_stream($input, $target);
+ fclose($input);
+ fclose($target);
} else {
- $fileName = str_replace(' ','',$relativePath);
+ $success = $mediaSource->uploadObjectsToContainer($targetDir,array($file));
}
+
+ // if(!$success) {
+ // $this->xpdo->log(xPDO::LOG_LEVEL_ERROR,'[Gallery] An error occurred while trying to upload the file: '.$filePath.' to '.$absolutePath);
+ // return false;
+ // }
return $fileName;
}
@@ -418,7 +426,8 @@ public static function getList(modX &$modx,array $scriptProperties = array()) {
$limit = $modx->getOption('limit',$scriptProperties,10);
$start = $modx->getOption('start',$scriptProperties,0);
$parent = $modx->getOption('parent',$scriptProperties,0);
- $id = $modx->getOption('id',$scriptProperties,false);
+ $showAll = $modx->getOption('showAll',$scriptProperties, false);
+ $id = $modx->getOption('id',$scriptProperties,false);
$showInactive = $modx->getOption('showInactive',$scriptProperties,false);
$prominentOnly = $modx->getOption('prominentOnly',$scriptProperties,true);
@@ -444,7 +453,7 @@ public static function getList(modX &$modx,array $scriptProperties = array()) {
'prominent' => true,
));
}
- if (empty($showAll)) {
+ if ($showAll == false) {
$c->where(array(
'parent' => $parent,
));
diff --git a/core/components/gallery/model/gallery/galitem.class.php b/core/components/gallery/model/gallery/galitem.class.php
index 61e85e8..597b12d 100644
--- a/core/components/gallery/model/gallery/galitem.class.php
+++ b/core/components/gallery/model/gallery/galitem.class.php
@@ -23,6 +23,24 @@
* @package gallery
*/
class galItem extends xPDOSimpleObject {
+ private $mediaSource = false;
+
+ private function getMediaSource() {
+ if($this->mediaSource) return $this->mediaSource;
+ //get modMediaSource
+ $mediaSource = $this->xpdo->getOption('gallery.mediaSource',null,1);
+
+ $def = $this->xpdo->getObject('sources.modMediaSource',array(
+ 'id' => $mediaSource,
+ ));
+
+ $def->initialize();
+
+ $this->mediaSource = $def;
+
+ return $this->mediaSource;
+ }
+
public function get($k, $format = null, $formatTemplate= null) {
switch ($k) {
case 'thumbnail':
@@ -35,6 +53,12 @@ public function get($k, $format = null, $formatTemplate= null) {
$format['src'] = $this->getSiteUrl();
$format['src'] .= $this->xpdo->call('galAlbum','getFilesUrl',array(&$this->xpdo)).$filename;
}
+
+ $ms = $this->getMediaSource();
+ if($ms->getBaseUrl() != '/') {
+ $format['src'] = $ms->getBaseUrl().$this->xpdo->call('galAlbum','getFilesUrl',array(&$this->xpdo)).$filename;
+ }
+
$url = $value.'&'.http_build_query($format,'','&');
if ($this->xpdo->getOption('xhtml_urls',null,false)) {
$value = str_replace('&','&',$url);
@@ -52,12 +76,24 @@ public function get($k, $format = null, $formatTemplate= null) {
$format['src'] = $this->getSiteUrl();
$format['src'] .= $this->xpdo->call('galAlbum','getFilesUrl',array(&$this->xpdo)).$filename;
}
+
+ $ms = $this->getMediaSource();
+ if($ms->getBaseUrl() != '/') {
+ $format['src'] = $ms->getBaseUrl().$this->xpdo->call('galAlbum','getFilesUrl',array(&$this->xpdo)).$filename;
+ }
+
$value = $this->getPhpThumbUrl().'&'.http_build_query($format,'','&');
$value = $this->xpdo->getOption('xhtml_urls',null,false) ? str_replace('&','&',$value) : $value;
break;
case 'absoluteImage':
$siteUrl = $this->getSiteUrl();
$value = $siteUrl.$this->xpdo->call('galAlbum','getFilesUrl',array(&$this->xpdo)).$this->get('filename');
+
+ // $ms = $this->getMediaSource();
+ // if($ms->getBaseUrl() != '/') {
+ // $value = $ms->getBaseUrl().$this->xpdo->call('galAlbum','getFilesUrl',array(&$this->xpdo)).$filename;
+ // }
+
break;
case 'relativeImage':
$baseUrl = $this->getOption('base_url');
@@ -67,6 +103,12 @@ public function get($k, $format = null, $formatTemplate= null) {
} else {
$value = str_replace($baseUrl,'',$path);
}
+
+ // $ms = $this->getMediaSource(); // for absolute + relative the link NEEDS the http:// domain
+ // if($ms->getBaseUrl() != '/') {
+ // $value = $ms->getBaseUrl().$this->xpdo->call('galAlbum','getFilesUrl',array(&$this->xpdo)).$baseUrl;
+ // }
+
break;
case 'filesize':
$filename = $this->xpdo->call('galAlbum','getFilesPath',array(&$this->xpdo)).$this->get('filename');
@@ -75,6 +117,14 @@ public function get($k, $format = null, $formatTemplate= null) {
break;
case 'image_path':
$value = $this->xpdo->call('galAlbum','getFilesPath',array(&$this->xpdo)).$this->get('filename');
+ break;
+ case 'base_url':
+ $ms = $this->getMediaSource();
+ $value='';
+ if($ms->getBaseUrl() != '/') {
+ $value = $ms->getBaseUrl();
+ }
+
break;
default:
$value = parent::get($k,$format,$formatTemplate);
@@ -93,7 +143,7 @@ public function getPath($absolute = true) {
public function getPhpThumbUrl() {
$assetsUrl = $this->xpdo->getOption('gallery.assets_url',null,$this->xpdo->getOption('assets_url',null,MODX_ASSETS_URL).'components/gallery/');
- $assetsUrl .= 'connector.php?action=web/phpthumb';
+ $assetsUrl .= 'connector.php?action=web/phpthumb&ctx='.$this->xpdo->context->get('key');
return $assetsUrl;
}
@@ -136,7 +186,7 @@ public function upload($file,$albumId) {
$album = $this->xpdo->getObject('galAlbum',$albumId);
if (empty($album)) return false;
- $fileName = $album->uploadItem($this,$file['tmp_name'],$file['name']);
+ $fileName = $album->uploadItem($this,$file['tmp_name'], $file['name'], $this->getMediaSource());
if (empty($fileName)) {
return false;
}
@@ -168,7 +218,9 @@ public function remove(array $ancestors = array()) {
$filename = $this->get('filename');
if (!empty($filename)) {
$filename = $this->xpdo->call('galAlbum','getFilesPath',array(&$this->xpdo)).$filename;
- if (!@unlink($filename)) {
+ $filename = str_ireplace(MODX_BASE_PATH, '', $filename);
+ $ms = $this->getMediaSource();
+ if (!@$ms->removeObject($filename)) {
$this->xpdo->log(xPDO::LOG_LEVEL_ERROR,'[Gallery] An error occurred while trying to remove the attachment file at: '.$filename);
}
}
@@ -243,6 +295,7 @@ public function move($album) {
}
public static function getList(modX &$modx,array $scriptProperties = array()) {
+ $sort = $modx->getOption('sort',$scriptProperties,'rank');
$cacheKey = 'gallery/item/list/'.md5(serialize($scriptProperties));
if ($modx->getCacheManager() && $cache = $modx->cacheManager->get($cacheKey)) {
$items = array();
@@ -252,8 +305,12 @@ public static function getList(modX &$modx,array $scriptProperties = array()) {
$item->fromArray($data,'',true,true);
$items[] = $item;
}
-
- $data = array(
+
+ if (in_array(strtolower($sort),array('random','rand()','rand'))) {
+ shuffle($items);
+ }
+
+ $data = array(
'items' => $items,
'total' => $cache['total'],
'album' => $cache['album'],
@@ -267,7 +324,6 @@ public static function getList(modX &$modx,array $scriptProperties = array()) {
/* Fix to make it work with getPage which uses "offset" instead of "start" */
$offset = $modx->getOption('offset',$scriptProperties,0);
if ($offset > 0) { $start = $offset; }
- $sort = $modx->getOption('sort',$scriptProperties,'rank');
$sortAlias = $modx->getOption('sortAlias',$scriptProperties,'galItem');
if ($sort == 'rank') $sortAlias = 'AlbumItems';
$dir = $modx->getOption('dir',$scriptProperties,'ASC');
diff --git a/core/components/gallery/model/gallery/gallery.class.php b/core/components/gallery/model/gallery/gallery.class.php
index 62ead5a..5d6bc36 100644
--- a/core/components/gallery/model/gallery/gallery.class.php
+++ b/core/components/gallery/model/gallery/gallery.class.php
@@ -382,4 +382,13 @@ public function getAllChilds($album, &$albumsWithSubs, $sort, $dir, $deep){
$this->getAllChilds($subAlbum, $albumsWithSubs, $sort, $dir, $deep+1);
}
}
+
+ public function explodeAndClean($array, $delimiter = ',') {
+ $array = explode($delimiter, $array); // Explode fields to array
+ $array = array_map('trim', $array); // Trim array's values
+ $array = array_keys(array_flip($array)); // Remove duplicate fields
+ $array = array_filter($array); // Remove empty values from array
+
+ return $array;
+ }
}
\ No newline at end of file
diff --git a/core/components/gallery/model/gallery/import/galzipimport.class.php b/core/components/gallery/model/gallery/import/galzipimport.class.php
index c733d02..3e6c75f 100644
--- a/core/components/gallery/model/gallery/import/galzipimport.class.php
+++ b/core/components/gallery/model/gallery/import/galzipimport.class.php
@@ -120,10 +120,10 @@ public function importFile($file,array $options = array()) {
$newRelativePath = $this->albumId.'/'.$newFileName;
$newAbsolutePath = $this->target.'/'.$newFileName;
- if (@file_exists($newAbsolutePath)) {
- @unlink($newAbsolutePath);
- }
- if (!@copy($filePathName,$newAbsolutePath)) {
+ $file = array("name" => $newRelativePath, "tmp_name" => $filePathName, "error" => "0"); // emulate a $_FILES object
+
+ $success = $item->upload($file,$options['album']);
+ if(!$success) {
$errors[] = $this->modx->lexicon('gallery.file_err_move',array(
'file' => $newFileName,
'target' => $newAbsolutePath,
diff --git a/core/components/gallery/processors/mgr/album/getnodes.class.php b/core/components/gallery/processors/mgr/album/getnodes.class.php
index 3b956c6..8c86152 100644
--- a/core/components/gallery/processors/mgr/album/getnodes.class.php
+++ b/core/components/gallery/processors/mgr/album/getnodes.class.php
@@ -47,7 +47,14 @@ public function getAlbums($id) {
$albumArray['text'] = $album->get('name').' ('.$album->get('id').')';
$albumArray['leaf'] = false;
$albumArray['parent'] = 0;
- $albumArray['cls'] = 'icon-tiff'.($album->get('active') ? '' : ' gal-item-inactive');
+
+ $version = $this->modx->getVersionData();
+ if ($version['major_version'] < 3) {
+ $albumArray['cls'] = 'icon-tiff'.($album->get('active') ? '' : ' gal-item-inactive');
+ } else {
+ $albumArray['iconCls'] = 'icon icon-tiff'.($album->get('active') ? '' : ' gal-item-inactive');
+ }
+
$albumArray['classKey'] = 'galAlbum';
if (!empty($action)) {
$albumArray['page'] = '?a='.$action->get('id').'&album='.$album->get('id').'&action=album/update';
diff --git a/core/components/gallery/processors/mgr/item/ajaxupload.php b/core/components/gallery/processors/mgr/item/ajaxupload.php
index c52fd29..90eb498 100644
--- a/core/components/gallery/processors/mgr/item/ajaxupload.php
+++ b/core/components/gallery/processors/mgr/item/ajaxupload.php
@@ -28,29 +28,26 @@
$albumDir = $album.'/';
$targetDir = $modx->call('galAlbum','getFilesPath',array(&$modx)).$albumDir;
-$cacheManager = $modx->getCacheManager();
-/* if directory doesnt exist, create it */
-if (!file_exists($targetDir) || !is_dir($targetDir)) {
- if (!$cacheManager->writeTree($targetDir)) {
- $modx->log(xPDO::LOG_LEVEL_ERROR,'[Gallery] Could not create directory: '.$targetDir);
- return $modx->toJSON(array('error' => 'Could not create directory: ' . $targetDir));
- }
-}
-/* make sure directory is readable/writable */
-if (!is_readable($targetDir) || !is_writable($targetDir)) {
- $modx->log(xPDO::LOG_LEVEL_ERROR,'[Gallery] Could not write to directory: '.$targetDir);
- return $modx->toJSON(array('error' => 'Could not write to directory: ' . $targetDir));
-}
+// $cacheManager = $modx->getCacheManager();
+// /* if directory doesnt exist, create it */
+// if (!file_exists($targetDir) || !is_dir($targetDir)) {
+// if (!$cacheManager->writeTree($targetDir)) {
+// $modx->log(xPDO::LOG_LEVEL_ERROR,'[Gallery] Could not create directory: '.$targetDir);
+// return $modx->toJSON(array('error' => 'Could not create directory: ' . $targetDir));
+// }
+// }
+// /* make sure directory is readable/writable */
+// if (!is_readable($targetDir) || !is_writable($targetDir)) {
+// $modx->log(xPDO::LOG_LEVEL_ERROR,'[Gallery] Could not write to directory: '.$targetDir);
+// return $modx->toJSON(array('error' => 'Could not write to directory: ' . $targetDir));
+// }
/* upload the file */
-$extension = end(explode('.', $filenm));
+$extension = @end(explode('.', $filenm));
$filename = $item->get('id').'.'.$extension;
$relativePath = $albumDir.$filename;
$absolutePath = $targetDir.$filename;
-if (@file_exists($absolutePath)) {
- @unlink($absolutePath);
-}
if (!empty($_FILES['qqfile'])) {
if (!$item->upload($_FILES['qqfile'],$scriptProperties['album'])) {
@@ -58,20 +55,35 @@
return $modx->error->failure($modx->lexicon('gallery.item_err_upload'));
}
} else {
- /* Using AJAX upload */
+
+ $length = 10;
+ $tmpDir = MODX_CORE_PATH."cache/gallery-tmp/";
+
+ if(!file_exists($tmpDir)) mkdir($tmpDir);
+
+ $randomFilename = $tmpDir.substr(str_shuffle("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"), 0, $length).".$extension";
+
+ /* Using AJAX upload - to tmp file then use the correct media source to upload */
$input = fopen("php://input", "r");
- $target = fopen($absolutePath, "w");
+ $target = fopen($randomFilename, "w");
$bytes = stream_copy_to_stream($input, $target);
fclose($input);
fclose($target);
-
- if ($bytes == 0) {
+
+ $file = array("name" => $relativePath, "tmp_name" => $randomFilename, "error" => "0"); // emulate a $_FILES object
+
+ $modx->log(xPDO::LOG_LEVEL_ERROR,'[Gallery] Album Type: '.$scriptProperties['album']);
+
+
+ if ($bytes == 0 || !$item->upload($file,$scriptProperties['album'])) {
$modx->log(xPDO::LOG_LEVEL_ERROR,'[Gallery] An error occurred while trying to upload the file to '.$absolutePath);
$item->remove();
return $modx->toJSON(array('error' => 'gallery.item_err_upload'));
} else {
$item->set('filename',str_replace(' ','',$relativePath));
}
+
+ @unlink($randomFilename);
}
$item->save();
@@ -105,4 +117,4 @@
/* output to browser */
return $modx->toJSON(array('success' => true));
-?>
\ No newline at end of file
+?>
diff --git a/core/components/gallery/processors/mgr/item/batchupload.php b/core/components/gallery/processors/mgr/item/batchupload.php
index 69d7900..32b7249 100644
--- a/core/components/gallery/processors/mgr/item/batchupload.php
+++ b/core/components/gallery/processors/mgr/item/batchupload.php
@@ -56,20 +56,6 @@
$targetDir = $modx->call('galAlbum','getFilesPath',array(&$modx)).$scriptProperties['album'].'/';
-$cacheManager = $modx->getCacheManager();
-/* if directory doesnt exist, create it */
-if (!file_exists($targetDir) || !is_dir($targetDir)) {
- if (!$cacheManager->writeTree($targetDir)) {
- $modx->log(modX::LOG_LEVEL_ERROR,'[Gallery] Could not create directory: '.$targetDir);
- return $modx->error->failure($modx->lexicon('gallery.directory_err_create',array('directory' => $targetDir)));
- }
-}
-/* make sure directory is readable/writable */
-if (!is_readable($targetDir) || !is_writable($targetDir)) {
- $modx->log(xPDO::LOG_LEVEL_ERROR,'[Gallery] Could not write to directory: '.$targetDir);
- return $modx->error->failure($modx->lexicon('gallery.directory_err_write',array('directory' => $targetDir)));
-}
-
$imagesExts = array('jpg','jpeg','png','gif','bmp');
$use_multibyte = $modx->getOption('use_multibyte',null,false);
$encoding = $modx->getOption('modx_charset',null,'UTF-8');
@@ -108,11 +94,11 @@
$newFileName = $item->get('id').'.'.$fileExtension;
$newRelativePath = $scriptProperties['album'].'/'.$newFileName;
$newAbsolutePath = $targetDir.'/'.$newFileName;
-
- if (@file_exists($newAbsolutePath)) {
- @unlink($newAbsolutePath);
- }
- if (!@copy($filePathName,$newAbsolutePath)) {
+
+ $file = array("name" => $newRelativePath, "tmp_name" => $filePathName, "error" => "0"); // emulate a $_FILES object
+
+ $success = $item->upload($file,$scriptProperties['album']);
+ if(!$success) {
$errors[] = $modx->lexicon('gallery.file_err_move',array(
'file' => $newFileName,
'target' => $newAbsolutePath,
diff --git a/core/components/gallery/processors/mgr/item/sort.php b/core/components/gallery/processors/mgr/item/sort.php
index 6f13021..3ce8880 100644
--- a/core/components/gallery/processors/mgr/item/sort.php
+++ b/core/components/gallery/processors/mgr/item/sort.php
@@ -43,11 +43,11 @@
SET rank = rank - 1
WHERE
album = ".$scriptProperties['album']."
- AND rank <= {$target->get('rank')}
+ AND rank < {$target->get('rank')}
AND rank > {$source->get('rank')}
AND rank > 0
");
- $newRank = $target->get('rank');
+ $newRank = $target->get('rank')-1;
} else {
$modx->exec("
UPDATE {$modx->getTableName('galAlbumItem')}
@@ -62,4 +62,4 @@
$source->set('rank',$newRank);
$source->save();
-return $modx->error->success();
\ No newline at end of file
+return $modx->error->success();
diff --git a/core/components/gallery/processors/web/phpthumb.php b/core/components/gallery/processors/web/phpthumb.php
index 08912b5..0ced2c6 100644
--- a/core/components/gallery/processors/web/phpthumb.php
+++ b/core/components/gallery/processors/web/phpthumb.php
@@ -1,4 +1,5 @@
loadClass('modPhpThumb',$modx->getOption('core_path').'model/phpthumb/',true,true)) {
- $modx->log(modX::LOG_LEVEL_ERROR,'[phpThumbOf] Could not load modPhpThumb class.');
- return '';
+
+
+if (!class_exists('phpthumb', false)) {
+ if (!$modx->loadClass('phpthumb', MODX_CORE_PATH . 'model/phpthumb/', true, true)) {
+ $modx->log(modX::LOG_LEVEL_ERROR, '[phpThumbOf] Could not load modPhpThumb class.');
+ return '';
+ }
}
-$debug = $modx->getOption('debug',$scriptProperties,false);
-$src = $modx->getOption('src',$scriptProperties,'');
-$src = str_replace('+','%27',urldecode($src));
+
+
+$debug = $modx->getOption('debug', $scriptProperties, false);
+
+$src = $modx->getOption('src', $scriptProperties, '');
+$src = str_replace('+', '%27', urldecode($src));
/* explode tag options */
-$ptOptions = $scriptProperties;
+$ptOptions = array();
+
+// Only public parameters of phpThumb should be allowed to pass from user input.
+// List properties between START PARAMETERS and START PARAMETERS in src/core/model/phpthumb/phpthumb.class.php
+$allowed = array(
+ 'src', 'new', 'w', 'h', 'wp', 'hp', 'wl', 'hl', 'ws', 'hs',
+ 'f', 'q', 'sx', 'sy', 'sw', 'sh', 'zc', 'bc', 'bg', 'fltr',
+ 'goto', 'err', 'xto', 'ra', 'ar', 'aoe', 'far', 'iar', 'maxb', 'down',
+ 'md5s', 'sfn', 'dpi', 'sia', 'phpThumbDebug'
+);
+
+/* iterate through properties */
+foreach ($scriptProperties as $property => $value) {
+ if (!in_array($property, $allowed, true)) {
+ $this->modx->log(modX::LOG_LEVEL_WARN, "Detected attempt of using private parameter `$property` (for internal usage) of phpThumb that not allowed and insecure");
+ continue;
+ }
+ $ptOptions[$property] = $value;
+}
-if (empty($ptOptions['f'])){
+if (empty($ptOptions['f'])) {
$ext = pathinfo($src, PATHINFO_EXTENSION);
$ext = strtolower($ext);
switch ($ext) {
@@ -37,55 +63,66 @@
}
/* load phpthumb */
-$assetsPath = $modx->getOption('gallery.assets_path',$scriptProperties,$modx->getOption('assets_path').'components/gallery/');
-$phpThumb = new modPhpThumb($modx,$ptOptions);
-$cacheDir = $assetsPath.'cache/';
+$assetsPath = $modx->getOption('gallery.assets_path', $scriptProperties, $modx->getOption('assets_path') . 'components/gallery/');
+$cacheDir = $assetsPath . 'cache/';
/* check to make sure cache dir is writable */
if (!is_writable($cacheDir)) {
if (!$modx->cacheManager->writeTree($cacheDir)) {
- $modx->log(modX::LOG_LEVEL_ERROR,'[phpThumbOf] Cache dir not writable: '.$assetsPath.'cache/');
+ $modx->log(modX::LOG_LEVEL_ERROR, '[phpThumbOf] Cache dir not writable: ' . $assetsPath . 'cache/');
return '';
}
}
-/* do initial setup */
-$phpThumb->initialize();
-$phpThumb->setParameter('config_cache_directory',$assetsPath.'cache/');
-$phpThumb->setParameter('config_allow_src_above_phpthumb',true);
-$phpThumb->setParameter('allow_local_http_src',true);
-$phpThumb->setParameter('config_document_root', $modx->getOption('base_path',null,MODX_BASE_PATH));
-$phpThumb->setCacheDirectory();
-
/* get absolute url of image */
-if (strpos($src,'/') != 0 && strpos($src,'http') != 0) {
- $src = $modx->getOption('base_url').$src;
+if (strpos($src, '/') != 0 && strpos($src, 'http') != 0) {
+ $src = $modx->getOption('base_url') . $src;
} else {
$src = urldecode($src);
}
/* auto-prepend base path if not a URL */
-if (strpos($src,'http') === false) {
- $basePath = $modx->getOption('base_path',null,MODX_BASE_PATH);
+if (strpos($src, 'http') === false) {
+ $basePath = $modx->getOption('base_path', null, MODX_BASE_PATH);
if ($basePath != '/') {
- $src = str_replace(basename($basePath),'',$src);
- $src = ltrim($src,'/');
- $src = $basePath.$src;
+ $src = str_replace(basename($basePath), '', $src);
+ $src = ltrim($src, '/');
+ $src = $basePath . $src;
}
}
-/* set source */
-$phpThumb->set($src);
+
+if (!isset($config['modphpthumb'])) { // make sure we get a few relevant system settings
+ $config['modphpthumb'] = array();
+ $config['modphpthumb']['config_allow_src_above_docroot'] = (boolean)$modx->getOption('phpthumb_allow_src_above_docroot', null, false);
+ $config['modphpthumb']['zc'] = $modx->getOption('phpthumb_zoomcrop', null, 0);
+ $config['modphpthumb']['far'] = $modx->getOption('phpthumb_far', null, 'C');
+ $config['modphpthumb']['config_ttf_directory'] = MODX_CORE_PATH . 'model/phpthumb/fonts/';
+ $config['modphpthumb']['config_document_root'] = $modx->getOption('phpthumb_document_root', null, '');
+}
+$phpThumb = new phpthumb(); // unfortunately we have to create a new object for each image!
+foreach ($config['modphpthumb'] as $param => $value) { // add MODX system settings
+ $phpThumb->$param = $value;
+}
+foreach ($ptOptions as $param => $value) { // add options passed to the snippet
+ $phpThumb->setParameter($param, $value);
+}
+// try to avert problems when $_SERVER['DOCUMENT_ROOT'] is different than MODX_BASE_PATH
+if (!$phpThumb->config_document_root) {
+ $phpThumb->config_document_root = MODX_BASE_PATH; // default if nothing set from system settings
+}
+$phpThumb->config_cache_directory = $assetsPath . 'cache/'; // doesn't matter, but saves phpThumb some frustration
+$phpThumb->setSourceFilename($src);
/* setup cache filename that is unique to this tag */
-$inputSanitized = str_replace(array(':','/'),'_',$src);
+$inputSanitized = str_replace(array(':', '/'), '_', $src);
$cacheFilename = $inputSanitized;
-$cacheFilename .= '.'.md5(serialize($scriptProperties));
+$cacheFilename .= '.' . md5(serialize($scriptProperties));
$cacheFilename .= '.' . (!empty($ptOptions['f']) ? $ptOptions['f'] : 'png');
-$cacheKey = $assetsPath.'cache/'.$cacheFilename;
+$cacheKey = $assetsPath . 'cache/' . $cacheFilename;
/* get cache Url */
-$assetsUrl = $modx->getOption('gallery.assets_url',$scriptProperties,$modx->getOption('assets_url').'components/gallery/');
-$cacheUrl = $assetsUrl.'cache/'.str_replace($cacheDir,'',$cacheKey);
-$cacheUrl = str_replace('//','/',$cacheUrl);
+$assetsUrl = $modx->getOption('gallery.assets_url', $scriptProperties, $modx->getOption('assets_url') . 'components/gallery/');
+$cacheUrl = $assetsUrl . 'cache/' . str_replace($cacheDir, '', $cacheKey);
+$cacheUrl = str_replace('//', '/', $cacheUrl);
/* ensure we have an accurate and clean cache directory */
$phpThumb->CleanUpCacheDirectory();
@@ -101,7 +138,7 @@
$oldLogTarget = $modx->getLogTarget();
$oldLogLevel = $modx->getLogLevel();
$modx->setLogLevel(modX::LOG_LEVEL_DEBUG);
- $logTarget = $modx->getOption('debugTarget',$scriptProperties,'');
+ $logTarget = $modx->getOption('debugTarget', $scriptProperties, '');
if (!empty($logTarget)) {
$modx->setLogTarget();
}
@@ -109,42 +146,54 @@
/* ensure file has proper permissions */
if (!empty($cacheKey)) {
- $filePerm = (int)$modx->getOption('new_file_permissions',$scriptProperties,'0664');
+ $filePerm = (int)$modx->getOption('new_file_permissions', $scriptProperties, '0664');
@chmod($cacheKey, octdec($filePerm));
}
if ($debug) {
- $mtime= microtime();
- $mtime= explode(" ", $mtime);
- $mtime= $mtime[1] + $mtime[0];
- $tend= $mtime;
- $totalTime= ($tend - $tstart);
- $totalTime= sprintf("%2.4f s", $totalTime);
-
- $modx->log(modX::LOG_LEVEL_DEBUG,"\n
Execution time: {$totalTime}\n
");
+ $mtime = microtime();
+ $mtime = explode(" ", $mtime);
+ $mtime = $mtime[1] + $mtime[0];
+ $tend = $mtime;
+ $totalTime = ($tend - $tstart);
+ $totalTime = sprintf("%2.4f s", $totalTime);
+
+ $modx->log(modX::LOG_LEVEL_DEBUG, "\n
Execution time: {$totalTime}\n
");
$modx->setLogLevel($oldLogLevel);
$modx->setLogTarget($oldLogTarget);
}
-$output = '';
+$output = $assetsUrl;
+
+
/* check to see if there's a cached file of this already */
if (file_exists($cacheKey)) {
- $modx->log(modX::LOG_LEVEL_DEBUG,'[phpThumbOf] Using cached file found for thumb: '.$cacheKey);
- $output = str_replace(' ','%20',$cacheUrl);
+ $modx->log(modX::LOG_LEVEL_DEBUG, '[phpThumbOf] Using cached file found for thumb: ' . $cacheKey);
+ $output = str_replace(' ', '%20', $cacheUrl);
} else {
/* actually make the thumbnail */
+ //return $cacheKey;
if ($phpThumb->GenerateThumbnail()) { // this line is VERY important, do not remove it!
if ($phpThumb->RenderToFile($cacheKey)) {
- $output = str_replace(' ','%20',$cacheUrl);
+ $output = str_replace(' ', '%20', $cacheUrl);
} else {
- $modx->log(modX::LOG_LEVEL_ERROR,'[phpThumbOf] Could not cache thumb "'.$src.'" to file at: '.$cacheKey.' - Debug: '.print_r($phpThumb->debugmessages,true));
+ $modx->log(modX::LOG_LEVEL_ERROR, '[phpThumbOf] Could not cache thumb "' . $src . '" to file at: ' . $cacheKey . ' - Debug: ' . print_r($phpThumb->debugmessages, true));
}
} else {
- $modx->log(modX::LOG_LEVEL_ERROR,'[phpThumbOf] Could not generate thumbnail: '.$src.' - Debug: '.print_r($phpThumb->debugmessages,true));
+ $modx->log(modX::LOG_LEVEL_ERROR, '[phpThumbOf] Could not generate thumbnail: ' . $src . ' - Debug: ' . print_r($phpThumb->debugmessages, true));
}
}
if (!headers_sent()) {
- $phpThumb->setOutputFormat();
+ $headers = $modx->request->getHeaders();
+ $mtime = filemtime($cacheKey);
+ if (isset($headers['If-Modified-Since']) && strtotime($headers['If-Modified-Since']) == $mtime) {
+ // cache is good, send 304
+ header('Last-Modified: '.gmdate('D, d M Y H:i:s', $mtime).' GMT', true, 304);
+ exit();
+ }
+ header('Last-Modified: '.gmdate('D, d M Y H:i:s', $mtime).' GMT', true, 200);
+ $phpThumb->setOutputFormat();
header('Content-Type: '.phpthumb_functions::ImageTypeToMIMEtype($phpThumb->thumbnailFormat));
header('Content-Disposition: inline; filename="'.basename($src).'"');
}
-return file_get_contents($cacheKey);
\ No newline at end of file
+
+return file_get_contents($cacheKey);
diff --git a/readme.md b/readme.md
index a66b98c..cda7759 100644
--- a/readme.md
+++ b/readme.md
@@ -18,5 +18,5 @@ For setting up the custom TV, create a TV with Input and Output types of
Documentation
=============
Please see the official documentation at:
-http://rtfm.modx.com/display/ADDON/Gallery/
+http://rtfm.modx.com/extras/revo/gallery