Доп. функции

Wertos

Заблокирован
#1
Раз уж флудилка, можно попостить сюда наброски... а то разбросаны кучей по всему форуму... Тут хоть обновлять буду.
Функция определения торрент-клиента по peer_id
PHP:
function detect_torrent_client($peer_id)
{
// Based on http://wiki.theory.org/BitTorrentSpecification
// Last update by NetS 15/05/2009
if (substr($peer_id,0,3) == "-UT")
return "uTorrent ".$peer_id{3}.".".$peer_id{4}.".".$peer_id{5}.".".$peer_id{6};
else if (substr($peer_id,0,3) == "M6-")
return "Bittorrent 6.".$peer_id{3}.".".$peer_id{5};
else if (substr($peer_id,0,3) == "-AZ")
return "Azureus ".$peer_id{3}.".".$peer_id{4}.".".$peer_id{5}.".".$peer_id{6};
else if (substr($peer_id,0,3) == "-SP")
return "BitSpirit ".$peer_id{3}.".".$peer_id{4}.".".$peer_id{5}.".".$peer_id{6};
else if (substr($peer_id,0,3) == "-KT")
return "KTorrent ".$peer_id{3}.".".$peer_id{4}.".".$peer_id{5}.".".$peer_id{6};
else if (substr($peer_id,0,3) == "-TR")
return "Transmission ".$peer_id{3}.".".$peer_id{4}.".".$peer_id{5}.".".$peer_id{6};
else if (substr($peer_id,0,3) == "-BC")
return "BitComet ".$peer_id{3}.".".$peer_id{4}.".".$peer_id{5}.".".$peer_id{6};
else if (substr($peer_id,0,3) == "-LT")
return "Libtorrent ".$peer_id{3}.".".$peer_id{4}.".".$peer_id{5}.".".$peer_id{6};
else if (substr($peer_id,0,3) == "-lt")
return "libTorrent ".$peer_id{3}.".".$peer_id{4}.".".$peer_id{5}.".".$peer_id{6};
else if (substr($peer_id,0,3) == "-DE")
return "DelugeTorrent ".$peer_id{3}.".".$peer_id{4}.".".$peer_id{5}.".".$peer_id{6};
else if (substr($peer_id,0,4) == "exbc")
return "BitComet";
else if (substr($peer_id,0,2) == "M4" || substr($peer_id,0,2) == "M3")
return "Bittorrent ".str_replace("-",".",substr($peer_id,1,5));
else if (substr($peer_id,0,2) == "OP")
return "Opera build".substr($peer_id,2,4);
else if (substr($peer_id,0,3) == "-qB")
return "qBittorrent ".$peer_id{3}.".".$peer_id{4}.".".$peer_id{5}.".".$peer_id{6};
else if (substr($peer_id,0,3) == "-XL")
return "Xunlei ".$peer_id{3}.".".$peer_id{4}.".".$peer_id{5}.".".$peer_id{6};
else if (substr($peer_id,0,3) == "-OS")
return "OneSwarm ".$peer_id{4}.".".$peer_id{5};
else if (substr($peer_id,0,3) == "XBT")
return "XBT Client ".$peer_id{4}.".".$peer_id{5}.".".$peer_id{6};
else if (substr($peer_id,0,3) == "-BB")
return "BitBuddy".$peer_id{3}.".".$peer_id{4}.".".$peer_id{5}.".".$peer_id{6};
else if (substr($peer_id,0,3) == "-CT")
return "CTorrent ".$peer_id{3}.".".$peer_id{4}.".".$peer_id{5}.".".$peer_id{6};
else if (substr($peer_id,0,3) == "-MT")
return "MoonlightTorrent ".$peer_id{3}.".".$peer_id{4}.".".$peer_id{5}.".".$peer_id{6};
else if (substr($peer_id,0,3) == "-BX")
return "Bittorrent X ".$peer_id{3}.".".$peer_id{4}.".".$peer_id{5}.".".$peer_id{6};
else if (substr($peer_id,0,3) == "-TS")
return "TorrentStorm ".$peer_id{3}.".".$peer_id{4}.".".$peer_id{5}.".".$peer_id{6};
else if (substr($peer_id,0,3) == "-QT")
return "QT 4 ".$peer_id{3}.".".$peer_id{4}.".".$peer_id{5}.".".$peer_id{6};
else if (substr($peer_id,0,3) == "-BL")
return "BitLord ".$peer_id{3}.".".$peer_id{4}.".".$peer_id{5}.".".$peer_id{6};
else if (substr($peer_id,0,3) == "-SZ")
return "Shareaza ".$peer_id{3}.".".$peer_id{4}.".".$peer_id{5}.".".$peer_id{6};
else if (substr($peer_id,0,3) == "-RT")
return "Retriever ".$peer_id{3}.".".$peer_id{4}.".".$peer_id{5}.".".$peer_id{6};
else if (substr($peer_id,0,3) == "-LP")
return "Lphant ".$peer_id{3}.".".$peer_id{4}.".".$peer_id{5}.".".$peer_id{6};
else if (substr($peer_id,0,3) == "-TN")
return "TorrentDotNet ".$peer_id{3}.".".$peer_id{4}.".".$peer_id{5}.".".$peer_id{6};
else if (substr($peer_id,0,3) == "-SS")
return "SwarmScope ".$peer_id{3}.".".$peer_id{4}.".".$peer_id{5}.".".$peer_id{6};
else if (substr($peer_id,0,3) == "-XT")
return "XanTorrent ".$peer_id{3}.".".$peer_id{4}.".".$peer_id{5}.".".$peer_id{6};
else if (substr($peer_id,0,3) == "-BS")
return "BTSlave ".$peer_id{3}.".".$peer_id{4}.".".$peer_id{5}.".".$peer_id{6};
else if (substr($peer_id,0,3) == "-ZT")
return "ZipTorrent ".$peer_id{3}.".".$peer_id{4}.".".$peer_id{5}.".".$peer_id{6};
else if (substr($peer_id,0,3) == "-AR")
return "Artic ".$peer_id{3}.".".$peer_id{4}.".".$peer_id{5}.".".$peer_id{6};
else if (substr($peer_id,0,3) == "-SB")
return "Swiftbit ".$peer_id{3}.".".$peer_id{4}.".".$peer_id{5}.".".$peer_id{6};
else if (substr($peer_id,0,3) == "-MP")
return "MooPolice ".$peer_id{3}.".".$peer_id{4}.".".$peer_id{5}.".".$peer_id{6};
else if (substr($peer_id,0,1) == "S" && is_int(substr($peer_id,1,3)))
return "Shadow ".$peer_id{1}.".".$peer_id{2}.".".$peer_id{3};
else if (substr($peer_id,0,1) == "U" && is_int(substr($peer_id,1,3)))
return "UPnP NAT Bit Torrent ".$peer_id{1}.".".$peer_id{2}.".".$peer_id{3};
else if (substr($peer_id,0,1) == "T")
return "BitTornado ".$peer_id{1}.".".$peer_id{2}.".".$peer_id{3};
else if (substr($peer_id,0,1) == "O" && is_int(substr($peer_id,1,3)))
return "Osprey Permaseed ".$peer_id{1}.".".$peer_id{2}.".".$peer_id{3};
else
return "Unknown";
}

-------------------------------------------------------

BB Media, поддерживает сервисы
YouTube с превьюхой
Vimeo с превьюхой
RuTube с превьюхой
xyu (адалт) с превьюхой(????)
redtube (адалт) с превьюхой
xhamster (адалт) без превьюхи
mail.ru video(???) без превьюхи
Прямые ссылки на медиа файлы
avi,mpg,mp4,vob,3gp,mov,mov,mp3,wav,ogg,wma,ac3,aac
Использует плагин Windows Media Player(прикручивать флеш плеер посчитал нецелесообразным).
Превьюх нет, выдирать кадр из видео не хотелось... Вроде на phpFFMpeg делается... да ну нафиг...
fix !! youtube additional parameter (&feature=player_embedded#at=177 etc...)
fix !! add object2array function
update !! переход на новую версию кода для youtube
add !! mail.ru video
PHP:
function getMediaThumb($id, $type = '')
{
switch ($type) {
case 'vimeo':
$xml = simplexml_load_file('http://vimeo.com/api/v2/video/'.$id.'.xml');
return (string) $xml->video->thumbnail_small;
break;
case 'rutube':
$xml = simplexml_load_file(rawurlencode('http://rutube.ru/api/video/'.$id.'/?format=xml'));
return (string) $xml->thumbnail_url;
break;
case 'xyu':
$arg1 = mb_substr($id, 0, 2);
$arg2 = mb_substr($id, 2, 2);
$img_src = "http://cdn-i2.xyu.tv/{$arg1}/{$arg2}/{$id}/160x120/0000000001.jpg";
return (string) $img_src;
break;
case 'red':
$xml = simplexml_load_file('http://api.redtube.com/?data=redtube.Videos.getVideoById&video_id='.$id.'&output=xml&thumbsize=small','SimpleXMLElement', LIBXML_NOCDATA);
$img_ary = array();
foreach ($xml->thumbs as $item) {
$img_ary[] = object2array($item[0]);
}
return (string) $img_ary[0]['thumb'][0];
break;
case 'xhamster':
return 'images/xhm_no_th.jpg';
break;
case 'mail':
return 'images/mail_no_th.jpg';
break;
default:
return 'images/no_th.jpg';
}
}
function parseMedia($text)
{
$img_src = 'images/no_th.jpg';
$img_src_v = 'images/no_thm.jpg';
$img_src_a = 'images/no_tha.jpg';
$rand = make_rand_str(10);
// Start parse and replase YouTube
$patterns = '~
https?:// # Required scheme. Either http or https.
(?:[0-9A-Z-]+\.)? # Optional subdomain.
(?: # Group host alternatives.
youtu\.be/ # Either youtu.be,
| youtube\.com # or youtube.com followed by
\S* # Allow anything up to VIDEO_ID,
[^\w\-\s] # but char before ID is non-ID char.
) # End host alternatives.
([\w\-]{11}) # $1: VIDEO_ID is exactly 11 chars.
(?=[^\w\-]|$) # Assert next char is non-ID or EOS.
(?! # Assert URL is not pre-linked.
[?=&+%\w]* # Allow URL (query) remainder.
(?: # Group pre-linked alternatives.
[\'"][^<>]*> # Either inside a start tag,
| </a> # or inside <a> element text contents.
) # End recognized pre-linked alts.
) # End negative lookahead assertion.
[?=&+%\w-]?(.*)? # Consume any URL (query) remainder.
~ix'; 
$replacements = '<img id="ytimg_\\1_'.$rand.'" width="120px" height="90px" onclick="$(this).hide(); $(this).next(\'div\').css({\'display\' : \'block\'});" class="bbmedia clickable" src="http://img.youtube.com/vi/\\1/0.jpg" /><div style="display: none;" id="ytdiv_\\1_'.$rand.'"><iframe width="640" height="360" src="//www.youtube.com/embed/\\1" frameborder="0" allowfullscreen></iframe> <br /><a href="#" class="small bold" onclick="$(\'#ytdiv_\\1_'.$rand.'\').css({\'display\' : \'none\'}); $(\'#ytimg_\\1_'.$rand.'\').show();">Скрыть</a></div>';
$text = preg_replace($patterns, $replacements, $text);
// End parse and replase YouTube

// Start parse and replase vimeo
$patterns_vimeo = '~https?:\/\/(?:[\w]+\.)*vimeo\.com(?:[\/\w]*\/videos?)?\/([0-9]+)[^\s]*~ix';
if(preg_match($patterns_vimeo, $text, $out)) $img_src = getMediaThumb($out[1], 'vimeo');
$patterns = '~https?:\/\/(?:[\w]+\.)*vimeo\.com(?:[\/\w]*\/videos?)?\/([0-9]+)[^\s]*~ix';
$replacements = '<img id="viimg_\\1_'.$rand.'" width="120px" height="90px" onclick="$(this).hide(); $(this).next(\'div\').css({\'display\' : \'block\'});" class="bbmedia clickable" src="'.$img_src.'" /><div style="display: none;" id="vidiv_\\1_'.$rand.'"><iframe src="http://player.vimeo.com/video/\\1?byline=0&amp;portrait=0&amp;badge=0" width="640" height="360" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe><br /><a href="#" class="small bold" onclick="$(\'#vidiv_\\1_'.$rand.'\').css({\'display\' : \'none\'}); $(\'#viimg_\\1_'.$rand.'\').show();">Скрыть</a></div>';
$text = preg_replace($patterns, $replacements, $text);
// End parse and replase vimeo 

// Start parse and replase rutube
$patterns_rutube = '~https?:\/\/(?:[\w]+\.)*rutube\.ru/video/([A-Za-z0-9-_]{5,40})/~ix';
if(preg_match($patterns_rutube, $text, $out)) $img_src = getMediaThumb($out[1], 'rutube');
$patterns = '~https?:\/\/(?:[\w]+\.)*rutube\.ru/video/([A-Za-z0-9-_]{5,40})/~ix';
$replacements = '<img id="ruimg_\\1_'.$rand.'" width="120px" height="90px" onclick="$(this).hide(); $(this).next(\'div\').css({\'display\' : \'block\'});" class="bbmedia clickable" src="'.$img_src.'" /><div style="display: none;" id="rudiv_\\1_'.$rand.'"><iframe width="640" height="360" src="http://rutube.ru/video/embed/\\1" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowfullscreen scrolling="no"></iframe><br /><a href="#" class="small bold" onclick="$(\'#rudiv_\\1_'.$rand.'\').css({\'display\' : \'none\'}); $(\'#ruimg_\\1_'.$rand.'\').show();">Скрыть</a></div>';
$text = preg_replace($patterns, $replacements, $text);
// End parse and replase rutube

// Start parse and replase xyu.tv
$patterns_xuy = '~https?:\/\/(?:[\w]+\.)*xyu\.tv/video/([0-9]{1,10})(.*)~ix';
if(preg_match_all($patterns_xuy, $text, $out, PREG_SET_ORDER)) $img_src = getMediaThumb($out[0][1], 'xyu');
$patterns = '~https?:\/\/(?:[\w]+\.)*xyu\.tv/video/([0-9]{1,10})(.*)~ix';
$replacements = '<img id="xyimg_\\1_'.$rand.'" width="120px" height="90px" onclick="$(this).hide(); $(this).next(\'div\').css({\'display\' : \'block\'});" class="bbmedia clickable" src="'.$img_src.'" /><div style="display: none; id="xydiv_\\1_'.$rand.'""><iframe width="640" height="360" src="http://xuy.tv/embed/?id=\\1&autoplay=0&color=white&related=0" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowfullscreen scrolling="no"></iframe><br /><a href="#" class="small bold" onclick="$(\'#xydiv_\\1_'.$rand.'\').css({\'display\' : \'none\'}); $(\'#xyimg_\\1_'.$rand.'\').show();">Скрыть</a></div>';
$text = preg_replace($patterns, $replacements, $text);
// End parse and replase xyu.tv

// Start parse and replase redtube.com
$patterns_red = '~https?:\/\/(?:[\w]+\.)*redtube\.com/([0-9]{1,7})(.*)~ix';
if(preg_match_all($patterns_red, $text, $out, PREG_SET_ORDER)) $img_src = getMediaThumb($out[0][1], 'red');
$patterns = '~https?:\/\/(?:[\w]+\.)*redtube\.com/([0-9]{1,7})(.*)~ix';
$replacements = '<img id="reimg_\\1_'.$rand.'" width="120px" height="90px" onclick="$(this).hide(); $(this).next(\'div\').css({\'display\' : \'block\'});" class="bbmedia clickable" src="'.$img_src.'" /><div style="display: none;" id="rediv_\\1_'.$rand.'"><object height="360" width="640"><param name="allowfullscreen" value="true"><param name="AllowScriptAccess" value="always"><param name="movie" value="http://embed.redtube.com/player/"><param name="FlashVars" value="id=\\1&style=redtube&autostart=false"><embed src="http://embed.redtube.com/player/?id=\\1&style=redtube" allowfullscreen="true" AllowScriptAccess="always" flashvars="autostart=false" pluginspage="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" height="360" width="640" /></object><br /><a href="#" class="small bold" onclick="$(\'#rediv_\\1_'.$rand.'\').css({\'display\' : \'none\'}); $(\'#reimg_\\1_'.$rand.'\').show();">Скрыть</a></div>';
$text = preg_replace($patterns, $replacements, $text);
// End parse and replase redtube.com

// Start parse and replase xhamster.com
$patterns_xhm = '~https?:\/\/(?:[\w]+\.)*xhamster\.com/movies/([0-9]{1,10})/?(.*?)~ix';
if(preg_match_all($patterns_xhm, $text, $out, PREG_SET_ORDER)) $img_src = getMediaThumb($out[0][1], 'xhamster');
$patterns = '~https?:\/\/(?:[\w]+\.)*xhamster\.com/movies/([0-9]{1,10})/?(.*)~ix';
$replacements = '<img id="xhimg_\\1_'.$rand.'" width="120px" height="90px" onclick="$(this).hide(); $(this).next(\'div\').css({\'display\' : \'block\'});" class="bbmedia clickable" src="'.$img_src.'" /><div style="display: none;" id="xhdiv_\\1_'.$rand.'"><iframe width="640" height="360" src="http://xhamster.com/xembed.php?video=\\1" frameborder="0" scrolling="no"></iframe><br /><a href="#" class="small bold" onclick="$(\'#xhdiv_\\1_'.$rand.'\').css({\'display\' : \'none\'}); $(\'#xhimg_\\1_'.$rand.'\').show();">Скрыть</a></div>';
$text = preg_replace($patterns, $replacements, $text);
// End parse and replase xhamster.com

// Start parse and replase video.mail.ru
$patterns_mail = '~https?:\/\/(?:[\w]+\.)*video\.mail\.ru/lvi/([0-9]{1,5})\.html~ix';
if(preg_match_all($patterns_mail, $text, $out, PREG_SET_ORDER))
{
$img_src = getMediaThumb($out[0][1], 'mail');
$replacements = '<img id="mailimg_\\1_'.$rand.'" width="120px" height="90px" onclick="$(this).hide(); $(this).next(\'div\').css({\'display\' : \'block\'});" class="bbmedia clickable" src="'.$img_src.'" /><div style="display: none;" id="maildiv_\\1_'.$rand.'"><object width="640" height="360" type="application/x-shockwave-flash" data="http://img.mail.ru/r/video2/player_v2.swf?3"><param name="movie" value="http://img.mail.ru/r/video2/player_v2.swf?3"><param name="flashvars" value="movieSrc=lvi/\\1"><param name="devicefont" value="false"><param name="menu" value="false"><param name="allowFullScreen" value="true"><param name="allowScriptAccess" value="always"></object><br /><a href="#" class="small bold" onclick="$(\'#maildiv_\\1_'.$rand.'\').css({\'display\' : \'none\'}); $(\'#mailimg_\\1_'.$rand.'\').show();">Скрыть</a></div>';
$text = preg_replace($patterns_mail, $replacements, $text);
}
// End parse and replase video.mail.ru

// Start parse and replase media files
$patterns_media = '~((http|ftp|https|ftps)://)([^\s\?&=\#\"<>]+?(\.(avi|mpg|mp4|vob|3gp|mov|wmv|flv)))~si';
if(preg_match_all($patterns_media, $text, $out, PREG_SET_ORDER))
{
$replacements = '<img id="medimg_\\2_'.$rand.'" width="120px" height="90px" onclick="$(this).hide(); $(this).next(\'div\').css({\'display\' : \'block\'});" class="bbmedia clickable" src="'.$img_src_v.'" /><div style="display: none;" id="meddiv_\\2_'.$rand.'"><object width="640"height="360" type="application/x-oleobject" classid="clsid:22d6f312-b0f6-11d0-94ab-0080c74c7e95" codebase="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#version=5,1,52,701"><param name="filename" value="\\1\\3"><param name="transparentatstart" value="false"><param name="autostart" value="false"><param name="showcontrols" value="true"><param name="showtracker" value="false"><param name="showaudiocontrols" value="true"><param name="showstatusbar" value="true"><embed type="application/x-mplayer2"width="640" height="360" src="\\1\\3" autostart="0" showstatusbar="1" showdisplay="0" showcontrols="1" controltype="1" showtracker="1" pluginspage="http://www.microsoft.com/windows/downloads/contents/products/mediaplayer/"></embed></object><br /><a href="#" class="small bold" onclick="$(\'#meddiv_\\2_'.$rand.'\').css({\'display\' : \'none\'}); $(\'#medimg_\\2_'.$rand.'\').show();">Скрыть</a></div>';
$text = preg_replace($patterns_media, $replacements, $text);
}
// End parse and replase media files

// Start parse and replase audio files
$patterns_audio = '~((http|ftp|https|ftps)://)([^\s\?&=\#\"<>]+?(\.(mp3|wav|ogg|wma|ac3|aac)))~si';
if(preg_match_all($patterns_audio, $text, $out, PREG_SET_ORDER))
{
$replacements = '<img id="audimg_\\2_'.$rand.'" width="120px" height="90px" onclick="$(this).hide(); $(this).next(\'div\').css({\'display\' : \'block\'});" class="bbmedia clickable" src="'.$img_src_a.'" /><div style="display: none;" id="auddiv_\\2_'.$rand.'"><object classid="CLSID:22d6f312-b0f6-11d0-94ab-0080c74c7e95" id="mediaplayer1" height="45" width="310"><param name="Filename" value="\\1\\3"><param name="AutoStart" value="False"><param name="ShowControls" value="True"><param name="ShowStatusBar" value="False"><param name="ShowDisplay" value="False"><param name="AutoRewind" value="True"><embed type="application/x-mplayer2" pluginspage="http://www.microsoft.com/Windows/Downloads/Contents/MediaPlayer/" src="\\1\\3" autostart="0" showcontrols="1" showstatusbar="0" showdisplay="0" autorewind="1" height="45" width="210"></embed></object><br /><a href="#" class="small bold" onclick="$(\'#auddiv_\\2_'.$rand.'\').css({\'display\' : \'none\'}); $(\'#audimg_\\2_'.$rand.'\').show();">Скрыть</a></div>';
$text = preg_replace($patterns_audio, $replacements, $text);
}
// End parse and replase audio files

return $text;
}

function object2array($object)
{
    return json_decode(json_encode($object),1);
}
css
HTML:
/**
*
* BB Media
*
*/
.bbmedia {
  background:transparent;
  border:6px solid #ABABAB;
  -webkit-border-radius: 3px;
  -moz-border-radius: 3px;
  border-radius: 3px;
  padding:1px;
  margin:3px 3px 3px 0;
}

-------------------------------------------------------

Перечёркнутый ник с XBTT аннонсером (реализация под ?)
PHP:
          $update_time = (TIMENOW > ($peer['update_time'] + $bb_cfg['announce_interval']));
          $name    = ($update_time) ? '<a href="'. $u_prof_href .'" style="text-decoration: line-through !important;" class="'. $link_class .'">'. wbr($peer['username']) .'</a>'. $rel_sign : '<a href="'. $u_prof_href .'" class="'. $link_class .'">'. wbr($peer['username']) .'</a>'. $rel_sign;
и
PHP:
            'NAME'        => $name,
 

Вложения

Сверху