r = $request; $this->b = $body; $this->structs = &$structs; $this->content = &$content; $this->domains = &$domains; } 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; } } } // 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; } if ($image) { $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("%s",$line); } } $new=sprintf("
" ."
\"user
" ."\"user" ."
%s
" ."
", $class, $ratio, (isset($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("
\n" ."
\n" ."
\n%s\n
\n" ."
\n", $class, "landscape", $md->text(implode("\n",$body)) ); } return $new; } }