Changeset 20338
- Timestamp:
- 10/01/08 07:41:06 (3 months ago)
- Location:
- events/phpframework/plain_php/trunk/model
- Files:
-
- 2 added
- 5 modified
-
mail (added)
-
mail/mail.php (added)
-
phwittr/AcountService.php (modified) (6 diffs)
-
phwittr/FriendshipService.php (modified) (1 diff)
-
phwittr/PhwittrFront.php (modified) (2 diffs)
-
phwittr/StatusService.php (modified) (2 diffs)
-
phwittr/TimelineService.php (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
events/phpframework/plain_php/trunk/model/phwittr/AcountService.php
r20036 r20338 3 3 class AcountService 4 4 { 5 /** 6 * @var PDO 7 */ 5 8 protected $pdo; 6 9 … … 36 39 $smt->bindValue(':delete_flag', $delete_flag, PDO::PARAM_INT); 37 40 $smt->execute(); 38 return $smt->rowCount() === 1 ? true : false;41 return $smt->rowCount() === 1; 39 42 } 40 43 function updatePicture($user_id, $image) … … 50 53 } 51 54 $smt->execute(); 52 return $smt->rowCount() === 1 ? true : false;55 return $smt->rowCount() === 1; 53 56 } 54 57 function updatePassword($user_id, $password) … … 61 64 $smt->bindValue(':password', $password, PDO::PARAM_STR); 62 65 $smt->execute(); 63 return $smt->rowCount() === 1 ? true : false;66 return $smt->rowCount() === 1; 64 67 } 65 68 function updateEmail($user_id, $email) … … 70 73 $smt->bindValue(':email', $email, PDO::PARAM_STR); 71 74 $smt->execute(); 72 return $smt->rowCount() === 1 ? true : false;75 return $smt->rowCount() === 1; 73 76 } 74 77 … … 94 97 $smt->bindValue(':act_key', $act_key, PDO::PARAM_STR); 95 98 $smt->execute(); 96 return $smt->rowCount() === 1 ? true : false;99 return $smt->rowCount() === 1; 97 100 } 98 101 99 102 function setPrivate($user_id) 100 103 { 101 // @todo 後で実装する 102 return true; 104 $smt = $this->pdo->prepare(' 105 update users set private_flag = 1 where id = :user_id limit 1 106 '); 107 $smt->bindValue(':user_id', $user_id, PDO::PARAM_INT); 108 $smt->execute(); 109 return $smt->rowCount() === 1; 103 110 } 104 111 function setPublic($user_id) 105 112 { 106 // @todo 後で実装する 113 $this->pdo->beginTransaction(); 114 115 $smt = $this->pdo->prepare(' 116 update users set private_flag = 0 where id = :user_id limit 1 117 '); 118 $smt->bindValue(':user_id', $user_id, PDO::PARAM_INT); 119 $smt->execute(); 120 121 if (!$smt->rowCount() === 1) { 122 $this->pdo->rollBack(); 123 return false; 124 } 125 126 $smt = $this->pdo->prepare(' 127 select * from requests 128 where request_id = :user_id 129 '); 130 $smt->bindValue(':user_id', $user_id, PDO::PARAM_INT); 131 $smt->execute(); 132 $arr = $smt->fetchAll(PDO::FETCH_ASSOC); // $user_idをリクエストしている行列を得る 133 if ($arr == false) { 134 $this->pdo->commit(); 135 return true; 136 } 137 138 foreach ($arr as $r) { 139 $smt = $this->pdo->prepare(' 140 insert into 141 followers(user_id, follow_id, created_at) 142 values(:user_id, :follow_id, NOW()) 143 '); 144 $smt->bindValue(':user_id', $r['user_id'], PDO::PARAM_INT); 145 $smt->bindValue(':follow_id', $user_id, PDO::PARAM_INT); 146 $smt->execute(); 147 } 148 149 $smt = $this->pdo->prepare(' 150 delete from requests where request_id = :user_id 151 '); 152 $smt->bindValue(':user_id', $user_id, PDO::PARAM_INT); 153 $smt->execute(); 154 155 $this->pdo->commit(); 107 156 return true; 108 157 } -
events/phpframework/plain_php/trunk/model/phwittr/FriendshipService.php
r20036 r20338 80 80 } 81 81 82 function follow($user_id, $follow_user_ name)82 function follow($user_id, $follow_user_id) 83 83 { 84 84 $smt = $this->pdo->prepare(' 85 85 insert into followers(user_id, follow_id, created_at) 86 values(:user_id, (select id from users where user_name = 87 :follow_user_name), now())'); 86 values(:user_id, :follow_user_id, now())'); 88 87 $smt->bindValue(':user_id', $user_id, PDO::PARAM_INT); 89 $smt->bindValue(':follow_user_ name', $follow_user_name, PDO::PARAM_STR);88 $smt->bindValue(':follow_user_id', $follow_user_id, PDO::PARAM_INT); 90 89 $smt->execute(); 91 90 } 92 91 93 function unfollow($user_id, $follow_user_name) 92 function request($user_id, $request_user_id) 93 { 94 $smt = $this->pdo->prepare(' 95 insert into requests(user_id, request_id, created_at) 96 values(:user_id, :request_user_id, now()) 97 '); 98 $smt->bindValue(':user_id', $user_id, PDO::PARAM_INT); 99 $smt->bindValue(':request_user_id', $request_user_id, PDO::PARAM_INT); 100 $smt->execute(); 101 } 102 103 function accept($user_id, $accept_user_id) 104 { 105 $this->pdo->beginTransaction(); 106 $this->deny($user_id, $accept_user_id); 107 $this->follow($accept_user_id, $user_id); 108 $this->pdo->commit(); 109 } 110 111 function deny($user_id, $deny_user_id) 112 { 113 $smt = $this->pdo->prepare( 114 'delete from requests where user_id = :deny_user_id and ' . 115 'request_id = :user_id'); 116 $smt->bindValue(':user_id', $user_id, PDO::PARAM_INT); 117 $smt->bindValue(':deny_user_id', $deny_user_id, PDO::PARAM_INT); 118 $smt->execute(); 119 } 120 121 function unfollow($user_id, $follow_user_id) 94 122 { 95 123 $smt = $this->pdo->prepare( 96 124 'delete from followers where user_id = :user_id and ' . 97 'follow_id = (select id from users where user_name = :follow_user_name)');125 'follow_id = :follow_user_id'); 98 126 $smt->bindValue(':user_id', $user_id, PDO::PARAM_INT); 99 $smt->bindValue(':follow_user_ name', $follow_user_name, PDO::PARAM_STR);127 $smt->bindValue(':follow_user_id', $follow_user_id, PDO::PARAM_INT); 100 128 $smt->execute(); 101 129 } 102 130 103 131 function isFollowing($user_id, $follow_id) 132 { 133 $smt = $this->pdo->prepare(' 134 select followers.user_id 135 from followers 136 where user_id = :user_id and follow_id = :follow_id 137 limit 1 138 '); 139 $smt->bindValue(':user_id', $user_id, PDO::PARAM_INT); 140 $smt->bindValue(':follow_id', $follow_id, PDO::PARAM_INT); 141 $smt->execute(); 142 143 return $smt->fetch(PDO::FETCH_ASSOC) !== false; 144 } 145 function isRequesting($user_id, $follow_id) 146 { 147 $smt = $this->pdo->prepare(' 148 select requests.user_id 149 from requests 150 where user_id = :user_id and request_id = :follow_id 151 limit 1 152 '); 153 $smt->bindValue(':user_id', $user_id, PDO::PARAM_INT); 154 $smt->bindValue(':follow_id', $follow_id, PDO::PARAM_INT); 155 $smt->execute(); 156 157 return $smt->fetch(PDO::FETCH_ASSOC) !== false; 158 } 104 159 } -
events/phpframework/plain_php/trunk/model/phwittr/PhwittrFront.php
r20036 r20338 39 39 '/(home|replies|public_timeline)' 40 40 => 'TimelineAction' , 41 '/public_timeline/rss' 42 => 'PublicTimelineRssAction' , 41 43 '/status/update' 42 44 => 'StatusUpdateAction' , 45 '/status/update/ajax' 46 => 'StatusUpdateAjaxAction' , 43 47 '/status/delete/([0-9]+)/([[:word:]]+)' 44 48 => 'StatusDeleteAction' , … … 51 55 '/friendships/create/([0-9]+)/([[:word:]]+)' 52 56 => 'FollowAction' , 53 '/friendships/de lete/([0-9]+)/([[:word:]]+)'57 '/friendships/destroy/([0-9]+)/([[:word:]]+)' 54 58 => 'RemoveAction' , 55 '/friend_requests/accept/[0-9]+' 56 => 'RequestAcceptAction' , 57 '/friend_requests/deny/[0-9]+' 58 => 'RequestDenyAction' , 59 '/friend_requests/(accept|deny)/([0-9]+)/([[:word:]]+)' 60 => 'RequestHandleAction' , 59 61 '/?' 60 62 => 'DefaultAction' , 61 63 '/([[:word:]]+)' 62 64 => 'UserAction', 65 '/([[:word:]]+)/rss' 66 => 'UserRssAction', 63 67 '/([[:word:]]+)/friends' 64 68 => 'UserFriendsAction', -
events/phpframework/plain_php/trunk/model/phwittr/StatusService.php
r20036 r20338 4 4 { 5 5 protected $pdo; 6 function __construct(PDO $pdo )6 function __construct(PDO $pdo, $base_url) 7 7 { 8 8 $this->pdo = $pdo; 9 $this->baseUrl = $base_url; 9 10 } 10 11 function reply($user_id, $comment, $reply_user_id) … … 48 49 $smt->execute(); 49 50 50 return $smt->fetch(PDO::FETCH_ASSOC); 51 $s = $smt->fetch(PDO::FETCH_ASSOC); 52 53 if ($s) $s = $this->processStatus($s); 54 return $s; 51 55 } 52 56 protected function processStatus($status) 57 { 58 $status['title_comment'] = h($status['comment']); 59 $status['comment'] = preg_replace('#(https?://[[:alnum:]+$;?.%,!\#~*/:@&=_-]+)#', '<a href="$1">$1</a>' , h($status['comment'])); 60 $status['comment'] = preg_replace('#@([[:word:]]{1,30})#', 61 '@<a href="' . $this->baseUrl . '/$1">$1</a>', 62 $status['comment']); 63 return $status; 64 } 53 65 } 54 66 -
events/phpframework/plain_php/trunk/model/phwittr/TimelineService.php
r20036 r20338 3 3 class TimelineService 4 4 { 5 protected $pdo, $ context;6 function __construct(PDO $pdo, ApplicationContext $context)5 protected $pdo, $baseUrl; 6 function __construct(PDO $pdo, $base_url) 7 7 { 8 8 $this->pdo = $pdo; 9 $this-> context = $context;9 $this->baseUrl = $base_url; 10 10 } 11 11 function fetchPublicTimeline($offset, $limit) … … 55 55 { 56 56 $smt = $this->pdo->prepare(' 57 select statuses.* from statuses57 select statuses.*, users.user_name, users.image from statuses 58 58 left join users on users.id = statuses.user_id where users.id = :user_id 59 59 order by statuses.created_at desc … … 92 92 select count(users.id) 93 93 from statuses left join users on users.id = statuses.user_id 94 left join followers f1 on f1.user_id = users.id95 96 where users.delete_flag = 0 and f1. follow_id = :user_id97 or users.id = :user_id ');94 left join (select * from followers where user_id = :user_id) f1 on f1.follow_id = users.id 95 96 where users.delete_flag = 0 and f1.user_id = :user_id 97 or users.id = :user_id '); 98 98 99 99 $smt->bindValue(':user_id', $user_id, PDO::PARAM_INT); … … 105 105 select users.user_name, users.image, statuses.* 106 106 from statuses left join users on users.id = statuses.user_id 107 left join followers f1 on f1.user_id = users.id107 left join (select * from followers where user_id = :user_id) f1 on f1.follow_id = users.id 108 108 109 where users.delete_flag = 0 and f1. follow_id = :user_id109 where users.delete_flag = 0 and f1.user_id = :user_id 110 110 or users.id = :user_id 111 111 … … 138 138 $status['comment'] = preg_replace('#(https?://[[:alnum:]+$;?.%,!\#~*/:@&=_-]+)#', '<a href="$1">$1</a>' , h($status['comment'])); 139 139 $status['comment'] = preg_replace('#@([[:word:]]{1,30})#', 140 '@<a href="' . $this-> context->baseUrl . '/$1">$1</a>',140 '@<a href="' . $this->baseUrl . '/$1">$1</a>', 141 141 $status['comment']); 142 142 return $status;
![(please configure the [header_logo] section in trac.ini)](/share/chrome/site/your_project_logo.png)