<?php
-use \Friendica\Core\Config;
+use Friendica\Core\Config;
-require_once("boot.php");
-require_once("include/follow.php");
+require_once('include/follow.php');
function RemoveReply($subject) {
while (in_array(strtolower(substr($subject, 0, 3)), array("re:", "aw:")))
}
function onepoll_run(&$argv, &$argc){
- global $a, $db;
+ global $a;
- if (is_null($a)) {
- $a = new App;
- }
-
- if (is_null($db)) {
- @include(".htconfig.php");
- require_once("include/dba.php");
- $db = new dba($db_host, $db_user, $db_pass, $db_data);
- unset($db_host, $db_user, $db_pass, $db_data);
- };
-
- require_once('include/session.php');
require_once('include/datetime.php');
require_once('include/items.php');
require_once('include/Contact.php');
require_once('include/socgraph.php');
require_once('include/queue_fn.php');
- Config::load();
-
- $a->set_baseurl(get_config('system','url'));
-
- load_hooks();
-
logger('onepoll: start');
$manual_id = 0;
return;
}
- // Don't check this stuff if the function is called by the poller
- if (App::callstack() != "poller_run") {
- if (App::is_already_running('onepoll'.$contact_id, '', 540)) {
- return;
- }
- }
-
$d = datetime_convert();
// Only poll from those with suitable relationships,
$contact = $contacts[0];
// load current friends if possible.
- if (($contact['poco'] != "") AND ($contact['success_update'] > $contact['failure_update'])) {
- $r = q("SELECT count(*) as total from glink
- where `cid` = %d and updated > UTC_TIMESTAMP() - INTERVAL 1 DAY",
+ if (($contact['poco'] != "") && ($contact['success_update'] > $contact['failure_update'])) {
+ $r = q("SELECT count(*) AS total FROM glink
+ WHERE `cid` = %d AND updated > UTC_TIMESTAMP() - INTERVAL 1 DAY",
intval($contact['id'])
);
if (dbm::is_result($r)) {
logger("onepoll: poll: ({$contact['id']}) IMPORTER: {$importer['name']}, CONTACT: {$contact['name']}");
- $last_update = (($contact['last-update'] === '0000-00-00 00:00:00')
+ $last_update = (($contact['last-update'] <= NULL_DATE)
? datetime_convert('UTC','UTC','now - 7 days', ATOM_TIME)
: datetime_convert('UTC','UTC',$contact['last-update'], ATOM_TIME)
);
// But this may be our first communication, so set the writable flag if it isn't set already.
if (! intval($contact['writable'])) {
- q("update contact set writable = 1 where id = %d", intval($contact['id']));
+ q("UPDATE `contact` SET `writable` = 1 WHERE `id` = %d", intval($contact['id']));
}
$url = $contact['poll'] . '?dfrn_id=' . $idtosend
intval($contact['id'])
);
mark_for_death($contact);
- } elseif ($contact['term-date'] != '0000-00-00 00:00:00') {
+ } elseif ($contact['term-date'] > NULL_DATE) {
logger("poller: $url back from the dead - removing mark for death");
unmark_for_death($contact);
}
unlink($cookiejar);
} elseif ($contact['network'] === NETWORK_MAIL || $contact['network'] === NETWORK_MAIL2) {
- logger("Mail: Fetching", LOGGER_DEBUG);
+ logger("Mail: Fetching for ".$contact['addr'], LOGGER_DEBUG);
$mail_disabled = ((function_exists('imap_open') && (! get_config('system','imap_disabled'))) ? 0 : 1);
if ($mail_disabled)
}
if ($mbox) {
- $msgs = email_poll($mbox,$contact['addr']);
+ $msgs = email_poll($mbox, $contact['addr']);
if (count($msgs)) {
- logger("Mail: Parsing ".count($msgs)." mails for ".$mailconf[0]['user'], LOGGER_DEBUG);
+ logger("Mail: Parsing ".count($msgs)." mails from ".$contact['addr']." for ".$mailconf[0]['user'], LOGGER_DEBUG);
$metas = email_msg_meta($mbox,implode(',',$msgs));
if (count($metas) != count($msgs)) {
logger("Mail: Seen before ".$msg_uid." for ".$mailconf[0]['user']." UID: ".$importer_uid." URI: ".$datarray['uri'],LOGGER_DEBUG);
// Only delete when mails aren't automatically moved or deleted
- if (($mailconf[0]['action'] != 1) AND ($mailconf[0]['action'] != 3))
+ if (($mailconf[0]['action'] != 1) && ($mailconf[0]['action'] != 3))
if ($meta->deleted && ! $r[0]['deleted']) {
q("UPDATE `item` SET `deleted` = 1, `changed` = '%s' WHERE `id` = %d",
dbesc(datetime_convert()),
if ($raw_refs) {
$refs_arr = explode(' ', $raw_refs);
if (count($refs_arr)) {
- for($x = 0; $x < count($refs_arr); $x ++)
+ for ($x = 0; $x < count($refs_arr); $x ++) {
$refs_arr[$x] = "'" . msgid2iri(str_replace(array('<','>',' '),array('','',''),dbesc($refs_arr[$x]))) . "'";
+ }
}
$qstr = implode(',',$refs_arr);
$r = q("SELECT `uri` , `parent-uri` FROM `item` USE INDEX (`uid_uri`) WHERE `uri` IN ($qstr) AND `uid` = %d LIMIT 1",
intval($importer_uid)
);
- if (dbm::is_result($r))
+ if (dbm::is_result($r)) {
$datarray['parent-uri'] = $r[0]['parent-uri']; // Set the parent as the top-level item
- // $datarray['parent-uri'] = $r[0]['uri'];
+ //$datarray['parent-uri'] = $r[0]['uri'];
+ }
}
// Decoding the header
$datarray['created'] = datetime_convert('UTC','UTC',$meta->date);
// Is it a reply?
- $reply = ((substr(strtolower($datarray['title']), 0, 3) == "re:") or
- (substr(strtolower($datarray['title']), 0, 3) == "re-") or
+ $reply = ((substr(strtolower($datarray['title']), 0, 3) == "re:") ||
+ (substr(strtolower($datarray['title']), 0, 3) == "re-") ||
($raw_refs != ""));
// Remove Reply-signs in the subject
$datarray['title'] = RemoveReply($datarray['title']);
// If it seems to be a reply but a header couldn't be found take the last message with matching subject
- if (!x($datarray,'parent-uri') and $reply) {
+ if (!x($datarray,'parent-uri') && $reply) {
$r = q("SELECT `uri` , `parent-uri` FROM `item` WHERE `title` = \"%s\" AND `uid` = %d AND `network` = '%s' ORDER BY `created` DESC LIMIT 1",
dbesc(protect_sprintf($datarray['title'])),
intval($importer_uid),
logger("Mail: Importing ".$msg_uid." for ".$mailconf[0]['user']);
- // some mailing lists have the original author as 'from' - add this sender info to msg body.
/// @TODO Adding a gravatar for the original author would be cool
- if (! stristr($meta->from,$contact['addr'])) {
- $from = imap_mime_header_decode($meta->from);
- $fromdecoded = "";
- foreach ($from as $frompart) {
- if ($frompart->charset != "default") {
- $fromdecoded .= iconv($frompart->charset, 'UTF-8//IGNORE', $frompart->text);
- } else {
- $fromdecoded .= $frompart->text;
- }
- }
-
- $fromarr = imap_rfc822_parse_adrlist($fromdecoded, $a->get_hostname());
-
- $frommail = $fromarr[0]->mailbox."@".$fromarr[0]->host;
-
- if (isset($fromarr[0]->personal)) {
- $fromname = $fromarr[0]->personal;
+ $from = imap_mime_header_decode($meta->from);
+ $fromdecoded = "";
+ foreach ($from as $frompart) {
+ if ($frompart->charset != "default") {
+ $fromdecoded .= iconv($frompart->charset, 'UTF-8//IGNORE', $frompart->text);
} else {
- $fromname = $frommail;
+ $fromdecoded .= $frompart->text;
}
+ }
- //$datarray['body'] = "[b]".t('From: ') . escape_tags($fromdecoded) . "[/b]\n\n" . $datarray['body'];
-
- $datarray['author-name'] = $fromname;
- $datarray['author-link'] = "mailto:".$frommail;
- $datarray['author-avatar'] = $contact['photo'];
+ $fromarr = imap_rfc822_parse_adrlist($fromdecoded, $a->get_hostname());
- $datarray['owner-name'] = $contact['name'];
- $datarray['owner-link'] = "mailto:".$contact['addr'];
- $datarray['owner-avatar'] = $contact['photo'];
+ $frommail = $fromarr[0]->mailbox."@".$fromarr[0]->host;
+ if (isset($fromarr[0]->personal)) {
+ $fromname = $fromarr[0]->personal;
} else {
- $datarray['author-name'] = $contact['name'];
- $datarray['author-link'] = 'mailbox';
- $datarray['author-avatar'] = $contact['photo'];
+ $fromname = $frommail;
}
+ $datarray['author-name'] = $fromname;
+ $datarray['author-link'] = "mailto:".$frommail;
+ $datarray['author-avatar'] = $contact['photo'];
+
+ $datarray['owner-name'] = $contact['name'];
+ $datarray['owner-link'] = "mailto:".$contact['addr'];
+ $datarray['owner-avatar'] = $contact['photo'];
+
$datarray['uid'] = $importer_uid;
$datarray['contact-id'] = $contact['id'];
if ($datarray['parent-uri'] === $datarray['uri'])
consume_feed($xml,$importer,$contact,$hub,1,2);
$hubmode = 'subscribe';
- if ($contact['network'] === NETWORK_DFRN || $contact['blocked'] || $contact['readonly'])
+ if ($contact['network'] === NETWORK_DFRN || $contact['blocked'] || $contact['readonly']) {
$hubmode = 'unsubscribe';
+ }
- if (($contact['network'] === NETWORK_OSTATUS || $contact['network'] == NETWORK_FEED) && (! $contact['hub-verify']))
+ if (($contact['network'] === NETWORK_OSTATUS || $contact['network'] == NETWORK_FEED) && (! $contact['hub-verify'])) {
$hub_update = true;
+ }
- if ($force)
+ if ($force) {
$hub_update = true;
+ }
logger("Contact ".$contact['id']." returned hub: ".$hub." Network: ".$contact['network']." Relation: ".$contact['rel']." Update: ".$hub_update);
return;
}
-
-if (array_search(__file__,get_included_files())===0) {
- onepoll_run($_SERVER["argv"],$_SERVER["argc"]);
- killme();
-}