Move mod/viewsrc to src/Module/ItemBody
[friendica.git/.git] / src / Module / ItemBody.php
1 <?php
2
3 namespace Friendica\Module;
4
5 use Friendica\BaseModule;
6 use Friendica\Core\L10n;
7 use Friendica\Model\Item;
8 use Friendica\Network\HTTPException;
9
10 /**
11  * Print the body of an Item
12  */
13 class ItemBody extends BaseModule
14 {
15         public static function content()
16         {
17                 if (!local_user()) {
18                         throw new HTTPException\UnauthorizedException(L10n::t('Access denied.'));
19                 }
20
21                 $app = self::getApp();
22
23                 // @TODO: Replace with parameter from router
24                 $itemId = (($app->argc > 1) ? intval($app->argv[1]) : 0);
25
26                 if (!$itemId) {
27                         throw new HTTPException\NotFoundException(L10n::t('Item not found.'));
28                 }
29
30                 $item = Item::selectFirst(['body'], ['uid' => local_user(), 'id' => $itemId]);
31
32                 if (!empty($item)) {
33                         if ($app->isAjax()) {
34                                 echo str_replace("\n", '<br />', $item['body']);
35                                 exit();
36                         } else {
37                                 return str_replace("\n", '<br />', $item['body']);
38                         }
39                 } else {
40                         throw new HTTPException\NotFoundException(L10n::t('Item not found.'));
41                 }
42         }
43 }