public function executeEmulateList(\core\HttpRequest $request) { $moduleName = $request->getData('emulateModule'); $itemsName = $request->getData('emulateListItems'); $emulatedController = $this->_emulateController(); $methodName = 'list' . ucfirst($itemsName); if (!method_exists($emulatedController, $methodName)) { throw new \RuntimeException('Unknown list items "' . $itemsName . '" on module "' . $moduleName . '"'); } $items = $emulatedController->{$methodName}(); $this->responseContent()->setData($items); }
public function executeLoadTpl(\core\HttpRequest $request) { $index = $request->getData('index'); $tplDirPath = __DIR__ . '/../../../tpl/frontend'; $tplPath = realpath($tplDirPath . '/' . $index . '.html'); if (strpos($tplPath, realpath($tplDirPath) . '/') !== 0) { throw new \RuntimeException('Accessing template "' . $tplPath . '" is not allowed'); } if (!file_exists($tplPath)) { throw new \RuntimeException('Template "' . $tplPath . '" doesn\'t exist'); } $content = file_get_contents($tplPath); $partials = $this->_loadPartials($content, dirname($tplPath)); $this->responseContent()->setData(array('tpl' => $content, 'partials' => $partials)); }
/** * API method helpers **/ protected function callUrl($url, $method, $callParams = array(), $forceAuth = false) { $headers = array('X-Twitter-Content-Type-Accept' => 'application/x-www-form-urlencoded'); if ($this->token || $forceAuth) { $headers['Authorization'] = $this->buildAuthorizationHeader($url, $method, $callParams); } try { $request = new HttpRequest(); $request->multipart = $this->multipart; $request->followLocation = $this->followLocation; $formattedHeaders = array(); foreach ($headers as $k => $v) { $formattedHeaders[] = "{$k}: {$v}"; } list($response, $httpInfo) = $request->send($url, $method, $callParams, $formattedHeaders); } catch (HTTPRequestException $e) { switch ($e->getHttpCode()) { case 400: $message = "Invalid Twitter request"; break; case 401: $message = "Unauthorised Twitter request"; break; case 403: $message = "Twitter refused this request"; break; case 413: $message = "Twitter request too large"; break; case 500: $message = 'Twitter’s having server troubles. Check their status: http://status.twitter.com/'; break; case 502: $message = "Twitter may be down or undergoing an upgrade, or this was just a slow query. Try again later"; break; case 503: $message = "Twitter’s temporarily overloaded. Try again"; break; default: $message = "Twitter request failed"; } if ($eMessage = $e->getMessage()) { $message .= " - {$eMessage}"; } throw new TwitterException($message, $e->getCode(), $e->getMethod(), $e->getUrl(), $callParams, $headers, $e->getResponse(), $e->getResponseHeaders(), $e->getHttpError()); } return array($response, $httpInfo); }