若快自动识别验证码, 文档见: http://wiki.ruokuai.com/
435645
def ruokuai_captcha_handler(self, params, image_url):
        

        headers = {
            'Connection': 'Keep-Alive',
            'Expect': '100-continue',
            'User-Agent': 'ben',
        }
        image_data = requests.get(image_url).content
        files = {'image': ('check_code.png', image_data)}
        r = requests.post(
            'http://api.ruokuai.com/create.json',
            data=params,
            files=files,
            headers=headers
        )
        verify_code_dict = r.json()
        if verify_code_dict:
            if 'Error' in verify_code_dict.keys():
                print (verify_code_dict['Error'])
                return ''
            verify_code = verify_code_dict.get('Result', '')
        else:
            print ('rk failed ', verify_code_dict)
            return ''

        return verify_code
622315
private function createSearchData()
    {
        $search_data = [];
        $files = $this->files;
        // 单页文件不解析
        foreach ($files as $key => $file) {
            if (in_array($file['page_uuid'], $this->single_pages)) {
                unset($files[$key]);
                continue;
            }
            $full_content = $this->fileSys->getContent($file['file_path'])['content'];
            // $desc_content = mb_substr($full_content, 0, 1000, 'utf-8');
            // $file['description'] = $this->markd2html->makeHtml( $desc_content );
            $search_data[] = [
                'title' => $file['title'],
                'href' => $file['href'],
                'date' => $file['date'],
                'tags' => implode(',', $file['tags']),
                'type' => implode(',', $file['type']),
                // 'desc' => $file['description'],
            ];
        }
        $file_path = $this->public_dir . DIRECTORY_SEPARATOR . 'articles/data.json';
        $html = json_encode($search_data, JSON_UNESCAPED_UNICODE);
        $this->fileSys->create($file_path, $html);
    }
1295003
public static function getModuleRoute() {
        //获取请求URL
        $requestUrlArr = self::getRouteArray();

        //处理请求URL
        if (count($requestUrlArr) == 1) {//dev.example.com/aaa
            $data = array(array(
                    'module' => $requestUrlArr[0],
                    'act' => 'index',
                    'op' => 'actionIndex',
                    'namespace' => ''
            ));
        } elseif (count($requestUrlArr) == 2) {//dev.example.com/aaa/bbb
            $data = array(array(
                    'module' => $requestUrlArr[0],
                    'act' => $requestUrlArr[1],
                    'op' => 'actionIndex',
                    'namespace' => ''
            ));
        } elseif (count($requestUrlArr) == 3) {//dev.example.com/aaa/bbb
            $data = array(array(
                    'module' => $requestUrlArr[0],
                    'act' => $requestUrlArr[1],
                    'op' => 'action' . ucfirst($requestUrlArr[2]),
                    'namespace' => ''
                ),
                array(
                    'module' => $requestUrlArr[0],
                    'act' => $requestUrlArr[2],
                    'op' => 'actionIndex',
                    'namespace' => $requestUrlArr[1]
            ));
        } elseif (count($requestUrlArr) >= 4) {//dev.example.com/aaa/bbb/ccc //dev.example.com/aaa/bbb/ccc/index
            $module = array_shift($requestUrlArr); //第一个元素即为module名字
            $origRequestUrlArr = $requestUrlArr;
            $lastParam = array_pop($requestUrlArr);

            if ($lastParam == 'index') {
                $data = array(array(
                        'module' => $module,
                        'act' => array_pop($requestUrlArr),
                        'op' => 'actionIndex',
                        'namespace' => implode('/', $requestUrlArr)
                ));
            } else {
                $data = array(
                    array(
                        'module' => $module,
                        'act' => array_pop($origRequestUrlArr),
                        'op' => 'actionIndex',
                        'namespace' => implode('/', $origRequestUrlArr),
                    ),
                    array(
                        'module' => $module,
                        'act' => array_pop($requestUrlArr),
                        'op' => 'action' . ucfirst($lastParam),
                        'namespace' => implode('/', $requestUrlArr),
                    )
                );
            }
        }

        return $data;
    }
848469
function(){
		/* URLの種類からURLを取得する */
		var domain = (!pzpr.env.node ? document.domain : ''), url = "", pid = this.pid;
		if(!!domain){ domain += location.pathname;}
		else{ domain = "pzv.jp/p.html";}
		switch(this.type){
			case URL_PZPRV3:  url="http://"+domain+"?%PID%/"; break;
			case URL_KANPEN:  url="http://www.kanpen.net/%KID%.html?problem="; break;
			case URL_KANPENP: url="http://www.kanpen.net/%KID%.html?pzpr="; break;
			case URL_HEYAAPP: url="http://www.geocities.co.jp/heyawake/?problem="; break;
		}

		return url.replace("%PID%", pzpr.variety(pid).urlid)
				  .replace("%KID%", pzpr.variety(pid).kanpenid);
	}
848026
function UserPermissions() {
	//使用者帳號(索引用)
	this.strAccount = "";
	//控制錄影權限
	this.bVideo = false;
	//操作回放權限
	this.bPlayback = false;
	//設備位移縮放
	this.bMoveScale = false;
	//設定設備名稱
	this.bSetDevice = false;
	//警報事件處理
	this.bAlertEvent = false;
	//下載備份權限
	this.bBackup = false;
	//拍照畫面權限
	this.bPhotograph = false;
	//軟體更新權限
	this.bUpdate = false;
	//登入權限
	this.bLogin = true;
}
1167047
function makeDirs(plan, dest, savedir, callback) {

  // フォルダパスのリストを作成
  let all = plan.map(file => {
    let dirname = path.dirname(path.join(savedir, dest, file)); //ファイル名を除外
    return pathcrumb(dirname);
  });

  // 配列をフラットにして重複分を排除
  let uniq = _.uniq(_.flatten(all));

  // フォルダを作成
  let shell = path.join(__dirname, '../sh/makedirs.sh');
  return exec('chmod +x ' + shell, (error, stdout, stderr) => {
    return execFile(shell, uniq, (error, stdout, stderr) => {
      if (error !== null) throw ('[Error: makeDirs makedis.sh:] ' + error);
    }).on('close', callback);
  });
}
17331
public function help()
    {
        //获取显示模板
        $tpl = \Grace\Base\Help::getplframe();

        //oblist
        $objectList = $this->objectList();

        $chr = $title = $_GET['chr'];

        //计算左侧菜单
        //<li  class="active"><a href="/index.php?book=01-grace&lm=controller&ar=controller.md"> Controller </a></li>
        $nav = '';
        foreach ($objectList as $key => $value) {
            if ($key == $chr) {
                $nav .= "<li  class=\"active\"><a href=\"?chr=$key\"> $key </a></li>";
            } else {
                $nav .= "<li><a href=\"?chr=$key\"> $key </a></li>";
            }
        }

        $nr = '';
        if ($objectList[$chr]) {
            //获取内容
            $file = $objectList[$chr];
            $nr = (new \Parsedown())->text(file_get_contents(__DIR__ . '/' . $file));

        } else {
            $nr = '';
        }

        $html = str_replace('##nav##', $nav, $tpl);
        $html = str_replace('##nr##', $nr, $html);
        $html = str_replace('##title##', $title, $html);
        echo $html;
        exit;
    }
35706
public static function detectUri()
    {
        // 如果PATH_INFO读不到，那么就从其他途径读
        if ( ! $uri = Arr::get($_SERVER, 'PATH_INFO'))
        {
            // REQUEST_URI和PHP_SELF会包含当前脚本路径
            if (isset($_SERVER['REQUEST_URI']))
            {
                $uri = $_SERVER['REQUEST_URI'];
                if ($requestUri = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH))
                {
                    $uri = $requestUri;
                }
                $uri = rawurldecode($uri);
            }
            elseif (isset($_SERVER['PHP_SELF']))
            {
                $uri = $_SERVER['PHP_SELF'];
            }
            elseif (isset($_SERVER['REDIRECT_URL']))
            {
                $uri = $_SERVER['REDIRECT_URL'];
            }
            else
            {
                throw new HelperException('Unable to detect the URI using PATH_INFO, REQUEST_URI, PHP_SELF or REDIRECT_URL');
            }

            $baseUrl = parse_url(Base::$baseUrl, PHP_URL_PATH);
            if (strpos($uri, $baseUrl) === 0)
            {
                $uri = (string) substr($uri, strlen($baseUrl));
            }
            if (Base::$indexFile && strpos($uri, Base::$indexFile) === 0)
            {
                $uri = (string) substr($uri, strlen(Base::$indexFile));
            }
        }

        return $uri;
    }
209341
function () {
            var reg = new RegExp(domUtils.fillChar, 'g');
            //取出来的空格会有c2a0会变成乱码，处理这种情况\u00a0
            return this.body[browser.ie ? 'innerText' : 'textContent'].replace(reg, '').replace(/\u00a0/g, ' ');
        }
258342
function(){
		var lines = this.fstr.split("\n");
		var firstline = lines.shift();
		delete this.fstr;
		
		/* ヘッダからパズルの種類・ファイルの種類を判定する */
		if(firstline.match(/^pzprv3/)){
			this.type = FILE_PZPR;
			if(firstline.match(/pzprv3\.(\d+)/)){ this.filever = +RegExp.$1;}
			this.pid = lines.shift();
			this.qdata = lines.join("\n");
		}
		else if(firstline.match(/^\<\?xml/)){ // jshint ignore:line
			this.type = FILE_PBOX_XML;
			lines.unshift(firstline);
			this.qdata = lines.join("\n");
			if(!!DOMParser){
				this.body = (new DOMParser()).parseFromString(this.qdata, 'text/xml');
				this.pid = this.body.querySelector('puzzle').getAttribute('type');
			}
			else{ this.pid = '';}
		}
		else if(firstline.match(/^\d+$/)){
			this.type = FILE_PBOX;
			lines.unshift(firstline);
			this.qdata = lines.join("\n");
		}
		else{
			this.pid = '';
		}
		this.pid = pzpr.variety.toPID(this.pid);
		
		return (!!this.pid);
	}
1055446
function(domain, ip, groupName, target_groupName) {
		this._batchHost(function(hostsobject) {
			var group = hostsobject[groupName];
			var t_group = hostsobject[target_groupName] = hostsobject[target_groupName] || [];
			if (group) {
				var host, move, i;
				//目标分组里是否存在该条host，若存在则不作处理。
				for (i = 0; i < t_group.length; i++) {
					host = t_group[i];
					if (host.domain === domain && host.ip === ip) {
						return false;
					}
				}
				for (i = 0; i < group.length; i++) {
					host = group[i];
					if (host.domain === domain && host.ip === ip) {
						t_group.push(host);
						group.splice(i, 1);
						break;
					}
				}
				return hostsobject;
			}
		});
	}
1062920
function generatorEntry(routeConfig = []) {
    const pages = {};


    routeConfig.forEach((route) => {
      const res = mustache.render(entryTpl, route);
      const entry = getPagesPath(`${route.key}/index.js`);
      // fs.openSync(entry, 'w+');
      // console.log('文件创建成功！');
      dirExists(path.parse(entry).dir);
      fs.writeFileSync(entry, res, 'utf-8');
      pages[route.key] = entry;
    });
    return pages;
  }
1198043
function(url, config) {
        config = config || {}

        // 获取头信息
        let realReq = setRequest(ctx, url, config);

        // 扩展请求头信息
        let headersObj = Object.assign({}, realReq.headers, config.headers)

        // 获取请求数据配置
        let requestData = parseData(ctx, config);

        // 请求request的最终配置
        let requestOpt = Object.assign({}, options, {
          uri: realReq.uri,
          method: realReq.method,
          headers: headersObj,
          timeout: undefined,
          gzip: false,
          encoding: null
        }, requestData, config.conf);

        // 发送请求前的钩子，可以对requestjs的参数自定义任何操作
        config.onBeforeRequest && config.onBeforeRequest.call(ctx, proxyName, requestOpt)

        return request(ctx, {
          needPipeRes: true
        }, requestOpt);
      }
757909
public function showTrace()
    {
        $_trace =   array();
        $included_files = get_included_files();

        // 系统默认显示信息
        if (!empty($this->request->server['SCRIPT_NAME']))
        {
            $_trace['请求脚本'] = $this->request->server['SCRIPT_NAME'];
        }

        $_trace['请求方法'] = $this->swoole->env['mvc']['controller'].'/'.$this->swoole->env['mvc']['view'];
        $_trace['USER_AGENT'] = $this->request->server['HTTP_USER_AGENT'];
        $_trace['HTTP版本'] = $this->request->server['SERVER_PROTOCOL'];
        $_trace['请求时间'] = date('Y-m-d H:i:s', $this->request->server['REQUEST_TIME']);

        if (isset($_SESSION))
        {
            $_trace['SESSION_ID'] = session_id();
        }
        if ($this->swoole->db instanceof \Swoole\Database)
        {
            $_trace['读取数据库'] = $this->swoole->db->read_times . '次';
            $_trace['写入数据库'] = $this->swoole->db->write_times . '次';
        }
        $_trace['加载文件数目'] = count($included_files);
        $_trace['PHP执行占用'] = $this->showTime();
        $_trace = array_merge($this->traceInfo, $_trace);

        // 调用Trace页面模板
        $html = <<<HTMLS
<style type="text/css">
#swoole_trace_content  {
font-family:		Consolas, Courier New, Courier, monospace;
font-size:			14px;
background-color:	#fff;
margin:				40px;
color:				#000;
border:				#999 1px solid;
padding:			20px 20px 12px 20px;
}
</style>
	<div>
		<fieldset style="margin:5px;">
		<div style="overflow:auto;text-align:left;">
HTMLS;
        $html .= "<a href='".Tool::url_merge('_show_request', '1')."'>显示请求参数</a> |
        <a href='".Tool::url_merge('_show_session', '1')."'>显示会话信息</a> |
        <a href='".Tool::url_merge('_show_files', '1')."'>显示加载的PHP文件</a>
        <hr/>";
        foreach ($_trace as $key => $info)
        {
            $html .= $key . ' : ' . $info . BL;
        }
        if (!empty($this->request->get['_show_files']))
        {
            //输出包含的文件
            $html .= '加载的文件：' . BL."<pre style='color: #666'>";
            foreach ($included_files as $file)
            {
                $html .= $file . "\n";
            }
            $html .= "</pre>";
        }
        $html .= "</div></fieldset>";
        $html .= "</div>";

        if (!empty($this->request->get['_show_request']))
        {
            $output = '<fieldset style="margin:5px;"><div style="overflow:auto;text-align:left;">';
            $request = $this->swoole->request;
            $output .= "<h2>HEADER:</h2>".Tool::dump($request->header);
            $output .= "<h2>SERVER:</h2>".Tool::dump($request->server);
            if (!empty($request->files))
            {
                $output .= "<h2>FILE:</h2>".Tool::dump($request->files);
            }
            if (!empty($request->cookie))
            {
                $output .= "<h2>COOKIES:</h2>".Tool::dump($request->cookie);
            }
            if (!empty($request->get))
            {
                $output .= "<h2>GET:</h2>".Tool::dump($this->swoole->request->get);
            }
            if (!empty($request->post))
            {
                $output .= "<h2>POST:</h2>".Tool::dump($request->post);
            }

            $html .= $output."</div></fieldset>";
        }

        if (!empty($this->request->get['_show_session']))
        {
            $output = '<fieldset style="margin:5px;"><div style="overflow:auto;text-align:left;">';
            $this->session->start();
            $output .= "<h2>SESSION:</h2>" . Tool::dump($this->request->session);
            $html .= $output."</div></fieldset>";
        }

        return $html;
    }
80011
function local(backendTplServer) {
    backendTplServer.app.get('/news/local', function(request, response) {
        // 公共的数据模型可以抽取到出来, 作为一个文件 require 进来, 防止多处重复定义数据模型的规则
        var data = Mock.mock({
            'news|10-20': [news]
        });

        // 单独修改其中的某个数据
        data.news[0].getUrls = function() {
            return [
                'http://dummyimage.com/112x74,',
                'http://dummyimage.com/112x74,',
                'http://dummyimage.com/112x74,',
                'http://dummyimage.com/112x74,'
            ]
        };

        response.render('news/local.html', data);
    });
}
68977
function margeConfig(options, origId) {
    if (!origId) return;
    var config = options.config,
        arr, modId;
    // 处理build.json => map
    if (options.map && options.map[origId]) {
        origId = options.map[origId];
    }

    // 处理seajs.config => vars
    if (config.vars) {
        if (~origId.indexOf('{')) {
            origId = origId.replace(rVar, function ($, $1) {
                if (config.vars[$1]) {
                    return config.vars[$1];
                }

                return $;
            });
        }
    }

    // 处理seajs.config => alias
    if (config.alias && config.alias[origId]) {
        origId = config.alias[origId];
    }

    // 处理seajs.config => paths
    if (config.paths) {
        arr = origId.split('/');
        modId = arr.splice(arr.length - 1, 1);

        arr.forEach(function (_item, i) {
            if (config.paths[_item]) {
                arr[i] = config.paths[_item];
            }
        });

        arr = arr.concat(modId);
        origId = arr.join('/');
    }
    return origId;
}
192275
function () {
            var _this = this;

            /* 滚动拉取图片 */
            domUtils.on($G('imageList'), 'scroll', function(e){
                var panel = this;
                if (panel.scrollHeight - (panel.offsetHeight + panel.scrollTop) < 10) {
                    _this.getImageData();
                }
            });
            /* 选中图片 */
            domUtils.on(this.container, 'click', function (e) {
                var target = e.target || e.srcElement,
                    li = target.parentNode,
                    nodes = $G('imageListUl').childNodes;

                if (li.tagName.toLowerCase() == 'li') {
                    updateFormState('nocolor', null, '');
                    for (var i = 0, node; node = nodes[i++];) {
                        if (node == li && !domUtils.hasClass(node, 'selected')) {
                            domUtils.addClass(node, 'selected');
                            updateFormState('colored', null, li.firstChild.getAttribute("_src"), 'repeat');
                        } else {
                            domUtils.removeClasses(node, 'selected');
                        }
                    }
                    updateBackground();
                }
            });
        }