1: <?php
2: /**
3: * This file contains content type generator class.
4: * TODO: This class needs more documentation.
5: *
6: * @package Core
7: * @subpackage ContentType
8: * @version SVN Revision $Rev:$
9: *
10: * @author Alexander Scheider
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: * This class generates content types.
21: *
22: * @package Core
23: * @subpackage ContentType
24: */
25: class cTypeGenerator {
26:
27: /**
28: *
29: * @var $cfg
30: */
31: private $cfg = NULL;
32:
33: /**
34: *
35: * @var $db
36: */
37: private static $db = NULL;
38:
39: /**
40: *
41: * @var $a_content
42: */
43: private static $a_content = array();
44:
45: /**
46: *
47: * @var $_idart
48: */
49: private $_idart = NULL;
50:
51: /**
52: *
53: * @var $_idlang
54: */
55: private $_idlang = NULL;
56:
57: /**
58: * Constructor function
59: */
60: public function __construct() {
61:
62: $this->_idart = cRegistry::getArticleId(true);
63: $this->_idlang = cRegistry::getLanguageId(true);
64: $this->cfg = cRegistry::getConfig();
65:
66: if (self::$db === null) {
67: self::$db = cRegistry::getDb();
68: }
69: if (!isset(self::$a_content[$this->_idart])) {
70: $this->fillContent();
71: }
72: }
73:
74: /**
75: * Returns the classname for a content type.
76: *
77: * @param string $type Content type, e. g. CMS_HTMLHEAD
78: * @return string The classname e. g. cContentTypeHtmlhead for content type
79: * CMS_HTMLHEAD
80: */
81: protected function _getContentTypeClassName($type) {
82: $typeClassName = 'cContentType' . ucfirst(strtolower(str_replace('CMS_', '', $type)));
83: return $typeClassName;
84: }
85:
86: /**
87: * Returns the full path to the include file name of a content type.
88: *
89: * @param string $type Content type, e. g. CMS_HTMLHEAD
90: * @return string The full path e. g.
91: * {path_to_contenido_includes}/type/code/include.CMS_HTMLHEAD.code.php
92: * for content type CMS_HTMLHEAD
93: */
94: protected function _getContentTypeCodeFilePathName($type) {
95: global $cfg;
96: $typeCodeFile = cRegistry::getBackendPath() . $cfg['path']['includes'] . 'type/code/include.' . $type . '.code.php';
97: return $typeCodeFile;
98: }
99:
100: /**
101: * Fill content from db for current article
102: */
103: private function fillContent() {
104: self::$a_content[$this->_idart] = array();
105:
106: $sql = "SELECT
107: *
108: FROM
109: " . $this->cfg["tab"]["content"] . " AS A,
110: " . $this->cfg["tab"]["art_lang"] . " AS B,
111: " . $this->cfg["tab"]["type"] . " AS C
112: WHERE
113: A.idtype = C.idtype AND
114: A.idartlang = B.idartlang AND
115: B.idart = '" . cSecurity::toInteger($this->_idart) . "' AND
116: B.idlang = '" . cSecurity::toInteger($this->_idlang) . "'";
117:
118: self::$db->query($sql);
119:
120: while (self::$db->next_record()) {
121: self::$a_content[$this->_idart][self::$db->f("type")][self::$db->f("typeid")] = self::$db->f("value");
122: }
123: }
124:
125: /**
126: *
127: * @param string $type
128: * @param int $index
129: */
130: private function _processCmsTags($type, $index) {
131: $_typeList = array();
132: $oTypeColl = new cApiTypeCollection();
133: $oTypeColl->select();
134: while ($oType = $oTypeColl->next()) {
135: $_typeList[] = $oType->toObject();
136: }
137:
138: // Replace all CMS_TAGS[]
139: foreach ($_typeList as $_typeItem) {
140:
141: if ($type === $_typeItem->type) {
142:
143: $items[] = $_typeItem->type;
144:
145: $typeClassName = $this->_getContentTypeClassName($_typeItem->type);
146: $typeCodeFile = $this->_getContentTypeCodeFilePathName($_typeItem->type);
147: $cTypeObject = new $typeClassName(self::$a_content[$this->_idart][$_typeItem->type][$index], $index, $items);
148: if (cRegistry::isBackendEditMode()) {
149:
150: $tmp = $cTypeObject->generateEditCode();
151: } else {
152: $tmp = $cTypeObject->generateViewCode();
153: }
154:
155: return $tmp;
156: }
157: }
158: }
159:
160:
161: /**
162: * Helper function to call a private function
163: *
164: * @param string $type
165: * @param int $index
166: *
167: * @return array
168: */
169: public function getGeneratedCmsTag($type, $index) {
170: return $this->_processCmsTags($type, $index);
171: }
172:
173: }
174:
175: ?>