PageRenderTime 66ms CodeModel.GetById 28ms RepoModel.GetById 0ms app.codeStats 0ms

/inc/bx/resources/text/html.php

https://github.com/whiletrue/fluxcms
PHP | 265 lines | 189 code | 64 blank | 12 comment | 36 complexity | 7042dd741468a7c2aca163e3a05f9da7 MD5 | raw file
  1. <?php
  2. class bx_resources_text_html extends bx_resource {
  3. protected $fulluri = "";
  4. protected $mimetype = "text/html";
  5. protected $id = "";
  6. protected $localName = "";
  7. protected $lang = "";
  8. public function __construct($id, $new = false) {
  9. $this->mimetype = "text/html";
  10. $this->fulluri = $id;
  11. $this->props['fileuri'] = BX_DATA_DIR.$id;
  12. $this->id = $id;
  13. if ($new === true) {
  14. $this->mock = true;
  15. }
  16. //TODO, check if file really exists...
  17. }
  18. public function getContentUri() {
  19. return BX_DATA_DIR.$this->fulluri;
  20. }
  21. public function getContentUriSample() {
  22. $theme = $GLOBALS['POOL']->config->getConfProperty('theme');
  23. if (isset($_REQUEST['template'])) {
  24. $template = sprintf("%s%s/templates/%s", BX_THEMES_DIR, $theme, $_REQUEST['template']);
  25. if (file_exists($template)) {
  26. return $template;
  27. }
  28. }
  29. $template = sprintf("%s%s/templates/%s", BX_THEMES_DIR, $theme, "default.xhtml");
  30. if (file_exists($template)) {
  31. return $template;
  32. }
  33. return BX_LIBS_DIR.'doctypes/default.xhtml';
  34. }
  35. public function create() {
  36. $this->init();
  37. }
  38. protected function init() {
  39. $this->setProperty("mimetype","text/html");
  40. $this->setProperty("output-mimetype","text/html");
  41. $this->setProperty("parent-uri",bx_collections::getCollectionUri($this->id));
  42. $this->setProperty("display-name",$this->getFileName());
  43. $this->setProperty("display-order",99);
  44. //parent::init();
  45. }
  46. public function getDisplayName() {
  47. $dn = $this->getProperty("display-name");
  48. if ($dn) {
  49. return $dn;
  50. }
  51. return $this->getFileName();
  52. }
  53. protected function parseName() {
  54. if (!$this->localName) {
  55. $p = bx_collections::getCollectionUriAndFileParts($this->getID());
  56. $this->collUri = $p['colluri'];
  57. $this->baseName = $p['rawname'];
  58. if (preg_match("#(.*)\.([a-z]{2})$#",$p['name'],$matches)) {
  59. $this->localName = $matches[1];
  60. $this->lang = $matches[2];
  61. }
  62. else {
  63. $this->localName = $p['name'];
  64. $this->lang = "";
  65. }
  66. }
  67. }
  68. public function getBaseName() {
  69. $this->parseName();
  70. return$this->baseName;
  71. }
  72. public function getOutputMimeType() {
  73. return "text/html";
  74. }
  75. public function getMimeType() {
  76. return "text/html";
  77. }
  78. public function getEditors() {
  79. $perm = bx_permm::getInstance();
  80. $localUri = substr($this->id, 0, strrpos($this->id, '/')+1);
  81. $e = array();
  82. if($perm->isAllowed($localUri,array('xhtml-back-edit_oneform'))) {
  83. $e[] = "oneform";
  84. }
  85. $e[] = "ooo";
  86. if(popoon_classes_browser::supportedByFCK() && $perm->isAllowed($localUri,array('xhtml-back-edit_fck'))) {
  87. array_unshift($e, "fck");
  88. }
  89. if (popoon_classes_browser::isMozilla()) {
  90. if($perm->isAllowed($localUri,array('xhtml-back-edit_kupu'))) {
  91. array_unshift($e, 'kupu');
  92. }
  93. if($perm->isAllowed($localUri,array('xhtml-back-edit_bxe'))) {
  94. array_unshift($e, 'bxe');
  95. }
  96. }
  97. else if (popoon_classes_browser::isMSIEWin()) {
  98. if($perm->isAllowed($localUri,array('xhtml-back-edit_kupu'))) {
  99. array_unshift($e, 'kupu');
  100. }
  101. }
  102. $a = $GLOBALS['POOL']->config->getConfProperty('assets');
  103. if (!empty($a)) {
  104. array_push($e, 'assets');
  105. }
  106. $v = $GLOBALS['POOL']->config->getConfProperty('versioning');
  107. if (!empty($v)) {
  108. array_push($e,'versioning');
  109. }
  110. return $e;
  111. }
  112. public function getLanguage() {
  113. $this->parseName();
  114. return $this->lang;
  115. }
  116. public function getFileName() {
  117. $this->parseName();
  118. return $this->localName;
  119. }
  120. public function addResource($name, $parentUri, $options=array()) {
  121. $perm = bx_permm::getInstance();
  122. $localUri = substr($this->id, 0, strrpos($this->id, '/')+1);
  123. if (!$perm->isAllowed($localUri,array('xhtml-back-edit_'.$options['editor']))) {
  124. throw new BxPageNotAllowedException();
  125. }
  126. $template = (isset($options['template'])) ? $options['template'] : 'default.xhtml';
  127. $editor = isset($options['editor']) ? '&editor='.$options['editor'] : '';
  128. $location = sprintf("%sadmin/edit%s?template=%s%s", BX_WEBROOT, $this->fulluri, $template, $editor);
  129. header("Location: $location");
  130. exit(0);
  131. }
  132. public function delete() {
  133. if (file_exists($this->props['fileuri'])) {
  134. @unlink($this->props['fileuri']);
  135. if (bx_resourcemanager::removeAllProperties($this->id)) {
  136. return true;
  137. }
  138. }
  139. return false;
  140. }
  141. public function onSave($old) {
  142. //filter tbody
  143. if (!empty($_GET['editor']) && $_GET['editor'] == 'fck') {
  144. $html = file_get_contents($this->props['fileuri']);
  145. if (strpos($html,'<tbody>') !== false) {
  146. $html = str_replace(array('<tbody>','</tbody>'),'',$html);
  147. file_put_contents($this->props['fileuri'],$html);
  148. }
  149. }
  150. //versioning
  151. $vconfig = $GLOBALS['POOL']->config->getConfProperty('versioning');
  152. if ($vconfig && !empty($vconfig)) {
  153. $vers = bx_versioning::versioning($vconfig);
  154. if ($vers) {
  155. $vers->setOld($old);
  156. $vers->commit($this->props['fileuri'], $this->fulluri, '');
  157. }
  158. }
  159. bx_metaindex::callIndexerFromFilename($this->props['fileuri'],$this->id);
  160. }
  161. public function getOutputUri() {
  162. if (!isset($this->outputUri)) {
  163. $this->parseName();
  164. if ($this->lang != BX_DEFAULT_LANGUAGE) {
  165. $this->outputUri = "/".$this->lang;
  166. } else {
  167. $this->outputUri = "";
  168. }
  169. $this->outputUri .= $this->collUri.$this->getFileName() .".html";
  170. }
  171. return $this->outputUri;
  172. }
  173. /* THIS ISN'T PERFECT
  174. we should use new bx_resources_text_html($to) or something like that
  175. and moreover check for the right extension...
  176. but basically it works for now
  177. */
  178. public function copy($to, $move = false) {
  179. // if enddestination is a directory, adjust accordingly
  180. if (is_dir(BX_DATA_DIR.$to)) {
  181. $to = $to .'/'.basename($this->props['fileuri']);
  182. }
  183. if (!copy($this->props['fileuri'],BX_DATA_DIR.$to)) {
  184. return false;
  185. }
  186. //copy properties
  187. foreach (bx_resourcemanager::getAllProperties($this->id) as $key => $value) {
  188. bx_resourcemanager::setProperty($to,$value['name'],$value['value'],$value['namespace']);
  189. }
  190. if (!$move) {
  191. bx_resourcemanager::setProperty($to,"display-order","0");
  192. }
  193. $newcolluri = bx_collections::getCollectionUri($to);
  194. bx_resourcemanager::setProperty($to,"parent-uri",$newcolluri);
  195. return true;
  196. }
  197. public function getDisplayOrder() {
  198. return $this->getProperty("display-order");
  199. }
  200. }