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