This repository has been archived by the owner on Jan 15, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmt-wp-plugin.pages.php
271 lines (255 loc) · 8.12 KB
/
mt-wp-plugin.pages.php
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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
<?php
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.FunctionNoCapital, PEAR.NamingConventions.ValidFunctionName.FunctionNameInvalid
use MT\WP\Plugin\Api\MT_Category;
use MT\WP\Plugin\Api\MT_Gallery;
use MT\WP\Plugin\Api\MT_News;
use MT\WP\Plugin\Api\MT_Photo;
use MT\WP\Plugin\Api\MT_Photographer;
use MT\WP\Plugin\Api\MT_Subcategory;
use MT\WP\Plugin\Backend\Model\Form\MT_Admin_Field;
use MT\WP\Plugin\Backend\Model\MT_Admin_Model_PhotoSearch;
use MT\WP\Plugin\Backend\Model\MT_Admin_NewsGeneration;
use MT\WP\Plugin\Backend\View\Crud\MT_Admin_View_PhotoEdit;
use MT\WP\Plugin\Backend\View\Crud\MT_View_Edit;
use MT\WP\Plugin\Backend\View\Crud\MT_View_List;
use MT\WP\Plugin\Common\Util\MT_Util_Html;
/**
* Type edit
*/
const TYPE_EDIT = 'edit';
/**
* Admin menu hook: Add pages to menu.
*/
add_action('admin_menu', function () {
// Add top-level and submenu menu item
add_menu_page('MT Bilder', 'MT Bilder', 'edit_others_pages', 'mt-photo', null, 'dashicons-palmtree', 3);
add_submenu_page('mt-photo', 'Fotos verwalten', 'Fotos verwalten', 'edit_others_pages', 'mt-photo', 'mt_page_photos');
add_submenu_page('mt-photo', 'Fotos hinzufügen', 'Fotos hinzufügen', 'edit_others_pages', 'mt-photo-add', 'mt_page_photos_add');
add_submenu_page('mt-photo', 'News generieren', 'News generieren', 'edit_others_pages', 'mt-news-generate', 'mt_page_news_generate');
add_menu_page('MT Verwaltung', 'MT Verwaltung', 'edit_others_pages', 'mt-news', null, 'dashicons-hammer', 4);
add_submenu_page('mt-news', 'News', 'News', 'edit_others_pages', 'mt-news', 'mt_page_news');
add_submenu_page('mt-news', 'Kategorien', 'Kategorien', 'edit_others_pages', 'mt-category', 'mt_page_categories');
add_submenu_page('mt-news', 'Unterkategorien', 'Unterkategorien', 'edit_others_pages', 'mt-subcategory', 'mt_page_subcategories');
add_submenu_page('mt-news', 'Galerien', 'Galerien', 'edit_others_pages', 'mt-gallery', 'mt_page_galleries');
add_submenu_page('mt-news', 'Fotografen', 'Fotografen', 'edit_others_pages', 'mt-photographer', 'mt_page_photographers');
});
/**
* Page edit photos
*
* @return void
*/
function mt_page_photos()
{
$tmp = new MT_Admin_Field(null, null);
$id = $_GET['mtId'];
$page = (!empty($_GET['mtpage']) ? $_GET['mtpage'] : 1);
?>
<select name="selectGalerie" onchange="location = '?page=mt-photo&mtId=' + this.options[this.selectedIndex].value;">
<option value=""><?php _e('Galerie wählen', MT_NAME); ?> ...</option>
<?php echo $tmp->outputAllGalleries($id); ?>
</select>
<?php
if (!empty($id)) {
$photoEditView = new MT_Admin_View_PhotoEdit($id, $page);
$photoEditView->outputContent();
}
}
/**
* Page add new photos
*
* @return void
*/
function mt_page_photos_add()
{
$paQueueClient = null;
// True, if the MT PA plugin exists
if (defined('MT_PA_NAME') && defined('MT_PA_OPTION_QUEUE_TOPIC')) {
include_once plugin_dir_path(__FILE__).'../'.MT_PA_NAME.'/src/php/QueueClient.php';
$paQueueClient = new MT\PhotoAnalysis\QueueClient(get_option(MT_PA_OPTION_QUEUE_TOPIC));
}
// Nach neuen Bildern suchen, wenn weniger als 8 neue Bilder in der Datenbank gespeichert sind
if (MT_Photo::getCountNewPhotos() < 10 or $_GET['action'] === 'search') {
(new MT_Admin_Model_PhotoSearch($paQueueClient))->search();
// Datum der letzten Suche speichern
update_option('datum_letzte_suche', time());
}
$photoEditView = new MT_Admin_View_PhotoEdit();
$photoEditView->outputContent();
}
/**
* Page generate news
*
* @return void
*/
function mt_page_news_generate()
{
$newsGeneration = new MT_Admin_NewsGeneration();
$newsData = $newsGeneration->getGeneratedNews();
if (!$newsGeneration->checkGenerateNews()) {
?>
<div class="wrap">
<h2>News <?php echo MT_Util_Html::addButton('?page=mt-'.MT_News::name().'&type=edit'); ?></h2>
<p>Es gibt keine neuen Bilder, sodass keine News generiert werden können!</p>
</div>
<?php
} else {
$editView = new MT_View_Edit(new MT_News());
$editView->setFields(array(
(new MT_Admin_Field('title', 'Title'))
->setRequired()
->setMaxLength(100),
(new MT_Admin_Field('text', 'Text', 'text'))->setRequired(),
(new MT_Admin_Field('gallery', 'Galerie'))
->setReference('gallery')
->setRequired()
));
$editView->setData($newsData);
$editView->outputContent();
}
}
/**
* Page list/edit news
*
* @return void
*/
function mt_page_news()
{
if ($_GET['type'] === TYPE_EDIT) {
$editView = new MT_View_Edit(new MT_News($_GET['id']));
$editView->setFields(array(
(new MT_Admin_Field('title', 'Title'))->setRequired(),
(new MT_Admin_Field('text', 'Text'))->setRequired(),
(new MT_Admin_Field('date', 'Datum', 'date'))->setDisabled(),
(new MT_Admin_Field('gallery', 'Galerie'))->setReference('gallery')
));
$editView->outputContent();
} else {
$listView = new MT_View_List(new MT_News());
$listView->setFields(array(
(new MT_Admin_Field('title', 'Titel')),
(new MT_Admin_Field('date', 'Datum', 'date'))
));
$listView->setOrder('date DESC');
$listView->setPerPage(20);
$listView->outputContent();
}
}
/**
* Page list/edit categories
*
* @return void
*/
function mt_page_categories()
{
if ($_GET['type'] === TYPE_EDIT) {
$editView = new MT_View_Edit(new MT_Category($_GET['id']));
$editView->setFields(array(
(new MT_Admin_Field('name', 'Name'))->setRequired(),
(new MT_Admin_Field('description', 'Beschreibung')),
(new MT_Admin_Field('path', 'Pfad'))->setDisabled()
));
$editView->outputContent();
} else {
$listView = new MT_View_List(new MT_Category());
$listView->setFields(array(
(new MT_Admin_Field('name', 'Name')),
(new MT_Admin_Field('path', 'Pfad'))
));
$listView->outputContent();
}
}
/**
* Page list/edit subcategories
*
* @return void
*/
function mt_page_subcategories()
{
if ($_GET['type'] === TYPE_EDIT) {
$fieldCategory = (new MT_Admin_Field('category', 'Kategorie'))
->setReference('category')
->setRequired();
$id = $_GET['id'];
if (!empty($id)) {
$fieldCategory->setDisabled();
}
$editView = new MT_View_Edit(new MT_Subcategory($id));
$editView->setFields(array(
(new MT_Admin_Field('name', 'Name'))->setRequired(),
(new MT_Admin_Field('path', 'Pfad'))->setDisabled(),
$fieldCategory
));
$editView->outputContent();
} else {
$listView = new MT_View_List(new MT_Subcategory());
$listView->setFields(array(
(new MT_Admin_Field('name', 'Name')),
(new MT_Admin_Field('category', 'Kategorie'))
->setReference('category', 'name')
));
$listView->outputContent();
}
}
/**
* Page list/edit galleries
*
* @return void
*/
function mt_page_galleries()
{
if ($_GET['type'] === TYPE_EDIT) {
$id = $_GET['id'];
$fieldCategory = (new MT_Admin_Field('category', 'Kategorie'))
->setReference('category', 'name')
->setRequired();
$fieldSubcategory = (new MT_Admin_Field('subcategory', 'Unterkategorie'))
->setReference('subcategory', 'name');
if (!empty($id)) {
$fieldCategory->setDisabled();
$fieldSubcategory->setDisabled();
}
$editView = new MT_View_Edit(new MT_Gallery($id));
$editView->setFields(array(
(new MT_Admin_Field('name', 'Name'))
->setRequired(),
(new MT_Admin_Field('description', 'Beschreibung', 'text')),
(new MT_Admin_Field('keywords', 'Keywords', 'text')),
(new MT_Admin_Field('path', 'Pfad'))
->setDisabled(),
$fieldCategory,
$fieldSubcategory
));
$editView->outputContent();
} else {
$listView = new MT_View_List(new MT_Gallery());
$listView->setFields(array(
(new MT_Admin_Field('name', 'Name')),
(new MT_Admin_Field('fullPath', 'Vollständiger Pfad'))
));
$listView->setOrder('fullPath');
$listView->outputContent();
}
}
/**
* Page list/edit photographers
*
* @return void
*/
function mt_page_photographers()
{
if ($_GET['type'] === TYPE_EDIT) {
$editView = new MT_View_Edit(new MT_Photographer($_GET['id']));
$editView->setFields(array(
(new MT_Admin_Field('name', 'Name'))->setRequired(),
(new MT_Admin_Field('date', 'Datum', 'date'))->setDisabled()
));
$editView->outputContent();
} else {
$listView = new MT_View_List(new MT_Photographer());
$listView->setFields(array(
(new MT_Admin_Field('name', 'Name'))
));
$listView->setOrder('name');
$listView->outputContent();
}
}