コード例 #1
0
ファイル: index.php プロジェクト: hinablue/TextCube
function RefererURLBeautifier_handler($target, $mother)
{
    $keyword = false;
    if (preg_match('/\\W(q|query|k|keyword|search|stext|nlia|aqa|wd)(?:=|%3D)([^&]+)/i', $mother['url'], $matches)) {
        $keyword = urldecode(rawurldecode($matches[2]));
    } else {
        if (strpos($mother['host'], 'images.google.') !== false && preg_match('/%3Fsearch%3D([^&]+)/i', $mother['url'], $matches)) {
            $keyword = urldecode(rawurldecode($matches[1]));
        } else {
            if (strpos($mother['host'], 'yahoo.') !== false && preg_match('/\\Wp=([^&]+)/i', $mother['url'], $matches)) {
                $keyword = urldecode(rawurldecode($matches[1]));
            } else {
                if (preg_match('@/search/(?:\\w+/)*([^/?]+)@i', $mother['url'], $matches)) {
                    $keyword = urldecode(rawurldecode($matches[1]));
                }
            }
        }
    }
    if (!UTF8::validate($keyword)) {
        $keyword = UTF8::correct(UTF8::bring($keyword));
    }
    $keyword = UTF16UrlDecode($keyword);
    $url = rawurldecode(substr($mother['url'], 7));
    if (!UTF8::validate($url)) {
        $url = UTF8::correct(UTF8::bring($url));
    }
    //return '<img src="http://'.$mother['host'].'/favicon.ico" width="16" height="16" alt="Favicon" onerror="this.parentNode.removeChild(this)" style="vertical-align: middle"/> ' . (($keyword) ? '<span style="font-weight: bold; color: #594">['.htmlspecialchars($keyword).']</span> ' . UTF8::lessenAsEm($url, 65 - UTF8::lengthAsEm($keyword)) : UTF8::lessenAsEm($url, 65));
    return $keyword ? '<span style="font-weight: bold; color: #594">[' . htmlspecialchars($keyword) . ']</span> ' . htmlspecialchars(UTF8::lessenAsEm($url, 70 - UTF8::lengthAsEm($keyword))) : htmlspecialchars(UTF8::lessenAsEm($url, 70));
}
コード例 #2
0
		function open($xml, $encoding = null, $nsenabled = false) {
			if (!empty($encoding) && (strtolower($encoding) != 'utf-8') && !UTF8::validate($xml)) {
				if (preg_match('/^<\?xml[^<]*\s+encoding=["\']?([\w-]+)["\']?/', $xml, $matches)) {
					$encoding = $matches[1];
					$xml = preg_replace('/^(<\?xml[^<]*\s+encoding=)["\']?[\w-]+["\']?/', '$1"utf-8"', $xml, 1);
				}
				if (strcasecmp($encoding, 'utf-8')) {
					$xml = UTF8::bring($xml, $encoding);
					if ($xml === null) {
						$this->error = XML_ERROR_UNKNOWN_ENCODING;
						return false;
					}
				}
			} else {
				if (substr($xml, 0, 3) == "\xEF\xBB\xBF")
					$xml = substr($xml, 3);
			}			
			
			$xml = str_replace('&', '&amp;', $xml); // for parse error code 23 (&)

			$this->nsenabled = $nsenabled;
			$p = ($nsenabled) ? xml_parser_create_ns() : xml_parser_create();
			xml_set_object($p, $this);
			xml_parser_set_option($p, XML_OPTION_CASE_FOLDING, 0);
			xml_set_element_handler($p, 'o', 'c');
			xml_set_character_data_handler($p, 'd');
			xml_set_default_handler($p, 'x');
			$this->struct = array();
			$this->_cursor = &$this->struct;
			$this->_path = array('');
			$this->_cdata = false;
			if (!xml_parse($p, $xml))
				return $this->_error($p);
			unset($this->_cursor);
			unset($this->_cdata);
			if (xml_get_error_code($p) != XML_ERROR_NONE)
				return $this->_error($p);
			xml_parser_free($p);
			return true;
		}
コード例 #3
0
 public static function validateArray(&$array, &$rules)
 {
     // Workaround for non Fancy-URL user.
     $cropArray = array();
     foreach ($array as $name => $value) {
         $doesHaveRequest = strpos($name, '?');
         if ($doesHaveRequest !== false) {
             $name = substr($name, $doesHaveRequest + 1);
         }
         $cropArray[$name] = $value;
     }
     $array = $cropArray;
     foreach ($rules as $key => $rule) {
         if (!isset($rule[0])) {
             trigger_error("Validator: The type of '{$key}' is not defined", E_USER_WARNING);
             continue;
         }
         if (isset($array[$key]) && ($rule[0] == 'file' || strlen($array[$key]) > 0)) {
             $value =& $array[$key];
             if (isset($rule['min'])) {
                 $rule[1] = $rule['min'];
             }
             if (isset($rule['max'])) {
                 $rule[2] = $rule['max'];
             }
             if (isset($rule['bypass'])) {
                 $rule[3] = $rule['bypass'];
             }
             switch ($rule[0]) {
                 case 'any':
                     if (isset($rule[1]) && strlen($value) < $rule[1]) {
                         return false;
                     }
                     if (isset($rule[2]) && strlen($value) > $rule[2]) {
                         return false;
                     }
                     break;
                 case 'bit':
                     $array[$key] = self::getBit($value);
                     break;
                 case 'bool':
                     $array[$key] = self::getBool($value);
                     break;
                 case 'number':
                     if (!self::number($value, isset($rule[1]) ? $rule[1] : null, isset($rule[2]) ? $rule[2] : null, isset($rule[3]) ? $rule[3] : false)) {
                         return false;
                     }
                     break;
                 case 'int':
                     if (!self::isInteger($value, isset($rule[1]) ? $rule[1] : -2147483648, isset($rule[2]) ? $rule[2] : 2147483647, isset($rule[3]) ? $rule[3] : false)) {
                         return false;
                     }
                     break;
                 case 'id':
                     if (!self::id($value, isset($rule[1]) ? $rule[1] : 1, isset($rule[2]) ? $rule[2] : 2147483647)) {
                         return false;
                     }
                     break;
                 case 'url':
                 case 'string':
                     if (!UTF8::validate($value)) {
                         $value = UTF8::bring($value);
                         if (!UTF8::validate($value)) {
                             return false;
                         }
                     }
                     $value = $array[$key] = UTF8::correct($value);
                     if (isset($rule[1]) && UTF8::length($value) < $rule[1]) {
                         return false;
                     }
                     if (isset($rule[2]) && UTF8::length($value) > $rule[2]) {
                         return false;
                     }
                     break;
                 case 'list':
                     if (!self::isList($value)) {
                         return false;
                     }
                     break;
                 case 'timestamp':
                     if (!self::timestamp($value)) {
                         return false;
                     }
                     break;
                 case 'period':
                     if (!self::period($value)) {
                         return false;
                     }
                     break;
                 case 'ip':
                     if (!self::ip($value)) {
                         return false;
                     }
                     break;
                 case 'phone':
                     if (!self::phone($value)) {
                         return false;
                     }
                     break;
                 case 'domain':
                     if (!self::domain($value)) {
                         return false;
                     }
                     break;
                 case 'email':
                     if (!self::email($value)) {
                         return false;
                     }
                     break;
                 case 'language':
                     if (!self::language($value)) {
                         return false;
                     }
                     break;
                 case 'filename':
                     if (!self::filename($value)) {
                         return false;
                     }
                     break;
                 case 'directory':
                     if (!self::directory($value)) {
                         return false;
                     }
                     break;
                 case 'path':
                     if (!self::path($value)) {
                         return false;
                     }
                     break;
                 case 'file':
                     if (!isset($value['name']) || preg_match('@[/\\\\]@', $value['name'])) {
                         return false;
                     }
                     break;
                 default:
                     if (is_array($rule[0])) {
                         if (!in_array($value, $rule[0])) {
                             return false;
                         }
                     } else {
                         trigger_error("Validator: The type of '{$key}' is unknown", E_USER_WARNING);
                     }
                     break;
             }
             if (isset($rule['check'])) {
                 $rule[5] = $rule['check'];
             }
             if (isset($rule[5])) {
                 if (function_exists($rule[5])) {
                     if (!call_user_func($rule[5], $value)) {
                         return false;
                     }
                 } else {
                     trigger_error("Validator: The check function of '{$key}' is not defined", E_USER_WARNING);
                 }
             }
         } else {
             if (array_key_exists(3, $rule)) {
                 $array[$key] = $rule[3];
             } else {
                 if (array_key_exists('default', $rule)) {
                     $array[$key] = $rule['default'];
                 } else {
                     if ((!isset($rule[4]) || $rule[4]) && (!isset($rule['mandatory']) || $rule['mandatory'])) {
                         return false;
                     }
                 }
             }
         }
     }
     return true;
 }
コード例 #4
0
ファイル: statistics_inc.php プロジェクト: hinablue/TextCube
function getRefererKeywordStatistics()
{
    $more = false;
    $refereres = getRefererLogsDB();
    $keywordlist = array();
    $record = array();
    for ($i = 0; $i < sizeof($refereres); $i++) {
        $record = $refereres[$i];
        if ($i == 0) {
            $referredend = $record['referred'];
        }
        $keyword = "";
        if (preg_match('/\\W(q|query|k|keyword|search|stext|nlia|aqa|wd)(?:=|%3D)([^&]+)/i', $record['url'], $matches)) {
            $keyword = urldecode(rawurldecode($matches[2]));
        } else {
            if (strpos($record['url'], 'yahoo.') !== false && preg_match('/\\Wp=([^&]+)/i', $record['url'], $matches)) {
                $keyword = urldecode(rawurldecode($matches[1]));
            } else {
                if (preg_match('@/search/(?:\\w+/)*([^/?]+)@i', $record['url'], $matches)) {
                    $keyword = urldecode(rawurldecode($matches[1]));
                }
            }
        }
        if (!UTF8::validate($keyword)) {
            $keyword = UTF8::correct(UTF8::bring($keyword));
        }
        if (array_key_exists($keyword, $keywordlist)) {
            $keywordlist[$keyword]++;
        } elseif ($keyword) {
            $keywordlist[$keyword] = 1;
        }
    }
    $referredstart = array_key_exists('referred', $record) ? $record['referred'] : '';
    $keywordlist = RefererKeywordArraySort($keywordlist, 'desc');
    $keywordkeys = array_keys($keywordlist);
    $beforekeywordvalue = '';
    $rank = 0;
    $keywordArray = array();
    for ($i = 0; $i < sizeof($keywordlist); $i++) {
        $keywordkey = $keywordkeys[$i];
        $keywordvalue = $keywordlist[$keywordkey];
        $keywordkey = str_replace("\"", "&quot;", $keywordkeys[$i]);
        if ($keywordvalue != $beforekeywordvalue) {
            $rank++;
            $beforekeywordvalue = $keywordvalue;
        }
        array_push($keywordArray, array('keyword' => $keywordkey, 'count' => $keywordvalue, 'total' => count($keywordlist), 'rank' => $rank, 'dateStart' => Timestamp::formatDate($referredstart), 'dateEnd' => Timestamp::formatDate($referredend)));
    }
    return $keywordArray;
}
コード例 #5
0
function isUTF8($str)
{
    return UTF8::validate($str);
}