建立请求，以表单HTML形式构造（默认）

@param $para_temp 请求参数数组
@param $method 提交方式。两个值可选：post、get
@param $button_name 确认按钮显示文字
@return String 提交表单HTML文本
332131
public function formPost($url, $para, $method, $charset)
    {
        //待请求参数数组
        $sHtml = "<form id='alipaysubmit' name='alipaysubmit' action='".$url."' method='".$method."'>";
        while (list ($key, $val) = each ($para)) {
            $sHtml.= "<input type='hidden' name='".$key."' value='".$val."'/>";
        }

        //submit按钮控件请不要含有name属性
        $sHtml = $sHtml."<input type='submit' value='确认'></form>";

        $sHtml = $sHtml."<script>document.forms['alipaysubmit'].submit();</script>";

        return $sHtml;
    }
260319
public function buildRequestHttpInFile($para_temp, $file_para_name, $file_name) {

        //待请求参数数组
        $para = $this->buildRequestPara($para_temp);
        $para[$file_para_name] = "@".$file_name;

        //远程获取数据
        $sResult = HelperFunction::getHttpResponsePOST($this->alipay_gateway_new, $this->cacert,$para,trim(strtolower($this->input_charset)));

        return $sResult;
    }
1021219
protected function api($name, $data = '', $method = 'POST', $param = ''){
        $params = array('access_token' => $this->accessToken);

        if(!empty($param) && is_array($param)){
            $params = array_merge($params, $param);
        }

        $url  = "{$this->apiURL}/{$name}";
        if(!empty($data)){
            //保护中文，微信api不支持中文转义的json结构
            array_walk_recursive($data, function(&$value){
                $value = urlencode($value);
            });
            $data = urldecode(json_encode($data));
        }

        $data = self::http($url, $params, $data, $method);

        return json_decode($data, true);
    }
1186817
static public function wx_contents_input($form_name, $form_value=null, $settings=null)
    {
        $settings['id']     = isset($settings['id']) ? $settings['id'] : str_replace(array('[', ']'), array('_'), $form_name);
        $index = 0;
        $template = <<<INPUT
<li style="%s" class="%s">
    <img src="%s" class="content-img">
    <div class="content-body">
        <span class="content-title">%s</span>
        <span class="content-description">%s</span>
        <input type="hidden" name="%s" value="%s" class="content-title-input">
        <input type="hidden" name="%s" value="%s" class="content-description-input">
        <input type="hidden" name="%s" value="%s" class="content-pic-url-input">
        <input type="hidden" name="%s" value="%s" class="content-url-input">
        <input type="hidden" name="%s" value="%s" class="content-id-input">
    </div>
    <div class="content-op">
        <input type="button" class="btn btn-primary btn-sm edit-content" value="编辑">
        <input type="button" class="btn btn-primary btn-sm delete-content" value="删除">
    </div>
</li>
INPUT;
        $str = '<ul class="list-unstyled contents-wrap">' . PHP_EOL;
        if (isset($form_value) && is_array($form_value)) foreach ($form_value as $k => $v) {
            $img_src = isset($v['pic_url']) ? $v['pic_url'] : '';
            $title = isset($v['title']) ? $v['title'] : '';
            $description = isset($v['description']) ? $v['description'] : '';
            $url = isset($v['url']) ? $v['url'] : '';
            $id  = isset($v['id']) ? $v['id'] : 0;
            $str .= sprintf($template
                , '', $settings['id'] . '-content-wrap-' . $index
                , $img_src, $title, $description
                , $settings['id'] . '['. $index . '][title]', $title
                , $settings['id'] . '['. $index . '][description]', $description
                , $settings['id'] . '['. $index . '][pic_url]', $img_src
                , $settings['id'] . '['. $index . '][url]', $url
                , $settings['id'] . '['. $index . '][id]', $id
            );
            $index += 1;
        }
        $str .= sprintf($template
            , 'display:none;', $settings['id'] . '-content-wrap-' . 'x'
            , '', '', ''
            , $settings['id'] . '['. 'x' . '][title]', ''
            , $settings['id'] . '['. 'x' . '][description]', ''
            , $settings['id'] . '['. 'x' . '][pic_url]', ''
            , $settings['id'] . '['. 'x' . '][url]', ''
            , $settings['id'] . '['. 'x' . '][id]', 0
        );
        $str .= '</ul>' . PHP_EOL;
        
        $str .= '<div style="margin-top:15px;">'. PHP_EOL;
        $str .= '    <input type="button" class="btn btn-warning btn-sm select-content" data-id="' . $settings['id'] . '" value="选择图文列表">';
        $str .= '    <input type="button" class="btn btn-warning btn-sm add-content" data-id="' . $settings['id'] . '" value="自定义图文列表">';
        $str .= '</div>'. PHP_EOL;
        
        //if (!static::$isLoadedImageText) {
        $select_url = isset($settings['modal_url']) ? $settings['modal_url'] : Ioc::url('common/data/select_content');
            $innerJs = <<<EOF
                <script>
                require(["util"], function(){
                    var index = "{$index}";
                	$(".contents-wrap").on("click", ".delete-content", function() {
                	    //console.log($(this));
                        $(this).parent().parent("li").remove();
                        return false;
                    });
                    $(".select-content").on("click", function() {
                        var tid = $(this).attr('data-id');
                        
                        var dlg = util.dialog.show({
                            width: '800px',
                    		title: '选择图文内容',
                    		url: "{$select_url}",
                    		okValue: '确 定',
                    		ok: false,
                    		cancelValue: '取消',
                    		cancel: null,
                    		cancelDisplay: true
                    	});
                    	
                        dlg.addEventListener('close', function () {
                            if (dlg.returnValue.data) {
                                console.log(dlg.returnValue);
                                data = dlg.returnValue.data;
                                if (data.length > 0) {
                    		        for (dindex in data) {
                    		            var item_index = Number(dindex) + Number(index);
                                        var tpl_ele = $("." + tid + '-content-wrap-x');
                                        var html = tpl_ele.html().replace(/\[x\]/g, '[' + item_index + ']');
                                        $('<li style="text-align:center;" class="' + tid + '-content-wrap-' + item_index + '">').insertBefore(tpl_ele).html(html);
                                        var ele = $("." + tid + '-content-wrap-' + item_index);
                                        ele.find(".content-img").attr('src', data[dindex]["pic_url"]).show();
                    		            ele.find(".content-title").html(data[dindex]["title"]);
                    		            ele.find(".content-description").html(data[dindex]["description"]);
                    		    
                                        ele.find(".content-title-input").val(data[dindex]["title"]);
                    		            ele.find(".content-description-input").val(data[dindex]["description"]);
                    		            ele.find(".content-pic-url-input").val(data[dindex]["pic_url"]);
                    		            ele.find(".content-url-input").val(data[dindex]["url"]);
                                    }
                    		        index = Number(index) + data.length;
                                }
                            }
                    	});
                        
                    });
                });
                </script>
EOF;
            $str .= $innerJs;
            // 动态的添加该输入框时脚本不能作用，暂时先重复脚本生成
            //static::$isLoadedImageText = true;
        //}
        return $str;
    }
817863
public static function searchForm($action, $method = 'post', $htmlOptions = array())
    {
        self::addCssClass('form-search', $htmlOptions);
        $inputOptions = TbArray::popValue('inputOptions', $htmlOptions, array());
        $inputOptions = TbArray::merge(array('type' => 'text', 'placeholder' => 'Search'), $inputOptions);
        $name = TbArray::popValue('name', $inputOptions, 'search');
        $value = TbArray::popValue('value', $inputOptions, '');
        $output = self::beginFormTb(self::FORM_LAYOUT_SEARCH, $action, $method, $htmlOptions);
        $output .= self::searchQueryField($name, $value, $inputOptions);
        $output .= parent::endForm();
        return $output;
    }
669873
protected Object getMethodParam(String methodName, String paramKey) {
        if (CommonUtils.isEmpty(configContext)) {
            return null;
        }
        Object o = configContext.get(buildMethodKey(methodName, paramKey));
        return o == null ? configContext.get(paramKey) : o;
    }
