diff options
Diffstat (limited to 'include')
-rw-r--r-- | include/bbcode.php | 9 | ||||
-rw-r--r-- | include/conversation.php | 53 | ||||
-rw-r--r-- | include/datetime.php | 6 | ||||
-rw-r--r-- | include/enotify.php | 3 | ||||
-rw-r--r-- | include/follow.php | 243 | ||||
-rw-r--r-- | include/profile_advanced.php | 5 | ||||
-rw-r--r-- | include/text.php | 1 |
7 files changed, 301 insertions, 19 deletions
diff --git a/include/bbcode.php b/include/bbcode.php index 85d310b75..efc362880 100644 --- a/include/bbcode.php +++ b/include/bbcode.php @@ -52,6 +52,8 @@ function bb_unspacefy_and_trim($st) { function bbcode($Text,$preserve_nl = false) { + $a = get_app(); + // Hide all [noparse] contained bbtags spacefying them $Text = preg_replace_callback("/\[noparse\](.*?)\[\/noparse\]/ism", 'bb_spacefy',$Text); @@ -114,6 +116,11 @@ function bbcode($Text,$preserve_nl = false) { $Text = preg_replace("/\[url\=([$URLSearchString]*)\](.*?)\[\/url\]/ism", '<a href="$1" target="external-link">$2</a>', $Text); //$Text = preg_replace("/\[url\=([$URLSearchString]*)\]([$URLSearchString]*)\[\/url\]/ism", '<a href="$1" target="_blank">$2</a>', $Text); + // we may need to restrict this further if it picks up too many strays + // link acct:user@host to a webfinger profile redirector + + $Text = preg_replace('/acct:(.*?)@(.*?)([ ,])/', '<a href="' . $a->get_baseurl() . '/acctlink?addr=' . "$1@$2" + . '" target="extlink" >acct:' . "$1@$2$3" . '</a>',$Text); // Perform MAIL Search $Text = preg_replace("/\[mail\]([$MAILSearchString]*)\[\/mail\]/", '<a href="mailto:$1">$1</a>', $Text); @@ -226,7 +233,7 @@ function bbcode($Text,$preserve_nl = false) { $endlessloop = 0; while ((strpos($Text, "[/quote]")!== false) and (strpos($Text, "[quote=") !== false) and (++$endlessloop < 20)) $Text = preg_replace("/\[quote=[\"\']*(.*?)[\"\']*\](.*?)\[\/quote\]/ism", - "<br /><strong class=".'"author"'.">" . $t_wrote . "</strong><blockquote class=".'"author"'.">$2</blockquote>", + "<br /><strong class=".'"author"'.">" . $t_wrote . "</strong><blockquote>$2</blockquote>", $Text); // [img=widthxheight]image source[/img] diff --git a/include/conversation.php b/include/conversation.php index dc574ddff..a9c6287a9 100644 --- a/include/conversation.php +++ b/include/conversation.php @@ -173,6 +173,12 @@ function localize_item(&$item){ $item['body'] = str_replace($mtch[0],'@[url=' . zrl($mtch[1]). ']',$item['body']); } } + if(preg_match_all('/\[url=(.*?)\/photos\/(.*?)\/image\/(.*?)\]\[img(.*?)\]h(.*?)\[\/img\]\[\/url\]/is',$item['body'],$matches,PREG_SET_ORDER)) { +logger('matched'); + foreach($matches as $mtch) { + $item['body'] = str_replace($mtch[0],'[url=' . zrl($mtch[1] . '/photos/' . $mtch[2] . '/image/' . $mtch[3] ,true) . '][img' . $mtch[4] . ']h' . $mtch[5] . '[/img][/url]',$item['body']); + } + } } @@ -496,7 +502,7 @@ function conversation(&$a, $items, $mode, $update, $preview = false) { // On the network page, I am the owner. On the display page it will be the profile owner. // This will have been stored in $a->page_contact by our calling page. - // Put this person on the left of the wall-to-wall notice. + // Put this person as the wall owner of the wall-to-wall notice. $owner_url = zrl($a->page_contact['url']); $owner_photo = $a->page_contact['thumb']; @@ -504,23 +510,38 @@ function conversation(&$a, $items, $mode, $update, $preview = false) { $template = $wallwall; $commentww = 'ww'; } - if((! $item['wall']) && (strlen($item['owner-link'])) && (! link_compare($item['owner-link'],$item['author-link']))) { - // Could be anybody. - - $owner_url = $item['owner-link']; - $owner_photo = $item['owner-avatar']; - $owner_name = $item['owner-name']; - $template = $wallwall; - $commentww = 'ww'; - // If it is our contact, use a friendly redirect link - if((link_compare($item['owner-link'],$item['url'])) - && ($item['network'] === NETWORK_DFRN)) { - $owner_url = $redirect_url; - $osparkle = ' sparkle'; + if((! $item['wall']) && $item['owner-link']) { + + $owner_linkmatch = (($item['owner-link']) && link_compare($item['owner-link'],$item['author-link'])); + $alias_linkmatch = (($item['alias']) && link_compare($item['alias'],$item['author-link'])); + $owner_namematch = (($item['owner-name']) && $item['owner-name'] == $item['author-name']); + if((! $owner_linkmatch) && (! $alias_linkmatch) && (! $owner_namematch)) { + + // The author url doesn't match the owner (typically the contact) + // and also doesn't match the contact alias. + // The name match is a hack to catch several weird cases where URLs are + // all over the park. It can be tricked, but this prevents you from + // seeing "Bob Smith to Bob Smith via Wall-to-wall" and you know darn + // well that it's the same Bob Smith. + + // But it could be somebody else with the same name. It just isn't highly likely. + + + $owner_url = $item['owner-link']; + $owner_photo = $item['owner-avatar']; + $owner_name = $item['owner-name']; + $template = $wallwall; + $commentww = 'ww'; + // If it is our contact, use a friendly redirect link + if((link_compare($item['owner-link'],$item['url'])) + && ($item['network'] === NETWORK_DFRN)) { + $owner_url = $redirect_url; + $osparkle = ' sparkle'; + } + else + $owner_url = zrl($owner_url); } - else - $owner_url = zrl($owner_url); } } diff --git a/include/datetime.php b/include/datetime.php index f4dcfce62..3b1491e4d 100644 --- a/include/datetime.php +++ b/include/datetime.php @@ -244,7 +244,7 @@ function timesel($pre,$h,$m) { // Limited to range of timestamps if(! function_exists('relative_date')) { -function relative_date($posted_date) { +function relative_date($posted_date,$format = null) { $localtime = datetime_convert('UTC',date_default_timezone_get(),$posted_date); @@ -274,7 +274,9 @@ function relative_date($posted_date) { if ($d >= 1) { $r = round($d); // translators - e.g. 22 hours ago, 1 minute ago - return sprintf( t('%1$d %2$s ago'),$r, (($r == 1) ? $str[0] : $str[1])); + if(! $format) + $format = t('%1$d %2$s ago'); + return sprintf( $format,$r, (($r == 1) ? $str[0] : $str[1])); } } }} diff --git a/include/enotify.php b/include/enotify.php index f7ef74fac..fe0f128b6 100644 --- a/include/enotify.php +++ b/include/enotify.php @@ -20,6 +20,9 @@ function notification($params) { $sender_name = $product; $hostname = $a->get_hostname(); + if(strpos($hostname,':')) + $hostname = substr($hostname,0,strpos($hostname,':')); + $sender_email = t('noreply') . '@' . $hostname; $additional_mail_header = ""; diff --git a/include/follow.php b/include/follow.php new file mode 100644 index 000000000..d92d7577d --- /dev/null +++ b/include/follow.php @@ -0,0 +1,243 @@ +<?php + + +// +// Takes a $uid and a url/handle and adds a new contact +// Currently if the contact is DFRN, interactive needs to be true, to redirect to the +// dfrn_request page. + +// Otherwise this can be used to bulk add statusnet contacts, twitter contacts, etc. +// Returns an array +// $return['success'] boolean true if successful +// $return['message'] error text if success is false. + + + +function new_contact($uid,$url,$interactive = false) { + + $result = array('success' => false,'message' => ''); + + $a = get_app(); + + // remove ajax junk, e.g. Twitter + + $url = str_replace('/#!/','/',$url); + + if(! allowed_url($url)) { + $result['message'] = t('Disallowed profile URL.'); + return $result; + } + + if(! $url) { + $result['message'] = t('Connect URL missing.'); + return $result; + } + + $arr = array('url' => $url, 'contact' => array()); + + call_hooks('follow', $arr); + + if(x($arr['contact'],'name')) + $ret = $arr['contact']; + else + $ret = probe_url($url); + + if($ret['network'] === NETWORK_DFRN) { + if($interactive) { + if(strlen($a->path)) + $myaddr = bin2hex($a->get_baseurl() . '/profile/' . $a->user['nickname']); + else + $myaddr = bin2hex($a->user['nickname'] . '@' . $a->get_hostname()); + + goaway($ret['request'] . "&addr=$myaddr"); + + // NOTREACHED + } + } + else { + if(get_config('system','dfrn_only')) { + $result['message'] = t('This site is not configured to allow communications with other networks.') . EOL; + $result['message'] != t('No compatible communication protocols or feeds were discovered.') . EOL; + return $result; + } + } + + // This extra param just confuses things, remove it + if($ret['network'] === NETWORK_DIASPORA) + $ret['url'] = str_replace('?absolute=true','',$ret['url']); + + + // do we have enough information? + + if(! ((x($ret,'name')) && (x($ret,'poll')) && ((x($ret,'url')) || (x($ret,'addr'))))) { + $result['message'] .= t('The profile address specified does not provide adequate information.') . EOL; + if(! x($ret,'poll')) + $result['message'] .= t('No compatible communication protocols or feeds were discovered.') . EOL; + if(! x($ret,'name')) + $result['message'] .= t('An author or name was not found.') . EOL; + if(! x($ret,'url')) + $result['message'] .= t('No browser URL could be matched to this address.') . EOL; + if(strpos($url,'@') !== false) { + $result['message'] .= t('Unable to match @-style Identity Address with a known protocol or email contact.') . EOL; + $result['message'] .= t('Use mailto: in front of address to force email check.') . EOL; + } + return $result; + } + + if($ret['network'] === NETWORK_OSTATUS && get_config('system','ostatus_disabled')) { + $result['message'] .= t('The profile address specified belongs to a network which has been disabled on this site.') . EOL; + $ret['notify'] = ''; + } + + if(! $ret['notify']) { + $result['message'] .= t('Limited profile. This person will be unable to receive direct/personal notifications from you.') . EOL; + } + + $writeable = ((($ret['network'] === NETWORK_OSTATUS) && ($ret['notify'])) ? 1 : 0); + $hidden = (($ret['network'] === NETWORK_MAIL) ? 1 : 0); + + if($ret['network'] === NETWORK_MAIL) { + $writeable = 1; + + } + if($ret['network'] === NETWORK_DIASPORA) + $writeable = 1; + + // check if we already have a contact + // the poll url is more reliable than the profile url, as we may have + // indirect links or webfinger links + + $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `poll` = '%s' LIMIT 1", + intval($uid), + dbesc($ret['poll']) + ); + + + if(count($r)) { + // update contact + if($r[0]['rel'] == CONTACT_IS_FOLLOWER || ($network === NETWORK_DIASPORA && $r[0]['rel'] == CONTACT_IS_SHARING)) { + q("UPDATE `contact` SET `rel` = %d , `readonly` = 0 WHERE `id` = %d AND `uid` = %d LIMIT 1", + intval(CONTACT_IS_FRIEND), + intval($r[0]['id']), + intval($uid) + ); + } + } + else { + + $new_relation = (($ret['network'] === NETWORK_MAIL) ? CONTACT_IS_FRIEND : CONTACT_IS_SHARING); + if($ret['network'] === NETWORK_DIASPORA) + $new_relation = CONTACT_IS_FOLLOWER; + + // create contact record + $r = q("INSERT INTO `contact` ( `uid`, `created`, `url`, `nurl`, `addr`, `alias`, `batch`, `notify`, `poll`, `poco`, `name`, `nick`, `photo`, `network`, `pubkey`, `rel`, `priority`, + `writable`, `hidden`, `blocked`, `readonly`, `pending` ) + VALUES ( %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d, %d, %d, %d, 0, 0, 0 ) ", + intval($uid), + dbesc(datetime_convert()), + dbesc($ret['url']), + dbesc(normalise_link($ret['url'])), + dbesc($ret['addr']), + dbesc($ret['alias']), + dbesc($ret['batch']), + dbesc($ret['notify']), + dbesc($ret['poll']), + dbesc($ret['poco']), + dbesc($ret['name']), + dbesc($ret['nick']), + dbesc($ret['photo']), + dbesc($ret['network']), + dbesc($ret['pubkey']), + intval($new_relation), + intval($ret['priority']), + intval($writeable), + intval($hidden) + ); + } + + $r = q("SELECT * FROM `contact` WHERE `url` = '%s' AND `uid` = %d LIMIT 1", + dbesc($ret['url']), + intval($uid) + ); + + if(! count($r)) { + $result['message'] .= t('Unable to retrieve contact information.') . EOL; + return $result; + } + + $contact = $r[0]; + $contact_id = $r[0]['id']; + + + $g = q("select def_gid from user where uid = %d limit 1", + intval($uid) + ); + if($g && intval($g[0]['def_gid'])) { + require_once('include/group.php'); + group_add_member($uid,'',$contact_id,$g[0]['def_gid']); + } + + require_once("Photo.php"); + + $photos = import_profile_photo($ret['photo'],$uid,$contact_id); + + $r = q("UPDATE `contact` SET `photo` = '%s', + `thumb` = '%s', + `micro` = '%s', + `name-date` = '%s', + `uri-date` = '%s', + `avatar-date` = '%s' + WHERE `id` = %d LIMIT 1 + ", + dbesc($photos[0]), + dbesc($photos[1]), + dbesc($photos[2]), + dbesc(datetime_convert()), + dbesc(datetime_convert()), + dbesc(datetime_convert()), + intval($contact_id) + ); + + + // pull feed and consume it, which should subscribe to the hub. + + proc_run('php',"include/poller.php","$contact_id"); + + // create a follow slap + + $tpl = get_markup_template('follow_slap.tpl'); + $slap = replace_macros($tpl, array( + '$name' => $a->user['username'], + '$profile_page' => $a->get_baseurl() . '/profile/' . $a->user['nickname'], + '$photo' => $a->contact['photo'], + '$thumb' => $a->contact['thumb'], + '$published' => datetime_convert('UTC','UTC', 'now', ATOM_TIME), + '$item_id' => 'urn:X-dfrn:' . $a->get_hostname() . ':follow:' . random_string(), + '$title' => '', + '$type' => 'text', + '$content' => t('following'), + '$nick' => $a->user['nickname'], + '$verb' => ACTIVITY_FOLLOW, + '$ostat_follow' => '' + )); + + $r = q("SELECT `contact`.*, `user`.* FROM `contact` LEFT JOIN `user` ON `contact`.`uid` = `user`.`uid` + WHERE `user`.`uid` = %d AND `contact`.`self` = 1 LIMIT 1", + intval($uid) + ); + + if(count($r)) { + if(($contact['network'] == NETWORK_OSTATUS) && (strlen($contact['notify']))) { + require_once('include/salmon.php'); + slapper($r[0],$contact['notify'],$slap); + } + if($contact['network'] == NETWORK_DIASPORA) { + require_once('include/diaspora.php'); + $ret = diaspora_share($a->user,$contact); + logger('mod_follow: diaspora_share returns: ' . $ret); + } + } + + $result['success'] = true; + return $result; +} diff --git a/include/profile_advanced.php b/include/profile_advanced.php index 8c2acd8e7..ffb45090b 100644 --- a/include/profile_advanced.php +++ b/include/profile_advanced.php @@ -39,11 +39,16 @@ function advanced_profile(&$a) { if($a->profile['with']) $profile['marital']['with'] = $a->profile['with']; + if(strlen($a->profile['howlong']) && $a->profile['howlong'] !== '0000-00-00 00:00:00') { + $profile['howlong'] = relative_date($a->profile['howlong'], t('for %1$d %2$s')); + } if($a->profile['sexual']) $profile['sexual'] = array( t('Sexual Preference:'), $a->profile['sexual'] ); if($a->profile['homepage']) $profile['homepage'] = array( t('Homepage:'), linkify($a->profile['homepage']) ); + if($a->profile['hometown']) $profile['hometown'] = array( t('Hometown:'), linkify($a->profile['hometown']) ); + if($a->profile['pub_keywords']) $profile['pub_keywords'] = array( t('Tags:'), $a->profile['pub_keywords']); if($a->profile['politic']) $profile['politic'] = array( t('Political Views:'), $a->profile['politic']); diff --git a/include/text.php b/include/text.php index 376ac473d..d4a4d5580 100644 --- a/include/text.php +++ b/include/text.php @@ -891,6 +891,7 @@ function prepare_body($item,$attach = false) { } else $s = prepare_text($item['body']); + $prep_arr = array('item' => $item, 'html' => $s); call_hooks('prepare_body', $prep_arr); $s = $prep_arr['html']; |