1: <?php
2:
3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15:
16:
17: defined('CON_FRAMEWORK') || die('Illegal call: Missing framework initialization - request aborted.');
18:
19:
20: cInclude('includes', 'functions.con2.php');
21:
22: 23: 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: function conEditFirstTime(
51: $idcat, $idcatnew, $idart, $isstart, $idtpl, $idartlang, $idlang, $title,
52: $summary, $artspec, $created, $lastmodified, $author, $online, $datestart,
53: $dateend, $artsort, $keyart = 0, $searchable = 1, $sitemapprio = 0.5,
54: $changefreq = ''
55: ) {
56:
57: global $client, $lang, $auth, $urlname, $page_title;
58:
59: global $redirect, $redirect_url, $external_redirect;
60: global $time_move_cat;
61: global $time_target_cat;
62: global $time_online_move;
63:
64: global $timemgmt;
65:
66: $page_title = addslashes($page_title);
67: $title = stripslashes($title);
68: $redirect_url = stripslashes($redirect_url);
69: $urlname = (trim($urlname) == '')? trim($title) : trim($urlname);
70:
71: if ($isstart == 1) {
72: $timemgmt = 0;
73: }
74:
75: if (!is_array($idcatnew)) {
76: $idcatnew[0] = 0;
77: }
78:
79: $versioning = new cContentVersioning();
80:
81: $oArtColl = new cApiArticleCollection();
82: $oArt = $oArtColl->create($client);
83: $idart = $oArt->get('idart');
84:
85: $status = 0;
86:
87:
88: $oCatArtColl = new cApiCategoryArticleCollection();
89: $oCatArt = $oCatArtColl->create($idcat, $idart, $status);
90: $idcatart = $oCatArt->get('idcatart');
91:
92: $aLanguages = array(
93: $lang
94: );
95:
96:
97: foreach ($aLanguages as $curLang) {
98: $lastmodified = ($lang == $curLang)? $lastmodified : '';
99: $modifiedby = '';
100:
101: if ($online == 1) {
102: $published_value = date('Y-m-d H:i:s');
103: $publishedby_value = $auth->auth['uname'];
104: } else {
105: $published_value = '';
106: $publishedby_value = '';
107: }
108:
109:
110: $oStatColl = new cApiStatCollection();
111: $oStat = $oStatColl->create($idcatart, $curLang, $client, 0);
112:
113:
114: $oArtLangColl = new cApiArticleLanguageCollection();
115: $oArtLang = $oArtLangColl->create($idart, $curLang, $title, $urlname, $page_title, $summary, $artspec, $created, $auth->auth['uname'], $lastmodified, $modifiedby, $published_value, $publishedby_value, $online, $redirect, $redirect_url, $external_redirect, $artsort, $timemgmt, $datestart, $dateend, $status, $time_move_cat, $time_target_cat, $time_online_move, 0, '', '', '', $searchable, $sitemapprio, $changefreq);
116: $lastId = $oArtLang->get('idartlang');
117: $availableTags = conGetAvailableMetaTagTypes();
118: foreach ($availableTags as $key => $value) {
119: conSetMetaValue($lastId, $key, $_POST['META' . $value['name']], $child);
120: }
121: }
122:
123:
124: $oCatArtColl = new cApiCategoryArticleCollection();
125: $aCatsForArt = $oCatArtColl->getCategoryIdsByArticleId($idart);
126: if (count($aCatsForArt) == 0) {
127: $aCatsForArt[0] = 0;
128: }
129:
130: $aLanguages = getLanguagesByClient($client);
131:
132: foreach ($idcatnew as $value) {
133: if (!in_array($value, $aCatsForArt)) {
134:
135: $oCatArtColl = new cApiCategoryArticleCollection();
136: $oCatArt = $oCatArtColl->create($value, $idart);
137: $curIdcatart = $oCatArt->get('idcatart');
138:
139:
140: foreach ($aLanguages as $curLang) {
141: $oStatColl = new cApiStatCollection();
142: $oStatColl->create($curIdcatart, $curLang, $client, 0);
143: }
144: }
145: }
146:
147: foreach ($aCatsForArt as $value) {
148: if (!in_array($value, $idcatnew)) {
149:
150:
151: conRemoveOldCategoryArticle($value, $idart, $idartlang, $client, $lang);
152: }
153: }
154:
155: if (!$title) {
156: $title = '--- ' . i18n("Default title") . ' ---';
157: }
158:
159:
160: foreach ($aLanguages as $curLang) {
161: $curOnline = ($lang == $curLang)? $online : 0;
162: $curLastmodified = ($lang == $curLang)? $lastmodified : '';
163:
164: $oArtLang = new cApiArticleLanguage();
165: $oArtLang->loadByArticleAndLanguageId($idart, $curLang);
166: if (!$oArtLang->isLoaded()) {
167: continue;
168: }
169:
170: $oArtLang->set('title', $title);
171: $oArtLang->set('urlname', $urlname);
172: $oArtLang->set('pagetitle', $page_title);
173: $oArtLang->set('summary', $summary);
174: $oArtLang->set('artspec', $artspec);
175: $oArtLang->set('created', $created);
176: $oArtLang->set('lastmodified', $curLastmodified);
177: $oArtLang->set('modifiedby', $author);
178: $oArtLang->set('online', $curOnline);
179: $oArtLang->set('searchable', $searchable);
180: $oArtLang->set('sitemapprio', $sitemapprio);
181: $oArtLang->set('changefreq', $changefreq);
182: $oArtLang->set('redirect', $redirect);
183: $oArtLang->set('redirect_url', $redirect_url);
184: $oArtLang->set('external_redirect', $external_redirect);
185: $oArtLang->set('artsort', $artsort);
186: $oArtLang->set('datestart', $datestart);
187: $oArtLang->set('dateend', $dateend);
188: $oArtLang->store();
189: }
190:
191: $versioningState = $versioning->getState();
192:
193: switch ($versioningState) {
194: case 'simple':
195: case 'advanced':
196:
197: $parameters = array(
198: 'published' => $published_value,
199: 'idcat' => $idcat,
200: 'idcatnew' => $idcatnew,
201: 'idart' => $idart,
202: 'isstart' => $isstart,
203: 'idtpl' => $idtpl,
204: 'idartlang' => $lastId,
205: 'idlang' => $idlang,
206: 'title' => $title,
207: 'summary' => $summary,
208: 'artspec' => $artspec,
209: 'created' => $created,
210: 'iscurrentversion' => 1,
211: 'lastmodified' => $lastmodified,
212: 'author' => $author,
213: 'online' => $online,
214: 'artsort' => $artsort,
215: 'datestart' => $datestart,
216: 'dateend' => $dateend,
217: 'keyart' => $keyart,
218: 'searchable' => $searchable,
219: 'sitemapprio' => $sitemapprio,
220: 'changefreq' => $changefreq
221: );
222:
223: $versioning->createArticleLanguageVersion($parameters);
224: break;
225: case 'disabled':
226: default:
227: break;
228: }
229:
230: return $idart;
231: }
232:
233: 234: 235: 236: 237: 238: 239: 240: 241: 242: 243: 244: 245: 246: 247: 248: 249: 250: 251: 252: 253: 254: 255: 256: 257: 258: 259: 260:
261: function conEditArt($idcat, $idcatnew, $idart, $isstart, $idtpl, $idartlang, $idlang, $title, $summary, $artspec, $created, $lastmodified, $author, $online, $datestart, $dateend, $published, $artsort, $keyart = 0, $searchable = 1, $sitemapprio = -1, $changefreq = 'nothing') {
262: global $client, $lang, $redirect, $redirect_url, $external_redirect, $perm;
263: global $urlname, $page_title;
264: global $time_move_cat, $time_target_cat;
265:
266: global $time_online_move;
267: global $timemgmt;
268:
269: $aAuthPerms = explode(',', $auth->auth['perm']);
270:
271: $admin = false;
272: if (count(preg_grep("/admin.*/", $aAuthPerms)) > 0) {
273: $admin = true;
274: }
275: $oArtLang = new cApiArticleLanguage($idartlang);
276: $locked = (int) $oArtLang->get('locked');
277:
278:
279: if (1 === $locked
280: && false === $admin) {
281: return $idart;
282: }
283:
284:
285: $page_title = addslashes($page_title);
286: $title = stripslashes($title);
287: $redirect_url = stripslashes($redirect_url);
288:
289: $urlname = (trim($urlname) == '')? trim($title) : trim($urlname);
290: $usetimemgmt = ((int) $timemgmt == 1)? 1 : 0;
291: if ($timemgmt == '1' && (($datestart == '' && $dateend == '') || ($datestart == '0000-00-00 00:00:00' && $dateend == '0000-00-00 00:00:00'))) {
292: $usetimemgmt = 0;
293: }
294:
295: if ($isstart == 1) {
296: $usetimemgmt = 0;
297: }
298:
299: if (!is_array($idcatnew)) {
300: $idcatnew[0] = 0;
301: }
302:
303: $artLang = new cApiArticleLanguage((int) $idartlang);
304: if (!$artLang->isLoaded()) {
305: return;
306: }
307:
308:
309: $idTplCfg = $artLang->get('idtplcfg');
310:
311:
312: $oCatArtColl = new cApiCategoryArticleCollection();
313: $aCatsForArt = $oCatArtColl->getCategoryIdsByArticleId($idart);
314: if (count($aCatsForArt) == 0) {
315: $aCatsForArt[0] = 0;
316: }
317:
318: foreach ($idcatnew as $value) {
319: if (!in_array($value, $aCatsForArt)) {
320:
321: $oCatArtColl = new cApiCategoryArticleCollection();
322: $oCatArt = $oCatArtColl->create($value, $idart);
323: $curIdcatart = $oCatArt->get('idcatart');
324:
325:
326: if ($idTplCfg != 0) {
327: $newIdTplCfg = conCopyTemplateConfiguration($idTplCfg);
328: conCopyContainerConf($idTplCfg, $newIdTplCfg);
329: }
330:
331: $aLanguages = getLanguagesByClient($client);
332:
333:
334: foreach ($aLanguages as $curLang) {
335: $oStatColl = new cApiStatCollection();
336: $oStatColl->create($curIdcatart, $curLang, $client, 0);
337: }
338: }
339: }
340:
341: foreach ($aCatsForArt as $value) {
342: if (!in_array($value, $idcatnew)) {
343:
344:
345: conRemoveOldCategoryArticle($value, $idart, $idartlang, $client, $lang);
346: }
347: }
348:
349: if ($title == '') {
350: $title = '--- ' . i18n('Default title') . ' ---';
351: }
352:
353: $versioning = new cContentVersioning();
354: $versioningState = $versioning->getState();
355:
356: switch ($versioningState) {
357: case 'simple':
358:
359: $artLang->set('title', $title);
360: $artLang->set('urlname', $urlname);
361: $artLang->set('summary', $summary);
362: $artLang->set('artspec', $artspec);
363: $artLang->set('created', $created);
364: $artLang->set('lastmodified', $lastmodified);
365: $artLang->set('modifiedby', $author);
366: $artLang->set('timemgmt', $usetimemgmt);
367: $artLang->set('redirect', $redirect);
368: $artLang->set('external_redirect', $external_redirect);
369: $artLang->set('redirect_url', $redirect_url);
370: $artLang->set('artsort', $artsort);
371: $artLang->set('searchable', $searchable);
372: if ($sitemapprio != -1) {
373: $artLang->set('sitemapprio', $sitemapprio);
374: }
375: if ($changefreq != "nothing") {
376: $artLang->set('changefreq', $changefreq);
377: }
378: $artLang->set('published', date("Y-m-d H:i:s", strtotime($published)));
379:
380:
381: if ($perm->have_perm_area_action('con', 'con_makeonline') || $perm->have_perm_area_action_item('con', 'con_makeonline', $idcat)) {
382: $oldOnline = $artLang->get('online');
383: if (isset($online)) {
384: $artLang->set('online', $online);
385: }
386:
387:
388:
389: if ((int) $online == 1 && $oldOnline == 0) {
390: $artLang->set('published', date('Y-m-d H:i:s'));
391: $artLang->set('publishedby', $author);
392: }
393:
394: $artLang->set('datestart', $datestart);
395: $artLang->set('dateend', $dateend);
396: $artLang->set('time_move_cat', $time_move_cat);
397: $artLang->set('time_target_cat', $time_target_cat);
398: $artLang->set('time_online_move', $time_online_move);
399: }
400:
401:
402: if (!empty($newIdTplCfg) && $idTplCfg != $newIdTplCfg) {
403: $artLang->set('idtplcfg', $newIdTplCfg);
404: }
405:
406: $artLang->store();
407: case 'advanced':
408: $oldOnline = $artLang->get('online');
409:
410: if ((int) $online == 1 && $oldOnline == 0) {
411: $published = date('Y-m-d H:i:s');
412: $publishedby = $author;
413: }
414: $parameters = array(
415: 'idcat' => $idcat,
416: 'idcatnew' => $idcatnew,
417: 'idart' => $idart,
418: 'isstart' => $isstart,
419: 'idtpl' => $idtpl,
420: 'idartlang' => $idartlang,
421: 'idlang' => $idlang,
422: 'title' => $title,
423: 'summary' => $summary,
424: 'artspec' => $artspec,
425: 'created' => $created,
426: 'iscurrentversion' => 1,
427: 'lastmodified' => $lastmodified,
428: 'published' => $published,
429: 'publishedby' => $publishedby,
430: 'author' => $author,
431: 'artsort' => $artsort,
432: 'datestart' => $datestart,
433: 'dateend' => $dateend,
434: 'keyart' => $keyart,
435: 'searchable' => $searchable,
436: 'sitemapprio' => $sitemapprio,
437: 'changefreq' => $changefreq
438: );
439:
440: if (isset($online)) {
441: $parameters['online'] = $online;
442: } else {
443: $parameters['online'] = $oldOnline;
444: }
445:
446: $versioning->createArticleLanguageVersion($parameters);
447:
448: break;
449: case 'disabled':
450: $artLang->set('title', $title);
451: $artLang->set('urlname', $urlname);
452: $artLang->set('summary', $summary);
453: $artLang->set('artspec', $artspec);
454: $artLang->set('created', $created);
455: $artLang->set('lastmodified', $lastmodified);
456: $artLang->set('modifiedby', $author);
457: $artLang->set('timemgmt', $usetimemgmt);
458: $artLang->set('redirect', $redirect);
459: $artLang->set('external_redirect', $external_redirect);
460: $artLang->set('redirect_url', $redirect_url);
461: $artLang->set('artsort', $artsort);
462: $artLang->set('searchable', $searchable);
463: if ($sitemapprio != -1) {
464: $artLang->set('sitemapprio', $sitemapprio);
465: }
466: if ($changefreq != "nothing") {
467: $artLang->set('changefreq', $changefreq);
468: }
469: $artLang->set('published', date("Y-m-d H:i:s", strtotime($published)));
470:
471:
472: if ($perm->have_perm_area_action('con', 'con_makeonline') || $perm->have_perm_area_action_item('con', 'con_makeonline', $idcat)) {
473: $oldOnline = $artLang->get('online');
474: if (isset($online)) {
475: $artLang->set('online', $online);
476: }
477:
478:
479:
480: if ((int) $online == 1 && $oldOnline == 0) {
481: $artLang->set('published', date('Y-m-d H:i:s'));
482: $artLang->set('publishedby', $author);
483: }
484:
485: $artLang->set('datestart', $datestart);
486: $artLang->set('dateend', $dateend);
487: $artLang->set('time_move_cat', $time_move_cat);
488: $artLang->set('time_target_cat', $time_target_cat);
489: $artLang->set('time_online_move', $time_online_move);
490: }
491:
492:
493: if (!empty($newIdTplCfg) && $idTplCfg != $newIdTplCfg) {
494: $artLang->set('idtplcfg', $newIdTplCfg);
495: }
496:
497: $artLang->store();
498: default:
499: break;
500: }
501:
502:
503: $purge = new cSystemPurge();
504: $purge->clearArticleCache($idartlang);
505: }
506:
507: 508: 509: 510: 511: 512: 513: 514: 515: 516: 517: 518: 519: 520: 521:
522: function conSaveContentEntry($idartlang, $type, $typeid, $value, $bForce = false) {
523: global $auth, $cfgClient, $client, $_cecRegistry, $lang;
524:
525: $oType = new cApiType();
526: if (!$oType->loadByType($type)) {
527:
528: return;
529: }
530:
531: $value = str_replace(cRegistry::getFrontendUrl(), '', $value);
532: $value = stripslashes($value);
533:
534: $iterator = $_cecRegistry->getIterator('Contenido.Content.SaveContentEntry');
535: while (($chainEntry = $iterator->next()) !== false) {
536: $value = $chainEntry->execute($idartlang, $type, $typeid, $value);
537: }
538:
539: $idtype = $oType->get('idtype');
540:
541:
542: $content = new cApiContent();
543: $content->loadByArticleLanguageIdTypeAndTypeId($idartlang, $idtype, $typeid);
544:
545: if (! $content->isLoaded()) {
546: $contentColl = new cApiContentCollection();
547: $content = $contentColl->create($idartlang, $idtype, $typeid, NULL, NULL);
548: }
549:
550:
551: $versioning = new cContentVersioning();
552: $versioning->prepareContentForSaving($idartlang, $content, $value);
553:
554:
555: $purge = new cSystemPurge();
556: $purge->clearArticleCache($idartlang);
557: }
558:
559: 560: 561: 562: 563: 564: 565: 566: 567: 568:
569: function conMakeArticleIndex($idartlang, $idart) {
570:
571:
572: if (cRegistry::getArticleLanguageId() == $idartlang) {
573:
574: $idclient = cRegistry::getClientId();
575: $idlang = cRegistry::getLanguageId();
576: $idcat = cRegistry::getCategoryId();
577: $idart = cRegistry::getArticleId();
578: $idcatlang = cRegistry::getCategoryLanguageId();
579: $idartlang = cRegistry::getArticleLanguageId();
580: } else {
581:
582:
583: $article = new cApiArticle($idart);
584: if ($article->isLoaded()) {
585: $idclient = $article->get('idclient');
586: }
587:
588: $articleLanguage = new cApiArticleLanguage($idartlang);
589: if ($articleLanguage->isLoaded()) {
590: $idlang = $articleLanguage->get('idlang');
591: }
592:
593: $coll = new cApiCategoryArticleCollection();
594: $idcat = array_shift($coll->getCategoryIdsByArticleId($idart));
595:
596: $categoryLanguage = new cApiCategoryLanguage();
597: $categoryLanguage->loadByCategoryIdAndLanguageId($idcat, $idlang);
598: if ($categoryLanguage->isLoaded()) {
599: $idcatlang = $articleLanguage->get('idlang');
600: }
601: }
602:
603:
604: $articleIds = array(
605: 'idclient' => $idclient,
606: 'idlang' => $idlang,
607: 'idcat' => $idcat,
608: 'idcatlang' => $idcatlang,
609: 'idart' => $idart,
610: 'idartlang' => $idartlang
611: );
612:
613:
614: $iterator = cRegistry::getCecRegistry()->getIterator('Contenido.Content.AfterStore');
615: while (false !== $chainEntry = $iterator->next()) {
616: $chainEntry->execute($articleIds);
617: }
618:
619: }
620:
621: 622: 623: 624: 625: 626: 627: 628: 629: 630:
631: function conMakeOnline($idart, $lang, $online = -1) {
632: $auth = cRegistry::getAuth();
633:
634: $artLang = new cApiArticleLanguage();
635: if (!$artLang->loadByArticleAndLanguageId($idart, $lang)) {
636: return;
637: }
638:
639:
640: if($online === -1) {
641: $online = ($artLang->get('online') == 0)? 1 : 0;
642: }
643:
644: $artLang->set('online', $online);
645:
646: if ($online == 1) {
647:
648: $artLang->set('published', date('Y-m-d H:i:s'));
649: $artLang->set('publishedby', $auth->auth['uname']);
650: }
651:
652: $artLang->store();
653:
654:
655: cApiCecHook::execute('Contenido.Article.ConMakeOnline', array(
656: 'idart' => $idart,
657: 'idlang' => $lang,
658: 'state' => $online
659: ));
660: }
661:
662: 663: 664: 665: 666: 667: 668: 669:
670: function conMakeOnlineBulkEditing($idarts, $idlang, $online) {
671: $auth = cRegistry::getAuth();
672:
673:
674: $idartString = implode("','", $idarts);
675: $artLangCollection = new cApiArticleLanguageCollection();
676: $artLangCollection->select("`idart` IN ('" . $idartString . "') AND `idlang`='" . cSecurity::toInteger($idlang) . "'");
677:
678:
679: while (($artLang = $artLangCollection->next()) !== false) {
680: $artLang->set('online', $online);
681: if ($online == 1) {
682:
683: $artLang->set('published', date('Y-m-d H:i:s'));
684: $artLang->set('publishedby', $auth->auth['uname']);
685: }
686: $artLang->store();
687: }
688: }
689:
690: 691: 692: 693: 694: 695: 696: 697:
698: function conLock($idart, $lang) {
699: $artLang = new cApiArticleLanguage();
700: if (!$artLang->loadByArticleAndLanguageId($idart, $lang)) {
701: return;
702: }
703:
704: $locked = ($artLang->get('locked') == 0)? 1 : 0;
705:
706: $artLang->set('locked', $locked);
707: $artLang->store();
708: }
709:
710: 711: 712: 713: 714: 715: 716: 717:
718: function conLockBulkEditing($idarts, $idlang, $lock) {
719:
720: $idartString = implode("','", $idarts);
721: $artLangCollection = new cApiArticleLanguageCollection();
722: $artLangCollection->select("`idart` IN ('" . $idartString . "') AND `idlang`='" . cSecurity::toInteger($idlang) . "'");
723:
724:
725: while (($artLang = $artLangCollection->next()) !== false) {
726: $artLang->set('locked', $lock);
727: $artLang->store();
728: }
729: }
730:
731: 732: 733: 734: 735: 736: 737: 738: 739:
740: function conIsLocked($idart, $lang) {
741: $artLang = new cApiArticleLanguage();
742: if (!$artLang->loadByArticleAndLanguageId($idart, $lang)) {
743: return false;
744: }
745: return (1 == $artLang->get('locked'));
746: }
747:
748: 749: 750: 751: 752: 753: 754: 755: 756: 757:
758: function conMakeCatOnline($idcat, $lang, $status) {
759: global $cfg;
760:
761: $catLang = new cApiCategoryLanguage();
762: if (!$catLang->loadByCategoryIdAndLanguageId($idcat, $lang)) {
763: return;
764: }
765:
766: $status = (1 == $status)? 1 : 0;
767:
768: $catLang->set('visible', $status);
769: $catLang->set('lastmodified', date('Y-m-d H:i:s'));
770: $catLang->store();
771:
772: if ($cfg['pathresolve_heapcache'] == true && !$status = 0) {
773: $oPathresolveCacheColl = new cApiPathresolveCacheCollection();
774: $oPathresolveCacheColl->deleteByCategoryAndLanguage($idcat, $lang);
775: }
776:
777:
778: cApiCecHook::execute('Contenido.Article.ConMakeCatOnline', array(
779: 'idcat' => $idcat,
780: 'idlang' => $lang,
781: ));
782: }
783:
784: 785: 786: 787: 788: 789: 790: 791: 792: 793: 794: 795: 796:
797: function conMakePublic($idcat, $lang, $public) {
798:
799: foreach (conDeeperCategoriesArray($idcat) as $tmpIdcat) {
800: $oCatLang = new cApiCategoryLanguage();
801: $oCatLang->loadByCategoryIdAndLanguageId($tmpIdcat, $lang);
802: $oCatLang->set('public', $public);
803: $oCatLang->set('lastmodified', date('Y-m-d H:i:s'));
804: $oCatLang->store();
805: }
806:
807: }
808:
809: 810: 811: 812: 813: 814:
815: function conDeleteart($idart) {
816: global $_cecRegistry, $cfgClient, $client;
817: $lang = cRegistry::getLanguageId();
818:
819:
820: $artLang = new cApiArticleLanguage();
821: if (!$artLang->loadByArticleAndLanguageId($idart, $lang)) {
822: return;
823: }
824:
825: $idartlang = $artLang->get('idartlang');
826: $idtplcfg = $artLang->get('idtplcfg');
827:
828: $catArtColl = new cApiCategoryArticleCollection();
829: $cats = $catArtColl->getIdsByWhereClause("idart = " . (int) $idart);
830:
831:
832: foreach ($cats as $idcat) {
833:
834: if (isStartArticle($idartlang, $idcat, $lang)) {
835: $catLang = new cApiCategoryLanguage();
836: $catLang->loadByCategoryIdAndLanguageId($idcat, $lang);
837: $catLang->set('startidartlang', 0);
838: $catLang->store();
839: }
840: }
841:
842: $contentColl = new cApiContentCollection();
843: $contentColl->deleteBy('idartlang', (int) $idartlang);
844:
845:
846: $artLangColl = new cApiArticleLanguageCollection();
847: $artLangColl->delete((int) $idartlang);
848:
849:
850: $oArtLangVersColl = new cApiArticleLanguageVersionCollection();
851: $oArtLangVersColl->deleteBy('idartlang', (int) $idartlang);
852:
853: if ($idtplcfg != 0) {
854: $containerConfColl = new cApiContainerConfigurationCollection();
855: $containerConfColl->deleteBy('idtplcfg', (int) $idtplcfg);
856:
857: $tplConfColl = new cApiTemplateConfigurationCollection();
858: $tplConfColl->delete($idtplcfg);
859: }
860:
861:
862: $artLangColl->resetQuery();
863: $artLangColl->select('idart = ' . (int) $idart);
864: if ($artLangColl->next()) {
865: return;
866: }
867:
868: $catArtColl = new cApiCategoryArticleCollection();
869: $catArtColl->select('idart = ' . (int) $idart);
870: while (($oCatArtItem = $catArtColl->next()) !== false) {
871:
872: if (cFileHandler::exists($cfgClient[$client]['code']['path'])) {
873:
874: foreach (new DirectoryIterator($cfgClient[$client]['code']['path']) as $file) {
875: if ($file->isFile() === false) {
876: continue;
877: }
878:
879: $extension = substr($file, strrpos($file->getBasename(), '.') + 1);
880: if ($extension != 'php') {
881: continue;
882: }
883:
884: if (preg_match('/[0-9*].[0-9*].' . $oCatArtItem->get('idcatart') . '/s', $file->getBasename())) {
885: cFileHandler::remove($cfgClient[$client]['code']['path'] . '/' . $file->getFilename());
886: }
887: }
888: }
889:
890:
891: $statColl = new cApiStatCollection();
892: $statColl->deleteBy('idcatart', (int) $oCatArtItem->get('idcatart'));
893: }
894:
895:
896: $catLangColl = new cApiCategoryLanguageCollection();
897: $catLangColl->select('`idlang`=' . cSecurity::toInteger($lang));
898: $idcats = $catLangColl->getAllIds();
899: $idcatsString = "('" . implode('\',\'', $idcats) . "')";
900: $catArtColl->resetQuery();
901: $catArtColl->deleteByWhereClause('`idart`=' . $idart . ' AND `idcat` IN ' . $idcatsString);
902:
903:
904: $oArtColl = new cApiArticleCollection();
905: $oArtColl->delete((int) $idart);
906:
907:
908: $search = new cSearchIndex();
909: $search->start($idart, array());
910:
911:
912: $metaTagColl = new cApiMetaTagCollection();
913: $metaTagColl->deleteBy('idartlang', (int) $idartlang);
914:
915:
916:
917: $iterator = $_cecRegistry->getIterator("Contenido.Content.DeleteArticle");
918: while (($chainEntry = $iterator->next()) !== false) {
919: $chainEntry->execute($idart);
920: }
921:
922:
923: $metaTagColl = new cApiMetaTagCollection();
924: $metaTagColl->deleteBy('idartlang', (int) $idartlang);
925:
926:
927: $contentVersionColl = new cApiContentVersionCollection();
928: $contentVersionColl->deleteBy('idartlang', (int) $idartlang);
929: $artLangVersionColl = new cApiArticleLanguageVersionCollection();
930: $artLangVersionColl->deleteBy('idartlang', (int) $idartlang);
931: $metaTagVersionColl = new cApiMetaTagVersionCollection();
932: $metaTagVersionColl->deleteBy('idartlang', (int) $idartlang);
933: }
934:
935: 936: 937: 938: 939: 940: 941: 942: 943:
944: function (&$string) {
945: return cString::extractNumber($string);
946: }
947:
948: 949: 950: 951: 952: 953: 954: 955:
956: function conChangeTemplateForCat($idcat, $idtpl) {
957: global $lang;
958:
959: $oCatLang = new cApiCategoryLanguage();
960: if (!$oCatLang->loadByCategoryIdAndLanguageId($idcat, $lang)) {
961: return;
962: }
963:
964: if ($oCatLang->get('idtplcfg')) {
965:
966: $oContainerConfColl = new cApiContainerConfigurationCollection();
967: $oContainerConfColl->deleteBy('idtplcfg', (int) $oCatLang->get('idtplcfg'));
968:
969:
970: $oTplConfColl = new cApiTemplateConfigurationCollection();
971: $oTplConfColl->delete((int) $oCatLang->get('idtplcfg'));
972: }
973:
974:
975: if (0 == $idtpl) {
976: $oCatLang->set('idtplcfg', 0);
977: $oCatLang->store();
978: } else {
979:
980: $oTpl = new cApiTemplate();
981: $oTpl->loadBy('idtpl', (int) $idtpl);
982:
983: if (0 != $oTpl->get('idtplcfg')) {
984:
985: $oTplConfColl = new cApiTemplateConfigurationCollection();
986: $oTplConf = $oTplConfColl->create($idtpl);
987:
988:
989:
990: $oTplConfColl->copyTemplatePreconfiguration($idtpl, $oTplConf->get('idtplcfg'));
991:
992:
993: $oCatLang->set('idtplcfg', $oTplConf->get('idtplcfg'));
994: $oCatLang->store();
995: } else {
996:
997: $oTplConfColl = new cApiTemplateConfigurationCollection();
998: $oTplConf = $oTplConfColl->create($idtpl);
999:
1000:
1001: $oCatLang->set('idtplcfg', $oTplConf->get('idtplcfg'));
1002: $oCatLang->store();
1003: }
1004: }
1005:
1006: conGenerateCodeForAllArtsInCategory($idcat);
1007: }
1008:
1009: 1010: 1011: 1012: 1013: 1014: 1015: 1016: 1017:
1018: function conFetchCategoryTree($client = false, $lang = false) {
1019: if ($client === false) {
1020: $client = $GLOBALS['client'];
1021: }
1022: if ($lang === false) {
1023: $lang = $GLOBALS['lang'];
1024: }
1025:
1026: $oCatTreeColl = new cApiCategoryTreeCollection();
1027: $aCatTree = $oCatTreeColl->getCategoryTreeStructureByClientIdAndLanguageId($client, $lang);
1028:
1029: return $aCatTree;
1030: }
1031:
1032: 1033: 1034: 1035: 1036: 1037: 1038: 1039:
1040: function conDeeperCategoriesArray($idcat) {
1041: global $client;
1042:
1043: $coll = new cApiCategoryCollection();
1044: $idcats = $coll->getAllCategoryIdsRecursive($idcat, $client);
1045:
1046: return $idcats;
1047: }
1048:
1049: 1050: 1051: 1052: 1053: 1054: 1055: 1056: 1057: 1058: 1059: 1060: 1061: 1062: 1063: 1064: 1065: 1066: 1067: 1068: 1069: 1070: 1071:
1072: function conCreateLocationString($idcat, $seperator, &$catStr, $makeLink = false, $linkClass = '', $firstTreeElementToUse = 0, $uselang = 0, $final = true, $usecache = false) {
1073: global $cfg, $client, $cfgClient, $lang, $sess;
1074:
1075: if ($idcat == 0) {
1076: $catStr = i18n("Lost and found");
1077: return;
1078: }
1079:
1080: if ($uselang == 0) {
1081: $uselang = $lang;
1082: }
1083:
1084: $locationStringCache = cRegistry::getAppVar('locationStringCache');
1085: $locationStringCacheFile = $cfgClient[$client]['cache']['path'] . "locationstring-cache-$uselang.txt";
1086:
1087: if ($final == true && $usecache == true) {
1088: if (!is_array($locationStringCache)) {
1089: if (cFileHandler::exists($locationStringCacheFile)) {
1090: $locationStringCache = unserialize(cFileHandler::read($locationStringCacheFile));
1091: } else {
1092: $locationStringCache = array();
1093: }
1094: cRegistry::setAppVar('locationStringCache', $locationStringCache);
1095: }
1096:
1097: if (array_key_exists($idcat, $locationStringCache)) {
1098: if ($locationStringCache[$idcat]['expires'] > time()) {
1099: $catStr = $locationStringCache[$idcat]['name'];
1100: return;
1101: }
1102: }
1103: }
1104:
1105: $db = cRegistry::getDb();
1106:
1107: $sql = "SELECT a.name AS name, a.idcat AS idcat, b.parentid AS parentid, c.level as level " . "FROM `:cat_lang` AS a, `:cat` AS b, `:cat_tree` AS c " . "WHERE a.idlang = :idlang AND b.idclient = :idclient AND b.idcat = :idcat AND a.idcat = b.idcat AND c.idcat = b.idcat";
1108:
1109: $sql = $db->prepare($sql, array(
1110: 'cat_lang' => $cfg['tab']['cat_lang'],
1111: 'cat' => $cfg['tab']['cat'],
1112: 'cat_tree' => $cfg['tab']['cat_tree'],
1113: 'idlang' => (int) $uselang,
1114: 'idclient' => (int) $client,
1115: 'idcat' => (int) $idcat
1116: ));
1117: $db->query($sql);
1118: $db->nextRecord();
1119:
1120: if ($db->f('level') >= $firstTreeElementToUse) {
1121: $name = $db->f('name');
1122: $parentid = $db->f('parentid');
1123:
1124:
1125: if ($makeLink == true) {
1126: $linkUrl = $sess->url("front_content.php?idcat=$idcat");
1127: $name = '<a href="' . $linkUrl . '" class="' . $linkClass . '">' . $name . '</a>';
1128: }
1129:
1130: $tmp_cat_str = $name . $seperator . $catStr;
1131: $catStr = $tmp_cat_str;
1132: }
1133:
1134: if ($parentid != 0) {
1135: conCreateLocationString($parentid, $seperator, $catStr, $makeLink, $linkClass, $firstTreeElementToUse, $uselang, false);
1136: } else {
1137: $sep_length = strlen($seperator);
1138: $str_length = strlen($catStr);
1139: $tmp_length = $str_length - $sep_length;
1140: $catStr = substr($catStr, 0, $tmp_length);
1141: }
1142:
1143: if ($final == true && $usecache == true) {
1144: $locationStringCache[$idcat]['name'] = $catStr;
1145: $locationStringCache[$idcat]['expires'] = time() + 3600;
1146:
1147: if (is_writable($cfgClient[$client]['cache']['path'])) {
1148: cFileHandler::write($locationStringCacheFile, serialize($locationStringCache));
1149: }
1150: cRegistry::setAppVar('locationStringCache', $locationStringCache);
1151: }
1152: }
1153:
1154: 1155: 1156: 1157: 1158: 1159: 1160: 1161: 1162: 1163:
1164: function conMakeStart($idcatart, $isstart) {
1165: global $lang;
1166:
1167:
1168: $oCatArt = new cApiCategoryArticle((int) $idcatart);
1169: if (!$oCatArt->isLoaded()) {
1170: return;
1171: }
1172: $idart = $oCatArt->get('idart');
1173: $idcat = $oCatArt->get('idcat');
1174:
1175:
1176: $oArtLang = new cApiArticleLanguage();
1177: if (!$oArtLang->loadByArticleAndLanguageId($idart, $lang)) {
1178: return;
1179: }
1180: $idartlang = $oArtLang->get('idartlang');
1181:
1182:
1183: $oCatLang = new cApiCategoryLanguage();
1184: if ($oCatLang->loadByCategoryIdAndLanguageId($idcat, $lang)) {
1185: if ($isstart == 1) {
1186: $oCatLang->set('startidartlang', $idartlang);
1187: } else {
1188: $oCatLang->set('startidartlang', 0);
1189: }
1190: $oCatLang->store();
1191: }
1192:
1193: if ($isstart == 1) {
1194:
1195: $oArtLang->set('timemgmt', 0);
1196: $oArtLang->store();
1197: }
1198:
1199:
1200: cApiCecHook::execute('Contenido.Article.ConMakeStart', array(
1201: 'idart' => $oCatArt->get("idart"),
1202: 'idlang' => $lang,
1203: ));
1204: }
1205:
1206: 1207: 1208: 1209: 1210: 1211:
1212: function conGenerateCodeForArtInAllCategories($idart) {
1213: $oCatArtColl = new cApiCategoryArticleCollection();
1214: $ids = $oCatArtColl->getIdsByWhereClause('idart = ' . (int) $idart);
1215: conSetCodeFlagBulkEditing($ids);
1216: }
1217:
1218: 1219: 1220: 1221: 1222: 1223:
1224: function conGenerateCodeForAllArtsInCategory($idcat) {
1225: $oCatArtColl = new cApiCategoryArticleCollection();
1226: $ids = $oCatArtColl->getIdsByWhereClause('idcat = ' . (int) $idcat);
1227: conSetCodeFlagBulkEditing($ids);
1228: }
1229:
1230: 1231: 1232:
1233: function conGenerateCodeForClient() {
1234: global $client;
1235: $oCatArtColl = new cApiCategoryArticleCollection();
1236: $ids = $oCatArtColl->getAllIdsByClientId($client);
1237: conSetCodeFlagBulkEditing($ids);
1238: }
1239:
1240: 1241: 1242: 1243: 1244: 1245:
1246: function conGenerateCodeForAllartsUsingLayout($idlay) {
1247: global $cfg;
1248:
1249: $db = cRegistry::getDb();
1250:
1251: $sql = "SELECT idtpl FROM " . $cfg["tab"]["tpl"] . " WHERE idlay='" . cSecurity::toInteger($idlay) . "'";
1252: $db->query($sql);
1253: while ($db->nextRecord()) {
1254: conGenerateCodeForAllArtsUsingTemplate($db->f("idtpl"));
1255: }
1256: }
1257:
1258: 1259: 1260: 1261: 1262: 1263:
1264: function conGenerateCodeForAllartsUsingMod($idmod) {
1265: $oContainerColl = new cApiContainerCollection();
1266: $rsList = $oContainerColl->getFieldsByWhereClause(array(
1267: 'idtpl'
1268: ), 'idmod = ' . (int) $idmod);
1269: foreach ($rsList as $rs) {
1270: conGenerateCodeForAllArtsUsingTemplate($rs['idtpl']);
1271: }
1272: }
1273:
1274: 1275: 1276: 1277: 1278: 1279:
1280: function conGenerateCodeForAllArtsUsingTemplate($idtpl) {
1281: global $cfg, $client;
1282:
1283: $db = cRegistry::getDb();
1284:
1285: $oCatArtColl = new cApiCategoryArticleCollection();
1286:
1287:
1288: $sql = "SELECT
1289: b.idcat
1290: FROM
1291: " . $cfg['tab']['tpl_conf'] . " AS a,
1292: " . $cfg['tab']['cat_lang'] . " AS b,
1293: " . $cfg['tab']['cat'] . " AS c
1294: WHERE
1295: a.idtpl = " . cSecurity::toInteger($idtpl) . " AND
1296: b.idtplcfg = a.idtplcfg AND
1297: c.idclient = " . cSecurity::toInteger($client) . " AND
1298: b.idcat = c.idcat";
1299:
1300: $db->query($sql);
1301:
1302: while ($db->nextRecord()) {
1303: $oCatArtColl->resetQuery();
1304: $ids = $oCatArtColl->getIdsByWhereClause('idcat = ' . cSecurity::toInteger($db->f('idcat')));
1305: foreach ($ids as $id) {
1306: conSetCodeFlag($id);
1307: }
1308: }
1309:
1310:
1311: $sql = "SELECT
1312: b.idart
1313: FROM
1314: " . $cfg['tab']['tpl_conf'] . " AS a,
1315: " . $cfg['tab']['art_lang'] . " AS b,
1316: " . $cfg['tab']['art'] . " AS c
1317: WHERE
1318: a.idtpl = " . cSecurity::toInteger($idtpl) . " AND
1319: b.idtplcfg = a.idtplcfg AND
1320: c.idclient = " . cSecurity::toInteger($client) . " AND
1321: b.idart = c.idart";
1322:
1323: $db->query($sql);
1324:
1325: while ($db->nextRecord()) {
1326: $oCatArtColl->resetQuery();
1327: $ids = $oCatArtColl->getIdsByWhereClause('idart = ' . (int) $db->f('idart'));
1328: foreach ($ids as $id) {
1329: conSetCodeFlag($id);
1330: }
1331: }
1332: }
1333:
1334: 1335: 1336:
1337: function conGenerateCodeForAllArts() {
1338: global $cfg;
1339:
1340: $db = cRegistry::getDb();
1341:
1342: $sql = "SELECT idcatart FROM " . $cfg['tab']['cat_art'];
1343: $db->query($sql);
1344: while ($db->nextRecord()) {
1345: conSetCodeFlag($db->f("idcatart"));
1346: }
1347: }
1348:
1349: 1350: 1351: 1352: 1353: 1354:
1355: function conSetCodeFlag($idcatart) {
1356: global $client, $cfgClient;
1357:
1358:
1359: $coll = new cApiCategoryArticleCollection();
1360: $coll->setCreateCodeFlag($idcatart);
1361:
1362:
1363: if (cFileHandler::exists($cfgClient[$client]['code']['path'])) {
1364:
1365: foreach (new DirectoryIterator($cfgClient[$client]['code']['path']) as $file) {
1366: if ($file->isFile() === false) {
1367: continue;
1368: }
1369:
1370: $extension = substr($file, strrpos($file->getBasename(), '.') + 1);
1371: if ($extension != 'php') {
1372: continue;
1373: }
1374:
1375: if (preg_match('/[0-9*].[0-9*].' . $idcatart . '/s', $file->getBasename())) {
1376: cFileHandler::remove($cfgClient[$client]['code']['path'] . '/' . $file->getFilename());
1377: }
1378: }
1379: }
1380: }
1381:
1382: 1383: 1384: 1385: 1386: 1387:
1388: function conSetCodeFlagBulkEditing(array $idcatarts) {
1389: global $client, $cfgClient;
1390:
1391: if (count($idcatarts) == 0) {
1392: return;
1393: }
1394:
1395:
1396: $oCatArtColl = new cApiCategoryArticleCollection();
1397: $oCatArtColl->setCreateCodeFlag($idcatarts);
1398:
1399: if (cFileHandler::exists($cfgClient[$client]['code']['path']) === false) {
1400: return;
1401: }
1402:
1403:
1404: foreach ($idcatarts as $id) {
1405:
1406: foreach (new DirectoryIterator($cfgClient[$client]['code']['path']) as $file) {
1407: if ($file->isFile() === false) {
1408: continue;
1409: }
1410:
1411: $extension = substr($file, strrpos($file->getBasename(), '.') + 1);
1412: if ($extension != 'php') {
1413: continue;
1414: }
1415:
1416: if (preg_match('/[0-9*].[0-9*].' . $id . '/s', $file->getBasename())) {
1417: cFileHandler::remove($cfgClient[$client]['code']['path'] . '/' . $file->getFilename());
1418: }
1419: }
1420: }
1421: }
1422:
1423: 1424: 1425:
1426: function conFlagOnOffline() {
1427: global $cfg;
1428:
1429: $db = cRegistry::getDb();
1430:
1431: $oArtLangColl = new cApiArticleLanguageCollection();
1432:
1433:
1434: $where = "NOW() < datestart AND datestart != '0000-00-00 00:00:00' AND datestart IS NOT NULL AND timemgmt = 1";
1435: $ids = $oArtLangColl->getIdsByWhereClause($where);
1436: foreach ($ids as $id) {
1437: $sql = "UPDATE " . $cfg['tab']['art_lang'] . " SET online = 0 WHERE idartlang = " . (int) $id;
1438: $db->query($sql);
1439: }
1440: if(count($ids) > 0) {
1441:
1442: cApiCecHook::execute('Contenido.Article.conFlagOnOffline', $ids);
1443: }
1444:
1445:
1446: $where = "NOW() > datestart AND (NOW() < dateend OR dateend = '0000-00-00 00:00:00') AND " . "online = 0 AND timemgmt = 1";
1447: $oArtLangColl->resetQuery();
1448: $ids = $oArtLangColl->getIdsByWhereClause($where);
1449: foreach ($ids as $id) {
1450: $sql = "UPDATE " . $cfg['tab']['art_lang'] . " SET online = 1, published = datestart WHERE idartlang = " . (int) $id;
1451: $db->query($sql);
1452: }
1453: if(count($ids) > 0) {
1454:
1455: cApiCecHook::execute('Contenido.Article.conFlagOnOffline', $ids);
1456: }
1457:
1458:
1459: $where = "NOW() > dateend AND dateend != '0000-00-00 00:00:00' AND timemgmt = 1 AND online = 1";
1460: $oArtLangColl->resetQuery();
1461: $ids = $oArtLangColl->getIdsByWhereClause($where);
1462: foreach ($ids as $id) {
1463: $sql = "UPDATE " . $cfg['tab']['art_lang'] . " SET online = 0 WHERE idartlang = " . (int) $id;
1464: $db->query($sql);
1465: }
1466: if(count($ids) > 0) {
1467:
1468: cApiCecHook::execute('Contenido.Article.conFlagOnOffline', $ids);
1469: }
1470: }
1471:
1472: 1473: 1474:
1475: function conMoveArticles() {
1476: global $cfg;
1477:
1478: $db = cRegistry::getDb();
1479:
1480:
1481: $fields = array(
1482: 'idartlang',
1483: 'idart',
1484: 'time_move_cat',
1485: 'time_target_cat',
1486: 'time_online_move'
1487: );
1488: $where = "NOW() > dateend AND dateend != '0000-00-00 00:00:00' AND timemgmt = 1 AND time_move_cat = 1";
1489: $oArtLangColl = new cApiArticleLanguageCollection();
1490: $rsList = $oArtLangColl->getFieldsByWhereClause($fields, $where);
1491:
1492: foreach ($rsList as $rs) {
1493: $online = ($rs['time_online_move'] == '1')? 1 : 0;
1494: $sql = array();
1495: $sql[] = 'UPDATE ' . $cfg['tab']['art_lang'] . ' SET timemgmt = 0, online = 0 WHERE idartlang = ' . (int) $rs['idartlang'] . ';';
1496: $sql[] = 'UPDATE ' . $cfg['tab']['cat_art'] . ' SET idcat = ' . (int) $rs['time_target_cat'] . ', createcode = 1 WHERE idart = ' . (int) $rs['idart'] . ';';
1497: $sql[] = 'UPDATE ' . $cfg['tab']['art_lang'] . ' SET online = ' . (int) $online . ' WHERE idart = ' . (int) $rs['idart'] . ';';
1498:
1499:
1500:
1501: $db->query($sql[0]);
1502: $db->query($sql[1]);
1503: $db->query($sql[2]);
1504:
1505:
1506: cApiCecHook::execute('Contenido.Article.conMoveArticles_Loop', $rs);
1507: }
1508: }
1509:
1510: 1511: 1512: 1513: 1514: 1515:
1516: function conCopyTemplateConfiguration($srcidtplcfg) {
1517: $oTemplateConf = new cApiTemplateConfiguration((int) $srcidtplcfg);
1518: if (!$oTemplateConf->isLoaded()) {
1519: return NULL;
1520: }
1521:
1522: $oTemplateConfColl = new cApiTemplateConfigurationCollection();
1523: $oNewTemplateConf = $oTemplateConfColl->create($oTemplateConf->get('idtpl'));
1524: return (is_object($oNewTemplateConf))? $oNewTemplateConf->get('idtplcfg') : NULL;
1525: }
1526:
1527: 1528: 1529: 1530: 1531: 1532: 1533: 1534:
1535: function conCopyContainerConf($srcidtplcfg, $dstidtplcfg) {
1536: $counter = 0;
1537: $oContainerConfColl = new cApiContainerConfigurationCollection();
1538: $oContainerConfColl->select('idtplcfg = ' . cSecurity::toInteger($srcidtplcfg));
1539: while (($oContainerConf = $oContainerConfColl->next()) !== false) {
1540: $oNewContainerConfColl = new cApiContainerConfigurationCollection();
1541: $oNewContainerConfColl->copyItem($oContainerConf, array(
1542: 'idtplcfg' => cSecurity::toInteger($dstidtplcfg)
1543: ));
1544: $counter++;
1545: }
1546: return ($counter > 0)? true : false;
1547: }
1548:
1549: 1550: 1551: 1552: 1553: 1554: 1555:
1556: function conCopyContent($srcidartlang, $dstidartlang) {
1557: $oContentColl = new cApiContentCollection();
1558: $oContentColl->select('idartlang = ' . cSecurity::toInteger($srcidartlang));
1559: while (($oContent = $oContentColl->next()) !== false) {
1560: $oNewContentColl = new cApiContentCollection();
1561: $oNewContentColl->copyItem($oContent, array(
1562: 'idartlang' => cSecurity::toInteger($dstidartlang)
1563: ));
1564: }
1565: }
1566:
1567: 1568: 1569: 1570: 1571: 1572: 1573:
1574: function conCopyMetaTags($srcidartlang, $dstidartlang) {
1575: $oMetaTagColl = new cApiMetaTagCollection();
1576: $oMetaTagColl->select('idartlang = ' . cSecurity::toInteger($srcidartlang));
1577: while (($oMetaTag = $oMetaTagColl->next()) !== false) {
1578: $oNewMetaTagColl = new cApiMetaTagCollection();
1579: $oNewMetaTagColl->copyItem($oMetaTag, array(
1580: 'idartlang' => cSecurity::toInteger($dstidartlang)
1581: ));
1582: }
1583: }
1584:
1585: 1586: 1587: 1588: 1589: 1590: 1591: 1592: 1593: 1594:
1595: function conCopyArtLang($srcidart, $dstidart, $newtitle, $useCopyLabel = true) {
1596: global $auth, $lang;
1597:
1598: $oSrcArtLang = new cApiArticleLanguage();
1599: if (!$oSrcArtLang->loadByArticleAndLanguageId($srcidart, $lang)) {
1600: return;
1601: }
1602:
1603:
1604: if ($oSrcArtLang->get('idtplcfg') != 0) {
1605: $newidtplcfg = conCopyTemplateConfiguration($oSrcArtLang->get('idtplcfg'));
1606: conCopyContainerConf($oSrcArtLang->get('idtplcfg'), $newidtplcfg);
1607: }
1608:
1609: $idart = $dstidart;
1610: $idlang = $oSrcArtLang->get('idlang');
1611: $idtplcfg = $newidtplcfg;
1612:
1613: if ($newtitle != '') {
1614: $title = sprintf($newtitle, $oSrcArtLang->get('title'));
1615: } else if ($useCopyLabel == true) {
1616: $title = sprintf(i18n('%s (Copy)'), $oSrcArtLang->get('title'));
1617: } else {
1618: $title = $oSrcArtLang->get('title');
1619: }
1620:
1621:
1622: $oArtLangColl = new cApiArticleLanguageCollection();
1623: $fieldsToOverwrite = array(
1624: 'idart' => $idart,
1625: 'idlang' => $idlang,
1626: 'idtplcfg' => cSecurity::toInteger($idtplcfg),
1627: 'online' => 0,
1628: 'title' => $title,
1629: 'created' => date('Y-m-d H:i:s'),
1630: 'lastmodified' => date('Y-m-d H:i:s'),
1631: 'modifiedby' => $auth->auth['uname'],
1632: 'published' => '',
1633: 'publishedby' => ''
1634: );
1635: $oNewArtLang = $oArtLangColl->copyItem($oSrcArtLang, $fieldsToOverwrite);
1636:
1637: if (!is_object($oNewArtLang)) {
1638: return;
1639: }
1640:
1641:
1642: conCopyContent($oSrcArtLang->get('idartlang'), $oNewArtLang->get('idartlang'));
1643:
1644:
1645: conCopyMetaTags($oSrcArtLang->get('idartlang'), $oNewArtLang->get('idartlang'));
1646:
1647:
1648: cApiCecHook::execute('Contenido.Article.conCopyArtLang_AfterInsert', array(
1649: 'idartlang' => cSecurity::toInteger($oNewArtLang->get('idartlang')),
1650: 'idart' => cSecurity::toInteger($idart),
1651: 'idlang' => cSecurity::toInteger($idlang),
1652: 'idtplcfg' => cSecurity::toInteger($idtplcfg),
1653: 'title' => $title
1654: ));
1655:
1656:
1657: $versioning = new cContentVersioning();
1658: if ($versioning->getState() != 'advanced') {
1659: conMakeArticleIndex($oNewArtLang->get('idartlang'), $idart);
1660: }
1661: }
1662:
1663: 1664: 1665: 1666: 1667: 1668: 1669: 1670: 1671: 1672:
1673: function conCopyArticle($srcidart, $targetcat = 0, $newtitle = '', $useCopyLabel = true) {
1674:
1675: $oSrcArt = new cApiArticle((int) $srcidart);
1676: if (!$oSrcArt->isLoaded()) {
1677: return false;
1678: }
1679: $idclient = $oSrcArt->get('idclient');
1680:
1681:
1682: $oArtCollection = new cApiArticleCollection();
1683: $oNewArt = $oArtCollection->create($idclient);
1684: if (!is_object($oNewArt)) {
1685: return false;
1686: }
1687: $dstidart = $oNewArt->get('idart');
1688:
1689: conCopyArtLang($srcidart, $dstidart, $newtitle, $useCopyLabel);
1690:
1691:
1692: $oCatArtColl = new cApiCategoryArticleCollection();
1693: $oCatArtColl->select('idart = ' . (int) $srcidart);
1694: while (($oCatArt = $oCatArtColl->next()) !== false) {
1695:
1696: $oCatArtColl2 = new cApiCategoryArticleCollection();
1697: $fieldsToOverwrite = array(
1698: 'idcat' => ($targetcat != 0)? $targetcat : $oCatArt->get('idcat'),
1699: 'idart' => $dstidart,
1700: 'status' => ($oCatArt->get('status') !== '')? $oCatArt->get('status') : 0,
1701: 'createcode' => 1,
1702: 'is_start' => 0
1703: );
1704: $oCatArtColl2->copyItem($oCatArt, $fieldsToOverwrite);
1705:
1706:
1707: if ($targetcat != 0) {
1708: break;
1709: }
1710: }
1711:
1712:
1713:
1714: $_cecRegistry = cApiCecRegistry::getInstance();
1715: $iterator = $_cecRegistry->getIterator('Contenido.Content.CopyArticle');
1716: while (($chainEntry = $iterator->next()) !== false) {
1717: $chainEntry->execute($srcidart, $dstidart);
1718: }
1719:
1720: return $dstidart;
1721: }
1722:
1723: 1724: 1725: 1726: 1727: 1728: 1729: 1730: 1731: 1732:
1733: function conGetTopmostCat($idcat, $minLevel = 0) {
1734: global $cfg, $client, $lang;
1735:
1736: $db = cRegistry::getDb();
1737:
1738: $sql = "SELECT a.name AS name, a.idcat AS idcat, b.parentid AS parentid, c.level AS level
1739: FROM `:cat_lang` AS a, `:cat` AS b, `:cat_tree` AS c
1740: WHERE a.idlang = :idlang AND b.idclient = :idclient AND b.idcat = :idcat
1741: AND c.idcat = b.idcat AND a.idcat = b.idcat";
1742:
1743: $sql = $db->prepare($sql, array(
1744: 'cat_lang' => $cfg['tab']['cat_lang'],
1745: 'cat' => $cfg['tab']['cat'],
1746: 'cat_tree' => $cfg['tab']['cat_tree'],
1747: 'idlang' => (int) $lang,
1748: 'idclient' => (int) $client,
1749: 'idcat' => (int) $idcat
1750: ));
1751: $db->query($sql);
1752: $db->nextRecord();
1753:
1754: $name = $db->f('name');
1755: $parentid = $db->f('parentid');
1756: $thislevel = $db->f('level');
1757:
1758: if ($parentid != 0 && $thislevel >= $minLevel) {
1759: return conGetTopmostCat($parentid, $minLevel);
1760: } else {
1761: return $idcat;
1762: }
1763: }
1764:
1765: 1766: 1767: 1768: 1769: 1770: 1771: 1772: 1773: 1774:
1775: function conSyncArticle($idart, $srclang, $dstlang) {
1776: $auth = cRegistry::getAuth();
1777:
1778:
1779: $dstArtLang = new cApiArticleLanguage();
1780: $dstArtLang->loadByArticleAndLanguageId($idart, $dstlang);
1781: if ($dstArtLang->isLoaded()) {
1782:
1783: return;
1784: }
1785:
1786: $srcArtLang = new cApiArticleLanguage();
1787: $srcArtLang->loadByArticleAndLanguageId($idart, $srclang);
1788: if (!$srcArtLang->isLoaded()) {
1789:
1790: return;
1791: }
1792: $srcidartlang = $srcArtLang->get('idartlang');
1793:
1794: if ($srcArtLang->get('idtplcfg') != 0) {
1795: $newidtplcfg = tplcfgDuplicate($srcArtLang->get('idtplcfg'));
1796: } else {
1797: $newidtplcfg = 0;
1798: }
1799:
1800:
1801: $artLangColl = new cApiArticleLanguageCollection();
1802: $fieldsToOverwrite = array(
1803: 'idart' => $idart,
1804: 'idlang' => $dstlang,
1805: 'artspec' => 0,
1806: 'online' => 0,
1807: 'created' => date('Y-m-d H:i:s'),
1808: 'lastmodified' => date('Y-m-d H:i:s'),
1809: 'modifiedby' => $auth->auth['uname'],
1810: 'published' => '',
1811: 'publishedby' => '',
1812: 'timemgmt' => 0,
1813: 'datestart' => '',
1814: 'dateend' => '',
1815: 'status' => 0,
1816: 'time_move_cat' => 0,
1817: 'time_target_cat' => 0,
1818: 'time_online_move' => 0,
1819: 'free_use_01' => '',
1820: 'free_use_02' => '',
1821: 'free_use_03' => ''
1822: );
1823: $artLang = $artLangColl->copyItem($srcArtLang, $fieldsToOverwrite);
1824: if (!is_object($artLang)) {
1825: return;
1826: }
1827:
1828: $newidartlang = $artLang->get('idartlang');
1829:
1830:
1831: $param = array();
1832: $param['src_art_lang'] = $srcArtLang->toArray();
1833: $param['dest_art_lang'] = $dstArtLang->toArray();
1834: $param['dest_art_lang']['idartlang'] = cSecurity::toInteger($newidartlang);
1835: $param['dest_art_lang']['idlang'] = cSecurity::toInteger($dstlang);
1836: $param['dest_art_lang']['idtplcfg'] = cSecurity::toInteger($newidtplcfg);
1837: cApiCecHook::execute('Contenido.Article.conSyncArticle_AfterInsert', $param);
1838:
1839:
1840: conCopyContent($srcidartlang, $newidartlang);
1841:
1842:
1843: conCopyMetaTags($srcidartlang, $newidartlang);
1844: }
1845:
1846: 1847: 1848: 1849: 1850: 1851: 1852: 1853: 1854: 1855:
1856: function isStartArticle($idartlang, $idcat, $idlang, $db = NULL) {
1857: $oCatLangColl = new cApiCategoryLanguageCollection();
1858: return $oCatLangColl->isStartArticle($idartlang, $idcat, $idlang);
1859: }
1860:
1861: 1862: 1863: 1864: 1865: 1866: 1867: 1868: 1869: 1870:
1871: function conGetCategoryAssignments($idart, $db = NULL) {
1872:
1873:
1874: if (empty($idart)) {
1875: return array();
1876: }
1877:
1878: $categories = array();
1879: $oCatArtColl = new cApiCategoryArticleCollection();
1880: $entries = $oCatArtColl->getFieldsByWhereClause(array(
1881: 'idcat'
1882: ), 'idart = ' . (int) $idart);
1883: foreach ($entries as $entry) {
1884: $categories[] = $entry['idcat'];
1885: }
1886: return $categories;
1887: }
1888:
1889: 1890: 1891: 1892: 1893: 1894: 1895: 1896: 1897: 1898: 1899:
1900: function conRemoveOldCategoryArticle($idcat, $idart, $idartlang, $client, $lang) {
1901: global $cfgClient;
1902:
1903:
1904: $oCatArtColl = new cApiCategoryArticleCollection();
1905: $oCatArt = $oCatArtColl->fetchByCategoryIdAndArticleId($idcat, $idart);
1906: if (!is_object($oCatArt)) {
1907: return;
1908: }
1909:
1910: $idcatart = $oCatArt->get('idcatart');
1911:
1912:
1913:
1914: foreach (new DirectoryIterator($cfgClient[$client]['code']['path']) as $file) {
1915: if ($file->isFile() === false) {
1916: continue;
1917: }
1918:
1919: $extension = substr($file, strrpos($file->getBasename(), '.') + 1);
1920: if ($extension != 'php') {
1921: continue;
1922: }
1923:
1924: if (preg_match('/[0-9*].[0-9*].' . $idcatart . '/s', $file->getBasename())) {
1925: cFileHandler::remove($cfgClient[$client]['code']['path'] . '/' . $file->getFilename());
1926: }
1927: }
1928:
1929:
1930: $oStatColl = new cApiStatCollection();
1931: $oStatColl->deleteByCategoryArticleAndLanguage($idcatart, $lang);
1932:
1933:
1934: $oCatArtColl->delete($idcatart);
1935:
1936:
1937: if (isStartArticle($idartlang, $idcat, $lang)) {
1938: $oCatLang = new cApiCategoryLanguage();
1939: $oCatLang->loadByCategoryIdAndLanguageId($idcat, $lang);
1940: if ($oCatLang->isLoaded()) {
1941: $oCatLang->set('startidartlang', 0);
1942: $oCatLang->store();
1943: }
1944: }
1945:
1946:
1947: $oArtLang = new cApiArticleLanguage();
1948: $oArtLang->loadByArticleAndLanguageId($idart, $lang);
1949: if ($oArtLang->isLoaded() && $oArtLang->get('idtplcfg') > 0) {
1950: $oTplCfgColl = new cApiTemplateConfigurationCollection();
1951: $oTplCfgColl->delete($oArtLang->get('idtplcfg'));
1952: }
1953: }
1954: