Plugin Directory

Changeset 598083


Ignore:
Timestamp:
09/12/2012 04:54:12 PM (13 years ago)
Author:
dphiffer
Message:

Updates to page model

File:
1 edited

Legend:

Unmodified
Added
Removed
  • json-api/trunk/models/post.php

    r568357 r598083  
    3131      $this->import_wp_object($wp_post);
    3232    }
     33    do_action("json_api_{$this->type}_constructor", $this);
    3334  }
    3435 
     
    149150    $this->set_thumbnail_value();
    150151    $this->set_custom_fields_value();
     152    $this->set_custom_taxonomies($wp_post->post_type);
     153    do_action("json_api_import_wp_post", $this, $wp_post);
    151154  }
    152155 
     
    245248    }
    246249    $thumbnail_size = $this->get_thumbnail_size();
    247     list($thumbnail) = wp_get_attachment_image_src($attachment_id, $thumbnail_size);
    248     $this->thumbnail = $thumbnail;
    249    
    250     $attachments = $json_api->introspector->get_attachments($this->id);
    251     foreach ($attachments as $attachment) {
    252       if ($attachment->id == $attachment_id) {
    253         $this->thumbnail_images = $attachment->images;
    254         break;
    255       }
    256     }
     250    $this->thumbnail_size = $thumbnail_size;
     251    $attachment = $json_api->introspector->get_attachment($attachment_id);
     252    $image = $attachment->images[$thumbnail_size];
     253    $this->thumbnail = $image->url;
     254    $this->thumbnail_images = $attachment->images;
    257255  }
    258256 
    259257  function set_custom_fields_value() {
    260258    global $json_api;
    261     if ($json_api->include_value('custom_fields') &&
    262         $json_api->query->custom_fields) {
    263       $keys = explode(',', $json_api->query->custom_fields);
     259    if ($json_api->include_value('custom_fields')) {
    264260      $wp_custom_fields = get_post_custom($this->id);
    265261      $this->custom_fields = new stdClass();
    266       foreach ($keys as $key) {
    267         if (isset($wp_custom_fields[$key])) {
     262      if ($json_api->query->custom_fields) {
     263        $keys = explode(',', $json_api->query->custom_fields);
     264      }
     265      foreach ($wp_custom_fields as $key => $value) {
     266        if ($json_api->query->custom_fields) {
     267          if (in_array($key, $keys)) {
     268            $this->custom_fields->$key = $wp_custom_fields[$key];
     269          }
     270        } else if (substr($key, 0, 1) != '_') {
    268271          $this->custom_fields->$key = $wp_custom_fields[$key];
    269272        }
     
    271274    } else {
    272275      unset($this->custom_fields);
     276    }
     277  }
     278 
     279  function set_custom_taxonomies($type) {
     280    global $json_api;
     281    $taxonomies = get_taxonomies(array(
     282      'object_type' => array($type),
     283      'public'   => true,
     284      '_builtin' => false
     285    ));
     286    foreach ($taxonomies as $taxonomy) {
     287      if ($json_api->include_value($taxonomy)) {
     288        $terms = get_the_terms($this->id, $taxonomy);
     289        if (!empty($terms)) {
     290          $this->$taxonomy = array_values($terms);
     291        } else {
     292          $this->$taxonomy = array();
     293        }
     294      }
    273295    }
    274296  }
Note: See TracChangeset for help on using the changeset viewer.