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:
639: $catArt = new cApiCategoryArticle();
640: $catArt->loadBy('idart', (int) $idart);
641: $idcat = $catArt->get('idcat');
642:
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: $contentColl = new cApiContentCollection();
652: $contentColl->deleteBy('idartlang', (int) $idartlang);
653:
654: $artLangColl = new cApiArticleLanguageCollection();
655: $artLangColl->delete((int) $idartlang);
656:
657: if ($idtplcfg != 0) {
658: $containerConfColl = new cApiContainerConfigurationCollection();
659: $containerConfColl->deleteBy('idtplcfg', (int) $idtplcfg);
660:
661: $tplConfColl = new cApiTemplateConfigurationCollection();
662: $tplConfColl->delete('idtplcfg', $idtplcfg);
663: }
664:
665:
666: $artLangColl->resetQuery();
667: $artLangColl->select('idart = ' . (int) $idart);
668: if ($artLangColl->next()) {
669: return;
670: }
671:
672: $catArtColl = new cApiCategoryArticleCollection();
673: $catArtColl->select('idart = ' . (int) $idart);
674: while (($oCatArtItem = $catArtColl->next()) !== false) {
675:
676: if (cFileHandler::exists($cfgClient[$client]['code']['path'])) {
677: 678: 679:
680: foreach (new DirectoryIterator($cfgClient[$client]['code']['path']) as $file) {
681: if ($file->isFile() === false) {
682: continue;
683: }
684:
685: $extension = substr($file, strrpos($file->getBasename(), '.') + 1);
686: if ($extension != 'php') {
687: continue;
688: }
689:
690: if (preg_match('/[0-9*].[0-9*].' . $oCatArtItem->get('idcatart') . '/s', $file->getBasename())) {
691: cFileHandler::remove($cfgClient[$client]['code']['path'] . '/' . $file->getFilename());
692: }
693: }
694: }
695:
696:
697: $statColl = new cApiStatCollection();
698: $statColl->deleteBy('idcatart', (int) $oCatArtItem->get('idcatart'));
699: }
700:
701:
702: $catLangColl = new cApiCategoryLanguageCollection();
703: $catLangColl->select('`idlang`=' . cSecurity::toInteger($lang));
704: $idcats = $catLangColl->getAllIds();
705: $idcatsString = "('" . implode(',', $idcats) . "')";
706: $catArtColl->resetQuery();
707: $catArtColl->deleteByWhereClause('`idart`=' . $idart . ' AND `idcat` IN ' . $idcatsString);
708:
709:
710: $oArtColl = new cApiArticleCollection();
711: $oArtColl->delete((int) $idart);
712:
713:
714: $search = new cSearchIndex();
715: $search->start($idart, array());
716:
717:
718:
719: $iterator = $_cecRegistry->getIterator("Contenido.Content.DeleteArticle");
720: while (($chainEntry = $iterator->next()) !== false) {
721: $chainEntry->execute($idart);
722: }
723: }
724:
725: 726: 727: 728: 729:
730: function (&$string) {
731: $string = preg_replace('/[^0-9]/', '', $string);
732: }
733:
734: 735: 736: 737: 738: 739:
740: function conChangeTemplateForCat($idcat, $idtpl) {
741: global $lang;
742:
743: $oCatLang = new cApiCategoryLanguage();
744: if (!$oCatLang->loadByCategoryIdAndLanguageId($idcat, $lang)) {
745: return;
746: }
747:
748: if ($oCatLang->get('idtplcfg')) {
749:
750: $oContainerConfColl = new cApiContainerConfigurationCollection();
751: $oContainerConfColl->deleteBy('idtplcfg', (int) $oCatLang->get('idtplcfg'));
752:
753:
754: $oTplConfColl = new cApiTemplateConfigurationCollection();
755: $oTplConfColl->delete('idtplcfg', (int) $oCatLang->get('idtplcfg'));
756: }
757:
758:
759: if (0 == $idtpl) {
760: $oCatLang->set('idtplcfg', 0);
761: $oCatLang->store();
762: } else {
763:
764: $oTpl = new cApiTemplate();
765: $oTpl->loadBy('idtpl', (int) $idtpl);
766:
767: if (0 != $oTpl->get('idtplcfg')) {
768:
769: $oTplConfColl = new cApiTemplateConfigurationCollection();
770: $oTplConf = $oTplConfColl->create($idtpl);
771:
772:
773:
774: $oTplConfColl->copyTemplatePreconfiguration($idtpl, $oTplConf->get('idtplcfg'));
775:
776:
777: $oCatLang->set('idtplcfg', $oTplConf->get('idtplcfg'));
778: $oCatLang->store();
779: } else {
780:
781: $oTplConfColl = new cApiTemplateConfigurationCollection();
782: $oTplConf = $oTplConfColl->create($idtpl);
783:
784:
785: $oCatLang->set('idtplcfg', $oTplConf->get('idtplcfg'));
786: $oCatLang->store();
787: }
788: }
789:
790: conGenerateCodeForAllartsInCategory($idcat);
791: }
792:
793: 794: 795: 796: 797: 798: 799:
800: function conFetchCategoryTree($client = false, $lang = false) {
801: if ($client === false) {
802: $client = $GLOBALS['client'];
803: }
804: if ($lang === false) {
805: $lang = $GLOBALS['lang'];
806: }
807:
808: $oCatTreeColl = new cApiCategoryTreeCollection();
809: $aCatTree = $oCatTreeColl->getCategoryTreeStructureByClientIdAndLanguageId($client, $lang);
810:
811: return $aCatTree;
812: }
813:
814: 815: 816: 817: 818: 819:
820: function conDeeperCategoriesArray($idcat) {
821: global $client;
822:
823: $oCatColl = new cApiCategoryCollection();
824: $aCatIds = $oCatColl->getAllCategoryIdsRecursive($idcat, $client);
825:
826: return $aCatIds;
827: }
828:
829: 830: 831: 832: 833: 834: 835: 836: 837: 838: 839: 840: 841: 842: 843:
844: function conCreateLocationString($idcat, $seperator, &$catStr, $makeLink = false, $linkClass = '', $firstTreeElementToUse = 0, $uselang = 0, $final = true, $usecache = false) {
845: global $cfg, $client, $cfgClient, $lang, $sess;
846:
847: if ($idcat == 0) {
848: $catStr = i18n("Lost and found");
849: return;
850: }
851:
852: if ($uselang == 0) {
853: $uselang = $lang;
854: }
855:
856: $locationStringCache = cRegistry::getAppVar('locationStringCache');
857: $locationStringCacheFile = $cfgClient[$client]['cache']['path'] . "locationstring-cache-$uselang.txt";
858:
859: if ($final == true && $usecache == true) {
860: if (!is_array($locationStringCache)) {
861: if (cFileHandler::exists($locationStringCacheFile)) {
862: $locationStringCache = unserialize(cFileHandler::read($locationStringCacheFile));
863: } else {
864: $locationStringCache = array();
865: }
866: cRegistry::setAppVar('locationStringCache', $locationStringCache);
867: }
868:
869: if (array_key_exists($idcat, $locationStringCache)) {
870: if ($locationStringCache[$idcat]['expires'] > time()) {
871: $catStr = $locationStringCache[$idcat]['name'];
872: return;
873: }
874: }
875: }
876:
877: $db = cRegistry::getDb();
878:
879: $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";
880:
881: $sql = $db->prepare($sql, array(
882: 'cat_lang' => $cfg['tab']['cat_lang'],
883: 'cat' => $cfg['tab']['cat'],
884: 'cat_tree' => $cfg['tab']['cat_tree'],
885: 'idlang' => (int) $uselang,
886: 'idclient' => (int) $client,
887: 'idcat' => (int) $idcat
888: ));
889: $db->query($sql);
890: $db->nextRecord();
891:
892: if ($db->f('level') >= $firstTreeElementToUse) {
893: $name = $db->f('name');
894: $parentid = $db->f('parentid');
895:
896:
897: if ($makeLink == true) {
898: $linkUrl = $sess->url("front_content.php?idcat=$idcat");
899: $name = '<a href="' . $linkUrl . '" class="' . $linkClass . '">' . $name . '</a>';
900: }
901:
902: $tmp_cat_str = $name . $seperator . $catStr;
903: $catStr = $tmp_cat_str;
904: }
905:
906: if ($parentid != 0) {
907: conCreateLocationString($parentid, $seperator, $catStr, $makeLink, $linkClass, $firstTreeElementToUse, $uselang, false);
908: } else {
909: $sep_length = strlen($seperator);
910: $str_length = strlen($catStr);
911: $tmp_length = $str_length - $sep_length;
912: $catStr = substr($catStr, 0, $tmp_length);
913: }
914:
915: if ($final == true && $usecache == true) {
916: $locationStringCache[$idcat]['name'] = $catStr;
917: $locationStringCache[$idcat]['expires'] = time() + 3600;
918:
919: if (is_writable($cfgClient[$client]['cache']['path'])) {
920: cFileHandler::write($locationStringCacheFile, serialize($locationStringCache));
921: }
922: cRegistry::setAppVar('locationStringCache', $locationStringCache);
923: }
924: }
925:
926: 927: 928: 929: 930: 931: 932: 933:
934: function conMakeStart($idcatart, $isstart) {
935: global $lang;
936:
937:
938: $oCatArt = new cApiCategoryArticle((int) $idcatart);
939: if (!$oCatArt->isLoaded()) {
940: return;
941: }
942: $idart = $oCatArt->get('idart');
943: $idcat = $oCatArt->get('idcat');
944:
945:
946: $oArtLang = new cApiArticleLanguage();
947: if (!$oArtLang->loadByArticleAndLanguageId($idart, $lang)) {
948: return;
949: }
950: $idartlang = $oArtLang->get('idartlang');
951:
952:
953: $oCatLang = new cApiCategoryLanguage();
954: if ($oCatLang->loadByCategoryIdAndLanguageId($idcat, $lang)) {
955: if ($isstart == 1) {
956: $oCatLang->set('startidartlang', $idartlang);
957: } else {
958: $oCatLang->set('startidartlang', 0);
959: }
960: $oCatLang->store();
961: }
962:
963: if ($isstart == 1) {
964:
965: $oArtLang->set('timemgmt', 0);
966: $oArtLang->store();
967: }
968: }
969:
970: 971: 972: 973: 974:
975: function conGenerateCodeForArtInAllCategories($idart) {
976: $oCatArtColl = new cApiCategoryArticleCollection();
977: $ids = $oCatArtColl->getIdsByWhereClause('idart = ' . (int) $idart);
978: conSetCodeFlagBulkEditing($ids);
979: }
980:
981: 982: 983: 984: 985:
986: function conGenerateCodeForAllArtsInCategory($idcat) {
987: $oCatArtColl = new cApiCategoryArticleCollection();
988: $ids = $oCatArtColl->getIdsByWhereClause('idcat = ' . (int) $idcat);
989: conSetCodeFlagBulkEditing($ids);
990: }
991:
992: 993: 994:
995: function conGenerateCodeForClient() {
996: global $client;
997: $oCatArtColl = new cApiCategoryArticleCollection();
998: $ids = $oCatArtColl->getAllIdsByClientId($client);
999: conSetCodeFlagBulkEditing($ids);
1000: }
1001:
1002: 1003: 1004: 1005: 1006:
1007: function conGenerateCodeForAllartsUsingLayout($idlay) {
1008: global $cfg;
1009:
1010: $db = cRegistry::getDb();
1011:
1012: $sql = "SELECT idtpl FROM " . $cfg["tab"]["tpl"] . " WHERE idlay='" . cSecurity::toInteger($idlay) . "'";
1013: $db->query($sql);
1014: while ($db->nextRecord()) {
1015: conGenerateCodeForAllartsUsingTemplate($db->f("idtpl"));
1016: }
1017: }
1018:
1019: 1020: 1021: 1022: 1023:
1024: function conGenerateCodeForAllartsUsingMod($idmod) {
1025: $oContainerColl = new cApiContainerCollection();
1026: $rsList = $oContainerColl->getFieldsByWhereClause(array(
1027: 'idtpl'
1028: ), 'idmod = ' . (int) $idmod);
1029: foreach ($rsList as $rs) {
1030: conGenerateCodeForAllArtsUsingTemplate($rs['idtpl']);
1031: }
1032: }
1033:
1034: 1035: 1036: 1037: 1038:
1039: function conGenerateCodeForAllArtsUsingTemplate($idtpl) {
1040: global $cfg, $client;
1041:
1042: $db = cRegistry::getDb();
1043:
1044: $oCatArtColl = new cApiCategoryArticleCollection();
1045:
1046:
1047: $sql = "SELECT
1048: b.idcat
1049: FROM
1050: " . $cfg['tab']['tpl_conf'] . " AS a,
1051: " . $cfg['tab']['cat_lang'] . " AS b,
1052: " . $cfg['tab']['cat'] . " AS c
1053: WHERE
1054: a.idtpl = " . cSecurity::toInteger($idtpl) . " AND
1055: b.idtplcfg = a.idtplcfg AND
1056: c.idclient = " . cSecurity::toInteger($client) . " AND
1057: b.idcat = c.idcat";
1058:
1059: $db->query($sql);
1060:
1061: while ($db->nextRecord()) {
1062: $oCatArtColl->resetQuery();
1063: $ids = $oCatArtColl->getIdsByWhereClause('idcat = ' . cSecurity::toInteger($db->f('idcat')));
1064: foreach ($ids as $id) {
1065: conSetCodeFlag($id);
1066: }
1067: }
1068:
1069:
1070: $sql = "SELECT
1071: b.idart
1072: FROM
1073: " . $cfg['tab']['tpl_conf'] . " AS a,
1074: " . $cfg['tab']['art_lang'] . " AS b,
1075: " . $cfg['tab']['art'] . " AS c
1076: WHERE
1077: a.idtpl = " . cSecurity::toInteger($idtpl) . " AND
1078: b.idtplcfg = a.idtplcfg AND
1079: c.idclient = " . cSecurity::toInteger($client) . " AND
1080: b.idart = c.idart";
1081:
1082: $db->query($sql);
1083:
1084: while ($db->nextRecord()) {
1085: $oCatArtColl->resetQuery();
1086: $ids = $oCatArtColl->getIdsByWhereClause('idart = ' . (int) $db->f('idart'));
1087: foreach ($ids as $id) {
1088: conSetCodeFlag($id);
1089: }
1090: }
1091: }
1092:
1093: 1094: 1095:
1096: function conGenerateCodeForAllArts() {
1097: global $cfg;
1098:
1099: $db = cRegistry::getDb();
1100:
1101: $sql = "SELECT idcatart FROM " . $cfg['tab']['cat_art'];
1102: $db->query($sql);
1103: while ($db->nextRecord()) {
1104: conSetCodeFlag($db->f("idcatart"));
1105: }
1106: }
1107:
1108: 1109: 1110: 1111: 1112:
1113: function conSetCodeFlag($idcatart) {
1114: global $client, $cfgClient;
1115:
1116:
1117: $oCatArtColl = new cApiCategoryArticleCollection();
1118: $oCatArtColl->setCreateCodeFlag($idcatart);
1119:
1120:
1121: if (cFileHandler::exists($cfgClient[$client]['code']['path'])) {
1122: 1123: 1124:
1125: foreach (new DirectoryIterator($cfgClient[$client]['code']['path']) as $file) {
1126: if ($file->isFile() === false) {
1127: continue;
1128: }
1129:
1130: $extension = substr($file, strrpos($file->getBasename(), '.') + 1);
1131: if ($extension != 'php') {
1132: continue;
1133: }
1134:
1135: if (preg_match('/[0-9*].[0-9*].' . $idcatart . '/s', $file->getBasename())) {
1136: cFileHandler::remove($cfgClient[$client]['code']['path'] . '/' . $file->getFilename());
1137: }
1138: }
1139: }
1140: }
1141:
1142: 1143: 1144: 1145: 1146:
1147: function conSetCodeFlagBulkEditing(array $idcatarts) {
1148: global $client, $cfgClient;
1149:
1150: if (count($idcatarts) == 0) {
1151: return;
1152: }
1153:
1154:
1155: $oCatArtColl = new cApiCategoryArticleCollection();
1156: $oCatArtColl->setCreateCodeFlag($idcatarts);
1157:
1158: if (cFileHandler::exists($cfgClient[$client]['code']['path']) === false) {
1159: return;
1160: }
1161:
1162:
1163: foreach ($idcatarts as $id) {
1164: 1165: 1166:
1167: foreach (new DirectoryIterator($cfgClient[$client]['code']['path']) as $file) {
1168: if ($file->isFile() === false) {
1169: continue;
1170: }
1171:
1172: $extension = substr($file, strrpos($file->getBasename(), '.') + 1);
1173: if ($extension != 'php') {
1174: continue;
1175: }
1176:
1177: if (preg_match('/[0-9*].[0-9*].' . $id . '/s', $file->getBasename())) {
1178: cFileHandler::remove($cfgClient[$client]['code']['path'] . '/' . $file->getFilename());
1179: }
1180: }
1181: }
1182: }
1183:
1184: 1185: 1186:
1187: function conFlagOnOffline() {
1188: global $cfg;
1189:
1190: $db = cRegistry::getDb();
1191:
1192: $oArtLangColl = new cApiArticleLanguageCollection();
1193:
1194:
1195: $where = "NOW() < datestart AND datestart != '0000-00-00 00:00:00' AND datestart IS NOT NULL AND timemgmt = 1";
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: $where = "NOW() > datestart AND (NOW() < dateend OR dateend = '0000-00-00 00:00:00') AND " . "online = 0 AND timemgmt = 1";
1204: $oArtLangColl->resetQuery();
1205: $ids = $oArtLangColl->getIdsByWhereClause($where);
1206: foreach ($ids as $id) {
1207: $sql = "UPDATE " . $cfg['tab']['art_lang'] . " SET online = 1, published = datestart WHERE idartlang = " . (int) $id;
1208: $db->query($sql);
1209: }
1210:
1211:
1212: $where = "NOW() > dateend AND dateend != '0000-00-00 00:00:00' AND timemgmt = 1";
1213: $oArtLangColl->resetQuery();
1214: $ids = $oArtLangColl->getIdsByWhereClause($where);
1215: foreach ($ids as $id) {
1216: $sql = "UPDATE " . $cfg['tab']['art_lang'] . " SET online = 0 WHERE idartlang = " . (int) $id;
1217: $db->query($sql);
1218: }
1219: }
1220:
1221: 1222: 1223:
1224: function conMoveArticles() {
1225: global $cfg;
1226:
1227: $db = cRegistry::getDb();
1228:
1229:
1230: $fields = array(
1231: 'idartlang',
1232: 'idart',
1233: 'time_move_cat',
1234: 'time_target_cat',
1235: 'time_online_move'
1236: );
1237: $where = "NOW() > dateend AND dateend != '0000-00-00 00:00:00' AND timemgmt = 1 AND time_move_cat = 1";
1238: $oArtLangColl = new cApiArticleLanguageCollection();
1239: $rsList = $oArtLangColl->getFieldsByWhereClause($fields, $where);
1240:
1241: foreach ($rsList as $rs) {
1242: $online = ($rs['time_online_move'] == '1')? 1 : 0;
1243: $sql = array();
1244: $sql[] = 'UPDATE ' . $cfg['tab']['art_lang'] . ' SET timemgmt = 0, online = 0 WHERE idartlang = ' . (int) $rs['idartlang'] . ';';
1245: $sql[] = 'UPDATE ' . $cfg['tab']['cat_art'] . ' SET idcat = ' . (int) $rs['time_target_cat'] . ', createcode = 1 WHERE idart = ' . (int) $rs['idart'] . ';';
1246: $sql[] = 'UPDATE ' . $cfg['tab']['art_lang'] . ' SET online = ' . (int) $online . ' WHERE idart = ' . (int) $rs['idart'] . ';';
1247:
1248: $sql = implode("\n", $sql);
1249: $db->query($sql);
1250:
1251:
1252: cApiCecHook::execute('Contenido.Article.conMoveArticles_Loop', $rs);
1253: }
1254: }
1255:
1256: 1257: 1258: 1259: 1260:
1261: function conCopyTemplateConfiguration($srcidtplcfg) {
1262: $oTemplateConf = new cApiTemplateConfiguration((int) $srcidtplcfg);
1263: if (!$oTemplateConf->isLoaded()) {
1264: return NULL;
1265: }
1266:
1267: $oTemplateConfColl = new cApiTemplateConfigurationCollection();
1268: $oNewTemplateConf = $oTemplateConfColl->create($oTemplateConf->get('idtpl'));
1269: return (is_object($oNewTemplateConf))? $oNewTemplateConf->get('idtplcfg') : NULL;
1270: }
1271:
1272: 1273: 1274: 1275: 1276: 1277: 1278:
1279: function conCopyContainerConf($srcidtplcfg, $dstidtplcfg) {
1280: $counter = 0;
1281: $oContainerConfColl = new cApiContainerConfigurationCollection();
1282: $oContainerConfColl->select('idtplcfg = ' . cSecurity::toInteger($srcidtplcfg));
1283: while (($oContainerConf = $oContainerConfColl->next()) !== false) {
1284: $oNewContainerConfColl = new cApiContainerConfigurationCollection();
1285: $oNewContainerConfColl->copyItem($oContainerConf, array(
1286: 'idtplcfg' => cSecurity::toInteger($dstidtplcfg)
1287: ));
1288: $counter++;
1289: }
1290: return ($counter > 0)? true : false;
1291: }
1292:
1293: 1294: 1295: 1296: 1297: 1298: 1299:
1300: function conCopyContent($srcidartlang, $dstidartlang) {
1301: $oContentColl = new cApiContentCollection();
1302: $oContentColl->select('idartlang = ' . cSecurity::toInteger($srcidartlang));
1303: while (($oContent = $oContentColl->next()) !== false) {
1304: $oNewContentColl = new cApiContentCollection();
1305: $oNewContentColl->copyItem($oContent, array(
1306: 'idartlang' => cSecurity::toInteger($dstidartlang)
1307: ));
1308: }
1309: }
1310:
1311: 1312: 1313: 1314: 1315: 1316: 1317:
1318: function conCopyMetaTags($srcidartlang, $dstidartlang) {
1319: $oMetaTagColl = new cApiMetaTagCollection();
1320: $oMetaTagColl->select('idartlang = ' . cSecurity::toInteger($srcidartlang));
1321: while (($oMetaTag = $oMetaTagColl->next()) !== false) {
1322: $oNewMetaTagColl = new cApiMetaTagCollection();
1323: $oNewMetaTagColl->copyItem($oMetaTag, array(
1324: 'idartlang' => cSecurity::toInteger($dstidartlang)
1325: ));
1326: }
1327: }
1328:
1329: 1330: 1331: 1332: 1333: 1334: 1335: 1336: 1337: 1338:
1339: function conCopyArtLang($srcidart, $dstidart, $newtitle, $useCopyLabel = true) {
1340: global $auth, $lang;
1341:
1342: $oSrcArtLang = new cApiArticleLanguage();
1343: if (!$oSrcArtLang->loadByArticleAndLanguageId($srcidart, $lang)) {
1344: return;
1345: }
1346:
1347:
1348: if ($oSrcArtLang->get('idtplcfg') != 0) {
1349: $newidtplcfg = conCopyTemplateConfiguration($oSrcArtLang->get('idtplcfg'));
1350: conCopyContainerConf($oSrcArtLang->get('idtplcfg'), $newidtplcfg);
1351: }
1352:
1353: $idart = $dstidart;
1354: $idlang = $oSrcArtLang->get('idlang');
1355: $idtplcfg = $newidtplcfg;
1356:
1357: if ($newtitle != '') {
1358: $title = sprintf($newtitle, $oSrcArtLang->get('title'));
1359: } else if ($useCopyLabel == true) {
1360: $title = sprintf(i18n('%s (Copy)'), $oSrcArtLang->get('title'));
1361: } else {
1362: $title = $oSrcArtLang->get('title');
1363: }
1364:
1365:
1366: $oArtLangColl = new cApiArticleLanguageCollection();
1367: $fieldsToOverwrite = array(
1368: 'idart' => $idart,
1369: 'idlang' => $idlang,
1370: 'idtplcfg' => cSecurity::toInteger($idtplcfg),
1371: 'online' => 0,
1372: 'title' => $title,
1373: 'created' => date('Y-m-d H:i:s'),
1374: 'lastmodified' => date('Y-m-d H:i:s'),
1375: 'modifiedby' => $auth->auth['uname'],
1376: 'published' => '',
1377: 'publishedby' => ''
1378: );
1379: $oNewArtLang = $oArtLangColl->copyItem($oSrcArtLang, $fieldsToOverwrite);
1380:
1381: if (!is_object($oNewArtLang)) {
1382: return;
1383: }
1384:
1385:
1386: conCopyContent($oSrcArtLang->get('idartlang'), $oNewArtLang->get('idartlang'));
1387:
1388:
1389: conCopyMetaTags($oSrcArtLang->get('idartlang'), $oNewArtLang->get('idartlang'));
1390:
1391:
1392: cApiCecHook::execute('Contenido.Article.conCopyArtLang_AfterInsert', array(
1393: 'idartlang' => cSecurity::toInteger($oNewArtLang->get('idartlang')),
1394: 'idart' => cSecurity::toInteger($idart),
1395: 'idlang' => cSecurity::toInteger($idlang),
1396: 'idtplcfg' => cSecurity::toInteger($idtplcfg),
1397: 'title' => $title
1398: ));
1399:
1400:
1401: conMakeArticleIndex($oNewArtLang->get('idartlang'), $idart);
1402: }
1403:
1404: 1405: 1406: 1407: 1408: 1409: 1410: 1411: 1412: 1413:
1414: function conCopyArticle($srcidart, $targetcat = 0, $newtitle = '', $useCopyLabel = true) {
1415:
1416: $oSrcArt = new cApiArticle((int) $srcidart);
1417: if (!$oSrcArt->isLoaded()) {
1418: return false;
1419: }
1420: $idclient = $oSrcArt->get('idclient');
1421:
1422:
1423: $oArtCollection = new cApiArticleCollection();
1424: $oNewArt = $oArtCollection->create($idclient);
1425: if (!is_object($oNewArt)) {
1426: return false;
1427: }
1428: $dstidart = $oNewArt->get('idart');
1429:
1430: conCopyArtLang($srcidart, $dstidart, $newtitle, $useCopyLabel);
1431:
1432:
1433: $oCatArtColl = new cApiCategoryArticleCollection();
1434: $oCatArtColl->select('idart = ' . (int) $srcidart);
1435: while (($oCatArt = $oCatArtColl->next()) !== false) {
1436:
1437: $oCatArtColl2 = new cApiCategoryArticleCollection();
1438: $fieldsToOverwrite = array(
1439: 'idcat' => ($targetcat != 0)? $targetcat : $oCatArt->get('idcat'),
1440: 'idart' => $dstidart,
1441: 'status' => ($oCatArt->get('status') !== '')? $oCatArt->get('status') : 0,
1442: 'createcode' => 1,
1443: 'is_start' => 0
1444: );
1445: $oCatArtColl2->copyItem($oCatArt, $fieldsToOverwrite);
1446:
1447:
1448: if ($targetcat != 0) {
1449: break;
1450: }
1451: }
1452:
1453:
1454:
1455: $_cecRegistry = cApiCecRegistry::getInstance();
1456: $iterator = $_cecRegistry->getIterator('Contenido.Content.CopyArticle');
1457: while (($chainEntry = $iterator->next()) !== false) {
1458: $chainEntry->execute($srcidart, $dstidart);
1459: }
1460:
1461: return $dstidart;
1462: }
1463:
1464: 1465: 1466: 1467: 1468: 1469: 1470: 1471: 1472: 1473:
1474: function conGetTopmostCat($idcat, $minLevel = 0) {
1475: global $cfg, $client, $lang;
1476:
1477: $db = cRegistry::getDb();
1478:
1479: $sql = "SELECT a.name AS name, a.idcat AS idcat, b.parentid AS parentid, c.level AS level
1480: FROM `:cat_lang` AS a, `:cat` AS b, `:cat_tree` AS c
1481: WHERE a.idlang = :idlang AND b.idclient = :idclient AND b.idcat = :idcat
1482: AND c.idcat = b.idcat AND a.idcat = b.idcat";
1483:
1484: $sql = $db->prepare($sql, array(
1485: 'cat_lang' => $cfg['tab']['cat_lang'],
1486: 'cat' => $cfg['tab']['cat'],
1487: 'cat_tree' => $cfg['tab']['cat_tree'],
1488: 'idlang' => (int) $lang,
1489: 'idclient' => (int) $client,
1490: 'idcat' => (int) $idcat
1491: ));
1492: $db->query($sql);
1493: $db->nextRecord();
1494:
1495: $name = $db->f('name');
1496: $parentid = $db->f('parentid');
1497: $thislevel = $db->f('level');
1498:
1499: if ($parentid != 0 && $thislevel >= $minLevel) {
1500: return conGetTopmostCat($parentid, $minLevel);
1501: } else {
1502: return $idcat;
1503: }
1504: }
1505:
1506: 1507: 1508: 1509: 1510: 1511: 1512:
1513: function conSyncArticle($idart, $srclang, $dstlang) {
1514: $auth = cRegistry::getAuth();
1515:
1516:
1517: $dstArtLang = new cApiArticleLanguage();
1518: $dstArtLang->loadByArticleAndLanguageId($idart, $dstlang);
1519: if ($dstArtLang->isLoaded()) {
1520:
1521: return;
1522: }
1523:
1524: $srcArtLang = new cApiArticleLanguage();
1525: $srcArtLang->loadByArticleAndLanguageId($idart, $srclang);
1526: if (!$srcArtLang->isLoaded()) {
1527:
1528: return;
1529: }
1530: $srcidartlang = $srcArtLang->get('idartlang');
1531:
1532: if ($srcArtLang->get('idtplcfg') != 0) {
1533: $newidtplcfg = tplcfgDuplicate($srcArtLang->get('idtplcfg'));
1534: } else {
1535: $newidtplcfg = 0;
1536: }
1537:
1538:
1539: $artLangColl = new cApiArticleLanguageCollection();
1540: $fieldsToOverwrite = array(
1541: 'idart' => $idart,
1542: 'idlang' => $dstlang,
1543: 'artspec' => 0,
1544: 'online' => 0,
1545: 'created' => date('Y-m-d H:i:s'),
1546: 'lastmodified' => date('Y-m-d H:i:s'),
1547: 'modifiedby' => $auth->auth['uname'],
1548: 'published' => '',
1549: 'publishedby' => '',
1550: 'timemgmt' => 0,
1551: 'datestart' => '',
1552: 'dateend' => '',
1553: 'status' => 0,
1554: 'time_move_cat' => 0,
1555: 'time_target_cat' => 0,
1556: 'time_online_move' => 0,
1557: 'free_use_01' => '',
1558: 'free_use_02' => '',
1559: 'free_use_03' => ''
1560: );
1561: $artLang = $artLangColl->copyItem($srcArtLang, $fieldsToOverwrite);
1562: if (!is_object($artLang)) {
1563: return;
1564: }
1565:
1566: $newidartlang = $artLang->get('idartlang');
1567:
1568:
1569: $param = array();
1570: $param['src_art_lang'] = $srcArtLang->toArray();
1571: $param['dest_art_lang'] = $dstArtLang->toArray();
1572: $param['dest_art_lang']['idartlang'] = cSecurity::toInteger($newidartlang);
1573: $param['dest_art_lang']['idlang'] = cSecurity::toInteger($dstlang);
1574: $param['dest_art_lang']['idtplcfg'] = cSecurity::toInteger($newidtplcfg);
1575: cApiCecHook::execute('Contenido.Article.conSyncArticle_AfterInsert', $param);
1576:
1577:
1578: conCopyContent($srcidartlang, $newidartlang);
1579:
1580:
1581: conCopyMetaTags($srcidartlang, $newidartlang);
1582: }
1583:
1584: 1585: 1586: 1587: 1588: 1589: 1590: 1591: 1592:
1593: function isStartArticle($idartlang, $idcat, $idlang, $db = NULL) {
1594: $oCatLangColl = new cApiCategoryLanguageCollection();
1595: return $oCatLangColl->isStartArticle($idartlang, $idcat, $idlang);
1596: }
1597:
1598: 1599: 1600: 1601: 1602: 1603: 1604:
1605: function conGetCategoryAssignments($idart, $db = NULL) {
1606: $categories = array();
1607: $oCatArtColl = new cApiCategoryArticleCollection();
1608: $entries = $oCatArtColl->getFieldsByWhereClause(array(
1609: 'idcat'
1610: ), 'idart = ' . (int) $idart);
1611: foreach ($entries as $entry) {
1612: $categories[] = $entry['idcat'];
1613: }
1614: return $categories;
1615: }
1616:
1617: 1618: 1619: 1620: 1621: 1622: 1623: 1624: 1625: 1626: 1627:
1628: function conRemoveOldCategoryArticle($idcat, $idart, $idartlang, $client, $lang) {
1629: global $cfgClient;
1630:
1631:
1632: $oCatArtColl = new cApiCategoryArticleCollection();
1633: $oCatArt = $oCatArtColl->fetchByCategoryIdAndArticleId($idcat, $idart);
1634: if (!is_object($oCatArt)) {
1635: return;
1636: }
1637:
1638: $idcatart = $oCatArt->get('idcatart');
1639:
1640:
1641: 1642: 1643:
1644: foreach (new DirectoryIterator($cfgClient[$client]['code']['path']) as $file) {
1645: if ($file->isFile() === false) {
1646: continue;
1647: }
1648:
1649: $extension = substr($file, strrpos($file->getBasename(), '.') + 1);
1650: if ($extension != 'php') {
1651: continue;
1652: }
1653:
1654: if (preg_match('/[0-9*].[0-9*].' . $idcatart . '/s', $file->getBasename())) {
1655: cFileHandler::remove($cfgClient[$client]['code']['path'] . '/' . $file->getFilename());
1656: }
1657: }
1658:
1659:
1660: $oStatColl = new cApiStatCollection();
1661: $oStatColl->deleteByCategoryArticleAndLanguage($idcatart, $lang);
1662:
1663:
1664: $oCatArtColl->delete($idcatart);
1665:
1666:
1667: if (isStartArticle($idartlang, $idcat, $lang)) {
1668: $oCatLang = new cApiCategoryLanguage();
1669: $oCatLang->loadByCategoryIdAndLanguageId($idcat, $lang);
1670: if ($oCatLang->isLoaded()) {
1671: $oCatLang->set('startidartlang', 0);
1672: $oCatLang->store();
1673: }
1674: }
1675:
1676:
1677: $oArtLang = new cApiArticleLanguage();
1678: $oArtLang->loadByArticleAndLanguageId($idart, $lang);
1679: if ($oArtLang->isLoaded() && $oArtLang->get('idtplcfg') > 0) {
1680: $oTplCfgColl = new cApiTemplateConfigurationCollection();
1681: $oTplCfgColl->delete($oArtLang->get('idtplcfg'));
1682: }
1683: }
1684:
1685: ?>