1: <?php
2: /**
3: * This file contains the article language collection and item class.
4: *
5: * @package Core
6: * @subpackage GenericDB_Model
7: * @version SVN Revision $Rev:$
8: *
9: * @author Bjoern Behrens
10: * @copyright four for business AG <www.4fb.de>
11: * @license http://www.contenido.org/license/LIZENZ.txt
12: * @link http://www.4fb.de
13: * @link http://www.contenido.org
14: */
15:
16: defined('CON_FRAMEWORK') || die('Illegal call: Missing framework initialization - request aborted.');
17:
18: /**
19: * Article language collection
20: *
21: * @package Core
22: * @subpackage GenericDB_Model
23: */
24: class cApiArticleLanguageCollection extends ItemCollection {
25:
26: /**
27: * Create a new collection of items.
28: *
29: * @param string $select where clause to use for selection (see
30: * ItemCollection::select())
31: */
32: public function __construct($select = false) {
33: global $cfg;
34: parent::__construct($cfg['tab']['art_lang'], 'idartlang');
35: $this->_setItemClass('cApiArticleLanguage');
36:
37: // set the join partners so that joins can be used via link() method
38: $this->_setJoinPartner('cApiArticleCollection');
39: $this->_setJoinPartner('cApiLanguageCollection');
40: $this->_setJoinPartner('cApiTemplateConfigurationCollection');
41:
42: if ($select !== false) {
43: $this->select($select);
44: }
45: }
46:
47: /**
48: * Creates an article language item entry.
49: *
50: * @global object $auth
51: * @param int $idart
52: * @param int $idlang
53: * @param string $title
54: * @param string $urlname
55: * @param string $pagetitle
56: * @param string $summary
57: * @param int $artspec
58: * @param string $created
59: * @param string $author
60: * @param string $lastmodified
61: * @param string $modifiedby
62: * @param string $published
63: * @param string $publishedby
64: * @param int $online
65: * @param int $redirect
66: * @param string $redirect_url
67: * @param int $external_redirect
68: * @param int $artsort
69: * @param int $timemgmt
70: * @param string $datestart
71: * @param string $dateend
72: * @param int $status
73: * @param int $time_move_cat
74: * @param int $time_target_cat
75: * @param int $time_online_move
76: * @param int $locked
77: * @param mixed $free_use_01
78: * @param mixed $free_use_02
79: * @param mixed $free_use_03
80: * @param int $searchable
81: * @param float $sitemapprio
82: * @param string $changefreq
83: * @return cApiArticleLanguage
84: */
85: public function create($idart, $idlang, $title, $urlname, $pagetitle, $summary, $artspec = 0, $created = '', $author = '', $lastmodified = '', $modifiedby = '', $published = '', $publishedby = '', $online = 0, $redirect = 0, $redirect_url = '', $external_redirect = 0, $artsort = 0, $timemgmt = 0, $datestart = '', $dateend = '', $status = 0, $time_move_cat = 0, $time_target_cat = 0, $time_online_move = 0, $locked = 0, $free_use_01 = '', $free_use_02 = '', $free_use_03 = '', $searchable = 1, $sitemapprio = 0.5, $changefreq = '') {
86: global $auth;
87:
88: if (empty($author)) {
89: $author = $auth->auth['uname'];
90: }
91: if (empty($created)) {
92: $created = date('Y-m-d H:i:s');
93: }
94: if (empty($lastmodified)) {
95: $lastmodified = date('Y-m-d H:i:s');
96: }
97:
98: $urlname = (trim($urlname) == '') ? trim($title) : trim($urlname);
99:
100: $item = parent::createNewItem();
101:
102: $item->set('idart', $idart);
103: $item->set('idlang', $idlang);
104: $item->set('title', $title);
105: $item->set('urlname', $urlname);
106: $item->set('pagetitle', $pagetitle);
107: $item->set('summary', $summary);
108: $item->set('artspec', $artspec);
109: $item->set('created', $created);
110: $item->set('author', $author);
111: $item->set('lastmodified', $lastmodified);
112: $item->set('modifiedby', $modifiedby);
113: $item->set('published', $published);
114: $item->set('publishedby', $publishedby);
115: $item->set('online', $online);
116: $item->set('redirect', $redirect);
117: $item->set('redirect_url', $redirect_url);
118: $item->set('external_redirect', $external_redirect);
119: $item->set('artsort', $artsort);
120: $item->set('timemgmt', $timemgmt);
121: $item->set('datestart', $datestart);
122: $item->set('dateend', $dateend);
123: $item->set('status', $status);
124: $item->set('time_move_cat', $time_move_cat);
125: $item->set('time_target_cat', $time_target_cat);
126: $item->set('time_online_move', $time_online_move);
127: $item->set('locked', $locked);
128: $item->set('free_use_01', $free_use_01);
129: $item->set('free_use_02', $free_use_02);
130: $item->set('free_use_03', $free_use_03);
131: $item->set('searchable', $searchable);
132: $item->set('sitemapprio', $sitemapprio);
133: $item->set('changefreq', $changefreq);
134:
135: $item->store();
136:
137: return $item;
138: }
139:
140: /**
141: * Returns id (idartlang) of articlelanguage by article id and language id
142: *
143: * @param int $idcat
144: * @param int $idlang
145: * @return int
146: */
147: public function getIdByArticleIdAndLanguageId($idart, $idlang) {
148: $sql = "SELECT idartlang FROM `%s` WHERE idart = %d AND idlang = %d";
149: $this->db->query($sql, $this->table, $idart, $idlang);
150: return ($this->db->nextRecord()) ? $this->db->f('idartlang') : 0;
151: }
152:
153: }
154:
155: /**
156: * CONTENIDO API - Article Object
157: *
158: * This object represents a CONTENIDO article
159: *
160: * Create object with
161: * $obj = new cApiArticleLanguage(idartlang);
162: * or with
163: * $obj = new cApiArticleLanguage();
164: * $obj->loadByArticleAndLanguageId(idart, lang);
165: *
166: * You can now read the article properties with
167: * $obj->getField(property);
168: *
169: * List of article properties:
170: *
171: * idartlang - Language dependant article id
172: * idart - Language indepenant article id
173: * idclient - Id of the client
174: * idtplcfg - Template configuration id
175: * title - Internal Title
176: * pagetitle - HTML Title
177: * summary - Article summary
178: * created - Date created
179: * lastmodified - Date lastmodiefied
180: * author - Article author (username)
181: * online - On-/offline
182: * redirect - Redirect
183: * redirect_url - Redirect URL
184: * artsort - Article sort key
185: * timemgmt - Time management
186: * datestart - Time management start date
187: * dateend - Time management end date
188: * status - Article status
189: * free_use_01 - Free to use
190: * free_use_02 - Free to use
191: * free_use_03 - Free to use
192: * time_move_cat - Move category after time management
193: * time_target_cat - Move category to this cat after time management
194: * time_online_move - Set article online after move
195: * external_redirect - Open article in new window
196: * locked - Article is locked for editing
197: * searchable - Whether article should be found via search
198: * sitemapprio - The priority for the sitemap
199: *
200: * You can extract article content with the
201: * $obj->getContent(contype [, number]) method.
202: *
203: * To extract the first headline you can use:
204: *
205: * $headline = $obj->getContent("htmlhead", 1);
206: *
207: * If the second parameter is ommitted the method returns an array with all
208: * available
209: * content of this type. The array has the following schema:
210: *
211: * array(number => content);
212: *
213: * $headlines = $obj->getContent("htmlhead");
214: *
215: * $headlines[1] First headline
216: * $headlines[2] Second headline
217: * $headlines[6] Sixth headline
218: *
219: * Legal content type string are defined in the CONTENIDO system table
220: * 'con_type'.
221: * Default content types are:
222: *
223: * NOTE: This parameter is case insesitive, you can use html or cms_HTML or
224: * CmS_HtMl.
225: * Your don't need start with cms, but it won't crash if you do so.
226: *
227: * htmlhead - HTML Headline
228: * html - HTML Text
229: * headline - Headline (no HTML)
230: * text - Text (no HTML)
231: * img - Upload id of the element
232: * imgdescr - Image description
233: * link - Link (URL)
234: * linktarget - Linktarget (_self, _blank, _top ...)
235: * linkdescr - Linkdescription
236: * swf - Upload id of the element
237: *
238: * @package Core
239: * @subpackage GenericDB_Model
240: */
241: class cApiArticleLanguage extends Item {
242:
243: /**
244: * Config array
245: *
246: * @var array
247: */
248: public $tab;
249:
250: /**
251: * Article content
252: *
253: * @var array
254: */
255: public $content = NULL;
256:
257: /**
258: * Constructor Function
259: *
260: * @param mixed $mId Specifies the ID of item to load
261: * @param bool $fetchContent Flag to fetch content
262: */
263: public function __construct($mId = false, $fetchContent = false) {
264: global $cfg;
265: parent::__construct($cfg['tab']['art_lang'], 'idartlang');
266: $this->setFilters(array(), array());
267: if ($mId !== false) {
268: $this->loadByPrimaryKey($mId);
269: if (true === $fetchContent) {
270: $this->_getArticleContent();
271: }
272: }
273: }
274:
275: /**
276: * Load data by article and language id
277: *
278: * @param int $idart Article id
279: * @param int $idlang Language id
280: * @param bool $fetchContent Flag to fetch content
281: * @return bool true on success, otherwhise false
282: */
283: public function loadByArticleAndLanguageId($idart, $idlang, $fetchContent = false) {
284: $result = true;
285: if (!$this->isLoaded()) {
286: $aProps = array(
287: 'idart' => $idart,
288: 'idlang' => $idlang
289: );
290: $aRecordSet = $this->_oCache->getItemByProperties($aProps);
291: if ($aRecordSet) {
292: // entry in cache found, load entry from cache
293: $this->loadByRecordSet($aRecordSet);
294: } else {
295: $idartlang = $this->_getIdArtLang($idart, $idlang);
296: $result = $this->loadByPrimaryKey($idartlang);
297: }
298: }
299:
300: if (true === $fetchContent) {
301: $this->_getArticleContent();
302: }
303:
304: return $result;
305: }
306:
307: /**
308: * Extract 'idartlang' for a specified 'idart' and 'idlang'
309: *
310: * @param int $idart Article id
311: * @param int $idlang Language id
312: * @return int Language dependant article id
313: */
314: protected function _getIdArtLang($idart, $idlang) {
315: global $cfg;
316:
317: $sql = 'SELECT idartlang FROM `%s` WHERE idart = %d AND idlang = %d';
318: $this->db->query($sql, $cfg['tab']['art_lang'], $idart, $idlang);
319: $this->db->nextRecord();
320:
321: return $this->db->f('idartlang');
322: }
323:
324: /**
325: * Load the articles content and stores it in the 'content' property of the
326: * article object.
327: *
328: * $article->content[type][number] = value;
329: */
330: public function loadArticleContent() {
331: $this->_getArticleContent();
332: }
333:
334: /**
335: * Load the articles content and stores it in the 'content' property of the
336: * article object.
337: *
338: * $article->content[type][number] = value;
339: */
340: protected function _getArticleContent() {
341: global $cfg;
342:
343: if (NULL !== $this->content) {
344: return;
345: }
346:
347: $sql = 'SELECT b.type, a.typeid, a.value FROM `%s` AS a, `%s` AS b ' . 'WHERE a.idartlang = %d AND b.idtype = a.idtype ORDER BY a.idtype, a.typeid';
348:
349: $this->db->query($sql, $cfg['tab']['content'], $cfg['tab']['type'], $this->get('idartlang'));
350:
351: $this->content = array();
352: while ($this->db->nextRecord()) {
353: $this->content[strtolower($this->db->f('type'))][$this->db->f('typeid')] = $this->db->f('value');
354: }
355: }
356:
357: /**
358: * Get the value of an article property
359: *
360: * List of article properties:
361: *
362: * idartlang - Language dependant article id
363: * idart - Language indepenant article id
364: * idclient - Id of the client
365: * idtplcfg - Template configuration id
366: * title - Internal Title
367: * pagetitle - HTML Title
368: * summary - Article summary
369: * created - Date created
370: * lastmodified - Date lastmodiefied
371: * author - Article author (username)
372: * online - On-/offline
373: * redirect - Redirect
374: * redirect_url - Redirect URL
375: * artsort - Article sort key
376: * timemgmt - Time management
377: * datestart - Time management start date
378: * dateend - Time management end date
379: * status - Article status
380: * free_use_01 - Free to use
381: * free_use_02 - Free to use
382: * free_use_03 - Free to use
383: * time_move_cat - Move category after time management
384: * time_target_cat - Move category to this cat after time management
385: * time_online_move - Set article online after move
386: * external_redirect - Open article in new window
387: * locked - Article is locked for editing
388: * searchable - Whether article should be found via search
389: * sitemapprio - The priority for the sitemap
390: *
391: * @param string $name
392: * @param bool $bSafe Flag to run defined outFilter on passed value
393: * NOTE: It's not used ATM!
394: * @return string Value of property
395: */
396: public function getField($name, $bSafe = true) {
397: return $this->values[$name];
398: }
399:
400: /**
401: * Userdefined setter for article language fields.
402: *
403: * @param string $name
404: * @param mixed $value
405: * @param bool $bSafe Flag to run defined inFilter on passed value
406: * @todo should return return value of overloaded method
407: */
408: public function setField($name, $value, $bSafe = true) {
409: switch ($name) {
410: case 'urlname':
411: $value = conHtmlSpecialChars(cApiStrCleanURLCharacters($value), ENT_QUOTES);
412: break;
413: case 'timemgmt':
414: case 'time_move_cat':
415: case 'time_online_move':
416: case 'redirect':
417: case 'external_redirect':
418: case 'locked':
419: $value = ($value == 1) ? 1 : 0;
420: break;
421: case 'idart':
422: case 'idlang':
423: case 'artspec':
424: case 'online':
425: case 'searchable':
426: case 'artsort':
427: case 'status':
428: $value = (int) $value;
429: break;
430: case 'redirect_url':
431: $value = ($value == 'http://' || $value == '') ? '0' : $value;
432: break;
433: }
434:
435: parent::setField($name, $value, $bSafe);
436: }
437:
438: /**
439: * Get content(s) from an article.
440: *
441: * Returns the specified content element or an array("id"=>"value") if the
442: * second parameter is omitted.
443: *
444: * Legal content type string are defined in the CONTENIDO system table
445: * 'con_type'.
446: * Default content types are:
447: *
448: * NOTE: Parameter is case insesitive, you can use html or cms_HTML or
449: * CmS_HtMl.
450: * Your don't need start with cms, but it won't crash if you do so.
451: *
452: * htmlhead - HTML Headline
453: * html - HTML Text
454: * headline - Headline (no HTML)
455: * text - Text (no HTML)
456: * img - Upload id of the element
457: * imgdescr - Image description
458: * link - Link (URL)
459: * linktarget - Linktarget (_self, _blank, _top ...)
460: * linkdescr - Linkdescription
461: * swf - Upload id of the element
462: *
463: * @param string $type CMS_TYPE - Legal cms type string
464: * @param int|NULL $id Id of the content
465: * @return string array data
466: */
467: public function getContent($type, $id = NULL) {
468: if (NULL === $this->content) {
469: $this->_getArticleContent();
470: }
471:
472: if (empty($this->content)) {
473: return '';
474: }
475:
476: if ($type == '') {
477: return 'Class ' . get_class($this) . ': content-type must be specified!';
478: }
479:
480: $type = strtolower($type);
481:
482: if (!strstr($type, 'cms_')) {
483: $type = 'cms_' . $type;
484: }
485:
486: if (is_null($id)) {
487: // return Array
488: return $this->content[$type];
489: }
490:
491: // return String
492: return (isset($this->content[$type][$id])) ? $this->content[$type][$id] : '';
493: }
494:
495: /**
496: * Similar to getContent this function returns the cContentType object
497: *
498: * @param string $type Name of the content type
499: * @param int $id Id of the content type in this article
500: * @return boolean|cContenType Returns false if the name was invalid
501: */
502: public function getContentObject($type, $id) {
503: $typeClassName = 'cContentType' . ucfirst(strtolower(str_replace('CMS_', '', $type)));
504:
505: if (!class_exists($typeClassName)) {
506: return false;
507: }
508:
509: return new $typeClassName($this->getContent($type, $id), $id, $this->content);
510: }
511:
512: /**
513: * Similar to getContent this function returns the view voce of the cContentType object
514: * @param string $type Name of the content type
515: * @param int $id Id of the content type in this article
516: * @return string
517: */
518: public function getContentViewCode($type, $id) {
519: $object = $this->getContentObject($type, $id);
520: if ($object === false) {
521: return "";
522: }
523:
524: return $object->generateViewCode();
525: }
526:
527: /**
528: * Returns all available content types
529: *
530: * @throws cException if no content has been loaded
531: * @return array
532: */
533: public function getContentTypes() {
534: if (empty($this->content)) {
535: throw new cException('getContentTypes() No content loaded');
536: }
537: return array_keys($this->content);
538: }
539:
540: /**
541: * Returns the link to the current object.
542: *
543: * @param int $changeLangId change language id for URL (optional)
544: * @return string link
545: */
546: public function getLink($changeLangId = 0) {
547: if ($this->isLoaded() === false) {
548: return '';
549: }
550:
551: $options = array();
552: $options['idart'] = $this->get('idart');
553: $options['lang'] = ($changeLangId == 0) ? $this->get('idlang') : $changeLangId;
554: if ($changeLangId > 0) {
555: $options['changelang'] = $changeLangId;
556: }
557:
558: return cUri::getInstance()->build($options);
559: }
560:
561: }
562: