SAL_Post

The WordPress Core SAL Post class.

Defined (1)

The class is defined in the following location(s).

/sal/class.json-api-post-base.php  
  1. abstract class SAL_Post { 
  2. public $post; 
  3. public $context; 
  4. public $site; 
  5.  
  6. function __construct( $site, $post, $context ) { 
  7. $this->post = $post; 
  8. $this->context = $context; 
  9. $this->site = $site; 
  10.  
  11. public function __set( $key, $value ) { 
  12. $this->post->{ $key } = $value; 
  13.  
  14. public function __get( $key ) { 
  15. if ( $key === 'links' ) { 
  16. require_once dirname( __FILE__ ) . '/class.json-api-links.php'; 
  17. return WPCOM_JSON_API_Links::getInstance(); 
  18. return $this->post->{ $key }; 
  19.  
  20. public function __call( $name, $arguments ) { 
  21. if ( is_callable( array( $this->post, $name ) ) ) { 
  22. return call_user_func_array( array( $this->post, $name ), $arguments ); 
  23. } else { 
  24. trigger_error("Call to undefined method '{$name}'"); 
  25.  
  26. public function __isset ( $name ) { 
  27. return isset( $this->post->{ $name } ); 
  28.  
  29. abstract public function get_like_count(); 
  30. abstract public function is_liked(); 
  31. abstract public function is_reblogged(); 
  32. abstract public function is_following(); 
  33. abstract public function get_global_id(); 
  34. abstract public function get_geo(); 
  35.  
  36. public function get_menu_order() { 
  37. return (int) $this->post->menu_order; 
  38.  
  39. public function get_guid() { 
  40. return (string) $this->post->guid; 
  41.  
  42. public function get_type() { 
  43. return (string) $this->post->post_type; 
  44.  
  45. public function get_terms() { 
  46. $taxonomies = get_object_taxonomies( $this->post, 'objects' ); 
  47. $terms = array(); 
  48. foreach ( $taxonomies as $taxonomy ) { 
  49. if ( ! $taxonomy->public && ! current_user_can( $taxonomy->cap->assign_terms ) ) { 
  50. continue; 
  51.  
  52. $terms[ $taxonomy->name ] = array(); 
  53.  
  54. $taxonomy_terms = wp_get_object_terms( $this->post->ID, $taxonomy->name, array( 'fields' => 'all' ) ); 
  55. foreach ( $taxonomy_terms as $term ) { 
  56. $formatted_term = $this->format_taxonomy( $term, $taxonomy->name, 'display' ); 
  57. $terms[ $taxonomy->name ][ $term->name ] = $formatted_term; 
  58.  
  59. $terms[ $taxonomy->name ] = (object) $terms[ $taxonomy->name ]; 
  60.  
  61. return (object) $terms; 
  62.  
  63. public function get_tags() { 
  64. $tags = array(); 
  65. $terms = wp_get_post_tags( $this->post->ID ); 
  66. foreach ( $terms as $term ) { 
  67. if ( !empty( $term->name ) ) { 
  68. $tags[$term->name] = $this->format_taxonomy( $term, 'post_tag', 'display' ); 
  69. return (object) $tags; 
  70.  
  71. public function get_categories() { 
  72. $categories = array(); 
  73. $terms = wp_get_object_terms( $this->post->ID, 'category', array( 'fields' => 'all' ) ); 
  74. foreach ( $terms as $term ) { 
  75. if ( !empty( $term->name ) ) { 
  76. $categories[$term->name] = $this->format_taxonomy( $term, 'category', 'display' ); 
  77. return (object) $categories; 
  78.  
  79. public function get_attachments_and_count() { 
  80. $attachments = array(); 
  81. $_attachments = new WP_Query( array( 'post_parent' => $this->post->ID, 'post_status' => 'inherit', 'post_type' => 'attachment', 'posts_per_page' => '20' ) ); 
  82. foreach ( $_attachments->posts as $attachment ) { 
  83. $attachments[$attachment->ID] = $this->get_media_item_v1_1( $attachment->ID ); 
  84. return array( (object) $attachments, (int) $_attachments->found_posts ); 
  85.  
  86. public function get_metadata() { 
  87. $metadata = array(); 
  88. foreach ( (array) has_meta( $this->post->ID ) as $meta ) { 
  89. // Don't expose protected fields. 
  90. $meta_key = $meta['meta_key']; 
  91.  
  92. $show = !( WPCOM_JSON_API_Metadata::is_internal_only( $meta_key ) ) 
  93. && 
  94. (  
  95. WPCOM_JSON_API_Metadata::is_public( $meta_key )  
  96. ||  
  97. current_user_can( 'edit_post_meta', $this->post->ID , $meta_key ) 
  98. ); 
  99.  
  100. // Only business plan subscribers can view custom meta description 
  101. if ( Jetpack_SEO_Posts::DESCRIPTION_META_KEY == $meta_key && ! Jetpack_SEO_Utils::is_enabled_jetpack_seo() ) { 
  102. $show = false; 
  103.  
  104. if ( $show ) { 
  105. $metadata[] = array( 
  106. 'id' => $meta['meta_id'],  
  107. 'key' => $meta['meta_key'],  
  108. 'value' => maybe_unserialize( $meta['meta_value'] ),  
  109. ); 
  110.  
  111. if ( ! empty( $metadata ) ) { 
  112. return $metadata; 
  113. } else { 
  114. return false; 
  115.  
  116. public function get_meta() { 
  117. $meta = (object) array( 
  118. 'links' => (object) array( 
  119. 'self' => (string) $this->get_post_link(),  
  120. 'help' => (string) $this->get_post_link( 'help' ),  
  121. 'site' => (string) $this->get_site_link(),  
  122. 'replies' => (string) $this->get_post_link( 'replies/' ),  
  123. 'likes' => (string) $this->get_post_link( 'likes/' ),  
  124. ),  
  125. ); 
  126.  
  127. // add autosave link if a more recent autosave exists 
  128. if ( 'edit' === $this->context ) { 
  129. $autosave = wp_get_post_autosave( $this->post->ID ); 
  130. if ( $autosave && $autosave->post_modified > $this->post->post_modified ) 
  131. $meta->links->autosave = (string) $this->get_post_link() . '/autosave'; 
  132.  
  133. return $meta; 
  134.  
  135. public function get_current_user_capabilities() { 
  136. return array( 
  137. 'publish_post' => current_user_can( 'publish_post', $this->post ),  
  138. 'delete_post' => current_user_can( 'delete_post', $this->post ),  
  139. 'edit_post' => current_user_can( 'edit_post', $this->post ) 
  140. ); 
  141.  
  142. public function get_revisions() { 
  143. if ( 'edit' !== $this->context ) { 
  144. return false; 
  145.  
  146. $revisions = array(); 
  147. $post_revisions = wp_get_post_revisions( $this->post->ID ); 
  148.  
  149. foreach ( $post_revisions as $_post ) { 
  150. $revisions[] = $_post->ID; 
  151.  
  152. return $revisions; 
  153.  
  154. public function get_other_urls() { 
  155. $other_urls = array(); 
  156.  
  157. if ( 'publish' !== $this->post->post_status ) { 
  158. $other_urls = $this->get_permalink_suggestions( $this->post->post_title ); 
  159.  
  160. return (object) $other_urls; 
  161.  
  162. protected function get_site_link() { 
  163. return $this->links->get_site_link( $this->site->get_id() ); 
  164.  
  165. protected function get_post_link( $path = null ) { 
  166. return $this->links->get_post_link( $this->site->get_id(), $this->post->ID, $path ); 
  167.  
  168. public function get_publicize_urls() { 
  169. $publicize_URLs = array(); 
  170. $publicize = get_post_meta( $this->post->ID, 'publicize_results', true ); 
  171. if ( $publicize ) { 
  172. foreach ( $publicize as $service => $data ) { 
  173. switch ( $service ) { 
  174. case 'twitter' : 
  175. foreach ( $data as $datum ) { 
  176. $publicize_URLs[] = esc_url_raw( "https://twitter.com/{$datum['user_id']}/status/{$datum['post_id']}" ); 
  177. break; 
  178. case 'fb' : 
  179. foreach ( $data as $datum ) { 
  180. $publicize_URLs[] = esc_url_raw( "https://www.facebook.com/permalink.php?story_fbid={$datum['post_id']}&id={$datum['user_id']}" ); 
  181. break; 
  182. return (array) $publicize_URLs; 
  183.  
  184. public function get_page_template() { 
  185. return (string) get_post_meta( $this->post->ID, '_wp_page_template', true ); 
  186.  
  187. // note this is overridden in jetpack-shadow 
  188. public function get_featured_image() { 
  189. $image_attributes = wp_get_attachment_image_src( get_post_thumbnail_id( $this->post->ID ), 'full' ); 
  190. if ( is_array( $image_attributes ) && isset( $image_attributes[0] ) ) { 
  191. return (string) $image_attributes[0]; 
  192. } else { 
  193. return ''; 
  194.  
  195. public function get_post_thumbnail() { 
  196. $thumb = null; 
  197.  
  198. $thumb_id = get_post_thumbnail_id( $this->post->ID ); 
  199.  
  200. if ( ! empty( $thumb_id ) ) { 
  201. $attachment = get_post( $thumb_id ); 
  202. if ( ! empty( $attachment ) ) 
  203. $featured_image_object = $this->get_attachment( $attachment ); 
  204.  
  205. if ( ! empty( $featured_image_object ) ) { 
  206. $thumb = (object) $featured_image_object; 
  207.  
  208. return $thumb; 
  209.  
  210. public function get_format() { 
  211. $format = (string) get_post_format( $this->post->ID ); 
  212. if ( !$format ) { 
  213. $format = 'standard'; 
  214.  
  215. return $format; 
  216.  
  217. private function get_attachment( $attachment ) { 
  218. $metadata = wp_get_attachment_metadata( $attachment->ID ); 
  219.  
  220. $result = array( 
  221. 'ID' => (int) $attachment->ID,  
  222. 'URL' => (string) wp_get_attachment_url( $attachment->ID ),  
  223. 'guid' => (string) $attachment->guid,  
  224. 'mime_type' => (string) $attachment->post_mime_type,  
  225. 'width' => (int) isset( $metadata['width'] ) ? $metadata['width'] : 0,  
  226. 'height' => (int) isset( $metadata['height'] ) ? $metadata['height'] : 0,  
  227. ); 
  228.  
  229. if ( isset( $metadata['duration'] ) ) { 
  230. $result['duration'] = (int) $metadata['duration']; 
  231.  
  232. /** This filter is documented in class.jetpack-sync.php */ 
  233. return (object) apply_filters( 'get_attachment', $result ); 
  234.  
  235. public function get_date() { 
  236. return (string) WPCOM_JSON_API_Date::format_date( $this->post->post_date_gmt, $this->post->post_date ); 
  237.  
  238. public function get_modified_date() { 
  239. return (string) WPCOM_JSON_API_Date::format_date( $this->post->post_modified_gmt, $this->post->post_modified ); 
  240.  
  241. public function get_title() { 
  242. if ( 'display' === $this->context ) { 
  243. return (string) get_the_title( $this->post->ID ); 
  244. } else { 
  245. return (string) htmlspecialchars_decode( $this->post->post_title, ENT_QUOTES ); 
  246.  
  247. public function get_url() { 
  248. if ( 'revision' === $this->post->post_type ) { 
  249. return (string) esc_url_raw( get_permalink( $this->post->post_parent ) ); 
  250. } else { 
  251. return (string) esc_url_raw( get_permalink( $this->post->ID ) ); 
  252.  
  253. public function get_shortlink() { 
  254. return (string) esc_url_raw( wp_get_shortlink( $this->post->ID ) ); 
  255.  
  256. public function get_content() { 
  257. if ( 'display' === $this->context ) { 
  258. // TODO: move this WPCOM-specific hack 
  259. add_filter( 'the_password_form', array( $this, 'the_password_form' ) ); 
  260. $content = (string) $this->get_the_post_content_for_display(); 
  261. remove_filter( 'the_password_form', array( $this, 'the_password_form' ) ); 
  262. return $content; 
  263. } else { 
  264. return (string) $this->post->post_content; 
  265.  
  266. public function get_excerpt() { 
  267. if ( 'display' === $this->context ) { 
  268. add_filter( 'the_password_form', array( $this, 'the_password_form' ) ); 
  269. ob_start(); 
  270. the_excerpt(); 
  271. $response = (string) ob_get_clean(); 
  272. remove_filter( 'the_password_form', array( $this, 'the_password_form' ) ); 
  273. } else { 
  274. $response = htmlspecialchars_decode( (string) $this->post->post_excerpt, ENT_QUOTES ); 
  275. return $response; 
  276.  
  277. public function get_status() { 
  278. return (string) get_post_status( $this->post->ID ); 
  279.  
  280. public function is_sticky() { 
  281. return (bool) is_sticky( $this->post->ID ); 
  282.  
  283. public function get_slug() { 
  284. return (string) $this->post->post_name; 
  285.  
  286. public function get_password() { 
  287. $password = (string) $this->post->post_password; 
  288. if ( 'edit' === $this->context ) { 
  289. $password = htmlspecialchars_decode( (string) $password, ENT_QUOTES ); 
  290. return $password; 
  291.  
  292. public function get_parent() { 
  293. if ( $this->post->post_parent ) { 
  294. $parent = get_post( $this->post->post_parent ); 
  295. if ( 'display' === $this->context ) { 
  296. $parent_title = (string) get_the_title( $parent->ID ); 
  297. } else { 
  298. $parent_title = (string) htmlspecialchars_decode( $this->post->post_title, ENT_QUOTES ); 
  299. return (object) array( 
  300. 'ID' => (int) $parent->ID,  
  301. 'type' => (string) $parent->post_type,  
  302. 'link' => (string) $this->links->get_post_link( $this->site->get_id(), $parent->ID ),  
  303. 'title' => $parent_title,  
  304. ); 
  305. } else { 
  306. return false; 
  307.  
  308. function the_password_form() { 
  309. return __( 'This post is password protected.', 'jetpack' ); 
  310.  
  311. public function get_discussion() { 
  312. return array( 
  313. 'comments_open' => (bool) comments_open( $this->post->ID ),  
  314. 'comment_status' => (string) $this->post->comment_status,  
  315. 'pings_open' => (bool) pings_open( $this->post->ID ),  
  316. 'ping_status' => (string) $this->post->ping_status,  
  317. 'comment_count' => (int) $this->post->comment_count,  
  318. ); 
  319.  
  320. public function is_likes_enabled() { 
  321. /** This filter is documented in modules/likes.php */ 
  322. $sitewide_likes_enabled = (bool) apply_filters( 'wpl_is_enabled_sitewide', ! get_option( 'disabled_likes' ) ); 
  323. $post_likes_switched = (bool) get_post_meta( $this->post->ID, 'switch_like_status', true ); 
  324. $post_likes_enabled = $sitewide_likes_enabled; 
  325. if ( $post_likes_switched ) { 
  326. $post_likes_enabled = ! $post_likes_enabled; 
  327. return (bool) $post_likes_enabled; 
  328.  
  329. public function is_sharing_enabled() { 
  330. $show = true; 
  331. /** This filter is documented in modules/sharedaddy/sharing-service.php */ 
  332. $show = apply_filters( 'sharing_show', $show, $this->post ); 
  333.  
  334. $switched_status = get_post_meta( $this->post->ID, 'sharing_disabled', false ); 
  335.  
  336. if ( !empty( $switched_status ) ) 
  337. $show = false; 
  338.  
  339. return (bool) $show; 
  340.  
  341. // No Blog ID parameter. No Post ID parameter. Depends on globals. 
  342. // Expects setup_postdata() to already have been run 
  343. function get_the_post_content_for_display() { 
  344. global $pages, $page; 
  345.  
  346. $old_pages = $pages; 
  347. $old_page = $page; 
  348.  
  349. $content = join( "\n\n", $pages ); 
  350. $content = preg_replace( '/<!--more(.*?)?-->/', '', $content ); 
  351. $pages = array( $content ); 
  352. $page = 1; 
  353.  
  354. ob_start(); 
  355. the_content(); 
  356. $return = ob_get_clean(); 
  357.  
  358. $pages = $old_pages; 
  359. $page = $old_page; 
  360.  
  361. return $return; 
  362.  
  363. public function get_author() { 
  364. if ( 0 == $this->post->post_author ) 
  365. return null; 
  366.  
  367. $show_email = $this->context === 'edit' && current_user_can( 'edit_post', $this->post ); 
  368.  
  369. $user = get_user_by( 'id', $this->post->post_author ); 
  370.  
  371. if ( ! $user || is_wp_error( $user ) ) { 
  372. trigger_error( 'Unknown user', E_USER_WARNING ); 
  373.  
  374. return null; 
  375.  
  376. // TODO factor this out 
  377. if ( defined( 'IS_WPCOM' ) && IS_WPCOM ) { 
  378. $active_blog = get_active_blog_for_user( $user->ID ); 
  379. $site_id = $active_blog->get_id(); 
  380. $profile_URL = "http://en.gravatar.com/{$user->user_login}"; 
  381. } else { 
  382. $profile_URL = 'http://en.gravatar.com/' . md5( strtolower( trim( $user->user_email ) ) ); 
  383. $site_id = -1; 
  384.  
  385. $author = array( 
  386. 'ID' => (int) $user->ID,  
  387. 'login' => (string) $user->user_login,  
  388. 'email' => $show_email ? (string) $user->user_email : false, // (string|bool) 
  389. 'name' => (string) $user->display_name,  
  390. 'first_name' => (string) $user->first_name,  
  391. 'last_name' => (string) $user->last_name,  
  392. 'nice_name' => (string) $user->user_nicename,  
  393. 'URL' => (string) esc_url_raw( $user->user_url ),  
  394. 'avatar_URL' => (string) esc_url_raw( $this->get_avatar_url( $user->user_email ) ),  
  395. 'profile_URL' => (string) esc_url_raw( $profile_URL ) 
  396. ); 
  397.  
  398. if ($site_id > -1) { 
  399. $author['site_ID'] = (int) $site_id; 
  400.  
  401. return (object) $author; 
  402.  
  403. protected function get_avatar_url( $email, $avatar_size = 96 ) { 
  404. $avatar_url = wpcom_get_avatar_url( $email, $avatar_size, '', true ); 
  405. if ( ! $avatar_url || is_wp_error( $avatar_url ) ) { 
  406. return ''; 
  407.  
  408. return esc_url_raw( htmlspecialchars_decode( $avatar_url[0] ) ); 
  409.  
  410. /** 
  411. * Get extra post permalink suggestions 
  412. * @return array array of permalink suggestions: 'permalink_URL', 'suggested_slug' 
  413. */ 
  414. public function get_permalink_suggestions( $title ) { 
  415. $suggestions = array(); 
  416. list( $suggestions['permalink_URL'], $suggestions['suggested_slug'] ) = get_sample_permalink( $this->post->ID, $title ); 
  417. return $suggestions; 
  418.  
  419. private function format_taxonomy( $taxonomy, $taxonomy_type, $context ) { 
  420. // Permissions 
  421. switch ( $context ) { 
  422. case 'edit' : 
  423. $tax = get_taxonomy( $taxonomy_type ); 
  424. if ( !current_user_can( $tax->cap->edit_terms ) ) 
  425. return new WP_Error( 'unauthorized', 'User cannot edit taxonomy', 403 ); 
  426. break; 
  427. case 'display' : 
  428. if ( -1 == get_option( 'blog_public' ) && ! current_user_can( 'read' ) ) { 
  429. return new WP_Error( 'unauthorized', 'User cannot view taxonomy', 403 ); 
  430. break; 
  431. default : 
  432. return new WP_Error( 'invalid_context', 'Invalid API CONTEXT', 400 ); 
  433.  
  434. $response = array(); 
  435. $response['ID'] = (int) $taxonomy->term_id; 
  436. $response['name'] = (string) $taxonomy->name; 
  437. $response['slug'] = (string) $taxonomy->slug; 
  438. $response['description'] = (string) $taxonomy->description; 
  439. $response['post_count'] = (int) $taxonomy->count; 
  440.  
  441. if ( is_taxonomy_hierarchical( $taxonomy_type ) ) { 
  442. $response['parent'] = (int) $taxonomy->parent; 
  443.  
  444. $response['meta'] = (object) array( 
  445. 'links' => (object) array( 
  446. 'self' => (string) $this->links->get_taxonomy_link( $this->site->get_id(), $taxonomy->slug, $taxonomy_type ),  
  447. 'help' => (string) $this->links->get_taxonomy_link( $this->site->get_id(), $taxonomy->slug, $taxonomy_type, 'help' ),  
  448. 'site' => (string) $this->links->get_site_link( $this->site->get_id() ),  
  449. ),  
  450. ); 
  451.  
  452. return (object) $response; 
  453.  
  454. // TODO: factor this out into site 
  455. private function get_media_item_v1_1( $media_id ) { 
  456. $media_item = get_post( $media_id ); 
  457.  
  458. if ( ! $media_item || is_wp_error( $media_item ) ) 
  459. return new WP_Error( 'unknown_media', 'Unknown Media', 404 ); 
  460.  
  461. $file = basename( wp_get_attachment_url( $media_item->ID ) ); 
  462. $file_info = pathinfo( $file ); 
  463. $ext = $file_info['extension']; 
  464.  
  465. $response = array( 
  466. 'ID' => $media_item->ID,  
  467. 'URL' => wp_get_attachment_url( $media_item->ID ),  
  468. 'guid' => $media_item->guid,  
  469. 'date' => (string) WPCOM_JSON_API_Date::format_date( $media_item->post_date_gmt, $media_item->post_date ),  
  470. 'post_ID' => $media_item->post_parent,  
  471. 'author_ID' => (int) $media_item->post_author,  
  472. 'file' => $file,  
  473. 'mime_type' => $media_item->post_mime_type,  
  474. 'extension' => $ext,  
  475. 'title' => $media_item->post_title,  
  476. 'caption' => $media_item->post_excerpt,  
  477. 'description' => $media_item->post_content,  
  478. 'alt' => get_post_meta( $media_item->ID, '_wp_attachment_image_alt', true ),  
  479. 'thumbnails' => array() 
  480. ); 
  481.  
  482. if ( in_array( $ext, array( 'jpg', 'jpeg', 'png', 'gif' ) ) ) { 
  483. $metadata = wp_get_attachment_metadata( $media_item->ID ); 
  484. if ( isset( $metadata['height'], $metadata['width'] ) ) { 
  485. $response['height'] = $metadata['height']; 
  486. $response['width'] = $metadata['width']; 
  487.  
  488. if ( isset( $metadata['sizes'] ) ) { 
  489. /** 
  490. * Filter the thumbnail sizes available for each attachment ID. 
  491. * @module json-api 
  492. * @since 3.9.0 
  493. * @param array $metadata['sizes'] Array of thumbnail sizes available for a given attachment ID. 
  494. * @param string $media_id Attachment ID. 
  495. */ 
  496. $sizes = apply_filters( 'rest_api_thumbnail_sizes', $metadata['sizes'], $media_id ); 
  497. if ( is_array( $sizes ) ) { 
  498. foreach ( $sizes as $size => $size_details ) { 
  499. $response['thumbnails'][ $size ] = dirname( $response['URL'] ) . '/' . $size_details['file']; 
  500.  
  501. if ( isset( $metadata['image_meta'] ) ) { 
  502. $response['exif'] = $metadata['image_meta']; 
  503.  
  504. if ( in_array( $ext, array( 'mp3', 'm4a', 'wav', 'ogg' ) ) ) { 
  505. $metadata = wp_get_attachment_metadata( $media_item->ID ); 
  506. $response['length'] = $metadata['length']; 
  507. $response['exif'] = $metadata; 
  508.  
  509. if ( in_array( $ext, array( 'ogv', 'mp4', 'mov', 'wmv', 'avi', 'mpg', '3gp', '3g2', 'm4v' ) ) ) { 
  510. $metadata = wp_get_attachment_metadata( $media_item->ID ); 
  511. if ( isset( $metadata['height'], $metadata['width'] ) ) { 
  512. $response['height'] = $metadata['height']; 
  513. $response['width'] = $metadata['width']; 
  514.  
  515. if ( isset( $metadata['length'] ) ) { 
  516. $response['length'] = $metadata['length']; 
  517.  
  518. // add VideoPress info 
  519. if ( function_exists( 'video_get_info_by_blogpostid' ) ) { 
  520. $info = video_get_info_by_blogpostid( $this->site->get_id(), $media_id ); 
  521.  
  522. // Thumbnails 
  523. if ( function_exists( 'video_format_done' ) && function_exists( 'video_image_url_by_guid' ) ) { 
  524. $response['thumbnails'] = array( 'fmt_hd' => '', 'fmt_dvd' => '', 'fmt_std' => '' ); 
  525. foreach ( $response['thumbnails'] as $size => $thumbnail_url ) { 
  526. if ( video_format_done( $info, $size ) ) { 
  527. $response['thumbnails'][ $size ] = video_image_url_by_guid( $info->guid, $size ); 
  528. } else { 
  529. unset( $response['thumbnails'][ $size ] ); 
  530.  
  531. $response['videopress_guid'] = $info->guid; 
  532. $response['videopress_processing_done'] = true; 
  533. if ( '0000-00-00 00:00:00' == $info->finish_date_gmt ) { 
  534. $response['videopress_processing_done'] = false; 
  535.  
  536. $response['thumbnails'] = (object) $response['thumbnails']; 
  537.  
  538. $response['meta'] = (object) array( 
  539. 'links' => (object) array( 
  540. 'self' => (string) $this->links->get_media_link( $this->site->get_id(), $media_id ),  
  541. 'help' => (string) $this->links->get_media_link( $this->site->get_id(), $media_id, 'help' ),  
  542. 'site' => (string) $this->links->get_site_link( $this->site->get_id() ),  
  543. ),  
  544. ); 
  545.  
  546. // add VideoPress link to the meta 
  547. if ( in_array( $ext, array( 'ogv', 'mp4', 'mov', 'wmv', 'avi', 'mpg', '3gp', '3g2', 'm4v' ) ) ) { 
  548. if ( function_exists( 'video_get_info_by_blogpostid' ) ) { 
  549. $response['meta']->links->videopress = (string) $this->links->get_link( '/videos/%s', $response['videopress_guid'], '' ); 
  550.  
  551. if ( $media_item->post_parent > 0 ) { 
  552. $response['meta']->links->parent = (string) $this->links->get_post_link( $this->site->get_id(), $media_item->post_parent ); 
  553.  
  554. return (object) $response;