/** * Takes an image file, moves the file and adds database entry * @param the verified REAL name of the local file including path * @param name of file according to user/browser or just the name excluding path * @param desired category * @param title of image, if empty will be created from $imgName * @param description of image, if empty will remain empty * @return returns true if successfull otherwise returns an ImageUploadError */ function importImage($imgTmpName, $imgName, $imgCat, $imgTitle = '', $imgDesc = '') { $handle = fileUtils::determineHandle($imgName); switch ($handle) { case 'imgUtils': return imgUtils::importImage($imgTmpName, $imgName, $imgCat, $imgTitle, $imgDesc); break; case 'videoUtils': return videoUtils::importImage($imgTmpName, $imgName, $imgCat, $imgTitle, $imgDesc); break; case 'audioUtils': return audioUtils::importImage($imgTmpName, $imgName, $imgCat, $imgTitle, $imgDesc); break; default: return new imageUploadError($imgName, "{$imgName}" . ' ' . JText::_('COM_RSGALLERY2_NOT_A_SUPPORTED_FILE_TYPE')); } }
function saveUploadedItem() { global $rsgConfig, $rsgAccess, $mainframe; $database = JFactory::getDBO(); //Set redirect URL $redirect = JRoute::_("index.php?option=com_rsgallery2&rsgOption=myGalleries", false); //Get category ID to check rights $i_cat = rsgInstance::getVar('i_cat', ''); //Get maximum number of images to upload $max_images = $rsgConfig->get('uu_maxImages'); //Check if user can upload in this gallery if (!$rsgAccess->checkGallery('up_mod_img', $i_cat)) { die('Unauthorized upload attempt!'); } //Check if number of images is not exceeded $count = 0; if ($count > $max_images) { //Notify user and redirect } else { //Go ahead and upload $upload = new fileHandler(); //Get parameters from form $i_file = rsgInstance::getVar('i_file', null, 'files', 'array'); $i_cat = rsgInstance::getInt('i_cat', ''); $title = rsgInstance::getVar('title', ''); $descr = rsgInstance::getVar('descr', '', 'post', 'string', JREQUEST_ALLOWRAW); $uploader = rsgInstance::getVar('uploader', ''); //Get filetype $file_ext = $upload->checkFileType($i_file['name']); //Check whether directories are there and writable $check = $upload->preHandlerCheck(); if ($check !== true) { $mainframe->redirect($redirect, $check); } switch ($file_ext) { case 'zip': if ($upload->checkSize($i_file) == 1) { $ziplist = $upload->handleZIP($i_file); //Set extract dir for uninstall purposes $extractdir = JPATH_ROOT . "/media/" . $upload->extractDir . '/'; //Import images into right folder for ($i = 0; $i < sizeof($ziplist); $i++) { $import = imgUtils::importImage($extractdir . $ziplist[$i], $ziplist[$i], $i_cat); } //Clean mediadir fileHandler::cleanMediaDir($upload->extractDir); //Redirect $mainframe->redirect($redirect, JText::_('Item uploaded succesfully!')); } else { //Error message $mainframe->redirect($redirect, JText::_('ZIP-file is too big!')); } break; case 'image': //Check if image is too big if ($i_file['error'] == 1) { $mainframe->redirect($redirect, JText::_('Image size is too big for upload')); } $file_name = $i_file['name']; if (move_uploaded_file($i_file['tmp_name'], JPATH_ROOT . "/media/" . $file_name)) { //Import into database and copy to the right places $imported = imgUtils::importImage(JPATH_ROOT . "/media/" . $file_name, $file_name, $i_cat, $title, $descr); if ($imported == 1) { if (file_exists(JPATH_ROOT . "/media/" . $file_name)) { unlink(JPATH_ROOT . "/media/" . $file_name); } } else { $mainframe->redirect($redirect, 'Importing image failed! Notify RSGallery2. This should never happen!'); } $mainframe->redirect($redirect, JText::_('Item uploaded succesfully!')); } else { $mainframe->redirect($redirect, JText::_('UPLOAD FAILED BACK TO UPLOADSCREEN')); } break; case 'error': $mainframe->redirect($redirect, JText::_('WRONG IMAGE FORMAT. WE WILL REDIRECT YOU TO THE UPLOAD SCREEN')); break; } } }
function save_batchupload() { global $rsgConfig, $mainframe; $database = JFactory::getDBO(); //Try to bypass max_execution_time as set in php.ini set_time_limit(0); $FTP_path = $rsgConfig->get('ftp_path'); $teller = rsgInstance::getInt('teller', null); $delete = rsgInstance::getVar('delete', null); $filename = rsgInstance::getVar('filename', null); $ptitle = rsgInstance::getVar('ptitle', null); $descr = rsgInstance::getVar('descr', array(0)); $extractdir = rsgInstance::getVar('extractdir', null); //Check if all categories are chosen if (isset($_REQUEST['category'])) { $category = rsgInstance::getVar('category', array(0)); } else { $category = array(0); } if (in_array('0', $category) || in_array('-1', $category)) { $mainframe->redirect("index2.php?option=com_rsgallery2&task=batchupload", JText::_('_RSGALLERY_ALERT_NOCATSELECTED')); } for ($i = 0; $i < $teller; $i++) { //If image is marked for deletion, delete and continue with next iteration if (isset($delete[$i]) and $delete[$i] == 'true') { //Delete file from server unlink(JPATH_ROOT . "/media/" . $extractdir . '/' . $filename[$i]); continue; } else { //Setting variables for importImage() $imgTmpName = JPATH_ROOT . "/media/" . $extractdir . '/' . $filename[$i]; $imgName = $filename[$i]; $imgCat = $category[$i]; $imgTitle = $ptitle[$i]; $imgDesc = $descr[$i]; //Import image $e = imgUtils::importImage($imgTmpName, $imgName, $imgCat, $imgTitle, $imgDesc); //Check for errors if ($e !== true) { $errors[] = $e; } } } //Clean up mediadir fileHandler::cleanMediaDir($extractdir); // Error handling if (isset($errors)) { if (count($errors) == 0) { echo JText::_('Item uploaded succesfully!'); } else { foreach ($errors as $err) { echo $err->toString(); } } } else { //Everything went smoothly, back to Control Panel global $mainframe; $mainframe->redirect("index2.php?option=com_rsgallery2", JText::_('Item uploaded succesfully!')); } }
function migrateImages($imgDir, $oldnewcats) { /* for every entry in $this->imgTable call imgUtils::importImage() with the info from $this->imgTable, $this->$commentTable and full path to image using $imgDir */ $database =& JFactory::getDBO(); $selectSQL = "SELECT imgfilename, imgtitle, catid FROM {$this->imgTable}"; $database->setQuery($selectSQL); $AKOFile = $database->loadObjectList(); $finalResult = true; foreach ($AKOFile as $file) { set_magic_quotes_runtime(0); $filePath = $imgDir . "/" . $file->imgfilename; $imgTitle = $file->imgtitle; $catId = $oldnewcats[$file->catid]; $fileName = $file->imgfilename; $result = imgUtils::importImage($filePath, $fileName, $catId, $imgTitle); if ($result !== true) { rsgInstall::writeInstallMsg($result->toString(), 'error'); $finalResult = false; return $finalResult; } } return $finalResult; }