/**
  * Method to get item data.
  *
  * @param     integer    $pk       The id of the item.
  *
  * @return    mixed      $item    Item data object on success, false on failure.
  */
 public function getItem($pk = null)
 {
     // Get the record from the parent class method
     $item = parent::getItem($pk);
     if ($item === false) {
         return false;
     }
     // Compute selected asset permissions.
     $user = JFactory::getUser();
     $uid = $user->get('id');
     $access = PFrepoHelper::getActions('note', $item->id);
     $view_access = true;
     if ($item->access && !$user->authorise('core.admin')) {
         $view_access = in_array($item->access, $user->getAuthorisedViewLevels());
     }
     $item->params->set('access-view', $view_access);
     if (!$view_access) {
         $item->params->set('access-edit', false);
         $item->params->set('access-change', false);
     } else {
         // Check general edit permission first.
         if ($access->get('core.edit')) {
             $item->params->set('access-edit', true);
         } elseif (!empty($uid) && $access->get('core.edit.own')) {
             // Check for a valid user and that they are the owner.
             if ($uid == $item->created_by) {
                 $item->params->set('access-edit', true);
             }
         }
         // Check edit state permission.
         $item->params->set('access-change', $access->get('core.edit.state'));
     }
     return $item;
 }
Example #2
0
 /**
  * Add the page title and toolbar.
  *
  */
 protected function addToolbar()
 {
     JRequest::setVar('hidemainmenu', true);
     $uid = JFactory::getUser()->get('id');
     $is_new = $this->item->id == 0;
     $checked_out = !($this->item->checked_out == 0 || $this->item->checked_out == $uid);
     $access = PFrepoHelper::getActions('directory', $this->item->id);
     JToolBarHelper::title(JText::_('COM_PROJECTFORK_PAGE_' . ($checked_out ? 'VIEW_DIRECTORY' : ($is_new ? 'ADD_DIRECTORY' : 'EDIT_DIRECTORY'))), 'article-add.png');
     // Built the actions for new and existing records.
     // For new records, check the create permission.
     if ($is_new) {
         JToolBarHelper::apply('directory.apply');
         JToolBarHelper::save('directory.save');
         JToolBarHelper::save2new('directory.save2new');
         JToolBarHelper::cancel('directory.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('directory.apply');
                 JToolBarHelper::save('directory.save');
                 JToolBarHelper::save2new('directory.save2new');
             }
         }
         // JToolBarHelper::save2copy('directory.save2copy');
         JToolBarHelper::cancel('directory.cancel', 'JTOOLBAR_CLOSE');
     }
 }
 function display($tpl = null)
 {
     $user = JFactory::getUser();
     $this->item = $this->get('Item');
     $this->state = $this->get('State');
     // Check for errors.
     if (count($errors = $this->get('Errors'))) {
         JError::raiseError(500, implode("\n", $errors));
         return false;
     }
     // Check access
     if ($this->item->params->get('access-view') != true) {
         JError::raiseWarning(403, JText::_('JERROR_ALERTNOAUTHOR'));
         return false;
     }
     $rev = JRequest::getUInt('rev');
     if ($rev) {
         $rev_model = JModelLegacy::getInstance('FileRevision', 'PFrepoModel', $c = array('ignore_request' => true));
         $file_rev = $rev_model->getItem($rev);
         if (!$file_rev || empty($file_rev->id)) {
             JError::raiseError(404, JText::_('COM_PROJECTFORK_ERROR_FILE_NOT_FOUND'));
             return false;
         }
         // Check access
         if ($file_rev->parent_id != $this->item->id) {
             JError::raiseWarning(403, JText::_('JERROR_ALERTNOAUTHOR'));
             return false;
         }
         $filepath = PFrepoHelper::getBasePath($this->item->project_id) . '/_revs/file_' . $this->item->id;
         $filename = $file_rev->file_name;
     } else {
         $filepath = $this->item->physical_path;
         $filename = $this->item->file_name;
     }
     // Check if the file exists
     if (empty($filepath) || !JFile::exists($filepath . '/' . $filename)) {
         JError::raiseError(404, JText::_('COM_PROJECTFORK_ERROR_FILE_NOT_FOUND'));
         return false;
     }
     if (headers_sent($file, $line)) {
         JError::raiseError(500, JText::sprintf('COM_PROJECTFORK_WARNING_FILE_DL_ERROR_HEADERS_SENT', $file, $line));
         return false;
     }
     while (ob_get_level()) {
         ob_end_clean();
     }
     header("Content-Type: APPLICATION/OCTET-STREAM");
     header("Content-Length: " . filesize($filepath . '/' . $filename));
     header("Content-Disposition: attachment; filename=\"" . $filename . "\";");
     header("Content-Transfer-Encoding: Binary");
     if (function_exists('readfile')) {
         readfile($filepath . '/' . $filename);
     } else {
         echo file_get_contents($filepath . '/' . $filename);
     }
     jexit();
 }
 /**
  * Method to display a view.
  *
  * @param     boolean        If true, the view output will be cached
  * @param     array          An array of safe url parameters
  *
  * @return    jcontroller    This object to support chaining.
  */
 public function display($cachable = false, $urlparams = false)
 {
     $view = JRequest::getCmd('view', $this->default_view);
     $layout = JRequest::getCmd('layout');
     $id = JRequest::getUint('id');
     // Inject default view if not set
     if (empty($view)) {
         JRequest::setVar('view', $this->default_view);
         $view = $this->default_view;
     }
     if ($view == $this->default_view) {
         $parent_id = JRequest::getUInt('filter_parent_id');
         $project = PFApplicationHelper::getActiveProjectId('filter_project');
         if ($parent_id && $project === "") {
             $this->setRedirect('index.php?option=com_pfrepo&view=' . $this->default_view);
             return $this;
         } elseif ($parent_id > 1 && $project > 0) {
             // Check if the folder belongs to the project
             $db = JFactory::getDbo();
             $query = $db->getQuery(true);
             $query->select('project_id')->from('#__pf_repo_dirs')->where('id = ' . (int) $parent_id);
             $db->setQuery($query);
             $pid = $db->loadResult();
             if ($pid != $project) {
                 // No match, redirect to the project root dir
                 $query->clear();
                 $query->select('id, path')->from('#__pf_repo_dirs')->where('parent_id = 1')->where('project_id = ' . (int) $project);
                 $db->setQuery($query, 0, 1);
                 $dir = $db->loadObject();
                 if ($dir) {
                     $this->setRedirect('index.php?option=com_pfrepo&view=' . $this->default_view . '&filter_project=' . $project . '&filter_parent_id=' . $dir->id);
                     return $this;
                 }
             }
         }
     }
     // Check form edit access
     if ($layout == 'edit' && !$this->checkEditId('com_pfrepo.edit.' . $view, $id)) {
         $this->setError(JText::sprintf('JLIB_APPLICATION_ERROR_UNHELD_ID', $id));
         $this->setMessage($this->getError(), 'error');
         $this->setRedirect(JRoute::_('index.php?option=com_pfrepo&view=' . $this->default_view, false));
         return false;
     }
     // Add the sub-menu
     PFrepoHelper::addSubmenu($view);
     // Display the view
     parent::display($cachable, $urlparams);
     return $this;
 }
