Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
7 changes: 6 additions & 1 deletion attachments_component/admin/src/Model/AttachmentsModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public function __construct($config = array())
if (empty($config['filter_fields'])) {
$config['filter_fields'] = array(
'id',
'parent_id',
'a.state',
'a.access',
'a.filename',
Expand Down Expand Up @@ -80,7 +81,11 @@ protected function getListQuery()
/** @var \Joomla\Database\DatabaseDriver $db */
$db = Factory::getContainer()->get('DatabaseDriver');
$query = $db->getQuery(true);

$id = $this->getState('filter.parent_id');
if (is_numeric($id))
{
$query->where('a.parent_id = ' . (int) $id);
}
$query->select('a.*, a.id as id');
$query->from('#__attachments as a');

Expand Down
26 changes: 24 additions & 2 deletions attachments_component/admin/src/View/Attachments/HtmlView.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use JMCameron\Component\Attachments\Administrator\Helper\AttachmentsPermissions;
use JMCameron\Component\Attachments\Site\Helper\AttachmentsDefines;
use JMCameron\Plugin\AttachmentsPluginFramework\AttachmentsPluginManager;
use JMCameron\Component\Attachments\Administrator\Model\AttachmentsModel;
use Joomla\CMS\Component\ComponentHelper;
use Joomla\CMS\Factory;
use Joomla\CMS\HTML\HTMLHelper;
Expand Down Expand Up @@ -52,10 +53,18 @@ public function display($tpl = null)
return;
}

$app = Factory::getApplication();
$jinput = $app->getInput();
$this->editor = $jinput->getString('editor', null);
$id = $jinput->getInt('parent_id', null);
if ($id) {
$model = $this->getModel();
$model->setState('filter.parent_id', $id);
}
$this->items = $this->get('Items');
$this->state = $this->get('State');
$this->pagination = $this->get('Pagination');

// Check for errors.
if (count($errors = $this->get('Errors'))) {
throw new \Exception(implode("\n", $errors) . ' (ERR 175)', 500);
Expand Down Expand Up @@ -166,9 +175,22 @@ public function display($tpl = null)
}

// Set the toolbar
$this->addToolBar();
if ( !$this->editor ) {
$this->addToolBar();
}

// Display the attachments
if ( $this->editor ) {
$document = Factory::getDocument();
HTMLHelper::_('jquery.framework');
$document->addScriptDeclaration('function insertAttachmentsIdToken($, editorName) {
let editor = parent.Joomla.editors.instances[editorName];
var adminform = document.getElementById("adminForm");
var Data = new FormData(adminform);
editor.replaceSelection("{attachmentsid id=" + Data.getAll("cid[]") +"}");
Comment thread
parapente marked this conversation as resolved.
Outdated
$(".btn-close", parent.document).click();
}');
}
parent::display($tpl);
}

Expand Down
17 changes: 16 additions & 1 deletion attachments_component/admin/tmpl/attachments/default.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@
use Joomla\CMS\Factory;
use Joomla\CMS\HTML\HTMLHelper;
use Joomla\CMS\Router\Route;
use Joomla\CMS\Language\Text;
use Joomla\CMS\Uri\Uri;


// No direct access
defined('_JEXEC') or die('Restricted access');

Expand All @@ -31,7 +33,14 @@

?>
<form action="<?php echo Route::_('index.php?option=com_attachments'); ?>" method="post" name="adminForm" id="adminForm">
<?php echo $this->loadTemplate('filter');?>
<?php if ( $this->editor ) : ?>
<button onclick="insertAttachmentsIdToken(jQuery, '<?php echo $this->editor ?>');"><?php echo "{attachmentid id=xx,yy}"; ?></button>
Comment thread
parapente marked this conversation as resolved.
Outdated
<?php endif; ?>
<?php
if (!$this->editor ) {
echo $this->loadTemplate('filter');
}
?>
<table class="adminlist" id="attachmentsList">
<thead><?php echo $this->loadTemplate('head');?></thead>
<tbody><?php echo $this->loadTemplate('body');?></tbody>
Expand All @@ -44,5 +53,11 @@
<input type="hidden" name="filter_order_Dir" value="<?php echo $listDirn; ?>" />
<?php echo HTMLHelper::_('form.token'); ?>
</div>

