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