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
    • ContentRssCreator
    • ContentSitemapHtml
    • ContentSitemapXml
    • ContentUserForum
    • NavigationTop
    • ScriptCookieDirective
  • mpAutoloaderClassMap
  • None
  • Plugin
    • ContentAllocation
    • CronjobOverview
    • FormAssistant
    • FrontendLogic
    • FrontendUsers
    • Linkchecker
    • ModRewrite
    • Newsletter
    • Repository
      • FrontendNavigation
      • KeywordDensity
    • SearchSolr
    • SmartyWrapper
    • UrlShortener
    • UserForum
    • Workflow
  • PluginManager
  • Setup
    • Form
    • GUI
    • Helper
      • Environment
      • Filesystem
      • MySQL
      • PHP
    • UpgradeJob

Classes

  • cTinyMCE4List
  • Overview
  • Package
  • Class
  • Tree
  • Deprecated
  • Todo
  1: <?php
  2: /**
  3:  * Project:
  4:  * CONTENIDO Content Management System
  5:  *
  6:  * Description:
  7:  * TINYMCE 4 PHP WYSIWYG interface
  8:  * Generates file/link list for editor
  9:  *
 10:  * Requirements:
 11:  * @con_php_req 5.3
 12:  * @con_notice
 13:  * TINYMCE 4 Fileversion
 14:  *
 15:  * @package    CONTENIDO Backend Editor
 16:  * @version    0.0.1
 17:  * @author     Thomas Stauer
 18:  * @copyright  four for business AG <www.4fb.de>
 19:  * @license    http://www.contenido.org/license/LIZENZ.txt
 20:  * @link       http://www.4fb.de
 21:  * @link       http://www.contenido.org
 22:  */
 23: 
 24: if (!defined('CON_FRAMEWORK')) {
 25:     define('CON_FRAMEWORK', true);
 26: }
 27: 
 28: // CONTENIDO startup process
 29: $contenido_path = str_replace('\\', '/', realpath(dirname(__FILE__) . '/../../../../../')) . '/';
 30: 
 31: if (!is_file($contenido_path . 'includes/startup.php')) {
 32:     die("<h1>Fatal Error</h1><br>Couldn't include CONTENIDO startup.");
 33: }
 34: include_once($contenido_path . 'includes/startup.php');
 35: 
 36: cRegistry::bootstrap(array(
 37:     'sess' => 'cSession',
 38:     'auth' => 'cAuthHandlerBackend',
 39:     'perm' => 'cPermission'
 40: ));
 41: 
 42: // include editor config/combat file
 43: include(dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR . 'config.php');
 44: 
 45: $db = cRegistry::getDb();
 46: 
 47: cInclude('includes', 'functions.lang.php');
 48: 
 49: $mediaList = new cTinyMCE4List($_GET['mode']);
 50: 
 51: /**
 52:  */
 53: class cTinyMCE4List {
 54: 
 55:     /**
 56:      * @param string|null $mode
 57:      */
 58:     public function __construct($mode = null) {
 59:         // output an empty list for no specified mode
 60:         if (false === isset($mode)) {
 61:             echo '[]';
 62:             return;
 63:         }
 64: 
 65:         $list = array();
 66:         // process defined list modes
 67:         switch ($mode) {
 68:             case 'image':
 69:                 $list = $this->_buildImageList();
 70:                 break;
 71:             case 'link':
 72:                 $list = $this->_buildLinkList();
 73:                 break;
 74:             default:
 75:                 // just output an empty list for unknown mode
 76:         }
 77: 
 78:         $this->_printList($list);
 79:     }
 80: 
 81:     /**
 82:      * get a list of images that is accessible for tinymce
 83:      * @return array The array of images filled with upload objects
 84:      */
 85:     private function _buildImageList() {
 86:         $client = cRegistry::getClientId();
 87:         $clientConfig = cRegistry::getClientConfig($client);
 88: 
 89:         // get needed data using cApiUploadCollection class
 90:         $oApiUploadCol = new cApiUploadCollection();
 91:         // get uploads for current client
 92:         // filetype can be either gif, jpg, jpeg or png
 93: 
 94:         $selectClause = "idclient='" . cSecurity::toInteger($client) . "' AND filetype IN ('gif', 'jpg', 'jpeg', 'png')";
 95:         $oApiUploadCol->select($selectClause, '', 'dirname, filename ASC');
 96:         // $oApiUploadCol->setWhere('idclient', cSecurity::toInteger($client));
 97:         // $oApiUploadCol->setWhere('filetype', array('gif', 'jpg', 'jpeg', 'png'), 'IN');
 98:         // $oApiUploadCol->setOrder('dirname, filename ASC');
 99:         // $oApiUploadCol->query();
100:         $aUplList = $oApiUploadCol->fetchArray($oApiUploadCol->getPrimaryKeyName(), array('idclient', 'dirname', 'filetype', 'filename'));
101: 
102:         $imageList = array();
103:         foreach ($aUplList as $uplItem) {
104:             $imageItem = new stdClass();
105:             $imageItem->title = $uplItem['dirname'] . $uplItem['filename'];
106:             $imageItem->value = $clientConfig['upload'] . $uplItem['dirname'] . $uplItem['filename'];
107: 
108:             $imageList[] = $imageItem;
109:         }
110: 
111:         return $imageList;
112:     }
113: 
114:     /**
115:      * This function helps adding the category entries to the wood according to their deepness level
116:      * @param array $woodTree
117:      * @param int $lvl The level where entry should be inserted into wood. Level 0 means we enter a tree to the wood.
118:      * @param stdClass $entry The entry to add into the wood.
119:      * @return array The altered woodTree with newly inserted entry at the correct level.
120:      */
121:     private function _addToWoodTree($woodTree, $lvl, $entry) {
122:         // add to wood if its a tree root
123:         if ($lvl === 0) {
124:             $woodTree[] = $entry;
125:             return $woodTree;
126:         }
127: 
128:         // get copy of catTree
129:         $res = unserialize(serialize($woodTree));
130: 
131:         // use pseudo-reference to manipulate result in-place
132:         $scope = &$res;
133:         for ($i = $lvl; $i > 0; $i--) {
134:             // set pointer to last element of array
135:             end($scope);
136:             // get reference to last element of array
137:             $scope = &$scope[key($scope)];
138:             // add menu property to object if it does not exist
139:             if (false === isset($scope->menu)) {
140:                 $scope->menu = array();
141:             }
142:             // get reference to menu
143:             $scope = &$scope->menu;
144:         }
145: 
146:         // add entry to scope
147:         // because scope is a reference the res variable is altered at the correct place, too
148:         $scope[] = $entry;
149: 
150:         // we're done
151:         return $res;
152: 
153:     }
154: 
155:     /**
156:      * get a list of links to articles for current client and language
157:      * @return array The array of articles filled with link objects
158:      */
159:     private function _buildLinkList() {
160:         global $client, $lang;
161: 
162:         $linkList = array();
163: 
164:         $catTree = new cApiCategoryTreeCollection();
165:         $catList = $catTree->getCategoryTreeStructureByClientIdAndLanguageId($client, $lang);
166: 
167:         foreach ($catList as $catEntry) {
168:             $tmp_catname = $catEntry['name'];
169:             if ($catEntry['visible'] == 0) {
170:                 $tmp_catname = "[" . $tmp_catname . "]";
171:             }
172:             $listEntry = (object) array('title' => $tmp_catname,
173:                                         'value' => 'front_content.php?idcat=' . $catEntry['idcat']);
174: 
175:             $linkList = $this->_addToWoodTree($linkList, (int) $catEntry['level'], $listEntry);
176: 
177:             $options = array();
178:             $options['idcat'] = $catEntry['idcat'];
179:             // order by title
180:             $options['order'] = 'title';
181:             // order ascending
182:             $options['direction'] = 'asc';
183:             // include start articles
184:             $options['start'] = true;
185:             // show offline articles
186:             $options['offline'] = true;
187: 
188: 
189:             // create cArticleCollector instance with specified options
190:             $articleCollector = new cArticleCollector($options);
191: 
192:             // add subcategories to communicate category structure
193:             if (0 === count($articleCollector)) {
194:                 continue;
195:             }
196: 
197:             $listEntry->menu = array();
198:             $listEntry->menu[] = (object) array('title' => $tmp_catname . ' ' . i18n('Category'),
199:                                                 'value' => 'front_content.php?idcat=' . $catEntry['idcat']
200:             );
201: 
202:             foreach ($articleCollector as $articleLanguage) {
203:                 $tmp_title = $articleLanguage->get("title");
204: 
205:                 if (strlen($tmp_title) > 32) {
206:                     $tmp_title = substr($tmp_title, 0, 32);
207:                 }
208: 
209:                 $is_start = isStartArticle($articleLanguage->get('idartlang'), $catEntry['idcat'], $lang);
210: 
211:                 if ($is_start) {
212:                     $tmp_title .= "*";
213:                 }
214: 
215:                 if ('0' === $articleLanguage->get("online")) {
216:                     $tmp_title = "[" . $tmp_title . "]";
217:                 }
218:                 $articleEntry = new stdClass();
219:                 $articleEntry->title = $tmp_title;
220:                 $articleEntry->value = 'front_content.php?idart=' . $articleLanguage->get('idart');
221:                 $listEntry->menu[] = $articleEntry;
222:             }
223:         }
224:         return $linkList;
225:     }
226: 
227:     /**
228:      * Output the created list as JSON.
229:      */
230:     private function _printList($list) {
231:         echo json_encode($list);
232:     }
233: }
234: ?>
CMS CONTENIDO 4.9.11 API documentation generated by ApiGen 2.8.0