* @license PHP License * @package WB * @subpackage service */ WBClass::load('WBService' , 'WBString' ); /** * Forward to (external) URL * * @version 0.1.3 * @package WB * @subpackage service */ class WBService_Forward extends WBService { /** * Forward to URL * * Actually try to load URL using path's URLid and redirect * * @param int $status * @param mixed $data to be send * @param string $checksum * @return bool true */ public function run(&$status, &$data, &$checksum = null) { // make session read only to avoid blocking further requests $this->sess->close(); // browser must revalidate $this->res->setCacheControl(WBResponse::CACHECONTROL_MUSTREVALIDATE); $this->res->setMaxAge(600); $data = WBString::replaceSuperPlaceholders('

URL not found!

You may want to got to the homepage or simply go back. Thank you.

'); $status = 404; $id = $this->extractUrlId($this->req->path); if (!$id) { return true; } $url = $this->getUrl($id); if (!$url) { return true; } /** @var WBStatistic_ForwardTracker */ $stat = WBClass::create('WBStatistic_ForwardTracker'); $stat->add($id); $data = str_replace('{URL}', $url, 'Please continue at {URL}. Thank you.'); $status = 200; if (1 > WBParam::get('wb/debug', 0)) { $this->res->addHeader('Location', $url); $status = 301; } return true; } /** * Get URL By Id * * @return string * @return string */ private function getUrl($id) { /** @var WBDictionary_URL */ $dict = WBClass::create('WBDictionary_URL'); try { $dict->load($id); } catch (Exception $e) { return ''; } return WBString::replaceSuperPlaceholders($dict->getWord()); } /** * Find URLid in Path * * @return string * @return string */ private function extractUrlId($path) { $path = explode('/', trim($path, '/')); if (preg_match('/^\d+$/', $path[0])) { return $path[0]; } return ''; } }