Пример #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
 function upload()
 {
     if (isset($_FILES['imgFile'])) {
         try {
             $save_name = $this->user_id . '_' . date("dHis");
             $upload = new s_upload($_FILES['imgFile'], $save_name, 5, 'editor', date('ym') . '/');
             $file_name = $upload->get('file_name');
             http::json(array('error' => 0, 'url' => U_R_L . strstr($file_name, 'file/editor/')));
         } catch (sException $e) {
             $message = config('error.' . $e->error, 'upload');
             http::json(array('error' => 1, 'message' => $message));
         }
     }
     http::json(array('error' => 1, 'message' => 'system busy, please try again later'));
 }
Пример #3
0
 private static function check_admin($account, $password)
 {
     //用配置管理员数据(可换数据库)
     $admin_account = config('admin|account', 'message_admin');
     $account_list = explode(',', $admin_account);
     if (!$account || !in_array($account, $account_list)) {
         http::json(array('error' => 3, 'info' => 'inexistent account'));
     }
     if ($password != config('password|' . $account, 'message_admin')) {
         http::json(array('error' => 4, 'info' => 'password error'));
     }
     $admin_access = config('access|' . $account, 'message_admin');
     session('admin', array('account' => $account, 'access' => $admin_access));
     http::json(array('error' => 0, 'info' => 'login succeed', 'url' => dc_url . 'message/manage'));
 }
Пример #4
0
 function email_reply()
 {
     //验证权限,跳转提示页面
     if (!in_array(parent::reply_access, $this->admin_access)) {
         http::skip('login/forbid');
     }
     $tip_info = array('error' => 1, 'info' => 'send email failed');
     if (post('email', 'isset')) {
         //接收数据
         $email = post('email', 'post');
         $title = post('title', 'title');
         $content = post('content', 'info');
         //发送邮件
         mail::send($email, $title, $content);
         $tip_info = array('error' => 0, 'info' => 'email sent');
     }
     http::json($tip_info);
 }
Пример #5
0
 static function check_tip($value, $rule, $type, $tip)
 {
     if (self::check($value, $rule, $type)) {
         return true;
     }
     if (is_array($tip)) {
         http::json($tip);
     }
     http::script($tip, 'alert');
 }
Пример #6
0
 static function edit()
 {
     $img_name = post('img_name', 'title');
     list($width, $height) = getimagesize($img_name);
     $p_width = post('p_w', 'int');
     $p_height = post('p_h', 'int');
     //先缩放
     $res = imagecreatetruecolor($p_width, $p_height);
     $img = img::open($img_name);
     imagecopyresampled($res, $img, 0, 0, 0, 0, $p_width, $p_height, $width, $height);
     img::clear($img);
     //再裁切
     $new_img = imagecreatetruecolor(post('n_w', 'int'), post('n_h', 'int'));
     imagecopyresampled($new_img, $res, 0, 0, post('t_x', 'int'), post('t_y', 'int'), $p_width, $p_height, $p_width, $p_height);
     $img_name = basename($img_name);
     img::save($new_img, $img_name, dc_file_create);
     http::json(array('error' => 0, 'info' => $img_name), true);
 }
Пример #7
0
 static function bootstrap($controller, $method)
 {
     try {
         if ($controller && $method) {
             define('CURRENT_ACTION', substr($controller . ':' . $method, 2));
             if (property_exists($controller, 'static_class')) {
                 if (method_exists($controller, '__before')) {
                     call_user_func($controller . '::__before');
                 }
                 call_user_func(array($controller, $method), explode('/', URL_REQUEST));
                 if (method_exists($controller, '__after')) {
                     call_user_func($controller, '::__after');
                 }
             } else {
                 $object = new $controller();
                 if (method_exists($controller, '__before')) {
                     $object->__before();
                 }
                 call_user_func_array(array($object, $method), array(explode('/', URL_REQUEST)));
                 if (method_exists($controller, '__after')) {
                     $object->__after();
                 }
             }
         } else {
             throw new Exception('absent controller or method', 101);
         }
     } catch (Exception $e) {
         logger::exception('exception', $e->getCode() . ' : ' . $e->getMessage());
         if (preg_match('/^(similar|product)$/', ENVIRONMENT)) {
             if (http::is_ajax()) {
                 http::json(array('error' => 4, 'message' => $e->getMessage(), 'data' => null));
             } else {
                 http::abort($e->getMessage(), '', 10);
             }
         }
         debug::exception($e);
     }
 }
Пример #8
0
 static function verify_tip($value, $option, $tip)
 {
     if (self::verify($value, $option)) {
         return true;
     }
     if (is_array($tip)) {
         http::json($tip);
     }
     http::script($tip, 'alert');
 }