/** * Public function that creates a single instance */ public static function getInstance() { if (!isset(self::$_instance)) { self::$_instance = new self(); } return self::$_instance; }
/** * Upload Finished callback * * This is called as soon as uploads have finished. * takes care of moving them to the right folder * * @param string $tempPath Path to the temporary directory containing the files at this moment * @param string $tempWebPath Points to the same folder as tempPath, but relative to the webroot * @param array $data Data given to setData() when creating the uploader * @param string $uploadId unique session id for the current upload * @param array $fileInfos uploaded file informations * @param array $response uploaded status * * @return array path and webpath */ public static function uploadFinished($tempPath, $tempWebPath, $data, $uploadId, $fileInfos, $response) { $path = $data['path']; $webPath = $data['webPath']; $objCategory = Category::getCategory($data['category_id']); // check for sufficient permissions if ($objCategory->getAddFilesAccessId() && !\Permission::checkAccess($objCategory->getAddFilesAccessId(), 'dynamic', true) && $objCategory->getOwnerId() != \FWUser::getFWUserObject()->objUser->getId()) { return; } //we remember the names of the uploaded files here. they are stored in the session afterwards, //so we can later display them highlighted. $arrFiles = array(); $uploadFiles = array(); //rename files, delete unwanted $arrFilesToRename = array(); //used to remember the files we need to rename $h = opendir($tempPath); if (!$h) { return array($path, $webPath); } while (false !== ($file = readdir($h))) { //skip . and .. if ($file == '.' || $file == '..') { continue; } try { //delete potentially malicious files $objTempFile = new \Cx\Lib\FileSystem\File($tempPath . '/' . $file); if (!\FWValidator::is_file_ending_harmless($file)) { $objTempFile->delete(); continue; } $cleanFile = \Cx\Lib\FileSystem\FileSystem::replaceCharacters($file); if ($cleanFile != $file) { $objTempFile->rename($tempPath . '/' . $cleanFile, false); $file = $cleanFile; } $info = pathinfo($file); //check if file needs to be renamed $newName = ''; $suffix = ''; if (file_exists($path . '/' . $file)) { $suffix = '_' . time(); $newName = $info['filename'] . $suffix . '.' . $info['extension']; $arrFilesToRename[$file] = $newName; array_push($arrFiles, $newName); } if (!isset($arrFilesToRename[$file])) { array_push($uploadFiles, $file); } //rename files where needed foreach ($arrFilesToRename as $oldName => $newName) { $objTempFile = new \Cx\Lib\FileSystem\File($tempPath . '/' . $oldName); $objTempFile->rename($tempPath . '/' . $newName, false); array_push($uploadFiles, $newName); } //move file from temp path into target folder $objImage = new \ImageManager(); foreach ($uploadFiles as $fileName) { $objFile = new \Cx\Lib\FileSystem\File($tempPath . '/' . $fileName); $objFile->move($path . '/' . $fileName, false); \Cx\Core\Core\Controller\Cx::instanciate()->getMediaSourceManager()->getThumbnailGenerator()->createThumbnailFromPath($path . '/' . $fileName); } } catch (\Cx\Lib\FileSystem\FileSystemException $e) { \DBG::msg($e->getMessage()); } $objDownloads = new downloads(''); $objDownloads->addDownloadFromUpload($info['filename'], $info['extension'], $suffix, $objCategory, $objDownloads, $fileInfos['name']); } return array($path, $webPath); }
$sql = 'SELECT element FROM _members_unread WHERE user_id = ? ORDER BY element, item'; if ($result = sql_rowset(sql_filter($sql, $user->data['user_id']))) { $items = w(); foreach ($result as $row) { if (!isset($items[$row['element']])) { $items[$row['element']] = 0; } $items[$row['element']]++; } if (isset($items[UH_D]) || isset($items[UH_M])) { $downloads = new downloads(); } _style('items', array( 'TOTAL_ITEMS' => count($result)) ); // // Notes (PM) // if (isset($items[UH_NOTE])) { $sql = 'SELECT c.*, c2.privmsgs_date, m.user_id, m.username, m.username_base FROM _members_unread u, _dc c, _dc c2, _members m WHERE u.user_id = ? AND u.element = ?
public static function uploadFinished($tempPath, $tempWebPath, $data, $uploadId, $fileInfos) { global $objDatabase, $_ARRAYLANG, $_CONFIG; $originalNames = $fileInfos['originalFileNames']; $path = $data['path']; $webPath = $data['webPath']; $objCategory = Category::getCategory($data['category_id']); // check for sufficient permissions if ($objCategory->getAddFilesAccessId() && !\Permission::checkAccess($objCategory->getAddFilesAccessId(), 'dynamic', true) && $objCategory->getOwnerId() != \FWUser::getFWUserObject()->objUser->getId()) { return; } //we remember the names of the uploaded files here. they are stored in the session afterwards, //so we can later display them highlighted. $arrFiles = array(); //rename files, delete unwanted $arrFilesToRename = array(); //used to remember the files we need to rename $h = opendir($tempPath); while (false !== ($file = readdir($h))) { //skip . and .. if ($file == '.' || $file == '..') { continue; } //delete potentially malicious files if (!\FWValidator::is_file_ending_harmless($file)) { @unlink($tempPath . '/' . $file); continue; } $info = pathinfo($file); $cleanFile = \Cx\Lib\FileSystem\FileSystem::replaceCharacters($file); if ($cleanFile != $file) { rename($tempPath . '/' . $file, $tempPath . '/' . $cleanFile); $file = $cleanFile; } //check if file needs to be renamed $newName = ''; $suffix = ''; if (file_exists($path . '/' . $file)) { if (empty($_REQUEST['uploadForceOverwrite']) || !intval($_REQUEST['uploadForceOverwrite'] > 0)) { $suffix = '_' . time(); $newName = $info['filename'] . $suffix . '.' . $info['extension']; $arrFilesToRename[$file] = $newName; array_push($arrFiles, $newName); } } if (!isset($arrFilesToRename[$file])) { //file will keep this name - create thumb \ImageManager::_createThumb($tempPath . '/', $tempWebPath . '/', $file); } $objDownloads = new downloads(''); $objDownloads->addDownloadFromUpload($info['filename'], $info['extension'], $suffix, $objCategory, $objDownloads, $originalNames[$file]); } //rename files where needed foreach ($arrFilesToRename as $oldName => $newName) { rename($tempPath . '/' . $oldName, $tempPath . '/' . $newName); //file will keep this name - create thumb \ImageManager::_createThumb($tempPath . '/', $tempWebPath . '/', $newName); } //remeber the uploaded files $_SESSION['media_upload_files_' . $uploadId] = $arrFiles; /* unwanted files have been deleted, unallowed filenames corrected. we can now simply return the desired target path, as only valid files are present in $tempPath */ return array($path, $webPath); }
} ${$class} = new $class(); $data_headers = ${$class}->field_a; $ignored_fields = ['created_by', 'creation_date', 'last_update_by', 'last_update_date']; $few_records = $class::find_few(5); $dataArray = []; foreach ($few_records as $rows) { $datarow = []; foreach ($data_headers as $columns) { if (!in_array($columns, $ignored_fields)) { $datarow[$columns] = $rows->{$columns}; } } array_push($dataArray, $datarow); } $dl = new downloads(); $dl->setProperty('_downloaded_data', $dataArray); if ($continue) { if (!empty(${$class}) && property_exists(${$class}, 'mass_upload_template_path')) { $template_file_names = $class::$mass_upload_template_path; } else { if (!empty(${$class})) { $template_file_names = ['extensions/file/massupload_template.php']; } } include_once THEME_DIR . '/main_template.inc'; } else { $continue = false; echo "<h2>Could n't call the header</h2>"; return; }