Overview

Packages

  • Core
    • Authentication
    • Backend
    • Cache
    • CEC
    • Chain
    • ContentType
    • Database
    • Datatype
    • Debug
    • Exception
    • Frontend
      • Search
      • URI
      • Util
    • GenericDB
      • Model
    • GUI
      • HTML
    • I18N
    • LayoutHandler
    • Log
    • Security
    • Session
    • Util
    • Validation
    • Versioning
    • XML
  • Module
    • ContentSitemapHtml
    • ContentSitemapXml
    • ContentUserForum
    • NavigationTop
  • 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

  • pApiContentAllocation
  • pApiContentAllocationArticle
  • pApiContentAllocationComplexList
  • pApiContentAllocationSelectBox
  • pApiContentAllocationTreeView
  • pApiTree

Functions

  • pica_ArticleListActions
  • pica_GetCustomTabProperties
  • pica_RegisterCustomTab
  • pica_RenderArticleAction
  • Overview
  • Package
  • Class
  • Tree
  • Deprecated
  • Todo
  1: <?php
  2: /**
  3:  * This file contains the tree class for the plugin content allocation.
  4:  *
  5:  * @package    Plugin
  6:  * @subpackage ContentAllocation
  7:  * @version    SVN Revision $Rev:$
  8:  *
  9:  * @author     Marco Jahn
 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: plugin_include('repository', 'custom/FrontendNavigation.php');
 19: 
 20: /**
 21:  * Tree class for content allocation
 22:  *
 23:  * @package    Plugin
 24:  * @subpackage ContentAllocation
 25:  */
 26: class pApiTree {
 27: 
 28:     /**
 29:      *
 30:      * Contenido DB
 31:      * @var cDb
 32:      */
 33:     var $db = NULL;
 34: 
 35:     /**
 36:      *
 37:      */
 38:     var $table = NULL;
 39: 
 40:     /**
 41:      *
 42:      */
 43:     var $lang = 1;
 44: 
 45:     /**
 46:      *
 47:      */
 48:     var $client = 1;
 49: 
 50:     /**
 51:      *
 52:      */
 53:     var $defaultLang = 1;
 54: 
 55:     /**
 56:      *
 57:      */
 58:     var $logger = NULL;
 59: 
 60:     /**
 61:      *
 62:      */
 63:     var $user = NULL;
 64: 
 65:     /**
 66:      *
 67:      */
 68:     var $treeStatus = array();
 69: 
 70:     /**
 71:      *
 72:      */
 73:     var $uuid = NULL;
 74: 
 75:     /**
 76:      *
 77:      */
 78:     var $_arrInFilters = array('htmlspecialchars', 'addslashes');
 79: 
 80:     /**
 81:      *
 82:      */
 83:     var $_arrOutFilters = array('stripslashes', 'htmldecode');
 84: 
 85:     function pApiTree ($uuid) {
 86:         global $db, $cfg, $lang, $client, $auth;
 87: 
 88:         $this->db = cRegistry::getDb();
 89:         $this->table = $cfg['tab'];
 90:         $this->lang = $lang;
 91:         $this->client = $client;
 92:         $this->bDebug = false;
 93: 
 94:         $this->uuid = $uuid;
 95: 
 96:         $this->user =  new cApiUser($auth->auth["uid"]);
 97:         $this->loadTreeStatus();
 98:     }
 99: 
100:     /**
101:      *
102:      * @param mixed $parentId
103:      * @param int $level
104:      * @param bool $bUseTreeStatus (if true use expand/collapsed status of the tree, otherwise not)
105:      * @modified 27.10.2005 Willi Man
106:      */
107:     function fetchTree ($parentId = false, $level = 0, $bUseTreeStatus = true) {
108: 
109:         // fetch current lang category
110:         $sql = "SELECT
111:                     tree.idpica_alloc, tree.parentid, tree.sortorder
112:                 FROM
113:                     " . $this->table['pica_alloc'] . " as tree";
114: 
115:         if ($parentId === false) { // fetch from root node
116:             $sql .= " WHERE tree.parentid = '0'";
117:         } else { // fetch by given id
118:             $sql .= " WHERE tree.parentid = " . cSecurity::toInteger($parentId);
119:         }
120: 
121:         $sql .= " ORDER BY sortorder ASC";
122: 
123:         $this->db->query($sql);
124: 
125:         $result_tmp = array(); // tmp result array
126:         while ($this->db->nextRecord()) { // walk resultset
127:             $item = $this->_fetchItemNameLang($this->db->f('idpica_alloc'));
128: 
129:             $itemStatus = 'expanded';
130: 
131:             if ($bUseTreeStatus) # modified 27.10.2005
132:             {
133:                 if (is_array($this->treeStatus) && array_key_exists($this->db->f('idpica_alloc'), $this->treeStatus))
134:                 {
135:                     $itemStatus = 'collapsed';
136:                 }
137:             }
138: 
139:             $rs = array(
140:                 'idpica_alloc' => $this->db->f('idpica_alloc'),
141:                 'parentid' => ($this->db->f('parentid') == NULL) ? false : $this->db->f('parentid'),
142:                 'sortorder' => $this->db->f('sortorder'),
143:                 'name' => $this->_outFilter($item['name']),
144:                 'idlang' => $item['idlang'],
145:                 'level' => $level,
146:                 'status' => $itemStatus,
147:                 'online' => $item['online']
148:             );
149: 
150:             array_push($result_tmp, $rs); // append recordset
151:         }
152: 
153:         if (count($result_tmp) > 0) {
154:             $result = array(); // result array
155:             foreach ($result_tmp as $rs) { // run results
156:                 $children = $this->fetchTree($rs['idpica_alloc'], $level + 1, $bUseTreeStatus);
157:                 if ($children !== false && $rs['status'] == 'expanded') {
158:                     $rs['children'] = $children;
159:                 }
160:                 array_push($result, $rs);
161:             }
162:             return $result;
163:         } else
164:         {
165:             return false;
166:         }
167:     }
168: 
169:     /**
170:      * Fetch ContentAllocation tree
171:      * Consider offline/online status
172:      *
173:      * @created 21.11.2005 Willi Man
174:      *
175:      * @param mixed $parentId
176:      * @param int $level
177:      * @return array with ContentAllocation id's
178:      */
179:     function fetchTreeIds ($parentId = false, $level = 0, $showOffline = false) {
180: 
181:         // fetch current lang category
182:         $sql = "SELECT
183:                     tree.idpica_alloc, tree.parentid, tree.sortorder
184:                 FROM
185:                     " . $this->table['pica_alloc'] . " as tree";
186: 
187:         if ($parentId === false) { // fetch from root node
188:             $sql .= " WHERE tree.parentid IS NULL";
189:         } else { // fetch by given id
190:             $sql .= " WHERE tree.parentid = " . cSecurity::toInteger($parentId);
191:         }
192: 
193:         $sql .= " ORDER BY sortorder ASC";
194: 
195:         if ($this->bDebug) {print "<!-- "; print $sql; print " -->";}
196: 
197:         $this->db->query($sql);
198: 
199:         $result_tmp = array(); // tmp result array
200:         while ($this->db->nextRecord()) { // walk resultset
201: 
202:             $item = $this->_fetchItemNameLang($this->db->f('idpica_alloc'));
203: 
204:             if ($showOffline OR $item['online'] == 1)
205:             {
206:                 $rs = array(
207:                     'idpica_alloc' => $this->db->f('idpica_alloc')
208:                 );
209: 
210:                 array_push($result_tmp, $rs); // append recordset
211:             }
212:         }
213: 
214:         if (count($result_tmp) > 0) {
215:             $result = array(); // result array
216:             foreach ($result_tmp as $rs) { // run results
217:                 $children = $this->fetchTreeIds($rs['idpica_alloc'], $level + 1, $showOffline);
218:                 if ($children !== false) {
219:                     $rs['children'] = $children;
220:                 }
221:                 array_push($result, $rs);
222:             }
223:             return $result;
224:         } else
225:         {
226:             return false;
227:         }
228:     }
229: 
230:     function setTreeStatus($idpica_alloc) {
231:         $idpica_alloc = cSecurity::toInteger($idpica_alloc);
232:         if (is_array($this->treeStatus) && array_key_exists($idpica_alloc, $this->treeStatus)) { // expand
233:             unset($this->treeStatus[$idpica_alloc]);
234:         } else { // collapse
235:             $this->treeStatus[$idpica_alloc] = true;
236:         }
237:         $this->user->setProperty("expandstate", $this->_uuid, serialize($this->treeStatus));
238:     }
239: 
240:     function loadTreeStatus () {
241:         $status = $this->user->getProperty("expandstate", $this->_uuid);
242:         if ($status !== false) {
243:             $this->treeStatus = unserialize($status);
244:         }
245:     }
246: 
247:     function fetchParent ($idpica_alloc) {
248:         $sql = "SELECT idpica_alloc FROM ".$this->table['pica_alloc']." WHERE parentId = " . cSecurity::toInteger($idpica_alloc);
249:         $this->db->query($sql);
250: 
251:         if ($this->db->nextRecord()) {
252:             return $this->fetchItem($this->db->f('idpica_alloc'));
253:         } else {
254:             return false;
255:         }
256:     }
257: 
258:     function fetchParents () {}
259: 
260:     function fetchLevel ($parentId = false, $showOffline = false) {
261:         // fetch current lang category
262:         $sql = "SELECT
263:                     tree.idpica_alloc, tree.parentid, tree.sortorder
264:                 FROM
265:                     " . $this->table['pica_alloc'] . " as tree
266:                 LEFT JOIN ".$this->table['pica_lang']." as treelang USING (idpica_alloc)";
267: 
268:         if ($parentId === false) { // fetch from root node
269:             $sql .= " WHERE tree.parentid IS NULL";
270:         } else { // fetch by given id
271:             $sql .= " WHERE tree.parentid = " . cSecurity::toInteger($parentId);
272:         }
273: 
274:         if ($showOffline === false) {
275:             $sql .= " AND treelang.online = 1";
276:         }
277: 
278:         $sql .= " ORDER BY sortorder ASC";
279: 
280:         $this->db->query($sql);
281: 
282:         $result_tmp = array(); // tmp result array
283:         while ($this->db->nextRecord()) { // walk resultset
284:             $item = $this->_fetchItemNameLang($this->db->f('idpica_alloc'));
285: 
286:             $itemStatus = 'expanded';
287:             if (is_array($this->treeStatus) && array_key_exists($this->db->f('idpica_alloc'), $this->treeStatus)) {
288:                 $itemStatus = 'collapsed';
289:             }
290: 
291:             $rs = array(
292:                 'idpica_alloc' => $this->db->f('idpica_alloc'),
293:                 'parentid' => ($this->db->f('parentid') == NULL) ? false : $this->db->f('parentid'),
294:                 'sortorder' => $this->db->f('sortorder'),
295:                 'name' => $this->_outFilter($item['name']),
296:                 'idlang' => $item['idlang'],
297:                 'level' => 0,
298:                 'status' => $itemStatus,
299:                 'online' => $item['online']
300:             );
301: 
302:             array_push($result_tmp, $rs); // append recordset
303:         }
304: 
305:         return $result_tmp;
306:     }
307: 
308:     function storeItem ($treeItem) {
309: 
310:         if (!$treeItem['idpica_alloc']) { // insert
311:             //$treeItem['idpica_alloc'] = $this->db->nextid($this->table['pica_alloc']);
312:             $treeItem['sortorder'] = $this->_fetchMaxOrder($treeItem['parentid']) + 1;
313: 
314:             if ($treeItem['parentid'] == 'root') {
315:                 $treeItem['parentid'] = 'NULL';
316:             }
317: 
318:             $treeItem['name'] = $this->_inFilter($treeItem['name']);
319: 
320:             $sql = "INSERT INTO " . $this->table['pica_alloc'] . "
321:                     (parentid, sortorder)
322:                     VALUES
323:                     (" . cSecurity::toInteger($treeItem['parentid']) . ", " . cSecurity::toInteger($treeItem['sortorder']) . ")";
324:             $this->db->query($sql);
325:             $treeItem['idpica_alloc'] = $this->db->getLastInsertedId();
326:             $sql = "INSERT INTO " . $this->table['pica_lang'] . "
327:                     (idpica_alloc, idlang, name)
328:                     VALUES
329:                     (" . cSecurity::toInteger($treeItem['idpica_alloc']) . ", " . cSecurity::toInteger($this->lang) . ", '" . $this->db->escape($treeItem['name']) . "')";
330:             $this->db->query($sql);
331: 
332:         } else { // update
333:             $treeItem['name'] = $this->_inFilter($treeItem['name']);
334: 
335:             $sql = "SELECT * FROM " . $this->table['pica_lang'] . " WHERE idpica_alloc = " . cSecurity::toInteger($treeItem['idpica_alloc']) . " AND idlang = " . cSecurity::toInteger($this->lang);
336:             $this->db->query($sql);
337: 
338:             if ($this->db->numRows() > 0) {
339:                 #Update existing translation
340:                 $sql = "UPDATE " . $this->table['pica_lang'] . " SET name = '" . $this->db->escape($treeItem['name']) . "' WHERE idpica_alloc = " . cSecurity::toInteger($treeItem['idpica_alloc']) . "
341:                         AND idlang = " . cSecurity::toInteger($this->lang);
342:             } else {
343:                 #Get current online status for item
344:                 $sql = "SELECT * FROM " . $this->table['pica_lang'] . " WHERE idpica_alloc = " . $treeItem['idpica_alloc'] . " ORDER BY idlang";
345:                 $this->db->query($sql);
346: 
347:                 if ($this->db->nextRecord()) {
348:                     $online_status = $this->db->f('online');
349:                 } else {
350:                     $online_status = 0;
351:                 }
352: 
353:                 #Insert new translation
354:                 $sql = "INSERT INTO " . $this->table['pica_lang'] . "(idpica_alloc, idlang, name, online) VALUES (".cSecurity::toInteger($treeItem['idpica_alloc']).", ".cSecurity::toInteger($this->lang).",
355:                         '".$this->db->escape($treeItem['name'])."', ".cSecurity::toInteger($online_status).")";
356:             }
357: 
358:             $this->db->query($sql);
359:         }
360: 
361:         return $treeItem;
362:     }
363: 
364:     function setOnline ($idpica_alloc) {
365:         $this->_switchOnOffline($idpica_alloc, 1);
366:     }
367: 
368:     function setOffline ($idpica_alloc) {
369:         $this->_switchOnOffline($idpica_alloc, 0);
370:     }
371: 
372:     function _switchOnOffline ($idpica_alloc, $status) {
373:         $sql = "UPDATE " . $this->table['pica_lang'] . " SET online = " . cSecurity::toInteger($status) . " WHERE idpica_alloc = " . cSecurity::toInteger($idpica_alloc) . "
374:                 AND idlang = " . cSecurity::toInteger($this->lang);
375:         $this->db->query($sql);
376:     }
377: 
378:     function itemMoveUp ($idpica_alloc) {
379:         $treeItem = $this->fetchItem($idpica_alloc);
380:         $treeItem_old = $treeItem;
381:         $treeItem['sortorder']--;
382: 
383:         if ($treeItem['sortorder'] < $treeItem_old['sortorder']) {
384:             if ($treeItem['sortorder'] >= 1) {
385:                 $this->_decreaseOrder($treeItem['parentid'], $treeItem_old['sortorder']);
386:                 $this->_increaseOrder($treeItem['parentid'], $treeItem['sortorder']);
387:             } else {
388:                 $treeItem['sortorder'] = $treeItem_old['sortorder'];
389:             }
390:         }
391: 
392:         $sql = "UPDATE " . $this->table['pica_alloc'] . " SET sortorder = " . $treeItem['sortorder'] . " WHERE idpica_alloc = " . cSecurity::toInteger($idpica_alloc);
393:         $this->db->query($sql);
394:     }
395: 
396:     function itemMoveDown () {}
397: 
398:     function deleteItem ($idpica_alloc) {
399:         $sql = "DELETE FROM " . $this->table['pica_alloc'] . " WHERE idpica_alloc = " . cSecurity::toInteger($idpica_alloc);
400:         $this->db->query($sql);
401: 
402:         $sql = "DELETE FROM " . $this->table['pica_lang'] . " WHERE idpica_alloc = " . cSecurity::toInteger($idpica_alloc);
403:         $this->db->query($sql);
404: 
405:         $sql = "DELETE FROM " . $this->table['pica_alloc_con'] . " WHERE idpica_alloc = " . cSecurity::toInteger($idpica_alloc);
406:         $this->db->query($sql);
407:     }
408: 
409:     function fetchItem ($idpica_alloc) {
410:         $sql = "SELECT parentid, sortorder FROM " . $this->table['pica_alloc'] . " WHERE idpica_alloc = " . $idpica_alloc;
411:         $this->db->query($sql);
412: 
413:         $item = $this->_fetchItemNameLang($idpica_alloc);
414: 
415:         if ($this->db->nextRecord()) {
416:             $row = array(
417:                 'idpica_alloc' => $idpica_alloc,
418:                 'parentid' => ($this->db->f('parentid') == NULL) ? false : $this->db->f('parentid'),
419:                 'sortorder' => $this->db->f('sortorder'),
420:                 'name' => $item['name'],
421:                 'idlang' => $item['idlang'],
422:                 'online' => $item['online']
423:             );
424:             return $row;
425:         } else {
426:             return false;
427:         }
428:     }
429: 
430:     function _fetchItemNameLang ($idpica_alloc) {
431:         $oDB = cRegistry::getDb(); // temp instance
432: 
433:         $sSQL = "SELECT name, idlang, online FROM " . $this->table['pica_lang'] . " WHERE idpica_alloc = " . cSecurity::toInteger($idpica_alloc) . " AND idlang = " . cSecurity::toInteger($this->lang);
434:         $oDB->query($sSQL);
435: 
436:         $aResult = array();
437:         if ($oDB->nextRecord()) { // item found for this language
438: 
439:             $aResult['name']   = $this->_outFilter($oDB->f('name'));
440:             $aResult['idlang'] = $oDB->f('idlang');
441:             $aResult['online'] = $oDB->f('online');
442: 
443:         } else { // no item in this language found
444:             // fetch alternative language name
445:             // HerrB, 2008-04-21: Get all translations, try to use defaultLang translation, use
446:             // first available, otherwise. Only using defaultLang results in "ghost" elements, if
447:             // created in a non-default language. See CON-110 for details.
448: 
449:             $sSQL = "SELECT name, idlang, online FROM " . $this->table['pica_lang'] . " WHERE idpica_alloc = " . cSecurity::toInteger($idpica_alloc) . " ORDER BY idlang";
450:             $oDB->query($sSQL);
451: 
452:             $aNames = array();
453:             while ($oDB->nextRecord()) {
454:                 $sKey = "k" . $oDB->f('idlang');
455: 
456:                 $aNames[$sKey]                 = array();
457:                 $aNames[$sKey]['name']        = $this->_outFilter($oDB->f('name'));
458:                 $aNames[$sKey]['idlang']    = $oDB->f('idlang');
459:                 $aNames[$sKey]['online']    = $oDB->f('online');
460:             }
461: 
462:             if ($aNames["k" . $this->defaultLang]) {
463:                 // defaultLang translation available
464:                 $aResult = $aNames["k" . $this->defaultLang];
465:             } else {
466:                 // no defaultLang translation available, use first in line (reset returns first element)
467:                 $aResult = reset($aNames);
468:             }
469:         }
470:         unset($oDB);
471:         unset($aNames);
472: 
473:         return $aResult;
474:     }
475: 
476:     function _fetchMaxOrder ($parentId = false) {
477: 
478:         if ($parentId == 'root') {
479:             $parentId = false;
480:         }
481: 
482:         $sql = "SELECT MAX(sortorder) as max FROM " . $this->table['pica_alloc'];
483:         if ($parentId === false) {
484:             $sql .= " WHERE parentid = 0";
485:         } else {
486:             $sql .= " WHERE parentid = " . cSecurity::toInteger($parentId);
487:         }
488:         $this->db->query($sql);
489:         if ($this->db->nextRecord()) {
490:             return $this->db->f('max');
491:         } else {
492:             return 0;
493:         }
494:     }
495: 
496:     function _decreaseOrder ($parentId = false, $fromOrder) {
497:         $sql = "UPDATE " . $this->table['pica_alloc'] . " SET sortorder = sortorder - 1 WHERE sortorder >= " . cSecurity::toInteger($fromOrder);
498:         if ($parentId === false) {
499:             $sql .= " AND parentid IS NULL";
500:         } else {
501:             $sql .= " AND parentid = " . cSecurity::toInteger($parentId);
502:         }
503:         $this->db->query($sql);
504:     }
505: 
506:     function _increaseOrder ($parentId = false, $fromOrder) {
507:         $sql = "UPDATE " . $this->table['pica_alloc'] . " SET sortorder = sortorder + 1 WHERE sortorder >= " . cSecurity::toInteger($fromOrder);
508:         if ($parentId === false) {
509:             $sql .= " AND parentid IS NULL";
510:         } else {
511:             $sql .= " AND parentid = " . cSecurity::toInteger($parentId);
512:         }
513:         $this->db->query($sql);
514:     }
515: 
516:     function setFilters($arrInFilters = array(), $arrOutFilters = array())
517:     {
518:         $this->_arrInFilters = $arrInFilters;
519:         $this->_arrOutFilters = $arrOutFilters;
520:     }
521: 
522:     function _inFilter($data)
523:     {
524:         foreach ($this->_arrInFilters as $_function)
525:         {
526:             if (function_exists($_function))
527:             {
528:                 $data = $_function($data);
529:             }
530:         }
531: 
532:         return $data;
533:     }
534: 
535:     function _outFilter($data)
536:     {
537:         foreach ($this->_arrOutFilters as $_function)
538:         {
539:             if (function_exists($_function))
540:             {
541:                 $data = $_function($data);
542:             }
543:         }
544: 
545:         return $data;
546:     }
547: }
548: 
549: ?>
CMS CONTENIDO 4.9.5 API documentation generated by ApiGen 2.8.0