primo commit
This commit is contained in:
236
components/com_ajax/ajax.php
Normal file
236
components/com_ajax/ajax.php
Normal file
@ -0,0 +1,236 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Joomla.Site
|
||||
* @subpackage com_ajax
|
||||
*
|
||||
* @copyright (C) 2013 Open Source Matters, Inc. <https://www.joomla.org>
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
\defined('_JEXEC') or die;
|
||||
|
||||
use Joomla\CMS\Event\Plugin\AjaxEvent;
|
||||
use Joomla\CMS\Factory;
|
||||
use Joomla\CMS\Language\Text;
|
||||
use Joomla\CMS\Log\Log;
|
||||
use Joomla\CMS\Plugin\PluginHelper;
|
||||
use Joomla\CMS\Response\JsonResponse;
|
||||
use Joomla\CMS\Table\Table;
|
||||
|
||||
/*
|
||||
* References
|
||||
* Support plugins in your component
|
||||
* - https://docs.joomla.org/Special:MyLanguage/Supporting_plugins_in_your_component
|
||||
*
|
||||
* Best way for JSON output
|
||||
* - https://groups.google.com/d/msg/joomla-dev-cms/WsC0nA9Fixo/Ur-gPqpqh-EJ
|
||||
*/
|
||||
|
||||
/** @var \Joomla\CMS\Application\CMSApplication $app */
|
||||
$app = Factory::getApplication();
|
||||
$app->allowCache(false);
|
||||
|
||||
// Prevent the api url from being indexed
|
||||
$app->setHeader('X-Robots-Tag', 'noindex, nofollow');
|
||||
|
||||
// JInput object
|
||||
$input = $app->getInput();
|
||||
|
||||
// Requested format passed via URL
|
||||
$format = strtolower($input->getWord('format', ''));
|
||||
|
||||
// Initialize default response and module name
|
||||
$results = null;
|
||||
$parts = null;
|
||||
|
||||
// Check for valid format
|
||||
if (!$format) {
|
||||
$results = new InvalidArgumentException(Text::_('COM_AJAX_SPECIFY_FORMAT'), 404);
|
||||
} elseif ($input->get('module')) {
|
||||
/**
|
||||
* Module support.
|
||||
*
|
||||
* modFooHelper::getAjax() is called where 'foo' is the value
|
||||
* of the 'module' variable passed via the URL
|
||||
* (i.e. index.php?option=com_ajax&module=foo).
|
||||
*
|
||||
*/
|
||||
$module = $input->get('module');
|
||||
$table = Table::getInstance('extension');
|
||||
$moduleId = $table->find(['type' => 'module', 'element' => 'mod_' . $module]);
|
||||
|
||||
if ($moduleId && $table->load($moduleId) && $table->enabled) {
|
||||
$helperFile = JPATH_BASE . '/modules/mod_' . $module . '/helper.php';
|
||||
|
||||
if (strpos($module, '_')) {
|
||||
$parts = explode('_', $module);
|
||||
} elseif (strpos($module, '-')) {
|
||||
$parts = explode('-', $module);
|
||||
}
|
||||
|
||||
if ($parts) {
|
||||
$class = 'Mod';
|
||||
|
||||
foreach ($parts as $part) {
|
||||
$class .= ucfirst($part);
|
||||
}
|
||||
|
||||
$class .= 'Helper';
|
||||
} else {
|
||||
$class = 'Mod' . ucfirst($module) . 'Helper';
|
||||
}
|
||||
|
||||
$method = $input->get('method') ?: 'get';
|
||||
|
||||
$moduleInstance = $app->bootModule('mod_' . $module, $app->getName());
|
||||
|
||||
if ($moduleInstance instanceof \Joomla\CMS\Helper\HelperFactoryInterface && $helper = $moduleInstance->getHelper(substr($class, 3))) {
|
||||
$results = method_exists($helper, $method . 'Ajax') ? $helper->{$method . 'Ajax'}() : null;
|
||||
}
|
||||
|
||||
if ($results === null && is_file($helperFile)) {
|
||||
JLoader::register($class, $helperFile);
|
||||
|
||||
if (method_exists($class, $method . 'Ajax')) {
|
||||
// Load language file for module
|
||||
$basePath = JPATH_BASE;
|
||||
$lang = Factory::getLanguage();
|
||||
$lang->load('mod_' . $module, $basePath)
|
||||
|| $lang->load('mod_' . $module, $basePath . '/modules/mod_' . $module);
|
||||
|
||||
try {
|
||||
$results = \call_user_func($class . '::' . $method . 'Ajax');
|
||||
} catch (Exception $e) {
|
||||
$results = $e;
|
||||
}
|
||||
} else {
|
||||
// Method does not exist
|
||||
$results = new LogicException(Text::sprintf('COM_AJAX_METHOD_NOT_EXISTS', $method . 'Ajax'), 404);
|
||||
}
|
||||
} elseif ($results === null) {
|
||||
// The helper file does not exist
|
||||
$results = new RuntimeException(Text::sprintf('COM_AJAX_FILE_NOT_EXISTS', 'mod_' . $module . '/helper.php'), 404);
|
||||
}
|
||||
} else {
|
||||
// Module is not published, you do not have access to it, or it is not assigned to the current menu item
|
||||
$results = new LogicException(Text::sprintf('COM_AJAX_MODULE_NOT_ACCESSIBLE', 'mod_' . $module), 404);
|
||||
}
|
||||
} elseif ($input->get('plugin')) {
|
||||
/**
|
||||
* Plugin support by default is based on the "Ajax" plugin group.
|
||||
* An optional 'group' variable can be passed via the URL.
|
||||
*
|
||||
* The plugin event triggered is onAjaxFoo, where 'foo' is
|
||||
* the value of the 'plugin' variable passed via the URL
|
||||
* (i.e. index.php?option=com_ajax&plugin=foo)
|
||||
*
|
||||
*/
|
||||
try {
|
||||
$dispatcher = $app->getDispatcher();
|
||||
$group = $input->get('group', 'ajax');
|
||||
$eventName = 'onAjax' . ucfirst($input->get('plugin', ''));
|
||||
|
||||
PluginHelper::importPlugin($group, null, true, $dispatcher);
|
||||
|
||||
$results = $dispatcher->dispatch($eventName, new AjaxEvent($eventName, ['subject' => $app]))->getArgument('result', []);
|
||||
} catch (Throwable $e) {
|
||||
$results = $e;
|
||||
}
|
||||
} elseif ($input->get('template')) {
|
||||
/**
|
||||
* Template support.
|
||||
*
|
||||
* tplFooHelper::getAjax() is called where 'foo' is the value
|
||||
* of the 'template' variable passed via the URL
|
||||
* (i.e. index.php?option=com_ajax&template=foo).
|
||||
*
|
||||
*/
|
||||
$template = $input->get('template');
|
||||
$table = Table::getInstance('extension');
|
||||
$templateId = $table->find(['type' => 'template', 'element' => $template]);
|
||||
|
||||
if ($templateId && $table->load($templateId) && $table->enabled) {
|
||||
$basePath = ($table->client_id) ? JPATH_ADMINISTRATOR : JPATH_SITE;
|
||||
$helperFile = $basePath . '/templates/' . $template . '/helper.php';
|
||||
|
||||
if (strpos($template, '_')) {
|
||||
$parts = explode('_', $template);
|
||||
} elseif (strpos($template, '-')) {
|
||||
$parts = explode('-', $template);
|
||||
}
|
||||
|
||||
if ($parts) {
|
||||
$class = 'Tpl';
|
||||
|
||||
foreach ($parts as $part) {
|
||||
$class .= ucfirst($part);
|
||||
}
|
||||
|
||||
$class .= 'Helper';
|
||||
} else {
|
||||
$class = 'Tpl' . ucfirst($template) . 'Helper';
|
||||
}
|
||||
|
||||
$method = $input->get('method') ?: 'get';
|
||||
|
||||
if (is_file($helperFile)) {
|
||||
JLoader::register($class, $helperFile);
|
||||
|
||||
if (method_exists($class, $method . 'Ajax')) {
|
||||
// Load language file for template
|
||||
$lang = Factory::getLanguage();
|
||||
$lang->load('tpl_' . $template, $basePath)
|
||||
|| $lang->load('tpl_' . $template, $basePath . '/templates/' . $template);
|
||||
|
||||
try {
|
||||
$results = \call_user_func($class . '::' . $method . 'Ajax');
|
||||
} catch (Exception $e) {
|
||||
$results = $e;
|
||||
}
|
||||
} else {
|
||||
// Method does not exist
|
||||
$results = new LogicException(Text::sprintf('COM_AJAX_METHOD_NOT_EXISTS', $method . 'Ajax'), 404);
|
||||
}
|
||||
} else {
|
||||
// The helper file does not exist
|
||||
$results = new RuntimeException(Text::sprintf('COM_AJAX_FILE_NOT_EXISTS', 'tpl_' . $template . '/helper.php'), 404);
|
||||
}
|
||||
} else {
|
||||
// Template is not assigned to the current menu item
|
||||
$results = new LogicException(Text::sprintf('COM_AJAX_TEMPLATE_NOT_ACCESSIBLE', 'tpl_' . $template), 404);
|
||||
}
|
||||
}
|
||||
|
||||
// Return the results in the desired format
|
||||
switch ($format) {
|
||||
case 'json':
|
||||
// JSONinzed
|
||||
echo new JsonResponse($results, null, false, $input->get('ignoreMessages', true, 'bool'));
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
// Handle as raw format
|
||||
// Output exception
|
||||
if ($results instanceof Exception) {
|
||||
// Log an error
|
||||
Log::add($results->getMessage(), Log::ERROR);
|
||||
|
||||
// Set status header code
|
||||
$app->setHeader('status', $results->getCode(), true);
|
||||
|
||||
// Echo exception type and message
|
||||
$out = \get_class($results) . ': ' . $results->getMessage();
|
||||
} elseif (\is_scalar($results)) {
|
||||
// Output string/ null
|
||||
$out = (string) $results;
|
||||
} else {
|
||||
// Output array/ object
|
||||
$out = implode((array) $results);
|
||||
}
|
||||
|
||||
echo $out;
|
||||
|
||||
break;
|
||||
}
|
||||
42
components/com_attachments/attachments.php
Normal file
42
components/com_attachments/attachments.php
Normal file
@ -0,0 +1,42 @@
|
||||
<?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');
|
||||
|
||||
/** Load the default controller */
|
||||
require_once( JPATH_COMPONENT.'/controller.php' );
|
||||
|
||||
// Check for requests for named controller
|
||||
$controller = JRequest::getWord('controller', False);
|
||||
if ( $controller ) {
|
||||
// Invoke the named controller, if it exists
|
||||
$path = JPATH_COMPONENT.'/controllers/'.$controller.'.php';
|
||||
$controller = JString::ucfirst($controller);
|
||||
jimport('joomla.filesystem.file');
|
||||
if ( JFile::exists($path) ) {
|
||||
require_once( $path );
|
||||
$classname = 'AttachmentsController' . $controller;
|
||||
}
|
||||
else {
|
||||
$errmsg = JText::_('ATTACH_UNKNOWN_CONTROLLER') . ' (ERR 48)';
|
||||
JError::raiseError(500, $errmsg);
|
||||
}
|
||||
}
|
||||
else {
|
||||
$classname = 'AttachmentsController';
|
||||
}
|
||||
|
||||
// Invoke the requested function of the controller
|
||||
$controller = new $classname( array('default_task' => 'noop') );
|
||||
$controller->execute( JRequest::getCmd('task') );
|
||||
$controller->redirect();
|
||||
806
components/com_attachments/controller.php
Normal file
806
components/com_attachments/controller.php
Normal file
@ -0,0 +1,806 @@
|
||||
<?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');
|
||||
|
||||
/** Load the Attachements defines */
|
||||
require_once(JPATH_SITE.'/components/com_attachments/defines.php');
|
||||
|
||||
/** Define the legacy classes, if necessary */
|
||||
require_once(JPATH_SITE.'/components/com_attachments/legacy/controller.php');
|
||||
|
||||
/** Load the attachments helper */
|
||||
require_once(JPATH_SITE.'/components/com_attachments/helper.php');
|
||||
require_once(JPATH_SITE.'/components/com_attachments/javascript.php');
|
||||
|
||||
|
||||
/**
|
||||
* The main attachments controller class (for the front end)
|
||||
*
|
||||
* @package Attachments
|
||||
*/
|
||||
class AttachmentsController extends JControllerLegacy
|
||||
{
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param array $default : An optional associative array of configuration settings.
|
||||
* Recognized key values include 'name', 'default_task', 'model_path', and
|
||||
* 'view_path' (this list is not meant to be comprehensive).
|
||||
*/
|
||||
public function __construct( $default = array() )
|
||||
{
|
||||
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 0)';
|
||||
JError::raiseError(500, $errmsg);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 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 = 'AttachmentModel', $config = array())
|
||||
{
|
||||
$model = parent::getModel($name, $prefix, array('ignore_request' => true));
|
||||
return $model;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Display a form for uploading a file/url
|
||||
*/
|
||||
public function upload()
|
||||
{
|
||||
// Access check.
|
||||
if (!JFactory::getUser()->authorise('core.create', 'com_attachments')) {
|
||||
return JError::raiseError(404, JText::_('JERROR_ALERTNOAUTHOR') . ' (ERR 1)');
|
||||
}
|
||||
|
||||
// Get the parent info
|
||||
$parent_entity = 'default';
|
||||
if ( JRequest::getString('article_id') ) {
|
||||
$pid_info = explode(',', JRequest::getString('article_id'));
|
||||
$parent_type = 'com_content';
|
||||
}
|
||||
else {
|
||||
$pid_info = explode(',', JRequest::getString('parent_id'));
|
||||
// Be extra cautious and remove all non-cmd characters except for ':'
|
||||
$parent_type = preg_replace('/[^A-Z0-9_\.:-]/i', '', JRequest::getString('parent_type', 'com_content'));
|
||||
|
||||
// If the entity is embedded in the parent type, split them
|
||||
if ( strpos($parent_type, '.') ) {
|
||||
$parts = explode('.', $parent_type);
|
||||
$parent_type = $parts[0];
|
||||
$parent_entity = $parts[1];
|
||||
}
|
||||
if ( strpos($parent_type, ':') ) {
|
||||
$parts = explode(':', $parent_type);
|
||||
$parent_type = $parts[0];
|
||||
$parent_entity = $parts[1];
|
||||
}
|
||||
}
|
||||
|
||||
// Get the parent id
|
||||
$parent_id = null;
|
||||
if ( is_numeric($pid_info[0]) ) {
|
||||
$parent_id = (int)$pid_info[0];
|
||||
}
|
||||
|
||||
// See if the parent is new (or already exists)
|
||||
$new_parent = false;
|
||||
if ( count($pid_info) > 1 ) {
|
||||
if ( $pid_info[1] == 'new' ) {
|
||||
$new_parent = true;
|
||||
}
|
||||
}
|
||||
|
||||
// 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 2)';
|
||||
JError::raiseError(500, $errmsg);
|
||||
}
|
||||
$parent = $apm->getAttachmentsPlugin($parent_type);
|
||||
|
||||
$parent_entity = $parent->getCanonicalEntityId($parent_entity);
|
||||
$parent_entity_name = JText::_('ATTACH_' . $parent_entity);
|
||||
|
||||
// Make sure this user can add attachments to this parent
|
||||
$user = JFactory::getUser();
|
||||
if ( !$parent->userMayAddAttachment($parent_id, $parent_entity, $new_parent) ) {
|
||||
$errmsg = JText::sprintf('ATTACH_ERROR_NO_PERMISSION_TO_UPLOAD_S', $parent_entity_name) . ' (ERR 3)';
|
||||
JError::raiseError(500, $errmsg);
|
||||
}
|
||||
|
||||
// Get the title of the parent
|
||||
$parent_title = '';
|
||||
if ( !$new_parent ) {
|
||||
$parent_title = $parent->getTitle($parent_id, $parent_entity);
|
||||
}
|
||||
|
||||
// Use a different template for the iframe view
|
||||
$from = JRequest::getWord('from');
|
||||
$Itemid = JRequest::getInt('Itemid', 1);
|
||||
if ( $from == 'closeme') {
|
||||
JRequest::setVar('tmpl', 'component');
|
||||
}
|
||||
|
||||
// Get the component parameters
|
||||
jimport('joomla.application.component.helper');
|
||||
$params = JComponentHelper::getParams('com_attachments');
|
||||
|
||||
// Make sure the attachments directory exists
|
||||
$upload_dir = JPATH_BASE.'/'.AttachmentsDefines::$ATTACHMENTS_SUBDIR;
|
||||
$secure = $params->get('secure', false);
|
||||
if ( !AttachmentsHelper::setup_upload_directory( $upload_dir, $secure ) ) {
|
||||
$errmsg = JText::sprintf('ATTACH_ERROR_UNABLE_TO_SETUP_UPLOAD_DIR_S', $upload_dir) . ' (ERR 4)';
|
||||
JError::raiseError(500, $errmsg);
|
||||
}
|
||||
|
||||
// Determine the type of upload
|
||||
$default_uri_type = 'file';
|
||||
$uri_type = JRequest::getWord('uri', $default_uri_type);
|
||||
if ( !in_array( $uri_type, AttachmentsDefines::$LEGAL_URI_TYPES ) ) {
|
||||
// Make sure only legal values are entered
|
||||
$uri_type = 'file';
|
||||
}
|
||||
|
||||
// Set up the view to redisplay the form with warnings
|
||||
require_once(JPATH_COMPONENT_SITE.'/views/upload/view.html.php');
|
||||
$view = new AttachmentsViewUpload();
|
||||
|
||||
// Set up the view
|
||||
if ( $new_parent ) {
|
||||
$parent_id_str = (string)$parent_id . ",new";
|
||||
}
|
||||
else {
|
||||
$parent_id_str = (string)$parent_id;
|
||||
}
|
||||
AttachmentsHelper::add_view_urls($view, 'upload', $parent_id_str, $parent_type, null, $from);
|
||||
|
||||
// We do not have a real attachment yet so fake it
|
||||
$attachment = new JObject();
|
||||
|
||||
// Set up the defaults
|
||||
$attachment->uri_type = $uri_type;
|
||||
$attachment->state = $params->get('publish_default', false);
|
||||
$attachment->url = '';
|
||||
$attachment->url_relative = false;
|
||||
$attachment->url_verify = true;
|
||||
$attachment->display_name = '';
|
||||
$attachment->description = '';
|
||||
$attachment->user_field_1 = '';
|
||||
$attachment->user_field_2 = '';
|
||||
$attachment->user_field_3 = '';
|
||||
$attachment->parent_id = $parent_id;
|
||||
$attachment->parent_type = $parent_type;
|
||||
$attachment->parent_entity = $parent_entity;
|
||||
$attachment->parent_title = $parent_title;
|
||||
|
||||
$view->attachment = $attachment;
|
||||
|
||||
$view->parent = $parent;
|
||||
$view->new_parent = $new_parent;
|
||||
$view->Itemid = $Itemid;
|
||||
$view->from = $from;
|
||||
|
||||
$view->params = $params;
|
||||
|
||||
$view->error = false;
|
||||
$view->error_msg = false;
|
||||
|
||||
// Display the upload form
|
||||
$view->display();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Save a new or edited attachment
|
||||
*/
|
||||
public function save()
|
||||
{
|
||||
// Check for request forgeries
|
||||
JSession::checkToken() or die(JText::_('JINVALID_TOKEN'));
|
||||
|
||||
// Make sure that the user is logged in
|
||||
$user = JFactory::getUser();
|
||||
|
||||
// Get the parameters
|
||||
jimport('joomla.application.component.helper');
|
||||
$params = JComponentHelper::getParams('com_attachments');
|
||||
|
||||
// Get the article/parent handler
|
||||
$new_parent = JRequest::getBool('new_parent', false);
|
||||
$parent_type = JRequest::getCmd('parent_type', 'com_content');
|
||||
$parent_entity = JRequest::getCmd('parent_entity', 'default');
|
||||
JPluginHelper::importPlugin('attachments');
|
||||
$apm = getAttachmentsPluginManager();
|
||||
if ( !$apm->attachmentsPluginInstalled($parent_type) ) {
|
||||
$errmsg = JText::sprintf('ATTACH_ERROR_INVALID_PARENT_TYPE_S', $parent_type) . ' (ERR 5)';
|
||||
JError::raiseError(500, $errmsg);
|
||||
}
|
||||
$parent = $apm->getAttachmentsPlugin($parent_type);
|
||||
|
||||
$parent_entity = $parent->getCanonicalEntityId($parent_entity);
|
||||
$parent_entity_name = JText::_('ATTACH_' . $parent_entity);
|
||||
|
||||
// Make sure we have a valid parent ID
|
||||
$parent_id = JRequest::getInt('parent_id', -1);
|
||||
if ( !$new_parent && (($parent_id == 0) ||
|
||||
($parent_id == -1) ||
|
||||
!$parent->parentExists($parent_id, $parent_entity)) ) {
|
||||
$errmsg = JText::sprintf('ATTACH_ERROR_INVALID_PARENT_S_ID_N',
|
||||
$parent_entity_name , $parent_id) . ' (ERR 6)';
|
||||
JError::raiseError(500, $errmsg);
|
||||
}
|
||||
|
||||
// Verify that this user may add attachments to this parent
|
||||
if ( !$parent->userMayAddAttachment($parent_id, $parent_entity, $new_parent) ) {
|
||||
$errmsg = JText::sprintf('ATTACH_ERROR_NO_PERMISSION_TO_UPLOAD_S', $parent_entity_name) . ' (ERR 7)';
|
||||
JError::raiseError(500, $errmsg);
|
||||
}
|
||||
|
||||
// Get the Itemid
|
||||
$Itemid = JRequest::getInt('Itemid', 1);
|
||||
|
||||
// How to redirect?
|
||||
$from = JRequest::getWord('from', 'closeme');
|
||||
$uri = JFactory::getURI();
|
||||
$base_url = $uri->base(false);
|
||||
if ( $from ) {
|
||||
if ( $from == 'frontpage' ) {
|
||||
$redirect_to = $uri->root(true);
|
||||
}
|
||||
elseif ( $from == 'article' ) {
|
||||
$redirect_to = JRoute::_($base_url . "index.php?option=com_content&view=article&id=$parent_id", False);
|
||||
}
|
||||
else {
|
||||
$redirect_to = $uri->root(true);
|
||||
}
|
||||
}
|
||||
else {
|
||||
$redirect_to = $uri->root(true);
|
||||
}
|
||||
|
||||
// See if we should cancel
|
||||
if ( $_POST['submit'] == JText::_('ATTACH_CANCEL') ) {
|
||||
$msg = JText::_('ATTACH_UPLOAD_CANCELED');
|
||||
$this->setRedirect( $redirect_to, $msg );
|
||||
return;
|
||||
}
|
||||
|
||||
// Figure out if we are uploading or updating
|
||||
$save_type = JString::strtolower(JRequest::getWord('save_type'));
|
||||
if ( !in_array($save_type, AttachmentsDefines::$LEGAL_SAVE_TYPES) ) {
|
||||
$errmsg = JText::_('ATTACH_ERROR_INVALID_SAVE_PARAMETERS') . ' (ERR 8)';
|
||||
JError::raiseError(500, $errmsg);
|
||||
}
|
||||
|
||||
// If this is an update, get the attachment id
|
||||
$attachment_id = false;
|
||||
if ( $save_type == 'update' ) {
|
||||
$attachment_id = JRequest::getInt('id');
|
||||
}
|
||||
|
||||
// Bind the info from the form
|
||||
JTable::addIncludePath(JPATH_ADMINISTRATOR.'/components/com_attachments/tables');
|
||||
$attachment = JTable::getInstance('Attachment', 'AttachmentsTable');
|
||||
if ( $attachment_id && !$attachment->load($attachment_id) ) {
|
||||
$errmsg = JText::sprintf('ATTACH_ERROR_CANNOT_UPDATE_ATTACHMENT_INVALID_ID_N', $id) . ' (ERR 9)';
|
||||
JError::raiseError(500, $errmsg);
|
||||
}
|
||||
if (!$attachment->bind(JRequest::get('post'))) {
|
||||
$errmsg = $attachment->getError() . ' (ERR 10)';
|
||||
JError::raiseError(500, $errmsg);
|
||||
}
|
||||
|
||||
// Note what the old uri type is, if updating
|
||||
$old_uri_type = null;
|
||||
if ( $save_type == 'update' ) {
|
||||
$old_uri_type = $attachment->uri_type;
|
||||
}
|
||||
|
||||
// Figure out what the new URI is
|
||||
if ( $save_type == 'upload' ) {
|
||||
|
||||
// See if we are uploading a file or URL
|
||||
$new_uri_type = JRequest::getWord('uri_type');
|
||||
if ( $new_uri_type && !in_array( $new_uri_type, AttachmentsDefines::$LEGAL_URI_TYPES ) ) {
|
||||
// Make sure only legal values are entered
|
||||
$new_uri_type = '';
|
||||
}
|
||||
|
||||
// Fix the access level
|
||||
if ( !$params->get('allow_frontend_access_editing', false) ) {
|
||||
$attachment->access = $params->get('default_access_level', AttachmentsDefines::$DEFAULT_ACCESS_LEVEL_ID);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
elseif ( $save_type == 'update' ) {
|
||||
|
||||
// See if we are updating a file or URL
|
||||
$new_uri_type = JRequest::getWord('update');
|
||||
if ( $new_uri_type && !in_array( $new_uri_type, AttachmentsDefines::$LEGAL_URI_TYPES ) ) {
|
||||
// Make sure only legal values are entered
|
||||
$new_uri_type = '';
|
||||
}
|
||||
|
||||
// Since URLs can be edited, we always evaluate them from scratch
|
||||
if ( ($new_uri_type == '') && ($old_uri_type == 'url') ) {
|
||||
$new_uri_type = 'url';
|
||||
}
|
||||
|
||||
// Double-check to see if the URL changed
|
||||
$old_url = JRequest::getString('old_url');
|
||||
if ( !$new_uri_type && $old_url && ($old_url != $attachment->url) ) {
|
||||
$new_uri_type = 'url';
|
||||
}
|
||||
}
|
||||
|
||||
// Get more info about the type of upload/update
|
||||
$verify_url = false;
|
||||
$relative_url = false;
|
||||
if ( $new_uri_type == 'url' ) {
|
||||
if ( JRequest::getWord('verify_url') == 'verify' ) {
|
||||
$verify_url = true;
|
||||
}
|
||||
if ( JRequest::getWord('relative_url') == 'relative' ) {
|
||||
$relative_url = true;
|
||||
}
|
||||
}
|
||||
|
||||
// Handle the various ways this function might get invoked
|
||||
if ( $save_type == 'upload' ) {
|
||||
$attachment->created_by = $user->get('id');
|
||||
$attachment->parent_id = $parent_id;
|
||||
}
|
||||
|
||||
// Update the modified info
|
||||
$now = JFactory::getDate();
|
||||
$attachment->modified_by = $user->get('id');
|
||||
$attachment->modified = $now->toSql();
|
||||
|
||||
// Set up a couple of items that the upload function may need
|
||||
$parent->new = $new_parent;
|
||||
if ( $new_parent ) {
|
||||
$attachment->parent_id = null;
|
||||
$parent->title = '';
|
||||
}
|
||||
else {
|
||||
$attachment->parent_id = $parent_id;
|
||||
$parent->title = $parent->getTitle($parent_id, $parent_entity);
|
||||
}
|
||||
|
||||
// Upload new file/url and create/update the attachment
|
||||
if ( $new_uri_type == 'file' ) {
|
||||
|
||||
// Upload a new file
|
||||
$msg = AttachmentsHelper::upload_file($attachment, $parent, $attachment_id, $save_type);
|
||||
// NOTE: store() is not needed if upload_file() is called since it does it
|
||||
}
|
||||
|
||||
elseif ( $new_uri_type == 'url' ) {
|
||||
|
||||
$attachment->url_relative = $relative_url;
|
||||
$attachment->url_verify = $verify_url;
|
||||
|
||||
// Upload/add the new URL
|
||||
$msg = AttachmentsHelper::add_url($attachment, $parent, $verify_url, $relative_url,
|
||||
$old_uri_type, $attachment_id);
|
||||
// NOTE: store() is not needed if add_url() is called since it does it
|
||||
}
|
||||
|
||||
else {
|
||||
|
||||
// Save the updated attachment info
|
||||
if (!$attachment->store()) {
|
||||
$errmsg = $attachment->getError() . ' (ERR 11)';
|
||||
JError::raiseError(500, $errmsg);
|
||||
}
|
||||
|
||||
$lang = JFactory::getLanguage();
|
||||
$lang->load('com_attachments', JPATH_SITE);
|
||||
|
||||
$msg = JText::_('ATTACH_ATTACHMENT_UPDATED');
|
||||
}
|
||||
|
||||
// If we are supposed to close this iframe, do it now.
|
||||
if ( in_array( $from, $parent->knownFroms() ) ) {
|
||||
|
||||
// If there is no parent_id, the parent is being created, use the username instead
|
||||
if ( $new_parent ) {
|
||||
$pid = 0;
|
||||
}
|
||||
else {
|
||||
$pid = (int)$parent_id;
|
||||
}
|
||||
|
||||
// Close the iframe and refresh the attachments list in the parent window
|
||||
$base_url = $uri->root(true);
|
||||
$lang = JRequest::getCmd('lang', '');
|
||||
AttachmentsJavascript::closeIframeRefreshAttachments($base_url, $parent_type, $parent_entity, $pid, $lang, $from);
|
||||
exit();
|
||||
}
|
||||
|
||||
$this->setRedirect( $redirect_to, $msg );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Download a file
|
||||
*/
|
||||
public function download()
|
||||
{
|
||||
// Get the attachment ID
|
||||
$id = JRequest::getInt('id');
|
||||
if ( !is_numeric($id) ) {
|
||||
$errmsg = JText::sprintf('ATTACH_ERROR_INVALID_ATTACHMENT_ID_N', $id) . ' (ERR 12)';
|
||||
JError::raiseError(500, $errmsg);
|
||||
}
|
||||
|
||||
// NOTE: The helper download_attachment($id) function does the access check
|
||||
AttachmentsHelper::download_attachment($id);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Delete an attachment
|
||||
*/
|
||||
public function delete()
|
||||
{
|
||||
$db = JFactory::getDBO();
|
||||
|
||||
// Make sure we have a valid attachment ID
|
||||
$id = JRequest::getInt( 'id');
|
||||
if ( is_numeric($id) ) {
|
||||
$id = (int)$id;
|
||||
}
|
||||
else {
|
||||
$errmsg = JText::sprintf('ATTACH_ERROR_CANNOT_DELETE_INVALID_ATTACHMENT_ID_N', $id) . ' (ERR 13)';
|
||||
JError::raiseError(500, $errmsg);
|
||||
}
|
||||
|
||||
// Get the attachment info
|
||||
require_once(JPATH_COMPONENT_SITE.'/models/attachment.php');
|
||||
$model = new AttachmentsModelAttachment();
|
||||
$model->setId($id);
|
||||
$attachment = $model->getAttachment();
|
||||
if ( !$attachment ) {
|
||||
$errmsg = JText::sprintf('ATTACH_ERROR_CANNOT_DELETE_INVALID_ATTACHMENT_ID_N', $id) . ' (ERR 14)';
|
||||
JError::raiseError(500, $errmsg);
|
||||
}
|
||||
$filename_sys = $attachment->filename_sys;
|
||||
$filename = $attachment->filename;
|
||||
$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 15)';
|
||||
JError::raiseError(500, $errmsg);
|
||||
}
|
||||
$parent = $apm->getAttachmentsPlugin($parent_type);
|
||||
|
||||
$parent_entity_name = JText::_('ATTACH_' . $parent_entity);
|
||||
|
||||
// Check to make sure we can edit it
|
||||
if ( !$parent->userMayDeleteAttachment($attachment) ) {
|
||||
return JError::raiseError(404, JText::_('JERROR_ALERTNOAUTHOR') . ' (ERR 16)');
|
||||
}
|
||||
|
||||
// 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) ) {
|
||||
$errmsg = JText::sprintf('ATTACH_ERROR_CANNOT_DELETE_INVALID_S_ID_N',
|
||||
$parent_entity_name, $parent_id) . ' (ERR 17)';
|
||||
JError::raiseError(500, $errmsg);
|
||||
}
|
||||
|
||||
// See if this user can edit (or delete) the attachment
|
||||
if ( !$parent->userMayDeleteAttachment($attachment) ) {
|
||||
$errmsg = JText::sprintf('ATTACH_ERROR_NO_PERMISSION_TO_DELETE_S', $parent_entity_name) . ' (ERR 18)';
|
||||
JError::raiseError(500, $errmsg);
|
||||
}
|
||||
|
||||
// First delete the actual attachment files (if any)
|
||||
if ( $filename_sys ) {
|
||||
jimport('joomla.filesystem.file');
|
||||
if ( JFile::exists( $filename_sys )) {
|
||||
JFile::delete($filename_sys);
|
||||
}
|
||||
}
|
||||
|
||||
// Delete the entries in the attachments table
|
||||
$query = $db->getQuery(true);
|
||||
$query->delete('#__attachments')->where('id = '.(int)$id);
|
||||
$db->setQuery($query);
|
||||
if (!$db->query()) {
|
||||
$errmsg = $db->getErrorMsg() . ' (ERR 19)';
|
||||
JError::raiseError(500, $errmsg);
|
||||
}
|
||||
|
||||
// Clean up after ourselves
|
||||
AttachmentsHelper::clean_directory($filename_sys);
|
||||
|
||||
// Get the Itemid
|
||||
$Itemid = JRequest::getInt( 'Itemid', 1);
|
||||
|
||||
$msg = JText::_('ATTACH_DELETED_ATTACHMENT') . " '$filename'";
|
||||
|
||||
// Figure out how to redirect
|
||||
$from = JRequest::getWord('from', 'closeme');
|
||||
$uri = JFactory::getURI();
|
||||
if ( in_array($from, $parent->knownFroms()) ) {
|
||||
|
||||
// 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
|
||||
$base_url = $uri->root(true);
|
||||
$lang = JRequest::getCmd('lang', '');
|
||||
AttachmentsJavascript::closeIframeRefreshAttachments($base_url, $parent_type, $parent_entity, $pid, $lang, $from);
|
||||
exit();
|
||||
}
|
||||
else {
|
||||
$redirect_to = $uri->root(true);
|
||||
}
|
||||
|
||||
$this->setRedirect( $redirect_to, $msg );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Show the warning for deleting an attachment
|
||||
*/
|
||||
public function delete_warning()
|
||||
{
|
||||
// Make sure we have a valid attachment ID
|
||||
$attachment_id = JRequest::getInt('id');
|
||||
if ( is_numeric($attachment_id) ) {
|
||||
$attachment_id = (int)$attachment_id;
|
||||
}
|
||||
else {
|
||||
$errmsg = JText::sprintf('ATTACH_ERROR_CANNOT_DELETE_INVALID_ATTACHMENT_ID_N', $attachment_id) . ' (ERR 20)';
|
||||
JError::raiseError(500, $errmsg);
|
||||
}
|
||||
|
||||
// Get the attachment record
|
||||
JTable::addIncludePath(JPATH_ADMINISTRATOR.'/components/com_attachments/tables');
|
||||
$attachment = JTable::getInstance('Attachment', 'AttachmentsTable');
|
||||
if ( !$attachment->load($attachment_id) ) {
|
||||
$errmsg = JText::sprintf('ATTACH_ERROR_CANNOT_DELETE_INVALID_ATTACHMENT_ID_N', $attachment_id) . ' (ERR 21)';
|
||||
JError::raiseError(500, $errmsg);
|
||||
}
|
||||
|
||||
// Get the parent object
|
||||
$parent_type = $attachment->parent_type;
|
||||
JPluginHelper::importPlugin('attachments');
|
||||
$apm = getAttachmentsPluginManager();
|
||||
if ( !$apm->attachmentsPluginInstalled($parent_type) ) {
|
||||
$errmsg = JText::sprintf('ATTACH_ERROR_INVALID_PARENT_TYPE_S', $parent_type) . ' (ERR 22)';
|
||||
JError::raiseError(500, $errmsg);
|
||||
}
|
||||
$parent = $apm->getAttachmentsPlugin($parent_type);
|
||||
|
||||
// Check to make sure we can edit it
|
||||
$parent_id = $attachment->parent_id;
|
||||
if ( !$parent->userMayDeleteAttachment($attachment) ) {
|
||||
$errmsg = JText::_('ATTACH_ERROR_NO_PERMISSION_TO_DELETE_ATTACHMENT') . ' (ERR 23)';
|
||||
JError::raiseError(500, $errmsg);
|
||||
}
|
||||
|
||||
// Set up the view
|
||||
require_once(JPATH_COMPONENT.'/views/warning/view.html.php');
|
||||
$view = new AttachmentsViewWarning( );
|
||||
$view->parent_id = $parent_id;
|
||||
$view->option = JRequest::getCmd('option');
|
||||
$view->from = JRequest::getWord('from', 'closeme');
|
||||
$view->tmpl = JRequest::getWord('tmpl');
|
||||
|
||||
// Prepare for the query
|
||||
$view->warning_title = JText::_('ATTACH_WARNING');
|
||||
if ( $attachment->uri_type == 'file' ) {
|
||||
$fname = "( {$attachment->filename} )";
|
||||
}
|
||||
else {
|
||||
$fname = "( {$attachment->url} )";
|
||||
}
|
||||
$view->warning_question = JText::_('ATTACH_REALLY_DELETE_ATTACHMENT') . '<br/>' . $fname;
|
||||
|
||||
$base_url = JFactory::getURI()->base(false);
|
||||
$delete_url = $base_url . "index.php?option=com_attachments&task=delete&id=$attachment_id";
|
||||
$delete_url = JRoute::_($delete_url);
|
||||
$view->action_url = $delete_url;
|
||||
$view->action_button_label = JText::_('ATTACH_DELETE');
|
||||
|
||||
$view->display();
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Display a form for updating/editing an attachment
|
||||
*/
|
||||
public function update()
|
||||
{
|
||||
// Call with: index.php?option=com_attachments&task=update&id=1&tmpl=component
|
||||
// or: component/attachments/update/id/1/tmpl/component
|
||||
|
||||
// Make sure we have a valid attachment ID
|
||||
$id = JRequest::getInt( 'id');
|
||||
if ( is_numeric($id) ) {
|
||||
$id = (int)$id;
|
||||
}
|
||||
else {
|
||||
$errmsg = JText::sprintf('ATTACH_ERROR_INVALID_ATTACHMENT_ID_N', $id) . ' (ERR 24)';
|
||||
JError::raiseError(500, $errmsg);
|
||||
}
|
||||
|
||||
// Get the attachment record
|
||||
require_once(JPATH_COMPONENT_SITE.'/models/attachment.php');
|
||||
$model = new AttachmentsModelAttachment();
|
||||
$model->setId($id);
|
||||
$attachment = $model->getAttachment();
|
||||
if ( !$attachment ) {
|
||||
$errmsg = JText::sprintf('ATTACH_ERROR_CANNOT_UPDATE_ATTACHMENT_INVALID_ID_N', $id) . ' (ERR 25)';
|
||||
JError::raiseError(500, $errmsg);
|
||||
}
|
||||
|
||||
// Get the component parameters
|
||||
jimport('joomla.application.component.helper');
|
||||
$params = JComponentHelper::getParams('com_attachments');
|
||||
|
||||
// Get the article/parent handler
|
||||
$parent_id = $attachment->parent_id;
|
||||
$parent_type = $attachment->parent_type;
|
||||
$parent_entity = $attachment->parent_entity;
|
||||
JPluginHelper::importPlugin('attachments');
|
||||
$apm = getAttachmentsPluginManager();
|
||||
if ( !$apm->attachmentsPluginInstalled($parent_type) ) {
|
||||
$errmsg = JText::sprintf('ATTACH_ERROR_INVALID_PARENT_TYPE_S', $parent_type) . ' (ERR 26)';
|
||||
JError::raiseError(500, $errmsg);
|
||||
}
|
||||
$parent = $apm->getAttachmentsPlugin($parent_type);
|
||||
|
||||
// Check to make sure we can edit it
|
||||
if ( !$parent->userMayEditAttachment($attachment) ) {
|
||||
return JError::raiseError(404, JText::_('JERROR_ALERTNOAUTHOR') . ' (ERR 27)');
|
||||
}
|
||||
|
||||
// Set up the entity name for display
|
||||
$parent_entity_name = JText::_('ATTACH_' . $parent_entity);
|
||||
|
||||
// Verify that this user may add attachments to this parent
|
||||
$user = JFactory::getUser();
|
||||
$new_parent = false;
|
||||
if ( $parent_id === null ) {
|
||||
$parent_id = 0;
|
||||
$new_parent = true;
|
||||
}
|
||||
|
||||
// Make sure the attachments directory exists
|
||||
$upload_dir = JPATH_BASE.'/'.AttachmentsDefines::$ATTACHMENTS_SUBDIR;
|
||||
$secure = $params->get('secure', false);
|
||||
if ( !AttachmentsHelper::setup_upload_directory( $upload_dir, $secure ) ) {
|
||||
$errmsg = JText::sprintf('ATTACH_ERROR_UNABLE_TO_SETUP_UPLOAD_DIR_S', $upload_dir) . ' (ERR 28)';
|
||||
JError::raiseError(500, $errmsg);
|
||||
}
|
||||
|
||||
// Make sure the update parameter is legal
|
||||
$update = JRequest::getWord('update');
|
||||
if ( $update && !in_array($update, AttachmentsDefines::$LEGAL_URI_TYPES) ) {
|
||||
$update = false;
|
||||
}
|
||||
|
||||
// Suppress the display filename if we are switching from file to url
|
||||
$display_name = $attachment->display_name;
|
||||
if ( $update && ($update != $attachment->uri_type) ) {
|
||||
$attachment->display_name = '';
|
||||
}
|
||||
|
||||
// Set up the view
|
||||
require_once(JPATH_COMPONENT_SITE.'/views/update/view.html.php');
|
||||
$view = new AttachmentsViewUpdate();
|
||||
$from = JRequest::getWord('from', 'closeme');
|
||||
AttachmentsHelper::add_view_urls($view, 'update', $parent_id,
|
||||
$attachment->parent_type, $id, $from);
|
||||
|
||||
$view->update = $update;
|
||||
$view->new_parent = $new_parent;
|
||||
|
||||
$view->attachment = $attachment;
|
||||
|
||||
$view->parent = $parent;
|
||||
$view->params = $params;
|
||||
|
||||
$view->from = $from;
|
||||
$view->Itemid = JRequest::getInt('Itemid', 1);
|
||||
|
||||
$view->error = false;
|
||||
$view->error_msg = false;
|
||||
|
||||
$view->display();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return the attachments list as HTML (for use by Ajax)
|
||||
*/
|
||||
public function attachmentsList()
|
||||
{
|
||||
$parent_id = JRequest::getInt('parent_id', false);
|
||||
$parent_type = JRequest::getWord('parent_type', '');
|
||||
$parent_entity = JRequest::getWord('parent_entity', 'default');
|
||||
$show_links = JRequest::getBool('show_links', true);
|
||||
$allow_edit = JRequest::getBool('allow_edit', true);
|
||||
$from = JRequest::getWord('from', 'closeme');
|
||||
$title = '';
|
||||
|
||||
$response = '';
|
||||
|
||||
if ( ($parent_id === false) || ($parent_type == '') ) {
|
||||
return '';
|
||||
}
|
||||
|
||||
// Allow remapping of parent ID (eg, for Joomfish)
|
||||
$lang = JRequest::getWord('lang', '');
|
||||
if ($lang and jimport('attachments_remapper.remapper'))
|
||||
{
|
||||
$parent_id = AttachmentsRemapper::remapParentID($parent_id, $parent_type, $parent_entity);
|
||||
}
|
||||
|
||||
require_once(JPATH_SITE.'/components/com_attachments/controllers/attachments.php');
|
||||
$controller = new AttachmentsControllerAttachments();
|
||||
$response = $controller->displayString($parent_id, $parent_type, $parent_entity,
|
||||
$title, $show_links, $allow_edit, false, $from);
|
||||
echo $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* Request the user log in
|
||||
*/
|
||||
public function requestLogin()
|
||||
{
|
||||
// Set up the view to redisplay the form with warnings
|
||||
require_once(JPATH_COMPONENT_SITE . '/views/login/view.html.php');
|
||||
$view = new AttachmentsViewLogin();
|
||||
|
||||
// Display the view
|
||||
$view->return_url = JRequest::getString('return');
|
||||
$view->display(null, false, false);
|
||||
}
|
||||
|
||||
}
|
||||
148
components/com_attachments/controllers/attachments.php
Normal file
148
components/com_attachments/controllers/attachments.php
Normal file
@ -0,0 +1,148 @@
|
||||
<?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 AttachmentsControllerAttachments extends JControllerLegacy
|
||||
{
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param array $default : An optional associative array of configuration settings.
|
||||
* Recognized key values include 'name', 'default_task', 'model_path', and
|
||||
* 'view_path' (this list is not meant to be comprehensive).
|
||||
*/
|
||||
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 59)';
|
||||
JError::raiseError(500, $errmsg);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Disable the default display function
|
||||
*/
|
||||
public function display($cachable = false, $urlparams = false)
|
||||
{
|
||||
// Do nothing (not sure why this works...)
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 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();
|
||||
if ( !$model ) {
|
||||
$errmsg = JText::_('ATTACH_ERROR_UNABLE_TO_FIND_MODEL') . ' (ERR 60)';
|
||||
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 article/content item
|
||||
$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 61)';
|
||||
JError::raiseError(500, $errmsg);
|
||||
}
|
||||
$view->setModel($model);
|
||||
|
||||
// Construct the update URL template
|
||||
$base_url = JFactory::getURI()->base(false);
|
||||
$update_url = $base_url . "index.php?option=com_attachments&task=update&id=%d";
|
||||
$update_url .= "&from=$from&tmpl=component";
|
||||
$update_url = JRoute::_($update_url);
|
||||
$view->update_url = $update_url;
|
||||
|
||||
// Construct the delete URL template
|
||||
$delete_url = $base_url . "index.php?option=com_attachments&task=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";
|
||||
$delete_url = JRoute::_($delete_url);
|
||||
$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;
|
||||
}
|
||||
|
||||
}
|
||||
1
components/com_attachments/controllers/index.html
Normal file
1
components/com_attachments/controllers/index.html
Normal file
@ -0,0 +1 @@
|
||||
<html><body bgcolor="#FFFFFF"></body></html>
|
||||
105
components/com_attachments/defines.php
Normal file
105
components/com_attachments/defines.php
Normal file
@ -0,0 +1,105 @@
|
||||
<?php
|
||||
/**
|
||||
* Attachments component
|
||||
*
|
||||
* @package Attachments
|
||||
* @subpackage Attachments_Component
|
||||
*
|
||||
* @author Jonathan M. Cameron <jmcameron@jmcameron.net>
|
||||
* @copyright Copyright (C) 2011-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/
|
||||
*/
|
||||
|
||||
// No direct access.
|
||||
defined('_JEXEC') or die('Restricted access');
|
||||
|
||||
/**
|
||||
* Attachments extension definies
|
||||
*
|
||||
* @package Attachments
|
||||
*
|
||||
* @since 2.2
|
||||
*/
|
||||
class AttachmentsDefines
|
||||
{
|
||||
/** The Attachments extension version number
|
||||
*/
|
||||
public static $ATTACHMENTS_VERSION = '3.2.6';
|
||||
|
||||
/** The Attachments extension version date
|
||||
*/
|
||||
public static $ATTACHMENTS_VERSION_DATE = 'March 26, 2018';
|
||||
|
||||
/** Project URL
|
||||
*/
|
||||
public static $PROJECT_URL = 'http://joomlacode.org/gf/project/attachments3/';
|
||||
|
||||
/** Supported save types for uploading/updating
|
||||
*/
|
||||
public static $LEGAL_SAVE_TYPES = Array('upload', 'update');
|
||||
|
||||
/** Supported URI types for uploading/updating
|
||||
*/
|
||||
public static $LEGAL_URI_TYPES = Array('file', 'url');
|
||||
|
||||
/** Default access level (if default_access_level parameter is not set)
|
||||
*
|
||||
* 1 = Public
|
||||
* 2 = Registered
|
||||
*/
|
||||
public static $DEFAULT_ACCESS_LEVEL_ID = '2';
|
||||
|
||||
/** Default 'Public' access level (in case it is different on this system)
|
||||
*/
|
||||
public static $PUBLIC_ACCESS_LEVEL_ID = '1';
|
||||
|
||||
/** Default permissions for new attachments rules
|
||||
*
|
||||
* These are the default settings for the custom ACL permissions for the
|
||||
* Attachments extension.
|
||||
*
|
||||
* Be careul if you edit this to conform to the proper json syntax!
|
||||
*
|
||||
* NB: Unfortunately, the syntax for setting a static variable does not
|
||||
* allow breaking the string up with dots to join the parts to make
|
||||
* this easier to read.
|
||||
*/
|
||||
public static $DEFAULT_ATTACHMENTS_ACL_PERMISSIONS = '{"attachments.delete.own":{"6":1,"3":1},"attachments.edit.state.own":{"6":1,"4":1},"attachments.edit.state.ownparent":{"6":1,"4":1},"attachments.edit.ownparent":{"6":1,"3":1},"attachments.delete.ownparent":{"6":1,"3":1}}';
|
||||
|
||||
/** Maximum filename length (MUST match the `filename` SQL definition)
|
||||
*/
|
||||
public static $MAXIMUM_FILENAME_LENGTH = 256;
|
||||
|
||||
/** Maximum filename path length (MUST match the `filename_sys` SQL definition)
|
||||
*/
|
||||
public static $MAXIMUM_FILENAME_SYS_LENGTH = 512;
|
||||
|
||||
/** Maximum URL length (MUST match the `url` SQL definition)
|
||||
*/
|
||||
public static $MAXIMUM_URL_LENGTH = 1024;
|
||||
|
||||
/** Attachments subdirectory
|
||||
*
|
||||
* NOTE: If you have any existing attachments, follow one of these procedures
|
||||
*
|
||||
* 1. If you do not care to keep any existing attachments, follow these steps:
|
||||
* - Suspend front-end operation of your website
|
||||
* - In the back end attachments page, delete all attachments
|
||||
* - Delete the attachments directory
|
||||
* - Change the value below and save this file
|
||||
* - Resume front-end operation of your website
|
||||
*
|
||||
* 2. If you are simply renaming the attachments directory, do the following
|
||||
* steps:
|
||||
* - Suspend front-end operation of your website
|
||||
* - Rename the attachments directory (must be within the top
|
||||
* directory of your website)
|
||||
* - Change the value below and save this file
|
||||
* - In the back end attachments page, under the "Utilities" command
|
||||
* on the right end of the toolbar, choose the "Regenerate system filenames"
|
||||
* command
|
||||
* - Resume front-end operation of your website
|
||||
*/
|
||||
public static $ATTACHMENTS_SUBDIR = 'attachments';
|
||||
}
|
||||
307
components/com_attachments/file_types.php
Normal file
307
components/com_attachments/file_types.php
Normal file
@ -0,0 +1,307 @@
|
||||
<?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');
|
||||
|
||||
/**
|
||||
* A utility class to help deal with file types
|
||||
*
|
||||
* @package Attachments
|
||||
*/
|
||||
class AttachmentsFileTypes {
|
||||
|
||||
/** Array of lookups for icon filename given a filename extension */
|
||||
static $attachments_icon_from_file_extension =
|
||||
Array( 'aif' => 'music.gif',
|
||||
'aiff' => 'music.gif',
|
||||
'avi' => 'video.gif',
|
||||
'bmp' => 'image.gif',
|
||||
'bz2' => 'archive.gif',
|
||||
'c' => 'c.gif',
|
||||
'c++' => 'cpp.gif',
|
||||
'cab' => 'zip.gif',
|
||||
'cc' => 'cpp.gif',
|
||||
'cpp' => 'cpp.gif',
|
||||
'css' => 'css.gif',
|
||||
'csv' => 'csv.gif',
|
||||
'doc' => 'word.gif',
|
||||
'docx' => 'wordx.gif',
|
||||
'eps' => 'eps.gif',
|
||||
'gif' => 'image.gif',
|
||||
'gz' => 'archive.gif',
|
||||
'h' => 'h.gif',
|
||||
'iv' => '3d.gif',
|
||||
'jpg' => 'image.gif',
|
||||
'js' => 'js.gif',
|
||||
'midi' => 'midi.gif',
|
||||
'mov' => 'mov.gif',
|
||||
'mp3' => 'music.gif',
|
||||
'mpeg' => 'video.gif',
|
||||
'mpg' => 'video.gif',
|
||||
'odg' => 'oo-draw.gif',
|
||||
'odp' => 'oo-impress.gif',
|
||||
'ods' => 'oo-calc.gif',
|
||||
'odt' => 'oo-write.gif',
|
||||
'pdf' => 'pdf.gif',
|
||||
'php' => 'php.gif',
|
||||
'png' => 'image.gif',
|
||||
'pps' => 'ppt.gif',
|
||||
'ppt' => 'ppt.gif',
|
||||
'pptx' => 'pptx.gif',
|
||||
'ps' => 'ps.gif',
|
||||
'ra' => 'audio.gif',
|
||||
'ram' => 'audio.gif',
|
||||
'rar' => 'archive.gif',
|
||||
'rtf' => 'rtf.gif',
|
||||
'sql' => 'sql.gif',
|
||||
'swf' => 'flash.gif',
|
||||
'tar' => 'archive.gif',
|
||||
'txt' => 'text.gif',
|
||||
'vcf' => 'vcard.gif',
|
||||
'vrml' => '3d.gif',
|
||||
'wav' => 'audio.gif',
|
||||
'wma' => 'music.gif',
|
||||
'wmv' => 'video.gif',
|
||||
'wrl' => '3d.gif',
|
||||
'xls' => 'excel.gif',
|
||||
'xlsx' => 'excelx.gif',
|
||||
'xml' => 'xml.gif',
|
||||
'zip' => 'zip.gif',
|
||||
|
||||
// Artificial
|
||||
'_generic' => 'generic.gif',
|
||||
'_link' => 'link.gif',
|
||||
);
|
||||
|
||||
/** Array of lookups for icon filename from mime type */
|
||||
static $attachments_icon_from_mime_type =
|
||||
Array( 'application/bzip2' => 'archive.gif',
|
||||
'application/excel' => 'excel.gif',
|
||||
'application/msword' => 'word.gif',
|
||||
'application/pdf' => 'pdf.gif',
|
||||
'application/postscript' => 'ps.gif',
|
||||
'application/powerpoint' => 'ppt.gif',
|
||||
'application/vnd.ms-cab-compressed' => 'zip.gif',
|
||||
'application/vnd.ms-excel' => 'excel.gif',
|
||||
'application/vnd.ms-powerpoint' => 'ppt.gif',
|
||||
'application/vnd.ms-pps' => 'ppt.gif',
|
||||
'application/vnd.ms-word' => 'word.gif',
|
||||
'application/vnd.oasis.opendocument.graphics' => 'oo-draw.gif',
|
||||
'application/vnd.oasis.opendocument.presentation' => 'oo-impress.gif',
|
||||
'application/vnd.oasis.opendocument.spreadsheet' => 'oo-calc.gif',
|
||||
'application/vnd.oasis.opendocument.text' => 'oo-write.gif',
|
||||
'application/vnd.openxmlformats' => 'xml.gif',
|
||||
'application/vnd.openxmlformats-officedocument.presentationml.presentation' => 'pptx.gif',
|
||||
'application/vnd.openxmlformats-officedocument.presentationml.slideshow' => 'ppt.gif',
|
||||
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' => 'xlsx.gif',
|
||||
'application/vnd.openxmlformats-officedocument.wordprocessingml.document' => 'wordx.gif',
|
||||
'application/x-bz2' => 'archive.gif',
|
||||
'application/x-gzip' => 'archive.gif',
|
||||
'application/x-javascript' => 'js.gif',
|
||||
'application/x-midi' => 'midi.gif',
|
||||
'application/x-shockwave-flash' => 'flash.gif',
|
||||
'application/x-rar-compressed' => 'archive.gif',
|
||||
'application/x-tar' => 'archive.gif',
|
||||
'application/x-vrml' => '3d.gif',
|
||||
'application/x-zip' => 'zip.gif',
|
||||
'application/xml' => 'xml.gif',
|
||||
'audio/mpeg' => 'music.gif',
|
||||
'audio/x-aiff' => 'music.gif',
|
||||
'audio/x-ms-wma' => 'music.gif',
|
||||
'audio/x-pn-realaudio' => 'audio.gif',
|
||||
'audio/x-wav' => 'audio.gif',
|
||||
'image/bmp' => 'image.gif',
|
||||
'image/gif' => 'image.gif',
|
||||
'image/jpeg' => 'image.gif',
|
||||
'image/png' => 'image.gif',
|
||||
'model/vrml' => '3d.gif',
|
||||
'text/css' => 'css.gif',
|
||||
'text/html' => 'generic.gif',
|
||||
'text/plain' => 'text.gif',
|
||||
'text/rtf' => 'rtf.gif',
|
||||
'text/x-vcard' => 'vcard.gif',
|
||||
'video/mpeg' => 'video.gif',
|
||||
'video/quicktime' => 'mov.gif',
|
||||
'video/x-ms-wmv' => 'video.gif',
|
||||
'video/x-msvideo' => 'video.gif',
|
||||
|
||||
// Artificial
|
||||
'link/generic' => 'generic.gif',
|
||||
'link/unknown' => 'link.gif'
|
||||
);
|
||||
|
||||
/** Array of lookups for mime type from filename extension */
|
||||
static $attachments_mime_type_from_extension =
|
||||
Array( 'aif' => 'audio/x-aiff',
|
||||
'aiff' => 'audio/x-aiff',
|
||||
'avi' => 'video/x-msvideo',
|
||||
'bmp' => 'image/bmp',
|
||||
'bz2' => 'application/x-bz2',
|
||||
'c' => 'text/plain',
|
||||
'c++' => 'text/plain',
|
||||
'cab' => 'application/vnd.ms-cab-compressed',
|
||||
'cc' => 'text/plain',
|
||||
'cpp' => 'text/plain',
|
||||
'css' => 'text/css',
|
||||
'csv' => 'text/csv',
|
||||
'doc' => 'application/msword',
|
||||
'docx' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
|
||||
'eps' => 'application/postscript',
|
||||
'gif' => 'image/gif',
|
||||
'gz' => 'application/x-gzip',
|
||||
'h' => 'text/plain',
|
||||
'iv' => 'graphics/x-inventor',
|
||||
'jpg' => 'image/jpeg',
|
||||
'js' => 'application/x-javascript',
|
||||
'midi' => 'application/x-midi',
|
||||
'mov' => 'video/quicktime',
|
||||
'mp3' => 'audio/mpeg',
|
||||
'mpeg' => 'audio/mpeg',
|
||||
'mpg' => 'audio/mpeg',
|
||||
'odg' => 'application/vnd.oasis.opendocument.graphics',
|
||||
'odp' => 'application/vnd.oasis.opendocument.presentation',
|
||||
'ods' => 'application/vnd.oasis.opendocument.spreadsheet',
|
||||
'odt' => 'application/vnd.oasis.opendocument.text',
|
||||
'pdf' => 'application/pdf',
|
||||
'php' => 'text/plain',
|
||||
'png' => 'image/png',
|
||||
'pps' => 'application/vnd.ms-powerpoint',
|
||||
'ppt' => 'application/vnd.ms-powerpoint',
|
||||
'pptx' => 'application/vnd.openxmlformats-officedocument.presentationml.presentation',
|
||||
'ps' => 'application/postscript',
|
||||
'ra' => 'audio/x-pn-realaudio',
|
||||
'ram' => 'audio/x-pn-realaudio',
|
||||
'rar' => 'application/x-rar-compressed',
|
||||
'rtf' => 'application/rtf',
|
||||
'sql' => 'text/plain',
|
||||
'swf' => 'application/x-shockwave-flash',
|
||||
'tar' => 'application/x-tar',
|
||||
'txt' => 'text/plain',
|
||||
'vcf' => 'text/x-vcard',
|
||||
'vrml' => 'application/x-vrml',
|
||||
'wav' => 'audio/x-wav',
|
||||
'wma' => 'audio/x-ms-wma',
|
||||
'wmv' => 'video/x-ms-wmv',
|
||||
'wrl' => 'x-world/x-vrml',
|
||||
'xls' => 'application/vnd.ms-excel',
|
||||
'xlsx' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
|
||||
'xml' => 'application/xml',
|
||||
'zip' => 'application/x-zip'
|
||||
);
|
||||
|
||||
/** Array of known PDF mime types */
|
||||
static $attachments_pdf_mime_types =
|
||||
array('application/pdf',
|
||||
'application/x-pdf',
|
||||
'application/vnd.fdf',
|
||||
'application/download',
|
||||
'application/x-download',
|
||||
'binary/octet-stream'
|
||||
);
|
||||
|
||||
|
||||
/**
|
||||
* Get the icon filename for a specific filename (or mime type)
|
||||
*
|
||||
* @param string $filename the filename to check
|
||||
* @param string $mime_type the MIME type to check (if the filename fails)
|
||||
*
|
||||
* @return the icon filename (or '' if none is found)
|
||||
*/
|
||||
public static function icon_filename($filename, $mime_type)
|
||||
{
|
||||
// Recognize some special cases first
|
||||
if ( ($mime_type == 'link/unknown') OR ($mime_type == 'unknown') ) {
|
||||
return 'link.gif';
|
||||
}
|
||||
if ( $mime_type == 'link/broken' ) {
|
||||
return 'link_bad.gif';
|
||||
}
|
||||
|
||||
if ( $filename ) {
|
||||
|
||||
// Make sure it is a real filename
|
||||
if (strpos($filename, '.') === false) {
|
||||
// Do not know any better, assume it is text
|
||||
return 'text/plain';
|
||||
}
|
||||
|
||||
$path_info = pathinfo($filename);
|
||||
|
||||
// Try the extension first
|
||||
$extension = JString::strtolower($path_info['extension']);
|
||||
if ( array_key_exists( $extension, AttachmentsFileTypes::$attachments_icon_from_file_extension ) ) {
|
||||
$iconf = AttachmentsFileTypes::$attachments_icon_from_file_extension[$extension];
|
||||
if ( JString::strlen($iconf) > 0 ) {
|
||||
return $iconf;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
else {
|
||||
|
||||
// Try the mime type
|
||||
if ( array_key_exists( $mime_type, AttachmentsFileTypes::$attachments_icon_from_mime_type ) ) {
|
||||
$iconf = AttachmentsFileTypes::$attachments_icon_from_mime_type[$mime_type];
|
||||
if ( $iconf && (JString::strlen($iconf) > 0) ) {
|
||||
return $iconf;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get an array of unique icon filenames
|
||||
*
|
||||
* @return an array of unique icon filenames
|
||||
*/
|
||||
public static function unique_icon_filenames()
|
||||
{
|
||||
$vals = array_unique(array_values(AttachmentsFileTypes::$attachments_icon_from_file_extension));
|
||||
sort($vals);
|
||||
|
||||
return $vals;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the mime type for a specific file
|
||||
*
|
||||
* @param string $filename the filename to check
|
||||
*
|
||||
* @return the mime type string
|
||||
*/
|
||||
public static function mime_type($filename)
|
||||
{
|
||||
$path_info = pathinfo($filename);
|
||||
|
||||
// Make sure it is a real filename
|
||||
if (strpos($filename, '.') === false) {
|
||||
return 'unknown';
|
||||
}
|
||||
|
||||
// Try the extension first
|
||||
$extension = strtolower($path_info['extension']);
|
||||
if ( array_key_exists($extension, AttachmentsFileTypes::$attachments_mime_type_from_extension) ) {
|
||||
$mime_type = AttachmentsFileTypes::$attachments_mime_type_from_extension[$extension];
|
||||
if ( strlen($mime_type) > 0 )
|
||||
return $mime_type;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
1887
components/com_attachments/helper.php
Normal file
1887
components/com_attachments/helper.php
Normal file
File diff suppressed because it is too large
Load Diff
1
components/com_attachments/index.html
Normal file
1
components/com_attachments/index.html
Normal file
@ -0,0 +1 @@
|
||||
<html><body bgcolor="#FFFFFF"></body></html>
|
||||
74
components/com_attachments/javascript.php
Normal file
74
components/com_attachments/javascript.php
Normal file
@ -0,0 +1,74 @@
|
||||
<?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');
|
||||
|
||||
/**
|
||||
* A class for attachments javascript functions
|
||||
*
|
||||
* @package Attachments
|
||||
*/
|
||||
class AttachmentsJavascript
|
||||
{
|
||||
/**
|
||||
* Set up the appropriate Javascript framework (Mootools or jQuery)
|
||||
*/
|
||||
public static function setupJavascript($add_refresh_script = true)
|
||||
{
|
||||
if (version_compare(JVERSION, '3.0', 'ge'))
|
||||
{
|
||||
JHtml::_('behavior.framework', true);
|
||||
JHtml::_('behavior.modal', 'a.modal');
|
||||
}
|
||||
else
|
||||
{
|
||||
// up the style sheet (to get the visual for the button working)
|
||||
JHtml::_('behavior.mootools');
|
||||
}
|
||||
if ($add_refresh_script)
|
||||
{
|
||||
JHtml::script('com_attachments/attachments_refresh.js', false, true);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Close the iframe
|
||||
*/
|
||||
public static function closeIframeRefreshAttachments($base_url, $parent_type, $parent_entity, $parent_id, $lang, $from)
|
||||
{
|
||||
echo "<script type=\"text/javascript\">
|
||||
window.parent.refreshAttachments(\"$base_url\",\"$parent_type\",\"$parent_entity\",$parent_id,\"$lang\",\"$from\");
|
||||
window.parent.SqueezeBox.close();
|
||||
</script>";
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set up the Javascript for the modal button
|
||||
*/
|
||||
public static function setupModalJavascript()
|
||||
{
|
||||
JHtml::_('behavior.modal', 'a.modal-button');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Close the modal window and reload the parent
|
||||
*/
|
||||
public static function closeModal()
|
||||
{
|
||||
echo '<script>var myparent = window.parent; window.parent.SqueezeBox.close(); myparent.location.reload();</script>';
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,118 @@
|
||||
; en-GB.com_attachments.ini (site component)
|
||||
; 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
|
||||
|
||||
; For forms, etc, from the front end
|
||||
|
||||
ATTACH_ACCESS_COLON="Access: "
|
||||
ATTACH_ACCESS_LEVEL_TOOLTIP="Access level defining who can view or download this attachment."
|
||||
ATTACH_ADD_ATTACHMENT="Add attachment"
|
||||
ATTACH_ADD_URL="Add URL"
|
||||
ATTACH_ATTACHMENT="Attachment"
|
||||
ATTACH_ATTACHMENTS="Attachments"
|
||||
ATTACH_ATTACHMENT_FILENAME_URL="Attachment Filename / URL"
|
||||
ATTACH_ATTACHMENT_SAVED="Attachment saved!"
|
||||
ATTACH_ATTACHMENT_UPDATED="Attachment updated!"
|
||||
ATTACH_ATTACH_FILE_COLON="Attach file:"
|
||||
ATTACH_CANCEL="Cancel"
|
||||
ATTACH_CHANGES_TO_ATTACHMENT_SAVED="Changes to attachment saved"
|
||||
ATTACH_CHANGE_FILE="Update File"
|
||||
ATTACH_CHANGE_FILE_TOOLTIP="Update the file for this attachment. (Other changes on this form will be lost.)"
|
||||
ATTACH_CHANGE_TO_FILE="Change to File"
|
||||
ATTACH_CHANGE_TO_FILE_TOOLTIP="Attach a file for this attachment. (Other changes on this form will be lost.)"
|
||||
ATTACH_CHANGE_TO_URL="Change to URL"
|
||||
ATTACH_CHANGE_TO_URL_TOOLTIP="Change uploaded file to a URL/link. (Other changes on this form will be lost.)"
|
||||
ATTACH_DELETE="Delete"
|
||||
ATTACH_DELETED_ATTACHMENT="Deleted attachment"
|
||||
ATTACH_DESCRIPTION="Description"
|
||||
ATTACH_DESCRIPTION_COLON="Description:"
|
||||
ATTACH_DISPLAY_FILENAME_OPTIONAL_COLON="Display Filename (optional):"
|
||||
ATTACH_DISPLAY_FILENAME_TOOLTIP="Optional: Enter an alternate filename or label to display instead of the full filename."
|
||||
ATTACH_DISPLAY_URL_COLON="Display URL:"
|
||||
ATTACH_DISPLAY_URL_TOOLTIP="Optional: Enter an alternate URL or label to display instead of the full URL."
|
||||
ATTACH_ENTER_NEW_URL_COLON="Enter new URL:"
|
||||
ATTACH_ENTER_URL="Enter URL"
|
||||
ATTACH_ENTER_URL_INSTEAD="Enter URL instead"
|
||||
ATTACH_ENTER_URL_TOOLTIP="Enter a URL here. The resource pointed to by the URL will not be uploaded; only the URL itself will be saved. NOTE: When entering relative URLs, unselect 'verify URL' and select 'relative URL'."
|
||||
ATTACH_ERROR_ADDING_HTACCESS_S="Please add an '.htaccess' file to your upload directory (%s) to prevent access to the directory."
|
||||
ATTACH_ERROR_ADDING_INDEX_HTML_IN_S="Please add an 'index.html' file to your upload directory (%s) to prevent browsing of the directory."
|
||||
ATTACH_ERROR_BAD_CHARACTER_S_IN_FILENAME_S="ERROR: Bad character (%s) in filename (%s), please rename it and try again!"
|
||||
ATTACH_ERROR_CANNOT_DELETE_INVALID_ATTACHMENT_ID_N="ERROR: Cannot delete attachment: Unable to get valid attachment ID (%d)!"
|
||||
ATTACH_ERROR_CANNOT_DELETE_INVALID_S_ID_N="ERROR: Cannot delete attachment for invalid %s ID: '%d'"
|
||||
ATTACH_ERROR_CANNOT_SWITCH_PARENT_S_NEW_FILE_S_ALREADY_EXISTS="ERROR: Cannot switch %s; new file '%s' already exists!"
|
||||
ATTACH_ERROR_CANNOT_SWITCH_PARENT_S_RENAMING_FILE_S_FAILED="ERROR: Cannot switch %s; renaming file '%' failed!"
|
||||
ATTACH_ERROR_CANNOT_UPDATE_ATTACHMENT_INVALID_ID_N="ERROR: Cannot update attachment; invalid attachment ID (%d)!"
|
||||
ATTACH_ERROR_CHANGE_IN_MEDIA_MANAGER="(Change this in the Media Manager settings.)"
|
||||
ATTACH_ERROR_CHECKING_URL_S="Error checking URL: '%s'! <br/>(You may wish to disable the 'Verify URL existence' option and try again.)"
|
||||
ATTACH_ERROR_CONNECTING_TO_URL_S="Error connecting to URL '%s'! <br/>(You may wish to disable the 'Verify URL existence' option and try again.)"
|
||||
ATTACH_ERROR_COULD_NOT_ACCESS_URL_S="ERROR: Could not access URL '%s'! <br/>(You may wish to disable the 'Verify URL existence' option and try again.)"
|
||||
ATTACH_ERROR_FILEPATH_TOO_LONG_N_N_S="ERROR: The filename with path is too long (%d > max %d). <br/>(File: %s)!"
|
||||
ATTACH_ERROR_FILE_S_ALREADY_ON_SERVER="ERROR: File '%s' already exists on the server. Please select another file or rename your file!"
|
||||
ATTACH_ERROR_FILE_S_NOT_FOUND_ON_SERVER="ERROR: File '%s' not found on server!"
|
||||
ATTACH_ERROR_FILE_S_TOO_BIG_N_N_N="File '%s' is too big at %.1f MB (max attachment size=%d MB, max PHP upload size=%d MB)"
|
||||
ATTACH_ERROR_ILLEGAL_FILE_EXTENSION="Illegal file extension:"
|
||||
ATTACH_ERROR_ILLEGAL_FILE_MIME_TYPE="Illegal file Mime type:"
|
||||
ATTACH_ERROR_INVALID_ATTACHMENT_ID_N="ERROR: Invalid attachment ID (%s)!"
|
||||
ATTACH_ERROR_INVALID_PARENT_TYPE_S="ERROR: Invalid parent type ('%s')!"
|
||||
ATTACH_ERROR_INVALID_SAVE_PARAMETERS="ERROR: Invalid save parameters!"
|
||||
ATTACH_ERROR_IN_URL_SYNTAX_S="Error in URL syntax: '%s'!"
|
||||
ATTACH_ERROR_MAY_BE_LARGER_THAN_LIMIT="Perhaps your file is larger than the size limit of"
|
||||
ATTACH_ERROR_MOVING_FILE="Error uploading (error moving file)"
|
||||
ATTACH_ERROR_NO_FUNCTION_SPECIFIED="ERROR: No function specified!"
|
||||
ATTACH_ERROR_NO_PARENT_ENTITY_SPECIFIED="ERROR: No parent entity specified!"
|
||||
ATTACH_ERROR_NO_PARENT_ID_SPECIFIED="ERROR: No parent ID specified!"
|
||||
ATTACH_ERROR_NO_PARENT_TYPE_SPECIFIED="ERROR: No parent type specified!"
|
||||
ATTACH_ERROR_NO_PERMISSION_TO_DELETE_ATTACHMENT="ERROR: You do not have permission to delete this attachment!"
|
||||
ATTACH_ERROR_NO_PERMISSION_TO_DELETE_S="ERROR: You do not have permission to delete an attachment for this %s!"
|
||||
ATTACH_ERROR_NO_PERMISSION_TO_DOWNLOAD="ERROR: You do not have permission to download this attachment!"
|
||||
ATTACH_ERROR_NO_PERMISSION_TO_UPLOAD_S="ERROR: You do not have permission to add an attachment to this %s! "
|
||||
ATTACH_ERROR_SAVING_FILE_ATTACHMENT_RECORD="Error saving file attachment record!"
|
||||
ATTACH_ERROR_SAVING_URL_ATTACHMENT_RECORD="Error saving URL attachment record!"
|
||||
ATTACH_ERROR_UNABLE_TO_CREATE_DIR_S="ERROR: Unable to create directory! <p>'%s'</p>"
|
||||
ATTACH_ERROR_UNABLE_TO_FIND_MODEL="ERROR: Unable to find model!"
|
||||
ATTACH_ERROR_UNABLE_TO_FIND_VIEW="ERROR: Unable to find view!"
|
||||
ATTACH_ERROR_UNABLE_TO_SETUP_UPLOAD_DIR_S="ERROR: Unable create or setup upload directory (%s)!"
|
||||
ATTACH_ERROR_UNKNOWN_PARENT_ID="ERROR: Unknown parent id!"
|
||||
ATTACH_ERROR_UNKNOWN_PARENT_TYPE_S="ERROR: Unknown parent type '%s'!"
|
||||
ATTACH_ERROR_UNKNOWN_PROTCOL_S_IN_URL_S="ERROR: Unknown protocol '%s' in URL: '%s'!"
|
||||
ATTACH_ERROR_UPLOADING_FILE_S="Error uploading file '%s'!"
|
||||
ATTACH_EXISTING_ATTACHMENTS="Existing Attachments:"
|
||||
ATTACH_FILENAME_COLON="Filename:"
|
||||
ATTACH_FILE_SIZE_KB="Size(kB)"
|
||||
ATTACH_FILE_TYPE="File type"
|
||||
ATTACH_FOR_PARENT_S_COLON_S="For %s: <i>'%s'</i>"
|
||||
ATTACH_LAST_MODIFIED_ON_D_BY_S="Last modified on %s by: %s"
|
||||
ATTACH_NORMAL_UPDATE="Normal update"
|
||||
ATTACH_NORMAL_UPDATE_TOOLTIP="Normal update (edit attachment info only)"
|
||||
ATTACH_NOTE_ENTER_URL_WITH_HTTP="NOTE: Enter URL with 'http...' prefix; otherwise the URL is presumed to be relative."
|
||||
ATTACH_OPTIONAL="(Optional)"
|
||||
ATTACH_PUBLISHED="Published"
|
||||
ATTACH_REALLY_DELETE_ATTACHMENT="Really delete attachment?"
|
||||
ATTACH_RELATIVE_URL="Relative URL?"
|
||||
ATTACH_RELATIVE_URL_TOOLTIP="Check this box to enter a URL relative to this Joomla! website. You will probably also need to unselect 'Verify URL' to add a relative URL."
|
||||
ATTACH_SELECT_FILE_TO_UPLOAD_INSTEAD="Select file to upload instead"
|
||||
ATTACH_SELECT_NEW_FILE_IF_YOU_WANT_TO_UPDATE_ATTACHMENT_FILE="Select new file (if you want to update the attachment file):"
|
||||
ATTACH_UNKNOWN_CONTROLLER="Unknown controller!"
|
||||
ATTACH_UPDATE="Update"
|
||||
ATTACH_UPDATED_ATTACHMENT="Updated Attachment"
|
||||
ATTACH_UPDATE_ATTACHMENT_COLON="Update Attachment:"
|
||||
ATTACH_UPDATE_ATTACHMENT_FILE_S="Update Attachment File: '%s'"
|
||||
ATTACH_UPDATE_ATTACHMENT_FOR_PARENT_S_COLON_S="Update attachment for %s: <i>'%s'</i>"
|
||||
ATTACH_UPDATE_ATTACHMENT_URL_S="Update Attachment URL: '%s'"
|
||||
ATTACH_UPLOAD_ATTACHMENT="Upload attachment"
|
||||
ATTACH_UPLOAD_CANCELED="Upload Canceled!"
|
||||
ATTACH_UPLOAD_VERB="Upload"
|
||||
ATTACH_URL_IS_VALID="URL is valid"
|
||||
ATTACH_URL_IS_VALID_TOOLTIP="Use this checkbox to manually change whether the link is valid. Ignored for new or edited links."
|
||||
ATTACH_VERIFY_URL_EXISTENCE="Verify URL existence?"
|
||||
ATTACH_VERIFY_URL_EXISTENCE_TOOLTIP="Check this box to verify that the URL works (only for new or edited URLs). Unselecting this will still validate the URL correctness."
|
||||
ATTACH_WARNING="Warning!"
|
||||
ATTACH_WARNING_ADMIN_MUST_PUBLISH="NOTE: Your attachment will not be published by default. Please contact your system administrator to have your attachment published."
|
||||
ATTACH_WARNING_FILENAME_TRUNCATED="Warning: Filename was too long! Truncated to:"
|
||||
ATTACH_WARNING_MUST_LOGIN_TO_DOWNLOAD_ATTACHMENT="WARNING: You must be logged in to download this attachment!"
|
||||
ATTACH_WARNING_YOU_ARE_ALREADY_LOGGED_IN="WARNING: You are already logged in!"
|
||||
ATTACH_YOU_MUST_SELECT_A_FILE_TO_UPLOAD="You must select a file to upload!"
|
||||
1
components/com_attachments/language/en-GB/index.html
Normal file
1
components/com_attachments/language/en-GB/index.html
Normal file
@ -0,0 +1 @@
|
||||
<html><body bgcolor="#FFFFFF"></body></html>
|
||||
1
components/com_attachments/language/index.html
Normal file
1
components/com_attachments/language/index.html
Normal file
@ -0,0 +1 @@
|
||||
<html><body bgcolor="#FFFFFF"></body></html>
|
||||
1
components/com_attachments/language/it-IT/index.html
Normal file
1
components/com_attachments/language/it-IT/index.html
Normal file
@ -0,0 +1 @@
|
||||
<html><body bgcolor="#FFFFFF"></body></html>
|
||||
@ -0,0 +1,118 @@
|
||||
; it-IT.com_attachments.ini (site component)
|
||||
; 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)
|
||||
|
||||
; For forms, etc, from the front end
|
||||
|
||||
ATTACH_ACCESS_COLON="Accesso: "
|
||||
ATTACH_ACCESS_LEVEL_TOOLTIP="Livello di accesso che definisce chi può vedere o scaricare questo allegato."
|
||||
ATTACH_ADD_ATTACHMENT="Aggiungi Allegato"
|
||||
ATTACH_ADD_URL="Aggiungi URL"
|
||||
ATTACH_ATTACHMENT="Allegato"
|
||||
ATTACH_ATTACHMENTS="Allegati"
|
||||
ATTACH_ATTACHMENT_FILENAME_URL="Nome / URL dell'allegato"
|
||||
ATTACH_ATTACHMENT_SAVED="Allegato Salvato"
|
||||
ATTACH_ATTACHMENT_UPDATED="Allegato aggiornato!"
|
||||
ATTACH_ATTACH_FILE_COLON="Allega File"
|
||||
ATTACH_CANCEL="Annulla"
|
||||
ATTACH_CHANGES_TO_ATTACHMENT_SAVED="Modifiche all'allegato salvato"
|
||||
ATTACH_CHANGE_FILE="Aggiorna il File"
|
||||
ATTACH_CHANGE_FILE_TOOLTIP="Aggiorna il file per questo allegato (Le altre modifiche a questo form andranno perse.)"
|
||||
ATTACH_CHANGE_TO_FILE="Cambia File"
|
||||
ATTACH_CHANGE_TO_FILE_TOOLTIP="Allega un file a questo allegato (Le altre modifiche a questo form andranno perse)"
|
||||
ATTACH_CHANGE_TO_URL="Cambia con URL"
|
||||
ATTACH_CHANGE_TO_URL_TOOLTIP="Modifica URL/link del file caricato. (Le altre modifiche a questo form andranno perse)"
|
||||
ATTACH_DELETE="Elimina"
|
||||
ATTACH_DELETED_ATTACHMENT="Allegato Cancellato"
|
||||
ATTACH_DESCRIPTION="Descrizione"
|
||||
ATTACH_DESCRIPTION_COLON="Descrizione:"
|
||||
ATTACH_DISPLAY_FILENAME_OPTIONAL_COLON="Mostra il nome del file (opzionale):"
|
||||
ATTACH_DISPLAY_FILENAME_TOOLTIP="Facoltativo: Inserire un nome o un'etichetta per il file da mostrare in alternativa al nome del file completo."
|
||||
ATTACH_DISPLAY_URL_COLON="Mostra URL:"
|
||||
ATTACH_DISPLAY_URL_TOOLTIP="Opzionale: Inserisci URL o etichetta da mostrare in alternativa al posto dell'URL completo."
|
||||
ATTACH_ENTER_NEW_URL_COLON="Inserisci nuovo URL:"
|
||||
ATTACH_ENTER_URL="Inserisci URL"
|
||||
ATTACH_ENTER_URL_INSTEAD="Inserisci URL alternativo"
|
||||
ATTACH_ENTER_URL_TOOLTIP="Inserisci un URL qui. La risorsa indicata dall'URL non sarà caricata; sarà salvato soltanto l'URL stesso. NOTA: Se l' URL è relativo, deseleziona 'verifica URL' e seleziona 'URL relativo'."
|
||||
ATTACH_ERROR_ADDING_HTACCESS_S="Ricorda di inserire un file '.htaccess' nella directory di upload (%s) per prevenire l'accesso alla directory."
|
||||
ATTACH_ERROR_ADDING_INDEX_HTML_IN_S="Ricorda di inserire un file 'index.html' nella directory di upload (%s) per prevenire il browsing della directory."
|
||||
ATTACH_ERROR_BAD_CHARACTER_S_IN_FILENAME_S="ERRORE: carattere non ammesso (%s) nel nome del file (%s), cambia il nome e riprova!"
|
||||
ATTACH_ERROR_CANNOT_DELETE_INVALID_ATTACHMENT_ID_N="ERRORE: Impossibile cancellare l'allegato: Impossibile ottenere valida ID dell'allegato (%d)!"
|
||||
ATTACH_ERROR_CANNOT_DELETE_INVALID_S_ID_N="ERRORE: Impossibile cancellare l'allegato a causa dell'ID %s non valida: '%d'"
|
||||
ATTACH_ERROR_CANNOT_SWITCH_PARENT_S_NEW_FILE_S_ALREADY_EXISTS="ERRORE: Impossibile scambiare %s; Il nuovo file '%s' esiste già!"
|
||||
ATTACH_ERROR_CANNOT_SWITCH_PARENT_S_RENAMING_FILE_S_FAILED="ERRORE: Impossibile scambiare %s; la rinominazione del file '%' è fallita!"
|
||||
ATTACH_ERROR_CANNOT_UPDATE_ATTACHMENT_INVALID_ID_N="ERRORE: Impossibile aggiornare l'allegato. ID allegato non valida ID (%d)!"
|
||||
ATTACH_ERROR_CHANGE_IN_MEDIA_MANAGER="(Questa modifica deve essere effettuata in Gestione Media.)"
|
||||
ATTACH_ERROR_CHECKING_URL_S="Errore durante la verifica URL: '%s'! <br/>(Potresti disabilitare 'Verifica esistenza URL' e riprovare)"
|
||||
ATTACH_ERROR_CONNECTING_TO_URL_S="Errore impossibile connettersi a URL '%s'! <br/>(Potresti disabilitare 'Verifica esistenza URL' e riprovare)"
|
||||
ATTACH_ERROR_COULD_NOT_ACCESS_URL_S="ERRORE: Impossibile accedere a URL '%s'! <br/>(Potresti disabilitare l'opzione 'Verifica esistenza URL' e riprovare)."
|
||||
ATTACH_ERROR_FILEPATH_TOO_LONG_N_N_S="ERRORE: il nome del file con il percorso è troppo lungo (%d > max %d). <br/>(File: %s)!"
|
||||
ATTACH_ERROR_FILE_S_ALREADY_ON_SERVER="ERRORE: Il file '%s' è già presente sul server. Seleziona un altro file o rinominalo!"
|
||||
ATTACH_ERROR_FILE_S_NOT_FOUND_ON_SERVER="ERROR: Il file '%s' non esiste sul server!"
|
||||
ATTACH_ERROR_FILE_S_TOO_BIG_N_N_N="Il file '%s' è troppo grande %.1f MB (max attachment size=%d MB, max PHP upload size=%d MB)"
|
||||
ATTACH_ERROR_ILLEGAL_FILE_EXTENSION="Estensione del file non consentita:"
|
||||
ATTACH_ERROR_ILLEGAL_FILE_MIME_TYPE="Tipo MIME del file non consentito:"
|
||||
ATTACH_ERROR_INVALID_ATTACHMENT_ID_N="ERRORE: ID allegato (%s) non valida"
|
||||
ATTACH_ERROR_INVALID_PARENT_TYPE_S="ERRORE: Tipo genitore non valido ('%s')!"
|
||||
ATTACH_ERROR_INVALID_SAVE_PARAMETERS="ERRORE: Parametri di salvataggio non validi!"
|
||||
ATTACH_ERROR_IN_URL_SYNTAX_S="Errore nella sintassi URL: '%s'!"
|
||||
ATTACH_ERROR_MAY_BE_LARGER_THAN_LIMIT="Probabilmente il tuo file è più grande del limite consentito di"
|
||||
ATTACH_ERROR_MOVING_FILE="Errore nel caricamento (errore nello spostamento del file)"
|
||||
ATTACH_ERROR_NO_FUNCTION_SPECIFIED="ERRORE:Nessuna funzione specificata!"
|
||||
ATTACH_ERROR_NO_PARENT_ENTITY_SPECIFIED="ERRORE: Non è stata specificata nessuna entità genitore!"
|
||||
ATTACH_ERROR_NO_PARENT_ID_SPECIFIED="ERRORE: Non è stato indicata l'ID del genitore!"
|
||||
ATTACH_ERROR_NO_PARENT_TYPE_SPECIFIED="ERRORE: Non è stato indicato il tipo di genitore!"
|
||||
ATTACH_ERROR_NO_PERMISSION_TO_DELETE_ATTACHMENT="ERRORE: eliminazione di questo allegato non è consentita!"
|
||||
ATTACH_ERROR_NO_PERMISSION_TO_DELETE_S="ERRORE: Non disponi delle autorizzazioni necessarie per cancellare un allegato per questo %s!"
|
||||
ATTACH_ERROR_NO_PERMISSION_TO_DOWNLOAD="ERRORE: Non disponi delle autorizzazioni necessarie per eseguire il download di questo allegato!"
|
||||
ATTACH_ERROR_NO_PERMISSION_TO_UPLOAD_S="ERRORE: non disponi dell'autorizzazione per aggiungere un allegato a questo %s!"
|
||||
ATTACH_ERROR_SAVING_FILE_ATTACHMENT_RECORD="Errore durante il salvataggio del record relativo al file allegato!"
|
||||
ATTACH_ERROR_SAVING_URL_ATTACHMENT_RECORD="Errore durante il salvataggio del record relativo all'URL!"
|
||||
ATTACH_ERROR_UNABLE_TO_CREATE_DIR_S="ERRORE: Impossibile creare la directory! <p>'%s'</p>"
|
||||
ATTACH_ERROR_UNABLE_TO_FIND_MODEL="ERRORE: Impossibile trovare il modello!"
|
||||
ATTACH_ERROR_UNABLE_TO_FIND_VIEW="ERRORE: Impossibile trovare la vista!"
|
||||
ATTACH_ERROR_UNABLE_TO_SETUP_UPLOAD_DIR_S="ERRORW: Impossibile creare o impostare la directory di upload (%s)!"
|
||||
ATTACH_ERROR_UNKNOWN_PARENT_ID="ERRORW: ID genitore sconosciuto!"
|
||||
ATTACH_ERROR_UNKNOWN_PARENT_TYPE_S="ERRORE: Tipo genitore sconosciuto '%s'!"
|
||||
ATTACH_ERROR_UNKNOWN_PROTCOL_S_IN_URL_S="ERRORE: Protocollo sconosciuto '%s' nell'URL: '%s'!"
|
||||
ATTACH_ERROR_UPLOADING_FILE_S="Errore durante il caricamento del file '%s'!"
|
||||
ATTACH_EXISTING_ATTACHMENTS="Allegati Esistenti"
|
||||
ATTACH_FILENAME_COLON="Nome del File:"
|
||||
ATTACH_FILE_SIZE_KB="Dimensione(KB)"
|
||||
ATTACH_FILE_TYPE="Tipo di File"
|
||||
ATTACH_FOR_PARENT_S_COLON_S="Per %s: <i>'%s'</i>"
|
||||
ATTACH_LAST_MODIFIED_ON_D_BY_S="Modificato l'ultima volta il %s da: %s"
|
||||
ATTACH_NORMAL_UPDATE="Aggiornamento normale"
|
||||
ATTACH_NORMAL_UPDATE_TOOLTIP="Aggiornamento normale (modifica delle sole info dell'allegato)"
|
||||
ATTACH_NOTE_ENTER_URL_WITH_HTTP="NOTA: Inseriere URL con il prefisso 'http...' ; diversamente l'URL è ritenuto relativo."
|
||||
ATTACH_OPTIONAL="(Facoltativo)"
|
||||
ATTACH_PUBLISHED="Pubblicato"
|
||||
ATTACH_REALLY_DELETE_ATTACHMENT="Confermi la cancellazione dell'allegato?"
|
||||
ATTACH_RELATIVE_URL="URL relativo"
|
||||
ATTACH_RELATIVE_URL_TOOLTIP="Spunta questo box per inserire un URL relativo a questo sito Joomla!. Probabilmente dovrai anche desiabilitare 'Verifica URL' per inserire un URL relativo."
|
||||
ATTACH_SELECT_FILE_TO_UPLOAD_INSTEAD="Seleziona il file da caricare"
|
||||
ATTACH_SELECT_NEW_FILE_IF_YOU_WANT_TO_UPDATE_ATTACHMENT_FILE="Seleziona un nuovo file (se desideri aggiornare il file dell'allegato):"
|
||||
ATTACH_UNKNOWN_CONTROLLER="Controller sconosciuto!"
|
||||
ATTACH_UPDATE="Aggiorna"
|
||||
ATTACH_UPDATED_ATTACHMENT="Allegato aggiornato"
|
||||
ATTACH_UPDATE_ATTACHMENT_COLON="Aggiorna l'allegato:"
|
||||
ATTACH_UPDATE_ATTACHMENT_FILE_S="Aggiorna File Allegato: '%s'"
|
||||
ATTACH_UPDATE_ATTACHMENT_FOR_PARENT_S_COLON_S="Aggiorna allegato per %s: <i>'%s'</i>"
|
||||
ATTACH_UPDATE_ATTACHMENT_URL_S="Aggiorna l'URL dell'allegato: '%s'"
|
||||
ATTACH_UPLOAD_ATTACHMENT="Carica allegato"
|
||||
ATTACH_UPLOAD_CANCELED="Caricamento interrotto!"
|
||||
ATTACH_UPLOAD_VERB="Carica"
|
||||
ATTACH_URL_IS_VALID="URL è valido"
|
||||
ATTACH_URL_IS_VALID_TOOLTIP="Usa questo checkbox per indicare manualmente se il link è valido. Ignorato nel caso di link nuovi o modificati."
|
||||
ATTACH_VERIFY_URL_EXISTENCE="Verifca esistenza dell'URL?"
|
||||
ATTACH_VERIFY_URL_EXISTENCE_TOOLTIP="Seleziona questo checkbox per verificare se l'URL è corretto (solo per URL nuovi o modificati). Disabilitandolo sarè comunque verificata la correttezza dell'URL."
|
||||
ATTACH_WARNING="Attenzione!"
|
||||
ATTACH_WARNING_ADMIN_MUST_PUBLISH="<strong>NOTA:</strong> Il tuo allegato non sarà pubblicato automaticamente. Per la pubblicazione contatta l'amministratore del sistema."
|
||||
ATTACH_WARNING_FILENAME_TRUNCATED="Attenzione: il nome del file era troppo lungo! E' stato troncato a:"
|
||||
ATTACH_WARNING_MUST_LOGIN_TO_DOWNLOAD_ATTACHMENT="ATTENZIONE: devi avere fatto l'accesso per scaricare questo allegato!"
|
||||
ATTACH_WARNING_YOU_ARE_ALREADY_LOGGED_IN="ATTENZIONE: hai già fatto l'accesso!"
|
||||
ATTACH_YOU_MUST_SELECT_A_FILE_TO_UPLOAD="Devi selezionare un file da caricare!"
|
||||
30
components/com_attachments/legacy/controller.php
Normal file
30
components/com_attachments/legacy/controller.php
Normal file
@ -0,0 +1,30 @@
|
||||
<?php
|
||||
/**
|
||||
* Attachments component Legacy controller class compatibility
|
||||
*
|
||||
* @package Attachments
|
||||
* @subpackage Attachments_Component
|
||||
*
|
||||
* @copyright Copyright (C) 2011-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.
|
||||
defined('_JEXEC') or die('Restricted access');
|
||||
|
||||
|
||||
if (!class_exists('JControllerLegacy', false))
|
||||
{
|
||||
if (version_compare(JVERSION, '3.0', 'ge'))
|
||||
{
|
||||
// Joomla 3.0
|
||||
jimport('legacy.controller.legacy');
|
||||
}
|
||||
else if (version_compare(JVERSION, '2.5', 'ge'))
|
||||
{
|
||||
// Joomla 2.5
|
||||
jimport('cms.controller.legacy');
|
||||
}
|
||||
}
|
||||
39
components/com_attachments/legacy/controller_form.php
Normal file
39
components/com_attachments/legacy/controller_form.php
Normal file
@ -0,0 +1,39 @@
|
||||
<?php
|
||||
/**
|
||||
* Attachments component Legacy controllerForm class compatibility
|
||||
*
|
||||
* @package Attachments
|
||||
* @subpackage Attachments_Component
|
||||
*
|
||||
* @copyright Copyright (C) 2011-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.
|
||||
defined('_JEXEC') or die('Restricted access');
|
||||
|
||||
|
||||
if (!class_exists('JControllerFormLegacy', false))
|
||||
{
|
||||
if (version_compare(JVERSION, '3.0', 'ge'))
|
||||
{
|
||||
// Joomla 3.0
|
||||
jimport('legacy.controller.form');
|
||||
class JControllerFormLegacy extends JControllerForm
|
||||
{
|
||||
}
|
||||
}
|
||||
else if (version_compare(JVERSION, '2.5', 'ge'))
|
||||
{
|
||||
// Joomla 2.5
|
||||
if (!class_exists('JControllerForm', false))
|
||||
{
|
||||
jimport('joomla.application.component.controllerform');
|
||||
}
|
||||
class JControllerFormLegacy extends JControllerForm
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
1
components/com_attachments/legacy/index.html
Normal file
1
components/com_attachments/legacy/index.html
Normal file
@ -0,0 +1 @@
|
||||
<html><body bgcolor="#FFFFFF"></body></html>
|
||||
30
components/com_attachments/legacy/model.php
Normal file
30
components/com_attachments/legacy/model.php
Normal file
@ -0,0 +1,30 @@
|
||||
<?php
|
||||
/**
|
||||
* Attachments component Legacy model class compatibility
|
||||
*
|
||||
* @package Attachments
|
||||
* @subpackage Attachments_Component
|
||||
*
|
||||
* @copyright Copyright (C) 2011-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.
|
||||
defined('_JEXEC') or die('Restricted access');
|
||||
|
||||
|
||||
if (!class_exists('JModelLegacy', false))
|
||||
{
|
||||
if (version_compare(JVERSION, '3.0', 'ge'))
|
||||
{
|
||||
// Joomla 3.0
|
||||
jimport('legacy.model.legacy');
|
||||
}
|
||||
else if (version_compare(JVERSION, '2.5', 'ge'))
|
||||
{
|
||||
// Joomla 2.5
|
||||
jimport('cms.model.legacy');
|
||||
}
|
||||
}
|
||||
30
components/com_attachments/legacy/view.php
Normal file
30
components/com_attachments/legacy/view.php
Normal file
@ -0,0 +1,30 @@
|
||||
<?php
|
||||
/**
|
||||
* Attachments component Legacy view class compatibility
|
||||
*
|
||||
* @package Attachments
|
||||
* @subpackage Attachments_Component
|
||||
*
|
||||
* @copyright Copyright (C) 2011-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.
|
||||
defined('_JEXEC') or die('Restricted access');
|
||||
|
||||
if (!class_exists('JViewLegacy', false))
|
||||
{
|
||||
if (version_compare(JVERSION, '3.0', 'ge'))
|
||||
{
|
||||
// Joomla 3.0
|
||||
jimport('legacy.view.legacy');
|
||||
}
|
||||
else if (version_compare(JVERSION, '2.5', 'ge'))
|
||||
{
|
||||
// Joomla 2.5
|
||||
jimport( 'joomla.application.component.view' );
|
||||
jimport('cms.view.legacy');
|
||||
}
|
||||
}
|
||||
215
components/com_attachments/models/attachment.php
Normal file
215
components/com_attachments/models/attachment.php
Normal file
@ -0,0 +1,215 @@
|
||||
<?php
|
||||
/**
|
||||
* Attachment model definition
|
||||
*
|
||||
* @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/model.php');
|
||||
|
||||
|
||||
/**
|
||||
* Attachment Model
|
||||
*
|
||||
* @package Attachments
|
||||
*/
|
||||
class AttachmentsModelAttachment extends JModelLegacy
|
||||
{
|
||||
|
||||
/**
|
||||
* Attachment ID
|
||||
*/
|
||||
var $_id = null;
|
||||
|
||||
|
||||
/**
|
||||
* Attachment object/data
|
||||
*
|
||||
* @var object
|
||||
*/
|
||||
var $_attachment = null;
|
||||
|
||||
|
||||
/**
|
||||
* Constructor, build object and determines its ID
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
// Get the cid array from the request
|
||||
$cid = JRequest::getVar('cid', false, 'DEFAULT', 'array');
|
||||
|
||||
if ($cid) {
|
||||
// Accept only the first id from the array
|
||||
$id = $cid[0];
|
||||
}
|
||||
else {
|
||||
$id = JRequest::getInt('id',0);
|
||||
}
|
||||
|
||||
$this->setId($id);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Reset the model ID and data
|
||||
*/
|
||||
public function setId($id=0)
|
||||
{
|
||||
$this->_id = $id;
|
||||
$this->_attachment = null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Load the attachment data
|
||||
*
|
||||
* @return true if loaded successfully
|
||||
*/
|
||||
private function _loadAttachment()
|
||||
{
|
||||
if ($this->_id == 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( empty($this->_attachment) ) {
|
||||
|
||||
$user = JFactory::getUser();
|
||||
$user_levels = $user->getAuthorisedViewLevels();
|
||||
|
||||
// If the user is not logged in, add extra view levels (if configured)
|
||||
if ( $user->get('username') == '' ) {
|
||||
|
||||
// Get the component parameters
|
||||
jimport('joomla.application.component.helper');
|
||||
$params = JComponentHelper::getParams('com_attachments');
|
||||
|
||||
// Add the specified access levels
|
||||
$guest_levels = $params->get('show_guest_access_levels', Array('1'));
|
||||
if (is_array($guest_levels)) {
|
||||
foreach ($guest_levels as $glevel) {
|
||||
$user_levels[] = $glevel;
|
||||
}
|
||||
}
|
||||
else {
|
||||
$user_levels[] = $glevel;
|
||||
}
|
||||
}
|
||||
$user_levels = implode(',', array_unique($user_levels));
|
||||
|
||||
// Load the attachment data and make sure this user has access
|
||||
$db = $this->getDbo();
|
||||
$query = $db->getQuery(true);
|
||||
$query->select('a.*, a.id as id');
|
||||
$query->from('#__attachments as a');
|
||||
$query->where('a.id = '.(int)$this->_id);
|
||||
if ( !$user->authorise('core.admin') ) {
|
||||
$query->where('a.access in ('.$user_levels.')');
|
||||
}
|
||||
$db->setQuery($query, 0, 1);
|
||||
$this->_attachment = $db->loadObject();
|
||||
if ( empty($this->_attachment) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Retrieve the information about the parent
|
||||
$parent_type = $this->_attachment->parent_type;
|
||||
$parent_entity = $this->_attachment->parent_entity;
|
||||
JPluginHelper::importPlugin('attachments');
|
||||
$apm = getAttachmentsPluginManager();
|
||||
if ( !$apm->attachmentsPluginInstalled($parent_type) ) {
|
||||
$this->_attachment->parent_type = false;
|
||||
return false;
|
||||
}
|
||||
$parent = $apm->getAttachmentsPlugin($parent_type);
|
||||
|
||||
// Set up the parent info
|
||||
$parent_id = $this->_attachment->parent_id;
|
||||
$this->_attachment->parent_title = $parent->getTitle($parent_id, $parent_entity);
|
||||
$this->_attachment->parent_published =
|
||||
$parent->isParentPublished($parent_id, $parent_entity);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create a new Attachment object
|
||||
*/
|
||||
private function _initAttachment()
|
||||
{
|
||||
echo "_initData not implemented yet <br />";
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the data
|
||||
*
|
||||
* @return object
|
||||
*/
|
||||
public function getAttachment()
|
||||
{
|
||||
if ( !$this->_loadAttachment() ) {
|
||||
// If the load fails, create a new one
|
||||
$this->_initAttachment();
|
||||
}
|
||||
|
||||
return $this->_attachment;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Save the attachment
|
||||
*
|
||||
* @param object $data mixed object or associative array of data to save
|
||||
*
|
||||
* @return Boolean true on success
|
||||
*/
|
||||
public function save($data)
|
||||
{
|
||||
// Get the table
|
||||
$table = $this->getTable('Attachments');
|
||||
|
||||
// Save the data
|
||||
if ( !$table->save($data) ) {
|
||||
// An error occured, save the model error message
|
||||
$this->setError($table->getError());
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Increment the download cout
|
||||
*
|
||||
* @param int $attachment_id the attachment ID
|
||||
*/
|
||||
public function incrementDownloadCount()
|
||||
{
|
||||
// Update the download count
|
||||
$db = JFactory::getDBO();
|
||||
$query = $db->getQuery(true);
|
||||
$query->update('#__attachments')->set('download_count = (download_count + 1)');
|
||||
$query->where('id = ' .(int)$this->_id);
|
||||
$db->setQuery($query);
|
||||
if ( !$db->query() ) {
|
||||
$errmsg = $db->stderr() . ' (ERR 49)';
|
||||
JError::raiseError(500, $errmsg);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
580
components/com_attachments/models/attachments.php
Normal file
580
components/com_attachments/models/attachments.php
Normal file
@ -0,0 +1,580 @@
|
||||
<?php
|
||||
/**
|
||||
* Attachment list model definition
|
||||
*
|
||||
* @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');
|
||||
|
||||
jimport('joomla.application.component.helper');
|
||||
|
||||
/** Define the legacy classes, if necessary */
|
||||
require_once(JPATH_SITE.'/components/com_attachments/legacy/model.php');
|
||||
|
||||
|
||||
/**
|
||||
* Attachment List Model for all attachments belonging to one
|
||||
* content article (or other content-related entity)
|
||||
*
|
||||
* @package Attachments
|
||||
*/
|
||||
class AttachmentsModelAttachments extends JModelLegacy
|
||||
{
|
||||
/**
|
||||
* ID of parent of the list of attachments
|
||||
*/
|
||||
var $_parent_id = null;
|
||||
|
||||
/**
|
||||
* type of parent
|
||||
*/
|
||||
var $_parent_type = null;
|
||||
|
||||
/**
|
||||
* type of parent entity (each parent_type can support several)
|
||||
*/
|
||||
var $_parent_entity = null;
|
||||
|
||||
/**
|
||||
* Parent class object (an Attachments extension plugin object)
|
||||
*/
|
||||
var $_parent = null;
|
||||
|
||||
/**
|
||||
* Parent title
|
||||
*/
|
||||
var $_parent_title = null;
|
||||
|
||||
/**
|
||||
* Parent entity name
|
||||
*/
|
||||
var $_parent_entity_name = null;
|
||||
|
||||
/**
|
||||
* Whether some of the attachments should be visible to the user
|
||||
*/
|
||||
var $_some_visible = null;
|
||||
|
||||
/**
|
||||
* Whether some of the attachments should be modifiable to the user
|
||||
*/
|
||||
var $_some_modifiable = null;
|
||||
|
||||
/**
|
||||
* The desired sort order
|
||||
*/
|
||||
var $_sort_order;
|
||||
|
||||
|
||||
/**
|
||||
* The list of attachments for the specified article/content entity
|
||||
*/
|
||||
var $_list = null;
|
||||
|
||||
/**
|
||||
* Number of attachments
|
||||
*
|
||||
* NOTE: After the list of attachments has been retrieved, if it is empty, this is set to zero.
|
||||
* But _list remains null. You can use this to check to see if the list has been loaded.
|
||||
*/
|
||||
var $_num_attachments = null;
|
||||
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set the parent id (and optionally the parent type)
|
||||
*
|
||||
* NOTE: If the $id is null, it will get both $id and $parent_id from JRequest
|
||||
*
|
||||
* @param int $id the id of the parent
|
||||
* @param string $parent_type the parent type (defaults to 'com_content')
|
||||
* @param string $parent_entity the parent entity (defaults to 'default')
|
||||
*/
|
||||
public function setParentId($id=null, $parent_type='com_content', $parent_entity='default')
|
||||
{
|
||||
// Get the parent id and type
|
||||
if ( is_numeric($id) ) {
|
||||
$parent_id = (int)$id;
|
||||
}
|
||||
else {
|
||||
// It was not an argument, so get parent id and type from the JRequest
|
||||
$parent_id = JRequest::getInt('article_id', null);
|
||||
|
||||
// Deal with special case of editing from the front end
|
||||
if ( $parent_id == null ) {
|
||||
if ( (JRequest::getCmd('view') == 'article') &&
|
||||
(JRequest::getCmd('task') == 'edit' )) {
|
||||
$parent_id = JRequest::getInt('id', null);
|
||||
}
|
||||
}
|
||||
|
||||
// If article_id is not specified, get the general parent id/type
|
||||
if ( $parent_id == null ) {
|
||||
$parent_id = JRequest::getInt('parent_id', null);
|
||||
if ( $parent_id == null ) {
|
||||
$errmsg = JText::_('ATTACH_ERROR_NO_PARENT_ID_SPECIFIED') . ' (ERR 50)';
|
||||
JError::raiseError(500, $errmsg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Reset instance variables
|
||||
$this->_parent_id = $parent_id;
|
||||
$this->_parent_type = $parent_type;
|
||||
$this->_parent_entity = $parent_entity;
|
||||
|
||||
$this->_parent = null;
|
||||
$this->_parent_class = null;
|
||||
$this->_parent_title = null;
|
||||
$this->_parent_entity_name = null;
|
||||
|
||||
$this->_list = null;
|
||||
$this->_sort_order = null;
|
||||
$this->_some_visible = null;
|
||||
$this->_some_modifiable = null;
|
||||
$this->_num_attachments = null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Get the parent id
|
||||
*
|
||||
* @return the parent id
|
||||
*/
|
||||
public function getParentId()
|
||||
{
|
||||
if ( $this->_parent_id === null ) {
|
||||
$errmsg = JText::_('ATTACH_ERROR_NO_PARENT_ID_SPECIFIED') . ' (ERR 51)';
|
||||
JError::raiseError(500, $errmsg);
|
||||
}
|
||||
return $this->_parent_id;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the parent type
|
||||
*
|
||||
* @return the parent type
|
||||
*/
|
||||
public function getParentType()
|
||||
{
|
||||
if ( $this->_parent_type == null ) {
|
||||
$errmsg = JText::_('ATTACH_ERROR_NO_PARENT_TYPE_SPECIFIED') . ' (ERR 52)';
|
||||
throw Exception($errmsg);
|
||||
// JError::raiseError(500, $errmsg);
|
||||
}
|
||||
return $this->_parent_type;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the parent entity
|
||||
*
|
||||
* @return the parent entity
|
||||
*/
|
||||
public function getParentEntity()
|
||||
{
|
||||
if ( $this->_parent_entity == null ) {
|
||||
$errmsg = JText::_('ATTACH_ERROR_NO_PARENT_ENTITY_SPECIFIED') . ' (ERR 53)';
|
||||
JError::raiseError(500, $errmsg);
|
||||
}
|
||||
|
||||
// Make sure we have a good parent_entity value
|
||||
if ( $this->_parent_entity == 'default' ) {
|
||||
$parent = $this->getParentClass();
|
||||
$this->_parent_entity = $parent->getDefaultEntity();
|
||||
}
|
||||
|
||||
return $this->_parent_entity;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the parent class object
|
||||
*
|
||||
* @return the parent class object
|
||||
*/
|
||||
public function &getParentClass()
|
||||
{
|
||||
if ( $this->_parent_type == null ) {
|
||||
$errmsg = JText::_('ATTACH_ERROR_NO_PARENT_TYPE_SPECIFIED') . ' (ERR 54)';
|
||||
JError::raiseError(500, $errmsg);
|
||||
}
|
||||
|
||||
if ( $this->_parent_class == null ) {
|
||||
|
||||
// Get the parent handler
|
||||
JPluginHelper::importPlugin('attachments');
|
||||
$apm = getAttachmentsPluginManager();
|
||||
if ( !$apm->attachmentsPluginInstalled($this->_parent_type) ) {
|
||||
$errmsg = JText::sprintf('ATTACH_ERROR_INVALID_PARENT_TYPE_S', $parent_type) . ' (ERR 55)';
|
||||
JError::raiseError(500, $errmsg);
|
||||
}
|
||||
$this->_parent_class = $apm->getAttachmentsPlugin($this->_parent_type);
|
||||
}
|
||||
|
||||
return $this->_parent_class;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the title for the parent
|
||||
*
|
||||
* @return the title for the parent
|
||||
*/
|
||||
public function getParentTitle()
|
||||
{
|
||||
// Get the title if we have not done it before
|
||||
if ( $this->_parent_title == null ) {
|
||||
|
||||
$parent = $this->getParentClass();
|
||||
|
||||
// Make sure we have an article ID
|
||||
if ( $this->_parent_id === null ) {
|
||||
$errmsg = JText::_('ATTACH_ERROR_UNKNOWN_PARENT_ID') . ' (ERR 56)';
|
||||
JError::raiseError(500, $errmsg);
|
||||
}
|
||||
|
||||
$this->_parent_title = $parent->getTitle( $this->_parent_id, $this->_parent_entity );
|
||||
}
|
||||
|
||||
return $this->_parent_title;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the EntityName for the parent
|
||||
*
|
||||
* @return the entity name for the parent
|
||||
*/
|
||||
public function getParentEntityName()
|
||||
{
|
||||
// Get the parent entity name if we have not done it before
|
||||
if ( $this->_parent_entity_name == null ) {
|
||||
|
||||
// Make sure we have an article ID
|
||||
if ( $this->_parent_id === null ) {
|
||||
$errmsg = JText::_('ATTACH_ERROR_NO_PARENT_ID_SPECIFIED') . ' (ERR 57)';
|
||||
JError::raiseError(500, $errmsg);
|
||||
}
|
||||
|
||||
$this->_parent_entity_name = JText::_('ATTACH_' . $this->getParentEntity());
|
||||
}
|
||||
|
||||
return $this->_parent_entity_name;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set the sort order (do this before doing getAttachmentsList)
|
||||
*
|
||||
* @param string $new_sort_order name of the new sort order
|
||||
*/
|
||||
public function setSortOrder($new_sort_order)
|
||||
{
|
||||
if ( $new_sort_order == 'filename' )
|
||||
$order_by = 'filename';
|
||||
else if ( $new_sort_order == 'filename_desc' )
|
||||
$order_by = 'filename DESC';
|
||||
else if ( $new_sort_order == 'file_size' )
|
||||
$order_by = 'file_size';
|
||||
else if ( $new_sort_order == 'file_size_desc' )
|
||||
$order_by = 'file_size DESC';
|
||||
else if ( $new_sort_order == 'description' )
|
||||
$order_by = 'description';
|
||||
else if ( $new_sort_order == 'description_desc' )
|
||||
$order_by = 'description DESC';
|
||||
else if ( $new_sort_order == 'display_name' )
|
||||
$order_by = 'display_name, filename';
|
||||
else if ( $new_sort_order == 'display_name_desc' )
|
||||
$order_by = 'display_name DESC, filename';
|
||||
else if ( $new_sort_order == 'created' )
|
||||
$order_by = 'created';
|
||||
else if ( $new_sort_order == 'created_desc' )
|
||||
$order_by = 'created DESC';
|
||||
else if ( $new_sort_order == 'modified' )
|
||||
$order_by = 'modified';
|
||||
else if ( $new_sort_order == 'modified_desc' )
|
||||
$order_by = 'modified DESC';
|
||||
else if ( $new_sort_order == 'user_field_1' )
|
||||
$order_by = 'user_field_1';
|
||||
else if ( $new_sort_order == 'user_field_1_desc' )
|
||||
$order_by = 'user_field_1 DESC';
|
||||
else if ( $new_sort_order == 'user_field_2' )
|
||||
$order_by = 'user_field_2';
|
||||
else if ( $new_sort_order == 'user_field_2_desc' )
|
||||
$order_by = 'user_field_2 DESC';
|
||||
else if ( $new_sort_order == 'user_field_3' )
|
||||
$order_by = 'user_field_3';
|
||||
else if ( $new_sort_order == 'user_field_3_desc' )
|
||||
$order_by = 'user_field_3 DESC';
|
||||
else if ( $new_sort_order == 'id' )
|
||||
$order_by = 'id';
|
||||
else
|
||||
$order_by = 'filename';
|
||||
|
||||
$this->_sort_order = $order_by;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Get or build the list of attachments
|
||||
*
|
||||
* @return the list of attachments for this parent
|
||||
*/
|
||||
public function &getAttachmentsList()
|
||||
{
|
||||
// Just return it if it has already been created
|
||||
if ( $this->_list != null ) {
|
||||
return $this->_list;
|
||||
}
|
||||
|
||||
// Get the component parameters
|
||||
$params = JComponentHelper::getParams('com_attachments');
|
||||
|
||||
// Create the list
|
||||
|
||||
// Get the parent id and type
|
||||
$parent_id = $this->getParentId();
|
||||
$parent_type = $this->getParentType();
|
||||
$parent_entity = $this->getParentEntity();
|
||||
|
||||
// Use parent entity corresponding to values saved in the attachments table
|
||||
$parent = $this->getParentClass();
|
||||
|
||||
// Define the list order
|
||||
if ( ! $this->_sort_order ) {
|
||||
$this->_sort_order = 'filename';
|
||||
}
|
||||
|
||||
// Determine allowed access levels
|
||||
$db = JFactory::getDBO();
|
||||
$user = JFactory::getUser();
|
||||
$user_levels = $user->getAuthorisedViewLevels();
|
||||
|
||||
// If the user is not logged in, add extra view levels (if configured)
|
||||
$secure = $params->get('secure', false);
|
||||
$logged_in = $user->get('username') <> '';
|
||||
if ( !$logged_in AND $secure ) {
|
||||
$user_levels = Array('1'); // Override the authorised levels
|
||||
// NOTE: Public attachments are ALWAYS visible
|
||||
$guest_levels = $params->get('show_guest_access_levels', Array());
|
||||
if (is_array($guest_levels)) {
|
||||
foreach ($guest_levels as $glevel) {
|
||||
$user_levels[] = $glevel;
|
||||
}
|
||||
}
|
||||
else {
|
||||
$user_levels[] = $glevel;
|
||||
}
|
||||
}
|
||||
$user_levels = implode(',', array_unique($user_levels));
|
||||
|
||||
// Create the query
|
||||
$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 ( $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);
|
||||
|
||||
// Handle the state part of the query
|
||||
if ( $user->authorise('core.edit.state', 'com_attachments') ) {
|
||||
// Do not filter on state since this user can change the state of any attachment
|
||||
}
|
||||
elseif ( $user->authorise('attachments.edit.state.own', 'com_attachments') ) {
|
||||
$query->where('((a.created_by = '.(int)$user->id.') OR (a.state = 1))');
|
||||
}
|
||||
elseif ( $user->authorise('attachments.edit.state.ownparent', 'com_attachments') ) {
|
||||
// The user can edit the state of any attachment if they created the article/parent
|
||||
$parent_creator_id = $parent->getParentCreatorId($parent_id, $parent_entity);
|
||||
if ( (int)$parent_creator_id == (int)$user->get('id') ) {
|
||||
// Do not filter on state since this user can change the state of any attachment on this article/parent
|
||||
}
|
||||
else {
|
||||
// Since the user is not the creator, they should only see published attachments
|
||||
$query->where('a.state = 1');
|
||||
}
|
||||
}
|
||||
else {
|
||||
// For everyone else only show published attachments
|
||||
$query->where('a.state = 1');
|
||||
}
|
||||
}
|
||||
|
||||
$query->where('a.parent_type=' . $db->quote($parent_type) . ' AND a.parent_entity=' . $db->quote($parent_entity));
|
||||
if ( !$user->authorise('core.admin') ) {
|
||||
$query->where('a.access IN ('.$user_levels.')');
|
||||
}
|
||||
$query->order($this->_sort_order);
|
||||
|
||||
// Do the query
|
||||
$db->setQuery($query);
|
||||
$attachments = $db->loadObjectList();
|
||||
if ( $db->getErrorNum() ) {
|
||||
$errmsg = $db->stderr() . ' (ERR 58)';
|
||||
JError::raiseError(500, $errmsg);
|
||||
}
|
||||
|
||||
$this->_some_visible = false;
|
||||
$this->_some_modifiable = false;
|
||||
|
||||
// Install the list of attachments in this object
|
||||
$this->_num_attachments = count($attachments);
|
||||
|
||||
// The query only returns items that are visible/accessible for
|
||||
// the user, so if it contains anything, they will be visible
|
||||
$this->_some_visible = $this->_num_attachments > 0;
|
||||
|
||||
// Add permissions for each attachment in the list
|
||||
if ( $this->_num_attachments > 0 ) {
|
||||
|
||||
$this->_list = $attachments;
|
||||
|
||||
// Add the permissions to each row
|
||||
$parent = $this->getParentClass();
|
||||
|
||||
// Add permissions
|
||||
foreach ( $attachments as $attachment ) {
|
||||
$attachment->user_may_delete = $parent->userMayDeleteAttachment($attachment);
|
||||
$attachment->user_may_edit = $parent->userMayEditAttachment($attachment);
|
||||
if ( $attachment->user_may_edit ) {
|
||||
$this->_some_modifiable = true;
|
||||
}
|
||||
}
|
||||
|
||||
// Fix relative URLs
|
||||
foreach ( $attachments as $attachment ) {
|
||||
if ( $attachment->uri_type == 'url' ) {
|
||||
$url = $attachment->url;
|
||||
if ( strpos($url, '://') === false ) {
|
||||
$uri = JFactory::getURI();
|
||||
$attachment->url = $uri->base(true) . '/' . $url;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Finally, return the list!
|
||||
return $this->_list;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the number of attachments
|
||||
*
|
||||
* @return the number of attachments for this parent
|
||||
*/
|
||||
public function numAttachments()
|
||||
{
|
||||
return $this->_num_attachments;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Are some of the attachments be visible?
|
||||
*
|
||||
* @return true if there are attachments and some should be visible
|
||||
*/
|
||||
public function someVisible()
|
||||
{
|
||||
// See if the attachments list has been loaded
|
||||
if ( $this->_list == null ) {
|
||||
|
||||
// See if we have already loaded the attachements list
|
||||
if ( $this->_num_attachments === 0 ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Since the attachments have not been loaded, load them now
|
||||
$this->getAttachmentsList();
|
||||
}
|
||||
|
||||
return $this->_some_visible;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Should some of the attachments be modifiable?
|
||||
*
|
||||
* @return true if there are attachments and some should be modifiable
|
||||
*/
|
||||
public function someModifiable()
|
||||
{
|
||||
// See if the attachments list has been loaded
|
||||
if ( $this->_list == null ) {
|
||||
|
||||
// See if we have already loaded the attachements list
|
||||
if ( $this->_num_attachments === 0 ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Since the attachments have not been loaded, load them now
|
||||
$this->getAttachmentsList();
|
||||
}
|
||||
|
||||
return $this->_some_modifiable;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Returns the types of attachments
|
||||
*
|
||||
* @return 'file', 'url', 'both', or false (if no attachments)
|
||||
*/
|
||||
public function types()
|
||||
{
|
||||
// Make sure the attachments are loaded
|
||||
if ( $this->_list == null ) {
|
||||
|
||||
// See if we have already loaded the attachements list
|
||||
if ( $this->_num_attachments === 0 ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Since the attachments have not been loaded, load them now
|
||||
$this->getAttachmentsList();
|
||||
}
|
||||
|
||||
// Scan the attachments
|
||||
$types = false;
|
||||
foreach ( $this->_list as $attachment ) {
|
||||
if ( $types ) {
|
||||
if ( $attachment->uri_type != $types ) {
|
||||
return 'both';
|
||||
}
|
||||
}
|
||||
else {
|
||||
$types = $attachment->uri_type;
|
||||
}
|
||||
}
|
||||
|
||||
return $types;
|
||||
}
|
||||
|
||||
}
|
||||
1
components/com_attachments/models/index.html
Normal file
1
components/com_attachments/models/index.html
Normal file
@ -0,0 +1 @@
|
||||
<html><body bgcolor="#FFFFFF"></body></html>
|
||||
260
components/com_attachments/router.php
Normal file
260
components/com_attachments/router.php
Normal file
@ -0,0 +1,260 @@
|
||||
<?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');
|
||||
|
||||
/**
|
||||
* Build the route
|
||||
*
|
||||
* @param &object &$query the query to construct
|
||||
*
|
||||
* @return the segments
|
||||
*/
|
||||
function AttachmentsBuildRoute(&$query)
|
||||
{
|
||||
// Syntax to upload an attachment:
|
||||
// index.php?option=com_attachments&task=upload&article_id=44
|
||||
// --> index.php/attachments/upload/article/44
|
||||
// or:
|
||||
// index.php?option=com_attachments&task=upload&parent_id=44
|
||||
// --> index.php/attachments/upload/parent/44
|
||||
|
||||
// Syntax to delete an attachment:
|
||||
// index.php?option=com_attachments&task=delete&id=4&article_id=44&from=article
|
||||
// --> /attachments/delete/4/artcile/44
|
||||
// --> /attachments/delete/4/article/44/from/article
|
||||
// or:
|
||||
// index.php?option=com_attachments&task=delete&id=4&parent_id=44&from=parent
|
||||
// --> /attachments/delete/4/parent/44
|
||||
// --> /attachments/delete/4/parent/44/from/parent
|
||||
|
||||
// Note: The 'from' clause indicates which view the item was called from (eg, article or frontpage)
|
||||
|
||||
$segments = array();
|
||||
|
||||
// get a menu item based on Itemid or currently active
|
||||
$app = JFactory::getApplication();
|
||||
$menu = $app->getMenu();
|
||||
|
||||
// we need a menu item. Either the one specified in the query, or the current active one if none specified
|
||||
if (empty($query['Itemid'])) {
|
||||
$menuItem = $menu->getActive();
|
||||
}
|
||||
else {
|
||||
$menuItem = $menu->getItem($query['Itemid']);
|
||||
}
|
||||
|
||||
if ( isset($query['task']) ) {
|
||||
$task = $query['task'];
|
||||
$segments[] = $task;
|
||||
unset($query['task']);
|
||||
}
|
||||
|
||||
if ( isset($query['id']) ) {
|
||||
if ( $task == 'update' ) {
|
||||
$segments[] = 'id';
|
||||
}
|
||||
$segments[] = $query['id'];
|
||||
unset($query['id']);
|
||||
}
|
||||
|
||||
if ( isset($query['article_id']) ) {
|
||||
$segments[] = 'article';
|
||||
$segments[] = $query['article_id'];
|
||||
unset($query['article_id']);
|
||||
}
|
||||
|
||||
if ( isset($query['parent_id']) ) {
|
||||
$segments[] = 'parent';
|
||||
$segments[] = $query['parent_id'];
|
||||
unset($query['parent_id']);
|
||||
}
|
||||
|
||||
if ( isset($query['parent_type']) ) {
|
||||
$segments[] = 'parent_type';
|
||||
$segments[] = $query['parent_type'];
|
||||
unset($query['parent_type']);
|
||||
}
|
||||
|
||||
if ( isset($query['parent_entity']) ) {
|
||||
$segments[] = 'parent_entity';
|
||||
$segments[] = $query['parent_entity'];
|
||||
unset($query['parent_entity']);
|
||||
}
|
||||
|
||||
if ( isset($query['controller']) ) {
|
||||
$segments[] = 'controller';
|
||||
$segments[] = $query['controller'];
|
||||
unset($query['controller']);
|
||||
}
|
||||
|
||||
if ( isset($query['uri']) ) {
|
||||
$segments[] = 'uri';
|
||||
$segments[] = $query['uri'];
|
||||
unset($query['uri']);
|
||||
}
|
||||
|
||||
if ( isset($query['update']) ) {
|
||||
$segments[] = 'update';
|
||||
$segments[] = $query['update'];
|
||||
unset($query['update']);
|
||||
}
|
||||
|
||||
if ( isset($query['from']) ) {
|
||||
$segments[] = 'from';
|
||||
$segments[] = $query['from'];
|
||||
unset($query['from']);
|
||||
}
|
||||
|
||||
if ( isset($query['tmpl']) ) {
|
||||
$segments[] = 'tmpl';
|
||||
$segments[] = $query['tmpl'];
|
||||
unset($query['tmpl']);
|
||||
}
|
||||
|
||||
return $segments;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse the route
|
||||
*
|
||||
* @param array $segments
|
||||
*
|
||||
* @return the variables parsed from the route
|
||||
*/
|
||||
function AttachmentsParseRoute($segments)
|
||||
{
|
||||
$vars = array();
|
||||
|
||||
// NOTE: The task=taskname pair must ALWAYS on the right after opton=com_attachments.
|
||||
// if a controller is specified, it must appear later in the URL.
|
||||
|
||||
$task = $segments[0];
|
||||
$vars['task'] = $task;
|
||||
$i = 1;
|
||||
|
||||
// Handle the the main keyword clause that have an id immediately following them
|
||||
if ( ($task == 'delete') || ($task == 'delete_warning') || ($task == 'download') ) {
|
||||
$vars['id'] = $segments[$i];
|
||||
$i = 2;
|
||||
}
|
||||
|
||||
// Handle the other clauses
|
||||
while ( $i < count($segments) ) {
|
||||
|
||||
// Look for article IDs
|
||||
if ( ($segments[$i] == 'article') && ($segments[$i-1] != 'from') ) {
|
||||
if ( $i+1 >= count($segments) ) {
|
||||
echo "<br />Error in AttachmentsParseRoute: Found 'article' without a following article ID!<br />";
|
||||
exit;
|
||||
}
|
||||
$vars['article_id'] = $segments[$i+1];
|
||||
$i++;
|
||||
}
|
||||
|
||||
// Look for parent ID clause
|
||||
if ( (($segments[$i] == 'parent') || ($segments[$i] == 'parent_id')) && ($segments[$i-1] != 'from') ) {
|
||||
if ( $i+1 >= count($segments) ) {
|
||||
echo "<br />Error in AttachmentsParseRoute: Found 'parent' without a following parent ID!<br />";
|
||||
exit;
|
||||
}
|
||||
$vars['parent_id'] = $segments[$i+1];
|
||||
$i++;
|
||||
}
|
||||
|
||||
// Look for 'parent_type' clause
|
||||
if ( $segments[$i] == 'parent_type' ) {
|
||||
if ( $i+1 >= count($segments) ) {
|
||||
echo "<br />Error in AttachmentsParseRoute: Found 'parent_type' without the actual type!<br />";
|
||||
exit;
|
||||
}
|
||||
$vars['parent_type'] = $segments[$i+1];
|
||||
$i++;
|
||||
}
|
||||
|
||||
// Look for 'parent_entity' clause
|
||||
if ( $segments[$i] == 'parent_entity' ) {
|
||||
if ( $i+1 >= count($segments) ) {
|
||||
echo "<br />Error in AttachmentsParseRoute: Found 'parent_entity' without the actual type!<br />";
|
||||
exit;
|
||||
}
|
||||
$vars['parent_entity'] = $segments[$i+1];
|
||||
$i++;
|
||||
}
|
||||
|
||||
// Look for 'controller' clause
|
||||
if ( $segments[$i] == 'controller' ) {
|
||||
if ( $i+1 >= count($segments) ) {
|
||||
echo "<br />Error in AttachmentsParseRoute: Found 'controller' without controller type!<br />";
|
||||
exit;
|
||||
}
|
||||
$vars['controller'] = $segments[$i+1];
|
||||
$i++;
|
||||
}
|
||||
|
||||
// Look for 'id' clause
|
||||
if ( $segments[$i] == 'id' ) {
|
||||
if ( $i+1 >= count($segments) ) {
|
||||
echo "<br />Error in AttachmentsParseRoute: Found 'id' without any info!<br />";
|
||||
exit;
|
||||
}
|
||||
$vars['id'] = $segments[$i+1];
|
||||
}
|
||||
|
||||
// Look for 'uri' clause
|
||||
if ( $segments[$i] == 'uri' ) {
|
||||
if ( $i+1 >= count($segments) ) {
|
||||
echo "<br />Error in AttachmentsParseRoute: Found 'uri' without any info!<br />";
|
||||
exit;
|
||||
}
|
||||
$vars['uri'] = $segments[$i+1];
|
||||
$i++;
|
||||
}
|
||||
|
||||
// Look for 'update' clause
|
||||
if ( $segments[$i] == 'update' ) {
|
||||
if ( $i+1 >= count($segments) ) {
|
||||
echo "<br />Error in AttachmentsParseRoute: Found 'update' without any info!<br />";
|
||||
exit;
|
||||
}
|
||||
$vars['update'] = $segments[$i+1];
|
||||
$i++;
|
||||
}
|
||||
|
||||
// Look for 'from' clause
|
||||
if ( $segments[$i] == 'from' ) {
|
||||
if ( $i+1 >= count($segments) ) {
|
||||
echo "<br />Error in AttachmentsParseRoute: Found 'from' without any info!<br />";
|
||||
exit;
|
||||
}
|
||||
$vars['from'] = $segments[$i+1];
|
||||
$i++;
|
||||
}
|
||||
|
||||
// Look for 'tmpl' clause
|
||||
if ( $segments[$i] == 'tmpl' ) {
|
||||
if ( $i+1 >= count($segments) ) {
|
||||
echo "<br />Error in AttachmentsParseRoute: Found 'tmpl' without any template name!<br />";
|
||||
exit;
|
||||
}
|
||||
$vars['tmpl'] = $segments[$i+1];
|
||||
$i++;
|
||||
}
|
||||
|
||||
$i++;
|
||||
}
|
||||
|
||||
return $vars;
|
||||
}
|
||||
|
||||
?>
|
||||
1
components/com_attachments/views/index.html
Normal file
1
components/com_attachments/views/index.html
Normal file
@ -0,0 +1 @@
|
||||
<html><body bgcolor="#FFFFFF"></body></html>
|
||||
1
components/com_attachments/views/login/index.html
Normal file
1
components/com_attachments/views/login/index.html
Normal file
@ -0,0 +1 @@
|
||||
<html><body bgcolor="#FFFFFF"></body></html>
|
||||
26
components/com_attachments/views/login/tmpl/default.php
Normal file
26
components/com_attachments/views/login/tmpl/default.php
Normal file
@ -0,0 +1,26 @@
|
||||
<?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
|
||||
*/
|
||||
|
||||
// No direct access
|
||||
defined('_JEXEC') or die('Restricted access');
|
||||
|
||||
?>
|
||||
<div class="requestLogin">
|
||||
<?php if ($this->logged_in): ?>
|
||||
<h1><?php echo JText::_('ATTACH_WARNING_YOU_ARE_ALREADY_LOGGED_IN'); ?></h1>
|
||||
<?php else: ?>
|
||||
<h1><?php echo $this->must_be_logged_in; ?></h1>
|
||||
<h2><a href="<?php echo $this->login_url; ?>"><?php echo $this->login_label; ?></a></h2>
|
||||
<h2><a href="<?php echo $this->register_url; ?>"><?php echo $this->register_label; ?></a></h2>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
1
components/com_attachments/views/login/tmpl/index.html
Normal file
1
components/com_attachments/views/login/tmpl/index.html
Normal file
@ -0,0 +1 @@
|
||||
<html><body bgcolor="#FFFFFF"></body></html>
|
||||
75
components/com_attachments/views/login/view.html.php
Normal file
75
components/com_attachments/views/login/view.html.php
Normal file
@ -0,0 +1,75 @@
|
||||
<?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
|
||||
*/
|
||||
|
||||
// no direct access
|
||||
defined( '_JEXEC' ) or die('Restricted access');
|
||||
|
||||
/** Define the legacy classes, if necessary */
|
||||
require_once(JPATH_SITE.'/components/com_attachments/legacy/view.php');
|
||||
|
||||
|
||||
/**
|
||||
* HTML View class for asking the user to log in
|
||||
*
|
||||
* @package Attachments
|
||||
*/
|
||||
class AttachmentsViewLogin extends JViewLegacy
|
||||
{
|
||||
/**
|
||||
* Display the login view
|
||||
*/
|
||||
public function display($tpl = null)
|
||||
{
|
||||
// Add the stylesheets
|
||||
JHtml::stylesheet('com_attachments/attachments_frontend_form.css', array(), true);
|
||||
$lang = JFactory::getLanguage();
|
||||
if ( $lang->isRTL() ) {
|
||||
JHtml::stylesheet('com_attachments/attachments_frontend_form_rtl.css', array(), true);
|
||||
}
|
||||
|
||||
// Is the user already logged in?
|
||||
$user = JFactory::getUser();
|
||||
$this->logged_in = $user->get('username') <> '';
|
||||
|
||||
// Get the component parameters for the registration and login URL
|
||||
jimport('joomla.application.component.helper');
|
||||
$params = JComponentHelper::getParams('com_attachments');
|
||||
|
||||
$base_url = JFactory::getURI()->base(false);
|
||||
$register_url = $params->get('register_url', 'index.php?option=com_users&view=registration');
|
||||
$register_url = JRoute::_($base_url . $register_url);
|
||||
$this->register_url = $register_url;
|
||||
|
||||
// Construct the login URL
|
||||
$return = '';
|
||||
if ( $this->return_url ) {
|
||||
$return = '&return=' . $this->return_url;
|
||||
}
|
||||
$base_url = JFactory::getURI()->base(false);
|
||||
$login_url = $params->get('login_url', 'index.php?option=com_users&view=login') . $return;
|
||||
$this->login_url = JRoute::_($base_url . $login_url);
|
||||
|
||||
// Get the warning message
|
||||
$this->must_be_logged_in = JText::_('ATTACH_WARNING_MUST_LOGIN_TO_DOWNLOAD_ATTACHMENT');
|
||||
|
||||
// Get a phrase from the login module to create the account
|
||||
$lang->load('com_users');
|
||||
$register = JText::_('COM_USERS_REGISTER_DEFAULT_LABEL');
|
||||
$this->register_label = $register;
|
||||
|
||||
$login = JText::_('JLOGIN');
|
||||
$this->login_label = $login;
|
||||
|
||||
parent::display($tpl);
|
||||
}
|
||||
}
|
||||
1
components/com_attachments/views/update/index.html
Normal file
1
components/com_attachments/views/update/index.html
Normal file
@ -0,0 +1 @@
|
||||
<html><body bgcolor="#FFFFFF"></body></html>
|
||||
5
components/com_attachments/views/update/metadata.xml
Normal file
5
components/com_attachments/views/update/metadata.xml
Normal file
@ -0,0 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<metadata>
|
||||
<view title="ATTACH_UPDATE_DO_NOT_ATTACH_TO_MENU_ITEM" hidden="true">
|
||||
</view>
|
||||
</metadata>
|
||||
262
components/com_attachments/views/update/tmpl/default.php
Normal file
262
components/com_attachments/views/update/tmpl/default.php
Normal file
@ -0,0 +1,262 @@
|
||||
<?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
|
||||
*/
|
||||
|
||||
// No direct access
|
||||
defined('_JEXEC') or die('Restricted access');
|
||||
|
||||
// Add the plugins stylesheet to style the list of attachments
|
||||
$user = JFactory::getUser();
|
||||
$document = JFactory::getDocument();
|
||||
$app = JFactory::getApplication();
|
||||
$uri = JFactory::getURI();
|
||||
|
||||
$lang = JFactory::getLanguage();
|
||||
|
||||
// For convenience
|
||||
$attachment = $this->attachment;
|
||||
$params = $this->params;
|
||||
$update = $this->update;
|
||||
|
||||
$parent_id = $attachment->parent_id;
|
||||
if ( $parent_id === null ) {
|
||||
$parent_id = 0;
|
||||
}
|
||||
|
||||
// set up URL redisplay in case of errors
|
||||
$old_url = '';
|
||||
if ( $this->error_msg && ($update == 'url') ) {
|
||||
$old_url = $attachment->url;
|
||||
}
|
||||
|
||||
// Decide what type of update to do
|
||||
if ( $update == 'file' ) {
|
||||
$enctype = "enctype=\"multipart/form-data\"";
|
||||
}
|
||||
else {
|
||||
$enctype = '';
|
||||
}
|
||||
|
||||
// Prepare for error displays
|
||||
$update_id = 'upload';
|
||||
$filename = $attachment->filename;
|
||||
if ( $this->error ) {
|
||||
switch ( $this->error ) {
|
||||
|
||||
case 'no_file':
|
||||
$update_id = 'upload_warning';
|
||||
$filename = '';
|
||||
break;
|
||||
|
||||
case 'file_too_big':
|
||||
$upload_id = 'upload_warning';
|
||||
break;
|
||||
|
||||
case 'file_already_on_server':
|
||||
$upload_id = 'upload_warning';
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Format modified date
|
||||
jimport( 'joomla.utilities.date' );
|
||||
$tz = new DateTimeZone( $user->getParam('timezone', $app->getCfg('offset')) );
|
||||
$mdate = JFactory::getDate($attachment->modified);
|
||||
$mdate->setTimezone($tz);
|
||||
$date_format = $params->get('date_format', 'Y-m-d H:i');
|
||||
$last_modified = $mdate->format($date_format, true);
|
||||
|
||||
// If this is an error re-display, display the CSS links directly
|
||||
$echo_css = $this->error;
|
||||
|
||||
/** Load the Attachments helper */
|
||||
require_once(JPATH_SITE.'/components/com_attachments/helper.php');
|
||||
require_once(JPATH_SITE.'/components/com_attachments/javascript.php');
|
||||
|
||||
// Add the stylesheets
|
||||
$uri = JFactory::getURI();
|
||||
|
||||
AttachmentsJavascript::setupJavascript();
|
||||
|
||||
if ( $attachment->uri_type == 'file' ) {
|
||||
$header_msg = JText::sprintf('ATTACH_UPDATE_ATTACHMENT_FILE_S', $filename);
|
||||
}
|
||||
else {
|
||||
$header_msg = JText::sprintf('ATTACH_UPDATE_ATTACHMENT_URL_S', $attachment->url);
|
||||
}
|
||||
|
||||
// If this is an error re-display, display the CSS links directly
|
||||
if ( $this->error )
|
||||
{
|
||||
echo $this->startHTML();
|
||||
}
|
||||
|
||||
?>
|
||||
<div id="uploadAttachmentsPage">
|
||||
<h1><?php echo $header_msg; ?></h1>
|
||||
<form class="attachments" <?php echo $enctype ?> name="upload_form"
|
||||
action="<?php echo $this->save_url; ?>" method="post">
|
||||
<fieldset>
|
||||
<legend><?php echo JText::sprintf('ATTACH_UPDATE_ATTACHMENT_FOR_PARENT_S_COLON_S',
|
||||
$attachment->parent_entity_name, $attachment->parent_title); ?></legend>
|
||||
<?php if ( $this->error_msg ): ?>
|
||||
<div class="formWarning" id="formWarning"><?php echo $this->error_msg; ?></div>
|
||||
<?php endif; ?>
|
||||
<?php if ( $update == 'file' ): ?>
|
||||
<p><label for="<?php echo $update_id; ?>"><?php
|
||||
echo JText::_('ATTACH_SELECT_NEW_FILE_IF_YOU_WANT_TO_UPDATE_ATTACHMENT_FILE') ?></label>
|
||||
<a class="changeButton" href="<?php echo $this->normal_update_url ?>"
|
||||
title="<?php echo JText::_('ATTACH_NORMAL_UPDATE_TOOLTIP'); ?>"
|
||||
><?php echo JText::_('ATTACH_NORMAL_UPDATE') ?></a> <br />
|
||||
<input type="file" name="upload" id="<?php echo $update_id; ?>"
|
||||
size="78" maxlength="1024" />
|
||||
</p>
|
||||
<?php elseif ( $update == 'url' ): ?>
|
||||
<p><label for="<?php echo $update_id; ?>"><?php echo JText::_('ATTACH_ENTER_URL') ?></label>
|
||||
|
||||
<label for="verify_url"><?php echo JText::_('ATTACH_VERIFY_URL_EXISTENCE') ?></label>
|
||||
<input type="checkbox" name="verify_url" value="verify" <?php echo $this->verify_url_checked ?>
|
||||
title="<?php echo JText::_('ATTACH_VERIFY_URL_EXISTENCE_TOOLTIP'); ?>" />
|
||||
|
||||
<label for="relative_url"><?php echo JText::_('ATTACH_RELATIVE_URL') ?></label>
|
||||
<input type="checkbox" name="relative_url" value="relative" <?php echo $this->relative_url_checked ?>
|
||||
title="<?php echo JText::_('ATTACH_RELATIVE_URL_TOOLTIP'); ?>" />
|
||||
<a class="changeButton" href="<?php echo $this->normal_update_url ?>"
|
||||
title="<?php echo JText::_('ATTACH_NORMAL_UPDATE_TOOLTIP'); ?>"
|
||||
><?php echo JText::_('ATTACH_NORMAL_UPDATE') ?></a> <br />
|
||||
<input type="text" name="url" id="<?php echo $update_id; ?>"
|
||||
size="80" maxlength="255" title="<?php echo JText::_('ATTACH_ENTER_URL_TOOLTIP'); ?>"
|
||||
value="<?php echo $old_url; ?>" /><br /><?php
|
||||
echo JText::_('ATTACH_NOTE_ENTER_URL_WITH_HTTP'); ?>
|
||||
</p>
|
||||
<?php else: ?>
|
||||
<?php if ( $attachment->uri_type == 'file' ): ?>
|
||||
<p><label><?php echo JText::_('ATTACH_FILENAME_COLON'); ?></label> <?php echo $filename; ?>
|
||||
<a class="changeButton" href="<?php echo $this->change_file_url ?>"
|
||||
title="<?php echo JText::_('ATTACH_CHANGE_FILE_TOOLTIP'); ?>"
|
||||
><?php echo JText::_('ATTACH_CHANGE_FILE') ?></a>
|
||||
<a class="changeButton" href="<?php echo $this->change_url_url ?>"
|
||||
title="<?php echo JText::_('ATTACH_CHANGE_TO_URL_TOOLTIP'); ?>"
|
||||
><?php echo JText::_('ATTACH_CHANGE_TO_URL') ?></a>
|
||||
</p>
|
||||
<?php elseif ( $attachment->uri_type == 'url' ): ?>
|
||||
<p><label for="<?php echo $update_id; ?>"><?php echo JText::_('ATTACH_ENTER_NEW_URL_COLON') ?></label>
|
||||
|
||||
<label for="verify_url"><?php echo JText::_('ATTACH_VERIFY_URL_EXISTENCE') ?></label>
|
||||
<input type="checkbox" name="verify_url" value="verify" <?php echo $this->verify_url_checked ?>
|
||||
title="<?php echo JText::_('ATTACH_VERIFY_URL_EXISTENCE_TOOLTIP'); ?>" />
|
||||
|
||||
<label for="relative_url"><?php echo JText::_('ATTACH_RELATIVE_URL') ?></label>
|
||||
<input type="checkbox" name="relative_url" value="relative" <?php echo $this->relative_url_checked ?>
|
||||
title="<?php echo JText::_('ATTACH_RELATIVE_URL_TOOLTIP'); ?>" />
|
||||
<a class="changeButton" href="<?php echo $this->change_file_url ?>"
|
||||
title="<?php echo JText::_('ATTACH_CHANGE_TO_FILE_TOOLTIP'); ?>"
|
||||
><?php echo JText::_('ATTACH_CHANGE_TO_FILE') ?></a> </p>
|
||||
<p><label for="url_valid"><?php echo JText::_('ATTACH_URL_IS_VALID') ?></label>
|
||||
<?php echo $this->lists['url_valid']; ?>
|
||||
</p>
|
||||
<p>
|
||||
<input type="text" name="url" id="<?php echo $update_id ?>"
|
||||
size="80" maxlength="255" title="<?php echo JText::_('ATTACH_ENTER_URL_TOOLTIP'); ?>"
|
||||
value="<?php echo $attachment->url; ?>" /><br /><?php
|
||||
echo JText::_('ATTACH_NOTE_ENTER_URL_WITH_HTTP'); ?>
|
||||
<input type="hidden" name="old_url" value="<?php echo $old_url; ?>" />
|
||||
</p>
|
||||
<?php endif; ?>
|
||||
<?php endif; ?>
|
||||
<?php if ( (($attachment->uri_type == 'file') AND ($update == '') ) OR ($update == 'file') ): ?>
|
||||
<p class="display_name"><label for="display_name"
|
||||
title="<?php echo JText::_('ATTACH_DISPLAY_FILENAME_TOOLTIP'); ?>"
|
||||
><?php echo JText::_('ATTACH_DISPLAY_FILENAME_OPTIONAL_COLON'); ?></label>
|
||||
<input type="text" name="display_name" id="display_name"
|
||||
size="70" maxlength="80"
|
||||
title="<?php echo JText::_('ATTACH_DISPLAY_FILENAME_TOOLTIP'); ?>"
|
||||
value="<?php echo $attachment->display_name; ?>" />
|
||||
<input type="hidden" name="old_display_name" value="<?php echo $attachment->display_name; ?>" />
|
||||
</p>
|
||||
<?php elseif ( (($attachment->uri_type == 'url') AND ($update == '')) OR ($update == 'url') ): ?>
|
||||
<p class="display_name"><label for="display_name"
|
||||
title="<?php echo JText::_('ATTACH_DISPLAY_URL_TOOLTIP'); ?>"
|
||||
><?php echo JText::_('ATTACH_DISPLAY_URL_COLON'); ?></label>
|
||||
<input type="text" name="display_name" id="display_name"
|
||||
size="70" maxlength="80"
|
||||
title="<?php echo JText::_('ATTACH_DISPLAY_URL_TOOLTIP'); ?>"
|
||||
value="<?php echo $attachment->display_name; ?>" />
|
||||
<input type="hidden" name="old_display_name" value="<?php echo $attachment->display_name; ?>" />
|
||||
</p>
|
||||
<?php endif; ?>
|
||||
<p><label for="description"><?php echo JText::_('ATTACH_DESCRIPTION_COLON'); ?></label>
|
||||
<input type="text" name="description" id="description"
|
||||
size="70" maxlength="255" value="<?php echo stripslashes($attachment->description) ?>" /></p>
|
||||
<?php if ( $this->may_publish ): ?>
|
||||
<div class="at_control"><label><?php echo JText::_('ATTACH_PUBLISHED'); ?></label><?php echo $this->lists['published']; ?></div>
|
||||
<?php endif; ?>
|
||||
<?php if ( $params->get('allow_frontend_access_editing', false) ): ?>
|
||||
|
||||
<div class="at_control"><label for="access" title="<?php echo $this->access_level_tooltip; ?>"><? echo JText::_('ATTACH_ACCESS_COLON'); ?></label> <?php echo $this->access_level; ?></div>
|
||||
<?php endif; ?>
|
||||
<?php if ( $params->get('user_field_1_name') ): ?>
|
||||
<p><label for="user_field_1"><?php echo $params->get('user_field_1_name'); ?>:</label>
|
||||
<input type="text" name="user_field_1" id="user_field_1" size="70" maxlength="100"
|
||||
value="<?php echo stripslashes($attachment->user_field_1); ?>" /></p>
|
||||
<?php endif; ?>
|
||||
<?php if ( $params->get('user_field_2_name') ): ?>
|
||||
<p><label for="user_field_2"><?php echo $params->get('user_field_2_name'); ?>:</label>
|
||||
<input type="text" name="user_field_2" id="user_field_2" size="70" maxlength="100"
|
||||
value="<?php echo stripslashes($attachment->user_field_2); ?>" /></p>
|
||||
<?php endif; ?>
|
||||
<?php if ( $params->get('user_field_3_name') ): ?>
|
||||
<p><label for="user_field_3"><?php echo $params->get('user_field_3_name'); ?>:</label>
|
||||
<input type="text" name="user_field_3" id="user_field_3" size="70" maxlength="100"
|
||||
value="<?php echo stripslashes($attachment->user_field_3); ?>" /></p>
|
||||
<?php endif; ?>
|
||||
<p><?php echo JText::sprintf('ATTACH_LAST_MODIFIED_ON_D_BY_S',
|
||||
$last_modified, $attachment->modifier_name); ?></p>
|
||||
</fieldset>
|
||||
<input type="hidden" name="MAX_FILE_SIZE" value="524288" />
|
||||
<input type="hidden" name="submitted" value="TRUE" />
|
||||
<input type="hidden" name="id" value="<?php echo $attachment->id; ?>" />
|
||||
<input type="hidden" name="save_type" value="update" />
|
||||
<input type="hidden" name="update" value="<?php echo $update; ?>" />
|
||||
<input type="hidden" name="uri_type" value="<?php echo $attachment->uri_type; ?>" />
|
||||
<input type="hidden" name="new_parent" value="<?php echo $this->new_parent; ?>" />
|
||||
<input type="hidden" name="parent_id" value="<?php echo $parent_id; ?>" />
|
||||
<input type="hidden" name="parent_type" value="<?php echo $attachment->parent_type; ?>" />
|
||||
<input type="hidden" name="parent_entity" value="<?php echo $attachment->parent_entity; ?>" />
|
||||
<input type="hidden" name="from" value="<?php echo $this->from; ?>" />
|
||||
<input type="hidden" name="Itemid" value="<?php echo $this->Itemid; ?>" />
|
||||
<?php echo JHtml::_( 'form.token' ); ?>
|
||||
<div class="form_buttons">
|
||||
<input type="submit" name="submit" value="<?php echo JText::_('ATTACH_UPDATE'); ?>" />
|
||||
<span class="right">
|
||||
<input type="button" name="cancel" value="<?php echo JText::_('ATTACH_CANCEL'); ?>"
|
||||
onClick="window.parent.SqueezeBox.close();" />
|
||||
</span>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<?php
|
||||
|
||||
// Generate the list of existing attachments
|
||||
if ( ($update == 'file') || ($attachment->uri_type == 'file') ) {
|
||||
require_once(JPATH_SITE.'/components/com_attachments/controllers/attachments.php');
|
||||
$controller = new AttachmentsControllerAttachments();
|
||||
$controller->display($parent_id, $attachment->parent_type, $attachment->parent_entity,
|
||||
'ATTACH_EXISTING_ATTACHMENTS',
|
||||
false, false, true, $this->from);
|
||||
}
|
||||
|
||||
echo '</div>';
|
||||
|
||||
if ( $this->error ) {
|
||||
echo $this->endHTML();
|
||||
}
|
||||
1
components/com_attachments/views/update/tmpl/index.html
Normal file
1
components/com_attachments/views/update/tmpl/index.html
Normal file
@ -0,0 +1 @@
|
||||
<html><body bgcolor="#FFFFFF"></body></html>
|
||||
88
components/com_attachments/views/update/view.html.php
Normal file
88
components/com_attachments/views/update/view.html.php
Normal file
@ -0,0 +1,88 @@
|
||||
<?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
|
||||
*/
|
||||
|
||||
// No direct access
|
||||
defined('_JEXEC') or die();
|
||||
|
||||
/** Define the legacy classes, if necessary */
|
||||
require_once(JPATH_SITE.'/components/com_attachments/views/view.php');
|
||||
|
||||
/** Load the Attachments helper */
|
||||
require_once(JPATH_SITE.'/components/com_attachments/helper.php');
|
||||
|
||||
|
||||
/**
|
||||
* View for the uploads
|
||||
*
|
||||
* @package Attachments
|
||||
*/
|
||||
class AttachmentsViewUpdate extends AttachmentsFormView
|
||||
{
|
||||
/**
|
||||
* Display the view
|
||||
*/
|
||||
public function display($tpl=null)
|
||||
{
|
||||
// Access check.
|
||||
if ( !(JFactory::getUser()->authorise('core.edit', 'com_attachments') OR
|
||||
JFactory::getUser()->authorise('core.edit.own', 'com_attachments')) ) {
|
||||
return JError::raiseError(404, JText::_('JERROR_ALERTNOAUTHOR') . ' (ERR 62)');
|
||||
}
|
||||
|
||||
// For convenience
|
||||
$attachment = $this->attachment;
|
||||
$parent = $this->parent;
|
||||
|
||||
// Construct derived data
|
||||
$attachment->parent_entity_name = JText::_('ATTACH_' . $attachment->parent_entity);
|
||||
$attachment->parent_title = $parent->getTitle($attachment->parent_id, $attachment->parent_entity);
|
||||
if (!isset($attachment->modifier_name))
|
||||
{
|
||||
AttachmentsHelper::addAttachmentUserNames($attachment);
|
||||
}
|
||||
|
||||
$this->relative_url_checked = $attachment->url_relative ? 'checked="yes"' : '';
|
||||
$this->verify_url_checked = $attachment->url_verify ? 'checked="yes"' : '';
|
||||
|
||||
$this->may_publish = $parent->userMayChangeAttachmentState($attachment->parent_id,
|
||||
$attachment->parent_entity,
|
||||
$attachment->created_by
|
||||
);
|
||||
|
||||
// Set up some HTML for display in the form
|
||||
$this->lists = Array();
|
||||
$this->lists['published'] = JHtml::_('select.booleanlist', 'state',
|
||||
'class="inputbox"', $attachment->state);
|
||||
$this->lists['url_valid'] = JHtml::_('select.booleanlist', 'url_valid',
|
||||
'class="inputbox" title="' . JText::_('ATTACH_URL_IS_VALID_TOOLTIP') . '"',
|
||||
$attachment->url_valid);
|
||||
|
||||
// Set up for editing the access level
|
||||
if ( $this->params->get('allow_frontend_access_editing', false) ) {
|
||||
require_once(JPATH_COMPONENT_ADMINISTRATOR.'/models/fields/accesslevels.php');
|
||||
$this->access_level = JFormFieldAccessLevels::getAccessLevels('access', 'access', $attachment->access);
|
||||
$this->access_level_tooltip = JText::_('ATTACH_ACCESS_LEVEL_TOOLTIP');
|
||||
}
|
||||
|
||||
// Add the stylesheets
|
||||
JHtml::stylesheet('com_attachments/attachments_frontend_form.css', array(), true);
|
||||
$lang = JFactory::getLanguage();
|
||||
if ( $lang->isRTL() ) {
|
||||
JHtml::stylesheet('com_attachments/attachments_frontend_form_rtl.css', array(), true);
|
||||
}
|
||||
|
||||
// Display the form
|
||||
parent::display($tpl);
|
||||
}
|
||||
|
||||
}
|
||||
1
components/com_attachments/views/upload/index.html
Normal file
1
components/com_attachments/views/upload/index.html
Normal file
@ -0,0 +1 @@
|
||||
<html><body bgcolor="#FFFFFF"></body></html>
|
||||
5
components/com_attachments/views/upload/metadata.xml
Normal file
5
components/com_attachments/views/upload/metadata.xml
Normal file
@ -0,0 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<metadata>
|
||||
<view title="ATTACH_UPLOAD_DO_NOT_ATTACH_TO_MENU_ITEM" hidden="true">
|
||||
</view>
|
||||
</metadata>
|
||||
211
components/com_attachments/views/upload/tmpl/default.php
Normal file
211
components/com_attachments/views/upload/tmpl/default.php
Normal file
@ -0,0 +1,211 @@
|
||||
<?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
|
||||
*/
|
||||
|
||||
// No direct access
|
||||
defined('_JEXEC') or die('Restricted access');
|
||||
|
||||
// Load the Attachments helper
|
||||
require_once(JPATH_SITE.'/components/com_attachments/helper.php');
|
||||
require_once(JPATH_SITE.'/components/com_attachments/javascript.php');
|
||||
|
||||
// Add the plugins stylesheet to style the list of attachments
|
||||
$uri = JFactory::getURI();
|
||||
|
||||
// Add javascript
|
||||
AttachmentsJavascript::setupJavascript();
|
||||
AttachmentsJavascript::setupModalJavascript();
|
||||
|
||||
// For convenience
|
||||
$attachment = $this->attachment;
|
||||
$params = $this->params;
|
||||
|
||||
// Get the parent id and a few other convenience items
|
||||
$parent_id = $attachment->parent_id;
|
||||
if ( $parent_id === null ) {
|
||||
$parent_id = 0;
|
||||
}
|
||||
|
||||
|
||||
// Set up to toggle between uploading file/urls
|
||||
if ( $attachment->uri_type == 'file' ) {
|
||||
$upload_toggle_button_text = JText::_('ATTACH_ENTER_URL_INSTEAD');
|
||||
$upload_toggle_url = $this->upload_url_url;
|
||||
$upload_button_text = JText::_('ATTACH_UPLOAD_VERB');
|
||||
}
|
||||
else {
|
||||
$upload_toggle_button_text = JText::_('ATTACH_SELECT_FILE_TO_UPLOAD_INSTEAD');
|
||||
$upload_toggle_url = $this->upload_file_url;
|
||||
$upload_button_text = JText::_('ATTACH_ADD_URL');
|
||||
}
|
||||
|
||||
// If this is for an existing content item, modify the URL appropriately
|
||||
if ( $this->new_parent ) {
|
||||
$upload_toggle_url .= "&parent_id=0,new";
|
||||
}
|
||||
if ( JRequest::getWord('editor') ) {
|
||||
$upload_toggle_url .= "&editor=" . JRequest::getWord('editor');
|
||||
}
|
||||
|
||||
// Needed URLs
|
||||
$save_url = JRoute::_($this->save_url);
|
||||
$base_url = $uri->root(true) . '/';
|
||||
|
||||
// Prepare for error displays
|
||||
$upload_id = 'upload';
|
||||
switch ( $this->error ) {
|
||||
case 'no_file':
|
||||
$upload_id = 'upload_warning';
|
||||
break;
|
||||
|
||||
case 'file_too_big':
|
||||
$upload_id = 'upload_warning';
|
||||
break;
|
||||
|
||||
case 'file_already_on_server':
|
||||
$upload_id = 'upload_warning';
|
||||
break;
|
||||
}
|
||||
|
||||
// If this is an error re-display, display the CSS links directly
|
||||
if ( $this->error )
|
||||
{
|
||||
echo $this->startHTML();
|
||||
}
|
||||
|
||||
// Display the form
|
||||
?>
|
||||
<div id="uploadAttachmentsPage">
|
||||
<h1><?php echo JText::sprintf('ATTACH_FOR_PARENT_S_COLON_S', $attachment->parent_entity_name, $attachment->parent_title) ?></h1>
|
||||
<form class="attachments" enctype="multipart/form-data" name="upload_form"
|
||||
action="<?php echo $this->save_url; ?>" method="post">
|
||||
<fieldset>
|
||||
<legend><?php echo JText::_('ATTACH_UPLOAD_ATTACHMENT'); ?></legend>
|
||||
<?php if ( $this->error_msg ): ?>
|
||||
<div class="formWarning" id="formWarning"><?php echo $this->error_msg; ?></div>
|
||||
<?php endif; ?>
|
||||
<?php if ( $attachment->uri_type == 'file' ): ?>
|
||||
<p><label for="<?php echo $upload_id ?>"><?php
|
||||
echo JText::_('ATTACH_ATTACH_FILE_COLON') ?></label>
|
||||
<a class="changeButton" href="<?php echo $upload_toggle_url ?>"><?php
|
||||
echo $upload_toggle_button_text;?></a></p>
|
||||
<p><input type="file" name="upload" id="<?php echo $upload_id; ?>"
|
||||
size="78" maxlength="1024" /></p>
|
||||
<p class="display_name"><label for="display_name"
|
||||
title="<?php echo JText::_('ATTACH_DISPLAY_FILENAME_TOOLTIP'); ?>"
|
||||
><?php echo JText::_('ATTACH_DISPLAY_FILENAME_OPTIONAL_COLON'); ?></label>
|
||||
<input type="text" name="display_name" id="display_name"
|
||||
size="70" maxlength="80"
|
||||
title="<?php echo JText::_('ATTACH_DISPLAY_FILENAME_TOOLTIP'); ?>"
|
||||
value="<?php echo $attachment->display_name; ?>" /></p>
|
||||
<?php else: ?>
|
||||
<p><label for="<?php echo $upload_id ?>"><?php
|
||||
echo JText::_('ATTACH_ENTER_URL') ?></label>
|
||||
|
||||
<label for="verify_url"><?php echo JText::_('ATTACH_VERIFY_URL_EXISTENCE') ?></label>
|
||||
<input type="checkbox" name="verify_url" value="verify" <?php echo $this->verify_url_checked ?>
|
||||
title="<?php echo JText::_('ATTACH_VERIFY_URL_EXISTENCE_TOOLTIP'); ?>" />
|
||||
|
||||
<label for="relative_url"><?php echo JText::_('ATTACH_RELATIVE_URL') ?></label>
|
||||
<input type="checkbox" name="relative_url" value="relative" <?php echo $this->relative_url_checked ?>
|
||||
title="<?php echo JText::_('ATTACH_RELATIVE_URL_TOOLTIP'); ?>" />
|
||||
<a class="changeButton" href="<?php echo $upload_toggle_url ?>"><?php
|
||||
echo $upload_toggle_button_text;?></a><br />
|
||||
<input type="text" name="url" id="<?php echo $upload_id; ?>"
|
||||
size="80" maxlength="255" title="<?php echo JText::_('ATTACH_ENTER_URL_TOOLTIP'); ?>"
|
||||
value="<?php echo $attachment->url; ?>" /><br /><?php
|
||||
echo JText::_('ATTACH_NOTE_ENTER_URL_WITH_HTTP'); ?></p>
|
||||
<p class="display_name"><label for="display_name"
|
||||
title="<?php echo JText::_('ATTACH_DISPLAY_URL_TOOLTIP'); ?>"
|
||||
><?php echo JText::_('ATTACH_DISPLAY_URL_COLON'); ?></label>
|
||||
<input type="text" name="display_name" id="display_name"
|
||||
size="70" maxlength="80"
|
||||
title="<?php echo JText::_('ATTACH_DISPLAY_URL_TOOLTIP'); ?>"
|
||||
value="<?php echo $attachment->display_name; ?>" /></p>
|
||||
<?php endif; ?>
|
||||
<p><label for="description"><?php echo JText::_('ATTACH_DESCRIPTION_COLON'); ?></label>
|
||||
<input type="text" name="description" id="description"
|
||||
size="70" maxlength="255"
|
||||
value="<?php echo stripslashes($attachment->description); ?>" /></p>
|
||||
<?php if ( $this->may_publish ): ?>
|
||||
<div class="at_control"><label><?php echo JText::_('ATTACH_PUBLISHED'); ?></label><?php echo $this->publish; ?></div>
|
||||
<?php endif; ?>
|
||||
<?php if ( $params->get('allow_frontend_access_editing', false) ): ?>
|
||||
|
||||
<div class="at_control"><label for="access" title="<?php echo $this->access_level_tooltip; ?>"><? echo JText::_('ATTACH_ACCESS_COLON'); ?></label> <?php echo $this->access_level; ?></div>
|
||||
<?php endif; ?>
|
||||
<?php if ( $params->get('user_field_1_name', false) ): ?>
|
||||
<p><label for="user_field_1"><?php echo $params->get('user_field_1_name'); ?>:</label>
|
||||
<input type="text" name="user_field_1" id="user_field_1" size="70" maxlength="100"
|
||||
value="<?php echo stripslashes($attachment->user_field_1); ?>" /></p>
|
||||
<?php endif; ?>
|
||||
<?php if ( $params->get('user_field_2_name', false) ): ?>
|
||||
<p><label for="user_field_2"><?php echo $params->get('user_field_2_name'); ?>:</label>
|
||||
<input type="text" name="user_field_2" id="user_field_2" size="70" maxlength="100"
|
||||
value="<?php echo stripslashes($attachment->user_field_2); ?>" /></p>
|
||||
<?php endif; ?>
|
||||
<?php if ( $params->get('user_field_3_name', false) ): ?>
|
||||
<p><label for="user_field_3"><?php echo $params->get('user_field_3_name'); ?>:</label>
|
||||
<input type="text" name="user_field_3" id="user_field_3" size="70" maxlength="100"
|
||||
value="<?php echo stripslashes($attachment->user_field_3); ?>" /></p>
|
||||
<?php endif; ?>
|
||||
|
||||
</fieldset>
|
||||
<input type="hidden" name="MAX_FILE_SIZE" value="524288" />
|
||||
<input type="hidden" name="submitted" value="TRUE" />
|
||||
<input type="hidden" name="save_type" value="upload" />
|
||||
<input type="hidden" name="uri_type" value="<?php echo $attachment->uri_type; ?>" />
|
||||
<input type="hidden" name="update_file" value="TRUE" />
|
||||
<input type="hidden" name="parent_id" value="<?php echo $parent_id; ?>" />
|
||||
<input type="hidden" name="parent_type" value="<?php echo $attachment->parent_type; ?>" />
|
||||
<input type="hidden" name="parent_entity" value="<?php echo $attachment->parent_entity; ?>" />
|
||||
<input type="hidden" name="new_parent" value="<?php echo $this->new_parent; ?>" />
|
||||
<input type="hidden" name="from" value="<?php echo $this->from; ?>" />
|
||||
<input type="hidden" name="Itemid" value="<?php echo $this->Itemid; ?>" />
|
||||
<?php echo JHtml::_( 'form.token' ); ?>
|
||||
|
||||
<br/><div class="form_buttons">
|
||||
<input type="submit" name="submit" value="<?php echo $upload_button_text ?>" />
|
||||
<span class="right">
|
||||
<input type="button" name="cancel" value="<?php echo JText::_('ATTACH_CANCEL'); ?>"
|
||||
onClick="window.parent.SqueezeBox.close();" />
|
||||
</span>
|
||||
</div>
|
||||
</form>
|
||||
<?php
|
||||
|
||||
// Display the auto-publish warning, if appropriate
|
||||
if ( !$params->get('publish_default', false) && !$this->may_publish ) {
|
||||
$msg = $params->get('auto_publish_warning', '');
|
||||
if ( JString::strlen($msg) == 0 ) {
|
||||
$msg = JText::_('ATTACH_WARNING_ADMIN_MUST_PUBLISH');
|
||||
}
|
||||
else {
|
||||
$msg = JText::_($msg);
|
||||
}
|
||||
echo "<h2>$msg</h2>";
|
||||
}
|
||||
|
||||
// Show the existing attachments (if any)
|
||||
if ( $parent_id || ($parent_id === 0) ) {
|
||||
require_once(JPATH_SITE.'/components/com_attachments/controllers/attachments.php');
|
||||
$controller = new AttachmentsControllerAttachments();
|
||||
$controller->displayString($parent_id, $attachment->parent_type, $attachment->parent_entity,
|
||||
'ATTACH_EXISTING_ATTACHMENTS',
|
||||
false, false, true, $this->from);
|
||||
}
|
||||
|
||||
echo "</div>";
|
||||
|
||||
if ( $this->error ) {
|
||||
echo $this->endHTML();
|
||||
}
|
||||
1
components/com_attachments/views/upload/tmpl/index.html
Normal file
1
components/com_attachments/views/upload/tmpl/index.html
Normal file
@ -0,0 +1 @@
|
||||
<html><body bgcolor="#FFFFFF"></body></html>
|
||||
77
components/com_attachments/views/upload/view.html.php
Normal file
77
components/com_attachments/views/upload/view.html.php
Normal file
@ -0,0 +1,77 @@
|
||||
<?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
|
||||
*/
|
||||
|
||||
// No direct access
|
||||
defined('_JEXEC') or die();
|
||||
|
||||
/** Define the legacy classes, if necessary */
|
||||
require_once(JPATH_SITE.'/components/com_attachments/views/view.php');
|
||||
|
||||
|
||||
/**
|
||||
* View for the uploads
|
||||
*
|
||||
* @package Attachments
|
||||
*/
|
||||
class AttachmentsViewUpload extends AttachmentsFormView
|
||||
{
|
||||
|
||||
/**
|
||||
* Display the view
|
||||
*/
|
||||
public function display($tpl=null)
|
||||
{
|
||||
// Access check.
|
||||
if (!JFactory::getUser()->authorise('core.create', 'com_attachments')) {
|
||||
return JError::raiseError(404, JText::_('JERROR_ALERTNOAUTHOR') . ' (ERR 64)' );
|
||||
}
|
||||
|
||||
// For convenience below
|
||||
$attachment = $this->attachment;
|
||||
$parent = $this->parent;
|
||||
|
||||
// Set up for editing the access level
|
||||
if ( $this->params->get('allow_frontend_access_editing', false) ) {
|
||||
require_once(JPATH_COMPONENT_ADMINISTRATOR.'/models/fields/accesslevels.php');
|
||||
$this->access_level = JFormFieldAccessLevels::getAccessLevels('access', 'access', null);
|
||||
$this->access_level_tooltip = JText::_('ATTACH_ACCESS_LEVEL_TOOLTIP');
|
||||
}
|
||||
|
||||
// Set up publishing info
|
||||
$user = JFactory::getUser();
|
||||
$this->may_publish = $parent->userMayChangeAttachmentState($attachment->parent_id,
|
||||
$attachment->parent_entity, $user->id);
|
||||
if ( $this->may_publish ) {
|
||||
$this->publish = JHtml::_('select.booleanlist', 'state', 'class="inputbox"', $attachment->state);
|
||||
}
|
||||
|
||||
// Construct derived data
|
||||
$attachment->parent_entity_name = JText::_('ATTACH_' . $attachment->parent_entity);
|
||||
$attachment->parent_title = $parent->getTitle($attachment->parent_id, $attachment->parent_entity);
|
||||
|
||||
$this->relative_url_checked = $attachment->url_relative ? 'checked="yes"' : '';
|
||||
$this->verify_url_checked = $attachment->url_verify ? 'checked="yes"' : '';
|
||||
|
||||
// Add the stylesheets for the form
|
||||
JHtml::stylesheet('com_attachments/attachments_frontend_form.css', array(), true);
|
||||
$lang = JFactory::getLanguage();
|
||||
if ( $lang->isRTL() ) {
|
||||
JHtml::stylesheet('com_attachments/attachments_frontend_form_rtl.css', array(), true);
|
||||
}
|
||||
|
||||
// Display the upload form
|
||||
parent::display($tpl);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
90
components/com_attachments/views/view.php
Normal file
90
components/com_attachments/views/view.php
Normal file
@ -0,0 +1,90 @@
|
||||
<?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
|
||||
*/
|
||||
|
||||
// No direct access
|
||||
defined('_JEXEC') or die();
|
||||
|
||||
/** Define the legacy classes, if necessary */
|
||||
require_once(JPATH_SITE.'/components/com_attachments/legacy/view.php');
|
||||
|
||||
/**
|
||||
* View for the uploads
|
||||
*
|
||||
* @package Attachments
|
||||
*/
|
||||
class AttachmentsFormView extends JViewLegacy
|
||||
{
|
||||
|
||||
/**
|
||||
* Return the starting HTML for the page
|
||||
*
|
||||
* Note: When displaying a View directly from user code (not a conroller),
|
||||
* it does not automatically create the HTML <html>, <body> and
|
||||
* <head> tags. This code fixes that.
|
||||
*
|
||||
* There is probably a better way to do this!
|
||||
*/
|
||||
protected function startHTML()
|
||||
{
|
||||
jimport('joomla.filesystem.file');
|
||||
|
||||
require_once JPATH_BASE.'/libraries/joomla/document/html/renderer/head.php';
|
||||
$document = JFactory::getDocument();
|
||||
$this->assignRef('document', $document);
|
||||
|
||||
$app = JFactory::getApplication();
|
||||
$this->template = $app->getTemplate(true)->template;
|
||||
$template_dir = $this->baseurl.'/templates/'.$this->template;
|
||||
|
||||
$file ='/templates/system/css/system.css';
|
||||
if (JFile::exists(JPATH_SITE.$file)) {
|
||||
$document->addStyleSheet($this->baseurl.$file);
|
||||
}
|
||||
|
||||
// Try to add the typical template stylesheets
|
||||
$files = Array('template.css', 'position.css', 'layout.css', 'general.css');
|
||||
foreach($files as $file) {
|
||||
$path = JPATH_SITE.'/templates/'.$this->template.'/css/'.$file;
|
||||
if (JFile::exists($path)) {
|
||||
$document->addStyleSheet($this->baseurl.'/templates/'.$this->template.'/css/'.$file);
|
||||
}
|
||||
}
|
||||
|
||||
// Add the CSS for the attachments list (whether we need it or not)
|
||||
JHtml::stylesheet('com_attachments/attachments_list.css', array(), true);
|
||||
|
||||
$head_renderer = new JDocumentRendererHead($document);
|
||||
|
||||
$html = '';
|
||||
$html .= "<html>\n";
|
||||
$html .= "<head>\n";
|
||||
$html .= $head_renderer->fetchHead($document);
|
||||
$html .= "</head>\n";
|
||||
$html .= "<body id=\"attachments_iframe\">\n";
|
||||
|
||||
return $html;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return the ending HTML tags for the page
|
||||
*/
|
||||
protected function endHTML()
|
||||
{
|
||||
$html = "\n";
|
||||
$html .= "</body>\n";
|
||||
$html .= "</html>\n";
|
||||
|
||||
return $html;
|
||||
}
|
||||
}
|
||||
1
components/com_attachments/views/warning/index.html
Normal file
1
components/com_attachments/views/warning/index.html
Normal file
@ -0,0 +1 @@
|
||||
<html><body bgcolor="#FFFFFF"></body></html>
|
||||
56
components/com_attachments/views/warning/tmpl/default.php
Normal file
56
components/com_attachments/views/warning/tmpl/default.php
Normal file
@ -0,0 +1,56 @@
|
||||
<?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
|
||||
*/
|
||||
|
||||
// Check to ensure this file is included in Joomla!
|
||||
defined('_JEXEC') or die();
|
||||
|
||||
$template = JFactory::getApplication()->getTemplate();
|
||||
|
||||
// Load the tooltip behavior.
|
||||
JHtml::_('behavior.tooltip');
|
||||
|
||||
$uri = JFactory::getURI();
|
||||
$document = JFactory::getDocument();
|
||||
|
||||
/** Load the Attachments helper */
|
||||
require_once(JPATH_SITE.'/components/com_attachments/helper.php');
|
||||
require_once(JPATH_SITE.'/components/com_attachments/javascript.php');
|
||||
|
||||
// Add the regular css file
|
||||
AttachmentsJavascript::setupJavascript(false);
|
||||
|
||||
// Hide the vertical scrollbar using javascript
|
||||
$hide_scrollbar = "window.addEvent('domready', function() {
|
||||
document.documentElement.style.overflow = \"hidden\";
|
||||
document.body.scroll = \"no\";});";
|
||||
$document->addScriptDeclaration($hide_scrollbar);
|
||||
|
||||
?>
|
||||
<div class="attachmentsWarning">
|
||||
<h1><?php echo $this->warning_title; ?></h1>
|
||||
<h2 id="warning_msg"><?php echo $this->warning_question ?></h2>
|
||||
<form action="<?php echo $this->action_url; ?>" name="warning_form" method="post">
|
||||
<div class="form_buttons">
|
||||
<span class="left"> </span>
|
||||
<input type="submit" name="submit" value="<?php echo $this->action_button_label ?>" />
|
||||
<span class="right">
|
||||
<input type="button" name="cancel" value="<?php echo JText::_('ATTACH_CANCEL'); ?>"
|
||||
onClick="window.parent.SqueezeBox.close();" />
|
||||
</span>
|
||||
</div>
|
||||
<input type="hidden" name="option" value="<?php echo $this->option;?>" />
|
||||
<input type="hidden" name="from" value="<?php echo $this->from;?>" />
|
||||
|
||||
<?php echo JHtml::_( 'form.token' ); ?>
|
||||
</form>
|
||||
</div>
|
||||
1
components/com_attachments/views/warning/tmpl/index.html
Normal file
1
components/com_attachments/views/warning/tmpl/index.html
Normal file
@ -0,0 +1 @@
|
||||
<html><body bgcolor="#FFFFFF"></body></html>
|
||||
42
components/com_attachments/views/warning/view.html.php
Normal file
42
components/com_attachments/views/warning/view.html.php
Normal file
@ -0,0 +1,42 @@
|
||||
<?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
|
||||
*/
|
||||
|
||||
// Check to ensure this file is included in Joomla!
|
||||
defined('_JEXEC') or die();
|
||||
|
||||
/** Define the legacy classes, if necessary */
|
||||
require_once(JPATH_SITE.'/components/com_attachments/legacy/view.php');
|
||||
|
||||
|
||||
/**
|
||||
* View for warnings
|
||||
*
|
||||
* @package Attachments
|
||||
*/
|
||||
class AttachmentsViewWarning extends JViewLegacy
|
||||
{
|
||||
/**
|
||||
* Display the view
|
||||
*/
|
||||
public function display($tpl = null)
|
||||
{
|
||||
// Add the stylesheets
|
||||
JHtml::stylesheet('com_attachments/attachments_frontend_form.css', array(), true);
|
||||
$lang = JFactory::getLanguage();
|
||||
if ( $lang->isRTL() ) {
|
||||
JHtml::stylesheet('com_attachments/attachments_frontend_form_rtl.css', array(), true);
|
||||
}
|
||||
|
||||
parent::display($tpl);
|
||||
}
|
||||
}
|
||||
45
components/com_banners/src/Controller/DisplayController.php
Normal file
45
components/com_banners/src/Controller/DisplayController.php
Normal file
@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Joomla.Site
|
||||
* @subpackage com_banners
|
||||
*
|
||||
* @copyright (C) 2006 Open Source Matters, Inc. <https://www.joomla.org>
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace Joomla\Component\Banners\Site\Controller;
|
||||
|
||||
use Joomla\CMS\MVC\Controller\BaseController;
|
||||
|
||||
// phpcs:disable PSR1.Files.SideEffects
|
||||
\defined('_JEXEC') or die;
|
||||
// phpcs:enable PSR1.Files.SideEffects
|
||||
|
||||
/**
|
||||
* Banners Controller
|
||||
*
|
||||
* @since 1.5
|
||||
*/
|
||||
class DisplayController extends BaseController
|
||||
{
|
||||
/**
|
||||
* Method when a banner is clicked on.
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 1.5
|
||||
*/
|
||||
public function click()
|
||||
{
|
||||
$id = $this->input->getInt('id', 0);
|
||||
|
||||
if ($id) {
|
||||
/** @var \Joomla\Component\Banners\Site\Model\BannerModel $model */
|
||||
$model = $this->getModel('Banner', 'Site', ['ignore_request' => true]);
|
||||
$model->setState('banner.id', $id);
|
||||
$model->click();
|
||||
$this->setRedirect($model->getUrl());
|
||||
}
|
||||
}
|
||||
}
|
||||
50
components/com_banners/src/Helper/BannerHelper.php
Normal file
50
components/com_banners/src/Helper/BannerHelper.php
Normal file
@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Joomla.Site
|
||||
* @subpackage com_banners
|
||||
*
|
||||
* @copyright (C) 2009 Open Source Matters, Inc. <https://www.joomla.org>
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace Joomla\Component\Banners\Site\Helper;
|
||||
|
||||
// phpcs:disable PSR1.Files.SideEffects
|
||||
\defined('_JEXEC') or die;
|
||||
// phpcs:enable PSR1.Files.SideEffects
|
||||
|
||||
/**
|
||||
* Banner Helper Class
|
||||
*
|
||||
* @since 1.6
|
||||
*
|
||||
* @deprecated 5.1 will be removed in 7.0
|
||||
*/
|
||||
abstract class BannerHelper
|
||||
{
|
||||
/**
|
||||
* Checks if a URL is an image
|
||||
*
|
||||
* @param string $url The URL path to the potential image
|
||||
*
|
||||
* @return boolean True if an image of type bmp, gif, jp(e)g, png or webp, false otherwise
|
||||
*
|
||||
* @since 1.6
|
||||
*
|
||||
* @deprecated 5.1 will be removed in 7.0
|
||||
* When testing the image file, use Joomla\CMS\Helper\MediaHelper::isImage($url) for pixel-based image files
|
||||
* in combination with Joomla\CMS\Helper\MediaHelper::getMimeType($url) === 'image/svg+xml' for vector based image files
|
||||
* Be aware that the image url should first be sanitized with the helper function Joomla\CMS\HTML\HTMLHelper::cleanImageURL($imageurl)
|
||||
*/
|
||||
public static function isImage($url)
|
||||
{
|
||||
$urlCheck = explode('?', $url);
|
||||
|
||||
if (preg_match('#\.(?:bmp|gif|jpe?g|png|webp)$#i', $urlCheck[0])) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
223
components/com_banners/src/Model/BannerModel.php
Normal file
223
components/com_banners/src/Model/BannerModel.php
Normal file
@ -0,0 +1,223 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Joomla.Site
|
||||
* @subpackage com_banners
|
||||
*
|
||||
* @copyright (C) 2006 Open Source Matters, Inc. <https://www.joomla.org>
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace Joomla\Component\Banners\Site\Model;
|
||||
|
||||
use Joomla\CMS\Cache\Exception\CacheExceptionInterface;
|
||||
use Joomla\CMS\Component\ComponentHelper;
|
||||
use Joomla\CMS\Factory;
|
||||
use Joomla\CMS\Language\Text;
|
||||
use Joomla\CMS\MVC\Model\BaseDatabaseModel;
|
||||
use Joomla\Database\ParameterType;
|
||||
|
||||
// phpcs:disable PSR1.Files.SideEffects
|
||||
\defined('_JEXEC') or die;
|
||||
// phpcs:enable PSR1.Files.SideEffects
|
||||
|
||||
/**
|
||||
* Banner model for the Joomla Banners component.
|
||||
*
|
||||
* @since 1.5
|
||||
*/
|
||||
class BannerModel extends BaseDatabaseModel
|
||||
{
|
||||
/**
|
||||
* Cached item object
|
||||
*
|
||||
* @var object
|
||||
* @since 1.6
|
||||
*/
|
||||
protected $_item;
|
||||
|
||||
/**
|
||||
* Clicks the URL, incrementing the counter
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 1.5
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function click()
|
||||
{
|
||||
$item = $this->getItem();
|
||||
|
||||
if (empty($item)) {
|
||||
throw new \Exception(Text::_('JERROR_PAGE_NOT_FOUND'), 404);
|
||||
}
|
||||
|
||||
$id = (int) $this->getState('banner.id');
|
||||
|
||||
// Update click count
|
||||
$db = $this->getDatabase();
|
||||
$query = $db->getQuery(true);
|
||||
|
||||
$query->update($db->quoteName('#__banners'))
|
||||
->set($db->quoteName('clicks') . ' = ' . $db->quoteName('clicks') . ' + 1')
|
||||
->where($db->quoteName('id') . ' = :id')
|
||||
->bind(':id', $id, ParameterType::INTEGER);
|
||||
|
||||
$db->setQuery($query);
|
||||
|
||||
try {
|
||||
$db->execute();
|
||||
} catch (\RuntimeException $e) {
|
||||
throw new \Exception($e->getMessage(), 500);
|
||||
}
|
||||
|
||||
// Track clicks
|
||||
$trackClicks = $item->track_clicks;
|
||||
|
||||
if ($trackClicks < 0 && $item->cid) {
|
||||
$trackClicks = $item->client_track_clicks;
|
||||
}
|
||||
|
||||
if ($trackClicks < 0) {
|
||||
$config = ComponentHelper::getParams('com_banners');
|
||||
$trackClicks = $config->get('track_clicks');
|
||||
}
|
||||
|
||||
if ($trackClicks > 0) {
|
||||
$trackDate = Factory::getDate()->format('Y-m-d H:00:00');
|
||||
$trackDate = Factory::getDate($trackDate)->toSql();
|
||||
|
||||
$query = $db->getQuery(true);
|
||||
|
||||
$query->select($db->quoteName('count'))
|
||||
->from($db->quoteName('#__banner_tracks'))
|
||||
->where(
|
||||
[
|
||||
$db->quoteName('track_type') . ' = 2',
|
||||
$db->quoteName('banner_id') . ' = :id',
|
||||
$db->quoteName('track_date') . ' = :trackDate',
|
||||
]
|
||||
)
|
||||
->bind(':id', $id, ParameterType::INTEGER)
|
||||
->bind(':trackDate', $trackDate);
|
||||
|
||||
$db->setQuery($query);
|
||||
|
||||
try {
|
||||
$db->execute();
|
||||
} catch (\RuntimeException $e) {
|
||||
throw new \Exception($e->getMessage(), 500);
|
||||
}
|
||||
|
||||
$count = $db->loadResult();
|
||||
|
||||
$query = $db->getQuery(true);
|
||||
|
||||
if ($count) {
|
||||
// Update count
|
||||
$query->update($db->quoteName('#__banner_tracks'))
|
||||
->set($db->quoteName('count') . ' = ' . $db->quoteName('count') . ' + 1')
|
||||
->where(
|
||||
[
|
||||
$db->quoteName('track_type') . ' = 2',
|
||||
$db->quoteName('banner_id') . ' = :id',
|
||||
$db->quoteName('track_date') . ' = :trackDate',
|
||||
]
|
||||
)
|
||||
->bind(':id', $id, ParameterType::INTEGER)
|
||||
->bind(':trackDate', $trackDate);
|
||||
} else {
|
||||
// Insert new count
|
||||
$query->insert($db->quoteName('#__banner_tracks'))
|
||||
->columns(
|
||||
[
|
||||
$db->quoteName('count'),
|
||||
$db->quoteName('track_type'),
|
||||
$db->quoteName('banner_id'),
|
||||
$db->quoteName('track_date'),
|
||||
]
|
||||
)
|
||||
->values('1, 2 , :id, :trackDate')
|
||||
->bind(':id', $id, ParameterType::INTEGER)
|
||||
->bind(':trackDate', $trackDate);
|
||||
}
|
||||
|
||||
$db->setQuery($query);
|
||||
|
||||
try {
|
||||
$db->execute();
|
||||
} catch (\RuntimeException $e) {
|
||||
throw new \Exception($e->getMessage(), 500);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the data for a banner.
|
||||
*
|
||||
* @return object
|
||||
*
|
||||
* @since 1.6
|
||||
*/
|
||||
public function &getItem()
|
||||
{
|
||||
if (!isset($this->_item)) {
|
||||
/** @var \Joomla\CMS\Cache\Controller\CallbackController $cache */
|
||||
$cache = Factory::getCache('com_banners', 'callback');
|
||||
|
||||
$id = (int) $this->getState('banner.id');
|
||||
|
||||
// For PHP 5.3 compat we can't use $this in the lambda function below, so grab the database driver now to use it
|
||||
$db = $this->getDatabase();
|
||||
|
||||
$loader = function ($id) use ($db) {
|
||||
$query = $db->getQuery(true);
|
||||
|
||||
$query->select(
|
||||
[
|
||||
$db->quoteName('a.clickurl'),
|
||||
$db->quoteName('a.cid'),
|
||||
$db->quoteName('a.track_clicks'),
|
||||
$db->quoteName('cl.track_clicks', 'client_track_clicks'),
|
||||
]
|
||||
)
|
||||
->from($db->quoteName('#__banners', 'a'))
|
||||
->join('LEFT', $db->quoteName('#__banner_clients', 'cl'), $db->quoteName('cl.id') . ' = ' . $db->quoteName('a.cid'))
|
||||
->where($db->quoteName('a.id') . ' = :id')
|
||||
->bind(':id', $id, ParameterType::INTEGER);
|
||||
|
||||
$db->setQuery($query);
|
||||
|
||||
return $db->loadObject();
|
||||
};
|
||||
|
||||
try {
|
||||
$this->_item = $cache->get($loader, [$id], md5(__METHOD__ . $id));
|
||||
} catch (CacheExceptionInterface $e) {
|
||||
$this->_item = $loader($id);
|
||||
}
|
||||
}
|
||||
|
||||
return $this->_item;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the URL for a banner
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
* @since 1.5
|
||||
*/
|
||||
public function getUrl()
|
||||
{
|
||||
$item = $this->getItem();
|
||||
$url = $item->clickurl;
|
||||
|
||||
// Check for links
|
||||
if (!preg_match('#http[s]?://|index[2]?\.php#', $url)) {
|
||||
$url = "http://$url";
|
||||
}
|
||||
|
||||
return $url;
|
||||
}
|
||||
}
|
||||
384
components/com_banners/src/Model/BannersModel.php
Normal file
384
components/com_banners/src/Model/BannersModel.php
Normal file
@ -0,0 +1,384 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Joomla.Site
|
||||
* @subpackage com_banners
|
||||
*
|
||||
* @copyright (C) 2009 Open Source Matters, Inc. <https://www.joomla.org>
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace Joomla\Component\Banners\Site\Model;
|
||||
|
||||
use Joomla\CMS\Component\ComponentHelper;
|
||||
use Joomla\CMS\Factory;
|
||||
use Joomla\CMS\MVC\Model\ListModel;
|
||||
use Joomla\Database\Exception\ExecutionFailureException;
|
||||
use Joomla\Database\ParameterType;
|
||||
use Joomla\Database\QueryInterface;
|
||||
use Joomla\Registry\Registry;
|
||||
use Joomla\Utilities\ArrayHelper;
|
||||
|
||||
// phpcs:disable PSR1.Files.SideEffects
|
||||
\defined('_JEXEC') or die;
|
||||
// phpcs:enable PSR1.Files.SideEffects
|
||||
|
||||
/**
|
||||
* Banners model for the Joomla Banners component.
|
||||
*
|
||||
* @since 1.6
|
||||
*/
|
||||
class BannersModel extends ListModel
|
||||
{
|
||||
/**
|
||||
* Method to get a store id based on model configuration state.
|
||||
*
|
||||
* This is necessary because the model is used by the component and
|
||||
* different modules that might need different sets of data or different
|
||||
* ordering requirements.
|
||||
*
|
||||
* @param string $id A prefix for the store id.
|
||||
*
|
||||
* @return string A store id.
|
||||
*
|
||||
* @since 1.6
|
||||
*/
|
||||
protected function getStoreId($id = '')
|
||||
{
|
||||
// Compile the store id.
|
||||
$id .= ':' . $this->getState('filter.search');
|
||||
$id .= ':' . $this->getState('filter.tag_search');
|
||||
$id .= ':' . $this->getState('filter.client_id');
|
||||
$id .= ':' . serialize($this->getState('filter.category_id'));
|
||||
$id .= ':' . serialize($this->getState('filter.keywords'));
|
||||
|
||||
return parent::getStoreId($id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to get a QueryInterface object for retrieving the data set from a database.
|
||||
*
|
||||
* @return QueryInterface An object implementing QueryInterface to retrieve the data set.
|
||||
*
|
||||
* @since 1.6
|
||||
*/
|
||||
protected function getListQuery()
|
||||
{
|
||||
$db = $this->getDatabase();
|
||||
$query = $db->getQuery(true);
|
||||
$ordering = $this->getState('filter.ordering');
|
||||
$tagSearch = $this->getState('filter.tag_search');
|
||||
$cid = (int) $this->getState('filter.client_id');
|
||||
$categoryId = $this->getState('filter.category_id');
|
||||
$keywords = $this->getState('filter.keywords');
|
||||
$randomise = ($ordering === 'random');
|
||||
$nowDate = Factory::getDate()->toSql();
|
||||
|
||||
$query->select(
|
||||
[
|
||||
$db->quoteName('a.id'),
|
||||
$db->quoteName('a.type'),
|
||||
$db->quoteName('a.name'),
|
||||
$db->quoteName('a.clickurl'),
|
||||
$db->quoteName('a.sticky'),
|
||||
$db->quoteName('a.cid'),
|
||||
$db->quoteName('a.description'),
|
||||
$db->quoteName('a.params'),
|
||||
$db->quoteName('a.custombannercode'),
|
||||
$db->quoteName('a.track_impressions'),
|
||||
$db->quoteName('cl.track_impressions', 'client_track_impressions'),
|
||||
]
|
||||
)
|
||||
->from($db->quoteName('#__banners', 'a'))
|
||||
->join('LEFT', $db->quoteName('#__banner_clients', 'cl'), $db->quoteName('cl.id') . ' = ' . $db->quoteName('a.cid'))
|
||||
->where($db->quoteName('a.state') . ' = 1')
|
||||
->extendWhere(
|
||||
'AND',
|
||||
[
|
||||
$db->quoteName('a.publish_up') . ' IS NULL',
|
||||
$db->quoteName('a.publish_up') . ' <= :nowDate1',
|
||||
],
|
||||
'OR'
|
||||
)
|
||||
->extendWhere(
|
||||
'AND',
|
||||
[
|
||||
$db->quoteName('a.publish_down') . ' IS NULL',
|
||||
$db->quoteName('a.publish_down') . ' >= :nowDate2',
|
||||
],
|
||||
'OR'
|
||||
)
|
||||
->extendWhere(
|
||||
'AND',
|
||||
[
|
||||
$db->quoteName('a.imptotal') . ' = 0',
|
||||
$db->quoteName('a.impmade') . ' < ' . $db->quoteName('a.imptotal'),
|
||||
],
|
||||
'OR'
|
||||
)
|
||||
->bind([':nowDate1', ':nowDate2'], $nowDate);
|
||||
|
||||
if ($cid) {
|
||||
$query->where(
|
||||
[
|
||||
$db->quoteName('a.cid') . ' = :clientId',
|
||||
$db->quoteName('cl.state') . ' = 1',
|
||||
]
|
||||
)
|
||||
->bind(':clientId', $cid, ParameterType::INTEGER);
|
||||
}
|
||||
|
||||
// Filter by a single or group of categories
|
||||
if (is_numeric($categoryId)) {
|
||||
$categoryId = (int) $categoryId;
|
||||
$type = $this->getState('filter.category_id.include', true) ? ' = ' : ' <> ';
|
||||
|
||||
// Add subcategory check
|
||||
if ($this->getState('filter.subcategories', false)) {
|
||||
$levels = (int) $this->getState('filter.max_category_levels', '1');
|
||||
|
||||
// Create a subquery for the subcategory list
|
||||
$subQuery = $db->getQuery(true);
|
||||
$subQuery->select($db->quoteName('sub.id'))
|
||||
->from($db->quoteName('#__categories', 'sub'))
|
||||
->join(
|
||||
'INNER',
|
||||
$db->quoteName('#__categories', 'this'),
|
||||
$db->quoteName('sub.lft') . ' > ' . $db->quoteName('this.lft')
|
||||
. ' AND ' . $db->quoteName('sub.rgt') . ' < ' . $db->quoteName('this.rgt')
|
||||
)
|
||||
->where(
|
||||
[
|
||||
$db->quoteName('this.id') . ' = :categoryId1',
|
||||
$db->quoteName('sub.level') . ' <= ' . $db->quoteName('this.level') . ' + :levels',
|
||||
]
|
||||
);
|
||||
|
||||
// Add the subquery to the main query
|
||||
$query->extendWhere(
|
||||
'AND',
|
||||
[
|
||||
$db->quoteName('a.catid') . $type . ':categoryId2',
|
||||
$db->quoteName('a.catid') . ' IN (' . $subQuery . ')',
|
||||
],
|
||||
'OR'
|
||||
)
|
||||
->bind([':categoryId1', ':categoryId2'], $categoryId, ParameterType::INTEGER)
|
||||
->bind(':levels', $levels, ParameterType::INTEGER);
|
||||
} else {
|
||||
$query->where($db->quoteName('a.catid') . $type . ':categoryId')
|
||||
->bind(':categoryId', $categoryId, ParameterType::INTEGER);
|
||||
}
|
||||
} elseif (\is_array($categoryId) && (\count($categoryId) > 0)) {
|
||||
$categoryId = ArrayHelper::toInteger($categoryId);
|
||||
|
||||
if ($this->getState('filter.category_id.include', true)) {
|
||||
$query->whereIn($db->quoteName('a.catid'), $categoryId);
|
||||
} else {
|
||||
$query->whereNotIn($db->quoteName('a.catid'), $categoryId);
|
||||
}
|
||||
}
|
||||
|
||||
if ($tagSearch) {
|
||||
if (!$keywords) {
|
||||
// No keywords, select nothing.
|
||||
$query->where('0 != 0');
|
||||
} else {
|
||||
$temp = [];
|
||||
$config = ComponentHelper::getParams('com_banners');
|
||||
$prefix = $config->get('metakey_prefix');
|
||||
|
||||
if ($categoryId) {
|
||||
$query->join('LEFT', $db->quoteName('#__categories', 'cat'), $db->quoteName('a.catid') . ' = ' . $db->quoteName('cat.id'));
|
||||
}
|
||||
|
||||
foreach ($keywords as $key => $keyword) {
|
||||
$regexp = '[[:<:]]' . $keyword . '[[:>:]]';
|
||||
$valuesToBind = [$keyword, $keyword, $regexp];
|
||||
|
||||
if ($cid) {
|
||||
$valuesToBind[] = $regexp;
|
||||
}
|
||||
|
||||
if ($categoryId) {
|
||||
$valuesToBind[] = $regexp;
|
||||
}
|
||||
|
||||
// Because values to $query->bind() are passed by reference, using $query->bindArray() here instead to prevent overwriting.
|
||||
$bounded = $query->bindArray($valuesToBind, ParameterType::STRING);
|
||||
|
||||
$condition1 = $db->quoteName('a.own_prefix') . ' = 1'
|
||||
. ' AND ' . $db->quoteName('a.metakey_prefix')
|
||||
. ' = SUBSTRING(' . $bounded[0] . ',1,LENGTH(' . $db->quoteName('a.metakey_prefix') . '))'
|
||||
. ' OR ' . $db->quoteName('a.own_prefix') . ' = 0'
|
||||
. ' AND ' . $db->quoteName('cl.own_prefix') . ' = 1'
|
||||
. ' AND ' . $db->quoteName('cl.metakey_prefix')
|
||||
. ' = SUBSTRING(' . $bounded[1] . ',1,LENGTH(' . $db->quoteName('cl.metakey_prefix') . '))'
|
||||
. ' OR ' . $db->quoteName('a.own_prefix') . ' = 0'
|
||||
. ' AND ' . $db->quoteName('cl.own_prefix') . ' = 0'
|
||||
. ' AND ' . ($prefix == substr($keyword, 0, \strlen($prefix)) ? '0 = 0' : '0 != 0');
|
||||
|
||||
$condition2 = $db->quoteName('a.metakey') . ' ' . $query->regexp($bounded[2]);
|
||||
|
||||
if ($cid) {
|
||||
$condition2 .= ' OR ' . $db->quoteName('cl.metakey') . ' ' . $query->regexp($bounded[3]) . ' ';
|
||||
}
|
||||
|
||||
if ($categoryId) {
|
||||
$condition2 .= ' OR ' . $db->quoteName('cat.metakey') . ' ' . $query->regexp($bounded[4]) . ' ';
|
||||
}
|
||||
|
||||
$temp[] = "($condition1) AND ($condition2)";
|
||||
}
|
||||
|
||||
$query->where('(' . implode(' OR ', $temp) . ')');
|
||||
}
|
||||
}
|
||||
|
||||
// Filter by language
|
||||
if ($this->getState('filter.language')) {
|
||||
$query->whereIn($db->quoteName('a.language'), [Factory::getLanguage()->getTag(), '*'], ParameterType::STRING);
|
||||
}
|
||||
|
||||
$query->order($db->quoteName('a.sticky') . ' DESC, ' . ($randomise ? $query->rand() : $db->quoteName('a.ordering')));
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of banners.
|
||||
*
|
||||
* @return array
|
||||
*
|
||||
* @since 1.6
|
||||
*/
|
||||
public function getItems()
|
||||
{
|
||||
if ($this->getState('filter.tag_search')) {
|
||||
// Filter out empty keywords.
|
||||
$keywords = array_values(array_filter(array_map('trim', $this->getState('filter.keywords')), 'strlen'));
|
||||
|
||||
// Re-set state before running the query.
|
||||
$this->setState('filter.keywords', $keywords);
|
||||
|
||||
// If no keywords are provided, avoid running the query.
|
||||
if (!$keywords) {
|
||||
$this->cache['items'] = [];
|
||||
|
||||
return $this->cache['items'];
|
||||
}
|
||||
}
|
||||
|
||||
if (!isset($this->cache['items'])) {
|
||||
$this->cache['items'] = parent::getItems();
|
||||
|
||||
foreach ($this->cache['items'] as &$item) {
|
||||
$item->params = new Registry($item->params);
|
||||
}
|
||||
}
|
||||
|
||||
return $this->cache['items'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Makes impressions on a list of banners
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 1.6
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function impress()
|
||||
{
|
||||
$trackDate = Factory::getDate()->format('Y-m-d H:00:00');
|
||||
$trackDate = Factory::getDate($trackDate)->toSql();
|
||||
$items = $this->getItems();
|
||||
$db = $this->getDatabase();
|
||||
$bid = [];
|
||||
|
||||
if (!\count($items)) {
|
||||
return;
|
||||
}
|
||||
|
||||
foreach ($items as $item) {
|
||||
$bid[] = (int) $item->id;
|
||||
}
|
||||
|
||||
// Increment impression made
|
||||
$query = $db->getQuery(true);
|
||||
$query->update($db->quoteName('#__banners'))
|
||||
->set($db->quoteName('impmade') . ' = ' . $db->quoteName('impmade') . ' + 1')
|
||||
->whereIn($db->quoteName('id'), $bid);
|
||||
$db->setQuery($query);
|
||||
|
||||
try {
|
||||
$db->execute();
|
||||
} catch (ExecutionFailureException $e) {
|
||||
throw new \Exception($e->getMessage(), 500);
|
||||
}
|
||||
|
||||
foreach ($items as $item) {
|
||||
// Track impressions
|
||||
$trackImpressions = $item->track_impressions;
|
||||
|
||||
if ($trackImpressions < 0 && $item->cid) {
|
||||
$trackImpressions = $item->client_track_impressions;
|
||||
}
|
||||
|
||||
if ($trackImpressions < 0) {
|
||||
$config = ComponentHelper::getParams('com_banners');
|
||||
$trackImpressions = $config->get('track_impressions');
|
||||
}
|
||||
|
||||
if ($trackImpressions > 0) {
|
||||
// Is track already created?
|
||||
// Update count
|
||||
$query = $db->getQuery(true);
|
||||
$query->update($db->quoteName('#__banner_tracks'))
|
||||
->set($db->quoteName('count') . ' = ' . $db->quoteName('count') . ' + 1')
|
||||
->where(
|
||||
[
|
||||
$db->quoteName('track_type') . ' = 1',
|
||||
$db->quoteName('banner_id') . ' = :id',
|
||||
$db->quoteName('track_date') . ' = :trackDate',
|
||||
]
|
||||
)
|
||||
->bind(':id', $item->id, ParameterType::INTEGER)
|
||||
->bind(':trackDate', $trackDate);
|
||||
|
||||
$db->setQuery($query);
|
||||
|
||||
try {
|
||||
$db->execute();
|
||||
} catch (ExecutionFailureException $e) {
|
||||
throw new \Exception($e->getMessage(), 500);
|
||||
}
|
||||
|
||||
if ($db->getAffectedRows() === 0) {
|
||||
// Insert new count
|
||||
$query = $db->getQuery(true);
|
||||
$query->insert($db->quoteName('#__banner_tracks'))
|
||||
->columns(
|
||||
[
|
||||
$db->quoteName('count'),
|
||||
$db->quoteName('track_type'),
|
||||
$db->quoteName('banner_id'),
|
||||
$db->quoteName('track_date'),
|
||||
]
|
||||
)
|
||||
->values('1, 1, :id, :trackDate')
|
||||
->bind(':id', $item->id, ParameterType::INTEGER)
|
||||
->bind(':trackDate', $trackDate);
|
||||
|
||||
$db->setQuery($query);
|
||||
|
||||
try {
|
||||
$db->execute();
|
||||
} catch (ExecutionFailureException $e) {
|
||||
throw new \Exception($e->getMessage(), 500);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
40
components/com_banners/src/Service/Category.php
Normal file
40
components/com_banners/src/Service/Category.php
Normal file
@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Joomla.Site
|
||||
* @subpackage com_banners
|
||||
*
|
||||
* @copyright (C) 2009 Open Source Matters, Inc. <https://www.joomla.org>
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace Joomla\Component\Banners\Site\Service;
|
||||
|
||||
use Joomla\CMS\Categories\Categories;
|
||||
|
||||
// phpcs:disable PSR1.Files.SideEffects
|
||||
\defined('_JEXEC') or die;
|
||||
// phpcs:enable PSR1.Files.SideEffects
|
||||
|
||||
/**
|
||||
* Banners Component Category Tree
|
||||
*
|
||||
* @since 1.6
|
||||
*/
|
||||
class Category extends Categories
|
||||
{
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param array $options Array of options
|
||||
*
|
||||
* @since 1.6
|
||||
*/
|
||||
public function __construct($options = [])
|
||||
{
|
||||
$options['table'] = '#__banners';
|
||||
$options['extension'] = 'com_banners';
|
||||
|
||||
parent::__construct($options);
|
||||
}
|
||||
}
|
||||
98
components/com_banners/src/Service/Router.php
Normal file
98
components/com_banners/src/Service/Router.php
Normal file
@ -0,0 +1,98 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Joomla.Site
|
||||
* @subpackage com_banners
|
||||
*
|
||||
* @copyright (C) 2006 Open Source Matters, Inc. <https://www.joomla.org>
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace Joomla\Component\Banners\Site\Service;
|
||||
|
||||
use Joomla\CMS\Component\Router\RouterBase;
|
||||
|
||||
// phpcs:disable PSR1.Files.SideEffects
|
||||
\defined('_JEXEC') or die;
|
||||
// phpcs:enable PSR1.Files.SideEffects
|
||||
|
||||
/**
|
||||
* Routing class from com_banners
|
||||
*
|
||||
* @since 3.3
|
||||
*/
|
||||
class Router extends RouterBase
|
||||
{
|
||||
/**
|
||||
* Build the route for the com_banners component
|
||||
*
|
||||
* @param array $query An array of URL arguments
|
||||
*
|
||||
* @return array The URL arguments to use to assemble the subsequent URL.
|
||||
*
|
||||
* @since 3.3
|
||||
*/
|
||||
public function build(&$query)
|
||||
{
|
||||
$segments = [];
|
||||
|
||||
if (isset($query['task'])) {
|
||||
$segments[] = $query['task'];
|
||||
unset($query['task']);
|
||||
}
|
||||
|
||||
if (isset($query['id'])) {
|
||||
$segments[] = $query['id'];
|
||||
unset($query['id']);
|
||||
}
|
||||
|
||||
foreach ($segments as &$segment) {
|
||||
$segment = str_replace(':', '-', $segment);
|
||||
}
|
||||
|
||||
return $segments;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse the segments of a URL.
|
||||
*
|
||||
* @param array $segments The segments of the URL to parse.
|
||||
*
|
||||
* @return array The URL attributes to be used by the application.
|
||||
*
|
||||
* @since 3.3
|
||||
*/
|
||||
public function parse(&$segments)
|
||||
{
|
||||
$vars = [];
|
||||
|
||||
foreach ($segments as &$segment) {
|
||||
$segment = preg_replace('/-/', ':', $segment, 1);
|
||||
}
|
||||
unset($segment);
|
||||
|
||||
// View is always the first element of the array
|
||||
$count = \count($segments);
|
||||
|
||||
if ($count) {
|
||||
$count--;
|
||||
$segment = array_shift($segments);
|
||||
|
||||
if (is_numeric($segment)) {
|
||||
$vars['id'] = $segment;
|
||||
} else {
|
||||
$vars['task'] = $segment;
|
||||
}
|
||||
}
|
||||
|
||||
if ($count) {
|
||||
$segment = array_shift($segments);
|
||||
|
||||
if (is_numeric($segment)) {
|
||||
$vars['id'] = $segment;
|
||||
}
|
||||
}
|
||||
|
||||
return $vars;
|
||||
}
|
||||
}
|
||||
121
components/com_config/forms/config.xml
Normal file
121
components/com_config/forms/config.xml
Normal file
@ -0,0 +1,121 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<form>
|
||||
<fieldset
|
||||
name="metadata"
|
||||
label="COM_CONFIG_METADATA_SETTINGS">
|
||||
<field
|
||||
name="MetaDesc"
|
||||
type="textarea"
|
||||
label="COM_CONFIG_FIELD_METADESC_LABEL"
|
||||
filter="string"
|
||||
rows="3"
|
||||
cols="30"
|
||||
maxlength="300"
|
||||
charcounter="true"
|
||||
/>
|
||||
|
||||
<field
|
||||
name="MetaRights"
|
||||
type="textarea"
|
||||
label="JFIELD_META_RIGHTS_LABEL"
|
||||
description="JFIELD_META_RIGHTS_DESC"
|
||||
filter="string"
|
||||
cols="60"
|
||||
rows="2"
|
||||
/>
|
||||
|
||||
</fieldset>
|
||||
|
||||
<fieldset
|
||||
name="seo"
|
||||
label="CONFIG_SEO_SETTINGS_LABEL">
|
||||
<field
|
||||
name="sef"
|
||||
type="radio"
|
||||
label="COM_CONFIG_FIELD_SEF_URL_LABEL"
|
||||
description="COM_CONFIG_FIELD_SEF_URL_DESC"
|
||||
default="1"
|
||||
layout="joomla.form.field.radio.switcher"
|
||||
filter="integer"
|
||||
>
|
||||
<option value="0">JNO</option>
|
||||
<option value="1">JYES</option>
|
||||
</field>
|
||||
|
||||
<field
|
||||
name="sitename_pagetitles"
|
||||
type="list"
|
||||
label="COM_CONFIG_FIELD_SITENAME_PAGETITLES_LABEL"
|
||||
default="0"
|
||||
filter="integer"
|
||||
validate="options"
|
||||
>
|
||||
<option value="2">COM_CONFIG_FIELD_VALUE_AFTER</option>
|
||||
<option value="1">COM_CONFIG_FIELD_VALUE_BEFORE</option>
|
||||
<option value="0">JNO</option>
|
||||
</field>
|
||||
|
||||
</fieldset>
|
||||
|
||||
<fieldset
|
||||
name="site"
|
||||
label="CONFIG_SITE_SETTINGS_LABEL">
|
||||
|
||||
<field
|
||||
name="sitename"
|
||||
type="text"
|
||||
label="COM_CONFIG_FIELD_SITE_NAME_LABEL"
|
||||
required="true"
|
||||
filter="string"
|
||||
size="50"
|
||||
/>
|
||||
|
||||
<field
|
||||
name="offline"
|
||||
type="radio"
|
||||
label="COM_CONFIG_FIELD_SITE_OFFLINE_LABEL"
|
||||
default="0"
|
||||
layout="joomla.form.field.radio.switcher"
|
||||
filter="integer"
|
||||
>
|
||||
<option value="0">JNO</option>
|
||||
<option value="1">JYES</option>
|
||||
</field>
|
||||
|
||||
<field
|
||||
name="access"
|
||||
type="accesslevel"
|
||||
label="COM_CONFIG_FIELD_DEFAULT_ACCESS_LEVEL_LABEL"
|
||||
description="COM_CONFIG_FIELD_DEFAULT_ACCESS_LEVEL_DESC"
|
||||
default="1"
|
||||
filter="UINT"
|
||||
validate="options"
|
||||
/>
|
||||
|
||||
<field
|
||||
name="list_limit"
|
||||
type="list"
|
||||
label="COM_CONFIG_FIELD_DEFAULT_LIST_LIMIT_LABEL"
|
||||
default="20"
|
||||
filter="integer"
|
||||
validate="options"
|
||||
>
|
||||
<option value="5">J5</option>
|
||||
<option value="10">J10</option>
|
||||
<option value="15">J15</option>
|
||||
<option value="20">J20</option>
|
||||
<option value="25">J25</option>
|
||||
<option value="30">J30</option>
|
||||
<option value="50">J50</option>
|
||||
<option value="100">J100</option>
|
||||
</field>
|
||||
|
||||
</fieldset>
|
||||
|
||||
<fieldset>
|
||||
<field
|
||||
name="asset_id"
|
||||
type="hidden"
|
||||
/>
|
||||
</fieldset>
|
||||
</form>
|
||||
136
components/com_config/forms/modules.xml
Normal file
136
components/com_config/forms/modules.xml
Normal file
@ -0,0 +1,136 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<form>
|
||||
<fieldset>
|
||||
<field
|
||||
name="id"
|
||||
type="number"
|
||||
label="JGLOBAL_FIELD_ID_LABEL"
|
||||
default="0"
|
||||
readonly="true"
|
||||
/>
|
||||
|
||||
<field
|
||||
name="title"
|
||||
type="text"
|
||||
label="JGLOBAL_TITLE"
|
||||
maxlength="100"
|
||||
required="true"
|
||||
size="35"
|
||||
/>
|
||||
|
||||
<field
|
||||
name="note"
|
||||
type="text"
|
||||
label="COM_MODULES_FIELD_NOTE_LABEL"
|
||||
maxlength="255"
|
||||
size="35"
|
||||
/>
|
||||
|
||||
<field
|
||||
name="module"
|
||||
type="hidden"
|
||||
label="COM_MODULES_FIELD_MODULE_LABEL"
|
||||
readonly="readonly"
|
||||
size="20"
|
||||
/>
|
||||
|
||||
<field
|
||||
name="showtitle"
|
||||
type="radio"
|
||||
label="COM_MODULES_FIELD_SHOWTITLE_LABEL"
|
||||
layout="joomla.form.field.radio.switcher"
|
||||
default="1"
|
||||
size="1"
|
||||
>
|
||||
<option value="0">JHIDE</option>
|
||||
<option value="1">JSHOW</option>
|
||||
</field>
|
||||
|
||||
<field
|
||||
name="published"
|
||||
type="list"
|
||||
label="JSTATUS"
|
||||
class="form-select-color-state"
|
||||
default="1"
|
||||
size="1"
|
||||
validate="options"
|
||||
>
|
||||
<option value="1">JPUBLISHED</option>
|
||||
<option value="0">JUNPUBLISHED</option>
|
||||
<option value="-2">JTRASHED</option>
|
||||
</field>
|
||||
|
||||
<field
|
||||
name="publish_up"
|
||||
type="calendar"
|
||||
label="COM_MODULES_FIELD_PUBLISH_UP_LABEL"
|
||||
filter="user_utc"
|
||||
translateformat="true"
|
||||
showtime="true"
|
||||
size="22"
|
||||
/>
|
||||
|
||||
<field
|
||||
name="publish_down"
|
||||
type="calendar"
|
||||
label="COM_MODULES_FIELD_PUBLISH_DOWN_LABEL"
|
||||
filter="user_utc"
|
||||
translateformat="true"
|
||||
showtime="true"
|
||||
size="22"
|
||||
/>
|
||||
|
||||
<field
|
||||
name="client_id"
|
||||
type="hidden"
|
||||
label="COM_MODULES_FIELD_CLIENT_ID_LABEL"
|
||||
readonly="true"
|
||||
size="1"
|
||||
/>
|
||||
|
||||
<field
|
||||
name="position"
|
||||
type="ModulesPositionedit"
|
||||
label="COM_MODULES_FIELD_POSITION_LABEL"
|
||||
addfieldprefix="Joomla\Component\Modules\Administrator\Field"
|
||||
default=""
|
||||
maxlength="50"
|
||||
client="site"
|
||||
/>
|
||||
|
||||
<field
|
||||
name="access"
|
||||
type="accesslevel"
|
||||
label="JFIELD_ACCESS_LABEL"
|
||||
filter="UINT"
|
||||
validate="options"
|
||||
/>
|
||||
|
||||
<field
|
||||
name="ordering"
|
||||
type="moduleorder"
|
||||
label="JFIELD_ORDERING_LABEL"
|
||||
/>
|
||||
|
||||
<field
|
||||
name="content"
|
||||
type="editor"
|
||||
label="COM_MODULES_FIELD_CONTENT_LABEL"
|
||||
buttons="true"
|
||||
filter="\Joomla\CMS\Component\ComponentHelper::filterText"
|
||||
hide="readmore,pagebreak"
|
||||
/>
|
||||
|
||||
<field
|
||||
name="language"
|
||||
type="contentlanguage"
|
||||
label="JFIELD_LANGUAGE_LABEL"
|
||||
>
|
||||
<option value="*">JALL</option>
|
||||
</field>
|
||||
|
||||
<field name="assignment" type="hidden" />
|
||||
|
||||
<field name="assigned" type="hidden" />
|
||||
</fieldset>
|
||||
</form>
|
||||
47
components/com_config/forms/modules_advanced.xml
Normal file
47
components/com_config/forms/modules_advanced.xml
Normal file
@ -0,0 +1,47 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<form>
|
||||
<fields name="params">
|
||||
<fieldset
|
||||
name="advanced">
|
||||
|
||||
<field
|
||||
name="module_tag"
|
||||
type="moduletag"
|
||||
label="COM_MODULES_FIELD_MODULE_TAG_LABEL"
|
||||
default="div"
|
||||
validate="options"
|
||||
/>
|
||||
|
||||
<field
|
||||
name="bootstrap_size"
|
||||
type="integer"
|
||||
label="COM_MODULES_FIELD_BOOTSTRAP_SIZE_LABEL"
|
||||
first="0"
|
||||
last="12"
|
||||
step="1"
|
||||
/>
|
||||
|
||||
<field
|
||||
name="header_tag"
|
||||
type="headertag"
|
||||
label="COM_MODULES_FIELD_HEADER_TAG_LABEL"
|
||||
default="h3"
|
||||
validate="options"
|
||||
/>
|
||||
|
||||
<field
|
||||
name="header_class"
|
||||
type="textarea"
|
||||
label="COM_MODULES_FIELD_HEADER_CLASS_LABEL"
|
||||
rows="3"
|
||||
validate="CssIdentifier"
|
||||
/>
|
||||
|
||||
<field
|
||||
name="style"
|
||||
type="chromestyle"
|
||||
label="COM_MODULES_FIELD_MODULE_STYLE_LABEL"
|
||||
/>
|
||||
</fieldset>
|
||||
</fields>
|
||||
</form>
|
||||
42
components/com_config/forms/templates.xml
Normal file
42
components/com_config/forms/templates.xml
Normal file
@ -0,0 +1,42 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<form>
|
||||
<fieldset>
|
||||
<field
|
||||
name="id"
|
||||
type="number"
|
||||
label="JGLOBAL_FIELD_ID_LABEL"
|
||||
default="0"
|
||||
readonly="true"
|
||||
class="readonly"
|
||||
/>
|
||||
|
||||
<field
|
||||
name="template"
|
||||
type="text"
|
||||
label="COM_TEMPLATES_FIELD_TEMPLATE_LABEL"
|
||||
class="readonly"
|
||||
size="30"
|
||||
readonly="true"
|
||||
/>
|
||||
|
||||
<field
|
||||
name="client_id"
|
||||
type="hidden"
|
||||
label="COM_TEMPLATES_FIELD_CLIENT_LABEL"
|
||||
class="readonly"
|
||||
default="0"
|
||||
readonly="true"
|
||||
/>
|
||||
|
||||
<field
|
||||
name="title"
|
||||
type="text"
|
||||
label="COM_TEMPLATES_FIELD_TITLE_LABEL"
|
||||
size="50"
|
||||
required="true"
|
||||
/>
|
||||
|
||||
<field name="assigned" type="hidden" />
|
||||
|
||||
</fieldset>
|
||||
</form>
|
||||
141
components/com_config/src/Controller/ConfigController.php
Normal file
141
components/com_config/src/Controller/ConfigController.php
Normal file
@ -0,0 +1,141 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Joomla.Site
|
||||
* @subpackage com_config
|
||||
*
|
||||
* @copyright (C) 2017 Open Source Matters, Inc. <https://www.joomla.org>
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace Joomla\Component\Config\Site\Controller;
|
||||
|
||||
use Joomla\CMS\Application\CMSApplication;
|
||||
use Joomla\CMS\Client\ClientHelper;
|
||||
use Joomla\CMS\Language\Text;
|
||||
use Joomla\CMS\MVC\Controller\BaseController;
|
||||
use Joomla\CMS\MVC\Factory\MVCFactoryInterface;
|
||||
use Joomla\CMS\Router\Route;
|
||||
use Joomla\CMS\Uri\Uri;
|
||||
|
||||
// phpcs:disable PSR1.Files.SideEffects
|
||||
\defined('_JEXEC') or die;
|
||||
// phpcs:enable PSR1.Files.SideEffects
|
||||
|
||||
/**
|
||||
* Component Controller
|
||||
*
|
||||
* @since 1.5
|
||||
*/
|
||||
class ConfigController extends BaseController
|
||||
{
|
||||
/**
|
||||
* @param array $config An optional associative array of configuration settings.
|
||||
* Recognized key values include 'name', 'default_task', 'model_path', and
|
||||
* 'view_path' (this list is not meant to be comprehensive).
|
||||
* @param ?MVCFactoryInterface $factory The factory.
|
||||
* @param ?CMSApplication $app The JApplication for the dispatcher
|
||||
* @param ?\Joomla\CMS\Input\Input $input The Input object for the request
|
||||
*
|
||||
* @since 1.6
|
||||
*/
|
||||
public function __construct($config = [], ?MVCFactoryInterface $factory = null, $app = null, $input = null)
|
||||
{
|
||||
parent::__construct($config, $factory, $app, $input);
|
||||
|
||||
$this->registerTask('apply', 'save');
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to handle cancel
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 3.2
|
||||
*/
|
||||
public function cancel()
|
||||
{
|
||||
// Redirect back to home(base) page
|
||||
$this->setRedirect(Uri::base());
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to save global configuration.
|
||||
*
|
||||
* @return boolean True on success.
|
||||
*
|
||||
* @since 3.2
|
||||
*/
|
||||
public function save()
|
||||
{
|
||||
// Check for request forgeries.
|
||||
$this->checkToken();
|
||||
|
||||
// Check if the user is authorized to do this.
|
||||
if (!$this->app->getIdentity()->authorise('core.admin')) {
|
||||
$this->app->enqueueMessage(Text::_('JERROR_ALERTNOAUTHOR'));
|
||||
$this->app->redirect('index.php');
|
||||
}
|
||||
|
||||
// Set FTP credentials, if given.
|
||||
ClientHelper::setCredentialsFromRequest('ftp');
|
||||
|
||||
$model = $this->getModel();
|
||||
|
||||
$form = $model->getForm();
|
||||
$data = $this->app->getInput()->post->get('jform', [], 'array');
|
||||
|
||||
// Validate the posted data.
|
||||
$return = $model->validate($form, $data);
|
||||
|
||||
// Check for validation errors.
|
||||
if ($return === false) {
|
||||
/*
|
||||
* The validate method enqueued all messages for us, so we just need to redirect back.
|
||||
*/
|
||||
|
||||
// Save the data in the session.
|
||||
$this->app->setUserState('com_config.config.global.data', $data);
|
||||
|
||||
// Redirect back to the edit screen.
|
||||
$this->app->redirect(Route::_('index.php?option=com_config&view=config', false));
|
||||
}
|
||||
|
||||
// Attempt to save the configuration.
|
||||
$data = $return;
|
||||
|
||||
// Access backend com_config
|
||||
$saveClass = $this->factory->createController('Application', 'Administrator', [], $this->app, $this->input);
|
||||
|
||||
// Get a document object
|
||||
$document = $this->app->getDocument();
|
||||
|
||||
// Set backend required params
|
||||
$document->setType('json');
|
||||
|
||||
// Execute backend controller
|
||||
$return = $saveClass->save();
|
||||
|
||||
// Reset params back after requesting from service
|
||||
$document->setType('html');
|
||||
|
||||
// Check the return value.
|
||||
if ($return === false) {
|
||||
/*
|
||||
* The save method enqueued all messages for us, so we just need to redirect back.
|
||||
*/
|
||||
|
||||
// Save the data in the session.
|
||||
$this->app->setUserState('com_config.config.global.data', $data);
|
||||
|
||||
// Save failed, go back to the screen and display a notice.
|
||||
$this->app->redirect(Route::_('index.php?option=com_config&view=config', false));
|
||||
}
|
||||
|
||||
// Redirect back to com_config display
|
||||
$this->app->enqueueMessage(Text::_('COM_CONFIG_SAVE_SUCCESS'));
|
||||
$this->app->redirect(Route::_('index.php?option=com_config&view=config', false));
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
39
components/com_config/src/Controller/DisplayController.php
Normal file
39
components/com_config/src/Controller/DisplayController.php
Normal file
@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Joomla.Site
|
||||
* @subpackage com_config
|
||||
*
|
||||
* @copyright (C) 2013 Open Source Matters, Inc. <https://www.joomla.org>
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace Joomla\Component\Config\Site\Controller;
|
||||
|
||||
use Joomla\CMS\MVC\Controller\BaseController;
|
||||
use Joomla\CMS\Uri\Uri;
|
||||
|
||||
// phpcs:disable PSR1.Files.SideEffects
|
||||
\defined('_JEXEC') or die;
|
||||
// phpcs:enable PSR1.Files.SideEffects
|
||||
|
||||
/**
|
||||
* Component Controller
|
||||
*
|
||||
* @since 1.5
|
||||
*/
|
||||
class DisplayController extends BaseController
|
||||
{
|
||||
/**
|
||||
* Method to handle cancel
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 3.2
|
||||
*/
|
||||
public function cancel()
|
||||
{
|
||||
// Redirect back to home(base) page
|
||||
$this->setRedirect(Uri::base());
|
||||
}
|
||||
}
|
||||
178
components/com_config/src/Controller/ModulesController.php
Normal file
178
components/com_config/src/Controller/ModulesController.php
Normal file
@ -0,0 +1,178 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Joomla.Site
|
||||
* @subpackage com_config
|
||||
*
|
||||
* @copyright (C) 2017 Open Source Matters, Inc. <https://www.joomla.org>
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace Joomla\Component\Config\Site\Controller;
|
||||
|
||||
use Joomla\CMS\Application\AdministratorApplication;
|
||||
use Joomla\CMS\Application\CMSApplication;
|
||||
use Joomla\CMS\Client\ClientHelper;
|
||||
use Joomla\CMS\Factory;
|
||||
use Joomla\CMS\Form\Form;
|
||||
use Joomla\CMS\Language\Text;
|
||||
use Joomla\CMS\MVC\Controller\BaseController;
|
||||
use Joomla\CMS\MVC\Factory\MVCFactoryInterface;
|
||||
use Joomla\CMS\Router\Route;
|
||||
use Joomla\CMS\Uri\Uri;
|
||||
use Joomla\Component\Modules\Administrator\Controller\ModuleController;
|
||||
|
||||
// phpcs:disable PSR1.Files.SideEffects
|
||||
\defined('_JEXEC') or die;
|
||||
// phpcs:enable PSR1.Files.SideEffects
|
||||
|
||||
/**
|
||||
* Component Controller
|
||||
*
|
||||
* @since 1.5
|
||||
*/
|
||||
class ModulesController extends BaseController
|
||||
{
|
||||
/**
|
||||
* @param array $config An optional associative array of configuration settings.
|
||||
* Recognized key values include 'name', 'default_task', 'model_path', and
|
||||
* 'view_path' (this list is not meant to be comprehensive).
|
||||
* @param ?MVCFactoryInterface $factory The factory.
|
||||
* @param ?CMSApplication $app The Application for the dispatcher
|
||||
* @param ?\Joomla\CMS\Input\Input $input The Input object for the request
|
||||
*
|
||||
* @since 1.6
|
||||
*/
|
||||
public function __construct($config = [], ?MVCFactoryInterface $factory = null, $app = null, $input = null)
|
||||
{
|
||||
parent::__construct($config, $factory, $app, $input);
|
||||
|
||||
$this->registerTask('apply', 'save');
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to handle cancel
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 3.2
|
||||
*/
|
||||
public function cancel()
|
||||
{
|
||||
// Redirect back to previous page
|
||||
$this->setRedirect($this->getReturnUrl());
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to save module editing.
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 3.2
|
||||
*/
|
||||
public function save()
|
||||
{
|
||||
// Check for request forgeries.
|
||||
$this->checkToken();
|
||||
|
||||
// Check if the user is authorized to do this.
|
||||
$user = $this->app->getIdentity();
|
||||
|
||||
if (!$user->authorise('module.edit.frontend', 'com_modules.module.' . $this->input->get('id'))) {
|
||||
$this->app->enqueueMessage(Text::_('JERROR_ALERTNOAUTHOR'), 'error');
|
||||
$this->app->redirect('index.php');
|
||||
}
|
||||
|
||||
// Set FTP credentials, if given.
|
||||
ClientHelper::setCredentialsFromRequest('ftp');
|
||||
|
||||
// Get submitted module id
|
||||
$moduleId = '&id=' . $this->input->getInt('id');
|
||||
|
||||
// Get returnUri
|
||||
$returnUri = $this->input->post->get('return', null, 'base64');
|
||||
$redirect = '';
|
||||
|
||||
if (!empty($returnUri)) {
|
||||
$redirect = '&return=' . $returnUri;
|
||||
}
|
||||
|
||||
/** @var AdministratorApplication $app */
|
||||
$app = Factory::getContainer()->get(AdministratorApplication::class);
|
||||
|
||||
// Reset Uri cache.
|
||||
Uri::reset();
|
||||
|
||||
// Get a document object
|
||||
$document = $this->app->getDocument();
|
||||
|
||||
// Load application dependencies.
|
||||
$app->loadLanguage($this->app->getLanguage());
|
||||
$app->loadDocument($document);
|
||||
$app->loadIdentity($user);
|
||||
|
||||
/** @var \Joomla\CMS\Dispatcher\ComponentDispatcher $dispatcher */
|
||||
$dispatcher = $app->bootComponent('com_modules')->getDispatcher($app);
|
||||
|
||||
/** @var ModuleController $controllerClass */
|
||||
$controllerClass = $dispatcher->getController('Module');
|
||||
|
||||
// Set backend required params
|
||||
$document->setType('json');
|
||||
|
||||
// Execute backend controller
|
||||
Form::addFormPath(JPATH_ADMINISTRATOR . '/components/com_modules/forms');
|
||||
$return = $controllerClass->save();
|
||||
|
||||
// Reset params back after requesting from service
|
||||
$document->setType('html');
|
||||
|
||||
// Check the return value.
|
||||
if ($return === false) {
|
||||
// Save the data in the session.
|
||||
$data = $this->input->post->get('jform', [], 'array');
|
||||
|
||||
$this->app->setUserState('com_config.modules.global.data', $data);
|
||||
|
||||
// Save failed, go back to the screen and display a notice.
|
||||
$this->app->enqueueMessage(Text::_('JERROR_SAVE_FAILED'));
|
||||
$this->app->redirect(Route::_('index.php?option=com_config&view=modules' . $moduleId . $redirect, false));
|
||||
}
|
||||
|
||||
// Redirect back to com_config display
|
||||
$this->app->enqueueMessage(Text::_('COM_CONFIG_MODULES_SAVE_SUCCESS'), 'success');
|
||||
|
||||
// Set the redirect based on the task.
|
||||
switch ($this->input->getCmd('task')) {
|
||||
case 'apply':
|
||||
$this->app->redirect(Route::_('index.php?option=com_config&view=modules' . $moduleId . $redirect, false));
|
||||
break;
|
||||
|
||||
case 'save':
|
||||
default:
|
||||
$this->setRedirect($this->getReturnUrl());
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to get redirect URL after saving or cancel editing a module from frontend
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
* @since 5.1.0
|
||||
*/
|
||||
private function getReturnUrl(): string
|
||||
{
|
||||
if ($return = $this->input->post->get('return', '', 'BASE64')) {
|
||||
$return = base64_decode(urldecode($return));
|
||||
|
||||
// Only redirect to if it is an internal URL
|
||||
if (Uri::isInternal($return)) {
|
||||
return $return;
|
||||
}
|
||||
}
|
||||
|
||||
return Uri::base();
|
||||
}
|
||||
}
|
||||
121
components/com_config/src/Controller/TemplatesController.php
Normal file
121
components/com_config/src/Controller/TemplatesController.php
Normal file
@ -0,0 +1,121 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Joomla.Site
|
||||
* @subpackage com_config
|
||||
*
|
||||
* @copyright (C) 2017 Open Source Matters, Inc. <https://www.joomla.org>
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace Joomla\Component\Config\Site\Controller;
|
||||
|
||||
use Joomla\CMS\Application\CMSApplication;
|
||||
use Joomla\CMS\Client\ClientHelper;
|
||||
use Joomla\CMS\Language\Text;
|
||||
use Joomla\CMS\MVC\Controller\BaseController;
|
||||
use Joomla\CMS\MVC\Factory\MVCFactoryInterface;
|
||||
use Joomla\CMS\Router\Route;
|
||||
use Joomla\CMS\Uri\Uri;
|
||||
|
||||
// phpcs:disable PSR1.Files.SideEffects
|
||||
\defined('_JEXEC') or die;
|
||||
// phpcs:enable PSR1.Files.SideEffects
|
||||
|
||||
/**
|
||||
* Component Controller
|
||||
*
|
||||
* @since 1.5
|
||||
*/
|
||||
class TemplatesController extends BaseController
|
||||
{
|
||||
/**
|
||||
* @param array $config An optional associative array of configuration settings.
|
||||
* Recognized key values include 'name', 'default_task', 'model_path', and
|
||||
* 'view_path' (this list is not meant to be comprehensive).
|
||||
* @param ?MVCFactoryInterface $factory The factory.
|
||||
* @param ?CMSApplication $app The Application for the dispatcher
|
||||
* @param ?\Joomla\CMS\Input\Input $input The Input object for the request
|
||||
*
|
||||
* @since 1.6
|
||||
*/
|
||||
public function __construct($config = [], ?MVCFactoryInterface $factory = null, $app = null, $input = null)
|
||||
{
|
||||
parent::__construct($config, $factory, $app, $input);
|
||||
|
||||
// Apply, Save & New, and Save As copy should be standard on forms.
|
||||
$this->registerTask('apply', 'save');
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to handle cancel
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 3.2
|
||||
*/
|
||||
public function cancel()
|
||||
{
|
||||
// Redirect back to home(base) page
|
||||
$this->setRedirect(Uri::base());
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to save global configuration.
|
||||
*
|
||||
* @return boolean True on success.
|
||||
*
|
||||
* @since 3.2
|
||||
*/
|
||||
public function save()
|
||||
{
|
||||
// Check for request forgeries.
|
||||
$this->checkToken();
|
||||
|
||||
// Check if the user is authorized to do this.
|
||||
if (!$this->app->getIdentity()->authorise('core.admin')) {
|
||||
$this->setRedirect('index.php', Text::_('JERROR_ALERTNOAUTHOR'));
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// Set FTP credentials, if given.
|
||||
ClientHelper::setCredentialsFromRequest('ftp');
|
||||
|
||||
$app = $this->app;
|
||||
|
||||
// Access backend com_templates
|
||||
$controllerClass = $app->bootComponent('com_templates')
|
||||
->getMVCFactory()->createController('Style', 'Administrator', [], $app, $app->getInput());
|
||||
|
||||
// Get a document object
|
||||
$document = $app->getDocument();
|
||||
|
||||
// Set backend required params
|
||||
$document->setType('json');
|
||||
$this->input->set('id', $app->getTemplate(true)->id);
|
||||
|
||||
// Execute backend controller
|
||||
$return = $controllerClass->save();
|
||||
|
||||
// Reset params back after requesting from service
|
||||
$document->setType('html');
|
||||
|
||||
// Check the return value.
|
||||
if ($return === false) {
|
||||
// Save failed, go back to the screen and display a notice.
|
||||
$this->setMessage(Text::sprintf('JERROR_SAVE_FAILED'), 'error');
|
||||
$this->setRedirect(Route::_('index.php?option=com_config&view=templates', false));
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// Set the success message.
|
||||
$this->setMessage(Text::_('COM_CONFIG_SAVE_SUCCESS'));
|
||||
|
||||
// Redirect back to com_config display
|
||||
$this->setRedirect(Route::_('index.php?option=com_config&view=templates', false));
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
52
components/com_config/src/Dispatcher/Dispatcher.php
Normal file
52
components/com_config/src/Dispatcher/Dispatcher.php
Normal file
@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Joomla.Site
|
||||
* @subpackage com_config
|
||||
*
|
||||
* @copyright (C) 2017 Open Source Matters, Inc. <https://www.joomla.org>
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace Joomla\Component\Config\Site\Dispatcher;
|
||||
|
||||
use Joomla\CMS\Access\Exception\NotAllowed;
|
||||
use Joomla\CMS\Dispatcher\ComponentDispatcher;
|
||||
|
||||
// phpcs:disable PSR1.Files.SideEffects
|
||||
\defined('_JEXEC') or die;
|
||||
// phpcs:enable PSR1.Files.SideEffects
|
||||
|
||||
/**
|
||||
* ComponentDispatcher class for com_config
|
||||
*
|
||||
* @since 4.0.0
|
||||
*/
|
||||
class Dispatcher extends ComponentDispatcher
|
||||
{
|
||||
/**
|
||||
* Method to check component access permission
|
||||
*
|
||||
* @since 4.0.0
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @throws \Exception|NotAllowed
|
||||
*/
|
||||
protected function checkAccess()
|
||||
{
|
||||
parent::checkAccess();
|
||||
|
||||
$task = $this->input->getCmd('task', 'display');
|
||||
$view = $this->input->get('view');
|
||||
$user = $this->app->getIdentity();
|
||||
|
||||
if (substr($task, 0, 8) === 'modules.' || $view === 'modules') {
|
||||
if (!$user->authorise('module.edit.frontend', 'com_modules.module.' . $this->input->get('id'))) {
|
||||
throw new NotAllowed($this->app->getLanguage()->_('JERROR_ALERTNOAUTHOR'), 403);
|
||||
}
|
||||
} elseif (!$user->authorise('core.admin')) {
|
||||
throw new NotAllowed($this->app->getLanguage()->_('JERROR_ALERTNOAUTHOR'), 403);
|
||||
}
|
||||
}
|
||||
}
|
||||
45
components/com_config/src/Model/ConfigModel.php
Normal file
45
components/com_config/src/Model/ConfigModel.php
Normal file
@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Joomla.Site
|
||||
* @subpackage com_config
|
||||
*
|
||||
* @copyright (C) 2013 Open Source Matters, Inc. <https://www.joomla.org>
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace Joomla\Component\Config\Site\Model;
|
||||
|
||||
// phpcs:disable PSR1.Files.SideEffects
|
||||
\defined('_JEXEC') or die;
|
||||
// phpcs:enable PSR1.Files.SideEffects
|
||||
|
||||
/**
|
||||
* Model for the global configuration
|
||||
*
|
||||
* @since 3.2
|
||||
*/
|
||||
class ConfigModel extends FormModel
|
||||
{
|
||||
/**
|
||||
* Method to get a form object.
|
||||
*
|
||||
* @param array $data Data for the form.
|
||||
* @param boolean $loadData True if the form is to load its own data (default case), false if not.
|
||||
*
|
||||
* @return mixed A Form object on success, false on failure
|
||||
*
|
||||
* @since 3.2
|
||||
*/
|
||||
public function getForm($data = [], $loadData = true)
|
||||
{
|
||||
// Get the form.
|
||||
$form = $this->loadForm('com_config.config', 'config', ['control' => 'jform', 'load_data' => $loadData]);
|
||||
|
||||
if (empty($form)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $form;
|
||||
}
|
||||
}
|
||||
271
components/com_config/src/Model/FormModel.php
Normal file
271
components/com_config/src/Model/FormModel.php
Normal file
@ -0,0 +1,271 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Joomla.Site
|
||||
* @subpackage com_config
|
||||
*
|
||||
* @copyright (C) 2013 Open Source Matters, Inc. <https://www.joomla.org>
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace Joomla\Component\Config\Site\Model;
|
||||
|
||||
use Joomla\CMS\Factory;
|
||||
use Joomla\CMS\Form\Form;
|
||||
use Joomla\CMS\Language\Text;
|
||||
use Joomla\CMS\MVC\Model\FormModel as BaseForm;
|
||||
use Joomla\CMS\Plugin\PluginHelper;
|
||||
use Joomla\Utilities\ArrayHelper;
|
||||
|
||||
// phpcs:disable PSR1.Files.SideEffects
|
||||
\defined('_JEXEC') or die;
|
||||
// phpcs:enable PSR1.Files.SideEffects
|
||||
|
||||
/**
|
||||
* Prototype form model.
|
||||
*
|
||||
* @see JForm
|
||||
* @see \Joomla\CMS\Form\FormField
|
||||
* @see \Joomla\CMS\Form\FormRule
|
||||
* @since 3.2
|
||||
*/
|
||||
abstract class FormModel extends BaseForm
|
||||
{
|
||||
/**
|
||||
* Array of form objects.
|
||||
*
|
||||
* @var array
|
||||
* @since 3.2
|
||||
*/
|
||||
protected $forms = [];
|
||||
|
||||
/**
|
||||
* Method to checkin a row.
|
||||
*
|
||||
* @param integer $pk The numeric id of the primary key.
|
||||
*
|
||||
* @return boolean False on failure or error, true otherwise.
|
||||
*
|
||||
* @since 3.2
|
||||
* @throws \RuntimeException
|
||||
*/
|
||||
public function checkin($pk = null)
|
||||
{
|
||||
// Only attempt to check the row in if it exists.
|
||||
if ($pk) {
|
||||
$user = $this->getCurrentUser();
|
||||
|
||||
// Get an instance of the row to checkin.
|
||||
$table = $this->getTable();
|
||||
|
||||
if (!$table->load($pk)) {
|
||||
throw new \RuntimeException($table->getError());
|
||||
}
|
||||
|
||||
// Check if this is the user has previously checked out the row.
|
||||
if (!\is_null($table->checked_out) && $table->checked_out != $user->id && !$user->authorise('core.admin', 'com_checkin')) {
|
||||
throw new \RuntimeException($table->getError());
|
||||
}
|
||||
|
||||
// Attempt to check the row in.
|
||||
if (!$table->checkIn($pk)) {
|
||||
throw new \RuntimeException($table->getError());
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to check-out a row for editing.
|
||||
*
|
||||
* @param integer $pk The numeric id of the primary key.
|
||||
*
|
||||
* @return boolean False on failure or error, true otherwise.
|
||||
*
|
||||
* @since 3.2
|
||||
*/
|
||||
public function checkout($pk = null)
|
||||
{
|
||||
// Only attempt to check the row in if it exists.
|
||||
if ($pk) {
|
||||
$user = $this->getCurrentUser();
|
||||
|
||||
// Get an instance of the row to checkout.
|
||||
$table = $this->getTable();
|
||||
|
||||
if (!$table->load($pk)) {
|
||||
throw new \RuntimeException($table->getError());
|
||||
}
|
||||
|
||||
// Check if this is the user having previously checked out the row.
|
||||
if (!\is_null($table->checked_out) && $table->checked_out != $user->id) {
|
||||
throw new \RuntimeException(Text::_('JLIB_APPLICATION_ERROR_CHECKOUT_USER_MISMATCH'));
|
||||
}
|
||||
|
||||
// Attempt to check the row out.
|
||||
if (!$table->checkOut($user->id, $pk)) {
|
||||
throw new \RuntimeException($table->getError());
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to get a form object.
|
||||
*
|
||||
* @param string $name The name of the form.
|
||||
* @param string $source The form source. Can be XML string if file flag is set to false.
|
||||
* @param array $options Optional array of options for the form creation.
|
||||
* @param boolean $clear Optional argument to force load a new form.
|
||||
* @param string $xpath An optional xpath to search for the fields.
|
||||
*
|
||||
* @return mixed JForm object on success, False on error.
|
||||
*
|
||||
* @see JForm
|
||||
* @since 3.2
|
||||
*/
|
||||
protected function loadForm($name, $source = null, $options = [], $clear = false, $xpath = false)
|
||||
{
|
||||
// Handle the optional arguments.
|
||||
$options['control'] = ArrayHelper::getValue($options, 'control', false);
|
||||
|
||||
// Create a signature hash.
|
||||
$hash = sha1($source . serialize($options));
|
||||
|
||||
// Check if we can use a previously loaded form.
|
||||
if (isset($this->_forms[$hash]) && !$clear) {
|
||||
return $this->_forms[$hash];
|
||||
}
|
||||
|
||||
// Register the paths for the form.
|
||||
Form::addFormPath(JPATH_SITE . '/components/com_config/forms');
|
||||
Form::addFormPath(JPATH_ADMINISTRATOR . '/components/com_config/forms');
|
||||
|
||||
try {
|
||||
// Get the form.
|
||||
$form = Form::getInstance($name, $source, $options, false, $xpath);
|
||||
|
||||
if (isset($options['load_data']) && $options['load_data']) {
|
||||
// Get the data for the form.
|
||||
$data = $this->loadFormData();
|
||||
} else {
|
||||
$data = [];
|
||||
}
|
||||
|
||||
// Allow for additional modification of the form, and events to be triggered.
|
||||
// We pass the data because plugins may require it.
|
||||
$this->preprocessForm($form, $data);
|
||||
|
||||
// Load the data into the form after the plugins have operated.
|
||||
$form->bind($data);
|
||||
} catch (\Exception $e) {
|
||||
Factory::getApplication()->enqueueMessage($e->getMessage());
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// Store the form for later.
|
||||
$this->_forms[$hash] = $form;
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to get the data that should be injected in the form.
|
||||
*
|
||||
* @return array The default data is an empty array.
|
||||
*
|
||||
* @since 3.2
|
||||
*/
|
||||
protected function loadFormData()
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to allow derived classes to preprocess the data.
|
||||
*
|
||||
* @param string $context The context identifier.
|
||||
* @param mixed &$data The data to be processed. It gets altered directly.
|
||||
* @param string $group The name of the plugin group to import (defaults to "content").
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 3.2
|
||||
*/
|
||||
protected function preprocessData($context, &$data, $group = 'content')
|
||||
{
|
||||
// Get the dispatcher and load the users plugins.
|
||||
PluginHelper::importPlugin('content');
|
||||
|
||||
// Trigger the data preparation event.
|
||||
Factory::getApplication()->triggerEvent('onContentPrepareData', [$context, $data]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to allow derived classes to preprocess the form.
|
||||
*
|
||||
* @param Form $form A Form object.
|
||||
* @param mixed $data The data expected for the form.
|
||||
* @param string $group The name of the plugin group to import (defaults to "content").
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @see \Joomla\CMS\Form\FormField
|
||||
* @since 3.2
|
||||
* @throws \Exception if there is an error in the form event.
|
||||
*/
|
||||
protected function preprocessForm(Form $form, $data, $group = 'content')
|
||||
{
|
||||
// Import the appropriate plugin group.
|
||||
PluginHelper::importPlugin($group);
|
||||
|
||||
// Trigger the form preparation event.
|
||||
Factory::getApplication()->triggerEvent('onContentPrepareForm', [$form, $data]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to validate the form data.
|
||||
*
|
||||
* @param Form $form The form to validate against.
|
||||
* @param array $data The data to validate.
|
||||
* @param string $group The name of the field group to validate.
|
||||
*
|
||||
* @return mixed Array of filtered data if valid, false otherwise.
|
||||
*
|
||||
* @see \Joomla\CMS\Form\FormRule
|
||||
* @see \Joomla\CMS\Filter\InputFilter
|
||||
* @since 3.2
|
||||
*/
|
||||
public function validate($form, $data, $group = null)
|
||||
{
|
||||
// Filter and validate the form data.
|
||||
$data = $form->filter($data);
|
||||
$return = $form->validate($data, $group);
|
||||
|
||||
// Check for an error.
|
||||
if ($return instanceof \Exception) {
|
||||
Factory::getApplication()->enqueueMessage($return->getMessage(), 'error');
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// Check the validation results.
|
||||
if ($return === false) {
|
||||
// Get the validation messages from the form.
|
||||
foreach ($form->getErrors() as $message) {
|
||||
if ($message instanceof \Exception) {
|
||||
$message = $message->getMessage();
|
||||
}
|
||||
|
||||
Factory::getApplication()->enqueueMessage($message, 'error');
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
253
components/com_config/src/Model/ModulesModel.php
Normal file
253
components/com_config/src/Model/ModulesModel.php
Normal file
@ -0,0 +1,253 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Joomla.Site
|
||||
* @subpackage com_config
|
||||
*
|
||||
* @copyright (C) 2014 Open Source Matters, Inc. <https://www.joomla.org>
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace Joomla\Component\Config\Site\Model;
|
||||
|
||||
use Joomla\CMS\Factory;
|
||||
use Joomla\CMS\Form\Form;
|
||||
use Joomla\CMS\HTML\HTMLHelper;
|
||||
use Joomla\CMS\Language\Text;
|
||||
use Joomla\Filesystem\Path;
|
||||
|
||||
// phpcs:disable PSR1.Files.SideEffects
|
||||
\defined('_JEXEC') or die;
|
||||
// phpcs:enable PSR1.Files.SideEffects
|
||||
|
||||
/**
|
||||
* Config Module model.
|
||||
*
|
||||
* @since 3.2
|
||||
*/
|
||||
class ModulesModel extends FormModel
|
||||
{
|
||||
/**
|
||||
* Method to auto-populate the model state.
|
||||
*
|
||||
* Note. Calling getState in this method will result in recursion.
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 3.2
|
||||
*/
|
||||
protected function populateState()
|
||||
{
|
||||
$app = Factory::getApplication();
|
||||
|
||||
// Load the User state.
|
||||
$pk = $app->getInput()->getInt('id');
|
||||
|
||||
$this->setState('module.id', $pk);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to get the record form.
|
||||
*
|
||||
* @param array $data Data for the form.
|
||||
* @param boolean $loadData True if the form is to load its own data (default case), false if not.
|
||||
*
|
||||
* @return Form A Form object on success, false on failure
|
||||
*
|
||||
* @since 3.2
|
||||
*/
|
||||
public function getForm($data = [], $loadData = true)
|
||||
{
|
||||
// Get the form.
|
||||
$form = $this->loadForm('com_config.modules', 'modules', ['control' => 'jform', 'load_data' => $loadData]);
|
||||
|
||||
if (empty($form)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to preprocess the form
|
||||
*
|
||||
* @param Form $form A form object.
|
||||
* @param mixed $data The data expected for the form.
|
||||
* @param string $group The name of the plugin group to import (defaults to "content").
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 3.2
|
||||
* @throws \Exception if there is an error loading the form.
|
||||
*/
|
||||
protected function preprocessForm(Form $form, $data, $group = 'content')
|
||||
{
|
||||
$lang = Factory::getLanguage();
|
||||
$module = $this->getState()->get('module.name');
|
||||
$basePath = JPATH_BASE;
|
||||
|
||||
$formFile = Path::clean($basePath . '/modules/' . $module . '/' . $module . '.xml');
|
||||
|
||||
// Load the core and/or local language file(s).
|
||||
$lang->load($module, $basePath)
|
||||
|| $lang->load($module, $basePath . '/modules/' . $module);
|
||||
|
||||
if (file_exists($formFile)) {
|
||||
// Get the module form.
|
||||
if (!$form->loadFile($formFile, false, '//config')) {
|
||||
throw new \Exception(Text::_('JERROR_LOADFILE_FAILED'));
|
||||
}
|
||||
|
||||
// Attempt to load the xml file.
|
||||
if (!$xml = simplexml_load_file($formFile)) {
|
||||
throw new \Exception(Text::_('JERROR_LOADFILE_FAILED'));
|
||||
}
|
||||
}
|
||||
|
||||
// Load the default advanced params
|
||||
Form::addFormPath(JPATH_BASE . '/components/com_config/model/form');
|
||||
$form->loadFile('modules_advanced', false);
|
||||
|
||||
// Trigger the default form events.
|
||||
parent::preprocessForm($form, $data, $group);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to get list of module positions in current template
|
||||
*
|
||||
* @return array
|
||||
*
|
||||
* @since 3.2
|
||||
*/
|
||||
public function getPositions()
|
||||
{
|
||||
$lang = Factory::getLanguage();
|
||||
$templateName = Factory::getApplication()->getTemplate();
|
||||
|
||||
// Load templateDetails.xml file
|
||||
$path = Path::clean(JPATH_BASE . '/templates/' . $templateName . '/templateDetails.xml');
|
||||
$currentTemplatePositions = [];
|
||||
|
||||
if (file_exists($path)) {
|
||||
$xml = simplexml_load_file($path);
|
||||
|
||||
if (isset($xml->positions[0])) {
|
||||
// Load language files
|
||||
$lang->load('tpl_' . $templateName . '.sys', JPATH_BASE)
|
||||
|| $lang->load('tpl_' . $templateName . '.sys', JPATH_BASE . '/templates/' . $templateName);
|
||||
|
||||
foreach ($xml->positions[0] as $position) {
|
||||
$value = (string) $position;
|
||||
$text = preg_replace('/[^a-zA-Z0-9_\-]/', '_', 'TPL_' . strtoupper($templateName) . '_POSITION_' . strtoupper($value));
|
||||
|
||||
// Construct list of positions
|
||||
$currentTemplatePositions[] = self::createOption($value, Text::_($text) . ' [' . $value . ']');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$templateGroups = [];
|
||||
|
||||
// Add an empty value to be able to deselect a module position
|
||||
$option = self::createOption();
|
||||
$templateGroups[''] = self::createOptionGroup('', [$option]);
|
||||
|
||||
$templateGroups[$templateName] = self::createOptionGroup($templateName, $currentTemplatePositions);
|
||||
|
||||
// Add custom position to options
|
||||
$customGroupText = Text::_('COM_MODULES_CUSTOM_POSITION');
|
||||
|
||||
$editPositions = true;
|
||||
$customPositions = self::getActivePositions(0, $editPositions);
|
||||
$templateGroups[$customGroupText] = self::createOptionGroup($customGroupText, $customPositions);
|
||||
|
||||
return $templateGroups;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of modules positions
|
||||
*
|
||||
* @param integer $clientId Client ID
|
||||
* @param boolean $editPositions Allow to edit the positions
|
||||
*
|
||||
* @return array A list of positions
|
||||
*
|
||||
* @since 3.6.3
|
||||
*/
|
||||
public static function getActivePositions($clientId, $editPositions = false)
|
||||
{
|
||||
$db = Factory::getDbo();
|
||||
$query = $db->getQuery(true)
|
||||
->select('DISTINCT position')
|
||||
->from($db->quoteName('#__modules'))
|
||||
->where($db->quoteName('client_id') . ' = ' . (int) $clientId)
|
||||
->order($db->quoteName('position'));
|
||||
|
||||
$db->setQuery($query);
|
||||
|
||||
try {
|
||||
$positions = $db->loadColumn();
|
||||
$positions = \is_array($positions) ? $positions : [];
|
||||
} catch (\RuntimeException $e) {
|
||||
Factory::getApplication()->enqueueMessage($e->getMessage(), 'error');
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// Build the list
|
||||
$options = [];
|
||||
|
||||
foreach ($positions as $position) {
|
||||
if (!$position && !$editPositions) {
|
||||
$options[] = HTMLHelper::_('select.option', 'none', ':: ' . Text::_('JNONE') . ' ::');
|
||||
} else {
|
||||
$options[] = HTMLHelper::_('select.option', $position, $position);
|
||||
}
|
||||
}
|
||||
|
||||
return $options;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create and return a new Option
|
||||
*
|
||||
* @param string $value The option value [optional]
|
||||
* @param string $text The option text [optional]
|
||||
*
|
||||
* @return object The option as an object (stdClass instance)
|
||||
*
|
||||
* @since 3.6.3
|
||||
*/
|
||||
private static function createOption($value = '', $text = '')
|
||||
{
|
||||
if (empty($text)) {
|
||||
$text = $value;
|
||||
}
|
||||
|
||||
$option = new \stdClass();
|
||||
$option->value = $value;
|
||||
$option->text = $text;
|
||||
|
||||
return $option;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create and return a new Option Group
|
||||
*
|
||||
* @param string $label Value and label for group [optional]
|
||||
* @param array $options Array of options to insert into group [optional]
|
||||
*
|
||||
* @return array Return the new group as an array
|
||||
*
|
||||
* @since 3.6.3
|
||||
*/
|
||||
private static function createOptionGroup($label = '', $options = [])
|
||||
{
|
||||
$group = [];
|
||||
$group['value'] = $label;
|
||||
$group['text'] = $label;
|
||||
$group['items'] = $options;
|
||||
|
||||
return $group;
|
||||
}
|
||||
}
|
||||
123
components/com_config/src/Model/TemplatesModel.php
Normal file
123
components/com_config/src/Model/TemplatesModel.php
Normal file
@ -0,0 +1,123 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Joomla.Site
|
||||
* @subpackage com_config
|
||||
*
|
||||
* @copyright (C) 2013 Open Source Matters, Inc. <https://www.joomla.org>
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace Joomla\Component\Config\Site\Model;
|
||||
|
||||
use Joomla\CMS\Component\ComponentHelper;
|
||||
use Joomla\CMS\Factory;
|
||||
use Joomla\CMS\Form\Form;
|
||||
use Joomla\CMS\Language\Text;
|
||||
use Joomla\Filesystem\Path;
|
||||
|
||||
// phpcs:disable PSR1.Files.SideEffects
|
||||
\defined('_JEXEC') or die;
|
||||
// phpcs:enable PSR1.Files.SideEffects
|
||||
|
||||
/**
|
||||
* Template style model.
|
||||
*
|
||||
* @since 3.2
|
||||
*/
|
||||
class TemplatesModel extends FormModel
|
||||
{
|
||||
/**
|
||||
* Method to auto-populate the model state.
|
||||
*
|
||||
* Note. Calling getState in this method will result in recursion.
|
||||
*
|
||||
* @return null
|
||||
*
|
||||
* @since 3.2
|
||||
*/
|
||||
protected function populateState()
|
||||
{
|
||||
parent::populateState();
|
||||
|
||||
$this->setState('params', ComponentHelper::getParams('com_templates'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to get the record form.
|
||||
*
|
||||
* @param array $data An optional array of data for the form to interrogate.
|
||||
* @param boolean $loadData True if the form is to load its own data (default case), false if not.
|
||||
*
|
||||
* @return Form|bool A Form object on success, false on failure
|
||||
*
|
||||
* @since 3.2
|
||||
*/
|
||||
public function getForm($data = [], $loadData = true)
|
||||
{
|
||||
try {
|
||||
// Get the form.
|
||||
$form = $this->loadForm('com_config.templates', 'templates', ['load_data' => $loadData]);
|
||||
|
||||
$data = [];
|
||||
$this->preprocessForm($form, $data);
|
||||
|
||||
// Load the data into the form
|
||||
$form->bind($data);
|
||||
} catch (\Exception $e) {
|
||||
Factory::getApplication()->enqueueMessage($e->getMessage());
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
if (empty($form)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to preprocess the form
|
||||
*
|
||||
* @param Form $form A form object.
|
||||
* @param mixed $data The data expected for the form.
|
||||
* @param string $group Plugin group to load
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 3.2
|
||||
* @throws \Exception if there is an error in the form event.
|
||||
*/
|
||||
protected function preprocessForm(Form $form, $data, $group = 'content')
|
||||
{
|
||||
$lang = Factory::getLanguage();
|
||||
|
||||
$template = Factory::getApplication()->getTemplate();
|
||||
|
||||
// Load the core and/or local language file(s).
|
||||
$lang->load('tpl_' . $template, JPATH_BASE)
|
||||
|| $lang->load('tpl_' . $template, JPATH_BASE . '/templates/' . $template);
|
||||
|
||||
// Look for com_config.xml, which contains fields to display
|
||||
$formFile = Path::clean(JPATH_BASE . '/templates/' . $template . '/com_config.xml');
|
||||
|
||||
if (!file_exists($formFile)) {
|
||||
// If com_config.xml not found, fall back to templateDetails.xml
|
||||
$formFile = Path::clean(JPATH_BASE . '/templates/' . $template . '/templateDetails.xml');
|
||||
}
|
||||
|
||||
// Get the template form.
|
||||
if (file_exists($formFile) && !$form->loadFile($formFile, false, '//config')) {
|
||||
throw new \Exception(Text::_('JERROR_LOADFILE_FAILED'));
|
||||
}
|
||||
|
||||
// Attempt to load the xml file.
|
||||
if (!$xml = simplexml_load_file($formFile)) {
|
||||
throw new \Exception(Text::_('JERROR_LOADFILE_FAILED'));
|
||||
}
|
||||
|
||||
// Trigger the default form events.
|
||||
parent::preprocessForm($form, $data, $group);
|
||||
}
|
||||
}
|
||||
49
components/com_config/src/Service/Router.php
Normal file
49
components/com_config/src/Service/Router.php
Normal file
@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Joomla.Site
|
||||
* @subpackage com_config
|
||||
*
|
||||
* @copyright (C) 2009 Open Source Matters, Inc. <https://www.joomla.org>
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace Joomla\Component\Config\Site\Service;
|
||||
|
||||
use Joomla\CMS\Application\SiteApplication;
|
||||
use Joomla\CMS\Component\Router\RouterView;
|
||||
use Joomla\CMS\Component\Router\RouterViewConfiguration;
|
||||
use Joomla\CMS\Component\Router\Rules\MenuRules;
|
||||
use Joomla\CMS\Component\Router\Rules\NomenuRules;
|
||||
use Joomla\CMS\Component\Router\Rules\StandardRules;
|
||||
use Joomla\CMS\Menu\AbstractMenu;
|
||||
|
||||
// phpcs:disable PSR1.Files.SideEffects
|
||||
\defined('_JEXEC') or die;
|
||||
// phpcs:enable PSR1.Files.SideEffects
|
||||
|
||||
/**
|
||||
* Routing class from com_config
|
||||
*
|
||||
* @since 4.0.0
|
||||
*/
|
||||
class Router extends RouterView
|
||||
{
|
||||
/**
|
||||
* Config Component router constructor
|
||||
*
|
||||
* @param SiteApplication $app The application object
|
||||
* @param AbstractMenu $menu The menu object to work with
|
||||
*/
|
||||
public function __construct(SiteApplication $app, AbstractMenu $menu)
|
||||
{
|
||||
$this->registerView(new RouterViewConfiguration('config'));
|
||||
$this->registerView(new RouterViewConfiguration('templates'));
|
||||
|
||||
parent::__construct($app, $menu);
|
||||
|
||||
$this->attachRule(new MenuRules($this));
|
||||
$this->attachRule(new StandardRules($this));
|
||||
$this->attachRule(new NomenuRules($this));
|
||||
}
|
||||
}
|
||||
135
components/com_config/src/View/Config/HtmlView.php
Normal file
135
components/com_config/src/View/Config/HtmlView.php
Normal file
@ -0,0 +1,135 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Joomla.Site
|
||||
* @subpackage com_config
|
||||
*
|
||||
* @copyright (C) 2017 Open Source Matters, Inc. <https://www.joomla.org>
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace Joomla\Component\Config\Site\View\Config;
|
||||
|
||||
use Joomla\CMS\Factory;
|
||||
use Joomla\CMS\MVC\View\HtmlView as BaseHtmlView;
|
||||
use Joomla\Component\Config\Administrator\Controller\RequestController;
|
||||
|
||||
// phpcs:disable PSR1.Files.SideEffects
|
||||
\defined('_JEXEC') or die;
|
||||
// phpcs:enable PSR1.Files.SideEffects
|
||||
|
||||
/**
|
||||
* View for the global configuration
|
||||
*
|
||||
* @since 3.2
|
||||
*/
|
||||
class HtmlView extends BaseHtmlView
|
||||
{
|
||||
/**
|
||||
* The form object
|
||||
*
|
||||
* @var \Joomla\CMS\Form\Form
|
||||
*
|
||||
* @since 3.2
|
||||
*/
|
||||
public $form;
|
||||
|
||||
/**
|
||||
* The data to be displayed in the form
|
||||
*
|
||||
* @var array
|
||||
*
|
||||
* @since 3.2
|
||||
*/
|
||||
public $data;
|
||||
|
||||
/**
|
||||
* Is the current user a super administrator?
|
||||
*
|
||||
* @var boolean
|
||||
*
|
||||
* @since 3.2
|
||||
*/
|
||||
protected $userIsSuperAdmin;
|
||||
|
||||
/**
|
||||
* The page class suffix
|
||||
*
|
||||
* @var string
|
||||
*
|
||||
* @since 4.0.0
|
||||
*/
|
||||
protected $pageclass_sfx = '';
|
||||
|
||||
/**
|
||||
* The page parameters
|
||||
*
|
||||
* @var \Joomla\Registry\Registry|null
|
||||
*
|
||||
* @since 4.0.0
|
||||
*/
|
||||
protected $params = null;
|
||||
|
||||
/**
|
||||
* Execute and display a template script.
|
||||
*
|
||||
* @param string $tpl The name of the template file to parse; automatically searches through the template paths.
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 3.2
|
||||
*/
|
||||
public function display($tpl = null)
|
||||
{
|
||||
$user = $this->getCurrentUser();
|
||||
$this->userIsSuperAdmin = $user->authorise('core.admin');
|
||||
|
||||
// Access backend com_config
|
||||
$requestController = new RequestController();
|
||||
|
||||
// Execute backend controller
|
||||
$serviceData = json_decode($requestController->getJson(), true);
|
||||
|
||||
$form = $this->getForm();
|
||||
|
||||
if ($form) {
|
||||
$form->bind($serviceData);
|
||||
}
|
||||
|
||||
$this->form = $form;
|
||||
$this->data = $serviceData;
|
||||
|
||||
$this->_prepareDocument();
|
||||
|
||||
parent::display($tpl);
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepares the document.
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 4.0.0
|
||||
*/
|
||||
protected function _prepareDocument()
|
||||
{
|
||||
$params = Factory::getApplication()->getParams();
|
||||
|
||||
// Because the application sets a default page title, we need to get it
|
||||
// right from the menu item itself
|
||||
|
||||
$this->setDocumentTitle($params->get('page_title', ''));
|
||||
|
||||
if ($params->get('menu-meta_description')) {
|
||||
$this->getDocument()->setDescription($params->get('menu-meta_description'));
|
||||
}
|
||||
|
||||
if ($params->get('robots')) {
|
||||
$this->getDocument()->setMetaData('robots', $params->get('robots'));
|
||||
}
|
||||
|
||||
// Escape strings for HTML output
|
||||
$this->pageclass_sfx = htmlspecialchars($params->get('pageclass_sfx', ''));
|
||||
$this->params = &$params;
|
||||
}
|
||||
}
|
||||
100
components/com_config/src/View/Modules/HtmlView.php
Normal file
100
components/com_config/src/View/Modules/HtmlView.php
Normal file
@ -0,0 +1,100 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Joomla.Site
|
||||
* @subpackage com_config
|
||||
*
|
||||
* @copyright (C) 2017 Open Source Matters, Inc. <https://www.joomla.org>
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace Joomla\Component\Config\Site\View\Modules;
|
||||
|
||||
use Joomla\CMS\Factory;
|
||||
use Joomla\CMS\Form\Form;
|
||||
use Joomla\CMS\Language\Text;
|
||||
use Joomla\CMS\MVC\View\HtmlView as BaseHtmlView;
|
||||
|
||||
// phpcs:disable PSR1.Files.SideEffects
|
||||
\defined('_JEXEC') or die;
|
||||
// phpcs:enable PSR1.Files.SideEffects
|
||||
|
||||
/**
|
||||
* View to edit a module.
|
||||
*
|
||||
* @since 3.2
|
||||
*/
|
||||
class HtmlView extends BaseHtmlView
|
||||
{
|
||||
/**
|
||||
* The module to be rendered
|
||||
*
|
||||
* @var array
|
||||
*
|
||||
* @since 3.2
|
||||
*/
|
||||
public $item;
|
||||
|
||||
/**
|
||||
* The form object
|
||||
*
|
||||
* @var Form
|
||||
*
|
||||
* @since 3.2
|
||||
*/
|
||||
public $form;
|
||||
|
||||
/**
|
||||
* Execute and display a template script.
|
||||
*
|
||||
* @param string $tpl The name of the template file to parse; automatically searches through the template paths.
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 3.2
|
||||
*/
|
||||
public function display($tpl = null)
|
||||
{
|
||||
$lang = Factory::getApplication()->getLanguage();
|
||||
$lang->load('', JPATH_ADMINISTRATOR, $lang->getTag());
|
||||
$lang->load('com_modules', JPATH_ADMINISTRATOR, $lang->getTag());
|
||||
|
||||
// @todo Move and clean up
|
||||
$module = (new \Joomla\Component\Modules\Administrator\Model\ModuleModel())->getItem(Factory::getApplication()->getInput()->getInt('id'));
|
||||
|
||||
$moduleData = $module->getProperties();
|
||||
unset($moduleData['xml']);
|
||||
|
||||
/** @var \Joomla\Component\Config\Site\Model\ModulesModel $model */
|
||||
$model = $this->getModel();
|
||||
|
||||
// Need to add module name to the state of model
|
||||
$model->getState()->set('module.name', $moduleData['module']);
|
||||
|
||||
/** @var Form form */
|
||||
$this->form = $this->get('form');
|
||||
$this->positions = $this->get('positions');
|
||||
$this->item = $moduleData;
|
||||
|
||||
if ($this->form) {
|
||||
$this->form->bind($moduleData);
|
||||
}
|
||||
|
||||
$this->_prepareDocument();
|
||||
|
||||
parent::display($tpl);
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepares the document.
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 4.0.0
|
||||
*/
|
||||
protected function _prepareDocument()
|
||||
{
|
||||
// There is no menu item for this so we have to use the title from the component
|
||||
$this->setDocumentTitle(Text::_('COM_CONFIG_MODULES_SETTINGS_TITLE'));
|
||||
}
|
||||
}
|
||||
158
components/com_config/src/View/Templates/HtmlView.php
Normal file
158
components/com_config/src/View/Templates/HtmlView.php
Normal file
@ -0,0 +1,158 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Joomla.Site
|
||||
* @subpackage com_config
|
||||
*
|
||||
* @copyright (C) 2017 Open Source Matters, Inc. <https://www.joomla.org>
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace Joomla\Component\Config\Site\View\Templates;
|
||||
|
||||
use Joomla\CMS\Factory;
|
||||
use Joomla\CMS\Form\Form;
|
||||
use Joomla\CMS\MVC\Factory\MVCFactory;
|
||||
use Joomla\CMS\MVC\View\HtmlView as BaseHtmlView;
|
||||
use Joomla\Component\Config\Administrator\Controller\RequestController;
|
||||
use Joomla\Component\Templates\Administrator\View\Style\JsonView;
|
||||
|
||||
// phpcs:disable PSR1.Files.SideEffects
|
||||
\defined('_JEXEC') or die;
|
||||
// phpcs:enable PSR1.Files.SideEffects
|
||||
|
||||
/**
|
||||
* View to edit a template style.
|
||||
*
|
||||
* @since 3.2
|
||||
*/
|
||||
class HtmlView extends BaseHtmlView
|
||||
{
|
||||
/**
|
||||
* The data to be displayed in the form
|
||||
*
|
||||
* @var array
|
||||
*
|
||||
* @since 3.2
|
||||
*/
|
||||
public $item;
|
||||
|
||||
/**
|
||||
* The form object
|
||||
*
|
||||
* @var Form
|
||||
*
|
||||
* @since 3.2
|
||||
*/
|
||||
public $form;
|
||||
|
||||
/**
|
||||
* Is the current user a super administrator?
|
||||
*
|
||||
* @var boolean
|
||||
*
|
||||
* @since 3.2
|
||||
*/
|
||||
protected $userIsSuperAdmin;
|
||||
|
||||
/**
|
||||
* The page class suffix
|
||||
*
|
||||
* @var string
|
||||
*
|
||||
* @since 4.0.0
|
||||
*/
|
||||
protected $pageclass_sfx = '';
|
||||
|
||||
/**
|
||||
* The page parameters
|
||||
*
|
||||
* @var \Joomla\Registry\Registry|null
|
||||
*
|
||||
* @since 4.0.0
|
||||
*/
|
||||
protected $params = null;
|
||||
|
||||
/**
|
||||
* Method to render the view.
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 3.2
|
||||
*/
|
||||
public function display($tpl = null)
|
||||
{
|
||||
$user = $this->getCurrentUser();
|
||||
$this->userIsSuperAdmin = $user->authorise('core.admin');
|
||||
|
||||
$app = Factory::getApplication();
|
||||
|
||||
$app->getInput()->set('id', $app->getTemplate(true)->id);
|
||||
|
||||
/** @var MVCFactory $factory */
|
||||
$factory = $app->bootComponent('com_templates')->getMVCFactory();
|
||||
|
||||
/** @var JsonView $view */
|
||||
$view = $factory->createView('Style', 'Administrator', 'Json');
|
||||
$view->setModel($factory->createModel('Style', 'Administrator'), true);
|
||||
$view->setLanguage($app->getLanguage());
|
||||
|
||||
$view->document = $this->getDocument();
|
||||
|
||||
$json = $view->display();
|
||||
|
||||
// Execute backend controller
|
||||
$serviceData = json_decode($json, true);
|
||||
|
||||
// Access backend com_config
|
||||
$requestController = new RequestController();
|
||||
|
||||
// Execute backend controller
|
||||
$configData = json_decode($requestController->getJson(), true);
|
||||
|
||||
$data = array_merge($configData, $serviceData);
|
||||
|
||||
/** @var Form $form */
|
||||
$form = $this->getForm();
|
||||
|
||||
if ($form) {
|
||||
$form->bind($data);
|
||||
}
|
||||
|
||||
$this->form = $form;
|
||||
|
||||
$this->data = $serviceData;
|
||||
|
||||
$this->_prepareDocument();
|
||||
|
||||
parent::display($tpl);
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepares the document.
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 4.0.0
|
||||
*/
|
||||
protected function _prepareDocument()
|
||||
{
|
||||
$params = Factory::getApplication()->getParams();
|
||||
|
||||
// Because the application sets a default page title, we need to get it
|
||||
// right from the menu item itself
|
||||
$this->setDocumentTitle($params->get('page_title', ''));
|
||||
|
||||
if ($params->get('menu-meta_description')) {
|
||||
$this->getDocument()->setDescription($params->get('menu-meta_description'));
|
||||
}
|
||||
|
||||
if ($params->get('robots')) {
|
||||
$this->getDocument()->setMetaData('robots', $params->get('robots'));
|
||||
}
|
||||
|
||||
// Escape strings for HTML output
|
||||
$this->pageclass_sfx = htmlspecialchars($params->get('pageclass_sfx', ''));
|
||||
$this->params = &$params;
|
||||
}
|
||||
}
|
||||
64
components/com_config/tmpl/config/default.php
Normal file
64
components/com_config/tmpl/config/default.php
Normal file
@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Joomla.Site
|
||||
* @subpackage com_config
|
||||
*
|
||||
* @copyright (C) 2013 Open Source Matters, Inc. <https://www.joomla.org>
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
use Joomla\CMS\HTML\HTMLHelper;
|
||||
use Joomla\CMS\Language\Text;
|
||||
use Joomla\CMS\Router\Route;
|
||||
|
||||
/** @var \Joomla\Component\Config\Site\View\Config\HtmlView $this */
|
||||
/** @var Joomla\CMS\WebAsset\WebAssetManager $wa */
|
||||
$wa = $this->getDocument()->getWebAssetManager();
|
||||
$wa->useScript('keepalive')
|
||||
->useScript('form.validate')
|
||||
->useScript('com_config.config')
|
||||
->useScript('inlinehelp');
|
||||
|
||||
?>
|
||||
<?php if ($this->params->get('show_page_heading')) : ?>
|
||||
<div class="page-header">
|
||||
<h1>
|
||||
<?php if ($this->escape($this->params->get('page_heading'))) : ?>
|
||||
<?php echo $this->escape($this->params->get('page_heading')); ?>
|
||||
<?php else : ?>
|
||||
<?php echo $this->escape($this->params->get('page_title')); ?>
|
||||
<?php endif; ?>
|
||||
</h1>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
<form action="<?php echo Route::_('index.php?option=com_config'); ?>" id="application-form" method="post" name="adminForm" class="form-validate">
|
||||
|
||||
<div class="mb-2 d-flex">
|
||||
<button type="button" class="btn btn-sm btn-outline-info button-inlinehelp ms-auto">
|
||||
<span class="fa fa-question-circle" aria-hidden="true"></span>
|
||||
<?php echo Text::_('JINLINEHELP') ?>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<?php echo $this->loadTemplate('site'); ?>
|
||||
<?php echo $this->loadTemplate('seo'); ?>
|
||||
<?php echo $this->loadTemplate('metadata'); ?>
|
||||
|
||||
<input type="hidden" name="task" value="">
|
||||
<?php echo HTMLHelper::_('form.token'); ?>
|
||||
|
||||
<div class="d-grid gap-2 d-sm-block mb-2">
|
||||
<button type="button" class="btn btn-primary" data-submit-task="config.apply">
|
||||
<span class="icon-check" aria-hidden="true"></span>
|
||||
<?php echo Text::_('JSAVE') ?>
|
||||
</button>
|
||||
<button type="button" class="btn btn-danger" data-submit-task="config.cancel">
|
||||
<span class="icon-times" aria-hidden="true"></span>
|
||||
<?php echo Text::_('JCANCEL') ?>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
</form>
|
||||
20
components/com_config/tmpl/config/default.xml
Normal file
20
components/com_config/tmpl/config/default.xml
Normal file
@ -0,0 +1,20 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<metadata>
|
||||
<layout title="COM_CONFIG_CONFIG_VIEW_DEFAULT_TITLE" option="COM_CONFIG_CONFIG_VIEW_DEFAULT_OPTION">
|
||||
<help
|
||||
key = "Menu_Item:_Site_Configuration_Options"
|
||||
/>
|
||||
<message>
|
||||
<![CDATA[COM_CONFIG_CONFIG_VIEW_DEFAULT_DESC]]>
|
||||
</message>
|
||||
</layout>
|
||||
<fields name="request">
|
||||
<fieldset name="request">
|
||||
<field
|
||||
name="controller"
|
||||
type="hidden"
|
||||
default=""
|
||||
/>
|
||||
</fieldset>
|
||||
</fields>
|
||||
</metadata>
|
||||
33
components/com_config/tmpl/config/default_metadata.php
Normal file
33
components/com_config/tmpl/config/default_metadata.php
Normal file
@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Joomla.Site
|
||||
* @subpackage com_config
|
||||
*
|
||||
* @copyright (C) 2013 Open Source Matters, Inc. <https://www.joomla.org>
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
use Joomla\CMS\Language\Text;
|
||||
|
||||
/** @var \Joomla\Component\Config\Site\View\Config\HtmlView $this */
|
||||
?>
|
||||
<fieldset>
|
||||
|
||||
<legend><?php echo Text::_('COM_CONFIG_METADATA_SETTINGS'); ?></legend>
|
||||
|
||||
<?php foreach ($this->form->getFieldset('metadata') as $field) : ?>
|
||||
<div class="mb-3">
|
||||
<?php echo $field->label; ?>
|
||||
<?php echo $field->input; ?>
|
||||
<?php if ($field->description) : ?>
|
||||
<div class="form-text hide-aware-inline-help d-none" id="<?php echo $field->id ?>-desc">
|
||||
<?php echo Text::_($field->description) ?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
<?php endforeach; ?>
|
||||
|
||||
</fieldset>
|
||||
33
components/com_config/tmpl/config/default_seo.php
Normal file
33
components/com_config/tmpl/config/default_seo.php
Normal file
@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Joomla.Site
|
||||
* @subpackage com_config
|
||||
*
|
||||
* @copyright (C) 2013 Open Source Matters, Inc. <https://www.joomla.org>
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
use Joomla\CMS\Language\Text;
|
||||
|
||||
/** @var \Joomla\Component\Config\Site\View\Config\HtmlView $this */
|
||||
?>
|
||||
<fieldset>
|
||||
|
||||
<legend><?php echo Text::_('COM_CONFIG_SEO_SETTINGS'); ?></legend>
|
||||
|
||||
<?php foreach ($this->form->getFieldset('seo') as $field) : ?>
|
||||
<div class="mb-3">
|
||||
<?php echo $field->label; ?>
|
||||
<?php echo $field->input; ?>
|
||||
<?php if ($field->description) : ?>
|
||||
<div class="form-text hide-aware-inline-help d-none" id="<?php echo $field->id ?>-desc">
|
||||
<?php echo Text::_($field->description) ?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
<?php endforeach; ?>
|
||||
|
||||
</fieldset>
|
||||
33
components/com_config/tmpl/config/default_site.php
Normal file
33
components/com_config/tmpl/config/default_site.php
Normal file
@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Joomla.Site
|
||||
* @subpackage com_config
|
||||
*
|
||||
* @copyright (C) 2013 Open Source Matters, Inc. <https://www.joomla.org>
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
use Joomla\CMS\Language\Text;
|
||||
|
||||
/** @var \Joomla\Component\Config\Site\View\Config\HtmlView $this */
|
||||
?>
|
||||
<fieldset>
|
||||
|
||||
<legend><?php echo Text::_('COM_CONFIG_SITE_SETTINGS'); ?></legend>
|
||||
|
||||
<?php foreach ($this->form->getFieldset('site') as $field) : ?>
|
||||
<div class="mb-3">
|
||||
<?php echo $field->label; ?>
|
||||
<?php echo $field->input; ?>
|
||||
<?php if ($field->description) : ?>
|
||||
<div class="form-text hide-aware-inline-help d-none" id="<?php echo $field->id ?>-desc">
|
||||
<?php echo Text::_($field->description) ?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
<?php endforeach; ?>
|
||||
|
||||
</fieldset>
|
||||
188
components/com_config/tmpl/modules/default.php
Normal file
188
components/com_config/tmpl/modules/default.php
Normal file
@ -0,0 +1,188 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Joomla.Site
|
||||
* @subpackage com_config
|
||||
*
|
||||
* @copyright (C) 2014 Open Source Matters, Inc. <https://www.joomla.org>
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
use Joomla\CMS\Factory;
|
||||
use Joomla\CMS\HTML\HTMLHelper;
|
||||
use Joomla\CMS\Language\Multilanguage;
|
||||
use Joomla\CMS\Language\Text;
|
||||
use Joomla\CMS\Router\Route;
|
||||
|
||||
HTMLHelper::_('behavior.combobox');
|
||||
|
||||
/** @var \Joomla\Component\Config\Site\View\Modules\HtmlView $this */
|
||||
/** @var Joomla\CMS\WebAsset\WebAssetManager $wa */
|
||||
$wa = $this->getDocument()->getWebAssetManager();
|
||||
$wa->useScript('keepalive')
|
||||
->useScript('form.validate')
|
||||
->useScript('com_config.modules');
|
||||
|
||||
$editorText = false;
|
||||
$moduleXml = JPATH_SITE . '/modules/' . $this->item['module'] . '/' . $this->item['module'] . '.xml';
|
||||
|
||||
if (is_file($moduleXml)) {
|
||||
$xml = simplexml_load_file($moduleXml);
|
||||
|
||||
if (isset($xml->customContent)) {
|
||||
$editorText = true;
|
||||
}
|
||||
}
|
||||
|
||||
// If multi-language site, make language read-only
|
||||
if (Multilanguage::isEnabled()) {
|
||||
$this->form->setFieldAttribute('language', 'readonly', 'true');
|
||||
}
|
||||
?>
|
||||
|
||||
<form action="<?php echo Route::_('index.php?option=com_config'); ?>" method="post" name="adminForm" id="modules-form" class="form-validate">
|
||||
<div class="row">
|
||||
<div class="col-md-12">
|
||||
<legend><?php echo Text::_('COM_CONFIG_MODULES_SETTINGS_TITLE'); ?></legend>
|
||||
|
||||
<div>
|
||||
<?php echo Text::_('COM_CONFIG_MODULES_MODULE_NAME'); ?>
|
||||
<span class="badge bg-secondary"><?php echo $this->item['title']; ?></span>
|
||||
|
||||
<?php echo Text::_('COM_CONFIG_MODULES_MODULE_TYPE'); ?>
|
||||
<span class="badge bg-secondary"><?php echo $this->item['module']; ?></span>
|
||||
</div>
|
||||
<hr>
|
||||
|
||||
<div class="row mb-4">
|
||||
<div class="col-md-12">
|
||||
|
||||
<div class="control-group">
|
||||
<div class="control-label">
|
||||
<?php echo $this->form->getLabel('title'); ?>
|
||||
</div>
|
||||
<div class="controls">
|
||||
<?php echo $this->form->getInput('title'); ?>
|
||||
</div>
|
||||
</div>
|
||||
<div class="control-group">
|
||||
<div class="control-label">
|
||||
<?php echo $this->form->getLabel('showtitle'); ?>
|
||||
</div>
|
||||
<div class="controls">
|
||||
<?php echo $this->form->getInput('showtitle'); ?>
|
||||
</div>
|
||||
</div>
|
||||
<div class="control-group">
|
||||
<div class="control-label">
|
||||
<?php echo $this->form->getLabel('position'); ?>
|
||||
</div>
|
||||
<div class="controls">
|
||||
<?php echo $this->form->getInput('position'); ?>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<hr>
|
||||
|
||||
<?php if ($this->getCurrentUser()->authorise('core.edit.state', 'com_modules.module.' . $this->item['id'])) : ?>
|
||||
<div class="control-group">
|
||||
<div class="control-label">
|
||||
<?php echo $this->form->getLabel('published'); ?>
|
||||
</div>
|
||||
<div class="controls">
|
||||
<?php echo $this->form->getInput('published'); ?>
|
||||
</div>
|
||||
</div>
|
||||
<?php endif ?>
|
||||
|
||||
<div class="control-group">
|
||||
<div class="control-label">
|
||||
<?php echo $this->form->getLabel('publish_up'); ?>
|
||||
</div>
|
||||
<div class="controls">
|
||||
<?php echo $this->form->getInput('publish_up'); ?>
|
||||
</div>
|
||||
</div>
|
||||
<div class="control-group">
|
||||
<div class="control-label">
|
||||
<?php echo $this->form->getLabel('publish_down'); ?>
|
||||
</div>
|
||||
<div class="controls">
|
||||
<?php echo $this->form->getInput('publish_down'); ?>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="control-group">
|
||||
<div class="control-label">
|
||||
<?php echo $this->form->getLabel('access'); ?>
|
||||
</div>
|
||||
<div class="controls">
|
||||
<?php echo $this->form->getInput('access'); ?>
|
||||
</div>
|
||||
</div>
|
||||
<div class="control-group">
|
||||
<div class="control-label">
|
||||
<?php echo $this->form->getLabel('ordering'); ?>
|
||||
</div>
|
||||
<div class="controls">
|
||||
<?php echo $this->form->getInput('ordering'); ?>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php if (Multilanguage::isEnabled()) : ?>
|
||||
<div class="control-group">
|
||||
<div class="control-label">
|
||||
<?php echo $this->form->getLabel('language'); ?>
|
||||
</div>
|
||||
<div class="controls">
|
||||
<?php echo $this->form->getInput('language'); ?>
|
||||
</div>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<div class="control-group">
|
||||
<div class="control-label">
|
||||
<?php echo $this->form->getLabel('note'); ?>
|
||||
</div>
|
||||
<div class="controls">
|
||||
<?php echo $this->form->getInput('note'); ?>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<hr>
|
||||
|
||||
<div id="options">
|
||||
<?php echo $this->loadTemplate('options'); ?>
|
||||
</div>
|
||||
|
||||
<?php if ($editorText) : ?>
|
||||
<div class="mt-2" id="custom">
|
||||
<?php echo $this->form->getInput('content'); ?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
|
||||
<input type="hidden" name="id" value="<?php echo $this->item['id']; ?>">
|
||||
<input type="hidden" name="return" value="<?php echo Factory::getApplication()->getInput()->get('return', null, 'base64'); ?>">
|
||||
<input type="hidden" name="task" value="">
|
||||
<?php echo HTMLHelper::_('form.token'); ?>
|
||||
</div>
|
||||
<div class="d-grid gap-2 d-sm-block mb-2">
|
||||
<button type="button" class="btn btn-primary" data-submit-task="modules.apply">
|
||||
<span class="icon-check" aria-hidden="true"></span>
|
||||
<?php echo Text::_('JAPPLY'); ?>
|
||||
</button>
|
||||
<button type="button" class="btn btn-primary" data-submit-task="modules.save">
|
||||
<span class="icon-check" aria-hidden="true"></span>
|
||||
<?php echo Text::_('JSAVE'); ?>
|
||||
</button>
|
||||
<button type="button" class="btn btn-danger" data-submit-task="modules.cancel">
|
||||
<span class="icon-times" aria-hidden="true"></span>
|
||||
<?php echo Text::_('JCANCEL'); ?>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
49
components/com_config/tmpl/modules/default_options.php
Normal file
49
components/com_config/tmpl/modules/default_options.php
Normal file
@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Joomla.Site
|
||||
* @subpackage com_config
|
||||
*
|
||||
* @copyright (C) 2014 Open Source Matters, Inc. <https://www.joomla.org>
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
use Joomla\CMS\HTML\HTMLHelper;
|
||||
use Joomla\CMS\Language\Multilanguage;
|
||||
use Joomla\CMS\Language\Text;
|
||||
|
||||
/** @var \Joomla\Component\Config\Site\View\Modules\HtmlView $this */
|
||||
$fieldSets = $this->form->getFieldsets('params');
|
||||
|
||||
echo HTMLHelper::_('bootstrap.startAccordion', 'collapseTypes');
|
||||
$i = 0;
|
||||
|
||||
foreach ($fieldSets as $name => $fieldSet) :
|
||||
$label = !empty($fieldSet->label) ? $fieldSet->label : 'COM_MODULES_' . strtoupper($name) . '_FIELDSET_LABEL';
|
||||
$class = isset($fieldSet->class) && !empty($fieldSet->class) ? $fieldSet->class : '';
|
||||
|
||||
|
||||
if (isset($fieldSet->description) && trim($fieldSet->description)) :
|
||||
echo '<p class="tip">' . $this->escape(Text::_($fieldSet->description)) . '</p>';
|
||||
endif;
|
||||
?>
|
||||
<?php echo HTMLHelper::_('bootstrap.addSlide', 'collapseTypes', Text::_($label), 'collapse' . ($i++)); ?>
|
||||
|
||||
<ul class="nav flex-column">
|
||||
<?php foreach ($this->form->getFieldset($name) as $field) : ?>
|
||||
<li>
|
||||
<?php // If multi-language site, make menu-type selection read-only ?>
|
||||
<?php if (Multilanguage::isEnabled() && $this->item['module'] === 'mod_menu' && $field->getAttribute('name') === 'menutype') : ?>
|
||||
<?php $field->readonly = true; ?>
|
||||
<?php endif; ?>
|
||||
<?php echo $field->renderField(); ?>
|
||||
</li>
|
||||
|
||||
<?php endforeach; ?>
|
||||
</ul>
|
||||
|
||||
<?php echo HTMLHelper::_('bootstrap.endSlide'); ?>
|
||||
<?php endforeach; ?>
|
||||
<?php echo HTMLHelper::_('bootstrap.endAccordion'); ?>
|
||||
62
components/com_config/tmpl/templates/default.php
Normal file
62
components/com_config/tmpl/templates/default.php
Normal file
@ -0,0 +1,62 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Joomla.Site
|
||||
* @subpackage com_config
|
||||
*
|
||||
* @copyright (C) 2013 Open Source Matters, Inc. <https://www.joomla.org>
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
use Joomla\CMS\HTML\HTMLHelper;
|
||||
use Joomla\CMS\Language\Text;
|
||||
use Joomla\CMS\Router\Route;
|
||||
|
||||
/** @var \Joomla\Component\Config\Site\View\Templates\HtmlView $this */
|
||||
$user = $this->getCurrentUser();
|
||||
|
||||
/** @var Joomla\CMS\WebAsset\WebAssetManager $wa */
|
||||
$wa = $this->getDocument()->getWebAssetManager();
|
||||
$wa->useScript('keepalive')
|
||||
->useScript('form.validate')
|
||||
->useScript('com_config.templates');
|
||||
|
||||
?>
|
||||
<?php if ($this->params->get('show_page_heading')) : ?>
|
||||
<div class="page-header">
|
||||
<h1>
|
||||
<?php if ($this->escape($this->params->get('page_heading'))) : ?>
|
||||
<?php echo $this->escape($this->params->get('page_heading')); ?>
|
||||
<?php else : ?>
|
||||
<?php echo $this->escape($this->params->get('page_title')); ?>
|
||||
<?php endif; ?>
|
||||
</h1>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
<form action="<?php echo Route::_('index.php?option=com_config'); ?>" method="post" name="adminForm" id="templates-form" class="form-validate">
|
||||
|
||||
<div id="page-site" class="tab-pane active">
|
||||
<div class="row">
|
||||
<div class="col-md-12">
|
||||
<?php echo $this->loadTemplate('options'); ?>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<input type="hidden" name="task" value="">
|
||||
<?php echo HTMLHelper::_('form.token'); ?>
|
||||
|
||||
<div class="d-grid gap-2 d-sm-block mb-2">
|
||||
<button type="button" class="btn btn-primary " data-submit-task="templates.apply">
|
||||
<span class="icon-check text-white" aria-hidden="true"></span>
|
||||
<?php echo Text::_('JSAVE') ?>
|
||||
</button>
|
||||
<button type="button" class="btn btn-danger" data-submit-task="templates.cancel">
|
||||
<span class="icon-times text-white" aria-hidden="true"></span>
|
||||
<?php echo Text::_('JCANCEL') ?>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
</form>
|
||||
20
components/com_config/tmpl/templates/default.xml
Normal file
20
components/com_config/tmpl/templates/default.xml
Normal file
@ -0,0 +1,20 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<metadata>
|
||||
<layout title="COM_CONFIG_TEMPLATES_VIEW_DEFAULT_TITLE" option="COM_CONFIG_TEMPLATES_VIEW_DEFAULT_OPTION">
|
||||
<help
|
||||
key = "Menu_Item:_Display_Template_Options"
|
||||
/>
|
||||
<message>
|
||||
<![CDATA[COM_CONFIG_TEMPLATES_VIEW_DEFAULT_DESC]]>
|
||||
</message>
|
||||
</layout>
|
||||
<fields name="request">
|
||||
<fieldset name="request" >
|
||||
<field
|
||||
name="controller"
|
||||
type="hidden"
|
||||
default=""
|
||||
/>
|
||||
</fieldset>
|
||||
</fields>
|
||||
</metadata>
|
||||
37
components/com_config/tmpl/templates/default_options.php
Normal file
37
components/com_config/tmpl/templates/default_options.php
Normal file
@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Joomla.Site
|
||||
* @subpackage com_config
|
||||
*
|
||||
* @copyright (C) 2013 Open Source Matters, Inc. <https://www.joomla.org>
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
use Joomla\CMS\Language\Text;
|
||||
|
||||
/** @var \Joomla\Component\Config\Site\View\Templates\HtmlView $this */
|
||||
$fieldSets = $this->form->getFieldsets('params');
|
||||
?>
|
||||
|
||||
<legend><?php echo Text::_('COM_CONFIG_TEMPLATE_SETTINGS'); ?></legend>
|
||||
|
||||
<?php
|
||||
|
||||
// Search for com_config field set
|
||||
if (!empty($fieldSets['com_config'])) {
|
||||
echo $this->form->renderFieldset('com_config');
|
||||
} else {
|
||||
// Fall-back to display all in params
|
||||
foreach ($fieldSets as $name => $fieldSet) {
|
||||
$label = !empty($fieldSet->label) ? $fieldSet->label : 'COM_CONFIG_' . $name . '_FIELDSET_LABEL';
|
||||
|
||||
if (isset($fieldSet->description) && trim($fieldSet->description)) {
|
||||
echo '<p class="tip">' . $this->escape(Text::_($fieldSet->description)) . '</p>';
|
||||
}
|
||||
|
||||
echo $this->form->renderFieldset($name);
|
||||
}
|
||||
}
|
||||
74
components/com_contact/forms/contact.xml
Normal file
74
components/com_contact/forms/contact.xml
Normal file
@ -0,0 +1,74 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<form>
|
||||
<fieldset name="contact" addruleprefix="Joomla\Component\Contact\Site\Rule" label="COM_CONTACT_CONTACT_DEFAULT_LABEL">
|
||||
<field
|
||||
name="spacer"
|
||||
type="spacer"
|
||||
label="COM_CONTACT_CONTACT_REQUIRED"
|
||||
class="text"
|
||||
/>
|
||||
|
||||
<field
|
||||
name="contact_name"
|
||||
type="text"
|
||||
label="COM_CONTACT_CONTACT_EMAIL_NAME_LABEL"
|
||||
id="contact-name"
|
||||
size="30"
|
||||
filter="string"
|
||||
required="true"
|
||||
/>
|
||||
|
||||
<field
|
||||
name="contact_email"
|
||||
type="email"
|
||||
label="COM_CONTACT_EMAIL_LABEL"
|
||||
id="contact-email"
|
||||
size="30"
|
||||
filter="string"
|
||||
validate="ContactEmail"
|
||||
autocomplete="email"
|
||||
required="true"
|
||||
/>
|
||||
|
||||
<field
|
||||
name="contact_subject"
|
||||
type="text"
|
||||
label="COM_CONTACT_CONTACT_MESSAGE_SUBJECT_LABEL"
|
||||
id="contact-emailmsg"
|
||||
size="60"
|
||||
filter="string"
|
||||
validate="ContactEmailSubject"
|
||||
required="true"
|
||||
/>
|
||||
|
||||
<field
|
||||
name="contact_message"
|
||||
type="textarea"
|
||||
label="COM_CONTACT_CONTACT_ENTER_MESSAGE_LABEL"
|
||||
cols="50"
|
||||
rows="10"
|
||||
id="contact-message"
|
||||
filter="safehtml"
|
||||
validate="ContactEmailMessage"
|
||||
required="true"
|
||||
/>
|
||||
|
||||
<field
|
||||
name="contact_email_copy"
|
||||
type="checkbox"
|
||||
label="COM_CONTACT_CONTACT_EMAIL_A_COPY_LABEL"
|
||||
id="contact-email-copy"
|
||||
default="0"
|
||||
/>
|
||||
</fieldset>
|
||||
|
||||
<fieldset name="captcha">
|
||||
<field
|
||||
name="captcha"
|
||||
type="captcha"
|
||||
label="COM_CONTACT_CAPTCHA_LABEL"
|
||||
validate="captcha"
|
||||
namespace="contact"
|
||||
/>
|
||||
</fieldset>
|
||||
</form>
|
||||
120
components/com_contact/forms/filter_contacts.xml
Normal file
120
components/com_contact/forms/filter_contacts.xml
Normal file
@ -0,0 +1,120 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<form>
|
||||
<fields name="filter">
|
||||
|
||||
<field
|
||||
name="search"
|
||||
type="text"
|
||||
inputmode="search"
|
||||
label="COM_CONTACT_FILTER_SEARCH_LABEL"
|
||||
description="COM_CONTACT_FILTER_SEARCH_DESC"
|
||||
hint="JSEARCH_FILTER"
|
||||
/>
|
||||
|
||||
<field
|
||||
name="published"
|
||||
type="status"
|
||||
label="JSTATUS"
|
||||
onchange="this.form.submit();"
|
||||
>
|
||||
<option value="">JOPTION_SELECT_PUBLISHED</option>
|
||||
</field>
|
||||
|
||||
<field
|
||||
name="category_id"
|
||||
type="category"
|
||||
label="JCATEGORY"
|
||||
multiple="true"
|
||||
extension="com_contact"
|
||||
layout="joomla.form.field.list-fancy-select"
|
||||
hint="JOPTION_SELECT_CATEGORY"
|
||||
onchange="this.form.submit();"
|
||||
published="0,1,2"
|
||||
/>
|
||||
|
||||
<field
|
||||
name="access"
|
||||
type="accesslevel"
|
||||
label="JGRID_HEADING_ACCESS"
|
||||
onchange="this.form.submit();"
|
||||
>
|
||||
<option value="">JOPTION_SELECT_ACCESS</option>
|
||||
</field>
|
||||
|
||||
<field
|
||||
name="language"
|
||||
type="contentlanguage"
|
||||
label="JGRID_HEADING_LANGUAGE"
|
||||
onchange="this.form.submit();"
|
||||
>
|
||||
<option value="">JOPTION_SELECT_LANGUAGE</option>
|
||||
<option value="*">JALL</option>
|
||||
</field>
|
||||
|
||||
<field
|
||||
name="tag"
|
||||
type="tag"
|
||||
label="JTAG"
|
||||
multiple="true"
|
||||
mode="nested"
|
||||
custom="false"
|
||||
hint="JOPTION_SELECT_TAG"
|
||||
onchange="this.form.submit();"
|
||||
/>
|
||||
|
||||
<field
|
||||
name="level"
|
||||
type="integer"
|
||||
label="JGLOBAL_MAXLEVEL_LABEL"
|
||||
first="1"
|
||||
last="10"
|
||||
step="1"
|
||||
languages="*"
|
||||
onchange="this.form.submit();"
|
||||
>
|
||||
<option value="">JOPTION_SELECT_MAX_LEVELS</option>
|
||||
</field>
|
||||
</fields>
|
||||
|
||||
<fields name="list">
|
||||
|
||||
<field
|
||||
name="fullordering"
|
||||
type="list"
|
||||
label="JGLOBAL_SORT_BY"
|
||||
default="a.name ASC"
|
||||
onchange="this.form.submit();"
|
||||
validate="options"
|
||||
>
|
||||
<option value="">JGLOBAL_SORT_BY</option>
|
||||
<option value="a.ordering ASC">JGRID_HEADING_ORDERING_ASC</option>
|
||||
<option value="a.ordering DESC">JGRID_HEADING_ORDERING_DESC</option>
|
||||
<option value="a.published ASC">JSTATUS_ASC</option>
|
||||
<option value="a.published DESC">JSTATUS_DESC</option>
|
||||
<option value="a.featured ASC">JFEATURED_ASC</option>
|
||||
<option value="a.featured DESC">JFEATURED_DESC</option>
|
||||
<option value="a.name ASC">JGLOBAL_NAME_ASC</option>
|
||||
<option value="a.name DESC">JGLOBAL_NAME_DESC</option>
|
||||
<option value="category_title ASC">JCATEGORY_ASC</option>
|
||||
<option value="category_title DESC">JCATEGORY_DESC</option>
|
||||
<option value="ul.name ASC">COM_CONTACT_FIELD_LINKED_USER_LABEL_ASC</option>
|
||||
<option value="ul.name DESC">COM_CONTACT_FIELD_LINKED_USER_LABEL_DESC</option>
|
||||
<option value="access_level ASC">JGRID_HEADING_ACCESS_ASC</option>
|
||||
<option value="access_level DESC">JGRID_HEADING_ACCESS_DESC</option>
|
||||
<option value="association ASC" requires="associations">JASSOCIATIONS_ASC</option>
|
||||
<option value="association DESC" requires="associations">JASSOCIATIONS_DESC</option>
|
||||
<option value="language_title ASC" requires="multilanguage">JGRID_HEADING_LANGUAGE_ASC</option>
|
||||
<option value="language_title DESC" requires="multilanguage">JGRID_HEADING_LANGUAGE_DESC</option>
|
||||
<option value="a.id ASC">JGRID_HEADING_ID_ASC</option>
|
||||
<option value="a.id DESC">JGRID_HEADING_ID_DESC</option>
|
||||
</field>
|
||||
|
||||
<field
|
||||
name="limit"
|
||||
type="limitbox"
|
||||
label="JGLOBAL_LIST_LIMIT"
|
||||
default="25"
|
||||
onchange="this.form.submit();"
|
||||
/>
|
||||
</fields>
|
||||
</form>
|
||||
351
components/com_contact/forms/form.xml
Normal file
351
components/com_contact/forms/form.xml
Normal file
@ -0,0 +1,351 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<form>
|
||||
<fieldset>
|
||||
<field
|
||||
name="id"
|
||||
type="number"
|
||||
label="JGLOBAL_FIELD_ID_LABEL"
|
||||
default="0"
|
||||
class="readonly"
|
||||
size="10"
|
||||
readonly="true"
|
||||
/>
|
||||
|
||||
<field
|
||||
name="name"
|
||||
type="text"
|
||||
label="COM_CONTACT_FIELD_NAME_LABEL"
|
||||
size="40"
|
||||
required="true"
|
||||
/>
|
||||
|
||||
<field
|
||||
name="alias"
|
||||
type="text"
|
||||
label="JFIELD_ALIAS_LABEL"
|
||||
description="JFIELD_ALIAS_DESC"
|
||||
size="45"
|
||||
hint="JFIELD_ALIAS_PLACEHOLDER"
|
||||
/>
|
||||
|
||||
<field
|
||||
name="misc"
|
||||
type="editor"
|
||||
label="COM_CONTACT_FIELD_INFORMATION_MISC_LABEL"
|
||||
filter="\Joomla\CMS\Component\ComponentHelper::filterText"
|
||||
buttons="true"
|
||||
hide="readmore,pagebreak"
|
||||
/>
|
||||
|
||||
<field
|
||||
name="created_by"
|
||||
type="user"
|
||||
label="JGLOBAL_FIELD_CREATED_BY_LABEL"
|
||||
validate="UserId"
|
||||
/>
|
||||
|
||||
<field
|
||||
name="created"
|
||||
type="calendar"
|
||||
label="COM_CONTACT_FIELD_CREATED_LABEL"
|
||||
size="22"
|
||||
translateformat="true"
|
||||
showtime="true"
|
||||
filter="user_utc"
|
||||
/>
|
||||
|
||||
<field
|
||||
name="modified"
|
||||
type="calendar"
|
||||
label="JGLOBAL_FIELD_MODIFIED_LABEL"
|
||||
class="readonly"
|
||||
size="22"
|
||||
readonly="true"
|
||||
translateformat="true"
|
||||
showtime="true"
|
||||
filter="user_utc"
|
||||
/>
|
||||
|
||||
<field
|
||||
name="modified_by"
|
||||
type="user"
|
||||
label="JGLOBAL_FIELD_MODIFIED_BY_LABEL"
|
||||
class="readonly"
|
||||
readonly="true"
|
||||
filter="unset"
|
||||
validate="UserId"
|
||||
/>
|
||||
|
||||
<field
|
||||
name="checked_out"
|
||||
type="hidden"
|
||||
filter="unset"
|
||||
/>
|
||||
|
||||
<field
|
||||
name="checked_out_time"
|
||||
type="hidden"
|
||||
filter="unset"
|
||||
/>
|
||||
|
||||
<field
|
||||
name="ordering"
|
||||
type="ordering"
|
||||
label="JFIELD_ORDERING_LABEL"
|
||||
content_type="com_contact.contact"
|
||||
/>
|
||||
|
||||
<field
|
||||
name="contenthistory"
|
||||
type="contenthistory"
|
||||
label="JTOOLBAR_VERSIONS"
|
||||
data-typeAlias="com_contact.contact"
|
||||
/>
|
||||
|
||||
</fieldset>
|
||||
|
||||
<fieldset
|
||||
name="details"
|
||||
label="COM_CONTACT_CONTACT_DETAILS"
|
||||
>
|
||||
<field
|
||||
name="image"
|
||||
type="media"
|
||||
schemes="http,https,ftp,ftps,data,file"
|
||||
validate="url"
|
||||
relative="true"
|
||||
label="COM_CONTACT_FIELD_PARAMS_IMAGE_LABEL"
|
||||
hide_none="1"
|
||||
/>
|
||||
|
||||
<field
|
||||
name="con_position"
|
||||
type="text"
|
||||
label="COM_CONTACT_FIELD_INFORMATION_POSITION_LABEL"
|
||||
size="30"
|
||||
/>
|
||||
|
||||
<field
|
||||
name="email_to"
|
||||
type="email"
|
||||
label="JGLOBAL_EMAIL"
|
||||
size="30"
|
||||
/>
|
||||
|
||||
<field
|
||||
name="address"
|
||||
type="textarea"
|
||||
label="COM_CONTACT_FIELD_INFORMATION_ADDRESS_LABEL"
|
||||
rows="3"
|
||||
cols="30"
|
||||
/>
|
||||
|
||||
<field
|
||||
name="suburb"
|
||||
type="text"
|
||||
label="COM_CONTACT_FIELD_INFORMATION_SUBURB_LABEL"
|
||||
size="30"
|
||||
/>
|
||||
|
||||
<field
|
||||
name="state"
|
||||
type="text"
|
||||
label="COM_CONTACT_FIELD_INFORMATION_STATE_LABEL"
|
||||
size="30"
|
||||
/>
|
||||
|
||||
<field
|
||||
name="postcode"
|
||||
type="text"
|
||||
label="COM_CONTACT_FIELD_INFORMATION_POSTCODE_LABEL"
|
||||
size="30"
|
||||
/>
|
||||
|
||||
<field
|
||||
name="country"
|
||||
type="text"
|
||||
label="COM_CONTACT_FIELD_INFORMATION_COUNTRY_LABEL"
|
||||
size="30"
|
||||
/>
|
||||
|
||||
<field
|
||||
name="telephone"
|
||||
type="text"
|
||||
label="COM_CONTACT_FIELD_INFORMATION_TELEPHONE_LABEL"
|
||||
size="30"
|
||||
/>
|
||||
|
||||
<field
|
||||
name="mobile"
|
||||
type="text"
|
||||
label="COM_CONTACT_FIELD_INFORMATION_MOBILE_LABEL"
|
||||
size="30"
|
||||
/>
|
||||
|
||||
<field
|
||||
name="fax"
|
||||
type="text"
|
||||
label="COM_CONTACT_FIELD_INFORMATION_FAX_LABEL"
|
||||
size="30"
|
||||
/>
|
||||
|
||||
<field
|
||||
name="webpage"
|
||||
type="url"
|
||||
label="COM_CONTACT_FIELD_INFORMATION_WEBPAGE_LABEL"
|
||||
size="30"
|
||||
filter="url"
|
||||
/>
|
||||
|
||||
<field
|
||||
name="sortname1"
|
||||
type="text"
|
||||
label="COM_CONTACT_FIELD_SORTNAME1_LABEL"
|
||||
size="30"
|
||||
/>
|
||||
|
||||
<field
|
||||
name="sortname2"
|
||||
type="text"
|
||||
label="COM_CONTACT_FIELD_SORTNAME2_LABEL"
|
||||
size="30"
|
||||
/>
|
||||
|
||||
<field
|
||||
name="sortname3"
|
||||
type="text"
|
||||
label="COM_CONTACT_FIELD_SORTNAME3_LABEL"
|
||||
size="30"
|
||||
/>
|
||||
</fieldset>
|
||||
|
||||
<fieldset
|
||||
name="publishing"
|
||||
label="COM_CONTACT_FIELDSET_PUBLISHING"
|
||||
>
|
||||
<field
|
||||
name="catid"
|
||||
type="categoryedit"
|
||||
label="JCATEGORY"
|
||||
extension="com_contact"
|
||||
addfieldprefix="Joomla\Component\Categories\Administrator\Field"
|
||||
required="true"
|
||||
default=""
|
||||
/>
|
||||
|
||||
<field
|
||||
name="tags"
|
||||
type="tag"
|
||||
label="JTAG"
|
||||
multiple="true"
|
||||
/>
|
||||
|
||||
<field
|
||||
name="version_note"
|
||||
type="text"
|
||||
label="JGLOBAL_FIELD_VERSION_NOTE_LABEL"
|
||||
labelclass="control-label"
|
||||
class=""
|
||||
size="45"
|
||||
maxlength="255"
|
||||
/>
|
||||
|
||||
<field
|
||||
name="created_by_alias"
|
||||
type="text"
|
||||
label="COM_CONTACT_FIELD_CREATED_BY_ALIAS_LABEL"
|
||||
size="20"
|
||||
/>
|
||||
|
||||
<field
|
||||
name="published"
|
||||
type="list"
|
||||
label="JSTATUS"
|
||||
default="1"
|
||||
class="form-select-color-state"
|
||||
size="1"
|
||||
validate="options"
|
||||
>
|
||||
<option value="1">JPUBLISHED</option>
|
||||
<option value="0">JUNPUBLISHED</option>
|
||||
<option value="2">JARCHIVED</option>
|
||||
<option value="-2">JTRASHED</option>
|
||||
|
||||
</field>
|
||||
|
||||
<field
|
||||
name="featured"
|
||||
type="list"
|
||||
label="JFEATURED"
|
||||
default="0"
|
||||
validate="options"
|
||||
>
|
||||
<option value="0">JNO</option>
|
||||
<option value="1">JYES</option>
|
||||
</field>
|
||||
|
||||
<field
|
||||
name="publish_up"
|
||||
type="calendar"
|
||||
label="COM_CONTACT_FIELD_PUBLISH_UP_LABEL"
|
||||
translateformat="true"
|
||||
showtime="true"
|
||||
size="22"
|
||||
filter="user_utc"
|
||||
/>
|
||||
|
||||
<field
|
||||
name="publish_down"
|
||||
type="calendar"
|
||||
label="COM_CONTACT_FIELD_PUBLISH_DOWN_LABEL"
|
||||
translateformat="true"
|
||||
showtime="true"
|
||||
size="22"
|
||||
filter="user_utc"
|
||||
/>
|
||||
|
||||
<field
|
||||
name="access"
|
||||
type="accesslevel"
|
||||
label="JFIELD_ACCESS_LABEL"
|
||||
filter="UINT"
|
||||
validate="options"
|
||||
/>
|
||||
</fieldset>
|
||||
|
||||
<fieldset
|
||||
name="language"
|
||||
label="JFIELD_LANGUAGE_LABEL"
|
||||
>
|
||||
<field
|
||||
name="language"
|
||||
type="contentlanguage"
|
||||
label="JFIELD_LANGUAGE_LABEL"
|
||||
>
|
||||
<option value="*">JALL</option>
|
||||
</field>
|
||||
</fieldset>
|
||||
|
||||
<fieldset
|
||||
name="metadata"
|
||||
label="COM_CONTACT_FIELDSET_METADATA"
|
||||
>
|
||||
<field
|
||||
name="metadesc"
|
||||
type="textarea"
|
||||
label="JFIELD_META_DESCRIPTION_LABEL"
|
||||
rows="3"
|
||||
cols="30"
|
||||
maxlength="300"
|
||||
charcounter="true"
|
||||
/>
|
||||
|
||||
<field
|
||||
name="metakey"
|
||||
type="textarea"
|
||||
label="JFIELD_META_KEYWORDS_LABEL"
|
||||
rows="3"
|
||||
cols="30"
|
||||
/>
|
||||
</fieldset>
|
||||
</form>
|
||||
33
components/com_contact/helpers/route.php
Normal file
33
components/com_contact/helpers/route.php
Normal file
@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Joomla.Site
|
||||
* @subpackage com_contact
|
||||
*
|
||||
* @copyright (C) 2009 Open Source Matters, Inc. <https://www.joomla.org>
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*
|
||||
* @phpcs:disable PSR1.Classes.ClassDeclaration.MissingNamespace
|
||||
*/
|
||||
|
||||
use Joomla\Component\Contact\Site\Helper\RouteHelper;
|
||||
|
||||
// phpcs:disable PSR1.Files.SideEffects
|
||||
\defined('_JEXEC') or die;
|
||||
// phpcs:enable PSR1.Files.SideEffects
|
||||
|
||||
/**
|
||||
* Contact Component Route Helper
|
||||
*
|
||||
* @static
|
||||
* @package Joomla.Site
|
||||
* @subpackage com_contact
|
||||
* @since 1.5
|
||||
*
|
||||
* @deprecated 4.3 will be removed in 6.0
|
||||
* Use \Joomla\Component\Contact\Site\Helper\RouteHelper instead
|
||||
* Example: RouteHelper::method();
|
||||
*/
|
||||
abstract class ContactHelperRoute extends RouteHelper
|
||||
{
|
||||
}
|
||||
29
components/com_contact/layouts/field/render.php
Normal file
29
components/com_contact/layouts/field/render.php
Normal file
@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Joomla.Site
|
||||
* @subpackage com_contact
|
||||
*
|
||||
* @copyright (C) 2016 Open Source Matters, Inc. <https://www.joomla.org>
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
use Joomla\CMS\Language\Text;
|
||||
|
||||
if (!array_key_exists('field', $displayData)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$field = $displayData['field'];
|
||||
|
||||
// Do nothing when not in mail context, like that the default rendering is used
|
||||
if ($field->context !== 'com_contact.mail') {
|
||||
return;
|
||||
}
|
||||
|
||||
// Prepare the value for the contact form mail
|
||||
$value = html_entity_decode($field->value);
|
||||
|
||||
echo ($field->params->get('showlabel') ? Text::_($field->label) . ': ' : '') . $value . "\r\n";
|
||||
57
components/com_contact/layouts/fields/render.php
Normal file
57
components/com_contact/layouts/fields/render.php
Normal file
@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Joomla.Site
|
||||
* @subpackage com_contact
|
||||
*
|
||||
* @copyright (C) 2016 Open Source Matters, Inc. <https://www.joomla.org>
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
use Joomla\Component\Fields\Administrator\Helper\FieldsHelper;
|
||||
|
||||
// Check if we have all the data
|
||||
if (!array_key_exists('item', $displayData) || !array_key_exists('context', $displayData)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Setting up for display
|
||||
$item = $displayData['item'];
|
||||
|
||||
if (!$item) {
|
||||
return;
|
||||
}
|
||||
|
||||
$context = $displayData['context'];
|
||||
|
||||
if (!$context) {
|
||||
return;
|
||||
}
|
||||
|
||||
$parts = explode('.', $context);
|
||||
$component = $parts[0];
|
||||
$fields = null;
|
||||
|
||||
if (array_key_exists('fields', $displayData)) {
|
||||
$fields = $displayData['fields'];
|
||||
} else {
|
||||
$fields = $item->jcfields ?: FieldsHelper::getFields($context, $item, true);
|
||||
}
|
||||
|
||||
// Do nothing when not in mail context, like that the default rendering is used
|
||||
if (!$fields || reset($fields)->context !== 'com_contact.mail') {
|
||||
return;
|
||||
}
|
||||
|
||||
// Loop through the fields and print them
|
||||
foreach ($fields as $field) {
|
||||
// If the value is empty do nothing
|
||||
if (!strlen($field->value)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$layout = $field->params->get('layout', 'render');
|
||||
echo FieldsHelper::render($context, 'field.' . $layout, ['field' => $field]);
|
||||
}
|
||||
459
components/com_contact/src/Controller/ContactController.php
Normal file
459
components/com_contact/src/Controller/ContactController.php
Normal file
@ -0,0 +1,459 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Joomla.Site
|
||||
* @subpackage com_contact
|
||||
*
|
||||
* @copyright (C) 2010 Open Source Matters, Inc. <https://www.joomla.org>
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace Joomla\Component\Contact\Site\Controller;
|
||||
|
||||
use Joomla\CMS\Event\Contact\SubmitContactEvent;
|
||||
use Joomla\CMS\Event\Contact\ValidateContactEvent;
|
||||
use Joomla\CMS\Factory;
|
||||
use Joomla\CMS\Language\Text;
|
||||
use Joomla\CMS\Log\Log;
|
||||
use Joomla\CMS\Mail\Exception\MailDisabledException;
|
||||
use Joomla\CMS\Mail\MailTemplate;
|
||||
use Joomla\CMS\MVC\Controller\FormController;
|
||||
use Joomla\CMS\Plugin\PluginHelper;
|
||||
use Joomla\CMS\Router\Route;
|
||||
use Joomla\CMS\String\PunycodeHelper;
|
||||
use Joomla\CMS\Uri\Uri;
|
||||
use Joomla\CMS\User\UserFactoryAwareInterface;
|
||||
use Joomla\CMS\User\UserFactoryAwareTrait;
|
||||
use Joomla\CMS\Versioning\VersionableControllerTrait;
|
||||
use Joomla\Component\Fields\Administrator\Helper\FieldsHelper;
|
||||
use Joomla\Utilities\ArrayHelper;
|
||||
use PHPMailer\PHPMailer\Exception as phpMailerException;
|
||||
|
||||
// phpcs:disable PSR1.Files.SideEffects
|
||||
\defined('_JEXEC') or die;
|
||||
// phpcs:enable PSR1.Files.SideEffects
|
||||
|
||||
/**
|
||||
* Controller for single contact view
|
||||
*
|
||||
* @since 1.5.19
|
||||
*/
|
||||
class ContactController extends FormController implements UserFactoryAwareInterface
|
||||
{
|
||||
use UserFactoryAwareTrait;
|
||||
use VersionableControllerTrait;
|
||||
|
||||
/**
|
||||
* The URL view item variable.
|
||||
*
|
||||
* @var string
|
||||
* @since 4.0.0
|
||||
*/
|
||||
protected $view_item = 'form';
|
||||
|
||||
/**
|
||||
* The URL view list variable.
|
||||
*
|
||||
* @var string
|
||||
* @since 4.0.0
|
||||
*/
|
||||
protected $view_list = 'categories';
|
||||
|
||||
/**
|
||||
* Method to get a model object, loading it if required.
|
||||
*
|
||||
* @param string $name The model name. Optional.
|
||||
* @param string $prefix The class prefix. Optional.
|
||||
* @param array $config Configuration array for model. Optional.
|
||||
*
|
||||
* @return \Joomla\CMS\MVC\Model\BaseDatabaseModel The model.
|
||||
*
|
||||
* @since 1.6.4
|
||||
*/
|
||||
public function getModel($name = 'form', $prefix = '', $config = ['ignore_request' => true])
|
||||
{
|
||||
return parent::getModel($name, $prefix, ['ignore_request' => false]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to submit the contact form and send an email.
|
||||
*
|
||||
* @return boolean True on success sending the email. False on failure.
|
||||
*
|
||||
* @since 1.5.19
|
||||
*/
|
||||
public function submit()
|
||||
{
|
||||
// Check for request forgeries.
|
||||
$this->checkToken();
|
||||
|
||||
$app = $this->app;
|
||||
$model = $this->getModel('contact');
|
||||
$stub = $this->input->getString('id');
|
||||
$id = (int) $stub;
|
||||
|
||||
// Get the data from POST
|
||||
$data = $this->input->post->get('jform', [], 'array');
|
||||
|
||||
// Get item
|
||||
$model->setState('filter.published', 1);
|
||||
$contact = $model->getItem($id);
|
||||
|
||||
if ($contact === false) {
|
||||
$this->setMessage($model->getError(), 'error');
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// Get item params, take menu parameters into account if necessary
|
||||
$active = $app->getMenu()->getActive();
|
||||
$stateParams = clone $model->getState()->get('params');
|
||||
|
||||
// If the current view is the active item and a contact view for this contact, then the menu item params take priority
|
||||
if ($active && strpos($active->link, 'view=contact') && strpos($active->link, '&id=' . (int) $contact->id)) {
|
||||
// $item->params are the contact params, $temp are the menu item params
|
||||
// Merge so that the menu item params take priority
|
||||
$contact->params->merge($stateParams);
|
||||
} else {
|
||||
// Current view is not a single contact, so the contact params take priority here
|
||||
$stateParams->merge($contact->params);
|
||||
$contact->params = $stateParams;
|
||||
}
|
||||
|
||||
// Check if the contact form is enabled
|
||||
if (!$contact->params->get('show_email_form')) {
|
||||
$this->setRedirect(Route::_('index.php?option=com_contact&view=contact&id=' . $stub . '&catid=' . $contact->catid, false));
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// Check for a valid session cookie
|
||||
if ($contact->params->get('validate_session', 0)) {
|
||||
if (Factory::getSession()->getState() !== 'active') {
|
||||
$this->app->enqueueMessage(Text::_('JLIB_ENVIRONMENT_SESSION_INVALID'), 'warning');
|
||||
|
||||
// Save the data in the session.
|
||||
$this->app->setUserState('com_contact.contact.data', $data);
|
||||
|
||||
// Redirect back to the contact form.
|
||||
$this->setRedirect(Route::_('index.php?option=com_contact&view=contact&id=' . $stub . '&catid=' . $contact->catid, false));
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Contact plugins
|
||||
PluginHelper::importPlugin('contact');
|
||||
|
||||
// Validate the posted data.
|
||||
$form = $model->getForm();
|
||||
|
||||
if (!$form) {
|
||||
throw new \Exception($model->getError(), 500);
|
||||
}
|
||||
|
||||
if (!$model->validate($form, $data)) {
|
||||
$errors = $model->getErrors();
|
||||
|
||||
foreach ($errors as $error) {
|
||||
$errorMessage = $error;
|
||||
|
||||
if ($error instanceof \Exception) {
|
||||
$errorMessage = $error->getMessage();
|
||||
}
|
||||
|
||||
$app->enqueueMessage($errorMessage, 'error');
|
||||
}
|
||||
|
||||
$app->setUserState('com_contact.contact.data', $data);
|
||||
|
||||
$this->setRedirect(Route::_('index.php?option=com_contact&view=contact&id=' . $stub . '&catid=' . $contact->catid, false));
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// Validation succeeded, continue with custom handlers
|
||||
$results = $this->getDispatcher()->dispatch('onValidateContact', new ValidateContactEvent('onValidateContact', [
|
||||
'subject' => $contact,
|
||||
'data' => &$data, // @todo: Remove reference in Joomla 6, @deprecated: Data modification onValidateContact is not allowed, use onSubmitContact instead
|
||||
]))->getArgument('result', []);
|
||||
|
||||
$passValidation = true;
|
||||
|
||||
foreach ($results as $result) {
|
||||
if ($result instanceof \Exception) {
|
||||
$passValidation = false;
|
||||
$app->enqueueMessage($result->getMessage(), 'error');
|
||||
}
|
||||
}
|
||||
|
||||
if (!$passValidation) {
|
||||
$app->setUserState('com_contact.contact.data', $data);
|
||||
|
||||
$this->setRedirect(Route::_('index.php?option=com_contact&view=contact&id=' . $id . '&catid=' . $contact->catid, false));
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// Passed Validation: Process the contact plugins to integrate with other applications
|
||||
$event = $this->getDispatcher()->dispatch('onSubmitContact', new SubmitContactEvent('onSubmitContact', [
|
||||
'subject' => $contact,
|
||||
'data' => &$data, // @todo: Remove reference in Joomla 6, see SubmitContactEvent::__constructor()
|
||||
]));
|
||||
// Get the final data
|
||||
$data = $event->getArgument('data', $data);
|
||||
|
||||
// Send the email
|
||||
$sent = false;
|
||||
|
||||
if (!$contact->params->get('custom_reply')) {
|
||||
$sent = $this->_sendEmail($data, $contact, $contact->params->get('show_email_copy', 0));
|
||||
}
|
||||
|
||||
$msg = '';
|
||||
|
||||
// Set the success message if it was a success
|
||||
if ($sent) {
|
||||
$msg = Text::_('COM_CONTACT_EMAIL_THANKS');
|
||||
}
|
||||
|
||||
// Flush the data from the session
|
||||
$this->app->setUserState('com_contact.contact.data', null);
|
||||
|
||||
// Redirect if it is set in the parameters, otherwise redirect back to where we came from
|
||||
if ($contact->params->get('redirect')) {
|
||||
$this->setRedirect($contact->params->get('redirect'), $msg);
|
||||
} else {
|
||||
$this->setRedirect(Route::_('index.php?option=com_contact&view=contact&id=' . $stub . '&catid=' . $contact->catid, false), $msg);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to get a model object, loading it if required.
|
||||
*
|
||||
* @param array $data The data to send in the email.
|
||||
* @param \stdClass $contact The user information to send the email to
|
||||
* @param boolean $emailCopyToSender True to send a copy of the email to the user.
|
||||
*
|
||||
* @return boolean True on success sending the email, false on failure.
|
||||
*
|
||||
* @since 1.6.4
|
||||
*/
|
||||
private function _sendEmail($data, $contact, $emailCopyToSender)
|
||||
{
|
||||
$app = $this->app;
|
||||
|
||||
if ($contact->email_to == '' && $contact->user_id != 0) {
|
||||
$contact_user = $this->getUserFactory()->loadUserById($contact->user_id);
|
||||
$contact->email_to = $contact_user->email;
|
||||
}
|
||||
|
||||
$templateData = [
|
||||
'sitename' => $app->get('sitename'),
|
||||
'name' => $data['contact_name'],
|
||||
'contactname' => $contact->name,
|
||||
'email' => PunycodeHelper::emailToPunycode($data['contact_email']),
|
||||
'subject' => $data['contact_subject'],
|
||||
'body' => stripslashes($data['contact_message']),
|
||||
'url' => Uri::base(),
|
||||
'customfields' => '',
|
||||
];
|
||||
|
||||
// Load the custom fields
|
||||
if (!empty($data['com_fields']) && $fields = FieldsHelper::getFields('com_contact.mail', $contact, true, $data['com_fields'])) {
|
||||
$output = FieldsHelper::render(
|
||||
'com_contact.mail',
|
||||
'fields.render',
|
||||
[
|
||||
'context' => 'com_contact.mail',
|
||||
'item' => $contact,
|
||||
'fields' => $fields,
|
||||
]
|
||||
);
|
||||
|
||||
if ($output) {
|
||||
$templateData['customfields'] = $output;
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
$mailer = new MailTemplate('com_contact.mail', $app->getLanguage()->getTag());
|
||||
$mailer->addRecipient($contact->email_to);
|
||||
$mailer->setReplyTo($templateData['email'], $templateData['name']);
|
||||
$mailer->addTemplateData($templateData);
|
||||
$mailer->addUnsafeTags(['name', 'email', 'body']);
|
||||
$sent = $mailer->send();
|
||||
|
||||
// If we are supposed to copy the sender, do so.
|
||||
if ($emailCopyToSender == true && !empty($data['contact_email_copy'])) {
|
||||
$mailer = new MailTemplate('com_contact.mail.copy', $app->getLanguage()->getTag());
|
||||
$mailer->addRecipient($templateData['email']);
|
||||
$mailer->setReplyTo($templateData['email'], $templateData['name']);
|
||||
$mailer->addTemplateData($templateData);
|
||||
$mailer->addUnsafeTags(['name', 'email', 'body']);
|
||||
$sent = $mailer->send();
|
||||
}
|
||||
} catch (MailDisabledException | phpMailerException $exception) {
|
||||
try {
|
||||
Log::add(Text::_($exception->getMessage()), Log::WARNING, 'jerror');
|
||||
|
||||
$sent = false;
|
||||
} catch (\RuntimeException $exception) {
|
||||
$this->app->enqueueMessage(Text::_($exception->errorMessage()), 'warning');
|
||||
|
||||
$sent = false;
|
||||
}
|
||||
}
|
||||
|
||||
return $sent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method override to check if you can add a new record.
|
||||
*
|
||||
* @param array $data An array of input data.
|
||||
*
|
||||
* @return boolean
|
||||
*
|
||||
* @since 4.0.0
|
||||
*/
|
||||
protected function allowAdd($data = [])
|
||||
{
|
||||
if ($categoryId = ArrayHelper::getValue($data, 'catid', $this->input->getInt('catid'), 'int')) {
|
||||
$user = $this->app->getIdentity();
|
||||
|
||||
// If the category has been passed in the data or URL check it.
|
||||
return $user->authorise('core.create', 'com_contact.category.' . $categoryId);
|
||||
}
|
||||
|
||||
// In the absence of better information, revert to the component permissions.
|
||||
return parent::allowAdd();
|
||||
}
|
||||
|
||||
/**
|
||||
* Method override to check if you can edit an existing record.
|
||||
*
|
||||
* @param array $data An array of input data.
|
||||
* @param string $key The name of the key for the primary key; default is id.
|
||||
*
|
||||
* @return boolean
|
||||
*
|
||||
* @since 4.0.0
|
||||
*/
|
||||
protected function allowEdit($data = [], $key = 'id')
|
||||
{
|
||||
$recordId = (int) isset($data[$key]) ? $data[$key] : 0;
|
||||
|
||||
if (!$recordId) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Need to do a lookup from the model.
|
||||
$record = $this->getModel()->getItem($recordId);
|
||||
$categoryId = (int) $record->catid;
|
||||
|
||||
if ($categoryId) {
|
||||
$user = $this->app->getIdentity();
|
||||
|
||||
// The category has been set. Check the category permissions.
|
||||
if ($user->authorise('core.edit', $this->option . '.category.' . $categoryId)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Fallback on edit.own.
|
||||
if ($user->authorise('core.edit.own', $this->option . '.category.' . $categoryId)) {
|
||||
return ($record->created_by === $user->id);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// Since there is no asset tracking, revert to the component permissions.
|
||||
return parent::allowEdit($data, $key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to cancel an edit.
|
||||
*
|
||||
* @param string $key The name of the primary key of the URL variable.
|
||||
*
|
||||
* @return boolean True if access level checks pass, false otherwise.
|
||||
*
|
||||
* @since 4.0.0
|
||||
*/
|
||||
public function cancel($key = null)
|
||||
{
|
||||
$result = parent::cancel($key);
|
||||
|
||||
$this->setRedirect(Route::_($this->getReturnPage(), false));
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the URL arguments to append to an item redirect.
|
||||
*
|
||||
* @param integer $recordId The primary key id for the item.
|
||||
* @param string $urlVar The name of the URL variable for the id.
|
||||
*
|
||||
* @return string The arguments to append to the redirect URL.
|
||||
*
|
||||
* @since 4.0.0
|
||||
*/
|
||||
protected function getRedirectToItemAppend($recordId = 0, $urlVar = 'id')
|
||||
{
|
||||
// Need to override the parent method completely.
|
||||
$tmpl = $this->input->get('tmpl');
|
||||
|
||||
$append = '';
|
||||
|
||||
// Setup redirect info.
|
||||
if ($tmpl) {
|
||||
$append .= '&tmpl=' . $tmpl;
|
||||
}
|
||||
|
||||
$append .= '&layout=edit';
|
||||
|
||||
$append .= '&' . $urlVar . '=' . (int) $recordId;
|
||||
|
||||
$itemId = $this->input->getInt('Itemid');
|
||||
$return = $this->getReturnPage();
|
||||
$catId = $this->input->getInt('catid');
|
||||
|
||||
if ($itemId) {
|
||||
$append .= '&Itemid=' . $itemId;
|
||||
}
|
||||
|
||||
if ($catId) {
|
||||
$append .= '&catid=' . $catId;
|
||||
}
|
||||
|
||||
if ($return) {
|
||||
$append .= '&return=' . base64_encode($return);
|
||||
}
|
||||
|
||||
return $append;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the return URL.
|
||||
*
|
||||
* If a "return" variable has been passed in the request
|
||||
*
|
||||
* @return string The return URL.
|
||||
*
|
||||
* @since 4.0.0
|
||||
*/
|
||||
protected function getReturnPage()
|
||||
{
|
||||
$return = $this->input->get('return', null, 'base64');
|
||||
|
||||
if (empty($return) || !Uri::isInternal(base64_decode($return))) {
|
||||
return Uri::base();
|
||||
}
|
||||
|
||||
return base64_decode($return);
|
||||
}
|
||||
}
|
||||
98
components/com_contact/src/Controller/DisplayController.php
Normal file
98
components/com_contact/src/Controller/DisplayController.php
Normal file
@ -0,0 +1,98 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Joomla.Site
|
||||
* @subpackage com_contact
|
||||
*
|
||||
* @copyright (C) 2006 Open Source Matters, Inc. <https://www.joomla.org>
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace Joomla\Component\Contact\Site\Controller;
|
||||
|
||||
use Joomla\CMS\Application\CMSApplication;
|
||||
use Joomla\CMS\Factory;
|
||||
use Joomla\CMS\MVC\Controller\BaseController;
|
||||
use Joomla\CMS\MVC\Factory\MVCFactoryInterface;
|
||||
|
||||
// phpcs:disable PSR1.Files.SideEffects
|
||||
\defined('_JEXEC') or die;
|
||||
// phpcs:enable PSR1.Files.SideEffects
|
||||
|
||||
/**
|
||||
* Contact Component Controller
|
||||
*
|
||||
* @since 1.5
|
||||
*/
|
||||
class DisplayController extends BaseController
|
||||
{
|
||||
/**
|
||||
* @param array $config An optional associative array of configuration settings.
|
||||
* Recognized key values include 'name', 'default_task', 'model_path', and
|
||||
* 'view_path' (this list is not meant to be comprehensive).
|
||||
* @param ?MVCFactoryInterface $factory The factory.
|
||||
* @param ?CMSApplication $app The Application for the dispatcher
|
||||
* @param ?\Joomla\CMS\Input\Input $input The Input object for the request
|
||||
*
|
||||
* @since 3.0
|
||||
*/
|
||||
public function __construct($config = [], ?MVCFactoryInterface $factory = null, $app = null, $input = null)
|
||||
{
|
||||
// Contact frontpage Editor contacts proxying.
|
||||
$input = Factory::getApplication()->getInput();
|
||||
|
||||
if ($input->get('view') === 'contacts' && $input->get('layout') === 'modal') {
|
||||
$config['base_path'] = JPATH_COMPONENT_ADMINISTRATOR;
|
||||
}
|
||||
|
||||
parent::__construct($config, $factory, $app, $input);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to display a view.
|
||||
*
|
||||
* @param boolean $cachable If true, the view output will be cached
|
||||
* @param array $urlparams An array of safe URL parameters and their variable types.
|
||||
* @see \Joomla\CMS\Filter\InputFilter::clean() for valid values.
|
||||
*
|
||||
* @return DisplayController This object to support chaining.
|
||||
*
|
||||
* @since 1.5
|
||||
*/
|
||||
public function display($cachable = false, $urlparams = [])
|
||||
{
|
||||
if ($this->app->getUserState('com_contact.contact.data') === null) {
|
||||
$cachable = true;
|
||||
}
|
||||
|
||||
// Set the default view name and format from the Request.
|
||||
$vName = $this->input->get('view', 'categories');
|
||||
$this->input->set('view', $vName);
|
||||
|
||||
if ($this->app->getIdentity()->get('id')) {
|
||||
$cachable = false;
|
||||
}
|
||||
|
||||
$safeurlparams = [
|
||||
'catid' => 'INT',
|
||||
'id' => 'INT',
|
||||
'cid' => 'ARRAY',
|
||||
'year' => 'INT',
|
||||
'month' => 'INT',
|
||||
'limit' => 'UINT',
|
||||
'limitstart' => 'UINT',
|
||||
'showall' => 'INT',
|
||||
'return' => 'BASE64',
|
||||
'filter' => 'STRING',
|
||||
'filter_order' => 'CMD',
|
||||
'filter_order_Dir' => 'CMD',
|
||||
'filter-search' => 'STRING',
|
||||
'print' => 'BOOLEAN',
|
||||
'lang' => 'CMD',
|
||||
];
|
||||
|
||||
parent::display($cachable, $safeurlparams);
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
48
components/com_contact/src/Dispatcher/Dispatcher.php
Normal file
48
components/com_contact/src/Dispatcher/Dispatcher.php
Normal file
@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Joomla.Site
|
||||
* @subpackage com_contact
|
||||
*
|
||||
* @copyright (C) 2017 Open Source Matters, Inc. <https://www.joomla.org>
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace Joomla\Component\Contact\Site\Dispatcher;
|
||||
|
||||
use Joomla\CMS\Dispatcher\ComponentDispatcher;
|
||||
use Joomla\CMS\Language\Text;
|
||||
|
||||
// phpcs:disable PSR1.Files.SideEffects
|
||||
\defined('_JEXEC') or die;
|
||||
// phpcs:enable PSR1.Files.SideEffects
|
||||
|
||||
/**
|
||||
* ComponentDispatcher class for com_contact
|
||||
*
|
||||
* @since 4.0.0
|
||||
*/
|
||||
class Dispatcher extends ComponentDispatcher
|
||||
{
|
||||
/**
|
||||
* Dispatch a controller task. Redirecting the user if appropriate.
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 4.0.0
|
||||
*/
|
||||
public function dispatch()
|
||||
{
|
||||
if ($this->input->get('view') === 'contacts' && $this->input->get('layout') === 'modal') {
|
||||
if (!$this->app->getIdentity()->authorise('core.create', 'com_contact')) {
|
||||
$this->app->enqueueMessage(Text::_('JERROR_ALERTNOAUTHOR'), 'warning');
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$this->app->getLanguage()->load('com_contact', JPATH_ADMINISTRATOR);
|
||||
}
|
||||
|
||||
parent::dispatch();
|
||||
}
|
||||
}
|
||||
64
components/com_contact/src/Helper/AssociationHelper.php
Normal file
64
components/com_contact/src/Helper/AssociationHelper.php
Normal file
@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Joomla.Site
|
||||
* @subpackage com_contact
|
||||
*
|
||||
* @copyright (C) 2013 Open Source Matters, Inc. <https://www.joomla.org>
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace Joomla\Component\Contact\Site\Helper;
|
||||
|
||||
use Joomla\CMS\Factory;
|
||||
use Joomla\CMS\Language\Associations;
|
||||
use Joomla\Component\Categories\Administrator\Helper\CategoryAssociationHelper;
|
||||
|
||||
// phpcs:disable PSR1.Files.SideEffects
|
||||
\defined('_JEXEC') or die;
|
||||
// phpcs:enable PSR1.Files.SideEffects
|
||||
|
||||
/**
|
||||
* Contact Component Association Helper
|
||||
*
|
||||
* @since 3.0
|
||||
*/
|
||||
abstract class AssociationHelper extends CategoryAssociationHelper
|
||||
{
|
||||
/**
|
||||
* Method to get the associations for a given item
|
||||
*
|
||||
* @param integer $id Id of the item
|
||||
* @param string $view Name of the view
|
||||
*
|
||||
* @return array Array of associations for the item
|
||||
*
|
||||
* @since 3.0
|
||||
*/
|
||||
public static function getAssociations($id = 0, $view = null)
|
||||
{
|
||||
$jinput = Factory::getApplication()->getInput();
|
||||
$view = $view ?? $jinput->get('view');
|
||||
$id = empty($id) ? $jinput->getInt('id') : $id;
|
||||
|
||||
if ($view === 'contact') {
|
||||
if ($id) {
|
||||
$associations = Associations::getAssociations('com_contact', '#__contact_details', 'com_contact.item', $id);
|
||||
|
||||
$return = [];
|
||||
|
||||
foreach ($associations as $tag => $item) {
|
||||
$return[$tag] = RouteHelper::getContactRoute($item->id, (int) $item->catid, $item->language);
|
||||
}
|
||||
|
||||
return $return;
|
||||
}
|
||||
}
|
||||
|
||||
if ($view === 'category' || $view === 'categories') {
|
||||
return self::getCategoryAssociations($id, 'com_contact');
|
||||
}
|
||||
|
||||
return [];
|
||||
}
|
||||
}
|
||||
88
components/com_contact/src/Helper/RouteHelper.php
Normal file
88
components/com_contact/src/Helper/RouteHelper.php
Normal file
@ -0,0 +1,88 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Joomla.Site
|
||||
* @subpackage com_contact
|
||||
*
|
||||
* @copyright (C) 2017 Open Source Matters, Inc. <https://www.joomla.org>
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace Joomla\Component\Contact\Site\Helper;
|
||||
|
||||
use Joomla\CMS\Categories\CategoryNode;
|
||||
use Joomla\CMS\Language\Multilanguage;
|
||||
|
||||
// phpcs:disable PSR1.Files.SideEffects
|
||||
\defined('_JEXEC') or die;
|
||||
// phpcs:enable PSR1.Files.SideEffects
|
||||
|
||||
/**
|
||||
* Contact Component Route Helper
|
||||
*
|
||||
* @static
|
||||
* @package Joomla.Site
|
||||
* @subpackage com_contact
|
||||
* @since 1.5
|
||||
*/
|
||||
abstract class RouteHelper
|
||||
{
|
||||
/**
|
||||
* Get the URL route for a contact from a contact ID, contact category ID and language
|
||||
*
|
||||
* @param integer $id The id of the contact
|
||||
* @param integer $catid The id of the contact's category
|
||||
* @param mixed $language The id of the language being used.
|
||||
*
|
||||
* @return string The link to the contact
|
||||
*
|
||||
* @since 1.5
|
||||
*/
|
||||
public static function getContactRoute($id, $catid, $language = 0)
|
||||
{
|
||||
// Create the link
|
||||
$link = 'index.php?option=com_contact&view=contact&id=' . $id;
|
||||
|
||||
if ($catid > 1) {
|
||||
$link .= '&catid=' . $catid;
|
||||
}
|
||||
|
||||
if ($language && $language !== '*' && Multilanguage::isEnabled()) {
|
||||
$link .= '&lang=' . $language;
|
||||
}
|
||||
|
||||
return $link;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the URL route for a contact category from a contact category ID and language
|
||||
*
|
||||
* @param mixed $catid The id of the contact's category either an integer id or an instance of CategoryNode
|
||||
* @param mixed $language The id of the language being used.
|
||||
*
|
||||
* @return string The link to the contact
|
||||
*
|
||||
* @since 1.5
|
||||
*/
|
||||
public static function getCategoryRoute($catid, $language = 0)
|
||||
{
|
||||
if ($catid instanceof CategoryNode) {
|
||||
$id = $catid->id;
|
||||
} else {
|
||||
$id = (int) $catid;
|
||||
}
|
||||
|
||||
if ($id < 1) {
|
||||
$link = '';
|
||||
} else {
|
||||
// Create the link
|
||||
$link = 'index.php?option=com_contact&view=category&id=' . $id;
|
||||
|
||||
if ($language && $language !== '*' && Multilanguage::isEnabled()) {
|
||||
$link .= '&lang=' . $language;
|
||||
}
|
||||
}
|
||||
|
||||
return $link;
|
||||
}
|
||||
}
|
||||
156
components/com_contact/src/Model/CategoriesModel.php
Normal file
156
components/com_contact/src/Model/CategoriesModel.php
Normal file
@ -0,0 +1,156 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Joomla.Site
|
||||
* @subpackage com_contact
|
||||
*
|
||||
* @copyright (C) 2008 Open Source Matters, Inc. <https://www.joomla.org>
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace Joomla\Component\Contact\Site\Model;
|
||||
|
||||
use Joomla\CMS\Categories\Categories;
|
||||
use Joomla\CMS\Categories\CategoryNode;
|
||||
use Joomla\CMS\Factory;
|
||||
use Joomla\CMS\MVC\Model\ListModel;
|
||||
use Joomla\Registry\Registry;
|
||||
|
||||
// phpcs:disable PSR1.Files.SideEffects
|
||||
\defined('_JEXEC') or die;
|
||||
// phpcs:enable PSR1.Files.SideEffects
|
||||
|
||||
/**
|
||||
* This models supports retrieving lists of contact categories.
|
||||
*
|
||||
* @since 1.6
|
||||
*/
|
||||
class CategoriesModel extends ListModel
|
||||
{
|
||||
/**
|
||||
* Model context string.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $_context = 'com_contact.categories';
|
||||
|
||||
/**
|
||||
* The category context (allows other extensions to derived from this model).
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_extension = 'com_contact';
|
||||
|
||||
/**
|
||||
* Parent category of the current one
|
||||
*
|
||||
* @var CategoryNode|null
|
||||
*/
|
||||
private $_parent = null;
|
||||
|
||||
/**
|
||||
* Array of child-categories
|
||||
*
|
||||
* @var CategoryNode[]|null
|
||||
*/
|
||||
private $_items = null;
|
||||
|
||||
/**
|
||||
* Method to auto-populate the model state.
|
||||
*
|
||||
* Note. Calling getState in this method will result in recursion.
|
||||
*
|
||||
* @param string $ordering An optional ordering field.
|
||||
* @param string $direction An optional direction (asc|desc).
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 1.6
|
||||
*/
|
||||
protected function populateState($ordering = null, $direction = null)
|
||||
{
|
||||
$app = Factory::getApplication();
|
||||
$this->setState('filter.extension', $this->_extension);
|
||||
|
||||
// Get the parent id if defined.
|
||||
$parentId = $app->getInput()->getInt('id');
|
||||
$this->setState('filter.parentId', $parentId);
|
||||
|
||||
$params = $app->getParams();
|
||||
$this->setState('params', $params);
|
||||
|
||||
$this->setState('filter.published', 1);
|
||||
$this->setState('filter.access', true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to get a store id based on model configuration state.
|
||||
*
|
||||
* This is necessary because the model is used by the component and
|
||||
* different modules that might need different sets of data or different
|
||||
* ordering requirements.
|
||||
*
|
||||
* @param string $id A prefix for the store id.
|
||||
*
|
||||
* @return string A store id.
|
||||
*/
|
||||
protected function getStoreId($id = '')
|
||||
{
|
||||
// Compile the store id.
|
||||
$id .= ':' . $this->getState('filter.extension');
|
||||
$id .= ':' . $this->getState('filter.published');
|
||||
$id .= ':' . $this->getState('filter.access');
|
||||
$id .= ':' . $this->getState('filter.parentId');
|
||||
|
||||
return parent::getStoreId($id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Redefine the function and add some properties to make the styling easier
|
||||
*
|
||||
* @return mixed An array of data items on success, false on failure.
|
||||
*/
|
||||
public function getItems()
|
||||
{
|
||||
if ($this->_items === null) {
|
||||
$app = Factory::getApplication();
|
||||
$menu = $app->getMenu();
|
||||
$active = $menu->getActive();
|
||||
|
||||
if ($active) {
|
||||
$params = $active->getParams();
|
||||
} else {
|
||||
$params = new Registry();
|
||||
}
|
||||
|
||||
$options = [];
|
||||
$options['countItems'] = $params->get('show_cat_items_cat', 1) || !$params->get('show_empty_categories_cat', 0);
|
||||
$categories = Categories::getInstance('Contact', $options);
|
||||
$this->_parent = $categories->get($this->getState('filter.parentId', 'root'));
|
||||
|
||||
if (\is_object($this->_parent)) {
|
||||
$this->_items = $this->_parent->getChildren();
|
||||
} else {
|
||||
$this->_items = false;
|
||||
}
|
||||
}
|
||||
|
||||
return $this->_items;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the id of the parent category for the selected list of categories
|
||||
*
|
||||
* @return integer The id of the parent category
|
||||
*
|
||||
* @since 1.6.0
|
||||
*/
|
||||
public function getParent()
|
||||
{
|
||||
if (!\is_object($this->_parent)) {
|
||||
$this->getItems();
|
||||
}
|
||||
|
||||
return $this->_parent;
|
||||
}
|
||||
}
|
||||
495
components/com_contact/src/Model/CategoryModel.php
Normal file
495
components/com_contact/src/Model/CategoryModel.php
Normal file
@ -0,0 +1,495 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Joomla.Site
|
||||
* @subpackage com_contact
|
||||
*
|
||||
* @copyright (C) 2006 Open Source Matters, Inc. <https://www.joomla.org>
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace Joomla\Component\Contact\Site\Model;
|
||||
|
||||
use Joomla\CMS\Categories\Categories;
|
||||
use Joomla\CMS\Categories\CategoryNode;
|
||||
use Joomla\CMS\Factory;
|
||||
use Joomla\CMS\Helper\TagsHelper;
|
||||
use Joomla\CMS\Language\Multilanguage;
|
||||
use Joomla\CMS\MVC\Model\ListModel;
|
||||
use Joomla\CMS\Table\Table;
|
||||
use Joomla\Database\ParameterType;
|
||||
use Joomla\Database\QueryInterface;
|
||||
use Joomla\Registry\Registry;
|
||||
|
||||
// phpcs:disable PSR1.Files.SideEffects
|
||||
\defined('_JEXEC') or die;
|
||||
// phpcs:enable PSR1.Files.SideEffects
|
||||
|
||||
/**
|
||||
* Single item model for a contact
|
||||
*
|
||||
* @package Joomla.Site
|
||||
* @subpackage com_contact
|
||||
* @since 1.5
|
||||
*/
|
||||
class CategoryModel extends ListModel
|
||||
{
|
||||
/**
|
||||
* Category item data
|
||||
*
|
||||
* @var CategoryNode
|
||||
*/
|
||||
protected $_item;
|
||||
|
||||
/**
|
||||
* Category left and right of this one
|
||||
*
|
||||
* @var CategoryNode[]|null
|
||||
*/
|
||||
protected $_siblings;
|
||||
|
||||
/**
|
||||
* Array of child-categories
|
||||
*
|
||||
* @var CategoryNode[]|null
|
||||
*/
|
||||
protected $_children;
|
||||
|
||||
/**
|
||||
* Parent category of the current one
|
||||
*
|
||||
* @var CategoryNode|null
|
||||
*/
|
||||
protected $_parent;
|
||||
|
||||
/**
|
||||
* The category that applies.
|
||||
*
|
||||
* @var object
|
||||
*/
|
||||
protected $_category;
|
||||
|
||||
/**
|
||||
* The list of other contact categories.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_categories;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param array $config An optional associative array of configuration settings.
|
||||
*
|
||||
* @since 1.6
|
||||
*/
|
||||
public function __construct($config = [])
|
||||
{
|
||||
if (empty($config['filter_fields'])) {
|
||||
$config['filter_fields'] = [
|
||||
'id', 'a.id',
|
||||
'name', 'a.name',
|
||||
'con_position', 'a.con_position',
|
||||
'suburb', 'a.suburb',
|
||||
'state', 'a.state',
|
||||
'country', 'a.country',
|
||||
'ordering', 'a.ordering',
|
||||
'sortname',
|
||||
'sortname1', 'a.sortname1',
|
||||
'sortname2', 'a.sortname2',
|
||||
'sortname3', 'a.sortname3',
|
||||
'featuredordering', 'a.featured',
|
||||
];
|
||||
}
|
||||
|
||||
parent::__construct($config);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to get a list of items.
|
||||
*
|
||||
* @return mixed An array of objects on success, false on failure.
|
||||
*/
|
||||
public function getItems()
|
||||
{
|
||||
// Invoke the parent getItems method to get the main list
|
||||
$items = parent::getItems();
|
||||
|
||||
if ($items === false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$taggedItems = [];
|
||||
|
||||
// Convert the params field into an object, saving original in _params
|
||||
foreach ($items as $item) {
|
||||
if (!isset($this->_params)) {
|
||||
$item->params = new Registry($item->params);
|
||||
}
|
||||
|
||||
// Some contexts may not use tags data at all, so we allow callers to disable loading tag data
|
||||
if ($this->getState('load_tags', true)) {
|
||||
$item->tags = new TagsHelper();
|
||||
$taggedItems[$item->id] = $item;
|
||||
}
|
||||
}
|
||||
|
||||
// Load tags of all items.
|
||||
if ($taggedItems) {
|
||||
$tagsHelper = new TagsHelper();
|
||||
$itemIds = array_keys($taggedItems);
|
||||
|
||||
foreach ($tagsHelper->getMultipleItemTags('com_contact.contact', $itemIds) as $id => $tags) {
|
||||
$taggedItems[$id]->tags->itemTags = $tags;
|
||||
}
|
||||
}
|
||||
|
||||
return $items;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to build an SQL query to load the list data.
|
||||
*
|
||||
* @return QueryInterface An SQL query
|
||||
*
|
||||
* @since 1.6
|
||||
*/
|
||||
protected function getListQuery()
|
||||
{
|
||||
$user = $this->getCurrentUser();
|
||||
$groups = $user->getAuthorisedViewLevels();
|
||||
|
||||
// Create a new query object.
|
||||
$db = $this->getDatabase();
|
||||
|
||||
/** @var \Joomla\Database\DatabaseQuery $query */
|
||||
$query = $db->getQuery(true);
|
||||
|
||||
$query->select($this->getState('list.select', 'a.*'))
|
||||
->select($this->getSlugColumn($query, 'a.id', 'a.alias') . ' AS slug')
|
||||
->select($this->getSlugColumn($query, 'c.id', 'c.alias') . ' AS catslug')
|
||||
/**
|
||||
* @todo: we actually should be doing it but it's wrong this way
|
||||
* . ' CASE WHEN CHAR_LENGTH(a.alias) THEN CONCAT_WS(\':\', a.id, a.alias) ELSE a.id END as slug, '
|
||||
* . ' CASE WHEN CHAR_LENGTH(c.alias) THEN CONCAT_WS(\':\', c.id, c.alias) ELSE c.id END AS catslug ');
|
||||
*/
|
||||
->from($db->quoteName('#__contact_details', 'a'))
|
||||
->leftJoin($db->quoteName('#__categories', 'c') . ' ON c.id = a.catid')
|
||||
->whereIn($db->quoteName('a.access'), $groups);
|
||||
|
||||
// Filter by category.
|
||||
$categoryId = (int) $this->getState('category.id');
|
||||
$includeSubcategories = (int) $this->getState('filter.max_category_levels', 1) !== 0;
|
||||
|
||||
if ($includeSubcategories) {
|
||||
$levels = (int) $this->getState('filter.max_category_levels', 1);
|
||||
|
||||
// Create a subquery for the subcategory list
|
||||
$subQuery = $db->getQuery(true)
|
||||
->select($db->quoteName('sub.id'))
|
||||
->from($db->quoteName('#__categories', 'sub'))
|
||||
->join(
|
||||
'INNER',
|
||||
$db->quoteName('#__categories', 'this'),
|
||||
$db->quoteName('sub.lft') . ' > ' . $db->quoteName('this.lft')
|
||||
. ' AND ' . $db->quoteName('sub.rgt') . ' < ' . $db->quoteName('this.rgt')
|
||||
)
|
||||
->where($db->quoteName('this.id') . ' = :subCategoryId');
|
||||
|
||||
$query->bind(':subCategoryId', $categoryId, ParameterType::INTEGER);
|
||||
|
||||
if ($levels >= 0) {
|
||||
$subQuery->where($db->quoteName('sub.level') . ' <= ' . $db->quoteName('this.level') . ' + :levels');
|
||||
$query->bind(':levels', $levels, ParameterType::INTEGER);
|
||||
}
|
||||
|
||||
// Add the subquery to the main query
|
||||
$query->where(
|
||||
'(' . $db->quoteName('a.catid') . ' = :categoryId OR ' . $db->quoteName('a.catid') . ' IN (' . $subQuery . '))'
|
||||
);
|
||||
$query->bind(':categoryId', $categoryId, ParameterType::INTEGER);
|
||||
} else {
|
||||
$query->where($db->quoteName('a.catid') . ' = :acatid')
|
||||
->whereIn($db->quoteName('c.access'), $groups);
|
||||
$query->bind(':acatid', $categoryId, ParameterType::INTEGER);
|
||||
}
|
||||
|
||||
// Join over the users for the author and modified_by names.
|
||||
$query->select("CASE WHEN a.created_by_alias > ' ' THEN a.created_by_alias ELSE ua.name END AS author")
|
||||
->select('ua.email AS author_email')
|
||||
->leftJoin($db->quoteName('#__users', 'ua') . ' ON ua.id = a.created_by')
|
||||
->leftJoin($db->quoteName('#__users', 'uam') . ' ON uam.id = a.modified_by');
|
||||
|
||||
// Filter by state
|
||||
$state = $this->getState('filter.published');
|
||||
|
||||
if (is_numeric($state)) {
|
||||
$query->where($db->quoteName('a.published') . ' = :published');
|
||||
$query->bind(':published', $state, ParameterType::INTEGER);
|
||||
} else {
|
||||
$query->whereIn($db->quoteName('c.published'), [0,1,2]);
|
||||
}
|
||||
|
||||
// Filter by start and end dates.
|
||||
$nowDate = Factory::getDate()->toSql();
|
||||
|
||||
if ($this->getState('filter.publish_date')) {
|
||||
$query->where('(' . $db->quoteName('a.publish_up')
|
||||
. ' IS NULL OR ' . $db->quoteName('a.publish_up') . ' <= :publish_up)')
|
||||
->where('(' . $db->quoteName('a.publish_down')
|
||||
. ' IS NULL OR ' . $db->quoteName('a.publish_down') . ' >= :publish_down)')
|
||||
->bind(':publish_up', $nowDate)
|
||||
->bind(':publish_down', $nowDate);
|
||||
}
|
||||
|
||||
// Filter by search in title
|
||||
$search = $this->getState('list.filter');
|
||||
|
||||
if (!empty($search)) {
|
||||
$search = '%' . trim($search) . '%';
|
||||
$query->where($db->quoteName('a.name') . ' LIKE :name ');
|
||||
$query->bind(':name', $search);
|
||||
}
|
||||
|
||||
// Filter on the language.
|
||||
if ($this->getState('filter.language')) {
|
||||
$query->whereIn($db->quoteName('a.language'), [Factory::getApplication()->getLanguage()->getTag(), '*'], ParameterType::STRING);
|
||||
}
|
||||
|
||||
// Set sortname ordering if selected
|
||||
if ($this->getState('list.ordering') === 'sortname') {
|
||||
$query->order($db->escape('a.sortname1') . ' ' . $db->escape($this->getState('list.direction', 'ASC')))
|
||||
->order($db->escape('a.sortname2') . ' ' . $db->escape($this->getState('list.direction', 'ASC')))
|
||||
->order($db->escape('a.sortname3') . ' ' . $db->escape($this->getState('list.direction', 'ASC')));
|
||||
} elseif ($this->getState('list.ordering') === 'featuredordering') {
|
||||
$query->order($db->escape('a.featured') . ' DESC')
|
||||
->order($db->escape('a.ordering') . ' ASC');
|
||||
} else {
|
||||
$query->order($db->escape($this->getState('list.ordering', 'a.ordering')) . ' ' . $db->escape($this->getState('list.direction', 'ASC')));
|
||||
}
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to auto-populate the model state.
|
||||
*
|
||||
* Note. Calling getState in this method will result in recursion.
|
||||
*
|
||||
* @param string $ordering An optional ordering field.
|
||||
* @param string $direction An optional direction (asc|desc).
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 1.6
|
||||
*/
|
||||
protected function populateState($ordering = null, $direction = null)
|
||||
{
|
||||
$app = Factory::getApplication();
|
||||
$input = $app->getInput();
|
||||
|
||||
$params = $app->getParams();
|
||||
$this->setState('params', $params);
|
||||
|
||||
// List state information
|
||||
$format = $input->getWord('format');
|
||||
|
||||
if ($format === 'feed') {
|
||||
$limit = $app->get('feed_limit');
|
||||
} else {
|
||||
$limit = $app->getUserStateFromRequest(
|
||||
'com_contact.category.list.limit',
|
||||
'limit',
|
||||
$params->get('contacts_display_num', $app->get('list_limit')),
|
||||
'uint'
|
||||
);
|
||||
}
|
||||
|
||||
$this->setState('list.limit', $limit);
|
||||
|
||||
$limitstart = $input->get('limitstart', 0, 'uint');
|
||||
$this->setState('list.start', $limitstart);
|
||||
|
||||
// Optional filter text
|
||||
$itemid = $input->get('Itemid', 0, 'int');
|
||||
$search = $app->getUserStateFromRequest('com_contact.category.list.' . $itemid . '.filter-search', 'filter-search', '', 'string');
|
||||
$this->setState('list.filter', $search);
|
||||
|
||||
$orderCol = $input->get('filter_order', $params->get('initial_sort', 'ordering'));
|
||||
|
||||
if (!\in_array($orderCol, $this->filter_fields)) {
|
||||
$orderCol = 'ordering';
|
||||
}
|
||||
|
||||
$this->setState('list.ordering', $orderCol);
|
||||
|
||||
$listOrder = $input->get('filter_order_Dir', 'ASC');
|
||||
|
||||
if (!\in_array(strtoupper($listOrder), ['ASC', 'DESC', ''])) {
|
||||
$listOrder = 'ASC';
|
||||
}
|
||||
|
||||
$this->setState('list.direction', $listOrder);
|
||||
|
||||
$id = $input->get('id', 0, 'int');
|
||||
$this->setState('category.id', $id);
|
||||
$this->setState('filter.max_category_levels', $params->get('maxLevel', 1));
|
||||
|
||||
$user = $this->getCurrentUser();
|
||||
|
||||
if ((!$user->authorise('core.edit.state', 'com_contact')) && (!$user->authorise('core.edit', 'com_contact'))) {
|
||||
// Limit to published for people who can't edit or edit.state.
|
||||
$this->setState('filter.published', 1);
|
||||
|
||||
// Filter by start and end dates.
|
||||
$this->setState('filter.publish_date', true);
|
||||
}
|
||||
|
||||
$this->setState('filter.language', Multilanguage::isEnabled());
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to get category data for the current category
|
||||
*
|
||||
* @return object The category object
|
||||
*
|
||||
* @since 1.5
|
||||
*/
|
||||
public function getCategory()
|
||||
{
|
||||
if (!\is_object($this->_item)) {
|
||||
$app = Factory::getApplication();
|
||||
$menu = $app->getMenu();
|
||||
$active = $menu->getActive();
|
||||
|
||||
if ($active) {
|
||||
$params = $active->getParams();
|
||||
} else {
|
||||
$params = new Registry();
|
||||
}
|
||||
|
||||
$options = [];
|
||||
$options['countItems'] = $params->get('show_cat_items', 1) || $params->get('show_empty_categories', 0);
|
||||
$categories = Categories::getInstance('Contact', $options);
|
||||
$this->_item = $categories->get($this->getState('category.id', 'root'));
|
||||
|
||||
if (\is_object($this->_item)) {
|
||||
$this->_children = $this->_item->getChildren();
|
||||
$this->_parent = false;
|
||||
|
||||
if ($this->_item->getParent()) {
|
||||
$this->_parent = $this->_item->getParent();
|
||||
}
|
||||
|
||||
$this->_rightsibling = $this->_item->getSibling();
|
||||
$this->_leftsibling = $this->_item->getSibling(false);
|
||||
} else {
|
||||
$this->_children = false;
|
||||
$this->_parent = false;
|
||||
}
|
||||
}
|
||||
|
||||
return $this->_item;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the parent category.
|
||||
*
|
||||
* @return mixed An array of categories or false if an error occurs.
|
||||
*/
|
||||
public function getParent()
|
||||
{
|
||||
if (!\is_object($this->_item)) {
|
||||
$this->getCategory();
|
||||
}
|
||||
|
||||
return $this->_parent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the sibling (adjacent) categories.
|
||||
*
|
||||
* @return mixed An array of categories or false if an error occurs.
|
||||
*/
|
||||
public function &getLeftSibling()
|
||||
{
|
||||
if (!\is_object($this->_item)) {
|
||||
$this->getCategory();
|
||||
}
|
||||
|
||||
return $this->_leftsibling;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the sibling (adjacent) categories.
|
||||
*
|
||||
* @return mixed An array of categories or false if an error occurs.
|
||||
*/
|
||||
public function &getRightSibling()
|
||||
{
|
||||
if (!\is_object($this->_item)) {
|
||||
$this->getCategory();
|
||||
}
|
||||
|
||||
return $this->_rightsibling;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the child categories.
|
||||
*
|
||||
* @return mixed An array of categories or false if an error occurs.
|
||||
*/
|
||||
public function &getChildren()
|
||||
{
|
||||
if (!\is_object($this->_item)) {
|
||||
$this->getCategory();
|
||||
}
|
||||
|
||||
return $this->_children;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate column expression for slug or catslug.
|
||||
*
|
||||
* @param \Joomla\Database\DatabaseQuery $query Current query instance.
|
||||
* @param string $id Column id name.
|
||||
* @param string $alias Column alias name.
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
* @since 4.0.0
|
||||
*/
|
||||
private function getSlugColumn($query, $id, $alias)
|
||||
{
|
||||
return 'CASE WHEN '
|
||||
. $query->charLength($alias, '!=', '0')
|
||||
. ' THEN '
|
||||
. $query->concatenate([$query->castAsChar($id), $alias], ':')
|
||||
. ' ELSE '
|
||||
. $query->castAsChar($id) . ' END';
|
||||
}
|
||||
|
||||
/**
|
||||
* Increment the hit counter for the category.
|
||||
*
|
||||
* @param integer $pk Optional primary key of the category to increment.
|
||||
*
|
||||
* @return boolean True if successful; false otherwise and internal error set.
|
||||
*
|
||||
* @since 3.2
|
||||
*/
|
||||
public function hit($pk = 0)
|
||||
{
|
||||
$input = Factory::getApplication()->getInput();
|
||||
$hitcount = $input->getInt('hitcount', 1);
|
||||
|
||||
if ($hitcount) {
|
||||
$pk = (!empty($pk)) ? $pk : (int) $this->getState('category.id');
|
||||
|
||||
$table = Table::getInstance('Category');
|
||||
$table->hit($pk);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
434
components/com_contact/src/Model/ContactModel.php
Normal file
434
components/com_contact/src/Model/ContactModel.php
Normal file
@ -0,0 +1,434 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Joomla.Site
|
||||
* @subpackage com_contact
|
||||
*
|
||||
* @copyright (C) 2006 Open Source Matters, Inc. <https://www.joomla.org>
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace Joomla\Component\Contact\Site\Model;
|
||||
|
||||
use Joomla\CMS\Application\SiteApplication;
|
||||
use Joomla\CMS\Component\ComponentHelper;
|
||||
use Joomla\CMS\Factory;
|
||||
use Joomla\CMS\Form\Form;
|
||||
use Joomla\CMS\Helper\TagsHelper;
|
||||
use Joomla\CMS\Language\Multilanguage;
|
||||
use Joomla\CMS\Language\Text;
|
||||
use Joomla\CMS\MVC\Model\FormModel;
|
||||
use Joomla\CMS\Plugin\PluginHelper;
|
||||
use Joomla\Database\ParameterType;
|
||||
use Joomla\Database\QueryInterface;
|
||||
use Joomla\Registry\Registry;
|
||||
|
||||
// phpcs:disable PSR1.Files.SideEffects
|
||||
\defined('_JEXEC') or die;
|
||||
// phpcs:enable PSR1.Files.SideEffects
|
||||
|
||||
/**
|
||||
* Single item model for a contact
|
||||
*
|
||||
* @package Joomla.Site
|
||||
* @subpackage com_contact
|
||||
* @since 1.5
|
||||
*/
|
||||
class ContactModel extends FormModel
|
||||
{
|
||||
/**
|
||||
* The name of the view for a single item
|
||||
*
|
||||
* @var string
|
||||
* @since 1.6
|
||||
*/
|
||||
protected $view_item = 'contact';
|
||||
|
||||
/**
|
||||
* A loaded item
|
||||
*
|
||||
* @var \stdClass[]
|
||||
* @since 1.6
|
||||
*/
|
||||
protected $_item = [];
|
||||
|
||||
/**
|
||||
* Model context string.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_context = 'com_contact.contact';
|
||||
|
||||
/**
|
||||
* Method to auto-populate the model state.
|
||||
*
|
||||
* Note. Calling getState in this method will result in recursion.
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 1.6
|
||||
*/
|
||||
protected function populateState()
|
||||
{
|
||||
/** @var SiteApplication $app */
|
||||
$app = Factory::getContainer()->get(SiteApplication::class);
|
||||
|
||||
if (Factory::getApplication()->isClient('api')) {
|
||||
// @todo: remove this
|
||||
$app->loadLanguage();
|
||||
$this->setState('contact.id', Factory::getApplication()->getInput()->post->getInt('id'));
|
||||
} else {
|
||||
$this->setState('contact.id', $app->getInput()->getInt('id'));
|
||||
}
|
||||
|
||||
$this->setState('params', $app->getParams());
|
||||
|
||||
$user = $this->getCurrentUser();
|
||||
|
||||
if ((!$user->authorise('core.edit.state', 'com_contact')) && (!$user->authorise('core.edit', 'com_contact'))) {
|
||||
$this->setState('filter.published', 1);
|
||||
$this->setState('filter.archived', 2);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to get the contact form.
|
||||
* The base form is loaded from XML and then an event is fired
|
||||
*
|
||||
* @param array $data An optional array of data for the form to interrogate.
|
||||
* @param boolean $loadData True if the form is to load its own data (default case), false if not.
|
||||
*
|
||||
* @return Form A Form object on success, false on failure
|
||||
*
|
||||
* @since 1.6
|
||||
*/
|
||||
public function getForm($data = [], $loadData = true)
|
||||
{
|
||||
$form = $this->loadForm('com_contact.contact', 'contact', ['control' => 'jform', 'load_data' => $loadData]);
|
||||
|
||||
if (empty($form)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$temp = clone $this->getState('params');
|
||||
$contact = $this->getItem($this->getState('contact.id'));
|
||||
$active = Factory::getContainer()->get(SiteApplication::class)->getMenu()->getActive();
|
||||
|
||||
if ($active) {
|
||||
// If the current view is the active item and a contact view for this contact, then the menu item params take priority
|
||||
if (strpos($active->link, 'view=contact') && strpos($active->link, '&id=' . (int) $contact->id)) {
|
||||
// $contact->params are the contact params, $temp are the menu item params
|
||||
// Merge so that the menu item params take priority
|
||||
$contact->params->merge($temp);
|
||||
} else {
|
||||
// Current view is not a single contact, so the contact params take priority here
|
||||
// Merge the menu item params with the contact params so that the contact params take priority
|
||||
$temp->merge($contact->params);
|
||||
$contact->params = $temp;
|
||||
}
|
||||
} else {
|
||||
// Merge so that contact params take priority
|
||||
$temp->merge($contact->params);
|
||||
$contact->params = $temp;
|
||||
}
|
||||
|
||||
if (!$contact->params->get('show_email_copy', 0)) {
|
||||
$form->removeField('contact_email_copy');
|
||||
}
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to get the data that should be injected in the form.
|
||||
*
|
||||
* @return array The default data is an empty array.
|
||||
*
|
||||
* @since 1.6.2
|
||||
*/
|
||||
protected function loadFormData()
|
||||
{
|
||||
$data = (array) Factory::getApplication()->getUserState('com_contact.contact.data', []);
|
||||
|
||||
if (empty($data['language']) && Multilanguage::isEnabled()) {
|
||||
$data['language'] = Factory::getLanguage()->getTag();
|
||||
}
|
||||
|
||||
// Add contact catid to contact form data, so fields plugin can work properly
|
||||
if (empty($data['catid'])) {
|
||||
$data['catid'] = $this->getItem()->catid;
|
||||
}
|
||||
|
||||
$this->preprocessData('com_contact.contact', $data);
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a contact
|
||||
*
|
||||
* @param integer $pk Id for the contact
|
||||
*
|
||||
* @return mixed \stdClass or null
|
||||
*
|
||||
* @since 1.6.0
|
||||
*/
|
||||
public function getItem($pk = null)
|
||||
{
|
||||
$pk = $pk ?: (int) $this->getState('contact.id');
|
||||
|
||||
if (!isset($this->_item[$pk])) {
|
||||
try {
|
||||
$db = $this->getDatabase();
|
||||
$query = $db->getQuery(true);
|
||||
|
||||
$query->select($this->getState('item.select', 'a.*'))
|
||||
->select($this->getSlugColumn($query, 'a.id', 'a.alias') . ' AS slug')
|
||||
->select($this->getSlugColumn($query, 'c.id', 'c.alias') . ' AS catslug')
|
||||
->from($db->quoteName('#__contact_details', 'a'))
|
||||
|
||||
// Join on category table.
|
||||
->select('c.title AS category_title, c.alias AS category_alias, c.access AS category_access')
|
||||
->leftJoin($db->quoteName('#__categories', 'c'), 'c.id = a.catid')
|
||||
|
||||
// Join over the categories to get parent category titles
|
||||
->select('parent.title AS parent_title, parent.id AS parent_id, parent.path AS parent_route, parent.alias AS parent_alias')
|
||||
->leftJoin($db->quoteName('#__categories', 'parent'), 'parent.id = c.parent_id')
|
||||
->where($db->quoteName('a.id') . ' = :id')
|
||||
->bind(':id', $pk, ParameterType::INTEGER);
|
||||
|
||||
// Filter by start and end dates.
|
||||
$nowDate = Factory::getDate()->toSql();
|
||||
|
||||
// Filter by published state.
|
||||
$published = $this->getState('filter.published');
|
||||
$archived = $this->getState('filter.archived');
|
||||
|
||||
if (is_numeric($published)) {
|
||||
$queryString = $db->quoteName('a.published') . ' = :published';
|
||||
|
||||
if ($archived !== null) {
|
||||
$queryString = '(' . $queryString . ' OR ' . $db->quoteName('a.published') . ' = :archived)';
|
||||
$query->bind(':archived', $archived, ParameterType::INTEGER);
|
||||
}
|
||||
|
||||
$query->where($queryString)
|
||||
->where('(' . $db->quoteName('a.publish_up') . ' IS NULL OR ' . $db->quoteName('a.publish_up') . ' <= :publish_up)')
|
||||
->where('(' . $db->quoteName('a.publish_down') . ' IS NULL OR ' . $db->quoteName('a.publish_down') . ' >= :publish_down)')
|
||||
->bind(':published', $published, ParameterType::INTEGER)
|
||||
->bind(':publish_up', $nowDate)
|
||||
->bind(':publish_down', $nowDate);
|
||||
}
|
||||
|
||||
$db->setQuery($query);
|
||||
$data = $db->loadObject();
|
||||
|
||||
if (empty($data)) {
|
||||
throw new \Exception(Text::_('COM_CONTACT_ERROR_CONTACT_NOT_FOUND'), 404);
|
||||
}
|
||||
|
||||
// Check for published state if filter set.
|
||||
if ((is_numeric($published) || is_numeric($archived)) && (($data->published != $published) && ($data->published != $archived))) {
|
||||
throw new \Exception(Text::_('COM_CONTACT_ERROR_CONTACT_NOT_FOUND'), 404);
|
||||
}
|
||||
|
||||
/**
|
||||
* In case some entity params have been set to "use global", those are
|
||||
* represented as an empty string and must be "overridden" by merging
|
||||
* the component and / or menu params here.
|
||||
*/
|
||||
$registry = new Registry($data->params);
|
||||
|
||||
$data->params = clone $this->getState('params');
|
||||
$data->params->merge($registry);
|
||||
|
||||
$registry = new Registry($data->metadata);
|
||||
$data->metadata = $registry;
|
||||
|
||||
// Some contexts may not use tags data at all, so we allow callers to disable loading tag data
|
||||
if ($this->getState('load_tags', true)) {
|
||||
$data->tags = new TagsHelper();
|
||||
$data->tags->getItemTags('com_contact.contact', $data->id);
|
||||
}
|
||||
|
||||
// Compute access permissions.
|
||||
if (($access = $this->getState('filter.access'))) {
|
||||
// If the access filter has been set, we already know this user can view.
|
||||
$data->params->set('access-view', true);
|
||||
} else {
|
||||
// If no access filter is set, the layout takes some responsibility for display of limited information.
|
||||
$user = $this->getCurrentUser();
|
||||
$groups = $user->getAuthorisedViewLevels();
|
||||
|
||||
if ($data->catid == 0 || $data->category_access === null) {
|
||||
$data->params->set('access-view', \in_array($data->access, $groups));
|
||||
} else {
|
||||
$data->params->set('access-view', \in_array($data->access, $groups) && \in_array($data->category_access, $groups));
|
||||
}
|
||||
}
|
||||
|
||||
$this->_item[$pk] = $data;
|
||||
} catch (\Exception $e) {
|
||||
if ($e->getCode() == 404) {
|
||||
// Need to go through the error handler to allow Redirect to work.
|
||||
throw $e;
|
||||
}
|
||||
|
||||
$this->setError($e);
|
||||
$this->_item[$pk] = false;
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->_item[$pk]) {
|
||||
$this->buildContactExtendedData($this->_item[$pk]);
|
||||
}
|
||||
|
||||
return $this->_item[$pk];
|
||||
}
|
||||
|
||||
/**
|
||||
* Load extended data (profile, articles) for a contact
|
||||
*
|
||||
* @param object $contact The contact object
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function buildContactExtendedData($contact)
|
||||
{
|
||||
$db = $this->getDatabase();
|
||||
$nowDate = Factory::getDate()->toSql();
|
||||
$user = $this->getCurrentUser();
|
||||
$groups = $user->getAuthorisedViewLevels();
|
||||
$published = $this->getState('filter.published');
|
||||
$query = $db->getQuery(true);
|
||||
|
||||
// If we are showing a contact list, then the contact parameters take priority
|
||||
// So merge the contact parameters with the merged parameters
|
||||
if ($this->getState('params')->get('show_contact_list')) {
|
||||
$this->getState('params')->merge($contact->params);
|
||||
}
|
||||
|
||||
// Get the com_content articles by the linked user
|
||||
if ((int) $contact->user_id && $this->getState('params')->get('show_articles')) {
|
||||
$query->select('a.id')
|
||||
->select('a.title')
|
||||
->select('a.state')
|
||||
->select('a.access')
|
||||
->select('a.catid')
|
||||
->select('a.created')
|
||||
->select('a.language')
|
||||
->select('a.publish_up')
|
||||
->select('a.introtext')
|
||||
->select('a.images')
|
||||
->select($this->getSlugColumn($query, 'a.id', 'a.alias') . ' AS slug')
|
||||
->select($this->getSlugColumn($query, 'c.id', 'c.alias') . ' AS catslug')
|
||||
->from($db->quoteName('#__content', 'a'))
|
||||
->leftJoin($db->quoteName('#__categories', 'c') . ' ON a.catid = c.id')
|
||||
->where($db->quoteName('a.created_by') . ' = :created_by')
|
||||
->whereIn($db->quoteName('a.access'), $groups)
|
||||
->bind(':created_by', $contact->user_id, ParameterType::INTEGER)
|
||||
->order('a.publish_up DESC');
|
||||
|
||||
// Filter per language if plugin published
|
||||
if (Multilanguage::isEnabled()) {
|
||||
$language = [Factory::getLanguage()->getTag(), '*'];
|
||||
$query->whereIn($db->quoteName('a.language'), $language, ParameterType::STRING);
|
||||
}
|
||||
|
||||
if (is_numeric($published)) {
|
||||
$query->where('a.state IN (1,2)')
|
||||
->where('(' . $db->quoteName('a.publish_up') . ' IS NULL' .
|
||||
' OR ' . $db->quoteName('a.publish_up') . ' <= :now1)')
|
||||
->where('(' . $db->quoteName('a.publish_down') . ' IS NULL' .
|
||||
' OR ' . $db->quoteName('a.publish_down') . ' >= :now2)')
|
||||
->bind([':now1', ':now2'], $nowDate);
|
||||
}
|
||||
|
||||
// Number of articles to display from config/menu params
|
||||
$articles_display_num = $this->getState('params')->get('articles_display_num', 10);
|
||||
|
||||
// Use contact setting?
|
||||
if ($articles_display_num === 'use_contact') {
|
||||
$articles_display_num = $contact->params->get('articles_display_num', 10);
|
||||
|
||||
// Use global?
|
||||
if ((string) $articles_display_num === '') {
|
||||
$articles_display_num = ComponentHelper::getParams('com_contact')->get('articles_display_num', 10);
|
||||
}
|
||||
}
|
||||
|
||||
$query->setLimit((int) $articles_display_num);
|
||||
$db->setQuery($query);
|
||||
$contact->articles = $db->loadObjectList();
|
||||
} else {
|
||||
$contact->articles = null;
|
||||
}
|
||||
|
||||
// Get the profile information for the linked user
|
||||
$userModel = $this->bootComponent('com_users')->getMVCFactory()
|
||||
->createModel('User', 'Administrator', ['ignore_request' => true]);
|
||||
$data = $userModel->getItem((int) $contact->user_id);
|
||||
|
||||
PluginHelper::importPlugin('user');
|
||||
|
||||
// Get the form.
|
||||
Form::addFormPath(JPATH_SITE . '/components/com_users/forms');
|
||||
|
||||
$form = Form::getInstance('com_users.profile', 'profile');
|
||||
|
||||
// Trigger the form preparation event.
|
||||
Factory::getApplication()->triggerEvent('onContentPrepareForm', [$form, $data]);
|
||||
|
||||
// Trigger the data preparation event.
|
||||
Factory::getApplication()->triggerEvent('onContentPrepareData', ['com_users.profile', $data]);
|
||||
|
||||
// Load the data into the form after the plugins have operated.
|
||||
$form->bind($data);
|
||||
$contact->profile = $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate column expression for slug or catslug.
|
||||
*
|
||||
* @param QueryInterface $query Current query instance.
|
||||
* @param string $id Column id name.
|
||||
* @param string $alias Column alias name.
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
* @since 4.0.0
|
||||
*/
|
||||
private function getSlugColumn($query, $id, $alias)
|
||||
{
|
||||
return 'CASE WHEN '
|
||||
. $query->charLength($alias, '!=', '0')
|
||||
. ' THEN '
|
||||
. $query->concatenate([$query->castAsChar($id), $alias], ':')
|
||||
. ' ELSE '
|
||||
. $query->castAsChar($id) . ' END';
|
||||
}
|
||||
|
||||
/**
|
||||
* Increment the hit counter for the contact.
|
||||
*
|
||||
* @param integer $pk Optional primary key of the contact to increment.
|
||||
*
|
||||
* @return boolean True if successful; false otherwise and internal error set.
|
||||
*
|
||||
* @since 3.0
|
||||
*/
|
||||
public function hit($pk = 0)
|
||||
{
|
||||
$input = Factory::getApplication()->getInput();
|
||||
$hitcount = $input->getInt('hitcount', 1);
|
||||
|
||||
if ($hitcount) {
|
||||
$pk = $pk ?: (int) $this->getState('contact.id');
|
||||
|
||||
$table = $this->getTable('Contact');
|
||||
$table->hit($pk);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
207
components/com_contact/src/Model/FeaturedModel.php
Normal file
207
components/com_contact/src/Model/FeaturedModel.php
Normal file
@ -0,0 +1,207 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Joomla.Site
|
||||
* @subpackage com_contact
|
||||
*
|
||||
* @copyright (C) 2010 Open Source Matters, Inc. <https://www.joomla.org>
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace Joomla\Component\Contact\Site\Model;
|
||||
|
||||
use Joomla\CMS\Component\ComponentHelper;
|
||||
use Joomla\CMS\Factory;
|
||||
use Joomla\CMS\Language\Multilanguage;
|
||||
use Joomla\CMS\MVC\Model\ListModel;
|
||||
use Joomla\Database\ParameterType;
|
||||
use Joomla\Database\QueryInterface;
|
||||
use Joomla\Registry\Registry;
|
||||
|
||||
// phpcs:disable PSR1.Files.SideEffects
|
||||
\defined('_JEXEC') or die;
|
||||
// phpcs:enable PSR1.Files.SideEffects
|
||||
|
||||
/**
|
||||
* Featured contact model class.
|
||||
*
|
||||
* @since 1.6.0
|
||||
*/
|
||||
class FeaturedModel extends ListModel
|
||||
{
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param array $config An optional associative array of configuration settings.
|
||||
*
|
||||
* @since 1.6
|
||||
*/
|
||||
public function __construct($config = [])
|
||||
{
|
||||
if (empty($config['filter_fields'])) {
|
||||
$config['filter_fields'] = [
|
||||
'id', 'a.id',
|
||||
'name', 'a.name',
|
||||
'con_position', 'a.con_position',
|
||||
'suburb', 'a.suburb',
|
||||
'state', 'a.state',
|
||||
'country', 'a.country',
|
||||
'ordering', 'a.ordering',
|
||||
];
|
||||
}
|
||||
|
||||
parent::__construct($config);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to get a list of items.
|
||||
*
|
||||
* @return mixed An array of objects on success, false on failure.
|
||||
*/
|
||||
public function getItems()
|
||||
{
|
||||
// Invoke the parent getItems method to get the main list
|
||||
$items = parent::getItems();
|
||||
|
||||
// Convert the params field into an object, saving original in _params
|
||||
foreach ($items as $item) {
|
||||
if (!isset($this->_params)) {
|
||||
$item->params = new Registry($item->params);
|
||||
}
|
||||
}
|
||||
|
||||
return $items;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to build an SQL query to load the list data.
|
||||
*
|
||||
* @return QueryInterface An SQL query
|
||||
*
|
||||
* @since 1.6
|
||||
*/
|
||||
protected function getListQuery()
|
||||
{
|
||||
$user = $this->getCurrentUser();
|
||||
$groups = $user->getAuthorisedViewLevels();
|
||||
|
||||
// Create a new query object.
|
||||
$db = $this->getDatabase();
|
||||
$query = $db->getQuery(true);
|
||||
|
||||
// Select required fields from the categories.
|
||||
$query->select($this->getState('list.select', 'a.*'))
|
||||
->from($db->quoteName('#__contact_details', 'a'))
|
||||
->where($db->quoteName('a.featured') . ' = 1')
|
||||
->whereIn($db->quoteName('a.access'), $groups)
|
||||
->innerJoin($db->quoteName('#__categories', 'c') . ' ON c.id = a.catid')
|
||||
->whereIn($db->quoteName('c.access'), $groups);
|
||||
|
||||
// Filter by category.
|
||||
if ($categoryId = $this->getState('category.id')) {
|
||||
$query->where($db->quoteName('a.catid') . ' = :catid');
|
||||
$query->bind(':catid', $categoryId, ParameterType::INTEGER);
|
||||
}
|
||||
|
||||
$query->select('c.published as cat_published, c.published AS parents_published')
|
||||
->where('c.published = 1');
|
||||
|
||||
// Filter by state
|
||||
$state = $this->getState('filter.published');
|
||||
|
||||
if (is_numeric($state)) {
|
||||
$query->where($db->quoteName('a.published') . ' = :published');
|
||||
$query->bind(':published', $state, ParameterType::INTEGER);
|
||||
|
||||
// Filter by start and end dates.
|
||||
$nowDate = Factory::getDate()->toSql();
|
||||
|
||||
$query->where('(' . $db->quoteName('a.publish_up') .
|
||||
' IS NULL OR ' . $db->quoteName('a.publish_up') . ' <= :publish_up)')
|
||||
->where('(' . $db->quoteName('a.publish_down') .
|
||||
' IS NULL OR ' . $db->quoteName('a.publish_down') . ' >= :publish_down)')
|
||||
->bind(':publish_up', $nowDate)
|
||||
->bind(':publish_down', $nowDate);
|
||||
}
|
||||
|
||||
// Filter by search in title
|
||||
$search = $this->getState('list.filter');
|
||||
|
||||
// Filter by search in title
|
||||
if (!empty($search)) {
|
||||
$search = '%' . trim($search) . '%';
|
||||
$query->where($db->quoteName('a.name') . ' LIKE :name ');
|
||||
$query->bind(':name', $search);
|
||||
}
|
||||
|
||||
// Filter by language
|
||||
if ($this->getState('filter.language')) {
|
||||
$query->whereIn($db->quoteName('a.language'), [Factory::getLanguage()->getTag(), '*'], ParameterType::STRING);
|
||||
}
|
||||
|
||||
// Add the list ordering clause.
|
||||
$query->order($db->escape($this->getState('list.ordering', 'a.ordering')) . ' ' . $db->escape($this->getState('list.direction', 'ASC')));
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to auto-populate the model state.
|
||||
*
|
||||
* Note. Calling getState in this method will result in recursion.
|
||||
*
|
||||
* @param string $ordering An optional ordering field.
|
||||
* @param string $direction An optional direction (asc|desc).
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 1.6
|
||||
*/
|
||||
protected function populateState($ordering = null, $direction = null)
|
||||
{
|
||||
$app = Factory::getApplication();
|
||||
$input = $app->getInput();
|
||||
$params = ComponentHelper::getParams('com_contact');
|
||||
|
||||
// List state information
|
||||
$limit = $app->getUserStateFromRequest('global.list.limit', 'limit', $app->get('list_limit'), 'uint');
|
||||
$this->setState('list.limit', $limit);
|
||||
|
||||
$limitstart = $input->get('limitstart', 0, 'uint');
|
||||
$this->setState('list.start', $limitstart);
|
||||
|
||||
// Optional filter text
|
||||
$this->setState('list.filter', $input->getString('filter-search'));
|
||||
|
||||
$orderCol = $input->get('filter_order', 'ordering');
|
||||
|
||||
if (!\in_array($orderCol, $this->filter_fields)) {
|
||||
$orderCol = 'ordering';
|
||||
}
|
||||
|
||||
$this->setState('list.ordering', $orderCol);
|
||||
|
||||
$listOrder = $input->get('filter_order_Dir', 'ASC');
|
||||
|
||||
if (!\in_array(strtoupper($listOrder), ['ASC', 'DESC', ''])) {
|
||||
$listOrder = 'ASC';
|
||||
}
|
||||
|
||||
$this->setState('list.direction', $listOrder);
|
||||
|
||||
$user = $this->getCurrentUser();
|
||||
|
||||
if ((!$user->authorise('core.edit.state', 'com_contact')) && (!$user->authorise('core.edit', 'com_contact'))) {
|
||||
// Limit to published for people who can't edit or edit.state.
|
||||
$this->setState('filter.published', 1);
|
||||
|
||||
// Filter by start and end dates.
|
||||
$this->setState('filter.publish_date', true);
|
||||
}
|
||||
|
||||
$this->setState('filter.language', Multilanguage::isEnabled());
|
||||
|
||||
// Load the parameters.
|
||||
$this->setState('params', $params);
|
||||
}
|
||||
}
|
||||
237
components/com_contact/src/Model/FormModel.php
Normal file
237
components/com_contact/src/Model/FormModel.php
Normal file
@ -0,0 +1,237 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Joomla.Site
|
||||
* @subpackage com_contact
|
||||
*
|
||||
* @copyright (C) 2020 Open Source Matters, Inc. <https://www.joomla.org>
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace Joomla\Component\Contact\Site\Model;
|
||||
|
||||
use Joomla\CMS\Factory;
|
||||
use Joomla\CMS\Form\Form;
|
||||
use Joomla\CMS\Helper\TagsHelper;
|
||||
use Joomla\CMS\Language\Associations;
|
||||
use Joomla\CMS\Language\Multilanguage;
|
||||
use Joomla\CMS\Table\Table;
|
||||
use Joomla\Registry\Registry;
|
||||
use Joomla\Utilities\ArrayHelper;
|
||||
|
||||
// phpcs:disable PSR1.Files.SideEffects
|
||||
\defined('_JEXEC') or die;
|
||||
// phpcs:enable PSR1.Files.SideEffects
|
||||
|
||||
/**
|
||||
* Contact Component Contact Model
|
||||
*
|
||||
* @since 4.0.0
|
||||
*/
|
||||
class FormModel extends \Joomla\Component\Contact\Administrator\Model\ContactModel
|
||||
{
|
||||
/**
|
||||
* Model typeAlias string. Used for version history.
|
||||
*
|
||||
* @var string
|
||||
*
|
||||
* @since 4.0.0
|
||||
*/
|
||||
public $typeAlias = 'com_contact.contact';
|
||||
|
||||
/**
|
||||
* Name of the form
|
||||
*
|
||||
* @var string
|
||||
*
|
||||
* @since 4.0.0
|
||||
*/
|
||||
protected $formName = 'form';
|
||||
|
||||
/**
|
||||
* Method to get the row form.
|
||||
*
|
||||
* @param array $data Data for the form.
|
||||
* @param boolean $loadData True if the form is to load its own data (default case), false if not.
|
||||
*
|
||||
* @return Form|boolean A Form object on success, false on failure
|
||||
*
|
||||
* @since 4.0.0
|
||||
*/
|
||||
public function getForm($data = [], $loadData = true)
|
||||
{
|
||||
$form = parent::getForm($data, $loadData);
|
||||
|
||||
// Prevent messing with article language and category when editing existing contact with associations
|
||||
if ($id = $this->getState('contact.id') && Associations::isEnabled()) {
|
||||
$associations = Associations::getAssociations('com_contact', '#__contact_details', 'com_contact.item', $id);
|
||||
|
||||
// Make fields read only
|
||||
if (!empty($associations)) {
|
||||
$form->setFieldAttribute('language', 'readonly', 'true');
|
||||
$form->setFieldAttribute('language', 'filter', 'unset');
|
||||
}
|
||||
}
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to get contact data.
|
||||
*
|
||||
* @param integer $itemId The id of the contact.
|
||||
*
|
||||
* @return mixed Contact item data object on success, false on failure.
|
||||
*
|
||||
* @throws \Exception
|
||||
*
|
||||
* @since 4.0.0
|
||||
*/
|
||||
public function getItem($itemId = null)
|
||||
{
|
||||
$itemId = (int) (!empty($itemId)) ? $itemId : $this->getState('contact.id');
|
||||
|
||||
// Get a row instance.
|
||||
$table = $this->getTable();
|
||||
|
||||
// Attempt to load the row.
|
||||
try {
|
||||
if (!$table->load($itemId)) {
|
||||
return false;
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
Factory::getApplication()->enqueueMessage($e->getMessage());
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
$properties = $table->getProperties();
|
||||
$value = ArrayHelper::toObject($properties, \Joomla\CMS\Object\CMSObject::class);
|
||||
|
||||
// Convert field to Registry.
|
||||
$value->params = new Registry($value->params);
|
||||
|
||||
// Convert the metadata field to an array.
|
||||
$registry = new Registry($value->metadata);
|
||||
$value->metadata = $registry->toArray();
|
||||
|
||||
if ($itemId) {
|
||||
$value->tags = new TagsHelper();
|
||||
$value->tags->getTagIds($value->id, 'com_contact.contact');
|
||||
$value->metadata['tags'] = $value->tags;
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the return URL.
|
||||
*
|
||||
* @return string The return URL.
|
||||
*
|
||||
* @since 4.0.0
|
||||
*/
|
||||
public function getReturnPage()
|
||||
{
|
||||
return base64_encode($this->getState('return_page', ''));
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to save the form data.
|
||||
*
|
||||
* @param array $data The form data.
|
||||
*
|
||||
* @return boolean True on success.
|
||||
*
|
||||
* @since 4.0.0
|
||||
*
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function save($data)
|
||||
{
|
||||
// Associations are not edited in frontend ATM so we have to inherit them
|
||||
if (
|
||||
Associations::isEnabled() && !empty($data['id'])
|
||||
&& $associations = Associations::getAssociations('com_contact', '#__contact_details', 'com_contact.item', $data['id'])
|
||||
) {
|
||||
foreach ($associations as $tag => $associated) {
|
||||
$associations[$tag] = (int) $associated->id;
|
||||
}
|
||||
|
||||
$data['associations'] = $associations;
|
||||
}
|
||||
|
||||
return parent::save($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to auto-populate the model state.
|
||||
*
|
||||
* Note. Calling getState in this method will result in recursion.
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 4.0.0
|
||||
*
|
||||
* @throws \Exception
|
||||
*/
|
||||
protected function populateState()
|
||||
{
|
||||
$app = Factory::getApplication();
|
||||
$input = $app->getInput();
|
||||
|
||||
// Load state from the request.
|
||||
$pk = $input->getInt('id');
|
||||
$this->setState('contact.id', $pk);
|
||||
|
||||
$this->setState('contact.catid', $input->getInt('catid'));
|
||||
|
||||
$return = $input->get('return', '', 'base64');
|
||||
$this->setState('return_page', base64_decode($return));
|
||||
|
||||
// Load the parameters.
|
||||
$params = $app->getParams();
|
||||
$this->setState('params', $params);
|
||||
|
||||
$this->setState('layout', $input->getString('layout'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Allows preprocessing of the JForm object.
|
||||
*
|
||||
* @param Form $form The form object
|
||||
* @param array $data The data to be merged into the form object
|
||||
* @param string $group The plugin group to be executed
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 4.0.0
|
||||
*/
|
||||
protected function preprocessForm(Form $form, $data, $group = 'contact')
|
||||
{
|
||||
if (!Multilanguage::isEnabled()) {
|
||||
$form->setFieldAttribute('language', 'type', 'hidden');
|
||||
$form->setFieldAttribute('language', 'default', '*');
|
||||
}
|
||||
|
||||
parent::preprocessForm($form, $data, $group);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to get a table object, load it if necessary.
|
||||
*
|
||||
* @param string $name The table name. Optional.
|
||||
* @param string $prefix The class prefix. Optional.
|
||||
* @param array $options Configuration array for model. Optional.
|
||||
*
|
||||
* @return bool|Table A Table object
|
||||
*
|
||||
* @since 4.0.0
|
||||
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function getTable($name = 'Contact', $prefix = 'Administrator', $options = [])
|
||||
{
|
||||
return parent::getTable($name, $prefix, $options);
|
||||
}
|
||||
}
|
||||
59
components/com_contact/src/Rule/ContactEmailMessageRule.php
Normal file
59
components/com_contact/src/Rule/ContactEmailMessageRule.php
Normal file
@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Joomla.Site
|
||||
* @subpackage com_contact
|
||||
*
|
||||
* @copyright (C) 2017 Open Source Matters, Inc. <https://www.joomla.org>
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace Joomla\Component\Contact\Site\Rule;
|
||||
|
||||
use Joomla\CMS\Component\ComponentHelper;
|
||||
use Joomla\CMS\Form\Form;
|
||||
use Joomla\CMS\Form\FormRule;
|
||||
use Joomla\Registry\Registry;
|
||||
use Joomla\String\StringHelper;
|
||||
|
||||
// phpcs:disable PSR1.Files.SideEffects
|
||||
\defined('_JEXEC') or die;
|
||||
// phpcs:enable PSR1.Files.SideEffects
|
||||
|
||||
/**
|
||||
* FormRule for com_contact to make sure the message body contains no banned word.
|
||||
*
|
||||
* @since 1.6
|
||||
*/
|
||||
class ContactEmailMessageRule extends FormRule
|
||||
{
|
||||
/**
|
||||
* Method to test a message for banned words
|
||||
*
|
||||
* @param \SimpleXMLElement $element The SimpleXMLElement object representing the <field /> tag for the form field object.
|
||||
* @param mixed $value The form field value to validate.
|
||||
* @param string $group The field name group control value. This acts as an array container for the field.
|
||||
* For example if the field has name="foo" and the group value is set to "bar" then the
|
||||
* full field name would end up being "bar[foo]".
|
||||
* @param ?Registry $input An optional Registry object with the entire data set to validate against the entire form.
|
||||
* @param ?Form $form The form object for which the field is being tested.
|
||||
*
|
||||
* @return boolean True if the value is valid, false otherwise.
|
||||
*/
|
||||
public function test(\SimpleXMLElement $element, $value, $group = null, ?Registry $input = null, ?Form $form = null)
|
||||
{
|
||||
$params = ComponentHelper::getParams('com_contact');
|
||||
$banned = $params->get('banned_text');
|
||||
|
||||
if ($banned) {
|
||||
foreach (explode(';', $banned) as $item) {
|
||||
$item = trim($item);
|
||||
if ($item != '' && StringHelper::stristr($value, $item) !== false) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
63
components/com_contact/src/Rule/ContactEmailRule.php
Normal file
63
components/com_contact/src/Rule/ContactEmailRule.php
Normal file
@ -0,0 +1,63 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Joomla.Site
|
||||
* @subpackage com_contact
|
||||
*
|
||||
* @copyright (C) 2017 Open Source Matters, Inc. <https://www.joomla.org>
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace Joomla\Component\Contact\Site\Rule;
|
||||
|
||||
use Joomla\CMS\Component\ComponentHelper;
|
||||
use Joomla\CMS\Form\Form;
|
||||
use Joomla\CMS\Form\Rule\EmailRule;
|
||||
use Joomla\Registry\Registry;
|
||||
use Joomla\String\StringHelper;
|
||||
|
||||
// phpcs:disable PSR1.Files.SideEffects
|
||||
\defined('_JEXEC') or die;
|
||||
// phpcs:enable PSR1.Files.SideEffects
|
||||
|
||||
/**
|
||||
* FormRule for com_contact to make sure the email address is not blocked.
|
||||
*
|
||||
* @since 1.6
|
||||
*/
|
||||
class ContactEmailRule extends EmailRule
|
||||
{
|
||||
/**
|
||||
* Method to test for banned email addresses
|
||||
*
|
||||
* @param \SimpleXMLElement $element The SimpleXMLElement object representing the <field /> tag for the form field object.
|
||||
* @param mixed $value The form field value to validate.
|
||||
* @param string $group The field name group control value. This acts as an array container for the field.
|
||||
* For example if the field has name="foo" and the group value is set to "bar" then the
|
||||
* full field name would end up being "bar[foo]".
|
||||
* @param ?Registry $input An optional Registry object with the entire data set to validate against the entire form.
|
||||
* @param ?Form $form The form object for which the field is being tested.
|
||||
*
|
||||
* @return boolean True if the value is valid, false otherwise.
|
||||
*/
|
||||
public function test(\SimpleXMLElement $element, $value, $group = null, ?Registry $input = null, ?Form $form = null)
|
||||
{
|
||||
if (!parent::test($element, $value, $group, $input, $form)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$params = ComponentHelper::getParams('com_contact');
|
||||
$banned = $params->get('banned_email');
|
||||
|
||||
if ($banned) {
|
||||
foreach (explode(';', $banned) as $item) {
|
||||
$item = trim($item);
|
||||
if ($item != '' && StringHelper::stristr($value, $item) !== false) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
59
components/com_contact/src/Rule/ContactEmailSubjectRule.php
Normal file
59
components/com_contact/src/Rule/ContactEmailSubjectRule.php
Normal file
@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Joomla.Site
|
||||
* @subpackage com_contact
|
||||
*
|
||||
* @copyright (C) 2017 Open Source Matters, Inc. <https://www.joomla.org>
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace Joomla\Component\Contact\Site\Rule;
|
||||
|
||||
use Joomla\CMS\Component\ComponentHelper;
|
||||
use Joomla\CMS\Form\Form;
|
||||
use Joomla\CMS\Form\FormRule;
|
||||
use Joomla\Registry\Registry;
|
||||
use Joomla\String\StringHelper;
|
||||
|
||||
// phpcs:disable PSR1.Files.SideEffects
|
||||
\defined('_JEXEC') or die;
|
||||
// phpcs:enable PSR1.Files.SideEffects
|
||||
|
||||
/**
|
||||
* FormRule for com_contact to make sure the subject contains no banned word.
|
||||
*
|
||||
* @since 1.6
|
||||
*/
|
||||
class ContactEmailSubjectRule extends FormRule
|
||||
{
|
||||
/**
|
||||
* Method to test for a banned subject
|
||||
*
|
||||
* @param \SimpleXMLElement $element The SimpleXMLElement object representing the <field /> tag for the form field object.
|
||||
* @param mixed $value The form field value to validate.
|
||||
* @param string $group The field name group control value. This acts as an array container for the field.
|
||||
* For example if the field has name="foo" and the group value is set to "bar" then the
|
||||
* full field name would end up being "bar[foo]".
|
||||
* @param ?Registry $input An optional Registry object with the entire data set to validate against the entire form.
|
||||
* @param ?Form $form The form object for which the field is being tested.
|
||||
*
|
||||
* @return boolean True if the value is valid, false otherwise
|
||||
*/
|
||||
public function test(\SimpleXMLElement $element, $value, $group = null, ?Registry $input = null, ?Form $form = null)
|
||||
{
|
||||
$params = ComponentHelper::getParams('com_contact');
|
||||
$banned = $params->get('banned_subject');
|
||||
|
||||
if ($banned) {
|
||||
foreach (explode(';', $banned) as $item) {
|
||||
$item = trim($item);
|
||||
if ($item != '' && StringHelper::stristr($value, $item) !== false) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
41
components/com_contact/src/Service/Category.php
Normal file
41
components/com_contact/src/Service/Category.php
Normal file
@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Joomla.Site
|
||||
* @subpackage com_contact
|
||||
*
|
||||
* @copyright (C) 2009 Open Source Matters, Inc. <https://www.joomla.org>
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace Joomla\Component\Contact\Site\Service;
|
||||
|
||||
use Joomla\CMS\Categories\Categories;
|
||||
|
||||
// phpcs:disable PSR1.Files.SideEffects
|
||||
\defined('_JEXEC') or die;
|
||||
// phpcs:enable PSR1.Files.SideEffects
|
||||
|
||||
/**
|
||||
* Contact Component Category Tree
|
||||
*
|
||||
* @since 1.6
|
||||
*/
|
||||
class Category extends Categories
|
||||
{
|
||||
/**
|
||||
* Class constructor
|
||||
*
|
||||
* @param array $options Array of options
|
||||
*
|
||||
* @since 1.6
|
||||
*/
|
||||
public function __construct($options = [])
|
||||
{
|
||||
$options['table'] = '#__contact_details';
|
||||
$options['extension'] = 'com_contact';
|
||||
$options['statefield'] = 'published';
|
||||
|
||||
parent::__construct($options);
|
||||
}
|
||||
}
|
||||
287
components/com_contact/src/Service/Router.php
Normal file
287
components/com_contact/src/Service/Router.php
Normal file
@ -0,0 +1,287 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Joomla.Site
|
||||
* @subpackage com_contact
|
||||
*
|
||||
* @copyright (C) 2007 Open Source Matters, Inc. <https://www.joomla.org>
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace Joomla\Component\Contact\Site\Service;
|
||||
|
||||
use Joomla\CMS\Application\SiteApplication;
|
||||
use Joomla\CMS\Categories\CategoryFactoryInterface;
|
||||
use Joomla\CMS\Categories\CategoryInterface;
|
||||
use Joomla\CMS\Component\ComponentHelper;
|
||||
use Joomla\CMS\Component\Router\RouterView;
|
||||
use Joomla\CMS\Component\Router\RouterViewConfiguration;
|
||||
use Joomla\CMS\Component\Router\Rules\MenuRules;
|
||||
use Joomla\CMS\Component\Router\Rules\NomenuRules;
|
||||
use Joomla\CMS\Component\Router\Rules\StandardRules;
|
||||
use Joomla\CMS\Menu\AbstractMenu;
|
||||
use Joomla\Database\DatabaseInterface;
|
||||
use Joomla\Database\ParameterType;
|
||||
|
||||
// phpcs:disable PSR1.Files.SideEffects
|
||||
\defined('_JEXEC') or die;
|
||||
// phpcs:enable PSR1.Files.SideEffects
|
||||
|
||||
/**
|
||||
* Routing class from com_contact
|
||||
*
|
||||
* @since 3.3
|
||||
*/
|
||||
class Router extends RouterView
|
||||
{
|
||||
/**
|
||||
* Flag to remove IDs
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
protected $noIDs = false;
|
||||
|
||||
/**
|
||||
* The category factory
|
||||
*
|
||||
* @var CategoryFactoryInterface
|
||||
*
|
||||
* @since 4.0.0
|
||||
*/
|
||||
private $categoryFactory;
|
||||
|
||||
/**
|
||||
* The category cache
|
||||
*
|
||||
* @var array
|
||||
*
|
||||
* @since 4.0.0
|
||||
*/
|
||||
private $categoryCache = [];
|
||||
|
||||
/**
|
||||
* The db
|
||||
*
|
||||
* @var DatabaseInterface
|
||||
*
|
||||
* @since 4.0.0
|
||||
*/
|
||||
private $db;
|
||||
|
||||
/**
|
||||
* Content Component router constructor
|
||||
*
|
||||
* @param SiteApplication $app The application object
|
||||
* @param AbstractMenu $menu The menu object to work with
|
||||
* @param CategoryFactoryInterface $categoryFactory The category object
|
||||
* @param DatabaseInterface $db The database object
|
||||
*/
|
||||
public function __construct(SiteApplication $app, AbstractMenu $menu, CategoryFactoryInterface $categoryFactory, DatabaseInterface $db)
|
||||
{
|
||||
$this->categoryFactory = $categoryFactory;
|
||||
$this->db = $db;
|
||||
|
||||
$params = ComponentHelper::getParams('com_contact');
|
||||
$this->noIDs = (bool) $params->get('sef_ids');
|
||||
$categories = new RouterViewConfiguration('categories');
|
||||
$categories->setKey('id');
|
||||
$this->registerView($categories);
|
||||
$category = new RouterViewConfiguration('category');
|
||||
$category->setKey('id')->setParent($categories, 'catid')->setNestable();
|
||||
$this->registerView($category);
|
||||
$contact = new RouterViewConfiguration('contact');
|
||||
$contact->setKey('id')->setParent($category, 'catid');
|
||||
$this->registerView($contact);
|
||||
$this->registerView(new RouterViewConfiguration('featured'));
|
||||
$form = new RouterViewConfiguration('form');
|
||||
$form->setKey('id');
|
||||
$this->registerView($form);
|
||||
|
||||
parent::__construct($app, $menu);
|
||||
|
||||
$this->attachRule(new MenuRules($this));
|
||||
$this->attachRule(new StandardRules($this));
|
||||
$this->attachRule(new NomenuRules($this));
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to get the segment(s) for a category
|
||||
*
|
||||
* @param string $id ID of the category to retrieve the segments for
|
||||
* @param array $query The request that is built right now
|
||||
*
|
||||
* @return array|string The segments of this item
|
||||
*/
|
||||
public function getCategorySegment($id, $query)
|
||||
{
|
||||
$category = $this->getCategories()->get($id);
|
||||
|
||||
if ($category) {
|
||||
$path = array_reverse($category->getPath(), true);
|
||||
$path[0] = '1:root';
|
||||
|
||||
if ($this->noIDs) {
|
||||
foreach ($path as &$segment) {
|
||||
list($id, $segment) = explode(':', $segment, 2);
|
||||
}
|
||||
}
|
||||
|
||||
return $path;
|
||||
}
|
||||
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to get the segment(s) for a category
|
||||
*
|
||||
* @param string $id ID of the category to retrieve the segments for
|
||||
* @param array $query The request that is built right now
|
||||
*
|
||||
* @return array|string The segments of this item
|
||||
*/
|
||||
public function getCategoriesSegment($id, $query)
|
||||
{
|
||||
return $this->getCategorySegment($id, $query);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to get the segment(s) for a contact
|
||||
*
|
||||
* @param string $id ID of the contact to retrieve the segments for
|
||||
* @param array $query The request that is built right now
|
||||
*
|
||||
* @return array|string The segments of this item
|
||||
*/
|
||||
public function getContactSegment($id, $query)
|
||||
{
|
||||
if (!strpos($id, ':')) {
|
||||
$id = (int) $id;
|
||||
$dbquery = $this->db->getQuery(true);
|
||||
$dbquery->select($this->db->quoteName('alias'))
|
||||
->from($this->db->quoteName('#__contact_details'))
|
||||
->where($this->db->quoteName('id') . ' = :id')
|
||||
->bind(':id', $id, ParameterType::INTEGER);
|
||||
$this->db->setQuery($dbquery);
|
||||
|
||||
$id .= ':' . $this->db->loadResult();
|
||||
}
|
||||
|
||||
if ($this->noIDs) {
|
||||
list($void, $segment) = explode(':', $id, 2);
|
||||
|
||||
return [$void => $segment];
|
||||
}
|
||||
|
||||
return [(int) $id => $id];
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to get the segment(s) for a form
|
||||
*
|
||||
* @param string $id ID of the contact form to retrieve the segments for
|
||||
* @param array $query The request that is built right now
|
||||
*
|
||||
* @return array|string The segments of this item
|
||||
*
|
||||
* @since 4.0.0
|
||||
*/
|
||||
public function getFormSegment($id, $query)
|
||||
{
|
||||
return $this->getContactSegment($id, $query);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to get the id for a category
|
||||
*
|
||||
* @param string $segment Segment to retrieve the ID for
|
||||
* @param array $query The request that is parsed right now
|
||||
*
|
||||
* @return mixed The id of this item or false
|
||||
*/
|
||||
public function getCategoryId($segment, $query)
|
||||
{
|
||||
if (isset($query['id'])) {
|
||||
$category = $this->getCategories(['access' => false])->get($query['id']);
|
||||
|
||||
if ($category) {
|
||||
foreach ($category->getChildren() as $child) {
|
||||
if ($this->noIDs) {
|
||||
if ($child->alias == $segment) {
|
||||
return $child->id;
|
||||
}
|
||||
} else {
|
||||
if ($child->id == (int) $segment) {
|
||||
return $child->id;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to get the segment(s) for a category
|
||||
*
|
||||
* @param string $segment Segment to retrieve the ID for
|
||||
* @param array $query The request that is parsed right now
|
||||
*
|
||||
* @return mixed The id of this item or false
|
||||
*/
|
||||
public function getCategoriesId($segment, $query)
|
||||
{
|
||||
return $this->getCategoryId($segment, $query);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to get the segment(s) for a contact
|
||||
*
|
||||
* @param string $segment Segment of the contact to retrieve the ID for
|
||||
* @param array $query The request that is parsed right now
|
||||
*
|
||||
* @return mixed The id of this item or false
|
||||
*/
|
||||
public function getContactId($segment, $query)
|
||||
{
|
||||
if ($this->noIDs) {
|
||||
$dbquery = $this->db->getQuery(true);
|
||||
$dbquery->select($this->db->quoteName('id'))
|
||||
->from($this->db->quoteName('#__contact_details'))
|
||||
->where($this->db->quoteName('alias') . ' = :alias')
|
||||
->bind(':alias', $segment);
|
||||
|
||||
if (isset($query['id']) && $query['id']) {
|
||||
$dbquery->where($this->db->quoteName('catid') . ' = :catid')
|
||||
->bind(':catid', $query['id'], ParameterType::INTEGER);
|
||||
}
|
||||
|
||||
$this->db->setQuery($dbquery);
|
||||
|
||||
return (int) $this->db->loadResult();
|
||||
}
|
||||
|
||||
return (int) $segment;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to get categories from cache
|
||||
*
|
||||
* @param array $options The options for retrieving categories
|
||||
*
|
||||
* @return CategoryInterface The object containing categories
|
||||
*
|
||||
* @since 4.0.0
|
||||
*/
|
||||
private function getCategories(array $options = []): CategoryInterface
|
||||
{
|
||||
$key = serialize($options);
|
||||
|
||||
if (!isset($this->categoryCache[$key])) {
|
||||
$this->categoryCache[$key] = $this->categoryFactory->createCategory($options);
|
||||
}
|
||||
|
||||
return $this->categoryCache[$key];
|
||||
}
|
||||
}
|
||||
39
components/com_contact/src/View/Categories/HtmlView.php
Normal file
39
components/com_contact/src/View/Categories/HtmlView.php
Normal file
@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Joomla.Site
|
||||
* @subpackage com_contact
|
||||
*
|
||||
* @copyright (C) 2008 Open Source Matters, Inc. <https://www.joomla.org>
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace Joomla\Component\Contact\Site\View\Categories;
|
||||
|
||||
use Joomla\CMS\MVC\View\CategoriesView;
|
||||
|
||||
// phpcs:disable PSR1.Files.SideEffects
|
||||
\defined('_JEXEC') or die;
|
||||
// phpcs:enable PSR1.Files.SideEffects
|
||||
|
||||
/**
|
||||
* Contact categories view.
|
||||
*
|
||||
* @since 1.6
|
||||
*/
|
||||
class HtmlView extends CategoriesView
|
||||
{
|
||||
/**
|
||||
* Language key for default page heading
|
||||
*
|
||||
* @var string
|
||||
* @since 3.2
|
||||
*/
|
||||
protected $pageHeading = 'COM_CONTACT_DEFAULT_PAGE_TITLE';
|
||||
|
||||
/**
|
||||
* @var string The name of the extension for the category
|
||||
* @since 3.2
|
||||
*/
|
||||
protected $extension = 'com_contact';
|
||||
}
|
||||
48
components/com_contact/src/View/Category/FeedView.php
Normal file
48
components/com_contact/src/View/Category/FeedView.php
Normal file
@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Joomla.Site
|
||||
* @subpackage com_contact
|
||||
*
|
||||
* @copyright (C) 2006 Open Source Matters, Inc. <https://www.joomla.org>
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace Joomla\Component\Contact\Site\View\Category;
|
||||
|
||||
use Joomla\CMS\MVC\View\CategoryFeedView;
|
||||
|
||||
// phpcs:disable PSR1.Files.SideEffects
|
||||
\defined('_JEXEC') or die;
|
||||
// phpcs:enable PSR1.Files.SideEffects
|
||||
|
||||
/**
|
||||
* HTML View class for the Contact component
|
||||
*
|
||||
* @since 1.5
|
||||
*/
|
||||
class FeedView extends CategoryFeedView
|
||||
{
|
||||
/**
|
||||
* @var string The name of the view to link individual items to
|
||||
* @since 3.2
|
||||
*/
|
||||
protected $viewName = 'contact';
|
||||
|
||||
/**
|
||||
* Method to reconcile non standard names from components to usage in this class.
|
||||
* Typically overridden in the component feed view class.
|
||||
*
|
||||
* @param object $item The item for a feed, an element of the $items array.
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 3.2
|
||||
*/
|
||||
protected function reconcileNames($item)
|
||||
{
|
||||
parent::reconcileNames($item);
|
||||
|
||||
$item->description = $item->address;
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user