Advertisement
Guest User

Untitled

a guest
Feb 21st, 2014
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.33 KB | None | 0 0
  1. // Fixes the encoding to uf8
  2. function fix_encoding($str)
  3. {
  4. $cur_encoding = mb_detect_encoding($str) ;
  5. if($cur_encoding == "UTF-8" && mb_check_encoding($str,"UTF-8"))
  6. return $str;
  7. else
  8. return utf8_encode($str);
  9. }
  10.  
  11. function elgg_preview($excerpt, $width=420, $height=315, $comment=false) {
  12.  
  13. if ($comment == true) {
  14. $cr='<br/>';
  15. } else {
  16. $cr='';
  17. }
  18.  
  19. preg_match_all("#http.*://[^\s\\n]*#", $excerpt, $matches);
  20. foreach ($matches[0] as &$url) {
  21.  
  22. //YOUTUBE
  23. if (strpos($url, "youtube") !== false
  24. || strpos($excerpt, "youtu.be") !== false) {
  25. preg_match("#\?v=([a-zA-Z0-9\-_]+)#", $url, $match);
  26. if ($match[1] == "") {
  27. preg_match("#youtu.be/([a-zA-Z0-9\-_]+)#", $url, $match);
  28. }
  29. $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);
  30. continue;
  31. }
  32.  
  33. //DAILYMOTION
  34. if (strpos($url, "dailymotion.com") !== false) {
  35. preg_match("#/video/([a-zA-Z0-9]+)#", $url, $match);
  36. $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);
  37. continue;
  38. }
  39.  
  40. //VIMEO
  41. if (strpos($url, "vimeo") !== false) {
  42. preg_match("#vimeo.com/([0-9]+)#", $url, $match);
  43. $excerpt = str_replace($url, "<iframe frameborder=\"0\" width='$width' height='$height' allowfullscreen src=\"https://player.vimeo.com/video/$match[1]\"></iframe>$cr",$excerpt);
  44. continue;
  45. }
  46.  
  47. //SOUNDCLOUD
  48. if (strpos($url, "soundcloud.com") !== false) {
  49. $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);
  50. continue;
  51. }
  52.  
  53. //JAMENDO
  54. if (strpos($url, "jamendo.com") !== false) {
  55. if (strpos($url, "/track/") !== false) {
  56. preg_match("#/track/([0-9]*)#", $url, $match);
  57. $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);
  58. continue;
  59. } else if (strpos($url, "/list/") !== false) {
  60. preg_match("#/list/a([0-9]*)#", $url, $match);
  61. $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);
  62. continue;
  63. }
  64. }
  65.  
  66. //IMG
  67. if (strpos($url, ".jpg") !== false
  68. ||strpos($url, ".jpeg") !== false
  69. ||strpos($url, ".png") !== false
  70. ||strpos($url, ".gif") !== false) {
  71.  
  72. $excerpt=str_replace($url, "$cr<a rel=\"nofollow\" target=\"_blank\" href=\"$url\"><img src=\"$url\" alt=\"$url\"/ width=\"$width\"></a>$cr", $excerpt);
  73. continue;
  74.  
  75. }
  76.  
  77. //VIDEO
  78. if (strpos($url, ".ogv") !== false
  79. ||strpos($url, ".webm") !==false) {
  80. $excerpt=str_replace($url,"$cr<video width=\"$width\" controls=\"true\" src=$url>$url</video>$cr", $excerpt);
  81. continue;
  82. }
  83.  
  84. //PHOTOFLOAT
  85. if (strpos($url, "https://*******.org/float/") !== false) {
  86. $excerpt=str_replace($url,"$cr<iframe frameborder=\"0\" width=\"500\" height=\"$height\" allowfullscreen html src=\"$url\"></iframe>$cr", $excerpt);
  87. continue;
  88. }
  89.  
  90. //KELTROTH
  91. if (strpos($url, "http://photos.********.net/index.php") !== false) {
  92. $url_em = str_replace("index.php", "wechepa.php", $url);
  93. $html = file_get_contents($url_em);
  94. preg_match_all('/(http:\/\/photos.*******.net\/.*)/',$html, $result);
  95. foreach ($result[1] as &$img) {
  96. $imgs .= "<a rel=\"nofollow\" target=\"_blank\" href=\"$img\"><img width=\"490\" src=\"$img\"/></a>";
  97. }
  98. $divheight=$height+5;
  99. $excerpt=str_replace($url, "<div style=\"height:660px;width:510px;border:1px;overflow:auto;\">".$imgs."</div>", $excerpt);
  100. continue;
  101. }
  102.  
  103. //LE RESTE
  104. $name=preg_replace("#/#", "_", $url);
  105. if (!file_exists("/var/www/www_data/url/title/$name")) {
  106. $html=file_get_contents($url);
  107. preg_match("#<title>\s*([^<\\n]*)\s*</title>#", $html, $mtitle);
  108. preg_match("#<\s*meta[^>]*[a-z]=\"(og:|)[dD]escription\"[^>]*>#", $html, $match);
  109.  
  110. if ($match[0] != "") {
  111. preg_match("#content=\"([^\"]*)#", $match[0], $mdesc);
  112. if ($mdesc[1] != "") {
  113. $desc=fix_encoding($mdesc[1]);
  114. }
  115. }
  116. if ($mtitle[1] != "") {
  117. $title=fix_encoding($mtitle[1]);
  118. }
  119. file_put_contents("/var/www/www_data/url/title/$name", $title);
  120. file_put_contents("/var/www/www_data/url/desc/$name", $desc);
  121.  
  122. } else {
  123. $title=file_get_contents("/var/www/www_data/url/title/$name");
  124. $desc=file_get_contents("/var/www/www_data/url/desc/$name");
  125. }
  126.  
  127. if ($title != "") {
  128. if ($desc != "") {
  129. $desc="<br/><i class=\"extract\">$desc</i>";
  130. }
  131. $excerpt=str_replace($url, "<span style=\"display: inline-block;\" class=\"preview\"><a rel=\"nofollow\" target=\"_blank\" href=\"$url\">$title</a>$desc</span>$cr", $excerpt);
  132. }
  133. }
  134.  
  135. preg_match('/.*\[:(.*)\].*/', $excerpt, $matches);
  136. if (sizeof($matches) >= 2) {
  137. $excerpt = preg_replace("/\[:(.*)\]/", "<a href=\"http://totoz.eu/img/$1\"><img src=\"http://totoz.eu/img/$1\" alt=\"$1\"/></a>", $excerpt);
  138. }
  139.  
  140. return $excerpt;
  141. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement