예제 #1
0
 /**
  * 自动创建接口ID
  * @param $module_id
  * @param $interface_key
  * @return int
  * @throws \Exception
  */
 private function getInterfaceId($module_id, $interface_key)
 {
     $interface_key = \Swoole\Filter::escape($interface_key);
     $table = 'interface';
     $params['select'] = "id";
     $params['name'] = $interface_key;
     $params['module_id'] = $module_id;
     $data = table($table)->gets($params);
     if (!empty($data)) {
         return $data[0]['id'];
     } else {
         $put['name'] = $interface_key;
         $put['alias'] = $interface_key;
         $put['module_id'] = $module_id;
         $put['create_host'] = $this->clientInfo['remote_ip'];
         return table($table)->put($put);
     }
 }
예제 #2
0
 function onReceive($serv, $fd, $thread_id, $data)
 {
     $info = $this->serv->connection_info($fd, $thread_id, true);
     $parts = explode("\n", $data, 2);
     $put = array();
     list($put['module'], $put['level'], $put['type'], $put['subtype'], $put['uid']) = explode("|", $parts[0]);
     $put['content'] = Filter::escape(rtrim($parts[1]));
     $put['hour'] = date('H');
     $put['ip'] = $info['remote_ip'];
     if (!is_numeric($put['uid'])) {
         $put['ukey'] = $put['uid'];
         $put['uid'] = 0;
     }
     $table = $this->getTableName();
     if (!table($table)->put($put) and \Swoole::$php->db->errno() == 1146) {
         $this->createTable($table);
         table($table)->put($put);
     }
     \Swoole::$php->redis->sAdd('logs2:client:' . $put['module'], $put['ip']);
     \Swoole::$php->redis->sAdd('logs2:type:' . $put['module'], $put['type']);
     \Swoole::$php->redis->sAdd('logs2:subtype:' . $put['module'], $put['subtype']);
 }
예제 #3
0
파일: Server.php 프로젝트: fyee/php-webim
 /**
  * 登录
  * @param $client_id
  * @param $msg
  */
 function cmd_login($client_id, $msg)
 {
     $info['name'] = Filter::escape($msg['name']);
     $info['avatar'] = Filter::escape($msg['avatar']);
     //回复给登录用户
     $resMsg = array('cmd' => 'login', 'fd' => $client_id, 'name' => $msg['name'], 'avatar' => $msg['avatar']);
     //把会话存起来
     $this->users[$client_id] = $resMsg;
     $this->store->login($client_id, $resMsg);
     $this->sendJson($client_id, $resMsg);
     //广播给其它在线用户
     $resMsg['cmd'] = 'newUser';
     //将上线消息发送给所有人
     $this->broadcastJson($client_id, $resMsg);
     //用户登录消息
     $loginMsg = array('cmd' => 'fromMsg', 'from' => 0, 'channal' => 0, 'data' => $msg['name'] . "上线了");
     $this->broadcastJson($client_id, $loginMsg);
 }
예제 #4
0
 function topic()
 {
     $tpl = array('id' => 0, 'title' => '', 'url' => 'http://www.v2ex.com/t/188087', 'content' => '', 'content_rendered' => '', 'replies' => 0, 'created' => 0, 'last_modified' => 0, 'last_touched' => 1430627831, 'member' => array('id' => 0, 'username' => '', 'tagline' => '', 'avatar_mini' => '', 'avatar_normal' => '', 'avatar_large' => ''), 'node' => array('id' => 1, 'name' => 'create', 'title' => '分享创造', 'title_alternative' => 'Create', 'url' => 'http://www.v2ex.com/go/create', 'topics' => 3800, 'avatar_mini' => '//cdn.v2ex.co/navatar/70ef/df2e/17_mini.png?m=1430065455', 'avatar_normal' => '//cdn.v2ex.co/navatar/70ef/df2e/17_normal.png?m=1430065455', 'avatar_large' => '//cdn.v2ex.co/navatar/70ef/df2e/17_large.png?m=1430065455'));
     $gets = array('order' => 'question_id desc', 'pagesize' => 20);
     $gets['page'] = empty($_GET['page']) ? 1 : intval($_GET['page']);
     $_user = table('aws_users');
     $_user->primary = 'uid';
     if (!empty($_GET['category'])) {
         $gets['category_id'] = intval($_GET['category']);
     }
     if (!empty($_GET['username'])) {
         $user = $_user->get($_GET['username'], 'user_name');
         $gets['published_uid'] = $user['uid'];
     }
     $pager = null;
     $list = table('aws_question')->gets($gets, $pager);
     $_uids = array();
     $_categorys = array();
     foreach ($list as $li) {
         $_uids[$li['published_uid']] = true;
         $_categorys[$li['category_id']] = true;
     }
     if (!empty($_uids)) {
         $users = $_user->getMap(['in' => array('uid', implode(',', array_keys($_uids)))]);
     } else {
         $users = array();
     }
     if (!empty($_uids)) {
         $categorys = table('aws_category')->getMap(['in' => array('id', implode(',', array_keys($_categorys)))]);
     } else {
         $categorys = array();
     }
     $result = array();
     foreach ($list as $li) {
         Swoole\Filter::safe($li['question_content']);
         $tpl['id'] = $li['question_id'];
         $tpl['title'] = $li['question_content'];
         $tpl['content'] = $li['question_detail'];
         $tpl['created'] = $li['add_time'];
         $tpl['last_modified'] = $li['update_time'];
         $tpl['replies'] = $li['answer_count'];
         //用户信息
         $uid = $li['published_uid'];
         $tpl['member']['id'] = $uid;
         $tpl['member']['username'] = $users[$uid]['user_name'];
         $_category_id = $li['category_id'];
         $tpl['node']['id'] = $_category_id;
         $tpl['node']['title_alternative'] = $tpl['node']['title'] = $tpl['node']['name'] = $categorys[$_category_id]['title'];
         $tpl['node']['name'] = $categorys[$_category_id]['title'];
         if (empty($users[$uid]['avatar_file'])) {
             $tpl['member']['avatar_mini'] = self::NO_AVATAR . 'avatar-min-img.jpg';
             $tpl['member']['avatar_normal'] = self::NO_AVATAR . 'avatar-mid-img.jpg';
             $tpl['member']['avatar_large'] = self::NO_AVATAR . 'avatar-max-img.jpg';
         } else {
             $tpl['member']['avatar_mini'] = self::AVATAR_URL . $users[$uid]['avatar_file'];
             $tpl['member']['avatar_normal'] = self::AVATAR_URL . str_replace('_min.', '_mid.', $users[$uid]['avatar_file']);
             $tpl['member']['avatar_large'] = self::AVATAR_URL . str_replace('_min.', '_max.', $users[$uid]['avatar_file']);
         }
         $tpl['content_rendered'] = self::parseMarkdown($li['question_detail']);
         $result[] = $tpl;
     }
     echo json_encode($result);
 }
예제 #5
0
 function write()
 {
     $_m = model('UserLogs');
     $_l = model('UserLogCat');
     if ($_POST) {
         //如果没得到id,说明提交的是添加操作
         if (empty($_POST['title'])) {
             return Swoole\JS::js_back('标题不能为空!');
         }
         Swoole\Filter::safe($_POST['content']);
         $_POST['content'] = Swoole\Filter::remove_xss($_POST['content']);
         Swoole\Filter::addslash($_POST['content']);
         $blog['title'] = $_POST['title'];
         $blog['content'] = $_POST['content'];
         $blog['c_id'] = (int) $_POST['c_id'];
         if (isset($_POST['act']) and $_POST['act'] == 'draft') {
             $blog['dir'] = 1;
         } else {
             $blog['dir'] = 0;
         }
         if (!empty($_POST['id'])) {
             //如果得到id,说明提交的是修改的操作
             $id = (int) $_POST['id'];
             $det = $_m->get($id)->get();
             if ($det['uid'] != $this->uid) {
                 exit('access deny!not your blog!');
             }
             $_m->set($id, $blog);
             if (isset($_POST['autosave'])) {
                 return 1;
             } else {
                 return Swoole\JS::js_back('修改成功', -2);
             }
         } else {
             $blog['uid'] = $this->uid;
             $bid = $_m->put($blog);
             $_l->set($blog['c_id'], array('num' => '`num`+1'));
             if (isset($_POST['autosave'])) {
                 return $bid;
             } else {
                 return Swoole\JS::js_back('添加成功');
             }
         }
     } else {
         require_once WEBPATH . '/swoole_plugin/fckeditor/Swoole.plugin.php';
         $cat = $_l->getMap(array('uid' => $this->uid), 'name');
         if (empty($cat)) {
             $cat = array();
         }
         if (!empty($_GET['id'])) {
             $id = $_GET['id'];
             $det = $_m->get($id)->get();
             Swoole\Filter::deslash($det['content']);
             $form = Swoole\Form::select('c_id', $cat, $det['c_id']);
             $this->swoole->tpl->assign('det', $det);
             $editor = editor("content", $det['content'], 480, false, false, array('empty' => '请选择日志分类'));
         } else {
             $form = Swoole\Form::select('c_id', $cat, '', false, array('empty' => '请选择日志分类'));
             $editor = editor("content", '', 480, false);
         }
         $this->swoole->tpl->assign('form', $form);
         $this->swoole->tpl->assign('editor', $editor);
         $this->swoole->tpl->display();
     }
 }