PageRenderTime 52ms CodeModel.GetById 25ms RepoModel.GetById 0ms app.codeStats 0ms

/inc/bx/plugin.php

https://github.com/chregu/fluxcms
PHP | 213 lines | 132 code | 38 blank | 43 comment | 17 complexity | 8a4987b323d86a292bc8fc5d27599535 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. /**
  16. * class bx_plugin
  17. * @package bx_plugins
  18. */
  19. abstract class bx_plugin extends bx_component implements bxIplugin {
  20. protected $mode;
  21. protected $javascriptsources = array();
  22. protected function __construct($mode = "output") {
  23. $this->mode = $mode;
  24. }
  25. function __destruct() {
  26. if (isset($this->res) && is_array($this->res)) {
  27. foreach($this->res as $res) {
  28. unset($res);
  29. }
  30. }
  31. }
  32. public function getChildren($uri, $id) {
  33. return array();
  34. }
  35. /** @bxIplugin::getIdByRequest*/
  36. public function getIdByRequest ($path, $name = NULL, $ext = NULL) {
  37. return "$name.$ext.".$this->name;
  38. }
  39. public function getContentById($path, $id) {
  40. return null;
  41. }
  42. public function getEditorsById($path, $id) {
  43. $resourceEditors = array();
  44. $res = $this->getResourceById($path,$id);
  45. if ($res instanceof bxIresource) {
  46. $resourceEditors = $res->getEditors();
  47. } else {
  48. // if no resource was found, try with a new one
  49. $res = $this->getResourceById($path, $id, TRUE);
  50. if ( $res instanceof bxIresource) {
  51. $resourceEditors = $res->getEditors();
  52. }
  53. }
  54. $pluginName = str_replace('bx_plugins_', '', get_class($this));
  55. $pluginEditors = $GLOBALS['POOL']->config->getEditorsByPlugin($pluginName);
  56. if(!empty($pluginEditors)) {
  57. $editors = array_intersect($pluginEditors, $resourceEditors);
  58. } else {
  59. $editors = $resourceEditors;
  60. }
  61. return $editors;
  62. }
  63. public function getMimeTypes() {
  64. return array();
  65. }
  66. public function getResourceTypes() {
  67. return array();
  68. }
  69. public function isRealResource($path, $id) {
  70. return false;
  71. }
  72. public function adminResourceExists($path, $id, $ext=null) {
  73. return false;
  74. }
  75. /** @bxIplugin::getContentUriById */
  76. public function getContentUriById($path, $id, $sample = false) {
  77. //FIXME... we do not have a Resource in the DB eventually...
  78. // take care of that here
  79. $res = $this->getResourceById($path,$id, $sample);
  80. if ($res instanceof bxIresource ) {
  81. if ($sample && $res->mock) {
  82. return $res->getContentUriSample();
  83. } else {
  84. return $res->getContentUri();
  85. }
  86. } else {
  87. return NULL;
  88. }
  89. }
  90. /** @bxIplugin::getResourceById
  91. *
  92. * NB: interface violation: adding mock
  93. * For weird situations when resource requested before created.
  94. * The only found call is $this->getEditorsById()
  95. *
  96. */
  97. public function getResourceById($path, $id, $mock = false) {
  98. return null;
  99. }
  100. public function resourceExistsById($path,$id) {
  101. if ($this->getResourceById($path,$id) instanceof bxIresource) {
  102. return true;
  103. }
  104. return false;
  105. }
  106. /**
  107. * Returns plugin-dependant parameters to pass into pipeline for specified resource
  108. *
  109. * @param path collection path
  110. * @param id resource id
  111. * @return array of parameters
  112. */
  113. public function getPipelineParametersById($path, $id) {
  114. return array();
  115. }
  116. public function stripRoot() {
  117. return false;
  118. }
  119. public function addResource($name, $parentUri, $options=array(), $resourceType = null) {
  120. return false;
  121. }
  122. public function deleteResourceById($path, $id) {
  123. $r = $this->getResourceById($path, $id);
  124. if (($r instanceof bx_resource) &&
  125. method_exists($r,"delete")) {
  126. return $r->delete();
  127. }
  128. return array();
  129. }
  130. public function copyResourceById($path, $id, $to, $move = false) {
  131. $r = $this->getResourceById($path, $id);
  132. if (($r instanceof bx_resource) &&
  133. method_exists($r,"copy")) {
  134. return $r->copy($to, $move);
  135. }
  136. return array();
  137. }
  138. /**
  139. * @return unix timestamp
  140. */
  141. public function getLastModifiedById($path, $id) {
  142. $res = $this->getResourceById($path,$id);
  143. if ($res) {
  144. return $res->getLastModified();
  145. }
  146. return NULL;
  147. }
  148. public function collectionCopy($point, $from, $to, $move) {
  149. return true;
  150. }
  151. public function collectionDelete($point, $dir) {
  152. return true;
  153. }
  154. public function getOverviewSections($path,$mainOverview) {
  155. return null;
  156. }
  157. protected function setOverviewTitle($dom,$title) {
  158. }
  159. /**
  160. * Returns a list of permissions for this plugin.
  161. * @return If an empty array is returned no permissions can be defined for this plugin.
  162. */
  163. public function getPermissionList() {
  164. return array();
  165. }
  166. public function getJavaScriptSources() {
  167. return $this->javascriptsources;
  168. }
  169. protected function setJavaScriptSource($src) {
  170. if (!in_array($src,$this->javascriptsources)) {
  171. $this->javascriptsources[] = $src;
  172. }
  173. }
  174. }
  175. ?>