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