function probe_url($url, $mode = PROBE_NORMAL) { require_once 'include/email.php'; $result = array(); if (!$url) { return $result; } $network = null; $diaspora = false; $diaspora_base = ''; $diaspora_guid = ''; $diaspora_key = ''; $has_lrdd = false; $email_conversant = false; $twitter = strpos($url, 'twitter.com') !== false ? true : false; $at_addr = strpos($url, '@') !== false ? true : false; if (!$twitter) { if (strpos($url, 'mailto:') !== false && $at_addr) { $url = str_replace('mailto:', '', $url); $links = array(); } else { $links = lrdd($url); } if (count($links)) { $has_lrdd = true; logger('probe_url: found lrdd links: ' . print_r($links, true), LOGGER_DATA); foreach ($links as $link) { if ($link['@attributes']['rel'] === NAMESPACE_ZOT) { $zot = unamp($link['@attributes']['href']); } if ($link['@attributes']['rel'] === NAMESPACE_DFRN) { $dfrn = unamp($link['@attributes']['href']); } if ($link['@attributes']['rel'] === 'salmon') { $notify = unamp($link['@attributes']['href']); } if ($link['@attributes']['rel'] === NAMESPACE_FEED) { $poll = unamp($link['@attributes']['href']); } if ($link['@attributes']['rel'] === 'http://microformats.org/profile/hcard') { $hcard = unamp($link['@attributes']['href']); } if ($link['@attributes']['rel'] === 'http://webfinger.net/rel/profile-page') { $profile = unamp($link['@attributes']['href']); } if ($link['@attributes']['rel'] === 'http://portablecontacts.net/spec/1.0') { $poco = unamp($link['@attributes']['href']); } if ($link['@attributes']['rel'] === 'http://joindiaspora.com/seed_location') { $diaspora_base = unamp($link['@attributes']['href']); $diaspora = true; } if ($link['@attributes']['rel'] === 'http://joindiaspora.com/guid') { $diaspora_guid = unamp($link['@attributes']['href']); $diaspora = true; } if ($link['@attributes']['rel'] === 'diaspora-public-key') { $diaspora_key = base64_decode(unamp($link['@attributes']['href'])); $pubkey = rsatopem($diaspora_key); $diaspora = true; } } // Status.Net can have more than one profile URL. We need to match the profile URL // to a contact on incoming messages to prevent spam, and we won't know which one // to match. So in case of two, one of them is stored as an alias. Only store URL's // and not webfinger user@host aliases. If they've got more than two non-email style // aliases, let's hope we're lucky and get one that matches the feed author-uri because // otherwise we're screwed. foreach ($links as $link) { if ($link['@attributes']['rel'] === 'alias') { if (strpos($link['@attributes']['href'], '@') === false) { if (isset($profile)) { if ($link['@attributes']['href'] !== $profile) { $alias = unamp($link['@attributes']['href']); } } else { $profile = unamp($link['@attributes']['href']); } } } } } elseif ($mode == PROBE_NORMAL) { // Check email $orig_url = $url; if (strpos($orig_url, '@') && validate_email($orig_url)) { $x = q("SELECT `prvkey` FROM `user` WHERE `uid` = %d LIMIT 1", intval(local_user())); $r = q("SELECT * FROM `mailacct` WHERE `uid` = %d AND `server` != '' LIMIT 1", intval(local_user())); if (count($x) && count($r)) { $mailbox = construct_mailbox_name($r[0]); $password = ''; openssl_private_decrypt(hex2bin($r[0]['pass']), $password, $x[0]['prvkey']); $mbox = email_connect($mailbox, $r[0]['user'], $password); if (!$mbox) { logger('probe_url: email_connect failed.'); } unset($password); } if ($mbox) { $msgs = email_poll($mbox, $orig_url); logger('probe_url: searching ' . $orig_url . ', ' . count($msgs) . ' messages found.', LOGGER_DEBUG); if (count($msgs)) { $addr = $orig_url; $network = NETWORK_MAIL; $name = substr($url, 0, strpos($url, '@')); $phost = substr($url, strpos($url, '@') + 1); $profile = 'http://' . $phost; // fix nick character range $vcard = array('fn' => $name, 'nick' => $name, 'photo' => avatar_img($url)); $notify = 'smtp ' . random_string(); $poll = 'email ' . random_string(); $priority = 0; $x = email_msg_meta($mbox, $msgs[0]); if (stristr($x->from, $orig_url)) { $adr = imap_rfc822_parse_adrlist($x->from, ''); } elseif (stristr($x->to, $orig_url)) { $adr = imap_rfc822_parse_adrlist($x->to, ''); } if (isset($adr)) { foreach ($adr as $feadr) { if (strcasecmp($feadr->mailbox, $name) == 0 && strcasecmp($feadr->host, $phost) == 0 && strlen($feadr->personal)) { $personal = imap_mime_header_decode($feadr->personal); $vcard['fn'] = ""; foreach ($personal as $perspart) { if ($perspart->charset != "default") { $vcard['fn'] .= iconv($perspart->charset, 'UTF-8//IGNORE', $perspart->text); } else { $vcard['fn'] .= $perspart->text; } } $vcard['fn'] = notags($vcard['fn']); } } } } imap_close($mbox); } } } } if ($mode == PROBE_NORMAL) { if (strlen($zot)) { $s = fetch_url($zot); if ($s) { $j = json_decode($s); if ($j) { $network = NETWORK_ZOT; $vcard = array('fn' => $j->fullname, 'nick' => $j->nickname, 'photo' => $j->photo); $profile = $j->url; $notify = $j->post; $pubkey = $j->pubkey; $poll = 'N/A'; } } } if (strlen($dfrn)) { $ret = scrape_dfrn($hcard ? $hcard : $dfrn); if (is_array($ret) && x($ret, 'dfrn-request')) { $network = NETWORK_DFRN; $request = $ret['dfrn-request']; $confirm = $ret['dfrn-confirm']; $notify = $ret['dfrn-notify']; $poll = $ret['dfrn-poll']; $vcard = array(); $vcard['fn'] = $ret['fn']; $vcard['nick'] = $ret['nick']; $vcard['photo'] = $ret['photo']; } } } if ($diaspora && $diaspora_base && $diaspora_guid) { if ($mode == PROBE_DIASPORA || !$notify) { $notify = $diaspora_base . 'receive/users/' . $diaspora_guid; $batch = $diaspora_base . 'receive/public'; } if (strpos($url, '@')) { $addr = str_replace('acct:', '', $url); } } if ($network !== NETWORK_ZOT && $network !== NETWORK_DFRN && $network !== NETWORK_MAIL) { if ($diaspora) { $network = NETWORK_DIASPORA; } elseif ($has_lrdd) { $network = NETWORK_OSTATUS; } $priority = 0; if ($hcard && !$vcard) { $vcard = scrape_vcard($hcard); // Google doesn't use absolute url in profile photos if (x($vcard, 'photo') && substr($vcard['photo'], 0, 1) == '/') { $h = @parse_url($hcard); if ($h) { $vcard['photo'] = $h['scheme'] . '://' . $h['host'] . $vcard['photo']; } } logger('probe_url: scrape_vcard: ' . print_r($vcard, true), LOGGER_DATA); } if ($twitter) { logger('twitter: setup'); $tid = basename($url); $tapi = 'https://api.twitter.com/1/statuses/user_timeline.rss'; if (intval($tid)) { $poll = $tapi . '?user_id=' . $tid; } else { $poll = $tapi . '?screen_name=' . $tid; } $profile = 'http://twitter.com/#!/' . $tid; $vcard['photo'] = 'https://api.twitter.com/1/users/profile_image/' . $tid; $vcard['nick'] = $tid; $vcard['fn'] = $tid . '@twitter'; } if (!x($vcard, 'fn')) { if (x($vcard, 'nick')) { $vcard['fn'] = $vcard['nick']; } } $check_feed = false; if ($twitter || !$poll) { $check_feed = true; } if (!isset($vcard) || !x($vcard, 'fn') || !$profile) { $check_feed = true; } if ($at_addr && !count($links)) { $check_feed = false; } if ($check_feed) { $feedret = scrape_feed($poll ? $poll : $url); logger('probe_url: scrape_feed ' . ($poll ? $poll : $url) . ' returns: ' . print_r($feedret, true), LOGGER_DATA); if (count($feedret) && ($feedret['feed_atom'] || $feedret['feed_rss'])) { $poll = x($feedret, 'feed_atom') ? unamp($feedret['feed_atom']) : unamp($feedret['feed_rss']); if (!x($vcard)) { $vcard = array(); } } if (x($feedret, 'photo') && !x($vcard, 'photo')) { $vcard['photo'] = $feedret['photo']; } require_once 'library/simplepie/simplepie.inc'; $feed = new SimplePie(); $xml = fetch_url($poll); logger('probe_url: fetch feed: ' . $poll . ' returns: ' . $xml, LOGGER_DATA); $a = get_app(); logger('probe_url: scrape_feed: headers: ' . $a->get_curl_headers(), LOGGER_DATA); $feed->set_raw_data($xml); $feed->init(); if ($feed->error()) { logger('probe_url: scrape_feed: Error parsing XML: ' . $feed->error()); } if (!x($vcard, 'photo')) { $vcard['photo'] = $feed->get_image_url(); } $author = $feed->get_author(); if ($author) { $vcard['fn'] = unxmlify(trim($author->get_name())); if (!$vcard['fn']) { $vcard['fn'] = trim(unxmlify($author->get_email())); } if (strpos($vcard['fn'], '@') !== false) { $vcard['fn'] = substr($vcard['fn'], 0, strpos($vcard['fn'], '@')); } $email = unxmlify($author->get_email()); if (!$profile && $author->get_link()) { $profile = trim(unxmlify($author->get_link())); } if (!$vcard['photo']) { $rawtags = $feed->get_feed_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'author'); if ($rawtags) { $elems = $rawtags[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]; if (x($elems, 'link') && $elems['link'][0]['attribs']['']['rel'] === 'photo') { $vcard['photo'] = $elems['link'][0]['attribs']['']['href']; } } } } else { $item = $feed->get_item(0); if ($item) { $author = $item->get_author(); if ($author) { $vcard['fn'] = trim(unxmlify($author->get_name())); if (!$vcard['fn']) { $vcard['fn'] = trim(unxmlify($author->get_email())); } if (strpos($vcard['fn'], '@') !== false) { $vcard['fn'] = substr($vcard['fn'], 0, strpos($vcard['fn'], '@')); } $email = unxmlify($author->get_email()); if (!$profile && $author->get_link()) { $profile = trim(unxmlify($author->get_link())); } } if (!$vcard['photo']) { $rawmedia = $item->get_item_tags('http://search.yahoo.com/mrss/', 'thumbnail'); if ($rawmedia && $rawmedia[0]['attribs']['']['url']) { $vcard['photo'] = unxmlify($rawmedia[0]['attribs']['']['url']); } } if (!$vcard['photo']) { $rawtags = $item->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'author'); if ($rawtags) { $elems = $rawtags[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]; if (x($elems, 'link') && $elems['link'][0]['attribs']['']['rel'] === 'photo') { $vcard['photo'] = $elems['link'][0]['attribs']['']['href']; } } } } } if (!$vcard['photo'] && strlen($email)) { $vcard['photo'] = avatar_img($email); } if ($poll === $profile) { $lnk = $feed->get_permalink(); } if (isset($lnk) && strlen($lnk)) { $profile = $lnk; } if (!x($vcard, 'fn')) { $vcard['fn'] = notags($feed->get_title()); } if (!x($vcard, 'fn')) { $vcard['fn'] = notags($feed->get_description()); } if (strpos($vcard['fn'], 'Twitter / ') !== false) { $vcard['fn'] = substr($vcard['fn'], strpos($vcard['fn'], '/') + 1); $vcard['fn'] = trim($vcard['fn']); } if (!x($vcard, 'nick')) { $vcard['nick'] = strtolower(notags(unxmlify($vcard['fn']))); if (strpos($vcard['nick'], ' ')) { $vcard['nick'] = trim(substr($vcard['nick'], 0, strpos($vcard['nick'], ' '))); } } if (!$network) { $network = NETWORK_FEED; } if (!$priority) { $priority = 2; } } } if (!x($vcard, 'photo')) { $a = get_app(); $vcard['photo'] = $a->get_baseurl() . '/images/person-175.jpg'; } if (!$profile) { $profile = $url; } // No human could be associated with this link, use the URL as the contact name if ($network === NETWORK_FEED && $poll && !x($vcard, 'fn')) { $vcard['fn'] = $url; } $vcard['fn'] = notags($vcard['fn']); $vcard['nick'] = str_replace(' ', '', notags($vcard['nick'])); $result['name'] = $vcard['fn']; $result['nick'] = $vcard['nick']; $result['url'] = $profile; $result['addr'] = $addr; $result['batch'] = $batch; $result['notify'] = $notify; $result['poll'] = $poll; $result['request'] = $request; $result['confirm'] = $confirm; $result['poco'] = $poco; $result['photo'] = $vcard['photo']; $result['priority'] = $priority; $result['network'] = $network; $result['alias'] = $alias; $result['pubkey'] = $pubkey; logger('probe_url: ' . print_r($result, true), LOGGER_DEBUG); return $result; }
function settings_post(&$a) { if (!local_user()) { return; } if (x($_SESSION, 'submanage') && intval($_SESSION['submanage'])) { return; } if (count($a->user) && x($a->user, 'uid') && $a->user['uid'] != local_user()) { notice(t('Permission denied.') . EOL); return; } $old_page_flags = $a->user['page-flags']; if ($a->argc > 1 && $a->argv[1] === 'oauth' && x($_POST, 'remove')) { check_form_security_token_redirectOnErr('/settings/oauth', 'settings_oauth'); $key = $_POST['remove']; q("DELETE FROM tokens WHERE id='%s' AND uid=%d", dbesc($key), local_user()); goaway($a->get_baseurl(true) . "/settings/oauth/"); return; } if ($a->argc > 2 && $a->argv[1] === 'oauth' && ($a->argv[2] === 'edit' || $a->argv[2] === 'add') && x($_POST, 'submit')) { check_form_security_token_redirectOnErr('/settings/oauth', 'settings_oauth'); $name = x($_POST, 'name') ? $_POST['name'] : ''; $key = x($_POST, 'key') ? $_POST['key'] : ''; $secret = x($_POST, 'secret') ? $_POST['secret'] : ''; $redirect = x($_POST, 'redirect') ? $_POST['redirect'] : ''; $icon = x($_POST, 'icon') ? $_POST['icon'] : ''; if ($name == "" || $key == "" || $secret == "") { notice(t("Missing some important data!")); } else { if ($_POST['submit'] == t("Update")) { $r = q("UPDATE clients SET\n\t\t\t\t\t\t\tclient_id='%s',\n\t\t\t\t\t\t\tpw='%s',\n\t\t\t\t\t\t\tname='%s',\n\t\t\t\t\t\t\tredirect_uri='%s',\n\t\t\t\t\t\t\ticon='%s',\n\t\t\t\t\t\t\tuid=%d\n\t\t\t\t\t\tWHERE client_id='%s'", dbesc($key), dbesc($secret), dbesc($name), dbesc($redirect), dbesc($icon), local_user(), dbesc($key)); } else { $r = q("INSERT INTO clients\n\t\t\t\t\t\t\t(client_id, pw, name, redirect_uri, icon, uid)\n\t\t\t\t\t\tVALUES ('%s','%s','%s','%s','%s',%d)", dbesc($key), dbesc($secret), dbesc($name), dbesc($redirect), dbesc($icon), local_user()); } } goaway($a->get_baseurl(true) . "/settings/oauth/"); return; } if ($a->argc > 1 && $a->argv[1] == 'addon') { check_form_security_token_redirectOnErr('/settings/addon', 'settings_addon'); call_hooks('plugin_settings_post', $_POST); return; } if ($a->argc > 1 && $a->argv[1] == 'connectors') { check_form_security_token_redirectOnErr('/settings/connectors', 'settings_connectors'); if (x($_POST, 'imap-submit')) { $mail_server = x($_POST, 'mail_server') ? $_POST['mail_server'] : ''; $mail_port = x($_POST, 'mail_port') ? $_POST['mail_port'] : ''; $mail_ssl = x($_POST, 'mail_ssl') ? strtolower(trim($_POST['mail_ssl'])) : ''; $mail_user = x($_POST, 'mail_user') ? $_POST['mail_user'] : ''; $mail_pass = x($_POST, 'mail_pass') ? trim($_POST['mail_pass']) : ''; $mail_action = x($_POST, 'mail_action') ? trim($_POST['mail_action']) : ''; $mail_movetofolder = x($_POST, 'mail_movetofolder') ? trim($_POST['mail_movetofolder']) : ''; $mail_replyto = x($_POST, 'mail_replyto') ? $_POST['mail_replyto'] : ''; $mail_pubmail = x($_POST, 'mail_pubmail') ? $_POST['mail_pubmail'] : ''; $mail_disabled = function_exists('imap_open') && !get_config('system', 'imap_disabled') ? 0 : 1; if (get_config('system', 'dfrn_only')) { $mail_disabled = 1; } if (!$mail_disabled) { $failed = false; $r = q("SELECT * FROM `mailacct` WHERE `uid` = %d LIMIT 1", intval(local_user())); if (!count($r)) { q("INSERT INTO `mailacct` (`uid`) VALUES (%d)", intval(local_user())); } if (strlen($mail_pass)) { $pass = ''; openssl_public_encrypt($mail_pass, $pass, $a->user['pubkey']); q("UPDATE `mailacct` SET `pass` = '%s' WHERE `uid` = %d", dbesc(bin2hex($pass)), intval(local_user())); } $r = q("UPDATE `mailacct` SET `server` = '%s', `port` = %d, `ssltype` = '%s', `user` = '%s',\n\t\t\t\t\t`action` = %d, `movetofolder` = '%s',\n\t\t\t\t\t`mailbox` = 'INBOX', `reply_to` = '%s', `pubmail` = %d WHERE `uid` = %d", dbesc($mail_server), intval($mail_port), dbesc($mail_ssl), dbesc($mail_user), intval($mail_action), dbesc($mail_movetofolder), dbesc($mail_replyto), intval($mail_pubmail), intval(local_user())); logger("mail: updating mailaccount. Response: " . print_r($r, true)); $r = q("SELECT * FROM `mailacct` WHERE `uid` = %d LIMIT 1", intval(local_user())); if (count($r)) { $eacct = $r[0]; require_once 'include/email.php'; $mb = construct_mailbox_name($eacct); if (strlen($eacct['server'])) { $dcrpass = ''; openssl_private_decrypt(hex2bin($eacct['pass']), $dcrpass, $a->user['prvkey']); $mbox = email_connect($mb, $mail_user, $dcrpass); unset($dcrpass); if (!$mbox) { $failed = true; notice(t('Failed to connect with email account using the settings provided.') . EOL); } } } if (!$failed) { info(t('Email settings updated.') . EOL); } } } call_hooks('connector_settings_post', $_POST); return; } if ($a->argc > 1 && $a->argv[1] === 'features') { check_form_security_token_redirectOnErr('/settings/features', 'settings_features'); foreach ($_POST as $k => $v) { if (strpos($k, 'feature_') === 0) { set_pconfig(local_user(), 'feature', substr($k, 8), intval($v) ? 1 : 0); } } info(t('Features updated') . EOL); return; } if ($a->argc > 1 && $a->argv[1] === 'display') { check_form_security_token_redirectOnErr('/settings/display', 'settings_display'); $theme = x($_POST, 'theme') ? notags(trim($_POST['theme'])) : $a->user['theme']; $mobile_theme = x($_POST, 'mobile_theme') ? notags(trim($_POST['mobile_theme'])) : ''; $nosmile = x($_POST, 'nosmile') ? intval($_POST['nosmile']) : 0; $noinfo = x($_POST, 'noinfo') ? intval($_POST['noinfo']) : 0; $infinite_scroll = x($_POST, 'infinite_scroll') ? intval($_POST['infinite_scroll']) : 0; $no_auto_update = x($_POST, 'no_auto_update') ? intval($_POST['no_auto_update']) : 0; $browser_update = x($_POST, 'browser_update') ? intval($_POST['browser_update']) : 0; $browser_update = $browser_update * 1000; if ($browser_update < 10000) { $browser_update = 10000; } $itemspage_network = x($_POST, 'itemspage_network') ? intval($_POST['itemspage_network']) : 40; if ($itemspage_network > 100) { $itemspage_network = 100; } $itemspage_mobile_network = x($_POST, 'itemspage_mobile_network') ? intval($_POST['itemspage_mobile_network']) : 20; if ($itemspage_mobile_network > 100) { $itemspage_mobile_network = 100; } if ($mobile_theme !== '') { set_pconfig(local_user(), 'system', 'mobile_theme', $mobile_theme); } set_pconfig(local_user(), 'system', 'update_interval', $browser_update); set_pconfig(local_user(), 'system', 'itemspage_network', $itemspage_network); set_pconfig(local_user(), 'system', 'itemspage_mobile_network', $itemspage_mobile_network); set_pconfig(local_user(), 'system', 'no_smilies', $nosmile); set_pconfig(local_user(), 'system', 'ignore_info', $noinfo); set_pconfig(local_user(), 'system', 'infinite_scroll', $infinite_scroll); set_pconfig(local_user(), 'system', 'no_auto_update', $no_auto_update); if ($theme == $a->user['theme']) { // call theme_post only if theme has not been changed if (($themeconfigfile = get_theme_config_file($theme)) != null) { require_once $themeconfigfile; theme_post($a); } } $r = q("UPDATE `user` SET `theme` = '%s' WHERE `uid` = %d", dbesc($theme), intval(local_user())); call_hooks('display_settings_post', $_POST); goaway($a->get_baseurl(true) . '/settings/display'); return; // NOTREACHED } check_form_security_token_redirectOnErr('/settings', 'settings'); if (x($_POST, 'resend_relocate')) { proc_run('php', 'include/notifier.php', 'relocate', local_user()); info(t("Relocate message has been send to your contacts")); goaway($a->get_baseurl(true) . '/settings'); } call_hooks('settings_post', $_POST); if (x($_POST, 'password') || x($_POST, 'confirm')) { $newpass = $_POST['password']; $confirm = $_POST['confirm']; $oldpass = hash('whirlpool', $_POST['opassword']); $err = false; if ($newpass != $confirm) { notice(t('Passwords do not match. Password unchanged.') . EOL); $err = true; } if (!x($newpass) || !x($confirm)) { notice(t('Empty passwords are not allowed. Password unchanged.') . EOL); $err = true; } // check if the old password was supplied correctly before // changing it to the new value $r = q("SELECT `password` FROM `user`WHERE `uid` = %d LIMIT 1", intval(local_user())); if ($oldpass != $r[0]['password']) { notice(t('Wrong password.') . EOL); $err = true; } if (!$err) { $password = hash('whirlpool', $newpass); $r = q("UPDATE `user` SET `password` = '%s' WHERE `uid` = %d", dbesc($password), intval(local_user())); if ($r) { info(t('Password changed.') . EOL); } else { notice(t('Password update failed. Please try again.') . EOL); } } } $username = x($_POST, 'username') ? notags(trim($_POST['username'])) : ''; $email = x($_POST, 'email') ? notags(trim($_POST['email'])) : ''; $timezone = x($_POST, 'timezone') ? notags(trim($_POST['timezone'])) : ''; $defloc = x($_POST, 'defloc') ? notags(trim($_POST['defloc'])) : ''; $openid = x($_POST, 'openid_url') ? notags(trim($_POST['openid_url'])) : ''; $maxreq = x($_POST, 'maxreq') ? intval($_POST['maxreq']) : 0; $expire = x($_POST, 'expire') ? intval($_POST['expire']) : 0; $def_gid = x($_POST, 'group-selection') ? intval($_POST['group-selection']) : 0; $expire_items = x($_POST, 'expire_items') ? intval($_POST['expire_items']) : 0; $expire_notes = x($_POST, 'expire_notes') ? intval($_POST['expire_notes']) : 0; $expire_starred = x($_POST, 'expire_starred') ? intval($_POST['expire_starred']) : 0; $expire_photos = x($_POST, 'expire_photos') ? intval($_POST['expire_photos']) : 0; $expire_network_only = x($_POST, 'expire_network_only') ? intval($_POST['expire_network_only']) : 0; $allow_location = x($_POST, 'allow_location') && intval($_POST['allow_location']) == 1 ? 1 : 0; $publish = x($_POST, 'profile_in_directory') && intval($_POST['profile_in_directory']) == 1 ? 1 : 0; $net_publish = x($_POST, 'profile_in_netdirectory') && intval($_POST['profile_in_netdirectory']) == 1 ? 1 : 0; $old_visibility = x($_POST, 'visibility') && intval($_POST['visibility']) == 1 ? 1 : 0; $page_flags = x($_POST, 'page-flags') && intval($_POST['page-flags']) ? intval($_POST['page-flags']) : 0; $blockwall = x($_POST, 'blockwall') && intval($_POST['blockwall']) == 1 ? 0 : 1; // this setting is inverted! $blocktags = x($_POST, 'blocktags') && intval($_POST['blocktags']) == 1 ? 0 : 1; // this setting is inverted! $unkmail = x($_POST, 'unkmail') && intval($_POST['unkmail']) == 1 ? 1 : 0; $cntunkmail = x($_POST, 'cntunkmail') ? intval($_POST['cntunkmail']) : 0; $suggestme = x($_POST, 'suggestme') ? intval($_POST['suggestme']) : 0; $hide_friends = $_POST['hide-friends'] == 1 ? 1 : 0; $hidewall = $_POST['hidewall'] == 1 ? 1 : 0; $post_newfriend = $_POST['post_newfriend'] == 1 ? 1 : 0; $post_joingroup = $_POST['post_joingroup'] == 1 ? 1 : 0; $post_profilechange = $_POST['post_profilechange'] == 1 ? 1 : 0; $email_textonly = $_POST['email_textonly'] == 1 ? 1 : 0; $notify = 0; if (x($_POST, 'notify1')) { $notify += intval($_POST['notify1']); } if (x($_POST, 'notify2')) { $notify += intval($_POST['notify2']); } if (x($_POST, 'notify3')) { $notify += intval($_POST['notify3']); } if (x($_POST, 'notify4')) { $notify += intval($_POST['notify4']); } if (x($_POST, 'notify5')) { $notify += intval($_POST['notify5']); } if (x($_POST, 'notify6')) { $notify += intval($_POST['notify6']); } if (x($_POST, 'notify7')) { $notify += intval($_POST['notify7']); } if (x($_POST, 'notify8')) { $notify += intval($_POST['notify8']); } $email_changed = false; $err = ''; $name_change = false; if ($username != $a->user['username']) { $name_change = true; if (strlen($username) > 40) { $err .= t(' Please use a shorter name.'); } if (strlen($username) < 3) { $err .= t(' Name too short.'); } } if ($email != $a->user['email']) { $email_changed = true; // check for the correct password $r = q("SELECT `password` FROM `user`WHERE `uid` = %d LIMIT 1", intval(local_user())); $password = hash('whirlpool', $_POST['mpassword']); if ($password != $r[0]['password']) { $err .= t('Wrong Password') . EOL; $email = $a->user['email']; } // check the email is valid if (!valid_email($email)) { $err .= t(' Not valid email.'); } // ensure new email is not the admin mail //if((x($a->config,'admin_email')) && (strcasecmp($email,$a->config['admin_email']) == 0)) { if (x($a->config, 'admin_email')) { $adminlist = explode(",", str_replace(" ", "", strtolower($a->config['admin_email']))); if (in_array(strtolower($email), $adminlist)) { $err .= t(' Cannot change to that email.'); $email = $a->user['email']; } } } if (strlen($err)) { notice($err . EOL); return; } if ($timezone != $a->user['timezone']) { if (strlen($timezone)) { date_default_timezone_set($timezone); } } $str_group_allow = perms2str($_POST['group_allow']); $str_contact_allow = perms2str($_POST['contact_allow']); $str_group_deny = perms2str($_POST['group_deny']); $str_contact_deny = perms2str($_POST['contact_deny']); $openidserver = $a->user['openidserver']; $openid = normalise_openid($openid); // If openid has changed or if there's an openid but no openidserver, try and discover it. if ($openid != $a->user['openid'] || strlen($openid) && !strlen($openidserver)) { $tmp_str = $openid; if (strlen($tmp_str) && validate_url($tmp_str)) { logger('updating openidserver'); require_once 'library/openid.php'; $open_id_obj = new LightOpenID(); $open_id_obj->identity = $openid; $openidserver = $open_id_obj->discover($open_id_obj->identity); } else { $openidserver = ''; } } set_pconfig(local_user(), 'expire', 'items', $expire_items); set_pconfig(local_user(), 'expire', 'notes', $expire_notes); set_pconfig(local_user(), 'expire', 'starred', $expire_starred); set_pconfig(local_user(), 'expire', 'photos', $expire_photos); set_pconfig(local_user(), 'expire', 'network_only', $expire_network_only); set_pconfig(local_user(), 'system', 'suggestme', $suggestme); set_pconfig(local_user(), 'system', 'post_newfriend', $post_newfriend); set_pconfig(local_user(), 'system', 'post_joingroup', $post_joingroup); set_pconfig(local_user(), 'system', 'post_profilechange', $post_profilechange); set_pconfig(local_user(), 'system', 'email_textonly', $email_textonly); if ($page_flags == PAGE_PRVGROUP) { $hidewall = 1; if (!$str_contact_allow && !$str_group_allow && !$str_contact_deny && !$str_group_deny) { if ($def_gid) { info(t('Private forum has no privacy permissions. Using default privacy group.') . EOL); $str_group_allow = '<' . $def_gid . '>'; } else { notice(t('Private forum has no privacy permissions and no default privacy group.') . EOL); } } } $r = q("UPDATE `user` SET `username` = '%s', `email` = '%s', `openid` = '%s', `timezone` = '%s', `allow_cid` = '%s', `allow_gid` = '%s', `deny_cid` = '%s', `deny_gid` = '%s', `notify-flags` = %d, `page-flags` = %d, `default-location` = '%s', `allow_location` = %d, `maxreq` = %d, `expire` = %d, `openidserver` = '%s', `def_gid` = %d, `blockwall` = %d, `hidewall` = %d, `blocktags` = %d, `unkmail` = %d, `cntunkmail` = %d WHERE `uid` = %d", dbesc($username), dbesc($email), dbesc($openid), dbesc($timezone), dbesc($str_contact_allow), dbesc($str_group_allow), dbesc($str_contact_deny), dbesc($str_group_deny), intval($notify), intval($page_flags), dbesc($defloc), intval($allow_location), intval($maxreq), intval($expire), dbesc($openidserver), intval($def_gid), intval($blockwall), intval($hidewall), intval($blocktags), intval($unkmail), intval($cntunkmail), intval(local_user())); if ($r) { info(t('Settings updated.') . EOL); } $r = q("UPDATE `profile`\n\t\tSET `publish` = %d,\n\t\t`name` = '%s',\n\t\t`net-publish` = %d,\n\t\t`hide-friends` = %d\n\t\tWHERE `is-default` = 1 AND `uid` = %d", intval($publish), dbesc($username), intval($net_publish), intval($hide_friends), intval(local_user())); if ($name_change) { q("UPDATE `contact` SET `name` = '%s', `name-date` = '%s' WHERE `uid` = %d AND `self` = 1", dbesc($username), dbesc(datetime_convert()), intval(local_user())); } if ($old_visibility != $net_publish || $page_flags != $old_page_flags) { // Update global directory in background $url = $_SESSION['my_url']; if ($url && strlen(get_config('system', 'directory_submit_url'))) { proc_run('php', "include/directory.php", "{$url}"); } } require_once 'include/profile_update.php'; profile_change(); //$_SESSION['theme'] = $theme; if ($email_changed && $a->config['register_policy'] == REGISTER_VERIFY) { // FIXME - set to un-verified, blocked and redirect to logout // Why? Are we verifying people or email addresses? } goaway($a->get_baseurl(true) . '/settings'); return; // NOTREACHED }
function poller_run($argv, $argc) { global $a, $db; if (is_null($a)) { $a = new App(); } if (is_null($db)) { @(include ".htconfig.php"); require_once "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 'library/simplepie/simplepie.inc'; require_once 'include/items.php'; require_once 'include/Contact.php'; require_once 'include/email.php'; require_once 'include/socgraph.php'; load_config('config'); load_config('system'); $a->set_baseurl(get_config('system', 'url')); load_hooks(); logger('poller: start'); // run queue delivery process in the background proc_run('php', "include/queue.php"); // expire any expired accounts q("UPDATE user SET `account_expired` = 1 where `account_expired` = 0 \n\t\tAND `account_expires_on` != '0000-00-00 00:00:00' \n\t\tAND `account_expires_on` < UTC_TIMESTAMP() "); $abandon_days = intval(get_config('system', 'account_abandon_days')); if ($abandon_days < 1) { $abandon_days = 0; } // once daily run birthday_updates and then expire in background $d1 = get_config('system', 'last_expire_day'); $d2 = intval(datetime_convert('UTC', 'UTC', 'now', 'd')); if ($d2 != intval($d1)) { update_contact_birthdays(); update_suggestions(); set_config('system', 'last_expire_day', $d2); proc_run('php', 'include/expire.php'); } // clear old cache Cache::clear(); $manual_id = 0; $generation = 0; $hub_update = false; $force = false; $restart = false; if ($argc > 1 && $argv[1] == 'force') { $force = true; } if ($argc > 1 && $argv[1] == 'restart') { $restart = true; $generation = intval($argv[2]); if (!$generation) { killme(); } } if ($argc > 1 && intval($argv[1])) { $manual_id = intval($argv[1]); $force = true; } $sql_extra = $manual_id ? " AND `id` = {$manual_id} " : ""; reload_plugins(); $d = datetime_convert(); if (!$restart) { proc_run('php', 'include/cronhooks.php'); } // Only poll from those with suitable relationships, // and which have a polling address and ignore Diaspora since // we are unable to match those posts with a Diaspora GUID and prevent duplicates. $abandon_sql = $abandon_days ? sprintf(" AND `user`.`login_date` > UTC_TIMESTAMP() - INTERVAL %d DAY ", intval($abandon_days)) : ''; $contacts = q("SELECT `contact`.`id` FROM `contact` LEFT JOIN `user` ON `user`.`uid` = `contact`.`uid` \n\t\tWHERE ( `rel` = %d OR `rel` = %d ) AND `poll` != ''\n\t\tAND NOT `network` IN ( '%s', '%s' )\n\t\t{$sql_extra} \n\t\tAND `self` = 0 AND `contact`.`blocked` = 0 AND `contact`.`readonly` = 0 \n\t\tAND `user`.`account_expired` = 0 {$abandon_sql} ORDER BY RAND()", intval(CONTACT_IS_SHARING), intval(CONTACT_IS_FRIEND), dbesc(NETWORK_DIASPORA), dbesc(NETWORK_FACEBOOK)); if (!count($contacts)) { return; } foreach ($contacts as $c) { $res = q("SELECT * FROM `contact` WHERE `id` = %d LIMIT 1", intval($c['id'])); if (!$res || !count($res)) { continue; } foreach ($res as $contact) { $xml = false; if ($manual_id) { $contact['last-update'] = '0000-00-00 00:00:00'; } if ($contact['network'] === NETWORK_DFRN || $contact['network'] === NETWORK_OSTATUS) { $contact['priority'] = 2; } if ($contact['priority'] || $contact['subhub']) { $hub_update = true; $update = false; $t = $contact['last-update']; // We should be getting everything via a hub. But just to be sure, let's check once a day. // (You can make this more or less frequent if desired by setting 'pushpoll_frequency' appropriately) // This also lets us update our subscription to the hub, and add or replace hubs in case it // changed. We will only update hubs once a day, regardless of 'pushpoll_frequency'. if ($contact['subhub']) { $interval = get_config('system', 'pushpoll_frequency'); $contact['priority'] = $interval !== false ? intval($interval) : 3; $hub_update = false; if (datetime_convert('UTC', 'UTC', 'now') > datetime_convert('UTC', 'UTC', $t . " + 1 day") || $force) { $hub_update = true; } } else { $hub_update = false; } /** * Based on $contact['priority'], should we poll this site now? Or later? */ switch ($contact['priority']) { case 5: if (datetime_convert('UTC', 'UTC', 'now') > datetime_convert('UTC', 'UTC', $t . " + 1 month")) { $update = true; } break; case 4: if (datetime_convert('UTC', 'UTC', 'now') > datetime_convert('UTC', 'UTC', $t . " + 1 week")) { $update = true; } break; case 3: if (datetime_convert('UTC', 'UTC', 'now') > datetime_convert('UTC', 'UTC', $t . " + 1 day")) { $update = true; } break; case 2: if (datetime_convert('UTC', 'UTC', 'now') > datetime_convert('UTC', 'UTC', $t . " + 12 hour")) { $update = true; } break; case 1: default: if (datetime_convert('UTC', 'UTC', 'now') > datetime_convert('UTC', 'UTC', $t . " + 1 hour")) { $update = true; } break; } if (!$update && !$force) { continue; } } // Check to see if we are running out of memory - if so spawn a new process and kill this one $avail_memory = return_bytes(ini_get('memory_limit')); $memused = memory_get_peak_usage(true); if (intval($avail_memory)) { if ($memused / $avail_memory > 0.95) { if ($generation + 1 > 10) { logger('poller: maximum number of spawns exceeded. Terminating.'); killme(); } logger('poller: memory exceeded. ' . $memused . ' bytes used. Spawning new poll.'); proc_run('php', 'include/poller.php', 'restart', (string) $generation + 1); killme(); } } $importer_uid = $contact['uid']; $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `self` = 1 LIMIT 1", intval($importer_uid)); if (!count($r)) { continue; } $importer = $r[0]; logger("poller: poll: ({$contact['id']}) IMPORTER: {$importer['name']}, CONTACT: {$contact['name']}"); $last_update = $contact['last-update'] === '0000-00-00 00:00:00' ? datetime_convert('UTC', 'UTC', 'now - 30 days', ATOM_TIME) : datetime_convert('UTC', 'UTC', $contact['last-update'], ATOM_TIME); if ($contact['network'] === NETWORK_DFRN) { $idtosend = $orig_id = $contact['dfrn-id'] ? $contact['dfrn-id'] : $contact['issued-id']; if (intval($contact['duplex']) && $contact['dfrn-id']) { $idtosend = '0:' . $orig_id; } if (intval($contact['duplex']) && $contact['issued-id']) { $idtosend = '1:' . $orig_id; } // they have permission to write to us. We already filtered this in the contact query. $perm = 'rw'; $url = $contact['poll'] . '?dfrn_id=' . $idtosend . '&dfrn_version=' . DFRN_PROTOCOL_VERSION . '&type=data&last_update=' . $last_update . '&perm=' . $perm; $handshake_xml = fetch_url($url); logger('poller: handshake with url ' . $url . ' returns xml: ' . $handshake_xml, LOGGER_DATA); if (!$handshake_xml) { logger("poller: {$url} appears to be dead - marking for death "); // dead connection - might be a transient event, or this might // mean the software was uninstalled or the domain expired. // Will keep trying for one month. mark_for_death($contact); // set the last-update so we don't keep polling $r = q("UPDATE `contact` SET `last-update` = '%s' WHERE `id` = %d LIMIT 1", dbesc(datetime_convert()), intval($contact['id'])); continue; } if (!strstr($handshake_xml, '<?xml')) { logger('poller: response from ' . $url . ' did not contain XML.'); $r = q("UPDATE `contact` SET `last-update` = '%s' WHERE `id` = %d LIMIT 1", dbesc(datetime_convert()), intval($contact['id'])); continue; } $res = parse_xml_string($handshake_xml); if (intval($res->status) == 1) { logger("poller: {$url} replied status 1 - marking for death "); // we may not be friends anymore. Will keep trying for one month. // set the last-update so we don't keep polling $r = q("UPDATE `contact` SET `last-update` = '%s' WHERE `id` = %d LIMIT 1", dbesc(datetime_convert()), intval($contact['id'])); mark_for_death($contact); } else { if ($contact['term-date'] != '0000-00-00 00:00:00') { logger("poller: {$url} back from the dead - removing mark for death"); unmark_for_death($contact); } } if (intval($res->status) != 0 || !strlen($res->challenge) || !strlen($res->dfrn_id)) { continue; } if ((double) $res->dfrn_version > 2.21 && $contact['poco'] == '') { q("update contact set poco = '%s' where id = %d limit 1", dbesc(str_replace('/profile/', '/poco/', $contact['url'])), intval($contact['id'])); } $postvars = array(); $sent_dfrn_id = hex2bin((string) $res->dfrn_id); $challenge = hex2bin((string) $res->challenge); $final_dfrn_id = ''; if ($contact['duplex'] && strlen($contact['prvkey'])) { openssl_private_decrypt($sent_dfrn_id, $final_dfrn_id, $contact['prvkey']); openssl_private_decrypt($challenge, $postvars['challenge'], $contact['prvkey']); } else { openssl_public_decrypt($sent_dfrn_id, $final_dfrn_id, $contact['pubkey']); openssl_public_decrypt($challenge, $postvars['challenge'], $contact['pubkey']); } $final_dfrn_id = substr($final_dfrn_id, 0, strpos($final_dfrn_id, '.')); if (strpos($final_dfrn_id, ':') == 1) { $final_dfrn_id = substr($final_dfrn_id, 2); } if ($final_dfrn_id != $orig_id) { logger('poller: ID did not decode: ' . $contact['id'] . ' orig: ' . $orig_id . ' final: ' . $final_dfrn_id); // did not decode properly - cannot trust this site continue; } $postvars['dfrn_id'] = $idtosend; $postvars['dfrn_version'] = DFRN_PROTOCOL_VERSION; $postvars['perm'] = 'rw'; $xml = post_url($contact['poll'], $postvars); } elseif ($contact['network'] === NETWORK_OSTATUS || $contact['network'] === NETWORK_DIASPORA || $contact['network'] === NETWORK_FEED) { // Upgrading DB fields from an older Friendika version // Will only do this once per notify-enabled OStatus contact // or if relationship changes $stat_writeable = $contact['notify'] && ($contact['rel'] == CONTACT_IS_FOLLOWER || $contact['rel'] == CONTACT_IS_FRIEND) ? 1 : 0; if ($stat_writeable != $contact['writable']) { q("UPDATE `contact` SET `writable` = %d WHERE `id` = %d LIMIT 1", intval($stat_writeable), intval($contact['id'])); } // Are we allowed to import from this person? if ($contact['rel'] == CONTACT_IS_FOLLOWER || $contact['blocked'] || $contact['readonly']) { continue; } $xml = fetch_url($contact['poll']); } elseif ($contact['network'] === NETWORK_MAIL || $contact['network'] === NETWORK_MAIL2) { $mail_disabled = function_exists('imap_open') && !get_config('system', 'imap_disabled') ? 0 : 1; if ($mail_disabled) { continue; } $mbox = null; $x = q("SELECT `prvkey` FROM `user` WHERE `uid` = %d LIMIT 1", intval($importer_uid)); $mailconf = q("SELECT * FROM `mailacct` WHERE `server` != '' AND `uid` = %d LIMIT 1", intval($importer_uid)); if (count($x) && count($mailconf)) { $mailbox = construct_mailbox_name($mailconf[0]); $password = ''; openssl_private_decrypt(hex2bin($mailconf[0]['pass']), $password, $x[0]['prvkey']); $mbox = email_connect($mailbox, $mailconf[0]['user'], $password); unset($password); if ($mbox) { q("UPDATE `mailacct` SET `last_check` = '%s' WHERE `id` = %d AND `uid` = %d LIMIT 1", dbesc(datetime_convert()), intval($mailconf[0]['id']), intval($importer_uid)); } } if ($mbox) { $msgs = email_poll($mbox, $contact['addr']); if (count($msgs)) { foreach ($msgs as $msg_uid) { $datarray = array(); $meta = email_msg_meta($mbox, $msg_uid); $headers = email_msg_headers($mbox, $msg_uid); // look for a 'references' header and try and match with a parent item we have locally. $raw_refs = x($headers, 'references') ? str_replace("\t", '', $headers['references']) : ''; $datarray['uri'] = trim($meta->message_id, '<>'); if ($raw_refs) { $refs_arr = explode(' ', $raw_refs); if (count($refs_arr)) { for ($x = 0; $x < count($refs_arr); $x++) { $refs_arr[$x] = "'" . str_replace(array('<', '>', ' '), array('', '', ''), dbesc($refs_arr[$x])) . "'"; } } $qstr = implode(',', $refs_arr); $r = q("SELECT `uri` , `parent-uri` FROM `item` WHERE `uri` IN ( {$qstr} ) AND `uid` = %d LIMIT 1", intval($importer_uid)); if (count($r)) { $datarray['parent-uri'] = $r[0]['uri']; } } if (!x($datarray, 'parent-uri')) { $datarray['parent-uri'] = $datarray['uri']; } // Have we seen it before? $r = q("SELECT * FROM `item` WHERE `uid` = %d AND `uri` = '%s' LIMIT 1", intval($importer_uid), dbesc($datarray['uri'])); if (count($r)) { if ($meta->deleted && !$r[0]['deleted']) { q("UPDATE `item` SET `deleted` = 1, `changed` = '%s' WHERE `id` = %d LIMIT 1", dbesc(datetime_convert()), intval($r[0]['id'])); } continue; } $datarray['title'] = notags(trim($meta->subject)); $datarray['created'] = datetime_convert('UTC', 'UTC', $meta->date); $r = email_get_msg($mbox, $msg_uid); if (!$r) { continue; } $datarray['body'] = escape_tags($r['body']); // 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'])) { $datarray['body'] = t('From: ') . escape_tags($meta->from) . "\n\n" . $datarray['body']; } $datarray['uid'] = $importer_uid; $datarray['contact-id'] = $contact['id']; if ($datarray['parent-uri'] === $datarray['uri']) { $datarray['private'] = 1; } if ($contact['network'] === NETWORK_MAIL && !get_pconfig($importer_uid, 'system', 'allow_public_email_replies')) { $datarray['private'] = 1; $datarray['allow_cid'] = '<' . $contact['id'] . '>'; } $datarray['author-name'] = $contact['name']; $datarray['author-link'] = 'mailbox'; $datarray['author-avatar'] = $contact['photo']; $stored_item = item_store($datarray); q("UPDATE `item` SET `last-child` = 0 WHERE `parent-uri` = '%s' AND `uid` = %d", dbesc($datarray['parent-uri']), intval($importer_uid)); q("UPDATE `item` SET `last-child` = 1 WHERE `id` = %d LIMIT 1", intval($stored_item)); } } imap_close($mbox); } } elseif ($contact['network'] === NETWORK_FACEBOOK) { // This is picked up by the Facebook plugin on a cron hook. // Ignored here. } if ($xml) { logger('poller: received xml : ' . $xml, LOGGER_DATA); if (!strstr($xml, '<?xml')) { logger('poller: post_handshake: response from ' . $url . ' did not contain XML.'); $r = q("UPDATE `contact` SET `last-update` = '%s' WHERE `id` = %d LIMIT 1", dbesc(datetime_convert()), intval($contact['id'])); continue; } consume_feed($xml, $importer, $contact, $hub, 1, 1); // do it twice. Ensures that children of parents which may be later in the stream aren't tossed consume_feed($xml, $importer, $contact, $hub, 1, 2); $hubmode = 'subscribe'; if ($contact['network'] === NETWORK_DFRN || $contact['blocked'] || $contact['readonly']) { $hubmode = 'unsubscribe'; } if (strlen($hub) && $hub_update && $contact['rel'] != CONTACT_IS_FOLLOWER) { logger('poller: hub ' . $hubmode . ' : ' . $hub . ' contact name : ' . $contact['name'] . ' local user : '******'name']); $hubs = explode(',', $hub); if (count($hubs)) { foreach ($hubs as $h) { $h = trim($h); if (!strlen($h)) { continue; } subscribe_to_hub($h, $importer, $contact, $hubmode); } } } } $updated = datetime_convert(); $r = q("UPDATE `contact` SET `last-update` = '%s', `success_update` = '%s' WHERE `id` = %d LIMIT 1", dbesc($updated), dbesc($updated), intval($contact['id'])); // load current friends if possible. if ($contact['poco']) { $r = q("SELECT count(*) as total from glink \n\t\t\t\t\twhere `cid` = %d and updated > UTC_TIMESTAMP() - INTERVAL 1 DAY", intval($contact['id'])); } if (count($r)) { if (!$r[0]['total']) { poco_load($contact['id'], $importer_uid, $contact['poco']); } } // loop - next contact } } return; }
function onepoll_run(&$argv, &$argc) { global $a, $db; 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 'library/simplepie/simplepie.inc'; require_once 'include/items.php'; require_once 'include/Contact.php'; require_once 'include/email.php'; require_once 'include/socgraph.php'; require_once 'include/pidfile.php'; require_once 'include/queue_fn.php'; load_config('config'); load_config('system'); $a->set_baseurl(get_config('system', 'url')); load_hooks(); logger('onepoll: start'); $manual_id = 0; $generation = 0; $hub_update = false; $force = false; $restart = false; if ($argc > 1 && intval($argv[1])) { $contact_id = intval($argv[1]); } if (!$contact_id) { logger('onepoll: no contact'); return; } $lockpath = get_lockpath(); if ($lockpath != '') { $pidfile = new pidfile($lockpath, 'onepoll' . $contact_id); if ($pidfile->is_already_running()) { logger("onepoll: Already running for contact " . $contact_id); if ($pidfile->running_time() > 9 * 60) { $pidfile->kill(); logger("killed stale process"); } exit; } } $d = datetime_convert(); // Only poll from those with suitable relationships, // and which have a polling address and ignore Diaspora since // we are unable to match those posts with a Diaspora GUID and prevent duplicates. $contacts = q("SELECT `contact`.* FROM `contact`\n\t\tWHERE ( `rel` = %d OR `rel` = %d ) AND `poll` != ''\n\t\tAND NOT `network` IN ( '%s', '%s', '%s' )\n\t\tAND `contact`.`id` = %d\n\t\tAND `self` = 0 AND `contact`.`blocked` = 0 AND `contact`.`readonly` = 0\n\t\tAND `contact`.`archive` = 0 LIMIT 1", intval(CONTACT_IS_SHARING), intval(CONTACT_IS_FRIEND), dbesc(NETWORK_DIASPORA), dbesc(NETWORK_FACEBOOK), dbesc(NETWORK_PUMPIO), intval($contact_id)); if (!count($contacts)) { return; } $contact = $contacts[0]; $xml = false; $t = $contact['last-update']; if ($contact['subhub']) { $poll_interval = get_config('system', 'pushpoll_frequency'); $contact['priority'] = $poll_interval !== false ? intval($poll_interval) : 3; $hub_update = false; if (datetime_convert('UTC', 'UTC', 'now') > datetime_convert('UTC', 'UTC', $t . " + 1 day")) { $hub_update = true; } } else { $hub_update = false; } $importer_uid = $contact['uid']; $r = q("SELECT `contact`.*, `user`.`page-flags` FROM `contact` INNER JOIN `user` on `contact`.`uid` = `user`.`uid` WHERE `user`.`uid` = %d AND `contact`.`self` = 1 LIMIT 1", intval($importer_uid)); if (!count($r)) { return; } $importer = $r[0]; logger("onepoll: poll: ({$contact['id']}) IMPORTER: {$importer['name']}, CONTACT: {$contact['name']}"); $last_update = $contact['last-update'] === '0000-00-00 00:00:00' ? datetime_convert('UTC', 'UTC', 'now - 7 days', ATOM_TIME) : datetime_convert('UTC', 'UTC', $contact['last-update'], ATOM_TIME); if ($contact['network'] === NETWORK_DFRN) { $idtosend = $orig_id = $contact['dfrn-id'] ? $contact['dfrn-id'] : $contact['issued-id']; if (intval($contact['duplex']) && $contact['dfrn-id']) { $idtosend = '0:' . $orig_id; } if (intval($contact['duplex']) && $contact['issued-id']) { $idtosend = '1:' . $orig_id; } // they have permission to write to us. We already filtered this in the contact query. $perm = 'rw'; // 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'])); } $url = $contact['poll'] . '?dfrn_id=' . $idtosend . '&dfrn_version=' . DFRN_PROTOCOL_VERSION . '&type=data&last_update=' . $last_update . '&perm=' . $perm; $handshake_xml = fetch_url($url); $html_code = $a->get_curl_code(); logger('onepoll: handshake with url ' . $url . ' returns xml: ' . $handshake_xml, LOGGER_DATA); if (!strlen($handshake_xml) || $html_code >= 400 || !$html_code) { logger("poller: {$url} appears to be dead - marking for death "); // dead connection - might be a transient event, or this might // mean the software was uninstalled or the domain expired. // Will keep trying for one month. mark_for_death($contact); // set the last-update so we don't keep polling $r = q("UPDATE `contact` SET `last-update` = '%s' WHERE `id` = %d", dbesc(datetime_convert()), intval($contact['id'])); return; } if (!strstr($handshake_xml, '<')) { logger('poller: response from ' . $url . ' did not contain XML.'); mark_for_death($contact); $r = q("UPDATE `contact` SET `last-update` = '%s' WHERE `id` = %d", dbesc(datetime_convert()), intval($contact['id'])); return; } $res = parse_xml_string($handshake_xml); if (intval($res->status) == 1) { logger("poller: {$url} replied status 1 - marking for death "); // we may not be friends anymore. Will keep trying for one month. // set the last-update so we don't keep polling $r = q("UPDATE `contact` SET `last-update` = '%s' WHERE `id` = %d", dbesc(datetime_convert()), intval($contact['id'])); mark_for_death($contact); } else { if ($contact['term-date'] != '0000-00-00 00:00:00') { logger("poller: {$url} back from the dead - removing mark for death"); unmark_for_death($contact); } } if (intval($res->status) != 0 || !strlen($res->challenge) || !strlen($res->dfrn_id)) { return; } if ((double) $res->dfrn_version > 2.21 && $contact['poco'] == '') { q("update contact set poco = '%s' where id = %d", dbesc(str_replace('/profile/', '/poco/', $contact['url'])), intval($contact['id'])); } $postvars = array(); $sent_dfrn_id = hex2bin((string) $res->dfrn_id); $challenge = hex2bin((string) $res->challenge); $final_dfrn_id = ''; if ($contact['duplex'] && strlen($contact['prvkey'])) { openssl_private_decrypt($sent_dfrn_id, $final_dfrn_id, $contact['prvkey']); openssl_private_decrypt($challenge, $postvars['challenge'], $contact['prvkey']); } else { openssl_public_decrypt($sent_dfrn_id, $final_dfrn_id, $contact['pubkey']); openssl_public_decrypt($challenge, $postvars['challenge'], $contact['pubkey']); } $final_dfrn_id = substr($final_dfrn_id, 0, strpos($final_dfrn_id, '.')); if (strpos($final_dfrn_id, ':') == 1) { $final_dfrn_id = substr($final_dfrn_id, 2); } if ($final_dfrn_id != $orig_id) { logger('poller: ID did not decode: ' . $contact['id'] . ' orig: ' . $orig_id . ' final: ' . $final_dfrn_id); // did not decode properly - cannot trust this site return; } $postvars['dfrn_id'] = $idtosend; $postvars['dfrn_version'] = DFRN_PROTOCOL_VERSION; $postvars['perm'] = 'rw'; $xml = post_url($contact['poll'], $postvars); } elseif ($contact['network'] === NETWORK_OSTATUS || $contact['network'] === NETWORK_DIASPORA || $contact['network'] === NETWORK_FEED) { // Upgrading DB fields from an older Friendica version // Will only do this once per notify-enabled OStatus contact // or if relationship changes $stat_writeable = $contact['notify'] && ($contact['rel'] == CONTACT_IS_FOLLOWER || $contact['rel'] == CONTACT_IS_FRIEND) ? 1 : 0; if ($contact['network'] === NETWORK_OSTATUS && get_pconfig($importer_uid, 'system', 'ostatus_autofriend')) { $stat_writeable = 1; } if ($stat_writeable != $contact['writable']) { q("UPDATE `contact` SET `writable` = %d WHERE `id` = %d", intval($stat_writeable), intval($contact['id'])); } // Are we allowed to import from this person? if ($contact['rel'] == CONTACT_IS_FOLLOWER || $contact['blocked'] || $contact['readonly']) { return; } $xml = fetch_url($contact['poll']); } elseif ($contact['network'] === NETWORK_MAIL || $contact['network'] === NETWORK_MAIL2) { logger("Mail: Fetching", LOGGER_DEBUG); $mail_disabled = function_exists('imap_open') && !get_config('system', 'imap_disabled') ? 0 : 1; if ($mail_disabled) { return; } logger("Mail: Enabled", LOGGER_DEBUG); $mbox = null; $x = q("SELECT `prvkey` FROM `user` WHERE `uid` = %d LIMIT 1", intval($importer_uid)); $mailconf = q("SELECT * FROM `mailacct` WHERE `server` != '' AND `uid` = %d LIMIT 1", intval($importer_uid)); if (count($x) && count($mailconf)) { $mailbox = construct_mailbox_name($mailconf[0]); $password = ''; openssl_private_decrypt(hex2bin($mailconf[0]['pass']), $password, $x[0]['prvkey']); $mbox = email_connect($mailbox, $mailconf[0]['user'], $password); unset($password); logger("Mail: Connect to " . $mailconf[0]['user']); if ($mbox) { q("UPDATE `mailacct` SET `last_check` = '%s' WHERE `id` = %d AND `uid` = %d", dbesc(datetime_convert()), intval($mailconf[0]['id']), intval($importer_uid)); logger("Mail: Connected to " . $mailconf[0]['user']); } else { logger("Mail: Connection error " . $mailconf[0]['user'] . " " . print_r(imap_errors())); } } if ($mbox) { $msgs = email_poll($mbox, $contact['addr']); if (count($msgs)) { 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); } else { $msgs = array_combine($msgs, $metas); foreach ($msgs as $msg_uid => $meta) { logger("Mail: Parsing mail " . $msg_uid, LOGGER_DATA); $datarray = array(); $datarray['verb'] = ACTIVITY_POST; $datarray['object-type'] = ACTIVITY_OBJ_NOTE; // $meta = email_msg_meta($mbox,$msg_uid); // $headers = email_msg_headers($mbox,$msg_uid); $datarray['uri'] = msgid2iri(trim($meta->message_id, '<>')); // Have we seen it before? $r = q("SELECT * FROM `item` WHERE `uid` = %d AND `uri` = '%s' LIMIT 1", intval($importer_uid), dbesc($datarray['uri'])); if (count($r)) { 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 ($meta->deleted && !$r[0]['deleted']) { q("UPDATE `item` SET `deleted` = 1, `changed` = '%s' WHERE `id` = %d", dbesc(datetime_convert()), intval($r[0]['id'])); } } switch ($mailconf[0]['action']) { case 0: logger("Mail: Seen before " . $msg_uid . " for " . $mailconf[0]['user'] . ". Doing nothing.", LOGGER_DEBUG); break; case 1: logger("Mail: Deleting " . $msg_uid . " for " . $mailconf[0]['user']); imap_delete($mbox, $msg_uid, FT_UID); break; case 2: logger("Mail: Mark as seen " . $msg_uid . " for " . $mailconf[0]['user']); imap_setflag_full($mbox, $msg_uid, "\\Seen", ST_UID); break; case 3: logger("Mail: Moving " . $msg_uid . " to " . $mailconf[0]['movetofolder'] . " for " . $mailconf[0]['user']); imap_setflag_full($mbox, $msg_uid, "\\Seen", ST_UID); if ($mailconf[0]['movetofolder'] != "") { imap_mail_move($mbox, $msg_uid, $mailconf[0]['movetofolder'], FT_UID); } break; } continue; } // look for a 'references' or an 'in-reply-to' header and try to match with a parent item we have locally. // $raw_refs = ((x($headers,'references')) ? str_replace("\t",'',$headers['references']) : ''); $raw_refs = property_exists($meta, 'references') ? str_replace("\t", '', $meta->references) : ''; if (!trim($raw_refs)) { $raw_refs = property_exists($meta, 'in_reply_to') ? str_replace("\t", '', $meta->in_reply_to) : ''; } $raw_refs = trim($raw_refs); // Don't allow a blank reference in $refs_arr if ($raw_refs) { $refs_arr = explode(' ', $raw_refs); if (count($refs_arr)) { 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` WHERE `uri` IN ( {$qstr} ) AND `uid` = %d LIMIT 1", intval($importer_uid)); if (count($r)) { $datarray['parent-uri'] = $r[0]['parent-uri']; } // Set the parent as the top-level item // $datarray['parent-uri'] = $r[0]['uri']; } // Decoding the header $subject = imap_mime_header_decode($meta->subject); $datarray['title'] = ""; foreach ($subject as $subpart) { if ($subpart->charset != "default") { $datarray['title'] .= iconv($subpart->charset, 'UTF-8//IGNORE', $subpart->text); } else { $datarray['title'] .= $subpart->text; } } $datarray['title'] = notags(trim($datarray['title'])); //$datarray['title'] = notags(trim($meta->subject)); $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 $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) { $r = q("SELECT `uri` , `parent-uri` FROM `item` WHERE `title` = \"%s\" AND `uid` = %d ORDER BY `created` DESC LIMIT 1", dbesc(protect_sprintf($datarray['title'])), intval($importer_uid)); if (count($r)) { $datarray['parent-uri'] = $r[0]['parent-uri']; } } if (!x($datarray, 'parent-uri')) { $datarray['parent-uri'] = $datarray['uri']; } $r = email_get_msg($mbox, $msg_uid, $reply); if (!$r) { logger("Mail: can't fetch msg " . $msg_uid . " for " . $mailconf[0]['user']); continue; } $datarray['body'] = escape_tags($r['body']); $datarray['body'] = limit_body_size($datarray['body']); 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; } else { $fromname = $frommail; } //$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']; $datarray['owner-name'] = $contact['name']; $datarray['owner-link'] = "mailto:" . $contact['addr']; $datarray['owner-avatar'] = $contact['photo']; } else { $datarray['author-name'] = $contact['name']; $datarray['author-link'] = 'mailbox'; $datarray['author-avatar'] = $contact['photo']; } $datarray['uid'] = $importer_uid; $datarray['contact-id'] = $contact['id']; if ($datarray['parent-uri'] === $datarray['uri']) { $datarray['private'] = 1; } if ($contact['network'] === NETWORK_MAIL && !get_pconfig($importer_uid, 'system', 'allow_public_email_replies')) { $datarray['private'] = 1; $datarray['allow_cid'] = '<' . $contact['id'] . '>'; } $stored_item = item_store($datarray); q("UPDATE `item` SET `last-child` = 0 WHERE `parent-uri` = '%s' AND `uid` = %d", dbesc($datarray['parent-uri']), intval($importer_uid)); q("UPDATE `item` SET `last-child` = 1 WHERE `id` = %d", intval($stored_item)); switch ($mailconf[0]['action']) { case 0: logger("Mail: Seen before " . $msg_uid . " for " . $mailconf[0]['user'] . ". Doing nothing.", LOGGER_DEBUG); break; case 1: logger("Mail: Deleting " . $msg_uid . " for " . $mailconf[0]['user']); imap_delete($mbox, $msg_uid, FT_UID); break; case 2: logger("Mail: Mark as seen " . $msg_uid . " for " . $mailconf[0]['user']); imap_setflag_full($mbox, $msg_uid, "\\Seen", ST_UID); break; case 3: logger("Mail: Moving " . $msg_uid . " to " . $mailconf[0]['movetofolder'] . " for " . $mailconf[0]['user']); imap_setflag_full($mbox, $msg_uid, "\\Seen", ST_UID); if ($mailconf[0]['movetofolder'] != "") { imap_mail_move($mbox, $msg_uid, $mailconf[0]['movetofolder'], FT_UID); } break; } } } } else { logger("Mail: no mails for " . $mailconf[0]['user']); } logger("Mail: closing connection for " . $mailconf[0]['user']); imap_close($mbox); } } elseif ($contact['network'] === NETWORK_FACEBOOK) { // This is picked up by the Facebook plugin on a cron hook. // Ignored here. } elseif ($contact['network'] === NETWORK_PUMPIO) { // This is picked up by the pump.io plugin on a cron hook. // Ignored here. } if ($xml) { logger('poller: received xml : ' . $xml, LOGGER_DATA); if (!strstr($xml, '<')) { logger('poller: post_handshake: response from ' . $url . ' did not contain XML.'); $r = q("UPDATE `contact` SET `last-update` = '%s' WHERE `id` = %d", dbesc(datetime_convert()), intval($contact['id'])); return; } consume_feed($xml, $importer, $contact, $hub, 1, 1); // do it twice. Ensures that children of parents which may be later in the stream aren't tossed consume_feed($xml, $importer, $contact, $hub, 1, 2); $hubmode = 'subscribe'; if ($contact['network'] === NETWORK_DFRN || $contact['blocked'] || $contact['readonly']) { $hubmode = 'unsubscribe'; } if (($contact['network'] === NETWORK_OSTATUS || $contact['network'] == NETWORK_FEED) && !$contact['hub-verify']) { $hub_update = true; } if (strlen($hub) && $hub_update && ($contact['rel'] != CONTACT_IS_FOLLOWER || $contact['network'] == NETWORK_FEED)) { logger('poller: hub ' . $hubmode . ' : ' . $hub . ' contact name : ' . $contact['name'] . ' local user : '******'name']); $hubs = explode(',', $hub); if (count($hubs)) { foreach ($hubs as $h) { $h = trim($h); if (!strlen($h)) { continue; } subscribe_to_hub($h, $importer, $contact, $hubmode); } } } } $updated = datetime_convert(); $r = q("UPDATE `contact` SET `last-update` = '%s', `success_update` = '%s' WHERE `id` = %d", dbesc($updated), dbesc($updated), intval($contact['id'])); // load current friends if possible. if ($contact['poco']) { $r = q("SELECT count(*) as total from glink\n\t\t\twhere `cid` = %d and updated > UTC_TIMESTAMP() - INTERVAL 1 DAY", intval($contact['id'])); } if (count($r)) { if (!$r[0]['total']) { poco_load($contact['id'], $importer_uid, 0, $contact['poco']); } } return; }
function probe_url($url, $mode = PROBE_NORMAL, $level = 1) { require_once 'include/email.php'; $result = array(); if (!$url) { return $result; } $result = Cache::get("probe_url:" . $mode . ":" . $url); if (!is_null($result)) { $result = unserialize($result); return $result; } $network = null; $diaspora = false; $diaspora_base = ''; $diaspora_guid = ''; $diaspora_key = ''; $has_lrdd = false; $email_conversant = false; $connectornetworks = false; $appnet = false; if (strpos($url, 'twitter.com')) { $connectornetworks = true; $network = NETWORK_TWITTER; } // Twitter is deactivated since twitter closed its old API //$twitter = ((strpos($url,'twitter.com') !== false) ? true : false); $lastfm = strpos($url, 'last.fm/user') !== false ? true : false; $at_addr = strpos($url, '@') !== false ? true : false; if (!$appnet && !$lastfm && !$connectornetworks) { if (strpos($url, 'mailto:') !== false && $at_addr) { $url = str_replace('mailto:', '', $url); $links = array(); } else { $links = lrdd($url); } if (count($links)) { $has_lrdd = true; logger('probe_url: found lrdd links: ' . print_r($links, true), LOGGER_DATA); foreach ($links as $link) { if ($link['@attributes']['rel'] === NAMESPACE_ZOT) { $zot = unamp($link['@attributes']['href']); } if ($link['@attributes']['rel'] === NAMESPACE_DFRN) { $dfrn = unamp($link['@attributes']['href']); } if ($link['@attributes']['rel'] === 'salmon') { $notify = unamp($link['@attributes']['href']); } if ($link['@attributes']['rel'] === NAMESPACE_FEED) { $poll = unamp($link['@attributes']['href']); } if ($link['@attributes']['rel'] === 'http://microformats.org/profile/hcard') { $hcard = unamp($link['@attributes']['href']); } if ($link['@attributes']['rel'] === 'http://webfinger.net/rel/profile-page') { $profile = unamp($link['@attributes']['href']); } if ($link['@attributes']['rel'] === 'http://portablecontacts.net/spec/1.0') { $poco = unamp($link['@attributes']['href']); } if ($link['@attributes']['rel'] === 'http://joindiaspora.com/seed_location') { $diaspora_base = unamp($link['@attributes']['href']); $diaspora = true; } if ($link['@attributes']['rel'] === 'http://joindiaspora.com/guid') { $diaspora_guid = unamp($link['@attributes']['href']); $diaspora = true; } if ($link['@attributes']['rel'] === 'diaspora-public-key') { $diaspora_key = base64_decode(unamp($link['@attributes']['href'])); if (strstr($diaspora_key, 'RSA ')) { $pubkey = rsatopem($diaspora_key); } else { $pubkey = $diaspora_key; } $diaspora = true; } if ($link['@attributes']['rel'] === 'http://ostatus.org/schema/1.0/subscribe' and $mode == PROBE_NORMAL) { $diaspora = false; } } // Status.Net can have more than one profile URL. We need to match the profile URL // to a contact on incoming messages to prevent spam, and we won't know which one // to match. So in case of two, one of them is stored as an alias. Only store URL's // and not webfinger user@host aliases. If they've got more than two non-email style // aliases, let's hope we're lucky and get one that matches the feed author-uri because // otherwise we're screwed. foreach ($links as $link) { if ($link['@attributes']['rel'] === 'alias') { if (strpos($link['@attributes']['href'], '@') === false) { if (isset($profile)) { if ($link['@attributes']['href'] !== $profile) { $alias = unamp($link['@attributes']['href']); } } else { $profile = unamp($link['@attributes']['href']); } } } } // If the profile is different from the url then the url is abviously an alias if ($alias == "" and $profile != "" and !$at_addr and normalise_link($profile) != normalise_link($url)) { $alias = $url; } } elseif ($mode == PROBE_NORMAL) { // Check email $orig_url = $url; if (strpos($orig_url, '@') && validate_email($orig_url)) { $x = q("SELECT `prvkey` FROM `user` WHERE `uid` = %d LIMIT 1", intval(local_user())); $r = q("SELECT * FROM `mailacct` WHERE `uid` = %d AND `server` != '' LIMIT 1", intval(local_user())); if (count($x) && count($r)) { $mailbox = construct_mailbox_name($r[0]); $password = ''; openssl_private_decrypt(hex2bin($r[0]['pass']), $password, $x[0]['prvkey']); $mbox = email_connect($mailbox, $r[0]['user'], $password); if (!$mbox) { logger('probe_url: email_connect failed.'); } unset($password); } if ($mbox) { $msgs = email_poll($mbox, $orig_url); logger('probe_url: searching ' . $orig_url . ', ' . count($msgs) . ' messages found.', LOGGER_DEBUG); if (count($msgs)) { $addr = $orig_url; $network = NETWORK_MAIL; $name = substr($url, 0, strpos($url, '@')); $phost = substr($url, strpos($url, '@') + 1); $profile = 'http://' . $phost; // fix nick character range $vcard = array('fn' => $name, 'nick' => $name, 'photo' => avatar_img($url)); $notify = 'smtp ' . random_string(); $poll = 'email ' . random_string(); $priority = 0; $x = email_msg_meta($mbox, $msgs[0]); if (stristr($x[0]->from, $orig_url)) { $adr = imap_rfc822_parse_adrlist($x[0]->from, ''); } elseif (stristr($x[0]->to, $orig_url)) { $adr = imap_rfc822_parse_adrlist($x[0]->to, ''); } if (isset($adr)) { foreach ($adr as $feadr) { if (strcasecmp($feadr->mailbox, $name) == 0 && strcasecmp($feadr->host, $phost) == 0 && strlen($feadr->personal)) { $personal = imap_mime_header_decode($feadr->personal); $vcard['fn'] = ""; foreach ($personal as $perspart) { if ($perspart->charset != "default") { $vcard['fn'] .= iconv($perspart->charset, 'UTF-8//IGNORE', $perspart->text); } else { $vcard['fn'] .= $perspart->text; } } $vcard['fn'] = notags($vcard['fn']); } } } } imap_close($mbox); } } } } if ($mode == PROBE_NORMAL) { if (strlen($zot)) { $s = fetch_url($zot); if ($s) { $j = json_decode($s); if ($j) { $network = NETWORK_ZOT; $vcard = array('fn' => $j->fullname, 'nick' => $j->nickname, 'photo' => $j->photo); $profile = $j->url; $notify = $j->post; $pubkey = $j->pubkey; $poll = 'N/A'; } } } if (strlen($dfrn)) { $ret = scrape_dfrn($hcard ? $hcard : $dfrn, true); if (is_array($ret) && x($ret, 'dfrn-request')) { $network = NETWORK_DFRN; $request = $ret['dfrn-request']; $confirm = $ret['dfrn-confirm']; $notify = $ret['dfrn-notify']; $poll = $ret['dfrn-poll']; $vcard = array(); $vcard['fn'] = $ret['fn']; $vcard['nick'] = $ret['nick']; $vcard['photo'] = $ret['photo']; } } } if ($diaspora && $diaspora_base && $diaspora_guid) { if ($mode == PROBE_DIASPORA || !$notify) { $notify = $diaspora_base . 'receive/users/' . $diaspora_guid; $batch = $diaspora_base . 'receive/public'; } if (strpos($url, '@')) { $addr = str_replace('acct:', '', $url); } } if ($network !== NETWORK_ZOT && $network !== NETWORK_DFRN && $network !== NETWORK_MAIL) { if ($diaspora) { $network = NETWORK_DIASPORA; } elseif ($has_lrdd and $notify) { $network = NETWORK_OSTATUS; } if (strpos($url, '@')) { $addr = str_replace('acct:', '', $url); } $priority = 0; if ($hcard && !$vcard) { $vcard = scrape_vcard($hcard); // Google doesn't use absolute url in profile photos if (x($vcard, 'photo') && substr($vcard['photo'], 0, 1) == '/') { $h = @parse_url($hcard); if ($h) { $vcard['photo'] = $h['scheme'] . '://' . $h['host'] . $vcard['photo']; } } logger('probe_url: scrape_vcard: ' . print_r($vcard, true), LOGGER_DATA); } if ($diaspora && $addr) { // Diaspora returns the name as the nick. As the nick will never be updated, // let's use the Diaspora nickname (the first part of the handle) as the nick instead $addr_parts = explode('@', $addr); $vcard['nick'] = $addr_parts[0]; } /* if($twitter) { logger('twitter: setup'); $tid = basename($url); $tapi = 'https://api.twitter.com/1/statuses/user_timeline.rss'; if(intval($tid)) $poll = $tapi . '?user_id=' . $tid; else $poll = $tapi . '?screen_name=' . $tid; $profile = 'http://twitter.com/#!/' . $tid; //$vcard['photo'] = 'https://api.twitter.com/1/users/profile_image/' . $tid; $vcard['photo'] = 'https://api.twitter.com/1/users/profile_image?screen_name=' . $tid . '&size=bigger'; $vcard['nick'] = $tid; $vcard['fn'] = $tid; } */ if ($lastfm) { $profile = $url; $poll = str_replace(array('www.', 'last.fm/'), array('', 'ws.audioscrobbler.com/1.0/'), $url) . '/recenttracks.rss'; $vcard['nick'] = basename($url); $vcard['fn'] = $vcard['nick'] . t(' on Last.fm'); $network = NETWORK_FEED; } if (!x($vcard, 'fn')) { if (x($vcard, 'nick')) { $vcard['fn'] = $vcard['nick']; } } $check_feed = false; if (stristr($url, 'tumblr.com') && !stristr($url, '/rss')) { $poll = $url . '/rss'; $check_feed = true; // Will leave it to others to figure out how to grab the avatar, which is on the $url page in the open graph meta links } if ($appnet || !$poll) { $check_feed = true; } if (!isset($vcard) || !x($vcard, 'fn') || !$profile) { $check_feed = true; } if ($at_addr && !count($links)) { $check_feed = false; } if ($connectornetworks) { $check_feed = false; } if ($check_feed) { $feedret = scrape_feed($poll ? $poll : $url); logger('probe_url: scrape_feed ' . ($poll ? $poll : $url) . ' returns: ' . print_r($feedret, true), LOGGER_DATA); if (count($feedret) && ($feedret['feed_atom'] || $feedret['feed_rss'])) { $poll = x($feedret, 'feed_atom') ? unamp($feedret['feed_atom']) : unamp($feedret['feed_rss']); if (!x($vcard)) { $vcard = array(); } } if (x($feedret, 'photo') && !x($vcard, 'photo')) { $vcard['photo'] = $feedret['photo']; } require_once 'library/simplepie/simplepie.inc'; $feed = new SimplePie(); $xml = fetch_url($poll); logger('probe_url: fetch feed: ' . $poll . ' returns: ' . $xml, LOGGER_DATA); $a = get_app(); logger('probe_url: scrape_feed: headers: ' . $a->get_curl_headers(), LOGGER_DATA); // Don't try and parse an empty string $feed->set_raw_data($xml ? $xml : '<?xml version="1.0" encoding="utf-8" ?><xml></xml>'); $feed->init(); if ($feed->error()) { logger('probe_url: scrape_feed: Error parsing XML: ' . $feed->error()); $network = NETWORK_PHANTOM; } if (!x($vcard, 'photo')) { $vcard['photo'] = $feed->get_image_url(); } $author = $feed->get_author(); if ($author) { $vcard['fn'] = unxmlify(trim($author->get_name())); if (!$vcard['fn']) { $vcard['fn'] = trim(unxmlify($author->get_email())); } if (strpos($vcard['fn'], '@') !== false) { $vcard['fn'] = substr($vcard['fn'], 0, strpos($vcard['fn'], '@')); } $email = unxmlify($author->get_email()); if (!$profile && $author->get_link()) { $profile = trim(unxmlify($author->get_link())); } if (!$vcard['photo']) { $rawtags = $feed->get_feed_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'author'); if ($rawtags) { $elems = $rawtags[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]; if (x($elems, 'link') && $elems['link'][0]['attribs']['']['rel'] === 'photo') { $vcard['photo'] = $elems['link'][0]['attribs']['']['href']; } } } // Fetch fullname via poco:displayName $pocotags = $feed->get_feed_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'author'); if ($pocotags) { $elems = $pocotags[0]['child']['http://portablecontacts.net/spec/1.0']; if (isset($elems["displayName"])) { $vcard['fn'] = $elems["displayName"][0]["data"]; } if (isset($elems["preferredUsername"])) { $vcard['nick'] = $elems["preferredUsername"][0]["data"]; } } } else { $item = $feed->get_item(0); if ($item) { $author = $item->get_author(); if ($author) { $vcard['fn'] = trim(unxmlify($author->get_name())); if (!$vcard['fn']) { $vcard['fn'] = trim(unxmlify($author->get_email())); } if (strpos($vcard['fn'], '@') !== false) { $vcard['fn'] = substr($vcard['fn'], 0, strpos($vcard['fn'], '@')); } $email = unxmlify($author->get_email()); if (!$profile && $author->get_link()) { $profile = trim(unxmlify($author->get_link())); } } if (!$vcard['photo']) { $rawmedia = $item->get_item_tags('http://search.yahoo.com/mrss/', 'thumbnail'); if ($rawmedia && $rawmedia[0]['attribs']['']['url']) { $vcard['photo'] = unxmlify($rawmedia[0]['attribs']['']['url']); } } if (!$vcard['photo']) { $rawtags = $item->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'author'); if ($rawtags) { $elems = $rawtags[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]; if (x($elems, 'link') && $elems['link'][0]['attribs']['']['rel'] === 'photo') { $vcard['photo'] = $elems['link'][0]['attribs']['']['href']; } } } } } // Workaround for misconfigured Friendica servers if ($network == "" and strstr($url, "/profile/")) { $noscrape = str_replace("/profile/", "/noscrape/", $url); $noscrapejson = fetch_url($noscrape); if ($noscrapejson) { $network = NETWORK_DFRN; $poco = str_replace("/profile/", "/poco/", $url); $noscrapedata = json_decode($noscrapejson, true); if (isset($noscrapedata["addr"])) { $addr = $noscrapedata["addr"]; } if (isset($noscrapedata["fn"])) { $vcard["fn"] = $noscrapedata["fn"]; } if (isset($noscrapedata["key"])) { $pubkey = $noscrapedata["key"]; } if (isset($noscrapedata["photo"])) { $vcard["photo"] = $noscrapedata["photo"]; } if (isset($noscrapedata["dfrn-request"])) { $request = $noscrapedata["dfrn-request"]; } if (isset($noscrapedata["dfrn-confirm"])) { $confirm = $noscrapedata["dfrn-confirm"]; } if (isset($noscrapedata["dfrn-notify"])) { $notify = $noscrapedata["dfrn-notify"]; } if (isset($noscrapedata["dfrn-poll"])) { $poll = $noscrapedata["dfrn-poll"]; } } } if (!$vcard['photo'] && strlen($email)) { $vcard['photo'] = avatar_img($email); } if ($poll === $profile) { $lnk = $feed->get_permalink(); } if (isset($lnk) && strlen($lnk)) { $profile = $lnk; } if (!$network) { $network = NETWORK_FEED; // If it is a feed, don't take the author name as feed name unset($vcard['fn']); } if (!x($vcard, 'fn')) { $vcard['fn'] = notags($feed->get_title()); } if (!x($vcard, 'fn')) { $vcard['fn'] = notags($feed->get_description()); } if (strpos($vcard['fn'], 'Twitter / ') !== false) { $vcard['fn'] = substr($vcard['fn'], strpos($vcard['fn'], '/') + 1); $vcard['fn'] = trim($vcard['fn']); } if (!x($vcard, 'nick')) { $vcard['nick'] = strtolower(notags(unxmlify($vcard['fn']))); if (strpos($vcard['nick'], ' ')) { $vcard['nick'] = trim(substr($vcard['nick'], 0, strpos($vcard['nick'], ' '))); } } if (!$priority) { $priority = 2; } } } if (!x($vcard, 'photo')) { $a = get_app(); $vcard['photo'] = $a->get_baseurl() . '/images/person-175.jpg'; } if (!$profile) { $profile = $url; } // No human could be associated with this link, use the URL as the contact name if ($network === NETWORK_FEED && $poll && !x($vcard, 'fn')) { $vcard['fn'] = $url; } if ($notify != "" and $poll != "") { $baseurl = matching(normalise_link($notify), normalise_link($poll)); $baseurl2 = matching($baseurl, normalise_link($profile)); if ($baseurl2 != "") { $baseurl = $baseurl2; } } if ($baseurl == "" and $notify != "") { $baseurl = matching(normalise_link($profile), normalise_link($notify)); } if ($baseurl == "" and $poll != "") { $baseurl = matching(normalise_link($profile), normalise_link($poll)); } $baseurl = rtrim($baseurl, "/"); if (strpos($url, '@') and $addr == "" and $network == NETWORK_DFRN) { $addr = str_replace('acct:', '', $url); } $vcard['fn'] = notags($vcard['fn']); $vcard['nick'] = str_replace(' ', '', notags($vcard['nick'])); $result['name'] = $vcard['fn']; $result['nick'] = $vcard['nick']; $result['url'] = $profile; $result['addr'] = $addr; $result['batch'] = $batch; $result['notify'] = $notify; $result['poll'] = $poll; $result['request'] = $request; $result['confirm'] = $confirm; $result['poco'] = $poco; $result['photo'] = $vcard['photo']; $result['priority'] = $priority; $result['network'] = $network; $result['alias'] = $alias; $result['pubkey'] = $pubkey; $result['baseurl'] = $baseurl; logger('probe_url: ' . print_r($result, true), LOGGER_DEBUG); if ($level == 1) { // Trying if it maybe a diaspora account if ($result['network'] == NETWORK_FEED or $result['addr'] == "") { require_once 'include/bbcode.php'; $address = GetProfileUsername($url, "", true); $result2 = probe_url($address, $mode, ++$level); if ($result2['network'] != "") { $result = $result2; } } // Maybe it's some non standard GNU Social installation (Single user, subfolder or no uri rewrite) if ($result['network'] == NETWORK_FEED and $result['baseurl'] != "" and $result['nick'] != "") { $addr = $result['nick'] . '@' . str_replace("http://", "", $result['baseurl']); $result2 = probe_url($addr, $mode, ++$level); if ($result2['network'] != "" and $result2['network'] != NETWORK_FEED) { $result = $result2; } } } // Only store into the cache if the value seems to be valid if ($result['network'] != NETWORK_PHANTOM) { Cache::set("probe_url:" . $mode . ":" . $url, serialize($result), CACHE_DAY); } return $result; }
function settings_post(&$a) { if (!local_user()) { notice(t('Permission denied.') . EOL); return; } if (count($a->user) && x($a->user, 'uid') && $a->user['uid'] != local_user()) { notice(t('Permission denied.') . EOL); return; } if ($a->argc > 1 && $a->argv[1] === 'oauth' && x($_POST, 'remove')) { $key = $_POST['remove']; q("DELETE FROM tokens WHERE id='%s' AND uid=%d", dbesc($key), local_user()); goaway($a->get_baseurl() . "/settings/oauth/"); return; } if ($a->argc > 2 && $a->argv[1] === 'oauth' && ($a->argv[2] === 'edit' || $a->argv[2] === 'add') && x($_POST, 'submit')) { $name = x($_POST, 'name') ? $_POST['name'] : ''; $key = x($_POST, 'key') ? $_POST['key'] : ''; $secret = x($_POST, 'secret') ? $_POST['secret'] : ''; $redirect = x($_POST, 'redirect') ? $_POST['redirect'] : ''; $icon = x($_POST, 'icon') ? $_POST['icon'] : ''; if ($name == "" || $key == "" || $secret == "") { notice(t("Missing some important data!")); } else { if ($_POST['submit'] == t("Update")) { $r = q("UPDATE clients SET\n\t\t\t\t\t\t\tclient_id='%s',\n\t\t\t\t\t\t\tpw='%s',\n\t\t\t\t\t\t\tname='%s',\n\t\t\t\t\t\t\tredirect_uri='%s',\n\t\t\t\t\t\t\ticon='%s',\n\t\t\t\t\t\t\tuid=%d\n\t\t\t\t\t\tWHERE client_id='%s'", dbesc($key), dbesc($secret), dbesc($name), dbesc($redirect), dbesc($icon), local_user(), dbesc($key)); } else { $r = q("INSERT INTO clients\n\t\t\t\t\t\t\t(client_id, pw, name, redirect_uri, icon, uid)\n\t\t\t\t\t\tVALUES ('%s','%s','%s','%s','%s',%d)", dbesc($key), dbesc($secret), dbesc($name), dbesc($redirect), dbesc($icon), local_user()); } } goaway($a->get_baseurl() . "/settings/oauth/"); return; } if ($a->argc > 1 && $a->argv[1] == 'addon') { call_hooks('plugin_settings_post', $_POST); return; } if ($a->argc > 1 && $a->argv[1] == 'connectors') { if (x($_POST['imap-submit'])) { $mail_server = x($_POST, 'mail_server') ? $_POST['mail_server'] : ''; $mail_port = x($_POST, 'mail_port') ? $_POST['mail_port'] : ''; $mail_ssl = x($_POST, 'mail_ssl') ? strtolower(trim($_POST['mail_ssl'])) : ''; $mail_user = x($_POST, 'mail_user') ? $_POST['mail_user'] : ''; $mail_pass = x($_POST, 'mail_pass') ? trim($_POST['mail_pass']) : ''; $mail_replyto = x($_POST, 'mail_replyto') ? $_POST['mail_replyto'] : ''; $mail_pubmail = x($_POST, 'mail_pubmail') ? $_POST['mail_pubmail'] : ''; $mail_disabled = function_exists('imap_open') && !get_config('system', 'imap_disabled') ? 0 : 1; if (get_config('system', 'dfrn_only')) { $mail_disabled = 1; } if (!$mail_disabled) { $failed = false; $r = q("SELECT * FROM `mailacct` WHERE `uid` = %d LIMIT 1", intval(local_user())); if (!count($r)) { q("INSERT INTO `mailacct` (`uid`) VALUES (%d)", intval(local_user())); } if (strlen($mail_pass)) { $pass = ''; openssl_public_encrypt($mail_pass, $pass, $a->user['pubkey']); q("UPDATE `mailacct` SET `pass` = '%s' WHERE `uid` = %d LIMIT 1", dbesc(bin2hex($pass)), intval(local_user())); } $r = q("UPDATE `mailacct` SET `server` = '%s', `port` = %d, `ssltype` = '%s', `user` = '%s',\n\t\t\t\t\t`mailbox` = 'INBOX', `reply_to` = '%s', `pubmail` = %d WHERE `uid` = %d LIMIT 1", dbesc($mail_server), intval($mail_port), dbesc($mail_ssl), dbesc($mail_user), dbesc($mail_replyto), intval($mail_pubmail), intval(local_user())); $r = q("SELECT * FROM `mailacct` WHERE `uid` = %d LIMIT 1", intval(local_user())); if (count($r)) { $eacct = $r[0]; require_once 'include/email.php'; $mb = construct_mailbox_name($eacct); if (strlen($eacct['server'])) { $dcrpass = ''; openssl_private_decrypt(hex2bin($eacct['pass']), $dcrpass, $a->user['prvkey']); $mbox = email_connect($mb, $mail_user, $dcrpass); unset($dcrpass); if (!$mbox) { $failed = true; notice(t('Failed to connect with email account using the settings provided.') . EOL); } } } if (!$failed) { info(t('Email settings updated.') . EOL); } } } call_hooks('connector_settings_post', $_POST); return; } call_hooks('settings_post', $_POST); if (x($_POST, 'npassword') || x($_POST, 'confirm')) { $newpass = $_POST['npassword']; $confirm = $_POST['confirm']; $err = false; if ($newpass != $confirm) { notice(t('Passwords do not match. Password unchanged.') . EOL); $err = true; } if (!x($newpass) || !x($confirm)) { notice(t('Empty passwords are not allowed. Password unchanged.') . EOL); $err = true; } if (!$err) { $password = hash('whirlpool', $newpass); $r = q("UPDATE `user` SET `password` = '%s' WHERE `uid` = %d LIMIT 1", dbesc($password), intval(local_user())); if ($r) { info(t('Password changed.') . EOL); } else { notice(t('Password update failed. Please try again.') . EOL); } } } $theme = x($_POST, 'theme') ? notags(trim($_POST['theme'])) : ''; $username = x($_POST, 'username') ? notags(trim($_POST['username'])) : ''; $email = x($_POST, 'email') ? notags(trim($_POST['email'])) : ''; $timezone = x($_POST, 'timezone') ? notags(trim($_POST['timezone'])) : ''; $defloc = x($_POST, 'defloc') ? notags(trim($_POST['defloc'])) : ''; $openid = x($_POST, 'openid_url') ? notags(trim($_POST['openid_url'])) : ''; $maxreq = x($_POST, 'maxreq') ? intval($_POST['maxreq']) : 0; $expire = x($_POST, 'expire') ? intval($_POST['expire']) : 0; $expire_items = x($_POST, 'expire_items') ? intval($_POST['expire_items']) : 0; $expire_notes = x($_POST, 'expire_notes') ? intval($_POST['expire_notes']) : 0; $expire_starred = x($_POST, 'expire_starred') ? intval($_POST['expire_starred']) : 0; $expire_photos = x($_POST, 'expire_photos') ? intval($_POST['expire_photos']) : 0; $allow_location = x($_POST, 'allow_location') && intval($_POST['allow_location']) == 1 ? 1 : 0; $publish = x($_POST, 'profile_in_directory') && intval($_POST['profile_in_directory']) == 1 ? 1 : 0; $net_publish = x($_POST, 'profile_in_netdirectory') && intval($_POST['profile_in_netdirectory']) == 1 ? 1 : 0; $old_visibility = x($_POST, 'visibility') && intval($_POST['visibility']) == 1 ? 1 : 0; $page_flags = x($_POST, 'page-flags') && intval($_POST['page-flags']) ? intval($_POST['page-flags']) : 0; $blockwall = x($_POST, 'blockwall') && intval($_POST['blockwall']) == 1 ? 0 : 1; // this setting is inverted! $blocktags = x($_POST, 'blocktags') && intval($_POST['blocktags']) == 1 ? 0 : 1; // this setting is inverted! $suggestme = x($_POST, 'suggestme') ? intval($_POST['suggestme']) : 0; $hide_friends = $_POST['hide-friends'] == 1 ? 1 : 0; $hidewall = $_POST['hidewall'] == 1 ? 1 : 0; $notify = 0; if (x($_POST, 'notify1')) { $notify += intval($_POST['notify1']); } if (x($_POST, 'notify2')) { $notify += intval($_POST['notify2']); } if (x($_POST, 'notify3')) { $notify += intval($_POST['notify3']); } if (x($_POST, 'notify4')) { $notify += intval($_POST['notify4']); } if (x($_POST, 'notify5')) { $notify += intval($_POST['notify5']); } $email_changed = false; $err = ''; $name_change = false; if ($username != $a->user['username']) { $name_change = true; if (strlen($username) > 40) { $err .= t(' Please use a shorter name.'); } if (strlen($username) < 3) { $err .= t(' Name too short.'); } } if ($email != $a->user['email']) { $email_changed = true; if (!valid_email($email)) { $err .= t(' Not valid email.'); } if (x($a->config, 'admin_email') && strcasecmp($email, $a->config['admin_email']) == 0) { $err .= t(' Cannot change to that email.'); $email = $a->user['email']; } } if (strlen($err)) { notice($err . EOL); return; } if ($timezone != $a->user['timezone']) { if (strlen($timezone)) { date_default_timezone_set($timezone); } } $str_group_allow = perms2str($_POST['group_allow']); $str_contact_allow = perms2str($_POST['contact_allow']); $str_group_deny = perms2str($_POST['group_deny']); $str_contact_deny = perms2str($_POST['contact_deny']); $openidserver = $a->user['openidserver']; // If openid has changed or if there's an openid but no openidserver, try and discover it. if ($openid != $a->user['openid'] || strlen($openid) && !strlen($openidserver)) { $tmp_str = $openid; if (strlen($tmp_str) && validate_url($tmp_str)) { logger('updating openidserver'); require_once 'library/openid.php'; $open_id_obj = new LightOpenID(); $open_id_obj->identity = $openid; $openidserver = $open_id_obj->discover($open_id_obj->identity); } else { $openidserver = ''; } } set_pconfig(local_user(), 'expire', 'items', $expire_items); set_pconfig(local_user(), 'expire', 'notes', $expire_notes); set_pconfig(local_user(), 'expire', 'starred', $expire_starred); set_pconfig(local_user(), 'expire', 'photos', $expire_photos); set_pconfig(local_user(), 'system', 'suggestme', $suggestme); $r = q("UPDATE `user` SET `username` = '%s', `email` = '%s', `openid` = '%s', `timezone` = '%s', `allow_cid` = '%s', `allow_gid` = '%s', `deny_cid` = '%s', `deny_gid` = '%s', `notify-flags` = %d, `page-flags` = %d, `default-location` = '%s', `allow_location` = %d, `theme` = '%s', `maxreq` = %d, `expire` = %d, `openidserver` = '%s', `blockwall` = %d, `hidewall` = %d, `blocktags` = %d WHERE `uid` = %d LIMIT 1", dbesc($username), dbesc($email), dbesc($openid), dbesc($timezone), dbesc($str_contact_allow), dbesc($str_group_allow), dbesc($str_contact_deny), dbesc($str_group_deny), intval($notify), intval($page_flags), dbesc($defloc), intval($allow_location), dbesc($theme), intval($maxreq), intval($expire), dbesc($openidserver), intval($blockwall), intval($hidewall), intval($blocktags), intval(local_user())); if ($r) { info(t('Settings updated.') . EOL); } $r = q("UPDATE `profile` \n\t\tSET `publish` = %d, \n\t\t`net-publish` = %d,\n\t\t`hide-friends` = %d\n\t\tWHERE `is-default` = 1 AND `uid` = %d LIMIT 1", intval($publish), intval($net_publish), intval($hide_friends), intval(local_user())); if ($name_change) { q("UPDATE `contact` SET `name` = '%s', `name-date` = '%s' WHERE `uid` = %d AND `self` = 1 LIMIT 1", dbesc($username), dbesc(datetime_convert()), intval(local_user())); } if ($old_visibility != $net_publish) { // Update global directory in background $url = $_SESSION['my_url']; if ($url && strlen(get_config('system', 'directory_submit_url'))) { proc_run('php', "include/directory.php", "{$url}"); } } require_once 'include/profile_update.php'; profile_change(); $_SESSION['theme'] = $theme; if ($email_changed && $a->config['register_policy'] == REGISTER_VERIFY) { // FIXME - set to un-verified, blocked and redirect to logout } goaway($a->get_baseurl() . '/settings'); return; // NOTREACHED }