1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Apps\Controller\Api; |
4
|
|
|
|
5
|
|
|
|
6
|
|
|
use Extend\Core\Arch\ApiController; |
7
|
|
|
use Apps\ActiveRecord\Content as ContentRecord; |
8
|
|
|
use Ffcms\Core\App; |
9
|
|
|
use Ffcms\Core\Helper\Date; |
10
|
|
|
use Ffcms\Core\Helper\Text; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* Class Api. Ffcms official website public API |
14
|
|
|
* @package Apps\Controller\Api |
15
|
|
|
*/ |
16
|
|
|
class Api extends ApiController |
17
|
|
|
{ |
18
|
|
|
private $newsCategories = [2, 4]; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* Show ffcms latest 10 news from special category as json data |
22
|
|
|
* @return string |
23
|
|
|
*/ |
24
|
|
|
public function actionNews() |
25
|
|
|
{ |
26
|
|
|
$this->setJsonHeader(); |
27
|
|
|
$data = []; |
28
|
|
|
if (App::$Cache->get('api.news.list.'.$this->lang) !== null) { |
29
|
|
|
$data = App::$Cache->get('api.news.list.'.$this->lang); |
30
|
|
|
} else { |
31
|
|
|
$records = ContentRecord::select(['contents.*', 'content_categories.path as cpath', 'content_categories.title as ctitle']) |
|
|
|
|
32
|
|
|
->whereIn('contents.category_id', $this->newsCategories) |
33
|
|
|
->join('content_categories', 'content_categories.id', '=', 'contents.category_id', 'left outer') |
34
|
|
|
->orderBy('contents.created_at', 'DESC') |
35
|
|
|
->take(10)->get()->toArray(); |
36
|
|
|
|
37
|
|
|
foreach ($records as $item) { |
38
|
|
|
$data[] = [ |
39
|
|
|
'title' => App::$Translate->getLocaleText($item['title']), |
40
|
|
|
'date' => Date::humanize($item['created_at']), |
41
|
|
|
'url' => 'https://ffcms.org/' . $this->request->getLanguage() . '/content/read/' . $item['cpath'] . '/' . $item['path'], |
42
|
|
|
'snippet' => Text::snippet(App::$Translate->getLocaleText($item['text'], $this->request->getLanguage())) |
43
|
|
|
]; |
44
|
|
|
} |
45
|
|
|
App::$Cache->set('api.news.list.'.$this->lang, $data, 3600); |
|
|
|
|
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
return json_encode([ |
49
|
|
|
'status' => 1, |
50
|
|
|
'data' => $data |
51
|
|
|
]); |
52
|
|
|
} |
53
|
|
|
} |
This check marks calls to methods that do not seem to exist on an object.
This is most likely the result of a method being renamed without all references to it being renamed likewise.