/** * @see \wcf\system\bbcode\IBBCode::getParsedTag() */ public function getParsedTag(array $openingTag, $content, array $closingTag, BBCodeParser $parser) { $src = ''; if (isset($openingTag['attributes'][0])) { $src = $openingTag['attributes'][0]; } if ($parser->getOutputType() == 'text/html') { $float = ''; if (isset($openingTag['attributes'][1])) { $float = $openingTag['attributes'][1]; } $style = ''; if ($float == 'left' || $float == 'right') { $style = 'float: ' . $float . '; margin: ' . ($float == 'left' ? '0 15px 7px 0' : '0 0 7px 15px') . ';'; } $width = 0; if (isset($openingTag['attributes'][2])) { $width = $openingTag['attributes'][2]; $style .= 'width: ' . $width . 'px;'; } return '<img src="' . $src . '" class="jsResizeImage" alt=""' . ($style ? ' style="' . $style . '"' : '') . ' />'; } else { if ($parser->getOutputType() == 'text/simplified-html') { $src = StringUtil::decodeHTML($src); $path = parse_url($src, PHP_URL_PATH); if ($path !== false) { return StringUtil::encodeHTML(basename($path)); } return ''; } } }
/** * @see \wcf\action\IAction::execute(); */ public function execute() { parent::execute(); // header @header('Content-type: text/xml'); // file name @header('Content-disposition: attachment; filename="options.xml"'); // no cache headers @header('Pragma: no-cache'); @header('Expires: 0'); // content echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<options>\n"; $options = Option::getOptions(); foreach ($options as $option) { if ($option->hidden) { continue; } // ignore hidden options echo "\t<option>\n"; echo "\t\t<name><![CDATA[" . StringUtil::escapeCDATA($option->optionName) . "]]></name>\n"; echo "\t\t<value><![CDATA[" . StringUtil::escapeCDATA($option->optionValue) . "]]></value>\n"; echo "\t</option>\n"; } echo '</options>'; $this->executed(); exit; }
/** * @see \wcf\form\IForm::readFormParameters() */ public function readFormParameters() { parent::readFormParameters(); if (isset($_POST['title'])) { $this->title = StringUtil::trim($_POST['title']); } }
/** * Parses search keywords. * * @param string $keywordString */ protected function parseKeywords($keywordString) { // convert encoding if necessary if (!StringUtil::isUTF8($keywordString)) { $keywordString = StringUtil::convertEncoding('ISO-8859-1', 'UTF-8', $keywordString); } // remove bad wildcards $keywordString = preg_replace('/(?<!\\w)\\*/', '', $keywordString); // remove search operators $keywordString = preg_replace('/[\\+\\-><()~]+/', '', $keywordString); if (mb_substr($keywordString, 0, 1) == '"' && mb_substr($keywordString, -1) == '"') { // phrases search $keywordString = StringUtil::trim(mb_substr($keywordString, 1, -1)); if (!empty($keywordString)) { $this->keywords = array_merge($this->keywords, array(StringUtil::encodeHTML($keywordString))); } } else { // replace word delimiters by space $keywordString = str_replace(array('.', ','), ' ', $keywordString); $keywords = ArrayUtil::encodeHTML(ArrayUtil::trim(explode(' ', $keywordString))); if (!empty($keywords)) { $this->keywords = array_merge($this->keywords, $keywords); } } }
/** * Sets element value. * * @param string $value */ public function setValue($value) { if (!is_string($value)) { die(print_r($value, true)); } $this->value = StringUtil::trim($value); }
/** * @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"; } } }
/** * upload an attachment * * @param Integer $forumId * @param String $groupId * @return Object $oMbqEtAtt */ public function uploadAttachment($oMbqEtForum, $groupId = null) { //ref wcf\action\AJAXUploadAction,wcf\action\AJAXProxyAction,wcf\data\attachment\AttachmentAction $parameters['objectType'] = 'com.woltlab.wbb.post'; $parameters['objectID'] = 0; $parameters['tmpHash'] = $groupId ? $groupId : StringUtil::getRandomID(); $parameters['parentObjectID'] = $oMbqEtForum->forumId->oriValue; $parameters['__files'] = UploadHandler::getUploadHandler('attachment'); //ref AJAXUploadAction::readParameters() $oAttachmentAction = new AttachmentAction(array(), 'upload', $parameters); //ref AJAXProxyAction::invoke() $oAttachmentAction->validateAction(); //todo:catch exception $ret = $oAttachmentAction->executeAction(); //todo:catch exception if ($ret['returnValues']['attachments']) { $r = array_shift($ret['returnValues']['attachments']); $oMbqEtAtt = MbqMain::$oClk->newObj('MbqEtAtt'); $oMbqEtAtt->attId->setOriValue($r['attachmentID']); $oMbqEtAtt->groupId->setOriValue($parameters['tmpHash']); $oMbqEtAtt->filtersSize->setOriValue($r['filesize']); $oMbqEtAtt->uploadFileName->setOriValue($r['filename']); return $oMbqEtAtt; } else { MbqError::alert('', "Upload attachment failed!", '', MBQ_ERR_APP); } }
/** * @see \wcf\system\option\user\IUserOptionOutput::getOutput() */ public function getOutput(User $user, UserOption $option, $value) { if (empty($value)) { return ''; } return '<img src="' . StringUtil::encodeHTML($value) . '" alt="" />'; }
/** * @see wcf\system\ICronjob::execute() */ public function execute(Cronjob $cronjob) { $filename = FileUtil::downloadFileFromHttp('http://www.woltlab.com/spiderlist/spiderlist.xml', 'spiders'); $xml = new XML(); $xml->load($filename); $xpath = $xml->xpath(); // fetch spiders $spiders = $xpath->query('/spiderlist/spider'); if (count($spiders)) { // delete old entries $sql = "DELETE FROM wcf" . WCF_N . "_spider"; $statement = WCF::getDB()->prepareStatement($sql); $statement->execute(); $statementParameters = array(); foreach ($spiders as $spider) { $identifier = StringUtil::toLowerCase($spider->getAttribute('ident')); $name = $xpath->query('name', $spider)->item(0); $info = $xpath->query('info', $spider)->item(0); $statementParameters[$identifier] = array('spiderIdentifier' => $identifier, 'spiderName' => $name->nodeValue, 'spiderURL' => $info ? $info->nodeValue : ''); } if (!empty($statementParameters)) { $sql = "INSERT INTO\twcf" . WCF_N . "_spider\n\t\t\t\t\t\t\t(spiderIdentifier, spiderName, spiderURL)\n\t\t\t\t\tVALUES\t\t(?, ?, ?)"; $statement = WCF::getDB()->prepareStatement($sql); foreach ($statementParameters as $parameters) { $statement->execute(array($parameters['spiderIdentifier'], $parameters['spiderName'], $parameters['spiderURL'])); } } // clear spider cache CacheHandler::getInstance()->clear(WCF_DIR . 'cache', 'cache.spiders.php'); } // delete tmp file @unlink($filename); }
/** * Prepares JSON-encoded values for disabling or enabling dependent options. * * @param wcf\data\option\Option $option * @return array */ protected function parseEnableOptions(Option $option) { $disableOptions = $enableOptions = ''; if (!empty($option->enableOptions)) { $options = $option->parseMultipleEnableOptions(); foreach ($options as $key => $optionData) { $tmp = explode(',', $optionData); foreach ($optionData as $item) { if ($item{0} == '!') { if (!empty($disableOptions)) $disableOptions .= ','; $disableOptions .= "{ value: '".$key."', option: '".StringUtil::substring($item, 1)."' }"; } else { if (!empty($enableOptions)) $enableOptions .= ','; $enableOptions .= "{ value: '".$key."', option: '".$item."' }"; } } } } return array( 'disableOptions' => $disableOptions, 'enableOptions' => $enableOptions ); }
/** * @see \wcf\page\IPage::readParameters() */ public function readParameters() { parent::readParameters(); if (isset($_REQUEST['search'])) { $this->search = StringUtil::trim($_REQUEST['search']); } }
/** * @see wcf\system\option\ISearchableUserOption::getCondition() */ public function getCondition(PreparedStatementConditionBuilder &$conditions, Option $option, $value) { $value = StringUtil::trim($value); if (!$value) return false; $conditions->add("option_value.userOption".$option->optionID." = ?", array($value)); return true; }
/** * @see \wcf\system\option\user\IUserOptionOutput::getOutput() */ public function getOutput(User $user, UserOption $option, $value) { if (empty($value) || $value == '0') { $value = 0.0; } return StringUtil::formatDouble($value, 2); }
/** * @see wcf\system\template\IModifierTemplatePlugin::execute() */ public function execute($tagArgs, TemplateEngine $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; } }
/** * Returns all aliases for this smiley. * * @return array<string> */ public function getAliases() { if (!$this->aliases) { return array(); } return explode("\n", StringUtil::unifyNewlines($this->aliases)); }
/** * @see \wcf\data\user\avatar\IUserAvatar::getImageTag() */ public function getImageTag($size = null) { if ($size === null) { $size = $this->size; } return '<img src="' . StringUtil::encodeHTML($this->getURL($size)) . '" style="width: ' . $size . 'px; height: ' . $size . 'px" alt="" class="userAvatarImage" />'; }
/** * Returns the extension of the original file name. * * @return string */ public function getFileExtension() { if (($position = StringUtil::lastIndexOf($this->getFilename(), '.')) !== false) { return StringUtil::toLowerCase(StringUtil::substring($this->getFilename(), $position + 1)); } return ''; }
/** * Validates the access-token and performs the login. */ protected function checkAccessToken() { if (isset($_REQUEST['at'])) { list($userID, $token) = explode('-', StringUtil::trim($_REQUEST['at'])); if (WCF::getUser()->userID) { if ($userID == WCF::getUser()->userID && PasswordUtil::secureCompare(WCF::getUser()->accessToken, $token)) { // everything is fine, but we are already logged in return; } else { // token is invalid throw new IllegalLinkException(); } } else { $user = new User($userID); if (PasswordUtil::secureCompare($user->accessToken, $token)) { // token is valid -> change user SessionHandler::getInstance()->changeUser($user, true); } else { // token is invalid throw new IllegalLinkException(); } } } }
/** * @see \wcf\form\IForm::readFormParameters() */ public function readFormParameters() { parent::readFormParameters(); if (isset($_POST['server'])) { $this->server = StringUtil::trim($_POST['server']); } }
/** * Executes StringUtil::encodeHTML on the given text if disableEncoding is false. * @see \wcf\util\StringUtil::encodeHTML() */ protected function encodeHTML($text) { if (!$this->disableEncoding) { $text = StringUtil::encodeHTML($text); } return $text; }
/** * @see wcf\system\option\IOptionType::getData() */ public function getData(Option $option, $newValue) { $number = StringUtil::replace(WCF::getLanguage()->get('wcf.global.thousandsSeparator'), '', $newValue); $d = preg_quote(WCF::getLanguage()->get('wcf.global.decimalPoint'), '~'); if (!preg_match('~^(?:\d*)(?:'.$d.')?\d+~', $number, $matches)) return 0; $number = $matches[0]; if (preg_match('/[kmgt]i?b$/i', $newValue, $multiplier)) { switch (StringUtil::toLowerCase($multiplier[0])) { case 'tb': $number *= 1000; case 'gb': $number *= 1000; case 'mb': $number *= 1000; case 'kb': $number *= 1000; break; case 'tib': $number *= 1024; case 'gib': $number *= 1024; case 'mib': $number *= 1024; case 'kib': $number *= 1024; break; } } return $number; }
/** * @see wcf\form\IForm::readFormParameters() */ public function readFormParameters() { parent::readFormParameters(); if (isset($_POST['serverURL'])) $this->serverURL = StringUtil::trim($_POST['serverURL']); if (isset($_POST['loginUsername'])) $this->loginUsername = $_POST['loginUsername']; if (isset($_POST['loginPassword'])) $this->loginPassword = $_POST['loginPassword']; }
/** * @see \wcf\system\importer\IImporter::import() */ public function import($oldID, array $data, array $additionalData = array()) { $data['packageID'] = 1; // set temporary option name $data['optionName'] = StringUtil::getRandomID(); if ($data['optionType'] == 'boolean' || $data['optionType'] == 'integer') { if (isset($data['defaultValue'])) { $data['defaultValue'] = intval($data['defaultValue']); } } // create category $this->createCategory($data['categoryName']); // save option $action = new UserOptionAction(array(), 'create', array('data' => $data)); $returnValues = $action->executeAction(); $userOption = $returnValues['returnValues']; // update generic option name $editor = new UserOptionEditor($userOption); $editor->update(array('optionName' => 'option' . $userOption->optionID)); // save name $sql = "INSERT IGNORE INTO\twcf" . WCF_N . "_language_item\n\t\t\t\t\t\t(languageID, languageItem, languageItemValue, languageItemOriginIsSystem, languageCategoryID, packageID)\n\t\t\tVALUES\t\t\t(?, ?, ?, ?, ?, ?)"; $statement = WCF::getDB()->prepareStatement($sql); $statement->execute(array(LanguageFactory::getInstance()->getDefaultLanguageID(), 'wcf.user.option.option' . $userOption->optionID, $additionalData['name'], 0, $this->languageCategoryID, 1)); ImportHandler::getInstance()->saveNewID('com.woltlab.wcf.user.option', $oldID, $userOption->optionID); return $userOption->optionID; }
/** * action implement */ public function actionImplement() { if (!MbqMain::$oMbqConfig->moduleIsEnable('forum')) { MbqError::alert('', "Not support module forum!", '', MBQ_ERR_NOT_SUPPORT); } $forumId = MbqMain::$input['forum_id']; $groupId = MbqMain::$input['group_id'] ? MbqMain::$input['group_id'] : StringUtil::getRandomID(); $oMbqRdEtForum = MbqMain::$oClk->newObj('MbqRdEtForum'); $objsMbqEtForum = $oMbqRdEtForum->getObjsMbqEtForum(array($forumId), array('case' => 'byForumIds')); if ($objsMbqEtForum && ($oMbqEtForum = $objsMbqEtForum[0])) { $oMbqAclEtAtt = MbqMain::$oClk->newObj('MbqAclEtAtt'); if ($oMbqAclEtAtt->canAclUploadAttach($oMbqEtForum)) { //acl judge $oMbqWrEtAtt = MbqMain::$oClk->newObj('MbqWrEtAtt'); $oMbqEtAtt = $oMbqWrEtAtt->uploadAttachment($forumId, $groupId); $oMbqRdEtAtt = MbqMain::$oClk->newObj('MbqRdEtAtt'); $this->data['result'] = true; $data1 = $oMbqRdEtAtt->returnApiDataAttachment($oMbqEtAtt); MbqMain::$oMbqCm->mergeApiData($this->data, $data1); } else { MbqError::alert('', '', '', MBQ_ERR_APP); } } else { MbqError::alert('', "Need valid forum id!", '', MBQ_ERR_APP); } }
/** * @see \wcf\action\IAction::readParameters() */ public function readParameters() { if (!MODULE_POLL) { throw new IllegalLinkException(); } AbstractSecureAction::readParameters(); if (isset($_POST['actionName'])) { $this->actionName = StringUtil::trim($_POST['actionName']); } if (isset($_POST['pollID'])) { $this->pollID = intval($_POST['pollID']); } $polls = PollManager::getInstance()->getPolls(array($this->pollID)); if (!isset($polls[$this->pollID])) { throw new UserInputException('pollID'); } $this->poll = $polls[$this->pollID]; // load related object $this->relatedObject = PollManager::getInstance()->getRelatedObject($this->poll); if ($this->relatedObject === null) { if ($this->poll->objectID) { throw new SystemException("Missing related object for poll id '" . $this->poll->pollID . "'"); } } else { $this->poll->setRelatedObject($this->relatedObject); } // validate action switch ($this->actionName) { case 'getResult': if (!$this->poll->canSeeResult()) { throw new PermissionDeniedException(); } break; case 'getVote': case 'vote': if (!$this->poll->canVote()) { throw new PermissionDeniedException(); } break; default: throw new SystemException("Unknown action '" . $this->actionName . "'"); break; } if (isset($_POST['optionIDs']) && is_array($_POST['optionIDs'])) { $this->optionIDs = ArrayUtil::toIntegerArray($_POST['optionIDs']); if (count($this->optionIDs) > $this->poll->maxVotes) { throw new PermissionDeniedException(); } $optionIDs = array(); foreach ($this->poll->getOptions() as $option) { $optionIDs[] = $option->optionID; } foreach ($this->optionIDs as $optionID) { if (!in_array($optionID, $optionIDs)) { throw new PermissionDeniedException(); } } } }
/** * Cleans up newlines and converts input to lower-case. * * @param string $newValue * @return string */ protected function cleanup($newValue) { $newValue = StringUtil::unifyNewlines($newValue); $newValue = trim($newValue); $newValue = preg_replace('~\\n+~', "\n", $newValue); $newValue = mb_strtolower($newValue); return $newValue; }
/** * @see \wcf\system\package\plugin\AbstractXMLPackageInstallationPlugin::prepareImport() */ protected function prepareImport(array $data) { $data = array('bbcodeTag' => mb_strtolower(StringUtil::trim($data['attributes']['name'])), 'htmlOpen' => !empty($data['elements']['htmlopen']) ? $data['elements']['htmlopen'] : '', 'htmlClose' => !empty($data['elements']['htmlclose']) ? $data['elements']['htmlclose'] : '', 'allowedChildren' => !empty($data['elements']['allowedchildren']) ? $data['elements']['allowedchildren'] : 'all', 'wysiwygIcon' => !empty($data['elements']['wysiwygicon']) ? $data['elements']['wysiwygicon'] : '', 'attributes' => isset($data['elements']['attributes']) ? $data['elements']['attributes'] : array(), 'className' => !empty($data['elements']['classname']) ? $data['elements']['classname'] : '', 'isSourceCode' => !empty($data['elements']['sourcecode']) ? 1 : 0, 'buttonLabel' => isset($data['elements']['buttonlabel']) ? $data['elements']['buttonlabel'] : '', 'originIsSystem' => 1); if ($data['wysiwygIcon'] && $data['buttonLabel']) { $data['showButton'] = 1; } return $data; }
/** * @see wcf\system\option\IOptionType::validate() */ public function validate(Option $option, $newValue) { if ($option->minlength !== null && $option->minlength > StringUtil::length($newValue)) { throw new UserInputException($option->optionName, 'tooShort'); } if ($option->maxlength !== null && $option->maxlength < StringUtil::length($newValue)) { throw new UserInputException($option->optionName, 'tooLong'); } }
/** * @see \wcf\form\IForm::readFormParameters() */ public function readFormParameters() { // call readFormParameters event EventHandler::getInstance()->fireAction($this, 'readFormParameters'); if (isset($_POST['activeTabMenuItem'])) { $this->activeTabMenuItem = StringUtil::trim($_POST['activeTabMenuItem']); } }
/** * @see \wcf\system\option\user\IUserOptionOutput::getOutput() */ public function getOutput(User $user, UserOption $option, $value) { if (empty($value)) { return ''; } $url = StringUtil::encodeHTML('https://plus.google.com/' . $value . '/posts'); $value = StringUtil::encodeHTML($value); return '<a href="' . $url . '" class="externalURL"' . (EXTERNAL_LINK_REL_NOFOLLOW ? ' rel="me nofollow"' : ' rel="me"') . (EXTERNAL_LINK_TARGET_BLANK ? ' target="_blank"' : '') . '>' . $value . '</a>'; }