PageRenderTime 61ms CodeModel.GetById 20ms RepoModel.GetById 1ms app.codeStats 0ms

/includes/functions.inc.php

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