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

/wp-content/plugins/rackspace-cloud-files-cdn/lib/functions.php

https://bitbucket.org/theshipswakecreative/psw
PHP | 803 lines | 505 code | 115 blank | 183 comment | 97 complexity | d89aa5a86fc82374cb2d2558a02ed02e MD5 | raw file
Possible License(s): LGPL-3.0, Apache-2.0
  1. <?php
  2. /**
  3. * Set global variables
  4. */
  5. global $wpdb;
  6. /**
  7. * Register session
  8. */
  9. function register_session() {
  10. if( !session_id() )
  11. session_start();
  12. }
  13. add_action('init','register_session');
  14. /**
  15. * Ensure CDN instance exists
  16. */
  17. function check_cdn() {
  18. // Verify class has been loaded
  19. if (!class_exists('RS_CDN')) {
  20. require_once(RS_CDN_PATH."lib/class.rs_cdn.php");
  21. }
  22. // Check if CDN exists
  23. try {
  24. $_SESSION['cdn'] = (isset($_SESSION['cdn']) && is_object($_SESSION['cdn'])) ? $_SESSION['cdn'] : new RS_CDN();
  25. } catch (Exception $exc) {
  26. return false;
  27. }
  28. // Check if connection OR container objects are null, if so, return false
  29. if (is_null($_SESSION['cdn']->connection_object()) || is_null($_SESSION['cdn']->container_object())) {
  30. return false;
  31. }
  32. // Session created successfully
  33. return true;
  34. }
  35. /**
  36. * Upload main image and thumbnails to CDN.
  37. * Remove the local copy if user specified in settings.
  38. */
  39. function upload_images($meta_id, $post_id, $meta_key='', $meta_value='') {
  40. // Check attachment metadata
  41. if ($meta_key == '_wp_attachment_metadata') {
  42. // Ensure CDN instance exists
  43. if (check_cdn() === false) {
  44. return false;
  45. die();
  46. }
  47. // Get upload dir
  48. $upload_dir = wp_upload_dir();
  49. // Get files to upload
  50. $files_to_upload = get_files_to_sync();
  51. // Add original file to array
  52. $files_to_upload['upload'][] = array('fn' => $meta_value['file']);
  53. // Upload files
  54. foreach ($files_to_upload['upload'] as $cur_file) {
  55. // Set file name
  56. $cur_file_data = $cur_file;
  57. $cur_file = $upload_dir['basedir'].'/'.$cur_file_data['fn'];
  58. $file_name = $cur_file_data['fn'];
  59. // Upload file to CDN, add to file check
  60. try {
  61. $_SESSION['cdn']->upload_file($cur_file, $file_name);
  62. } catch (Exception $exc) {
  63. return false;
  64. die();
  65. }
  66. // Delete file when successfully uploaded, if set
  67. if (isset($_SESSION['cdn']->api_settings->remove_local_files) && $_SESSION['cdn']->api_settings->remove_local_files == true) {
  68. @unlink($cur_file);
  69. }
  70. }
  71. // Update CDN image cache
  72. $_SESSION['cdn']->get_cdn_objects(true);
  73. return true;
  74. }
  75. // Check attached file meta
  76. if ($meta_key == '_wp_attached_file') {
  77. // Ensure CDN instance exists
  78. if (check_cdn() === false) {
  79. return false;
  80. die();
  81. }
  82. // Get upload dir
  83. $upload_dir = wp_upload_dir();
  84. $cur_file = $upload_dir['basedir'].'/'.$meta_value;
  85. $file_name = $meta_value;
  86. $content_type = get_content_type($cur_file);
  87. // Upload file to CDN, add to file check
  88. try {
  89. $_SESSION['cdn']->upload_file($cur_file, $file_name);
  90. } catch (Exception $exc) {
  91. return false;
  92. die();
  93. }
  94. // Delete file when successfully uploaded, if set
  95. if (isset($_SESSION['cdn']->api_settings->remove_local_files) && $_SESSION['cdn']->api_settings->remove_local_files == true) {
  96. if (stripos($content_type, 'image') === false) {
  97. @unlink($cur_file);
  98. }
  99. }
  100. // Update CDN image cache
  101. $_SESSION['cdn']->get_cdn_objects(true);
  102. return true;
  103. }
  104. }
  105. add_action('added_post_meta', 'upload_images', 10, 4);
  106. add_action('updated_post_meta', 'upload_images', 10, 4);
  107. /**
  108. * Delete file from CDN
  109. */
  110. function remove_cdn_files( $post_id ){
  111. global $wpdb;
  112. // Ensure CDN instance exists
  113. if (check_cdn() === false) {
  114. return false;
  115. }
  116. // Get attachment metadata so we can delete all attachments associated with this image
  117. $attachment_metadata = $wpdb->get_results("SELECT meta_key,meta_value FROM ".$wpdb->prefix."postmeta WHERE post_id = '$post_id' AND (meta_key='_wp_attachment_metadata' OR meta_key='_wp_attached_file')");
  118. if ($wpdb->num_rows > 0) {
  119. // Check if meta value or attached file
  120. foreach ($attachment_metadata as $cur_attachment_metadata) {
  121. // Unserialize image data
  122. $all_image_sizes = unserialize($cur_attachment_metadata->meta_value);
  123. // Check if unserialize was successful, if so, this is an array/object
  124. if ($all_image_sizes !== false) {
  125. // Add main file to delete request
  126. if (trim($all_image_sizes['file']) != '') {
  127. $files_to_delete[] = $all_image_sizes['file'];
  128. }
  129. // Get attachment folder name
  130. $attach_folder = pathinfo($all_image_sizes['file']);
  131. $attach_folder = ($attach_folder['dirname'] != '') ? trim($attach_folder['dirname'], '/').'/' : '';
  132. // Add each thumb to array
  133. if (isset($all_image_sizes['sizes']) && count($all_image_sizes['sizes']) > 0) {
  134. foreach ($all_image_sizes['sizes'] as $cur_img_size) {
  135. // Add attachment to delete queue
  136. if (trim($cur_img_size['file']) != '') {
  137. // Set current file name
  138. $cur_file = trim($attach_folder.basename($cur_img_size['file']));
  139. // Don't add if already in array
  140. if (!in_array($cur_file, $files_to_delete)) {
  141. $files_to_delete[] = $cur_file;
  142. }
  143. }
  144. }
  145. }
  146. } else {
  147. // Add file to delete
  148. $files_to_delete[] = $cur_attachment_metadata->meta_value;
  149. }
  150. }
  151. }
  152. // Send batch delete
  153. $_SESSION['cdn']->delete_files( $files_to_delete );
  154. }
  155. add_action( 'delete_attachment', 'remove_cdn_files');
  156. /**
  157. * Verify file does not exist so we don't overwrite it.
  158. * If the file exists, increment the file name.
  159. */
  160. function verify_filename($filename, $filename_raw = null) {
  161. global $wpdb;
  162. // Ensure CDN instance exists
  163. if (check_cdn() === false) {
  164. return $filename;
  165. }
  166. // Get CDN information
  167. if (isset($_SESSION['cdn']->api_settings->custom_cname) && trim($_SESSION['cdn']->api_settings->custom_cname) != '') {
  168. $cdn_url = $_SESSION['cdn']->api_settings->custom_cname;
  169. } else {
  170. $cdn_url = (isset($_SESSION['cdn']->api_settings->use_ssl)) ? get_cdn_url('ssl') : get_cdn_url();
  171. }
  172. // Get file info
  173. $info = pathinfo($filename);
  174. $ext = empty($info['extension']) ? '' : '.' . $info['extension'];
  175. // Get attachment metadata so we can delete all attachments associated with this image
  176. $existing_files = $wpdb->get_results("SELECT guid FROM ".$wpdb->prefix."posts WHERE guid LIKE '%".preg_replace('/[0-9]*$/', '', $info['filename'])."%".$info['extension']."'");
  177. // Check if file exists
  178. if (count($existing_files) > 0) {
  179. // File list
  180. foreach ($existing_files as $cur_file) {
  181. $my_files[] = basename($cur_file->guid);
  182. }
  183. // Loop through files
  184. $i=1;
  185. foreach ($my_files as $cur_file) {
  186. $file_parts = pathinfo($cur_file);
  187. if ($file_parts['basename'] == basename($filename)) {
  188. $filename = $file_parts['filename'].'.'.$file_parts['extension'];
  189. while (in_array($filename, $my_files)) {
  190. $filename = $file_parts['filename'].$i++.'.'.$file_parts['extension'];
  191. }
  192. }
  193. }
  194. }
  195. return basename($filename);
  196. }
  197. add_filter('sanitize_file_name', 'verify_filename', 10, 2);
  198. /**
  199. * Get a list of the files that need uploaded
  200. */
  201. function get_files($params) {
  202. // Ensure CDN instance exists
  203. if (check_cdn() === false) {
  204. return array('response' => 'fail', 'message' => 'Error instantiating CDN session.');
  205. }
  206. $arr_files_to_sync = get_files_to_sync();
  207. $arr_files_to_sync = array_merge($arr_files_to_sync['upload'], $arr_files_to_sync['download']);
  208. echo json_encode($arr_files_to_sync);
  209. die();
  210. }
  211. add_action('wp_ajax_get_files', 'get_files');
  212. /**
  213. * Get list of files to sync
  214. */
  215. function get_files_to_sync() {
  216. // Array to store files needing upload/download
  217. $objects_to_upload = array();
  218. $objects_to_download = array();
  219. // Ensure CDN instance exists
  220. if (check_cdn() === false) {
  221. return array('response' => 'fail', 'message' => 'Error instantiating CDN session.', 'upload' => $objects_to_upload, 'download' => $objects_to_download);
  222. }
  223. // Get CDN objects
  224. $local_objects = get_local_files();
  225. $remote_objects = $_SESSION['cdn']->get_cdn_objects(true);
  226. // If CDN objects is null, we need to return an error because we couldn't fetch them
  227. if (is_null($remote_objects)) {
  228. return array('response' => 'error', 'message' => 'Unable to retrieve files.');
  229. }
  230. // Check local files needing uploaded
  231. foreach ($local_objects as $cur_local_object) {
  232. if (!in_array($cur_local_object, $remote_objects) && $cur_local_object['fs'] > 0) {
  233. $objects_to_upload[] = $cur_local_object;
  234. }
  235. }
  236. // Check remote files needing DOWNloaded
  237. foreach ($remote_objects as $cur_remote_object) {
  238. if (!in_array($cur_remote_object, $local_objects) && $cur_remote_object['fs'] > 0) {
  239. $cdn_url = (isset($_SESSION['cdn']->api_settings->use_ssl)) ? get_cdn_url('ssl') : get_cdn_url();
  240. $cur_remote_object['fn'] = $cdn_url.'/'.$cur_remote_object['fn'];
  241. $objects_to_download[] = $cur_remote_object;
  242. }
  243. }
  244. // Return array of files that need synchronized
  245. return array('upload' => $objects_to_upload, 'download' => $objects_to_download);
  246. }
  247. /**
  248. * Get a list of the files that need uploaded
  249. */
  250. function get_files_to_remove($params) {
  251. echo json_encode(get_local_files());
  252. die();
  253. }
  254. add_action('wp_ajax_get_files_to_remove', 'get_files_to_remove');
  255. /**
  256. * Sync existing local file to CDN
  257. */
  258. function sync_existing_file() {
  259. // Ensure CDN instance exists
  260. if (check_cdn() === false) {
  261. echo json_encode(array('response' => 'fail', 'message' => 'Error instantiating CDN session.'));
  262. die();
  263. }
  264. // Get CDN object(s)
  265. // $cdn_objects = $_SESSION['cdn']->get_cdn_objects();
  266. // Upload file - Get file to upload
  267. $upload_dir = wp_upload_dir();
  268. $file_to_sync = $_REQUEST['file_path'];
  269. // Check if file needs uploaded or downloaded
  270. if (stripos($file_to_sync, 'http') === false) {
  271. // Upload file, prepend local file path
  272. $file_to_sync = $upload_dir['basedir'].'/'.$file_to_sync;
  273. // Check if file exists, fail if not
  274. if (!file_exists($file_to_sync)) {
  275. echo json_encode(array('response' => 'error', 'message' => 'Upload for "'.basename($file_to_sync).'" failed (SEF-001).'));
  276. die();
  277. }
  278. // Get upload dir
  279. $upload_dir = wp_upload_dir();
  280. // Try to upload file
  281. try {
  282. // Try to upload file
  283. $_SESSION['cdn']->upload_file($file_to_sync, str_replace($upload_dir['basedir'].'/', '', $file_to_sync));
  284. } catch (Exception $exc) {
  285. // Let the browser know upload failed
  286. echo json_encode(array('response' => 'error', 'message' => 'Upload for "'.basename($file_to_sync).'" failed. Exception: '.$exc.' (SEF-002).'));
  287. die();
  288. }
  289. // Verify file was successfully uploaded
  290. if (isset($_SESSION['cdn']->api_settings->remove_local_files) && $_SESSION['cdn']->api_settings->remove_local_files == true) {
  291. if (verify_exists($file_to_sync) == true) {
  292. @unlink($file_to_sync);
  293. }
  294. }
  295. // Force CDN object cache
  296. $_SESSION['cdn']->force_object_cache();
  297. } else {
  298. // Download file - Get CDN URL
  299. $cdn_url = (isset($_SESSION['cdn']->api_settings->use_ssl)) ? get_cdn_url('ssl') : get_cdn_url();
  300. // Write file to disk
  301. $file_info = pathinfo($file_to_sync);
  302. $remote_file_name = rawurlencode($file_info['filename']);
  303. file_put_contents(str_replace($cdn_url, $upload_dir['basedir'], $file_to_sync), file_get_contents(str_replace($file_info['filename'], $remote_file_name, $file_to_sync)));
  304. }
  305. // If this is the last file, force update CDN cache
  306. if ($_REQUEST['current_file_num'] == $_REQUEST['rs_cdn_num_files_to_sync']) {
  307. $_SESSION['cdn']->force_object_cache();
  308. }
  309. // Let the browser know upload was successful
  310. echo json_encode(array('response' => 'success', 'file_path' => $file_to_sync));
  311. die();
  312. }
  313. add_action('wp_ajax_sync_existing_file', 'sync_existing_file');
  314. add_action('wp_ajax_upload_existing_file', 'sync_existing_file');
  315. /**
  316. * Remove existing local file, verify it's on the CDN first
  317. */
  318. function remove_existing_file() {
  319. // Ensure CDN instance exists
  320. if (check_cdn() === false) {
  321. echo json_encode(array('response' => 'error', 'message' => 'Error instantiating CDN session.'));
  322. die();
  323. }
  324. // Upload file - Get file to upload
  325. $upload_dir = wp_upload_dir();
  326. $file_to_sync = $_REQUEST['file_path'];
  327. // Get CDN URL
  328. $cdn_url = (isset($_SESSION['cdn']->api_settings->use_ssl)) ? get_cdn_url('ssl') : get_cdn_url();
  329. // Get remote file URL
  330. $file_info = pathinfo($file_to_sync);
  331. $remote_file_name = str_replace($file_info['filename'], rawurlencode($file_info['filename']), $file_to_sync);
  332. // If file is not on the CDN, upload it
  333. if (verify_exists($cdn_url.'/'.$remote_file_name)) {
  334. // Headers are good, delete local file
  335. try {
  336. // Remove file
  337. unlink($upload_dir['basedir'].'/'.$file_to_sync);
  338. } catch (Exception $exc) {
  339. // Let the browser know file removal failed
  340. echo json_encode(array('response' => 'error', 'message' => $exc));
  341. die();
  342. }
  343. } else {
  344. // Try to upload file
  345. try {
  346. // Try to upload file
  347. $_SESSION['cdn']->upload_file($upload_dir['basedir'].'/'.$file_to_sync, $file_to_sync);
  348. // Successful upload, delete the file
  349. unlink($upload_dir['basedir'].'/'.$file_to_sync);
  350. } catch (Exception $exc) {
  351. // Let the browser know upload failed
  352. echo json_encode(array('response' => 'error', 'message' => 'Upload for "'.basename($file_to_sync).'" failed (REF-002).'));
  353. die();
  354. }
  355. }
  356. // If this is the last file, force update CDN cache
  357. if ($_REQUEST['current_file_num'] == $_REQUEST['rs_cdn_num_files_to_sync']) {
  358. $_SESSION['cdn']->force_object_cache();
  359. }
  360. // Let the browser know upload was successful
  361. echo json_encode(array('response' => 'success', 'file_path' => $upload_dir['basedir'].'/'.$file_to_sync));
  362. die();
  363. }
  364. add_action('wp_ajax_remove_existing_file', 'remove_existing_file');
  365. /**
  366. * Set CDN path for image
  367. */
  368. function set_cdn_path($attachment) {
  369. // Ensure CDN instance exists
  370. if (check_cdn() === false) {
  371. return $attachment;
  372. }
  373. // Uploads folder data
  374. $upload_data = wp_upload_dir();
  375. // If HTTPS is on, replace http with https URL
  376. if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on') {
  377. $local_uploads_url = str_replace('http://', 'https://', $upload_data['baseurl']).'/';
  378. } else {
  379. $local_uploads_url = $upload_data['baseurl'];
  380. }
  381. // Get public CDN URL
  382. try {
  383. if (isset($_SESSION['cdn']->api_settings->custom_cname) && trim($_SESSION['cdn']->api_settings->custom_cname) != '') {
  384. $cdn_url = $_SESSION['cdn']->api_settings->custom_cname;
  385. } else {
  386. $cdn_url = (isset($_SESSION['cdn']->api_settings->use_ssl)) ? get_cdn_url('ssl') : get_cdn_url();
  387. }
  388. } catch (Exception $e) {
  389. return $attachment;
  390. }
  391. // Get base URL defined for uploads
  392. $base_uploads_url = str_replace(array('http://','https://'), '(http|https)://', $upload_data['baseurl']);
  393. $base_uploads_url = str_replace('/', '\/', $base_uploads_url);
  394. // Loop through attachments and rewrite with CDN URL if they are on the CDN
  395. preg_match_all('/'.$base_uploads_url.'\/.*?\.[a-z]{3}+/i', $attachment, $attachments);
  396. // Get attachments and check if on CDN
  397. if (count($attachments) > 0) {
  398. foreach ($attachments as $cur_attachments) {
  399. // Check if array
  400. foreach ($cur_attachments as $cur_attachment) {
  401. if ($cur_attachment != 'http' && $cur_attachment != 'https') {
  402. // Verify attachment exists
  403. $new_attachment = trim(str_replace($local_uploads_url, '', $cur_attachment), '/');
  404. // If we are good to go, return the attachment
  405. if (verify_exists( $new_attachment )) {
  406. $attachment = str_replace($cur_attachment, $cdn_url.'/'.$new_attachment, $attachment);
  407. }
  408. }
  409. }
  410. }
  411. }
  412. // Return attachment
  413. return $attachment;
  414. }
  415. add_filter('the_content', 'set_cdn_path');
  416. add_filter('richedit_pre', 'set_cdn_path');
  417. add_filter('wp_get_attachment_url', 'set_cdn_path');
  418. /**
  419. * Get local files
  420. */
  421. function get_local_files() {
  422. // Get uploads directory
  423. $upload_dir = wp_upload_dir();
  424. $dir = $upload_dir['basedir'];
  425. $local_files = array();
  426. // If uploads directory is not found, tell the user to create it
  427. if (!is_dir($dir)) {
  428. return array('response' => 'error', 'message' => 'Directory "'.$dir.'" not found. Please create it.');
  429. }
  430. // Setup directory iterator
  431. $files = new RecursiveIteratorIterator(
  432. new RecursiveDirectoryIterator($dir, RecursiveDirectoryIterator::SKIP_DOTS), RecursiveIteratorIterator::CHILD_FIRST
  433. );
  434. // Loop through files and find out if they need uploaded
  435. $i = 0;
  436. foreach ($files as $fileinfo) {
  437. $the_file = $fileinfo->getRealPath();
  438. $file_path = pathinfo($the_file);
  439. if (!is_dir($the_file)) {
  440. if (isset($_SESSION['cdn']->api_settings->files_to_ignore)) {
  441. // File extensions ignored
  442. $ignore_files = explode(",", $_SESSION['cdn']->api_settings->files_to_ignore);
  443. if (!in_array($file_path['extension'], $ignore_files)) {
  444. $cur_local_file = $fileinfo->getRealPath();
  445. $local_files[$i++] = array('fn' => trim(str_replace($upload_dir['basedir'], '', $cur_local_file), '/'), 'fs' => filesize($cur_local_file));
  446. }
  447. } else {
  448. // No file extensions ignored
  449. $cur_local_file = $fileinfo->getRealPath();
  450. $local_files[$i++] = array('fn' => trim(str_replace($upload_dir['basedir'], '', $cur_local_file), '/'), 'fs' => filesize($cur_local_file));
  451. }
  452. }
  453. }
  454. return $local_files;
  455. }
  456. /**
  457. * Verify file exists
  458. */
  459. function verify_exists( $file_path = null ) {
  460. // Ensure CDN instance exists
  461. if (check_cdn() === false || is_null($file_path)) {
  462. return false;
  463. }
  464. // Get CDN URL
  465. if (isset($_SESSION['cdn']->api_settings->custom_cname) && trim($_SESSION['cdn']->api_settings->custom_cname) != '') {
  466. $cdn_url = $_SESSION['cdn']->api_settings->custom_cname;
  467. } else {
  468. $cdn_url = (isset($_SESSION['cdn']->api_settings->use_ssl)) ? get_cdn_url('ssl') : get_cdn_url();
  469. }
  470. // Define variables needed
  471. $upload_dir = wp_upload_dir();
  472. // Get local file path
  473. $file_url = str_replace(array($cdn_url.'/', $upload_dir['basedir'].'/', $upload_dir['baseurl'].'/'), '', $file_path);
  474. // Return true/false if file exists on CDN or not
  475. return find_file_name( $file_url );
  476. }
  477. /**
  478. * Multidimensional array search
  479. */
  480. function find_file_name( $file_name ) {
  481. // Ensure CDN instance exists
  482. if (check_cdn() === false) {
  483. return false;
  484. }
  485. // Get CDN objects
  486. $cdn_objects = $_SESSION['cdn']->get_cdn_objects();
  487. // Loop through and see if we can find the file name
  488. foreach ($cdn_objects as $cur_cdn_object) {
  489. if ($cur_cdn_object['fn'] === $file_name) {
  490. return true;
  491. }
  492. }
  493. // Return false by default
  494. return false;
  495. }
  496. /**
  497. * Get CDN URL
  498. */
  499. function get_cdn_url($type = 'http') {
  500. // Ensure CDN instance exists
  501. if (check_cdn() === false) {
  502. $wp_url = wp_upload_dir();
  503. return $wp_url['baseurl'];
  504. }
  505. // Get correct CDN URL
  506. $type = strtolower($type);
  507. if ($type == 'ssl' || $type == 'https') {
  508. // Return HTTPS URI
  509. return $_SESSION['cdn']->container_object()->SSLURI();
  510. } else {
  511. // Return HTTP URI
  512. return $_SESSION['cdn']->container_object()->CDNURI();
  513. }
  514. }
  515. /**
  516. * Get content/mime type of file
  517. */
  518. function get_content_type($file) {
  519. // Get file info
  520. $ext = pathinfo($file);
  521. $ext = $ext['extension'];
  522. // Get available content types
  523. $cdn_content_types = get_available_content_types();
  524. // Return mime type for extension
  525. if (isset($cdn_content_types[$ext])) {
  526. return $cdn_content_types[$ext];
  527. } else {
  528. return false;
  529. }
  530. }
  531. /**
  532. * Get available content types
  533. */
  534. function get_available_content_types() {
  535. return array(
  536. "ez" => "application/andrew-inset",
  537. "hqx" => "application/mac-binhex40",
  538. "cpt" => "application/mac-compactpro",
  539. "doc" => "application/msword",
  540. "bin" => "application/octet-stream",
  541. "dms" => "application/octet-stream",
  542. "lha" => "application/octet-stream",
  543. "lzh" => "application/octet-stream",
  544. "exe" => "application/octet-stream",
  545. "class" => "application/octet-stream",
  546. "so" => "application/octet-stream",
  547. "dll" => "application/octet-stream",
  548. "oda" => "application/oda",
  549. "pdf" => "application/pdf",
  550. "ai" => "application/postscript",
  551. "eps" => "application/postscript",
  552. "ps" => "application/postscript",
  553. "smi" => "application/smil",
  554. "smil" => "application/smil",
  555. "wbxml" => "application/vnd.wap.wbxml",
  556. "wmlc" => "application/vnd.wap.wmlc",
  557. "wmlsc" => "application/vnd.wap.wmlscriptc",
  558. "bcpio" => "application/x-bcpio",
  559. "vcd" => "application/x-cdlink",
  560. "pgn" => "application/x-chess-pgn",
  561. "cpio" => "application/x-cpio",
  562. "csh" => "application/x-csh",
  563. "dcr" => "application/x-director",
  564. "dir" => "application/x-director",
  565. "dxr" => "application/x-director",
  566. "dvi" => "application/x-dvi",
  567. "spl" => "application/x-futuresplash",
  568. "gtar" => "application/x-gtar",
  569. "hdf" => "application/x-hdf",
  570. "js" => "application/x-javascript",
  571. "skp" => "application/x-koan",
  572. "skd" => "application/x-koan",
  573. "skt" => "application/x-koan",
  574. "skm" => "application/x-koan",
  575. "latex" => "application/x-latex",
  576. "nc" => "application/x-netcdf",
  577. "cdf" => "application/x-netcdf",
  578. "sh" => "application/x-sh",
  579. "shar" => "application/x-shar",
  580. "swf" => "application/x-shockwave-flash",
  581. "sit" => "application/x-stuffit",
  582. "sv4cpio" => "application/x-sv4cpio",
  583. "sv4crc" => "application/x-sv4crc",
  584. "tar" => "application/x-tar",
  585. "tcl" => "application/x-tcl",
  586. "tex" => "application/x-tex",
  587. "texinfo" => "application/x-texinfo",
  588. "texi" => "application/x-texinfo",
  589. "t" => "application/x-troff",
  590. "tr" => "application/x-troff",
  591. "roff" => "application/x-troff",
  592. "man" => "application/x-troff-man",
  593. "me" => "application/x-troff-me",
  594. "ms" => "application/x-troff-ms",
  595. "ustar" => "application/x-ustar",
  596. "src" => "application/x-wais-source",
  597. "xhtml" => "application/xhtml+xml",
  598. "xht" => "application/xhtml+xml",
  599. "zip" => "application/zip",
  600. "au" => "audio/basic",
  601. "snd" => "audio/basic",
  602. "mid" => "audio/midi",
  603. "midi" => "audio/midi",
  604. "kar" => "audio/midi",
  605. "mpga" => "audio/mpeg",
  606. "mp2" => "audio/mpeg",
  607. "mp3" => "audio/mpeg",
  608. "aif" => "audio/x-aiff",
  609. "aiff" => "audio/x-aiff",
  610. "aifc" => "audio/x-aiff",
  611. "m3u" => "audio/x-mpegurl",
  612. "ram" => "audio/x-pn-realaudio",
  613. "rm" => "audio/x-pn-realaudio",
  614. "rpm" => "audio/x-pn-realaudio-plugin",
  615. "ra" => "audio/x-realaudio",
  616. "wav" => "audio/x-wav",
  617. "pdb" => "chemical/x-pdb",
  618. "xyz" => "chemical/x-xyz",
  619. "bmp" => "image/bmp",
  620. "gif" => "image/gif",
  621. "ief" => "image/ief",
  622. "jpeg" => "image/jpeg",
  623. "jpg" => "image/jpeg",
  624. "jpe" => "image/jpeg",
  625. "png" => "image/png",
  626. "tiff" => "image/tiff",
  627. "tif" => "image/tif",
  628. "djvu" => "image/vnd.djvu",
  629. "djv" => "image/vnd.djvu",
  630. "wbmp" => "image/vnd.wap.wbmp",
  631. "ras" => "image/x-cmu-raster",
  632. "pnm" => "image/x-portable-anymap",
  633. "pbm" => "image/x-portable-bitmap",
  634. "pgm" => "image/x-portable-graymap",
  635. "ppm" => "image/x-portable-pixmap",
  636. "rgb" => "image/x-rgb",
  637. "xbm" => "image/x-xbitmap",
  638. "xpm" => "image/x-xpixmap",
  639. "xwd" => "image/x-windowdump",
  640. "igs" => "model/iges",
  641. "iges" => "model/iges",
  642. "msh" => "model/mesh",
  643. "mesh" => "model/mesh",
  644. "silo" => "model/mesh",
  645. "wrl" => "model/vrml",
  646. "vrml" => "model/vrml",
  647. "css" => "text/css",
  648. "html" => "text/html",
  649. "htm" => "text/html",
  650. "asc" => "text/plain",
  651. "txt" => "text/plain",
  652. "rtx" => "text/richtext",
  653. "rtf" => "text/rtf",
  654. "sgml" => "text/sgml",
  655. "sgm" => "text/sgml",
  656. "tsv" => "text/tab-seperated-values",
  657. "wml" => "text/vnd.wap.wml",
  658. "wmls" => "text/vnd.wap.wmlscript",
  659. "etx" => "text/x-setext",
  660. "xml" => "text/xml",
  661. "xsl" => "text/xml",
  662. "mpeg" => "video/mpeg",
  663. "mpg" => "video/mpeg",
  664. "mpe" => "video/mpeg",
  665. "qt" => "video/quicktime",
  666. "mov" => "video/quicktime",
  667. "mxu" => "video/vnd.mpegurl",
  668. "avi" => "video/x-msvideo",
  669. "movie" => "video/x-sgi-movie",
  670. "ice" => "x-conference-xcooltalk"
  671. );
  672. }
  673. /**
  674. * Add download link for all file(s)
  675. */
  676. /*
  677. function show_download_link($actions, $post) {
  678. // Relative path/name of the file
  679. $the_file = str_replace(WP_CONTENT_URL, '.', $post->guid);
  680. // adding the Action to the Quick Edit row
  681. $actions['Download'] = '<a href="'.WP_CONTENT_URL.'/download.php?file='.$the_file.'">Download</a>';
  682. return $actions;
  683. }
  684. add_filter('media_row_actions', 'show_download_link', 10, 2);
  685. */
  686. ?>