mostly filebased Content Presentation System
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

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