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: * CONTENIDO API - Article Object
156: *
157: * This object represents a CONTENIDO article
158: *
159: * Create object with
160: * $obj = new cApiArticleLanguage(idartlang);
161: * or with
162: * $obj = new cApiArticleLanguage();
163: * $obj->loadByArticleAndLanguageId(idart, lang);
164: *
165: * You can now read the article properties with
166: * $obj->getField(property);
167: *
168: * List of article properties:
169: *
170: * idartlang - Language dependant article id
171: * idart - Language indepenant article id
172: * idclient - Id of the client
173: * idtplcfg - Template configuration id
174: * title - Internal Title
175: * pagetitle - HTML Title
176: * summary - Article summary
177: * created - Date created
178: * lastmodified - Date lastmodiefied
179: * author - Article author (username)
180: * online - On-/offline
181: * redirect - Redirect
182: * redirect_url - Redirect URL
183: * artsort - Article sort key
184: * timemgmt - Time management
185: * datestart - Time management start date
186: * dateend - Time management end date
187: * status - Article status
188: * free_use_01 - Free to use
189: * free_use_02 - Free to use
190: * free_use_03 - Free to use
191: * time_move_cat - Move category after time management
192: * time_target_cat - Move category to this cat after time management
193: * time_online_move - Set article online after move
194: * external_redirect - Open article in new window
195: * locked - Article is locked for editing
196: * searchable - Whether article should be found via search
197: * sitemapprio - The priority for the sitemap
198: *
199: * You can extract article content with the
200: * $obj->getContent(contype [, number]) method.
201: *
202: * To extract the first headline you can use:
203: *
204: * $headline = $obj->getContent("htmlhead", 1);
205: *
206: * If the second parameter is ommitted the method returns an array with all
207: * available
208: * content of this type. The array has the following schema:
209: *
210: * array(number => content);
211: *
212: * $headlines = $obj->getContent("htmlhead");
213: *
214: * $headlines[1] First headline
215: * $headlines[2] Second headline
216: * $headlines[6] Sixth headline
217: *
218: * Legal content type string are defined in the CONTENIDO system table
219: * 'con_type'.
220: * Default content types are:
221: *
222: * NOTE: This parameter is case insesitive, you can use html or cms_HTML or
223: * CmS_HtMl.
224: * Your don't need start with cms, but it won't crash if you do so.
225: *
226: * htmlhead - HTML Headline
227: * html - HTML Text
228: * headline - Headline (no HTML)
229: * text - Text (no HTML)
230: * img - Upload id of the element
231: * imgdescr - Image description
232: * link - Link (URL)
233: * linktarget - Linktarget (_self, _blank, _top ...)
234: * linkdescr - Linkdescription
235: * swf - Upload id of the element
236: *
237: * @package Core
238: * @subpackage GenericDB_Model
239: */
240: class cApiArticleLanguage extends Item {
241:
242: /**
243: * Config array
244: *
245: * @var array
246: */
247: public $tab;
248:
249: /**
250: * Article content
251: *
252: * @var array
253: */
254: public $content = NULL;
255:
256: /**
257: * Constructor Function
258: *
259: * @param mixed $mId Specifies the ID of item to load
260: * @param bool $fetchContent Flag to fetch content
261: */
262: public function __construct($mId = false, $fetchContent = false) {
263: global $cfg;
264: parent::__construct($cfg['tab']['art_lang'], 'idartlang');
265: $this->setFilters(array(), array());
266: if ($mId !== false) {
267: $this->loadByPrimaryKey($mId);
268: if (true === $fetchContent) {
269: $this->_getArticleContent();
270: }
271: }
272: }
273:
274: /**
275: * Load data by article and language id
276: *
277: * @param int $idart Article id
278: * @param int $idlang Language id
279: * @param bool $fetchContent Flag to fetch content
280: * @return bool true on success, otherwhise false
281: */
282: public function loadByArticleAndLanguageId($idart, $idlang, $fetchContent = false) {
283: $result = true;
284: if (!$this->isLoaded()) {
285: $aProps = array(
286: 'idart' => $idart,
287: 'idlang' => $idlang
288: );
289: $aRecordSet = $this->_oCache->getItemByProperties($aProps);
290: if ($aRecordSet) {
291: // entry in cache found, load entry from cache
292: $this->loadByRecordSet($aRecordSet);
293: } else {
294: $idartlang = $this->_getIdArtLang($idart, $idlang);
295: $result = $this->loadByPrimaryKey($idartlang);
296: }
297: }
298:
299: if (true === $fetchContent) {
300: $this->_getArticleContent();
301: }
302:
303: return $result;
304: }
305:
306: /**
307: * Extract 'idartlang' for a specified 'idart' and 'idlang'
308: *
309: * @param int $idart Article id
310: * @param int $idlang Language id
311: * @return int Language dependant article id
312: */
313: protected function _getIdArtLang($idart, $idlang) {
314: global $cfg;
315:
316: $sql = 'SELECT idartlang FROM `%s` WHERE idart = %d AND idlang = %d';
317: $this->db->query($sql, $cfg['tab']['art_lang'], $idart, $idlang);
318: $this->db->nextRecord();
319:
320: return $this->db->f('idartlang');
321: }
322:
323: /**
324: * Load the articles content and stores it in the 'content' property of the
325: * article object.
326: *
327: * $article->content[type][number] = value;
328: */
329: public function loadArticleContent() {
330: $this->_getArticleContent();
331: }
332:
333: /**
334: * Load the articles content and stores it in the 'content' property of the
335: * article object.
336: *
337: * $article->content[type][number] = value;
338: */
339: protected function _getArticleContent() {
340: global $cfg;
341:
342: if (NULL !== $this->content) {
343: return;
344: }
345:
346: $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';
347:
348: $this->db->query($sql, $cfg['tab']['content'], $cfg['tab']['type'], $this->get('idartlang'));
349:
350: $this->content = array();
351: while ($this->db->nextRecord()) {
352: $this->content[strtolower($this->db->f('type'))][$this->db->f('typeid')] = $this->db->f('value');
353: }
354: }
355:
356: /**
357: * Get the value of an article property
358: *
359: * List of article properties:
360: *
361: * idartlang - Language dependant article id
362: * idart - Language indepenant article id
363: * idclient - Id of the client
364: * idtplcfg - Template configuration id
365: * title - Internal Title
366: * pagetitle - HTML Title
367: * summary - Article summary
368: * created - Date created
369: * lastmodified - Date lastmodiefied
370: * author - Article author (username)
371: * online - On-/offline
372: * redirect - Redirect
373: * redirect_url - Redirect URL
374: * artsort - Article sort key
375: * timemgmt - Time management
376: * datestart - Time management start date
377: * dateend - Time management end date
378: * status - Article status
379: * free_use_01 - Free to use
380: * free_use_02 - Free to use
381: * free_use_03 - Free to use
382: * time_move_cat - Move category after time management
383: * time_target_cat - Move category to this cat after time management
384: * time_online_move - Set article online after move
385: * external_redirect - Open article in new window
386: * locked - Article is locked for editing
387: * searchable - Whether article should be found via search
388: * sitemapprio - The priority for the sitemap
389: *
390: * @param string $name
391: * @return string Value of property
392: */
393: public function getField($name) {
394: return $this->values[$name];
395: }
396:
397: /**
398: * Userdefined setter for article language fields.
399: *
400: * @param string $name
401: * @param mixed $value
402: * @param bool $bSafe Flag to run defined inFilter on passed value
403: * @todo should return return value of overloaded method
404: */
405: public function setField($name, $value, $bSafe = true) {
406: switch ($name) {
407: case 'urlname':
408: $value = conHtmlSpecialChars(cApiStrCleanURLCharacters($value), ENT_QUOTES);
409: break;
410: case 'timemgmt':
411: case 'time_move_cat':
412: case 'time_online_move':
413: case 'redirect':
414: case 'external_redirect':
415: case 'locked':
416: $value = ($value == 1) ? 1 : 0;
417: break;
418: case 'idart':
419: case 'idlang':
420: case 'artspec':
421: case 'online':
422: case 'searchable':
423: case 'artsort':
424: case 'status':
425: $value = (int) $value;
426: break;
427: case 'redirect_url':
428: $value = ($value == 'http://' || $value == '') ? '0' : $value;
429: break;
430: }
431:
432: parent::setField($name, $value, $bSafe);
433: }
434:
435: /**
436: * Get content(s) from an article.
437: *
438: * Returns the specified content element or an array("id"=>"value") if the
439: * second parameter is omitted.
440: *
441: * Legal content type string are defined in the CONTENIDO system table
442: * 'con_type'.
443: * Default content types are:
444: *
445: * NOTE: Parameter is case insesitive, you can use html or cms_HTML or
446: * CmS_HtMl.
447: * Your don't need start with cms, but it won't crash if you do so.
448: *
449: * htmlhead - HTML Headline
450: * html - HTML Text
451: * headline - Headline (no HTML)
452: * text - Text (no HTML)
453: * img - Upload id of the element
454: * imgdescr - Image description
455: * link - Link (URL)
456: * linktarget - Linktarget (_self, _blank, _top ...)
457: * linkdescr - Linkdescription
458: * swf - Upload id of the element
459: *
460: * @param string $type CMS_TYPE - Legal cms type string
461: * @param int|NULL $id Id of the content
462: * @return string array data
463: */
464: public function getContent($type, $id = NULL) {
465: if (NULL === $this->content) {
466: $this->_getArticleContent();
467: }
468:
469: if (empty($this->content)) {
470: return '';
471: }
472:
473: if ($type == '') {
474: return 'Class ' . get_class($this) . ': content-type must be specified!';
475: }
476:
477: $type = strtolower($type);
478:
479: if (!strstr($type, 'cms_')) {
480: $type = 'cms_' . $type;
481: }
482:
483: if (is_null($id)) {
484: // return Array
485: return $this->content[$type];
486: }
487:
488: // return String
489: return (isset($this->content[$type][$id])) ? $this->content[$type][$id] : '';
490: }
491:
492: /**
493: * Returns all available content types
494: *
495: * @throws cException if no content has been loaded
496: * @return array
497: */
498: public function getContentTypes() {
499: if (empty($this->content)) {
500: throw new cException('getContentTypes() No content loaded');
501: }
502: return array_keys($this->content);
503: }
504:
505: /**
506: * Returns the link to the current object.
507: *
508: * @param integer $changeLangId change language id for URL (optional)
509: * @return string link
510: */
511: public function getLink($changeLangId = 0) {
512: if ($this->isLoaded() === false) {
513: return '';
514: }
515:
516: $options = array();
517: $options['idart'] = $this->get('idart');
518: $options['lang'] = ($changeLangId == 0) ? $this->get('idlang') : $changeLangId;
519: if ($changeLangId > 0) {
520: $options['changelang'] = $changeLangId;
521: }
522:
523: return cUri::getInstance()->build($options);
524: }
525: }
526: