diff --git a/gapi.class.php b/gapi.class.php index c704301..8af7311 100644 --- a/gapi.class.php +++ b/gapi.class.php @@ -359,6 +359,43 @@ public function getResults() { return is_array($this->results) ? $this->results : false; } + /** + * Get current analytics results + * and output as xml format strings ( API v2.3 faked ). + * + * @return String + */ + public function getResultsXML() { + $xmlstring = ""; + $xmlentry = array(); + + if(is_array($this->results) && count($this->results) >= 1 ){ + // generate tags each entry + foreach ($this->results as $entry) { + $xmlentrydetail = array(); + foreach ( $entry->getDimensions() as $key => $value) { + $xmlentrydetail[] = "\t"; + } + foreach ( $entry->getMetrics() as $key => $value) { + $type = (is_integer($value)) ? 'integer' : 'string'; + $xmlentrydetail[] = "\t"; + } + $xmlentry[] = ''."\n".implode("\n", $xmlentrydetail)."\n".''; + } + + // Put xml header/footer + $xmlheader = '' . "\n"; + $xmlheader .= ''; + $xmlfooter = ''; + // combine all entry and make strings of faked xml format. + $xmlstring = $xmlheader . "\n" + . implode("\n", $xmlentry) . "\n" + . $xmlfooter; + return $xmlstring; + } + return false; + } + /** * Get current account data *