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 guid = '%s' and uid = %d limit 1", intval($item['conv_guid']), intval($item['channel_id'])); if (!count($r)) { logger('diaspora_send_mail: conversation not found.'); return; } $cnv = $r[0]; $cnv['subject'] = base64url_decode(str_rot47($cnv['subject'])); $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_obscured', $item) && intval($item['mail_obscured'])) { if ($item['title']) { $item['title'] = base64url_decode(str_rot47($item['title'])); } if ($item['body']) { $item['body'] = base64url_decode(str_rot47($item['body'])); } } $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_queue($owner, $contact, $slap, false, $item['mid']); }