Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Initial commit - prepare Attachments plugin to work with Joomla 4.

14 changes: 13 additions & 1 deletion attachments_component/admin/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,13 @@
<option value="1">JYES</option>
<option value="0">JNO</option>
</field>
<field name="hide_brackets_if_empty" type="radio" default="0" class="btn-group"
label="ATTACH_HIDE_BRACKETS_IF_EMPTY"
description="ATTACH_HIDE_BRACKETS_IF_EMPTY_DESCRIPTION">
<option value="1">JYES</option>
<option value="0">JNO</option>
</field>

<field name="show_creator_name" type="radio" default="0" class="btn-group"
label="ATTACH_SHOW_ATTACHMENT_CREATOR"
description="ATTACH_SHOW_ATTACHMENT_CREATOR_DESCRIPTION">
Expand Down Expand Up @@ -224,7 +231,12 @@
label="ATTACH_URL_TO_REGISTER" size="65"
description="ATTACH_URL_TO_REGISTER_DESCRIPTION">
</field>

<field name="alternative_search_results" type="radio" default="0" class="btn-group"
label="ATTACH_ALTERNATIVE_SEARCH_RESULTS"
description="ATTACH_ALTERNATIVE_SEARCH_RESULTS_DESC">
<option value="1">JYES</option>
<option value="0">JNO</option>
</field>
</fieldset>

<fieldset name="security"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -378,3 +378,8 @@ COM_ATTACHMENTS_N_ITEMS_PUBLISHED="%d Attachments successfully published"
COM_ATTACHMENTS_N_ITEMS_PUBLISHED_1="Attachment successfully published"
COM_ATTACHMENTS_N_ITEMS_UNPUBLISHED="%d Attachments successfully unpublished"
COM_ATTACHMENTS_N_ITEMS_UNPUBLISHED_1="Attachment successfully unpublished"

ATTACH_ALTERNATIVE_SEARCH_RESULTS="Alternative search results format"
ATTACH_ALTERNATIVE_SEARCH_RESULTS_DESC="Switch to alternative search results format for searching attachments - create links to content to which attachment is connected, keep attachment detail information in result"
ATTACH_HIDE_BRACKETS_IF_EMPTY="Hide brackets when empty"
ATTACH_HIDE_BRACKETS_IF_EMPTY_DESCRIPTION="Hide brackets when there is no value in 'description' or user defined fields"
43 changes: 35 additions & 8 deletions attachments_component/site/views/attachments/tmpl/default.php
Original file line number Diff line number Diff line change
Expand Up @@ -222,41 +222,68 @@
// Add description (maybe)
if ( $this->show_description ) {
$description = htmlspecialchars(stripslashes($attachment->description));
if ( JString::strlen($description) == 0)
$is_empty = 0;
if ( JString::strlen($description) == 0) {
$description = '&nbsp;';
$is_empty = 1;
}

if ( $this->show_column_titles )
$html .= "<td class=\"at_description\">$description</td>";
else
$html .= "<td class=\"at_description\">[$description]</td>";
if ($is_empty && $this->params->get('hide_brackets_if_empty'))
$html .= "<td class=\"at_description\">$description</td>";
else
$html .= "<td class=\"at_description\">[$description]</td>";
}

// 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 = '&nbsp;';
$is_empty = 1;
}

if ( $this->show_column_titles )
$html .= "<td class=\"at_user_field\">" . $user_field . "</td>";
else
$html .= "<td class=\"at_user_field\">[" . $user_field . "]</td>";
if ($is_empty && $this->params->get('hide_brackets_if_empty'))
$html .= "<td class=\"at_user_field\">" . $user_field . "</td>";
else
$html .= "<td class=\"at_user_field\">[" . $user_field . "]</td>";
}
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 = '&nbsp;';
$is_empty = 1;
}

if ( $this->show_column_titles )
$html .= "<td class=\"at_user_field\">" . $user_field . "</td>";
else
$html .= "<td class=\"at_user_field\">[" . $user_field . "]</td>";
if ($is_empty && $this->params->get('hide_brackets_if_empty'))
$html .= "<td class=\"at_user_field\">" . $user_field . "</td>";
else
$html .= "<td class=\"at_user_field\">[" . $user_field . "]</td>";
}
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 = '&nbsp;';
$is_empty = 1;
}

if ( $this->show_column_titles )
$html .= "<td class=\"at_user_field\">" . $user_field . "</td>";
else
$html .= "<td class=\"at_user_field\">[" . $user_field . "]</td>";
if ($is_empty && $this->params->get('hide_brackets_if_empty'))
$html .= "<td class=\"at_user_field\">" . $user_field . "</td>";
else
$html .= "<td class=\"at_user_field\">[" . $user_field . "]</td>";
}

// Add the creator's username (if requested)
Expand Down
25 changes: 23 additions & 2 deletions attachments_search/attachments.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.')');
Expand Down Expand Up @@ -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++;
Expand Down