mostly filebased Content Presentation System
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

114 行
3.6KB

  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. $new="";
  32. // see if we can find image
  33. if ( is_file($request[1])) {
  34. $image= $request[1];
  35. } else if ($this->structs) {
  36. foreach($this->structs as $domain=>$destination) {
  37. if(array_key_exists($key, $this->structs[$domain]['pic'])) {
  38. $image = $this->structs[$domain]['pic'][$key];
  39. unset($this->structs[$domain]['pic'][$key]);
  40. unset($this->content[$this->domains[$domain]][$key]);
  41. break;
  42. }
  43. }
  44. }
  45. // image positioning
  46. if( in_array($request[2],array('left','right','full','auto'))) {
  47. $class = $request[2];
  48. } else {
  49. $class = 'full';
  50. }
  51. if (isset($request[3])) {
  52. $width=self::is_width($request[3]) ? $request[3] : null;
  53. }
  54. if ($image) {
  55. $gallery = "gallery";
  56. // image orientation?
  57. $img = new \Image($image);
  58. // $ratio = "landscape";
  59. $ratio = ($img->width() >= $img->height())
  60. ? "landscape"
  61. : "portrait"
  62. ;
  63. unset($img);
  64. $cached = new CachedImage($image);
  65. // identify if caption contains a copyright note
  66. // if so, indicate with a class
  67. foreach ($body as $k=>$line) {
  68. if (strpos($line,"©") !== FALSE
  69. || strpos($line,"&copy;") !== FALSE) {
  70. $body[$k] = sprintf("<span class=\"copyright\">%s</span>",$line);
  71. }
  72. }
  73. $new=sprintf("<div class='content_element_image %s'>"
  74. ."<div class=\"media %s\" %s><a href=\"%s\" class=\"$gallery\"><img src=\"%s\" alt=\"user supplied image\" /></a></div>"
  75. ."<img src=\"%s\" style=\"display:none;\" alt=\"user supplied image\" />"
  76. ."<div class=\"caption\">%s</div>"
  77. ."</div>",
  78. $class,
  79. $ratio,
  80. (isset($width) ? "style=\"flex-basis:$width;\"" : ''),
  81. $cached->get_src(1600),
  82. $cached->get_src(1600),
  83. $cached->get_src(1600),
  84. $md->text(implode("\n",$body))
  85. );
  86. unset($cached);
  87. } else {
  88. // image not found
  89. $new=sprintf("<div class='content_element_image %s'>\n"
  90. ."<div class=\"media %s\">\n"
  91. ."<div class=\"caption\">\n%s\n</div>\n"
  92. ."</div>\n",
  93. $class,
  94. "landscape",
  95. $md->text(implode("\n",$body))
  96. );
  97. }
  98. return $new;
  99. }
  100. }