/**
  * Attach the Attachments CSS sheets for category pages
  *
  * @param	string	The context of the content being passed to the plugin.
  * @param	object	The article object.	 Note $article->text is also available
  * @param	object	The article params
  * @param	int		The 'page' number
  *
  * @return	void
  */
 public function onContentPrepare($context, &$row, &$params, $page = 0)
 {
     $view = JRequest::getCmd('view');
     $layout = JRequest::getWord('layout');
     if ($view == 'category') {
         $app = JFactory::getApplication();
         if ($app->isAdmin()) {
             return;
         }
         // Note if this is a category view, we must add attachment
         // javascript and CSS whether we know there are going to be
         // attachments later or not because when the attachments list is
         // created it, it is in the onAfterRender() callback, which means
         // that the headers have already been rendered, so we cannot go
         // go back and add headers (easily)
         // Not necessary in more recent versions of Joomla since it can
         // handled by the normal Attachments onContentPrepare callback
         if (version_compare(JVERSION, '3.1', 'ge') or version_compare(JVERSION, '2.5.10', 'ge')) {
             return;
         }
         $uri = JFactory::getURI();
         $base_url = $uri->root(true);
         AttachmentsJavascript::setupJavascript();
         AttachmentsJavascript::setupModalJavascript();
         // Add the style sheets
         JHtml::stylesheet('com_attachments/attachments_list.css', array(), true);
         JHtml::stylesheet('com_attachments/attachments_hide.css', array(), true);
         $lang = JFactory::getLanguage();
         if ($lang->isRTL()) {
             JHtml::stylesheet('com_attachments/attachments_list_rtl.css', array(), true);
         }
     }
 }
Example #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);
 }
Example #3
0
 /**
  * The content plugin that inserts the attachments list into content items
  *
  * @param	string	 $context  the context of the content being passed to the plugin.
  * @param	&object	 &$row	   the content object (eg, article) being displayed
  * @param	&object	 &$params  the parameters
  * @param	int		 $page	   the 'page' number
  *
  * @return true if anything has been inserted into the content object
  */
 public function onContentBeforeDisplay($context, &$row, &$params, $page = 0)
 {
     $view = JRequest::getCmd('view');
     $layout = JRequest::getCmd('layout');
     if ($context == 'com_content.category' and $view == 'category' and $layout == 'blog') {
         // Use onContentPrepare for category blog articles for Joomla 3.4+
         if (version_compare(JVERSION, '3.4', 'ge')) {
             return false;
         }
     }
     // Set the parent info from the context
     if (strpos($context, '.') === false) {
         // Assume the context is the parent_type
         $parent_type = $context;
         $parent_entity = '';
     } else {
         list($parent_type, $parent_entity) = explode('.', $context, 2);
     }
     // ??? Do we need to filter to ensure only articles use this callback?
     // Load the language
     $lang = JFactory::getLanguage();
     $lang->load('plg_content_attachments', dirname(__FILE__));
     // Add the refresh javascript
     AttachmentsJavascript::setupJavascript();
     // Always include the hide rule (since it may be needed to hide the custom tags)
     JHtml::stylesheet('com_attachments/attachments_hide.css', array(), true);
     // Get the article/parent handler
     JPluginHelper::importPlugin('attachments');
     $apm = getAttachmentsPluginManager();
     if (!$apm->attachmentsPluginInstalled($parent_type)) {
         // Exit quietly if there is no Attachments plugin to handle this parent_type
         return false;
     }
     $parent = $apm->getAttachmentsPlugin($parent_type);
     // If this attachments plugin is disabled, skip it
     if (!$apm->attachmentsPluginEnabled($parent_type)) {
         return false;
     }
     // Figure out the parent entity
     $parent_entity = $parent->determineParentEntity($row);
     if (!$parent_entity) {
         return false;
     }
     // Get the parent ID
     $parent_id = null;
     if (isset($row->id) && $row->id > 0) {
         $parent_id = (int) $row->id;
     } else {
         $parent_id = $parent->getParentId($row);
     }
     // Exit if there is no parent
     if ($parent_id === false) {
         return false;
     }
     // Allow remapping of parent ID (eg, for Joomfish)
     if (jimport('attachments_remapper.remapper')) {
         $parent_id = AttachmentsRemapper::remapParentID($parent_id, $parent_type, $parent_entity);
     }
     // Exit if we should not display attachments for this parent
     if ($parent->attachmentsHiddenForParent($row, $parent_id, $parent_entity)) {
         return false;
     }
     // Add the attachments list
     $parent->insertAttachmentsList($row, $parent_id, $parent_entity);
     // ??? if (isset($row->text)) $row->text .= " [OCBD text $context]";
     // ??? if (isset($row->introtext)) $row->introtext .= " [OCBD introtext $context]";
     return;
 }
Example #4
0
 /**
  * Save an attachment (from editing)
  */
 public function save($key = null, $urlVar = null)
 {
     // Check for request forgeries
     JSession::checkToken() or die(JText::_('JINVALID_TOKEN'));
     // 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::_('JERROR_ALERTNOAUTHOR') . ' (ERR 134)');
     }
     $model = $this->getModel();
     $attachment = $model->getTable();
     // Make sure the article ID is valid
     $attachment_id = JRequest::getInt('id');
     if (!$attachment->load($attachment_id)) {
         $errmsg = JText::sprintf('ATTACH_ERROR_CANNOT_UPDATE_ATTACHMENT_INVALID_ID_N', $id) . ' (ERR 135)';
         JError::raiseError(500, $errmsg);
     }
     // Note the old uri type
     $old_uri_type = $attachment->uri_type;
     // Get the data from the form
     if (!$attachment->bind(JRequest::get('post'))) {
         $errmsg = $attachment->getError() . ' (ERR 136)';
         JError::raiseError(500, $errmsg);
     }
     // Get the parent handler for this attachment
     JPluginHelper::importPlugin('attachments');
     $apm = getAttachmentsPluginManager();
     if (!$apm->attachmentsPluginInstalled($attachment->parent_type)) {
         $errmsg = JText::sprintf('ATTACH_ERROR_INVALID_PARENT_TYPE_S', $attachment->parent_type) . ' (ERR 135B)';
         JError::raiseError(500, $errmsg);
     }
     $parent = $apm->getAttachmentsPlugin($attachment->parent_type);
     // See if the parent ID has been changed
     $parent_changed = false;
     $old_parent_id = JRequest::getString('old_parent_id');
     if ($old_parent_id == '') {
         $old_parent_id = null;
     } else {
         $old_parent_id = JRequest::getInt('old_parent_id');
     }
     // Handle new parents (in process of creation)
     if ($parent->newParent($attachment)) {
         $attachment->parent_id = null;
     }
     // Deal with updating an orphaned attachment
     if ($old_parent_id == null && is_numeric($attachment->parent_id)) {
         $parent_changed = true;
     }
     // Check for normal parent changes
     if ($old_parent_id && $attachment->parent_id != $old_parent_id) {
         $parent_changed = true;
     }
     // See if we are updating a file or URL
     $new_uri_type = JRequest::getWord('update');
     if ($new_uri_type && !in_array($new_uri_type, AttachmentsDefines::$LEGAL_URI_TYPES)) {
         // Make sure only legal values are entered
         $new_uri_type = '';
     }
     // See if the parent type has changed
     $new_parent_type = JRequest::getCmd('new_parent_type');
     $new_parent_entity = JRequest::getCmd('new_parent_entity');
     $old_parent_type = JRequest::getCmd('old_parent_type');
     $old_parent_entity = JRequest::getCmd('old_parent_entity');
     if ($new_parent_type && ($new_parent_type != $old_parent_type || $new_parent_entity != $old_parent_entity)) {
         $parent_changed = true;
     }
     // If the parent has changed, make sure they have selected the new parent
     if ($parent_changed && (int) $attachment->parent_id == -1) {
         $errmsg = JText::sprintf('ATTACH_ERROR_MUST_SELECT_PARENT');
         echo "<script type=\"text/javascript\"> alert('{$errmsg}'); window.history.go(-1); </script>\n";
         exit;
     }
     // If the parent has changed, switch the parent, rename files if necessary
     if ($parent_changed) {
         if ($new_uri_type == 'url' && $old_uri_type == 'file') {
             // If we are changing parents and converting from file to URL, delete the old file
             jimport('joomla.filesystem.file');
             // Load the attachment so we can get its filename_sys
             $db = JFactory::getDBO();
             $query = $db->getQuery(true);
             $query->select('filename_sys, id')->from('#__attachments')->where('id=' . (int) $attachment->id);
             $db->setQuery($query, 0, 1);
             $filename_sys = $db->loadResult();
             JFile::delete($filename_sys);
             AttachmentsHelper::clean_directory($filename_sys);
         } else {
             // Otherwise switch the file/url to the new parent
             if ($old_parent_id == null) {
                 $old_parent_id = 0;
                 // NOTE: When attaching a file to an article during creation,
                 //		 the article_id (parent_id) is initially null until
                 //		 the article is saved (at that point the
                 //		 parent_id/article_id updated).	 If the attachment is
                 //		 added and creating the article is canceled, the
                 //		 attachment exists but is orhpaned since it does not
                 //		 have a parent.	 It's article_id is null, but it is
                 //		 saved in directory as if its article_id is 0:
                 //		 article/0/file.txt.  Therefore, if the parent has
                 //		 changed, we pretend the old_parent_id=0 for file
                 //		 renaming/moving.
             }
             $error_msg = AttachmentsHelper::switch_parent($attachment, $old_parent_id, $attachment->parent_id, $new_parent_type, $new_parent_entity);
             if ($error_msg != '') {
                 $errmsg = JText::_($error_msg) . ' (ERR 137)';
                 $link = 'index.php?option=com_attachments';
                 $this->setRedirect($link, $errmsg, 'error');
                 return;
             }
         }
     }
     // Update parent type/entity, if needed
     if ($new_parent_type && $new_parent_type != $old_parent_type) {
         $attachment->parent_type = $new_parent_type;
     }
     if ($new_parent_type && $new_parent_entity != $old_parent_entity) {
         $attachment->parent_entity = $new_parent_entity;
     }
     // Get the article/parent handler
     if ($new_parent_type) {
         $parent_type = $new_parent_type;
         $parent_entity = $new_parent_entity;
     } else {
         $parent_type = JRequest::getCmd('parent_type', 'com_content');
         $parent_entity = JRequest::getCmd('parent_entity', 'default');
     }
     $parent = $apm->getAttachmentsPlugin($parent_type);
     $parent_entity = $parent->getCanonicalEntityId($parent_entity);
     // Get the title of the article/parent
     $new_parent = JRequest::getBool('new_parent', false);
     $parent->new = $new_parent;
     if ($new_parent) {
         $attachment->parent_id = null;
         $parent->title = '';
     } else {
         $parent->title = $parent->getTitle($attachment->parent_id, $parent_entity);
     }
     // Check to make sure the user has permissions to edit the attachment
     if (!$parent->userMayEditAttachment($attachment)) {
         // ??? Add better error message
         return JError::raiseError(403, JText::_('JERROR_ALERTNOAUTHOR') . ' (ERR 139)');
     }
     // Double-check to see if the URL changed
     $old_url = JRequest::getString('old_url');
     if (!$new_uri_type && $old_url && $old_url != $attachment->url) {
         $new_uri_type = 'url';
     }
     // If this is a URL, get settings
     $verify_url = false;
     $relative_url = false;
     if ($new_uri_type == 'url') {
         // See if we need to verify the URL (if applicable)
         if (JRequest::getWord('verify_url') == 'verify') {
             $verify_url = true;
         }
         // Allow relative URLs?
         if (JRequest::getWord('url_relative') == 'relative') {
             $relative_url = true;
         }
     }
     // Compute the update time
     $now = JFactory::getDate();
     // Update create/modify info
     $attachment->modified_by = $user->get('id');
     $attachment->modified = $now->toSql();
     // Upload new file/url and create/update the attachment
     $msg = null;
     $msgType = 'message';
     if ($new_uri_type == 'file') {
         // Upload a new file
         $result = AttachmentsHelper::upload_file($attachment, $parent, $attachment_id, 'update');
         if (is_object($result)) {
             $msg = $result->error_msg . ' (ERR 140)';
             $msgType = 'error';
         } else {
             $msg = $result;
         }
         // NOTE: store() is not needed if upload_file() is called since it does it
     } elseif ($new_uri_type == 'url') {
         // Upload/add the new URL
         $result = AttachmentsHelper::add_url($attachment, $parent, $verify_url, $relative_url, $old_uri_type, $attachment_id);
         // NOTE: store() is not needed if add_url() is called since it does it
         if (is_object($result)) {
             $msg = $result->error_msg . ' (ERR 141)';
             $msgType = 'error';
         } else {
             $msg = $result;
         }
     } else {
         // Extra handling for checkboxes for URLs
         if ($attachment->uri_type == 'url') {
             // Update the url_relative field
             $attachment->url_relative = $relative_url;
             $attachment->url_verify = $verify_url;
         }
         // Remove any extraneous fields
         if (isset($attachment->parent_entity_name)) {
             unset($attachment->parent_entity_name);
         }
         // Save the updated attachment info
         if (!$attachment->store()) {
             $errmsg = $attachment->getError() . ' (ERR 142)';
             JError::raiseError(500, $errmsg);
         }
     }
     switch ($this->getTask()) {
         case 'apply':
             if (!$msg) {
                 $msg = JText::_('ATTACH_CHANGES_TO_ATTACHMENT_SAVED');
             }
             $link = 'index.php?option=com_attachments&task=attachment.edit&cid[]=' . (int) $attachment->id;
             break;
         case 'save':
         default:
             if (!$msg) {
                 $msg = JText::_('ATTACH_ATTACHMENT_UPDATED');
             }
             $link = 'index.php?option=com_attachments';
             break;
     }
     // If invoked from an iframe popup, close it and refresh the attachments list
     $from = JRequest::getWord('from');
     $known_froms = $parent->knownFroms();
     if (in_array($from, $known_froms)) {
         // If there has been a problem, alert the user and redisplay
         if ($msgType == 'error') {
             $errmsg = $msg;
             if (DIRECTORY_SEPARATOR == "\\") {
                 // Fix filename on Windows system so alert can display it
                 $errmsg = str_replace(DIRECTORY_SEPARATOR, "\\\\", $errmsg);
             }
             $errmsg = str_replace("'", "\\'", $errmsg);
             $errmsg = str_replace("<br />", "\\n", $errmsg);
             echo "<script type=\"text/javascript\"> alert('{$errmsg}');  window.history.go(-1); </script>";
             exit;
         }
         // Can only refresh the old parent
         if ($parent_changed) {
             $parent_type = $old_parent_type;
             $parent_entity = $old_parent_entity;
             $parent_id = $old_parent_id;
         } else {
             $parent_id = (int) $attachment->parent_id;
         }
         // Close the iframe and refresh the attachments list in the parent window
         $uri = JFactory::getURI();
         $base_url = $uri->base(true);
         $lang = JRequest::getCmd('lang', '');
         AttachmentsJavascript::closeIframeRefreshAttachments($base_url, $parent_type, $parent_entity, $parent_id, $lang, $from);
         exit;
     }
     $this->setRedirect($link, $msg, $msgType);
 }
Example #5
0
 /**
  * Delete attachment(s)
  */
 public function delete()
 {
     // Check for request forgeries
     JSession::checkToken() or die(JText::_('JINVALID_TOKEN'));
     // Get ready
     $app = JFactory::getApplication();
     jimport('joomla.filesystem.file');
     require_once JPATH_SITE . '/components/com_attachments/helper.php';
     // Get the attachments parent manager
     JPluginHelper::importPlugin('attachments');
     $apm = getAttachmentsPluginManager();
     // Get attachments to remove from the request
     $cid = JRequest::getVar('cid', array(), '', 'array');
     $deleted_ids = array();
     if (count($cid)) {
         $model = $this->getModel('Attachment');
         $attachment = $model->getTable();
         // Loop through the attachments and delete them one-by-one
         foreach ($cid as $attachment_id) {
             // Load the attachment object
             $id = (int) $attachment_id;
             if ($id == 0 or !$attachment->load($id)) {
                 $errmsg = JText::sprintf('ATTACH_ERROR_CANNOT_DELETE_INVALID_ATTACHMENT_ID_N', $id) . ' (ERR 166)';
                 JError::raiseError(500, $errmsg);
             }
             $parent_id = $attachment->parent_id;
             $parent_type = $attachment->parent_type;
             $parent_entity = $attachment->parent_entity;
             // Get the article/parent handler
             JPluginHelper::importPlugin('attachments');
             $apm = getAttachmentsPluginManager();
             if (!$apm->attachmentsPluginInstalled($parent_type)) {
                 $errmsg = JText::sprintf('ATTACH_ERROR_INVALID_PARENT_TYPE_S', $parent_type) . ' (ERR 167)';
                 JError::raiseError(500, $errmsg);
             }
             $parent = $apm->getAttachmentsPlugin($parent_type);
             // If we may not delete it, complain!
             if ($parent->userMayDeleteAttachment($attachment)) {
                 // Delete the actual file
                 if (JFile::exists($attachment->filename_sys)) {
                     JFile::delete($attachment->filename_sys);
                     AttachmentsHelper::clean_directory($attachment->filename_sys);
                 }
                 $deleted_ids[] = $id;
             } else {
                 $parent_entity = $parent->getCanonicalEntityId($parent_entity);
                 $errmsg = JText::sprintf('ATTACH_ERROR_NO_PERMISSION_TO_DELETE_S_ATTACHMENT_S_ID_N', $parent_entity, $attachment->filename, $id);
                 $app->enqueueMessage($errmsg, 'warning');
             }
         }
         // Delete entries in the attachments table for deleted attachments
         if (!empty($deleted_ids)) {
             $db = JFactory::getDBO();
             $query = $db->getQuery(true);
             $query->delete('#__attachments')->where("id IN (" . implode(',', $deleted_ids) . ")");
             $db->setQuery($query);
             if (!$db->query()) {
                 $errmsg = $db->getErrorMsg() . ' (ERR 168)';
                 JError::raiseError(500, $errmsg);
             }
         }
     }
     // Figure out how to redirect
     $from = JRequest::getWord('from');
     $known_froms = array('frontpage', 'article', 'editor', 'closeme');
     if (in_array($from, $known_froms)) {
         // Get the parent info from the last attachment
         $parent_id = $attachment->parent_id;
         $parent_type = $attachment->parent_type;
         $parent_entity = $attachment->parent_entity;
         // Get the article/parent handler
         if (!$apm->attachmentsPluginInstalled($parent_type)) {
             $errmsg = JText::sprintf('ATTACH_ERROR_INVALID_PARENT_TYPE_S', $parent_type) . ' (ERR 169)';
             JError::raiseError(500, $errmsg);
         }
         $parent = $apm->getAttachmentsPlugin($parent_type);
         $parent_entity = $parent->getCanonicalEntityId($parent_entity);
         // Make sure the parent exists
         // NOTE: $parent_id===null means the parent is being created
         if ($parent_id !== null && !$parent->parentExists($parent_id, $parent_entity)) {
             $parent_entity_name = JText::_('ATTACH_' . $parent_entity);
             $errmsg = JText::sprintf('ATTACH_ERROR_CANNOT_DELETE_INVALID_S_ID_N', $parent_entity_name, $parent_id) . ' (ERR 170)';
             JError::raiseError(500, $errmsg);
         }
         // If there is no parent_id, the parent is being created, use the username instead
         if (!$parent_id) {
             $pid = 0;
         } else {
             $pid = (int) $parent_id;
         }
         // Close the iframe and refresh the attachments list in the parent window
         require_once JPATH_SITE . '/components/com_attachments/javascript.php';
         $uri = JFactory::getURI();
         $base_url = $uri->base(true);
         $lang = JRequest::getCmd('lang', '');
         AttachmentsJavascript::closeIframeRefreshAttachments($base_url, $parent_type, $parent_entity, $pid, $lang, $from);
         exit;
     }
     $this->setRedirect('index.php?option=' . $this->option);
 }
Example #6
0
 /**
  * Delete an attachment
  */
 public function delete()
 {
     $db = JFactory::getDBO();
     // Make sure we have a valid attachment ID
     $id = JRequest::getInt('id');
     if (is_numeric($id)) {
         $id = (int) $id;
     } else {
         $errmsg = JText::sprintf('ATTACH_ERROR_CANNOT_DELETE_INVALID_ATTACHMENT_ID_N', $id) . ' (ERR 13)';
         JError::raiseError(500, $errmsg);
     }
     // Get the attachment info
     require_once JPATH_COMPONENT_SITE . '/models/attachment.php';
     $model = new AttachmentsModelAttachment();
     $model->setId($id);
     $attachment = $model->getAttachment();
     if (!$attachment) {
         $errmsg = JText::sprintf('ATTACH_ERROR_CANNOT_DELETE_INVALID_ATTACHMENT_ID_N', $id) . ' (ERR 14)';
         JError::raiseError(500, $errmsg);
     }
     $filename_sys = $attachment->filename_sys;
     $filename = $attachment->filename;
     $parent_id = $attachment->parent_id;
     $parent_type = $attachment->parent_type;
     $parent_entity = $attachment->parent_entity;
     // Get the article/parent handler
     JPluginHelper::importPlugin('attachments');
     $apm = getAttachmentsPluginManager();
     if (!$apm->attachmentsPluginInstalled($parent_type)) {
         $errmsg = JText::sprintf('ATTACH_ERROR_INVALID_PARENT_TYPE_S', $parent_type) . ' (ERR 15)';
         JError::raiseError(500, $errmsg);
     }
     $parent = $apm->getAttachmentsPlugin($parent_type);
     $parent_entity_name = JText::_('ATTACH_' . $parent_entity);
     // Check to make sure we can edit it
     if (!$parent->userMayDeleteAttachment($attachment)) {
         return JError::raiseError(404, JText::_('JERROR_ALERTNOAUTHOR') . ' (ERR 16)');
     }
     // Make sure the parent exists
     // NOTE: $parent_id===null means the parent is being created
     if ($parent_id !== null && !$parent->parentExists($parent_id, $parent_entity)) {
         $errmsg = JText::sprintf('ATTACH_ERROR_CANNOT_DELETE_INVALID_S_ID_N', $parent_entity_name, $parent_id) . ' (ERR 17)';
         JError::raiseError(500, $errmsg);
     }
     // See if this user can edit (or delete) the attachment
     if (!$parent->userMayDeleteAttachment($attachment)) {
         $errmsg = JText::sprintf('ATTACH_ERROR_NO_PERMISSION_TO_DELETE_S', $parent_entity_name) . ' (ERR 18)';
         JError::raiseError(500, $errmsg);
     }
     // First delete the actual attachment files (if any)
     if ($filename_sys) {
         jimport('joomla.filesystem.file');
         if (JFile::exists($filename_sys)) {
             JFile::delete($filename_sys);
         }
     }
     // Delete the entries in the attachments table
     $query = $db->getQuery(true);
     $query->delete('#__attachments')->where('id = ' . (int) $id);
     $db->setQuery($query);
     if (!$db->query()) {
         $errmsg = $db->getErrorMsg() . ' (ERR 19)';
         JError::raiseError(500, $errmsg);
     }
     // Clean up after ourselves
     AttachmentsHelper::clean_directory($filename_sys);
     // Get the Itemid
     $Itemid = JRequest::getInt('Itemid', 1);
     $msg = JText::_('ATTACH_DELETED_ATTACHMENT') . " '{$filename}'";
     // Figure out how to redirect
     $from = JRequest::getWord('from', 'closeme');
     $uri = JFactory::getURI();
     if (in_array($from, $parent->knownFroms())) {
         // If there is no parent_id, the parent is being created, use the username instead
         if (!$parent_id) {
             $pid = 0;
         } else {
             $pid = (int) $parent_id;
         }
         // Close the iframe and refresh the attachments list in the parent window
         $base_url = $uri->root(true);
         $lang = JRequest::getCmd('lang', '');
         AttachmentsJavascript::closeIframeRefreshAttachments($base_url, $parent_type, $parent_entity, $pid, $lang, $from);
         exit;
     } else {
         $redirect_to = $uri->root(true);
     }
     $this->setRedirect($redirect_to, $msg);
 }
