Пример #1
0
function deleteImages()
{
    global $mainframe;
    $database =& JFactory::getDBO();
    $name = rsgInstance::getVar('name', null);
    if (imgUtils::deleteImage($name)) {
        $txt = JText::_('Image(s) deleted succesfully!');
    } else {
        $txt = JText::_('Image(s) were not deleted!');
    }
    $mainframe->redirect("index2.php?option=com_rsgallery2&rsgOption=maintenance&task=consolidateDB", $txt);
    /*
    //Check if file is in database
    $sql ="SELECT count(name) FROM #__rsgallery2_files WHERE name = '$name'";
    $database->setQuery($sql);
    $result = $database->loadResult();
    
    if ($result > 0) {
    	//Delete from database
    	imgUtils::deleteImage( $name );
    }
    $mainframe->redirect("index2.php?option=com_rsgallery2&rsgOption=maintenance&task=consolidateDB", JText::_('Image(s) deleted succesfully!'));
    */
}
Пример #2
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;
 }
Пример #3
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;
 }
Пример #4
0
 /**
  * recursively deletes a tree of galleries
  * @param id of the gallery
  * @todo this is a quick hack.  galleryUtils and imgUtils need to be reorganized; and a rsgImage class created to do this proper
  */
 function _deleteTree($galleries)
 {
     global $rsgAccess;
     $database =& JFactory::getDBO();
     foreach ($galleries as $gallery) {
         rsgGalleryManager::_deleteTree($gallery->kids());
         // delete images in gallery
         foreach ($gallery->items() as $item) {
             imgUtils::deleteImage(galleryUtils::getFileNameFromId($item->id));
         }
         // delete gallery
         $id = $gallery->get('id');
         if (!is_numeric($id)) {
             return false;
         }
         $query = "DELETE FROM #__rsgallery2_galleries WHERE id = {$id}";
         echo "<br>deleting gallery {$id}";
         $database->setQuery($query);
         if (!$database->query()) {
             echo $database->error();
         }
         // Delete permissions here
         $rsgAccess->deletePermissions($id);
     }
 }
Пример #5
0
function deleteCat()
{
    global $rsgConfig, $mainframe;
    $my = JFactory::getUser();
    $database = JFactory::getDBO();
    //Get values from URL
    $catid = rsgInstance::getInt('gid', null);
    //Mirjam: catid is gid as of v1.14
    //Set redirect URL
    $redirect = JRoute::_("index.php?option=com_rsgallery2&rsgOption=myGalleries", false);
    //Get category details
    $database->setQuery("SELECT * FROM #__rsgallery2_galleries WHERE id = '{$catid}'");
    $rows = $database->LoadObjectList();
    foreach ($rows as $row) {
        $uid = $row->uid;
        $parent = $row->parent;
    }
    //Check if gallery has children
    $database->setQuery("SELECT COUNT(1) FROM #__rsgallery2_galleries WHERE parent = '{$catid}'");
    $count = $database->loadResult();
    if ($count > 0) {
        $mainframe->redirect($redirect, JText::_('USERCAT_SUBCATS'));
    }
    //No children from here, so lets continue
    if ($uid == $my->id or $my->usertype == 'Super Administrator') {
        //Delete images
        $database->setQuery("SELECT name FROM #__rsgallery2_files WHERE gallery_id = '{$catid}'");
        $result = $database->loadResultArray();
        $error = 0;
        foreach ($result as $filename) {
            if (!imgUtils::deleteImage($filename)) {
                $error++;
            }
        }
        //Error checking
        if ($error == 0) {
            //Gallery can be deleted
            $database->setQuery("DELETE FROM #__rsgallery2_galleries WHERE id = '{$catid}'");
            if (!$database->query()) {
                //Error message, gallery could not be deleted
                $mainframe->redirect($redirect, JText::_('Gallery could not be deleted!'));
            } else {
                //Ok, goto mainpage
                $mainframe->redirect($redirect, JText::_('Gallery deleted!'));
            }
        } else {
            //There were errors. Gallery will not be deleted
            $mainframe->redirect($redirect, JText::_('Gallery could not be deleted!'));
        }
    } else {
        //Abort and return to mainscreen
        $mainframe->redirect($redirect, JText::_('USER_CAT_NOTOWNER'));
    }
}