/**
  * Test the round-trip conversions form icon-filename to mime-type and back
  */
 public function testRoundTrip()
 {
     $icon_filenames = AttachmentsFileTypes::unique_icon_filenames();
     $mime_from_icon = array_flip(AttachmentsFileTypes::$attachments_icon_from_mime_type);
     foreach ($icon_filenames as $icon) {
         if (array_key_exists($icon, $mime_from_icon)) {
             $mime_type = $mime_from_icon[$icon];
             $this->assertEquals($icon, AttachmentsFileTypes::icon_filename('', $mime_type));
         }
     }
 }
Beispiel #2
0
 /**
  * Display the edit view
  */
 public function display($tpl = null)
 {
     // For convenience
     $attachment = $this->attachment;
     // Prevent unallowed editing
     if (!$this->attachment->parent->userMayEditAttachment($attachment)) {
         $errmsg = JText::_('ATTACH_ERROR_NO_PERMISSION_TO_EDIT');
         return JError::raiseError(403, $errmsg . ' (ERR 178)');
     }
     // Construct derived data
     $attachment->parent_entity_name = JText::_('ATTACH_' . $attachment->parent_entity);
     if (!isset($attachment->modifier_name)) {
         AttachmentsHelper::addAttachmentUserNames($attachment);
     }
     // Compute the attachment size in kB
     $attachment->size_kb = (int) (10 * $attachment->file_size / 1024.0) / 10.0;
     // set up lists for form controls
     $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);
     // Construct the drop-down list for legal icon filenames
     $icon_filenames = array();
     require_once JPATH_COMPONENT_SITE . '/file_types.php';
     foreach (AttachmentsFileTypes::unique_icon_filenames() as $ifname) {
         $icon_filenames[] = JHtml::_('select.option', $ifname);
     }
     $this->lists['icon_filenames'] = JHtml::_('select.genericlist', $icon_filenames, 'icon_filename', 'class="inputbox" size="1"', 'value', 'text', $attachment->icon_filename);
     // If switching from article to URL default url_verify to true
     if ($attachment->uri_type == 'file' and $this->update == 'url') {
         $attachment->url_verify = true;
     }
     // Set up for checkboxes
     $this->relative_url_checked = $attachment->url_relative ? 'checked="yes"' : '';
     $this->verify_url_checked = $attachment->url_verify ? 'checked="yes"' : '';
     // Set up 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');
     $this->download_count_tooltip = JText::_('ATTACH_NUMBER_OF_DOWNLOADS') . '::' . JText::_('ATTACH_NUMBER_OF_DOWNLOADS_TOOLTIP');
     // Set up mootools/modal
     AttachmentsJavascript::setupModalJavascript();
     // 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 the toolbar
     $this->addToolBar();
     // Display the form
     parent::display($tpl);
 }
 function edit()
 {
     global $option, $mainframe;
     $db =& JFactory::getDBO();
     $row =& JTable::getInstance('Attachments', 'Table');
     $cid = JRequest::getVar('cid', array(0), '', 'array');
     $change_article = JRequest::getVar('change', False) == 'article';
     $update_file = JRequest::getVar('change', False) == 'file';
     $id = $cid[0];
     $row->load($id);
     $lists = array();
     $lists['published'] = JHTML::_('select.booleanlist', 'published', 'class="inputbox"', $row->published);
     // Construct the drop-down list for legal icon filenames
     $icon_filenames = array();
     require_once JPATH_COMPONENT_SITE . DS . 'file_types.php';
     foreach (AttachmentsFileTypes::unique_icon_filenames() as $ifname) {
         $icon_filenames[] = JHTML::_('select.option', $ifname);
     }
     $lists['icon_filenames'] = JHTML::_('select.genericlist', $icon_filenames, 'icon_filename', 'class="inputbox" size="1"', 'value', 'text', $row->icon_filename);
     // Get the uploaders name
     $query = "SELECT name FROM #__users WHERE id='" . $row->uploader_id . "' LIMIT 1";
     $db->setQuery($query);
     $row->uploader_name = $db->loadResult();
     // Massage the data
     $row->size = intval($row->file_size / 1024.0);
     $row->url = $mainframe->getSiteURL() . $row->url;
     // Get the article name
     $article_id = $row->article_id;
     $query = "SELECT * FROM #__content WHERE id='{$article_id}' LIMIT 1";
     $db->setQuery($query);
     $arows = $db->loadObjectList();
     if (count($arows) != 1) {
         $errmsg = JText::_('ERROR INVALID ARTICLE ID') . " ({$article_id})";
         JError::raiseError(500, $errmsg);
     }
     $row->article_title = $arows[0]->title;
     if ($change_article) {
         $document =& JFactory::getDocument();
         $document->addScript(JURI::root(true) . '/media/system/js/modal.js');
         $js = "\r\n            function jSelectArticle(id, title) {\r\n                    document.getElementById('article_id').value = id;\r\n                    document.getElementById('article_title').value = title;\r\n                    document.getElementById('sbox-window').close();\r\n                    }";
         $document->addScriptDeclaration($js);
         JHTML::_('behavior.modal', 'a.modal-button');
     }
     JRequest::setVar('hidemainmenu', 1);
     HTML_attachments::editAttachment($row, $lists, $option, $change_article, $update_file);
 }
 /**
  * Method to get the field input markup.
  *
  * @return	string	The field input markup.
  * @since	1.6
  */
 public function getInput()
 {
     // Initialize variables.
     $html = array();
     // Construct the list of legal icon filenames
     $icon_filenames = array();
     require_once JPATH_COMPONENT_SITE . '/file_types.php';
     foreach (AttachmentsFileTypes::unique_icon_filenames() as $ifname) {
         $icon_filenames[] = JHtml::_('select.option', $ifname);
     }
     $icon_list = JHtml::_('select.genericlist', $icon_filenames, 'jform[icon_filename]', 'class="inputbox" size="1"', 'value', 'text', $this->value, 'jform_icon_filename');
     // Is it readonly?
     if ((string) $this->element['readonly'] == 'true') {
         // Create a read-only list (no name) with a hidden input to store the value.
         $html[] = $icon_list;
         $html[] = '<input type="hidden" name="' . $this->name . '" value="' . $this->value . '"/>';
     } else {
         // Create a regular list.
         $html[] = $icon_list;
     }
     return implode($html);
 }