-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathModSourcesController.php
More file actions
190 lines (156 loc) · 8 KB
/
ModSourcesController.php
File metadata and controls
190 lines (156 loc) · 8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
<?php
use Core2\Mod\Sources;
require_once DOC_ROOT . "core2/inc/classes/Common.php";
require_once DOC_ROOT . "core2/inc/classes/Alert.php";
require_once DOC_ROOT . "core2/inc/classes/Panel.php";
require_once 'classes/autoload.php';
/**
* @property \SourcesSites $dataSourcesSites
* @property \SourcesSitesContentsRaw $dataSourcesSitesContentsRaw
* @property \SourcesSitesPages $dataSourcesSitesPages
* @property \SourcesSitesPagesContents $dataSourcesSitesPagesContents
* @property \SourcesSitesPagesMedia $dataSourcesSitesPagesMedia
* @property \SourcesSitesPagesReferences $dataSourcesSitesPagesReferences
* @property \SourcesSitesPagesTags $dataSourcesSitesPagesTags
* @property \SourcesSitesTags $dataSourcesSitesTags
*
* @property \SourcesChats $dataSourcesChats
* @property \SourcesChatsAccounts $dataSourcesChatsAccounts
* @property \SourcesChatsAccountsSubscribes $dataSourcesChatsAccountsSubscribes
* @property \SourcesChatsCategories $dataSourcesChatsCategories
* @property \SourcesChatsCategoriesLink $dataSourcesChatsCategoriesLink
* @property \SourcesChatsContent $dataSourcesChatsContent
* @property \SourcesChatsUsers $dataSourcesChatsUsers
* @property \SourcesChatsUsersLinks $dataSourcesChatsUsersLinks
* @property \SourcesChatsReactions $dataSourcesChatsReactions
* @property \SourcesChatsLinks $dataSourcesChatsLinks
* @property \SourcesChatsHashtags $dataSourcesChatsHashtags
* @property \SourcesChatsFiles $dataSourcesChatsFiles
* @property \SourcesChatsSubscribers $dataSourcesChatsSubscribers
* @property \SourcesChatsMessages $dataSourcesChatsMessages
* @property \SourcesChatsMessagesReactions $dataSourcesChatsMessagesReactions
* @property \SourcesChatsMessagesFiles $dataSourcesChatsMessagesFiles
* @property \SourcesChatsMessagesLinks $dataSourcesChatsMessagesLinks
* @property \SourcesChatsMessagesReplies $dataSourcesChatsMessagesReplies
* @property \SourcesChatsMessagesHashtag $dataSourcesChatsMessagesHashtag
*
* @property \SourcesVideos $dataSourcesVideos
* @property \SourcesVideosAccounts $dataSourcesVideosAccounts
* @property \SourcesVideosChannelsHashtags $dataSourcesVideosChannelsHashtags
* @property \SourcesVideosChannelsLinks $dataSourcesVideosChannelsLinks
* @property \SourcesVideosClips $dataSourcesVideosClips
* @property \SourcesVideosClipsComments $dataSourcesVideosClipsComments
* @property \SourcesVideosClipsFiles $dataSourcesVideosClipsFiles
* @property \SourcesVideosClipsHashtags $dataSourcesVideosClipsHashtags
* @property \SourcesVideosClipsLinks $dataSourcesVideosClipsLinks
* @property \SourcesVideosClipsSubtitles $dataSourcesVideosClipsSubtitles
* @property \SourcesVideosClipsTags $dataSourcesVideosClipsTags
* @property \SourcesVideosHashtags $dataSourcesVideosHashtags
* @property \SourcesVideosLinks $dataSourcesVideosLinks
* @property \SourcesVideosStats $dataSourcesVideosStats
* @property \SourcesVideosRaw $dataSourcesVideosRaw
* @property \SourcesVideosUsers $dataSourcesVideosUsers
*/
class ModSourcesController extends Common {
/**
* @return string
* @throws Exception
*/
public function action_sites(): string {
$base_url = 'index.php?module=sources&action=sites';
$view = new Sources\Sites\View();
$panel = new Panel('tab');
$content = [];
try {
if ( ! empty($_GET['edit'])) {
$page = $this->dataSourcesSitesPages->find($_GET['edit'])->current();
if (empty($page)) {
throw new Exception('Указанная страница не найдена');
}
$source = $this->dataSourcesSites->find($page->source_id)->current();
$date_publish = $page->date_publish
? (new \DateTime($page->date_publish))->format('d.m.Y H:i:s')
: 'не указано';
$description = "{$source->title} / {$date_publish}";
$panel->setTitle($page->title, $description, $base_url);
$edit = $view->getEdit($page);
$base_url .= "&edit={$page->id}";
if (empty($_GET['edited'])) {
$edit->readOnly = true;
$edit->addButtonCustom("<input type=\"button\" class=\"button btn btn-info\"
value=\"Редактировать\" onclick=\"load('{$base_url}&edited=1')\">");
} else {
$edit->addButton($this->translate->tr("Отменить"), "load('{$base_url}')");
}
$content[] = $edit->render();
} else {
$panel->addTab('Публикации', 'publications', $base_url);
$panel->addTab('Источники', 'sources', $base_url);
switch ($panel->getActiveTab()) {
case 'publications': $content[] = $view->getTable($base_url)->render(); break;
case 'sources': $content[] = $view->getTableSources($base_url)->render();break;
}
}
} catch (\Exception $e) {
$content[] = Alert::danger($e->getMessage(), 'Ошибка');
}
$panel->setContent(implode('', $content));
return $panel->render();
}
/**
* @return string
* @throws Exception
*/
public function action_test(): string {
if ( ! empty($_GET['data'])) {
try {
switch ($_GET['data']) {
case 'test_site':
if (empty($_POST['rules'])) {
throw new Exception($this->_('Не переданы правила для запуска'));
}
$model = new Sources\Test\Model();
ob_start();
$time_start = microtime(true);
$body = $model->testSite($_POST['rules'], $_POST['options'] ?? []);
$time_end = microtime(true);
$body .= ob_get_clean();
return json_encode([
'status' => 'success',
'time' => round($time_end - $time_start, 3),
'mem' => round(memory_get_peak_usage(true) / 1024 / 1024, 2),
'body' => $body,
]);
break;
}
} catch (Exception $e) {
return json_encode([
'status' => 'error',
'error_message' => $e->getMessage()
]);
}
}
$base_url = 'index.php?module=sources&action=test';
$view = new Sources\Test\View();
$panel = new Panel('tab');
$content = [];
try {
$panel->addTab('Сайты', 'sites', $base_url);
$panel->addTab('Telegram', 'telegram', $base_url);
$panel->addTab('Youtube', 'youtube', $base_url);
ob_start();
$this->printJsModule('sources', '/assets/test/js/source.test.js');
$this->printCssModule('sources', '/assets/test/css/source.test.css');
$content[] = ob_get_clean();
switch ($panel->getActiveTab()) {
case 'sites': $content[] = $view->getSiteContainer(); break;
case 'telegram': break;
case 'youtube': break;
}
} catch (\Exception $e) {
$content[] = Alert::danger($e->getMessage(), 'Ошибка');
}
$panel->setContent(implode('', $content));
return $panel->render();
}
}