1: <?php
2:
3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14:
15:
16: defined('CON_FRAMEWORK') || die('Illegal call: Missing framework initialization - request aborted.');
17:
18: 19: 20: 21: 22: 23:
24: class cTypeGenerator {
25:
26: 27: 28: 29:
30: private $cfg = NULL;
31:
32: 33: 34: 35:
36: private static $db = NULL;
37:
38: 39: 40: 41:
42: private static $a_content = array();
43:
44: 45: 46: 47:
48: private $_idart = NULL;
49:
50: 51: 52: 53:
54: private $_idlang = NULL;
55:
56: 57: 58:
59: public function __construct() {
60: $this->_idart = cRegistry::getArticleId(true);
61: $this->_idlang = cRegistry::getLanguageId();
62: $this->cfg = cRegistry::getConfig();
63:
64: if (self::$db === NULL) {
65: self::$db = cRegistry::getDb();
66: }
67: if (!isset(self::$a_content[$this->_idart])) {
68: $this->fillContent();
69: }
70: }
71:
72: 73: 74: 75: 76: 77: 78: 79:
80: protected function _getContentTypeClassName($type) {
81: $typeClassName = 'cContentType' . ucfirst(strtolower(str_replace('CMS_', '', $type)));
82: return $typeClassName;
83: }
84:
85: 86: 87: 88: 89:
90: public static function getContentTypeClassName($type) {
91: $contentType = substr($type, 4);
92: return 'cContentType' . strtoupper($contentType[0]) . strtolower(substr($contentType, 1));
93: }
94:
95: 96: 97: 98: 99: 100: 101: 102: 103: 104:
105: protected function _getContentTypeCodeFilePathName($type) {
106: global $cfg;
107: $typeCodeFile = cRegistry::getBackendPath() . $cfg['path']['includes'] . 'type/code/include.' . $type . '.code.php';
108: return $typeCodeFile;
109: }
110:
111: 112: 113:
114: private function fillContent() {
115: self::$a_content[$this->_idart] = array();
116:
117: $sql = "SELECT
118: *
119: FROM
120: " . $this->cfg["tab"]["content"] . " AS A,
121: " . $this->cfg["tab"]["art_lang"] . " AS B,
122: " . $this->cfg["tab"]["type"] . " AS C
123: WHERE
124: A.idtype = C.idtype AND
125: A.idartlang = B.idartlang AND
126: B.idart = '" . cSecurity::toInteger($this->_idart) . "' AND
127: B.idlang = '" . cSecurity::toInteger($this->_idlang) . "'";
128:
129: self::$db->query($sql);
130:
131: while (self::$db->next_record()) {
132: self::$a_content[$this->_idart][self::$db->f("type")][self::$db->f("typeid")] = self::$db->f("value");
133: }
134: }
135:
136: 137: 138: 139: 140: 141:
142: private function _processCmsTags($type, $index) {
143: $oTypeColl = new cApiTypeCollection();
144: $oTypeColl->select();
145:
146: $typeList = array();
147: while (false !== $oType = $oTypeColl->next()) {
148: $typeList[] = $oType->toObject();
149: }
150:
151:
152: foreach ($typeList as $typeItem) {
153:
154: if ($type === $typeItem->type) {
155:
156: $items[] = $typeItem->type;
157:
158: $typeClassName = $this->_getContentTypeClassName($typeItem->type);
159: $typeCodeFile = $this->_getContentTypeCodeFilePathName($typeItem->type);
160:
161: $cTypeObject = new $typeClassName(self::$a_content[$this->_idart][$typeItem->type][$index], $index, $items);
162: if (cRegistry::isBackendEditMode()) {
163: $tmp = $cTypeObject->generateEditCode();
164: } else {
165: $tmp = $cTypeObject->generateViewCode();
166: }
167:
168: return $tmp;
169: }
170: }
171: }
172:
173: 174: 175: 176: 177: 178: 179: 180:
181: public function getGeneratedCmsTag($type, $index) {
182: return $this->_processCmsTags($type, $index);
183: }
184: }
185: