$method, 'parameter' => $parameter); return $id; } private static function parameterToString($parameter) { $return = ''; if (is_array($parameter)) foreach ($parameter as $key => $value) $return .= '&'.$key.'='.$value; return $return; } public function perform($id) { if ( self::$settings->getGlobalOption('cache') && false !== ( $cached = get_transient( 'wp-piwik_c_'.md5(self::$isCacheable[$id] ) ) ) ) { if (!empty ( $cached ) && !(! empty ( $cached['result'] ) && $cached['result'] == 'error') ) { self::$wpPiwik->log("Deliver cached data: ".$id); return $cached; } } self::$wpPiwik->log("Perform request: ".$id); if (!isset(self::$requests[$id])) return array('result' => 'error', 'message' => 'Request '.$id.' was not registered.'); elseif (!isset(self::$results[$id])) { $this->request($id); } if ( isset ( self::$results[$id] ) ) { if ( self::$settings->getGlobalOption('cache') && self::$isCacheable[$id] ) { set_transient( 'wp-piwik_c_'.md5(self::$isCacheable[$id]) , self::$results[$id], WEEK_IN_SECONDS ); } return self::$results[$id]; } else return false; } public function getDebug($id) { return isset( self::$debug[$id] )? self::$debug[$id] : false; } protected function buildURL($config, $urlDecode = false) { $url = 'method='.($config['method']).'&idSite='.self::$settings->getOption('site_id'); foreach ($config['parameter'] as $key => $value) $url .= '&'.$key.'='.($urlDecode?urldecode($value):$value); return $url; } protected function unserialize($str) { self::$wpPiwik->log("Result string: ".$str); return ($str == json_decode(false, true) || @json_decode($str, true) !== false)?json_decode($str, true):array(); } public static function getLastError() { return self::$lastError; } abstract protected function request($id); }