PageRenderTime 49ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/demos/demo.browse.php

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