コード例 #1
0
ファイル: view.html.php プロジェクト: MrJookie/pm
 /**
  * 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');
     }
 }
コード例 #2
0
ファイル: view.html.php プロジェクト: MrJookie/pm
 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::getActions();
         $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);
 }
コード例 #3
0
ファイル: designform.json.php プロジェクト: MrJookie/pm
 /**
  * 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);
 }
コード例 #4
0
ファイル: albums.php プロジェクト: MrJookie/pm
 /**
  * Build a list of item authors
  *
  * @return    jdatabasequery
  */
 public function getAuthors()
 {
     // Return empty array if no project is select
     $project = (int) $this->getState('filter.project');
     if ($project <= 0) {
         return array();
     }
     $db = $this->getDbo();
     $query = $db->getQuery(true);
     $user = JFactory::getUser();
     $access = PFdesignsHelper::getActions();
     // Construct the query
     $query->select('u.id AS value, u.name AS text')->from('#__users AS u')->join('INNER', '#__pf_design_albums AS a ON a.created_by = u.id');
     // Implement View Level Access
     if (!$user->authorise('core.admin', 'com_pfdesigns')) {
         $levels = implode(',', $user->getAuthorisedViewLevels());
         $query->where('a.access IN (' . $levels . ')');
     }
     // Filter fields
     $filters = array();
     $filters['a.project_id'] = array('INT-NOTZERO', $this->getState('filter.project'));
     if (!$access->get('core.edit.state') && !$access->get('core.edit')) {
         $filters['a.state'] = array('STATE', '1');
     }
     // Apply Filter
     PFQueryHelper::buildFilter($query, $filters);
     // Group and order
     $query->group('u.id');
     $query->order('u.name ASC');
     // Return the result
     $db->setQuery((string) $query);
     return (array) $db->loadObjectList();
 }
コード例 #5
0
ファイル: default.php プロジェクト: MrJookie/pm
    ?>
                    </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];
コード例 #6
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;
 }
コード例 #7
0
ファイル: revision.php プロジェクト: MrJookie/pm
 /**
  * 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');
 }
コード例 #8
0
ファイル: view.html.php プロジェクト: MrJookie/pm
 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();
 }
コード例 #9
0
ファイル: view.html.php プロジェクト: MrJookie/pm
 /**
  * Generates the toolbar for the top of the view
  *
  * @return    string    Toolbar with buttons
  */
 protected function getToolbar()
 {
     $access = PFdesignsHelper::getActions();
     $state = $this->get('State');
     PFToolbar::button('COM_PROJECTFORK_ACTION_NEW', 'designform.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();
 }
コード例 #10
0
ファイル: design.php プロジェクト: MrJookie/pm
 /**
  * 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::getInt('id');
     $this->setState($this->getName() . '.id', $pk);
     $offset = JRequest::getUInt('limitstart');
     $this->setState('list.offset', $offset);
     $revision = JRequest::getUInt('revision');
     $this->setState($this->getName() . '.revision', $revision);
     // Load the parameters.
     $params = JFactory::getApplication('site')->getParams();
     $this->setState('params', $params);
     $access = PFdesignsHelper::getActions();
     if (!$access->get('core.edit.state') && !$access->get('core.edit')) {
         $this->setState('filter.published', 1);
         $this->setState('filter.archived', 2);
     }
 }
コード例 #11
0
ファイル: designs.php プロジェクト: MrJookie/pm
 /**
  * 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::getActions();
     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);
     // Filter - Category
     $album = $app->getUserStateFromRequest($this->context . '.filter.album', 'filter_album', '');
     $this->setState('filter.album', $album);
     // Filter - Labels
     $labels = JRequest::getVar('filter_label', array());
     $this->setState('filter.labels', $labels);
     // Do not allow some filters if no project is selected
     if (!is_numeric($project) || intval($project) == 0) {
         $this->setState('filter.author', '');
         $this->setState('filter.album', '');
         $this->setState('filter.labels', array());
         $author = '';
         $album = '';
         $labels = array();
     }
     if (!is_array($labels)) {
         $labels = array();
     }
     // Filter - Is set
     $this->setState('filter.isset', is_numeric($state) || !empty($search) || is_numeric($author) || is_numeric($album) && $album > 0 || count($labels));
     // Call parent method
     parent::populateState($ordering, $direction);
 }