tutto cho che serve attachments

This commit is contained in:
2025-01-01 12:22:03 +01:00
parent d6f07ccdb2
commit 934dd6bf52
210 changed files with 5186 additions and 0 deletions

View File

@ -0,0 +1,424 @@
<?php
/**
* Attachments plugin for inserting attachments lists into content
*
* @package Attachments
* @subpackage Main_Attachments_Plugin
*
* @author Jonathan M. Cameron <jmcameron@jmcameron.net>
* @copyright Copyright (C) 2007-2018 Jonathan M. Cameron, All Rights Reserved
* @license http://www.gnu.org/licenses/gpl-3.0.html GNU/GPL
* @link http://joomlacode.org/gf/project/attachments/frs/
*/
defined('_JEXEC') or die('Restricted access');
/** Load the Attachments defines (if available) */
if (file_exists(JPATH_SITE . '/components/com_attachments/defines.php'))
{
require_once JPATH_SITE . '/components/com_attachments/defines.php';
require_once(JPATH_SITE . '/components/com_attachments/helper.php');
require_once(JPATH_SITE . '/components/com_attachments/javascript.php');
}
else
{
// Exit quietly if the attachments component has been uninstalled or deleted
return;
}
/**
* Attachments plugin
*
* @package Attachments
* @since 1.3.4
*/
class plgContentAttachments extends JPlugin
{
/**
* Constructor
*
* @param object &$subject The object to observe
* @param array $config An array that holds the plugin configuration
*
* @access protected
*/
public function __construct(&$subject, $config)
{
parent::__construct($subject, $config);
// Save this page's URL
$uri= JFactory::getURI();
$return = '&return=' . urlencode(base64_encode(JUri::current() . '?' . $uri->getQuery()));
$app = JFactory::getApplication();
$app->setUserState('com_attachments.current_url', $return);
$this->loadLanguage();
}
/**
* The content plugin that inserts the attachments list into content items
*
* @param string The context of the content being passed to the plugin.
* @param &object &$row the content object (eg, article) being displayed
* @param &object &$params the parameters
* @param int $page the 'page' number
*
* @return true if anything has been inserted into the content object
*/
public function onContentPrepare($context, &$row, &$params, $page = 0)
{
// Enable the following four diagnostic lines to see if a component uses onContentPrepare
// $msg = "<br/>onContentPrepare: CONTEXT: $context, OBJ: " . get_class($row) . ", VIEW: " . JRequest::getCmd('view');
// if (isset($row->text)) $row->text .= $msg;
// if (isset($row->introtext)) $row->introtext .= $msg;
// return;
// Set the parent info from the context
if (strpos($context, '.') === false)
{
// Assume the context is the parent_type
$parent_type = $context;
$parent_entity = 'default';
}
else
{
list ($parent_type, $parent_entity) = explode('.', $context, 2);
}
// This callback handles everything but articles
if ( $parent_type == 'com_content' )
{
if (in_array($parent_entity, Array('featured', 'article'))) {
return false;
}
if ($parent_entity == 'category.title') {
// Do not add attachments to categtory titles (Joomla 3 only)
return false;
}
if (($parent_entity == 'category') AND (isset($row->catid))) {
// Ignore the callback for articles on category blogs
if (version_compare(JVERSION, '3.4.0', 'lt')) {
return false;
}
}
$parent_entity = 'category';
// Older versions of Joomla do not deal well with category lists and
// it is necessary to use the show_attachments callback to display
// category descriptions in those cases.
if (version_compare(JVERSION, '2.5.10', 'lt') OR
(version_compare(JVERSION, '3.0', 'ge') AND version_compare(JVERSION, '3.1', 'lt'))) {
return false;
}
}
$view = JRequest::getCmd('view');
$layout = JRequest::getCmd('layout');
if ( ($parent_type == 'mod_custom') AND ($parent_entity == 'content') AND ($view == 'category') )
{
// Do not add attachments to categtory titles (Joomla 3.4+)
return false;
}
// Handle category blog articles specially
if (($context == 'com_content.category') AND ($view == 'category') AND ($layout == 'blog')) {
if (isset($row->id) and is_numeric($row->id)) {
$parent_entity = 'article';
}
}
if (version_compare(JVERSION, '3.7.0'))
{
# Ignore this for Joomla 3.7.0+ (seems to be new and category attachments are handled ok without it)
if ($context == 'com_content.categories')
return false;
}
// Get the article/parent handler
JPluginHelper::importPlugin('attachments');
$apm = getAttachmentsPluginManager();
if ( !$apm->attachmentsPluginInstalled($parent_type) ) {
// Exit quietly if there is no Attachments plugin to handle this parent_type
return false;
}
$parent = $apm->getAttachmentsPlugin($parent_type);
// If this attachments plugin is disabled, skip it
if ( ! $apm->attachmentsPluginEnabled($parent_type) ) {
return false;
}
// Get the parent ID
$parent_id = null;
if (isset($row->id) and is_numeric($row->id))
{
// If the $row has 'id', just use it
$parent_id = (int)$row->id;
}
else if ($parent_entity == 'category')
{
$db = JFactory::getDBO();
$description = $row->text;
$query = $db->getQuery(true);
$query->select('id')->from('#__categories');
$query->where('description=' . $db->quote($description));
$db->setQuery($query, 0, 1);
$result = $db->loadResult();
if ($result) {
$parent_id = (int)$result;
}
}
// Let the attachment pluging try to figure out the id
if ( $parent_id === null )
{
$parent_id = $parent->getParentId($row);
}
if ( $parent_id === null )
{
return false;
}
// Load the language
$lang = JFactory::getLanguage();
$lang->load('plg_content_attachments', dirname(__FILE__));
// Set up the refresh behavior
AttachmentsJavascript::setupJavascript();
// Always include the hide rule (since it may be needed to hide the custom tags)
JHtml::stylesheet('com_attachments/attachments_hide.css', Array(), true);
// Allow remapping of parent ID (eg, for Joomfish)
if (jimport('attachments_remapper.remapper'))
{
$parent_id = AttachmentsRemapper::remapParentID($parent_id, $parent_type, $parent_entity);
}
// Exit if we should not display attachments for this parent
if ( $parent->attachmentsHiddenForParent($row, $parent_id, $parent_entity) ) {
return false;
}
// Get the component parameters
jimport('joomla.application.component.helper');
$attachParams = JComponentHelper::getParams('com_attachments');
// Make sure we should be showing the category attachments
$always_show_category_attachments = $attachParams->get('always_show_category_attachments', false);
$all_but_article_views = $attachParams->get('hide_except_article_views', false);
if ( $all_but_article_views && !$always_show_category_attachments ) {
return false;
}
// Add the attachments list
$parent->insertAttachmentsList($row, $parent_id, $parent_entity);
// FOR DEBUGGING
// if (isset($row->text)) $row->text .= " [AP text CONTEXT($context) PE($parent_entity) ]";
// if (isset($row->introtext)) $row->introtext .= " [AP introtext CONTEXT($context) PE($parent_entity)]";
return true;
}
/**
* The content plugin that inserts the attachments list into content items
*
* @param string $context the context of the content being passed to the plugin.
* @param &object &$row the content object (eg, article) being displayed
* @param &object &$params the parameters
* @param int $page the 'page' number
*
* @return true if anything has been inserted into the content object
*/
public function onContentBeforeDisplay($context, &$row, &$params, $page = 0)
{
$view = JRequest::getCmd('view');
$layout = JRequest::getCmd('layout');
if (($context == 'com_content.category') AND ($view == 'category') AND ($layout == 'blog')) {
// Use onContentPrepare for category blog articles for Joomla 3.4+
if (version_compare(JVERSION, '3.4', 'ge')) {
return false;
}
}
// Set the parent info from the context
if (strpos($context, '.') === false)
{
// Assume the context is the parent_type
$parent_type = $context;
$parent_entity = '';
}
else
{
list ($parent_type, $parent_entity) = explode('.', $context, 2);
}
// ??? Do we need to filter to ensure only articles use this callback?
// Load the language
$lang = JFactory::getLanguage();
$lang->load('plg_content_attachments', dirname(__FILE__));
// Add the refresh javascript
AttachmentsJavascript::setupJavascript();
// Always include the hide rule (since it may be needed to hide the custom tags)
JHtml::stylesheet('com_attachments/attachments_hide.css', array(), true);
// Get the article/parent handler
JPluginHelper::importPlugin('attachments');
$apm = getAttachmentsPluginManager();
if (!$apm->attachmentsPluginInstalled($parent_type))
{
// Exit quietly if there is no Attachments plugin to handle this parent_type
return false;
}
$parent = $apm->getAttachmentsPlugin($parent_type);
// If this attachments plugin is disabled, skip it
if (!$apm->attachmentsPluginEnabled($parent_type))
{
return false;
}
// Figure out the parent entity
$parent_entity = $parent->determineParentEntity($row);
if (!$parent_entity)
{
return false;
}
// Get the parent ID
$parent_id = null;
if (isset( $row->id ) && ($row->id > 0)) {
$parent_id = (int) $row->id;
} else {
$parent_id = $parent->getParentId($row);
}
// Exit if there is no parent
if ($parent_id === false)
{
return false;
}
// Allow remapping of parent ID (eg, for Joomfish)
if (jimport('attachments_remapper.remapper'))
{
$parent_id = AttachmentsRemapper::remapParentID($parent_id, $parent_type, $parent_entity);
}
// Exit if we should not display attachments for this parent
if ($parent->attachmentsHiddenForParent($row, $parent_id, $parent_entity))
{
return false;
}
// Add the attachments list
$parent->insertAttachmentsList($row, $parent_id, $parent_entity);
// ??? if (isset($row->text)) $row->text .= " [OCBD text $context]";
// ??? if (isset($row->introtext)) $row->introtext .= " [OCBD introtext $context]";
return;
}
/**
* Set the parent_id for all attachments that were added to this
* content before it was saved the first time.
*
* This method is called right after the content is saved.
*
* @param string The context of the content being passed to the plugin.
* @param object $item A JTableContent object
* @param bool $isNew If the content is newly created
*
* @return void
*/
function onContentAfterSave($context, $item, $isNew )
{
if ( !$isNew ) {
// If the item is not new, this step is not needed
return true;
}
$ctxinfo = explode('.', $context);
$parent_type = $ctxinfo[0];
$parent_entity = $ctxinfo[1];
// Special handling for categories
if ( $parent_type == 'com_categories' ) {
$parent_type = 'com_content';
}
// Get the attachments associated with this newly created item.
// NOTE: We assume that all attachments that have parent_id=null
// and are created by the current user are for this item.
$user = JFactory::getUser();
$user_id = $user->get('id');
$db = JFactory::getDBO();
$query = $db->getQuery(true);
$query->select('*')->from('#__attachments');
$query->where('created_by=' . (int) $user_id . ' AND parent_id IS NULL');
$db->setQuery($query);
$attachments = $db->loadObjectList();
if ( $db->getErrorNum() ) {
$errmsg = $db->stderr() . ' (ERR 200)';
JError::raiseError(500, $errmsg);
}
// Exit if there are no new attachments
if ( count($attachments) == 0 ) {
return true;
}
// Change the attachment to the new content item!
JTable::addIncludePath(JPATH_ADMINISTRATOR.'/components/com_attachments/tables');
$atrow = JTable::getInstance('Attachment', 'AttachmentsTable');
foreach ($attachments as $attachment) {
// Fix for odd issue; on some systems, something is changing the
// parent_type in or out of the database
if ( ($attachment->parent_type) == 'com_media' AND
($attachment->parent_entity) == 'article' ) {
// Override/fix the incorrect parent type
$attachment->parent_type = 'com_content';
}
// Change the filename/URL as necessary
$error_msg = AttachmentsHelper::switch_parent($attachment, null, $item->id);
if ( $error_msg != '' ) {
$errmsg = JText::_($error_msg) . ' (ERR 201)';
JError::raiseError(500, $errmsg);
}
// Update the parent info
$atrow->load($attachment->id);
$atrow->parent_id = $item->id;
$atrow->parent_type = $parent_type;
$atrow->filename_sys = $attachment->filename_sys;
$atrow->url = $attachment->url;
if ( !$atrow->store() ) {
$errmsg = $attachment->getError() . ' (ERR 202)';
JError::raiseError(500, $errmsg);
}
}
return true;
}
}

