1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22:
23:
24: if (!defined('CON_FRAMEWORK')) {
25: define('CON_FRAMEWORK', true);
26: }
27:
28:
29: $contenido_path = str_replace('\\', '/', realpath(dirname(__FILE__) . '/../../../../../')) . '/';
30:
31: if (!is_file($contenido_path . 'includes/startup.php')) {
32: die("<h1>Fatal Error</h1><br>Couldn't include CONTENIDO startup.");
33: }
34: include_once($contenido_path . 'includes/startup.php');
35:
36: cRegistry::bootstrap(array(
37: 'sess' => 'cSession',
38: 'auth' => 'cAuthHandlerBackend',
39: 'perm' => 'cPermission'
40: ));
41:
42:
43: include(dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR . 'config.php');
44:
45: $db = cRegistry::getDb();
46:
47: cInclude('includes', 'functions.lang.php');
48:
49: $mediaList = new cTinyMCE4List($_GET['mode']);
50:
51: 52:
53: class cTinyMCE4List {
54:
55: 56: 57:
58: public function __construct($mode = null) {
59:
60: if (false === isset($mode)) {
61: echo '[]';
62: return;
63: }
64:
65: $list = array();
66:
67: switch ($mode) {
68: case 'image':
69: $list = $this->_buildImageList();
70: break;
71: case 'link':
72: $list = $this->_buildLinkList();
73: break;
74: default:
75:
76: }
77:
78: $this->_printList($list);
79: }
80:
81: 82: 83: 84:
85: private function _buildImageList() {
86: $client = cRegistry::getClientId();
87: $clientConfig = cRegistry::getClientConfig($client);
88:
89:
90: $oApiUploadCol = new cApiUploadCollection();
91:
92:
93:
94: $selectClause = "idclient='" . cSecurity::toInteger($client) . "' AND filetype IN ('gif', 'jpg', 'jpeg', 'png')";
95: $oApiUploadCol->select($selectClause, '', 'dirname, filename ASC');
96:
97:
98:
99:
100: $aUplList = $oApiUploadCol->fetchArray($oApiUploadCol->getPrimaryKeyName(), array('idclient', 'dirname', 'filetype', 'filename'));
101:
102: $imageList = array();
103: foreach ($aUplList as $uplItem) {
104: $imageItem = new stdClass();
105: $imageItem->title = $uplItem['dirname'] . $uplItem['filename'];
106: $imageItem->value = $clientConfig['upload'] . $uplItem['dirname'] . $uplItem['filename'];
107:
108: $imageList[] = $imageItem;
109: }
110:
111: return $imageList;
112: }
113:
114: 115: 116: 117: 118: 119: 120:
121: private function _addToWoodTree($woodTree, $lvl, $entry) {
122:
123: if ($lvl === 0) {
124: $woodTree[] = $entry;
125: return $woodTree;
126: }
127:
128:
129: $res = unserialize(serialize($woodTree));
130:
131:
132: $scope = &$res;
133: for ($i = $lvl; $i > 0; $i--) {
134:
135: end($scope);
136:
137: $scope = &$scope[key($scope)];
138:
139: if (false === isset($scope->menu)) {
140: $scope->menu = array();
141: }
142:
143: $scope = &$scope->menu;
144: }
145:
146:
147:
148: $scope[] = $entry;
149:
150:
151: return $res;
152:
153: }
154:
155: 156: 157: 158:
159: private function _buildLinkList() {
160: global $client, $lang;
161:
162: $linkList = array();
163:
164: $catTree = new cApiCategoryTreeCollection();
165: $catList = $catTree->getCategoryTreeStructureByClientIdAndLanguageId($client, $lang);
166:
167: foreach ($catList as $catEntry) {
168: $tmp_catname = $catEntry['name'];
169: if ($catEntry['visible'] == 0) {
170: $tmp_catname = "[" . $tmp_catname . "]";
171: }
172: $listEntry = (object) array('title' => $tmp_catname,
173: 'value' => 'front_content.php?idcat=' . $catEntry['idcat']);
174:
175: $linkList = $this->_addToWoodTree($linkList, (int) $catEntry['level'], $listEntry);
176:
177: $options = array();
178: $options['idcat'] = $catEntry['idcat'];
179:
180: $options['order'] = 'title';
181:
182: $options['direction'] = 'asc';
183:
184: $options['start'] = true;
185:
186: $options['offline'] = true;
187:
188:
189:
190: $articleCollector = new cArticleCollector($options);
191:
192:
193: if (0 === count($articleCollector)) {
194: continue;
195: }
196:
197: $listEntry->menu = array();
198: $listEntry->menu[] = (object) array('title' => $tmp_catname . ' ' . i18n('Category'),
199: 'value' => 'front_content.php?idcat=' . $catEntry['idcat']
200: );
201:
202: foreach ($articleCollector as $articleLanguage) {
203: $tmp_title = $articleLanguage->get("title");
204:
205: if (cString::getStringLength($tmp_title) > 32) {
206: $tmp_title = cString::getPartOfString($tmp_title, 0, 32);
207: }
208:
209: $is_start = isStartArticle($articleLanguage->get('idartlang'), $catEntry['idcat'], $lang);
210:
211: if ($is_start) {
212: $tmp_title .= "*";
213: }
214:
215: if ('0' === $articleLanguage->get("online")) {
216: $tmp_title = "[" . $tmp_title . "]";
217: }
218: $articleEntry = new stdClass();
219: $articleEntry->title = $tmp_title;
220: $articleEntry->value = 'front_content.php?idart=' . $articleLanguage->get('idart');
221: $listEntry->menu[] = $articleEntry;
222: }
223: }
224: return $linkList;
225: }
226:
227: 228: 229:
230: private function _printList($list) {
231: echo json_encode($list);
232: }
233: }
234: ?>