Exemplo n.º 1
0
 /**
  * Evaluation of 'input'-type values based on 'eval' list
  *
  * @param string $value Value to evaluate
  * @param array $evalArray Array of evaluations to traverse.
  * @param string $is_in Is-in string for 'is_in' evaluation
  * @return array Modified $value in key 'value' or empty array
  * @todo Define visibility
  */
 public function checkValue_input_Eval($value, $evalArray, $is_in)
 {
     $res = array();
     $newValue = $value;
     $set = TRUE;
     foreach ($evalArray as $func) {
         switch ($func) {
             case 'int':
             case 'year':
             case 'time':
             case 'timesec':
                 $value = intval($value);
                 break;
             case 'date':
             case 'datetime':
                 $value = intval($value);
                 if ($value > 0 && !$this->dontProcessTransformations) {
                     $value -= date('Z', $value);
                 }
                 break;
             case 'double2':
                 $value = preg_replace('/[^0-9,\\.-]/', '', $value);
                 $negative = substr($value, 0, 1) == '-';
                 $value = strtr($value, array(',' => '.', '-' => ''));
                 if (strpos($value, '.') === FALSE) {
                     $value .= '.0';
                 }
                 $valueArray = explode('.', $value);
                 $dec = array_pop($valueArray);
                 $value = join('', $valueArray) . '.' . $dec;
                 if ($negative) {
                     $value *= -1;
                 }
                 $value = number_format($value, 2, '.', '');
                 break;
             case 'md5':
                 if (strlen($value) != 32) {
                     $set = FALSE;
                 }
                 break;
             case 'trim':
                 $value = trim($value);
                 break;
             case 'upper':
                 $value = $GLOBALS['LANG']->csConvObj->conv_case($GLOBALS['LANG']->charSet, $value, 'toUpper');
                 break;
             case 'lower':
                 $value = $GLOBALS['LANG']->csConvObj->conv_case($GLOBALS['LANG']->charSet, $value, 'toLower');
                 break;
             case 'required':
                 if (!isset($value) || $value === '') {
                     $set = FALSE;
                 }
                 break;
             case 'is_in':
                 $c = strlen($value);
                 if ($c) {
                     $newVal = '';
                     for ($a = 0; $a < $c; $a++) {
                         $char = substr($value, $a, 1);
                         if (strpos($is_in, $char) !== FALSE) {
                             $newVal .= $char;
                         }
                     }
                     $value = $newVal;
                 }
                 break;
             case 'nospace':
                 $value = str_replace(' ', '', $value);
                 break;
             case 'alpha':
                 $value = preg_replace('/[^a-zA-Z]/', '', $value);
                 break;
             case 'num':
                 $value = preg_replace('/[^0-9]/', '', $value);
                 break;
             case 'alphanum':
                 $value = preg_replace('/[^a-zA-Z0-9]/', '', $value);
                 break;
             case 'alphanum_x':
                 $value = preg_replace('/[^a-zA-Z0-9_-]/', '', $value);
                 break;
             case 'domainname':
                 if (!preg_match('/^[a-z0-9\\.\\-]*$/i', $value)) {
                     \TYPO3\CMS\Core\Utility\GeneralUtility::requireOnce(PATH_typo3 . 'contrib/idna/idna_convert.class.php');
                     $idnaConvert = new \idna_convert();
                     $idnaConvert->set_parameter('idn_version', '2008');
                     $value = $idnaConvert->encode($value);
                     unset($idnaConvert);
                 }
                 break;
             default:
                 $evalObj = \TYPO3\CMS\Core\Utility\GeneralUtility::getUserObj($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tce']['formevals'][$func] . ':&' . $func);
                 if (is_object($evalObj) && method_exists($evalObj, 'evaluateFieldValue')) {
                     $value = $evalObj->evaluateFieldValue($value, $is_in, $set);
                 }
                 break;
         }
     }
     if ($set) {
         $res['value'] = $value;
     }
     return $res;
 }
     }
 }
 //$forum_page['user_contact']['forum-mail'] = '<li><span>'.$lang_profile['Escrow'].': <a href="'.forum_link($forum_url['escrow'], $id).'">'.$lang_profile['Start new escrow'].'</a></span></li>';
 /*
 //else if ($forum_user['id'] == $id || ($forum_user['is_admmod'] && $user['email_setting'] == '2'))
 //	$forum_page['user_private']['forum-mail'] = '<li><span>'.$lang_profile['E-mail'].': <a href="'.forum_link($forum_url['email'], $id).'">'.$lang_profile['Send forum e-mail'].'</a></span></li>';
 */
 // Website
 if ($user['url'] != '') {
     $url_source = $user['url'];
     // IDNA url handling
     if (defined('FORUM_SUPPORT_PCRE_UNICODE') && defined('FORUM_ENABLE_IDNA')) {
         // Load the IDNA class for international url handling
         require_once FORUM_ROOT . 'include/idna/idna_convert.class.php';
         $idn = new idna_convert();
         $idn->set_parameter('encoding', 'utf8');
         $idn->set_parameter('strict', false);
         if (preg_match('!^(https?|ftp|news){1}' . preg_quote('://xn--', '!') . '!', $url_source)) {
             $user['url'] = $idn->decode($url_source);
         } else {
             $url_source = $idn->encode($url_source);
         }
     }
     if ($forum_config['o_censoring'] == '1') {
         $user['url'] = censor_words($user['url']);
     }
     $url_source = forum_htmlencode($url_source);
     $user['url'] = forum_htmlencode($user['url']);
     $forum_page['url'] = '<a href="' . $url_source . '" class="external url" rel="me">' . $user['url'] . '</a>';
     $forum_page['user_contact']['website'] = '<li><span>' . $lang_profile['Website'] . ': ' . $forum_page['url'] . '</span></li>';
 }
Exemplo n.º 3
0
function handle_url_tag($url, $link = '', $bbcode = false)
{
    $return = ($hook = get_hook('ps_handle_url_tag_start')) ? eval($hook) : null;
    if ($return != null) {
        return $return;
    }
    $full_url = str_replace(array(' ', '\'', '`', '"'), array('%20', '', '', ''), $url);
    if (strpos($url, 'www.') === 0) {
        // If it starts with www, we add http://
        $full_url = 'http://' . $full_url;
    } else {
        if (strpos($url, 'ftp.') === 0) {
            // Else if it starts with ftp, we add ftp://
            $full_url = 'ftp://' . $full_url;
        } else {
            if (!preg_match('#^([a-z0-9]{3,6})://#', $url)) {
                // Else if it doesn't start with abcdef://, we add http://
                $full_url = 'http://' . $full_url;
            }
        }
    }
    if (defined('FORUM_SUPPORT_PCRE_UNICODE') && defined('FORUM_ENABLE_IDNA')) {
        static $idn;
        static $cached_encoded_urls = null;
        if (is_null($cached_encoded_urls)) {
            $cached_encoded_urls = array();
        }
        // Check in cache
        $cache_key = md5($full_url);
        if (isset($cached_encoded_urls[$cache_key])) {
            $full_url = $cached_encoded_urls[$cache_key];
        } else {
            if (!isset($idn)) {
                $idn = new idna_convert();
                $idn->set_parameter('encoding', 'utf8');
                $idn->set_parameter('strict', false);
            }
            $full_url = $idn->encode($full_url);
            $cached_encoded_urls[$cache_key] = $full_url;
        }
    }
    // Ok, not very pretty :-)
    if (!$bbcode) {
        if (defined('FORUM_SUPPORT_PCRE_UNICODE') && defined('FORUM_ENABLE_IDNA')) {
            $link_name = $link == '' || $link == $url ? $url : $link;
            if (preg_match('!^(https?|ftp|news){1}' . preg_quote('://xn--', '!') . '!', $link_name)) {
                $link = $idn->decode($link_name);
            }
        }
        $link = $link == '' || $link == $url ? utf8_strlen($url) > 55 ? utf8_substr($url, 0, 39) . ' … ' . utf8_substr($url, -10) : $url : stripslashes($link);
    }
    $return = ($hook = get_hook('ps_handle_url_tag_end')) ? eval($hook) : null;
    if ($return != null) {
        return $return;
    }
    if ($bbcode) {
        if (defined('FORUM_SUPPORT_PCRE_UNICODE') && defined('FORUM_ENABLE_IDNA')) {
            if (preg_match('!^(https?|ftp|news){1}' . preg_quote('://xn--', '!') . '!', $link)) {
                $link = $idn->decode($link);
            }
        }
        if ($full_url == $link) {
            return '[url]' . $link . '[/url]';
        } else {
            return '[url=' . $full_url . ']' . $link . '[/url]';
        }
    } else {
        return '<a href="' . $full_url . '">' . $link . '</a>';
    }
}