Skip to content

Commit

Permalink
Added (in file browser and configuration->update) ability to update s…
Browse files Browse the repository at this point in the history
…elected directory only (#26)
  • Loading branch information
ArturSierzant committed Jan 31, 2017
1 parent 93473ba commit d26a08b
Show file tree
Hide file tree
Showing 15 changed files with 408 additions and 55 deletions.
1 change: 1 addition & 0 deletions about.php
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ function about() {
<li> added display of other versions of album</li>
<li> added list of favorite tracks in artist search results</li>
<li> added ability to play any track/folder www server has access to (i.e. files outside of MPD and O!MPD database) on any MPD in network</li>
<li> added ability to update selected directory only (no need to do full update when adding single albums)</li>
<li> added random play from directory</li>
</ul>
<br>
Expand Down
3 changes: 2 additions & 1 deletion ajax-random-files.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@
$file = array();
$file_count = 0;

$dir = str_replace('ompd_ampersand_ompd','&',$dir);
//$dir = str_replace('ompd_ampersand_ompd','&',$dir);
$dir = myDecode($dir);
$dir = iconv('UTF-8', NJB_DEFAULT_FILESYSTEM_CHARSET, $dir);

setcookie('random_limit', $limit, time() + (86400 * 30 * 365), "/"); // 86400 = 1 day
Expand Down
26 changes: 23 additions & 3 deletions browser.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,14 +104,20 @@ function findSmallest($i, $end, $data)

$self = $_SERVER['PHP_SELF'];
$showSelect = isset($_GET['showSelect']) ? $_GET['showSelect'] : '';
$showUpdateSelect = isset($_GET['showUpdateSelect']) ? $_GET['showUpdateSelect'] : '';
$showSelectQS = '';
$tileSizePHP = isset($_GET['tileSizePHP']) ? ('tileSizePHP=' . $_GET['showSelect'] . '&') : '';
$tileSizePHP = isset($_GET['tileSizePHP']) ? ('tileSizePHP=' . $_GET['tileSizePHP'] . '&') : '';
//show 'Select this dir' button
if ($showSelect == 'true') {
$showSelectQS = 'showSelect=true&';
}
if ($showUpdateSelect == 'true') {
$showSelectQS = 'showUpdateSelect=true&';
}
if (isset($_GET['dir'])) {
$dir = str_replace('ompd_ampersand_ompd','&',$_GET['dir']);
//$dir = myDecode($_GET['dir']);
//echo $dir;
$allowAccess = false;
//restrict acccess to files/folders outside media_dir
if (!$cfg['allow_access_to_all_files']) {
Expand Down Expand Up @@ -167,7 +173,7 @@ function findSmallest($i, $end, $data)
else {
if ($part != '') $actDirToHref .= '/'. $part;
}
$actDirToShow .= '<a href="' . $self. '?dir=' . rawurlencode($actDirToHref) . '">' . $part . '</a>/';
$actDirToShow .= '<a href="' . $self. '?' . $showSelectQS . 'dir=' . rawurlencode($actDirToHref) . '">' . $part . '</a>/';
}
}
else {
Expand All @@ -177,7 +183,21 @@ function findSmallest($i, $end, $data)
if ($showSelect == 'true') {
?>
<div class="buttons">
<span id="selectDir" onclick="window.location.href='index.php?action=viewRandomFile&<?php echo $tileSizePHP; ?>selectedDir=<?php echo str_replace('%26','ompd_ampersand_ompd',urlencode($dir));?>'">Select this directory</span>
<span id="selectDir" onclick="window.location.href='index.php?action=viewRandomFile&<?php echo $tileSizePHP; ?>selectedDir=<?php echo str_replace('%26','ompd_ampersand_ompd',rawurlencode($dir));?>'">Select this directory</span>
</div>
<?php
}

$inMediaDir = false;
$pos = strpos($dir,substr($cfg['media_dir'], 0, -1));
if ($pos !== false) {
$inMediaDir = true;
}

if ($showUpdateSelect == 'true' && $inMediaDir == true) {
?>
<div class="buttons">
<span id="selectDir" onclick="window.location.href='config-update-select.php?action=updateSelect&<?php echo $tileSizePHP; ?>selectedDir=<?php echo str_replace('%26','ompd_ampersand_ompd',rawurlencode($dir));?>'">Select this directory</span>
</div>
<?php
}
Expand Down
158 changes: 158 additions & 0 deletions config-update-select.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
<?php
// +------------------------------------------------------------------------+
// | O!MPD, Copyright © 2015-2016 Artur Sierzant |
// | http://www.ompd.pl |
// | |
// | |
// | netjukebox, Copyright © 2001-2012 Willem Bartels |
// | |
// | http://www.netjukebox.nl |
// | http://forum.netjukebox.nl |
// | |
// | This program 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 3 of the License, or |
// | (at your option) any later version. |
// | |
// | This program 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 this program. If not, see <http://www.gnu.org/licenses/>. |
// +------------------------------------------------------------------------+




// +------------------------------------------------------------------------+
// | config.php |
// +------------------------------------------------------------------------+
require_once('include/initialize.inc.php');
$cfg['menu'] = 'config';

$action = getpost('action');
$update = getpost('update');

if ($action == 'updateSelect') updateSelect();

else message(__FILE__, __LINE__, 'error', '[b]Unsupported input value for[/b][br]action');




// +------------------------------------------------------------------------+
// | Select update range |
// +------------------------------------------------------------------------+
function updateSelect() {
global $cfg, $db;
authenticate('access_admin');
require_once('include/play.inc.php');

$result = mysqli_query($db,'SELECT * FROM update_progress');
$row = mysqli_fetch_assoc($result);
$update_status = $row["update_status"];

if ($update_status == 1) {
header('Location: update.php?action=update&sign=' . $cfg['sign']);
exit();
}

// formattedNavigator
$nav = array();
$nav['name'][] = 'Configuration';
$nav['url'][] = 'config.php';
$nav['name'][] = 'Update';
require_once('include/header.inc.php');



if(!isset($_COOKIE['update_dir']) || $_COOKIE['update_dir'] == '') {
$dir = $cfg['media_dir'];
} else {
$dir = myHTMLencode($_COOKIE['update_dir']);
}

//$selectedDir = isset($_GET['selectedDir']) ? str_replace('ompd_ampersand_ompd','&',$_GET['selectedDir']) : $dir;

$selectedDir = isset($_GET['selectedDir']) ? myHTMLencode($_GET['selectedDir']) : $dir;


?>

<table width="100%" cellspacing="0" cellpadding="0" class="border">
<tr class="header">
<td>&nbsp;</td>
<td colspan="3">Update only selected directory</td>
</tr>

<tr>
<td>&nbsp;</td>
<td></td>
<td>&nbsp;</td>
<td></td>
</tr>
<tr>
<td>&nbsp;</td>
<td style="max-width: 4em;">Select directory:</td>
<td>&nbsp;</td>
<td>
<div class="buttons">
<input id="updateDir" value="<?php echo $selectedDir; ?>">
<span id="updateBrowse"><i class="fa fa-folder-open-o fa-fw"></i> Browse...</span>
</div>
</td>
</tr>
<tr>
<td>&nbsp;</td>
<td></td>
<td>&nbsp;</td>
<td>
<div class="buttons">
<span id="updateSelectedDir" onmouseover="return overlib('Update this dir');" onmouseout="return nd();">&nbsp;<i class="fa fa-refresh fa-fw"></i> Update this directory only</span>
</div>
<div id="errorMessage"></div>
</td>
</tr>
<tr>
<td>&nbsp;</td>
<td></td>
<td>&nbsp;</td>
<td></td>
</tr>
<tr class="header">
<td>&nbsp;</td>
<td colspan="3">Update whole media directory (<?php echo $cfg['media_dir'];?>)</td>
</tr>

<tr>
<td>&nbsp;</td>
<td></td>
<td>&nbsp;</td>
<td></td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>
<div class="buttons">
<span id="updateAll" onmouseover="return overlib('Update this dir');" onmouseout="return nd();">&nbsp;<i class="fa fa-refresh fa-fw"></i> Update all</span>
</div>
<div id="errorMessage"></div>
</td>
</tr>
</table>


<?php

echo '</table>' . "\n";
require_once('include/footer.inc.php');
}




?>
2 changes: 1 addition & 1 deletion config.php
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ function config() {
?>
<tr class="<?php echo ($i++ & 1) ? 'even' : 'odd'; ?>">
<td></td>
<td class="update"><a href="update.php?action=update&amp;sign=<?php echo $cfg['sign']; ?>"><i class="fa fa-refresh fa-fw icon-small <?php echo $spin ?>"></i>Update</a></td>
<td class="update"><a href="config-update-select.php?action=updateSelect"><i class="fa fa-refresh fa-fw icon-small <?php echo $spin ?>"></i>Update</a></td>
<td></td>
<td>Update media <?php echo $update_info?></td>
<td></td>
Expand Down
1 change: 1 addition & 0 deletions include/config.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@
// +------------------------------------------------------------------------+
// | Leave this empty to use PHP's default |
// +------------------------------------------------------------------------+

$cfg['timezone'] = '';


Expand Down
2 changes: 1 addition & 1 deletion include/header.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ function javascript_hash() {
$header['menu'] .= "\t" . '<a href="config.php?action=downloadProfile">download profile</a>' . $header['seperation'];
$header['menu'] .= "\t" . '<a href="config.php?action=skinProfile">skin profile</a>' . $header['seperation'];
$header['menu'] .= "\t" . '<a href="users.php">users</a>' . $header['seperation'];
$header['menu'] .= "\t" . '<a href="update.php?action=update&amp;sign=' . $cfg['sign'] . '">update</a>' . "\n";
$header['menu'] .= "\t" . '<a href="update.php?action=update&amp;sign=' . $cfg['sign'] . '">update all</a>' . "\n";
}

elseif ($cfg['menu'] == 'about') {
Expand Down
73 changes: 57 additions & 16 deletions include/library.inc.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<?php
// +------------------------------------------------------------------------+
// | O!MPD, Copyright © 2015-2016 Artur Sierzant |
// | O!MPD, Copyright 2015-2016 Artur Sierzant |
// | http://www.ompd.pl |
// | |
// | |
// | netjukebox, Copyright © 2001-2012 Willem Bartels |
// | netjukebox, Copyright 2001-2012 Willem Bartels |
// | |
// | http://www.netjukebox.nl |
// | http://forum.netjukebox.nl |
Expand Down Expand Up @@ -252,29 +252,36 @@ function dirSubMenu($i, $dir) {
} else {
$limit = $_COOKIE['random_limit'];
}

$showUpdate = false;
$pos = strpos($dir,$cfg['media_dir']);
if ($pos !== false) {
$showUpdate = true;
}

$dirpath = str_ireplace($cfg['media_dir'],'', $dir);
//$dirpath = str_replace('%26','ompd_ampersand_ompd',urlencode($dirpath));
//$dir = str_replace('%26','ompd_ampersand_ompd',urlencode($dir));
$dirpath = myUrlencode($dirpath);
$dir = myUrlencode($dir);
?>
<div class="menuSub" id="menu-sub-track<?php echo $i ?>" onclick='//offMenuSub(<?php echo $i ?>);'>

<div><?php if ($cfg['access_play']) {
echo '<a href="javascript:ajaxRequest(\'play.php?dirpath=' . $dirpath . '&amp;fulldirpath=' . $dir . '&amp;action=playSelect&amp;id=' . $i .'\',evaluateAdd);" onMouseOver="return overlib(\'Play all files from this dir\');" onMouseOut="return nd();"><i id = "play_' . $i . '" class="fa fa-play-circle-o fa-fw icon-small"></i>Play all files from this dir</a>';
<?php if ($cfg['access_play']) {
echo '<div><a href="javascript:ajaxRequest(\'play.php?dirpath=' . $dirpath . '&amp;fulldirpath=' . $dir . '&amp;action=playSelect&amp;id=' . $i .'\',evaluateAdd);" onMouseOver="return overlib(\'Play all files from this dir\');" onMouseOut="return nd();"><i id = "play_' . $i . '" class="fa fa-play-circle-o fa-fw icon-small"></i>Play all files from this dir</a></div>';
}
?>
</div>
<div><?php if ($cfg['access_play']) {
echo '<a href="javascript:ajaxRequest(\'play.php?dirpath=' . $dirpath . '&amp;fulldirpath=' . $dir . '&amp;action=addSelect&amp;track_id=' . ($i - 100000) .'\',evaluateAdd);" onMouseOver="return overlib(\'Add all files from this dir\');" onMouseOut="return nd();"><i id = "add_' . ($i - 100000) . '" class="fa fa-plus-circle fa-fw icon-small"></i>Add all files from this dir</a>';

if ($cfg['access_play']) {
echo '<div><a href="javascript:ajaxRequest(\'play.php?dirpath=' . $dirpath . '&amp;fulldirpath=' . $dir . '&amp;action=addSelect&amp;track_id=' . ($i - 100000) .'\',evaluateAdd);" onMouseOver="return overlib(\'Add all files from this dir\');" onMouseOut="return nd();"><i id = "add_' . ($i - 100000) . '" class="fa fa-plus-circle fa-fw icon-small"></i>Add all files from this dir</a></div>';
}
?>
</div>
<div><?php if ($cfg['access_play']) {
echo '<a href="javascript:ajaxRequest(\'ajax-random-files.php?dir=' . $dir . '&amp;limit=' . $limit . '&amp;id=' . $i .'\',evaluateRandom);" onMouseOver="return overlib(\'Play random files from this dir\');" onMouseOut="return nd();"><i id = "randomPlay_' . $i . '" class="fa fa-random fa-fw icon-small"></i>Play random files from this dir</a>';

if ($cfg['access_play']) {
echo '<div><a href="javascript:ajaxRequest(\'ajax-random-files.php?dir=' . $dir . '&amp;limit=' . $limit . '&amp;id=' . $i .'\',evaluateRandom);" onMouseOver="return overlib(\'Play random files from this dir\');" onMouseOut="return nd();"><i id = "randomPlay_' . $i . '" class="fa fa-random fa-fw icon-small"></i>Play random files from this dir</a></div>';
}
?>
</div>

if ($cfg['access_admin'] && $showUpdate) {
echo '<div><a href="update.php?action=update&amp;dir_to_update=' . $dir . '/&amp;sign=' . $cfg['sign'] . '" onMouseOver="return overlib(\'Import this dir to database and MPD\');" onMouseOut="return nd();"><i id = "update_' . $i . '" class="fa fa-refresh fa-fw icon-small"></i>Update this directory in database and MPD</a></div>';
}
?>

</div>
<?php
Expand Down Expand Up @@ -1178,12 +1185,30 @@ function backgroundQueries(){




// +------------------------------------------------------------------------+
// | HTMLencode &, ', " |
// +------------------------------------------------------------------------+

function myHTMLencode($str1){

$str1 = str_replace('ompd_ampersand_ompd','&',$str1);
//$str1 = str_replace("'","&apos;",$str1);
//$str1 = str_replace('"',"&quot;",$str1);
$str1 = htmlentities($str1, ENT_QUOTES);

return $str1;
}



// +------------------------------------------------------------------------+
// | Urlencode &, ', " |
// +------------------------------------------------------------------------+

function myUrlencode($str1){

$str1 = str_replace('+','ompd_plus_ompd',$str1);
$str1 = str_replace('%26','ompd_ampersand_ompd',urlencode($str1));
$str1 = str_replace('%22','%5C%22',$str1);
$str1 = str_replace('%27','%5C%27',$str1);
Expand All @@ -1193,7 +1218,6 @@ function myUrlencode($str1){




// +------------------------------------------------------------------------+
// | Urldecode &, ', " |
// +------------------------------------------------------------------------+
Expand All @@ -1210,6 +1234,23 @@ function myUrldecode($str1){



// +------------------------------------------------------------------------+
// | Decode &, ', " |
// +------------------------------------------------------------------------+

function myDecode($str1){

$str1 = str_replace('ompd_ampersand_ompd','&',$str1);
$str1 = str_replace('\"','"',$str1);
$str1 = str_replace("\'","'",$str1);
$str1 = str_replace("ompd_plus_ompd","+",$str1);

return $str1;
}




// +------------------------------------------------------------------------+
// | mime_content_type replacement by svogal: |
// | http://php.net/manual/en/function.mime-content-type.php#87856 |
Expand Down
Loading

0 comments on commit d26a08b

Please sign in to comment.