Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update 'create' plugin #2144

Merged
merged 1 commit into from
Feb 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 42 additions & 10 deletions plugins/create/action.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ public function store()
$this->strip();
return($cache->set($this));
}
public function delete($trk)
{
$cache = new rCache();
$this->list = array_diff($this->list,$trk);
return($cache->set($this));
}
public function get()
{
$ret = array();
Expand All @@ -34,7 +40,19 @@ public function strip()
{
global $recentTrackersMaxCount;
$this->list = array_values( array_unique($this->list) );
$cnt = count($this->list)-$recentTrackersMaxCount;
$cnt = count($this->list);
$arr = array_values($this->list);
$lastAnn = self::getTrackerDomain(end($arr));
$i = 0;
foreach( $this->list as $ann )
{
if( ($i + 1) === $cnt )
break;
if( self::getTrackerDomain($ann) === $lastAnn )
array_splice($this->list,$i,1);
$i = $i + 1;
}
$cnt = $cnt-$recentTrackersMaxCount;
if($cnt>0)
array_splice($this->list,0,$cnt);
}
Expand Down Expand Up @@ -70,6 +88,23 @@ static public function getTrackerDomain($announce)
$ret = $rt->get();
break;
}
case "rtdelete":
{
if(isset($_REQUEST['trackers']))
{
$rt = recentTrackers::load();
$trk = array();
$arr = explode("\r",$_REQUEST['trackers']);
foreach( $arr as $key => $value )
{
$value = trim($value);
if(strlen($value))
$trk[] = $value;
}
$ret = $rt->delete($trk);
}
break;
}
case "create":
{
$error = "Invalid parameters";
Expand All @@ -81,7 +116,7 @@ static public function getTrackerDomain($announce)
if(rTorrentSettings::get()->correctDirectory($path_edit))
{
$rt = recentTrackers::load();
$trackers = array();
$trackers = array();
$announce_list = '';
if(isset($_REQUEST['trackers']))
{
Expand Down Expand Up @@ -114,26 +149,23 @@ static public function getTrackerDomain($announce)
$pathToCreatetorrent = $useExternal;
if($useExternal=="mktorrent")
$piece_size = log($piece_size,2);
else

if(isset($_REQUEST['hybrid']))
$hybrid = TRUE;

if($useExternal===false)
$useExternal = "inner";
$task = new rTask( array
(
(
'arg' => getFileName($path_edit),
'requester'=>'create',
'name'=>'create',
'name'=>'create',
'path_edit'=>$_REQUEST['path_edit'],
'trackers'=>$_REQUEST['trackers'],
'comment'=>$_REQUEST['comment'],
'source'=>$_REQUEST['source'],
'start_seeding'=>$_REQUEST['start_seeding'],
'piece_size'=>$_REQUEST['piece_size'],
'private'=>$_REQUEST['private'],
'hybrid'=>$_REQUEST['hybrid'],
'hybrid'=>$_REQUEST['hybrid']
) );
$commands = array();

Expand All @@ -146,10 +178,10 @@ static public function getTrackerDomain($announce)
escapeshellarg(getUser())." ".
escapeshellarg(rTask::formatPath($task->id))." ".
escapeshellarg($hybrid);

$commands[] = '{';
$commands[] = 'chmod a+r "${dir}"/result.torrent';
$commands[] = '}';
$commands[] = '}';
$ret = $task->start($commands, 0);
break;
}
Expand Down
1 change: 1 addition & 0 deletions plugins/create/create.css
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ div#tcreate iframe {border-width: 1px; width:170px; height:200px; visibility:hid
#browse_path {width: 30px;}

#recentTrackers { float: left; width: 130px }
#deleteFromRecentTrackers {float: left; text-align: left}
65 changes: 47 additions & 18 deletions plugins/create/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@ theWebUI.checkCreate = function()
var trk = '';
for( var i in arr )
trk+=($.trim(arr[i])+'\r');
this.startConsoleTask( "create", plugin.name,
{
"piece_size" : $('#piece_size').val(),
this.startConsoleTask( "create", plugin.name,
{
"piece_size" : $('#piece_size').val(),
"trackers" : trk,
"path_edit" : $.trim($("#path_edit").val()),
"path_edit" : $.trim($("#path_edit").val()),
"comment" : $.trim($("#comment").val()),
"source" : $.trim($("#source").val()),
"private" : $('#private').prop('checked') ? 1 : 0,
"start_seeding" : $('#start_seeding').prop('checked') ? 1 : 0,
"hybrid" : $('#hybrid').prop('checked') ? 1 : 0,
"hybrid" : $('#hybrid').prop('checked') ? 1 : 0
},
{
noclose: true
Expand All @@ -35,25 +35,37 @@ plugin.onTaskFinished = function(task,fromBackground)
$("#xtaskno").val(task.no);
if(!task.status)
$('#xcsave').show();
}
}
theWebUI.request('?action=rtget',[plugin.getRecentTrackers, plugin]);
}

rTorrentStub.prototype.rtget = function()
{
this.content = "cmd=rtget";
this.contentType = "application/x-www-form-urlencoded";
this.contentType = "application/x-www-form-urlencoded";
this.mountPoint = "plugins/create/action.php";
this.dataType = "json";
}

rTorrentStub.prototype.rtdelete = function()
{
this.content = "cmd=rtdelete&trackers="+plugin.deleteFromRecentTrackers;
this.contentType = "application/x-www-form-urlencoded";
this.mountPoint = "plugins/create/action.php";
this.dataType = "json";
}

theWebUI.showCreate = function()
{
if( $("#trackers").val().trim().length < 1 )
$("#deleteFromRecentTrackers").addClass("disabled");
else
$("#deleteFromRecentTrackers").removeClass("disabled");
$('#start_seeding').prop('disabled',!theWebUI.systemInfo.rTorrent.started);
if(theWebUI.systemInfo.rTorrent.started)
$('#lbl_start_seeding').removeClass('disabled');
else
$('#lbl_start_seeding').addClass('disabled');
else
$('#lbl_start_seeding').addClass('disabled');
theDialogManager.show('tcreate');
}

Expand All @@ -68,6 +80,7 @@ plugin.getRecentTrackers = function( data )

theWebUI.addTrackerToBox = function(ann)
{
$("#deleteFromRecentTrackers").removeClass("disabled");
var val = $('#trackers').val();
if(val.length)
val+='\r\n';
Expand All @@ -87,6 +100,22 @@ theWebUI.showRecentTrackers = function()
}
}

theWebUI.deleteFromRecentTrackers = function()
{
$("#deleteFromRecentTrackers").addClass("disabled");
var trklist = $('#trackers').val();
if(!trklist)
return(false);
var arr = trklist.split("\n");
$('#trackers').val('');
var trk = '';
for( var i in arr )
trk+=($.trim(arr[i])+'\r');
plugin.deleteFromRecentTrackers = trk;
theWebUI.request('?action=rtdelete');
theWebUI.request('?action=rtget',[plugin.getRecentTrackers, plugin]);
}

plugin.onLangLoaded = function()
{
var plg = thePlugins.get("_task");
Expand All @@ -100,7 +129,7 @@ plugin.onLangLoaded = function()
);
plugin.addButtonToToolbar("create",theUILang.mnu_create,"theWebUI.showCreate()","remove");
plugin.addSeparatorToToolbar("remove");
var pieceSize =
var pieceSize =
"<label>"+theUILang.PieceSize+": </label>"+
"<select id='piece_size' name='piece_size'>"+
"<option value=\"32\">32"+theUILang.KB+"</option>"+
Expand All @@ -115,14 +144,14 @@ plugin.onLangLoaded = function()
"<option value=\"16384\">16"+theUILang.MB+"</option>"+
"</select>";
if(plugin.hidePieceSize)
pieceSize = "";
pieceSize = "";

var hybridTorrent =
var hybridTorrent =
"<label for='hybrid' id='lbl_hybrid' class='nomargin'>"+
"<input type='checkbox' name='hybrid' id='hybrid'/>"+theUILang.HybridTorrent+"</label>";

if(plugin.hideHybrid)
hybridTorrent = "";
hybridTorrent = "";

theDialogManager.make("tcreate",theUILang.CreateNewTorrent,
"<div class='cont fxcaret'>"+
Expand All @@ -139,7 +168,7 @@ plugin.onLangLoaded = function()
"<input type='text' id='comment' name='comment' class='TextboxLarge'/><br/>"+
"<label>" + theUILang.source + ": </label>"+
"<input type='text' id='source' name='source' class='TextboxLarge'/><br/>"+
pieceSize+
pieceSize+
"</fieldset>"+
"<fieldset>"+
"<legend>"+theUILang.Other+"</legend>"+
Expand All @@ -148,7 +177,7 @@ plugin.onLangLoaded = function()
hybridTorrent+"<br/>"+
"</fieldset>"+
"</div>"+
"<div class='aright buttons-list'><input type='button' id='recentTrackers' value='"+theUILang.recentTrackers+"...' class='Button menuitem' onclick='theWebUI.showRecentTrackers()'/><input type='button' id='torrentCreate' value='"+theUILang.torrentCreate+"' class='OK Button' onclick='theWebUI.checkCreate()'/><input type='button' class='Cancel Button' value='"+theUILang.Cancel+"'/></div>",true);
"<div class='aright buttons-list'><input type='button' id='recentTrackers' value='"+theUILang.recentTrackers+"...' class='Button menuitem' onclick='theWebUI.showRecentTrackers()'/><input type='button' id='deleteFromRecentTrackers' value='"+theUILang.deleteFromRecentTrackers+"' class='Button' onclick='theWebUI.deleteFromRecentTrackers()'/><input type='button' id='torrentCreate' value='"+theUILang.torrentCreate+"' class='OK Button' onclick='theWebUI.checkCreate()'/><input type='button' class='Cancel Button' value='"+theUILang.Cancel+"'/></div>",true);
$(document.body).append($("<iframe name='xcreatefrm'/>").css({visibility: "hidden"}).attr( { name: "xcreatefrm", id: "xcreatefrm" } ).width(0).height(0));
$(document.body).append(
$('<form action="plugins/create/action.php" id="xgetfile" method="post" target="xcreatefrm">'+
Expand All @@ -173,7 +202,7 @@ plugin.onLangLoaded = function()
{
$('#xcsave').hide();
});
plugin.markLoaded();
plugin.markLoaded();
}
};

Expand All @@ -183,7 +212,7 @@ plugin.onRemove = function()
plugin.removeButtonFromToolbar("create");
}

plugin.langLoaded = function()
plugin.langLoaded = function()
{
if(plugin.enabled)
plugin.onLangLoaded();
Expand Down
3 changes: 2 additions & 1 deletion plugins/create/lang/cs.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
theUILang.torrentKilled = "Process was stopped.";
theUILang.recentTrackers = "Recent trackers";
theUILang.source = "Source";
theUILang.HybridTorrent = "Hybrid torrent";
theUILang.HybridTorrent = "Hybrid torrent";
theUILang.deleteFromRecentTrackers = "> Delete";

thePlugins.get("create").langLoaded();
3 changes: 2 additions & 1 deletion plugins/create/lang/da.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
theUILang.torrentKilled = "Process was stopped.";
theUILang.recentTrackers = "Recent trackers";
theUILang.source = "Source";
theUILang.HybridTorrent = "Hybrid torrent";
theUILang.HybridTorrent = "Hybrid torrent";
theUILang.deleteFromRecentTrackers = "> Delete";

thePlugins.get("create").langLoaded();
3 changes: 2 additions & 1 deletion plugins/create/lang/de.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
theUILang.torrentKilled = "Process was stopped.";
theUILang.recentTrackers = "Recent trackers";
theUILang.source = "Source";
theUILang.HybridTorrent = "Hybrid torrent";
theUILang.HybridTorrent = "Hybrid torrent";
theUILang.deleteFromRecentTrackers = "> Delete";

thePlugins.get("create").langLoaded();
3 changes: 2 additions & 1 deletion plugins/create/lang/el.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
theUILang.torrentKilled = "Η λειτουργία τερματίστηκε.";
theUILang.recentTrackers = "Πρόσφατοι trackers";
theUILang.source = "Πηγή";
theUILang.HybridTorrent = "Υβριδικό τόρεντ";
theUILang.HybridTorrent = "Υβριδικό τόρεντ";
theUILang.deleteFromRecentTrackers = "> Delete";

thePlugins.get("create").langLoaded();
3 changes: 2 additions & 1 deletion plugins/create/lang/en.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
theUILang.torrentKilled = "Process was stopped.";
theUILang.recentTrackers = "Recent trackers";
theUILang.source = "Source";
theUILang.HybridTorrent = "Hybrid torrent";
theUILang.HybridTorrent = "Hybrid torrent";
theUILang.deleteFromRecentTrackers = "> Delete";

thePlugins.get("create").langLoaded();
3 changes: 2 additions & 1 deletion plugins/create/lang/es.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
theUILang.torrentKilled = "El proceso fue detenido.";
theUILang.recentTrackers = "Recent trackers";
theUILang.source = "Source";
theUILang.HybridTorrent = "Hybrid torrent";
theUILang.HybridTorrent = "Hybrid torrent";
theUILang.deleteFromRecentTrackers = "> Delete";

thePlugins.get("create").langLoaded();
3 changes: 2 additions & 1 deletion plugins/create/lang/fi.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
theUILang.torrentKilled = "Process was stopped.";
theUILang.recentTrackers = "Recent trackers";
theUILang.source = "Source";
theUILang.HybridTorrent = "Hybrid torrent";
theUILang.HybridTorrent = "Hybrid torrent";
theUILang.deleteFromRecentTrackers = "> Delete";

thePlugins.get("create").langLoaded();
5 changes: 3 additions & 2 deletions plugins/create/lang/fr.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
theUILang.torrentKilled = "Le processus a été interrompu.";
theUILang.recentTrackers = "Trackers récents";
theUILang.source = "Source";
theUILang.HybridTorrent = "Hybrid torrent";
theUILang.HybridTorrent = "Torrent hybride";
theUILang.deleteFromRecentTrackers = "> Supprimer";

thePlugins.get("create").langLoaded();
thePlugins.get("create").langLoaded();
3 changes: 2 additions & 1 deletion plugins/create/lang/hu.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
theUILang.torrentKilled = "Folyamat leállt.";
theUILang.recentTrackers = "Recent trackers";
theUILang.source = "Source";
theUILang.HybridTorrent = "Hybrid torrent";
theUILang.HybridTorrent = "Hybrid torrent";
theUILang.deleteFromRecentTrackers = "> Delete";

thePlugins.get("create").langLoaded();
3 changes: 2 additions & 1 deletion plugins/create/lang/it.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
theUILang.torrentKilled = "Il processo è stato arrestato.";
theUILang.recentTrackers = "Tracker recenti";
theUILang.source = "Source";
theUILang.HybridTorrent = "Hybrid torrent";
theUILang.HybridTorrent = "Hybrid torrent";
theUILang.deleteFromRecentTrackers = "> Delete";

thePlugins.get("create").langLoaded();
3 changes: 2 additions & 1 deletion plugins/create/lang/ko.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
theUILang.torrentKilled = "프로세스가 중지되었습니다.";
theUILang.recentTrackers = "최근 트래커";
theUILang.source = "원본";
theUILang.HybridTorrent = "Hybrid torrent";
theUILang.HybridTorrent = "Hybrid torrent";
theUILang.deleteFromRecentTrackers = "> Delete";

thePlugins.get("create").langLoaded();
3 changes: 2 additions & 1 deletion plugins/create/lang/lv.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
theUILang.torrentKilled = "Process was stopped.";
theUILang.recentTrackers = "Recent trackers";
theUILang.source = "Source";
theUILang.HybridTorrent = "Hybrid torrent";
theUILang.HybridTorrent = "Hybrid torrent";
theUILang.deleteFromRecentTrackers = "> Delete";

thePlugins.get("create").langLoaded();
Loading