コード例 #1
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;
 }
コード例 #2
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 .= '&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;
 }
コード例 #3
0
ファイル: controller.php プロジェクト: appukonrad/attachments
 /**
  * Return the attachments list as HTML (for use by Ajax)
  */
 public function attachmentsList()
 {
     $parent_id = JRequest::getInt('parent_id', false);
     $parent_type = JRequest::getWord('parent_type', '');
     $parent_entity = JRequest::getWord('parent_entity', 'default');
     $show_links = JRequest::getBool('show_links', true);
     $allow_edit = JRequest::getBool('allow_edit', true);
     $from = JRequest::getWord('from', 'closeme');
     $title = '';
     $response = '';
     if ($parent_id === false || $parent_type == '') {
         return '';
     }
     // Allow remapping of parent ID (eg, for Joomfish)
     $lang = JRequest::getWord('lang', '');
     if ($lang and jimport('attachments_remapper.remapper')) {
         $parent_id = AttachmentsRemapper::remapParentID($parent_id, $parent_type, $parent_entity);
     }
     require_once JPATH_SITE . '/components/com_attachments/controllers/attachments.php';
     $controller = new AttachmentsControllerAttachments();
     $response = $controller->displayString($parent_id, $parent_type, $parent_entity, $title, $show_links, $allow_edit, false, $from);
     echo $response;
 }
コード例 #4
0
 /**
  * Inserts the attachments list above the row of xtd-buttons
  *
  * And in older versions, inserts the attachments list for category
  * descriptions.
  *
  * @access	public
  * @since	1.5
  */
 public function onAfterRender()
 {
     $task = JRequest::getCmd('task');
     $view = JRequest::getCmd('view');
     $layout = JRequest::getWord('layout');
     // Make sure this we should handle this
     $parent_type = JRequest::getCMD('option');
     if (!$parent_type) {
         return;
     }
     // Handle the special case of Global Config for Attachments 3.x
     if (version_compare(JVERSION, '3.0', 'ge')) {
         if ($parent_type == 'com_config' and $task == '' and $view == '') {
             // Force use of the Attachments options editor
             // option=com_config&view=component&component=com_attachments
             $body = JResponse::getBody();
             $body = str_replace('option=com_config&view=component&component=com_attachments', 'option=com_attachments&task=params.edit', $body);
             JResponse::setBody($body);
         }
     }
     // Handle attachments
     $parent_entity = 'default';
     // Handle categories specially (since they are really com_content)
     if ($parent_type == 'com_categories') {
         $parent_type = 'com_content';
         $parent_entity = 'category';
     }
     // Get the article/parent handler
     if (!JPluginHelper::importPlugin('attachments')) {
         // Exit if the framework does not exist (eg, during uninstallaton)
         return false;
     }
     if (!function_exists('getAttachmentsPluginManager')) {
         // Exit if the function does not exist (eg, during uninstallaton)
         return false;
     }
     $apm = getAttachmentsPluginManager();
     if (!$apm->attachmentsPluginInstalled($parent_type)) {
         // Exit if there is no Attachments plugin to handle this parent_type
         return false;
     }
     $parent = $apm->getAttachmentsPlugin($parent_type);
     // Get the parent ID
     $parent_entity = $parent->getCanonicalEntityId($parent_entity);
     $parent_id = $parent->getParentIdInEditor($parent_entity, $view, $layout);
     // Exit if we do not have an parent (exiting or being created)
     if ($parent_id === false) {
         return;
     }
     // See if this type of content suports displaying attachments in its editor
     if ($parent->showAttachmentsInEditor($parent_entity, $view, $layout)) {
         // Get the article/parent handler
         $user_can_add = $parent->userMayAddAttachment($parent_id, $parent_entity);
         // Allow remapping of parent ID (eg, for Joomfish)
         if (jimport('attachments_remapper.remapper')) {
             $parent_id = AttachmentsRemapper::remapParentID($parent_id, $parent_type, $parent_entity);
         }
         // Force the ID to zero when creating the entity
         if (!$parent_id) {
             $parent_id = 0;
         }
         // Construct the attachment list
         $Itemid = JRequest::getInt('Itemid', 1);
         $from = 'editor';
         $attachments = AttachmentsHelper::attachmentsListHTML($parent_id, $parent_type, $parent_entity, $user_can_add, $Itemid, $from, false, true);
         // If the attachments list is empty, insert an empty div for it
         if ($attachments == '') {
             jimport('joomla.application.component.helper');
             $params = JComponentHelper::getParams('com_attachments');
             $class_name = $params->get('attachments_table_style', 'attachmentsList');
             $div_id = 'attachmentsList' . '_' . $parent_type . '_' . $parent_entity . '_' . (string) $parent_id;
             $attachments = "\n<div class=\"{$class_name}\" id=\"{$div_id}\"></div>\n";
         }
         // Insert the attachments above the editor buttons
         // NOTE: Assume that anyone editing the article can see its attachments
         $body = $parent->insertAttachmentsListInEditor($parent_id, $parent_entity, $attachments, JResponse::getBody());
         JResponse::setBody($body);
     } elseif ($parent_id && $view == 'category') {
         // Only dislay this in the front end
         $app = JFactory::getApplication();
         if ($app->isAdmin()) {
             return;
         }
         // More recent versions of Joomla allow this to be handled better
         // by the normal Attachments onContentPrepare callback
         if (version_compare(JVERSION, '3.1', 'ge') or version_compare(JVERSION, '2.5.10', 'ge') and version_compare(JVERSION, '3.0', 'lt')) {
             return;
         }
         // Display attachments lists for category descriptions
         $parent_entity = 'category';
         // Add the refresh Javascript
         $uri = JFactory::getURI();
         $base_url = $uri->root(true);
         $doc = JFactory::getDocument();
         // Allow remapping of parent ID (eg, for Joomfish)
         if (jimport('attachments_remapper.remapper')) {
             $parent_id = AttachmentsRemapper::remapParentID($parent_id, $parent_type, $parent_entity);
         }
         // Figure out if the attachments list should be visible for this category
         jimport('joomla.application.component.helper');
         $params = JComponentHelper::getParams('com_attachments');
         $always_show_category_attachments = $params->get('always_show_category_attachments', false);
         $all_but_article_views = $params->get('hide_except_article_views', false);
         if ($all_but_article_views && !$always_show_category_attachments) {
             return;
         }
         // Construct the attachment list
         $Itemid = JRequest::getInt('Itemid', 1);
         $from = 'frontpage';
         $user_can_add = $parent->userMayAddAttachment($parent_id, $parent_entity);
         $attachments = AttachmentsHelper::attachmentsListHTML($parent_id, $parent_type, $parent_entity, $user_can_add, $Itemid, $from, true, $user_can_add);
         // If the attachments list is empty, insert an empty div for it
         if ($attachments == '') {
             jimport('joomla.application.component.helper');
             $class_name = $params->get('attachments_table_style', 'attachmentsList');
             $div_id = 'attachmentsList' . '_' . $parent_type . '_' . $parent_entity . '_' . (string) $parent_id;
             $attachments = "\n<div class=\"{$class_name}\" id=\"{$div_id}\"></div>\n";
         }
         // Insert the attachments after the category description
         $reptag = '<div class="clr"></div>';
         $body = JResponse::getBody();
         $body = str_replace($reptag, $attachments . $reptag, $body);
         JResponse::setBody($body);
     }
 }