function fileSharingUpdate() { try { //update module name \Cx\Lib\UpdateUtil::sql("UPDATE `" . DBPREFIX . "modules` SET `name` = 'FileSharing' WHERE `id` = 68"); //update navigation url \Cx\Lib\UpdateUtil::sql("UPDATE `" . DBPREFIX . "backend_areas` SET `uri` = 'index.php?cmd=media&archive=FileSharing' WHERE `area_id` = 187"); //Insert component entry \Cx\Lib\UpdateUtil::sql("INSERT INTO `" . DBPREFIX . "component` (`id`, `name`, `type`) VALUES ('68', 'FileSharing', 'module')"); //update module name for frontend pages \Cx\Lib\UpdateUtil::sql("UPDATE `" . DBPREFIX . "content_page` SET `module` = 'FileSharing' WHERE `module` = 'filesharing'"); //update section \Cx\Lib\UpdateUtil::sql("UPDATE `" . DBPREFIX . "core_setting` SET `section` = 'FileSharing',`value` = 'on' WHERE\n `section` = 'filesharing' AND `name` = 'permission' AND `group` = 'config'"); } catch (\Cx\Lib\UpdateException $e) { return "Error: {$e->sql}"; } $sourcePath = ASCMS_DOCUMENT_ROOT . '/media/filesharing'; $targetPath = ASCMS_DOCUMENT_ROOT . '/media/FileSharing'; try { if (file_exists($sourcePath) && !file_exists($targetPath)) { \Cx\Lib\FileSystem\FileSystem::makeWritable($sourcePath); if (!\Cx\Lib\FileSystem\FileSystem::move($sourcePath, $targetPath)) { return 'Failed to Moved the files from ' . $sourcePath . ' to ' . $targetPath . '.<br>'; } } } catch (\Cx\Lib\FileSystem\FileSystemException $e) { return $e->getMessage(); } return 'FileSharing updated successfully'; }
function galleryUpdate() { try { //update module name \Cx\Lib\UpdateUtil::sql("UPDATE `" . DBPREFIX . "modules` SET `name` = 'Gallery' WHERE `id` = 3"); //update navigation url \Cx\Lib\UpdateUtil::sql("UPDATE `" . DBPREFIX . "backend_areas` SET `uri` = 'index.php?cmd=Gallery' WHERE `area_id` = 12"); //Insert component entry \Cx\Lib\UpdateUtil::sql("INSERT INTO `" . DBPREFIX . "component` (`id`, `name`, `type`) VALUES ('3', 'Gallery', 'module')"); //update module name for frontend pages \Cx\Lib\UpdateUtil::sql("UPDATE `" . DBPREFIX . "content_page` SET `module` = 'Gallery' WHERE `module` = 'gallery'"); } catch (\Cx\Lib\UpdateException $e) { return "Error: {$e->sql}"; } $sourcePath = ASCMS_DOCUMENT_ROOT . '/images/gallery'; $targetPath = ASCMS_DOCUMENT_ROOT . '/images/Gallery'; try { if (file_exists($sourcePath) && !file_exists($targetPath)) { \Cx\Lib\FileSystem\FileSystem::makeWritable($sourcePath); if (!\Cx\Lib\FileSystem\FileSystem::move($sourcePath, $targetPath)) { return 'Failed to Moved the files from ' . $sourcePath . ' to ' . $targetPath . '.<br>'; } } } catch (\Cx\Lib\FileSystem\FileSystemException $e) { return $e->getMessage(); } return 'Gallery Component Updated Successfully'; }
function marketUpdates() { //Update the database changes try { //update module name \Cx\Lib\UpdateUtil::sql("UPDATE `" . DBPREFIX . "modules` SET `name` = 'Market' WHERE `id` = 33"); //update navigation url \Cx\Lib\UpdateUtil::sql("UPDATE `" . DBPREFIX . "backend_areas` SET `uri` = 'index.php?cmd=Market' WHERE `area_id` = 98"); //Insert component entry \Cx\Lib\UpdateUtil::sql("INSERT INTO `" . DBPREFIX . "component` (`id`, `name`, `type`) VALUES ('33', 'Market', 'module')"); //update module name for frontend pages \Cx\Lib\UpdateUtil::sql("UPDATE `" . DBPREFIX . "content_page` SET `module` = 'Market' WHERE `module` = 'market'"); } catch (\Cx\Lib\UpdateException $e) { return "Error: {$e->sql}"; } //Update script for moving the folder $marketMediaPath = ASCMS_DOCUMENT_ROOT . '/media'; try { if (file_exists($marketMediaPath . '/market') && !file_exists($marketMediaPath . '/Market')) { \Cx\Lib\FileSystem\FileSystem::makeWritable($marketMediaPath . '/market'); if (!\Cx\Lib\FileSystem\FileSystem::move($marketMediaPath . '/market', $marketMediaPath . '/Market')) { return 'Failed to move the folder from ' . $marketMediaPath . '/market to ' . $marketMediaPath . '/Market.'; } } } catch (\Cx\Lib\FileSystem\FileSystemException $e) { return $e->getMessage(); } return 'Market updated successfully.'; }
function calendarUpdate() { try { //update module name \Cx\Lib\UpdateUtil::sql("UPDATE `" . DBPREFIX . "modules` SET `name` = 'Calendar' WHERE `id` = 21"); //update navigation url \Cx\Lib\UpdateUtil::sql("UPDATE `" . DBPREFIX . "backend_areas` SET `uri` = 'index.php?cmd=Calendar' WHERE `area_id` = 16"); //Insert component entry \Cx\Lib\UpdateUtil::sql("INSERT INTO `" . DBPREFIX . "component` (`id`, `name`, `type`) VALUES ('21', 'Calendar', 'module')"); //update module name for frontend pages \Cx\Lib\UpdateUtil::sql("UPDATE `" . DBPREFIX . "content_page` SET `module` = 'Calendar' WHERE `module` = 'calendar'"); //following queries for changing the path from images/calendar into images/Calendar \Cx\Lib\UpdateUtil::sql("UPDATE `" . DBPREFIX . "module_calendar_event` SET `pic` = REPLACE(`pic`, 'images/calendar', 'images/Calendar'),\n `attach` = REPLACE(`attach`, 'images/calendar', 'images/Calendar'),\n `place_map` = REPLACE(`place_map`, 'images/calendar', 'images/Calendar')\n WHERE `pic` LIKE ('" . ASCMS_PATH_OFFSET . "/images/calendar%') "); } catch (\Cx\Lib\UpdateException $e) { return "Error: {$e->sql}"; } $sourcePath = ASCMS_DOCUMENT_ROOT . '/images/calendar'; $targetPath = ASCMS_DOCUMENT_ROOT . '/images/Calendar'; try { if (file_exists($sourcePath) && !file_exists($targetPath)) { \Cx\Lib\FileSystem\FileSystem::makeWritable($sourcePath); if (!\Cx\Lib\FileSystem\FileSystem::move($sourcePath, $targetPath)) { return 'Failed to Moved the files from ' . $sourcePath . ' to ' . $targetPath . '.<br>'; } } } catch (\Cx\Lib\FileSystem\FileSystemException $e) { return $e->getMessage(); } return 'Calendar Component Updated Successfully'; }
function downloadsUpdate() { try { //update module name \Cx\Lib\UpdateUtil::sql("UPDATE `" . DBPREFIX . "modules` SET `name` = 'Downloads' WHERE `id` = 53"); //update navigation url \Cx\Lib\UpdateUtil::sql("UPDATE `" . DBPREFIX . "backend_areas` SET `uri` = 'index.php?cmd=Downloads' WHERE `area_id` = 132"); //Insert component entry \Cx\Lib\UpdateUtil::sql("INSERT INTO `" . DBPREFIX . "component` (`id`, `name`, `type`) VALUES ('53', 'Downloads', 'module')"); //update module name for frontend pages \Cx\Lib\UpdateUtil::sql("UPDATE `" . DBPREFIX . "content_page` SET `module` = 'Downloads' WHERE `module` = 'downloads'"); //following queries for changing the path from images/downloads into images/Downloads \Cx\Lib\UpdateUtil::sql("UPDATE `" . DBPREFIX . "module_downloads_download`\n SET `image` = REPLACE(`image`, 'images/downloads', 'images/Downloads')\n WHERE `image` LIKE ('" . ASCMS_PATH_OFFSET . "/images/downloads%')"); \Cx\Lib\UpdateUtil::sql("UPDATE `" . DBPREFIX . "module_downloads_category`\n SET `image` = REPLACE(`image`, 'images/downloads', 'images/Downloads')\n WHERE `image` LIKE ('" . ASCMS_PATH_OFFSET . "/images/downloads%')"); \Cx\Lib\UpdateUtil::sql("UPDATE `" . DBPREFIX . "module_downloads_download_locale`\n SET `source` = REPLACE(`source`, 'images/downloads', 'images/Downloads')\n WHERE `source` LIKE ('" . ASCMS_PATH_OFFSET . "/images/downloads%')"); } catch (\Cx\Lib\UpdateException $e) { return "Error: {$e->sql}"; } $sourcePath = ASCMS_DOCUMENT_ROOT . '/images/downloads'; $targetPath = ASCMS_DOCUMENT_ROOT . '/images/Downloads'; try { if (file_exists($sourcePath) && !file_exists($targetPath)) { \Cx\Lib\FileSystem\FileSystem::makeWritable($sourcePath); if (!\Cx\Lib\FileSystem\FileSystem::move($sourcePath, $targetPath)) { return 'Failed to Moved the files from ' . $sourcePath . ' to ' . $targetPath . '.<br>'; } } } catch (\Cx\Lib\FileSystem\FileSystemException $e) { return $e->getMessage(); } return 'Downloads Updated successfully'; }
function forumUpdates() { //Update the database changes try { //update module name \Cx\Lib\UpdateUtil::sql("UPDATE `" . DBPREFIX . "modules` SET `name` = 'Forum' WHERE `id` = 20"); //update navigation url \Cx\Lib\UpdateUtil::sql("UPDATE `" . DBPREFIX . "backend_areas` SET `uri` = 'index.php?cmd=Forum' WHERE `area_id` = 106"); //Insert component entry \Cx\Lib\UpdateUtil::sql("INSERT INTO `" . DBPREFIX . "component` (`id`, `name`, `type`) VALUES ('20', 'Forum', 'module')"); //update module name for frontend pages \Cx\Lib\UpdateUtil::sql("UPDATE `" . DBPREFIX . "content_page` SET `module` = 'Forum' WHERE `module` = 'forum'"); } catch (\Cx\Lib\UpdateException $e) { return "Error: {$e->sql}"; } //Update script for moving the folder $sourcePath = ASCMS_DOCUMENT_ROOT . '/media/forum'; $destinationPath = ASCMS_DOCUMENT_ROOT . '/media/Forum'; try { if (file_exists($sourcePath) && !file_exists($destinationPath)) { \Cx\Lib\FileSystem\FileSystem::makeWritable($sourcePath); if (!\Cx\Lib\FileSystem\FileSystem::move($sourcePath, $destinationPath)) { return 'Failed to move the folder from ' . $sourcePath . ' to ' . $destinationPath . '.'; } } } catch (\Cx\Lib\FileSystem\FileSystemException $e) { return $e->getMessage(); } return 'Forum updated successfully.'; }
function accessUpdates() { //Update the database changes try { //update module name \Cx\Lib\UpdateUtil::sql("UPDATE `" . DBPREFIX . "modules` SET `name` = 'Access' WHERE `id` = 23"); //update navigation url \Cx\Lib\UpdateUtil::sql("UPDATE `" . DBPREFIX . "backend_areas` SET `uri` = 'index.php?cmd=Access', `module_id` = '23' WHERE `area_id` = 18"); \Cx\Lib\UpdateUtil::sql("UPDATE `" . DBPREFIX . "backend_areas` SET `uri` = 'index.php?cmd=Access' WHERE `area_id` = 208"); //Insert component entry \Cx\Lib\UpdateUtil::sql("INSERT INTO `" . DBPREFIX . "component` (`id`, `name`, `type`) VALUES ('23', 'Access', 'core_module')"); //update module name for frontend pages \Cx\Lib\UpdateUtil::sql("UPDATE `" . DBPREFIX . "content_page` SET `module` = 'Access' WHERE `module` = 'access'"); //update module name for crm core settings \Cx\Lib\UpdateUtil::sql("UPDATE `" . DBPREFIX . "core_setting` SET `section` = 'Access' WHERE `section` = 'access' AND `name` = 'providers' AND `group` = 'sociallogin'"); } catch (\Cx\Lib\UpdateException $e) { return "Error: {$e->sql}"; } //Update script for moving the folder $accessImgPath = ASCMS_DOCUMENT_ROOT . '/images'; try { if (file_exists($accessImgPath . '/access') && !file_exists($accessImgPath . '/Access')) { \Cx\Lib\FileSystem\FileSystem::makeWritable($accessImgPath . '/access'); if (!\Cx\Lib\FileSystem\FileSystem::move($accessImgPath . '/access', $accessImgPath . '/Access')) { return 'Failed to move the folder from ' . $accessImgPath . '/access to ' . $accessImgPath . '/Access.'; } } } catch (\Cx\Lib\FileSystem\FileSystemException $e) { return $e->getMessage(); } return 'Access updated successfully.'; }
function ecardUpdates() { //Update database changes try { //update module name \Cx\Lib\UpdateUtil::sql("UPDATE `" . DBPREFIX . "modules` SET `name` = 'Ecard' WHERE `id` = 49"); //update navigation url \Cx\Lib\UpdateUtil::sql("UPDATE `" . DBPREFIX . "backend_areas` SET `uri` = 'index.php?cmd=Ecard' WHERE `area_id` = 130"); //Insert component entry \Cx\Lib\UpdateUtil::sql("INSERT INTO `" . DBPREFIX . "component` (`id`, `name`, `type`) VALUES ('49', 'Ecard', 'module')"); //update module name for frontend pages \Cx\Lib\UpdateUtil::sql("UPDATE `" . DBPREFIX . "content_page` SET `module` = 'Ecard' WHERE `module` = 'ecard'"); } catch (\Cx\Lib\UpdateException $e) { return "Error: {$e->sql}"; } //Update script for moving the folders $imgModulesfolderPath = ASCMS_DOCUMENT_ROOT . '/images/modules/ecard'; $mediafolderPath = ASCMS_DOCUMENT_ROOT . '/media/Ecard'; try { if (!file_exists($mediafolderPath)) { \Cx\Lib\FileSystem\FileSystem::make_folder($mediafolderPath); \Cx\Lib\FileSystem\FileSystem::makeWritable($mediafolderPath); } //move the folder from '/images/modules/ecard/ecards_optimized' to '/media/Ecard/ecards_optimized' if (file_exists($imgModulesfolderPath . '/ecards_optimized') && !file_exists($mediafolderPath . '/ecards_optimized')) { \Cx\Lib\FileSystem\FileSystem::makeWritable($imgModulesfolderPath . '/ecards_optimized'); if (!\Cx\Lib\FileSystem\FileSystem::move($imgModulesfolderPath . '/ecards_optimized', $mediafolderPath . '/ecards_optimized')) { return 'Failed to Move the folders from ' . $imgModulesfolderPath . '/ecards_optimized to ' . $mediafolderPath . '/ecards_optimized.'; } } //move the folder from '/images/modules/ecard/send_ecards' to '/media/Ecard/send_ecards' if (file_exists($imgModulesfolderPath . '/send_ecards') && !file_exists($mediafolderPath . '/send_ecards')) { \Cx\Lib\FileSystem\FileSystem::makeWritable($imgModulesfolderPath . '/send_ecards'); if (!\Cx\Lib\FileSystem\FileSystem::move($imgModulesfolderPath . '/send_ecards', $mediafolderPath . '/send_ecards')) { return 'Failed to Move the folders from ' . $imgModulesfolderPath . '/send_ecards to ' . $mediafolderPath . '/send_ecards.'; } } //move the folder from '/images/modules/ecard/thumbnails' to '/media/Ecard/thumbnails' if (file_exists($imgModulesfolderPath . '/thumbnails') && !file_exists($mediafolderPath . '/thumbnails')) { \Cx\Lib\FileSystem\FileSystem::makeWritable($imgModulesfolderPath . '/thumbnails'); if (!\Cx\Lib\FileSystem\FileSystem::move($imgModulesfolderPath . '/thumbnails', $mediafolderPath . '/thumbnails')) { return 'Failed to Move the folders from ' . $imgModulesfolderPath . '/thumbnails to ' . $mediafolderPath . '/thumbnails.'; } } return 'Successfully updated.'; } catch (\Cx\Lib\FileSystem\FileSystemException $e) { return $e->getMessage(); } }
/** * @override */ public function handleRequest() { global $_FILES; //get a writable directory $targetDir = '/upload_' . $this->uploadId; $tempPath = $_SESSION->getTempPath(); $webTempPath = $_SESSION->getWebTempPath(); //make sure target directory exists if (!file_exists($tempPath . $targetDir)) { \Cx\Lib\FileSystem\FileSystem::make_folder($webTempPath . $targetDir); } //move all uploaded file to this upload's temp directory foreach ($_FILES["uploaderFiles"]["error"] as $key => $error) { if ($error == UPLOAD_ERR_OK) { $tmpName = $_FILES["uploaderFiles"]["tmp_name"][$key]; $name = $_FILES["uploaderFiles"]["name"][$key]; if (!\FWValidator::is_file_ending_harmless($name)) { die('Error:' . sprintf('The file %s was refused due to its file extension which is not allowed!', htmlentities($name, ENT_QUOTES, CONTREXX_CHARSET))); } //TODO: Uploader::addChunk does this also -> centralize in function // remember the "raw" file name, we want to store all original // file names in the session. $originalFileName = $name; // Clean the fileName for security reasons $name = preg_replace('/[^\\w\\._]+/', '', $name); $originalFileNames = array(); if (isset($_SESSION['upload']['handlers'][$this->uploadId]['originalFileNames'])) { $originalFileNames = $_SESSION['upload']['handlers'][$this->uploadId]['originalFileNames']; } $originalFileNames[$name] = $originalFileName; $_SESSION['upload']['handlers'][$this->uploadId]['originalFileNames'] = $originalFileNames; //end of TODO-region //move file somewhere we know both the web- and normal path... @move_uploaded_file($tmpName, ASCMS_TEMP_PATH . '/' . $name); //...then do a safe-mode-safe (yeah) move operation \Cx\Lib\FileSystem\FileSystem::move(ASCMS_TEMP_WEB_PATH . '/' . $name, $webTempPath . $targetDir . '/' . $name, true); } } //and call back. $this->notifyCallback(); //redirect the user where he belongs $this->redirect(); }
function crmUpdates() { //Update the database changes try { //update module name \Cx\Lib\UpdateUtil::sql("UPDATE `" . DBPREFIX . "modules` SET `name` = 'Crm' WHERE `id` = 69"); //update navigation url \Cx\Lib\UpdateUtil::sql("UPDATE `" . DBPREFIX . "backend_areas` SET `uri` = 'index.php?cmd=Crm&act=customers' WHERE `area_id` = 191"); \Cx\Lib\UpdateUtil::sql("UPDATE `" . DBPREFIX . "backend_areas` SET `uri` = 'index.php?cmd=Crm&act=task' WHERE `area_id` = 192"); \Cx\Lib\UpdateUtil::sql("UPDATE `" . DBPREFIX . "backend_areas` SET `uri` = 'index.php?cmd=Crm&act=deals' WHERE `area_id` = 193"); \Cx\Lib\UpdateUtil::sql("UPDATE `" . DBPREFIX . "backend_areas` SET `uri` = 'index.php?cmd=Crm&act=settings' WHERE `area_id` = 195"); //Insert component entry \Cx\Lib\UpdateUtil::sql("INSERT INTO `" . DBPREFIX . "component` (`id`, `name`, `type`) VALUES ('69', 'Crm', 'module')"); //update module name for email templates \Cx\Lib\UpdateUtil::sql("UPDATE `" . DBPREFIX . "core_mail_template` SET `section` = 'Crm' WHERE `section` = 'crm'"); \Cx\Lib\UpdateUtil::sql("UPDATE `" . DBPREFIX . "core_text` SET `section` = 'Crm' WHERE `section` = 'crm'"); //update module name for crm core settings \Cx\Lib\UpdateUtil::sql("UPDATE `" . DBPREFIX . "core_setting` SET `section` = 'Crm' WHERE `section` = 'crm'"); } catch (\Cx\Lib\UpdateException $e) { return "Error: {$e->sql}"; } //Update script for moving the folder $crmImgPath = ASCMS_DOCUMENT_ROOT . '/images'; $crmMediaPath = ASCMS_DOCUMENT_ROOT . '/media'; try { if (file_exists($crmImgPath . '/crm') && !file_exists($crmImgPath . '/Crm')) { \Cx\Lib\FileSystem\FileSystem::makeWritable($crmImgPath . '/crm'); if (!\Cx\Lib\FileSystem\FileSystem::move($crmImgPath . '/crm', $crmImgPath . '/Crm')) { return 'Failed to move the folder from ' . $crmImgPath . '/crm to ' . $crmImgPath . '/Crm.'; } } if (file_exists($crmMediaPath . '/crm') && !file_exists($crmMediaPath . '/Crm')) { \Cx\Lib\FileSystem\FileSystem::makeWritable($crmMediaPath . '/crm'); if (!\Cx\Lib\FileSystem\FileSystem::move($crmMediaPath . '/crm', $crmMediaPath . '/Crm')) { return 'Failed to move the folder from ' . $crmMediaPath . '/crm to ' . $crmMediaPath . '/Crm.'; } } } catch (\Cx\Lib\FileSystem\FileSystemException $e) { return $e->getMessage(); } return 'Crm updated successfully.'; }
function shopUpdates() { //Update the database changes try { //update module name \Cx\Lib\UpdateUtil::sql("UPDATE `" . DBPREFIX . "modules` SET `name` = 'Shop' WHERE `id` = 16"); //update navigation url \Cx\Lib\UpdateUtil::sql("UPDATE `" . DBPREFIX . "backend_areas` SET `uri` = 'index.php?cmd=Shop' WHERE `area_id` = 13"); //Insert component entry \Cx\Lib\UpdateUtil::sql("INSERT INTO `" . DBPREFIX . "component` (`id`, `name`, `type`) VALUES ('16', 'Shop', 'module')"); //update module name for frontend pages \Cx\Lib\UpdateUtil::sql("UPDATE `" . DBPREFIX . "content_page` SET `module` = 'Shop' WHERE `module` = 'shop'"); //update module name for crm core settings \Cx\Lib\UpdateUtil::sql("UPDATE `" . DBPREFIX . "core_setting` SET `section` = 'Shop' WHERE `section` = 'shop'"); //update module name for email templates \Cx\Lib\UpdateUtil::sql("UPDATE `" . DBPREFIX . "core_mail_template` SET `section` = 'Shop' WHERE `section` = 'shop'"); \Cx\Lib\UpdateUtil::sql("UPDATE `" . DBPREFIX . "core_text` SET `section` = 'Shop' WHERE `section` = 'shop'"); } catch (\Cx\Lib\UpdateException $e) { return "Error: {$e->sql}"; } //Update script for moving the folder $shopImgPath = ASCMS_DOCUMENT_ROOT . '/images'; $shopMediaPath = ASCMS_DOCUMENT_ROOT . '/media'; try { if (file_exists($shopImgPath . '/shop') && !file_exists($shopImgPath . '/Shop')) { \Cx\Lib\FileSystem\FileSystem::makeWritable($shopImgPath . '/shop'); if (!\Cx\Lib\FileSystem\FileSystem::move($shopImgPath . '/shop', $shopImgPath . '/Shop')) { return 'Failed to move the folder from ' . $shopImgPath . '/shop to ' . $shopImgPath . '/Shop.'; } } if (file_exists($shopMediaPath . '/shop') && !file_exists($shopMediaPath . '/Shop')) { \Cx\Lib\FileSystem\FileSystem::makeWritable($shopMediaPath . '/shop'); if (!\Cx\Lib\FileSystem\FileSystem::move($shopMediaPath . '/shop', $shopMediaPath . '/Shop')) { return 'Failed to move the folder from ' . $shopMediaPath . '/shop to ' . $shopMediaPath . '/Shop.'; } } } catch (\Cx\Lib\FileSystem\FileSystemException $e) { return $e->getMessage(); } return 'Shop updated successfully.'; }
function mediaDirUpdate() { try { //update module name \Cx\Lib\UpdateUtil::sql("UPDATE `" . DBPREFIX . "modules` SET `name` = 'MediaDir' WHERE `id` = 60"); //update navigation url \Cx\Lib\UpdateUtil::sql("UPDATE `" . DBPREFIX . "backend_areas` SET `uri` = 'index.php?cmd=MediaDir' WHERE `area_id` = 153"); //Insert component entry \Cx\Lib\UpdateUtil::sql("INSERT INTO `" . DBPREFIX . "component` (`id`, `name`, `type`) VALUES ('60', 'MediaDir', 'module')"); //update module name for frontend pages \Cx\Lib\UpdateUtil::sql("UPDATE `" . DBPREFIX . "content_page` SET `module` = 'MediaDir' WHERE `module` = 'mediadir'"); //update class name \Cx\Lib\UpdateUtil::sql("UPDATE `" . DBPREFIX . "module_mediadir_inputfield_types` SET `name` = 'linkGroup' WHERE `name` = 'link_group'"); \Cx\Lib\UpdateUtil::sql("UPDATE `" . DBPREFIX . "module_mediadir_inputfield_types` SET `name` = 'googleMap' WHERE `name` = 'google_map'"); \Cx\Lib\UpdateUtil::sql("UPDATE `" . DBPREFIX . "module_mediadir_inputfield_types` SET `name` = 'addStep' WHERE `name` = 'add_step'"); \Cx\Lib\UpdateUtil::sql("UPDATE `" . DBPREFIX . "module_mediadir_inputfield_types` SET `name` = 'fieldGroup' WHERE `name` = 'field_group'"); \Cx\Lib\UpdateUtil::sql("UPDATE `" . DBPREFIX . "module_mediadir_inputfield_types` SET `name` = 'productAttributes' WHERE `name` = 'product_attributes'"); \Cx\Lib\UpdateUtil::sql("UPDATE `" . DBPREFIX . "module_mediadir_inputfield_types` SET `name` = 'googleWeather' WHERE `name` = 'google_weather'"); //following queries for changing the path from images/mediadir into images/MediaDir \Cx\Lib\UpdateUtil::sql("UPDATE `" . DBPREFIX . "module_mediadir_categories` \n SET `picture` = REPLACE(`picture`, 'images/mediadir', 'images/MediaDir')\n WHERE `picture` LIKE ('" . ASCMS_PATH_OFFSET . "/images/mediadir%')"); \Cx\Lib\UpdateUtil::sql("UPDATE `" . DBPREFIX . "module_mediadir_forms` \n SET `picture` = REPLACE(`picture`, 'images/mediadir', 'images/MediaDir')\n WHERE `picture` LIKE ('" . ASCMS_PATH_OFFSET . "/images/mediadir%')"); \Cx\Lib\UpdateUtil::sql("UPDATE `" . DBPREFIX . "module_mediadir_levels` \n SET `picture` = REPLACE(`picture`, 'images/mediadir', 'images/MediaDir')\n WHERE `picture` LIKE ('" . ASCMS_PATH_OFFSET . "/images/mediadir%')"); \Cx\Lib\UpdateUtil::sql("UPDATE `" . DBPREFIX . "module_mediadir_rel_entry_inputfields` \n SET `value` = REPLACE(`value`, 'images/mediadir', 'images/MediaDir')\n WHERE `value` LIKE ('" . ASCMS_PATH_OFFSET . "/images/mediadir%')"); \Cx\Lib\UpdateUtil::sql("UPDATE `" . DBPREFIX . "module_mediadir_rel_entry_inputfields_clean1` \n SET `value` = REPLACE(`value`, 'images/mediadir', 'images/MediaDir')\n WHERE `value` LIKE ('" . ASCMS_PATH_OFFSET . "/images/mediadir%')"); } catch (\Cx\Lib\UpdateException $e) { return "Error: {$e->sql}"; } $sourcePath = ASCMS_DOCUMENT_ROOT . '/images/mediadir'; $targetPath = ASCMS_DOCUMENT_ROOT . '/images/MediaDir'; try { if (file_exists($sourcePath) && !file_exists($targetPath)) { \Cx\Lib\FileSystem\FileSystem::makeWritable($sourcePath); if (!\Cx\Lib\FileSystem\FileSystem::move($sourcePath, $targetPath)) { return 'Failed to Moved the files from ' . $sourcePath . ' to ' . $targetPath . '.<br>'; } } } catch (\Cx\Lib\FileSystem\FileSystemException $e) { return $e->getMessage(); } return 'Media Directory Updated Successfully'; }
function blogUpdates() { //Update the database changes try { //update module name \Cx\Lib\UpdateUtil::sql("UPDATE `" . DBPREFIX . "modules` SET `name` = 'Blog' WHERE `id` = 47"); //update navigation url \Cx\Lib\UpdateUtil::sql("UPDATE `" . DBPREFIX . "backend_areas` SET `uri` = 'index.php?cmd=Blog' WHERE `area_id` = 119"); \Cx\Lib\UpdateUtil::sql("UPDATE `" . DBPREFIX . "backend_areas` SET `uri` = 'index.php?cmd=Blog&act=manageEntry' WHERE `area_id` = 120"); \Cx\Lib\UpdateUtil::sql("UPDATE `" . DBPREFIX . "backend_areas` SET `uri` = 'index.php?cmd=Blog&act=addEntry' WHERE `area_id` = 121"); \Cx\Lib\UpdateUtil::sql("UPDATE `" . DBPREFIX . "backend_areas` SET `uri` = 'index.php?cmd=Blog&act=manageCategory' WHERE `area_id` = 122"); \Cx\Lib\UpdateUtil::sql("UPDATE `" . DBPREFIX . "backend_areas` SET `uri` = 'index.php?cmd=Blog&act=addCategory' WHERE `area_id` = 123"); \Cx\Lib\UpdateUtil::sql("UPDATE `" . DBPREFIX . "backend_areas` SET `uri` = 'index.php?cmd=Blog&act=settings' WHERE `area_id` = 124"); \Cx\Lib\UpdateUtil::sql("UPDATE `" . DBPREFIX . "backend_areas` SET `uri` = 'index.php?cmd=Blog&act=networks' WHERE `area_id` = 125"); //Insert component entry \Cx\Lib\UpdateUtil::sql("INSERT INTO `" . DBPREFIX . "component` (`id`, `name`, `type`) VALUES ('47', 'Blog', 'module')"); //update module name for frontend pages \Cx\Lib\UpdateUtil::sql("UPDATE `" . DBPREFIX . "content_page` SET `module` = 'Blog' WHERE `module` = 'blog'"); //following queries for changing the path from images/blog into images/Blog \Cx\Lib\UpdateUtil::sql("UPDATE `" . DBPREFIX . "module_blog_messages_lang` \n SET `image` = REPLACE(`image`, 'images/blog', 'images/Blog')\n WHERE `image` LIKE ('" . ASCMS_PATH_OFFSET . "/images/blog%')"); \Cx\Lib\UpdateUtil::sql("UPDATE `" . DBPREFIX . "module_blog_networks` \n SET `icon` = REPLACE(`icon`, 'images/blog', 'images/Blog')\n WHERE `icon` LIKE ('" . ASCMS_PATH_OFFSET . "/images/blog%')"); } catch (\Cx\Lib\UpdateException $e) { return "Error: {$e->sql}"; } //Update script for moving the folder $blogImgPath = ASCMS_DOCUMENT_ROOT . '/images'; try { if (file_exists($blogImgPath . '/blog') && !file_exists($blogImgPath . '/Blog')) { \Cx\Lib\FileSystem\FileSystem::makeWritable($blogImgPath . '/blog'); if (!\Cx\Lib\FileSystem\FileSystem::move($blogImgPath . '/blog', $blogImgPath . '/Blog')) { return 'Failed to move the folder from ' . $blogImgPath . '/blog to ' . $blogImgPath . '/Blog.'; } } } catch (\Cx\Lib\FileSystem\FileSystemException $e) { return $e->getMessage(); } return 'Blog updated successfully.'; }
function podcastUpdate() { try { // Update module name \Cx\Lib\UpdateUtil::sql("UPDATE `" . DBPREFIX . "modules` SET `name` = 'Podcast' WHERE `id` = 35"); // Update navigation url value \Cx\Lib\UpdateUtil::sql("UPDATE `" . DBPREFIX . "backend_areas` SET `uri` = 'index.php?cmd=Podcast' WHERE `area_id` = 93"); // Insert entry for component \Cx\Lib\UpdateUtil::sql("INSERT INTO `" . DBPREFIX . "component` (`id`, `name`, `type`) VALUES ('35', 'Podcast', 'module')"); // Update module name for frontend pages \Cx\Lib\UpdateUtil::sql("UPDATE `" . DBPREFIX . "content_page` SET `module` = 'Podcast' WHERE `module` = 'podcast'"); // Update the thumbnail path from images/podcast into images/Podcast \Cx\Lib\UpdateUtil::sql("UPDATE `" . DBPREFIX . "module_podcast_medium`\n SET `thumbnail` = REPLACE(`thumbnail`, 'images/podcast', 'images/Podcast')\n WHERE `thumbnail` LIKE ('" . ASCMS_PATH_OFFSET . "/images/podcast%')"); } catch (\Cx\Lib\UpdateException $e) { return "Error: {$e->sql}"; } //Update script for moving the folder $imgPath = ASCMS_DOCUMENT_ROOT . '/images'; $mediaPath = ASCMS_DOCUMENT_ROOT . '/media'; try { if (file_exists($imgPath . '/podcast') && !file_exists($imgPath . '/Podcast')) { \Cx\Lib\FileSystem\FileSystem::makeWritable($imgPath . '/podcast'); if (!\Cx\Lib\FileSystem\FileSystem::move($imgPath . '/podcast', $imgPath . '/Podcast')) { return 'Failed to move the folder from ' . $imgPath . '/podcast to ' . $imgPath . '/Podcast.'; } } if (file_exists($mediaPath . '/podcast') && !file_exists($mediaPath . '/Podcast')) { \Cx\Lib\FileSystem\FileSystem::makeWritable($mediaPath . '/podcast'); if (!\Cx\Lib\FileSystem\FileSystem::move($mediaPath . '/podcast', $mediaPath . '/Podcast')) { return 'Failed to move the folder from ' . $mediaPath . '/podcast to ' . $mediaPath . '/Podcast.'; } } } catch (\Cx\Lib\FileSystem\FileSystemException $e) { return $e->getMessage(); } return 'Podcast Component database updated successfully'; }
/** * Upload the submitted images * * @global ADONewConnection * @global array * @global array * @param string $tempPath * @param array $paths * @param integer $uploadId */ public static function uploadFinished($tempPath, $tempWebPath, $paths, $uploadId, $fileInfos, $response) { global $objDatabase, $_ARRAYLANG, $_CONFIG, $objInit; $lang = $objInit->loadLanguageData('Gallery'); $objGallery = new GalleryManager(); $path = $paths['path']; $webPath = $paths['webPath']; //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(); //get allowed file types $arrAllowedFileTypes = array(); if (imagetypes() & IMG_GIF) { $arrAllowedFileTypes[] = 'gif'; } if (imagetypes() & IMG_JPG) { $arrAllowedFileTypes[] = 'jpg'; $arrAllowedFileTypes[] = 'jpeg'; } if (imagetypes() & IMG_PNG) { $arrAllowedFileTypes[] = 'png'; } //rename files, delete unwanted $arrFilesToRename = array(); //used to remember the files we need to rename $file = str_replace($tempPath . '/', '', $fileInfos['path']); $info = pathinfo($file); //delete unwanted files if (!in_array(strtolower($info['extension']), $arrAllowedFileTypes)) { @unlink($tempPath . '/' . $file); } //width of the image is wider than the allowed value. Show Error. $arrImageSize = getimagesize($tempPath . '/' . $file); if (intval($arrImageSize[0]) > intval($objGallery->arrSettings['image_width'])) { $objGallery->strErrMessage = str_replace('{WIDTH}', $objGallery->arrSettings['image_width'], $lang['TXT_GALLERY_UPLOAD_ERROR_WIDTH']); @unlink($tempPath . '/' . $file); } //check if file needs to be renamed $newName = \Cx\Lib\FileSystem\FileSystem::replaceCharacters($file); if (self::fileExists($path . '/' . $newName, false)) { $info = pathinfo($newName); $exte = $info['extension']; $exte = !empty($exte) ? '.' . $exte : ''; $part1 = $info['filename']; if (empty($_REQUEST['uploadForceOverwrite']) || !intval($_REQUEST['uploadForceOverwrite'] > 0)) { $newName = $part1 . '_' . time() . $exte; } } //if the name has changed, the file needs to be renamed afterwards if ($newName != $file) { $arrFilesToRename[$file] = $newName; array_push($arrFiles, $newName); } //create entry in the database for the uploaded image self::insertImage($objGallery, $newName, $newName); //rename files where needed foreach ($arrFilesToRename as $oldName => $newName) { rename($tempPath . '/' . $oldName, $tempPath . '/' . $newName); } FileSystem::move($tempPath . '/' . $newName, $path . '/' . $newName, true); /* 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, $newName); }
public function moveFile(File $file, $destination) { global $_ARRAYLANG; if (!empty($destination)) { if ($file->getExtension() == '' && is_dir($this->rootPath . ltrim($file->getPath(), '.') . '/' . $file->getName())) { $fileName = $this->rootPath . ltrim($file->getPath(), '.') . '/' . $file->getName(); $destinationFileName = $this->rootPath . ltrim($file->getPath(), '.') . '/' . $destination; } else { $fileName = $this->rootPath . ltrim($file->getPath(), '.') . '/' . $file->getName() . '.' . $file->getExtension(); $destinationFileName = $this->rootPath . ltrim($file->getPath(), '.') . '/' . $destination . '.' . $file->getExtension(); } if ($fileName == $destinationFileName) { return sprintf($_ARRAYLANG['TXT_FILEBROWSER_FILE_SUCCESSFULLY_RENAMED'], $file->getName()); } if (!\Cx\Lib\FileSystem\FileSystem::move($fileName, $destinationFileName, false)) { return sprintf($_ARRAYLANG['TXT_FILEBROWSER_FILE_UNSUCCESSFULLY_RENAMED'], $file->getName()); } return sprintf($_ARRAYLANG['TXT_FILEBROWSER_FILE_SUCCESSFULLY_RENAMED'], $file->getName()); } else { return sprintf($_ARRAYLANG['TXT_FILEBROWSER_FILE_UNSUCCESSFULLY_RENAMED'], $file->getName()); } }
/** * Notifies the callback. Invoked on upload completion. */ public function notifyCallback() { //temporary path where files were uploaded $tempDir = '/upload_' . $this->uploadId; $tempPath = $_SESSION->getTempPath() . $tempDir; $tempWebPath = $_SESSION->getWebTempPath() . $tempDir; //we're going to call the callbck, so the data is not needed anymore //well... not quite sure. need it again in contact form. //TODO: code session cleanup properly if time. //$this->cleanupCallbackData(); $classFile = $this->callbackData[0]; //call the callback, get return code if ($classFile != null) { if (!file_exists($classFile)) { throw new UploaderException("Class file '{$classFile}' specified for callback does not exist!"); } require_once $this->callbackData[0]; } $originalFileNames = array(); if (isset($_SESSION['upload']['handlers'][$this->uploadId]['originalFileNames'])) { $originalFileNames = $_SESSION['upload']['handlers'][$this->uploadId]['originalFileNames']; } //various file infos are passed via this array $fileInfos = array('originalFileNames' => $originalFileNames); $response = null; //the response data. if (isset($_SESSION['upload']['handlers'][$this->uploadId]['response_data'])) { $response = UploadResponse::fromSession($_SESSION['upload']['handlers'][$this->uploadId]['response_data']); } else { $response = new UploadResponse(); } $ret = call_user_func(array($this->callbackData[1], $this->callbackData[2]), $tempPath, $tempWebPath, $this->getData(), $this->uploadId, $fileInfos, $response); //clean up session: we do no longer need the array with the original file names unset($_SESSION['upload']['handlers'][$this->uploadId]['originalFileNames']); //same goes for the data //if(isset($_SESSION['upload']['handlers'][$this->uploadId]['data'])) // TODO: unset this when closing the uploader dialog, but not before // unset($_SESSION['upload']['handlers'][$this->uploadId]['data']); if (\Cx\Lib\FileSystem\FileSystem::exists($tempWebPath)) { //the callback could have returned a path where he wants the files moved to // check that $ret[1] is not empty is VERY important!!! if (!is_null($ret) && !empty($ret[1])) { //we need to move the files //gather target information $path = pathinfo($ret[0]); $pathWeb = pathinfo($ret[1]); //make sure the target directory is writable \Cx\Lib\FileSystem\FileSystem::makeWritable($pathWeb['dirname'] . '/' . $path['basename']); //revert $path and $pathWeb to whole path instead of pathinfo path for copying $path = $path['dirname'] . '/' . $path['basename'] . '/'; $pathWeb = $pathWeb['dirname'] . '/' . $pathWeb['basename'] . '/'; //trailing slash needed for File-class calls $tempPath .= '/'; $tempWebPath .= '/'; //move everything uploaded to target dir $h = opendir($tempPath); $im = new \ImageManager(); while (false != ($f = readdir($h))) { //skip . and .. if ($f == '.' || $f == '..') { continue; } //TODO: if return value = 'error' => react \Cx\Lib\FileSystem\FileSystem::move($tempWebPath . $f, $pathWeb . $f, true); if ($im->_isImage($path . $f)) { $im->_createThumb($path, $pathWeb, $f); } $response->increaseUploadedFilesCount(); } closedir($h); } else { // TODO: what now???? } //delete the folder \Cx\Lib\FileSystem\FileSystem::delete_folder($tempWebPath, true); } else { // TODO: output error message to user that no files had been uploaded!!! } $response->uploadFinished(); $_SESSION['upload']['handlers'][$this->uploadId]['response_data'] = $response->toSessionValue(); }
/** * Moves or copies the filesystem part of this component to another location * @param string $destination Destination path * @param boolean $copy (optional) Copy or move? True means copy, default is move * @return null */ protected function internalFsRelocate($destination, $copy = false) { if ($destination == $this->getDirectory()) { // nothing to do return; } $status = false; if ($copy) { $status = \Cx\Lib\FileSystem\FileSystem::copy_folder($this->getDirectory(), $destination); } else { $status = \Cx\Lib\FileSystem\FileSystem::move($this->getDirectory(), $destination); } return $status; }
/** * Upload handler. * * @param $params * * @return array * @throws UploaderException */ public function upload($params) { global $_ARRAYLANG; $id = null; if (isset($params['get']['id']) && preg_match('/^[a-z0-9]+$/i', $params['get']['id'])) { $id = $params['get']['id']; $uploadedFileCount = isset($params['get']['uploadedFileCount']) ? intval($params['get']['uploadedFileCount']) : 0; $path = $_SESSION->getTempPath() . '/' . $id . '/'; $tmpPath = $path; } elseif (isset($params['post']['path'])) { $path_part = explode("/", $params['post']['path'], 2); $mediaSourceManager = $this->cx->getMediaSourceManager(); $path = $mediaSourceManager->getMediaTypePathsbyNameAndOffset($path_part[0], 0) . '/' . $path_part[1]; $tmpPath = $_SESSION->getTempPath(); } else { return array('OK' => 0, 'error' => array('message' => 'No id specified')); } $allowedExtensions = false; if (isset($_SESSION['uploader']['handlers'][$id]['config']['allowed-extensions'])) { $allowedExtensions = $_SESSION['uploader']['handlers'][$id]['config']['allowed-extensions']->toArray(); } $uploader = UploaderController::handleRequest(array('allow_extensions' => is_array($allowedExtensions) ? explode(', ', $allowedExtensions) : $allowedExtensions, 'target_dir' => $path, 'tmp_dir' => $tmpPath)); $fileLocation = array($uploader['path'], str_replace($this->cx->getWebsitePath(), '', $uploader['path'])); $response = new UploadResponse(); if (isset($_SESSION['uploader']['handlers'][$id]['callback']) && $uploader !== true) { /** * @var $callback RecursiveArrayAccess * @var $data RecursiveArrayAccess */ $callback = $_SESSION['uploader']['handlers'][$id]['callback']; $data = $_SESSION['uploader']['handlers'][$id]['data']; if (isset($_SESSION['uploader']['handlers'][$id]['config']['upload-limit']) && $_SESSION['uploader']['handlers'][$id]['config']['upload-limit'] <= $uploadedFileCount) { return array('status' => 'error', 'message' => $_ARRAYLANG['TXT_CORE_MODULE_UPLOADER_MAX_LIMIT_REACHED']); } if (!is_string($callback)) { $callback = $callback->toArray(); } if ($data) { $data = $data->toArray(); } $filePath = dirname($uploader['path']); if (!is_array($callback)) { $class = new \ReflectionClass($callback); if ($class->implementsInterface('\\Cx\\Core_Modules\\Uploader\\Model\\UploadCallbackInterface')) { /** * @var \Cx\Core_Modules\Uploader\Model\UploadCallbackInterface $callbackInstance */ $callbackInstance = $class->newInstance($this->cx); $fileLocation = $callbackInstance->uploadFinished($filePath, str_replace($this->cx->getWebsiteTempPath(), $this->cx->getWebsiteTempWebPath(), $filePath), $data, $id, $uploader, $response); } } else { $fileLocation = call_user_func(array($callback[1], $callback[2]), $filePath, str_replace($this->cx->getWebsiteTempPath(), $this->cx->getWebsiteTempWebPath(), $filePath), $data, $id, $uploader, $response); } $files = new \RegexIterator(new \DirectoryIterator($filePath . '/'), '/.*/'); $file = false; foreach ($files as $fileInfo) { if ($fileInfo->isFile()) { $file = $fileInfo->getRealPath(); break; } } if ($file) { \Cx\Lib\FileSystem\FileSystem::move($file, rtrim($fileLocation[0], '/') . '/' . pathinfo($file, PATHINFO_BASENAME), true); if (isset($fileLocation[2])) { $uploader['name'] = $fileLocation[2]; } $fileLocation = array(rtrim($fileLocation[0], '/') . '/' . pathinfo($file, PATHINFO_BASENAME), rtrim($fileLocation[1], '/') . '/' . pathinfo($file, PATHINFO_BASENAME)); } } if ($response->getWorstStatus()) { $result = $response->getResponse(); return array('OK' => 0, 'file' => $fileLocation[1], 'response' => $result['messages']); } if (isset($uploader['error'])) { throw new UploaderException(UploaderController::getErrorCode()); } else { return array('OK' => 1, 'file' => $fileLocation[1]); } }
/** * Handles the upload request. * * @param array $conf * * @return array|bool */ static function handleRequest($conf = array()) { $cx = Cx::instanciate(); // 5 minutes execution time @set_time_limit(5 * 60); self::$_error = null; // start fresh $conf = self::$conf = array_merge(array('file_data_name' => 'file', 'tmp_dir' => $_SESSION->getTempPath(), 'target_dir' => 'images/content/', 'cleanup' => true, 'max_file_age' => 5 * 3600, 'chunk' => isset($_REQUEST['chunk']) ? intval($_REQUEST['chunk']) : 0, 'chunks' => isset($_REQUEST['chunks']) ? intval($_REQUEST['chunks']) : 0, 'fileName' => isset($_REQUEST['name']) ? $_REQUEST['name'] : false, 'allow_extensions' => false, 'delay' => 0, 'cb_sanitizeFileName' => array(__CLASS__, 'sanitizeFileName'), 'cb_check_file' => false), $conf); try { if (!$conf['fileName']) { if (!empty($_FILES)) { $conf['fileName'] = $_FILES[$conf['file_data_name']]['name']; } else { throw new UploaderException('', PLUPLOAD_INPUT_ERR); } } // Cleanup outdated temp files and folders if ($conf['cleanup']) { self::cleanup(); } // Fake network congestion if ($conf['delay']) { usleep($conf['delay']); } // callback function for sanitizie filename if (is_callable($conf['cb_sanitizeFileName'])) { $fileName = call_user_func($conf['cb_sanitizeFileName'], $conf['fileName']); } else { $fileName = $conf['fileName']; } // Check if file type is allowed if ($conf['allow_extensions']) { if (is_string($conf['allow_extensions'])) { $conf['allow_extensions'] = preg_split('{\\s*,\\s*}', $conf['allow_extensions']); } if (!in_array(strtolower(pathinfo($fileName, PATHINFO_EXTENSION)), $conf['allow_extensions'])) { throw new UploaderException('', PLUPLOAD_TYPE_ERR); } } $file_path = rtrim($conf['tmp_dir'], DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . $fileName; $tmp_path = $file_path . ".part"; // Write file or chunk to appropriate temp location if ($conf['chunks']) { self::writeFileTo("{$file_path}.dir.part" . DIRECTORY_SEPARATOR . $conf['chunk']); // Check if all chunks already uploaded if ($conf['chunk'] == $conf['chunks'] - 1) { self::writeChunksToFile("{$file_path}.dir.part", $tmp_path); } } else { self::writeFileTo($tmp_path); } // Upload complete write a temp file to the final destination if (!$conf['chunks'] || $conf['chunk'] == $conf['chunks'] - 1) { if (is_callable($conf['cb_check_file']) && !call_user_func($conf['cb_check_file'], $tmp_path)) { @unlink($tmp_path); throw new UploaderException('', PLUPLOAD_SECURITY_ERR); } $new_path = $conf['target_dir'] . $fileName; \Cx\Lib\FileSystem\FileSystem::move($tmp_path, $new_path, true); $rootPath = $cx->getWebsitePath() . $conf['target_dir']; $rootPathFull = $cx->getWebsitePath() . $new_path; $filePathinfo = pathinfo($rootPathFull); $fileExtension = $filePathinfo['extension']; $fileNamePlain = $filePathinfo['filename']; $im = new \ImageManager(); if ($im->_isImage($rootPathFull)) { foreach (UploaderConfiguration::getInstance()->getThumbnails() as $thumbnail) { $im->_createThumb($rootPath, $conf['target_dir'], $fileName, $thumbnail['size'], $thumbnail['quality'], $fileNamePlain . $thumbnail['value'] . '.' . $fileExtension); } } return array('name' => $fileName, 'path' => $file_path, 'size' => filesize($file_path)); } // ok so far return true; } catch (UploaderException $ex) { self::$_error = $ex->getCode(); return array('error' => $ex->getCode()); } }
public function moveFile(File $file, $destination) { global $_ARRAYLANG; if (!empty($destination) || !\FWValidator::is_file_ending_harmless($destination)) { if (is_dir($this->getFullPath($file) . $file->getFullName())) { $fileName = $this->getFullPath($file) . $file->getFullName(); $destinationFileName = $this->getFullPath($file) . $destination; } else { $fileName = $this->getFullPath($file) . $file->getFullName(); $destinationFileName = $this->getFullPath($file) . $destination . '.' . $file->getExtension(); } if ($fileName == $destinationFileName) { return sprintf($_ARRAYLANG['TXT_FILEBROWSER_FILE_SUCCESSFULLY_RENAMED'], $file->getName()); } $destinationFolder = realpath(pathinfo($this->getFullPath($file) . $destination, PATHINFO_DIRNAME)); if (!MediaSourceManager::isSubdirectory($this->rootPath, $destinationFolder)) { return sprintf($_ARRAYLANG['TXT_FILEBROWSER_FILE_UNSUCCESSFULLY_RENAMED'], $file->getName()); } $this->removeThumbnails($file); if (!\Cx\Lib\FileSystem\FileSystem::move($fileName, $destinationFileName, false)) { return sprintf($_ARRAYLANG['TXT_FILEBROWSER_FILE_UNSUCCESSFULLY_RENAMED'], $file->getName()); } return sprintf($_ARRAYLANG['TXT_FILEBROWSER_FILE_SUCCESSFULLY_RENAMED'], $file->getName()); } else { return sprintf($_ARRAYLANG['TXT_FILEBROWSER_FILE_UNSUCCESSFULLY_RENAMED'], $file->getName()); } }
/** * handles the upload of a file * * @param string $inputName name of the HTML input element used to upload the file * * @return array $uploadedFileInfo array containing the properties for the uploaded file, * false when upload has failed */ function _handleUpload($inputName) { global $_ARRAYLANG, $sessionObj; $fileName = isset($_POST[$inputName]) ? contrexx_input2raw($_POST[$inputName]) : ''; if (empty($fileName)) { return array('name' => '', 'path' => '', 'size' => 0); } $uploaderId = isset($_POST['forumUploaderId']) ? contrexx_input2raw($_POST['forumUploaderId']) : ''; if (empty($uploaderId)) { \DBG::log('Uploader id is empty'); return false; } //Re-initialize the $sessionObj if it is empty if (empty($sessionObj)) { $sessionObj = \cmsSession::getInstance(); } $tempPath = $sessionObj->getTempPath() . '/' . $uploaderId . '/' . $fileName; if (!\Cx\Lib\FileSystem\FileSystem::exists($tempPath)) { return false; } $cx = \Cx\Core\Core\Controller\Cx::instanciate(); $filePath = $cx->getWebsiteMediaForumUploadPath() . '/'; $pathinfo = pathinfo($fileName); $i = 1; while (\Cx\Lib\FileSystem\FileSystem::exists($filePath . $fileName)) { $fileName = $pathinfo['filename'] . '_' . $i++ . '.' . $pathinfo['extension']; } if (\Cx\Lib\FileSystem\FileSystem::move($tempPath, $filePath . $fileName, true) === false) { $this->_objTpl->setVariable('TXT_FORUM_ERROR', $filePath . $fileName . ': ' . $_ARRAYLANG['TXT_FORUM_UPLOAD_NOT_MOVABLE']); return false; } return array('name' => contrexx_addslashes($fileName), 'path' => $filePath, 'size' => filesize($filePath . $fileName)); }
/** * rename the file or directory * * @param array $params supplied arguments from JsonData-request * @return string */ public function rename($params) { global $_ARRAYLANG, $objInit; $_ARRAYLANG = $objInit->loadLanguageData('ViewManager'); if (empty($params['post']['theme']) || empty($params['post']['oldName']) || empty($params['post']['newName'])) { return array('status' => 'error', 'message' => $_ARRAYLANG['TXT_THEME_OPERATION_FAILED_FOR_EMPTY_NAME']); } if ($params['post']['isFolder'] && preg_match('/^\\./', trim($params['post']['newName']))) { // folder name should not start with dot(.) return array('status' => 'error', 'reload' => false, 'message' => sprintf($_ARRAYLANG['TXT_THEME_FOLDER_NAME_NOT_ALLOWED'], contrexx_input2xhtml($params['post']['newName']))); } $matches = null; preg_match('@{([0-9A-Za-z._-]+)(:([_a-zA-Z][A-Za-z_0-9]*))?}@sm', $params['post']['newName'], $matches); if (!empty($matches)) { return array('status' => 'error', 'reload' => false, 'message' => sprintf($_ARRAYLANG['TXT_THEME_NAME_NOT_ALLOWED'], contrexx_input2xhtml($params['post']['newName']))); } $currentThemeFolder = \Env::get('cx')->getWebsiteThemesPath() . '/' . $params['post']['theme']; $oldFilePath = $params['post']['oldName']; $newFileName = $params['post']['newName']; $isFolder = $params['post']['isFolder'] ?: 0; $newFilePath = \Cx\Lib\FileSystem\FileSystem::replaceCharacters($newFileName); // Cannot rename the virtual directory $virtualDirs = array('/' . \Cx\Core\Core\Model\Entity\SystemComponent::TYPE_CORE_MODULE, '/' . \Cx\Core\Core\Model\Entity\SystemComponent::TYPE_MODULE, '/' . \Cx\Core\Core\Model\Entity\SystemComponent::TYPE_CORE); if (in_array($oldFilePath, $virtualDirs) || in_array('/' . $newFilePath, $virtualDirs)) { return array('status' => 'error', 'reload' => false, 'message' => $_ARRAYLANG['TXT_THEME_OPERATION_FAILED_FOR_RENAME_VIRTUAL_FOLDER']); } if (!\Cx\Lib\FileSystem\FileSystem::exists($currentThemeFolder . $oldFilePath) && \Cx\Core\ViewManager\Controller\ViewManager::isFileTypeComponent($oldFilePath)) { // resolve the component file $componentFilePath = \Cx\Core\ViewManager\Controller\ViewManager::getComponentFilePath($oldFilePath, false); if ($componentFilePath && \Cx\Lib\FileSystem\FileSystem::exists($currentThemeFolder . $componentFilePath)) { // file exists $oldFilePath = \Cx\Core\ViewManager\Controller\ViewManager::getComponentFilePath($oldFilePath, false); } else { // file not exists may be a folder $oldFilePath = \Cx\Core\ViewManager\Controller\ViewManager::replaceComponentFolderByItsType($oldFilePath); } } if (\Cx\Lib\FileSystem\FileSystem::exists($currentThemeFolder . '/' . $oldFilePath)) { $dirName = dirname($currentThemeFolder . $oldFilePath); if (!\FWValidator::is_file_ending_harmless($newFilePath)) { return array('status' => 'error', 'reload' => false, 'message' => sprintf($_ARRAYLANG['TXT_THEME_FILE_EXTENSION_NOT_ALLOWED'], contrexx_input2xhtml($newFilePath))); } if (\Cx\Lib\FileSystem\FileSystem::exists($dirName . '/' . $newFilePath)) { return array('status' => 'error', 'reload' => false, 'message' => sprintf($_ARRAYLANG['TXT_THEME_OPERATION_FAILED_FOR_FILE_ALREADY_EXITS'], contrexx_input2xhtml($newFileName))); } \Cx\Lib\FileSystem\FileSystem::move($currentThemeFolder . $oldFilePath, $dirName . '/' . $newFilePath, true); if (!\Cx\Lib\FileSystem\FileSystem::exists($dirName . '/' . $newFilePath)) { return array('status' => 'error', 'reload' => false, 'message' => $_ARRAYLANG['TXT_THEME_RENAME_FAILED']); } $path = preg_replace('#' . $currentThemeFolder . '#', '', $dirName . '/' . $newFilePath); $message = $isFolder ? $_ARRAYLANG['TXT_THEME_FOLDER_RENAME_SUCCESS'] : $_ARRAYLANG['TXT_THEME_FILE_RENAME_SUCCESS']; return array('status' => 'success', 'reload' => true, 'path' => \Cx\Core\ViewManager\Controller\ViewManager::getThemeRelativePath($path), 'message' => $message); } return array('status' => 'error', 'reload' => false, 'message' => sprintf($_ARRAYLANG['TXT_THEME_OPERATION_FAILED_FOR_FILE_NOT_EXITS'], contrexx_input2xhtml($newFileName))); }