欢迎光临 - 我的站长站,本站所有资源仅供学习与参考,禁止用于商业用途或从事违法行为!

帝国cms教程

帝国CMS全站alert弹窗改json格式输出

帝国cms教程 我的站长站 2024-10-05 共0人阅读

帝国CMS全站alert弹窗改JSON格式输出,不影响原版功能。
1、在要输出json头部代码

define('API_WORK', true);

2.改造printerror和printerror2,增加一个参数$statuscode,不写的状态200

/**
* cighsen02 365182575 弹窗改 json接口,还支持 404, 401等
* time: 2022.09.15
*/
//错误提示
function printerror($error="",$gotourl="",$ecms=0,$noautourl=0,$novar=0, $statuscode = 200){
        global $empire,$editor,$public_r,$ecms_config;
        if($editor==1){$a="../";}
        elseif($editor==2){$a="../../";}
        elseif($editor==3){$a="../../../";}
        else{$a="";}
        if($ecms==1||$ecms==9)
        {
                $a=ECMS_PATH.'e/data/';
        }
        if(strstr($gotourl,"(")||empty($gotourl))
        {
                if(strstr($gotourl,"(-2"))
                {
                        $gotourl_js="history.go(-2)";
                        $gotourl="javascript:history.go(-2)";
                }
                else
                {
                        $gotourl_js="history.go(-1)";
                        $gotourl="javascript:history.go(-1)";
                }
        }
        else
        {$gotourl_js="self.location.href='$gotourl';";}
        if(empty($error))
        {$error="DbError";}
        if($ecms==9)//前台弹出对话框
        {
                @include $a.LoadLang("pub/q_message.php");
                $error=empty($novar)?$qmessage_r[$error]:$error;
               
                //cighsen02 365182575
                if(defined('API_WORK') && API_WORK)        throw new Exception($error, '1' . $statuscode);
               
                echo"<script>alert('".$error."');".$gotourl_js."</script>";
                db_close();
                $empire=null;
                exit();
        }
        elseif($ecms==8)//后台弹出对话框
        {
                @include $a.LoadLang("pub/message.php");
                $error=empty($novar)?$message_r[$error]:$error;
               
                //cighsen02 365182575
                if(defined('API_WORK') && API_WORK)        throw new Exception($error, '1' . $statuscode);
               
                echo"<script>alert('".$error."');".$gotourl_js."</script>";
                db_close();
                $empire=null;
                exit();
        }
        elseif($ecms==7)//前台弹出对话框并关闭窗口
        {
                @include $a.LoadLang("pub/q_message.php");
                $error=empty($novar)?$qmessage_r[$error]:$error;
               
                //cighsen02 365182575
                if(defined('API_WORK') && API_WORK)        throw new Exception($error, '1' . $statuscode);
               
                echo"<script>alert('".$error."');window.close();</script>";
                db_close();
                $empire=null;
                exit();
        }
        elseif($ecms==6)//后台弹出对话框并关闭窗口
        {
                @include $a.LoadLang("pub/message.php");
                $error=empty($novar)?$message_r[$error]:$error;
                echo"<script>alert('".$error."');window.close();</script>";
                db_close();
                $empire=null;
                exit();
        }
        elseif($ecms==0)
        {
                @include $a.LoadLang("pub/message.php");
                $error=empty($novar)?$message_r[$error]:$error;
               
                //cighsen02 365182575
                if(defined('API_WORK') && API_WORK)        throw new Exception($error, '1' . $statuscode);
               
                @include($a."message.php");
        }
        else
        {
                @include $a.LoadLang("pub/q_message.php");
                $error=empty($novar)?$qmessage_r[$error]:$error;
               
                //cighsen02 365182575
                if(defined('API_WORK') && API_WORK)        throw new Exception($error, '1' . $statuscode);
               
                @include($a."../message/index.php");
        }
        db_close();
        $empire=null;
        exit();
}
/**
* cighsen02 365182575 弹窗改 json接口,还支持 404, 401等
* time: 2022.09.15
*/
//错误提示2:直接文字
function printerror2($error='',$gotourl='',$ecms=0,$noautourl=0, $statuscode = 200){
        global $empire,$public_r;
        if(strstr($gotourl,"(")||empty($gotourl))
        {
                if(strstr($gotourl,"(-2"))
                {
                        $gotourl_js="history.go(-2)";
                        $gotourl="javascript:history.go(-2)";
                }
                else
                {
                        $gotourl_js="history.go(-1)";
                        $gotourl="javascript:history.go(-1)";
                }
        }
        else
        {$gotourl_js="self.location.href='$gotourl';";}
        if($ecms==9)//弹出对话框
        {
                //cighsen02 365182575
                if(defined('API_WORK') && API_WORK)        throw new Exception($error, '1' . $statuscode);
               
                echo"<script>alert('".$error."');".$gotourl_js."</script>";
        }
        elseif($ecms==7)//弹出对话框并关闭窗口
        {
                //cighsen02 365182575
                if(defined('API_WORK') && API_WORK)        throw new Exception($error, '1' . $statuscode);
               
                echo"<script>alert('".$error."');window.close();</script>";
        }
        else
        {
                @include(ECMS_PATH.'e/message/index.php');
        }
        db_close();
        exit();
}

3、使用自动加载功能和异常处理,以上3个步骤完成,一起来体验吧

标签 JSON
下一篇:返回列表
相关推荐
  • JSON
  • JSON字段过滤工具
    JSON字段过滤工具

    工具介绍吾爱大佬分享的一款JSON字段过滤工具,可以从json文件提取多个相同的字段。Python开发的简易工具,支持嵌套的json,可以直接输入字段名,或者A.B的形式来遍历所有符合的字段值,以key:value的形式...

    开发软件 50 1年前
  • PHP数组转换为JSON格式数据

    PHP数组转换为JSON格式数据,这里介绍下PHP json_encode函数,他可以轻松完成转换。json_encode函数PHP json_encode() 用于对变量进行 JSON 编码,该函数如果执行成功返回 JSON 数据,否则返回 FALSE 。json_encode语法string json_encode ( $value [, $opt...

    php教程 108 4年前
  • json_encode函数中文乱码解决方法

    在用到json_encode函数对数据进行json格式转换时,中文会乱码,这里需要用到JSON_UNESCAPED_UNICODE对中文不编码处理。实战案列<?php $arr = array(&#39;11px&#39; => &#39;我的站长站&#39;, &#39;taobao&#39; => &#39;淘宝网&#39;); echo json_enc...

    php教程 59 4年前
  • 此响应不是合法的JSON响应的解决办法

    WordPress无法通过Gutenberg编辑器发布和修改网站内容,提示“此响应不是合法的JSON响应”,禁用所有插件,并且切换回WordPress自带的官方主机,问题依旧,说明不是主题和插件导致的。开启浏览器调试默认,访问 工具 - 站点健康 界面,可以看到提示 REST API 遇到...

    wordpress教程 96 3年前
  • json参数的传递和接收处理方法

    php传递json参数示例<? function http_post_data($url, $data_string) { $ch = curl_init(); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string); ...

    php教程 54 2年前