@@ -19,7 +19,7 @@ discard block |
||
| 19 | 19 | $this->user_friends_table = $user_friends_table; |
| 20 | 20 | } |
| 21 | 21 | |
| 22 | - public function getFriends() |
|
| 22 | + public function getFriends() |
|
| 23 | 23 | { |
| 24 | 24 | $sql = " |
| 25 | 25 | SELECT u.user_id, |
@@ -44,7 +44,7 @@ discard block |
||
| 44 | 44 | 'user_id' => $row['user_id'], |
| 45 | 45 | 'username' => $row['username_clean'], |
| 46 | 46 | 'user_colour' => $row['user_colour'], |
| 47 | - 'user_status' => ($row['session_time'] >= (time() - ($this->config['load_online_time'] * 60))) ? 1 : 0, |
|
| 47 | + 'user_status' => ($row['session_time'] >= (time() - ($this->config['load_online_time'] * 60))) ? 1 : 0, |
|
| 48 | 48 | ); |
| 49 | 49 | } |
| 50 | 50 | $this->db->sql_freeresult(); |
@@ -106,9 +106,9 @@ discard block |
||
| 106 | 106 | } |
| 107 | 107 | } |
| 108 | 108 | |
| 109 | - public function get_request_by_sender_id($sender_id) |
|
| 110 | - { |
|
| 111 | - $sql = " |
|
| 109 | + public function get_request_by_sender_id($sender_id) |
|
| 110 | + { |
|
| 111 | + $sql = " |
|
| 112 | 112 | SELECT `request_id`, |
| 113 | 113 | `user_id`, |
| 114 | 114 | `sender_id`, |
@@ -120,11 +120,11 @@ discard block |
||
| 120 | 120 | ORDER BY `time` DESC |
| 121 | 121 | LIMIT 1 |
| 122 | 122 | "; |
| 123 | - $result = $this->db->sql_query($sql); |
|
| 124 | - $row = $this->db->sql_fetchrow($result); |
|
| 123 | + $result = $this->db->sql_query($sql); |
|
| 124 | + $row = $this->db->sql_fetchrow($result); |
|
| 125 | 125 | |
| 126 | 126 | return $row; |
| 127 | - } |
|
| 127 | + } |
|
| 128 | 128 | |
| 129 | 129 | public function insert_friends_request(array $data) { |
| 130 | 130 | $sql = " |
@@ -246,13 +246,13 @@ discard block |
||
| 246 | 246 | } |
| 247 | 247 | } |
| 248 | 248 | |
| 249 | - public function remove_friend($user_id) |
|
| 250 | - { |
|
| 251 | - $sql = "DELETE FROM ". $this->user_friends_table ." WHERE `user_id` = ". (int)$user_id .""; |
|
| 252 | - $this->db->sql_query($sql); |
|
| 249 | + public function remove_friend($user_id) |
|
| 250 | + { |
|
| 251 | + $sql = "DELETE FROM ". $this->user_friends_table ." WHERE `user_id` = ". (int)$user_id .""; |
|
| 252 | + $this->db->sql_query($sql); |
|
| 253 | 253 | |
| 254 | - $sql = "DELETE FROM ". $this->user_friends_table ." WHERE `friend_id` = ". (int)$user_id .""; |
|
| 255 | - $this->db->sql_query($sql); |
|
| 256 | - } |
|
| 254 | + $sql = "DELETE FROM ". $this->user_friends_table ." WHERE `friend_id` = ". (int)$user_id .""; |
|
| 255 | + $this->db->sql_query($sql); |
|
| 256 | + } |
|
| 257 | 257 | |
| 258 | 258 | } |
@@ -29,16 +29,16 @@ discard block |
||
| 29 | 29 | u.user_colour, |
| 30 | 30 | s.session_id, |
| 31 | 31 | s.session_time |
| 32 | - FROM ". $this->user_friends_table ." |
|
| 33 | - LEFT JOIN ". USERS_TABLE ." AS u ON u.user_id = ". $this->user_friends_table .".friend_id |
|
| 34 | - LEFT JOIN ". SESSIONS_TABLE ." AS s ON s.session_user_id = u.user_id |
|
| 35 | - WHERE ". $this->user_friends_table .".user_id = ". (int)$this->user->data['user_id'] ." |
|
| 32 | + FROM ". $this->user_friends_table." |
|
| 33 | + LEFT JOIN ". USERS_TABLE." AS u ON u.user_id = ".$this->user_friends_table.".friend_id |
|
| 34 | + LEFT JOIN ". SESSIONS_TABLE." AS s ON s.session_user_id = u.user_id |
|
| 35 | + WHERE ". $this->user_friends_table.".user_id = ".(int)$this->user->data['user_id']." |
|
| 36 | 36 | GROUP BY u.user_id |
| 37 | 37 | "; |
| 38 | 38 | $result = $this->db->sql_query($sql); |
| 39 | 39 | |
| 40 | 40 | $friends = array(); |
| 41 | - while($row = $this->db->sql_fetchrow($result)) |
|
| 41 | + while ($row = $this->db->sql_fetchrow($result)) |
|
| 42 | 42 | { |
| 43 | 43 | $friends[] = array( |
| 44 | 44 | 'user_id' => $row['user_id'], |
@@ -63,15 +63,15 @@ discard block |
||
| 63 | 63 | `sender_id`, |
| 64 | 64 | `status`, |
| 65 | 65 | `time` |
| 66 | - FROM ". $this->friends_request_table ." |
|
| 67 | - WHERE `user_id` = ". (int)$this->user->data['user_id'] ." |
|
| 66 | + FROM ". $this->friends_request_table." |
|
| 67 | + WHERE `user_id` = ". (int)$this->user->data['user_id']." |
|
| 68 | 68 | AND `status` = 0 |
| 69 | 69 | ORDER BY `time` DESC |
| 70 | 70 | "; |
| 71 | 71 | |
| 72 | 72 | $result = $this->db->sql_query($sql); |
| 73 | 73 | |
| 74 | - while($row = $this->db->sql_fetchrow($result)) |
|
| 74 | + while ($row = $this->db->sql_fetchrow($result)) |
|
| 75 | 75 | { |
| 76 | 76 | $requests[] = $row; |
| 77 | 77 | } |
@@ -87,8 +87,8 @@ discard block |
||
| 87 | 87 | `sender_id`, |
| 88 | 88 | `status`, |
| 89 | 89 | `time` |
| 90 | - FROM ". $this->friends_request_table ." |
|
| 91 | - WHERE `request_id` = ". (int)$id ." |
|
| 90 | + FROM ". $this->friends_request_table." |
|
| 91 | + WHERE `request_id` = ". (int)$id." |
|
| 92 | 92 | AND `status` = 0 |
| 93 | 93 | ORDER BY `time` DESC |
| 94 | 94 | LIMIT 1 |
@@ -96,7 +96,7 @@ discard block |
||
| 96 | 96 | $result = $this->db->sql_query($sql); |
| 97 | 97 | $row = $this->db->sql_fetchrow($result); |
| 98 | 98 | |
| 99 | - if($this->approve_friend_request($id)) |
|
| 99 | + if ($this->approve_friend_request($id)) |
|
| 100 | 100 | { |
| 101 | 101 | return $row; |
| 102 | 102 | } |
@@ -114,8 +114,8 @@ discard block |
||
| 114 | 114 | `sender_id`, |
| 115 | 115 | `status`, |
| 116 | 116 | `time` |
| 117 | - FROM ". $this->friends_request_table ." |
|
| 118 | - WHERE `sender_id` = ". (int)$sender_id ." |
|
| 117 | + FROM ". $this->friends_request_table." |
|
| 118 | + WHERE `sender_id` = ". (int)$sender_id." |
|
| 119 | 119 | AND `status` = 0 |
| 120 | 120 | ORDER BY `time` DESC |
| 121 | 121 | LIMIT 1 |
@@ -128,7 +128,7 @@ discard block |
||
| 128 | 128 | |
| 129 | 129 | public function insert_friends_request(array $data) { |
| 130 | 130 | $sql = " |
| 131 | - INSERT INTO " . $this->friends_request_table . " |
|
| 131 | + INSERT INTO " . $this->friends_request_table." |
|
| 132 | 132 | ( |
| 133 | 133 | `user_id`, |
| 134 | 134 | `sender_id`, |
@@ -137,21 +137,21 @@ discard block |
||
| 137 | 137 | ) |
| 138 | 138 | VALUES |
| 139 | 139 | ( |
| 140 | - " . ( int ) $data ['user_id'] . ", |
|
| 141 | - " . ( int ) $data ['sender_id'] . ", |
|
| 140 | + " . (int)$data ['user_id'].", |
|
| 141 | + " . (int)$data ['sender_id'].", |
|
| 142 | 142 | 0, |
| 143 | - " . time () . " |
|
| 143 | + " . time()." |
|
| 144 | 144 | ) |
| 145 | 145 | "; |
| 146 | - $this->db->sql_query ( $sql ); |
|
| 146 | + $this->db->sql_query($sql); |
|
| 147 | 147 | |
| 148 | - return $this->db->sql_nextid (); |
|
| 148 | + return $this->db->sql_nextid(); |
|
| 149 | 149 | } |
| 150 | 150 | |
| 151 | 151 | public function delete_friend_request($request_id) |
| 152 | 152 | { |
| 153 | 153 | $sql = " |
| 154 | - DELETE FROM ". $this->friends_request_table ." WHERE `request_id` = ". (int)$request_id ." |
|
| 154 | + DELETE FROM ". $this->friends_request_table." WHERE `request_id` = ".(int)$request_id." |
|
| 155 | 155 | "; |
| 156 | 156 | |
| 157 | 157 | return $this->db->sql_query($sql); |
@@ -160,7 +160,7 @@ discard block |
||
| 160 | 160 | public function approve_friend_request($request_id) |
| 161 | 161 | { |
| 162 | 162 | $sql = " |
| 163 | - UPDATE ". $this->friends_request_table ." SET `status` = 1 WHERE `request_id` = ". (int)$request_id ." |
|
| 163 | + UPDATE ". $this->friends_request_table." SET `status` = 1 WHERE `request_id` = ".(int)$request_id." |
|
| 164 | 164 | "; |
| 165 | 165 | |
| 166 | 166 | return $this->db->sql_query($sql); |
@@ -170,21 +170,21 @@ discard block |
||
| 170 | 170 | { |
| 171 | 171 | |
| 172 | 172 | $check_friend = $this->check_friend($data); |
| 173 | - if($check_friend == false) |
|
| 173 | + if ($check_friend == false) |
|
| 174 | 174 | { |
| 175 | 175 | $sql = " |
| 176 | - INSERT INTO ". $this->user_friends_table ." |
|
| 176 | + INSERT INTO ". $this->user_friends_table." |
|
| 177 | 177 | ( |
| 178 | 178 | `user_id`, |
| 179 | 179 | `friend_id` |
| 180 | 180 | ) |
| 181 | 181 | VALUES |
| 182 | 182 | ( |
| 183 | - ". (int)$data['user_id'] .", |
|
| 184 | - ". (int)$data['friend_id'] ." |
|
| 183 | + ". (int)$data['user_id'].", |
|
| 184 | + ". (int)$data['friend_id']." |
|
| 185 | 185 | ) |
| 186 | 186 | "; |
| 187 | - if($this->db->sql_query($sql)) |
|
| 187 | + if ($this->db->sql_query($sql)) |
|
| 188 | 188 | { |
| 189 | 189 | $aux = $data['user_id']; |
| 190 | 190 | $data['user_id'] = $data['friend_id']; |
@@ -208,13 +208,13 @@ discard block |
||
| 208 | 208 | { |
| 209 | 209 | $sql = " |
| 210 | 210 | SELECT COUNT(*) AS `count` |
| 211 | - FROM ". $this->user_friends_table ." |
|
| 212 | - WHERE `user_id` = ". (int)$data['user_id'] ." |
|
| 213 | - AND `friend_id` = ". (int)$data['friend_id'] ." |
|
| 211 | + FROM ". $this->user_friends_table." |
|
| 212 | + WHERE `user_id` = ". (int)$data['user_id']." |
|
| 213 | + AND `friend_id` = ". (int)$data['friend_id']." |
|
| 214 | 214 | "; |
| 215 | 215 | $this->db->sql_query($sql); |
| 216 | 216 | $count = $this->db->sql_fetchfield('count'); |
| 217 | - if($count > 0) |
|
| 217 | + if ($count > 0) |
|
| 218 | 218 | { |
| 219 | 219 | return true; |
| 220 | 220 | } |
@@ -228,15 +228,15 @@ discard block |
||
| 228 | 228 | { |
| 229 | 229 | $sql = " |
| 230 | 230 | SELECT COUNT(*) AS `count` |
| 231 | - FROM ". $this->friends_request_table ." |
|
| 232 | - WHERE `user_id` = ". (int)$data['user_id'] ." |
|
| 233 | - AND `sender_id` = ". (int)$data['sender_id'] ." |
|
| 231 | + FROM ". $this->friends_request_table." |
|
| 232 | + WHERE `user_id` = ". (int)$data['user_id']." |
|
| 233 | + AND `sender_id` = ". (int)$data['sender_id']." |
|
| 234 | 234 | AND `status` = 0 |
| 235 | 235 | LIMIT 1 |
| 236 | 236 | "; |
| 237 | 237 | $this->db->sql_query($sql); |
| 238 | 238 | $count = $this->db->sql_fetchfield('count'); |
| 239 | - if($count > 0) |
|
| 239 | + if ($count > 0) |
|
| 240 | 240 | { |
| 241 | 241 | return true; |
| 242 | 242 | } |
@@ -248,10 +248,10 @@ discard block |
||
| 248 | 248 | |
| 249 | 249 | public function remove_friend($user_id) |
| 250 | 250 | { |
| 251 | - $sql = "DELETE FROM ". $this->user_friends_table ." WHERE `user_id` = ". (int)$user_id .""; |
|
| 251 | + $sql = "DELETE FROM ".$this->user_friends_table." WHERE `user_id` = ".(int)$user_id.""; |
|
| 252 | 252 | $this->db->sql_query($sql); |
| 253 | 253 | |
| 254 | - $sql = "DELETE FROM ". $this->user_friends_table ." WHERE `friend_id` = ". (int)$user_id .""; |
|
| 254 | + $sql = "DELETE FROM ".$this->user_friends_table." WHERE `friend_id` = ".(int)$user_id.""; |
|
| 255 | 255 | $this->db->sql_query($sql); |
| 256 | 256 | } |
| 257 | 257 | |
@@ -99,8 +99,7 @@ discard block |
||
| 99 | 99 | if($this->approve_friend_request($id)) |
| 100 | 100 | { |
| 101 | 101 | return $row; |
| 102 | - } |
|
| 103 | - else |
|
| 102 | + } else |
|
| 104 | 103 | { |
| 105 | 104 | return false; |
| 106 | 105 | } |
@@ -191,13 +190,11 @@ discard block |
||
| 191 | 190 | $data['friend_id'] = $aux; |
| 192 | 191 | |
| 193 | 192 | self::add_friend($data); |
| 194 | - } |
|
| 195 | - else |
|
| 193 | + } else |
|
| 196 | 194 | { |
| 197 | 195 | return false; |
| 198 | 196 | } |
| 199 | - } |
|
| 200 | - else |
|
| 197 | + } else |
|
| 201 | 198 | { |
| 202 | 199 | return false; |
| 203 | 200 | } |
@@ -217,8 +214,7 @@ discard block |
||
| 217 | 214 | if($count > 0) |
| 218 | 215 | { |
| 219 | 216 | return true; |
| 220 | - } |
|
| 221 | - else |
|
| 217 | + } else |
|
| 222 | 218 | { |
| 223 | 219 | return false; |
| 224 | 220 | } |
@@ -239,8 +235,7 @@ discard block |
||
| 239 | 235 | if($count > 0) |
| 240 | 236 | { |
| 241 | 237 | return true; |
| 242 | - } |
|
| 243 | - else |
|
| 238 | + } else |
|
| 244 | 239 | { |
| 245 | 240 | return false; |
| 246 | 241 | } |
@@ -124,7 +124,9 @@ |
||
| 124 | 124 | 'sender_id' => $user_id |
| 125 | 125 | )); |
| 126 | 126 | $check_widget = true; |
| 127 | - if ($user_id == $this->user->data['user_id']) $check_widget = false; |
|
| 127 | + if ($user_id == $this->user->data['user_id']) { |
|
| 128 | + $check_widget = false; |
|
| 129 | + } |
|
| 128 | 130 | $this->template->assign_vars(array( |
| 129 | 131 | 'U_USER_ID' => $user_id, |
| 130 | 132 | 'U_CHECK_FRIEND' => $check_friend, |
@@ -2401,7 +2401,7 @@ discard block |
||
| 2401 | 2401 | // useful for sending emojis back to mobile devices |
| 2402 | 2402 | static function shortnameToUnicode($string) { |
| 2403 | 2403 | $string = preg_replace_callback('/'.self::$ignoredRegexp.'|('.self::$shortcodeRegexp.')/Si', 'static::shortnameToUnicodeCallback', $string); |
| 2404 | - if(self::$ascii) { |
|
| 2404 | + if (self::$ascii) { |
|
| 2405 | 2405 | $string = preg_replace_callback('/'.self::$ignoredRegexp.'|((\\s|^)'.self::$asciiRegexp.'(?=\\s|$|[!,\.]))/S', 'static::asciiToUnicodeCallback', $string); |
| 2406 | 2406 | } |
| 2407 | 2407 | return $string; |
@@ -2414,7 +2414,7 @@ discard block |
||
| 2414 | 2414 | } |
| 2415 | 2415 | static function shortnameToImage($string) { |
| 2416 | 2416 | $string = preg_replace_callback('/'.self::$ignoredRegexp.'|('.self::$shortcodeRegexp.')/Si', 'static::shortnameToImageCallback', $string); |
| 2417 | - if(self::$ascii) { |
|
| 2417 | + if (self::$ascii) { |
|
| 2418 | 2418 | $string = preg_replace_callback('/'.self::$ignoredRegexp.'|((\\s|^)'.self::$asciiRegexp.'(?=\\s|$|[!,\.]))/S', 'static::asciiToImageCallback', $string); |
| 2419 | 2419 | } |
| 2420 | 2420 | return $string; |
@@ -2430,7 +2430,7 @@ discard block |
||
| 2430 | 2430 | // ######## preg_replace callbacks |
| 2431 | 2431 | // ########################################## |
| 2432 | 2432 | static function shortnameToAsciiCallback($m) { |
| 2433 | - if((!is_array($m)) || (!isset($m[1])) || (empty($m[1]))) { |
|
| 2433 | + if ((!is_array($m)) || (!isset($m[1])) || (empty($m[1]))) { |
|
| 2434 | 2434 | return $m[0]; |
| 2435 | 2435 | } |
| 2436 | 2436 | else { |
@@ -2438,7 +2438,7 @@ discard block |
||
| 2438 | 2438 | |
| 2439 | 2439 | $shortname = $m[0]; |
| 2440 | 2440 | |
| 2441 | - if(!isset(self::$shortcode_replace[$shortname])) { |
|
| 2441 | + if (!isset(self::$shortcode_replace[$shortname])) { |
|
| 2442 | 2442 | return $m[0]; |
| 2443 | 2443 | } |
| 2444 | 2444 | |
@@ -2448,7 +2448,7 @@ discard block |
||
| 2448 | 2448 | } |
| 2449 | 2449 | } |
| 2450 | 2450 | static function shortnameToUnicodeCallback($m) { |
| 2451 | - if((!is_array($m)) || (!isset($m[1])) || (empty($m[1]))) { |
|
| 2451 | + if ((!is_array($m)) || (!isset($m[1])) || (empty($m[1]))) { |
|
| 2452 | 2452 | return $m[0]; |
| 2453 | 2453 | } |
| 2454 | 2454 | else { |
@@ -2456,7 +2456,7 @@ discard block |
||
| 2456 | 2456 | |
| 2457 | 2457 | $shortname = $m[1]; |
| 2458 | 2458 | |
| 2459 | - if(!isset($flipped[$shortname])) { |
|
| 2459 | + if (!isset($flipped[$shortname])) { |
|
| 2460 | 2460 | return $m[0]; |
| 2461 | 2461 | } |
| 2462 | 2462 | |
@@ -2466,13 +2466,13 @@ discard block |
||
| 2466 | 2466 | } |
| 2467 | 2467 | } |
| 2468 | 2468 | static function shortnameToImageCallback($m) { |
| 2469 | - if((!is_array($m)) || (!isset($m[1])) || (empty($m[1]))) { |
|
| 2469 | + if ((!is_array($m)) || (!isset($m[1])) || (empty($m[1]))) { |
|
| 2470 | 2470 | return $m[0]; |
| 2471 | 2471 | } |
| 2472 | 2472 | else { |
| 2473 | 2473 | $shortname = $m[1]; |
| 2474 | 2474 | |
| 2475 | - if(!isset(self::$shortcode_replace[$shortname])) { |
|
| 2475 | + if (!isset(self::$shortcode_replace[$shortname])) { |
|
| 2476 | 2476 | return $m[0]; |
| 2477 | 2477 | } |
| 2478 | 2478 | |
@@ -2480,11 +2480,11 @@ discard block |
||
| 2480 | 2480 | $unicode = self::$shortcode_replace[$shortname]; |
| 2481 | 2481 | $filename = strtoupper($unicode); |
| 2482 | 2482 | |
| 2483 | - if(self::$unicodeAlt) { $alt = self::convert($unicode); } |
|
| 2483 | + if (self::$unicodeAlt) { $alt = self::convert($unicode); } |
|
| 2484 | 2484 | else { $alt = $shortname; } |
| 2485 | 2485 | |
| 2486 | - if(self::$imageType == 'png') { |
|
| 2487 | - if(self::$sprites) { |
|
| 2486 | + if (self::$imageType == 'png') { |
|
| 2487 | + if (self::$sprites) { |
|
| 2488 | 2488 | return '<span class="emojione-'.strtoupper($unicode).'" title="'.htmlspecialchars($shortname).'">'.$alt.'</span>'; |
| 2489 | 2489 | } |
| 2490 | 2490 | else { |
@@ -2492,7 +2492,7 @@ discard block |
||
| 2492 | 2492 | } |
| 2493 | 2493 | } |
| 2494 | 2494 | |
| 2495 | - if(self::$sprites) { |
|
| 2495 | + if (self::$sprites) { |
|
| 2496 | 2496 | return '<svg class="emojione"><description>'.$alt.'</description><use xlink:href="'.self::$imagePathSVGSprites.'#emoji-'.strtoupper($unicode).'"></use></svg>'; |
| 2497 | 2497 | } |
| 2498 | 2498 | else { |
@@ -2501,7 +2501,7 @@ discard block |
||
| 2501 | 2501 | } |
| 2502 | 2502 | } |
| 2503 | 2503 | static function asciiToUnicodeCallback($m) { |
| 2504 | - if((!is_array($m)) || (!isset($m[3])) || (empty($m[3]))) { |
|
| 2504 | + if ((!is_array($m)) || (!isset($m[3])) || (empty($m[3]))) { |
|
| 2505 | 2505 | return $m[0]; |
| 2506 | 2506 | } |
| 2507 | 2507 | else { |
@@ -2511,7 +2511,7 @@ discard block |
||
| 2511 | 2511 | } |
| 2512 | 2512 | } |
| 2513 | 2513 | static function asciiToImageCallback($m) { |
| 2514 | - if((!is_array($m)) || (!isset($m[3])) || (empty($m[3]))) { |
|
| 2514 | + if ((!is_array($m)) || (!isset($m[3])) || (empty($m[3]))) { |
|
| 2515 | 2515 | return $m[0]; |
| 2516 | 2516 | } |
| 2517 | 2517 | else { |
@@ -2519,11 +2519,11 @@ discard block |
||
| 2519 | 2519 | $unicode = self::$ascii_replace[$shortname]; |
| 2520 | 2520 | |
| 2521 | 2521 | // unicode char or shortname for the alt tag? (unicode is better for copying and pasting the resulting text) |
| 2522 | - if(self::$unicodeAlt) { $alt = self::convert($unicode); } |
|
| 2522 | + if (self::$unicodeAlt) { $alt = self::convert($unicode); } |
|
| 2523 | 2523 | else { $alt = htmlspecialchars($shortname); } |
| 2524 | 2524 | |
| 2525 | - if(self::$imageType == 'png') { |
|
| 2526 | - if(self::$sprites) { |
|
| 2525 | + if (self::$imageType == 'png') { |
|
| 2526 | + if (self::$sprites) { |
|
| 2527 | 2527 | return $m[2].'<span class="emojione-'.strtoupper($unicode).'" title="'.htmlspecialchars($shortname).'">'.$alt.'</span>'; |
| 2528 | 2528 | } |
| 2529 | 2529 | else { |
@@ -2531,7 +2531,7 @@ discard block |
||
| 2531 | 2531 | } |
| 2532 | 2532 | } |
| 2533 | 2533 | |
| 2534 | - if(self::$sprites) { |
|
| 2534 | + if (self::$sprites) { |
|
| 2535 | 2535 | return $m[2].'<svg class="emojione"><description>'.$alt.'</description><use xlink:href="'.self::$imagePathSVGSprites.'#emoji-'.strtoupper($unicode).'"></use></svg>'; |
| 2536 | 2536 | } |
| 2537 | 2537 | else { |
@@ -2540,14 +2540,14 @@ discard block |
||
| 2540 | 2540 | } |
| 2541 | 2541 | } |
| 2542 | 2542 | static function toShortCallback($m) { |
| 2543 | - if((!is_array($m)) || (!isset($m[1])) || (empty($m[1]))) { |
|
| 2543 | + if ((!is_array($m)) || (!isset($m[1])) || (empty($m[1]))) { |
|
| 2544 | 2544 | return $m[0]; |
| 2545 | 2545 | } |
| 2546 | 2546 | else { |
| 2547 | 2547 | $unicode = $m[1]; |
| 2548 | - if(!isset(self::$unicode_replace[$unicode])) { |
|
| 2548 | + if (!isset(self::$unicode_replace[$unicode])) { |
|
| 2549 | 2549 | $unicode = substr($m[1], 0, 4); |
| 2550 | - if(!isset(self::$unicode_replace[$unicode])) { |
|
| 2550 | + if (!isset(self::$unicode_replace[$unicode])) { |
|
| 2551 | 2551 | return $m[0]; |
| 2552 | 2552 | } |
| 2553 | 2553 | } |
@@ -2556,15 +2556,15 @@ discard block |
||
| 2556 | 2556 | } |
| 2557 | 2557 | } |
| 2558 | 2558 | static function unicodeToImageCallback($m) { |
| 2559 | - if((!is_array($m)) || (!isset($m[1])) || (empty($m[1]))) { |
|
| 2559 | + if ((!is_array($m)) || (!isset($m[1])) || (empty($m[1]))) { |
|
| 2560 | 2560 | return $m[0]; |
| 2561 | 2561 | } |
| 2562 | 2562 | else { |
| 2563 | 2563 | $unicode = $m[1]; |
| 2564 | 2564 | |
| 2565 | - if(!isset(self::$unicode_replace[$unicode])) { |
|
| 2565 | + if (!isset(self::$unicode_replace[$unicode])) { |
|
| 2566 | 2566 | $unicode = substr($m[1], 0, 4); |
| 2567 | - if(!isset(self::$unicode_replace[$unicode])) { |
|
| 2567 | + if (!isset(self::$unicode_replace[$unicode])) { |
|
| 2568 | 2568 | return $m[0]; |
| 2569 | 2569 | } |
| 2570 | 2570 | } |
@@ -2572,11 +2572,11 @@ discard block |
||
| 2572 | 2572 | $shortname = self::$unicode_replace[$unicode]; |
| 2573 | 2573 | $filename = strtoupper(self::$shortcode_replace[$shortname]); |
| 2574 | 2574 | |
| 2575 | - if(self::$unicodeAlt) { $alt = $unicode; } |
|
| 2575 | + if (self::$unicodeAlt) { $alt = $unicode; } |
|
| 2576 | 2576 | else { $alt = $shortname; } |
| 2577 | 2577 | |
| 2578 | - if(self::$imageType == 'png') { |
|
| 2579 | - if(self::$sprites) { |
|
| 2578 | + if (self::$imageType == 'png') { |
|
| 2579 | + if (self::$sprites) { |
|
| 2580 | 2580 | return '<span class="emojione-'.strtoupper($unicode).'" title="'.htmlspecialchars($shortname).'">'.$alt.'</span>'; |
| 2581 | 2581 | } |
| 2582 | 2582 | else { |
@@ -2584,7 +2584,7 @@ discard block |
||
| 2584 | 2584 | } |
| 2585 | 2585 | } |
| 2586 | 2586 | |
| 2587 | - if(self::$sprites) { |
|
| 2587 | + if (self::$sprites) { |
|
| 2588 | 2588 | return '<svg class="emojione"><description>'.$alt.'</description><use xlink:href="'.self::$imagePathSVGSprites.'#emoji-'.strtoupper($unicode).'"></use></svg>'; |
| 2589 | 2589 | } |
| 2590 | 2590 | else { |
@@ -2597,9 +2597,9 @@ discard block |
||
| 2597 | 2597 | // ######## helper methods |
| 2598 | 2598 | // ########################################## |
| 2599 | 2599 | static function convert($unicode) { |
| 2600 | - if(stristr($unicode,'-')) { |
|
| 2601 | - $pairs = explode('-',$unicode); |
|
| 2602 | - return '&#x'.implode(';&#x',$pairs).';'; |
|
| 2600 | + if (stristr($unicode, '-')) { |
|
| 2601 | + $pairs = explode('-', $unicode); |
|
| 2602 | + return '&#x'.implode(';&#x', $pairs).';'; |
|
| 2603 | 2603 | } |
| 2604 | 2604 | else { |
| 2605 | 2605 | return '&#x'.$unicode.';'; |
@@ -2432,8 +2432,7 @@ discard block |
||
| 2432 | 2432 | static function shortnameToAsciiCallback($m) { |
| 2433 | 2433 | if((!is_array($m)) || (!isset($m[1])) || (empty($m[1]))) { |
| 2434 | 2434 | return $m[0]; |
| 2435 | - } |
|
| 2436 | - else { |
|
| 2435 | + } else { |
|
| 2437 | 2436 | $aflipped = array_flip(self::$ascii_replace); |
| 2438 | 2437 | |
| 2439 | 2438 | $shortname = $m[0]; |
@@ -2450,8 +2449,7 @@ discard block |
||
| 2450 | 2449 | static function shortnameToUnicodeCallback($m) { |
| 2451 | 2450 | if((!is_array($m)) || (!isset($m[1])) || (empty($m[1]))) { |
| 2452 | 2451 | return $m[0]; |
| 2453 | - } |
|
| 2454 | - else { |
|
| 2452 | + } else { |
|
| 2455 | 2453 | $flipped = array_flip(self::$unicode_replace); |
| 2456 | 2454 | |
| 2457 | 2455 | $shortname = $m[1]; |
@@ -2468,8 +2466,7 @@ discard block |
||
| 2468 | 2466 | static function shortnameToImageCallback($m) { |
| 2469 | 2467 | if((!is_array($m)) || (!isset($m[1])) || (empty($m[1]))) { |
| 2470 | 2468 | return $m[0]; |
| 2471 | - } |
|
| 2472 | - else { |
|
| 2469 | + } else { |
|
| 2473 | 2470 | $shortname = $m[1]; |
| 2474 | 2471 | |
| 2475 | 2472 | if(!isset(self::$shortcode_replace[$shortname])) { |
@@ -2480,22 +2477,19 @@ discard block |
||
| 2480 | 2477 | $unicode = self::$shortcode_replace[$shortname]; |
| 2481 | 2478 | $filename = strtoupper($unicode); |
| 2482 | 2479 | |
| 2483 | - if(self::$unicodeAlt) { $alt = self::convert($unicode); } |
|
| 2484 | - else { $alt = $shortname; } |
|
| 2480 | + if(self::$unicodeAlt) { $alt = self::convert($unicode); } else { $alt = $shortname; } |
|
| 2485 | 2481 | |
| 2486 | 2482 | if(self::$imageType == 'png') { |
| 2487 | 2483 | if(self::$sprites) { |
| 2488 | 2484 | return '<span class="emojione-'.strtoupper($unicode).'" title="'.htmlspecialchars($shortname).'">'.$alt.'</span>'; |
| 2489 | - } |
|
| 2490 | - else { |
|
| 2485 | + } else { |
|
| 2491 | 2486 | return '<img class="emojione" alt="'.$alt.'" src="'.self::$imagePathPNG.$filename.'.png'.self::$cacheBustParam.'"/>'; |
| 2492 | 2487 | } |
| 2493 | 2488 | } |
| 2494 | 2489 | |
| 2495 | 2490 | if(self::$sprites) { |
| 2496 | 2491 | return '<svg class="emojione"><description>'.$alt.'</description><use xlink:href="'.self::$imagePathSVGSprites.'#emoji-'.strtoupper($unicode).'"></use></svg>'; |
| 2497 | - } |
|
| 2498 | - else { |
|
| 2492 | + } else { |
|
| 2499 | 2493 | return '<object class="emojione" data="'.self::$imagePathSVG.$filename.'.svg'.self::$cacheBustParam.'" type="image/svg+xml" standby="'.$alt.'">'.$alt.'</object>'; |
| 2500 | 2494 | } |
| 2501 | 2495 | } |
@@ -2503,8 +2497,7 @@ discard block |
||
| 2503 | 2497 | static function asciiToUnicodeCallback($m) { |
| 2504 | 2498 | if((!is_array($m)) || (!isset($m[3])) || (empty($m[3]))) { |
| 2505 | 2499 | return $m[0]; |
| 2506 | - } |
|
| 2507 | - else { |
|
| 2500 | + } else { |
|
| 2508 | 2501 | $shortname = $m[3]; |
| 2509 | 2502 | $unicode = self::$ascii_replace[$shortname]; |
| 2510 | 2503 | return $m[2].self::convert($unicode); |
@@ -2513,28 +2506,24 @@ discard block |
||
| 2513 | 2506 | static function asciiToImageCallback($m) { |
| 2514 | 2507 | if((!is_array($m)) || (!isset($m[3])) || (empty($m[3]))) { |
| 2515 | 2508 | return $m[0]; |
| 2516 | - } |
|
| 2517 | - else { |
|
| 2509 | + } else { |
|
| 2518 | 2510 | $shortname = html_entity_decode($m[3]); |
| 2519 | 2511 | $unicode = self::$ascii_replace[$shortname]; |
| 2520 | 2512 | |
| 2521 | 2513 | // unicode char or shortname for the alt tag? (unicode is better for copying and pasting the resulting text) |
| 2522 | - if(self::$unicodeAlt) { $alt = self::convert($unicode); } |
|
| 2523 | - else { $alt = htmlspecialchars($shortname); } |
|
| 2514 | + if(self::$unicodeAlt) { $alt = self::convert($unicode); } else { $alt = htmlspecialchars($shortname); } |
|
| 2524 | 2515 | |
| 2525 | 2516 | if(self::$imageType == 'png') { |
| 2526 | 2517 | if(self::$sprites) { |
| 2527 | 2518 | return $m[2].'<span class="emojione-'.strtoupper($unicode).'" title="'.htmlspecialchars($shortname).'">'.$alt.'</span>'; |
| 2528 | - } |
|
| 2529 | - else { |
|
| 2519 | + } else { |
|
| 2530 | 2520 | return $m[2].'<img class="emojione" alt="'.$alt.'" src="'.self::$imagePathPNG.strtoupper($unicode).'.png'.self::$cacheBustParam.'"/>'; |
| 2531 | 2521 | } |
| 2532 | 2522 | } |
| 2533 | 2523 | |
| 2534 | 2524 | if(self::$sprites) { |
| 2535 | 2525 | return $m[2].'<svg class="emojione"><description>'.$alt.'</description><use xlink:href="'.self::$imagePathSVGSprites.'#emoji-'.strtoupper($unicode).'"></use></svg>'; |
| 2536 | - } |
|
| 2537 | - else { |
|
| 2526 | + } else { |
|
| 2538 | 2527 | return $m[2].'<object class="emojione" data="'.self::$imagePathSVG.strtoupper($unicode).'.svg'.self::$cacheBustParam.'" type="image/svg+xml" standby="'.$alt.'">'.$alt.'</object>'; |
| 2539 | 2528 | } |
| 2540 | 2529 | } |
@@ -2542,8 +2531,7 @@ discard block |
||
| 2542 | 2531 | static function toShortCallback($m) { |
| 2543 | 2532 | if((!is_array($m)) || (!isset($m[1])) || (empty($m[1]))) { |
| 2544 | 2533 | return $m[0]; |
| 2545 | - } |
|
| 2546 | - else { |
|
| 2534 | + } else { |
|
| 2547 | 2535 | $unicode = $m[1]; |
| 2548 | 2536 | if(!isset(self::$unicode_replace[$unicode])) { |
| 2549 | 2537 | $unicode = substr($m[1], 0, 4); |
@@ -2558,8 +2546,7 @@ discard block |
||
| 2558 | 2546 | static function unicodeToImageCallback($m) { |
| 2559 | 2547 | if((!is_array($m)) || (!isset($m[1])) || (empty($m[1]))) { |
| 2560 | 2548 | return $m[0]; |
| 2561 | - } |
|
| 2562 | - else { |
|
| 2549 | + } else { |
|
| 2563 | 2550 | $unicode = $m[1]; |
| 2564 | 2551 | |
| 2565 | 2552 | if(!isset(self::$unicode_replace[$unicode])) { |
@@ -2572,22 +2559,19 @@ discard block |
||
| 2572 | 2559 | $shortname = self::$unicode_replace[$unicode]; |
| 2573 | 2560 | $filename = strtoupper(self::$shortcode_replace[$shortname]); |
| 2574 | 2561 | |
| 2575 | - if(self::$unicodeAlt) { $alt = $unicode; } |
|
| 2576 | - else { $alt = $shortname; } |
|
| 2562 | + if(self::$unicodeAlt) { $alt = $unicode; } else { $alt = $shortname; } |
|
| 2577 | 2563 | |
| 2578 | 2564 | if(self::$imageType == 'png') { |
| 2579 | 2565 | if(self::$sprites) { |
| 2580 | 2566 | return '<span class="emojione-'.strtoupper($unicode).'" title="'.htmlspecialchars($shortname).'">'.$alt.'</span>'; |
| 2581 | - } |
|
| 2582 | - else { |
|
| 2567 | + } else { |
|
| 2583 | 2568 | return '<img class="emojione" alt="'.$alt.'" src="'.self::$imagePathPNG.$filename.'.png'.self::$cacheBustParam.'"/>'; |
| 2584 | 2569 | } |
| 2585 | 2570 | } |
| 2586 | 2571 | |
| 2587 | 2572 | if(self::$sprites) { |
| 2588 | 2573 | return '<svg class="emojione"><description>'.$alt.'</description><use xlink:href="'.self::$imagePathSVGSprites.'#emoji-'.strtoupper($unicode).'"></use></svg>'; |
| 2589 | - } |
|
| 2590 | - else { |
|
| 2574 | + } else { |
|
| 2591 | 2575 | return '<object class="emojione" data="'.self::$imagePathSVG.$filename.'.svg'.self::$cacheBustParam.'" type="image/svg+xml" standby="'.$alt.'">'.$alt.'</object>'; |
| 2592 | 2576 | } |
| 2593 | 2577 | } |
@@ -2600,8 +2584,7 @@ discard block |
||
| 2600 | 2584 | if(stristr($unicode,'-')) { |
| 2601 | 2585 | $pairs = explode('-',$unicode); |
| 2602 | 2586 | return '&#x'.implode(';&#x',$pairs).';'; |
| 2603 | - } |
|
| 2604 | - else { |
|
| 2587 | + } else { |
|
| 2605 | 2588 | return '&#x'.$unicode.';'; |
| 2606 | 2589 | } |
| 2607 | 2590 | } |
@@ -20,7 +20,7 @@ discard block |
||
| 20 | 20 | array( |
| 21 | 21 | 'module_basename' => '\florinp\messenger\ucp\ucp_friends_module', |
| 22 | 22 | 'module_class' => 'ucp_friends_module', |
| 23 | - 'modes' => array('friends','requests'), |
|
| 23 | + 'modes' => array('friends', 'requests'), |
|
| 24 | 24 | ), |
| 25 | 25 | ) |
| 26 | 26 | ), |
@@ -36,7 +36,7 @@ discard block |
||
| 36 | 36 | array( |
| 37 | 37 | 'module_basename' => '\florinp\messenger\ucp\ucp_friends_module', |
| 38 | 38 | 'module_class' => 'ucp_friends_module', |
| 39 | - 'modes' => array('friends','requests'), |
|
| 39 | + 'modes' => array('friends', 'requests'), |
|
| 40 | 40 | ) |
| 41 | 41 | ) |
| 42 | 42 | ), |
@@ -114,10 +114,11 @@ discard block |
||
| 114 | 114 | 'sentAt' => time() |
| 115 | 115 | ); |
| 116 | 116 | |
| 117 | - if ($this->db->insert('messages', $insert)) |
|
| 118 | - return $this->db->lastInsertId(); |
|
| 119 | - else |
|
| 120 | - return false; |
|
| 117 | + if ($this->db->insert('messages', $insert)) { |
|
| 118 | + return $this->db->lastInsertId(); |
|
| 119 | + } else { |
|
| 120 | + return false; |
|
| 121 | + } |
|
| 121 | 122 | } |
| 122 | 123 | |
| 123 | 124 | public function sendFile($data) |
@@ -131,10 +132,11 @@ discard block |
||
| 131 | 132 | 'sentAt' => time() |
| 132 | 133 | ); |
| 133 | 134 | |
| 134 | - if ($this->db->insert('files', $insert)) |
|
| 135 | - return $this->db->lastInsertId(); |
|
| 136 | - else |
|
| 137 | - return false; |
|
| 135 | + if ($this->db->insert('files', $insert)) { |
|
| 136 | + return $this->db->lastInsertId(); |
|
| 137 | + } else { |
|
| 138 | + return false; |
|
| 139 | + } |
|
| 138 | 140 | } |
| 139 | 141 | |
| 140 | 142 | public function getMessageById($id) |
@@ -63,12 +63,12 @@ |
||
| 63 | 63 | public function get_title() |
| 64 | 64 | { |
| 65 | 65 | $user_id = $this->user_loader->load_user_by_username($this->get_data('sender_username')); |
| 66 | - return $this->user->lang('FRIEND_REQUEST_FROM') .$this->user_loader->get_username($user_id, 'no_profile'); |
|
| 66 | + return $this->user->lang('FRIEND_REQUEST_FROM').$this->user_loader->get_username($user_id, 'no_profile'); |
|
| 67 | 67 | } |
| 68 | 68 | |
| 69 | 69 | public function get_url() |
| 70 | 70 | { |
| 71 | - return append_sid($this->phpbb_root_path . 'ucp.' . $this->php_ext, "i=-florinp-messenger-ucp-ucp_friends_module&mode=requests"); |
|
| 71 | + return append_sid($this->phpbb_root_path.'ucp.'.$this->php_ext, "i=-florinp-messenger-ucp-ucp_friends_module&mode=requests"); |
|
| 72 | 72 | } |
| 73 | 73 | |
| 74 | 74 | public function get_avatar() |
@@ -17,22 +17,22 @@ discard block |
||
| 17 | 17 | |
| 18 | 18 | $this->tpl_name = 'friends'; |
| 19 | 19 | |
| 20 | - switch($mode) |
|
| 20 | + switch ($mode) |
|
| 21 | 21 | { |
| 22 | 22 | case 'friends': |
| 23 | 23 | |
| 24 | 24 | $action = $request->variable('action', ''); |
| 25 | - switch($action) |
|
| 25 | + switch ($action) |
|
| 26 | 26 | { |
| 27 | 27 | case 'add_friend': |
| 28 | 28 | $user_id = $request->variable('user_id', 0); |
| 29 | - if($user_id > 0) |
|
| 29 | + if ($user_id > 0) |
|
| 30 | 30 | { |
| 31 | - if(confirm_box(true)) |
|
| 31 | + if (confirm_box(true)) |
|
| 32 | 32 | { |
| 33 | 33 | $user_id = $request->variable('user_id', 0); |
| 34 | 34 | $redirect_url = $request->variable('redirect_url', ''); |
| 35 | - if($friends_controller->send_request($user_id)) |
|
| 35 | + if ($friends_controller->send_request($user_id)) |
|
| 36 | 36 | { |
| 37 | 37 | redirect($redirect_url); |
| 38 | 38 | } |
@@ -71,17 +71,17 @@ discard block |
||
| 71 | 71 | } |
| 72 | 72 | break; |
| 73 | 73 | default: |
| 74 | - if($request->is_set_post('action')) |
|
| 74 | + if ($request->is_set_post('action')) |
|
| 75 | 75 | { |
| 76 | 76 | $action = $request->variable('action', ''); |
| 77 | - switch($action) |
|
| 77 | + switch ($action) |
|
| 78 | 78 | { |
| 79 | 79 | case 'remove': |
| 80 | - if(confirm_box(true)) |
|
| 80 | + if (confirm_box(true)) |
|
| 81 | 81 | { |
| 82 | 82 | $user_id = $request->variable('user_id', array(0)); |
| 83 | 83 | $redirect_url = $request->variable('redirect_url', ''); |
| 84 | - if($friends_controller->remove_friend($user_id)) |
|
| 84 | + if ($friends_controller->remove_friend($user_id)) |
|
| 85 | 85 | { |
| 86 | 86 | redirect($redirect_url); |
| 87 | 87 | } |
@@ -106,15 +106,15 @@ discard block |
||
| 106 | 106 | |
| 107 | 107 | case 'requests': |
| 108 | 108 | |
| 109 | - if($request->is_set_post('action')) |
|
| 109 | + if ($request->is_set_post('action')) |
|
| 110 | 110 | { |
| 111 | 111 | $action = $request->variable('action', ''); |
| 112 | 112 | |
| 113 | - switch($action) |
|
| 113 | + switch ($action) |
|
| 114 | 114 | { |
| 115 | 115 | case 'delete': |
| 116 | 116 | |
| 117 | - if(confirm_box(true)) |
|
| 117 | + if (confirm_box(true)) |
|
| 118 | 118 | { |
| 119 | 119 | $requests_id = $request->variable('requests_id', array(0)); |
| 120 | 120 | $friends_controller->delete_request($requests_id); |
@@ -138,14 +138,14 @@ discard block |
||
| 138 | 138 | } |
| 139 | 139 | |
| 140 | 140 | $action = $request->variable('action', ''); |
| 141 | - switch($action) |
|
| 141 | + switch ($action) |
|
| 142 | 142 | { |
| 143 | 143 | case 'cancel_request': |
| 144 | - if(confirm_box(true)) |
|
| 144 | + if (confirm_box(true)) |
|
| 145 | 145 | { |
| 146 | 146 | $request_id = $request->variable('request_id', 0); |
| 147 | 147 | $redirect_url = $request->variable('redirect_url', ''); |
| 148 | - if($friends_controller->delete_request($request_id)) |
|
| 148 | + if ($friends_controller->delete_request($request_id)) |
|
| 149 | 149 | { |
| 150 | 150 | redirect($redirect_url); |
| 151 | 151 | } |
@@ -85,8 +85,7 @@ discard block |
||
| 85 | 85 | { |
| 86 | 86 | redirect($redirect_url); |
| 87 | 87 | } |
| 88 | - } |
|
| 89 | - else |
|
| 88 | + } else |
|
| 90 | 89 | { |
| 91 | 90 | $user_id = $request->variable('user_id', array(0)); |
| 92 | 91 | $redirect_url = $request->server('HTTP_REFERER'); |
@@ -118,8 +117,7 @@ discard block |
||
| 118 | 117 | { |
| 119 | 118 | $requests_id = $request->variable('requests_id', array(0)); |
| 120 | 119 | $friends_controller->delete_request($requests_id); |
| 121 | - } |
|
| 122 | - else |
|
| 120 | + } else |
|
| 123 | 121 | { |
| 124 | 122 | $requests_id = $request->variable('requests_id', array(0)); |
| 125 | 123 | confirm_box(false, $user->lang('CONFIRM_REMOVE_REQUESTS'), build_hidden_fields(array( |
@@ -149,8 +147,7 @@ discard block |
||
| 149 | 147 | { |
| 150 | 148 | redirect($redirect_url); |
| 151 | 149 | } |
| 152 | - } |
|
| 153 | - else |
|
| 150 | + } else |
|
| 154 | 151 | { |
| 155 | 152 | $request_id = $request->variable('request_id', 0); |
| 156 | 153 | $redirect_url = $request->server('HTTP_REFERER'); |
@@ -365,7 +365,7 @@ discard block |
||
| 365 | 365 | /** |
| 366 | 366 | * Set allowed mime types |
| 367 | 367 | * |
| 368 | - * @param array $mimes |
|
| 368 | + * @param string[] $mimes |
|
| 369 | 369 | */ |
| 370 | 370 | public function set_allowed_mime_types($mimes) |
| 371 | 371 | { |
@@ -515,7 +515,7 @@ discard block |
||
| 515 | 515 | * Convert bytes to mb. |
| 516 | 516 | * |
| 517 | 517 | * @param int $bytes |
| 518 | - * @return int |
|
| 518 | + * @return double |
|
| 519 | 519 | */ |
| 520 | 520 | protected function bytes_to_mb($bytes) |
| 521 | 521 | { |
@@ -13,514 +13,514 @@ |
||
| 13 | 13 | class upload |
| 14 | 14 | { |
| 15 | 15 | |
| 16 | - /** |
|
| 17 | - * Default directory persmissions (destination dir) |
|
| 18 | - */ |
|
| 19 | - protected $default_permissions = 750; |
|
| 20 | - |
|
| 21 | - |
|
| 22 | - /** |
|
| 23 | - * File post array |
|
| 24 | - * |
|
| 25 | - * @var array |
|
| 26 | - */ |
|
| 27 | - protected $files_post = array(); |
|
| 28 | - |
|
| 29 | - |
|
| 30 | - /** |
|
| 31 | - * Destination directory |
|
| 32 | - * |
|
| 33 | - * @var string |
|
| 34 | - */ |
|
| 35 | - protected $destination; |
|
| 36 | - |
|
| 37 | - |
|
| 38 | - /** |
|
| 39 | - * Fileinfo |
|
| 40 | - * |
|
| 41 | - * @var object |
|
| 42 | - */ |
|
| 43 | - protected $finfo; |
|
| 44 | - |
|
| 45 | - |
|
| 46 | - /** |
|
| 47 | - * Data about file |
|
| 48 | - * |
|
| 49 | - * @var array |
|
| 50 | - */ |
|
| 51 | - public $file = array(); |
|
| 52 | - |
|
| 53 | - |
|
| 54 | - /** |
|
| 55 | - * Max. file size |
|
| 56 | - * |
|
| 57 | - * @var int |
|
| 58 | - */ |
|
| 59 | - protected $max_file_size; |
|
| 60 | - |
|
| 61 | - |
|
| 62 | - /** |
|
| 63 | - * Allowed mime types |
|
| 64 | - * |
|
| 65 | - * @var array |
|
| 66 | - */ |
|
| 67 | - protected $mimes = array(); |
|
| 68 | - |
|
| 69 | - |
|
| 70 | - /** |
|
| 71 | - * External callback object |
|
| 72 | - * |
|
| 73 | - * @var obejct |
|
| 74 | - */ |
|
| 75 | - protected $external_callback_object; |
|
| 76 | - |
|
| 77 | - |
|
| 78 | - /** |
|
| 79 | - * External callback methods |
|
| 80 | - * |
|
| 81 | - * @var array |
|
| 82 | - */ |
|
| 83 | - protected $external_callback_methods = array(); |
|
| 84 | - |
|
| 85 | - |
|
| 86 | - /** |
|
| 87 | - * Temp path |
|
| 88 | - * |
|
| 89 | - * @var string |
|
| 90 | - */ |
|
| 91 | - protected $tmp_name; |
|
| 92 | - |
|
| 93 | - |
|
| 94 | - /** |
|
| 95 | - * Validation errors |
|
| 96 | - * |
|
| 97 | - * @var array |
|
| 98 | - */ |
|
| 99 | - protected $validation_errors = array(); |
|
| 100 | - |
|
| 101 | - |
|
| 102 | - /** |
|
| 103 | - * Filename (new) |
|
| 104 | - * |
|
| 105 | - * @var string |
|
| 106 | - */ |
|
| 107 | - protected $filename; |
|
| 108 | - |
|
| 109 | - /** |
|
| 110 | - * File extension |
|
| 111 | - * @var string |
|
| 112 | - */ |
|
| 113 | - protected $extension; |
|
| 114 | - |
|
| 115 | - /** |
|
| 116 | - * Internal callbacks (filesize check, mime, etc) |
|
| 117 | - * |
|
| 118 | - * @var array |
|
| 119 | - */ |
|
| 120 | - private $callbacks = array(); |
|
| 121 | - |
|
| 122 | - /** |
|
| 123 | - * Root dir |
|
| 124 | - * |
|
| 125 | - * @var string |
|
| 126 | - */ |
|
| 127 | - protected $root; |
|
| 128 | - |
|
| 129 | - /** |
|
| 130 | - * Return upload object |
|
| 131 | - * |
|
| 132 | - * $destination = 'path/to/your/file/destination/folder'; |
|
| 133 | - * |
|
| 134 | - * @param string $phpbb_root_path |
|
| 135 | - * @return Upload |
|
| 136 | - */ |
|
| 137 | - public static function factory($phpbb_root_path) |
|
| 138 | - { |
|
| 139 | - return new Upload($phpbb_root_path); |
|
| 140 | - } |
|
| 141 | - |
|
| 142 | - /** |
|
| 143 | - * Define ROOT constant and set & create destination path |
|
| 144 | - * |
|
| 145 | - * @param string $phpbb_root_path |
|
| 146 | - * @throws Exception |
|
| 147 | - */ |
|
| 148 | - public function __construct($phpbb_root_path) |
|
| 149 | - { |
|
| 150 | - $phpbb_root_path = $phpbb_root_path . 'store/messenger/files'; |
|
| 151 | - // set & create destination path |
|
| 152 | - if (!$this->set_destination($phpbb_root_path)) { |
|
| 153 | - throw new Exception('Upload: Can\'t create destination. ' . $this->root . $this->destination); |
|
| 154 | - } |
|
| 155 | - |
|
| 156 | - //create finfo object |
|
| 157 | - $this->finfo = new finfo(); |
|
| 158 | - } |
|
| 159 | - |
|
| 160 | - /** |
|
| 161 | - * Set target filename |
|
| 162 | - * |
|
| 163 | - * @param string $filename |
|
| 164 | - */ |
|
| 165 | - public function set_filename($filename) |
|
| 166 | - { |
|
| 167 | - $this->filename = $filename; |
|
| 168 | - } |
|
| 169 | - |
|
| 170 | - /** |
|
| 171 | - * Check & Save file |
|
| 172 | - * |
|
| 173 | - * Return data about current upload |
|
| 174 | - * |
|
| 175 | - * @return array |
|
| 176 | - */ |
|
| 177 | - public function upload($filename = '') |
|
| 178 | - { |
|
| 179 | - if ($this->check()) { |
|
| 180 | - $this->save(); |
|
| 181 | - } |
|
| 182 | - // return state data |
|
| 183 | - return $this->get_state(); |
|
| 184 | - } |
|
| 185 | - |
|
| 186 | - |
|
| 187 | - /** |
|
| 188 | - * Save file on server |
|
| 189 | - * |
|
| 190 | - * Return state data |
|
| 191 | - * |
|
| 192 | - * @return array |
|
| 193 | - */ |
|
| 194 | - public function save() |
|
| 195 | - { |
|
| 196 | - $this->save_file(); |
|
| 197 | - return $this->get_state(); |
|
| 198 | - } |
|
| 199 | - |
|
| 200 | - |
|
| 201 | - /** |
|
| 202 | - * Validate file (execute callbacks) |
|
| 203 | - * |
|
| 204 | - * Returns TRUE if validation successful |
|
| 205 | - * |
|
| 206 | - * @return bool |
|
| 207 | - */ |
|
| 208 | - public function check() |
|
| 209 | - { |
|
| 210 | - //execute callbacks (check filesize, mime, also external callbacks |
|
| 211 | - $this->validate(); |
|
| 212 | - |
|
| 213 | - //add error messages |
|
| 214 | - $this->file['errors'] = $this->get_errors(); |
|
| 215 | - |
|
| 216 | - //change file validation status |
|
| 217 | - $this->file['status'] = empty($this->validation_errors); |
|
| 218 | - |
|
| 219 | - return $this->file['status']; |
|
| 220 | - } |
|
| 221 | - |
|
| 222 | - /** |
|
| 223 | - * Get current state data |
|
| 224 | - * |
|
| 225 | - * @return array |
|
| 226 | - */ |
|
| 227 | - public function get_state() |
|
| 228 | - { |
|
| 229 | - return $this->file; |
|
| 230 | - } |
|
| 231 | - |
|
| 232 | - |
|
| 233 | - /** |
|
| 234 | - * Save file on server |
|
| 235 | - */ |
|
| 236 | - protected function save_file() |
|
| 237 | - { |
|
| 238 | - //create & set new filename |
|
| 239 | - if (empty($this->filename)) { |
|
| 240 | - $this->create_new_filename(); |
|
| 241 | - } |
|
| 242 | - |
|
| 243 | - //set filename |
|
| 244 | - $this->file['filename'] = $this->filename; |
|
| 245 | - |
|
| 246 | - //set full path |
|
| 247 | - $this->file['full_path'] = $this->root . $this->destination . $this->filename; |
|
| 248 | - $this->file['path'] = $this->destination . $this->filename; |
|
| 249 | - |
|
| 250 | - $status = move_uploaded_file($this->tmp_name, $this->file['full_path']); |
|
| 251 | - |
|
| 252 | - //checks whether upload successful |
|
| 253 | - if (!$status) { |
|
| 254 | - throw new Exception('Upload: Can\'t upload file.'); |
|
| 255 | - } |
|
| 256 | - |
|
| 257 | - //done |
|
| 258 | - $this->file['status'] = true; |
|
| 259 | - } |
|
| 260 | - |
|
| 261 | - /** |
|
| 262 | - * Set data about file |
|
| 263 | - */ |
|
| 264 | - protected function set_file_data() |
|
| 265 | - { |
|
| 266 | - $file_size = $this->get_file_size(); |
|
| 267 | - |
|
| 268 | - $this->file = array( |
|
| 269 | - 'status' => false, |
|
| 270 | - 'destination' => $this->destination, |
|
| 271 | - 'size_in_bytes' => $file_size, |
|
| 272 | - 'size_in_mb' => $this->bytes_to_mb($file_size), |
|
| 273 | - 'mime' => $this->get_file_mime(), |
|
| 274 | - 'original_filename' => $this->file_post['name'], |
|
| 275 | - 'tmp_name' => $this->file_post['tmp_name'], |
|
| 276 | - 'post_data' => $this->file_post, |
|
| 277 | - ); |
|
| 278 | - } |
|
| 279 | - |
|
| 280 | - /** |
|
| 281 | - * Set validation error |
|
| 282 | - * |
|
| 283 | - * @param string $message |
|
| 284 | - */ |
|
| 285 | - public function set_error($message) |
|
| 286 | - { |
|
| 287 | - $this->validation_errors[] = $message; |
|
| 288 | - } |
|
| 289 | - |
|
| 290 | - /** |
|
| 291 | - * Return validation errors |
|
| 292 | - * |
|
| 293 | - * @return array |
|
| 294 | - */ |
|
| 295 | - public function get_errors() |
|
| 296 | - { |
|
| 297 | - return $this->validation_errors; |
|
| 298 | - } |
|
| 299 | - |
|
| 300 | - /** |
|
| 301 | - * Set external callback methods |
|
| 302 | - * |
|
| 303 | - * @param object $instance_of_callback_object |
|
| 304 | - * @param array $callback_methods |
|
| 305 | - * @throws Exception |
|
| 306 | - */ |
|
| 307 | - public function callbacks($instance_of_callback_object, $callback_methods) |
|
| 308 | - { |
|
| 309 | - if (empty($instance_of_callback_object)) { |
|
| 310 | - throw new Exception('Upload: $instance_of_callback_object can\'t be empty.'); |
|
| 311 | - } |
|
| 312 | - |
|
| 313 | - if (!is_array($callback_methods)) { |
|
| 314 | - throw new Exception('Upload: $callback_methods data type need to be array.'); |
|
| 315 | - } |
|
| 316 | - |
|
| 317 | - $this->external_callback_object = $instance_of_callback_object; |
|
| 318 | - $this->external_callback_methods = $callback_methods; |
|
| 319 | - } |
|
| 320 | - |
|
| 321 | - /** |
|
| 322 | - * Execute callbacks |
|
| 323 | - */ |
|
| 324 | - protected function validate() |
|
| 325 | - { |
|
| 326 | - //get curent errors |
|
| 327 | - $errors = $this->get_errors(); |
|
| 328 | - |
|
| 329 | - if (empty($errors)) { |
|
| 330 | - //set data about current file |
|
| 331 | - $this->set_file_data(); |
|
| 332 | - |
|
| 333 | - //execute internal callbacks |
|
| 334 | - $this->execute_callbacks($this->callbacks, $this); |
|
| 335 | - |
|
| 336 | - //execute external callbacks |
|
| 337 | - $this->execute_callbacks($this->external_callback_methods, $this->external_callback_object); |
|
| 338 | - } |
|
| 339 | - } |
|
| 340 | - |
|
| 341 | - /** |
|
| 342 | - * Execute callbacks |
|
| 343 | - */ |
|
| 344 | - protected function execute_callbacks($callbacks, $object) |
|
| 345 | - { |
|
| 346 | - foreach ($callbacks as $method) { |
|
| 347 | - $object->$method($this); |
|
| 348 | - } |
|
| 349 | - } |
|
| 350 | - |
|
| 351 | - /** |
|
| 352 | - * File mime type validation callback |
|
| 353 | - * |
|
| 354 | - * @param mixed $object |
|
| 355 | - */ |
|
| 356 | - protected function check_mime_type($object) |
|
| 357 | - { |
|
| 358 | - if (!empty($object->mimes)) { |
|
| 359 | - if (!in_array($object->file['mime'], $object->mimes)) { |
|
| 360 | - $object->set_error('Mime type not allowed.'); |
|
| 361 | - } |
|
| 362 | - } |
|
| 363 | - } |
|
| 364 | - |
|
| 365 | - /** |
|
| 366 | - * Set allowed mime types |
|
| 367 | - * |
|
| 368 | - * @param array $mimes |
|
| 369 | - */ |
|
| 370 | - public function set_allowed_mime_types($mimes) |
|
| 371 | - { |
|
| 372 | - $this->mimes = $mimes; |
|
| 373 | - //if mime types is set -> set callback |
|
| 374 | - $this->callbacks[] = 'check_mime_type'; |
|
| 375 | - } |
|
| 376 | - |
|
| 377 | - /** |
|
| 378 | - * File size validation callback |
|
| 379 | - * |
|
| 380 | - * @param object $object |
|
| 381 | - */ |
|
| 382 | - protected function check_file_size($object) |
|
| 383 | - { |
|
| 384 | - if (!empty($object->max_file_size)) { |
|
| 385 | - $file_size_in_mb = $this->bytes_to_mb($object->file['size_in_bytes']); |
|
| 386 | - if ($object->max_file_size <= $file_size_in_mb) { |
|
| 387 | - $object->set_error('File is too big.'); |
|
| 388 | - } |
|
| 389 | - } |
|
| 390 | - } |
|
| 391 | - |
|
| 392 | - /** |
|
| 393 | - * Set max. file size |
|
| 394 | - * |
|
| 395 | - * @param int $size |
|
| 396 | - */ |
|
| 397 | - public function set_max_file_size($size) |
|
| 398 | - { |
|
| 399 | - $this->max_file_size = $size; |
|
| 400 | - //if max file size is set -> set callback |
|
| 401 | - $this->callbacks[] = 'check_file_size'; |
|
| 402 | - } |
|
| 403 | - |
|
| 404 | - /** |
|
| 405 | - * Set File array to object |
|
| 406 | - * |
|
| 407 | - * @param array $file |
|
| 408 | - */ |
|
| 409 | - public function file($file) |
|
| 410 | - { |
|
| 411 | - $this->set_file_array($file); |
|
| 412 | - } |
|
| 413 | - |
|
| 414 | - /** |
|
| 415 | - * Set file array |
|
| 416 | - * |
|
| 417 | - * @param array $file |
|
| 418 | - */ |
|
| 419 | - protected function set_file_array($file) |
|
| 420 | - { |
|
| 421 | - //checks whether file array is valid |
|
| 422 | - if (!$this->check_file_array($file)) { |
|
| 423 | - //file not selected or some bigger problems (broken files array) |
|
| 424 | - $this->set_error('Please select file.'); |
|
| 425 | - } |
|
| 426 | - |
|
| 427 | - //set file data |
|
| 428 | - $this->file_post = $file; |
|
| 429 | - |
|
| 430 | - //set tmp path |
|
| 431 | - $this->tmp_name = $file['tmp_name']; |
|
| 432 | - |
|
| 433 | - // set file extension |
|
| 434 | - $this->extension = pathinfo($file['name'], PATHINFO_EXTENSION); |
|
| 435 | - } |
|
| 436 | - |
|
| 437 | - /** |
|
| 438 | - * Checks whether Files post array is valid |
|
| 439 | - * |
|
| 440 | - * @return bool |
|
| 441 | - */ |
|
| 442 | - protected function check_file_array($file) |
|
| 443 | - { |
|
| 444 | - return isset($file['error']) |
|
| 445 | - && !empty($file['name']) |
|
| 446 | - && !empty($file['type']) |
|
| 447 | - && !empty($file['tmp_name']) |
|
| 448 | - && !empty($file['size']); |
|
| 449 | - } |
|
| 450 | - |
|
| 451 | - /** |
|
| 452 | - * Get file mime type |
|
| 453 | - * |
|
| 454 | - * @return string |
|
| 455 | - */ |
|
| 456 | - protected function get_file_mime() |
|
| 457 | - { |
|
| 458 | - return $this->finfo->file($this->tmp_name, FILEINFO_MIME_TYPE); |
|
| 459 | - } |
|
| 460 | - |
|
| 461 | - /** |
|
| 462 | - * Get file size |
|
| 463 | - * |
|
| 464 | - * @return int |
|
| 465 | - */ |
|
| 466 | - protected function get_file_size() |
|
| 467 | - { |
|
| 468 | - return filesize($this->tmp_name); |
|
| 469 | - } |
|
| 470 | - |
|
| 471 | - /** |
|
| 472 | - * Set destination path (return TRUE on success) |
|
| 473 | - * |
|
| 474 | - * @param string $destination |
|
| 475 | - * @return bool |
|
| 476 | - */ |
|
| 477 | - protected function set_destination($destination) |
|
| 478 | - { |
|
| 479 | - $this->destination = $destination . DIRECTORY_SEPARATOR; |
|
| 480 | - return $this->destination_exist() ? TRUE : $this->create_destination(); |
|
| 481 | - } |
|
| 482 | - |
|
| 483 | - /** |
|
| 484 | - * Checks whether destination folder exists |
|
| 485 | - * |
|
| 486 | - * @return bool |
|
| 487 | - */ |
|
| 488 | - protected function destination_exist() |
|
| 489 | - { |
|
| 490 | - return is_writable($this->root . $this->destination); |
|
| 491 | - } |
|
| 492 | - |
|
| 493 | - /** |
|
| 494 | - * Create path to destination |
|
| 495 | - * |
|
| 496 | - * @return bool |
|
| 497 | - */ |
|
| 498 | - protected function create_destination() |
|
| 499 | - { |
|
| 500 | - return mkdir($this->root . $this->destination, $this->default_permissions, true); |
|
| 501 | - } |
|
| 502 | - |
|
| 503 | - /** |
|
| 504 | - * Set unique filename |
|
| 505 | - * |
|
| 506 | - * @return string |
|
| 507 | - */ |
|
| 508 | - protected function create_new_filename() |
|
| 509 | - { |
|
| 510 | - $filename = sha1(mt_rand(1, 9999) . $this->destination . uniqid()) . time() . '.' . $this->extension; |
|
| 511 | - $this->set_filename($filename); |
|
| 512 | - } |
|
| 513 | - |
|
| 514 | - /** |
|
| 515 | - * Convert bytes to mb. |
|
| 516 | - * |
|
| 517 | - * @param int $bytes |
|
| 518 | - * @return int |
|
| 519 | - */ |
|
| 520 | - protected function bytes_to_mb($bytes) |
|
| 521 | - { |
|
| 522 | - return round(($bytes / 1048576), 2); |
|
| 523 | - } |
|
| 16 | + /** |
|
| 17 | + * Default directory persmissions (destination dir) |
|
| 18 | + */ |
|
| 19 | + protected $default_permissions = 750; |
|
| 20 | + |
|
| 21 | + |
|
| 22 | + /** |
|
| 23 | + * File post array |
|
| 24 | + * |
|
| 25 | + * @var array |
|
| 26 | + */ |
|
| 27 | + protected $files_post = array(); |
|
| 28 | + |
|
| 29 | + |
|
| 30 | + /** |
|
| 31 | + * Destination directory |
|
| 32 | + * |
|
| 33 | + * @var string |
|
| 34 | + */ |
|
| 35 | + protected $destination; |
|
| 36 | + |
|
| 37 | + |
|
| 38 | + /** |
|
| 39 | + * Fileinfo |
|
| 40 | + * |
|
| 41 | + * @var object |
|
| 42 | + */ |
|
| 43 | + protected $finfo; |
|
| 44 | + |
|
| 45 | + |
|
| 46 | + /** |
|
| 47 | + * Data about file |
|
| 48 | + * |
|
| 49 | + * @var array |
|
| 50 | + */ |
|
| 51 | + public $file = array(); |
|
| 52 | + |
|
| 53 | + |
|
| 54 | + /** |
|
| 55 | + * Max. file size |
|
| 56 | + * |
|
| 57 | + * @var int |
|
| 58 | + */ |
|
| 59 | + protected $max_file_size; |
|
| 60 | + |
|
| 61 | + |
|
| 62 | + /** |
|
| 63 | + * Allowed mime types |
|
| 64 | + * |
|
| 65 | + * @var array |
|
| 66 | + */ |
|
| 67 | + protected $mimes = array(); |
|
| 68 | + |
|
| 69 | + |
|
| 70 | + /** |
|
| 71 | + * External callback object |
|
| 72 | + * |
|
| 73 | + * @var obejct |
|
| 74 | + */ |
|
| 75 | + protected $external_callback_object; |
|
| 76 | + |
|
| 77 | + |
|
| 78 | + /** |
|
| 79 | + * External callback methods |
|
| 80 | + * |
|
| 81 | + * @var array |
|
| 82 | + */ |
|
| 83 | + protected $external_callback_methods = array(); |
|
| 84 | + |
|
| 85 | + |
|
| 86 | + /** |
|
| 87 | + * Temp path |
|
| 88 | + * |
|
| 89 | + * @var string |
|
| 90 | + */ |
|
| 91 | + protected $tmp_name; |
|
| 92 | + |
|
| 93 | + |
|
| 94 | + /** |
|
| 95 | + * Validation errors |
|
| 96 | + * |
|
| 97 | + * @var array |
|
| 98 | + */ |
|
| 99 | + protected $validation_errors = array(); |
|
| 100 | + |
|
| 101 | + |
|
| 102 | + /** |
|
| 103 | + * Filename (new) |
|
| 104 | + * |
|
| 105 | + * @var string |
|
| 106 | + */ |
|
| 107 | + protected $filename; |
|
| 108 | + |
|
| 109 | + /** |
|
| 110 | + * File extension |
|
| 111 | + * @var string |
|
| 112 | + */ |
|
| 113 | + protected $extension; |
|
| 114 | + |
|
| 115 | + /** |
|
| 116 | + * Internal callbacks (filesize check, mime, etc) |
|
| 117 | + * |
|
| 118 | + * @var array |
|
| 119 | + */ |
|
| 120 | + private $callbacks = array(); |
|
| 121 | + |
|
| 122 | + /** |
|
| 123 | + * Root dir |
|
| 124 | + * |
|
| 125 | + * @var string |
|
| 126 | + */ |
|
| 127 | + protected $root; |
|
| 128 | + |
|
| 129 | + /** |
|
| 130 | + * Return upload object |
|
| 131 | + * |
|
| 132 | + * $destination = 'path/to/your/file/destination/folder'; |
|
| 133 | + * |
|
| 134 | + * @param string $phpbb_root_path |
|
| 135 | + * @return Upload |
|
| 136 | + */ |
|
| 137 | + public static function factory($phpbb_root_path) |
|
| 138 | + { |
|
| 139 | + return new Upload($phpbb_root_path); |
|
| 140 | + } |
|
| 141 | + |
|
| 142 | + /** |
|
| 143 | + * Define ROOT constant and set & create destination path |
|
| 144 | + * |
|
| 145 | + * @param string $phpbb_root_path |
|
| 146 | + * @throws Exception |
|
| 147 | + */ |
|
| 148 | + public function __construct($phpbb_root_path) |
|
| 149 | + { |
|
| 150 | + $phpbb_root_path = $phpbb_root_path . 'store/messenger/files'; |
|
| 151 | + // set & create destination path |
|
| 152 | + if (!$this->set_destination($phpbb_root_path)) { |
|
| 153 | + throw new Exception('Upload: Can\'t create destination. ' . $this->root . $this->destination); |
|
| 154 | + } |
|
| 155 | + |
|
| 156 | + //create finfo object |
|
| 157 | + $this->finfo = new finfo(); |
|
| 158 | + } |
|
| 159 | + |
|
| 160 | + /** |
|
| 161 | + * Set target filename |
|
| 162 | + * |
|
| 163 | + * @param string $filename |
|
| 164 | + */ |
|
| 165 | + public function set_filename($filename) |
|
| 166 | + { |
|
| 167 | + $this->filename = $filename; |
|
| 168 | + } |
|
| 169 | + |
|
| 170 | + /** |
|
| 171 | + * Check & Save file |
|
| 172 | + * |
|
| 173 | + * Return data about current upload |
|
| 174 | + * |
|
| 175 | + * @return array |
|
| 176 | + */ |
|
| 177 | + public function upload($filename = '') |
|
| 178 | + { |
|
| 179 | + if ($this->check()) { |
|
| 180 | + $this->save(); |
|
| 181 | + } |
|
| 182 | + // return state data |
|
| 183 | + return $this->get_state(); |
|
| 184 | + } |
|
| 185 | + |
|
| 186 | + |
|
| 187 | + /** |
|
| 188 | + * Save file on server |
|
| 189 | + * |
|
| 190 | + * Return state data |
|
| 191 | + * |
|
| 192 | + * @return array |
|
| 193 | + */ |
|
| 194 | + public function save() |
|
| 195 | + { |
|
| 196 | + $this->save_file(); |
|
| 197 | + return $this->get_state(); |
|
| 198 | + } |
|
| 199 | + |
|
| 200 | + |
|
| 201 | + /** |
|
| 202 | + * Validate file (execute callbacks) |
|
| 203 | + * |
|
| 204 | + * Returns TRUE if validation successful |
|
| 205 | + * |
|
| 206 | + * @return bool |
|
| 207 | + */ |
|
| 208 | + public function check() |
|
| 209 | + { |
|
| 210 | + //execute callbacks (check filesize, mime, also external callbacks |
|
| 211 | + $this->validate(); |
|
| 212 | + |
|
| 213 | + //add error messages |
|
| 214 | + $this->file['errors'] = $this->get_errors(); |
|
| 215 | + |
|
| 216 | + //change file validation status |
|
| 217 | + $this->file['status'] = empty($this->validation_errors); |
|
| 218 | + |
|
| 219 | + return $this->file['status']; |
|
| 220 | + } |
|
| 221 | + |
|
| 222 | + /** |
|
| 223 | + * Get current state data |
|
| 224 | + * |
|
| 225 | + * @return array |
|
| 226 | + */ |
|
| 227 | + public function get_state() |
|
| 228 | + { |
|
| 229 | + return $this->file; |
|
| 230 | + } |
|
| 231 | + |
|
| 232 | + |
|
| 233 | + /** |
|
| 234 | + * Save file on server |
|
| 235 | + */ |
|
| 236 | + protected function save_file() |
|
| 237 | + { |
|
| 238 | + //create & set new filename |
|
| 239 | + if (empty($this->filename)) { |
|
| 240 | + $this->create_new_filename(); |
|
| 241 | + } |
|
| 242 | + |
|
| 243 | + //set filename |
|
| 244 | + $this->file['filename'] = $this->filename; |
|
| 245 | + |
|
| 246 | + //set full path |
|
| 247 | + $this->file['full_path'] = $this->root . $this->destination . $this->filename; |
|
| 248 | + $this->file['path'] = $this->destination . $this->filename; |
|
| 249 | + |
|
| 250 | + $status = move_uploaded_file($this->tmp_name, $this->file['full_path']); |
|
| 251 | + |
|
| 252 | + //checks whether upload successful |
|
| 253 | + if (!$status) { |
|
| 254 | + throw new Exception('Upload: Can\'t upload file.'); |
|
| 255 | + } |
|
| 256 | + |
|
| 257 | + //done |
|
| 258 | + $this->file['status'] = true; |
|
| 259 | + } |
|
| 260 | + |
|
| 261 | + /** |
|
| 262 | + * Set data about file |
|
| 263 | + */ |
|
| 264 | + protected function set_file_data() |
|
| 265 | + { |
|
| 266 | + $file_size = $this->get_file_size(); |
|
| 267 | + |
|
| 268 | + $this->file = array( |
|
| 269 | + 'status' => false, |
|
| 270 | + 'destination' => $this->destination, |
|
| 271 | + 'size_in_bytes' => $file_size, |
|
| 272 | + 'size_in_mb' => $this->bytes_to_mb($file_size), |
|
| 273 | + 'mime' => $this->get_file_mime(), |
|
| 274 | + 'original_filename' => $this->file_post['name'], |
|
| 275 | + 'tmp_name' => $this->file_post['tmp_name'], |
|
| 276 | + 'post_data' => $this->file_post, |
|
| 277 | + ); |
|
| 278 | + } |
|
| 279 | + |
|
| 280 | + /** |
|
| 281 | + * Set validation error |
|
| 282 | + * |
|
| 283 | + * @param string $message |
|
| 284 | + */ |
|
| 285 | + public function set_error($message) |
|
| 286 | + { |
|
| 287 | + $this->validation_errors[] = $message; |
|
| 288 | + } |
|
| 289 | + |
|
| 290 | + /** |
|
| 291 | + * Return validation errors |
|
| 292 | + * |
|
| 293 | + * @return array |
|
| 294 | + */ |
|
| 295 | + public function get_errors() |
|
| 296 | + { |
|
| 297 | + return $this->validation_errors; |
|
| 298 | + } |
|
| 299 | + |
|
| 300 | + /** |
|
| 301 | + * Set external callback methods |
|
| 302 | + * |
|
| 303 | + * @param object $instance_of_callback_object |
|
| 304 | + * @param array $callback_methods |
|
| 305 | + * @throws Exception |
|
| 306 | + */ |
|
| 307 | + public function callbacks($instance_of_callback_object, $callback_methods) |
|
| 308 | + { |
|
| 309 | + if (empty($instance_of_callback_object)) { |
|
| 310 | + throw new Exception('Upload: $instance_of_callback_object can\'t be empty.'); |
|
| 311 | + } |
|
| 312 | + |
|
| 313 | + if (!is_array($callback_methods)) { |
|
| 314 | + throw new Exception('Upload: $callback_methods data type need to be array.'); |
|
| 315 | + } |
|
| 316 | + |
|
| 317 | + $this->external_callback_object = $instance_of_callback_object; |
|
| 318 | + $this->external_callback_methods = $callback_methods; |
|
| 319 | + } |
|
| 320 | + |
|
| 321 | + /** |
|
| 322 | + * Execute callbacks |
|
| 323 | + */ |
|
| 324 | + protected function validate() |
|
| 325 | + { |
|
| 326 | + //get curent errors |
|
| 327 | + $errors = $this->get_errors(); |
|
| 328 | + |
|
| 329 | + if (empty($errors)) { |
|
| 330 | + //set data about current file |
|
| 331 | + $this->set_file_data(); |
|
| 332 | + |
|
| 333 | + //execute internal callbacks |
|
| 334 | + $this->execute_callbacks($this->callbacks, $this); |
|
| 335 | + |
|
| 336 | + //execute external callbacks |
|
| 337 | + $this->execute_callbacks($this->external_callback_methods, $this->external_callback_object); |
|
| 338 | + } |
|
| 339 | + } |
|
| 340 | + |
|
| 341 | + /** |
|
| 342 | + * Execute callbacks |
|
| 343 | + */ |
|
| 344 | + protected function execute_callbacks($callbacks, $object) |
|
| 345 | + { |
|
| 346 | + foreach ($callbacks as $method) { |
|
| 347 | + $object->$method($this); |
|
| 348 | + } |
|
| 349 | + } |
|
| 350 | + |
|
| 351 | + /** |
|
| 352 | + * File mime type validation callback |
|
| 353 | + * |
|
| 354 | + * @param mixed $object |
|
| 355 | + */ |
|
| 356 | + protected function check_mime_type($object) |
|
| 357 | + { |
|
| 358 | + if (!empty($object->mimes)) { |
|
| 359 | + if (!in_array($object->file['mime'], $object->mimes)) { |
|
| 360 | + $object->set_error('Mime type not allowed.'); |
|
| 361 | + } |
|
| 362 | + } |
|
| 363 | + } |
|
| 364 | + |
|
| 365 | + /** |
|
| 366 | + * Set allowed mime types |
|
| 367 | + * |
|
| 368 | + * @param array $mimes |
|
| 369 | + */ |
|
| 370 | + public function set_allowed_mime_types($mimes) |
|
| 371 | + { |
|
| 372 | + $this->mimes = $mimes; |
|
| 373 | + //if mime types is set -> set callback |
|
| 374 | + $this->callbacks[] = 'check_mime_type'; |
|
| 375 | + } |
|
| 376 | + |
|
| 377 | + /** |
|
| 378 | + * File size validation callback |
|
| 379 | + * |
|
| 380 | + * @param object $object |
|
| 381 | + */ |
|
| 382 | + protected function check_file_size($object) |
|
| 383 | + { |
|
| 384 | + if (!empty($object->max_file_size)) { |
|
| 385 | + $file_size_in_mb = $this->bytes_to_mb($object->file['size_in_bytes']); |
|
| 386 | + if ($object->max_file_size <= $file_size_in_mb) { |
|
| 387 | + $object->set_error('File is too big.'); |
|
| 388 | + } |
|
| 389 | + } |
|
| 390 | + } |
|
| 391 | + |
|
| 392 | + /** |
|
| 393 | + * Set max. file size |
|
| 394 | + * |
|
| 395 | + * @param int $size |
|
| 396 | + */ |
|
| 397 | + public function set_max_file_size($size) |
|
| 398 | + { |
|
| 399 | + $this->max_file_size = $size; |
|
| 400 | + //if max file size is set -> set callback |
|
| 401 | + $this->callbacks[] = 'check_file_size'; |
|
| 402 | + } |
|
| 403 | + |
|
| 404 | + /** |
|
| 405 | + * Set File array to object |
|
| 406 | + * |
|
| 407 | + * @param array $file |
|
| 408 | + */ |
|
| 409 | + public function file($file) |
|
| 410 | + { |
|
| 411 | + $this->set_file_array($file); |
|
| 412 | + } |
|
| 413 | + |
|
| 414 | + /** |
|
| 415 | + * Set file array |
|
| 416 | + * |
|
| 417 | + * @param array $file |
|
| 418 | + */ |
|
| 419 | + protected function set_file_array($file) |
|
| 420 | + { |
|
| 421 | + //checks whether file array is valid |
|
| 422 | + if (!$this->check_file_array($file)) { |
|
| 423 | + //file not selected or some bigger problems (broken files array) |
|
| 424 | + $this->set_error('Please select file.'); |
|
| 425 | + } |
|
| 426 | + |
|
| 427 | + //set file data |
|
| 428 | + $this->file_post = $file; |
|
| 429 | + |
|
| 430 | + //set tmp path |
|
| 431 | + $this->tmp_name = $file['tmp_name']; |
|
| 432 | + |
|
| 433 | + // set file extension |
|
| 434 | + $this->extension = pathinfo($file['name'], PATHINFO_EXTENSION); |
|
| 435 | + } |
|
| 436 | + |
|
| 437 | + /** |
|
| 438 | + * Checks whether Files post array is valid |
|
| 439 | + * |
|
| 440 | + * @return bool |
|
| 441 | + */ |
|
| 442 | + protected function check_file_array($file) |
|
| 443 | + { |
|
| 444 | + return isset($file['error']) |
|
| 445 | + && !empty($file['name']) |
|
| 446 | + && !empty($file['type']) |
|
| 447 | + && !empty($file['tmp_name']) |
|
| 448 | + && !empty($file['size']); |
|
| 449 | + } |
|
| 450 | + |
|
| 451 | + /** |
|
| 452 | + * Get file mime type |
|
| 453 | + * |
|
| 454 | + * @return string |
|
| 455 | + */ |
|
| 456 | + protected function get_file_mime() |
|
| 457 | + { |
|
| 458 | + return $this->finfo->file($this->tmp_name, FILEINFO_MIME_TYPE); |
|
| 459 | + } |
|
| 460 | + |
|
| 461 | + /** |
|
| 462 | + * Get file size |
|
| 463 | + * |
|
| 464 | + * @return int |
|
| 465 | + */ |
|
| 466 | + protected function get_file_size() |
|
| 467 | + { |
|
| 468 | + return filesize($this->tmp_name); |
|
| 469 | + } |
|
| 470 | + |
|
| 471 | + /** |
|
| 472 | + * Set destination path (return TRUE on success) |
|
| 473 | + * |
|
| 474 | + * @param string $destination |
|
| 475 | + * @return bool |
|
| 476 | + */ |
|
| 477 | + protected function set_destination($destination) |
|
| 478 | + { |
|
| 479 | + $this->destination = $destination . DIRECTORY_SEPARATOR; |
|
| 480 | + return $this->destination_exist() ? TRUE : $this->create_destination(); |
|
| 481 | + } |
|
| 482 | + |
|
| 483 | + /** |
|
| 484 | + * Checks whether destination folder exists |
|
| 485 | + * |
|
| 486 | + * @return bool |
|
| 487 | + */ |
|
| 488 | + protected function destination_exist() |
|
| 489 | + { |
|
| 490 | + return is_writable($this->root . $this->destination); |
|
| 491 | + } |
|
| 492 | + |
|
| 493 | + /** |
|
| 494 | + * Create path to destination |
|
| 495 | + * |
|
| 496 | + * @return bool |
|
| 497 | + */ |
|
| 498 | + protected function create_destination() |
|
| 499 | + { |
|
| 500 | + return mkdir($this->root . $this->destination, $this->default_permissions, true); |
|
| 501 | + } |
|
| 502 | + |
|
| 503 | + /** |
|
| 504 | + * Set unique filename |
|
| 505 | + * |
|
| 506 | + * @return string |
|
| 507 | + */ |
|
| 508 | + protected function create_new_filename() |
|
| 509 | + { |
|
| 510 | + $filename = sha1(mt_rand(1, 9999) . $this->destination . uniqid()) . time() . '.' . $this->extension; |
|
| 511 | + $this->set_filename($filename); |
|
| 512 | + } |
|
| 513 | + |
|
| 514 | + /** |
|
| 515 | + * Convert bytes to mb. |
|
| 516 | + * |
|
| 517 | + * @param int $bytes |
|
| 518 | + * @return int |
|
| 519 | + */ |
|
| 520 | + protected function bytes_to_mb($bytes) |
|
| 521 | + { |
|
| 522 | + return round(($bytes / 1048576), 2); |
|
| 523 | + } |
|
| 524 | 524 | |
| 525 | 525 | |
| 526 | 526 | } // end of Upload |
| 527 | 527 | \ No newline at end of file |
@@ -147,10 +147,10 @@ discard block |
||
| 147 | 147 | */ |
| 148 | 148 | public function __construct($phpbb_root_path) |
| 149 | 149 | { |
| 150 | - $phpbb_root_path = $phpbb_root_path . 'store/messenger/files'; |
|
| 150 | + $phpbb_root_path = $phpbb_root_path.'store/messenger/files'; |
|
| 151 | 151 | // set & create destination path |
| 152 | 152 | if (!$this->set_destination($phpbb_root_path)) { |
| 153 | - throw new Exception('Upload: Can\'t create destination. ' . $this->root . $this->destination); |
|
| 153 | + throw new Exception('Upload: Can\'t create destination. '.$this->root.$this->destination); |
|
| 154 | 154 | } |
| 155 | 155 | |
| 156 | 156 | //create finfo object |
@@ -244,8 +244,8 @@ discard block |
||
| 244 | 244 | $this->file['filename'] = $this->filename; |
| 245 | 245 | |
| 246 | 246 | //set full path |
| 247 | - $this->file['full_path'] = $this->root . $this->destination . $this->filename; |
|
| 248 | - $this->file['path'] = $this->destination . $this->filename; |
|
| 247 | + $this->file['full_path'] = $this->root.$this->destination.$this->filename; |
|
| 248 | + $this->file['path'] = $this->destination.$this->filename; |
|
| 249 | 249 | |
| 250 | 250 | $status = move_uploaded_file($this->tmp_name, $this->file['full_path']); |
| 251 | 251 | |
@@ -476,7 +476,7 @@ discard block |
||
| 476 | 476 | */ |
| 477 | 477 | protected function set_destination($destination) |
| 478 | 478 | { |
| 479 | - $this->destination = $destination . DIRECTORY_SEPARATOR; |
|
| 479 | + $this->destination = $destination.DIRECTORY_SEPARATOR; |
|
| 480 | 480 | return $this->destination_exist() ? TRUE : $this->create_destination(); |
| 481 | 481 | } |
| 482 | 482 | |
@@ -487,7 +487,7 @@ discard block |
||
| 487 | 487 | */ |
| 488 | 488 | protected function destination_exist() |
| 489 | 489 | { |
| 490 | - return is_writable($this->root . $this->destination); |
|
| 490 | + return is_writable($this->root.$this->destination); |
|
| 491 | 491 | } |
| 492 | 492 | |
| 493 | 493 | /** |
@@ -497,7 +497,7 @@ discard block |
||
| 497 | 497 | */ |
| 498 | 498 | protected function create_destination() |
| 499 | 499 | { |
| 500 | - return mkdir($this->root . $this->destination, $this->default_permissions, true); |
|
| 500 | + return mkdir($this->root.$this->destination, $this->default_permissions, true); |
|
| 501 | 501 | } |
| 502 | 502 | |
| 503 | 503 | /** |
@@ -507,7 +507,7 @@ discard block |
||
| 507 | 507 | */ |
| 508 | 508 | protected function create_new_filename() |
| 509 | 509 | { |
| 510 | - $filename = sha1(mt_rand(1, 9999) . $this->destination . uniqid()) . time() . '.' . $this->extension; |
|
| 510 | + $filename = sha1(mt_rand(1, 9999).$this->destination.uniqid()).time().'.'.$this->extension; |
|
| 511 | 511 | $this->set_filename($filename); |
| 512 | 512 | } |
| 513 | 513 | |
@@ -6,98 +6,98 @@ |
||
| 6 | 6 | |
| 7 | 7 | class database extends \PDO |
| 8 | 8 | { |
| 9 | - protected $extension_manager; |
|
| 10 | - |
|
| 11 | - public function __construct() |
|
| 12 | - { |
|
| 13 | - global $phpbb_root_path; |
|
| 14 | - |
|
| 15 | - $database = $phpbb_root_path . 'store/messenger.db'; |
|
| 16 | - parent::__construct('sqlite:' . $database); |
|
| 17 | - parent::setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); |
|
| 18 | - } |
|
| 19 | - |
|
| 20 | - /** |
|
| 21 | - * @param string $sql |
|
| 22 | - * @return array |
|
| 23 | - */ |
|
| 24 | - public function select($sql, $array = array(), $fetchMode = PDO::FETCH_ASSOC) |
|
| 25 | - { |
|
| 26 | - $sth = $this->prepare($sql); |
|
| 27 | - foreach ($array as $key => $value) { |
|
| 28 | - $sth->bindValue("$key", $value); |
|
| 29 | - } |
|
| 30 | - |
|
| 31 | - $sth->execute(); |
|
| 32 | - return $sth->fetchAll($fetchMode); |
|
| 33 | - } |
|
| 34 | - |
|
| 35 | - /** |
|
| 36 | - * @param string $table |
|
| 37 | - * @return bool |
|
| 38 | - */ |
|
| 39 | - public function insert($table, $data) |
|
| 40 | - { |
|
| 41 | - //ksort($data); |
|
| 42 | - |
|
| 43 | - $fieldNames = implode('`, `', array_keys($data)); |
|
| 44 | - $fieldValues = ':' . implode(', :', array_keys($data)); |
|
| 45 | - |
|
| 46 | - $sth = $this->prepare("INSERT INTO $table (`$fieldNames`) VALUES ($fieldValues)"); |
|
| 47 | - |
|
| 48 | - foreach ($data as $key => $value) { |
|
| 49 | - $sth->bindValue(":$key", $value); |
|
| 50 | - } |
|
| 51 | - |
|
| 52 | - return $sth->execute(); |
|
| 53 | - } |
|
| 54 | - |
|
| 55 | - /** |
|
| 56 | - * @param string $table |
|
| 57 | - * @param array $data |
|
| 58 | - * @param string $where |
|
| 59 | - * @return bool |
|
| 60 | - */ |
|
| 61 | - public function update($table, $data, $where) |
|
| 62 | - { |
|
| 63 | - ksort($data); |
|
| 64 | - |
|
| 65 | - $fieldDetails = NULL; |
|
| 66 | - foreach ($data as $key => $value) { |
|
| 67 | - $fieldDetails .= "`$key`=:$key,"; |
|
| 68 | - } |
|
| 69 | - $fieldDetails = rtrim($fieldDetails, ','); |
|
| 70 | - |
|
| 71 | - $sth = $this->prepare("UPDATE $table SET $fieldDetails WHERE $where"); |
|
| 72 | - |
|
| 73 | - foreach ($data as $key => $value) { |
|
| 74 | - $sth->bindValue(":$key", $value); |
|
| 75 | - } |
|
| 76 | - |
|
| 77 | - return $sth->execute(); |
|
| 78 | - } |
|
| 79 | - |
|
| 80 | - /** |
|
| 81 | - * @param string $table |
|
| 82 | - * @param string $where |
|
| 83 | - * @param int $limit |
|
| 84 | - * @return int |
|
| 85 | - */ |
|
| 86 | - public function delete($table, $where, $limit = 1) |
|
| 87 | - { |
|
| 88 | - return $this->exec("DELETE FROM $table WHERE $where LIMIT $limit"); |
|
| 89 | - } |
|
| 90 | - |
|
| 91 | - protected function find($path, $prefix, $suffix) |
|
| 92 | - { |
|
| 93 | - $finder = $this->extension_manager->get_finder(); |
|
| 94 | - |
|
| 95 | - return $finder |
|
| 96 | - ->set_extensions(array('phpbb/messenger')) |
|
| 97 | - ->prefix($prefix) |
|
| 98 | - ->suffix($suffix) |
|
| 99 | - ->core_path("$path/") |
|
| 100 | - ->extension_directory("/$path") |
|
| 101 | - ->find(); |
|
| 102 | - } |
|
| 9 | + protected $extension_manager; |
|
| 10 | + |
|
| 11 | + public function __construct() |
|
| 12 | + { |
|
| 13 | + global $phpbb_root_path; |
|
| 14 | + |
|
| 15 | + $database = $phpbb_root_path . 'store/messenger.db'; |
|
| 16 | + parent::__construct('sqlite:' . $database); |
|
| 17 | + parent::setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); |
|
| 18 | + } |
|
| 19 | + |
|
| 20 | + /** |
|
| 21 | + * @param string $sql |
|
| 22 | + * @return array |
|
| 23 | + */ |
|
| 24 | + public function select($sql, $array = array(), $fetchMode = PDO::FETCH_ASSOC) |
|
| 25 | + { |
|
| 26 | + $sth = $this->prepare($sql); |
|
| 27 | + foreach ($array as $key => $value) { |
|
| 28 | + $sth->bindValue("$key", $value); |
|
| 29 | + } |
|
| 30 | + |
|
| 31 | + $sth->execute(); |
|
| 32 | + return $sth->fetchAll($fetchMode); |
|
| 33 | + } |
|
| 34 | + |
|
| 35 | + /** |
|
| 36 | + * @param string $table |
|
| 37 | + * @return bool |
|
| 38 | + */ |
|
| 39 | + public function insert($table, $data) |
|
| 40 | + { |
|
| 41 | + //ksort($data); |
|
| 42 | + |
|
| 43 | + $fieldNames = implode('`, `', array_keys($data)); |
|
| 44 | + $fieldValues = ':' . implode(', :', array_keys($data)); |
|
| 45 | + |
|
| 46 | + $sth = $this->prepare("INSERT INTO $table (`$fieldNames`) VALUES ($fieldValues)"); |
|
| 47 | + |
|
| 48 | + foreach ($data as $key => $value) { |
|
| 49 | + $sth->bindValue(":$key", $value); |
|
| 50 | + } |
|
| 51 | + |
|
| 52 | + return $sth->execute(); |
|
| 53 | + } |
|
| 54 | + |
|
| 55 | + /** |
|
| 56 | + * @param string $table |
|
| 57 | + * @param array $data |
|
| 58 | + * @param string $where |
|
| 59 | + * @return bool |
|
| 60 | + */ |
|
| 61 | + public function update($table, $data, $where) |
|
| 62 | + { |
|
| 63 | + ksort($data); |
|
| 64 | + |
|
| 65 | + $fieldDetails = NULL; |
|
| 66 | + foreach ($data as $key => $value) { |
|
| 67 | + $fieldDetails .= "`$key`=:$key,"; |
|
| 68 | + } |
|
| 69 | + $fieldDetails = rtrim($fieldDetails, ','); |
|
| 70 | + |
|
| 71 | + $sth = $this->prepare("UPDATE $table SET $fieldDetails WHERE $where"); |
|
| 72 | + |
|
| 73 | + foreach ($data as $key => $value) { |
|
| 74 | + $sth->bindValue(":$key", $value); |
|
| 75 | + } |
|
| 76 | + |
|
| 77 | + return $sth->execute(); |
|
| 78 | + } |
|
| 79 | + |
|
| 80 | + /** |
|
| 81 | + * @param string $table |
|
| 82 | + * @param string $where |
|
| 83 | + * @param int $limit |
|
| 84 | + * @return int |
|
| 85 | + */ |
|
| 86 | + public function delete($table, $where, $limit = 1) |
|
| 87 | + { |
|
| 88 | + return $this->exec("DELETE FROM $table WHERE $where LIMIT $limit"); |
|
| 89 | + } |
|
| 90 | + |
|
| 91 | + protected function find($path, $prefix, $suffix) |
|
| 92 | + { |
|
| 93 | + $finder = $this->extension_manager->get_finder(); |
|
| 94 | + |
|
| 95 | + return $finder |
|
| 96 | + ->set_extensions(array('phpbb/messenger')) |
|
| 97 | + ->prefix($prefix) |
|
| 98 | + ->suffix($suffix) |
|
| 99 | + ->core_path("$path/") |
|
| 100 | + ->extension_directory("/$path") |
|
| 101 | + ->find(); |
|
| 102 | + } |
|
| 103 | 103 | } |
@@ -12,8 +12,8 @@ discard block |
||
| 12 | 12 | { |
| 13 | 13 | global $phpbb_root_path; |
| 14 | 14 | |
| 15 | - $database = $phpbb_root_path . 'store/messenger.db'; |
|
| 16 | - parent::__construct('sqlite:' . $database); |
|
| 15 | + $database = $phpbb_root_path.'store/messenger.db'; |
|
| 16 | + parent::__construct('sqlite:'.$database); |
|
| 17 | 17 | parent::setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); |
| 18 | 18 | } |
| 19 | 19 | |
@@ -41,7 +41,7 @@ discard block |
||
| 41 | 41 | //ksort($data); |
| 42 | 42 | |
| 43 | 43 | $fieldNames = implode('`, `', array_keys($data)); |
| 44 | - $fieldValues = ':' . implode(', :', array_keys($data)); |
|
| 44 | + $fieldValues = ':'.implode(', :', array_keys($data)); |
|
| 45 | 45 | |
| 46 | 46 | $sth = $this->prepare("INSERT INTO $table (`$fieldNames`) VALUES ($fieldValues)"); |
| 47 | 47 | |