PageRenderTime 58ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/includes/functions.inc.php

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