本文整理汇总了PHP中wcf\util\StringUtil类的典型用法代码示例。如果您正苦于以下问题:PHP StringUtil类的具体用法?PHP StringUtil怎么用?PHP StringUtil使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了StringUtil类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getParsedTag
/**
* @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 '';
}
}
}
示例2: execute
/**
* @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;
}
示例3: readFormParameters
/**
* @see \wcf\form\IForm::readFormParameters()
*/
public function readFormParameters()
{
parent::readFormParameters();
if (isset($_POST['title'])) {
$this->title = StringUtil::trim($_POST['title']);
}
}
示例4: parseKeywords
/**
* 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);
}
}
}
示例5: setValue
/**
* Sets element value.
*
* @param string $value
*/
public function setValue($value)
{
if (!is_string($value)) {
die(print_r($value, true));
}
$this->value = StringUtil::trim($value);
}
示例6: getParsedTag
/**
* @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";
}
}
}
示例7: uploadAttachment
/**
* 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);
}
}
示例8: getOutput
/**
* @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="" />';
}
示例9: execute
/**
* @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);
}
示例10: parseEnableOptions
/**
* 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
);
}
示例11: readParameters
/**
* @see \wcf\page\IPage::readParameters()
*/
public function readParameters()
{
parent::readParameters();
if (isset($_REQUEST['search'])) {
$this->search = StringUtil::trim($_REQUEST['search']);
}
}
示例12: getCondition
/**
* @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;
}
示例13: getOutput
/**
* @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);
}
示例14: execute
/**
* @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;
}
}
示例15: getAliases
/**
* Returns all aliases for this smiley.
*
* @return array<string>
*/
public function getAliases()
{
if (!$this->aliases) {
return array();
}
return explode("\n", StringUtil::unifyNewlines($this->aliases));
}