Overview

Packages

  • CONTENIDO
  • Core
    • Authentication
    • Backend
    • Cache
    • CEC
    • Chain
    • ContentType
    • Database
    • Debug
    • Exception
    • Frontend
      • Search
      • URI
      • Util
    • GenericDB
      • Model
    • GUI
      • HTML
    • I18N
    • LayoutHandler
    • Log
    • Security
    • Session
    • Util
    • Validation
    • Versioning
    • XML
  • Module
    • ContentSitemapHtml
    • ContentSitemapXml
    • ContentUserForum
    • NavigationTop
    • ScriptCookieDirective
  • mpAutoloaderClassMap
  • None
  • PHP
  • Plugin
    • ContentAllocation
    • CronjobOverview
    • FormAssistant
    • FrontendLogic
    • FrontendUsers
    • Linkchecker
    • ModRewrite
    • Newsletter
    • Repository
      • FrontendNavigation
      • KeywordDensity
    • SIWECOS
    • SmartyWrapper
    • UrlShortener
    • UserForum
    • Workflow
  • PluginManager
  • Setup
    • Form
    • GUI
    • Helper
      • Environment
      • Filesystem
      • MySQL
      • PHP
    • UpgradeJob

Classes

  • cCodeGeneratorAbstract
  • cCodeGeneratorFactory
  • cCodeGeneratorStandard
  • cContentTypeAbstract
  • cContentTypeAbstractTabbed
  • cContentTypeDate
  • cContentTypeFilelist
  • cContentTypeHead
  • cContentTypeHtml
  • cContentTypeHtmlhead
  • cContentTypeImg
  • cContentTypeImgdescr
  • cContentTypeImgeditor
  • cContentTypeLink
  • cContentTypeLinkdescr
  • cContentTypeLinkeditor
  • cContentTypeLinktarget
  • cContentTypeRaw
  • cContentTypeTeaser
  • cContentTypeText
  • cTypeGenerator
  • Overview
  • Package
  • Class
  • Tree
  • Deprecated
  • Todo
  1: <?php
  2: 
  3: /**
  4:  * This file contains content type generator class.
  5:  * TODO: This class needs more documentation.
  6:  *
  7:  * @package Core
  8:  * @subpackage ContentType
  9:  * @author Alexander Scheider
 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:  * This class generates content types.
 20:  *
 21:  * @package Core
 22:  * @subpackage ContentType
 23:  */
 24: class cTypeGenerator {
 25: 
 26:     /**
 27:      *
 28:      * @var array
 29:      */
 30:     private $cfg = NULL;
 31: 
 32:     /**
 33:      *
 34:      * @var cDb
 35:      */
 36:     private static $db = NULL;
 37: 
 38:     /**
 39:      *
 40:      * @var array
 41:      */
 42:     private static $a_content = array();
 43: 
 44:     /**
 45:      *
 46:      * @var int
 47:      */
 48:     private $_idart = NULL;
 49: 
 50:     /**
 51:      *
 52:      * @var int
 53:      */
 54:     private $_idlang = NULL;
 55: 
 56:     /**
 57:      * Constructor to create an instance of this class.
 58:      *
 59:      * @throws cDbException
 60:      */
 61:     public function __construct() {
 62:         $this->_idart = cRegistry::getArticleId(true);
 63:         $this->_idlang = cRegistry::getLanguageId();
 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
 78:      *         Content type, e.g. CMS_HTMLHEAD
 79:      * @return string
 80:      *         The classname e.g. cContentTypeHtmlhead for content type CMS_HTMLHEAD
 81:      */
 82:     protected function _getContentTypeClassName($type) {
 83:         $typeClassName = 'cContentType' . ucfirst(cString::toLowerCase(str_replace('CMS_', '', $type)));
 84:         return $typeClassName;
 85:     }
 86: 
 87:     /**
 88:      *
 89:      * @param string $type
 90:      * @return string
 91:      */
 92:     public static function getContentTypeClassName($type)  {
 93:         $contentType = cString::getPartOfString($type, 4);
 94:         return 'cContentType' . cString::toUpperCase($contentType[0]) . cString::toLowerCase(cString::getPartOfString($contentType, 1));
 95:     }
 96: 
 97:     /**
 98:      * Returns the full path to the include file name of a content type.
 99:      *
100:      * @param string $type
101:      *         Content type, e.g. CMS_HTMLHEAD
102:      * @return string
103:      *         The full path e.g.
104:      *         {path_to_contenido_includes}/type/code/include.CMS_HTMLHEAD.code.php
105:      *         for content type CMS_HTMLHEAD
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:      * Fill content from db for current article
115:      *
116:      * @throws cDbException
117:      */
118:     private function fillContent() {
119:         self::$a_content[$this->_idart] = array();
120: 
121:         $sql = "SELECT
122:                     *
123:                 FROM
124:                     " . $this->cfg["tab"]["content"] . " AS A,
125:                     " . $this->cfg["tab"]["art_lang"] . " AS B,
126:                     " . $this->cfg["tab"]["type"] . " AS C
127:                 WHERE
128:                     A.idtype    = C.idtype AND
129:                     A.idartlang = B.idartlang AND
130:                     B.idart     = '" . cSecurity::toInteger($this->_idart) . "' AND
131:                     B.idlang    = '" . cSecurity::toInteger($this->_idlang) . "'";
132: 
133:         self::$db->query($sql);
134: 
135:         while (self::$db->next_record()) {
136:             self::$a_content[$this->_idart][self::$db->f("type")][self::$db->f("typeid")] = self::$db->f("value");
137:         }
138:     }
139: 
140:     /**
141:      *
142:      * @param string $type
143:      * @param int    $index
144:      *
145:      * @return string
146:      *
147:      * @throws cDbException
148:      * @throws cException
149:      */
150:     private function _processCmsTags($type, $index) {
151:         $oTypeColl = new cApiTypeCollection();
152:         $oTypeColl->select();
153: 
154:         $typeList = array();
155:         while (false !== $oType = $oTypeColl->next()) {
156:             $typeList[] = $oType->toObject();
157:         }
158: 
159:         // Replace all CMS_TAGS[]
160:         foreach ($typeList as $typeItem) {
161: 
162:             if ($type === $typeItem->type) {
163: 
164:                 $items[] = $typeItem->type;
165: 
166:                 $typeClassName = $this->_getContentTypeClassName($typeItem->type);
167:                 $typeCodeFile = $this->_getContentTypeCodeFilePathName($typeItem->type);
168: 
169:                 $cTypeObject = new $typeClassName(self::$a_content[$this->_idart][$typeItem->type][$index], $index, $items);
170:                 if (cRegistry::isBackendEditMode()) {
171:                     $tmp = $cTypeObject->generateEditCode();
172:                 } else {
173:                     $tmp = $cTypeObject->generateViewCode();
174:                 }
175: 
176:                 return $tmp;
177:             }
178:         }
179:     }
180: 
181:     /**
182:      * Helper function to call a private function
183:      *
184:      * @param string $type
185:      * @param int    $index
186:      *
187:      * @return string
188:      *
189:      * @throws cDbException
190:      * @throws cException
191:      */
192:     public function getGeneratedCmsTag($type, $index) {
193:         return $this->_processCmsTags($type, $index);
194:     }
195: }
196: 
CMS CONTENIDO 4.10.1 API documentation generated by ApiGen 2.8.0