本文整理汇总了PHP中Contao\StringUtil类的典型用法代码示例。如果您正苦于以下问题:PHP StringUtil类的具体用法?PHP StringUtil怎么用?PHP StringUtil使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了StringUtil类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: run
/**
* Run the controller and parse the login template
*
* @return Response
*/
public function run()
{
/** @var BackendTemplate|object $objTemplate */
$objTemplate = new \BackendTemplate('be_login');
$strHeadline = sprintf($GLOBALS['TL_LANG']['MSC']['loginTo'], \Config::get('websiteTitle'));
$objTemplate->theme = \Backend::getTheme();
$objTemplate->messages = \Message::generate();
$objTemplate->base = \Environment::get('base');
$objTemplate->language = $GLOBALS['TL_LANGUAGE'];
$objTemplate->languages = \System::getLanguages(true);
$objTemplate->title = \StringUtil::specialchars($strHeadline);
$objTemplate->charset = \Config::get('characterSet');
$objTemplate->action = ampersand(\Environment::get('request'));
$objTemplate->userLanguage = $GLOBALS['TL_LANG']['tl_user']['language'][0];
$objTemplate->headline = $strHeadline;
$objTemplate->curLanguage = \Input::post('language') ?: str_replace('-', '_', $GLOBALS['TL_LANGUAGE']);
$objTemplate->curUsername = \Input::post('username') ?: '';
$objTemplate->uClass = $_POST && empty($_POST['username']) ? ' class="login_error"' : '';
$objTemplate->pClass = $_POST && empty($_POST['password']) ? ' class="login_error"' : '';
$objTemplate->loginButton = \StringUtil::specialchars($GLOBALS['TL_LANG']['MSC']['loginBT']);
$objTemplate->username = $GLOBALS['TL_LANG']['tl_user']['username'][0];
$objTemplate->password = $GLOBALS['TL_LANG']['MSC']['password'][0];
$objTemplate->feLink = $GLOBALS['TL_LANG']['MSC']['feLink'];
$objTemplate->default = $GLOBALS['TL_LANG']['MSC']['default'];
$objTemplate->jsDisabled = $GLOBALS['TL_LANG']['MSC']['jsDisabled'];
return $objTemplate->getResponse();
}
示例2: generate
/**
* Display a wildcard in the back end
*
* @return string
*/
public function generate()
{
if (TL_MODE == 'BE') {
/** @var BackendTemplate|object $objTemplate */
$objTemplate = new \BackendTemplate('be_wildcard');
$objTemplate->wildcard = '### ' . Utf8::strtoupper($GLOBALS['TL_LANG']['FMD']['rssReader'][0]) . ' ###';
$objTemplate->title = $this->headline;
$objTemplate->id = $this->id;
$objTemplate->link = $this->name;
$objTemplate->href = 'contao/main.php?do=themes&table=tl_module&act=edit&id=' . $this->id;
return $objTemplate->parse();
}
$this->objFeed = new \SimplePie();
$arrUrls = \StringUtil::trimsplit('[\\n\\t ]', trim($this->rss_feed));
if (count($arrUrls) > 1) {
$this->objFeed->set_feed_url($arrUrls);
} else {
$this->objFeed->set_feed_url($arrUrls[0]);
}
$this->objFeed->set_output_encoding(\Config::get('characterSet'));
$this->objFeed->set_cache_location(TL_ROOT . '/system/tmp');
$this->objFeed->enable_cache(false);
if ($this->rss_cache > 0) {
$this->objFeed->enable_cache(true);
$this->objFeed->set_cache_duration($this->rss_cache);
}
if (!$this->objFeed->init()) {
$this->log('Error importing RSS feed "' . $this->rss_feed . '"', __METHOD__, TL_ERROR);
return '';
}
$this->objFeed->handle_content_type();
return parent::generate();
}
示例3: compile
/**
* Generate the module
*/
protected function compile()
{
/** @var PageModel $objPage */
global $objPage;
if (!strlen($this->inColumn)) {
$this->inColumn = 'main';
}
$intCount = 0;
$articles = array();
$id = $objPage->id;
$this->Template->request = \Environment::get('request');
// Show the articles of a different page
if ($this->defineRoot && $this->rootPage > 0) {
if (($objTarget = $this->objModel->getRelated('rootPage')) instanceof PageModel) {
$id = $objTarget->id;
/** @var PageModel $objTarget */
$this->Template->request = $objTarget->getFrontendUrl();
}
}
// Get published articles
$objArticles = \ArticleModel::findPublishedByPidAndColumn($id, $this->inColumn);
if ($objArticles === null) {
return;
}
while ($objArticles->next()) {
// Skip first article
if (++$intCount <= intval($this->skipFirst)) {
continue;
}
$cssID = \StringUtil::deserialize($objArticles->cssID, true);
$articles[] = array('link' => $objArticles->title, 'title' => \StringUtil::specialchars($objArticles->title), 'id' => $cssID[0] ?: 'article-' . $objArticles->id, 'articleId' => $objArticles->id);
}
$this->Template->articles = $articles;
}
示例4: split_and_fix
public function split_and_fix($size, $scss, $grid, $width, $paddingTop, $paddingBottom, $default)
{
if ($size == 'XS') {
$grid = '90';
$unitGrid = '%';
$width = '90';
$unitWidth = '%';
} else {
$gridvar = is_array($grid) ? $grid : \Contao\StringUtil::deserialize($grid);
$widthvar = is_array($width) ? $width : \Contao\StringUtil::deserialize($width);
$paddingTopvar = is_array($paddingTop) ? $paddingTop : \Contao\StringUtil::deserialize($paddingTop);
$paddingBottomvar = is_array($paddingBottom) ? $paddingBottom : \Contao\StringUtil::deserialize($paddingBottom);
$grid = empty($gridvar['value']) ? $default['Grid'][$size] : $gridvar['value'];
$unitGrid = empty($gridvar['unit']) ? $default['GridUnit'][$size] : $gridvar['unit'];
$width = empty($widthvar['value']) ? $default['Width'][$size] : $widthvar['value'];
$unitWidth = empty($widthvar['unit']) ? $default['WidthUnit'][$size] : $widthvar['unit'];
}
$paddingTop = empty($paddingTopvar['value']) ? $default['PaddingTop'][$size] : $paddingTopvar['value'];
$unitPadingTop = empty($paddingTopvar['unit']) ? $default['PaddingTopUnit'][$size] : $paddingTopvar['unit'];
$paddingBottom = empty($paddingBottomvar['value']) ? $default['PaddingBottom'][$size] : $paddingBottomvar['value'];
$unitPadingBottom = empty($paddingBottomvar['unit']) ? $default['PaddingBottomUnit'][$size] : $paddingBottomvar['unit'];
$grid1 = (int) $grid - 1;
$scss = str_replace('[[grid' . $size . ']]', $grid . $unitGrid, $scss);
$scss = str_replace('[[grid' . $size . '1]]', $grid1 . $unitGrid, $scss);
$scss = str_replace('[[width' . $size . ']]', $width . $unitWidth, $scss);
$scss = str_replace('[[paddingTop' . $size . ']]', $paddingTop . $unitPadingTop, $scss);
$scss = str_replace('[[paddingBottom' . $size . ']]', $paddingBottom . $unitPadingBottom, $scss);
return $scss;
}
示例5: compile
/**
* Generate the module
*/
protected function compile()
{
$objFaq = \FaqModel::findPublishedByPids($this->faq_categories);
if ($objFaq === null) {
$this->Template->faq = array();
return;
}
$arrFaq = array_fill_keys($this->faq_categories, array());
// Add FAQs
while ($objFaq->next()) {
$arrTemp = $objFaq->row();
$arrTemp['title'] = \StringUtil::specialchars($objFaq->question, true);
$arrTemp['href'] = $this->generateFaqLink($objFaq);
/** @var FaqCategoryModel $objPid */
$objPid = $objFaq->getRelated('pid');
$arrFaq[$objFaq->pid]['items'][] = $arrTemp;
$arrFaq[$objFaq->pid]['headline'] = $objPid->headline;
$arrFaq[$objFaq->pid]['title'] = $objPid->title;
}
$arrFaq = array_values(array_filter($arrFaq));
$cat_count = 0;
$cat_limit = count($arrFaq);
// Add classes
foreach ($arrFaq as $k => $v) {
$count = 0;
$limit = count($v['items']);
for ($i = 0; $i < $limit; $i++) {
$arrFaq[$k]['items'][$i]['class'] = trim((++$count == 1 ? ' first' : '') . ($count >= $limit ? ' last' : '') . ($count % 2 == 0 ? ' odd' : ' even'));
}
$arrFaq[$k]['class'] = trim((++$cat_count == 1 ? ' first' : '') . ($cat_count >= $cat_limit ? ' last' : '') . ($cat_count % 2 == 0 ? ' odd' : ' even'));
}
$this->Template->faq = $arrFaq;
}
示例6: compile
/**
* Generate the module
*/
protected function compile()
{
/** @var PageModel $objPage */
global $objPage;
$arrJumpTo = array();
$arrNewsletter = array();
$strRequest = ampersand(\Environment::get('request'), true);
$objNewsletter = \NewsletterModel::findSentByPids($this->nl_channels);
if ($objNewsletter !== null) {
while ($objNewsletter->next()) {
/** @var NewsletterChannelModel $objTarget */
if (!($objTarget = $objNewsletter->getRelated('pid')) instanceof NewsletterChannelModel) {
continue;
}
$jumpTo = intval($objTarget->jumpTo);
// A jumpTo page is not mandatory for newsletter channels (see #6521) but required for the list module
if ($jumpTo < 1) {
throw new \Exception("Newsletter channels without redirect page cannot be used in a newsletter list");
}
$strUrl = $strRequest;
if (!isset($arrJumpTo[$objTarget->jumpTo])) {
if (($objJumpTo = $objTarget->getRelated('jumpTo')) instanceof PageModel) {
/** @var PageModel $objJumpTo */
$arrJumpTo[$objTarget->jumpTo] = $objJumpTo->getFrontendUrl(\Config::get('useAutoItem') ? '/%s' : '/items/%s');
} else {
$arrJumpTo[$objTarget->jumpTo] = $strUrl;
}
}
$strUrl = $arrJumpTo[$objTarget->jumpTo];
$strAlias = $objNewsletter->alias ?: $objNewsletter->id;
$arrNewsletter[] = array('subject' => $objNewsletter->subject, 'title' => \StringUtil::stripInsertTags($objNewsletter->subject), 'href' => sprintf($strUrl, $strAlias), 'date' => \Date::parse($objPage->dateFormat, $objNewsletter->date), 'datim' => \Date::parse($objPage->datimFormat, $objNewsletter->date), 'time' => \Date::parse($objPage->timeFormat, $objNewsletter->date), 'channel' => $objNewsletter->pid);
}
}
$this->Template->newsletters = $arrNewsletter;
}
示例7: generate
/**
* Display a wildcard in the back end
*
* @return string
*/
public function generate()
{
if (TL_MODE == 'BE') {
/** @var BackendTemplate|object $objTemplate */
$objTemplate = new \BackendTemplate('be_wildcard');
$objTemplate->wildcard = '### ' . Utf8::strtoupper($GLOBALS['TL_LANG']['FMD']['newsarchive'][0]) . ' ###';
$objTemplate->title = $this->headline;
$objTemplate->id = $this->id;
$objTemplate->link = $this->name;
$objTemplate->href = 'contao/main.php?do=themes&table=tl_module&act=edit&id=' . $this->id;
return $objTemplate->parse();
}
$this->news_archives = $this->sortOutProtected(\StringUtil::deserialize($this->news_archives));
// No news archives available
if (!is_array($this->news_archives) || empty($this->news_archives)) {
return '';
}
// Show the news reader if an item has been selected
if ($this->news_readerModule > 0 && (isset($_GET['items']) || \Config::get('useAutoItem') && isset($_GET['auto_item']))) {
return $this->getFrontendModule($this->news_readerModule, $this->strColumn);
}
// Hide the module if no period has been selected
if ($this->news_jumpToCurrent == 'hide_module' && !isset($_GET['year']) && !isset($_GET['month']) && !isset($_GET['day'])) {
return '';
}
return parent::generate();
}
示例8: compile
/**
* Generate the module
*/
protected function compile()
{
/** @var PageModel $objPage */
global $objPage;
// Set the trail and level
if ($this->defineRoot && $this->rootPage > 0) {
$trail = array($this->rootPage);
$level = 0;
} else {
$trail = $objPage->trail;
$level = $this->levelOffset > 0 ? $this->levelOffset : 0;
}
$lang = null;
$host = null;
// Overwrite the domain and language if the reference page belongs to a differnt root page (see #3765)
if ($this->defineRoot && $this->rootPage > 0) {
$objRootPage = \PageModel::findWithDetails($this->rootPage);
// Set the language
if (\Config::get('addLanguageToUrl') && $objRootPage->rootLanguage != $objPage->rootLanguage) {
$lang = $objRootPage->rootLanguage;
}
// Set the domain
if ($objRootPage->rootId != $objPage->rootId && $objRootPage->domain != '' && $objRootPage->domain != $objPage->domain) {
$host = $objRootPage->domain;
}
}
$this->Template->request = ampersand(\Environment::get('indexFreeRequest'));
$this->Template->skipId = 'skipNavigation' . $this->id;
$this->Template->skipNavigation = \StringUtil::specialchars($GLOBALS['TL_LANG']['MSC']['skipNavigation']);
$this->Template->items = $this->renderNavigation($trail[$level], 1, $host, $lang);
}
示例9: write
/**
* {@inheritdoc}
*/
protected function write(array $record)
{
$this->createStatement();
/** @var \DateTime $date */
$date = $record['datetime'];
/** @var ContaoContext $context */
$context = $record['extra']['contao'];
$this->statement->execute(['tstamp' => $date->format('U'), 'text' => StringUtil::specialchars((string) $record['formatted']), 'source' => (string) $context->getSource(), 'action' => (string) $context->getAction(), 'username' => (string) $context->getUsername(), 'func' => (string) $context->getFunc(), 'ip' => (string) $context->getIp(), 'browser' => (string) $context->getBrowser()]);
}
示例10: generate
/**
* Show the raw markdown code in the back end
*
* @return string
*/
public function generate()
{
if (TL_MODE == 'BE') {
$return = '<pre>' . \StringUtil::specialchars($this->code) . '</pre>';
if ($this->headline != '') {
$return = '<' . $this->hl . '>' . $this->headline . '</' . $this->hl . '>' . $return;
}
return $return;
}
return parent::generate();
}
示例11: run
/**
* Run the controller and parse the template
*
* @return Response
*/
public function run()
{
/** @var BackendTemplate|object $objTemplate */
$objTemplate = new \BackendTemplate('be_alerts');
$objTemplate->theme = \Backend::getTheme();
$objTemplate->base = \Environment::get('base');
$objTemplate->language = $GLOBALS['TL_LANGUAGE'];
$objTemplate->title = \StringUtil::specialchars($GLOBALS['TL_LANG']['MSC']['systemMessages']);
$objTemplate->charset = \Config::get('characterSet');
$objTemplate->messages = \Message::generateUnwrapped() . \Backend::getSystemMessages();
return $objTemplate->getResponse();
}
示例12: scopeUuid
public function scopeUuid(Builder $query, $uuid)
{
if (is_array($uuid)) {
$uuid = array_map(function ($uuid) {
return Validator::isStringUuid($uuid) ? StringUtil::uuidToBin($uuid) : $uuid;
}, $uuid);
return $query->whereIn('uuid', $uuid);
}
if (Validator::isStringUuid($uuid)) {
$uuid = StringUtil::uuidToBin($uuid);
}
return $query->where('uuid', $uuid);
}
示例13: setContaoFile
private function setContaoFile($file)
{
if (is_array($file)) {
return serialize(array_map([__CLASS__, 'setContaoFile'], $file));
}
if ($file instanceof FilesModel) {
return $file->uuid;
}
if (Validator::isStringUuid($file)) {
return StringUtil::uuidToBin($file);
}
return $file;
}
示例14: onGeneratePage
/**
* Adds the feeds to the page header.
*
* @param PageModel $objPage
* @param LayoutModel|object $objLayout
*/
public function onGeneratePage(PageModel $objPage, LayoutModel $objLayout)
{
$newsfeeds = StringUtil::deserialize($objLayout->newsfeeds);
if (empty($newsfeeds) || !is_array($newsfeeds)) {
return;
}
$this->framework->initialize();
/** @var NewsFeedModel $adapter */
$adapter = $this->framework->getAdapter(NewsFeedModel::class);
if (!($feeds = $adapter->findByIds($newsfeeds)) instanceof Collection) {
return;
}
$this->addFeedMarkupToPageHeader($feeds);
}
示例15: testExtractEmail
/**
* Tests the StringUtil::extactEmail() method.
*/
public function testExtractEmail()
{
$text = <<<EOF
This is a niceandsimple@example.com and this a very.common@example.com. Another little.lengthy.but.fine@dept.example.com and also a disposable.style.email.with+symbol@example.com or an other.email-with-dash@example.com. There are "very.unusual.@.unusual.com"@example.com and "very.(),:;<>[]\\".VERY.\\"very@\\ \\"very\\".unusual"@strange.example.com and even !#\$%&'*+-/=?^_`{}|~@example.org or "()<>[]:,;@\\"!#\$%&'*+-/=?^_`{}|~.a"@example.org but they are all valid.
IP addresses as in user@[255.255.255.255], user@[IPv6:2001:db8:1ff::a0b:dbd0], user@[IPv6:2001:0db8:85a3:08d3:1319:8a2e:0370:7344], user@[IPv6:2001::7344] or user@[IPv6:1111:2222:3333:4444:5555:6666:255.255.255.255] are valid, too.
We also support IDNA domains as in test@exämple.com, test@ä-.xe, test@subexample.wizard, test@wähwähwäh.ümläüts.de or "tes@t"@wähwähwäh.ümläüts.de. And we support new TLDs as in test@example.photography or test@sub-domain.example.photography.
And we support unicode characters in the local part (RFC 6531) as in niceändsimple@example.com, véry.çommon@example.com, a.lîttle.lengthy.but.fiñe@dept.example.com, dîsposable.style.émail.with+symbol@example.com, other.émail-with-dash@example.com, "verî.uñusual.@.uñusual.com"@example.com, "verî.(),:;<>[]\\".VERÎ.\\"verî@\\ \\"verî\\".unüsual"@strange.example.com, üñîçøðé@example.com, "üñîçøðé"@example.com or DžǼ੧ఘⅧ⒇৪@example.com.
Of course also with IP addresses: üser@[255.255.255.255], üser@[IPv6:2001:db8:1ff::a0b:dbd0], üser@[IPv6:2001:0db8:85a3:08d3:1319:8a2e:0370:7344], üser@[IPv6:2001::7344] or üser@[IPv6:1111:2222:3333:4444:5555:6666:255.255.255.255] and unicode characters in the local part: tést@exämple.com, tést@ä-.xe, tést@subexample.wizard, tést@wähwähwäh.ümläüts.de, "tés@t"@wähwähwäh.ümläüts.de. New TLDs? No problem: tést@example.photography or tést@sub-domain.example.photography.
And hopefully we do not match invalid addresses such as test..child@example.com, test@sub.-example.com, test@_smtp_.example.com, test@sub..example.com, test@subexamplecom, Abc.example.com, a"b(c)d,e:f;gi[j\\k]l@example.com, this is"not\\allowed@example.com, this\\ still\\"not\\allowed@example.com, (comment)test@iana.org, test@[1.2.3.4, @ or test@.
EOF;
$expected = ['niceandsimple@example.com', 'very.common@example.com', 'little.lengthy.but.fine@dept.example.com', 'disposable.style.email.with+symbol@example.com', 'other.email-with-dash@example.com', '"very.unusual.@.unusual.com"@example.com', '"very.(),:;<>[]\\".VERY.\\"very@\\ \\"very\\".unusual"@strange.example.com', '!#$%&\'*+-/=?^_`{}|~@example.org', '"()<>[]:,;@\\"!#$%&\'*+-/=?^_`{}|~.a"@example.org', 'user@[255.255.255.255]', 'user@[IPv6:2001:db8:1ff::a0b:dbd0]', 'user@[IPv6:2001:0db8:85a3:08d3:1319:8a2e:0370:7344]', 'user@[IPv6:2001::7344]', 'user@[IPv6:1111:2222:3333:4444:5555:6666:255.255.255.255]', 'test@exämple.com', 'test@ä-.xe', 'test@subexample.wizard', 'test@wähwähwäh.ümläüts.de', '"tes@t"@wähwähwäh.ümläüts.de', 'test@example.photography', 'test@sub-domain.example.photography', 'niceändsimple@example.com', 'véry.çommon@example.com', 'a.lîttle.lengthy.but.fiñe@dept.example.com', 'dîsposable.style.émail.with+symbol@example.com', 'other.émail-with-dash@example.com', '"verî.uñusual.@.uñusual.com"@example.com', '"verî.(),:;<>[]\\".VERÎ.\\"verî@\\ \\"verî\\".unüsual"@strange.example.com', 'üñîçøðé@example.com', '"üñîçøðé"@example.com', 'DžǼ੧ఘⅧ⒇৪@example.com', 'üser@[255.255.255.255]', 'üser@[IPv6:2001:db8:1ff::a0b:dbd0]', 'üser@[IPv6:2001:0db8:85a3:08d3:1319:8a2e:0370:7344]', 'üser@[IPv6:2001::7344]', 'üser@[IPv6:1111:2222:3333:4444:5555:6666:255.255.255.255]', 'tést@exämple.com', 'tést@ä-.xe', 'tést@subexample.wizard', 'tést@wähwähwäh.ümläüts.de', '"tés@t"@wähwähwäh.ümläüts.de', 'tést@example.photography', 'tést@sub-domain.example.photography'];
$actual = StringUtil::extractEmail($text);
sort($actual);
sort($expected);
$this->assertEquals($expected, $actual);
}