1069187
public function getHTMLBodyWithEmbeddedUrlImages($route_name, $params = []) {
        return $this->getCustomHTMLBody(function($body, $oAttachment) use($route_name, $params){
            /** @var \Webklex\IMAP\Attachment $oAttachment */
            if ($oAttachment->id && $oAttachment->getImgSrc() != null) {
                $oMessage = $oAttachment->getMessage();

                $image_url = route($route_name, array_merge([
                    'muid' => urlencode($oMessage->uid),
                    'mid' => urlencode($oMessage->message_id),
                    'mti' => urlencode($oMessage->date->timestamp),
                    'aid' => urlencode($oAttachment->id)
                ], $params));

                $body = str_replace('cid:'.$oAttachment->id, $image_url, $body);
            }

            return $body;
        });
    }
290507
public function run(string $link = null, string $method = null): string
    {
        if ($link === null) {
            if (isset($_SERVER['REQUEST_URI']) === false) {
                $_SERVER['REQUEST_URI'] = '/';
            }
            $link = str_replace("?" . $_SERVER["QUERY_STRING"], "", $_SERVER["REQUEST_URI"]);
        }
        $link = '/' . trim($link, '/');
        if ($link == '/Core-Framework') {
            $link .= '/';
        }

        if ($method === null) {
            if (isset($_SERVER['REQUEST_METHOD']) === false) {
                $_SERVER['REQUEST_METHOD'] = 'GET';
            }
            $method = $_SERVER['REQUEST_METHOD'];
        }
        if ($method == 'POST' && empty($_POST['_method']) === false) {
            $method = $_POST['_method'];
            unset($_POST['_method']);
        }

        $result = $this->router->match($link, $method);
        $this->templates->addData([
            'template' => isset($_GET['template'])
        ]);

        try {
            if ($result !== false) {
                if (func_num_args() > 2) {
                    $arguments_list = func_get_args();
                    array_shift($arguments_list);array_shift($arguments_list);
                    foreach ($arguments_list as $argument) {
                        $result['params'][] = $argument;
                    }
                } elseif ($_SERVER['REQUEST_METHOD'] == 'POST' && empty($_POST) === false) {
                    $result['params'][] = $_POST;
                } elseif ($_SERVER['REQUEST_METHOD'] == 'GET' && empty($_GET) === false) {
                    $result['params'][] = $_GET;
                }
                if (is_string($result['target']) === true) {
                    $result['target'] = explode("@", $result['target']);
                } else {
                    $result['target'] = [$result['target']];
                }
                if (count($result['target']) === 1 && $result['target'][0] == "API") {
                    return $this->api($result['params'][0])->run();
                } elseif (count($result['target']) === 1 && is_callable($result['target'][0]) === true) {
                    return call_user_func_array($result['target'][0], $result['params']);
                } elseif (count($result['target']) === 2 && class_exists("TheCMSThread\\Core\\Admin\\Controller\\" . $result['target'][0]) === true && method_exists("TheCMSThread\\Core\\Admin\\Controller\\" . $result['target'][0], $result['target'][1]) === true) {
                    $controller = new \ReflectionClass("TheCMSThread\\Core\\Admin\\Controller\\" . $result['target'][0]);
                    $controller = $controller->newInstance($this->core, $this->router, $this->templates, $this->container);
                    return call_user_func_array([
                        $controller,
                        $result['target'][1]
                    ], $result['params']);
                } else {
                    throw new \LogicException("Cannot find route handler");
                }
            } else {
                if (headers_sent() === false) {
                    header('X-PHP-Response-Code: 404', true, 404);
                }
                return $this->templates->render("404");
            }
        } catch (\Throwable $e) {
                if (headers_sent() === false) {
                    header('X-PHP-Response-Code: 500', true, 500);
                }
            return $this->templates->render("500", [
                "error" => $e,
                "result" => $result
            ]);
        }
    }
1263270
public static function method() {
        // $this->methodParam 默认值为 '_method'
        // 如果指定 $_POST['_method'] ，表示使用POST请求来模拟其他方法的请求。
        // 此时 $_POST['_method'] 即为所模拟的请求类型。
        if (isset($_POST[$this->methodParam])) {
            return strtoupper($_POST[$this->methodParam]);
            // 或者使用 $_SERVER['HTTP_X_HTTP_METHOD_OVERRIDE'] 的值作为方法名。
        } elseif (isset($_SERVER['HTTP_X_HTTP_METHOD_OVERRIDE'])) {
            return strtoupper($_SERVER['HTTP_X_HTTP_METHOD_OVERRIDE']);
            // 或者使用 $_SERVER['REQUEST_METHOD'] 作为方法名，未指定时，默认为 GET 方法
        } else {
            return isset($_SERVER['REQUEST_METHOD']) ? strtoupper($_SERVER['REQUEST_METHOD']) : 'GET';
        }
    }
288119
protected function getMethodName($method, $docBlock = null): string
    {
        if ($docBlock !== null && $docBlock->hasTag(self::API_METHOD_NAME)) {
            $tags = $docBlock->getTagsByName(self::API_METHOD_NAME);

            return (string)$tags[0];
        }

        $controllerName = $method->getDeclaringClass();

        if (!empty($this->server->endpoint)) {
            return $method->getName();
        }

        return $this->getShortNameForController($controllerName->getName()) . '_' . $method->getName();
    }
398689
public function generateMethod(Method $method): string
    {
        return $this->twig->render('method.html', [
            'method' => $method,
            'namespace' => $this->getNamespace(),
            'full_namespace' => $this->getFullNamespace()
        ]);
    }
63873
public function handleDatasource($name, $method, array $preloadedData, array &$templateVariables)
    {
        $this->name = $name;

        $datasource = ActionUtils::createActionDatasource($name,$method);

        // set the variables for use
        $this->templateVars =& $templateVariables;

        $this->currentDatasource = $datasource;

        // set the current datasource
        $this->currentActionOrDatasource = $datasource;

        $methodResolved = ActionUtils::parseMethod($method);

        $this->currentMethod = $methodResolved;

        //if(LOG_ENABLE) System::log(self::$logType, 'Datasource: ['.$datasource.']');

        // if we did an action and the datasource is already set, use it
        if(self::$actionBoundDatasource == $datasource)
            return $this;

        if(!method_exists($this, $methodResolved))
            throw new Exception('Method ['.$methodResolved.'] does not exist on class ['.get_class($this).']');

        // clear the data first
        $this->setData(null);

        // set preloaded data (from Renderer)
        if(!empty($preloadedData))
            $this->setData($preloadedData);

        $this->preDatasource();

        //if(LOG_ENABLE) System::log(self::$logType, 'Executing method ['.$methodResolved.']');

        $result = null;

        $result = $this->$methodResolved();

        if($result == null)
            $result = array();

        // bind to datasource
        $this->setData($result);

        $this->postDatasource();

        return $this; // for chaining
    }
1294941
public static function method($method, $base_class = null, $model = false, $constructor_parameters = null) {
		$temp = explode('::', $method);
		if (count($temp) > 1) {
			$temp_model = $temp[0];
			$temp_method = $temp[1];
		} else {
			$temp_model = $base_class;
			$temp_method = $temp[0];
		}
		if ($model) {
			$temp_model = \Factory::model($temp_model, false, $constructor_parameters);
		}
		return [& $temp_model, $temp_method];
	}
868697
private function parse_buttons( $buttons, $post = null )
    {
        $buttons = explode( '|', $buttons );

        $buttons = array_map( function ( $button ) use ( $post ) {

            $params = array_map( 'trim', explode( ',', $button ) );

            $button = [
                'title' => $params[0],
                'type'  => $params[1],
            ];

            if ( $button['type'] === 'postback' ) {
                $button['payload'] = $params[2];
            }

            if ( $button['type'] === 'web_url' ) {
                if ( $params[2] === 'permalink' ) {
                    $params[2] = get_permalink( $post );
                }

                if ( filter_var( $params[2], FILTER_VALIDATE_URL ) ) {
                    $button['url'] = $params[2];
                }
            }

            return $button;

        }, $buttons );

        return $buttons;
    }
