/** * Check the information received from the form of creation of a submenu item and call the api function to create it * @author: Albert Pérez Monfort (aperezm@xtec.cat) * @param: Array with the form information needed in case the form is reloaded * @return: Redirect to the main admin page */ public function create_sub($args) { // Get parameters from whatever input we need $text = FormUtil::getPassedValue('text', isset($args['text']) ? $args['text'] : null, 'POST'); $url = FormUtil::getPassedValue('url', isset($args['url']) ? $args['url'] : null, 'POST'); $descriu = FormUtil::getPassedValue('descriu', isset($args['descriu']) ? $args['descriu'] : null, 'POST'); $icon = FormUtil::getPassedValue('icon', isset($args['icon']) ? $args['icon'] : null, 'FILES'); $target = FormUtil::getPassedValue('target', isset($args['target']) ? $args['target'] : null, 'POST'); $grup = FormUtil::getPassedValue('grup', isset($args['grup']) ? $args['grup'] : null, 'POST'); $active = FormUtil::getPassedValue('active', isset($args['active']) ? $args['active'] : null, 'POST'); $mid = FormUtil::getPassedValue('mid', isset($args['mid']) ? $args['mid'] : null, 'POST'); $level = FormUtil::getPassedValue('level', isset($args['level']) ? $args['level'] : null, 'POST'); // Security check if (!SecurityUtil::checkPermission('IWmenu::', '::', ACCESS_ADMIN)) { throw new Zikula_Exception_Forbidden(); } // Confirm authorisation code $this->checkCsrfToken(); // Construct the group string $groups = '$' . $grup . '$'; $textSerialized = serialize($text); $urlSerialized = serialize($url); // Create a submenu item $lid = ModUtil::apiFunc('IWmenu', 'admin', 'create_sub', array('mid' => $mid, 'text' => $textSerialized, 'descriu' => $descriu, 'active' => $active, 'target' => $target, 'url' => $urlSerialized, 'groups' => $groups, 'id_parent' => $mid, 'level' => $level, 'icon' => $icon)); if ($lid != false) { if ($icon['name'] != '') { $iconsFolderPath = ModUtil::getVar('IWmain', 'documentRoot') . '/' . ModUtil::getVar('IWmenu', 'imagedir'); // get file extension $fileName = $icon['name']; $fileExtension = FileUtil::getExtension(strtolower($fileName)); $fileNewName = $lid . '.' . $fileExtension; if ($fileExtension == 'gif' || $fileExtension == 'png' || $fileExtension == 'jpg') { $destination = $iconsFolderPath . '/' . $fileNewName; if (!move_uploaded_file($icon['tmp_name'], $destination)) { LogUtil::registerError($this->__("The item has been created without the icon because the upload of the file has failed.")); return System::redirect(ModUtil::url('IWmenu', 'admin', 'main')); } $width = 16; $height = 16; // thumbnail image to $width (max.) x $height (max.) $sv = ModUtil::func('IWmain', 'user', 'genSecurityValue'); $msg = ModUtil::func('IWmain', 'user', 'thumbnail', array('sv' => $sv, 'imgSource' => $destination, 'imgDest' => $destination, 'widthImg' => $width, 'heightImg' => $height)); if ($msg != '') { LogUtil::registerError($msg); return System::redirect(ModUtil::url('IWmenu', 'admin', 'main')); } } else { LogUtil::registerError($this->__("The item has been created without the icon because the file extension for the icon is not valid.")); return System::redirect(ModUtil::url('IWmenu', 'admin', 'main')); } // change the image name acording with the new name ModUtil::apiFunc('IWmenu', 'admin', 'updateIcon', array('mid' => $lid, 'icon' => $fileNewName)); } // Successfull creation LogUtil::registerStatus($this->__('A new option has been created')); // Reorder the menu items ModUtil::func('IWmenu', 'admin', 'reorder', array('id_parent' => $mid)); // Reset the users menus for all users $sv = ModUtil::func('IWmain', 'user', 'genSecurityValue'); ModUtil::func('IWmain', 'user', 'usersVarsDelModule', array('module' => 'IWmenu', 'name' => 'userMenu', 'sv' => $sv)); } // Redirect to admin main page return System::redirect(ModUtil::url('IWmenu', 'admin', 'main')); }
/** * Get a concrete filename for automagically created content. * * @param string $path The base path. * @param string $auto_source The file name (optional). * @param string $auto_id The ID (optional). * * @return string The concrete path and file name to the content. */ public function _get_auto_filename($path, $auto_source = null, $auto_id = null, $themedir = null) { // enables a flags to detect when is treating compiled templates $tocompile = $path == $this->compile_dir ? true : false; // format auto_source for os to make sure that id does not contain 'ugly' characters $auto_source = DataUtil::formatForOS($auto_source); // build a hierarchical directory path $path .= '/' . $this->modinfo['directory']; if ($this instanceof Zikula_View_Plugin) { $path .= '_' . $this->getPluginName(); } // add the cache_id path if set $path .= !empty($auto_id) ? '/' . $auto_id : ''; // takes in account the source subdirectory if ($auto_source) { if (strpos($auto_source, 'file:') === 0) { // This is an absolute path needing special handling. $auto_source = substr($auto_source, 5); $cwd = DataUtil::formatForOS(getcwd()); if (strpos($auto_source, $cwd) !== 0) { throw new \RuntimeException('The template path cannot be outside the Zikula root.'); } $path .= '/absolutepath' . substr(dirname($auto_source), strlen($cwd)); } else { $path .= strpos($auto_source, '/') !== false ? '/' . dirname($auto_source) : ''; } } // make sure the path exists to write the compiled/cached template there if (!file_exists($path)) { mkdir($path, $this->serviceManager['system.chmod_dir'], true); } // if there's a explicit source, it if ($auto_source) { $path .= '/'; $extension = FileUtil::getExtension($auto_source); // isolates the filename on the source path passed $path .= FileUtil::getFilebase($auto_source); // add theme and language to our path if (empty($themedir)) { $themedir = $this->themeinfo['directory']; } $path .= '--t_' . $themedir . '-l_' . $this->language; // if we are not compiling, end with a suffix if (!$tocompile) { $path .= $extension ? ".{$extension}" : ''; } } return $path; }
/** * Get a concrete filename for automagically created content. * * Generates a filename path like: Theme / auto_id [/ source_dir / filename-l{lang}.ext] * the final part gets generated only if $auto_source is specified. * * @param string $path The base path. * @param string $auto_source The file name (optional). * @param string $auto_id The ID (optional). * * @return string The concrete path and file name to the content. */ public function _get_auto_filename($path, $auto_source = null, $auto_id = null, $themedir = null) { // enables a flags to detect when is treating compiled templates $tocompile = $path == $this->compile_dir ? true : false; // format auto_source for os to make sure that id does not contain 'ugly' characters $auto_source = DataUtil::formatForOS($auto_source); // add the Theme name as first folder if (empty($themedir)) { $path .= '/' . $this->directory; } else { $path .= '/' . $themedir; } // the last folder is the cache_id if set $path .= !empty($auto_id) ? '/' . $auto_id : ''; // takes in account the source subdirectory $path .= strpos($auto_source, '/') !== false ? '/' . dirname($auto_source) : ''; // make sure the path exists to write the compiled/cached template there if (!file_exists($path)) { mkdir($path, $this->serviceManager['system.chmod_dir'], true); } // if there's a explicit source, it if ($auto_source) { $path .= '/'; $extension = FileUtil::getExtension($auto_source); // isolates the filename on the source path passed $path .= FileUtil::getFilebase($auto_source); // if we are compiling we do not include cache variables if (!$tocompile) { // add the variable stuff only if $auto_source is present // to allow a easy flush cache for all the languages (if needed) $path .= '-l'; if (System::getVar('multilingual') == 1) { $path .= $this->language; } // end with a suffix convention of filename--Themename-lang.ext $path .= $extension ? ".{$extension}" : ''; } } return $path; }
/** * Deletes an existing upload file. * For images the thumbnails are removed, too. * * @param string $objectType Currently treated entity type. * @param string $objectData Object data array. * @param string $fieldName Name of upload field. * @param integer $objectId Primary identifier of the given object. * * @return mixed Array with updated object data on success, else false. */ public function deleteUploadFile($objectType, $objectData, $fieldName, $objectId) { if (!in_array($objectType, $this->allowedObjectTypes)) { return false; } if (empty($objectData[$fieldName])) { return $objectData; } $serviceManager = ServiceUtil::getManager(); $controllerHelper = new MUVideo_Util_Controller($serviceManager); // determine file system information try { $basePath = $controllerHelper->getFileBaseFolder($objectType, $fieldName); } catch (\Exception $e) { LogUtil::registerError($e->getMessage()); } $fileName = $objectData[$fieldName]; // path to original file $filePath = $basePath . $fileName; // check whether we have to consider thumbnails, too $fileExtension = FileUtil::getExtension($fileName, false); if (in_array($fileExtension, $this->imageFileTypes) && $fileExtension != 'swf') { // remove thumbnail images as well $manager = ServiceUtil::getManager()->getService('systemplugin.imagine.manager'); $manager->setModule('MUVideo'); $fullObjectId = $objectType . '-' . $objectId; $manager->removeImageThumbs($filePath, $fullObjectId); } // remove original file if (!unlink($filePath)) { return false; } $objectData[$fieldName] = ''; $objectData[$fieldName . 'Meta'] = array(); return $objectData; }
/** * Import several users from a CSV file. Checks needed values and format. * * Parameters passed via GET: * -------------------------- * None. * * Parameters passed via POST: * --------------------------- * None. * * Parameters passed via SESSION: * ------------------------------ * None. * * @param array $importFile Information about the file to import. Used as the default * if $_FILES['importFile'] is not set. Allows this function to be called internally, * rather than as a result of a form post. * @param integer $delimiter A code indicating the delimiter used in the file. Used as the * default if $_POST['delimiter'] is not set. Allows this function to be called internally, * rather than as a result of a form post. * * @return a empty message if success or an error message otherwise */ protected function uploadImport(array $importFile, $delimiter) { // get needed values $is_admin = (SecurityUtil::checkPermission('Users::', '::', ACCESS_ADMIN)) ? true : false; $minpass = $this->getVar('minpass'); $defaultGroup = ModUtil::getVar('Groups', 'defaultgroup'); // Create output object; // calcs $pregcondition needed to verify illegal usernames $reg_illegalusername = $this->getVar('reg_Illegalusername'); $pregcondition = ''; if (!empty($reg_illegalusername)) { $usernames = explode(" ", $reg_illegalusername); $count = count($usernames); $pregcondition = "/(("; for ($i = 0; $i < $count; $i++) { if ($i != $count-1) { $pregcondition .= $usernames[$i] . ")|("; } else { $pregcondition .= $usernames[$i] . "))/iAD"; } } } // get available groups $allGroups = ModUtil::apiFunc('Groups', 'user', 'getall'); // create an array with the groups identities where the user can add other users $allGroupsArray = array(); foreach ($allGroups as $group) { if (SecurityUtil::checkPermission('Groups::', $group['gid'] . '::', ACCESS_EDIT)) { $allGroupsArray[] = $group['gid']; } } // check if the user's email must be unique $reg_uniemail = $this->getVar('reg_uniemail'); // get the CSV delimiter switch ($delimiter) { case 1: $delimiterChar = ","; break; case 2: $delimiterChar = ";"; break; case 3: $delimiterChar = ":"; break; } // check that the user have selected a file $fileName = $importFile['name']; if ($fileName == '') { return $this->__("Error! You have not chosen any file."); } // check if user have selected a correct file if (FileUtil::getExtension($fileName) != 'csv') { return $this->__("Error! The file extension is incorrect. The only allowed extension is csv."); } // read the choosen file if (!$lines = file($importFile['tmp_name'])) { return $this->__("Error! It has not been possible to read the import file."); } $expectedFields = array('uname', 'pass', 'email', 'activated', 'sendmail', 'groups'); $counter = 0; $importValues = array(); // read the lines and create an array with the values. Check if the values passed are correct and set the default values if it is necessary foreach ($lines as $line_num => $line) { $line = str_replace('"', '', trim($line)); if ($counter == 0) { // check the fields defined in the first row $firstLineArray = explode($delimiterChar, $line); foreach ($firstLineArray as $field) { if (!in_array(trim(strtolower($field)), $expectedFields)) { return $this->__f("Error! The import file does not have the expected field %s in the first row. Please check your import file.", array($field)); } } $counter++; continue; } // get and check the second and following lines $lineArray = array(); $lineArray = DataUtil::formatForOS(explode($delimiterChar, $line)); // check if the line have all the needed values if (count($lineArray) != count($firstLineArray)) { return $this->__f('Error! The number of parameters in line %s is not correct. Please check your import file.', $counter); } $importValues[] = array_combine($firstLineArray, $lineArray); // check all the obtained values // check user name $uname = trim($importValues[$counter - 1]['uname']); if ($uname == '' || strlen($uname) > 25) { return $this->__f('Sorry! The user name is not valid in line %s. The user name is mandatory and the maximum length is 25 characters. Please check your import file.', $counter); } // check if it is a valid user name // admins are allowed to add any usernames, even those defined as being illegal if (!$is_admin && $pregcondition != '') { // check for illegal usernames if (preg_match($pregcondition, $uname)) { return $this->__f('Sorry! The user name %1$s is reserved and cannot be registered in line %2$s. Please check your import file.', array($uname, $counter)); } } // check if the user name is valid because spaces or invalid characters if (preg_match("/[[:space:]]/", $uname) || !System::varValidate($uname, 'uname')) { return $this->__f('Sorry! The user name %1$s cannot contain spaces in line %2$s. Please check your import file.', array($uname, $counter)); } // check if the user name is repeated if (in_array($uname, $usersArray)) { return $this->__f('Sorry! The user name %1$s is repeated in line %2$s, and it cannot be used twice for creating accounts. Please check your import file.', array($uname, $counter)); } $usersArray[] = $uname; // check password $pass = (string)trim($importValues[$counter - 1]['pass']); if ($pass == '') { return $this->__f('Sorry! You did not provide a password in line %s. Please check your import file.', $counter); } // check password length if (strlen($pass) < $minpass) { return $this->__f('Sorry! The password must be at least %1$s characters long in line %2$s. Please check your import file.', array($minpass, $counter)); } // check email $email = trim($importValues[$counter - 1]['email']); if ($email == '') { return $this->__f('Sorry! You did not provide a email in line %s. Please check your import file.', $counter); } // check email format if (!System::varValidate($email, 'email')) { return $this->__f('Sorry! The e-mail address you entered was incorrectly formatted or is unacceptable for other reasons in line %s. Please check your import file.', $counter); } // check if email is unique only if it is necessary if ($reg_uniemail == 1) { if (in_array($email, $emailsArray)) { return $this->__f('Sorry! The %1$s e-mail address is repeated in line %2$s, and it cannot be used twice for creating accounts. Please check your import file.', array($email, $counter)); } $emailsArray[] = $email; } // validate activation value $importValues[$counter - 1]['activated'] = isset($importValues[$counter - 1]['activated']) ? (int)$importValues[$counter - 1]['activated'] : Users_Constant::ACTIVATED_ACTIVE; $activated = $importValues[$counter - 1]['activated']; if (($activated != Users_Constant::ACTIVATED_INACTIVE) && ($activated != Users_Constant::ACTIVATED_ACTIVE)) { return $this->__f('Error! The CSV is not valid: the "activated" column must contain 0 or 1 only.'); } // validate sendmail $importValues[$counter - 1]['sendmail'] = isset($importValues[$counter - 1]['sendmail']) ? (int)$importValues[$counter - 1]['sendmail'] : 0; if ($importValues[$counter - 1]['sendmail'] < 0 || $importValues[$counter - 1]['sendmail'] > 1) { return $this->__f('Error! The CSV is not valid: the "sendmail" column must contain 0 or 1 only.'); } // check groups and set defaultGroup as default if there are not groups defined $importValues[$counter - 1]['groups'] = isset($importValues[$counter - 1]['groups']) ? (int)$importValues[$counter - 1]['groups'] : ''; $groups = $importValues[$counter - 1]['groups']; if ($groups == '') { $importValues[$counter - 1]['groups'] = $defaultGroup; } else { $groupsArray = explode('|', $groups); foreach ($groupsArray as $group) { if (!in_array($group, $allGroupsArray)) { return $this->__f('Sorry! The identity of the group %1$s is not not valid in line %2$s. Perhaps it do not exist. Please check your import file.', array($group, $counter)); } } } $counter++; } // seams that the import file is formated correctly and its values are valid if (empty($importValues)) { return $this->__("Error! The import file does not have values."); } // check if users exists in database $usersInDB = ModUtil::apiFunc($this->name, 'admin', 'checkMultipleExistence', array('valuesarray' => $usersArray, 'key' => 'uname')); if ($usersInDB === false) { return $this->__("Error! Trying to read the existing user names in database."); } else { if (count($usersInDB) > 0) { return $this->__("Sorry! One or more user names really exist in database. The user names must be uniques."); } } // check if emails exists in data base in case the email have to be unique if ($reg_uniemail == 1) { $emailsInDB = ModUtil::apiFunc($this->name, 'admin', 'checkMultipleExistence', array('valuesarray' => $emailsArray, 'key' => 'email')); if ($emailsInDB === false) { return $this->__("Error! Trying to read the existing users' email addressess in database."); } else { if (count($emailsInDB) > 0) { return $this->__("Sorry! One or more users' email addresses exist in the database. Each user's e-mail address must be unique."); } } } // seems that the values in import file are ready. Procceed creating users if (!ModUtil::apiFunc($this->name, 'admin', 'createImport', array('importvalues' => $importValues))) { return $this->__("Error! The creation of users has failed."); } return ''; }
/** * List the files in server folder * @author: Albert Pérez Monfort * @param: args the folder name where to list the files and subfolders * @return: The list of files and folders */ public function getFiles($args) { $hook = FormUtil::getPassedValue('hook', isset($args['hook']) ? $args['hook'] : 0, 'GET'); $editor = FormUtil::getPassedValue('editor', isset($args['editor']) ? $args['editor'] : false, 'GET'); PageUtil::AddVar('javascript', 'modules/Files/javascript/getFiles.js'); // get arguments $root = FormUtil::getPassedValue('root', isset($args['root']) ? $args['root'] : null, 'REQUEST'); $lastFolder = isset($_SESSION['filesModuleLastFolder']) ? $_SESSION['filesModuleLastFolder'] : null; $folder = FormUtil::getPassedValue('folder', isset($args['folder']) ? $args['folder'] : null, 'REQUEST'); $folder = (is_null($folder) && !is_null($lastFolder) && is_null($root)) ? $lastFolder : $folder; $_SESSION['filesModuleLastFolder'] = $folder; $folder = str_replace("|", "/", $folder); // security check if (!SecurityUtil::checkPermission( 'Files::', '::', ACCESS_ADD) || !UserUtil::isLoggedIn()) { $errorMsg = $this->__('Sorry! You have not been granted access to this page.'); $this->view->assign('errorMsg', $errorMsg); $this->view->assign('external', 1); $this->view->display('Files_user_errorMsg.tpl'); exit; } $oFolder = $folder; // gets root folder for the user $check = ModUtil::func('Files', 'user', 'checkingModule'); if ($check['status'] != 'ok') { $this->view->assign('check', $check); return $this->view->fetch('Files_user_failedConf.tpl'); } $initFolderPath = $check['initFolderPath']; // check if the root folder exists if(!file_exists($initFolderPath)){ $errorMsg = $this->__('The server directory does not exist. Contact with the website administrator to solve this problem.'); $this->view->assign('errorMsg', $errorMsg); $this->view->assign('external', 1); $this->view->display('Files_user_errorMsg.tpl'); exit; } // protection. User can not navigate out their root folder if($folder == ".." || $folder == "."){ $errorMsg = $this->__('Invalid folder') . ': ' . $folder; $this->view->assign('errorMsg', $errorMsg); $this->view->assign('external', 1); $this->view->display('Files_user_errorMsg.tpl'); exit; } // get folder name $folderName = str_replace($initFolderPath . '/' , '', $folder); $folder = $initFolderPath . '/' . $folder; // users can not browser the thumbnails folders if(strpos($folder, '.tbn') !== false) { LogUtil::registerError($this->__('It is not possible to browse this folder')); return System::redirect(ModUtil::url('Files', 'external', 'getFiles', array('folder' => substr($folderName, 0, strrpos($folderName, '/'))))); } // needed arguments // check if the folder exists if(!file_exists($folder)){ $errorMsg = $this->__('Invalid folder').': '.$folderName; $this->view->assign('errorMsg', $errorMsg); $this->view->assign('external', 1); $this->view->display('Files_user_errorMsg.tpl'); exit; } // get user's disk use $userDiskUse = ModUtil::apiFunc('Files', 'user', 'get'); $usedSpace = $userDiskUse['diskUse']; // get user's allowed space $userAllowedSpace = ModUtil::func('Files', 'user', 'getUserQuota'); $maxDiskSpace = round($userAllowedSpace * 1024 * 1024); $percentage = round($usedSpace * 100 / $maxDiskSpace); $widthUsage = ($percentage > 100) ? 100 : $percentage; $usedSpaceArray = array('maxDiskSpace' => ModUtil::func('Files', 'user', 'diskUseFormat', array('value' => $maxDiskSpace)), 'percentage' => $percentage, 'usedDiskSpace' => ModUtil::func('Files', 'user', 'diskUseFormat', array('value' => $usedSpace)), 'widthUsage' => $widthUsage); // create output object $this->view = Zikula_View::getInstance('Files', false); // get folder files and subfolders $fileList = ModUtil::func('Files', 'user', 'dir_list', array('folder' => $folder, 'external' => 1, 'hook' => $hook, 'editor' => $editor)); sort($fileList['dir']); sort($fileList['file']); $notwriteable = (!is_writable($folder)) ? true : false; // check if it is a public directori $is_public = (!file_exists($folder.'/.locked')) ? true : false ; $this->view->assign('publicFolder', $is_public); $this->view->assign('folderPrev', substr($folderName, 0 , strrpos($folderName, '/'))); $folderPath = (SecurityUtil::checkPermission( 'Files::', '::', ACCESS_ADMIN)) ? $folderName : ModUtil::getVar('Files', 'usersFolder') . '/' . strtolower(substr(UserUtil::getVar('uname'), 0 , 1)) . '/' . UserUtil::getVar('uname') . '/' .$folderName; $imagesArray = array(); // get folder files and subfolders if(file_exists($folder . '/.tbn')) { $images = ModUtil::func('Files', 'user', 'dir_list', array('folder' => $folder . '/.tbn', 'external' => 1)); foreach($images['file'] as $file) { $fileExtension = FileUtil::getExtension($file['name']); if(in_array(strtolower($fileExtension), array('gif','png','jpg','jpeg'))) { list($width, $height) = getimagesize($folder . '/' . $file['name']); list($newWidth, $newHeight) = getimagesize($folder . '/.tbn/' . $file['name']); $factor = round($width/$newWidth,2); $imagesArray[] = array('name' => $file['name'], 'viewWidth' => $newWidth, 'width' => $width, 'viewHeight' => $newHeight, 'height' => $height, 'factor' => $factor); } } } $scribite_v4 = ModUtil::getVar('Files', 'scribite_v4'); $this->view->assign('scribite_v4', $scribite_v4); $scribite_v5 = ModUtil::getVar('Files', 'scribite_v5'); $this->view->assign('scribite_v5', $scribite_v5); $scribite_v4_name = ModUtil::getVar('Files', 'scribite_v4_name'); $this->view->assign('scribite_v4_name', $scribite_v4_name); $scribite_v5_name = ModUtil::getVar('Files', 'scribite_v5_name'); $this->view->assign('scribite_v5_name', $scribite_v5_name); $defaultPublic = ModUtil::getVar('Files', 'defaultPublic'); $this->view->assign('defaultPublic', $defaultPublic); $this->view->assign('editor', $editor); $this->view->assign('folderPath', DataUtil::formatForDisplay($folderPath)); $this->view->assign('folderName', DataUtil::formatForDisplay($folderName)); $this->view->assign('fileList', $fileList); $this->view->assign('hook', $hook); $this->view->assign('imagesArray', DataUtil::formatForDisplay($imagesArray)); $this->view->assign('usedSpace', $usedSpaceArray); $this->view->assign('notwriteable', $notwriteable); //path to zk jquery lib $js =new JCSSUtil; $scripts = $js->scriptsMap(); $jquery = $scripts['jquery']['path']; $this->view->assign('jquery',$jquery); return $this->view->display('Files_external_getFiles.tpl'); }
/** * Get a concrete filename for automagically created content. * * @param string $path The base path. * @param string $auto_source The file name (optional). * @param string $auto_id The ID (optional). * * @return string The concrete path and file name to the content. */ public function _get_auto_filename($path, $auto_source = null, $auto_id = null) { // enables a flags to detect when is treating compiled templates $tocompile = ($path == $this->compile_dir) ? true : false; // format auto_source for os to make sure that id does not contain 'ugly' characters $auto_source = DataUtil::formatForOS($auto_source); // build a hierarchical directory path $path .= '/' . $this->modinfo['directory']; if ($this instanceof Zikula_View_Plugin) { $path .= '_' . $this->pluginName; } // add the cache_id path if set $path .= !empty($auto_id) ? '/' . $auto_id : ''; // takes in account the source subdirectory $path .= strpos($auto_source, '/') !== false ? '/' . dirname($auto_source) : ''; // make sure the path exists to write the compiled/cached template there if (!file_exists($path)) { mkdir($path, $this->serviceManager['system.chmod_dir'], true); } // if there's a explicit source, it if ($auto_source) { $path .= '/'; $extension = FileUtil::getExtension($auto_source); // isolates the filename on the source path passed $path .= FileUtil::getFilebase($auto_source); // if we are compiling we do not include cache variables if (!$tocompile) { // add the variable stuff only if $auto_source is present // to allow a easy flush cache for all the themes/languages $path .= '--t_'.$this->themeinfo['directory'].'-l_' . $this->language; // end with a suffix convention of filename--Themename-lang.ext $path .= ($extension ? ".$extension" : ''); } } return $path; }
public function viewDocumentVersions($args) { $documentId = FormUtil::getPassedValue('documentId', isset($args['documentId']) ? $args['documentId'] : 0, 'GET'); // get document $documentOrigin = ModUtil::apiFunc($this->name, 'user', 'getDocument', array('documentId' => $documentId)); if (!$documentOrigin) { LogUtil::registerError($this->__('Document not found.')); return System::redirect(ModUtil::url($this->name, 'user', 'viewDocs')); } $documentOrigin['extension'] = FileUtil::getExtension($documentOrigin['fileName']); $documentOrigin['filesize'] = ModUtil::func($this->name, 'user', 'getReadableFileSize', array('filesize' => $documentOrigin['filesize'])); $categoryId = $documentOrigin['categoryId']; // check if user can access to this category $canAccess = ModUtil::func($this->name, 'user', 'canAccessCategory', array('categoryId' => $categoryId, 'accessType' => 'read', )); if (!$canAccess) { LogUtil::registerError($this->__('You can not access to this document.')); return System::redirect(ModUtil::url($this->name, 'user', 'viewDocs')); } // versions $documents = ModUtil::apiFunc($this->name, 'user', 'getDocumentVersions', array('documentId' => $documentId)); if (!$documents) { LogUtil::registerError($this->__('This document have not versions.')); return System::redirect(ModUtil::url($this->name, 'user', 'viewDocs', array('categoryId' => $categoryId))); } $usersList = $documentOrigin['cr_uid'] . '$$'; $users = array(); $canEdit = false; $canDelete = false; $canAdd = false; $canEditCategory = (SecurityUtil::checkPermission('IWdocmanager::', "$categoryId::", ACCESS_EDIT)) ? true : false; $canDeleteCategory = (SecurityUtil::checkPermission('IWdocmanager::', "$categoryId::", ACCESS_DELETE)) ? true : false; foreach ($documents as $document) { $extensionIcon['icon'] = ''; if ($document['fileName'] != '') { $extension = FileUtil::getExtension($document['fileName']); $extensionIcon = ($extension != '') ? ModUtil::func('IWmain', 'user', 'getMimetype', array('extension' => $extension)) : ''; } $documents[$document['documentId']]['extension'] = $extensionIcon['icon']; if ($document['authorName'] == '') { $usersList .= $document['cr_uid'] . '$$'; } $documents[$document['documentId']]['canEdit'] = false; $documents[$document['documentId']]['canDelete'] = false; if ($canEditCategory || ($document['validated'] == 0 && UserUtil::getVar('uid') == $document['cr_uid'] && DateUtil::makeTimestamp($document['cr_date']) + $this->getVar('editTime') * 30 > time())) { $documents[$document['documentId']]['canEdit'] = true; $canEdit = true; // in order to show edit icon in legend } if ($canDeleteCategory || ($document['validated'] == 0 && UserUtil::getVar('uid') == $document['cr_uid'] && DateUtil::makeTimestamp($document['cr_date']) + $this->getVar('deleteTime') * 30 > time())) { $documents[$document['documentId']]['canDelete'] = true; $canDelete = true; // in order to show delete icon in legend } $documents[$document['documentId']]['filesize'] = ModUtil::func($this->name, 'user', 'getReadableFileSize', array('filesize' => $document['filesize'])); } if ($usersList != '') { // get all users information $sv = ModUtil::func('IWmain', 'user', 'genSecurityValue'); $users = ModUtil::func('IWmain', 'user', 'getAllUsersInfo', array('sv' => $sv, 'info' => 'ncc', 'list' => $usersList)); } return $this->view->assign('documentOrigin', $documentOrigin) ->assign('documents', $documents) ->assign('canAdd', $canAdd) ->assign('users', $users) ->assign('canEdit', $canEdit) ->assign('canDelete', $canDelete) ->assign('versionsVision', 1) ->fetch('IWdocmanager_user_viewDocumentVersions.tpl'); }
/** * Importa les taules de entitats-gtaf i grups d'entitats a partir d'un csv a la base de dades de Sirius * * Esborra el contingut previ de les taules i importa el contingut del fitxer * * @return void Retorna a la funció *gtafEntitiesGest* amb els missatges d'execució */ public function importGtafEntities() { if (!SecurityUtil::checkPermission('Cataleg::', '::', ACCESS_ADMIN)) { return LogUtil::registerPermissionError(); } // get input values. Check for direct function call first because calling function might be either get or post if (isset($args) && is_array($args) && !empty($args)) { $confirmed = isset($args['confirmed']) ? $args['confirmed'] : false; $case = isset($args['case']) ? $args['case'] : false; } elseif (isset($args) && !is_array($args)) { throw new Zikula_Exception_Fatal(LogUtil::getErrorMsgArgs()); } elseif ($this->request->isGet()) { $confirmed = 1; } elseif ($this->request->isPost()) { $this->checkCsrfToken(); $confirmed = $this->request->request->get('confirmed', false); $case = $this->request->request->get('case',false); } if ($confirmed == 2) { if ($case == 'entities') { $caps = array( 'gtafEntityId' => 'gtafEntityId', 'nom' => 'nom', 'tipus' => 'tipus', 'gtafGroupId' => 'gtafGroupId' ); $caps_man = $caps; $taula = 'cataleg_gtafEntities'; $mes = "Importació d'entitats-gtaf"; $field_id = 'gtafEntityId'; } else { $caps = array( 'gtafGroupId' => 'gtafGroupId', 'nom' => 'nom', 'resp_uid' => 'resp_uid' ); $caps_man = array( 'gtafGroupId' => 'gtafGroupId', 'nom' => 'nom' ); $taula = 'cataleg_gtafGroups'; $mes = "Importació de grups d'entitats-gtaf"; $field_id = 'gtafGroupId'; } // get other import values $importFile = $this->request->files->get('importFile', isset($args['importFile']) ? $args['importFile'] : null); $fileName = $importFile['name']; $importResults = ''; if ($fileName == '') { $importResults = $this->__("No heu triat cap fitxer."); } elseif (FileUtil::getExtension($fileName) != 'csv') { $importResults = $this->__("L'extensió del fitxer ha de ser csv."); } elseif (!$file_handle = fopen($importFile['tmp_name'], 'r')) { $importResults = $this->__("No s'ha pogut llegir el fitxer csv."); } else { while (!feof($file_handle)) { $line = fgetcsv($file_handle, 1024, ';', '"'); if ($line != '') { $lines[] = $line; } } fclose($file_handle); // foreach ($lines as $line_num => $line) { if ($line_num != 0) { if (count($lines[0]) != count($line)) { $importResults .= $this->__("<div>Hi ha registres amb un número de camps incorrecte.</div>"); } else { $import[] = array_combine($lines[0], $line); $import_id[] = $line[0]; } } else { $difs = array_diff($line, $caps); $difs2 = array_diff($caps_man,$line); if (count($line) != count(array_unique($line))) { $importResults .= $this->__("<div>La capçalera del csv té columnes repetides.</div>"); } elseif (!in_array($field_id, $line)) { $importResults .= $this->__("<div>Falta el camp obligatori de la clau primària (id).</div>"); } elseif ($line[0] != $field_id) { $importResults .= $this->__("<div>El camp obligatori de la clau primària (id) ha d'ocupar el primer lloc.</div>"); } elseif (!empty($difs2)) { $importResults .= $this->__("<div>Falten camps obligatoris.</div>"); } elseif (!empty($difs)) { $importResults .= $this->__("div>El csv té camps incorrectes.</div>"); } } } if (count($import_id) != count(array_unique($import_id))) $importResults .= $this->__("<div>El fitxer té alguna id repetida.</div>"); } if ($importResults == '') { $old_reg = DBUtil::selectObjectCount($taula); DBUtil::deleteWhere($taula); $inserts = count($import); DBUtil::insertObjectArray($import, $taula); $this->registerStatus($mes); $this->registerStatus($this->__('La importació s\'ha realitzat correctament')); $this->registerStatus($this->__('Registres antics: ' . $old_reg . ' - Registres actuals: ' . $inserts)); return system::redirect(ModUtil::url('Cataleg', 'admin', 'gtafEntitiesGest')); } else { $this->view->assign('case',$case); $post_max_size = ini_get('post_max_size'); return $this->view->assign('importResults', isset($importResults) ? $importResults : '') ->assign('post_max_size', $post_max_size) ->fetch('admin/Cataleg_admin_importGtafEntities.tpl'); } } elseif ($confirmed == 1){ // shows the form $case = $this->request->query->get('case',false); $this->view->assign('case',$case); $post_max_size = ini_get('post_max_size'); return $this->view->assign('importResults', isset($importResults) ? $importResults : '') ->assign('post_max_size', $post_max_size) ->fetch('admin/Cataleg_admin_importGtafEntities.tpl'); } else { LogUtil::registerError($this->__('La petició no és vàlida')); return system::redirect(ModUtil::url('Cataleg', 'admin', 'gtafEntitiesGest')); } }
/** * Get a concrete filename for automagically created content. * * @param string $path The base path. * @param string $auto_source The file name (optional). * @param string $auto_id The ID (optional). * * @return string The concrete path and file name to the content. */ public function _get_auto_filename($path, $auto_source = null, $auto_id = null, $themedir = null) { // enables a flags to detect when is treating compiled templates $tocompile = $path == $this->compile_dir ? true : false; // format auto_source for os to make sure that id does not contain 'ugly' characters $auto_source = DataUtil::formatForOS($auto_source); // build a hierarchical directory path $path .= '/' . $this->modinfo['directory']; if ($this instanceof Zikula_View_Plugin) { $path .= '_' . $this->pluginName; } // add the cache_id path if set $path .= !empty($auto_id) ? '/' . $auto_id : ''; // takes in account the source subdirectory $path .= strpos($auto_source, '/') !== false ? '/' . dirname($auto_source) : ''; // make sure the path exists to write the compiled/cached template there if (!file_exists($path)) { mkdir($path, $this->container['system.chmod_dir'], true); } // if there's a explicit source, it if ($auto_source) { $path .= '/'; $extension = FileUtil::getExtension($auto_source); // isolates the filename on the source path passed $path .= FileUtil::getFilebase($auto_source); // add theme and language to our path if (empty($themedir)) { $themedir = $this->themeinfo['directory']; } $path .= '--t_' . $themedir . '-l_' . $this->language; // if we are not compiling, end with a suffix if (!$tocompile) { $path .= $extension ? ".{$extension}" : ''; } } return $path; }
/** * Unzip a zip file. * @author: Albert Pérez Monfort & Robert Barrera * @param: args * @return: True if success and false if not */ public function unzipFile($args) { $fileName = FormUtil::getPassedValue('fileName', isset($args['fileName']) ? $args['fileName'] : null, 'REQUEST'); $folder = FormUtil::getPassedValue('folder', isset($args['folder']) ? $args['folder'] : null, 'REQUEST'); $folder = str_replace("|", "/", $folder); $external = FormUtil::getPassedValue('external', isset($args['external']) ? $args['external'] : null, 'GET'); $hook = FormUtil::getPassedValue('hook', isset($args['hook']) ? $args['hook'] : null, 'GET'); $editor = FormUtil::getPassedValue('editor', isset($args['editor']) ? $args['editor'] : null, 'GET'); // security check if (!SecurityUtil::checkPermission('Files::', "::", ACCESS_ADD)) { return LogUtil::registerError($this->__('Error! You are not authorized to access this module.'), 403); } $returnType = ($external == 1) ? 'external' : 'user'; $returnFunc = ($external == 1) ? 'getFiles' : 'main'; $check = ModUtil::func('Files', 'user', 'checkingModule'); if ($check['status'] != 'ok') { $this->view->assign('check', $check); return $this->view->fetch('Files_user_failedConf.tpl'); } $initFolderPath = $check['initFolderPath']; // protection. User can not navigate out their root folder if ($folder == ".." || $folder == "." || strpos($folder, "..") !== false) { $errorMsg = $this->__('Invalid folder') . ': ' . $folder; $this->view->assign('errorMsg', $errorMsg); return $this->view->fetch('Files_user_errorMsg.tpl'); } $file = ($folder != "") ? $initFolderPath . "/" . $folder . "/" . $fileName : $initFolderPath . "/" . $fileName; require_once ('modules/Files/includes/pclzip.lib.php'); $archive = new PclZip($file); if (($list = $archive->listContent()) == 0) { LogUtil::registerError($this->__('Failed to list content zip file.') . ': ' . $fileName); $folder = str_replace("/", "|", $folder); return System::redirect(ModUtil::url('Files', $returnType, $returnFunc, array('folder' => $folder, 'hook' => $hook))); } $filesSize = 0; $allowedExtensions = ModUtil::getVar('Files', 'allowedExtensions'); $allowedExtensionsArray = explode(',', $allowedExtensions); foreach ($list as $file) { // calc the size of the file unziped $filesSize += $file['size']; // checks if user can unzip the file because the extensions into this file // get file extension $file_extension = FileUtil::getExtension($file['filename']); if ($file_extension != '') { if (!in_array(strtolower($file_extension), $allowedExtensionsArray) && !in_array(strtoupper(($file_extension)), $allowedExtensionsArray)) { LogUtil::registerError($this->__f('The zip file contains at least one file with the extension <strong>%s</strong> which is not allowed. The allowed extensions are: <strong>%s</strong>.', array( $file_extension, str_replace(',', ', ', $allowedExtensions)))); $folder = str_replace("/", "|", $folder); return System::redirect(ModUtil::url('Files', $returnType, $returnFunc, array('folder' => $folder, 'hook' => $hook))); } } } // check if user have enough space to unzip the file // get user used space in folder $userDiskUse = ModUtil::apiFunc('Files', 'user', 'get'); $usedSpace = $userDiskUse['diskUse']; // get user allowed space $userAllowedSpace = ModUtil::func('Files', 'user', 'getUserQuota') * 1024 * 1024; // check if user have enough space to unzip the file if ($filesSize + $usedSpace > $userAllowedSpace && $userAllowedSpace != -1048576) { LogUtil::registerError($this->__f('You have not enough disk space to unzip the file. You need %s extra bytes.', $filesSize + $usedSpace - $userAllowedSpace)); $folder = str_replace("/", "|", $folder); return System::redirect(ModUtil::url('Files', $returnType, $returnFunc, array('folder' => $folder, 'hook' => $hook))); } if ($archive->extract(PCLZIP_OPT_PATH, ($initFolderPath . "/" . $folder)) == 0) { LogUtil::registerError($this->__('Failed to unzip')); $folder = str_replace("/", "|", $folder); return System::redirect(ModUtil::url('Files', $returnType, $returnFunc, array('folder' => $folder, 'hook' => $hook))); } // update the number of bytes used by user ModUtil::apiFunc('Files', 'user', 'updateUsedSpace'); // protect the folders with the .htaccess and .locked files ModUtil::func('Files', 'user', 'createProtectFiles', array('folder' => $folder)); LogUtil::registerStatus($this->__('Successfully unzipped')); $folder = str_replace("/", "|", $folder); return System::redirect(ModUtil::url('Files', $returnType, $returnFunc, array('folder' => $folder, 'hook' => $hook, 'editor' => $editor))); }
/** * Count the valid uploaded pictures and mark them as resizable * convert status of news item to DRAFT if unsuccessful upload * * @author msshams * @author craigh * @param array $files * @param array $item * @return array ($files, $item) */ public static function validateImages($files, $item) { $uploadNoFile = false; $count = 0; $modvars = ModUtil::getVar('News'); $allowedExtensionsArray = explode(',', $modvars['picupload_allowext']); foreach ($files as $key => $file) { $files[$key]['resize'] = false; // set default to no resize if ($file['size'] > $modvars['picupload_maxfilesize']) { $file['error'] = UPLOAD_ERR_FORM_SIZE; } $dom = ZLanguage::getModuleDomain('News'); switch ($file['error']) { case UPLOAD_ERR_FORM_SIZE: $uploadNoFile = true; LogUtil::registerStatus(__f('Warning! Picture %s is not uploaded, since the filesize was too large (max. %s kB).', array($key+1, $modvars['picupload_maxfilesize']/1000), $dom)); break; case UPLOAD_ERR_NO_FILE: $uploadNoFile = true; break; case UPLOAD_ERR_INI_SIZE: case UPLOAD_ERR_PARTIAL: case UPLOAD_ERR_NO_TMP_DIR: case UPLOAD_ERR_CANT_WRITE: case UPLOAD_ERR_EXTENSION: $uploadNoFile = true; LogUtil::registerStatus(__f('Warning! Picture %1$s gave an error (code %2$s, explained on this page: %3$s) during uploading.', array($key+1, $error, 'http://php.net/manual/features.file-upload.errors.php'), $dom)); break; case UPLOAD_ERR_OK: $file_extension = FileUtil::getExtension($file['name']); if (!in_array(strtolower($file_extension), $allowedExtensionsArray) && !in_array(strtoupper(($file_extension)), $allowedExtensionsArray)) { LogUtil::registerStatus(__f('Warning! Picture %s is not uploaded, since the file extension is now allowed (only %s is allowed).', array($key+1, $modvars['picupload_allowext']), $dom)); } else { $files[$key]['resize'] = true; $count++; } break; } } $item['pictures'] = $count; // make the article draft when there is an upload error and ADD permission is present // TODO why only for ADD ??? if (($uploadNoFile) && SecurityUtil::checkPermission('News::', '::', ACCESS_ADD)) { $item['action'] = 6; } return array($files, $item); }
/** * create a thumbnail of an image * @author: Albert Pérez Monfort (aperezm@xtec.cat) * @param: imgSource => Path of the source of the image * @param: imgDest => Path of the destiny of the image * @param: widthImg => Maximum width of the image * @param: heightImg => Maximum height of the image * @return: True if success and false otherwise */ public function thumbnail($args) { $sv = FormUtil::getPassedValue('sv', isset($args['sv']) ? $args['sv'] : null, 'POST'); $imgSource = FormUtil::getPassedValue('imgSource', isset($args['imgSource']) ? $args['imgSource'] : null, 'POST'); $imgDest = FormUtil::getPassedValue('imgDest', isset($args['imgDest']) ? $args['imgDest'] : null, 'POST'); $widthImg = FormUtil::getPassedValue('widthImg', isset($args['widthImg']) ? $args['widthImg'] : 0, 'POST'); $heightImg = FormUtil::getPassedValue('heightImg', isset($args['heightImg']) ? $args['heightImg'] : 0, 'POST'); $imageName = FormUtil::getPassedValue('imageName', isset($args['imageName']) ? $args['imageName'] : null, 'POST'); if (!ModUtil::func('IWmain', 'user', 'checkSecurityValue', array('sv' => $sv))) { return LogUtil::registerError($this->__('You are not allowed to access to use this functionality.')); } $errorMsg = ''; if (($widthImg == 0 && $heightImg == 0) || $imgSource == null || $imgDest == null || !file_exists($imgSource)) { return $this->__('Error! The parameters receiver are not correct.'); } // seems that all the parameters required are available and the thumbnail is created $fileExtension = ($imageName != numm && $imageName != '') ? FileUtil::getExtension($imageName) : FileUtil::getExtension($imgSource); $thumbnailExtensions = array('gif', 'jpg', 'jpeg', 'png'); if (!in_array(strtolower($fileExtension), $thumbnailExtensions)) { return $this->__('Error! Thumbnailing the image file.'); } $format = ''; if (strtolower($fileExtension) == 'jpg' || strtolower($fileExtension) == 'jpeg') { $format = 'image/jpeg'; } elseif (strtolower($fileExtension) == 'gif') { $format = 'image/gif'; } elseif (strtolower($fileExtension) == 'png') { $format = 'image/png'; } // size calculation // get original image size list($width, $height) = getimagesize($imgSource); // set the default vaules like the original $newWidth = $width; $newHeight = $height; // fix the width to the value set in the module configuration (or lower if the image is smaller) and calc the height if ($widthImg > 0) { // fix the width $newWidth = ($width <= $widthImg) ? $width : $widthImg; $newHeight = $height * $newWidth / $width; if (($newHeight > $heightImg) && $heightImg > 0) { $newHeight = $heightImg; $newWidth = $width * $newHeight / $height; } } if ($heightImg > 0 && $widthImg == 0) { // fix the width $newHeight = ($height <= $heightImg) ? $height : $heightImg; $newWidth = $width * $newHeight / $height; } if (!$destimg = imagecreatetruecolor($newWidth, $newHeight)) { return $this->__('Error! Thumbnailing the image file.'); } // set alphablending to on imagesavealpha($destimg, true); imagealphablending($destimg, true); // create the image switch ($format) { case 'image/gif': if (!$srcimg = imagecreatefromgif($imgSource)) { return $this->__('Error! Thumbnailing the image file.'); } // preserve the transparency $transIndex = imagecolortransparent($srcimg); if ($transIndex >= 0) { // get transparent colors from the received image $transColor = imagecolorsforindex($srcimg, $transIndex); // allocate the color to the destiny image $transIndex = imagecolorallocate($destimg, $transColor['red'], $transColor['green'], $transColor['blue']); // fills the background of destiny image with the allocated color. imagefill($destimg, 0, 0, $transIndex); // set the background color for destiny image to transparent imagecolortransparent($destimg, $transIndex); } if (!imagecopyresampled($destimg, $srcimg, 0, 0, 0, 0, $newWidth, $newHeight, imagesx($srcimg), imagesy($srcimg))) { return $this->__('Error! Thumbnailing the image file.'); } if (!imagegif($destimg, $imgDest)) { return $this->__('Error! Thumbnailing the image file.'); } break; case 'image/jpeg': if (!$srcimg = imagecreatefromjpeg($imgSource)) { return $this->__('Error! Thumbnailing the image file.'); } if (!imagecopyresampled($destimg, $srcimg, 0, 0, 0, 0, $newWidth, $newHeight, ImageSX($srcimg), ImageSY($srcimg))) { return $this->__('Error! Thumbnailing the image file.'); } if (!imagejpeg($destimg, $imgDest)) { return $this->__('Error! Thumbnailing the image file.'); } break; case 'image/png': if (!$srcimg = imagecreatefrompng($imgSource)) { return $this->__('Error! Thumbnailing the image file.'); } // preserve the transparency // turns off transparency blending imagealphablending($destimg, false); // create a transparent color $color = imagecolorallocatealpha($destimg, 0, 0, 0, 127); // fills the background of the image with the allocated color. imagefill($destimg, 0, 0, $color); // turns on transparency blending imagesavealpha($destimg, true); if (!imagecopyresampled($destimg, $srcimg, 0, 0, 0, 0, $newWidth, $newHeight, ImageSX($srcimg), ImageSY($srcimg))) { return $this->__('Error! Thumbnailing the image file.'); } if (!imagepng($destimg, $imgDest)) { return $this->__('Error! Thumbnailing the image file.'); } break; } // frees image from memory imagedestroy($destimg); return ''; }
/** * Deletes an existing upload file. * For images the thumbnails are removed, too. * * @param string $objectType Currently treated entity type. * @param string $objectData Object data array. * @param string $fieldName Name of upload field. * * @return mixed Array with updated object data on success, else false. */ public function deleteUploadFile($objectType, $objectData, $fieldName) { if (!in_array($objectType, $this->allowedObjectTypes)) { return false; } if (empty($objectData[$fieldName])) { return $objectData; } // determine file system information $basePath = MUBoard_Util_Controller::getFileBaseFolder($objectType, $fieldName); $fileName = $objectData[$fieldName]; // remove original file if (!unlink($basePath . $fileName)) { return false; } $objectData[$fieldName] = ''; $objectData[$fieldName . 'Meta'] = array(); $fileExtension = FileUtil::getExtension($fileName, false); if (!in_array($fileExtension, $this->imageFileTypes)) { // we are done, so let's return return $objectData; } // get extension again, but including the dot $fileExtension = FileUtil::getExtension($fileName, true); $thumbFileNameBase = str_replace($fileExtension, '', $fileName) . '_tmb_'; $thumbFileNameBaseLength = strlen($thumbFileNameBase); // remove image thumbnails $thumbPath = $basePath . 'tmb/'; $thumbFiles = FileUtil::getFiles($thumbPath, false, true, null, 'f'); // non-recursive, relative pathes foreach ($thumbFiles as $thumbFile) { $thumbFileBase = substr($thumbFile, 0, $thumbFileNameBaseLength); if ($thumbFileBase != $thumbFileNameBase) { // let other thumbnails untouched continue; } unlink($thumbPath . $thumbFile); } return $objectData; }