public function getUnreadMessage($user_id) { $user_id = intval($user_id); if (!isset($this->count_info[$user_id]['unread_message_count'])) { $this->getUserCount(User::getUser($user_id)); } return isset($this->count_info[$user_id]['unread_message_count']) ? $this->count_info[$user_id]['unread_message_count'] : 0; }
public function user_permission($id = 0) { try { $user = User::getUser(0 + $id); $info = $user->Permission(); $this->__view("Control/user_permission.php", ["info" => implode("\n", $info), "user_id" => $user->getId()]); } catch (\Exception $ex) { echo "<h3 class='text-danger'>用户权限加载失败:</h3><p>" . $ex->getMessage() . "</p>"; } }
/** * 获取用户主页地址 * @param string|int $name 用户名或ID * @return string */ function user_link($name) { static $router = NULL; if ($router === NULL) { $router = lib()->using('router'); } if (is_numeric($name)) { try { $name = \ULib\User::getUser(intval($name))->getName(); } catch (Exception $ex) { //nothing } } return get_url($router->getLink('user', $name)); }
/** * 发送信息 * @param string $title * @param string $users * @param string $content * @param int $send_user * @return array */ public function send($title, $users, $content, $send_user) { if (login_user()->Permission('MessageDeny')) { $this->throwMsg(-10); } $title = trim($title); $users = array_map('trim', preg_split("/[\\s]+/", $users)); $content = trim($content); if (strlen($content) < 1) { $this->throwMsg(-4); } $send_user = intval($send_user); if ($send_user < 0) { $this->throwMsg(-1); } else { if ($send_user === 0) { //系统信息 if (!login_user()->Permission('MessageSystem')) { $this->throwMsg(-2); } } else { //用户信息 if (!User::getUser($send_user)->is_active()) { //未激活不允许发送信息 $this->throwMsg(-3); } if (count($users) == 1 && $users[0] == User::getUser($send_user)->getName()) { $this->throwMsg(-13); } } } if (count($users) < 1) { $this->throwMsg(-6); } if ($send_user > 0) { $this->checkLastSend($send_user); } if ($send_user > 0) { $list = $this->checkUser($users, $send_user); if (($l = count($list)) === 0) { $this->throwMsg(-6); } else { if ($l > hook()->apply("Message_send_number", 5)) { $this->throwMsg(-7); } } } else { //系统发信,可以使用ID序列 if (empty($title)) { //系统消息标题不能为空 $this->throwMsg(-19); } $list_id = $this->db->select("users", ['id'], ['OR' => ['user_name' => $users, 'id' => $users]]); $list = []; if ($list_id === false) { Log::write(_("select user id list error on message."), Log::SQL); } foreach ($list_id as $v) { $list[] = $v['id']; } } $send_user !== 0 or $send_user = NULL; $time = date("Y-m-d H:i:s"); $status = ['ok' => 0, 'error' => 0]; foreach ($list as $t_id) { $data = ['msg_title' => $title, 'msg_content' => $content, 'msg_datetime' => $time, 'from_users_id' => $send_user, 'to_users_id' => $t_id]; $data = hook()->apply('Message_send_before', $data); if (empty($data)) { continue; } $insert = $this->db->insert("message", $data); if ($insert > 0) { ++$status['ok']; //运行成功处理 hook()->apply('Message_send_success', NULL, $data, $insert); } else { Log::write(_("Insert message error."), Log::SQL); ++$status['error']; } } return $status; }
* @var string $__error */ if (!empty($__error)) { ?> <div class="well text-danger"><h3><?php echo $__error; ?> </h3></div> <?php } else { if ($__content['from_users_id'] > 0) { $from_user = \ULib\User::getUser($__content['from_users_id']); } else { $from_user = NULL; } $to_user = \ULib\User::getUser($__content['to_users_id']); ?> <div class="panel panel-primary"> <div class="panel-heading"> <h2 class="panel-title">消息阅读</h2> </div> <div class="panel-body"> <?php if (!empty($__content['msg_title'])) { ?> <h3 class=""><?php echo $__content['msg_title']; ?> </h3> <?php }
/** * 构造方法,使用评论的信息和对应的用户类 * @param array $set_info * @param int $user_id */ function __construct($set_info, $user_id) { $this->ip_c = Ip::getInstance(); $this->user = User::getUser($user_id); if (is_array($set_info) && isset($set_info['comment_id'])) { static $names = []; if (count($names) === 0) { $ref = new \ReflectionClass($this); foreach ($ref->getProperties() as $ro) { $names[] = $ro->getName(); } $names = array_flip($names); unset($names['ip_c'], $names['user'], $names['sub_node']); } if (isset($set_info['comment_ip'])) { $set_info['comment_ip'] = $this->ip_c->bin2ip($set_info['comment_ip']); } foreach ($set_info as $k => $v) { if (isset($names[$k])) { $this->{$k} = $v; } } self::$comment_stack[$this->getCommentId()] = $this; } else { Log::write(_("Comment class construct error"), Log::ALERT); } }
public function user_change_status() { $req = req()->_plain(); if ($req->is_post()) { $id = intval($req->post('id')); $status = intval($req->post('status')); try { $user = new User($id); $user->set(['status' => $status]); $this->rt_msg['status'] = true; } catch (\Exception $ex) { $this->rt_msg['msg'] = $ex->getMessage(); } } else { $this->rt_msg['msg'] = "必须以POST方式提交数据"; } }
/** * 发送消息给关注用户 * @param null $rt * @param int $f_id 被关注ID * @param int $u_id 关注者ID * @return null */ public function message_follow_me($rt, $f_id, $u_id) { try { if ($this->notice($f_id, 'message', 'follow_me')) { $user = User::getUser($u_id); $follow_user = User::getUser($f_id); $mt = new MailTemplate("message_notice/follow_me.md"); $mt->setUserInfo($follow_user->getInfo()); $mt->setValues(['follow_user_aliases' => $user->getAliases(), 'follow_user_url' => user_link($user->getName()), 'follow_list_link' => get_url('Follow', 'ta'), 'follow_user_name' => $user->getName()]); $this->message->addNoticeMsg($mt->getTitle(), $mt->getContent(), $f_id); } } catch (\Exception $ex) { Log::write(_("Message to message_follow_me create a Exception.") . "EX:[" . $ex->getCode() . "]:" . $ex->getMessage(), Log::NOTICE); } return $rt; }
/** * 使用COOKIE登录系统 * @return bool|User */ public static function CookieLogin() { $cookie = trim(req()->cookie('UserLogin')); if (!empty($cookie)) { $cookie = explode("\t", $cookie); } if (count($cookie) == 2) { $cookie[0] = intval($cookie[0]); $cookie[1] = trim($cookie[1]); if ($cookie[0] > 0) { try { $user = new User($cookie[0]); if ($user->getCookieLogin() == $cookie[1]) { if (in_array($user->getStatus(), [0, 1, 2])) { if (trim(req()->cookie('LoginFlag')) != date("Y-m-d")) { //如果COOKIE中的日期和当前日期不相符就设置 try { self::setLastLoginInfo($user); } catch (\Exception $ex) { Log::write(_("User last login info set error.ID: ") . $user->getId() . _(".Exception:") . $ex->getMessage(), Log::SQL); } } return $user; } } } catch (\Exception $ex) { return false; } } } return false; }
/** * POST登录 * @param string $account * @param string $password * @param string $captcha * @param bool $save_status */ public function PostLogin($account, $password, $captcha, $save_status) { if (empty($account) || empty($password)) { $this->throwMsg(-10); } $save_status = !empty($save_status); if (!$this->Captcha($captcha)) { //验证码检测 $this->throwMsg(-5); } $account = strtolower($account); $password = strtolower($password); $this->GetAccountUser($account); lib()->load('UserCheck'); if (!UserCheck::CheckPasswordChar($password)) { $this->throwMsg(-3); } $ip = Ip::getInstance(); $max_error_count = hook()->apply("UserLogin_max_error_count", 6); $now_ip = $ip->realip(); if ($max_error_count <= $this->user->getErrorLoginCount() && $ip->fill($now_ip) === $ip->fill($this->user->getErrorLoginIp()) && explode(" ", $this->user->getErrorLoginTime())[0] == date("Y-m-d")) { //登录被限制 $this->throwMsg(-8); } else { if (UserCheck::CreatePassword($password, $this->user->getSalt()) !== $this->user->getPassword()) { //错误登录记录 $this->user->set(array("error_login_count" => 1 + $this->user->getErrorLoginCount(), 'error_login_time' => date("Y-m-d H:i:s"), 'error_login_ip' => $now_ip)); if ($this->user->getErrorLoginCount() >= $max_error_count) { hook()->apply("UserLogin_PostLogin_restrictions", NULL, $this->user); } $this->throwMsg(-4); } else { if (in_array($this->user->getStatus(), [0, 1, 2])) { if ($this->user->getErrorLoginCount() > 0) { //错误登录清零 $this->user->set(array("error_login_count" => 0)); } } else { //登录受限制,无法登录 $this->throwMsg(-9); } } } try { //登录成功后的COOKIE设置 if (strlen($this->user->getCookieLogin()) < 10) { $this->user->set(array("cookie_login" => salt_hash(time() . $this->user->getEmail(), salt(20)))); } if ($save_status) { cookie()->set("UserLogin", $this->user->getId() . "\t" . $this->user->getCookieLogin(), hook()->apply("UserLogin_PostLogin_CookieTime", time() + 60 * 60 * 24 * 7)); } else { cookie()->set("UserLogin", $this->user->getId() . "\t" . $this->user->getCookieLogin()); } } catch (\Exception $ex) { $this->throwMsg(-6); } try { //最后登录信息 self::setLastLoginInfo($this->user); } catch (\Exception $ex) { $this->code = -7; } hook()->apply('UserLogin_PostLogin_Success', NULL, $this->user); }
<small>第<?php echo $__number; ?> 页</small> </h2> <?php } ?> <div id="Gallery_list"> <?php $i = 0; $count = count($__list); foreach ($__list as $v) { $pic_link = picture_link($v['pic_id']); $gallery_link = gallery_link($v['gallery_id']); $user = \ULib\User::getUser($v['users_id']); ?> <?php if ($i % 2 === 0) { ?> <div class="row list_box"> <?php } ?> <div class="media col-md-6"> <a href="<?php echo $pic_link; ?> " rel="external"> <img class="media-object img-thumbnail" src="<?php echo $v['pic_thumbnails_url'];
public function user_gallery_list($user = NULL, $page = 0) { $page = (int) $page; $this->__lib('ListGallery'); $lg = new ListGallery(); $lg->setPager($page, 6); $pager = ['previous' => NULL, 'next' => NULL]; $list = $lg->getListOfUser($user); if (!isset($list[0]) || !reset($list[0])) { $this->__load_404(); } else { $count = $lg->getCount(); /** * @var \ULib\Router $router */ $router = lib()->using('router'); if ($count['page'] > 1) { if ($count['page'] == 2) { $pager['previous'] = get_url($router->getLink("user_gallery_list", $user)); } else { $pager['previous'] = get_url($router->getLink("user_gallery_list_pager", $user, $count['page'] - 1)); } } if ($count['page'] < $count['max']) { $pager['next'] = get_url($router->getLink("user_gallery_list_pager", $user, $count['page'] + 1)); } $user = User::getUser($user); if ($page > 0) { $this->theme->setTitle($user->getName() . " 的图集列表 第{$page}页"); } else { $this->theme->setTitle($user->getName() . " 的图集列表"); } $this->__view("Home/header.php"); $this->__view("Show/user_header.php", ['user' => $user]); $this->__view("Show/gallery_list.php", ['list' => $list, 'pager' => $pager, 'type' => 'user', 'number' => $count['page']]); $this->__view("Home/footer.php"); } }
/** * 获取当前设置的图集信息 * @return array */ private function get() { $where = ['gallery.id' => $this->gallery_id]; if ($this->user_id !== NULL) { $where = ['AND' => ['gallery.id' => $this->gallery_id, 'gallery.users_id' => intval($this->user_id)]]; } $this->info = $this->db->select("gallery", ['[><]users' => ['users_id' => 'id'], '[>]users_like_gallery' => ['id' => 'gallery_id', '______' => ['users_like_gallery.users_id' => is_login() ? login_user()->getId() : 0]]], ['users.user_name' => 'user_name', 'users.user_url' => 'user_url', 'users.user_aliases' => 'user_aliases', 'users.user_status' => 'user_status', 'users.user_avatar' => 'user_avatar', 'gallery.id' => 'gallery_id', 'gallery.users_id' => 'user_id', 'gallery.gallery_title' => 'gallery_title', 'gallery.gallery_description' => 'gallery_description', 'gallery.gallery_create_time' => 'gallery_create_time', 'gallery.gallery_like_count' => 'gallery_like_count', 'gallery.gallery_update_time' => 'gallery_update_time', 'gallery.gallery_comment_count' => 'gallery_comment_count', 'gallery.gallery_comment_status' => 'gallery_comment_status', 'gallery.gallery_front_cover' => 'gallery_front_cover', 'gallery.gallery_status' => 'gallery_status', 'users_like_gallery.like_time' => 'gallery_like_time'], $where); if (!isset($this->info[0])) { $this->info = NULL; $this->error = _('Gallery not found.'); } else { lib()->load('Avatar', 'User'); $this->info = $this->info[0]; $this->info['user_avatar'] = Avatar::get($this->info['user_avatar'], User::getUser($this->info['user_id'])); $this->info['gallery_tags'] = $this->getTags($this->gallery_id); $this->info['gallery_pictures'] = $this->getPictures($this->gallery_id); $front_cover = intval($this->info['gallery_front_cover']); if ($front_cover > 0) { lib()->load('Picture'); $pic = new Picture(); $this->info['front_cover'] = $pic->get_pic($front_cover); } } return $this->info; }
public function time_line() { try { $this->throwMsgCheck('is_get', 'is_ajax', 'is_login'); $id = (int) req()->get('id'); $list = Feed::getInstance()->getList(login_user()->getId(), $id); $u = []; $c = []; foreach ($list as $fid => &$v) { $id = $v->getUserId(); $oid = $v->getObjUserId(); if (!isset($u[$id])) { $u[$id] = User::getUser($id)->getSimpleInfo(); $u[$id]['link'] = user_link($u[$id]['name']); } if (!isset($u[$oid])) { $u[$oid] = User::getUser($oid)->getSimpleInfo(); $u[$oid]['link'] = user_link($u[$oid]['name']); } $c[$fid] = $v->getInfo(); } $this->rt_msg['content'] = ['list' => $c, 'user' => $u, 'count' => count($list)]; $this->rt_msg['status'] = true; } catch (\Exception $ex) { $this->rt_msg['msg'] = $ex->getMessage(); $this->rt_msg['code'] = $ex->getCode(); } }
/** * @param User $user * @param string $code * @throws \Exception * @return int 返回用户状态码 */ public static function UserActivation($user, $code) { if ($user->is_active()) { throw new \Exception(_("User is already activation")); } $meta = $user->getMeta()->get(["activation_code", "activation_time"], ''); if (empty($meta['activation_time']) || empty($meta['activation_code'])) { throw new \Exception(_("Activation code is invalid")); } if (time() - strtotime($meta['activation_time']) > hook()->apply('UserRegister_UserActivation_time', 3 * 24 * 60 * 60)) { throw new \Exception(_("Activation code is time out")); } if ($meta['activation_code'] != $code) { throw new \Exception(_("Activation code is error")); } else { $user->set(['status' => 1]); } return $user->getStatus(); }
/** * 对数组信息进行解析,和增加部分信息 * @param array $list * @param bool $convert_avatar 是否对头像进行处理 * @return mixed */ public function parsePic(&$list, $convert_avatar = true) { if ($convert_avatar) { lib()->load('User', 'Avatar'); } for ($i = 0, $l = count($list); $i < $l; $i++) { if (!empty($list[$i]['user_avatar'])) { if ($convert_avatar) { $list[$i]['user_avatar'] = Avatar::get($list[$i]['user_avatar'], User::getUser($list[$i]['user_id'])); } } if (empty($list[$i]['server_url'])) { continue; } $list[$i]['pic_url'] = $this->makePictureUrl($list[$i]['server_url'], $list[$i]['pic_path'], $list[$i]['pic_path']); $list[$i]['pic_thumbnails_url'] = $this->makePictureUrl($list[$i]['server_url'], $list[$i]['pic_thumbnails_path'], $list[$i]['pic_path']); $list[$i]['pic_hd_url'] = $this->makePictureUrl($list[$i]['server_url'], $list[$i]['pic_hd_path'], $list[$i]['pic_path']); $list[$i]['pic_display_url'] = $this->makePictureUrl($list[$i]['server_url'], $list[$i]['pic_display_path'], $list[$i]['pic_path']); } return $list; }
/** * @param User $user */ public function upload_avatar($user) { c_lib()->load('upload'); $upload = new Upload(['root_path' => 'avatar', 'exts' => ['jpg', 'png'], 'sub_status' => false, 'name_callback' => [function ($param) { return $param; }, $user->getId()], 'replace' => true, 'max_size' => 500 * 1024, 'save_ext' => 'jpg'], 'Local'); if (!isset($_FILES['avatar'])) { $this->throwMsg(-16); } $info = $upload->uploadOne($_FILES['avatar']); lib()->load('Avatar'); $avatar = new Avatar(); $avatar->process_avatar($info['save_name'], 400, 400); }
/** * @param User $user * @return string */ public static function upload_avatar($user) { $path = _BasePath_ . "/avatar/"; if (is_file($path . $user->getId() . ".jpg")) { return self::local_avatar($user->getId()); } return ""; }
/** * 根据用户获取对他的项目上的对应评论 * @param int $uid * @return array */ public function getListOfUserOnObject($uid) { if (!$this->setCount(self::TYPE_Object_user, $uid)) { return []; } $list = $this->db->select($this->table, ['[><]comments' => ['comments_id' => 'id'], '[><]users' => ['users_id' => 'id']], [$this->table . "." . $this->type . "_id" => $this->type . "_id", $this->table . ".comments_id" => "comments_id", $this->table . ".object_users_id" => "object_users_id", $this->table . '.users_id' => 'users_id', 'users.id' => 'user_id', 'users.user_name' => 'user_name', 'users.user_aliases' => 'user_aliases', 'users.user_email' => 'user_email', 'users.user_url' => 'user_url', 'users.user_status' => 'user_status', 'users.user_registered_time' => 'user_registered_time', 'users.user_last_login_time' => 'user_last_login_time', 'users.user_avatar' => 'user_avatar', 'comments.comment_content' => 'comment_content', 'comments.comment_time' => 'comment_time'], [$this->table . '.object_users_id' => $uid, 'LIMIT' => [($this->count['page'] - 1) * $this->count['number'], $this->count['number']], 'ORDER' => $this->table . ".comments_id DESC"]); $this->getListDataParse($list); for ($i = 0, $l = count($list); $i < $l; $i++) { $user_info = []; foreach ($list[$i] as $k => $v) { if (strpos($k, "user_") === 0) { $user_info[substr($k, 5)] = $v; } } //从堆栈获取用户 $list[$i]['user_object'] = User::UserStack(+$user_info['id']); if (!is_object($list[$i]['user_object'])) { $list[$i]['user_object'] = new User($user_info, true); } } return $list; }
/** * 提交评论 * @param string $content * @param int $reply * @param int $user_id * @return int */ public function comment($content, $reply, $user_id) { if (!$this->checkAllowComment($this->id)) { $this->throwMsg(-11); } $user = User::getUser($user_id); $content = $this->comment_check($content); $reply = intval($reply); if ($reply < 0) { $this->throwMsg(-3); } $top = 0; if ($reply > 0) { $reply_info = $this->reply_comment_info($reply); if (!isset($reply_info['users_id'])) { $this->throwMsg(-4); } $top = intval($reply_info['comment_parent_top']); if ($top === 0 && $reply_info['comment_parent'] == 0) { $top = $reply; } } return $this->insert_comment($content, $reply, $top, $user->getId()); }
/** * @param $title * @param $name * @param $users_id * @return array */ public function create($title, $name, $users_id) { $title = trim($title); $name = trim($name); $this->checkTitle($title); $this->checkName($name); if ($this->existsName($name)) { $this->throwMsg(-7); } User::getUser($users_id); $data = ['post_title' => $title, 'post_name' => $name, 'post_time' => date("Y-m-d H:i:s"), 'post_category' => $this->getCategory(0), 'post_status' => 0, 'post_update_time' => date("Y-m-d H:i:s"), 'post_content' => '', 'users_id' => $users_id]; $insert = $this->db->insert("posts", $data); if ($insert < 1) { Log::write(_("Insert post content error."), Log::SQL); $this->throwMsg(-3); } $data['id'] = $insert; return $data; }
public function getListOfUser($user_name) { $user = User::getUser($user_name); if (!is_object($user)) { return []; } if (!$this->getCountInfo($user->getId(), 'user')) { return []; } $list = $this->db->select("pictures", ['[<]gallery' => ['id' => 'gallery_front_cover'], '[>]server' => ['server_name' => 'name']], ['gallery.id' => 'gallery_id', 'gallery.users_id' => 'users_id', 'gallery.gallery_title' => 'gallery_title', 'gallery.gallery_description' => 'gallery_description', 'gallery.gallery_create_time' => 'gallery_create_time', 'gallery.gallery_update_time' => 'gallery_update_time', 'gallery.gallery_like_count' => 'gallery_like_count', 'gallery.gallery_comment_count' => 'gallery_comment_count', 'gallery.gallery_comment_status' => 'gallery_comment_status', 'gallery.gallery_front_cover' => 'gallery_front_cover', 'pictures.id' => 'pic_id', 'pictures.server_name' => 'server_name', 'server.url' => 'server_url', 'pictures.pic_name' => 'pic_name', 'pictures.pic_path' => 'pic_path', 'pictures.pic_create_time' => 'pic_create_time', 'pictures.pic_width' => 'pic_width', 'pictures.pic_height' => 'pic_height', 'pictures.pic_description' => 'pic_description', 'pictures.pic_thumbnails_path' => 'pic_thumbnails_path', 'pictures.pic_thumbnails_width' => 'pic_thumbnails_width', 'pictures.pic_thumbnails_height' => 'pic_thumbnails_height', 'pictures.pic_hd_path' => 'pic_hd_path', 'pictures.pic_hd_width' => 'pic_hd_width', 'pictures.pic_hd_height' => 'pic_hd_height', 'pictures.pic_status' => 'pic_status', 'pictures.pic_comment_count' => 'pic_comment_count', 'pictures.pic_display_path' => 'pic_display_path', 'pictures.pic_display_width' => 'pic_display_width', 'pictures.pic_display_height' => 'pic_display_height'], ['AND' => ['gallery.gallery_status' => 1, 'gallery.users_id' => $user->getId()], 'ORDER' => 'gallery.id DESC', 'LIMIT' => [$this->count['number'] * ($this->count['page'] - 1), $this->count['number']]]); $this->parseList($list); return $list; }
private function initUser($ids) { $idl = []; foreach ($ids as $v) { if (!User::UserStack($v)) { $idl[$v] = $v; } } unset($ids); if (reset($idl)) { $list = $this->db->select("users", ['id' => 'id', 'user_name' => 'name', 'user_aliases' => 'aliases', 'user_email' => 'email', 'user_url' => 'url', 'user_status' => 'status', 'user_registered_time' => 'registered_time', 'user_last_login_time' => 'last_login_time', 'user_avatar' => 'avatar'], ['id' => $idl]); if ($list === false) { Log::write(_("Select other users error."), Log::SQL); } else { foreach ($list as &$v) { //保存数据到堆栈 new User($v, true); } } } }
echo $info['front_cover']['pic_thumbnails_url']; ?> " alt=""/></div> <?php } ?> <div class="time"><span class="glyphicon-time glyphicon"></span><?php echo $info['time']; ?> </div> </div> <?php break; case 'sharepicture': if ($info['share_users_id'] != $info['object_users_id']) { $ou = \ULib\User::getUser($info['object_users_id']); $other = "<a rel='external' href='" . user_link($ou->getName()) . "'>" . $ou->getAliases() . "</a> "; } ?> <div id="Share_<?php echo $id; ?> " class="s_picture share_box"> <button class="close" type="button">×</button> <h4><span>[<?php echo $id; ?> ]</span>分享了<?php echo $other; ?> 图片