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