示例#1
0
 protected function outputCORSHeaders()
 {
     $corsHandler = new CORSHandler();
     $corsHandler->handle();
 }
示例#2
0
 /**
  * Dispatches the API request to the appropriate API method and returns the result
  * after post-processing.
  *
  * Post-processing includes:
  *
  * - flattening if **flat** is 0
  * - running generic filters unless **disable_generic_filters** is set to 1
  * - URL decoding label column values
  * - running queued filters unless **disable_queued_filters** is set to 1
  * - removing columns based on the values of the **hideColumns** and **showColumns** query parameters
  * - filtering rows if the **label** query parameter is set
  * - converting the result to the appropriate format (ie, XML, JSON, etc.)
  *
  * If `'original'` is supplied for the output format, the result is returned as a PHP
  * object.
  *
  * @throws PluginDeactivatedException if the module plugin is not activated.
  * @throws Exception if the requested API method cannot be called, if required parameters for the
  *                   API method are missing or if the API method throws an exception and the **format**
  *                   query parameter is **original**.
  * @return DataTable|Map|string The data resulting from the API call.
  */
 public function process()
 {
     // read the format requested for the output data
     $outputFormat = strtolower(Common::getRequestVar('format', 'xml', 'string', $this->request));
     // create the response
     $response = new ResponseBuilder($outputFormat, $this->request);
     $corsHandler = new CORSHandler();
     $corsHandler->handle();
     try {
         // read parameters
         $moduleMethod = Common::getRequestVar('method', null, 'string', $this->request);
         list($module, $method) = $this->extractModuleAndMethod($moduleMethod);
         $module = $this->renameModule($module);
         if (!\Piwik\Plugin\Manager::getInstance()->isPluginActivated($module)) {
             throw new PluginDeactivatedException($module);
         }
         $apiClassName = $this->getClassNameAPI($module);
         self::reloadAuthUsingTokenAuth($this->request);
         // call the method
         $returnedValue = Proxy::getInstance()->call($apiClassName, $method, $this->request);
         $toReturn = $response->getResponse($returnedValue, $module, $method);
     } catch (Exception $e) {
         Log::debug($e);
         $toReturn = $response->getResponseException($e);
     }
     return $toReturn;
 }
示例#3
0
 /**
  * Dispatches the API request to the appropriate API method and returns the result
  * after post-processing.
  *
  * Post-processing includes:
  *
  * - flattening if **flat** is 0
  * - running generic filters unless **disable_generic_filters** is set to 1
  * - URL decoding label column values
  * - running queued filters unless **disable_queued_filters** is set to 1
  * - removing columns based on the values of the **hideColumns** and **showColumns** query parameters
  * - filtering rows if the **label** query parameter is set
  * - converting the result to the appropriate format (ie, XML, JSON, etc.)
  *
  * If `'original'` is supplied for the output format, the result is returned as a PHP
  * object.
  *
  * @throws PluginDeactivatedException if the module plugin is not activated.
  * @throws Exception if the requested API method cannot be called, if required parameters for the
  *                   API method are missing or if the API method throws an exception and the **format**
  *                   query parameter is **original**.
  * @return DataTable|Map|string The data resulting from the API call.
  */
 public function process()
 {
     // read the format requested for the output data
     $outputFormat = strtolower(Common::getRequestVar('format', 'xml', 'string', $this->request));
     // create the response
     $response = new ResponseBuilder($outputFormat, $this->request);
     $corsHandler = new CORSHandler();
     $corsHandler->handle();
     $tokenAuth = Common::getRequestVar('token_auth', '', 'string', $this->request);
     $shouldReloadAuth = false;
     try {
         // read parameters
         $moduleMethod = Common::getRequestVar('method', null, 'string', $this->request);
         list($module, $method) = $this->extractModuleAndMethod($moduleMethod);
         list($module, $method) = self::getRenamedModuleAndAction($module, $method);
         PluginManager::getInstance()->checkIsPluginActivated($module);
         $apiClassName = self::getClassNameAPI($module);
         if ($shouldReloadAuth = self::shouldReloadAuthUsingTokenAuth($this->request)) {
             $access = Access::getInstance();
             $tokenAuthToRestore = $access->getTokenAuth();
             $hadSuperUserAccess = $access->hasSuperUserAccess();
             self::forceReloadAuthUsingTokenAuth($tokenAuth);
         }
         // call the method
         $returnedValue = Proxy::getInstance()->call($apiClassName, $method, $this->request);
         $toReturn = $response->getResponse($returnedValue, $module, $method);
     } catch (Exception $e) {
         Log::debug($e);
         $toReturn = $response->getResponseException($e);
     }
     if ($shouldReloadAuth) {
         $this->restoreAuthUsingTokenAuth($tokenAuthToRestore, $hadSuperUserAccess);
     }
     return $toReturn;
 }