Пример #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();
     }
 }
Пример #2
0
 /**
  * Returns absolute page URL.
  * 
  * @return	string
  */
 public function getPageURL()
 {
     if (empty($this->pageURL)) {
         $this->pageURL = RouteHandler::getProtocol() . $this->domainName . $this->domainPath;
     }
     return $this->pageURL;
 }
Пример #3
0
 /**
  * @see	\wcf\system\bbcode\IBBCode::getParsedTag()
  */
 public function getParsedTag(array $openingTag, $content, array $closingTag, BBCodeParser $parser)
 {
     if ($parser->getOutputType() == 'text/html') {
         $quoteLink = !empty($openingTag['attributes'][1]) ? $openingTag['attributes'][1] : '';
         $externalQuoteLink = !empty($openingTag['attributes'][1]) ? !ApplicationHandler::getInstance()->isInternalURL($openingTag['attributes'][1]) : false;
         if (!$externalQuoteLink) {
             $quoteLink = preg_replace('~^https?://~', RouteHandler::getProtocol(), $quoteLink);
         }
         $quoteAuthor = !empty($openingTag['attributes'][0]) ? $openingTag['attributes'][0] : '';
         $quoteAuthorObject = null;
         if ($quoteAuthor && !$externalQuoteLink) {
             $quoteAuthorLC = mb_strtolower(StringUtil::decodeHTML($quoteAuthor));
             foreach (MessageEmbeddedObjectManager::getInstance()->getObjects('com.woltlab.wcf.quote') as $user) {
                 if (mb_strtolower($user->username) == $quoteAuthorLC) {
                     $quoteAuthorObject = $user;
                     break;
                 }
             }
         }
         WCF::getTPL()->assign(array('content' => $content, 'quoteLink' => $quoteLink, 'quoteAuthor' => $quoteAuthor, 'quoteAuthorObject' => $quoteAuthorObject, 'isExternalQuoteLink' => $externalQuoteLink));
         return WCF::getTPL()->fetch('quoteBBCodeTag');
     } else {
         if ($parser->getOutputType() == 'text/simplified-html') {
             return WCF::getLanguage()->getDynamicVariable('wcf.bbcode.quote.text', array('content' => $content, 'cite' => !empty($openingTag['attributes'][0]) ? $openingTag['attributes'][0] : '')) . "\n";
         }
     }
 }
 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, '&');
 }
Пример #5
0
 /**
  * @see wcf\page\IPage::show()
  */
 public function show()
 {
     // use detailed view if accessing WCF ACP directly
     if (PACKAGE_ID == 1) {
         // base tag is determined on runtime
         $host = RouteHandler::getHost();
         $path = RouteHandler::getPath();
         HeaderUtil::redirect($host . $path . 'index.php/PackageListDetailed/' . SID_ARG_1ST, false);
         exit;
     }
     // enable menu item
     ACPMenu::getInstance()->setActiveMenuItem('wcf.acp.menu.link.package.list');
     parent::show();
 }
 /**
  * @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);
         }
     }
 }
Пример #7
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);
         }
     }
 }
Пример #9
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);
 }
Пример #10
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']);
     }
 }
Пример #11
0
	/**
	 * Alias to php setcookie() function.
	 */
	public static function setCookie($name, $value = '', $expire = 0) {
		$application = ApplicationHandler::getInstance()->getActiveApplication();
		$addDomain = (StringUtil::indexOf($application->cookieDomain, '.') === false || StringUtil::endsWith($application->cookieDomain, '.lan') || StringUtil::endsWith($application->cookieDomain, '.local')) ? false : true;
		
		@header('Set-Cookie: '.rawurlencode(COOKIE_PREFIX.$name).'='.rawurlencode($value).($expire ? '; expires='.gmdate('D, d-M-Y H:i:s', $expire).' GMT; max-age='.($expire - TIME_NOW) : '').'; path='.$application->cookiePath.($addDomain ? '; domain='.$application->cookieDomain : '').(RouteHandler::secureConnection() ? '; secure' : '').'; HttpOnly', false);
	}
