/** * 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; }
/** Insert the attachments list into the content text (for front end) * * @param object &$content the text of the content item (eg, article text) * @param int $parent_id the ID for the parent object * @param string $parent_entity the type of entity for this parent type * * @return string the modified content text (false for failure) */ public function insertAttachmentsList(&$content, $parent_id, $parent_entity) { $aparams = $this->attachmentsParams(); // Get the desired placement $attachments_placement = $aparams->get('attachments_placement', 'end'); if ($attachments_placement == 'disabled_nofilter') { return false; } // Determine where we are $from = JRequest::getCmd('view', 'closeme'); $Itemid = JRequest::getInt('Itemid', 1); // See whether we can display the links to add attachments $user_can_add = $this->userMayAddAttachment($parent_id, $parent_entity); // Get the field name for the content item's text $text_field_name = $this->getTextFieldName($content, $parent_entity); if ($text_field_name === null) { return false; } // Get the attachments tag, if present $attachments_tag = ''; $attachments_tag_args = ''; $match = false; if (JString::strpos($content->{$text_field_name}, '{attachments')) { if (preg_match('@(<span class="hide_attachments_token">)?{attachments([ ]*:*[^}]+)?}(</span>)?@', $content->{$text_field_name}, $match)) { $attachments_tag = true; } if (isset($match[1]) && $match[1]) { $attachments_tag_args_raw = $match[1]; $attachments_tag_args = ltrim($attachments_tag_args_raw, ' :'); } if ($attachments_tag) { $attachments_tag = $match[0]; } } // Check the security status $attach_dir = JPATH_SITE . '/' . AttachmentsDefines::$ATTACHMENTS_SUBDIR; $secure = $aparams->get('secure', false); $hta_filename = $attach_dir . '/ . htaccess'; if ($secure && !file_exists($hta_filename) || !$secure && file_exists($hta_filename)) { AttachmentsHelper::setup_upload_directory($attach_dir, $secure); } // Construct the attachment list (if appropriate) $html = ''; $attachments_list = false; $add_attachement_btn = false; // Get the html for the attachments list require_once JPATH_SITE . '/components/com_attachments/controllers/attachments.php'; $controller = new AttachmentsControllerAttachments(); $attachments_list = $controller->displayString($parent_id, $this->parent_type, $parent_entity, null, true, true, false, $from); // If the attachments list is empty, insert an empty div for it if ($attachments_list == '') { $class_name = $aparams->get('attachments_table_style', 'attachmentsList'); $div_id = 'attachmentsList' . '_' . $this->parent_type . '_' . $parent_entity . '_' . (string) $parent_id; $attachments_list = "\n<div class=\"{$class_name}\" id=\"{$div_id}\"></div>\n"; } $html .= $attachments_list; if ($html || $user_can_add) { // Add the style sheet JHtml::stylesheet('com_attachments/attachments_list.css', array(), true); // Handle RTL styling (if necessary) $lang = JFactory::getLanguage(); if ($lang->isRTL()) { JHtml::stylesheet('com_attachments/attachments_list_rtl.css', array(), true); } } // Construct the add-attachments button, if appropriate $hide_add_attachments_link = $aparams->get('hide_add_attachments_link', 0); if ($user_can_add && !$hide_add_attachments_link) { $add_attachments_btn = AttachmentsHelper::attachmentButtonsHTML($this->parent_type, $parent_id, $parent_entity, $Itemid, $from); $html .= $add_attachments_btn; } // Wrap both list and the Add Attachments button in another div if ($html) { $html = "<div class=\"attachmentsContainer\">\n" . $html . "\n</div>"; } // Finally, add the attachments // NOTE: Hope str_replace() below is UTF8 safe (since the token being replaced is UTF8)... switch ($attachments_placement) { case 'beginning': // Put the attachments list at the beginning if ($attachments_list || $user_can_add) { if ($attachments_tag) { $content->{$text_field_name} = $html . $content->{$text_field_name}; } else { $content->{$text_field_name} = $html . str_replace($attachments_tag, '', $content->{$text_field_name}); } } break; case 'custom': // Insert the attachments at the desired location if ($attachments_list || $user_can_add) { if ($attachments_tag) { $content->{$text_field_name} = str_replace($attachments_tag, $html, $content->{$text_field_name}); } else { // If there is no tag, insert the attachments at the end $content->{$text_field_name} .= $html; } } break; case 'disabled_filter': // Disable and strip out any attachments tags if ($attachments_tag) { $content->{$text_field_name} = str_replace($attachments_tag, '', $content->{$text_field_name}); } break; default: // Add the attachments to the end if ($attachments_list || $user_can_add) { if ($attachments_tag) { $content->{$text_field_name} = str_replace($attachments_tag, '', $content->{$text_field_name}) . $html; } else { $content->{$text_field_name} .= $html; } } break; } return $content; }
" /> <span class="right"> <input type="button" name="cancel" value="<?php echo JText::_('ATTACH_CANCEL'); ?> " onClick="window.parent.SqueezeBox.close();" /> </span> </div> </form> <?php // Display the auto-publish warning, if appropriate if (!$params->get('publish_default', false) && !$this->may_publish) { $msg = $params->get('auto_publish_warning', ''); if (JString::strlen($msg) == 0) { $msg = JText::_('ATTACH_WARNING_ADMIN_MUST_PUBLISH'); } else { $msg = JText::_($msg); } echo "<h2>{$msg}</h2>"; } // Show the existing attachments (if any) if ($parent_id || $parent_id === 0) { require_once JPATH_SITE . '/components/com_attachments/controllers/attachments.php'; $controller = new AttachmentsControllerAttachments(); $controller->displayString($parent_id, $attachment->parent_type, $attachment->parent_entity, 'ATTACH_EXISTING_ATTACHMENTS', false, false, true, $this->from); } echo "</div>"; if ($this->error) { echo $this->endHTML(); }
/** * Construct and return the attachments list (as HTML) * * @param int $parent_id the id of the parent * @param string $parent_type the type of the parent (usually $option) * @param string $parent_entity the parent entity * @param bool $user_can_add true if the user can add attachments to this parent * @param int $Itemid the system item id (for menus) * @param string $from a token indicating where to return to * @param bool $show_file_links true if the files should be shown as links * @param bool $allow_edit true if the user can edit/delete attachments for this parent * * @return the html as a string */ public static function attachmentsListHTML($parent_id, $parent_type, $parent_entity, $user_can_add, $Itemid, $from, $show_file_links = true, $allow_edit = true) { $app = JFactory::getApplication(); $user = JFactory::getUser(); $user_levels = implode(',', array_unique($user->getAuthorisedViewLevels())); // Make sure there are some potentially accessible attachments for // this parent before proceeding. Note that this check is not as // careful as the check in the Attachments model which is used by // the 'Attachments' view which is invoked below. $alist = ''; $db = JFactory::getDBO(); $query = $db->getQuery(true); $query->select('count(*)')->from('#__attachments'); $query->where('((parent_id=' . (int) $parent_id . ') OR (parent_id is NULL))' . ' AND parent_type=' . $db->quote($parent_type) . ' AND parent_entity=' . $db->quote($parent_entity)); if (!$user->authorise('core.admin')) { $query->where('access in (' . $user_levels . ')'); } $db->setQuery($query); $total = $db->loadResult(); if ($db->getErrorNum()) { $errmsg = $db->stderr() . ' (ERR 47)'; JError::raiseError(500, $errmsg); } // Generate the HTML for the attachments for the specified parent if ($total > 0) { // Get the component parameters jimport('joomla.application.component.helper'); $params = JComponentHelper::getParams('com_attachments'); // Check the security status $attach_dir = JPATH_SITE . '/' . AttachmentsDefines::$ATTACHMENTS_SUBDIR; $secure = $params->get('secure', false); $hta_filename = $attach_dir . '/.htaccess'; if ($secure && !file_exists($hta_filename) || !$secure && file_exists($hta_filename)) { require_once JPATH_SITE . '/components/com_attachments/helper.php'; AttachmentsHelper::setup_upload_directory($attach_dir, $secure); } if ($app->isAdmin()) { // Get the html for the attachments list require_once JPATH_ADMINISTRATOR . '/components/com_attachments/controllers/list.php'; $controller = new AttachmentsControllerList(); $alist = $controller->displayString($parent_id, $parent_type, $parent_entity, null, $show_file_links, $allow_edit, false, $from); } else { // Get the html for the attachments list require_once JPATH_SITE . '/components/com_attachments/controllers/attachments.php'; $controller = new AttachmentsControllerAttachments(); $alist = $controller->displayString($parent_id, $parent_type, $parent_entity, null, $show_file_links, $allow_edit, false, $from); } } return $alist; }