diff options
Diffstat (limited to 'include')
-rw-r--r-- | include/Contact.php | 2 | ||||
-rw-r--r-- | include/ItemObject.php | 11 | ||||
-rw-r--r-- | include/account.php | 95 | ||||
-rw-r--r-- | include/apps.php | 30 | ||||
-rw-r--r-- | include/bb2diaspora.php | 296 | ||||
-rw-r--r-- | include/conversation.php | 16 | ||||
-rw-r--r-- | include/datetime.php | 2 | ||||
-rwxr-xr-x | include/dba/dba_driver.php | 8 | ||||
-rwxr-xr-x | include/diaspora.php | 356 | ||||
-rw-r--r-- | include/dir_fns.php | 4 | ||||
-rw-r--r-- | include/event.php | 24 | ||||
-rw-r--r-- | include/externals.php | 4 | ||||
-rw-r--r-- | include/follow.php | 12 | ||||
-rw-r--r-- | include/identity.php | 29 | ||||
-rwxr-xr-x | include/items.php | 97 | ||||
-rw-r--r-- | include/message.php | 2 | ||||
-rw-r--r-- | include/network.php | 49 | ||||
-rw-r--r-- | include/onepoll.php | 2 | ||||
-rwxr-xr-x | include/plugin.php | 87 | ||||
-rw-r--r-- | include/poller.php | 21 | ||||
-rw-r--r-- | include/socgraph.php | 31 | ||||
-rw-r--r-- | include/text.php | 30 | ||||
-rw-r--r-- | include/zot.php | 4 |
23 files changed, 596 insertions, 616 deletions
diff --git a/include/Contact.php b/include/Contact.php index a9e737bde..0590f9d1e 100644 --- a/include/Contact.php +++ b/include/Contact.php @@ -484,7 +484,7 @@ function contact_remove($channel_id, $abook_id) { ); if($r) { foreach($r as $rr) { - drop_item($rr,false); + drop_item($rr['id'],false); } } diff --git a/include/ItemObject.php b/include/ItemObject.php index a5870ef91..451e369b0 100644 --- a/include/ItemObject.php +++ b/include/ItemObject.php @@ -90,6 +90,10 @@ class Item extends BaseObject { : false); $shareable = ((($conv->get_profile_owner() == local_user()) && ($item['item_private'] != 1)) ? true : false); + // allow an exemption for sharing stuff from your private feeds + if($item['author']['xchan_network'] === 'rss') + $shareable = true; + $mode = $conv->get_mode(); if(local_user() && $observer['xchan_hash'] === $item['author_xchan']) @@ -207,10 +211,11 @@ class Item extends BaseObject { if($this->is_commentable()) { $like = array( t("I like this \x28toggle\x29"), t("like")); $dislike = array( t("I don't like this \x28toggle\x29"), t("dislike")); - if ($shareable) - $share = array( t('Share This'), t('share')); } + if ($shareable) + $share = array( t('Share This'), t('share')); + if(strcmp(datetime_convert('UTC','UTC',$item['created']),datetime_convert('UTC','UTC','now - 12 hours')) > 0) $indent .= ' shiny'; @@ -251,7 +256,7 @@ class Item extends BaseObject { 'isotime' => datetime_convert('UTC', date_default_timezone_get(), $item['created'], 'c'), 'localtime' => datetime_convert('UTC', date_default_timezone_get(), $item['created'], 'r'), 'editedtime' => (($item['edited'] != $item['created']) ? sprintf( t('last edited: %s'), datetime_convert('UTC', date_default_timezone_get(), $item['edited'], 'r')) : ''), - 'expiretime' => (($item['expires'] !== '0000-00-00 00:00:00') ? sprintf( t('Expires: %s'), datetime_convert('UTC', date_default_timezone_get(), $item['expires'], 'r')):''), + 'expiretime' => (($item['expires'] !== NULL_DATE) ? sprintf( t('Expires: %s'), datetime_convert('UTC', date_default_timezone_get(), $item['expires'], 'r')):''), 'lock' => $lock, 'verified' => $verified, 'unverified' => $unverified, diff --git a/include/account.php b/include/account.php index 4ded069d5..9b4dc409c 100644 --- a/include/account.php +++ b/include/account.php @@ -108,7 +108,7 @@ function create_account($arr) { $parent = ((x($arr,'parent')) ? intval($arr['parent']) : 0 ); $flags = ((x($arr,'account_flags')) ? intval($arr['account_flags']) : ACCOUNT_OK); $roles = ((x($arr,'account_roles')) ? intval($arr['account_roles']) : 0 ); - $expires = ((x($arr,'expires')) ? intval($arr['expires']) : '0000-00-00 00:00:00'); + $expires = ((x($arr,'expires')) ? intval($arr['expires']) : NULL_DATE); $default_service_class = get_config('system','default_service_class'); @@ -511,8 +511,9 @@ function user_approve($hash) { function downgrade_accounts() { $r = q("select * from account where not ( account_flags & %d ) - and account_expires != '0000-00-00 00:00:00' + and account_expires != '%s' and account_expires < UTC_TIMESTAMP() ", + dbesc(NULL_DATE), intval(ACCOUNT_EXPIRED) ); @@ -528,7 +529,7 @@ function downgrade_accounts() { $x = q("UPDATE account set account_service_class = '%s', account_expires = '%s' where account_id = %d limit 1", dbesc($basic), - dbesc('0000-00-00 00:00:00'), + dbesc(NULL_DATE), intval($rr['account_id']) ); $ret = array('account' => $rr); @@ -547,3 +548,91 @@ function downgrade_accounts() { } } + + +// check service_class restrictions. If there are no service_classes defined, everything is allowed. +// if $usage is supplied, we check against a maximum count and return true if the current usage is +// less than the subscriber plan allows. Otherwise we return boolean true or false if the property +// is allowed (or not) in this subscriber plan. An unset property for this service plan means +// the property is allowed, so it is only necessary to provide negative properties for each plan, +// or what the subscriber is not allowed to do. + + +function service_class_allows($uid,$property,$usage = false) { + $a = get_app(); + if($uid == local_user()) { + $service_class = $a->account['account_service_class']; + } + else { + $r = q("select account_service_class as service_class + from channel c, account a + where c.channel_account_id=a.account_id and c.channel_id= %d limit 1", + intval($uid) + ); + if($r !== false and count($r)) { + $service_class = $r[0]['service_class']; + } + } + if(! x($service_class)) + return true; // everything is allowed + + $arr = get_config('service_class',$service_class); + if(! is_array($arr) || (! count($arr))) + return true; + + if($usage === false) + return ((x($arr[$property])) ? (bool) $arr[$property] : true); + else { + if(! array_key_exists($property,$arr)) + return true; + return (((intval($usage)) < intval($arr[$property])) ? true : false); + } +} + + +function service_class_fetch($uid,$property) { + $a = get_app(); + if($uid == local_user()) { + $service_class = $a->account['account_service_class']; + } + else { + $r = q("select account_service_class as service_class + from channel c, account a + where c.channel_account_id=a.account_id and c.channel_id= %d limit 1", + intval($uid) + ); + if($r !== false and count($r)) { + $service_class = $r[0]['service_class']; + } + } + if(! x($service_class)) + return false; // everything is allowed + + $arr = get_config('service_class',$service_class); + + if(! is_array($arr) || (! count($arr))) + return false; + + return((array_key_exists($property,$arr)) ? $arr[$property] : false); +} + +function upgrade_link($bbcode = false) { + $l = get_config('service_class','upgrade_link'); + if(! $l) + return ''; + if($bbcode) + $t = sprintf('[zrl=%s]' . t('Click here to upgrade.') . '[/zrl]', $l); + else + $t = sprintf('<a href="%s">' . t('Click here to upgrade.') . '</div>', $l); + return $t; +} + +function upgrade_message($bbcode = false) { + $x = upgrade_link($bbcode); + return t('This action exceeds the limits set by your subscription plan.') . (($x) ? ' ' . $x : '') ; +} + +function upgrade_bool_message($bbcode = false) { + $x = upgrade_link($bbcode); + return t('This action is not available under your subscription plan.') . (($x) ? ' ' . $x : '') ; +} diff --git a/include/apps.php b/include/apps.php index 7ac4c7e4b..91012b0ef 100644 --- a/include/apps.php +++ b/include/apps.php @@ -470,33 +470,3 @@ function papp_encode($papp) { } -/** - * install a shared design element (layout, webpage, block, menu, whatever) - * - */ - -function element_install($channel,$s) { - - $ret = array('success' => false); - - $s = str_replace(array('[element]','[/element]'),array('',''),$s); - $s = base64url_decode($s); - if(! $s) - return $ret; - $x = json_decode($s,true); - if(! $x) - return $ret; - - $d = array(); - - - - - - - - - $result = item_store($d); - -} - diff --git a/include/bb2diaspora.php b/include/bb2diaspora.php index f15a34e99..0f91c8bc8 100644 --- a/include/bb2diaspora.php +++ b/include/bb2diaspora.php @@ -77,6 +77,25 @@ function share_unshield($m) { } +function diaspora_mention_callback($matches) { + + $webbie = $matches[2]; + $link = ''; + if($webbie) { + $r = q("select * from hubloc left join xchan on hubloc_hash = xchan_hash where hubloc_addr = '%s' limit 1", + dbesc($webbie) + ); + if($r) + $link = $r[0]['xchan_url']; + } + if(! $link) + $link = 'https://' . $matches[3] . '/u/' . $matches[2]; + + return '@[url=' . $link . ']' . trim($matches[1]) . ((substr($mentions[0],-1,1) === '+') ? '+' : '') . '[/url]' ; + +} + + // we don't want to support a bbcode specific markdown interpreter // and the markdown library we have is pretty good, but provides HTML output. @@ -97,7 +116,12 @@ function diaspora2bb($s,$use_zrl = false) { $s = str_replace("<br/>","<br />",$s); $s = str_replace("\n","<br />",$s); - $s = preg_replace('/\@\{(.+?)\; (.+?)\@(.+?)\}/','@[url=https://$3/u/$2]$1[/url]',$s); + +// $s = preg_replace('/\@\{(.+?)\; (.+?)\@(.+?)\}/','@[url=https://$3/u/$2]$1[/url]',$s); + + // first try plustags + $s = preg_replace_callback('/\@\{(.+?)\; (.+?)\@(.+?)\}\+/','diaspora_mention_callback',$s); + $s = preg_replace_callback('/\@\{(.+?)\; (.+?)\@(.+?)\}/','diaspora_mention_callback',$s); // Escaping the hash tags - doesn't always seem to work // $s = preg_replace('/\#([^\s\#])/','\\#$1',$s); @@ -211,6 +235,80 @@ function diaspora_ol($s) { return preg_replace("/\[\\\\\*\]( *)/", "1. ", $s[1]); } +function bb2dmention_callback($match) { + + $r = q("select xchan_addr from xchan where xchan_url = '%s'", + dbesc($match[2]) + ); + + if($r) + return '@{' . $match[3] . ' ; ' . $r[0]['xchan_addr'] . '}'; + return '@' . $match[3]; + +} + + + +function bb2diaspora_itembody($item) { + + if($item['diaspora_meta']) { + $j = json_decode($item['diaspora_meta'],true); + if($j && $j['body']) { + logger('bb2diaspora_itembody: cached '); + return $j['body']; + } + } + + $body = $item['body']; + + if(array_key_exists('item_flags',$item) && ($item['item_flags'] & ITEM_OBSCURED)) { + $key = get_config('system','prvkey'); + $title = (($item['title']) ? crypto_unencapsulate(json_decode($item['title'],true),$key) : ''); + $body = (($item['body']) ? crypto_unencapsulate(json_decode($item['body'],true),$key) : ''); + } + + $body = preg_replace('/\#\^http/i', 'http', $body); + + // protect tags and mentions from hijacking + + if(intval(get_pconfig($item['uid'],'system','prevent_tag_hijacking'))) { + $new_tag = html_entity_decode('⋕',ENT_COMPAT,'UTF-8'); + $new_mention = html_entity_decode('@',ENT_COMPAT,'UTF-8'); + + // #-tags + $body = preg_replace('/\#\[url/i', $new_tag . '[url', $body); + $body = preg_replace('/\#\[zrl/i', $new_tag . '[zrl', $body); + // @-mentions + $body = preg_replace('/\@\!?\[url/i', $new_mention . '[url', $body); + $body = preg_replace('/\@\!?\[zrl/i', $new_mention . '[zrl', $body); + } + + // remove multiple newlines + do { + $oldbody = $body; + $body = str_replace("\n\n\n", "\n\n", $body); + } while ($oldbody != $body); + + $body = bb2diaspora($body); + + if(strlen($title)) + $body = "## " . $title . "\n\n" . $body; + + if($item['attach']) { + $cnt = preg_match_all('/href=\"(.*?)\"(.*?)title=\"(.*?)\"/ism',$item['attach'],$matches,PREG_SET_ORDER); + if(cnt) { + $body .= "\n" . t('Attachments:') . "\n"; + foreach($matches as $mtch) { + $body .= '[' . $mtch[3] . '](' . $mtch[1] . ')' . "\n"; + } + } + } + + logger('bb2diaspora_itembody : ' . $body); + + return html_entity_decode($body); + +} function bb2diaspora($Text,$preserve_nl = false, $fordiaspora = true) { @@ -221,10 +319,14 @@ function bb2diaspora($Text,$preserve_nl = false, $fordiaspora = true) { /** * Transform #tags, strip off the [url] and replace spaces with underscore */ - $Text = preg_replace_callback('/#\[url\=(\w+.*?)\](\w+.*?)\[\/url\]/i', create_function('$match', - 'return \'#\'. str_replace(\' \', \'_\', $match[2]);' + $Text = preg_replace_callback('/#\[([zu])rl\=(\w+.*?)\](\w+.*?)\[\/[(zu)]rl\]/i', create_function('$match', + 'return \'#\'. str_replace(\' \', \'_\', $match[3]);' ), $Text); + $Text = preg_replace('/#\^\[([zu])rl\=(\w+.*?)\](\w+.*?)\[\/([zu])rl\]/i', '[$1rl=$2]$3[/$4rl]', $Text); + + $Text = preg_replace_callback('/\@\!?\[([zu])rl\=(\w+.*?)\](\w+.*?)\[\/([zu])rl\]/i', 'bb2dmention_callback', $Text); + // Converting images with size parameters to simple images. Markdown doesn't know it. $Text = preg_replace("/\[img\=([0-9]*)x([0-9]*)\](.*?)\[\/img\]/ism", '[img]$3[/img]', $Text); @@ -252,195 +354,9 @@ function bb2diaspora($Text,$preserve_nl = false, $fordiaspora = true) { // Remove all unconverted tags $Text = strip_tags($Text); - -/* Old routine - - $ev = bbtoevent($Text); - - // Replace any html brackets with HTML Entities to prevent executing HTML or script - // Don't use strip_tags here because it breaks [url] search by replacing & with amp - - $Text = str_replace("<", "<", $Text); - $Text = str_replace(">", ">", $Text); - - // If we find any event code, turn it into an event. - // After we're finished processing the bbcode we'll - // replace all of the event code with a reformatted version. - - if($preserve_nl) - $Text = str_replace(array("\n","\r"), array('',''),$Text); - else - // Remove the "return" character, as Diaspora uses only the "newline" - // character, so having the "return" character can cause signature - // failures - $Text = str_replace("\r", "", $Text); - - - // Set up the parameters for a URL search string - $URLSearchString = "^\[\]"; - // Set up the parameters for a MAIL search string - $MAILSearchString = $URLSearchString; - - // Perform URL Search - - // [img]pathtoimage[/img] - - // the following was added on 10-January-2012 due to an inability of Diaspora's - // new javascript markdown processor to handle links with images as the link "text" - // It is not optimal and may be removed if this ability is restored in the future - - $Text = preg_replace("/\[url\=([$URLSearchString]*)\]\[img\](.*?)\[\/img\]\[\/url\]/ism", - '![' . t('image/photo') . '](' . '$2' . ')' . "\n" . '[' . t('link') . '](' . '$1' . ')', $Text); - - $Text = preg_replace("/\[bookmark\]([$URLSearchString]*)\[\/bookmark\]/ism", '[$1]($1)', $Text); - $Text = preg_replace("/\[bookmark\=([$URLSearchString]*)\](.*?)\[\/bookmark\]/ism", '[$2]($1)', $Text); - - $Text = preg_replace("/\[url\]([$URLSearchString]*)\[\/url\]/ism", '[$1]($1)', $Text); - $Text = preg_replace("/\#\[url\=([$URLSearchString]*)\](.*?)\[\/url\]/ism", '[#$2]($1)', $Text); - $Text = preg_replace("/\[url\=([$URLSearchString]*)\](.*?)\[\/url\]/ism", '[$2]($1)', $Text); - - - $Text = preg_replace("/\[img\](.*?)\[\/img\]/", '![' . t('image/photo') . '](' . '$1' . ')', $Text); - $Text = preg_replace("/\[img\=(.*?)\](.*?)\[\/img\]/", '![' . t('image/photo') . '](' . '$2' . ')', $Text); - - $Text = preg_replace("/\[zrl\]([$URLSearchString]*)\[\/zrl\]/ism", '[$1]($1)', $Text); - $Text = preg_replace("/\#\[zrl\=([$URLSearchString]*)\](.*?)\[\/zrl\]/ism", '[#$2]($1)', $Text); - $Text = preg_replace("/\[zrl\=([$URLSearchString]*)\](.*?)\[\/zrl\]/ism", '[$2]($1)', $Text); - - - $Text = preg_replace("/\[zmg\](.*?)\[\/zmg\]/", '![' . t('image/photo') . '](' . '$1' . ')', $Text); - $Text = preg_replace("/\[zmg\=(.*?)\](.*?)\[\/zmg\]/", '![' . t('image/photo') . '](' . '$2' . ')', $Text); - - // Perform MAIL Search - $Text = preg_replace("(\[mail\]([$MAILSearchString]*)\[/mail\])", '[$1](mailto:$1)', $Text); - $Text = preg_replace("/\[mail\=([$MAILSearchString]*)\](.*?)\[\/mail\]/", '[$2](mailto:$1)', $Text); - - $Text = str_replace('*', '\\*', $Text); - $Text = str_replace('_', '\\_', $Text); - - $Text = str_replace('`','\\`', $Text); - - // Check for bold text - $Text = preg_replace("(\[b\](.*?)\[\/b\])is",'**$1**',$Text); - - // Check for italics text - $Text = preg_replace("(\[i\](.*?)\[\/i\])is",'_$1_',$Text); - - // Check for underline text - // Replace with italics since Diaspora doesn't have underline - $Text = preg_replace("(\[u\](.*?)\[\/u\])is",'_$1_',$Text); - - // Check for strike-through text - $Text = preg_replace("(\[s\](.*?)\[\/s\])is",'**[strike]**$1**[/strike]**',$Text); - - // Check for over-line text -// $Text = preg_replace("(\[o\](.*?)\[\/o\])is",'<span class="overline">$1</span>',$Text); - - // Check for colored text - // Remove color since Diaspora doesn't support it - $Text = preg_replace("(\[color=(.*?)\](.*?)\[\/color\])is","$2",$Text); - - // Check for sized text - // Remove it since Diaspora doesn't support sizes very well - $Text = preg_replace("(\[size=(.*?)\](.*?)\[\/size\])is","$2",$Text); - - // Check for list text - $endlessloop = 0; - while ((((strpos($Text, "[/list]") !== false) && (strpos($Text, "[list") !== false)) || - ((strpos($Text, "[/ol]") !== false) && (strpos($Text, "[ol]") !== false)) || - ((strpos($Text, "[/ul]") !== false) && (strpos($Text, "[ul]") !== false)) || - ((strpos($Text, "[/li]") !== false) && (strpos($Text, "[li]") !== false))) && (++$endlessloop < 20)) { - $Text = preg_replace_callback("/\[list\](.*?)\[\/list\]/is", 'diaspora_ul', $Text); - $Text = preg_replace_callback("/\[list=1\](.*?)\[\/list\]/is", 'diaspora_ol', $Text); - $Text = preg_replace_callback("/\[list=i\](.*?)\[\/list\]/s",'diaspora_ol', $Text); - $Text = preg_replace_callback("/\[list=I\](.*?)\[\/list\]/s", 'diaspora_ol', $Text); - $Text = preg_replace_callback("/\[list=a\](.*?)\[\/list\]/s", 'diaspora_ol', $Text); - $Text = preg_replace_callback("/\[list=A\](.*?)\[\/list\]/s", 'diaspora_ol', $Text); - $Text = preg_replace_callback("/\[ul\](.*?)\[\/ul\]/is", 'diaspora_ul', $Text); - $Text = preg_replace_callback("/\[ol\](.*?)\[\/ol\]/is", 'diaspora_ol', $Text); - $Text = preg_replace("/\[li\]( *)(.*?)\[\/li\]/s", '* $2' ,$Text); - } - - // Just get rid of table tags since Diaspora doesn't support tables - $Text = preg_replace("/\[th\](.*?)\[\/th\]/s", '$1' ,$Text); - $Text = preg_replace("/\[td\](.*?)\[\/td\]/s", '$1' ,$Text); - $Text = preg_replace("/\[tr\](.*?)\[\/tr\]/s", '$1' ,$Text); - $Text = preg_replace("/\[table\](.*?)\[\/table\]/s", '$1' ,$Text); - - $Text = preg_replace("/\[table border=(.*?)\](.*?)\[\/table\]/s", '$2' ,$Text); -// $Text = preg_replace("/\[table border=0\](.*?)\[\/table\]/s", '<table border="0" >$1</table>' ,$Text); - - -// $Text = str_replace("[*]", "<li>", $Text); - - // Check for font change text -// $Text = preg_replace("(\[font=(.*?)\](.*?)\[\/font\])","<span style=\"font-family: $1;\">$2</span>",$Text); - - - $Text = preg_replace_callback("/\[code\](.*?)\[\/code\]/is",'stripdcode_br_cb',$Text); - - // Check for [code] text - $Text = preg_replace("/(\[code\])+(.*?)(\[\/code\])+/is","\t$2\n", $Text); - - - - - // Declare the format for [quote] layout - // $QuoteLayout = '<blockquote>$1</blockquote>'; - // Check for [quote] text - $Text = preg_replace("/\[quote\](.*?)\[\/quote\]/is",">$1\n\n", $Text); - $Text = preg_replace("/\[quote=(.*?)\](.*?)\[\/quote\]/is",">$2\n\n", $Text); - - // Images - - // html5 video and audio - - $Text = preg_replace("/\[video\](.*?)\[\/video\]/", '$1', $Text); - - $Text = preg_replace("/\[audio\](.*?)\[\/audio\]/", '$1', $Text); - -// $Text = preg_replace("/\[iframe\](.*?)\[\/iframe\]/", '<iframe src="$1" width="425" height="350"><a href="$1">$1</a></iframe>', $Text); - - // [img=widthxheight]image source[/img] -// $Text = preg_replace("/\[img\=([0-9]*)x([0-9]*)\](.*?)\[\/img\]/", '<img src="$3" style="height:{$2}px; width:{$1}px;" >', $Text); - - $Text = preg_replace("/\[youtube\]https?:\/\/www.youtube.com\/watch\?v\=(.*?)\[\/youtube\]/ism",'http://www.youtube.com/watch?v=$1',$Text); - $Text = preg_replace("/\[youtube\]https?:\/\/www.youtube.com\/embed\/(.*?)\[\/youtube\]/ism",'http://www.youtube.com/watch?v=$1',$Text); - $Text = preg_replace("/\[youtube\]https?:\/\/youtu.be\/(.*?)\[\/youtube\]/ism",'http://www.youtube.com/watch?v=$1',$Text); - $Text = preg_replace("/\[youtube\]([A-Za-z0-9\-_=]+)(.*?)\[\/youtube\]/ism", 'http://www.youtube.com/watch?v=$1', $Text); - - $Text = preg_replace("/\[vimeo\]https?:\/\/player.vimeo.com\/video\/([0-9]+)(.*?)\[\/vimeo\]/ism",'http://vimeo.com/$1',$Text); - $Text = preg_replace("/\[vimeo\]https?:\/\/vimeo.com\/([0-9]+)(.*?)\[\/vimeo\]/ism",'http://vimeo.com/$1',$Text); - $Text = preg_replace("/\[vimeo\]([0-9]+)(.*?)\[\/vimeo\]/ism", 'http://vimeo.com/$1',$Text); - - - $Text = str_replace('[nosmile]','',$Text); - - // oembed tag - // $Text = oembed_bbcode2html($Text); - - // If we found an event earlier, strip out all the event code and replace with a reformatted version. - - if(x($ev,'start')) { - - $sub = format_event_diaspora($ev); - - $Text = preg_replace("/\[event\-summary\](.*?)\[\/event\-summary\]/is",'',$Text); - $Text = preg_replace("/\[event\-description\](.*?)\[\/event\-description\]/is",'',$Text); - $Text = preg_replace("/\[event\-start\](.*?)\[\/event\-start\]/is",$sub,$Text); - $Text = preg_replace("/\[event\-finish\](.*?)\[\/event\-finish\]/is",'',$Text); - $Text = preg_replace("/\[event\-location\](.*?)\[\/event\-location\]/is",'',$Text); - $Text = preg_replace("/\[event\-adjust\](.*?)\[\/event\-adjust\]/is",'',$Text); - } - - $Text = preg_replace("/\<(.*?)(src|href)=(.*?)\&\;(.*?)\>/ism",'<$1$2=$3&$4>',$Text); - - $Text = preg_replace_callback('/\[(.*?)\]\((.*?)\)/ism','unescape_underscores_in_links',$Text); - -*/ - // Remove any leading or trailing whitespace, as this will mess up // the Diaspora signature verification and cause the item to disappear + $Text = trim($Text); call_hooks('bb2diaspora',$Text); diff --git a/include/conversation.php b/include/conversation.php index b14e609dd..05ae72d61 100644 --- a/include/conversation.php +++ b/include/conversation.php @@ -707,7 +707,7 @@ function conversation(&$a, $items, $mode, $update, $page_mode = 'traditional', $ 'isotime' => datetime_convert('UTC', date_default_timezone_get(), $item['created'], 'c'), 'localtime' => datetime_convert('UTC', date_default_timezone_get(), $item['created'], 'r'), 'editedtime' => (($item['edited'] != $item['created']) ? sprintf( t('last edited: %s'), datetime_convert('UTC', date_default_timezone_get(), $item['edited'], 'r')) : ''), - 'expiretime' => (($item['expires'] !== '0000-00-00 00:00:00') ? sprintf( t('Expires: %s'), datetime_convert('UTC', date_default_timezone_get(), $item['expires'], 'r')):''), + 'expiretime' => (($item['expires'] !== NULL_DATE) ? sprintf( t('Expires: %s'), datetime_convert('UTC', date_default_timezone_get(), $item['expires'], 'r')):''), 'location' => $location, 'indent' => '', 'owner_name' => $owner_name, @@ -1417,7 +1417,7 @@ function network_tabs() { if(! get_config('system','disable_discover_tab')) { $tabs[] = array( 'label' => t('Discover'), - 'url'=>$a->get_baseurl(true) . '/' . $cmd . '?f=&fh=1' . ((x($_GET,'cid')) ? '&cid=' . $_GET['cid'] : '') . ((x($_GET,'gid')) ? '&gid=' . $_GET['gid'] : ''), + 'url'=>z_root() . '/' . $cmd . '?f=&fh=1' , 'sel'=> $public_active, 'title'=> t('Imported public streams'), ); @@ -1425,14 +1425,14 @@ function network_tabs() { $tabs[] = array( 'label' => t('Commented Order'), - 'url'=>$a->get_baseurl(true) . '/' . $cmd . '?f=&order=comment' . ((x($_GET,'cid')) ? '&cid=' . $_GET['cid'] : '') . ((x($_GET,'gid')) ? '&gid=' . $_GET['gid'] : ''), + 'url'=>z_root() . '/' . $cmd . '?f=&order=comment' . ((x($_GET,'cid')) ? '&cid=' . $_GET['cid'] : '') . ((x($_GET,'gid')) ? '&gid=' . $_GET['gid'] : ''), 'sel'=>$all_active, 'title'=> t('Sort by Comment Date'), ); $tabs[] = array( 'label' => t('Posted Order'), - 'url'=>$a->get_baseurl(true) . '/' . $cmd . '?f=&order=post' . ((x($_GET,'cid')) ? '&cid=' . $_GET['cid'] : '') . ((x($_GET,'gid')) ? '&gid=' . $_GET['gid'] : ''), + 'url'=>z_root() . '/' . $cmd . '?f=&order=post' . ((x($_GET,'cid')) ? '&cid=' . $_GET['cid'] : '') . ((x($_GET,'gid')) ? '&gid=' . $_GET['gid'] : ''), 'sel'=>$postord_active, 'title' => t('Sort by Post Date'), ); @@ -1440,7 +1440,7 @@ function network_tabs() { if(feature_enabled(local_user(),'personal_tab')) { $tabs[] = array( 'label' => t('Personal'), - 'url' => $a->get_baseurl(true) . '/' . $cmd . '?f=' . ((x($_GET,'cid')) ? '&cid=' . $_GET['cid'] : '') . '&conv=1', + 'url' => z_root() . '/' . $cmd . '?f=' . ((x($_GET,'cid')) ? '&cid=' . $_GET['cid'] : '') . '&conv=1', 'sel' => $conv_active, 'title' => t('Posts that mention or involve you'), ); @@ -1449,7 +1449,7 @@ function network_tabs() { if(feature_enabled(local_user(),'new_tab')) { $tabs[] = array( 'label' => t('New'), - 'url' => $a->get_baseurl(true) . '/' . $cmd . '?f=' . ((x($_GET,'cid')) ? '&cid=' . $_GET['cid'] : '') . '&new=1' . ((x($_GET,'gid')) ? '&gid=' . $_GET['gid'] : ''), + 'url' => z_root() . '/' . $cmd . '?f=' . ((x($_GET,'cid')) ? '&cid=' . $_GET['cid'] : '') . '&new=1' . ((x($_GET,'gid')) ? '&gid=' . $_GET['gid'] : ''), 'sel' => $new_active, 'title' => t('Activity Stream - by date'), ); @@ -1458,7 +1458,7 @@ function network_tabs() { if(feature_enabled(local_user(),'star_posts')) { $tabs[] = array( 'label' => t('Starred'), - 'url'=>$a->get_baseurl(true) . '/' . $cmd . ((x($_GET,'cid')) ? '/?f=&cid=' . $_GET['cid'] : '') . '&star=1', + 'url'=>z_root() . '/' . $cmd . ((x($_GET,'cid')) ? '/?f=&cid=' . $_GET['cid'] : '') . '&star=1', 'sel'=>$starred_active, 'title' => t('Favourite Posts'), ); @@ -1468,7 +1468,7 @@ function network_tabs() { if(feature_enabled(local_user(),'spam_filter')) { $tabs[] = array( 'label' => t('Spam'), - 'url'=>$a->get_baseurl(true) . '/network?f=&spam=1', + 'url'=> z_root() . '/network?f=&spam=1', 'sel'=> $spam_active, 'title' => t('Posts flagged as SPAM'), ); diff --git a/include/datetime.php b/include/datetime.php index 0214b9e4c..84ab1e2fa 100644 --- a/include/datetime.php +++ b/include/datetime.php @@ -271,7 +271,7 @@ function relative_date($posted_date,$format = null) { $abs = strtotime($localtime); - if (is_null($posted_date) || $posted_date === '0000-00-00 00:00:00' || $abs === False) { + if (is_null($posted_date) || $posted_date === NULL_DATE || $abs === False) { return t('never'); } diff --git a/include/dba/dba_driver.php b/include/dba/dba_driver.php index c829c3714..3e19b7aa4 100755 --- a/include/dba/dba_driver.php +++ b/include/dba/dba_driver.php @@ -112,8 +112,12 @@ function q($sql) { if($db && $db->connected) { $stmt = vsprintf($sql,$args); - if($stmt === false) - logger('dba: vsprintf error: ' . print_r(debug_backtrace(),true)); + if($stmt === false) { + if(version_compare(PHP_VERSION,'5.4.0') >= 0) + logger('dba: vsprintf error: ' . print_r(debug_backtrace(DEBUG_BACKTRACE_PROVIDE_OBJECT,1),true)); + else + logger('dba: vsprintf error: ' . print_r(debug_backtrace(),true)); + } return $db->q($stmt); } diff --git a/include/diaspora.php b/include/diaspora.php index b544dad53..8da256bc5 100755 --- a/include/diaspora.php +++ b/include/diaspora.php @@ -269,8 +269,8 @@ function diaspora_handle_from_contact($contact_hash) { logger("diaspora_handle_from_contact: contact id is " . $contact_hash, LOGGER_DEBUG); - $r = q("SELECT * from abook left join xchan on abook_xchan = xchan_hash where abook_xchan = '%s' limit 1", - intval($contact_hash) + $r = q("SELECT xchan_addr from xchan where xchan_hash = '%s' limit 1", + dbesc($contact_hash) ); if($r) { return $r[0]['xchan_addr']; @@ -689,7 +689,7 @@ function diaspora_request($importer,$xml) { $their_perms = PERMS_R_STREAM|PERMS_R_PROFILE|PERMS_R_PHOTOS|PERMS_R_ABOOK|PERMS_W_STREAM|PERMS_W_COMMENT|PERMS_W_MAIL|PERMS_W_CHAT|PERMS_R_STORAGE|PERMS_R_PAGES; - $r = q("insert into abook ( abook_account, abook_channel, abook_xchan, abook_my_perms, abook_their_perms, abook_closeness, abook_rating, abook_created, abook_updated, abook_connected, abook_dob, abook_flags, abook_profile) values ( %d, %d, '%s' %d %d, %d, %d, '%s', '%s', '%s', '%s', %d, '%s')", + $r = q("insert into abook ( abook_account, abook_channel, abook_xchan, abook_my_perms, abook_their_perms, abook_closeness, abook_rating, abook_created, abook_updated, abook_connected, abook_dob, abook_flags) values ( %d, %d, '%s', %d, %d, %d, %d, '%s', '%s', '%s', '%s', %d )", intval($importer['channel_account_id']), intval($importer['channel_id']), dbesc($ret['xchan_hash']), @@ -700,7 +700,7 @@ function diaspora_request($importer,$xml) { dbesc(datetime_convert()), dbesc(datetime_convert()), dbesc(datetime_convert()), - dbesc('0000-00-00 00:00:00'), + dbesc(NULL_DATE), intval(($default_perms) ? 0 : ABOOK_FLAG_PENDING) ); @@ -805,6 +805,12 @@ function diaspora_post($importer,$xml,$msg) { $body = diaspora2bb($xml->raw_message); + if($xml->photo) { + $body = '[img]' . $xml->photo->remote_photo_path . $xml->photo->remote_photo_name . '[/img]' . "\n\n" . $body; + $body = scale_external_images($body); + } + + //WTF? FIXME // Add OEmbed and other information to the body // $body = add_page_info_to_body($body, false, true); @@ -933,23 +939,13 @@ function diaspora_reshare($importer,$xml,$msg) { } logger('diaspora_reshare: source: ' . $x['body']); - $x = str_replace(array('<activity_streams-photo>','</activity_streams-photo>'),array('<asphoto>','</asphoto>'),$x['body']); - $source_xml = parse_xml_string($x,false); - if(strlen($source_xml->post->asphoto->objectId) && ($source_xml->post->asphoto->objectId != 0) && ($source_xml->post->asphoto->image_url)) { - $body = '[url=' . notags(unxmlify($source_xml->post->asphoto->image_url)) . '][img]' . notags(unxmlify($source_xml->post->asphoto->objectId)) . '[/img][/url]' . "\n"; - $body = scale_external_images($body,false); - } - elseif($source_xml->post->asphoto->image_url) { - $body = '[img]' . notags(unxmlify($source_xml->post->asphoto->image_url)) . '[/img]' . "\n"; - $body = scale_external_images($body); - } - elseif($source_xml->post->status_message) { + if($source_xml->post->status_message) { $body = diaspora2bb($source_xml->post->status_message->raw_message); // Checking for embedded pictures - if($source_xml->post->status_message->photo->remote_photo_path AND + if($source_xml->post->status_message->photo->remote_photo_path && $source_xml->post->status_message->photo->remote_photo_name) { $remote_photo_path = notags(unxmlify($source_xml->post->status_message->photo->remote_photo_path)); @@ -979,12 +975,19 @@ function diaspora_reshare($importer,$xml,$msg) { $person = find_diaspora_person_by_handle($orig_author); - /*if(is_array($person) && x($person,'name') && x($person,'url')) - $details = '[url=' . $person['url'] . ']' . $person['name'] . '[/url]'; - else - $details = $orig_author; + if($person) { + $orig_author_name = $person['xchan_name']; + $orig_author_link = $person['xchan_url']; + $orig_author_photo = $person['xchan_photo_m']; + } - $prefix = html_entity_decode("♲ ", ENT_QUOTES, 'UTF-8') . $details . "\n";*/ + $newbody = "[share author='" . urlencode($orig_author_name) + . "' profile='" . $orig_author_link + . "' avatar='" . $orig_author_photo + . "' link='" . $orig_url + . "' posted='" . datetime_convert('UTC','UTC',unxmlify($sourcexml->post->status_message->created_at)) + . "' message_id='" . unxmlify($source_xml->post->status_message->guid) + . "]" . $body . "[/share]"; $created = unxmlify($xml->created_at); @@ -994,7 +997,7 @@ function diaspora_reshare($importer,$xml,$msg) { $str_tags = ''; - $tags = get_tags($body); + $tags = get_tags($newbody); if(count($tags)) { @@ -1008,13 +1011,13 @@ function diaspora_reshare($importer,$xml,$msg) { // don't link tags that are already embedded in links - if(preg_match('/\[(.*?)' . preg_quote($tag,'/') . '(.*?)\]/',$body)) + if(preg_match('/\[(.*?)' . preg_quote($tag,'/') . '(.*?)\]/',$newbody)) continue; - if(preg_match('/\[(.*?)\]\((.*?)' . preg_quote($tag,'/') . '(.*?)\)/',$body)) + if(preg_match('/\[(.*?)\]\((.*?)' . preg_quote($tag,'/') . '(.*?)\)/',$newbody)) continue; $basetag = str_replace('_',' ',substr($tag,1)); - $body = str_replace($tag,'#[url=' . $a->get_baseurl() . '/search?tag=' . rawurlencode($basetag) . ']' . $basetag . '[/url]',$body); + $newbody = str_replace($tag,'#[url=' . $a->get_baseurl() . '/search?tag=' . rawurlencode($basetag) . ']' . $basetag . '[/url]',$newbody); $datarray['term'][] = array( 'uid' => $importer['channel_id'], @@ -1027,7 +1030,7 @@ function diaspora_reshare($importer,$xml,$msg) { } } - $cnt = preg_match_all('/@\[url=(.*?)\](.*?)\[\/url\]/ism',$body,$matches,PREG_SET_ORDER); + $cnt = preg_match_all('/@\[url=(.*?)\](.*?)\[\/url\]/ism',$newbody,$matches,PREG_SET_ORDER); if($cnt) { foreach($matches as $mtch) { $datarray['term'][] = array( @@ -1049,9 +1052,9 @@ function diaspora_reshare($importer,$xml,$msg) { $datarray['item_private'] = $private; $datarray['plink'] = $plink; $datarray['owner_xchan'] = $contact['xchan_hash']; - $datarray['author_xchan'] = $person['xchan_hash']; + $datarray['author_xchan'] = $contact['xchan_hash']; - $datarray['body'] = $body; + $datarray['body'] = $newbody; $datarray['app'] = 'Diaspora'; @@ -1343,6 +1346,11 @@ function diaspora_comment($importer,$xml,$msg) { $datarray['body'] = $body; $datarray['app'] = 'Diaspora'; + + if(! $parent_author_signature) { + $datarray['diaspora_meta'] = array('signer' => $diaspora_handle, 'body' => $text, + 'signed_text' => $signed_data, 'signature' => base64_encode($author_signature)); + } $result = item_store($datarray); @@ -1676,36 +1684,29 @@ function diaspora_photo($importer,$xml,$msg,$attempt=1) { return 202; } - $r = q("SELECT * FROM `item` WHERE `uid` = %d AND `guid` = '%s' LIMIT 1", + $r = q("SELECT * FROM `item` WHERE `uid` = %d AND `mid` = '%s' LIMIT 1", intval($importer['channel_id']), dbesc($status_message_guid) ); - if(! count($r)) { - if($attempt <= 3) { - q("INSERT INTO dsprphotoq (uid, msg, attempt) VALUES (%d, '%s', %d)", - intval($importer['channel_id']), - dbesc(serialize($msg)), - intval($attempt + 1) - ); - } + if(! $r) { logger('diaspora_photo: attempt = ' . $attempt . '; status message not found: ' . $status_message_guid . ' for photo: ' . $guid); return; } - $parent_item = $r[0]; +// $parent_item = $r[0]; - $link_text = '[img]' . $remote_photo_path . $remote_photo_name . '[/img]' . "\n"; +// $link_text = '[img]' . $remote_photo_path . $remote_photo_name . '[/img]' . "\n"; - $link_text = scale_external_images($link_text, true, - array($remote_photo_name, 'scaled_full_' . $remote_photo_name)); +// $link_text = scale_external_images($link_text, true, +// array($remote_photo_name, 'scaled_full_' . $remote_photo_name)); - if(strpos($parent_item['body'],$link_text) === false) { - $r = q("update item set `body` = '%s', `visible` = 1 where `id` = %d and `uid` = %d", - dbesc($link_text . $parent_item['body']), - intval($parent_item['id']), - intval($parent_item['uid']) - ); - } +// if(strpos($parent_item['body'],$link_text) === false) { +// $r = q("update item set `body` = '%s', `visible` = 1 where `id` = %d and `uid` = %d", +// dbesc($link_text . $parent_item['body']), +// intval($parent_item['id']), +// intval($parent_item['uid']) +// ); +// } return; } @@ -1742,7 +1743,7 @@ function diaspora_like($importer,$xml,$msg) { return 202; } - $r = q("SELECT * FROM `item` WHERE `uid` = %d AND `guid` = '%s' LIMIT 1", + $r = q("SELECT * FROM `item` WHERE `uid` = %d AND `mid` = '%s' LIMIT 1", intval($importer['channel_id']), dbesc($parent_guid) ); @@ -1753,7 +1754,7 @@ function diaspora_like($importer,$xml,$msg) { $parent_item = $r[0]; - $r = q("SELECT * FROM `item` WHERE `uid` = %d AND `guid` = '%s' LIMIT 1", + $r = q("SELECT * FROM `item` WHERE `uid` = %d AND `mid` = '%s' LIMIT 1", intval($importer['channel_id']), dbesc($guid) ); @@ -1775,6 +1776,13 @@ function diaspora_like($importer,$xml,$msg) { return; } } + + $i = q("select * from xchan where xchan_hash = '%s' limit 1", + dbesc($parent_item['author_xchan']) + ); + if($i) + $item_author = $i[0]; + // Note: I don't think "Like" objects with positive = "false" are ever actually used // It looks like "RelayableRetractions" are used for "unlike" instead if($positive === 'false') { @@ -1807,12 +1815,12 @@ function diaspora_like($importer,$xml,$msg) { $parent_author_signature = base64_decode($parent_author_signature); if(! rsa_verify($signed_data,$parent_author_signature,$key,'sha256')) { - if (intval(get_config('system','ignore_diaspora_like_signature'))) +// if (intval(get_config('system','ignore_diaspora_like_signature'))) logger('diaspora_like: top-level owner verification failed. Proceeding anyway.'); - else { - logger('diaspora_like: top-level owner verification failed.'); - return; - } +// else { +// logger('diaspora_like: top-level owner verification failed.'); +// return; +// } } } else { @@ -1824,12 +1832,12 @@ function diaspora_like($importer,$xml,$msg) { $author_signature = base64_decode($author_signature); if(! rsa_verify($signed_data,$author_signature,$key,'sha256')) { - if (intval(get_config('system','ignore_diaspora_like_signature'))) +// if (intval(get_config('system','ignore_diaspora_like_signature'))) logger('diaspora_like: like creator verification failed. Proceeding anyway'); - else { - logger('diaspora_like: like creator verification failed.'); - return; - } +// else { +// logger('diaspora_like: like creator verification failed.'); +// return; +// } } } @@ -1852,87 +1860,75 @@ function diaspora_like($importer,$xml,$msg) { $uri = $diaspora_handle . ':' . $guid; $activity = ACTIVITY_LIKE; - $post_type = (($parent_item['resource-id']) ? t('photo') : t('status')); - $objtype = (($parent_item['resource-id']) ? ACTIVITY_OBJ_PHOTO : ACTIVITY_OBJ_NOTE ); - $link = xmlify('<link rel="alternate" type="text/html" href="' . $a->get_baseurl() . '/display/' . $importer['nickname'] . '/' . $parent_item['id'] . '" />' . "\n") ; + + $post_type = (($parent_item['resource_type'] === 'photo') ? t('photo') : t('status')); + + $links = array(array('rel' => 'alternate','type' => 'text/html', 'href' => $parent_item['plink'])); + $objtype = (($parent_item['resource_type'] === 'photo') ? ACTIVITY_OBJ_PHOTO : ACTIVITY_OBJ_NOTE ); + $body = $parent_item['body']; - $obj = <<< EOT - <object> - <type>$objtype</type> - <local>1</local> - <id>{$parent_item['uri']}</id> - <link>$link</link> - <title></title> - <content>$body</content> - </object> -EOT; + $object = json_encode(array( + 'type' => $post_type, + 'id' => $parent_item['mid'], + 'parent' => (($parent_item['thr_parent']) ? $parent_item['thr_parent'] : $parent_item['parent_mid']), + 'link' => $links, + 'title' => $parent_item['title'], + 'content' => $parent_item['body'], + 'created' => $parent_item['created'], + 'edited' => $parent_item['edited'], + 'author' => array( + 'name' => $item_author['xchan_name'], + 'address' => $item_author['xchan_addr'], + 'guid' => $item_author['xchan_guid'], + 'guid_sig' => $item_author['xchan_guid_sig'], + 'link' => array( + array('rel' => 'alternate', 'type' => 'text/html', 'href' => $item_author['xchan_url']), + array('rel' => 'photo', 'type' => $item_author['xchan_photo_mimetype'], 'href' => $item_author['xchan_photo_m'])), + ), + )); + + $bodyverb = t('%1$s likes %2$s\'s %3$s'); $arr = array(); $arr['uri'] = $uri; $arr['uid'] = $importer['channel_id']; - $arr['guid'] = $guid; - $arr['network'] = NETWORK_DIASPORA; - $arr['contact-id'] = $contact['id']; - $arr['type'] = 'activity'; - $arr['wall'] = $parent_item['wall']; - $arr['gravity'] = GRAVITY_LIKE; - $arr['parent'] = $parent_item['id']; - $arr['parent-uri'] = $parent_item['uri']; - - $arr['owner-name'] = $parent_item['name']; - $arr['owner-link'] = $parent_item['url']; - //$arr['owner-avatar'] = $parent_item['thumb']; - $arr['owner-avatar'] = ((x($parent_item,'thumb')) ? $parent_item['thumb'] : $parent_item['photo']); - - $arr['author-name'] = $person['name']; - $arr['author-link'] = $person['url']; - $arr['author-avatar'] = ((x($person,'thumb')) ? $person['thumb'] : $person['photo']); + $arr['aid'] = $importer['channel_account_id']; + $arr['mid'] = $guid; + $arr['parent_mid'] = $parent_item['mid']; + $arr['owner_xchan'] = $parent_item['owner_xchan']; + $arr['author_xchan'] = $person['xchan_hash']; $ulink = '[url=' . $contact['url'] . ']' . $contact['name'] . '[/url]'; $alink = '[url=' . $parent_item['author-link'] . ']' . $parent_item['author-name'] . '[/url]'; - //$plink = '[url=' . $a->get_baseurl() . '/display/' . $importer['nickname'] . '/' . $parent_item['id'] . ']' . $post_type . '[/url]'; - $plink = '[url='.$a->get_baseurl().'/display/'.$guid.']'.$post_type.'[/url]'; + $plink = '[url='. z_root() .'/display/'.$guid.']'.$post_type.'[/url]'; $arr['body'] = sprintf( $bodyverb, $ulink, $alink, $plink ); $arr['app'] = 'Diaspora'; - $arr['private'] = $parent_item['private']; + $arr['item_private'] = $parent_item['item_private']; $arr['verb'] = $activity; $arr['object-type'] = $objtype; - $arr['object'] = $obj; - $arr['visible'] = 1; - $arr['unseen'] = 1; - $arr['last-child'] = 0; - - $message_id = item_store($arr); - - - //if($message_id) { - // q("update item set plink = '%s' where id = %d", - // //dbesc($a->get_baseurl() . '/display/' . $importer['nickname'] . '/' . $message_id), - // dbesc($a->get_baseurl().'/display/'.$guid), - // intval($message_id) - // ); - //} + $arr['object'] = $object; if(! $parent_author_signature) { - q("insert into sign (`iid`,`signed_text`,`signature`,`signer`) values (%d,'%s','%s','%s') ", - intval($message_id), - dbesc($signed_data), - dbesc(base64_encode($author_signature)), - dbesc($diaspora_handle) - ); + $datarray['diaspora_meta'] = array('signer' => $diaspora_handle, 'body' => $text, + 'signed_text' => $signed_data, 'signature' => base64_encode($author_signature)); } + $x = item_store($arr); + + if($x) + $message_id = $x['item_id']; + // if the message isn't already being relayed, notify others // the existence of parent_author_signature means the parent_author or owner // is already relaying. The parent_item['origin'] indicates the message was created on our system - if(($parent_item['origin']) && (! $parent_author_signature)) + if(($parent_item['item_flags'] & ITEM_ORIGIN) && (! $parent_author_signature)) proc_run('php','include/notifier.php','comment-import',$message_id); return; @@ -2213,7 +2209,7 @@ function diaspora_send_status($item,$owner,$contact,$public_batch = false) { $images = array(); $title = $item['title']; - $body = $item['body']; + $body = bb2diaspora_itembody($item); /* // We're trying to match Diaspora's split message/photo protocol but @@ -2239,52 +2235,6 @@ function diaspora_send_status($item,$owner,$contact,$public_batch = false) { */ - $body = str_ireplace("[quote", "\n\n[quote", $body); - $body = str_ireplace("[/quote]", "[/quote]\n\n", $body); - - // strip bookmark indicators - - $body = preg_replace('/\#\^\[([zu])rl/i', '[$1rl', $body); - $body = preg_replace('/\#\^http/i', 'http', $body); - - // protect tags and mentions from hijacking - - if(! intval(get_pconfig($owner['channel_id'],'system','allow_tag_hijacking'))) { - $new_tag = html_entity_decode('⋕',ENT_COMPAT,'UTF-8'); - $new_mention = html_entity_decode('@',ENT_COMPAT,'UTF-8'); - - // #-tags - $body = preg_replace('/\#\[url/i', $new_tag . '[url', $body); - $body = preg_replace('/\#\[zrl/i', $new_tag . '[zrl', $body); - // @-mentions - $body = preg_replace('/\@\[url/i', $new_mention . '[url', $body); - $body = preg_replace('/\@\[zrl/i', $new_mention . '[zrl', $body); - } - - // remove multiple newlines - do { - $oldbody = $body; - $body = str_replace("\n\n\n", "\n\n", $body); - } while ($oldbody != $body); - - - // convert to markdown - $body = xmlify(html_entity_decode(bb2diaspora($body))); - - // Adding the title - if(strlen($title)) - $body = "## ".html_entity_decode($title)."\n\n".$body; - - if($item['attach']) { - $cnt = preg_match_all('/href=\"(.*?)\"(.*?)title=\"(.*?)\"/ism',$item['attach'],$matches,PREG_SET_ORDER); - if(cnt) { - $body .= "\n" . t('Attachments:') . "\n"; - foreach($matches as $mtch) { - $body .= '[' . $mtch[3] . '](' . $mtch[1] . ')' . "\n"; - } - } - } - $public = (($item['item_private']) ? 'false' : 'true'); require_once('include/datetime.php'); @@ -2306,7 +2256,7 @@ function diaspora_send_status($item,$owner,$contact,$public_batch = false) { } else { $tpl = get_markup_template('diaspora_post.tpl'); $msg = replace_macros($tpl, array( - '$body' => $body, + '$body' => xmlify($body), '$guid' => $item['mid'], '$handle' => xmlify($myaddr), '$public' => $public, @@ -2460,16 +2410,28 @@ function diaspora_send_followup($item,$owner,$contact,$public_batch = false) { $like = false; } - $text = html_entity_decode(bb2diaspora($item['body'])); + if($item['diaspora_meta'] && ! $like) { + $j = json_decode($item['diaspora_meta'],true); + if($j) { + $signed_text = $j['signed_text']; + $text = $j['body']; + $signer = $j['signer']; + $authorsig = $j['signature']; + } + } + else { + $text = bb2diaspora_itembody($item); - // sign it + // sign it - if($like) - $signed_text = $item['mid'] . ';' . $target_type . ';' . $parent['mid'] . ';' . $positive . ';' . $myaddr; - else - $signed_text = $item['mid'] . ';' . $parent['mid'] . ';' . $text . ';' . $myaddr; + if($like) + $signed_text = $item['mid'] . ';' . $target_type . ';' . $parent['mid'] . ';' . $positive . ';' . $myaddr; + else + $signed_text = $item['mid'] . ';' . $parent['mid'] . ';' . $text . ';' . $myaddr; + + $authorsig = base64_encode(rsa_sign($signed_text,$owner['channel_prvkey'],'sha256')); - $authorsig = base64_encode(rsa_sign($signed_text,$owner['channel_prvkey'],'sha256')); + } $msg = replace_macros($tpl,array( '$guid' => xmlify($item['mid']), @@ -2496,9 +2458,9 @@ function diaspora_send_relay($item,$owner,$contact,$public_batch = false) { $a = get_app(); $myaddr = $owner['channel_address'] . '@' . substr($a->get_baseurl(), strpos($a->get_baseurl(),'://') + 3); + $text = bb2diaspora_itembody($item); - $body = $item['body']; - $text = html_entity_decode(bb2diaspora($body)); + $body = $text; // Diaspora doesn't support threaded comments, but some // versions of Diaspora (i.e. Diaspora-pistos) support @@ -2551,26 +2513,15 @@ function diaspora_send_relay($item,$owner,$contact,$public_batch = false) { $tpl = get_markup_template('diaspora_comment_relay.tpl'); } - - // fetch the original signature if the relayable was created by a Diaspora, Friendica-over Diaspora, - // or zot user. Relayables for other networks are not supported. - - $r = q("select * from sign where " . $sql_sign_id . " = %d limit 1", - intval($item['id']) - ); - if(count($r)) { - $orig_sign = $r[0]; - $signed_text = $orig_sign['signed_text']; - $authorsig = $orig_sign['signature']; - $handle = $orig_sign['signer']; - } - else { - // Author signature information (for likes, comments, and retractions of likes or comments, - // whether from Diaspora or Friendica) must be placed in the `sign` table before this - // function is called - logger('diaspora_send_relay: original author signature not found, cannot send relayable'); - return; + $diaspora_meta = (($item['diaspora_meta']) ? json_decode($item['diaspora_meta'],true) : ''); + if($diaspora_meta) { + $sender_signed_text = $diaspora_meta['signed_text']; + $authorsig = $diaspora_meta['signature']; + $handle = $diaspora_meta['signer']; + $text = $diaspora_meta['body']; } + else + logger('diaspora_send_relay: original author signature not found'); /* Since the author signature is only checked by the parent, not by the relay recipients, * I think it may not be necessary for us to do so much work to preserve all the original @@ -2583,19 +2534,26 @@ function diaspora_send_relay($item,$owner,$contact,$public_batch = false) { * * */ - - $handle = diaspora_handle_from_contact($item['author_xchan']); +// bug - nomadic identity may/will affect diaspora_handle_from_contact + if(! $handle) { + if($item['author_xchan'] === $owner['channel_hash']) + $handle = $owner['channel_address'] . '@' . substr($a->get_baseurl(), strpos($a->get_baseurl(),'://') + 3); + else + $handle = diaspora_handle_from_contact($item['author_xchan']); + } if(! $handle) { logger('diaspora_send_relay: no handle'); return; } - if($relay_retract) - $sender_signed_text = $item['guid'] . ';' . $target_type; - elseif($like) - $sender_signed_text = $item['guid'] . ';' . $target_type . ';' . $parent['guid'] . ';' . $positive . ';' . $handle; - else - $sender_signed_text = $item['guid'] . ';' . $parent['guid'] . ';' . $text . ';' . $handle; + if(! $sender_signed_text) { + if($relay_retract) + $sender_signed_text = $item['mid'] . ';' . $target_type; + elseif($like) + $sender_signed_text = $item['mid'] . ';' . $target_type . ';' . $parent['mid'] . ';' . $positive . ';' . $handle; + else + $sender_signed_text = $item['mid'] . ';' . $parent['mid'] . ';' . $text . ';' . $handle; + } // Sign the relayable with the top-level owner's signature // diff --git a/include/dir_fns.php b/include/dir_fns.php index 5fad6567e..f58e7c307 100644 --- a/include/dir_fns.php +++ b/include/dir_fns.php @@ -107,7 +107,7 @@ function sync_directories($dirmode) { $r = array( 'site_url' => DIRECTORY_FALLBACK_MASTER, 'site_flags' => DIRECTORY_MODE_PRIMARY, - 'site_update' => '0000-00-00 00:00:00', + 'site_update' => NULL_DATE, 'site_directory' => DIRECTORY_FALLBACK_MASTER . '/dirsearch', 'site_realm' => DIRECTORY_REALM ); @@ -137,7 +137,7 @@ function sync_directories($dirmode) { // for brand new directory servers, only load the last couple of days. Everything before that will be repeats. - $syncdate = (($rr['site_sync'] === '0000-00-00 00:00:00') ? datetime_convert('UTC','UTC','now - 2 days') : $rr['site_sync']); + $syncdate = (($rr['site_sync'] === NULL_DATE) ? datetime_convert('UTC','UTC','now - 2 days') : $rr['site_sync']); $x = z_fetch_url($rr['site_directory'] . '?f=&sync=' . urlencode($syncdate)); if(! $x['success']) diff --git a/include/event.php b/include/event.php index 0c29d26f6..1fe6e6f7f 100644 --- a/include/event.php +++ b/include/event.php @@ -374,6 +374,26 @@ function event_store_item($arr,$event) { intval($arr['uid']) ); + + $s = q("delete from term where oid = %d and otype = %d", + intval($r[0]['id']), + intval(TERM_OBJ_POST) + ); + + if(($arr['term']) && (is_array($arr['term']))) { + foreach($arr['term'] as $t) { + q("insert into term (uid,oid,otype,type,term,url) + values(%d,%d,%d,%d,'%s','%s') ", + intval($arr['uid']), + intval($r[0]['id']), + intval(TERM_OBJ_POST), + intval($t['type']), + dbesc($t['term']), + dbesc($t['url']) + ); + } + } + $item_id = $r[0]['id']; call_hooks('event_updated', $event['id']); return $item_id; @@ -424,6 +444,10 @@ function event_store_item($arr,$event) { $item_arr['item_private'] = $private; $item_arr['verb'] = ACTIVITY_POST; + + if(array_key_exists('term',$arr)) + $item_arr['term'] = $arr['term']; + $item_arr['resource_type'] = 'event'; $item_arr['resource_id'] = $event['event_hash']; diff --git a/include/externals.php b/include/externals.php index 8944524b7..acfaae3b6 100644 --- a/include/externals.php +++ b/include/externals.php @@ -60,8 +60,8 @@ function externals_run($argv, $argc){ } if($url) { - if($r[0]['site_pull'] !== '0000-00-00 00:00:00') - $mindate = urlencode($r[0]['site_pull']); + if($r[0]['site_pull'] !== NULL_DATE) + $mindate = urlencode(datetime_convert('','',$r[0]['site_pull'] . ' - 1 day')); else { $days = get_config('externals','since_days'); if($days === false) diff --git a/include/follow.php b/include/follow.php index d1c6afbee..18a9e66ea 100644 --- a/include/follow.php +++ b/include/follow.php @@ -51,7 +51,7 @@ function new_contact($uid,$url,$channel,$interactive = false, $confirm = false) if($arr['channel']['success']) $ret = $arr['channel']; - elseif($is_http) + elseif(! $is_http) $ret = zot_finger($url,$channel); if($ret && $ret['success']) { @@ -118,6 +118,12 @@ function new_contact($uid,$url,$channel,$interactive = false, $confirm = false) } } else { + if(! ($is_http)) { + if(! intval(get_config('system','diaspora_enabled'))) { + $result['message'] = t('Protocol disabled.'); + return $result; + } + } $my_perms = 0; $their_perms = 0; @@ -181,7 +187,7 @@ function new_contact($uid,$url,$channel,$interactive = false, $confirm = false) return $result; } - $r = q("select count(*) as total from abook where abook_account = %d and abook_network = 'rss'", + $r = q("select count(*) as total from abook where abook_account = %d and ( abook_flags & ABOOK_FLAG_FEED )", intval($aid) ); if($r) @@ -215,7 +221,7 @@ function new_contact($uid,$url,$channel,$interactive = false, $confirm = false) intval($uid), dbesc($xchan_hash), intval(($is_http) ? ABOOK_FLAG_FEED : 0), - intval($their_perms), + intval(($is_http) ? $their_perms|PERMS_R_STREAM|PERMS_A_REPUBLISH : $their_perms), intval($my_perms), dbesc(datetime_convert()), dbesc(datetime_convert()) diff --git a/include/identity.php b/include/identity.php index 8b742f53e..d8f59e56c 100644 --- a/include/identity.php +++ b/include/identity.php @@ -774,22 +774,17 @@ logger('online: ' . $profile['online']); ? trim(substr($profile['channel_name'],0,strpos($profile['channel_name'],' '))) : $profile['channel_name']); $lastname = (($firstname === $profile['channel_name']) ? '' : trim(substr($profile['channel_name'],strlen($firstname)))); - if(get_config('system','diaspora_enabled')) { - $diaspora = array( - 'podloc' => z_root(), - 'searchable' => (($block) ? 'false' : 'true'), - 'nickname' => $profile['channel_address'], - 'fullname' => $profile['channel_name'], - 'firstname' => $firstname, - 'lastname' => $lastname, - 'photo300' => z_root() . '/photo/profile/300/' . $profile['uid'] . '.jpg', - 'photo100' => z_root() . '/photo/profile/100/' . $profile['uid'] . '.jpg', - 'photo50' => z_root() . '/photo/profile/50/' . $profile['uid'] . '.jpg', - ); - } - else - $diaspora = null; - + $diaspora = array( + 'podloc' => z_root(), + 'searchable' => (($block) ? 'false' : 'true'), + 'nickname' => $profile['channel_address'], + 'fullname' => $profile['channel_name'], + 'firstname' => $firstname, + 'lastname' => $lastname, + 'photo300' => z_root() . '/photo/profile/300/' . $profile['uid'] . '.jpg', + 'photo100' => z_root() . '/photo/profile/100/' . $profile['uid'] . '.jpg', + 'photo50' => z_root() . '/photo/profile/50/' . $profile['uid'] . '.jpg', + ); $contact_block = contact_block(); @@ -1047,7 +1042,7 @@ function advanced_profile(&$a) { if($a->profile['with']) $profile['marital']['with'] = bbcode($a->profile['with']); - if(strlen($a->profile['howlong']) && $a->profile['howlong'] !== '0000-00-00 00:00:00') { + if(strlen($a->profile['howlong']) && $a->profile['howlong'] !== NULL_DATE) { $profile['howlong'] = relative_date($a->profile['howlong'], t('for %1$d %2$s')); } diff --git a/include/items.php b/include/items.php index 7764d2f62..b93bf05ee 100755 --- a/include/items.php +++ b/include/items.php @@ -144,7 +144,7 @@ function filter_insecure($channel_id,$arr) { function comments_are_now_closed($item) { - if($item['comments_closed'] !== '0000-00-00 00:00:00') { + if($item['comments_closed'] !== NULL_DATE) { $d = datetime_convert(); if($d > $item['comments_closed']) return true; @@ -448,7 +448,7 @@ function post_activity_item($arr) { function get_public_feed($channel,$params) { $type = 'xml'; - $begin = '0000-00-00 00:00:00'; + $begin = NULL_DATE; $end = ''; $start = 0; $records = 40; @@ -459,7 +459,7 @@ function get_public_feed($channel,$params) { $params = array(); $params['type'] = ((x($params,'type')) ? $params['type'] : 'xml'); - $params['begin'] = ((x($params,'begin')) ? $params['begin'] : '0000-00-00 00:00:00'); + $params['begin'] = ((x($params,'begin')) ? $params['begin'] : NULL_DATE); $params['end'] = ((x($params,'end')) ? $params['end'] : datetime_convert('UTC','UTC','now')); $params['start'] = ((x($params,'start')) ? $params['start'] : 0); $params['records'] = ((x($params,'records')) ? $params['records'] : 40); @@ -518,13 +518,13 @@ function get_feed_for($channel, $observer_hash, $params) { $atom .= replace_macros($feed_template, array( '$version' => xmlify(RED_VERSION), '$red' => xmlify(RED_PLATFORM), - '$feed_id' => xmlify($channel['channel_url']), + '$feed_id' => xmlify($channel['xchan_url']), '$feed_title' => xmlify($channel['channel_name']), '$feed_updated' => xmlify(datetime_convert('UTC', 'UTC', 'now' , ATOM_TIME)) , '$hub' => '', // feed_hublinks(), '$salmon' => '', // feed_salmonlinks($channel['channel_address']), '$name' => xmlify($channel['channel_name']), - '$profile_page' => xmlify($channel['channel_url']), + '$profile_page' => xmlify($channel['xchan_url']), '$mimephoto' => xmlify($channel['xchan_photo_mimetype']), '$photo' => xmlify($channel['xchan_photo_l']), '$thumb' => xmlify($channel['xchan_photo_m']), @@ -758,14 +758,14 @@ function get_item_elements($x) { $arr['expires'] = ((x($x,'expires') && $x['expires']) ? datetime_convert('UTC','UTC',$x['expires']) - : '0000-00-00 00:00:00'); + : NULL_DATE); $arr['commented'] = ((x($x,'commented') && $x['commented']) ? datetime_convert('UTC','UTC',$x['commented']) : $arr['created']); $arr['comments_closed'] = ((x($x,'comments_closed') && $x['comments_closed']) ? datetime_convert('UTC','UTC',$x['comments_closed']) - : '0000-00-00 00:00:00'); + : NULL_DATE); $arr['title'] = (($x['title']) ? htmlspecialchars($x['title'], ENT_COMPAT,'UTF-8',false) : ''); @@ -795,7 +795,7 @@ function get_item_elements($x) { $arr['sig'] = (($x['signature']) ? htmlspecialchars($x['signature'], ENT_COMPAT,'UTF-8',false) : ''); - + $arr['diaspora_meta'] = (($x['diaspora_meta']) ? $x['diaspora_meta'] : ''); $arr['object'] = activity_sanitise($x['object']); $arr['target'] = activity_sanitise($x['target']); @@ -871,6 +871,8 @@ function import_author_xchan($x) { if((! array_key_exists('network', $x)) || ($x['network'] === 'zot')) { $y = import_author_zot($x); } + if(! $y) + $y = import_author_diaspora($x); if($x['network'] === 'rss') { $y = import_author_rss($x); @@ -879,6 +881,21 @@ function import_author_xchan($x) { return(($y) ? $y : false); } + +function import_author_diaspora($x) { + if(! $x['address']) + return false; + if(discover_by_webbie($x['address'])) { + $r = q("select xchan_hash from xchan where xchan_addr = '%s' limit 1", + dbesc($x['address']) + ); + if($r) + return $r[0]['xchan_hash']; + } + return false; +} + + function import_author_rss($x) { if(! $x['url']) @@ -893,16 +910,17 @@ function import_author_rss($x) { } $name = trim($x['name']); - $r = q("insert into xchan ( xchan_hash, xchan_url, xchan_name, xchan_network ) - values ( '%s', '%s', '%s', '%s' )", - dbesc($x['url']), + $r = q("insert into xchan ( xchan_hash, xchan_guid, xchan_url, xchan_name, xchan_network ) + values ( '%s', '%s', '%s', '%s', '%s' )", + dbesc($x['guid']), + dbesc($x['guid']), dbesc($x['url']), dbesc(($name) ? $name : t('(Unknown)')), dbesc('rss') ); - if($r) { + if($r && $x['photo']) { - $photos = import_profile_photo($x['photo'],$x['url']); + $photos = import_profile_photo($x['photo']['src'],$x['url']); if($photos) { $r = q("update xchan set xchan_photo_date = '%s', xchan_photo_l = '%s', xchan_photo_m = '%s', xchan_photo_s = '%s', xchan_photo_mimetype = '%s' where xchan_url = '%s' and xchan_network = 'rss' limit 1", @@ -985,7 +1003,7 @@ function encode_item($item) { if($y = encode_item_flags($item)) $x['flags'] = $y; - if($item['comments_closed'] !== '0000-00-00 00:00:00') + if($item['comments_closed'] !== NULL_DATE) $x['comments_closed'] = $item['comments_closed']; $x['public_scope'] = $scope; @@ -1051,7 +1069,7 @@ function encode_item_xchan($xchan) { $ret = array(); $ret['name'] = $xchan['xchan_name']; $ret['address'] = $xchan['xchan_addr']; - $ret['url'] = $xchan['hubloc_url']; + $ret['url'] = (($xchan['hubloc_url']) ? $xchan['hubloc_url'] : $xchan['xchan_url']); $ret['network'] = $xchan['xchan_network']; $ret['photo'] = array('mimetype' => $xchan['xchan_photo_mimetype'], 'src' => $xchan['xchan_photo_m']); $ret['guid'] = $xchan['xchan_guid']; @@ -1194,6 +1212,7 @@ function encode_mail($item) { $x['message_parent'] = $item['parent_mid']; $x['created'] = $item['created']; $x['expires'] = $item['expires']; + $x['diaspora_meta'] = $item['diaspora_meta']; $x['title'] = $item['title']; $x['body'] = $item['body']; $x['from'] = encode_item_xchan($item['from']); @@ -1223,8 +1242,8 @@ function get_mail_elements($x) { $arr['title'] = (($x['title'])? htmlspecialchars($x['title'],ENT_COMPAT,'UTF-8',false) : ''); $arr['created'] = datetime_convert('UTC','UTC',$x['created']); - if((! array_key_exists('expires',$x)) || ($x['expires'] === '0000-00-00 00:00:00')) - $arr['expires'] = '0000-00-00 00:00:00'; + if((! array_key_exists('expires',$x)) || ($x['expires'] === NULL_DATE)) + $arr['expires'] = NULL_DATE; else $arr['expires'] = datetime_convert('UTC','UTC',$x['expires']); @@ -1592,8 +1611,8 @@ function get_atom_elements($feed,$item,&$author) { $title = ' '; if(! $type) $type = 'application/octet-stream'; + $res['attach'][] = array('href' => $link, 'length' => $len, 'type' => $type, 'title' => $title ); } - $res['attach'][] = array('href' => $link, 'length' => $len, 'type' => $type, 'title' => $title ); } $rawobj = $item->get_item_tags(NAMESPACE_ACTIVITY, 'object'); @@ -1748,6 +1767,7 @@ function item_store($arr,$allow_exec = false) { $arr['title'] = ((array_key_exists('title',$arr) && strlen($arr['title'])) ? trim($arr['title']) : ''); $arr['body'] = ((array_key_exists('body',$arr) && strlen($arr['body'])) ? trim($arr['body']) : ''); + $arr['diaspora_meta'] = ((x($arr,'diaspora_meta')) ? $arr['diaspora_meta'] : ''); $arr['allow_cid'] = ((x($arr,'allow_cid')) ? trim($arr['allow_cid']) : ''); $arr['allow_gid'] = ((x($arr,'allow_gid')) ? trim($arr['allow_gid']) : ''); $arr['deny_cid'] = ((x($arr,'deny_cid')) ? trim($arr['deny_cid']) : ''); @@ -1819,9 +1839,9 @@ function item_store($arr,$allow_exec = false) { $arr['owner_xchan'] = ((x($arr,'owner_xchan')) ? notags(trim($arr['owner_xchan'])) : ''); $arr['created'] = ((x($arr,'created') !== false) ? datetime_convert('UTC','UTC',$arr['created']) : datetime_convert()); $arr['edited'] = ((x($arr,'edited') !== false) ? datetime_convert('UTC','UTC',$arr['edited']) : datetime_convert()); - $arr['expires'] = ((x($arr,'expires') !== false) ? datetime_convert('UTC','UTC',$arr['expires']) : '0000-00-00 00:00:00'); + $arr['expires'] = ((x($arr,'expires') !== false) ? datetime_convert('UTC','UTC',$arr['expires']) : NULL_DATE); $arr['commented'] = ((x($arr,'commented') !== false) ? datetime_convert('UTC','UTC',$arr['commented']) : datetime_convert()); - $arr['comments_closed'] = ((x($arr,'comments_closed') !== false) ? datetime_convert('UTC','UTC',$arr['comments_closed']) : '0000-00-00 00:00:00'); + $arr['comments_closed'] = ((x($arr,'comments_closed') !== false) ? datetime_convert('UTC','UTC',$arr['comments_closed']) : NULL_DATE); $arr['received'] = datetime_convert(); $arr['changed'] = datetime_convert(); @@ -2228,7 +2248,7 @@ function item_store_update($arr,$allow_exec = false) { $arr['edited'] = ((x($arr,'edited') !== false) ? datetime_convert('UTC','UTC',$arr['edited']) : datetime_convert()); $arr['expires'] = ((x($arr,'expires') !== false) ? datetime_convert('UTC','UTC',$arr['expires']) : $orig[0]['expires']); - if(array_key_exists('comments_closed',$arr) && $arr['comments_closed'] != '0000-00-00 00:00:00') + if(array_key_exists('comments_closed',$arr) && $arr['comments_closed'] != NULL_DATE) $arr['comments_closed'] = datetime_convert('UTC','UTC',$arr['comments_closed']); else $arr['comments_closed'] = $orig[0]['comments_closed']; @@ -2236,6 +2256,8 @@ function item_store_update($arr,$allow_exec = false) { $arr['commented'] = $orig[0]['commented']; $arr['received'] = datetime_convert(); $arr['changed'] = datetime_convert(); + + $arr['diaspora_meta'] = ((x($arr,'diaspora_meta')) ? $arr['diaspora_meta'] : $orig[0]['diaspora_meta']); $arr['location'] = ((x($arr,'location')) ? notags(trim($arr['location'])) : $orig[0]['location']); $arr['coord'] = ((x($arr,'coord')) ? notags(trim($arr['coord'])) : $orig[0]['coord']); $arr['verb'] = ((x($arr,'verb')) ? notags(trim($arr['verb'])) : $orig[0]['verb']); @@ -2370,6 +2392,13 @@ function store_diaspora_comment_sig($datarray, $channel, $parent_item, $post_id) else $authorsig = ''; + $x = array('signer' => $diaspora_handle, 'body' => $signed_body, 'signed_text' => $signed_text, 'signature' => base64_encode($authorsig)); + + $r = q("update item set diaspora_meta = '%s' where id = %d limit 1", + dbesc(json_encode($x)), + intval($post_id) + ); + $r = q("insert into sign (`iid`,`signed_text`,`signature`,`signer`) values (%d,'%s','%s','%s') ", intval($post_id), dbesc($signed_text), @@ -2816,7 +2845,6 @@ function tgroup_check($uid,$item) { function start_delivery_chain($channel,$item,$item_id,$parent) { - // Change this copy of the post to a forum head message and deliver to all the tgroup members // also reset all the privacy bits to the forum default permissions @@ -2830,6 +2858,11 @@ function start_delivery_chain($channel,$item,$item_id,$parent) { $flag_bits = $item['item_flags'] | ITEM_WALL|ITEM_ORIGIN; + // unset the nocomment bit if it's there. + + if($flag_bits & ITEM_NOCOMMENT) + $flag_bits = $flag_bits ^ ITEM_NOCOMMENT; + // maintain the original source, which will be the original item owner and was stored in source_xchan // when we created the delivery fork @@ -2910,29 +2943,33 @@ function start_delivery_chain($channel,$item,$item_id,$parent) { function check_item_source($uid,$item) { - if($item['item_private']) - return false; - $r = q("select * from source where src_channel_id = %d and ( src_xchan = '%s' || src_xchan = '*' ) limit 1", intval($uid), dbesc(($item['source_xchan']) ? $item['source_xchan'] : $item['owner_xchan']) ); + if(! $r) return false; - $x = q("select abook_their_perms from abook where abook_channel = %d and abook_xchan = '%s' limit 1", + $x = q("select abook_their_perms, abook_flags from abook where abook_channel = %d and abook_xchan = '%s' limit 1", intval($uid), dbesc($item['owner_xchan']) ); + if(! $x) return false; + if(! ($x[0]['abook_their_perms'] & PERMS_A_REPUBLISH)) return false; + if($item['item_private'] && (! ($x[0]['abook_flags'] & ABOOK_FLAG_FEED))) + return false; + + if($r[0]['src_channel_xchan'] === $item['owner_xchan']) return false; @@ -2981,7 +3018,7 @@ function mail_store($arr) { $arr['from_xchan'] = ((x($arr,'from_xchan')) ? notags(trim($arr['from_xchan'])) : ''); $arr['to_xchan'] = ((x($arr,'to_xchan')) ? notags(trim($arr['to_xchan'])) : ''); $arr['created'] = ((x($arr,'created') !== false) ? datetime_convert('UTC','UTC',$arr['created']) : datetime_convert()); - $arr['expires'] = ((x($arr,'expires') !== false) ? datetime_convert('UTC','UTC',$arr['expires']) : '0000-00-00 00:00:00'); + $arr['expires'] = ((x($arr,'expires') !== false) ? datetime_convert('UTC','UTC',$arr['expires']) : NULL_DATE); $arr['title'] = ((x($arr,'title')) ? notags(trim($arr['title'])) : ''); $arr['parent_mid'] = ((x($arr,'parent_mid')) ? notags(trim($arr['parent_mid'])) : ''); $arr['body'] = ((x($arr,'body')) ? trim($arr['body']) : ''); @@ -4039,7 +4076,7 @@ function zot_feed($uid,$observer_xchan,$mindate) { $result = array(); $mindate = datetime_convert('UTC','UTC',$mindate); if(! $mindate) - $mindate = '0000-00-00 00:00:00'; + $mindate = NULL_DATE; $mindate = dbesc($mindate); @@ -4055,8 +4092,8 @@ function zot_feed($uid,$observer_xchan,$mindate) { $sql_extra = item_permissions_sql($uid); } - if($mindate != '0000-00-00 00:00:00') { - $sql_extra .= " and created > '$mindate' "; + if($mindate != NULL_DATE) { + $sql_extra .= " and ( created > '$mindate' or edited > '$mindate' ) "; $limit = ""; } else diff --git a/include/message.php b/include/message.php index 607166ec9..96c3532c1 100644 --- a/include/message.php +++ b/include/message.php @@ -23,7 +23,7 @@ function send_message($uid = 0, $recipient='', $body='', $subject='', $replyto=' $subject = t('[no subject]'); // if(! $expires) -// $expires = '0000-00-00 00:00:00'; +// $expires = NULL_DATE; // else // $expires = datetime_convert(date_default_timezone_get(),'UTC',$expires); diff --git a/include/network.php b/include/network.php index c44ed77c4..0191f203d 100644 --- a/include/network.php +++ b/include/network.php @@ -132,6 +132,29 @@ function z_fetch_url($url, $binary = false, $redirects = 0, $opts = array()) { } +/** + * @function z_post_url + * @param string $url + * URL to post + * @param mixed $params + * The full data to post in a HTTP "POST" operation. This parameter can + * either be passed as a urlencoded string like 'para1=val1¶2=val2&...' + * or as an array with the field name as key and field data as value. If value + * is an array, the Content-Type header will be set to multipart/form-data. + * @param int $redirects = 0 + * internal use, recursion counter + * @param array $opts (optional parameters) + * 'accept_content' => supply Accept: header with 'accept_content' as the value + * 'timeout' => int seconds, default system config value or 60 seconds + * 'http_auth' => username:password + * 'novalidate' => do not validate SSL certs, default is to validate using our CA list + * + * @returns array + * 'return_code' => HTTP return code or 0 if timeout or failure + * 'success' => boolean true (if HTTP 2xx result) or false + * 'header' => HTTP headers + * 'body' => fetched content + */ function z_post_url($url,$params, $redirects = 0, $opts = array()) { @@ -868,15 +891,18 @@ function discover_by_url($url,$arr = null) { if($feed->error()) logger('probe_url: scrape_feed: Error parsing XML: ' . $feed->error()); + $name = unxmlify(trim($feed->get_title())); $photo = $feed->get_image_url(); $author = $feed->get_author(); if($author) { - $name = unxmlify(trim($author->get_name())); if(! $name) + $name = unxmlify(trim($author->get_name())); + if(! $name) { $name = trim(unxmlify($author->get_email())); - if(strpos($name,'@') !== false) - $name = substr($name,0,strpos($name,'@')); + if(strpos($name,'@') !== false) + $name = substr($name,0,strpos($name,'@')); + } if(! $profile && $author->get_link()) $profile = trim(unxmlify($author->get_link())); if(! $photo) { @@ -893,11 +919,13 @@ function discover_by_url($url,$arr = null) { if($item) { $author = $item->get_author(); if($author) { - $name = trim(unxmlify($author->get_name())); - if(! $name) - $name = trim(unxmlify($author->get_email())); - if(strpos($name,'@') !== false) - $name = substr($name,0,strpos($name,'@')); + if(! $name) { + $name = trim(unxmlify($author->get_name())); + if(! $name) + $name = trim(unxmlify($author->get_email())); + if(strpos($name,'@') !== false) + $name = substr($name,0,strpos($name,'@')); + } if(! $profile && $author->get_link()) $profile = trim(unxmlify($author->get_link())); } @@ -924,8 +952,7 @@ function discover_by_url($url,$arr = null) { if(! $network) { $network = 'rss'; } - if(! $name) - $name = notags($feed->get_title()); + if(! $name) $name = notags($feed->get_description()); @@ -1029,7 +1056,7 @@ function discover_by_webbie($webbie) { } } - if($diaspora && $diaspora_base && $diaspora_guid && intval(get_config('system','diaspora_enabled'))) { + if($diaspora && $diaspora_base && $diaspora_guid) { $guid = $diaspora_guid; $diaspora_base = trim($diaspora_base,'/'); diff --git a/include/onepoll.php b/include/onepoll.php index d64785f92..1f28852e9 100644 --- a/include/onepoll.php +++ b/include/onepoll.php @@ -67,7 +67,7 @@ function onepoll_run($argv, $argc){ logger("onepoll: poll: ({$contact['id']}) IMPORTER: {$importer['xchan_name']}, CONTACT: {$contact['xchan_name']}"); - $last_update = ((($contact['abook_updated'] === $contact['abook_created']) || ($contact['abook_updated'] === '0000-00-00 00:00:00')) + $last_update = ((($contact['abook_updated'] === $contact['abook_created']) || ($contact['abook_updated'] === NULL_DATE)) ? datetime_convert('UTC','UTC','now - 7 days') : datetime_convert('UTC','UTC',$contact['abook_updated'] . ' - 2 days') ); diff --git a/include/plugin.php b/include/plugin.php index c5f57829d..c2e08a989 100755 --- a/include/plugin.php +++ b/include/plugin.php @@ -430,93 +430,6 @@ function get_theme_screenshot($theme) { } -// check service_class restrictions. If there are no service_classes defined, everything is allowed. -// if $usage is supplied, we check against a maximum count and return true if the current usage is -// less than the subscriber plan allows. Otherwise we return boolean true or false if the property -// is allowed (or not) in this subscriber plan. An unset property for this service plan means -// the property is allowed, so it is only necessary to provide negative properties for each plan, -// or what the subscriber is not allowed to do. - - -function service_class_allows($uid,$property,$usage = false) { - $a = get_app(); - if($uid == local_user()) { - $service_class = $a->account['account_service_class']; - } - else { - $r = q("select account_service_class as service_class - from channel c, account a - where c.channel_account_id=a.account_id and c.channel_id= %d limit 1", - intval($uid) - ); - if($r !== false and count($r)) { - $service_class = $r[0]['service_class']; - } - } - if(! x($service_class)) - return true; // everything is allowed - - $arr = get_config('service_class',$service_class); - if(! is_array($arr) || (! count($arr))) - return true; - - if($usage === false) - return ((x($arr[$property])) ? (bool) $arr['property'] : true); - else { - if(! array_key_exists($property,$arr)) - return true; - return (((intval($usage)) < intval($arr[$property])) ? true : false); - } -} - - -function service_class_fetch($uid,$property) { - $a = get_app(); - if($uid == local_user()) { - $service_class = $a->account['account_service_class']; - } - else { - $r = q("select account_service_class as service_class - from channel c, account a - where c.channel_account_id=a.account_id and c.channel_id= %d limit 1", - intval($uid) - ); - if($r !== false and count($r)) { - $service_class = $r[0]['service_class']; - } - } - if(! x($service_class)) - return false; // everything is allowed - - $arr = get_config('service_class',$service_class); - - if(! is_array($arr) || (! count($arr))) - return false; - - return((array_key_exists($property,$arr)) ? $arr[$property] : false); -} - -function upgrade_link($bbcode = false) { - $l = get_config('service_class','upgrade_link'); - if(! $l) - return ''; - if($bbcode) - $t = sprintf('[zrl=%s]' . t('Click here to upgrade.') . '[/zrl]', $l); - else - $t = sprintf('<a href="%s">' . t('Click here to upgrade.') . '</div>', $l); - return $t; -} - -function upgrade_message($bbcode = false) { - $x = upgrade_link($bbcode); - return t('This action exceeds the limits set by your subscription plan.') . (($x) ? ' ' . $x : '') ; -} - -function upgrade_bool_message($bbcode = false) { - $x = upgrade_link($bbcode); - return t('This action is not available under your subscription plan.') . (($x) ? ' ' . $x : '') ; -} - /** * @brief add CSS to <head> * diff --git a/include/poller.php b/include/poller.php index 2ba86dc0b..c90e48d6b 100644 --- a/include/poller.php +++ b/include/poller.php @@ -35,12 +35,15 @@ function poller_run($argv, $argc){ // expire any expired mail - q("delete from mail where expires != '0000-00-00 00:00:00' and expires < UTC_TIMESTAMP() "); + q("delete from mail where expires != '%s' and expires < UTC_TIMESTAMP() ", + dbesc(NULL_DATE) + ); // expire any expired items - $r = q("select id from item where expires != '0000-00-00 00:00:00' and expires < UTC_TIMESTAMP() + $r = q("select id from item where expires != '%s' and expires < UTC_TIMESTAMP() and not ( item_restrict & %d ) ", + dbesc(NULL_DATE), intval(ITEM_DELETED) ); if($r) { @@ -151,7 +154,6 @@ function poller_run($argv, $argc){ q("delete from notify where seen = 1 and date < UTC_TIMESTAMP() - INTERVAL 30 DAY"); // expire any expired accounts - require_once('include/account.php'); downgrade_accounts(); // If this is a directory server, request a sync with an upstream @@ -264,7 +266,9 @@ function poller_run($argv, $argc){ $c = $contact['abook_connected']; if($contact['abook_flags'] & ABOOK_FLAG_FEED) { - $min = intval(get_config('system','minimum_feedcheck_minutes')); + $min = service_class_fetch($contact['abook_channel'],'minimum_feedcheck_minutes'); + if(! $min) + $min = intval(get_config('system','minimum_feedcheck_minutes')); if(! $min) $min = 60; $x = datetime_convert('UTC','UTC',"now - $min minutes"); @@ -284,7 +288,7 @@ function poller_run($argv, $argc){ else { // if we've never connected with them, start the mark for death countdown from now - if($c == '0000-00-00 00:00:00') { + if($c == NULL_DATE) { $r = q("update abook set abook_connected = '%s' where abook_id = %d limit 1", dbesc(datetime_convert()), intval($contact['abook_id']) @@ -337,8 +341,9 @@ function poller_run($argv, $argc){ } if($dirmode == DIRECTORY_MODE_SECONDARY || $dirmode == DIRECTORY_MODE_PRIMARY) { - $r = q("select distinct ud_addr, updates.* from updates where not ( ud_flags & %d ) and ud_addr != '' and ( ud_last = '0000-00-00 00:00:00' OR ud_last > UTC_TIMESTAMP() - INTERVAL 7 DAY ) group by ud_addr ", - intval(UPDATE_FLAGS_UPDATED) + $r = q("select distinct ud_addr, updates.* from updates where not ( ud_flags & %d ) and ud_addr != '' and ( ud_last = '%s' OR ud_last > UTC_TIMESTAMP() - INTERVAL 7 DAY ) group by ud_addr ", + intval(UPDATE_FLAGS_UPDATED), + dbesc(NULL_DATE) ); if($r) { foreach($r as $rr) { @@ -346,7 +351,7 @@ function poller_run($argv, $argc){ // If they didn't respond when we attempted before, back off to once a day // After 7 days we won't bother anymore - if($rr['ud_last'] != '0000-00-00 00:00:00') + if($rr['ud_last'] != NULL_DATE) if($rr['ud_last'] > datetime_convert('UTC','UTC', 'now - 1 day')) continue; proc_run('php','include/onedirsync.php',$rr['ud_id']); diff --git a/include/socgraph.php b/include/socgraph.php index e12da5862..504a6b2c0 100644 --- a/include/socgraph.php +++ b/include/socgraph.php @@ -123,7 +123,8 @@ function poco_load($xchan = '',$url = null) { $profile_url = $url['value']; continue; } - if($url['type'] == 'zot') { + if($url['type'] == 'zot' || $url['type'] == 'diaspora' || $url['type'] == 'friendica') { + $network = $url['type']; $address = str_replace('acct:' , '', $url['value']); continue; } @@ -151,17 +152,25 @@ function poco_load($xchan = '',$url = null) { if(($x !== false) && (! count($x))) { if($address) { - $z = zot_finger($address,null); - if($z['success']) { - $j = json_decode($z['body'],true); - if($j) - import_xchan($j); + if($network === 'zot') { + $z = zot_finger($address,null); + if($z['success']) { + $j = json_decode($z['body'],true); + if($j) + import_xchan($j); + } + $x = q("select xchan_hash from xchan where xchan_hash = '%s' limit 1", + dbesc($hash) + ); + if(! $x) { + continue; + } } - $x = q("select xchan_hash from xchan where xchan_hash = '%s' limit 1", - dbesc($hash) - ); - if(! $x) { - continue; + else { + $x = import_author_diaspora(array('address' => $address)); + if(! $x) { + continue; + } } } else { diff --git a/include/text.php b/include/text.php index 7da6a8f2b..599c5d445 100644 --- a/include/text.php +++ b/include/text.php @@ -508,8 +508,14 @@ function logger($msg,$level = 0) { if((! $debugging) || (! $logfile) || ($level > $loglevel)) return; - - @file_put_contents($logfile, datetime_convert() . ':' . session_id() . ' ' . $msg . "\n", FILE_APPEND); + + $where = ''; + if(version_compare(PHP_VERSION,'5.4.0') >= 0) { + $stack = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS,2); + $where = basename($stack[0]['file']) . ':' . $stack[0]['line'] . ':' . $stack[1]['function'] . ': '; + } + + @file_put_contents($logfile, datetime_convert() . ':' . session_id() . ' ' . $where . $msg . "\n", FILE_APPEND); return; } @@ -966,6 +972,7 @@ function smilies($s, $sample = false) { || (local_user() && intval(get_pconfig(local_user(),'system','no_smilies')))) return $s; + $s = preg_replace_callback('{<(pre|code)>.*?</\1>}ism','smile_shield',$s); $s = preg_replace_callback('/<[a-z]+ .*?>/ism','smile_shield',$s); @@ -1040,8 +1047,8 @@ function smilies($s, $sample = false) { '<img class="smiley" src="' . $a->get_baseurl() . '/images/smiley-facepalm.gif" alt=":facepalm" />', '<img class="smiley" src="' . $a->get_baseurl() . '/images/like.gif" alt=":like" />', '<img class="smiley" src="' . $a->get_baseurl() . '/images/dislike.gif" alt=":dislike" />', - '<a href="http://getzot.com"><strong>red<img class="smiley" src="' . $a->get_baseurl() . '/images/rm-16.png" alt="red#matrix" />matrix</strong></a>', - '<a href="http://getzot.com"><strong>red<img class="smiley" src="' . $a->get_baseurl() . '/images/rm-16.png" alt="red#" />matrix</strong></a>', + '<a href="http://getzot.com"><strong>red<img class="smiley" src="' . $a->get_baseurl() . '/images/rm-16.png" alt="' . urlencode('red#matrix') . '" />matrix</strong></a>', + '<a href="http://getzot.com"><strong>red<img class="smiley" src="' . $a->get_baseurl() . '/images/rm-16.png" alt="' . urlencode('red#') . '" />matrix</strong></a>', '<a href="http://getzot.com"><strong>red<img class="smiley" src="' . $a->get_baseurl() . '/images/rm-16.png" alt="r#" />matrix</strong></a>' ); @@ -2027,4 +2034,19 @@ function normalise_openid($s) { return trim(str_replace(array('http://','https://'),array('',''),$s),'/'); } +// used in ajax endless scroll request to find out all the args that the master page was viewing. +// This was using $_REQUEST, but $_REQUEST also contains all your cookies. So we're restricting it +// to $_GET. If this is used in a post handler, that decision may need to be considered. +function extra_query_args() { + $s = ''; + if(count($_GET)) { + foreach($_GET as $k => $v) { + // these are request vars we don't want to duplicate + if(! in_array($k, array('q','f','zid','page','PHPSESSID'))) { + $s .= '&' . $k . '=' . $v; + } + } + } + return $s; +}
\ No newline at end of file diff --git a/include/zot.php b/include/zot.php index 6ccee8c39..f5099df8c 100644 --- a/include/zot.php +++ b/include/zot.php @@ -384,7 +384,7 @@ function zot_refresh($them,$channel = null, $force = false) { $next_birthday = datetime_convert('UTC','UTC',$j['profile']['next_birthday']); } else { - $next_birthday = '0000-00-00 00:00:00'; + $next_birthday = NULL_DATE; } if($r) { @@ -1024,7 +1024,7 @@ function import_xchan($arr,$ud_flags = UPDATE_FLAGS_UPDATED, $ud_arr = null) { $realm = get_directory_realm(); if(array_key_exists('site',$arr) && array_key_exists('realm',$arr['site']) - && (strpos($arr['site']['realm'],$realm) !== false)) + && (strpos($arr['site']['realm'],$realm) === false)) $other_realm = true; if($dirmode != DIRECTORY_MODE_NORMAL) { |