Пример #1
0
 static function act_message()
 {
     if (post('message_submit', 'isset')) {
         //检查验证码
         $check_code = post('code', 'post');
         if ($check_code != session('message_code', true)) {
             http::json(array('error' => 2, 'info' => 'check_code error'));
         }
         //接收、过滤数据
         $data['user_name'] = post('name', 'title');
         $data['tel'] = post('contact_tel', 'number');
         $data['phone'] = post('contact_phone', 'account');
         $data['email'] = post('email', 'account');
         $data['message'] = post('message_content', 'info');
         //验证数据
         $data['tel'] = safe::reg($data['tel'], 'tel') ? $data['tel'] : null;
         $data['phone'] = safe::reg($data['phone'], 'phone') ? $data['phone'] : null;
         $data['email'] = safe::reg($data['email'], 'email') ? $data['email'] : null;
         if ($data['message']) {
             $add_result = db::add('message', $data);
             //将数据写入留言表
             if ($add_result) {
                 http::json(array('error' => 0, 'info' => 'add message succeed'));
             }
         }
     }
     //以json格式返回给浏览器
     http::json(array('error' => 1, 'info' => 'add message failed'));
 }
Пример #2
0
 static function get_qrcode($str, $w_h = '120', $level = 'L', $margin = '0')
 {
     $str = trim($str);
     $str = safe::reg($str, 'url') ? urlencode($str) : $str;
     $gg_url = 'http://chart.apis.google.com/chart?';
     $url_param = 'chs=' . $w_h . 'x' . $w_h . '&cht=qr&chld=' . $level . '|' . $margin . '&chl=' . $str;
     // return $gg_url.$url_param;
     return '<img src=' . $gg_url . $url_param . '>';
 }
Пример #3
0
function url($lie = 0, $type = 0)
{
    // $lie=$lie+n; //n为相对根目录的深度
    $server_uri = isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : '';
    $param = explode('/', trim($server_uri, '/'));
    if ($lie < count($param)) {
        $value = get_magic_quotes_gpc() ? $param[$lie] : addslashes($param[$lie]);
        if (is_int($type)) {
            return $type ? abs((int) $value) : strval(trim($value));
        }
        return safe::reg($value, $type) ? $value : null;
    }
}
Пример #4
0
 static function act_login()
 {
     if (post('login_submit', 'isset')) {
         //检查验证码
         $check_code = post('code', 'post');
         if ($check_code != session('login_code', true)) {
             http::json(array('error' => 2, 'info' => 'check_code error'));
         }
         //接收数据并验证
         $account = post('account', 'account');
         $password = safe::md5(post('password', 'post'));
         self::check_admin($account, $password);
     }
     http::json(array('error' => 1, 'info' => 'login failed'));
 }
Пример #5
0
 static function check($value, $rule, $type = 'regex')
 {
     $type = strtolower(trim($type));
     switch ($type) {
         case 'in':
             //是否在指定范围值之内,逗号分隔字符串或者数组
         //是否在指定范围值之内,逗号分隔字符串或者数组
         case 'notin':
             $range = is_array($rule) ? $rule : explode(',', $rule);
             return $type == 'in' ? in_array($value, $range) : !in_array($value, $range);
         case 'between':
             //在某个区间内
         //在某个区间内
         case 'notbetween':
             //在某个区间外
             list($min, $max) = is_array($rule) ? $rule : explode(',', $rule);
             return $type == 'between' ? $value >= $min && $value <= $max : $value < $min || $value > $max;
         case 'equal':
             //是否相等
         //是否相等
         case 'notequal':
             //是否不等
             return $type == 'equal' ? $value == $rule : $value != $rule;
         case 'length':
             //长度
             $length = mb_strlen($value, 'utf-8');
             if (strpos($rule, ',')) {
                 //指定长度区间内
                 list($min, $max) = explode(',', $rule);
                 return $length >= $min && $length <= $max;
             } else {
                 //长度相等
                 return $length == $rule;
             }
         case 'expire':
             //有效期
             $now_time = time();
             list($start, $end) = explode(',', $rule);
             $start = is_numeric($start) ? $start : strtotime($start);
             $start = is_numeric($end) ? $end : strtotime($end);
             return $now_time >= $start && $now_time <= $end;
         case 'regex':
         default:
             //默认使用正则验证 可以使用验证类中定义的验证名称
             //检查附加规则
             return safe::reg($value, $rule);
     }
 }
Пример #6
0
 /**
  * @brief 取得pageBar
  * @param string $url URL地址,一般为空!
  * @param string $attrs URL后接参数
  * @return string pageBar的对应HTML代码
  */
 public function getPageBar($url = '', $attrs = '')
 {
     $attr = '';
     if ($attrs != '') {
         $ajax_attr = " {$attrs} ";
     }
     $flag = false;
     if ($url == '') {
         $flag = true;
         $url = url::getUri();
         $url = preg_replace('/page=\\d?&/', '', $url);
         $url = preg_replace('/(\\?|&|\\/)page(\\/|=).*/i', '', $url);
         $mark = '=';
         if (strpos($url, '?') !== false) {
             $index = '&page';
         } else {
             $index = '?page';
         }
     } else {
         $flag = false;
         $index = '';
         $mark = '';
     }
     $baseUrl = "{$url}{$index}{$mark}";
     $baseUrl = safe::filter($baseUrl, 'text');
     $attr = str_replace('[page]', 1, $attrs);
     $href = $baseUrl . ($flag ? 1 : '');
     $tem = "<div class='pages_bar'><a href='{$href}' {$attr}>首页</a>";
     $attr = str_replace('[page]', $this->getIndex() - 1, $attrs);
     $href = $baseUrl . ($flag ? $this->getIndex() - 1 : '');
     if ($this->firstpage > 1) {
         $tem .= "<a href='{$href}' {$attr}>上一页</a>";
     }
     for ($i = $this->firstpage; $i <= $this->lastpage; $i++) {
         $attr = str_replace('[page]', $i, $attrs);
         $href = $baseUrl . ($flag ? $i : '');
         if ($i == $this->index) {
             $tem .= "<a class='current_page' href='{$href}' {$attr}>{$i}</a>";
         } else {
             $tem .= "<a href='{$href}' {$attr}>{$i}</a>";
         }
     }
     $attr = str_replace('[page]', $this->getIndex() + 1, $attrs);
     $href = $baseUrl . ($flag ? $this->getIndex() + 1 : '');
     if ($this->lastpage < $this->totalpage) {
         $tem .= "<a href='{$href}' {$attr}>下一页</a>";
     }
     if ($this->totalpage == 0) {
         $this->index = 1;
     }
     $attr = str_replace('[page]', $this->totalpage, $attrs);
     $href = $baseUrl . ($flag ? $this->totalpage : '');
     return $tem . "<a href='{$href}' {$attr}>尾页</a><span>当前第{$this->index}页/共{$this->totalpage}页</span></div>";
 }
Пример #7
0
 public function __construct()
 {
     if (!self::$magic_quotes_gpc) {
         self::$magic_quotes_gpc = get_magic_quotes_gpc();
     }
 }
Пример #8
0
    outputJSON(i18n::s('Request is invalid.'));
} else {
    $name = $_REQUEST['name'];
}
$action = isset($_REQUEST['action']) ? $_REQUEST['action'] : '';
// Output JSON
function outputJSON($msg, $status = 'error', $preview = '')
{
    global $context;
    Js_css::prepare_scripts_for_overlaying();
    $js = $context['javascript']['footer'];
    header('Content-Type: application/json');
    die(json_encode(array('data' => $msg, 'status' => $status, 'preview' => $preview, 'js' => $js)));
}
load_skin();
safe::make_path('temporary/uploaded/');
// we need a file
if (isset($_FILES[$name]) && count($_FILES[$name])) {
    // Check for errors
    if ($_FILES[$name]['error'] > 0) {
        Safe::header('Status: Internal 500 server error', TRUE, 500);
        outputJSON(i18n::s('An error ocurred when uploading.'));
    }
    /*if(!getimagesize($_FILES['SelectedFile']['tmp_name'])){
          outputJSON('Please ensure you are uploading an image.');
      }*/
    // Check filetype
    if (!Files::is_authorized($_FILES[$name]['name'])) {
        Safe::header('Status: 415 Unsupported media', TRUE, 415);
        outputJSON(i18n::s('Unsupported filetype uploaded.'));
    }
Пример #9
0
function safe($action)
{
    $ip = get_ip();
    $hours = intval(get_varia('safe_' . $action . '_hours'));
    $times = intval(get_varia('safe_' . $action . '_times'));
    $time = time() - $hours * 60 * 60;
    $obj = new safe();
    $obj->set_where("saf_action = '{$action}'");
    $obj->set_where("saf_time < {$time}");
    $obj->del();
    $obj->set_where('');
    $obj->set_where("saf_ip = '{$ip}'");
    $obj->set_where("saf_action = '{$action}'");
    if ($obj->get_count() > $times - 1) {
        header('location:./safe.html');
        exit;
    } else {
        $obj->set_value("saf_ip", $ip);
        $obj->set_value("saf_action", $action);
        $obj->set_value("saf_time", time());
        $obj->add();
    }
}