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