/** * returns a gallery * @param id of the gallery * @todo move published check to rsgAccess */ function get($id = null) { global $rsgAccess, $rsgConfig; $my =& JFactory::getUser(); if ($id === null) { $id = rsgInstance::getInt('catid', 0); $id = rsgInstance::getInt('gid', $id); if (!$id) { // check if an item id is set and if so return the gallery for that item id if (rsgInstance::getInt('id', 0)) { return rsgGalleryManager::getGalleryByItemID(); } } } // since the user will never be offered the chance to view a gallery they can't, unauthorized attempts at viewing are a hacking attempt, so it is ok to print an unfriendly error. $rsgAccess->checkGallery('view', $id) or die("RSGallery2: Access denied to gallery {$id}"); $gallery = rsgGalleryManager::_get($id); // if gallery is unpublished don't show it unless ACL is enabled and users has permissions to modify (owners can view their unpublished galleries). if ($gallery->get('published') < 1) { // if user is admin or superadmin then always return the gallery if ($my->gid > 23) { return $gallery; } if ($rsgConfig->get('acl_enabled')) { if (!$rsgAccess->checkGallery('create_mod_gal', $id)) { die("RSGallery2: Access denied to gallery {$id}"); } } else { die("RSGallery2: Access denied to gallery {$id}"); } } return $gallery; }
/** * Forces a download box to download single images * Thanks to Rich Malak <*****@*****.**>for his invaluable contribution * to this very important feature! * @param int Id of the file to download */ function downloadFile($id) { global $rsgConfig; //Clean and delete current output buffer ob_end_clean(); $gallery = rsgGalleryManager::getGalleryByItemID(); $item = $gallery->getItem(); $original = $item->original(); $file = $original->filePath(); //Open up the file if ($fd = fopen($file, "r")) { $fsize = filesize($file); $path_parts = pathinfo($file); $ext = strtolower($path_parts["extension"]); //Check the extension and provide the right headers for the file switch ($ext) { case "pdf": header("Content-type: application/pdf"); // add here more headers for diff. extensions header("Content-Disposition: attachment; filename=\"" . $path_parts["basename"] . "\""); // use 'attachement' to force a download break; case "jpg": header("Content-type: image/jpeg"); header("Content-Disposition: attachment; filename=\"" . $path_parts["basename"] . "\""); break; case "gif": header("Content-type: image/gif"); header("Content-Disposition: attachment; filename=\"" . $path_parts["basename"] . "\""); break; case "png": header("Content-type: image/png"); header("Content-Disposition: attachment; filename=\"" . $path_parts["basename"] . "\""); break; default: header("Content-type: application/octet-stream"); header("Content-Disposition: attachment; filename=\"" . $path_parts["basename"] . "\""); } header("Content-length: {$fsize}"); header("Cache-control: private"); //Read the contents of the file while (!feof($fd)) { $buffer = fread($fd, 4096); echo $buffer; } } //Close file after use! fclose($fd); }
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!'); } } }
function showImages($option, &$rows, &$lists, &$search, &$pageNav) { global $rsgOption, $option, $rsgConfig; $my = JFactory::getUser(); ?> <form action="index2.php" method="post" name="adminForm"> <table border="0" width="100%"> <tr> <td align="left" width="50%"> </td> <td align="right" width="50%"> <?php echo JText::_('Copy/Move:'); ?> <?php echo $lists['move_id']; ?> <?php echo JText::_('Filter:'); ?> <input type="text" name="search" value="<?php echo $search; ?> " class="text_area" onChange="document.adminForm.submit();" /> <?php echo $lists['gallery_id']; ?> </td> </tr> </table> <table class="adminlist"> <thead> <tr> <th width="5">ID</th> <th width="20"> <input type="checkbox" name="toggle" value="" onclick="checkAll(<?php echo count($rows); ?> );" /> </th> <th class="title"><?php echo JText::_('Title (filename)'); echo JText::_('Num'); ?> </th> <th width="5%"><?php echo JText::_('Published'); ?> </th> <th colspan="2" width="5%"><?php echo JText::_('Reorder'); ?> </th> <th width="2%"><?php echo JText::_('Order'); ?> </th> <th width="2%"> <a href="javascript: saveorder( <?php echo count($rows) - 1; ?> )"> <img src="images/filesave.png" border="0" width="16" height="16" alt="Save Order" /> </a> </th> <th width="15%" align="left"><?php echo JText::_('Gallery'); ?> </th> <th width="5%"><?php echo JText::_('Hits'); ?> </th> <th width=""><?php echo JText::_('Date & time'); ?> </th> </tr> </thead> <tbody> <?php $k = 0; for ($i = 0, $n = count($rows); $i < $n; $i++) { $row =& $rows[$i]; $link = 'index2.php?option=com_rsgallery2&rsgOption=' . $rsgOption . '&task=editA&hidemainmenu=1&id=' . $row->id; $task = $row->published ? 'unpublish' : 'publish'; $img = $row->published ? 'publish_g.png' : 'publish_x.png'; $alt = $row->published ? 'Published' : 'Unpublished'; $checked = JHTML::_('grid.checkedout', $row, $i); $row->cat_link = 'index2.php?option=com_rsgallery2&rsgOption=galleries&task=editA&hidemainmenu=1&id=' . $row->gallery_id; ?> <tr class="<?php echo "row{$k}"; ?> "> <td> <?php echo $row->id; ?> </td> <td> <?php echo $checked; ?> </td> <td> <?php if ($row->checked_out && $row->checked_out != $my->id) { echo $row->title; } else { $gallery = rsgGalleryManager::getGalleryByItemID($row->id); if ($gallery !== null) { if (is_a($gallery->getItem($row->id), 'rsgItem_audio')) { $type = 'audio'; } else { $type = 'image'; } } echo JHTML::tooltip('<img src="' . JURI_SITE . $rsgConfig->get('imgPath_thumb') . '/' . $row->name . '.jpg" alt="' . $row->name . '" />', JText::_('Edit Images'), $row->name, htmlspecialchars(stripslashes($row->title), ENT_QUOTES) . ' (' . $row->name . ')', $link, 1); } ?> </td> <td align="center"> <a href="javascript: void(0);" onclick="return listItemTask('cb<?php echo $i; ?> ','<?php echo $task; ?> ')"> <img src="images/<?php echo $img; ?> " width="12" height="12" border="0" alt="<?php echo $alt; ?> " /> </a> </td> <td> <?php echo $pageNav->orderUpIcon($i, $row->gallery_id == @$rows[$i - 1]->gallery_id); ?> </td> <td> <?php echo $pageNav->orderDownIcon($i, $n, $row->gallery_id == @$rows[$i + 1]->gallery_id); ?> </td> <td colspan="2" align="center"> <input type="text" name="order[]" size="5" value="<?php echo $row->ordering; ?> " class="text_area" style="text-align: center" /> </td> <td> <a href="<?php echo $row->cat_link; ?> " title="Edit Category"> <?php echo $row->category; ?> </a> </td> <td align="left"> <?php echo $row->hits; ?> </td> <td align="left"> <?php echo $row->date; ?> </td> </tr> </tbody> <?php $k = 1 - $k; } ?> <tfoot> <tr> <td colspan="11"><?php echo $pageNav->getListFooter(); ?> </td> </tr> </tfoot> </table> <input type="hidden" name="option" value="<?php echo $option; ?> " /> <input type="hidden" name="rsgOption" value="<?php echo $rsgOption; ?> " /> <input type="hidden" name="task" value="" /> <input type="hidden" name="boxchecked" value="0" /> <input type="hidden" name="hidemainmenu" value="0"> </form> <?php }