From 5b688b4d5f2de97977584401620e7004c6a53afc Mon Sep 17 00:00:00 2001 From: Daniel Date: Tue, 8 May 2012 19:09:32 +0100 Subject: [PATCH] handle duplicate values i.e. photo-url and tag arrays --- application/libraries/tumblr.php | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/application/libraries/tumblr.php b/application/libraries/tumblr.php index dba35e5..44f21da 100644 --- a/application/libraries/tumblr.php +++ b/application/libraries/tumblr.php @@ -339,7 +339,25 @@ function parse_posts($url, $data="", $method="POST") } foreach($post as $a => $b) { - if (!is_array($b)) $posts[$i][$a] = (string) $b; else $posts[$i][$a] = $b; + + // type cast from simple xml element to string if appropriate + $value = null; + if (!is_array($b)){ + $value = (string) $b; + }else{ + $value = $b; + } + + // convert an existing node to a sub array and append this value + // or not + if(isset($posts[$i][$a])){ + if(! is_array($posts[$i][$a])) + $posts[$i][$a] = array($posts[$i][$a]); + + $posts[$i][$a][] = $value; + }else{ + $posts[$i][$a] = $value; + } } $i++;