Browse Source

Update PHP files to use PSR-2 via StyleCI's checks

pull/34/head
Amelia Ikeda 3 years ago
parent
commit
49f166e640
100 changed files with 8196 additions and 7792 deletions
  1. 4
    0
      .styleci.yml
  2. 72
    74
      app/Console/Commands/ModdingQueueUpdateCommand.php
  3. 71
    76
      app/Console/Commands/ModdingRankCommand.php
  4. 72
    74
      app/Console/Commands/ModdingScoreIndexCommand.php
  5. 39
    39
      app/Console/Commands/SilentEnabledCommand.php
  6. 149
    161
      app/Console/Commands/StoreCheckOrderTrackingStatus.php
  7. 46
    47
      app/Console/Kernel.php
  8. 86
    83
      app/Contracts/OsuHasher.php
  9. 20
    22
      app/Events/Event.php
  10. 28
    30
      app/Events/Forum/TopicUpdate.php
  11. 18
    19
      app/Events/Forum/TopicWasCreated.php
  12. 18
    19
      app/Events/Forum/TopicWasReplied.php
  13. 18
    19
      app/Events/Forum/TopicWasViewed.php
  14. 117
    113
      app/Exceptions/Handler.php
  15. 173
    165
      app/Http/Controllers/APIController.php
  16. 46
    49
      app/Http/Controllers/AccountController.php
  17. 91
    88
      app/Http/Controllers/BeatmapController.php
  18. 40
    44
      app/Http/Controllers/CommunityController.php
  19. 31
    32
      app/Http/Controllers/Controller.php
  20. 33
    33
      app/Http/Controllers/Forum/Controller.php
  21. 42
    41
      app/Http/Controllers/Forum/ForumsController.php
  22. 89
    84
      app/Http/Controllers/Forum/PostsController.php
  23. 160
    158
      app/Http/Controllers/Forum/TopicsController.php
  24. 29
    28
      app/Http/Controllers/ForumController.php
  25. 32
    31
      app/Http/Controllers/HelpController.php
  26. 49
    46
      app/Http/Controllers/HomeController.php
  27. 29
    29
      app/Http/Controllers/ModdingController.php
  28. 113
    119
      app/Http/Controllers/ModdingPostController.php
  29. 138
    132
      app/Http/Controllers/NotificationController.php
  30. 113
    118
      app/Http/Controllers/PostController.php
  31. 40
    38
      app/Http/Controllers/RankingController.php
  32. 263
    247
      app/Http/Controllers/StoreController.php
  33. 61
    54
      app/Http/Controllers/TournamentsController.php
  34. 133
    129
      app/Http/Controllers/UsersController.php
  35. 45
    47
      app/Http/Kernel.php
  36. 55
    58
      app/Http/Middleware/Authenticate.php
  37. 52
    51
      app/Http/Middleware/CheckUserBanStatus.php
  38. 52
    53
      app/Http/Middleware/RedirectIfAuthenticated.php
  39. 29
    31
      app/Http/Middleware/UpdateUserLastvisit.php
  40. 31
    32
      app/Http/Middleware/VerifyCsrfToken.php
  41. 20
    22
      app/Http/Requests/Request.php
  42. 73
    78
      app/Http/routes.php
  43. 21
    22
      app/Jobs/Job.php
  44. 295
    274
      app/Libraries/BBCodeForDB.php
  45. 268
    245
      app/Libraries/BBCodeFromDB.php
  46. 31
    30
      app/Libraries/CleanHTML.php
  47. 188
    178
      app/Libraries/ProfileCover.php
  48. 29
    30
      app/Libraries/StorageLocal.php
  49. 46
    47
      app/Libraries/StorageS3v2.php
  50. 35
    36
      app/Listeners/Forum/MarkTopicRead.php
  51. 133
    134
      app/Listeners/Forum/NotifySlack.php
  52. 25
    26
      app/Models/Achievement.php
  53. 23
    24
      app/Models/Api.php
  54. 41
    41
      app/Models/Beatmap.php
  55. 334
    274
      app/Models/BeatmapSet.php
  56. 43
    43
      app/Models/Changelog.php
  57. 28
    27
      app/Models/Country.php
  58. 21
    21
      app/Models/DeletedUser.php
  59. 84
    69
      app/Models/Forum/Authorize.php
  60. 153
    138
      app/Models/Forum/Forum.php
  61. 176
    157
      app/Models/Forum/Post.php
  62. 297
    272
      app/Models/Forum/Topic.php
  63. 50
    47
      app/Models/Forum/TopicTrack.php
  64. 46
    46
      app/Models/Group.php
  65. 42
    39
      app/Models/LoginAttempt.php
  66. 198
    171
      app/Models/Mod.php
  67. 20
    20
      app/Models/ModdingPost.php
  68. 80
    80
      app/Models/Notification.php
  69. 29
    29
      app/Models/Post.php
  70. 26
    25
      app/Models/Rank.php
  71. 26
    26
      app/Models/Smiley.php
  72. 60
    59
      app/Models/Store/Address.php
  73. 242
    220
      app/Models/Store/Order.php
  74. 53
    48
      app/Models/Store/OrderItem.php
  75. 140
    128
      app/Models/Store/Product.php
  76. 107
    95
      app/Models/Tournament.php
  77. 34
    37
      app/Models/TournamentRegistration.php
  78. 682
    573
      app/Models/User.php
  79. 32
    33
      app/Models/UserAchievement.php
  80. 42
    44
      app/Models/UserBanHistory.php
  81. 48
    48
      app/Models/UserProfileCustomization.php
  82. 18
    19
      app/Models/UserStatistics/Ctb.php
  83. 18
    19
      app/Models/UserStatistics/Mania.php
  84. 109
    108
      app/Models/UserStatistics/Model.php
  85. 18
    19
      app/Models/UserStatistics/Osu.php
  86. 18
    19
      app/Models/UserStatistics/Taiko.php
  87. 25
    26
      app/Models/UsernameChangeHistory.php
  88. 44
    46
      app/Providers/AppServiceProvider.php
  89. 43
    45
      app/Providers/BusServiceProvider.php
  90. 34
    36
      app/Providers/ConfigServiceProvider.php
  91. 45
    46
      app/Providers/EventServiceProvider.php
  92. 23
    22
      app/Providers/OsuHashServiceProvider.php
  93. 53
    54
      app/Providers/RouteServiceProvider.php
  94. 23
    24
      app/Traits/BeatmapAPI.php
  95. 294
    287
      app/Traits/ModdingAPI.php
  96. 28
    29
      app/Transformers/UserAchievementTransformer.php
  97. 50
    51
      app/Transformers/UserStatisticsTransformer.php
  98. 41
    42
      app/Transformers/UserTransformer.php
  99. 264
    231
      app/helpers.php
  100. 0
    0
      app/jobs/ModdingQueue.php

+ 4
- 0
.styleci.yml View File

@@ -0,0 +1,4 @@
1
+preset: laravel
2
+
3
+enabled:
4
+  - unalign_double_arrow

+ 72
- 74
app/Console/Commands/ModdingQueueUpdateCommand.php View File

@@ -1,89 +1,87 @@
1 1
 <?php
2 2
 
3 3
 /**
4
-*    Copyright 2015 ppy Pty. Ltd.
5
-*
6
-*    This file is part of osu!web. osu!web is distributed with the hope of
7
-*    attracting more community contributions to the core ecosystem of osu!.
8
-*
9
-*    osu!web is free software: you can redistribute it and/or modify
10
-*    it under the terms of the Affero GNU General Public License as published by
11
-*    the Free Software Foundation, either version 3 of the License, or
12
-*    (at your option) any later version.
13
-*
14
-*    osu!web is distributed WITHOUT ANY WARRANTY; without even the implied
15
-*    warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16
-*    See the GNU Affero General Public License for more details.
17
-*
18
-*    You should have received a copy of the GNU Affero General Public License
19
-*    along with osu!web.  If not, see <http://www.gnu.org/licenses/>.
20
-*
21
-*/
4
+ *    Copyright 2015 ppy Pty. Ltd.
5
+ *
6
+ *    This file is part of osu!web. osu!web is distributed with the hope of
7
+ *    attracting more community contributions to the core ecosystem of osu!.
8
+ *
9
+ *    osu!web is free software: you can redistribute it and/or modify
10
+ *    it under the terms of the Affero GNU General Public License as published by
11
+ *    the Free Software Foundation, either version 3 of the License, or
12
+ *    (at your option) any later version.
13
+ *
14
+ *    osu!web is distributed WITHOUT ANY WARRANTY; without even the implied
15
+ *    warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16
+ *    See the GNU Affero General Public License for more details.
17
+ *
18
+ *    You should have received a copy of the GNU Affero General Public License
19
+ *    along with osu!web.  If not, see <http://www.gnu.org/licenses/>.
20
+ */
22 21
 
23 22
 namespace App\Console\Commands;
24 23
 
25 24
 use Illuminate\Console\Command;
26
-use Symfony\Component\Console\Input\InputOption;
27 25
 use Symfony\Component\Console\Input\InputArgument;
26
+use Symfony\Component\Console\Input\InputOption;
28 27
 
29
-class ModdingQueueUpdateCommand extends Command {
30
-
31
-	/**
32
-	 * The console command name.
33
-	 *
34
-	 * @var string
35
-	 */
36
-	protected $name = 'modding:queue-update';
37
-
38
-	/**
39
-	 * The console command description.
40
-	 *
41
-	 * @var string
42
-	 */
43
-	protected $description = 'Process the global modding queue.';
28
+class ModdingQueueUpdateCommand extends Command
29
+{
30
+    /**
31
+     * The console command name.
32
+     *
33
+     * @var string
34
+     */
35
+    protected $name = 'modding:queue-update';
44 36
 
45
-	/**
46
-	 * Create a new command instance.
47
-	 *
48
-	 * @return void
49
-	 */
50
-	public function __construct()
51
-	{
52
-		parent::__construct();
53
-	}
37
+    /**
38
+     * The console command description.
39
+     *
40
+     * @var string
41
+     */
42
+    protected $description = 'Process the global modding queue.';
54 43
 
55
-	/**
56
-	 * Execute the console command.
57
-	 *
58
-	 * @return mixed
59
-	 */
60
-	public function fire()
61
-	{
62
-		//
63
-	}
44
+    /**
45
+     * Create a new command instance.
46
+     *
47
+     * @return void
48
+     */
49
+    public function __construct()
50
+    {
51
+        parent::__construct();
52
+    }
64 53
 
65
-	/**
66
-	 * Get the console command arguments.
67
-	 *
68
-	 * @return array
69
-	 */
70
-	protected function getArguments()
71
-	{
72
-		return array(
73
-			array('example', InputArgument::REQUIRED, 'An example argument.'),
74
-		);
75
-	}
54
+    /**
55
+     * Execute the console command.
56
+     *
57
+     * @return mixed
58
+     */
59
+    public function fire()
60
+    {
61
+        //
62
+    }
76 63
 
77
-	/**
78
-	 * Get the console command options.
79
-	 *
80
-	 * @return array
81
-	 */
82
-	protected function getOptions()
83
-	{
84
-		return array(
85
-			array('example', null, InputOption::VALUE_OPTIONAL, 'An example option.', null),
86
-		);
87
-	}
64
+    /**
65
+     * Get the console command arguments.
66
+     *
67
+     * @return array
68
+     */
69
+    protected function getArguments()
70
+    {
71
+        return [
72
+            ['example', InputArgument::REQUIRED, 'An example argument.'],
73
+        ];
74
+    }
88 75
 
76
+    /**
77
+     * Get the console command options.
78
+     *
79
+     * @return array
80
+     */
81
+    protected function getOptions()
82
+    {
83
+        return [
84
+            ['example', null, InputOption::VALUE_OPTIONAL, 'An example option.', null],
85
+        ];
86
+    }
89 87
 }

+ 71
- 76
app/Console/Commands/ModdingRankCommand.php View File

@@ -1,91 +1,86 @@
1 1
 <?php
2 2
 
3 3
 /**
4
-*    Copyright 2015 ppy Pty. Ltd.
5
-*
6
-*    This file is part of osu!web. osu!web is distributed with the hope of
7
-*    attracting more community contributions to the core ecosystem of osu!.
8
-*
9
-*    osu!web is free software: you can redistribute it and/or modify
10
-*    it under the terms of the Affero GNU General Public License as published by
11
-*    the Free Software Foundation, either version 3 of the License, or
12
-*    (at your option) any later version.
13
-*
14
-*    osu!web is distributed WITHOUT ANY WARRANTY; without even the implied
15
-*    warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16
-*    See the GNU Affero General Public License for more details.
17
-*
18
-*    You should have received a copy of the GNU Affero General Public License
19
-*    along with osu!web.  If not, see <http://www.gnu.org/licenses/>.
20
-*
21
-*/
4
+ *    Copyright 2015 ppy Pty. Ltd.
5
+ *
6
+ *    This file is part of osu!web. osu!web is distributed with the hope of
7
+ *    attracting more community contributions to the core ecosystem of osu!.
8
+ *
9
+ *    osu!web is free software: you can redistribute it and/or modify
10
+ *    it under the terms of the Affero GNU General Public License as published by
11
+ *    the Free Software Foundation, either version 3 of the License, or
12
+ *    (at your option) any later version.
13
+ *
14
+ *    osu!web is distributed WITHOUT ANY WARRANTY; without even the implied
15
+ *    warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16
+ *    See the GNU Affero General Public License for more details.
17
+ *
18
+ *    You should have received a copy of the GNU Affero General Public License
19
+ *    along with osu!web.  If not, see <http://www.gnu.org/licenses/>.
20
+ */
22 21
 
23 22
 namespace App\Console\Commands;
24 23
 
25 24
 use Illuminate\Console\Command;
26
-use Symfony\Component\Console\Input\InputOption;
27
-use Symfony\Component\Console\Input\InputArgument;
28 25
 
29
-class ModdingRankCommand extends Command {
26
+class ModdingRankCommand extends Command
27
+{
28
+    /**
29
+     * The console command name.
30
+     *
31
+     * @var string
32
+     */
33
+    protected $name = 'modding:rank';
30 34
 
31
-	/**
32
-	 * The console command name.
33
-	 *
34
-	 * @var string
35
-	 */
36
-	protected $name = 'modding:rank';
35
+    /**
36
+     * The console command description.
37
+     *
38
+     * @var string
39
+     */
40
+    protected $description = 'Process Queued Qualified maps that meet the criteria for ranking.';
37 41
 
38
-	/**
39
-	 * The console command description.
40
-	 *
41
-	 * @var string
42
-	 */
43
-	protected $description = 'Process Queued Qualified maps that meet the criteria for ranking.';
42
+    /**
43
+     * Create a new command instance.
44
+     *
45
+     * @return void
46
+     */
47
+    public function __construct()
48
+    {
49
+        parent::__construct();
50
+    }
44 51
 
45
-	/**
46
-	 * Create a new command instance.
47
-	 *
48
-	 * @return void
49
-	 */
50
-	public function __construct()
51
-	{
52
-		parent::__construct();
53
-	}
52
+    /**
53
+     * Execute the console command.
54
+     *
55
+     * @return mixed
56
+     */
57
+    public function fire()
58
+    {
59
+        $rankable = BeatmapSet::rankable();
54 60
 
55
-	/**
56
-	 * Execute the console command.
57
-	 *
58
-	 * @return mixed
59
-	 */
60
-	public function fire()
61
-	{
62
-		$rankable = BeatmapSet::rankable();
61
+        if ($rankable) {
62
+            foreach ($rankable as $rank) {
63
+            }
64
+        }
65
+    }
63 66
 
64
-		if ($rankable) {
65
-			foreach ($rankable as $rank) {
66
-
67
-			}
68
-		}
69
-	}
70
-
71
-	/**
72
-	 * Get the console command arguments.
73
-	 *
74
-	 * @return array
75
-	 */
76
-	protected function getArguments()
77
-	{
78
-		return array();
79
-	}
80
-
81
-	/**
82
-	 * Get the console command options.
83
-	 *
84
-	 * @return array
85
-	 */
86
-	protected function getOptions()
87
-	{
88
-		return array();
89
-	}
67
+    /**
68
+     * Get the console command arguments.
69
+     *
70
+     * @return array
71
+     */
72
+    protected function getArguments()
73
+    {
74
+        return [];
75
+    }
90 76
 
77
+    /**
78
+     * Get the console command options.
79
+     *
80
+     * @return array
81
+     */
82
+    protected function getOptions()
83
+    {
84
+        return [];
85
+    }
91 86
 }

+ 72
- 74
app/Console/Commands/ModdingScoreIndexCommand.php View File

@@ -1,89 +1,87 @@
1 1
 <?php
2 2
 
3 3
 /**
4
-*    Copyright 2015 ppy Pty. Ltd.
5
-*
6
-*    This file is part of osu!web. osu!web is distributed with the hope of
7
-*    attracting more community contributions to the core ecosystem of osu!.
8
-*
9
-*    osu!web is free software: you can redistribute it and/or modify
10
-*    it under the terms of the Affero GNU General Public License as published by
11
-*    the Free Software Foundation, either version 3 of the License, or
12
-*    (at your option) any later version.
13
-*
14
-*    osu!web is distributed WITHOUT ANY WARRANTY; without even the implied
15
-*    warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16
-*    See the GNU Affero General Public License for more details.
17
-*
18
-*    You should have received a copy of the GNU Affero General Public License
19
-*    along with osu!web.  If not, see <http://www.gnu.org/licenses/>.
20
-*
21
-*/
4
+ *    Copyright 2015 ppy Pty. Ltd.
5
+ *
6
+ *    This file is part of osu!web. osu!web is distributed with the hope of
7
+ *    attracting more community contributions to the core ecosystem of osu!.
8
+ *
9
+ *    osu!web is free software: you can redistribute it and/or modify
10
+ *    it under the terms of the Affero GNU General Public License as published by
11
+ *    the Free Software Foundation, either version 3 of the License, or
12
+ *    (at your option) any later version.
13
+ *
14
+ *    osu!web is distributed WITHOUT ANY WARRANTY; without even the implied
15
+ *    warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16
+ *    See the GNU Affero General Public License for more details.
17
+ *
18
+ *    You should have received a copy of the GNU Affero General Public License
19
+ *    along with osu!web.  If not, see <http://www.gnu.org/licenses/>.
20
+ */
22 21
 
23 22
 namespace App\Console\Commands;
24 23
 
25 24
 use Illuminate\Console\Command;
26
-use Symfony\Component\Console\Input\InputOption;
27 25
 use Symfony\Component\Console\Input\InputArgument;
26
+use Symfony\Component\Console\Input\InputOption;
28 27
 
29
-class ModdingScoreIndexCommand extends Command {
30
-
31
-	/**
32
-	 * The console command name.
33
-	 *
34
-	 * @var string
35
-	 */
36
-	protected $name = 'modding:index';
37
-
38
-	/**
39
-	 * The console command description.
40
-	 *
41
-	 * @var string
42
-	 */
43
-	protected $description = "Process users' modding points and award (or remove) new privileges";
28
+class ModdingScoreIndexCommand extends Command
29
+{
30
+    /**
31
+     * The console command name.
32
+     *
33
+     * @var string
34
+     */
35
+    protected $name = 'modding:index';
44 36
 
45
-	/**
46
-	 * Create a new command instance.
47
-	 *
48
-	 * @return void
49
-	 */
50
-	public function __construct()
51
-	{
52
-		parent::__construct();
53
-	}
37
+    /**
38
+     * The console command description.
39
+     *
40
+     * @var string
41
+     */
42
+    protected $description = "Process users' modding points and award (or remove) new privileges";
54 43
 
55
-	/**
56
-	 * Execute the console command.
57
-	 *
58
-	 * @return mixed
59
-	 */
60
-	public function fire()
61
-	{
62
-		//
63
-	}
44
+    /**
45
+     * Create a new command instance.
46
+     *
47
+     * @return void
48
+     */
49
+    public function __construct()
50
+    {
51
+        parent::__construct();
52
+    }
64 53
 
65
-	/**
66
-	 * Get the console command arguments.
67
-	 *
68
-	 * @return array
69
-	 */
70
-	protected function getArguments()
71
-	{
72
-		return array(
73
-			array('example', InputArgument::REQUIRED, 'An example argument.'),
74
-		);
75
-	}
54
+    /**
55
+     * Execute the console command.
56
+     *
57
+     * @return mixed
58
+     */
59
+    public function fire()
60
+    {
61
+        //
62
+    }
76 63
 
77
-	/**
78
-	 * Get the console command options.
79
-	 *
80
-	 * @return array
81
-	 */
82
-	protected function getOptions()
83
-	{
84
-		return array(
85
-			array('example', null, InputOption::VALUE_OPTIONAL, 'An example option.', null),
86
-		);
87
-	}
64
+    /**
65
+     * Get the console command arguments.
66
+     *
67
+     * @return array
68
+     */
69
+    protected function getArguments()
70
+    {
71
+        return [
72
+            ['example', InputArgument::REQUIRED, 'An example argument.'],
73
+        ];
74
+    }
88 75
 
76
+    /**
77
+     * Get the console command options.
78
+     *
79
+     * @return array
80
+     */
81
+    protected function getOptions()
82
+    {
83
+        return [
84
+            ['example', null, InputOption::VALUE_OPTIONAL, 'An example option.', null],
85
+        ];
86
+    }
89 87
 }

+ 39
- 39
app/Console/Commands/SilentEnabledCommand.php View File

@@ -1,49 +1,49 @@
1 1
 <?php
2 2
 
3 3
 /**
4
-*    Copyright 2015 ppy Pty. Ltd.
5
-*
6
-*    This file is part of osu!web. osu!web is distributed with the hope of
7
-*    attracting more community contributions to the core ecosystem of osu!.
8
-*
9
-*    osu!web is free software: you can redistribute it and/or modify
10
-*    it under the terms of the Affero GNU General Public License as published by
11
-*    the Free Software Foundation, either version 3 of the License, or
12
-*    (at your option) any later version.
13
-*
14
-*    osu!web is distributed WITHOUT ANY WARRANTY; without even the implied
15
-*    warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16
-*    See the GNU Affero General Public License for more details.
17
-*
18
-*    You should have received a copy of the GNU Affero General Public License
19
-*    along with osu!web.  If not, see <http://www.gnu.org/licenses/>.
20
-*
21
-*/
4
+ *    Copyright 2015 ppy Pty. Ltd.
5
+ *
6
+ *    This file is part of osu!web. osu!web is distributed with the hope of
7
+ *    attracting more community contributions to the core ecosystem of osu!.
8
+ *
9
+ *    osu!web is free software: you can redistribute it and/or modify
10
+ *    it under the terms of the Affero GNU General Public License as published by
11
+ *    the Free Software Foundation, either version 3 of the License, or
12
+ *    (at your option) any later version.
13
+ *
14
+ *    osu!web is distributed WITHOUT ANY WARRANTY; without even the implied
15
+ *    warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16
+ *    See the GNU Affero General Public License for more details.
17
+ *
18
+ *    You should have received a copy of the GNU Affero General Public License
19
+ *    along with osu!web.  If not, see <http://www.gnu.org/licenses/>.
20
+ */
22 21
 
23 22
 namespace App\Console\Commands;
24 23
 
25 24
 use Illuminate\Console\Command;
26 25
 use Symfony\Component\Console\Input\InputOption;
27
-use Symfony\Component\Console\Input\InputArgument;
28
-
29
-abstract class SilentEnabledCommand extends Command {
30
-
31
-	public function info($string) {
32
-		if (!$this->option("silent")) {
33
-			parent::info($string);
34
-		}
35
-	}
36
-
37
-	public function comment($string) {
38
-		if (!$this->option("silent")) {
39
-			parent::comment($string);
40
-		}
41
-	}
42
-
43
-	public function getOptions() {
44
-		return [
45
-			["silent", null, InputOption::VALUE_NONE, 'Silence the output from the function', null],
46
-		];
47
-	}
48 26
 
27
+abstract class SilentEnabledCommand extends Command
28
+{
29
+    public function info($string)
30
+    {
31
+        if (! $this->option('silent')) {
32
+            parent::info($string);
33
+        }
34
+    }
35
+
36
+    public function comment($string)
37
+    {
38
+        if (! $this->option('silent')) {
39
+            parent::comment($string);
40
+        }
41
+    }
42
+
43
+    public function getOptions()
44
+    {
45
+        return [
46
+            ['silent', null, InputOption::VALUE_NONE, 'Silence the output from the function', null],
47
+        ];
48
+    }
49 49
 }

+ 149
- 161
app/Console/Commands/StoreCheckOrderTrackingStatus.php View File

@@ -1,121 +1,113 @@
1 1
 <?php
2 2
 
3 3
 /**
4
-*    Copyright 2015 ppy Pty. Ltd.
5
-*
6
-*    This file is part of osu!web. osu!web is distributed with the hope of
7
-*    attracting more community contributions to the core ecosystem of osu!.
8
-*
9
-*    osu!web is free software: you can redistribute it and/or modify
10
-*    it under the terms of the Affero GNU General Public License as published by
11
-*    the Free Software Foundation, either version 3 of the License, or
12
-*    (at your option) any later version.
13
-*
14
-*    osu!web is distributed WITHOUT ANY WARRANTY; without even the implied
15
-*    warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16
-*    See the GNU Affero General Public License for more details.
17
-*
18
-*    You should have received a copy of the GNU Affero General Public License
19
-*    along with osu!web.  If not, see <http://www.gnu.org/licenses/>.
20
-*
21
-*/
4
+ *    Copyright 2015 ppy Pty. Ltd.
5
+ *
6
+ *    This file is part of osu!web. osu!web is distributed with the hope of
7
+ *    attracting more community contributions to the core ecosystem of osu!.
8
+ *
9
+ *    osu!web is free software: you can redistribute it and/or modify
10
+ *    it under the terms of the Affero GNU General Public License as published by
11
+ *    the Free Software Foundation, either version 3 of the License, or
12
+ *    (at your option) any later version.
13
+ *
14
+ *    osu!web is distributed WITHOUT ANY WARRANTY; without even the implied
15
+ *    warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16
+ *    See the GNU Affero General Public License for more details.
17
+ *
18
+ *    You should have received a copy of the GNU Affero General Public License
19
+ *    along with osu!web.  If not, see <http://www.gnu.org/licenses/>.
20
+ */
22 21
 
23 22
 namespace App\Console\Commands;
24 23
 
25 24
 use App\Models\Store;
26
-
25
+use Illuminate\Console\Command;
27 26
 use Slack;
28 27
 
29
-use Illuminate\Console\Command;
30
-use Symfony\Component\Console\Input\InputOption;
31
-use Symfony\Component\Console\Input\InputArgument;
32
-
33
-class StoreCheckOrderTrackingStatus extends Command {
34
-
35
-	/**
36
-	 * The console command name.
37
-	 *
38
-	 * @var string
39
-	 */
40
-	protected $name = 'store:tracking';
41
-
42
-	/**
43
-	 * The console command description.
44
-	 *
45
-	 * @var string
46
-	 */
47
-	protected $description = 'Checks tracking status of all shipped (but not delivered) items.';
48
-
49
-	/**
50
-	 * Create a new command instance.
51
-	 *
52
-	 * @return void
53
-	 */
54
-	public function __construct()
55
-	{
56
-		parent::__construct();
57
-	}
58
-
59
-	/**
60
-	 * Execute the console command.
61
-	 *
62
-	 * @return mixed
63
-	 */
64
-	public function fire()
65
-	{
66
-		$orders = Store\Order::where("status", "=", "shipped")->where("tracking_code", "!=", "")->orderBy('updated_at')->get();
67
-		$count = count($orders);
68
-
69
-		if (!$count)
70
-			return;
71
-
72
-		$this->info("found $count orders.");
73
-
74
-		Slack::send("Checking order tracking status ($count orders)...");
75
-
76
-		$statuses = [];
77
-
78
-		$i = 0;
79
-		foreach ($orders as $o)
80
-		{
81
-			$i++;
82
-
83
-			try
84
-			{
85
-				if (!strlen(trim($o->tracking_code)) || strpos($o->tracking_code, "EJ") !== 0)
86
-					continue;
87
-
88
-				if (!$o->shipped_at)
89
-				{
90
-					$o->shipped_at = time();
91
-					$o->save();
92
-				}
93
-
94
-				$response = file_get_contents("https://trackings.post.japanpost.jp/services/srv/search/direct?searchKind=S004&locale=en&reqCodeNo1=$o->tracking_code");
95
-
96
-				preg_match_all("/\<td rowspan=\"2\" class=\"w_150\"\>([^\<]*)\<\/td\>/", $response, $status);
97
-
98
-				if (!count($status[1]))
99
-				{
100
-					if (!$o->last_tracking_state)
101
-					{
102
-						$days_until_warning = 4;
103
-						if (time() - $o->shipped_at->timestamp > 3600 * 24 * $days_until_warning)
104
-							Slack::send("WARNING: <https://store.ppy.sh/store/admin/{$o->order_id}|Order #{$o->order_id}> has no tracking after {$days_until_warning} days!");
105
-					}
106
-					continue;
107
-				}
108
-
109
-				$lastStatus = end($status[1]);
110
-
111
-				$statuses[$lastStatus][] = $o;
112
-
113
-				$this->info("#$i: Order #{$o->order_id} (https://store.ppy.sh/store/invoice/{$o->order_id})\t{$o->address->country_code}\tshipped {$o->shipped_at}\t$lastStatus");
114
-
115
-				if (!$o->last_tracking_state)
116
-				{
117
-					mail($o->user->user_email, "Your osu!store order is on its way!",
118
-					"Hi {$o->user->username},
28
+class StoreCheckOrderTrackingStatus extends Command
29
+{
30
+    /**
31
+     * The console command name.
32
+     *
33
+     * @var string
34
+     */
35
+    protected $name = 'store:tracking';
36
+
37
+    /**
38
+     * The console command description.
39
+     *
40
+     * @var string
41
+     */
42
+    protected $description = 'Checks tracking status of all shipped (but not delivered) items.';
43
+
44
+    /**
45
+     * Create a new command instance.
46
+     *
47
+     * @return void
48
+     */
49
+    public function __construct()
50
+    {
51
+        parent::__construct();
52
+    }
53
+
54
+    /**
55
+     * Execute the console command.
56
+     *
57
+     * @return mixed
58
+     */
59
+    public function fire()
60
+    {
61
+        $orders = Store\Order::where('status', '=', 'shipped')->where('tracking_code', '!=', '')->orderBy('updated_at')->get();
62
+        $count = count($orders);
63
+
64
+        if (! $count) {
65
+            return;
66
+        }
67
+
68
+        $this->info("found $count orders.");
69
+
70
+        Slack::send("Checking order tracking status ($count orders)...");
71
+
72
+        $statuses = [];
73
+
74
+        $i = 0;
75
+        foreach ($orders as $o) {
76
+            $i++;
77
+
78
+            try {
79
+                if (! strlen(trim($o->tracking_code)) || strpos($o->tracking_code, 'EJ') !== 0) {
80
+                    continue;
81
+                }
82
+
83
+                if (! $o->shipped_at) {
84
+                    $o->shipped_at = time();
85
+                    $o->save();
86
+                }
87
+
88
+                $response = file_get_contents("https://trackings.post.japanpost.jp/services/srv/search/direct?searchKind=S004&locale=en&reqCodeNo1=$o->tracking_code");
89
+
90
+                preg_match_all("/\<td rowspan=\"2\" class=\"w_150\"\>([^\<]*)\<\/td\>/", $response, $status);
91
+
92
+                if (! count($status[1])) {
93
+                    if (! $o->last_tracking_state) {
94
+                        $days_until_warning = 4;
95
+                        if (time() - $o->shipped_at->timestamp > 3600 * 24 * $days_until_warning) {
96
+                            Slack::send("WARNING: <https://store.ppy.sh/store/admin/{$o->order_id}|Order #{$o->order_id}> has no tracking after {$days_until_warning} days!");
97
+                        }
98
+                    }
99
+                    continue;
100
+                }
101
+
102
+                $lastStatus = end($status[1]);
103
+
104
+                $statuses[$lastStatus][] = $o;
105
+
106
+                $this->info("#$i: Order #{$o->order_id} (https://store.ppy.sh/store/invoice/{$o->order_id})\t{$o->address->country_code}\tshipped {$o->shipped_at}\t$lastStatus");
107
+
108
+                if (! $o->last_tracking_state) {
109
+                    mail($o->user->user_email, 'Your osu!store order is on its way!',
110
+                    "Hi {$o->user->username},
119 111
 
120 112
 	Thanks again for your osu!store order!
121 113
 
@@ -124,23 +116,21 @@ class StoreCheckOrderTrackingStatus extends Command {
124 116
 	If you have any questions, don't hesitate to reply to this email.
125 117
 
126 118
 	Regards,
127
-	The osu!store team", "From: \"osu!store team\" <osustore@ppy.sh>");
128
-				}
129
-
130
-				if ($lastStatus != $o->last_tracking_state)
131
-				{
132
-					switch ($lastStatus)
133
-					{
134
-						case "Final delivery":
135
-						case "P.O.Box Delivery":
136
-							Slack::send("<https://store.ppy.sh/store/invoice/{$o->order_id}|Order #{$o->order_id}> has been delivered!");
137
-							$o->status = "delivered";
138
-							break;
139
-						case "Retention":
140
-						case "Absence. Attempted delivery.":
141
-								mail($o->user->user_email,
142
-						"IMPORTANT: Your osu!store order is pending delivery",
143
-						"Hi {$o->user->username},
119
+	The osu!store team", 'From: "osu!store team" <osustore@ppy.sh>');
120
+                }
121
+
122
+                if ($lastStatus != $o->last_tracking_state) {
123
+                    switch ($lastStatus) {
124
+                        case 'Final delivery':
125
+                        case 'P.O.Box Delivery':
126
+                            Slack::send("<https://store.ppy.sh/store/invoice/{$o->order_id}|Order #{$o->order_id}> has been delivered!");
127
+                            $o->status = 'delivered';
128
+                            break;
129
+                        case 'Retention':
130
+                        case 'Absence. Attempted delivery.':
131
+                                mail($o->user->user_email,
132
+                        'IMPORTANT: Your osu!store order is pending delivery',
133
+                        "Hi {$o->user->username},
144 134
 
145 135
 	We have been tracking your order and noticed that it is currently in the state of \"{$lastStatus}\".
146 136
 
@@ -151,39 +141,37 @@ class StoreCheckOrderTrackingStatus extends Command {
151 141
 	If you have any questions, don't hesitate to reply to this email.
152 142
 
153 143
 	Regards,
154
-	The osu!store team", "From: \"osu!store team\" <osustore@ppy.sh>");
155
-							Slack::send("<https://store.ppy.sh/store/invoice/{$o->order_id}|Order #{$o->order_id}> is being held at the destination post office. Contacting user ({$o->user->user_email}).");
156
-							break;
157
-						default:
158
-							if ($o->last_tracking_state)
159
-								Slack::send("<https://store.ppy.sh/store/invoice/{$o->order_id}|Order #{$o->order_id}> has changed status from \"{$o->last_tracking_state}\" to \"$lastStatus\"");
160
-							else
161
-								Slack::send("<https://store.ppy.sh/store/invoice/{$o->order_id}|Order #{$o->order_id}> is now being tracked with an initial state of \"$lastStatus\"");
162
-					}
163
-
164
-					$o->last_tracking_state = $lastStatus;
165
-					$o->save();
166
-				}
167
-			}
168
-			catch (\Exception $e)
169
-			{
170
-				//slack could throw errors here if their servers are dead.
171
-			}
172
-		}
173
-
174
-		$fields = [];
175
-		foreach ($statuses as $k => $v)
176
-		{
177
-			$orderstring = "";
178
-			foreach ($v as $o)
179
-				$orderstring .= "<https://store.ppy.sh/store/invoice/{$o->order_id}|{$o->order_id}({$o->address->country_code})> ";
180
-			$fields[] = ['title' => $k, 'value' => $orderstring];
181
-		}
182
-
183
-		Slack::attach([
184
-			'color' => 'good',
185
-			'fields' => $fields
186
-		])->send('Tracking Results are in:');
187
-	}
188
-
144
+	The osu!store team", 'From: "osu!store team" <osustore@ppy.sh>');
145
+                            Slack::send("<https://store.ppy.sh/store/invoice/{$o->order_id}|Order #{$o->order_id}> is being held at the destination post office. Contacting user ({$o->user->user_email}).");
146
+                            break;
147
+                        default:
148
+                            if ($o->last_tracking_state) {
149
+                                Slack::send("<https://store.ppy.sh/store/invoice/{$o->order_id}|Order #{$o->order_id}> has changed status from \"{$o->last_tracking_state}\" to \"$lastStatus\"");
150
+                            } else {
151
+                                Slack::send("<https://store.ppy.sh/store/invoice/{$o->order_id}|Order #{$o->order_id}> is now being tracked with an initial state of \"$lastStatus\"");
152
+                            }
153
+                    }
154
+
155
+                    $o->last_tracking_state = $lastStatus;
156
+                    $o->save();
157
+                }
158
+            } catch (\Exception $e) {
159
+                //slack could throw errors here if their servers are dead.
160
+            }
161
+        }
162
+
163
+        $fields = [];
164
+        foreach ($statuses as $k => $v) {
165
+            $orderstring = '';
166
+            foreach ($v as $o) {
167
+                $orderstring .= "<https://store.ppy.sh/store/invoice/{$o->order_id}|{$o->order_id}({$o->address->country_code})> ";
168
+            }
169
+            $fields[] = ['title' => $k, 'value' => $orderstring];
170
+        }
171
+
172
+        Slack::attach([
173
+            'color' => 'good',
174
+            'fields' => $fields,
175
+        ])->send('Tracking Results are in:');
176
+    }
189 177
 }

+ 46
- 47
app/Console/Kernel.php View File

@@ -1,57 +1,56 @@
1 1
 <?php
2 2
 
3 3
 /**
4
-*    Copyright 2015 ppy Pty. Ltd.
5
-*
6
-*    This file is part of osu!web. osu!web is distributed with the hope of
7
-*    attracting more community contributions to the core ecosystem of osu!.
8
-*
9
-*    osu!web is free software: you can redistribute it and/or modify
10
-*    it under the terms of the Affero GNU General Public License as published by
11
-*    the Free Software Foundation, either version 3 of the License, or
12
-*    (at your option) any later version.
13
-*
14
-*    osu!web is distributed WITHOUT ANY WARRANTY; without even the implied
15
-*    warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16
-*    See the GNU Affero General Public License for more details.
17
-*
18
-*    You should have received a copy of the GNU Affero General Public License
19
-*    along with osu!web.  If not, see <http://www.gnu.org/licenses/>.
20
-*
21
-*/
4
+ *    Copyright 2015 ppy Pty. Ltd.
5
+ *
6
+ *    This file is part of osu!web. osu!web is distributed with the hope of
7
+ *    attracting more community contributions to the core ecosystem of osu!.
8
+ *
9
+ *    osu!web is free software: you can redistribute it and/or modify
10
+ *    it under the terms of the Affero GNU General Public License as published by
11
+ *    the Free Software Foundation, either version 3 of the License, or
12
+ *    (at your option) any later version.
13
+ *
14
+ *    osu!web is distributed WITHOUT ANY WARRANTY; without even the implied
15
+ *    warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16
+ *    See the GNU Affero General Public License for more details.
17
+ *
18
+ *    You should have received a copy of the GNU Affero General Public License
19
+ *    along with osu!web.  If not, see <http://www.gnu.org/licenses/>.
20
+ */
22 21
 
23 22
 namespace App\Console;
24 23
 
25 24
 use Illuminate\Console\Scheduling\Schedule;
26 25
 use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
27 26
 
28
-class Kernel extends ConsoleKernel {
29
-
30
-	/**
31
-	 * The Artisan commands provided by your application.
32
-	 *
33
-	 * @var array
34
-	 */
35
-	protected $commands = [
36
-		// modding stuff
37
-		'App\Console\Commands\ModdingQueueUpdateCommand',
38
-		'App\Console\Commands\ModdingRankCommand',
39
-		'App\Console\Commands\ModdingScoreIndexCommand',
40
-
41
-		// parsing html with regexp
42
-		'App\Console\Commands\StoreCheckOrderTrackingStatus',
43
-	];
44
-
45
-	/**
46
-	 * Define the application's command schedule.
47
-	 *
48
-	 * @param  \Illuminate\Console\Scheduling\Schedule  $schedule
49
-	 * @return void
50
-	 */
51
-	protected function schedule(Schedule $schedule)
52
-	{
53
-		$schedule->command("store:tracking")
54
-			->cron("0 0,8,16 * * *");
55
-	}
56
-
27
+class Kernel extends ConsoleKernel
28
+{
29
+    /**
30
+     * The Artisan commands provided by your application.
31
+     *
32
+     * @var array
33
+     */
34
+    protected $commands = [
35
+        // modding stuff
36
+        'App\Console\Commands\ModdingQueueUpdateCommand',
37
+        'App\Console\Commands\ModdingRankCommand',
38
+        'App\Console\Commands\ModdingScoreIndexCommand',
39
+
40
+        // parsing html with regexp
41
+        'App\Console\Commands\StoreCheckOrderTrackingStatus',
42
+    ];
43
+
44
+    /**
45
+     * Define the application's command schedule.
46
+     *
47
+     * @param \Illuminate\Console\Scheduling\Schedule $schedule
48
+     *
49
+     * @return void
50
+     */
51
+    protected function schedule(Schedule $schedule)
52
+    {
53
+        $schedule->command('store:tracking')
54
+            ->cron('0 0,8,16 * * *');
55
+    }
57 56
 }

+ 86
- 83
app/Contracts/OsuHasher.php View File

@@ -1,103 +1,106 @@
1 1
 <?php
2 2
 
3 3
 /**
4
-*    Copyright 2015 ppy Pty. Ltd.
5
-*
6
-*    This file is part of osu!web. osu!web is distributed with the hope of
7
-*    attracting more community contributions to the core ecosystem of osu!.
8
-*
9
-*    osu!web is free software: you can redistribute it and/or modify
10
-*    it under the terms of the Affero GNU General Public License as published by
11
-*    the Free Software Foundation, either version 3 of the License, or
12
-*    (at your option) any later version.
13
-*
14
-*    osu!web is distributed WITHOUT ANY WARRANTY; without even the implied
15
-*    warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16
-*    See the GNU Affero General Public License for more details.
17
-*
18
-*    You should have received a copy of the GNU Affero General Public License
19
-*    along with osu!web.  If not, see <http://www.gnu.org/licenses/>.
20
-*
21
-*/
4
+ *    Copyright 2015 ppy Pty. Ltd.
5
+ *
6
+ *    This file is part of osu!web. osu!web is distributed with the hope of
7
+ *    attracting more community contributions to the core ecosystem of osu!.
8
+ *
9
+ *    osu!web is free software: you can redistribute it and/or modify
10
+ *    it under the terms of the Affero GNU General Public License as published by
11
+ *    the Free Software Foundation, either version 3 of the License, or
12
+ *    (at your option) any later version.
13
+ *
14
+ *    osu!web is distributed WITHOUT ANY WARRANTY; without even the implied
15
+ *    warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16
+ *    See the GNU Affero General Public License for more details.
17
+ *
18
+ *    You should have received a copy of the GNU Affero General Public License
19
+ *    along with osu!web.  If not, see <http://www.gnu.org/licenses/>.
20
+ */
22 21
 
23 22
 namespace App\Contracts;
24 23
 
25 24
 use Illuminate\Contracts\Hashing\Hasher as HasherContract;
26 25
 
27
-class OsuHasher implements HasherContract {
26
+class OsuHasher implements HasherContract
27
+{
28
+    protected $hasher;
29
+    protected $rounds = 4;
28 30
 
29
-	protected $hasher;
30
-	protected $rounds = 4;
31
+    /**
32
+     * Hash the given value.
33
+     *
34
+     * @param string $value
35
+     *
36
+     * @return array  $options
37
+     * @return string
38
+     */
39
+    public function make($value, array $options = [])
40
+    {
41
+        if (isset($options['osu_migration']) && $options['osu_migration']) {
42
+            $cost = isset($options['cost']) ? $options['cost'] : $this->rounds;
31 43
 
32
-	/**
33
-	 * Hash the given value.
34
-	 *
35
-	 * @param  string  $value
36
-	 * @return array   $options
37
-	 * @return string
38
-	 */
39
-	public function make($value, array $options = [])
40
-	{
41
-		if (isset($options["osu_migration"]) && $options["osu_migration"]) {
44
+            $hash = password_hash(md5($value), PASSWORD_BCRYPT, ['cost' => $cost]);
42 45
 
43
-			$cost = isset($options["cost"]) ? $options["cost"] : $this->rounds;
46
+            // see static::check()
47
+            return str_replace('$2y$', '$2a$', $hash);
48
+        }
44 49
 
45
-			$hash = password_hash(md5($value), PASSWORD_BCRYPT, ["cost" => $cost]);
50
+        return md5($value);
51
+    }
46 52
 
47
-			// see static::check()
48
-			return str_replace("$2y$", "$2a$", $hash);
49
-		}
53
+    /**
54
+     * Check the given plain value against a hash.
55
+     *
56
+     * @param string $value
57
+     * @param string $hashedValue
58
+     * @param array  $options
59
+     *
60
+     * @return bool
61
+     */
62
+    public function check($value, $hashedValue, array $options = [])
63
+    {
64
+        if (strlen($hashedValue) == 60) {
65
+            // To clarify here: the 2y implementation of bcrypt is specific to
66
+            // the crypt_blowfish implementation of bcrypt (that PHP uses).
67
+            // the act of naming this bugfix "2y" was a stupid idea as it is not
68
+            // an updated version of the algorithm at all.
69
+            // 2a and 2y are literally identical; crypt_blowfish just had bugs in 2a
50 70
 
51
-		return md5($value);
52
-	}
71
+            // anyways, this replacement is because the .NET library this interacts with
72
+            // needs 2a since a string replacement on every connection is needless overhead
73
+            // for a realtime processing server and only lowers max connections.
74
+            $hashedValue = str_replace('$2a$', '$2y$', $hashedValue);
53 75
 
54
-	/**
55
-	 * Check the given plain value against a hash.
56
-	 *
57
-	 * @param  string  $value
58
-	 * @param  string  $hashedValue
59
-	 * @param  array   $options
60
-	 * @return bool
61
-	 */
62
-	public function check($value, $hashedValue, array $options = [])
63
-	{
64
-		if (strlen($hashedValue) == 60) {
65
-			// To clarify here: the 2y implementation of bcrypt is specific to
66
-			// the crypt_blowfish implementation of bcrypt (that PHP uses).
67
-			// the act of naming this bugfix "2y" was a stupid idea as it is not
68
-			// an updated version of the algorithm at all.
69
-			// 2a and 2y are literally identical; crypt_blowfish just had bugs in 2a
76
+            return password_verify(md5($value), $hashedValue);
77
+        }
70 78
 
71
-			// anyways, this replacement is because the .NET library this interacts with
72
-			// needs 2a since a string replacement on every connection is needless overhead
73
-			// for a realtime processing server and only lowers max connections.
74
-			$hashedValue = str_replace("$2a$", "$2y$", $hashedValue);
75
-			return password_verify(md5($value), $hashedValue);
76
-		}
79
+        return md5($value) === $hashedValue;
80
+    }
77 81
 
78
-		return md5($value) === $hashedValue;
82
+    /**
83
+     * Check if the given hash has been hashed using the given options.
84
+     *
85
+     * @param string $hashedValue
86
+     * @param array  $options
87
+     *
88
+     * @return bool
89
+     */
90
+    public function needsRehash($hashedValue, array $options = [])
91
+    {
92
+        if (isset($options['osu_migration']) && $options['osu_migration']) {
93
+            if ((strlen($hashedValue) == 32) && ctype_xdigit($hashedValue)) {
94
+                // md5
95
+                return true;
96
+            } else {
97
+                $cost = isset($options['rounds']) ? $options['rounds'] : $this->rounds;
98
+                $hashedValue = str_replace('$2a$', '$2y$', $hashedValue);
79 99
 
80
-	}
100
+                return password_needs_rehash($hashedValue, PASSWORD_BCRYPT, ['cost' => $cost]);
101
+            }
102
+        }
81 103
 
82
-	/**
83
-	 * Check if the given hash has been hashed using the given options.
84
-	 *
85
-	 * @param  string  $hashedValue
86
-	 * @param  array   $options
87
-	 * @return bool
88
-	 */
89
-	public function needsRehash($hashedValue, array $options = array())
90
-	{
91
-		if (isset($options["osu_migration"]) && $options["osu_migration"]) {
92
-			if ((strlen($hashedValue) == 32) && ctype_xdigit($hashedValue))  {
93
-				// md5
94
-				return true;
95
-			} else {
96
-				$cost = isset($options["rounds"]) ? $options["rounds"] : $this->rounds;
97
-				$hashedValue = str_replace("$2a$", "$2y$", $hashedValue);
98
-				return password_needs_rehash($hashedValue, PASSWORD_BCRYPT, ["cost" => $cost]);
99
-			}
100
-		}
101
-		return false;
102
-	}
104
+        return false;
105
+    }
103 106
 }

+ 20
- 22
app/Events/Event.php View File

@@ -1,29 +1,27 @@
1 1
 <?php
2 2
 
3 3
 /**
4
-*    Copyright 2015 ppy Pty. Ltd.
5
-*
6
-*    This file is part of osu!web. osu!web is distributed with the hope of
7
-*    attracting more community contributions to the core ecosystem of osu!.
8
-*
9
-*    osu!web is free software: you can redistribute it and/or modify
10
-*    it under the terms of the Affero GNU General Public License as published by
11
-*    the Free Software Foundation, either version 3 of the License, or
12
-*    (at your option) any later version.
13
-*
14
-*    osu!web is distributed WITHOUT ANY WARRANTY; without even the implied
15
-*    warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16
-*    See the GNU Affero General Public License for more details.
17
-*
18
-*    You should have received a copy of the GNU Affero General Public License
19
-*    along with osu!web.  If not, see <http://www.gnu.org/licenses/>.
20
-*
21
-*/
4
+ *    Copyright 2015 ppy Pty. Ltd.
5
+ *
6
+ *    This file is part of osu!web. osu!web is distributed with the hope of
7
+ *    attracting more community contributions to the core ecosystem of osu!.
8
+ *
9
+ *    osu!web is free software: you can redistribute it and/or modify
10
+ *    it under the terms of the Affero GNU General Public License as published by
11
+ *    the Free Software Foundation, either version 3 of the License, or
12
+ *    (at your option) any later version.
13
+ *
14
+ *    osu!web is distributed WITHOUT ANY WARRANTY; without even the implied
15
+ *    warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16
+ *    See the GNU Affero General Public License for more details.
17
+ *
18
+ *    You should have received a copy of the GNU Affero General Public License
19
+ *    along with osu!web.  If not, see <http://www.gnu.org/licenses/>.
20
+ */
22 21
 
23 22
 namespace App\Events;
24 23
 
25
-abstract class Event {
26
-
27
-	//
28
-
24
+abstract class Event
25
+{
26
+    //
29 27
 }

+ 28
- 30
app/Events/Forum/TopicUpdate.php View File

@@ -1,46 +1,44 @@
1 1
 <?php
2 2
 
3 3
 /**
4
-*    Copyright 2015 ppy Pty. Ltd.
5
-*
6
-*    This file is part of osu!web. osu!web is distributed with the hope of
7
-*    attracting more community contributions to the core ecosystem of osu!.
8
-*
9
-*    osu!web is free software: you can redistribute it and/or modify
10
-*    it under the terms of the Affero GNU General Public License as published by
11
-*    the Free Software Foundation, either version 3 of the License, or
12
-*    (at your option) any later version.
13
-*
14
-*    osu!web is distributed WITHOUT ANY WARRANTY; without even the implied
15
-*    warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16
-*    See the GNU Affero General Public License for more details.
17
-*
18
-*    You should have received a copy of the GNU Affero General Public License
19
-*    along with osu!web.  If not, see <http://www.gnu.org/licenses/>.
20
-*
21
-*/
4
+ *    Copyright 2015 ppy Pty. Ltd.
5
+ *
6
+ *    This file is part of osu!web. osu!web is distributed with the hope of
7
+ *    attracting more community contributions to the core ecosystem of osu!.
8
+ *
9
+ *    osu!web is free software: you can redistribute it and/or modify
10
+ *    it under the terms of the Affero GNU General Public License as published by
11
+ *    the Free Software Foundation, either version 3 of the License, or
12
+ *    (at your option) any later version.
13
+ *
14
+ *    osu!web is distributed WITHOUT ANY WARRANTY; without even the implied
15
+ *    warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16
+ *    See the GNU Affero General Public License for more details.
17
+ *
18
+ *    You should have received a copy of the GNU Affero General Public License
19
+ *    along with osu!web.  If not, see <http://www.gnu.org/licenses/>.
20
+ */
22 21
 
23 22
 namespace App\Events\Forum;
24 23
 
24
+use App\Events\Event;
25 25
 use App\Models\Forum\Post;
26 26
 use App\Models\Forum\Topic;
27 27
 use App\Models\User;
28
-
29
-use App\Events\Event;
30 28
 use Illuminate\Queue\SerializesModels;
31 29
 
32 30
 abstract class TopicUpdate extends Event
33 31
 {
34
-	use SerializesModels;
32
+    use SerializesModels;
35 33
 
36
-	public $topic;
37
-	public $post;
38
-	public $user;
34
+    public $topic;
35
+    public $post;
36
+    public $user;
39 37
 
40
-	public function __construct(Topic $topic, Post $post, User $user = null)
41
-	{
42
-		$this->topic = $topic;
43
-		$this->post = $post;
44
-		$this->user = $user;
45
-	}
38
+    public function __construct(Topic $topic, Post $post, User $user = null)
39
+    {
40
+        $this->topic = $topic;
41
+        $this->post = $post;
42
+        $this->user = $user;
43
+    }
46 44
 }

+ 18
- 19
app/Events/Forum/TopicWasCreated.php View File

@@ -1,28 +1,27 @@
1 1
 <?php
2 2
 
3 3
 /**
4
-*    Copyright 2015 ppy Pty. Ltd.
5
-*
6
-*    This file is part of osu!web. osu!web is distributed with the hope of
7
-*    attracting more community contributions to the core ecosystem of osu!.
8
-*
9
-*    osu!web is free software: you can redistribute it and/or modify
10
-*    it under the terms of the Affero GNU General Public License as published by
11
-*    the Free Software Foundation, either version 3 of the License, or
12
-*    (at your option) any later version.
13
-*
14
-*    osu!web is distributed WITHOUT ANY WARRANTY; without even the implied
15
-*    warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16
-*    See the GNU Affero General Public License for more details.
17
-*
18
-*    You should have received a copy of the GNU Affero General Public License
19
-*    along with osu!web.  If not, see <http://www.gnu.org/licenses/>.
20
-*
21
-*/
4
+ *    Copyright 2015 ppy Pty. Ltd.
5
+ *
6
+ *    This file is part of osu!web. osu!web is distributed with the hope of
7
+ *    attracting more community contributions to the core ecosystem of osu!.
8
+ *
9
+ *    osu!web is free software: you can redistribute it and/or modify
10
+ *    it under the terms of the Affero GNU General Public License as published by
11
+ *    the Free Software Foundation, either version 3 of the License, or
12
+ *    (at your option) any later version.
13
+ *
14
+ *    osu!web is distributed WITHOUT ANY WARRANTY; without even the implied
15
+ *    warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16
+ *    See the GNU Affero General Public License for more details.
17
+ *
18
+ *    You should have received a copy of the GNU Affero General Public License
19
+ *    along with osu!web.  If not, see <http://www.gnu.org/licenses/>.
20
+ */
22 21
 
23 22
 namespace App\Events\Forum;
24 23
 
25 24
 class TopicWasCreated extends TopicUpdate
26 25
 {
27
-	//
26
+    //
28 27
 }

+ 18
- 19
app/Events/Forum/TopicWasReplied.php View File

@@ -1,28 +1,27 @@
1 1
 <?php
2 2
 
3 3
 /**
4
-*    Copyright 2015 ppy Pty. Ltd.
5
-*
6
-*    This file is part of osu!web. osu!web is distributed with the hope of
7
-*    attracting more community contributions to the core ecosystem of osu!.
8
-*
9
-*    osu!web is free software: you can redistribute it and/or modify
10
-*    it under the terms of the Affero GNU General Public License as published by
11
-*    the Free Software Foundation, either version 3 of the License, or
12
-*    (at your option) any later version.
13
-*
14
-*    osu!web is distributed WITHOUT ANY WARRANTY; without even the implied
15
-*    warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16
-*    See the GNU Affero General Public License for more details.
17
-*
18
-*    You should have received a copy of the GNU Affero General Public License
19
-*    along with osu!web.  If not, see <http://www.gnu.org/licenses/>.
20
-*
21
-*/
4
+ *    Copyright 2015 ppy Pty. Ltd.
5
+ *
6
+ *    This file is part of osu!web. osu!web is distributed with the hope of
7
+ *    attracting more community contributions to the core ecosystem of osu!.
8
+ *
9
+ *    osu!web is free software: you can redistribute it and/or modify
10
+ *    it under the terms of the Affero GNU General Public License as published by
11
+ *    the Free Software Foundation, either version 3 of the License, or
12
+ *    (at your option) any later version.
13
+ *
14
+ *    osu!web is distributed WITHOUT ANY WARRANTY; without even the implied
15
+ *    warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16
+ *    See the GNU Affero General Public License for more details.
17
+ *
18
+ *    You should have received a copy of the GNU Affero General Public License
19
+ *    along with osu!web.  If not, see <http://www.gnu.org/licenses/>.
20
+ */
22 21
 
23 22
 namespace App\Events\Forum;
24 23
 
25 24
 class TopicWasReplied extends TopicUpdate
26 25
 {
27
-	//
26
+    //
28 27
 }

+ 18
- 19
app/Events/Forum/TopicWasViewed.php View File

@@ -1,28 +1,27 @@
1 1
 <?php
2 2
 
3 3
 /**
4
-*    Copyright 2015 ppy Pty. Ltd.
5
-*
6
-*    This file is part of osu!web. osu!web is distributed with the hope of
7
-*    attracting more community contributions to the core ecosystem of osu!.
8
-*
9
-*    osu!web is free software: you can redistribute it and/or modify
10
-*    it under the terms of the Affero GNU General Public License as published by
11
-*    the Free Software Foundation, either version 3 of the License, or
12
-*    (at your option) any later version.
13
-*
14
-*    osu!web is distributed WITHOUT ANY WARRANTY; without even the implied
15
-*    warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16
-*    See the GNU Affero General Public License for more details.
17
-*
18
-*    You should have received a copy of the GNU Affero General Public License
19
-*    along with osu!web.  If not, see <http://www.gnu.org/licenses/>.
20
-*
21
-*/
4
+ *    Copyright 2015 ppy Pty. Ltd.
5
+ *
6
+ *    This file is part of osu!web. osu!web is distributed with the hope of
7
+ *    attracting more community contributions to the core ecosystem of osu!.
8
+ *
9
+ *    osu!web is free software: you can redistribute it and/or modify
10
+ *    it under the terms of the Affero GNU General Public License as published by
11
+ *    the Free Software Foundation, either version 3 of the License, or
12
+ *    (at your option) any later version.
13
+ *
14
+ *    osu!web is distributed WITHOUT ANY WARRANTY; without even the implied
15
+ *    warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16
+ *    See the GNU Affero General Public License for more details.
17
+ *
18
+ *    You should have received a copy of the GNU Affero General Public License
19
+ *    along with osu!web.  If not, see <http://www.gnu.org/licenses/>.
20
+ */
22 21
 
23 22
 namespace App\Events\Forum;
24 23
 
25 24
 class TopicWasViewed extends TopicUpdate
26 25
 {
27
-	//
26
+    //
28 27
 }

+ 117
- 113
app/Exceptions/Handler.php View File

@@ -1,126 +1,130 @@
1 1
 <?php
2 2
 
3 3
 /**
4
-*    Copyright 2015 ppy Pty. Ltd.
5
-*
6
-*    This file is part of osu!web. osu!web is distributed with the hope of
7
-*    attracting more community contributions to the core ecosystem of osu!.
8
-*
9
-*    osu!web is free software: you can redistribute it and/or modify
10
-*    it under the terms of the Affero GNU General Public License as published by
11
-*    the Free Software Foundation, either version 3 of the License, or
12
-*    (at your option) any later version.
13
-*
14
-*    osu!web is distributed WITHOUT ANY WARRANTY; without even the implied
15
-*    warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16
-*    See the GNU Affero General Public License for more details.
17
-*
18
-*    You should have received a copy of the GNU Affero General Public License
19
-*    along with osu!web.  If not, see <http://www.gnu.org/licenses/>.
20
-*
21
-*/
4
+ *    Copyright 2015 ppy Pty. Ltd.
5
+ *
6
+ *    This file is part of osu!web. osu!web is distributed with the hope of
7
+ *    attracting more community contributions to the core ecosystem of osu!.
8
+ *
9
+ *    osu!web is free software: you can redistribute it and/or modify
10
+ *    it under the terms of the Affero GNU General Public License as published by
11
+ *    the Free Software Foundation, either version 3 of the License, or
12
+ *    (at your option) any later version.
13
+ *
14
+ *    osu!web is distributed WITHOUT ANY WARRANTY; without even the implied
15
+ *    warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16
+ *    See the GNU Affero General Public License for more details.
17
+ *
18
+ *    You should have received a copy of the GNU Affero General Public License
19
+ *    along with osu!web.  If not, see <http://www.gnu.org/licenses/>.
20
+ */
22 21
 
23 22
 namespace App\Exceptions;
24 23
 
25 24
 use Auth;
26
-use Raven_Client;
27
-
28 25
 use Exception;
29
-use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
30
-
31 26
 use Illuminate\Database\Eloquent\ModelNotFoundException;
27
+use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
32 28
 use Illuminate\Session\TokenMismatchException;
29
+use Raven_Client;
33 30
 use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
34 31
 
35
-class Handler extends ExceptionHandler {
36
-
37
-	/**
38
-	 * A list of the exception types that should not be reported.
39
-	 *
40
-	 * @var array
41
-	 */
42
-	protected $dontReport = [
43
-		"Symfony\Component\HttpKernel\Exception\HttpException",
44
-		"Illuminate\Database\Eloquent\ModelNotFoundException",
45
-	];
46
-
47
-	/**
48
-	 * Report or log an exception.
49
-	 *
50
-	 * This is a great spot to send exceptions to Sentry, Bugsnag, etc.
51
-	 *
52
-	 * @param  \Exception  $e
53
-	 * @return void
54
-	 */
55
-	public function report(Exception $e)
56
-	{
57
-		view()->share("current_action", $this->statusCode($e));
58
-		view()->share("current_section", "error");
59
-
60
-		// immediately done if the error should not be reported
61
-		if ($this->shouldntReport($e)) return;
62
-
63
-		if (config("app.sentry")) {
64
-			$this->reportWithSentry($e);
65
-		} else {
66
-			return parent::report($e);
67
-		}
68
-	}
69
-
70
-	private function statusCode($e) {
71
-		if (method_exists($e, "getStatusCode")) {
72
-			return $e->getStatusCode();
73
-		} elseif ($e instanceof ModelNotFoundException) {
74
-			return 404;
75
-		} elseif ($e instanceof NotFoundHttpException) {
76
-			return 404;
77
-		} elseif ($e instanceof TokenMismatchException) {
78
-			return 403;
79
-		} else {
80
-			return 500;
81
-		}
82
-	}
83
-
84
-	private function reportWithSentry($e) {
85
-		$tags = [
86
-			"http_code" => $this->statusCode($e)
87
-		];
88
-
89
-		if (Auth::check()) {
90
-			$tags["user"] = Auth::user()->user_id;
91
-			$tags["username"] = Auth::user()->username_clean;
92
-		}
93
-
94
-		$client = new Raven_Client(config("app.sentry"), ["tags" => $tags]);
95
-
96
-		$ref = $client->getIdent(
97
-			$client->captureException($e));
98
-
99
-		view()->share("ref", $ref);
100
-	}
101
-	/**
102
-	 * Render an exception into an HTTP response.
103
-	 *
104
-	 * @param  \Illuminate\Http\Request  $request
105
-	 * @param  \Exception  $e
106
-	 * @return \Illuminate\Http\Response
107
-	 */
108
-	public function render($request, Exception $e)
109
-	{
110
-		if (config("app.debug")) {
111
-			if ($this->isHttpException($e)) {
112
-				return $this->renderHttpException($e);
113
-			} else {
114
-				return parent::render($request, $e);
115
-			}
116
-		} else {
117
-			if ($request->ajax()) {
118
-				// turbolinks always reload on page error.
119
-				$response = response([]);
120
-			} else {
121
-				$response = response()->view("layout.error");
122
-			}
123
-			return $response->setStatusCode($this->statusCode($e));
124
-		}
125
-	}
32
+class Handler extends ExceptionHandler
33
+{
34
+    /**
35
+     * A list of the exception types that should not be reported.
36
+     *
37
+     * @var array
38
+     */
39
+    protected $dontReport = [
40
+        "Symfony\Component\HttpKernel\Exception\HttpException",
41
+        "Illuminate\Database\Eloquent\ModelNotFoundException",
42
+    ];
43
+
44
+    /**
45
+     * Report or log an exception.
46
+     *
47
+     * This is a great spot to send exceptions to Sentry, Bugsnag, etc.
48
+     *
49
+     * @param \Exception $e
50
+     *
51
+     * @return void
52
+     */
53
+    public function report(Exception $e)
54
+    {
55
+        view()->share('current_action', $this->statusCode($e));
56
+        view()->share('current_section', 'error');
57
+
58
+        // immediately done if the error should not be reported
59
+        if ($this->shouldntReport($e)) {
60
+            return;
61
+        }
62
+
63
+        if (config('app.sentry')) {
64
+            $this->reportWithSentry($e);
65
+        } else {
66
+            return parent::report($e);
67
+        }
68
+    }
69
+
70
+    private function statusCode($e)
71
+    {
72
+        if (method_exists($e, 'getStatusCode')) {
73
+            return $e->getStatusCode();
74
+        } elseif ($e instanceof ModelNotFoundException) {
75
+            return 404;
76
+        } elseif ($e instanceof NotFoundHttpException) {
77
+            return 404;
78
+        } elseif ($e instanceof TokenMismatchException) {
79
+            return 403;
80
+        } else {
81
+            return 500;
82
+        }
83
+    }
84
+
85
+    private function reportWithSentry($e)
86
+    {
87
+        $tags = [
88
+            'http_code' => $this->statusCode($e),
89
+        ];
90
+
91
+        if (Auth::check()) {
92
+            $tags['user'] = Auth::user()->user_id;
93
+            $tags['username'] = Auth::user()->username_clean;
94
+        }
95
+
96
+        $client = new Raven_Client(config('app.sentry'), ['tags' => $tags]);
97
+
98
+        $ref = $client->getIdent(
99
+            $client->captureException($e));
100
+
101
+        view()->share('ref', $ref);
102
+    }
103
+    /**
104
+     * Render an exception into an HTTP response.
105
+     *
106
+     * @param \Illuminate\Http\Request $request
107
+     * @param \Exception               $e
108
+     *
109
+     * @return \Illuminate\Http\Response
110
+     */
111
+    public function render($request, Exception $e)
112
+    {
113
+        if (config('app.debug')) {
114
+            if ($this->isHttpException($e)) {
115
+                return $this->renderHttpException($e);
116
+            } else {
117
+                return parent::render($request, $e);
118
+            }
119
+        } else {
120
+            if ($request->ajax()) {
121
+                // turbolinks always reload on page error.
122
+                $response = response([]);
123
+            } else {
124
+                $response = response()->view('layout.error');
125
+            }
126
+
127
+            return $response->setStatusCode($this->statusCode($e));
128
+        }
129
+    }
126 130
 }

+ 173
- 165
app/Http/Controllers/APIController.php View File

@@ -1,172 +1,180 @@
1 1
 <?php
2 2
 
3 3
 /**
4
-*    Copyright 2015 ppy Pty. Ltd.
5
-*
6
-*    This file is part of osu!web. osu!web is distributed with the hope of
7
-*    attracting more community contributions to the core ecosystem of osu!.
8
-*
9
-*    osu!web is free software: you can redistribute it and/or modify
10
-*    it under the terms of the Affero GNU General Public License as published by
11
-*    the Free Software Foundation, either version 3 of the License, or
12
-*    (at your option) any later version.
13
-*
14
-*    osu!web is distributed WITHOUT ANY WARRANTY; without even the implied
15
-*    warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16
-*    See the GNU Affero General Public License for more details.
17
-*
18
-*    You should have received a copy of the GNU Affero General Public License
19
-*    along with osu!web.  If not, see <http://www.gnu.org/licenses/>.
20
-*
21
-*/
4
+ *    Copyright 2015 ppy Pty. Ltd.
5
+ *
6
+ *    This file is part of osu!web. osu!web is distributed with the hope of
7
+ *    attracting more community contributions to the core ecosystem of osu!.
8
+ *
9
+ *    osu!web is free software: you can redistribute it and/or modify
10
+ *    it under the terms of the Affero GNU General Public License as published by
11
+ *    the Free Software Foundation, either version 3 of the License, or
12
+ *    (at your option) any later version.
13
+ *
14
+ *    osu!web is distributed WITHOUT ANY WARRANTY; without even the implied
15
+ *    warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16
+ *    See the GNU Affero General Public License for more details.
17
+ *
18
+ *    You should have received a copy of the GNU Affero General Public License
19
+ *    along with osu!web.  If not, see <http://www.gnu.org/licenses/>.
20
+ */
22 21
 
23 22
 namespace App\Http\Controllers;
24 23
 
25
-class APIController extends Controller {
26
-	
27
-	use \App\Traits\ModdingAPI;
28
-	use \App\Traits\BeatmapAPI;
29
-
30
-	public function __construct() {
31
-		//$this->beforeFilter("auth");
32
-		$this->beforeFilter("csrf.api", ['on' => ['get', 'post', 'put', 'delete']]);
33
-	}
34
-
35
-	/**
36
-	 * GET /api/$version/translation/$lang?/$string 
37
-	 *
38
-	 * @api
39
-	 * @return json
40
-	 */
41
-	public function getTranslation($lang, $string = null) {
42
-
43
-		if (!$string) {
44
-			$string = $lang;
45
-			$lang = "en";
46
-		}
47
-
48
-		try {
49
-			App::setLocale($lang);
50
-		} catch (Exception $e) {
51
-			return Response::json(["error" => "unsupported language"]);
52
-		}
53
-
54
-		if (strpos($string, " ")) {
55
-			// dealing with an array
56
-			$strings = explode(" ", $string);
57
-			$translation = [];
58
-
59
-			foreach ($strings as $str)
60
-				$translation[$str] = Lang::get($str);
61
-
62
-		} else {
63
-			// single strings allow for fallback to english.
64
-			// multiples would involve too much 
65
-			$translation = Lang::get($string);
66
-
67
-			if ($translation == $string and $lang != "en") {
68
-				App::setLocale(Config::get("app.locale", "en"));
69
-				$translation = Lang::get($string);
70
-			}
71
-		}
72
-
73
-		return Response::json(["translation" => $translation]);
74
-
75
-	}
76
-
77
-	/**
78
-	 * Get the user who initiated an action
79
-	 *
80
-	 * @return User
81
-	 */
82
-	protected function user() {
83
-		return User::findByKey(Input::get("key")) ?: Auth::user();
84
-	}
85
-
86
-	/**
87
-	 * Get the error view for the code given.
88
-	 *
89
-	 * @return View
90
-	 */
91
-	public function getError($code = 404) {
92
-		return osu_error($code);
93
-	}
94
-
95
-	/**
96
-	 * DRYing up code a bit.
97
-	 *
98
-	 * @return json
99
-	 */
100
-	public function error($key, $namespace) {
101
-		return Response::json(["error" => Lang::get("$namespace.errors.$key")]);
102
-	}
103
-
104
-	/**
105
-	 * GET /api/$version/
106
-	 *
107
-	 * @api
108
-	 * @return json
109
-	 */
110
-	public function getIndex() {
111
-		return Response::json(["error" => "throw new NotImplementedError();"]);
112
-	}
113
-
114
-	/**
115
-	 * 404 method.
116
-	 *
117
-	 * @api
118
-	 * @return json
119
-	 */
120
-	public function missingMethod($parameters = []) {
121
-		return Response::json(["error" => 404]);
122
-	}
123
-
124
-	public function getFetchUserKey($username, $password, $hmac) {
125
-		// all bancho input should be HMAC'd to be sure it's coming from bancho
126
-		$check = hash_hmac("sha512", $username . $password, Config::get("osu.bancho.hmac"));
127
-
128
-		if ($check !== $hmac) {
129
-			// log HMAC failures
130
-			sentry_log("HMAC failure for fetch-user-key", 403, Raven_Client::FATAL);
131
-
132
-			return Response::json(["error" => 400]);
133
-		}
134
-
135
-		if (Auth::check() and Auth::user()->user_id === User::SYSTEM) {
136
-			$user = User::where("username", "=", $username)->get();
137
-
138
-			if ($user) {
139
-				if ($key = $user->getBanchoKey()) {
140
-					if (Auth::validate(["username" => $username, "password" => $password])) {
141
-						return Response::json(["success" => $key]);
142
-					} else {
143
-						return Response::json(["error" => 403]);
144
-					}
145
-				} else {
146
-					// If a user doesn;t have a key, they're banned
147
-					return Response::json(["error" => 401]);
148
-				}
149
-			} else {
150
-				// use status codes. they're easier for bancho
151
-				// to understand and easier to deserialize
152
-				return Response::json(["error" => 404]);
153
-			}
154
-		} else {
155
-			// log bancho auth failures
156
-			sentry_log("auth failure for fetch-user-key", 403, Raven_Client::FATAL);
157
-		}
158
-	}
159
-
160
-	public function anyGitCallback() {
161
-		if (Auth::check() and Auth::user()->user_id === User::GITHUB) {
162
-			
163
-			if (Input::get("ref") == "refs/heads/master") {
164
-				Artisan::call("git:pull", ["--silent"]);
165
-			}
166
-			
167
-		} else {
168
-			sentry_log("user attempting to access git callback", "fatal", Raven_Client::FATAL);
169
-			return Response::json(["error" => "no"]);
170
-		}
171
-	}
24
+class APIController extends Controller
25
+{
26
+    use \App\Traits\ModdingAPI;
27
+    use \App\Traits\BeatmapAPI;
28
+
29
+    public function __construct()
30
+    {
31
+        //$this->beforeFilter("auth");
32
+        $this->beforeFilter('csrf.api', ['on' => ['get', 'post', 'put', 'delete']]);
33
+    }
34
+
35
+    /**
36
+     * GET /api/$version/translation/$lang?/$string.
37
+     *
38
+     * @api
39
+     *
40
+     * @return json
41
+     */
42
+    public function getTranslation($lang, $string = null)
43
+    {
44
+        if (! $string) {
45
+            $string = $lang;
46
+            $lang = 'en';
47
+        }
48
+
49
+        try {
50
+            App::setLocale($lang);
51
+        } catch (Exception $e) {
52
+            return Response::json(['error' => 'unsupported language']);
53
+        }
54
+
55
+        if (strpos($string, ' ')) {
56
+            // dealing with an array
57
+            $strings = explode(' ', $string);
58
+            $translation = [];
59
+
60
+            foreach ($strings as $str) {
61
+                $translation[$str] = Lang::get($str);
62
+            }
63
+        } else {
64
+            // single strings allow for fallback to english.
65
+            // multiples would involve too much
66
+            $translation = Lang::get($string);
67
+
68
+            if ($translation == $string and $lang != 'en') {
69
+                App::setLocale(Config::get('app.locale', 'en'));
70
+                $translation = Lang::get($string);
71
+            }
72
+        }
73
+
74
+        return Response::json(['translation' => $translation]);
75
+    }
76
+
77
+    /**
78
+     * Get the user who initiated an action.
79
+     *
80
+     * @return User
81
+     */
82
+    protected function user()
83
+    {
84
+        return User::findByKey(Input::get('key')) ?: Auth::user();
85
+    }
86
+
87
+    /**
88
+     * Get the error view for the code given.
89
+     *
90
+     * @return View
91
+     */
92
+    public function getError($code = 404)
93
+    {
94
+        return osu_error($code);
95
+    }
96
+
97
+    /**
98
+     * DRYing up code a bit.
99
+     *
100
+     * @return json
101
+     */
102
+    public function error($key, $namespace)
103
+    {
104
+        return Response::json(['error' => Lang::get("$namespace.errors.$key")]);
105
+    }
106
+
107
+    /**
108
+     * GET /api/$version/.
109
+     *
110
+     * @api
111
+     *
112
+     * @return json
113
+     */
114
+    public function getIndex()
115
+    {
116
+        return Response::json(['error' => 'throw new NotImplementedError();']);
117
+    }
118
+
119
+    /**
120
+     * 404 method.
121
+     *
122
+     * @api
123
+     *
124
+     * @return json
125
+     */
126
+    public function missingMethod($parameters = [])
127
+    {
128
+        return Response::json(['error' => 404]);
129
+    }
130
+
131
+    public function getFetchUserKey($username, $password, $hmac)
132
+    {
133
+        // all bancho input should be HMAC'd to be sure it's coming from bancho
134
+        $check = hash_hmac('sha512', $username.$password, Config::get('osu.bancho.hmac'));
135
+
136
+        if ($check !== $hmac) {
137
+            // log HMAC failures
138
+            sentry_log('HMAC failure for fetch-user-key', 403, Raven_Client::FATAL);
139
+
140
+            return Response::json(['error' => 400]);
141
+        }
142
+
143
+        if (Auth::check() and Auth::user()->user_id === User::SYSTEM) {
144
+            $user = User::where('username', '=', $username)->get();
145
+
146
+            if ($user) {
147
+                if ($key = $user->getBanchoKey()) {
148
+                    if (Auth::validate(['username' => $username, 'password' => $password])) {
149
+                        return Response::json(['success' => $key]);
150
+                    } else {
151
+                        return Response::json(['error' => 403]);
152
+                    }
153
+                } else {
154
+                    // If a user doesn;t have a key, they're banned
155
+                    return Response::json(['error' => 401]);
156
+                }
157
+            } else {
158
+                // use status codes. they're easier for bancho
159
+                // to understand and easier to deserialize
160
+                return Response::json(['error' => 404]);
161
+            }
162
+        } else {
163
+            // log bancho auth failures
164
+            sentry_log('auth failure for fetch-user-key', 403, Raven_Client::FATAL);
165
+        }
166
+    }
167
+
168
+    public function anyGitCallback()
169
+    {
170
+        if (Auth::check() and Auth::user()->user_id === User::GITHUB) {
171
+            if (Input::get('ref') == 'refs/heads/master') {
172
+                Artisan::call('git:pull', ['--silent']);
173
+            }
174
+        } else {
175
+            sentry_log('user attempting to access git callback', 'fatal', Raven_Client::FATAL);
176
+
177
+            return Response::json(['error' => 'no']);
178
+        }
179
+    }
172 180
 }

+ 46
- 49
app/Http/Controllers/AccountController.php View File

@@ -1,68 +1,65 @@
1 1
 <?php
2 2
 
3 3
 /**
4
-*    Copyright 2015 ppy Pty. Ltd.
5
-*
6
-*    This file is part of osu!web. osu!web is distributed with the hope of
7
-*    attracting more community contributions to the core ecosystem of osu!.
8
-*
9
-*    osu!web is free software: you can redistribute it and/or modify
10
-*    it under the terms of the Affero GNU General Public License as published by
11
-*    the Free Software Foundation, either version 3 of the License, or
12
-*    (at your option) any later version.
13
-*
14
-*    osu!web is distributed WITHOUT ANY WARRANTY; without even the implied
15
-*    warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16
-*    See the GNU Affero General Public License for more details.
17
-*
18
-*    You should have received a copy of the GNU Affero General Public License
19
-*    along with osu!web.  If not, see <http://www.gnu.org/licenses/>.
20
-*
21
-*/
4
+ *    Copyright 2015 ppy Pty. Ltd.
5
+ *
6
+ *    This file is part of osu!web. osu!web is distributed with the hope of
7
+ *    attracting more community contributions to the core ecosystem of osu!.
8
+ *
9
+ *    osu!web is free software: you can redistribute it and/or modify
10
+ *    it under the terms of the Affero GNU General Public License as published by
11
+ *    the Free Software Foundation, either version 3 of the License, or
12
+ *    (at your option) any later version.
13
+ *
14
+ *    osu!web is distributed WITHOUT ANY WARRANTY; without even the implied
15
+ *    warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16
+ *    See the GNU Affero General Public License for more details.
17
+ *
18
+ *    You should have received a copy of the GNU Affero General Public License
19
+ *    along with osu!web.  If not, see <http://www.gnu.org/licenses/>.
20
+ */
22 21
 
23 22
 namespace App\Http\Controllers;
24 23
 
24
+use App\Transformers\UserTransformer;
25 25
 use Auth;
26 26
 use Request;
27 27
 
28
-use App\Models\UserProfileCustomization;
29
-use App\Transformers\UserTransformer;
30
-
31 28
 class AccountController extends Controller
32 29
 {
33
-	protected $section = "account";
30
+    protected $section = 'account';
34 31
 
35
-	public function __construct()
36
-	{
37
-		$this->middleware('auth');
32
+    public function __construct()
33
+    {
34
+        $this->middleware('auth');
38 35
 
39
-		return parent::__construct();
40
-	}
36
+        return parent::__construct();
37
+    }
41 38
 
42
-	public function updateProfileCover()
43
-	{
44
-		if (Request::hasFile('cover_file') && !Auth::user()->osu_subscriber) {
45
-			abort(403);
46
-		}
39
+    public function updateProfileCover()
40
+    {
41
+        if (Request::hasFile('cover_file') && ! Auth::user()->osu_subscriber) {
42
+            abort(403);
43
+        }
47 44
 
48
-		$customization = Auth::user()->profileCustomization()->firstOrNew([]);
49
-		$customization->setCover($errors, Request::input('cover_id'), Request::file('cover_file'));
50
-		if (count($errors) === 0) {
51
-			return fractal_item_array(Auth::user(), new UserTransformer);
52
-		} else {
53
-			return error_popup(implode(',', $errors));
54
-		}
55
-	}
45
+        $customization = Auth::user()->profileCustomization()->firstOrNew([]);
46
+        $customization->setCover($errors, Request::input('cover_id'), Request::file('cover_file'));
47
+        if (count($errors) === 0) {
48
+            return fractal_item_array(Auth::user(), new UserTransformer());
49
+        } else {
50
+            return error_popup(implode(',', $errors));
51
+        }
52
+    }
56 53
 
57
-	public function updatePage()
58
-	{
59
-		$user = Auth::user();
60
-		if (!$user->osu_subscriber && $user->userPage === null) {
61
-			abort(403);
62
-		}
54
+    public function updatePage()
55
+    {
56
+        $user = Auth::user();
57
+        if (! $user->osu_subscriber && $user->userPage === null) {
58
+            abort(403);
59
+        }
63 60
 
64
-		$user = $user->updatePage(Request::input("body"));
61
+        $user = $user->updatePage(Request::input('body'));
65 62
 
66
-		return ["html" => $user->userPage->bodyHTML];
67
-	}
63
+        return ['html' => $user->userPage->bodyHTML];
64
+    }
68 65
 }

+ 91
- 88
app/Http/Controllers/BeatmapController.php View File

@@ -1,97 +1,100 @@
1 1
 <?php
2 2
 
3 3
 /**
4
-*    Copyright 2015 ppy Pty. Ltd.
5
-*
6
-*    This file is part of osu!web. osu!web is distributed with the hope of
7
-*    attracting more community contributions to the core ecosystem of osu!.
8
-*
9
-*    osu!web is free software: you can redistribute it and/or modify
10
-*    it under the terms of the Affero GNU General Public License as published by
11
-*    the Free Software Foundation, either version 3 of the License, or
12
-*    (at your option) any later version.
13
-*
14
-*    osu!web is distributed WITHOUT ANY WARRANTY; without even the implied
15
-*    warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16
-*    See the GNU Affero General Public License for more details.
17
-*
18
-*    You should have received a copy of the GNU Affero General Public License
19
-*    along with osu!web.  If not, see <http://www.gnu.org/licenses/>.
20
-*
21
-*/
4
+ *    Copyright 2015 ppy Pty. Ltd.
5
+ *
6
+ *    This file is part of osu!web. osu!web is distributed with the hope of
7
+ *    attracting more community contributions to the core ecosystem of osu!.
8
+ *
9
+ *    osu!web is free software: you can redistribute it and/or modify
10
+ *    it under the terms of the Affero GNU General Public License as published by
11
+ *    the Free Software Foundation, either version 3 of the License, or
12
+ *    (at your option) any later version.
13
+ *
14
+ *    osu!web is distributed WITHOUT ANY WARRANTY; without even the implied
15
+ *    warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16
+ *    See the GNU Affero General Public License for more details.
17
+ *
18
+ *    You should have received a copy of the GNU Affero General Public License
19
+ *    along with osu!web.  If not, see <http://www.gnu.org/licenses/>.
20
+ */
22 21
 
23 22
 namespace App\Http\Controllers;
24 23
 
25 24
 use App\Models\BeatmapSet;
26 25
 
27
-class BeatmapController extends Controller {
28
-
29
-	protected $section = "beatmaps";
30
-
31
-	public function getListing() {
32
-
33
-		$listing = BeatmapSet::listing();
34
-
35
-		return view("beatmaps.listings")
36
-			->with("beatmaps", $listing);
37
-	}
38
-
39
-
40
-	public function getMap($id = null) {
41
-		$beatmap = Beatmap::findOrFail($id);
42
-
43
-		return view("beatmaps.map")
44
-			->with("beatmap", $beatmap);
45
-	}
46
-
47
-
48
-	public function getMapSet($id = null) {
49
-		$set = BeatmapSet::findOrFail($id);
50
-
51
-		return view("beatmaps.set")
52
-			->with("set", $set);
53
-	}
54
-
55
-
56
-	public function getPacks($id = null) {
57
-		if ($id === null)
58
-			return view("beatmaps.packs");
59
-
60
-		return view("beatmaps.pack")->with("id", $id);
61
-	}
62
-
63
-
64
-	public function getCharts($id = null) {
65
-		if ($id === null)
66
-			return view("beatmaps.charts");
67
-
68
-		// TODO: chart model
69
-		return view("beatmaps.chart")->with("id", $id);
70
-	}
71
-
72
-
73
-	public function getModding($id = null) {
74
-		if ($id === null) {
75
-			return redirect("/user/login");
76
-		} else {
77
-			$set = BeatmapSet::findOrFail($id);
78
-
79
-			return view("beatmaps.modding")
80
-				->with("set", $set);
81
-		}
82
-	}
83
-
84
-	public function getModdingReact($id = null) {
85
-		if ($id === null) {
86
-			return redirect("/user/login");
87
-		} else {
88
-			$beatmapSet = BeatmapSet::findOrFail($id);
89
-
90
-			return view("beatmaps.modding_react")->with("beatmapset", $beatmapSet);
91
-		}
92
-	}
93
-
94
-	public function getDownload($id) {
95
-		$set = BeatmapSet::findOrFail($id);
96
-	}
26
+class BeatmapController extends Controller
27
+{
28
+    protected $section = 'beatmaps';
29
+
30
+    public function getListing()
31
+    {
32
+        $listing = BeatmapSet::listing();
33
+
34
+        return view('beatmaps.listings')
35
+            ->with('beatmaps', $listing);
36
+    }
37
+
38
+    public function getMap($id = null)
39
+    {
40
+        $beatmap = Beatmap::findOrFail($id);
41
+
42
+        return view('beatmaps.map')
43
+            ->with('beatmap', $beatmap);
44
+    }
45
+
46
+    public function getMapSet($id = null)
47
+    {
48
+        $set = BeatmapSet::findOrFail($id);
49
+
50
+        return view('beatmaps.set')
51
+            ->with('set', $set);
52
+    }
53
+
54
+    public function getPacks($id = null)
55
+    {
56
+        if ($id === null) {
57
+            return view('beatmaps.packs');
58
+        }
59
+
60
+        return view('beatmaps.pack')->with('id', $id);
61
+    }
62
+
63
+    public function getCharts($id = null)
64
+    {
65
+        if ($id === null) {
66
+            return view('beatmaps.charts');
67
+        }
68
+
69
+        // TODO: chart model
70
+        return view('beatmaps.chart')->with('id', $id);
71
+    }
72
+
73
+    public function getModding($id = null)
74
+    {
75
+        if ($id === null) {
76
+            return redirect('/user/login');
77
+        } else {
78
+            $set = BeatmapSet::findOrFail($id);
79
+
80
+            return view('beatmaps.modding')
81
+                ->with('set', $set);
82
+        }
83
+    }
84
+
85
+    public function getModdingReact($id = null)
86
+    {
87
+        if ($id === null) {
88
+            return redirect('/user/login');
89
+        } else {
90
+            $beatmapSet = BeatmapSet::findOrFail($id);
91
+
92
+            return view('beatmaps.modding_react')->with('beatmapset', $beatmapSet);
93
+        }
94
+    }
95
+
96
+    public function getDownload($id)
97
+    {
98
+        $set = BeatmapSet::findOrFail($id);
99
+    }
97 100
 }

+ 40
- 44
app/Http/Controllers/CommunityController.php View File

@@ -1,53 +1,49 @@
1 1
 <?php
2 2
 
3 3
 /**
4
-*    Copyright 2015 ppy Pty. Ltd.
5
-*
6
-*    This file is part of osu!web. osu!web is distributed with the hope of
7
-*    attracting more community contributions to the core ecosystem of osu!.
8
-*
9
-*    osu!web is free software: you can redistribute it and/or modify
10
-*    it under the terms of the Affero GNU General Public License as published by
11
-*    the Free Software Foundation, either version 3 of the License, or
12
-*    (at your option) any later version.
13
-*
14
-*    osu!web is distributed WITHOUT ANY WARRANTY; without even the implied
15
-*    warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16
-*    See the GNU Affero General Public License for more details.
17
-*
18
-*    You should have received a copy of the GNU Affero General Public License
19
-*    along with osu!web.  If not, see <http://www.gnu.org/licenses/>.
20
-*
21
-*/
4
+ *    Copyright 2015 ppy Pty. Ltd.
5
+ *
6
+ *    This file is part of osu!web. osu!web is distributed with the hope of
7
+ *    attracting more community contributions to the core ecosystem of osu!.
8
+ *
9
+ *    osu!web is free software: you can redistribute it and/or modify
10
+ *    it under the terms of the Affero GNU General Public License as published by
11
+ *    the Free Software Foundation, either version 3 of the License, or
12
+ *    (at your option) any later version.
13
+ *
14
+ *    osu!web is distributed WITHOUT ANY WARRANTY; without even the implied
15
+ *    warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16
+ *    See the GNU Affero General Public License for more details.
17
+ *
18
+ *    You should have received a copy of the GNU Affero General Public License
19
+ *    along with osu!web.  If not, see <http://www.gnu.org/licenses/>.
20
+ */
22 21
 
23 22
 namespace App\Http\Controllers;
24 23
 
25
-use App\Models\User;
26
-use App\Models\UserStatistics;
27
-use App\Transformers\UserTransformer;
28
-use App\Transformers\UserStatisticsTransformer;
24
+class CommunityController extends Controller
25
+{
26
+    /*
27
+    |--------------------------------------------------------------------------
28
+    | Community Controller
29
+    |--------------------------------------------------------------------------
30
+    |
31
+    | Frontend to the community of osu!
32
+    | Unsure if forum should use /forum or not.
33
+    | Route:
34
+    |
35
+    |	Route::get('/community</page>', 'CommunityController@get<Page>');
36
+    |
37
+    */
38
+    protected $section = 'community';
29 39
 
30
-class CommunityController extends Controller {
40
+    public function getChat()
41
+    {