]> git.mxchange.org Git - friendica.git/commitdiff
Merge pull request #1530 from tobiasd/20150424
authorTobias Diekershoff <tobias.diekershoff@gmx.net>
Fri, 24 Apr 2015 08:02:42 +0000 (10:02 +0200)
committerTobias Diekershoff <tobias.diekershoff@gmx.net>
Fri, 24 Apr 2015 08:02:42 +0000 (10:02 +0200)
linefeeds in DE docs part of #1478

boot.php
include/dbstructure.php
include/diaspora.php
include/enotify.php
include/items.php
mod/ping.php
update.php

index 5e0a70db1f748ee625b76cd2ff5195f18960fc68..5994b2030ac21c5aa2c045ade6bcb0524758c945 100644 (file)
--- a/boot.php
+++ b/boot.php
@@ -18,7 +18,7 @@ define ( 'FRIENDICA_PLATFORM',     'Friendica');
 define ( 'FRIENDICA_CODENAME',     'Lily of the valley');
 define ( 'FRIENDICA_VERSION',      '3.4.0' );
 define ( 'DFRN_PROTOCOL_VERSION',  '2.23'    );
-define ( 'DB_UPDATE_VERSION',      1183      );
+define ( 'DB_UPDATE_VERSION',      1184      );
 define ( 'EOL',                    "<br />\r\n"     );
 define ( 'ATOM_TIME',              'Y-m-d\TH:i:s\Z' );
 
