primo commit

This commit is contained in:
2024-12-17 17:34:10 +01:00
commit e650f8df99
16435 changed files with 2451012 additions and 0 deletions

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,325 @@
<?php
/**
* Attachments component attachments controller
*
* @package Attachments
* @subpackage Attachments_Component
*
* @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/
* @author Jonathan M. Cameron
*/
// No direct access to this file
defined('_JEXEC') or die('Restricted access');
// import Joomla controlleradmin library
jimport('joomla.application.component.controlleradmin');
/**
* Attachments Controller
*
* @package Attachments
*/
class AttachmentsControllerAttachments extends JControllerAdmin
{
/**
* Method to get a model object, loading it if required.
*
* @param string The model name. Optional.
* @param string The class prefix. Optional.
* @param array Configuration array for model. Optional.
*
* @return object The model.
*/
public function getModel($name = 'Attachments', $prefix = 'AttachmentsModel', $config = array())
{
$model = parent::getModel($name, $prefix, array('ignore_request' => true));
return $model;
}
/**
* Display the attachments list
*
* @param int $parent_id the id of the parent
* @param string $parent_type the type of parent
* @param string $parent_entity the type entity of the parent
* @param string $title title to be shown above the list of articles. If null, use system defaults.
* @param bool $show_file_links enable showing links for the filenames
* @param bool $allow_edit enable showing edit/delete links (if permissions are okay)
* @param bool $echo if true the output will be echoed; otherwise the results are returned.
* @param string $from The 'from' info
*
* @return the string (if $echo is false)
*/
public function displayString($parent_id, $parent_type, $parent_entity,
$title=null, $show_file_links=true, $allow_edit=true,
$echo=true, $from=null)
{
$document = JFactory::getDocument();
// Get an instance of the model
$this->addModelPath(JPATH_SITE.'/components/com_attachments/models');
$model = $this->getModel('Attachments');
if ( !$model ) {
$errmsg = JText::_('ATTACH_ERROR_UNABLE_TO_FIND_MODEL') . ' (ERR 164)';
JError::raiseError(500, $errmsg);
}
$model->setParentId($parent_id, $parent_type, $parent_entity);
// Get the component parameters
jimport('joomla.application.component.helper');
$params = JComponentHelper::getParams('com_attachments');
// Set up to list the attachments for this artticle
$sort_order = $params->get('sort_order', 'filename');
$model->setSortOrder($sort_order);
// If none of the attachments should be visible, exit now
if ( ! $model->someVisible() ) {
return false;
}
// Get the view
$this->addViewPath(JPATH_SITE.'/components/com_attachments/views');
$viewType = $document->getType();
$view = $this->getView('Attachments', $viewType);
if ( !$view ) {
$errmsg = JText::_('ATTACH_ERROR_UNABLE_TO_FIND_VIEW') . ' (ERR 165)';
JError::raiseError(500, $errmsg);
}
$view->setModel($model);
// Construct the update URL template
$update_url = "index.php?option=com_attachments&task=edit&cid[]=%d";
$update_url .= "&from=$from&tmpl=component";
$view->update_url = $update_url;
// Construct the delete URL template
$delete_url = "index.php?option=com_attachments&task=attachment.delete_warning&id=%d";
$delete_url .= "&parent_type=$parent_type&parent_entity=$parent_entity&parent_id=" . (int)$parent_id;
$delete_url .= "&from=$from&tmpl=component";
$view->delete_url = $delete_url;
// Set some display settings
$view->title = $title;
$view->show_file_links = $show_file_links;
$view->allow_edit = $allow_edit;
$view->from = $from;
// Get the view to generate the display output from the template
if ( $view->display() === true ) {
// Display or return the results
if ( $echo ) {
echo $view->getOutput();
}
else {
return $view->getOutput();
}
}
return false;
}
/**
* Delete attachment(s)
*/
public function delete()
{
// Check for request forgeries
JSession::checkToken() or die(JText::_('JINVALID_TOKEN'));
// Get ready
$app = JFactory::getApplication();
jimport('joomla.filesystem.file');
require_once(JPATH_SITE.'/components/com_attachments/helper.php');
// Get the attachments parent manager
JPluginHelper::importPlugin('attachments');
$apm = getAttachmentsPluginManager();
// Get attachments to remove from the request
$cid = JRequest::getVar('cid', array(), '', 'array');
$deleted_ids = Array();
if (count($cid))
{
$model = $this->getModel('Attachment');
$attachment = $model->getTable();
// Loop through the attachments and delete them one-by-one
foreach ($cid as $attachment_id)
{
// Load the attachment object
$id = (int)$attachment_id;
if ( ($id == 0) OR !$attachment->load($id) ) {
$errmsg = JText::sprintf('ATTACH_ERROR_CANNOT_DELETE_INVALID_ATTACHMENT_ID_N', $id) . ' (ERR 166)';
JError::raiseError(500, $errmsg);
}
$parent_id = $attachment->parent_id;
$parent_type = $attachment->parent_type;
$parent_entity = $attachment->parent_entity;
// Get the article/parent handler
JPluginHelper::importPlugin('attachments');
$apm = getAttachmentsPluginManager();
if ( !$apm->attachmentsPluginInstalled($parent_type) ) {
$errmsg = JText::sprintf('ATTACH_ERROR_INVALID_PARENT_TYPE_S', $parent_type) . ' (ERR 167)';
JError::raiseError(500, $errmsg);
}
$parent = $apm->getAttachmentsPlugin($parent_type);
// If we may not delete it, complain!
if ( $parent->userMayDeleteAttachment($attachment) )
{
// Delete the actual file
if ( JFile::exists($attachment->filename_sys) )
{
JFile::delete($attachment->filename_sys);
AttachmentsHelper::clean_directory($attachment->filename_sys);
}
$deleted_ids[] = $id;
}
else
{
$parent_entity = $parent->getCanonicalEntityId($parent_entity);
$errmsg = JText::sprintf('ATTACH_ERROR_NO_PERMISSION_TO_DELETE_S_ATTACHMENT_S_ID_N',
$parent_entity, $attachment->filename, $id);
$app->enqueueMessage($errmsg, 'warning');
}
}
// Delete entries in the attachments table for deleted attachments
if (!empty($deleted_ids))
{
$db = JFactory::getDBO();
$query = $db->getQuery(true);
$query->delete('#__attachments')->where("id IN (".implode(',', $deleted_ids).")");
$db->setQuery($query);
if (!$db->query()) {
$errmsg = $db->getErrorMsg() . ' (ERR 168)';
JError::raiseError(500, $errmsg);
}
}
}
// Figure out how to redirect
$from = JRequest::getWord('from');
$known_froms = array('frontpage', 'article', 'editor', 'closeme');
if ( in_array( $from, $known_froms ) )
{
// Get the parent info from the last attachment
$parent_id = $attachment->parent_id;
$parent_type = $attachment->parent_type;
$parent_entity = $attachment->parent_entity;
// Get the article/parent handler
if ( !$apm->attachmentsPluginInstalled($parent_type) ) {
$errmsg = JText::sprintf('ATTACH_ERROR_INVALID_PARENT_TYPE_S', $parent_type) . ' (ERR 169)';
JError::raiseError(500, $errmsg);
}
$parent = $apm->getAttachmentsPlugin($parent_type);
$parent_entity = $parent->getCanonicalEntityId($parent_entity);
// Make sure the parent exists
// NOTE: $parent_id===null means the parent is being created
if ( ($parent_id !== null) && !$parent->parentExists($parent_id, $parent_entity) ) {
$parent_entity_name = JText::_('ATTACH_' . $parent_entity);
$errmsg = JText::sprintf('ATTACH_ERROR_CANNOT_DELETE_INVALID_S_ID_N',
$parent_entity_name, $parent_id) . ' (ERR 170)';
JError::raiseError(500, $errmsg);
}
// If there is no parent_id, the parent is being created, use the username instead
if ( !$parent_id ) {
$pid = 0;
}
else {
$pid = (int)$parent_id;
}
// Close the iframe and refresh the attachments list in the parent window
require_once(JPATH_SITE.'/components/com_attachments/javascript.php');
$uri = JFactory::getURI();
$base_url = $uri->base(true);
$lang = JRequest::getCmd('lang', '');
AttachmentsJavascript::closeIframeRefreshAttachments($base_url, $parent_type, $parent_entity, $pid, $lang, $from);
exit();
}
$this->setRedirect( 'index.php?option=' . $this->option);
}
/**
* Method to publish a list of items
* (Adapted from JControllerAdmin)
*
* @return void
*
* @since 11.1
*/
public function publish()
{
// Check for request forgeries
JSession::checkToken() or die(JText::_('JINVALID_TOKEN'));
// Get items to publish from the request.
$cid = JRequest::getVar('cid', array(), '', 'array');
$data = array('publish' => 1, 'unpublish' => 0, 'archive' => 2, 'trash' => -2, 'report' => -3);
$task = $this->getTask();
$value = JArrayHelper::getValue($data, $task, 0, 'int');
if (empty($cid))
{
JError::raiseError(500, JText::_($this->text_prefix . '_NO_ITEM_SELECTED'));
}
else
{
// Get the model.
$model = $this->getModel();
// Make sure the item ids are integers
JArrayHelper::toInteger($cid);
// Publish the items.
$att_published = $model->publish($cid, $value);
if (($att_published == false) OR ($att_published == 0))
{
JError::raiseError(500, $model->getError());
}
else
{
if ($value == 1)
{
$ntext = $this->text_prefix . '_N_ITEMS_PUBLISHED';
}
elseif ($value == 0)
{
$ntext = $this->text_prefix . '_N_ITEMS_UNPUBLISHED';
}
elseif ($value == 2)
{
$ntext = $this->text_prefix . '_N_ITEMS_ARCHIVED';
}
else
{
$ntext = $this->text_prefix . '_N_ITEMS_TRASHED';
}
$this->setMessage(JText::plural($ntext, $att_published));
}
}
$extension = JRequest::getCmd('extension');
$extensionURL = ($extension) ? '&extension=' . JRequest::getCmd('extension') : '';
$this->setRedirect(JRoute::_('index.php?option=' . $this->option . '&view=' . $this->view_list . $extensionURL, false));
}
}

View File

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

View File

@ -0,0 +1,132 @@
<?php
/**
* Attachments component
*
* @package Attachments
* @subpackage Attachments_Component
*
* @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/
* @author Jonathan M. Cameron
*/
defined('_JEXEC') or die('Restricted access');
/** Define the legacy classes, if necessary */
require_once(JPATH_SITE.'/components/com_attachments/legacy/controller.php');
/**
* Class for a controller for dealing with lists of attachments
*
* @package Attachments
*/
class AttachmentsControllerList extends JControllerLegacy
{
/**
* Constructor.
*
* @param array An optional associative array of configuration settings.
*
* @return JControllerForm
*/
public function __construct( $default = array('default_task' => 'noop') )
{
parent::__construct( $default );
}
/**
* A noop function so this controller does not have a usable default
*/
public function noop()
{
$errmsg = JText::_('ATTACH_ERROR_NO_FUNCTION_SPECIFIED') . ' (ERR 119)';
JError::raiseError(500, $errmsg);
}
/**
* Display the attachments list
*
* @param int $parent_id the id of the parent
* @param string $parent_type the type of parent
* @param string $parent_entity the type entity of the parent
* @param string $title title to be shown above the list of articles. If null, use system defaults.
* @param bool $show_file_links enable showing links for the filenames
* @param bool $allow_edit enable showing edit/delete links (if permissions are okay)
* @param bool $echo if true the output will be echoed; otherwise the results are returned.
* @param string $from The 'from' info
*
* @return the string (if $echo is false)
*/
public function displayString($parent_id, $parent_type, $parent_entity,
$title=null, $show_file_links=true, $allow_edit=true,
$echo=true, $from=null)
{
$document = JFactory::getDocument();
// Get an instance of the model
require_once(JPATH_SITE.'/components/com_attachments/models/attachments.php');
$model = new AttachmentsModelAttachments();
$model->setParentId($parent_id, $parent_type, $parent_entity);
// Get the component parameters
jimport('joomla.application.component.helper');
$params = JComponentHelper::getParams('com_attachments');
// Set up to list the attachments for this artticle
$sort_order = $params->get('sort_order', 'filename');
$model->setSortOrder($sort_order);
// If none of the attachments should be visible, exit now
if ( ! $model->someVisible() ) {
return false;
}
// Get the view
$this->addViewPath(JPATH_SITE.'/components/com_attachments/views');
$viewType = $document->getType();
$view = $this->getView('Attachments', $viewType);
if ( !$view ) {
$errmsg = JText::_('ATTACH_ERROR_UNABLE_TO_FIND_VIEW') . ' (ERR 120)';
JError::raiseError(500, $errmsg);
}
$view->setModel($model);
// Construct the update URL template
$update_url = "index.php?option=com_attachments&task=attachment.edit&cid[]=%d";
$update_url .= "&from=$from&tmpl=component";
$view->update_url = $update_url;
// Construct the delete URL template
$delete_url = "index.php?option=com_attachments&task=attachment.delete_warning&id=%d";
$delete_url .= "&parent_type=$parent_type&parent_entity=$parent_entity&parent_id=" . (int)$parent_id;
$delete_url .= "&from=$from&tmpl=component";
$view->delete_url = $delete_url;
// Set some display settings
$view->title = $title;
$view->show_file_links = $show_file_links;
$view->allow_edit = $allow_edit;
$view->from = $from;
// Get the view to generate the display output from the template
if ( $view->display() === true ) {
// Display or return the results
if ( $echo ) {
echo $view->getOutput();
}
else {
return $view->getOutput();
}
}
return false;
}
}

