diff --git a/README.md b/README.md new file mode 100644 index 00000000..10a1137f --- /dev/null +++ b/README.md @@ -0,0 +1,2 @@ +Initial commit - prepare Attachments plugin to work with Joomla 4. + diff --git a/attachments_component/admin/config.xml b/attachments_component/admin/config.xml index a2ecbf96..d26d9b01 100644 --- a/attachments_component/admin/config.xml +++ b/attachments_component/admin/config.xml @@ -65,6 +65,13 @@ + + + + + @@ -224,7 +231,12 @@ label="ATTACH_URL_TO_REGISTER" size="65" description="ATTACH_URL_TO_REGISTER_DESCRIPTION"> - + + + +
show_description ) { $description = htmlspecialchars(stripslashes($attachment->description)); - if ( JString::strlen($description) == 0) + $is_empty = 0; + if ( JString::strlen($description) == 0) { $description = ' '; + $is_empty = 1; + } + if ( $this->show_column_titles ) $html .= "$description"; else - $html .= "[$description]"; + if ($is_empty && $this->params->get('hide_brackets_if_empty')) + $html .= "$description"; + else + $html .= "[$description]"; } // Show the USER DEFINED FIELDs (maybe) if ( $this->show_user_field_1 ) { $user_field = stripslashes($attachment->user_field_1); - if ( JString::strlen($user_field) == 0 ) + $is_empty = 0; + if ( JString::strlen($user_field) == 0 ) { $user_field = ' '; + $is_empty = 1; + } + if ( $this->show_column_titles ) $html .= "" . $user_field . ""; else - $html .= "[" . $user_field . "]"; + if ($is_empty && $this->params->get('hide_brackets_if_empty')) + $html .= "" . $user_field . ""; + else + $html .= "[" . $user_field . "]"; } if ( $this->show_user_field_2 ) { $user_field = stripslashes($attachment->user_field_2); - if ( JString::strlen($user_field) == 0 ) + if ( JString::strlen($user_field) == 0 ) { $user_field = ' '; + $is_empty = 1; + } + if ( $this->show_column_titles ) $html .= "" . $user_field . ""; else - $html .= "[" . $user_field . "]"; + if ($is_empty && $this->params->get('hide_brackets_if_empty')) + $html .= "" . $user_field . ""; + else + $html .= "[" . $user_field . "]"; } if ( $this->show_user_field_3 ) { $user_field = stripslashes($attachment->user_field_3); - if ( JString::strlen($user_field) == 0 ) + $is_empty = 0; + if ( JString::strlen($user_field) == 0 ) { $user_field = ' '; + $is_empty = 1; + } + if ( $this->show_column_titles ) $html .= "" . $user_field . ""; else - $html .= "[" . $user_field . "]"; + if ($is_empty && $this->params->get('hide_brackets_if_empty')) + $html .= "" . $user_field . ""; + else + $html .= "[" . $user_field . "]"; } // Add the creator's username (if requested) diff --git a/attachments_search/attachments.php b/attachments_search/attachments.php index 19816a50..3c69a604 100644 --- a/attachments_search/attachments.php +++ b/attachments_search/attachments.php @@ -169,7 +169,10 @@ public function onContentSearch($text, $phrase='', $ordering='', $areas=null) // Construct and execute the query $query = $db->getQuery(true); - $query->select('*')->from('#__attachments AS a'); + if ($attachParams->get('alternative_search_results', 0)) + $query->select('a.*, c.alias, c.catid')->from('#__attachments AS a')->join('LEFT', '#__content AS c ON a.parent_id = c.id'); + else + $query->select('*')->from('#__attachments AS a'); $query->where("( $where ) AND a.state = 1"); if ( !$user->authorise('core.admin') ) { $query->where('a.access in ('.$user_levels.')'); @@ -273,8 +276,26 @@ public function onContentSearch($text, $phrase='', $ordering='', $areas=null) $parent_title = JText::_($parent->getTitle($attachment->parent_id, $parent_entity)); - $attachment->section = JText::sprintf('ATTACH_ATTACHED_TO_PARENT_S_TITLE_S', + if ($attachParams->get('alternative_search_results', 0)) + $attachment->section = ''; + else + $attachment->section = JText::sprintf('ATTACH_ATTACHED_TO_PARENT_S_TITLE_S', $parent_entity_name, $parent_title); + + if ($attachParams->get('alternative_search_results', 0)) { + + $url = ''; + switch($attachment->parent_entity) { + case 'category': + $url = ContentHelperRoute::getCategoryRoute($attachment->catid.':'.$attachment->alias); + break; + default: // case 'article': + $url = ContentHelperRoute::getArticleRoute( $attachment->parent_id.':'.$attachment->alias, $attachment->catid); + } + $attachment->href = $url; + $attachment->title = $attachment->parent_title; + + } $results[$k] = $attachment; $k++;