Example #5
0
 public function saveAvatar($pk, $file)
 {
     if (!PFImage::isValid($file['name'], $file['tmp_name'])) {
         $this->setError(JText::_('COM_PROJECTFORK_WARNING_NOT_AN_IMAGE'));
         return false;
     }
     // Delete any previous avatar
     if (!$this->deleteAvatar($pk)) {
         return false;
     }
     if ($file['error']) {
         $error = PFrepoHelper::getFileErrorMsg($file['error'], $file['name']);
         $this->setError($error);
         return false;
     }
     $uploadpath = JPATH_ROOT . '/media/com_projectfork/repo/0/avatar';
     $name = $pk . '.' . strtolower(JFile::getExt($file['name']));
     if (JFile::upload($file['tmp_name'], $uploadpath . '/' . $name) === true) {
         return true;
     }
     return false;
 }
 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();
     // Check for errors.
     if (count($errors = $this->get('Errors'))) {
         JError::raiseWarning(500, implode("\n", $errors));
         return false;
     }
     // Permission check.
     if (empty($this->item->id)) {
         $access = PFrepoHelper::getActions('directory');
         $authorised = $access->get('core.create');
     } else {
         $authorised = $this->item->params->get('access-edit');
     }
     if ($authorised !== true) {
         JError::raiseError(403, JText::_('JERROR_ALERTNOAUTHOR'));
         return false;
     }
     // Create a shortcut to the parameters.
     $params =& $this->state->params;
     //Escape strings for HTML output
     $this->pageclass_sfx = htmlspecialchars($params->get('pageclass_sfx'));
     $this->params = $params;
     $this->user = $user;
     // Prepare the document
     $this->_prepareDocument();
     // Display the view
     parent::display($tpl);
 }
Example #7
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())
 {
     $user = JFactory::getUser();
     $dir_id = (int) JRequest::getUInt('filter_parent_id', 0);
     $access = true;
     if (isset($data['dir_id'])) {
         $dir_id = (int) $data['dir_id'];
     }
     // Verify directory access
     if ($dir_id) {
         $model = $this->getModel('Directory', 'PFrepoModel');
         $item = $model->getItem($dir_id);
         if (!empty($item)) {
             $access = PFrepoHelper::getActions('directory', $item->id);
             if (!$user->authorise('core.admin')) {
                 if (!in_array($item->access, $user->getAuthorisedViewLevels())) {
                     $this->setError(JText::_('COM_PROJECTFORK_WARNING_DIRECTORY_ACCESS_DENIED'));
                     $access = false;
                 } elseif (!$access->get('core.create')) {
                     $this->setError(JText::_('COM_PROJECTFORK_WARNING_DIRECTORY_CREATE_NOTE_DENIED'));
                     $access = false;
                 }
             }
         } else {
             $this->setError(JText::_('COM_PROJECTFORK_WARNING_DIRECTORY_NOT_FOUND'));
             $access = false;
         }
     } else {
         $access = PFrepoHelper::getActions();
         if (!$access->get('core.create')) {
             $this->setError(JText::_('COM_PROJECTFORK_WARNING_CREATE_NOTE_DENIED'));
             $access = false;
         }
     }
     return $access && $dir_id > 0;
 }
 /**
  * Method to get the pyhsical path location of a file
  *
  * @param     string     $name    The file name
  * @param     integer    $dir     The directory id in which the file is stored
  *
  * @return    string              The path
  */
 public static function getFilePath($name, $dir)
 {
     $db = JFactory::getDbo();
     $query = $db->getQuery(true);
     $query->select('project_id, path')->from('#__pf_repo_dirs')->where('id = ' . (int) $dir);
     $db->setQuery($query);
     $dir = $db->loadObject();
     if (empty($dir)) {
         return '';
     }
     $base = PFrepoHelper::getBasePath();
     $file = $base . '/' . $dir->path . '/' . $name;
     // Look in the directory
     if (JFile::exists($file)) {
         return $base . '/' . $dir->path;
     }
     // Look in the base dir (4.0 backwards compat)
     $file = $base . '/' . $dir->project_id . '/' . $name;
     if (JFile::exists($file)) {
         return $base . '/' . $dir->project_id;
     }
     // Look in the base dir (3.0 backwards compat)
     $file = $base . '/project_' . $dir->project_id . '/' . $name;
     if (JFile::exists($file)) {
         return $base . '/project_' . $dir->project_id;
     }
     return '';
 }
Example #9
0
 /**
  * Method to delete a file
  *
  * @param     string     $name    The file name
  * @param     integer    $dir     The dir id to which the file belongs to
  *
  * @return    boolean             True on success, otherwise False
  */
 public function deleteFile($name, $dir = 0)
 {
     $path = PFrepoHelper::getFilePath($name, $dir);
     if (empty($path)) {
         return false;
     }
     if (JFile::delete($path . '/' . $name) !== true) {
         return false;
     }
     return true;
 }
        <td colspan="5">

            <a href="<?php 
    echo JRoute::_(PFrepoHelperRoute::getRepositoryRoute($this_dir->project_id, $this_dir->parent_id, $this_dir->path));
    ?>
" class="btn btn-mini">
                <span aria-hidden="true" class="icon-arrow-left"></span> <?php 
    echo JText::_('JPREVIOUS');
    ?>
            </a>
        </td>
    </tr>
<?php 
}
foreach ($this->items['directories'] as $i => $item) {
    $access = PFrepoHelper::getActions('directory', $item->id);
    // Set folder icon
    $icon = 'icon-folder';
    if ($item->orphaned) {
        $icon = 'icon-warning';
    } elseif ($item->parent_id == 1) {
        $icon = 'icon-folder-2';
    } elseif ($item->protected) {
        $icon = 'icon-locked';
    }
    // Prepare the watch button
    $watch = '';
    if ($uid) {
        $options = array('a-class' => 'btn-mini', 'div-class' => 'pull-right');
        $watch = JHtml::_('pfhtml.button.watch', 'repository', $i, $item->watching, $options);
    }
Example #11
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())
 {
     $user = JFactory::getUser();
     $project = JArrayHelper::getValue($data, 'project_id', JRequest::getUInt('filter_project'), 'int');
     $dir_id = JArrayHelper::getValue($data, 'dir_id', JRequest::getUInt('filter_parent_id'), 'int');
     // Check general access
     if (!$user->authorise('core.create', 'com_pfrepo')) {
         $this->setError(JText::_('COM_PROJECTFORK_WARNING_CREATE_FILE_DENIED'));
         return false;
     }
     // Validate directory access
     $model = $this->getModel('Directory', 'PFrepoModel');
     $item = $model->getItem($dir_id);
     if ($item == false || empty($item->id) || $dir_id <= 1) {
         $this->setError(JText::_('COM_PROJECTFORK_WARNING_DIRECTORY_NOT_FOUND'));
         return false;
     }
     $access = PFrepoHelper::getActions('directory', $item->id);
     if (!$user->authorise('core.admin')) {
         if (!in_array($item->access, $user->getAuthorisedViewLevels())) {
             $this->setError(JText::_('COM_PROJECTFORK_WARNING_DIRECTORY_ACCESS_DENIED'));
             return false;
         } elseif (!$access->get('core.create')) {
             $this->setError(JText::_('COM_PROJECTFORK_WARNING_DIRECTORY_CREATE_FILE_DENIED'));
             return false;
         }
     }
     return true;
 }
 /**
  * Generates the toolbar for the top of the view
  *
  * @return    string    Toolbar with buttons
  */
 protected function getToolbar()
 {
     $access = PFrepoHelper::getActions('note', $this->item->id);
     $link = PFrepoHelperRoute::getRepositoryRoute($this->item->project_id, $this->item->dir_id, $this->item->path);
     $back_opts = array('access' => true, 'href' => $link);
     $edit_opts = array('access' => $access->get('core.edit'));
     PFToolbar::button('COM_PROJECTFORK_ACTION_BACK', '', false, $back_opts);
     PFToolbar::button('COM_PROJECTFORK_ACTION_EDIT', 'noteform.edit', false, $edit_opts);
     PFToolbar::filterButton($this->state->get('filter.isset'));
     return PFToolbar::render();
 }
 public function save($key = null, $urlVar = null)
 {
     $rdata = array();
     $rdata['success'] = true;
     $rdata['messages'] = array();
     $rdata['data'] = array();
     $rdata['file'] = '';
     $files_data = JRequest::getVar('qqfile', null, 'files');
     $get_data = JRequest::getVar('qqfile', null, 'get');
     $dir = JRequest::getUInt('filter_parent_id', JRequest::getUInt('dir_id'));
     $project = JRequest::getUInt('filter_project', PFApplicationHelper::getActiveProjectId());
     $method = null;
     // Determine the upload method
     if ($files_data) {
         $method = 'form';
         $file = $files_data;
     } elseif ($get_data) {
         $method = 'xhr';
         $file = array('name' => $get_data, 'tmp_name' => $get_data, 'error' => 0);
     } else {
         $rdata['success'] = false;
         $rdata['messages'][] = JText::_('COM_PROJECTFORK_WARNING_FILE_UPLOAD_ERROR_4');
         $this->sendResponse($rdata);
     }
     // Access check.
     if (!$this->allowSave($d = array()) || defined('PFDEMO')) {
         $rdata['success'] = false;
         $rdata['messages'][] = JText::_('JLIB_APPLICATION_ERROR_SAVE_NOT_PERMITTED');
         $this->sendResponse($rdata);
     }
     // Check for upload error
     if ($file['error']) {
         $error = PFrepoHelper::getFileErrorMsg($file['error'], $file['name']);
         $rdata['success'] = false;
         $rdata['messages'][] = $error;
         $this->sendResponse($rdata);
     }
     // Find file with the same name in the same dir
     $db = JFactory::getDbo();
     $query = $db->getQuery(true);
     $name = JFile::makeSafe($file['name']);
     $query->select('id')->from('#__pf_repo_files')->where('dir_id = ' . (int) $dir)->where('file_name = ' . $db->quote($name));
     $db->setQuery($query, 0, 1);
     $parent_id = (int) $db->loadResult();
     $model = $this->getModel();
     $result = $model->upload($file, $dir, $method == 'xhr' ? true : false, $parent_id);
     if (!$result) {
         $rdata['success'] = false;
         $rdata['messages'][] = $model->getError();
         $this->sendResponse($rdata);
     }
     // Prepare data for saving
     $data = array();
     $data['project_id'] = $project;
     $data['dir_id'] = $dir;
     $data['file'] = $result;
     $data['title'] = $result['name'];
     if ($parent_id) {
         $data['id'] = $parent_id;
     }
     if (!$model->save($data)) {
         $rdata['success'] = false;
         $rdata['messages'][] = $model->getError();
         $this->sendResponse($rdata);
     }
     $this->sendResponse($rdata);
 }
 /**
  * Adds the page title and toolbar.
  *
  */
 protected function addToolbar()
 {
     $user = JFactory::getUser();
     $state = $this->get('State');
     JToolBarHelper::title(JText::_('COM_PROJECTFORK_REPO_TITLE'), 'article.png');
     if ($state->get('filter.project') && $this->items['directory']->id > 1) {
         $access = PFrepoHelper::getActions('directory', $this->items['directory']->id);
         if ($access->get('core.create')) {
             JToolBarHelper::custom('directory.add', 'new.png', 'new_f2.png', 'JTOOLBAR_ADD_DIRECTORY', false);
             JToolBarHelper::custom('file.add', 'upload.png', 'upload_f2.png', 'JTOOLBAR_ADD_FILE', false);
             JToolBarHelper::custom('note.add', 'copy.png', 'html_f2.png', 'JTOOLBAR_ADD_NOTE', false);
         }
         if ($access->get('core.delete')) {
             JToolBarHelper::divider();
             JToolBarHelper::deleteList('', 'repository.delete', 'JTOOLBAR_DELETE');
         }
     }
     if ($user->authorise('core.admin')) {
         JToolBarHelper::preferences('com_pfrepo');
     }
 }
