<?phpswitch($modx->event->name){case'OnFileManagerUpload':foreach($filesas$f){// $modx->log(1, 'file: '.print_r($f,1));$addDir='';if(isset($_POST['p_id'])andisset($_POST['tv_id']))$addDir=date('Y').'/'.date('m').'/'.$_POST['p_id'].'/';$currentdoc=$modx->newObject('modResource');$f['name']=$currentdoc->cleanAlias($f['name']);if(explode("/",$f['type'])[0]=="image"){$thms=$modx->fromJSON($thumbs);foreach($thmsas$thumb){//Directory check//$modx->log(MODx::LOG_LEVEL_ERROR,print_r($source->toArray(),true));if($source){$arr=$source->toArray();$directory=$arr['properties']['basePath']['value'];if($source->id==16)$directory.=$addDir;}if(!file_exists(MODX_BASE_PATH.$directory.$thumb['name'])){mkdir(MODX_BASE_PATH.$directory.$thumb['name'],0775,true);}if(!class_exists('modPhpThumb')){/** @noinspection PhpIncludeInspection */requireMODX_CORE_PATH.'model/phpthumb/modphpthumb.class.php';}$phpThumb=newmodPhpThumb($modx);$phpThumb->initialize();// Указываем исходник$phpThumb->setSourceFilename(str_replace('//','/',MODX_BASE_PATH.$directory.$f['name']));// Выставляем параметрыforeach($thumb['props']as$k=>$v){$phpThumb->setParameter($k,$v);}// Генерируем уменьшенную копиюif($phpThumb->GenerateThumbnail()){if(!$phpThumb->renderToFile(MODX_BASE_PATH.$directory.$thumb['name']."/".$f['name'])){$modx->log(modX::LOG_LEVEL_ERROR,'Could not save rendered image to'.MODX_BASE_PATH.$directory.$thumb['name']."/".$f['name']);}}else{// Если возникла ошибка - пишем лог работы в журнал MODX$modx->log(modX::LOG_LEVEL_ERROR,print_r($phpThumb->debugmessages,1));}}}}break;case'OnMODXInit':if(empty($_FILES))return;foreach($_FILESas&$file){$currentdoc=$modx->newObject('modResource');$file['name']=str_replace(' ','-',$currentdoc->cleanAlias($file['name']));}break;}
Comments (0)
HTTPSSSH
You can clone a snippet to your computer for local editing.
Learn more.