]> git.mxchange.org Git - friendica.git/blobdiff - mod/ping.php
Merge pull request #2664 from annando/1607-remote-auth
[friendica.git] / mod / ping.php
index 30b5785aeca7d2df4e8524c56c67299e30775627..f2e57430d2d6ac14488be6cd7e363eb9632fbf52 100644 (file)
@@ -1,6 +1,8 @@
 <?php
 require_once("include/datetime.php");
 require_once('include/bbcode.php');
+require_once('include/ForumManager.php');
+require_once('include/group.php');
 require_once("mod/proxy.php");
 
 function ping_init(&$a) {
@@ -30,10 +32,13 @@ function ping_init(&$a) {
                $dislikes = array();
                $friends = array();
                $posts = array();
+               $regs = array();
+               $mails = array();
 
                $home = 0;
                $network = 0;
-               $network_group = array();
+               $groups_unseen = array();
+               $forums_unseen = array();
 
                $r = q("SELECT `item`.`id`,`item`.`parent`, `item`.`verb`, `item`.`wall`, `item`.`author-name`,
                                `item`.`contact-id`, `item`.`author-link`, `item`.`author-avatar`, `item`.`created`, `item`.`object`,
@@ -41,11 +46,12 @@ function ping_init(&$a) {
                                FROM `item` INNER JOIN `item` as `pitem` ON  `pitem`.`id`=`item`.`parent`
                                WHERE `item`.`unseen` = 1 AND `item`.`visible` = 1 AND
                                 `item`.`deleted` = 0 AND `item`.`uid` = %d AND `pitem`.`parent` != 0
+                               AND `item`.`contact-id` != %d
                                ORDER BY `item`.`created` DESC",
-                       intval(local_user())
+                       intval(local_user()), intval(local_user())
                );
 
-               if(count($r)) {
+               if(dbm::is_result($r)) {
 
                        $arr = array('items' => $r);
                        call_hooks('network_ping', $arr);
@@ -85,20 +91,15 @@ function ping_init(&$a) {
                        }
                }
 
-               if ( $network )
-               {
-                       # Find out how unseen network posts are spread across groups
-                       $sql = "SELECT g.id, g.name, count(i.id) count " .
-                               "FROM `group` g, group_member gm, item i " .
-                               "WHERE g.uid = %d " .
-                               "AND i.uid = %d " .
-                               "AND i.unseen AND i.visible " .
-                               "AND NOT i.deleted " .
-                               "AND i.`contact-id` = gm.`contact-id` " .
-                               "AND gm.gid = g.id GROUP BY g.id";
-                       #echo '<SQL id="' . intval(local_user()) . '">' . $sql . '</SQL>';
-                       $network_group = q($sql, intval(local_user()), intval(local_user()));
-                       #echo '<COUNT R="' . count($network_group) . '"/>';
+               if($network) {
+                       if(intval(feature_enabled(local_user(),'groups'))) {
+                               // Find out how unseen network posts are spread across groups
+                               $groups_unseen = groups_count_unseen();
+                       }
+
+                       if(intval(feature_enabled(local_user(),'forumlist_widget'))) {
+                               $forums_unseen = ForumManager::count_unseen_items();
+                       }
                }
 
                $intros1 = q("SELECT  `intro`.`id`, `intro`.`datetime`,
@@ -117,8 +118,6 @@ function ping_init(&$a) {
                $intro = count($intros1) + count($intros2);
                $intros = $intros1+$intros2;
 
-
-
                $myurl = $a->get_baseurl() . '/profile/' . $a->user['nickname'] ;
                $mails = q("SELECT * FROM `mail`
                        WHERE `uid` = %d AND `seen` = 0 AND `from-url` != '%s' ",
@@ -151,7 +150,7 @@ function ping_init(&$a) {
                        dbesc(datetime_convert('UTC','UTC','now'))
                );
 
-               if($ev && count($ev)) {
+               if(dbm::is_result($ev)) {
                        $all_events = intval($ev[0]['total']);
 
                        if($all_events) {
@@ -190,7 +189,12 @@ function ping_init(&$a) {
                 *              'message' => notification message. "{0}" will be replaced by subject name
                 **/
                function xmlize($n){
-                       $n['photo'] = proxy_url($n['photo'], false, PROXY_SIZE_MICRO);
+
+                       $contact = get_contact_details_by_url($n['url']);
+                       if (isset($contact["micro"]))
+                               $n['photo'] = proxy_url($contact["micro"], false, PROXY_SIZE_MICRO);
+                       else
+                               $n['photo'] = proxy_url($n['photo'], false, PROXY_SIZE_MICRO);
 
                        $n['message'] = html_entity_decode($n['message'], ENT_COMPAT | ENT_HTML401, "UTF-8");
                        $n['name'] = html_entity_decode($n['name'], ENT_COMPAT | ENT_HTML401, "UTF-8");
@@ -206,9 +210,9 @@ function ping_init(&$a) {
                        $local_time = datetime_convert('UTC',date_default_timezone_get(),$n['date']);
 
                        call_hooks('ping_xmlize', $n);
-                       $notsxml = '<note href="%s" name="%s" url="%s" photo="%s" date="%s" seen="%s" timestamp="%s" >%s</note>'."\n";
-                       return sprintf ( $notsxml,
-                               xmlify($n['href']), xmlify($n['name']), xmlify($n['url']), xmlify($n['photo']),
+                       $notsxml = '<note id="%d" href="%s" name="%s" url="%s" photo="%s" date="%s" seen="%s" timestamp="%s" >%s</note>'."\n";
+                       return sprintf ( $notsxml, intval($n['id']),
+                               xmlify($n['href']), xmlify(xmlify($n['name'])), xmlify($n['url']), xmlify($n['photo']),
                                xmlify(relative_date($n['date'])), xmlify($n['seen']), xmlify(strtotime($local_time)),
                                xmlify($n['message'])
                        );
@@ -219,14 +223,25 @@ function ping_init(&$a) {
                                <net>$network</net>
                                <home>$home</home>\r\n";
                if ($register!=0) echo "<register>$register</register>";
-               if ( count($network_group) ) {
+
+               if ( dbm::is_result($groups_unseen) ) {
                        echo '<groups>';
-                       foreach ($network_group as $it) {
-                               echo '<group id="' . $it['id'] . '">' . $it['count'] . "</group>";
-                       }
+                       foreach ($groups_unseen as $it)
+                               if ($it['count'] > 0)
+                                       echo '<group id="'.$it['id'].'">'.$it['count']."</group>";
+
                        echo "</groups>";
                }
 
+               if ( dbm::is_result($forums_unseen) ) {
+                       echo '<forums>';
+                       foreach ($forums_unseen as $it)
+                               if ($it['count'] > 0)
+                                       echo '<forum id="'.$it['id'].'">'.$it['count']."</forum>";
+
+                       echo "</forums>";
+               }
+
                echo "<all-events>$all_events</all-events>
                        <all-events-today>$all_events_today</all-events-today>
                        <events>$events</events>
@@ -235,8 +250,8 @@ function ping_init(&$a) {
                        <birthdays-today>$birthdays_today</birthdays-today>\r\n";
 
 
-               if(count($notifs) && (! $sysnotify)) {
-                       foreach($notifs as $zz) {
+               if (dbm::is_result($notifs) && (! $sysnotify)) {
+                       foreach ($notifs as $zz) {
                                if($zz['seen'] == 0)
                                        $sysnotify ++;
                        }
@@ -245,7 +260,7 @@ function ping_init(&$a) {
                echo '  <notif count="'. ($sysnotify + $intro + $mail + $register) .'">';
 
                // merge all notification types in one array
-               if ($intro>0){
+               if ( dbm::is_result($intros) ) {
                        foreach ($intros as $i) {
                                $n = array(
                                        'href' => $a->get_baseurl().'/notifications/intros/'.$i['id'],
@@ -260,7 +275,7 @@ function ping_init(&$a) {
                        }
                }
 
-               if ($mail>0){
+               if ( dbm::is_result($mails) ) {
                        foreach ($mails as $i) {
                                $n = array(
                                        'href' => $a->get_baseurl().'/message/'.$i['id'],
@@ -275,7 +290,7 @@ function ping_init(&$a) {
                        }
                }
 
-               if ($register>0){
+               if ( dbm::is_result($regs) ) {
                        foreach ($regs as $i) {
                                $n = array(
                                        'href' => $a->get_baseurl().'/admin/users/',
@@ -289,6 +304,7 @@ function ping_init(&$a) {
                                $notifs[] = $n;
                        }
                }
+
                // sort notifications by $[]['date']
                $sort_function = function($a, $b) {
                        $adate = date($a['date']);
@@ -300,7 +316,7 @@ function ping_init(&$a) {
                };
                usort($notifs, $sort_function);
 
-               if(count($notifs)) {
+               if( dbm::is_result($notifs) ) {
                        foreach($notifs as $n) {
                                echo xmlize($n);
                        }
@@ -381,7 +397,11 @@ function ping_get_notifications($uid) {
                        // Replace the name with {0} but ensure to make that only once
                        // The {0} is used later and prints the name in bold.
 
-                       $pos = strpos($notification["message"],$notification['name']);
+                       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"]));