View File

@ -0,0 +1,205 @@
<?php
/**
* Attachments component param controller
*
* @package Attachments
* @subpackage Attachments_Component
*
* @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/
* @author Jonathan M. Cameron
*/
// No direct access to this file
defined('_JEXEC') or die('Restricted access');
/** Define the legacy classes, if necessary */
require_once(JPATH_SITE.'/components/com_attachments/legacy/controller_form.php');
/** Load the class for the model component form and make it work for both 3.2 and less */
if (version_compare(JVERSION, '3.2', 'ge'))
{
require_once(JPATH_SITE . '/components/com_config/model/cms.php');
require_once(JPATH_SITE . '/components/com_config/model/form.php');
}
require_once(JPATH_ADMINISTRATOR.'/components/com_config/models/component.php');
/**
* Attachment Controller
*
* @package Attachments
*/
class AttachmentsControllerParams extends JControllerFormLegacy
{
/**
* Edit the component parameters
*/
public function edit($key = null, $urlVar = null)
{
// Access check.
if (!JFactory::getUser()->authorise('core.admin', 'com_attachments')) {
return JError::raiseError(404, JText::_('JERROR_ALERTNOAUTHOR') . ' (ERR 117)');
}
// Get the component parameters
jimport('joomla.application.component.helper');
$params = JComponentHelper::getParams('com_attachments');
// Get the component model/table
$model = new ConfigModelComponent();
$state = $model->getState();
$state->set('component.option', 'com_attachments');
$state->set('component.path', JPATH_ADMINISTRATOR.'/components/com_attachments');
$model->setState($state);
$form = $model->getForm();
$component = JComponentHelper::getComponent('com_attachments');
// Check for errors.
if (count($errors = $this->get('Errors'))) {
JError::raiseError(500, implode("\n", $errors) . ' (ERR 118)');
return false;
}
// Bind the form to the data.
if ($form && $component->params) {
$form->bind($component->params);
}
// Set up the view
require_once(JPATH_COMPONENT_ADMINISTRATOR.'/views/params/view.html.php');
$view = new AttachmentsViewParams( );
$view->setModel($model);
$view->params = $params;
$view->form = $form;
$view->component = $component;
$view->display();
}
/**
* Save the parameters
*/
public function save($key = null, $urlVar = null)
{
// Check for request forgeries.
JSession::checkToken() or jexit(JText::_('JINVALID_TOKEN'));
$app = JFactory::getApplication();
// Get the old component parameters
jimport('joomla.application.component.helper');
$old_params = JComponentHelper::getParams('com_attachments');
$old_secure = JRequest::getInt('old_secure');
// Set FTP credentials, if given.
jimport('joomla.client.helper');
JClientHelper::setCredentialsFromRequest('ftp');
// Initialise variables.
$model = new ConfigModelComponent();
$form = $model->getForm();
$data = JRequest::getVar('jform', array(), 'post', 'array');
$id = JRequest::getInt('id');
$option = JRequest::getCmd('component');
// Get the new component parameters
$new_secure = $data['secure'];
// Check if the user is authorized to do this.
if (!JFactory::getUser()->authorise('core.admin', $option))
{
JFactory::getApplication()->redirect('index.php', JText::_('JERROR_ALERTNOAUTHOR'));
return;
}
// Validate the posted data.
$return = $model->validate($form, $data);
// Check for validation errors.
if ($return === false) {
// Get the validation messages.
$errors = $model->getErrors();
// Push up to three validation messages out to the user.
for ($i = 0, $n = count($errors); $i < $n && $i < 3; $i++) {
if ($errors[$i] instanceof Exception) {
$app->enqueueMessage($errors[$i]->getMessage(), 'warning');
} else {
$app->enqueueMessage($errors[$i], 'warning');
}
}
// Save the data in the session.
$app->setUserState('com_config.config.global.data', $data);
// Redirect back to the edit screen.
$this->setRedirect(JRoute::_('index.php?option=com_attachments&task=params.edit', false));
return false;
}
// Attempt to save the configuration.
$data = array(
'params' => $return,
'id' => $id,
'option' => $option
);
$return = $model->save($data);
// Check the return value.
if ($return === false)
{
// Save the data in the session.
$app->setUserState('com_config.config.global.data', $data);
// Save failed, go back to the screen and display a notice.
$message = JText::sprintf('JERROR_SAVE_FAILED', $model->getError());
$this->setRedirect(JRoute::_('index.php?option=com_attachments&task=params.edit'), $message, 'error');
return false;
}
// Deal with any changes in the 'secure mode' (or upload directories)
if ( $new_secure != $old_secure ) {
// Check/update the security status
require_once(JPATH_SITE.'/components/com_attachments/helper.php');
$attach_dir = JPATH_SITE.'/'.AttachmentsDefines::$ATTACHMENTS_SUBDIR;
AttachmentsHelper::setup_upload_directory($attach_dir, $new_secure == 1);
$msg = JText::_('ATTACH_UPDATED_ATTACHMENTS_PARAMETERS_AND_SECURITY_SETTINGS');
}
else {
$msg = JText::_( 'ATTACH_UPDATED_ATTACHMENTS_PARAMETERS' );
}
// Set the redirect based on the task.
switch ($this->getTask())
{
case 'apply':
$this->setRedirect('index.php?option=com_attachments&task=params.edit', $msg, 'message');
break;
case 'save':
default:
$this->setRedirect('index.php?option=com_attachments', $msg, 'message');
break;
}
return true;
}
/**
* Save parameters and go back to the main listing display
*/
public function cancel($key = null)
{
$this->setRedirect('index.php?option=com_attachments');
}
}

View File

@ -0,0 +1,150 @@
<?php
/**
* Attachments component
*
* @package Attachments
* @subpackage Attachments_Component
*
* @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/
* @author Jonathan M. Cameron
*/
defined('_JEXEC') or die('Restricted access');
// Access check.
if (!JFactory::getUser()->authorise('core.admin', 'com_attachments')) {
return JError::raiseError(404, JText::_('JERROR_ALERTNOAUTHOR') . ' (ERR 147)');
}
/** Define the legacy classes, if necessary */
require_once(JPATH_SITE.'/components/com_attachments/legacy/controller.php');
/**
* The controller for special requests
* (adapted from administrator/components/com_config/controllers/component.php)
*
* @package Attachments
*/
class AttachmentsControllerSpecial extends JControllerLegacy
{
/**
* Constructor.
*
* @param array An optional associative array of configuration settings.
*/
public function __construct( $default = array())
{
$default['default_task'] = 'noop';
parent::__construct( $default );
}
/**
* A noop function so this controller does not have a usable default
*/
public function noop()
{
echo "<h1>" . JText::_('ATTACH_ERROR_NO_SPECIAL_FUNCTION_SPECIFIED') . "</h1>";
exit();
}
/**
* Show the current SEF mode
*
* This is for system testing purposes only
*/
public function showSEF()
{
$app = JFactory::getApplication();
echo '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">';
echo "<html><head><title>SEF Status</title></head><body>";
echo "SEF: " . $app->getCfg('sef') . "<br />";
echo "</body></html>";
exit();
}
/**
* Show a list of all attachment IDs
*
* This is for system testing purposes only
*/
public function listAttachmentIDs()
{
// Get the article IDs
$db = JFactory::getDBO();
$query = $db->getQuery(true);
$query->select('att.id,parent_id,parent_type,parent_entity,art.catid');
$query->from('#__attachments as att');
$query->leftJoin('#__content as art ON att.parent_id = art.id');
$query->where('att.parent_entity=' . $db->quote('article'));
$query->order('art.id');
$db->setQuery($query);
$attachments = $db->loadObjectList();
if ( $db->getErrorNum() ) {
$errmsg = $db->stderr() . ' (ERR 148)';
JError::raiseError(500, $errmsg);
}
// Get the category IDs
$query = $db->getQuery(true);
$query->select('att.id,att.parent_id,parent_type,parent_entity');
$query->from('#__attachments as att');
$query->leftJoin('#__categories as c ON att.parent_id = c.id');
$query->where('att.parent_entity=' . $db->quote('category'));
$query->order('c.id');
$db->setQuery($query);
$crows = $db->loadObjectList();
if ( $db->getErrorNum() ) {
$errmsg = $db->stderr() . ' (ERR 149)';
JError::raiseError(500, $errmsg);
}
echo '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">';
echo '<html><head><title>Attachment IDs</title></head><body>';
echo 'Attachment IDs:<br/>';
// Do the article attachments
foreach ($attachments as $attachment) {
if ( empty($attachment->id) ) {
$attachment->id = '0';
}
if ( empty($attachment->catid) ) {
$attachment->catid = '0';
}
$parent_entity = JString::strtolower($attachment->parent_entity);
echo ' ' . $attachment->id . '/' . $attachment->parent_id . '/' .
$attachment->parent_type . '/' . $parent_entity . '/' . $attachment->catid . '<br/>';
}
foreach ($crows as $attachment) {
if ( empty($attachment->id) ) {
$attachment->id = '0';
}
$parent_entity = JString::strtolower($attachment->parent_entity);
echo ' ' . $attachment->id . '/' . $attachment->parent_id . '/' .
$attachment->parent_type . '/' . $parent_entity . '/' . $attachment->parent_id . '<br/>';
}
echo '</body></html>';
exit();
}
/**
* Show a list of all attachment IDs
*
* This is for system testing purposes only
*/
public function listKnownParentTypes()
{
// Get the article/parent handler
JPluginHelper::importPlugin('attachments');
$apm = getAttachmentsPluginManager();
$ptypes = $apm->getInstalledParentTypes();
echo implode($ptypes, '<br/>');
}
}

View File

@ -0,0 +1,377 @@
<?php
/**
* Attachments component
*
* @package Attachments
* @subpackage Attachments_Component
*
* @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/
* @author Jonathan M. Cameron
*/
defined('_JEXEC') or die('Restricted access');
// Access check.
if (!JFactory::getUser()->authorise('core.admin', 'com_attachments')) {
return JError::raiseError(404, JText::_('JERROR_ALERTNOAUTHOR') . ' (ERR 150)');
}
/** Define the legacy classes, if necessary */
require_once(JPATH_SITE.'/components/com_attachments/legacy/controller.php');
// Load the helper functions
require_once(JPATH_SITE.'/components/com_attachments/javascript.php');
/**
* The controller for utils requests
* (adapted from administrator/components/com_config/controllers/component.php)
*
* @package Attachments
*/
class AttachmentsControllerUtils extends JControllerLegacy
{
/**
* Constructor.
*
* @param array An optional associative array of configuration settings.
*/
public function __construct( $default = array())
{
$default['default_task'] = 'noop';
parent::__construct( $default );
}
/**
* A noop function so this controller does not have a usable default
*/
public function noop()
{
echo "<h1>" . JText::_('ATTACH_ERROR_NO_UTILS_FUNCTION_SPECIFIED') . "</h1>";
exit();
}
/**
*
*/
/**
* Enqueue a system message.
*
* @param string $msg The message to enqueue.
* @param string $type The message type. Default is message.
*
* @return void
*/
protected function enqueueSystemMessage($msg, $type = 'message')
{
$app = JFactory::getApplication();
$app->enqueueMessage($msg, $type);
// Not sure why I need the extra saving to the session below,
// but it it seems necessary because I'm doing it from an iframe.
$session = JFactory::getSession();
$session->set('application.queue', $app->getMessageQueue());
}
/**
* Add icon filenames for attachments missing an icon
* (See AttachmentsUpdate::add_icon_filenames() in update.php for details )
*/
public function add_icon_filenames()
{
// Access check.
if (!JFactory::getUser()->authorise('core.admin', 'com_attachments')) {
return JError::raiseError(404, JText::_('JERROR_ALERTNOAUTHOR') . ' (ERR 151)');
}
require_once(JPATH_ADMINISTRATOR.'/components/com_attachments/update.php');
$msg = AttachmentsUpdate::add_icon_filenames();
$this->setRedirect('index.php?option=' . $this->option, $msg);
}
/**
* Update any null dates in any attachments
* (See AttachmentsUpdate::update_null_dates() in update.php for details )
*/
public function update_null_dates()
{
// Access check.
if (!JFactory::getUser()->authorise('core.admin', 'com_attachments')) {
return JError::raiseError(404, JText::_('JERROR_ALERTNOAUTHOR') . ' (ERR 152)');
}
require_once(JPATH_ADMINISTRATOR.'/components/com_attachments/update.php');
$numUpdated = AttachmentsUpdate::update_null_dates();
$msg = JText::sprintf( 'ATTACH_UPDATED_N_ATTACHMENTS', $numUpdated );
$this->setRedirect('index.php?option=' . $this->option, $msg);
}
/**
* Disable SQL uninstall of existing attachments (when Attachments is uninstalled)
* (See AttachmentsUpdate::disable_sql_uninstall() in update.php for details )
*/
public function disable_sql_uninstall()
{
// Access check.
if (!JFactory::getUser()->authorise('core.admin', 'com_attachments')) {
return JError::raiseError(404, JText::_('JERROR_ALERTNOAUTHOR') . ' (ERR 153)');
}
require_once(JPATH_ADMINISTRATOR.'/components/com_attachments/update.php');
$msg = AttachmentsUpdate::disable_sql_uninstall();
if ( JRequest::getBool('close') ) {
$this->enqueueSystemMessage($msg);
// Close this window and refesh the parent window
AttachmentsJavascript::closeModal();
}
else {
$this->setRedirect('index.php?option=com_attachments', $msg);
}
}
/**
* Regenerate system filenames
* (See AttachmentsUpdate::regenerate_system_filenames() in update.php for details )
*/
public function regenerate_system_filenames()
{
// Access check.
if (!JFactory::getUser()->authorise('core.admin', 'com_attachments')) {
return JError::raiseError(404, JText::_('JERROR_ALERTNOAUTHOR') . ' (ERR 154)');
}
require_once(JPATH_ADMINISTRATOR.'/components/com_attachments/update.php');
$msg = AttachmentsUpdate::regenerate_system_filenames();
if ( JRequest::getBool('close') ) {
$this->enqueueSystemMessage($msg);
// Close this window and refesh the parent window
AttachmentsJavascript::closeModal();
}
else {
$this->setRedirect('index.php?option=' . $this->option, $msg);
}
}
/**
* Remove spaces from system filenames for all attachments
* (See AttachmentsUpdate::remove_spaces_from_system_filenames() in update.php for details )
*/
public function remove_spaces_from_system_filenames()
{
// Access check.
if (!JFactory::getUser()->authorise('core.admin', 'com_attachments')) {
return JError::raiseError(404, JText::_('JERROR_ALERTNOAUTHOR') . ' (ERR 155)');
}
require_once(JPATH_ADMINISTRATOR.'/components/com_attachments/update.php');
$msg = AttachmentsUpdate::remove_spaces_from_system_filenames();
if ( JRequest::getBool('close') ) {
$this->enqueueSystemMessage($msg);
// Close this window and refesh the parent window
AttachmentsJavascript::closeModal();
}
else {
$this->setRedirect('index.php?option=' . $this->option, $msg);
}
}
/**
* Update file sizes for all attachments
* (See AttachmentsUpdate::update_file_sizes() in update.php for details )
*/
public function update_file_sizes()
{
// Access check.
if (!JFactory::getUser()->authorise('core.admin', 'com_attachments')) {
return JError::raiseError(404, JText::_('JERROR_ALERTNOAUTHOR') . ' (ERR 156)');
}
require_once(JPATH_ADMINISTRATOR.'/components/com_attachments/update.php');
$msg = AttachmentsUpdate::update_file_sizes();
if ( JRequest::getBool('close') ) {
$this->enqueueSystemMessage($msg);
// Close this window and refesh the parent window
AttachmentsJavascript::closeModal();
}
else {
$this->setRedirect('index.php?option=' . $this->option, $msg);
}
}
/**
* Check all files in any attachments
* (See AttachmentsUpdate::check_files() in update.php for details )
*/
public function check_files()
{
// Access check.
if (!JFactory::getUser()->authorise('core.admin', 'com_attachments')) {
return JError::raiseError(404, JText::_('JERROR_ALERTNOAUTHOR') . ' (ERR 157)');
}
require_once(JPATH_ADMINISTRATOR.'/components/com_attachments/update.php');
$msg = AttachmentsUpdate::check_files_existance();
if ( JRequest::getBool('close') ) {
$this->enqueueSystemMessage($msg);
// Close this window and refesh the parent window
AttachmentsJavascript::closeModal();
}
else {
$this->setRedirect('index.php?option=' . $this->option, $msg);
}
}
/**
* Validate all URLS in any attachments
* (See AttachmentsUpdate::validate_urls() in update.php for details )
*/
public function validate_urls()
{
// Access check.
if (!JFactory::getUser()->authorise('core.admin', 'com_attachments')) {
return JError::raiseError(404, JText::_('JERROR_ALERTNOAUTHOR') . ' (ERR 158)');
}
require_once(JPATH_ADMINISTRATOR.'/components/com_attachments/update.php');
$msg = AttachmentsUpdate::validate_urls();
if ( JRequest::getBool('close') ) {
$this->enqueueSystemMessage($msg);
// Close this window and refesh the parent window
AttachmentsJavascript::closeModal();
}
else {
$this->setRedirect('index.php?option=' . $this->option, $msg);
}
}
/**
* Validate all URLS in any attachments
* (See AttachmentsUpdate::reinstall_permissions() in update.php for details )
*/
public function reinstall_permissions()
{
// Access check.
if (!JFactory::getUser()->authorise('core.admin', 'com_attachments')) {
return JError::raiseError(404, JText::_('JERROR_ALERTNOAUTHOR') . ' (ERR 159)');
}
require_once(JPATH_ADMINISTRATOR.'/components/com_attachments/update.php');
$msg = AttachmentsUpdate::installAttachmentsPermissions();
if ( JRequest::getBool('close') ) {
$this->enqueueSystemMessage($msg);
// Close this window and refesh the parent window
AttachmentsJavascript::closeModal();
}
else {
$this->setRedirect('index.php?option=' . $this->option, $msg);
}
}
/**
* Install attachments data from CSV file
*/
public function installAttachmentsFromCsvFile()
{
// Access check.
if (!JFactory::getUser()->authorise('core.admin', 'com_attachments')) {
return JError::raiseError(404, JText::_('JERROR_ALERTNOAUTHOR') . ' (ERR 160)');
}
require_once(JPATH_ADMINISTRATOR.'/components/com_attachments/import.php');
$filename = JRequest::getString('filename', null);
if ( $filename == null ) {
$errmsg = JText::_('ATTACH_ERROR_MUST_ADD_FILENAME_TO_URL') . ' (ERR 161)';
return JError::raiseError(500, $errmsg);
}
$verify_parent = JRequest::getBool('verify_parent', true);
$update = JRequest::getBool('update', false);
$dry_run = JRequest::getBool('dry_run', false);
$status = AttachmentsImport::importAttachmentsFromCSVFile($filename, $verify_parent,
$update, $dry_run);
// Abort if it is an error message
if ( is_string($status) ) {
return JError::raiseError(500, $status);
}
// Otherwise, report the results
if ( is_array($status) ) {
$msg = JText::sprintf('ATTACH_ADDED_DATA_FOR_N_ATTACHMENTS', count($status));
$this->setRedirect('index.php?option=com_attachments', $msg);
}
else {
if ( $dry_run ) {
$msg = JText::sprintf('ATTACH_DATA_FOR_N_ATTACHMENTS_OK', $status) . ' (ERR 162)';
return JError::raiseNotice(200, $msg);
}
else {
$errmsg = JText::sprintf('ATTACH_ERROR_IMPORTING_ATTACHMENTS_S', $status) . ' (ERR 163)';
return JError::raiseError(500, $errmsg);
}
}
}
/**
* Test function
*/
public function test()
{
// Access check.
if (!JFactory::getUser()->authorise('core.admin', 'com_attachments')) {
return JError::raiseError(404, JText::_('JERROR_ALERTNOAUTHOR'));
}
echo "Test!";
exit();
}
}