]> git.mxchange.org Git - friendica.git/blobdiff - mod/ping.php
Removed commented code
[friendica.git] / mod / ping.php
index 4f939eaa0cbe12a5217254f9ad73b72ce350f440..0ed7eb3fed85812055c8f9bf9e07578a30b95003 100644 (file)
@@ -8,12 +8,14 @@ require_once('include/xml.php');
 
 function ping_init(&$a) {
 
+       $xmlhead = "<"."?xml version='1.0' encoding='UTF-8' ?".">";
+
        if (local_user()){
                // Different login session than the page that is calling us.
                if (intval($_GET['uid']) && intval($_GET['uid']) != local_user()) {
                        $data = array("invalid" => 1);
                        header("Content-type: text/xml");
-                       echo xml::from_array(array("result" => $data));
+                       echo xml::from_array(array("result" => $data), $xml);
                        killme();
                }
 
@@ -338,10 +340,16 @@ function ping_init(&$a) {
        $data["sysmsgs"] = $sysmsg;
 
        header("Content-type: text/xml");
-       echo xml::from_array(array("result" => $data));
+       echo xml::from_array(array("result" => $data), $xml);
        killme();
 }
 
+/**
+ * @brief Retrieves the notifications array for the given user ID
+ *
+ * @param int $uid User id
+ * @return array Associative array of notifications
+ */
 function ping_get_notifications($uid) {
 
        $result = array();
@@ -370,46 +378,47 @@ function ping_get_notifications($uid) {
                        $seensql = "";
                        $order = "DESC";
                        $offset = 0;
-               } elseif (!$r)
+               } elseif (!$r) {
                        $quit = true;
-               else
+               } else {
                        $offset += 50;
-
+               }
 
                foreach ($r AS $notification) {
-                       if (is_null($notification["visible"]))
+                       if (is_null($notification["visible"])) {
                                $notification["visible"] = true;
+                       }
 
-                       if (is_null($notification["spam"]))
+                       if (is_null($notification["spam"])) {
                                $notification["spam"] = 0;
+                       }
 
-                       if (is_null($notification["deleted"]))
+                       if (is_null($notification["deleted"])) {
                                $notification["deleted"] = 0;
+                       }
 
-                       $notification["message"] = strip_tags(bbcode($notification["msg"]));
-                       $notification["name"] = strip_tags(bbcode($notification["name"]));
-
-                       // Replace the name with {0} but ensure to make that only once
-                       // The {0} is used later and prints the name in bold.
-
-                       if ($notification['name'] != "")
-                               $pos = strpos($notification["message"],$notification['name']);
-                       else
-                               $pos = false;
-
-                       if ($pos !== false)
-                               $notification["message"] = substr_replace($notification["message"],"{0}",$pos,strlen($notification["name"]));
+                       if ($notification["msg_cache"]) {
+                               $notification["name"] = $notification["name_cache"];
+                               $notification["message"] = $notification["msg_cache"];
+                       } else {
+                               $notification["name"] = strip_tags(bbcode($notification["name"]));
+                               $notification["message"] = format_notification_message($notification["name"], strip_tags(bbcode($notification["msg"])));
+
+                               q("UPDATE `notify` SET `name_cache` = '%s', `msg_cache` = '%s' WHERE `id` = %d",
+                                       dbesc($notification["name"]),
+                                       dbesc($notification["message"]),
+                                       intval($notification["id"])
+                               );
+                       }
 
-                       $notification['href'] = $a->get_baseurl() . '/notify/view/' . $notification['id'];
+                       $notification["href"] = $a->get_baseurl() . "/notify/view/" . $notification["id"];
 
                        if ($notification["visible"] AND !$notification["spam"] AND
                                !$notification["deleted"] AND !is_array($result[$notification["parent"]])) {
                                $result[$notification["parent"]] = $notification;
                        }
                }
-
        } while ((count($result) < 50) AND !$quit);
 
-
        return($result);
 }