예제 #1
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');
     }
 }
예제 #2
0
 /**
  * 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;
 }
예제 #3
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();
     // 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);
 }
예제 #4
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;
 }
예제 #5
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);
 */
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');
    ?>
        <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);
    }
예제 #8
0
 /**
  * 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();
 }
예제 #9
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];
 }
예제 #10
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;
 }
예제 #11
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();
 }
예제 #12
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;
 }
예제 #13
0
 /**
  * Batch copy items to a new directory.
  *
  * @param     integer    $value       The destination dir.
  * @param     array      $pks         An array of row IDs.
  * @param     array      $contexts    An array of item 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_FILE'));
             return false;
         }
     }
     $dir_path = $table->path;
     $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;
             }
         }
         // Copy the physical file
         $path = PFrepoHelper::getFilePath($table->file_name, $table->dir_id);
         if (empty($path)) {
             $this->setError(JText::sprintf('JGLOBAL_BATCH_MOVE_ROW_NOT_FOUND', $pk));
             continue;
         }
         $base = PFrepoHelper::getBasePath();
         $from = $path . '/' . $table->file_name;
         $to = $base . '/' . $dir_path;
         $name = $this->generateNewFileName($to, $table->file_name);
         if (!JFolder::exists($to)) {
             if (JFolder::create($to) !== true) {
                 continue;
             }
         }
         if (!JFile::copy($from, $to . '/' . $name)) {
             continue;
         } else {
             $table->file_name = $name;
         }
         // Reset the id because we are making a copy.
         $table->id = 0;
         // Set the new location directory
         $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;
 }
예제 #14
0
 /**
  * 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');
     }
 }