/**
  * checks whether the passed email-address is valid / following a pattern
  * @todo is this an exact representation of the RFC 2822?
  * @todo this should be checked: what about umlaut-domains and tld like '.museum'?
  * @see http://tools.ietf.org/html/rfc2822
  *
  * @param <string> a all lowercase email adress to test
  * @return <boolean> answer to "is the passed over email valid?""
  */
 function isValidEmail($email)
 {
     if (mb_eregi("^[_a-z0-9-]+(\\.[_a-z0-9-]+)*@[a-z0-9-]+(\\.[a-z0-9-]+)*(\\.[a-z]{2,3})\$", $email)) {
         return true;
     }
     return false;
 }
Ejemplo n.º 2
0
function cs2cs_core2($lat, $lon, $to)
{
    $descriptorspec = array(0 => array("pipe", "r"), 1 => array("pipe", "w"), 2 => array("pipe", "w"));
    if (mb_eregi('^[a-z0-9_ ,.\\+\\-=]*$', $to) == 0) {
        die("invalid arguments in command: " . $to . "\n");
    }
    $command = CS2CS . " +proj=latlong +ellps=WGS84 +to " . $to;
    $process = proc_open($command, $descriptorspec, $pipes);
    if (is_resource($process)) {
        fwrite($pipes[0], $lon . " " . $lat);
        fclose($pipes[0]);
        $stdout = stream_get_contents($pipes[1]);
        fclose($pipes[1]);
        $stderr = stream_get_contents($pipes[2]);
        fclose($pipes[2]);
        //
        // $procstat = proc_get_status($process);
        //
        // neither proc_close nor proc_get_status return reasonable results with PHP5 and linux 2.6.11,
        // see http://bugs.php.net/bug.php?id=32533
        //
        // as temporary (?) workaround, check stderr output.
        // (Vinnie, 2006-02-09)
        if ($stderr) {
            die("proc_open() failed:<br />command='{$command}'<br />stderr='" . $stderr . "'");
        }
        proc_close($process);
        return mb_split("\t|\n| ", mb_trim($stdout));
    } else {
        die("proc_open() failed, command={$command}\n");
    }
}
Ejemplo n.º 3
0
 /**
  * マルチバイト対応で正規表現マッチする
  *
  * @param string $pattern マッチ文字列。SJISで入ってくる。
  * @param string $target  検索対象文字列。SJISで入ってくる。
  * @param string $zenhan  全角/半角の区別を完全になくす
  * (これをオンにすると、メモリの使用量が倍くらいになる。速度負担はそれほどでもない)
  */
 public static function filterMatch($pattern, $target, $zenhan = true)
 {
     // 全角/半角を(ある程度)区別なくマッチ
     if ($zenhan) {
         // 全角/半角を 完全に 区別なくマッチ
         $pattern = self::getPatternToHan($pattern);
         $target = self::getPatternToHan($target, true);
     } else {
         // 全角/半角を ある程度 区別なくマッチ
         $pattern = self::getPatternZenHan($pattern);
     }
     // HTML要素にマッチさせないための否定先読みパターンを付加
     $pattern = '(' . $pattern . ')(?![^<]*>)';
     if (P2_MBREGEX_AVAILABLE == 1) {
         $result = @mb_eregi($pattern, $target);
         // None|Error:false
     } else {
         // UTF-8に変換してから処理する
         $pattern_utf8 = '/' . mb_convert_encoding($pattern, 'UTF-8', 'CP932') . '/iu';
         $target_utf8 = mb_convert_encoding($target, 'UTF-8', 'CP932');
         $result = @preg_match($pattern_utf8, $target_utf8);
         // None:0, Error:false
         //$result = mb_convert_encoding($result, 'CP932', 'UTF-8');
     }
     if (!$result) {
         return false;
     } else {
         return true;
     }
 }
 public static function path2array_paquet($_path, $lg1, $lg2, $mesure)
 {
     $array_lg = array($lg1, $lg2);
     sort($array_lg);
     $data = Tool_files::file_load($_path);
     $f = Tool_files::csv2array_line($data, "\n");
     $array_paquet = array();
     $tmp = array();
     $flag_vu = false;
     foreach ($f as $line) {
         if (mb_eregi("[:alnum:]", $line)) {
             $tmp[] = trim($line);
         } elseif (len($tmp) > 0) {
             list($dist, $rep) = mb_split(" : ", $tmp[0]);
             list($score, $l1, $l2) = mb_split(" ", $rep);
             $score = trim($score);
             $dist = trim($dist);
             $l1 = trim($l1);
             $l2 = trim($l2);
             if ($dist == $mesure) {
                 if ($l1 == $lg2 and $l2 == $lg1 or $lg1 == $l1 and $lg2 == $l2) {
                     $flag_vu = true;
                     list($str1, $rep1) = self::line2str_rep($tmp[1]);
                     list($str2, $rep2) = self::line2str_rep($tmp[2]);
                     $array_paquet[] = array('score' => $score, $l1 => $rep1, $l2 => $rep2, "str_{$l1}" => $str1, "str_{$l2}" => $str2);
                 }
             } elseif ($flag_vu) {
                 break;
             }
             $tmp = array();
         }
     }
     return $array_paquet;
 }
Ejemplo n.º 5
0
 public function is_seo_visit()
 {
     if (isset($_SERVER['HTTP_REFERER'])) {
         $referer = $_SERVER['HTTP_REFERER'];
         return mb_eregi('www.google.', $referer);
     }
 }
Ejemplo n.º 6
0
 function peg_regex_test($pattern, $string)
 {
     if (substr($pattern, -1) == 'i') {
         return mb_eregi(substr($pattern, 1, -2), $string);
     } else {
         return mb_ereg(substr($pattern, 1, -1), $string);
     }
 }
Ejemplo n.º 7
0
 /**
  * Alphanumeric characters (including full stop [.] minus [-], underscore [_] and space [ ])
  * 
  * @param mixed $varValue The value to be validated
  * 
  * @return boolean True if the value is alphanumeric
  */
 public static function isAlphanumeric($varValue)
 {
     if (function_exists('mb_eregi')) {
         return mb_eregi('^[[:alnum:] \\._-]*$', $varValue);
     } else {
         return preg_match('/^[\\pN\\pL \\._-]*$/u', $varValue);
     }
 }
Ejemplo n.º 8
0
/**
 * @param $pattern
 * @param $substring
 * @param string $options
 * @return array
 */
function match($pattern, $substring, $options = 'ms')
{
    $result = [];
    if (function_exists('mb_ereg_search')) {
        mb_eregi($pattern, $substring, $result);
        return $result;
    }
    preg_match($pattern, $substring, $result);
    return $result;
}
Ejemplo n.º 9
0
function uppsite_match($pattern, $subject)
{
    $ret = array();
    if (function_exists('mb_eregi')) {
        mb_eregi($pattern, $subject, $ret);
    } else {
        preg_match("/" . $pattern . "/", $subject, $ret);
    }
    return $ret;
}
Ejemplo n.º 10
0
 function email($string)
 {
     if (mb_strlen($string) > 200) {
         return false;
     }
     if (mb_eregi("^[a-z0-9\\._-]+@[a-z0-9\\._-]+\\.[a-z]{2,4}\$", $string)) {
         return true;
     } else {
         return false;
     }
 }
 function open($command)
 {
     $descriptorspec = array(0 => array("pipe", "r"), 1 => array("pipe", "w"), 2 => array("pipe", "w"));
     if (mb_eregi('^[a-z0-9_ ,\\+\\-=\\.]*$', $command) == 0) {
         die("invalid arguments in command: " . $command . "\n");
     }
     $command = BIN_CS2CS . " " . $command;
     $this->process = proc_open($command, $descriptorspec, $this->pipes);
     if (!is_resource($this->process)) {
         die("proc_open() failed, command={$command}\n");
     }
 }
Ejemplo n.º 12
0
/**
 * A PHP implementation of the Quicksilver string score algorithm. Requires “MBString” extension (for unicode support).
 * 
 * Quicksilver URL: http://docs.blacktree.com/quicksilver/development/string_ranking
 * 
 * @param       string      Text to match against.
 * @param       search      Text to try to match with.
 * @param       offset      Offset to start matching from.
 * @return      float       Score (between 0.0 and 1.0).
 * @category    Strings
 */
function strscore($string, $search, $offset = 0)
{
    // Save some time from calling functions
    $stringlen = mb_strlen($string);
    $searchlen = mb_strlen($search);
    if ($searchlen == 0) {
        return 0.9;
    }
    if ($searchlen > $stringlen) {
        return 0;
    }
    // Search for smaller and smaller portions
    for ($i = $searchlen; $i > 0; --$i) {
        $part = mb_substr($search, 0, $i);
        $index = mb_stripos($string, $part);
        if ($index === FALSE) {
            continue;
        }
        if ($index + $searchlen > $stringlen + $offset) {
            continue;
        }
        $next = mb_substr($string, $index + mb_strlen($part));
        $nextlen = mb_strlen($next);
        $abbr = '';
        if ($i < $searchlen) {
            $abbr = mb_substr($search, $i);
        }
        // Search for the rest of the abbreviation (that didn't match)
        $rem = strscore($next, $abbr, $offset + $index);
        if ($rem > 0) {
            $score = $stringlen - $nextlen;
            if ($index != 0) {
                if (mb_eregi('\\s', mb_substr($string, $index - 1, 1))) {
                    for ($j = $index - 2; $j > -1; --$j) {
                        if (mb_eregi('\\s', mb_substr($string, $j, 1))) {
                            $score -= 1.0;
                        } else {
                            $score -= 0.15;
                        }
                    }
                } else {
                    $score -= $index;
                }
            }
            $score += $rem * $nextlen;
            $score /= $stringlen;
            return (double) $score;
        }
    }
    return 0;
}
Ejemplo n.º 13
0
 public static function getFullRuDateFromMysqlDate($mysqlDate)
 {
     $date = null;
     if (mb_eregi('^\\d{4,}-\\d{2}-\\d{2}$', $mysqlDate)) {
         $date = DateTime::createFromFormat('Y-m-d', $mysqlDate);
     } elseif (mb_eregi('^\\d{4,}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2}$', $mysqlDate)) {
         $date = DateTime::createFromFormat('Y-m-d H:i:s', $mysqlDate);
     }
     if (is_null($date)) {
         return false;
     } else {
         return $date->format('j') . ' ' . self::translateMonthRuEn($date->format('F')) . ' ' . $date->format('Y');
     }
 }
Ejemplo n.º 14
0
 public function getLink($link)
 {
     if (mb_eregi("^https\\:\\/\\/docs.google.com\\/", $link)) {
         return '/doc?src=' . $link . '';
     }
     if (mb_eregi("^(https?|ftp)\\:\\/\\/", $link)) {
         return $link;
     }
     if (is_numeric($link)) {
         return "/view/" . $link;
     }
     if ($link == "") {
         return "http://" . $_SERVER['HTTP_HOST'];
     }
     return "/" . $link;
 }
function smarty_outputfilter_highlight($source, &$smarty)
{
    global $prefs;
    $highlight = $_REQUEST['highlight'];
    if (isset($prefs['feature_referer_highlight']) && $prefs['feature_referer_highlight'] == 'y') {
        $refererhi = _refererhi();
        if (isset($refererhi) && !empty($refererhi)) {
            if (isset($highlight) && !empty($highlight)) {
                $highlight = $highlight . " " . $refererhi;
            } else {
                $highlight = $refererhi;
            }
        }
    }
    if (!isset($highlight) || empty($highlight)) {
        return $source;
    }
    $matches = array();
    if (strstr($source, 'id="rightcolumn"')) {
        if (function_exists('mb_eregi')) {
            // UTF8 support enabled
            mb_eregi('^(.*\\s+id="centercolumn"[^>]*>)(.*)(<td[^>]*\\s+id="rightcolumn".*)$', $source, $matches);
        } else {
            // This may not work at all with UTF8 chars
            preg_match('~(.* id="centercolumn"[^>]*>)(.*)(<td[^>]* id="rightcolumn".*)~xsi', $source, $matches);
        }
    } elseif (function_exists('mb_eregi')) {
        if (!mb_eregi('^(.*\\s+id="centercolumn"[^>]*>)(.*)$', $source, $matches)) {
            return $source;
        }
    } elseif (!preg_match('~(.* id="centercolumn"[^>]*>)(.*)~xsi', $source, $matches)) {
        return $source;
    } else {
        $matches[3] = '';
    }
    // Avoid highlight parsing in unknown cases where $matches[2] is empty, which will result in an empty page.
    if ($matches[2] != '') {
        $source = preg_replace_callback('~(?:<head>.*</head>                          # head blocks
	      |<div[^>]*nohighlight.*</div><!--nohighlight--> # div with nohightlight
	      |<script[^>]+>.*</script>                     # script blocks
	      |<a[^>]*onmouseover.*onmouseout[^>]*>            # onmouseover (user popup)
	      |<[^>]*>                                      # all html tags
	      |(' . _enlightColor($highlight) . '))~xsiU', '_enlightColor', $matches[2]);
    }
    return $matches[1] . $source . $matches[3];
}
Ejemplo n.º 16
0
function lire_aux_lens($filename)
{
    ob_start();
    readfile($filename);
    $source = ob_get_contents();
    ob_end_clean();
    $xmpdata_start = strpos($source, "<x:xmpmeta");
    $xmpdata_end = strpos($source, "</x:xmpmeta>");
    $xmplenght = $xmpdata_end - $xmpdata_start;
    $xmpdata = substr($source, $xmpdata_start, $xmplenght + 12);
    if (mb_eregi("aux:Lens=\"([^\"]*)\"", $xmpdata, $regs)) {
        return $regs[1];
    }
    if (mb_eregi("<aux:Lens>([^<]*)<\\/aux:Lens>", $xmpdata, $regs)) {
        return $regs[1];
    }
}
Ejemplo n.º 17
0
 public static function check(FormChecker_Field &$oField, $params)
 {
     $value = $oField->getValue();
     if (is_null($value) && !$oField->isRequired()) {
         return true;
     }
     if (!mb_eregi('^[a-z0-9\\._-]+@[a-z0-9\\._-]+$', $value)) {
         //      if ( !mb_eregi( '^[-!#$%&\'*+\\./0-9=?A-Z^_`a-z{|}~]+'.'@'.'[-!#$%&\'*+\\/0-9=?A-Z^_`a-z{|}~]+\.'.'[-!#$%&\'*+\\./0-9=?A-Z^_`a-z{|}~]+$', $value ) )
         return $oField->raiseError('Votre email n\'est pas correct');
     } else {
         $tmp = explode('@', $value);
         if (!is_array($tmp)) {
             return false;
         } elseif (!dns_check_record($tmp[1], 'MX')) {
             return $oField->raiseError('Votre nom de domaine n\'est pas valide, veuillez vérifier votre saisie');
         }
     }
     return true;
 }
Ejemplo n.º 18
0
 /**
  * Removes previews from previews directory.
  * If no arguments passed - removes ALL available previews.
  *
  * @param string $originalImage
  */
 public static function removePreviews($originalImage = null)
 {
     $dir = self::getPreviewsDir();
     if (file_exists($dir) && is_dir($dir)) {
         $md5 = null;
         if (!is_null($originalImage)) {
             $md5 = md5_file($originalImage);
         }
         $previews = scandir($dir);
         array_shift($previews);
         //.
         array_shift($previews);
         //..
         foreach ($previews as $preview) {
             if (is_file($dir . $preview) && Admin::isImageFile($preview) && (is_null($originalImage) || mb_eregi('^' . $md5, $preview))) {
                 unlink($dir . $preview);
             }
         }
     }
 }
Ejemplo n.º 19
0
 public static function check(FormChecker_Field &$oField, $params)
 {
     $value = $oField->getValue();
     if (is_null($value) && !$oField->isRequired()) {
         return true;
     }
     switch ($params) {
         case 'YYYY-mm-dd':
         case 'Y-m-d':
             $regPattern = '^[0-9]{4}-[0-9]{2}-[0-9]{2}$';
             break;
         case 'jj-mm-aaaa':
         case 'd-m-Y':
             $regPattern = '^[0-9]{2}-[0-9]{2}-[0-9]{4}$';
             break;
     }
     if (!mb_eregi($regPattern, $value)) {
         return $oField->raiseError('Mauvais format de date : ' . $params);
     }
     return true;
 }
