/web herbalspa.net php/web herbalspa.net/administrator/components/com_media/models/manager.php

https://gitlab.com/phamngsinh/baitaplon_sinhvien · PHP · 135 lines · 83 code · 25 blank · 27 comment · 10 complexity · b51ffd51972839a9b9b6c6ad9e835fae MD5 · raw file

  1. <?php
  2. /**
  3. * @copyright Copyright (C) 2005 - 2012 Open Source Matters, Inc. All rights reserved.
  4. * @license GNU General Public License version 2 or later; see LICENSE.txt
  5. */
  6. defined('_JEXEC') or die;
  7. /**
  8. * Media Component Manager Model
  9. *
  10. * @package Joomla.Administrator
  11. * @subpackage com_media
  12. * @since 1.5
  13. */
  14. class MediaModelManager extends JModelLegacy
  15. {
  16. function getState($property = null, $default = null)
  17. {
  18. static $set;
  19. if (!$set) {
  20. $folder = JRequest::getVar('folder', '', '', 'path');
  21. $this->setState('folder', $folder);
  22. $fieldid = JRequest::getCmd('fieldid', '');
  23. $this->setState('field.id', $fieldid);
  24. $parent = str_replace("\\", "/", dirname($folder));
  25. $parent = ($parent == '.') ? null : $parent;
  26. $this->setState('parent', $parent);
  27. $set = true;
  28. }
  29. return parent::getState($property, $default);
  30. }
  31. /**
  32. * Image Manager Popup
  33. *
  34. * @param string $listFolder The image directory to display
  35. * @since 1.5
  36. */
  37. function getFolderList($base = null)
  38. {
  39. // Get some paths from the request
  40. if (empty($base)) {
  41. $base = COM_MEDIA_BASE;
  42. }
  43. //corrections for windows paths
  44. $base = str_replace(DIRECTORY_SEPARATOR, '/', $base);
  45. $com_media_base_uni = str_replace(DIRECTORY_SEPARATOR, '/', COM_MEDIA_BASE);
  46. // Get the list of folders
  47. jimport('joomla.filesystem.folder');
  48. $folders = JFolder::folders($base, '.', true, true);
  49. $document = JFactory::getDocument();
  50. $document->setTitle(JText::_('COM_MEDIA_INSERT_IMAGE'));
  51. // Build the array of select options for the folder list
  52. $options[] = JHtml::_('select.option', "", "/");
  53. foreach ($folders as $folder)
  54. {
  55. $folder = str_replace($com_media_base_uni, "", str_replace(DIRECTORY_SEPARATOR, '/', $folder));
  56. $value = substr($folder, 1);
  57. $text = str_replace(DIRECTORY_SEPARATOR, "/", $folder);
  58. $options[] = JHtml::_('select.option', $value, $text);
  59. }
  60. // Sort the folder list array
  61. if (is_array($options)) {
  62. sort($options);
  63. }
  64. // Get asset and author id (use integer filter)
  65. $input = JFactory::getApplication()->input;
  66. $asset = $input->get('asset', 0, 'integer');
  67. $author = $input->get('author', 0, 'integer');
  68. // Create the drop-down folder select list
  69. $list = JHtml::_('select.genericlist', $options, 'folderlist', 'class="inputbox" size="1" onchange="ImageManager.setFolder(this.options[this.selectedIndex].value, '.$asset.', '.$author.')" ', 'value', 'text', $base);
  70. return $list;
  71. }
  72. function getFolderTree($base = null)
  73. {
  74. // Get some paths from the request
  75. if (empty($base)) {
  76. $base = COM_MEDIA_BASE;
  77. }
  78. $mediaBase = str_replace(DIRECTORY_SEPARATOR, '/', COM_MEDIA_BASE.'/');
  79. // Get the list of folders
  80. jimport('joomla.filesystem.folder');
  81. $folders = JFolder::folders($base, '.', true, true);
  82. $tree = array();
  83. foreach ($folders as $folder)
  84. {
  85. $folder = str_replace(DIRECTORY_SEPARATOR, '/', $folder);
  86. $name = substr($folder, strrpos($folder, '/') + 1);
  87. $relative = str_replace($mediaBase, '', $folder);
  88. $absolute = $folder;
  89. $path = explode('/', $relative);
  90. $node = (object) array('name' => $name, 'relative' => $relative, 'absolute' => $absolute);
  91. $tmp = &$tree;
  92. for ($i=0, $n=count($path); $i<$n; $i++)
  93. {
  94. if (!isset($tmp['children'])) {
  95. $tmp['children'] = array();
  96. }
  97. if ($i == $n-1) {
  98. // We need to place the node
  99. $tmp['children'][$relative] = array('data' =>$node, 'children' => array());
  100. break;
  101. }
  102. if (array_key_exists($key = implode('/', array_slice($path, 0, $i+1)), $tmp['children'])) {
  103. $tmp = &$tmp['children'][$key];
  104. }
  105. }
  106. }
  107. $tree['data'] = (object) array('name' => JText::_('COM_MEDIA_MEDIA'), 'relative' => '', 'absolute' => $base);
  108. return $tree;
  109. }
  110. }