Changeset 598083
- Timestamp:
- 09/12/2012 04:54:12 PM (13 years ago)
- File:
-
- 1 edited
-
json-api/trunk/models/post.php (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
json-api/trunk/models/post.php
r568357 r598083 31 31 $this->import_wp_object($wp_post); 32 32 } 33 do_action("json_api_{$this->type}_constructor", $this); 33 34 } 34 35 … … 149 150 $this->set_thumbnail_value(); 150 151 $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); 151 154 } 152 155 … … 245 248 } 246 249 $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; 257 255 } 258 256 259 257 function set_custom_fields_value() { 260 258 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')) { 264 260 $wp_custom_fields = get_post_custom($this->id); 265 261 $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) != '_') { 268 271 $this->custom_fields->$key = $wp_custom_fields[$key]; 269 272 } … … 271 274 } else { 272 275 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 } 273 295 } 274 296 }
Note: See TracChangeset
for help on using the changeset viewer.