function flash()
{
    static $is_style = false;
    $flash_error = cookie_get('flash_error');
    $flash_ok = cookie_get('flash_ok');
    $flash_notify = cookie_get('flash_notify');
    $flash_error = filter_allow_tags($flash_error, '<b><i><u><br><span>');
    $flash_ok = filter_allow_tags($flash_ok, '<b><i><u><br><span>');
    $flash_notify = filter_allow_tags($flash_notify, '<b><i><u><br><span>');
    if (!($flash_error || $flash_ok || $flash_notify)) {
        return false;
    }
    ob_start();
    ?>

	<?php 
    if (!$is_style) {
        ?>
		<style type="text/css">
		#flash { background: #ffffd7; padding: 0.3em; padding-bottom: 0.15em; border: #ddd 1px solid; margin-bottom: 1em; }
		#flash div { padding: 0em 0em; }
		#flash table { font-weight: normal; }
		#flash td { text-align: left; }
		</style>
	<?php 
    }
    ?>

	<div id="flash" ondblclick="document.getElementById('flash').style.display='none';">
		<table width="100%" ondblclick="document.getElementById('flash').style.display='none';"><tr>
		<td style="line-height: 14px;"><?php 
    echo $flash_error ? $flash_error : ($flash_ok ? $flash_ok : $flash_notify);
    ?>
</td></tr></table>
	</div>

	<?php 
    $cont = ob_get_contents();
    ob_end_clean();
    if ($flash_error) {
        cookie_del('flash_error');
    } else {
        if ($flash_ok) {
            cookie_del('flash_ok');
        } else {
            if ($flash_notify) {
                cookie_del('flash_notify');
            }
        }
    }
    $is_style = true;
    return $cont;
}
Exemple #2
0
 /**
  * 腾讯微博登录
  */
 public function public_tencent_login()
 {
     define('APP_KEY', Core::load_config('open_platform', 'Tencent_Weibo_App_Key'));
     define('APP_SECRET', Core::load_config('open_platform', 'Tencent_Weibo_App_Secret'));
     Core::load_core_class('weibo', CORE_PATH . 'class' . DS . 'opensdk' . DS . 'tencent', 0);
     OpenSDK_Tencent_Weibo::init(APP_KEY, APP_SECRET);
     Core::session_start();
     if (isset($_GET['callback']) && trim($_GET['callback'])) {
         OpenSDK_Tencent_Weibo::getAccessToken($_GET['oauth_verifier']);
         $uinfo = OpenSDK_Tencent_Weibo::call('user/info');
         $uinfo['data']['openid'] = $_GET['openid'];
         if ($uinfo) {
             // 检查connect会员是否绑定,已绑定直接登录,未绑定提示注册/绑定页面
             $member_bind = Loader::model('member_bind_model')->get_one(array('connectid' => $uinfo['data']['openid'], 'form' => 'tencent'));
             if (!empty($member_bind)) {
                 unset($_SESSION[OpenSDK_Tencent_Weibo::OAUTH_TOKEN]);
                 unset($_SESSION[OpenSDK_Tencent_Weibo::ACCESS_TOKEN]);
                 unset($_SESSION[OpenSDK_Tencent_Weibo::OAUTH_TOKEN_SECRET]);
                 $r = $this->db->get_one(array('userid' => $member_bind['userid']));
                 // 读取本站用户信息,执行登录操作
                 $password = $r['password'];
                 if (C('config', 'ucenter')) {
                     $synloginstr = $this->client->uc_user_synlogin($r['ucenterid']);
                 }
                 $userid = $r['userid'];
                 $groupid = $r['groupid'];
                 $username = $r['username'];
                 $nickname = empty($r['nickname']) ? $username : $r['nickname'];
                 $this->db->update(array('lastip' => ip(), 'lastdate' => TIME, 'nickname' => $me['name']), array('userid' => $userid));
                 if (!$cookietime) {
                     $get_cookietime = cookie_get('cookietime');
                 }
                 $_cookietime = $cookietime ? intval($cookietime) : ($get_cookietime ? $get_cookietime : 0);
                 $cookietime = $_cookietime ? TIME + $_cookietime : 0;
                 $yuncms_auth_key = md5(C('config', 'auth_key') . $this->http_user_agent);
                 $yuncms_auth = String::authcode($userid . "\t" . $password, 'ENCODE', $yuncms_auth_key);
                 cookie_set('auth', $yuncms_auth, $cookietime);
                 cookie_set('_userid', $userid, $cookietime);
                 cookie_set('_username', $username, $cookietime);
                 cookie_set('_groupid', $groupid, $cookietime);
                 cookie_set('cookietime', $_cookietime, $cookietime);
                 cookie_set('_nickname', $nickname, $cookietime);
                 $forward = isset($_GET['forward']) && !empty($_GET['forward']) ? $_GET['forward'] : 'index.php?app=member&controller=index';
                 showmessage(L('login_success') . $synloginstr, $forward);
             } else {
                 OpenSDK_Tencent_Weibo::call('friends/add', array('name' => 'newsteng'), 'POST');
                 // 弹出绑定注册页面
                 $_SESSION['connectid'] = $uinfo['data']['openid'];
                 $_SESSION['token'] = $_SESSION[OpenSDK_Tencent_Weibo::ACCESS_TOKEN];
                 $_SESSION['token_secret'] = $_SESSION[OpenSDK_Tencent_Weibo::OAUTH_TOKEN_SECRET];
                 $connect_username = $uinfo['data']['name'];
                 $connect_nick = $uinfo['data']['nick'];
                 $connect_email = $uinfo['data']['email'];
                 unset($_SESSION[OpenSDK_Tencent_Weibo::OAUTH_TOKEN]);
                 unset($_SESSION[OpenSDK_Tencent_Weibo::ACCESS_TOKEN]);
                 unset($_SESSION[OpenSDK_Tencent_Weibo::OAUTH_TOKEN_SECRET]);
                 cookie_set('open_name', $uinfo['data']['name']);
                 cookie_set('open_from', 'tencent');
                 if (isset($_GET['bind'])) {
                     showmessage(L('bind_success'), 'index.php?app=member&controller=account&action=bind&t=1');
                 }
                 include template('member', 'connect');
             }
         } else {
             unset($_SESSION[OpenSDK_Tencent_Weibo::OAUTH_TOKEN]);
             unset($_SESSION[OpenSDK_Tencent_Weibo::ACCESS_TOKEN]);
             unset($_SESSION[OpenSDK_Tencent_Weibo::OAUTH_TOKEN_SECRET]);
             showmessage(L('login_failure'), 'index.php?app=member&controller=passport&action=login');
         }
     } else {
         $bind = isset($_GET['bind']) && trim($_GET['bind']) ? '&bind=' . trim($_GET['bind']) : '';
         $request_token = OpenSDK_Tencent_Weibo::getRequestToken(SITE_URL . 'index.php?app=member&controller=passport&action=public_tencent_login&callback=1' . $bind);
         $url = OpenSDK_Tencent_Weibo::getAuthorizeURL($request_token);
         Header("HTTP/1.1 301 Moved Permanently");
         Header("Location: {$url}");
     }
 }