-
Notifications
You must be signed in to change notification settings - Fork 0
/
helper.php
211 lines (186 loc) · 5.84 KB
/
helper.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
<?php
/**
* @package HerrnhuterLosungen
* @author Thomas Hunziker <admin@sermonspeaker.net>
* @copyright (C) 2022 - Thomas Hunziker
* @license http://www.gnu.org/licenses/gpl.html
**/
defined('_JEXEC') or die();
use Joomla\CMS\Factory;
use Joomla\CMS\Helper\ModuleHelper;
use Joomla\CMS\HTML\HTMLHelper;
use Joomla\CMS\Language\Text;
use Joomla\Registry\Registry;
/**
* Helper class for Herrnhuter Losungen module
*
* @since 1.0
*/
abstract class ModHerrnhuterlosungenHelper
{
/**
* Get Losung from XML
*
* @param Registry $params module parameters
*
* @return array|false
*
* @since 1.0
*/
public static function getLosungAjax()
{
$input = Factory::getApplication()->input;
if ($input->get('nav') == 'prev')
{
$date = strtotime($input->get('date') . ' - 1 day');
}
else
{
$date = strtotime($input->get('date') . ' + 1 day');
}
$module = ModuleHelper::getModule('mod_herrnhuter_losungen');
$params = new Registry($module->params);
$files = array();
$files[] = JPATH_ROOT . '/' . trim($params->get('path'), '/') . '/Losungen ' . date('Y', $date). '.xml';
$files[] = JPATH_ROOT . '/' . trim($params->get('path'), '/') . '/Losungen Free ' . date('Y', $date) . '.xml';
foreach ($files as $file)
{
if (file_exists($file))
{
if ($xml = simplexml_load_file($file))
{
$index = date('z', $date);
$losung = (array) $xml->Losungen[(int) $index];
$losung['Sonntag'] = (string) $xml->Losungen[(int) $index]->Sonntag;
$losung['LosungstextFormatiert'] = self::formatText($losung['Losungstext']);
$losung['Losungsverslink'] = self::linkScripture($losung['Losungsvers'], $params);
$losung['LehrtextFormatiert'] = self::formatText($losung['Lehrtext']);
$losung['Lehrtextverslink'] = self::linkScripture($losung['Lehrtextvers'], $params);
$losung['DatumUS'] = HTMLHelper::_('date', $losung['Datum'], 'Y-m-d');
$losung['DatumFormatiert'] = HTMLHelper::_('date', $losung['Datum'], Text::_($params->get('date_format', 'DATE_FORMAT_LC4')));
return $losung;
}
}
}
return false;
}
/**
* Get Losung from XML
*
* @param Registry $params module parameters
*
* @return array|false
*
* @since 1.0
*/
public static function getLosung($params)
{
$date = Factory::getDate();
$files = array();
$path = trim($params->get('path', ''), '/');
$files[] = JPATH_ROOT . '/' . $path . '/Losungen ' . $date->year . '.xml';
$files[] = JPATH_ROOT . '/' . $path . '/Losungen Free ' . $date->year . '.xml';
$files[] = JPATH_ROOT . '/' . $path . '/Losungen_Free_' . $date->year . '.xml';
foreach ($files as $file)
{
if (file_exists($file))
{
if ($xml = simplexml_load_file($file))
{
$index = $date->dayofyear;
$losung = (array) $xml->Losungen[(int) $index];
$losung['Sonntag'] = (string) $xml->Losungen[(int) $index]->Sonntag;
return $losung;
}
}
}
return false;
}
/**
* @param string $text Bibleverse
*
* @return string
*
* @since 1.0
*/
public static function formatText(string $text): string
{
// In XML intro passages which state who is the speaker are formatted as such: /Jesus spricht:/
if (strpos($text, '/') !== 0)
{
return $text;
}
$text = substr_replace($text, '<span class="sprecher">', 0, 1);
$text = str_replace('/', '</span>', $text);
return $text;
}
/**
* @param string $scripture Bibleverse
* @param Registry $params module parameters
*
* @return string
*
* @since 1.0
*/
public static function linkScripture(string $scripture, Registry $params)
{
$translation = $params->get('bible_version_custom', $params->get('bible_version', 'LUT'));
$url = 'http://www.bibleserver.com/' . $translation . '/' . $scripture;
switch ($params->get('link_scripture', 1))
{
case 0:
return $scripture;
case 1:
$title = Text::_('MOD_HERRNHUTER_LOSUNGEN_SCRIPTURELINK_NEW_WINDOW');
return '<a title="' . $title . '" href="' . $url . '" target="_blank" class="losungstext hasTooltip">'
. $scripture . '</a>';
case 2:
$title = Text::_('MOD_HERRNHUTER_LOSUNGEN_SCRIPTURELINK_POPUP');
$width = $params->get('popup_width', 900);
$height = $params->get('popup_height', 600);
$onclick = "Popup=window.open('" . $url . "','popup','toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=yes,"
. 'width=' . $width . ',height=' . $height . ",left='+(screen.availWidth/2-(" . $width . "/2))+',top='+(screen.availHeight/2-(" . $height . "/2)));return false;";
return '<a title="' . $title . '" href="#" onclick="' . $onclick . '" class="losungstext hasTooltip">'
. $scripture . '</a>';
}
}
/**
* @param integer $index Bibleverse
* @param \Joomla\Registry\Registry $params module parameters
* @param integer $moduleId module ID
*
* @return string
*
* @since 1.0
*/
public static function linkExtern(int $index, Registry $params, int $moduleId)
{
if ($index !== 1 && $index !== 2)
{
return '';
}
$url = $params->get('link' . $index . '_url');
$text = $params->get('link' . $index . '_title');
$html = '';
if ($params->get('link_icon_class'))
{
$html = '<span class="fa ' . $params->get('link_icon_class') . '"> </span> ';
}
if ($params->get('link_mode', 1) == 1)
{
$html .= '<a href="' . $url . '" target="_blank">' . $text . '</a>';
}
else
{
$id = 'losung_' . $moduleId . '_link_' . $index;
$params = array(
'title' => $text,
'url' => $url,
'height' => $params->get('modal_height', 600),
);
$html .= HtmlHelper::_('bootstrap.renderModal', $id, $params);
$html .= '<a href="#' . $id . '" data-bs-toggle="modal" >' . $text . '</a>';
}
return $html;
}
}