Example #15
0
 * @author       Tobias Kuhn (eaxs)
 * @copyright    Copyright (C) 2006-2012 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');
$function = JRequest::getCmd('function', 'pfSelectAttachment');
$user = JFactory::getUser();
$uid = $user->get('id');
$list_order = $this->escape($this->state->get('list.ordering'));
$list_dir = $this->escape($this->state->get('list.direction'));
$project = (int) $this->state->get('filter.project');
$this_dir = $this->items['directory'];
$link_append = '&layout=modal&tmpl=component&function=' . $function;
$access = PFrepoHelper::getActions('directory', $this_dir->id);
$allowed = PFrepoHelper::getAllowedFileExtensions();
$config = JComponentHelper::getParams('com_pfrepo');
$filter_admin = $config->get('filter_ext_admin');
$is_admin = $user->authorise('core.admin');
// Restrict file extensions?
$txt_upload = '';
if ($is_admin && !$filter_admin) {
    $allowed = array();
}
if (count($allowed)) {
    $txt_upload = JText::_('COM_PROJECTFORK_UPLOAD_ALLOWED_EXT') . ' ' . implode(', ', $allowed);
}
?>
<form action="<?php 
echo JRoute::_('index.php?option=com_pfrepo&view=repository' . $link_append);
?>
Example #16
0
 /**
  * Method to physically copy directory
  *
  * @param     array      $data    The directory data
  *
  * @return    boolean             True on success
  */
 protected function copyPhysical($project, $path, $dest)
 {
     if (!$project) {
         return false;
     }
     $base = PFrepoHelper::getBasePath();
     $path_exists = JFolder::exists($base . '/' . $path);
     $dest_exists = JFolder::exists($base . '/' . $dest);
     // Do nothing if the path does not exist or if the destination already exists
     if (!$path_exists || $dest_exists) {
         return true;
     }
     return JFolder::copy($base . '/' . $path, $base . '/' . $dest);
 }
Example #17
0
 /**
  * Method to delete one or more records.
  *
  * @param     array      An array of record primary keys.
  *
  * @return    boolean    True if successful, false if an error occurs.
  */
 public function delete(&$pks)
 {
     $pks = (array) $pks;
     $table = $this->getTable();
     $query = $this->_db->getQuery(true);
     $active_id = PFApplicationHelper::getActiveProjectId();
     $repo_exists = PFApplicationHelper::exists('com_pfrepo');
     if ($repo_exists) {
         $base_path = PFrepoHelper::getBasePath();
     }
     // Include the content plugins for the on delete events.
     $dispatcher = JDispatcher::getInstance();
     JPluginHelper::importPlugin('content');
     // Iterate the items to delete each one.
     foreach ($pks as $i => $pk) {
         // Try to load from the db
         if ($table->load($pk) === false) {
             $this->setError($table->getError());
             return false;
         }
         // Check delete permission
         if (!$this->canDelete($table)) {
             unset($pks[$i]);
             $error = $this->getError();
             if ($error) {
                 JError::raiseWarning(500, $error);
             } else {
                 JError::raiseWarning(403, JText::_('JLIB_APPLICATION_ERROR_DELETE_NOT_PERMITTED'));
             }
             return false;
         }
         // Trigger the onContentBeforeDelete event.
         $context = $this->option . '.' . $this->name;
         $result = $dispatcher->trigger($this->event_before_delete, array($context, $table));
         if (in_array(false, $result, true)) {
             $this->setError($table->getError());
             return false;
         }
         if ($repo_exists) {
             $params = new JRegistry();
             $params->loadString($table->attribs);
             $repo_dir = (int) $params->get('repo_dir');
             $query->clear()->select('path')->from('#__pf_repo_dirs')->where('id = ' . $repo_dir);
             $this->_db->setQuery($query);
             $repo_path = $this->_db->loadResult();
         }
         // Delete the item
         if (!$table->delete($pk)) {
             $this->setError($table->getError());
             return false;
         }
         // Delete the repo directory
         if ($repo_exists) {
             if ($repo_path && $repo_dir) {
                 // Delete repo 4.1
                 $repo = $base_path . '/' . $repo_path;
                 if (JFolder::exists($repo) && $repo != $base_path) {
                     JFolder::delete($repo);
                 }
                 // Delete repo 4.0
                 $repo = $base_path . '/' . $pk;
                 if (JFolder::exists($repo)) {
                     JFolder::delete($repo);
                 }
                 // Delete repo 3.0
                 $repo = $base_path . '/project_' . $pk;
                 if (JFolder::exists($repo)) {
                     JFolder::delete($repo);
                 }
             }
         }
         // Delete the logo
         $this->deleteLogo($pk);
         // Check if the currently active project is being deleted.
         // If so, clear it from the session
         if ($active_id == $pk) {
             $this->setActive(array('id' => 0));
         }
         // Trigger the onContentAfterDelete event.
         $dispatcher->trigger($this->event_after_delete, array($context, $table));
     }
     // Clear the component's cache
     $this->cleanCache();
     return true;
 }
Example #18
0
 /**
  * Generates the toolbar for the top of the view
  *
  * @return    string    Toolbar with buttons
  */
 protected function getToolbar()
 {
     $dir = $this->items['directory'];
     $access = PFrepoHelper::getActions('directory', $dir->id);
     if ($dir->id > 1) {
         $items = array();
         $items[] = array('text' => 'COM_PROJECTFORK_ACTION_NEW_FILE', 'task' => 'fileform.add', 'options' => array('access' => $access->get('core.create') && !defined('PFDEMO')));
         $items[] = array('text' => 'COM_PROJECTFORK_ACTION_NEW_DIRECTORY', 'task' => 'directoryform.add', 'options' => array('access' => $access->get('core.create')));
         $items[] = array('text' => 'COM_PROJECTFORK_ACTION_NEW_NOTE', 'task' => 'noteform.add', 'options' => array('access' => $access->get('core.create')));
         PFToolbar::dropdownButton($items);
         $items = array();
         $items[] = array('text' => 'COM_PROJECTFORK_ACTION_DELETE', 'task' => $this->getName() . '.delete', 'options' => array('access' => $access->get('core.delete')));
         $items[] = array('text' => 'COM_PROJECTFORK_ACTION_CHECKIN', 'task' => $this->getName() . '.checkin');
         if (count($items)) {
             PFToolbar::listButton($items);
         }
     }
     PFToolbar::filterButton($this->state->get('filter.isset'));
     return PFToolbar::render();
 }
Example #19
0
 /**
  * Batch copy notes to a new directory.
  *
  * @param     integer    $value    The destination dir.
  * @param     array      $pks      An array of row IDs.
  * @param     array      $contexts      An array of row contexts.
  *
  * @return    mixed                An array of new IDs on success, boolean false on failure.
  */
 protected function batchCopy($value, $pks, $contexts = array())
 {
     $dest = (int) $value;
     $rbid = null;
     $table = $this->getTable('Directory');
     $db = $this->getDbo();
     $user = JFactory::getUser();
     $i = 0;
     // Check that the parent exists
     if ($dest) {
         if (!$table->load($dest)) {
             if ($error = $table->getError()) {
                 $this->setError($error);
                 return false;
             } else {
                 $this->setError(JText::_('COM_PROJECTFORK_ERROR_BATCH_COPY_DIRECTORY_NOT_FOUND'));
                 return false;
             }
         }
         // Check that user has create permission for parent directory
         $access = PFrepoHelper::getActions('directory', $dest);
         if (!$access->get('core.create')) {
             // Error since user cannot create in parent dir
             $this->setError(JText::_('COM_PROJECTFORK_ERROR_BATCH_CANNOT_CREATE_NOTE'));
             return false;
         }
     }
     $table = $this->getTable();
     $newIds = array();
     // Parent exists so we let's proceed
     foreach ($pks as $pk) {
         // Check that the row actually exists
         if (!$table->load($pk)) {
             if ($error = $table->getError()) {
                 // Fatal error
                 $this->setError($error);
                 return false;
             } else {
                 // Not fatal error
                 $this->setError(JText::sprintf('JGLOBAL_BATCH_MOVE_ROW_NOT_FOUND', $pk));
                 continue;
             }
         }
         // Reset the id because we are making a copy.
         $table->id = 0;
         // Set the new location in the tree for the node.
         $table->dir_id = (int) $dest;
         // Alter the title & alias
         list($title, $alias) = $this->generateNewTitle($table->dir_id, $table->title, $table->alias);
         $table->title = $title;
         $table->alias = $alias;
         // Store the row.
         if (!$table->store()) {
             $this->setError($table->getError());
             return false;
         }
         // Get the new item ID
         $newId = $table->get('id');
         // Add the new ID to the array
         $newIds[] = $newId;
     }
     return $newIds;
 }
 */
