/** * Process a file upload. * * @param string $objectType Currently treated entity type. * @param string $fileData Form data array. * @param string $fieldName Name of upload field. * * @return array Resulting file name and collected meta data. */ public function performFileUpload($objectType, $fileData, $fieldName) { $dom = ZLanguage::getModuleDomain('MUBoard'); $result = array('fileName' => '', 'metaData' => array()); // check whether uploads are allowed for the given object type if (!in_array($objectType, $this->allowedObjectTypes)) { return $result; } // perform validation if (!$this->validateFileUpload($objectType, $fileData[$fieldName], $fieldName)) { // skip this upload field return false; //$result; } // retrieve the final file name $fileName = $fileData[$fieldName]['name']; $fileNameParts = explode('.', $fileName); $extension = $fileNameParts[count($fileNameParts) - 1]; $extension = str_replace('jpeg', 'jpg', strtolower($extension)); $fileNameParts[count($fileNameParts) - 1] = $extension; $fileName = implode('.', $fileNameParts); // retrieve the final file name $basePath = MUBoard_Util_Controller::getFileBaseFolder($objectType, $fieldName); $fileName = $this->determineFileName($objectType, $fieldName, $basePath, $fileName, $extension); if (!move_uploaded_file($fileData[$fieldName]['tmp_name'], $basePath . $fileName)) { return LogUtil::registerError(__('Error! Could not move your file to the destination folder.', $dom)); } // collect data to return $result['fileName'] = $fileName; $result['metaData'] = $this->readMetaDataForFile($fileName, $basePath . $fileName); return $result; }
/** * Post-Process the data after the entity has been constructed by the entity manager. * The event happens after the entity has been loaded from database or after a refresh call. * * Restrictions: * - no access to entity manager or unit of work apis * - no access to associations (not initialised yet) * * @see MUBoard_Entity_Rank::postLoadCallback() * @return boolean true if completed successfully else false. */ protected function performPostLoadCallback() { // echo 'loaded a record ...'; $currentType = FormUtil::getPassedValue('type', 'user', 'GETPOST', FILTER_SANITIZE_STRING); $currentFunc = FormUtil::getPassedValue('func', 'main', 'GETPOST', FILTER_SANITIZE_STRING); // initialise the upload handler $uploadManager = new MUBoard_UploadHandler(); $this['id'] = (int) (isset($this['id']) && !empty($this['id']) ? DataUtil::formatForDisplay($this['id']) : 0); if ($currentFunc != 'edit') { $this['name'] = isset($this['name']) && !empty($this['name']) ? DataUtil::formatForDisplayHTML($this['name']) : ''; } $this['minPostings'] = (int) (isset($this['minPostings']) && !empty($this['minPostings']) ? DataUtil::formatForDisplay($this['minPostings']) : 0); $this['maxPostings'] = (int) (isset($this['maxPostings']) && !empty($this['maxPostings']) ? DataUtil::formatForDisplay($this['maxPostings']) : 0); $this['numberOfIcons'] = (int) (isset($this['numberOfIcons']) && !empty($this['numberOfIcons']) ? DataUtil::formatForDisplay($this['numberOfIcons']) : 0); if (!empty($this['uploadImage'])) { $basePath = MUBoard_Util_Controller::getFileBaseFolder('rank', 'uploadImage'); $fullPath = $basePath . $this['uploadImage']; $this['uploadImageFullPath'] = $fullPath; $this['uploadImageFullPathURL'] = System::getBaseUrl() . $fullPath; // just some backwards compatibility stuff if (!isset($this['uploadImageMeta']) || !is_array($this['uploadImageMeta']) || !count($this['uploadImageMeta'])) { // assign new meta data $this['uploadImageMeta'] = $uploadManager->readMetaDataForFile($this['uploadImage'], $fullPath); } } $this['special'] = (bool) $this['special']; $this->prepareItemActions(); return true; }
/** * Install the MUBoard application. * * @return boolean True on success, or false. */ public function install() { $basePath = MUBoard_Util_Controller::getFileBaseFolder('posting', 'firstImage'); if (!is_dir($basePath)) { return LogUtil::registerError($this->__f('The upload folder "%s" does not exist. Please create it before installing this application.', array($basePath))); } if (!is_writable($basePath)) { return LogUtil::registerError($this->__f('The upload folder "%s" is not writable. Please change permissions accordingly before installing this application.', array($basePath))); } $basePath = MUBoard_Util_Controller::getFileBaseFolder('posting', 'secondImage'); if (!is_dir($basePath)) { return LogUtil::registerError($this->__f('The upload folder "%s" does not exist. Please create it before installing this application.', array($basePath))); } if (!is_writable($basePath)) { return LogUtil::registerError($this->__f('The upload folder "%s" is not writable. Please change permissions accordingly before installing this application.', array($basePath))); } $basePath = MUBoard_Util_Controller::getFileBaseFolder('posting', 'thirdImage'); if (!is_dir($basePath)) { return LogUtil::registerError($this->__f('The upload folder "%s" does not exist. Please create it before installing this application.', array($basePath))); } if (!is_writable($basePath)) { return LogUtil::registerError($this->__f('The upload folder "%s" is not writable. Please change permissions accordingly before installing this application.', array($basePath))); } $basePath = MUBoard_Util_Controller::getFileBaseFolder('posting', 'firstFile'); if (!is_dir($basePath)) { return LogUtil::registerError($this->__f('The upload folder "%s" does not exist. Please create it before installing this application.', array($basePath))); } if (!is_writable($basePath)) { return LogUtil::registerError($this->__f('The upload folder "%s" is not writable. Please change permissions accordingly before installing this application.', array($basePath))); } $basePath = MUBoard_Util_Controller::getFileBaseFolder('posting', 'secondFile'); if (!is_dir($basePath)) { return LogUtil::registerError($this->__f('The upload folder "%s" does not exist. Please create it before installing this application.', array($basePath))); } if (!is_writable($basePath)) { return LogUtil::registerError($this->__f('The upload folder "%s" is not writable. Please change permissions accordingly before installing this application.', array($basePath))); } $basePath = MUBoard_Util_Controller::getFileBaseFolder('posting', 'thirdFile'); if (!is_dir($basePath)) { return LogUtil::registerError($this->__f('The upload folder "%s" does not exist. Please create it before installing this application.', array($basePath))); } if (!is_writable($basePath)) { return LogUtil::registerError($this->__f('The upload folder "%s" is not writable. Please change permissions accordingly before installing this application.', array($basePath))); } $basePath = MUBoard_Util_Controller::getFileBaseFolder('rank', 'uploadImage'); if (!is_dir($basePath)) { return LogUtil::registerError($this->__f('The upload folder "%s" does not exist. Please create it before installing this application.', array($basePath))); } if (!is_writable($basePath)) { return LogUtil::registerError($this->__f('The upload folder "%s" is not writable. Please change permissions accordingly before installing this application.', array($basePath))); } // create all tables from according entity definitions try { DoctrineHelper::createSchema($this->entityManager, $this->listEntityClasses()); } catch (Exception $e) { if (System::isDevelopmentMode()) { LogUtil::registerError($this->__('Doctrine Exception: ') . $e->getMessage()); } return LogUtil::registerError($this->__f('An error was encountered while creating the tables for the %s module.', array($this->getName()))); } // set up all our vars with initial values $this->setVar('uploadImages', false); $this->setVar('allowedSizeOfImages', 0); $this->setVar('numberImages', array('1')); $this->setVar('uploadFiles', false); $this->setVar('allowedSizeOfFiles', 0); $this->setVar('numberFiles', array('1')); $this->setVar('editPostings', false); $this->setVar('editTime', 6); $this->setVar('latestPostings', 1); $this->setVar('sortingPostings', array('descending')); $this->setVar('iconSet', array('1')); $this->setVar('template', array('normal')); $this->setVar('pagesize', 10); $this->setVar('standardIcon', 'images/icons/extrasmall/favorites.png'); $this->setVar('specialIcon', 'images/icons/extrasmall/package_favorite.png'); $this->setVar('showStatisticInDetails', true); $this->setVar('showStatisticOnBottom', false); // create the default data for MUBoard $this->createDefaultData(); // register persistent event handlers $this->registerPersistentEventHandlers(); // register hook subscriber bundles HookUtil::registerSubscriberBundles($this->version->getHookSubscriberBundles()); // initialisation successful return true; }
/** * 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; }