Skip to content
Open
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
33 changes: 33 additions & 0 deletions addfunctions.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

function re_name(){
$is_file = $_GET['is_file'];
$rnm_dir = urldecode($_GET['rnm_dir']);
$new_name = $_GET['new_name'];

if($is_file){
$inf = pathinfo($rnm_dir);
$ext = $inf['extension'];
$dir = $inf['dirname'];

$n_inf = pathinfo($new_name);
$n_ext = $n_inf['extension'];

$n_file = $dir.'/'.$new_name.( strlen($n_ext)>2 ? '' : '.'.$ext);
@rename($rnm_dir, $n_file);
$out['name'] = $n_file;
echo json_encode($out);
} else {
$dir = dirname($rnm_dir);
$n_dir = $dir.'/'.$new_name;
@rename($rnm_dir, $n_dir);
$out['name'] = $n_dir;
echo json_encode($out);
}
}

if ($_REQUEST['function'] == 'rename'){
re_name();
}

?>
71 changes: 69 additions & 2 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@
$_CONFIG['upload_enable'] = true;
$_CONFIG['newdir_enable'] = true;
$_CONFIG['delete_enable'] = false;

$_CONFIG['rename_enable'] = true;
/*
* UPLOADING
*/
Expand Down Expand Up @@ -2045,6 +2045,12 @@ public static function isUploadAllowed(){
return true;
return false;
}

public static function isRenameAllowed(){
if(EncodeExplorer::getConfig("rename_enable") == true && GateKeeper::isUserLoggedIn() == true && GateKeeper::getUserStatus() == "admin")
return true;
return false;
}

public static function isNewdirAllowed(){
if(EncodeExplorer::getConfig("newdir_enable") == true && GateKeeper::isUserLoggedIn() == true && GateKeeper::getUserStatus() == "admin")
Expand Down Expand Up @@ -2953,7 +2959,7 @@ function outputHtml()
|| (GateKeeper::isDeleteAllowed()))
{
?>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js"></script>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script type="text/javascript">
//<![CDATA[
$(document).ready(function() {
Expand Down Expand Up @@ -3269,6 +3275,67 @@ function(){
<a href="http://encode-explorer.siineiolekala.net">Encode Explorer</a>
</div>
<!-- END: Info area -->

<?php
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If anyone wants renaming to be allowed explicitly

if(GateKeeper::isAccessAllowed() && GateKeeper::isRenameAllowed()){
?>
<script type="text/javascript">// <![CDATA[
$(function () {
$("td.name").dblclick(function (e) {
e.stopPropagation();
var currentEle = $(this).children("a");
var currentVal = currentEle.html();
if ($("#NewName").length <= 0){
updateVal(currentEle, currentVal);
}
});
});

function updateVal(currentEle, currentVal) {
var is_file = 0;
if(currentEle.hasClass('file')){
is_file = 1;
}
var rnm_dir = currentEle.attr('href');
rnm_dir = rnm_dir.replace('?dir=','');

$(currentEle).parent().append('<input id="NewName" type="text" value="' + currentVal + '" />');
$(currentEle).hide();
$("#NewName").focus();

$("#NewName").keyup(function (event) {
if (event.keyCode == 13) {
var n_name = $("#NewName").val();
$('#NewName').remove();
$.ajax({
cache: false,
type: 'GET',
url: 'addfunctions.php',
data: {'rnm_dir':rnm_dir, 'is_file':is_file, 'new_name':n_name, 'function':'rename'},
dataType: "json",
success: function(response){
if(!is_file){
response.name = '?dir=' + response.name;
}
currentEle.attr('href', response.name);
$(currentEle).html(n_name).show();
},
error: function (request, status, error) {
$(currentEle).html('Error updating').show();
alert(request.responseText);
}
});
}
}).blur(function () {
$('#NewName').remove();
$(currentEle).html(currentVal).show();
});
}
// ]]></script>
<?php
}
?>

</body>
</html>

Expand Down