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: public function __construct($mode = null) {
58:
59: if (false === isset($mode)) {
60: echo '[]';
61: return;
62: }
63:
64: $list = array();
65:
66: switch ($mode) {
67: case 'image':
68: $list = $this->_buildImageList();
69: break;
70: case 'link':
71: $list = $this->_buildLinkList();
72: break;
73: default:
74:
75: }
76:
77: $this->_printList($list);
78: }
79:
80: 81: 82: 83:
84: private function _buildImageList() {
85: $client = cRegistry::getClientId();
86: $clientConfig = cRegistry::getClientConfig($client);
87:
88:
89: $oApiUploadCol = new cApiUploadCollection();
90:
91:
92:
93: $selectClause = "idclient='" . cSecurity::toInteger($client) . "' AND filetype IN ('gif', 'jpg', 'jpeg', 'png')";
94: $oApiUploadCol->select($selectClause, '', 'dirname, filename ASC');
95:
96:
97:
98:
99: $aUplList = $oApiUploadCol->fetchArray($oApiUploadCol->getPrimaryKeyName(), array('idclient', 'dirname', 'filetype', 'filename'));
100:
101: $imageList = array();
102: foreach ($aUplList as $uplItem) {
103: $imageItem = new stdClass();
104: $imageItem->title = $uplItem['dirname'] . $uplItem['filename'];
105: $imageItem->value = $clientConfig['upload'] . $uplItem['dirname'] . $uplItem['filename'];
106:
107: $imageList[] = $imageItem;
108: }
109:
110: return $imageList;
111: }
112:
113: 114: 115: 116: 117: 118: 119:
120: private function _addToWoodTree($woodTree, $lvl, $entry) {
121:
122: if ($lvl === 0) {
123: $woodTree[] = $entry;
124: return $woodTree;
125: }
126:
127:
128: $res = unserialize(serialize($woodTree));
129:
130:
131: $scope = &$res;
132: for ($i = $lvl; $i > 0; $i--) {
133:
134: end($scope);
135:
136: $scope = &$scope[key($scope)];
137:
138: if (false === isset($scope->menu)) {
139: $scope->menu = array();
140: }
141:
142: $scope = &$scope->menu;
143: }
144:
145:
146:
147: $scope[] = $entry;
148:
149:
150: return $res;
151:
152: }
153:
154: 155: 156: 157:
158: private function _buildLinkList() {
159: global $client, $lang;
160:
161: $linkList = array();
162:
163: $catTree = new cApiCategoryTreeCollection();
164: $catList = $catTree->getCategoryTreeStructureByClientIdAndLanguageId($client, $lang);
165:
166: foreach ($catList as $catEntry) {
167: $tmp_catname = $catEntry['name'];
168: if ($catEntry['visible'] == 0) {
169: $tmp_catname = "[" . $tmp_catname . "]";
170: }
171: $listEntry = (object) array('title' => $tmp_catname,
172: 'value' => 'front_content.php?idcat=' . $catEntry['idcat']);
173:
174: $linkList = $this->_addToWoodTree($linkList, (int) $catEntry['level'], $listEntry);
175:
176: $options = array();
177: $options['idcat'] = $catEntry['idcat'];
178:
179: $options['order'] = 'title';
180:
181: $options['direction'] = 'asc';
182:
183: $options['start'] = true;
184:
185: $options['offline'] = true;
186:
187:
188:
189: $articleCollector = new cArticleCollector($options);
190:
191:
192: if (0 === count($articleCollector)) {
193: continue;
194: }
195:
196: $listEntry->menu = array();
197: $listEntry->menu[] = (object) array('title' => $tmp_catname . ' ' . i18n('Category'),
198: 'value' => 'front_content.php?idcat=' . $catEntry['idcat']
199: );
200:
201: foreach ($articleCollector as $articleLanguage) {
202: $tmp_title = $articleLanguage->get("title");
203:
204: if (strlen($tmp_title) > 32) {
205: $tmp_title = substr($tmp_title, 0, 32);
206: }
207:
208: $is_start = isStartArticle($articleLanguage->get('idartlang'), $catEntry['idcat'], $lang);
209:
210: if ($is_start) {
211: $tmp_title .= "*";
212: }
213:
214: if ('0' === $articleLanguage->get("online")) {
215: $tmp_title = "[" . $tmp_title . "]";
216: }
217: $articleEntry = new stdClass();
218: $articleEntry->title = $tmp_title;
219: $articleEntry->value = 'front_content.php?idart=' . $articleLanguage->get('idart');
220: $listEntry->menu[] = $articleEntry;
221: }
222: }
223: return $linkList;
224: }
225:
226: 227: 228:
229: private function _printList($list) {
230: echo json_encode($list);
231: }
232: }
233: ?>