144946
public function showHTML($result, $link_myself = true, $params = 'query=$0&amp;output=nice')
    {

        // adds links for HTML output

        $email_regex = "/([-_\w\.]+)(@)([-_\w\.]+)\b/i";
        $html_regex = "/(?:^|\b)((((http|https|ftp):\/\/)|(www\.))([\w\.]+)([,:%#&\/?~=\w+\.-]+))(?:\b|$)/is";
        $ip_regex = "/\b(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b/i";

        $out = '';
        $lempty = true;

        foreach ($result['rawdata'] as $line) {
            $line = trim($line);

            if ($line == '') {
                if ($lempty) {
                    continue;
                } else {
                    $lempty = true;
                }
            } else {
                $lempty = false;
            }

            $out .= $line . "\n";
        }

        if ($lempty) {
            $out = trim($out);
        }

        $out = strip_tags($out);
        $out = preg_replace($email_regex, '<a href="mailto:$0">$0</a>', $out);
        $out = preg_replace_callback(
            $html_regex,
            function ($matches) {
                if (substr($matches[0], 0, 4) == 'www.') {
                    $web = $matches[0];
                    $url = 'http://' . $web;
                } else {
                    $web = $matches[0];
                    $url = $web;
                }

                return '<a href="' . $url . '" target="_blank">' . $web . '</a>';
            },
            $out
        );

        if ($link_myself) {
            if ($params[0] == '/') {
                $link = $params;
            } else {
                $link = $_SERVER['PHP_SELF'] . '?' . $params;
            }

            $out = preg_replace($ip_regex, '<a href="' . $link . '">$0</a>', $out);

            if (isset($result['regrinfo']['domain']['nserver'])) {
                $nserver = $result['regrinfo']['domain']['nserver'];
            } else {
                $nserver = false;
            }

            if (isset($result['regrinfo']['network']['nserver'])) {
                $nserver = $result['regrinfo']['network']['nserver'];
            }

            if (is_array($nserver)) {
                reset($nserver);
                while (list($host, $ip) = each($nserver)) {
                    $url = '<a href="' . str_replace('$0', $ip, $link) . "\">$host</a>";
                    $out = str_replace($host, $url, $out);
                    $out = str_replace(strtoupper($host), $url, $out);
                }
            }
        }

        // Add bold field names
        $out = preg_replace("/(?m)^([-\s\.&;'\w\t\(\)\/]+:\s*)/", '<b>$1</b>', $out);

        // Add italics for disclaimer
        $out = preg_replace("/(?m)^(%.*)/", '<i>$0</i>', $out);

        return str_replace("\n", "<br/>\n", $out);
    }
581150
public function send($mobile, $temp_id, $params = '')
    {
        //主帐号
        $accountSid = self::$yun['accountSid'];

        //主帐号Token
        $accountToken = self::$yun['accountToken'];

        //应用Id
        $appId = self::$yun['appid'];

        //请求地址，格式如下，不需要写https://
        $serverIP = self::$yun['serverIP'];

        //请求端口
        $serverPort = self::$yun['serverPort'];

        //REST版本号
        $softVersion = self::$yun['softVersion'];

        if(is_array($mobile)){
            $mobile= implode(',', $mobile);
        }

        $rest = new CCPRest($serverIP,$serverPort,$softVersion);
        $rest->setAccount($accountSid,$accountToken);
        $rest->setAppId($appId);

        $result = $rest->sendTemplateSMS($mobile, $params, $temp_id);
        if($result == NULL ) {
            return false;
        }

        if($result->statusCode!=0) {
            //echo "error code :" . $result->statusCode . "<br>";
            //echo "error msg :" . $result->statusMsg . "<br>";
            $msg = $mobile .':'.json_encode($params). '---' . 'error code :' . $result->statusCode.'---' .'error msg :' . $result->statusMsg;
            //Logger::writeSMSLog($msg);
        }

        return ($result->statusCode == 0) ? TRUE : FALSE;
    }
904139
public function send($mobile, $temp_id, $params = array())
    {
        $ucpass = new UcpaasProvider(self::$ucpaas);

        $appId = self::$ucpaas['appid']; //应用id

        if (is_array($mobile)) {
            $tel = implode(',', $mobile);
        }

        $param = implode(',', $params);

        $res = $ucpass->templateSMS($appId, $mobile, $temp_id, $param);

        $res = json_decode($res, true);
        $errcode = $res['resp']['respCode'];
        if ($errcode !== '000000') {
            $msg = $mobile . ':' . json_encode($params) . '---' . 'errcode:'. $errcode;
            $this->writeLog($msg);
        }

        return ($errcode === '000000') ? TRUE : FALSE;
    }