PageRenderTime 949ms CodeModel.GetById 29ms RepoModel.GetById 7ms app.codeStats 0ms

/inc/bx/popoon/components/generators/admintree.php

https://github.com/chregu/fluxcms
PHP | 156 lines | 107 code | 45 blank | 4 comment | 21 complexity | a0b7650197dc7d0a595b713825af5f30 MD5 | raw file
Possible License(s): GPL-2.0, BSD-3-Clause, Apache-2.0, LGPL-2.1
  1. <?php
  2. class popoon_components_generators_admintree extends popoon_components_reader {
  3. private $requestUri = "";
  4. function __construct ($sitemap) {
  5. parent::__construct($sitemap);
  6. $this->requestUri = str_replace('//', '/', $_SERVER['REQUEST_URI']);
  7. }
  8. function init($attribs) {
  9. parent::init($attribs);
  10. }
  11. public function DomStart(&$xml) {
  12. if (!empty($this->requestUri)) {
  13. $strpos = strpos($this->requestUri,"/admin/navi/tree");
  14. $path = substr($this->requestUri,$strpos+16);
  15. if (!$path) {
  16. $path = '/';
  17. }
  18. /* strip GET params for collection lookup */
  19. $path = preg_replace("/\?.*$/", "", $path);
  20. $outputPath = $path;
  21. // FIXME: No hardcoded Paths, and no preg_replace'ing them
  22. if (preg_match("/\/data\//", $path)) {
  23. $path = preg_replace("/\/data/", "", $path);
  24. }
  25. }
  26. $permObj = bx_permm::getInstance(bx_config::getInstance()->getConfProperty('permm'));
  27. $p = bx_collections::getCollectionAndFileParts($path, "output");
  28. $coll = $p['coll'];
  29. $dom = new domDocument();
  30. $dom->loadXML("<navitree/>");
  31. $pathNode = $dom->createElement('path');
  32. $pathNode->appendChild($dom->createTextNode($outputPath));
  33. $dom->documentElement->appendChild($pathNode);
  34. $params = $this->getGetParamsNode($dom);
  35. $dom->documentElement->appendChild($params);
  36. // $dom->documentElement->appendChild());
  37. $ch = $coll->getChildren($p['rawname']) ;
  38. usort($ch,array("popoon_components_generators_admintree","sortByRang"));
  39. foreach( $ch as $element => $entry) {
  40. $el = $dom->createElement("item");
  41. $el->setAttribute('mimetype',$entry->getProperty("output-mimetype"));
  42. $el->setAttribute('uri',$entry->getLocalName());
  43. switch ($entry->getProperty("output-mimetype")) {
  44. case "httpd/unix-directory":
  45. $el->setAttribute('iconAction',"testopen('".$coll->uri.$p['rawname'].$entry->getBaseName()."/',this)");
  46. $el->setAttribute('icon', BX_WEBROOT.'admin/webinc/img/icons/fileicon_folder.gif');
  47. $el->setAttribute('openIcon', BX_WEBROOT.'admin/webinc/img/icons/fileicon_folder.gif');
  48. $el->setAttribute('title',$entry->getDisplayName());
  49. $el->setAttribute('src', BX_WEBROOT.'admin/navi/tree'.$entry->uri);
  50. $do = $entry->getDisplayOrder();
  51. if ($do) {
  52. $do = " (".$do .")";
  53. } else {
  54. $do = '';
  55. }
  56. $el->setAttribute('name', $entry->getBaseName() .$do);
  57. $el->setAttribute('action',BX_WEBROOT. 'admin/overview'.$coll->uri.$p['rawname'].$entry->getBaseName().'/');
  58. if($entry->getBaseName() == 'themes' AND $permObj->isAllowed('/',array('admin'))) {
  59. $dom->documentElement->appendChild($el);
  60. } else if($entry->getBaseName() != 'themes') {
  61. $dom->documentElement->appendChild($el);
  62. }
  63. break;
  64. default:
  65. $mimetype = $entry->getMimeType();
  66. $el->setAttribute('iconAction',"testopen('".$coll->uri.$p['rawname'].$entry->getLocalName()."',this)");
  67. $el->setAttribute('action', BX_WEBROOT.'admin/overview'.$coll->uri.$p['rawname'].$entry->getLocalName());
  68. $el->setAttribute('icon', BX_WEBROOT.'admin/webinc/img/icons/'.$mimetype.'.gif');
  69. $el->setAttribute('openIcon', BX_WEBROOT.'admin/webinc/img/icons/'.$mimetype.'.gif');
  70. $el->setAttribute('title',$entry->getDisplayName());
  71. $el->setAttribute('name', $entry->getLocalName() );
  72. $dom->documentElement->appendChild($el);
  73. }
  74. }
  75. $xml = $dom;
  76. }
  77. static function sortByRang($a,$b) {
  78. $aIsDir = ($a->getMimeType() == "httpd/unix-directory") ?true :false;
  79. $bIsDir = ($b->getMimeType() == "httpd/unix-directory") ?true :false;
  80. if ($aIsDir && !($bIsDir)) {
  81. return -1;
  82. }
  83. if ($bIsDir && !($aIsDir)) {
  84. return 1;
  85. }
  86. $ad = $a->getDisplayOrder();
  87. $bd = $b->getDisplayOrder();
  88. if ($ad == $bd) {
  89. return (strtolower($a->getLocalName()) < strtolower($b->getLocalName())) ? -1 : 1;
  90. };
  91. if (!$ad) {
  92. return 1;
  93. }
  94. if (!$bd) {
  95. return -1;
  96. }
  97. return ($ad < $bd) ? -1 : 1;
  98. }
  99. protected static function getGetParamsNode(&$dom) {
  100. $params = $dom->createElement('params');
  101. foreach($_GET as $name => $value) {
  102. // echo $name."00".$value."<br/>";
  103. $param = $dom->createElement('param');
  104. $param->setAttribute('name', $name);
  105. $param->setAttribute('value', $value);
  106. $params->appendChild($param);
  107. }
  108. return $params;
  109. }
  110. }
  111. ?>