コード例 #1
0
ファイル: view.raw.php プロジェクト: MrJookie/pm
 /**
  * Display the view
  *
  * @return    void
  */
 public function display($tpl = null)
 {
     $item = $this->get('Item');
     $params = JComponentHelper::getParams('com_pfdesigns', true);
     $layout = JRequest::getCmd('layout', 'preview');
     // Permission check.
     if ($item->params->get('access-view') !== true) {
         JError::raiseError(403, JText::_('JERROR_ALERTNOAUTHOR'));
         return false;
     }
     $options = array();
     if ($layout == 'preview') {
         $options['crop'] = true;
         $options['quality'] = 75;
         $options['size'] = $params->get('img_preview_size', '300x200');
     } else {
         $options['crop'] = false;
         $options['quality'] = 90;
         $options['size'] = $params->get('img_full_size', '960x540');
     }
     $source = PFdesignsHelper::getBasePath($item->project_id) . '/' . $item->file_name;
     $image = JModelLegacy::getInstance('Image', 'PFdesignsModel', $options);
     $image->setSource($source);
     $image->setCacheId('revision', $item->project_id, $item->id);
     $image->setAuthor($item->author_name);
     $image->save();
     if ($image->isCached()) {
         JFactory::getApplication()->redirect($image->getCachedURL());
     } else {
         $buffer = $image->getBuffer();
         if ($buffer) {
             header("Content-Type: image/jpeg");
             header("Accept-Ranges: bytes");
             header("Content-Length: " . filesize($image->getCachedFilePath()));
             echo $buffer;
         }
     }
     die;
 }
コード例 #2
0
ファイル: import.php プロジェクト: MrJookie/pm
 public function getItems()
 {
     $project = (int) $this->getState('filter.project');
     $base_path = PFdesignsHelper::getBasePath($project);
     $import_path = JPath::clean($base_path . '/_import');
     if ($project <= 0 || JFolder::exists($import_path) == false) {
         return array();
     }
     $i = 0;
     $items = array();
     $files = (array) JFolder::files($import_path);
     // First pass: Get uncategorised new designs
     foreach ($files as $file) {
         $ext = strtolower(JFile::getExt($file));
         if (!in_array($ext, array('jpeg', 'jpg', 'png', 'gif'))) {
             continue;
         }
         $info = getimagesize($import_path . '/' . $file);
         if (!$info) {
             continue;
         }
         if (!in_array($info[2], array(IMAGETYPE_GIF, IMAGETYPE_JPEG, IMAGETYPE_PNG))) {
             continue;
         }
         $item = new stdClass();
         $item->file_name = $file;
         $item->file_size = round(filesize($import_path . '/' . $file) / 1024);
         $item->file_ext = $ext;
         $item->file_source = '_import';
         $item->title = $file;
         $item->size = $info[0] . 'x' . $info[1];
         $item->project_id = $project;
         $item->parent_id = 0;
         $item->album_id = 0;
         $item->album_title = '';
         $item->design_title = '';
         $items[$i] = $item;
         $i++;
     }
     $sub_folders = (array) JFolder::folders($import_path);
     // Second pass: Find categorised new designs and design revisions
     foreach ($sub_folders as $folder) {
         $folder_length = strlen($folder);
         $is_album_folder = false;
         $is_design_folder = false;
         $album_id = 0;
         $design_id = 0;
         $album_title = '';
         $design_title = '';
         if ($folder_length < 6) {
             continue;
         }
         if (substr($folder, 0, 7) == 'design_') {
             $is_design_folder = true;
         } elseif ($folder_length > 6) {
             if (substr($folder, 0, 6) == 'album_') {
                 $is_album_folder = true;
             }
         }
         if (!$is_design_folder && !$is_album_folder) {
             // Folder is neither a design or album dir. skip it
             continue;
         }
         list($type, $id) = explode('_', $folder, 2);
         $id = (int) $id;
         // Find the album title
         if ($is_album_folder) {
             $album_title = $this->getAlbumTitle($id);
             $album_id = $id;
             if (!$album_title) {
                 continue;
             }
         }
         // Find the design title
         if ($is_design_folder) {
             $design_title = $this->getDesignTitle($id, $project);
             $design_id = $id;
             if (!$design_title) {
                 continue;
             }
         }
         // Get the actual files in the folder
         $files = (array) JFolder::files($import_path . '/' . $folder);
         foreach ($files as $file) {
             $ext = strtolower(JFile::getExt($file));
             if (!in_array($ext, array('jpeg', 'jpg', 'png', 'gif'))) {
                 continue;
             }
             $info = getimagesize($import_path . '/' . $folder . '/' . $file);
             if (!$info) {
                 continue;
             }
             if (!in_array($info[2], array(IMAGETYPE_GIF, IMAGETYPE_JPEG, IMAGETYPE_PNG))) {
                 continue;
             }
             $item = new stdClass();
             $item->file_name = $file;
             $item->file_size = round(filesize($import_path . '/' . $folder . '/' . $file) / 1024);
             $item->file_ext = $ext;
             $item->file_source = '_import/' . $folder;
             $item->title = $file;
             $item->size = $info[0] . 'x' . $info[1];
             $item->project_id = $project;
             $item->parent_id = $design_id;
             $item->album_id = $album_id;
             $item->album_title = $album_title;
             $item->design_title = $design_title;
             $items[$i] = $item;
             $i++;
         }
     }
     return $items;
 }
