Example #1
0
 public function __call($method, $arguments)
 {
     try {
         // check if API method is enabled
         // @TODO this is a temp fix, fix as part of VBV-10619
         // performing checkApiState for those being called through callNamed is definitive
         // Also Skip state check for the 'getRoute' and 'checkBeforeView' api calls, because
         // this state check uses the route info from getRoute and calls checkBeforeView  to
         // determine state. See VBV-11808 and the vB5_ApplicationAbstract::checkState calls
         // in vB5_Frontend_Routing::setRoutes.
         if (!in_array($method, array('callNamed', 'getRoute', 'checkBeforeView'))) {
             if (!$this->api->checkApiState($method)) {
                 return false;
             }
         }
         $result = null;
         $type = $this->validateCall($this->api, $method, $arguments);
         if ($type) {
             if (is_callable(array($this->api, $method))) {
                 $call = call_user_func_array(array(&$this->api, $method), $arguments);
                 if ($call !== null) {
                     $result = $call;
                 }
             }
         }
         if ($elist = vB_Api_Extensions::getExtensions($this->controller)) {
             foreach ($elist as $class) {
                 if (is_callable(array($class, $method))) {
                     $args = $arguments;
                     array_unshift($args, $result);
                     $call = call_user_func_array(array($class, $method), $args);
                     if ($call !== null) {
                         $result = $call;
                     }
                 }
             }
         }
         return $result;
     } catch (vB_Exception_Api $e) {
         $errors = $e->get_errors();
         $config = vB::getConfig();
         if (!empty($config['Misc']['debug'])) {
             $trace = '## ' . $e->getFile() . '(' . $e->getLine() . ") Exception Thrown \n" . $e->getTraceAsString();
             $errors[] = array("exception_trace", $trace);
         }
         return array('errors' => $errors);
     } catch (vB_Exception_Database $e) {
         $config = vB::getConfig();
         if (!empty($config['Misc']['debug']) or vB::getUserContext()->hasAdminPermission('cancontrolpanel')) {
             $errors = array('Error ' . $e->getMessage());
             $trace = '## ' . $e->getFile() . '(' . $e->getLine() . ") Exception Thrown \n" . $e->getTraceAsString();
             $errors[] = array("exception_trace", $trace);
             return array('errors' => $errors);
         } else {
             // This text is purposely hard-coded since we don't have
             // access to the database to get a phrase
             return array('errors' => array(array('There has been a database error, and the current page cannot be displayed. Site staff have been notified.')));
         }
     } catch (Exception $e) {
         $errors = array(array('unexpected_error', $e->getMessage()));
         $config = vB::getConfig();
         if (!empty($config['Misc']['debug'])) {
             $trace = '## ' . $e->getFile() . '(' . $e->getLine() . ") Exception Thrown \n" . $e->getTraceAsString();
             $errors[] = array("exception_trace", $trace);
         }
         return array('errors' => $errors);
     }
 }
Example #2
0
 /**
  *	Checks if method returns false response only when API is disabled.
  *
  * @param 	string 	API method to check.
  * @return 	bool 	Indicates whether method returns false response only.
  */
 protected function isDisableFalseReturnOnly($method)
 {
     if (!is_string($method)) {
         return false;
     }
     // extensions check
     if ($elist = vB_Api_Extensions::getExtensions($this->controller)) {
         foreach ($elist as $class) {
             if (in_array($method, $class->disableFalseReturnOnly)) {
                 return true;
             }
         }
     }
     return in_array($method, $this->disableFalseReturnOnly);
 }