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

Functions

  • addArticlesToTree
  • getArticlesFromCategory
  • getStartIdArtLang
  • Overview
  • Package
  • Function
  • Tree
  • Deprecated
  • Todo
  1: <?php
  2: 
  3: /**
  4:  *
  5:  * @package Module
  6:  * @subpackage ContentSitemapHtml
  7:  * @author marcus.gnass@4fb.de
  8:  * @author alexander.scheider@4fb.de
  9:  * @copyright four for business AG
 10:  * @link http://www.4fb.de
 11:  */
 12: 
 13: // get globals
 14: $client = cRegistry::getClientId();
 15: $lang = cRegistry::getLanguageId();
 16: $idart = cRegistry::getArticleId();
 17: 
 18: // get content of current article
 19: $artLang = new cApiArticleLanguage();
 20: $artLang->loadByArticleAndLanguageId($idart, $lang);
 21: 
 22: $content = $artLang->getContent('CMS_TEXT', 1);
 23: $level = $artLang->getContent('CMS_TEXT', 2);
 24: $article = $artLang->getContent('CMS_TEXT', 3);
 25: 
 26: // get smarty template instance
 27: $tpl = cSmartyFrontend::getInstance();
 28: $tpl->assign('isBackendEditMode', cRegistry::isBackendEditMode());
 29: 
 30: // assign module translations
 31: $tpl->assign('trans', [
 32:     'headline' => mi18n("HEADLINE"),
 33:     'categoryLabel' => mi18n("CATEGORY_LABEL"),
 34:     'levelLabel' => mi18n("LEVEL_LABEL"),
 35:     'articleLabel' => mi18n("ARTICLE_LABEL"),
 36:     'articleHintLabel' => mi18n("ARTICLE_HINT_LABEL"),
 37:     'categoryHintLabel' => mi18n("GATEGORY_HINT_LABEL"),
 38:     'levelHintLabel' => mi18n("LEVEL_HINT_LABEL")
 39: ]);
 40: 
 41: // assign CMS input fields
 42: $tpl->assign('category', "CMS_TEXT[1]");
 43: $tpl->assign('level', "CMS_TEXT[2]");
 44: $tpl->assign('article', "CMS_TEXT[3]");
 45: $tpl->assign('first', false);
 46: 
 47: // check if content is numeric
 48: if (false === is_numeric($content) || false === is_numeric($level)) {
 49:     $tpl->assign('error', mi18n("NOT_NUMERIC_VALUE"));
 50: } else if ($article != 0 && $article != 1) {
 51:     $tpl->assign('error', mi18n("NOT_ZERO_OR_ONE"));
 52: } else {
 53:     // get category tree
 54:     $categoryHelper = cCategoryHelper::getInstance();
 55:     $categoryHelper->setAuth(cRegistry::getAuth());
 56:     $tree = $categoryHelper->getSubCategories($content, $level);
 57:     if (1 == $article) {
 58:         $tree = addArticlesToTree($tree);
 59:     }
 60:     $tpl->assign('tree', $tree);
 61: }
 62: 
 63: $tpl->display('get.tpl');
 64: 
 65: /**
 66:  * Adds articles to categories in given array $tree as returned by
 67:  * cCategoryHelper->getSubCategories().
 68:  *
 69:  * @param array $tree
 70:  * @return array
 71:  */
 72: function addArticlesToTree(array $tree) {
 73:     $startIdArtLang = getStartIdArtLang();
 74: 
 75:     foreach ($tree as $key => $wrapper) {
 76:         $tree[$key]['articles'] = getArticlesFromCategory($wrapper['idcat'], $startIdArtLang);
 77:         $tree[$key]['subcats'] = addArticlesToTree($tree[$key]['subcats']);
 78:     }
 79: 
 80:     return $tree;
 81: }
 82: 
 83: /**
 84:  * Read the IDs of all article languages that are used as start article
 85:  * of their respective category.
 86:  *
 87:  * @return array
 88:  *         of article language IDs
 89:  */
 90: function getStartIdArtLang() {
 91:     $cfg = cRegistry::getConfig();
 92:     $db = cRegistry::getDb();
 93: 
 94:     // get all startidartlangs
 95:     $ret = $db->query('-- getStartIdArtLang()
 96:         SELECT
 97:             startidartlang
 98:         FROM
 99:             `' . $cfg['tab']['cat_lang'] . '`
100:         WHERE
101:             visible = 1
102:             AND public = 1
103:         ;');
104: 
105:     $result = [];
106:     while ($db->nextRecord()) {
107:         $result[] = $db->f('startidartlang');
108:     }
109: 
110:     return $result;
111: }
112: 
113: /**
114:  * Read article languages of given category and the current language.
115:  * Only online articles that are searchable are considered.
116:  * Optionally an array of article language IDs to exclude can be given.
117:  * If no article languages were found an empty array will be returned.
118:  *
119:  * @param int $idcat
120:  *         ID of category to search in
121:  * @param array $excludedIdArtLangs [optional]
122:  *         ID of article languages to exclude
123:  * @return array
124:  *         of article languages
125:  */
126: function getArticlesFromCategory($idcat, array $excludedIdArtLangs = []) {
127:     $cfg = cRegistry::getConfig();
128:     $db = cRegistry::getDb();
129:     $idlang = cRegistry::getLanguageId();
130: 
131:     $ret = $db->query('-- getArticlesFromCategory()
132:         SELECT
133:             art_lang.idartlang
134:         FROM
135:             `' . $cfg['tab']['art_lang'] . '` AS art_lang,
136:             `' . $cfg['tab']['cat_art'] . '` AS cat_art
137:         WHERE
138:             art_lang.idart = cat_art.idart
139:             AND art_lang.idlang = ' . cSecurity::toInteger($idlang) . '
140:             AND art_lang.online = 1
141:             AND art_lang.searchable = 1
142:             AND cat_art.idcat = ' . cSecurity::toInteger($idcat) . '
143:         ;');
144: 
145:     if (false === $ret) {
146:         return [];
147:     }
148: 
149:     $result = [];
150:     while ($db->nextRecord()) {
151:         // skip article languages to exclude
152:         if (in_array($db->f('idartlang'), $excludedIdArtLangs)) {
153:             continue;
154:         }
155: 
156:         // add article languages to result
157:         $result[] = new cApiArticleLanguage($db->f('idartlang'));
158:     }
159: 
160:     return $result;
161: }
162: 
163: ?>
CMS CONTENIDO 4.10.1 API documentation generated by ApiGen 2.8.0