Ejemplo n.º 1
0
 /**
  * Display the view
  */
 public function display($tpl = null)
 {
     // Access check.
     if (!JFactory::getUser()->authorise('core.create', 'com_attachments')) {
         return JError::raiseError(404, JText::_('JERROR_ALERTNOAUTHOR') . ' (ERR 64)');
     }
     // For convenience below
     $attachment = $this->attachment;
     $parent = $this->parent;
     // Set up for editing the access level
     if ($this->params->get('allow_frontend_access_editing', false)) {
         require_once JPATH_COMPONENT_ADMINISTRATOR . '/models/fields/accesslevels.php';
         $this->access_level = JFormFieldAccessLevels::getAccessLevels('access', 'access', null);
         $this->access_level_tooltip = JText::_('ATTACH_ACCESS_LEVEL_TOOLTIP');
     }
     // Set up publishing info
     $user = JFactory::getUser();
     $this->may_publish = $parent->userMayChangeAttachmentState($attachment->parent_id, $attachment->parent_entity, $user->id);
     if ($this->may_publish) {
         $this->publish = JHtml::_('select.booleanlist', 'state', 'class="inputbox"', $attachment->state);
     }
     // Construct derived data
     $attachment->parent_entity_name = JText::_('ATTACH_' . $attachment->parent_entity);
     $attachment->parent_title = $parent->getTitle($attachment->parent_id, $attachment->parent_entity);
     $this->relative_url_checked = $attachment->url_relative ? 'checked="yes"' : '';
     $this->verify_url_checked = $attachment->url_verify ? 'checked="yes"' : '';
     // Add the stylesheets for the form
     JHtml::stylesheet('com_attachments/attachments_frontend_form.css', array(), true);
     $lang = JFactory::getLanguage();
     if ($lang->isRTL()) {
         JHtml::stylesheet('com_attachments/attachments_frontend_form_rtl.css', array(), true);
     }
     // Display the upload form
     parent::display($tpl);
 }
Ejemplo n.º 2
0
 /**
  * Display the view
  */
 public function display($tpl = null)
 {
     // Access check.
     if (!(JFactory::getUser()->authorise('core.edit', 'com_attachments') or JFactory::getUser()->authorise('core.edit.own', 'com_attachments'))) {
         return JError::raiseError(404, JText::_('JERROR_ALERTNOAUTHOR') . ' (ERR 62)');
     }
     // For convenience
     $attachment = $this->attachment;
     $parent = $this->parent;
     // Construct derived data
     $attachment->parent_entity_name = JText::_('ATTACH_' . $attachment->parent_entity);
     $attachment->parent_title = $parent->getTitle($attachment->parent_id, $attachment->parent_entity);
     if (!isset($attachment->modifier_name)) {
         AttachmentsHelper::addAttachmentUserNames($attachment);
     }
     $this->relative_url_checked = $attachment->url_relative ? 'checked="yes"' : '';
     $this->verify_url_checked = $attachment->url_verify ? 'checked="yes"' : '';
     $this->may_publish = $parent->userMayChangeAttachmentState($attachment->parent_id, $attachment->parent_entity, $attachment->created_by);
     // Set up some HTML for display in the form
     $this->lists = array();
     $this->lists['published'] = JHtml::_('select.booleanlist', 'state', 'class="inputbox"', $attachment->state);
     $this->lists['url_valid'] = JHtml::_('select.booleanlist', 'url_valid', 'class="inputbox" title="' . JText::_('ATTACH_URL_IS_VALID_TOOLTIP') . '"', $attachment->url_valid);
     // Set up for editing the access level
     if ($this->params->get('allow_frontend_access_editing', false)) {
         require_once JPATH_COMPONENT_ADMINISTRATOR . '/models/fields/accesslevels.php';
         $this->access_level = JFormFieldAccessLevels::getAccessLevels('access', 'access', $attachment->access);
         $this->access_level_tooltip = JText::_('ATTACH_ACCESS_LEVEL_TOOLTIP');
     }
     // Add the stylesheets
     JHtml::stylesheet('com_attachments/attachments_frontend_form.css', array(), true);
     $lang = JFactory::getLanguage();
     if ($lang->isRTL()) {
         JHtml::stylesheet('com_attachments/attachments_frontend_form_rtl.css', array(), true);
     }
     // Display the form
     parent::display($tpl);
 }
Ejemplo n.º 3
0
 /**
  * Edit - display the form for the user to edit an attachment
  *
  * @param	string	$key	 The name of the primary key of the URL variable (IGNORED)
  * @param	string	$urlVar	 The name of the URL variable if different from the primary key. (IGNORED)
  */
 public function edit($key = null, $urlVar = null)
 {
     // Fail gracefully if the Attachments plugin framework plugin is disabled
     if (!JPluginHelper::isEnabled('attachments', 'attachments_plugin_framework')) {
         echo '<h1>' . JText::_('ATTACH_WARNING_ATTACHMENTS_PLUGIN_FRAMEWORK_DISABLED') . '</h1>';
         return;
     }
     // Access check.
     $user = JFactory::getUser();
     if (!($user->authorise('core.edit', 'com_attachments') or $user->authorise('core.edit.own', 'com_attachments'))) {
         return JError::raiseError(403, JText::_('ATTACH_ERROR_NO_PERMISSION_TO_EDIT') . ' (ERR 132)');
     }
     $uri = JFactory::getURI();
     $db = JFactory::getDBO();
     $model = $this->getModel();
     $attachment = $model->getTable();
     $cid = JRequest::getVar('cid', array(0), '', 'array');
     $change = JRequest::getWord('change', '');
     $change_parent = $change == 'parent';
     $update_file = JRequest::getWord('change') == 'file';
     $attachment_id = (int) $cid[0];
     // Get the attachment data
     $attachment = $model->getItem($attachment_id);
     $from = JRequest::getWord('from');
     $layout = JRequest::getWord('tmpl');
     // Fix the URL for files
     if ($attachment->uri_type == 'file') {
         $attachment->url = $uri->root(true) . '/' . $attachment->url;
     }
     $parent_id = $attachment->parent_id;
     $parent_type = $attachment->parent_type;
     $parent_entity = $attachment->parent_entity;
     // Get the parent handler
     JPluginHelper::importPlugin('attachments');
     $apm = getAttachmentsPluginManager();
     if (!$apm->attachmentsPluginInstalled($parent_type)) {
         // Exit if there is no Attachments plugin to handle this parent_type
         $errmsg = JText::sprintf('ATTACH_ERROR_INVALID_PARENT_TYPE_S', $parent_type) . ' (ERR 133)';
         JError::raiseError(500, $errmsg);
     }
     $entity_info = $apm->getInstalledEntityInfo();
     $parent = $apm->getAttachmentsPlugin($parent_type);
     // Get the parent info
     $parent_entity_name = JText::_('ATTACH_' . $parent_entity);
     $parent_title = $parent->getTitle($parent_id, $parent_entity);
     if (!$parent_title) {
         $parent_title = JText::sprintf('ATTACH_NO_PARENT_S', $parent_entity_name);
     }
     $attachment->parent_entity_name = $parent_entity_name;
     $attachment->parent_title = $parent_title;
     $attachment->parent_published = $parent->isParentPublished($parent_id, $parent_entity);
     $update = JRequest::getWord('update');
     if ($update && !in_array($update, AttachmentsDefines::$LEGAL_URI_TYPES)) {
         $update = false;
     }
     // Set up view for changing parent
     $document = JFactory::getDocument();
     if ($change_parent) {
         $js = " \n\t   function jSelectArticle(id, title) {\n\t\t   document.getElementById('parent_id').value = id;\n\t\t   document.getElementById('parent_title').value = title;\n\t\t   window.parent.SqueezeBox.close();\n\t\t   };";
         $document->addScriptDeclaration($js);
     }
     // See if a new type of parent was requested
     $new_parent_type = '';
     $new_parent_entity = 'default';
     $new_parent_entity_name = '';
     if ($change_parent) {
         $new_parent_type = JRequest::getCmd('new_parent_type');
         if ($new_parent_type) {
             if (strpos($new_parent_type, '.')) {
                 $parts = explode('.', $new_parent_type);
                 $new_parent_type = $parts[0];
                 $new_parent_entity = $parts[1];
             }
             $new_parent = $apm->getAttachmentsPlugin($new_parent_type);
             $new_parent_entity = $new_parent->getCanonicalEntityId($new_parent_entity);
             $new_parent_entity_name = JText::_('ATTACH_' . $new_parent_entity);
             // Set up the 'select parent' button
             $selpar_label = JText::sprintf('ATTACH_SELECT_ENTITY_S_COLON', $new_parent_entity_name);
             $selpar_btn_text = '&nbsp;' . JText::sprintf('ATTACH_SELECT_ENTITY_S', $new_parent_entity_name) . '&nbsp;';
             $selpar_btn_tooltip = JText::sprintf('ATTACH_SELECT_ENTITY_S_TOOLTIP', $new_parent_entity_name);
             $selpar_btn_url = $new_parent->getSelectEntityURL($new_parent_entity);
             $selpar_parent_title = '';
             $selpar_parent_id = '-1';
         } else {
             // Set up the 'select parent' button
             $selpar_label = JText::sprintf('ATTACH_SELECT_ENTITY_S_COLON', $attachment->parent_entity_name);
             $selpar_btn_text = '&nbsp;' . JText::sprintf('ATTACH_SELECT_ENTITY_S', $attachment->parent_entity_name) . '&nbsp;';
             $selpar_btn_tooltip = JText::sprintf('ATTACH_SELECT_ENTITY_S_TOOLTIP', $attachment->parent_entity_name);
             $selpar_btn_url = $parent->getSelectEntityURL($parent_entity);
             $selpar_parent_title = $attachment->parent_title;
             $selpar_parent_id = $attachment->parent_id;
         }
     }
     $change_parent_url = $uri->base(true) . "/index.php?option=com_attachments&amp;task=attachment.edit&amp;cid[]={$attachment_id}&amp;change=parent";
     if ($layout) {
         $change_parent_url .= "&amp;from={$from}&amp;tmpl={$layout}";
     }
     // Get the component parameters
     jimport('joomla.application.component.helper');
     $params = JComponentHelper::getParams('com_attachments');
     // Set up the view
     require_once JPATH_COMPONENT_ADMINISTRATOR . '/views/edit/view.html.php';
     $view = new AttachmentsViewEdit();
     AttachmentsControllerAttachment::add_view_urls($view, 'update', $parent_id, $parent_type, $attachment_id, $from);
     // Update change URLS to remember if we want to change the parent
     if ($change_parent) {
         $view->change_file_url .= "&amp;change=parent&amp;new_parent_type={$new_parent_type}";
         $view->change_url_url .= "&amp;change=parent&amp;new_parent_type={$new_parent_type}";
         $view->normal_update_url .= "&amp;change=parent&amp;new_parent_type={$new_parent_type}";
         if ($new_parent_entity != 'default') {
             $view->change_file_url .= ".{$new_parent_entity}";
             $view->change_url_url .= ".{$new_parent_entity}";
             $view->normal_update_url .= ".{$new_parent_entity}";
         }
     }
     // Add a few necessary things for iframe popups
     if ($layout) {
         $view->change_file_url .= "&amp;from={$from}&amp;tmpl={$layout}";
         $view->change_url_url .= "&amp;from={$from}&amp;tmpl={$layout}";
         $view->normal_update_url .= "&amp;from={$from}&amp;tmpl={$layout}";
     }
     // Suppress the display filename if we are switching from file to url
     $display_name = $attachment->display_name;
     if ($update && $update != $attachment->uri_type) {
         $attachment->display_name = '';
     }
     // Handle iframe popup requests
     $known_froms = $parent->knownFroms();
     $in_popup = false;
     $save_url = 'index.php';
     if (in_array($from, $known_froms)) {
         $in_popup = true;
         AttachmentsJavascript::setupJavascript();
         $save_url = 'index.php?option=com_attachments&amp;task=attachment.save';
     }
     $view->save_url = $save_url;
     $view->in_popup = $in_popup;
     // Set up the access field
     require_once JPATH_COMPONENT_ADMINISTRATOR . '/models/fields/accesslevels.php';
     $view->access_level_tooltip = JText::_('JFIELD_ACCESS_LABEL') . '::' . JText::_('JFIELD_ACCESS_DESC');
     $view->access_level = JFormFieldAccessLevels::getAccessLevels('access', 'access', $attachment->access);
     // Set up view info
     $view->update = $update;
     $view->change_parent = $change_parent;
     $view->new_parent_type = $new_parent_type;
     $view->new_parent_entity = $new_parent_entity;
     $view->change_parent_url = $change_parent_url;
     $view->entity_info = $entity_info;
     $view->may_publish = $parent->userMayChangeAttachmentState($parent_id, $parent_entity, $user->id);
     $view->from = $from;
     $view->option = $this->option;
     $view->attachment = $attachment;
     $view->parent = $parent;
     $view->params = $params;
     // Set up for selecting a new type of parent
     if ($change_parent) {
         $view->selpar_label = $selpar_label;
         $view->selpar_btn_text = $selpar_btn_text;
         $view->selpar_btn_tooltip = $selpar_btn_tooltip;
         $view->selpar_btn_url = $selpar_btn_url;
         $view->selpar_parent_title = $selpar_parent_title;
         $view->selpar_parent_id = $selpar_parent_id;
     }
     $view->display();
 }
Ejemplo n.º 4
0
 /**
  * Display the add/create view
  */
 public function display($tpl = null)
 {
     // For convenience below
     $attachment = $this->attachment;
     $parent_id = $attachment->parent_id;
     $parent_type = $attachment->parent_type;
     $parent_entity = $attachment->parent_entity;
     $attachment->parent_entity_name = JText::_('ATTACH_' . $attachment->parent_entity);
     $parent_entity_name = $attachment->parent_entity_name;
     $params = $this->params;
     // Prevent unallowed editing PID PE
     if (!$this->parent->userMayAddAttachment($parent_id, $parent_entity, $this->new_parent)) {
         $errmsg = JText::sprintf('ATTACH_ERROR_NO_PERMISSION_TO_UPLOAD_S', $attachment->parent_entity_name);
         return JError::raiseError(403, $errmsg . ' (ERR 173)');
     }
     // Construct derived data
     $this->relative_url_checked = $attachment->url_relative ? 'checked="yes"' : '';
     $this->verify_url_checked = $attachment->url_verify ? 'checked="yes"' : '';
     // Construct some tooltips
     $this->enter_url_tooltip = JText::_('ATTACH_ENTER_URL') . '::' . JText::_('ATTACH_ENTER_URL_TOOLTIP');
     $this->display_filename_tooltip = JText::_('ATTACH_DISPLAY_FILENAME') . '::' . JText::_('ATTACH_DISPLAY_FILENAME_TOOLTIP');
     $this->display_url_tooltip = JText::_('ATTACH_DISPLAY_URL') . '::' . JText::_('ATTACH_DISPLAY_URL_TOOLTIP');
     // Add the published selection
     $this->lists = array();
     $this->lists['published'] = JHtml::_('select.booleanlist', 'state', 'class="inputbox"', $attachment->state);
     // Set up the access field
     require_once JPATH_COMPONENT_ADMINISTRATOR . '/models/fields/accesslevels.php';
     $this->access_level = JFormFieldAccessLevels::getAccessLevels('access', 'access', null);
     $this->access_level_tooltip = JText::_('JFIELD_ACCESS_LABEL') . '::' . JText::_('JFIELD_ACCESS_DESC');
     // Handle user field 1
     $show_user_field_1 = false;
     $user_field_1_name = $params->get('user_field_1_name', '');
     if ($user_field_1_name != '') {
         $show_user_field_1 = true;
         $this->user_field_1_name = $user_field_1_name;
     }
     $this->show_user_field_1 = $show_user_field_1;
     // Handle user field 2
     $show_user_field_2 = false;
     $user_field_2_name = $params->get('user_field_2_name', '');
     if ($user_field_2_name != '') {
         $show_user_field_2 = true;
         $this->user_field_2_name = $user_field_2_name;
     }
     $this->show_user_field_2 = $show_user_field_2;
     // Handle user field 3
     $show_user_field_3 = false;
     $user_field_3_name = $params->get('user_field_3_name', '');
     if ($user_field_3_name != '') {
         $show_user_field_3 = true;
         $this->user_field_3_name = $user_field_3_name;
     }
     $this->show_user_field_3 = $show_user_field_3;
     // Set up to toggle between uploading file/urls
     if ($attachment->uri_type == 'file') {
         $upload_toggle_button_text = JText::_('ATTACH_ENTER_URL_INSTEAD');
         $upload_toggle_tooltip = JText::_('ATTACH_ENTER_URL_INSTEAD_TOOLTIP');
         $upload_toggle_url = 'index.php?option=com_attachments&amp;task=attachment.add&amp;uri=url';
     } else {
         $upload_toggle_button_text = JText::_('ATTACH_SELECT_FILE_TO_UPLOAD_INSTEAD');
         $upload_toggle_tooltip = JText::_('ATTACH_SELECT_FILE_TO_UPLOAD_INSTEAD_TOOLTIP');
         $upload_toggle_url = 'index.php?option=com_attachments&amp;task=attachment.add&amp;uri=file';
     }
     if ($this->from == 'closeme') {
         $upload_toggle_url .= '&amp;tmpl=component';
     }
     if ($this->from) {
         $upload_toggle_url .= '&amp;from=' . $this->from;
     }
     // Update the toggle URL to not forget if the parent is not simply an article
     if (!($parent_type == 'com_content' && $parent_entity == 'default')) {
         $upload_toggle_url .= "&amp;parent_type={$parent_type}";
         if ($parent_entity != 'default') {
             $upload_toggle_url .= ".{$parent_entity}";
         }
     }
     // If this is for an existing content item, modify the URL appropriately
     if ($this->new_parent) {
         $upload_toggle_url .= "&amp;parent_id=0,new";
     } elseif ($parent_id && $parent_id != -1) {
         $upload_toggle_url .= "&amp;parent_id={$parent_id}";
     }
     if (JRequest::getWord('editor')) {
         $upload_toggle_url .= "&amp;editor=" . JRequest::getWord('editor');
     }
     $this->upload_toggle_button_text = $upload_toggle_button_text;
     $this->upload_toggle_url = $upload_toggle_url;
     $this->upload_toggle_tooltip = $upload_toggle_tooltip;
     // Set up the 'select parent' button
     $this->selpar_label = JText::sprintf('ATTACH_SELECT_ENTITY_S_COLON', $parent_entity_name);
     $this->selpar_btn_text = '&nbsp;' . JText::sprintf('ATTACH_SELECT_ENTITY_S', $parent_entity_name) . '&nbsp;';
     $this->selpar_btn_tooltip = JText::sprintf('ATTACH_SELECT_ENTITY_S_TOOLTIP', $parent_entity_name);
     $this->selpar_btn_url = $this->parent->getSelectEntityURL($parent_entity);
     // Add the style sheets
     JHtml::stylesheet('com_attachments/attachments_admin_form.css', array(), true);
     $lang = JFactory::getLanguage();
     if ($lang->isRTL()) {
         JHtml::stylesheet('com_attachments/attachments_admin_form_rtl.css', array(), true);
     }
     // Set up mootools/modal
     AttachmentsJavascript::setupModalJavascript();
     // Set the toolbar
     $this->addToolBar();
     // Display the form
     parent::display($tpl);
 }