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 );
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);
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__)));
}
}
return $pageURL;
}
+ function random_digits($digits) {
+ $rn = '';
+ for($i = 0; $i < $digits; $i++) {
+ $rn .= rand(0,9);
+ }
+ return $rn;
+ }
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)
);
}
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
// 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
}
<?php
-
require_once("boot.php");
require_once('include/queue_fn.php');
require_once('include/html2plain.php');
*/
-function notifier_run($argv, $argc){
+function notifier_run(&$argv, &$argc){
global $a, $db;
if(is_null($a)){
$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();
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()),
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),
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'])) : '');
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])
);
$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])
);