diff --git a/attachments_component/site/controllers/attachments.php b/attachments_component/site/controllers/attachments.php index a20b410e..7a496c8b 100644 --- a/attachments_component/site/controllers/attachments.php +++ b/attachments_component/site/controllers/attachments.php @@ -72,7 +72,7 @@ public function display($cachable = false, $urlparams = false) */ public function displayString($parent_id, $parent_type, $parent_entity, $title=null, $show_file_links=true, $allow_edit=true, - $echo=true, $from=null) + $echo=true, $from=null, $attachmentid=null) { $document = JFactory::getDocument(); @@ -95,7 +95,7 @@ public function displayString($parent_id, $parent_type, $parent_entity, $model->setSortOrder($sort_order); // If none of the attachments should be visible, exit now - if ( ! $model->someVisible() ) { + if ( ! $model->someVisible($attachmentid) ) { return false; } diff --git a/attachments_component/site/models/attachments.php b/attachments_component/site/models/attachments.php index b2a8e757..da7ee764 100644 --- a/attachments_component/site/models/attachments.php +++ b/attachments_component/site/models/attachments.php @@ -339,7 +339,7 @@ public function setSortOrder($new_sort_order) * * @return the list of attachments for this parent */ - public function &getAttachmentsList() + public function &getAttachmentsList($attachmentid=null) { // Just return it if it has already been created if ( $this->_list != null ) { @@ -426,6 +426,7 @@ public function &getAttachmentsList() } $query->where('a.parent_type=' . $db->quote($parent_type) . ' AND a.parent_entity=' . $db->quote($parent_entity)); + if ($attachmentid != null) $query->where('a.id = ' . $attachmentid); if ( !$user->authorise('core.admin') ) { $query->where('a.access IN ('.$user_levels.')'); } @@ -500,7 +501,7 @@ public function numAttachments() * * @return true if there are attachments and some should be visible */ - public function someVisible() + public function someVisible($attachmentid=null) { // See if the attachments list has been loaded if ( $this->_list == null ) { @@ -511,7 +512,7 @@ public function someVisible() } // Since the attachments have not been loaded, load them now - $this->getAttachmentsList(); + $this->getAttachmentsList($attachmentid); } return $this->_some_visible; diff --git a/attachments_plugin_framework/attachments_plugin.php b/attachments_plugin_framework/attachments_plugin.php index 0b3ae574..56772920 100644 --- a/attachments_plugin_framework/attachments_plugin.php +++ b/attachments_plugin_framework/attachments_plugin.php @@ -872,16 +872,19 @@ public function insertAttachmentsList(&$content, $parent_id, $parent_entity) $attachments_tag = ''; $attachments_tag_args = ''; $match = false; - if (JString::strpos($content->$text_field_name, '{attachments')) + $offset = -1; + while ($offset != FALSE) { + if ($offset == -1) $offset = 0; + if ($offset = JString::strpos($content->$text_field_name, '{attachments', $offset)) { if (preg_match('@()?{attachments([ ]*:*[^}]+)?}()?@', $content->$text_field_name, $match)) { $attachments_tag = true; } - if (isset($match[1]) && $match[1]) + if (isset($match[2]) && $match[2]) { - $attachments_tag_args_raw = $match[1]; + $attachments_tag_args_raw = $match[2]; $attachments_tag_args = ltrim($attachments_tag_args_raw, ' :'); } @@ -908,7 +911,7 @@ public function insertAttachmentsList(&$content, $parent_id, $parent_entity) // 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); + $attachments_list = $controller->displayString($parent_id, $this->parent_type, $parent_entity, null, true, true, false, $from, $attachments_tag_args); // If the attachments list is empty, insert an empty div for it if ($attachments_list == '') @@ -1007,6 +1010,7 @@ public function insertAttachmentsList(&$content, $parent_id, $parent_entity) } break; } + } // while return $content; }