PageRenderTime 63ms CodeModel.GetById 33ms RepoModel.GetById 0ms app.codeStats 0ms

/inc/bx/resource.php

https://github.com/chregu/fluxcms
PHP | 322 lines | 260 code | 57 blank | 5 comment | 48 complexity | 864a52bbd1b44284886eb4954094aa3b MD5 | raw file
Possible License(s): GPL-2.0, BSD-3-Clause, Apache-2.0, LGPL-2.1
  1. <?php
  2. abstract class bx_resource implements bxIresource {
  3. protected $id;
  4. protected $mimetype;
  5. protected $properties = array();
  6. protected $allproperties = array();
  7. protected $lang = null;
  8. public $mock = false;
  9. public function __construct() {
  10. }
  11. public function getContentHandle() {
  12. return fopen($this->getContentUri());
  13. }
  14. public function setProperty($name, $value, $namespace = BX_PROPERTY_DEFAULT_NAMESPACE) {
  15. $fullname = $namespace .":".$name;
  16. bx_resourcemanager::setProperty($this->id, $name, $value, $namespace);
  17. $this->properties[$fullname] = $value;
  18. $this->allproperties = array();
  19. }
  20. public function getAllProperties($namespace = null) {
  21. if (!isset($this->allproperties[$namespace])) {
  22. $this->allproperties[$namespace] = bx_resourcemanager::getAllProperties($this->id, $namespace);
  23. foreach ($this->allproperties[$namespace] as $key => $value) {
  24. $this->properties[$key] = $value['value'];
  25. }
  26. }
  27. return $this->allproperties[$namespace];
  28. }
  29. public function getProperty($name, $namespace = BX_PROPERTY_DEFAULT_NAMESPACE) {
  30. if ($namespace == BX_PROPERTY_DEFAULT_NAMESPACE) {
  31. switch ($name) {
  32. case "mimetype":
  33. return $this->getMimeType();
  34. case "output-mimetype":
  35. return $this->getOutputMimeType();
  36. case "id":
  37. return $this->getId();
  38. case "localname":
  39. return $this->getLocalName();
  40. case "creationdate":
  41. return $this->getCreationDate();
  42. case "datauri";
  43. return $this->getDataUri();
  44. case "displayname";
  45. return $this->getDisplayname();
  46. case "lastmodified";
  47. return $this->lastModified();
  48. }
  49. }
  50. $fullname = $namespace .":".$name;
  51. if (!isset($this->properties[$fullname])) {
  52. $this->getAllProperties($namespace);
  53. }
  54. if (!isset($this->properties[$fullname])) {
  55. return NULL;
  56. }
  57. return $this->properties[$fullname];
  58. }
  59. public function removeProperty($name, $namespace = BX_PROPERTY_DEFAULT_NAMESPACE) {
  60. bx_resourcemanager::removeProperty($this->id, $name, $namespace);
  61. }
  62. public function saveFile($file , $uploadInfo = NULL) {
  63. // overwrite old file with uploaded file
  64. $fspath = $this->getContentUri();
  65. if (!$fspath) {
  66. return false;
  67. }
  68. if ($this->mock) {
  69. $this->init();
  70. }
  71. if(!empty($fspath) && file_exists($file)) {
  72. if ( copy($file, $fspath)) {
  73. $mt = popoon_helpers_mimetypes::getFromFileLocation($fspath);
  74. if ($mt) {
  75. $this->callMetaIndex($fspath);
  76. }
  77. return true;
  78. } else {
  79. return false;
  80. }
  81. }
  82. return false;
  83. }
  84. public function callMetaIndex($fspath) {
  85. bx_metaindex::callIndexerFromFilename($fspath,$this->id);
  86. }
  87. public function save () {
  88. if ($this->mock) {
  89. return $this->saveFile($this->getContentUriSample());
  90. }
  91. print "TO BE IMPLEMENTED " . __FILE__ . " " . __METHOD__;
  92. }
  93. public function getContentUri($sample = false) {
  94. return NULL;
  95. }
  96. public function getContentUriSample() {
  97. return NULL;
  98. //return BX_LIBS_DIR.'doctypes/dreispalt.xhtml';
  99. }
  100. public function getId() {
  101. return $this->id;
  102. }
  103. public function getLocalName() {
  104. if (isset($this->props['localname'])) {
  105. return $this->props['localname'];
  106. }
  107. if (isset($this->props['fileuri'])) {
  108. $b = basename($this->props['fileuri']);
  109. $p = bx_collections::getFileParts($b);
  110. $this->props['localname'] = $p['name'].".".$p['ext'];
  111. return $this->props['localname'];
  112. }
  113. return null;
  114. }
  115. public function getLanguage() {
  116. if ($this->lang) {
  117. return $this->lang;
  118. } else {
  119. return $GLOBALS['POOL']->config->getOutputLanguage();
  120. }
  121. }
  122. public function getOutputUri() {
  123. if ($this->props['outputUri']) {
  124. return $this->props['outputUri'];
  125. } else {
  126. return $this->getDataUri();
  127. }
  128. }
  129. public function getDisplayName() {
  130. if (isset($this->props['displayname'])) {
  131. return $this->props['displayname'];
  132. }
  133. if (isset($this->props['fileuri'])) {
  134. $b = basename($this->props['fileuri']);
  135. $p = bx_collections::getFileParts($b);
  136. $this->props['displayname'] = $p['name'];
  137. return $this->props['displayname'];
  138. }
  139. return null;
  140. }
  141. public function getTitle() {
  142. if (isset($this->props['title'])) {
  143. return $this->props['title'];
  144. } else {
  145. return $this->getDisplayName();
  146. }
  147. }
  148. public function getStatus() {
  149. if (isset($this->props['status'])) {
  150. return $this->props['status'];
  151. } else {
  152. return 1;
  153. }
  154. }
  155. public function getDisplayOrder() {
  156. }
  157. public function getDisplayImage() {
  158. }
  159. public function getMimeType() {
  160. if (isset($this->props['mimetype'])) {
  161. return $this->props['mimetype'];
  162. } else {
  163. return $this->getResourceName();
  164. }
  165. return null;
  166. }
  167. public function getOutputMimeType() {
  168. if (isset($this->props['output-mimetype'])) {
  169. return $this->props['output-mimetype'];
  170. }
  171. if (isset($this->props['mimetype'])) {
  172. return $this->props['mimetype'];
  173. }
  174. return null;
  175. }
  176. public function getLastModified() {
  177. if (isset($this->props['lastmodified'])) {
  178. return $this->props['lastmodified'];
  179. }
  180. if (isset($this->props['fileuri'])) {
  181. $this->props['lastmodified'] = @filemtime($this->props['fileuri']);
  182. return $this->props['lastmodified'];
  183. }
  184. return null;
  185. }
  186. public function getCreationDate() {
  187. if (isset($this->props['creationdate'])) {
  188. return $this->props['creationdate'];
  189. }
  190. if (isset($this->props['fileuri'])) {
  191. $this->props['creationdate'] = @filectime($this->props['fileuri']);
  192. return $this->props['creationdate'];
  193. }
  194. return null;
  195. }
  196. public function getContentLength() {
  197. if (isset($this->props['contentlength'])) {
  198. return $this->props['contentlength'];
  199. }
  200. if (isset($this->props['fileuri'])) {
  201. $this->props['contentlength'] = @filesize($this->props['fileuri']);
  202. return $this->props['contentlength'];
  203. }
  204. return null;
  205. }
  206. public function getEditors() {
  207. return array();
  208. }
  209. public function getDataUri() {
  210. return $this->fulluri;
  211. }
  212. public function getResourceName() {
  213. return get_class($this);
  214. }
  215. public function getResourceDescription() {
  216. if (isset($this->props['resourceDescription'])) {
  217. return $this->props['resourceDescription'];
  218. }
  219. }
  220. public function onSave($old) {
  221. return null;
  222. }
  223. public function getOverviewSections($dom,$coll = null) {
  224. $permObj = bx_permm::getInstance(bx_config::getInstance()->getConfProperty('permm'));
  225. if($permObj->isAllowed('/',array('admin'))) {
  226. $perm = bx_permm::getInstance();
  227. $permId = substr($this->id, 0, strrpos($this->id, '/', -1)+1);
  228. //$dom->setIcon("resource");
  229. $dom->setType("resource");
  230. $dom->setPath($this->id);
  231. $dom->addSeperator();
  232. if ($perm->isAllowed($permId, array('collection-back-properties'))) {
  233. $dom->addLink("Properties", "properties".$this->id);
  234. }
  235. if ($coll && $this->getMimetype() == 'httpd/unix-directory') {
  236. $dom->addSeperator();
  237. $dom->addLink("Create new Collection", 'collection'.$this->id);
  238. $resourceTypes = $coll->getPluginResourceTypes();
  239. if(!empty($resourceTypes)) {
  240. foreach($resourceTypes as $resourceType) {
  241. $dom->addLink("Create new " . $resourceType,'addresource'. $this->id.'?type='.$resourceType);
  242. }
  243. }
  244. }
  245. $dom->addTab("Operations");
  246. if ($perm->isAllowed($permId,array('collection-back-copy'))) {
  247. $dom->addLink("Copy",'javascript:parent.navi.admin.copyResource("'.$this->id.'");');
  248. }
  249. if ($perm->isAllowed($permId,array('collection-back-copy', 'collection-back-delete'))) {
  250. $dom->addLink("Move/Rename",'javascript:parent.navi.admin.copyResource("'.$this->id.'",true);');
  251. }
  252. if ($perm->isAllowed($permId,array('collection-back-delete'))) {
  253. $dom->addLink("Delete",'javascript:parent.navi.admin.deleteResource("'.$this->id.'");');
  254. }
  255. $dom->addTab("History");
  256. // TODO: Check permissions
  257. $vconfig = $GLOBALS['POOL']->config->getConfProperty('versioning');
  258. if ($vconfig && !empty($vconfig)) {
  259. $dom->addLink("List", 'history'.$this->id);
  260. }
  261. //$dom->addLink("Overview",'history'.$this->);
  262. }
  263. }
  264. }
  265. ?>