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