Error!

www.taodisoft.com | /www/wwwroot/taodisoft_v2/public

AJAX PAUSED www.taodisoft.com/tool/56342.html X RETRY

fsockopen(): unable to connect to localhost:8384 (Connection refused)

711 /www/wwwroot/taodisoft_v2/vendor/hightman/xunsearch/lib/XS.class.php

save changes
<?php /** * XS 主类定义文件 * * @author hightman * @link http://www.xunsearch.com/ * @copyright Copyright &copy; 2011 HangZhou YunSheng Network Technology Co., Ltd. * @license http://www.xunsearch.com/license/ * @version $Id$ * * <ul> * <li>XS 是 XunSearch 的统一缩写, XS 是解决方案而不仅仅针对搜索, 还包括索引管理等</li> * <li>XS 运行环境要求 PHP 5.2.0 及以上版本, 带有 SPL 扩展</li> * <li>如果您的数据包含 utf-8 以外的编码(如: gbk), 则要求安装 mbstring 或 iconv 以便转换编码</li> * <li>对于 bool 类型函数/方法若无特别说明, 均表示成功返回 true, 失败返回 false</li> * <li>对于致命的异常情况均抛出类型为 XSException 的异常, 应将 xs 所有操作放入 try/catch 区块</li> * <li>这只是 XunSearch 项目客户端的 PHP 实现, 需要配合 xunsearch 服务端协同工作</li> * </ul> * * 用法简例: * <pre> * try { * // 创建 xs 实例 (包含3个字段 id, title, content) * $xs = new XS('etc/sample.ini'); * * // 索引管理 * $doc = new XSDocument('gbk'); * * // 新增/根据主键更新数据 * $doc->id = 123; * $doc->title = '您好, 世界!'; * $doc->setFields(array('content' => '英文说法是: Hello, the world!')); * $xs->index->add($doc); * * $doc->title = '世界, 你好!'; * $xs->index->update($doc); * * $xs->index->del(124); // 删除单条主键为 124 的数据 * $xs->index->del(array(125, 126, 129)); // 批量删除 3条数据 * * // 正常检索 * // 快速检索取得结果 * // 快速检索匹配数量(估算) * * } catch (XSException $e) { * echo $e . "<br />\n"; * } * </pre> */ define('XS_LIB_ROOT', dirname(__FILE__)); include_once XS_LIB_ROOT . '/xs_cmd.inc.php'; /** * XS 异常类定义, XS 所有操作过程发生异常均抛出该实例 * * @author hightman <[email protected]> * @version 1.0.0 * @package XS */ class XSException extends Exception { /** * 将类对象转换成字符串 * @return string 异常的简要描述信息 */ public function __toString() { $string = '[' . __CLASS__ . '] ' . $this->getRelPath($this->getFile()) . '(' . $this->getLine() . '): '; $string .= $this->getMessage() . ($this->getCode() > 0 ? '(S#' . $this->getCode() . ')' : ''); return $string; } /** * 取得相对当前的文件路径 * @param string $file 需要转换的绝对路径 * @return string 转换后的相对路径 */ public static function getRelPath($file) { $from = getcwd(); $file = realpath($file); if (is_dir($file)) { $pos = false; $to = $file; } else { $pos = strrpos($file, '/'); $to = substr($file, 0, $pos); } for ($rel = '';; $rel .= '../') { if ($from === $to) { break; } if ($from === dirname($from)) { $rel .= substr($to, 1); break; } if (!strncmp($from . '/', $to, strlen($from) + 1)) { $rel .= substr($to, strlen($from) + 1); break; } $from = dirname($from); } if (substr($rel, -1, 1) === '/') { $rel = substr($rel, 0, -1); } if ($pos !== false) { $rel .= substr($file, $pos); } return $rel; } } /** * XS 错误异常类定义, XS 所有操作过程发生错误均抛出该实例 * * @author hightman <[email protected]> * @version 1.0.0 * @package XS */ class XSErrorException extends XSException { private $_file, $_line; /** * 构造函数 * 将 $file, $line 记录到私有属性在 __toString 中使用 * @param int $code 出错代码 * @param string $message 出错信息 * @param string $file 出错所在文件 * @param int $line 出错所在的行数 * @param Exception $previous */ public function __construct($code, $message, $file, $line, $previous = null) { $this->_file = $file; $this->_line = $line; if (version_compare(PHP_VERSION, '5.3.0', '>=')) { parent::__construct($message, $code, $previous); } else { parent::__construct($message, $code); } } /** * 将类对象转换成字符串 * @return string 异常的简要描述信息 */ public function __toString() { $string = '[' . __CLASS__ . '] ' . $this->getRelPath($this->_file) . '(' . $this->_line . '): '; $string .= $this->getMessage() . '(' . $this->getCode() . ')'; return $string; } } /** * XS 组件基类 * 封装一些魔术方法, 以实现支持模拟属性 * * 模拟属性通过定义读取函数, 写入函数来实现, 允许两者缺少其中一个 * 这类属性可以跟正常定义的属性一样存取, 但是这类属性名称不区分大小写. 例: * <pre> * $a = $obj->text; // $a 值等于 $obj->getText() 的返回值 * $obj->text = $a; // 等同事调用 $obj->setText($a) * </pre> * * @author hightman <[email protected]> * @version 1.0.0 * @package XS */ class XSComponent { /** * 魔术方法 __get * 取得模拟属性的值, 内部实际调用 getXxx 方法的返回值 * @param string $name 属性名称 * @return mixed 属性值 * @throw XSException 属性不存在或不可读时抛出异常 */ public function __get($name) { $getter = 'get' . $name; if (method_exists($this, $getter)) { return $this->$getter(); } // throw exception $msg = method_exists($this, 'set' . $name) ? 'Write-only' : 'Undefined'; $msg .= ' property: ' . get_class($this) . '::$' . $name; throw new XSException($msg); } /** * 魔术方法 __set * 设置模拟属性的值, 内部实际是调用 setXxx 方法 * @param string $name 属性名称 * @param mixed $value 属性值 * @throw XSException 属性不存在或不可写入时抛出异常 */ public function __set($name, $value) { $setter = 'set' . $name; if (method_exists($this, $setter)) { return $this->$setter($value); } // throw exception $msg = method_exists($this, 'get' . $name) ? 'Read-only' : 'Undefined'; $msg .= ' property: ' . get_class($this) . '::$' . $name; throw new XSException($msg); } /** * 魔术方法 __isset * 判断模拟属性是否存在并可读取 * @param string $name 属性名称 * @return bool 若存在为 true, 反之为 false */ public function __isset($name) { return method_exists($this, 'get' . $name); } /** * 魔术方法 __unset * 删除、取消模拟属性, 相当于设置属性值为 null * @param string $name 属性名称 */ public function __unset($name) { $this->__set($name, null); } } /** * XS 搜索项目主类 * * @property XSFieldScheme $scheme 当前在用的字段方案 * @property string $defaultCharset 默认字符集编码 * @property-read string $name 项目名称 * @property-read XSIndex $index 索引操作对象 * @property-read XSSearch $search 搜索操作对象 * @property-read XSFieldMeta $idField 主键字段 * @author hightman <[email protected]> * @version 1.0.0 * @package XS */ class XS extends XSComponent { /** * @var XSIndex 索引操作对象 */ private $_index; /** * @var XSSearch 搜索操作对象 */ private $_search; /** * @var XSServer scws 分词服务器 */ private $_scws; /** * @var XSFieldScheme 当前字段方案 */ private $_scheme, $_bindScheme; private $_config; /** * @var XS 最近创建的 XS 对象 */ private static $_lastXS; /** * 构造函数 * 特别说明一个小技巧, 参数 $file 可以直接是配置文件的内容, 还可以是仅仅是文件名, * 如果只是文件名会自动查找 XS_LIB_ROOT/../app/$file.ini * @param string $file 要加载的项目配置文件 */ public function __construct($file) { if (strlen($file) < 255 && !is_file($file)) { $appRoot = getenv('XS_APP_ROOT'); if ($appRoot === false) { $appRoot = defined('XS_APP_ROOT') ? XS_APP_ROOT : XS_LIB_ROOT . '/../app'; } $file2 = $appRoot . '/' . $file . '.ini'; if (is_file($file2)) { $file = $file2; } } $this->loadIniFile($file); self::$_lastXS = $this; } /** * 析构函数 * 由于对象交叉引用, 如需提前销毁对象, 请强制调用该函数 */ public function __destruct() { $this->_index = null; $this->_search = null; } /** * 获取最新的 XS 实例 * @return XS 最近创建的 XS 对象 */ public static function getLastXS() { return self::$_lastXS; } /** * 获取当前在用的字段方案 * 通用于搜索结果文档和修改、添加的索引文档 * @return XSFieldScheme 当前字段方案 */ public function getScheme() { return $this->_scheme; } /** * 设置当前在用的字段方案 * @param XSFieldScheme $fs 一个有效的字段方案对象 * @throw XSException 无效方案则直接抛出异常 */ public function setScheme(XSFieldScheme $fs) { $fs->checkValid(true); $this->_scheme = $fs; if ($this->_search !== null) { $this->_search->markResetScheme(); } } /** * 还原字段方案为项目绑定方案 */ public function restoreScheme() { if ($this->_scheme !== $this->_bindScheme) { $this->_scheme = $this->_bindScheme; if ($this->_search !== null) { $this->_search->markResetScheme(true); } } } /** * @return array 获取配置原始数据 */ public function getConfig() { return $this->_config; } /** * 获取当前项目名称 * @return string 当前项目名称 */ public function getName() { return $this->_config['project.name']; } /** * 修改当前项目名称 * 注意,必须在 {@link getSearch} 和 {@link getIndex} 前调用才能起作用 * @param string $name 项目名称 */ public function setName($name) { $this->_config['project.name'] = $name; } /** * 获取项目的默认字符集 * @return string 默认字符集(已大写) */ public function getDefaultCharset() { return isset($this->_config['project.default_charset']) ? strtoupper($this->_config['project.default_charset']) : 'UTF-8'; } /** * 改变项目的默认字符集 * @param string $charset 修改后的字符集 */ public function setDefaultCharset($charset) { $this->_config['project.default_charset'] = strtoupper($charset); } /** * 获取索引操作对象 * @return XSIndex 索引操作对象 */ public function getIndex() { if ($this->_index === null) { $adds = array(); $conn = isset($this->_config['server.index']) ? $this->_config['server.index'] : 8383; if (($pos = strpos($conn, ';')) !== false) { $adds = explode(';', substr($conn, $pos + 1)); $conn = substr($conn, 0, $pos); } $this->_index = new XSIndex($conn, $this); $this->_index->setTimeout(0); foreach ($adds as $conn) { $conn = trim($conn); if ($conn !== '') { $this->_index->addServer($conn)->setTimeout(0); } } } return $this->_index; } /** * 获取搜索操作对象 * @return XSSearch 搜索操作对象 */ public function getSearch() { if ($this->_search === null) { $conns = array(); if (!isset($this->_config['server.search'])) { $conns[] = 8384; } else { foreach (explode(';', $this->_config['server.search']) as $conn) { $conn = trim($conn); if ($conn !== '') { $conns[] = $conn; } } } if (count($conns) > 1) { shuffle($conns); } for ($i = 0; $i < count($conns); $i++) { try { $this->_search = new XSSearch($conns[$i], $this); $this->_search->setCharset($this->getDefaultCharset()); return $this->_search; } catch (XSException $e) { if (($i + 1) === count($conns)) { throw $e; } } } } return $this->_search; } /** * 创建 scws 分词连接 * @return XSServer 分词服务器 */ public function getScwsServer() { if ($this->_scws === null) { $conn = isset($this->_config['server.search']) ? $this->_config['server.search'] : 8384; $this->_scws = new XSServer($conn, $this); } return $this->_scws; } /** * 获取当前主键字段 * @return XSFieldMeta 类型为 ID 的字段 * @see XSFieldScheme::getFieldId */ public function getFieldId() { return $this->_scheme->getFieldId(); } /** * 获取当前标题字段 * @return XSFieldMeta 类型为 TITLE 的字段 * @see XSFieldScheme::getFieldTitle */ public function getFieldTitle() { return $this->_scheme->getFieldTitle(); } /** * 获取当前内容字段 * @return XSFieldMeta 类型为 BODY 的字段 * @see XSFieldScheme::getFieldBody */ public function getFieldBody() { return $this->_scheme->getFieldBody(); } /** * 获取项目字段元数据 * @param mixed $name 字段名称(string) 或字段序号(vno, int) * @param bool $throw 当字段不存在时是否抛出异常, 默认为 true * @return XSFieldMeta 字段元数据对象 * @throw XSException 当字段不存在并且参数 throw 为 true 时抛出异常 * @see XSFieldScheme::getField */ public function getField($name, $throw = true) { return $this->_scheme->getField($name, $throw); } /** * 获取项目所有字段结构设置 * @return XSFieldMeta[] */ public function getAllFields() { return $this->_scheme->getAllFields(); } /** * 智能加载类库文件 * 要求以 Name.class.php 命名并与本文件存放在同一目录, 如: XSTokenizerXxx.class.php * @param string $name 类的名称 */ public static function autoload($name) { $file = XS_LIB_ROOT . '/' . $name . '.class.php'; if (file_exists($file)) { require_once $file; } } /** * 字符集转换 * 要求安装有 mbstring, iconv 中的一种 * @param mixed $data 需要转换的数据, 支持 string 和 array, 数组会自动递归转换 * @param string $to 转换后的字符集 * @param string $from 转换前的字符集 * @return mixed 转换后的数据 * @throw XSEXception 如果没有合适的转换函数抛出异常 */ public static function convert($data, $to, $from) { // need not convert if ($to == $from) { return $data; } // array traverse if (is_array($data)) { foreach ($data as $key => $value) { $data[$key] = self::convert($value, $to, $from); } return $data; } // string contain 8bit characters if (is_string($data) && preg_match('/[\x81-\xfe]/', $data)) { // mbstring, iconv, throw ... if (function_exists('mb_convert_encoding')) { return mb_convert_encoding($data, $to, $from); } elseif (function_exists('iconv')) { return iconv($from, $to . '//TRANSLIT', $data); } else { throw new XSException('Cann\'t find the mbstring or iconv extension to convert encoding'); } } return $data; } /** * 计算经纬度距离 * @param float $lon1 原点经度 * @param float $lat1 原点纬度 * @param float $lon2 目标点经度 * @param float $lat2 目标点纬度 * @return float 两点大致距离,单位:米 */ public static function geoDistance($lon1, $lat1, $lon2, $lat2) { $dx = $lon1 - $lon2; $dy = $lat1 - $lat2; $b = ($lat1 + $lat2) / 2; $lx = 6367000.0 * deg2rad($dx) * cos(deg2rad($b)); $ly = 6367000.0 * deg2rad($dy); return sqrt($lx * $lx + $ly * $ly); } /** * 解析INI配置文件 * 由于 PHP 自带的 parse_ini_file 存在一些不兼容,故自行简易实现 * @param string $data 文件内容 * @return array 解析后的结果 */ private function parseIniData($data) { $ret = array(); $cur = &$ret; $lines = explode("\n", $data); foreach ($lines as $line) { if ($line === '' || $line[0] == ';' || $line[0] == '#') { continue; } $line = trim($line); if ($line === '') { continue; } if ($line[0] === '[' && substr($line, -1, 1) === ']') { $sec = substr($line, 1, -1); $ret[$sec] = array(); $cur = &$ret[$sec]; continue; } if (($pos = strpos($line, '=')) === false) { continue; } $key = trim(substr($line, 0, $pos)); $value = trim(substr($line, $pos + 1), " '\t\""); $cur[$key] = $value; } return $ret; } /** * 加载项目配置文件 * @param string $file 配置文件路径 * @throw XSException 出错时抛出异常 * @see XSFieldMeta::fromConfig */ private function loadIniFile($file) { // check cache $cache = false; $cache_write = ''; if (strlen($file) < 255 && file_exists($file)) { $cache_key = md5(__CLASS__ . '::ini::' . realpath($file)); if (function_exists('apcu_fetch')) { $cache = apcu_fetch($cache_key); $cache_write = 'apcu_store'; } elseif (function_exists('xcache_get') && php_sapi_name() !== 'cli') { $cache = xcache_get($cache_key); $cache_write = 'xcache_set'; } elseif (function_exists('eaccelerator_get')) { $cache = eaccelerator_get($cache_key); $cache_write = 'eaccelerator_put'; } if ($cache && isset($cache['mtime']) && isset($cache['scheme']) && filemtime($file) <= $cache['mtime']) { // cache HIT $this->_scheme = $this->_bindScheme = unserialize($cache['scheme']); $this->_config = $cache['config']; return; } $data = file_get_contents($file); } else { // parse ini string $data = $file; $file = substr(md5($file), 8, 8) . '.ini'; } // parse ini file $this->_config = $this->parseIniData($data); if ($this->_config === false) { throw new XSException('Failed to parse project config file/string: \'' . substr($file, 0, 10) . '...\''); } // create the scheme object $scheme = new XSFieldScheme; foreach ($this->_config as $key => $value) { if (is_array($value)) { $scheme->addField($key, $value); } } $scheme->checkValid(true); // load default config if (!isset($this->_config['project.name'])) { $this->_config['project.name'] = basename($file, '.ini'); } // save to cache $this->_scheme = $this->_bindScheme = $scheme; if ($cache_write != '') { $cache['mtime'] = filemtime($file); $cache['scheme'] = serialize($this->_scheme); $cache['config'] = $this->_config; call_user_func($cache_write, $cache_key, $cache); } } } /** * Add autoload handler to search classes on current directory * Class file should be named as Name.class.php */ spl_autoload_register('XS::autoload', true, true); /** * 修改默认的错误处理函数 * 把发生的错误修改为抛出异常, 方便统一处理 */ function xsErrorHandler($errno, $error, $file, $line) { if (($errno & ini_get('error_reporting')) && !strncmp($file, XS_LIB_ROOT, strlen(XS_LIB_ROOT))) { throw new XSErrorException($errno, $error, $file, $line); } return false; } set_error_handler('xsErrorHandler');
<?php /** * XSServer 类定义文件 * * @author hightman * @link http://www.xunsearch.com/ * @copyright Copyright &copy; 2011 HangZhou YunSheng Network Technology Co., Ltd. * @license http://www.xunsearch.com/license/ * @version $Id$ */ /** * XSCommand 命令对象 * 是与服务端交互的最基本单位, 命令对象可自动转换为通讯字符串, * 命令结构参见 C 代码中的 struct xs_cmd 定义, 头部长度为 8字节. * * @property int $arg 参数, 相当于 (arg1<<8)|arg2 的值 * @author hightman <[email protected]> * @version 1.0.0 * @package XS */ class XSCommand extends XSComponent { /** * @var int 命令代码 * 通常是预定义常量 XS_CMD_xxx, 取值范围 0~255 */ public $cmd = XS_CMD_NONE; /** * @var int 参数1 * 取值范围 0~255, 具体含义根据不同的 CMD 而变化 */ public $arg1 = 0; /** * @var int 参数2 * 取值范围 0~255, 常用于存储 value no, 具体参照不同 CMD 而确定 */ public $arg2 = 0; /** * @var string 主数据内容, 最长 2GB */ public $buf = ''; /** * @var string 辅数据内容, 最长 255字节 */ public $buf1 = ''; /** * 构造函数 * @param mixed $cmd 命令类型或命令数组 * 当类型为 int 表示命令代码, 范围是 1~255, 参见 xs_cmd.inc.php 里的定义 * 当类型为 array 时忽略其它参数, 可包含 cmd, arg1, arg2, buf, buf1 这些键值 * @param int $arg1 参数1, 其值为 0~255, 具体含义视不同 CMD 而确定 * @param int $arg2 参数2, 其值为 0~255, 具体含义视不同 CMD 而确定, 常用于存储 value no * @param string $buf 字符串内容, 最大长度为 2GB * @param string $buf1 字符串内容1, 最大长度为 255字节 */ public function __construct($cmd, $arg1 = 0, $arg2 = 0, $buf = '', $buf1 = '') { if (is_array($cmd)) { foreach ($cmd as $key => $value) { if ($key === 'arg' || property_exists($this, $key)) { $this->$key = $value; } } } else { $this->cmd = $cmd; $this->arg1 = $arg1; $this->arg2 = $arg2; $this->buf = $buf; $this->buf1 = $buf1; } } /** * 转换为封包字符串 * @return string 用于服务端交互的字符串 */ public function __toString() { if (strlen($this->buf1) > 0xff) { $this->buf1 = substr($this->buf1, 0, 0xff); } return pack('CCCCI', $this->cmd, $this->arg1, $this->arg2, strlen($this->buf1), strlen($this->buf)) . $this->buf . $this->buf1; } /** * 获取属性 arg 的值 * @return int 参数值 */ public function getArg() { return $this->arg2 | ($this->arg1 << 8); } /** * 设置属性 arg 的值 * @param int $arg 参数值 */ public function setArg($arg) { $this->arg1 = ($arg >> 8) & 0xff; $this->arg2 = $arg & 0xff; } } /** * XSServer 服务器操作对象 * 同时兼容于 indexd, searchd, 所有交互均采用 {@link XSCommand} 对象 * * @property string $project 当前使用的项目名 * @property-write int $timeout 服务端IO超时秒数, 默认为 5秒 * @author hightman <[email protected]> * @version 1.0.0 * @package XS */ class XSServer extends XSComponent { /** * 连接标志定义(常量) */ const FILE = 0x01; const BROKEN = 0x02; /** * @var XS 服务端关联的 XS 对象 */ public $xs; protected $_sock, $_conn; protected $_flag; protected $_project; protected $_sendBuffer; /** * 构造函数, 打开连接 * @param string $conn 服务端连接参数 * @param XS $xs 需要捆绑的 xs 对象 */ public function __construct($conn = null, $xs = null) { $this->xs = $xs; if ($conn !== null) { $this->open($conn); } } /** * 析构函数, 关闭连接 */ public function __destruct() { $this->xs = null; $this->close(); } /** * 打开服务端连接 * 如果已关联 XS 对象, 则会同时切换至相应的项目名称 * @param mixed $conn 服务端连接参数, 支持: <端口号|host:port|本地套接字路径> */ public function open($conn) { $this->close(); $this->_conn = $conn; $this->_flag = self::BROKEN; $this->_sendBuffer = ''; $this->_project = null; $this->connect(); $this->_flag ^= self::BROKEN; if ($this->xs instanceof XS) { $this->setProject($this->xs->getName()); } } /** * 重新打开连接 * 仅应用于曾经成功打开的连并且异常关闭了 * @param bool $force 是否强制重新连接, 默认为否 * @return XSServer 返回自己, 以便串接操作 */ public function reopen($force = false) { if ($this->_flag & self::BROKEN || $force === true) { $this->open($this->_conn); } return $this; } /** * 关闭连接 * 附带发送发送 quit 命令 * @param bool $ioerr 关闭调用是否由于 IO 错误引起的, 以免发送 quit 指令 */ public function close($ioerr = false) { if ($this->_sock && !($this->_flag & self::BROKEN)) { if (!$ioerr && $this->_sendBuffer !== '') { $this->write($this->_sendBuffer); $this->_sendBuffer = ''; } if (!$ioerr && !($this->_flag & self::FILE)) { $cmd = new XSCommand(XS_CMD_QUIT); fwrite($this->_sock, $cmd); } fclose($this->_sock); $this->_flag |= self::BROKEN; } } /** * @return string 连接字符串 */ public function getConnString() { $str = $this->_conn; if (is_int($str) || is_numeric($str)) { $str = 'localhost:' . $str; } elseif (strpos($str, ':') === false) { $str = 'unix://' . $str; } return $str; } /** * 获取连接资源描述符 * @return mixed 连接标识, 仅用于内部测试等目的 */ public function getSocket() { return $this->_sock; } /** * 获取当前项目名称 * @return string 项目名称 */ public function getProject() { return $this->_project; } /** * 设置当前项目 * @param string $name 项目名称 * @param string $home 项目在服务器上的目录路径, 可选参数(不得超过255字节). */ public function setProject($name, $home = '') { if ($name !== $this->_project) { $cmd = array('cmd' => XS_CMD_USE, 'buf' => $name, 'buf1' => $home); $this->execCommand($cmd, XS_CMD_OK_PROJECT); $this->_project = $name; } } /** * 设置服务端超时秒数 * @param int $sec 秒数, 设为 0则永不超时直到客户端主动关闭 */ public function setTimeout($sec) { $cmd = array('cmd' => XS_CMD_TIMEOUT, 'arg' => $sec); $this->execCommand($cmd, XS_CMD_OK_TIMEOUT_SET); } /** * 执行服务端指令并获取返回值 * @param mixed $cmd 要提交的指令, 若不是 XSCommand 实例则作为构造函数的第一参数创建对象 * @param int $res_arg 要求的响应参数, 默认为 XS_CMD_NONE 即不检测, 若检测结果不符 * 则认为命令调用失败, 会返回 false 并设置相应的出错信息 * @param int $res_cmd 要求的响应指令, 默认为 XS_CMD_OK 即要求结果必须正确. * @return mixed 若无需要检测结果则返回 true, 其它返回响应的 XSCommand 对象 * @throw XSException 操作失败或响应命令不正确时抛出异常 */ public function execCommand($cmd, $res_arg = XS_CMD_NONE, $res_cmd = XS_CMD_OK) { // create command object if (!$cmd instanceof XSCommand) { $cmd = new XSCommand($cmd); } // just cache the cmd for those need not answer if ($cmd->cmd & 0x80) { $this->_sendBuffer .= $cmd; return true; } // send cmd to server $buf = $this->_sendBuffer . $cmd; $this->_sendBuffer = ''; $this->write($buf); // return true directly for local file if ($this->_flag & self::FILE) { return true; } // got the respond $res = $this->getRespond(); // check respond if ($res->cmd === XS_CMD_ERR && $res_cmd != XS_CMD_ERR) { throw new XSException($res->buf, $res->arg); } // got unexpected respond command if ($res->cmd != $res_cmd || ($res_arg != XS_CMD_NONE && $res->arg != $res_arg)) { throw new XSException('Unexpected respond {CMD:' . $res->cmd . ', ARG:' . $res->arg . '}'); } return $res; } /** * 往服务器直接发送指令 (无缓存) * @param mixed $cmd 要提交的指令, 支持 XSCommand 实例或 cmd 构造函数的第一参数 * @throw XSException 失败时抛出异常 */ public function sendCommand($cmd) { if (!$cmd instanceof XSCommand) { $cmd = new XSCommand($cmd); } $this->write(strval($cmd)); } /** * 从服务器读取响应指令 * @return XSCommand 成功返回响应指令 * @throw XSException 失败时抛出异常 */ public function getRespond() { // read data from server $buf = $this->read(8); $hdr = unpack('Ccmd/Carg1/Carg2/Cblen1/Iblen', $buf); $res = new XSCommand($hdr); $res->buf = $this->read($hdr['blen']); $res->buf1 = $this->read($hdr['blen1']); return $res; } /** * 判断服务端是否有可读数据 * 用于某些特别情况在 {@link getRespond} 前先调用和判断, 以免阻塞 * @return bool 如果有返回 true, 否则返回 false */ public function hasRespond() { // check socket if ($this->_sock === null || $this->_flag & (self::BROKEN | self::FILE)) { return false; } $wfds = $xfds = array(); $rfds = array($this->_sock); $res = stream_select($rfds, $wfds, $xfds, 0, 0); return $res > 0; } /** * 写入数据 * @param string $buf 要写入的字符串 * @param string $len 要写入的长度, 默认为字符串长度 * @throw XSException 失败时抛出异常 */ protected function write($buf, $len = 0) { // quick return for empty buf $buf = strval($buf); if ($len == 0 && ($len = $size = strlen($buf)) == 0) { return true; } // loop to send data $this->check(); while (true) { $bytes = fwrite($this->_sock, $buf, $len); if ($bytes === false || $bytes === 0 || $bytes === $len) { break; } $len -= $bytes; $buf = substr($buf, $bytes); } // error occured if ($bytes === false || $bytes === 0) { $meta = stream_get_meta_data($this->_sock); $this->close(true); $reason = $meta['timed_out'] ? 'timeout' : ($meta['eof'] ? 'closed' : 'unknown'); $msg = 'Failed to send the data to server completely '; $msg .= '(SIZE:' . ($size - $len) . '/' . $size . ', REASON:' . $reason . ')'; throw new XSException($msg); } } /** * 读取数据 * @param int $len 要读入的长度 * @return string 成功时返回读到的字符串 * @throw XSException 失败时抛出异常 */ protected function read($len) { // quick return for zero size if ($len == 0) { return ''; } // loop to send data $this->check(); for ($buf = '', $size = $len;;) { $bytes = fread($this->_sock, $len); if ($bytes === false || strlen($bytes) == 0) { break; } $len -= strlen($bytes); $buf .= $bytes; if ($len === 0) { return $buf; } } // error occured $meta = stream_get_meta_data($this->_sock); $this->close(true); $reason = $meta['timed_out'] ? 'timeout' : ($meta['eof'] ? 'closed' : 'unknown'); $msg = 'Failed to recv the data from server completely '; $msg .= '(SIZE:' . ($size - $len) . '/' . $size . ', REASON:' . $reason . ')'; throw new XSException($msg); } /** * 检测服务端的连接情况 * @throw XSException 连接不可用时抛出异常 */ protected function check() { if ($this->_sock === null) { throw new XSException('No server connection'); } if ($this->_flag & self::BROKEN) { throw new XSException('Broken server connection'); } } /** * 连接服务端 * @throw XSException 无法连接时抛出异常 */ protected function connect() { // connect to server $conn = $this->_conn; if (is_int($conn) || is_numeric($conn)) { $host = 'localhost'; $port = intval($conn); } elseif (!strncmp($conn, 'file://', 7)) { // write-only for saving index exchangable data to file // NOTE: this will cause file content be turncated $conn = substr($conn, 7); if (($sock = @fopen($conn, 'wb')) === false) { throw new XSException('Failed to open local file for writing: `' . $conn . '\''); } $this->_flag |= self::FILE; $this->_sock = $sock; return; } elseif (($pos = strpos($conn, ':')) !== false) { $host = substr($conn, 0, $pos); $port = intval(substr($conn, $pos + 1)); } else { $host = 'unix://' . $conn; $port = -1; } if (($sock = @fsockopen($host, $port, $errno, $error, 5)) === false) { throw new XSException($error . '(C#' . $errno . ', ' . $host . ':' . $port . ')'); } // set socket options $timeout = ini_get('max_execution_time'); $timeout = $timeout > 0 ? ($timeout - 1) : 30; stream_set_blocking($sock, true); stream_set_timeout($sock, $timeout); $this->_sock = $sock; } }
<?php /** * XSSearch 类定义文件 * * @author hightman * @link http://www.xunsearch.com/ * @copyright Copyright &copy; 2011 HangZhou YunSheng Network Technology Co., Ltd. * @license http://www.xunsearch.com/license/ * @version $Id$ */ /** * XS 搜索类, 执行搜索功能 * 有部分方法支持串接操作 * <pre> * $xs->search->setQuery($str)->setLimit(10, 10)->search(); * $xs->close(); * </pre> * * @property string $query 默认搜索语句 * @property-read int $dbTotal 数据库内的数据总量 * @property-read int $lastCount 最近那次搜索的匹配总量估值 * @property-read array $hotQuery 热门搜索词列表 * @property-read array $relatedQuery 相关搜索词列表 * @property-read array $expandedQuery 展开前缀的搜索词列表 * @property-read array $corredtedQuery 修正后的建议搜索词列表 * @author hightman <[email protected]> * @version 1.0.0 * @package XS */ class XSSearch extends XSServer { /** * 搜索结果默认分页数量 */ const PAGE_SIZE = 10; const LOG_DB = 'log_db'; private $_defaultOp = XS_CMD_QUERY_OP_AND; private $_prefix, $_fieldSet, $_resetScheme = false; private $_query, $_terms, $_count; private $_lastCount, $_highlight; private $_curDb, $_curDbs = array(); private $_lastDb, $_lastDbs = array(); private $_facets = array(); private $_limit = 0, $_offset = 0; private $_charset = 'UTF-8'; /** * 连接搜索服务端并初始化 * 每次重新连接后所有的搜索语句相关设置均被还原 * @param string $conn * @see XSServer::open */ public function open($conn) { parent::open($conn); $this->_prefix = array(); $this->_fieldSet = false; $this->_lastCount = false; } /** * 设置字符集 * 默认字符集是 UTF-8, 如果您提交的搜索语句和预期得到的搜索结果为其它字符集, 请先设置 * @param string $charset * @return XSSearch 返回对象本身以支持串接操作 */ public function setCharset($charset) { $this->_charset = strtoupper($charset); if ($this->_charset == 'UTF8') { $this->_charset = 'UTF-8'; } return $this; } /** * 开启模糊搜索 * 默认情况只返回包含所有搜索词的记录, 通过本方法可以获得更多搜索结果 * @param bool $value 设为 true 表示开启模糊搜索, 设为 false 关闭模糊搜索 * @return XSSearch 返回对象本身以支持串接操作 */ public function setFuzzy($value = true) { $this->_defaultOp = $value === true ? XS_CMD_QUERY_OP_OR : XS_CMD_QUERY_OP_AND; return $this; } /** * 设置百分比/权重剔除参数 * 通常是在开启 {@link setFuzzy} 或使用 OR 连接搜索语句时才需要设置此项 * @param int $percent 剔除匹配百分比低于此值的文档, 值范围 0-100 * @param float $weight 剔除权重低于此值的文档, 值范围 0.1-25.5, 0 表示不剔除 * @return XSSearch 返回对象本身以支持串接操作 * @see setFuzzy */ public function setCutOff($percent, $weight = 0) { $percent = max(0, min(100, intval($percent))); $weight = max(0, (intval($weight * 10) & 255)); $cmd = new XSCommand(XS_CMD_SEARCH_SET_CUTOFF, $percent, $weight); $this->execCommand($cmd); return $this; } /** * 设置在搜索结果文档中返回匹配词表 * 请在 {@link search} 前调用本方法, 然后使用 {@link XSDocument::matched} 获取 * @param bool $value 设为 true 表示开启返回, 设为 false 关闭该功能, 默认是不开启 * @return XSSearch 返回对象本身以支持串接操作 * @since 1.4.8 */ public function setRequireMatchedTerm($value = true) { $arg1 = XS_CMD_SEARCH_MISC_MATCHED_TERM; $arg2 = $value === true ? 1 : 0; $cmd = new XSCommand(XS_CMD_SEARCH_SET_MISC, $arg1, $arg2); $this->execCommand($cmd); return $this; } /** * 设置检索匹配的权重方案 * 目前支持三种权重方案: 0=BM25/1=Bool/2=Trad * @param int $scheme 匹配权重方案 * @return XSSearch 返回对象本身以支持串接操作 * @since 1.4.11 */ public function setWeightingScheme($scheme) { $arg1 = XS_CMD_SEARCH_MISC_WEIGHT_SCHEME; $arg2 = intval($scheme); $cmd = new XSCommand(XS_CMD_SEARCH_SET_MISC, $arg1, $arg2); $this->execCommand($cmd); return $this; } /** * 开启自动同义词搜索功能 * @param bool $value 设为 true 表示开启同义词功能, 设为 false 关闭同义词功能 * @return XSSearch 返回对象本身以支持串接操作 * @since 1.3.0 */ public function setAutoSynonyms($value = true) { $flag = XS_CMD_PARSE_FLAG_BOOLEAN | XS_CMD_PARSE_FLAG_PHRASE | XS_CMD_PARSE_FLAG_LOVEHATE; if ($value === true) { $flag |= XS_CMD_PARSE_FLAG_AUTO_MULTIWORD_SYNONYMS; } $cmd = array('cmd' => XS_CMD_QUERY_PARSEFLAG, 'arg' => $flag); $this->execCommand($cmd); return $this; } /** * 设置同义词搜索的权重比例 * @param float $value 取值范围 0.01-2.55, 1 表示不调整 * @return XSSearch 返回对象本身以支持串接操作 * @notice scws 的复合分词也是以同义词方式呈现的 * @since 1.4.7 */ public function setSynonymScale($value) { $arg1 = XS_CMD_SEARCH_MISC_SYN_SCALE; $arg2 = max(0, (intval($value * 100) & 255)); $cmd = new XSCommand(XS_CMD_SEARCH_SET_MISC, $arg1, $arg2); $this->execCommand($cmd); return $this; } /** * 获取当前库内的全部同义词列表 * @param int $limit 数量上限, 若设为 0 则启用默认值 100 个 * @param int $offset 偏移量, 即跳过的结果数量, 默认为 0 * @param bool $stemmed 是否包含处理过的词根同义词, 默认为 false 表示否 * @return array 同义词记录数组, 每个词条为键, 同义词条组成的数组为值 * @since 1.3.0 */ public function getAllSynonyms($limit = 0, $offset = 0, $stemmed = false) { $page = $limit > 0 ? pack('II', intval($offset), intval($limit)) : ''; $cmd = array('cmd' => XS_CMD_SEARCH_GET_SYNONYMS, 'buf1' => $page); $cmd['arg1'] = $stemmed == true ? 1 : 0; $res = $this->execCommand($cmd, XS_CMD_OK_RESULT_SYNONYMS); $ret = array(); if (!empty($res->buf)) { foreach (explode("\n", $res->buf) as $line) { $value = explode("\t", $line); $key = array_shift($value); $ret[$key] = $value; } } return $ret; } /** * 获取指定词汇的同义词列表 * @param string $term 要查询同义词的原词 * @return array 同义词记录数组, 不存在同义词则返回空数组 * @since 1.4.9 */ public function getSynonyms($term) { $term = strval($term); if (strlen($term) === 0) { return false; } $cmd = array('cmd' => XS_CMD_SEARCH_GET_SYNONYMS, 'arg1' => 2, 'buf' => $term); $res = $this->execCommand($cmd, XS_CMD_OK_RESULT_SYNONYMS); $ret = $res->buf === '' ? array() : explode("\n", $res->buf); return $ret; } /** * 获取解析后的搜索语句 * @param string $query 搜索语句, 若传入 null 使用默认语句 * @return string 返回解析后的搜索语句 */ public function getQuery($query = null) { $query = $query === null ? '' : $this->preQueryString($query); $cmd = new XSCommand(XS_CMD_QUERY_GET_STRING, 0, $this->_defaultOp, $query); $res = $this->execCommand($cmd, XS_CMD_OK_QUERY_STRING); if (strpos($res->buf, 'VALUE_RANGE') !== false) { $regex = '/(VALUE_RANGE) (\d+) (\S+) (.+?)(?=\))/'; $res->buf = preg_replace_callback($regex, array($this, 'formatValueRange'), $res->buf); } if (strpos($res->buf, 'VALUE_GE') !== false || strpos($res->buf, 'VALUE_LE') !== false) { $regex = '/(VALUE_[GL]E) (\d+) (.+?)(?=\))/'; $res->buf = preg_replace_callback($regex, array($this, 'formatValueRange'), $res->buf); } return XS::convert($res->buf, $this->_charset, 'UTF-8'); } /** * 设置默认搜索语句 * 用于不带参数的 {@link count} 或 {@link search} 以及 {@link terms} 调用 * 可与 {@link addWeight} 组合运用 * @param string $query 搜索语句, 设为 null 则清空搜索语句, 最大长度为 80 字节 * @return XSSearch 返回对象本身以支持串接操作 */ public function setQuery($query) { $this->clearQuery(); if ($query !== null) { $this->_query = $query; $this->addQueryString($query); } return $this; } /** * 设置地理位置距离排序方式 * * 请务必先以 numeric 类型字段定义经纬度坐标字段,例如用 lon 代表经度、lat 代表纬度, * 那么设置排序代码如下,必须将经度定义在前纬度在后: * <pre> * $search->setGeodistSort(array('lon' => 39.18, 'lat' => 120.51)); * </pre> * @param array $fields 在此定义地理位置信息原点坐标信息,数组至少必须包含2个值 * @param bool $reverse 是否由远及近排序, 默认为由近及远 * @param bool $relevance_first 是否优先相关性排序, 默认为否 * @return XSSearch 返回对象本身以支持串接操作 * @since 1.4.10 */ public function setGeodistSort($fields, $reverse = false, $relevance_first = false) { if (!is_array($fields) || count($fields) < 2) { throw new XSException("Fields of `setGeodistSort' should be an array contain two or more elements"); } // [vno][vlen][vbuf] ... $buf = ''; foreach ($fields as $key => $value) { $field = $this->xs->getField($key, true); if (!$field->isNumeric()) { throw new XSException("Type of GeoField `$key' shoud be numeric"); } $vno = $field->vno; $vbuf = strval(floatval($value)); $vlen = strlen($vbuf); if ($vlen >= 255) { throw new XSException("Value of `$key' too long"); } $buf .= chr($vno) . chr($vlen) . $vbuf; } $type = XS_CMD_SORT_TYPE_GEODIST; if ($relevance_first) { $type |= XS_CMD_SORT_FLAG_RELEVANCE; } if (!$reverse) { $type |= XS_CMD_SORT_FLAG_ASCENDING; } $cmd = new XSCommand(XS_CMD_SEARCH_SET_SORT, $type, 0, $buf); $this->execCommand($cmd); return $this; } /** * 设置多字段组合排序方式 * 当您需要根据多个字段的值按不同的方式综合排序时, 请使用这项 * @param array $fields 排序依据的字段数组, 以字段名称为键, true/false 为值表示正序或逆序 * @param bool $reverse 是否为倒序显示, 默认为正向, 此处和 {@link setSort} 略有不同 * @param bool $relevance_first 是否优先相关性排序, 默认为否 * @return XSSearch 返回对象本身以支持串接操作 * @since 1.1.0 */ public function setMultiSort($fields, $reverse = false, $relevance_first = false) { if (!is_array($fields)) { return $this->setSort($fields, !$reverse, $relevance_first); } // [vno][0/1] (0:reverse,1:asc) $buf = ''; foreach ($fields as $key => $value) { if (is_bool($value)) { $vno = $this->xs->getField($key, true)->vno; $asc = $value; } else { $vno = $this->xs->getField($value, true)->vno; $asc = false; } if ($vno != XSFieldScheme::MIXED_VNO) { $buf .= chr($vno) . chr($asc ? 1 : 0); } } if ($buf !== '') { $type = XS_CMD_SORT_TYPE_MULTI; if ($relevance_first) { $type |= XS_CMD_SORT_FLAG_RELEVANCE; } if (!$reverse) { $type |= XS_CMD_SORT_FLAG_ASCENDING; } $cmd = new XSCommand(XS_CMD_SEARCH_SET_SORT, $type, 0, $buf); $this->execCommand($cmd); } return $this; } /** * 设置搜索结果的排序方式 * 注意, 每当调用 {@link setDb} 或 {@link addDb} 修改当前数据库时会重置排序设定 * 此函数第一参数的用法与 {@link setMultiSort} 兼容, 即也可以用该方法实现多字段排序 * @param string $field 依据指定字段的值排序, 设为 null 则用默认顺序 * @param bool $asc 是否为正序排列, 即从小到大, 从少到多, 默认为反序 * @param bool $relevance_first 是否优先相关性排序, 默认为否 * @return XSSearch 返回对象本身以支持串接操作 */ public function setSort($field, $asc = false, $relevance_first = false) { if (is_array($field)) { return $this->setMultiSort($field, $asc, $relevance_first); } if ($field === null) { $cmd = new XSCommand(XS_CMD_SEARCH_SET_SORT, XS_CMD_SORT_TYPE_RELEVANCE); } else { $type = XS_CMD_SORT_TYPE_VALUE; if ($relevance_first) { $type |= XS_CMD_SORT_FLAG_RELEVANCE; } if ($asc) { $type |= XS_CMD_SORT_FLAG_ASCENDING; } $vno = $this->xs->getField($field, true)->vno; $cmd = new XSCommand(XS_CMD_SEARCH_SET_SORT, $type, $vno); } $this->execCommand($cmd); return $this; } /** * 设置结果按索引入库先后排序 * 注意, 此项排序不影响相关排序, 权重高的仍会在前面, 主要适合用于布尔检索 * @param bool $asc 是否为正序排列, 即从先到后, 默认为反序 * @return XSSearch 返回对象本身以支持串接操作 */ public function setDocOrder($asc = false) { $type = XS_CMD_SORT_TYPE_DOCID | ($asc ? XS_CMD_SORT_FLAG_ASCENDING : 0); $cmd = new XSCommand(XS_CMD_SEARCH_SET_SORT, $type); $this->execCommand($cmd); return $this; } /** * 设置折叠搜索结果 * 注意, 每当调用 {@link setDb} 或 {@link addDb} 修改当前数据库时会重置此项设置 * @param string $field 依据该字段的值折叠搜索结果, 设为 null 则取消折叠 * @param int $num 折叠后只是返最匹配的数据数量, 默认为 1, 最大值 255 * @return XSSearch 返回对象本身以支持串接操作 */ public function setCollapse($field, $num = 1) { $vno = $field === null ? XSFieldScheme::MIXED_VNO : $this->xs->getField($field, true)->vno; $max = min(255, intval($num)); $cmd = new XSCommand(XS_CMD_SEARCH_SET_COLLAPSE, $max, $vno); $this->execCommand($cmd); return $this; } /** * 添加搜索过滤区间或范围 * @param string $field * @param mixed $from 起始值(不包含), 若设为 null 则相当于匹配 <= to (字典顺序) * @param mixed $to 结束值(包含), 若设为 null 则相当于匹配 >= from (字典顺序) * @return XSSearch 返回对象本身以支持串接操作 */ public function addRange($field, $from, $to) { if ($from === '' || $from === false) { $from = null; } if ($to === '' || $to === false) { $to = null; } if ($from !== null || $to !== null) { if (strlen($from) > 255 || strlen($to) > 255) { throw new XSException('Value of range is too long'); } $vno = $this->xs->getField($field)->vno; $from = XS::convert($from, 'UTF-8', $this->_charset); $to = XS::convert($to, 'UTF-8', $this->_charset); if ($from === null) { $cmd = new XSCommand(XS_CMD_QUERY_VALCMP, XS_CMD_QUERY_OP_FILTER, $vno, $to, chr(XS_CMD_VALCMP_LE)); } elseif ($to === null) { $cmd = new XSCommand(XS_CMD_QUERY_VALCMP, XS_CMD_QUERY_OP_FILTER, $vno, $from, chr(XS_CMD_VALCMP_GE)); } else { $cmd = new XSCommand(XS_CMD_QUERY_RANGE, XS_CMD_QUERY_OP_FILTER, $vno, $from, $to); } $this->execCommand($cmd); } return $this; } /** * 添加权重索引词 * 无论是否包含这种词都不影响搜索匹配, 但会参与计算结果权重, 使结果的相关度更高 * @param string $field 索引词所属的字段 * @param string $term 索引词 * @param float $weight 权重计算缩放比例 * @return XSSearch 返回对象本身以支持串接操作 * @see addQueryTerm */ public function addWeight($field, $term, $weight = 1) { return $this->addQueryTerm($field, $term, XS_CMD_QUERY_OP_AND_MAYBE, $weight); } /** * 设置分面搜索记数 * 用于记录匹配搜索结果中按字段值分组的数量统计, 每次调用 {@link search} 后会还原设置 * 对于多次调用 $exact 参数以最后一次为准, 只支持字段值不超过 255 字节的情况 * * 自 v1.4.10 起自动对空值的字段按 term 分面统计(相当于多值) * @param mixed $field 要进行分组统计的字段或字段组成的数组, 最多同时支持 8 个 * @param bool $exact 是否要求绝对精确搜索, 这会造成较大的系统开销 * @return XSSearch 返回对象本身以支持串接操作 * @throw XSException 在非字符串字段建立分面搜索会抛出异常 * @since 1.1.0 */ public function setFacets($field, $exact = false) { $buf = ''; if (!is_array($field)) { $field = array($field); } foreach ($field as $name) { $ff = $this->xs->getField($name); if ($ff->type !== XSFieldMeta::TYPE_STRING) { throw new XSException("Field `$name' cann't be used for facets search, can only be string type"); } $buf .= chr($ff->vno); } $cmd = array('cmd' => XS_CMD_SEARCH_SET_FACETS, 'buf' => $buf); $cmd['arg1'] = $exact === true ? 1 : 0; $this->execCommand($cmd); return $this; } /** * 读取最近一次分面搜索记数 * 必须在某一次 {@link search} 之后调用本函数才有意义 * @param string $field 读取分面记数的字段, 若为 null 则返回全部分面搜索记录 * @return array 返回由值和计数组成的关联数组, 若不存在或未曾登记过则返回空数组 * @since 1.1.0 */ public function getFacets($field = null) { if ($field === null) { return $this->_facets; } return isset($this->_facets[$field]) ? $this->_facets[$field] : array(); } /** * 设置当前搜索语句的分词复合等级 * 复合等级是 scws 分词粒度控制的一个重要参数, 是长词细分处理依据, 默认为 3, 值范围 0~15 * 注意: 这个设置仅直对本次搜索有效, 仅对设置之后的 {@link setQuery} 起作用, 由于 query * 设计的方式问题, 目前无法支持搜索语句单字切分, 但您可以在模糊检索时设为 0 来关闭复合分词 * @param int $level 要设置的分词复合等级 * @return XSSearch 返回自身对象以支持串接操作 * @since 1.4.7 */ public function setScwsMulti($level) { $level = intval($level); if ($level >= 0 && $level < 16) { $cmd = array('cmd' => XS_CMD_SEARCH_SCWS_SET, 'arg1' => XS_CMD_SCWS_SET_MULTI, 'arg2' => $level); $this->execCommand($cmd); } return $this; } /** * 设置搜索结果的数量和偏移 * 用于搜索结果分页, 每次调用 {@link search} 后会还原这2个变量到初始值 * @param int $limit 数量上限, 若设为 0 则启用默认值 self::PAGE_SIZE * @param int $offset 偏移量, 即跳过的结果数量, 默认为 0 * @return XSSearch 返回对象本身以支持串接操作 */ public function setLimit($limit, $offset = 0) { $this->_limit = intval($limit); $this->_offset = intval($offset); return $this; } /** * 设置要搜索的数据库名 * 若未设置, 使用默认数据库, 数据库必须位于服务端用户目录下 * 对于远程数据库, 请使用 stub 文件来支持 * @param string $name * @return XSSearch 返回对象本身以支持串接操作 */ public function setDb($name) { $name = strval($name); $this->execCommand(array('cmd' => XS_CMD_SEARCH_SET_DB, 'buf' => strval($name))); $this->_lastDb = $this->_curDb; $this->_lastDbs = $this->_curDbs; $this->_curDb = $name; $this->_curDbs = array(); return $this; } /** * 添加搜索的数据库名, 支持多库同时搜索 * @param string $name * @return XSSearch 返回对象本身以支持串接操作 * @see setDb */ public function addDb($name) { $name = strval($name); $this->execCommand(array('cmd' => XS_CMD_SEARCH_ADD_DB, 'buf' => $name)); $this->_curDbs[] = $name; return $this; } /** * 标记字段方案重置 * @see XS::setScheme */ public function markResetScheme() { $this->_resetScheme = true; } /** * 获取搜索语句中的高亮词条列表 * @param string $query 搜索语句, 若传入 null 使用默认语句, 最大长度为 80 字节 * @param bool $convert 是否进行编码转换, 默认为 true * @return array 可用于高亮显示的词条列表 */ public function terms($query = null, $convert = true) { $query = $query === null ? '' : $this->preQueryString($query); if ($query === '' && $this->_terms !== null) { $ret = $this->_terms; } else { $cmd = new XSCommand(XS_CMD_QUERY_GET_TERMS, 0, $this->_defaultOp, $query); $res = $this->execCommand($cmd, XS_CMD_OK_QUERY_TERMS); $ret = array(); $tmps = explode(' ', $res->buf); for ($i = 0; $i < count($tmps); $i++) { if ($tmps[$i] === '' || strpos($tmps[$i], ':') !== false) { continue; } $ret[] = $tmps[$i]; } if ($query === '') { $this->_terms = $ret; } } return $convert ? XS::convert($ret, $this->_charset, 'UTF-8') : $ret; } /** * 估算搜索语句的匹配数据量 * @param string $query 搜索语句, 若传入 null 使用默认语句, 调用后会还原默认排序方式 * 如果搜索语句和最近一次 {@link search} 的语句一样, 请改用 {@link getLastCount} 以提升效率 * 最大长度为 80 字节 * @return int 匹配的搜索结果数量, 估算数值 */ public function count($query = null) { $query = $query === null ? '' : $this->preQueryString($query); if ($query === '' && $this->_count !== null) { return $this->_count; } $cmd = new XSCommand(XS_CMD_SEARCH_GET_TOTAL, 0, $this->_defaultOp, $query); $res = $this->execCommand($cmd, XS_CMD_OK_SEARCH_TOTAL); $ret = unpack('Icount', $res->buf); if ($query === '') { $this->_count = $ret['count']; } return $ret['count']; } /** * 获取匹配的搜索结果文档 * 默认提取最匹配的前 self::PAGE_SIZE 个结果 * 如需分页请参见 {@link setLimit} 设置, 每次调用本函数后都会还原 setLimit 的设置 * @param string $query 搜索语句, 若传入 null 使用默认语句, 最大长度为 80 字节 * @param boolean $saveHighlight 是否存储查询词用于高亮处理, 默认为 true * @return XSDocument[] 匹配的搜索结果文档列表 */ public function search($query = null, $saveHighlight = true) { if ($this->_curDb !== self::LOG_DB && $saveHighlight) { $this->_highlight = $query; } $query = $query === null ? '' : $this->preQueryString($query); $page = pack('II', $this->_offset, $this->_limit > 0 ? $this->_limit : self::PAGE_SIZE); // get result header $cmd = new XSCommand(XS_CMD_SEARCH_GET_RESULT, 0, $this->_defaultOp, $query, $page); $res = $this->execCommand($cmd, XS_CMD_OK_RESULT_BEGIN); $tmp = unpack('Icount', $res->buf); $this->_lastCount = $tmp['count']; // load vno map to name of fields $ret = $this->_facets = array(); $vnoes = $this->xs->getScheme()->getVnoMap(); // get result documents while (true) { $res = $this->getRespond(); if ($res->cmd == XS_CMD_SEARCH_RESULT_FACETS) { $off = 0; while (($off + 6) < strlen($res->buf)) { $tmp = unpack('Cvno/Cvlen/Inum', substr($res->buf, $off, 6)); if (isset($vnoes[$tmp['vno']])) { $name = $vnoes[$tmp['vno']]; $value = substr($res->buf, $off + 6, $tmp['vlen']); if (!isset($this->_facets[$name])) { $this->_facets[$name] = array(); } $this->_facets[$name][$value] = $tmp['num']; } $off += $tmp['vlen'] + 6; } } elseif ($res->cmd == XS_CMD_SEARCH_RESULT_DOC) { // got new doc $doc = new XSDocument($res->buf, $this->_charset); $ret[] = $doc; } elseif ($res->cmd == XS_CMD_SEARCH_RESULT_FIELD) { // fields of doc if (isset($doc)) { $name = isset($vnoes[$res->arg]) ? $vnoes[$res->arg] : $res->arg; $doc->setField($name, $res->buf); } } elseif ($res->cmd == XS_CMD_SEARCH_RESULT_MATCHED) { // matched terms if (isset($doc)) { $doc->setField('matched', explode(' ', $res->buf), true); } } elseif ($res->cmd == XS_CMD_OK && $res->arg == XS_CMD_OK_RESULT_END) { // got the end break; } else { $msg = 'Unexpected respond in search {CMD:' . $res->cmd . ', ARG:' . $res->arg . '}'; throw new XSException($msg); } } if ($query === '') { $this->_count = $this->_lastCount; // trigger log & highlight if ($this->_curDb !== self::LOG_DB) { $this->logQuery(); if ($saveHighlight) { $this->initHighlight(); } } } $this->_limit = $this->_offset = 0; return $ret; } /** * 获取最近那次搜索的匹配总数估值 * @return int 匹配数据量, 如从未搜索则返回 false * @see search */ public function getLastCount() { return $this->_lastCount; } /** * 获取搜索数据库内的数据总量 * @return int 数据总量 */ public function getDbTotal() { $cmd = new XSCommand(XS_CMD_SEARCH_DB_TOTAL); $res = $this->execCommand($cmd, XS_CMD_OK_DB_TOTAL); $tmp = unpack('Itotal', $res->buf); return $tmp['total']; } /** * 获取热门搜索词列表 * @param int $limit 需要返回的热门搜索数量上限, 默认为 6, 最大值为 50 * @param string $type 排序类型, 默认为 total(搜索总量), 可选值还有 lastnum(上周), currnum(本周) * @return array 返回以搜索词为键, 搜索指数为值的关联数组 */ public function getHotQuery($limit = 6, $type = 'total') { $ret = array(); $limit = max(1, min(50, intval($limit))); // query from log_db $this->xs->setScheme(XSFieldScheme::logger()); try { $this->setDb(self::LOG_DB)->setLimit($limit); if ($type !== 'lastnum' && $type !== 'currnum') { $type = 'total'; } $result = $this->search($type . ':1'); foreach ($result as $doc) /* @var $doc XSDocument */ { $body = $doc->body; $ret[$body] = $doc->f($type); } $this->restoreDb(); } catch (XSException $e) { if ($e->getCode() != XS_CMD_ERR_XAPIAN) { throw $e; } } $this->xs->restoreScheme(); return $ret; } /** * 获取相关搜索词列表 * @param string $query 搜索语句, 若传入 null 使用默认语句 * @param int $limit 需要返回的相关搜索数量上限, 默认为 6, 最大值为 20 * @return array 返回搜索词组成的数组 */ public function getRelatedQuery($query = null, $limit = 6) { $ret = array(); $limit = max(1, min(20, intval($limit))); // Simple to disable query with field filter if ($query === null) { $query = $this->cleanFieldQuery($this->_query); } if (empty($query) || strpos($query, ':') !== false) { return $ret; } // Search the log database $op = $this->_defaultOp; $this->xs->setScheme(XSFieldScheme::logger()); try { $result = $this->setDb(self::LOG_DB)->setFuzzy()->setLimit($limit + 1)->search($query); foreach ($result as $doc) /* @var $doc XSDocument */ { $doc->setCharset($this->_charset); $body = $doc->body; if (!strcasecmp($body, $query)) { continue; } $ret[] = $body; if (count($ret) == $limit) { break; } } } catch (XSException $e) { if ($e->getCode() != XS_CMD_ERR_XAPIAN) { throw $e; } } $this->restoreDb(); $this->xs->restoreScheme(); $this->_defaultOp = $op; return $ret; } /** * 获取展开的搜索词列表 * @param string $query 需要展开的前缀, 可为拼音、英文、中文 * @param int $limit 需要返回的搜索词数量上限, 默认为 10, 最大值为 20 * @return array 返回搜索词组成的数组 */ public function getExpandedQuery($query, $limit = 10) { $ret = array(); $limit = max(1, min(20, intval($limit))); try { $buf = XS::convert($query, 'UTF-8', $this->_charset); $cmd = array('cmd' => XS_CMD_QUERY_GET_EXPANDED, 'arg1' => $limit, 'buf' => $buf); $res = $this->execCommand($cmd, XS_CMD_OK_RESULT_BEGIN); // echo "Raw Query: " . $res->buf . "\n"; // get result documents while (true) { $res = $this->getRespond(); if ($res->cmd == XS_CMD_SEARCH_RESULT_FIELD) { $ret[] = XS::convert($res->buf, $this->_charset, 'UTF-8'); } elseif ($res->cmd == XS_CMD_OK && $res->arg == XS_CMD_OK_RESULT_END) { // got the end // echo "Parsed Query: " . $res->buf . "\n"; break; } else { $msg = 'Unexpected respond in search {CMD:' . $res->cmd . ', ARG:' . $res->arg . '}'; throw new XSException($msg); } } } catch (XSException $e) { if ($e->getCode() != XS_CMD_ERR_XAPIAN) { throw $e; } } return $ret; } /** * 获取修正后的搜索词列表 * 通常当某次检索结果数量偏少时, 可以用该函数设计 "你是不是要找: ..." 功能 * @param string $query 需要展开的前缀, 可为拼音、英文、中文 * @return array 返回搜索词组成的数组 */ public function getCorrectedQuery($query = null) { $ret = array(); try { if ($query === null) { if ($this->_count > 0 && $this->_count > ceil($this->getDbTotal() * 0.001)) { return $ret; } $query = $this->cleanFieldQuery($this->_query); } if (empty($query) || strpos($query, ':') !== false) { return $ret; } $buf = XS::convert($query, 'UTF-8', $this->_charset); $cmd = array('cmd' => XS_CMD_QUERY_GET_CORRECTED, 'buf' => $buf); $res = $this->execCommand($cmd, XS_CMD_OK_QUERY_CORRECTED); if ($res->buf !== '') { $ret = explode("\n", XS::convert($res->buf, $this->_charset, 'UTF-8')); } } catch (XSException $e) { if ($e->getCode() != XS_CMD_ERR_XAPIAN) { throw $e; } } return $ret; } /** * 添加搜索日志关键词到缓冲区里 * 需要调用 {@link XSIndex::flushLogging} 才能确保立即刷新, 否则要隔一段时间 * @param string $query 需要记录的数据 * @param int $wdf 需要记录的次数, 默认为 1 * @since 1.1.1 */ public function addSearchLog($query, $wdf = 1) { $cmd = array('cmd' => XS_CMD_SEARCH_ADD_LOG, 'buf' => $query); if ($wdf > 1) { $cmd['buf1'] = pack('i', $wdf); } $this->execCommand($cmd, XS_CMD_OK_LOGGED); } /** * 搜索结果字符串高亮处理 * 对搜索结果文档的字段进行高亮、飘红处理, 高亮部分加上 em 标记 * @param string $value 需要处理的数据 * @return string 高亮后的数据 */ public function highlight($value, $strtr = false) { // return empty value directly if (empty($value)) { return $value; } // initlize the highlight replacements if (!is_array($this->_highlight)) { $this->initHighlight(); } // process replace if (isset($this->_highlight['pattern'])) { $value = preg_replace($this->_highlight['pattern'], $this->_highlight['replace'], $value); } if (isset($this->_highlight['pairs'])) { $value = $strtr ? strtr($value, $this->_highlight['pairs']) : str_replace(array_keys($this->_highlight['pairs']), array_values($this->_highlight['pairs']), $value); } return $value; } /** * 记录搜索语句 * 主要是用于相关搜索, 修正搜索等功能, 为避免记录一些杂乱无用的搜索信息, * 系统会先检测这条语句是否符合记录需求, 力争记录一些规范清洁的数据 * @param string $query 用于记录的搜索词 */ private function logQuery($query = null) { if ($this->isRobotAgent()) { return; } if ($query !== '' && $query !== null) { $terms = $this->terms($query, false); } else { // 无结果、包含 OR、XOR、NOT/-、默认 fuzzy $query = $this->_query; if (!$this->_lastCount || ($this->_defaultOp == XS_CMD_QUERY_OP_OR && strpos($query, ' ')) || strpos($query, ' OR ') || strpos($query, ' NOT ') || strpos($query, ' XOR ')) { return; } $terms = $this->terms(null, false); } // purify the query statement to log $log = ''; $pos = $max = 0; foreach ($terms as $term) { $pos1 = ($pos > 3 && strlen($term) === 6) ? $pos - 3 : $pos; if (($pos2 = strpos($query, $term, $pos1)) === false) { continue; } if ($pos2 === $pos) { $log .= $term; } elseif ($pos2 < $pos) { $log .= substr($term, 3); } else { if (++$max > 3 || strlen($log) > 42) { break; } $log .= ' ' . $term; } $pos = $pos2 + strlen($term); } // run the command, filter for single word character $log = trim($log); if (strlen($log) < 2 || (strlen($log) == 3 && ord($log[0]) > 0x80)) { return; } $this->addSearchLog($log); } /** * 清空默认搜索语句 */ private function clearQuery() { $cmd = new XSCommand(XS_CMD_QUERY_INIT); if ($this->_resetScheme === true) { $cmd->arg1 = 1; $this->_prefix = array(); $this->_fieldSet = false; $this->_resetScheme = false; } $this->execCommand($cmd); $this->_query = $this->_count = $this->_terms = null; } /** * 增加默认搜索语句 * @param string $query 搜索语句 * @param int $addOp 与旧语句的结合操作符, 如果无旧语句或为空则这此无意义, 支持的操作符有: * XS_CMD_QUERY_OP_AND * XS_CMD_QUERY_OP_OR * XS_CMD_QUERY_OP_AND_NOT * XS_CMD_QUERY_OP_XOR * XS_CMD_QUERY_OP_AND_MAYBE * XS_CMD_QUERY_OP_FILTER * @param float $scale 权重计算缩放比例, 默认为 1表示不缩放, 其它值范围 0.xx ~ 655.35 * @return string 修正后的搜索语句 */ public function addQueryString($query, $addOp = XS_CMD_QUERY_OP_AND, $scale = 1) { $query = $this->preQueryString($query); $bscale = ($scale > 0 && $scale != 1) ? pack('n', intval($scale * 100)) : ''; $cmd = new XSCommand(XS_CMD_QUERY_PARSE, $addOp, $this->_defaultOp, $query, $bscale); $this->execCommand($cmd); return $query; } /** * 增加默认搜索词汇 * @param string $field 索引词所属的字段, 若为混合区词汇可设为 null 或 body 型的字段名 * @param string|array $term 索引词或列表 * @param int $addOp 与旧语句的结合操作符, 如果无旧语句或为空则这此无意义, 支持的操作符有: * @param float $scale 权重计算缩放比例, 默认为 1表示不缩放, 其它值范围 0.xx ~ 655.35 * @return XSSearch 返回对象本身以支持串接操作 * @see addQueryString * * 注:自 v1.4.10 起,允许传入数组,多词之间通过 defaultOp 连接,并且这些词不会再被分词。 */ public function addQueryTerm($field, $term, $addOp = XS_CMD_QUERY_OP_AND, $scale = 1) { $term = XS::convert($term, 'UTF-8', $this->_charset); $bscale = ($scale > 0 && $scale != 1) ? pack('n', intval($scale * 100)) : ''; $vno = $field === null ? XSFieldScheme::MIXED_VNO : $this->xs->getField($field, true)->vno; $cmd = XS_CMD_QUERY_TERM; if (is_array($term)) { if (count($term) === 0) { return $this; } elseif (count($term) === 1) { $term = current($term); } else { $term = implode("\t", $term); $cmd = XS_CMD_QUERY_TERMS; } } $cmd = new XSCommand($cmd, $addOp, $vno, $term, $bscale); $this->execCommand($cmd); return $this; } /** * 还原搜索 DB * 常用于因需改变当前 db 为 LOG_DB 后还原 */ private function restoreDb() { $db = $this->_lastDb; $dbs = $this->_lastDbs; $this->setDb($db); foreach ($dbs as $name) { $this->addDb($name); } } /** * 搜索语句的准备工作 * 登记相关的字段前缀并给非布尔字段补上括号, 首次搜索必须通知服务端关于 cutlen, numeric 字段的设置 * @param string $query 要准备的搜索语句 * @return string 准备好的搜索语句 */ private function preQueryString($query) { // check to register prefix $query = trim($query); //if ($query === '') // throw new XSException('Query string cann\'t be empty'); // force to clear query with resetScheme if ($this->_resetScheme === true) { $this->clearQuery(); } // init special field here $this->initSpecialField(); $newQuery = ''; $parts = preg_split('/[ \t\r\n]+/', $query); foreach ($parts as $part) { if ($part === '') { continue; } if ($newQuery != '') { $newQuery .= ' '; } if (($pos = strpos($part, ':', 1)) !== false) { for ($i = 0; $i < $pos; $i++) { if (strpos('+-~(', $part[$i]) === false) { break; } } $name = substr($part, $i, $pos - $i); if (($field = $this->xs->getField($name, false)) !== false && $field->vno != XSFieldScheme::MIXED_VNO) { $this->regQueryPrefix($name); if ($field->hasCustomTokenizer()) { $prefix = $i > 0 ? substr($part, 0, $i) : ''; $suffix = ''; // force to lowercase for boolean terms $value = substr($part, $pos + 1); if (substr($value, -1, 1) === ')') { $suffix = ')'; $value = substr($value, 0, -1); } $terms = array(); $tokens = $field->getCustomTokenizer()->getTokens($value); foreach ($tokens as $term) { $terms[] = strtolower($term); } $terms = array_unique($terms); $newQuery .= $prefix . $name . ':' . implode(' ' . $name . ':', $terms) . $suffix; } elseif (substr($part, $pos + 1, 1) != '(' && preg_match('/[\x81-\xfe]/', $part)) { // force to add brackets for default scws tokenizer $newQuery .= substr($part, 0, $pos + 1) . '(' . substr($part, $pos + 1) . ')'; } else { $newQuery .= $part; } continue; } } if (strlen($part) > 1 && ($part[0] == '+' || $part[0] == '-') && $part[1] != '(' && preg_match('/[\x81-\xfe]/', $part)) { $newQuery .= substr($part, 0, 1) . '(' . substr($part, 1) . ')'; continue; } $newQuery .= $part; } return XS::convert($newQuery, 'UTF-8', $this->_charset); } /** * 登记搜索语句中的字段 * @param string $name 字段名称 */ private function regQueryPrefix($name) { if (!isset($this->_prefix[$name]) && ($field = $this->xs->getField($name, false)) && ($field->vno != XSFieldScheme::MIXED_VNO)) { $type = $field->isBoolIndex() ? XS_CMD_PREFIX_BOOLEAN : XS_CMD_PREFIX_NORMAL; $cmd = new XSCommand(XS_CMD_QUERY_PREFIX, $type, $field->vno, $name); $this->execCommand($cmd); $this->_prefix[$name] = true; } } /** * 设置字符型字段及裁剪长度 */ private function initSpecialField() { if ($this->_fieldSet === true) { return; } foreach ($this->xs->getAllFields() as $field) /* @var $field XSFieldMeta */ { if ($field->cutlen != 0) { $len = min(127, ceil($field->cutlen / 10)); $cmd = new XSCommand(XS_CMD_SEARCH_SET_CUT, $len, $field->vno); $this->execCommand($cmd); } if ($field->isNumeric()) { $cmd = new XSCommand(XS_CMD_SEARCH_SET_NUMERIC, 0, $field->vno); $this->execCommand($cmd); } } $this->_fieldSet = true; } /** * 清除查询语句中的字段名、布尔字段条件 * @param string $query 查询语句 * @return string 净化后的语句 */ private function cleanFieldQuery($query) { $query = strtr($query, array(' AND ' => ' ', ' OR ' => ' ')); if (strpos($query, ':') !== false) { $regex = '/(^|\s)([0-9A-Za-z_\.-]+):([^\s]+)/'; return preg_replace_callback($regex, array($this, 'cleanFieldCallback'), $query); } return $query; } /** * 清除布尔字段查询语句和非布尔的字段名 * 用于正则替换回调函数, 净化 {@link getCorrectedQuery} 和 {@link getRelatedQuery} 中的搜索语句 * @param array $match 正则匹配的部分, [1]:prefix [2]:field, [3]:data */ private function cleanFieldCallback($match) { if (($field = $this->xs->getField($match[2], false)) === false) { return $match[0]; } if ($field->isBoolIndex()) { return ''; } if (substr($match[3], 0, 1) == '(' && substr($match[3], -1, 1) == ')') { $match[3] = substr($match[3], 1, -1); } return $match[1] . $match[3]; } /** * 初始始化高亮替换数据 */ private function initHighlight() { $terms = array(); $tmps = $this->terms($this->_highlight, false); for ($i = 0; $i < count($tmps); $i++) { if (strlen($tmps[$i]) !== 6 || ord(substr($tmps[$i], 0, 1)) < 0xc0) { $terms[] = XS::convert($tmps[$i], $this->_charset, 'UTF-8'); continue; } // auto fixed duality in libscws // ABC => AB,BC => ABC,BC,AB // ABCD => AB,BC,CD => CD,ABC,BC,AB // ABCDE => AB,BC,CD,DE => CDE,DE,CD,ABC,BC,AB for ($j = $i + 1; $j < count($tmps); $j++) { if (strlen($tmps[$j]) !== 6 || substr($tmps[$j], 0, 3) !== substr($tmps[$j - 1], 3, 3)) { break; } } if (($k = ($j - $i)) === 1) { $terms[] = XS::convert($tmps[$i], $this->_charset, 'UTF-8'); } else { $i = $j - 1; while ($k--) { $j--; if ($k & 1) { $terms[] = XS::convert(substr($tmps[$j - 1], 0, 3) . $tmps[$j], $this->_charset, 'UTF-8'); } $terms[] = XS::convert($tmps[$j], $this->_charset, 'UTF-8'); } } } $pattern = $replace = $pairs = array(); foreach ($terms as $term) { if (!preg_match('/[a-zA-Z]/', $term)) { $pairs[$term] = '<em>' . $term . '</em>'; } else { $pattern[] = '/' . strtr($term, array('+' => '\\+', '/' => '\\/')) . '/i'; $replace[] = '<em>$0</em>'; } } $this->_highlight = array(); if (count($pairs) > 0) { $this->_highlight['pairs'] = $pairs; } if (count($pattern) > 0) { $this->_highlight['pattern'] = $pattern; $this->_highlight['replace'] = $replace; } } /** * Format the value range/ge * @param array $match * @return string */ private function formatValueRange($match) { // VALUE_[GL]E 0 xxx yyy $field = $this->xs->getField(intval($match[2]), false); if ($field === false) { return $match[0]; } $val1 = $val2 = '~'; if (isset($match[4])) { $val2 = $field->isNumeric() ? $this->xapianUnserialise($match[4]) : $match[4]; } if ($match[1] === 'VALUE_LE') { $val2 = $field->isNumeric() ? $this->xapianUnserialise($match[3]) : $match[3]; } else { $val1 = $field->isNumeric() ? $this->xapianUnserialise($match[3]) : $match[3]; } return $field->name . ':[' . $val1 . ',' . $val2 . ']'; } private function numfromstr($str, $index) { return $index < strlen($str) ? ord($str[$index]) : 0; } /** * Convert a string encoded by xapian to a floating point number * @param string $value * @return double unserialised number */ private function xapianUnserialise($value) { if ($value === "\x80") { return 0.0; } if ($value === str_repeat("\xff", 9)) { return INF; } if ($value === '') { return -INF; } $i = 0; $c = ord($value[0]); $c ^= ($c & 0xc0) >> 1; $negative = !($c & 0x80) ? 1 : 0; $exponent_negative = ($c & 0x40) ? 1 : 0; $explen = !($c & 0x20) ? 1 : 0; $exponent = $c & 0x1f; if (!$explen) { $exponent >>= 2; if ($negative ^ $exponent_negative) { $exponent ^= 0x07; } } else { $c = $this->numfromstr($value, ++$i); $exponent <<= 6; $exponent |= ($c >> 2); if ($negative ^ $exponent_negative) { $exponent &= 0x07ff; } } $word1 = ($c & 0x03) << 24; $word1 |= $this->numfromstr($value, ++$i) << 16; $word1 |= $this->numfromstr($value, ++$i) << 8; $word1 |= $this->numfromstr($value, ++$i); $word2 = 0; if ($i < strlen($value)) { $word2 = $this->numfromstr($value, ++$i) << 24; $word2 |= $this->numfromstr($value, ++$i) << 16; $word2 |= $this->numfromstr($value, ++$i) << 8; $word2 |= $this->numfromstr($value, ++$i); } if (!$negative) { $word1 |= 1 << 26; } else { $word1 = 0 - $word1; if ($word2 != 0) { ++$word1; } $word2 = 0 - $word2; $word1 &= 0x03ffffff; } $mantissa = 0; if ($word2) { $mantissa = $word2 / 4294967296.0; // 1<<32 } $mantissa += $word1; $mantissa /= 1 << ($negative === 1 ? 26 : 27); if ($exponent_negative) { $exponent = 0 - $exponent; } $exponent += 8; if ($negative) { $mantissa = 0 - $mantissa; } return round($mantissa * pow(2, $exponent), 2); } /** * @return boolean whether the user agent is a robot or search engine */ private function isRobotAgent() { if (isset($_SERVER['HTTP_USER_AGENT'])) { $agent = strtolower($_SERVER['HTTP_USER_AGENT']); $keys = array('bot', 'slurp', 'spider', 'crawl', 'curl'); foreach ($keys as $key) { if (strpos($agent, $key) !== false) { return true; } } } return false; } }
<?php namespace KieCMS\Provider; use Hashids\Hashids as RealHashIds; class XunSSearch extends Base { public function getInstance() { if (!defined('XS_APP_ROOT')) { define('XS_APP_ROOT', \KieCMS::app('/xunsearch')); } $xs = new \XS('tdv2app'); return $xs->search; } }
<?php namespace KieCMS\Provider; abstract class Base { static $providers = array(); static $instances = array(); abstract public function getInstance(); protected function single( $callback ) { $classname = get_class($this); if( !isset( static::$instances[$classname] ) ) { if( is_callable($callback) ) { static::$instances[$classname] = $callback(); } else if( is_object($callback)) { static::$instances[$classname] = $callback; } else { static::$instances[$classname] = call_user_func_array($callback, array()); } } return static::$instances[$classname]; } static function __callStatic($name, $args) { $caller = get_called_class(); if( !isset( static::$providers[$caller] ) ) { static::$providers[$caller] = new $caller(); } $provider = static::$providers[$caller]->getInstance(); return call_user_func_array(array( $provider, $name ), $args); } static function instance() { $caller = get_called_class(); if( !isset( static::$providers[$caller] ) ) { static::$providers[$caller] = new $caller(); } return static::$providers[$caller]->getInstance(); } }
<?php namespace Component\App\Model; use KieCMS\Database\Model; use Component\Category\Model\Category; use Component\Basic\Model\Attachment; use KieCMS\Database\Collection; use Component\Article\Model\Article; use Component\Tag\Model\Tag; class App extends Model { const CATEGORY_TYPE = 'app'; static $_STATUS = array( 0 => '草稿', 1 => '已发布', -1 => '已拒绝', ); protected $_snapshot; protected $table = 'app'; protected $timestamps = true; protected $fillable = array( 'category_id', 'template_id', 'name', 'cover', 'version', 'screenshots', 'is_suggest_word', 'auth', 'game_type', 'download_az', 'download_ios', 'go_id', 'redirect_id', 'language', 'size', 'star', 'platform', 'extras', 'seo_title', 'seo_keywords', 'seo_description', 'content', ); public function isBan() { return in_array($this->category_id, [4, 5, 7, 8, 9, 10, 11, 13]); } protected function beforeSave() { // checkTitleForbids($this->name); // checkContentForbids($this->content); } protected function afterDelete($result) { $this->tags()->sync([]); \XunSIndex::del("app:" . $this->id); } protected function afterSave() { $this->pushToXs(); if (strlen($this->tags_name)) { $tags_name = $this->tags_name; $tags_name = explode(',', $tags_name); $tags_name = array_map('trim', $tags_name); $exist_tags = Tag::whereIn('name', $tags_name)->get(); $exist_tags_name = $exist_tags->lists('name'); $tags_id = $exist_tags->lists('id'); foreach ($tags_name as $name) { if (strlen($name) && !in_array($name, $exist_tags_name)) { $tag = new Tag(); $tag->name = $name; $tag->save(); $tags_id[] = $tag->id; } } $tags_id = array_unique($tags_id); } else { $tags_id = array(); } $this->tags()->sync($tags_id); } function pushToXs() { if ($this->status <= 0) { \XunSIndex::del("app:" . $this->id); return; } $data = array( 'id' => "app:" . $this->id, 'app_id' => $this->id, 'category_id' => $this->category_id, 'name' => $this->name, 'cover' => $this->cover, 'version' => $this->version, 'size' => $this->size, 'url' => $this->url(), 'updated_at' => $this->updated_at->timestamp, 'created_at' => $this->created_at->timestamp, ); // 创建文档对象 $doc = new \XSDocument; $doc->setFields($data); // 添加到索引数据库中 $result = \XunSIndex::update($doc); } function getVersionAttribute($value) { if (!isset($this->attributes['version']) || !$this->attributes['version']) { $this->attributes['version'] = sprintf('%0.1f', mt_rand(10, 30) / 10); } return $this->attributes['version'] ?? ''; } function getGameTypeAttribute($value) { if (!isset($this->attributes['game_type']) || !$this->attributes['game_type']) { if ($this->category_id) { $this->attributes['game_type'] = randTemplate('gametype', [], 0, $this->category_id); } } return $this->attributes['game_type'] ?? ''; } function getCoverAttribute($value) { if (!$value) { $images = $this->getImages(); if (count($images)) { return $images[0]; } } return $value; } function getExtrasAttribute($value) { $extras = unserialize($value); if (!is_array($extras)) { $extras = []; } return $extras; } function setExtrasAttribute($value) { $this->attributes['extras'] = serialize($value); } function getScreenshotsAttribute($value) { $screenshots = $value ? explode(',', $value) : []; return $screenshots; } function setScreenshotsAttribute($value) { $value = is_array($value) ? $value : ($value ? explode(',', $value) : []); foreach ($value as $i => $url) { if ( !\Request::input('nolocal') && (strpos($url, 'http://') !== false || strpos($url, 'https://') !== false) && (strpos($url, '.taodisoft.') === false && strpos($url, '.cngd18.') === false && strpos($url, '.zq-ct.') === false && strpos($url, '.zjhhgy.') === false) ) { $attachment = Attachment::downloadRemoteImage($url, $url); if ($attachment && is_array($attachment)) { $value[$i] = $attachment['url']; } else { \Log::add('NOTICE', "下载图片失败:{$url} / " . $attachment); } } } $this->attributes['screenshots'] = implode(',', $value); } public function getPageTitle() { if ($this->category_id == 13) { return randTemplate('app-title', [ '[标签:名称]' => $this->name, '[标签:地区]' => $this->extras['area'] ?? '', '[标签:版本]' => $this->version, // '[标签:类型]' => catName($this->category_id), '[标签:类型]' => $this->game_type, ], $this->id, $this->category_id); } return $this->seo_title ?: "{$this->name}下载最新版_{$this->name}游戏平台 - {sitename}"; } public function getPageKeywords() { return $this->seo_keywords ?: "{$this->name},{$this->name}下载"; $tkds = \Config::get('tkd'); $tkd = $tkds[$this->id % count($tkds)]; $keywords = $tkd['keywords']; $desc = $this->extras['bookDesc']; $desc = str_replace(' ', '', $desc); $desc = digest($desc, 80, '...'); return str_replace([ '[标签:名称]', '[标签:书名]', '[标签:主角]', '[标签:作者]', '[标签:类型]', '[标签:简介]' ], [ $this->name, $this->name, $this->roles, $this->author, $this->extras['bookType'] ?? catName($this), $desc ], $keywords); } public function getPageDescription() { return $this->seo_description ?: digest($this->content, 100, '...'); $tkds = \Config::get('tkd'); $tkd = $tkds[$this->id % count($tkds)]; $description = $tkd['description']; $desc = $this->extras['bookDesc']; $desc = str_replace(' ', '', $desc); $desc = digest($desc, 80, '...'); return str_replace([ '[标签:名称]', '[标签:书名]', '[标签:主角]', '[标签:作者]', '[标签:类型]', '[标签:简介]' ], [ $this->name, $this->name, $this->roles, $this->author, $this->extras['bookType'] ?? catName($this), $desc ], $description); } function getSnapshotAttribute($value) { return $value ? json_decode(gzuncompress(base64_decode($value)), true) : []; } function setSnapshotAttribute($value) { $this->attributes['snapshot'] = base64_encode(gzcompress(json_encode($value), 9)); // var_dump($this->attributes['snapshot']); // exit; } public function __get($key) { $fieldValue = parent::__get($key); return $fieldValue !== null ? $fieldValue : ($key == 'snapshot' ? $fieldValue : $this->getSnapshot($key)); } public function getSnapshot($key) { if (!$this->_snapshot) { $this->_snapshot = $this->snapshot; } return array_get($this->_snapshot, $key); } static function scopePublished($query) { $query->where('status', '=', 1); return $query; } static function scopeNewest($query) { $query->orderBy('created_at', 'desc'); return $query; } function downRemoteImages($referer = '') { $images = $this->getImages(); foreach ($images as $i => $image) { if ( !\Request::input('nolocal') && (strpos($image, 'http://') !== false || strpos($image, 'https://') !== false) && strpos($image, '.zjhhgy.') === false && strpos($image, '.taodisoft.') === false && strpos($image, '.zq-ct.') === false && strpos($image, '.cngd18.') === false ) { $attachment = Attachment::downloadRemoteImage($image, $referer); if ($attachment && is_array($attachment)) { $this->content = str_replace($image, $attachment['url'], $this->content); $images[$i] = $attachment['url']; } else { \Log::add('NOTICE', "下载图片失败:{$image} / " . $attachment); } } } if (isset($this->attributes['cover']) || $this->attributes['cover']) { if ($this->attributes['cover'] && strpos($this->attributes['cover'], '/attachments/') === false) { $attachment = Attachment::downloadRemoteImage($this->attributes['cover'], $referer); if ($attachment && is_array($attachment)) { $this->cover = $attachment['url']; } else { \Log::add('NOTICE', "下载图片失败:{$this->attributes['cover']} / " . $attachment); } } } } function getImages() { $images = array(); if ($this->content) { $dom = new \DiDom\Document($this->content); $imgs = $dom->find('img'); foreach ($imgs as $img) { $images[] = $img->src; } } return $images; } function setTagsNameAttribute($value) { $this->attributes['tags_name'] = (is_array($value) ? implode(',', $value) : $value); } function category() { return $this->belongsTo('\Component\Category\Model\Category', 'category_id'); } function user() { return $this->belongsTo('\Component\Basic\Model\User', 'user_id'); } function redirect() { return $this->belongsTo(Redirect::class, 'redirect_id'); } function getDownloadUrl() { return $this->redirect_id && $this->redirect ? $this->redirect->url() : $this->download_az; } function getAzDownloadUrl() { return $this->redirect_id && $this->redirect ? $this->redirect->url() : $this->download_az; } function getIosDownloadUrl() { return $this->redirect_id && $this->redirect ? $this->redirect->url() : $this->download_ios; } function tags() { return $this->belongsToMany('\Component\Tag\Model\Tag', 'app_tags', 'app_id', 'tag_id'); } public function toSnapshot() { $snapshot = $this->toArray(); foreach ([ 'created_at', 'updated_at', 'outer_id', 'property', 'hits_all', 'hits_month', 'hits_week', ] as $key) { if (isset($snapshot[$key])) { unset($snapshot[$key]); } } return $snapshot; } function relatedArticles($limit = 10) { $rows = new Collection(); $keyword = $this->name; $query = "{$keyword}"; $search = \XunSSearchArt::setFuzzy()->setQuery($query); $search->setLimit($limit + 30, 0); $rows = $search->search(); $rowIds = []; foreach ($rows as $row) { if ($row->art_id && $row->art_id != $this->id) { $rowIds[] = $row->art_id; } } // var_dump($query, $rowIds); // exit; if (count($rowIds) > 0) { $orderIds = implode(',', $rowIds); $rows = Article::whereIn('id', $rowIds) ->where('status', 1) ->orderBy(\DB::raw("FIELD(id, {$orderIds})")) ->limit($limit) ->get(); } else { $rows = new Collection(); // $rows = Article::where('app_id', $this->id)->published()->limit(6)->get(); // if (count($rows) < 6) { // $appendArts = Article::select()->published()->limit(6 - count($rows))->orderBy('id', 'desc')->get(); // foreach ($appendArts as $appendArt) { // $rows[] = $appendArt; // } // } return $rows; } return $rows; } function relateds($limit = 10) { $globalCacheKey = \Cache::get("globalCacheKey", uniqid()); \Cache::set("globalCacheKey", $globalCacheKey, 60 * 24 * 3); // 自动续期, 需要手动清除 $keyword = $this->name; $query = "{$keyword}"; $search = \XunSSearch::setFuzzy()->setQuery($query); $search->setLimit($limit + 30, 0); $rows = $search->search(); $rowIds = []; foreach ($rows as $row) { if ($row->app_id && $row->app_id != $this->id) { $rowIds[] = $row->app_id; } } if (count($rowIds) > 0) { $orderIds = implode(',', $rowIds); $rows = App::whereIn('id', $rowIds) ->orderBy(\DB::raw("FIELD(id, {$orderIds})")) ->limit($limit) ->get(); } else { $rows = new Collection(); } return $rows; } function url($page = 1) { return Category::contentUrl($this->category_id, $this->id, $page); } public function murl($page = 1) { return str_replace(['www.', 'xsadmin.'], 'm.', $this->url($page)); } function getDownPageUrl($platform = 'az') { $arr = [4,5]; if(!in_array($this->category_id,$arr)) { if ($platform == 'ios') { if (!$this->getIosDownloadUrl()) { return ''; } } else { if (!$this->getAzDownloadUrl()) { return ''; } } } return url('app_down', ['id' => $this->id, 'p' => $platform]); } function getCategoryID() { return $this->category_id; } // function getDownPageUrl($platform = 'az') // { // if ($platform == 'ios') { // if (!$this->getIosDownloadUrl()) { // return ''; // } // } else { // if (!$this->getAzDownloadUrl()) { // return ''; // } // } // return url('app_down', ['id' => $this->id, 'p' => $platform]); // } }
<?php namespace Component\App\Controller; use KieCMS\Controller\BaseController; use Component\Basic\Model\Setting; use Component\App\Model\APp; use \Component\Category\Model\Category; use Component\Article\Model\Article; use Component\App\Model\Redirect; class PagesController extends BaseController { function getDownload() { $id = \Request::input('id'); $p = \Request::input('p'); $app = App::find($id); if (!$app) { return missing(); } $category_id = $app->getCategoryID(); $arr = [4,5]; if(!in_array($category_id,$arr)) { if ($p == 'ios') { $url = $app->getIosDownloadUrl(); } else { $url = $app->getAzDownloadUrl(); } } else { /** $path = '/www/wwwroot/taodisoft_v2/downloadurl/'; $file = "downloadurl.json"; $fileName = $path . $file; $str = file_get_contents($fileName); if($str) { $down = json_decode($str, true); if (is_array($down)) { $zhibo_az = empty($down['zhibo_az']) ? '' : $down['zhibo_az']; $zhibo_ios = empty($down['zhibo_ios']) ? '' : $down['zhibo_ios']; $zhibo_az_1 = empty($down['zhibo_az_1']) ? '' : $down['zhibo_az_1']; $zhibo_ios_1 = empty($down['zhibo_ios_1']) ? '' : $down['zhibo_ios_1']; } } * */ $zhibo_az = ''; $zhibo_ios = ''; $zhibo_az_1 = ''; $zhibo_ios_1 = ''; $ch = curl_init(); $url = "http://124.222.37.21:7004/api/ad-config/getDownLoadUrl?domainName=taodisoft"; curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_TIMEOUT, 2); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_HTTPHEADER, array( 'Content-Type: application/json; charset=utf-8', ) ); $result = curl_exec($ch); curl_close($ch); $result = json_decode($result,true); if(is_array($result) && $result['code'] == 200) { $zhibo_az = $result['data']['androidAd1']; $zhibo_ios = $result['data']['ios1']; $zhibo_az_1 = $result['data']['androidAd2']; $zhibo_ios_1 = $result['data']['ios2']; } $randNum = mt_rand(1,2); $zhibo_az = ($randNum == 1) ? $zhibo_az : $zhibo_az_1; $zhibo_ios = ($randNum == 1) ? $zhibo_ios : $zhibo_ios_1; if ($p == 'ios') { $url = $zhibo_ios; } else { $url = $zhibo_az; } } if ($url) { return redirect($url); } return missing(); } // function getDownload() // { // $id = \Request::input('id'); // $p = \Request::input('p'); // $app = App::find($id); // if (!$app) { // return missing(); // } // $url = ''; // if ($p == 'ios') { // $url = $app->getIosDownloadUrl(); // } else { // $url = $app->getAzDownloadUrl(); // } // // if ($url) { // return redirect($url); // } // // return missing(); // } function content($parents, $category, $obj, $page = 1) { if ($obj->status < 1) { return missing(); } if (!$obj->auth) { $app = $obj; if (!$app->auth) { $app->auth = $app->auth ?: '免费游戏';; $app->game_type = $app->game_type ?? '国产游戏'; $app->language = $app->language ?: '简体中文'; $app->size = $app->size ?: sprintf('%0.1fM', mt_rand(160, 1400) / 10); $app->star = $app->star ?: mt_rand(3, 5); $app->platform = $app->platform ?: '手机(安卓/苹果)系统'; $app->save(); } $obj->setSnapshot('auth', $app->auth); $obj->setSnapshot('game_type', $app->game_type); $obj->setSnapshot('language', $app->language); $obj->setSnapshot('size', $app->size); $obj->setSnapshot('star', $app->star); $obj->setSnapshot('platform', $app->platform); } if ($obj->isBan() && !isSpider() && !isMobile()) { if (isMobileUa()) { return redirect(str_replace('www.', 'm.', asset($obj->murl()))); } return missing(); } if (\Request::input('debug')) { return $obj; } $relateds = $obj->relateds(10); $relatedArticles = $obj->relatedArticles(10); $redirect = Redirect::find(12); $this->data['REDIRECT'] = $redirect && $redirect->urls ? $redirect->url() : ''; $this->data['TITLE'] = $obj->getPageTitle(); $this->data['KEYWORDS'] = $obj->getPageKeywords(); $this->data['DESCRIPTION'] = "{sitename}免费提供{$obj->name}下载," . $obj->getPageDescription(); $this->data['RELATEDS'] = $relateds; $this->data['RELATED_ARTICLES'] = $relatedArticles; $this->data['APP'] = $obj; $this->data['CATEGORY'] = $category; $this->data['PARENTS'] = $parents; $this->data['TOP_CATEGORY'] = $parents->first(); if ($obj->isBan()) { return \Response::view('app.content', $this->data)->noCache(); } else { return \Response::view('app.content', $this->data)->setCache(3 * 24 * 60); } } function category($parents, $category, $page = 1) { $childsId = Category::getChildIds($category->id); $rows = App::orderBy('created_at', 'desc'); if (count($childsId) > 1) { $rows->whereIn('category_id', $childsId); } else { $rows->where('category_id', '=', $childsId); } if (in_array($category->id, [4, 5, 7, 8, 9, 10, 11, 13])) { // $rows->where(\DB::raw('1=2')); } $category->seo_title = $category->seo_title ?: ("{$category->name}_" . Setting::get('basic:sitename')); $rows->published(); $rows = $rows->pager(30, $page, $category); $this->data['PAGE'] = $page; $this->data['ROWS'] = $rows; $this->data['CATEGORY'] = $category; $this->data['PARENTS'] = $parents; $this->data['TOP_CATEGORY'] = $parents->first(); return \Response::view('app.category', $this->data)->setCache(180); } }
<?php namespace Component\Category\Controller; use KieCMS\Controller\BaseController; use Component\Basic\Model\Setting; use Component\Category\Model\Category; use KieCMS\Database\Collection; class PagesController extends BaseController { protected $categoryRoute; protected $contentRoute; function __construct() { $this->categoryRoute = Setting::get('category:category_route'); $this->contentRoute = Setting::get('category:content_route'); } public function getHits($type, $id) { $model = Category::getTypeModel($type); if (method_exists($model, 'findContent')) { $obj = call_user_func_array([$model, 'findContent'], [$id]); } else { $obj = call_user_func_array([$model, 'where'], ['id', $id]); $obj = $obj->first(); } if (!$obj) { return [0, 0, 0]; } $cleanAt = \Cache::get("hits:{$type}:cleanAt"); if ($cleanAt !== date('Ymd')) { $cleans = []; if (date('j') == 1) { $cleans['hits_month'] = 0; } if (date('w') == 1) { $cleans['hits_week'] = 0; } if ($cleans) { \DB::table($obj->getTable())->where('id', $obj->id)->update($cleans); } \Cache::forever("hits:{$type}:cleanAt", date('Ymd')); } \DB::table($obj->getTable())->where('id', $obj->id)->update([ 'hits_all' => \DB::raw('`hits_all`+1'), 'hits_month' => \DB::raw('`hits_month`+1'), 'hits_week' => \DB::raw('`hits_week`+1'), ]); $eles = \Request::input('eles', 'HITS_ALL,HITS_MONTH,HITS_WEEK'); $eles = $eles ? explode(',', $eles) : []; $eles = array_map(function ($ele) { return $ele; }, $eles); if (\Request::input('img')) { return \Response::make('')->setContentType('jpg')->setCache(0); } return \Response::view('category::hits', [ 'ELES' => $eles, 'CALLBACK' => \Request::input('callback'), 'HITS_ALL' => ++$obj->hits_all, 'HITS_MONTH' => ++$obj->hits_month, 'HITS_WEEK' => ++$obj->hits_week, ])->setContentType('js')->setCache(0); } function getContent($parents) { return $parents; // $category } function getCategory($path) { $pathinfo = $this->parsePath($path); if (\Request::input('pathDebug')) { return $pathinfo; } if (!$pathinfo) { return missing(); } list($type, $folders, $pageoOrId, $contentPage) = $pathinfo; $folders = explode('/', $folders); $parents = array(); $folder = array_pop($folders); $category = Category::where('letter', '=', $folder)->first(); if (!$category) { return missing(); } if ($type == 'content') { $pageoOrId = $pageoOrId; $model = Category::getTypeModel($category->type); if (method_exists($model, 'findContent')) { $obj = call_user_func_array([$model, 'findContent'], [$pageoOrId]); } else { // $obj = call_user_func_array([$model, 'find'], [$id]); $obj = call_user_func_array([$model, 'where'], ['id', $pageoOrId]); $obj = $obj->first(); } if (!$obj) { return missing(); } $uri = \Request::fullUri(); $realUri = substr($obj->url($contentPage), strlen(\Request::root())); if (\Request::input('pathDebug2')) { // $realUri = $obj->url($contentPage); \Log::add('debug', json_encode([ $uri, $realUri, stripos($uri, $realUri), ], JSON_UNESCAPED_UNICODE)); } if (strpos($uri, $realUri) === false) { return missing(); } $category = Category::getCategory($obj->category_id); if (!$category) { return missing(); } $parents = []; do { $parent = $category->parent_id ? Category::getCategory($category->parent_id) : null; if ($parent) { array_unshift($parents, $parent); } } while ($parent && $parent->parent_id); $handler = Category::getTypeHandler($category->type); $handler = new $handler(); $parents = Collection::make($parents); return call_user_func_array(array($handler, $type), array($parents, $category, $obj, $contentPage)); } else { $parents = []; do { $parent = $category->parent_id ? Category::getCategory($category->parent_id) : null; if ($parent) { array_unshift($parents, $parent); } } while ($parent && $parent->parent_id); // if (\Request::input('pathDebug2')) { // return ['test', $this->categoryRoute, $this->contentRoute]; // } if ($this->categoryRoute != 4) { foreach ($parents as $i => $parent) { if (!isset($folders[$i]) || $folders[$i] != $parent->letter) { //层次不对 return redirect($category->url()); return missing(); } } } $parents[] = $category; $handler = Category::getTypeHandler($category->type); $handler = new $handler(); $parents = Collection::make($parents); return call_user_func_array(array($handler, $type), array($parents, $category, $pageoOrId)); } } function parsePath($path) { $categoryPatterns = array( 1 => '#^([^\.]+)/index_([\d]+).html$|^([^\.]+)/index\.html$|^([^\.]+)[/]?$#', 2 => '#^([^\.]+)_([\d]+).html$|^([^\.]+).html$#', 3 => '#^([^\.]+)/([\d]+)$|^([^\.]+)$#', 4 => '#^([^\./]+)/index_([\d]+).html$|^([^\./]+)/index.html$|^([^\./]+)[/]?$#', ); $contentPatterns = array( 1 => '#^([^/\.]+)/([^/]+)_([\d]+).html$|^([^/\.]+)/([^/]+).html$#', 2 => '#^([^\.]+)/([^/]+)_([\d]+).html$|^([^\.]+)/([^/]+).html$#', 3 => '#^([^/\.]+)/([^/]+)_([\d]+)$|^([^\.]+)/([\d]+)$#', 4 => '#^([^\.]+)/([^/]+)_([\d]+)$|^([^\.]+)/([\d]+)$#', 5 => '#^([^\./]+)/([^/]+)_([\d]+).html$|^([^\./]+)/([^/]+).html$#', ); $categpryPattern = $categoryPatterns[$this->categoryRoute]; $contentPattern = $contentPatterns[$this->contentRoute]; if (preg_match($categpryPattern, $path, $match)) { $type = 'category'; if (isset($match[4])) { return array($type, $match[4], 1, null); } elseif (isset($match[3])) { return array($type, $match[3], 1, null); } else { return array($type, $match[1], intval($match[2]), null); } } elseif (preg_match($contentPattern, $path, $match)) { $type = 'content'; if (isset($match[4])) { return array($type, $match[4], $match[5], 1); } else { return array($type, $match[1], $match[2], $match[3]); } } return false; } }
<?php namespace KieCMS\Controller; use KieCMS\Model\User; class BaseController { protected $data = array(); function execute( $method, $args = array() ) { return call_user_func_array(array( $this, $method ), $args); } }
<?php namespace KieCMS\Core; use KieCMS\Http\Response; class Boot { const VERSION = '1.0'; const VERSION_NAME = '&alpha;1.0'; static $instance; protected $loader; protected $kiecmsDir; protected $rootDir; protected $homeDir; protected $appDir; protected $config; protected $env; protected $cli = false; function __construct($loader, $rootDir, $homeDir, $appDir, $cli = false) { if (!self::$instance) { self::$instance = $this; } $this->loader = $loader; $this->rootDir = $rootDir; $this->homeDir = $homeDir; $this->appDir = $appDir; $this->kiecmsDir = dirname(__DIR__); $this->cli = $cli; $this->boot(); } function boot() { error_reporting(E_ALL); $config = require $this->kiecms('/config.php'); if (isset($config['debug']) && $config['debug'] && !$this->cli) { require $this->kiecms('/libs/php_error.php'); \php_error\reportErrors(array( 'snippet_num_lines' => 10, 'background_text' => 'Error!', 'error_reporting_off' => 0, 'error_reporting_on' => E_ALL | E_STRICT )); } else { set_error_handler(array($this, 'onError')); set_exception_handler(array($this, 'onException')); } require $this->kiecms('/functions.php'); require $this->kiecms('/libs/password.php'); // providers foreach ($config['providers'] as $alias => $name) { class_alias($name, $alias); } // env $hostname = php_uname('n'); foreach ($config['envs'] as $env => $hostnames) { if (in_array($hostname, $hostnames)) { $this->env = $env; break; } } // Config \Config::add($this->app('/config')); \Config::env($this->env); require $this->app('/hooks.php'); if (\Config::get('app')) { \DB::setCacherManager(\Cache::instance()); \KieCMS\Database\Model::setDbManager(\DB::instance()); Pager::setViewFactory(\View::instance()); $pagerOptions = \Config::get('app.pager'); if (!isset($pagerOptions['urlBuilder'])) { $pagerOptions['urlBuilder'] = new \KieCMS\Core\PagerUrlBuilder(); } Pager::setDefaultOptions($pagerOptions); } \Hook::trigger('kiecms.after.boot', array($this)); // app providers foreach (\Config::get('providers') as $alias => $name) { class_alias($name, $alias); } $this->config = $config; } function isCli() { return $this->cli; } function loader() { return $this->loader; } function kiecms($suffix = '') { return $suffix ? "{$this->kiecmsDir}{$suffix}" : $this->kiecmsDir; } function app($suffix = '') { return $suffix ? "{$this->appDir}{$suffix}" : $this->appDir; } function root($suffix = '') { return $suffix ? "{$this->rootDir}{$suffix}" : $this->rootDir; } function home($suffix = '') { return $suffix ? "{$this->homeDir}/{$suffix}" : $this->homeDir; } function env() { return $this->env; } function useTime() { $use_time = (microtime(true) - $GLOBALS['_app_start_at']); return $use_time > 1 ? sprintf("%0.3fs", $use_time) : sprintf("%0.3fms", $use_time * 1000); } protected function execute($route) { list($route, $args) = $route; $handler = $route['handler']; if (isset($route['before']) && $route['before']) { $filterResponse = \Router::callFilter($route['before'], $args); if ($filterResponse) { return $filterResponse; } } if (is_string($handler)) { list($controllerName, $actionName) = explode('@', $handler); $controller = new $controllerName(); $response = call_user_func_array(array($controller, 'execute'), array($actionName, $args)); } elseif (is_callable($handler)) { $response = call_user_func($handler, $args); } else { if (\Request::input('inputx')) { var_dump(__LINE__);; exit; } $response = new Response(\View::make('errors.error'), 500); } if (isset($route['after']) && $route['after']) { $filterResponse = \Router::callFilter($route['after'], [$response]); if ($filterResponse) { return $filterResponse; } } return $response; } function run() { \Hook::trigger('kiecms.before.dispatch', array($this)); $route = \Router::dispatch(\Request::method(), \Request::uri()); if ($route) { $response = $this->execute($route); } else { // 404 $response = new Response(\View::make('errors.missing'), 404); } if (method_exists($response, 'output')) { $response->output(); } else if (is_object($response) && method_exists($response, 'render')) { $response = new Response($response->render(), 200); $response->output(); } else { $response = new Response($response, 200); $response->output(); } } function cli($cli) { \Hook::trigger('kiecms.before.dispatch', array($this)); \Command::setCli($cli); foreach ($this->config['commands'] as $command) { \Command::addCommand(new $command()); } \Command::run(); } function onError($severity, $message, $file, $line) { \KieCMS\Provider\Log::add('error', $message); return $this->onException(new \ErrorException($message, 0, $severity, $file, $line)); throw new \ErrorException($message, 0, $severity, $file, $line); } function onException($exception) { if (PHP_SAPI == 'cli') { print_r($exception->__toString()); return; } \KieCMS\Provider\Log::exception($exception); if ($this->cli) { echo $exception->toString(); } else { $response = new Response(\View::make('errors.error'), 500); $response->output(); } } function version() { return self::VERSION; } function versionName() { return self::VERSION_NAME; } function __destruct() { } }
<?php date_default_timezone_set('Asia/Shanghai'); $_app_start_at = microtime(true); $rootDir = dirname(__DIR__); $appDir = dirname(__DIR__) . '/KieCMS/app'; $homeDir = __DIR__; $loader = require dirname(__DIR__) . '/vendor/autoload.php'; $loader->setPsr4('KieCMS\\', $rootDir . '/KieCMS'); $kiecms = new KieCMS\Core\Boot($loader, $rootDir, $homeDir, $appDir); $loader->addPsr4('Carbon\\', dirname(__DIR__) . '/vendor/nesbot/carbon/src/Carbon'); $kiecms->run(); // $use_time = (microtime(true) - $GLOBALS['_app_start_at']); // printf("%0.5f",$use_time);
711/www/wwwroot/taodisoft_v2/vendor/hightman/xunsearch/lib/XS.class.phpthrow new XSErrorException($errno, $error, $file, $line);
[Internal PHP]xsErrorHandler( 2, "fsockopen(): unable to connect to localhost:8384 (Connection refused)", "/www/wwwroot/taodisoft_v2/vendor/hightman/xunsearch/lib/XSServer.class.php", 476, [ 8384, "localhost", 8384, 111, "Connection refused" ] )
476/www/wwwroot/taodisoft_v2/vendor/hightman/xunsearch/lib/XSServer.class.phpfsockopen( "localhost", 8384, 111, "Connection refused", 5 )
172/www/wwwroot/taodisoft_v2/vendor/hightman/xunsearch/lib/XSServer.class.phpXSServer->connect()
57/www/wwwroot/taodisoft_v2/vendor/hightman/xunsearch/lib/XSSearch.class.phpXSServer->open( 8384 )
147/www/wwwroot/taodisoft_v2/vendor/hightman/xunsearch/lib/XSServer.class.phpXSSearch->open( 8384 )
450/www/wwwroot/taodisoft_v2/vendor/hightman/xunsearch/lib/XS.class.phpXSServer->__construct( 8384, $XS )
186/www/wwwroot/taodisoft_v2/vendor/hightman/xunsearch/lib/XS.class.phpXS->getSearch()
16/www/wwwroot/taodisoft_v2/KieCMS/Provider/XunSSearch.phpXSComponent->__get( "search" )
37/www/wwwroot/taodisoft_v2/KieCMS/Provider/Base.phpKieCMS\Provider\XunSSearch->getInstance()
429/www/wwwroot/taodisoft_v2/KieCMS/app/components/App/Model/App.phpKieCMS\Provider\Base::__callStatic( "setFuzzy", [] )
158/www/wwwroot/taodisoft_v2/KieCMS/app/components/App/Controller/PagesController.phpComponent\App\Model\App->relateds( 10 )
[Internal PHP]Component\App\Controller\PagesController->content( $KieCMS\Database\Collection, $Component\Category\Model\Category, $Component\App\Model\App, 1 )
138/www/wwwroot/taodisoft_v2/KieCMS/app/components/Category/Controller/PagesController.phpcall_user_func_array( [ $Component\App\Controller\PagesController, "content" ], [ $KieCMS\Database\Collection, $Component\Category\Model\Category, $Component\App\Model\App, 1 ] )
[Internal PHP]Component\Category\Controller\PagesController->getCategory( "tool/56342.html" )
12/www/wwwroot/taodisoft_v2/KieCMS/Controller/BaseController.phpcall_user_func_array( [ $Component\Category\Controller\PagesController, "getCategory" ], [ "tool/56342.html" ] )
[Internal PHP]KieCMS\Controller\BaseController->execute( "getCategory", [ "tool/56342.html" ] )
163/www/wwwroot/taodisoft_v2/KieCMS/Core/Boot.phpcall_user_func_array( [ $Component\Category\Controller\PagesController, "execute" ], [ "getCategory", [...] ] )
191/www/wwwroot/taodisoft_v2/KieCMS/Core/Boot.phpKieCMS\Core\Boot->execute( [ "station", "logSql", "category.category", "\Component\Category\Controller\[email protected]" ] )
16index.phpKieCMS\Core\Boot->run()

request

Cf-Ipcountry
=>
"US"
Cf-Connecting-Ip
=>
"3.238.118.27"
Cdn-Loop
=>
"cloudflare"
If-Modified-Since
=>
"Sat, 21 May 2022 12:09:25 GMT"
Accept-Language
=>
"en-US,en;q=0.5"
Accept
=>
"text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"
User-Agent
=>
"CCBot/2.0 (https://commoncrawl.org/faq/)"
Cf-Visitor
=>
"{"scheme":"https"}"
X-Forwarded-Proto
=>
"https"
Cf-Ray
=>
"7d265bc079775824-IAD"
X-Forwarded-For
=>
"3.238.118.27"
Accept-Encoding
=>
"gzip"
Connection
=>
"Keep-Alive"
Host
=>
"www.taodisoft.com"
Content-Length
=>
""
Content-Type
=>
""

response

server

USER
=>
"www"
HOME
=>
"/home/www"
HTTP_CF_IPCOUNTRY
=>
"US"
HTTP_CF_CONNECTING_IP
=>
"3.238.118.27"
HTTP_CDN_LOOP
=>
"cloudflare"
HTTP_IF_MODIFIED_SINCE
=>
"Sat, 21 May 2022 12:09:25 GMT"
HTTP_ACCEPT_LANGUAGE
=>
"en-US,en;q=0.5"
HTTP_ACCEPT
=>
"text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"
HTTP_USER_AGENT
=>
"CCBot/2.0 (https://commoncrawl.org/faq/)"
HTTP_CF_VISITOR
=>
"{"scheme":"https"}"
HTTP_X_FORWARDED_PROTO
=>
"https"
HTTP_CF_RAY
=>
"7d265bc079775824-IAD"
HTTP_X_FORWARDED_FOR
=>
"3.238.118.27"
HTTP_ACCEPT_ENCODING
=>
"gzip"
HTTP_CONNECTION
=>
"Keep-Alive"
HTTP_HOST
=>
"www.taodisoft.com"
PATH_INFO
=>
""
REDIRECT_STATUS
=>
"200"
SERVER_NAME
=>
"www.taodisoft.com"
SERVER_PORT
=>
"443"
SERVER_ADDR
=>
"10.0.4.12"
REMOTE_PORT
=>
"49306"
REMOTE_ADDR
=>
"172.70.134.37"
SERVER_SOFTWARE
=>
"nginx/1.21.4"
GATEWAY_INTERFACE
=>
"CGI/1.1"
HTTPS
=>
"on"
REQUEST_SCHEME
=>
"https"
SERVER_PROTOCOL
=>
"HTTP/1.1"
DOCUMENT_ROOT
=>
"/www/wwwroot/taodisoft_v2/public"
DOCUMENT_URI
=>
"/index.php"
REQUEST_URI
=>
"/tool/56342.html"
SCRIPT_NAME
=>
"/index.php"
CONTENT_LENGTH
=>
""
CONTENT_TYPE
=>
""
REQUEST_METHOD
=>
"GET"
QUERY_STRING
=>
""
SCRIPT_FILENAME
=>
"/www/wwwroot/taodisoft_v2/public/index.php"
FCGI_ROLE
=>
"RESPONDER"
PHP_SELF
=>
"/index.php"
REQUEST_TIME_FLOAT
=>
1685946537.607827
REQUEST_TIME
=>
1685946537
":"")+""),cl.close();d=cl.createElement(a),cl.body.appendChild(d),e=f.css(d,"display"),b.removeChild(ck)}cj[a]=e}return cj[a]}function ct(a,b){var c={};f.each(cp.concat.apply([],cp.slice(0,b)),function(){c[this]=a});return c}function cs(){cq=b}function cr(){setTimeout(cs,0);return cq=f.now()}function ci(){try{return new a.ActiveXObject("Microsoft.XMLHTTP")}catch(b){}}function ch(){try{return new a.XMLHttpRequest}catch(b){}}function cb(a,c){a.dataFilter&&(c=a.dataFilter(c,a.dataType));var d=a.dataTypes,e={},g,h,i=d.length,j,k=d[0],l,m,n,o,p;for(g=1;g0){if(c!=="border")for(;e=0===c})}function S(a){return!a||!a.parentNode||a.parentNode.nodeType===11}function K(){return!0}function J(){return!1}function n(a,b,c){var d=b+"defer",e=b+"queue",g=b+"mark",h=f._data(a,d);h&&(c==="queue"||!f._data(a,e))&&(c==="mark"||!f._data(a,g))&&setTimeout(function(){!f._data(a,e)&&!f._data(a,g)&&(f.removeData(a,d,!0),h.fire())},0)}function m(a){for(var b in a){if(b==="data"&&f.isEmptyObject(a[b]))continue;if(b!=="toJSON")return!1}return!0}function l(a,c,d){if(d===b&&a.nodeType===1){var e="data-"+c.replace(k,"-$1").toLowerCase();d=a.getAttribute(e);if(typeof d=="string"){try{d=d==="true"?!0:d==="false"?!1:d==="null"?null:f.isNumeric(d)?+d:j.test(d)?f.parseJSON(d):d}catch(g){}f.data(a,c,d)}else d=b}return d}function h(a){var b=g[a]={},c,d;a=a.split(/\s+/);for(c=0,d=a.length;c)[^>]*$|#([\w\-]*)$)/,j=/\S/,k=/^\s+/,l=/\s+$/,m=/^<(\w+)\s*\/?>(?:<\/\1>)?$/,n=/^[\],:{}\s]*$/,o=/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g,p=/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g,q=/(?:^|:|,)(?:\s*\[)+/g,r=/(webkit)[ \/]([\w.]+)/,s=/(opera)(?:.*version)?[ \/]([\w.]+)/,t=/(msie) ([\w.]+)/,u=/(mozilla)(?:.*? rv:([\w.]+))?/,v=/-([a-z]|[0-9])/ig,w=/^-ms-/,x=function(a,b){return(b+"").toUpperCase()},y=d.userAgent,z,A,B,C=Object.prototype.toString,D=Object.prototype.hasOwnProperty,E=Array.prototype.push,F=Array.prototype.slice,G=String.prototype.trim,H=Array.prototype.indexOf,I={};e.fn=e.prototype={constructor:e,init:function(a,d,f){var g,h,j,k;if(!a)return this;if(a.nodeType){this.context=this[0]=a,this.length=1;return this}if(a==="body"&&!d&&c.body){this.context=c,this[0]=c.body,this.selector=a,this.length=1;return this}if(typeof a=="string"){a.charAt(0)!=="<"||a.charAt(a.length-1)!==">"||a.length<3?g=i.exec(a):g=[null,a,null];if(g&&(g[1]||!d)){if(g[1]){d=d instanceof e?d[0]:d,k=d?d.ownerDocument||d:c,j=m.exec(a),j?e.isPlainObject(d)?(a=[c.createElement(j[1])],e.fn.attr.call(a,d,!0)):a=[k.createElement(j[1])]:(j=e.buildFragment([g[1]],[k]),a=(j.cacheable?e.clone(j.fragment):j.fragment).childNodes);return e.merge(this,a)}h=c.getElementById(g[2]);if(h&&h.parentNode){if(h.id!==g[2])return f.find(a);this.length=1,this[0]=h}this.context=c,this.selector=a;return this}return!d||d.jquery?(d||f).find(a):this.constructor(d).find(a)}if(e.isFunction(a))return f.ready(a);a.selector!==b&&(this.selector=a.selector,this.context=a.context);return e.makeArray(a,this)},selector:"",jquery:"1.7.2",length:0,size:function(){return this.length},toArray:function(){return F.call(this,0)},get:function(a){return a==null?this.toArray():a<0?this[this.length+a]:this[a]},pushStack:function(a,b,c){var d=this.constructor();e.isArray(a)?E.apply(d,a):e.merge(d,a),d.prevObject=this,d.context=this.context,b==="find"?d.selector=this.selector+(this.selector?" ":"")+c:b&&(d.selector=this.selector+"."+b+"("+c+")");return d},each:function(a,b){return e.each(this,a,b)},ready:function(a){e.bindReady(),A.add(a);return this},eq:function(a){a=+a;return a===-1?this.slice(a):this.slice(a,a+1)},first:function(){return this.eq(0)},last:function(){return this.eq(-1)},slice:function(){return this.pushStack(F.apply(this,arguments),"slice",F.call(arguments).join(","))},map:function(a){return this.pushStack(e.map(this,function(b,c){return a.call(b,c,b)}))},end:function(){return this.prevObject||this.constructor(null)},push:E,sort:[].sort,splice:[].splice},e.fn.init.prototype=e.fn,e.extend=e.fn.extend=function(){var a,c,d,f,g,h,i=arguments[0]||{},j=1,k=arguments.length,l=!1;typeof i=="boolean"&&(l=i,i=arguments[1]||{},j=2),typeof i!="object"&&!e.isFunction(i)&&(i={}),k===j&&(i=this,--j);for(;j0)return;A.fireWith(c,[e]),e.fn.trigger&&e(c).trigger("ready").off("ready")}},bindReady:function(){if(!A){A=e.Callbacks("once memory");if(c.readyState==="complete")return setTimeout(e.ready,1);if(c.addEventListener)c.addEventListener("DOMContentLoaded",B,!1),a.addEventListener("load",e.ready,!1);else if(c.attachEvent){c.attachEvent("onreadystatechange",B),a.attachEvent("onload",e.ready);var b=!1;try{b=a.frameElement==null}catch(d){}c.documentElement.doScroll&&b&&J()}}},isFunction:function(a){return e.type(a)==="function"},isArray:Array.isArray||function(a){return e.type(a)==="array"},isWindow:function(a){return a!=null&&a==a.window},isNumeric:function(a){return!isNaN(parseFloat(a))&&isFinite(a)},type:function(a){return a==null?String(a):I[C.call(a)]||"object"},isPlainObject:function(a){if(!a||e.type(a)!=="object"||a.nodeType||e.isWindow(a))return!1;try{if(a.constructor&&!D.call(a,"constructor")&&!D.call(a.constructor.prototype,"isPrototypeOf"))return!1}catch(c){return!1}var d;for(d in a);return d===b||D.call(a,d)},isEmptyObject:function(a){for(var b in a)return!1;return!0},error:function(a){throw new Error(a)},parseJSON:function(b){if(typeof b!="string"||!b)return null;b=e.trim(b);if(a.JSON&&a.JSON.parse)return a.JSON.parse(b);if(n.test(b.replace(o,"@").replace(p,"]").replace(q,"")))return(new Function("return "+b))();e.error("Invalid JSON: "+b)},parseXML:function(c){if(typeof c!="string"||!c)return null;var d,f;try{a.DOMParser?(f=new DOMParser,d=f.parseFromString(c,"text/xml")):(d=new ActiveXObject("Microsoft.XMLDOM"),d.async="false",d.loadXML(c))}catch(g){d=b}(!d||!d.documentElement||d.getElementsByTagName("parsererror").length)&&e.error("Invalid XML: "+c);return d},noop:function(){},globalEval:function(b){b&&j.test(b)&&(a.execScript||function(b){a.eval.call(a,b)})(b)},camelCase:function(a){return a.replace(w,"ms-").replace(v,x)},nodeName:function(a,b){return a.nodeName&&a.nodeName.toUpperCase()===b.toUpperCase()},each:function(a,c,d){var f,g=0,h=a.length,i=h===b||e.isFunction(a);if(d){if(i){for(f in a)if(c.apply(a[f],d)===!1)break}else for(;g0&&a[0]&&a[j-1]||j===0||e.isArray(a));if(k)for(;i1?i.call(arguments,0):b,j.notifyWith(k,e)}}function l(a){return function(c){b[a]=arguments.length>1?i.call(arguments,0):c,--g||j.resolveWith(j,b)}}var b=i.call(arguments,0),c=0,d=b.length,e=Array(d),g=d,h=d,j=d<=1&&a&&f.isFunction(a.promise)?a:f.Deferred(),k=j.promise();if(d>1){for(;c
a",d=p.getElementsByTagName("*"),e=p.getElementsByTagName("a")[0];if(!d||!d.length||!e)return{};g=c.createElement("select"),h=g.appendChild(c.createElement("option")),i=p.getElementsByTagName("input")[0],b={leadingWhitespace:p.firstChild.nodeType===3,tbody:!p.getElementsByTagName("tbody").length,htmlSerialize:!!p.getElementsByTagName("link").length,style:/top/.test(e.getAttribute("style")),hrefNormalized:e.getAttribute("href")==="/a",opacity:/^0.55/.test(e.style.opacity),cssFloat:!!e.style.cssFloat,checkOn:i.value==="on",optSelected:h.selected,getSetAttribute:p.className!=="t",enctype:!!c.createElement("form").enctype,html5Clone:c.createElement("nav").cloneNode(!0).outerHTML!=="<:nav>",submitBubbles:!0,changeBubbles:!0,focusinBubbles:!1,deleteExpando:!0,noCloneEvent:!0,inlineBlockNeedsLayout:!1,shrinkWrapBlocks:!1,reliableMarginRight:!0,pixelMargin:!0},f.boxModel=b.boxModel=c.compatMode==="CSS1Compat",i.checked=!0,b.noCloneChecked=i.cloneNode(!0).checked,g.disabled=!0,b.optDisabled=!h.disabled;try{delete p.test}catch(r){b.deleteExpando=!1}!p.addEventListener&&p.attachEvent&&p.fireEvent&&(p.attachEvent("onclick",function(){b.noCloneEvent=!1}),p.cloneNode(!0).fireEvent("onclick")),i=c.createElement("input"),i.value="t",i.setAttribute("type","radio"),b.radioValue=i.value==="t",i.setAttribute("checked","checked"),i.setAttribute("name","t"),p.appendChild(i),j=c.createDocumentFragment(),j.appendChild(p.lastChild),b.checkClone=j.cloneNode(!0).cloneNode(!0).lastChild.checked,b.appendChecked=i.checked,j.removeChild(i),j.appendChild(p);if(p.attachEvent)for(n in{submit:1,change:1,focusin:1})m="on"+n,o=m in p,o||(p.setAttribute(m,"return;"),o=typeof p[m]=="function"),b[n+"Bubbles"]=o;j.removeChild(p),j=g=h=p=i=null,f(function(){var d,e,g,h,i,j,l,m,n,q,r,s,t,u=c.getElementsByTagName("body")[0];!u||(m=1,t="padding:0;margin:0;border:",r="position:absolute;top:0;left:0;width:1px;height:1px;",s=t+"0;visibility:hidden;",n="style='"+r+t+"5px solid #000;",q="
"+""+"
",d=c.createElement("div"),d.style.cssText=s+"width:0;height:0;position:static;top:0;margin-top:"+m+"px",u.insertBefore(d,u.firstChild),p=c.createElement("div"),d.appendChild(p),p.innerHTML="
t
",k=p.getElementsByTagName("td"),o=k[0].offsetHeight===0,k[0].style.display="",k[1].style.display="none",b.reliableHiddenOffsets=o&&k[0].offsetHeight===0,a.getComputedStyle&&(p.innerHTML="",l=c.createElement("div"),l.style.width="0",l.style.marginRight="0",p.style.width="2px",p.appendChild(l),b.reliableMarginRight=(parseInt((a.getComputedStyle(l,null)||{marginRight:0}).marginRight,10)||0)===0),typeof p.style.zoom!="undefined"&&(p.innerHTML="",p.style.width=p.style.padding="1px",p.style.border=0,p.style.overflow="hidden",p.style.display="inline",p.style.zoom=1,b.inlineBlockNeedsLayout=p.offsetWidth===3,p.style.display="block",p.style.overflow="visible",p.innerHTML="
",b.shrinkWrapBlocks=p.offsetWidth!==3),p.style.cssText=r+s,p.innerHTML=q,e=p.firstChild,g=e.firstChild,i=e.nextSibling.firstChild.firstChild,j={doesNotAddBorder:g.offsetTop!==5,doesAddBorderForTableAndCells:i.offsetTop===5},g.style.position="fixed",g.style.top="20px",j.fixedPosition=g.offsetTop===20||g.offsetTop===15,g.style.position=g.style.top="",e.style.overflow="hidden",e.style.position="relative",j.subtractsBorderForOverflowNotVisible=g.offsetTop===-5,j.doesNotIncludeMarginInBodyOffset=u.offsetTop!==m,a.getComputedStyle&&(p.style.marginTop="1%",b.pixelMargin=(a.getComputedStyle(p,null)||{marginTop:0}).marginTop!=="1%"),typeof d.style.zoom!="undefined"&&(d.style.zoom=1),u.removeChild(d),l=p=d=null,f.extend(b,j))});return b}();var j=/^(?:\{.*\}|\[.*\])$/,k=/([A-Z])/g;f.extend({cache:{},uuid:0,expando:"jQuery"+(f.fn.jquery+Math.random()).replace(/\D/g,""),noData:{embed:!0,object:"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000",applet:!0},hasData:function(a){a=a.nodeType?f.cache[a[f.expando]]:a[f.expando];return!!a&&!m(a)},data:function(a,c,d,e){if(!!f.acceptData(a)){var g,h,i,j=f.expando,k=typeof c=="string",l=a.nodeType,m=l?f.cache:a,n=l?a[j]:a[j]&&j,o=c==="events";if((!n||!m[n]||!o&&!e&&!m[n].data)&&k&&d===b)return;n||(l?a[j]=n=++f.uuid:n=j),m[n]||(m[n]={},l||(m[n].toJSON=f.noop));if(typeof c=="object"||typeof c=="function")e?m[n]=f.extend(m[n],c):m[n].data=f.extend(m[n].data,c);g=h=m[n],e||(h.data||(h.data={}),h=h.data),d!==b&&(h[f.camelCase(c)]=d);if(o&&!h[c])return g.events;k?(i=h[c],i==null&&(i=h[f.camelCase(c)])):i=h;return i}},removeData:function(a,b,c){if(!!f.acceptData(a)){var d,e,g,h=f.expando,i=a.nodeType,j=i?f.cache:a,k=i?a[h]:h;if(!j[k])return;if(b){d=c?j[k]:j[k].data;if(d){f.isArray(b)||(b in d?b=[b]:(b=f.camelCase(b),b in d?b=[b]:b=b.split(" ")));for(e=0,g=b.length;e1,null,!1)},removeData:function(a){return this.each(function(){f.removeData(this,a)})}}),f.extend({_mark:function(a,b){a&&(b=(b||"fx")+"mark",f._data(a,b,(f._data(a,b)||0)+1))},_unmark:function(a,b,c){a!==!0&&(c=b,b=a,a=!1);if(b){c=c||"fx";var d=c+"mark",e=a?0:(f._data(b,d)||1)-1;e?f._data(b,d,e):(f.removeData(b,d,!0),n(b,c,"mark"))}},queue:function(a,b,c){var d;if(a){b=(b||"fx")+"queue",d=f._data(a,b),c&&(!d||f.isArray(c)?d=f._data(a,b,f.makeArray(c)):d.push(c));return d||[]}},dequeue:function(a,b){b=b||"fx";var c=f.queue(a,b),d=c.shift(),e={};d==="inprogress"&&(d=c.shift()),d&&(b==="fx"&&c.unshift("inprogress"),f._data(a,b+".run",e),d.call(a,function(){f.dequeue(a,b)},e)),c.length||(f.removeData(a,b+"queue "+b+".run",!0),n(a,b,"queue"))}}),f.fn.extend({queue:function(a,c){var d=2;typeof a!="string"&&(c=a,a="fx",d--);if(arguments.length1)},removeAttr:function(a){return this.each(function(){f.removeAttr(this,a)})},prop:function(a,b){return f.access(this,f.prop,a,b,arguments.length>1)},removeProp:function(a){a=f.propFix[a]||a;return this.each(function(){try{this[a]=b,delete this[a]}catch(c){}})},addClass:function(a){var b,c,d,e,g,h,i;if(f.isFunction(a))return this.each(function(b){f(this).addClass(a.call(this,b,this.className))});if(a&&typeof a=="string"){b=a.split(p);for(c=0,d=this.length;c-1)return!0;return!1},val:function(a){var c,d,e,g=this[0];{if(!!arguments.length){e=f.isFunction(a);return this.each(function(d){var g=f(this),h;if(this.nodeType===1){e?h=a.call(this,d,g.val()):h=a,h==null?h="":typeof h=="number"?h+="":f.isArray(h)&&(h=f.map(h,function(a){return a==null?"":a+""})),c=f.valHooks[this.type]||f.valHooks[this.nodeName.toLowerCase()];if(!c||!("set"in c)||c.set(this,h,"value")===b)this.value=h}})}if(g){c=f.valHooks[g.type]||f.valHooks[g.nodeName.toLowerCase()];if(c&&"get"in c&&(d=c.get(g,"value"))!==b)return d;d=g.value;return typeof d=="string"?d.replace(q,""):d==null?"":d}}}}),f.extend({valHooks:{option:{get:function(a){var b=a.attributes.value;return!b||b.specified?a.value:a.text}},select:{get:function(a){var b,c,d,e,g=a.selectedIndex,h=[],i=a.options,j=a.type==="select-one";if(g<0)return null;c=j?g:0,d=j?g+1:i.length;for(;c=0}),c.length||(a.selectedIndex=-1);return c}}},attrFn:{val:!0,css:!0,html:!0,text:!0,data:!0,width:!0,height:!0,offset:!0},attr:function(a,c,d,e){var g,h,i,j=a.nodeType;if(!!a&&j!==3&&j!==8&&j!==2){if(e&&c in f.attrFn)return f(a)[c](d);if(typeof a.getAttribute=="undefined")return f.prop(a,c,d);i=j!==1||!f.isXMLDoc(a),i&&(c=c.toLowerCase(),h=f.attrHooks[c]||(u.test(c)?x:w));if(d!==b){if(d===null){f.removeAttr(a,c);return}if(h&&"set"in h&&i&&(g=h.set(a,d,c))!==b)return g;a.setAttribute(c,""+d);return d}if(h&&"get"in h&&i&&(g=h.get(a,c))!==null)return g;g=a.getAttribute(c);return g===null?b:g}},removeAttr:function(a,b){var c,d,e,g,h,i=0;if(b&&a.nodeType===1){d=b.toLowerCase().split(p),g=d.length;for(;i=0}})});var z=/^(?:textarea|input|select)$/i,A=/^([^\.]*)?(?:\.(.+))?$/,B=/(?:^|\s)hover(\.\S+)?\b/,C=/^key/,D=/^(?:mouse|contextmenu)|click/,E=/^(?:focusinfocus|focusoutblur)$/,F=/^(\w*)(?:#([\w\-]+))?(?:\.([\w\-]+))?$/,G=function( a){var b=F.exec(a);b&&(b[1]=(b[1]||"").toLowerCase(),b[3]=b[3]&&new RegExp("(?:^|\\s)"+b[3]+"(?:\\s|$)"));return b},H=function(a,b){var c=a.attributes||{};return(!b[1]||a.nodeName.toLowerCase()===b[1])&&(!b[2]||(c.id||{}).value===b[2])&&(!b[3]||b[3].test((c["class"]||{}).value))},I=function(a){return f.event.special.hover?a:a.replace(B,"mouseenter$1 mouseleave$1")};f.event={add:function(a,c,d,e,g){var h,i,j,k,l,m,n,o,p,q,r,s;if(!(a.nodeType===3||a.nodeType===8||!c||!d||!(h=f._data(a)))){d.handler&&(p=d,d=p.handler,g=p.selector),d.guid||(d.guid=f.guid++),j=h.events,j||(h.events=j={}),i=h.handle,i||(h.handle=i=function(a){return typeof f!="undefined"&&(!a||f.event.triggered!==a.type)?f.event.dispatch.apply(i.elem,arguments):b},i.elem=a),c=f.trim(I(c)).split(" ");for(k=0;k=0&&(h=h.slice(0,-1),k=!0),h.indexOf(".")>=0&&(i=h.split("."),h=i.shift(),i.sort());if((!e||f.event.customEvent[h])&&!f.event.global[h])return;c=typeof c=="object"?c[f.expando]?c:new f.Event(h,c):new f.Event(h),c.type=h,c.isTrigger=!0,c.exclusive=k,c.namespace=i.join("."),c.namespace_re=c.namespace?new RegExp("(^|\\.)"+i.join("\\.(?:.*\\.)?")+"(\\.|$)"):null,o=h.indexOf(":")<0?"on"+h:"";if(!e){j=f.cache;for(l in j)j[l].events&&j[l].events[h]&&f.event.trigger(c,d,j[l].handle.elem,!0);return}c.result=b,c.target||(c.target=e),d=d!=null?f.makeArray(d):[],d.unshift(c),p=f.event.special[h]||{};if(p.trigger&&p.trigger.apply(e,d)===!1)return;r=[[e,p.bindType||h]];if(!g&&!p.noBubble&&!f.isWindow(e)){s=p.delegateType||h,m=E.test(s+h)?e:e.parentNode,n=null;for(;m;m=m.parentNode)r.push([m,s]),n=m;n&&n===e.ownerDocument&&r.push([n.defaultView||n.parentWindow||a,s])}for(l=0;le&&j.push({elem:this,matches:d.slice(e)});for(k=0;k0?this.on(b,null,a,c):this.trigger(b)},f.attrFn&&(f.attrFn[b]=!0),C.test(b)&&(f.event.fixHooks[b]=f.event.keyHooks),D.test(b)&&(f.event.fixHooks[b]=f.event.mouseHooks)}),function(){function x(a,b,c,e,f,g){for(var h=0,i=e.length;h0){k=j;break}}j=j[a]}e[h]=k}}}function w(a,b,c,e,f,g){for(var h=0,i=e.length;h+~,(\[\\]+)+|[>+~])(\s*,\s*)?((?:.|\r|\n)*)/g,d="sizcache"+(Math.random()+"").replace(".",""),e=0,g=Object.prototype.toString,h=!1,i=!0,j=/\\/g,k=/\r\n/g,l=/\W/;[0,0].sort(function(){i=!1;return 0});var m=function(b,d,e,f){e=e||[],d=d||c;var h=d;if(d.nodeType!==1&&d.nodeType!==9)return[];if(!b||typeof b!="string")return e;var i,j,k,l,n,q,r,t,u=!0,v=m.isXML(d),w=[],x=b;do{a.exec(""),i=a.exec(x);if(i){x=i[3],w.push(i[1]);if(i[2]){l=i[3];break}}}while(i);if(w.length>1&&p.exec(b))if(w.length===2&&o.relative[w[0]])j=y(w[0]+w[1],d,f);else{j=o.relative[w[0]]?[d]:m(w.shift(),d);while(w.length)b=w.shift(),o.relative[b]&&(b+=w.shift()),j=y(b,j,f)}else{!f&&w.length>1&&d.nodeType===9&&!v&&o.match.ID.test(w[0])&&!o.match.ID.test(w[w.length-1])&&(n=m.find(w.shift(),d,v),d=n.expr?m.filter(n.expr,n.set)[0]:n.set[0]);if(d){n=f?{expr:w.pop(),set:s(f)}:m.find(w.pop(),w.length===1&&(w[0]==="~"||w[0]==="+")&&d.parentNode?d.parentNode:d,v),j=n.expr?m.filter(n.expr,n.set):n.set,w.length>0?k=s(j):u=!1;while(w.length)q=w.pop(),r=q,o.relative[q]?r=w.pop():q="",r==null&&(r=d),o.relative[q](k,r,v)}else k=w=[]}k||(k=j),k||m.error(q||b);if(g.call(k)==="[object Array]")if(!u)e.push.apply(e,k);else if(d&&d.nodeType===1)for(t=0;k[t]!=null;t++)k[t]&&(k[t]===!0||k[t].nodeType===1&&m.contains(d,k[t]))&&e.push(j[t]);else for(t=0;k[t]!=null;t++)k[t]&&k[t].nodeType===1&&e.push(j[t]);else s(k,e);l&&(m(l,h,e,f),m.uniqueSort(e));return e};m.uniqueSort=function(a){if(u){h=i,a.sort(u);if(h)for(var b=1;b0},m.find=function(a,b,c){var d,e,f,g,h,i;if(!a)return[];for(e=0,f=o.order.length;e":function(a,b){var c,d=typeof b=="string",e=0,f=a.length;if(d&&!l.test(b)){b=b.toLowerCase();for(;e=0)?c||d.push(h):c&&(b[g]=!1));return!1},ID:function(a){return a[1].replace(j,"")},TAG:function(a,b){return a[1].replace(j,"").toLowerCase()},CHILD:function(a){if(a[1]==="nth"){a[2]||m.error(a[0]),a[2]=a[2].replace(/^\+|\s*/g,"");var b=/(-?)(\d*)(?:n([+\-]?\d*))?/.exec(a[2]==="even"&&"2n"||a[2]==="odd"&&"2n+1"||!/\D/.test(a[2])&&"0n+"+a[2]||a[2]);a[2]=b[1]+(b[2]||1)-0,a[3]=b[3]-0}else a[2]&&m.error(a[0]);a[0]=e++;return a},ATTR:function(a,b,c,d,e,f){var g=a[1]=a[1].replace(j,"");!f&&o.attrMap[g]&&(a[1]=o.attrMap[g]),a[4]=(a[4]||a[5]||"").replace(j,""),a[2]==="~="&&(a[4]=" "+a[4]+" ");return a},PSEUDO:function(b,c,d,e,f){if(b[1]==="not")if((a.exec(b[3])||"").length>1||/^\w/.test(b[3]))b[3]=m(b[3],null,null,c);else{var g=m.filter(b[3],c,d,!0^f);d||e.push.apply(e,g);return!1}else if(o.match.POS.test(b[0])||o.match.CHILD.test(b[0]))return!0;return b},POS:function(a){a.unshift(!0);return a}},filters:{enabled:function(a){return a.disabled===!1&&a.type!=="hidden"},disabled:function(a){return a.disabled===!0},checked:function(a){return a.checked===!0},selected:function(a){a.parentNode&&a.parentNode.selectedIndex;return a.selected===!0},parent:function(a){return!!a.firstChild},empty:function(a){return!a.firstChild},has:function(a,b,c){return!!m(c[3],a).length},header:function(a){return/h\d/i.test(a.nodeName)},text:function(a){var b=a.getAttribute("type"),c=a.type;return a.nodeName.toLowerCase()==="input"&&"text"===c&&(b===c||b===null)},radio:function(a){return a.nodeName.toLowerCase()==="input"&&"radio"===a.type},checkbox:function(a){return a.nodeName.toLowerCase()==="input"&&"checkbox"===a.type},file:function(a){return a.nodeName.toLowerCase()==="input"&&"file"===a.type},password:function(a){return a.nodeName.toLowerCase()==="input"&&"password"===a.type},submit:function(a){var b=a.nodeName.toLowerCase();return(b==="input"||b==="button")&&"submit"===a.type},image:function(a){return a.nodeName.toLowerCase()==="input"&&"image"===a.type},reset:function(a){var b=a.nodeName.toLowerCase();return(b==="input"||b==="button")&&"reset"===a.type},button:function(a){var b=a.nodeName.toLowerCase();return b==="input"&&"button"===a.type||b==="button"},input:function(a){return/input|select|textarea|button/i.test(a.nodeName)},focus:function(a){return a===a.ownerDocument.activeElement}},setFilters:{first:function(a,b){return b===0},last:function(a,b,c,d){return b===d.length-1},even:function(a,b){return b%2===0},odd:function(a,b){return b%2===1},lt:function(a,b,c){return bc[3]-0},nth:function(a,b,c){return c[3]-0===b},eq:function(a,b,c){return c[3]-0===b}},filter:{PSEUDO:function(a,b,c,d){var e=b[1],f=o.filters[e];if(f)return f(a,c,b,d);if(e==="contains")return(a.textContent||a.innerText||n([a])||"").indexOf(b[3])>=0;if(e==="not"){var g=b[3];for(var h=0,i=g.length;h=0}},ID:function(a,b){return a.nodeType===1&&a.getAttribute("id")===b},TAG:function(a,b){return b==="*"&&a.nodeType===1||!!a.nodeName&&a.nodeName.toLowerCase()===b},CLASS:function(a,b){return(" "+(a.className||a.getAttribute("class"))+" ").indexOf(b)>-1},ATTR:function(a,b){var c=b[1],d=m.attr?m.attr(a,c):o.attrHandle[c]?o.attrHandle[c](a):a[c]!=null?a[c]:a.getAttribute(c),e=d+"",f=b[2],g=b[4];return d==null?f==="!=":!f&&m.attr?d!=null:f==="="?e===g:f==="*="?e.indexOf(g)>=0:f==="~="?(" "+e+" ").indexOf(g)>=0:g?f==="!="?e!==g:f==="^="?e.indexOf(g)===0:f==="$="?e.substr(e.length-g.length)===g:f==="|="?e===g||e.substr(0,g.length+1)===g+"-":!1:e&&d!==!1},POS:function(a,b,c,d){var e=b[2],f=o.setFilters[e];if(f)return f(a,c,b,d)}}},p=o.match.POS,q=function(a,b){return"\\"+(b-0+1)};for(var r in o.match)o.match[r]=new RegExp(o.match[r].source+/(?![^\[]*\])(?![^\(]*\))/.source),o.leftMatch[r]=new RegExp(/(^(?:.|\r|\n)*?)/.source+o.match[r].source.replace(/\\(\d+)/g,q));o.match.globalPOS=p;var s=function(a,b){a=Array.prototype.slice.call(a,0);if(b){b.push.apply(b,a);return b}return a};try{Array.prototype.slice.call(c.documentElement.childNodes,0)[0].nodeType}catch(t){s=function(a,b){var c=0,d=b||[];if(g.call(a)==="[object Array]")Array.prototype.push.apply(d,a);else if(typeof a.length=="number")for(var e=a.length;c",e.insertBefore(a,e.firstChild),c.getElementById(d)&&(o.find.ID=function(a,c,d){if(typeof c.getElementById!="undefined"&&!d){var e=c.getElementById(a[1]);return e?e.id===a[1]||typeof e.getAttributeNode!="undefined"&&e.getAttributeNode("id").nodeValue===a[1]?[e]:b:[]}},o.filter.ID=function(a,b){var c=typeof a.getAttributeNode!="undefined"&&a.getAttributeNode("id");return a.nodeType===1&&c&&c.nodeValue===b}),e.removeChild(a),e=a=null}(),function(){var a=c.createElement("div");a.appendChild(c.createComment("")),a.getElementsByTagName("*").length>0&&(o.find.TAG=function(a,b){var c=b.getElementsByTagName(a[1]);if(a[1]==="*"){var d=[];for(var e=0;c[e];e++)c[e].nodeType===1&&d.push(c[e]);c=d}return c}),a.innerHTML="",a.firstChild&&typeof a.firstChild.getAttribute!="undefined"&&a.firstChild.getAttribute("href")!=="#"&&(o.attrHandle.href=function(a){return a.getAttribute("href",2)}),a=null}(),c.querySelectorAll&&function(){var a=m,b=c.createElement("div"),d="__sizzle__";b.innerHTML="

";if(!b.querySelectorAll||b.querySelectorAll(".TEST").length!==0){m=function(b,e,f,g){e=e||c;if(!g&&!m.isXML(e)){var h=/^(\w+$)|^\.([\w\-]+$)|^#([\w\-]+$)/.exec(b);if(h&&(e.nodeType===1||e.nodeType===9)){if(h[1])return s(e.getElementsByTagName(b),f);if(h[2]&&o.find.CLASS&&e.getElementsByClassName)return s(e.getElementsByClassName(h[2]),f)}if(e.nodeType===9){if(b==="body"&&e.body)return s([e.body],f);if(h&&h[3]){var i=e.getElementById(h[3]);if(!i||!i.parentNode)return s([],f);if(i.id===h[3])return s([i],f)}try{return s(e.querySelectorAll(b),f)}catch(j){}}else if(e.nodeType===1&&e.nodeName.toLowerCase()!=="object"){var k=e,l=e.getAttribute("id"),n=l||d,p=e.parentNode,q=/^\s*[+~]/.test(b);l?n=n.replace(/'/g,"\\$&"):e.setAttribute("id",n),q&&p&&(e=e.parentNode);try{if(!q||p)return s(e.querySelectorAll("[id='"+n+"'] "+b),f)}catch(r){}finally{l||k.removeAttribute("id")}}}return a(b,e,f,g)};for(var e in a)m[e]=a[e];b=null}}(),function(){var a=c.documentElement,b=a.matchesSelector||a.mozMatchesSelector||a.webkitMatchesSelector||a.msMatchesSelector;if(b){var d=!b.call(c.createElement("div"),"div"),e=!1;try{b.call(c.documentElement,"[test!='']:sizzle")}catch(f){e=!0}m.matchesSelector=function(a,c){c=c.replace(/\=\s*([^'"\]]*)\s*\]/g,"='$1']");if(!m.isXML(a))try{if(e||!o.match.PSEUDO.test(c)&&!/!=/.test(c)){var f=b.call(a,c);if(f||!d||a.document&&a.document.nodeType!==11)return f}}catch(g){}return m(c,null,null,[a]).length>0}}}(),function(){var a=c.createElement("div");a.innerHTML="
";if(!!a.getElementsByClassName&&a.getElementsByClassName("e").length!==0){a.lastChild.className="e";if(a.getElementsByClassName("e").length===1)return;o.order.splice(1,0,"CLASS"),o.find.CLASS=function(a,b,c){if(typeof b.getElementsByClassName!="undefined"&&!c)return b.getElementsByClassName(a[1])},a=null}}(),c.documentElement.contains?m.contains=function(a,b){return a!==b&&(a.contains?a.contains(b):!0)}:c.documentElement.compareDocumentPosition?m.contains=function(a,b){return!!(a.compareDocumentPosition(b)&16)}:m.contains=function(){return!1},m.isXML=function(a){var b=(a?a.ownerDocument||a:0).documentElement;return b?b.nodeName!=="HTML":!1};var y=function(a,b,c){var d,e=[],f="",g=b.nodeType?[b]:b;while(d=o.match.PSEUDO.exec(a))f+=d[0],a=a.replace(o.match.PSEUDO,"");a=o.relative[a]?a+"*":a;for(var h=0,i=g.length;h0)for(h=g;h=0:f.filter(a,this).length>0:this.filter(a).length>0)},closest:function(a,b){var c=[],d,e,g=this[0];if(f.isArray(a)){var h=1;while(g&&g.ownerDocument&&g!==b){for(d=0;d-1:f.find.matchesSelector(g,a)){c.push(g);break}g=g.parentNode;if(!g||!g.ownerDocument||g===b||g.nodeType===11)break}}c=c.length>1?f.unique(c):c;return this.pushStack(c,"closest",a)},index:function(a){if(!a)return this[0]&&this[0].parentNode?this.prevAll().length:-1;if(typeof a=="string")return f.inArray(this[0],f(a));return f.inArray(a.jquery?a[0]:a,this)},add:function(a,b){var c=typeof a=="string"?f(a,b):f.makeArray(a&&a.nodeType?[a]:a),d=f.merge(this.get(),c);return this.pushStack(S(c[0])||S(d[0])?d:f.unique(d))},andSelf:function(){return this.add(this.prevObject)}}),f.each({parent:function(a){var b=a.parentNode;return b&&b.nodeType!==11?b:null},parents:function(a){return f.dir(a,"parentNode")},parentsUntil:function(a,b,c){return f.dir(a,"parentNode",c)},next:function(a){return f.nth(a,2,"nextSibling")},prev:function(a){return f.nth(a,2,"previousSibling")},nextAll:function(a){return f.dir(a,"nextSibling")},prevAll:function(a){return f.dir(a,"previousSibling")},nextUntil:function(a,b,c){return f.dir(a,"nextSibling",c)},prevUntil:function(a,b,c){return f.dir(a,"previousSibling",c)},siblings:function(a){return f.sibling((a.parentNode||{}).firstChild,a)},children:function(a){return f.sibling(a.firstChild)},contents:function(a){return f.nodeName(a,"iframe")?a.contentDocument||a.contentWindow.document:f.makeArray(a.childNodes)}},function(a,b){f.fn[a]=function(c,d){var e=f.map(this,b,c);L.test(a)||(d=c),d&&typeof d=="string"&&(e=f.filter(d,e)),e=this.length>1&&!R[a]?f.unique(e):e,(this.length>1||N.test(d))&&M.test(a)&&(e=e.reverse());return this.pushStack(e,a,P.call(arguments).join(","))}}),f.extend({filter:function(a,b,c){c&&(a=":not("+a+")");return b.length===1?f.find.matchesSelector(b[0],a)?[b[0]]:[]:f.find.matches(a,b)},dir:function(a,c,d){var e=[],g=a[c];while(g&&g.nodeType!==9&&(d===b||g.nodeType!==1||!f(g).is(d)))g.nodeType===1&&e.push(g),g=g[c];return e},nth:function(a,b,c,d){b=b||1;var e=0;for(;a;a=a[c])if(a.nodeType===1&&++e===b)break;return a},sibling:function(a,b){var c=[];for(;a;a=a.nextSibling)a.nodeType===1&&a!==b&&c.push(a);return c}});var V="abbr|article|aside|audio|bdi|canvas|data|datalist|details|figcaption|figure|footer|header|hgroup|mark|meter|nav|output|progress|section|summary|time|video",W=/ jQuery\d+="(?:\d+|null)"/g,X=/^\s+/,Y=/<(?!area|br|col|embed|hr|img|input|link|meta|param)(([\w:]+)[^>]*)\/>/ig,Z=/<([\w:]+)/,$=/]","i"),bd=/checked\s*(?:[^=]|=\s*.checked.)/i,be=/\/(java|ecma)script/i,bf=/^\s*",""],legend:[1,"
","
"],thead:[1,"","
"],tr:[2,"","
"],td:[3,"","
"],col:[2,"","
"],area:[1,"",""],_default:[0,"",""]},bh=U(c);bg.optgroup=bg.option,bg.tbody=bg.tfoot=bg.colgroup=bg.caption=bg.thead,bg.th=bg.td,f.support.htmlSerialize||(bg._default=[1,"div
","
"]),f.fn.extend({text:function(a){return f.access(this,function(a){return a===b?f.text(this):this.empty().append((this[0]&&this[0].ownerDocument||c).createTextNode(a))},null,a,arguments.length)},wrapAll:function(a){if(f.isFunction(a))return this.each(function(b){f(this).wrapAll(a.call(this,b))});if(this[0]){var b=f(a,this[0].ownerDocument).eq(0).clone(!0);this[0].parentNode&&b.insertBefore(this[0]),b.map(function(){var a=this;while(a.firstChild&&a.firstChild.nodeType===1)a=a.firstChild;return a}).append(this)}return this},wrapInner:function(a){if(f.isFunction(a))return this.each(function(b){f(this).wrapInner(a.call(this,b))});return this.each(function(){var b=f(this),c=b.contents();c.length?c.wrapAll(a):b.append(a)})},wrap:function(a){var b=f.isFunction(a);return this.each(function(c){f(this).wrapAll(b?a.call(this,c):a)})},unwrap:function(){return this.parent().each(function(){f.nodeName(this,"body")||f(this).replaceWith(this.childNodes)}).end()},append:function(){return this.domManip(arguments,!0,function(a){this.nodeType===1&&this.appendChild(a)})},prepend:function(){return this.domManip(arguments,!0,function(a){this.nodeType===1&&this.insertBefore(a,this.firstChild)})},before:function(){if(this[0]&&this[0].parentNode)return this.domManip(arguments,!1,function(a){this.parentNode.insertBefore(a,this)});if(arguments.length){var a=f .clean(arguments);a.push.apply(a,this.toArray());return this.pushStack(a,"before",arguments)}},after:function(){if(this[0]&&this[0].parentNode)return this.domManip(arguments,!1,function(a){this.parentNode.insertBefore(a,this.nextSibling)});if(arguments.length){var a=this.pushStack(this,"after",arguments);a.push.apply(a,f.clean(arguments));return a}},remove:function(a,b){for(var c=0,d;(d=this[c])!=null;c++)if(!a||f.filter(a,[d]).length)!b&&d.nodeType===1&&(f.cleanData(d.getElementsByTagName("*")),f.cleanData([d])),d.parentNode&&d.parentNode.removeChild(d);return this},empty:function(){for(var a=0,b;(b=this[a])!=null;a++){b.nodeType===1&&f.cleanData(b.getElementsByTagName("*"));while(b.firstChild)b.removeChild(b.firstChild)}return this},clone:function(a,b){a=a==null?!1:a,b=b==null?a:b;return this.map(function(){return f.clone(this,a,b)})},html:function(a){return f.access(this,function(a){var c=this[0]||{},d=0,e=this.length;if(a===b)return c.nodeType===1?c.innerHTML.replace(W,""):null;if(typeof a=="string"&&!ba.test(a)&&(f.support.leadingWhitespace||!X.test(a))&&!bg[(Z.exec(a)||["",""])[1].toLowerCase()]){a=a.replace(Y,"<$1>");try{for(;d1&&l0?this.clone(!0):this).get();f(e[h])[b](j),d=d.concat(j)}return this.pushStack(d,a,e.selector)}}),f.extend({clone:function(a,b,c){var d,e,g,h=f.support.html5Clone||f.isXMLDoc(a)||!bc.test("<"+a.nodeName+">")?a.cloneNode(!0):bo(a);if((!f.support.noCloneEvent||!f.support.noCloneChecked)&&(a.nodeType===1||a.nodeType===11)&&!f.isXMLDoc(a)){bk(a,h),d=bl(a),e=bl(h);for(g=0;d[g];++g)e[g]&&bk(d[g],e[g])}if(b){bj(a,h);if(c){d=bl(a),e=bl(h);for(g=0;d[g];++g)bj(d[g],e[g])}}d=e=null;return h},clean:function(a,b,d,e){var g,h,i,j=[];b=b||c,typeof b.createElement=="undefined"&&(b=b.ownerDocument||b[0]&&b[0].ownerDocument||c);for(var k=0,l;(l=a[k])!=null;k++){typeof l=="number"&&(l+="");if(!l)continue;if(typeof l=="string")if(!_.test(l))l=b.createTextNode(l);else{l=l.replace(Y,"<$1>");var m=(Z.exec(l)||["",""])[1].toLowerCase(),n=bg[m]||bg._default,o=n[0],p=b.createElement("div"),q=bh.childNodes,r;b===c?bh.appendChild(p):U(b).appendChild(p),p.innerHTML=n[1]+l+n[2];while(o--)p=p.lastChild;if(!f.support.tbody){var s=$.test(l),t=m==="table"&&!s?p.firstChild&&p.firstChild.childNodes:n[1]===""&&!s?p.childNodes:[];for(i=t.length-1;i>=0;--i)f.nodeName(t[i],"tbody")&&!t[i].childNodes.length&&t[i].parentNode.removeChild(t[i])}!f.support.leadingWhitespace&&X.test(l)&&p.insertBefore(b.createTextNode(X.exec(l)[0]),p.firstChild),l=p.childNodes,p&&(p.parentNode.removeChild(p),q.length>0&&(r=q[q.length-1],r&&r.parentNode&&r.parentNode.removeChild(r)))}var u;if(!f.support.appendChecked)if(l[0]&&typeof (u=l.length)=="number")for(i=0;i1)},f.extend({cssHooks:{opacity:{get:function(a,b){if(b){var c=by(a,"opacity");return c===""?"1":c}return a.style.opacity}}},cssNumber:{fillOpacity:!0,fontWeight:!0,lineHeight:!0,opacity:!0,orphans:!0,widows:!0,zIndex:!0,zoom:!0},cssProps:{"float":f.support.cssFloat?"cssFloat":"styleFloat"},style:function(a,c,d,e){if(!!a&&a.nodeType!==3&&a.nodeType!==8&&!!a.style){var g,h,i=f.camelCase(c),j=a.style,k=f.cssHooks[i];c=f.cssProps[i]||i;if(d===b){if(k&&"get"in k&&(g=k.get(a,!1,e))!==b)return g;return j[c]}h=typeof d,h==="string"&&(g=bu.exec(d))&&(d=+(g[1]+1)*+g[2]+parseFloat(f.css(a,c)),h="number");if(d==null||h==="number"&&isNaN(d))return;h==="number"&&!f.cssNumber[i]&&(d+="px");if(!k||!("set"in k)||(d=k.set(a,d))!==b)try{j[c]=d}catch(l){}}},css:function(a,c,d){var e,g;c=f.camelCase(c),g=f.cssHooks[c],c=f.cssProps[c]||c,c==="cssFloat"&&(c="float");if(g&&"get"in g&&(e=g.get(a,!0,d))!==b)return e;if(by)return by(a,c)},swap:function(a,b,c){var d={},e,f;for(f in b)d[f]=a.style[f],a.style[f]=b[f];e=c.call(a);for(f in b)a.style[f]=d[f];return e}}),f.curCSS=f.css,c.defaultView&&c.defaultView.getComputedStyle&&(bz=function(a,b){var c,d,e,g,h=a.style;b=b.replace(br,"-$1").toLowerCase(),(d=a.ownerDocument.defaultView)&&(e=d.getComputedStyle(a,null))&&(c=e.getPropertyValue(b),c===""&&!f.contains(a.ownerDocument.documentElement,a)&&(c=f.style(a,b))),!f.support.pixelMargin&&e&&bv.test(b)&&bt.test(c)&&(g=h.width,h.width=c,c=e.width,h.width=g);return c}),c.documentElement.currentStyle&&(bA=function(a,b){var c,d,e,f=a.currentStyle&&a.currentStyle[b],g=a.style;f==null&&g&&(e=g[b])&&(f=e),bt.test(f)&&(c=g.left,d=a.runtimeStyle&&a.runtimeStyle.left,d&&(a.runtimeStyle.left=a.currentStyle.left),g.left=b==="fontSize"?"1em":f,f=g.pixelLeft+"px",g.left=c,d&&(a.runtimeStyle.left=d));return f===""?"auto":f}),by=bz||bA,f.each(["height","width"],function(a,b){f.cssHooks[b]={get:function(a,c,d){if(c)return a.offsetWidth!==0?bB(a,b,d):f.swap(a,bw,function(){return bB(a,b,d)})},set:function(a,b){return bs.test(b)?b+"px":b}}}),f.support.opacity||(f.cssHooks.opacity={get:function(a,b){return bq.test((b&&a.currentStyle?a.currentStyle.filter:a.style.filter)||"")?parseFloat(RegExp.$1)/100+"":b?"1":""},set:function(a,b){var c=a.style,d=a.currentStyle,e=f.isNumeric(b)?"alpha(opacity="+b*100+")":"",g=d&&d.filter||c.filter||"";c.zoom=1;if(b>=1&&f.trim(g.replace(bp,""))===""){c.removeAttribute("filter");if(d&&!d.filter)return}c.filter=bp.test(g)?g.replace(bp,e):g+" "+e}}),f(function(){f.support.reliableMarginRight||(f.cssHooks.marginRight={get:function(a,b){return f.swap(a,{display:"inline-block"},function(){return b?by(a,"margin-right"):a.style.marginRight})}})}),f.expr&&f.expr.filters&&(f.expr.filters.hidden=function(a){var b=a.offsetWidth,c=a.offsetHeight;return b===0&&c===0||!f.support.reliableHiddenOffsets&&(a.style&&a.style.display||f.css(a,"display"))==="none"},f.expr.filters.visible=function(a){return!f.expr.filters.hidden(a)}),f.each({margin:"",padding:"",border:"Width"},function(a,b){f.cssHooks[a+b]={expand:function(c){var d,e=typeof c=="string"?c.split(" "):[c],f={};for(d=0;d<4;d++)f[a+bx[d]+b]=e[d]||e[d-2]||e[0];return f}}});var bC=/%20/g,bD=/\[\]$/,bE=/\r?\n/g,bF=/#.*$/,bG=/^(.*?):[ \t]*([^\r\n]*)\r?$/mg,bH=/^(?:color|date|datetime|datetime-local|email|hidden|month|number|password|range|search|tel|text|time|url|week)$/i,bI=/^(?:about|app|app\-storage|.+\-extension|file|res|widget):$/,bJ=/^(?:GET|HEAD)$/,bK=/^\/\//,bL=/\?/,bM=/)<[^<]*)*<\/script>/gi,bN=/^(?:select|textarea)/i,bO=/\s+/,bP=/([?&])_=[^&]*/,bQ=/^([\w\+\.\-]+:)(?:\/\/([^\/?#:]*)(?::(\d+))?)?/,bR=f.fn.load,bS={},bT={},bU,bV,bW=["*/"]+["*"];try{bU=e.href}catch(bX){bU=c.createElement("a"),bU.href="",bU=bU.href}bV=bQ.exec(bU.toLowerCase())||[],f.fn.extend({load:function(a,c,d){if(typeof a!="string"&&bR)return bR.apply(this,arguments);if(!this.length)return this;var e=a.indexOf(" ");if(e>=0){var g=a.slice(e,a.length);a=a.slice(0,e)}var h="GET";c&&(f.isFunction(c)?(d=c,c=b):typeof c=="object"&&(c=f.param(c,f.ajaxSettings.traditional),h="POST"));var i=this;f.ajax({url:a,type:h,dataType:"html",data:c,complete:function(a,b,c){c=a.responseText,a.isResolved()&&(a.done(function(a){c=a}),i.html(g?f("
").append(c.replace(bM,"")).find(g):c)),d&&i.each(d,[c,b,a])}});return this},serialize:function(){return f.param(this.serializeArray())},serializeArray:function(){return this.map(function(){return this.elements?f.makeArray(this.elements):this}).filter(function(){return this.name&&!this.disabled&&(this.checked||bN.test(this.nodeName)||bH.test(this.type))}).map(function(a,b){var c=f(this).val();return c==null?null:f.isArray(c)?f.map(c,function(a,c){return{name:b.name,value:a.replace(bE,"\r\n")}}):{name:b.name,value:c.replace(bE,"\r\n")}}).get()}}),f.each("ajaxStart ajaxStop ajaxComplete ajaxError ajaxSuccess ajaxSend".split(" "),function(a,b){f.fn[b]=function(a){return this.on(b,a)}}),f.each(["get","post"],function(a,c){f[c]=function(a,d,e,g){f.isFunction(d)&&(g=g||e,e=d,d=b);return f.ajax({type:c,url:a,data:d,success:e,dataType:g})}}),f.extend({getScript:function(a,c){return f.get(a,b,c,"script")},getJSON:function(a,b,c){return f.get(a,b,c,"json")},ajaxSetup:function(a,b){b?b$(a,f.ajaxSettings):(b=a,a=f.ajaxSettings),b$(a,b);return a},ajaxSettings:{url:bU,isLocal:bI.test(bV[1]),global:!0,type:"GET",contentType:"application/x-www-form-urlencoded; charset=UTF-8",processData:!0,async:!0,accepts:{xml:"application/xml, text/xml",html:"text/html",text:"text/plain",json:"application/json, text/javascript","*":bW},contents:{xml:/xml/,html:/html/,json:/json/},responseFields:{xml:"responseXML",text:"responseText"},converters:{"* text":a.String,"text html":!0,"text json":f.parseJSON,"text xml":f.parseXML},flatOptions:{context:!0,url:!0}},ajaxPrefilter:bY(bS),ajaxTransport:bY(bT),ajax:function(a,c){function w(a,c,l,m){if(s!==2){s=2,q&&clearTimeout(q),p=b,n=m||"",v.readyState=a>0?4:0;var o,r,u,w=c,x=l?ca(d,v,l):b,y,z;if(a>=200&&a<300||a===304){if(d.ifModified){if(y=v.getResponseHeader("Last-Modified"))f.lastModified[k]=y;if(z=v.getResponseHeader("Etag"))f.etag[k]=z}if(a===304)w="notmodified",o=!0;else try{r=cb(d,x),w="success",o=!0}catch(A){w="parsererror",u=A}}else{u=w;if(!w||a)w="error",a<0&&(a=0)}v.status=a,v.statusText=""+(c||w),o?h.resolveWith(e,[r,w,v]):h.rejectWith(e,[v,w,u]),v.statusCode(j),j=b,t&&g.trigger("ajax"+(o?"Success":"Error"),[v,d,o?r:u]),i.fireWith(e,[v,w]),t&&(g.trigger("ajaxComplete",[v,d]),--f.active||f.event.trigger("ajaxStop"))}}typeof a=="object"&&(c=a,a=b),c=c||{};var d=f.ajaxSetup({},c),e=d.context||d,g=e!==d&&(e.nodeType||e instanceof f)?f(e):f.event,h=f.Deferred(),i=f.Callbacks("once memory"),j=d.statusCode||{},k,l={},m={},n,o,p,q,r,s=0,t,u,v={readyState:0,setRequestHeader:function(a,b){if(!s){var c=a.toLowerCase();a=m[c]=m[c]||a,l[a]=b}return this},getAllResponseHeaders:function(){return s===2?n:null},getResponseHeader:function(a){var c;if(s===2){if(!o){o={};while(c=bG.exec(n))o[c[1].toLowerCase()]=c[2]}c=o[a.toLowerCase()]}return c===b?null:c},overrideMimeType:function(a){s||(d.mimeType=a);return this},abort:function(a){a=a||"abort",p&&p.abort(a),w(0,a);return this}};h.promise(v),v.success=v.done,v.error=v.fail,v.complete=i.add,v.statusCode=function(a){if(a){var b;if(s<2)for(b in a)j[b]=[j[b],a[b]];else b=a[v.status],v.then(b,b)}return this},d.url=((a||d.url)+"").replace(bF,"").replace(bK,bV[1]+"//"),d.dataTypes=f.trim(d.dataType||"*").toLowerCase().split(bO),d.crossDomain==null&&(r=bQ.exec(d.url.toLowerCase()),d.crossDomain=!(!r||r[1]==bV[1]&&r[2]==bV[2]&&(r[3]||(r[1]==="http:"?80:443))==(bV[3]||(bV[1]==="http:"?80:443)))),d.data&&d.processData&&typeof d.data!="string"&&(d.data=f.param(d.data,d.traditional)),bZ(bS,d,c,v);if(s===2)return!1;t=d.global,d.type=d.type.toUpperCase(),d.hasContent=!bJ.test(d.type),t&&f.active++===0&&f.event.trigger("ajaxStart");if(!d.hasContent){d.data&&(d.url+=(bL.test(d.url)?"&":"?")+d.data,delete d.data),k=d.url;if(d.cache===!1){var x=f.now(),y=d.url.replace(bP,"$1_="+x);d.url=y+(y===d.url?(bL.test(d.url)?"&":"?")+"_="+x:"")}}(d.data&&d.hasContent&&d.contentType!==!1||c.contentType)&&v.setRequestHeader("Content-Type",d.contentType),d.ifModified&&(k=k||d.url,f.lastModified[k]&&v.setRequestHeader("If-Modified-Since",f.lastModified[k]),f.etag[k]&&v.setRequestHeader("If-None-Match",f.etag[k])),v.setRequestHeader("Accept",d.dataTypes[0]&&d.accepts[d.dataTypes[0]]?d.accepts[d.dataTypes[0]]+(d.dataTypes[0]!=="*"?", "+bW+"; q=0.01":""):d.accepts["*"]);for(u in d.headers)v.setRequestHeader(u,d.headers[u]);if(d.beforeSend&&(d.beforeSend.call(e,v,d)===!1||s===2)){v.abort();return!1}for(u in{success:1,error:1,complete:1})v[u](d[u]);p=bZ(bT,d,c,v);if(!p)w(-1,"No Transport");else{v.readyState=1,t&&g.trigger("ajaxSend",[v,d]),d.async&&d.timeout>0&&(q=setTimeout(function(){v.abort("timeout")},d.timeout));try{s=1,p.send(l,w)}catch(z){if(s<2)w(-1,z);else throw z}}return v},param:function(a,c){var d=[],e=function(a,b){b=f.isFunction(b)?b():b,d[d.length]=encodeURIComponent(a)+"="+encodeURIComponent(b)};c===b&&(c=f.ajaxSettings.traditional);if(f.isArray(a)||a.jquery&&!f.isPlainObject(a))f.each(a,function(){e(this.name,this.value)});else for(var g in a)b_(g,a[g],c,e);return d.join("&").replace(bC,"+")}}),f.extend({active:0,lastModified:{},etag:{}});var cc=f.now(),cd=/(\=)\?(&|$)|\?\?/i;f.ajaxSetup({jsonp:"callback",jsonpCallback:function(){return f.expando+"_"+cc++}}),f.ajaxPrefilter("json jsonp",function(b,c,d){var e=typeof b.data=="string"&&/^application\/x\-www\-form\-urlencoded/.test(b.contentType);if(b.dataTypes[0]==="jsonp"||b.jsonp!==!1&&(cd.test(b.url)||e&&cd.test(b.data))){var g,h=b.jsonpCallback=f.isFunction(b.jsonpCallback)?b.jsonpCallback():b.jsonpCallback,i=a[h],j=b.url,k=b.data,l="$1"+h+"$2";b.jsonp!==!1&&(j=j.replace(cd,l),b.url===j&&(e&&(k=k.replace(cd,l)),b.data===k&&(j+=(/\?/.test(j)?"&":"?")+b.jsonp+"="+h))),b.url=j,b.data=k,a[h]=function(a){g=[a]},d.always(function(){a[h]=i,g&&f.isFunction(i)&&a[h](g[0])}),b.converters["script json"]=function(){g||f.error(h+" was not called");return g[0]},b.dataTypes[0]="json";return"script"}}),f.ajaxSetup({accepts:{script:"text/javascript, application/javascript, application/ecmascript, application/x-ecmascript"},contents:{script:/javascript|ecmascript/},converters:{"text script":function(a){f.globalEval(a);return a}}}),f.ajaxPrefilter("script",function(a){a.cache===b&&(a.cache=!1),a.crossDomain&&(a.type="GET",a.global=!1)}),f.ajaxTransport("script",function(a){if(a.crossDomain){var d,e=c.head||c.getElementsByTagName("head")[0]||c.documentElement;return{send:function(f,g){d=c.createElement("script"),d.async="async",a.scriptCharset&&(d.charset=a.scriptCharset),d.src=a.url,d.onload=d.onreadystatechange=function(a,c){if(c||!d.readyState||/loaded|complete/.test(d.readyState))d.onload=d.onreadystatechange=null,e&&d.parentNode&&e.removeChild(d),d=b,c||g(200,"success")},e.insertBefore(d,e.firstChild)},abort:function(){d&&d.onload(0,1)}}}});var ce=a.ActiveXObject?function(){for(var a in cg)cg[a](0,1)}:!1,cf=0,cg;f.ajaxSettings.xhr=a.ActiveXObject?function(){return!this.isLocal&&ch()||ci()}:ch,function(a){f.extend(f.support,{ajax:!!a,cors:!!a&&"withCredentials"in a})}(f.ajaxSettings.xhr()),f.support.ajax&&f.ajaxTransport(function(c){if(!c.crossDomain||f.support.cors){var d;return{send:function(e,g){var h=c.xhr(),i,j;c.username?h.open(c.type,c.url,c.async,c.username,c.password):h.open(c.type,c.url,c.async);if(c.xhrFields)for(j in c.xhrFields)h[j]=c.xhrFields[j];c.mimeType&&h.overrideMimeType&&h.overrideMimeType(c.mimeType),!c.crossDomain&&!e["X-Requested-With"]&&(e["X-Requested-With"]="XMLHttpRequest");try{for(j in e)h.setRequestHeader(j,e[j])}catch(k){}h.send(c.hasContent&&c.data||null),d=function(a,e){var j,k,l,m,n;try{if(d&&(e||h.readyState===4)){d=b,i&&(h.onreadystatechange=f.noop,ce&&delete cg[i]);if(e)h.readyState!==4&&h.abort();else{j=h.status,l=h.getAllResponseHeaders(),m={},n=h.responseXML,n&&n.documentElement&&(m.xml=n);try{m.text=h.responseText}catch(a){}try{k=h.statusText}catch(o){k=""}!j&&c.isLocal&&!c.crossDomain?j=m.text?200:404:j===1223&&(j=204)}}}catch(p){e||g(-1,p)}m&&g(j,k,m,l)},!c.async||h.readyState===4?d():(i=++cf,ce&&(cg||(cg={},f(a).unload(ce)),cg[i]=d),h.onreadystatechange=d)},abort:function(){d&&d(0,1)}}}});var cj={},ck,cl,cm=/^(?:toggle|show|hide)$/,cn=/^([+\-]=)?([\d+.\-]+)([a-z%]*)$/i,co,cp=[["height","marginTop","marginBottom","paddingTop","paddingBottom"],["width","marginLeft","marginRight","paddingLeft","paddingRight"],["opacity"]],cq;f.fn.extend({show:function(a,b,c){var d,e;if(a||a===0)return this.animate(ct("show",3),a,b,c);for(var g=0,h=this.length;g=i.duration+this.startTime){this.now=this.end,this.pos=this.state=1,this.update(),i.animatedProperties[this.prop]=!0;for(b in i.animatedProperties)i.animatedProperties[b]!==!0&&(g=!1);if(g){i.overflow!=null&&!f.support.shrinkWrapBlocks&&f.each(["","X","Y"],function(a,b){h.style["overflow"+b]=i.overflow[a]}),i.hide&&f(h).hide();if(i.hide||i.show)for(b in i.animatedProperties)f.style(h,b,i.orig[b]),f.removeData(h,"fxshow"+b,!0),f.removeData(h,"toggle"+b,!0);d=i.complete,d&&(i.complete=!1,d.call(h))}return!1}i.duration==Infinity?this.now=e:(c=e-this.startTime,this.state=c/i.duration,this.pos=f.easing[i.animatedProperties[this.prop]](this.state,c,0,1,i.duration),this.now=this.start+(this.end-this.start)*this.pos),this.update();return!0}},f.extend(f.fx,{tick:function(){var a,b=f.timers,c=0;for(;c-1,k={},l={},m,n;j?(l=e.position(),m=l.top,n=l.left):(m=parseFloat(h)||0,n=parseFloat(i)||0),f.isFunction(b)&&(b=b.call(a,c,g)),b.top!=null&&(k.top=b.top-g.top+m),b.left!=null&&(k.left=b.left-g.left+n),"using"in b?b.using.call(a,k):e.css(k)}},f.fn.extend({position:function(){if(!this[0])return null;var a=this[0],b=this.offsetParent(),c=this.offset(),d=cx.test(b[0].nodeName)?{top:0,left:0}:b.offset();c.top-=parseFloat(f.css(a,"marginTop"))||0,c.left-=parseFloat(f.css(a,"marginLeft"))||0,d.top+=parseFloat(f.css(b[0],"borderTopWidth"))||0,d.left+=parseFloat(f.css(b[0],"borderLeftWidth"))||0;return{top:c.top-d.top,left:c.left-d.left}},offsetParent:function(){return this.map(function(){var a=this.offsetParent||c.body;while(a&&!cx.test(a.nodeName)&&f.css(a,"position")==="static")a=a.offsetParent;return a})}}),f.each({scrollLeft:"pageXOffset",scrollTop:"pageYOffset"},function(a,c){var d=/Y/.test(c);f.fn[a]=function(e){return f.access(this,function(a,e,g){var h=cy(a);if(g===b)return h?c in h?h[c]:f.support.boxModel&&h.document.documentElement[e]||h.document.body[e]:a[e];h?h.scrollTo(d?f(h).scrollLeft():g,d?g:f(h).scrollTop()):a[e]=g},a,e,arguments.length,null)}}),f.each({Height:"height",Width:"width"},function(a,c){var d="client"+a,e="scroll"+a,g="offset"+a;f.fn["inner"+a]=function(){var a=this[0];return a?a.style?parseFloat(f.css(a,c,"padding")):this[c]():null},f.fn["outer"+a]=function(a){var b=this[0];return b?b.style?parseFloat(f.css(b,c,a?"margin":"border")):this[c]():null},f.fn[c]=function(a){return f.access(this,function(a,c,h){var i,j,k,l;if(f.isWindow(a)){i=a.document,j=i.documentElement[d];return f.support.boxModel&&j||i.body&&i.body[d]||j}if(a.nodeType===9){i=a.documentElement;if(i[d]>=i[e])return i[d];return Math.max(a.body[e],i[e],a.body[g],i[g])}if(h===b){k=f.css(a,c),l=parseFloat(k);return f.isNumeric(l)?l:k}f(a).css(c,h)},c,a,arguments.length,null)}}),a.jQuery=a.$=f,typeof define=="function"&&define.amd&&define.amd.jQuery&&define("jquery",[],function(){return f})})(window);