diff --git a/_build/data/events/events.gallerycustomtv.php b/_build/data/events/events.gallerycustomtv.php index 76abcf6..565296e 100644 --- a/_build/data/events/events.gallerycustomtv.php +++ b/_build/data/events/events.gallerycustomtv.php @@ -29,6 +29,8 @@ $events = array(); $evs = array( + 'OnDocFormSave', + 'OnResourceDuplicate', 'OnTVInputRenderList', 'OnTVInputPropertiesList', 'OnTVOutputRenderList', diff --git a/assets/components/gallery/connector.php b/assets/components/gallery/connector.php index 8086d71..958ac59 100644 --- a/assets/components/gallery/connector.php +++ b/assets/components/gallery/connector.php @@ -47,7 +47,6 @@ if ($modx->user->hasSessionContext($modx->context->get('key'))) { $_SERVER['HTTP_MODAUTH'] = $_SESSION["modx.{$modx->context->get('key')}.user.token"]; } else { - $_SESSION["modx.{$modx->context->get('key')}.user.token"] = 0; $_SERVER['HTTP_MODAUTH'] = 0; } } else { @@ -61,4 +60,4 @@ $modx->request->handleRequest(array( 'processors_path' => $path, 'location' => '', -)); \ No newline at end of file +)); diff --git a/assets/components/gallery/css/fileuploader.css b/assets/components/gallery/css/fileuploader.css index 0625faf..0bae5d2 100644 --- a/assets/components/gallery/css/fileuploader.css +++ b/assets/components/gallery/css/fileuploader.css @@ -1,5 +1,11 @@ .qq-uploader { position:relative; width: 100%;} +.qq-uploader a { + display: inline-block; + margin-top: 10px; + text-decoration: none; +} + .qq-upload-button { display:block; /* or inline-block */ padding: 7px 0; @@ -11,6 +17,12 @@ margin-top: 10px; font-weight: bold; } +/* 2.3 style fixes */ +.qq-upload-button.x-btn { + border: 0; + padding: 10px 15px; + text-shadow: none; +} .qq-upload-button-hover {background:#5C7F17;} .qq-upload-button-focus {outline:1px dotted black;} diff --git a/assets/components/gallery/css/mgr.css b/assets/components/gallery/css/mgr.css index ac91c7d..892f230 100644 --- a/assets/components/gallery/css/mgr.css +++ b/assets/components/gallery/css/mgr.css @@ -6,25 +6,38 @@ .gal-item-inactive { opacity: 0.5; } -.green { color: green; } -.red { color: red; } +/* unnecessary as defined in default styles */ +/*.green { color: green; } +.red { color: red; }*/ .gal-detail-active { float: right; } .gal-view-item-albums { overflow:auto; - border-top: 1px solid #d4d4d4; - margin-top: 4px; + border-top: 1px solid #E4E4E4; + margin-top: 7px; } .gal-item-thumb { border: 1px solid #ddd; - padding: 5px 5px 3px; + padding: 5px; } .gal-item-update-preview { margin: 0 auto; text-align: center; padding: 2px; +} + +#gal-album-items-detail { + border-left: 1px solid #E4E4E4; + -webkit-box-sizing: border-box; + -moz-box-sizing: border-box; + box-sizing: border-box; + margin-left: 0 !important; /* override default modx theme styles for .x-column */ +} + +.modx-browser-thumb-wrap .gal-item-thumb { + height: 100px; } \ No newline at end of file diff --git a/assets/components/gallery/images/.DS_Store b/assets/components/gallery/images/.DS_Store new file mode 100644 index 0000000..5008ddf Binary files /dev/null and b/assets/components/gallery/images/.DS_Store differ diff --git a/assets/components/gallery/js/mgr/gallery.js b/assets/components/gallery/js/mgr/gallery.js index fba4de3..99753f7 100755 --- a/assets/components/gallery/js/mgr/gallery.js +++ b/assets/components/gallery/js/mgr/gallery.js @@ -16,8 +16,8 @@ GAL.window.CreateAlbum = function(config) { Ext.applyIf(config,{ title: _('gallery.album_create') ,id: this.ident - ,height: 150 - ,width: 650 + // ,height: 150 + ,width: 600 ,url: GAL.config.connector_url ,action: 'mgr/album/create' ,fields: [{ @@ -57,6 +57,12 @@ GAL.window.CreateAlbum = function(config) { },{ columnWidth: .5 ,items: [{ + xtype: 'textfield' + ,fieldLabel: _('gallery.year') + ,name: 'year' + ,anchor: '100%' + ,allowBlank: true + },{ xtype: 'checkbox' ,boxLabel: _('gallery.active') ,description: MODx.expandHelp ? '' : _('gallery.active_desc') @@ -104,8 +110,9 @@ GAL.window.UpdateItem = function(config) { title: _('gallery.item_update') ,id: this.ident ,closeAction: 'close' - ,height: 150 - ,width: '55%' + // ,height: 150 + // ,width: '55%' + ,width: 600 ,url: GAL.config.connector_url ,action: 'mgr/item/update' ,fileUpload: true @@ -177,6 +184,7 @@ GAL.window.UpdateItem = function(config) { ,name: 'id' ,fieldLabel: _('id') ,submitValue: true + ,anchor: '100%' },{ xtype: 'checkbox' ,boxLabel: _('gallery.active') @@ -218,9 +226,10 @@ GAL.window.UploadItem = function(config) { Ext.applyIf(config,{ title: _('gallery.item_upload') ,id: this.ident - ,height: 150 - ,width: '55%' - ,minWidth: 650 + // ,height: 150 + // ,width: '55%' + ,width: 600 + // ,minWidth: 650 ,url: GAL.config.connector_url ,action: 'mgr/item/upload' ,fileUpload: true @@ -235,7 +244,7 @@ GAL.window.UploadItem = function(config) { ,labelAlign: 'top' ,anchor: '100%' ,border: false - ,cls:'main-wrapper' + ,cls: (MODx.config.connector_url) ? '' : 'main-wrapper' // check for 2.3 ,labelSeparator: '' } ,items: [{ @@ -268,8 +277,8 @@ GAL.window.UploadItem = function(config) { },{ columnWidth: .5 ,items: [{ - xtype: 'textfield' - ,inputType: 'file' + xtype: (MODx.config.connector_url) ? 'fileuploadfield' : 'textfield' // check for 2.3 + ,inputType: (MODx.config.connector_url) ? 'text' : 'file' // check for 2.3 ,fieldLabel: _('gallery.file') ,description: MODx.expandHelp ? '' : _('gallery.item_upload_file_desc') ,name: 'file' @@ -327,9 +336,10 @@ GAL.window.UploadCover = function(config) { Ext.applyIf(config,{ title: _('gallery.cover_upload') ,id: this.ident - ,height: 150 - ,width: 350 - ,minWidth: 350 + // ,height: 150 + ,height: 300 // account for the preview thumbnail that is rendered after the window is opened + // ,width: 350 + // ,minWidth: 350 ,saveBtnText:_('gallery.upload_cover') ,url: GAL.config.connector_url ,action: 'mgr/album/uploadcover' @@ -344,7 +354,7 @@ GAL.window.UploadCover = function(config) { layout: 'form' ,labelAlign: 'top' ,border: false - ,cls:'main-wrapper' + ,cls: (MODx.config.connector_url) ? '' : 'main-wrapper' // check for 2.3 ,labelSeparator: '' } ,items: [{ @@ -353,8 +363,8 @@ GAL.window.UploadCover = function(config) { xtype:'hidden' ,name:'id' },{ - xtype: 'textfield' - ,inputType: 'file' + xtype: (MODx.config.connector_url) ? 'fileuploadfield' : 'textfield' // check for 2.3 + ,inputType: (MODx.config.connector_url) ? 'text' : 'file' // check for 2.3 ,fieldLabel: _('gallery.file') ,description: MODx.expandHelp ? '' : _('gallery.item_upload_file_desc') ,name: 'file' @@ -382,7 +392,7 @@ GAL.window.UploadMultiItems = function(config) { title: _('gallery.multi_item_upload') ,id: this.ident ,height: 350 - ,width: 475 + // ,width: 475 ,fields: [{ xtype: 'hidden' ,name: 'album' @@ -483,8 +493,8 @@ GAL.window.BatchUpload = function(config) { Ext.applyIf(config,{ title: _('gallery.batch_upload') ,id: this.ident - ,height: 150 - ,width: 500 + // ,height: 150 + // ,width: 600 ,url: GAL.config.connector_url ,action: 'mgr/item/batchupload' ,fileUpload: true @@ -547,8 +557,8 @@ GAL.window.ZipUpload = function(config) { Ext.applyIf(config,{ title: _('gallery.zip_upload') ,id: this.ident - ,height: 150 - ,width: 500 + // ,height: 150 + // ,width: 600 ,url: GAL.config.connector_url ,action: 'mgr/item/zipupload' ,fileUpload: true @@ -556,8 +566,8 @@ GAL.window.ZipUpload = function(config) { xtype: 'hidden' ,name: 'album' },{ - xtype: 'textfield' - ,inputType: 'file' + xtype: (MODx.config.connector_url) ? 'fileuploadfield' : 'textfield' // check for 2.3 + ,inputType: (MODx.config.connector_url) ? 'text' : 'file' // check for 2.3 ,fieldLabel: _('gallery.zip_file') ,description: MODx.expandHelp ? '' : _('gallery.zip_upload_intro') ,name: 'zip' diff --git a/assets/components/gallery/js/mgr/sections/album/update.js b/assets/components/gallery/js/mgr/sections/album/update.js index 82708ea..69de8fd 100644 --- a/assets/components/gallery/js/mgr/sections/album/update.js +++ b/assets/components/gallery/js/mgr/sections/album/update.js @@ -1,7 +1,3 @@ -Ext.onReady(function() { - MODx.load({ xtype: 'gal-page-album-update'}); -}); - GAL.page.UpdateAlbum = function(config) { config = config || {}; Ext.applyIf(config,{ @@ -9,6 +5,7 @@ GAL.page.UpdateAlbum = function(config) { ,buttons: [{ text: _('save') ,id: 'gal-btn-save' + ,cls: 'primary-button' ,process: 'mgr/album/update' ,method: 'remote' ,keys: [{ diff --git a/assets/components/gallery/js/mgr/sections/home.js b/assets/components/gallery/js/mgr/sections/home.js index 27c29c6..ba2c5b7 100644 --- a/assets/components/gallery/js/mgr/sections/home.js +++ b/assets/components/gallery/js/mgr/sections/home.js @@ -1,7 +1,3 @@ -Ext.onReady(function() { - MODx.load({ xtype: 'gal-page-home'}); -}); - GAL.page.Home = function(config) { config = config || {}; Ext.applyIf(config,{ diff --git a/assets/components/gallery/js/mgr/utils/fileuploader.js b/assets/components/gallery/js/mgr/utils/fileuploader.js index 19f4264..6be9f92 100644 --- a/assets/components/gallery/js/mgr/utils/fileuploader.js +++ b/assets/components/gallery/js/mgr/utils/fileuploader.js @@ -495,7 +495,7 @@ qq.FileUploader = function(o){ template: '
' + _('gallery.clearsuccessful') + ' | ' + '' + _('gallery.clearfailure') + '
' + 'Пожалуйста, сохраните документ и обновите страницу перед созданием галереи
+{/if} \ No newline at end of file diff --git a/core/components/gallery/elements/tv/input/galleryalbumview.class.php b/core/components/gallery/elements/tv/input/galleryalbumview.class.php new file mode 100644 index 0000000..5b3b50a --- /dev/null +++ b/core/components/gallery/elements/tv/input/galleryalbumview.class.php @@ -0,0 +1,9 @@ +modx->getOption('gallery.core_path',null, $this->modx->getOption('core_path').'components/gallery/').'elements/tv/galleryalbumview.input.tpl'; + } +} +return 'GalleryAlbumViewInputRender'; +?> \ No newline at end of file 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..892f1a6 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; -if (empty($ptOptions['f'])){ +if (empty($ptOptions['f'])) { $ext = pathinfo($src, PATHINFO_EXTENSION); $ext = strtolower($ext); switch ($ext) { @@ -37,55 +45,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 +120,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 +128,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