Example #1
0
 /**
  * Displays the view.
  *
  */
 public function display($tpl = null)
 {
     // Get data from model
     $this->items = $this->get('Items');
     $this->state = $this->get('State');
     $this->albums = $this->get('Albums');
     $this->designs = $this->get('Designs');
     if (PFApplicationHelper::getActiveProjectId() <= 0) {
         $text = JText::_('COM_PROJECTFORK_DESIGNS_WARNING_IMPORT_SELECT_PROJECT');
         JFactory::getApplication()->enqueueMessage($text);
     }
     // Check for errors
     if (count($errors = $this->get('Errors'))) {
         JError::raiseError(500, implode("\n", $errors));
         return false;
     }
     if ($this->getLayout() !== 'modal') {
         $this->addToolbar();
         if (version_compare(JVERSION, '3', 'ge')) {
             PFdesignsHelper::addSubmenu('import');
             $this->sidebar = JHtmlSidebar::render();
         }
     }
     parent::display($tpl);
 }
Example #2
0
 /**
  * Adds the page title and toolbar.
  *
  */
 protected function addToolbar()
 {
     JRequest::setVar('hidemainmenu', true);
     $id = $this->item->id;
     $uid = JFactory::getUser()->get('id');
     $access = PFdesignsHelper::getActions($id);
     $checked_out = !($this->item->checked_out == 0 || $this->item->checked_out == $uid);
     $is_new = (int) $this->item->id == 0;
     JToolBarHelper::title(JText::_('COM_PROJECTFORK_PAGE_' . ($checked_out ? 'VIEW_DESIGN_REVISION' : ($is_new ? 'ADD_DESIGN_REVISION' : 'EDIT_DESIGN_REVISION'))), 'article-add.png');
     // Build the actions for new and existing records
     // For new records, check the create permission.
     if ($is_new) {
         JToolBarHelper::apply('revision.apply');
         JToolBarHelper::save('revision.save');
         JToolBarHelper::save2new('revision.save2new');
         JToolBarHelper::cancel('revision.cancel');
     } else {
         // Can't save the record if it's checked out.
         if (!$checked_out) {
             if ($access->get('core.edit') || $access->get('core.edit.own') && $this->item->created_by == $uid) {
                 JToolBarHelper::apply('revision.apply');
                 JToolBarHelper::save('revision.save');
                 JToolBarHelper::save2new('revision.save2new');
             }
         }
         JToolBarHelper::cancel('revision.cancel', 'JTOOLBAR_CLOSE');
     }
 }
Example #3
0
 public function display($cachable = false, $urlparams = false)
 {
     if (version_compare(JVERSION, '3', 'lt')) {
         PFdesignsHelper::addSubmenu(JFactory::getApplication()->input->get('view', $this->default_view));
     }
     parent::display();
     return $this;
 }
Example #4
0
 /**
  * Method to get item data.
  *
  * @param     integer    $id    The id of the item.
  * @return    mixed             Item data object on success, false on failure.
  */
 public function getItem($id = null)
 {
     // Initialise variables.
     $id = (int) (!empty($id)) ? $id : $this->getState($this->getName() . '.id');
     // Get a row instance.
     $table = $this->getTable();
     // Attempt to load the row.
     $return = $table->load($id);
     // Check for a table object error.
     if ($return === false && $table->getError()) {
         $this->setError($table->getError());
         return false;
     }
     $properties = $table->getProperties(1);
     $value = JArrayHelper::toObject($properties, 'JObject');
     // Convert attrib field to Registry.
     $value->params = new JRegistry();
     $value->params->loadString($value->attribs);
     $value->attribs = $value->params->toArray();
     // Compute selected asset permissions.
     $uid = JFactory::getUser()->get('id');
     if ($id) {
         $access = PFdesignsHelper::getAlbumActions($value->id);
     } else {
         $access = PFdesignsHelper::getAlbumActions();
     }
     // Check general edit permission first.
     if ($access->get('core.edit')) {
         $value->params->set('access-edit', true);
     } elseif (!empty($uid) && $access->get('core.edit.own')) {
         // Now check if edit.own is available.
         // Check for a valid user and that they are the owner.
         if ($uid == $value->created_by) {
             $value->params->set('access-edit', true);
         }
     }
     // Check edit state permission.
     $value->params->set('access-change', $access->get('core.edit.state'));
     return $value;
 }
Example #5
0
 /**
  * Displays the view.
  *
  */
 public function display($tpl = null)
 {
     // Get data from model
     $this->items = $this->get('Items');
     $this->pagination = $this->get('Pagination');
     $this->state = $this->get('State');
     $this->authors = $this->get('Authors');
     $this->nulldate = JFactory::getDbo()->getNullDate();
     // Check for errors
     if (count($errors = $this->get('Errors'))) {
         JError::raiseError(500, implode("\n", $errors));
         return false;
     }
     if ($this->getLayout() !== 'modal') {
         $this->addToolbar();
         if (version_compare(JVERSION, '3', 'ge')) {
             PFdesignsHelper::addSubmenu('albums');
             $this->sidebar = JHtmlSidebar::render();
         }
     }
     parent::display($tpl);
 }
Example #6
0
 /**
  * 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;
 }
Example #7
0
 public function display($tpl = null)
 {
     // Initialise variables.
     $app = JFactory::getApplication();
     $user = JFactory::getUser();
     // Get model data.
     $this->state = $this->get('State');
     $this->item = $this->get('Item');
     $this->form = $this->get('Form');
     $this->return_page = $this->get('ReturnPage');
     $this->toolbar = $this->getToolbar();
     // Permission check.
     if ($this->item->id <= 0) {
         $access = PFdesignsHelper::getAlbumActions();
         $authorised = $access->get('core.create');
     } else {
         $authorised = $this->item->params->get('access-edit');
     }
     if ($authorised !== true) {
         JError::raiseError(403, JText::_('JERROR_ALERTNOAUTHOR'));
         return false;
     }
     // Check for errors.
     if (count($errors = $this->get('Errors'))) {
         JError::raiseWarning(500, implode("\n", $errors));
         return false;
     }
     //Escape strings for HTML output
     $this->pageclass_sfx = htmlspecialchars($this->state->params->get('pageclass_sfx'));
     $this->params = $this->state->params;
     $this->user = $user;
     // Prepare the document
     $this->_prepareDocument();
     // Display the view
     parent::display($tpl);
 }
Example #8
0
    ?>
                    </th>
                <?php 
}
?>
                <th width="1%" class="nowrap hidden-phone">
                    <?php 
echo JHtml::_('grid.sort', 'JGRID_HEADING_ID', 'a.id', $list_dir, $list_order);
?>
                </th>
            </tr>
        </thead>
        <tbody>
        <?php 
foreach ($this->items as $i => $item) {
    $access = PFdesignsHelper::getActions($item->id);
    $ordering = $list_order == 'a.ordering';
    $can_create = $access->get('core.create');
    $can_edit = $access->get('core.edit');
    $can_checkin = $user->authorise('core.manage', 'com_checkin') || $item->checked_out == $uid || $item->checked_out == 0;
    $can_edit_own = $access->get('core.edit.own') && $item->created_by == $uid;
    $can_change = $access->get('core.edit.state') && $can_checkin;
    // Prepare re-order conditions
    $order_up = false;
    $order_down = false;
    $prev_item = null;
    $next_item = null;
    $prev_i = $i - 1;
    $next_i = $i + 1;
    if (array_key_exists($prev_i, $this->items)) {
        $prev_item = $this->items[$prev_i];
Example #9
0
 /**
  * Method override to check if you can edit an existing record.
  *
  * @param     array      $data    An array of input data.
  * @param     string     $key     The name of the key for the primary key.
  *
  * @return    boolean
  */
 protected function allowEdit($data = array(), $key = 'id')
 {
     // Initialise variables.
     $id = (int) isset($data[$key]) ? $data[$key] : 0;
     $uid = JFactory::getUser()->get('id');
     $access = PFdesignsHelper::getActions($id);
     // Check general edit permission first.
     if ($access->get('core.edit')) {
         return true;
     }
     // Fallback on edit.own.
     // First test if the permission is available.
     if ($access->get('core.edit.own')) {
         // Now test the owner is the user.
         $owner = (int) isset($data['created_by']) ? $data['created_by'] : 0;
         if (empty($owner) && $id) {
             // Need to do a lookup from the model.
             $record = $this->getModel()->getItem($id);
             if (empty($record)) {
                 return false;
             }
             $owner = $record->created_by;
         }
         // If the owner matches 'me' then do the test.
         if ($owner == $uid) {
             return true;
         }
     }
     // Since there is no asset tracking, revert to the component permissions.
     return parent::allowEdit($data, $key);
 }
Example #10
0
 /**
  * Generates the toolbar for the top of the view
  *
  * @return    string    Toolbar with buttons
  */
 protected function getToolbar()
 {
     $access = PFdesignsHelper::getAlbumActions();
     $state = $this->get('State');
     PFToolbar::button('COM_PROJECTFORK_ACTION_NEW', 'albumform.add', false, array('access' => $access->get('core.create')));
     $options = array();
     if ($access->get('core.edit.state')) {
         $options[] = array('text' => 'COM_PROJECTFORK_ACTION_PUBLISH', 'task' => $this->getName() . '.publish');
         $options[] = array('text' => 'COM_PROJECTFORK_ACTION_UNPUBLISH', 'task' => $this->getName() . '.unpublish');
         $options[] = array('text' => 'COM_PROJECTFORK_ACTION_ARCHIVE', 'task' => $this->getName() . '.archive');
         $options[] = array('text' => 'COM_PROJECTFORK_ACTION_CHECKIN', 'task' => $this->getName() . '.checkin');
     }
     if ($state->get('filter.published') == -2 && $access->get('core.delete')) {
         $options[] = array('text' => 'COM_PROJECTFORK_ACTION_DELETE', 'task' => $this->getName() . '.delete');
     } elseif ($access->get('core.edit.state')) {
         $options[] = array('text' => 'COM_PROJECTFORK_ACTION_TRASH', 'task' => $this->getName() . '.trash');
     }
     if (count($options)) {
         PFToolbar::listButton($options);
     }
     PFToolbar::filterButton($this->state->get('filter.isset'));
     return PFToolbar::render();
 }
Example #11
0
 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;
 }
Example #12
0
 protected function getRevisionsToolbar()
 {
     $access = PFdesignsHelper::getActions($this->item->id);
     $options = array();
     if ($access->get('core.edit.state')) {
         $options[] = array('text' => 'COM_PROJECTFORK_ACTION_PUBLISH', 'task' => 'revisions.publish');
         $options[] = array('text' => 'COM_PROJECTFORK_ACTION_UNPUBLISH', 'task' => 'revisions.unpublish');
         $options[] = array('text' => 'COM_PROJECTFORK_ACTION_ARCHIVE', 'task' => 'revisions.archive');
         $options[] = array('text' => 'COM_PROJECTFORK_ACTION_CHECKIN', 'task' => 'revisions.checkin');
     }
     if ($this->state->get('filter.published') == -2 && $access->get('core.delete')) {
         $options[] = array('text' => 'COM_PROJECTFORK_ACTION_DELETE', 'task' => 'revisions.delete');
     } elseif ($access->get('core.edit.state')) {
         $options[] = array('text' => 'COM_PROJECTFORK_ACTION_TRASH', 'task' => 'revisions.trash');
     }
     PFToolbar::clear();
     if (count($options)) {
         PFToolbar::listButton($options);
     }
     PFToolbar::filterButton($this->model_revisions->getState('filter.isset'));
     return PFToolbar::render();
 }
Example #13
0
 /**
  * Method to check if you can add a new record.
  *
  * @param     array      $data    An array of input data.
  *
  * @return    boolean
  */
 protected function allowAdd($data = array())
 {
     $parent = isset($data['parent_id']) ? (int) $data['parent_id'] : JRequest::getUInt('filter_parent_id');
     $access = PFdesignsHelper::getActions($parent);
     if (!$parent) {
         $this->setError(JText::_('COM_PROJECTFORK_WARNING_DESIGN_NOT_FOUND'));
         return false;
     }
     return $access->get('core.create');
 }
Example #14
0
 /**
  * Method to check for upload errors
  *
  * @param     array      $files    The files to check
  *
  * @return    boolean              True if no error
  */
 protected function checkFileError(&$files, $record_id = 0)
 {
     foreach ($files as &$file) {
         // Uploading a file is not required when updating an existing record
         if ($file['error'] == 4 && $record_id > 0) {
             $file['error'] = 0;
         }
         if ($file['error']) {
             $error = PFdesignsHelper::getFileErrorMsg($file['error'], $file['name']);
             $this->setError($error);
             $this->setMessage($error, 'error');
             return false;
         }
     }
     return true;
 }
Example #15
0
 /**
  * Method to auto-populate the model state.
  * Note. Calling getState in this method will result in recursion.
  *
  * @return    void
  */
 protected function populateState($ordering = 'a.ordering', $direction = 'ASC')
 {
     $app = JFactory::getApplication();
     // Adjust the context to support modal layouts.
     $layout = JRequest::getCmd('layout');
     // View Layout
     $this->setState('layout', $layout);
     if ($layout) {
         $this->context .= '.' . $layout;
     }
     // Params
     $value = $app->getParams();
     $this->setState('params', $value);
     // State
     $state = $app->getUserStateFromRequest($this->context . '.filter.published', 'filter_published', '');
     $this->setState('filter.published', $state);
     // Filter on published for those who do not have edit or edit.state rights.
     $access = PFdesignsHelper::getAlbumActions();
     if (!$access->get('core.edit.state') && !$access->get('core.edit')) {
         $this->setState('filter.published', 1);
         $state = '';
     }
     // Filter - Search
     $search = JRequest::getString('filter_search', '');
     $this->setState('filter.search', $search);
     // Filter - Project
     $project = PFApplicationHelper::getActiveProjectId('filter_project');
     $this->setState('filter.project', $project);
     // Filter - Author
     $author = $app->getUserStateFromRequest($this->context . '.filter.author', 'filter_author', '');
     $this->setState('filter.author', $author);
     // Do not allow some filters if no project is selected
     if (!is_numeric($project) || intval($project) == 0) {
         $this->setState('filter.author', '');
         $author = '';
     }
     // Filter - Is set
     $this->setState('filter.isset', is_numeric($state) || !empty($search) || is_numeric($author));
     // Call parent method
     parent::populateState($ordering, $direction);
 }
Example #16
0
 /**
  * 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;
 }
Example #17
0
 /**
  * Method to auto-populate the model state.
  * Note. Calling getState in this method will result in recursion.
  *
  * @return    void
  */
 protected function populateState()
 {
     // Load state from the request.
     $pk = JRequest::getUInt('id');
     $this->setState($this->getName() . '.id', $pk);
     $offset = JRequest::getUInt('limitstart');
     $this->setState('list.offset', $offset);
     // Load the parameters.
     $params = JFactory::getApplication('site')->getParams();
     $this->setState('params', $params);
     $access = PFdesignsHelper::getRevisionActions($pk);
     if (!$access->get('core.edit.state') && !$access->get('core.edit')) {
         $this->setState('filter.published', 1);
         $this->setState('filter.archived', 2);
     }
 }
Example #18
0
/**
 * @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)) {
Example #19
0
 /**
  * Method to get a list of items.
  * Overriden to inject convert the attribs field into a JParameter object.
  *
  * @return    mixed    $items    An array of objects on success, false on failure.
  */
 public function getItems()
 {
     // Get the list of revisions
     $items = parent::getItems();
     // Iterate through each revision to add some additional stuff
     foreach ($items as $i => &$item) {
         $params = new JRegistry();
         $params->loadString($item->attribs);
         // Convert the parameter fields into objects.
         $items[$i]->params = clone $this->getState('params');
         // Create slugs
         $item->slug = $item->alias ? $item->id . ':' . $item->alias : $item->id;
         $item->project_slug = $item->project_alias ? $item->project_id . ':' . $item->project_alias : $item->project_id;
         // Get the thumbnails
         PFdesignsHelper::getThumbnails($item, 'revision');
     }
     return $items;
 }
Example #20
0
 /**
  * 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);
     }
 }
Example #21
0
 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;
 }