Overview

Packages

  • CONTENIDO
  • Core
    • Authentication
    • Backend
    • Cache
    • CEC
    • Chain
    • ContentType
    • Database
    • Debug
    • Exception
    • Frontend
      • Search
      • URI
      • Util
    • GenericDB
      • Model
    • GUI
      • HTML
    • I18N
    • LayoutHandler
    • Log
    • Security
    • Session
    • Util
    • Validation
    • Versioning
    • XML
  • Module
    • ContentRssCreator
    • ContentSitemapHtml
    • ContentSitemapXml
    • ContentUserForum
    • NavigationTop
    • ScriptCookieDirective
  • mpAutoloaderClassMap
  • None
  • Plugin
    • ContentAllocation
    • CronjobOverview
    • FormAssistant
    • FrontendLogic
    • FrontendUsers
    • Linkchecker
    • ModRewrite
    • Newsletter
    • Repository
      • FrontendNavigation
      • KeywordDensity
    • SearchSolr
    • SmartyWrapper
    • UrlShortener
    • UserForum
    • Workflow
  • PluginManager
  • Setup
    • Form
    • GUI
    • Helper
      • Environment
      • Filesystem
      • MySQL
      • PHP
    • UpgradeJob

Classes

  • cContentVersioning
  • cVersion
  • cVersionFile
  • cVersionLayout
  • cVersionModule
  • Overview
  • Package
  • Class
  • Tree
  • Deprecated
  • Todo
  1: <?php
  2: 
  3: /**
  4:  * This file contains the versioning class.
  5:  *
  6:  * @package Core
  7:  * @subpackage Versioning
  8:  * @version
  9:  *
 10:  * @author Jann Dieckmann
 11:  * @copyright four for business AG <www.4fb.de>
 12:  * @license http://www.contenido.org/license/LIZENZ.txt
 13:  * @link http://www.4fb.de
 14:  * @link http://www.contenido.org
 15:  */
 16: 
 17: defined('CON_FRAMEWORK') || die('Illegal call: Missing framework initialization - request aborted.');
 18: 
 19: /**
 20:  * Versioning.
 21:  *
 22:  * @package Core
 23:  * @subpackage Versioning
 24:  */
 25: class cContentVersioning {
 26: 
 27:     /**
 28:      * db instance
 29:      *
 30:      * @var cDb
 31:      */
 32:     protected $db;
 33: 
 34:     /**
 35:      * article type (current, version, editable)
 36:      *
 37:      * @var string
 38:      */
 39:     protected $articleType;
 40: 
 41:     /**
 42:      * selected article language (version)
 43:      *
 44:      * @var cApiArticleLanguageVersion or cApiArticleLanguage
 45:      */
 46:     public $selectedArticle;
 47: 
 48:     /**
 49:      * editable article language version id
 50:      *
 51:      * @var int
 52:      */
 53:     public $editableArticleId;
 54: 
 55:     /**
 56:      * Constructor to create an instance of this class.
 57:      */
 58:     public function __construct() {
 59:         $this->db = cRegistry::getDb();
 60:     }
 61: 
 62:     /**
 63:      * Cms type sort function for article output.
 64:      *
 65:      * @SuppressWarnings docBlocks
 66:      * @param array $result[cms type][typeId] = value
 67:      * @return array $result[cms type][typeId] = value
 68:      */
 69:     public function sortResults(array $result) {
 70: 
 71:         uksort($result, function($a, $b) {
 72: 
 73:             // cms type sort sequence
 74:             $cmsType = array(
 75:                 "CMS_HTMLHEAD",
 76:                 "CMS_HEAD",
 77:                 "CMS_HTML",
 78:                 "CMS_TEXT",
 79:                 "CMS_IMG",
 80:                 "CMS_IMGDESCR",
 81:                 "CMS_IMGEDITOR",
 82:                 "CMS_LINK",
 83:                 "CMS_LINKTARGET",
 84:                 "CMS_LINKDESCR",
 85:                 "CMS_LINKEDITOR",
 86:                 "CMS_DATE",
 87:                 "CMS_TEASER",
 88:                 "CMS_FILELIST",
 89:                 "CMS_RAW"
 90:             );
 91: 
 92:             return array_search($a, $cmsType) - array_search($b, $cmsType);
 93: 
 94:         });
 95: 
 96:         return $result;
 97: 
 98:     }
 99: 
100:     /**
101:      * Return date for select box.
102:      * If current time - lastModified < 1 hour return "%d minutes ago"
103:      * else return "Y-M-D H:I:S".
104:      *
105:      * @param string $lastModified
106:      * @return string
107:      */
108:     public function getTimeDiff($lastModified) {
109:         $currentTime = new DateTime(date('Y-m-d H:i:s'));
110:         $modifiedTime = new DateTime($lastModified);
111:         $diff = $currentTime->diff($modifiedTime);
112:         $diff2 = (int) $diff->format('%Y%M%D%H');
113: 
114:         if ($diff2 === 0) {
115:             return sprintf(i18n("%d minutes ago"), $diff->format('%i'));
116:         } else {
117:             return date('d.m.Y, H:i\h', strtotime($lastModified));
118:         }
119: 
120:     }
121: 
122:     /**
123:      * Returns the current versioning state (disabled (default), simple, advanced).
124:      *
125:      * @return string $versioningState
126:      */
127:     public static function getState() {
128: 
129:         static $versioningState;
130: 
131:         if (!isset($versioningState)) {
132: 
133:             // versioning enabled is a tri-state => disabled (default), simple, advanced
134:             $systemPropColl = new cApiSystemPropertyCollection();
135:             $prop = $systemPropColl->fetchByTypeName('versioning', 'enabled');
136:             $versioningState = $prop ? $prop->get('value') : false;
137: 
138:             if (false === $versioningState || NULL === $versioningState) {
139:                 $versioningState = 'disabled';
140:             } else if ('' === $versioningState) {
141:                 // NOTE: An non empty default value overrides an empty value
142:                 $versioningState = 'disabled';
143:             }
144: 
145:         }
146: 
147:         return $versioningState;
148: 
149:     }
150: 
151:     /**
152:      * Returns selected article.
153:      *
154:      * @todo $idArtlangVersion <-> $selectedArticleId
155:      * @param int $idArtLangVersion
156:      * @param int $idArtLang
157:      * @param string $articleType
158:      * @param int $selectedArticleId [optional]
159:      * @return cApiArticleLanguage|cApiArticleLanguageVersion $this->selectedArticle
160:      */
161:     public function getSelectedArticle($idArtLangVersion, $idArtLang, $articleType, $selectedArticleId = NULL) {
162: 
163:         $this->editableArticleId = $this->getEditableArticleId($idArtLang);
164:         $versioningState = $this->getState();
165:         $this->selectedArticle = NULL;
166:         if (is_numeric($selectedArticleId)) {
167:             $idArtLangVersion = $selectedArticleId;
168:         }
169: 
170:         if (($articleType == 'version' || $articleType == 'editable') && ($versioningState == 'advanced')
171:         || ($articleType == 'version' && $versioningState == 'simple')) {
172:             if (is_numeric($idArtLangVersion) && $articleType == 'version') {
173:                 $this->selectedArticle = new cApiArticleLanguageVersion($idArtLangVersion);
174:             } else if (isset($this->editableArticleId)) {
175:                 $this->selectedArticle = new cApiArticleLanguageVersion($this->editableArticleId);
176:             }
177:         } else if ($articleType == 'current' || $articleType == 'editable') {
178:             $this->selectedArticle = new cApiArticleLanguage($idArtLang);
179:         }
180: 
181:         return $this->selectedArticle;
182: 
183:     }
184: 
185:     /**
186:      * Returns $list[1] = CMS_HTMLHEAD for every content existing
187:      * in article/version with $idArtLang.
188:      *
189:      * @param int $idArtLang
190:      * @param string $articleType
191:      * @return array $list
192:      */
193:     public function getList($idArtLang, $articleType) {
194: 
195:         $sql = 'SELECT DISTINCT b.idtype as idtype, b.type as name
196:                 FROM %s AS a, %s AS b
197:                 WHERE a.idartlang = %d AND a.idtype = b.idtype
198:                 ORDER BY idtype, name';
199: 
200:         if (($articleType == 'version' || $articleType == 'editable') && $this->getState() == 'advanced'
201:                 || $articleType == 'version' && $this->getState() == 'simple') {
202:             $this->db->query($sql, cRegistry::getDbTableName('content_version'), cRegistry::getDbTableName('type'), $idArtLang);
203:         } else if ($articleType == 'current' || $articleType == 'editable' && $this->getState() != 'advanced') {
204:             $this->db->query($sql, cRegistry::getDbTableName('content'), cRegistry::getDbTableName('type'), $idArtLang);
205:         }
206: 
207:         $list = array();
208:         while ($this->db->nextRecord()) {
209:             $list[$this->db->f('idtype')] = $this->db->f('name');
210:         }
211: 
212:         return $list;
213: 
214:     }
215: 
216:     /**
217:      * Return max idcontent.
218:      *
219:      * @return int
220:      */
221:     public function getMaxIdContent() {
222: 
223:         $sql = 'SELECT max(idcontent) AS max FROM %s';
224:         $this->db->query($sql, cRegistry::getDbTableName('content'));
225:         $this->db->nextRecord();
226: 
227:         return $this->db->f('max');
228:     }
229: 
230:     /**
231:      * Returns type of article (current, version or editable).
232:      *
233:      * @param int $idArtLangVersion
234:      * @param int $idArtLang
235:      * @param string $action
236:      * @param mixed $selectedArticleId
237:      * @return string $this->articleType
238:      *
239:      */
240:     public function getArticleType($idArtLangVersion, $idArtLang, $action, $selectedArticleId) {
241: 
242:         $this->editableArticleId = $this->getEditableArticleId($idArtLang);
243: 
244:         if ($this->getState() == 'disabled' // disabled
245:             || ($this->getState() == 'simple' && ($selectedArticleId == 'current'
246:                 || $selectedArticleId == NULL)
247:                 && ($action == 'con_meta_deletetype' || $action == 'copyto'
248:                  || $action == 'con_content' || $idArtLangVersion == NULL
249:                  || $action == 'con_saveart' || $action == 'con_edit' || $action == 'con_meta_edit' || $action == 'con_editart'))
250:             || $idArtLangVersion == 'current' && $action != 'copyto'
251:             || $action == 'copyto' && $idArtLangVersion == $this->editableArticleId
252:             || $action == 'con_meta_change_version' && $idArtLang == 'current'
253:             || $selectedArticleId == 'current' && $action != 'copyto'
254:             || $this->editableArticleId == NULL
255:             && $action != 'con_meta_saveart' && $action != 'con_newart') { // advanced
256:             $this->articleType = 'current';
257:         } else if ($this->getState() == 'advanced' && ($selectedArticleId == 'editable'
258:             || $selectedArticleId == NULL || $this->editableArticleId === $selectedArticleId)
259:             && ($action == 'con_content' || $action == 'con_meta_deletetype'
260:                 || $action == 'con_meta_edit' || $action == 'con_edit' || $action == 'con_editart')
261:             || $action == 'copyto' || $idArtLangVersion == 'current'
262:             || $idArtLangVersion == $this->editableArticleId
263:             || $action == 'importrawcontent' || $action == 'savecontype'
264:             || $action == 'con_editart' && $this->getState() == 'advanced' && $selectedArticleId == 'editable'
265:             || $action == 'con_edit' && $this->getState() == 'advanced' && $selectedArticleId == NULL
266:             || $action == '20' && $idArtLangVersion == NULL
267:             || $action == 'con_meta_saveart' || $action == 'con_saveart'
268:             || $action == 'con_newart' || $action == 'con_meta_change_version'
269:             && $idArtLangVersion == $this->editableArticleId) {
270:             $this->articleType = 'editable';
271:         } else {
272:             $this->articleType = 'version';
273:         }
274: 
275:         return $this->articleType;
276: 
277:     }
278: 
279:     /**
280:      *
281:      * @param string $class
282:      * @param string $selectElement
283:      * @param string $copyToButton
284:      * @param string $infoText
285:      * @return string
286:      */
287:     public function getVersionSelectionField($class, $selectElement, $copyToButton, $infoText) {
288: 
289:         // TODO avoid inline CSS!!!
290:         $versionselection = '
291:             <div class="%s">
292:                 <div>
293:                     <span style="width: 280px; display: inline; padding: 0px 0px 0px 2px;">
294:                         <span style="font-weight:bold;color:black;">' . i18n('Select Article Version') . '</span>
295:                         <span style="margin: 0;"> %s %s
296:                         </span>
297:                         <a
298:                             href="#"
299:                             id="pluginInfoDetails-link"
300:                             class="main i-link infoButton"
301:                             title="">
302:                         </a>
303:                     </span>
304:                 </div>
305:                 <div id="pluginInfoDetails" style="display:none;" class="nodisplay">
306:                        %s
307:                 </div>
308:             </div>';
309: 
310:         return sprintf(
311:             $versionselection,
312:             $class,
313:             $selectElement,
314:             $copyToButton,
315:             $infoText
316:         );
317:     }
318: 
319:     /**
320:      * Returns idartlangversion of editable article.
321:      *
322:      * @param int $idArtLang
323:      * @return int $editableArticleId
324:      */
325:     public function getEditableArticleId($idArtLang) {
326: 
327:         if ($this->getState() == 'advanced') {
328: 
329:             $this->db->query(
330:                 'SELECT
331:                     max(idartlangversion) AS max
332:                 FROM
333:                     %s
334:                 WHERE
335:                     idartlang = %d',
336:                 cRegistry::getDbTableName('art_lang_version'),
337:                 $idArtLang
338:             );
339:             $this->db->nextRecord();
340:             $this->editableArticleId = $this->db->f('max');
341: 
342:             return $this->editableArticleId;
343: 
344:         } else if ($this->getState() == 'simple' || $this->getState() == 'disabled') {
345: 
346:             return $idArtLang;
347: 
348:         }
349: 
350:     }
351: 
352:     /**
353:      * Returns idcontent or idcontentversion.
354:      *
355:      * @todo check datatype of return value
356:      * @param int $idArtLang
357:      * @param int $typeId
358:      * @param int $type
359:      * @param int $versioningState
360:      * @param int $articleType
361:      * @param int $version
362:      * @return array $idContent
363:      */
364:     public function getContentId($idArtLang, $typeId, $type, $versioningState, $articleType, $version) {
365: 
366:         $idContent = array();
367:         $type = addslashes($type);
368: 
369:         if ($versioningState == 'simple' && $articleType != 'version'
370:         || $versioningState == 'advanced' && $articleType == 'current'
371:         || $versioningState == 'disabled') {
372:             $this->db->query("
373:                 SELECT
374:                     a.idcontent
375:                 FROM
376:                     " . cRegistry::getDbTableName('content') . " as a,
377:                     " . cRegistry::getDbTableName('type') . " as b
378:                 WHERE
379:                     a.idartlang=" . $idArtLang . "
380:                     AND a.idtype=b.idtype
381:                     AND a.typeid = " . $typeId . "
382:                     AND b.type = '" . $type . "'
383:                 ORDER BY
384:                     a.idartlang, a.idtype, a.typeid");
385:             while ($this->db->nextRecord()) {
386:                 $idContent = $this->db->f('idcontent');
387:             }
388:         } else {
389:             $this->db->query("
390:                 SELECT
391:                     a.idcontentversion
392:                 FROM
393:                     " . cRegistry::getDbTableName('content_version') . " as a,
394:                     " . cRegistry::getDbTableName('type') . " as b
395:                 WHERE
396:                     a.version <= " . $version . "
397:                     AND a.idartlang = " . $idArtLang . "
398:                     AND a.idtype = b.idtype
399:                     AND a.typeid = " . $typeId . "
400:                     AND b.type = '" . $type . "'
401:                 ORDER BY
402:                     a.version DESC, a.idartlang, a.idtype, a.typeid LIMIT 1");
403:             while ($this->db->nextRecord()) {
404:                 $idContent = $this->db->f('idcontentversion');
405:             }
406:         }
407: 
408:         return $idContent;
409: 
410:     }
411: 
412:     /**
413:      * Returns $artLangVersionMap[version][idartlangversion] = lastmodified
414:      * either from each article-/content- or metatag-version.
415:      *
416:      * @param int $idArtLang
417:      * @param string $selectElementType [optional]
418:      *         either 'content', 'seo' or 'config'
419:      * @return array
420:      */
421:     public function getDataForSelectElement($idArtLang, $selectElementType = '') {
422: 
423:         $artLangVersionMap = array();
424: 
425:         $artLangVersionColl = new cApiArticleLanguageVersionCollection();
426:         $artLangVersionColl->addResultField('version');
427:         $artLangVersionColl->addResultField('lastmodified');
428:         $artLangVersionColl->setWhere('idartlang', $idArtLang);
429:         $artLangVersionColl->setOrder('version desc');
430: 
431:         try {
432: 
433:             if ($selectElementType == 'content') {
434: 
435:                 // select only versions with different content versions
436:                 $contentVersionColl = new cApiContentVersionCollection();
437:                 $contentVersionColl->addResultField('version');
438:                 $contentVersionColl->setWhere('idartlang', $idArtLang);
439:                 $contentVersionColl->query();
440:                 $contentFields['version'] = 'version';
441: 
442:                 // check ...
443:                 if (0 >= $contentVersionColl->count()) {
444:                     throw new cException('no content versions');
445:                 }
446: 
447:                 $table = $contentVersionColl->fetchTable($contentFields);
448: 
449:                 // add ...
450:                 $contentVersionMap = array();
451:                 foreach ($table AS $key => $item) {
452:                     $contentVersionMap[] = $item['version'];
453:                 }
454:                 $contentVersionMap = array_unique($contentVersionMap);
455:                 $artLangVersionColl->setWhere('version', $contentVersionMap, 'IN');
456: 
457:             } else if ($selectElementType == 'seo') {
458: 
459:                 // select only versions with different seo versions
460:                 $metaVersionColl = new cApiMetaTagVersionCollection();
461:                 $metaVersionColl->addResultField('version');
462:                 $metaVersionColl->setWhere('idartlang', $idArtLang);
463:                 $metaVersionColl->query();
464:                 $metaFields['version'] = 'version';
465: 
466:                 // check...
467:                 if (0 >= $metaVersionColl->count()) {
468:                     throw new cException('no meta versions');
469:                 }
470: 
471:                 $table = $metaVersionColl->fetchTable($metaFields);
472: 
473:                 // add ...
474:                 $metaVersionMap = array();
475:                 foreach ($table AS $key => $item) {
476:                     $metaVersionMap[] = $item['version'];
477:                 }
478:                 $metaVersionMap = array_unique($metaVersionMap);
479:                 $artLangVersionColl->setWhere('version', $metaVersionMap, 'IN');
480: 
481:             } else if ($selectElementType == 'config') {
482: 
483:                 // select all versions
484: 
485:             }
486: 
487:         } catch (cException $e) {
488:             return $artLangVersionMap;
489:         }
490: 
491:         $artLangVersionColl->query();
492: 
493:         $fields['idartlangversion'] = 'idartlangversion';
494:         $fields['version'] = 'version';
495:         $fields['lastmodified'] = 'lastmodified';
496: 
497:         if (0 < $artLangVersionColl->count()) {
498:             $table = $artLangVersionColl->fetchTable($fields);
499: 
500:             foreach ($table AS $key => $item) {
501:                 $artLangVersionMap[$item['version']][$item['idartlangversion']] = $item['lastmodified'];
502:             }
503:         }
504: 
505:         return $artLangVersionMap;
506: 
507:     }
508: 
509:     /**
510:      * Prepares content for saving (consider versioning-mode; prevents multiple
511:      * storings for filelists e.g.).
512:      *
513:      * @param int $idartlang
514:      *         the contents idartlang
515:      * @param cApiContent $content
516:      *         the content to store
517:      * @param unknown_type $value
518:      *         the contents value to store
519:      */
520:     public function prepareContentForSaving($idartlang, cApiContent $content, $value) {
521: 
522:         // Through a CONTENIDO bug filelists save each of their changes multiple
523:         // times. Therefore its necessary to check if the same change already
524:         // has been saved and prevent multiple savings.
525:         static $savedTypes = array();
526:         if (isset($savedTypes[$content->get('idtype') . $content->get('typeid')])) {
527:             return;
528:         }
529:         $savedTypes[$content->get('idtype').$content->get('typeid')] = $value;
530: 
531:         $versioningState = $this->getState();
532:         $date = date('Y-m-d H:i:s');
533: 
534:         $auth = cRegistry::getAuth();
535:         $author = $auth->auth['uname'];
536: 
537:         switch ($versioningState) {
538:             case 'simple':
539:                 // Create Content Version
540:                 $idContent = NULL;
541:                 if ($content->isLoaded()) {
542:                     $idContent = $content->getField('idcontent');
543:                 }
544: 
545:                 if ($idContent == NULL) {
546:                     $idContent = $this->getMaxIdContent() + 1;
547:                 }
548: 
549:                 $parameters = array(
550:                     'idcontent' => $idContent,
551:                     'idartlang' => $idartlang,
552:                     'idtype' => $content->get('idtype'),
553:                     'typeid' => $content->get('typeid'),
554:                     'value' => $value,
555:                     'author' => $author,
556:                     'created' => $date,
557:                     'lastmodified' => $date
558:                 );
559: 
560:                 $this->createContentVersion($parameters);
561:             case 'disabled':
562:                 if ($content->isLoaded()) {
563:                     // Update existing entry
564:                     $content->set('value', $value);
565:                     $content->set('author', $author);
566:                     $content->set('lastmodified', date('Y-m-d H:i:s'));
567:                     $content->store();
568:                 } else {
569:                     // Create new entry
570:                     $contentColl = new cApiContentCollection();
571:                     $content = $contentColl->create(
572:                         $idartlang,
573:                         $content->get('idtype'),
574:                         $content->get('typeid'),
575:                         $value,
576:                         0,
577:                         $author,
578:                         $date,
579:                         $date
580:                     );
581:                 }
582: 
583:                 // Touch the article to update last modified date
584:                 $lastmodified = date('Y-m-d H:i:s');
585:                 $artLang = new cApiArticleLanguage($idartlang);
586:                 $artLang->set('lastmodified', $lastmodified);
587:                 $artLang->set('modifiedby', $author);
588:                 $artLang->store();
589: 
590:                 break;
591:             case 'advanced':
592:                 // Create Content Version
593:                 $idContent = NULL;
594:                 if ($content->isLoaded()) {
595:                     $idContent = $content->getField('idcontent');
596:                 }
597: 
598:                 if ($idContent == NULL) {
599:                     $idContent = $this->getMaxIdContent() + 1;
600:                 }
601: 
602:                 $parameters = array(
603:                     'idcontent' => $idContent,
604:                     'idartlang' => $idartlang,
605:                     'idtype' => $content->get('idtype'),
606:                     'typeid' => $content->get('typeid'),
607:                     'value' => $value,
608:                     'author' => $author,
609:                     'created' => $date,
610:                     'lastmodified' => $date
611:                 );
612: 
613:                 $this->createContentVersion($parameters);
614:             default:
615:                 break;
616:         }
617:     }
618: 
619:     /**
620:      * Create new content version.
621:      *
622:      * @param mixed[] $parameters {
623:      *     @type int $idContent
624:      *     @type int $idArtLang
625:      *     @type int $idType
626:      *     @type int $typeId
627:      *     @type string $value
628:      *     @type string $author
629:      *     @type string $created
630:      *     @type string $lastModified
631:      * }
632:     */
633:     public function createContentVersion(array $parameters) {
634: 
635:         // set parameters for article language version
636:         $currentArticle = cRegistry::getArticleLanguage();
637: 
638:         // create new article language version and get the version number
639:         $parametersArticleVersion = array(
640:             'idartlang' => $currentArticle->getField('idartlang'),
641:             'idart' => $currentArticle->getField('idart'),
642:             'idlang' => $currentArticle->getField('idlang'),
643:             'title' => $currentArticle->getField('title'),
644:             'urlname' => $currentArticle->getField('urlname'),
645:             'pagetitle' => $currentArticle->getField('pagetitle'),
646:             'summary' => $currentArticle->getField('summary'),
647:             'artspec' => $currentArticle->getField('artspec'),
648:             'created' => $currentArticle->getField('created'),
649:             'iscurrentversion' => 1,
650:             'author' => $currentArticle->getField('author'),
651:             'lastmodified' => date('Y-m-d H:i:s'),
652:             'modifiedby' => $currentArticle->getField('author'),
653:             'published' => $currentArticle->getField('published'),
654:             'publishedby' => $currentArticle->getField('publishedby'),
655:             'online' => $currentArticle->getField('online'),
656:             'redirect' => $currentArticle->getField('redirect'),
657:             'redirect_url' => $currentArticle->getField('redirect_url'),
658:             'external_redirect' => $currentArticle->getField('external_redirect'),
659:             'artsort' => $currentArticle->getField('artsort'),
660:             'timemgmt' => $currentArticle->getField('timemgmt'),
661:             'datestart' => $currentArticle->getField('datestart'),
662:             'dateend' => $currentArticle->getField('dateend'),
663:             'status' => $currentArticle->getField('status'),
664:             'time_move_cat' => $currentArticle->getField('time_move_cat'),
665:             'time_target_cat' => $currentArticle->getField('time_target_cat'),
666:             'time_online_move' => $currentArticle->getField('time_online_move'),
667:             'locked' => $currentArticle->getField('locked'),
668:             'free_use_01' => $currentArticle->getField('free_use_01'),
669:             'free_use_02' => $currentArticle->getField('free_use_02'),
670:             'free_use_03' => $currentArticle->getField('free_use_03'),
671:             'searchable' => $currentArticle->getField('searchable'),
672:             'sitemapprio' => $currentArticle->getField('sitemapprio'),
673:             'changefreq' => $currentArticle->getField('changefreq')
674:         );
675: 
676:         $artLangVersion = $this->createArticleLanguageVersion($parametersArticleVersion);
677: 
678:         // get the version number of the new article language version that belongs to the content
679:         $parameters['version'] = $artLangVersion->getField('version');
680: 
681:         $parametersToCheck = $parameters;
682:         unset(
683:             $parametersToCheck['lastmodified'],
684:             $parametersToCheck['author'],
685:             $parametersToCheck['value'],
686:             $parametersToCheck['created']
687:         );
688: 
689:         // if there already is a content type like this in this version,
690:         // create a new article version, too (needed for storing
691:         // a version after first change in simple-mode)
692:         $contentVersion = new cApiContentVersion();
693:         $contentVersion->loadByMany($parametersToCheck);
694:         if ($contentVersion->isLoaded()) {
695:             $artLangVersion = $this->createArticleLanguageVersion($parametersArticleVersion);
696:             $parameters['version'] = $artLangVersion->getField('version');
697:             $contentVersionColl = new cApiContentVersionCollection();
698:             $contentVersionColl->create($parameters);
699:         } else {
700:             // if there is no content type like this in this version, create one
701:             $contentVersionColl = new cApiContentVersionCollection();
702:             $contentVersionColl->create($parameters);
703:         }
704:     }
705: 
706:     /**
707:      * Create new article language version.
708:      *
709:      * @global int $lang
710:      * @global object $auth
711:      * @global string $urlname
712:      * @global string $page_title
713:      * @param mixed[] $parameters {
714:      *     @type int $idart
715:      *     @type int $idlang
716:      *     @type string $title
717:      *     @type string $urlname
718:      *     @type string $pagetitle
719:      *     @type string $summary
720:      *     @type int $artspec
721:      *     @type string $created
722:      *     @type int $iscurrentverseion
723:      *     @type string $author
724:      *     @type string $lastmodified
725:      *     @type string $modifiedby
726:      *     @type string $published
727:      *     @type string $publishedby
728:      *     @type int $online
729:      *     @type int $redirect
730:      *     @type string $redirect_url
731:      *     @type int $external_redirect
732:      *     @type int $artsort
733:      *     @type int $timemgmt
734:      *     @type string $datestart
735:      *     @type string $dateend
736:      *     @type int $status
737:      *     @type int $time_move_cat
738:      *     @type int $time_target_cat
739:      *     @type int $time_online_move
740:      *     @type int $locked
741:      *     @type mixed $free_use_01
742:      *     @type mixed $free_use_02
743:      *     @type mixed $free_use_03
744:      *     @type int $searchable
745:      *     @type float $sitemapprio
746:      *     @type string $changefreq
747:      * }
748:      * @return cApiArticleLanguageVersion
749:     */
750:     public function createArticleLanguageVersion(array $parameters) {
751: 
752:         global $lang, $auth, $urlname, $page_title;
753: 
754:         // Some stuff for the redirect
755:         global $redirect, $redirect_url, $external_redirect;
756: 
757:         // Used to indicate "move to cat"
758:         global $time_move_cat;
759: 
760:         // Used to indicate the target category
761:         global $time_target_cat;
762: 
763:         // Used to indicate if the moved article should be online
764:         global $time_online_move;
765: 
766:         global $timemgmt;
767: 
768:         $page_title = (empty($parameters['pagetitle'])) ? addslashes($page_title) : $parameters['pagetitle'];
769: 
770:         $parameters['title'] = stripslashes($parameters['title']);
771: 
772:         $redirect = (empty($parameters['redirect'])) ? cSecurity::toInteger($redirect) : $parameters['redirect'];
773:         $redirect_url = (empty($parameters['page_title'])) ? stripslashes($redirect_url) : stripslashes($parameters['redirect_url']);
774:         $external_redirect = (empty($parameters['external_redirect'])) ? stripslashes($external_redirect) : stripslashes($parameters['external_redirect']);
775: 
776:         $urlname = (trim($urlname) == '')? trim($parameters['title']) : trim($urlname);
777: 
778:         if ($parameters['isstart'] == 1) {
779:             $timemgmt = 0;
780:         }
781: 
782:         if (!is_array($parameters['idcatnew'])) {
783:             $parameters['idcatnew'][0] = 0;
784:         }
785: 
786:         // Set parameters for article language version
787:         $artLangVersionParameters = array(
788:             'idartlang' => $parameters['idartlang'],
789:             'idart' => $parameters['idart'],
790:             'idlang' => $lang,
791:             'title' => $parameters['title'],
792:             'urlname' => $urlname,
793:             'pagetitle' => $page_title,
794:             'summary' => $parameters['summary'],
795:             'artspec' => $parameters['artspec'],
796:             'created' => $parameters['created'],
797:             'iscurrentversion' => $parameters['iscurrentversion'],
798:             'author' => $parameters['author'],
799:             'lastmodified' => date('Y-m-d H:i:s'),
800:             'modifiedby' => $auth->auth['uname'],
801:             'published' => $parameters['published'],
802:             'publishedby' => $parameters['publishedby'],
803:             'online' => $parameters['online'],
804:             'redirect' => $redirect,
805:             'redirect_url' => $redirect_url,
806:             'external_redirect' => $external_redirect,
807:             'artsort' => $parameters['artsort'],
808:             'timemgmt' => $timemgmt,
809:             'datestart' => $parameters['datestart'],
810:             'dateend' => $parameters['dateend'],
811:             'status' => 0,
812:             'time_move_cat' => $time_move_cat,
813:             'time_target_cat' => $time_target_cat,
814:             'time_online_move' => $time_online_move,
815:             'locked' => 0,
816:             'free_use_01' => '',
817:             'free_use_02' => '',
818:             'free_use_03' => '',
819:             'searchable' => $parameters['searchable'],
820:             'sitemapprio' => $parameters['sitemapprio'],
821:             'changefreq' => $parameters['changefreq']
822:         );
823: 
824:         // Create article language version entry
825:         $artLangVersionColl = new cApiArticleLanguageVersionCollection();
826:         $artLangVersion = $artLangVersionColl->create($artLangVersionParameters);
827: 
828:         // version Contents if contents are not versioned yet
829:         if (isset($parameters['idartlang'])){
830:             $where = 'idartlang = ' . $parameters['idartlang'];
831:             $contentVersionColl = new cApiContentVersionCollection();
832:             $contentVersions = $contentVersionColl->getIdsByWhereClause($where);
833:         }
834: 
835:         if (empty($contentVersions)) {
836:             $artLang = new cApiArticleLanguage($parameters['idartlang']);
837:             $conType = new cApiType();
838:             $content = new cApiContent();
839:             foreach ($artLang->getContent() AS $type => $typeids) {
840:                 foreach ($typeids AS $typeid => $value) {
841:                     $conType->loadByType($type);
842:                     $content->loadByArticleLanguageIdTypeAndTypeId(
843:                         $parameters['idartlang'],
844:                         $conType->get('idtype'),
845:                         $typeid
846:                     );
847:                     $content->markAsEditable($artLangVersion->get('version'), 0);
848:                 }
849:             }
850:         }
851: 
852:         // version meta tags if they are not versioned yet
853:         if (isset($parameters['idartlang'])) {
854:             $where = 'idartlang = ' . $parameters['idartlang'];
855:             $metaTagVersionColl = new cApiMetaTagVersionCollection();
856:             $metaTagVersions = $metaTagVersionColl->getIdsByWhereClause($where);
857:         }
858: 
859:         if (empty($metaTagVersions)) {
860:             $where = 'idartlang = ' . $parameters['idartlang'];
861:             $metaTagColl = new cApiMetaTagCollection();
862:             $metaTags = $metaTagColl->getIdsByWhereClause($where);
863:             $metaTag = new cApiMetaTag();
864:             foreach ($metaTags AS $id) {
865:                 $metaTag->loadBy('idmetatag', $id);
866:                 $metaTag->markAsEditable($artLangVersion->get('version'));
867:             }
868:         }
869: 
870:         return $artLangVersion;
871:     }
872: 
873:     /**
874:      * Create new Meta Tag Version.
875:      *
876:      * @param mixed[] $parameters {
877:      *     @type int $idmetatag
878:      *     @type int $idartlang
879:      *     @type string $idmetatype
880:      *     @type string $value
881:      *     @type int version
882:      * }
883:      * @return cApiMetaTagVersion
884:     */
885:     public function createMetaTagVersion(array $parameters) {
886: 
887:         $coll = new cApiMetaTagVersionCollection();
888:         $item = $coll->create(
889:             $parameters['idmetatag'],
890:             $parameters['idartlang'],
891:             $parameters['idmetatype'],
892:             $parameters['value'],
893:             $parameters['version']
894:         );;
895: 
896:         return $item;
897: 
898:     }
899: }
900: 
CMS CONTENIDO 4.9.11 API documentation generated by ApiGen 2.8.0