Пример #12
0
 /**
  * Returns the URI of the current page.
  * 
  * @return	string
  */
 public static function getRequestURI()
 {
     if (URL_LEGACY_MODE) {
         // resolve path and query components
         $scriptName = $_SERVER['SCRIPT_NAME'];
         $pathInfo = RouteHandler::getPathInfo();
         if (empty($pathInfo)) {
             // bug fix if URL omits script name and path
             $scriptName = substr($scriptName, 0, strrpos($scriptName, '/'));
         }
         $path = str_replace('/index.php', '', str_replace($scriptName, '', $_SERVER['REQUEST_URI']));
         if (!StringUtil::isUTF8($path)) {
             $path = StringUtil::convertEncoding('ISO-8859-1', 'UTF-8', $path);
         }
         $path = FileUtil::removeLeadingSlash($path);
         $baseHref = self::getTPL()->get('baseHref');
         if (!empty($path) && mb_strpos($path, '?') !== 0) {
             $baseHref .= 'index.php/';
         }
         return $baseHref . $path;
     } else {
         $url = preg_replace('~^(https?://[^/]+)(?:/.*)?$~', '$1', self::getTPL()->get('baseHref'));
         $url .= $_SERVER['REQUEST_URI'];
         return $url;
     }
 }
Пример #13
0
 /**
  * Generates an anchor tag from given URL.
  * 
  * @param	string		$url
  * @param	string		$title
  * @param	boolean		$encodeTitle
  * @return	string		anchor tag
  */
 public static function getAnchorTag($url, $title = '', $encodeTitle = true)
 {
     $url = self::trim($url);
     $external = true;
     if (ApplicationHandler::getInstance()->isInternalURL($url)) {
         $external = false;
         $url = preg_replace('~^https?://~', RouteHandler::getProtocol(), $url);
     }
     // cut visible url
     if (empty($title)) {
         // use URL and remove protocol and www subdomain
         $title = preg_replace('~^(?:https?|ftps?)://(?:www\\.)?~i', '', $url);
         if (mb_strlen($title) > 60) {
             $title = mb_substr($title, 0, 30) . self::HELLIP . mb_substr($title, -25);
         }
         if (!$encodeTitle) {
             $title = self::encodeHTML($title);
         }
     }
     return '<a href="' . self::encodeHTML($url) . '"' . ($external ? ' class="externalURL"' . (EXTERNAL_LINK_REL_NOFOLLOW ? ' rel="nofollow"' : '') . (EXTERNAL_LINK_TARGET_BLANK ? ' target="_blank"' : '') : '') . '>' . ($encodeTitle ? self::encodeHTML($title) : $title) . '</a>';
 }
Пример #14
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;
 }
 /**
  * Installs current package.
  * 
  * @param	array		$nodeData
  */
 protected function installPackage(array $nodeData)
 {
     $installationStep = new PackageInstallationStep();
     // check requirements
     if (!empty($nodeData['requirements'])) {
         foreach ($nodeData['requirements'] as $package => $requirementData) {
             // get existing package
             if ($requirementData['packageID']) {
                 $sql = "SELECT\tpackageName, packageVersion\n\t\t\t\t\t\tFROM\twcf" . WCF_N . "_package\n\t\t\t\t\t\tWHERE\tpackageID = ?";
                 $statement = WCF::getDB()->prepareStatement($sql);
                 $statement->execute(array($requirementData['packageID']));
             } else {
                 // try to find matching package
                 $sql = "SELECT\tpackageName, packageVersion\n\t\t\t\t\t\tFROM\twcf" . WCF_N . "_package\n\t\t\t\t\t\tWHERE\tpackage = ?";
                 $statement = WCF::getDB()->prepareStatement($sql);
                 $statement->execute(array($package));
             }
             $row = $statement->fetchArray();
             // package is required but not available
             if ($row === false) {
                 throw new SystemException("Package '" . $package . "' is required by '" . $nodeData['packageName'] . "', but is neither installed nor shipped.");
             }
             // check version requirements
             if ($requirementData['minVersion']) {
                 if (Package::compareVersion($row['packageVersion'], $requirementData['minVersion']) < 0) {
                     throw new SystemException("Package '" . $nodeData['packageName'] . "' requires package '" . $row['packageName'] . "' in version '" . $requirementData['minVersion'] . "', but only version '" . $row['packageVersion'] . "' is installed");
                 }
             }
         }
     }
     unset($nodeData['requirements']);
     // update package
     if ($this->queue->packageID) {
         $packageEditor = new PackageEditor(new Package($this->queue->packageID));
         $packageEditor->update($nodeData);
         // delete old excluded packages
         $sql = "DELETE FROM\twcf" . WCF_N . "_package_exclusion\n\t\t\t\tWHERE\t\tpackageID = ?";
         $statement = WCF::getDB()->prepareStatement($sql);
         $statement->execute(array($this->queue->packageID));
         // delete old requirements and dependencies
         $sql = "DELETE FROM\twcf" . WCF_N . "_package_requirement\n\t\t\t\tWHERE\t\tpackageID = ?";
         $statement = WCF::getDB()->prepareStatement($sql);
         $statement->execute(array($this->queue->packageID));
     } else {
         // create package entry
         $package = PackageEditor::create($nodeData);
         // update package id for current queue
         $queueEditor = new PackageInstallationQueueEditor($this->queue);
         $queueEditor->update(array('packageID' => $package->packageID));
         // reload queue
         $this->queue = new PackageInstallationQueue($this->queue->queueID);
         $this->package = null;
         if ($package->isApplication) {
             $host = str_replace(RouteHandler::getProtocol(), '', RouteHandler::getHost());
             $path = RouteHandler::getPath(array('acp'));
             // insert as application
             ApplicationEditor::create(array('domainName' => $host, 'domainPath' => $path, 'cookieDomain' => $host, 'cookiePath' => $path, 'packageID' => $package->packageID));
         }
     }
     // save excluded packages
     if (count($this->getArchive()->getExcludedPackages())) {
         $sql = "INSERT INTO\twcf" . WCF_N . "_package_exclusion\n\t\t\t\t\t\t(packageID, excludedPackage, excludedPackageVersion)\n\t\t\t\tVALUES\t\t(?, ?, ?)";
         $statement = WCF::getDB()->prepareStatement($sql);
         foreach ($this->getArchive()->getExcludedPackages() as $excludedPackage) {
             $statement->execute(array($this->queue->packageID, $excludedPackage['name'], !empty($excludedPackage['version']) ? $excludedPackage['version'] : ''));
         }
     }
     // insert requirements and dependencies
     $requirements = $this->getArchive()->getAllExistingRequirements();
     if (!empty($requirements)) {
         $sql = "INSERT INTO\twcf" . WCF_N . "_package_requirement\n\t\t\t\t\t\t(packageID, requirement)\n\t\t\t\tVALUES\t\t(?, ?)";
         $statement = WCF::getDB()->prepareStatement($sql);
         foreach ($requirements as $identifier => $possibleRequirements) {
             $requirement = array_shift($possibleRequirements);
             $statement->execute(array($this->queue->packageID, $requirement['packageID']));
         }
     }
     if ($this->getPackage()->isApplication && $this->getPackage()->package != 'com.woltlab.wcf' && $this->getAction() == 'install') {
         if (empty($this->getPackage()->packageDir)) {
             $document = $this->promptPackageDir();
             if ($document !== null && $document instanceof FormDocument) {
                 $installationStep->setDocument($document);
             }
             $installationStep->setSplitNode();
         }
     }
     return $installationStep;
 }
Пример #16
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();
		}
	}
Пример #17
0
	/**
	 * @see	wcf\system\WCF::assignDefaultTemplateVariables()
	 */
	protected function assignDefaultTemplateVariables() {
		parent::assignDefaultTemplateVariables();
		
		// base tag is determined on runtime
		$host = RouteHandler::getHost();
		$path = RouteHandler::getPath();
		
		self::getTPL()->assign(array(
			'baseHref' => $host . $path,
			'quickAccessPackages' => $this->getQuickAccessPackages(),
			// todo: 'timezone' => \wcf\util\DateUtil::getTimezone()
		));
	}
Пример #18
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;
	}
	/**
	 * Prompts for a text input for package directory (applies for applications only)
	 * 
	 * @return	wcf\system\form\FormDocument
	 */
	protected function promptPackageDir() {
		if (!PackageInstallationFormManager::findForm($this->queue, 'packageDir')) {
			
			$container = new GroupFormElementContainer();
			$packageDir = new TextInputFormElement($container);
			$packageDir->setName('packageDir');
			$packageDir->setLabel(WCF::getLanguage()->get('wcf.acp.package.packageDir.input'));
			
			$path = RouteHandler::getPath(array('wcf', 'acp'));
			$defaultPath = FileUtil::addTrailingSlash(FileUtil::unifyDirSeperator($_SERVER['DOCUMENT_ROOT'] . $path));
			$packageDir->setValue($defaultPath);
			$container->appendChild($packageDir);
			
			$document = new FormDocument('packageDir');
			$document->appendContainer($container);
			
			PackageInstallationFormManager::registerForm($this->queue, $document);
			return $document;
		}
		else {
			$document = PackageInstallationFormManager::getForm($this->queue, 'packageDir');
			$document->handleRequest();
			$packageDir = $document->getValue('packageDir');
			
			if ($packageDir !== null) {
				// validate package dir
				if (file_exists(FileUtil::addTrailingSlash($packageDir) . 'global.php')) {
					$document->setError('packageDir', WCF::getLanguage()->get('wcf.acp.package.packageDir.notAvailable'));
					return $document;
				}
				
				// set package dir
				$packageEditor = new PackageEditor($this->getPackage());
				$packageEditor->update(array(
					'packageDir' => FileUtil::getRelativePath(WCF_DIR, $packageDir)
				));
				
				// parse domain path
				$domainPath = FileUtil::getRelativePath(FileUtil::unifyDirSeperator($_SERVER['DOCUMENT_ROOT']), FileUtil::unifyDirSeperator($packageDir));
				
				// work-around for applications installed in document root
				if ($domainPath == './') {
					$domainPath = '';
				}
				
				$domainPath = FileUtil::addLeadingSlash(FileUtil::addTrailingSlash($domainPath));
				
				// update application path
				$application = new Application($this->getPackage()->packageID);
				$applicationEditor = new ApplicationEditor($application);
				$applicationEditor->update(array(
					'domainPath' => $domainPath,
					'cookiePath' => $domainPath
				));
				
				// create directory and set permissions
				@mkdir($packageDir, 0777, true);
				@chmod($packageDir, 0777);
			}
			
			return null;
		}
	}
Пример #20
0
 /**
  * @see	\wcf\system\WCF::assignDefaultTemplateVariables()
  */
 protected function assignDefaultTemplateVariables()
 {
     parent::assignDefaultTemplateVariables();
     // base tag is determined on runtime
     $host = RouteHandler::getHost();
     $path = RouteHandler::getPath();
     self::getTPL()->assign(array('baseHref' => $host . $path));
 }
Пример #21
0
 /**
  * @see	\wcf\form\IForm::save()
  */
 public function save()
 {
     parent::save();
     // change user
     WCF::getSession()->changeUser($this->user);
     $this->saved();
     if (!empty($this->url)) {
         // append session
         if (mb_strpos($this->url, '?') !== false) {
             $this->url .= SID_ARG_2ND_NOT_ENCODED;
         } else {
             $this->url .= SID_ARG_1ST;
         }
         HeaderUtil::redirect($this->url);
     } else {
         if (RequestHandler::getInstance()->inRescueMode()) {
             $path = RouteHandler::getHost() . RouteHandler::getPath() . SID_ARG_1ST;
         } else {
             $application = ApplicationHandler::getInstance()->getActiveApplication();
             $path = $application->getPageURL() . 'acp/' . SID_ARG_1ST;
         }
         HeaderUtil::redirect($path);
     }
     exit;
 }
Пример #22
0
 /**
  * Assigns template variables for reCAPTCHA.
  */
 public function assignVariables()
 {
     WCF::getTPL()->assign(array('recaptchaLanguageCode' => $this->languageCode, 'recaptchaPublicKey' => $this->publicKey, 'recaptchaUseSSL' => RouteHandler::secureConnection(), 'recaptchaLegacyMode' => true));
 }
Пример #23
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;
 }