more && $this->from < 0 && $this->more = preg_match('/^\[\[(images?|slider|videos?|audios?|embed|thumbnails?) ?(([^\]"\'\n\r]+|[\r\n]+|"(([^\\\\"]+|\\\\(.|[\r\n]))*)"|\'(([^\\\\\']+|\\\\(.|[\r\n]))*)\'|\][^\]])+)\]\]/m', $string, $this->matches, PREG_OFFSET_CAPTURE) ) $this->from = $this->matches[0][1]; } private static function multimedia_box($html, $multiple){ return '
' . $html . '
'; } public function image($data){ if(!$data) return ''; $images; $text; if(is_string($data)){ if(!preg_match('/^(\[(([^\\\\\]]+|\\\\(.|[\r\n]))*)\]|[^ ]+)( (.+))?$/', trim($data), $matches)) return ''; $images = $matches[1][0] == "[" ? json_decode($matches[1], true) : [$matches[1]]; $text = isset($matches[6]) ? $matches[6] : null; }else{ if(isset($data[0])) $data = ["images" => $data]; $images = $data["images"]; $text = isset($data["text"]) && $data["text"] ? $data["text"] : null; }; $html = ''; $image_text = $text ? $text : "image"; foreach($images as $image) $html .= '' . $image_text . ''; return (' ' . $text . ' ' . ($text !== null ? '' . $text . '' : '') . ' '); } public function images($data){ return preg_replace_callback('/^([\s\t]+)?(\[(([^\\\\\[\]"\'\r\n]+|"(([^\\\\"\r\n]+|\\\\(.|[\r\n]))*)"|\'(([^\\\\\'\r\n]+|\\\\(.|[\r\n]))*)\'|\\\\(.|[\n\r])|[\r\n])*)\]|[^\r\n]+)( ([^\r\n]+)?)?[\r\n]?$/m', function($values){ return ($string = trim($values[0])) ? $this->image($string) : ""; }, $data); } public function video($data){ if(!$data) return ''; $videos; $posters; $text; if(is_string($data)){ if(!preg_match('/^(\[(([^\\\\\]]+|\\\\(.|[\r\n]))*)\]|[^ ]+)( (\[(([^\\\\\[]+|\\\\(.|[\r\n]))*)\]|[a-z][a-z\d]{2,}\:\/{2}[^ ]+))?( (.+))?$/im', trim($data), $matches)) return ''; $videos = $matches[1][0] == "[" ? json_decode($matches[1], true) : [$matches[1]]; $posters = isset($matches[6]) && $matches[6] ? ($matches[6][0] == "[" ? json_decode($matches[6], true) : [$matches[6]]) : null; $text = isset($matches[11]) && $matches[11] ? $matches[11] : null; }else{ if(isset($data[0])) $data = ["videos" => $data]; $videos = $data["videos"]; $posters = isset($data["posters"]) ? $data["posters"] : null; $text = isset($data["text"]) ? $data["text"] : null; }; $html = ''; $video_text = $text ? $text : "video"; foreach($videos as $video) $html .= (' '); return (' ' . ($text !== null ? '' . $text . '' : null) . ' '); } public function videos($data){ return preg_replace_callback('/^([\s\t]+)?(\[(([^\\\\\[]+|\\\\(.|[\n\r]))*)\]|[^ ]+)( (\[(([^\\\\\[]+|\\\\(.|[\n\r]))*)\]|[a-z][a-z\d]{2,}\:\/{2}[^ ]+))?( (.+)?)?/im', function($values){ return $this->video($values[0]); }, $data); } private function audio_poster($data){ return self::multimedia_box($this->image($data), false); } public function audio($data, $multiple = null){ if(!$data) return ''; $audios; $posters; $text; if(is_string($data)){ if(!preg_match('/^(\[(([^\\\\\]]+|\\\\(.|[\r\n]))*)\]|[^ ]+)( (\[(([^\\\\\[]+|\\\\(.|[\r\n]))*)\]|[a-z][a-z\d]{2,}\:\/{2}[^ ]+))?( (.+))?$/im', trim($data), $matches)) return ''; $audios = $matches[1][0] == "[" ? json_decode($matches[1], true) : [$matches[1]]; $posters = isset($matches[6]) && $matches[6] ? ($matches[6][0] == "[" ? json_decode($matches[6], true) : [$matches[6]]) : null; $text = isset($matches[11]) && $matches[11] ? $matches[11] : null; }else{ if(isset($data[0])) $data = ["audios" => $data]; $audios = $data["audios"]; $posters = isset($data["posters"]) ? $data["posters"] : null; $text = isset($data["text"]) ? $data["text"] : null; }; $html = ''; $audio_text = $text ? $text : "audio"; foreach($audios as $audio) $html .= (' '); return (' ' . (!empty($posters) ? $this->audio_poster([ "images" => $posters, "text" => $text ], $multiple) : ($text !== null ? '' . $text . '' : null)) . ' '); } public function audios($data){ return preg_replace_callback('/^([\s\t]+)?(\[(([^\\\\\[]+|\\\\(.|[\n\r]))*)\]|[^ ]+)( (\[(([^\\\\\[]+|\\\\(.|[\n\r]))*)\]|[a-z][a-z\d]{2,}\:\/{2}[^ ]+))?( (.+)?)?/im', function($values){ return $this->audio($values[0], true); }, $data); } private static function check($matches, $is){ if(!$matches || count($matches) < 2) return null; foreach(is_array($is) ? $is : [$is] as $i) if(isset($matches[$i]) && $matches[$i]) return $i; return null; } public function embed($links){ if(!$links) return ''; if(!is_array($links)) $links = preg_split('/[\r\n]+/', "" . $links); $html = ''; $j = 0; foreach($links as $link){ if(!($link = trim($link))) continue; $j ++; if(preg_match('/^https?\:\/{2}(www\.)?(youtube\.com\/(embed\/|(((?![\?\&]v\=).)+)?[\?\&]v\=)([^\/\&]+)|youtu\.be\/([^\/\&\?]+))/', $link, $matches) && ($i = self::check($matches, [6, 7]))) $html .= (' '); elseif(preg_match('/^https?\:\/{2}((www|player)\.)?vimeo\.com\/(video\/)?(\d+)/', $link, $matches) && ($i = self::check($matches, [4]))) $html .= (' '); elseif(preg_match('/^https?\:\/{2}(www\.)?facebook\.com\/((?!\/videos\/).)+\/videos\/(\d+)/', $link, $matches) && ($i = self::check($matches, [3]))) $html .= (' '); elseif(preg_match('/^https?\:\/{2}((www|player)\.)?twitch\.(com|tv)\/(videos\/|\?video\=)(\d+)/', $link, $matches) && ($i = self::check($matches, [5]))) $html .= (' '); else $j --; }; return '' . $html . ''; } /*public static function process($wmarkdown, $key, $data, $multiple = null){ return '
' . ( $data && method_exists('\WMarkDown\Modules\Multimedia', $key) ? \call_user_func('\WMarkDown\Modules\Multimedia::' . $key, $wmarkdown, $data) : '' ) . '
'; }*/ public function thumbnails($data){ // print_r($data); return ""; } public function process($string, $modules, $level){ $method = $this->matches[1][0]; // if($method == "images") // print_r($this->matches); // $this->html = self::process($this->wmarkdown, $this->matches[1][0], $this->matches[2][0]); $this->html = self::multimedia_box($this->matches[2][0] && method_exists($this, $method) ? $this->$method($this->matches[2][0]) : '', $method[strlen($method) - 1] == "s"); $this->length = strlen($this->matches[0][0]); $this->to = $this->from + $this->length; $this->content = $this->matches[2][0]; } };