1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14:
15:
16: defined('CON_FRAMEWORK') || die('Illegal call: Missing framework initialization - request aborted.');
17:
18: $backendPath = cRegistry::getBackendPath();
19: $backendUrl = cRegistry::getBackendUrl();
20:
21: cInclude('includes', 'functions.str.php');
22: cInclude('includes', 'functions.pathresolver.php');
23:
24: if (!isset($idcat)) {
25: cRegistry::shutdown();
26: return;
27: }
28:
29: $edit = 'true';
30: $scripts = '';
31:
32: $allowedContentTypes = array(
33: "CMS_HTMLHEAD",
34: "CMS_HTML",
35: "CMS_TEXT",
36: "CMS_LINK",
37: "CMS_LINKTARGET",
38: "CMS_LINKDESCR",
39: "CMS_HEAD",
40: "CMS_DATE",
41: "CMS_RAW"
42: );
43:
44: $page = new cGuiPage("con_content_list");
45:
46: if (!($perm->have_perm_area_action($area, "savecontype") || $perm->have_perm_area_action_item($area, "savecontype", $idcat) || $perm->have_perm_area_action("con", "deletecontype") || $perm->have_perm_area_action_item("con", "deletecontype", $idcat))) {
47:
48: $page->abortRendering();
49: $page->render();
50: die();
51: }
52:
53:
54: if (($action == 'savecontype' || $action == 10)) {
55: if ($perm->have_perm_area_action($area, "savecontype") || $perm->have_perm_area_action_item($area, "savecontype", $idcat)) {
56: if ($data != '') {
57: $data = explode('||', substr($data, 0, -2));
58: foreach ($data as $value) {
59: $value = explode('|', $value);
60: if ($value[3] == '%$%EMPTY%$%') {
61: $value[3] = '';
62: } else {
63: $value[3] = str_replace('%$%SEPERATOR%$%', '|', $value[3]);
64: }
65: conSaveContentEntry($value[0], 'CMS_' . $value[1], $value[2], $value[3]);
66: }
67:
68: conMakeArticleIndex($idartlang, $idart);
69:
70:
71: $data = $_REQUEST['data'];
72: $value = $_REQUEST['value'];
73:
74: $notification->displayNotification("info", i18n("Changes saved"));
75: }
76:
77: conGenerateCodeForArtInAllCategories($idart);
78: } else {
79: $page->displayError(i18n("Permission denied"));
80: }
81: } else if ($action == 'deletecontype') {
82: if ($perm->have_perm_area_action($Area, "deletecontype") || $perm->have_perm_area_action_item($area, "deletecontype", $idcat)) {
83: if (isset($_REQUEST['idcontent']) && is_numeric($_REQUEST['idcontent'])) {
84: $oContentColl = new cApiContentCollection();
85:
86: $linkedTypes = array(
87: 4 => 22,
88:
89: 22 => 4
90: );
91:
92: $contentItem = new cApiContent((int) $_REQUEST["idcontent"]);
93: if (isset($linkedTypes[$contentItem->get("idtype")])) {
94: $linkedIds = $oContentColl->getIdsByWhereClause("`idartlang`='" . $idartlang . "' AND `idtype`='" . $linkedTypes[$contentItem->get("idtype")] . "' AND `value`='" . $contentItem->get("value") . "'");
95: foreach ($linkedIds as $linkedId) {
96: $oContentColl->delete($linkedId);
97: }
98: }
99: $oContentColl->delete((int) $_REQUEST['idcontent']);
100: $notification->displayNotification("info", i18n("Changes saved"));
101:
102: conGenerateCodeForArtInAllCategories($idart);
103: }
104: } else {
105: $page->displayError(i18n("Permission denied"));
106: }
107: } else if ($action == 'exportrawcontent') {
108:
109:
110: class SimpleXMLExtended extends SimpleXMLElement{
111: public function addCData($cdata_text){
112: $node= dom_import_simplexml($this);
113: $no = $node->ownerDocument;
114: $node->appendChild($no->createCDATASection($cdata_text));
115: }
116: }
117:
118:
119: $cApiArticleLanguage = new cApiArticleLanguage(cSecurity::toInteger($idartlang));
120:
121: $articleElement = new SimpleXMLExtended('<?xml version="1.0" encoding="UTF-8"?><articles></articles>');
122:
123:
124: $articleNode = $articleElement->addChild("article");
125: $articleNode->addAttribute("id", $cApiArticleLanguage->get('idart'));
126:
127:
128: $titleNode = $articleNode->addChild("title");
129: $titleNode->addCData($cApiArticleLanguage->get('title'));
130:
131: $summaryNode = $articleNode->addChild("shortdesc");
132: $summaryNode->addCData($cApiArticleLanguage->get('summary'));
133:
134: $pageTitleNode = $articleNode->addChild("seo_title");
135: $pageTitleNode->addCData($cApiArticleLanguage->get('pagetitle'));
136:
137: $seoDescrNode = $articleNode->addChild("seo_description");
138: $seoDescrNode->addCData(conGetMetaValue($cApiArticleLanguage->get('idartlang'), 3));
139:
140: $keywordsNode = $articleNode->addChild("seo_keywords");
141: $keywordsNode->addCData(conGetMetaValue($cApiArticleLanguage->get('idartlang'), 5));
142:
143: $copyrightNode = $articleNode->addChild("seo_copyright");
144: $copyrightNode->addCData(conGetMetaValue($cApiArticleLanguage->get('idartlang'), 8));
145:
146: $seoauthorNode = $articleNode->addChild("seo_author");
147: $seoauthorNode->addCData(conGetMetaValue($cApiArticleLanguage->get('idartlang'), 1));
148:
149:
150: $conColl = new cApiContentCollection();
151: $contentIds = $conColl->getIdsByWhereClause('idartlang="'. $cApiArticleLanguage->get("idartlang") .'"');
152:
153:
154: foreach ($contentIds as $contentId) {
155:
156: $content = new cApiContent($contentId);
157:
158: if($content->isLoaded()) {
159: $type = new cApiType($content->get("idtype"));
160:
161: if($type->isLoaded() && in_array($type->get("type"), $allowedContentTypes)) {
162: foreach ($_POST as $key => $contentType) {
163: if($key == $type->get("type") && $contentType == $content->get("typeid")) {
164:
165: $contentNode = $articleNode->addChild("content");
166: $contentNode->addCData($content->get("value"));
167: $contentNode->addAttribute("type", $type->get("type"));
168: $contentNode->addAttribute("id", $content->get("typeid"));
169: }
170: }
171: }
172:
173: }
174: }
175:
176: header('Content-Type: application/xml;');
177: header('Content-Disposition: attachment; filename='.$cApiArticleLanguage->get('title').';');
178: ob_clean();
179: echo $articleElement->asXML();
180: exit;
181: } else if ($action == "importrawcontent") {
182:
183:
184:
185: $error = false;
186:
187:
188: $rawDataFile = $_FILES['rawfile']['tmp_name'];
189:
190:
191: if(strlen($rawDataFile) > 0 && isset($_FILES['rawfile'])) {
192:
193:
194: $rawData = file_get_contents($rawDataFile);
195:
196:
197: try {
198: $xmlDocument = new SimpleXMLElement($rawData);
199:
200: foreach ($xmlDocument->children() as $articleNode) {
201: $articleId = $articleNode->attributes()->id;
202:
203:
204: if($articleId > 0) {
205:
206:
207: $articleLanguage = new cApiArticleLanguage();
208: $articleLanguage->loadByMany(array("idart" => $articleId, "idlang" => cRegistry::getLanguageId()));
209:
210:
211: if($articleLanguage->isLoaded()) {
212:
213:
214: foreach ($articleNode->children() as $key => $child) {
215:
216:
217: switch ($key) {
218: case 'title':
219: $articleLanguage->set("title", $child);
220: $articleLanguage->store();
221:
222: break;
223: case 'shortdesc':
224: $articleLanguage->set("summary", $child);
225: $articleLanguage->store();
226:
227: break;
228: case 'seo_title':
229: $articleLanguage->set("pagetitle", $child);
230: $articleLanguage->store();
231:
232: break;
233: case 'seo_description':
234: conSetMetaValue($articleLanguage->get('idartlang'), 3, $child);
235:
236: break;
237: case 'seo_keywords':
238: conSetMetaValue($articleLanguage->get('idartlang'), 5, $child);
239:
240: break;
241: case 'seo_copyright':
242: conSetMetaValue($articleLanguage->get('idartlang'), 8, $child);
243:
244: break;
245: case 'seo_author':
246: conSetMetaValue($articleLanguage->get('idartlang'), 1, $child);
247:
248: break;
249: case 'content':
250: $type = $child->attributes()->type;
251: $typeid = $child->attributes()->id;
252:
253: $typeEntry = new cApiType();
254: $typeEntry->loadBy("type", $type);
255:
256: if(strlen($type) > 0 && $typeid > 0 && in_array($typeEntry->get("type"), $allowedContentTypes)) {
257: if(isset($_POST['overwritecontent']) && $_POST['overwritecontent'] == 1) {
258: conSaveContentEntry($articleLanguage->get('idartlang'), $type, $typeid, $child);
259: } else {
260:
261: $contentEntry = new cApiContent();
262:
263: $contentEntry->loadByMany(array("idtype" => $typeEntry->get("idtype"), "typeid" => $typeid, "idartlang" => $articleLanguage->get('idartlang')));
264: if(!$contentEntry->isLoaded()) {
265: conSaveContentEntry($articleLanguage->get('idartlang'), $type, $typeid, $child);
266: }
267: }
268: } else {
269:
270: }
271:
272: break;
273: case 'default':
274: break;
275: }
276:
277: }
278:
279: } else {
280: $page->displayError(i18n("Can not load article"));
281: $error = true;
282: }
283: } else {
284: $page->displayError(i18n("Can not find article"));
285: $error = true;
286:
287: }
288: }
289: if($error === false) {
290: $page->displayInfo(i18n("Raw data was imported successfully"));
291: }
292:
293: } catch (Exception $e) {
294: $page->displayError(i18n("Error: The XML file is not valid"));
295: }
296: } else {
297: $page->displayWarning(i18n("Please choose a file"));
298: }
299:
300: }
301:
302:
303:
304: $result = array();
305: $aList = array();
306: $currentTypes = array();
307: $sortID = array(
308: "CMS_HTMLHEAD",
309: "CMS_HEAD",
310: "CMS_HTML",
311: "CMS_TEXT",
312: "CMS_IMG",
313: "CMS_IMGDESCR",
314: "CMS_IMGEDITOR",
315: "CMS_LINK",
316: "CMS_LINKTARGET",
317: "CMS_LINKDESCR",
318: "CMS_LINKEDITOR",
319: "CMS_DATE",
320: "CMS_TEASER",
321: "CMS_FILELIST",
322: "CMS_RAW"
323: );
324:
325: $aIdtype = array();
326: $sql = "SELECT DISTINCT typeid FROM %s WHERE idartlang = %d ORDER BY typeid";
327: $db->query($sql, $cfg["tab"]["content"], $_REQUEST["idartlang"]);
328: while ($db->nextRecord()) {
329: $aIdtype[] = $db->f("typeid");
330: }
331:
332: foreach ($sortID as $name) {
333:
334:
335:
336:
337:
338:
339: $sql = "SELECT b.idtype as idtype, b.type as name, a.typeid as id, a.value as value FROM %s AS a, %s AS b " . "WHERE a.idartlang = %d AND a.idtype = b.idtype AND b.type = '%s' ORDER BY idtype, typeid, idcontent";
340: $db->query($sql, $cfg["tab"]["content"], $cfg["tab"]["type"], $_REQUEST["idartlang"], $name);
341: while ($db->nextRecord() && $db->f("value") != '') {
342: $result[$db->f("name")][$db->f("id")] = $db->f("value");
343: if (!in_array($db->f("name"), $aList)) {
344: $aList[$db->f("idtype")] = $db->f("name");
345: }
346: }
347: }
348:
349: $currentTypes = _getCurrentTypes($currentTypes, $aList);
350:
351:
352:
353:
354:
355: $markSubItem = markSubMenuItem(4, true);
356:
357:
358: include($backendPath . 'external/wysiwyg/tinymce3/editorclass.php');
359: $oEditor = new cTinyMCEEditor('', '');
360: $oEditor->setToolbar('inline_edit');
361:
362:
363: $sConfigInlineEdit = $oEditor->getConfigInlineEdit();
364: $sConfigFullscreen = $oEditor->getConfigFullscreen();
365:
366:
367:
368:
369: $page->set('s', 'IMAGE', $backendUrl . 'frameset.php?area=upl&contenido=' . $sess->id . '&appendparameters=imagebrowser');
370: $page->set('s', 'FILE', $backendUrl . 'frameset.php?area=upl&contenido=' . $sess->id . '&appendparameters=filebrowser');
371: $page->set('s', 'FLASH', $backendUrl . 'frameset.php?area=upl&contenido=' . $sess->id . '&appendparameters=imagebrowser');
372: $page->set('s', 'MEDIA', $backendUrl . 'frameset.php?area=upl&contenido=' . $sess->id . '&appendparameters=imagebrowser');
373: $page->set('s', 'FRONTEND', cRegistry::getFrontendUrl());
374:
375:
376: $page->set('s', 'TINY_OPTIONS', $sConfigInlineEdit);
377: $page->set('s', 'TINY_FULLSCREEN', $sConfigFullscreen);
378: $page->set('s', 'IDARTLANG', $idartlang);
379: $page->set('s', 'CLOSE', i18n('Close editor'));
380: $page->set('s', 'SAVE', i18n('Close editor and save changes'));
381: $page->set('s', 'QUESTION', i18n('Do you want to save changes?'));
382:
383:
384: $page->set('s', 'EXPORT_RAWDATA', i18n("Export raw data"));
385: $page->set('s', 'IMPORT_RAWDATA', i18n("Import raw data"));
386: $page->set('s', 'EXPORT_LABEL', i18n("Raw data export"));
387: $page->set('s', 'IMPORT_LABEL', i18n("Raw data import"));
388: $page->set('s', 'OVERWRITE_DATA_LABEL', i18n("Overwrite data"));
389:
390:
391: if (getEffectiveSetting('system', 'insite_editing_activated', 'true') == 'false') {
392: $page->set('s', 'USE_TINY', '');
393: } else {
394: $page->set('s', 'USE_TINY', '1');
395: }
396:
397:
398: $breadcrumb = renderBackendBreadcrumb($syncoptions, true, true);
399: $page->set('s', 'CATEGORY', $breadcrumb);
400:
401: if (count($result) <= 0) {
402: $page->displayInfo(i18n("Article has no raw data"));
403: $page->abortRendering();
404:
405: } else {
406: foreach ($aIdtype as $idtype) {
407: foreach ($sortID as $name) {
408: if (in_array($name, array_keys($result)) && $result[$name][$idtype] != '') {
409: if (in_array($name . "[" . $idtype . "]", $currentTypes)) {
410: $class = '';
411: } else {
412: $class = ' noactive';
413: }
414: $page->set("d", "EXTRA_CLASS", $class);
415: $page->set("d", "NAME", $name);
416: $page->set("d", "ID_TYPE", $idtype);
417: if(in_array($name, $allowedContentTypes)) {
418: $page->set("d", "EXPORT_CONTENT", '<input type="checkbox" class="rawtypes" name="' . $name .'" value="' .$idtype .'" checked="checked">');
419: $page->set('d', 'EXPORT_CONTENT_LABEL', i18n("Export"));
420: } else {
421: $page->set("d", "EXPORT_CONTENT", '');
422: $page->set('d', 'EXPORT_CONTENT_LABEL', '');
423: }
424: $page->next();
425: }
426: }
427: }
428: }
429:
430:
431: if (!isset($syncfrom)) {
432: $syncfrom = -1;
433: }
434: $syncoptions = $syncfrom;
435: $page->set("s", "SYNCHOPTIONS", $syncoptions);
436:
437: $page->set("s", "IDART", $idart);
438: $page->set("s", "IDCAT", $idcat);
439: $page->set("s", "IDLANG", $lang);
440: $page->set("s", "IDARTLANG", $idartlang);
441: $page->set("s", "IDCLIENT", $client);
442:
443:
444: $code = _processCmsTags($aList, $result, true, $page->render(NULL, true));
445:
446: if ($code == "0601") {
447: markSubMenuItem("1");
448: $code = "<script type='text/javascript'>location.href = '" . $backendUrl . "main.php?frame=4&area=con_content_list&action=con_content&idart=" . $idart . "&idcat=" . $idcat . "&contenido=" . $contenido . "'; /*console.log(location.href);*/</script>";
449: } else {
450:
451: $code = cString::iReplaceOnce("</head>", "$markSubItem $scripts\n<meta http-equiv=\"Content-Type\" content=\"text/html; charset=$encoding[$lang]\"></head>", $code);
452: }
453:
454: if ($cfg["debug"]["codeoutput"]) {
455: cDebug::out(conHtmlSpecialChars($code));
456: }
457:
458:
459: chdir(cRegistry::getFrontendPath());
460: eval("?>\n" . $code . "\n<?php\n");
461:
462:
463: cRegistry::shutdown();
464:
465: 466: 467: 468: 469: 470: 471: 472: 473: 474:
475: function _processCmsTags($aList, $contentList, $saveKeywords = true, $layoutCode) {
476:
477:
478:
479: global $db, $db2, $sess, $cfg, $code, $cfgClient, $encoding, $notification;
480:
481:
482:
483: global $edit, $editLink, $belang;
484:
485: $idcat = $_REQUEST['idcat'];
486: $idart = $_REQUEST['idart'];
487: $lang = $_REQUEST['lang'];
488: $client = $_REQUEST['client'];
489: $idartlang = $_REQUEST['idartlang'];
490: $contenido = $_REQUEST['contenido'];
491:
492:
493: $cApiArticleLanguage = new cApiArticleLanguage(cSecurity::toInteger($idartlang));
494: $locked = $cApiArticleLanguage->getField('locked');
495:
496:
497: if ($locked == 1) {
498: $notification->displayNotification('warning', i18n('This article is currently frozen and can not be edited!'));
499: }
500:
501: if (!is_object($db2)) {
502: $db2 = cRegistry::getDb();
503: }
504:
505:
506:
507: $match = array();
508: $keycode = array();
509:
510:
511: $a_content = $contentList;
512:
513:
514: $_typeList = array();
515: $oTypeColl = new cApiTypeCollection();
516: $oTypeColl->select();
517: while ($oType = $oTypeColl->next()) {
518: $_typeList[] = $oType->toObject();
519: }
520:
521:
522: foreach ($_typeList as $_typeItem) {
523: $key = strtolower($_typeItem->type);
524: $type = $_typeItem->type;
525: if (in_array($type, $aList)) {
526:
527:
528:
529: $tmp = preg_match_all('/(' . $type . '\[+(\d)+\])/i', $layoutCode, $match);
530:
531: $a_[$key] = $match[0];
532:
533: $success = array_walk($a_[$key], 'extractNumber');
534:
535: $search = array();
536: $replacements = array();
537:
538: $backendPath = cRegistry::getBackendPath();
539:
540: $typeCodeFile = $backendPath . 'includes/type/code/include.' . $type . '.code.php';
541: $cTypeClassFile = $backendPath . 'classes/content_types/class.content.type.' . strtolower(str_replace('CMS_', '', $type)) . '.php';
542:
543: $className = 'cContentType' . ucfirst(strtolower(str_replace('CMS_', '', $type)));
544:
545: foreach ($a_[$key] as $val) {
546: if (cFileHandler::exists($cTypeClassFile)) {
547: $tmp = $a_content[$_typeItem->type][$val];
548: $cTypeObject = new $className($tmp, $val, $a_content);
549: if (cRegistry::isBackendEditMode() && $locked == 0) {
550: $tmp = $cTypeObject->generateEditCode();
551: } else {
552: $tmp = $cTypeObject->generateViewCode();
553: }
554: } else if (cFileHandler::exists($typeCodeFile)) {
555:
556: include($typeCodeFile);
557: } elseif (!empty($_typeItem->code)) {
558:
559: cDeprecated("Move code for $type from table into file system (contenido/includes/type/code/)");
560: eval($_typeItem->code);
561: }
562: $sql = "SELECT a.idcontent
563: FROM " . $cfg["tab"]["content"] . " as a, " . $cfg["tab"]["type"] . " as b
564: WHERE a.idartlang=" . cSecurity::toInteger($_REQUEST["idartlang"]) . " AND a.idtype=b.idtype AND a.typeid = " . cSecurity::toInteger($val) . " AND b.type = '" . cSecurity::toString($type) . "'
565: ORDER BY a.idartlang, a.idtype, a.typeid";
566: $db->query($sql);
567: while ($db->nextRecord()) {
568: $idcontent = $db->f("idcontent");
569: }
570: $backendUrl = cRegistry::getBackendUrl();
571:
572: $search[$val] = sprintf('%s[%s]', $type, $val);
573: $path = $backendUrl . 'main.php?area=con_content_list&action=deletecontype&changeview=edit&idart=' . $idart . '&idartlang=' . $idartlang . '&idcat=' . $idcat . '&client=' . $client . '&lang=' . $lang . '&frame=4&contenido=' . $contenido . '&idcontent=' . $idcontent;
574: if ($_typeItem->idtype == 20 || $_typeItem->idtype == 21) {
575: $tmp = str_replace('";?>', '', $tmp);
576: $tmp = str_replace('<?php echo "', '', $tmp);
577:
578:
579: }
580:
581: if ($locked == 0) {
582: $replacements[$val] = $tmp . '<a href="#" onclick="Con.showConfirmation(\'' . i18n("Are you sure you want to delete this content type from this article?") . '\', function() { Con.Tiny.setContent(\'1\',\'' . $path . '\'); });">
583: <img border="0" src="' . $backendUrl . 'images/delete.gif">
584: </a>';
585: $keycode[$type][$val] = $tmp . '<a href="#" onclick="Con.showConfirmation(\'' . i18n("Are you sure you want to delete this content type from this article?") . '\', function() { Con.Tiny.setContent(\'1\',\'' . $path . '\'); });">
586: <img border="0" src="' . $backendUrl . 'images/delete.gif">
587: </a>';
588: } else {
589: $replacements[$val] = $tmp;
590: $keycode[$type][$val] = $tmp;
591: }
592: }
593:
594: $code = str_ireplace($search, $replacements, $layoutCode);
595:
596: $code = cApiCecHook::executeAndReturn('Contenido.Content.conGenerateCode', $code);
597: $layoutCode = stripslashes($code);
598: }
599: }
600: $layoutCode = str_ireplace("<<", "[", $layoutCode);
601: $layoutCode = str_ireplace(">>", "]", $layoutCode);
602: return $layoutCode;
603: }
604:
605: 606: 607: 608: 609: 610:
611: function _getCurrentTypes($r, $aList) {
612: $idcat = $_REQUEST['idcat'];
613: $idart = $_REQUEST['idart'];
614: $lang = $_REQUEST['lang'];
615: $client = $_REQUEST['client'];
616: global $db, $db2, $sess, $cfg, $code, $cfgClient, $encoding;
617:
618:
619: $_typeList = array();
620: $oTypeColl = new cApiTypeCollection();
621: $oTypeColl->select();
622: while ($oType = $oTypeColl->next()) {
623: $_typeList[] = $oType->toObject();
624: }
625:
626:
627: $code = conGenerateCode($idcat, $idart, $lang, $client, false, false, false);
628: foreach ($_typeList as $_typeItem) {
629: $type = $_typeItem->type;
630: if (in_array($type, $aList)) {
631:
632: $tmp = preg_match_all('/(' . $type . '\[+(\d)+\])/i', $code, $match);
633: foreach ($match[0] as $s) {
634: if (!in_array($s, $r)) {
635: array_push($r, $s);
636: }
637: }
638: }
639: }
640: return $r;
641: }
642: