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