View File

@ -0,0 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<extension type="plugin" group="content" version="2.5" method="upgrade">
<name>plg_content_attachments</name>
<version>3.2.6</version>
<creationDate>March 26, 2018</creationDate>
<author>Jonathan M. Cameron</author>
<authorEmail>jmcameron@jmcameron.net</authorEmail>
<authorUrl>http://joomlacode.org/gf/project/attachments/</authorUrl>
<copyright>(C) 2007-2018 Jonathan M. Cameron. All rights reserved.</copyright>
<license>http://www.gnu.org/licenses/gpl-3.0.html GNU/GPL</license>
<description>ATTACH_ATTACHMENTS_PLUGIN_DESCRIPTION</description>
<scriptfile>install.php</scriptfile>
<files>
<filename plugin="attachments">attachments.php</filename>
<filename>index.html</filename>
<folder>language</folder>
</files>
</extension>

View File

@ -0,0 +1 @@
<html><body bgcolor="#FFFFFF"></body></html>

View File

@ -0,0 +1,61 @@
<?php
/**
* Attachments plugin installation script
*
* @package Attachments
* @subpackage Attachments_Plugin
*
* @author Jonathan M. Cameron
* @copyright Copyright (C) 2014-2018 Jonathan M. Cameron
* @license http://www.gnu.org/licenses/gpl-3.0.html GNU/GPL
* @link http://joomlacode.org/gf/project/attachments/frs/
*/
// No direct access
defined('_JEXEC') or die('Restricted access');
/**
* The attachments content plugin installation class
*
* @package Attachments
*/
class plgContentAttachmentsInstallerScript
{
/**
* Attachments plugin uninstall function
*
* @param $parent : the installer parent
*/
public function uninstall($parent)
{
// List all the Attachments plugins
$plugins = Array('plg_content_attachments',
'plg_search_attachments',
'plg_attachments_plugin_framework',
'plg_attachments_for_content',
'plg_editors-xtd_add_attachment_btn',
'plg_editors-xtd_insert_attachments_token_btn',
'plg_system_show_attachments_in_editor',
'plg_quickicon_attachments'
);
// To be safe, disable ALL attachments plugins first!
foreach ($plugins as $plugin_name)
{
// Make the query to enable the plugin
$db = JFactory::getDBO();
$query = $db->getQuery(true);
$query->update('#__extensions')
->set("enabled = 0")
->where('type=' . $db->quote('plugin') . ' AND name=' . $db->quote($plugin_name));
$db->setQuery($query);
$db->query();
// NOTE: Do NOT complain if there was an error
// (in case any plugin is already uninstalled and this query fails)
}
}
}

View File

@ -0,0 +1,31 @@
; en-GB.plg_frontend_attachments.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
; Just for the front end display
ATTACH_ACCESS_THIS_URL_S="Access this URL (%s)"
ATTACH_ADD_ATTACHMENT="Add attachment"
ATTACH_ATTACHMENTS="Attachments"
ATTACH_ATTACHMENTS_PLUGIN_DESCRIPTION="Attachments plugin: Displays a list of the attachments for article (or supported content item),"
ATTACH_ATTACHMENTS_TITLE="Attachments:"
ATTACH_CREATED="Created"
ATTACH_CREATOR="Creator"
ATTACH_DELETE_THIS_FILE="Delete this file"
ATTACH_DESCRIPTION="Description"
ATTACH_DOWNLOADS="Downloads"
ATTACH_DOWNLOAD_NOUN="Download"
ATTACH_DOWNLOAD_THIS_FILE_S="Download this file (%s)"
ATTACH_EXISTING_ATTACHMENTS="Existing&nbsp;Attachments:"
ATTACH_FILE="File"
ATTACH_FILE_SIZE="File size"
ATTACH_FILE_URL="File / URL"
ATTACH_S_KB="%s kB"
ATTACH_LAST_MODIFIED="Last modified"
ATTACH_REALLY_DELETE_ATTACHMENT="Really delete attachment?"
ATTACH_UPDATE_THIS_FILE="Update this file"
ATTACH_URL="URL"

View File

@ -0,0 +1,12 @@
; en-GB.plg_content_attachments.sys.ini
; Attachments for Joomla! extension
; Copyright (C) 2009-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
; For the plugin manager
ATTACH_ATTACHMENTS_PLUGIN_DESCRIPTION="Attachments plugin: Displays a list of the attachments for article (or supported content item),"
PLG_CONTENT_ATTACHMENTS="Content - Attachments"

View File

@ -0,0 +1 @@
<html><body bgcolor="#FFFFFF"></body></html>

View File

@ -0,0 +1 @@
<html><body bgcolor="#FFFFFF"></body></html>

View File

@ -0,0 +1 @@
<html><body bgcolor="#FFFFFF"></body></html>

View File

@ -0,0 +1,30 @@
; it-IT.plg_frontend_attachments.ini
; Attachments for Joomla! extension
; Copyright (C) 2007-2013 Jonathan M. Cameron, All rights reserved.
; License GNU GPL 3: http://www.gnu.org/licenses/gpl-3.0.html
; Note : All ini files need to be saved as UTF-8 - No BOM
; Italian translation by: Piero Mattirolo (2.0, 3.0), Lemminkainen (version 1.3.4)
; Just for the front end display
ATTACH_ACCESS_THIS_URL_S="Accedi a questo URL (%s)"
ATTACH_ADD_ATTACHMENT="Aggiungi Allegato"
ATTACH_ATTACHMENTS="Allegati"
ATTACH_ATTACHMENTS_PLUGIN_DESCRIPTION="Allegati: questo plugin mostrerà una lista degli allegati disponibili per ciascun articolo (o elemento di contenuto supportato), "
ATTACH_ATTACHMENTS_TITLE="Allegati:"
ATTACH_CREATED="Creato"
ATTACH_CREATOR="Autore"
ATTACH_DELETE_THIS_FILE="Cancella questo file"
ATTACH_DESCRIPTION="Descrizione"
ATTACH_DOWNLOADS="Downloads"
ATTACH_DOWNLOAD_NOUN="Download"
ATTACH_DOWNLOAD_THIS_FILE_S="Scarica questo file (%s)"
ATTACH_EXISTING_ATTACHMENTS="Allegati Esistenti"
ATTACH_FILE="File"
ATTACH_FILE_SIZE="Dimensione del File"
ATTACH_FILE_URL="File / URL"
ATTACH_LAST_MODIFIED="Modificato il"
ATTACH_REALLY_DELETE_ATTACHMENT="Confermi la cancellazione dell'allegato?"
ATTACH_UPDATE_THIS_FILE="Aggiorna questo file"
ATTACH_URL="URL:"

View File

@ -0,0 +1,12 @@
; it-IT.plg_content_attachments.sys.ini
; Attachments for Joomla! extension
; Copyright (C) 2009-2013 Jonathan M. Cameron, All rights reserved.
; License GNU GPL 3: http://www.gnu.org/licenses/gpl-3.0.html
; Note : All ini files need to be saved as UTF-8 - No BOM
; Italian translation by: Piero Mattirolo (2.0, 3.0), Lemminkainen (version 1.3.4)
; For the plugin manager
ATTACH_ATTACHMENTS_PLUGIN_DESCRIPTION="Plugin allegati: visualizza una lista degli allegati per ogni articolo (o elemento di contenuto supportato),"
PLG_CONTENT_ATTACHMENTS="Contenuto - Allegati"