PageRenderTime 45ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/components/com_media/media.php

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