Advertisement
Guest User

Untitled

a guest
Nov 8th, 2012
660
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2. /*
  3. Controller name: timeline
  4. Controller description: Data manipulation methods for timeline posts in the verite format
  5. */
  6.  
  7. class JSON_API_Timeline_Controller {
  8.  
  9.         public function timeline_posts() {
  10.                 global $json_api;
  11.                 $json = array();
  12.               $main_post_id = $json_api->query->main_post_id;
  13.                $post_type = 'post';
  14.                 $amount = -1;
  15.  
  16.                 $posts = get_posts(array('post_type' => $post_type, 'numberposts' => $amount, 'orderby' => 'post_date', 'order' => 'DESC'));
  17.  
  18.                $main_post = get_post($main_post_id);
  19.                
  20.  
  21.                 if($main_post) {
  22.  
  23.                         // setting first (main) post
  24.  
  25.                         $json['timeline'] = array();
  26.  
  27.                         $json['timeline']['headline'] = $main_post->post_title;
  28.                         $startDate=get_post_meta($post->ID, 'startDate',true); //gets the startdate from the custom fields plugin
  29.                                         $json['timeline']['date'][$i]['startDate'] = $startDate;
  30.  
  31.                         $json['timeline']['type'] = 'default';
  32.                         $json['timeline']['text'] = $main_post->post_content;
  33.                         /*
  34.                          if(has_post_thumbnail($main_post->ID)) {
  35.  
  36.                                 $thumbnail_id = get_post_thumbnail_id($main_post->ID);
  37.                                 $thumbnail_src = wp_get_attachment_image_src($thumbnail_id, 'medium');
  38.                                 $json['timeline']['asset']['media'] = $thumbnail_src[0];
  39.                                
  40.                         }
  41.                         */
  42.  
  43.                         if($posts) {
  44.                                 $json['timeline']['date'] = array();
  45.                                 $i = 0;
  46.                                 foreach($posts as $post) {
  47.  
  48.                                 $startDate=get_post_meta($post->ID, 'startDate',true);  //gets the enddate from the custom fields plugin
  49.                                 $endDate=get_post_meta($post->ID, 'endDate',true); //gets the enddate from the custom fields plugin
  50.                                         $json['timeline']['date'][$i]['startDate'] = $startDate;
  51.                                         $json['timeline']['date'][$i]['endDate'] = $endDate;
  52.  
  53.  
  54.                                         $json['timeline']['date'][$i]['headline'] = $post->post_title;
  55.                                         $json['timeline']['date'][$i]['text'] = $post->post_content;
  56.                                         //preg_replace( $json['timeline']['date'][$i]['text'] ,'class="','class="lightbox ')
  57.  
  58.                                         // example of media asset using the post thumbnail
  59.                                       /*  if(has_post_thumbnail($post->ID)) {
  60.  
  61.                                                 $thumbnail_id = get_post_thumbnail_id($post->ID);
  62.                                                 $thumbnail_src = wp_get_attachment_image_src($thumbnail_id, 'medium');
  63.  
  64.                                                 $json['timeline']['date'][$i]['asset']['media'] = $thumbnail_src[0];
  65.  
  66.                                         }
  67.  */
  68.                                         $i++;
  69.  
  70.                                 }
  71.  
  72.                                 return $json;
  73.  
  74.                         } else return 'Posts not found';
  75.  
  76.                 } else return 'Main post not found';
  77.  
  78.         }
  79.  
  80. }
  81.  
  82. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement