PageRenderTime 53ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/inc/bx/collection.php

https://github.com/chregu/fluxcms
PHP | 865 lines | 610 code | 168 blank | 87 comment | 124 complexity | d966e3461fd7d0a3223e5558039e3dc2 MD5 | raw file
Possible License(s): GPL-2.0, BSD-3-Clause, Apache-2.0, LGPL-2.1
  1. <?php
  2. // +----------------------------------------------------------------------+
  3. // | Bx |
  4. // +----------------------------------------------------------------------+
  5. // | Copyright (c) 2001-2007 Liip AG |
  6. // +----------------------------------------------------------------------+
  7. // | This program is free software; you can redistribute it and/or |
  8. // | modify it under the terms of the GNU General Public License (GPL) |
  9. // | as published by the Free Software Foundation; either version 2 |
  10. // | of the License, or (at your option) any later version. |
  11. // | The GPL can be found at http://www.gnu.org/licenses/gpl.html |
  12. // +----------------------------------------------------------------------+
  13. // | Author: Liip AG <devel@liip.ch> |
  14. // +----------------------------------------------------------------------+
  15. class bx_collection implements bxIresource {
  16. protected $pluginMap = array();
  17. protected $plugins = array();
  18. protected $filters = array();
  19. protected $allproperties = array();
  20. protected $properties = array();
  21. protected $mimetypeMapping =array("text/html" => "xhtml" , "text/wiki" => "wiki");
  22. protected $outputLanguage = 'de';
  23. protected $lastModifiedResource = NULL;
  24. protected $config;
  25. /*** magic methods ***/
  26. public function __get($name) {
  27. }
  28. public function __construct($url, $mode, $new = false) {
  29. if ($url == "") {
  30. $url ="/";
  31. }
  32. $url = str_replace("//","/",$url);
  33. $this->uri = $url;
  34. $this->id = $url;
  35. $this->mode = $mode;
  36. if ($new) {
  37. $this->init();
  38. }
  39. $this->config = new bx_collectionconfig($this->uri, $mode);
  40. $this->outputLanguage = $GLOBALS['POOL']->config->getOutputLanguage();
  41. }
  42. /** general methods **/
  43. private function init() {
  44. //bx_log::log('bx_collection::init');
  45. $this->uri = str_replace("..","",$this->uri);
  46. $parent = BX_DATA_DIR.bx_collections::sanitizeUrl(dirname($this->uri));
  47. if (!file_exists($parent)) {
  48. throw new PopoonFileNotFoundException(dirname($this->uri));
  49. }
  50. $name = basename($this->uri);
  51. // create directory on filesystem for new collection
  52. $collectionDirName = $parent.'/'.$name;
  53. if(!file_exists($collectionDirName)) {
  54. $stat = mkdir ( $collectionDirName, 0755);
  55. }
  56. // do nothing, if we have a .children file here
  57. if (file_exists($parent.'/'.BX_CONFIGXML_FILENAME.'.children')) {
  58. }
  59. // copy .configxml, if it exists, otherwise we assume, that there's a .children somewhere up
  60. else if (file_exists($parent.'/'.BX_CONFIGXML_FILENAME )) {
  61. copy($parent.'/'.BX_CONFIGXML_FILENAME,$parent.'/'.$name.'/'.BX_CONFIGXML_FILENAME);
  62. }
  63. $this->setProperty("mimetype","httpd/unix-directory");
  64. $this->setProperty("output-mimetype","httpd/unix-directory");
  65. $parentUri = bx_collections::sanitizeUrl(dirname($this->uri));
  66. $this->setProperty("parent-uri",$parentUri);
  67. $this->setProperty("display-name",$name, BX_PROPERTY_DEFAULT_NAMESPACE.BX_DEFAULT_LANGUAGE);
  68. $this->setProperty("display-order",0);
  69. $this->setProperty("unique-id", bx_helpers_sql::nextSequence() );
  70. return true;
  71. }
  72. public function resourceExistsByRequest($filename,$ext) {
  73. $map = $this->getPluginMapByRequest($filename,$ext);
  74. if (count($map) > 0) {
  75. foreach ($map as $p) {
  76. if (isset($p['plugin']) && $p['plugin']->isRealResource($this->uri,$p['id'])) {
  77. return true;
  78. }
  79. }
  80. }
  81. return false;
  82. }
  83. public function resourceExistsById($id) {
  84. $map = $this->getPluginMapById($id);
  85. return $map['plugin']->resourceExistsById($this->uri, $id);
  86. }
  87. /**
  88. * gets the content of all relevent output plugins
  89. *
  90. * @param string $filename filename of the request
  91. * @param string $ext extension of the request
  92. * @param DomDocument A Dom Object
  93. */
  94. public function getContentByRequest($filename, $ext) {
  95. return $this->getContentByPluginMap($this->getPluginMapByRequest($filename, $ext , false) );
  96. }
  97. public function getContentById($id) {
  98. $p = array();
  99. $p[0] = $this->getPluginMapById($id);
  100. return $this->getContentByPluginMap($p);
  101. }
  102. public function getChildResourceById($id) {
  103. $plugin = $this->getPluginById($id);
  104. if ($plugin instanceof bxIplugin) {
  105. return $plugin->getResourceById($this->uri,$id);
  106. }
  107. return null;
  108. }
  109. protected function getContentByPluginMap($pluginMap) {
  110. $xml = new DomDocument();
  111. $xml->appendChild($xml->createElement("bx"));
  112. if (is_array($pluginMap)) {
  113. $javascripts= array();
  114. foreach ($pluginMap as $p) {
  115. if(isset($p['plugin']) && $p['plugin'] instanceof bxIplugin) {
  116. $plugin = $xml->createElement("plugin");
  117. $plugin->setAttribute("name", $p['plugin']->name);
  118. $p['plugin']->setCurrentRequest($this->uri,$p['id']);
  119. $pluginXML =$p['plugin']->getContentById($this->uri,$p['id']);
  120. if (method_exists($p['plugin'],"getLastModifiedById")) {
  121. $this->lastModifiedResource = max($this->lastModifiedResource,$p['plugin']->getLastModifiedById($this->uri, $p['id']));
  122. }
  123. $p['plugin']->removeCurrentRequest($this->uri,$p['id']);
  124. if ($pluginXML instanceof DomDocument && $pluginXML->documentElement) {
  125. if ($p['plugin']->stripRoot()) {
  126. foreach ($pluginXML->documentElement->childNodes as $node) {
  127. $import = $xml->importNode($node ,true);
  128. $plugin->appendChild($import );
  129. }
  130. }
  131. else {
  132. $import = $xml->importNode($pluginXML->documentElement ,true);
  133. $plugin->appendChild($import );
  134. }
  135. $xml->documentElement->appendChild($plugin);
  136. unset($pluginXML);
  137. } else {
  138. $xml->documentElement->appendChild($plugin);
  139. }
  140. if (method_exists($p['plugin'],"getJavaScriptSources")) {
  141. $javascripts =
  142. array_merge($javascripts,$p['plugin']->getJavaScriptSources());
  143. }
  144. }
  145. }
  146. if (count($javascripts) > 0) {
  147. $jsroot = $xml->documentElement->appendChild($xml->createElement("javascripts"));
  148. foreach($javascripts as $js) {
  149. $jsroot->appendChild($xml->createElement("src",$js));
  150. }
  151. }
  152. }
  153. return $xml;
  154. }
  155. public function getPluginMapByRequest($filename,$ext,$first = false ) {
  156. if (!isset($this->pluginMap[$filename.$ext])) {
  157. $plugins = $this->getPluginsByRequest($filename,$ext ,$first);
  158. foreach ($plugins as $p) {
  159. $id = str_replace("//","/",$p->getIdByRequest($this->uri,$filename,$ext));
  160. if ($id) {
  161. $map = Array();
  162. $map['plugin'] = $p;
  163. $map['id'] = $id;
  164. $this->pluginMap[$filename.$ext][$id] = $map;
  165. } else {
  166. //$this->pluginMap[$filename.$ext][$id] = array();
  167. }
  168. }
  169. if (!isset($this->pluginMap[$filename.$ext])) {
  170. $this->pluginMap[$filename.$ext] = null;
  171. }
  172. }
  173. return $this->pluginMap[$filename.$ext];
  174. }
  175. /**
  176. * gets all the outputplugins associated to a $name
  177. * $name is usually the filename part of an uri
  178. *
  179. * @param string $name the name of the request
  180. * @param string $ext the extension part of the request
  181. * @return array all outputplugins
  182. */
  183. protected function getPluginsByRequest($name, $ext, $first=false) {
  184. if (empty($this->plugins[$name.$ext])) {
  185. $this->plugins[$name.$ext] = $this->config->getPlugins($name, $ext,$first);
  186. }
  187. return $this->plugins[$name.$ext];
  188. }
  189. public function getFirstPluginMapByRequest($filename,$ext) {
  190. $map = $this->getPluginMapByRequest($filename,$ext);
  191. if(is_array($map))
  192. return array_shift($map);
  193. }
  194. protected function getPluginMapById($id) {
  195. $map = NULL;
  196. if (isset($this->pluginMap[$id]) and isset($this->pluginMap[$id][$id])) {
  197. $map = $this->pluginMap[$id][$id];
  198. }
  199. // try to find it...
  200. if (!$map) {
  201. $map = array();
  202. $map['plugin'] = $this->getPluginById($id);
  203. $map['id'] = $id;
  204. $this->pluginMap[$id][$id]=$map;
  205. }
  206. return $map;
  207. }
  208. public function getContentUriById($id, $sample = false) {
  209. $p = $this->getPluginMapById($id);
  210. if (is_object($p['plugin'])) {
  211. return $p['plugin']->getContentUriById($this->uri, $id, $sample);
  212. } else {
  213. return false;
  214. }
  215. }
  216. public function getPluginResourceById($id) {
  217. $p = $this->getPluginMapById($id);
  218. if ($p['plugin'] instanceof bxIplugin) {
  219. return $p['plugin']->getResourceById($this->uri, $id);
  220. } else {
  221. return null;
  222. }
  223. }
  224. public function handlePostById($id,$data, $mode = null) {
  225. $p = $this->getPluginMapById($id);
  226. $old = file_get_contents($this->getContentUriById($id,$this->uri));
  227. $return = $p['plugin']->handlePOST($this->uri,$id,$data,$mode);
  228. $r = $this->getChildResourceById($id);
  229. if ($r) {
  230. $r->onSave($old);
  231. }
  232. return $return;
  233. }
  234. public function getPluginById($id, $sample = false) {
  235. $parts = bx_collections::getFileParts($id);
  236. $ret = $this->config->getAdminPlugin($parts['name'], $parts['ext'],$sample);
  237. return $ret;
  238. }
  239. public function getPluginMimeTypes() {
  240. $ps = $this->getChildrenPlugins();
  241. $mimetypes = array();
  242. foreach ($ps as $p) {
  243. $mimetypes = array_merge_recursive($mimetypes,$p->getMimeTypes());
  244. }
  245. $mimetypeMap = array();
  246. foreach ($mimetypes as $mimetype) {
  247. //FIXME: the mimetype mapping is hardcoded for the time being
  248. // should be changeable in .configxml
  249. if (isset($this->mimetypeMapping[$mimetype])) {
  250. $mimetypeMap[$this->mimetypeMapping[$mimetype]] = $mimetype;
  251. }
  252. }
  253. return $mimetypeMap;
  254. }
  255. public function getPluginResourceTypes() {
  256. $ps = $this->getChildrenPlugins();
  257. $resourceTypes = array();
  258. foreach ($ps as $p) {
  259. $resourceTypes = array_merge_recursive($resourceTypes, $p->getResourceTypes());
  260. }
  261. return $resourceTypes;
  262. }
  263. public function getPluginByResourceType($type) {
  264. $ps = $this->getChildrenPlugins();
  265. foreach ($ps as $p) {
  266. if (in_array($type,$p->getResourceTypes())) {
  267. return $p;
  268. }
  269. }
  270. return null;
  271. }
  272. /**
  273. * returns all Output Plugins associated to this collections
  274. *
  275. * useful for the tree plugin (if you need for example all
  276. * the resources of all plugins for navigation
  277. *
  278. * @returns array all plugins associated to this children
  279. */
  280. public function getChildrenPlugins() {
  281. if (count($this->childrenPlugins) == 0) {
  282. $this->childrenPlugins = $this->config->getChildrenPlugins();
  283. }
  284. return $this->childrenPlugins;
  285. }
  286. /** pipeline methods **/
  287. public function getRequestById($id) {
  288. $p = $this->getPluginById($id);
  289. if ($p) {
  290. return $p->getRequestById($this->uri,$id);
  291. }
  292. return null;
  293. }
  294. /**
  295. * Returns general and plugin/request - dependant parameters.
  296. * Required parameters:
  297. * 'pipelineName' - returned by FIRST plugin (is it logical?)
  298. * 'filters' - configured in .configxml
  299. *
  300. * @param name filename/path of request
  301. * @ext extension of request
  302. * @return array of parameters
  303. *
  304. */
  305. public function getPipelineParametersByRequest($filename, $ext) {
  306. $map = $this->getPluginMapByRequest($filename, $ext);
  307. $a = array();
  308. $a['pipelineName'] = 'standard'; /// default
  309. $a['filters'] = $this->getFiltersByRequest($filename, $ext);
  310. // merge other parameters from all plugins
  311. if (is_array($map)) {
  312. foreach ($map as $p) {
  313. if(isset($p['plugin']) && $p['plugin'] instanceof bxIplugin) {
  314. $params = $p['plugin']->getPipelineParametersById($this->uri, $p['id']);
  315. $a = array_merge($a, $params);
  316. }
  317. }
  318. }
  319. return $a;
  320. }
  321. protected function getFiltersByRequest($name, $ext) {
  322. if (empty($this->filters[$name.$ext])) {
  323. $this->filters[$name.$ext] = $this->config->getFilters($name, $ext);
  324. }
  325. return $this->filters[$name.$ext];
  326. }
  327. public function getParentCollection() {
  328. if ($parent = $this->getProperty("parent-uri")) {
  329. return bx_collections::getCollection($parent,$this->mode);
  330. }
  331. return NULL;
  332. }
  333. public function getSubCollection($name, $mode) {
  334. return bx_collections::getCollection($name, $mode);
  335. }
  336. public function getEditorsById($id) {
  337. $p = $this->getPluginMapById($id);
  338. if ($p['plugin'] instanceof bxIplugin) {
  339. return $p['plugin']->getEditorsById($this->uri, $id);
  340. }
  341. return array();
  342. }
  343. public function copyResourceById($id, $to) {
  344. // id $id is empty, it's a collection
  345. if ($id == "") {
  346. return $this->copy($to);
  347. }
  348. $p = $this->getPluginMapById($id);
  349. if ($p['plugin'] instanceof bxIplugin) {
  350. return $p['plugin']->copyResourceById($this->uri, $id, $to);
  351. }
  352. }
  353. public function moveResourceById($id, $to) {
  354. // id $id is empty, it's a collection
  355. if ($id == "") {
  356. if ($this->copy($to, true)) {
  357. return $this->delete();
  358. } else {
  359. return false;
  360. }
  361. }
  362. $p = $this->getPluginMapById($id);
  363. if ($p['plugin'] instanceof bxIplugin) {
  364. if ($p['plugin']->copyResourceById($this->uri, $id, $to, true)) {
  365. return $p['plugin']->deleteResourceById($this->uri, $id);
  366. } else {
  367. return false;
  368. }
  369. }
  370. }
  371. public function deleteResourceById( $id) {
  372. // id $id is empty, it's a collection
  373. if ($id == "") {
  374. return $this->delete();
  375. }
  376. bx_metaindex::removeAllTagsById($this->uri . $id);
  377. $p = $this->getPluginMapById($id);
  378. if ($p['plugin'] instanceof bxIplugin) {
  379. return $p['plugin']->deleteResourceById($this->uri, $id);
  380. }
  381. }
  382. public function copy($to, $move = false) {
  383. $to = str_replace("//","/",$to);
  384. if (substr($to , -1) != "/") {
  385. $to .= "/";
  386. }
  387. // if enddestination is a directory, adjust accordingly
  388. // meaning copy it into that directory instead of replace it
  389. /*
  390. DOES NOT WORK YET :)
  391. if (is_dir(BX_DATA_DIR.$to)) {
  392. $to = $to . basename($this->uri);
  393. }
  394. */
  395. new bx_collection($to, $this->mode, true);
  396. foreach (bx_resourcemanager::getAllProperties($this->uri) as $key => $value) {
  397. if ($value['name'] != 'parent-uri' AND $value['name'] != 'unique-id') {
  398. bx_resourcemanager::setProperty($to,$value['name'],$value['value'],$value['namespace']);
  399. }
  400. }
  401. $ps = $this->getChildrenPlugins();
  402. foreach ($ps as $p ) {
  403. $p->collectionCopy('before',$this->uri, $to, $move);
  404. }
  405. // copy .configxml
  406. @copy(BX_DATA_DIR.$this->uri.BX_CONFIGXML_FILENAME,BX_DATA_DIR.$to.BX_CONFIGXML_FILENAME);
  407. @copy(BX_DATA_DIR.$this->uri.BX_CONFIGXML_FILENAME.'.children',BX_DATA_DIR.$to.BX_CONFIGXML_FILENAME.'.children');
  408. if (!$move) {
  409. bx_resourcemanager::setProperty($to,"display-order","0");
  410. }
  411. foreach($this->getChildren() as $res) {
  412. if (method_exists($res,"copy")) {
  413. $res->copy($to . $res->getBaseName(), $move);
  414. }
  415. }
  416. //inform plugins, that collection moved
  417. // inform permission management that collection has beem moved:
  418. $permObj = bx_permm::getInstance(bx_config::getInstance()->getConfProperty('permm'));
  419. $permObj->movePermissions($this->uri, $to);
  420. return true;
  421. }
  422. public function delete() {
  423. if($this->uri == '/')
  424. return FALSE;
  425. foreach($this->getChildren() as $res) {
  426. $res->delete();
  427. }
  428. bx_resourcemanager::removeAllProperties( $this->uri);
  429. // delete all files in that dir
  430. $d = new DirectoryIterator(BX_DATA_DIR.$this->uri);
  431. foreach ($d as $file) {
  432. $filename = $file->getFileName();
  433. if ($filename == '.' || $filename == '..') {
  434. continue;
  435. }
  436. if ($file->isDir()) {
  437. bx_helpers_file::rmdir(BX_DATA_DIR.$this->uri.$filename);
  438. } else {
  439. unlink(BX_DATA_DIR.$this->uri.$filename);
  440. }
  441. }
  442. bx_helpers_file::rmdir(BX_DATA_DIR.$this->uri);
  443. $ps = $this->getChildrenPlugins();
  444. foreach ($ps as $p ) {
  445. $p->collectionDelete('after',$this->uri);
  446. }
  447. return true;
  448. }
  449. public function getResourceIdsByRequest($name, $ext) {
  450. $map = $this->getPluginMapByRequest($name,$ext);
  451. return array_keys($map);
  452. }
  453. // Resource Interface stuff
  454. public function getAllProperties($namespace = null) {
  455. if (!isset($this->allproperties[$namespace])) {
  456. $this->allproperties[$namespace] = bx_resourcemanager::getAllProperties($this->uri, $namespace);
  457. foreach ($this->allproperties[$namespace] as $key => $value) {
  458. $this->properties[$key] = $value['value'];
  459. }
  460. }
  461. return $this->allproperties[$namespace];
  462. }
  463. public function setProperty($name, $value, $namespace = BX_PROPERTY_DEFAULT_NAMESPACE) {
  464. $fullname = $namespace .":".$name;
  465. bx_resourcemanager::setProperty($this->uri, $name, $value, $namespace);
  466. $this->properties[$fullname] = $value;
  467. $this->allproperties = array();
  468. }
  469. public function getProperty($name, $namespace = BX_PROPERTY_DEFAULT_NAMESPACE) {
  470. if ($name == "output-mimetype") {
  471. return "httpd/unix-directory";
  472. }
  473. $fullname = $namespace .":".$name;
  474. //var_duop($this->properties);
  475. //var_dump($this->properties[$fullname]);
  476. if (!isset($this->properties[$fullname])) {
  477. $this->getAllProperties($namespace);
  478. }
  479. if (!isset($this->properties[$fullname])) {
  480. return NULL;
  481. }
  482. return $this->properties[$fullname];
  483. }
  484. public function removeProperty($name, $namespace = BX_PROPERTY_DEFAULT_NAMESPACE) {
  485. bx_resourcemanager::removeProperty($this->uri, $name, $namespace);
  486. }
  487. public function removeAllProperties($namespace = NULL) {
  488. bx_resourcemanager::removeAllProperties($this->uri, $namespace);
  489. }
  490. public function getId() {
  491. return $this->uri;
  492. }
  493. public function getMimeType() {
  494. return "httpd/unix-directory";
  495. }
  496. public function getLastModified() {
  497. return filemtime(BX_DATA_DIR.$this->uri);
  498. }
  499. public function getLastModifiedResource() {
  500. return $this->lastModifiedResource;
  501. }
  502. public function getCreationDate() {
  503. return filectime(BX_DATA_DIR.$this->uri);
  504. }
  505. public function getDisplayName($lang = null) {
  506. if (!$lang) {
  507. $lang = $this->outputLanguage;
  508. }
  509. if ($d = $this->getProperty("display-name", sprintf("bx:%2s", $lang))) {
  510. return $d;
  511. } else {
  512. return preg_replace("#/(.*)/$#","$1",$this->id);
  513. }
  514. }
  515. public function getDisplayImage() {
  516. if (!$lang) {
  517. $lang = $this->outputLanguage;
  518. }
  519. if (($o = $this->getProperty('display-image', sprintf("bx:%2s", $lang))) !== NULL) {
  520. return $o;
  521. }
  522. }
  523. public function getDisplayOrder() {
  524. if (($o = $this->getProperty('display-order')) !== NULL) {
  525. return $o;
  526. } else {
  527. return 0;
  528. }
  529. }
  530. public function getContentLength() {
  531. return 0;
  532. }
  533. public function getLocalName() {
  534. return $this->uri;
  535. }
  536. public function getLanguage() {
  537. return $GLOBALS['POOL']->config->getOutputLanguage();
  538. }
  539. public function getEditors() {
  540. return array();
  541. }
  542. public function saveFile($file, $uploadInfo = NULL) {
  543. return false;
  544. }
  545. public function getContentUri($sample = false) {
  546. return NULL;
  547. }
  548. public function getContentUriSample() {
  549. return NULL;
  550. }
  551. public function getResourceById($id) {
  552. return bx_collections::getCollection($id, $this->mode);
  553. }
  554. public function getResourceName() {
  555. return get_class($this);
  556. }
  557. /**
  558. * returns all Children of All Outputplugins belonging to this collection
  559. *
  560. * The returned Children are resources
  561. *
  562. * @return array with resources of all Children belonging to this section
  563. */
  564. public function getChildren($id = "") {
  565. $children = array();
  566. $p = $this->getChildrenPlugins();
  567. foreach($p as $plugin) {
  568. $plugin->setCurrentRequest($this->uri,"");
  569. $children = array_merge_recursive($children,$plugin->getChildren($this,$id));
  570. $plugin->removeCurrentRequest($this->uri,"");
  571. }
  572. // for the collection itself
  573. if ($id == "" || substr($id,0,1) == "/") {
  574. $ch = bx_resourcemanager::getChildrenByMimeType($this,$this->getMimetype());
  575. foreach( $ch as $path) {
  576. $ch = $this->getResourceById($path);
  577. /*check if uri is child of $coll->uri
  578. */
  579. if( strpos($ch->uri,$this->uri) === 0 && $this->uri != $ch->uri) {
  580. $children[] = $ch;
  581. }
  582. }
  583. }
  584. return $children;
  585. }
  586. public function freePlugins() {
  587. foreach ($this->plugins as $p) {
  588. unset($p);
  589. }
  590. }
  591. public function getPipelineProperties() {
  592. $props = $this->getAllProperties(BX_PROPERTY_PIPELINE_NAMESPACE);
  593. $params = array();
  594. foreach ($props as $p ) {
  595. $params[$p['name']] = $p['value'];
  596. }
  597. $params = array_merge( $params, $this->config->getParameters("pipeline"));
  598. return $params;
  599. }
  600. public function getBaseName() {
  601. return basename($this->uri);
  602. }
  603. public function getAdminMasterPlugin() {
  604. if(($plugin = $this->config->getAdminMasterPlugin()) != NULL) {
  605. return $plugin;
  606. }
  607. return $this->getPluginById("");
  608. }
  609. public function getAllOverviewSections($mainOverview) {
  610. $ps = $this->getChildrenPlugins();
  611. $sections = array();
  612. foreach ($ps as $name =>$p) {
  613. if ($s = $p->getOverviewSections($this->uri,$mainOverview)) {
  614. $sections[] = $s;
  615. }
  616. }
  617. if (!$mainOverview) {
  618. $sections[] = $this->getOverviewSections($mainOverview);
  619. }
  620. return $sections;
  621. }
  622. public function getOverviewSections($mainOverview) {
  623. $i18n = $GLOBALS['POOL']->i18nadmin;
  624. $permObj = bx_permm::getInstance(bx_config::getInstance()->getConfProperty('permm'));
  625. if(!$permObj->isAllowed('/',array('admin'))) {
  626. return;
  627. }
  628. $perm = bx_permm::getInstance();
  629. $sections = array();
  630. $dom = new bx_domdocs_overview();
  631. $dom->setTitle("Collection" ,"Create/Edit");
  632. $dom->setType("collection");
  633. $dom->setIcon("collection");
  634. $dom->setPath($this->uri);
  635. if ($perm->isAllowed($this->uri,array('collection-back-properties'))) {
  636. $dom->addLink("Properties", "properties/".$this->uri);
  637. }
  638. if ($perm->isEditable()) {
  639. if ($perm->isAllowed('/permissions/',array('permissions-back-manage'))) {
  640. $dom->addLink("Edit Permissions", "edit/permissions/".$this->uri);
  641. }
  642. }
  643. $dom->addSeperator();
  644. if ($perm->isAllowed($this->uri, array('collection-back-create'))) {
  645. $dom->addLink("Create new Collection", 'collection'.$this->uri);
  646. }
  647. $resourceTypes = $this->getPluginResourceTypes();
  648. if(!empty($resourceTypes)) {
  649. foreach($resourceTypes as $resourceType) {
  650. if($resourceType == "xhtml") {
  651. if (!$perm->isAllowed($this->uri, array('xhtml-back-create'))) {
  652. continue;
  653. }
  654. } else if($resourceType == "gallery") {
  655. if (!$perm->isAllowed($this->uri, array('gallery-back-gallery'))) {
  656. continue;
  657. }
  658. } else if($resourceType == "file" or $resourceType == "archive") {
  659. if (!$perm->isAllowed($this->uri, array('file-back-upload')) and !$perm->isAllowed($this->uri, array('gallery-back-upload'))) {
  660. continue;
  661. }
  662. }
  663. $dom->addLink($i18n->translate2("Create new {resourcetype}", array('resourcetype'=>$resourceType)), 'addresource'. $this->uri.'?type='.$resourceType);
  664. }
  665. }
  666. $dom->addTab("Configuration");
  667. $this->overviewAddEditConfigXML($dom,".configxml");
  668. $this->overviewAddEditConfigXML($dom,".configxml.children");
  669. if ($this->uri != "/") {
  670. $dom->addTab("Operations");
  671. if ($perm->isAllowed($this->uri,array('collection-back-copy'))) {
  672. $dom->addLink("Copy",'javascript:parent.navi.admin.copyResource("'.$this->uri.'");');
  673. }
  674. if ($perm->isAllowed($this->uri,array('collection-back-copy', 'collection-back-delete'))) {
  675. $dom->addLink("Move/Rename",'javascript:parent.navi.admin.copyResource("'.$this->uri.'",true);');
  676. }
  677. if ($perm->isAllowed($this->uri,array('collection-back-delete'))) {
  678. $dom->addLink("Delete",'javascript:parent.navi.admin.deleteResource("'.$this->uri.'",true);');
  679. }
  680. }
  681. return $dom;
  682. }
  683. protected function overviewAddEditConfigXML($dom, $file) {
  684. $perm = bx_permm::getInstance();
  685. if ($perm->isAllowed($this->uri,array('collection-back-configxml'))) {
  686. if (file_exists(BX_DATA_DIR.$this->uri.$file)) {
  687. $dom->addLink("Edit $file", 'edit'.$this->uri.$file.'?editor=oneform');
  688. } else {
  689. $dom->addLink( "Add $file", 'edit'.$this->uri.$file.'?editor=oneform');
  690. }
  691. }
  692. }
  693. public function getJavaScriptSources() {
  694. return array();
  695. }
  696. }
  697. ?>