/**
  * Default function to retrieve web service formated data for a post
  */
 public static function get_post_data($_post, $component = null)
 {
     if ($component === null) {
         $component = new WpakComponent('wpak-internal', 'Internal', 'wpak-internal');
     }
     global $post;
     $post = $_post;
     setup_postdata($post);
     $post_data = array('id' => $post->ID, 'post_type' => $post->post_type, 'date' => strtotime($post->post_date), 'title' => $post->post_title, 'content' => '', 'excerpt' => '', 'thumbnail' => '', 'author' => get_the_author_meta('nickname'), 'nb_comments' => (int) get_comments_number());
     /**
      * Filter post content. Use this to format app posts content your own way.
      *
      * To apply the default WP AppKit formating to the content and add only minor modifications to it,
      * use the "wpak_post_content_format" filter instead.
      *
      * @see WpakComponentsUtils::get_formated_content()
      *
      * @param string 			''    			The post content: an empty string by default.
      * @param WP_Post 			$post 			The post object.
      * @param WpakComponent 	$component		The component object.
      */
     $content = apply_filters('wpak_post_content', '', $post, $component);
     if (empty($content)) {
         $content = WpakComponentsUtils::get_formated_content();
     }
     $post_data['content'] = $content;
     $post_data['excerpt'] = WpakComponentsUtils::get_post_excerpt($post);
     $post_featured_img_id = get_post_thumbnail_id($post->ID);
     if (!empty($post_featured_img_id)) {
         /**
          * Use this 'wpak_post_featured_image_size' to define a specific image
          * size to pass to the web service for posts.
          * By default the full (original) image size is used.
          */
         $featured_image_size = apply_filters('wpak_post_featured_image_size', 'full', $post, $component);
         $featured_img_src = wp_get_attachment_image_src($post_featured_img_id, $featured_image_size);
         @($post_data['thumbnail']['src'] = $featured_img_src[0]);
         $post_data['thumbnail']['width'] = $featured_img_src[1];
         $post_data['thumbnail']['height'] = $featured_img_src[2];
     }
     /**
      * Filter post data sent in web service.
      *
      * Use this for example to add a post meta to the default post data.
      *
      * @param array 			$post_data    	The default post data sent to an app.
      * @param WP_Post 			$post 			The post object.
      * @param WpakComponent 	$component		The component object.
      */
     $post_data = apply_filters('wpak_post_data', $post_data, $post, $component);
     return $post_data;
 }
Example #2
0
 protected static function get_page_data($component, $post, $tree_data = array())
 {
     $post_data = WpakComponentsUtils::get_post_data($post, $component);
     /**
      * Filter page content for page components. 
      * Use this to format app pages content your own way only for page component.
      *
      * To apply a custom content to all component types, use the "wpak_post_data_post_content" filter instead.
      *
      * @see WpakComponentsUtils::get_formated_content()
      *
      * @param string 			$post_content   The default post content.
      * @param WP_Post 			$post 			The post object.
      * @param WpakComponent 	$component		The component object.
      */
     $post_data['content'] = apply_filters('wpak_page_content', $post_data['content'], $post, $component);
     $post_data['tree_data'] = !empty($tree_data) ? $tree_data : array();
     /**
      * Filter page data sent to the app from a page component.
      *
      * Use this for example to add a page meta to the default page data only for page component.
      *
      * @param array 			$post_data    	The default page data sent to an app.
      * @param WP_Post 			$post 			The page object.
      * @param WpakComponent 	$component		The component object.
      */
     $post_data = apply_filters('wpak_page_data', $post_data, $post, $component);
     return (object) $post_data;
 }