/**
  * @see TemplatePluginModifier::execute()
  */
 public function execute($tagArgs, Template $tplObj)
 {
     // default values
     $length = 80;
     $etc = '...';
     $breakWords = false;
     // get values
     $string = $tagArgs[0];
     if (isset($tagArgs[1])) {
         $length = intval($tagArgs[1]);
     }
     if (isset($tagArgs[2])) {
         $etc = $tagArgs[2];
     }
     if (isset($tagArgs[3])) {
         $breakWords = $tagArgs[3];
     }
     // execute plugin
     if ($length == 0) {
         return '';
     }
     if (StringUtil::length($string) > $length) {
         $length -= StringUtil::length($etc);
         if (!$breakWords) {
             $string = preg_replace('/\\s+?(\\S+)?$/', '', StringUtil::substring($string, 0, $length + 1));
         }
         return StringUtil::substring($string, 0, $length) . $etc;
     } else {
         return $string;
     }
 }
 /**
  * Checks the condition.
  *
  * @param	PMRuleCondition		$condition
  * @param	string			$string
  * @return	boolean
  */
 protected function checkCondition(PMRuleCondition $condition, $string)
 {
     $value = StringUtil::toLowerCase($condition->ruleConditionValue);
     $string = StringUtil::toLowerCase($string);
     switch ($condition->ruleCondition) {
         case 'contains':
             if (StringUtil::indexOf($string, $value) !== false) {
                 return true;
             }
             break;
         case 'dontContains':
             if (StringUtil::indexOf($string, $value) === false) {
                 return true;
             }
             break;
         case 'beginsWith':
             if (StringUtil::indexOf($string, $value) === 0) {
                 return true;
             }
             break;
         case 'endsWith':
             if (StringUtil::substring($string, -1 * StringUtil::length($value)) == $value) {
                 return true;
             }
             break;
         case 'isEqualTo':
             if ($value == $string) {
                 return true;
             }
             break;
     }
     return false;
 }
 /**
  * @see Form::validate()
  */
 public function validate()
 {
     parent::validate();
     if (empty($this->message)) {
         throw new UserInputException('message');
     }
     if (StringUtil::length($this->message) > WCF::getUser()->getPermission('user.contest.maxSolutionLength')) {
         throw new UserInputException('message', 'tooLong');
     }
 }
 /**
  * Returns an excerpt of this private message.
  * 
  * @return	string
  */
 public function getMessagePreview()
 {
     AttachmentBBCode::setMessageID($this->pmID);
     $parser = MessageParser::getInstance();
     $parser->setOutputType('text/plain');
     $message = $parser->parse($this->message, $this->enableSmilies, $this->enableHtml, $this->enableBBCodes, false);
     if (StringUtil::length($message) > 500) {
         $message = StringUtil::substring($message, 0, 497) . '...';
     }
     return $message;
 }
 /**
  * @see Form::validate()
  */
 public function validate()
 {
     parent::validate();
     if (empty($this->comment)) {
         throw new UserInputException('comment');
     }
     if (StringUtil::length($this->comment) > WCF::getUser()->getPermission('user.contest.maxSolutionLength')) {
         throw new UserInputException('comment', 'tooLong');
     }
     // username
     $this->validateUsername();
 }
 /**
  * Returns an excerpt of the message.
  * 
  * @return	string
  */
 public function getExcerpt()
 {
     $enableSmilies = 1;
     $enableHtml = 0;
     $enableBBCodes = 1;
     MessageParser::getInstance()->setOutputType('text/plain');
     $message = MessageParser::getInstance()->parse($this->comment, $enableSmilies, $enableHtml, $enableBBCodes);
     // get abstract
     if (StringUtil::length($message) > 50) {
         $message = StringUtil::substring($message, 0, 47) . '...';
     }
     return $message;
 }
 /**
  * @see NotificationObject::getTitle()
  */
 public function getTitle()
 {
     $message = $this->getFormattedMessage('text/plain');
     $message = StringUtil::stripHTML($message);
     $message = StringUtil::trim($message);
     if (StringUtil::length($message) > 100) {
         $message = StringUtil::substring($message, 0, 97) . '...';
     }
     if (empty($message)) {
         $message = '#' . $this->entryID;
     }
     return $message;
 }
Пример #8
0
 /**
  * Returns true, if the given name is a valid username.
  * 
  * @param	string		$name		username
  * @return 	boolean
  */
 public static function isValidUsername($name)
 {
     // check illegal characters
     if (!preg_match('!^[^,\\n]+$!', $name)) {
         return false;
     }
     // check long words
     $words = preg_split('!\\s+!', $name, -1, PREG_SPLIT_NO_EMPTY);
     foreach ($words as $word) {
         if (StringUtil::length($word) > 20) {
             return false;
         }
     }
     return true;
 }
 /**
  * Returns an excerpt of the message.
  * 
  * @return	string
  */
 public function getExcerpt()
 {
     // pre-format
     $message = StringUtil::trim(StringUtil::unifyNewlines($this->message));
     // find 1st paragraph
     $excerpt = preg_replace('/^(.*?)\\n\\n.*/s', '$1', $message);
     if (StringUtil::length($excerpt) != StringUtil::length($message)) {
         $this->data['hasMoreText'] = 1;
     }
     // format
     require_once WCF_DIR . 'lib/data/message/bbcode/MessageParser.class.php';
     MessageParser::getInstance()->setOutputType('text/html');
     require_once WCF_DIR . 'lib/data/message/bbcode/AttachmentBBCode.class.php';
     AttachmentBBCode::setMessageID($this->contestID);
     return MessageParser::getInstance()->parse($excerpt, $this->enableSmilies, $this->enableHtml, $this->enableBBCodes);
 }
Пример #10
0
 /**
  * Returns an excerpt of the help item.
  * 
  * @return	string
  */
 public function getExcerpt()
 {
     // get text
     $description = WCF::getLanguage()->getDynamicVariable('wcf.help.item.' . $this->helpItem . '.description');
     // remove headlines
     $description = preg_replace('~<h4>.*?</h4>~', '', $description);
     // remove help images
     $description = preg_replace('~<p class="helpImage.*?</p>~s', '', $description);
     // strip html tags
     $description = strip_tags($description);
     // truncate text
     if (StringUtil::length($description) > 250) {
         $description = preg_replace('/\\s+?(\\S+)?$/', '', StringUtil::substring($description, 0, 251));
         $description = StringUtil::substring($description, 0, 250) . '...';
     }
     return $description;
 }
	/**
	 * @see Form::validate()
	 */
	public function validate() {
		parent::validate();
		
		if (empty($this->pageName))
			throw new UserInputException('pageName', 'empty');
		
		if (!preg_match('/^[a-z0-9_-]+$/i', $this->pageName))
			throw new UserInputException('pageName', 'invalid');
		
		if (StringUtil::length($this->pageName) > 20)
			throw new UserInputException('pageName', 'tooLong');
		
		if (empty($this->menuItem))
			throw new UserInputException('menuItem', 'empty');
		
		if (StringUtil::length($this->menuItem) > 20)
			throw new UserInputException('menuItem', 'tooLong');
	}
 /**
  * autoload method for classname
  *
  * @param 	string		$className
  */
 public function autoload($className)
 {
     if (!isset($className)) {
         throw new SystemException('missing className');
     }
     $className = StringUtil::getClassName($className);
     $dir = StringUtil::toLowercase(StringUtil::substring($className, StringUtil::length('ViewableContest')));
     if (empty($dir)) {
         throw new SystemException('wrong dir: ' . $dir);
     }
     $file = WCF_DIR . 'lib/data/contest/' . $dir . '/' . $className . '.class.php';
     if (!is_file($file)) {
         throw new SystemException('wrong file: ' . $file);
     }
     require_once $file;
     if (!class_exists($className)) {
         throw new SystemException('class does not exist: ' . $className);
     }
 }
 public function __construct($data, $boxname = "")
 {
     $this->threadLastPostsBoxData['templatename'] = "threadlastpostsbox";
     $this->getBoxStatus($data);
     $this->threadLastPostsBoxData['boxID'] = $data['boxID'];
     $cntPosts = 0;
     if (!defined('THREADLASTPOSTSBOX_THREADID')) {
         define('THREADLASTPOSTSBOX_THREADID', 0);
     }
     if (!defined('THREADLASTPOSTSBOX_LIMIT')) {
         define('THREADLASTPOSTSBOX_LIMIT', 10);
     }
     if (!defined('THREADLASTPOSTSBOX_TITLELENGTH')) {
         define('THREADLASTPOSTSBOX_TITLELENGTH', 28);
     }
     if (!defined('THREADLASTPOSTSBOX_SBCOLOR')) {
         define('THREADLASTPOSTSBOX_SBCOLOR', 2);
     }
     require_once WBB_DIR . 'lib/data/board/Board.class.php';
     $boardIDs = Board::getAccessibleBoards();
     if (!empty($boardIDs) && THREADLASTPOSTSBOX_THREADID) {
         $sql = "SELECT wp.postID, wp.threadID, wp.userID, wp.subject, wp.message, wp.time" . "\n  FROM wbb1_1_post wp" . "\n  JOIN wbb1_1_thread wt ON (wt.threadID = wp.threadID)" . "\n WHERE wp.threadID = " . THREADLASTPOSTSBOX_THREADID . "\n   AND wp.isDeleted = 0" . "\n   AND wp.isDisabled = 0" . "\n   AND wt.isDeleted = 0" . "\n   AND wt.isDisabled = 0" . "\n   AND wt.boardID IN (" . $boardIDs . ")" . "\n ORDER BY wp.postID DESC" . "\n  LIMIT 0, " . THREADLASTPOSTSBOX_LIMIT;
         $result = WBBCore::getDB()->sendQuery($sql);
         while ($row = WBBCore::getDB()->fetchArray($result)) {
             if (!empty($row['subject'])) {
                 $title = $row['subject'];
             } else {
                 $title = preg_replace('/\\[/', '<', $row['message']);
                 $title = preg_replace('/\\]/', '>', $title);
                 $title = strip_tags($title);
                 //StringUtil::stripHTML($title);
             }
             if (THREADLASTPOSTSBOX_TITLELENGTH != 0 && StringUtil::length($title) > THREADLASTPOSTSBOX_TITLELENGTH) {
                 $title = StringUtil::substring($title, 0, THREADLASTPOSTSBOX_TITLELENGTH - 3) . '...';
             }
             $row['title'] = StringUtil::encodeHTML($title);
             $this->threadLastPostsBoxData['box'][] = $row;
             $cntPosts++;
         }
     }
     WCF::getTPL()->assign(array('THREADLASTPOSTSBOX_SBCOLOR' => intval(THREADLASTPOSTSBOX_SBCOLOR), 'threadLastPostBoxCnt' => $cntPosts));
 }
 /**
  * @see Form::validate()
  */
 public function validate()
 {
     ACPForm::validate();
     if (empty($this->masterPassword)) {
         throw new UserInputException('masterPassword');
     }
     // check password security
     if (StringUtil::length($this->masterPassword) < 8) {
         throw new UserInputException('masterPassword', 'notSecure');
     }
     // digits
     if (!preg_match('![0-9]+!', $this->masterPassword)) {
         throw new UserInputException('masterPassword', 'notSecure');
     }
     // latin characters (lower-case)
     if (!preg_match('![a-z]+!', $this->masterPassword)) {
         throw new UserInputException('masterPassword', 'notSecure');
     }
     // latin characters (upper-case)
     if (!preg_match('![A-Z]+!', $this->masterPassword)) {
         throw new UserInputException('masterPassword', 'notSecure');
     }
     // special characters
     if (!preg_match('![^A-Za-z0-9]+!', $this->masterPassword)) {
         throw new UserInputException('masterPassword', 'notSecure');
     }
     // search for identical admin passwords
     $sql = "SELECT\tpassword, salt\n\t\t\tFROM\twcf" . WCF_N . "_user\n\t\t\tWHERE\tuserID IN (\n\t\t\t\t\tSELECT\tuserID\n\t\t\t\t\tFROM\twcf" . WCF_N . "_user_to_groups\n\t\t\t\t\tWHERE\tgroupID = 4\n\t\t\t\t)";
     $result = WCF::getDB()->sendQuery($sql);
     while ($row = WCF::getDB()->fetchArray($result)) {
         if (StringUtil::getDoubleSaltedHash($this->masterPassword, $row['salt']) == $row['password']) {
             throw new UserInputException('masterPassword', 'notSecure');
         }
     }
     // confirm master password
     if (empty($this->confirmMasterPassword)) {
         throw new UserInputException('confirmMasterPassword');
     }
     if ($this->confirmMasterPassword != $this->masterPassword) {
         throw new UserInputException('confirmMasterPassword', 'notEqual');
     }
 }
 /**
  * Returns true, if the given password is secure.
  * 
  * @param	string		$password
  * @return 	boolean
  */
 public static function isSecurePassword($password)
 {
     if (REGISTER_ENABLE_PASSWORD_SECURITY_CHECK) {
         if (StringUtil::length($password) < REGISTER_PASSWORD_MIN_LENGTH) {
             return false;
         }
         if (REGISTER_PASSWORD_MUST_CONTAIN_DIGIT && !preg_match('![0-9]+!', $password)) {
             return false;
         }
         if (REGISTER_PASSWORD_MUST_CONTAIN_LOWER_CASE && !preg_match('![a-z]+!', $password)) {
             return false;
         }
         if (REGISTER_PASSWORD_MUST_CONTAIN_UPPER_CASE && !preg_match('![A-Z]+!', $password)) {
             return false;
         }
         if (REGISTER_PASSWORD_MUST_CONTAIN_SPECIAL_CHAR && !preg_match('![^A-Za-z0-9]+!', $password)) {
             return false;
         }
     }
     return true;
 }
Пример #16
0
 /**
  * @see BBCode::getParsedTag()
  */
 public function getParsedTag($openingTag, $content, $closingTag, BBCodeParser $parser)
 {
     $url = '';
     if (isset($openingTag['attributes'][0])) {
         $url = $openingTag['attributes'][0];
     }
     $noTitle = $content == $url;
     // add protocol if necessary
     if (!preg_match("/[a-z]:\\/\\//si", $url)) {
         $url = 'http://' . $url;
     }
     if ($parser->getOutputType() == 'text/html') {
         $external = true;
         if (($newURL = $this->isInternalURL($url)) !== false) {
             $url = $newURL;
             $external = false;
         }
         // cut visible url
         if ($noTitle) {
             $decodedContent = StringUtil::decodeHTML($content);
             if (StringUtil::length($decodedContent) > 60) {
                 $content = StringUtil::encodeHTML(StringUtil::substring($decodedContent, 0, 40)) . '&hellip;' . StringUtil::encodeHTML(StringUtil::substring($decodedContent, -15));
             }
         } else {
             $content = StringUtil::trim($content);
         }
         return '<a href="' . $url . '"' . ($external ? ' class="externalURL"' : '') . '>' . $content . '</a>';
     } else {
         if ($parser->getOutputType() == 'text/plain') {
             if ($noTitle) {
                 return $url;
             }
             return $content . ': ' . $url;
         }
     }
 }
 /**
  * Process configured dates with plaintext names, dashed ranges and slashed intervals.
  * 
  * @param	array		$cronjobsCache
  */
 protected function processConfiguredDates($cronjobsCache = array())
 {
     // get arrays containing the configured dates from our database (or, respectively, the cache).
     $this->cronjobsDataRaw['startMinute'] = explode(',', $cronjobsCache['startMinute']);
     $this->cronjobsDataRaw['startHour'] = explode(',', $cronjobsCache['startHour']);
     $this->cronjobsDataRaw['startDom'] = explode(',', $cronjobsCache['startDom']);
     $this->cronjobsDataRaw['startMonth'] = explode(',', $cronjobsCache['startMonth']);
     $this->cronjobsDataRaw['startDow'] = explode(',', $cronjobsCache['startDow']);
     // process plaintext month and day of week values.
     foreach ($this->cronjobsDataRaw as $element => $datesRaw) {
         foreach ($datesRaw as $position => $dateRaw) {
             switch ($element) {
                 // months.
                 case 'startMonth':
                     $datesPlain = array('jan', 'feb', 'mar', 'apr', 'may', 'jun', 'jul', 'aug', 'sep', 'oct', 'nov', 'dec');
                     break;
                     // days of week.
                 // days of week.
                 case 'startDow':
                     // for us, the week begins on sunday because date() wants us to think that way.
                     $datesPlain = array('sun', 'mon', 'tue', 'wed', 'thu', 'fri', 'sat');
                     break;
                     // nothing to do for the others.
                 // nothing to do for the others.
                 default:
                     break;
             }
             // if $dateRaw is a time range expressed with a dash, a special handling is needed.
             if (StringUtil::indexOf($dateRaw, '-')) {
                 // dismantle the range into an array.
                 $range = explode('-', $dateRaw);
                 // investigate the new array.
                 foreach ($range as $key => $value) {
                     $slashPos = StringUtil::indexOf($value, '/');
                     if (StringUtil::length($value) == 3 && $slashPos === false) {
                         // this is a plaintext name, so convert this into a number.
                         $datePlain = StringUtil::toLowerCase($value);
                         $dateNum = array_search($datePlain, $datesPlain);
                         // put the converted value back to the array.
                         if ($dateNum !== false) {
                             $range[$key] = $dateNum;
                         }
                     } else {
                         if ($slashPos !== false) {
                             // this value additionally contains a slashed interval,
                             // so once again part this value.
                             $interval = explode('/', $value);
                             if (StringUtil::length($interval['0']) == 3) {
                                 // this is a plaintext name, so convert this into a number.
                                 $datePlain = StringUtil::toLowerCase($interval['0']);
                                 $dateNum = array_search($datePlain, $datesPlain);
                                 if ($dateNum !== false) {
                                     $range[$key] = $dateNum;
                                 }
                             } else {
                                 $range[$key] = $interval['0'];
                             }
                             $range[$key + 1] = $interval['1'];
                         }
                     }
                 }
                 // reassemble array.
                 foreach ($range as $key => $digit) {
                     $range[$key] = intval($digit);
                 }
                 $newPos = array_search($dateRaw, $this->cronjobsDataRaw[$element]);
                 $this->cronjobsDataRaw[$element][$newPos] = $range;
                 $this->getDashedRange($element, $newPos);
             } else {
                 // this is no range.
                 $slashPos = StringUtil::indexOf($dateRaw, '/');
                 if (StringUtil::length($dateRaw) == 3 && $slashPos === false) {
                     // this is a plaintext name, so convert this into a number.
                     $datePlain = StringUtil::toLowerCase($dateRaw);
                     $dateNum = array_search($datePlain, $datesPlain);
                     // put the converted value back to the original array.
                     if ($dateNum !== false) {
                         $this->cronjobsDataRaw[$element][$position] = $dateNum;
                     }
                 } else {
                     if ($slashPos !== false) {
                         // this value additionally contains a slashed interval,
                         // so once again part this value.
                         $interval = explode('/', $dateRaw);
                         // put parted value back to array.
                         unset($this->cronjobsDataRaw[$element][$position]);
                         $this->cronjobsDataRaw[$element][$position][] = $interval['0'];
                         $this->cronjobsDataRaw[$element][$position][] = $interval['1'];
                         // break down slashed interval.
                         $this->getSlashedInterval($element, $position);
                     }
                 }
             }
         }
     }
 }
 /**
  * @see Form::validate()
  */
 public function validate()
 {
     if (!count($this->groupIDs)) {
         throw new UserInputException('groupIDs', 'empty');
     }
     if (!@is_int($this->maxLifeTime)) {
         throw new UserInputException('maxLifeTime', 'isNoInteger');
     }
     if (empty($this->subject)) {
         throw new UserInputException('subject', 'empty');
     }
     if (empty($this->text)) {
         throw new UserInputException('text', 'empty');
     } else {
         if (StringUtil::length($this->text) > $this->maxTextLength) {
             throw new UserInputException('text', 'tooLong');
         } else {
             if (defined('ENABLE_CENSORSHIP') && ENABLE_CENSORSHIP) {
                 require_once WCF_DIR . 'lib/data/message/censorship/Censorship.class.php';
                 $result = Censorship::test($this->text);
                 if ($result) {
                     WCF::getTPL()->assign('censoredWords', $result);
                     throw new UserInputException('text', 'censoredWordsFound');
                 }
             }
         }
     }
     parent::validate();
 }
 private static function parseURLsCallback($matches)
 {
     $url = $title = $matches[0];
     $decodedTitle = StringUtil::decodeHTML($title);
     if (StringUtil::length($decodedTitle) > 60) {
         $title = StringUtil::encodeHTML(StringUtil::substring($decodedTitle, 0, 40)) . '&hellip;' . StringUtil::encodeHTML(StringUtil::substring($decodedTitle, -15));
     }
     // add protocol if necessary
     if (!preg_match("/[a-z]:\\/\\//si", $url)) {
         $url = 'http://' . $url;
     }
     $external = true;
     if (($newURL = self::isInternalURL($url)) !== false) {
         $url = $newURL;
         $external = false;
     }
     return '<a href="' . $url . '"' . ($external ? ' class="externalURL"' : '') . '>' . $title . '</a>';
 }
 /**
  * Validates message text.
  */
 protected function validateText()
 {
     if (empty($this->text)) {
         throw new UserInputException('text');
     }
     // check text length
     if ($this->maxTextLength !== null && StringUtil::length($this->text) > $this->maxTextLength) {
         throw new UserInputException('text', 'tooLong');
     }
     // search for censored words
     if (ENABLE_CENSORSHIP) {
         require_once WCF_DIR . 'lib/data/message/censorship/Censorship.class.php';
         $result = Censorship::test($this->text);
         if ($result) {
             WCF::getTPL()->assign('censoredWords', $result);
             throw new UserInputException('text', 'censoredWordsFound');
         }
     }
 }
 /**
  * @see Form::validate()
  */
 public function validate()
 {
     parent::validate();
     if (empty($this->subject)) {
         throw new UserInputException('subject');
     }
     if (empty($this->text)) {
         throw new UserInputException('text');
     }
     if (StringUtil::length($this->text) > WCF::getUser()->getPermission('user.contest.maxSolutionLength')) {
         throw new UserInputException('text', 'tooLong');
     }
     if (StringUtil::length($this->secretMessage) > WCF::getUser()->getPermission('user.contest.maxSolutionLength')) {
         throw new UserInputException('secretMessage', 'tooLong');
     }
     if ($this->groupID) {
         $this->ownerGroups = ContestUtil::readAvailableGroups();
         // validate group ids
         if (!array_key_exists($this->groupID, $this->ownerGroups)) {
             throw new UserInputException('ownerID');
         }
     }
     if ($this->sponsorID) {
         if (!$this->contest->isOwner() && !ContestCrew::isMember()) {
             throw new UserInputException('ownerID');
         }
         $this->ownerSponsors = array();
         if ($this->contest->isOwner() || ContestCrew::isMember()) {
             foreach ($this->contest->getSponsors() as $sponsor) {
                 $this->ownerSponsors[$sponsor->sponsorID] = $sponsor;
             }
         }
         // validate group ids
         if (!array_key_exists($this->sponsorID, $this->ownerSponsors)) {
             throw new UserInputException('ownerID');
         }
     }
     if (!array_key_exists($this->state, $this->getStates())) {
         throw new UserInputException('state');
     }
 }
 private function addLine($string)
 {
     // wrap text
     if (StringUtil::length($string) > 75) {
         $string = StringUtil::splitIntoChunks($string, 75, "\r\n ");
     }
     $this->add($string . "\r\n");
 }
 /**
  * @see Form::validate()
  */
 public function validate()
 {
     parent::validate();
     if (empty($this->query)) {
         throw new UserInputException('query');
     }
     if (StringUtil::length($this->query) < 3 || strpos($this->query, '%') !== false || strpos($this->query, '_') !== false) {
         throw new UserInputException('query', 'invalid');
     }
     // search
     $itemNames = array();
     $sql = "SELECT\tlanguageItem\n\t\t\tFROM\twcf" . WCF_N . "_language_item\n\t\t\tWHERE\tlanguageID = " . WCF::getLanguage()->getLanguageID() . "\n\t\t\t\tAND languageCategoryID = (\n\t\t\t\t\tSELECT\tlanguageCategoryID\n\t\t\t\t\tFROM\twcf" . WCF_N . "_language_category\n\t\t\t\t\tWHERE\tlanguageCategory = 'wcf.help.item'\n\t\t\t\t)\n\t\t\t\tAND packageID IN (\n\t\t\t\t\tSELECT\tdependency\n\t\t\t\t\tFROM\twcf" . WCF_N . "_package_dependency\n\t\t\t\t\tWHERE\tpackageID = " . PACKAGE_ID . "\n\t\t\t\t)\n\t\t\t\tAND (\n\t\t\t\t\t(languageUseCustomValue = 0 AND languageItemValue LIKE '%" . escapeString($this->query) . "%')\n\t\t\t\t\tOR (languageUseCustomValue = 1 AND languageCustomItemValue LIKE '%" . escapeString($this->query) . "%')\n\t\t\t\t)";
     $result = WCF::getDB()->sendQuery($sql, 1000);
     while ($row = WCF::getDB()->fetchArray($result)) {
         // search parsed variables
         try {
             $languageItemValue = WCF::getLanguage()->getDynamicVariable($row['languageItem']);
             if (preg_match('!' . preg_quote($this->query) . '!i', $languageItemValue)) {
                 $itemNames[] = str_replace('.description', '', str_replace('wcf.help.item.', '', $row['languageItem']));
             }
         } catch (SystemException $e) {
         }
         // ignore errors
     }
     if (!count($itemNames)) {
         throw new NamedUserException(WCF::getLanguage()->get('wcf.help.search.error.noMatches', array('$query' => StringUtil::encodeHTML($this->query))));
     }
     // get help items
     $sql = "SELECT\t\thelpItem, permissions, options\n\t\t\tFROM\t\twcf" . WCF_N . "_help_item\n\t\t\tWHERE\t\thelpItem IN ('" . implode("','", $itemNames) . "')\n\t\t\t\t\tAND isDisabled = 0\n\t\t\tORDER BY\tshowOrder";
     $result = WCF::getDB()->sendQuery($sql);
     while ($row = WCF::getDB()->fetchArray($result)) {
         // check options
         if (!empty($row['options'])) {
             $hasEnabledOption = false;
             $options = explode(',', strtoupper($row['options']));
             foreach ($options as $option) {
                 if (defined($option) && constant($option)) {
                     $hasEnabledOption = true;
                     break;
                 }
             }
             if (!$hasEnabledOption) {
                 continue;
             }
         }
         // check permissions
         if (!empty($row['permissions'])) {
             $hasPermission = false;
             $permissions = explode(',', $row['permissions']);
             foreach ($permissions as $permission) {
                 if (WCF::getUser()->getPermission($permission)) {
                     $hasPermission = true;
                     break;
                 }
             }
             if (!$hasPermission) {
                 continue;
             }
         }
         $this->result[] = $row['helpItem'];
     }
     if (!count($this->result)) {
         throw new NamedUserException(WCF::getLanguage()->get('wcf.help.search.error.noMatches', array('$query' => StringUtil::encodeHTML($this->query))));
     }
 }
 /**
  * Validates message text.
  */
 protected function validateText()
 {
     parent::validateText();
     // check text length
     if ($this->minCharLength > 0 && StringUtil::length($this->text) < $this->minCharLength) {
         throw new UserInputException('text', 'tooShort');
     }
     // check word count
     if ($this->minWordCount > 0 && count(preg_split('/[\\W]+/', $this->text, -1, PREG_SPLIT_NO_EMPTY)) < $this->minWordCount) {
         throw new UserInputException('text', 'tooShort');
     }
 }
 /**
  * Returns html entities of all characters in the given string.
  * 
  * @param	string		$string
  * @return	string
  */
 public static function encodeAllChars($string)
 {
     $result = '';
     for ($i = 0, $j = StringUtil::length($string); $i < $j; $i++) {
         $char = StringUtil::substring($string, $i, 1);
         $result .= '&#' . (USE_MBSTRING ? StringUtil::getCharValue($char) : ord($char)) . ';';
     }
     return $result;
 }
 /**
  * @see NotificationObject::getTitle()
  */
 public function getTitle()
 {
     $substring = StringUtil::substring($this->className, StringUtil::length('Contest'));
     return $substring;
 }
 /**
  * Builds a bbcode tag.
  * 
  * @param	string		$string
  * @return	array		bbcode tag data
  */
 protected function buildTag($string)
 {
     $tag = array('name' => '', 'closing' => false, 'source' => $string);
     if (StringUtil::substring($string, 1, 1) == '/') {
         // closing tag
         $tag['name'] = StringUtil::toLowerCase(StringUtil::substring($string, 2, StringUtil::length($string) - 3));
         $tag['closing'] = true;
     } else {
         // opening tag
         // split tag and attributes
         preg_match("!^\\[([a-z0-9]+)=?(.*)]\$!si", $string, $match);
         $tag['name'] = StringUtil::toLowerCase($match[1]);
         // build attributes
         if (!empty($match[2])) {
             $tag['attributes'] = $this->buildTagAttributes($match[2]);
         }
     }
     return $tag;
 }
Пример #28
0
 /**
  * Adds tags to a tagged object.
  * 
  * @param 	array 		$tags 		array holding tag names
  * @param 	Tagged 		$object 	object that should be tagged
  */
 public function addTags($tags, Tagged $object, $languageID = 0)
 {
     $tagIDs = array();
     foreach ($tags as $tag) {
         if (empty($tag)) {
             continue;
         }
         $tagID = Tag::test($tag, $languageID);
         if (!$tagID) {
             $tagID = Tag::insert($tag, $languageID);
         }
         $tagIDs[] = $tagID;
     }
     $tagIDs = array_unique($tagIDs);
     $sql = "INSERT INTO\twcf" . WCF_N . "_tag_to_object\n\t\t\t\t\t(objectID, tagID, taggableID, time, languageID)\n\t\t\tVALUES ";
     foreach ($tagIDs as $tagID) {
         $sql .= "(" . $object->getObjectID() . ", " . $tagID . ", " . $object->getTaggable()->getTaggableID() . ", " . TIME_NOW . ", " . $languageID . "),";
     }
     $sql = StringUtil::substring($sql, 0, StringUtil::length($sql) - 1);
     $result = WCF::getDB()->sendQuery($sql);
 }
 /**
  * Sends the email notification.
  */
 public function sendNotification($post = null, $attachmentList = null)
 {
     $sql = "SELECT\t\tuser.*\n\t\t\tFROM\t\twbb" . WBB_N . "_board_subscription subscription\n\t\t\tLEFT JOIN\twcf" . WCF_N . "_user user\n\t\t\tON\t\t(user.userID = subscription.userID)\n\t\t\tWHERE\t\tsubscription.boardID = " . $this->boardID . "\n\t\t\t\t\tAND subscription.enableNotification = 1\n\t\t\t\t\tAND subscription.emails = 0\n\t\t\t\t\tAND subscription.userID <> " . $this->userID . "\n\t\t\t\t\tAND user.userID IS NOT NULL";
     $result = WCF::getDB()->sendQuery($sql);
     if (WCF::getDB()->countRows($result)) {
         // get first post
         if ($post === null) {
             require_once WBB_DIR . 'lib/data/post/Post.class.php';
             $post = new Post($this->firstPostID);
         }
         // get attachments
         if ($attachmentList === null) {
             require_once WCF_DIR . 'lib/data/attachment/MessageAttachmentList.class.php';
             $attachmentList = new MessageAttachmentList($this->firstPostID);
             $attachmentList->readObjects();
         }
         // set attachments
         require_once WCF_DIR . 'lib/data/message/bbcode/AttachmentBBCode.class.php';
         AttachmentBBCode::setAttachments($attachmentList->getSortedAttachments());
         // parse text
         require_once WCF_DIR . 'lib/data/message/bbcode/MessageParser.class.php';
         $parser = MessageParser::getInstance();
         $parser->setOutputType('text/plain');
         $parsedText = $parser->parse($post->message, $post->enableSmilies, $post->enableHtml, $post->enableBBCodes, false);
         // truncate message
         if (!POST_NOTIFICATION_SEND_FULL_MESSAGE && StringUtil::length($parsedText) > 500) {
             $parsedText = StringUtil::substring($parsedText, 0, 500) . '...';
         }
         // send notifications
         $languages = array();
         $languages[WCF::getLanguage()->getLanguageID()] = WCF::getLanguage();
         $languages[0] = WCF::getLanguage();
         require_once WCF_DIR . 'lib/data/mail/Mail.class.php';
         require_once WCF_DIR . 'lib/data/user/User.class.php';
         require_once WBB_DIR . 'lib/data/board/Board.class.php';
         $board = Board::getBoard($this->boardID);
         while ($row = WCF::getDB()->fetchArray($result)) {
             $recipient = new User(null, $row);
             // get language
             if (!isset($languages[$recipient->languageID])) {
                 $languages[$recipient->languageID] = new Language($recipient->languageID);
             }
             // enable language
             $languages[$recipient->languageID]->setLocale();
             // send mail
             $data = array('PAGE_TITLE' => $languages[$recipient->languageID]->get(PAGE_TITLE), 'PAGE_URL' => PAGE_URL, '$recipient' => $recipient->username, '$author' => $this->username, '$boardTitle' => $languages[$recipient->languageID]->get($board->title), '$topic' => $this->topic, '$threadID' => $this->threadID, '$text' => $parsedText);
             $mail = new Mail(array($recipient->username => $recipient->email), $languages[$recipient->languageID]->get('wbb.threadAdd.notification.subject', array('$title' => $languages[$recipient->languageID]->get($board->title))), $languages[$recipient->languageID]->get('wbb.threadAdd.notification.mail', $data));
             $mail->send();
         }
         // enable user language
         WCF::getLanguage()->setLocale();
         // update notification count
         $sql = "UPDATE\twbb" . WBB_N . "_board_subscription\n\t\t\t\tSET \temails = emails + 1\n\t\t\t\tWHERE\tboardID = " . $this->boardID . "\n\t\t\t\t\tAND enableNotification = 1\n\t\t\t\t\tAND emails = 0";
         WCF::getDB()->registerShutdownUpdate($sql);
     }
 }
 /**
  * Compiles a template tag.
  * 
  * @param	string		$tag
  */
 protected function compileTag($tag)
 {
     if (preg_match('~^' . $this->outputPattern . '~s', $tag)) {
         // variable output
         return $this->compileOutputTag($tag);
     }
     $match = array();
     // replace 'else if' with 'elseif'
     $tag = preg_replace('~^else\\s+if(?=\\s)~i', 'elseif', $tag);
     if (preg_match('~^(/?\\w+)~', $tag, $match)) {
         // build in function or plugin
         $tagCommand = $match[1];
         $tagArgs = StringUtil::substring($tag, StringUtil::length($tagCommand));
         switch ($tagCommand) {
             case 'if':
                 $this->pushTag('if');
                 return $this->compileIfTag($tagArgs);
             case 'elseif':
                 list($openTag) = end($this->tagStack);
                 if ($openTag != 'if' && $openTag != 'elseif') {
                     throw new SystemException($this->formatSyntaxError('unxepected {elseif}', $this->currentIdentifier, $this->currentLineNo));
                 } else {
                     if ($openTag == 'if') {
                         $this->pushTag('elseif');
                     }
                 }
                 return $this->compileIfTag($tagArgs, true);
             case 'else':
                 list($openTag) = end($this->tagStack);
                 if ($openTag != 'if' && $openTag != 'elseif') {
                     throw new SystemException($this->formatSyntaxError('unexpected {else}', $this->currentIdentifier, $this->currentLineNo));
                 } else {
                     $this->pushTag('else');
                     return '<?php } else { ?>';
                 }
             case '/if':
                 list($openTag) = end($this->tagStack);
                 if ($openTag != 'if' && $openTag != 'elseif' && $openTag != 'else') {
                     throw new SystemException($this->formatSyntaxError('unexpected {/if}', $this->currentIdentifier, $this->currentLineNo));
                 } else {
                     $this->popTag('if');
                 }
                 return '<?php } ?>';
             case 'include':
                 return $this->compileIncludeTag($tagArgs);
             case 'foreach':
                 $this->pushTag('foreach');
                 return $this->compileForeachTag($tagArgs);
             case 'foreachelse':
                 list($openTag) = end($this->tagStack);
                 if ($openTag != 'foreach') {
                     throw new SystemException($this->formatSyntaxError('unexpected {foreachelse}', $this->currentIdentifier, $this->currentLineNo));
                 } else {
                     $this->pushTag('foreachelse');
                     return '<?php } } else { { ?>';
                 }
             case '/foreach':
                 $this->popTag('foreach');
                 return "<?php } } ?>";
             case 'section':
                 $this->pushTag('section');
                 return $this->compileSectionTag($tagArgs);
             case 'sectionelse':
                 list($openTag) = end($this->tagStack);
                 if ($openTag != 'section') {
                     throw new SystemException($this->formatSyntaxError('unexpected {sectionelse}', $this->currentIdentifier, $this->currentLineNo));
                 } else {
                     $this->pushTag('sectionelse');
                     return '<?php } } else { { ?>';
                 }
             case '/section':
                 $this->popTag('section');
                 return "<?php } } ?>";
             case 'capture':
                 $this->pushTag('capture');
                 return $this->compileCaptureTag(true, $tagArgs);
             case '/capture':
                 $this->popTag('capture');
                 return $this->compileCaptureTag(false);
             case 'ldelim':
                 return $this->leftDelimiter;
             case 'rdelim':
                 return $this->rightDelimiter;
             default:
                 // 1) compiler functions first
                 if ($phpCode = $this->compileCompilerPlugin($tagCommand, $tagArgs)) {
                     return $phpCode;
                 }
                 // 2) block functions
                 if ($phpCode = $this->compileBlockPlugin($tagCommand, $tagArgs)) {
                     return $phpCode;
                 }
                 // 3) functions
                 if ($phpCode = $this->compileFunctionPlugin($tagCommand, $tagArgs)) {
                     return $phpCode;
                 }
         }
     }
     throw new SystemException($this->formatSyntaxError('unknown tag {' . $tag . '}', $this->currentIdentifier, $this->currentLineNo), 12003);
 }