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