summaryrefslogtreecommitdiff
path: root/includes/helper
diff options
context:
space:
mode:
authormsquare <msquare@notrademark.de>2017-06-20 16:50:21 +0200
committermsquare <msquare@notrademark.de>2017-06-20 16:50:21 +0200
commit56814fa2fdf58b4013f4d57c5ea87619c7122957 (patch)
tree640945769b7e9626cdf43162c786147f5c962029 /includes/helper
parenta5fc5bd0979e8de1fce8a8addd351a6e7bd6aeb8 (diff)
parentcd30017b97afc3c7001fbb9eb14b54dbb980b7b6 (diff)
Merge branch 'pr/316' into feature-igel-rewrite
Diffstat (limited to 'includes/helper')
-rw-r--r--includes/helper/email_helper.php66
-rw-r--r--includes/helper/error_helper.php7
-rw-r--r--includes/helper/graph_helper.php56
-rw-r--r--includes/helper/internationalization_helper.php87
-rw-r--r--includes/helper/message_helper.php76
5 files changed, 173 insertions, 119 deletions
diff --git a/includes/helper/email_helper.php b/includes/helper/email_helper.php
index 462b5641..a2e25269 100644
--- a/includes/helper/email_helper.php
+++ b/includes/helper/email_helper.php
@@ -1,26 +1,50 @@
<?php
-function engelsystem_email_to_user($recipient_user, $title, $message, $not_if_its_me = false) {
- global $user;
-
- if ($not_if_its_me && $user['UID'] == $recipient_user['UID']) {
- return true;
- }
-
- gettext_locale($recipient_user['Sprache']);
-
- $message = sprintf(_("Hi %s,"), $recipient_user['Nick']) . "\n\n" . _("here is a message for you from the engelsystem:") . "\n\n" . $message . "\n\n" . _("This email is autogenerated and has not to be signed. You got this email because you are registered in the engelsystem.");
-
- gettext_locale();
- return engelsystem_email($recipient_user['email'], $title, $message);
-}
+/**
+ * @param array $recipient_user
+ * @param string $title
+ * @param string $message
+ * @param bool $not_if_its_me
+ * @return bool
+ */
+function engelsystem_email_to_user($recipient_user, $title, $message, $not_if_its_me = false)
+{
+ global $user;
+
+ if ($not_if_its_me && $user['UID'] == $recipient_user['UID']) {
+ return true;
+ }
+
+ gettext_locale($recipient_user['Sprache']);
+
+ $message = sprintf(_('Hi %s,'), $recipient_user['Nick']) . "\n\n"
+ . _('here is a message for you from the engelsystem:') . "\n\n"
+ . $message . "\n\n"
+ . _('This email is autogenerated and has not to be signed. You got this email because you are registered in the engelsystem.');
-function engelsystem_email($address, $title, $message) {
- global $no_reply_email;
- $result = mail($address, $title, $message, sprintf("Content-Type: text/plain; charset=UTF-8\r\nFrom: Engelsystem <%s>", $no_reply_email));
- if ($result === false) {
- engelsystem_error('Unable to send email.');
- }
+ gettext_locale();
+
+ return engelsystem_email($recipient_user['email'], $title, $message);
}
-?>
+/**
+ * @param string $address
+ * @param string $title
+ * @param string $message
+ * @return bool
+ */
+function engelsystem_email($address, $title, $message)
+{
+ $result = mail(
+ $address,
+ $title,
+ $message,
+ "Content-Type: text/plain; charset=UTF-8\r\nFrom: Engelsystem <noreply@engelsystem.de>"
+ );
+
+ if ($result === false) {
+ engelsystem_error('Unable to send email.');
+ }
+
+ return true;
+}
diff --git a/includes/helper/error_helper.php b/includes/helper/error_helper.php
index 58d0ac86..9314a57a 100644
--- a/includes/helper/error_helper.php
+++ b/includes/helper/error_helper.php
@@ -5,8 +5,7 @@
*
* @param string $message
*/
-function engelsystem_error($message) {
- raw_output($message);
+function engelsystem_error($message)
+{
+ raw_output($message);
}
-
-?> \ No newline at end of file
diff --git a/includes/helper/graph_helper.php b/includes/helper/graph_helper.php
index 42a6c07a..12c7df6c 100644
--- a/includes/helper/graph_helper.php
+++ b/includes/helper/graph_helper.php
@@ -2,40 +2,42 @@
/**
* Renders a bargraph
- * @param string $key keyname of the x-axis
- * @param array $row_names keynames for the data rows
- * @param unknown $colors colors for the data rows
- * @param unknown $data the data
+ *
+ * @param string $dom_id
+ * @param string $key key name of the x-axis
+ * @param array $row_names key names for the data rows
+ * @param array $colors colors for the data rows
+ * @param array $data the data
+ * @return string
*/
-function bargraph($dom_id, $key, $row_names, $colors, $data) {
- $labels = [];
- foreach ($data as $dataset) {
- $labels[] = $dataset[$key];
- }
-
- $datasets = [];
- foreach ($row_names as $row_key => $name) {
- $values = [];
+function bargraph($dom_id, $key, $row_names, $colors, $data)
+{
+ $labels = [];
foreach ($data as $dataset) {
- $values[] = $dataset[$row_key];
+ $labels[] = $dataset[$key];
}
- $datasets[] = [
- 'label' => $name,
- 'fillColor' => $colors[$row_key],
- 'data' => $values
- ];
- }
-
- return '<canvas id="' . $dom_id . '" style="width: 100%; height: 300px;"></canvas>
+
+ $datasets = [];
+ foreach ($row_names as $row_key => $name) {
+ $values = [];
+ foreach ($data as $dataset) {
+ $values[] = $dataset[$row_key];
+ }
+ $datasets[] = [
+ 'label' => $name,
+ 'fillColor' => $colors[$row_key],
+ 'data' => $values
+ ];
+ }
+
+ return '<canvas id="' . $dom_id . '" style="width: 100%; height: 300px;"></canvas>
<script type="text/javascript">
$(function(){
var ctx = $("#' . $dom_id . '").get(0).getContext("2d");
var chart = new Chart(ctx).Bar(' . json_encode([
- 'labels' => $labels,
- 'datasets' => $datasets
- ]) . ');
+ 'labels' => $labels,
+ 'datasets' => $datasets
+ ]) . ');
});
</script>';
}
-
-?> \ No newline at end of file
diff --git a/includes/helper/internationalization_helper.php b/includes/helper/internationalization_helper.php
index a537ef3d..ed16de15 100644
--- a/includes/helper/internationalization_helper.php
+++ b/includes/helper/internationalization_helper.php
@@ -1,71 +1,76 @@
<?php
-$locales = [
- 'de_DE.UTF-8' => "Deutsch",
- 'en_US.UTF-8' => "English"
-];
-
-$default_locale = 'en_US.UTF-8';
/**
* Return currently active locale
+ *
+ * @return string
*/
-function locale() {
- return $_SESSION['locale'];
+function locale()
+{
+ return $_SESSION['locale'];
}
/**
* Returns two letter language code from currently active locale
+ *
+ * @return string
*/
-function locale_short() {
- return substr(locale(), 0, 2);
+function locale_short()
+{
+ return substr(locale(), 0, 2);
}
/**
* Initializes gettext for internationalization and updates the sessions locale to use for translation.
*/
-function gettext_init() {
- global $locales, $default_locale;
+function gettext_init()
+{
+ $locales = config('locales');
+ $default_locale = config('default_locale');
- if (isset($_REQUEST['set_locale']) && isset($locales[$_REQUEST['set_locale']])) {
- $_SESSION['locale'] = $_REQUEST['set_locale'];
- } elseif (! isset($_SESSION['locale'])) {
- $_SESSION['locale'] = $default_locale;
- }
+ if (isset($_REQUEST['set_locale']) && isset($locales[$_REQUEST['set_locale']])) {
+ $_SESSION['locale'] = $_REQUEST['set_locale'];
+ } elseif (!isset($_SESSION['locale'])) {
+ $_SESSION['locale'] = $default_locale;
+ }
- gettext_locale();
- bindtextdomain('default', realpath(__DIR__ . '/../../locale'));
- bind_textdomain_codeset('default', 'UTF-8');
- textdomain('default');
+ gettext_locale();
+ bindtextdomain('default', realpath(__DIR__ . '/../../locale'));
+ bind_textdomain_codeset('default', 'UTF-8');
+ textdomain('default');
}
/**
* Swich gettext locale.
*
- * @param string $locale
+ * @param string $locale
*/
-function gettext_locale($locale = null) {
- if ($locale == null) {
- $locale = $_SESSION['locale'];
- }
-
- putenv('LC_ALL=' . $locale);
- setlocale(LC_ALL, $locale);
+function gettext_locale($locale = null)
+{
+ if ($locale == null) {
+ $locale = $_SESSION['locale'];
+ }
+
+ putenv('LC_ALL=' . $locale);
+ setlocale(LC_ALL, $locale);
}
/**
* Renders language selection.
*
- * @return string
+ * @return array
*/
-function make_langselect() {
- global $locales;
- $URL = $_SERVER["REQUEST_URI"] . (strpos($_SERVER["REQUEST_URI"], "?") > 0 ? '&' : '?') . "set_locale=";
-
- $items = [];
- foreach ($locales as $locale => $name) {
- $items[] = toolbar_item_link(htmlspecialchars($URL) . $locale, '', '<img src="pic/flag/' . $locale . '.png" alt="' . $name . '" title="' . $name . '"> ' . $name);
- }
- return $items;
-}
+function make_langselect()
+{
+ $url = $_SERVER['REQUEST_URI'] . (strpos($_SERVER['REQUEST_URI'], '?') > 0 ? '&' : '?') . 'set_locale=';
-?> \ No newline at end of file
+ $items = [];
+ foreach (config('locales') as $locale => $name) {
+ $items[] = toolbar_item_link(
+ htmlspecialchars($url) . $locale,
+ '',
+ '<img src="pic/flag/' . $locale . '.png" alt="' . $name . '" title="' . $name . '"> ' . $name
+ );
+ }
+ return $items;
+}
diff --git a/includes/helper/message_helper.php b/includes/helper/message_helper.php
index 37fc84bb..1f429c27 100644
--- a/includes/helper/message_helper.php
+++ b/includes/helper/message_helper.php
@@ -2,52 +2,76 @@
/**
* Gibt zwischengespeicherte Fehlermeldungen zurück und löscht den Zwischenspeicher
+ *
+ * @return string
*/
-function msg() {
- if (! isset($_SESSION['msg'])) {
- return "";
- }
- $msg = $_SESSION['msg'];
- $_SESSION['msg'] = "";
- return $msg;
+function msg()
+{
+ if (!isset($_SESSION['msg'])) {
+ return '';
+ }
+ $msg = $_SESSION['msg'];
+ $_SESSION['msg'] = '';
+ return $msg;
}
/**
* Rendert eine Information
+ *
+ * @param string $msg
+ * @param bool $immediately
+ * @return string
*/
-function info($msg, $immediatly = false) {
- return alert('info', $msg, $immediatly);
+function info($msg, $immediately = false)
+{
+ return alert('info', $msg, $immediately);
}
/**
* Rendert eine Fehlermeldung
+ *
+ * @param string $msg
+ * @param bool $immediately
+ * @return string
*/
-function error($msg, $immediatly = false) {
- return alert('danger', $msg, $immediatly);
+function error($msg, $immediately = false)
+{
+ return alert('danger', $msg, $immediately);
}
/**
* Rendert eine Erfolgsmeldung
+ *
+ * @param string $msg
+ * @param bool $immediately
+ * @return string
*/
-function success($msg, $immediatly = false) {
- return alert('success', $msg, $immediatly);
+function success($msg, $immediately = false)
+{
+ return alert('success', $msg, $immediately);
}
/**
* Renders an alert with given alert-* class.
+ *
+ * @param string $class
+ * @param string $msg
+ * @param bool $immediately
+ * @return string|null
*/
-function alert($class, $msg, $immediatly = false) {
- if ($immediatly) {
- if ($msg == "") {
- return "";
+function alert($class, $msg, $immediately = false)
+{
+ if ($immediately) {
+ if ($msg == '') {
+ return '';
+ }
+ return '<div class="alert alert-' . $class . '">' . $msg . '</div>';
}
- return '<div class="alert alert-' . $class . '">' . $msg . '</div>';
- }
-
- if (! isset($_SESSION['msg'])) {
- $_SESSION['msg'] = "";
- }
- $_SESSION['msg'] .= alert($class, $msg, true);
-}
-?> \ No newline at end of file
+ if (!isset($_SESSION['msg'])) {
+ $_SESSION['msg'] = '';
+ }
+ $_SESSION['msg'] .= alert($class, $msg, true);
+
+ return null;
+}