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