web/wp-app.php
branchwordpress
changeset 132 4d4862461b8d
parent 109 03b0d1493584
equal deleted inserted replaced
131:a4642baaf829 132:4d4862461b8d
    15 define('APP_REQUEST', true);
    15 define('APP_REQUEST', true);
    16 
    16 
    17 /** Set up WordPress environment */
    17 /** Set up WordPress environment */
    18 require_once('./wp-load.php');
    18 require_once('./wp-load.php');
    19 
    19 
    20 /** Post Template API */
       
    21 require_once(ABSPATH . WPINC . '/post-template.php');
       
    22 
       
    23 /** Atom Publishing Protocol Class */
    20 /** Atom Publishing Protocol Class */
    24 require_once(ABSPATH . WPINC . '/atomlib.php');
    21 require_once(ABSPATH . WPINC . '/atomlib.php');
    25 
       
    26 /** Feed Handling API */
       
    27 require_once(ABSPATH . WPINC . '/feed.php');
       
    28 
    22 
    29 /** Admin Image API for metadata updating */
    23 /** Admin Image API for metadata updating */
    30 require_once(ABSPATH . '/wp-admin/includes/image.php');
    24 require_once(ABSPATH . '/wp-admin/includes/image.php');
    31 
    25 
    32 $_SERVER['PATH_INFO'] = preg_replace( '/.*\/wp-app\.php/', '', $_SERVER['REQUEST_URI'] );
    26 $_SERVER['PATH_INFO'] = preg_replace( '/.*\/wp-app\.php/', '', $_SERVER['REQUEST_URI'] );
    66 		$date = gmdate( 'Y-m-d H:i:s' );
    60 		$date = gmdate( 'Y-m-d H:i:s' );
    67 		fwrite($fp, "\n\n$date - $label\n$msg\n");
    61 		fwrite($fp, "\n\n$date - $label\n$msg\n");
    68 		fclose($fp);
    62 		fclose($fp);
    69 	}
    63 	}
    70 }
    64 }
    71 
       
    72 if ( !function_exists('wp_set_current_user') ) :
       
    73 /**
       
    74  * @ignore
       
    75  */
       
    76 function wp_set_current_user($id, $name = '') {
       
    77 	global $current_user;
       
    78 
       
    79 	if ( isset($current_user) && ($id == $current_user->ID) )
       
    80 		return $current_user;
       
    81 
       
    82 	$current_user = new WP_User($id, $name);
       
    83 
       
    84 	return $current_user;
       
    85 }
       
    86 endif;
       
    87 
    65 
    88 /**
    66 /**
    89  * Filter to add more post statuses.
    67  * Filter to add more post statuses.
    90  *
    68  *
    91  * @since 2.2.0
    69  * @since 2.2.0
   353 			$this->auth_required( __( 'Sorry, you do not have the right to access this blog.' ) );
   331 			$this->auth_required( __( 'Sorry, you do not have the right to access this blog.' ) );
   354 
   332 
   355 		$entries_url = esc_attr($this->get_entries_url());
   333 		$entries_url = esc_attr($this->get_entries_url());
   356 		$categories_url = esc_attr($this->get_categories_url());
   334 		$categories_url = esc_attr($this->get_categories_url());
   357 		$media_url = esc_attr($this->get_attachments_url());
   335 		$media_url = esc_attr($this->get_attachments_url());
       
   336 		$accepted_media_types = '';
   358 		foreach ($this->media_content_types as $med) {
   337 		foreach ($this->media_content_types as $med) {
   359 			$accepted_media_types = $accepted_media_types . "<accept>" . $med . "</accept>";
   338 			$accepted_media_types = $accepted_media_types . "<accept>" . $med . "</accept>";
   360 		}
   339 		}
   361 		$atom_prefix="atom";
   340 		$atom_prefix="atom";
   362 		$atom_blogname=get_bloginfo('name');
   341 		$atom_blogname=get_bloginfo('name');
   778 		if(!current_user_can('edit_post', $postID)) {
   757 		if(!current_user_can('edit_post', $postID)) {
   779 			$this->auth_required(__('Sorry, you do not have the right to edit this post.'));
   758 			$this->auth_required(__('Sorry, you do not have the right to edit this post.'));
   780 		}
   759 		}
   781 
   760 
   782 		$location = get_post_meta($entry['ID'], '_wp_attached_file', true);
   761 		$location = get_post_meta($entry['ID'], '_wp_attached_file', true);
   783 		$location = get_option ('upload_path') . '/' . $location; 
   762 		$location = get_option ('upload_path') . '/' . $location;
   784 		$filetype = wp_check_filetype($location);
   763 		$filetype = wp_check_filetype($location);
   785 
   764 
   786 		if(!isset($location) || 'attachment' != $entry['post_type'] || empty($filetype['ext']))
   765 		if(!isset($location) || 'attachment' != $entry['post_type'] || empty($filetype['ext']))
   787 			$this->internal_error(__('Error ocurred while accessing post metadata for file location.'));
   766 			$this->internal_error(__('Error ocurred while accessing post metadata for file location.'));
   788 
   767 
   789 		status_header('200');
   768 		status_header('200');
   790 		header('Content-Type: ' . $entry['post_mime_type']);
   769 		header('Content-Type: ' . $entry['post_mime_type']);
   791 		header('Connection: close');
   770 		header('Connection: close');
   792 
   771 
   793 		if ($fp = fopen($location, "rb")) { 
   772 		if ($fp = fopen($location, "rb")) {
   794 			status_header('200'); 
   773 			status_header('200');
   795 			header('Content-Type: ' . $entry['post_mime_type']); 
   774 			header('Content-Type: ' . $entry['post_mime_type']);
   796 			header('Connection: close');
   775 			header('Connection: close');
   797 
   776 
   798 			while(!feof($fp)) {
   777 			while(!feof($fp)) {
   799 				echo fread($fp, 4096);
   778 				echo fread($fp, 4096);
   800 			}
   779 			}
   875 	 *
   854 	 *
   876 	 * @param int $page Page ID.
   855 	 * @param int $page Page ID.
   877 	 * @return string
   856 	 * @return string
   878 	 */
   857 	 */
   879 	function get_entries_url($page = null) {
   858 	function get_entries_url($page = null) {
   880 		if($GLOBALS['post_type'] == 'attachment') {
   859 		if ( isset($GLOBALS['post_type']) && ( $GLOBALS['post_type'] == 'attachment' ) ) {
   881 			$path = $this->MEDIA_PATH;
   860 			$path = $this->MEDIA_PATH;
   882 		} else {
   861 		} else {
   883 			$path = $this->ENTRIES_PATH;
   862 			$path = $this->ENTRIES_PATH;
   884 		}
   863 		}
   885 		$url = $this->app_base . $path;
   864 		$url = $this->app_base . $path;
  1238 	 */
  1217 	 */
  1239 	function no_content() {
  1218 	function no_content() {
  1240 		log_app('Status','204: No Content');
  1219 		log_app('Status','204: No Content');
  1241 		header('Content-Type: text/plain');
  1220 		header('Content-Type: text/plain');
  1242 		status_header('204');
  1221 		status_header('204');
  1243 		echo "Deleted.";
  1222 		echo "Moved to Trash.";
  1244 		exit;
  1223 		exit;
  1245 	}
  1224 	}
  1246 
  1225 
  1247 	/**
  1226 	/**
  1248 	 * Display 'Internal Server Error' (500) status header.
  1227 	 * Display 'Internal Server Error' (500) status header.
  1499 		}
  1478 		}
  1500 
  1479 
  1501 		// If Basic Auth is working...
  1480 		// If Basic Auth is working...
  1502 		if(isset($_SERVER['PHP_AUTH_USER']) && isset($_SERVER['PHP_AUTH_PW'])) {
  1481 		if(isset($_SERVER['PHP_AUTH_USER']) && isset($_SERVER['PHP_AUTH_PW'])) {
  1503 			log_app("Basic Auth",$_SERVER['PHP_AUTH_USER']);
  1482 			log_app("Basic Auth",$_SERVER['PHP_AUTH_USER']);
  1504 		}
  1483 
  1505 
  1484 			$user = wp_authenticate($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW']);
  1506 		$user = wp_authenticate($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW']);
  1485 			if ( $user && !is_wp_error($user) ) {
  1507 		if ( $user && !is_wp_error($user) ) {
  1486 				wp_set_current_user($user->ID);
  1508 			wp_set_current_user($user->ID);
  1487 				log_app("authenticate()", $user->user_login);
  1509 			log_app("authenticate()", $user->user_login);
  1488 				return true;
  1510 			return true;
  1489 			}
  1511 		}
  1490 		}
  1512 
  1491 
  1513 		return false;
  1492 		return false;
  1514 	}
  1493 	}
  1515 
  1494