|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109 |
- <?php
-
- namespace Modules;
-
- class CEimage
- {
- public $r;
- public $b;
- public $structs;
- public $content;
-
- function __construct($request,$body=[],$structs=false,$content=false) {
- $this->r = $request;
- $this->b = $body;
- $this->structs = &$structs;
- $this->content = &$content;
- }
-
- function is_width($string) {
- $pattern="/^[0-9]+%$/";
- if (preg_match($pattern,$string)) {
- return true;
- } else {
- return false;
- }
- }
- function index() {
- $md = new \freaParsedown();
- $request = $this->r;
- $body = $this->b;
- $key=$request[1];
- $image="";
- $new="";
-
- // see if we can find image
- if ( is_file($request[1])) {
- $image= $request[1];
- } else if ($this->structs) {
- foreach($this->structs as $domain=>$destination) {
- if(array_key_exists($key, $this->structs[$domain]['pic'])) {
- $image = $this->structs[$domain]['pic'][$key];
- unset($this->structs[$domain]['pic'][$key]);
- unset($this->content[$this->domains[$domain]][$key]);
- break;
- }
- }
- }
-
- if ($image) {
-
- // image positioning
- if( in_array($request[2],array('left','right','full','auto'))) {
- $class = $request[2];
- } else {
- $class = 'full';
- }
- if (isset($request[3])) {
- $width=self::is_width($request[3]) ? $request[3] : false;
- }
- $gallery = "gallery";
- // image orientation?
- $img = new \Image($image);
- // $ratio = "landscape";
- $ratio = ($img->width() >= $img->height())
- ? "landscape"
- : "portrait"
- ;
- unset($img);
- $cached = new CachedImage($image);
-
- // identify if caption contains a copyright note
- // if so, indicate with a class
- foreach ($body as $k=>$line) {
- if (strpos($line,"©") !== FALSE
- || strpos($line,"©") !== FALSE) {
- $body[$k] = sprintf("<span class=\"copyright\">%s</span>",$line);
- }
- }
-
- $new=sprintf("<div class='content_element_image %s'>"
- ."<div class=\"media %s\" %s><a href=\"%s\" class=\"$gallery\"><img src=\"%s\" alt=\"user supplied image\" /></a></div>"
- ."<img src=\"%s\" style=\"display:none;\" alt=\"user supplied image\" />"
- ."<div class=\"caption\">%s</div>"
- ."</div>",
- $class,
- $ratio,
- ($width ? "style=\"flex-basis:$width;\"" : ''),
- $cached->get_src(1600),
- $cached->get_src(1600),
- $cached->get_src(1600),
- $md->text(implode("\n",$body))
- );
- unset($cached);
- } else {
- // image not found
- $new=sprintf("<div class='content_element_image %s'>\n"
- ."<div class=\"media %s\">\n"
- ."<div class=\"caption\">\n%s\n</div>\n"
- ."</div>\n",
- $class,
- $ratio,
- $md->text(implode("\n",$body))
- );
- }
-
- return $new;
- }
- }
-
|