demo.browse.php 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622
  1. <?php
  2. /////////////////////////////////////////////////////////////////
  3. /// getID3() by James Heinrich <info@getid3.org> //
  4. // available at https://github.com/JamesHeinrich/getID3 //
  5. // or https://www.getid3.org //
  6. // or http://getid3.sourceforge.net //
  7. // //
  8. // /demo/demo.browse.php - part of getID3() //
  9. // Sample script for browsing/scanning files and displaying //
  10. // information returned by getID3() //
  11. // see readme.txt for more details //
  12. // ///
  13. /////////////////////////////////////////////////////////////////
  14. die('For security reasons, this demo has been disabled. It can be enabled by removing line '.__LINE__.' in demos/'.basename(__FILE__));
  15. define('GETID3_DEMO_BROWSE_ALLOW_EDIT_LINK', false); // if enabled, shows "edit" links (to /demos/demo.write.php) to allow ID3/APE/etc tag editing on applicable file types
  16. define('GETID3_DEMO_BROWSE_ALLOW_DELETE_LINK', false); // if enabled, shows "delete" links to delete files from the browse interface
  17. define('GETID3_DEMO_BROWSE_ALLOW_MD5_LINK', false); // if enabled, shows "enable" link for MD5 hashes for file/data/source
  18. /////////////////////////////////////////////////////////////////
  19. // die if magic_quotes_runtime or magic_quotes_gpc are set
  20. if (version_compare(PHP_VERSION, '7.4.0', '<')) { // get_magic_quotes_runtime / get_magic_quotes_gpc functions give deprecation warnings in PHP v7.4
  21. if (function_exists('get_magic_quotes_runtime') && get_magic_quotes_runtime()) {
  22. die('magic_quotes_runtime is enabled, getID3 will not run.');
  23. }
  24. if (function_exists('get_magic_quotes_gpc') && get_magic_quotes_gpc()) {
  25. die('magic_quotes_gpc is enabled, getID3 will not run.');
  26. }
  27. }
  28. /////////////////////////////////////////////////////////////////
  29. require_once('../getid3/getid3.php');
  30. $PageEncoding = 'UTF-8';
  31. $FileSystemEncoding = ((GETID3_OS_ISWINDOWS && version_compare(PHP_VERSION, '7.1.0', '<')) ? 'Windows-1252' : 'UTF-8');
  32. $writescriptfilename = 'demo.write.php';
  33. // Needed for windows only. Leave commented-out to auto-detect, only define here if auto-detection does not work properly
  34. //define('GETID3_HELPERAPPSDIR', 'C:\\helperapps\\');
  35. // Initialize getID3 engine
  36. $getID3 = new getID3;
  37. $getID3->setOption(array(
  38. 'encoding' => $PageEncoding,
  39. 'options_audiovideo_quicktime_ReturnAtomData' => true,
  40. ));
  41. $getID3checkColor_Head = 'CCCCDD';
  42. $getID3checkColor_DirectoryLight = 'FFCCCC';
  43. $getID3checkColor_DirectoryDark = 'EEBBBB';
  44. $getID3checkColor_FileLight = 'EEEEEE';
  45. $getID3checkColor_FileDark = 'DDDDDD';
  46. $getID3checkColor_UnknownLight = 'CCCCFF';
  47. $getID3checkColor_UnknownDark = 'BBBBDD';
  48. ///////////////////////////////////////////////////////////////////////////////
  49. header('Content-Type: text/html; charset='.$PageEncoding);
  50. echo '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">';
  51. echo '<html><head>';
  52. echo '<title>getID3() - /demo/demo.browse.php (sample script)</title>';
  53. echo '<link rel="stylesheet" href="getid3.css" type="text/css">';
  54. echo '<meta http-equiv="Content-Type" content="text/html;charset='.$PageEncoding.'" />';
  55. echo '</head><body>';
  56. if (isset($_REQUEST['deletefile']) && GETID3_DEMO_BROWSE_ALLOW_DELETE_LINK) {
  57. if (file_exists($_REQUEST['deletefile'])) {
  58. if (unlink($_REQUEST['deletefile'])) {
  59. $deletefilemessage = 'Successfully deleted '.$_REQUEST['deletefile'];
  60. } else {
  61. $deletefilemessage = 'FAILED to delete '.$_REQUEST['deletefile'].' - error deleting file';
  62. }
  63. } else {
  64. $deletefilemessage = 'FAILED to delete '.$_REQUEST['deletefile'].' - file does not exist';
  65. }
  66. if (isset($_REQUEST['noalert'])) {
  67. echo '<span style="font-weight: bold; color: #'.(($deletefilemessage[0] == 'F') ? 'FF0000' : '008000').';">'.htmlentities($deletefilemessage, ENT_QUOTES).'</span><hr>';
  68. } else {
  69. echo '<script type="text/javascript">alert("'.addslashes($deletefilemessage).'");</script>';
  70. }
  71. }
  72. if (isset($_REQUEST['filename'])) {
  73. if (!file_exists($_REQUEST['filename']) || !is_file($_REQUEST['filename'])) {
  74. die(getid3_lib::iconv_fallback($FileSystemEncoding, $PageEncoding, $_REQUEST['filename'].' does not exist'));
  75. }
  76. $starttime = microtime(true);
  77. //$getID3->setOption(array(
  78. // 'option_md5_data' => $AutoGetHashes,
  79. // 'option_sha1_data' => $AutoGetHashes,
  80. //));
  81. $ThisFileInfo = $getID3->analyze($_REQUEST['filename']);
  82. $AutoGetHashes = (bool) (isset($ThisFileInfo['filesize']) && ($ThisFileInfo['filesize'] > 0) && ($ThisFileInfo['filesize'] < (50 * 1048576))); // auto-get md5_data, md5_file, sha1_data, sha1_file if filesize < 50MB, and NOT zero (which may indicate a file>2GB)
  83. $AutoGetHashes = ($AutoGetHashes && GETID3_DEMO_BROWSE_ALLOW_MD5_LINK);
  84. if ($AutoGetHashes) {
  85. $ThisFileInfo['md5_file'] = md5_file($_REQUEST['filename']);
  86. $ThisFileInfo['sha1_file'] = sha1_file($_REQUEST['filename']);
  87. }
  88. $getID3->CopyTagsToComments($ThisFileInfo);
  89. $listdirectory = dirname($_REQUEST['filename']);
  90. $listdirectory = realpath($listdirectory); // get rid of /../../ references
  91. if (GETID3_OS_ISWINDOWS) {
  92. // this mostly just gives a consistant look to Windows and *nix filesystems
  93. // (windows uses \ as directory seperator, *nix uses /)
  94. $listdirectory = str_replace(DIRECTORY_SEPARATOR, '/', $listdirectory.'/');
  95. }
  96. if (preg_match('#^(ht|f)tp://#', $_REQUEST['filename'])) {
  97. echo '<i>Cannot browse remote filesystems</i><br>';
  98. } else {
  99. echo 'Browse: <a href="'.htmlentities($_SERVER['PHP_SELF'].'?listdirectory='.urlencode($listdirectory), ENT_QUOTES | ENT_SUBSTITUTE, $PageEncoding).'">'.getid3_lib::iconv_fallback($FileSystemEncoding, $PageEncoding, $listdirectory).'</a><br>';
  100. }
  101. getid3_lib::ksort_recursive($ThisFileInfo);
  102. echo table_var_dump($ThisFileInfo, false, $PageEncoding);
  103. $endtime = microtime(true);
  104. echo 'File parsed in '.number_format($endtime - $starttime, 3).' seconds.<br>';
  105. } else {
  106. $listdirectory = (isset($_REQUEST['listdirectory']) ? $_REQUEST['listdirectory'] : '.');
  107. $listdirectory = getid3_lib::truepath($listdirectory); // get rid of /../../ references
  108. $currentfulldir = str_replace(DIRECTORY_SEPARATOR, '/', $listdirectory).'/'; // this mostly just gives a consistant look to Windows and *nix filesystems: (Windows uses \ as directory seperator, *nix uses /)
  109. ob_start();
  110. if ($handle = opendir($listdirectory)) {
  111. ob_end_clean();
  112. echo str_repeat(' ', 300); // IE buffers the first 300 or so chars, making this progressive display useless - fill the buffer with spaces
  113. echo 'Processing';
  114. $starttime = microtime(true);
  115. $TotalScannedUnknownFiles = 0;
  116. $TotalScannedKnownFiles = 0;
  117. $TotalScannedPlaytimeFiles = 0;
  118. $TotalScannedBitrateFiles = 0;
  119. $TotalScannedFilesize = 0;
  120. $TotalScannedPlaytime = 0;
  121. $TotalScannedBitrate = 0;
  122. $FilesWithWarnings = 0;
  123. $FilesWithErrors = 0;
  124. while ($file = readdir($handle)) {
  125. $currentfilename = $listdirectory.'/'.$file;
  126. set_time_limit(30); // allocate another 30 seconds to process this file - should go much quicker than this unless intense processing (like bitrate histogram analysis) is enabled
  127. echo ' <span title="'.htmlentities($file, ENT_QUOTES).'">.</span>'; // progress indicator dot
  128. flush(); // make sure the dot is shown, otherwise it's useless
  129. switch ($file) {
  130. case '..':
  131. $ParentDir = realpath($file.'/..').'/';
  132. if (GETID3_OS_ISWINDOWS) {
  133. $ParentDir = str_replace(DIRECTORY_SEPARATOR, '/', $ParentDir);
  134. }
  135. $DirectoryContents[$currentfulldir]['dir'][$file]['filename'] = $ParentDir;
  136. continue 2;
  137. break;
  138. case '.':
  139. // ignore
  140. continue 2;
  141. break;
  142. }
  143. // symbolic-link-resolution enhancements by davidbullock״ech-center*com
  144. $TargetObject = realpath($currentfilename); // Find actual file path, resolve if it's a symbolic link
  145. $TargetObjectType = filetype($TargetObject); // Check file type without examining extension
  146. if ($TargetObjectType == 'dir') {
  147. $DirectoryContents[$currentfulldir]['dir'][$file]['filename'] = $file;
  148. } elseif ($TargetObjectType == 'file') {
  149. $getID3->setOption(array('option_md5_data' => (isset($_REQUEST['ShowMD5']) && GETID3_DEMO_BROWSE_ALLOW_MD5_LINK)));
  150. $fileinformation = $getID3->analyze($currentfilename);
  151. $getID3->CopyTagsToComments($fileinformation);
  152. $TotalScannedFilesize += (isset($fileinformation['filesize']) ? $fileinformation['filesize'] : 0);
  153. if (isset($_REQUEST['ShowMD5']) && GETID3_DEMO_BROWSE_ALLOW_MD5_LINK) {
  154. $fileinformation['md5_file'] = md5_file($currentfilename);
  155. }
  156. if (!empty($fileinformation['fileformat'])) {
  157. $DirectoryContents[$currentfulldir]['known'][$file] = $fileinformation;
  158. $TotalScannedPlaytime += (isset($fileinformation['playtime_seconds']) ? $fileinformation['playtime_seconds'] : 0);
  159. $TotalScannedBitrate += (isset($fileinformation['bitrate']) ? $fileinformation['bitrate'] : 0);
  160. $TotalScannedKnownFiles++;
  161. } else {
  162. $DirectoryContents[$currentfulldir]['other'][$file] = $fileinformation;
  163. $DirectoryContents[$currentfulldir]['other'][$file]['playtime_string'] = '-';
  164. $TotalScannedUnknownFiles++;
  165. }
  166. if (isset($fileinformation['playtime_seconds']) && ($fileinformation['playtime_seconds'] > 0)) {
  167. $TotalScannedPlaytimeFiles++;
  168. }
  169. if (isset($fileinformation['bitrate']) && ($fileinformation['bitrate'] > 0)) {
  170. $TotalScannedBitrateFiles++;
  171. }
  172. } else {
  173. echo '<div style="color: red;">Unknown filesystem entry: "'.htmlentities($currentfilename, ENT_QUOTES | ENT_SUBSTITUTE, $PageEncoding).'"</div>';
  174. }
  175. }
  176. $endtime = microtime(true);
  177. closedir($handle);
  178. echo 'done<br>';
  179. echo 'Directory scanned in '.number_format($endtime - $starttime, 2).' seconds.<br>';
  180. flush();
  181. $columnsintable = 14;
  182. echo '<table class="table" cellspacing="0" cellpadding="3">';
  183. echo '<tr bgcolor="#'.$getID3checkColor_Head.'"><th colspan="'.$columnsintable.'">Files in '.getid3_lib::iconv_fallback($FileSystemEncoding, $PageEncoding, $currentfulldir).'</th></tr>';
  184. $rowcounter = 0;
  185. foreach ($DirectoryContents as $dirname => $val) {
  186. if (isset($DirectoryContents[$dirname]['dir']) && is_array($DirectoryContents[$dirname]['dir'])) {
  187. uksort($DirectoryContents[$dirname]['dir'], 'MoreNaturalSort');
  188. foreach ($DirectoryContents[$dirname]['dir'] as $filename => $fileinfo) {
  189. echo '<tr bgcolor="#'.(($rowcounter++ % 2) ? $getID3checkColor_DirectoryLight : $getID3checkColor_DirectoryDark).'">';
  190. if ($filename == '..') {
  191. echo '<td colspan="'.$columnsintable.'">';
  192. echo '<form action="'.htmlentities($_SERVER['PHP_SELF'], ENT_QUOTES | ENT_SUBSTITUTE, $PageEncoding).'" method="get">';
  193. echo 'Parent directory: ';
  194. echo '<input type="text" name="listdirectory" size="50" style="background-color: '.$getID3checkColor_DirectoryDark.';" value="';
  195. if (GETID3_OS_ISWINDOWS) {
  196. echo htmlentities(str_replace(DIRECTORY_SEPARATOR, '/', realpath($dirname.$filename)), ENT_QUOTES | ENT_SUBSTITUTE, $PageEncoding);
  197. } else {
  198. echo htmlentities(realpath($dirname.$filename), ENT_QUOTES | ENT_SUBSTITUTE, $PageEncoding);
  199. }
  200. echo '"> <input type="submit" value="Go">';
  201. echo '</form></td>';
  202. } else {
  203. $escaped_filename = htmlentities($filename, ENT_SUBSTITUTE, $FileSystemEncoding); // do filesystems always return filenames in ISO-8859-1?
  204. $escaped_filename = ($escaped_filename ? $escaped_filename : rawurlencode($filename));
  205. echo '<td colspan="'.$columnsintable.'"><a href="'.htmlentities($_SERVER['PHP_SELF'].'?listdirectory='.urlencode($dirname.$filename), ENT_QUOTES | ENT_SUBSTITUTE, $PageEncoding).'"><b>'.$escaped_filename.'</b></a></td>';
  206. }
  207. echo '</tr>';
  208. }
  209. }
  210. echo '<tr bgcolor="#'.$getID3checkColor_Head.'">';
  211. echo '<th>Filename</th>';
  212. echo '<th>File Size</th>';
  213. echo '<th>Format</th>';
  214. echo '<th>Playtime</th>';
  215. echo '<th>Bitrate</th>';
  216. echo '<th>Artist</th>';
  217. echo '<th>Title</th>';
  218. if (isset($_REQUEST['ShowMD5']) && GETID3_DEMO_BROWSE_ALLOW_MD5_LINK) {
  219. echo '<th>MD5&nbsp;File (File) (<a href="'.htmlentities($_SERVER['PHP_SELF'].'?listdirectory='.rawurlencode(isset($_REQUEST['listdirectory']) ? $_REQUEST['listdirectory'] : '.'), ENT_QUOTES | ENT_SUBSTITUTE, $PageEncoding).'">disable</a>)</th>';
  220. echo '<th>MD5&nbsp;Data (File) (<a href="'.htmlentities($_SERVER['PHP_SELF'].'?listdirectory='.rawurlencode(isset($_REQUEST['listdirectory']) ? $_REQUEST['listdirectory'] : '.'), ENT_QUOTES | ENT_SUBSTITUTE, $PageEncoding).'">disable</a>)</th>';
  221. echo '<th>MD5&nbsp;Data (Source) (<a href="'.htmlentities($_SERVER['PHP_SELF'].'?listdirectory='.rawurlencode(isset($_REQUEST['listdirectory']) ? $_REQUEST['listdirectory'] : '.'), ENT_QUOTES | ENT_SUBSTITUTE, $PageEncoding).'">disable</a>)</th>';
  222. } else {
  223. echo '<th colspan="3">MD5&nbsp;Data'.(GETID3_DEMO_BROWSE_ALLOW_MD5_LINK ?' (<a href="'.htmlentities($_SERVER['PHP_SELF'].'?listdirectory='.rawurlencode(isset($_REQUEST['listdirectory']) ? $_REQUEST['listdirectory'] : '.').'&ShowMD5=1', ENT_QUOTES | ENT_SUBSTITUTE, $PageEncoding).'">enable</a>)' : '').'</th>';
  224. }
  225. echo '<th>Tags</th>';
  226. echo '<th>Errors &amp; Warnings</th>';
  227. echo (GETID3_DEMO_BROWSE_ALLOW_EDIT_LINK ? '<th>Edit</th>' : '');
  228. echo (GETID3_DEMO_BROWSE_ALLOW_DELETE_LINK ? '<th>Delete</th>' : '');
  229. echo '</tr>';
  230. if (isset($DirectoryContents[$dirname]['known']) && is_array($DirectoryContents[$dirname]['known'])) {
  231. uksort($DirectoryContents[$dirname]['known'], 'MoreNaturalSort');
  232. foreach ($DirectoryContents[$dirname]['known'] as $filename => $fileinfo) {
  233. echo '<tr bgcolor="#'.(($rowcounter++ % 2) ? $getID3checkColor_FileDark : $getID3checkColor_FileLight).'">';
  234. $escaped_filename = htmlentities($filename, ENT_SUBSTITUTE, $FileSystemEncoding); // do filesystems always return filenames in ISO-8859-1?
  235. $escaped_filename = ($escaped_filename ? $escaped_filename : rawurlencode($filename));
  236. echo '<td><a href="'.htmlentities($_SERVER['PHP_SELF'].'?filename='.urlencode($dirname.$filename), ENT_QUOTES | ENT_SUBSTITUTE, $PageEncoding).'" title="View detailed analysis">'.$escaped_filename.'</a></td>';
  237. echo '<td align="right">&nbsp;'.number_format($fileinfo['filesize']).'</td>';
  238. echo '<td align="right">&nbsp;'.NiceDisplayFiletypeFormat($fileinfo).'</td>';
  239. echo '<td align="right">&nbsp;'.(isset($fileinfo['playtime_string']) ? $fileinfo['playtime_string'] : '-').'</td>';
  240. echo '<td align="right">&nbsp;'.(isset($fileinfo['bitrate']) ? BitrateText($fileinfo['bitrate'] / 1000, 0, ((isset($fileinfo['audio']['bitrate_mode']) && ($fileinfo['audio']['bitrate_mode'] == 'vbr')) ? true : false)) : '-').'</td>';
  241. echo '<td align="left">&nbsp;'.(isset($fileinfo['comments_html']['artist']) ? implode('<br>', $fileinfo['comments_html']['artist']) : ((isset($fileinfo['video']['resolution_x']) && isset($fileinfo['video']['resolution_y'])) ? $fileinfo['video']['resolution_x'].'x'.$fileinfo['video']['resolution_y'] : '')).'</td>';
  242. echo '<td align="left">&nbsp;'.(isset($fileinfo['comments_html']['title']) ? implode('<br>', $fileinfo['comments_html']['title']) : (isset($fileinfo['video']['frame_rate']) ? number_format($fileinfo['video']['frame_rate'], 3).'fps' : '')).'</td>';
  243. if (isset($_REQUEST['ShowMD5']) && GETID3_DEMO_BROWSE_ALLOW_MD5_LINK) {
  244. echo '<td align="left"><tt>'.(isset($fileinfo['md5_file']) ? $fileinfo['md5_file'] : '&nbsp;').'</tt></td>';
  245. echo '<td align="left"><tt>'.(isset($fileinfo['md5_data']) ? $fileinfo['md5_data'] : '&nbsp;').'</tt></td>';
  246. echo '<td align="left"><tt>'.(isset($fileinfo['md5_data_source']) ? $fileinfo['md5_data_source'] : '&nbsp;').'</tt></td>';
  247. } else {
  248. echo '<td align="center" colspan="3">-</td>';
  249. }
  250. echo '<td align="left">&nbsp;'.(!empty($fileinfo['tags']) ? implode(', ', array_keys($fileinfo['tags'])) : '').'</td>';
  251. echo '<td align="left">&nbsp;';
  252. if (!empty($fileinfo['warning'])) {
  253. $FilesWithWarnings++;
  254. echo '<a href="#" onClick="alert(\''.htmlentities(str_replace("'", "\\'", preg_replace('#[\r\n\t]+#', ' ', implode('\\n', $fileinfo['warning']))), ENT_QUOTES | ENT_SUBSTITUTE, $PageEncoding).'\'); return false;" title="'.htmlentities(implode("; \n", $fileinfo['warning']), ENT_QUOTES | ENT_SUBSTITUTE, $PageEncoding).'">warning</a><br>';
  255. }
  256. if (!empty($fileinfo['error'])) {
  257. $FilesWithErrors++;
  258. echo '<a href="#" onClick="alert(\''.htmlentities(str_replace("'", "\\'", preg_replace('#[\r\n\t]+#', ' ', implode('\\n', $fileinfo['error']))), ENT_QUOTES | ENT_SUBSTITUTE, $PageEncoding).'\'); return false;" title="'.htmlentities(implode("; \n", $fileinfo['error']), ENT_QUOTES | ENT_SUBSTITUTE, $PageEncoding).'">error</a><br>';
  259. }
  260. echo '</td>';
  261. if (GETID3_DEMO_BROWSE_ALLOW_EDIT_LINK) {
  262. echo '<td align="left">&nbsp;';
  263. $fileinfo['fileformat'] = (isset($fileinfo['fileformat']) ? $fileinfo['fileformat'] : '');
  264. switch ($fileinfo['fileformat']) {
  265. case 'mp3':
  266. case 'mp2':
  267. case 'mp1':
  268. case 'flac':
  269. case 'mpc':
  270. case 'real':
  271. echo '<a href="'.htmlentities($writescriptfilename.'?Filename='.urlencode($dirname.$filename), ENT_QUOTES | ENT_SUBSTITUTE, $PageEncoding).'" title="Edit tags">edit&nbsp;tags</a>';
  272. break;
  273. case 'ogg':
  274. if (isset($fileinfo['audio']['dataformat']) && ($fileinfo['audio']['dataformat'] == 'vorbis')) {
  275. echo '<a href="'.htmlentities($writescriptfilename.'?Filename='.urlencode($dirname.$filename), ENT_QUOTES | ENT_SUBSTITUTE, $PageEncoding).'" title="Edit tags">edit&nbsp;tags</a>';
  276. }
  277. break;
  278. default:
  279. break;
  280. }
  281. echo '</td>';
  282. }
  283. if (GETID3_DEMO_BROWSE_ALLOW_DELETE_LINK) {
  284. echo '<td align="left">&nbsp;<a href="'.htmlentities($_SERVER['PHP_SELF'].'?listdirectory='.urlencode($listdirectory).'&deletefile='.urlencode($dirname.$filename), ENT_QUOTES | ENT_SUBSTITUTE, $PageEncoding).'" onClick="return confirm(\'Are you sure you want to delete '.addslashes(htmlentities($dirname.$filename)).'? \n(this action cannot be un-done)\');" title="'.htmlentities('Permanently delete '."\n".$filename."\n".' from'."\n".' '.$dirname, ENT_QUOTES | ENT_SUBSTITUTE, $PageEncoding).'">delete</a></td>';
  285. }
  286. echo '</tr>';
  287. }
  288. }
  289. if (isset($DirectoryContents[$dirname]['other']) && is_array($DirectoryContents[$dirname]['other'])) {
  290. uksort($DirectoryContents[$dirname]['other'], 'MoreNaturalSort');
  291. foreach ($DirectoryContents[$dirname]['other'] as $filename => $fileinfo) {
  292. echo '<tr bgcolor="#'.(($rowcounter++ % 2) ? $getID3checkColor_UnknownDark : $getID3checkColor_UnknownLight).'">';
  293. $escaped_filename = htmlentities($filename, ENT_SUBSTITUTE, $PageEncoding);
  294. $escaped_filename = ($escaped_filename ? $escaped_filename : rawurlencode($filename));
  295. echo '<td><a href="'.htmlentities($_SERVER['PHP_SELF'].'?filename='.urlencode($dirname.$filename), ENT_QUOTES | ENT_SUBSTITUTE, $PageEncoding).'"><i>'.$escaped_filename.'</i></a></td>';
  296. echo '<td align="right">&nbsp;'.(isset($fileinfo['filesize']) ? number_format($fileinfo['filesize']) : '-').'</td>';
  297. echo '<td align="right">&nbsp;'.NiceDisplayFiletypeFormat($fileinfo).'</td>';
  298. echo '<td align="right">&nbsp;'.(isset($fileinfo['playtime_string']) ? $fileinfo['playtime_string'] : '-').'</td>';
  299. echo '<td align="right">&nbsp;'.(isset($fileinfo['bitrate']) ? BitrateText($fileinfo['bitrate'] / 1000) : '-').'</td>';
  300. echo '<td align="left">&nbsp;</td>'; // Artist
  301. echo '<td align="left">&nbsp;</td>'; // Title
  302. echo '<td align="left" colspan="3">&nbsp;</td>'; // MD5_data
  303. echo '<td align="left">&nbsp;</td>'; // Tags
  304. //echo '<td align="left">&nbsp;</td>'; // Warning/Error
  305. echo '<td align="left">&nbsp;';
  306. if (!empty($fileinfo['warning'])) {
  307. $FilesWithWarnings++;
  308. echo '<a href="#" onClick="alert(\''.htmlentities(implode('\\n', $fileinfo['warning']), ENT_QUOTES | ENT_SUBSTITUTE, $PageEncoding).'\'); return false;" title="'.htmlentities(implode("\n", $fileinfo['warning']), ENT_QUOTES | ENT_SUBSTITUTE, $PageEncoding).'">warning</a><br>';
  309. }
  310. if (!empty($fileinfo['error'])) {
  311. if ($fileinfo['error'][0] != 'unable to determine file format') {
  312. $FilesWithErrors++;
  313. echo '<a href="#" onClick="alert(\''.htmlentities(implode('\\n', $fileinfo['error']), ENT_QUOTES | ENT_SUBSTITUTE, $PageEncoding).'\'); return false;" title="'.htmlentities(implode("\n", $fileinfo['error']), ENT_QUOTES | ENT_SUBSTITUTE, $PageEncoding).'">error</a><br>';
  314. }
  315. }
  316. echo '</td>';
  317. if (GETID3_DEMO_BROWSE_ALLOW_EDIT_LINK) {
  318. echo '<td align="left">&nbsp;</td>'; // Edit
  319. }
  320. if (GETID3_DEMO_BROWSE_ALLOW_DELETE_LINK) {
  321. echo '<td align="left">&nbsp;<a href="'.htmlentities($_SERVER['PHP_SELF'].'?listdirectory='.urlencode($listdirectory).'&deletefile='.urlencode($dirname.$filename), ENT_QUOTES | ENT_SUBSTITUTE, $PageEncoding).'" onClick="return confirm(\'Are you sure you want to delete '.addslashes($dirname.$filename).'? \n(this action cannot be un-done)\');" title="Permanently delete '.addslashes($dirname.$filename).'">delete</a></td>';
  322. }
  323. echo '</tr>';
  324. }
  325. }
  326. echo '<tr bgcolor="#'.$getID3checkColor_Head.'">';
  327. echo '<td><b>Average:</b></td>';
  328. echo '<td align="right">'.number_format($TotalScannedFilesize / max($TotalScannedKnownFiles, 1)).'</td>';
  329. echo '<td>&nbsp;</td>';
  330. echo '<td align="right">'.getid3_lib::PlaytimeString($TotalScannedPlaytime / max($TotalScannedPlaytimeFiles, 1)).'</td>';
  331. echo '<td align="right">'.BitrateText(round(($TotalScannedBitrate / 1000) / max($TotalScannedBitrateFiles, 1))).'</td>';
  332. echo '<td rowspan="2" colspan="'.($columnsintable - 5).'"><table class="table" border="0" cellspacing="0" cellpadding="2"><tr><th align="right">Identified Files:</th><td align="right">'.number_format($TotalScannedKnownFiles).'</td><td>&nbsp;&nbsp;&nbsp;</td><th align="right">Errors:</th><td align="right">'.number_format($FilesWithErrors).'</td></tr><tr><th align="right">Unknown Files:</th><td align="right">'.number_format($TotalScannedUnknownFiles).'</td><td>&nbsp;&nbsp;&nbsp;</td><th align="right">Warnings:</th><td align="right">'.number_format($FilesWithWarnings).'</td></tr></table>';
  333. echo '</tr>';
  334. echo '<tr bgcolor="#'.$getID3checkColor_Head.'">';
  335. echo '<td><b>Total:</b></td>';
  336. echo '<td align="right">'.number_format($TotalScannedFilesize).'</td>';
  337. echo '<td>&nbsp;</td>';
  338. echo '<td align="right">'.getid3_lib::PlaytimeString($TotalScannedPlaytime).'</td>';
  339. echo '<td>&nbsp;</td>';
  340. echo '</tr>';
  341. }
  342. echo '</table>';
  343. } else {
  344. $errormessage = ob_get_contents();
  345. ob_end_clean();
  346. echo '<b>ERROR: Could not open directory: <u>'.htmlentities($currentfulldir, ENT_QUOTES | ENT_SUBSTITUTE, $PageEncoding).'</u></b><br>';
  347. //echo $errormessage.'<br>'; // uncomment for debugging
  348. }
  349. }
  350. echo PoweredBygetID3().'<br clear="all">';
  351. echo '</body></html>';
  352. /////////////////////////////////////////////////////////////////
  353. function RemoveAccents($string) {
  354. // Revised version by markstewardרotmail*com
  355. // Again revised by James Heinrich (19-June-2006)
  356. return strtr(
  357. strtr(
  358. $string,
  359. "\x8A\x8E\x9A\x9E\x9F\xC0\xC1\xC2\xC3\xC4\xC5\xC7\xC8\xC9\xCA\xCB\xCC\xCD\xCE\xCF\xD1\xD2\xD3\xD4\xD5\xD6\xD8\xD9\xDA\xDB\xDC\xDD\xE0\xE1\xE2\xE3\xE4\xE5\xE7\xE8\xE9\xEA\xEB\xEC\xED\xEE\xEF\xF1\xF2\xF3\xF4\xF5\xF6\xF8\xF9\xFA\xFB\xFC\xFD\xFF",
  360. 'SZszYAAAAAACEEEEIIIINOOOOOOUUUUYaaaaaaceeeeiiiinoooooouuuuyy'
  361. ),
  362. array(
  363. "\xDE" => 'TH',
  364. "\xFE" => 'th',
  365. "\xD0" => 'DH',
  366. "\xF0" => 'dh',
  367. "\xDF" => 'ss',
  368. "\x8C" => 'OE',
  369. "\x9C" => 'oe',
  370. "\xC6" => 'AE',
  371. "\xE6" => 'ae',
  372. "\xB5" => 'u'
  373. )
  374. );
  375. }
  376. function BitrateColor($bitrate, $BitrateMaxScale=768) {
  377. // $BitrateMaxScale is bitrate of maximum-quality color (bright green)
  378. // below this is gradient, above is solid green
  379. $bitrate *= (256 / $BitrateMaxScale); // scale from 1-[768]kbps to 1-256
  380. $bitrate = round(min(max($bitrate, 1), 256));
  381. $bitrate--; // scale from 1-256kbps to 0-255kbps
  382. $Rcomponent = max(255 - ($bitrate * 2), 0);
  383. $Gcomponent = max(($bitrate * 2) - 255, 0);
  384. if ($bitrate > 127) {
  385. $Bcomponent = max((255 - $bitrate) * 2, 0);
  386. } else {
  387. $Bcomponent = max($bitrate * 2, 0);
  388. }
  389. return str_pad(dechex($Rcomponent), 2, '0', STR_PAD_LEFT).str_pad(dechex($Gcomponent), 2, '0', STR_PAD_LEFT).str_pad(dechex($Bcomponent), 2, '0', STR_PAD_LEFT);
  390. }
  391. function BitrateText($bitrate, $decimals=0, $vbr=false) {
  392. return '<span style="color: #'.BitrateColor($bitrate).($vbr ? '; font-weight: bold;' : '').'">'.number_format($bitrate, $decimals).' kbps</span>';
  393. }
  394. function string_var_dump($variable) {
  395. if (version_compare(PHP_VERSION, '4.3.0', '>=')) {
  396. return print_r($variable, true);
  397. }
  398. ob_start();
  399. var_dump($variable);
  400. $dumpedvariable = ob_get_contents();
  401. ob_end_clean();
  402. return $dumpedvariable;
  403. }
  404. function table_var_dump($variable, $wrap_in_td=false, $encoding='') {
  405. global $FileSystemEncoding;
  406. $encoding = ($encoding ? $encoding : $FileSystemEncoding);
  407. $returnstring = '';
  408. switch (gettype($variable)) {
  409. case 'array':
  410. $returnstring .= ($wrap_in_td ? '<td>' : '');
  411. $returnstring .= '<table class="dump" cellspacing="0" cellpadding="2">';
  412. foreach ($variable as $key => $value) {
  413. $returnstring .= '<tr><td valign="top"><b>'.str_replace("\x00", ' ', $key).'</b></td>'."\n";
  414. $returnstring .= '<td valign="top">'.gettype($value);
  415. if (is_array($value)) {
  416. $returnstring .= '&nbsp;('.count($value).')';
  417. } elseif (is_string($value)) {
  418. $returnstring .= '&nbsp;('.strlen($value).')';
  419. }
  420. //if (($key == 'data') && isset($variable['image_mime']) && isset($variable['dataoffset'])) {
  421. if (($key == 'data') && isset($variable['image_mime'])) {
  422. $imageinfo = array();
  423. if ($imagechunkcheck = getid3_lib::GetDataImageSize($value, $imageinfo)) {
  424. $returnstring .= '</td>'."\n".'<td><img src="data:'.$variable['image_mime'].';base64,'.base64_encode($value).'" width="'.$imagechunkcheck[0].'" height="'.$imagechunkcheck[1].'"></td></tr>'."\n";
  425. } else {
  426. $returnstring .= '</td>'."\n".'<td><i>invalid image data</i></td></tr>'."\n";
  427. }
  428. } else {
  429. $returnstring .= '</td>'."\n".table_var_dump($value, true, $encoding).'</tr>'."\n";
  430. }
  431. }
  432. $returnstring .= '</table>'."\n";
  433. $returnstring .= ($wrap_in_td ? '</td>'."\n" : '');
  434. break;
  435. case 'boolean':
  436. $returnstring .= ($wrap_in_td ? '<td class="dump_boolean">' : '').($variable ? 'TRUE' : 'FALSE').($wrap_in_td ? '</td>'."\n" : '');
  437. break;
  438. case 'integer':
  439. $returnstring .= ($wrap_in_td ? '<td class="dump_integer">' : '').$variable.($wrap_in_td ? '</td>'."\n" : '');
  440. break;
  441. case 'double':
  442. case 'float':
  443. $returnstring .= ($wrap_in_td ? '<td class="dump_double">' : '').$variable.($wrap_in_td ? '</td>'."\n" : '');
  444. break;
  445. case 'object':
  446. case 'null':
  447. $returnstring .= ($wrap_in_td ? '<td>' : '').string_var_dump($variable).($wrap_in_td ? '</td>'."\n" : '');
  448. break;
  449. case 'string':
  450. $returnstring = htmlentities($variable, ENT_QUOTES | ENT_SUBSTITUTE, $encoding);
  451. $returnstring = ($wrap_in_td ? '<td class="dump_string">' : '').nl2br($returnstring).($wrap_in_td ? '</td>'."\n" : '');
  452. break;
  453. default:
  454. $imageinfo = array();
  455. if (($imagechunkcheck = getid3_lib::GetDataImageSize($variable, $imageinfo)) && ($imagechunkcheck[2] >= 1) && ($imagechunkcheck[2] <= 3)) {
  456. $returnstring .= ($wrap_in_td ? '<td>' : '');
  457. $returnstring .= '<table class="dump" cellspacing="0" cellpadding="2">';
  458. $returnstring .= '<tr><td><b>type</b></td><td>'.image_type_to_mime_type($imagechunkcheck[2]).'</td></tr>'."\n";
  459. $returnstring .= '<tr><td><b>width</b></td><td>'.number_format($imagechunkcheck[0]).' px</td></tr>'."\n";
  460. $returnstring .= '<tr><td><b>height</b></td><td>'.number_format($imagechunkcheck[1]).' px</td></tr>'."\n";
  461. $returnstring .= '<tr><td><b>size</b></td><td>'.number_format(strlen($variable)).' bytes</td></tr></table>'."\n";
  462. $returnstring .= ($wrap_in_td ? '</td>'."\n" : '');
  463. } else {
  464. $returnstring .= ($wrap_in_td ? '<td>' : '').nl2br(htmlspecialchars(str_replace("\x00", ' ', $variable))).($wrap_in_td ? '</td>'."\n" : '');
  465. }
  466. break;
  467. }
  468. return $returnstring;
  469. }
  470. function NiceDisplayFiletypeFormat(&$fileinfo) {
  471. if (empty($fileinfo['fileformat'])) {
  472. return '-';
  473. }
  474. $output = $fileinfo['fileformat'];
  475. if (empty($fileinfo['video']['dataformat']) && empty($fileinfo['audio']['dataformat'])) {
  476. return $output; // 'gif'
  477. }
  478. if (empty($fileinfo['video']['dataformat']) && !empty($fileinfo['audio']['dataformat'])) {
  479. if ($fileinfo['fileformat'] == $fileinfo['audio']['dataformat']) {
  480. return $output; // 'mp3'
  481. }
  482. $output .= '.'.$fileinfo['audio']['dataformat']; // 'ogg.flac'
  483. return $output;
  484. }
  485. if (!empty($fileinfo['video']['dataformat']) && empty($fileinfo['audio']['dataformat'])) {
  486. if ($fileinfo['fileformat'] == $fileinfo['video']['dataformat']) {
  487. return $output; // 'mpeg'
  488. }
  489. $output .= '.'.$fileinfo['video']['dataformat']; // 'riff.avi'
  490. return $output;
  491. }
  492. if ($fileinfo['video']['dataformat'] == $fileinfo['audio']['dataformat']) {
  493. if ($fileinfo['fileformat'] == $fileinfo['video']['dataformat']) {
  494. return $output; // 'real'
  495. }
  496. $output .= '.'.$fileinfo['video']['dataformat']; // any examples?
  497. return $output;
  498. }
  499. $output .= '.'.$fileinfo['video']['dataformat'];
  500. $output .= '.'.$fileinfo['audio']['dataformat']; // asf.wmv.wma
  501. return $output;
  502. }
  503. function MoreNaturalSort($ar1, $ar2) {
  504. if ($ar1 === $ar2) {
  505. return 0;
  506. }
  507. $len1 = strlen($ar1);
  508. $len2 = strlen($ar2);
  509. $shortest = min($len1, $len2);
  510. if (substr($ar1, 0, $shortest) === substr($ar2, 0, $shortest)) {
  511. // the shorter argument is the beginning of the longer one, like "str" and "string"
  512. if ($len1 < $len2) {
  513. return -1;
  514. } elseif ($len1 > $len2) {
  515. return 1;
  516. }
  517. return 0;
  518. }
  519. $ar1 = RemoveAccents(strtolower(trim($ar1)));
  520. $ar2 = RemoveAccents(strtolower(trim($ar2)));
  521. $translatearray = array('\''=>'', '"'=>'', '_'=>' ', '('=>'', ')'=>'', '-'=>' ', ' '=>' ', '.'=>'', ','=>'');
  522. foreach ($translatearray as $key => $val) {
  523. $ar1 = str_replace($key, $val, $ar1);
  524. $ar2 = str_replace($key, $val, $ar2);
  525. }
  526. if ($ar1 < $ar2) {
  527. return -1;
  528. } elseif ($ar1 > $ar2) {
  529. return 1;
  530. }
  531. return 0;
  532. }
  533. /**
  534. * @param string $string
  535. *
  536. * @return mixed
  537. */
  538. function PoweredBygetID3($string='') {
  539. global $getID3;
  540. if (!$string) {
  541. $string = '<div style="border: 1px #CCCCCC solid; padding: 5px; margin: 5px 0; float: left; background-color: #EEEEEE; font-size: 8pt; font-family: sans-serif;">Powered by <a href="https://www.getid3.org/"><b>getID3() v<!--GETID3VER--></b><br>https://www.getid3.org/</a><br>Running on PHP v'.PHP_VERSION.' ('.(8 * PHP_INT_SIZE).'-bit, '.(defined('PHP_OS_FAMILY') ? PHP_OS_FAMILY : PHP_OS).')</div>';
  542. }
  543. return str_replace('<!--GETID3VER-->', $getID3->version(), $string);
  544. }