1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13:
14:
15: defined('CON_FRAMEWORK') || die('Illegal call: Missing framework initialization - request aborted.');
16:
17: 18: 19: 20: 21: 22:
23: class cAjaxRequest {
24:
25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74:
75: public function handle($action) {
76: $backendPath = cRegistry::getBackendPath();
77: $frontendURL = cRegistry::getFrontendUrl();
78: $frontendPath = cRegistry::getFrontendPath();
79:
80: $string = '';
81: switch ($action) {
82: case 'artsel':
83: $name = (string) $_REQUEST['name'];
84: $idcat = (int) $_REQUEST['idcat'];
85: $value = (int) $_REQUEST['value'];
86:
87: $string = buildArticleSelect($name, $idcat, $value);
88: break;
89:
90: case 'dirlist':
91:
92: $idartlang = (int) $_REQUEST['idartlang'];
93: $fileListId = (int) $_REQUEST['id'];
94: $dirname = (string) $_REQUEST['dir'];
95:
96: global $cfgClient, $client;
97: $uplPath = $cfgClient[$client]['upl']['path'];
98:
99: $art = new cApiArticleLanguage($idartlang, true);
100: $content = $art->getContent('CMS_FILELIST', $fileListId);
101:
102: $fileList = new cContentTypeFilelist($content, $fileListId, array());
103: $directoryList = $fileList->buildDirectoryList($uplPath . $dirname);
104: $string = $fileList->generateDirectoryList($directoryList);
105: break;
106:
107: case 'filelist':
108: $idartlang = (int) $_REQUEST['idartlang'];
109: $fileListId = (int) $_REQUEST['id'];
110: $dirname = (string) $_REQUEST['dir'];
111:
112: $art = new cApiArticleLanguage($idartlang, true);
113: $content = $art->getContent('CMS_FILELIST', $fileListId);
114:
115: $fileList = new cContentTypeFilelist($content, $fileListId, array());
116: $string = $fileList->generateFileSelect($dirname);
117: break;
118:
119: case 'inused_layout':
120: global $cfg;
121: if (0 < (int) $_REQUEST['id']) {
122: $layout = new cApiLayout((int) $_REQUEST['id']);
123: if ($layout->isInUse(true)) {
124: $template = new cTemplate();
125: $usedTemplates = $layout->getUsedTemplates();
126: if (count($usedTemplates) > 0) {
127: foreach ($usedTemplates as $i => $usedTemplate) {
128: if ($i % 2 == 0) {
129: $template->set('d', 'CLASS', 'grey');
130: } else {
131: $template->set('d', 'CLASS', 'white');
132: }
133: $template->set('d', 'NAME', $usedTemplate['tpl_name']);
134: $template->next();
135: }
136:
137: $string = '<div class="inuse_info" >' . $template->generate($backendPath . $cfg['path']['templates'] . $cfg['templates']['inuse_lay_mod'], true) . '</div>';
138: } else {
139: $string = i18n('No data found!');
140: }
141: }
142: }
143: break;
144:
145: case 'inused_module':
146: global $cfg;
147: $module = new cApiModule();
148: if ((int) $_REQUEST['id'] > 0 && $module->moduleInUse((int) $_REQUEST['id'], true)) {
149: $template = new cTemplate();
150: $usedTemplates = $module->getUsedTemplates();
151: if (count($usedTemplates) > 0) {
152: foreach ($usedTemplates as $i => $usedTemplate) {
153: if ($i % 2 == 0) {
154: $template->set('d', 'CLASS', 'grey');
155: } else {
156: $template->set('d', 'CLASS', 'white');
157: }
158:
159: $template->set('d', 'NAME', $usedTemplate['tpl_name']);
160: $template->next();
161: }
162:
163: $string = '<div class="inuse_info" >' . $template->generate($backendPath . $cfg['path']['templates'] . $cfg['templates']['inuse_lay_mod'], true) . '</div>';
164: } else {
165: $string = i18n('No data found!');
166: }
167: }
168: break;
169:
170: case 'inused_template':
171: global $cfg;
172: cInclude('backend', 'includes/functions.tpl.php');
173:
174: if ((int) $_REQUEST['id'] > 0) {
175: $template = new cTemplate();
176: $template->reset();
177: $usedData = tplGetInUsedData((int) $_REQUEST['id']);
178:
179: if (isset($usedData['cat'])) {
180: $template->set('s', 'HEAD_TYPE', i18n('Category'));
181: foreach ($usedData['cat'] as $i => $cat) {
182: $template->set('d', 'ID', $cat['idcat']);
183: $template->set('d', 'LANG', $cat['lang']);
184: $template->set('d', 'NAME', $cat['name']);
185: $template->next();
186: }
187: $template->set('s', 'HEAD_ID', i18n('idcat'));
188: $template->set('s', 'HEAD_LANG', i18n('idlang'));
189: $template->set('s', 'HEAD_NAME', i18n('Name'));
190: $response = $template->generate($backendPath . $cfg['path']['templates'] . $cfg['templates']['inuse_tpl'], true);
191: }
192:
193: $template->reset();
194:
195: if (isset($usedData['art'])) {
196: $template->set('s', 'HEAD_TYPE', i18n('Article'));
197: foreach ($usedData['art'] as $i => $aArt) {
198: $template->set('d', 'ID', $aArt['idart']);
199: $template->set('d', 'LANG', $aArt['lang']);
200: $template->set('d', 'NAME', $aArt['title']);
201: $template->next();
202: }
203: $template->set('s', 'HEAD_ID', i18n('idart'));
204: $template->set('s', 'HEAD_LANG', i18n('idlang'));
205: $template->set('s', 'HEAD_NAME', i18n('Name'));
206: $response .= $template->generate($backendPath . $cfg['path']['templates'] . $cfg['templates']['inuse_tpl'], true);
207: }
208:
209: $string = '<div class="inuse_info" >' . $response . '</div>';
210: } else {
211: $string = i18n('No data found!');
212: }
213:
214: break;
215:
216: case 'scaleImage':
217: $filename_a = $_REQUEST['url'];
218: $filename = str_replace($frontendURL, $frontendPath, $filename_a);
219:
220:
221: $filetype = substr($filename, strlen($filename) - 4, 4);
222: switch (strtolower($filetype)) {
223: case '.gif':
224: $string = cApiImgScale($filename, 428, 210);
225: break;
226: case '.png':
227: $string = cApiImgScale($filename, 428, 210);
228: break;
229: case '.jpg':
230: $string = cApiImgScale($filename, 428, 210);
231: break;
232: case 'jpeg':
233: $string = cApiImgScale($filename, 428, 210);
234: break;
235: default:
236: $string = $filename_a;
237: break;
238: }
239:
240:
241: if ($string == '') {
242: $filename = str_replace($frontendPath, $frontendURL, $filename_a);
243: $string = $filename;
244: }
245: break;
246:
247: case 'imagelist':
248: $dirName = (string) $_REQUEST['dir'];
249: $imageId = (int) $_REQUEST['id'];
250: $idArtLang = (int) $_REQUEST['idartlang'];
251:
252: $art = new cApiArticleLanguage($idArtLang, true);
253: $artReturn = $art->getContent('CMS_IMGEDITOR', $imageId);
254: $image = new cContentTypeImgeditor($artReturn, $imageId, array());
255:
256: $string = $image->generateFileSelect($dirName);
257: break;
258:
259: case 'inlineeditart':
260:
261: $languageCollection = new cApiArticleLanguageCollection();
262:
263: for ($i = 0; $i < count($_REQUEST['fields']); $i++) {
264:
265: $idartlang = $languageCollection->getIdByArticleIdAndLanguageId(cSecurity::toInteger($_REQUEST['fields'][$i]['idart']), cRegistry::getLanguageId());
266:
267: $artLang = new cApiArticleLanguage(cSecurity::toInteger($idartlang));
268: $artLang->set('title', cSecurity::escapeString($_REQUEST['fields'][$i]['title']));
269: $artLang->set('artsort', cSecurity::escapeString($_REQUEST['fields'][$i]['index']));
270: $artLang->store();
271: }
272:
273: break;
274:
275: case 'loadImageMeta':
276: $imageId = (int) $_REQUEST['id'];
277: $idArtLang = (int) $_REQUEST['idartlang'];
278:
279: $art = new cApiArticleLanguage($idArtLang, true);
280: $artReturn = $art->getContent('CMS_IMGEDITOR', $imageId);
281: $image = new cContentTypeImgeditor($artReturn, $imageId, array());
282:
283: $filename = (string) basename($_REQUEST['filename']);
284: $dirname = (string) dirname($_REQUEST['filename']);
285: if ($dirname != '.') {
286: $dirname .= '/';
287: } else {
288: $dirname = '';
289: }
290:
291: $string = $image->getImageMeta($filename, $dirname);
292: break;
293:
294: case 'upl_mkdir':
295: $imageId = (int) $_REQUEST['id'];
296: $idArtLang = (int) $_REQUEST['idartlang'];
297: $path = (string) $_REQUEST['path'];
298: $name = (string) $_REQUEST['foldername'];
299:
300: $art = new cApiArticleLanguage($idArtLang, true);
301: $artReturn = $art->getContent('CMS_IMGEDITOR', $imageId);
302: $image = new cContentTypeImgeditor($artReturn, $imageId, array());
303:
304: $string = $image->uplmkdir($path, $name);
305: switch ($string) {
306: case 1:
307: break;
308: case '0702':
309: $string = i18n('Directory already exist.');
310: break;
311: case '0703':
312: $string = i18n('Directories with special characters and spaces are not allowed.');
313: break;
314: }
315: break;
316:
317: case 'upl_upload':
318: $imageId = (int) $_REQUEST['id'];
319: $idArtLang = (int) $_REQUEST['idartlang'];
320: $path = (string) $_REQUEST['path'];
321: if ($path == '/') {
322: $path = '';
323: }
324:
325: $art = new cApiArticleLanguage($idArtLang, true);
326: $artReturn = $art->getContent('CMS_IMGEDITOR', $imageId);
327: $image = new cContentTypeImgeditor($artReturn, $imageId, array());
328:
329: $string = $image->uplupload($path);
330: break;
331:
332: case 'linkeditorfilelist':
333: $id = (int) $_REQUEST['id'];
334: $idArtLang = (int) $_REQUEST['idartlang'];
335: $idCat = (string) $_REQUEST['idcat'];
336:
337: $art = new cApiArticleLanguage($idArtLang, true);
338: $artReturn = $art->getContent('CMS_LINKEDITOR', $id);
339: $linkEditor = new cContentTypeLinkeditor($artReturn, $id, array());
340:
341: $string = $linkEditor->generateArticleSelect($idCat);
342: break;
343:
344: case 'linkeditordirlist':
345: $id = (int) $_REQUEST['id'];
346: $idArtLang = (int) $_REQUEST['idartlang'];
347: $levelId = (string) $_REQUEST['level'];
348: $parentidcat = (string) $_REQUEST['parentidcat'];
349:
350: $art = new cApiArticleLanguage($idArtLang, true);
351: $artReturn = $art->getContent('CMS_LINKEDITOR', $id);
352: $linkEditor = new cContentTypeLinkeditor($artReturn, $id, array());
353:
354: $string = $linkEditor->getCategoryList($linkEditor->buildCategoryArray($levelId, $parentidcat));
355: break;
356:
357: case 'linkeditorimagelist':
358: $dirName = (string) $_REQUEST['dir'];
359: $id = (int) $_REQUEST['id'];
360: $idArtLang = (int) $_REQUEST['idartlang'];
361:
362: $art = new cApiArticleLanguage($idArtLang, true);
363: $artReturn = $art->getContent('CMS_LINKEDITOR', $id);
364: $linkEditor = new cContentTypeLinkeditor($artReturn, $id, array());
365:
366: $string = $linkEditor->getUploadFileSelect($dirName);
367: break;
368:
369: case 'generaljstranslations':
370: $translations = array();
371: $translations['Confirmation Required'] = i18n('Confirmation Required');
372: $translations['OK'] = i18n('OK');
373: $translations['Cancel'] = i18n('Cancel');
374: $string = json_encode($translations);
375: break;
376:
377: case 'logfilecontent':
378: $type = cSecurity::escapeString($_REQUEST['logfile']);
379: $numberOfLines = cSecurity::toInteger($_REQUEST['numberOfLines']);
380: $cfg = cRegistry::getConfig();
381: if (in_array($type, $cfg['system_log']['allowed_filenames'])) {
382: $filename = $cfg['path']['frontend'] . DIRECTORY_SEPARATOR . $cfg['path']['logs'] . $type;
383: $lines = file($filename);
384: $lines = array_splice($lines, $numberOfLines * -1);
385: $string = implode('', $lines);
386: }
387: break;
388:
389: case 'updatepluginorder':
390:
391: if (cRegistry::getPerm()->have_perm()) {
392: $newOrder = cSecurity::toInteger($_POST['neworder']);
393: $pluginColl = new PimPluginCollection();
394: $pluginColl->select();
395: if ($newOrder <= 0 || $newOrder > $pluginColl->count()) {
396: $string = 'order must be > 0 and <= number of plugins';
397: break;
398: }
399:
400: $pluginId = cSecurity::toInteger($_POST['idplugin']);
401: $plugin = new PimPlugin($pluginId);
402: $result = $plugin->updateExecOrder($newOrder);
403: if ($result === true) {
404: $string = 'ok';
405: }
406: } else {
407: $string = 'Unknown Ajax Action';
408: }
409: break;
410:
411: case 'verify_module':
412: $idmod = isset($_POST['idmod']) ? $_POST['idmod'] : NULL;
413: $inputType = isset($_POST['type']) ? $_POST['type'] : NULL;
414:
415:
416: $moduleCheck = getSystemProperty('system', 'modulecheck');
417: $moduleCheck = ($moduleCheck == '' && $moduleCheck != 'false') || $moduleCheck == 'true' || $moduleCheck == '1';
418:
419: $result = array(
420: 'state' => 'ok',
421: 'message' => i18n("Module successfully compiled")
422: );
423:
424: if ($idmod && $inputType && $moduleCheck) {
425: $contenidoModuleHandler = new cModuleHandler($idmod);
426: switch ($inputType) {
427: case 'input':
428: $result = $contenidoModuleHandler->testInput();
429: break;
430: case 'output':
431: $result = $contenidoModuleHandler->testOutput();
432: break;
433: default:
434: $result = array(
435: 'state' => 'error',
436: 'message' => 'No cModuleHandler for ' . $idmod . ', or wrong code type: ' . $inputType
437: );
438: }
439:
440:
441: if ($result['state']) {
442: $result['state'] = 'ok';
443: $result['message'] = i18n("Module successfully compiled");
444: } else {
445: $result['state'] = 'error';
446: $result['message'] = $result['errorMessage'];
447: }
448: }
449:
450: $string = json_encode($result);
451: break;
452:
453: case 'authentication_fail':
454: $string = json_encode(array(
455: 'state' => 'error',
456: 'code' => 401,
457: 'message' => 'Unauthorized',
458: 'type' => 'authentication_failure'
459: ));
460: break;
461: case 'custom':
462: $string = cApiCecHook::executeAndReturn('Contenido.AjaxMain.CustomCall', $_REQUEST['method']);
463: if($string === NULL) {
464: $string = 'Unknown Custom Ajax Action';
465: }
466: break;
467: default:
468:
469: $string = 'Unknown Ajax Action';
470: break;
471: }
472:
473: return $string;
474: }
475:
476: }
477: