]> git.mxchange.org Git - friendica.git/commitdiff
Merge remote-tracking branch 'remotes/friendica/master' into moveme
authorFabrixxm <fabrix.xm@gmail.com>
Mon, 5 Nov 2012 08:37:58 +0000 (09:37 +0100)
committerFabrixxm <fabrix.xm@gmail.com>
Mon, 5 Nov 2012 08:37:58 +0000 (09:37 +0100)
1  2 
boot.php
include/delivery.php
include/items.php
include/notifier.php
include/onepoll.php
include/poller.php
mod/dfrn_notify.php

diff --combined boot.php
index 71304e53e2e84ddaa97a7822dcc445f63f2e57b7,2628c0f3f113fb46de4aa7625f2c82331a56a902..cd309d86552548e4bbd9b314e1ea38b35af9dfcc
+++ b/boot.php
@@@ -11,7 -11,7 +11,7 @@@ require_once('include/cache.php')
  require_once('library/Mobile_Detect/Mobile_Detect.php');
  
  define ( 'FRIENDICA_PLATFORM',     'Friendica');
- define ( 'FRIENDICA_VERSION',      '3.0.1508' );
+ define ( 'FRIENDICA_VERSION',      '3.0.1517' );
  define ( 'DFRN_PROTOCOL_VERSION',  '2.23'    );
  define ( 'DB_UPDATE_VERSION',      1156      );
  
@@@ -385,7 -385,7 +385,7 @@@ if(! class_exists('App')) 
                                                        
                function __construct() {
  
 -                      global $default_timezone;
 +                      global $default_timezone, $argv, $argc;
  
                        $this->timezone = ((x($default_timezone)) ? $default_timezone : 'UTC');
  
                                if(isset($path) && strlen($path) && ($path != $this->path))
                                        $this->path = $path;
                        }
 +                      if (is_array($argv) && $argc>1 && !x($_SERVER,'SERVER_NAME') && substr(end($argv), 0, 4)=="http" ) {
 +                              $this->set_baseurl(array_pop($argv) );
 +                      }
  
                        set_include_path(
                                        "include/$this->hostname" . PATH_SEPARATOR
                                        . 'library/phpsec' . PATH_SEPARATOR
                                        . 'library/langdet' . PATH_SEPARATOR
                                        . '.' );
 +            
  
                        if((x($_SERVER,'QUERY_STRING')) && substr($_SERVER['QUERY_STRING'],0,2) === "q=") {
                                $this->query_string = substr($_SERVER['QUERY_STRING'],2);
@@@ -1505,20 -1501,14 +1505,20 @@@ if(! function_exists('proc_run')) 
  
                if(count($args) && $args[0] === 'php')
                        $args[0] = ((x($a->config,'php_path')) && (strlen($a->config['php_path'])) ? $a->config['php_path'] : 'php');
 -              for($x = 0; $x < count($args); $x ++)
 +        
 +        // add baseurl to args. cli scripts can't construct it
 +        $args[] = $a->get_baseurl();
 +        
 +        for($x = 0; $x < count($args); $x ++)
                        $args[$x] = escapeshellarg($args[$x]);
  
 +        
 +
                $cmdline = implode($args," ");
                if(get_config('system','proc_windows'))
-                       proc_close(proc_open('cmd /c start /b ' . $cmdline,array(),$foo));
+                       proc_close(proc_open('cmd /c start /b ' . $cmdline,array(),$foo,dirname(__FILE__)));
                else
-                       proc_close(proc_open($cmdline." &",array(),$foo));
+                       proc_close(proc_open($cmdline." &",array(),$foo,dirname(__FILE__)));
        }
  }
  
@@@ -1806,3 -1796,10 +1806,10 @@@ function curPageURL() 
        return $pageURL;
  }
  
+ function random_digits($digits) {
+       $rn = '';
+       for($i = 0; $i < $digits; $i++) {
+               $rn .= rand(0,9);
+       }
+       return $rn;
+ }
diff --combined include/delivery.php
index d879deedb5a49cdb870a020900d02d7fc028e334,613453bc7adec9985087c37b644f759c94b315cc..4280359735c7ab317f1ec484b8f9a9aa6c375adc
@@@ -3,7 -3,7 +3,7 @@@ require_once("boot.php")
  require_once('include/queue_fn.php');
  require_once('include/html2plain.php');
  
 -function delivery_run($argv, $argc){
 +function delivery_run(&$argv, &$argc){
        global $a, $db;
  
        if(is_null($a)){
                                                WHERE `contact`.`blocked` = 0 AND `contact`.`pending` = 0
                                                AND `contact`.`network` = '%s' AND `user`.`nickname` = '%s'
                                                $sql_extra
-                                               AND `user`.`account_expired` = 0 LIMIT 1",
+                                               AND `user`.`account_expired` = 0 AND `user`.`account_removed` = 0 LIMIT 1",
                                                dbesc(NETWORK_DFRN),
                                                dbesc($nickname)
                                        );
diff --combined include/items.php
index 426673484229fad6f9c766aa2567030f6f6c6c6c,939cefc3dd70578635ed5f378dc9217ee845662f..5ad89d8c180d9afeeb3e20706db2e1aeb4651cfd
@@@ -2168,10 -2168,9 +2168,10 @@@ function consume_feed($xml,$importer,&$
  }
  
  function local_delivery($importer,$data) {
 -
        $a = get_app();
  
 +    logger(__function__, LOGGER_TRACE);
 +
        if($importer['readonly']) {
                // We aren't receiving stuff from this person. But we will quietly ignore them
                // rather than a blatant "go away" message.
        }
  
  
 -/*
 +
        // Currently unsupported - needs a lot of work
        $reloc = $feed->get_feed_tags( NAMESPACE_DFRN, 'relocate' );
        if(isset($reloc[0]['child'][NAMESPACE_DFRN])) {
                $newloc['cid'] = $importer['id'];
                $newloc['name'] = notags(unxmlify($base['name'][0]['data']));
                $newloc['photo'] = notags(unxmlify($base['photo'][0]['data']));
 +              $newloc['thumb'] = notags(unxmlify($base['thumb'][0]['data']));
 +              $newloc['micro'] = notags(unxmlify($base['micro'][0]['data']));
                $newloc['url'] = notags(unxmlify($base['url'][0]['data']));
                $newloc['request'] = notags(unxmlify($base['request'][0]['data']));
                $newloc['confirm'] = notags(unxmlify($base['confirm'][0]['data']));
                $newloc['notify'] = notags(unxmlify($base['notify'][0]['data']));
                $newloc['poll'] = notags(unxmlify($base['poll'][0]['data']));
 -              $newloc['site-pubkey'] = notags(unxmlify($base['site-pubkey'][0]['data']));
 -              $newloc['pubkey'] = notags(unxmlify($base['pubkey'][0]['data']));
 -              $newloc['prvkey'] = notags(unxmlify($base['prvkey'][0]['data']));
 +              $newloc['sitepubkey'] = notags(unxmlify($base['sitepubkey'][0]['data']));
 +              /** relocated user must have original key pair */
 +              /*$newloc['pubkey'] = notags(unxmlify($base['pubkey'][0]['data']));
 +              $newloc['prvkey'] = notags(unxmlify($base['prvkey'][0]['data']));*/
 +              
 +        logger("items:relocate contact ".print_r($newloc, true).print_r($importer, true), LOGGER_DEBUG);
 +        
 +        // update contact
 +        $r = q("SELECT photo, url FROM contact WHERE id=%d AND uid=%d;",
 +                    intval($importer['id']),
 +                                      intval($importer['importer_uid']));
 +              if ($r === false) 
 +                      return 1;
 +        $old = $r[0];
 +        
 +        $x = q("UPDATE contact SET
 +                        name = '%s',
 +                        photo = '%s',
 +                        thumb = '%s',
 +                        micro = '%s',
 +                        url = '%s',
 +                        request = '%s',
 +                        confirm = '%s',
 +                        notify = '%s',
 +                        poll = '%s',
 +                        `site-pubkey` = '%s'
 +                WHERE id=%d AND uid=%d;",
 +                    dbesc($newloc['name']),
 +                    dbesc($newloc['photo']),
 +                    dbesc($newloc['thumb']),
 +                    dbesc($newloc['micro']),
 +                    dbesc($newloc['url']),
 +                    dbesc($newloc['request']),
 +                    dbesc($newloc['confirm']),
 +                    dbesc($newloc['notify']),
 +                    dbesc($newloc['poll']),
 +                    dbesc($newloc['sitepubkey']),
 +                    intval($importer['id']),
 +                                      intval($importer['importer_uid']));
 +
 +        if ($x === false)
 +                      return 1;
 +        // update items
 +        $fields = array(
 +            'owner-link' => array($old['url'], $newloc['url']),
 +            'author-link' => array($old['url'], $newloc['url']),
 +            'owner-avatar' => array($old['photo'], $newloc['photo']),
 +            'author-avatar' => array($old['photo'], $newloc['photo']),
 +        );
 +        foreach ($fields as $n=>$f){
 +            $x = q("UPDATE item SET `%s`='%s' WHERE `%s`='%s' AND uid=%d",
 +                        $n, dbesc($f[1]),
 +                        $n, dbesc($f[0]),
 +                        intval($importer['importer_uid']));
 +                      if ($x === false)
 +                              return 1;
 +              }
                
                // TODO
                // merge with current record, current contents have priority
                // update record, set url-updated
                // update profile photos
                // schedule a scan?
 -
 +        return 0;
        }
 -*/
 +
  
        // handle friend suggestion notification
  
@@@ -3958,10 -3901,10 +3958,10 @@@ function drop_item($id,$interactive = t
  
                // send the notification upstream/downstream as the case may be
  
+               proc_run('php',"include/notifier.php","drop","$drop_id");
                if(! $interactive)
                        return $owner;
-               proc_run('php',"include/notifier.php","drop","$drop_id");
                goaway($a->get_baseurl() . '/' . $_SESSION['return_url']);
                //NOTREACHED
        }
diff --combined include/notifier.php
index c78d2f1a763473584ff720b23977a9fcf2390996,a999c3297b4c55cc3096f723c55b5302a9d2d23a..c58a8a854f60420b501606c8e426e60acbba2c82
@@@ -1,4 -1,5 +1,4 @@@
  <?php
 -
  require_once("boot.php");
  require_once('include/queue_fn.php');
  require_once('include/html2plain.php');
@@@ -42,7 -43,7 +42,7 @@@
   */
  
  
 -function notifier_run($argv, $argc){
 +function notifier_run(&$argv, &$argc){
        global $a, $db;
  
        if(is_null($a)){
@@@ -88,7 -89,6 +88,7 @@@
        $expire = false;
        $mail = false;
        $fsuggest = false;
 +    $relocate = false;
        $top_level = false;
        $recipients = array();
        $url_recipients = array();
                $recipients[] = $suggest[0]['cid'];
                $item = $suggest[0];
        }
+       elseif($cmd === 'removeme') {
+               $r = q("SELECT * FROM `user` WHERE `uid` = %d LIMIT 1", intval($item_id));
+               $user = $r[0];
+               $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `self` = 1 LIMIT 1", intval($item_id));
+               $self = $r[0];
+               $r = q("SELECT * FROM `contact` WHERE `self` = 0 AND `uid` = %d", intval($item_id));
+               if(! count($r))
+                       return;
+               require_once('include/Contact.php');
+               foreach($r as $contact) {
+                       terminate_friendship($user, $self, $contact);
+               }
+               return;
+       }
 +    elseif($cmd === 'relocate') {
 +        $normal_mode = false;
 +              $relocate = true;
 +        $uid = $item_id;
 +    }
        else {
--
                // find ancestors
                $r = q("SELECT * FROM `item` WHERE `id` = %d and visible = 1 and moderated = 0 LIMIT 1",
                        intval($item_id)
        // fill this in with a single salmon slap if applicable
        $slap = '';
  
 -      if(! ($mail || $fsuggest)) {
 +      if(! ($mail || $fsuggest || $relocate)) {
  
                require_once('include/group.php');
  
                );
  
        }
 +    elseif($relocate) {
 +        $public_message = false;  // suggestions are not public
 +
 +              $sugg_template = get_markup_template('atom_relocate.tpl');
 +
 +              /* get site pubkey. this could be a new installation with no site keys*/
 +              $pubkey = get_config('system','site_pubkey');
 +              if(! $pubkey) {
 +                      $res = new_keypair(1024);
 +                      set_config('system','site_prvkey', $res['prvkey']);
 +                      set_config('system','site_pubkey', $res['pubkey']);
 +              }
 +              
 +              $rp = q("SELECT `resource-id` , `scale`, type FROM `photo` 
 +                                              WHERE `profile` = 1 AND `uid` = %d ORDER BY scale;", $uid);
 +              $photos = array();
 +              $ext = Photo::supportedTypes();
 +              foreach($rp as $p){
 +                      $photos[$p['scale']] = $a->get_baseurl().'/photo/'.$p['resource-id'].'-'.$p['scale'].'.'.$ext[$p['type']];
 +              }
 +              unset($rp, $ext);
 +              
 +        $atom .= replace_macros($sugg_template, array(
 +            '$name' => xmlify($owner['name']),
 +            '$photo' => xmlify($photos[4]),
 +            '$thumb' => xmlify($photos[5]),
 +            '$micro' => xmlify($photos[6]),
 +            '$url' => xmlify($owner['url']),
 +            '$request' => xmlify($owner['request']),
 +            '$confirm' => xmlify($owner['confirm']),
 +            '$notify' => xmlify($owner['notify']),
 +            '$poll' => xmlify($owner['poll']),
 +            '$sitepubkey' => xmlify(get_config('system','site_pubkey')),
 +            //'$pubkey' => xmlify($owner['pubkey']),
 +            //'$prvkey' => xmlify($owner['prvkey']),
 +              )); 
 +        $recipients_relocate = q("SELECT * FROM contact WHERE uid = %d  AND self = 0 AND network = '%s'" , intval($uid), NETWORK_DFRN);
 +              unset($photos);
 +    }
        else {
                if($followup) {
                        foreach($items as $item) {  // there is only one item
        else
                $recip_str = implode(', ', $recipients);
  
 -      $r = q("SELECT * FROM `contact` WHERE `id` IN ( %s ) AND `blocked` = 0 AND `pending` = 0 ",
 -              dbesc($recip_str)
 -      );
 +    if ($relocate)
 +        $r = $recipients_relocate;
 +    else
 +        $r = q("SELECT * FROM `contact` WHERE `id` IN ( %s ) AND `blocked` = 0 AND `pending` = 0 ",
 +            dbesc($recip_str)
 +        );
  
  
        require_once('include/salmon.php');
        if(count($r)) {
  
                foreach($r as $contact) {
 -                      if((! $mail) && (! $fsuggest) && (! $followup) && (! $contact['self'])) {
 +                      if((! $mail) && (! $fsuggest) && (! $followup) && (!$relocate) && (! $contact['self'])) {
                                if(($contact['network'] === NETWORK_DIASPORA) && ($public_message))
                                        continue;
                                q("insert into deliverq ( `cmd`,`item`,`contact` ) values ('%s', %d, %d )",
                        // potentially more than one recipient. Start a new process and space them out a bit.
                        // we will deliver single recipient types of message and email recipients here. 
                
 -                      if((! $mail) && (! $fsuggest) && (! $followup)) {
 +                      if((! $mail) && (! $fsuggest) && (!$relocate) && (! $followup)) {
  
                                $this_batch[] = $contact['id'];
  
  
                        $deliver_status = 0;
  
 -                      logger("main delivery by notifier: followup=$followup mail=$mail fsuggest=$fsuggest");
 +                      logger("main delivery by notifier: followup=$followup mail=$mail fsuggest=$fsuggest relocate=$relocate");
  
                        switch($contact['network']) {
                                case NETWORK_DFRN:
                                                        AND `contact`.`pending` = 0
                                                        AND `contact`.`network` = '%s' AND `user`.`nickname` = '%s'
                                                        $sql_extra
-                                                       AND `user`.`account_expired` = 0 LIMIT 1",
+                                                       AND `user`.`account_expired` = 0 AND `user`.`account_removed` = 0 LIMIT 1",
                                                        dbesc(NETWORK_DFRN),
                                                        dbesc($nickname)
                                                );
        return;
  }
  
 +
  if (array_search(__file__,get_included_files())===0){
    notifier_run($argv,$argc);
    killme();
diff --combined include/onepoll.php
index b7199deb616090d6fc36fdbfb49fd88409325df0,9fbef168c6fa4d594f1fc875ce430794c616b959..019455e820350cd98b996784286a4e13e281e558
@@@ -2,7 -2,7 +2,7 @@@
  
  require_once("boot.php");
  
 -function onepoll_run($argv, $argc){
 +function onepoll_run(&$argv, &$argc){
        global $a, $db;
  
        if(is_null($a)) {
                                logger("Mail: Parsing ".count($msgs)." mails for ".$mailconf[0]['user'], LOGGER_DEBUG);
  
                                $metas = email_msg_meta($mbox,implode(',',$msgs));
+                               if(count($metas) != count($msgs)) {
+                                       logger("onepoll: for " . $mailconf[0]['user'] . " there are ". count($msgs) . " messages but received " . count($metas) . " metas", LOGGER_DEBUG);
+                                       break;
+                               }
                                $msgs = array_combine($msgs, $metas);
                                foreach($msgs as $msg_uid => $meta) {
                                        logger("Mail: Parsing mail ".$msg_uid, LOGGER_DATA);
  
                                        );
  
                                        if(count($r)) {
-                                               logger("Mail: Seen before ".$msg_uid." for ".$mailconf[0]['user']);
+                                               logger("Mail: Seen before ".$msg_uid." for ".$mailconf[0]['user'],LOGGER_DEBUG);
                                                if($meta->deleted && ! $r[0]['deleted']) {
                                                        q("UPDATE `item` SET `deleted` = 1, `changed` = '%s' WHERE `id` = %d LIMIT 1",
                                                                dbesc(datetime_convert()),
diff --combined include/poller.php
index 235603979dbf6f8b9b0630d92b18f17848f5bed5,1af23eb13bae095b7422121b3667557e07aa55e8..d5efa36a832b42544b9840ba134589d14286c75b
@@@ -3,7 -3,7 +3,7 @@@
  require_once("boot.php");
  
  
 -function poller_run($argv, $argc){
 +function poller_run(&$argv, &$argc){
        global $a, $db;
  
        if(is_null($a)) {
        q("UPDATE user SET `account_expired` = 1 where `account_expired` = 0 
                AND `account_expires_on` != '0000-00-00 00:00:00' 
                AND `account_expires_on` < UTC_TIMESTAMP() ");
+       
+       // delete user and contact records for recently removed accounts
+       $r = q("SELECT * FROM `user` WHERE `account_removed` = 1 AND `account_expires_on` < UTC_TIMESTAMP() - INTERVAL 3 DAY");
+       if ($r) {
+               foreach($r as $user) {
+                       q("DELETE FROM `contact` WHERE `uid` = %d", intval($user['uid']));
+                       q("DELETE FROM `user` WHERE `uid` = %d", intval($user['uid']));
+               }
+       }
    
        $abandon_days = intval(get_config('system','account_abandon_days'));
        if($abandon_days < 1)
                $sql_extra 
                AND `self` = 0 AND `contact`.`blocked` = 0 AND `contact`.`readonly` = 0 
                AND `contact`.`archive` = 0 
-               AND `user`.`account_expired` = 0 $abandon_sql ORDER BY RAND()",
+               AND `user`.`account_expired` = 0 AND `user`.`account_removed` = 0 $abandon_sql ORDER BY RAND()",
                intval(CONTACT_IS_SHARING),
                intval(CONTACT_IS_FRIEND),
                dbesc(NETWORK_DIASPORA),
diff --combined mod/dfrn_notify.php
index b50602b6bda6c4cd6de0dac55576ac9302bb3ada,476212b7afdb17624ac4a2090836915322101160..44761be153855ab5f23b4557d0897091352bc9e7
@@@ -6,7 -6,7 +6,7 @@@ require_once('include/event.php')
  
  
  function dfrn_notify_post(&$a) {
 -
 +    logger(__function__, LOGGER_TRACE);
        $dfrn_id      = ((x($_POST,'dfrn_id'))      ? notags(trim($_POST['dfrn_id']))   : '');
        $dfrn_version = ((x($_POST,'dfrn_version')) ? (float) $_POST['dfrn_version']    : 2.0);
        $challenge    = ((x($_POST,'challenge'))    ? notags(trim($_POST['challenge'])) : '');
@@@ -77,7 -77,7 +77,7 @@@
                        FROM `contact` 
                        LEFT JOIN `user` ON `contact`.`uid` = `user`.`uid` 
                        WHERE `contact`.`blocked` = 0 AND `contact`.`pending` = 0 
-                               AND `user`.`nickname` = '%s' AND `user`.`account_expired` = 0 $sql_extra LIMIT 1",
+                               AND `user`.`nickname` = '%s' AND `user`.`account_expired` = 0 AND `user`.`account_removed` = 0 $sql_extra LIMIT 1",
                dbesc($a->argv[1])
        );
  
@@@ -220,7 -220,7 +220,7 @@@ function dfrn_notify_content(&$a) 
  
                $r = q("SELECT `contact`.*, `user`.`nickname`, `user`.`page-flags` FROM `contact` LEFT JOIN `user` ON `user`.`uid` = `contact`.`uid` 
                                WHERE `contact`.`blocked` = 0 AND `contact`.`pending` = 0 AND `user`.`nickname` = '%s' 
-                               AND `user`.`account_expired` = 0 $sql_extra LIMIT 1",
+                               AND `user`.`account_expired` = 0 AND `user`.`account_removed` = 0 $sql_extra LIMIT 1",
                                dbesc($a->argv[1])
                );