www.gusucode.com > mcms手机网站系统 v3.1源码程序 > mcms_v3.1.0/upload/app/admin/config.senior.php

    <?php
/*
 * MCMS Copyright (c) 2012-2013 ZhangYiYeTai Inc.
 *
 *  http://www.mcms.cc
 *
 * The program developed by loyjers core architecture, individual all rights reserved,
 * if you have any questions please contact loyjers@126.com
 */

require_once(dirname(__FILE__) . "/../../init.php"); //公用引导启动文件
check_login();
check_level('C06',AJAX);
$time_start = H :: getmicrotime(); //开始时间

// 动作处理
call_mfunc();

// 模板处理
require_once(assign_tpl(basename(__FILE__), 'admin'));

// ******************************************************* 函数方法 *******************************************************
function m__list(){
    global $skins_set;
    $skins=H::get_dirs(ROOT_PATH.'/static/');
    $skins_set=array();
    foreach($skins as $v){
        if(substr($v,0,4)=='sty_'){
            $skin=substr($v,4);
            array_push($skins_set,array('txt'=>$v,'value'=>$skin,'txt_color'=>''));
        }
    }
}
//保存
function m__save(){
    global $global_global;
    $_POST=H::sqlxss($_POST);
	foreach($_POST as $k=>$v) if(!is_array($v)) $_POST[$k]=trim(stripcslashes($v));
    $config=$_POST;
    $domain_upload=$config['domain_upload'];
    $mem_server=$config['mem_server'];
    $cache_type=$config['cache_type'];

    unset($config['cache_type']);
    unset($config['smtp_test_email']);
    unset($config['ytx_test_mobile']);
    $config['domain_upload']=explode(',',$domain_upload);
    $config['mem_server']=explode(',',$mem_server);

    //更改值和插入新值
    foreach($config as $k=>$v){
        $global_global[$k]=$config[$k];
    }
    //写入数组配置缓存
    $global_global_file=ROOT_PATH."/config/cache/global.php";
    if(is_writable($global_global_file)) {
        H::cache(array('key'=>'global','val'=>$global_global,'time'=>0,'cache_type'=>'file_cache'));
    }else{
        die('{"code":1,"msg":"'.$global_global_file.' 没有写入权限"}');
    }

    //更改上一级global.php 配置
    if(!in_array($cache_type,array('file_cache','memcache','memcached'))) die('{"code":1,"msg":"不支持的缓存方式"}');
    save_global_top('CACHE_TYPE',$cache_type);

    die('{"code":0,"msg":"操作成功"}');
}
//邮件发送测试
function m__test_email(){
    $_POST=H::sqlxss($_POST);
    require_once(ROOT_PATH."/class/phpmailer/class.phpmailer.php");
    require_once(ROOT_PATH."/class/phpmailer/class.smtp.php");
    $verify=verify::verify_email($_POST['smtp_test_email']);
    if($verify!='') die('{"code":1,"msg":"'.$verify.'"}');
    $mail = new phpMailer();
    $mail -> IsSMTP();
    $mail -> SMTPAuth = true;
    $mail -> Host = SMTP_HOST;
    $mail -> Username = SMTP_UNAME;
    $mail -> Password = SMTP_UPASS;

    $mail -> IsHTML(true);
    $mail -> CharSet = 'utf-8';
    $mail -> From = SMTP_UNAME;

    $mail -> FromName = SITE_NAME;
    $mail -> AddAddress($_POST['smtp_test_email']);
    $mail -> Subject = SITE_NAME.'测试邮件';
    $mail -> Body = str_replace(array('\n','\r',chr(10),chr(13)), '<br>', '测试邮件发送成功');
    if (!$mail -> Send()) {
        $result = $mail -> ErrorInfo;
        die('{"code":0,"msg":"发送失败 '.$result.'"}');
    }
    die('{"code":0,"msg":"发送成功,请查收邮件"}');
}
/**
  * 发送模板短信
  * @param to 手机号码集合,用英文逗号分开
  * @param datas 内容数据 格式为数组 例如:array('Marry','Alon'),如不需替换请填 null
  * @param $tempId 模板Id
  */
function m__test_sms(){
    $_POST=H::sqlxss($_POST);
    require_once(ROOT_PATH."/class/yuntongxun.sdk.class.php");
    $verify=verify::verify_mobile($_POST['ytx_test_mobile']);
    if($verify!='') die('{"code":1,"msg":"'.$verify.'"}');
    // 初始化REST SDK
    $rest = new REST(YTX_SERVER_IP,YTX_SERVER_PORT,YTX_VERSION);
    $rest->setAccount(YTX_ACCOUNT_SID,YTX_ACCOUNT_TOKEN);
    $rest->setAppId(YTX_APPID);

    // 发送模板短信
    $result = $rest->sendTemplateSMS($_POST['ytx_test_mobile'],array(rand(1000,9999),'60'),YTX_SMS_TPL);

    if($result == NULL) {
        die('{"code":1,"msg":"发送失败"}');
    }

    if(intval($result['statusCode'])==0){
        die('{"code":0,"msg":"发送成功,请查看手机短信"}');
    }else{
        die('{"code":1,"msg":"'.$result['statusMsg'].'"}');
    }
}

//更改 global.php 顶部独立配置
function save_global_top($key,$val){
    $key=str_replace('"',"",$key);
    $val=str_replace('"',"\\\"",$val);
    $global_file=ROOT_PATH."/config/global.php";

    $global=  file_get_contents($global_file);
    $global = preg_replace('~define\("'.$key.'"\s*,\s*"(.*?)"\)\s*;~','define("'.$key.'","'.$val.'");',$global);

    if(is_writable($global_file)) {
        file_put_contents($global_file,$global);
    }else{
        die('{"code":1,"msg":"'.$global_file.' 没有写入权限"}');
    }
}

?>