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