forked from mattias-ohlsson/joomla-example
/
media.php
86 lines (71 loc) · 2.76 KB
/
media.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
<?php
/**
* @package Joomla.Site
* @subpackage com_media
* @copyright Copyright (C) 2005 - 2012 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
// no direct access
defined('_JEXEC') or die;
$params = JComponentHelper::getParams('com_media');
// Make sure the user is authorized to view this page
$user = JFactory::getUser();
$asset = JRequest::getCmd('asset');
$author = JRequest::getCmd('author');
if (!$asset or
!$user->authorise('core.edit', $asset)
&& !$user->authorise('core.create', $asset)
&& count($user->getAuthorisedCategories($asset, 'core.create')) == 0
&& !($user->id==$author && $user->authorise('core.edit.own', $asset)))
{
return JError::raiseWarning(403, JText::_('JERROR_ALERTNOAUTHOR'));
}
// Set the path definitions
define('COM_MEDIA_BASE', JPATH_ROOT.'/'.$params->get('image_path', 'images'));
define('COM_MEDIA_BASEURL', JURI::root().'/'.$params->get('image_path', 'images'));
$lang = JFactory::getLanguage();
$lang->load('com_media', JPATH_ADMINISTRATOR, null, false, false)
|| $lang->load('com_media', JPATH_SITE, null, false, false)
|| $lang->load('com_media', JPATH_ADMINISTRATOR, $lang->getDefault(), false, false);
// Load the admin HTML view
require_once JPATH_COMPONENT_ADMINISTRATOR.'/helpers/media.php';
// Require the base controller
require_once JPATH_COMPONENT.'/controller.php';
// Make sure the user is authorized to view this page
$user = JFactory::getUser();
$app = JFactory::getApplication();
$cmd = JRequest::getCmd('task', null);
if (strpos($cmd, '.') != false) {
// We have a defined controller/task pair -- lets split them out
list($controllerName, $task) = explode('.', $cmd);
// Define the controller name and path
$controllerName = strtolower($controllerName);
$controllerPath = JPATH_COMPONENT_ADMINISTRATOR.'/controllers/'.$controllerName.'.php';
// If the controller file path exists, include it ... else lets die with a 500 error
if (file_exists($controllerPath)) {
require_once $controllerPath;
}
else {
JError::raiseError(500, JText::_('JERROR_INVALID_CONTROLLER'));
}
}
else {
// Base controller, just set the task :)
$controllerName = null;
$task = $cmd;
}
// Set the name for the controller and instantiate it
$controllerClass = 'MediaController'.ucfirst($controllerName);
if (class_exists($controllerClass)) {
$controller = new $controllerClass();
}
else {
JError::raiseError(500, JText::_('JERROR_INVALID_CONTROLLER_CLASS'));
}
// Set the model and view paths to the administrator folders
$controller->addViewPath(JPATH_COMPONENT_ADMINISTRATOR.'/views');
$controller->addModelPath(JPATH_COMPONENT_ADMINISTRATOR.'/models');
// Perform the Request task
$controller->execute($task);
// Redirect if set by the controller
$controller->redirect();