]> git.mxchange.org Git - friendica.git/blobdiff - include/enotify.php
Merge remote-tracking branch 'upstream/develop' into develop
[friendica.git] / include / enotify.php
index c6e0506e96ef2e34191e6d3fd250f4192e068a8a..10723fb418af41432d91f80d3a8da7f7f8320d03 100644 (file)
@@ -1,4 +1,8 @@
 <?php
+
+use Friendica\App;
+use Friendica\Core\System;
+
 require_once('include/Emailer.php');
 require_once('include/email.php');
 require_once('include/bbcode.php');
@@ -23,7 +27,7 @@ function notification($params) {
 
        $banner = t('Friendica Notification');
        $product = FRIENDICA_PLATFORM;
-       $siteurl = $a->get_baseurl(true);
+       $siteurl = System::baseUrl(true);
        $thanks = t('Thank You,');
        $sitename = $a->config['sitename'];
        if (!x($a->config['admin_name']))
@@ -42,9 +46,16 @@ function notification($params) {
        if (empty($sender_email))
                $sender_email = t('noreply').'@'.$hostname;
 
-       $user = q("SELECT `nickname` FROM `user` WHERE `uid` = %d", intval($params['uid']));
-       if ($user)
-               $nickname = $user[0]["nickname"];
+       if ($params['type'] != SYSTEM_EMAIL) {
+               $user = dba::select('user', array('nickname', 'page-flags'),
+                       array('uid' => $params['uid']), array('limit' => 1));
+
+               // There is no need to create notifications for forum accounts
+               if (!dbm::is_result($user) || in_array($user["page-flags"], array(PAGE_COMMUNITY, PAGE_PRVGROUP))) {
+                       return;
+               }
+       }
+       $nickname = $user["nickname"];
 
        // with $params['show_in_notification_page'] == false, the notification isn't inserted into
        // the database, and an email is sent if applicable.
@@ -58,7 +69,7 @@ function notification($params) {
        $additional_mail_header .= "X-Friendica-Platform: ".FRIENDICA_PLATFORM."\n";
        $additional_mail_header .= "X-Friendica-Version: ".FRIENDICA_VERSION."\n";
        $additional_mail_header .= "List-ID: <notification.".$hostname.">\n";
-       $additional_mail_header .= "List-Archive: <".$a->get_baseurl()."/notifications/system>\n";
+       $additional_mail_header .= "List-Archive: <".System::baseUrl()."/notifications/system>\n";
 
        if (array_key_exists('item', $params)) {
                $title = $params['item']['title'];
@@ -96,7 +107,7 @@ function notification($params) {
                        intval($parent_id),
                        intval($params['uid'])
                );
-               if ($p AND count($p) AND ($p[0]["ignored"])) {
+               if ($p && count($p) && ($p[0]["ignored"])) {
                        logger("Thread ".$parent_id." will be ignored", LOGGER_DEBUG);
                        return;
                }
@@ -105,14 +116,14 @@ function notification($params) {
                // If so don't create a second notification
 
                $p = null;
-               $p = q("SELECT `id` FROM `notify` WHERE (`type` = %d OR `type` = %d OR `type` = %d) AND `link` = '%s' AND `uid` = %d LIMIT 1",
+               $p = q("SELECT `id` FROM `notify` WHERE `type` IN (%d, %d, %d) AND `link` = '%s' AND `uid` = %d LIMIT 1",
                        intval(NOTIFY_TAGSELF),
                        intval(NOTIFY_COMMENT),
                        intval(NOTIFY_SHARE),
                        dbesc($params['link']),
                        intval($params['uid'])
                );
-               if ($p and count($p)) {
+               if ($p && count($p)) {
                        pop_lang();
                        return;
                }
@@ -357,7 +368,7 @@ function notification($params) {
                }
        }
 
-       if ($params['type'] == "SYSTEM_EMAIL") {
+       if ($params['type'] == SYSTEM_EMAIL) {
                // not part of the notifications.
                // it just send a mail to the user.
                // It will be used by the system to send emails to users (like
@@ -411,10 +422,12 @@ function notification($params) {
                        $hash = random_string();
                        $r = q("SELECT `id` FROM `notify` WHERE `hash` = '%s' LIMIT 1",
                                dbesc($hash));
-                       if (dbm::is_result($r))
+                       if (dbm::is_result($r)) {
                                $dups = true;
-               } while($dups == true);
+                       }
+               } while ($dups == true);
 
+               /// @TODO One statement is enough
                $datarray = array();
                $datarray['hash']  = $hash;
                $datarray['name']  = $params['source_name'];
@@ -472,7 +485,7 @@ function notification($params) {
                // After we've stored everything, look again to see if there are any duplicates and if so remove them
 
                $p = null;
-               $p = q("SELECT `id` FROM `notify` WHERE (`type` = %d OR `type` = %d) AND `link` = '%s' AND `uid` = %d ORDER BY `id`",
+               $p = q("SELECT `id` FROM `notify` WHERE `type` IN (%d, %d) AND `link` = '%s' AND `uid` = %d ORDER BY `id`",
                        intval(NOTIFY_TAGSELF),
                        intval(NOTIFY_COMMENT),
                        dbesc($params['link']),
@@ -480,9 +493,7 @@ function notification($params) {
                );
                if ($p && (count($p) > 1)) {
                        for ($d = 1; $d < count($p); $d ++) {
-                               q("DELETE FROM `notify` WHERE `id` = %d",
-                                       intval($p[$d]['id'])
-                               );
+                               dba::delete('notify', array('id' => $p[$d]['id']));
                        }
 
                        // only continue on if we stored the first one
@@ -494,7 +505,7 @@ function notification($params) {
                }
 
 
-               $itemlink = $a->get_baseurl().'/notify/view/'.$notify_id;
+               $itemlink = System::baseUrl().'/notify/view/'.$notify_id;
                $msg = replace_macros($epreamble, array('$itemlink' => $itemlink));
                $msg_cache = format_notification_message($datarray['name_cache'], strip_tags(bbcode($msg)));
                $r = q("UPDATE `notify` SET `msg` = '%s', `msg_cache` = '%s' WHERE `id` = %d AND `uid` = %d",
@@ -508,11 +519,11 @@ function notification($params) {
        // send email notification if notification preferences permit
        if ((intval($params['notify_flags']) & intval($params['type']))
                || $params['type'] == NOTIFY_SYSTEM
-               || $params['type'] == "SYSTEM_EMAIL") {
+               || $params['type'] == SYSTEM_EMAIL) {
 
                logger('sending notification email');
 
-               if (isset($params['parent']) AND (intval($params['parent']) != 0)) {
+               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?
@@ -577,8 +588,8 @@ function notification($params) {
                call_hooks('enotify_mail', $datarray);
 
                // check whether sending post content in email notifications is allowed
-               // always true for "SYSTEM_EMAIL"
-               $content_allowed = ((!get_config('system', 'enotify_no_content')) || ($params['type'] == "SYSTEM_EMAIL"));
+               // always true for SYSTEM_EMAIL
+               $content_allowed = ((!get_config('system', 'enotify_no_content')) || ($params['type'] == SYSTEM_EMAIL));
 
                // load the template for private message notifications
                $tpl = get_markup_template('email_notify_html.tpl');
@@ -648,8 +659,6 @@ function notification($params) {
  * @param str $defaulttype (Optional) Forces a notification with this type.
  */
 function check_item_notification($itemid, $uid, $defaulttype = "") {
-       $a = get_app();
-
        $notification_data = array("uid" => $uid, "profiles" => array());
        call_hooks('check_item_notification', $notification_data);
 
@@ -667,7 +676,7 @@ function check_item_notification($itemid, $uid, $defaulttype = "") {
        $profiles[] = $owner[0]["url"];
 
        // Notifications from Diaspora are often with an URL in the Diaspora format
-       $profiles[] = $a->get_baseurl()."/u/".$user[0]["nickname"];
+       $profiles[] = System::baseUrl()."/u/".$user[0]["nickname"];
 
        $profiles2 = array();
 
@@ -675,7 +684,7 @@ 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) AND (normalise_link($profile) != "http:")) {
+               if ((strlen($profile) >= 13) && (normalise_link($profile) != "http:")) {
                        if (!in_array($profile, $profiles2))
                                $profiles2[] = $profile;
 
@@ -721,7 +730,7 @@ function check_item_notification($itemid, $uid, $defaulttype = "") {
        $params["to_email"] = $user[0]["email"];
        $params["item"] = $item[0];
        $params["parent"] = $item[0]["parent"];
-       $params["link"] = App::get_baseurl().'/display/'.urlencode($item[0]["guid"]);
+       $params["link"] = System::baseUrl().'/display/'.urlencode($item[0]["guid"]);
        $params["otype"] = 'item';
        $params["source_name"] = $item[0]["author-name"];
        $params["source_link"] = $item[0]["author-link"];
@@ -759,11 +768,11 @@ function check_item_notification($itemid, $uid, $defaulttype = "") {
        $tagged = false;
 
        foreach ($profiles AS $profile) {
-               if (strpos($item[0]["tag"], "=".$profile."]") OR strpos($item[0]["body"], "=".$profile."]"))
+               if (strpos($item[0]["tag"], "=".$profile."]") || strpos($item[0]["body"], "=".$profile."]"))
                        $tagged = true;
        }
 
-       if ($item[0]["mention"] OR $tagged OR ($defaulttype == NOTIFY_TAGSELF)) {
+       if ($item[0]["mention"] || $tagged || ($defaulttype == NOTIFY_TAGSELF)) {
                $params["type"] = NOTIFY_TAGSELF;
                $params["verb"] = ACTIVITY_TAG;
        }
@@ -775,7 +784,7 @@ function check_item_notification($itemid, $uid, $defaulttype = "") {
                        LIMIT 1",
                        intval($item[0]["parent"]), intval($uid));
 
-       if ($parent AND !isset($params["type"])) {
+       if ($parent && !isset($params["type"])) {
                $params["type"] = NOTIFY_COMMENT;
                $params["verb"] = ACTIVITY_POST;
        }