-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
boot.php
131 lines (112 loc) · 5.39 KB
/
boot.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
<?php
use TobiasKrais\D2UCourses\FrontendHelper;
if (\rex::isBackend() && is_object(\rex::getUser())) {
rex_perm::register('d2u_courses[]', rex_i18n::msg('d2u_courses_rights_all'));
rex_perm::register('d2u_courses[courses_all]', rex_i18n::msg('d2u_courses_rights_courses_all'), rex_perm::OPTIONS);
rex_perm::register('d2u_courses[categories]', rex_i18n::msg('d2u_courses_rights_categories'), rex_perm::OPTIONS);
rex_perm::register('d2u_courses[settings]', rex_i18n::msg('d2u_courses_rights_settings'), rex_perm::OPTIONS);
}
if (\rex::isBackend()) {
rex_extension::register('ART_PRE_DELETED', rex_d2u_courses_article_is_in_use(...));
rex_extension::register('MEDIA_IS_IN_USE', rex_d2u_courses_media_is_in_use(...));
}
else {
rex_extension::register('D2U_HELPER_BREADCRUMBS', rex_d2u_courses_breadcrumbs(...));
}
/**
* Checks if article is used by this addon.
* @param rex_extension_point<string> $ep Redaxo extension point
* @throws rex_api_exception If article is used
* @return string Warning message
*/
function rex_d2u_courses_article_is_in_use(rex_extension_point $ep)
{
$warning = [];
$params = $ep->getParams();
$article_id = $params['id'];
// Courses
$sql_courses = \rex_sql::factory();
$sql_courses->setQuery('SELECT course_id, name FROM `' . \rex::getTablePrefix() . 'd2u_courses_courses` '
.'WHERE redaxo_article = "'. $article_id .'"');
// Prepare warnings
// Courses
for ($i = 0; $i < $sql_courses->getRows(); ++$i) {
$message = '<a href="javascript:openPage(\'index.php?page=d2u_courses/courses&func=edit&entry_id='.
$sql_courses->getValue('course_id') .'\')">'. rex_i18n::msg('d2u_courses_rights_all') .' - '. rex_i18n::msg('d2u_courses_courses') .': '. $sql_courses->getValue('name') .'</a>';
if (!in_array($message, $warning, true)) {
$warning[] = $message;
}
$sql_courses->next();
}
// Settings
$addon = rex_addon::get('d2u_courses');
if (($addon->hasConfig('article_id_courses') && (int) $addon->getConfig('article_id_courses') === $article_id) ||
($addon->hasConfig('article_id_shopping_cart') && (int) $addon->getConfig('article_id_shopping_cart') === $article_id) ||
($addon->hasConfig('article_id_conditions') && (int) $addon->getConfig('article_id_conditions') === $article_id) ||
($addon->hasConfig('article_id_terms_of_participation') && (int) $addon->getConfig('article_id_terms_of_participation') === $article_id)) {
$message = '<a href="index.php?page=d2u_courses/settings">'.
rex_i18n::msg('d2u_courses_rights_all') .' - '. rex_i18n::msg('d2u_helper_settings') . '</a>';
if (!in_array($message, $warning, true)) {
$warning[] = $message;
}
}
if (count($warning) > 0) {
throw new rex_api_exception(rex_i18n::msg('d2u_helper_rex_article_cannot_delete').'<ul><li>'. implode('</li><li>', $warning) .'</li></ul>');
}
return '';
}
/**
* Get breadcrumb part for courses.
* @param rex_extension_point<array<string>> $ep Redaxo extension point
* @return array<int,string> HTML formatted breadcrumb elements
*/
function rex_d2u_courses_breadcrumbs(rex_extension_point $ep)
{
$params = $ep->getParams();
$url_namespace = (string) $params['url_namespace'];
$url_id = (int) $params['url_id'];
$breadcrumbs = FrontendHelper::getBreadcrumbs($url_namespace, $url_id);
if (count($breadcrumbs) === 0) {
$breadcrumbs = $ep->getSubject();
}
return $breadcrumbs;
}
/**
* Checks if media is used by this addon.
* @param rex_extension_point<array<string>> $ep Redaxo extension point
* @return array<string> Warning message as array
*/
function rex_d2u_courses_media_is_in_use(rex_extension_point $ep)
{
$warning = $ep->getSubject();
$params = $ep->getParams();
$filename = addslashes($params['filename']);
// Courses
$sql_courses = \rex_sql::factory();
$sql_courses->setQuery('SELECT course_id, `name` FROM `' . \rex::getTablePrefix() . 'd2u_courses_courses` '
.'WHERE FIND_IN_SET("'. $filename .'", downloads) OR picture = "'. $filename .'" OR description LIKE "%'. $filename .'%"');
// Categories
$sql_categories = \rex_sql::factory();
$sql_categories->setQuery('SELECT category_id, name FROM `' . \rex::getTablePrefix() . 'd2u_courses_categories` '
.'WHERE picture = "'. $filename .'"');
// Prepare warnings
// Courses
for ($i = 0; $i < $sql_courses->getRows(); ++$i) {
$message = rex_i18n::msg('d2u_courses_rights_all') .' - '. rex_i18n::msg('d2u_courses_courses') .': <a href="javascript:openPage(\'index.php?page=d2u_courses/course&func=edit&entry_id='.
$sql_courses->getValue('course_id') .'\')">'. $sql_courses->getValue('name') .'</a>';
if (!in_array($message, $warning, true)) {
$warning[] = $message;
}
$sql_courses->next();
}
// Categories
for ($i = 0; $i < $sql_categories->getRows(); ++$i) {
$message = rex_i18n::msg('d2u_courses_rights_all') .' - '. rex_i18n::msg('d2u_helper_categories') .': <a href="javascript:openPage(\'index.php?page=d2u_courses/category&func=edit&entry_id='. $sql_categories->getValue('category_id') .'\')">'.
$sql_categories->getValue('name') . '</a>';
if (!in_array($message, $warning, true)) {
$warning[] = $message;
}
$sql_categories->next();
}
return $warning;
}