function diaspora_send_mail($item, $owner, $contact) { $a = get_app(); $myaddr = $owner['nickname'] . '@' . substr($a->get_baseurl(), strpos($a->get_baseurl(), '://') + 3); $r = q("select * from conv where id = %d and uid = %d limit 1", intval($item['convid']), intval($item['uid'])); if (!count($r)) { logger('diaspora_send_mail: conversation not found.'); return; } $cnv = $r[0]; $conv = array('guid' => xmlify($cnv['guid']), 'subject' => xmlify($cnv['subject']), 'created_at' => xmlify(datetime_convert('UTC', 'UTC', $cnv['created'], 'Y-m-d H:i:s \\U\\T\\C')), 'diaspora_handle' => xmlify($cnv['creator']), 'participant_handles' => xmlify($cnv['recips'])); $body = bb2diaspora($item['body']); $created = datetime_convert('UTC', 'UTC', $item['created'], 'Y-m-d H:i:s \\U\\T\\C'); $signed_text = $item['guid'] . ';' . $cnv['guid'] . ';' . $body . ';' . $created . ';' . $myaddr . ';' . $cnv['guid']; $sig = base64_encode(rsa_sign($signed_text, $owner['uprvkey'], 'sha256')); $msg = array('guid' => xmlify($item['guid']), 'parent_guid' => xmlify($cnv['guid']), 'parent_author_signature' => xmlify($sig), 'author_signature' => xmlify($sig), 'text' => xmlify($body), 'created_at' => xmlify($created), 'diaspora_handle' => xmlify($myaddr), 'conversation_guid' => xmlify($cnv['guid'])); if ($item['reply']) { $tpl = get_markup_template('diaspora_message.tpl'); $xmsg = replace_macros($tpl, array('$msg' => $msg)); } else { $conv['messages'] = array($msg); $tpl = get_markup_template('diaspora_conversation.tpl'); $xmsg = replace_macros($tpl, array('$conv' => $conv)); } logger('diaspora_conversation: ' . print_r($xmsg, true), LOGGER_DATA); $slap = 'xml=' . urlencode(urlencode(diaspora_msg_build($xmsg, $owner, $contact, $owner['uprvkey'], $contact['pubkey'], false))); //$slap = 'xml=' . urlencode(diaspora_msg_build($xmsg,$owner,$contact,$owner['uprvkey'],$contact['pubkey'],false)); return diaspora_transmit($owner, $contact, $slap, false); }
function diaspora_profile_change($channel, $recip, $public_batch = false) { $channel_id = $channel['channel_id']; $r = q("SELECT profile.uid AS profile_uid, profile.* , channel.* FROM profile\n\t\tleft join channel on profile.uid = channel.channel_id\n\t\tWHERE channel.channel_id = %d and profile.is_default = 1 ", intval($channel_id)); $profile_visible = perm_is_allowed($channel_id, '', 'view_profile'); if (!$r) { return; } $profile = $r[0]; $handle = xmlify($channel['channel_address'] . '@' . App::get_hostname()); $first = xmlify(strpos($profile['channel_name'], ' ') ? trim(substr($profile['channel_name'], 0, strpos($profile['channel_name'], ' '))) : $profile['channel_name']); $last = xmlify($first === $profile['channel_name'] ? '' : trim(substr($profile['channel_name'], strlen($first)))); $large = xmlify(z_root() . '/photo/profile/300/' . $profile['profile_uid'] . '.jpg'); $medium = xmlify(z_root() . '/photo/profile/100/' . $profile['profile_uid'] . '.jpg'); $small = xmlify(z_root() . '/photo/profile/50/' . $profile['profile_uid'] . '.jpg'); $searchable = xmlify($profile_visible ? 'true' : 'false'); $nsfw = $channel['channel_pageflags'] & (PAGE_ADULT | PAGE_CENSORED) ? 'true' : 'false'; if ($searchable === 'true') { $dob = '1000-00-00'; if ($profile['dob'] && $profile['dob'] != '0000-00-00') { $dob = (intval($profile['dob']) ? intval($profile['dob']) : '1000') . '-' . datetime_convert('UTC', 'UTC', $profile['dob'], 'm-d'); } if ($dob === '1000-00-00') { $dob = ''; } $gender = xmlify($profile['gender']); $about = $profile['about']; require_once 'include/bbcode.php'; $about = xmlify(strip_tags(bbcode($about))); $location = ''; if ($profile['locality']) { $location .= $profile['locality']; } if ($profile['region']) { if ($location) { $location .= ', '; } $location .= $profile['region']; } if ($profile['country_name']) { if ($location) { $location .= ', '; } $location .= $profile['country_name']; } $location = xmlify($location); $tags = ''; if ($profile['keywords']) { $kw = str_replace(',', ' ', $profile['keywords']); $kw = str_replace(' ', ' ', $kw); $arr = explode(' ', $profile['keywords']); if (count($arr)) { for ($x = 0; $x < 5; $x++) { if (trim($arr[$x])) { $tags .= '#' . trim($arr[$x]) . ' '; } } } } $tags = xmlify(trim($tags)); } $tpl = get_markup_template('diaspora_profile.tpl', 'addon/diaspora'); $msg = replace_macros($tpl, array('$handle' => $handle, '$first' => $first, '$last' => $last, '$large' => $large, '$medium' => $medium, '$small' => $small, '$dob' => $dob, '$gender' => $gender, '$about' => $about, '$location' => $location, '$searchable' => $searchable, '$nsfw' => $nsfw, '$tags' => $tags)); logger('profile_change: ' . $msg, LOGGER_ALL, LOG_DEBUG); $slap = 'xml=' . urlencode(urlencode(diaspora_msg_build($msg, $channel, $recip, $channel['channel_prvkey'], $recip['xchan_pubkey'], $public_batch))); return diaspora_queue($channel, $recip, $slap, $public_batch); }
function diaspora_send_mail($item, $owner, $contact) { $a = get_app(); $myaddr = $owner['channel_address'] . '@' . get_app()->get_hostname(); $r = q("select * from conv where id = %d and uid = %d limit 1", intval($item['convid']), intval($item['channel_id'])); if (!count($r)) { logger('diaspora_send_mail: conversation not found.'); return; } $cnv = $r[0]; $conv = array('guid' => xmlify($cnv['guid']), 'subject' => xmlify($cnv['subject']), 'created_at' => xmlify(datetime_convert('UTC', 'UTC', $cnv['created'], 'Y-m-d H:i:s \\U\\T\\C')), 'diaspora_handle' => xmlify($cnv['creator']), 'participant_handles' => xmlify($cnv['recips'])); if (array_key_exists('mail_flags', $item) && $item['mail_flags'] & MAIL_OBSCURED) { $key = get_config('system', 'prvkey'); // if($item['title']) // $item['title'] = crypto_unencapsulate(json_decode_plus($item['title']),$key); if ($item['body']) { $item['body'] = crypto_unencapsulate(json_decode_plus($item['body']), $key); } } $body = bb2diaspora($item['body']); $created = datetime_convert('UTC', 'UTC', $item['created'], 'Y-m-d H:i:s \\U\\T\\C'); $signed_text = $item['mid'] . ';' . $cnv['guid'] . ';' . $body . ';' . $created . ';' . $myaddr . ';' . $cnv['guid']; $sig = base64_encode(rsa_sign($signed_text, $owner['channel_prvkey'], 'sha256')); $msg = array('guid' => xmlify($item['mid']), 'parent_guid' => xmlify($cnv['guid']), 'parent_author_signature' => $item['reply'] ? null : xmlify($sig), 'author_signature' => xmlify($sig), 'text' => xmlify($body), 'created_at' => xmlify($created), 'diaspora_handle' => xmlify($myaddr), 'conversation_guid' => xmlify($cnv['guid'])); if ($item['reply']) { $tpl = get_markup_template('diaspora_message.tpl'); $xmsg = replace_macros($tpl, array('$msg' => $msg)); } else { $conv['messages'] = array($msg); $tpl = get_markup_template('diaspora_conversation.tpl'); $xmsg = replace_macros($tpl, array('$conv' => $conv)); } logger('diaspora_conversation: ' . print_r($xmsg, true), LOGGER_DATA); $slap = 'xml=' . urlencode(urlencode(diaspora_msg_build($xmsg, $owner, $contact, $owner['channel_prvkey'], $contact['xchan_pubkey'], false))); return diaspora_transmit($owner, $contact, $slap, false); }
function profile_change() { $a = get_app(); if (!local_user()) { return; } // $url = $a->get_baseurl() . '/profile/' . $a->user['nickname']; // if($url && strlen(get_config('system','directory_submit_url'))) // proc_run('php',"include/directory.php","$url"); $recips = q("SELECT `id`,`name`,`network`,`pubkey`,`notify` FROM `contact` WHERE `network` = '%s'\n\t\tAND `uid` = %d AND `rel` != %d ", dbesc(NETWORK_DIASPORA), intval(local_user()), intval(CONTACT_IS_SHARING)); if (!count($recips)) { return; } $r = q("SELECT `profile`.`uid` AS `profile_uid`, `profile`.* , `user`.* FROM `profile`\n\t\tINNER JOIN `user` ON `profile`.`uid` = `user`.`uid`\n\t\tWHERE `user`.`uid` = %d AND `profile`.`is-default` = 1 LIMIT 1", intval(local_user())); if (!count($r)) { return; } $profile = $r[0]; $handle = xmlify($a->user['nickname'] . '@' . substr($a->get_baseurl(), strpos($a->get_baseurl(), '://') + 3)); $first = xmlify(strpos($profile['name'], ' ') ? trim(substr($profile['name'], 0, strpos($profile['name'], ' '))) : $profile['name']); $last = xmlify($first === $profile['name'] ? '' : trim(substr($profile['name'], strlen($first)))); $large = xmlify($a->get_baseurl() . '/photo/custom/300/' . $profile['uid'] . '.jpg'); $medium = xmlify($a->get_baseurl() . '/photo/custom/100/' . $profile['uid'] . '.jpg'); $small = xmlify($a->get_baseurl() . '/photo/custom/50/' . $profile['uid'] . '.jpg'); $searchable = xmlify($profile['publish'] && $profile['net-publish'] ? 'true' : 'false'); // $searchable = 'true'; if ($searchable === 'true') { $dob = '1000-00-00'; if ($profile['dob'] && $profile['dob'] != '0000-00-00') { $dob = (intval($profile['dob']) ? intval($profile['dob']) : '1000') . '-' . datetime_convert('UTC', 'UTC', $profile['dob'], 'm-d'); } $gender = xmlify($profile['gender']); $about = xmlify($profile['about']); require_once 'include/bbcode.php'; $about = xmlify(strip_tags(bbcode($about))); $location = ''; if ($profile['locality']) { $location .= $profile['locality']; } if ($profile['region']) { if ($location) { $location .= ', '; } $location .= $profile['region']; } if ($profile['country-name']) { if ($location) { $location .= ', '; } $location .= $profile['country-name']; } $location = xmlify($location); $tags = ''; if ($profile['pub_keywords']) { $kw = str_replace(',', ' ', $profile['pub_keywords']); $kw = str_replace(' ', ' ', $kw); $arr = explode(' ', $profile['pub_keywords']); if (count($arr)) { for ($x = 0; $x < 5; $x++) { if (trim($arr[$x])) { $tags .= '#' . trim($arr[$x]) . ' '; } } } } $tags = xmlify(trim($tags)); } $tpl = get_markup_template('diaspora_profile.tpl'); $msg = replace_macros($tpl, array('$handle' => $handle, '$first' => $first, '$last' => $last, '$large' => $large, '$medium' => $medium, '$small' => $small, '$dob' => $dob, '$gender' => $gender, '$about' => $about, '$location' => $location, '$searchable' => $searchable, '$tags' => $tags)); logger('profile_change: ' . $msg, LOGGER_ALL); foreach ($recips as $recip) { $msgtosend = 'xml=' . urlencode(urlencode(diaspora_msg_build($msg, $a->user, $recip, $a->user['prvkey'], $recip['pubkey'], false))); add_to_queue($recip['id'], NETWORK_DIASPORA, $msgtosend, false); } }