コード例 #3
0
ファイル: pfdesigns.php プロジェクト: MrJookie/pm
 /**
  * Method to get the thumbnail links of an item
  *
  * @param     object    $item    The design or revision object
  * @param     string    $type    The item type (design or revision)
  *
  * @return    void
  */
 public static function getThumbnails(&$item, $type = 'design')
 {
     static $preview_img = null;
     static $full_img = null;
     static $cover_img = null;
     $global_params = JComponentHelper::getParams('com_pfdesigns', true);
     // Set preview image class instance
     if (is_null($preview_img)) {
         $options = array();
         $options['crop'] = true;
         $options['quality'] = 60;
         $options['size'] = $global_params->get('img_preview_size', '300x200');
         $preview_img = JModelLegacy::getInstance('Image', 'PFdesignsModel', $options);
     }
     // Set full image class instance
     if (is_null($full_img)) {
         $options = array();
         $options['crop'] = true;
         $options['quality'] = 80;
         $options['size'] = $global_params->get('img_full_size', '1280x720');
         $full_img = JModelLegacy::getInstance('Image', 'PFdesignsModel', $options);
     }
     // Set cover image class instance
     if (is_null($cover_img)) {
         $options = array();
         $options['crop'] = true;
         $options['quality'] = 75;
         $options['size'] = $global_params->get('img_cover_size', '770x300');
         $cover_img = JModelLegacy::getInstance('Image', 'PFdesignsModel', $options);
     }
     // Try to find the media file
     $uploadpath = PFdesignsHelper::getBasePath($item->project_id);
     $item->file_exists = JFile::exists($uploadpath . '/' . $item->file_name);
     if ($item->file_exists) {
         // Find out whether the image is cached or not
         $preview_img->setCacheId($type, $item->project_id, $item->id);
         $item->preview_cached = $preview_img->isCached();
         $full_img->setCacheId($type, $item->project_id, $item->id);
         $item->full_cached = $full_img->isCached();
         $cover_img->setCacheId($type, $item->project_id, $item->id);
         $item->cover_cached = $cover_img->isCached();
         if ($type == 'design') {
             $link = PFdesignsHelperRoute::getDesignRoute($item->slug, $item->project_slug, $item->album_slug, '0:original');
             $item->preview_source = $item->preview_cached ? $preview_img->getCachedURL() : JRoute::_($link . '&tmpl=component&layout=preview&format=raw');
             $item->full_source = $item->full_cached ? $full_img->getCachedURL() : JRoute::_($link . '&tmpl=component&layout=full&format=raw');
             $item->cover_source = $item->cover_cached ? $cover_img->getCachedURL() : JRoute::_($link . '&tmpl=component&layout=cover&format=raw');
         } else {
             $link = 'index.php?option=com_pfdesigns&view=revision&id=' . $item->slug;
             $item->preview_source = $item->preview_cached ? $preview_img->getCachedURL() : JRoute::_($link . '&tmpl=component&layout=preview&format=raw');
             $item->full_source = $item->full_cached ? $full_img->getCachedURL() : JRoute::_($link . '&tmpl=component&layout=full&format=raw');
         }
     } else {
         list($p_w, $p_h) = explode('x', $global_params->get('img_preview_size', '400x300'), 2);
         list($c_w, $c_h) = explode('x', $global_params->get('img_cover_size', '770x300'), 2);
         $item->preview_source = JHtml::_('image', 'com_pfdesigns/preview-missing-' . intval($p_w) . 'x' . intval($p_h) . '.jpg', 'placeholder', null, true, true);
         $item->full_source = JHtml::_('image', 'com_pfdesigns/full-missing.jpg', 'placeholder', null, true, true);
         $item->cover_source = JHtml::_('image', 'com_pfdesigns/cover-missing-' . intval($p_w) . 'x' . intval($p_h) . '.jpg', 'placeholder', null, true, true);
     }
 }
コード例 #4
0
ファイル: revision.php プロジェクト: MrJookie/pm
 public function import($data)
 {
     $project = (int) $data['project_id'];
     if (!$project) {
         $this->setError(JText::_('COM_PROJECTFORK_DESIGNS_ERROR_IMPORT_NO_PROJECT'));
         return false;
     }
     $base_path = PFdesignsHelper::getBasePath($project);
     $source_path = $base_path . '/' . $data['source'] . '/' . $data['file_name'];
     if (!JFile::exists($source_path)) {
         $this->setError(JText::_('COM_PROJECTFORK_ERROR_IMAGE_NOT_FOUND'));
         return false;
     }
     $file_name = $this->generateNewFileName($base_path, $data['file_name']);
     if (!JFile::copy($source_path, $base_path . '/' . $file_name)) {
         $this->setError(JText::_('COM_PROJECTFORK_ERROR_IMPORT_COPY_FAILED'));
         return false;
     }
     $this->setState($this->getName() . '.id', 0);
     $item = array();
     $item['id'] = 0;
     $item['project_id'] = (int) $data['project_id'];
     $item['parent_id'] = (int) $data['parent_id'];
     $item['title'] = $data['title'];
     $data['rules'] = null;
     $item['file'] = array();
     $item['file']['name'] = $file_name;
     $item['file']['size'] = filesize($base_path . '/' . $file_name);
     $item['file']['extension'] = strtolower(JFile::getExt($file_name));
     if (!$this->save($item)) {
         JFile::delete($source_path, $base_path . '/' . $file_name);
         return false;
     }
     if (!JFile::delete($source_path)) {
         $this->setError(JText::_('COM_PROJECTFORK_ERROR_IMPORT_DELETE_FAILED'));
         $cid = array($this->getState($this->getName() . '.id'));
         $this->delete($cid);
         return false;
     }
     return true;
 }
コード例 #5
0
ファイル: view.raw.php プロジェクト: MrJookie/pm
 /**
  * Display the view
  *
  * @return    void
  */
 public function display($tpl = null)
 {
     $item = $this->get('Item');
     $params = JComponentHelper::getParams('com_pfdesigns', true);
     $layout = JRequest::getCmd('layout', 'preview');
     // Permission check.
     if ($item->params->get('access-view') !== true) {
         JError::raiseError(403, JText::_('JERROR_ALERTNOAUTHOR'));
         return false;
     }
     if ($layout == 'download' || $layout == 'downloadAll') {
         if (headers_sent($file, $line)) {
             JError::raiseError(500, JText::sprintf('COM_PROJECTFORK_WARNING_FILE_DL_ERROR_HEADERS_SENT', $file, $line));
             return false;
         }
         // Download permission check.
         $access = PFdesignsHelper::getActions($item->id);
         if (($access->get('core.admin') || $access->get('core.download')) !== true) {
             JError::raiseError(403, JText::_('JERROR_ALERTNOAUTHOR'));
             return false;
         }
         // Download a file
         if ($layout == 'download') {
             $base_path = PFdesignsHelper::getBasePath($item->project_id);
             if ($item->revision) {
                 $file_path = $base_path . '/' . $item->revision->file_name;
                 $name = $item->revision->alias . '.' . $item->revision->file_extension;
             } else {
                 $file_path = $base_path . '/' . $item->file_name;
                 $name = $item->alias . '.' . $item->file_extension;
             }
             if (!JFile::exists($file_path)) {
                 JError::raiseError(404, JText::_('COM_PROJECTFORK_ERROR_FILE_NOT_FOUND'));
                 return false;
             }
             ob_end_clean();
             header("Content-Type: APPLICATION/OCTET-STREAM");
             header("Content-Length: " . filesize($file_path));
             header("Content-Disposition: attachment; filename=\"" . $name . "\";");
             header("Content-Transfer-Encoding: Binary");
             if (function_exists('readfile')) {
                 readfile($file_path);
             } else {
                 echo file_get_contents($file_path);
             }
         } else {
             // Download including revisions
             if (!class_exists('ZipArchive')) {
                 JError::raiseError(500, JText::_('COM_PROJECTFORK_DESIGNS_ERROR_ZIP_EXTENSION'));
                 return false;
             }
             // Get all revisions
             $revs_model = JModelLegacy::getInstance('Revisions', 'PFdesignsModel');
             $revisions = (array) $revs_model->getItems();
             // Collect files
             $base_path = PFdesignsHelper::getBasePath($item->project_id);
             $files = array();
             // Add the design itself to the list
             $file_path = $base_path . '/' . $item->file_name;
             if (JFile::exists($file_path)) {
                 $files[$file_path] = '0-' . $item->alias . '.' . $item->file_extension;
             }
             foreach ($revisions as $rev) {
                 // Download permission check.
                 $access = PFdesignsHelper::getRevisionActions($rev->id);
                 if (($access->get('core.admin') || $access->get('core.download')) !== true) {
                     continue;
                 }
                 $file_path = $base_path . '/' . $rev->file_name;
                 if (JFile::exists($file_path)) {
                     $files[$file_path] = $rev->ordering . '-' . $rev->alias . '.' . $rev->file_extension;
                 }
             }
             // Make sure we have files
             if (!count($files)) {
                 JError::raiseError(404, JText::_('COM_PROJECTFORK_ERROR_FILE_NOT_FOUND'));
                 return false;
             }
             // Delete old archive if exists
             $archive = $base_path . '/' . $item->alias . '.zip';
             if (JFile::exists($archive)) {
                 if (!JFile::delete($archive)) {
                     JError::raiseError(500, JText::_('COM_PROJECTFORK_DESIGNS_ERROR_ZIP_DELETE_FAILED'));
                     return false;
                 }
             }
             // Create new archive
             $zip = new ZipArchive();
             $zip_class = true;
             if (!$zip->open($archive, ZIPARCHIVE::CREATE)) {
                 JError::raiseError(500, JText::_('COM_PROJECTFORK_DESIGNS_ERROR_ZIP_CREATE_FAILED'));
                 return false;
             }
             // Add files to archive
             foreach ($files as $path => $name) {
                 $zip->addFile($path, $name);
             }
             // Close archive
             $zip->close();
             if (JFile::exists($archive)) {
                 ob_end_clean();
                 header("Content-Type: APPLICATION/OCTET-STREAM");
                 header("Content-Length: " . filesize($archive));
                 header("Content-Disposition: attachment; filename=\"" . $item->alias . '.zip' . "\";");
                 header("Content-Transfer-Encoding: Binary");
                 if (function_exists('readfile')) {
                     readfile($archive);
                 } else {
                     echo file_get_contents($archive);
                 }
             } else {
                 JError::raiseError(500, JText::_('COM_PROJECTFORK_DESIGNS_ERROR_ZIP_STORE_FAILED'));
                 return false;
             }
         }
     } else {
         // Generate thumbnail
         $options = array();
         switch ($layout) {
             case 'full':
                 $options['crop'] = false;
                 $options['quality'] = 90;
                 $options['size'] = $params->get('img_full_size', '1280x720');
                 break;
             case 'cover':
                 $options['crop'] = true;
                 $options['quality'] = 75;
                 $options['size'] = $params->get('img_cover_size', '1280x720');
                 break;
             case 'preview':
             default:
                 $options['crop'] = true;
                 $options['quality'] = 75;
                 $options['size'] = $params->get('img_preview_size', '300x200');
                 break;
         }
         $source = PFdesignsHelper::getBasePath($item->project_id) . '/' . $item->file_name;
         $image = JModelLegacy::getInstance('Image', 'PFdesignsModel', $options);
         $image->setSource($source);
         $image->setCacheId('design', $item->project_id, $item->id);
         $image->setAuthor($item->author_name);
         $image->save();
         if ($image->isCached()) {
             JFactory::getApplication()->redirect($image->getCachedURL());
         } else {
             $buffer = $image->getBuffer();
             if ($buffer) {
                 ob_end_clean();
                 header("Content-Type: image/jpeg");
                 header("Accept-Ranges: bytes");
                 header("Content-Length: " . filesize($image->getCachedFilePath()));
                 echo $buffer;
             }
         }
     }
     die;
 }
コード例 #6
0
ファイル: default.php プロジェクト: MrJookie/pm
/**
 * @package      Projectfork Pro
 * @subpackage   Designs
 *
 * @author       Tobias Kuhn (eaxs)
 * @copyright    Copyright (C) 2006-2013 Tobias Kuhn. All rights reserved.
 * @license      http://www.gnu.org/licenses/gpl.html GNU/GPL, see LICENSE.txt
 */
defined('_JEXEC') or die;
JHtml::_('behavior.tooltip');
JHtml::_('behavior.multiselect');
$user = JFactory::getUser();
$uid = $user->get('id');
$is_j25 = version_compare(JVERSION, '3', 'lt');
$path = PFdesignsHelper::getBasePath($this->state->get('filter.project'));
$path = str_replace(JPATH_ROOT, '', $path);
if (!$is_j25) {
    JHtml::_('dropdown.init');
    JHtml::_('formbehavior.chosen', 'select');
}
?>
<form action="<?php 
echo JRoute::_('index.php?option=com_pfdesigns&view=import');
?>
" method="post" name="adminForm" id="adminForm">
    <?php 
if (!$is_j25) {
    ?>
        <?php 
    if (!empty($this->sidebar)) {