Esempio n. 1
0
 static function CreatePost($wall, $title, $content, $creator)
 {
     try {
         $safeWall = ensureInt($wall, 10);
         $safeTitle = '\'' . ensureString($title, 100, false) . '\'';
         $safeContent = '\'' . ensureString($content, 10000) . '\'';
         $safeCreator = ensureInt($creator, 10);
     } catch (Exception $e) {
         throw new Exception('创建墙贴时失败:' . $e->getMessage());
         return null;
     }
     $sql = "insert into wa_post (`post_wall`, `post_title`, `post_content`, `post_creator`) values ({$safeWall}, {$safeTitle}, {$safeContent}, {$safeCreator})";
     $ret = runSql($sql);
     if (!$ret) {
         throw new Exception('创建墙贴时失败。');
         return null;
     }
     $lastId = lastId();
     $cacheKey = 'wallpost_' . $safeWall;
     $cache = getCache($cacheKey);
     if ($cache) {
         array_unshift($cache, array('post_id' => $lastId));
     }
     setCache($cacheKey, $cache);
     return $lastId;
 }
Esempio n. 2
0
 public static function CreateComment($creator, $post, $content, $replyto)
 {
     try {
         $safeCreator = ensureInt($creator, 10);
         $safePost = ensureInt($post, 10);
         $safeContent = '\'' . ensureString($content, 1000) . '\'';
         $safeReplyto = '\'' . ensureString($replyto, 10, false, true) . '\'';
     } catch (Exception $e) {
         throw new Exception('创建回复时出错:' . $e->getMessage());
         return null;
     }
     $sql = "insert into wa_comment (`comment_creator`, `comment_post`, `comment_content`, `comment_replyto`) values ({$safeCreator}, {$safePost}, {$safeContent}, {$safeReplyto});";
     $result = runSql($sql);
     if (!$result) {
         throw new Exception('创建回复时出错。');
         return null;
     }
     $cacheKey = 'postcomment_' . $safePost;
     $cache = setCache($cacheKey, null);
     $ret = lastId();
     return $ret;
 }
Esempio n. 3
0
 public static function CreateUser($email, $pass, $name, $access)
 {
     try {
         $safeEmail = ensureString($email, 32);
         $safePass = ensureString($pass, 40);
         $safeName = ensureString($name, 20);
         $safeAccess = ensureInt($access, 2);
     } catch (Exception $e) {
         throw new Exception('创建用户时出错:' . $e->getMessage());
         return false;
     }
     $sqlInfo = "insert into wa_user (`user_email`, `user_pass`, `user_name`, `user_access`) values ('{$safeEmail}', '{$safePass}', '{$safeName}', {$safeAccess});";
     if (!runSql($sqlInfo)) {
         throw new Exception("创建用户时出错:{$name。}");
         return null;
     }
     $lastId = lastId();
     if ($lastId < 1) {
         throw new Exception("创建用户时出错:{$name。}");
         return null;
     }
     $sqlData = "insert into wa_userdata (`user_id`, `user_exp`, `user_wealth`, `user_lastsign`) values ({$lastId}, 50, 6, '" . date('Y-m-d H:i:s', strtotime('-2 days')) . "');";
     $sqlProfile = "insert into wa_userprofile (`user_id`) values ({$lastId});";
     if (runSql($sqlData) & runSql($sqlProfile)) {
         $userCache = getCache('users');
         if ($userCache != null) {
             array_unshift($userCache, array('user_id' => $lastId));
             setCache('users', $userCache);
             return $lastId;
         }
     } else {
         throw new Exception("创建用户时出错:{$name。}");
         return null;
     }
     return $lastId;
 }
Esempio n. 4
0
 public static function CreateMsg($sender, $receiver, $content, $sysmsg = false)
 {
     try {
         $safeSender = ensureInt($sender, 10);
         $safeReceiver = ensureInt($receiver, 10);
         $safeContent = '\'' . ensureString($content, 1000) . '\'';
     } catch (Exception $e) {
         throw new Exception('创建消息失败:' . $e->getMessage());
         return null;
     }
     if (!$sysmsg) {
         WaDialog::CreateDialog($safeSender, $safeReceiver);
     }
     WaDialog::CreateDialog($safeReceiver, $safeSender);
     $msgSql = "insert into wa_msg (`msg_sender`, `msg_receiver`, `msg_content`) values ({$safeSender}, {$safeReceiver}, {$safeContent})";
     $result = runSql($msgSql);
     if (!$result) {
         throw new Exception('创建消息失败。');
         return null;
     }
     $lastId = lastId();
     $cacheKey = "userunreadmsg_{$safeReceiver}";
     $cache = getCache($cacheKey);
     if ($cache) {
         array_unshift($cache, array('msg_id' => $lastId));
         setCache($cacheKey, $cache);
     }
     /*$cacheKey = "usermsg_$safeReceiver";
     		$cache  =getCache($cacheKey);
     		if ($cache)
     		{
     			array_unshift($cache, array('msg_id' => $lastId));
     			setCache($cacheKey, $cache);
     		}
     		$cacheKey = 'userunreadmsg_' . $safeReceiver;*/
     $cacheKey = "usermsg_{$safeSender_}{$safeReceiver}";
     $cache = getCache($cacheKey);
     if ($cache) {
         array_unshift($cache, array('msg_id' => $lastId));
         setCache($cacheKey, $cache);
     }
     $cacheKey = "usermsg_{$safeReceiver_}{$safeSender}";
     $cache = getCache($cacheKey);
     if ($cache) {
         array_unshift($cache, array('msg_id' => $lastId));
         setCache($cacheKey, $cache);
     }
     return $lastId;
 }
Esempio n. 5
0
 public static function AddUserToWall($user, $id)
 {
     try {
         $safeUser = ensureInt($user, 10);
         $safeId = ensureInt($id, 10);
     } catch (Exception $e) {
         throw new Exception('墙添加用户失败:' . $e->getMessage());
         return null;
     }
     $cacheKey = 'userwall_' . $safeUser;
     $cache = getCache($cacheKey);
     if ($cache) {
         array_unshift($cache, array('wall_id' => $safeId));
         setCache($cacheKey, $cache);
     }
     $cacheKey = 'walluser_' . $safeId;
     $cache = getCache($cacheKey);
     if ($cache) {
         array_unshift($cache, array('user_id' => $safeUser));
         setCache($cacheKey, $cache);
     }
     $sql = "insert into wa_walluser (`user_id`, `wall_id`) values ({$safeUser}, {$safeId});";
     $result = runSql($sql);
     if (!$result) {
         throw new Exception('墙添加用户失败。');
         return null;
     }
     $lastId = lastId();
     if (!$lastId) {
         throw new Exception('墙添加用户失败。');
         return null;
     }
     return $lastId;
 }