本文整理汇总了PHP中StringUtil::substrHtml方法的典型用法代码示例。如果您正苦于以下问题:PHP StringUtil::substrHtml方法的具体用法?PHP StringUtil::substrHtml怎么用?PHP StringUtil::substrHtml使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类StringUtil
的用法示例。
在下文中一共展示了StringUtil::substrHtml方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: listView
//.........这里部分代码省略.........
list($strTable, $strField) = explode('.', $strTable);
$objRef = $this->Database->prepare("SELECT " . $strField . " FROM " . $strTable . " WHERE id=?")->limit(1)->execute($row[$strKey]);
$args[$k] = $objRef->numRows ? $objRef->{$strField} : '';
} elseif (in_array($GLOBALS['TL_DCA'][$this->strTable]['fields'][$v]['flag'], array(5, 6, 7, 8, 9, 10))) {
if ($GLOBALS['TL_DCA'][$this->strTable]['fields'][$v]['eval']['rgxp'] == 'date') {
$args[$k] = $row[$v] ? \Date::parse(\Config::get('dateFormat'), $row[$v]) : '-';
} elseif ($GLOBALS['TL_DCA'][$this->strTable]['fields'][$v]['eval']['rgxp'] == 'time') {
$args[$k] = $row[$v] ? \Date::parse(\Config::get('timeFormat'), $row[$v]) : '-';
} else {
$args[$k] = $row[$v] ? \Date::parse(\Config::get('datimFormat'), $row[$v]) : '-';
}
} elseif ($GLOBALS['TL_DCA'][$this->strTable]['fields'][$v]['inputType'] == 'checkbox' && !$GLOBALS['TL_DCA'][$this->strTable]['fields'][$v]['eval']['multiple']) {
$args[$k] = $row[$v] != '' ? $GLOBALS['TL_LANG']['MSC']['yes'] : $GLOBALS['TL_LANG']['MSC']['no'];
} else {
$row_v = deserialize($row[$v]);
if (is_array($row_v)) {
$args_k = array();
foreach ($row_v as $option) {
$args_k[] = $GLOBALS['TL_DCA'][$table]['fields'][$v]['reference'][$option] ?: $option;
}
$args[$k] = implode(', ', $args_k);
} elseif (isset($GLOBALS['TL_DCA'][$table]['fields'][$v]['reference'][$row[$v]])) {
$args[$k] = is_array($GLOBALS['TL_DCA'][$table]['fields'][$v]['reference'][$row[$v]]) ? $GLOBALS['TL_DCA'][$table]['fields'][$v]['reference'][$row[$v]][0] : $GLOBALS['TL_DCA'][$table]['fields'][$v]['reference'][$row[$v]];
} elseif (($GLOBALS['TL_DCA'][$table]['fields'][$v]['eval']['isAssociative'] || array_is_assoc($GLOBALS['TL_DCA'][$table]['fields'][$v]['options'])) && isset($GLOBALS['TL_DCA'][$table]['fields'][$v]['options'][$row[$v]])) {
$args[$k] = $GLOBALS['TL_DCA'][$table]['fields'][$v]['options'][$row[$v]];
} else {
$args[$k] = $row[$v];
}
}
}
// Shorten the label it if it is too long
$label = vsprintf($GLOBALS['TL_DCA'][$this->strTable]['list']['label']['format'] ?: '%s', $args);
if ($GLOBALS['TL_DCA'][$this->strTable]['list']['label']['maxCharacters'] > 0 && $GLOBALS['TL_DCA'][$this->strTable]['list']['label']['maxCharacters'] < strlen(strip_tags($label))) {
$label = trim(\StringUtil::substrHtml($label, $GLOBALS['TL_DCA'][$this->strTable]['list']['label']['maxCharacters'])) . ' …';
}
// Remove empty brackets (), [], {}, <> and empty tags from the label
$label = preg_replace('/\\( *\\) ?|\\[ *\\] ?|\\{ *\\} ?|< *> ?/', '', $label);
$label = preg_replace('/<[^>]+>\\s*<\\/[^>]+>/', '', $label);
// Build the sorting groups
if ($GLOBALS['TL_DCA'][$this->strTable]['list']['sorting']['mode'] > 0) {
$current = $row[$firstOrderBy];
$orderBy = $GLOBALS['TL_DCA'][$this->strTable]['list']['sorting']['fields'];
$sortingMode = count($orderBy) == 1 && $firstOrderBy == $orderBy[0] && $GLOBALS['TL_DCA'][$this->strTable]['list']['sorting']['flag'] != '' && $GLOBALS['TL_DCA'][$this->strTable]['fields'][$firstOrderBy]['flag'] == '' ? $GLOBALS['TL_DCA'][$this->strTable]['list']['sorting']['flag'] : $GLOBALS['TL_DCA'][$this->strTable]['fields'][$firstOrderBy]['flag'];
$remoteNew = $this->formatCurrentValue($firstOrderBy, $current, $sortingMode);
// Add the group header
if (!$GLOBALS['TL_DCA'][$this->strTable]['list']['label']['showColumns'] && !$GLOBALS['TL_DCA'][$this->strTable]['list']['sorting']['disableGrouping'] && ($remoteNew != $remoteCur || $remoteCur === false)) {
$eoCount = -1;
$group = $this->formatGroupHeader($firstOrderBy, $remoteNew, $sortingMode, $row);
$remoteCur = $remoteNew;
$return .= '
<tr>
<td colspan="2" class="' . $groupclass . '">' . $group . '</td>
</tr>';
$groupclass = 'tl_folder_list';
}
}
$return .= '
<tr class="' . (++$eoCount % 2 == 0 ? 'even' : 'odd') . ' click2edit toggle_select" onmouseover="Theme.hoverRow(this,1)" onmouseout="Theme.hoverRow(this,0)">
';
$colspan = 1;
// Call the label_callback ($row, $label, $this)
if (is_array($GLOBALS['TL_DCA'][$this->strTable]['list']['label']['label_callback']) || is_callable($GLOBALS['TL_DCA'][$this->strTable]['list']['label']['label_callback'])) {
if (is_array($GLOBALS['TL_DCA'][$this->strTable]['list']['label']['label_callback'])) {
$strClass = $GLOBALS['TL_DCA'][$this->strTable]['list']['label']['label_callback'][0];
$strMethod = $GLOBALS['TL_DCA'][$this->strTable]['list']['label']['label_callback'][1];
$this->import($strClass);
示例2: parentView
//.........这里部分代码省略.........
list($strTable, $strField) = explode('.', $strTable);
$objRef = $this->Database->prepare("SELECT " . $strField . " FROM " . $strTable . " WHERE id=?")->limit(1)->execute($row[$strKey]);
$args[$k] = $objRef->numRows ? $objRef->{$strField} : '';
} elseif (in_array($GLOBALS['TL_DCA'][$this->strTable]['fields'][$v]['flag'], array(5, 6, 7, 8, 9, 10))) {
if ($GLOBALS['TL_DCA'][$this->strTable]['fields'][$v]['eval']['rgxp'] == 'date') {
$args[$k] = $row[$v] ? \Date::parse($GLOBALS['TL_CONFIG']['dateFormat'], $row[$v]) : '-';
} elseif ($GLOBALS['TL_DCA'][$this->strTable]['fields'][$v]['eval']['rgxp'] == 'time') {
$args[$k] = $row[$v] ? \Date::parse($GLOBALS['TL_CONFIG']['timeFormat'], $row[$v]) : '-';
} else {
$args[$k] = $row[$v] ? \Date::parse($GLOBALS['TL_CONFIG']['datimFormat'], $row[$v]) : '-';
}
} elseif ($GLOBALS['TL_DCA'][$this->strTable]['fields'][$v]['inputType'] == 'checkbox' && !$GLOBALS['TL_DCA'][$this->strTable]['fields'][$v]['eval']['multiple']) {
$args[$k] = $row[$v] != '' ? $GLOBALS['TL_DCA'][$this->strTable]['fields'][$v]['label'][0] : '';
} else {
$row_v = deserialize($row[$v]);
if (is_array($row_v)) {
$args_k = array();
foreach ($row_v as $option) {
$args_k[] = $GLOBALS['TL_DCA'][$this->strTable]['fields'][$v]['reference'][$option] ?: $option;
}
$args[$k] = implode(', ', $args_k);
} elseif (isset($GLOBALS['TL_DCA'][$this->strTable]['fields'][$v]['reference'][$row[$v]])) {
$args[$k] = is_array($GLOBALS['TL_DCA'][$this->strTable]['fields'][$v]['reference'][$row[$v]]) ? $GLOBALS['TL_DCA'][$this->strTable]['fields'][$v]['reference'][$row[$v]][0] : $GLOBALS['TL_DCA'][$this->strTable]['fields'][$v]['reference'][$row[$v]];
} elseif (($GLOBALS['TL_DCA'][$this->strTable]['fields'][$v]['eval']['isAssociative'] || array_is_assoc($GLOBALS['TL_DCA'][$this->strTable]['fields'][$v]['options'])) && isset($GLOBALS['TL_DCA'][$this->strTable]['fields'][$v]['options'][$row[$v]])) {
$args[$k] = $GLOBALS['TL_DCA'][$this->strTable]['fields'][$v]['options'][$row[$v]];
} else {
$args[$k] = $row[$v];
}
}
}
// Shorten the label it if it is too long
$label = vsprintf($GLOBALS['TL_DCA'][$this->strTable]['list']['label']['format'] ?: '%s', $args);
if ($GLOBALS['TL_DCA'][$this->strTable]['list']['label']['maxCharacters'] > 0 && $GLOBALS['TL_DCA'][$this->strTable]['list']['label']['maxCharacters'] < strlen(strip_tags($label))) {
$label = trim(\StringUtil::substrHtml($label, $GLOBALS['TL_DCA'][$this->strTable]['list']['label']['maxCharacters'])) . ' …';
}
// Remove empty brackets (), [], {}, <> and empty tags from the label
$label = preg_replace('/\\( *\\) ?|\\[ *\\] ?|\\{ *\\} ?|< *> ?/', '', $label);
$label = preg_replace('/<[^>]+>\\s*<\\/[^>]+>/', '', $label);
// Build the sorting groups
if ($GLOBALS['TL_DCA'][$this->strTable]['list']['sorting']['mode'] > 0) {
$current = $row[$firstOrderBy];
$orderBy = $GLOBALS['TL_DCA'][$this->strTable]['list']['sorting']['fields'];
$sortingMode = count($orderBy) == 1 && $firstOrderBy == $orderBy[0] && $GLOBALS['TL_DCA'][$this->strTable]['list']['sorting']['flag'] != '' && $GLOBALS['TL_DCA'][$this->strTable]['fields'][$firstOrderBy]['flag'] == '' ? $GLOBALS['TL_DCA'][$this->strTable]['list']['sorting']['flag'] : $GLOBALS['TL_DCA'][$this->strTable]['fields'][$firstOrderBy]['flag'];
$remoteNew = $this->formatCurrentValue($firstOrderBy, $current, $sortingMode);
// Add the group header
if (!$GLOBALS['TL_DCA'][$this->strTable]['list']['label']['showColumns'] && !$GLOBALS['TL_DCA'][$this->strTable]['list']['sorting']['disableGrouping'] && ($remoteNew != $remoteCur || $remoteCur === false)) {
$eoCount = -1;
$group = $this->formatGroupHeader($firstOrderBy, $remoteNew, $sortingMode, $row);
$remoteCur = $remoteNew;
$return .= '
<tr>
<td colspan="2" class="' . $groupclass . '">' . $group . '</td>
</tr>';
$groupclass = 'tl_folder_list';
}
}
$return .= '
<tr class="' . (++$eoCount % 2 == 0 ? 'even' : 'odd') . ' click2edit" onmouseover="Theme.hoverRow(this,1)" onmouseout="Theme.hoverRow(this,0)" onclick="Theme.toggleSelect(this)">
';
$colspan = 1;
// Call the label callback ($row, $label, $this)
if (is_array($GLOBALS['TL_DCA'][$this->strTable]['list']['label']['label_callback']) || is_callable($GLOBALS['TL_DCA'][$this->strTable]['list']['label']['label_callback'])) {
if (is_array($GLOBALS['TL_DCA'][$this->strTable]['list']['label']['label_callback'])) {
$strClass = $GLOBALS['TL_DCA'][$this->strTable]['list']['label']['label_callback'][0];
$strMethod = $GLOBALS['TL_DCA'][$this->strTable]['list']['label']['label_callback'][1];
$this->import($strClass);
示例3: compile
//.........这里部分代码省略.........
$arrResult = json_decode($objFile->getContent(), true);
} else {
$objFile->delete();
}
}
// Cache the result
if ($arrResult === null) {
try {
$objSearch = \Search::searchFor($strKeywords, $strQueryType == 'or', $arrPages, 0, 0, $blnFuzzy);
$arrResult = $objSearch->fetchAllAssoc();
} catch (\Exception $e) {
$this->log('Website search failed: ' . $e->getMessage(), __METHOD__, TL_ERROR);
$arrResult = array();
}
\File::putContent($strCacheFile, json_encode($arrResult));
}
$query_endtime = microtime(true);
// Sort out protected pages
if (\Config::get('indexProtected') && !BE_USER_LOGGED_IN) {
$this->import('FrontendUser', 'User');
foreach ($arrResult as $k => $v) {
if ($v['protected']) {
if (!FE_USER_LOGGED_IN) {
unset($arrResult[$k]);
} else {
$groups = deserialize($v['groups']);
if (!is_array($groups) || empty($groups) || !count(array_intersect($groups, $this->User->groups))) {
unset($arrResult[$k]);
}
}
}
}
$arrResult = array_values($arrResult);
}
$count = count($arrResult);
$this->Template->count = $count;
$this->Template->page = null;
$this->Template->keywords = $strKeywords;
// No results
if ($count < 1) {
$this->Template->header = sprintf($GLOBALS['TL_LANG']['MSC']['sEmpty'], $strKeywords);
$this->Template->duration = substr($query_endtime - $query_starttime, 0, 6) . ' ' . $GLOBALS['TL_LANG']['MSC']['seconds'];
return;
}
$from = 1;
$to = $count;
// Pagination
if ($this->perPage > 0) {
$id = 'page_s' . $this->id;
$page = \Input::get($id) !== null ? \Input::get($id) : 1;
$per_page = \Input::get('per_page') ?: $this->perPage;
// Do not index or cache the page if the page number is outside the range
if ($page < 1 || $page > max(ceil($count / $per_page), 1)) {
/** @var \PageError404 $objHandler */
$objHandler = new $GLOBALS['TL_PTY']['error_404']();
$objHandler->generate($objPage->id);
}
$from = ($page - 1) * $per_page + 1;
$to = $from + $per_page > $count ? $count : $from + $per_page - 1;
// Pagination menu
if ($to < $count || $from > 1) {
$objPagination = new \Pagination($count, $per_page, \Config::get('maxPaginationLinks'), $id);
$this->Template->pagination = $objPagination->generate("\n ");
}
$this->Template->page = $page;
}
// Get the results
for ($i = $from - 1; $i < $to && $i < $count; $i++) {
/** @var \FrontendTemplate|object $objTemplate */
$objTemplate = new \FrontendTemplate($this->searchTpl ?: 'search_default');
$objTemplate->url = $arrResult[$i]['url'];
$objTemplate->link = $arrResult[$i]['title'];
$objTemplate->href = $arrResult[$i]['url'];
$objTemplate->title = specialchars($arrResult[$i]['title']);
$objTemplate->class = ($i == $from - 1 ? 'first ' : '') . ($i == $to - 1 || $i == $count - 1 ? 'last ' : '') . ($i % 2 == 0 ? 'even' : 'odd');
$objTemplate->relevance = sprintf($GLOBALS['TL_LANG']['MSC']['relevance'], number_format($arrResult[$i]['relevance'] / $arrResult[0]['relevance'] * 100, 2) . '%');
$objTemplate->filesize = $arrResult[$i]['filesize'];
$objTemplate->matches = $arrResult[$i]['matches'];
$arrContext = array();
$arrMatches = trimsplit(',', $arrResult[$i]['matches']);
// Get the context
foreach ($arrMatches as $strWord) {
$arrChunks = array();
preg_match_all('/(^|\\b.{0,' . $this->contextLength . '}\\PL)' . str_replace('+', '\\+', $strWord) . '(\\PL.{0,' . $this->contextLength . '}\\b|$)/ui', $arrResult[$i]['text'], $arrChunks);
foreach ($arrChunks[0] as $strContext) {
$arrContext[] = ' ' . $strContext . ' ';
}
}
// Shorten the context and highlight all keywords
if (!empty($arrContext)) {
$objTemplate->context = trim(\StringUtil::substrHtml(implode('…', $arrContext), $this->totalLength));
$objTemplate->context = preg_replace('/(\\PL)(' . implode('|', $arrMatches) . ')(\\PL)/ui', '$1<span class="highlight">$2</span>$3', $objTemplate->context);
$objTemplate->hasContext = true;
}
$this->Template->results .= $objTemplate->parse();
}
$this->Template->header = vsprintf($GLOBALS['TL_LANG']['MSC']['sResults'], array($from, $to, $count, $strKeywords));
$this->Template->duration = substr($query_endtime - $query_starttime, 0, 6) . ' ' . $GLOBALS['TL_LANG']['MSC']['seconds'];
}
}
示例4: importCsv
//.........这里部分代码省略.........
$fieldValue = $fieldValue != '' ? explode($arrDelim, $fieldValue) : null;
}
\Input::setPost($fieldname, $fieldValue);
$objWidget->value = $fieldValue;
}
}
// validate input
$objWidget->validate();
$fieldValue = $objWidget->value;
// Convert date formats into timestamps
$rgxp = $arrDCA['eval']['rgxp'];
if (($rgxp == 'date' || $rgxp == 'time' || $rgxp == 'datim') && $fieldValue != '' && !$objWidget->hasErrors()) {
try {
$strTimeFormat = $GLOBALS['TL_CONFIG'][$rgxp . 'Format'];
$objDate = new \Date($fieldValue, $strTimeFormat);
$fieldValue = $objDate->tstamp;
} catch (\OutOfBoundsException $e) {
$objWidget->addError(sprintf($GLOBALS['TL_LANG']['ERR']['invalidDate'], $fieldValue));
}
}
// Make sure that unique fields are unique
if ($arrDCA['eval']['unique'] && $fieldValue != '' && !$this->Database->isUniqueValue($strTable, $fieldname, $fieldValue, null)) {
$objWidget->addError(sprintf($GLOBALS['TL_LANG']['ERR']['unique'], $arrDCA['label'][0] ?: $fieldname));
}
// Do not save the field if there are errors
if ($objWidget->hasErrors()) {
$doNotSave = true;
$fieldValue = sprintf('"%s" => <span class="errMsg">%s</span>', $fieldValue, $objWidget->getErrorsAsString());
} else {
// Set the correct empty value
if ($fieldValue === '') {
$fieldValue = $objWidget->getEmptyValue();
}
}
}
$set[$fieldname] = is_array($fieldValue) ? serialize($fieldValue) : $fieldValue;
}
// insert data record
if (!$doNotSave) {
// insert tstamp
if ($this->Database->fieldExists('tstamp', $strTable)) {
if (!$set['tstamp'] > 0) {
$set['tstamp'] = time();
}
}
// insert dateAdded (tl_member)
if ($this->Database->fieldExists('dateAdded', $strTable)) {
if (!$set['dateAdded'] > 0) {
$set['dateAdded'] = time();
}
}
// add new member to newsletter recipient list
if ($strTable == 'tl_member' && $set['email'] != '' && $set['newsletter'] != '') {
foreach (deserialize($set['newsletter'], true) as $newsletterId) {
// check for unique email-address
$objRecipient = $this->Database->prepare("SELECT * FROM tl_newsletter_recipients WHERE email=? AND pid=(SELECT pid FROM tl_newsletter_recipients WHERE id=?) AND id!=?")->execute($set['email'], $newsletterId, $newsletterId);
if (!$objRecipient->numRows) {
$arrRecipient = array();
$arrRecipient['tstamp'] = time();
$arrRecipient['pid'] = $newsletterId;
$arrRecipient['email'] = $set['email'];
$arrRecipient['active'] = '1';
if ($blnTestMode !== true) {
$this->Database->prepare('INSERT INTO tl_newsletter_recipients %s')->set($arrRecipient)->execute();
}
}
}
}
try {
if ($blnTestMode !== true) {
// insert entry into database
$this->Database->prepare('INSERT INTO ' . $strTable . ' %s')->set($set)->execute();
}
} catch (\Exception $e) {
$set['insertError'] = $e->getMessage();
$doNotSave = true;
}
}
// generate html markup for the import report table
$htmlReport = '';
$cssClass = 'allOk';
if ($doNotSave) {
$cssClass = 'error';
$htmlReport .= sprintf('<tr class="%s"><td class="tdTitle" colspan="2">#%s Datensatz konnte nicht angelegt werden!</td></tr>', $cssClass, $line);
// increment error counter if necessary
$insertError++;
} else {
$htmlReport .= sprintf('<tr class="%s"><td class="tdTitle" colspan="2">#%s Datensatz erfolgreich angelegt!</td></tr>', $cssClass, $line);
}
foreach ($set as $k => $v) {
if (is_array($v)) {
$v = serialize($v);
}
$htmlReport .= sprintf('<tr class="%s"><td>%s</td><td>%s</td></tr>', $cssClass, \StringUtil::substr($k, 30), \StringUtil::substrHtml($v, 90));
}
$htmlReport .= '<tr class="delim"><td> </td><td> </td></tr>';
$_SESSION['import_from_csv']['report'][] = $htmlReport;
}
$_SESSION['import_from_csv']['status'] = array('blnTestMode' => $blnTestMode, 'rows' => $rows, 'success' => $rows - $insertError, 'errors' => $insertError);
}
示例5: generateItemLabel
protected function generateItemLabel($objRow, $folderAttribute)
{
$blnProtected = false;
$showFields = $this->arrDca['list']['label']['fields'];
$dc = new DC_Table(\Config::get('fieldpalette_table'));
$dc->id = $this->currentRecord;
$dc->activeRecord = $objRow;
foreach ($showFields as $k => $v) {
$args[$k] = FormSubmission::prepareSpecialValueForPrint($objRow->{$v}, $this->arrDca['fields'][$v], $this->strTable, $dc);
}
$label = vsprintf(strlen($this->arrDca['list']['label']['format']) ? $this->arrDca['list']['label']['format'] : '%s', $args);
// Shorten the label if it is too long
if ($this->arrDca['list']['label']['maxCharacters'] > 0 && $this->arrDca['list']['label']['maxCharacters'] < utf8_strlen(strip_tags($label))) {
$label = trim(\StringUtil::substrHtml($label, $this->arrDca['list']['label']['maxCharacters'])) . ' …';
}
// Call the label_callback ($row, $label, $this)
if (is_array($this->arrDca['list']['label']['label_callback'])) {
$strClass = $this->arrDca['list']['label']['label_callback'][0];
$strMethod = $this->arrDca['list']['label']['label_callback'][1];
$this->import($strClass);
return $this->{$strClass}->{$strMethod}($objRow->row(), $label, $this, $folderAttribute, false, $blnProtected);
} elseif (is_callable($this->arrDca['list']['label']['label_callback'])) {
return $this->arrDca['list']['label']['label_callback']($objRow->row(), $label, $this, $folderAttribute, false, $blnProtected);
} else {
return $label;
}
return $label;
}