本文整理汇总了PHP中benc函数的典型用法代码示例。如果您正苦于以下问题:PHP benc函数的具体用法?PHP benc怎么用?PHP benc使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了benc函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: benc
function benc($str)
{
if (is_string($str)) {
//string
return strlen($str) . ':' . $str;
}
if (is_numeric($str)) {
//integer
return 'i' . $str . 'e';
}
if (is_array($str)) {
$ret_str = '';
//the return string
$k = key($str);
//we check the 1st key, if the key is 0 then is a list if not a dictionary
foreach ($str as $var => $val) {
if ($k) {
//is dictionary
$ret_str .= benc($var);
//bencode the var
}
$ret_str .= benc($val);
//we recursivly bencode the contents
}
if ($k) {
//is dictionary
return 'd' . $ret_str . 'e';
}
return 'l' . $ret_str . 'e';
}
}
示例2: benc_list
function benc_list($a)
{
$s = 'l';
foreach ($a as $e) {
$s .= benc($e);
}
$s .= 'e';
return $s;
}
示例3: benc_dict
function benc_dict($d)
{
$s = "d";
$keys = array_keys($d);
sort($keys);
foreach ($keys as $k) {
$v = $d[$k];
$s .= benc_str($k);
$s .= benc($v);
}
$s .= "e";
return $s;
}
示例4: bark
// ///////////////////////////END///////////////////////////////////
if (!$ret) {
if (mysql_errno() == 1062) {
bark("#{$i} torrent was already uploaded!");
}
bark("mysql puked: " . mysql_error());
}
$id = mysql_insert_id();
$ids[] = $id;
@mysql_query("DELETE FROM files WHERE torrent = {$id}");
foreach ($filelist as $file) {
@mysql_query("INSERT INTO files (torrent, filename, size) VALUES ({$id}, " . sqlesc($file[0]) . "," . $file[1] . ")");
}
$fp = fopen("{$torrent_dir}/{$id}.torrent", "w");
if ($fp) {
@fwrite($fp, benc($dict[$i]), strlen(benc($dict[$i])));
fclose($fp);
}
// ===add karma
mysql_query("UPDATE users SET seedbonus = seedbonus+75.0 WHERE id = {$CURUSER['id']}") or sqlerr(__FILE__, __LINE__);
// ===end
// //////new torrent upload detail sent to shoutbox//////////
autoshout($message);
// ///////////////////////////end///////////////////////////////////
$i++;
}
function dict_check($d, $s)
{
// echo $d["type"];
// print_r($d);
if ($d["type"] != "dictionary") {
示例5: bark
if (!$ret) {
if (mysql_errno() == 1062) {
bark($lang_takeupload['std_torrent_existed']);
}
bark("mysql puked: " . mysql_error());
//bark("mysql puked: ".preg_replace_callback('/./s', "hex_esc2", mysql_error()));
}
$id = mysql_insert_id();
@sql_query("DELETE FROM files WHERE torrent = {$id}");
foreach ($filelist as $file) {
@sql_query("INSERT INTO files (torrent, filename, size) VALUES ({$id}, " . sqlesc($file[0]) . "," . $file[1] . ")");
}
//move_uploaded_file($tmpname, "$torrent_dir/$id.torrent");
$fp = fopen("{$torrent_dir}/{$id}.torrent", "w");
if ($fp) {
@fwrite($fp, benc($dict), strlen(benc($dict)));
fclose($fp);
}
//===add karma
KPS("+", $uploadtorrent_bonus, $CURUSER["id"]);
//===end
write_log("Torrent {$id} ({$torrent}) was uploaded by {$anon}");
//===notify people who voted on offer thanks CoLdFuSiOn :)
if ($is_offer) {
$res = sql_query("SELECT `userid` FROM `offervotes` WHERE `userid` != " . $CURUSER["id"] . " AND `offerid` = " . sqlesc($offerid) . " AND `vote` = 'yeah'") or sqlerr(__FILE__, __LINE__);
while ($row = mysql_fetch_assoc($res)) {
$pn_msg = $lang_takeupload_target[get_user_lang($row["userid"])]['msg_offer_you_voted'] . $torrent . $lang_takeupload_target[get_user_lang($row["userid"])]['msg_was_uploaded_by'] . $CURUSER["username"] . $lang_takeupload_target[get_user_lang($row["userid"])]['msg_you_can_download'] . "[url=" . get_protocol_prefix() . "{$BASEURL}/details.php?id={$id}&hit=1]" . $lang_takeupload_target[get_user_lang($row["userid"])]['msg_here'] . "[/url]";
//=== use this if you DO have subject in your PMs
$subject = $lang_takeupload_target[get_user_lang($row["userid"])]['msg_offer'] . $torrent . $lang_takeupload_target[get_user_lang($row["userid"])]['msg_was_just_uploaded'];
//=== use this if you DO NOT have subject in your PMs
//$some_variable .= "(0, $row[userid], '" . date("Y-m-d H:i:s") . "', " . sqlesc($pn_msg) . ")";
示例6: benc_resp
function benc_resp($d)
{
benc_resp_raw(benc(array(type => "dictionary", value => $d)));
}
示例7: bark
bark("mysql puked: " . mysql_error());
}
$id = mysql_insert_id();
@mysql_query("DELETE FROM files WHERE torrent = {$id}");
function file_list($arr, $id)
{
foreach ($arr as $v) {
$new[] = "({$id}," . sqlesc($v[0]) . "," . $v[1] . ")";
}
return join(",", $new);
}
mysql_query("INSERT INTO files (torrent, filename, size) VALUES " . file_list($filelist, $id));
//#Morgan: Instead of moving the uploaded torrent just create a new one with the simpler announce url
#move_uploaded_file($tmpname, "$torrent_dir/$id.torrent");
$morgan_fh = fopen("{$torrent_dir}/{$id}.torrent", 'w');
fwrite($morgan_fh, benc($my_dict));
fclose($morgan_fh);
write_log("Torrent {$id} ({$torrent}) was uploaded by " . $CURUSER["username"]);
/* RSS feeds */
require_once "rss_old.php";
/* Email notifs */
/*******************
$res = mysql_query("SELECT name FROM categories WHERE id=$catid") or sqlerr();
$arr = mysql_fetch_assoc($res);
$cat = $arr["name"];
$res = mysql_query("SELECT email FROM users WHERE enabled='yes' AND notifs LIKE '%[cat$catid]%'") or sqlerr();
$uploader = $CURUSER['username'];
$size = mksize($totallen);
$description = ($html ? strip_tags($descr) : $descr);
示例8: happyLog
happyLog($CURUSER["id"], $id, $multiplier);
mysql_query("INSERT INTO happyhour (userid, torrentid, multiplier ) VALUES (" . sqlesc($CURUSER["id"]) . " , " . sqlesc($id) . ", " . sqlesc($multiplier) . " )") or sqlerr(__FILE__, __LINE__);
}
// Passkey Mod
require_once "include/benc.php";
if ($row["vip"] == 'yes' && get_user_class() < UC_VIP) {
stdmsg("Sorry...", "You are not allowed to download this torrent");
exit;
}
$dict = bdec_file($fn, 1024 * 1024);
$dict['value']['announce']['value'] = "{$BASEURL}/announce.php?passkey={$CURUSER['passkey']}";
$dict['value']['announce']['string'] = strlen($dict['value']['announce']['value']) . ":" . $dict['value']['announce']['value'];
$dict['value']['announce']['strlen'] = strlen($dict['value']['announce']['string']);
// download as zip file by putyn tbdev
$name = str_replace(array(" ", ".", "-"), "_", $row["name"]);
$new = benc($dict);
$f = $torrent_dir . '/' . $name . '.torrent';
$newFile = fopen($f, "w");
fwrite($newFile, $new);
fclose($newFile);
$file = array();
$zip = new PHPZip();
$file[] = "{$f}";
$fName = "{$torrent_dir}/{$name}.zip";
$zip->Zip($file, $fName);
$zip->forceDownload($fName);
unlink($torrent_dir . '/' . $name . '.torrent');
unlink($torrent_dir . '/' . $name . '.zip');
/**
* ********************************** uploadpos people only ***************************************
*/
示例9: benc_resp
function benc_resp($d)
{
benc_resp_raw(benc(array('type' => 'dictionary', 'value' => $d)));
}
示例10: DB
$torrent_id = $_GET['torrent'];
$torrent = new DB("torrents");
$torrent->setColPrefix("torrent_");
$torrent->select("torrent_id = '" . $torrent_id . "'");
if (!$torrent->numRows()) {
throw new Exception("File not found");
}
$torrent->nextRecord();
if (!isset($_GET['passkey'])) {
$acl = new Acl(USER_ID);
} else {
$db = new DB("users");
$db->setColPrefix("user_");
$db->select("user_passkey = '" . $db->escape($_GET['passkey']) . "'");
if (!$db->numRows()) {
throw new Exception("user not found");
}
$db->nextRecord();
$acl = new Acl($db->id);
}
$fn = PATH_TORRENTS . $torrent->id . ".torrent";
$dict = bdec_file($fn, filesize($fn));
$dict['value']['announce']['value'] = CMS_URL . "announce.php?passkey=" . $acl->passkey;
$dict['value']['announce']['string'] = strlen($dict['value']['announce']['value']) . ":" . $dict['value']['announce']['value'];
$dict['value']['announce']['strlen'] = strlen($dict['value']['announce']['string']);
header('Content-Disposition: attachment; filename="' . $torrent->filename . '"');
header("Content-Type: application/x-bittorrent");
die(benc($dict));
} catch (Exception $e) {
echo $e->getMessage(), "\n";
}
示例11: download
public function download($id)
{
$torrent = $this->get($id);
include 'benc.php';
$filepath = $this->torrentDir . $torrent["id"] . ".torrent";
if (!file_exists($filepath)) {
throw new Exception('Torrentfilen saknas.');
}
if ($this->user->getHttps()) {
$announce = Helper::$trackerUrlSsl . "/tracker.php/" . $this->user->getPasskey() . "/announce";
} else {
$announce = Helper::$trackerUrl . "/tracker.php/" . $this->user->getPasskey() . "/announce";
}
$dict = bdec_file($filepath, filesize($filepath));
$dict['value']['announce']['value'] = $announce;
$dict['value']['announce']['string'] = strlen($dict['value']['announce']['value']) . ":" . $dict['value']['announce']['value'];
$dict['value']['announce']['strlen'] = strlen($dict['value']['announce']['string']);
$dict["value"]["comment"]["type"] = "string";
$dict["value"]["comment"]["value"] = Helper::$siteName;
$dict["value"]["comment"]["strlen"] = strlen(strlen(Helper::$siteName) . ":" . Helper::$siteName);
$dict["value"]["comment"]["string"] = strlen(Helper::$siteName) . ":" . Helper::$siteName;
unset($dict['value']['announce-list']);
header('Content-Disposition: attachment;filename="' . $torrent['filename'] . '"');
header("Content-Type: application/x-bittorrent");
print benc($dict);
exit;
}
示例12: download
public function download($id, $passkey = null)
{
$useHttps = null;
if ($passkey) {
$sth = $this->db->prepare("SELECT https FROM users WHERE passkey = ? AND enabled = 'yes'");
$sth->bindParam(1, $passkey, PDO::PARAM_STR);
$sth->execute();
$user = $sth->fetch(PDO::FETCH_ASSOC);
if (!$user) {
throw new Exception(L::get("USER_NOT_EXIST"), 404);
}
$useHttps = $user["https"] == 1;
} else {
$useHttps = $this->user->getHttps();
$passkey = $this->user->getPasskey();
}
$torrent = $this->get($id);
include 'benc.php';
$filepath = $this->torrentDir . $torrent["id"] . ".torrent";
if (!file_exists($filepath)) {
throw new Exception(L::get("TORRENT_NOT_FOUND"), 404);
}
if ($useHttps) {
$announce = Config::TRACKER_URL_SSL . "/tracker.php/" . $passkey . "/announce";
} else {
$announce = Config::TRACKER_URL . "/tracker.php/" . $passkey . "/announce";
}
$dict = bdec_file($filepath, filesize($filepath));
$dict['value']['announce']['value'] = $announce;
$dict['value']['announce']['string'] = strlen($dict['value']['announce']['value']) . ":" . $dict['value']['announce']['value'];
$dict['value']['announce']['strlen'] = strlen($dict['value']['announce']['string']);
$dict["value"]["comment"]["type"] = "string";
$dict["value"]["comment"]["value"] = Config::SITE_NAME;
$dict["value"]["comment"]["strlen"] = strlen(strlen(Config::SITE_NAME) . ":" . Config::SITE_NAME);
$dict["value"]["comment"]["string"] = strlen(Config::SITE_NAME) . ":" . Config::SITE_NAME;
unset($dict['value']['announce-list']);
header('Content-Disposition: attachment;filename="' . $torrent['filename'] . '"');
header("Content-Type: application/x-bittorrent");
print benc($dict);
exit;
}
示例13: mysql_query
if (!$row || !is_file($fn) || !is_readable($fn))
httperr();
mysql_query("UPDATE torrents SET hits = hits + 1 WHERE id = $id");
if (strlen($CURUSER['passkey']) != 32) {
$CURUSER['passkey'] = md5($CURUSER['username'].get_date_time().$CURUSER['passhash']);
mysql_query("UPDATE users SET passkey='$CURUSER[passkey]' WHERE id=$CURUSER[id]");
}
$dict = bdec_file($fn, filesize($fn));
$dict['value']['announce']['value'] = "$BASEURL/announce.php?passkey=$CURUSER[passkey]";
$dict['value']['announce']['string'] = strlen($dict['value']['announce']['value']).":".$dict['value']['announce']['value'];
$dict['value']['announce']['strlen'] = strlen($dict['value']['announce']['string']);
header('Content-Disposition: attachment; filename="'.$row['filename'].'"');
header('Content-Type: application/x-bittorrent');
print(benc($dict));
?>
示例14: doubleUp
function doubleUp()
{
$this->_dict = bdec(benc($this->_dict));
}
示例15: header
header ("Last-Modified: ".date("D, d M Y H:i:s"));
header ("Cache-Control: no-store, no-cache, must-revalidate");
header ("Cache-Control: post-check=0, pre-check=0", false);
header ("Pragma: no-cache");
header ("X-Powered-By: ".VERSION." (c) ".date("Y")." ".$SITENAME."");
header ("Accept-Ranges: bytes");
header ("Connection: close");
header ("Content-Transfer-Encoding: binary");
*/
header("Content-Type: application/x-bittorrent");
if (str_replace("Gecko", "", $_SERVER['HTTP_USER_AGENT']) != $_SERVER['HTTP_USER_AGENT']) {
header("Content-Disposition: attachment; filename=\"{$torrentnameprefix}." . $row["save_as"] . ".torrent\" ; charset=utf-8");
} else {
if (str_replace("Firefox", "", $_SERVER['HTTP_USER_AGENT']) != $_SERVER['HTTP_USER_AGENT']) {
header("Content-Disposition: attachment; filename=\"{$torrentnameprefix}." . $row["save_as"] . ".torrent\" ; charset=utf-8");
} else {
if (str_replace("Opera", "", $_SERVER['HTTP_USER_AGENT']) != $_SERVER['HTTP_USER_AGENT']) {
header("Content-Disposition: attachment; filename=\"{$torrentnameprefix}." . $row["save_as"] . ".torrent\" ; charset=utf-8");
} else {
if (str_replace("IE", "", $_SERVER['HTTP_USER_AGENT']) != $_SERVER['HTTP_USER_AGENT']) {
header("Content-Disposition: attachment; filename=" . str_replace("+", "%20", rawurlencode("{$torrentnameprefix}." . $row["save_as"] . ".torrent")));
} else {
header("Content-Disposition: attachment; filename=" . str_replace("+", "%20", rawurlencode("{$torrentnameprefix}." . $row["save_as"] . ".torrent")));
}
}
}
}
//header ("Content-Disposition: attachment; filename=".$row["filename"]."");
//ob_implicit_flush(true);
print benc($dict);