/**
  * 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);
         }
     }
 }
Esempio n. 2
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;
 }
Esempio 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();
 }
Esempio n. 4
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;
 }
Esempio n. 5
0
 * @subpackage Attachments_Component
 *
 * @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 {
Esempio n. 6
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;
Esempio n. 7
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;
 }