</form>
<script>
Comment thread
parapente marked this conversation as resolved.
Outdated
$(document).ready(function() {
alert("ici");
})};
</script>

14 changes: 11 additions & 3 deletions attachments_component/admin/tmpl/attachments/default_body.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,14 @@
?>
<tr class="<?php echo "row$k"; ?>">
<td class="at_checked hidden-phone"><?php echo $checked; ?></td>
<?php if ( !$this->editor ) : ?>
<td class="at_published" align="center"><?php echo $published;?></td>
<?php endif; ?>
<td class="at_filename">
<a href="<?php echo $link; ?>" title="<?php echo $edit_attachment_title; ?>"
><?php echo HTMLHelper::image('com_attachments/file_icons/'.$icon, $download_verb, null, true);
<?php if ( !$this->editor ) : ?>
<a href="<?php echo $link; ?>" title="<?php echo $edit_attachment_title; ?>" >
<?php endif; ?>
<?php echo HTMLHelper::image('com_attachments/file_icons/'.$icon, $download_verb, null, true);
if ( ($item->uri_type == 'url') && $superimpose_link_icons ) {
if ( $item->url_valid ) {
echo HTMLHelper::image('com_attachments/file_icons/link_arrow.png', '', 'class="link_overlay"', true);
Expand All @@ -127,7 +131,11 @@
echo HTMLHelper::image('com_attachments/file_icons/link_broken.png', '', 'class="link_overlay"', true);
}
}
?></a>&nbsp;<a
?>
<?php if ( !$this->editor ) : ?>
</a>
<?php endif; ?>
&nbsp;<a
href="<?php echo $link; ?>" title="<?php echo $edit_attachment_title; ?>"
><?php if ( $item->uri_type == 'file' ) {
echo $item->filename;
Expand Down
2 changes: 2 additions & 0 deletions attachments_component/admin/tmpl/attachments/default_head.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,10 @@
<th class="at_checked hidden-phone">
<input type="checkbox" name="checkall-toggle" value="" onclick="Joomla.checkAll(this)" />
</th>
<?php if ( !$this->editor ) : ?>
<th class="at_published" width="5%" nowrap="nowrap"><?php echo HTMLHelper::_('grid.sort', 'ATTACH_PUBLISHED',
'a.state', $listDirn, $listOrder ) ?></th>
<?php endif; ?>
<th class="at_filename"><?php echo HTMLHelper::_('grid.sort', 'ATTACH_ATTACHMENT_FILENAME_URL',
'a.filename', $listDirn, $listOrder ) ?></th>
<th class="at_description"><?php echo HTMLHelper::_('grid.sort', 'ATTACH_DESCRIPTION',
Expand Down
18 changes: 13 additions & 5 deletions attachments_component/site/src/Model/AttachmentsModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,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 ) {
Expand All @@ -349,6 +349,10 @@ public function &getAttachmentsList()
$parent_id = $this->getParentId();
$parent_type = $this->getParentType();
$parent_entity = $this->getParentEntity();

Comment thread
parapente marked this conversation as resolved.
if ($attachmentid) {
$parent_id = '%';
}

// Use parent entity corresponding to values saved in the attachments table
$parent = $this->getParentClass();
Expand Down Expand Up @@ -387,15 +391,19 @@ public function &getAttachmentsList()
$query = $db->getQuery(true);
$query->select('a.*, u.name as creator_name')->from('#__attachments AS a');
$query->leftJoin('#__users AS u ON u.id = a.created_by');

if ($attachmentid != null) {
$query->where('a.id in (' . $attachmentid . ')' );
}
if ( $parent_id == 0 ) {
// If the parent ID is zero, the parent is being created so we have
// do the query differently
$user_id = $user->get('id');
$query->where('a.parent_id IS NULL AND u.id=' . (int)$user_id);
}
else {
$query->where('a.parent_id='.(int)$parent_id);
if ($parent_id != '%') {
$query->where('a.parent_id LIKE "'.(int)$parent_id . '"');
}

// Handle the state part of the query
if ( $user->authorise('core.edit.state', 'com_attachments') ) {
Expand Down Expand Up @@ -497,7 +505,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 ) {
Expand All @@ -508,7 +516,7 @@ public function someVisible()
}

// Since the attachments have not been loaded, load them now
$this->getAttachmentsList();
$this->getAttachmentsList($attachmentid);
}

return $this->_some_visible;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="utf-8"?>
<extension type="plugin" group="editors-xtd" version="4.0" method="upgrade">
<name>plg_editors-xtd_insert_attachments_id_token_btn</name>
<version>4.0.4</version>
<creationDate>November 9, 2024</creationDate>
<author>Jonathan M. Cameron</author>
<copyright>(C) 2007-2024 Jonathan M. Cameron. All rights reserved.</copyright>
<license>http://www.gnu.org/licenses/gpl-3.0.html GNU/GPL</license>
<authorEmail>jmcameron@jmcameron.net</authorEmail>
<authorUrl>https://github.com/jmcameron/attachments/</authorUrl>
<description>ATTACH_INSERT_ATTACHMENTSID_TOKEN_BUTTON_PLUGIN_DESCRIPTION</description>
<namespace path="src">JMCameron\Plugin\EditorsXtd\InsertAttachmentsIdToken</namespace>
<files>
<folder>src</folder>
<folder plugin="insert_attachments_id_token">services</folder>
</files>
<languages>
<language tag="en-GB">language/en-GB/en-GB.plg_editors-xtd_insert_attachmentsid_token.ini</language>
Comment thread
parapente marked this conversation as resolved.
Outdated
<language tag="en-GB">language/en-GB/en-GB.plg_editors-xtd_insert_attachmentsid_token.sys.ini</language>
<language tag="fr-FR">language/fr-FR/fr-FR.plg_editors-xtd_insert_attachmentsid_token.ini</language>
<language tag="fr-FR">language/fr-FR/fr-FR.plg_editors-xtd_insert_attachmentsid_token.sys.ini</language>
</languages>
</extension>
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
; en-GB.plg_editors-xtd_add_attachment.ini
; Attachments for Joomla! extension
; Copyright (C) 2007-2018 Jonathan M. Cameron, All rights reserved.
; License http://www.gnu.org/licenses/gpl-3.0.html GNU/GPL
; Note : All ini files need to be saved as UTF-8 - No BOM

; English translation

; NOTE TO TRANSLATORS:
; Do not translate the '{attachments}' part of any of the right-hand
; strings below! It must appear exactly as '{attachments}' in the
; article/parent text in order for the substitutions to work correctly in
; 'custom placement' mode.!

INSERT_ATTACHMENTS_ID_TOKEN="Insert {attachments id=xxx} token"
INSERT_ATTACHMENTS_ID_TOKEN_DESCRIPTION="Place the cursor in the location where you want the attachments list to display (in the front end) and then click on this button. This inserts the {attachments} token that the 'Custom Placement' option uses. Some HTML is also added to hide the token when attachments lists are not shown."
ATTACH_INSERT_ATTACHMENTS_ID_TOKEN_BUTTON_PLUGIN_DESCRIPTION="The insert attachments token plugin adds a button that allows you to insert an {attachments id=xxx} custom placement token while editing articles or categories."
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
; en-GB.plg_editors-xtd_add_attachment.sys.ini
; Attachments for Joomla! extension
; Copyright (C) 2007-2018 Jonathan M. Cameron, All rights reserved.
; License http://www.gnu.org/licenses/gpl-3.0.html GNU/GPL
; Note : All ini files need to be saved as UTF-8 - No BOM

; English translation

; NOTE TO TRANSLATORS:
; Do not translate the '{attachments}' part of any of the right-hand
; strings below! It must appear exactly as '{attachments}' in the
; article/parent text in order for the substitutions to work correctly in
; 'custom placement' mode.!

ATTACH_INSERT_ATTACHMENTSID_TOKEN_BUTTON_PLUGIN_DESCRIPTION="The insert attachments token plugin adds a button that allows you to insert an {attachments} custom placement token while editing articles or categories."
PLG_EDITORS-XTD_INSERT_ATTACHMENTSID_TOKEN_BTN="Editor Button - Insert Attachments Token"
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
; fr-FR.plg_editors-xtd_add_attachment.ini
; Attachments for Joomla! extension
; Copyright (C) 2007-2018 Jonathan M. Cameron, All rights reserved.
; License http://www.gnu.org/licenses/gpl-3.0.html GNU/GPL
; Note : All ini files need to be saved as UTF-8 - No BOM

; French translation by: Marc-André Ladouceur (2.0), Pascal Adalian and Sylvain Faivre

; NOTE TO TRANSLATORS:
; Do not translate the '{attachments}' part of any of the right-hand
; strings below! It must appear exactly as '{attachments}' in the
; article/parent text in order for the substitutions to work correctly in
; 'custom placement' mode.!

ATTACH_ATTACHMENTS_ID_TOKEN="Inserer le symbole {attachments id=xxx}"
ATTACH_ATTACHMENTS_ID_TOKEN_DESCRIPTION="Placer le curseur à l'endroit où vous voulez la liste des pièces jointes à afficher (dans le front-end) et ensuite cliquez sur ce bouton. Ceci insert le symbole {attachments} qui utilise l'option 'Emplacement personnalisé'. Un peu de HTML est aussi ajouté pour cacher le symbole quand les listes de pièces jointes ne sont pas affichées."
ATTACH_INSERT_ATTACHMENTS_ID_TOKEN_BUTTON_PLUGIN_DESCRIPTION="Ajoute un bouton qui vous permet d'insérer un symbole d'emplacement personnalisé {attachments id=xxx} pendant la modification."
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
; fr-FR.plg_editors-xtd_add_attachment.sys.ini
; Attachments for Joomla! extension
; Copyright (C) 2007-2018 Jonathan M. Cameron, All rights reserved.
; License http://www.gnu.org/licenses/gpl-3.0.html GNU/GPL
; Note : All ini files need to be saved as UTF-8 - No BOM

; French translation by: Marc-André Ladouceur (2.0), Pascal Adalian and Sylvain Faivre

; NOTE TO TRANSLATORS:
; Do not translate the '{attachments}' part of any of the right-hand
; strings below! It must appear exactly as '{attachments}' in the
; article/parent text in order for the substitutions to work correctly in
; 'custom placement' mode.!

ATTACH_INSERT_ATTACHMENTS_ID_TOKEN_BUTTON_PLUGIN_DESCRIPTION="Ajoute un bouton qui vous permet d'insérer un symbole d'emplacement personnalisé {attachments id=xxx} pendant la modification."
PLG_EDITORS-XTD_INSERT_ATTACHMENTS_ID_TOKEN_BTN="Bouton Editer - Insére un symbole Pièces jointes (id)"
39 changes: 39 additions & 0 deletions insert_attachments_id_token_btn_plugin/services/provider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

\defined('_JEXEC') or die;

use Joomla\CMS\Extension\PluginInterface;
use Joomla\CMS\Factory;
use Joomla\CMS\Plugin\PluginHelper;
use Joomla\DI\Container;
use Joomla\DI\ServiceProviderInterface;
use Joomla\Event\DispatcherInterface;
use JMCameron\Plugin\EditorsXtd\InsertAttachmentsIdToken\Extension\InsertAttachmentsIdToken;

return new class () implements ServiceProviderInterface {
/**
* Registers the service provider with a DI container.
*
* @param Container $container The DI container.
*
* @return void
*
* @since 4.3.0
*/
public function register(Container $container)
{
$container->set(
PluginInterface::class,
function (Container $container) {
$dispatcher = $container->get(DispatcherInterface::class);
$plugin = new InsertAttachmentsIdToken(
$dispatcher,
(array) PluginHelper::getPlugin('editors-xtd', 'insert_attachments_id_token')
);
$plugin->setApplication(Factory::getApplication());

return $plugin;
}
);
}
};
Loading