function complex_report_query($start_date, $end_date, $dimensions = array(), $metrics = array(), $sort = array(), $filters = array()) { $url = $this->base_url . 'data'; $url .= '?ids=' . $this->ids; $url .= sizeof($dimensions) > 0 ? '&dimensions=' . join(array_reverse($dimensions), ',') : ''; $url .= sizeof($metrics) > 0 ? '&metrics=' . join($metrics, ',') : ''; $url .= sizeof($sort) > 0 ? '&sort=' . join($sort, ',') : ''; $url .= sizeof($filters) > 0 ? '&filters=' . urlencode(join($filters, ',')) : ''; $url .= '&start-date=' . $start_date; $url .= '&end-date=' . $end_date; if (!SimpleFileCache::isExpired($url, $this->cache_timeout)) { $this->http_code = 200; // We never cache bad requests return SimpleFileCache::cacheGet($url); } else { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); curl_setopt($ch, CURLOPT_HTTPHEADER, array($this->createAuthHeader($url, 'GET'))); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $return = curl_exec($ch); if (curl_errno($ch)) { $this->error_message = curl_error($ch); return false; } $this->http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE); if ($this->http_code != 200) { $this->error_message = $return; return false; } else { $xml = simplexml_load_string($return); curl_close($ch); $return_values = array(); foreach ($xml->entry as $entry) { $metrics = array(); foreach ($entry->xpath('dxp:metric') as $metric) { $metric_attributes = $metric->attributes(); $metrics[(string) $metric_attributes['name']] = (string) $metric_attributes['value']; } $last_dimension_var_name = null; foreach ($entry->xpath('dxp:dimension') as $dimension) { $dimension_attributes = $dimension->attributes(); $dimension_var_name = 'dimensions_' . strtr((string) $dimension_attributes['name'], ':', '_'); ${$dimension_var_name} = array(); if ($last_dimension_var_name == null) { ${$dimension_var_name} = array('name' => (string) $dimension_attributes['name'], 'value' => (string) $dimension_attributes['value'], 'children' => $metrics); } else { ${$dimension_var_name} = array('name' => (string) $dimension_attributes['name'], 'value' => (string) $dimension_attributes['value'], 'children' => ${$last_dimension_var_name}); } $last_dimension_var_name = $dimension_var_name; } array_push($return_values, ${$last_dimension_var_name}); } SimpleFileCache::cachePut($url, $return_values, $this->cache_timeout); return $return_values; } } }