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

/includes/functions.inc.php

https://github.com/gotow/Shine
PHP | 773 lines | 647 code | 72 blank | 54 comment | 114 complexity | f9723d78e21422d644c1cd698477c755 MD5 | raw file
  1. <?PHP
  2. function set_option($key, $val)
  3. {
  4. $db = Database::getDatabase();
  5. $db->query('REPLACE INTO shine_options (`key`, `value`) VALUES (:key, :value)', array('key' => $key, 'value' => $val));
  6. }
  7. function get_option($key, $default = null)
  8. {
  9. $db = Database::getDatabase();
  10. $db->query('SELECT `value` FROM shine_options WHERE `key` = :key', array('key' => $key));
  11. if($db->hasRows())
  12. return $db->getValue();
  13. else
  14. return $default;
  15. }
  16. function printr($var)
  17. {
  18. $output = print_r($var, true);
  19. $output = str_replace("\n", "<br>", $output);
  20. $output = str_replace(' ', '&nbsp;', $output);
  21. echo "<div style='font-family:courier;'>$output</div>";
  22. }
  23. // Formats a given number of seconds into proper mm:ss format
  24. function format_time($seconds)
  25. {
  26. return floor($seconds / 60) . ':' . str_pad($seconds % 60, 2, '0');
  27. }
  28. // Given a string such as "comment_123" or "id_57", it returns the final, numeric id.
  29. function split_id($str)
  30. {
  31. return match('/[_-]([0-9]+)$/', $str, 1);
  32. }
  33. // Creates a friendly URL slug from a string
  34. function slugify($str)
  35. {
  36. $str = preg_replace('/[^a-zA-Z0-9 -]/', '', $str);
  37. $str = strtolower(str_replace(' ', '-', trim($str)));
  38. $str = preg_replace('/-+/', '-', $str);
  39. return $str;
  40. }
  41. // Computes the *full* URL of the current page (protocol, server, path, query parameters, etc)
  42. function full_url()
  43. {
  44. $s = empty($_SERVER['HTTPS']) ? '' : ($_SERVER['HTTPS'] == 'on') ? 's' : '';
  45. $protocol = substr(strtolower($_SERVER['SERVER_PROTOCOL']), 0, strpos(strtolower($_SERVER['SERVER_PROTOCOL']), '/')) . $s;
  46. $port = ($_SERVER['SERVER_PORT'] == '80') ? '' : (":".$_SERVER['SERVER_PORT']);
  47. return $protocol . "://" . $_SERVER['HTTP_HOST'] . $port . $_SERVER['REQUEST_URI'];
  48. }
  49. // Returns an English representation of a past date within the last month
  50. // Graciously stolen from http://ejohn.org/files/pretty.js
  51. function time2str($ts)
  52. {
  53. if(!ctype_digit($ts))
  54. $ts = strtotime($ts);
  55. $diff = time() - $ts;
  56. if($diff == 0)
  57. return 'now';
  58. elseif($diff > 0)
  59. {
  60. $day_diff = floor($diff / 86400);
  61. if($day_diff == 0)
  62. {
  63. if($diff < 60) return 'just now';
  64. if($diff < 120) return '1 minute ago';
  65. if($diff < 3600) return floor($diff / 60) . ' minutes ago';
  66. if($diff < 7200) return '1 hour ago';
  67. if($diff < 86400) return floor($diff / 3600) . ' hours ago';
  68. }
  69. if($day_diff == 1) return 'Yesterday';
  70. if($day_diff < 7) return $day_diff . ' days ago';
  71. if($day_diff < 31) return ceil($day_diff / 7) . ' weeks ago';
  72. if($day_diff < 60) return 'last month';
  73. $ret = date('F Y', $ts);
  74. return ($ret == 'December 1969') ? '' : $ret;
  75. }
  76. else
  77. {
  78. $diff = abs($diff);
  79. $day_diff = floor($diff / 86400);
  80. if($day_diff == 0)
  81. {
  82. if($diff < 120) return 'in a minute';
  83. if($diff < 3600) return 'in ' . floor($diff / 60) . ' minutes';
  84. if($diff < 7200) return 'in an hour';
  85. if($diff < 86400) return 'in ' . floor($diff / 3600) . ' hours';
  86. }
  87. if($day_diff == 1) return 'Tomorrow';
  88. if($day_diff < 4) return date('l', $ts);
  89. if($day_diff < 7 + (7 - date('w'))) return 'next week';
  90. if(ceil($day_diff / 7) < 4) return 'in ' . ceil($day_diff / 7) . ' weeks';
  91. if(date('n', $ts) == date('n') + 1) return 'next month';
  92. $ret = date('F Y', $ts);
  93. return ($ret == 'December 1969') ? '' : $ret;
  94. }
  95. }
  96. // Returns an array representation of the given calendar month.
  97. // The array values are timestamps which allow you to easily format
  98. // and manipulate the dates as needed.
  99. function calendar($month = null, $year = null)
  100. {
  101. if(is_null($month)) $month = date('n');
  102. if(is_null($year)) $year = date('Y');
  103. $first = mktime(0, 0, 0, $month, 1, $year);
  104. $last = mktime(23, 59, 59, $month, date('t', $first), $year);
  105. $start = $first - (86400 * date('w', $first));
  106. $stop = $last + (86400 * (7 - date('w', $first)));
  107. $out = array();
  108. while($start < $stop)
  109. {
  110. $week = array();
  111. if($start > $last) break;
  112. for($i = 0; $i < 7; $i++)
  113. {
  114. $week[$i] = $start;
  115. $start += 86400;
  116. }
  117. $out[] = $week;
  118. }
  119. return $out;
  120. }
  121. // Processes mod_rewrite URLs into key => value pairs
  122. // See .htacess for more info.
  123. function pick_off($grab_first = false, $sep = '/')
  124. {
  125. $ret = array();
  126. $arr = explode($sep, trim($_SERVER['REQUEST_URI'], $sep));
  127. if($grab_first) $ret[0] = array_shift($arr);
  128. while(count($arr) > 0)
  129. $ret[array_shift($arr)] = array_shift($arr);
  130. return (count($ret) > 0) ? $ret : false;
  131. }
  132. // Creates a list of <option>s from the given database table.
  133. // table name, column to use as value, column(s) to use as text, default value(s) to select (can accept an array of values), extra sql to limit results
  134. function get_options($table, $val, $text, $default = null, $sql = '')
  135. {
  136. $db = Database::getDatabase(true);
  137. $out = '';
  138. $table = $db->escape($table);
  139. $rows = $db->getRows("SELECT * FROM `$table` $sql");
  140. foreach($rows as $row)
  141. {
  142. $the_text = '';
  143. if(!is_array($text)) $text = array($text); // Allows you to concat multiple fields for display
  144. foreach($text as $t)
  145. $the_text .= $row[$t] . ' ';
  146. $the_text = htmlspecialchars(trim($the_text));
  147. if(!is_null($default) && $row[$val] == $default)
  148. $out .= '<option value="' . htmlspecialchars($row[$val], ENT_QUOTES) . '" selected="selected">' . $the_text . '</option>';
  149. elseif(is_array($default) && in_array($row[$val],$default))
  150. $out .= '<option value="' . htmlspecialchars($row[$val], ENT_QUOTES) . '" selected="selected">' . $the_text . '</option>';
  151. else
  152. $out .= '<option value="' . htmlspecialchars($row[$val], ENT_QUOTES) . '">' . $the_text . '</option>';
  153. }
  154. return $out;
  155. }
  156. // More robust strict date checking for string representations
  157. function chkdate($str)
  158. {
  159. // Requires PHP 5.2
  160. if(function_exists('date_parse'))
  161. {
  162. $info = date_parse($str);
  163. if($info !== false && $info['error_count'] == 0)
  164. {
  165. if(checkdate($info['month'], $info['day'], $info['year']))
  166. return true;
  167. }
  168. return false;
  169. }
  170. // Else, for PHP < 5.2
  171. return strtotime($str);
  172. }
  173. // Converts a date/timestamp into the specified format
  174. function dater($date = null, $format = null)
  175. {
  176. if(is_null($format))
  177. $format = 'Y-m-d H:i:s';
  178. if(is_null($date))
  179. $date = time();
  180. // if $date contains only numbers, treat it as a timestamp
  181. if(ctype_digit($date) === true)
  182. return date($format, $date);
  183. else
  184. return date($format, strtotime($date));
  185. }
  186. // Formats a phone number as (xxx) xxx-xxxx or xxx-xxxx depending on the length.
  187. function format_phone($phone)
  188. {
  189. $phone = preg_replace("/[^0-9]/", '', $phone);
  190. if(strlen($phone) == 7)
  191. return preg_replace("/([0-9]{3})([0-9]{4})/", "$1-$2", $phone);
  192. elseif(strlen($phone) == 10)
  193. return preg_replace("/([0-9]{3})([0-9]{3})([0-9]{4})/", "($1) $2-$3", $phone);
  194. else
  195. return $phone;
  196. }
  197. // Outputs hour, minute, am/pm dropdown boxes
  198. function hourmin($hid = 'hour', $mid = 'minute', $pid = 'ampm', $hval = null, $mval = null, $pval = null)
  199. {
  200. // Dumb hack to let you just pass in a timestamp instead
  201. if(func_num_args() == 1)
  202. {
  203. list($hval, $mval, $pval) = explode(' ', date('g i a', strtotime($hid)));
  204. $hid = 'hour';
  205. $mid = 'minute';
  206. $aid = 'ampm';
  207. }
  208. else
  209. {
  210. if(is_null($hval)) $hval = date('h');
  211. if(is_null($mval)) $mval = date('i');
  212. if(is_null($pval)) $pval = date('a');
  213. }
  214. $hours = array(12, 1, 2, 3, 4, 5, 6, 7, 9, 10, 11);
  215. $out = "<select name='$hid' id='$hid'>";
  216. foreach($hours as $hour)
  217. if(intval($hval) == intval($hour)) $out .= "<option value='$hour' selected>$hour</option>";
  218. else $out .= "<option value='$hour'>$hour</option>";
  219. $out .= "</select>";
  220. $minutes = array('00', 15, 30, 45);
  221. $out .= "<select name='$mid' id='$mid'>";
  222. foreach($minutes as $minute)
  223. if(intval($mval) == intval($minute)) $out .= "<option value='$minute' selected>$minute</option>";
  224. else $out .= "<option value='$minute'>$minute</option>";
  225. $out .= "</select>";
  226. $out .= "<select name='$pid' id='$pid'>";
  227. $out .= "<option value='am'>am</option>";
  228. if($pval == 'pm') $out .= "<option value='pm' selected>pm</option>";
  229. else $out .= "<option value='pm'>pm</option>";
  230. $out .= "</select>";
  231. return $out;
  232. }
  233. // Returns the HTML for a month, day, and year dropdown boxes.
  234. // You can set the default date by passing in a timestamp OR a parseable date string.
  235. // $prefix_ will be appened to the name/id's of each dropdown, allowing for multiple calls in the same form.
  236. // $output_format lets you specify which dropdowns appear and in what order.
  237. function mdy($date = null, $prefix = null, $output_format = 'm d y')
  238. {
  239. if(is_null($date)) $date = time();
  240. if(!ctype_digit($date)) $date = strtotime($date);
  241. if(!is_null($prefix)) $prefix .= '_';
  242. list($yval, $mval, $dval) = explode(' ', date('Y n j', $date));
  243. $month_dd = "<select name='{$prefix}month' id='{$prefix}month'>";
  244. for($i = 1; $i <= 12; $i++)
  245. {
  246. $selected = ($mval == $i) ? ' selected="selected"' : '';
  247. $month_dd .= "<option value='$i'$selected>" . date('F', mktime(0, 0, 0, $i, 1, 2000)) . "</option>";
  248. }
  249. $month_dd .= "</select>";
  250. $day_dd = "<select name='{$prefix}day' id='{$prefix}day'>";
  251. for($i = 1; $i <= 31; $i++)
  252. {
  253. $selected = ($dval == $i) ? ' selected="selected"' : '';
  254. $day_dd .= "<option value='$i'$selected>$i</option>";
  255. }
  256. $day_dd .= "</select>";
  257. $year_dd = "<select name='{$prefix}year' id='{$prefix}year'>";
  258. for($i = date('Y'); $i < date('Y') + 10; $i++)
  259. {
  260. $selected = ($yval == $i) ? ' selected="selected"' : '';
  261. $year_dd .= "<option value='$i'$selected>$i</option>";
  262. }
  263. $year_dd .= "</select>";
  264. $trans = array('m' => $month_dd, 'd' => $day_dd, 'y' => $year_dd);
  265. return strtr($output_format, $trans);
  266. }
  267. // Redirects user to $url
  268. function redirect($url = null)
  269. {
  270. if(is_null($url)) $url = $_SERVER['PHP_SELF'];
  271. header("Location: $url");
  272. exit();
  273. }
  274. // Ensures $str ends with a single /
  275. function slash($str)
  276. {
  277. return rtrim($str, '/') . '/';
  278. }
  279. // Ensures $str DOES NOT end with a /
  280. function unslash($str)
  281. {
  282. return rtrim($str, '/');
  283. }
  284. // Returns an array of the values of the specified column from a multi-dimensional array
  285. function gimme($arr, $key = null, $mod = 1)
  286. {
  287. if(is_null($key))
  288. $key = current(array_keys($arr));
  289. $out = array();
  290. $i = 0;
  291. foreach($arr as $k => $a)
  292. {
  293. if($i % $mod == 0)
  294. $out[] = $a[$key];
  295. $i++;
  296. }
  297. return $out;
  298. }
  299. // Fixes MAGIC_QUOTES
  300. function fix_slashes($arr = '')
  301. {
  302. if(is_null($arr) || $arr == '') return null;
  303. if(!get_magic_quotes_gpc()) return $arr;
  304. return is_array($arr) ? array_map('fix_slashes', $arr) : stripslashes($arr);
  305. }
  306. // Returns the first $num words of $str
  307. function max_words($str, $num, $suffix = '')
  308. {
  309. $words = explode(' ', $str);
  310. if(count($words) < $num)
  311. return $str;
  312. else
  313. return implode(' ', array_slice($words, 0, $num)) . $suffix;
  314. }
  315. // Serves an external document for download as an HTTP attachment.
  316. function download_document($filename, $mimetype = 'application/octet-stream')
  317. {
  318. if(!file_exists($filename) || !is_readable($filename)) return false;
  319. $base = basename($filename);
  320. header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
  321. header("Content-Disposition: attachment; filename=$base");
  322. header("Content-Length: " . filesize($filename));
  323. header("Content-Type: $mimetype");
  324. readfile($filename);
  325. exit();
  326. }
  327. // Retrieves the filesize of a remote file.
  328. function remote_filesize($url, $user = null, $pw = null)
  329. {
  330. $ch = curl_init($url);
  331. curl_setopt($ch, CURLOPT_HEADER, 1);
  332. curl_setopt($ch, CURLOPT_NOBODY, 1);
  333. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  334. if(!is_null($user) && !is_null($pw))
  335. {
  336. $headers = array('Authorization: Basic ' . base64_encode("$user:$pw"));
  337. curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
  338. }
  339. $head = curl_exec($ch);
  340. curl_close($ch);
  341. preg_match('/Content-Length:\s([0-9].+?)\s/', $head, $matches);
  342. return isset($matches[1]) ? $matches[1] : false;
  343. }
  344. // Outputs a filesize in human readable format.
  345. function bytes2str($val, $round = 0)
  346. {
  347. $unit = array('','K','M','G','T','P','E','Z','Y');
  348. while($val >= 1000)
  349. {
  350. $val /= 1024;
  351. array_shift($unit);
  352. }
  353. return round($val, $round) . array_shift($unit) . 'B';
  354. }
  355. // Tests for a valid email address and optionally tests for valid MX records, too.
  356. function valid_email($email, $test_mx = false)
  357. {
  358. if(preg_match("/^([_a-z0-9+-]+)(\.[_a-z0-9-]+)*@([a-z0-9-]+)(\.[a-z0-9-]+)*(\.[a-z]{2,4})$/i", $email))
  359. {
  360. if($test_mx)
  361. {
  362. list( , $domain) = explode("@", $email);
  363. return getmxrr($domain, $mxrecords);
  364. }
  365. else
  366. return true;
  367. }
  368. else
  369. return false;
  370. }
  371. // Grabs the contents of a remote URL. Can perform basic authentication if un/pw are provided.
  372. function geturl($url, $username = null, $password = null)
  373. {
  374. if(function_exists('curl_init'))
  375. {
  376. $ch = curl_init();
  377. if(!is_null($username) && !is_null($password))
  378. curl_setopt($ch, CURLOPT_HTTPHEADER, array('Authorization: Basic ' . base64_encode("$username:$password")));
  379. curl_setopt($ch, CURLOPT_URL, $url);
  380. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  381. curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
  382. $html = curl_exec($ch);
  383. curl_close($ch);
  384. return $html;
  385. }
  386. elseif(ini_get('allow_url_fopen') == true)
  387. {
  388. if(!is_null($username) && !is_null($password))
  389. $url = str_replace("://", "://$username:$password@", $url);
  390. $html = file_get_contents($url);
  391. return $html;
  392. }
  393. else
  394. {
  395. // Cannot open url. Either install curl-php or set allow_url_fopen = true in php.ini
  396. return false;
  397. }
  398. }
  399. // Returns the user's browser info.
  400. // browscap.ini must be available for this to work.
  401. // See the PHP manual for more details.
  402. function browser_info()
  403. {
  404. $info = get_browser(null, true);
  405. $browser = $info['browser'] . ' ' . $info['version'];
  406. $os = $info['platform'];
  407. $ip = $_SERVER['REMOTE_ADDR'];
  408. return array('ip' => $ip, 'browser' => $browser, 'os' => $os);
  409. }
  410. // Quick wrapper for preg_match
  411. function match($regex, $str, $i = 0)
  412. {
  413. if(preg_match($regex, $str, $match) == 1)
  414. return $match[$i];
  415. else
  416. return false;
  417. }
  418. // Sends an HTML formatted email
  419. function send_html_mail($to, $subject, $msg, $from, $plaintext = '')
  420. {
  421. if(!is_array($to)) $to = array($to);
  422. foreach($to as $address)
  423. {
  424. $boundary = uniqid(rand(), true);
  425. $headers = "From: $from\n";
  426. $headers .= "MIME-Version: 1.0\n";
  427. $headers .= "Content-Type: multipart/alternative; boundary = $boundary\n";
  428. $headers .= "This is a MIME encoded message.\n\n";
  429. $headers .= "--$boundary\n" .
  430. "Content-Type: text/plain; charset=ISO-8859-1\n" .
  431. "Content-Transfer-Encoding: base64\n\n";
  432. $headers .= chunk_split(base64_encode($plaintext));
  433. $headers .= "--$boundary\n" .
  434. "Content-Type: text/html; charset=ISO-8859-1\n" .
  435. "Content-Transfer-Encoding: base64\n\n";
  436. $headers .= chunk_split(base64_encode($msg));
  437. $headers .= "--$boundary--\n" .
  438. mail($address, $subject, '', $headers);
  439. }
  440. }
  441. // Returns the lat, long of an address via Yahoo!'s geocoding service.
  442. // You'll need an App ID, which is available from here:
  443. // http://developer.yahoo.com/maps/rest/V1/geocode.html
  444. function geocode($location, $appid)
  445. {
  446. $location = urlencode($location);
  447. $appid = urlencode($appid);
  448. $data = file_get_contents("http://local.yahooapis.com/MapsService/V1/geocode?output=php&appid=$appid&location=$location");
  449. $data = unserialize($data);
  450. if($data === false) return false;
  451. $data = $data['ResultSet']['Result'];
  452. return array('lat' => $data['Latitude'], 'lng' => $data['Longitude']);
  453. }
  454. // Quick and dirty wrapper for curl scraping.
  455. function curl($url, $referer = null, $post = null)
  456. {
  457. static $tmpfile;
  458. if(!isset($tmpfile) || ($tmpfile == '')) $tmpfile = tempnam('/tmp', 'FOO');
  459. $ch = curl_init($url);
  460. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  461. curl_setopt($ch, CURLOPT_COOKIEFILE, $tmpfile);
  462. curl_setopt($ch, CURLOPT_COOKIEJAR, $tmpfile);
  463. curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
  464. curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Macintosh; U; Intel Mac OS X; en-US; rv:1.8.1) Gecko/20061024 BonEcho/2.0");
  465. // curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  466. // curl_setopt($ch, CURLOPT_VERBOSE, 1);
  467. if($referer) curl_setopt($ch, CURLOPT_REFERER, $referer);
  468. if(!is_null($post))
  469. {
  470. curl_setopt($ch, CURLOPT_POST, true);
  471. curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
  472. }
  473. $html = curl_exec($ch);
  474. // $last_url = curl_getinfo($ch, CURLINFO_EFFECTIVE_URL);
  475. return $html;
  476. }
  477. // Accepts any number of arguments and returns the first non-empty one
  478. function pick()
  479. {
  480. foreach(func_get_args() as $arg)
  481. if(!empty($arg))
  482. return $arg;
  483. return '';
  484. }
  485. // Secure a PHP script using basic HTTP authentication
  486. function http_auth($un, $pw, $realm = "Secured Area")
  487. {
  488. if(!(isset($_SERVER['PHP_AUTH_USER']) && isset($_SERVER['PHP_AUTH_PW']) && $_SERVER['PHP_AUTH_USER'] == $un && $_SERVER['PHP_AUTH_PW'] == $pw))
  489. {
  490. header('WWW-Authenticate: Basic realm="' . $realm . '"');
  491. header('Status: 401 Unauthorized');
  492. exit();
  493. }
  494. }
  495. // This is easier than typing 'echo WEB_ROOT'
  496. function WEBROOT()
  497. {
  498. echo WEB_ROOT;
  499. }
  500. // Class Autloader
  501. function __autoload($class_name)
  502. {
  503. require DOC_ROOT . '/includes/class.' . strtolower($class_name) . '.php';
  504. }
  505. // Returns a file's mimetype based on its extension
  506. function mime_type($filename, $default = 'application/octet-stream')
  507. {
  508. $mime_types = array('323' => 'text/h323',
  509. 'acx' => 'application/internet-property-stream',
  510. 'ai' => 'application/postscript',
  511. 'aif' => 'audio/x-aiff',
  512. 'aifc' => 'audio/x-aiff',
  513. 'aiff' => 'audio/x-aiff',
  514. 'asf' => 'video/x-ms-asf',
  515. 'asr' => 'video/x-ms-asf',
  516. 'asx' => 'video/x-ms-asf',
  517. 'au' => 'audio/basic',
  518. 'avi' => 'video/x-msvideo',
  519. 'axs' => 'application/olescript',
  520. 'bas' => 'text/plain',
  521. 'bcpio' => 'application/x-bcpio',
  522. 'bin' => 'application/octet-stream',
  523. 'bmp' => 'image/bmp',
  524. 'c' => 'text/plain',
  525. 'cat' => 'application/vnd.ms-pkiseccat',
  526. 'cdf' => 'application/x-cdf',
  527. 'cer' => 'application/x-x509-ca-cert',
  528. 'class' => 'application/octet-stream',
  529. 'clp' => 'application/x-msclip',
  530. 'cmx' => 'image/x-cmx',
  531. 'cod' => 'image/cis-cod',
  532. 'cpio' => 'application/x-cpio',
  533. 'crd' => 'application/x-mscardfile',
  534. 'crl' => 'application/pkix-crl',
  535. 'crt' => 'application/x-x509-ca-cert',
  536. 'csh' => 'application/x-csh',
  537. 'css' => 'text/css',
  538. 'dcr' => 'application/x-director',
  539. 'der' => 'application/x-x509-ca-cert',
  540. 'dir' => 'application/x-director',
  541. 'dll' => 'application/x-msdownload',
  542. 'dms' => 'application/octet-stream',
  543. 'doc' => 'application/msword',
  544. 'dot' => 'application/msword',
  545. 'dvi' => 'application/x-dvi',
  546. 'dxr' => 'application/x-director',
  547. 'eps' => 'application/postscript',
  548. 'etx' => 'text/x-setext',
  549. 'evy' => 'application/envoy',
  550. 'exe' => 'application/octet-stream',
  551. 'fif' => 'application/fractals',
  552. 'flac' => 'audio/flac',
  553. 'flr' => 'x-world/x-vrml',
  554. 'gif' => 'image/gif',
  555. 'gtar' => 'application/x-gtar',
  556. 'gz' => 'application/x-gzip',
  557. 'h' => 'text/plain',
  558. 'hdf' => 'application/x-hdf',
  559. 'hlp' => 'application/winhlp',
  560. 'hqx' => 'application/mac-binhex40',
  561. 'hta' => 'application/hta',
  562. 'htc' => 'text/x-component',
  563. 'htm' => 'text/html',
  564. 'html' => 'text/html',
  565. 'htt' => 'text/webviewhtml',
  566. 'ico' => 'image/x-icon',
  567. 'ief' => 'image/ief',
  568. 'iii' => 'application/x-iphone',
  569. 'ins' => 'application/x-internet-signup',
  570. 'isp' => 'application/x-internet-signup',
  571. 'jfif' => 'image/pipeg',
  572. 'jpe' => 'image/jpeg',
  573. 'jpeg' => 'image/jpeg',
  574. 'jpg' => 'image/jpeg',
  575. 'js' => 'application/x-javascript',
  576. 'latex' => 'application/x-latex',
  577. 'lha' => 'application/octet-stream',
  578. 'lsf' => 'video/x-la-asf',
  579. 'lsx' => 'video/x-la-asf',
  580. 'lzh' => 'application/octet-stream',
  581. 'm13' => 'application/x-msmediaview',
  582. 'm14' => 'application/x-msmediaview',
  583. 'm3u' => 'audio/x-mpegurl',
  584. 'man' => 'application/x-troff-man',
  585. 'mdb' => 'application/x-msaccess',
  586. 'me' => 'application/x-troff-me',
  587. 'mht' => 'message/rfc822',
  588. 'mhtml' => 'message/rfc822',
  589. 'mid' => 'audio/mid',
  590. 'mny' => 'application/x-msmoney',
  591. 'mov' => 'video/quicktime',
  592. 'movie' => 'video/x-sgi-movie',
  593. 'mp2' => 'video/mpeg',
  594. 'mp3' => 'audio/mpeg',
  595. 'mpa' => 'video/mpeg',
  596. 'mpe' => 'video/mpeg',
  597. 'mpeg' => 'video/mpeg',
  598. 'mpg' => 'video/mpeg',
  599. 'mpp' => 'application/vnd.ms-project',
  600. 'mpv2' => 'video/mpeg',
  601. 'ms' => 'application/x-troff-ms',
  602. 'mvb' => 'application/x-msmediaview',
  603. 'nws' => 'message/rfc822',
  604. 'oda' => 'application/oda',
  605. 'oga' => 'audio/ogg',
  606. 'ogg' => 'audio/ogg',
  607. 'ogv' => 'video/ogg',
  608. 'ogx' => 'application/ogg',
  609. 'p10' => 'application/pkcs10',
  610. 'p12' => 'application/x-pkcs12',
  611. 'p7b' => 'application/x-pkcs7-certificates',
  612. 'p7c' => 'application/x-pkcs7-mime',
  613. 'p7m' => 'application/x-pkcs7-mime',
  614. 'p7r' => 'application/x-pkcs7-certreqresp',
  615. 'p7s' => 'application/x-pkcs7-signature',
  616. 'pbm' => 'image/x-portable-bitmap',
  617. 'pdf' => 'application/pdf',
  618. 'pfx' => 'application/x-pkcs12',
  619. 'pgm' => 'image/x-portable-graymap',
  620. 'pko' => 'application/ynd.ms-pkipko',
  621. 'pma' => 'application/x-perfmon',
  622. 'pmc' => 'application/x-perfmon',
  623. 'pml' => 'application/x-perfmon',
  624. 'pmr' => 'application/x-perfmon',
  625. 'pmw' => 'application/x-perfmon',
  626. 'pnm' => 'image/x-portable-anymap',
  627. 'pot' => 'application/vnd.ms-powerpoint',
  628. 'ppm' => 'image/x-portable-pixmap',
  629. 'pps' => 'application/vnd.ms-powerpoint',
  630. 'ppt' => 'application/vnd.ms-powerpoint',
  631. 'prf' => 'application/pics-rules',
  632. 'ps' => 'application/postscript',
  633. 'pub' => 'application/x-mspublisher',
  634. 'qt' => 'video/quicktime',
  635. 'ra' => 'audio/x-pn-realaudio',
  636. 'ram' => 'audio/x-pn-realaudio',
  637. 'ras' => 'image/x-cmu-raster',
  638. 'rgb' => 'image/x-rgb',
  639. 'rmi' => 'audio/mid',
  640. 'roff' => 'application/x-troff',
  641. 'rtf' => 'application/rtf',
  642. 'rtx' => 'text/richtext',
  643. 'scd' => 'application/x-msschedule',
  644. 'sct' => 'text/scriptlet',
  645. 'setpay' => 'application/set-payment-initiation',
  646. 'setreg' => 'application/set-registration-initiation',
  647. 'sh' => 'application/x-sh',
  648. 'shar' => 'application/x-shar',
  649. 'sit' => 'application/x-stuffit',
  650. 'snd' => 'audio/basic',
  651. 'spc' => 'application/x-pkcs7-certificates',
  652. 'spl' => 'application/futuresplash',
  653. 'src' => 'application/x-wais-source',
  654. 'sst' => 'application/vnd.ms-pkicertstore',
  655. 'stl' => 'application/vnd.ms-pkistl',
  656. 'stm' => 'text/html',
  657. 'svg' => "image/svg+xml",
  658. 'sv4cpio' => 'application/x-sv4cpio',
  659. 'sv4crc' => 'application/x-sv4crc',
  660. 't' => 'application/x-troff',
  661. 'tar' => 'application/x-tar',
  662. 'tcl' => 'application/x-tcl',
  663. 'tex' => 'application/x-tex',
  664. 'texi' => 'application/x-texinfo',
  665. 'texinfo' => 'application/x-texinfo',
  666. 'tgz' => 'application/x-compressed',
  667. 'tif' => 'image/tiff',
  668. 'tiff' => 'image/tiff',
  669. 'tr' => 'application/x-troff',
  670. 'trm' => 'application/x-msterminal',
  671. 'tsv' => 'text/tab-separated-values',
  672. 'txt' => 'text/plain',
  673. 'uls' => 'text/iuls',
  674. 'ustar' => 'application/x-ustar',
  675. 'vcf' => 'text/x-vcard',
  676. 'vrml' => 'x-world/x-vrml',
  677. 'wav' => 'audio/x-wav',
  678. 'wcm' => 'application/vnd.ms-works',
  679. 'wdb' => 'application/vnd.ms-works',
  680. 'wks' => 'application/vnd.ms-works',
  681. 'wmf' => 'application/x-msmetafile',
  682. 'wps' => 'application/vnd.ms-works',
  683. 'wri' => 'application/x-mswrite',
  684. 'wrl' => 'x-world/x-vrml',
  685. 'wrz' => 'x-world/x-vrml',
  686. 'xaf' => 'x-world/x-vrml',
  687. 'xbm' => 'image/x-xbitmap',
  688. 'xla' => 'application/vnd.ms-excel',
  689. 'xlc' => 'application/vnd.ms-excel',
  690. 'xlm' => 'application/vnd.ms-excel',
  691. 'xls' => 'application/vnd.ms-excel',
  692. 'xlt' => 'application/vnd.ms-excel',
  693. 'xlw' => 'application/vnd.ms-excel',
  694. 'xof' => 'x-world/x-vrml',
  695. 'xpm' => 'image/x-xpixmap',
  696. 'xwd' => 'image/x-xwindowdump',
  697. 'z' => 'application/x-compress',
  698. 'zip' => 'application/zip');
  699. $ext = pathinfo($filename, PATHINFO_EXTENSION);
  700. return isset($mime_types[$ext]) ? $mime_types[$ext] : $default;
  701. }