1: <?php
2: /**
3: * Magento
4: *
5: * NOTICE OF LICENSE
6: *
7: * This source file is subject to the Open Software License (OSL 3.0)
8: * that is bundled with this package in the file LICENSE.txt.
9: * It is also available through the world-wide-web at this URL:
10: * http://opensource.org/licenses/osl-3.0.php
11: * If you did not receive a copy of the license and are unable to
12: * obtain it through the world-wide-web, please send an email
13: * to license@magentocommerce.com so we can send you a copy immediately.
14: *
15: * DISCLAIMER
16: *
17: * Do not edit or add to this file if you wish to upgrade Magento to newer
18: * versions in the future. If you wish to customize Magento for your
19: * needs please refer to http://www.magentocommerce.com for more information.
20: *
21: * @category Mage
22: * @package Mage_Adminhtml
23: * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24: * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25: */
26:
27: /**
28: * Directoty tree renderer for Cms Wysiwyg Images
29: *
30: * @category Mage
31: * @package Mage_Adminhtml
32: * @author Magento Core Team <core@magentocommerce.com>
33: */
34: class Mage_Adminhtml_Block_Cms_Wysiwyg_Images_Tree extends Mage_Adminhtml_Block_Template
35: {
36:
37: /**
38: * Json tree builder
39: *
40: * @return string
41: */
42: public function getTreeJson()
43: {
44: $helper = Mage::helper('cms/wysiwyg_images');
45: $storageRoot = $helper->getStorageRoot();
46: $collection = Mage::registry('storage')->getDirsCollection($helper->getCurrentPath());
47: $jsonArray = array();
48: foreach ($collection as $item) {
49: $jsonArray[] = array(
50: 'text' => $helper->getShortFilename($item->getBasename(), 20),
51: 'id' => $helper->convertPathToId($item->getFilename()),
52: 'cls' => 'folder'
53: );
54: }
55: return Zend_Json::encode($jsonArray);
56: }
57:
58: /**
59: * Json source URL
60: *
61: * @return string
62: */
63: public function getTreeLoaderUrl()
64: {
65: return $this->getUrl('*/*/treeJson');
66: }
67:
68: /**
69: * Root node name of tree
70: *
71: * @return string
72: */
73: public function getRootNodeName()
74: {
75: return $this->helper('cms')->__('Storage Root');
76: }
77:
78: /**
79: * Return tree node full path based on current path
80: *
81: * @return string
82: */
83: public function getTreeCurrentPath()
84: {
85: $treePath = '/root';
86: if ($path = Mage::registry('storage')->getSession()->getCurrentPath()) {
87: $helper = Mage::helper('cms/wysiwyg_images');
88: $path = str_replace($helper->getStorageRoot(), '', $path);
89: $relative = '';
90: foreach (explode(DS, $path) as $dirName) {
91: if ($dirName) {
92: $relative .= DS . $dirName;
93: $treePath .= '/' . $helper->idEncode($relative);
94: }
95: }
96: }
97: return $treePath;
98: }
99: }
100: