Esempio n. 1
0
 /**
  * @see	\wcf\system\SingletonFactory::init()
  */
 protected function init()
 {
     // get menu items from cache
     $this->loadCache();
     // check menu items
     $this->checkMenuItems('header');
     $this->checkMenuItems('footer');
     // build plain menu item list
     $this->buildMenuItemList('header');
     $this->buildMenuItemList('footer');
     // call init event
     EventHandler::getInstance()->fireAction($this, 'init');
     foreach ($this->menuItems as $menuItems) {
         foreach ($menuItems as $menuItem) {
             if ($menuItem->isLandingPage) {
                 $this->landingPage = $menuItem;
                 break 2;
             }
         }
     }
     if ($this->landingPage === null) {
         throw new SystemException("Missing landing page");
     }
     $this->setActiveMenuItem($this->landingPage->menuItem);
 }
 /**
  * @see	\wcf\system\worker\IWorker::execute()
  */
 public function execute()
 {
     EventHandler::getInstance()->fireAction($this, 'execute');
     if (!$this->loopCount) {
         // delete existing stat
         $sql = "DELETE FROM\twcf" . WCF_N . "_stat_daily";
         $statement = WCF::getDB()->prepareStatement($sql);
         $statement->execute();
     }
     // prepare insert statement
     $sql = "INSERT IGNORE INTO\twcf" . WCF_N . "_stat_daily\n\t\t\t\t\t\t(objectTypeID, date, counter, total)\n\t\t\tVALUES\t\t\t(?, ?, ?, ?)";
     $statement = WCF::getDB()->prepareStatement($sql);
     $this->getStartDate();
     $d = DateUtil::getDateTimeByTimestamp($this->startDate);
     $d->setTimezone(new \DateTimeZone(TIMEZONE));
     $d->setTime(0, 0);
     if ($this->loopCount) {
         $d->add(new \DateInterval('P' . $this->loopCount * $this->limit . 'D'));
     }
     for ($i = 0; $i < $this->limit; $i++) {
         if ($d->getTimestamp() > TIME_NOW) {
             break;
         }
         // get object types
         foreach (ObjectTypeCache::getInstance()->getObjectTypes('com.woltlab.wcf.statDailyHandler') as $objectType) {
             $data = $objectType->getProcessor()->getData($d->getTimestamp());
             $statement->execute(array($objectType->objectTypeID, $d->format('Y-m-d'), $data['counter'], $data['total']));
         }
         $d->add(new \DateInterval('P1D'));
     }
 }
Esempio n. 3
0
 /**
  * Preparses the given text.
  * 
  * @param	string			$text
  * @param	array<string>		$allowedBBCodes
  * @return	string
  */
 public function parse($text, array $allowedBBCodes = null)
 {
     $this->text = $text;
     $this->allowedBBCodes = $allowedBBCodes;
     // cache codes
     $this->cacheCodes();
     // cache url bbcodes
     $this->cacheURLBBCodes();
     // call event
     EventHandler::getInstance()->fireAction($this, 'beforeParsing');
     // parse urls
     if ($this->allowedBBCodes === null || BBCode::isAllowedBBCode('media', $this->allowedBBCodes) || BBCode::isAllowedBBCode('url', $this->allowedBBCodes)) {
         $this->parseURLs();
     }
     // parse email addresses
     if ($this->allowedBBCodes === null || BBCode::isAllowedBBCode('email', $this->allowedBBCodes)) {
         $this->parseEmails();
     }
     // call event
     EventHandler::getInstance()->fireAction($this, 'afterParsing');
     // insert cached url bbcodes
     $this->insertCachedURLBBCodes();
     // insert cached codes
     $this->insertCachedCodes();
     return $this->text;
 }
Esempio n. 4
0
 /**
  * Calls all init functions of the WCF and the WCFACP class. 
  */
 public function __construct()
 {
     // add autoload directory
     self::$autoloadDirectories['wcf'] = WCF_DIR . 'lib/';
     // define tmp directory
     if (!defined('TMP_DIR')) {
         define('TMP_DIR', FileUtil::getTempFolder());
     }
     // start initialization
     $this->initMagicQuotes();
     $this->initDB();
     $this->loadOptions();
     $this->initPackage();
     $this->initSession();
     $this->initLanguage();
     $this->initTPL();
     $this->initCronjobs();
     $this->initCoreObjects();
     // prevent application loading during setup
     if (PACKAGE_ID) {
         $this->initApplications();
     }
     $this->initBlacklist();
     $this->initAuth();
     EventHandler::getInstance()->fireAction($this, 'initialized');
 }
 /** 
  * @see	\wcf\system\package\plugin\IPackageInstallationPlugin::uninstall()
  */
 public function uninstall()
 {
     // call uninstall event
     EventHandler::getInstance()->fireAction($this, 'uninstall');
     // get all style of this package
     $isDefault = false;
     $styleList = new StyleList();
     $styleList->getConditionBuilder()->add("packageID = ?", array($this->installation->getPackageID()));
     $styleList->readObjects();
     foreach ($styleList->getObjects() as $style) {
         $styleEditor = new StyleEditor($style);
         $styleEditor->delete();
         $isDefault = $isDefault || $style->isDefault;
     }
     // default style deleted
     if ($isDefault) {
         $styleList = new StyleList();
         $styleList->sqlOrderBy = 'style.styleID ASC';
         $styleList->sqlLimit = 1;
         $styleList->readObjects();
         $styles = $styleList->getObjects();
         if (!empty($styles)) {
             $styleEditor = new StyleEditor(current($styles));
             $styleEditor->setAsDefault();
         }
     }
 }
 /**
  * @see	wcf\system\package\plugin\IPackageInstallationPlugin::uninstall()
  */
 public function uninstall()
 {
     // call uninstall event
     EventHandler::getInstance()->fireAction($this, 'uninstall');
     $sql = "DELETE FROM\twcf" . WCF_N . "_" . $this->tableName . "\n\t\t\tWHERE\t\tpackageID = ?";
     $statement = WCF::getDB()->prepareStatement($sql);
     $statement->execute(array($this->installation->getPackageID()));
 }
 /**
  * @see	\wcf\system\SingletonFactory
  */
 protected function init()
 {
     // call loadInstance event
     EventHandler::getInstance()->fireAction($this, 'init');
     if (!ClassUtil::isInstanceOf($this->className, 'wcf\\system\\user\\authentication\\IUserAuthentication')) {
         throw new SystemException("'" . $this->className . "' does not implement 'wcf\\system\\user\\authentication\\IUserAuthentication'");
     }
     $this->userAuthentication = call_user_func(array($this->className, 'getInstance'));
 }
 /**
  * @see	wcf\system\package\plugin\IPackageInstallationPlugin::uninstall()
  */
 public function uninstall()
 {
     // call uninstall event
     EventHandler::getInstance()->fireAction($this, 'uninstall');
     $packageIcon = $this->installation->getPackage()->packageIcon;
     if (!empty($packageIcon)) {
         @unlink(WCF_DIR . $packageIcon);
     }
 }
Esempio n. 9
0
 /**
  * @see wcf\system\jcoins\shop\item\type\IShopItem::validateBuy()
  */
 public function validateBuy()
 {
     if (WCF::getUser()->userID == 0) {
         throw new PermissionDeniedException();
     }
     if (!MODULE_JCOINS || !MODULE_JCOINS_SHOP) {
         throw new PermissionDeniedException();
     }
     EventHandler::getInstance()->fireAction($this, 'validate');
 }
 /**
  * Returns user authentication instance.
  * 
  * @return wcf\system\user\authentication\IUserAuthentication
  */
 public static function getUserAuthentication()
 {
     if (static::$userAuthentication === null) {
         // call loadInstance event
         EventHandler::getInstance()->fireAction(__CLASS__, 'loadUserAuthentication');
         // get default implementation
         static::loadUserAuthentication();
     }
     return static::$userAuthentication;
 }
Esempio n. 11
0
 /**
  * Validates the given sort order parameter. 
  */
 public function validateSortOrder()
 {
     // call validateSortOrder event
     EventHandler::getInstance()->fireAction($this, 'validateSortOrder');
     switch ($this->sortOrder) {
         case 'ASC':
         case 'DESC':
             break;
         default:
             $this->sortOrder = $this->defaultSortOrder;
     }
 }
 /**
  * @see \wcf\data\DatabaseObjectList::readObjects()
  */
 public function readObjects()
 {
     parent::readObjects();
     EventHandler::getInstance()->fireAction($this, 'afterReadObjects');
     // cache userids
     $userIDs = array();
     foreach ($this->objects as $object) {
         $userIDs[] = $object->userID;
         $userIDs[] = $object->executedUserID;
     }
     array_unique($userIDs);
     UserProfile::getUserProfiles($userIDs);
 }
Esempio n. 13
0
 /**
  * @see wcf\system\SingletonFactory::init()
  */
 protected function init()
 {
     // get menu items from cache
     $this->loadCache();
     // check menu items
     $this->checkMenuItems('header');
     $this->checkMenuItems('footer');
     // build plain menu item list
     $this->buildMenuItemList('header');
     $this->buildMenuItemList('footer');
     // call init event
     EventHandler::getInstance()->fireAction($this, 'init');
 }
Esempio n. 14
0
 /**
  * Updates session's last activity time to prevent it from expiring. In addition this method
  * will return updated counters for notifications and 3rd party components.
  * 
  * @return	array<mixed>
  */
 public function keepAlive()
 {
     // ignore sessions created by this request
     if (WCF::getSession()->lastActivityTime == TIME_NOW) {
         return;
     }
     // update last activity time
     SessionHandler::getInstance()->keepAlive();
     // update notification counts
     $this->keepAliveData = array('userNotificationCount' => UserNotificationHandler::getInstance()->getNotificationCount(true));
     // notify 3rd party components
     EventHandler::getInstance()->fireAction($this, 'keepAlive');
     return $this->keepAliveData;
 }
Esempio n. 15
0
 /**
  * Loads the object of the active session.
  */
 public function load()
 {
     // get session
     $sessionID = $this->readSessionID();
     SessionHandler::getInstance()->load($this->sessionEditor, $sessionID);
     // call beforeInit event
     if (!defined('NO_IMPORTS')) {
         EventHandler::getInstance()->fireAction($this, 'beforeInit');
     }
     $this->init();
     // call afterInit event
     if (!defined('NO_IMPORTS')) {
         EventHandler::getInstance()->fireAction($this, 'afterInit');
     }
 }
 /**
  * @see	\wcf\form\IForm::validate()
  */
 public function validate()
 {
     EventHandler::getInstance()->fireAction($this, 'validate');
     // check given user name
     if ($this->user === null || !$this->user->userID) {
         throw new UserInputException('username', 'notFound');
     }
     // user is already enabled
     if ($this->user->activationCode == 0) {
         throw new NamedUserException(WCF::getLanguage()->get('wcf.user.registerActivation.error.userAlreadyEnabled'));
     }
     // check given activation code
     if ($this->user->activationCode != $this->activationCode) {
         throw new UserInputException('activationCode', 'notValid');
     }
 }
 /**
  * Uninstalls node components and returns next node.
  * 
  * @param	string		$node
  * @return	string
  */
 public function uninstall($node)
 {
     $nodes = $this->nodeBuilder->getNodeData($node);
     // invoke node-specific actions
     foreach ($nodes as $data) {
         $nodeData = unserialize($data['nodeData']);
         switch ($data['nodeType']) {
             case 'package':
                 $this->uninstallPackage($nodeData);
                 break;
             case 'pip':
                 $this->executePIP($nodeData);
                 break;
         }
     }
     // mark node as completed
     $this->nodeBuilder->completeNode($node);
     $node = $this->nodeBuilder->getNextNode($node);
     // perform post-uninstall actions
     if ($node == '') {
         // update options.inc.php if uninstallation is completed
         OptionEditor::resetCache();
         // clear cache
         CacheHandler::getInstance()->flushAll();
         // reset language cache
         LanguageFactory::getInstance()->clearCache();
         LanguageFactory::getInstance()->deleteLanguageCache();
         // reset stylesheets
         StyleHandler::resetStylesheets();
         // rebuild application paths
         ApplicationHandler::rebuild();
         // clear user storage
         UserStorageHandler::getInstance()->clear();
         EventHandler::getInstance()->fireAction($this, 'postUninstall');
     }
     if ($this->requireRestructureVersionTables) {
         $this->restructureVersionTables();
     }
     // return next node
     return $node;
 }
 /**
  * @see	\wcf\form\IForm::validate()
  */
 public function validate()
 {
     EventHandler::getInstance()->fireAction($this, 'validate');
     // check given user id
     $this->user = new User($this->userID);
     if (!$this->user->userID) {
         throw new UserInputException('u', 'notValid');
     }
     // user is already enabled
     if ($this->user->reactivationCode == 0) {
         throw new NamedUserException(WCF::getLanguage()->get('wcf.user.emailActivation.error.emailAlreadyEnabled'));
     }
     // check whether the new email isn't unique anymore
     if (!UserUtil::isAvailableEmail($this->user->newEmail)) {
         throw new NamedUserException(WCF::getLanguage()->get('wcf.user.email.error.notUnique'));
     }
     // check given activation code
     if ($this->user->reactivationCode != $this->activationCode) {
         throw new UserInputException('a', 'notValid');
     }
 }
Esempio n. 19
0
	/**
	 * @see	wcf\page\IPage::show()
	 */
	public function show() {
		// check if active user is logged in
		if ($this->loginRequired && !WCF::getUser()->userID) {
			throw new PermissionDeniedException();
		}
		
		// sets the active menu item
		$this->setActiveMenuItem();
		
		// check modules
		$this->checkModules();
		
		// check permission
		$this->checkPermissions();
		
		// read data
		$this->readData();
		
		// assign variables
		$this->assignVariables();
		
		// call show event
		EventHandler::getInstance()->fireAction($this, 'show');
		
		// try to guess template name
		$classParts = explode('\\', get_class($this));
		if (empty($this->templateName)) {
			$className = preg_replace('~(Form|Page)$~', '', array_pop($classParts));
				
			// check if this an *Edit page and use the add-template instead
			if (substr($className, -4) == 'Edit') {
				$className = substr($className, 0, -4) . 'Add';
			}
				
			$this->templateName = lcfirst($className);
			
			// assign guessed template name
			WCF::getTPL()->assign('templateName', $this->templateName);
		}
		
		if ($this->useTemplate) {
			// show template
			WCF::getTPL()->display($this->templateName, array_shift($classParts));
		}
	}
Esempio n. 20
0
 /**
  * Sets available variables
  */
 protected function setVariables()
 {
     // set color variables
     $this->colors = array('wcfButtonBackgroundColor', 'wcfButtonBorderColor', 'wcfButtonColor', 'wcfButtonHoverBackgroundColor', 'wcfButtonHoverBorderColor', 'wcfButtonHoverColor', 'wcfButtonPrimaryBackgroundColor', 'wcfButtonPrimaryBorderColor', 'wcfButtonPrimaryColor', 'wcfColor', 'wcfContainerAccentBackgroundColor', 'wcfContainerBackgroundColor', 'wcfContainerBorderColor', 'wcfContainerHoverBackgroundColor', 'wcfContentBackgroundColor', 'wcfDimmedColor', 'wcfInputBackgroundColor', 'wcfInputBorderColor', 'wcfInputColor', 'wcfInputHoverBackgroundColor', 'wcfInputHoverBorderColor', 'wcfLinkColor', 'wcfLinkHoverColor', 'wcfPageBackgroundColor', 'wcfPageColor', 'wcfPageLinkColor', 'wcfPageLinkHoverColor', 'wcfTabularBoxBackgroundColor', 'wcfTabularBoxColor', 'wcfTabularBoxHoverColor', 'wcfUserPanelBackgroundColor', 'wcfUserPanelColor', 'wcfUserPanelHoverBackgroundColor', 'wcfUserPanelHoverColor');
     // set global variables
     $this->globals = array('wcfBaseFontSize', 'wcfLayoutFixedWidth', 'wcfLayoutMinWidth', 'wcfLayoutMaxWidth');
     // set specialized variables
     $this->specialVariables = array('individualLess', 'overrideLess', 'pageLogo', 'useFluidLayout', 'wcfBaseFontFamily');
     EventHandler::getInstance()->fireAction($this, 'setVariables');
 }
Esempio n. 21
0
 /**
  * @see wcf\page\IPage::show()
  */
 public function show()
 {
     // check modules
     $this->checkModules();
     // check permission
     $this->checkPermissions();
     // read data
     $this->readData();
     // try to guess template name
     if (empty($this->templateName)) {
         $classParts = explode('\\', get_class($this));
         $className = preg_replace('~(Form|Page)$~', '', array_pop($classParts));
         // check if this an *Edit page and use the add-template instead
         if (substr($className, -4) == 'Edit') {
             $className = substr($className, 0, -4) . 'Add';
         }
         $this->templateName = lcfirst($className);
     }
     // assign variables
     $this->assignVariables();
     // call show event
     EventHandler::getInstance()->fireAction($this, 'show');
     if ($this->useTemplate) {
         // show template
         WCF::getTPL()->display($this->templateName);
     }
 }
Esempio n. 22
0
 /**
  * Calls the 'executed' event after the successful execution of this action.
  * This functions won't called automatically. You must do this manually, if you inherit AbstractAction.
  */
 protected function executed()
 {
     EventHandler::getInstance()->fireAction($this, 'executed');
 }
Esempio n. 23
0
 /**
  * Gets all options and option categories from cache.
  */
 protected function readCache()
 {
     $cache = call_user_func(array($this->cacheClass, 'getInstance'));
     // get cache contents
     $this->cachedCategories = $cache->getData(array(), 'categories');
     $this->cachedOptions = $cache->getData(array(), 'options');
     $this->cachedCategoryStructure = $cache->getData(array(), 'categoryStructure');
     $this->cachedOptionToCategories = $cache->getData(array(), 'optionToCategories');
     // allow option manipulation
     EventHandler::getInstance()->fireAction($this, 'afterReadCache');
 }
Esempio n. 24
0
 /**
  * @see	\wcf\page\IPage::show()
  */
 public function show()
 {
     // check if active user is logged in
     if ($this->loginRequired && !WCF::getUser()->userID) {
         throw new PermissionDeniedException();
     }
     // check if current request URL matches the canonical URL
     if ($this->canonicalURL && empty($_POST)) {
         $canoncialURL = parse_url(preg_replace('~[?&]s=[a-f0-9]{40}~', '', $this->canonicalURL));
         // use $_SERVER['REQUEST_URI'] because it represents the URL used to access the site and not the internally rewritten one
         // IIS Rewrite-Module has a bug causing the REQUEST_URI to be ISO-encoded
         $requestURI = !empty($_SERVER['UNENCODED_URL']) ? $_SERVER['UNENCODED_URL'] : $_SERVER['REQUEST_URI'];
         $requestURI = preg_replace('~[?&]s=[a-f0-9]{40}~', '', $requestURI);
         if (!StringUtil::isUTF8($requestURI)) {
             $requestURI = StringUtil::convertEncoding('ISO-8859-1', 'UTF-8', $requestURI);
         }
         // some webservers output lower-case encoding (e.g. %c3 instead of %C3)
         $requestURI = preg_replace_callback('~%(?P<encoded>[a-zA-Z0-9]{2})~', function ($matches) {
             return '%' . strtoupper($matches['encoded']);
         }, $requestURI);
         $requestURL = parse_url($requestURI);
         $redirect = false;
         if ($canoncialURL['path'] != $requestURL['path']) {
             $redirect = true;
         } else {
             if (isset($canoncialURL['query'])) {
                 if (!isset($requestURL['query'])) {
                     $redirect = true;
                 } else {
                     parse_str($canoncialURL['query'], $cQueryString);
                     parse_str($requestURL['query'], $rQueryString);
                     foreach ($cQueryString as $key => $value) {
                         if (!isset($rQueryString[$key]) || $rQueryString[$key] != $value) {
                             $redirect = true;
                             break;
                         }
                     }
                 }
             }
         }
         if ($redirect) {
             $redirectURL = $this->canonicalURL;
             if (!empty($requestURL['query'])) {
                 $queryString = $requestURL['query'];
                 parse_str($requestURL['query'], $rQueryString);
                 if (!empty($canoncialURL['query'])) {
                     parse_str($canoncialURL['query'], $cQueryString);
                     // clean query string
                     foreach ($cQueryString as $key => $value) {
                         if (isset($rQueryString[$key])) {
                             unset($rQueryString[$key]);
                         }
                     }
                 }
                 // drop route data from query
                 if (!URL_LEGACY_MODE) {
                     foreach ($rQueryString as $key => $value) {
                         if ($value === '') {
                             unset($rQueryString[$key]);
                         }
                     }
                 }
                 if (!empty($rQueryString)) {
                     $redirectURL .= (mb_strpos($redirectURL, '?') === false ? '?' : '&') . http_build_query($rQueryString, '', '&');
                 }
             }
             // force a permanent redirect as recommended by Google
             // https://support.google.com/webmasters/answer/6033086?hl=en#a_note_about_redirects
             @header('HTTP/1.0 301 Moved Permanently');
             HeaderUtil::redirect($redirectURL, false);
             exit;
         }
     }
     // sets the active menu item
     $this->setActiveMenuItem();
     // check modules
     $this->checkModules();
     // check permission
     $this->checkPermissions();
     // read data
     $this->readData();
     // assign variables
     $this->assignVariables();
     // call show event
     EventHandler::getInstance()->fireAction($this, 'show');
     // try to guess template name
     $classParts = explode('\\', get_class($this));
     if (empty($this->templateName)) {
         $className = preg_replace('~(Form|Page)$~', '', array_pop($classParts));
         // check if this an *Edit page and use the add-template instead
         if (substr($className, -4) == 'Edit') {
             $className = substr($className, 0, -4) . 'Add';
         }
         $this->templateName = lcfirst($className);
         // assign guessed template name
         WCF::getTPL()->assign('templateName', $this->templateName);
     }
     if (empty($this->templateNameApplication)) {
         $this->templateNameApplication = array_shift($classParts);
         // assign guessed template application
         WCF::getTPL()->assign('templateNameApplication', $this->templateNameApplication);
     }
     if ($this->useTemplate) {
         // show template
         WCF::getTPL()->display($this->templateName, $this->templateNameApplication);
     }
 }
Esempio n. 25
0
 /**
  * @see wcf\page\MultipleLinkPage::countItems()
  */
 public function countItems()
 {
     // call countItems event
     EventHandler::getInstance()->fireAction($this, 'countItems');
     $sql = "SELECT\tCOUNT(*) AS count\n\t\t\tFROM\twcf" . WCF_N . "_user user_table\n\t\t\t" . $this->conditions;
     $statement = WCF::getDB()->prepareStatement($sql);
     $statement->execute($this->conditions->getParameters());
     $row = $statement->fetchArray();
     return $row['count'];
 }
 /**
  * @see	\wcf\form\IForm::save()
  */
 public function save()
 {
     parent::save();
     // build conditions
     $this->conditions = new PreparedStatementConditionBuilder();
     // deny self delete
     if ($this->action == 'delete') {
         $this->conditions->add("user_table.userID <> ?", array(WCF::getUser()->userID));
     }
     // static fields
     if (!empty($this->username)) {
         $this->conditions->add("user_table.username LIKE ?", array('%' . addcslashes($this->username, '_%') . '%'));
     }
     if (!empty($this->email)) {
         $this->conditions->add("user_table.email LIKE ?", array('%' . addcslashes($this->email, '_%') . '%'));
     }
     if (!empty($this->groupIDs)) {
         $this->conditions->add("user_table.userID " . ($this->invertGroupIDs == 1 ? 'NOT ' : '') . "IN (SELECT userID FROM wcf" . WCF_N . "_user_to_group WHERE groupID IN (?))", array($this->groupIDs));
     }
     if (!empty($this->languageIDs)) {
         $this->conditions->add("user_table.languageID IN (?)", array($this->languageIDs));
     }
     // registration date
     if ($startDate = @strtotime($this->registrationDateStart)) {
         $this->conditions->add('user_table.registrationDate >= ?', array($startDate));
     }
     if ($endDate = @strtotime($this->registrationDateEnd)) {
         $this->conditions->add('user_table.registrationDate <= ?', array($endDate));
     }
     if ($this->banned) {
         $this->conditions->add('user_table.banned = ?', array(1));
     }
     if ($this->notBanned) {
         $this->conditions->add('user_table.banned = ?', array(0));
     }
     // last activity time
     if ($startDate = @strtotime($this->lastActivityTimeStart)) {
         $this->conditions->add('user_table.lastActivityTime >= ?', array($startDate));
     }
     if ($endDate = @strtotime($this->lastActivityTimeEnd)) {
         $this->conditions->add('user_table.lastActivityTime <= ?', array($endDate));
     }
     if ($this->enabled) {
         $this->conditions->add('user_table.activationCode = ?', array(0));
     }
     if ($this->disabled) {
         $this->conditions->add('user_table.activationCode <> ?', array(0));
     }
     // dynamic fields
     foreach ($this->activeOptions as $name => $option) {
         $value = isset($this->values[$option['optionName']]) ? $this->values[$option['optionName']] : null;
         $this->getTypeObject($option['optionType'])->getCondition($this->conditions, $option, $value);
     }
     // call buildConditions event
     EventHandler::getInstance()->fireAction($this, 'buildConditions');
     // execute action
     switch ($this->action) {
         case 'sendMail':
             WCF::getSession()->checkPermissions(array('admin.user.canMailUser'));
             // get user ids
             $userIDs = array();
             $sql = "SELECT\t\tuser_table.userID\n\t\t\t\t\tFROM\t\twcf" . WCF_N . "_user user_table\n\t\t\t\t\tLEFT JOIN\twcf" . WCF_N . "_user_option_value option_value\n\t\t\t\t\tON\t\t(option_value.userID = user_table.userID)" . $this->conditions;
             $statement = WCF::getDB()->prepareStatement($sql);
             $statement->execute($this->conditions->getParameters());
             while ($row = $statement->fetchArray()) {
                 $userIDs[] = $row['userID'];
                 $this->affectedUsers++;
             }
             if (!empty($userIDs)) {
                 // save config in session
                 $userMailData = WCF::getSession()->getVar('userMailData');
                 if ($userMailData === null) {
                     $userMailData = array();
                 }
                 $mailID = count($userMailData);
                 $userMailData[$mailID] = array('action' => '', 'userIDs' => $userIDs, 'groupIDs' => '', 'subject' => $this->subject, 'text' => $this->text, 'from' => $this->from, 'enableHTML' => $this->enableHTML);
                 WCF::getSession()->register('userMailData', $userMailData);
                 WCF::getTPL()->assign('mailID', $mailID);
             }
             break;
         case 'exportMailAddress':
             WCF::getSession()->checkPermissions(array('admin.user.canMailUser'));
             // send content type
             header('Content-Type: text/' . $this->fileType . '; charset=UTF-8');
             header('Content-Disposition: attachment; filename="export.' . $this->fileType . '"');
             if ($this->fileType == 'xml') {
                 echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<addresses>\n";
             }
             // count users
             $sql = "SELECT\t\tCOUNT(*) AS count\n\t\t\t\t\tFROM\t\twcf" . WCF_N . "_user user_table\n\t\t\t\t\tLEFT JOIN\twcf" . WCF_N . "_user_option_value option_value\n\t\t\t\t\tON\t\t(option_value.userID = user_table.userID)\n\t\t\t\t\t" . $this->conditions;
             $statement = WCF::getDB()->prepareStatement($sql);
             $statement->execute($this->conditions->getParameters());
             $count = $statement->fetchArray();
             // get users
             $sql = "SELECT\t\tuser_table.email\n\t\t\t\t\tFROM\t\twcf" . WCF_N . "_user user_table\n\t\t\t\t\tLEFT JOIN\twcf" . WCF_N . "_user_option_value option_value\n\t\t\t\t\tON\t\t(option_value.userID = user_table.userID)\n\t\t\t\t\t" . $this->conditions . "\n\t\t\t\t\tORDER BY\tuser_table.email";
             $statement = WCF::getDB()->prepareStatement($sql);
             $statement->execute($this->conditions->getParameters());
             $i = 0;
             while ($row = $statement->fetchArray()) {
                 if ($this->fileType == 'xml') {
                     echo "<address><![CDATA[" . StringUtil::escapeCDATA($row['email']) . "]]></address>\n";
                 } else {
                     echo $this->textSeparator . $row['email'] . $this->textSeparator . ($i < $count['count'] ? $this->separator : '');
                 }
                 $i++;
                 $this->affectedUsers++;
             }
             if ($this->fileType == 'xml') {
                 echo "</addresses>";
             }
             $this->saved();
             exit;
             break;
         case 'assignToGroup':
             WCF::getSession()->checkPermissions(array('admin.user.canEditUser'));
             $_this = $this;
             $userIDs = $this->fetchUsers(function ($userID, array $userData) use($_this) {
                 $user = new UserEditor(new User(null, $userData));
                 $user->addToGroups($_this->assignToGroupIDs, false, false);
             });
             if (!empty($userIDs)) {
                 UserStorageHandler::getInstance()->reset($userIDs, 'groupIDs', 1);
             }
             break;
         case 'delete':
             WCF::getSession()->checkPermissions(array('admin.user.canDeleteUser'));
             $userIDs = $this->fetchUsers();
             if (!empty($userIDs)) {
                 $userAction = new UserAction($userIDs, 'delete');
                 $userAction->executeAction();
             }
             break;
     }
     $this->saved();
     WCF::getTPL()->assign('affectedUsers', $this->affectedUsers);
 }
