mostly filebased Content Presentation System
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

125 lines
3.9KB

  1. <?php
  2. namespace Modules;
  3. class CEimage
  4. {
  5. public $r;
  6. public $b;
  7. public $structs;
  8. public $content;
  9. public $domains;
  10. function __construct($request,$body=[],$structs=false,$content=false,$domains=false) {
  11. $this->r = $request;
  12. $this->b = $body;
  13. $this->structs = &$structs;
  14. $this->content = &$content;
  15. $this->domains = &$domains;
  16. }
  17. function is_width($string) {
  18. $pattern="/^[0-9]+%$/";
  19. if (preg_match($pattern,$string)) {
  20. return true;
  21. } else {
  22. return false;
  23. }
  24. }
  25. function index() {
  26. $md = new \freaParsedown();
  27. $request = $this->r;
  28. $body = $this->b;
  29. $key=$request[1];
  30. $image="";
  31. $width=null;
  32. $format=false;
  33. $new="";
  34. // see if we can find image
  35. if ( is_file($request[1])) {
  36. $image= $request[1];
  37. } else if ($this->structs) {
  38. foreach($this->structs as $domain=>$destination) {
  39. if(array_key_exists($key, $this->structs[$domain]['pic'])) {
  40. $image = $this->structs[$domain]['pic'][$key];
  41. unset($this->structs[$domain]['pic'][$key]);
  42. unset($this->content[$this->domains[$domain]][$key]);
  43. break;
  44. }
  45. }
  46. }
  47. // image positioning
  48. if (count($request) >= 3) {
  49. if( in_array($request[2],array('left','right','full','auto'))) {
  50. $class = $request[2];
  51. } else {
  52. $class = 'left';
  53. }
  54. } else {
  55. $class = 'left';
  56. }
  57. if (isset($request[3])) {
  58. if (self::is_width($request[3])) {
  59. $width=$request[3];
  60. } elseif (in_array($request[3], ['png','jpg','jpeg','nocache'])) {
  61. $format=$request[3];
  62. }
  63. }
  64. if ($image) {
  65. $gallery = "gallery";
  66. // image orientation?
  67. $img = new \Image($image);
  68. // $ratio = "landscape";
  69. $ratio = ($img->width() >= $img->height())
  70. ? "landscape"
  71. : "portrait"
  72. ;
  73. unset($img);
  74. $cached = new CachedImage($image,$format);
  75. // identify if caption contains a copyright note
  76. // if so, indicate with a class
  77. foreach ($body as $k=>$line) {
  78. if (strpos($line,"©") !== FALSE
  79. || strpos($line,"&copy;") !== FALSE) {
  80. $body[$k] = sprintf("<span class=\"copyright\">%s</span>",$line);
  81. }
  82. }
  83. $new=sprintf("<div class='content_element_image %s'>"
  84. ."<div class=\"media %s\" %s><a href=\"%s\" class=\"$gallery\"><img src=\"%s\" alt=\"user supplied image\" /></a></div>"
  85. ."<img src=\"%s\" style=\"display:none;\" alt=\"user supplied image\" />"
  86. ."<div class=\"caption\">%s</div>"
  87. ."</div>",
  88. $class,
  89. $ratio,
  90. ($width ? "style=\"flex-basis:$width;\"" : ''),
  91. $cached->get_src(1600),
  92. $cached->get_src(1600),
  93. $cached->get_src(1600),
  94. $md->text(implode("\n",$body))
  95. );
  96. unset($cached);
  97. } else {
  98. // image not found
  99. $new=sprintf("<div class='content_element_image %s'>\n"
  100. ."<div class=\"media %s\">\n"
  101. ."<div class=\"caption\">\n%s\n</div>\n"
  102. ."</div>\n",
  103. $class,
  104. "landscape",
  105. $md->text(implode("\n",$body))
  106. );
  107. }
  108. return $new;
  109. }
  110. }