normalize() public static method

Makes the string lowercase, replaces umlauts by their ascii representation (ä -> ae etc.), and replaces all other chars that do not match a-z, 0-9 or $allowedChars by $replaceChar.
public static normalize ( string $string, string $replaceChar = '_', string $allowedChars = '' ) : string
$string string Input string
$replaceChar string Character that is used to replace not allowed chars
$allowedChars string Character whitelist
return string
Exemplo n.º 1
0
 public function formatElement()
 {
     $s = '';
     $values = explode('|', trim($this->getValue(), '|'));
     $options = $this->getOptions();
     $name = $this->getAttribute('name');
     $id = $this->getAttribute('id');
     $attr = '';
     foreach ($this->getAttributes() as $attributeName => $attributeValue) {
         if ($attributeName == 'name' || $attributeName == 'id') {
             continue;
         }
         $attr .= ' ' . htmlspecialchars($attributeName) . '="' . htmlspecialchars($attributeValue) . '"';
     }
     $formElements = [];
     foreach ($options as $opt_name => $opt_value) {
         $opt_id = $id;
         if ($opt_value != '') {
             $opt_id .= '-' . rex_string::normalize($opt_value, '-');
         }
         $opt_attr = $attr . ' id="' . htmlspecialchars($opt_id) . '"';
         $checked = in_array($opt_value, $values) ? ' checked="checked"' : '';
         $n = [];
         $n['label'] = '<label class="control-label" for="' . htmlspecialchars($opt_id) . '">' . htmlspecialchars($opt_name) . '</label>';
         $n['field'] = '<input type="checkbox" name="' . htmlspecialchars($name) . '[' . htmlspecialchars($opt_value) . ']" value="' . htmlspecialchars($opt_value) . '"' . $opt_attr . $checked . ' />';
         $formElements[] = $n;
     }
     $fragment = new rex_fragment();
     $fragment->setVar('elements', $formElements, false);
     $fragment->setVar('grouped', true);
     $s = $fragment->parse('core/form/checkbox.php');
     return $s;
 }
Exemplo n.º 2
0
/**
 * Erstellt einen Filename der eindeutig ist für den Medienpool.
 *
 * @param string $FILENAME      Dateiname
 * @param bool   $doSubindexing
 *
 * @return string
 */
function rex_mediapool_filename($FILENAME, $doSubindexing = true)
{
    // ----- neuer filename und extension holen
    $NFILENAME = rex_string::normalize($FILENAME, '_', '.-');
    if (strrpos($NFILENAME, '.') != '') {
        $NFILE_NAME = substr($NFILENAME, 0, strlen($NFILENAME) - (strlen($NFILENAME) - strrpos($NFILENAME, '.')));
        $NFILE_EXT = substr($NFILENAME, strrpos($NFILENAME, '.'), strlen($NFILENAME) - strrpos($NFILENAME, '.'));
    } else {
        $NFILE_NAME = $NFILENAME;
        $NFILE_EXT = '';
    }
    // ---- ext checken - alle scriptendungen rausfiltern
    if (in_array(ltrim($NFILE_EXT, '.'), rex_addon::get('mediapool')->getProperty('blocked_extensions'))) {
        $NFILE_NAME .= $NFILE_EXT;
        $NFILE_EXT = '.txt';
    }
    // ---- multiple extension check
    foreach (rex_addon::get('mediapool')->getProperty('blocked_extensions') as $ext) {
        $NFILE_NAME = str_replace($ext . '.', $ext . '_.', $NFILE_NAME);
    }
    $NFILENAME = $NFILE_NAME . $NFILE_EXT;
    if ($doSubindexing || $FILENAME != $NFILENAME) {
        // ----- datei schon vorhanden -> namen aendern -> _1 ..
        if (file_exists(rex_path::media($NFILENAME))) {
            $cnt = 1;
            while (file_exists(rex_path::media($NFILE_NAME . '_' . $cnt . $NFILE_EXT))) {
                ++$cnt;
            }
            $NFILENAME = $NFILE_NAME . '_' . $cnt . $NFILE_EXT;
        }
    }
    return $NFILENAME;
}
Exemplo n.º 3
0
 public function formatElement()
 {
     $s = '';
     $value = $this->getValue();
     $options = $this->getOptions();
     $id = $this->getAttribute('id');
     $attr = '';
     foreach ($this->getAttributes() as $attributeName => $attributeValue) {
         if ($attributeName == 'id') {
             continue;
         }
         $attr .= ' ' . htmlspecialchars($attributeName) . '="' . htmlspecialchars($attributeValue) . '"';
     }
     $formElements = [];
     foreach ($options as $opt_name => $opt_value) {
         $checked = $opt_value == $value ? ' checked="checked"' : '';
         $opt_id = $id . '-' . rex_string::normalize($opt_value, '-');
         $opt_attr = $attr . ' id="' . $opt_id . '"';
         $n = [];
         $n['label'] = '<label class="control-label" for="' . $opt_id . '">' . htmlspecialchars($opt_name) . '</label>';
         $n['field'] = '<input type="radio" value="' . htmlspecialchars($opt_value) . '"' . $opt_attr . $checked . ' />';
         $formElements[] = $n;
     }
     $fragment = new rex_fragment();
     $fragment->setVar('elements', $formElements, false);
     $s = $fragment->parse('core/form/radio.php');
     return $s;
 }
Exemplo n.º 4
0
 /**
  * @param string $fieldsetName
  *
  * @return array
  */
 public function fieldsetPostValues($fieldsetName)
 {
     // Name normalisieren, da der gepostete Name auch zuvor normalisiert wurde
     $normalizedFieldsetName = rex_string::normalize($fieldsetName, '_', '[]');
     return rex_post($normalizedFieldsetName, 'array');
 }
Exemplo n.º 5
0
/**
 * @param string $name
 *
 * @return string
 *
 * @package redaxo\structure
 */
function rex_parse_article_name($name)
{
    return str_replace('+', '-', urlencode(preg_replace('/ {2,}/', ' ', rex_string::normalize($name, '', ' _'))));
}
Exemplo n.º 6
0
 public function setAttribute($name, $value)
 {
     if ($name == 'value') {
         $this->setValue($value);
     } else {
         if ($name == 'id') {
             $value = rex_string::normalize($value, '-');
         } elseif ($name == 'name') {
             $value = rex_string::normalize($value, '_', '[]');
         }
         $this->attributes[$name] = $value;
     }
 }
Exemplo n.º 7
0
">
  <dt>
    <label class="control-label" for="<?php 
echo rex_string::normalize($name, '');
?>
"><?php 
echo $label;
?>
</label>
  </dt>
  <dd>
    <?php 
$newSelect = new rex_select();
$newSelect->setMultiple($this->getVar('multiple'));
$newSelect->setAttribute('class', 'form-control');
$newSelect->setId(rex_string::normalize($name, ''));
$newSelect->setSize($size);
$newSelect->setName($name);
$newSelect->setSelected($this->getVar('selected'));
if (count($options) > 0) {
    foreach ($options as $key => $module) {
        if (is_array($module)) {
            $newSelect->addOption($module['name'], $module['id']);
        } else {
            $newSelect->addOption($module, $key);
        }
    }
}
echo $newSelect->get();
?>
    <br><span class="rex-form-notice"><?php 
Exemplo n.º 8
0
Arquivo: top.php Projeto: eaCe/redaxo
$body_attr['id'] = ['rex-page-' . $body_id];
$body_attr['onunload'] = ['closeAll();'];
$body_attr['class'] = ['rex-is-logged-out'];
if (rex::getUser()) {
    $body_attr['class'] = ['rex-is-logged-in'];
}
if ($curPage->isPopup()) {
    $body_attr['class'][] = 'rex-is-popup';
}
// ----- EXTENSION POINT
$body_attr = rex_extension::registerPoint(new rex_extension_point('PAGE_BODY_ATTR', $body_attr));
$body = '';
foreach ($body_attr as $k => $v) {
    $body .= ' ' . $k . '="';
    if (is_array($v)) {
        $body .= rex_string::normalize(implode(' ', $v), '-', ' ');
    }
    $body .= '"';
}
$hasNavigation = $curPage->hasNavigation();
$meta_items = [];
if (rex::getUser() && $hasNavigation) {
    if (rex::isSafeMode()) {
        $item = [];
        $item['title'] = rex_i18n::msg('safemode_deactivate');
        $item['href'] = rex_url::backendController(['safemode' => 0]);
        $meta_items[] = $item;
        unset($item);
    }
    $user_name = rex::getUser()->getValue('name') != '' ? rex::getUser()->getValue('name') : rex::getUser()->getValue('login');
    $item = [];
Exemplo n.º 9
0
 /**
  * @dataProvider normalizeProvider
  */
 public function testNormalize($expected, $string, $replaceChar = '_', $allowedChars = '')
 {
     $this->assertEquals($expected, rex_string::normalize($string, $replaceChar, $allowedChars));
 }
Exemplo n.º 10
0
      </label>
      <?php 
if ($fields = $this->getVar('toggleFields')) {
    ?>
      <script type="text/javascript">
        jQuery(function($) {
          $("#<?php 
    echo rex_string::normalize($name, '');
    ?>
").click(function() {
            $("<?php 
    echo str_replace('.', '.group_', $fields);
    ?>
").slideToggle("slow");
          });
          if($("#<?php 
    echo rex_string::normalize($name, '');
    ?>
").is(":checked"))
            $("<?php 
    echo str_replace('.', '.group_', $fields);
    ?>
").hide();
        });
        </script>
      <?php 
}
?>
    </div>
  </dd>
</dl>
Exemplo n.º 11
0
 /**
  * @param string $fieldsetName
  * @param string $fieldName
  * @param mixed  $default
  *
  * @return string
  */
 public function elementPostValue($fieldsetName, $fieldName, $default = null)
 {
     $fields = $this->fieldsetPostValues($fieldsetName);
     // name attributes are normalized
     $normalizedFieldName = rex_string::normalize($fieldName, '_', '[]');
     if (isset($fields[$normalizedFieldName])) {
         return $fields[$normalizedFieldName];
     }
     return $default;
 }
Exemplo n.º 12
0
/**
 * Layout Kopf des Backends.
 *
 * @package redaxo5
 */
$curPage = rex_be_controller::getCurrentPageObject();
if (!$curPage->hasLayout()) {
    if (rex_request::isPJAXRequest()) {
        // add title to the page, so pjax can update it. see gh#136
        echo '<title>' . htmlspecialchars(rex_be_controller::getPageTitle()) . '</title>';
    }
    return;
}
$body_attr = [];
$body_id = rex_string::normalize(rex_be_controller::getCurrentPage(), '-', ' ');
$body_attr['id'] = ['rex-page-' . $body_id];
$body_attr['onunload'] = ['closeAll();'];
$body_attr['class'] = ['rex-is-logged-out'];
if (rex::getUser()) {
    $body_attr['class'] = ['rex-is-logged-in'];
}
if ($curPage->isPopup()) {
    $body_attr['class'][] = 'rex-is-popup';
}
// ----- EXTENSION POINT
$body_attr = rex_extension::registerPoint(new rex_extension_point('PAGE_BODY_ATTR', $body_attr));
$body = '';
foreach ($body_attr as $k => $v) {
    $body .= ' ' . $k . '="';
    if (is_array($v)) {
Exemplo n.º 13
0
if ($func == 'add') {
    $content .= '
                <tr class="mark">
                    <td class="rex-table-icon"><i class="rex-icon rex-icon-refresh"></i></td>
                    <td class="rex-table-id" data-title="' . $this->i18n('id') . '">–</td>
                    <td data-title="' . $this->i18n('wildcard') . '"><input class="form-control" type="text" name="wildcard_name" value="' . htmlspecialchars($wildcard_name) . '" /></td>
                    ' . $td_add . '
                    <td class="rex-table-action" colspan="2"><button class="btn btn-save" type="submit" name="add_wildcard_save"' . rex::getAccesskey($this->i18n('add'), 'save') . ' value="1">' . $this->i18n('add') . '</button></td>
                </tr>
            ';
}
$querySelect = [];
$queryJoin = [];
foreach (rex_clang::getAll() as $clang_id => $clang) {
    if (rex::getUser()->getComplexPerm('clang')->hasPerm($clang_id)) {
        $as = rex_string::normalize($clang->getName());
        $querySelect[] = $as . '.replace AS ' . 'id' . $clang->getId();
        $queryJoin[] = 'LEFT JOIN ' . rex::getTable('sprog_wildcard') . ' AS ' . $as . ' ON a.id = ' . $as . '.id AND ' . $as . '.clang_id = ' . $clang->getId();
    }
}
$querySelectAsString = count($querySelect) ? ', ' . implode(',', $querySelect) : '';
$wildcards = rex_sql::factory();
$entries = $wildcards->setQuery('SELECT DISTINCT a.id, a.wildcard AS wildcard' . $querySelectAsString . ' FROM ' . rex::getTable('sprog_wildcard') . ' AS a ' . implode(' ', $queryJoin) . ' ORDER BY wildcard')->getArray();
if (count($entries)) {
    foreach ($entries as $entry) {
        $entry_id = $entry['id'];
        $entry_wildcard = $entry['wildcard'];
        unset($entry['id']);
        unset($entry['wildcard']);
        // Edit form
        if ($func == 'edit' && $wildcard_id == $entry_id) {
Exemplo n.º 14
0
<?php

$css_classes = [];
if ($this->getElement('css_classes') != '') {
    $css_classes = explode(',', $this->getElement('css_classes'));
}
$labels = explode(',', $this->getElement('labels'));
foreach ($labels as $index => $label) {
    $classes = ['btn'];
    if (isset($css_classes[$index]) && trim($css_classes[$index]) != '') {
        $classes[] = trim($css_classes[$index]);
    }
    if ($this->getWarningClass() != '') {
        $classes[] = $this->getWarningClass();
    }
    $id = $this->getFieldId() . '-' . rex_string::normalize($label);
    $value = htmlspecialchars(stripslashes(rex_i18n::translate($label)));
    echo '<button class="' . implode(' ', $classes) . '" type="submit" name="' . $this->getFieldName() . '" id="' . $id . '" value="' . $value . '">' . $label . '</button>';
}