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