Ejemplo n.º 20
0
Archivo: StrCtl.php Proyecto: poppen/p2
 /**
  * マルチバイト対応で正規表現マッチ判定する
  *
  * @static
  * @access  public
  * @param   string  $pattern    マッチ文字列。SJISで入ってくる。
  * @param   string  $targetHtml 検索対象文字列。SJISで入ってくる。HTML
  * @param   int     $zenhan     1:全角/半角の区別を完全になくす
  *                             (これをオンにすると、メモリの使用量が倍くらいになる。速度負担はそれほどでもない)
  *                              2:全角/半角を ある程度 区別なくマッチ
  *                              0:全角/半角を 区別しない
  * @return  string|false      マッチしたらマッチ文字列を、マッチしなかったらfalseを返す
  */
 function filterMatch($pattern, $targetHtml, $zenhan = 1)
 {
     global $res_filter;
     if ($res_filter['method'] == 'regex') {
         $pattern = StrCtl::replaceRegexAnyChar($pattern);
     }
     // IDフィルタリング時は、全角半角を常に区別しない
     if ($res_filter['field'] == 'id' && $res_filter['method'] == 'just') {
         $zenhan = 0;
     }
     if ($zenhan == 1) {
         // 全角/半角を 完全に 区別なくマッチ
         $pattern = StrCtl::getPatternToHan($pattern);
         $targetHtml = StrCtl::getPatternToHan($targetHtml, true);
     } elseif ($zenhan == 2) {
         // 全角/半角を ある程度 区別なくマッチ
         $pattern = StrCtl::getPatternZenHan($pattern);
         // 正規表現パターン
     }
     // HTML要素にマッチさせないための否定先読みパターンを付加
     $pattern = $pattern . '(?![^<]*>)';
     if (P2_MBREGEX_AVAILABLE == 1) {
         $result = mb_eregi($pattern, $targetHtml, $matches);
         // None|Error:FALSE
     } else {
         // UTF-8に変換してから処理する
         $pattern = str_replace('/', '\\/', $pattern);
         $pattern_utf8 = '/' . mb_convert_encoding($pattern, 'UTF-8', 'SJIS-win') . '/iu';
         $target_utf8 = mb_convert_encoding($targetHtml, 'UTF-8', 'SJIS-win');
         $result = preg_match($pattern_utf8, $target_utf8, $matches);
         // None:0, Error:FALSE
         //$result = mb_convert_encoding($result, 'SJIS-win', 'UTF-8');
     }
     if (!$result) {
         return false;
     }
     return $matches[0];
 }
Ejemplo n.º 21
0
 /**
  * Determines if $char is really a char.
  *
  * @param string $char
  * @return bool
  * @todo rewrite me to charcode range ! ;)
  * @access private
  */
 protected function isChar($char)
 {
     return extension_loaded('mbstring') && phpQuery::$mbstringSupport ? mb_eregi('\\w', $char) : preg_match('@\\w@', $char);
 }
Ejemplo n.º 22
0
 public static function getFilterParams()
 {
     $prefix = Admin::getConfig('filterQueryPrefix');
     $params = [];
     if (!empty($_GET)) {
         $regs = [];
         foreach ($_GET as $key => $value) {
             if (mb_eregi('^' . $prefix . self::$prefixSeparator . '(\\w+)', $key, $regs)) {
                 $params[$regs[1]] = $value;
             }
         }
     }
     return $params;
 }
/**
 * Note: Try to avoid using this function. Use api_preg_match() with Perl-compatible regular expression syntax.
 *
 * Executes a regular expression match, ignoring case, with extended multibyte support.
 * By default this function uses the platform character set.
 * @param string $pattern            The regular expression pattern.
 * @param string $string            The searched string.
 * @param array $regs (optional)    If specified, by this passed by reference parameter an array containing found match and its substrings is returned.
 * @return mixed                    1 if match is found, FALSE if not. If $regs has been specified, byte-length of the found match is returned, or FALSE if no match has been found.
 * This function is aimed at replacing the functions eregi() and mb_eregi() for human-language strings.
 * @link http://php.net/manual/en/function.eregi
 * @link http://php.net/manual/en/function.mb-eregi
 */
