Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Fixes the encoding to uf8
- function fix_encoding($str)
- {
- $cur_encoding = mb_detect_encoding($str) ;
- if($cur_encoding == "UTF-8" && mb_check_encoding($str,"UTF-8"))
- return $str;
- else
- return utf8_encode($str);
- }
- function elgg_preview($excerpt, $width=420, $height=315, $comment=false) {
- if ($comment == true) {
- $cr='<br/>';
- } else {
- $cr='';
- }
- preg_match_all("#http.*://[^\s\\n]*#", $excerpt, $matches);
- foreach ($matches[0] as &$url) {
- //YOUTUBE
- if (strpos($url, "youtube") !== false
- || strpos($excerpt, "youtu.be") !== false) {
- preg_match("#\?v=([a-zA-Z0-9\-_]+)#", $url, $match);
- if ($match[1] == "") {
- preg_match("#youtu.be/([a-zA-Z0-9\-_]+)#", $url, $match);
- }
- $excerpt=str_replace($url, "<iframe frameborder=\"0\" width='$width' height='$height' allowfullscreen src=\"https://www.youtube.com/embed/$match[1]?html5=1&fs=1\"></iframe>$cr", $excerpt);
- continue;
- }
- //DAILYMOTION
- if (strpos($url, "dailymotion.com") !== false) {
- preg_match("#/video/([a-zA-Z0-9]+)#", $url, $match);
- $excerpt = str_replace($url, "<iframe frameborder=\"0\" width=\"$width\" height=\"$height\" allowfullscreen html src=\"https://www.dailymotion.com/embed/video/$match[1]\"></iframe>$cr", $excerpt);
- continue;
- }
- //VIMEO
- if (strpos($url, "vimeo") !== false) {
- preg_match("#vimeo.com/([0-9]+)#", $url, $match);
- $excerpt = str_replace($url, "<iframe frameborder=\"0\" width='$width' height='$height' allowfullscreen src=\"https://player.vimeo.com/video/$match[1]\"></iframe>$cr",$excerpt);
- continue;
- }
- //SOUNDCLOUD
- if (strpos($url, "soundcloud.com") !== false) {
- $excerpt = str_replace($url, "<iframe frameborder=\"0\" width=100% height=166 src=\"https://w.soundcloud.com/player/?url=$url&auto_play=false&color=915f33&theme_color=00FF00\"></iframe>$cr",$excerpt);
- continue;
- }
- //JAMENDO
- if (strpos($url, "jamendo.com") !== false) {
- if (strpos($url, "/track/") !== false) {
- preg_match("#/track/([0-9]*)#", $url, $match);
- $excerpt=str_replace($url, "<iframe id=\"widget\" scrolling=\"no\" frameborder=\"0\" width=\"400\" height=\"170\" src=\"//widgets.jamendo.com/v3/track/$match[1]?tracklist=true&width=400&tracklist_n=4\"></iframe>$cr", $excerpt);
- continue;
- } else if (strpos($url, "/list/") !== false) {
- preg_match("#/list/a([0-9]*)#", $url, $match);
- $excerpt=str_replace($url, "<iframe id=\"widget\" scrolling=\"no\" frameborder=\"0\" width=\"400\" height=\"310\" src=\"//widgets.jamendo.com/v3/album/$match[1]?tracklist=true&width=400&tracklist_n=4\"></iframe>$cr", $excerpt);
- continue;
- }
- }
- //IMG
- if (strpos($url, ".jpg") !== false
- ||strpos($url, ".jpeg") !== false
- ||strpos($url, ".png") !== false
- ||strpos($url, ".gif") !== false) {
- $excerpt=str_replace($url, "$cr<a rel=\"nofollow\" target=\"_blank\" href=\"$url\"><img src=\"$url\" alt=\"$url\"/ width=\"$width\"></a>$cr", $excerpt);
- continue;
- }
- //VIDEO
- if (strpos($url, ".ogv") !== false
- ||strpos($url, ".webm") !==false) {
- $excerpt=str_replace($url,"$cr<video width=\"$width\" controls=\"true\" src=$url>$url</video>$cr", $excerpt);
- continue;
- }
- //PHOTOFLOAT
- if (strpos($url, "https://*******.org/float/") !== false) {
- $excerpt=str_replace($url,"$cr<iframe frameborder=\"0\" width=\"500\" height=\"$height\" allowfullscreen html src=\"$url\"></iframe>$cr", $excerpt);
- continue;
- }
- //KELTROTH
- if (strpos($url, "http://photos.********.net/index.php") !== false) {
- $url_em = str_replace("index.php", "wechepa.php", $url);
- $html = file_get_contents($url_em);
- preg_match_all('/(http:\/\/photos.*******.net\/.*)/',$html, $result);
- foreach ($result[1] as &$img) {
- $imgs .= "<a rel=\"nofollow\" target=\"_blank\" href=\"$img\"><img width=\"490\" src=\"$img\"/></a>";
- }
- $divheight=$height+5;
- $excerpt=str_replace($url, "<div style=\"height:660px;width:510px;border:1px;overflow:auto;\">".$imgs."</div>", $excerpt);
- continue;
- }
- //LE RESTE
- $name=preg_replace("#/#", "_", $url);
- if (!file_exists("/var/www/www_data/url/title/$name")) {
- $html=file_get_contents($url);
- preg_match("#<title>\s*([^<\\n]*)\s*</title>#", $html, $mtitle);
- preg_match("#<\s*meta[^>]*[a-z]=\"(og:|)[dD]escription\"[^>]*>#", $html, $match);
- if ($match[0] != "") {
- preg_match("#content=\"([^\"]*)#", $match[0], $mdesc);
- if ($mdesc[1] != "") {
- $desc=fix_encoding($mdesc[1]);
- }
- }
- if ($mtitle[1] != "") {
- $title=fix_encoding($mtitle[1]);
- }
- file_put_contents("/var/www/www_data/url/title/$name", $title);
- file_put_contents("/var/www/www_data/url/desc/$name", $desc);
- } else {
- $title=file_get_contents("/var/www/www_data/url/title/$name");
- $desc=file_get_contents("/var/www/www_data/url/desc/$name");
- }
- if ($title != "") {
- if ($desc != "") {
- $desc="<br/><i class=\"extract\">$desc</i>";
- }
- $excerpt=str_replace($url, "<span style=\"display: inline-block;\" class=\"preview\"><a rel=\"nofollow\" target=\"_blank\" href=\"$url\">$title</a>$desc</span>$cr", $excerpt);
- }
- }
- preg_match('/.*\[:(.*)\].*/', $excerpt, $matches);
- if (sizeof($matches) >= 2) {
- $excerpt = preg_replace("/\[:(.*)\]/", "<a href=\"http://totoz.eu/img/$1\"><img src=\"http://totoz.eu/img/$1\" alt=\"$1\"/></a>", $excerpt);
- }
- return $excerpt;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement