|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Coyote\Http\Controllers\Microblog; |
|
4
|
|
|
|
|
5
|
|
|
use Coyote\Events\MicroblogWasDeleted; |
|
6
|
|
|
use Coyote\Events\MicroblogSaved; |
|
7
|
|
|
use Coyote\Http\Controllers\Controller; |
|
8
|
|
|
use Coyote\Http\Requests\MicroblogRequest; |
|
9
|
|
|
use Coyote\Http\Resources\MicroblogResource; |
|
10
|
|
|
use Coyote\Microblog; |
|
11
|
|
|
use Coyote\Notifications\Microblog\DeletedNotification; |
|
12
|
|
|
use Coyote\Repositories\Criteria\WithTrashed; |
|
13
|
|
|
use Coyote\Repositories\Contracts\UserRepositoryInterface as UserRepository; |
|
14
|
|
|
use Coyote\Services\Stream\Activities\Create as Stream_Create; |
|
15
|
|
|
use Coyote\Services\Stream\Activities\Update as Stream_Update; |
|
16
|
|
|
use Coyote\Services\Stream\Activities\Delete as Stream_Delete; |
|
17
|
|
|
use Coyote\Services\Stream\Objects\Microblog as Stream_Microblog; |
|
18
|
|
|
use Illuminate\Http\Request; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* Class SubmitController |
|
22
|
|
|
* @package Coyote\Http\Controllers\Microblog |
|
23
|
|
|
*/ |
|
24
|
|
|
class SubmitController extends Controller |
|
25
|
|
|
{ |
|
26
|
|
|
/** |
|
27
|
|
|
* @var UserRepository |
|
28
|
|
|
*/ |
|
29
|
|
|
private $user; |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* @param UserRepository $user |
|
33
|
|
|
*/ |
|
34
|
|
|
public function __construct(UserRepository $user) |
|
35
|
|
|
{ |
|
36
|
|
|
parent::__construct(); |
|
37
|
|
|
|
|
38
|
|
|
$this->user = $user; |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* @param MicroblogRequest $request |
|
43
|
|
|
* @param $microblog |
|
44
|
|
|
* @return MicroblogResource |
|
45
|
|
|
* @throws \Illuminate\Auth\Access\AuthorizationException |
|
46
|
|
|
*/ |
|
47
|
|
|
public function save(MicroblogRequest $request, ?Microblog $microblog) |
|
48
|
|
|
{ |
|
49
|
|
|
$this->user->pushCriteria(new WithTrashed()); |
|
50
|
|
|
|
|
51
|
|
|
if (!$microblog->exists) { |
|
52
|
|
|
$microblog->user()->associate($this->auth); |
|
|
|
|
|
|
53
|
|
|
} else { |
|
54
|
|
|
$this->authorize('update', $microblog); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
$microblog->fill($request->only(['text'])); |
|
58
|
|
|
|
|
59
|
|
|
$this->transaction(function () use ($microblog, $request) { |
|
60
|
|
|
$microblog->save(); |
|
61
|
|
|
$microblog->assets()->sync($request->input('assets')); |
|
62
|
|
|
|
|
63
|
|
|
$object = (new Stream_Microblog())->map($microblog); |
|
|
|
|
|
|
64
|
|
|
|
|
65
|
|
|
if ($microblog->wasRecentlyCreated) { |
|
66
|
|
|
// increase reputation points |
|
67
|
|
|
app('reputation.microblog.create')->map($microblog)->save(); |
|
|
|
|
|
|
68
|
|
|
|
|
69
|
|
|
// put this to activity stream |
|
70
|
|
|
stream(Stream_Create::class, $object); |
|
71
|
|
|
|
|
72
|
|
|
if ($this->auth->allow_subscribe) { |
|
73
|
|
|
// enable subscribe button |
|
74
|
|
|
$microblog->is_subscribed = true; |
|
|
|
|
|
|
75
|
|
|
$microblog->subscribers()->create(['user_id' => $this->auth->id]); |
|
76
|
|
|
} |
|
77
|
|
|
} else { |
|
78
|
|
|
stream(Stream_Update::class, $object); |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
$microblog->setTags(array_pluck($request->input('tags', []), 'name')); |
|
82
|
|
|
}); |
|
83
|
|
|
|
|
84
|
|
|
broadcast(new MicroblogSaved($microblog))->toOthers(); |
|
|
|
|
|
|
85
|
|
|
|
|
86
|
|
|
MicroblogResource::withoutWrapping(); |
|
87
|
|
|
|
|
88
|
|
|
$microblog->unsetRelation('assets'); |
|
89
|
|
|
$microblog->load(['assets', 'tags']); |
|
90
|
|
|
|
|
91
|
|
|
return new MicroblogResource($microblog); |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
/** |
|
95
|
|
|
* Usuniecie wpisu z mikrobloga |
|
96
|
|
|
* |
|
97
|
|
|
* @param \Coyote\Microblog $microblog |
|
98
|
|
|
*/ |
|
99
|
|
|
public function delete($microblog) |
|
100
|
|
|
{ |
|
101
|
|
|
abort_if(!$microblog->exists, 404); |
|
102
|
|
|
$this->authorize('delete', $microblog); |
|
103
|
|
|
|
|
104
|
|
|
$this->transaction(function () use ($microblog) { |
|
105
|
|
|
$microblog->delete(); |
|
106
|
|
|
// cofniecie pkt reputacji |
|
107
|
|
|
app('reputation.microblog.create')->undo($microblog->id); |
|
|
|
|
|
|
108
|
|
|
|
|
109
|
|
|
// put this to activity stream |
|
110
|
|
|
stream(Stream_Delete::class, (new Stream_Microblog())->map($microblog)); |
|
111
|
|
|
}); |
|
112
|
|
|
|
|
113
|
|
|
if ($this->userId !== $microblog->user_id) { |
|
114
|
|
|
$microblog->user->notify(new DeletedNotification($microblog, $this->auth)); |
|
115
|
|
|
} |
|
116
|
|
|
|
|
117
|
|
|
event(new MicroblogWasDeleted($microblog)); |
|
118
|
|
|
} |
|
119
|
|
|
|
|
120
|
|
|
/** |
|
121
|
|
|
* @param Request $request |
|
122
|
|
|
* @return \Symfony\Component\HttpFoundation\Response |
|
123
|
|
|
*/ |
|
124
|
|
|
public function preview(Request $request) |
|
125
|
|
|
{ |
|
126
|
|
|
return response($this->getParser()->parse((string) $request->get('text'))); |
|
127
|
|
|
} |
|
128
|
|
|
|
|
129
|
|
|
/** |
|
130
|
|
|
* @param Microblog $microblog |
|
131
|
|
|
* @throws \Illuminate\Auth\Access\AuthorizationException |
|
132
|
|
|
*/ |
|
133
|
|
|
public function toggleSponsored(Microblog $microblog) |
|
134
|
|
|
{ |
|
135
|
|
|
$this->authorize('moderate', $microblog); |
|
136
|
|
|
|
|
137
|
|
|
$microblog->is_sponsored = !$microblog->is_sponsored; |
|
138
|
|
|
$microblog->save(); |
|
139
|
|
|
} |
|
140
|
|
|
|
|
141
|
|
|
/** |
|
142
|
|
|
* @return \Coyote\Services\Parser\Factories\PmFactory |
|
143
|
|
|
*/ |
|
144
|
|
|
private function getParser() |
|
145
|
|
|
{ |
|
146
|
|
|
return app('parser.microblog'); |
|
|
|
|
|
|
147
|
|
|
} |
|
148
|
|
|
} |
|
149
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.