├── README.md ├── config.php ├── control ├── controlbase.php ├── index.php └── user.php ├── data └── view │ ├── default_footer.tpl.php │ ├── default_header.tpl.php │ ├── default_index.tpl.php │ ├── default_login.tpl.php │ ├── default_register.tpl.php │ └── default_space.tpl.php ├── html ├── index.htm ├── index2.htm ├── login.htm ├── register.htm ├── space.htm └── static │ ├── css │ ├── bootstrap-admin-theme.css │ ├── bootstrap-dialog.css │ ├── bootstrap-theme.css │ ├── bootstrap-theme.min.css │ ├── bootstrap.css │ ├── bootstrap.min.css │ └── mybase.css │ ├── fonts │ ├── glyphicons-halflings-regular.eot │ ├── glyphicons-halflings-regular.svg │ ├── glyphicons-halflings-regular.ttf │ └── glyphicons-halflings-regular.woff │ └── js │ ├── bootstrap-dialog.js │ ├── bootstrap.js │ ├── bootstrap.min.js │ ├── holder.min.js │ └── jquery.min.js ├── index.php ├── lib ├── cache.class.php ├── encoding │ ├── big5-gb.table │ ├── big5-unicode.table │ ├── gb-big5.table │ ├── gb-unicode.table │ └── pinyin.dat ├── global.func.php ├── iconv.func.php ├── simple_html_dom.php ├── template.func.php └── zip.class.php ├── model ├── setting.class.php ├── user.class.php └── weibo.class.php ├── session ├── s1.php └── s2.php ├── static ├── css │ ├── bootstrap-admin-theme.css │ ├── bootstrap-dialog.css │ ├── bootstrap-theme.css │ ├── bootstrap-theme.min.css │ ├── bootstrap.css │ ├── bootstrap.min.css │ └── mybase.css ├── fonts │ ├── glyphicons-halflings-regular.eot │ ├── glyphicons-halflings-regular.svg │ ├── glyphicons-halflings-regular.ttf │ └── glyphicons-halflings-regular.woff ├── img │ ├── ajax-loader.gif │ ├── android.png │ ├── banner_1.png │ ├── code.png │ ├── diy.png │ ├── iconv.png │ ├── ios.png │ ├── jiaoyou.png │ ├── logo.gif │ ├── news.png │ ├── page.png │ ├── phone.png │ ├── preview.png │ └── xiaohua.png └── js │ ├── bootstrap-dialog.js │ ├── bootstrap.js │ ├── bootstrap.min.js │ ├── holder.min.js │ └── jquery.min.js ├── view └── default │ ├── footer.html │ ├── header.html │ ├── index.html │ ├── login.html │ ├── register.html │ └── space.html ├── 微博html.zip └── 微博数据存储.png /README.md: -------------------------------------------------------------------------------- 1 | php_redis_weibo 2 | =============== 3 | 4 | 基于redis的微博demo 5 | 6 | redis存储结构参考"微博数据存储.png" 7 | 静态页面模版参考 “微博html.zip” 8 | -------------------------------------------------------------------------------- /config.php: -------------------------------------------------------------------------------- 1 | 'default', 16 | 'cookie_pre'=>'t_', 17 | 'cookie_domain'=>'', 18 | 'time_friendly'=>1, 19 | 'date_format'=>'Y-m-d', 20 | 'time_format'=>'H:i', 21 | 'time_offset'=> 0, 22 | 'time_diff'=> 0, 23 | ); 24 | -------------------------------------------------------------------------------- /control/controlbase.php: -------------------------------------------------------------------------------- 1 | time = time(); 18 | $this->ip = getip(); 19 | $this->get = $get; 20 | $this->post = $post; 21 | $this->init_db(); 22 | //$this->init_cache(); 23 | $this->init_user(); 24 | } 25 | 26 | /* 27 | $eventlist=$this('event')->findAll(); 28 | 本特性只在PHP 5.3.0 及以上版本有效。 29 | */ 30 | function __invoke($modelname, $base = NULL) { 31 | $base = $base ? $base : $this; 32 | if (empty($_ENV[$modelname])) { 33 | $modelfile= APP_ROOT.'/model/'.$modelname.'.class.php'; 34 | //动态创建model类,一般的通用model无需再创建。 35 | if(false===@include($modelfile)) { 36 | // echo $modelname; 37 | eval('class '.$modelname.'model {}'); 38 | } 39 | eval('$_ENV[$modelname] = new ' . $modelname . 'model($base);'); 40 | } 41 | return $_ENV[$modelname]; 42 | } 43 | 44 | function init_db() { 45 | try { 46 | $redis = new Redis(); 47 | $redis->connect( REDIS_HOST, REDIS_PORT ); //php客户端设置的ip及端口 48 | $redis->select( REDIS_INDEX ); 49 | $this->redis = $redis ; 50 | } catch(RedisException $e) { 51 | exit("Redis连接失败,请检查服务是否正常!"); 52 | } 53 | } 54 | 55 | 56 | 57 | /* 一旦setting的缓存文件读取失败,则更新所有cache */ 58 | 59 | function init_cache() { 60 | global $setting; 61 | $this->cache = new cache($this->db); 62 | $setting = $this->setting = $this->cache->load('setting'); 63 | } 64 | 65 | function init_user() { 66 | @$auth = tcookie('auth'); 67 | $user = array('uid'=>0); 68 | @list($uid, $password) = empty($auth) ? array(0, 0) : taddslashes(explode("\t", strcode($auth, AUTH_KEY, 'DECODE')), 1); 69 | if ($uid && $password) { 70 | $finduser = $this('user')->findById($uid); 71 | $finduser && ($password == $finduser['password']) && $user = $finduser; 72 | } 73 | $user['ip'] = $this->ip; 74 | $this->user = $user; 75 | } 76 | 77 | /* 权限检测 */ 78 | function checkable($regular) { 79 | return 1; 80 | } 81 | 82 | 83 | /*中转提示页面 84 | $ishtml=1 表示是跳转到静态网页 85 | */ 86 | function message($message, $url = '') { 87 | $url= $url ? $url : SITE_URL ; 88 | header('location:'.$url); 89 | exit; 90 | } 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | } -------------------------------------------------------------------------------- /control/index.php: -------------------------------------------------------------------------------- 1 | getTimeLine($this->user['uid']); 9 | include template('index'); 10 | } 11 | 12 | function onindex() { 13 | $this->ondefault(); 14 | } 15 | 16 | function onpost() { 17 | $title='发微博'; 18 | $content=htmlspecialchars($this->post['content']); 19 | $this('weibo')->add($content); 20 | $this->message('发微博成功!', '?c=index'); 21 | } 22 | 23 | 24 | 25 | /*function oneveryday() { 26 | $title='每日一题'; 27 | include template('everyday'); 28 | }*/ 29 | 30 | 31 | 32 | 33 | 34 | 35 | } -------------------------------------------------------------------------------- /control/user.php: -------------------------------------------------------------------------------- 1 | post['submit'])) { 11 | $username = $user['username']=trim($this->post['username']); 12 | $user['email']=trim($this->post['email']); 13 | 14 | $finduser=$this('user')->findByUsername($username); 15 | if($finduser) $this->message("用户名 $username 已经注册!", 'c=user&a=register'); 16 | 17 | $user['posts'] = 0; //微博数为 0 18 | $user['fans'] = 0; //粉丝数为 0 19 | $user['regip'] = $this->ip; 20 | $user['regtime'] = $this->time; 21 | $user['password'] = md5($this->post['password']); 22 | $user['uid'] = $this('user')->getNextUid(); 23 | 24 | $this('user')->insert($user); 25 | $this('user')->refresh($user); 26 | 27 | header('location:?c=index'); 28 | 29 | } else { 30 | include template('register'); 31 | } 32 | } 33 | 34 | function onlogin() { 35 | $title = '登录'; 36 | $forward = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : SITE_URL; 37 | if (isset($this->post['submit'])) { 38 | $username=$this->post['username']; 39 | $password=md5($this->post['password']); 40 | 41 | $user=$this('user')->findByUsername($username); 42 | 43 | if(is_array($user)&&($password==$user['password'])){ 44 | $this('user')->refresh($user); 45 | $this->message('登录成功!', '?c=index'); 46 | }else{ 47 | $this->message('登录失败!', '?c=user&a=login'); 48 | } 49 | } 50 | include template('login'); 51 | } 52 | 53 | 54 | 55 | 56 | /* 退出系统 */ 57 | function onlogout() { 58 | $title = '登出系统'; 59 | $forward = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : SITE_URL; 60 | $this('user')->logout(); 61 | header('location:?c=index'); 62 | } 63 | 64 | 65 | 66 | /* 用户空间 */ 67 | function onspace() { 68 | $title = '用户空间'; 69 | $uid=$this->get['uid']; 70 | $userInfo=$this('user')->findById($uid); 71 | $postList = $this('weibo')->getUserPosts($uid); 72 | include template('space'); 73 | } 74 | 75 | /* 关注 */ 76 | function onfollow() { 77 | $title = '关注用户'; 78 | $uid=$this->get['uid']; 79 | $targetUser=$this('user')->findById($uid); 80 | if( 0 != $this->user['uid']){ 81 | $this('user')->follow($targetUser,$this->user); 82 | } 83 | $this->message('关注成功!', '?c=user&a=space&uid='.$targetUser['uid']); 84 | } 85 | 86 | /* 取消关注 */ 87 | function onunfollow() { 88 | $title = '取消关注'; 89 | $uid=$this->get['uid']; 90 | $targetUser=$this('user')->findById($uid); 91 | if( 0 != $this->user['uid']){ 92 | $this('user')->unfollow($targetUser,$this->user); 93 | } 94 | $this->message('取消关注成功!', '?c=user&a=space&uid='.$targetUser['uid']); 95 | } 96 | 97 | 98 | 99 | /* 修改密码 */ 100 | function onuppass() { 101 | 102 | } 103 | 104 | /* 修改头像 */ 105 | function onupimg() { 106 | 107 | } 108 | 109 | } -------------------------------------------------------------------------------- /data/view/default_footer.tpl.php: -------------------------------------------------------------------------------- 1 | if(!defined('IN_APP')) exit('Access Denied'); ?> 2 |
3 |