1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
|
<?php
/*************************************************************
* TorrentFlux - PHP Torrent Manager
* www.torrentflux.com
**************************************************************/
/*
This file is part of TorrentFlux.
TorrentFlux is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
TorrentFlux is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with TorrentFlux; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
include_once("settingsfunctions.php");
function getFile($var)
{
if ($var < 65535)
return true;
else
return false;
}
//*********************************************************
// setPriority()
function setPriority($torrent)
{
global $cfg;
// we will use this to determine if we should create a prio file.
// if the user passes all 1's then they want the whole thing.
// so we don't need to create a prio file.
// if there is a -1 in the array then they are requesting
// to skip a file. so we will need to create the prio file.
$okToCreate = false;
if(!empty($torrent))
{
$alias = getAliasName($torrent);
$fileName = $cfg["torrent_file_path"].$alias.".prio";
$result = array();
$files = array();
$files = getRequestVar('files');
// if there are files to get then process and create a prio file.
if (is_array($files) && count($files) > 0)
{
$files = array_filter($files,"getFile");
for($i=0;$i<getRequestVar('count');$i++)
{
if(in_array($i,$files))
{
array_push($result,1);
}
else
{
$okToCreate = true;
array_push($result,-1);
}
}
$alias = getAliasName($torrent);
if ($okToCreate)
{
$fp = fopen($fileName, "w");
fwrite($fp,getRequestVar('filecount').",");
fwrite($fp,implode($result,','));
fclose($fp);
}
else
{
// No files to skip so must be wanting them all.
// So we will remove the prio file.
@unlink($fileName);
}
}
else
{
// No files selected so must be wanting them all.
// So we will remove the prio file.
@unlink($fileName);
}
}
}
?>
|