index 76ba37e37c0a519ef241a83dd65eca9639b8d5d5..3a6e0705d0debf49105c2d9d2287aefb6c741497 100644 (file)
@@ -925,6 +925,7 @@ function db_definition() {
                                        "msg" => array("type" => "mediumtext", "not null" => "1"),
                                        "uid" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
                                        "link" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
+                                       "iid" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
                                        "parent" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
                                        "seen" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
                                        "verb" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
index 6b42e3c555dbdc6f2b51ec217ee3b15f923bcd4b..689f5765b3a3418be23921addf18fc083fd8237f 100755 (executable)
@@ -1473,6 +1473,8 @@ function diaspora_comment($importer,$xml,$msg) {
        DiasporaFetchGuid($datarray);
        $message_id = item_store($datarray);
 
+       $datarray['id'] = $message_id;
+
        //if($message_id) {
                //q("update item set plink = '%s' where id = %d",
                //      //dbesc($a->get_baseurl() . '/display/' . $importer['nickname'] . '/' . $message_id),
index 4327e75b837d5c25fb36fbad03c7f123e861b5eb..027293d4f3a9b3c957046cb6f415c55ce2bf5750 100644 (file)
@@ -27,7 +27,7 @@ function notification($params) {
        $hostname = $a->get_hostname();
        if(strpos($hostname,':'))
                $hostname = substr($hostname,0,strpos($hostname,':'));
-       
+
        $sender_email = $a->config['sender_email'];
        if (empty($sender_email)) {
                $sender_email = t('noreply') . '@' . $hostname;
@@ -63,6 +63,16 @@ function notification($params) {
        // e.g. "your post", "David's photo", etc.
        $possess_desc = t('%s <!item_type!>');
 
+       if (isset($params['item']['id']))
+               $item_id = $params['item']['id'];
+       else
+               $item_id = 0;
+
+       if (isset($params['parent']))
+               $parent_id = $params['parent'];
+       else
+               $parent_id = 0;
+
        if($params['type'] == NOTIFY_MAIL) {
 
                $subject =      sprintf( t('[Friendica:Notify] New mail received at %s'),$sitename);
@@ -78,7 +88,7 @@ function notification($params) {
        if($params['type'] == NOTIFY_COMMENT) {
 //             logger("notification: params = " . print_r($params, true), LOGGER_DEBUG);
 
-               $parent_id = $params['parent'];
+               //$parent_id = $params['parent'];
 
                $p = q("SELECT `ignored` FROM `thread` WHERE `iid` = %d AND `uid` = %d LIMIT 1",
                        intval($parent_id),
@@ -400,6 +410,7 @@ function notification($params) {
                $datarray['date']  = datetime_convert();
                $datarray['uid']   = $params['uid'];
                $datarray['link']  = $itemlink;
+               $datarray['iid']   = $item_id;
                $datarray['parent'] = $parent_id;
                $datarray['type']  = $params['type'];
                $datarray['verb']  = $params['verb'];
@@ -415,8 +426,8 @@ function notification($params) {
 
                // create notification entry in DB
 
-               $r = q("insert into notify (hash,name,url,photo,date,uid,link,parent,type,verb,otype)
-                       values('%s','%s','%s','%s','%s',%d,'%s',%d,%d,'%s','%s')",
+               $r = q("insert into notify (hash,name,url,photo,date,uid,link,iid,parent,type,verb,otype)
+                       values('%s','%s','%s','%s','%s',%d,'%s',%d,%d,%d,'%s','%s')",
                        dbesc($datarray['hash']),
                        dbesc($datarray['name']),
                        dbesc($datarray['url']),
@@ -424,6 +435,7 @@ function notification($params) {
                        dbesc($datarray['date']),
                        intval($datarray['uid']),
                        dbesc($datarray['link']),
+                       intval($datarray['iid']),
                        intval($datarray['parent']),
                        intval($datarray['type']),
                        dbesc($datarray['verb']),
index 8a0deb437b041582bc2846592089e24dbfd40c06..ff31e84f7cab9baec570db3160eae70790eaaaef 100644 (file)
@@ -1567,7 +1567,8 @@ function item_store($arr,$force_parent = false, $notify = false, $dontcache = fa
                                'source_link'  => $item[0]['author-link'],
                                'source_photo' => $item[0]['author-avatar'],
                                'verb'         => ACTIVITY_TAG,
-                               'otype'        => 'item'
+                               'otype'        => 'item',
+                               'parent'       => $arr['parent']
                        ));
                        logger('item_store: Notification sent for contact '.$arr['contact-id'].' and post '.$current_post, LOGGER_DEBUG);
                }
@@ -3659,6 +3660,9 @@ function local_delivery($importer,$data) {
                                $parent = 0;
 
                                if($posted_id) {
+
+                                       $datarray["id"] = $posted_id;
+
                                        $r = q("SELECT `parent`, `parent-uri` FROM `item` WHERE `id` = %d AND `uid` = %d LIMIT 1",
                                                intval($posted_id),
                                                intval($importer['importer_uid'])
@@ -4021,7 +4025,7 @@ function local_delivery($importer,$data) {
                                                        'verb'         => $datarray['verb'],
                                                        'otype'        => 'person',
                                                        'activity'     => $verb,
-
+                                                       'parent'       => $datarray['parent']
                                                ));
                                        }
                                }
index 405edd3c49dedba39dee250112459c8db8c9326b..15e7dfab150be936d5a5021f253721e598cdc18a 100644 (file)
@@ -22,32 +22,8 @@ function ping_init(&$a) {
 
                $firehose = intval(get_pconfig(local_user(),'system','notify_full'));
 
-               $t = q("select count(*) as total from notify where uid = %d and seen = 0",
-                       intval(local_user())
-               );
-               if($t && intval($t[0]['total']) > 49) {
-                       $z = q("select * from notify where uid = %d
-                               and seen = 0 order by date desc limit 0, 50",
-                               intval(local_user())
-                       );
-                       $sysnotify = $t[0]['total'];
-               }
-               else {
-                       $z1 = q("select * from notify where uid = %d
-                               and seen = 0 order by date desc limit 0, 50",
-                               intval(local_user())
-                       );
-
-                       $z2 = q("select * from notify where uid = %d
-                               and seen = 1 order by date desc limit 0, %d",
-                               intval(local_user()),
-                               intval(50 - intval($t[0]['total']))
-                       );
-                       $z = array_merge($z1,$z2);
-                       $sysnotify = 0; // we will update this in a moment
-               }
-
-
+               $z = ping_get_notifications(local_user());
+               $sysnotify = 0; // we will update this in a moment
 
                $tags = array();
                $comments = array();
@@ -128,13 +104,12 @@ function ping_init(&$a) {
 
 
                $myurl = $a->get_baseurl() . '/profile/' . $a->user['nickname'] ;
-               $mails = q("SELECT *,  COUNT(*) AS `total` FROM `mail`
+               $mails = q("SELECT * FROM `mail`
                        WHERE `uid` = %d AND `seen` = 0 AND `from-url` != '%s' ",
                        intval(local_user()),
                        dbesc($myurl)
                );
-               if($mails)
-                       $mail = $mails[0]['total'];
+               $mail = count($mails);
 
                if ($a->config['register_policy'] == REGISTER_APPROVE && is_site_admin()){
                        $regs = q("SELECT `contact`.`name`, `contact`.`url`, `contact`.`micro`, `register`.`created`, COUNT(*) as `total` FROM `contact` RIGHT JOIN `register` ON `register`.`uid`=`contact`.`uid` WHERE `contact`.`self`=1");
@@ -226,7 +201,24 @@ function ping_init(&$a) {
                                }
                        }
 
-                       echo '  <notif count="'. $sysnotify .'">';
+                       echo '  <notif count="'. ($sysnotify + $intro + $mail + $register) .'">';
+
+                       if ($intro>0){
+                               foreach ($intros as $i) {
+                                       echo xmlize( $a->get_baseurl().'/notifications/intros/'.$i['id'], $i['name'], $i['url'], $i['photo'], relative_date($i['datetime']), 'notify-unseen',t("{0} wants to be your friend") );
+                               };
+                       }
+                       if ($mail>0){
+                               foreach ($mails as $i) {
+                                       echo xmlize( $a->get_baseurl().'/message/'.$i['id'], $i['from-name'], $i['from-url'], $i['from-photo'], relative_date($i['created']), 'notify-unseen',t("{0} sent you a message") );
+                               };
+                       }
+                       if ($register>0){
+                               foreach ($regs as $i) {
+                                       echo xmlize( $a->get_baseurl().'/admin/users/', $i['name'], $i['url'], $i['micro'], relative_date($i['created']), 'notify-unseen',t("{0} requested registration") );
+                               };
+                       }
+
                        if(count($z)) {
                                foreach($z as $zz) {
                                        echo xmlize($a->get_baseurl() . '/notify/view/' . $zz['id'], $zz['name'],$zz['url'],$zz['photo'],relative_date($zz['date']), ($zz['seen'] ? 'notify-seen' : 'notify-unseen'), ($zz['seen'] ? '' : '&rarr; ') .strip_tags(bbcode($zz['msg'])));
@@ -241,12 +233,12 @@ function ping_init(&$a) {
                                };
                        }
                        if ($mail>0){
-                               foreach ($mails as $i) { 
+                               foreach ($mails as $i) {
                                        echo xmlize( $a->get_baseurl().'/message/'.$i['id'], $i['from-name'], $i['from-url'], $i['from-photo'], relative_date($i['created']), 'notify-unseen',t("{0} sent you a message") );
                                };
                        }
                        if ($register>0){
-                               foreach ($regs as $i) { 
+                               foreach ($regs as $i) {
                                        echo xmlize( $a->get_baseurl().'/admin/users/', $i['name'], $i['url'], $i['micro'], relative_date($i['created']), 'notify-unseen',t("{0} requested registration") );
                                };
                        }
@@ -305,7 +297,7 @@ function ping_init(&$a) {
                }
                unset($_SESSION['sysmsg_info']);
        }
-       
+
        echo " </sysmsgs>";
        echo"</result>
        ";
@@ -313,3 +305,59 @@ function ping_init(&$a) {
        killme();
 }
 
+function ping_get_notifications($uid) {
+
+       $result = array();
+       $offset = 0;
+       $seen = false;
+       $seensql = "NOT";
+       $order = "";
+       $quit = false;
+
+       do {
+               $r = q("SELECT `notify`.*, `item`.`visible`, `item`.`spam`, `item`.`deleted`
+                       FROM `notify` LEFT JOIN `item` ON `item`.`id` = `notify`.`iid`
+                       WHERE `notify`.`uid` = %d AND `notify`.`msg` != ''
+                       AND NOT (`notify`.`type` IN (%d, %d))
+                       AND $seensql `notify`.`seen` ORDER BY `notify`.`date` $order LIMIT %d, 50",
+                       intval($uid),
+                       intval(NOTIFY_INTRO),
+                       intval(NOTIFY_MAIL),
+                       intval($offset)
+               );
+
+               if (!$r AND !$seen) {
+                       $seen = true;
+                       $seensql = "";
+                       $order = "DESC";
+                       $offset = 0;
+               } elseif (!$r)
+                       $quit = true;
+               else
+                       $offset += 50;
+
+               foreach ($r AS $notification) {
+                       if (is_null($notification["visible"]))
+                               $notification["visible"] = true;
+
+                       if (is_null($notification["spam"]))
+                               $notification["spam"] = 0;
+
+                       if (is_null($notification["deleted"]))
+                               $notification["deleted"] = 0;
+
+                       // 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["msg"],$notification['name']);
+                       if ($pos !== false)
+                               $notification["msg"] = substr_replace($notification["msg"],"{0}",$pos,strlen($notification['name']));
+
+                       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);
+}
index 35aaff2c064eec7a9ed0cdb20e748ffb51dc63b1..ca86c8557e494b5328af2c93fb1db3fa405b1781 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 
-define( 'UPDATE_VERSION' , 1183 );
+define( 'UPDATE_VERSION' , 1184 );
 
 /**
  *