Esempio n. 1
0
/**
 * Used in the consolidate database function
 * Creates images based on an image id or an image name
 */
function regenerateImage()
{
    global $mainframe;
    global $rsgConfig;
    $database =& JFactory::getDBO();
    //Check if id or name is set
    if (isset($_REQUEST['id'])) {
        $id = rsgInstance::getInt('id', null);
        $name = galleryUtils::getFileNameFromId($id);
    } elseif (isset($_REQUEST['name'])) {
        $name = rsgInstance::getVar('name', null);
    } else {
        $mainframe->redirect("index2.php?option=com_rsgallery2&task=batchupload", JText::_('No fileinformation found. This should never happen!'));
    }
    //Just for readability of code
    $original = JPATH_ORIGINAL . '/' . $name;
    $display = JPATH_DISPLAY . '/' . imgUtils::getImgNameDisplay($name);
    $thumb = JPATH_THUMB . '/' . imgUtils::getImgNameThumb($name);
    if (file_exists($original)) {
        //Check if display image exists, if not make it.
        if (!file_exists($display)) {
            imgUtils::makeDisplayImage($original, NULL, $rsgConfig->get('image_width'));
        }
        if (!file_exists($thumb)) {
            imgUtils::makeThumbImage($original);
        }
    } else {
        if (file_exists($display)) {
            copy($display, $original);
        }
        if (!file_exists($thumb)) {
            imgUtils::makeThumbImage($display);
        }
    }
}
Esempio n. 2
0
/**
* Deletes one or more records
* @param array An array of unique category id numbers
* @param string The current url option
*/
function removeImages($cid, $option)
{
    global $rsgOption, $rsgConfig, $mainframe;
    $database =& JFactory::getDBO();
    $return = "index.php?option={$option}&rsgOption=images";
    if (!is_array($cid) || count($cid) < 1) {
        echo "<script> alert('Select an item to delete'); window.history.go(-1);</script>\n";
        exit;
    }
    //Delete images from filesystem
    if (count($cid)) {
        //Delete images from filesystem
        foreach ($cid as $id) {
            $name = galleryUtils::getFileNameFromId($id);
            $thumb = JPATH_ROOT . $rsgConfig->get('imgPath_thumb') . '/' . imgUtils::getImgNameThumb($name);
            $display = JPATH_ROOT . $rsgConfig->get('imgPath_display') . '/' . imgUtils::getImgNameDisplay($name);
            $original = JPATH_ROOT . $rsgConfig->get('imgPath_original') . '/' . $name;
            if (file_exists($thumb)) {
                if (!JFile::delete($thumb)) {
                    JError::raiseNotice('ERROR_CODE', JText::_('ERROR DELETING THUMB IMAGE') . " " . $thumb);
                    $mainframe->redirect($return);
                    return;
                }
            }
            if (file_exists($display)) {
                if (!JFile::delete($display)) {
                    JError::raiseNotice('ERROR_CODE', JText::_('ERROR DELETING DISPLAY IMAGE') . " " . $display);
                    $mainframe->redirect($return);
                    return;
                }
            }
            if (file_exists($original)) {
                if (!JFile::delete($original)) {
                    JError::raiseNotice('ERROR_CODE', JText::_('ERROR DELETING ORIGINAL IMAGE') . " " . $original);
                    $mainframe->redirect($return);
                    return;
                }
            }
        }
        //Delete from database
        $cids = implode(',', $cid);
        $query = "DELETE FROM #__rsgallery2_files" . "\n WHERE id IN ( {$cids} )";
        $database->setQuery($query);
        if (!$database->query()) {
            echo "<script> alert('" . $database->getErrorMsg() . "'); window.history.go(-1); </script>\n";
        }
    }
    $mainframe->redirect($return, JText::_('Image(s) deleted succesfully!'));
}
Esempio n. 3
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);
     }
 }
 /**
  * Retrieves the thumbnail image. presented in the category overview
  * @param int Category id
  * @param int image height
  * @param int image width
  * @param string Class name to format thumb view in css files
  * @return string html tag, showing the thumbnail
  * @todo being depreciated in favor of $rsgGallery->thumb() and $rsgDisplay functions
  */
 function getThumb($catid, $height = 0, $width = 0, $class = "")
 {
     global $mainframe;
     $database = JFactory::getDBO();
     //Setting attributes for image tag
     $imgatt = "";
     if ($height > 0) {
         $imgatt .= " height=\"{$height}\" ";
     }
     if ($width > 0) {
         $imgatt .= " width=\"{$width}\" ";
     }
     if ($class != "") {
         $imgatt .= " class=\"{$class}\" ";
     } else {
         $imgatt .= " class=\"rsg2-galleryList-thumb\" ";
     }
     //If no thumb, show default image.
     if (galleryUtils::getFileCount($catid) == 0) {
         $thumb_html = "<img {$imgatt} src=\"" . JURI_SITE . "/components/com_rsgallery2/images/no_pics.gif\" alt=\"No pictures in gallery\" />";
     } else {
         //Select thumb setting for specific gallery("Random" or "Specific thumb")
         $sql = "SELECT thumb_id FROM #__rsgallery2_galleries WHERE id = '{$catid}'";
         $database->setQuery($sql);
         $thumb_id = $database->loadResult();
         $list = galleryUtils::getChildList($catid);
         if ($thumb_id == 0) {
             //Random thumbnail
             $sql = "SELECT name FROM #__rsgallery2_files WHERE gallery_id IN ({$list}) AND published=1 ORDER BY rand() LIMIT 1";
             $database->setQuery($sql);
             $thumb_name = $database->loadResult();
         } else {
             //Specific thumbnail
             $thumb_name = galleryUtils::getFileNameFromId($thumb_id);
         }
         $thumb_html = "<img {$imgatt} src=\"" . imgUtils::getImgThumb($thumb_name) . "\" alt=\"\" />";
     }
     return $thumb_html;
 }
Esempio n. 5
0
/**
 * Deletes an item through the frontend My Galleries part
 */
function deleteItem()
{
    global $rsgAccess, $mainframe;
    $my = JFactory::getUser();
    $database = JFactory::getDBO();
    $id = rsgInstance::getInt('id', '');
    if ($id) {
        //Get gallery id
        $gallery_id = galleryUtils::getCatidFromFileId($id);
        //Check if file deletion is allowed in this gallery
        if ($rsgAccess->checkGallery('del_img', $gallery_id)) {
            $filename = galleryUtils::getFileNameFromId($id);
            imgUtils::deleteImage($filename);
            $mainframe->redirect(JRoute::_("index.php?option=com_rsgallery2&rsgOption=myGalleries"), JText::_('Image is deleted'));
        } else {
            $mainframe->redirect(JRoute::_("index.php?option=com_rsgallery2&rsgOption=myGalleries"), JText::_('USERIMAGE_NOTOWNER'));
        }
    } else {
        //No ID sent, no delete possible, back to my galleries
        $mainframe->redirect(JRoute::_("index.php?option=com_rsgallery2&rsgOption=myGalleries"), JText::_('No Id provided. Contact component developer'));
    }
}