Esempio n. 27
0
 /**
  * @see	\wcf\data\AbstractDatabaseObjectAction::update()
  */
 public function update()
 {
     if (isset($this->parameters['data'])) {
         parent::update();
         if (isset($this->parameters['data']['languageID'])) {
             foreach ($this->objects as $object) {
                 if ($object->userID == WCF::getUser()->userID) {
                     if ($this->parameters['data']['languageID'] != WCF::getUser()->languageID) {
                         WCF::setLanguage($this->parameters['data']['languageID']);
                     }
                     break;
                 }
             }
         }
     } else {
         if (empty($this->objects)) {
             $this->readObjects();
         }
     }
     $groupIDs = isset($this->parameters['groups']) ? $this->parameters['groups'] : array();
     $languageIDs = isset($this->parameters['languageIDs']) ? $this->parameters['languageIDs'] : array();
     $removeGroups = isset($this->parameters['removeGroups']) ? $this->parameters['removeGroups'] : array();
     $userOptions = isset($this->parameters['options']) ? $this->parameters['options'] : array();
     if (!empty($groupIDs)) {
         $action = new UserAction($this->objects, 'addToGroups', array('groups' => $groupIDs, 'addDefaultGroups' => false));
         $action->executeAction();
     }
     if (!empty($removeGroups)) {
         $action = new UserAction($this->objects, 'removeFromGroups', array('groups' => $removeGroups));
         $action->executeAction();
     }
     foreach ($this->objects as $userEditor) {
         if (!empty($userOptions)) {
             $userEditor->updateUserOptions($userOptions);
         }
         if (!empty($languageIDs)) {
             $userEditor->addToLanguages($languageIDs);
         }
     }
     // handle user rename
     if (count($this->objects) == 1 && !empty($this->parameters['data']['username'])) {
         if ($this->objects[0]->username != $this->parameters['data']['username']) {
             $userID = $this->objects[0]->userID;
             $username = $this->parameters['data']['username'];
             WCF::getDB()->beginTransaction();
             // update comments
             $sql = "UPDATE\twcf" . WCF_N . "_comment\n\t\t\t\t\tSET\tusername = ?\n\t\t\t\t\tWHERE\tuserID = ?";
             $statement = WCF::getDB()->prepareStatement($sql);
             $statement->execute(array($username, $userID));
             $sql = "UPDATE\twcf" . WCF_N . "_comment_response\n\t\t\t\t\tSET\tusername = ?\n\t\t\t\t\tWHERE\tuserID = ?";
             $statement = WCF::getDB()->prepareStatement($sql);
             $statement->execute(array($username, $userID));
             // modification log
             $sql = "UPDATE\twcf" . WCF_N . "_modification_log\n\t\t\t\t\tSET\tusername = ?\n\t\t\t\t\tWHERE\tuserID = ?";
             $statement = WCF::getDB()->prepareStatement($sql);
             $statement->execute(array($username, $userID));
             WCF::getDB()->commitTransaction();
             // fire event to handle other database tables
             EventHandler::getInstance()->fireAction($this, 'rename');
         }
     }
 }
Esempio n. 28
0
 /**
  * @see wcf\system\cronjob\ICronjob::execute()
  */
 public function execute(Cronjob $cronjob)
 {
     EventHandler::getInstance()->fireAction($this, 'execute');
 }
Esempio n. 29
0
	/**
	 * @see	wcf\form\IForm::save()
	 */
	public function save() {
		parent::save();
		
		// build conditions
		$this->conditions = new PreparedStatementConditionBuilder();
		
		// static fields
		if (!empty($this->username)) {
			$this->conditions->add("user.username LIKE ?", array('%'.addcslashes($this->username, '_%').'%'));
		}
		if (!empty($this->email)) {
			$this->conditions->add("user.email LIKE ?", array('%'.addcslashes($this->email, '_%').'%'));
		}
		if (!empty($this->groupIDArray)) {
			$this->conditions->add("user.userID ".($this->invertGroupIDs == 1 ? 'NOT ' : '')."IN (SELECT userID FROM wcf".WCF_N."_user_to_group WHERE groupID IN (?))", array($this->groupIDArray));
		}
		if (!empty($this->languageIDArray)) {
			$this->conditions->add("user.languageID IN (?)", array($this->languageIDArray));
		}
		
		// dynamic fields
		foreach ($this->activeOptions as $name => $option) {
			$value = isset($this->values[$option['optionName']]) ? $this->values[$option['optionName']] : null;
			$this->getTypeObject($option['optionType'])->getCondition($this->conditions, $option, $value);
		}
		
		// call buildConditions event
		EventHandler::getInstance()->fireAction($this, 'buildConditions');
		
		// execute action
		switch ($this->action) {
			case 'sendMail':
				WCF::getSession()->checkPermissions(array('admin.user.canMailUser'));
				// get user ids
				$userIDArray = array();
				$sql = "SELECT		user.userID
					FROM		wcf".WCF_N."_user
					LEFT JOIN	wcf".WCF_N."_user_option_value option_value
					ON		(option_value.userID = user.userID)".
					$this->conditions;
				$statement = WCF::getDB()->prepareStatement($sql);
				$statement->execute($this->conditions->getParameters());
				while ($row = $statement->fetchArray()) {
					$userIDArray[] = $row['userID'];
					$this->affectedUsers++;
				}
				
				// save config in session
				$userMailData = WCF::getSession()->getVar('userMailData');
				if ($userMailData === null) $userMailData = array();
				$mailID = count($userMailData);
				$userMailData[$mailID] = array(
					'action' => '',
					'userIDs' => implode(',', $userIDArray),
					'groupIDs' => '',
					'subject' => $this->subject,
					'text' => $this->text,
					'from' => $this->from,
					'enableHTML' => $this->enableHTML
				);
				WCF::getSession()->register('userMailData', $userMailData);
				$this->saved();
				
				$url = LinkHandler::getInstance()->getLink('UserMail', array('id' => $mailID));
				
				// show worker template
				WCF::getTPL()->assign(array(
					'pageTitle' => WCF::getLanguage()->get('wcf.acp.user.sendMail'),
					'url' => $url
				));
				WCF::getTPL()->display('worker');
				exit;
			break;
			
			case 'exportMailAddress':
				WCF::getSession()->checkPermissions(array('admin.user.canMailUser'));
				// send content type
				header('Content-Type: text/'.$this->fileType.'; charset=UTF-8');
				header('Content-Disposition: attachment; filename="export.'.$this->fileType.'"');
				
				if ($this->fileType == 'xml') {
					echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<addresses>\n";
				}
				
				// count users
				$sql = "SELECT		COUNT(*) AS count
					FROM		wcf".WCF_N."_user user
					LEFT JOIN	wcf".WCF_N."_user_option_value option_value
					ON		(option_value.userID = user.userID)
					".$this->conditions;
				$statement = WCF::getDB()->prepareStatement($sql);
				$statement->execute($this->conditions->getParameters());
				$count = $statement->fetchArray();
				
				// get users
				$sql = "SELECT		user.email
					FROM		wcf".WCF_N."_user user
					LEFT JOIN	wcf".WCF_N."_user_option_value option_value
					ON		(option_value.userID = user.userID)
					".$this->conditions."
					ORDER BY	user.email";
				$statement = WCF::getDB()->prepareStatement($sql);
				$statement->execute($this->conditions->getParameters());
				
				$i = 0;
				while ($row = $statement->fetchArray()) {
					if ($this->fileType == 'xml') echo "<address><![CDATA[".StringUtil::escapeCDATA($row['email'])."]]></address>\n";
					else echo $this->textSeparator . $row['email'] . $this->textSeparator . ($i < $count['count'] ? $this->separator : '');
					$i++;
					$this->affectedUsers++;
				}
				
				if ($this->fileType == 'xml') {
					echo "</addresses>";
				}
				$this->saved();
				exit;
			break;
			
			case 'assignToGroup':
				WCF::getSession()->checkPermissions(array('admin.user.canEditUser'));
				
				$userIDArray = $this->fetchUsers(function($userID, array $userData) {
					$user = new UserEditor(new User(null, $userData));
					$user->addToGroups($this->assignToGroupIDArray, false, false);
				});
				
				UserStorageHandler::getInstance()->reset($userIDArray, 'groupIDs', 1);
			break;
			
			case 'delete':
				WCF::getSession()->checkPermissions(array('admin.user.canDeleteUser'));
				
				$userIDArray = $this->fetchUsers();
				
				UserEditor::deleteUsers($userIDArray);
			break;
		}
		$this->saved();
		
		WCF::getTPL()->assign('affectedUsers', $this->affectedUsers);
	}
Esempio n. 30
0
 /**
  * Counts the displayed items.
  * 
  * @return	integer
  */
 public function countItems()
 {
     // call countItems event
     EventHandler::getInstance()->fireAction($this, 'countItems');
     return $this->objectList->countObjects();
 }