Created
September 4, 2012 10:50
-
-
Save simenbrekken/3620046 to your computer and use it in GitHub Desktop.
Vae property plucker.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <? | |
| function vae_pluck($path, $properties, $json = true) { | |
| $results = array(); | |
| $context = vae($path); | |
| foreach ($context as $entry) { | |
| $result = array(); | |
| foreach ($properties as $key) { | |
| $property = $entry[$key]; | |
| switch ($property->structure->type) { | |
| case 'FileItem': | |
| $value = vae_data_url() . vae_file($property); | |
| break; | |
| case 'ImageItem': | |
| $value = vae_data_url() . vae_image($property); | |
| break; | |
| default: | |
| $value = (string) $property; | |
| if (is_float($value)) { | |
| $value = (float) $value; | |
| } else if (is_int($value)) { | |
| $value = (int) $value; | |
| } | |
| } | |
| $result[$key] = $value; | |
| } | |
| $results[] = $result; | |
| } | |
| return $json ? json_encode($results) : $results; | |
| } | |
| print_r(vae_pluck('/settings/backgrounds[section="home"]', array('section', 'image'))); | |
| ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment