]> git.mxchange.org Git - friendica.git/blobdiff - include/enotify.php
Don't try to build form for "None" backend.
[friendica.git] / include / enotify.php
index d8e5614c171034ae4270eb5d38bceaddb765400b..9edfaaca82b8e2ea2a5b46365b94ad74c859fd61 100644 (file)
@@ -7,12 +7,15 @@ use Friendica\Content\Text\BBCode;
 use Friendica\Core\Addon;
 use Friendica\Core\Config;
 use Friendica\Core\L10n;
+use Friendica\Core\Logger;
+use Friendica\Core\Renderer;
 use Friendica\Core\System;
 use Friendica\Database\DBA;
 use Friendica\Model\Contact;
 use Friendica\Model\Item;
 use Friendica\Util\DateTimeFormat;
 use Friendica\Util\Emailer;
+use Friendica\Util\Strings;
 
 /**
  * @brief Creates a notification entry and possibly sends a mail
@@ -25,11 +28,11 @@ use Friendica\Util\Emailer;
  */
 function notification($params)
 {
-       $a = get_app();
+       $a = \get_app();
 
        // Temporary logging for finding the origin
        if (!isset($params['language']) || !isset($params['uid'])) {
-               logger('Missing parameters.' . System::callstack());
+               Logger::log('Missing parameters.' . System::callstack());
        }
 
        // Ensure that the important fields are set at any time
@@ -37,7 +40,7 @@ function notification($params)
        $user = DBA::selectFirst('user', $fields, ['uid' => $params['uid']]);
 
        if (!DBA::isResult($user)) {
-               logger('Unknown user ' . $params['uid']);
+               Logger::log('Unknown user ' . $params['uid']);
                return;
        }
 
@@ -84,7 +87,7 @@ function notification($params)
        // with $params['show_in_notification_page'] == false, the notification isn't inserted into
        // the database, and an email is sent if applicable.
        // default, if not specified: true
-       $show_in_notification_page = ((x($params, 'show_in_notification_page')) ? $params['show_in_notification_page']:true);
+       $show_in_notification_page = isset($params['show_in_notification_page']) ? $params['show_in_notification_page'] : true;
 
        $additional_mail_header = "";
        $additional_mail_header .= "Precedence: list\n";
@@ -133,7 +136,8 @@ function notification($params)
        if ($params['type'] == NOTIFY_COMMENT) {
                $thread = Item::selectFirstThreadForUser($params['uid'] ,['ignored'], ['iid' => $parent_id]);
                if (DBA::isResult($thread) && $thread["ignored"]) {
-                       logger("Thread ".$parent_id." will be ignored", LOGGER_DEBUG);
+                       Logger::log("Thread ".$parent_id." will be ignored", Logger::DEBUG);
+                       L10n::popLang();
                        return;
                }
 
@@ -154,7 +158,7 @@ function notification($params)
                        $item = Item::selectFirstForUser($params['uid'], Item::ITEM_FIELDLIST, ['id' => $parent_id]);
                }
 
-               $item_post_type = item_post_type($item);
+               $item_post_type = Item::postType($item);
                $itemlink = $item['plink'];
 
                // "a post"
@@ -451,10 +455,10 @@ function notification($params)
        $itemlink  = $h['itemlink'];
 
        if ($show_in_notification_page) {
-               logger("adding notification entry", LOGGER_DEBUG);
+               Logger::log("adding notification entry", Logger::DEBUG);
                do {
                        $dups = false;
-                       $hash = random_string();
+                       $hash = Strings::getRandomHex();
                        if (DBA::exists('notify', ['hash' => $hash])) {
                                $dups = true;
                        }
@@ -515,7 +519,7 @@ function notification($params)
                }
 
                $itemlink = System::baseUrl().'/notify/view/'.$notify_id;
-               $msg = replace_macros($epreamble, ['$itemlink' => $itemlink]);
+               $msg = Renderer::replaceMacros($epreamble, ['$itemlink' => $itemlink]);
                $msg_cache = format_notification_message($datarray['name_cache'], strip_tags(BBCode::convert($msg)));
 
                $fields = ['msg' => $msg, 'msg_cache' => $msg_cache];
@@ -528,14 +532,14 @@ function notification($params)
                || $params['type'] == NOTIFY_SYSTEM
                || $params['type'] == SYSTEM_EMAIL) {
 
-               logger('sending notification email');
+               Logger::log('sending notification email');
 
                if (isset($params['parent']) && (intval($params['parent']) != 0)) {
                        $id_for_parent = $params['parent']."@".$hostname;
 
                        // Is this the first email notification for this parent item and user?
                        if (!DBA::exists('notify-threads', ['master-parent-item' => $params['parent'], 'receiver-uid' => $params['uid']])) {
-                               logger("notify_id:".intval($notify_id).", parent: ".intval($params['parent'])."uid: ".intval($params['uid']), LOGGER_DEBUG);
+                               Logger::log("notify_id:".intval($notify_id).", parent: ".intval($params['parent'])."uid: ".intval($params['uid']), Logger::DEBUG);
 
                                $fields = ['notify-id' => $notify_id, 'master-parent-item' => $params['parent'],
                                        'receiver-uid' => $params['uid'], 'parent-item' => 0];
@@ -544,11 +548,11 @@ function notification($params)
                                $additional_mail_header .= "Message-ID: <${id_for_parent}>\n";
                                $log_msg = "include/enotify: No previous notification found for this parent:\n".
                                                "  parent: ${params['parent']}\n"."  uid   : ${params['uid']}\n";
-                               logger($log_msg, LOGGER_DEBUG);
+                               Logger::log($log_msg, Logger::DEBUG);
                        } else {
                                // If not, just "follow" the thread.
                                $additional_mail_header .= "References: <${id_for_parent}>\nIn-Reply-To: <${id_for_parent}>\n";
-                               logger("There's already a notification for this parent.", LOGGER_DEBUG);
+                               Logger::log("There's already a notification for this parent.", Logger::DEBUG);
                        }
                }
 
@@ -587,8 +591,8 @@ function notification($params)
                $content_allowed = ((!Config::get('system', 'enotify_no_content')) || ($params['type'] == SYSTEM_EMAIL));
 
                // load the template for private message notifications
-               $tpl = get_markup_template('email_notify_html.tpl');
-               $email_html_body = replace_macros($tpl, [
+               $tpl = Renderer::getMarkupTemplate('email_notify_html.tpl');
+               $email_html_body = Renderer::replaceMacros($tpl, [
                        '$banner'       => $datarray['banner'],
                        '$product'      => $datarray['product'],
                        '$preamble'     => str_replace("\n", "<br>\n", $datarray['preamble']),
@@ -608,8 +612,8 @@ function notification($params)
                ]);
 
                // load the template for private message notifications
-               $tpl = get_markup_template('email_notify_text.tpl');
-               $email_text_body = replace_macros($tpl, [
+               $tpl = Renderer::getMarkupTemplate('email_notify_text.tpl');
+               $email_text_body = Renderer::replaceMacros($tpl, [
                        '$banner'       => $datarray['banner'],
                        '$product'      => $datarray['product'],
                        '$preamble'     => $datarray['preamble'],
@@ -628,6 +632,7 @@ function notification($params)
                        '$content_allowed'      => $content_allowed,
                ]);
 
+               L10n::popLang();
                // use the Emailer class to send the message
                return Emailer::send(
                        [
@@ -643,6 +648,7 @@ function notification($params)
                );
        }
 
+       L10n::popLang();
        return false;
 }
 
@@ -698,11 +704,11 @@ function check_item_notification($itemid, $uid, $defaulttype = "") {
                // Check for invalid profile urls. 13 should be the shortest possible profile length:
                // http://a.bc/d
                // Additionally check for invalid urls that would return the normalised value "http:"
-               if ((strlen($profile) >= 13) && (normalise_link($profile) != "http:")) {
+               if ((strlen($profile) >= 13) && (Strings::normaliseLink($profile) != "http:")) {
                        if (!in_array($profile, $profiles2))
                                $profiles2[] = $profile;
 
-                       $profile = normalise_link($profile);
+                       $profile = Strings::normaliseLink($profile);
                        if (!in_array($profile, $profiles2))
                                $profiles2[] = $profile;
 
@@ -756,7 +762,7 @@ function check_item_notification($itemid, $uid, $defaulttype = "") {
 
                        if (DBA::isResult($tags)) {
                                foreach ($tags AS $tag) {
-                                       $condition = ['nurl' => normalise_link($tag["url"]), 'uid' => $uid, 'notify_new_posts' => true];
+                                       $condition = ['nurl' => Strings::normaliseLink($tag["url"]), 'uid' => $uid, 'notify_new_posts' => true];
                                        $r = DBA::exists('contact', $condition);
                                        if ($r) {
                                                $send_notification = true;