PageRenderTime 58ms CodeModel.GetById 17ms RepoModel.GetById 1ms app.codeStats 0ms

/phpvideotoolkit/adapters/ffmpeg-php/getid3/demos/demo.browse.php

http://phpvideotoolkit.googlecode.com/
PHP | 669 lines | 535 code | 92 blank | 42 comment | 93 complexity | fdb6d6a2e1338c5c65b2ba0e691b9d8a 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. /////////////////////////////////////////////////////////////////
  15. // set predefined variables as if magic_quotes_gpc was off,
  16. // whether the server's got it or not:
  17. UnifyMagicQuotes(false);
  18. /////////////////////////////////////////////////////////////////
  19. /////////////////////////////////////////////////////////////////
  20. // showfile is used to display embedded images from table_var_dump()
  21. // md5 of requested file is required to prevent abuse where any
  22. // random file on the server could be viewed
  23. if (@$_REQUEST['showfile']) {
  24. if (is_readable($_REQUEST['showfile'])) {
  25. if (md5_file($_REQUEST['showfile']) == @$_REQUEST['md5']) {
  26. readfile($_REQUEST['showfile']);
  27. exit;
  28. }
  29. }
  30. die('Cannot display "'.$_REQUEST['showfile'].'"');
  31. }
  32. /////////////////////////////////////////////////////////////////
  33. if (!function_exists('getmicrotime')) {
  34. function getmicrotime() {
  35. list($usec, $sec) = explode(' ', microtime());
  36. return ((float) $usec + (float) $sec);
  37. }
  38. }
  39. ///////////////////////////////////////////////////////////////////////////////
  40. $writescriptfilename = 'demo.write.php';
  41. require_once('../getid3/getid3.php');
  42. // Needed for windows only
  43. define('GETID3_HELPERAPPSDIR', 'C:/helperapps/');
  44. // Initialize getID3 engine
  45. $getID3 = new getID3;
  46. $getID3->setOption(array('encoding' => 'UTF-8'));
  47. $getID3checkColor_Head = 'CCCCDD';
  48. $getID3checkColor_DirectoryLight = 'FFCCCC';
  49. $getID3checkColor_DirectoryDark = 'EEBBBB';
  50. $getID3checkColor_FileLight = 'EEEEEE';
  51. $getID3checkColor_FileDark = 'DDDDDD';
  52. $getID3checkColor_UnknownLight = 'CCCCFF';
  53. $getID3checkColor_UnknownDark = 'BBBBDD';
  54. ///////////////////////////////////////////////////////////////////////////////
  55. header('Content-Type: text/html; charset=UTF-8');
  56. ob_start();
  57. echo '<html><head>';
  58. echo '<title>getID3() - /demo/demo.browse.php (sample script)</title>';
  59. echo '<style>BODY,TD,TH { font-family: sans-serif; font-size: 9pt; }</style>';
  60. echo '</head><body>';
  61. if (isset($_REQUEST['deletefile'])) {
  62. if (file_exists($_REQUEST['deletefile'])) {
  63. if (unlink($_REQUEST['deletefile'])) {
  64. $deletefilemessage = 'Successfully deleted '.addslashes($_REQUEST['deletefile']);
  65. } else {
  66. $deletefilemessage = 'FAILED to delete '.addslashes($_REQUEST['deletefile']).' - error deleting file';
  67. }
  68. } else {
  69. $deletefilemessage = 'FAILED to delete '.addslashes($_REQUEST['deletefile']).' - file does not exist';
  70. }
  71. if (isset($_REQUEST['noalert'])) {
  72. echo '<b><font color="'.(($deletefilemessage{0} == 'F') ? '#FF0000' : '#008000').'">'.$deletefilemessage.'</font></b><hr>';
  73. } else {
  74. echo '<script language="JavaScript">alert("'.$deletefilemessage.'");</script>';
  75. }
  76. }
  77. if (isset($_REQUEST['filename'])) {
  78. if (!file_exists($_REQUEST['filename'])) {
  79. die(getid3_lib::iconv_fallback('ISO-8859-1', 'UTF-8', $_REQUEST['filename'].' does not exist'));
  80. }
  81. $starttime = getmicrotime();
  82. $AutoGetHashes = (bool) (filesize($_REQUEST['filename']) < 52428800); // auto-get md5_data, md5_file, sha1_data, sha1_file if filesize < 50MB
  83. $getID3->setOption(array(
  84. 'option_md5_data' => $AutoGetHashes,
  85. 'option_sha1_data' => $AutoGetHashes,
  86. ));
  87. $ThisFileInfo = $getID3->analyze($_REQUEST['filename']);
  88. if ($AutoGetHashes) {
  89. $ThisFileInfo['md5_file'] = getid3_lib::md5_file($_REQUEST['filename']);
  90. $ThisFileInfo['sha1_file'] = getid3_lib::sha1_file($_REQUEST['filename']);
  91. }
  92. getid3_lib::CopyTagsToComments($ThisFileInfo);
  93. $listdirectory = dirname(getid3_lib::SafeStripSlashes($_REQUEST['filename']));
  94. $listdirectory = realpath($listdirectory); // get rid of /../../ references
  95. if (GETID3_OS_ISWINDOWS) {
  96. // this mostly just gives a consistant look to Windows and *nix filesystems
  97. // (windows uses \ as directory seperator, *nix uses /)
  98. $listdirectory = str_replace('\\', '/', $listdirectory.'/');
  99. }
  100. if (strstr($_REQUEST['filename'], 'http://') || strstr($_REQUEST['filename'], 'ftp://')) {
  101. echo '<i>Cannot browse remote filesystems</i><br>';
  102. } else {
  103. echo 'Browse: <a href="'.$_SERVER['PHP_SELF'].'?listdirectory='.urlencode($listdirectory).'">'.getid3_lib::iconv_fallback('ISO-8859-1', 'UTF-8', $listdirectory).'</a><br>';
  104. }
  105. echo table_var_dump($ThisFileInfo);
  106. $endtime = getmicrotime();
  107. echo 'File parsed in '.number_format($endtime - $starttime, 3).' seconds.<br>';
  108. } else {
  109. $listdirectory = (isset($_REQUEST['listdirectory']) ? getid3_lib::SafeStripSlashes($_REQUEST['listdirectory']) : '.');
  110. $listdirectory = realpath($listdirectory); // get rid of /../../ references
  111. $currentfulldir = $listdirectory.'/';
  112. if (GETID3_OS_ISWINDOWS) {
  113. // this mostly just gives a consistant look to Windows and *nix filesystems
  114. // (windows uses \ as directory seperator, *nix uses /)
  115. $currentfulldir = str_replace('\\', '/', $listdirectory.'/');
  116. }
  117. if ($handle = @opendir($listdirectory)) {
  118. echo str_repeat(' ', 300); // IE buffers the first 300 or so chars, making this progressive display useless - fill the buffer with spaces
  119. echo 'Processing';
  120. $starttime = getmicrotime();
  121. $TotalScannedUnknownFiles = 0;
  122. $TotalScannedKnownFiles = 0;
  123. $TotalScannedPlaytimeFiles = 0;
  124. $TotalScannedBitrateFiles = 0;
  125. $TotalScannedFilesize = 0;
  126. $TotalScannedPlaytime = 0;
  127. $TotalScannedBitrate = 0;
  128. $FilesWithWarnings = 0;
  129. $FilesWithErrors = 0;
  130. while ($file = readdir($handle)) {
  131. 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
  132. echo ' .'; // progress indicator dot
  133. flush(); // make sure the dot is shown, otherwise it's useless
  134. $currentfilename = $listdirectory.'/'.$file;
  135. switch ($file) {
  136. case '..':
  137. $ParentDir = realpath($file.'/..').'/';
  138. if (GETID3_OS_ISWINDOWS) {
  139. $ParentDir = str_replace('\\', '/', $ParentDir);
  140. }
  141. $DirectoryContents[$currentfulldir]['dir'][$file]['filename'] = $ParentDir;
  142. continue 2;
  143. break;
  144. case '.':
  145. // ignore
  146. continue 2;
  147. break;
  148. }
  149. // symbolic-link-resolution enhancements by davidbullock?ech-center*com
  150. $TargetObject = realpath($currentfilename); // Find actual file path, resolve if it's a symbolic link
  151. $TargetObjectType = filetype($TargetObject); // Check file type without examining extension
  152. if ($TargetObjectType == 'dir') {
  153. $DirectoryContents[$currentfulldir]['dir'][$file]['filename'] = $file;
  154. } elseif ($TargetObjectType == 'file') {
  155. $getID3->setOption(array('option_md5_data' => isset($_REQUEST['ShowMD5'])));
  156. $fileinformation = $getID3->analyze($currentfilename);
  157. getid3_lib::CopyTagsToComments($fileinformation);
  158. $TotalScannedFilesize += @$fileinformation['filesize'];
  159. if (isset($_REQUEST['ShowMD5'])) {
  160. $fileinformation['md5_file'] = md5($currentfilename);
  161. $fileinformation['md5_file'] = getid3_lib::md5_file($currentfilename);
  162. }
  163. if (!empty($fileinformation['fileformat'])) {
  164. $DirectoryContents[$currentfulldir]['known'][$file] = $fileinformation;
  165. $TotalScannedPlaytime += @$fileinformation['playtime_seconds'];
  166. $TotalScannedBitrate += @$fileinformation['bitrate'];
  167. $TotalScannedKnownFiles++;
  168. } else {
  169. $DirectoryContents[$currentfulldir]['other'][$file] = $fileinformation;
  170. $DirectoryContents[$currentfulldir]['other'][$file]['playtime_string'] = '-';
  171. $TotalScannedUnknownFiles++;
  172. }
  173. if (isset($fileinformation['playtime_seconds']) && ($fileinformation['playtime_seconds'] > 0)) {
  174. $TotalScannedPlaytimeFiles++;
  175. }
  176. if (isset($fileinformation['bitrate']) && ($fileinformation['bitrate'] > 0)) {
  177. $TotalScannedBitrateFiles++;
  178. }
  179. }
  180. }
  181. $endtime = getmicrotime();
  182. closedir($handle);
  183. echo 'done<br>';
  184. echo 'Directory scanned in '.number_format($endtime - $starttime, 2).' seconds.<br>';
  185. flush();
  186. $columnsintable = 14;
  187. echo '<table border="1" cellspacing="0" cellpadding="3">';
  188. echo '<tr bgcolor="#'.$getID3checkColor_Head.'"><th colspan="'.$columnsintable.'">Files in '.getid3_lib::iconv_fallback('ISO-8859-1', 'UTF-8', $currentfulldir).'</th></tr>';
  189. $rowcounter = 0;
  190. foreach ($DirectoryContents as $dirname => $val) {
  191. if (is_array($DirectoryContents[$dirname]['dir'])) {
  192. uksort($DirectoryContents[$dirname]['dir'], 'MoreNaturalSort');
  193. foreach ($DirectoryContents[$dirname]['dir'] as $filename => $fileinfo) {
  194. echo '<tr bgcolor="#'.(($rowcounter++ % 2) ? $getID3checkColor_DirectoryLight : $getID3checkColor_DirectoryDark).'">';
  195. if ($filename == '..') {
  196. echo '<form action="'.$_SERVER['PHP_SELF'].'" method="get">';
  197. echo '<td colspan="'.$columnsintable.'">Parent directory: ';
  198. echo '<input type="text" name="listdirectory" size="50" style="background-color: '.$getID3checkColor_DirectoryDark.';" value="';
  199. if (GETID3_OS_ISWINDOWS) {
  200. echo htmlentities(str_replace('\\', '/', realpath($dirname.$filename)), ENT_QUOTES);
  201. } else {
  202. echo htmlentities(realpath($dirname.$filename), ENT_QUOTES);
  203. }
  204. echo '"> <input type="submit" value="Go">';
  205. echo '</td></form>';
  206. } else {
  207. echo '<td colspan="'.$columnsintable.'"><a href="'.$_SERVER['PHP_SELF'].'?listdirectory='.urlencode($dirname.$filename).'"><b>'.FixTextFields($filename).'</b></a></td>';
  208. }
  209. echo '</tr>';
  210. }
  211. }
  212. echo '<tr bgcolor="#'.$getID3checkColor_Head.'">';
  213. echo '<th>Filename</th>';
  214. echo '<th>File Size</th>';
  215. echo '<th>Format</th>';
  216. echo '<th>Playtime</th>';
  217. echo '<th>Bitrate</th>';
  218. echo '<th>Artist</th>';
  219. echo '<th>Title</th>';
  220. if (isset($_REQUEST['ShowMD5'])) {
  221. echo '<th>MD5&nbsp;File (File) (<a href="'.$_SERVER['PHP_SELF'].'?listdirectory='.rawurlencode(isset($_REQUEST['listdirectory']) ? $_REQUEST['listdirectory'] : '.').'">disable</a>)</th>';
  222. echo '<th>MD5&nbsp;Data (File) (<a href="'.$_SERVER['PHP_SELF'].'?listdirectory='.rawurlencode(isset($_REQUEST['listdirectory']) ? $_REQUEST['listdirectory'] : '.').'">disable</a>)</th>';
  223. echo '<th>MD5&nbsp;Data (Source) (<a href="'.$_SERVER['PHP_SELF'].'?listdirectory='.rawurlencode(isset($_REQUEST['listdirectory']) ? $_REQUEST['listdirectory'] : '.').'">disable</a>)</th>';
  224. } else {
  225. echo '<th colspan="3">MD5&nbsp;Data (<a href="'.$_SERVER['PHP_SELF'].'?listdirectory='.rawurlencode(isset($_REQUEST['listdirectory']) ? $_REQUEST['listdirectory'] : '.').'&ShowMD5=1">enable</a>)</th>';
  226. }
  227. echo '<th>Tags</th>';
  228. echo '<th>Errors & Warnings</th>';
  229. echo '<th>Edit</th>';
  230. echo '<th>Delete</th>';
  231. echo '</tr>';
  232. if (isset($DirectoryContents[$dirname]['known']) && is_array($DirectoryContents[$dirname]['known'])) {
  233. uksort($DirectoryContents[$dirname]['known'], 'MoreNaturalSort');
  234. foreach ($DirectoryContents[$dirname]['known'] as $filename => $fileinfo) {
  235. echo '<tr bgcolor="#'.(($rowcounter++ % 2) ? $getID3checkColor_FileDark : $getID3checkColor_FileLight).'">';
  236. echo '<td><a href="'.$_SERVER['PHP_SELF'].'?filename='.urlencode($dirname.$filename).'" TITLE="View detailed analysis">'.FixTextFields(getid3_lib::SafeStripSlashes($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, ((@$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']) : '').'</td>';
  242. echo '<td align="left">&nbsp;'.(isset($fileinfo['comments_html']['title']) ? implode('<br>', $fileinfo['comments_html']['title']) : '').'</td>';
  243. if (isset($_REQUEST['ShowMD5'])) {
  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;'.@implode(', ', array_keys($fileinfo['tags'])).'</td>';
  251. echo '<td align="left">&nbsp;';
  252. if (!empty($fileinfo['warning'])) {
  253. $FilesWithWarnings++;
  254. echo '<a href="javascript:alert(\''.FixTextFields(implode('\\n', $fileinfo['warning'])).'\');" TITLE="'.FixTextFields(implode("\n", $fileinfo['warning'])).'">warning</a><br>';
  255. }
  256. if (!empty($fileinfo['error'])) {
  257. $FilesWithErrors++;
  258. echo '<a href="javascript:alert(\''.FixTextFields(implode('\\n', $fileinfo['error'])).'\');" TITLE="'.FixTextFields(implode("\n", $fileinfo['error'])).'">error</a><br>';
  259. }
  260. echo '</td>';
  261. echo '<td align="left">&nbsp;';
  262. switch (@$fileinfo['fileformat']) {
  263. case 'mp3':
  264. case 'mp2':
  265. case 'mp1':
  266. case 'flac':
  267. case 'mpc':
  268. case 'real':
  269. echo '<a href="'.$writescriptfilename.'?Filename='.urlencode($dirname.$filename).'" TITLE="Edit tags">edit&nbsp;tags</a>';
  270. break;
  271. case 'ogg':
  272. switch (@$fileinfo['audio']['dataformat']) {
  273. case 'vorbis':
  274. echo '<a href="'.$writescriptfilename.'?Filename='.urlencode($dirname.$filename).'" TITLE="Edit tags">edit&nbsp;tags</a>';
  275. break;
  276. }
  277. break;
  278. default:
  279. break;
  280. }
  281. echo '</td>';
  282. echo '<td align="left">&nbsp;<a href="'.$_SERVER['PHP_SELF'].'?listdirectory='.urlencode($listdirectory).'&deletefile='.urlencode($dirname.$filename).'" onClick="return confirm(\'Are you sure you want to delete '.addslashes($dirname.$filename).'? \n(this action cannot be un-done)\');" TITLE="Permanently delete '."\n".FixTextFields($filename)."\n".' from'."\n".' '.FixTextFields($dirname).'">delete</a></td>';
  283. echo '</tr>';
  284. }
  285. }
  286. if (isset($DirectoryContents[$dirname]['other']) && is_array($DirectoryContents[$dirname]['other'])) {
  287. uksort($DirectoryContents[$dirname]['other'], 'MoreNaturalSort');
  288. foreach ($DirectoryContents[$dirname]['other'] as $filename => $fileinfo) {
  289. echo '<tr bgcolor="#'.(($rowcounter++ % 2) ? $getID3checkColor_UnknownDark : $getID3checkColor_UnknownLight).'">';
  290. echo '<td><a href="'.$_SERVER['PHP_SELF'].'?filename='.urlencode($dirname.$filename).'"><i>'.$filename.'</i></a></td>';
  291. echo '<td align="right">&nbsp;'.(isset($fileinfo['filesize']) ? number_format($fileinfo['filesize']) : '-').'</td>';
  292. echo '<td align="right">&nbsp;'.NiceDisplayFiletypeFormat($fileinfo).'</td>';
  293. echo '<td align="right">&nbsp;'.(isset($fileinfo['playtime_string']) ? $fileinfo['playtime_string'] : '-').'</td>';
  294. echo '<td align="right">&nbsp;'.(isset($fileinfo['bitrate']) ? BitrateText($fileinfo['bitrate'] / 1000) : '-').'</td>';
  295. echo '<td align="left">&nbsp;</td>'; // Artist
  296. echo '<td align="left">&nbsp;</td>'; // Title
  297. echo '<td align="left" colspan="3">&nbsp;</td>'; // MD5_data
  298. echo '<td align="left">&nbsp;</td>'; // Tags
  299. //echo '<td align="left">&nbsp;</td>'; // Warning/Error
  300. echo '<td align="left">&nbsp;';
  301. if (!empty($fileinfo['warning'])) {
  302. $FilesWithWarnings++;
  303. echo '<a href="javascript:alert(\''.FixTextFields(implode('\\n', $fileinfo['warning'])).'\');" TITLE="'.FixTextFields(implode("\n", $fileinfo['warning'])).'">warning</a><br>';
  304. }
  305. if (!empty($fileinfo['error'])) {
  306. if ($fileinfo['error'][0] != 'unable to determine file format') {
  307. $FilesWithErrors++;
  308. echo '<a href="javascript:alert(\''.FixTextFields(implode('\\n', $fileinfo['error'])).'\');" TITLE="'.FixTextFields(implode("\n", $fileinfo['error'])).'">error</a><br>';
  309. }
  310. }
  311. echo '</td>';
  312. echo '<td align="left">&nbsp;</td>'; // Edit
  313. echo '<td align="left">&nbsp;<a href="'.$_SERVER['PHP_SELF'].'?listdirectory='.urlencode($listdirectory).'&deletefile='.urlencode($dirname.$filename).'" 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>';
  314. echo '</tr>';
  315. }
  316. }
  317. echo '<tr bgcolor="#'.$getID3checkColor_Head.'">';
  318. echo '<td><b>Average:</b></td>';
  319. echo '<td align="right">'.number_format($TotalScannedFilesize / max($TotalScannedKnownFiles, 1)).'</td>';
  320. echo '<td>&nbsp;</td>';
  321. echo '<td align="right">'.getid3_lib::PlaytimeString($TotalScannedPlaytime / max($TotalScannedPlaytimeFiles, 1)).'</td>';
  322. echo '<td align="right">'.BitrateText(round(($TotalScannedBitrate / 1000) / max($TotalScannedBitrateFiles, 1))).'</td>';
  323. echo '<td rowspan="2" colspan="'.($columnsintable - 5).'"><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>';
  324. echo '</tr>';
  325. echo '<tr bgcolor="#'.$getID3checkColor_Head.'">';
  326. echo '<td><b>Total:</b></td>';
  327. echo '<td align="right">'.number_format($TotalScannedFilesize).'</td>';
  328. echo '<td>&nbsp;</td>';
  329. echo '<td align="right">'.getid3_lib::PlaytimeString($TotalScannedPlaytime).'</td>';
  330. echo '<td>&nbsp;</td>';
  331. echo '</tr>';
  332. }
  333. echo '</table>';
  334. } else {
  335. echo '<b>ERROR: Could not open directory: <u>'.$currentfulldir.'</u></b><br>';
  336. }
  337. }
  338. echo PoweredBygetID3();
  339. echo 'Running on PHP v'.phpversion();
  340. echo '</body></html>';
  341. ob_end_flush();
  342. /////////////////////////////////////////////////////////////////
  343. function RemoveAccents($string) {
  344. // Revised version by marksteward?otmail*com
  345. // Again revised by James Heinrich (19-June-2006)
  346. return strtr(
  347. strtr(
  348. $string,
  349. "\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",
  350. 'SZszYAAAAAACEEEEIIIINOOOOOOUUUUYaaaaaaceeeeiiiinoooooouuuuyy'
  351. ),
  352. array(
  353. "\xDE" => 'TH',
  354. "\xFE" => 'th',
  355. "\xD0" => 'DH',
  356. "\xF0" => 'dh',
  357. "\xDF" => 'ss',
  358. "\x8C" => 'OE',
  359. "\x9C" => 'oe',
  360. "\xC6" => 'AE',
  361. "\xE6" => 'ae',
  362. "\xB5" => 'u'
  363. )
  364. );
  365. }
  366. function BitrateColor($bitrate, $BitrateMaxScale=768) {
  367. // $BitrateMaxScale is bitrate of maximum-quality color (bright green)
  368. // below this is gradient, above is solid green
  369. $bitrate *= (256 / $BitrateMaxScale); // scale from 1-[768]kbps to 1-256
  370. $bitrate = round(min(max($bitrate, 1), 256));
  371. $bitrate--; // scale from 1-256kbps to 0-255kbps
  372. $Rcomponent = max(255 - ($bitrate * 2), 0);
  373. $Gcomponent = max(($bitrate * 2) - 255, 0);
  374. if ($bitrate > 127) {
  375. $Bcomponent = max((255 - $bitrate) * 2, 0);
  376. } else {
  377. $Bcomponent = max($bitrate * 2, 0);
  378. }
  379. 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);
  380. }
  381. function BitrateText($bitrate, $decimals=0, $vbr=false) {
  382. return '<SPAN STYLE="color: #'.BitrateColor($bitrate).($vbr ? '; font-weight: bold;' : '').'">'.number_format($bitrate, $decimals).' kbps</SPAN>';
  383. }
  384. function FixTextFields($text) {
  385. $text = getid3_lib::SafeStripSlashes($text);
  386. $text = htmlentities($text, ENT_QUOTES);
  387. return $text;
  388. }
  389. function string_var_dump($variable) {
  390. ob_start();
  391. var_dump($variable);
  392. $dumpedvariable = ob_get_contents();
  393. ob_end_clean();
  394. return $dumpedvariable;
  395. }
  396. function table_var_dump($variable) {
  397. $returnstring = '';
  398. switch (gettype($variable)) {
  399. case 'array':
  400. $returnstring .= '<table border="1" cellspacing="0" cellpadding="2">';
  401. foreach ($variable as $key => $value) {
  402. $returnstring .= '<tr><td valign="top"><b>'.str_replace("\x00", ' ', $key).'</b></td>';
  403. $returnstring .= '<td valign="top">'.gettype($value);
  404. if (is_array($value)) {
  405. $returnstring .= '&nbsp;('.count($value).')';
  406. } elseif (is_string($value)) {
  407. $returnstring .= '&nbsp;('.strlen($value).')';
  408. }
  409. if (($key == 'data') && isset($variable['image_mime']) && isset($variable['dataoffset'])) {
  410. $imagechunkcheck = getid3_lib::GetDataImageSize($value);
  411. $DumpedImageSRC = (!empty($_REQUEST['filename']) ? $_REQUEST['filename'] : '.getid3').'.'.$variable['dataoffset'].'.'.getid3_lib::ImageTypesLookup($imagechunkcheck[2]);
  412. if ($tempimagefile = @fopen($DumpedImageSRC, 'wb')) {
  413. fwrite($tempimagefile, $value);
  414. fclose($tempimagefile);
  415. }
  416. $returnstring .= '</td><td><img src="'.$_SERVER['PHP_SELF'].'?showfile='.urlencode($DumpedImageSRC).'&md5='.md5_file($DumpedImageSRC).'" width="'.$imagechunkcheck[0].'" height="'.$imagechunkcheck[1].'"></td></tr>';
  417. } else {
  418. $returnstring .= '</td><td>'.table_var_dump($value).'</td></tr>';
  419. }
  420. }
  421. $returnstring .= '</table>';
  422. break;
  423. case 'boolean':
  424. $returnstring .= ($variable ? 'TRUE' : 'FALSE');
  425. break;
  426. case 'integer':
  427. case 'double':
  428. case 'float':
  429. $returnstring .= $variable;
  430. break;
  431. case 'object':
  432. case 'null':
  433. $returnstring .= string_var_dump($variable);
  434. break;
  435. case 'string':
  436. $variable = str_replace("\x00", ' ', $variable);
  437. $varlen = strlen($variable);
  438. for ($i = 0; $i < $varlen; $i++) {
  439. if (ereg('['."\x0A\x0D".' -;0-9A-Za-z]', $variable{$i})) {
  440. $returnstring .= $variable{$i};
  441. } else {
  442. $returnstring .= '&#'.str_pad(ord($variable{$i}), 3, '0', STR_PAD_LEFT).';';
  443. }
  444. }
  445. $returnstring = nl2br($returnstring);
  446. break;
  447. default:
  448. $imagechunkcheck = getid3_lib::GetDataImageSize($variable);
  449. if (($imagechunkcheck[2] >= 1) && ($imagechunkcheck[2] <= 3)) {
  450. $returnstring .= '<table border="1" cellspacing="0" cellpadding="2">';
  451. $returnstring .= '<tr><td><b>type</b></td><td>'.getid3_lib::ImageTypesLookup($imagechunkcheck[2]).'</td></tr>';
  452. $returnstring .= '<tr><td><b>width</b></td><td>'.number_format($imagechunkcheck[0]).' px</td></tr>';
  453. $returnstring .= '<tr><td><b>height</b></td><td>'.number_format($imagechunkcheck[1]).' px</td></tr>';
  454. $returnstring .= '<tr><td><b>size</b></td><td>'.number_format(strlen($variable)).' bytes</td></tr></table>';
  455. } else {
  456. $returnstring .= nl2br(htmlspecialchars(str_replace("\x00", ' ', $variable)));
  457. }
  458. break;
  459. }
  460. return $returnstring;
  461. }
  462. function NiceDisplayFiletypeFormat(&$fileinfo) {
  463. if (empty($fileinfo['fileformat'])) {
  464. return '-';
  465. }
  466. $output = $fileinfo['fileformat'];
  467. if (empty($fileinfo['video']['dataformat']) && empty($fileinfo['audio']['dataformat'])) {
  468. return $output; // 'gif'
  469. }
  470. if (empty($fileinfo['video']['dataformat']) && !empty($fileinfo['audio']['dataformat'])) {
  471. if ($fileinfo['fileformat'] == $fileinfo['audio']['dataformat']) {
  472. return $output; // 'mp3'
  473. }
  474. $output .= '.'.$fileinfo['audio']['dataformat']; // 'ogg.flac'
  475. return $output;
  476. }
  477. if (!empty($fileinfo['video']['dataformat']) && empty($fileinfo['audio']['dataformat'])) {
  478. if ($fileinfo['fileformat'] == $fileinfo['video']['dataformat']) {
  479. return $output; // 'mpeg'
  480. }
  481. $output .= '.'.$fileinfo['video']['dataformat']; // 'riff.avi'
  482. return $output;
  483. }
  484. if ($fileinfo['video']['dataformat'] == $fileinfo['audio']['dataformat']) {
  485. if ($fileinfo['fileformat'] == $fileinfo['video']['dataformat']) {
  486. return $output; // 'real'
  487. }
  488. $output .= '.'.$fileinfo['video']['dataformat']; // any examples?
  489. return $output;
  490. }
  491. $output .= '.'.$fileinfo['video']['dataformat'];
  492. $output .= '.'.$fileinfo['audio']['dataformat']; // asf.wmv.wma
  493. return $output;
  494. }
  495. function MoreNaturalSort($ar1, $ar2) {
  496. if ($ar1 === $ar2) {
  497. return 0;
  498. }
  499. $len1 = strlen($ar1);
  500. $len2 = strlen($ar2);
  501. $shortest = min($len1, $len2);
  502. if (substr($ar1, 0, $shortest) === substr($ar2, 0, $shortest)) {
  503. // the shorter argument is the beginning of the longer one, like "str" and "string"
  504. if ($len1 < $len2) {
  505. return -1;
  506. } elseif ($len1 > $len2) {
  507. return 1;
  508. }
  509. return 0;
  510. }
  511. $ar1 = RemoveAccents(strtolower(trim($ar1)));
  512. $ar2 = RemoveAccents(strtolower(trim($ar2)));
  513. $translatearray = array('\''=>'', '"'=>'', '_'=>' ', '('=>'', ')'=>'', '-'=>' ', ' '=>' ', '.'=>'', ','=>'');
  514. foreach ($translatearray as $key => $val) {
  515. $ar1 = str_replace($key, $val, $ar1);
  516. $ar2 = str_replace($key, $val, $ar2);
  517. }
  518. if ($ar1 < $ar2) {
  519. return -1;
  520. } elseif ($ar1 > $ar2) {
  521. return 1;
  522. }
  523. return 0;
  524. }
  525. function PoweredBygetID3($string='<br><HR NOSHADE><DIV STYLE="font-size: 8pt; font-face: sans-serif;">Powered by <a href="http://getid3.sourceforge.net" TARGET="_blank"><b>getID3() v<!--GETID3VER--></b><br>http://getid3.sourceforge.net</a></DIV>') {
  526. return str_replace('<!--GETID3VER-->', GETID3_VERSION, $string);
  527. }
  528. /////////////////////////////////////////////////////////////////
  529. // Unify the contents of GPC,
  530. // whether magic_quotes_gpc is on or off
  531. function AddStripSlashesArray($input, $addslashes=false) {
  532. if (is_array($input)) {
  533. $output = $input;
  534. foreach ($input as $key => $value) {
  535. $output[$key] = AddStripSlashesArray($input[$key]);
  536. }
  537. return $output;
  538. } elseif ($addslashes) {
  539. return addslashes($input);
  540. }
  541. return stripslashes($input);
  542. }
  543. function UnifyMagicQuotes($turnon=false) {
  544. global $HTTP_GET_VARS, $HTTP_POST_VARS, $HTTP_COOKIE_VARS;
  545. if (get_magic_quotes_gpc() && !$turnon) {
  546. // magic_quotes_gpc is on and we want it off!
  547. $_GET = AddStripSlashesArray($_GET, true);
  548. $_POST = AddStripSlashesArray($_POST, true);
  549. $_COOKIE = AddStripSlashesArray($_COOKIE, true);
  550. unset($_REQUEST);
  551. $_REQUEST = array_merge_recursive($_GET, $_POST, $_COOKIE);
  552. } elseif (!get_magic_quotes_gpc() && $turnon) {
  553. // magic_quotes_gpc is off and we want it on (why??)
  554. $_GET = AddStripSlashesArray($_GET, true);
  555. $_POST = AddStripSlashesArray($_POST, true);
  556. $_COOKIE = AddStripSlashesArray($_COOKIE, true);
  557. unset($_REQUEST);
  558. $_REQUEST = array_merge_recursive($_GET, $_POST, $_COOKIE);
  559. }
  560. $HTTP_GET_VARS = $_GET;
  561. $HTTP_POST_VARS = $_POST;
  562. $HTTP_COOKIE_VARS = $_COOKIE;
  563. return true;
  564. }
  565. /////////////////////////////////////////////////////////////////
  566. ?>
  567. </BODY>
  568. </HTML>