/**
  * 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 $name
  * @param description of image, if empty will remain empty
  * @return returns true if successfull otherwise returns an ImageUploadError
  */
 function importImage($tmpName, $name, $cat, $title = '', $desc = '')
 {
     global $rsgConfig;
     $database =& JFactory::getDBO();
     $my =& JFactory::getUser();
     $destination = fileUtils::move_uploadedFile_to_orignalDir($tmpName, $name);
     if (is_a($destination, imageUploadError)) {
         return $destination;
     }
     $parts = pathinfo($destination);
     $newName = $parts['basename'];
     // fill $title if empty
     if ($title == '') {
         $title = substr($parts['basename'], 0, -(strlen($parts['extension']) + ($parts['extension'] == '' ? 0 : 1)));
     }
     // determine ordering
     $database->setQuery("SELECT COUNT(1) FROM #__rsgallery2_files WHERE gallery_id = '{$cat}'");
     $ordering = $database->loadResult() + 1;
     //Store image details in database
     $alias = mysql_real_escape_string(JFilterOutput::stringURLSafe($title));
     $desc = mysql_real_escape_string($desc);
     $title = mysql_real_escape_string($title);
     $database->setQuery("INSERT INTO #__rsgallery2_files" . " (title, name, descr, gallery_id, date, ordering, userid, alias) VALUES" . " ('{$title}', '{$newName}', '{$desc}', '{$cat}', now(), '{$ordering}', '{$my->id}', '{$alias}')");
     if (!$database->query()) {
         audioUtils::deleteAudio($parts['basename']);
         return new imageUploadError($parts['basename'], $database->stderr(true));
     }
     return true;
 }
 /**
  * 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'));
     }
 }
Exemple #3
0
 /**
  *
  * Output specified file
  *
  * @access	public
  * @param	$file	string	File URL
  */
 public function output($file, $asname = '')
 {
     if (empty($asname)) {
         $asname = basename($file);
     }
     switch (fileUtils::getFileExtension($file)) {
         case 'jpeg':
         case 'jpg':
             $ctype = 'image/jpeg';
             break;
         case 'gif':
             $ctype = 'image/gif';
             break;
         case 'png':
             $ctype = 'image/png';
             break;
         default:
             $ctype = 'application/force-download';
             header('content-disposition:attachment;filename=' . $asname);
             break;
     }
     header('Content-Type:' . $ctype);
     readfile($file);
     exit(0);
 }
 /**
  * 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 $name
  * @param description of image, if empty will remain empty
  * @todo deleteImage (video)
  * @return returns true if successfull otherwise returns an ImageUploadError
  */
 function importImage($tmpName, $name, $cat, $title = '', $desc = '')
 {
     global $rsgConfig;
     $my =& JFactory::getUser();
     $database =& JFactory::getDBO();
     $destination = fileUtils::move_uploadedFile_to_orignalDir($tmpName, $name);
     if (is_a($destination, imageUploadError)) {
         return $destination;
     }
     $parts = pathinfo($destination);
     // fill $imgTitle if empty
     if ($imgTitle == '') {
         $imgTitle = substr($parts['basename'], 0, -(strlen($parts['extension']) + ($parts['extension'] == '' ? 0 : 1)));
     }
     // replace names with the new name we will actually use
     $parts = pathinfo($destination);
     $newName = $parts['basename'];
     $imgName = $parts['basename'];
     //Destination becomes original video, just for readability
     $original_video = $destination;
     $result = true;
     do {
         // New video will be located in display folder
         $newVideo = JPATH_DISPLAY . DS . $newName . "." . $rsgConfig->get("videoConverter_extension");
         $result = Ffmpeg::convertVideo($original_video, $newVideo);
         if (!$result) {
             $result = new imageUploadError($imgName, "error converting video: <pre>" . print_r($result->getMessage(), true) . "</pre>");
             break;
         }
         // get first frame of the video to genetrate a thumbnail from
         $videoPreviewImage = JPATH_ORIGINAL . DS . $newName . ".png";
         $result = Ffmpeg::capturePreviewImage($original_video, $videoPreviewImage);
         if (!$result) {
             $result = new imageUploadError($imgName, "error capturing preview image: <pre>" . print_r($result->getMessage(), true) . "</pre>");
             break;
         }
         //Get details of the original image.
         $width = getimagesize($videoPreviewImage);
         if (!$width) {
             $result = new imageUploadError($videoPreviewImage, "not an image OR can't read {$videoPreviewImage}");
             break;
         } else {
             //the actual image width
             $width = $width[0];
         }
         $result = imgUtils::makeThumbImage($videoPreviewImage, $newName);
         // remove the temporary preview image
         JFile::delete($videoPreviewImage);
         if (!$result) {
             $result = new imageUploadError($imgName, JText::_('ERROR CREATING THUMB IMAGE') . ": " . $videoPreviewImage);
             break;
         }
         // determine ordering
         $database->setQuery("SELECT COUNT(1) FROM #__rsgallery2_files WHERE gallery_id = '{$cat}'");
         $ordering = $database->loadResult() + 1;
         //Store image details in database
         $alias = mysql_real_escape_string(JFilterOutput::stringURLSafe($title));
         $desc = mysql_real_escape_string($desc);
         $title = mysql_real_escape_string($title);
         $database->setQuery("INSERT INTO #__rsgallery2_files" . " (title, name, descr, gallery_id, date, ordering, userid, alias) VALUES" . " ('{$title}', '{$newName}', '{$desc}', '{$cat}', now(), '{$ordering}', '{$my->id}', '{$alias}')");
         if (!$database->query()) {
             $result = new imageUploadError($parts['basename'], $database->stderr(true));
             break;
         }
     } while (false);
     if ($result !== true) {
         // clean up
         if (JFile::exists($newVideo)) {
             JFile::delete($newVideo);
         }
         if (JFile::exists($videoPreviewImage)) {
             JFile::delete($videoPreviewImage);
         }
         imgUtils::deleteImage($newName);
     }
     return $result;
 }
Exemple #5
0
function copyImage($cid, $option)
{
    global $mainframe;
    $database =& JFactory::getDBO();
    //For each error that is found, store error message in array
    $errors = array();
    $cat_id = rsgInstance::getInt('move_id', '');
    //get gallery id to copy item to
    if (!$cat_id) {
        echo "<script> alert('No gallery selected to move to'); window.history.go(-1);</script>\n";
        exit;
    }
    //Create unique copy name
    $tmpdir = uniqid('rsgcopy_');
    //Get full path to copy directory
    $copyDir = JPath::clean(JPATH_ROOT . '/media/' . $tmpdir . '/');
    if (!JFolder::create($copyDir)) {
        $errors[] = 'Unable to create temp directory ' . $copyDir;
    } else {
        foreach ($cid as $id) {
            $gallery = rsgGalleryManager::getGalleryByItemID($id);
            $item = $gallery->getItem($id);
            $original = $item->original();
            $source = $original->filePath();
            $destination = $copyDir . $item->name;
            if (is_dir($copyDir)) {
                if (file_exists($source)) {
                    if (!JFile::copy($source, $destination)) {
                        $errors[] = 'The file could not be copied!';
                    } else {
                        //Actually importing the image
                        $e = fileUtils::importImage($destination, $item->name, $cat_id, $item->title, $item->description);
                        if ($e !== true) {
                            $errors[] = $e;
                        }
                        if (!JFile::delete($destination)) {
                            $errors[] = 'Unable to delete the file' . $item->name;
                        }
                    }
                }
            }
        }
        if (!rmdir($copyDir)) {
            $errors[] = 'Unable to delete the temp directory' . $copyDir;
        }
    }
    //Error handling if necessary
    if (count($errors) == 0) {
        $mainframe->redirect("index2.php?option={$option}&rsgOption=images", JText::_('Item(s) copied successfully!'));
    } else {
        //Show error message for each error encountered
        foreach ($errors as $e) {
            echo $e->toString();
        }
        //If there were more files than errors, assure the user the rest went well
        if (count($errors) < count($files["error"])) {
            echo "<br>" . JText::_('Rest of the items copied successfully!');
        }
    }
}
 public static function upgrade()
 {
     require_once 'filehandler.class.php';
     $path = GSDATAOTHERPATH . 'custom_settings/';
     $files = array_diff(scandir($path), array('.', '..', '.htaccess'));
     $flag = false;
     foreach ($files as $file) {
         $data = file_get_contents($path . $file);
         $data = json_decode($data, TRUE);
         $tabs = array(&$data);
         if (array_key_exists('site', $data)) {
             $tabs =& $data['site'];
         }
         foreach ($tabs as &$tab) {
             foreach ($tab['settings'] as &$setting) {
                 if (strpos($setting['type'], 'fancy-') > -1) {
                     $setting['type'] = str_replace('fancy', 'icon', $setting['type']);
                     $flag = true;
                 }
                 if (array_key_exists('values', $setting)) {
                     $setting['i18n'] = $setting['values'];
                     unset($setting['values']);
                     $flag = true;
                 }
                 if (array_key_exists('langs', $setting)) {
                     $setting['i18n'] = $setting['langs'];
                     unset($setting['langs']);
                     $flag = true;
                 }
                 if (array_key_exists('i18n', $setting) && array_key_exists('value', $setting) && $setting['value'] !== $setting['i18n'][0]) {
                     $setting['value'] = $setting['i18n'][0];
                     $flag = true;
                 }
             }
         }
         if ($flag === true) {
             file_put_contents($path . $file, fileUtils::indentJSON($data));
         }
     }
 }
