PageRenderTime 46ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/inc/bx/plugins/image.php

https://github.com/chregu/fluxcms
PHP | 68 lines | 53 code | 14 blank | 1 comment | 10 complexity | 3a74c6b1bce7276694fdbd863ed8ffb3 MD5 | raw file
Possible License(s): GPL-2.0, BSD-3-Clause, Apache-2.0, LGPL-2.1
  1. <?php
  2. class bx_plugins_image extends bx_plugin {
  3. static private $instance = array();
  4. static private $idMapper = null;
  5. public static function getInstance($mode) {
  6. if (!isset(bx_plugins_image::$instance[$mode])) {
  7. bx_plugins_image::$instance[$mode] = new bx_plugins_image($mode);
  8. }
  9. return bx_plugins_image::$instance[$mode];
  10. }
  11. public function getIdByRequest($path, $name = NULL, $ext = NULL) {
  12. if (!isset($this->idMapper[$path.$name])) {
  13. if (file_exists(BX_DATA_DIR.$path.$name.".".$ext)) {
  14. $this->idMapper[$path.$name] = $name.".".$ext;
  15. }
  16. }
  17. return $this->idMapper[$path.$name];
  18. }
  19. public function getPipelineParametersById($path = NULL, $id = NULL) {
  20. // FIXME, we need another resource reader, it doesn't work if request != id
  21. return array('pipelineName'=>'resourceReader');
  22. }
  23. public function isRealResource($path , $id) {
  24. return true;
  25. }
  26. public function getResourceById($path,$id, $mock = false) {
  27. $id = $path.$id;
  28. if (!isset($this->res[$id])) {
  29. if (file_exists(BX_DATA_DIR.$id)) {
  30. $this->res[$id] = new bx_resources_image_image($id);
  31. } else if ($mock) {
  32. $this->res[$id] = new bx_resources_image_image($id, $mock);
  33. } else {
  34. $this->res[$id] = null;
  35. }
  36. }
  37. return $this->res[$id];
  38. }
  39. public function adminResourceExists($path, $id, $ext=null, $sample = false) {
  40. switch (strtolower($ext)) {
  41. case "jpg":
  42. case "jpeg":
  43. case "gif":
  44. case "png":
  45. $res = $this->getResourceById($path, $id.".".$ext,$sample);
  46. if ($res) {
  47. return $this;
  48. }
  49. default:
  50. return null;
  51. }
  52. }
  53. }
  54. ?>