-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathboot.php
144 lines (125 loc) · 6.07 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
132
133
134
135
136
137
138
139
140
141
142
143
144
<?php
if (\rex::isBackend() && is_object(\rex::getUser())) {
rex_perm::register('d2u_immo[]', rex_i18n::msg('d2u_immo_rights_all'));
rex_perm::register('d2u_immo[edit_lang]', rex_i18n::msg('d2u_immo_rights_edit_lang'), rex_perm::OPTIONS);
rex_perm::register('d2u_immo[edit_data]', rex_i18n::msg('d2u_immo_rights_edit_data'), rex_perm::OPTIONS);
rex_perm::register('d2u_immo[settings]', rex_i18n::msg('d2u_immo_rights_settings'), rex_perm::OPTIONS);
}
if (\rex::isBackend()) {
rex_extension::register('CLANG_DELETED', rex_d2u_immo_clang_deleted(...));
rex_extension::register('MEDIA_IS_IN_USE', rex_d2u_immo_media_is_in_use(...));
rex_extension::register('ART_PRE_DELETED', rex_d2u_immo_article_is_in_use(...));
}
/**
* 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 array<string> Warning message as array
*/
function rex_d2u_immo_article_is_in_use(rex_extension_point $ep)
{
$warning = [];
$params = $ep->getParams();
$article_id = $params['id'];
// Prepare warnings
// Settings
$addon = rex_addon::get('d2u_immo');
if ($addon->hasConfig('article_id') && (int) $addon->getConfig('article_id') === $article_id) {
$message = '<a href="index.php?page=d2u_immo/settings">'.
rex_i18n::msg('d2u_immo_rights_all') .' - '. rex_i18n::msg('d2u_immo_meta_settings') . '</a>';
$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 [];
}
/**
* Deletes language specific configurations and objects.
* @param rex_extension_point<array<string>> $ep Redaxo extension point
* @return array<string> Warning message as array
*/
function rex_d2u_immo_clang_deleted(rex_extension_point $ep)
{
$warning = $ep->getSubject();
$params = $ep->getParams();
$clang_id = $params['id'];
// Delete
$categories = D2U_Immo\Category::getAll($clang_id);
foreach ($categories as $category) {
$category->delete(false);
}
$properties = D2U_Immo\Property::getAll($clang_id, '', false);
foreach ($properties as $property) {
$property->delete(false);
}
// Delete language settings
if (rex_config::has('d2u_immo', 'lang_replacement_'. $clang_id)) {
rex_config::remove('d2u_immo', 'lang_replacement_'. $clang_id);
}
// Delete language replacements
d2u_immo_lang_helper::factory()->uninstall($clang_id);
return $warning;
}
/**
* 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_immo_media_is_in_use(rex_extension_point $ep)
{
$warning = $ep->getSubject();
$params = $ep->getParams();
$filename = addslashes($params['filename']);
// Contacts
$sql_contacts = rex_sql::factory();
$sql_contacts->setQuery('SELECT contact_id, firstname, lastname FROM `' . \rex::getTablePrefix() . 'd2u_immo_contacts` '
.'WHERE picture = "'. $filename .'" ');
// Categories
$sql_categories = rex_sql::factory();
$sql_categories->setQuery('SELECT lang.category_id, name FROM `' . \rex::getTablePrefix() . 'd2u_immo_categories_lang` AS lang '
.'LEFT JOIN `' . \rex::getTablePrefix() . 'd2u_immo_categories` AS categories ON lang.category_id = categories.category_id '
.'WHERE picture = "'. $filename .'" ');
// Properties
$sql_properties = rex_sql::factory();
$sql_properties->setQuery('SELECT lang.property_id, name FROM `' . \rex::getTablePrefix() . 'd2u_immo_properties_lang` AS lang '
.'LEFT JOIN `' . \rex::getTablePrefix() . 'd2u_immo_properties` AS properties ON lang.property_id = properties.property_id '
.'WHERE FIND_IN_SET("'. $filename .'", pictures) OR FIND_IN_SET("'. $filename .'", ground_plans) OR FIND_IN_SET("'. $filename .'", location_plans) OR FIND_IN_SET("'. $filename .'", documents)');
// Prepare warnings
// Categories
for ($i = 0; $i < $sql_categories->getRows(); ++$i) {
$message = '<a href="javascript:openPage(\'index.php?page=d2u_immo/category&func=edit&entry_id='. $sql_categories->getValue('category_id') .'\')">'.
rex_i18n::msg('d2u_immo_rights_all') .' - '. rex_i18n::msg('d2u_helper_categories') .': '. $sql_categories->getValue('name') . '</a>';
if (!in_array($message, $warning, true)) {
$warning[] = $message;
}
$sql_categories->next();
}
// Contacts
for ($i = 0; $i < $sql_contacts->getRows(); ++$i) {
$message = '<a href="javascript:openPage(\'index.php?page=d2u_immo/contact&func=edit&entry_id='.
$sql_contacts->getValue('contact_id') .'\')">'. rex_i18n::msg('d2u_immo_rights_all') .' - '. rex_i18n::msg('d2u_immo_contacts') .': '. $sql_contacts->getValue('firstname') .' '. $sql_contacts->getValue('lastname') .'</a>';
if (!in_array($message, $warning, true)) {
$warning[] = $message;
}
$sql_contacts->next();
}
// Properties
for ($i = 0; $i < $sql_properties->getRows(); ++$i) {
$message = '<a href="javascript:openPage(\'index.php?page=d2u_immo/property&func=edit&entry_id='.
$sql_properties->getValue('property_id') .'\')">'. rex_i18n::msg('d2u_immo_rights_all') .' - '. rex_i18n::msg('d2u_immo_properties') .': '. $sql_properties->getValue('name') .'</a>';
if (!in_array($message, $warning, true)) {
$warning[] = $message;
}
$sql_properties->next();
}
$addon = rex_addon::get('d2u_immo');
if ($addon->hasConfig('even_informative_pdf') && (string) $addon->getConfig('even_informative_pdf') === $filename) {
$message = '<a href="javascript:openPage(\'index.php?page=d2u_immo/settings\')">'.
rex_i18n::msg('d2u_immo') .' - '. rex_i18n::msg('d2u_helper_settings') . '</a>';
if (!in_array($message, $warning, true)) {
$warning[] = $message;
}
}
return $warning;
}