defined('_JEXEC') or die;
$user = JFactory::getUser();
$uid = $user->get('id');
$this_dir = $this->items['directory'];
$this_path = empty($this_dir) ? '' : $this_dir->path;
$filter_search = $this->state->get('filter.search');
$filter_project = (int) $this->state->get('filter.project');
$is_search = empty($filter_search) ? false : true;
$txt_revs = JText::_('COM_PROJECTFORK_VIEW_REVISIONS');
$txt_icon = JText::_('COM_PROJECTFORK_FIELD_FILE_LABEL');
$date_format = JText::_('DATE_FORMAT_LC4');
$txt_dl = JText::_('COM_PROJECTFORK_DOWNLOAD');
foreach ($this->items['files'] as $i => $item) {
    $edit_link = 'task=file.edit&filter_project=' . $item->project_id . 'filter_parent_id=' . $item->dir_id . '&id=' . $item->id;
    $access = PFrepoHelper::getActions('file', $item->id);
    $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;
    $cm_dl = 'index.php?option=com_pfrepo&task=file.download' . '&filter_project=' . $item->project_id . 'filter_parent_id=' . $item->dir_id . '&id=' . $item->id;
    ?>
    <tr class="row<?php 
    echo $i % 2;
    ?>
">
        <td class="center hidden-phone">
            <?php 
    echo JHtml::_('grid.id', $i, $item->id, false, 'fid');
    ?>
Example #21
0
 /**
  * Method to get item data.
  *
  * @param     integer    The id of the item.
  * @return    mixed      Menu item data object on success, false on failure.
  */
 public function getItem($pk = null)
 {
     // Initialise variables.
     $pk = !empty($pk) ? $pk : (int) $this->getState($this->getName() . '.id');
     if ($this->_item === null) {
         $this->_item = array();
     }
     if (isset($this->_item[$pk])) {
         return $this->_item[$pk];
     }
     try {
         $db = $this->getDbo();
         $query = $db->getQuery(true);
         $query->select($this->getState('item.select', 'a.id, a.asset_id, a.project_id, a.dir_id, a.title, a.alias, a.description AS text, ' . 'a.created, a.created_by, a.modified, a.modified_by, a.checked_out, a.checked_out_time, ' . 'a.attribs, a.access'));
         $query->from('#__pf_repo_notes AS a');
         // Join on project table.
         $query->select('p.title AS project_title, p.alias AS project_alias');
         $query->join('LEFT', '#__pf_projects AS p on p.id = a.project_id');
         // Join on directories table.
         $query->select('d.title AS dir_title, d.alias AS dir_alias, d.path');
         $query->join('LEFT', '#__pf_repo_dirs AS d on d.id = a.dir_id');
         // Join on user table.
         $query->select('u.name AS author');
         $query->join('LEFT', '#__users AS u on u.id = a.created_by');
         $query->where('a.id = ' . (int) $pk);
         $db->setQuery($query);
         $item = $db->loadObject();
         if ($error = $db->getErrorMsg()) {
             throw new Exception($error);
         }
         if (empty($item)) {
             return JError::raiseError(404, JText::_('COM_PROJECTFORK_ERROR_NOTE_NOT_FOUND'));
         }
         // Convert parameter fields to objects.
         $registry = new JRegistry();
         $registry->loadString($item->attribs);
         $params = $this->getState('params');
         if ($params) {
             $item->params = clone $this->getState('params');
             $item->params->merge($registry);
         } else {
             $item->params = $registry;
         }
         // Generate 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;
         $item->dir_slug = $item->dir_alias ? $item->dir_id . ':' . $item->dir_alias : $item->dir_id;
         // Compute selected asset permissions.
         $user = JFactory::getUser();
         $uid = $user->get('id');
         $access = PFrepoHelper::getActions('note', $item->id);
         $view_access = true;
         if ($item->access && !$user->authorise('core.admin')) {
             $view_access = in_array($item->access, $user->getAuthorisedViewLevels());
         }
         $item->params->set('access-view', $view_access);
         if (!$view_access) {
             $item->params->set('access-edit', false);
             $item->params->set('access-change', false);
         } else {
             // Check general edit permission first.
             if ($access->get('core.edit')) {
                 $item->params->set('access-edit', true);
             } elseif (!empty($uid) && $access->get('core.edit.own')) {
                 // Check for a valid user and that they are the owner.
                 if ($uid == $item->created_by) {
                     $item->params->set('access-edit', true);
                 }
             }
             // Check edit state permission.
             $item->params->set('access-change', $access->get('core.edit.state'));
         }
         // Get the revision if requested
         $rev = (int) $this->getState($this->getName() . '.rev');
         if ($rev) {
             $cfg = array('ignore_request' => true);
             $rev_model = $this->getInstance('NoteRevision', 'PFrepoModel', $cfg);
             $rev_item = $rev_model->getItem($rev);
             // Check for error
             if ($error = $rev_model->getError()) {
                 throw new Exception($error);
             }
             if (empty($rev_item)) {
                 return JError::raiseError(404, JText::_('COM_PROJECTFORK_ERROR_NOTE_NOT_FOUND'));
             }
             if (!$rev_item || $rev_item->parent_id != $item->id) {
                 $item->params->set('access-view', false);
             } else {
                 // Override properties of item
                 $props = array('title', 'description', 'created', 'created_by');
                 foreach ($props as $prop) {
                     $item->{$prop} = $rev_item->{$prop};
                 }
                 $item->text = $rev_item->description;
             }
         }
         $this->_item[$pk] = $item;
     } catch (JException $e) {
         if ($e->getCode() == 404) {
             // Need to go thru the error handler to allow Redirect to work.
             JError::raiseError(404, $e->getMessage());
         } else {
             $this->setError($e);
             $this->_item[$pk] = false;
         }
     }
     return $this->_item[$pk];
 }
Example #22
0
 /**
  * Method to delete referenced data of an item.
  *
  * @param     mixed      $pk    An primary key value to delete.
  *
  * @return    boolean
  */
 public function deleteReferences($pk = null)
 {
     if (empty($this->id) || $this->id != $pk) {
         if (!$this->load($pk)) {
             return false;
         }
     }
     // Delete the physical file
     $path = PFrepoHelper::getFilePath($this->file_name, $this->dir_id);
     if (!empty($path)) {
         JFile::delete($path . '/' . $this->file_name);
     }
     // Delete the revisions folder
     $path = PFrepoHelper::getBasePath($this->project_id) . '/_revs/file_' . (int) $pk;
     if (JFolder::exists($path)) {
         JFolder::delete($path);
     }
     // Delete revisions
     $query = $this->_db->getQuery(true);
     $query->clear()->delete('#__pf_repo_file_revs')->where('parent_id = ' . (int) $pk);
     $this->_db->setQuery($query);
     $this->_db->execute();
 }
 /**
  * Method to check for upload errors
  *
  * @param     array      $files    The files to check
  * @param     integer $record_id The file id
  *
  * @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 = PFrepoHelper::getFileErrorMsg($file['error'], $file['name']);
             $this->setError($error);
             $this->setMessage($error, 'error');
             return false;
         }
     }
     return true;
 }