Ejemplo n.º 1
0
 /**
  * Builds a new request.
  *
  * @param 	string 		$application
  */
 protected function buildRequest($application)
 {
     try {
         $routeData = RouteHandler::getInstance()->getRouteData();
         $controller = $routeData['controller'];
         // validate class name
         if (!preg_match('~^[a-z0-9_]+$~i', $controller)) {
             throw new SystemException("Illegal class name '" . $controller . "'");
         }
         // find class
         $classData = $this->getClassData($controller, 'page', $application);
         if ($classData === null) {
             $classData = $this->getClassData($controller, 'form', $application);
         }
         if ($classData === null) {
             $classData = $this->getClassData($controller, 'action', $application);
         }
         if ($classData === null) {
             throw new SystemException("unable to find class for controller '" . $controller . "'");
         } else {
             if (!class_exists($classData['className'])) {
                 throw new SystemException("unable to find class '" . $classData['className'] . "'");
             }
         }
         $this->activeRequest = new Request($classData['className'], $classData['controller'], $classData['pageType']);
     } catch (SystemException $e) {
         throw new IllegalLinkException();
     }
 }
 private function getSchemeURL(&$location)
 {
     $params = array();
     $baseUrl = str_replace(RouteHandler::getProtocol(), 'tapatalk://', WCF::getPath('wbb')) . '?';
     $routeData = RouteHandler::getInstance()->getRouteData();
     $controller = strtolower(isset($routeData['controller']) ? $routeData['controller'] : '');
     $userID = WCF::getUser()->userID;
     if ($userID) {
         $params['user_id'] = $userID;
     }
     if (!empty($this->eventObj->pageNo)) {
         $params['page'] = intval($this->eventObj->pageNo);
     }
     if (!empty($this->eventObj->itemsPerPage)) {
         $params['perpage'] = intval($this->eventObj->itemsPerPage);
     }
     switch ($controller) {
         case 'thread':
             $params['location'] = $location = 'topic';
             $params['tid'] = intval($this->eventObj->threadID);
             $params['fid'] = intval($this->eventObj->board->boardID);
             break;
         case 'board':
             $params['location'] = $location = 'forum';
             $params['fid'] = intval($this->eventObj->boardID);
             break;
         case 'user':
             $params['location'] = $location = 'profile';
             $params['uid'] = intval($this->eventObj->userID);
             break;
         case 'conversation':
             $params['location'] = $location = 'message';
             $params['mid'] = intval($this->eventObj->conversationID);
             break;
         case 'users-online-list':
         case 'usersonlinelist':
             $params['location'] = $location = 'online';
             break;
         case 'search-result':
         case 'searchresult':
             $params['location'] = $location = 'search';
             $params['search_id'] = intval($this->eventObj->searchID);
             break;
         case 'login':
             $params['location'] = $location = 'login';
             break;
         default:
             $params['location'] = $location = 'home';
             break;
     }
     return $baseUrl . http_build_query($params, '&');
 }
 /**
  * @see \wcf\system\event\IEventListener::execute()
  */
 public function execute($eventObj, $className, $eventName)
 {
     if (!WBB_TAPATALK_ENABLE_PUSH_NOTIFICATION) {
         return;
     }
     $method = '';
     $pushData = array();
     $routeData = RouteHandler::getInstance()->getRouteData();
     $controller = $routeData['controller'];
     $parameters = $eventObj->getParameters();
     $returnValues = $eventObj->getReturnValues();
     $actionName = $eventObj->getActionName();
     if ($controller == 'ConversationAdd' && $actionName == 'create') {
         // new conversation
         if (!empty($parameters['conversation']) && $parameters['conversation']->conversationID && $parameters['conversation']->subject) {
             $method = 'doPushConversation';
             $pushData = array('convId' => $returnValues['returnValues']->conversationID, 'msgId' => $returnValues['returnValues']->messageID);
         }
     } else {
         if ($controller == 'ConversationMessageAdd' && $actionName == 'create') {
             // extended reply
             if (!empty($returnValues['returnValues']) && $returnValues['returnValues']->messageID && $returnValues['returnValues']->conversationID) {
                 $method = 'doPushConversation';
                 $pushData = array('convId' => $returnValues['returnValues']->conversationID, 'msgId' => $returnValues['returnValues']->messageID);
             }
         } else {
             if ($controller == 'AJAXProxy' && $actionName == 'quickReply') {
                 // quick reply
                 if (!empty($parameters['data']['conversationID']) && $parameters['data']['conversationID']) {
                     $latestMessageID = $this->getLatestMsgID($parameters['data']['conversationID']);
                     if ($latestMessageID) {
                         $method = 'doPushConversation';
                         $pushData = array('convId' => $parameters['data']['conversationID'], 'msgId' => $latestMessageID);
                     }
                 }
             }
         }
     }
     // push
     if (!empty($method) && !empty($pushData)) {
         if (file_exists(WBB_TAPATALK_DIR . '/push/TapatalkPush.php')) {
             require_once WBB_TAPATALK_DIR . '/push/TapatalkPush.php';
             $tapatalkPush = new \TapatalkPush();
             $tapatalkPush->callMethod($method, $pushData);
         }
     }
 }
Ejemplo n.º 4
0
	/**
	 * Builds a new request.
	 * 
	 * @param	string		$application
	 */
	protected function buildRequest($application) {
		try {
			$routeData = RouteHandler::getInstance()->getRouteData();
			
			// handle landing page for frontend requests
			if (!$this->isACPRequest()) {
				$landingPage = PageMenu::getInstance()->getLandingPage();
				if ($landingPage !== null && RouteHandler::getInstance()->isDefaultController()) {
					// check if redirect URL matches current URL
					$redirectURL = $landingPage->getLink();
					if (StringUtil::replace(RouteHandler::getHost(), '', $redirectURL) == $_SERVER['REQUEST_URI']) {
						$routeData['controller'] = $landingPage->getController();
					}
					else {
						// redirect to landing page
						HeaderUtil::redirect($landingPage->getLink(), true);
						exit;
					}
				}
			}
			
			$controller = $routeData['controller'];
			
			// validate class name
			if (!preg_match('~^[a-z0-9_]+$~i', $controller)) {
				throw new SystemException("Illegal class name '".$controller."'");
			}
			
			// find class
			$classData = $this->getClassData($controller, 'page', $application);
			if ($classData === null) $classData = $this->getClassData($controller, 'form', $application);
			if ($classData === null) $classData = $this->getClassData($controller, 'action', $application);
			
			if ($classData === null) {
				throw new SystemException("unable to find class for controller '".$controller."'");
			}
			else if (!class_exists($classData['className'])) {
				throw new SystemException("unable to find class '".$classData['className']."'");
			}
			
			$this->activeRequest = new Request($classData['className'], $classData['controller'], $classData['pageType']);
		}
		catch (SystemException $e) {
			throw new IllegalLinkException();
		}
	}
Ejemplo n.º 5
0
	/**
	 * @see	wcf\action\IAction::execute()
	 */
	public function execute() {
		parent::execute();
		
		$routeData = RouteHandler::getInstance()->getRouteData();
		
		if (!isset($routeData['className']) || !isset($routeData['id'])) {
			throw new IllegalLinkException();
		}
		
		// validate class name
		if (!preg_match('~^[a-z0-9_]+$~i', $routeData['className'])) {
			throw new AJAXException("Illegal class name '".$routeData['className']."'");
		}
		
		//get class data
		$classData = $this->getClassData($routeData['className']);
		
		if ($classData === null) {
			throw new AJAXException("unable to find class for controller '".$routeData['className']."'");
		}
		else if (!class_exists($classData['className'])) {
			throw new AJAXException("unable to find class '".$classData['className']."'");
		}
		
		//create object
		$object = new $classData['className']($routeData['id']);
		
		if (!$object || !($object instanceof IRESTfulResponse)) {
			throw new AJAXException("unable to create object of '".$routeData['className']."'");
		}
		
		$this->data = $this->prune($object);
		
		if (empty($this->data)) {
			throw new AJAXException("no results");
		}
		
		$this->executed();
	}
 /**
  * @see \wcf\system\event\IEventListener::execute()
  */
 public function execute($eventObj, $className, $eventName)
 {
     if (!WBB_TAPATALK_ENABLE_PUSH_NOTIFICATION) {
         return;
     }
     $method = '';
     $pushData = array();
     $routeData = RouteHandler::getInstance()->getRouteData();
     $controller = $routeData['controller'];
     $returnValues = $eventObj->getReturnValues();
     $actionName = $eventObj->getActionName();
     if ($actionName == 'triggerPublication' && !empty($returnValues['objectIDs'][0])) {
         if ($controller == 'AJAXProxy') {
             // quick reply post
             $post = new Post($returnValues['objectIDs'][0]);
             if ($post->postID) {
                 $method = 'doPushReply';
                 $pushData = array('oPost' => $post);
             }
         } else {
             if ($controller == 'ThreadAdd' && (!isset($_POST['type']) || $_POST['type'] != 2)) {
                 // new topic
                 $objects = $eventObj->getObjects();
                 $data = $objects[0];
                 $method = 'doPushNewTopic';
                 $pushData = array('postId' => $returnValues['objectIDs'][0], 'boardId' => $data->getThread()->boardID);
             }
         }
     }
     // push
     if (!empty($method) && !empty($pushData)) {
         if (file_exists(WBB_TAPATALK_DIR . '/push/TapatalkPush.php')) {
             require_once WBB_TAPATALK_DIR . '/push/TapatalkPush.php';
             $tapatalkPush = new \TapatalkPush();
             $tapatalkPush->callMethod($method, $pushData);
         }
     }
 }
Ejemplo n.º 7
0
 /**
  * Returns a relative link.
  * 
  * @param	string		$controller
  * @param	array		$parameters
  * @param	string		$url
  * @return	string
  */
 public function getLink($controller = null, array $parameters = array(), $url = '')
 {
     $abbreviation = 'wcf';
     $anchor = '';
     $isACP = $originIsACP = RequestHandler::getInstance()->isACPRequest();
     $forceWCF = $isRaw = false;
     $appendSession = $encodeTitle = true;
     // enforce a certain level of sanitation and protection for links embedded in emails
     if (isset($parameters['isEmail']) && (bool) $parameters['isEmail']) {
         $parameters['forceFrontend'] = true;
         $parameters['appendSession'] = false;
         unset($parameters['isEmail']);
     }
     if (isset($parameters['application'])) {
         $abbreviation = $parameters['application'];
     }
     if (isset($parameters['isRaw'])) {
         $isRaw = $parameters['isRaw'];
         unset($parameters['isRaw']);
     }
     if (isset($parameters['appendSession'])) {
         $appendSession = $parameters['appendSession'];
         unset($parameters['appendSession']);
     }
     if (isset($parameters['isACP'])) {
         $isACP = (bool) $parameters['isACP'];
         unset($parameters['isACP']);
         // drop session id if link leads to ACP from frontend or vice versa
         if ($originIsACP != $isACP) {
             $appendSession = false;
         }
     }
     if (isset($parameters['forceFrontend'])) {
         if ($parameters['forceFrontend'] && $isACP) {
             $isACP = false;
             $appendSession = false;
         }
         unset($parameters['forceFrontend']);
     }
     if (isset($parameters['forceWCF'])) {
         if ($parameters['forceWCF'] && $isACP) {
             $forceWCF = true;
         }
         unset($parameters['forceWCF']);
     }
     if (isset($parameters['encodeTitle'])) {
         $encodeTitle = $parameters['encodeTitle'];
         unset($parameters['encodeTitle']);
     }
     // remove anchor before parsing
     if (($pos = strpos($url, '#')) !== false) {
         $anchor = substr($url, $pos);
         $url = substr($url, 0, $pos);
     }
     // build route
     if ($controller === null) {
         if ($isACP) {
             $controller = 'Index';
         } else {
             return PageMenu::getInstance()->getLandingPage()->getProcessor()->getLink();
         }
     }
     // handle object
     if (isset($parameters['object'])) {
         if (!$parameters['object'] instanceof IRouteController && $parameters['object'] instanceof DatabaseObjectDecorator && $parameters['object']->getDecoratedObject() instanceof IRouteController) {
             $parameters['object'] = $parameters['object']->getDecoratedObject();
         }
         if ($parameters['object'] instanceof IRouteController) {
             $parameters['id'] = $parameters['object']->getObjectID();
             $parameters['title'] = $parameters['object']->getTitle();
         }
     }
     unset($parameters['object']);
     if (isset($parameters['title'])) {
         // component replacement
         if (!empty($this->titleSearch)) {
             $parameters['title'] = str_replace($this->titleSearch, $this->titleReplace, $parameters['title']);
         }
         // remove illegal characters
         $parameters['title'] = trim($this->titleRegex->replace($parameters['title'], '-'), '-');
         // trim to 80 characters
         $parameters['title'] = rtrim(mb_substr($parameters['title'], 0, 80), '-');
         if (!URL_LEGACY_MODE) {
             $parameters['title'] = mb_strtolower($parameters['title']);
         }
         // encode title
         if ($encodeTitle) {
             $parameters['title'] = rawurlencode($parameters['title']);
         }
     }
     $parameters['controller'] = $controller;
     $routeURL = RouteHandler::getInstance()->buildRoute($parameters, $isACP);
     if (!$isRaw && !empty($url)) {
         $routeURL .= strpos($routeURL, '?') === false ? '?' : '&';
     }
     // encode certain characters
     if (!empty($url)) {
         $url = str_replace(array('[', ']'), array('%5B', '%5D'), $url);
     }
     $url = $routeURL . $url;
     // append session id
     if ($appendSession) {
         $url .= strpos($url, '?') === false ? SID_ARG_1ST : SID_ARG_2ND_NOT_ENCODED;
     }
     // handle applications
     if (!PACKAGE_ID) {
         $url = RouteHandler::getHost() . RouteHandler::getPath(array('acp')) . ($isACP ? 'acp/' : '') . $url;
     } else {
         if (RequestHandler::getInstance()->inRescueMode()) {
             $pageURL = RouteHandler::getHost() . str_replace('//', '/', RouteHandler::getPath(array('acp')));
         } else {
             // try to resolve abbreviation
             $application = null;
             if ($abbreviation != 'wcf') {
                 $application = ApplicationHandler::getInstance()->getApplication($abbreviation);
             }
             // fallback to primary application if abbreviation is 'wcf' or unknown
             if ($forceWCF) {
                 $application = ApplicationHandler::getInstance()->getWCF();
             } else {
                 if ($application === null) {
                     $application = ApplicationHandler::getInstance()->getPrimaryApplication();
                 }
             }
             $pageURL = $application->getPageURL();
         }
         $url = $pageURL . ($isACP ? 'acp/' : '') . $url;
     }
     // append previously removed anchor
     $url .= $anchor;
     return $url;
 }
Ejemplo n.º 8
0
 /**
  * Returns a relative link.
  * 
  * @param	string		$controller
  * @param 	array		$parameters
  * @param 	string		$url
  * @return	string
  */
 public function getLink($controller = null, array $parameters = array(), $url = '')
 {
     $abbreviation = 'wcf';
     $anchor = '';
     $isRaw = false;
     if (isset($parameters['application'])) {
         $abbreviation = $parameters['application'];
         unset($parameters['application']);
     }
     if (isset($parameters['isRaw'])) {
         $isRaw = $parameters['isRaw'];
         unset($parameters['isRaw']);
     }
     // remove anchor before parsing
     if (($pos = strpos($url, '#')) !== false) {
         $anchor = substr($url, $pos);
         $url = substr($url, 0, $pos);
     }
     // build route
     if ($controller !== null) {
         // handle object
         if (isset($parameters['object'])) {
             if (!$parameters['object'] instanceof \wcf\system\request\IRouteController && $parameters['object'] instanceof \wcf\data\DatabaseObjectDecorator && $parameters['object']->getDecoratedObject() instanceof \wcf\system\request\IRouteController) {
                 $parameters['object'] = $parameters['object']->getDecoratedObject();
             }
             if ($parameters['object'] instanceof \wcf\system\request\IRouteController) {
                 $parameters['id'] = $parameters['object']->getID();
                 $parameters['title'] = $parameters['object']->getTitle();
             }
             unset($parameters['object']);
         }
         if (isset($parameters['title'])) {
             // remove illegal characters
             $parameters['title'] = trim(preg_replace('/[\\x0-\\x2F\\x3A-\\x40\\x5B-\\x60\\x7B-\\x7F]+/', '-', $parameters['title']), '-');
         }
         $parameters['controller'] = $controller;
         $routeURL = RouteHandler::getInstance()->buildRoute($parameters);
         if (!$isRaw && !empty($url)) {
             $routeURL .= strpos($routeURL, '?') === false ? '?' : '&';
         }
         $url = $routeURL . $url;
     }
     // append session id
     $url .= strpos($url, '?') === false ? SID_ARG_1ST : SID_ARG_2ND_NOT_ENCODED;
     // handle application groups
     $applicationGroup = ApplicationHandler::getInstance()->getActiveGroup();
     if ($applicationGroup !== null) {
         // try to resolve abbreviation
         $application = null;
         if ($abbreviation != 'wcf') {
             $application = ApplicationHandler::getInstance()->getApplication($abbreviation);
         }
         // fallback to primary application if abbreviation is 'wcf' or unknown
         if ($application === null) {
             $application = ApplicationHandler::getInstance()->getPrimaryApplication();
         }
         $url = $application->domainName . $application->domainPath . (RequestHandler::getInstance()->isACPRequest() ? 'acp/' : '') . $url;
     }
     // append previously removed anchor
     $url .= $anchor;
     return $url;
 }
Ejemplo n.º 9
0
 /**
  * Checks page access for possible mandatory redirects.
  * 
  * @param	string		$application
  * @param	array		$routeData
  */
 protected function handleDefaultController($application, array &$routeData)
 {
     if (!RouteHandler::getInstance()->isDefaultController()) {
         return;
     }
     $landingPage = PageMenu::getInstance()->getLandingPage();
     if ($landingPage === null) {
         return;
     }
     if (empty($routeData['controller'])) {
         $routeData['isImplicitController'] = true;
     }
     // resolve implicit application abbreviation for landing page controller
     $landingPageApplication = $landingPage->getApplication();
     $primaryApplication = ApplicationHandler::getInstance()->getPrimaryApplication();
     $primaryApplicationAbbr = ApplicationHandler::getInstance()->getAbbreviation($primaryApplication->packageID);
     if ($landingPageApplication == 'wcf') {
         $landingPageApplication = $primaryApplicationAbbr;
     }
     // check if currently invoked application matches the landing page
     if ($landingPageApplication == $application) {
         $routeData['controller'] = $landingPage->getController();
         if (!URL_LEGACY_MODE) {
             $routeData['controller'] = self::getTokenizedController($routeData['controller']);
         }
         // use alias if defined to prevent incorrect recognition
         $alias = $this->getAliasByController($routeData['controller']);
         if ($alias !== null) {
             $routeData['controller'] = $alias;
         }
         return;
     }
     // redirect if this is the primary application
     if ($application === $primaryApplicationAbbr) {
         HeaderUtil::redirect($landingPage->getLink());
         exit;
     }
     // set default controller
     $applicationObj = WCF::getApplicationObject(ApplicationHandler::getInstance()->getApplication($application));
     $routeData['controller'] = preg_replace('~^.*?\\\\([^\\\\]+)(?:Action|Form|Page)$~', '\\1', $applicationObj->getPrimaryController());
     if (!URL_LEGACY_MODE) {
         $routeData['controller'] = self::getTokenizedController($routeData['controller']);
     }
 }
Ejemplo n.º 10
0
	/**
	 * Returns a relative link.
	 * 
	 * @param	string		$controller
	 * @param	array		$parameters
	 * @param	string		$url
	 * @return	string
	 */
	public function getLink($controller = null, array $parameters = array(), $url = '') {
		$abbreviation = 'wcf';
		$anchor = '';
		$isACP = $originIsACP = RequestHandler::getInstance()->isACPRequest();
		$isRaw = false;
		$appendSession = true;
		if (isset($parameters['application'])) {
			$abbreviation = $parameters['application'];
			unset($parameters['application']);
		}
		if (isset($parameters['isRaw'])) {
			$isRaw = $parameters['isRaw'];
			unset($parameters['isRaw']);
		}
		if (isset($parameters['appendSession'])) {
			$appendSession = $parameters['appendSession'];
			unset($parameters['appendSession']);
		}
		if (isset($parameters['isACP'])) {
			$isACP = (bool) $parameters['isACP'];
			unset($parameters['isACP']);
			
			// drop session id if link leads to ACP from frontend or vice versa
			if ($originIsACP != $isACP) {
				$appendSession = false;
			}
		}
		
		// remove anchor before parsing
		if (($pos = strpos($url, '#')) !== false) {
			$anchor = substr($url, $pos);
			$url = substr($url, 0, $pos);
		}
		
		// build route
		if ($controller === null) {
			// build link to landing page
			$landingPage = PageMenu::getInstance()->getLandingPage();
			$controller = $landingPage->getController();
			$abbreviation = $landingPage->getApplication();
			$url = $landingPage->menuItemLink;
		}
		
		// handle object
		if (isset($parameters['object'])) {
			if (!($parameters['object'] instanceof IRouteController) && $parameters['object'] instanceof DatabaseObjectDecorator && $parameters['object']->getDecoratedObject() instanceof IRouteController) {
				$parameters['object'] = $parameters['object']->getDecoratedObject();
			}
			
			if ($parameters['object'] instanceof IRouteController) {
				$parameters['id'] = $parameters['object']->getObjectID();
				$parameters['title'] = $parameters['object']->getTitle();
			}
			
			unset($parameters['object']);
		}
		
		if (isset($parameters['title'])) {
			// remove illegal characters
			$parameters['title'] = trim($this->titleRegex->replace($parameters['title'], '-'), '-');
		}
		
		$parameters['controller'] = $controller;
		$routeURL = RouteHandler::getInstance()->buildRoute($parameters);
		if (!$isRaw && !empty($url)) {
			$routeURL .= (strpos($routeURL, '?') === false) ? '?' : '&';
		}
		$url = $routeURL . $url;
		
		// append session id
		if ($appendSession) {
			$url .= (strpos($url, '?') === false) ? SID_ARG_1ST : SID_ARG_2ND_NOT_ENCODED;
		}
		
		// handle applications
		if (!PACKAGE_ID) {
			$url = RouteHandler::getHost() . RouteHandler::getPath(array('acp')) . ($isACP ? 'acp/' : '') . $url;
		}
		else {
			// try to resolve abbreviation
			$application = null;
			if ($abbreviation != 'wcf') {
				$application = ApplicationHandler::getInstance()->getApplication($abbreviation);
			}
			
			// fallback to primary application if abbreviation is 'wcf' or unknown
			if ($application === null) {
				$application = ApplicationHandler::getInstance()->getPrimaryApplication();
			}
			
			$url = $application->getPageURL() . ($isACP ? 'acp/' : '') . $url;
		}
		
		// append previously removed anchor
		$url .= $anchor;
		
		return $url;
	}
Ejemplo n.º 11
0
 /**
  * @see	\wcf\system\request\IRoute::buildLink()
  */
 public function buildLink(array $components)
 {
     $application = isset($components['application']) ? $components['application'] : null;
     // drop application component to avoid being appended as query string
     unset($components['application']);
     // handle default values for controller
     $useBuildSchema = true;
     if (count($components) == 1 && isset($components['controller'])) {
         $ignoreController = false;
         if (!RequestHandler::getInstance()->isACPRequest()) {
             $landingPage = PageMenu::getInstance()->getLandingPage();
             if ($this->primaryApplication === '') {
                 $primaryApplication = ApplicationHandler::getInstance()->getPrimaryApplication();
                 $this->primaryApplication = ApplicationHandler::getInstance()->getAbbreviation($primaryApplication->packageID);
             }
             // check if this is the default controller
             if (strcasecmp(RouteHandler::getInstance()->getDefaultController($application), $components['controller']) === 0) {
                 // check if this matches the primary application
                 if ($this->primaryApplication === $application) {
                     if (strcasecmp($landingPage->getController(), $components['controller']) === 0) {
                         // skip controller if it matches the default controller
                         $ignoreController = true;
                     }
                 } else {
                     // skip default controller
                     $ignoreController = true;
                 }
             } else {
                 if (strcasecmp($landingPage->getController(), $components['controller']) === 0) {
                     // landing page
                     $ignoreController = true;
                 }
             }
         }
         // drops controller from route
         if ($ignoreController) {
             $useBuildSchema = false;
             // unset the controller, since it would otherwise be added with http_build_query()
             unset($components['controller']);
         }
     }
     return $this->buildRoute($components, $application, $useBuildSchema);
 }