Example #7
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);
 }
Example #8
0
 /**
  * Construct the output for the view/template.
  *
  * NOTE: This only constructs the output; it does not display it!
  *		 Use getOutput() to actually display it.
  *
  * @param string $tpl template name (optional)
  *
  * @return if there are no attachments for this article,
  *		   if everything is okay, return true
  *		   if there is an error, return the error code
  */
 public function display($tpl = null)
 {
     jimport('joomla.application.component.helper');
     $document = JFactory::getDocument();
     if (JRequest::getWord('format', '') == 'raw') {
         // Choose raw text even though it is actually html
         $document->setMimeEncoding('text/plain');
     }
     // Add javascript
     $uri = JFactory::getURI();
     AttachmentsJavascript::setupJavascript();
     // Get the model
     $model = $this->getModel('Attachments');
     if (!$model) {
         $errmsg = JText::_('ATTACH_ERROR_UNABLE_TO_FIND_MODEL') . ' (ERR 63)';
         JError::raiseError(500, $errmsg);
     }
     // See if there are any attachments
     $list = $model->getAttachmentsList();
     if (!$list) {
         return null;
     }
     // if we have attachments, add the stylesheets for the attachments list
     JHtml::stylesheet('com_attachments/attachments_list.css', array(), true);
     $lang = JFactory::getLanguage();
     if ($lang->isRTL()) {
         JHtml::stylesheet('com_attachments/attachments_list_rtl.css', array(), true);
     }
     // Add the default path
     $this->addTemplatePath(JPATH_SITE . '/components/com_attachments/views/attachments/tmpl');
     // Set up the correct path for template overloads
     // (Do this after previous addTemplatePath so that template overrides actually override)
     $app = JFactory::getApplication();
     $templateDir = JPATH_SITE . '/templates/' . $app->getTemplate() . '/html/com_attachments/attachments';
     $this->addTemplatePath($templateDir);
     // Load the language files from the attachments plugin
     $lang = JFactory::getLanguage();
     $lang->load('plg_content_attachments', JPATH_SITE . '/plugins/content/attachments');
     // Get the component parameters
     $params = JComponentHelper::getParams('com_attachments');
     // See whether the user-defined fields should be shown
     $from = JRequest::getWord('from', 'closeme');
     $layout = JRequest::getWord('layout');
     $tmpl = JRequest::getWord('tmpl');
     $task = JRequest::getWord('task');
     $show_hidden_user_fields = false;
     if ($app->isAdmin() || $from == 'editor' || $layout == 'edit' || $tmpl == 'component') {
         $show_hidden_user_fields = true;
     }
     if ($task == 'attachmentsList') {
         // Always hide the hidden user fields on Ajax requests
         $show_hidden_user_fields = false;
     }
     // User field 1
     $show_user_field_1 = false;
     $user_field_1_name = $params->get('user_field_1_name');
     if ($user_field_1_name) {
         if ($show_hidden_user_fields || $user_field_1_name[JString::strlen($user_field_1_name) - 1] != '*') {
             $show_user_field_1 = true;
             $this->user_field_1_name = $user_field_1_name;
         }
     }
     $this->show_user_field_1 = $show_user_field_1;
     // User field 2
     $show_user_field_2 = false;
     $user_field_2_name = $params->get('user_field_2_name');
     if ($user_field_2_name) {
         if ($show_hidden_user_fields || $user_field_2_name[JString::strlen($user_field_2_name) - 1] != '*') {
             $show_user_field_2 = true;
             $this->user_field_2_name = $user_field_2_name;
         }
     }
     $this->show_user_field_2 = $show_user_field_2;
     // User field 3
     $show_user_field_3 = false;
     $user_field_3_name = $params->get('user_field_3_name');
     if ($user_field_3_name) {
         if ($show_hidden_user_fields || $user_field_3_name[JString::strlen($user_field_3_name) - 1] != '*') {
             $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 for the template
     $parent_id = $model->getParentId();
     $parent_type = $model->getParentType();
     $parent_entity = JString::strtolower($model->getParentEntity());
     // ?? fix this!
     if ($parent_type == 'com_content' && $parent_entity == 'default') {
         $parent_entity = 'article';
     }
     $this->parent_id = $parent_id;
     $this->parent_type = $parent_type;
     $this->parent_entity = $parent_entity;
     $this->parent_title = $model->getParentTitle();
     $this->parent_entity_name = $model->getParentEntityName();
     $this->some_attachments_visible = $model->someVisible();
     $this->some_attachments_modifiable = $model->someModifiable();
     $this->from = $from;
     $this->list = $list;
     $this->secure = $params->get('secure', false);
     $this->params = $params;
     // Get the display options
     $this->superimpose_link_icons = $params->get('superimpose_url_link_icons', true);
     $this->style = $params->get('attachments_table_style', 'attachmentsList');
     $this->show_column_titles = $params->get('show_column_titles', false);
     $this->show_description = $params->get('show_description', true);
     $this->show_creator_name = $params->get('show_creator_name', false);
     $this->show_file_size = $params->get('show_file_size', true);
     $this->show_downloads = $params->get('show_downloads', false);
     $this->show_created_date = $params->get('show_created_date', false);
     $this->show_modified_date = $params->get('show_modified_date', false);
     $this->file_link_open_mode = $params->get('file_link_open_mode', 'in_same_window');
     // Set up the file/url titleshow_mod_date
     if ($this->show_column_titles) {
         switch ($model->types()) {
             case 'file':
                 $this->file_url_title = JText::_('ATTACH_FILE');
                 break;
             case 'url':
                 $this->file_url_title = JText::_('ATTACH_URL');
                 break;
             default:
                 $this->file_url_title = JText::_('ATTACH_FILE_URL');
         }
     }
     if ($this->show_created_date or $this->show_modified_date) {
         $this->date_format = $params->get('date_format', '%Y-%m-%d %I:%M%P');
     }
     // Get the attachments list title
     $title = $this->title;
     if (!$title || JString::strlen($title) == 0) {
         $title = 'ATTACH_ATTACHMENTS_TITLE';
     }
     $parent = $model->getParentClass();
     $title = $parent->attachmentsListTitle($title, $parent_id, $parent_entity);
     $this->title = $title;
     // Note: assume it is translated
     // Construct the path for the icons
     $uri = JFactory::getURI();
     $base_url = $uri->root(true) . '/';
     $this->base_url = $base_url;
     $this->icon_url_base = $base_url . 'components/com_attachments/media/icons/';
     // Get the output of the template
     $result = $this->loadTemplate($tpl);
     if (JError::isError($result)) {
         return $result;
     }
     return true;
 }
Example #9
0
 /**
  * Validate all URLS in any attachments
  * (See AttachmentsUpdate::reinstall_permissions() in update.php for details )
  */
 public function reinstall_permissions()
 {
     // Access check.
     if (!JFactory::getUser()->authorise('core.admin', 'com_attachments')) {
         return JError::raiseError(404, JText::_('JERROR_ALERTNOAUTHOR') . ' (ERR 159)');
     }
     require_once JPATH_ADMINISTRATOR . '/components/com_attachments/update.php';
     $msg = AttachmentsUpdate::installAttachmentsPermissions();
     if (JRequest::getBool('close')) {
         $this->enqueueSystemMessage($msg);
         // Close this window and refesh the parent window
         AttachmentsJavascript::closeModal();
     } else {
         $this->setRedirect('index.php?option=' . $this->option, $msg);
     }
 }
Example #10
0
 *
 * @copyright Copyright (C) 2007-2015 Jonathan M. Cameron, All Rights Reserved
 * @license http://www.gnu.org/licenses/gpl-3.0.html GNU/GPL
 * @link http://joomlacode.org/gf/project/attachments/frs/
 * @author Jonathan M. Cameron
 */
// No direct access
defined('_JEXEC') or die('Restricted access');
// Load the Attachments helper
require_once JPATH_SITE . '/components/com_attachments/helper.php';
require_once JPATH_SITE . '/components/com_attachments/javascript.php';
// Add the plugins stylesheet to style the list of attachments
$uri = JFactory::getURI();
// Add javascript
AttachmentsJavascript::setupJavascript();
AttachmentsJavascript::setupModalJavascript();
// For convenience
$attachment = $this->attachment;
$params = $this->params;
// Get the parent id and a few other convenience items
$parent_id = $attachment->parent_id;
if ($parent_id === null) {
    $parent_id = 0;
}
// Set up to toggle between uploading file/urls
if ($attachment->uri_type == 'file') {
    $upload_toggle_button_text = JText::_('ATTACH_ENTER_URL_INSTEAD');
    $upload_toggle_url = $this->upload_url_url;
    $upload_button_text = JText::_('ATTACH_UPLOAD_VERB');
} else {
    $upload_toggle_button_text = JText::_('ATTACH_SELECT_FILE_TO_UPLOAD_INSTEAD');
Example #11
0
}
// Format modified date
jimport('joomla.utilities.date');
$tz = new DateTimeZone($user->getParam('timezone', $app->getCfg('offset')));
$mdate = JFactory::getDate($attachment->modified);
$mdate->setTimezone($tz);
$date_format = $params->get('date_format', 'Y-m-d H:i');
$last_modified = $mdate->format($date_format, true);
// If this is an error re-display, display the CSS links directly
$echo_css = $this->error;
/** Load the Attachments helper */
require_once JPATH_SITE . '/components/com_attachments/helper.php';
require_once JPATH_SITE . '/components/com_attachments/javascript.php';
// Add the stylesheets
$uri = JFactory::getURI();
AttachmentsJavascript::setupJavascript();
if ($attachment->uri_type == 'file') {
    $header_msg = JText::sprintf('ATTACH_UPDATE_ATTACHMENT_FILE_S', $filename);
} else {
    $header_msg = JText::sprintf('ATTACH_UPDATE_ATTACHMENT_URL_S', $attachment->url);
}
// If this is an error re-display, display the CSS links directly
if ($this->error) {
    echo $this->startHTML();
}
?>
<div id="uploadAttachmentsPage">
<h1><?php 
echo $header_msg;
?>
</h1>
Example #12
0
 /**
  * Return the HTML for the "Add Attachments" link
  *
  * @param int $parent_id ID of the parent object
  * @param string $parent_entity type of the entity involved
  * @param int $Itemid the menu item id for the display
  * @param string $from where the control should return to
  *
  * @return the HTML for the "Add Attachments" link
  */
 public static function attachmentButtonsHTML($parent_type, $parent_id, $parent_entity, $Itemid, $from)
 {
     AttachmentsJavascript::setupModalJavascript();
     // Generate the HTML for a	button for the user to click to get to a form to add an attachment
     if ($parent_type == 'com_content' && $parent_entity == 'default') {
         $url = "index.php?option=com_attachments&task=upload&article_id={$parent_id}&tmpl=component";
     } else {
         if ($parent_entity != 'default') {
             $parent_type .= ':' . $parent_entity;
         }
         $url = "index.php?option=com_attachments&task=upload" . "&parent_id={$parent_id}&parent_type={$parent_type}&tmpl=component";
     }
     if ($from) {
         // Add a var to give a hint of where to return to
         // $url .= "&from=$from";
         $url .= "&from=closeme";
     }
     $url = JRoute::_($url);
     $add_attachment_txt = JText::_('ATTACH_ADD_ATTACHMENT');
     $icon = JHtml::image('com_attachments/add_attachment.gif', $add_attachment_txt, null, true);
     $ahead = '<a class="modal-button" type="button" href="' . $url . '" ';
     $ahead .= "rel=\"{handler: 'iframe', size: {x: 920, y: 550}}\">";
     $links = $ahead . $icon . "</a>";
     $links .= $ahead . $add_attachment_txt . "</a>";
     return "\n<div class=\"addattach\">{$links}</div>\n";
 }
Example #13
0
 * @license http://www.gnu.org/licenses/gpl-3.0.html GNU/GPL
 * @link http://joomlacode.org/gf/project/attachments/frs/
 * @author Jonathan M. Cameron
 */
// Check to ensure this file is included in Joomla!
defined('_JEXEC') or die;
$template = JFactory::getApplication()->getTemplate();
// Load the tooltip behavior.
JHtml::_('behavior.tooltip');
$uri = JFactory::getURI();
$document = JFactory::getDocument();
/** Load the Attachments helper */
require_once JPATH_SITE . '/components/com_attachments/helper.php';
require_once JPATH_SITE . '/components/com_attachments/javascript.php';
// Add the regular css file
AttachmentsJavascript::setupJavascript(false);
// Hide the vertical scrollbar using javascript
$hide_scrollbar = "window.addEvent('domready', function() {\n\t   document.documentElement.style.overflow = \"hidden\";\n\t   document.body.scroll = \"no\";});";
$document->addScriptDeclaration($hide_scrollbar);
?>
<div class="attachmentsWarning">
	 <h1><?php 
echo $this->warning_title;
?>
</h1>
	 <h2 id="warning_msg"><?php 
echo $this->warning_question;
?>
</h2>
  <form action="<?php 
echo $this->action_url;
Example #14
0
 /**
  * Add Attachment button
  *
  * @param string $name The name of the editor form
  * @param int $asset The asset ID for the entity being edited
  * @param int $authro The ID of the author of the entity
  *
  * @return a button
  */
 public function onDisplay($name, $asset, $author)
 {
     $app = JFactory::getApplication();
     // Avoid displaying the button for anything except for registered parents
     $parent_type = JRequest::getCmd('option');
     if (!$parent_type) {
         return;
     }
     $parent_entity = 'default';
     $editor = 'article';
     // Handle categories specially (since they are really com_content)
     if ($parent_type == 'com_categories') {
         $parent_type = 'com_content';
         $parent_entity = 'category';
         $editor = 'category';
     }
     // Get the parent ID (id or first of cid array)
     //	   NOTE: $parent_id=0 means no id (usually means creating a new entity)
     $cid = JRequest::getVar('cid', array(0), '', 'array');
     $parent_id = 0;
     if (count($cid) > 0) {
         $parent_id = (int) $cid[0];
     }
     if ($parent_id == 0) {
         $a_id = JRequest::getInt('a_id');
         if (!is_null($a_id)) {
             $parent_id = (int) $a_id;
         }
     }
     if ($parent_id == 0) {
         $nid = JRequest::getInt('id');
         if (!is_null($nid)) {
             $parent_id = (int) $nid;
         }
     }
     // Check for the special case where we are creating an article from a category list
     $item_id = JRequest::getInt('Itemid');
     $menu = $app->getMenu();
     $menu_item = $menu->getItem($item_id);
     if ($menu_item and $menu_item->query['view'] == 'category' and empty($a_id)) {
         $parent_entity = 'article';
         $parent_id = NULL;
     }
     // Get the article/parent handler
     JPluginHelper::importPlugin('attachments');
     $apm = getAttachmentsPluginManager();
     if (!$apm->attachmentsPluginInstalled($parent_type)) {
         // Exit if there is no Attachments plugin to handle this parent_type
         return new JObject();
     }
     // Figure out where we are and construct the right link and set
     $uri = JFactory::getURI();
     $base_url = $uri->root(true);
     if ($app->isAdmin()) {
         $base_url = str_replace('/administrator', '', $base_url);
     }
     // Set up the Javascript framework
     require_once JPATH_SITE . '/components/com_attachments/javascript.php';
     AttachmentsJavascript::setupJavascript();
     // Get the parent handler
     $parent = $apm->getAttachmentsPlugin($parent_type);
     $parent_entity = $parent->getCanonicalEntityId($parent_entity);
     if ($parent_id == 0) {
         # Last chance to get the id in extension editors
         $view = JRequest::getWord('view');
         $layout = JRequest::getWord('layout');
         $parent_id = $parent->getParentIdInEditor($parent_entity, $view, $layout);
     }
     // Make sure we have permissions to add attachments to this article or category
     if (!$parent->userMayAddAttachment($parent_id, $parent_entity, $parent_id == 0)) {
         return;
     }
     // Allow remapping of parent ID (eg, for Joomfish)
     if (jimport('attachments_remapper.remapper')) {
         $parent_id = AttachmentsRemapper::remapParentID($parent_id, $parent_type, $parent_entity);
     }
     // Add the regular css file
     JHtml::stylesheet('com_attachments/attachments_list.css', array(), true);
     JHtml::stylesheet('com_attachments/add_attachment_button.css', array(), true);
     // Handle RTL styling (if necessary)
     $lang = JFactory::getLanguage();
     if ($lang->isRTL()) {
         JHtml::stylesheet('com_attachments/attachments_list_rtl.css', array(), true);
         JHtml::stylesheet('com_attachments/add_attachment_button_rtl.css', array(), true);
     }
     // Load the language file from the frontend
     $lang->load('com_attachments', dirname(__FILE__));
     // Create the [Add Attachment] button object
     $button = new JObject();
     $link = $parent->getEntityAddUrl($parent_id, $parent_entity, 'closeme');
     $link .= '&amp;editor=' . $editor;
     // Finalize the [Add Attachment] button info
     $button->set('modal', true);
     $button->set('class', 'btn');
     $button->set('text', JText::_('ATTACH_ADD_ATTACHMENT'));
     if ($app->isAdmin()) {
         $button_name = 'add_attachment';
         if (version_compare(JVERSION, '3.3', 'ge')) {
             $button_name = 'paperclip';
         }
         $button->set('name', $button_name);
     } else {
         // Needed for Joomal 2.5
         $button_name = 'add_attachment_frontend';
         if (version_compare(JVERSION, '3.3', 'ge')) {
             $button_name = 'paperclip';
         }
         $button->set('name', $button_name);
     }
     $button->set('link', $link);
     $button->set('options', "{handler: 'iframe', size: {x: 920, y: 530}}");
     return $button;
 }