| Línea 100... |
Línea 100... |
| 100 |
$id = $this->params()->fromRoute('id');
|
100 |
$id = $this->params()->fromRoute('id');
|
| Línea 101... |
Línea 101... |
| 101 |
|
101 |
|
| 102 |
$postMapper = PostMapper::getInstance($this->adapter);
|
102 |
$postMapper = PostMapper::getInstance($this->adapter);
|
| Línea -... |
Línea 103... |
| - |
|
103 |
$post = $postMapper->fetchOneByUuid($id);
|
| - |
|
104 |
|
| - |
|
105 |
$isJson = false;
|
| - |
|
106 |
|
| - |
|
107 |
$headers = $request->getHeaders();
|
| - |
|
108 |
if ($headers->has('Accept')) {
|
| - |
|
109 |
$accept = $headers->get('Accept');
|
| - |
|
110 |
|
| - |
|
111 |
$prioritized = $accept->getPrioritized();
|
| - |
|
112 |
|
| - |
|
113 |
foreach ($prioritized as $key => $value) {
|
| - |
|
114 |
$raw = trim($value->getRaw());
|
| - |
|
115 |
|
| - |
|
116 |
if (!$isJson) {
|
| - |
|
117 |
$isJson = strpos($raw, 'json');
|
| - |
|
118 |
}
|
| - |
|
119 |
}
|
| - |
|
120 |
}
|
| - |
|
121 |
|
| 103 |
$post = $postMapper->fetchOneByUuid($id);
|
122 |
// $isJson = true;
|
| - |
|
123 |
if ($isJson) {
|
| - |
|
124 |
if (!$post || $post->status != Post::STATUS_ACTIVE) {
|
| - |
|
125 |
return new JsonModel([
|
| - |
|
126 |
'success' => false,
|
| - |
|
127 |
'data' => 'ERROR_POST_NOT_AVAILABLE'
|
| - |
|
128 |
]);
|
| - |
|
129 |
}
|
| - |
|
130 |
|
| - |
|
131 |
} else {
|
| - |
|
132 |
|
| 104 |
|
133 |
|
| 105 |
if (!$post || $post->status != Post::STATUS_ACTIVE) {
|
134 |
if (!$post || $post->status != Post::STATUS_ACTIVE) {
|
| 106 |
$flashMessenger = $this->plugin('FlashMessenger');
|
135 |
$flashMessenger = $this->plugin('FlashMessenger');
|
| 107 |
|
136 |
|
| 108 |
if (!$id) {
|
137 |
if (!$id) {
|
| - |
|
138 |
$flashMessenger->addErrorMessage('ERROR_POST_NOT_AVAILABLE');
|
| 109 |
$flashMessenger->addErrorMessage('ERROR_POST_NOT_AVAILABLE');
|
139 |
return $this->redirect()->toRoute('dashboard');
|
| 110 |
return $this->redirect()->toRoute('dashboard');
|
140 |
}
|
| 111 |
}
|
- |
|
| 112 |
}
|
- |
|
| Línea 113... |
Línea 141... |
| 113 |
|
141 |
}
|
| 114 |
|
142 |
}
|
| 115 |
|
143 |
|
| 116 |
$timestamp = time();
|
144 |
$timestamp = time();
|
| 117 |
|
145 |
|
| 118 |
list($usec, $sec) = explode(' ', microtime());
|
146 |
list($usec, $sec) = explode(' ', microtime());
|
| 119 |
$seed = intval($sec + ((float) $usec * 100000));
|
147 |
$seed = intval($sec + ((float) $usec * 100000));
|
| 120 |
mt_srand($seed, MT_RAND_MT19937);
|
148 |
mt_srand($seed, MT_RAND_MT19937);
|
| 121 |
$rand = mt_rand();
|
149 |
$rand = mt_rand();
|
| 122 |
|
150 |
|
| 123 |
|
151 |
|
| 124 |
|
152 |
|
| 125 |
$password = md5('user-' . $currentUser->uuid . '-post-' . $post->uuid . '-timestamp-' . $timestamp . '-rand-' . $rand . '-share-key-' . $currentUser->share_key);
|
153 |
$password = md5('user-' . $currentUser->uuid . '-post-' . $post->uuid . '-timestamp-' . $timestamp . '-rand-' . $rand . '-share-key-' . $currentUser->share_key);
|
| 126 |
|
154 |
|
| 127 |
|
155 |
|
| 128 |
$share_params = [
|
156 |
$share_params = [
|
| 129 |
'type' => 'post',
|
157 |
'type' => 'post',
|
| 130 |
'code' => $post->uuid,
|
158 |
'code' => $post->uuid,
|
| 131 |
'user' => $currentUser->uuid,
|
159 |
'user' => $currentUser->uuid,
|
| 132 |
'timestamp' => $timestamp,
|
160 |
'timestamp' => $timestamp,
|
| 133 |
'rand' => $rand,
|
- |
|
| 134 |
'password' => $password,
|
- |
|
| 135 |
];
|
- |
|
| 136 |
|
161 |
'rand' => $rand,
|
| 137 |
|
162 |
'password' => $password,
|
| 138 |
|
163 |
];
|
| 139 |
$share_increment_external_counter_url = $this->url()->fromRoute('share/increment-external-counter', $share_params, ['force_canonical' => true]);
|
164 |
$share_increment_external_counter_url = $this->url()->fromRoute('share/increment-external-counter', $share_params, ['force_canonical' => true]);
|
| 140 |
|
165 |
|
| 141 |
|
166 |
|
| 142 |
$share_external_url = $this->url()->fromRoute('shorter/generate', ['code' => $post->uuid, 'type' => 'post'], ['force_canonical' => true]);
|
167 |
$share_external_url = $this->url()->fromRoute('shorter/generate', ['code' => $post->uuid, 'type' => 'post'], ['force_canonical' => true]);
|
| 143 |
|
168 |
|
| 144 |
//$contentReactionMapper = ContentReactionMapper::getInstance($this->adapter);
|
169 |
//$contentReactionMapper = ContentReactionMapper::getInstance($this->adapter);
|
| 145 |
//$contentReaction = $contentReactionMapper->fetchOneByPostIdAndUserId($post->id, $currentUser->id);
|
170 |
//$contentReaction = $contentReactionMapper->fetchOneByPostIdAndUserId($post->id, $currentUser->id);
|
| 146 |
|
171 |
|
| 147 |
$contentReactionMapper = ContentReactionMapper::getInstance($this->adapter);
|
172 |
$contentReactionMapper = ContentReactionMapper::getInstance($this->adapter);
|
| - |
|
173 |
$reactions = $contentReactionMapper->fetchCountByPostId($post->id);
|
| - |
|
174 |
$reaction = $contentReactionMapper->fetchOneByPostIdAndUserId($post->id, $currentUser->id);
|
| - |
|
175 |
|
| - |
|
176 |
if ($isJson) {
|
| - |
|
177 |
return new JsonModel([
|
| - |
|
178 |
'success' => true,
|
| - |
|
179 |
'data' => [
|
| - |
|
180 |
'post' => $post,
|
| - |
|
181 |
'id' => $post->id,
|
| - |
|
182 |
'uuid' => $post->uuid,
|
| - |
|
183 |
'title' => $post->title,
|
| - |
|
184 |
'description' => $post->description,
|
| - |
|
185 |
'url' => $post->url,
|
| - |
|
186 |
'date' => $post->date,
|
| - |
|
187 |
'status' => $post->status,
|
| - |
|
188 |
'image' => $post->image,
|
| - |
|
189 |
'file' => $post->file,
|
| - |
|
190 |
'added_on' => $post->added_on,
|
| - |
|
191 |
'share_external_url' => $share_external_url,
|
| - |
|
192 |
'total_share_external' => $post->total_external_shared,
|
| - |
|
193 |
'share_increment_external_counter_url' => $share_increment_external_counter_url,
|
| - |
|
194 |
'comments_url' => $this->url()->fromRoute('post/comments', ['id' => $post->uuid]),
|
| - |
|
195 |
'comments_add_url' => $this->url()->fromRoute('post/comments/add', ['id' => $post->uuid]),
|
| - |
|
196 |
'save_reaction_url' => $this->url()->fromRoute('post/save-reaction', ['id' => $post->uuid]),
|
| - |
|
197 |
'delete_reaction_url' => $this->url()->fromRoute('post/delete-reaction', ['id' => $post->uuid]),
|
| - |
|
198 |
'my_reaction' => $reaction ? $reaction->reaction : '',
|
| - |
|
199 |
'reactions' => $reactions,
|
| - |
|
200 |
//'is_liked' => $contentReaction ? 1 : 0,
|
| - |
|
201 |
//'like_url' => $this->url()->fromRoute('post/like', ['id' => $post->uuid]),
|
| - |
|
202 |
//'unlike_url' => $this->url()->fromRoute('post/unlike', ['id' => $post->uuid]),
|
| - |
|
203 |
|
| - |
|
204 |
]
|
| 148 |
$reactions = $contentReactionMapper->fetchCountByPostId($post->id);
|
205 |
]);
|
| 149 |
$reaction = $contentReactionMapper->fetchOneByPostIdAndUserId($post->id, $currentUser->id);
|
206 |
} else {
|
| 150 |
|
207 |
|
| 151 |
|
208 |
|
| 152 |
$this->layout()->setTemplate('layout/layout.phtml');
|
209 |
$this->layout()->setTemplate('layout/layout.phtml');
|
| 153 |
$viewModel = new ViewModel();
|
210 |
$viewModel = new ViewModel();
|
| 154 |
$viewModel->setTemplate('leaders-linked/post/view.phtml');
|
211 |
$viewModel->setTemplate('leaders-linked/post/view.phtml');
|
| 155 |
$viewModel->setVariables([
|
212 |
$viewModel->setVariables([
|
| 156 |
'post' => $post,
|
213 |
'post' => $post,
|
| 157 |
'id' => $post->id,
|
214 |
'id' => $post->id,
|
| 158 |
'uuid' => $post->uuid,
|
215 |
'uuid' => $post->uuid,
|
| 159 |
'title' => $post->title,
|
216 |
'title' => $post->title,
|
| 160 |
'description' => $post->description,
|
217 |
'description' => $post->description,
|
| 161 |
'url' => $post->url,
|
218 |
'url' => $post->url,
|
| 162 |
'date' => $post->date,
|
219 |
'date' => $post->date,
|
| 163 |
'status' => $post->status,
|
220 |
'status' => $post->status,
|
| 164 |
'image' => $post->image,
|
221 |
'image' => $post->image,
|
| 165 |
'file' => $post->file,
|
222 |
'file' => $post->file,
|
| 166 |
'added_on' => $post->added_on,
|
223 |
'added_on' => $post->added_on,
|
| 167 |
'share_external_url' => $share_external_url,
|
224 |
'share_external_url' => $share_external_url,
|
| 168 |
'total_share_external' => $post->total_external_shared,
|
225 |
'total_share_external' => $post->total_external_shared,
|
| 169 |
'share_increment_external_counter_url' => $share_increment_external_counter_url,
|
226 |
'share_increment_external_counter_url' => $share_increment_external_counter_url,
|
| 170 |
'comments_url' => $this->url()->fromRoute('post/comments', ['id' => $post->uuid]),
|
227 |
'comments_url' => $this->url()->fromRoute('post/comments', ['id' => $post->uuid]),
|
| 171 |
'comments_add_url' => $this->url()->fromRoute('post/comments/add', ['id' => $post->uuid]),
|
228 |
'comments_add_url' => $this->url()->fromRoute('post/comments/add', ['id' => $post->uuid]),
|
| 172 |
'save_reaction_url' => $this->url()->fromRoute('post/save-reaction', ['id' => $post->uuid]),
|
229 |
'save_reaction_url' => $this->url()->fromRoute('post/save-reaction', ['id' => $post->uuid]),
|
| 173 |
'delete_reaction_url' => $this->url()->fromRoute('post/delete-reaction', ['id' => $post->uuid]),
|
230 |
'delete_reaction_url' => $this->url()->fromRoute('post/delete-reaction', ['id' => $post->uuid]),
|
| 174 |
'my_reaction' => $reaction ? $reaction->reaction : '',
|
231 |
'my_reaction' => $reaction ? $reaction->reaction : '',
|
| 175 |
'reactions' => $reactions,
|
232 |
'reactions' => $reactions,
|
| 176 |
//'is_liked' => $contentReaction ? 1 : 0,
|
233 |
//'is_liked' => $contentReaction ? 1 : 0,
|
| 177 |
//'like_url' => $this->url()->fromRoute('post/like', ['id' => $post->uuid]),
|
234 |
//'like_url' => $this->url()->fromRoute('post/like', ['id' => $post->uuid]),
|
| 178 |
//'unlike_url' => $this->url()->fromRoute('post/unlike', ['id' => $post->uuid]),
|
235 |
//'unlike_url' => $this->url()->fromRoute('post/unlike', ['id' => $post->uuid]),
|
| - |
|
236 |
|
| 179 |
|
237 |
]);
|
| 180 |
]);
|
238 |
return $viewModel;
|
| 181 |
return $viewModel;
|
239 |
}
|
| 182 |
} else {
|
240 |
} else {
|
| 183 |
$response = [
|
241 |
$response = [
|