function api_eregi($pattern, $string, &$regs = null)
{
    $count = func_num_args();
    $encoding = _api_mb_regex_encoding();
    if (_api_mb_supports($encoding)) {
        if ($count < 3) {
            return @mb_eregi($pattern, $string);
        }
        return @mb_eregi($pattern, $string, $regs);
    }
    if (MBSTRING_INSTALLED && api_is_encoding_supported($encoding)) {
        global $_api_encoding;
        $_api_encoding = $encoding;
        _api_mb_regex_encoding('UTF-8');
        if ($count < 3) {
            $result = @mb_eregi(api_utf8_encode($pattern, $encoding), api_utf8_encode($string, $encoding));
        } else {
            $result = @mb_eregi(api_utf8_encode($pattern, $encoding), api_utf8_encode($string, $encoding), $regs);
            $regs = _api_array_utf8_decode($regs);
        }
        _api_mb_regex_encoding($encoding);
        return $result;
    }
    if ($count < 3) {
        return eregi($pattern, $string);
    }
    return eregi($pattern, $string, $regs);
}
Ejemplo n.º 24
0
 /**
  * Valid folder alias name
  *
  * @param mixed $varValue The value to be validated
  *
  * @return boolean True if the value is a valid folder alias name
  */
 public static function isFolderAlias($varValue)
 {
     if (function_exists('mb_eregi')) {
         return mb_eregi('^[[:alnum:]\\/\\._-]+$', $varValue);
     } else {
         return preg_match('/^[\\w\\/.-]+$/u', $varValue);
     }
 }
Ejemplo n.º 25
0
 /**
  * Internal method, which
  * is also called recursively if needed
  * It wraps the text of text nodes into
  * the special 'highliting' tag (usually 'em')
  * It skips text inside the elements that should
  * be excluded (like 'i' and 'em' tags)
  *
  * @param \DomNode $o
  */
 protected function hilight(\DOMNode $o = null)
 {
     $o = $o ? $o : $this->getElementsByTagName('body')->item(0);
     d("\nNode name: " . $o->nodeName . ' type: ' . $o->nodeType . ' value: ' . $o->nodeValue);
     $nodeName = strtolower($o->nodeName);
     /**
      * Skip nodes that are already the "a" node (link)
      * and skip tags that are already <em> or <i> tags
      */
     if (!in_array($nodeName, $this->aExcluded) && !in_array($nodeName, array('em', 'i'))) {
         if (XML_TEXT_NODE == $o->nodeType) {
             d('passing node to hiInNode');
             /**
              * Now replace the Node $o with the
              * new CDATA node (CDATA node will simulate innerHTML)
              */
             if (\mb_eregi('\\b(' . $this->pattern . ')\\b', $o->nodeValue)) {
                 $ret = \mb_eregi_replace('\\b(' . $this->pattern . ')\\b', '<' . $this->hlTag . ' class="' . $this->hlClass . '">' . '\\1' . '</' . $this->hlTag . '>', $o->nodeValue);
                 $CDATA = $o->ownerDocument->createCDATASection($ret);
                 $o->parentNode->replaceChild($CDATA, $o);
                 $this->bCDATA = true;
             }
         }
         /**
          * If node has children then recursively
          * call this method for all child nodes
          */
         $oChildred = $o->childNodes;
         if ($oChildred && $oChildred->length > 0) {
             for ($i = 0; $i < $oChildred->length; $i += 1) {
                 $this->hilight($oChildred->item($i));
             }
         }
     }
 }
Ejemplo n.º 26
0
function smarty_outputfilter_highlight($source, $smarty)
{
    global $prefs;
    if (empty($_REQUEST['highlight'])) {
        return $source;
    }
    if (!strstr($source, 'id="tiki-center"')) {
        return $source;
    }
    $highlight = $_REQUEST['highlight'];
    if (isset($_REQUEST['boolean']) && ($_REQUEST['boolean'] == 'on' || $_REQUEST['boolean'] == 'y')) {
        $highlight = str_replace(array('(', ')', '*', '-', '"', '~', '<', '>'), ' ', $highlight);
    }
    if (isset($prefs['feature_referer_highlight']) && $prefs['feature_referer_highlight'] == 'y') {
        $refererhi = _refererhi();
        if (isset($refererhi) && !empty($refererhi)) {
            if (isset($highlight) && !empty($highlight)) {
                $highlight = $highlight . " " . $refererhi;
            } else {
                $highlight = $refererhi;
            }
        }
    }
    if (!isset($highlight) || empty($highlight)) {
        return $source;
    }
    $matches = array();
    $end = 0;
    if ($end = strrpos($source, 'id="col2"')) {
        $stop_pattern = '(<div[^>]*\\s+id="col2".*)';
    } elseif ($end = strrpos($source, 'id="col3"')) {
        $stop_pattern = '(<div[^>]*\\s+id="col3".*)';
    } else {
        $stop_pattern = '';
    }
    $result = false;
    if (function_exists('mb_eregi')) {
        // UTF8 support enabled
        $result = mb_eregi('^(.*\\s+id="tiki-center"[^>]*>)(.*)' . $stop_pattern . '$', $source, $matches);
    } else {
        // We do not fallback on the preg_match function, since it is limited by 'pcre.backtrack_limit' which is too low by default (100K)
        //  and this script will not be allowed to change its value on most systems
        //
        if (($start = strpos($source, 'id="tiki-center"')) > 0) {
            $matches = array($source, substr($source, 0, $start), $end > $start ? substr($source, $start, $end - $start) : substr($source, $start), $end > $start ? substr($source, $end) : '');
            $result = true;
        }
    }
    if (!$result) {
        return $source;
    }
    if (strlen($matches[2]) > ini_get('pcre.backtrack_limit')) {
        return $source;
    }
    if (!isset($matches[3])) {
        $matches[3] = '';
    }
    // Avoid highlight parsing in unknown cases where $matches[2] is empty, which will result in an empty page.
    if ($matches[2] != '') {
        $source = preg_replace_callback('~(?:<head>.*</head>                            # head blocks
		|<div[^>]*nohighlight.*</div><!--nohighlight--> # div with nohightlight
		|<script[^>]+>.*</script>                       # script blocks
		|<a[^>]*onmouseover.*onmouseout[^>]*>           # onmouseover (user popup)
		|<[^>]*>                                        # all html tags
		|(' . _enlightColor($highlight) . '))~xsiU', '_enlightColor', $matches[2]);
    }
    return $matches[1] . $source . $matches[3];
}
Ejemplo n.º 27
0
	public static function set($buffer, $wordset=null) {
		//先还原原始文本
		$buffer = self::rip($buffer);

		if (($wordset) && (is_array($wordset))) {
			$seolinkdata = &$wordset;
		} else {
			self::getLinkData();
			$seolinkdata = self::$linkdata;
		}
		
		//将文本中的链接保护起来
		self::$links = array();
		self::$linkcount = 0;
		$buffer = preg_replace_callback('/((\<a|\[url).*?(\<\/a\>|\[\/url\]))/i', array('self', "storeLink"), $buffer);
				
		//保持前n个字符不变
		$prefix = "";
		$matches = null;
		if (self::$_min_preserve > 0) {
			if (preg_match('/^(.{'.self::$_min_preserve.'}.*?)(\.|。|\<br\s*\/?\>|\n)(.*)$/is', $buffer, $matches)) {
				$prefix = $matches[1];
				$buffer = $matches[2].$matches[3];
			}
		}
		
		$count = 0;
		//将关键词替换为简短标识
        $buffer = mb_convert_encoding($buffer, 'utf8', 'gbk');
        mb_regex_encoding('utf8');
		foreach($seolinkdata as $order => $item) {
            $item['id'] = mb_convert_encoding($item['id'], 'utf8', 'gbk');
			if (mb_eregi($item["id"], $buffer)) {
				$buffer = mb_eregi_replace($item["id"], "<!--HDF:$order-->", $buffer, self::$_replace_limit);
				$count++;
				//记录到文件
				//file_put_contents("/Data/cache/in/seolink.hits.log", "$item[id]\n", FILE_APPEND);
			}
			//超过最大次数则退出
			if ((self::$_max_replace > 0) && ($count >= self::$_max_replace)) break;
		}
        $buffer =  mb_convert_encoding($buffer, 'gbk', 'utf8');

		//将简短标识替换为完整标识 
		if ($count) $buffer = preg_replace('/\<!\-\-HDF:(.+?)\-\-\>/e', "'<!--HAODF:'.\$seolinkdata[\${1}]['value'].'-->'.\$seolinkdata[\${1}]['id'].'<!--HAODF:/'.\$seolinkdata[\${1}]['value'].'-->'", $buffer); 
		
		$buffer = $prefix.$buffer;
		
		//还原保护的链接
		if (self::$linkcount > 0) $buffer = preg_replace_callback('/\{HDFSEOLINK\:(\d+)\}/', array('self', "restoreLink"), $buffer);

		return $buffer;
	}
Ejemplo n.º 28
0
 function detectUrl($url)
 {
     $parse = parse_url($url);
     $id = 0;
     //echo $url;
     if (isset($parse['host'])) {
         switch ($parse['host']) {
             case 'youtu.be':
                 $info[0] = 'youtube';
                 $info[1] = substr($parse['path'], 1);
                 return $info;
                 break;
             case 'www.youtube.com':
                 $info[0] = 'youtube';
                 if (isset($parse['query'])) {
                     $parse2 = parse_str($parse['query'], $data);
                     if (isset($data['v'])) {
                         $info[1] = $data['v'];
                         return $info;
                     } else {
                         return $url;
                     }
                 } else {
                     $info[1] = substr($parse['path'], 7);
                     return $info;
                 }
                 break;
             case 'vimeo.com':
                 $info[0] = 'vimeo';
                 $info[1] = substr($parse['path'], 1);
                 break;
             case 'www.dailymotion.com':
                 $info[0] = 'dailymotion';
                 $info[1] = substr($parse['path'], 7);
                 break;
             case 'v.youku.com':
                 $info[0] = 'youku';
                 $id = $parse['path'];
                 $id = explode("/", $id);
                 $id = explode(".", $id[2]);
                 $info[1] = substr($id[0], 3);
                 return $info;
                 break;
             case 'docs.google.com':
                 if (mb_eregi("presentation", $parse['path'])) {
                     $info[0] = 'googleDocPres';
                     if (isset($parse['query'])) {
                         /*$parse2 = parse_str($parse['query'], $data);
                         		$info[1] = $data['id'];*/
                         return $url;
                     } else {
                         $id = $parse['path'];
                         $id = strstr($id, "d");
                         $id = explode("/", $id);
                         $info[1] = $id[1];
                     }
                     return $info;
                 } else {
                     return $url;
                 }
                 break;
             default:
                 return $url;
                 break;
         }
     } else {
         return $url;
     }
 }
Ejemplo n.º 29
0
 private function getbgcolorlist($data)
 {
     $ret = array();
     foreach ($data as $type => $typedata) {
         foreach ($typedata as $item => $var) {
             if (mb_eregi('BGCOLOR\\((.+)\\)', $var[0], $m)) {
                 $ret[$this->type2name[$type]][$item] = $m[1];
             }
         }
     }
     return $ret;
 }
Ejemplo n.º 30
0
            define('POSTURL', 'https://'.$hostname.'.'.$domain.':8443/login');
            define('POSTVARS', "username=$login&password=$password&lt=$lt&service=".$_POST['service']);

            $ch = curl_init(POSTURL);
            ob_start();
            curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
            curl_setopt($ch,CURLOPT_SSL_VERIFYHOST, 0);
            curl_setopt($ch, CURLOPT_POST, 1);
            curl_setopt($ch, CURLOPT_POSTFIELDS, POSTVARS);
            curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0);
            curl_setopt($ch, CURLOPT_HEADER, 1);  // DO NOT RETURN HTTP HEADERS
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);  // RETURN THE CONTENTS OF THE CALL
            $Rec_Data = curl_exec($ch);

            $Final_Out=ob_get_clean();
            if (mb_eregi('Set-Cookie:',$Rec_Data)) {
                $infos = explode('Set-Cookie:',$Rec_Data);
				$t = explode(';',$infos[1]);
				$ticket=explode('=',$t[0]);
				$ticket_propre=mb_substr($ticket[1], 0, 33);
				#system ("echo 'ticket $ticket_propre' > /var/log/lcs/debugcas.log");
				setcookie('tgt',"",0,"/","",0);
				setcookie('tgt',"$ticket_propre",0,"/","",0);
				#echo("Votre serveur CAS vous a attribu&eacute; le ticket: $ticket[1] \n Vous avez d&egrave;s lors acc&egrave;s aux applications SSO.");
            } else
                echo "Attention vous n'&ecirc;tes pas identifi&eacute; sur le serveur CAS! Contactez votre administrateur.";

            curl_close($ch);
        }
    } else die('D&#233;sol&#233; cet espace ne vous concerne pas !');
 } else