<?php

/**
 *--------------------------------------
 * 公用
 *--------------------------------------
 * @project		: uwa
 * @author		: cblee
 * @created		: 2012-09-29
 * @copyright	: (c)2012 AsThis
 *--------------------------------------
 */

class CommonCtrlr extends Ctrlr
{
	public function __construct()
	{
		parent::__construct();

		/* 检查入口 */
		session_start();
		if(!isset($_SESSION['admin_enter']) or 1 != $_SESSION['admin_enter'])
		{
			redirect(Url::U('home@index/index'));
			exit();
		}
	}

	/* 验证码图片 */
	public function captcha_img()
	{
		$name = in_array(ARequest::get('name'), array('vcode', 'test')) ? ARequest::get('name', 'get') : 'vcode';

		$fonts = array('spacing' => 2, 'size' => 16, 'font' => PUBLIC_PATH.D_S.'font/font.ttf');
		$ac = new ACaptcha(90, 30, 5, $fonts);
		ASession::set($name, strtolower($ac->text));
		$ac->create_image();
	}

	/* 检查新版本 */
	public function check_new_version()
	{
		$s = get_instance('Snoopy');
		$s->agent = $_SERVER['HTTP_USER_AGENT'];
		$s->rawheaders['X_FORWARDED_FOR'] = AServer::get_ip();
		$s->expandlinks = true;

		$s->fetch(SOFT_UPGRADE_URL);
		if(200 == $s->status)
		{
			$data = 1;
			$info = substr(trim($s->results), 16, -3);
		}
		else
		{
			$data = 0;
			$info = '';
		}
		$this->ajax_return($data, $info);
	}

}

?>