<?php

if (isset($_REQUEST) && isset($_REQUEST['id']) && isset($_REQUEST['requestToken']) && isset($_REQUEST['adminDir'])) {
    require_once '../../' . $_REQUEST['adminDir'] . '/inc/common.php';
    require_once 'filehandler.class.php';
    require_once 'customsettings.class.php';
    require_once '../../' . $_REQUEST['adminDir'] . '/inc/plugin_functions.php';
    global $USR, $i18n, $custom_settings, $custom_settings_dictionary;
    $token = $_REQUEST['requestToken'];
    $id = $_REQUEST['id'];
    $getToken = fileUtils::requestToken('kosstt');
    if ($token === $getToken) {
        if (isset($_REQUEST['action'])) {
            $data = isset($_REQUEST['data']) ? $_REQUEST['data'] : NULL;
            switch ($_REQUEST['action']) {
                case 'loadPluginInfo':
                    echo customSettings::loadPluginInfo();
                    break;
                case 'loadImageBrowser':
                    echo json_encode(GSutils::getImageUploads(GSDATAUPLOADPATH));
                    break;
                case 'getI18NFile':
                    echo customSettings::i18nMerge();
                    break;
                case 'getDataFile':
                    echo json_encode($custom_settings);
                    break;
                case 'saveData':
                    $custom_settings = array('data' => json_decode($data, TRUE));
                    $custom_settings_dictionary = customSettings::mapAllSettings();
                    customSettings::saveAllSettings($custom_settings);
Exemple #8
0
 /**
  * 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 = '')
 {
     global $rsgConfig;
     $my =& JFactory::getUser();
     $database =& JFactory::getDBO();
     //First move uploaded file to original directory
     $destination = fileUtils::move_uploadedFile_to_orignalDir($imgTmpName, $imgName);
     if (is_a($destination, 'imageUploadError')) {
         return $destination;
     }
     $parts = pathinfo($destination);
     // If IPTC parameter in config is true and the user left either the image title
     // or description empty in the upload step we want to get that IPTC data.
     if ($rsgConfig->get('useIPTCinformation')) {
         if ($imgTitle == '' or $imgDesc == '') {
             getimagesize($destination, $imageInfo);
             if (isset($imageInfo['APP13'])) {
                 $iptc = iptcparse($imageInfo['APP13']);
                 //Get Iptc.Caption for the description (null if it does not exist)
                 $IPTCcaption = $iptc["2#120"][0];
                 //Get Iptc.ObjectName for the title
                 $IPTCtitle = $iptc["2#005"][0];
                 //If the field (description or title) in the import step is emtpy, and we have IPTC info, then use the IPTC info:
                 if ($imgDesc == '' and !is_null($IPTCcaption)) {
                     $imgDesc = $IPTCcaption;
                 }
                 if ($imgTitle == '' and !is_null($IPTCtitle)) {
                     $imgTitle = $IPTCtitle;
                 }
             }
         }
     }
     // fill $imgTitle if empty
     if ($imgTitle == '') {
         $imgTitle = substr($parts['basename'], 0, -(strlen($parts['extension']) + ($parts['extension'] == '' ? 0 : 1)));
     }
     // replace names with the new name we will actually use
     $parts = pathinfo($destination);
     $newName = $parts['basename'];
     $imgName = $parts['basename'];
     //Get details of the original image.
     $width = getimagesize($destination);
     if (!$width) {
         imgUtils::deleteImage($newName);
         return new imageUploadError($destination, JText::_('NOT AN IMAGE OR CANNOT READ') . " " . $destination);
     } else {
         //the actual image width and height and its max
         $height = $width[1];
         $width = $width[0];
         if ($height > $width) {
             $maxSideImage = $height;
         } else {
             $maxSideImage = $width;
         }
     }
     //Destination becomes original image, just for readability
     $original_image = $destination;
     // if original is wider or higher than display size, create a display image
     if ($maxSideImage > $rsgConfig->get('image_width')) {
         $result = imgUtils::makeDisplayImage($original_image, $newName, $rsgConfig->get('image_width'));
         if (!$result) {
             imgUtils::deleteImage($newName);
             return new imageUploadError($imgName, JText::_('ERROR CREATING DISPLAY IMAGE') . ": " . $newName);
         }
     } else {
         $result = imgUtils::makeDisplayImage($original_image, $newName, $maxSideImage);
         if (!$result) {
             imgUtils::deleteImage($newName);
             return new imageUploadError($imgName, JText::_('ERROR CREATING DISPLAY IMAGE') . ": " . $newName);
         }
     }
     // if original is wider or higher than thumb, create a thumb image
     if ($maxSideImage > $rsgConfig->get('thumb_width')) {
         $result = imgUtils::makeThumbImage($original_image, $newName);
         if (!$result) {
             imgUtils::deleteImage($newName);
             return new imageUploadError($imgName, JText::_('ERROR CREATING THUMB IMAGE') . ": " . $newName);
         }
     }
     // determine ordering
     $database->setQuery("SELECT COUNT(1) FROM #__rsgallery2_files WHERE gallery_id = '{$imgCat}'");
     $ordering = $database->loadResult() + 1;
     //Store image details in database
     $imgAlias = $database->getEscaped(JFilterOutput::stringURLSafe($imgTitle));
     $imgDesc = $database->getEscaped($imgDesc);
     $imgTitle = $database->getEscaped($imgTitle);
     $database->setQuery("INSERT INTO #__rsgallery2_files" . " (title, name, descr, gallery_id, date, ordering, userid, alias) VALUES" . " ('{$imgTitle}', '{$newName}', '{$imgDesc}', '{$imgCat}', now(), '{$ordering}', '{$my->id}', '{$imgAlias}')");
     if (!$database->query()) {
         imgUtils::deleteImage($newName);
         return new imageUploadError($imgName, $database->stderr(true));
     }
     //check if original image needs to be kept, otherwise delete it.
     if (!$rsgConfig->get('keepOriginalImage')) {
         JFile::delete(imgUtils::getImgOriginal($newName, true));
     }
     return true;
 }
 /**
  * Copies original images from Pony Gallery to the RSGallery2 file structure
  * and then creates display and thumb images.
  * @param string full path to the original Pony Images
  * @return True id succesfull, false if not
  */
 function copyImages($basedir, $prefix = "easy_")
 {
     global $rsgConfig;
     $database = JFactory::getDBO();
     $sql = "SELECT * FROM #__easygallery";
     $database->setQuery($sql);
     $result = $database->loadObjectList();
     $i = 0;
     foreach ($result as $image) {
         $source = $basedir . "/" . $image->path;
         $filename = array_reverse(explode("/", $image->path));
         $destination = JPATH_ORIGINAL . "/" . $prefix . $filename[0];
         //First move image to original folder
         $newpath = fileUtils::move_uploadedFile_to_orignalDir($source, $destination);
         if ($newpath) {
             imgUtils::makeDisplayImage($newpath, '', $rsgConfig->get('image_width'));
             imgUtils::makeThumbImage($newpath);
         } else {
             $i++;
         }
     }
     if ($i > 0) {
         return false;
     } else {
         return true;
     }
 }