protected function cleanup() { parent::cleanup(); $start = mb_strpos($this->data, $this->partToken) + mb_strlen($this->partToken); $end = mb_strrpos($this->data, $this->partToken); $this->data = mb_substr($this->data, $start, $end - $start); }
/** * Définir un cookie avec le contenu de paramètres transmis en GET puis rappeler la page * * @param string $query_string éventuellement avec 'url_redirection' en dernier paramètre * @return void */ public static function save_get_and_exit_reload( $query_string ) { Cookie::definir( COOKIE_MEMOGET , $query_string , 300 /* 60*5 = 5 min */ ); $param_redir_pos = mb_strpos($query_string,'&url_redirection'); $param_sans_redir = ($param_redir_pos) ? mb_substr( $query_string , 0 , $param_redir_pos ) : $query_string ; // J'ai déjà eu un msg d'erreur car il n'aime pas les chaines trop longues + Pas la peine d'encombrer avec le paramètre de redirection qui sera retrouvé dans le cookie de toutes façons exit_redirection(URL_BASE.$_SERVER['SCRIPT_NAME'].'?'.$param_sans_redir); }
function f_banners(&$text) { $phrase = 'БАННЕР'; if (mb_strpos($text, $phrase) === false) { return true; } if (!cmsCore::getInstance()->isComponentEnable('banners')) { return true; } $regex = '/{(' . $phrase . '=)\\s*(.*?)}/i'; $matches = array(); preg_match_all($regex, $text, $matches, PREG_SET_ORDER); if (!$matches) { return true; } cmsCore::loadModel('banners'); foreach ($matches as $elm) { $elm[0] = str_replace('{', '', $elm[0]); $elm[0] = str_replace('}', '', $elm[0]); mb_parse_str($elm[0], $args); $position = @$args[$phrase]; if ($position) { $output = cms_model_banners::getBannerHTML($position); } else { $output = ''; } $text = str_replace('{' . $phrase . '=' . $position . '}', $output, $text); } return true; }
/** * Get plugin options. * * @since 151002 Improving multisite compat. * * @param bool $intersect Discard options not present in $this->default_options * @param bool $refresh Force-pull options directly from get_site_option() * * @return array Plugin options. * * @note $intersect should be `false` when this method is called via a VS upgrade routine or during inital startup on when upgrading. See https://git.io/viGIK */ public function getOptions($intersect = true, $refresh = false) { if (!($options = $this->options) || $refresh) { // If not defined yet, or if we're forcing a refresh via get_site_option() if (!is_array($options = get_site_option(GLOBAL_NS . '_options'))) { $options = []; // Force array. } if (!$options && is_array($zencache_options = get_site_option('zencache_options'))) { $options = $zencache_options; // Old ZenCache options. $options['crons_setup'] = $this->default_options['crons_setup']; $options['latest_lite_version'] = $this->default_options['latest_lite_version']; $options['latest_pro_version'] = $this->default_options['latest_pro_version']; } } $this->options = array_merge($this->default_options, $options); $this->options = $this->applyWpFilters(GLOBAL_NS . '_options', $this->options); $this->options = $intersect ? array_intersect_key($this->options, $this->default_options) : $this->options; foreach ($this->options as $_key => &$_value) { $_value = trim((string) $_value); // Force strings. } unset($_key, $_value); // Housekeeping. $this->options['base_dir'] = trim($this->options['base_dir'], '\\/' . " \t\n\r\v"); if (!$this->options['base_dir'] || mb_strpos(basename($this->options['base_dir']), 'wp-') === 0) { $this->options['base_dir'] = $this->default_options['base_dir']; } return $this->options; // Plugin options. }
function f_includes(&$text){ $phrase = 'ФАЙЛ'; if (mb_strpos($text, $phrase) === false){ return true; } $regex = '/{('.$phrase.'=)\s*(.*?)}/i'; $matches = array(); preg_match_all( $regex, $text, $matches, PREG_SET_ORDER ); foreach ($matches as $elm) { $elm[0] = str_replace('{', '', $elm[0]); $elm[0] = str_replace('}', '', $elm[0]); mb_parse_str( $elm[0], $args ); $file=@$args[$phrase]; if ($file){ $output = getLink($file); } else { $output = ''; } $text = str_replace('{'.$phrase.'='.$file.'}', $output, $text ); } return true; }
/** * Assumes mbstring internal encoding is set to UTF-8 * Wrapper around mb_strpos * Find position of first occurrence of a string * @param string haystack * @param string needle (you should validate this with utf8_is_valid) * @param integer offset in characters (from left) * @return mixed integer position or FALSE on failure * @package utf8 * @subpackage strings */ function utf8_strpos($str, $search, $offset = FALSE){ if ( $offset === FALSE ) { return mb_strpos($str, $search); } else { return mb_strpos($str, $search, $offset); } }
protected function validateIdentical($input) { if (is_array($input)) { return reset($input) === $this->startValue; } return 0 === mb_strpos($input, $this->startValue, 0, mb_detect_encoding($input)); }
/** Last inn siden (kalles til slutten av scriptet for å hente themet */ public function load() { $this->content .= ob_get_contents(); @ob_clean(); // load through twig template? $templates = array('guest_simple' => 'templates/guest/simple', 'guest' => 'templates/guest/wide', 'node' => 'templates/guest/node', 'doc' => 'templates/doc'); if (isset($templates[$this->theme_file])) { $template = $templates[$this->theme_file]; \Kofradia\View::forgeTwig($template); $response = new \Kofradia\Response(); $response->setContents(\Kofradia\View::forgeTwig($template)); $response->output(); die; } global $_base; $_base->dt("page_load_pre"); // temafilen $theme_file = PATH_PUBLIC . "/themes/" . $this->theme . "/" . $this->theme_file . ".php"; // finnes ikke temafilen? if (!file_exists($theme_file)) { throw new HSException("Fant ikke temafilen <b>{$this->theme_file}.php</b> for temaet <b>{$this->theme}</b>."); } if (mb_strpos($this->content, '<boxes />') === false) { $this->content = '<boxes />' . $this->content; } // hent temafilen require $theme_file; // hent full html kode som ble generert $content = ob_get_contents(); @ob_clean(); echo $this->postParse($content); die; }
/** * prints a block * */ function smarty_function_eF_template_printMessageBlock($params, &$smarty) { !isset($params['type']) || !$params['type'] ? $params['type'] = 'failure' : null; in_array($params['type'], array('success', 'failure')) or $params['type'] = 'failure'; if ($params['type'] == 'success') { $messageImage = '<img src = "images/32x32/success.png" alt = "' . _SUCCESS . '" title = "' . _SUCCESS . '">'; } else { $messageImage = '<img src = "images/32x32/warning.png" alt = "' . _FAILURE . '" title = "' . _FAILURE . '">'; } $link = mb_substr($params['content'], mb_strpos($params['content'], ' <a href = "javascript:void(0)" onclick = "eF_js_showDivPopup(event, \'' . _ERRORDETAILS . '\', 2, \'error_details\')">' . _MOREINFO . '</a>')); $message = mb_substr($params['content'], 0, mb_strpos($params['content'], ' <a href = "javascript:void(0)" onclick = "eF_js_showDivPopup(event, \'' . _ERRORDETAILS . '\', 2, \'error_details\')">' . _MOREINFO . '</a>')); $params['content'] = strip_tags($message) . $link; if (mb_strlen($params['content']) > 1000) { $prefix = mb_substr($params['content'], 0, 1000); $suffix = mb_substr($params['content'], mb_strlen($params['content']) - 300, mb_strlen($params['content'])); $infix = mb_substr($params['content'], 1001, mb_strlen($params['content']) - mb_strlen($prefix) - mb_strlen($suffix)); $params['content'] = $prefix . '<a href = "javascript:void(0)" onclick = "this.style.display = \'none\';Element.extend(this).next().show()"><br>[...]<br></a><span style = "display:none">' . $infix . '</span>' . $suffix; } $str .= ' <div class = "block" id = "messageBlock"> <div class = "blockContents messageContents"> <table class = "messageBlock"> <tr><td>' . $messageImage . '</td> <td class = "' . strip_tags($params['type']) . 'Block">' . $params['content'] . '</td> <td><img src = "images/32x32/close.png" alt = "' . _CLOSE . '" title = "' . _CLOSE . '" onclick = "window.Effect ? new Effect.Fade($(\'messageBlock\')) : document.getElementById(\'messageBlock\').style.display = \'none\';"></td></tr> </table> </div> </div>'; return $str; }
protected function _renderFilters() { /* @var $core Mana_Core_Helper_Data */ $core = Mage::helper(strtolower('Mana_Core')); $items = array(); foreach ($this->_items as $key => $item) { $conforms = true; foreach ($this->_mFilters as $filter) { if ($filter['attribute'] == 'entity_type_id') { continue; } $method = 'get' . $core->pascalCased($filter['attribute']); $value = $item->{$method}(); if (isset($filter['condition']['like'])) { $value = mb_convert_case($value, MB_CASE_UPPER, "UTF-8"); $test = mb_convert_case($filter['condition']['like'], MB_CASE_UPPER, "UTF-8"); if (mb_strpos($value, mb_substr($test, 1, mb_strlen($test) - 2)) === false) { $conforms = false; break; } } elseif (isset($filter['condition']['eq'])) { $test = $filter['condition']['eq']; if ($value != $test) { $conforms = false; break; } } } if ($conforms) { $items[$key] = $item; } } $this->_items = $items; return $this; }
/** * Creates config file * * @param ConfigFile $cf Config file instance * * @return string */ public static function getConfigFile(ConfigFile $cf) { $crlf = isset($_SESSION['eol']) && $_SESSION['eol'] == 'win' ? "\r\n" : "\n"; $conf = $cf->getConfig(); // header $ret = '<?php' . $crlf . '/*' . $crlf . ' * Generated configuration file' . $crlf . ' * Generated by: phpMyAdmin ' . $GLOBALS['PMA_Config']->get('PMA_VERSION') . ' setup script' . $crlf . ' * Date: ' . date(DATE_RFC1123) . $crlf . ' */' . $crlf . $crlf; //servers if (!empty($conf['Servers'])) { $ret .= self::getServerPart($cf, $crlf, $conf['Servers']); unset($conf['Servers']); } // other settings $persistKeys = $cf->getPersistKeysMap(); foreach ($conf as $k => $v) { $k = preg_replace('/[^A-Za-z0-9_]/', '_', $k); $ret .= self::_getVarExport($k, $v, $crlf); if (isset($persistKeys[$k])) { unset($persistKeys[$k]); } } // keep 1d array keys which are present in $persist_keys (config.values.php) foreach (array_keys($persistKeys) as $k) { if (mb_strpos($k, '/') === false) { $k = preg_replace('/[^A-Za-z0-9_]/', '_', $k); $ret .= self::_getVarExport($k, $cf->getDefault($k), $crlf); } } $ret .= '?' . '>'; return $ret; }
public function getSchemeHTML() { $template = cmsTemplate::getInstance(); $scheme_html = $template->getSchemeHTML(); if (!$scheme_html) { return false; } if (!preg_match_all('/{([a-zA-Z0-9:_\\-]+)}/u', $scheme_html, $matches)) { return false; } $blocks = $matches[1]; foreach ($blocks as $block) { list($type, $value) = explode(':', $block); if ($type == 'position') { $replace_html = '<ul class="position" rel="' . $value . '" id="pos-' . $value . '"></ul>'; } if ($type == 'block') { if (mb_strpos($value, 'LANG_') === 0) { $value = constant($value); } $replace_html = '<div class="block"><span>' . $value . '</span></div>'; } if ($type == 'cell') { if (mb_strpos($value, 'LANG_') === 0) { $value = constant($value); } $replace_html = '<div class="cell"><span>' . $value . '</span></div>'; } $scheme_html = str_replace("{{$block}}", $replace_html, $scheme_html); } return $scheme_html; }
private function strpos($haystack, $needle, $offset = 0) { # echo "n: ->$needle<-, o: $offset len: ".strlen($haystack)." mblen: ".mb_strlen($haystack, mb_detect_encoding($haystack)); # echo " enc: ".mb_detect_encoding($haystack)."\n"; # echo "hs: $haystack, n: $needle, o: $offset\n"; return mb_strpos($haystack, $needle, $offset, mb_detect_encoding($haystack)); }
/** * Сохраняем сообщение об ошибке * @return Errors объект */ function set($errCodeName, $sErrorKey = null, $bSuccessfull = false, $sParam1 = null, $sParam2 = null, $sParam3 = null) { if ($errCodeName == 1) { $this->sm->assign('errno', 1); } if ($bSuccessfull) { $this->isSuccessfull = true; } if (is_string($errCodeName) && mb_strpos($errCodeName, ':') !== FALSE) { list($type, $param) = explode(':', $errCodeName); if (isset($this->lang['err_' . $type])) { $sMessage = $this->lang['err_' . $type]; $sParam1 = '<b>' . mb_strtolower($this->getMessage($param)) . '</b>'; } else { $sMessage = $this->getMessage($errCodeName); } } else { $sMessage = $this->getMessage($errCodeName); } $sMessage = str_replace(array('##$1##', '##$2##', '##$3##'), array($sParam1, $sParam2, $sParam3), $sMessage); if (isset($sErrorKey)) { $this->aErrors[$sErrorKey] = array('successfull' => $bSuccessfull, 'errno' => $errCodeName, 'msg' => $sMessage); } else { $this->aErrors[] = array('successfull' => $bSuccessfull, 'errno' => $errCodeName, 'msg' => $sMessage); } return $this; }
/** * Returns HTML code to include javascript file. * * @param array $files The list of js file to include * * @return string HTML code for javascript inclusion. */ private function _includeFiles($files) { $first_dynamic_scripts = ""; $dynamic_scripts = ""; $scripts = array(); foreach ($files as $value) { if (mb_strpos($value['filename'], "?") !== false) { if ($value['before_statics'] === true) { $first_dynamic_scripts .= "<script type='text/javascript' src='js/" . $value['filename'] . "'></script>"; } else { $dynamic_scripts .= "<script type='text/javascript' src='js/" . $value['filename'] . "'></script>"; } continue; } $include = true; if ($value['conditional_ie'] !== false && PMA_USR_BROWSER_AGENT === 'IE') { if ($value['conditional_ie'] === true) { $include = true; } else { if ($value['conditional_ie'] == PMA_USR_BROWSER_VER) { $include = true; } else { $include = false; } } } if ($include) { $scripts[] = "scripts[]=" . $value['filename']; } } $separator = PMA_URL_getArgSeparator(); $url = 'js/get_scripts.js.php' . PMA_URL_getCommon(array(), 'none') . $separator . implode($separator, $scripts); $static_scripts = sprintf('<script type="text/javascript" src="%s"></script>', htmlspecialchars($url)); return $first_dynamic_scripts . $static_scripts . $dynamic_scripts; }
function doSplitName($name) { $results = array(); $r = explode(' ', $name); $size = count($r); if (mb_strpos($r[0], '.') === false) { $results['salutation'] = ''; $results['first'] = $r[0]; } else { $results['salutation'] = $r[0]; $results['first'] = $r[1]; } if (mb_strpos($r[$size - 1], '.') === false) { $results['suffix'] = ''; } else { $results['suffix'] = $r[$size - 1]; } $start = $results['salutation'] ? 2 : 1; $end = $results['suffix'] ? $size - 2 : $size - 1; $last = ''; for ($i = $start; $i <= $end; $i++) { $last .= ' ' . $r[$i]; } $results['last'] = trim($last); return $results; }
function theme_strpos($source, $target) { if (function_exists('mb_strpos')) { return mb_strpos($source, $target); } return strpos($source, $target); }
protected function initValidator() { $class = $this->getValidatorClass(); if ($class) { $validator = new $class(); $this->validator_messages = $validator->messages(); $this->validator_rules = $validator->rules(); foreach ($this->validator_rules as $element_name => $element_rules) { if (false !== mb_strpos($element_name, '.')) { $element_name = str_replace('.', '][', $element_name) . ']'; $e = explode(']', $element_name, 2); $element_name = implode('', $e); } foreach ($this->getElementsByName($element_name) as $el) { $element_rules = explode('|', $element_rules); foreach ($element_rules as $rule) { $_rule = explode(':', $rule); $rule_name = Arr::get($_rule, 0); $rule_params = Arr::get($_rule, 1); $rule_params = explode(',', $rule_params); $method = Str::camel('rule_' . $rule_name); if (method_exists($el, $method)) { call_user_func_array([$el, $method], $rule_params); } } } } } return $this; }
private static function loadSerializationPolicy($moduleBaseURL, $strongName) { // The request can tell you the path of the web app relative to the // container root $contextPath = parse_url($_SERVER['SCRIPT_NAME'], PHP_URL_PATH); if (!is_null($moduleBaseURL)) { $modulePath = parse_url($moduleBaseURL, PHP_URL_PATH); } /* * Check that the module path must be in the same web app as the servlet * itself. If you need to implement a scheme different than this, override * this method. */ if (empty($modulePath) || mb_strpos($modulePath, $contextPath) != 0) { $message = 'ERROR: The module path requested, ' . $modulePath . ', is not in the same web application as this servlet, ' . $contextPath . '. Your module may not be properly configured or your client and server code maybe out of date.'; echo $message; } else { // Strip off the context path from module base URL. It should be // strict prefix //$contextRelativePath = mb_substr($modulePath, mb_strlen($contextPath)); $contextRelativePath = GWT::getModuleBasePath(); $serializationPolicyFilePath = SerializationPolicyLoader::getSerializationPolicyFileName($contextRelativePath . $strongName); // Open the RPC resource file and read its content try { $serializationPolicy = SerializationPolicyLoader::loadFromFile($serializationPolicyFilePath); } catch (ParseException $e) { echo "ERROR: Failed to parse the policy file '{$serializationPolicyFilePath}'", $e; } return $serializationPolicy; } }
private static function detectContext() { if (self::$context !== null) { return; } if (defined('OW_USE_CONTEXT')) { switch (true) { case OW_USE_CONTEXT == 1: self::$context = self::CONTEXT_DESKTOP; return; case OW_USE_CONTEXT == 1 << 1: self::$context = self::CONTEXT_MOBILE; return; case OW_USE_CONTEXT == 1 << 2: self::$context = self::CONTEXT_API; return; } } $context = self::CONTEXT_DESKTOP; try { $isSmart = UTIL_Browser::isSmartphone(); } catch (Exception $e) { return; } if (defined('OW_CRON')) { $context = self::CONTEXT_DESKTOP; } else { if (self::getSession()->isKeySet(OW_Application::CONTEXT_NAME)) { $context = self::getSession()->get(OW_Application::CONTEXT_NAME); } else { if ($isSmart) { $context = self::CONTEXT_MOBILE; } } } if (defined('OW_USE_CONTEXT')) { if ((OW_USE_CONTEXT & 1 << 1) == 0 && $context == self::CONTEXT_MOBILE) { $context = self::CONTEXT_DESKTOP; } if ((OW_USE_CONTEXT & 1 << 2) == 0 && $context == self::CONTEXT_API) { $context = self::CONTEXT_DESKTOP; } } if ((bool) OW::getConfig()->getValue('base', 'disable_mobile_context') && $context == self::CONTEXT_MOBILE) { $context = self::CONTEXT_DESKTOP; } //temp API context detection //TODO remake $uri = UTIL_Url::getRealRequestUri(OW::getRouter()->getBaseUrl(), $_SERVER['REQUEST_URI']); if (mb_strstr($uri, '/')) { if (trim(mb_substr($uri, 0, mb_strpos($uri, '/'))) == 'api') { $context = self::CONTEXT_API; } } else { if (trim($uri) == 'api') { $context = self::CONTEXT_API; } } self::$context = $context; }
/** * Normalizes directory/file separators. * * @since 150422 Rewrite. * * @param string $dir_file Directory/file path. * @param bool $allow_trailing_slash Defaults to FALSE. * If TRUE; and `$dir_file` contains a trailing slash; we'll leave it there. * * @return string Normalized directory/file path. */ public function nDirSeps($dir_file, $allow_trailing_slash = false) { $dir_file = (string) $dir_file; if (!isset($dir_file[0])) { return ''; // Catch empty string. } if (mb_strpos($dir_file, '://' !== false)) { if (preg_match('/^(?P<stream_wrapper>[a-zA-Z0-9]+)\\:\\/\\//u', $dir_file, $stream_wrapper)) { $dir_file = preg_replace('/^(?P<stream_wrapper>[a-zA-Z0-9]+)\\:\\/\\//u', '', $dir_file); } } if (mb_strpos($dir_file, ':' !== false)) { if (preg_match('/^(?P<drive_letter>[a-zA-Z])\\:[\\/\\\\]/u', $dir_file)) { $dir_file = preg_replace_callback('/^(?P<drive_letter>[a-zA-Z])\\:[\\/\\\\]/u', create_function('$m', 'return mb_strtoupper($m[0]);'), $dir_file); } } $dir_file = preg_replace('/\\/+/u', '/', str_replace([DIRECTORY_SEPARATOR, '\\', '/'], '/', $dir_file)); $dir_file = $allow_trailing_slash ? $dir_file : rtrim($dir_file, '/'); // Strip trailing slashes. if (!empty($stream_wrapper[0])) { $dir_file = mb_strtolower($stream_wrapper[0]) . $dir_file; } return $dir_file; // Normalized now. }
/** * Maps input and output character set names to corresponding AIX ones * * @param string $in_charset input character set * @param string $out_charset output character set * * @return array array of mapped input and output character set names */ function PMA_convertAIXMapCharsets($in_charset, $out_charset) { global $gnu_iconv_to_aix_iconv_codepage_map; // Check for transliteration argument at the end of output character set name $translit_search = mb_strpos(mb_strtolower($out_charset), '//translit'); $using_translit = !($translit_search === false); // Extract "plain" output character set name // (without any transliteration argument) $out_charset_plain = $using_translit ? mb_substr($out_charset, 0, $translit_search) : $out_charset; // Transform name of input character set (if found) $in_charset_exisits = array_key_exists(mb_strtolower($in_charset), $gnu_iconv_to_aix_iconv_codepage_map); if ($in_charset_exisits) { $in_charset = $gnu_iconv_to_aix_iconv_codepage_map[mb_strtolower($in_charset)]; } // Transform name of "plain" output character set (if found) $out_charset_plain_exists = array_key_exists(mb_strtolower($out_charset_plain), $gnu_iconv_to_aix_iconv_codepage_map); if ($out_charset_plain_exists) { $out_charset_plain = $gnu_iconv_to_aix_iconv_codepage_map[mb_strtolower($out_charset_plain)]; } // Add transliteration argument again (exactly as specified by user) if used // Build the output character set name that we will use /* Not needed because always overwritten $out_charset = ($using_translit ? $out_charset_plain . $pmaString->substr($out_charset, $translit_search) : $out_charset_plain); */ // NOTE: Transliteration not supported; we will use the "plain" // output character set name $out_charset = $out_charset_plain; return array($in_charset, $out_charset); }
/** * * {@inheritDoc} * * @see \Nia\Logging\LoggerInterface::log($message, $context) */ public function log(string $message, array $context) : LoggerInterface { if (mb_strpos($message, $this->needle) === false) { $this->logger->log($message, $context); } return $this; }
/** * Parses a long option token and returns an array of data * * @param string $token The token to parse * @param array $remainingTokens The list of remaining tokens * @return array The name of the option mapped to its value * @throws RuntimeException Thrown if the option could not be parsed */ protected function parseLongOption($token, array &$remainingTokens) { if (mb_substr($token, 0, 2) !== "--") { throw new RuntimeException("Invalid long option \"{$token}\""); } // Trim the "--" $option = mb_substr($token, 2); if (mb_strpos($option, "=") === false) { /** * The option is either of the form "--foo" or "--foo bar" or "--foo -b" or "--foo --bar" * So, we need to determine if the option has a value */ $nextToken = array_shift($remainingTokens); // Check if the next token is also an option if (mb_substr($nextToken, 0, 1) == "-" || empty($nextToken)) { // The option must have not had a value, so put the next token back array_unshift($remainingTokens, $nextToken); return [$option, null]; } // Make it "--foo=bar" $option .= "=" . $nextToken; } list($name, $value) = explode("=", $option); $value = $this->trimQuotes($value); return [$name, $value]; }
function VerifyTransactionDate($TranDate, $i, $Errors, $db) { $sql = "SELECT confvalue FROM config WHERE confname='" . DefaultDateFormat . "'"; $result = DB_query($sql, $db); $myrow = DB_fetch_array($result); $DateFormat = $myrow[0]; if (mb_strpos($TranDate, '/') > 0) { $DateArray = explode('/', $TranDate); } elseif (mb_strpos($TranDate, '.') > 0) { $DateArray = explode('.', $TranDate); } if ($DateFormat == 'd/m/Y') { $Day = $DateArray[0]; $Month = $DateArray[1]; $Year = $DateArray[2]; } elseif ($DateFormat == 'm/d/Y') { $Day = $DateArray[1]; $Month = $DateArray[0]; $Year = $DateArray[2]; } elseif ($DateFormat == 'Y/m/d') { $Day = $DateArray[2]; $Month = $DateArray[1]; $Year = $DateArray[0]; } elseif ($DateFormat == 'd.m.Y') { $Day = $DateArray[0]; $Month = $DateArray[1]; $Year = $DateArray[2]; } if (!checkdate(intval($Month), intval($Day), intval($Year))) { $Errors[$i] = InvalidCurCostDate; } return $Errors; }
protected function _newline_break($text) { if (($i = mb_strpos($text, "\n")) === false) { return false; } return $i + 1; }
function test_encoding($path) { static $ur_exclude = array('lang/de/ocstyle/search1/search.result.caches', 'lib2/b2evo-captcha', 'lib2/HTMLPurifier', 'lib2/html2text.class.php', 'lib2/imagebmp.inc.php', 'lib2/Net/IDNA2', 'lib2/smarty'); $contents = file_get_contents($path, false, null, 0, 2048); $ur = stripos($contents, "Unicode Reminder"); if ($ur) { if (mb_trim(mb_substr($contents, $ur + 17, 2)) != "メモ") { $ur = mb_stripos($contents, "Unicode Reminder"); if (mb_trim(mb_substr($contents, $ur + 17, 2)) != "メモ") { echo "Bad Unicode Reminder found in {$path}: " . mb_trim(mb_substr($contents, $ur + 17, 2)) . "\n"; } else { echo "Unexpected non-ASCII chars (BOMs?) in header of {$path}\n"; } } } else { $ok = false; foreach ($ur_exclude as $exclude) { if (mb_strpos($path, $exclude) === 0) { $ok = true; } } if (!$ok) { echo "No Unicode Reminder found in {$path}\n"; } } }
/** * @param string $line * @param int $lineNumber * @return string */ private function trimOutputLine($line, $lineNumber) { if (strlen($line) < 80) { return $line; } $positionsWordColor = []; $positionsResetColor = []; $parts = []; $lastPos = 0; //iterate over all WORD_COLORs and save the positions into $positionsWordColor while (($lastPos = mb_strpos($line, static::WORD_COLOR, $lastPos)) !== false) { $positionsWordColor[] = $lastPos; $lastPos = $lastPos + mb_strlen(static::WORD_COLOR); } $lastPos = 0; //iterate over all RESET_COLORs and save the positions into $positionsResetColor while (($lastPos = mb_strpos($line, static::RESET_COLOR, $lastPos)) !== false) { $positionsResetColor[] = $lastPos; $lastPos = $lastPos + mb_strlen(static::RESET_COLOR); } foreach ($positionsWordColor as $pos) { do { $pos2 = array_shift($positionsResetColor); } while ($pos2 < $pos); $pos -= static::SPACE_BEFORE; $pos2 += static::SPACE_AFTER; $part = ' ' . $lineNumber . static::COLON_COLOR . ':' . static::RESET_COLOR; $part .= $pos + static::SPACE_BEFORE . static::COLON_COLOR . ':' . static::RESET_COLOR; $part .= ' ' . mb_substr($line, $pos, $pos2 - $pos) . static::RESET_COLOR; $parts[] = $part; } return implode(PHP_EOL, $parts); }
/** * Minimizes the given URL to a maximum length * * @param string $url the url * @param int|null $max the maximum length * @param array $options * - placeholder * @return string the manipulated url (+ eventuell ...) */ public function minimizeUrl($url, $max = null, array $options = []) { // check if there is nothing to do if (empty($url) || mb_strlen($url) <= (int) $max) { return $url; } // http:// etc has not to be displayed, so $url = $this->stripProtocol($url); // cut the parameters if (mb_strpos($url, '/') !== false) { $url = strtok($url, '/'); } // return if the url is short enough if (mb_strlen($url) <= (int) $max) { return $url; } // otherwise cut a part in the middle (but only if long enough!) // TODO: more dynamically $placeholder = CHAR_HELLIP; if (!empty($options['placeholder'])) { $placeholder = $options['placeholder']; } $end = mb_substr($url, -5, 5); $front = mb_substr($url, 0, (int) $max - 8); return $front . $placeholder . $end; }
public function maybe_adbuster($file, $filesize_check = true, $file_examination = true) { //checkout the file extension - we are looking for htm and html files only $path_parts = pathinfo($file); if (false === isset($path_parts['extension'])) { return false; } $suspicious_extensions = array('html', 'htm'); $extension = mb_strtolower($path_parts['extension']); if (false === in_array($extension, $suspicious_extensions)) { return false; } //first - check on the file size, frame busters are usually small files if (true === $filesize_check && filesize($file) > 1024) { return false; } //some strings in name are highly suspicious - let's flag such files $suspicious_strings = array('buster'); foreach ($suspicious_strings as $string) { if (false !== mb_strpos(mb_strtolower($path_parts['basename']), $string)) { return true; } } if (true === $file_examination) { //ok, so the file is relatively small and it is a static HTML file - that's suspicious, let's do some more tests return $this->possible_adbuster_body_check(file_get_contents($file)); } return false; }