From c533c62c640cf081c44bf0489680ee3be3e45ecb Mon Sep 17 00:00:00 2001 From: zotlabs Date: Sun, 5 Mar 2017 14:47:20 -0800 Subject: some event work --- include/bbcode.php | 1 + include/event.php | 4 ++++ 2 files changed, 5 insertions(+) (limited to 'include') diff --git a/include/bbcode.php b/include/bbcode.php index c0033f280..5aa61760f 100644 --- a/include/bbcode.php +++ b/include/bbcode.php @@ -1174,6 +1174,7 @@ function bbcode($Text, $preserve_nl = false, $tryoembed = true, $cache = false) $Text = preg_replace("/\[event\-start\](.*?)\[\/event\-start\]/ism",$sub,$Text); + $Text = preg_replace("/\event\](.*?)\[\/event\]/ism",'',$Text); $Text = preg_replace("/\[event\-summary\](.*?)\[\/event\-summary\]/ism",'',$Text); $Text = preg_replace("/\[event\-description\](.*?)\[\/event\-description\]/ism",'',$Text); $Text = preg_replace("/\[event\-finish\](.*?)\[\/event\-finish\]/ism",'',$Text); diff --git a/include/event.php b/include/event.php index a9634d7a5..726eb667c 100644 --- a/include/event.php +++ b/include/event.php @@ -210,6 +210,10 @@ function format_event_bbcode($ev) { $o = ''; + if($ev['event_vdata']) { + $o .= '[event]' . $ev['event_vdata'] . '[/event]'; + } + if($ev['summary']) $o .= '[event-summary]' . $ev['summary'] . '[/event-summary]'; -- cgit v1.2.3 From 9ca53fdc5d5d3515a4074527a619a6d6f2ef55cf Mon Sep 17 00:00:00 2001 From: zotlabs Date: Tue, 7 Mar 2017 17:44:19 -0800 Subject: DCV stuff --- include/markdown.php | 26 ++++++-------------------- 1 file changed, 6 insertions(+), 20 deletions(-) (limited to 'include') diff --git a/include/markdown.php b/include/markdown.php index 7e1f1c42c..de95544af 100644 --- a/include/markdown.php +++ b/include/markdown.php @@ -314,7 +314,11 @@ function bb2diaspora_itemwallwall(&$item,$uplink = false) { // We will provide wallwall (embedded author on the Diaspora side) if // 1. It is a wall-to-wall post // 2. A comment arrived which has no Diaspora signature info + // 3. The channel allows us to send unsigned activities + $dcv = get_pconfig($item['uid'],'system','diaspora_send_unsigned'); + if(! $dcv) + return; $wallwall = false; $author_exists = true; @@ -346,7 +350,8 @@ function bb2diaspora_itemwallwall(&$item,$uplink = false) { if($uplink) $wallwall = true; - if(($wallwall) && (is_array($item['author'])) && $item['author']['xchan_url'] && $item['author']['xchan_name'] && $item['author']['xchan_photo_s']) { + if(($wallwall) && (is_array($item['author'])) && $item['author']['xchan_url'] + && $item['author']['xchan_name'] && $item['author']['xchan_photo_s']) { logger('bb2diaspora_itemwallwall: wall to wall post',LOGGER_DEBUG); // post will come across with the owner's identity. Throw a preamble onto the post to indicate the true author. $item['body'] = "\n\n" @@ -373,25 +378,6 @@ function bb2diaspora_itembody($item, $force_update = false, $have_channel = fals $matches = array(); - if(($item['diaspora_meta']) && (! $force_update)) { - $diaspora_meta = json_decode($item['diaspora_meta'],true); - if($diaspora_meta) { - if(array_key_exists('iv',$diaspora_meta)) { - $key = get_config('system','prvkey'); - $meta = json_decode(crypto_unencapsulate($diaspora_meta,$key),true); - } - else { - $meta = $diaspora_meta; - } - if($meta) { - logger('bb2diaspora_itembody: cached '); - $newitem = $item; - $newitem['body'] = $meta['body']; - return $newitem['body']; - } - } - } - create_export_photo_body($item); $newitem = $item; -- cgit v1.2.3 From 15ab331b6b5793d04979e204af92084e8d5bb03c Mon Sep 17 00:00:00 2001 From: zotlabs Date: Wed, 8 Mar 2017 17:35:19 -0800 Subject: move all the diaspora content hacks to the diaspora plugin --- include/markdown.php | 417 ++------------------------------------------------- 1 file changed, 9 insertions(+), 408 deletions(-) (limited to 'include') diff --git a/include/markdown.php b/include/markdown.php index de95544af..841540357 100644 --- a/include/markdown.php +++ b/include/markdown.php @@ -81,70 +81,6 @@ function share_unshield($m) { return str_replace($m[1], base64url_decode($x), $m[0]); } - -function diaspora_mention_callback($matches) { - - $webbie = $matches[2] . '@' . $matches[3]; - $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) { - $x = discover_by_webbie($webbie); - if($x) { - $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]; - - if($r && $r[0]['hubloc_network'] === 'zot') - return '@[zrl=' . $link . ']' . trim($matches[1]) . ((substr($matches[0],-1,1) === '+') ? '+' : '') . '[/zrl]' ; - else - return '@[url=' . $link . ']' . trim($matches[1]) . ((substr($matches[0],-1,1) === '+') ? '+' : '') . '[/url]' ; - -} - -function diaspora_mention_callback2($matches) { - - $webbie = $matches[1] . '@' . $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) { - $x = discover_by_webbie($webbie); - if($x) { - $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']; - } - - $name = (($r) ? $r[0]['xchan_name'] : $matches[1]); - - if(! $link) - $link = 'https://' . $matches[2] . '/u/' . $matches[1]; - - if($r && $r[0]['hubloc_network'] === 'zot') - return '@[zrl=' . $link . ']' . trim($name) . ((substr($matches[0],-1,1) === '+') ? '+' : '') . '[/zrl]' ; - else - return '@[url=' . $link . ']' . trim($name) . ((substr($matches[0],-1,1) === '+') ? '+' : '') . '[/url]' ; - -} - - - /** * @brief * @@ -157,28 +93,29 @@ function diaspora_mention_callback2($matches) { * @param boolean $use_zrl default false * @return string */ -function markdown_to_bb($s, $use_zrl = false) { - $s = str_replace(" ","\r",$s); - $s = str_replace(" \n>","",$s); +function markdown_to_bb($s, $use_zrl = false, $options = []) { + if(is_array($s)) { btlogger('markdown_to_bb called with array. ' . print_r($s,true), LOGGER_NORMAL, LOG_WARNING); return ''; } + + $s = str_replace(" ","\r",$s); + $s = str_replace(" \n>","",$s); + $s = html_entity_decode($s,ENT_COMPAT,'UTF-8'); // if empty link text replace with the url $s = preg_replace("/\[\]\((.*?)\)/ism",'[$1]($1)',$s); - // first try plustags + $x = [ 'text' => $s , 'zrl' => $use_zrl, 'options' => $options ]; - $s = preg_replace_callback('/\@\{(.+?)\; (.+?)\@(.+?)\}\+/','diaspora_mention_callback',$s); - $s = preg_replace_callback('/\@\{(.+?)\; (.+?)\@(.+?)\}/','diaspora_mention_callback',$s); + call_hooks('markdown_to_bb_init',$x); - $s = preg_replace_callback('/\@\{(.+?)\@(.+?)\}\+/','diaspora_mention_callback2',$s); - $s = preg_replace_callback('/\@\{(.+?)\@(.+?)\}/','diaspora_mention_callback2',$s); + $s = $x['text']; // Escaping the hash tags - doesn't always seem to work // $s = preg_replace('/\#([^\s\#])/','\\#$1',$s); @@ -193,9 +130,6 @@ function markdown_to_bb($s, $use_zrl = false) { $s = html2bbcode($s); - // protect the recycle symbol from turning into a tag, but without unescaping angles and naked ampersands - $s = str_replace('♲',html_entity_decode('♲',ENT_QUOTES,'UTF-8'),$s); - // Convert everything that looks like a link to a link if($use_zrl) { $s = str_replace(array('[img','/img]'),array('[zmg','/zmg]'),$s); @@ -217,336 +151,3 @@ function markdown_to_bb($s, $use_zrl = false) { } -function stripdcode_br_cb($s) { - return '[code]' . str_replace('
', "\n\t", $s[1]) . '[/code]'; -} - - -////////////////////// -// The following "diaspora_ul" and "diaspora_ol" are only appropriate for the -// pre-Markdownify conversion. If Markdownify isn't used, use the non-Markdownify -// versions below -////////////////////// -/* -function diaspora_ul($s) { - // Replace "[*]" followed by any number (including zero) of - // spaces by "* " to match Diaspora's list format - if( strpos($s[0], "[list]") === 0 ) - return '
    ' . preg_replace("/\[\*\]( *)/", "* ", $s[1]) . '
'; - elseif( strpos($s[0], "[ul]") === 0 ) - return '
    ' . preg_replace("/\[\*\]( *)/", "* ", $s[1]) . '
'; - else - return $s[0]; -} - - -function diaspora_ol($s) { - // A hack: Diaspora will create a properly-numbered ordered list even - // if you use '1.' for each element of the list, like: - // 1. First element - // 1. Second element - // 1. Third element - if( strpos($s[0], "[list=1]") === 0 ) - return '
    ' . preg_replace("/\[\*\]( *)/", "1. ", $s[1]) . '
'; - elseif( strpos($s[0], "[list=i]") === 0 ) - return '
    ' . preg_replace("/\[\*\]( *)/", "1. ", $s[1]) . '
'; - elseif( strpos($s[0], "[list=I]") === 0 ) - return '
    ' . preg_replace("/\[\*\]( *)/", "1. ", $s[1]) . '
'; - elseif( strpos($s[0], "[list=a]") === 0 ) - return '
    ' . preg_replace("/\[\*\]( *)/", "1. ", $s[1]) . '
'; - elseif( strpos($s[0], "[list=A]") === 0 ) - return '
    ' . preg_replace("/\[\*\]( *)/", "1. ", $s[1]) . '
'; - elseif( strpos($s[0], "[ol]") === 0 ) - return '
    ' . preg_replace("/\[\*\]( *)/", "1. ", $s[1]) . '
'; - else - return $s[0]; -} -*/ - -////////////////////// -// Non-Markdownify versions of "diaspora_ol" and "diaspora_ul" -////////////////////// -/** - * @brief - * - * Replace "[\\*]" followed by any number (including zero) of - * spaces by "* " to match Diaspora's list format. - * - * @param string $s - * @return string - */ -function diaspora_ul($s) { - return preg_replace("/\[\\\\\*\]( *)/", "* ", $s[1]); -} - -/** - * @brief - * - * A hack: Diaspora will create a properly-numbered ordered list even - * if you use '1.' for each element of the list, like: - * \code - * 1. First element - * 1. Second element - * 1. Third element - * \endcode - * @param string $s - * @return string - */ -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_itemwallwall(&$item,$uplink = false) { - - // We will provide wallwall (embedded author on the Diaspora side) if - // 1. It is a wall-to-wall post - // 2. A comment arrived which has no Diaspora signature info - // 3. The channel allows us to send unsigned activities - - $dcv = get_pconfig($item['uid'],'system','diaspora_send_unsigned'); - if(! $dcv) - return; - - $wallwall = false; - $author_exists = true; - - if(! array_key_exists('author',$item)) { - $author_exists = false; - logger('bb2diaspora_itemwallwall: no author'); - $r = q("select * from xchan where xchan_hash = '%s' limit 1", - dbesc($item['author_xchan']) - ); - if($r) - $item['author'] = $r[0]; - } - - $has_meta = false; - if($item['diaspora_meta'] || get_iconfig($item,'diaspora','fields')) - $has_meta = true; - - if($item['author_xchan'] != $item['owner_xchan']) { - if($item['mid'] == $item['parent_mid']) - $wallwall = true; - else { - if(! $has_meta) { - $wallwall = true; - } - } - } - - if($uplink) - $wallwall = true; - - if(($wallwall) && (is_array($item['author'])) && $item['author']['xchan_url'] - && $item['author']['xchan_name'] && $item['author']['xchan_photo_s']) { - logger('bb2diaspora_itemwallwall: wall to wall post',LOGGER_DEBUG); - // post will come across with the owner's identity. Throw a preamble onto the post to indicate the true author. - $item['body'] = "\n\n" - . '[quote]' - . '[img]' . $item['author']['xchan_photo_s'] . '[/img]' - . ' ' - . '[url=' . $item['author']['xchan_url'] . '][b]' . $item['author']['xchan_name'] . '[/b][/url]' . "\n\n" - . $item['body'] - . '[/quote]'; - } - - // $item['author'] might cause a surprise further down the line if it wasn't expected to be here. - - if(! $author_exists) - unset($item['author']); -} - - -function bb2diaspora_itembody($item, $force_update = false, $have_channel = false, $uplink = false) { - - if(! get_iconfig($item,'diaspora','fields')) { - $force_update = true; - } - - $matches = array(); - - create_export_photo_body($item); - - $newitem = $item; - - if(array_key_exists('item_obscured',$item) && intval($item['item_obscured'])) { - $key = get_config('system','prvkey'); - $b = json_decode($item['body'],true); - // if called from diaspora_process_outbound, this decoding has already been done. - // Everything else that calls us will not yet be decoded. - if($b && is_array($b) && array_key_exists('iv',$b)) { - $newitem['title'] = (($item['title']) ? crypto_unencapsulate(json_decode($item['title'],true),$key) : ''); - $newitem['body'] = (($item['body']) ? crypto_unencapsulate(json_decode($item['body'],true),$key) : ''); - } - } - - if(! $have_channel) - bb2diaspora_itemwallwall($newitem,$uplink); - - $title = $newitem['title']; - $body = preg_replace('/\#\^http/i', 'http', $newitem['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, LOGGER_DATA); - - return html_entity_decode($body); -} - -function bb2diaspora($Text, $preserve_nl = false, $fordiaspora = true) { - - // Re-enabling the converter again. - // The bbcode parser now handles youtube-links (and the other stuff) correctly. - // Additionally the html code is now fixed so that lists are now working. - - /* - * Transform #tags, strip off the [url] and replace spaces with underscore - */ - $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); - - // strip map tags, as the rendering is performed in bbcode() and the resulting output - // is not compatible with Diaspora (at least in the case of openstreetmap and probably - // due to the inclusion of an html iframe) - - $Text = preg_replace("/\[map\=(.*?)\]/ism", '$1', $Text); - $Text = preg_replace("/\[map\](.*?)\[\/map\]/ism", '$1', $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); - - // 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 - //if ($fordiaspora) - // $Text = preg_replace("/\[url\=([^\[\]]*)\]\s*\[img\](.*?)\[\/img\]\s*\[\/url\]/ism", - // "[url]$1[/url]\n[img]$2[/img]", $Text); - - // Convert it to HTML - don't try oembed - $Text = bbcode($Text, $preserve_nl, false); - - // Markdownify does not preserve previously escaped html entities such as <> and &. - - $Text = str_replace(array('<','>','&'),array('&_lt_;','&_gt_;','&_amp_;'),$Text); - - // Now convert HTML to Markdown - $md = new Converter(Converter::LINK_AFTER_CONTENT, false, false); - $Text = $md->parseString($Text); - - - // It also adds backslashes to our attempt at getting around the html entity preservation for some weird reason. - - $Text = str_replace(array('&\\_lt\\_;','&\\_gt\\_;','&\\_amp\\_;'),array('<','>','&'),$Text); - - // If the text going into bbcode() has a plain URL in it, i.e. - // with no [url] tags around it, it will come out of parseString() - // looking like: , which gets removed by strip_tags(). - // So take off the angle brackets of any such URL - $Text = preg_replace("//is", "http$1", $Text); - - // Remove empty zrl links - $Text = preg_replace("/\[zrl\=\].*?\[\/zrl\]/is", "", $Text); - - // Remove all unconverted tags - $Text = strip_tags($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); - - return $Text; -} - -function unescape_underscores_in_links($m) { - $y = str_replace('\\_','_', $m[2]); - return('[' . $m[1] . '](' . $y . ')'); -} - -function format_event_diaspora($ev) { - - if(! ((is_array($ev)) && count($ev))) - return ''; - - $bd_format = t('l F d, Y \@ g:i A') ; // Friday January 18, 2011 @ 8 AM - - $o = t('$Projectname event notification:') . "\n"; - - $o .= '**' . (($ev['summary']) ? bb2diaspora($ev['summary']) : bb2diaspora($ev['desc'])) . '**' . "\n"; - - $o .= t('Starts:') . ' ' . '[' - . (($ev['adjust']) ? day_translate(datetime_convert('UTC', 'UTC', - $ev['start'] , $bd_format )) - : day_translate(datetime_convert('UTC', 'UTC', - $ev['start'] , $bd_format))) - . '](' . z_root() . '/localtime/?f=&time=' . urlencode(datetime_convert('UTC','UTC',$ev['start'])) . ")\n"; - - if(! $ev['nofinish']) - $o .= t('Finishes:') . ' ' . '[' - . (($ev['adjust']) ? day_translate(datetime_convert('UTC', 'UTC', - $ev['finish'] , $bd_format )) - : day_translate(datetime_convert('UTC', 'UTC', - $ev['finish'] , $bd_format ))) - . '](' . z_root() . '/localtime/?f=&time=' . urlencode(datetime_convert('UTC','UTC',$ev['finish'])) . ")\n"; - - if(strlen($ev['location'])) - $o .= t('Location:') . bb2diaspora($ev['location']) - . "\n"; - - $o .= "\n"; - - return $o; -} -- cgit v1.2.3 From b6477cd38b532ebe69a480460e7b883964ec6627 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Thu, 9 Mar 2017 11:51:21 -0800 Subject: go back to where the problem started --- include/items.php | 70 +------ include/network.php | 543 ++-------------------------------------------------- 2 files changed, 13 insertions(+), 600 deletions(-) (limited to 'include') diff --git a/include/items.php b/include/items.php index 6d21953a9..8032f53c4 100755 --- a/include/items.php +++ b/include/items.php @@ -600,11 +600,6 @@ function get_item_elements($x,$allow_code = false) { $arr['sig'] = (($x['signature']) ? htmlspecialchars($x['signature'], ENT_COMPAT,'UTF-8',false) : ''); - if(array_key_exists('diaspora_signature',$x) && is_array($x['diaspora_signature'])) - $x['diaspora_signature'] = json_encode($x['diaspora_signature']); - - $arr['diaspora_meta'] = (($x['diaspora_signature']) ? $x['diaspora_signature'] : ''); - $arr['obj'] = activity_sanitise($x['object']); $arr['target'] = activity_sanitise($x['target']); @@ -1035,17 +1030,7 @@ function encode_item($item,$mirror = false) { if($item['iconfig']) $x['meta'] = encode_item_meta($item['iconfig'],$mirror); - if($item['diaspora_meta']) { - $z = json_decode($item['diaspora_meta'],true); - if($z) { - if(is_array($z) && array_key_exists('iv',$z)) - $x['diaspora_signature'] = crypto_unencapsulate($z,$key); - else - $x['diaspora_signature'] = $z; - if(! is_array($z)) - logger('encode_item: diaspora meta is not an array: ' . print_r($z,true)); - } - } + logger('encode_item: ' . print_r($x,true), LOGGER_DATA); return $x; @@ -1324,7 +1309,6 @@ function encode_mail($item,$extended = false) { $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']); @@ -1517,7 +1501,6 @@ function item_store($arr, $allow_exec = false, $deliver = true) { $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']) : ''); @@ -2027,7 +2010,7 @@ function item_store_update($arr,$allow_exec = false, $deliver = true) { $arr['changed'] = $orig[0]['changed']; $arr['route'] = ((array_key_exists('route',$arr)) ? trim($arr['route']) : $orig[0]['route']); - $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']); @@ -2186,55 +2169,6 @@ function item_store_update($arr,$allow_exec = false, $deliver = true) { -function store_diaspora_comment_sig($datarray, $channel, $parent_item, $post_id, $walltowall = false) { - - // We won't be able to sign Diaspora comments for authenticated visitors - // - we don't have their private key - - // since Diaspora doesn't handle edits we can only do this for the original text and not update it. - - require_once('include/markdown.php'); - $signed_body = bb2diaspora_itembody($datarray,$walltowall); - - if($walltowall) { - logger('wall to wall comment',LOGGER_DEBUG); - // post will come across with the owner's identity. Throw a preamble onto the post to indicate the true author. - $signed_body = "\n\n" - . '![' . $datarray['author']['xchan_name'] . '](' . $datarray['author']['xchan_photo_m'] . ')' - . '[' . $datarray['author']['xchan_name'] . '](' . $datarray['author']['xchan_url'] . ')' . "\n\n" - . $signed_body; - } - - logger('storing diaspora comment signature',LOGGER_DEBUG); - - $diaspora_handle = channel_reddress($channel); - - $signed_text = $datarray['mid'] . ';' . $parent_item['mid'] . ';' . $signed_body . ';' . $diaspora_handle; - - - if( $channel && $channel['channel_prvkey'] ) - $authorsig = base64_encode(rsa_sign($signed_text, $channel['channel_prvkey'], 'sha256')); - else - $authorsig = ''; - - $x = array('signer' => $diaspora_handle, 'body' => $signed_body, 'signed_text' => $signed_text, 'signature' => $authorsig); - - $y = json_encode($x); - - $r = q("update item set diaspora_meta = '%s' where id = %d", - dbesc($y), - intval($post_id) - ); - - - if(! $r) - logger('store_diaspora_comment_sig: DB write failed'); - - return; -} - - - function send_status_notifications($post_id,$item) { // only send notifications for comments diff --git a/include/network.php b/include/network.php index 6d1a05e9f..4d0bc6f0b 100644 --- a/include/network.php +++ b/include/network.php @@ -984,40 +984,6 @@ function email_header_encode($in_str, $charset = 'UTF-8') { return $out_str; } -function email_send($addr, $subject, $headers, $item) { - //$headers .= 'MIME-Version: 1.0' . "\n"; - //$headers .= 'Content-Type: text/html; charset=UTF-8' . "\n"; - //$headers .= 'Content-Type: text/plain; charset=UTF-8' . "\n"; - //$headers .= 'Content-Transfer-Encoding: 8bit' . "\n\n"; - - $part = uniqid("", true); - - $html = prepare_body($item); - - $headers .= "Mime-Version: 1.0\n"; - $headers .= 'Content-Type: multipart/alternative; boundary="=_'.$part.'"'."\n\n"; - - $body = "\n--=_".$part."\n"; - $body .= "Content-Transfer-Encoding: 8bit\n"; - $body .= "Content-Type: text/plain; charset=utf-8; format=flowed\n\n"; - - $body .= html2plain($html)."\n"; - - $body .= "--=_".$part."\n"; - $body .= "Content-Transfer-Encoding: 8bit\n"; - $body .= "Content-Type: text/html; charset=utf-8\n\n"; - - $body .= ''.$html."\n"; - - $body .= "--=_".$part."--"; - - //$message = '' . $html . ''; - //$message = html2plain($html); - logger('notifier: email delivery to ' . $addr); - mail($addr, $subject, $body, $headers); -} - - function discover_by_url($url,$arr = null) { require_once('library/HTML5/Parser.php'); @@ -1027,10 +993,10 @@ function discover_by_url($url,$arr = null) { if(! $arr) return false; $network = (($arr['network']) ? $arr['network'] : 'unknown'); - $name = (($arr['name']) ? $arr['name'] : 'unknown'); - $photo = (($arr['photo']) ? $arr['photo'] : ''); - $addr = (($arr['addr']) ? $arr['addr'] : ''); - $guid = $url; + $name = (($arr['name']) ? $arr['name'] : 'unknown'); + $photo = (($arr['photo']) ? $arr['photo'] : ''); + $addr = (($arr['addr']) ? $arr['addr'] : ''); + $guid = $url; } $profile = $url; @@ -1067,8 +1033,8 @@ 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(); + $name = unxmlify(trim($feed->get_title())); + $photo = $feed->get_image_url(); $author = $feed->get_author(); if($author) { @@ -1172,23 +1138,11 @@ function discover_by_url($url,$arr = null) { function discover_by_webbie($webbie) { - require_once('library/HTML5/Parser.php'); - $result = array(); + $result = []; $network = null; - $diaspora = false; - $gnusoc = false; - $dfrn = false; - - $has_salmon = false; - $salmon_key = false; - $atom_feed = false; - $diaspora_base = ''; - $diaspora_guid = ''; - $diaspora_key = ''; - $webbie = strtolower($webbie); $x = webfinger_rfc7033($webbie,true); @@ -1214,21 +1168,6 @@ function discover_by_webbie($webbie) { } } } - if($link['rel'] == NAMESPACE_DFRN) { - $dfrn = $link['href']; - } - if($link['rel'] == 'magic-public-key') { - if(substr($link['href'],0,5) === 'data:') { - $salmon_key = convert_salmon_key($link['href']); - } - } - if($link['rel'] == 'salmon') { - $has_salmon = true; - $salmon = $link['href']; - } - if($link['rel'] == 'http://schemas.google.com/g/2010#updates-from') { - $atom_feed = $link['href']; - } } } } @@ -1240,287 +1179,9 @@ function discover_by_webbie($webbie) { if($arr['success']) return true; - $aliases = array(); - - // Now let's make some decisions on what we may need - // to obtain further info - - $probe_atom = false; - $probe_old = false; - $probe_hcard = false; - - $address = ''; - $location = ''; - $nickname = ''; - $fullname = ''; - $avatar = ''; - $pubkey = ''; - - if(is_array($x)) { - if(array_key_exists('address',$x)) - $address = $x['address']; - if(array_key_exists('location',$x)) - $location = $x['location']; - if(array_key_exists('nickname',$x)) - $nickname = $x['nickname']; - } - - if(! $x) - $probe_old = true; - - - if((! $dfrn) && (! $has_salmon)) - $probe_old = true; - - if($probe_old) { - $y = old_webfinger($webbie); - if($y) { - logger('old_webfinger: ' . print_r($x,true)); - foreach($y as $link) { - if($link['@attributes']['rel'] === NAMESPACE_DFRN) - $dfrn = unamp($link['@attributes']['href']); - if($link['@attributes']['rel'] === 'salmon') - $notify = unamp($link['@attributes']['href']); - if($link['@attributes']['rel'] === NAMESPACE_FEED) - $poll = unamp($link['@attributes']['href']); - if($link['@attributes']['rel'] === 'http://microformats.org/profile/hcard') - $hcard = unamp($link['@attributes']['href']); - if($link['@attributes']['rel'] === 'http://webfinger.net/rel/profile-page') - $profile = unamp($link['@attributes']['href']); - if($link['@attributes']['rel'] === 'http://portablecontacts.net/spec/1.0') - $poco = unamp($link['@attributes']['href']); - if($link['@attributes']['rel'] === 'http://joindiaspora.com/seed_location') { - $diaspora_base = unamp($link['@attributes']['href']); - $diaspora = true; - } - if($link['@attributes']['rel'] === 'http://joindiaspora.com/guid') { - $diaspora_guid = unamp($link['@attributes']['href']); - $diaspora = true; - } - if($link['@attributes']['rel'] === 'diaspora-public-key') { - $diaspora_key = base64_decode(unamp($link['@attributes']['href'])); - if(strstr($diaspora_key,'RSA ')) - $pubkey = rsatopem($diaspora_key); - else - $pubkey = $diaspora_key; - $diaspora = true; - } - if($link['@attributes']['rel'] == 'magic-public-key') { - if(substr($link['@attributes']['href'],0,5) === 'data:') { - $salmon_key = convert_salmon_key($link['@attributes']['href']); - } - } - if($link['@attributes']['rel'] == 'salmon') { - $has_salmon = true; - $salmon = $link['@attributes']['href']; - } - - if($link['@attributes']['rel'] == 'http://schemas.google.com/g/2010#updates-from') { - $atom_feed = $link['@attributes']['href']; - } - if($link['@attributes']['rel'] === 'alias') { - $aliases[] = $link['@attributes']['href']; - } - if($link['@attributes']['rel'] === 'subject') { - $subject = $link['@attributes']['href']; - } - } - } - } - - if($subject || $aliases) { - if(strpos($webbie,'@')) { - $rhs = substr($webbie,strpos($webbie,'@')+1); - } - else { - $m = parse_url($webbie); - if($m) { - $rhs = $m['host'] . (($m['port']) ? ':' . $m['port'] : ''); - } - } - - $v = array('subject' => $subject,'aliases' => $aliases); - $address = find_webfinger_address($v,$rhs); - $location = find_webfinger_location($v,$rhs); - if($address) - $nickname = substr($address,0,strpos($address,'@')); - - } - - if($salmon_key && $has_salmon && $atom_feed && (! $dfrn) && (! $diaspora)) { - $gnusoc = true; - $probe_atom = true; - } - - if(! $pubkey) - $pubkey = $salmon_key; - - if(($dfrn || $diaspora) && $hcard) - $probe_hcard = true; - - if(! $fullname) - $fullname = $nickname; - - if($probe_atom) { - $k = z_fetch_url($atom_feed); - if($k['success']) - $feed_meta = feed_meta($k['body']); - if($feed_meta) { - - // stash any discovered pubsubhubbub hubs in case we need to follow them - // this will save an expensive lookup later - - if($feed_meta['hubs'] && $address) { - set_xconfig($address,'system','push_hubs',$feed_meta['hubs']); - set_xconfig($address,'system','feed_url',$atom_feed); - } - if($feed_meta['author']['author_name']) { - $fullname = $feed_meta['author']['author_name']; - } - if(! $avatar) { - if($feed_meta['author']['author_photo']) - $avatar = $feed_meta['author']['author_photo']; - } - - // for GNU-social over-ride any url aliases we may have picked up in webfinger - // The author.uri element in the feed is likely to be more accurate - - if($gnusoc && $feed_meta['author']['author_uri']) - $location = $feed_meta['author']['author_uri']; - } - } - else { - if($probe_hcard) { - $vcard = scrape_vcard($hcard); - if($vcard) { - logger('vcard: ' . print_r($vcard,true), LOGGER_DATA); - if($vcard['fn']) - $fullname = $vcard['fn']; - if($vcard['photo'] && (strpos($vcard['photo'],'http') !== 0)) - $vcard['photo'] = $diaspora_base . '/' . $vcard['photo']; - if(($vcard['public_key']) && (! $pubkey)) { - $diaspora_key = $vcard['public_key']; - if(strstr($diaspora_key,'RSA ')) - $pubkey = rsatopem($diaspora_key); - else - $pubkey = $diaspora_key; - } - if(! $avatar) - $avatar = $vcard['photo']; - if($diaspora) { - if(($vcard['uid']) && (! $diaspora_guid)) - $diaspora_guid = $vcard['uid']; - if(($vcard['url']) && (! $diaspora_base)) - $diaspora_base = $vcard['url']; - - - - - } - - } - } - } - - if(($profile) && (! $location)) - $location = $profile; - - if($location) { - $m = parse_url($location); - $base = $m['scheme'] . '://' . $m['host']; - $host = $m['host']; - } - - - if($diaspora && $diaspora_base && $diaspora_guid) { - if($dfrn) - $network = 'friendica-over-diaspora'; - else - $network = 'diaspora'; - - $base = trim($diaspora_base,'/'); - $notify = $base . '/receive'; - - } - else { - if($gnusoc) { - $network = 'gnusoc'; - $notify = $salmon; - } - } - - - logger('network: ' . $network); - logger('address: ' . $address); - logger('fullname: ' . $fullname); - logger('pubkey: ' . $pubkey); - logger('location: ' . $location); - - - - // if we have everything we need, let's create the records - - if($network && $address && $fullname && $pubkey && $location) { - $r = q("select * from xchan where xchan_hash = '%s' limit 1", - dbesc($address) - ); - if($r) { - $r = q("update xchan set xchan_name = '%s', xchan_network = '%s', xchan_name_date = '%s' where xchan_hash = '%s'", - dbesc($fullname), - dbesc($network), - dbesc(datetime_convert()), - dbesc($address) - ); - } - else { - $r = xchan_store_lowlevel( - [ - 'xchan_hash' => $address, - 'xchan_guid' => (($diaspora_guid) ? $diaspora_guid : $location), - 'xchan_pubkey' => $pubkey, - 'xchan_addr' => $address, - 'xchan_url' => $location, - 'xchan_name' => $fullname, - 'xchan_name_date' => datetime_convert(), - 'xchan_network' => $network - ] - ); - } - - $r = q("select * from hubloc where hubloc_hash = '%s' limit 1", - dbesc($address) - ); - - if(! $r) { - $r = hubloc_store_lowlevel( - [ - 'hubloc_guid' => (($diaspora_guid) ? $diaspora_guid : $location), - 'hubloc_hash' => $address, - 'hubloc_addr' => $address, - 'hubloc_network' => $network, - 'hubloc_url' => $base, - 'hubloc_host' => $host, - 'hubloc_callback' => $notify, - 'hubloc_updated' => datetime_convert(), - 'hubloc_primary' => 1 - ] - ); - } - $photos = import_xchan_photo($avatar,$address); - $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_hash = '%s'", - dbescdate(datetime_convert()), - dbesc($photos[0]), - dbesc($photos[1]), - dbesc($photos[2]), - dbesc($photos[3]), - dbesc($address) - ); - return true; - } return false; -} - +} function webfinger_rfc7033($webbie,$zot = false) { @@ -1547,88 +1208,13 @@ function webfinger_rfc7033($webbie,$zot = false) { if($s['success']) { $j = json_decode($s['body'],true); - - // We could have a number of URL aliases and webbies - // make an executive decision about the most likely "best" of each - // by comparing against some examples from known networks we're likely to encounter. - // Otherwise we have to store every alias that we may ever encounter and - // validate every URL we ever find against every possible alias - - // @fixme pump.io is going to be a real bugger since it doesn't return subject or aliases - // or provide lookup by url - - $j['address'] = find_webfinger_address($j,$rhs); - $j['location'] = find_webfinger_location($j,$rhs); - if($j['address']) - $j['nickname'] = substr($j['address'],0,strpos($j['address'],'@')); - } - else - return false; - - return($j); -} - -function find_webfinger_address($j,$rhs) { - if(is_array($j) && ($j)) { - if(strpos($j['subject'],'acct:') !== false && strpos($j['subject'],'@' . $rhs)) - return str_replace('acct:','',$j['subject']); - if($j['aliases']) { - foreach($j['aliases'] as $alias) { - if(strpos($alias,'acct:') !== false && strpos($alias,'@' . $rhs)) { - return str_replace('acct:','',$alias); - } - } - } - } - return ''; -} - - -function find_webfinger_location($j,$rhs) { - if(is_array($j) && ($j)) { - if(strpos($j['subject'],'http') === 0) { - $x = match_webfinger_location($j['subject'],$rhs); - if($x) - return $x; - } - if($j['aliases']) { - foreach($j['aliases'] as $alias) { - if(strpos($alias,'http') === 0) { - $x = match_webfinger_location($alias,$rhs); - if($x) - return($x); - } - } - } + return($j); } - return ''; -} - -function match_webfinger_location($s,$h) { - // GNU-social and the older StatusNet - the $host/user/123 form doesn't work - if(preg_match('|' . $h . '/index.php/user/([0-9]*?)$|',$s)) - return $s; - // Redmatrix / hubzilla - if(preg_match('|' . $h . '/channel/|',$s)) - return $s; - // Friendica - if(preg_match('|' . $h . '/profile/|',$s)) - return $s; + return false; - $arr = array('test' => $s, 'host' => $h, 'success' => false); - call_hooks('match_webfinger_location',$arr); - if($arr['success']) - return $s; - return ''; } - - - - - - function old_webfinger($webbie) { $host = ''; @@ -1696,9 +1282,6 @@ function fetch_xrd_links($url) { if ((! $xml) || (! stristr($xml,''),array('href="','"/>'),$xml); - $h = parse_xml_string($xml); if(! $h) return array(); @@ -1738,85 +1321,6 @@ function fetch_xrd_links($url) { } -function scrape_vcard($url) { - - $ret = array(); - - logger('scrape_vcard: url=' . $url); - - $x = z_fetch_url($url); - if(! $x['success']) - return $ret; - - $s = $x['body']; - - if(! $s) - return $ret; - - $headers = $x['header']; - $lines = explode("\n",$headers); - if(count($lines)) { - foreach($lines as $line) { - // don't try and run feeds through the html5 parser - if(stristr($line,'content-type:') && ((stristr($line,'application/atom+xml')) || (stristr($line,'application/rss+xml')))) - return ret; - } - } - - try { - $dom = HTML5_Parser::parse($s); - } catch (DOMException $e) { - logger('scrape_vcard: parse error: ' . $e); - } - - if(! $dom) - return $ret; - - // Pull out hCard profile elements - - $largest_photo = 0; - - $items = $dom->getElementsByTagName('*'); - foreach($items as $item) { - if(attribute_contains($item->getAttribute('class'), 'vcard')) { - $level2 = $item->getElementsByTagName('*'); - foreach($level2 as $x) { - if(attribute_contains($x->getAttribute('id'),'pod_location')) - $ret['pod_location'] = $x->textContent; - if(attribute_contains($x->getAttribute('class'),'fn')) - $ret['fn'] = $x->textContent; - if(attribute_contains($x->getAttribute('class'),'uid')) - $ret['uid'] = $x->textContent; - if(attribute_contains($x->getAttribute('class'),'nickname')) - $ret['nick'] = $x->textContent; - if(attribute_contains($x->getAttribute('class'),'searchable')) - $ret['searchable'] = $x->textContent; - if(attribute_contains($x->getAttribute('class'),'key')) - $ret['public_key'] = $x->textContent; - if(attribute_contains($x->getAttribute('class'),'given_name')) - $ret['given_name'] = $x->textContent; - if(attribute_contains($x->getAttribute('class'),'family_name')) - $ret['family_name'] = $x->textContent; - if(attribute_contains($x->getAttribute('class'),'url')) - $ret['url'] = $x->textContent; - - if((attribute_contains($x->getAttribute('class'),'photo')) - || (attribute_contains($x->getAttribute('class'),'avatar'))) { - $size = intval($x->getAttribute('width')); - if(($size > $largest_photo) || (! $largest_photo)) { - $ret['photo'] = $x->getAttribute('src'); - $largest_photo = $size; - } - } - } - } - } - - return $ret; -} - - - function scrape_feed($url) { $ret = array(); @@ -1910,31 +1414,6 @@ function scrape_feed($url) { } - -function service_plink($contact, $guid) { - - $plink = ''; - - $m = parse_url($contact['xchan_url']); - if($m) { - $url = $m['scheme'] . '://' . $m['host'] . (($m['port']) ? ':' . $m['port'] : ''); - } - else - $url = 'https://' . substr($contact['xchan_addr'],strpos($contact['xchan_addr'],'@')+1); - - $handle = substr($contact['xchan_addr'], 0, strpos($contact['xchan_addr'],'@')); - - if($contact['xchan_network'] === 'diaspora') - $plink = $url . '/posts/' . $guid; - if($contact['xchan_network'] === 'friendica-over-diaspora') - $plink = $url . '/display/' . $handle . '/' . $guid; - if($contact['xchan_network'] === 'zot') - $plink = $url . '/channel/' . $handle . '?f=&mid=' . $guid; - - return $plink; -} - - function format_and_send_email($sender,$xchan,$item) { $title = $item['title']; @@ -1944,7 +1423,7 @@ function format_and_send_email($sender,$xchan,$item) { $htmlversion = bbcode(str_replace(array("\\r","\\n"), array("","
\n"),$body)); - $banner = t('$Projectname Notification'); + $banner = t('$Projectname Notification'); $product = t('$projectname'); // PLATFORM_NAME; $siteurl = z_root(); $thanks = t('Thank You,'); -- cgit v1.2.3 From c93db2cd218d5a1e8ff6e5b243b99e7fcbae36ea Mon Sep 17 00:00:00 2001 From: zotlabs Date: Thu, 9 Mar 2017 14:31:54 -0800 Subject: more cleanup --- include/items.php | 35 +---------------------------------- include/text.php | 6 ++---- 2 files changed, 3 insertions(+), 38 deletions(-) (limited to 'include') diff --git a/include/items.php b/include/items.php index 033863c42..58305aa63 100755 --- a/include/items.php +++ b/include/items.php @@ -248,8 +248,6 @@ function can_comment_on_post($observer_xchan, $item) { } if(strstr($item['comment_policy'],'network:') && strstr($item['comment_policy'],'red')) return true; - if(strstr($item['comment_policy'],'network:') && strstr($item['comment_policy'],'diaspora')) - return true; if(strstr($item['comment_policy'],'site:') && strstr($item['comment_policy'],App::get_hostname())) return true; @@ -766,8 +764,6 @@ 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); @@ -780,36 +776,6 @@ function import_author_xchan($x) { return(($y) ? $y : false); } -/** - * @brief Imports an author from Diaspora. - * - * @param array $x an associative array with - * * \e string \b address - * @return boolean|string false on error, otherwise xchan_hash of the new entry - */ -function import_author_diaspora($x) { - if(! $x['address']) - return false; - - $r = q("select * from xchan where xchan_addr = '%s' limit 1", - dbesc($x['address']) - ); - if($r) { - logger('in_cache: ' . $x['address'], LOGGER_DATA); - return $r[0]['xchan_hash']; - } - - 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; -} - /** * @brief Imports an author from a RSS feed. * @@ -819,6 +785,7 @@ function import_author_diaspora($x) { * * \e string \b guid * @return boolean|string */ + function import_author_rss($x) { if(! $x['url']) return false; diff --git a/include/text.php b/include/text.php index 9d76f9d78..fe3206b32 100644 --- a/include/text.php +++ b/include/text.php @@ -1183,8 +1183,7 @@ function list_smilies() { ':coffee', ':facepalm', ':like', - ':dislike', - ':hubzilla' + ':dislike' ); $icons = array( @@ -1219,8 +1218,7 @@ function list_smilies() { ':coffee', ':facepalm', ':like', - ':dislike', - ':hubzilla', + ':dislike' ); -- cgit v1.2.3 From 6f3493bb3ca3718d4b69278c96df384c8a4d5811 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Sun, 12 Mar 2017 15:50:47 -0700 Subject: db issues --- include/dba/dba_pdo.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'include') diff --git a/include/dba/dba_pdo.php b/include/dba/dba_pdo.php index f76e6cdd7..f119d8926 100755 --- a/include/dba/dba_pdo.php +++ b/include/dba/dba_pdo.php @@ -74,19 +74,19 @@ class dba_pdo extends dba_driver { return $result; } - if($this->debug) { - db_logger('dba_pdo: DEBUG: ' . printable($sql) . ' returned ' . count($result) . ' results.', LOGGER_NORMAL, LOG_INFO); - } - $r = array(); if($result) { foreach($result as $x) { $r[] = $x; } - if($this->debug) { - db_logger('dba_pdo: ' . printable(print_r($r,true)), LOGGER_NORMAL, LOG_INFO); - } } + + if($this->debug) { + db_logger('dba_pdo: DEBUG: ' . printable($sql) . ' returned ' . count($r) . ' results.', LOGGER_NORMAL, LOG_INFO); + db_logger('dba_pdo: ' . printable(print_r($r,true)), LOGGER_NORMAL, LOG_INFO); + } + + return (($this->error) ? false : $r); } -- cgit v1.2.3 From c39c925d8db1fd6a62033c1ece71cc4424899935 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Sun, 12 Mar 2017 17:32:45 -0700 Subject: grrr. stop making branding assumptions. --- include/help.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include') diff --git a/include/help.php b/include/help.php index e4725575d..ab31e9400 100644 --- a/include/help.php +++ b/include/help.php @@ -57,7 +57,7 @@ function get_help_content($tocpath = false) { if(! $text) { $doctype = 'bbcode'; $text = load_doc_file('doc/main.bb'); - goaway('/help/about/about_hubzilla'); + goaway('/help/about/about'); \App::$page['title'] = t('Help'); } -- cgit v1.2.3 From 1ee76cb5066870db9ea427e00e5c18edfb292496 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Sun, 12 Mar 2017 20:54:48 -0700 Subject: remove more hardwired branding --- include/network.php | 52 +++++++++++++++++++-------------------- include/photos.php | 70 +++++++++++++++++++++++++++-------------------------- 2 files changed, 62 insertions(+), 60 deletions(-) (limited to 'include') diff --git a/include/network.php b/include/network.php index 4d0bc6f0b..bce59d38c 100644 --- a/include/network.php +++ b/include/network.php @@ -1611,33 +1611,33 @@ function get_site_info() { - $data = Array( - 'version' => $version, - 'version_tag' => $tag, - 'server_role' => Zotlabs\Lib\System::get_server_role(), - 'commit' => $commit, - 'url' => z_root(), - 'plugins' => $visible_plugins, - 'register_policy' => $register_policy[get_config('system','register_policy')], - 'invitation_only' => intval(get_config('system','invitation_only')), - 'directory_mode' => $directory_mode[get_config('system','directory_mode')], - 'language' => get_config('system','language'), - 'rss_connections' => intval(get_config('system','feed_contacts')), - 'expiration' => $site_expire, + $data = [ + 'url' => z_root(), + 'platform' => Zotlabs\Lib\System::get_platform_name(), + 'site_name' => (($site_name) ? $site_name : ''), + 'version' => $version, + 'version_tag' => $tag, + 'server_role' => Zotlabs\Lib\System::get_server_role(), + 'commit' => $commit, + 'plugins' => $visible_plugins, + 'register_policy' => $register_policy[get_config('system','register_policy')], + 'invitation_only' => intval(get_config('system','invitation_only')), + 'directory_mode' => $directory_mode[get_config('system','directory_mode')], + 'language' => get_config('system','language'), + 'rss_connections' => intval(get_config('system','feed_contacts')), + 'expiration' => $site_expire, 'default_service_restrictions' => $service_class, - 'locked_features' => $locked_features, - 'admin' => $admin, - 'site_name' => (($site_name) ? $site_name : ''), - 'platform' => Zotlabs\Lib\System::get_platform_name(), - 'dbdriver' => DBA::$dba->getdriver(), - 'lastpoll' => get_config('system','lastpoll'), - 'info' => (($site_info) ? $site_info : ''), - 'channels_total' => $channels_total_stat, - 'channels_active_halfyear' => $channels_active_halfyear_stat, - 'channels_active_monthly' => $channels_active_monthly_stat, - 'local_posts' => $local_posts_stat, - 'hide_in_statistics' => $hide_in_statistics - ); + 'locked_features' => $locked_features, + 'admin' => $admin, + 'dbdriver' => DBA::$dba->getdriver(), + 'lastpoll' => get_config('system','lastpoll'), + 'info' => (($site_info) ? $site_info : ''), + 'channels_total' => $channels_total_stat, + 'channels_active_halfyear' => $channels_active_halfyear_stat, + 'channels_active_monthly' => $channels_active_monthly_stat, + 'local_posts' => $local_posts_stat, + 'hide_in_statistics' => $hide_in_statistics + ]; return $data; } diff --git a/include/photos.php b/include/photos.php index c0f7dc8c4..68ff32924 100644 --- a/include/photos.php +++ b/include/photos.php @@ -17,6 +17,7 @@ require_once('include/text.php'); * @param array $args * @return array */ + function photo_upload($channel, $observer, $args) { $ret = array('success' => false); @@ -28,9 +29,6 @@ function photo_upload($channel, $observer, $args) { return $ret; } - -//call_hooks('photo_upload_begin', $args); - /* * Determine the album to use */ @@ -90,8 +88,6 @@ function photo_upload($channel, $observer, $args) { } else { $f = array('src' => '', 'filename' => '', 'filesize' => 0, 'type' => ''); -// call_hooks('photo_upload_file',$f); - if (x($f,'src') && x($f,'filesize')) { $src = $f['src']; $filename = $f['filename']; @@ -374,37 +370,37 @@ function photo_upload($channel, $observer, $args) { else { $mid = item_message_id(); - $arr = array(); - - if($lat && $lon) - $arr['coord'] = $lat . ' ' . $lon; + $arr = [ + 'aid' => $account_id, + 'uid' => $channel_id, + 'mid' => $mid, + 'parent_mid' => $mid, + 'item_hidden' => $item_hidden, + 'resource_type' => 'photo', + 'resource_id' => $photo_hash, + 'owner_xchan' => $channel['channel_hash'], + 'author_xchan' => $observer['xchan_hash'], + 'title' => $title, + 'allow_cid' => $ac['allow_cid'], + 'allow_gid' => $ac['allow_gid'], + 'deny_cid' => $ac['deny_cid'], + 'deny_gid' => $ac['deny_gid'], + 'verb' => ACTIVITY_POST, + 'obj_type' => ACTIVITY_OBJ_PHOTO, + 'obj' => json_encode($object), + 'tgt_type' => ACTIVITY_OBJ_ALBUM, + 'target' => json_encode($target), + 'item_wall' => $visible, + 'item_origin' => 1, + 'item_thread_top' => 1, + 'item_private' => intval($acl->is_private()), + 'body' => $summary + ]; - $arr['aid'] = $account_id; - $arr['uid'] = $channel_id; - $arr['mid'] = $mid; - $arr['parent_mid'] = $mid; - $arr['item_hidden'] = $item_hidden; - $arr['resource_type'] = 'photo'; - $arr['resource_id'] = $photo_hash; - $arr['owner_xchan'] = $channel['channel_hash']; - $arr['author_xchan'] = $observer['xchan_hash']; - $arr['title'] = $title; - $arr['allow_cid'] = $ac['allow_cid']; - $arr['allow_gid'] = $ac['allow_gid']; - $arr['deny_cid'] = $ac['deny_cid']; - $arr['deny_gid'] = $ac['deny_gid']; - $arr['verb'] = ACTIVITY_POST; - $arr['obj_type'] = ACTIVITY_OBJ_PHOTO; - $arr['obj'] = json_encode($object); - $arr['tgt_type'] = ACTIVITY_OBJ_ALBUM; - $arr['target'] = json_encode($target); - $arr['item_wall'] = 1; - $arr['item_origin'] = 1; - $arr['item_thread_top'] = 1; - $arr['item_private'] = intval($acl->is_private()); $arr['plink'] = z_root() . '/channel/' . $channel['channel_address'] . '/?f=&mid=' . urlencode($arr['mid']); - $arr['body'] = $summary; + if($lat && $lon) + $arr['coord'] = $lat . ' ' . $lon; // this one is tricky because the item and the photo have the same permissions, those of the photo. // Use the channel read_stream permissions to get the correct public_policy for the item and recalculate the @@ -451,6 +447,7 @@ function photo_upload($channel, $observer, $args) { * * \e boolean \b success * * \e array \b albums */ + function photos_albums_list($channel, $observer, $sort_key = 'album', $direction = 'asc') { $channel_id = $channel['channel_id']; @@ -531,6 +528,7 @@ function photos_album_widget($channelx,$observer,$sortkey = 'album',$direction = * @param string $album default empty * @return boolean|array */ + function photos_list_photos($channel, $observer, $album = '') { $channel_id = $channel['channel_id']; @@ -570,6 +568,7 @@ function photos_list_photos($channel, $observer, $album = '') { * @param string $album name of the album * @return boolean */ + function photos_album_exists($channel_id, $album) { $r = q("SELECT id FROM photo WHERE album = '%s' AND uid = %d limit 1", dbesc($album), @@ -589,6 +588,7 @@ function photos_album_exists($channel_id, $album) { * @param string $newname The new name of the album * @return bool|array */ + function photos_album_rename($channel_id, $oldname, $newname) { return q("UPDATE photo SET album = '%s' WHERE album = '%s' AND uid = %d", dbesc($newname), @@ -607,6 +607,7 @@ function photos_album_rename($channel_id, $oldname, $newname) { * @param string $remote_xchan * @return string|boolean */ + function photos_album_get_db_idstr($channel_id, $album, $remote_xchan = '') { if ($remote_xchan) { @@ -642,6 +643,7 @@ function photos_album_get_db_idstr($channel_id, $album, $remote_xchan = '') { * @param boolean $visible default false * @return int item_id */ + function photos_create_item($channel, $creator_hash, $photo, $visible = false) { // Create item container @@ -697,7 +699,7 @@ function getGps($exifCoord, $hemi) { function getGpstimestamp($exifCoord) { - $hours = count($exifCoord) > 0 ? gps2Num($exifCoord[0]) : 0; + $hours = count($exifCoord) > 0 ? gps2Num($exifCoord[0]) : 0; $minutes = count($exifCoord) > 1 ? gps2Num($exifCoord[1]) : 0; $seconds = count($exifCoord) > 2 ? gps2Num($exifCoord[2]) : 0; -- cgit v1.2.3 From 58aa0f3e1a52a0c20016a4330100231ad505e6e4 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Mon, 13 Mar 2017 16:19:47 -0700 Subject: code_allowed is a real mess. Start the cleanup by remving the account level code allow and limiting to specific channels only. This reduces the possibility of cross channel security issues coming into play. Then provide a single function for checking the code permission. This is only partially done as we often need to check against the observer or logged in channel as well as the resource owner to ensure that this only returns true for local channels which also own the requested resource. --- include/channel.php | 17 +++++++++++++++++ include/import.php | 34 +++------------------------------- include/text.php | 26 ++++---------------------- 3 files changed, 24 insertions(+), 53 deletions(-) (limited to 'include') diff --git a/include/channel.php b/include/channel.php index b838f8393..ceb5eeb7a 100644 --- a/include/channel.php +++ b/include/channel.php @@ -2252,3 +2252,20 @@ function channel_remove($channel_id, $local = true, $unset_session=false) { } } + +/* + * This checks if a channel is allowed to publish executable code. + * It is up to the caller to determine if the observer or local_channel + * is in fact the resource owner whose channel_id is being checked + */ + +function channel_codeallowed($channel_id) { + + if(! intval($channel_id)) + return false; + + $x = channelx_by_n($channel_id); + if(($x) && ($x['channel_pageflags'] & PAGE_ALLOWCODE)) + return true; + return false; +} \ No newline at end of file diff --git a/include/import.php b/include/import.php index 5c73b7ca3..bbe930864 100644 --- a/include/import.php +++ b/include/import.php @@ -534,16 +534,8 @@ function sync_chatrooms($channel,$chatrooms) { function import_items($channel,$items,$sync = false,$relocate = null) { if($channel && $items) { - $allow_code = false; - $r = q("select account_id, account_roles, channel_pageflags from account left join channel on channel_account_id = account_id - where channel_id = %d limit 1", - intval($channel['channel_id']) - ); - if($r) { - if(($r[0]['account_roles'] & ACCOUNT_ROLE_ALLOWCODE) || ($r[0]['channel_pageflags'] & PAGE_ALLOWCODE)) { - $allow_code = true; - } - } + + $allow_code = channel_codeallowed($channel['channel_id']); $deliver = false; // Don't deliver any messages or notifications when importing @@ -1358,28 +1350,8 @@ function import_webpage_element($element, $channel, $type) { } // Verify ability to use html or php!!! - $execflag = false; - if($arr['mimetype'] === 'application/x-php' || $arr['mimetype'] === 'text/html') { - $z = q("select account_id, account_roles, channel_pageflags from account " - . "left join channel on channel_account_id = account_id where channel_id = %d limit 1", - intval(local_channel()) - ); - if($z && (($z[0]['account_roles'] & ACCOUNT_ROLE_ALLOWCODE) || ($z[0]['channel_pageflags'] & PAGE_ALLOWCODE))) { - $execflag = true; - } - else { - logger('Unable to import element "' . $name .'" because AllowCode permission is denied.'); - notice( t('Unable to import element "' . $name .'" because AllowCode permission is denied.') . EOL); - $element['import_success'] = 0; - return $element; - } - } - -// $z = q("select * from iconfig where v = '%s' and k = '%s' and cat = 'system' limit 1", -// dbesc($name), -// dbesc($namespace) -// ); + $execflag = channel_codeallowed(local_channel()); $i = q("select id, edited, item_deleted from item where mid = '%s' and uid = %d limit 1", dbesc($arr['mid']), diff --git a/include/text.php b/include/text.php index fe3206b32..6715eca22 100644 --- a/include/text.php +++ b/include/text.php @@ -104,15 +104,11 @@ function z_input_filter($channel_id,$s,$type = 'text/bbcode') { return $s; } - $r = q("select account_id, account_roles, channel_pageflags from account left join channel on channel_account_id = account_id where channel_id = %d limit 1", + $r = q("select channel_pageflags from channel where channel_id = %d limit 1", intval($channel_id) ); - if($r) { - if(($r[0]['account_roles'] & ACCOUNT_ROLE_ALLOWCODE) || ($r[0]['channel_pageflags'] & PAGE_ALLOWCODE)) { - if(local_channel() && (get_account_id() == $r[0]['account_id'])) { - return $s; - } - } + if(($r) && (local_channel() == $channel_id) && ($r[0]['channel_pageflags'] & PAGE_ALLOWCODE)) { + return $s; } if($type === 'text/html') @@ -1795,23 +1791,9 @@ function mimetype_select($channel_id, $current = 'text/bbcode') { ); - if(App::$is_sys) { + if((App::$is_sys) || (channel_codeallowed($channel_id) && $channel_id == local_channel())){ $x[] = 'application/x-php'; } - else { - $r = q("select account_id, account_roles, channel_pageflags from account left join channel on account_id = channel_account_id where - channel_id = %d limit 1", - intval($channel_id) - ); - - if($r) { - if(($r[0]['account_roles'] & ACCOUNT_ROLE_ALLOWCODE) || ($r[0]['channel_pageflags'] & PAGE_ALLOWCODE)) { - if(local_channel() && get_account_id() == $r[0]['account_id']) { - $x[] = 'application/x-php'; - } - } - } - } foreach($x as $y) { $selected = (($y == $current) ? ' selected="selected" ' : ''); -- cgit v1.2.3 From 2f5f1a4d641c5873c308d6ab58ae239f2758e1e4 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Tue, 14 Mar 2017 16:14:05 -0700 Subject: fix group by item query --- include/items.php | 32 +++++++++++++++----------------- 1 file changed, 15 insertions(+), 17 deletions(-) (limited to 'include') diff --git a/include/items.php b/include/items.php index 58305aa63..1037f9814 100755 --- a/include/items.php +++ b/include/items.php @@ -3674,7 +3674,7 @@ function zot_feed($uid,$observer_hash,$arr) { if(! is_sys_channel($uid)) $sql_extra = item_permissions_sql($uid,$observer_hash); - $limit = " LIMIT 100 "; + $limit = " LIMIT 5000 "; if($mindate > NULL_DATE) { $sql_extra .= " and ( created > '$mindate' or changed > '$mindate' ) "; @@ -3686,15 +3686,7 @@ function zot_feed($uid,$observer_hash,$arr) { } - $items = array(); - - /** @FIXME re-unite these SQL statements. There is no need for them to be separate. The mySQL is convoluted with misuse of group by. As it stands, there is a slight difference where the postgres version doesn't remove the duplicate parents up to 100. In practice this doesn't matter. It could be made to match behavior by adding "distinct on (parent) " to the front of the selection list, at a not-worth-it performance penalty (page temp results to disk). duplicates are still ignored in the in() clause, you just get less than 100 parents if there are many children. */ - - if(ACTIVE_DBTYPE == DBTYPE_POSTGRES) { - $groupby = ''; - } else { - $groupby = 'GROUP BY parent'; - } + $items = []; $item_normal = item_normal(); @@ -3703,7 +3695,7 @@ function zot_feed($uid,$observer_hash,$arr) { WHERE uid != %d $item_normal AND item_wall = 1 - and item_private = 0 $sql_extra $groupby ORDER BY created ASC $limit", + and item_private = 0 $sql_extra ORDER BY created ASC $limit", intval($uid) ); } @@ -3711,19 +3703,25 @@ function zot_feed($uid,$observer_hash,$arr) { $r = q("SELECT parent, created, postopts from item WHERE uid = %d $item_normal AND item_wall = 1 - $sql_extra $groupby ORDER BY created ASC $limit", + $sql_extra ORDER BY created ASC $limit", intval($uid) ); } + $parents = []; + if($r) { - for($x = 0; $x < count($r); $x ++) { - if(strpos($r[$x]['postopts'],'nodeliver') !== false) { - unset($r[$x]); - } + foreach($r as $rv) { + if(array_key_exists($rv['parent'],$parents)) + continue; + if(strpos($rv['postopts'],'nodeliver') !== false) + continue; + $parents[$rv['parent']] = $rv; + if(count($parents) > 200) + break; } - $parents_str = ids_to_querystr($r,'parent'); + $parents_str = ids_to_querystr($parents,'parent'); $sys_query = ((is_sys_channel($uid)) ? $sql_extra : ''); $item_normal = item_normal(); -- cgit v1.2.3 From 2c73b457ef0943d46804480a0aa016f64c11edbf Mon Sep 17 00:00:00 2001 From: zotlabs Date: Tue, 14 Mar 2017 17:07:29 -0700 Subject: input filter updates --- include/items.php | 87 +++++++++++++++++++++++-------------------------------- include/text.php | 18 +++++++----- 2 files changed, 48 insertions(+), 57 deletions(-) (limited to 'include') diff --git a/include/items.php b/include/items.php index 1037f9814..c978805cd 100755 --- a/include/items.php +++ b/include/items.php @@ -334,18 +334,6 @@ function post_activity_item($arr,$allow_code = false,$deliver = true) { if(! array_key_exists('mimetype',$arr)) $arr['mimetype'] = 'text/bbcode'; - if(array_key_exists('item_private',$arr) && $arr['item_private']) { - - $arr['body'] = trim(z_input_filter($arr['uid'],$arr['body'],$arr['mimetype'])); - - if($channel) { - if($channel['channel_hash'] === $arr['author_xchan']) { - $arr['sig'] = base64url_encode(rsa_sign($arr['body'],$channel['channel_prvkey'])); - $arr['item_verified'] = 1; - } - } - } - $arr['mid'] = ((x($arr,'mid')) ? $arr['mid'] : item_message_id()); $arr['parent_mid'] = ((x($arr,'parent_mid')) ? $arr['parent_mid'] : $arr['mid']); $arr['thr_parent'] = ((x($arr,'thr_parent')) ? $arr['thr_parent'] : $arr['mid']); @@ -1483,35 +1471,36 @@ function item_store($arr, $allow_exec = false, $deliver = true) { // obsolete, but needed so as not to throw not-null constraints on some database driveres $arr['item_flags'] = ((x($arr,'item_flags')) ? intval($arr['item_flags']) : 0 ); - // only detect language if we have text content, and if the post is private but not yet - // obscured, make it so. - if((! array_key_exists('item_obscured',$arr)) || $arr['item_obscured'] == 0) { - $arr['lang'] = detect_language($arr['body']); - // apply the input filter here - if it is obscured it has been filtered already - $arr['body'] = trim(z_input_filter($arr['uid'],$arr['body'],$arr['mimetype'])); + $arr['lang'] = detect_language($arr['body']); + // apply the input filter here + $arr['body'] = trim(z_input_filter($arr['body'],$arr['mimetype'],$allow_exec)); - if(local_channel() && (local_channel() == $arr['uid']) && (! $arr['sig'])) { + if(local_channel() && (local_channel() == $arr['uid'])) { + if(! $arr['sig']) { $channel = App::get_channel(); if($channel['channel_hash'] === $arr['author_xchan']) { $arr['sig'] = base64url_encode(rsa_sign($arr['body'],$channel['channel_prvkey'])); $arr['item_verified'] = 1; } } + } - $allowed_languages = get_pconfig($arr['uid'],'system','allowed_languages'); + if(! array_key_exists('sig',$arr)) + $arr['sig'] = ''; - if((is_array($allowed_languages)) && ($arr['lang']) && (! array_key_exists($arr['lang'],$allowed_languages))) { - $translate = array('item' => $arr, 'from' => $arr['lang'], 'to' => $allowed_languages, 'translated' => false); - call_hooks('item_translate', $translate); - if((! $translate['translated']) && (intval(get_pconfig($arr['uid'],'system','reject_disallowed_languages')))) { - logger('item_store: language ' . $arr['lang'] . ' not accepted for uid ' . $arr['uid']); - $ret['message'] = 'language not accepted'; - return $ret; - } - $arr = $translate['item']; + $allowed_languages = get_pconfig($arr['uid'],'system','allowed_languages'); + + if((is_array($allowed_languages)) && ($arr['lang']) && (! array_key_exists($arr['lang'],$allowed_languages))) { + $translate = array('item' => $arr, 'from' => $arr['lang'], 'to' => $allowed_languages, 'translated' => false); + call_hooks('item_translate', $translate); + if((! $translate['translated']) && (intval(get_pconfig($arr['uid'],'system','reject_disallowed_languages')))) { + logger('item_store: language ' . $arr['lang'] . ' not accepted for uid ' . $arr['uid']); + $ret['message'] = 'language not accepted'; + return $ret; } + $arr = $translate['item']; } if((x($arr,'obj')) && is_array($arr['obj'])) { @@ -1907,33 +1896,31 @@ function item_store_update($arr,$allow_exec = false, $deliver = true) { return $ret; } - if((! array_key_exists('item_obscured', $arr)) || $arr['item_obscured'] == 0) { - $arr['lang'] = detect_language($arr['body']); + $arr['lang'] = detect_language($arr['body']); - // apply the input filter here - if it is obscured it has been filtered already - $arr['body'] = trim(z_input_filter($arr['uid'],$arr['body'],$arr['mimetype'])); + // apply the input filter here + $arr['body'] = trim($arr['body'],$arr['mimetype'],$allow_exec); - if(local_channel() && (local_channel() == $arr['uid']) && (! $arr['sig'])) { - $channel = App::get_channel(); - if($channel['channel_hash'] === $arr['author_xchan']) { - $arr['sig'] = base64url_encode(rsa_sign($arr['body'],$channel['channel_prvkey'])); - $arr['item_verified'] = 1; - } - } + if(local_channel() && (local_channel() == $arr['uid']) && (! $arr['sig'])) { + $channel = App::get_channel(); + if($channel['channel_hash'] === $arr['author_xchan']) { + $arr['sig'] = base64url_encode(rsa_sign($arr['body'],$channel['channel_prvkey'])); + $arr['item_verified'] = 1; + } + } - $allowed_languages = get_pconfig($arr['uid'],'system','allowed_languages'); + $allowed_languages = get_pconfig($arr['uid'],'system','allowed_languages'); - if((is_array($allowed_languages)) && ($arr['lang']) && (! array_key_exists($arr['lang'],$allowed_languages))) { - $translate = array('item' => $arr, 'from' => $arr['lang'], 'to' => $allowed_languages, 'translated' => false); - call_hooks('item_translate', $translate); - if((! $translate['translated']) && (intval(get_pconfig($arr['uid'],'system','reject_disallowed_languages')))) { - logger('item_store: language ' . $arr['lang'] . ' not accepted for uid ' . $arr['uid']); - $ret['message'] = 'language not accepted'; - return $ret; - } - $arr = $translate['item']; + if((is_array($allowed_languages)) && ($arr['lang']) && (! array_key_exists($arr['lang'],$allowed_languages))) { + $translate = array('item' => $arr, 'from' => $arr['lang'], 'to' => $allowed_languages, 'translated' => false); + call_hooks('item_translate', $translate); + if((! $translate['translated']) && (intval(get_pconfig($arr['uid'],'system','reject_disallowed_languages')))) { + logger('item_store: language ' . $arr['lang'] . ' not accepted for uid ' . $arr['uid']); + $ret['message'] = 'language not accepted'; + return $ret; } + $arr = $translate['item']; } if((x($arr,'obj')) && is_array($arr['obj'])) { diff --git a/include/text.php b/include/text.php index 6715eca22..500c87ad5 100644 --- a/include/text.php +++ b/include/text.php @@ -3,6 +3,7 @@ * @file include/text.php */ +use \Zotlabs\Lib as Zlib; use \Michelf\MarkdownExtra; require_once("include/bbcode.php"); @@ -89,12 +90,10 @@ function escape_tags($string) { } -function z_input_filter($channel_id,$s,$type = 'text/bbcode') { +function z_input_filter($s,$type = 'text/bbcode',$allow_code = false) { if($type === 'text/bbcode') return escape_tags($s); - if($type === 'text/markdown') - return escape_tags($s); if($type == 'text/plain') return escape_tags($s); if($type == 'application/x-pdl') @@ -104,13 +103,17 @@ function z_input_filter($channel_id,$s,$type = 'text/bbcode') { return $s; } - $r = q("select channel_pageflags from channel where channel_id = %d limit 1", - intval($channel_id) - ); - if(($r) && (local_channel() == $channel_id) && ($r[0]['channel_pageflags'] & PAGE_ALLOWCODE)) { + if($allow_code) { + if($type === 'text/markdown') + return htmlspecialchars($s,ENT_QUOTES); return $s; } + if($type === 'text/markdown') { + $x = new Zlib\MarkdownSoap($s); + return $x->clean(); + } + if($type === 'text/html') return purify_html($s); @@ -1636,6 +1639,7 @@ function prepare_text($text, $content_type = 'text/bbcode', $cache = false) { break; case 'text/markdown': + $text = Zlib\MarkdownSoap::unescape($text); $s = MarkdownExtra::defaultTransform($text); break; -- cgit v1.2.3 From e399de8ad4a17c4fa07f7ad41c879278f6ce5458 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Tue, 14 Mar 2017 21:40:11 -0700 Subject: store os_path and display_path with files --- include/attach.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'include') diff --git a/include/attach.php b/include/attach.php index 79313ab1a..f8227fb4b 100644 --- a/include/attach.php +++ b/include/attach.php @@ -705,8 +705,9 @@ function attach_store($channel, $observer_hash, $options = '', $arr = null) { $os_relpath .= $hash; // not yet used - $os_path = ''; - $display_path = ''; + $os_path = ltrim($os_relpath,'/'); + + $display_path = $pathname . '/' . $filename; if($src) @file_put_contents($os_basepath . $os_relpath,@file_get_contents($src)); -- cgit v1.2.3 From fa89b8f66d98f8d74ce9283314649d4916652df9 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Tue, 14 Mar 2017 22:02:28 -0700 Subject: add os_path and display_path to photos, fix some issues with multiple path separators after cloud/nickname in the content field of attach and photos --- include/attach.php | 9 ++--- include/photo/photo_driver.php | 88 +----------------------------------------- include/photos.php | 11 +++--- 3 files changed, 12 insertions(+), 96 deletions(-) (limited to 'include') diff --git a/include/attach.php b/include/attach.php index f8227fb4b..cbcdbc399 100644 --- a/include/attach.php +++ b/include/attach.php @@ -702,11 +702,10 @@ function attach_store($channel, $observer_hash, $options = '', $arr = null) { $os_relpath .= $folder_hash . '/'; } - $os_relpath .= $hash; - - // not yet used - $os_path = ltrim($os_relpath,'/'); + $os_relpath .= $hash; + $os_relpath = ltrim($os_relpath,'/'); + $os_path = $os_relpath; $display_path = $pathname . '/' . $filename; if($src) @@ -811,7 +810,7 @@ function attach_store($channel, $observer_hash, $options = '', $arr = null) { if($is_photo) { - $args = array( 'source' => $source, 'visible' => $visible, 'resource_id' => $hash, 'album' => basename($pathname), 'os_path' => $os_basepath . $os_relpath, 'filename' => $filename, 'getimagesize' => $gis, 'directory' => $direct, 'options' => $options ); + $args = array( 'source' => $source, 'visible' => $visible, 'resource_id' => $hash, 'album' => basename($pathname), 'os_syspath' => $os_basepath . $os_relpath, 'os_path' => $os_path, 'display_path' => $display_path, 'filename' => $filename, 'getimagesize' => $gis, 'directory' => $direct, 'options' => $options ); if($arr['contact_allow']) $args['contact_allow'] = $arr['contact_allow']; if($arr['group_allow']) diff --git a/include/photo/photo_driver.php b/include/photo/photo_driver.php index c8b3c3782..923e34dbe 100644 --- a/include/photo/photo_driver.php +++ b/include/photo/photo_driver.php @@ -380,7 +380,7 @@ abstract class photo_driver { dbesc($p['album']), intval($this->getHeight()), intval($this->getWidth()), - (intval($p['os_storage']) ? dbescbin($p['os_path']) : dbescbin($this->imageString())), + (intval($p['os_storage']) ? dbescbin($p['os_syspath']) : dbescbin($this->imageString())), intval($p['os_storage']), intval(strlen($this->imageString())), intval($p['imgscale']), @@ -411,7 +411,7 @@ abstract class photo_driver { dbesc($p['album']), intval($this->getHeight()), intval($this->getWidth()), - (intval($p['os_storage']) ? dbescbin($p['os_path']) : dbescbin($this->imageString())), + (intval($p['os_storage']) ? dbescbin($p['os_syspath']) : dbescbin($this->imageString())), intval($p['os_storage']), intval(strlen($this->imageString())), intval($p['imgscale']), @@ -429,90 +429,6 @@ abstract class photo_driver { return $r; } - - // should be obsolete now - - public function store($aid, $uid, $xchan, $rid, $filename, $album, $scale, $usage = PHOTO_NORMAL, $allow_cid = '', $allow_gid = '', $deny_cid = '', $deny_gid = '') { - - $x = q("select id from photo where resource_id = '%s' and uid = %d and xchan = '%s' and imgscale = %d limit 1", - dbesc($rid), - intval($uid), - dbesc($xchan), - intval($scale) - ); - if(count($x)) { - $r = q("UPDATE photo - set aid = %d, - uid = %d, - xchan = '%s', - resource_id = '%s', - created = '%s', - edited = '%s', - filename = '%s', - mimetype = '%s', - album = '%s', - height = %d, - width = %d, - content = '%s', - filesize = %d, - imgscale = %d, - photo_usage = %d, - allow_cid = '%s', - allow_gid = '%s', - deny_cid = '%s', - deny_gid = '%s' - where id = %d", - - intval($aid), - intval($uid), - dbesc($xchan), - dbesc($rid), - dbesc(datetime_convert()), - dbesc(datetime_convert()), - dbesc(basename($filename)), - dbesc($this->getType()), - dbesc($album), - intval($this->getHeight()), - intval($this->getWidth()), - dbescbin($this->imageString()), - intval(strlen($this->imageString())), - intval($scale), - intval($photo_usage), - dbesc($allow_cid), - dbesc($allow_gid), - dbesc($deny_cid), - dbesc($deny_gid), - intval($x[0]['id']) - ); - } - else { - $r = q("INSERT INTO photo - ( aid, uid, xchan, resource_id, created, edited, filename, mimetype, album, height, width, content, filesize, imgscale, photo_usage, allow_cid, allow_gid, deny_cid, deny_gid ) - VALUES ( %d, %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d, %d, '%s', %d, %d, %d, '%s', '%s', '%s', '%s' )", - intval($aid), - intval($uid), - dbesc($xchan), - dbesc($rid), - dbesc(datetime_convert()), - dbesc(datetime_convert()), - dbesc(basename($filename)), - dbesc($this->getType()), - dbesc($album), - intval($this->getHeight()), - intval($this->getWidth()), - dbescbin($this->imageString()), - intval(strlen($this->imageString())), - intval($scale), - intval($photo_usage), - dbesc($allow_cid), - dbesc($allow_gid), - dbesc($deny_cid), - dbesc($deny_gid) - ); - } - return $r; - } - } diff --git a/include/photos.php b/include/photos.php index 68ff32924..46007fd42 100644 --- a/include/photos.php +++ b/include/photos.php @@ -65,8 +65,8 @@ function photo_upload($channel, $observer, $args) { $os_storage = 0; - if($args['os_path'] && $args['getimagesize']) { - $imagedata = @file_get_contents($args['os_path']); + if($args['os_syspath'] && $args['getimagesize']) { + $imagedata = @file_get_contents($args['os_syspath']); $filename = $args['filename']; $filesize = strlen($imagedata); // this is going to be deleted if it exists @@ -149,7 +149,7 @@ function photo_upload($channel, $observer, $args) { return $ret; } - $exif = $ph->orient(($args['os_path']) ? $args['os_path'] : $src); + $exif = $ph->orient(($args['os_syspath']) ? $args['os_syspath'] : $src); @unlink($src); @@ -176,7 +176,8 @@ function photo_upload($channel, $observer, $args) { 'filename' => $filename, 'album' => $album, 'imgscale' => 0, 'photo_usage' => PHOTO_NORMAL, 'allow_cid' => $ac['allow_cid'], 'allow_gid' => $ac['allow_gid'], 'deny_cid' => $ac['deny_cid'], 'deny_gid' => $ac['deny_gid'], - 'os_storage' => $os_storage, 'os_path' => $args['os_path'] + 'os_storage' => $os_storage, 'os_syspath' => $args['os_syspath'], + 'os_path' => $args['os_path'], 'display_path' => $args['display_path'] ); if($args['created']) $p['created'] = $args['created']; @@ -201,7 +202,7 @@ function photo_upload($channel, $observer, $args) { $errors = true; unset($p['os_storage']); - unset($p['os_path']); + unset($p['os_syspath']); if(($width > 1024 || $height > 1024) && (! $errors)) $ph->scaleImage(1024); -- cgit v1.2.3 From bcd02edd8032ba3a3de40cbc35dda3529da00a7c Mon Sep 17 00:00:00 2001 From: zotlabs Date: Wed, 15 Mar 2017 15:53:03 -0700 Subject: ensure z_input_filter is called exactly once, since we now depend on the number of htmlspecialchars operations for markdown content. Also ensure that the content is escaped the correct number of times on imported items. --- include/items.php | 68 ++++++++++++++++++++++++++++++++++++------------------ include/photos.php | 9 ++++++++ 2 files changed, 55 insertions(+), 22 deletions(-) (limited to 'include') diff --git a/include/items.php b/include/items.php index c978805cd..ace8b2fb2 100755 --- a/include/items.php +++ b/include/items.php @@ -528,11 +528,6 @@ function get_item_elements($x,$allow_code = false) { $arr = array(); - if($allow_code) - $arr['body'] = $x['body']; - else - $arr['body'] = (($x['body']) ? htmlspecialchars($x['body'],ENT_COMPAT,'UTF-8',false) : ''); - $key = get_config('system','pubkey'); $maxlen = get_max_import_size(); @@ -640,7 +635,17 @@ function get_item_elements($x,$allow_code = false) { return array(); } + // Check signature on the body text received. + // This presents an issue that we aren't verifying the text that is actually displayed + // on this site. We are however verifying the received text was exactly as received. + // We have every right to strip content that poses a security risk. You are welcome to + // create a plugin to verify the content after filtering if this offends you. + if($arr['sig']) { + + // check the supplied signature against the supplied content. + // Note that we will purify the content which could change it. + $r = q("select xchan_pubkey from xchan where xchan_hash = '%s' limit 1", dbesc($arr['author_xchan']) ); @@ -650,6 +655,14 @@ function get_item_elements($x,$allow_code = false) { logger('get_item_elements: message verification failed.'); } + // if the input is markdown, remove one level of html escaping. + // It will be re-applied in item_store() and/or item_store_update(). + // Do this after signature checking as the original signature + // was generated on the escaped content. + + if($arr['mimetype'] === 'text/markdown') + $arr['body'] = \Zotlabs\Lib\MarkdownSoap::unescape($arr['body']); + if(array_key_exists('revision',$x)) { // extended export encoding @@ -1475,14 +1488,20 @@ function item_store($arr, $allow_exec = false, $deliver = true) { $arr['lang'] = detect_language($arr['body']); // apply the input filter here - $arr['body'] = trim(z_input_filter($arr['body'],$arr['mimetype'],$allow_exec)); - - if(local_channel() && (local_channel() == $arr['uid'])) { - if(! $arr['sig']) { - $channel = App::get_channel(); - if($channel['channel_hash'] === $arr['author_xchan']) { - $arr['sig'] = base64url_encode(rsa_sign($arr['body'],$channel['channel_prvkey'])); - $arr['item_verified'] = 1; + + if(array_key_exists('input_filtered_signed',$arr)) { + unset($arr['input_filtered_signed']); + } + else { + $arr['body'] = trim(z_input_filter($arr['body'],$arr['mimetype'],$allow_exec)); + + if(local_channel() && (local_channel() == $arr['uid'])) { + if(! $arr['sig']) { + $channel = App::get_channel(); + if($channel['channel_hash'] === $arr['author_xchan']) { + $arr['sig'] = base64url_encode(rsa_sign($arr['body'],$channel['channel_prvkey'])); + $arr['item_verified'] = 1; + } } } } @@ -1896,17 +1915,22 @@ function item_store_update($arr,$allow_exec = false, $deliver = true) { return $ret; } - $arr['lang'] = detect_language($arr['body']); - // apply the input filter here - $arr['body'] = trim($arr['body'],$arr['mimetype'],$allow_exec); - - if(local_channel() && (local_channel() == $arr['uid']) && (! $arr['sig'])) { - $channel = App::get_channel(); - if($channel['channel_hash'] === $arr['author_xchan']) { - $arr['sig'] = base64url_encode(rsa_sign($arr['body'],$channel['channel_prvkey'])); - $arr['item_verified'] = 1; + if(array_key_exists('input_filtered_signed',$arr)) { + unset($arr['input_filtered_signed']); + } + else { + $arr['body'] = trim(z_input_filter($arr['body'],$arr['mimetype'],$allow_exec)); + + if(local_channel() && (local_channel() == $arr['uid'])) { + if(! $arr['sig']) { + $channel = App::get_channel(); + if($channel['channel_hash'] === $arr['author_xchan']) { + $arr['sig'] = base64url_encode(rsa_sign($arr['body'],$channel['channel_prvkey'])); + $arr['item_verified'] = 1; + } + } } } diff --git a/include/photos.php b/include/photos.php index 46007fd42..c0f0ec8a9 100644 --- a/include/photos.php +++ b/include/photos.php @@ -333,12 +333,15 @@ function photo_upload($channel, $observer, $args) { if($item['mid'] === $item['parent_mid']) { $item['body'] = $summary; + $item['mimetype'] = 'text/bbcode'; $item['obj_type'] = ACTIVITY_OBJ_PHOTO; $item['obj'] = json_encode($object); $item['tgt_type'] = ACTIVITY_OBJ_ALBUM; $item['target'] = json_encode($target); + $item['body'] = trim(z_input_filter($item['body'],$item['mimetype'],false)); + if($item['author_xchan'] === $channel['channel_hash']) { $item['sig'] = base64url_encode(rsa_sign($item['body'],$channel['channel_prvkey'])); $item['item_verified'] = 1; @@ -346,6 +349,12 @@ function photo_upload($channel, $observer, $args) { else { $item['sig'] = ''; } + + // notify item_store or item_store_update that the input has been filtered and signed already. + // The signing procedure in those functions uses local_channel() which may not apply here. + + $item['input_filtered_signed'] = true; + $force = true; } -- cgit v1.2.3 From df6c07aaadda2e89d2843bae136f813c909637ba Mon Sep 17 00:00:00 2001 From: zotlabs Date: Wed, 15 Mar 2017 16:55:47 -0700 Subject: Comanche: allow widgets to be class based and stored appropriately in Zotlabs --- include/widgets.php | 16 ---------------- 1 file changed, 16 deletions(-) (limited to 'include') diff --git a/include/widgets.php b/include/widgets.php index f05c7c0ee..b5389e60d 100644 --- a/include/widgets.php +++ b/include/widgets.php @@ -174,22 +174,6 @@ function widget_follow($args) { } -function widget_notes($arr) { - if(! local_channel()) - return ''; - if(! feature_enabled(local_channel(),'private_notes')) - return ''; - - $text = get_pconfig(local_channel(),'notes','text'); - - $o = replace_macros(get_markup_template('notes.tpl'), array( - '$banner' => t('Notes'), - '$text' => $text, - '$save' => t('Save'), - )); - - return $o; -} function widget_savedsearch($arr) { -- cgit v1.2.3 From 9cb9608209ab5f9fb123acc82a563ba54c450db1 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Wed, 15 Mar 2017 18:31:34 -0700 Subject: convert more widgets to classes --- include/widgets.php | 133 ---------------------------------------------------- 1 file changed, 133 deletions(-) (limited to 'include') diff --git a/include/widgets.php b/include/widgets.php index b5389e60d..86d3989ef 100644 --- a/include/widgets.php +++ b/include/widgets.php @@ -10,141 +10,8 @@ require_once('include/contact_widgets.php'); require_once('include/attach.php'); -function widget_profile($args) { - $block = observer_prohibited(); - return profile_sidebar(App::$profile, $block, true); -} - -function widget_zcard($args) { - - $block = observer_prohibited(); - $channel = channelx_by_n(App::$profile_uid); - return get_zcard($channel,get_observer_hash(),array('width' => 875)); -} - - - - -// FIXME The problem with the next widget is that we don't have a search function for webpages that we can send the links to. -// Then we should also provide an option to search webpages and conversations. - -function widget_tagcloud($args) { - - $o = ''; - //$tab = 0; - - $uid = App::$profile_uid; - $count = ((x($args,'count')) ? intval($args['count']) : 24); - $flags = 0; - $type = TERM_CATEGORY; - - // FIXME there exists no $authors variable - $r = tagadelic($uid, $count, $authors, $owner, $flags, ITEM_TYPE_WEBPAGE, $type); - - if($r) { - $o = '

' . t('Categories') . '

'; - foreach($r as $rr) { - $o .= ''.$rr[0].' ' . "\r\n"; - } - $o .= '
'; - } - return $o; -} - -function widget_collections($args) { - require_once('include/group.php'); - - $mode = ((array_key_exists('mode',$args)) ? $args['mode'] : 'conversation'); - switch($mode) { - case 'conversation': - $every = argv(0); - $each = argv(0); - $edit = true; - $current = $_REQUEST['gid']; - $abook_id = 0; - $wmode = 0; - break; - case 'connections': - $every = 'connections'; - $each = 'group'; - $edit = true; - $current = $_REQUEST['gid']; - $abook_id = 0; - $wmode = 0; - case 'groups': - $every = 'connections'; - $each = argv(0); - $edit = false; - $current = intval(argv(1)); - $abook_id = 0; - $wmode = 1; - break; - case 'abook': - $every = 'connections'; - $each = 'group'; - $edit = false; - $current = 0; - $abook_id = App::$poi['abook_xchan']; - $wmode = 1; - break; - default: - return ''; - break; - } - - return group_side($every, $each, $edit, $current, $abook_id, $wmode); -} - -function widget_suggestions($arr) { - - if((! local_channel()) || (! feature_enabled(local_channel(),'suggest'))) - return ''; - - require_once('include/socgraph.php'); - - $r = suggestion_query(local_channel(),get_observer_hash(),0,20); - - if(! $r) { - return; - } - - $arr = array(); - - // Get two random entries from the top 20 returned. - // We'll grab the first one and the one immediately following. - // This will throw some entropy intot he situation so you won't - // be looking at the same two mug shots every time the widget runs - - $index = ((count($r) > 2) ? mt_rand(0,count($r) - 2) : 0); - for($x = $index; $x <= ($index+1); $x ++) { - $rr = $r[$x]; - if(! $rr['xchan_url']) - break; - - $connlnk = z_root() . '/follow/?url=' . $rr['xchan_addr']; - - $arr[] = array( - 'url' => chanlink_url($rr['xchan_url']), - 'profile' => $rr['xchan_url'], - 'name' => $rr['xchan_name'], - 'photo' => $rr['xchan_photo_m'], - 'ignlnk' => z_root() . '/directory?ignore=' . $rr['xchan_hash'], - 'conntxt' => t('Connect'), - 'connlnk' => $connlnk, - 'ignore' => t('Ignore/Hide') - ); - } - - $o = replace_macros(get_markup_template('suggest_widget.tpl'),array( - '$title' => t('Suggestions'), - '$more' => t('See more...'), - '$entries' => $arr - )); - - return $o; -} function widget_follow($args) { -- cgit v1.2.3 From 664c762b35d894b6c055eb57a72f01dae97b48c3 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Wed, 15 Mar 2017 18:48:27 -0700 Subject: more widgets --- include/widgets.php | 154 +--------------------------------------------------- 1 file changed, 1 insertion(+), 153 deletions(-) (limited to 'include') diff --git a/include/widgets.php b/include/widgets.php index 86d3989ef..f0a207dcb 100644 --- a/include/widgets.php +++ b/include/widgets.php @@ -2,7 +2,7 @@ /** * @file include/widgets.php * - * @brief This file contains the widgets. + * @brief This file contains some widgets. */ require_once('include/dir_fns.php'); @@ -10,158 +10,6 @@ require_once('include/contact_widgets.php'); require_once('include/attach.php'); - - - - -function widget_follow($args) { - if(! local_channel()) - return ''; - - $uid = App::$channel['channel_id']; - $r = q("select count(*) as total from abook where abook_channel = %d and abook_self = 0 ", - intval($uid) - ); - if($r) - $total_channels = $r[0]['total']; - $limit = service_class_fetch($uid,'total_channels'); - if($limit !== false) { - $abook_usage_message = sprintf( t("You have %1$.0f of %2$.0f allowed connections."), $total_channels, $limit); - } - else { - $abook_usage_message = ''; - } - return replace_macros(get_markup_template('follow.tpl'),array( - '$connect' => t('Add New Connection'), - '$desc' => t('Enter channel address'), - '$hint' => t('Examples: bob@example.com, https://example.com/barbara'), - '$follow' => t('Connect'), - '$abook_usage_message' => $abook_usage_message - )); -} - - - - -function widget_savedsearch($arr) { - if((! local_channel()) || (! feature_enabled(local_channel(),'savedsearch'))) - return ''; - - $search = ((x($_GET,'netsearch')) ? $_GET['netsearch'] : ''); - if(! $search) - $search = ((x($_GET,'search')) ? $_GET['search'] : ''); - - if(x($_GET,'searchsave') && $search) { - $r = q("select * from term where uid = %d and ttype = %d and term = '%s' limit 1", - intval(local_channel()), - intval(TERM_SAVEDSEARCH), - dbesc($search) - ); - if(! $r) { - q("insert into term ( uid,ttype,term ) values ( %d, %d, '%s') ", - intval(local_channel()), - intval(TERM_SAVEDSEARCH), - dbesc($search) - ); - } - } - - if(x($_GET,'searchremove') && $search) { - q("delete from term where uid = %d and ttype = %d and term = '%s'", - intval(local_channel()), - intval(TERM_SAVEDSEARCH), - dbesc($search) - ); - $search = ''; - } - - $srchurl = App::$query_string; - - $srchurl = rtrim(preg_replace('/searchsave\=[^\&].*?(\&|$)/is','',$srchurl),'&'); - $hasq = ((strpos($srchurl,'?') !== false) ? true : false); - $srchurl = rtrim(preg_replace('/searchremove\=[^\&].*?(\&|$)/is','',$srchurl),'&'); - - $srchurl = rtrim(preg_replace('/search\=[^\&].*?(\&|$)/is','',$srchurl),'&'); - $srchurl = rtrim(preg_replace('/submit\=[^\&].*?(\&|$)/is','',$srchurl),'&'); - $srchurl = str_replace(array('?f=','&f='),array('',''),$srchurl); - - - $hasq = ((strpos($srchurl,'?') !== false) ? true : false); - $hasamp = ((strpos($srchurl,'&') !== false) ? true : false); - - if(($hasamp) && (! $hasq)) - $srchurl = substr($srchurl,0,strpos($srchurl,'&')) . '?f=&' . substr($srchurl,strpos($srchurl,'&')+1); - - $o = ''; - - $r = q("select tid,term from term WHERE uid = %d and ttype = %d ", - intval(local_channel()), - intval(TERM_SAVEDSEARCH) - ); - - $saved = array(); - - if(count($r)) { - foreach($r as $rr) { - $saved[] = array( - 'id' => $rr['tid'], - 'term' => $rr['term'], - 'dellink' => z_root() . '/' . $srchurl . (($hasq || $hasamp) ? '' : '?f=') . '&searchremove=1&search=' . urlencode($rr['term']), - 'srchlink' => z_root() . '/' . $srchurl . (($hasq || $hasamp) ? '' : '?f=') . '&search=' . urlencode($rr['term']), - 'displayterm' => htmlspecialchars($rr['term'], ENT_COMPAT,'UTF-8'), - 'encodedterm' => urlencode($rr['term']), - 'delete' => t('Remove term'), - 'selected' => ($search==$rr['term']), - ); - } - } - - $tpl = get_markup_template("saved_searches.tpl"); - $o = replace_macros($tpl, array( - '$title' => t('Saved Searches'), - '$add' => t('add'), - '$searchbox' => searchbox($search, 'netsearch-box', $srchurl . (($hasq) ? '' : '?f='), true), - '$saved' => $saved, - )); - - return $o; -} - -function widget_sitesearch($arr) { - - $search = ((x($_GET,'search')) ? $_GET['search'] : ''); - - $srchurl = App::$query_string; - - $srchurl = rtrim(preg_replace('/search\=[^\&].*?(\&|$)/is','',$srchurl),'&'); - $srchurl = rtrim(preg_replace('/submit\=[^\&].*?(\&|$)/is','',$srchurl),'&'); - $srchurl = str_replace(array('?f=','&f='),array('',''),$srchurl); - - - $hasq = ((strpos($srchurl,'?') !== false) ? true : false); - $hasamp = ((strpos($srchurl,'&') !== false) ? true : false); - - if(($hasamp) && (! $hasq)) - $srchurl = substr($srchurl,0,strpos($srchurl,'&')) . '?f=&' . substr($srchurl,strpos($srchurl,'&')+1); - - $o = ''; - - $saved = array(); - - $tpl = get_markup_template("sitesearch.tpl"); - $o = replace_macros($tpl, array( - '$title' => t('Search'), - '$searchbox' => searchbox($search, 'netsearch-box', $srchurl . (($hasq) ? '' : '?f='), false), - '$saved' => $saved, - )); - - return $o; -} - - - - - function widget_filer($arr) { if(! local_channel()) return ''; -- cgit v1.2.3 From 92d7c32f61e8d8a72141629e73bb3bba38546278 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Wed, 15 Mar 2017 19:30:57 -0700 Subject: more widgets --- include/widgets.php | 83 ----------------------------------------------------- 1 file changed, 83 deletions(-) (limited to 'include') diff --git a/include/widgets.php b/include/widgets.php index f0a207dcb..1cf144aa6 100644 --- a/include/widgets.php +++ b/include/widgets.php @@ -10,91 +10,8 @@ require_once('include/contact_widgets.php'); require_once('include/attach.php'); -function widget_filer($arr) { - if(! local_channel()) - return ''; - - $selected = ((x($_REQUEST,'file')) ? $_REQUEST['file'] : ''); - $terms = array(); - $r = q("select distinct term from term where uid = %d and ttype = %d order by term asc", - intval(local_channel()), - intval(TERM_FILE) - ); - if(! $r) - return; - - foreach($r as $rr) - $terms[] = array('name' => $rr['term'], 'selected' => (($selected == $rr['term']) ? 'selected' : '')); - - return replace_macros(get_markup_template('fileas_widget.tpl'),array( - '$title' => t('Saved Folders'), - '$desc' => '', - '$sel_all' => (($selected == '') ? 'selected' : ''), - '$all' => t('Everything'), - '$terms' => $terms, - '$base' => z_root() . '/' . App::$cmd - )); -} - -function widget_archive($arr) { - - $o = ''; - - if(! App::$profile_uid) { - return ''; - } - - $uid = App::$profile_uid; - - if(! feature_enabled($uid,'archives')) - return ''; - - if(! perm_is_allowed($uid,get_observer_hash(),'view_stream')) - return ''; - - $wall = ((array_key_exists('wall', $arr)) ? intval($arr['wall']) : 0); - $style = ((array_key_exists('style', $arr)) ? $arr['style'] : 'select'); - $showend = ((get_pconfig($uid,'system','archive_show_end_date')) ? true : false); - $mindate = get_pconfig($uid,'system','archive_mindate'); - $visible_years = get_pconfig($uid,'system','archive_visible_years'); - if(! $visible_years) - $visible_years = 5; - - $url = z_root() . '/' . App::$cmd; - - $ret = list_post_dates($uid,$wall,$mindate); - - if(! count($ret)) - return ''; - - $cutoff_year = intval(datetime_convert('',date_default_timezone_get(),'now','Y')) - $visible_years; - $cutoff = ((array_key_exists($cutoff_year,$ret))? true : false); - - $o = replace_macros(get_markup_template('posted_date_widget.tpl'),array( - '$title' => t('Archives'), - '$size' => $visible_years, - '$cutoff_year' => $cutoff_year, - '$cutoff' => $cutoff, - '$url' => $url, - '$style' => $style, - '$showend' => $showend, - '$dates' => $ret - )); - return $o; -} - - -function widget_fullprofile($arr) { - - if(! App::$profile['profile_uid']) - return; - - $block = observer_prohibited(); - - return profile_sidebar(App::$profile, $block); -} function widget_shortprofile($arr) { -- cgit v1.2.3 From dfd626548fc903a4ecffe3241570957a2df9a37a Mon Sep 17 00:00:00 2001 From: zotlabs Date: Wed, 15 Mar 2017 20:11:28 -0700 Subject: more widget migrations --- include/widgets.php | 73 ----------------------------------------------------- 1 file changed, 73 deletions(-) (limited to 'include') diff --git a/include/widgets.php b/include/widgets.php index 1cf144aa6..db3e195d5 100644 --- a/include/widgets.php +++ b/include/widgets.php @@ -13,82 +13,9 @@ require_once('include/attach.php'); -function widget_shortprofile($arr) { - if(! App::$profile['profile_uid']) - return; - - $block = observer_prohibited(); - - return profile_sidebar(App::$profile, $block, true, true); -} - - -function widget_categories($arr) { - - - if(App::$profile['profile_uid'] && (! perm_is_allowed(App::$profile['profile_uid'],get_observer_hash(),'view_stream'))) - return ''; - - $cat = ((x($_REQUEST,'cat')) ? htmlspecialchars($_REQUEST['cat'],ENT_COMPAT,'UTF-8') : ''); - $srchurl = App::$query_string; - $srchurl = rtrim(preg_replace('/cat\=[^\&].*?(\&|$)/is','',$srchurl),'&'); - $srchurl = str_replace(array('?f=','&f='),array('',''),$srchurl); - - return categories_widget($srchurl, $cat); - -} - -function widget_appcategories($arr) { - - if(! local_channel()) - return ''; - - $selected = ((x($_REQUEST,'cat')) ? htmlspecialchars($_REQUEST['cat'],ENT_COMPAT,'UTF-8') : ''); - $srchurl = rtrim(preg_replace('/cat\=[^\&].*?(\&|$)/is','',$srchurl),'&'); - $srchurl = str_replace(array('?f=','&f='),array('',''),$srchurl); - $srchurl = z_root() . '/apps'; - - $terms = array(); - - $r = q("select distinct(term.term) - from term join app on term.oid = app.id - where app_channel = %d - and term.uid = app_channel - and term.otype = %d - and term.term != 'nav_featured_app' - order by term.term asc", - intval(local_channel()), - intval(TERM_OBJ_APP) - ); - if($r) { - foreach($r as $rr) - $terms[] = array('name' => $rr['term'], 'selected' => (($selected == $rr['term']) ? 'selected' : '')); - - return replace_macros(get_markup_template('categories_widget.tpl'),array( - '$title' => t('Categories'), - '$desc' => '', - '$sel_all' => (($selected == '') ? 'selected' : ''), - '$all' => t('Everything'), - '$terms' => $terms, - '$base' => $srchurl, - - )); - } - - - -} - - - -function widget_appcloud($arr) { - if(! local_channel()) - return ''; - return app_tagblock(z_root() . '/apps'); -} function widget_tagcloud_wall($arr) { -- cgit v1.2.3 From 16d750d1f6cf0d2866388269e02445630c4e3464 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Wed, 15 Mar 2017 20:56:12 -0700 Subject: widgets cont. --- include/widgets.php | 345 ---------------------------------------------------- 1 file changed, 345 deletions(-) (limited to 'include') diff --git a/include/widgets.php b/include/widgets.php index db3e195d5..6241f3a6b 100644 --- a/include/widgets.php +++ b/include/widgets.php @@ -18,347 +18,16 @@ require_once('include/attach.php'); -function widget_tagcloud_wall($arr) { - if((! App::$profile['profile_uid']) || (! App::$profile['channel_hash'])) - return ''; - if(! perm_is_allowed(App::$profile['profile_uid'], get_observer_hash(), 'view_stream')) - return ''; - - $limit = ((array_key_exists('limit', $arr)) ? intval($arr['limit']) : 50); - if(feature_enabled(App::$profile['profile_uid'], 'tagadelic')) - return wtagblock(App::$profile['profile_uid'], $limit, '', App::$profile['channel_hash'], 'wall'); - - return ''; -} - -function widget_catcloud_wall($arr) { - - - if((! App::$profile['profile_uid']) || (! App::$profile['channel_hash'])) - return ''; - if(! perm_is_allowed(App::$profile['profile_uid'], get_observer_hash(), 'view_stream')) - return ''; - - $limit = ((array_key_exists('limit',$arr)) ? intval($arr['limit']) : 50); - - return catblock(App::$profile['profile_uid'], $limit, '', App::$profile['channel_hash'], 'wall'); -} - - -function widget_affinity($arr) { - - if(! local_channel()) - return ''; - - // Get default cmin value from pconfig, but allow GET parameter to override - $cmin = intval(get_pconfig(local_channel(),'affinity','cmin')); - $cmin = (($cmin) ? $cmin : 0); - $cmin = ((x($_REQUEST,'cmin')) ? intval($_REQUEST['cmin']) : $cmin); - - // Get default cmax value from pconfig, but allow GET parameter to override - $cmax = intval(get_pconfig(local_channel(),'affinity','cmax')); - $cmax = (($cmax) ? $cmax : 99); - $cmax = ((x($_REQUEST,'cmax')) ? intval($_REQUEST['cmax']) : $cmax); - - - if(feature_enabled(local_channel(),'affinity')) { - - $labels = array( - t('Me'), - t('Family'), - t('Friends'), - t('Acquaintances'), - t('All') - ); - call_hooks('affinity_labels',$labels); - $label_str = ''; - - if($labels) { - foreach($labels as $l) { - if($label_str) { - $label_str .= ", '|'"; - $label_str .= ", '" . $l . "'"; - } - else - $label_str .= "'" . $l . "'"; - } - } - - $tpl = get_markup_template('main_slider.tpl'); - $x = replace_macros($tpl,array( - '$val' => $cmin . ',' . $cmax, - '$refresh' => t('Refresh'), - '$labels' => $label_str, - )); - $arr = array('html' => $x); - call_hooks('main_slider',$arr); - return $arr['html']; - } - - return ''; -} - - -function widget_settings_menu($arr) { - - if(! local_channel()) - return; - - - $channel = App::get_channel(); - - $abook_self_id = 0; - - // Retrieve the 'self' address book entry for use in the auto-permissions link - - $role = get_pconfig(local_channel(),'system','permissions_role'); - - $abk = q("select abook_id from abook where abook_channel = %d and abook_self = 1 limit 1", - intval(local_channel()) - ); - if($abk) - $abook_self_id = $abk[0]['abook_id']; - - $x = q("select count(*) as total from hubloc where hubloc_hash = '%s' and hubloc_deleted = 0 ", - dbesc($channel['channel_hash']) - ); - - $hublocs = (($x && $x[0]['total'] > 1) ? true : false); - - $tabs = array( - array( - 'label' => t('Account settings'), - 'url' => z_root().'/settings/account', - 'selected' => ((argv(1) === 'account') ? 'active' : ''), - ), - - array( - 'label' => t('Channel settings'), - 'url' => z_root().'/settings/channel', - 'selected' => ((argv(1) === 'channel') ? 'active' : ''), - ), - - ); - - if(get_account_techlevel() > 0 && get_features()) { - $tabs[] = array( - 'label' => t('Additional features'), - 'url' => z_root().'/settings/features', - 'selected' => ((argv(1) === 'features') ? 'active' : ''), - ); - } - - $tabs[] = array( - 'label' => t('Feature/Addon settings'), - 'url' => z_root().'/settings/featured', - 'selected' => ((argv(1) === 'featured') ? 'active' : ''), - ); - - $tabs[] = array( - 'label' => t('Display settings'), - 'url' => z_root().'/settings/display', - 'selected' => ((argv(1) === 'display') ? 'active' : ''), - ); - - if($hublocs) { - $tabs[] = array( - 'label' => t('Manage locations'), - 'url' => z_root() . '/locs', - 'selected' => ((argv(1) === 'locs') ? 'active' : ''), - ); - } - - $tabs[] = array( - 'label' => t('Export channel'), - 'url' => z_root() . '/uexport', - 'selected' => '' - ); - - $tabs[] = array( - 'label' => t('Connected apps'), - 'url' => z_root() . '/settings/oauth', - 'selected' => ((argv(1) === 'oauth') ? 'active' : ''), - ); - - if(get_account_techlevel() > 2) { - $tabs[] = array( - 'label' => t('Guest Access Tokens'), - 'url' => z_root() . '/settings/tokens', - 'selected' => ((argv(1) === 'tokens') ? 'active' : ''), - ); - } - - if(feature_enabled(local_channel(),'permcats')) { - $tabs[] = array( - 'label' => t('Permission Groups'), - 'url' => z_root() . '/settings/permcats', - 'selected' => ((argv(1) === 'permcats') ? 'active' : ''), - ); - } - if($role === false || $role === 'custom') { - $tabs[] = array( - 'label' => t('Connection Default Permissions'), - 'url' => z_root() . '/connedit/' . $abook_self_id, - 'selected' => '' - ); - } - if(feature_enabled(local_channel(),'premium_channel')) { - $tabs[] = array( - 'label' => t('Premium Channel Settings'), - 'url' => z_root() . '/connect/' . $channel['channel_address'], - 'selected' => '' - ); - } - if(feature_enabled(local_channel(),'channel_sources')) { - $tabs[] = array( - 'label' => t('Channel Sources'), - 'url' => z_root() . '/sources', - 'selected' => '' - ); - } - - $tabtpl = get_markup_template("generic_links_widget.tpl"); - return replace_macros($tabtpl, array( - '$title' => t('Settings'), - '$class' => 'settings-widget', - '$items' => $tabs, - )); -} - - -function widget_mailmenu($arr) { - if (! local_channel()) - return; - return replace_macros(get_markup_template('message_side.tpl'), array( - '$title' => t('Private Mail Menu'), - '$combined'=>array( - 'label' => t('Combined View'), - 'url' => z_root() . '/mail/combined', - 'sel' => (argv(1) == 'combined'), - ), - '$inbox'=>array( - 'label' => t('Inbox'), - 'url' => z_root() . '/mail/inbox', - 'sel' => (argv(1) == 'inbox'), - ), - '$outbox'=>array( - 'label' => t('Outbox'), - 'url' => z_root() . '/mail/outbox', - 'sel' => (argv(1) == 'outbox'), - ), - '$new'=>array( - 'label' => t('New Message'), - 'url' => z_root() . '/mail/new', - 'sel'=> (argv(1) == 'new'), - ) - )); -} -function widget_conversations($arr) { - if (! local_channel()) - return; - - if(argc() > 1) { - - switch(argv(1)) { - case 'combined': - $mailbox = 'combined'; - $header = t('Conversations'); - break; - case 'inbox': - $mailbox = 'inbox'; - $header = t('Received Messages'); - break; - case 'outbox': - $mailbox = 'outbox'; - $header = t('Sent Messages'); - break; - default: - $mailbox = 'combined'; - $header = t('Conversations'); - break; - } - - require_once('include/message.php'); - - // private_messages_list() can do other more complicated stuff, for now keep it simple - $r = private_messages_list(local_channel(), $mailbox, App::$pager['start'], App::$pager['itemspage']); - - if(! $r) { - info( t('No messages.') . EOL); - return $o; - } - - $messages = array(); - - foreach($r as $rr) { - - $messages[] = array( - 'mailbox' => $mailbox, - 'id' => $rr['id'], - 'from_name' => $rr['from']['xchan_name'], - 'from_url' => chanlink_hash($rr['from_xchan']), - 'from_photo' => $rr['from']['xchan_photo_s'], - 'to_name' => $rr['to']['xchan_name'], - 'to_url' => chanlink_hash($rr['to_xchan']), - 'to_photo' => $rr['to']['xchan_photo_s'], - 'subject' => (($rr['seen']) ? $rr['title'] : '' . $rr['title'] . ''), - 'delete' => t('Delete conversation'), - 'body' => $rr['body'], - 'date' => datetime_convert('UTC',date_default_timezone_get(),$rr['created'], 'c'), - 'seen' => $rr['seen'], - 'selected' => ((argv(2)) ? (argv(2) == $rr['id']) : ($r[0]['id'] == $rr['id'])) - ); - } - - $tpl = get_markup_template('mail_head.tpl'); - $o .= replace_macros($tpl, array( - '$header' => $header, - '$messages' => $messages - )); - - //$o .= alt_pager($a,count($r)); - - } - - return $o; -} - -function widget_eventstools($arr) { - if (! local_channel()) - return; - - return replace_macros(get_markup_template('events_tools_side.tpl'), array( - '$title' => t('Events Tools'), - '$export' => t('Export Calendar'), - '$import' => t('Import Calendar'), - '$submit' => t('Submit') - )); -} - -function widget_design_tools($arr) { - - // mod menu doesn't load a profile. For any modules which load a profile, check it. - // otherwise local_channel() is sufficient for permissions. - - if(App::$profile['profile_uid']) - if((App::$profile['profile_uid'] != local_channel()) && (! App::$is_sys)) - return ''; - - if(! local_channel()) - return ''; - - return design_tools(); -} function widget_website_portation_tools($arr) { @@ -380,20 +49,6 @@ function widget_findpeople($arr) { } -function widget_photo_albums($arr) { - - if(! App::$profile['profile_uid']) - return ''; - $channelx = channelx_by_n(App::$profile['profile_uid']); - if((! $channelx) || (! perm_is_allowed(App::$profile['profile_uid'], get_observer_hash(), 'view_storage'))) - return ''; - require_once('include/photos.php'); - $sortkey = ((array_key_exists('sortkey',$arr)) ? $arr['sortkey'] : 'album'); - $direction = ((array_key_exists('direction',$arr)) ? $arr['direction'] : 'asc'); - - return photos_album_widget($channelx, App::get_observer(),$sortkey,$direction); -} - function widget_vcard($arr) { return vcard_from_xchan('', App::get_observer()); -- cgit v1.2.3 From f6b643e84ee1ce8b4e13f959e0d58804f4aabd3b Mon Sep 17 00:00:00 2001 From: zotlabs Date: Wed, 15 Mar 2017 21:26:28 -0700 Subject: widgets cont. --- include/widgets.php | 208 ---------------------------------------------------- 1 file changed, 208 deletions(-) (limited to 'include') diff --git a/include/widgets.php b/include/widgets.php index 6241f3a6b..b669b73fa 100644 --- a/include/widgets.php +++ b/include/widgets.php @@ -12,22 +12,6 @@ require_once('include/attach.php'); - - - - - - - - - - - - - - - - function widget_website_portation_tools($arr) { @@ -50,10 +34,6 @@ function widget_findpeople($arr) { -function widget_vcard($arr) { - return vcard_from_xchan('', App::get_observer()); -} - /* * The following directory widgets are only useful on the directory page @@ -68,114 +48,10 @@ function widget_dirtags($arr) { return dir_tagblock(z_root() . '/directory', null); } -function widget_menu_preview($arr) { - if(! App::$data['menu_item']) - return; - require_once('include/menu.php'); - return menu_render(App::$data['menu_item']); -} -function widget_chatroom_list($arr) { - $r = Zotlabs\Lib\Chatroom::roomlist(App::$profile['profile_uid']); - - if($r) { - return replace_macros(get_markup_template('chatroomlist.tpl'), array( - '$header' => t('Chatrooms'), - '$baseurl' => z_root(), - '$nickname' => App::$profile['channel_address'], - '$items' => $r, - '$overview' => t('Overview') - )); - } -} - -function widget_chatroom_members() { - $o = replace_macros(get_markup_template('chatroom_members.tpl'), array( - '$header' => t('Chat Members') - )); - - return $o; -} - -function widget_wiki_list($arr) { - - $channel = channelx_by_n(App::$profile_uid); - - $wikis = Zotlabs\Lib\NativeWiki::listwikis($channel,get_observer_hash()); - - if($wikis) { - return replace_macros(get_markup_template('wikilist_widget.tpl'), array( - '$header' => t('Wiki List'), - '$channel' => $channel['channel_address'], - '$wikis' => $wikis['wikis'] - )); - } - return ''; -} - -function widget_wiki_pages($arr) { - - $channelname = ((array_key_exists('channel',$arr)) ? $arr['channel'] : ''); - $c = channelx_by_nick($channelname); - - $wikiname = ''; - if (array_key_exists('refresh', $arr)) { - $not_refresh = (($arr['refresh']=== true) ? false : true); - } else { - $not_refresh = true; - } - $pages = array(); - if (! array_key_exists('resource_id', $arr)) { - $hide = true; - } else { - $p = Zotlabs\Lib\NativeWikiPage::page_list($c['channel_id'],get_observer_hash(),$arr['resource_id']); - - if($p['pages']) { - $pages = $p['pages']; - $w = $p['wiki']; - // Wiki item record is $w['wiki'] - $wikiname = $w['urlName']; - if (!$wikiname) { - $wikiname = ''; - } - } - } - $can_create = perm_is_allowed(\App::$profile['uid'],get_observer_hash(),'write_wiki'); - - $can_delete = ((local_channel() && (local_channel() == \App::$profile['uid'])) ? true : false); - - return replace_macros(get_markup_template('wiki_page_list.tpl'), array( - '$hide' => $hide, - '$resource_id' => $arr['resource_id'], - '$not_refresh' => $not_refresh, - '$header' => t('Wiki Pages'), - '$channel' => $channelname, - '$wikiname' => $wikiname, - '$pages' => $pages, - '$canadd' => $can_create, - '$candel' => $can_delete, - '$addnew' => t('Add new page'), - '$pageName' => array('pageName', t('Page name')), - )); -} - -function widget_wiki_page_history($arr) { - - $pageUrlName = ((array_key_exists('pageUrlName', $arr)) ? $arr['pageUrlName'] : ''); - $resource_id = ((array_key_exists('resource_id', $arr)) ? $arr['resource_id'] : ''); - - $pageHistory = Zotlabs\Lib\NativeWikiPage::page_history(array('channel_id' => App::$profile_uid, 'observer_hash' => get_observer_hash(), 'resource_id' => $resource_id, 'pageUrlName' => $pageUrlName)); - return replace_macros(get_markup_template('nwiki_page_history.tpl'), array( - '$pageHistory' => $pageHistory['history'], - '$permsWrite' => $arr['permsWrite'], - '$name_lbl' => t('Name'), - '$msg_label' => t('Message','wiki_history') - )); - -} function widget_bookmarkedchats($arr) { @@ -749,28 +625,6 @@ function widget_activity($arr) { -function widget_tasklist($arr) { - - if (! local_channel()) - return; - - require_once('include/event.php'); - $o .= ''; - $o .= ''; - - $o .= '
' . '

' . t('Tasks') . '

'; - $o .= '
'; - $o .= '
'; - return $o; - -} - function widget_helpindex($arr) { @@ -814,68 +668,6 @@ function widget_helpindex($arr) { -function widget_admin($arr) { - - /* - * Side bar links - */ - - if(! is_site_admin()) { - return ''; - } - - $o = ''; - - // array( url, name, extra css classes ) - - $aside = array( - 'site' => array(z_root() . '/admin/site/', t('Site'), 'site'), - 'accounts' => array(z_root() . '/admin/accounts/', t('Accounts'), 'accounts', 'pending-update', t('Member registrations waiting for confirmation')), - 'channels' => array(z_root() . '/admin/channels/', t('Channels'), 'channels'), - 'security' => array(z_root() . '/admin/security/', t('Security'), 'security'), - 'features' => array(z_root() . '/admin/features/', t('Features'), 'features'), - 'plugins' => array(z_root() . '/admin/plugins/', t('Plugins'), 'plugins'), - 'themes' => array(z_root() . '/admin/themes/', t('Themes'), 'themes'), - 'queue' => array(z_root() . '/admin/queue', t('Inspect queue'), 'queue'), - 'profs' => array(z_root() . '/admin/profs', t('Profile Fields'), 'profs'), - 'dbsync' => array(z_root() . '/admin/dbsync/', t('DB updates'), 'dbsync') - - ); - - /* get plugins admin page */ - - $r = q("SELECT * FROM addon WHERE plugin_admin = 1"); - - $plugins = array(); - if($r) { - foreach ($r as $h){ - $plugin = $h['aname']; - $plugins[] = array(z_root() . '/admin/plugins/' . $plugin, $plugin, 'plugin'); - // temp plugins with admin - App::$plugins_admin[] = $plugin; - } - } - - $logs = array(z_root() . '/admin/logs/', t('Logs'), 'logs'); - - $arr = array('links' => $aside,'plugins' => $plugins,'logs' => $logs); - call_hooks('admin_aside',$arr); - - $o .= replace_macros(get_markup_template('admin_aside.tpl'), array( - '$admin' => $aside, - '$admtxt' => t('Admin'), - '$plugadmtxt' => t('Plugin Features'), - '$plugins' => $plugins, - '$logtxt' => t('Logs'), - '$logs' => $logs, - '$h_pending' => t('Member registrations waiting for confirmation'), - '$admurl'=> z_root() . '/admin/' - )); - - return $o; - -} - function widget_album($args) { -- cgit v1.2.3 From fb3f63bf596e77fe25c8b60c74651e39b62b1436 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Wed, 15 Mar 2017 21:49:27 -0700 Subject: input filter issue --- include/items.php | 2 ++ 1 file changed, 2 insertions(+) (limited to 'include') diff --git a/include/items.php b/include/items.php index ace8b2fb2..c929bb378 100755 --- a/include/items.php +++ b/include/items.php @@ -532,6 +532,8 @@ function get_item_elements($x,$allow_code = false) { $maxlen = get_max_import_size(); + $arr['body'] = $x['body']; + if($maxlen && mb_strlen($arr['body']) > $maxlen) { $arr['body'] = mb_substr($arr['body'],0,$maxlen,'UTF-8'); logger('get_item_elements: message length exceeds max_import_size: truncated'); -- cgit v1.2.3 From 051759580dc7aff7d5b349b3b5271f054c7d3423 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Thu, 16 Mar 2017 01:16:29 -0700 Subject: namespace error --- include/items.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'include') diff --git a/include/items.php b/include/items.php index c929bb378..c6aedc2e4 100755 --- a/include/items.php +++ b/include/items.php @@ -528,12 +528,10 @@ function get_item_elements($x,$allow_code = false) { $arr = array(); - $key = get_config('system','pubkey'); + $arr['body'] = $x['body']; $maxlen = get_max_import_size(); - $arr['body'] = $x['body']; - if($maxlen && mb_strlen($arr['body']) > $maxlen) { $arr['body'] = mb_substr($arr['body'],0,$maxlen,'UTF-8'); logger('get_item_elements: message length exceeds max_import_size: truncated'); -- cgit v1.2.3 From 446b5550a2c2b52bb31db5b99602c42b9dfdade6 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Thu, 16 Mar 2017 17:11:48 -0700 Subject: the rest of the standard widgets converted --- include/widgets.php | 763 +--------------------------------------------------- 1 file changed, 1 insertion(+), 762 deletions(-) (limited to 'include') diff --git a/include/widgets.php b/include/widgets.php index b669b73fa..f35915d72 100644 --- a/include/widgets.php +++ b/include/widgets.php @@ -2,767 +2,6 @@ /** * @file include/widgets.php * - * @brief This file contains some widgets. + * @brief This file may contain some widgets. */ -require_once('include/dir_fns.php'); -require_once('include/contact_widgets.php'); -require_once('include/attach.php'); - - - - - -function widget_website_portation_tools($arr) { - - // mod menu doesn't load a profile. For any modules which load a profile, check it. - // otherwise local_channel() is sufficient for permissions. - - if(App::$profile['profile_uid']) - if((App::$profile['profile_uid'] != local_channel()) && (! App::$is_sys)) - return ''; - - if(! local_channel()) - return ''; - - return website_portation_tools(); -} - -function widget_findpeople($arr) { - return findpeople_widget(); -} - - - - -/* - * The following directory widgets are only useful on the directory page - */ - - -function widget_dirsort($arr) { - return dir_sort_links(); -} - -function widget_dirtags($arr) { - return dir_tagblock(z_root() . '/directory', null); -} - - - - - - -function widget_bookmarkedchats($arr) { - - if(! feature_enabled(App::$profile['profile_uid'],'ajaxchat')) - return ''; - - $h = get_observer_hash(); - if(! $h) - return; - $r = q("select xchat_url, xchat_desc from xchat where xchat_xchan = '%s' order by xchat_desc", - dbesc($h) - ); - if($r) { - for($x = 0; $x < count($r); $x ++) { - $r[$x]['xchat_url'] = zid($r[$x]['xchat_url']); - } - } - return replace_macros(get_markup_template('bookmarkedchats.tpl'),array( - '$header' => t('Bookmarked Chatrooms'), - '$rooms' => $r - )); -} - -function widget_suggestedchats($arr) { - - if(! feature_enabled(App::$profile['profile_uid'],'ajaxchat')) - return ''; - - // There are reports that this tool does not ever remove chatrooms on dead sites, - // and also will happily link to private chats which you cannot enter. - // For those reasons, it will be disabled until somebody decides it's worth - // fixing and comes up with a plan for doing so. - - return ''; - - - // probably should restrict this to your friends, but then the widget will only work - // if you are logged in locally. - - $h = get_observer_hash(); - if(! $h) - return; - $r = q("select xchat_url, xchat_desc, count(xchat_xchan) as total from xchat group by xchat_url, xchat_desc order by total desc, xchat_desc limit 24"); - if($r) { - for($x = 0; $x < count($r); $x ++) { - $r[$x]['xchat_url'] = zid($r[$x]['xchat_url']); - } - } - return replace_macros(get_markup_template('bookmarkedchats.tpl'),array( - '$header' => t('Suggested Chatrooms'), - '$rooms' => $r - )); -} - -function widget_item($arr) { - - $channel_id = 0; - if(array_key_exists('channel_id',$arr) && intval($arr['channel_id'])) - $channel_id = intval($arr['channel_id']); - if(! $channel_id) - $channel_id = App::$profile_uid; - if(! $channel_id) - return ''; - - - if((! $arr['mid']) && (! $arr['title'])) - return ''; - - if(! perm_is_allowed($channel_id, get_observer_hash(), 'view_pages')) - return ''; - - require_once('include/security.php'); - $sql_extra = item_permissions_sql($channel_id); - - if($arr['title']) { - $r = q("select item.* from item left join iconfig on item.id = iconfig.iid - where item.uid = %d and iconfig.cat = 'system' and iconfig.v = '%s' - and iconfig.k = 'WEBPAGE' and item_type = %d $sql_options $revision limit 1", - intval($channel_id), - dbesc($arr['title']), - intval(ITEM_TYPE_WEBPAGE) - ); - } - else { - $r = q("select * from item where mid = '%s' and uid = %d and item_type = " . intval(ITEM_TYPE_WEBPAGE) . " $sql_extra limit 1", - dbesc($arr['mid']), - intval($channel_id) - ); - } - - if(! $r) - return ''; - - xchan_query($r); - $r = fetch_post_tags($r, true); - - $o = prepare_page($r[0]); - return $o; -} - -function widget_clock($arr) { - - $miltime = 0; - if(isset($arr['military']) && $arr['military']) - $miltime = 1; - -$o = <<< EOT -
-

- -
-EOT; -return $o; - -} - -/** - * @brief Widget to display a single photo. - * - * @param array $arr associative array with - * * \e string \b src URL of photo; URL must be an http or https URL - * * \e boolean \b zrl use zid in URL - * * \e string \b style CSS string - * - * @return string with parsed HTML - */ -function widget_photo($arr) { - - $style = $zrl = false; - - if(array_key_exists('src', $arr) && isset($arr['src'])) - $url = $arr['src']; - - if(strpos($url, 'http') !== 0) - return ''; - - if(array_key_exists('style', $arr) && isset($arr['style'])) - $style = $arr['style']; - - // ensure they can't sneak in an eval(js) function - - if(strpbrk($style, '(\'"<>') !== false) - $style = ''; - - if(array_key_exists('zrl', $arr) && isset($arr['zrl'])) - $zrl = (($arr['zrl']) ? true : false); - - if($zrl) - $url = zid($url); - - $o = '
'; - - $o .= '' . t('photo/image') . ''; - - $o .= '
'; - - return $o; -} - - -function widget_cover_photo($arr) { - - require_once('include/channel.php'); - $o = ''; - - if(App::$module == 'channel' && $_REQUEST['mid']) - return ''; - - $channel_id = 0; - if(array_key_exists('channel_id', $arr) && intval($arr['channel_id'])) - $channel_id = intval($arr['channel_id']); - if(! $channel_id) - $channel_id = App::$profile_uid; - if(! $channel_id) - return ''; - - $channel = channelx_by_n($channel_id); - - if(array_key_exists('style', $arr) && isset($arr['style'])) - $style = $arr['style']; - else - $style = 'width:100%; height: auto;'; - - // ensure they can't sneak in an eval(js) function - - if(strpbrk($style,'(\'"<>') !== false) - $style = ''; - - if(array_key_exists('title', $arr) && isset($arr['title'])) - $title = $arr['title']; - else - $title = $channel['channel_name']; - - if(array_key_exists('subtitle', $arr) && isset($arr['subtitle'])) - $subtitle = $arr['subtitle']; - else - $subtitle = str_replace('@','@',$channel['xchan_addr']); - - $c = get_cover_photo($channel_id,'html'); - - if($c) { - $photo_html = (($style) ? str_replace('alt=',' style="' . $style . '" alt=',$c) : $c); - - $o = replace_macros(get_markup_template('cover_photo_widget.tpl'),array( - '$photo_html' => $photo_html, - '$title' => $title, - '$subtitle' => $subtitle, - '$hovertitle' => t('Click to show more'), - )); - } - return $o; -} - - -function widget_photo_rand($arr) { - - require_once('include/photos.php'); - $style = false; - - if(array_key_exists('album', $arr) && isset($arr['album'])) - $album = $arr['album']; - else - $album = ''; - - $channel_id = 0; - if(array_key_exists('channel_id', $arr) && intval($arr['channel_id'])) - $channel_id = intval($arr['channel_id']); - if(! $channel_id) - $channel_id = App::$profile_uid; - if(! $channel_id) - return ''; - - $scale = ((array_key_exists('scale',$arr)) ? intval($arr['scale']) : 0); - - $ret = photos_list_photos(array('channel_id' => $channel_id),App::get_observer(),$album); - - $filtered = array(); - if($ret['success'] && $ret['photos']) - foreach($ret['photos'] as $p) - if($p['imgscale'] == $scale) - $filtered[] = $p['src']; - - if($filtered) { - $e = mt_rand(0, count($filtered) - 1); - $url = $filtered[$e]; - } - - if(strpos($url, 'http') !== 0) - return ''; - - if(array_key_exists('style', $arr) && isset($arr['style'])) - $style = $arr['style']; - - // ensure they can't sneak in an eval(js) function - - if(strpos($style,'(') !== false) - return ''; - - $url = zid($url); - - $o = '
'; - - $o .= '' . t('photo/image') . ''; - - $o .= '
'; - - return $o; -} - - -function widget_random_block($arr) { - - $channel_id = 0; - if(array_key_exists('channel_id',$arr) && intval($arr['channel_id'])) - $channel_id = intval($arr['channel_id']); - if(! $channel_id) - $channel_id = App::$profile_uid; - if(! $channel_id) - return ''; - - if(array_key_exists('contains',$arr)) - $contains = $arr['contains']; - - $o = ''; - - require_once('include/security.php'); - $sql_options = item_permissions_sql($channel_id); - - $randfunc = db_getfunc('RAND'); - - $r = q("select item.* from item left join iconfig on item.id = iconfig.iid - where item.uid = %d and iconfig.cat = 'system' and iconfig.v like '%s' and iconfig.k = 'BUILDBLOCK' and - item_type = %d $sql_options order by $randfunc limit 1", - intval($channel_id), - dbesc('%' . $contains . '%'), - intval(ITEM_TYPE_BLOCK) - ); - - if($r) { - $o = '
'; - if($r[0]['title']) - $o .= '

' . $r[0]['title'] . '

'; - - $o .= prepare_text($r[0]['body'],$r[0]['mimetype']); - $o .= '
'; - } - - return $o; -} - - -function widget_rating($arr) { - - - $rating_enabled = get_config('system','rating_enabled'); - if(! $rating_enabled) { - return; - } - - if($arr['target']) - $hash = $arr['target']; - else - $hash = App::$poi['xchan_hash']; - - if(! $hash) - return; - - $url = ''; - $remote = false; - - if(remote_channel() && ! local_channel()) { - $ob = App::get_observer(); - if($ob && $ob['xchan_url']) { - $p = parse_url($ob['xchan_url']); - if($p) { - $url = $p['scheme'] . '://' . $p['host'] . (($p['port']) ? ':' . $p['port'] : ''); - $url .= '/rate?f=&target=' . urlencode($hash); - } - $remote = true; - } - } - - $self = false; - - if(local_channel()) { - $channel = App::get_channel(); - - if($hash == $channel['channel_hash']) - $self = true; - - head_add_js('ratings.js'); - - } - - - $o = '
'; - $o .= '

' . t('Rating Tools') . '

'; - - if((($remote) || (local_channel())) && (! $self)) { - if($remote) - $o .= ' ' . t('Rate Me') . ''; - else - $o .= '
' . t('Rate Me') . '
'; - } - - $o .= ' ' . t('View Ratings') . ''; - $o .= '
'; - - return $o; - -} - -// used by site ratings pages to provide a return link -function widget_pubsites($arr) { - if(App::$poi) - return; - return ''; -} - - -function widget_forums($arr) { - - if(! local_channel()) - return ''; - - $o = ''; - - if(is_array($arr) && array_key_exists('limit',$arr)) - $limit = " limit " . intval($limit) . " "; - else - $limit = ''; - - $unseen = 0; - if(is_array($arr) && array_key_exists('unseen',$arr) && intval($arr['unseen'])) - $unseen = 1; - - $perms_sql = item_permissions_sql(local_channel()) . item_normal(); - - $xf = false; - - $x1 = q("select xchan from abconfig where chan = %d and cat = 'their_perms' and k = 'send_stream' and v = '0'", - intval(local_channel()) - ); - if($x1) { - $xc = ids_to_querystr($x1,'xchan',true); - $x2 = q("select xchan from abconfig where chan = %d and cat = 'their_perms' and k = 'tag_deliver' and v = '1' and xchan in (" . $xc . ") ", - intval(local_channel()) - ); - if($x2) - $xf = ids_to_querystr($x2,'xchan',true); - } - - $sql_extra = (($xf) ? " and ( xchan_hash in (" . $xf . ") or xchan_pubforum = 1 ) " : " and xchan_pubforum = 1 "); - - $r1 = q("select abook_id, xchan_hash, xchan_name, xchan_url, xchan_photo_s from abook left join xchan on abook_xchan = xchan_hash where xchan_deleted = 0 and abook_channel = %d $sql_extra order by xchan_name $limit ", - intval(local_channel()) - ); - if(! $r1) - return $o; - - $str = ''; - - // Trying to cram all this into a single query with joins and the proper group by's is tough. - // There also should be a way to update this via ajax. - - for($x = 0; $x < count($r1); $x ++) { - $r = q("select sum(item_unseen) as unseen from item where owner_xchan = '%s' and uid = %d and item_unseen = 1 $perms_sql ", - dbesc($r1[$x]['xchan_hash']), - intval(local_channel()) - ); - if($r) - $r1[$x]['unseen'] = $r[0]['unseen']; - -/** - * @FIXME - * This SQL makes the counts correct when you get forum posts arriving from different routes/sources - * (like personal channels). However the network query for these posts doesn't yet include this - * correction and it makes the SQL for that query pretty hairy so this is left as a future exercise. - * It may make more sense in that query to look for the mention in the body rather than another join, - * but that makes it very inefficient. - * - $r = q("select sum(item_unseen) as unseen from item left join term on oid = id where otype = %d and owner_xchan != '%s' and item.uid = %d and url = '%s' and ttype = %d $perms_sql ", - intval(TERM_OBJ_POST), - dbesc($r1[$x]['xchan_hash']), - intval(local_channel()), - dbesc($r1[$x]['xchan_url']), - intval(TERM_MENTION) - ); - if($r) - $r1[$x]['unseen'] = ((array_key_exists('unseen',$r1[$x])) ? $r1[$x]['unseen'] + $r[0]['unseen'] : $r[0]['unseen']); - * - * end @FIXME - */ - - } - - if($r1) { - $o .= '
'; - $o .= '

' . t('Forums') . '

'; - } - return $o; - -} - - -function widget_activity($arr) { - - if(! local_channel()) - return ''; - - $o = ''; - - if(is_array($arr) && array_key_exists('limit',$arr)) - $limit = " limit " . intval($limit) . " "; - else - $limit = ''; - - $perms_sql = item_permissions_sql(local_channel()) . item_normal(); - - $r = q("select author_xchan from item where item_unseen = 1 and uid = %d $perms_sql", - intval(local_channel()) - ); - - $contributors = []; - $arr = []; - - if($r) { - foreach($r as $rv) { - if(array_key_exists($rv['author_xchan'],$contributors)) { - $contributors[$rv['author_xchan']] ++; - } - else { - $contributors[$rv['author_xchan']] = 1; - } - } - foreach($contributors as $k => $v) { - $arr[] = [ 'author_xchan' => $k, 'total' => $v ]; - } - usort($arr,'total_sort'); - xchan_query($arr); - } - - $x = [ 'entries' => $arr ]; - call_hooks('activity_widget',$x); - $arr = $x['entries']; - - if($arr) { - $o .= '
'; - $o .= '

' . t('Activity','widget') . '

'; - } - return $o; - -} - - - - - -function widget_helpindex($arr) { - - $o .= '
'; - - $level_0 = get_help_content('sitetoc'); - if(! $level_0) - $level_0 = get_help_content('toc'); - - $level_0 = preg_replace('/\/','
'; - - return $o; - -} - - - - - -function widget_album($args) { - - $owner_uid = App::$profile_uid; - $sql_extra = permissions_sql($owner_uid); - - - if(! perm_is_allowed($owner_uid,get_observer_hash(),'view_storage')) - return ''; - - if($args['album']) - $album = $args['album']; - if($args['title']) - $title = $args['title']; - - /** - * This may return incorrect permissions if you have multiple directories of the same name. - * It is a limitation of the photo table using a name for a photo album instead of a folder hash - */ - - if($album) { - $x = q("select hash from attach where filename = '%s' and uid = %d limit 1", - dbesc($album), - intval($owner_uid) - ); - if($x) { - $y = attach_can_view_folder($owner_uid,get_observer_hash(),$x[0]['hash']); - if(! $y) - return ''; - } - } - - $order = 'DESC'; - - $r = q("SELECT p.resource_id, p.id, p.filename, p.mimetype, p.imgscale, p.description, p.created FROM photo p INNER JOIN - (SELECT resource_id, max(imgscale) imgscale FROM photo WHERE uid = %d AND album = '%s' AND imgscale <= 4 AND photo_usage IN ( %d, %d ) $sql_extra GROUP BY resource_id) ph - ON (p.resource_id = ph.resource_id AND p.imgscale = ph.imgscale) - ORDER BY created $order ", - intval($owner_uid), - dbesc($album), - intval(PHOTO_NORMAL), - intval(PHOTO_PROFILE) - ); - - //edit album name - $album_edit = null; - - $photos = array(); - if($r) { - $twist = 'rotright'; - foreach($r as $rr) { - - if($twist == 'rotright') - $twist = 'rotleft'; - else - $twist = 'rotright'; - - $ext = $phototypes[$rr['mimetype']]; - - $imgalt_e = $rr['filename']; - $desc_e = $rr['description']; - - $imagelink = (z_root() . '/photos/' . App::$profile['channel_address'] . '/image/' . $rr['resource_id']); - - - $photos[] = array( - 'id' => $rr['id'], - 'twist' => ' ' . $twist . rand(2,4), - 'link' => $imagelink, - 'title' => t('View Photo'), - 'src' => z_root() . '/photo/' . $rr['resource_id'] . '-' . $rr['imgscale'] . '.' .$ext, - 'alt' => $imgalt_e, - 'desc'=> $desc_e, - 'ext' => $ext, - 'hash'=> $rr['resource_id'], - 'unknown' => t('Unknown') - ); - } - } - - - $tpl = get_markup_template('photo_album.tpl'); - $o .= replace_macros($tpl, array( - '$photos' => $photos, - '$album' => (($title) ? $title : $album), - '$album_id' => rand(), - '$album_edit' => array(t('Edit Album'), $album_edit), - '$can_post' => false, - '$upload' => array(t('Upload'), z_root() . '/photos/' . App::$profile['channel_address'] . '/upload/' . bin2hex($album)), - '$order' => false, - '$upload_form' => $upload_form, - '$usage' => $usage_message - )); - - return $o; -} - -- cgit v1.2.3 From cf11ba1147355f0583016db2cec4f7793e656dfc Mon Sep 17 00:00:00 2001 From: zotlabs Date: Thu, 16 Mar 2017 18:19:03 -0700 Subject: simplify the message signing spaghetti --- include/items.php | 61 ++++++++++++++++++++++++++---------------------------- include/photos.php | 15 -------------- 2 files changed, 29 insertions(+), 47 deletions(-) (limited to 'include') diff --git a/include/items.php b/include/items.php index c6aedc2e4..3d0f380b4 100755 --- a/include/items.php +++ b/include/items.php @@ -1408,6 +1408,26 @@ function get_profile_elements($x) { } + + +function item_sign(&$item) { + + if(array_key_exists('sig',$item) && $item['sig']) + return; + + $r = q("select channel_prvkey from channel where channel_id = %d and channel_hash = '%s' ", + intval($item['uid']), + dbesc($item['author_xchan']) + ); + if(! $r) + return; + + $item['sig'] = base64url_encode(rsa_sign($item['body'],$r[0]['channel_prvkey'])); + $item['item_verified'] = 1; + +} + + /** * @brief * @@ -1487,24 +1507,12 @@ function item_store($arr, $allow_exec = false, $deliver = true) { $arr['lang'] = detect_language($arr['body']); + // apply the input filter here - if(array_key_exists('input_filtered_signed',$arr)) { - unset($arr['input_filtered_signed']); - } - else { - $arr['body'] = trim(z_input_filter($arr['body'],$arr['mimetype'],$allow_exec)); - - if(local_channel() && (local_channel() == $arr['uid'])) { - if(! $arr['sig']) { - $channel = App::get_channel(); - if($channel['channel_hash'] === $arr['author_xchan']) { - $arr['sig'] = base64url_encode(rsa_sign($arr['body'],$channel['channel_prvkey'])); - $arr['item_verified'] = 1; - } - } - } - } + $arr['body'] = trim(z_input_filter($arr['body'],$arr['mimetype'],$allow_exec)); + + item_sign($arr); if(! array_key_exists('sig',$arr)) $arr['sig'] = ''; @@ -1917,22 +1925,11 @@ function item_store_update($arr,$allow_exec = false, $deliver = true) { $arr['lang'] = detect_language($arr['body']); - if(array_key_exists('input_filtered_signed',$arr)) { - unset($arr['input_filtered_signed']); - } - else { - $arr['body'] = trim(z_input_filter($arr['body'],$arr['mimetype'],$allow_exec)); - - if(local_channel() && (local_channel() == $arr['uid'])) { - if(! $arr['sig']) { - $channel = App::get_channel(); - if($channel['channel_hash'] === $arr['author_xchan']) { - $arr['sig'] = base64url_encode(rsa_sign($arr['body'],$channel['channel_prvkey'])); - $arr['item_verified'] = 1; - } - } - } - } + // apply the input filter here + + $arr['body'] = trim(z_input_filter($arr['body'],$arr['mimetype'],$allow_exec)); + + item_sign($arr); $allowed_languages = get_pconfig($arr['uid'],'system','allowed_languages'); diff --git a/include/photos.php b/include/photos.php index c0f0ec8a9..b4d297bfd 100644 --- a/include/photos.php +++ b/include/photos.php @@ -340,21 +340,6 @@ function photo_upload($channel, $observer, $args) { $item['tgt_type'] = ACTIVITY_OBJ_ALBUM; $item['target'] = json_encode($target); - $item['body'] = trim(z_input_filter($item['body'],$item['mimetype'],false)); - - if($item['author_xchan'] === $channel['channel_hash']) { - $item['sig'] = base64url_encode(rsa_sign($item['body'],$channel['channel_prvkey'])); - $item['item_verified'] = 1; - } - else { - $item['sig'] = ''; - } - - // notify item_store or item_store_update that the input has been filtered and signed already. - // The signing procedure in those functions uses local_channel() which may not apply here. - - $item['input_filtered_signed'] = true; - $force = true; } -- cgit v1.2.3 From d9037589407162f51578856b084baaa5353a8a04 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Thu, 16 Mar 2017 18:36:58 -0700 Subject: remove include/widgets.php --- include/channel.php | 7 +------ include/widgets.php | 7 ------- 2 files changed, 1 insertion(+), 13 deletions(-) delete mode 100644 include/widgets.php (limited to 'include') diff --git a/include/channel.php b/include/channel.php index ceb5eeb7a..f88a2f8aa 100644 --- a/include/channel.php +++ b/include/channel.php @@ -1193,11 +1193,6 @@ function profile_sidebar($profile, $block = 0, $show_connect = true, $zcard = fa else $tpl = get_markup_template('profile_vcard.tpl'); - require_once('include/widgets.php'); - -// if(! feature_enabled($profile['uid'],'hide_rating')) - $z = widget_rating(array('target' => $profile['channel_hash'])); - $o .= replace_macros($tpl, array( '$zcard' => $zcard, '$profile' => $profile, @@ -1211,7 +1206,7 @@ function profile_sidebar($profile, $block = 0, $show_connect = true, $zcard = fa '$chanmenu' => $channel_menu, '$diaspora' => $diaspora, '$reddress' => $reddress, - '$rating' => $z, + '$rating' => '', '$contact_block' => $contact_block, '$editmenu' => profile_edit_menu($profile['uid']) )); diff --git a/include/widgets.php b/include/widgets.php deleted file mode 100644 index f35915d72..000000000 --- a/include/widgets.php +++ /dev/null @@ -1,7 +0,0 @@ - Date: Sat, 18 Mar 2017 16:41:43 -0700 Subject: various input filter fixes --- include/event.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'include') diff --git a/include/event.php b/include/event.php index 726eb667c..001bd7dd3 100644 --- a/include/event.php +++ b/include/event.php @@ -614,7 +614,7 @@ function parse_vobject($ical, $type) { $ev['etype'] = $type; $dtstart = $ical->DTSTART->getDateTime(); - $ev['adjust'] = (($ical->DTSTART->isFloating()) ? 1 : 0); + $ev['adjust'] = (($ical->DTSTART->isFloating()) ? 0 : 1); $ev['dtstart'] = datetime_convert((($ev['adjust']) ? 'UTC' : date_default_timezone_get()),'UTC', $dtstart->format(\DateTime::W3C)); @@ -755,7 +755,7 @@ function event_import_ical($ical, $uid) { } $dtstart = $ical->DTSTART->getDateTime(); - $ev['adjust'] = (($ical->DTSTART->isFloating()) ? 1 : 0); + $ev['adjust'] = (($ical->DTSTART->isFloating()) ? 0 : 1); // logger('dtstart: ' . var_export($dtstart,true)); @@ -858,7 +858,7 @@ function event_import_ical_task($ical, $uid) { $dtstart = $ical->DTSTART->getDateTime(); - $ev['adjust'] = (($ical->DTSTART->isFloating()) ? 1 : 0); + $ev['adjust'] = (($ical->DTSTART->isFloating()) ? 0 : 1); // logger('dtstart: ' . var_export($dtstart,true)); -- cgit v1.2.3 From a12a614e7e6c7d7b5e789d9c69396be55925c951 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Sun, 19 Mar 2017 19:43:00 -0700 Subject: attach_folder_rpaths() providing incorrect results --- include/attach.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'include') diff --git a/include/attach.php b/include/attach.php index cbcdbc399..d7c1b9da4 100644 --- a/include/attach.php +++ b/include/attach.php @@ -2243,11 +2243,12 @@ function attach_folder_select_list($channel_id) { if($r) { foreach($r as $rv) { $x = attach_folder_rpaths($r,$rv); - if($x) + if($x) { $out[$x[0]] = $x[1]; + } } } - +logger('results: ' . print_r($out,true)); return $out; } @@ -2266,7 +2267,6 @@ function attach_folder_rpaths($all_folders,$that_folder) { continue; if($selected['hash'] == $parent_hash) { $path = '/' . $selected['filename'] . $path; - $current_hash = $selected['hash']; $parent_hash = $selected['folder']; $found = true; break; -- cgit v1.2.3 From 78aeb50ce59b9d83d88b5e1bc9f82195635b0996 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Sun, 19 Mar 2017 21:39:28 -0700 Subject: add function attach_syspaths to calculate the contents of os_path and display_path; add this to the rename function. We will also need it to populate existing file/photo structures as an upgrade task. --- include/attach.php | 44 ++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 42 insertions(+), 2 deletions(-) (limited to 'include') diff --git a/include/attach.php b/include/attach.php index d7c1b9da4..93401226d 100644 --- a/include/attach.php +++ b/include/attach.php @@ -2212,10 +2212,23 @@ function attach_move($channel_id, $resource_id, $new_folder_hash) { intval($r[0]['id']) ); + + $x = attach_syspaths($channel_id,$resource_id); + + $t1 = q("update attach set os_path = '%s', display_path = '%s' where id = %d", + dbesc($x['os_path']), + dbesc($x['path']), + intval($r[0]['id']) + ); + + if($r[0]['is_photo']) { - $t = q("update photo set album = '%s', filename = '%s' where resource_id = '%s' and uid = %d", + $t = q("update photo set album = '%s', filename = '%s', os_path = '%s', display_path = '%s' + where resource_id = '%s' and uid = %d", dbesc($newdirname), dbesc($filename), + dbesc($x['os_path']), + dbesc($x['path']), dbesc($resource_id), intval($channel_id) ); @@ -2248,7 +2261,7 @@ function attach_folder_select_list($channel_id) { } } } -logger('results: ' . print_r($out,true)); + return $out; } @@ -2280,3 +2293,30 @@ function attach_folder_rpaths($all_folders,$that_folder) { return (($error) ? false : [ $current_hash , $path ]); } + + +function attach_syspaths($channel_id,$attach_hash) { + + $os_path = ''; + $path = ''; + do { + + $r = q("select folder, filename, hash from attach where hash = '%s' and uid = %d", + dbesc($attach_hash), + intval($channel_id) + ); + if(! $r) + break; + + $os_path = $r[0]['hash'] . (($os_path) ? '/' . $os_path : ''); + $path = $r[0]['filename'] . (($path) ? '/' . $path : ''); + $attach_hash = $r[0]['folder']; + } + while($attach_hash); + + return [ 'os_path' => $os_path, 'path' => $path ]; + + +} + + -- cgit v1.2.3 From da823125b92a4cb2a128e5b3e7c7298c4ee74be8 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Mon, 20 Mar 2017 15:24:47 -0700 Subject: remove redundant and non-functional/broken check for successfully cloned channel record which was left over from an earlier method of creating the table; which was deprecated a few months back. --- include/import.php | 6 ------ 1 file changed, 6 deletions(-) (limited to 'include') diff --git a/include/import.php b/include/import.php index bbe930864..d0e15c89d 100644 --- a/include/import.php +++ b/include/import.php @@ -85,12 +85,6 @@ function import_channel($channel, $account_id, $seize) { create_table_from_array('channel',$clean); } - if(! $r) { - logger('mod_import: channel clone failed. ' . print_r($channel,true)); - notice( t('Channel clone failed. Import failed.') . EOL); - return false; - } - $r = q("select * from channel where channel_account_id = %d and channel_guid = '%s' limit 1", intval($account_id), $channel['channel_guid'] // Already dbesc'd -- cgit v1.2.3 From 7a611c6d47020d227630a96de8026da4dae5f862 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Mon, 20 Mar 2017 18:14:50 -0700 Subject: create channel_store_lowlevel() and remove more diaspora stuff from core. --- include/channel.php | 93 +++++++++++++++++++++++++++++++---------------------- 1 file changed, 55 insertions(+), 38 deletions(-) (limited to 'include') diff --git a/include/channel.php b/include/channel.php index f88a2f8aa..465a1524a 100644 --- a/include/channel.php +++ b/include/channel.php @@ -242,24 +242,22 @@ function create_identity($arr) { $expire = 0; - $r = q("insert into channel ( channel_account_id, channel_primary, - channel_name, channel_address, channel_guid, channel_guid_sig, - channel_hash, channel_prvkey, channel_pubkey, channel_pageflags, channel_system, channel_expire_days, channel_timezone ) - values ( %d, %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d, %d, %d, '%s' ) ", - - intval($arr['account_id']), - intval($primary), - dbesc($name), - dbesc($nick), - dbesc($guid), - dbesc($sig), - dbesc($hash), - dbesc($key['prvkey']), - dbesc($key['pubkey']), - intval($pageflags), - intval($system), - intval($expire), - dbesc(App::$timezone) + $r = channel_store_lowlevel( + [ + channel_account_id => intval($arr['account_id']), + channel_primary => intval($primary), + channel_name => $name, + channel_address => $nick, + channel_guid => $guid, + channel_guid_sig => $sig, + channel_hash => $hash, + channel_prvkey => $key['prvkey'], + channel_pubkey => $key['pubkey'], + channel_pageflags => intval($pageflags), + channel_system => intval($system), + channel_expire_days => intval($expire), + channel_timezone => App::$timezone + ] ); $r = q("select * from channel where channel_account_id = %d @@ -1153,25 +1151,6 @@ function profile_sidebar($profile, $block = 0, $show_connect = true, $zcard = fa // @fixme move this to the diaspora plugin itself - if(plugin_is_installed('diaspora')) { - $diaspora = array( - 'podloc' => z_root(), - 'guid' => $profile['channel_guid'] . str_replace('.','',App::get_hostname()), - 'pubkey' => pemtorsa($profile['channel_pubkey']), - '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 = ''; - - $contact_block = contact_block(); $channel_menu = false; @@ -1204,7 +1183,6 @@ function profile_sidebar($profile, $block = 0, $show_connect = true, $zcard = fa '$marital' => $marital, '$homepage' => $homepage, '$chanmenu' => $channel_menu, - '$diaspora' => $diaspora, '$reddress' => $reddress, '$rating' => '', '$contact_block' => $contact_block, @@ -1989,6 +1967,45 @@ function remote_login() { } +function channel_store_lowlevel($arr) { + $store = [ + 'channel_account_id' => ((array_key_exists('channel_account_id',$arr)) ? $arr['channel_account_id'] : '0'), + 'channel_primary' => ((array_key_exists('channel_primary',$arr)) ? $arr['channel_primary'] : '0'), + 'channel_name' => ((array_key_exists('channel_name',$arr)) ? $arr['channel_name'] : ''), + 'channel_address' => ((array_key_exists('channel_address',$arr)) ? $arr['channel_address'] : ''), + 'channel_guid' => ((array_key_exists('channel_guid',$arr)) ? $arr['channel_guid'] : ''), + 'channel_guid_sig' => ((array_key_exists('channel_guid_sig',$arr)) ? $arr['channel_guid_sig'] : ''), + 'channel_hash' => ((array_key_exists('channel_hash',$arr)) ? $arr['channel_hash'] : ''), + 'channel_timezone' => ((array_key_exists('channel_timezone',$arr)) ? $arr['channel_timezone'] : 'UTC'), + 'channel_location' => ((array_key_exists('channel_location',$arr)) ? $arr['channel_location'] : ''), + 'channel_theme' => ((array_key_exists('channel_theme',$arr)) ? $arr['channel_theme'] : ''), + 'channel_startpage' => ((array_key_exists('channel_startpage',$arr)) ? $arr['channel_startpage'] : ''), + 'channel_pubkey' => ((array_key_exists('channel_pubkey',$arr)) ? $arr['channel_pubkey'] : ''), + 'channel_prvkey' => ((array_key_exists('channel_prvkey',$arr)) ? $arr['channel_prvkey'] : ''), + 'channel_notifyflags' => ((array_key_exists('channel_notifyflags',$arr)) ? $arr['channel_notifyflags'] : '65535'), + 'channel_pageflags' => ((array_key_exists('channel_pageflags',$arr)) ? $arr['channel_pageflags'] : '0'), + 'channel_dirdate' => ((array_key_exists('channel_dirdate',$arr)) ? $arr['channel_dirdate'] : NULL_DATE), + 'channel_lastpost' => ((array_key_exists('channel_lastpost',$arr)) ? $arr['channel_lastpost'] : NULL_DATE), + 'channel_deleted' => ((array_key_exists('channel_deleted',$arr)) ? $arr['channel_deleted'] : NULL_DATE), + 'channel_max_anon_mail' => ((array_key_exists('channel_max_anon_mail',$arr)) ? $arr['channel_max_anon_mail'] : '10'), + 'channel_max_friend_req' => ((array_key_exists('channel_max_friend_req',$arr)) ? $arr['channel_max_friend_req'] : '10'), + 'channel_expire_days' => ((array_key_exists('channel_expire_days',$arr)) ? $arr['channel_expire_days'] : '0'), + 'channel_passwd_reset' => ((array_key_exists('channel_passwd_reset',$arr)) ? $arr['channel_passwd_reset'] : ''), + 'channel_default_group' => ((array_key_exists('channel_default_group',$arr)) ? $arr['channel_default_group'] : ''), + 'channel_allow_cid' => ((array_key_exists('channel_allow_cid',$arr)) ? $arr['channel_allow_cid'] : ''), + 'channel_allow_gid' => ((array_key_exists('channel_allow_gid',$arr)) ? $arr['channel_allow_gid'] : ''), + 'channel_deny_cid' => ((array_key_exists('channel_deny_cid',$arr)) ? $arr['channel_deny_cid'] : ''), + 'channel_deny_gid' => ((array_key_exists('channel_deny_gid',$arr)) ? $arr['channel_deny_gid'] : ''), + 'channel_removed' => ((array_key_exists('channel_removed',$arr)) ? $arr['channel_removed'] : '0'), + 'channel_system' => ((array_key_exists('channel_system',$arr)) ? $arr['channel_system'] : '0'), + 'channel_moved' => ((array_key_exists('channel_moved',$arr)) ? $arr['channel_moved'] : '') + + ]; + + return create_table_from_array('channel',$store); + +} + function profile_store_lowlevel($arr) { -- cgit v1.2.3 From b153c651b45842b0062c0b32a1a3816a1f06856c Mon Sep 17 00:00:00 2001 From: zotlabs Date: Mon, 20 Mar 2017 21:53:39 -0700 Subject: perform attach_upgrade() --- include/attach.php | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'include') diff --git a/include/attach.php b/include/attach.php index 93401226d..c8582f8d3 100644 --- a/include/attach.php +++ b/include/attach.php @@ -2320,3 +2320,26 @@ function attach_syspaths($channel_id,$attach_hash) { } + +function attach_upgrade() { + + $r = q("select id, uid, hash from attach where os_path = '' and display_path = '' limit 100"); + if($r) { + foreach($r as $rv) { + $x = attach_syspaths($rv['uid'],$rv['hash']); + if($x) { + $w = q("update attach set os_path = '%s', display_path = '%s' where id = %d", + dbesc($x['os_path']), + dbesc($x['path']), + intval($rv['id']) + ); + $y = q("update photo set os_path = '%s', display_path = '%s' where uid = %d and resource_id = '%s'", + dbesc($x['os_path']), + dbesc($x['path']), + intval($rv['uid']), + dbesc($rv['hash']) + ); + } + } + } +} \ No newline at end of file -- cgit v1.2.3 From bedc39342514a37d311274210f30a4abd14284fa Mon Sep 17 00:00:00 2001 From: zotlabs Date: Tue, 21 Mar 2017 20:11:48 -0700 Subject: begin the process of using the relevant attach directory/path for photo albums instead of an album basename which may not be unique. Created an 'ellipsify()' function to shorten long names and keep the beginning and end intact --- include/photos.php | 48 ++++++++++++++++++++++++++++++++++-------------- include/text.php | 11 +++++++++++ 2 files changed, 45 insertions(+), 14 deletions(-) (limited to 'include') diff --git a/include/photos.php b/include/photos.php index b4d297bfd..e68290c9d 100644 --- a/include/photos.php +++ b/include/photos.php @@ -443,7 +443,7 @@ function photo_upload($channel, $observer, $args) { * * \e array \b albums */ -function photos_albums_list($channel, $observer, $sort_key = 'album', $direction = 'asc') { +function photos_albums_list($channel, $observer, $sort_key = 'display_path', $direction = 'asc') { $channel_id = $channel['channel_id']; $observer_xchan = (($observer) ? $observer['xchan_hash'] : ''); @@ -456,16 +456,31 @@ function photos_albums_list($channel, $observer, $sort_key = 'album', $direction $sort_key = dbesc($sort_key); $direction = dbesc($direction); - //$albums = q("SELECT count( distinct resource_id ) as total, album from photo where uid = %d and photo_usage IN ( %d, %d ) $sql_extra group by album order by $sort_key $direction", - // intval($channel_id), - // intval(PHOTO_NORMAL), - // intval(PHOTO_PROFILE) - //); - - // this query provides the same results but might perform better - $albums = q("SELECT count( distinct resource_id ) as total, album from photo where uid = %d and os_storage = 1 $sql_extra group by album order by $sort_key $direction", + $r = q("select display_path, hash from attach where is_dir = 1 and uid = %d order by $sort_key $direction", intval($channel_id) ); + array_unshift($r,[ 'display_path' => '/', 'hash' => '' ]); + $str = ids_to_querystr($r,'hash',true); + + $albums = []; + + if($str) { + $x = q("select count( distinct hash ) as total, folder from attach where is_photo = 1 and uid = %d and folder in ( $str ) group by folder ", + intval($channel_id) + ); + if($x) { + foreach($r as $rv) { + foreach($x as $xv) { + if($xv['folder'] === $rv['hash']) { + if($xv['total'] != 0) { + $albums[] = [ 'album' => $rv['display_path'], 'folder' => $xv['folder'], 'total' => $xv['total'] ]; + } + continue; + } + } + } + } + } // add various encodings to the array so we can just loop through and pick them out in a template @@ -477,11 +492,12 @@ function photos_albums_list($channel, $observer, $sort_key = 'album', $direction foreach($albums as $k => $album) { $entry = array( 'text' => (($album['album']) ? $album['album'] : '/'), + 'shorttext' => (($album['album']) ? ellipsify($album['album'],28) : '/'), 'jstext' => (($album['album']) ? addslashes($album['album']) : '/'), 'total' => $album['total'], - 'url' => z_root() . '/photos/' . $channel['channel_address'] . '/album/' . bin2hex($album['album']), + 'url' => z_root() . '/photos/' . $channel['channel_address'] . '/album/' . $album['folder'], 'urlencode' => urlencode($album['album']), - 'bin2hex' => bin2hex($album['album']) + 'bin2hex' => $album['folder'] ); $ret['albums'][] = $entry; } @@ -492,7 +508,7 @@ function photos_albums_list($channel, $observer, $sort_key = 'album', $direction return $ret; } -function photos_album_widget($channelx,$observer,$sortkey = 'album',$direction = 'asc') { +function photos_album_widget($channelx,$observer,$sortkey = 'display_path',$direction = 'asc') { $o = ''; @@ -505,6 +521,7 @@ function photos_album_widget($channelx,$observer,$sortkey = 'album',$direction = $o = replace_macros(get_markup_template('photo_albums.tpl'),array( '$nick' => $channelx['channel_address'], '$title' => t('Photo Albums'), + '$recent' => t('Recent Photos'), '$albums' => $albums['albums'], '$baseurl' => z_root(), '$upload' => ((perm_is_allowed($channelx['channel_id'],(($observer) ? $observer['xchan_hash'] : ''),'write_storage')) @@ -565,12 +582,15 @@ function photos_list_photos($channel, $observer, $album = '') { */ function photos_album_exists($channel_id, $album) { - $r = q("SELECT id FROM photo WHERE album = '%s' AND uid = %d limit 1", + + $sql_extra = permissions_sql($channel_id); + + $r = q("SELECT folder, hash, is_dir, filename, os_path, display_path FROM attach WHERE hash = '%s' AND is_dir = 1 AND uid = %d $sql_extra limit 1", dbesc($album), intval($channel_id) ); - return (($r) ? true : false); + return (($r) ? $r[0] : false); } /** diff --git a/include/text.php b/include/text.php index 500c87ad5..49b588f13 100644 --- a/include/text.php +++ b/include/text.php @@ -3113,3 +3113,14 @@ function array_escape_tags(&$v,$k) { $v = escape_tags($v); } +function ellipsify($s,$maxlen) { + if($maxlen & 1) + $maxlen --; + if($maxlen < 4) + $maxlen = 4; + + if(mb_strlen($s) < $maxlen) + return $s; + + return mb_substr($s,0,$maxlen / 2) . '...' . mb_substr($s,mb_strlen($s) - ($maxlen / 2)); +} \ No newline at end of file -- cgit v1.2.3 From 83a78a949d67dbbe3294f7f02ffeb45b6f96423d Mon Sep 17 00:00:00 2001 From: zotlabs Date: Tue, 21 Mar 2017 21:13:14 -0700 Subject: photos_album_exists() requires an observer to work correctly; provide it. --- include/photos.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'include') diff --git a/include/photos.php b/include/photos.php index e68290c9d..69b31de9f 100644 --- a/include/photos.php +++ b/include/photos.php @@ -581,9 +581,9 @@ function photos_list_photos($channel, $observer, $album = '') { * @return boolean */ -function photos_album_exists($channel_id, $album) { +function photos_album_exists($channel_id, $observer_hash, $album) { - $sql_extra = permissions_sql($channel_id); + $sql_extra = permissions_sql($channel_id,$observer_hash); $r = q("SELECT folder, hash, is_dir, filename, os_path, display_path FROM attach WHERE hash = '%s' AND is_dir = 1 AND uid = %d $sql_extra limit 1", dbesc($album), -- cgit v1.2.3 From 65ecc5ae15757b41bda8e0aed23a17d5e258cdc7 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Tue, 21 Mar 2017 22:05:36 -0700 Subject: more work on the photo album mess --- include/photos.php | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'include') diff --git a/include/photos.php b/include/photos.php index 69b31de9f..3ce307067 100644 --- a/include/photos.php +++ b/include/photos.php @@ -625,14 +625,15 @@ function photos_album_rename($channel_id, $oldname, $newname) { function photos_album_get_db_idstr($channel_id, $album, $remote_xchan = '') { - if ($remote_xchan) { - $r = q("SELECT distinct resource_id from photo where xchan = '%s' and uid = %d and album = '%s' ", + if($remote_xchan) { + $r = q("SELECT hash from attach where creator = '%s' and uid = %d and folder = '%s' ", dbesc($remote_xchan), intval($channel_id), dbesc($album) ); - } else { - $r = q("SELECT distinct resource_id from photo where uid = %d and album = '%s' ", + } + else { + $r = q("SELECT hash from attach where uid = %d and folder = '%s' ", intval($channel_id), dbesc($album) ); @@ -640,7 +641,7 @@ function photos_album_get_db_idstr($channel_id, $album, $remote_xchan = '') { if ($r) { $arr = array(); foreach ($r as $rr) { - $arr[] = "'" . dbesc($rr['resource_id']) . "'" ; + $arr[] = "'" . dbesc($rr['hash']) . "'" ; } $str = implode(',',$arr); return $str; -- cgit v1.2.3 From 0fb024190192c92e542bceb486e8875ddabfdeb6 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Wed, 22 Mar 2017 16:11:38 -0700 Subject: some more photo issues --- include/attach.php | 12 +++++++----- include/photos.php | 7 ++++--- 2 files changed, 11 insertions(+), 8 deletions(-) (limited to 'include') diff --git a/include/attach.php b/include/attach.php index c8582f8d3..675dd0da2 100644 --- a/include/attach.php +++ b/include/attach.php @@ -209,7 +209,7 @@ function attach_list_files($channel_id, $observer, $hash = '', $filename = '', $ // Retrieve all columns except 'data' - $r = q("select id, aid, uid, hash, filename, filetype, filesize, revision, folder, os_storage, is_dir, is_photo, flags, created, edited, allow_cid, allow_gid, deny_cid, deny_gid from attach where uid = %d $sql_extra ORDER BY $orderby $limit", + $r = q("select id, aid, uid, hash, filename, filetype, filesize, revision, folder, os_path, display_path, os_storage, is_dir, is_photo, flags, created, edited, allow_cid, allow_gid, deny_cid, deny_gid from attach where uid = %d $sql_extra ORDER BY $orderby $limit", intval($channel_id) ); @@ -284,6 +284,7 @@ function attach_by_hash($hash, $observer_hash, $rev = 0) { return $ret; } + function attach_can_view_folder($uid,$ob_hash,$folder_hash) { $sql_extra = permissions_sql($uid,$ob_hash); @@ -348,7 +349,7 @@ function attach_by_hash_nodata($hash, $observer_hash, $rev = 0) { // Now we'll see if we can access the attachment - $r = q("select id, aid, uid, hash, creator, filename, filetype, filesize, revision, folder, os_storage, is_photo, is_dir, flags, created, edited, allow_cid, allow_gid, deny_cid, deny_gid from attach where uid = %d and hash = '%s' $sql_extra limit 1", + $r = q("select id, aid, uid, hash, creator, filename, filetype, filesize, revision, folder, os_storage, is_photo, os_path, display_path, is_dir, flags, created, edited, allow_cid, allow_gid, deny_cid, deny_gid from attach where uid = %d and hash = '%s' $sql_extra limit 1", intval($r[0]['uid']), dbesc($hash) ); @@ -531,7 +532,7 @@ function attach_store($channel, $observer_hash, $options = '', $arr = null) { if($options === 'update' && $arr && array_key_exists('revision',$arr)) $sql_options = " and revision = " . intval($arr['revision']) . " "; - $x = q("select id, aid, uid, filename, filetype, filesize, hash, revision, folder, os_storage, is_photo, flags, created, edited, allow_cid, allow_gid, deny_cid, deny_gid from attach where hash = '%s' and uid = %d $sql_options limit 1", + $x = q("select id, aid, uid, filename, filetype, filesize, hash, revision, folder, os_storage, is_photo, os_path, display_path, flags, created, edited, allow_cid, allow_gid, deny_cid, deny_gid from attach where hash = '%s' and uid = %d $sql_options limit 1", dbesc($arr['hash']), intval($channel_id) ); @@ -929,7 +930,7 @@ function z_readdir($channel_id, $observer_hash, $pathname, $parent_hash = '') { else $paths = array($pathname); - $r = q("select id, aid, uid, hash, creator, filename, filetype, filesize, revision, folder, is_photo, is_dir, os_storage, flags, created, edited, allow_cid, allow_gid, deny_cid, deny_gid from attach where id = %d and folder = '%s' and filename = '%s' and is_dir != 0 " . permissions_sql($channel_id), + $r = q("select id, aid, uid, hash, creator, filename, filetype, filesize, revision, folder, os_path, display_path, is_photo, is_dir, os_storage, flags, created, edited, allow_cid, allow_gid, deny_cid, deny_gid from attach where id = %d and folder = '%s' and filename = '%s' and is_dir != 0 " . permissions_sql($channel_id), intval($channel_id), dbesc($parent_hash), dbesc($paths[0]) @@ -2342,4 +2343,5 @@ function attach_upgrade() { } } } -} \ No newline at end of file +} + diff --git a/include/photos.php b/include/photos.php index 3ce307067..eae9689a9 100644 --- a/include/photos.php +++ b/include/photos.php @@ -456,23 +456,24 @@ function photos_albums_list($channel, $observer, $sort_key = 'display_path', $di $sort_key = dbesc($sort_key); $direction = dbesc($direction); - $r = q("select display_path, hash from attach where is_dir = 1 and uid = %d order by $sort_key $direction", + $r = q("select display_path, hash from attach where is_dir = 1 and uid = %d $sql_extra order by $sort_key $direction", intval($channel_id) ); + array_unshift($r,[ 'display_path' => '/', 'hash' => '' ]); $str = ids_to_querystr($r,'hash',true); $albums = []; if($str) { - $x = q("select count( distinct hash ) as total, folder from attach where is_photo = 1 and uid = %d and folder in ( $str ) group by folder ", + $x = q("select count( distinct hash ) as total, folder from attach where is_photo = 1 and uid = %d and folder in ( $str ) $sql_extra group by folder ", intval($channel_id) ); if($x) { foreach($r as $rv) { foreach($x as $xv) { if($xv['folder'] === $rv['hash']) { - if($xv['total'] != 0) { + if($xv['total'] != 0 && attach_can_view_folder($channel_id,$observer_xchan,$xv['folder'])) { $albums[] = [ 'album' => $rv['display_path'], 'folder' => $xv['folder'], 'total' => $xv['total'] ]; } continue; -- cgit v1.2.3 From 0499deea6969129bd3b642f2d4edd676e1e5d4c9 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Wed, 22 Mar 2017 19:31:43 -0700 Subject: more cloud updates - upgrade the DAV structures as well. --- include/attach.php | 46 ++++++++++++++++++++++++++++------------------ 1 file changed, 28 insertions(+), 18 deletions(-) (limited to 'include') diff --git a/include/attach.php b/include/attach.php index 675dd0da2..ac50b05b1 100644 --- a/include/attach.php +++ b/include/attach.php @@ -811,7 +811,7 @@ function attach_store($channel, $observer_hash, $options = '', $arr = null) { if($is_photo) { - $args = array( 'source' => $source, 'visible' => $visible, 'resource_id' => $hash, 'album' => basename($pathname), 'os_syspath' => $os_basepath . $os_relpath, 'os_path' => $os_path, 'display_path' => $display_path, 'filename' => $filename, 'getimagesize' => $gis, 'directory' => $direct, 'options' => $options ); + $args = array( 'source' => $source, 'visible' => $visible, 'resource_id' => $hash, 'album' => $pathname, 'os_syspath' => $os_basepath . $os_relpath, 'os_path' => $os_path, 'display_path' => $display_path, 'filename' => $filename, 'getimagesize' => $gis, 'directory' => $direct, 'options' => $options ); if($arr['contact_allow']) $args['contact_allow'] = $arr['contact_allow']; if($arr['group_allow']) @@ -915,7 +915,7 @@ function z_readdir($channel_id, $observer_hash, $pathname, $parent_hash = '') { if(count($paths) > 1) { $curpath = array_shift($paths); - $r = q("select hash, id, is_dir from attach where uid = %d and filename = '%s' and is_dir != 0 " . permissions_sql($channel_id) . " limit 1", + $r = q("select hash, id, is_dir from attach where uid = %d and filename = '%s' and is_dir != 0 " . permissions_sql($channel_id,$observer_hash) . " limit 1", intval($channel_id), dbesc($curpath) ); @@ -969,12 +969,15 @@ function attach_mkdir($channel, $observer_hash, $arr = null) { $sql_options = ''; - $basepath = 'store/' . $channel['channel_address']; + $os_basepath = 'store/' . $channel['channel_address']; - logger('attach_mkdir: basepath: ' . $basepath); + logger('attach_mkdir: basepath: ' . $os_basepath); + + if(! is_dir($os_basepath)) + os_mkdir($os_basepath,STORAGE_DEFAULT_PERMISSIONS, true); - if(! is_dir($basepath)) - os_mkdir($basepath,STORAGE_DEFAULT_PERMISSIONS, true); + + $os_basepath .= '/'; if(! perm_is_allowed($channel_id, $observer_hash, 'write_storage')) { $ret['message'] = t('Permission denied.'); @@ -1020,10 +1023,13 @@ function attach_mkdir($channel, $observer_hash, $arr = null) { $lpath = ''; $lfile = $arr['folder']; + $dpath = ''; + $sql_options = permissions_sql($channel['channel_id']); + do { - $r = q("select filename, hash, flags, is_dir, folder from attach where uid = %d and hash = '%s' and is_dir != 0 + $r = q("select filename, hash, flags, is_dir, folder, display_path from attach where uid = %d and hash = '%s' and is_dir = 1 $sql_options limit 1", intval($channel['channel_id']), dbesc($lfile) @@ -1033,22 +1039,26 @@ function attach_mkdir($channel, $observer_hash, $arr = null) { $ret['message'] = t('Path not found.'); return $ret; } + + $dpath = $r[0]['filename'] . (($dpath) ? '/' . $dpath : ''); + if($lfile) - $lpath = $r[0]['hash'] . '/' . $lpath; + $lpath = $r[0]['hash'] . (($lpath) ? '/' . $lpath : ''); + $lfile = $r[0]['folder']; + } while ( ($r[0]['folder']) && intval($r[0]['is_dir'])) ; - $path = $basepath . '/' . $lpath; + + $path = $lpath; } else - $path = $basepath . '/'; - - $path .= $arr['hash']; + $path = ''; $created = datetime_convert(); - // not yet used - $os_path = ''; - $display_path = ''; + $os_path = ltrim($path . '/' . $arr['hash'],'/'); + $display_path = ltrim($dpath . '/' . $arr['filename'],'/'); + $r = q("INSERT INTO attach ( aid, uid, hash, creator, filename, filetype, filesize, revision, folder, os_storage, is_dir, content, created, edited, os_path, display_path, allow_cid, allow_gid, deny_cid, deny_gid ) VALUES ( %d, %d, '%s', '%s', '%s', '%s', %d, %d, '%s', %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s' ) ", @@ -1063,7 +1073,7 @@ function attach_mkdir($channel, $observer_hash, $arr = null) { dbesc($arr['folder']), intval(1), intval(1), - dbescbin($path), + dbescbin($os_basepath . $os_path), dbesc($created), dbesc($created), dbesc($os_path), @@ -1075,7 +1085,7 @@ function attach_mkdir($channel, $observer_hash, $arr = null) { ); if($r) { - if(os_mkdir($path, STORAGE_DEFAULT_PERMISSIONS, true)) { + if(os_mkdir($os_basepath . $os_path, STORAGE_DEFAULT_PERMISSIONS, true)) { $ret['success'] = true; // update the parent folder's lastmodified timestamp @@ -1093,7 +1103,7 @@ function attach_mkdir($channel, $observer_hash, $arr = null) { $ret['data'] = $z[0]; } else { - logger('attach_mkdir: ' . mkdir . ' ' . $path . ' failed.'); + logger('attach_mkdir: ' . mkdir . ' ' . $os_basepath . $os_path . ' failed.'); $ret['message'] = t('mkdir failed.'); } } -- cgit v1.2.3 From a2e101997836ebd904e94aa896a1bcc2e2c70f01 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Thu, 23 Mar 2017 21:49:20 -0700 Subject: move db_upgrade to zlib --- include/conversation.php | 112 ++++------------------------------------------- 1 file changed, 9 insertions(+), 103 deletions(-) (limited to 'include') diff --git a/include/conversation.php b/include/conversation.php index a1acc456a..20ed4f216 100644 --- a/include/conversation.php +++ b/include/conversation.php @@ -2,10 +2,6 @@ require_once('include/items.php'); -// Note: the code in 'item_extract_images' and 'item_redir_and_replace_images' -// is identical to the code in mod/message.php for 'item_extract_images' and -// 'item_redir_and_replace_images' - function item_extract_images($body) { @@ -375,13 +371,14 @@ function localize_item(&$item){ * * \e array \b children * @return number */ + function count_descendants($item) { $total = count($item['children']); - if ($total > 0) { - foreach ($item['children'] as $child) { - if (! visible_activity($child)) + if($total > 0) { + foreach($item['children'] as $child) { + if(! visible_activity($child)) $total --; $total += count_descendants($child); @@ -408,8 +405,8 @@ function visible_activity($item) { if(intval($item['item_notshown'])) return false; - foreach ($hidden_activities as $act) { - if ((activity_match($item['verb'], $act)) && ($item['mid'] != $item['parent_mid'])) { + foreach($hidden_activities as $act) { + if((activity_match($item['verb'], $act)) && ($item['mid'] != $item['parent_mid'])) { return false; } } @@ -870,98 +867,6 @@ function best_link_url($item) { -function item_photo_menu($item){ - - $contact = null; - - $ssl_state = false; - - $sub_link=""; - $poke_link=""; - $contact_url=""; - $pm_url=""; - $vsrc_link = ""; - $follow_url = ""; - - $local_channel = local_channel(); - - if($local_channel) { - $ssl_state = true; - if(! count(App::$contacts)) - load_contact_links($local_channel); - $channel = App::get_channel(); - $channel_hash = (($channel) ? $channel['channel_hash'] : ''); - } - - if(($local_channel) && $local_channel == $item['uid']) { - $vsrc_link = 'javascript:viewsrc(' . $item['id'] . '); return false;'; - if($item['parent'] == $item['id'] && $channel && ($channel_hash != $item['author_xchan'])) { - $sub_link = 'javascript:dosubthread(' . $item['id'] . '); return false;'; - } - if($channel) { - $unsub_link = 'javascript:dounsubthread(' . $item['id'] . '); return false;'; - } - } - - $profile_link = chanlink_hash($item['author_xchan']); - if($item['uid'] > 0) - $pm_url = z_root() . '/mail/new/?f=&hash=' . $item['author_xchan']; - - if(App::$contacts && array_key_exists($item['author_xchan'],App::$contacts)) - $contact = App::$contacts[$item['author_xchan']]; - else - if($local_channel && $item['author']['xchan_addr']) - $follow_url = z_root() . '/follow/?f=&url=' . $item['author']['xchan_addr']; - - if($contact) { - $poke_link = z_root() . '/poke/?f=&c=' . $contact['abook_id']; - if (! intval($contact['abook_self'])) - $contact_url = z_root() . '/connedit/' . $contact['abook_id']; - $posts_link = z_root() . '/network/?cid=' . $contact['abook_id']; - - $clean_url = normalise_link($item['author-link']); - } - - $rating_enabled = get_config('system','rating_enabled'); - - $ratings_url = (($rating_enabled) ? z_root() . '/ratings/' . urlencode($item['author_xchan']) : ''); - - $post_menu = Array( - t("View Source") => $vsrc_link, - t("Follow Thread") => $sub_link, - t("Unfollow Thread") => $unsub_link, - ); - - $author_menu = array( - t("View Profile") => $profile_link, - t("Activity/Posts") => $posts_link, - t("Connect") => $follow_url, - t("Edit Connection") => $contact_url, - t("Message") => $pm_url, - t('Ratings') => $ratings_url, - t("Poke") => $poke_link - ); - - - $args = array('item' => $item, 'post_menu' => $post_menu, 'author_menu' => $author_menu); - - call_hooks('item_photo_menu', $args); - - $menu = array_merge($args['post_menu'],$args['author_menu']); - - $o = ""; - foreach($menu as $k=>$v){ - if(strpos($v,'javascript:') === 0) { - $v = substr($v,11); - $o .= "
  • $k
  • \n"; - } - elseif ($v!="") $o .= "
  • $k
  • \n"; - } - - return $o; -} - - function thread_action_menu($item,$mode = '') { $menu = []; @@ -1021,14 +926,15 @@ function thread_author_menu($item, $mode = '') { } $profile_link = chanlink_hash($item['author_xchan']); + if($item['uid'] > 0) - $pm_url = z_root() . '/mail/new/?f=&hash=' . $item['author_xchan']; + $pm_url = z_root() . '/mail/new/?f=&hash=' . urlencode($item['author_xchan']); if(App::$contacts && array_key_exists($item['author_xchan'],App::$contacts)) $contact = App::$contacts[$item['author_xchan']]; else if($local_channel && $item['author']['xchan_addr']) - $follow_url = z_root() . '/follow/?f=&url=' . $item['author']['xchan_addr']; + $follow_url = z_root() . '/follow/?f=&url=' . urlencode($item['author']['xchan_addr']); if($contact) { $poke_link = z_root() . '/poke/?f=&c=' . $contact['abook_id']; -- cgit v1.2.3 From 5c63f7dd58c5b3b88efcc47120c791f92527f720 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Sat, 25 Mar 2017 14:19:32 -0700 Subject: provide platform specific install script --- include/dba/dba_driver.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'include') diff --git a/include/dba/dba_driver.php b/include/dba/dba_driver.php index e47f97387..ad1d9d194 100755 --- a/include/dba/dba_driver.php +++ b/include/dba/dba_driver.php @@ -15,7 +15,7 @@ class DBA { static public $scheme = 'mysql'; static public $logging = false; - static public $install_script = 'install/schema_mysql.sql'; + static public $install_script = 'schema_mysql.sql'; static public $null_date = '0001-01-01 00:00:00'; static public $utc_now = 'UTC_TIMESTAMP()'; static public $tquot = "`"; @@ -46,7 +46,7 @@ class DBA { if(!($port)) $port = 5432; - self::$install_script = 'install/schema_postgres.sql'; + self::$install_script = 'schema_postgres.sql'; self::$utc_now = "now() at time zone 'UTC'"; self::$tquot = '"'; self::$scheme = 'pgsql'; @@ -163,7 +163,9 @@ abstract class dba_driver { } function get_install_script() { - return \DBA::$install_script; + if(file_exists('install/' . PLATFORM_NAME . '/' . \DBA::$install_script)) + return 'install/' . PLATFORM_NAME . '/' . \DBA::$install_script; + return 'install/' . \DBA::$install_script; } function get_table_quote() { -- cgit v1.2.3 From 94e458018bc9af7cac2221e852c90ba3bb84b45f Mon Sep 17 00:00:00 2001 From: zotlabs Date: Sat, 25 Mar 2017 14:41:43 -0700 Subject: rm widgets again --- include/widgets.php | 1778 --------------------------------------------------- 1 file changed, 1778 deletions(-) delete mode 100644 include/widgets.php (limited to 'include') diff --git a/include/widgets.php b/include/widgets.php deleted file mode 100644 index c88c03f7e..000000000 --- a/include/widgets.php +++ /dev/null @@ -1,1778 +0,0 @@ - 875)); -} - - - - -// FIXME The problem with the next widget is that we don't have a search function for webpages that we can send the links to. -// Then we should also provide an option to search webpages and conversations. - -function widget_tagcloud($args) { - - $o = ''; - //$tab = 0; - - $uid = App::$profile_uid; - $count = ((x($args,'count')) ? intval($args['count']) : 24); - $flags = 0; - $type = TERM_CATEGORY; - - // FIXME there exists no $authors variable - $r = tagadelic($uid, $count, $authors, $owner, $flags, ITEM_TYPE_WEBPAGE, $type); - - if($r) { - $o = '

    ' . t('Categories') . '

    '; - foreach($r as $rr) { - $o .= ''.$rr[0].' ' . "\r\n"; - } - $o .= '
    '; - } - return $o; -} - -function widget_collections($args) { - require_once('include/group.php'); - - $mode = ((array_key_exists('mode',$args)) ? $args['mode'] : 'conversation'); - switch($mode) { - case 'conversation': - $every = argv(0); - $each = argv(0); - $edit = true; - $current = $_REQUEST['gid']; - $abook_id = 0; - $wmode = 0; - break; - case 'connections': - $every = 'connections'; - $each = 'group'; - $edit = true; - $current = $_REQUEST['gid']; - $abook_id = 0; - $wmode = 0; - case 'groups': - $every = 'connections'; - $each = argv(0); - $edit = false; - $current = intval(argv(1)); - $abook_id = 0; - $wmode = 1; - break; - case 'abook': - $every = 'connections'; - $each = 'group'; - $edit = false; - $current = 0; - $abook_id = App::$poi['abook_xchan']; - $wmode = 1; - break; - default: - return ''; - break; - } - - return group_side($every, $each, $edit, $current, $abook_id, $wmode); -} - -function widget_suggestions($arr) { - - if((! local_channel()) || (! feature_enabled(local_channel(),'suggest'))) - return ''; - - require_once('include/socgraph.php'); - - $r = suggestion_query(local_channel(),get_observer_hash(),0,20); - - if(! $r) { - return; - } - - $arr = array(); - - // Get two random entries from the top 20 returned. - // We'll grab the first one and the one immediately following. - // This will throw some entropy intot he situation so you won't - // be looking at the same two mug shots every time the widget runs - - $index = ((count($r) > 2) ? mt_rand(0,count($r) - 2) : 0); - - for($x = $index; $x <= ($index+1); $x ++) { - $rr = $r[$x]; - if(! $rr['xchan_url']) - break; - - $connlnk = z_root() . '/follow/?url=' . $rr['xchan_addr']; - - $arr[] = array( - 'url' => chanlink_url($rr['xchan_url']), - 'profile' => $rr['xchan_url'], - 'name' => $rr['xchan_name'], - 'photo' => $rr['xchan_photo_m'], - 'ignlnk' => z_root() . '/directory?ignore=' . $rr['xchan_hash'], - 'conntxt' => t('Connect'), - 'connlnk' => $connlnk, - 'ignore' => t('Ignore/Hide') - ); - } - - $o = replace_macros(get_markup_template('suggest_widget.tpl'),array( - '$title' => t('Suggestions'), - '$more' => t('See more...'), - '$entries' => $arr - )); - - return $o; -} - - -function widget_follow($args) { - if(! local_channel()) - return ''; - - $uid = App::$channel['channel_id']; - $r = q("select count(*) as total from abook where abook_channel = %d and abook_self = 0 ", - intval($uid) - ); - if($r) - $total_channels = $r[0]['total']; - $limit = service_class_fetch($uid,'total_channels'); - if($limit !== false) { - $abook_usage_message = sprintf( t("You have %1$.0f of %2$.0f allowed connections."), $total_channels, $limit); - } - else { - $abook_usage_message = ''; - } - return replace_macros(get_markup_template('follow.tpl'),array( - '$connect' => t('Add New Connection'), - '$desc' => t('Enter channel address'), - '$hint' => t('Examples: bob@example.com, https://example.com/barbara'), - '$follow' => t('Connect'), - '$abook_usage_message' => $abook_usage_message - )); -} - - -function widget_notes($arr) { - if(! local_channel()) - return ''; - if(! feature_enabled(local_channel(),'private_notes')) - return ''; - - $text = get_pconfig(local_channel(),'notes','text'); - - $o = replace_macros(get_markup_template('notes.tpl'), array( - '$banner' => t('Notes'), - '$text' => $text, - '$save' => t('Save'), - )); - - return $o; -} - - -function widget_savedsearch($arr) { - if((! local_channel()) || (! feature_enabled(local_channel(),'savedsearch'))) - return ''; - - $search = ((x($_GET,'netsearch')) ? $_GET['netsearch'] : ''); - if(! $search) - $search = ((x($_GET,'search')) ? $_GET['search'] : ''); - - if(x($_GET,'searchsave') && $search) { - $r = q("select * from term where uid = %d and ttype = %d and term = '%s' limit 1", - intval(local_channel()), - intval(TERM_SAVEDSEARCH), - dbesc($search) - ); - if(! $r) { - q("insert into term ( uid,ttype,term ) values ( %d, %d, '%s') ", - intval(local_channel()), - intval(TERM_SAVEDSEARCH), - dbesc($search) - ); - } - } - - if(x($_GET,'searchremove') && $search) { - q("delete from term where uid = %d and ttype = %d and term = '%s'", - intval(local_channel()), - intval(TERM_SAVEDSEARCH), - dbesc($search) - ); - $search = ''; - } - - $srchurl = App::$query_string; - - $srchurl = rtrim(preg_replace('/searchsave\=[^\&].*?(\&|$)/is','',$srchurl),'&'); - $hasq = ((strpos($srchurl,'?') !== false) ? true : false); - $srchurl = rtrim(preg_replace('/searchremove\=[^\&].*?(\&|$)/is','',$srchurl),'&'); - - $srchurl = rtrim(preg_replace('/search\=[^\&].*?(\&|$)/is','',$srchurl),'&'); - $srchurl = rtrim(preg_replace('/submit\=[^\&].*?(\&|$)/is','',$srchurl),'&'); - $srchurl = str_replace(array('?f=','&f='),array('',''),$srchurl); - - - $hasq = ((strpos($srchurl,'?') !== false) ? true : false); - $hasamp = ((strpos($srchurl,'&') !== false) ? true : false); - - if(($hasamp) && (! $hasq)) - $srchurl = substr($srchurl,0,strpos($srchurl,'&')) . '?f=&' . substr($srchurl,strpos($srchurl,'&')+1); - - $o = ''; - - $r = q("select tid,term from term WHERE uid = %d and ttype = %d ", - intval(local_channel()), - intval(TERM_SAVEDSEARCH) - ); - - $saved = array(); - - if(count($r)) { - foreach($r as $rr) { - $saved[] = array( - 'id' => $rr['tid'], - 'term' => $rr['term'], - 'dellink' => z_root() . '/' . $srchurl . (($hasq || $hasamp) ? '' : '?f=') . '&searchremove=1&search=' . urlencode($rr['term']), - 'srchlink' => z_root() . '/' . $srchurl . (($hasq || $hasamp) ? '' : '?f=') . '&search=' . urlencode($rr['term']), - 'displayterm' => htmlspecialchars($rr['term'], ENT_COMPAT,'UTF-8'), - 'encodedterm' => urlencode($rr['term']), - 'delete' => t('Remove term'), - 'selected' => ($search==$rr['term']), - ); - } - } - - $tpl = get_markup_template("saved_searches.tpl"); - $o = replace_macros($tpl, array( - '$title' => t('Saved Searches'), - '$add' => t('add'), - '$searchbox' => searchbox($search, 'netsearch-box', $srchurl . (($hasq) ? '' : '?f='), true), - '$saved' => $saved, - )); - - return $o; -} - -function widget_sitesearch($arr) { - - $search = ((x($_GET,'search')) ? $_GET['search'] : ''); - - $srchurl = App::$query_string; - - $srchurl = rtrim(preg_replace('/search\=[^\&].*?(\&|$)/is','',$srchurl),'&'); - $srchurl = rtrim(preg_replace('/submit\=[^\&].*?(\&|$)/is','',$srchurl),'&'); - $srchurl = str_replace(array('?f=','&f='),array('',''),$srchurl); - - - $hasq = ((strpos($srchurl,'?') !== false) ? true : false); - $hasamp = ((strpos($srchurl,'&') !== false) ? true : false); - - if(($hasamp) && (! $hasq)) - $srchurl = substr($srchurl,0,strpos($srchurl,'&')) . '?f=&' . substr($srchurl,strpos($srchurl,'&')+1); - - $o = ''; - - $saved = array(); - - $tpl = get_markup_template("sitesearch.tpl"); - $o = replace_macros($tpl, array( - '$title' => t('Search'), - '$searchbox' => searchbox($search, 'netsearch-box', $srchurl . (($hasq) ? '' : '?f='), false), - '$saved' => $saved, - )); - - return $o; -} - - - - - -function widget_filer($arr) { - if(! local_channel()) - return ''; - - - $selected = ((x($_REQUEST,'file')) ? $_REQUEST['file'] : ''); - - $terms = array(); - $r = q("select distinct term from term where uid = %d and ttype = %d order by term asc", - intval(local_channel()), - intval(TERM_FILE) - ); - if(! $r) - return; - - foreach($r as $rr) - $terms[] = array('name' => $rr['term'], 'selected' => (($selected == $rr['term']) ? 'selected' : '')); - - return replace_macros(get_markup_template('fileas_widget.tpl'),array( - '$title' => t('Saved Folders'), - '$desc' => '', - '$sel_all' => (($selected == '') ? 'selected' : ''), - '$all' => t('Everything'), - '$terms' => $terms, - '$base' => z_root() . '/' . App::$cmd - )); -} - -function widget_archive($arr) { - - $o = ''; - - if(! App::$profile_uid) { - return ''; - } - - $uid = App::$profile_uid; - - if(! feature_enabled($uid,'archives')) - return ''; - - if(! perm_is_allowed($uid,get_observer_hash(),'view_stream')) - return ''; - - $wall = ((array_key_exists('wall', $arr)) ? intval($arr['wall']) : 0); - $style = ((array_key_exists('style', $arr)) ? $arr['style'] : 'select'); - $showend = ((get_pconfig($uid,'system','archive_show_end_date')) ? true : false); - $mindate = get_pconfig($uid,'system','archive_mindate'); - $visible_years = get_pconfig($uid,'system','archive_visible_years'); - if(! $visible_years) - $visible_years = 5; - - $url = z_root() . '/' . App::$cmd; - - $ret = list_post_dates($uid,$wall,$mindate); - - if(! count($ret)) - return ''; - - $cutoff_year = intval(datetime_convert('',date_default_timezone_get(),'now','Y')) - $visible_years; - $cutoff = ((array_key_exists($cutoff_year,$ret))? true : false); - - $o = replace_macros(get_markup_template('posted_date_widget.tpl'),array( - '$title' => t('Archives'), - '$size' => $visible_years, - '$cutoff_year' => $cutoff_year, - '$cutoff' => $cutoff, - '$url' => $url, - '$style' => $style, - '$showend' => $showend, - '$dates' => $ret - )); - return $o; -} - - -function widget_fullprofile($arr) { - - if(! App::$profile['profile_uid']) - return; - - $block = observer_prohibited(); - - return profile_sidebar(App::$profile, $block); -} - -function widget_shortprofile($arr) { - - if(! App::$profile['profile_uid']) - return; - - $block = observer_prohibited(); - - return profile_sidebar(App::$profile, $block, true, true); -} - - -function widget_categories($arr) { - - - if(App::$profile['profile_uid'] && (! perm_is_allowed(App::$profile['profile_uid'],get_observer_hash(),'view_stream'))) - return ''; - - $cat = ((x($_REQUEST,'cat')) ? htmlspecialchars($_REQUEST['cat'],ENT_COMPAT,'UTF-8') : ''); - $srchurl = App::$query_string; - $srchurl = rtrim(preg_replace('/cat\=[^\&].*?(\&|$)/is','',$srchurl),'&'); - $srchurl = str_replace(array('?f=','&f='),array('',''),$srchurl); - - return categories_widget($srchurl, $cat); - -} - -function widget_appcategories($arr) { - - if(! local_channel()) - return ''; - - $selected = ((x($_REQUEST,'cat')) ? htmlspecialchars($_REQUEST['cat'],ENT_COMPAT,'UTF-8') : ''); - - $srchurl = rtrim(preg_replace('/cat\=[^\&].*?(\&|$)/is','',$srchurl),'&'); - $srchurl = str_replace(array('?f=','&f='),array('',''),$srchurl); - - $srchurl = z_root() . '/apps'; - - $terms = array(); - - $r = q("select distinct(term.term) - from term join app on term.oid = app.id - where app_channel = %d - and term.uid = app_channel - and term.otype = %d - and term.term != 'nav_featured_app' - order by term.term asc", - intval(local_channel()), - intval(TERM_OBJ_APP) - ); - if($r) { - foreach($r as $rr) - $terms[] = array('name' => $rr['term'], 'selected' => (($selected == $rr['term']) ? 'selected' : '')); - - return replace_macros(get_markup_template('categories_widget.tpl'),array( - '$title' => t('Categories'), - '$desc' => '', - '$sel_all' => (($selected == '') ? 'selected' : ''), - '$all' => t('Everything'), - '$terms' => $terms, - '$base' => $srchurl, - - )); - } - - - -} - - - -function widget_appcloud($arr) { - if(! local_channel()) - return ''; - return app_tagblock(z_root() . '/apps'); -} - - -function widget_tagcloud_wall($arr) { - - - if((! App::$profile['profile_uid']) || (! App::$profile['channel_hash'])) - return ''; - if(! perm_is_allowed(App::$profile['profile_uid'], get_observer_hash(), 'view_stream')) - return ''; - - $limit = ((array_key_exists('limit', $arr)) ? intval($arr['limit']) : 50); - if(feature_enabled(App::$profile['profile_uid'], 'tagadelic')) - return wtagblock(App::$profile['profile_uid'], $limit, '', App::$profile['channel_hash'], 'wall'); - - return ''; -} - -function widget_catcloud_wall($arr) { - - - if((! App::$profile['profile_uid']) || (! App::$profile['channel_hash'])) - return ''; - if(! perm_is_allowed(App::$profile['profile_uid'], get_observer_hash(), 'view_stream')) - return ''; - - $limit = ((array_key_exists('limit',$arr)) ? intval($arr['limit']) : 50); - - return catblock(App::$profile['profile_uid'], $limit, '', App::$profile['channel_hash'], 'wall'); -} - - -function widget_affinity($arr) { - - if(! local_channel()) - return ''; - - // Get default cmin value from pconfig, but allow GET parameter to override - $cmin = intval(get_pconfig(local_channel(),'affinity','cmin')); - $cmin = (($cmin) ? $cmin : 0); - $cmin = ((x($_REQUEST,'cmin')) ? intval($_REQUEST['cmin']) : $cmin); - - // Get default cmax value from pconfig, but allow GET parameter to override - $cmax = intval(get_pconfig(local_channel(),'affinity','cmax')); - $cmax = (($cmax) ? $cmax : 99); - $cmax = ((x($_REQUEST,'cmax')) ? intval($_REQUEST['cmax']) : $cmax); - - - if(feature_enabled(local_channel(),'affinity')) { - - $labels = array( - t('Me'), - t('Family'), - t('Friends'), - t('Acquaintances'), - t('All') - ); - call_hooks('affinity_labels',$labels); - $label_str = ''; - - if($labels) { - foreach($labels as $l) { - if($label_str) { - $label_str .= ", '|'"; - $label_str .= ", '" . $l . "'"; - } - else - $label_str .= "'" . $l . "'"; - } - } - - $tpl = get_markup_template('main_slider.tpl'); - $x = replace_macros($tpl,array( - '$val' => $cmin . ',' . $cmax, - '$refresh' => t('Refresh'), - '$labels' => $label_str, - )); - $arr = array('html' => $x); - call_hooks('main_slider',$arr); - return $arr['html']; - } - - return ''; -} - - -function widget_settings_menu($arr) { - - if(! local_channel()) - return; - - - $channel = App::get_channel(); - - $abook_self_id = 0; - - // Retrieve the 'self' address book entry for use in the auto-permissions link - - $role = get_pconfig(local_channel(),'system','permissions_role'); - - $abk = q("select abook_id from abook where abook_channel = %d and abook_self = 1 limit 1", - intval(local_channel()) - ); - if($abk) - $abook_self_id = $abk[0]['abook_id']; - - $x = q("select count(*) as total from hubloc where hubloc_hash = '%s' and hubloc_deleted = 0 ", - dbesc($channel['channel_hash']) - ); - - $hublocs = (($x && $x[0]['total'] > 1) ? true : false); - - $tabs = array( - array( - 'label' => t('Account settings'), - 'url' => z_root().'/settings/account', - 'selected' => ((argv(1) === 'account') ? 'active' : ''), - ), - - array( - 'label' => t('Channel settings'), - 'url' => z_root().'/settings/channel', - 'selected' => ((argv(1) === 'channel') ? 'active' : ''), - ), - - ); - - if(get_account_techlevel() > 0 && get_features()) { - $tabs[] = array( - 'label' => t('Additional features'), - 'url' => z_root().'/settings/features', - 'selected' => ((argv(1) === 'features') ? 'active' : ''), - ); - } - - $tabs[] = array( - 'label' => t('Feature/Addon settings'), - 'url' => z_root().'/settings/featured', - 'selected' => ((argv(1) === 'featured') ? 'active' : ''), - ); - - $tabs[] = array( - 'label' => t('Display settings'), - 'url' => z_root().'/settings/display', - 'selected' => ((argv(1) === 'display') ? 'active' : ''), - ); - - if($hublocs) { - $tabs[] = array( - 'label' => t('Manage locations'), - 'url' => z_root() . '/locs', - 'selected' => ((argv(1) === 'locs') ? 'active' : ''), - ); - } - - $tabs[] = array( - 'label' => t('Export channel'), - 'url' => z_root() . '/uexport', - 'selected' => '' - ); - - $tabs[] = array( - 'label' => t('Connected apps'), - 'url' => z_root() . '/settings/oauth', - 'selected' => ((argv(1) === 'oauth') ? 'active' : ''), - ); - - if(get_account_techlevel() > 2) { - $tabs[] = array( - 'label' => t('Guest Access Tokens'), - 'url' => z_root() . '/settings/tokens', - 'selected' => ((argv(1) === 'tokens') ? 'active' : ''), - ); - } - - if(feature_enabled(local_channel(),'permcats')) { - $tabs[] = array( - 'label' => t('Permission Groups'), - 'url' => z_root() . '/settings/permcats', - 'selected' => ((argv(1) === 'permcats') ? 'active' : ''), - ); - } - - - if($role === false || $role === 'custom') { - $tabs[] = array( - 'label' => t('Connection Default Permissions'), - 'url' => z_root() . '/connedit/' . $abook_self_id, - 'selected' => '' - ); - } - - if(feature_enabled(local_channel(),'premium_channel')) { - $tabs[] = array( - 'label' => t('Premium Channel Settings'), - 'url' => z_root() . '/connect/' . $channel['channel_address'], - 'selected' => '' - ); - } - - if(feature_enabled(local_channel(),'channel_sources')) { - $tabs[] = array( - 'label' => t('Channel Sources'), - 'url' => z_root() . '/sources', - 'selected' => '' - ); - } - - $tabtpl = get_markup_template("generic_links_widget.tpl"); - return replace_macros($tabtpl, array( - '$title' => t('Settings'), - '$class' => 'settings-widget', - '$items' => $tabs, - )); -} - - -function widget_mailmenu($arr) { - if (! local_channel()) - return; - - - return replace_macros(get_markup_template('message_side.tpl'), array( - '$title' => t('Private Mail Menu'), - '$combined'=>array( - 'label' => t('Combined View'), - 'url' => z_root() . '/mail/combined', - 'sel' => (argv(1) == 'combined'), - ), - '$inbox'=>array( - 'label' => t('Inbox'), - 'url' => z_root() . '/mail/inbox', - 'sel' => (argv(1) == 'inbox'), - ), - '$outbox'=>array( - 'label' => t('Outbox'), - 'url' => z_root() . '/mail/outbox', - 'sel' => (argv(1) == 'outbox'), - ), - '$new'=>array( - 'label' => t('New Message'), - 'url' => z_root() . '/mail/new', - 'sel'=> (argv(1) == 'new'), - ) - )); -} - - -function widget_conversations($arr) { - if (! local_channel()) - return; - - if(argc() > 1) { - - switch(argv(1)) { - case 'combined': - $mailbox = 'combined'; - $header = t('Conversations'); - break; - case 'inbox': - $mailbox = 'inbox'; - $header = t('Received Messages'); - break; - case 'outbox': - $mailbox = 'outbox'; - $header = t('Sent Messages'); - break; - default: - $mailbox = 'combined'; - $header = t('Conversations'); - break; - } - - require_once('include/message.php'); - - // private_messages_list() can do other more complicated stuff, for now keep it simple - $r = private_messages_list(local_channel(), $mailbox, App::$pager['start'], App::$pager['itemspage']); - - if(! $r) { - info( t('No messages.') . EOL); - return $o; - } - - $messages = array(); - - foreach($r as $rr) { - - $messages[] = array( - 'mailbox' => $mailbox, - 'id' => $rr['id'], - 'from_name' => $rr['from']['xchan_name'], - 'from_url' => chanlink_hash($rr['from_xchan']), - 'from_photo' => $rr['from']['xchan_photo_s'], - 'to_name' => $rr['to']['xchan_name'], - 'to_url' => chanlink_hash($rr['to_xchan']), - 'to_photo' => $rr['to']['xchan_photo_s'], - 'subject' => (($rr['seen']) ? $rr['title'] : '' . $rr['title'] . ''), - 'delete' => t('Delete conversation'), - 'body' => $rr['body'], - 'date' => datetime_convert('UTC',date_default_timezone_get(),$rr['created'], 'c'), - 'seen' => $rr['seen'], - 'selected' => ((argv(2)) ? (argv(2) == $rr['id']) : ($r[0]['id'] == $rr['id'])) - ); - } - - $tpl = get_markup_template('mail_head.tpl'); - $o .= replace_macros($tpl, array( - '$header' => $header, - '$messages' => $messages - )); - - //$o .= alt_pager($a,count($r)); - - } - - return $o; -} - -function widget_eventstools($arr) { - if (! local_channel()) - return; - - return replace_macros(get_markup_template('events_tools_side.tpl'), array( - '$title' => t('Events Tools'), - '$export' => t('Export Calendar'), - '$import' => t('Import Calendar'), - '$submit' => t('Submit') - )); -} - -function widget_design_tools($arr) { - - // mod menu doesn't load a profile. For any modules which load a profile, check it. - // otherwise local_channel() is sufficient for permissions. - - if(App::$profile['profile_uid']) - if((App::$profile['profile_uid'] != local_channel()) && (! App::$is_sys)) - return ''; - - if(! local_channel()) - return ''; - - return design_tools(); -} - -function widget_website_portation_tools($arr) { - - // mod menu doesn't load a profile. For any modules which load a profile, check it. - // otherwise local_channel() is sufficient for permissions. - - if(App::$profile['profile_uid']) - if((App::$profile['profile_uid'] != local_channel()) && (! App::$is_sys)) - return ''; - - if(! local_channel()) - return ''; - - return website_portation_tools(); -} - -function widget_findpeople($arr) { - return findpeople_widget(); -} - - -function widget_photo_albums($arr) { - - if(! App::$profile['profile_uid']) - return ''; - $channelx = channelx_by_n(App::$profile['profile_uid']); - if((! $channelx) || (! perm_is_allowed(App::$profile['profile_uid'], get_observer_hash(), 'view_storage'))) - return ''; - require_once('include/photos.php'); - $sortkey = ((array_key_exists('sortkey',$arr)) ? $arr['sortkey'] : 'album'); - $direction = ((array_key_exists('direction',$arr)) ? $arr['direction'] : 'asc'); - - return photos_album_widget($channelx, App::get_observer(),$sortkey,$direction); -} - - -function widget_vcard($arr) { - return vcard_from_xchan('', App::get_observer()); -} - - -/* - * The following directory widgets are only useful on the directory page - */ - - -function widget_dirsort($arr) { - return dir_sort_links(); -} - -function widget_dirtags($arr) { - return dir_tagblock(z_root() . '/directory', null); -} - -function widget_menu_preview($arr) { - if(! App::$data['menu_item']) - return; - require_once('include/menu.php'); - - return menu_render(App::$data['menu_item']); -} - -function widget_chatroom_list($arr) { - - - $r = Zotlabs\Lib\Chatroom::roomlist(App::$profile['profile_uid']); - - if($r) { - return replace_macros(get_markup_template('chatroomlist.tpl'), array( - '$header' => t('Chatrooms'), - '$baseurl' => z_root(), - '$nickname' => App::$profile['channel_address'], - '$items' => $r, - '$overview' => t('Overview') - )); - } -} - -function widget_chatroom_members() { - $o = replace_macros(get_markup_template('chatroom_members.tpl'), array( - '$header' => t('Chat Members') - )); - - return $o; -} - -function widget_wiki_list($arr) { - - $channel = channelx_by_n(App::$profile_uid); - - $wikis = Zotlabs\Lib\NativeWiki::listwikis($channel,get_observer_hash()); - - if($wikis) { - return replace_macros(get_markup_template('wikilist_widget.tpl'), array( - '$header' => t('Wiki List'), - '$channel' => $channel['channel_address'], - '$wikis' => $wikis['wikis'] - )); - } - return ''; -} - -function widget_wiki_pages($arr) { - - $channelname = ((array_key_exists('channel',$arr)) ? $arr['channel'] : ''); - $c = channelx_by_nick($channelname); - - $wikiname = ''; - if (array_key_exists('refresh', $arr)) { - $not_refresh = (($arr['refresh']=== true) ? false : true); - } else { - $not_refresh = true; - } - $pages = array(); - if (! array_key_exists('resource_id', $arr)) { - $hide = true; - } else { - $p = Zotlabs\Lib\NativeWikiPage::page_list($c['channel_id'],get_observer_hash(),$arr['resource_id']); - - if($p['pages']) { - $pages = $p['pages']; - $w = $p['wiki']; - // Wiki item record is $w['wiki'] - $wikiname = $w['urlName']; - if (!$wikiname) { - $wikiname = ''; - } - } - } - $can_create = perm_is_allowed(\App::$profile['uid'],get_observer_hash(),'write_wiki'); - - $can_delete = ((local_channel() && (local_channel() == \App::$profile['uid'])) ? true : false); - - return replace_macros(get_markup_template('wiki_page_list.tpl'), array( - '$hide' => $hide, - '$resource_id' => $arr['resource_id'], - '$not_refresh' => $not_refresh, - '$header' => t('Wiki Pages'), - '$channel' => $channelname, - '$wikiname' => $wikiname, - '$pages' => $pages, - '$canadd' => $can_create, - '$candel' => $can_delete, - '$addnew' => t('Add new page'), - '$pageName' => array('pageName', t('Page name')), - )); -} - -function widget_wiki_page_history($arr) { - - $pageUrlName = ((array_key_exists('pageUrlName', $arr)) ? $arr['pageUrlName'] : ''); - $resource_id = ((array_key_exists('resource_id', $arr)) ? $arr['resource_id'] : ''); - - $pageHistory = Zotlabs\Lib\NativeWikiPage::page_history(array('channel_id' => App::$profile_uid, 'observer_hash' => get_observer_hash(), 'resource_id' => $resource_id, 'pageUrlName' => $pageUrlName)); - return replace_macros(get_markup_template('nwiki_page_history.tpl'), array( - '$pageHistory' => $pageHistory['history'], - '$permsWrite' => $arr['permsWrite'], - '$name_lbl' => t('Name'), - '$msg_label' => t('Message','wiki_history') - )); - -} - -function widget_bookmarkedchats($arr) { - - if(! feature_enabled(App::$profile['profile_uid'],'ajaxchat')) - return ''; - - $h = get_observer_hash(); - if(! $h) - return; - $r = q("select xchat_url, xchat_desc from xchat where xchat_xchan = '%s' order by xchat_desc", - dbesc($h) - ); - if($r) { - for($x = 0; $x < count($r); $x ++) { - $r[$x]['xchat_url'] = zid($r[$x]['xchat_url']); - } - } - return replace_macros(get_markup_template('bookmarkedchats.tpl'),array( - '$header' => t('Bookmarked Chatrooms'), - '$rooms' => $r - )); -} - -function widget_suggestedchats($arr) { - - if(! feature_enabled(App::$profile['profile_uid'],'ajaxchat')) - return ''; - - // There are reports that this tool does not ever remove chatrooms on dead sites, - // and also will happily link to private chats which you cannot enter. - // For those reasons, it will be disabled until somebody decides it's worth - // fixing and comes up with a plan for doing so. - - return ''; - - - // probably should restrict this to your friends, but then the widget will only work - // if you are logged in locally. - - $h = get_observer_hash(); - if(! $h) - return; - $r = q("select xchat_url, xchat_desc, count(xchat_xchan) as total from xchat group by xchat_url, xchat_desc order by total desc, xchat_desc limit 24"); - if($r) { - for($x = 0; $x < count($r); $x ++) { - $r[$x]['xchat_url'] = zid($r[$x]['xchat_url']); - } - } - return replace_macros(get_markup_template('bookmarkedchats.tpl'),array( - '$header' => t('Suggested Chatrooms'), - '$rooms' => $r - )); -} - -function widget_item($arr) { - - $channel_id = 0; - if(array_key_exists('channel_id',$arr) && intval($arr['channel_id'])) - $channel_id = intval($arr['channel_id']); - if(! $channel_id) - $channel_id = App::$profile_uid; - if(! $channel_id) - return ''; - - - if((! $arr['mid']) && (! $arr['title'])) - return ''; - - if(! perm_is_allowed($channel_id, get_observer_hash(), 'view_pages')) - return ''; - - require_once('include/security.php'); - $sql_extra = item_permissions_sql($channel_id); - - if($arr['title']) { - $r = q("select item.* from item left join iconfig on item.id = iconfig.iid - where item.uid = %d and iconfig.cat = 'system' and iconfig.v = '%s' - and iconfig.k = 'WEBPAGE' and item_type = %d $sql_options $revision limit 1", - intval($channel_id), - dbesc($arr['title']), - intval(ITEM_TYPE_WEBPAGE) - ); - } - else { - $r = q("select * from item where mid = '%s' and uid = %d and item_type = " . intval(ITEM_TYPE_WEBPAGE) . " $sql_extra limit 1", - dbesc($arr['mid']), - intval($channel_id) - ); - } - - if(! $r) - return ''; - - xchan_query($r); - $r = fetch_post_tags($r, true); - - $o = prepare_page($r[0]); - return $o; -} - -function widget_clock($arr) { - - $miltime = 0; - if(isset($arr['military']) && $arr['military']) - $miltime = 1; - -$o = <<< EOT -
    -

    - -
    -EOT; -return $o; - -} - -/** - * @brief Widget to display a single photo. - * - * @param array $arr associative array with - * * \e string \b src URL of photo; URL must be an http or https URL - * * \e boolean \b zrl use zid in URL - * * \e string \b style CSS string - * - * @return string with parsed HTML - */ -function widget_photo($arr) { - - $style = $zrl = false; - - if(array_key_exists('src', $arr) && isset($arr['src'])) - $url = $arr['src']; - - if(strpos($url, 'http') !== 0) - return ''; - - if(array_key_exists('style', $arr) && isset($arr['style'])) - $style = $arr['style']; - - // ensure they can't sneak in an eval(js) function - - if(strpbrk($style, '(\'"<>') !== false) - $style = ''; - - if(array_key_exists('zrl', $arr) && isset($arr['zrl'])) - $zrl = (($arr['zrl']) ? true : false); - - if($zrl) - $url = zid($url); - - $o = '
    '; - - $o .= '' . t('photo/image') . ''; - - $o .= '
    '; - - return $o; -} - - -function widget_cover_photo($arr) { - - require_once('include/channel.php'); - $o = ''; - - if(App::$module == 'channel' && $_REQUEST['mid']) - return ''; - - $channel_id = 0; - if(array_key_exists('channel_id', $arr) && intval($arr['channel_id'])) - $channel_id = intval($arr['channel_id']); - if(! $channel_id) - $channel_id = App::$profile_uid; - if(! $channel_id) - return ''; - - $channel = channelx_by_n($channel_id); - - if(array_key_exists('style', $arr) && isset($arr['style'])) - $style = $arr['style']; - else - $style = 'width:100%; height: auto;'; - - // ensure they can't sneak in an eval(js) function - - if(strpbrk($style,'(\'"<>') !== false) - $style = ''; - - if(array_key_exists('title', $arr) && isset($arr['title'])) - $title = $arr['title']; - else - $title = $channel['channel_name']; - - if(array_key_exists('subtitle', $arr) && isset($arr['subtitle'])) - $subtitle = $arr['subtitle']; - else - $subtitle = str_replace('@','@',$channel['xchan_addr']); - - $c = get_cover_photo($channel_id,'html'); - - if($c) { - $photo_html = (($style) ? str_replace('alt=',' style="' . $style . '" alt=',$c) : $c); - - $o = replace_macros(get_markup_template('cover_photo_widget.tpl'),array( - '$photo_html' => $photo_html, - '$title' => $title, - '$subtitle' => $subtitle, - '$hovertitle' => t('Click to show more'), - )); - } - return $o; -} - - -function widget_photo_rand($arr) { - - require_once('include/photos.php'); - $style = false; - - if(array_key_exists('album', $arr) && isset($arr['album'])) - $album = $arr['album']; - else - $album = ''; - - $channel_id = 0; - if(array_key_exists('channel_id', $arr) && intval($arr['channel_id'])) - $channel_id = intval($arr['channel_id']); - if(! $channel_id) - $channel_id = App::$profile_uid; - if(! $channel_id) - return ''; - - $scale = ((array_key_exists('scale',$arr)) ? intval($arr['scale']) : 0); - - $ret = photos_list_photos(array('channel_id' => $channel_id),App::get_observer(),$album); - - $filtered = array(); - if($ret['success'] && $ret['photos']) - foreach($ret['photos'] as $p) - if($p['imgscale'] == $scale) - $filtered[] = $p['src']; - - if($filtered) { - $e = mt_rand(0, count($filtered) - 1); - $url = $filtered[$e]; - } - - if(strpos($url, 'http') !== 0) - return ''; - - if(array_key_exists('style', $arr) && isset($arr['style'])) - $style = $arr['style']; - - // ensure they can't sneak in an eval(js) function - - if(strpos($style,'(') !== false) - return ''; - - $url = zid($url); - - $o = '
    '; - - $o .= '' . t('photo/image') . ''; - - $o .= '
    '; - - return $o; -} - - -function widget_random_block($arr) { - - $channel_id = 0; - if(array_key_exists('channel_id',$arr) && intval($arr['channel_id'])) - $channel_id = intval($arr['channel_id']); - if(! $channel_id) - $channel_id = App::$profile_uid; - if(! $channel_id) - return ''; - - if(array_key_exists('contains',$arr)) - $contains = $arr['contains']; - - $o = ''; - - require_once('include/security.php'); - $sql_options = item_permissions_sql($channel_id); - - $randfunc = db_getfunc('RAND'); - - $r = q("select item.* from item left join iconfig on item.id = iconfig.iid - where item.uid = %d and iconfig.cat = 'system' and iconfig.v like '%s' and iconfig.k = 'BUILDBLOCK' and - item_type = %d $sql_options order by $randfunc limit 1", - intval($channel_id), - dbesc('%' . $contains . '%'), - intval(ITEM_TYPE_BLOCK) - ); - - if($r) { - $o = '
    '; - if($r[0]['title']) - $o .= '

    ' . $r[0]['title'] . '

    '; - - $o .= prepare_text($r[0]['body'],$r[0]['mimetype']); - $o .= '
    '; - } - - return $o; -} - - -function widget_rating($arr) { - - - $rating_enabled = get_config('system','rating_enabled'); - if(! $rating_enabled) { - return; - } - - if($arr['target']) - $hash = $arr['target']; - else - $hash = App::$poi['xchan_hash']; - - if(! $hash) - return; - - $url = ''; - $remote = false; - - if(remote_channel() && ! local_channel()) { - $ob = App::get_observer(); - if($ob && $ob['xchan_url']) { - $p = parse_url($ob['xchan_url']); - if($p) { - $url = $p['scheme'] . '://' . $p['host'] . (($p['port']) ? ':' . $p['port'] : ''); - $url .= '/rate?f=&target=' . urlencode($hash); - } - $remote = true; - } - } - - $self = false; - - if(local_channel()) { - $channel = App::get_channel(); - - if($hash == $channel['channel_hash']) - $self = true; - - head_add_js('ratings.js'); - - } - - - $o = '
    '; - $o .= '

    ' . t('Rating Tools') . '

    '; - - if((($remote) || (local_channel())) && (! $self)) { - if($remote) - $o .= ' ' . t('Rate Me') . ''; - else - $o .= '
    ' . t('Rate Me') . '
    '; - } - - $o .= ' ' . t('View Ratings') . ''; - $o .= '
    '; - - return $o; - -} - -// used by site ratings pages to provide a return link -function widget_pubsites($arr) { - if(App::$poi) - return; - return ''; -} - - -function widget_forums($arr) { - - if(! local_channel()) - return ''; - - $o = ''; - - if(is_array($arr) && array_key_exists('limit',$arr)) - $limit = " limit " . intval($limit) . " "; - else - $limit = ''; - - $unseen = 0; - if(is_array($arr) && array_key_exists('unseen',$arr) && intval($arr['unseen'])) - $unseen = 1; - - $perms_sql = item_permissions_sql(local_channel()) . item_normal(); - - $xf = false; - - $x1 = q("select xchan from abconfig where chan = %d and cat = 'their_perms' and k = 'send_stream' and v = '0'", - intval(local_channel()) - ); - if($x1) { - $xc = ids_to_querystr($x1,'xchan',true); - $x2 = q("select xchan from abconfig where chan = %d and cat = 'their_perms' and k = 'tag_deliver' and v = '1' and xchan in (" . $xc . ") ", - intval(local_channel()) - ); - if($x2) - $xf = ids_to_querystr($x2,'xchan',true); - } - - $sql_extra = (($xf) ? " and ( xchan_hash in (" . $xf . ") or xchan_pubforum = 1 ) " : " and xchan_pubforum = 1 "); - - $r1 = q("select abook_id, xchan_hash, xchan_name, xchan_url, xchan_photo_s from abook left join xchan on abook_xchan = xchan_hash where xchan_deleted = 0 and abook_channel = %d $sql_extra order by xchan_name $limit ", - intval(local_channel()) - ); - if(! $r1) - return $o; - - $str = ''; - - // Trying to cram all this into a single query with joins and the proper group by's is tough. - // There also should be a way to update this via ajax. - - for($x = 0; $x < count($r1); $x ++) { - $r = q("select sum(item_unseen) as unseen from item where owner_xchan = '%s' and uid = %d and item_unseen = 1 $perms_sql ", - dbesc($r1[$x]['xchan_hash']), - intval(local_channel()) - ); - if($r) - $r1[$x]['unseen'] = $r[0]['unseen']; - -/** - * @FIXME - * This SQL makes the counts correct when you get forum posts arriving from different routes/sources - * (like personal channels). However the network query for these posts doesn't yet include this - * correction and it makes the SQL for that query pretty hairy so this is left as a future exercise. - * It may make more sense in that query to look for the mention in the body rather than another join, - * but that makes it very inefficient. - * - $r = q("select sum(item_unseen) as unseen from item left join term on oid = id where otype = %d and owner_xchan != '%s' and item.uid = %d and url = '%s' and ttype = %d $perms_sql ", - intval(TERM_OBJ_POST), - dbesc($r1[$x]['xchan_hash']), - intval(local_channel()), - dbesc($r1[$x]['xchan_url']), - intval(TERM_MENTION) - ); - if($r) - $r1[$x]['unseen'] = ((array_key_exists('unseen',$r1[$x])) ? $r1[$x]['unseen'] + $r[0]['unseen'] : $r[0]['unseen']); - * - * end @FIXME - */ - - } - - if($r1) { - $o .= '
    '; - $o .= '

    ' . t('Forums') . '

    '; - } - return $o; - -} - - -function widget_activity($arr) { - - if(! local_channel()) - return ''; - - $o = ''; - - if(is_array($arr) && array_key_exists('limit',$arr)) - $limit = " limit " . intval($limit) . " "; - else - $limit = ''; - - $perms_sql = item_permissions_sql(local_channel()) . item_normal(); - - $r = q("select author_xchan from item where item_unseen = 1 and uid = %d $perms_sql", - intval(local_channel()) - ); - - $contributors = []; - $arr = []; - - if($r) { - foreach($r as $rv) { - if(array_key_exists($rv['author_xchan'],$contributors)) { - $contributors[$rv['author_xchan']] ++; - } - else { - $contributors[$rv['author_xchan']] = 1; - } - } - foreach($contributors as $k => $v) { - $arr[] = [ 'author_xchan' => $k, 'total' => $v ]; - } - usort($arr,'total_sort'); - xchan_query($arr); - } - - $x = [ 'entries' => $arr ]; - call_hooks('activity_widget',$x); - $arr = $x['entries']; - - if($arr) { - $o .= '
    '; - $o .= '

    ' . t('Activity','widget') . '

    '; - } - return $o; - -} - - - - -function widget_tasklist($arr) { - - if (! local_channel()) - return; - - require_once('include/event.php'); - $o .= ''; - $o .= ''; - - $o .= '
    ' . '

    ' . t('Tasks') . '

    '; - $o .= '
    '; - $o .= '
    '; - return $o; - -} - - -function widget_helpindex($arr) { - - $o .= '
    '; - - $level_0 = get_help_content('sitetoc'); - if(! $level_0) - $level_0 = get_help_content('toc'); - - $level_0 = preg_replace('/\/','
    '; - - return $o; - -} - - - -function widget_admin($arr) { - - /* - * Side bar links - */ - - if(! is_site_admin()) { - return ''; - } - - $o = ''; - - // array( url, name, extra css classes ) - - $aside = array( - 'site' => array(z_root() . '/admin/site/', t('Site'), 'site'), - 'accounts' => array(z_root() . '/admin/accounts/', t('Accounts'), 'accounts', 'pending-update', t('Member registrations waiting for confirmation')), - 'channels' => array(z_root() . '/admin/channels/', t('Channels'), 'channels'), - 'security' => array(z_root() . '/admin/security/', t('Security'), 'security'), - 'features' => array(z_root() . '/admin/features/', t('Features'), 'features'), - 'plugins' => array(z_root() . '/admin/plugins/', t('Plugins'), 'plugins'), - 'themes' => array(z_root() . '/admin/themes/', t('Themes'), 'themes'), - 'queue' => array(z_root() . '/admin/queue', t('Inspect queue'), 'queue'), - 'profs' => array(z_root() . '/admin/profs', t('Profile Fields'), 'profs'), - 'dbsync' => array(z_root() . '/admin/dbsync/', t('DB updates'), 'dbsync') - - ); - - /* get plugins admin page */ - - $r = q("SELECT * FROM addon WHERE plugin_admin = 1"); - - $plugins = array(); - if($r) { - foreach ($r as $h){ - $plugin = $h['aname']; - $plugins[] = array(z_root() . '/admin/plugins/' . $plugin, $plugin, 'plugin'); - // temp plugins with admin - App::$plugins_admin[] = $plugin; - } - } - - $logs = array(z_root() . '/admin/logs/', t('Logs'), 'logs'); - - $arr = array('links' => $aside,'plugins' => $plugins,'logs' => $logs); - call_hooks('admin_aside',$arr); - - $o .= replace_macros(get_markup_template('admin_aside.tpl'), array( - '$admin' => $aside, - '$admtxt' => t('Admin'), - '$plugadmtxt' => t('Plugin Features'), - '$plugins' => $plugins, - '$logtxt' => t('Logs'), - '$logs' => $logs, - '$h_pending' => t('Member registrations waiting for confirmation'), - '$admurl'=> z_root() . '/admin/' - )); - - return $o; - -} - - - -function widget_album($args) { - - $owner_uid = App::$profile_uid; - $sql_extra = permissions_sql($owner_uid); - - - if(! perm_is_allowed($owner_uid,get_observer_hash(),'view_storage')) - return ''; - - if($args['album']) - $album = $args['album']; - if($args['title']) - $title = $args['title']; - - /** - * This may return incorrect permissions if you have multiple directories of the same name. - * It is a limitation of the photo table using a name for a photo album instead of a folder hash - */ - - if($album) { - $x = q("select hash from attach where filename = '%s' and uid = %d limit 1", - dbesc($album), - intval($owner_uid) - ); - if($x) { - $y = attach_can_view_folder($owner_uid,get_observer_hash(),$x[0]['hash']); - if(! $y) - return ''; - } - } - - $order = 'DESC'; - - $r = q("SELECT p.resource_id, p.id, p.filename, p.mimetype, p.imgscale, p.description, p.created FROM photo p INNER JOIN - (SELECT resource_id, max(imgscale) imgscale FROM photo WHERE uid = %d AND album = '%s' AND imgscale <= 4 AND photo_usage IN ( %d, %d ) $sql_extra GROUP BY resource_id) ph - ON (p.resource_id = ph.resource_id AND p.imgscale = ph.imgscale) - ORDER BY created $order ", - intval($owner_uid), - dbesc($album), - intval(PHOTO_NORMAL), - intval(PHOTO_PROFILE) - ); - - //edit album name - $album_edit = null; - - $photos = array(); - if($r) { - $twist = 'rotright'; - foreach($r as $rr) { - - if($twist == 'rotright') - $twist = 'rotleft'; - else - $twist = 'rotright'; - - $ext = $phototypes[$rr['mimetype']]; - - $imgalt_e = $rr['filename']; - $desc_e = $rr['description']; - - $imagelink = (z_root() . '/photos/' . App::$profile['channel_address'] . '/image/' . $rr['resource_id']); - - - $photos[] = array( - 'id' => $rr['id'], - 'twist' => ' ' . $twist . rand(2,4), - 'link' => $imagelink, - 'title' => t('View Photo'), - 'src' => z_root() . '/photo/' . $rr['resource_id'] . '-' . $rr['imgscale'] . '.' .$ext, - 'alt' => $imgalt_e, - 'desc'=> $desc_e, - 'ext' => $ext, - 'hash'=> $rr['resource_id'], - 'unknown' => t('Unknown') - ); - } - } - - - $tpl = get_markup_template('photo_album.tpl'); - $o .= replace_macros($tpl, array( - '$photos' => $photos, - '$album' => (($title) ? $title : $album), - '$album_id' => rand(), - '$album_edit' => array(t('Edit Album'), $album_edit), - '$can_post' => false, - '$upload' => array(t('Upload'), z_root() . '/photos/' . App::$profile['channel_address'] . '/upload/' . bin2hex($album)), - '$order' => false, - '$upload_form' => $upload_form, - '$usage' => $usage_message - )); - - return $o; -} - -- cgit v1.2.3 From 3e6088c6142d1dabbfdbb8b5df276ae942bd3554 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Mon, 27 Mar 2017 15:49:48 -0700 Subject: add 'author_is_pmable()' function with plugin hooks to control whether or not to display a 'send mail' link in the thread author menu. --- include/conversation.php | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) (limited to 'include') diff --git a/include/conversation.php b/include/conversation.php index b4f959afa..5b2d60583 100644 --- a/include/conversation.php +++ b/include/conversation.php @@ -917,6 +917,24 @@ function thread_action_menu($item,$mode = '') { } +function author_is_pmable($xchan) { + + $x = [ 'xchan' => $xchan, 'result' => 'unset' ]; + call_hooks('author_is_pmable',$x); + if($x['result'] !== 'unset') + return $x['result']; + + if($xchan['xchan_network'] === 'zot') + return true; + return false; + +} + + + + + + function thread_author_menu($item, $mode = '') { $menu = []; @@ -932,8 +950,6 @@ function thread_author_menu($item, $mode = '') { $profile_link = chanlink_hash($item['author_xchan']); - if($item['uid'] > 0) - $pm_url = z_root() . '/mail/new/?f=&hash=' . urlencode($item['author_xchan']); if(App::$contacts && array_key_exists($item['author_xchan'],App::$contacts)) $contact = App::$contacts[$item['author_xchan']]; @@ -941,6 +957,12 @@ function thread_author_menu($item, $mode = '') { if($local_channel && $item['author']['xchan_addr']) $follow_url = z_root() . '/follow/?f=&url=' . urlencode($item['author']['xchan_addr']); + + if($item['uid'] > 0 && author_is_pmable($item['author'])) + $pm_url = z_root() . '/mail/new/?f=&hash=' . urlencode($item['author_xchan']); + + + if($contact) { $poke_link = z_root() . '/poke/?f=&c=' . $contact['abook_id']; if (! intval($contact['abook_self'])) -- cgit v1.2.3 From c5828fecc1fadb4db705bbf94edfa7ff873b491a Mon Sep 17 00:00:00 2001 From: zotlabs Date: Tue, 28 Mar 2017 16:02:47 -0700 Subject: get rid of get_app() --- include/message.php | 2 -- 1 file changed, 2 deletions(-) (limited to 'include') diff --git a/include/message.php b/include/message.php index bde07afd8..da3514184 100644 --- a/include/message.php +++ b/include/message.php @@ -13,10 +13,8 @@ function send_message($uid = 0, $recipient = '', $body = '', $subject = '', $rep $ret = array('success' => false); $is_reply = false; - $a = get_app(); $observer_hash = get_observer_hash(); - if($uid) { $r = q("select * from channel where channel_id = %d limit 1", intval($uid) -- cgit v1.2.3 From f43428aacf940b84b05e1554cc53e29e60846ae4 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Wed, 29 Mar 2017 16:16:29 -0700 Subject: channel_store_lowlevel declared twice --- include/channel.php | 41 ----------------------------------------- 1 file changed, 41 deletions(-) (limited to 'include') diff --git a/include/channel.php b/include/channel.php index b224e3623..7394b1308 100644 --- a/include/channel.php +++ b/include/channel.php @@ -2007,47 +2007,6 @@ function channel_store_lowlevel($arr) { } - -function channel_store_lowlevel($arr) { - - $store = [ - 'channel_account_id' => ((array_key_exists('channel_account_id',$arr)) ? $arr['channel_account_id'] : '0'), - 'channel_primary' => ((array_key_exists('channel_primary',$arr)) ? $arr['channel_primary'] : '0'), - 'channel_name' => ((array_key_exists('channel_name',$arr)) ? $arr['channel_name'] : ''), - 'channel_address' => ((array_key_exists('channel_address',$arr)) ? $arr['channel_address'] : ''), - 'channel_guid' => ((array_key_exists('channel_guid',$arr)) ? $arr['channel_guid'] : ''), - 'channel_guid_sig' => ((array_key_exists('channel_guid_sig',$arr)) ? $arr['channel_guid_sig'] : ''), - 'channel_hash' => ((array_key_exists('channel_hash',$arr)) ? $arr['channel_hash'] : ''), - 'channel_timezone' => ((array_key_exists('channel_timezone',$arr)) ? $arr['channel_timezone'] : 'UTC'), - 'channel_location' => ((array_key_exists('channel_location',$arr)) ? $arr['channel_location'] : ''), - 'channel_theme' => ((array_key_exists('channel_theme',$arr)) ? $arr['channel_theme'] : ''), - 'channel_startpage' => ((array_key_exists('channel_startpage',$arr)) ? $arr['channel_startpage'] : ''), - 'channel_pubkey' => ((array_key_exists('channel_pubkey',$arr)) ? $arr['channel_pubkey'] : ''), - 'channel_prvkey' => ((array_key_exists('channel_prvkey',$arr)) ? $arr['channel_prvkey'] : ''), - 'channel_notifyflags' => ((array_key_exists('channel_notifyflags',$arr)) ? $arr['channel_notifyflags'] : '65535'), - 'channel_pageflags' => ((array_key_exists('channel_pageflags',$arr)) ? $arr['channel_pageflags'] : '0'), - 'channel_dirdate' => ((array_key_exists('channel_dirdate',$arr)) ? $arr['channel_dirdate'] : NULL_DATE), - 'channel_lastpost' => ((array_key_exists('channel_lastpost',$arr)) ? $arr['channel_lastpost'] : NULL_DATE), - 'channel_deleted' => ((array_key_exists('channel_deleted',$arr)) ? $arr['channel_deleted'] : NULL_DATE), - 'channel_max_anon_mail' => ((array_key_exists('channel_max_anon_mail',$arr)) ? $arr['channel_max_anon_mail'] : '10'), - 'channel_max_friend_req' => ((array_key_exists('channel_max_friend_req',$arr)) ? $arr['channel_max_friend_req'] : '10'), - 'channel_expire_days' => ((array_key_exists('channel_expire_days',$arr)) ? $arr['channel_expire_days'] : '0'), - 'channel_passwd_reset' => ((array_key_exists('channel_passwd_reset',$arr)) ? $arr['channel_passwd_reset'] : ''), - 'channel_default_group' => ((array_key_exists('channel_default_group',$arr)) ? $arr['channel_default_group'] : ''), - 'channel_allow_cid' => ((array_key_exists('channel_allow_cid',$arr)) ? $arr['channel_allow_cid'] : ''), - 'channel_allow_gid' => ((array_key_exists('channel_allow_gid',$arr)) ? $arr['channel_allow_gid'] : ''), - 'channel_deny_cid' => ((array_key_exists('channel_deny_cid',$arr)) ? $arr['channel_deny_cid'] : ''), - 'channel_deny_gid' => ((array_key_exists('channel_deny_gid',$arr)) ? $arr['channel_deny_gid'] : ''), - 'channel_removed' => ((array_key_exists('channel_removed',$arr)) ? $arr['channel_removed'] : '0'), - 'channel_system' => ((array_key_exists('channel_system',$arr)) ? $arr['channel_system'] : '0'), - 'channel_moved' => ((array_key_exists('channel_moved',$arr)) ? $arr['channel_moved'] : '') - ]; - - return create_table_from_array('channel',$store); - -} - - function profile_store_lowlevel($arr) { $store = [ -- cgit v1.2.3 From 6118570118eb97ee1daa69e7628aae03c3fe4b77 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Thu, 30 Mar 2017 20:43:49 -0700 Subject: make aes256gcm the primary crypto mode --- include/crypto.php | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'include') diff --git a/include/crypto.php b/include/crypto.php index f75390985..758cec24f 100644 --- a/include/crypto.php +++ b/include/crypto.php @@ -79,6 +79,19 @@ function STD_decrypt($data,$key,$iv) { return openssl_decrypt($data,'aes-256-cbc',str_pad($key,32,"\0"),OPENSSL_RAW_DATA,str_pad($iv,16,"\0")); } +function AES256GCM_encrypt($data,$key,$iv) { + $key = substr($key,0,32); + $iv = substr($iv,0,16); + return openssl_encrypt($data,'aes-256-gcm',str_pad($key,32,"\0"),OPENSSL_RAW_DATA,str_pad($iv,16,"\0")); +} + +function AES256GCM_decrypt($data,$key,$iv) { + $key = substr($key,0,32); + $iv = substr($iv,0,16); + return openssl_decrypt($data,'aes-256-gcm',str_pad($key,32,"\0"),OPENSSL_RAW_DATA,str_pad($iv,16,"\0")); +} + + function CAST5CBC_encrypt($data,$key,$iv) { $key = substr($key,0,16); $iv = substr($iv,0,8); @@ -152,7 +165,7 @@ function crypto_methods() { // The actual methods are responsible for deriving the actual key/iv from the provided parameters; // possibly by truncation or segmentation - though many other methods could be used. - $r = [ 'std', 'aes256cbc', 'aes128cbc', 'cast5cbc' ]; + $r = [ 'aes256gcm', 'std', 'aes256cbc', 'aes128cbc', 'cast5cbc' ]; call_hooks('crypto_methods',$r); return $r; -- cgit v1.2.3 From d1a018f2e8330fbf49ade51ec94fe5d7eb475d57 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Thu, 30 Mar 2017 21:04:55 -0700 Subject: whitespace --- include/import.php | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) (limited to 'include') diff --git a/include/import.php b/include/import.php index f6ebd4bff..9007dbe74 100644 --- a/include/import.php +++ b/include/import.php @@ -98,7 +98,7 @@ function import_channel($channel, $account_id, $seize) { $r = q("select * from channel where channel_account_id = %d and channel_guid = '%s' limit 1", intval($account_id), - $channel['channel_guid'] // Already dbesc'd + dbesc($channel['channel_guid']) ); if(! $r) { logger('mod_import: channel not found. ' . print_r($channel,true)); @@ -195,23 +195,24 @@ function import_hublocs($channel, $hublocs, $seize, $moving = false) { } if(! array_key_exists('hubloc_primary',$hubloc)) { - $hubloc['hubloc_primary'] = (($hubloc['hubloc_flags'] & 0x0001) ? 1 : 0); - $hubloc['hubloc_orphancheck'] = (($hubloc['hubloc_flags'] & 0x0004) ? 1 : 0); - $hubloc['hubloc_error'] = (($hubloc['hubloc_status'] & 0x0003) ? 1 : 0); - $hubloc['hubloc_deleted'] = (($hubloc['hubloc_flags'] & 0x1000) ? 1 : 0); + $hubloc['hubloc_primary'] = (($hubloc['hubloc_flags'] & 0x0001) ? 1 : 0); + $hubloc['hubloc_orphancheck'] = (($hubloc['hubloc_flags'] & 0x0004) ? 1 : 0); + $hubloc['hubloc_error'] = (($hubloc['hubloc_status'] & 0x0003) ? 1 : 0); + $hubloc['hubloc_deleted'] = (($hubloc['hubloc_flags'] & 0x1000) ? 1 : 0); } if($moving && $hubloc['hubloc_hash'] === $channel['channel_hash'] && $hubloc['hubloc_url'] !== z_root()) { $hubloc['hubloc_deleted'] = 1; } - $arr = array( - 'guid' => $hubloc['hubloc_guid'], + $arr = [ + 'guid' => $hubloc['hubloc_guid'], 'guid_sig' => $hubloc['hubloc_guid_sig'], - 'url' => $hubloc['hubloc_url'], - 'url_sig' => $hubloc['hubloc_url_sig'], - 'sitekey' => ((array_key_exists('hubloc_sitekey',$hubloc)) ? $hubloc['hubloc_sitekey'] : '') - ); + 'url' => $hubloc['hubloc_url'], + 'url_sig' => $hubloc['hubloc_url_sig'], + 'sitekey' => ((array_key_exists('hubloc_sitekey',$hubloc)) ? $hubloc['hubloc_sitekey'] : '') + ]; + if(($hubloc['hubloc_hash'] === $channel['channel_hash']) && intval($hubloc['hubloc_primary']) && ($seize)) $hubloc['hubloc_primary'] = 0; @@ -1443,7 +1444,8 @@ function import_webpage_element($element, $channel, $type) { // The author is either the owner or whomever was specified $arr['author_xchan'] = (($element['author_xchan']) ? $element['author_xchan'] : get_observer_hash()); // Import mimetype if it is a valid mimetype for the element - $mimetypes = [ 'text/bbcode', + $mimetypes = [ + 'text/bbcode', 'text/html', 'text/markdown', 'text/plain', -- cgit v1.2.3 From e79f450af9690433aaa1b81ca94555e7dcf14103 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Thu, 30 Mar 2017 21:45:29 -0700 Subject: aes256gcm is not ready for prime time. Stay tuned. Until it is, we're pretty much stuffed unless we go to 3rd party crypto libs. --- include/crypto.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'include') diff --git a/include/crypto.php b/include/crypto.php index 758cec24f..bcbb3d388 100644 --- a/include/crypto.php +++ b/include/crypto.php @@ -81,14 +81,14 @@ function STD_decrypt($data,$key,$iv) { function AES256GCM_encrypt($data,$key,$iv) { $key = substr($key,0,32); - $iv = substr($iv,0,16); - return openssl_encrypt($data,'aes-256-gcm',str_pad($key,32,"\0"),OPENSSL_RAW_DATA,str_pad($iv,16,"\0")); + $iv = substr($iv,0,12); + return openssl_encrypt($data,'aes-256-gcm',str_pad($key,32,"\0"),OPENSSL_RAW_DATA,str_pad($iv,12,"\0")); } function AES256GCM_decrypt($data,$key,$iv) { $key = substr($key,0,32); - $iv = substr($iv,0,16); - return openssl_decrypt($data,'aes-256-gcm',str_pad($key,32,"\0"),OPENSSL_RAW_DATA,str_pad($iv,16,"\0")); + $iv = substr($iv,0,12); + return openssl_decrypt($data,'aes-256-gcm',str_pad($key,32,"\0"),OPENSSL_RAW_DATA,str_pad($iv,12,"\0")); } @@ -165,7 +165,7 @@ function crypto_methods() { // The actual methods are responsible for deriving the actual key/iv from the provided parameters; // possibly by truncation or segmentation - though many other methods could be used. - $r = [ 'aes256gcm', 'std', 'aes256cbc', 'aes128cbc', 'cast5cbc' ]; + $r = [ 'std', 'aes256cbc', 'aes128cbc', 'cast5cbc' ]; call_hooks('crypto_methods',$r); return $r; -- cgit v1.2.3 From 810d9e21bcf35c3897718d8eb5a798372656f517 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Sat, 1 Apr 2017 15:30:59 -0700 Subject: use aes-ctr which is slightly/arguably better than a poke in the eye and don't restrict the crypto algorithm by server role. --- include/crypto.php | 17 +++++++---------- include/zot.php | 3 --- 2 files changed, 7 insertions(+), 13 deletions(-) (limited to 'include') diff --git a/include/crypto.php b/include/crypto.php index bcbb3d388..187330c6c 100644 --- a/include/crypto.php +++ b/include/crypto.php @@ -79,16 +79,16 @@ function STD_decrypt($data,$key,$iv) { return openssl_decrypt($data,'aes-256-cbc',str_pad($key,32,"\0"),OPENSSL_RAW_DATA,str_pad($iv,16,"\0")); } -function AES256GCM_encrypt($data,$key,$iv) { +function AES256CTR_encrypt($data,$key,$iv) { $key = substr($key,0,32); - $iv = substr($iv,0,12); - return openssl_encrypt($data,'aes-256-gcm',str_pad($key,32,"\0"),OPENSSL_RAW_DATA,str_pad($iv,12,"\0")); + $iv = substr($iv,0,16); + return openssl_encrypt($data,'aes-256-ctr',str_pad($key,32,"\0"),OPENSSL_RAW_DATA,str_pad($iv,16,"\0")); } -function AES256GCM_decrypt($data,$key,$iv) { +function AES256CTR_decrypt($data,$key,$iv) { $key = substr($key,0,32); - $iv = substr($iv,0,12); - return openssl_decrypt($data,'aes-256-gcm',str_pad($key,32,"\0"),OPENSSL_RAW_DATA,str_pad($iv,12,"\0")); + $iv = substr($iv,0,16); + return openssl_decrypt($data,'aes-256-ctr',str_pad($key,32,"\0"),OPENSSL_RAW_DATA,str_pad($iv,16,"\0")); } @@ -155,9 +155,6 @@ function other_encapsulate($data,$pubkey,$alg) { function crypto_methods() { - if(\Zotlabs\Lib\System::get_server_role() !== 'pro') - return [ 'aes256cbc' ]; - // 'std' is the new project standard which is aes256cbc but transmits/receives 256-byte key and iv. // aes256cbc is provided for compatibility with earlier zot implementations which assume 32-byte key and 16-byte iv. // other_encapsulate() now produces these longer keys/ivs by default so that it is difficult to guess a @@ -165,7 +162,7 @@ function crypto_methods() { // The actual methods are responsible for deriving the actual key/iv from the provided parameters; // possibly by truncation or segmentation - though many other methods could be used. - $r = [ 'std', 'aes256cbc', 'aes128cbc', 'cast5cbc' ]; + $r = [ 'aes256ctr', 'std', 'aes256cbc', 'aes128cbc', 'cast5cbc' ]; call_hooks('crypto_methods',$r); return $r; diff --git a/include/zot.php b/include/zot.php index 8a2178913..b3999920f 100644 --- a/include/zot.php +++ b/include/zot.php @@ -165,9 +165,6 @@ function zot_build_packet($channel, $type = 'notify', $recipients = null, $remot function zot_best_algorithm($methods) { - if(\Zotlabs\Lib\System::get_server_role() !== 'pro') - return 'aes256cbc'; - $x = [ 'methods' => $methods, 'result' => '' ]; call_hooks('zot_best_algorithm',$x); if($x['result']) -- cgit v1.2.3 From 044067f0556be3b896fc1b183038777d971e9b57 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Sun, 2 Apr 2017 16:40:36 -0700 Subject: harden security --- include/crypto.php | 36 ++++++++++++++++++++++++++---------- 1 file changed, 26 insertions(+), 10 deletions(-) (limited to 'include') diff --git a/include/crypto.php b/include/crypto.php index 187330c6c..2c5545e9b 100644 --- a/include/crypto.php +++ b/include/crypto.php @@ -55,6 +55,7 @@ function AES256CBC_decrypt($data,$key,$iv) { return openssl_decrypt($data,'aes-256-cbc',str_pad($key,32,"\0"),OPENSSL_RAW_DATA,str_pad($iv,16,"\0")); } + function AES128CBC_encrypt($data,$key,$iv) { $key = substr($key,0,16); $iv = substr($iv,0,16); @@ -67,28 +68,30 @@ function AES128CBC_decrypt($data,$key,$iv) { return openssl_decrypt($data,'aes-128-cbc',str_pad($key,16,"\0"),OPENSSL_RAW_DATA,str_pad($iv,16,"\0")); } -function STD_encrypt($data,$key,$iv) { + +function AES256CTR_encrypt($data,$key,$iv) { $key = substr($key,0,32); $iv = substr($iv,0,16); - return openssl_encrypt($data,'aes-256-cbc',str_pad($key,32,"\0"),OPENSSL_RAW_DATA,str_pad($iv,16,"\0")); + return openssl_encrypt($data,'aes-256-ctr',str_pad($key,32,"\0"),OPENSSL_RAW_DATA,str_pad($iv,16,"\0")); } -function STD_decrypt($data,$key,$iv) { +function AES256CTR_decrypt($data,$key,$iv) { $key = substr($key,0,32); $iv = substr($iv,0,16); - return openssl_decrypt($data,'aes-256-cbc',str_pad($key,32,"\0"),OPENSSL_RAW_DATA,str_pad($iv,16,"\0")); + return openssl_decrypt($data,'aes-256-ctr',str_pad($key,32,"\0"),OPENSSL_RAW_DATA,str_pad($iv,16,"\0")); } -function AES256CTR_encrypt($data,$key,$iv) { + +function CAMELLIA256CFB_encrypt($data,$key,$iv) { $key = substr($key,0,32); $iv = substr($iv,0,16); - return openssl_encrypt($data,'aes-256-ctr',str_pad($key,32,"\0"),OPENSSL_RAW_DATA,str_pad($iv,16,"\0")); + return openssl_encrypt($data,'camellia-256-cfb',str_pad($key,32,"\0"),OPENSSL_RAW_DATA,str_pad($iv,16,"\0")); } -function AES256CTR_decrypt($data,$key,$iv) { +function CAMELLIA256CFB_decrypt($data,$key,$iv) { $key = substr($key,0,32); $iv = substr($iv,0,16); - return openssl_decrypt($data,'aes-256-ctr',str_pad($key,32,"\0"),OPENSSL_RAW_DATA,str_pad($iv,16,"\0")); + return openssl_decrypt($data,'camellia-256-cfb',str_pad($key,32,"\0"),OPENSSL_RAW_DATA,str_pad($iv,16,"\0")); } @@ -104,6 +107,20 @@ function CAST5CBC_decrypt($data,$key,$iv) { return openssl_decrypt($data,'cast5-cbc',str_pad($key,16,"\0"),OPENSSL_RAW_DATA,str_pad($iv,8,"\0")); } +function CAST5CFB_encrypt($data,$key,$iv) { + $key = substr($key,0,16); + $iv = substr($iv,0,8); + return openssl_encrypt($data,'cast5-cfb',str_pad($key,16,"\0"),OPENSSL_RAW_DATA,str_pad($iv,8,"\0")); +} + +function CAST5CFB_decrypt($data,$key,$iv) { + $key = substr($key,0,16); + $iv = substr($iv,0,8); + return openssl_decrypt($data,'cast5-cfb',str_pad($key,16,"\0"),OPENSSL_RAW_DATA,str_pad($iv,8,"\0")); +} + + + function crypto_encapsulate($data,$pubkey,$alg='aes256cbc') { $fn = strtoupper($alg) . '_encrypt'; @@ -155,14 +172,13 @@ function other_encapsulate($data,$pubkey,$alg) { function crypto_methods() { - // 'std' is the new project standard which is aes256cbc but transmits/receives 256-byte key and iv. // aes256cbc is provided for compatibility with earlier zot implementations which assume 32-byte key and 16-byte iv. // other_encapsulate() now produces these longer keys/ivs by default so that it is difficult to guess a // particular implementation or choice of underlying implementations based on the key/iv length. // The actual methods are responsible for deriving the actual key/iv from the provided parameters; // possibly by truncation or segmentation - though many other methods could be used. - $r = [ 'aes256ctr', 'std', 'aes256cbc', 'aes128cbc', 'cast5cbc' ]; + $r = [ 'aes256ctr', 'camellia256cfb', 'cast5cfb', 'aes256cbc', 'aes128cbc', 'cast5cbc' ]; call_hooks('crypto_methods',$r); return $r; -- cgit v1.2.3 From d985db60cca1256698f15a9cb7a39688c72ec082 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Sun, 2 Apr 2017 17:09:51 -0700 Subject: import authors from any unrecognised network as network 'unknown'. --- include/items.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'include') diff --git a/include/items.php b/include/items.php index 3d0f380b4..4ef52fb41 100755 --- a/include/items.php +++ b/include/items.php @@ -762,6 +762,8 @@ function import_author_xchan($x) { if($arr['xchan_hash']) return $arr['xchan_hash']; + $y = false; + if((! array_key_exists('network', $x)) || ($x['network'] === 'zot')) { $y = import_author_zot($x); } @@ -770,9 +772,7 @@ function import_author_xchan($x) { $y = import_author_rss($x); } - if($x['network'] === 'unknown') { - $y = import_author_unknown($x); - } + $y = import_author_unknown($x); return(($y) ? $y : false); } -- cgit v1.2.3 From 1a28fb2a0c8b183fc4463c7f2c08212d068deb69 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Sun, 2 Apr 2017 17:12:42 -0700 Subject: logic error --- include/items.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'include') diff --git a/include/items.php b/include/items.php index 4ef52fb41..ea72d1d4e 100755 --- a/include/items.php +++ b/include/items.php @@ -772,9 +772,11 @@ function import_author_xchan($x) { $y = import_author_rss($x); } - $y = import_author_unknown($x); + if(! $y) { + $y = import_author_unknown($x); + } - return(($y) ? $y : false); + return($y); } /** -- cgit v1.2.3 From 4a49643bcd125fde6c62c37a2d0a7902bbf502d7 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Sun, 2 Apr 2017 19:46:20 -0700 Subject: import_author_zot() - check for both hubloc and xchan entries. This should catch and repair entries which were subject to transient storage failures. --- include/zot.php | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) (limited to 'include') diff --git a/include/zot.php b/include/zot.php index b3999920f..266060839 100644 --- a/include/zot.php +++ b/include/zot.php @@ -3578,21 +3578,30 @@ function get_rpost_path($observer) { function import_author_zot($x) { + // Check that we have both a hubloc and xchan record - as occasionally storage calls will fail and + // we may only end up with one; which results in posts with no author name or photo and are a bit + // of a hassle to repair. If either or both are missing, do a full discovery probe. + $hash = make_xchan_hash($x['guid'],$x['guid_sig']); - $r = q("select hubloc_url from hubloc where hubloc_guid = '%s' and hubloc_guid_sig = '%s' and hubloc_primary = 1 limit 1", + $r1 = q("select hubloc_url from hubloc where hubloc_guid = '%s' and hubloc_guid_sig = '%s' and hubloc_primary = 1 limit 1", dbesc($x['guid']), dbesc($x['guid_sig']) ); - if ($r) { - logger('import_author_zot: in cache', LOGGER_DEBUG); + $r2 = q("select xchan_hash from xchan where xchan_guid = '%s' and xchan_guid_sig = '%s' limit 1", + dbesc($x['guid']), + dbesc($x['guid_sig']) + ); + + if($r1 && $r2) { + logger('in cache', LOGGER_DEBUG); return $hash; } - logger('import_author_zot: entry not in cache - probing: ' . print_r($x,true), LOGGER_DEBUG); + logger('not in cache - probing: ' . print_r($x,true), LOGGER_DEBUG); $them = array('hubloc_url' => $x['url'], 'xchan_guid' => $x['guid'], 'xchan_guid_sig' => $x['guid_sig']); - if (zot_refresh($them)) + if(zot_refresh($them)) return $hash; return false; -- cgit v1.2.3 From af14020e42481088f0e9f2773bda6453b60bcdb9 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Sun, 2 Apr 2017 20:03:27 -0700 Subject: change hook for perm_is_allowed while retaining backwards compatibility --- include/permissions.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'include') diff --git a/include/permissions.php b/include/permissions.php index d21b45550..f719394c5 100644 --- a/include/permissions.php +++ b/include/permissions.php @@ -314,11 +314,12 @@ function perm_is_allowed($uid, $observer_xchan, $permission) { 'channel_id' => $uid, 'observer_hash' => $observer_xchan, 'permission' => $permission, - 'result' => false); + 'result' => 'unset'); call_hooks('perm_is_allowed', $arr); - if($arr['result']) - return true; + if($arr['result'] !== 'unset') { + return $arr['result']; + } $global_perms = \Zotlabs\Access\Permissions::Perms(); -- cgit v1.2.3 From 9a5ce2354d4abd7fd398bd10b1b22d7e09b6433b Mon Sep 17 00:00:00 2001 From: zotlabs Date: Sun, 2 Apr 2017 20:51:40 -0700 Subject: remove some obsolete permissions stuff --- include/permissions.php | 420 +----------------------------------------------- 1 file changed, 5 insertions(+), 415 deletions(-) (limited to 'include') diff --git a/include/permissions.php b/include/permissions.php index f719394c5..f97142fab 100644 --- a/include/permissions.php +++ b/include/permissions.php @@ -7,60 +7,10 @@ require_once('include/security.php'); * * This file conntains functions to check and work with permissions. * - * Most of this file is obsolete and has been superceded by extensible permissions in v1.12; it is left here - * for reference and because we haven't yet checked that all functions have been replaced and are available - * elsewhere (typically Zotlabs/Access/*). */ -/** - * @brief Return an array with all available permissions. - * - * These are channel specific permissions. - * The list of available permissions can get manipulated by the hook - * global_permissions. - * - * @return array associative array containing all permissions - */ -function get_perms() { - -// thinking about making element[2] a bitmask instead of boolean so that we can provide a list of applicable selections -// for any given permission. Currently we use the boolean to disallow write access to "everybody", but we also want to be -// able to handle troublesome settings such as allowing channel_w_stream to anybody in the network. You can allow it, but -// there's no way to implement sending it. - - $global_perms = array( - // Read only permissions - 'view_stream' => array('channel_r_stream', intval(PERMS_R_STREAM), true, t('Can view my normal stream and posts'), ''), - 'view_profile' => array('channel_r_profile', intval(PERMS_R_PROFILE), true, t('Can view my default channel profile'), ''), - 'view_contacts' => array('channel_r_abook', intval(PERMS_R_ABOOK), true, t('Can view my connections'), ''), - 'view_storage' => array('channel_r_storage', intval(PERMS_R_STORAGE), true, t('Can view my file storage and photos'), ''), - 'view_pages' => array('channel_r_pages', intval(PERMS_R_PAGES), true, t('Can view my webpages'), ''), - - // Write permissions - 'send_stream' => array('channel_w_stream', intval(PERMS_W_STREAM), false, t('Can send me their channel stream and posts'), ''), - 'post_wall' => array('channel_w_wall', intval(PERMS_W_WALL), false, t('Can post on my channel page ("wall")'), ''), - 'post_comments' => array('channel_w_comment', intval(PERMS_W_COMMENT), false, t('Can comment on or like my posts'), ''), - 'post_mail' => array('channel_w_mail', intval(PERMS_W_MAIL), false, t('Can send me private mail messages'), ''), - 'post_like' => array('channel_w_like', intval(PERMS_W_LIKE), false, t('Can like/dislike stuff'), t('Profiles and things other than posts/comments')), - - 'tag_deliver' => array('channel_w_tagwall', intval(PERMS_W_TAGWALL), false, t('Can forward to all my channel contacts via post @mentions'), t('Advanced - useful for creating group forum channels')), - 'chat' => array('channel_w_chat', intval(PERMS_W_CHAT), false, t('Can chat with me (when available)'), t('')), - 'write_storage' => array('channel_w_storage', intval(PERMS_W_STORAGE), false, t('Can write to my file storage and photos'), ''), - 'write_pages' => array('channel_w_pages', intval(PERMS_W_PAGES), false, t('Can edit my webpages'), ''), - - 'republish' => array('channel_a_republish', intval(PERMS_A_REPUBLISH), false, t('Can source my public posts in derived channels'), t('Somewhat advanced - very useful in open communities')), - - 'delegate' => array('channel_a_delegate', intval(PERMS_A_DELEGATE), false, t('Can administer my channel resources'), t('Extremely advanced. Leave this alone unless you know what you are doing')), - ); - $ret = array('global_permissions' => $global_perms); - call_hooks('global_permissions', $ret); - - return $ret['global_permissions']; -} - - /** * get_all_perms($uid,$observer_xchan) * @@ -297,7 +247,6 @@ function get_all_perms($uid, $observer_xchan, $internal_use = true) { * * Checks if the given observer with the hash $observer_xchan has permission * $permission on channel_id $uid. - * $permission is one defined in get_perms(); * * @param int $uid The channel_id associated with the resource owner * @param string $observer_xchan The xchan_hash representing the observer @@ -465,7 +414,7 @@ function perm_is_allowed($uid, $observer_xchan, $permission) { function get_all_api_perms($uid,$api) { - $global_perms = get_perms(); + $global_perms = \Zotlabs\Access\Permissions::Perms(); $ret = array(); @@ -568,6 +517,7 @@ function site_default_perms() { 'view_contacts' => PERMS_PUBLIC, 'view_storage' => PERMS_PUBLIC, 'view_pages' => PERMS_PUBLIC, + 'view_wiki' => PERMS_PUBLIC, 'send_stream' => PERMS_SPECIFIC, 'post_wall' => PERMS_SPECIFIC, 'post_comments' => PERMS_SPECIFIC, @@ -576,16 +526,15 @@ function site_default_perms() { 'chat' => PERMS_SPECIFIC, 'write_storage' => PERMS_SPECIFIC, 'write_pages' => PERMS_SPECIFIC, + 'write_wiki' => PERMS_SPECIFIC, 'delegate' => PERMS_SPECIFIC, 'post_like' => PERMS_NETWORK ); - $global_perms = get_perms(); + $global_perms = \Zotlabs\Access\Permissions::Perms(); foreach($global_perms as $perm => $v) { - $x = get_config('default_perms', $perm); - if($x === false) - $x = $typical[$perm]; + $x = get_config('default_perms', $perm, $typical[$perm]); $ret[$perm] = $x; } @@ -593,362 +542,3 @@ function site_default_perms() { } -/** - * @brief Return an array of all permissions for this role. - * - * Given a string for the channel role ('social','forum', etc) - * return an array of all permission fields pre-filled for this role. - * This includes the channel permission scope indicators (anything beginning with 'channel_') as well as - * * perms_auto: true or false to create auto-permissions for this channel - * * perms_follow: The permissions to apply when initiating a connection request to another channel - * * perms_accept: The permissions to apply when accepting a connection request from another channel (not automatic) - * * default_collection: true or false to make the default ACL include the channel's default collection - * * directory_publish: true or false to publish this channel in the directory - * Any attributes may be extended (new roles defined) and modified (specific permissions altered) by plugins - * - * @param string $role - * @return array - */ -function get_role_perms($role) { - - $ret = array(); - - $ret['role'] = $role; - - switch($role) { - case 'social': - $ret['perms_auto'] = false; - $ret['default_collection'] = false; - $ret['directory_publish'] = true; - $ret['online'] = true; - $ret['perms_connect'] = [ - 'view_stream', 'view_profile', 'view_contacts', 'view_storage', - 'view_pages', 'send_stream', 'post_wall', 'post_comments', - 'post_mail', 'chat', 'post_like', 'republish' ]; - $ret['limits'] = [ - 'view_stream' => PERMS_PUBLIC, - 'view_profile' => PERMS_PUBLIC, - 'view_contacts' => PERMS_PUBLIC, - 'view_storage' => PERMS_PUBLIC, - 'view_pages' => PERMS_PUBLIC, - 'send_stream' => PERMS_SPECIFIC, - 'post_wall' => PERMS_SPECIFIC, - 'post_comments' => PERMS_SPECIFIC, - 'post_mail' => PERMS_SPECIFIC, - 'post_like' => PERMS_SPECIFIC, - 'tag_deliver' => PERMS_SPECIFIC, - 'chat' => PERMS_SPECIFIC, - 'write_storage' => PERMS_SPECIFIC, - 'write_pages' => PERMS_SPECIFIC, - 'republish' => PERMS_SPECIFIC, - 'delegate' => PERMS_SPECIFIC - ]; - - break; - - case 'social_restricted': - $ret['perms_auto'] = false; - $ret['default_collection'] = true; - $ret['directory_publish'] = true; - $ret['online'] = true; - $ret['perms_connect'] = [ - 'view_stream', 'view_profile', 'view_contacts', 'view_storage', - 'view_pages', 'send_stream', 'post_wall', 'post_comments', - 'post_mail', 'chat', 'post_like' ]; - $ret['limits'] = [ - 'view_stream' => PERMS_PUBLIC, - 'view_profile' => PERMS_PUBLIC, - 'view_contacts' => PERMS_PUBLIC, - 'view_storage' => PERMS_PUBLIC, - 'view_pages' => PERMS_PUBLIC, - 'send_stream' => PERMS_SPECIFIC, - 'post_wall' => PERMS_SPECIFIC, - 'post_comments' => PERMS_SPECIFIC, - 'post_mail' => PERMS_SPECIFIC, - 'post_like' => PERMS_SPECIFIC, - 'tag_deliver' => PERMS_SPECIFIC, - 'chat' => PERMS_SPECIFIC, - 'write_storage' => PERMS_SPECIFIC, - 'write_pages' => PERMS_SPECIFIC, - 'republish' => PERMS_SPECIFIC, - 'delegate' => PERMS_SPECIFIC - ]; - - - break; - - case 'social_private': - $ret['perms_auto'] = false; - $ret['default_collection'] = true; - $ret['directory_publish'] = false; - $ret['online'] = false; - $ret['perms_connect'] = [ - 'view_stream', 'view_profile', 'view_contacts', 'view_storage', - 'view_pages', 'send_stream', 'post_wall', 'post_comments', - 'post_mail', 'post_like' ]; - $ret['limits'] = [ - 'view_stream' => PERMS_PUBLIC, - 'view_profile' => PERMS_PUBLIC, - 'view_contacts' => PERMS_SPECIFIC, - 'view_storage' => PERMS_SPECIFIC, - 'view_pages' => PERMS_PUBLIC, - 'send_stream' => PERMS_SPECIFIC, - 'post_wall' => PERMS_SPECIFIC, - 'post_comments' => PERMS_SPECIFIC, - 'post_mail' => PERMS_SPECIFIC, - 'post_like' => PERMS_SPECIFIC, - 'tag_deliver' => PERMS_SPECIFIC, - 'chat' => PERMS_SPECIFIC, - 'write_storage' => PERMS_SPECIFIC, - 'write_pages' => PERMS_SPECIFIC, - 'republish' => PERMS_SPECIFIC, - 'delegate' => PERMS_SPECIFIC - ]; - - break; - - case 'forum': - $ret['perms_auto'] = true; - $ret['default_collection'] = false; - $ret['directory_publish'] = true; - $ret['online'] = false; - $ret['perms_connect'] = [ - 'view_stream', 'view_profile', 'view_contacts', 'view_storage', - 'view_pages', 'post_wall', 'post_comments', 'tag_deliver', - 'post_mail', 'post_like' , 'republish', 'chat' ]; - $ret['limits'] = [ - 'view_stream' => PERMS_PUBLIC, - 'view_profile' => PERMS_PUBLIC, - 'view_contacts' => PERMS_PUBLIC, - 'view_storage' => PERMS_PUBLIC, - 'view_pages' => PERMS_PUBLIC, - 'send_stream' => PERMS_SPECIFIC, - 'post_wall' => PERMS_SPECIFIC, - 'post_comments' => PERMS_SPECIFIC, - 'post_mail' => PERMS_SPECIFIC, - 'post_like' => PERMS_SPECIFIC, - 'tag_deliver' => PERMS_SPECIFIC, - 'chat' => PERMS_SPECIFIC, - 'write_storage' => PERMS_SPECIFIC, - 'write_pages' => PERMS_SPECIFIC, - 'republish' => PERMS_SPECIFIC, - 'delegate' => PERMS_SPECIFIC - ]; - - break; - - case 'forum_restricted': - $ret['perms_auto'] = false; - $ret['default_collection'] = true; - $ret['directory_publish'] = true; - $ret['online'] = false; - $ret['perms_connect'] = [ - 'view_stream', 'view_profile', 'view_contacts', 'view_storage', - 'view_pages', 'post_wall', 'post_comments', 'tag_deliver', - 'post_mail', 'post_like' , 'chat' ]; - $ret['limits'] = [ - 'view_stream' => PERMS_PUBLIC, - 'view_profile' => PERMS_PUBLIC, - 'view_contacts' => PERMS_PUBLIC, - 'view_storage' => PERMS_PUBLIC, - 'view_pages' => PERMS_PUBLIC, - 'send_stream' => PERMS_SPECIFIC, - 'post_wall' => PERMS_SPECIFIC, - 'post_comments' => PERMS_SPECIFIC, - 'post_mail' => PERMS_SPECIFIC, - 'post_like' => PERMS_SPECIFIC, - 'tag_deliver' => PERMS_SPECIFIC, - 'chat' => PERMS_SPECIFIC, - 'write_storage' => PERMS_SPECIFIC, - 'write_pages' => PERMS_SPECIFIC, - 'republish' => PERMS_SPECIFIC, - 'delegate' => PERMS_SPECIFIC - ]; - - break; - - case 'forum_private': - $ret['perms_auto'] = false; - $ret['default_collection'] = true; - $ret['directory_publish'] = false; - $ret['online'] = false; - - $ret['perms_connect'] = [ - 'view_stream', 'view_profile', 'view_contacts', 'view_storage', - 'view_pages', 'post_wall', 'post_comments', - 'post_mail', 'post_like' , 'chat' ]; - $ret['limits'] = [ - 'view_stream' => PERMS_PUBLIC, - 'view_profile' => PERMS_SPECIFIC, - 'view_contacts' => PERMS_SPECIFIC, - 'view_storage' => PERMS_SPECIFIC, - 'view_pages' => PERMS_SPECIFIC, - 'send_stream' => PERMS_SPECIFIC, - 'post_wall' => PERMS_SPECIFIC, - 'post_comments' => PERMS_SPECIFIC, - 'post_mail' => PERMS_SPECIFIC, - 'post_like' => PERMS_SPECIFIC, - 'tag_deliver' => PERMS_SPECIFIC, - 'chat' => PERMS_SPECIFIC, - 'write_storage' => PERMS_SPECIFIC, - 'write_pages' => PERMS_SPECIFIC, - 'republish' => PERMS_SPECIFIC, - 'delegate' => PERMS_SPECIFIC - ]; - - break; - - case 'feed': - $ret['perms_auto'] = true; - $ret['default_collection'] = false; - $ret['directory_publish'] = true; - $ret['online'] = false; - - $ret['perms_connect'] = [ - 'view_stream', 'view_profile', 'view_contacts', 'view_storage', - 'view_pages', 'send_stream', 'post_wall', 'post_comments', - 'post_mail', 'post_like' , 'republish' ]; - $ret['limits'] = [ - 'view_stream' => PERMS_PUBLIC, - 'view_profile' => PERMS_PUBLIC, - 'view_contacts' => PERMS_PUBLIC, - 'view_storage' => PERMS_PUBLIC, - 'view_pages' => PERMS_PUBLIC, - 'send_stream' => PERMS_SPECIFIC, - 'post_wall' => PERMS_SPECIFIC, - 'post_comments' => PERMS_SPECIFIC, - 'post_mail' => PERMS_SPECIFIC, - 'post_like' => PERMS_SPECIFIC, - 'tag_deliver' => PERMS_SPECIFIC, - 'chat' => PERMS_SPECIFIC, - 'write_storage' => PERMS_SPECIFIC, - 'write_pages' => PERMS_SPECIFIC, - 'republish' => PERMS_SPECIFIC, - 'delegate' => PERMS_SPECIFIC - ]; - - break; - - case 'feed_restricted': - $ret['perms_auto'] = false; - $ret['default_collection'] = true; - $ret['directory_publish'] = false; - $ret['online'] = false; - $ret['perms_connect'] = [ - 'view_stream', 'view_profile', 'view_contacts', 'view_storage', - 'view_pages', 'send_stream', 'post_wall', 'post_comments', - 'post_mail', 'post_like' , 'republish' ]; - $ret['limits'] = [ - 'view_stream' => PERMS_PUBLIC, - 'view_profile' => PERMS_PUBLIC, - 'view_contacts' => PERMS_PUBLIC, - 'view_storage' => PERMS_PUBLIC, - 'view_pages' => PERMS_PUBLIC, - 'send_stream' => PERMS_SPECIFIC, - 'post_wall' => PERMS_SPECIFIC, - 'post_comments' => PERMS_SPECIFIC, - 'post_mail' => PERMS_SPECIFIC, - 'post_like' => PERMS_SPECIFIC, - 'tag_deliver' => PERMS_SPECIFIC, - 'chat' => PERMS_SPECIFIC, - 'write_storage' => PERMS_SPECIFIC, - 'write_pages' => PERMS_SPECIFIC, - 'republish' => PERMS_SPECIFIC, - 'delegate' => PERMS_SPECIFIC - ]; - - break; - - case 'soapbox': - $ret['perms_auto'] = true; - $ret['default_collection'] = false; - $ret['directory_publish'] = true; - $ret['online'] = false; - - $ret['perms_connect'] = [ - 'view_stream', 'view_profile', 'view_contacts', 'view_storage', - 'view_pages', 'post_like' , 'republish' ]; - - $ret['limits'] = [ - 'view_stream' => PERMS_PUBLIC, - 'view_profile' => PERMS_PUBLIC, - 'view_contacts' => PERMS_PUBLIC, - 'view_storage' => PERMS_PUBLIC, - 'view_pages' => PERMS_PUBLIC, - 'send_stream' => PERMS_SPECIFIC, - 'post_wall' => PERMS_SPECIFIC, - 'post_comments' => PERMS_SPECIFIC, - 'post_mail' => PERMS_SPECIFIC, - 'post_like' => PERMS_SPECIFIC, - 'tag_deliver' => PERMS_SPECIFIC, - 'chat' => PERMS_SPECIFIC, - 'write_storage' => PERMS_SPECIFIC, - 'write_pages' => PERMS_SPECIFIC, - 'republish' => PERMS_SPECIFIC, - 'delegate' => PERMS_SPECIFIC - ]; - - break; - - case 'repository': - $ret['perms_auto'] = true; - $ret['default_collection'] = false; - $ret['directory_publish'] = true; - $ret['online'] = false; - - $ret['perms_connect'] = [ - 'view_stream', 'view_profile', 'view_contacts', 'view_storage', - 'view_pages', 'write_storage', 'write_pages', 'post_wall', 'post_comments', 'tag_deliver', - 'post_mail', 'post_like' , 'republish', 'chat' ]; - $ret['limits'] = [ - 'view_stream' => PERMS_PUBLIC, - 'view_profile' => PERMS_PUBLIC, - 'view_contacts' => PERMS_PUBLIC, - 'view_storage' => PERMS_PUBLIC, - 'view_pages' => PERMS_PUBLIC, - 'send_stream' => PERMS_SPECIFIC, - 'post_wall' => PERMS_SPECIFIC, - 'post_comments' => PERMS_SPECIFIC, - 'post_mail' => PERMS_SPECIFIC, - 'post_like' => PERMS_SPECIFIC, - 'tag_deliver' => PERMS_SPECIFIC, - 'chat' => PERMS_SPECIFIC, - 'write_storage' => PERMS_SPECIFIC, - 'write_pages' => PERMS_SPECIFIC, - 'republish' => PERMS_SPECIFIC, - 'delegate' => PERMS_SPECIFIC - ]; - - - break; - - default: - break; - } - - $x = get_config('system','role_perms'); - // let system settings over-ride any or all - if($x && is_array($x) && array_key_exists($role,$x)) - $ret = array_merge($ret,$x[$role]); - - call_hooks('get_role_perms',$ret); - - return $ret; -} - -/** - * @brief Returns a list or roles, grouped by type. - * - * @return string Returns an array of roles, grouped by type - */ -function get_roles() { - $roles = array( - t('Social Networking') => array('social' => t('Social - Mostly Public'), 'social_restricted' => t('Social - Restricted'), 'social_private' => t('Social - Private')), - t('Community Forum') => array('forum' => t('Forum - Mostly Public'), 'forum_restricted' => t('Forum - Restricted'), 'forum_private' => t('Forum - Private')), - t('Feed Republish') => array('feed' => t('Feed - Mostly Public'), 'feed_restricted' => t('Feed - Restricted')), - t('Special Purpose') => array('soapbox' => t('Special - Celebrity/Soapbox'), 'repository' => t('Special - Group Repository')), - t('Other') => array('custom' => t('Custom/Expert Mode')) - ); - - return $roles; -} -- cgit v1.2.3 From 263efbfe39d36a7133fca82e8e689435255fd9e2 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Sun, 2 Apr 2017 21:49:50 -0700 Subject: reference to deprecated function import_author_diaspora in socgraph.php --- include/socgraph.php | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) (limited to 'include') diff --git a/include/socgraph.php b/include/socgraph.php index 69365f80f..d28531c43 100644 --- a/include/socgraph.php +++ b/include/socgraph.php @@ -122,7 +122,7 @@ function poco_load($xchan = '', $url = null) { $profile_url = $url['value']; continue; } - if($url['type'] == 'zot' || $url['type'] == 'diaspora' || $url['type'] == 'friendica') { + if($url['type'] == 'zot') { $network = $url['type']; $address = str_replace('acct:' , '', $url['value']); continue; @@ -163,12 +163,6 @@ function poco_load($xchan = '', $url = null) { continue; } } - else { - $x = import_author_diaspora(array('address' => $address)); - if(! $x) { - continue; - } - } } else { continue; @@ -564,8 +558,6 @@ function poco($a,$extended = false) { if($fields_ret['urls']) { $entry['urls'] = array(array('value' => $rr['xchan_url'], 'type' => 'profile')); $network = $rr['xchan_network']; - if(strpos($network,'friendica') !== false) - $network = 'friendica'; if($rr['xchan_addr']) $entry['urls'][] = array('value' => 'acct:' . $rr['xchan_addr'], 'type' => $network); } -- cgit v1.2.3 From 26125bcf0b8ce98fa4522f89792d7e77f25ff1ca Mon Sep 17 00:00:00 2001 From: zotlabs Date: Sun, 2 Apr 2017 22:20:37 -0700 Subject: sql error photos_albums_list with non-logged-in viewer --- include/items.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'include') diff --git a/include/items.php b/include/items.php index ea72d1d4e..e3147dea4 100755 --- a/include/items.php +++ b/include/items.php @@ -1776,9 +1776,12 @@ logger('revision: ' . $arr['revision']); intval($arr['revision']) ); - if($r && count($r)) { + if($r) { + // This will gives us a fresh copy of what's now in the DB and undo the db escaping, + // which really messes up the notifications + $current_post = $r[0]['id']; - $arr = $r[0]; // This will gives us a fresh copy of what's now in the DB and undo the db escaping, which really messes up the notifications + $arr = $r[0]; logger('item_store: created item ' . $current_post, LOGGER_DEBUG); } else { -- cgit v1.2.3 From d6c23486d563e29862d3db891e67649d13e6def0 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Mon, 3 Apr 2017 16:43:30 -0700 Subject: create site_store_lowlevel() to initialise data structures for the site table --- include/dir_fns.php | 31 +++++++++++-------------------- include/hubloc.php | 27 +++++++++++++++++++++++++++ include/queue_fn.php | 12 ++++++++---- include/zot.php | 32 +++++++++++++++++--------------- 4 files changed, 63 insertions(+), 39 deletions(-) (limited to 'include') diff --git a/include/dir_fns.php b/include/dir_fns.php index 3922730fc..2bd1228ec 100644 --- a/include/dir_fns.php +++ b/include/dir_fns.php @@ -185,26 +185,17 @@ function sync_directories($dirmode) { /** @FIXME What to do if we're in a different realm? */ if ((! $r) && (z_root() != DIRECTORY_FALLBACK_MASTER)) { - $r = array(); - $r[] = array( - 'site_url' => DIRECTORY_FALLBACK_MASTER, - 'site_flags' => DIRECTORY_MODE_PRIMARY, - 'site_update' => NULL_DATE, - 'site_directory' => DIRECTORY_FALLBACK_MASTER . '/dirsearch', - 'site_realm' => DIRECTORY_REALM, - 'site_valid' => 1, - 'site_crypto' => 'aes256cbc' - - ); - $x = q("insert into site ( site_url, site_flags, site_update, site_directory, site_realm, site_valid, site_crypto ) - values ( '%s', %d, '%s', '%s', '%s', %d, '%s' ) ", - dbesc($r[0]['site_url']), - intval($r[0]['site_flags']), - dbesc($r[0]['site_update']), - dbesc($r[0]['site_directory']), - dbesc($r[0]['site_realm']), - intval($r[0]['site_valid']), - dbesc($r[0]['site_crypto']) + + $x = site_store_lowlevel( + [ + 'site_url' => DIRECTORY_FALLBACK_MASTER, + 'site_flags' => DIRECTORY_MODE_PRIMARY, + 'site_update' => NULL_DATE, + 'site_directory' => DIRECTORY_FALLBACK_MASTER . '/dirsearch', + 'site_realm' => DIRECTORY_REALM, + 'site_valid' => 1, + 'site_crypto' => 'aes256cbc' + ] ); $r = q("select * from site where site_flags in (%d, %d) and site_url != '%s' and site_type = %d ", diff --git a/include/hubloc.php b/include/hubloc.php index 599252522..0daa5908c 100644 --- a/include/hubloc.php +++ b/include/hubloc.php @@ -39,6 +39,33 @@ function hubloc_store_lowlevel($arr) { return create_table_from_array('hubloc', $store); } +function site_store_lowlevel($arr) { + + $store = [ + 'site_url' => ((array_key_exists('site_url',$arr)) ? $arr['site_url'] : ''), + 'site_access' => ((array_key_exists('site_access',$arr)) ? $arr['site_access'] : 0), + 'site_flags' => ((array_key_exists('site_flags',$arr)) ? $arr['site_flags'] : 0), + 'site_update' => ((array_key_exists('site_update',$arr)) ? $arr['site_update'] : NULL_DATE), + 'site_pull' => ((array_key_exists('site_pull',$arr)) ? $arr['site_pull'] : NULL_DATE), + 'site_sync' => ((array_key_exists('site_sync',$arr)) ? $arr['site_sync'] : NULL_DATE), + 'site_directory' => ((array_key_exists('site_directory',$arr)) ? $arr['site_directory'] : ''), + 'site_register' => ((array_key_exists('site_register',$arr)) ? $arr['site_register'] : 0), + 'site_sellpage' => ((array_key_exists('site_sellpage',$arr)) ? $arr['site_sellpage'] : ''), + 'site_location' => ((array_key_exists('site_location',$arr)) ? $arr['site_location'] : ''), + 'site_realm' => ((array_key_exists('site_realm',$arr)) ? $arr['site_realm'] : ''), + 'site_valid' => ((array_key_exists('site_valid',$arr)) ? $arr['site_valid'] : 0), + 'site_dead' => ((array_key_exists('site_dead',$arr)) ? $arr['site_dead'] : 0), + 'site_type' => ((array_key_exists('site_type',$arr)) ? $arr['site_type'] : 0), + 'site_project' => ((array_key_exists('site_project',$arr)) ? $arr['site_project'] : ''), + 'site_version' => ((array_key_exists('site_version',$arr)) ? $arr['site_version'] : ''), + 'site_crypto' => ((array_key_exists('site_crypto',$arr)) ? $arr['site_crypto'] : '') + ]; + + return create_table_from_array('site', $store); +} + + + function prune_hub_reinstalls() { diff --git a/include/queue_fn.php b/include/queue_fn.php index ede6c8f11..c9179b953 100644 --- a/include/queue_fn.php +++ b/include/queue_fn.php @@ -146,10 +146,14 @@ function queue_deliver($outq, $immediate = false) { // your site has existed. Since we don't know for sure what these sites are, // call them unknown - q("insert into site (site_url, site_update, site_dead, site_type, site_crypto) values ('%s','%s',0,%d,'') ", - dbesc($base), - dbesc(datetime_convert()), - intval(($outq['outq_driver'] === 'post') ? SITE_TYPE_NOTZOT : SITE_TYPE_UNKNOWN) + site_store_lowlevel( + [ + 'site_url' => $base, + 'site_update' => datetime_convert(), + 'site_dead' => 0, + 'site_type' => intval(($outq['outq_driver'] === 'post') ? SITE_TYPE_NOTZOT : SITE_TYPE_UNKNOWN), + 'site_crypto' => '' + ] ); } } diff --git a/include/zot.php b/include/zot.php index 266060839..1a4f6534b 100644 --- a/include/zot.php +++ b/include/zot.php @@ -2897,22 +2897,24 @@ function import_site($arr, $pubkey) { else { $update = true; - $r = q("insert into site ( site_location, site_url, site_access, site_flags, site_update, site_directory, site_register, site_sellpage, site_realm, site_type, site_project, site_version, site_crypto ) - values ( '%s', '%s', %d, %d, '%s', '%s', %d, '%s', '%s', %d, '%s', '%s', '%s' )", - dbesc($site_location), - dbesc($url), - intval($access_policy), - intval($site_directory), - dbesc(datetime_convert()), - dbesc($directory_url), - intval($register_policy), - dbesc($sellpage), - dbesc($site_realm), - intval(SITE_TYPE_ZOT), - dbesc($site_project), - dbesc($site_version), - dbesc($site_crypto) + $r = site_store_lowlevel( + [ + 'site_location' => $site_location, + 'site_url' => $url, + 'site_access' => intval($access_policy), + 'site_flags' => intval($site_directory), + 'site_update' => datetime_convert(), + 'site_directory' => $directory_url, + 'site_register' => intval($register_policy), + 'site_sellpage' => $sellpage, + 'site_realm' => $site_realm, + 'site_type' => intval(SITE_TYPE_ZOT), + 'site_project' => $site_project, + 'site_version' => $site_version, + 'site_crypto' => $site_crypto + ] ); + if(! $r) { logger('import_site: record create failed. ' . print_r($arr,true)); } -- cgit v1.2.3 From a92256e1cbd0b6bcaac5711c751479b97b30e00e Mon Sep 17 00:00:00 2001 From: zotlabs Date: Mon, 3 Apr 2017 22:13:12 -0700 Subject: legal_webbie() now provides different character rules depending on whether you federate or not. Added some comments in a few places that needed them. --- include/text.php | 67 +++++++++++++++++++++++++++++++++++--------------------- 1 file changed, 42 insertions(+), 25 deletions(-) (limited to 'include') diff --git a/include/text.php b/include/text.php index 1b0150706..e02becf31 100644 --- a/include/text.php +++ b/include/text.php @@ -2000,23 +2000,40 @@ function legal_webbie($s) { if(! strlen($s)) return ''; + + // Has to start with a lowercase alphabetic character - not a number. + // This is so we can differentiate between something like channel=123 + // and channel=foo and lookup the first by numeric id and the second + // by nickname. + $x = $s; do { $s = $x; $x = preg_replace('/^([^a-z])(.*?)/',"$2",$s); } while($x != $s); - return preg_replace('/([^a-z0-9\-\_])/','',$x); + // Use the lowest common denominator rules (letters, numbers, and underscore) + // if the site configuration allows federation with other networks + + if(Zlib\System::get_server_role() === 'pro') { + return preg_replace('/([^a-z0-9\-\_\.])/','',$x); + } + else { + return preg_replace('/([^a-z0-9\_])/','',$x); + } } function check_webbie($arr) { + + // These names conflict with the CalDAV server + $taken = [ 'principals', 'addressbooks', 'calendars' ]; + $reservechan = get_config('system','reserved_channels'); - if(strlen($reservechan)) - $taken = explode(',', $reservechan); - else - $taken = array('principals','addressbooks','calendars'); + if(strlen($reservechan)) { + $taken = array_merge($taken,explode(',', $reservechan)); + } $str = ''; if(count($arr)) { @@ -2267,13 +2284,13 @@ function design_tools() { $who = $channel['channel_address']; return replace_macros(get_markup_template('design_tools.tpl'), array( - '$title' => t('Design Tools'), - '$who' => $who, - '$sys' => $sys, + '$title' => t('Design Tools'), + '$who' => $who, + '$sys' => $sys, '$blocks' => t('Blocks'), - '$menus' => t('Menus'), + '$menus' => t('Menus'), '$layout' => t('Layouts'), - '$pages' => t('Pages') + '$pages' => t('Pages') )); } @@ -2294,21 +2311,21 @@ function website_portation_tools() { } return replace_macros(get_markup_template('website_portation_tools.tpl'), array( - '$title' => t('Import'), - '$import_label' => t('Import website...'), - '$import_placeholder' => t('Select folder to import'), - '$file_upload_text' => t('Import from a zipped folder:'), - '$file_import_text' => t('Import from cloud files:'), - '$desc' => t('/cloud/channel/path/to/folder'), - '$hint' => t('Enter path to website files'), - '$select' => t('Select folder'), - '$export_label' => t('Export website...'), - '$file_download_text' => t('Export to a zip file'), - '$filename_desc' => t('website.zip'), - '$filename_hint' => t('Enter a name for the zip file.'), - '$cloud_export_text' => t('Export to cloud files'), - '$cloud_export_desc' => t('/path/to/export/folder'), - '$cloud_export_hint' => t('Enter a path to a cloud files destination.'), + '$title' => t('Import'), + '$import_label' => t('Import website...'), + '$import_placeholder' => t('Select folder to import'), + '$file_upload_text' => t('Import from a zipped folder:'), + '$file_import_text' => t('Import from cloud files:'), + '$desc' => t('/cloud/channel/path/to/folder'), + '$hint' => t('Enter path to website files'), + '$select' => t('Select folder'), + '$export_label' => t('Export website...'), + '$file_download_text' => t('Export to a zip file'), + '$filename_desc' => t('website.zip'), + '$filename_hint' => t('Enter a name for the zip file.'), + '$cloud_export_text' => t('Export to cloud files'), + '$cloud_export_desc' => t('/path/to/export/folder'), + '$cloud_export_hint' => t('Enter a path to a cloud files destination.'), '$cloud_export_select' => t('Specify folder'), )); } -- cgit v1.2.3 From a4685e6df38dd530b348268f383f59a993607cad Mon Sep 17 00:00:00 2001 From: zotlabs Date: Wed, 5 Apr 2017 17:08:13 -0700 Subject: import_author_xchan - since we rarely refresh zot-info for non-connections, force a cache reload once a week to catch things like profile photo updates and location changes --- include/zot.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include') diff --git a/include/zot.php b/include/zot.php index 1a4f6534b..8afed1c3c 100644 --- a/include/zot.php +++ b/include/zot.php @@ -3595,7 +3595,7 @@ function import_author_zot($x) { dbesc($x['guid_sig']) ); - if($r1 && $r2) { + if($r1 && $r2 && $r1[0]['hubloc_updated'] > datetime_convert('UTC','UTC','now - 1 week')) { logger('in cache', LOGGER_DEBUG); return $hash; } -- cgit v1.2.3 From 9fb08fb5022c9eaf6368a9d3ac07bb1dcf856c20 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Wed, 5 Apr 2017 19:08:43 -0700 Subject: make legal_webbie() pluggable - * this should not be merged with federated projects unless the federation drivers make use of the hooks. --- include/text.php | 38 +++++++++++++++++++++----------------- 1 file changed, 21 insertions(+), 17 deletions(-) (limited to 'include') diff --git a/include/text.php b/include/text.php index e02becf31..bbf0b5b98 100644 --- a/include/text.php +++ b/include/text.php @@ -2000,30 +2000,34 @@ function legal_webbie($s) { if(! strlen($s)) return ''; + // WARNING: This regex will not work in a federated environment. + // You will probably want something like + // preg_replace('/([^a-z0-9\_])/','',strtolower($s)); - // Has to start with a lowercase alphabetic character - not a number. - // This is so we can differentiate between something like channel=123 - // and channel=foo and lookup the first by numeric id and the second - // by nickname. + $r = preg_replace('/([^a-z0-9\-\_\.])/','',strtolower($s)); - $x = $s; - do { - $s = $x; - $x = preg_replace('/^([^a-z])(.*?)/',"$2",$s); - } while($x != $s); + $x = [ 'input' => $s, 'output' => $r ]; + call_hooks('legal_webbie',$x); + return $x['output']; - // Use the lowest common denominator rules (letters, numbers, and underscore) - // if the site configuration allows federation with other networks +} + +function legal_webbie_text() { + + // WARNING: This will not work in a federated environment. + + $s = t('a-z, 0-9, -, _, and . only'); + + $x = [ 'text' => $s ]; + call_hooks('legal_webbie_text',$x); + return $x['text']; - if(Zlib\System::get_server_role() === 'pro') { - return preg_replace('/([^a-z0-9\-\_\.])/','',$x); - } - else { - return preg_replace('/([^a-z0-9\_])/','',$x); - } } + + + function check_webbie($arr) { -- cgit v1.2.3 From ebcfc7f2b2f8604671fb7729c8da578d42fe3d36 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Thu, 6 Apr 2017 16:24:19 -0700 Subject: revisit the import_author_zot algorithm yet again. There was one bug that we weren't returning necessary information in the first SQL query - and performance/loading problem if one tries to refresh a dead site. --- include/zot.php | 36 ++++++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) (limited to 'include') diff --git a/include/zot.php b/include/zot.php index 8afed1c3c..d1fd1db6a 100644 --- a/include/zot.php +++ b/include/zot.php @@ -3585,7 +3585,9 @@ function import_author_zot($x) { // of a hassle to repair. If either or both are missing, do a full discovery probe. $hash = make_xchan_hash($x['guid'],$x['guid_sig']); - $r1 = q("select hubloc_url from hubloc where hubloc_guid = '%s' and hubloc_guid_sig = '%s' and hubloc_primary = 1 limit 1", + + $r1 = q("select hubloc_url, hubloc_updated, site_dead from hubloc left join site on + hubloc_url = site_url where hubloc_guid = '%s' and hubloc_guid_sig = '%s' and hubloc_primary = 1 limit 1", dbesc($x['guid']), dbesc($x['guid_sig']) ); @@ -3595,12 +3597,42 @@ function import_author_zot($x) { dbesc($x['guid_sig']) ); + $site_dead = false; + + if($r1 && intval($r1[0]['site_dead'])) { + $site_dead = true; + } + + // We have valid and somewhat fresh information. + if($r1 && $r2 && $r1[0]['hubloc_updated'] > datetime_convert('UTC','UTC','now - 1 week')) { logger('in cache', LOGGER_DEBUG); return $hash; } - logger('not in cache - probing: ' . print_r($x,true), LOGGER_DEBUG); + logger('not in cache or cache stale - probing: ' . print_r($x,true), LOGGER_DEBUG,LOG_INFO); + + // The primary hub may be dead. Try to find another one associated with this identity that is + // still alive. If we find one, use that url for the discovery/refresh probe. Otherwise, the dead site + // is all we have and there is no point probing it. Just return the hash indicating we have a + // cached entry and the identity is valid. It's just unreachable until they bring back their + // server from the grave or create another clone elsewhere. + + if($site_dead) { + logger('dead site - ignoring', LOGGER_DEBUG,LOG_INFO); + + $r = q("select hubloc_url from hubloc left join site on hubloc_url = site_url + where hubloc_hash = '%s' and site_dead = 0", + dbesc($hash) + ); + if($r) { + logger('found another site that is not dead: ' . $r[0]['hubloc_url'], LOGGER_DEBUG,LOG_INFO); + $x['url'] = $r[0]['hubloc_url']; + } + else { + return $hash; + } + } $them = array('hubloc_url' => $x['url'], 'xchan_guid' => $x['guid'], 'xchan_guid_sig' => $x['guid_sig']); if(zot_refresh($them)) -- cgit v1.2.3 From d52ee7ae27133a526778b8a6553de5c318ded7fe Mon Sep 17 00:00:00 2001 From: zotlabs Date: Thu, 6 Apr 2017 19:55:43 -0700 Subject: only log zot_refresh content if json decode was successful. --- include/zot.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'include') diff --git a/include/zot.php b/include/zot.php index d1fd1db6a..3e1b27c83 100644 --- a/include/zot.php +++ b/include/zot.php @@ -310,8 +310,6 @@ function zot_refresh($them, $channel = null, $force = false) { $result = z_post_url($url . $rhs,$postvars); - logger('zot_refresh: zot-info: ' . print_r($result,true), LOGGER_DATA, LOG_DEBUG); - if ($result['success']) { $j = json_decode($result['body'],true); @@ -321,6 +319,8 @@ function zot_refresh($them, $channel = null, $force = false) { return false; } + logger('zot-info: ' . print_r($result,true), LOGGER_DATA, LOG_DEBUG); + $signed_token = ((is_array($j) && array_key_exists('signed_token',$j)) ? $j['signed_token'] : null); if($signed_token) { $valid = rsa_verify('token.' . $token,base64url_decode($signed_token),$j['key']); -- cgit v1.2.3 From 65e5894363e5cd5a9c8a61a0387f90068215f58e Mon Sep 17 00:00:00 2001 From: zotlabs Date: Fri, 7 Apr 2017 14:56:12 -0700 Subject: photo size-0 issue --- include/photo/photo_driver.php | 1 + 1 file changed, 1 insertion(+) (limited to 'include') diff --git a/include/photo/photo_driver.php b/include/photo/photo_driver.php index 923e34dbe..cc1f3b5d0 100644 --- a/include/photo/photo_driver.php +++ b/include/photo/photo_driver.php @@ -330,6 +330,7 @@ abstract class photo_driver { $p['photo_usage'] = intval($arr['photo_usage']); $p['os_storage'] = intval($arr['os_storage']); $p['os_path'] = $arr['os_path']; + $p['os_syspath'] = ((array_key_exists('os_syspath',$arr)) ? $arr['os_syspath'] : ''); $p['display_path'] = (($arr['display_path']) ? $arr['display_path'] : ''); if(! intval($p['imgscale'])) -- cgit v1.2.3 From 063577c19ea45918e332ec640fb7369bf757b348 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Sun, 9 Apr 2017 20:25:41 -0700 Subject: some signatures showing as invalid because of recent import_author_zot() changes. --- include/items.php | 32 +++++++++++++++++++++++++------- 1 file changed, 25 insertions(+), 7 deletions(-) (limited to 'include') diff --git a/include/items.php b/include/items.php index c3b57f6cb..f290b5ec1 100755 --- a/include/items.php +++ b/include/items.php @@ -625,14 +625,17 @@ function get_item_elements($x,$allow_code = false) { return array(); // save a potentially expensive lookup if author == owner + if($arr['author_xchan'] === make_xchan_hash($x['owner']['guid'],$x['owner']['guid_sig'])) $arr['owner_xchan'] = $arr['author_xchan']; else { $xchan_hash = import_author_xchan($x['owner']); - if($xchan_hash) + if($xchan_hash) { $arr['owner_xchan'] = $xchan_hash; - else + } + else { return array(); + } } // Check signature on the body text received. @@ -649,10 +652,25 @@ function get_item_elements($x,$allow_code = false) { $r = q("select xchan_pubkey from xchan where xchan_hash = '%s' limit 1", dbesc($arr['author_xchan']) ); - if($r && rsa_verify($x['body'],base64url_decode($arr['sig']),$r[0]['xchan_pubkey'])) - $arr['item_verified'] = 1; - else - logger('get_item_elements: message verification failed.'); + if($r) { + if($r[0]['xchan_pubkey']) { + if(rsa_verify($x['body'],base64url_decode($arr['sig']),$r[0]['xchan_pubkey'])) { + $arr['item_verified'] = 1; + } + else { + logger('get_item_elements: message verification failed.'); + } + } + else { + + // If we don't have a public key, strip the signature so it won't show as invalid. + // This won't happen in normal use, but could happen if import_author_xchan() + // failed to load the zot-info packet due to a server failure and had + // to create an alternate xchan with network 'unknown' + + unset($arr['sig']); + } + } } // if the input is markdown, remove one level of html escaping. @@ -1107,7 +1125,7 @@ function encode_item_xchan($xchan) { $ret['address'] = $xchan['xchan_addr']; $ret['url'] = $xchan['xchan_url']; $ret['network'] = $xchan['xchan_network']; - $ret['photo'] = array('mimetype' => $xchan['xchan_photo_mimetype'], 'src' => $xchan['xchan_photo_m']); + $ret['photo'] = [ 'mimetype' => $xchan['xchan_photo_mimetype'], 'src' => $xchan['xchan_photo_m'] ]; $ret['guid'] = $xchan['xchan_guid']; $ret['guid_sig'] = $xchan['xchan_guid_sig']; -- cgit v1.2.3 From ed8e4962b9c589941534b702efe0bc3fac628a95 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Mon, 10 Apr 2017 20:31:45 -0700 Subject: ugly hack to webfinger to allow connections to be made to mastodon servers. --- include/network.php | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'include') diff --git a/include/network.php b/include/network.php index bce59d38c..e6a6fc2b4 100644 --- a/include/network.php +++ b/include/network.php @@ -22,7 +22,6 @@ function get_capath() { * @param int $redirects default 0 * internal use, recursion counter * @param array $opts (optional parameters) associative array with: - * * \b accept_content => supply Accept: header with 'accept_content' as the value * * \b timeout => int seconds, default system config value or 60 seconds * * \b headers => array of additional header fields * * \b http_auth => username:password @@ -202,7 +201,6 @@ function z_fetch_url($url, $binary = false, $redirects = 0, $opts = array()) { * @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 @@ -1204,7 +1202,16 @@ function webfinger_rfc7033($webbie,$zot = false) { } logger('fetching url from resource: ' . $rhs . ':' . $webbie); - $s = z_fetch_url('https://' . $rhs . '/.well-known/webfinger?f=&resource=' . $resource . (($zot) ? '&zot=1' : '')); + // The default curl Accept: header is */*, which is incorrectly handled by Mastodon servers + // and results in a 406 (Not Acceptable) response, and will also incorrectly produce an XML + // document if you use 'application/jrd+json, */*'. We could set this to application/jrd+json, + // but some test webfinger servers may not explicitly set the content type and they would be + // blocked. The best compromise until Mastodon is fixed is to remove the Accept header which is + // accomplished by setting it to nothing. + + $counter = 0; + $s = z_fetch_url('https://' . $rhs . '/.well-known/webfinger?f=&resource=' . $resource . (($zot) ? '&zot=1' : ''), + false, $counter, [ 'headers' => [ 'Accept:' ] ]); if($s['success']) { $j = json_decode($s['body'],true); -- cgit v1.2.3 From 1609473e5d1bd9b131e61d41b6123669e7b8885d Mon Sep 17 00:00:00 2001 From: zotlabs Date: Tue, 11 Apr 2017 20:17:22 -0700 Subject: correct the mastodon "boost" (aka 'share') author attribution by checking for share activities and pulling the original author info from the activity:object --- include/feedutils.php | 139 ++++++++++++++++++++++++++++++-------------------- 1 file changed, 85 insertions(+), 54 deletions(-) (limited to 'include') diff --git a/include/feedutils.php b/include/feedutils.php index d1985649d..477685f9a 100644 --- a/include/feedutils.php +++ b/include/feedutils.php @@ -254,81 +254,124 @@ function get_atom_elements($feed, $item, &$author) { else $base_url = ''; - // look for a photo. We should check media size and find the best one, - // but for now let's just find any author photo - $rawauthor = $item->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10,'author'); + $rawverb = $item->get_item_tags(NAMESPACE_ACTIVITY, 'verb'); - if($rawauthor && $rawauthor[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['link']) { - $base = $rawauthor[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['link']; - foreach($base as $link) { - if(!x($author, 'author_photo') || ! $author['author_photo']) { - if($link['attribs']['']['rel'] === 'photo' || $link['attribs']['']['rel'] === 'avatar') - $author['author_photo'] = unxmlify($link['attribs']['']['href']); - } - } + // select between supported verbs + + if($rawverb) { + $res['verb'] = unxmlify($rawverb[0]['data']); } - $rawactor = $item->get_item_tags(NAMESPACE_ACTIVITY, 'actor'); + // translate OStatus unfollow to activity streams if it happened to get selected + + if((x($res,'verb')) && ($res['verb'] === 'http://ostatus.org/schema/1.0/unfollow')) + $res['verb'] = ACTIVITY_UNFOLLOW; - if($rawactor && activity_match($rawactor[0]['child'][NAMESPACE_ACTIVITY]['obj_type'][0]['data'],ACTIVITY_OBJ_PERSON)) { - $base = $rawactor[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['link']; - if($base && count($base)) { - foreach($base as $link) { - if($link['attribs']['']['rel'] === 'alternate' && (! $res['author_link'])) - $author['author_link'] = unxmlify($link['attribs']['']['href']); - if(!x($author, 'author_photo') || ! $author['author_photo']) { - if($link['attribs']['']['rel'] === 'avatar' || $link['attribs']['']['rel'] === 'photo') - $author['author_photo'] = unxmlify($link['attribs']['']['href']); - } - } - } - } - // check for a yahoo media element (github etc.) - if(! $author['author_photo']) { - $rawmedia = $item->get_item_tags(NAMESPACE_YMEDIA,'thumbnail'); - if($rawmedia && $rawmedia[0]['attribs']['']['url']) { - $author['author_photo'] = strip_tags(unxmlify($rawmedia[0]['attribs']['']['url'])); + if(array_key_exists('verb',$res) && $res['verb'] === ACTIVITY_SHARE) { + // For Mastodon shares ("boosts"), we need to parse the original author information + // from the activity:object -> author structure + $rawobj = $item->get_item_tags(NAMESPACE_ACTIVITY, 'object'); + + if($rawobj) { + $rawauthor = $rawobj->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10,'author'); + if($rawauthor && $rawauthor[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name']) { + $author['author_name'] = unxmlify($rawauthor[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name']); + } + + if($rawauthor && $rawauthor[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['uri']) { + $author['author_link'] = unxmlify($rawauthor[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['uri']); + } + if($rawauthor && $rawauthor[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['link']) { + $base = $rawauthor[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['link']; + foreach($base as $link) { + if(!x($author, 'author_photo') || ! $author['author_photo']) { + if($link['attribs']['']['rel'] === 'photo' || $link['attribs']['']['rel'] === 'avatar') + $author['author_photo'] = unxmlify($link['attribs']['']['href']); + } + } + } } } + else { + // look for a photo. We should check media size and find the best one, + // but for now let's just find any author photo + $rawauthor = $item->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10,'author'); - // No photo/profile-link on the item - look at the feed level - - if((! (x($author,'author_link'))) || (! (x($author,'author_photo')))) { - $rawauthor = $feed->get_feed_tags(SIMPLEPIE_NAMESPACE_ATOM_10,'author'); if($rawauthor && $rawauthor[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['link']) { $base = $rawauthor[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['link']; foreach($base as $link) { - if($link['attribs']['']['rel'] === 'alternate' && (! $author['author_link'])) { - $author['author_link'] = unxmlify($link['attribs']['']['href']); - $author['author_is_feed'] = true; - } - if(! $author['author_photo']) { + if(!x($author, 'author_photo') || ! $author['author_photo']) { if($link['attribs']['']['rel'] === 'photo' || $link['attribs']['']['rel'] === 'avatar') $author['author_photo'] = unxmlify($link['attribs']['']['href']); } } } - $rawactor = $feed->get_feed_tags(NAMESPACE_ACTIVITY, 'subject'); + $rawactor = $item->get_item_tags(NAMESPACE_ACTIVITY, 'actor'); if($rawactor && activity_match($rawactor[0]['child'][NAMESPACE_ACTIVITY]['obj_type'][0]['data'],ACTIVITY_OBJ_PERSON)) { $base = $rawactor[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['link']; - if($base && count($base)) { foreach($base as $link) { if($link['attribs']['']['rel'] === 'alternate' && (! $res['author_link'])) $author['author_link'] = unxmlify($link['attribs']['']['href']); - if(! (x($author,'author_photo'))) { + if(!x($author, 'author_photo') || ! $author['author_photo']) { if($link['attribs']['']['rel'] === 'avatar' || $link['attribs']['']['rel'] === 'photo') $author['author_photo'] = unxmlify($link['attribs']['']['href']); } } } } + + // check for a yahoo media element (github etc.) + + if(! $author['author_photo']) { + $rawmedia = $item->get_item_tags(NAMESPACE_YMEDIA,'thumbnail'); + if($rawmedia && $rawmedia[0]['attribs']['']['url']) { + $author['author_photo'] = strip_tags(unxmlify($rawmedia[0]['attribs']['']['url'])); + } + } + + + // No photo/profile-link on the item - look at the feed level + + if((! (x($author,'author_link'))) || (! (x($author,'author_photo')))) { + $rawauthor = $feed->get_feed_tags(SIMPLEPIE_NAMESPACE_ATOM_10,'author'); + if($rawauthor && $rawauthor[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['link']) { + $base = $rawauthor[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['link']; + foreach($base as $link) { + if($link['attribs']['']['rel'] === 'alternate' && (! $author['author_link'])) { + $author['author_link'] = unxmlify($link['attribs']['']['href']); + $author['author_is_feed'] = true; + } + if(! $author['author_photo']) { + if($link['attribs']['']['rel'] === 'photo' || $link['attribs']['']['rel'] === 'avatar') + $author['author_photo'] = unxmlify($link['attribs']['']['href']); + } + } + } + + $rawactor = $feed->get_feed_tags(NAMESPACE_ACTIVITY, 'subject'); + + if($rawactor && activity_match($rawactor[0]['child'][NAMESPACE_ACTIVITY]['obj_type'][0]['data'],ACTIVITY_OBJ_PERSON)) { + $base = $rawactor[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['link']; + + if($base && count($base)) { + foreach($base as $link) { + if($link['attribs']['']['rel'] === 'alternate' && (! $res['author_link'])) + $author['author_link'] = unxmlify($link['attribs']['']['href']); + if(! (x($author,'author_photo'))) { + if($link['attribs']['']['rel'] === 'avatar' || $link['attribs']['']['rel'] === 'photo') + $author['author_photo'] = unxmlify($link['attribs']['']['href']); + } + } + } + } + } } $ostatus_protocol = (($item->get_item_tags(NAMESPACE_OSTATUS,'conversation')) ? true : false); @@ -492,18 +535,6 @@ function get_atom_elements($feed, $item, &$author) { $res['coord'] = unxmlify($rawgeo[0]['data']); - $rawverb = $item->get_item_tags(NAMESPACE_ACTIVITY, 'verb'); - - // select between supported verbs - - if($rawverb) { - $res['verb'] = unxmlify($rawverb[0]['data']); - } - - // translate OStatus unfollow to activity streams if it happened to get selected - - if((x($res,'verb')) && ($res['verb'] === 'http://ostatus.org/schema/1.0/unfollow')) - $res['verb'] = ACTIVITY_UNFOLLOW; $cats = $item->get_categories(); if($cats) { -- cgit v1.2.3 From 1c32564536cbfa12bd21a1c8161921b13d7dcc66 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Wed, 12 Apr 2017 17:32:28 -0700 Subject: backend infrastructure for 'channel protection password'; which will be used to optionally encrypt export files and resolve channel/identity ownership/hijacking disputes --- include/channel.php | 7 ++++++- include/import.php | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) (limited to 'include') diff --git a/include/channel.php b/include/channel.php index 7394b1308..890bb8bd6 100644 --- a/include/channel.php +++ b/include/channel.php @@ -538,6 +538,8 @@ function identity_basic_export($channel_id, $sections = null) { $ret['relocate'] = [ 'channel_address' => $r[0]['channel_address'], 'url' => z_root()]; if(in_array('channel',$sections)) { $ret['channel'] = $r[0]; + unset($ret['channel']['channel_password']); + unset($ret['channel']['channel_salt']); } } @@ -1999,7 +2001,10 @@ function channel_store_lowlevel($arr) { 'channel_deny_gid' => ((array_key_exists('channel_deny_gid',$arr)) ? $arr['channel_deny_gid'] : ''), 'channel_removed' => ((array_key_exists('channel_removed',$arr)) ? $arr['channel_removed'] : '0'), 'channel_system' => ((array_key_exists('channel_system',$arr)) ? $arr['channel_system'] : '0'), - 'channel_moved' => ((array_key_exists('channel_moved',$arr)) ? $arr['channel_moved'] : '') + + 'channel_moved' => ((array_key_exists('channel_moved',$arr)) ? $arr['channel_moved'] : ''), + 'channel_password' => ((array_key_exists('channel_password',$arr)) ? $arr['channel_password'] : ''), + 'channel_salt' => ((array_key_exists('channel_salt',$arr)) ? $arr['channel_salt'] : '') ]; diff --git a/include/import.php b/include/import.php index 9007dbe74..224bb1803 100644 --- a/include/import.php +++ b/include/import.php @@ -82,7 +82,7 @@ function import_channel($channel, $account_id, $seize) { 'channel_r_storage', 'channel_r_pages', 'channel_w_stream', 'channel_w_wall', 'channel_w_comment', 'channel_w_mail', 'channel_w_like', 'channel_w_tagwall', 'channel_w_chat', 'channel_w_storage', 'channel_w_pages', 'channel_a_republish', - 'channel_a_delegate', 'perm_limits' + 'channel_a_delegate', 'perm_limits', 'channel_password', 'channel_salt' ]; $clean = array(); -- cgit v1.2.3 From 91d0f871817ba79131d4b55c7a9f8e2eac9eb8d4 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Wed, 12 Apr 2017 17:43:27 -0700 Subject: make sure the new fields don't leak through sync packets and break older versions --- include/zot.php | 2 ++ 1 file changed, 2 insertions(+) (limited to 'include') diff --git a/include/zot.php b/include/zot.php index 3e1b27c83..20a25ce3b 100644 --- a/include/zot.php +++ b/include/zot.php @@ -2956,6 +2956,8 @@ function build_sync_packet($uid = 0, $packet = null, $groups_changed = false) { return; $channel = $r[0]; + unset($channel['channel_password']); + unset($channel['channel_salt']); translate_channel_perms_outbound($channel); if($packet && array_key_exists('abook',$packet) && $packet['abook']) { -- cgit v1.2.3 From 397fef519c7929c70636c50015f7a0389062bab5 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Tue, 18 Apr 2017 21:18:49 -0700 Subject: give the item_obscured flag a new lease on life by using it to designate third party client-side e2ee or binary content which can only be downloaded and not viewed directly on the web (as a side effect this also allows binary files to be submitted as activities/content). The content display is suppressed and replaced with a download button. This is unfinished but harmless to backport while work is in progress unless told otherwise. Future development will take care of the remaining loose ends. --- include/conversation.php | 8 -------- include/text.php | 18 +++++++++++++++++- 2 files changed, 17 insertions(+), 9 deletions(-) (limited to 'include') diff --git a/include/conversation.php b/include/conversation.php index 5b2d60583..93a6d7406 100644 --- a/include/conversation.php +++ b/include/conversation.php @@ -353,14 +353,6 @@ function localize_item(&$item){ } */ - // if item body was obscured and we changed it, re-obscure it - // FIXME - we need a better filter than just the string 'data'; try and - // match the fact that it's json encoded - - if(intval($item['item_obscured']) - && strlen($item['body']) && (! strpos($item['body'],'data'))) { - $item['body'] = z_obscure($item['body']); - } } diff --git a/include/text.php b/include/text.php index bbf0b5b98..d276595ae 100644 --- a/include/text.php +++ b/include/text.php @@ -1570,7 +1570,12 @@ function prepare_body(&$item,$attach = false) { } } - $s .= prepare_text($item['body'],$item['mimetype'], false); + if($item['item_obscured']) { + $s .= prepare_binary($item); + } + else { + $s .= prepare_text($item['body'],$item['mimetype'], false); + } $event = (($item['obj_type'] === ACTIVITY_OBJ_EVENT) ? format_event_obj($item['obj']) : false); @@ -1633,6 +1638,17 @@ function prepare_body(&$item,$attach = false) { return $prep_arr; } + +function prepare_binary($item) { + return replace_macros(get_markup_template('item_binary.tpl'), [ + '$download' => t('Download binary/encrypted content'), + '$url' => z_root() . '/viewsrc/' . $item['id'] . '/download' + ]); +} + + + + /** * @brief Given a text string, convert from bbcode to html and add smilie icons. * -- cgit v1.2.3 From 1c6d2857cb6978ca7b87a0564013aa2b39024e96 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Wed, 19 Apr 2017 17:52:15 -0700 Subject: follow_from_feed issue when called from push --- include/feedutils.php | 2 +- include/follow.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'include') diff --git a/include/feedutils.php b/include/feedutils.php index a5161dc6e..03eb1f256 100644 --- a/include/feedutils.php +++ b/include/feedutils.php @@ -946,7 +946,7 @@ function consume_feed($xml, $importer, &$contact, $pass = 0) { $datarray['author_xchan'] = ''; if(activity_match($datarray['verb'],ACTIVITY_FOLLOW) && $datarray['obj_type'] === ACTIVITY_OBJ_PERSON) { - $cb = array('item' => $datarray,'channel' => $importer, 'xchan' => null, 'author' => $author, 'caught' => false); + $cb = array('item' => $datarray,'channel' => $importer, 'xchan' => [ 'placeholder' => '' ], 'author' => $author, 'caught' => false); call_hooks('follow_from_feed',$cb); if($cb['caught']) { if($cb['return_code']) diff --git a/include/follow.php b/include/follow.php index 751d86db1..0d7c16aa3 100644 --- a/include/follow.php +++ b/include/follow.php @@ -49,7 +49,7 @@ function new_contact($uid,$url,$channel,$interactive = false, $confirm = false) $arr = array('url' => $url, 'channel' => array()); - call_hooks('follow', $arr); + call_hooks('follow_init', $arr); if($arr['channel']['success']) $ret = $arr['channel']; -- cgit v1.2.3 From f52c670c05b01610f60e736c44c81e5b6f9f7ceb Mon Sep 17 00:00:00 2001 From: zotlabs Date: Wed, 19 Apr 2017 20:48:10 -0700 Subject: support reverse magic-auth in oembed requests. --- include/oembed.php | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'include') diff --git a/include/oembed.php b/include/oembed.php index aac7d15b4..5865c95d5 100755 --- a/include/oembed.php +++ b/include/oembed.php @@ -149,7 +149,14 @@ function oembed_fetch_url($embedurl){ if ($action !== 'block') { // try oembed autodiscovery $redirects = 0; - $result = z_fetch_url($furl, false, $redirects, array('timeout' => 30, 'accept_content' => "text/*", 'novalidate' => true )); + $result = z_fetch_url($furl, false, $redirects, + [ + 'timeout' => 30, + 'accept_content' => "text/*", + 'novalidate' => true, + 'session' => ((local_channel() && $zrl) ? true : false) + ] + ); if($result['success']) $html_text = $result['body']; @@ -200,7 +207,7 @@ function oembed_fetch_url($embedurl){ if ($txt[0]!="{") $txt='{"type":"error"}'; - //save in cache + // save in cache if(! get_config('system','oembed_cache_disable')) Zlib\Cache::set('[' . App::$videowidth . '] ' . $furl, $txt); -- cgit v1.2.3 From 94f15e355166f0abd3698414948abff2397a7ad0 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Thu, 20 Apr 2017 20:19:15 -0700 Subject: The rest of the library and backend changes to support client-side e2ee and deprecate previous uses of item_obscured. --- include/items.php | 35 +++++++++-------------------------- include/text.php | 15 +-------------- 2 files changed, 10 insertions(+), 40 deletions(-) (limited to 'include') diff --git a/include/items.php b/include/items.php index f290b5ec1..c71e8011d 100755 --- a/include/items.php +++ b/include/items.php @@ -605,6 +605,9 @@ function get_item_elements($x,$allow_code = false) { if(in_array('notshown',$x['flags'])) $arr['item_notshown'] = 1; + if(in_array('obscured',$x['flags'])) + $arr['item_obscured'] = 1; + // hidden item are no longer propagated - notshown may be a suitable alternative if(in_array('hidden',$x['flags'])) @@ -707,7 +710,7 @@ function get_item_elements($x,$allow_code = false) { // local only $arr['item_relay'] = $x['item_relay']; $arr['item_mentionsme'] = $x['item_mentionsme']; $arr['item_nocomment'] = $x['item_nocomment']; - // local only $arr['item_obscured'] = $x['item_obscured']; + $arr['item_obscured'] = $x['item_obscured']; // local only $arr['item_verified'] = $x['item_verified']; $arr['item_retained'] = $x['item_retained']; $arr['item_rss'] = $x['item_rss']; @@ -955,13 +958,6 @@ function encode_item($item,$mirror = false) { $key = get_config('system','prvkey'); - if(array_key_exists('item_obscured',$item) && intval($item['item_obscured'])) { - if($item['title']) - $item['title'] = crypto_unencapsulate(json_decode($item['title'],true),$key); - if($item['body']) - $item['body'] = crypto_unencapsulate(json_decode($item['body'],true),$key); - } - // If we're trying to backup an item so that it's recoverable or for export/imprt, // add all the attributes we need to recover it @@ -1309,7 +1305,9 @@ function encode_item_flags($item) { $ret[] = 'nsfw'; if(intval($item['item_consensus'])) $ret[] = 'consensus'; - if(intval($item['item_private'])) + if(intval($item['item_obscured'])) + $ret[] = 'obscured'; + if(intval($item['item_privat'])) $ret[] = 'private'; return $ret; @@ -2479,15 +2477,7 @@ function tag_deliver($uid, $item_id) { // Now let's check if this mention was inside a reshare so we don't spam a forum // If it's private we may have to unobscure it momentarily so that we can parse it. - $body = ''; - - if(intval($item['item_obscured'])) { - $key = get_config('system','prvkey'); - if($item['body']) - $body = crypto_unencapsulate(json_decode($item['body'],true),$key); - } - else - $body = $item['body']; + $body = $item['body']; $body = preg_replace('/\[share(.*?)\[\/share\]/','',$body); @@ -2638,11 +2628,6 @@ function tgroup_check($uid,$item) { $body = $item['body']; - if(array_key_exists('item_obscured',$item) && intval($item['item_obscured']) && $body) { - $key = get_config('system','prvkey'); - $body = crypto_unencapsulate(json_decode($body,true),$key); - } - $body = preg_replace('/\[share(.*?)\[\/share\]/','',$body); // $pattern = '/@\!?\[zrl\=' . preg_quote($term['url'],'/') . '\]' . preg_quote($term['term'] . '+','/') . '\[\/zrl\]/'; @@ -2736,7 +2721,6 @@ function start_delivery_chain($channel, $item, $item_id, $parent) { $item_origin = 1; $item_uplink = 0; $item_nocomment = 0; - $item_obscured = 0; $flag_bits = $item['item_flags']; @@ -2759,11 +2743,10 @@ function start_delivery_chain($channel, $item, $item_id, $parent) { $title = $item['title']; $body = $item['body']; - $r = q("update item set item_uplink = %d, item_nocomment = %d, item_obscured = %d, item_flags = %d, owner_xchan = '%s', allow_cid = '%s', allow_gid = '%s', + $r = q("update item set item_uplink = %d, item_nocomment = %d, item_flags = %d, owner_xchan = '%s', allow_cid = '%s', allow_gid = '%s', deny_cid = '%s', deny_gid = '%s', item_private = %d, public_policy = '%s', comment_policy = '%s', title = '%s', body = '%s', item_wall = %d, item_origin = %d where id = %d", intval($item_uplink), intval($item_nocomment), - intval($item_obscured), intval($flag_bits), dbesc($channel['channel_hash']), dbesc($channel['channel_allow_cid']), diff --git a/include/text.php b/include/text.php index d276595ae..1a4e2b223 100644 --- a/include/text.php +++ b/include/text.php @@ -1372,20 +1372,7 @@ function link_compare($a, $b) { function unobscure(&$item) { - if(array_key_exists('item_obscured',$item) && intval($item['item_obscured'])) { - $key = get_config('system','prvkey'); - if($item['title']) - $item['title'] = crypto_unencapsulate(json_decode($item['title'],true),$key); - if($item['body']) - $item['body'] = crypto_unencapsulate(json_decode($item['body'],true),$key); - if(get_config('system','item_cache')) { - q("update item set title = '%s', body = '%s', item_obscured = 0 where id = %d", - dbesc($item['title']), - dbesc($item['body']), - intval($item['id']) - ); - } - } + return; } function unobscure_mail(&$item) { -- cgit v1.2.3 From 02ea713d6a12b767250eba12918018bb72cf4e38 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Thu, 20 Apr 2017 21:25:37 -0700 Subject: make it easier to hook into feed headers in the future --- include/feedutils.php | 34 ++++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-) (limited to 'include') diff --git a/include/feedutils.php b/include/feedutils.php index 03eb1f256..079d57072 100644 --- a/include/feedutils.php +++ b/include/feedutils.php @@ -63,7 +63,7 @@ function get_public_feed($channel, $params) { */ function get_feed_for($channel, $observer_hash, $params) { - if(! channel) + if(! $channel) http_status_exit(401); if($params['pages']) { @@ -73,19 +73,6 @@ function get_feed_for($channel, $observer_hash, $params) { if(! perm_is_allowed($channel['channel_id'],$observer_hash,'view_stream')) http_status_exit(403); } - $items = items_fetch(array( - 'wall' => '1', - 'datequery' => $params['end'], - 'datequery2' => $params['begin'], - 'start' => $params['start'], // FIXME - 'records' => $params['records'], // FIXME - 'direction' => $params['direction'], // FIXME - 'pages' => $params['pages'], - 'order' => 'post', - 'top' => $params['top'], - 'cat' => $params['cat'] - ), $channel, $observer_hash, CLIENT_MODE_NORMAL, App::$module); - $feed_template = get_markup_template('atom_feed.tpl'); @@ -112,8 +99,27 @@ function get_feed_for($channel, $observer_hash, $params) { )); + $x = [ 'xml' => $atom, 'channel' => $channel, 'observer_hash' => $observer_hash, 'params' => $params ]; + call_hooks('atom_feed_top',$x); + + $atom = $x['xml']; + + // a much simpler interface call_hooks('atom_feed', $atom); + $items = items_fetch(array( + 'wall' => '1', + 'datequery' => $params['end'], + 'datequery2' => $params['begin'], + 'start' => $params['start'], // FIXME + 'records' => $params['records'], // FIXME + 'direction' => $params['direction'], // FIXME + 'pages' => $params['pages'], + 'order' => 'post', + 'top' => $params['top'], + 'cat' => $params['cat'] + ), $channel, $observer_hash, CLIENT_MODE_NORMAL, App::$module); + if($items) { $type = 'html'; foreach($items as $item) { -- cgit v1.2.3 From f1c6fd08c462b663a26cf58cfd81591129057c41 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Sun, 23 Apr 2017 20:28:04 -0700 Subject: database upgrade --- include/items.php | 5 +---- include/text.php | 2 +- 2 files changed, 2 insertions(+), 5 deletions(-) (limited to 'include') diff --git a/include/items.php b/include/items.php index c71e8011d..a4862208e 100755 --- a/include/items.php +++ b/include/items.php @@ -4263,10 +4263,7 @@ function sync_an_item($channel_id,$item_id) { if($r) { xchan_query($r); $sync_item = fetch_post_tags($r); - $rid = q("select * from item_id where iid = %d", - intval($item_id) - ); - build_sync_packet($channel_d,array('item' => array(encode_item($sync_item[0],true)),'item_id' => $rid)); + build_sync_packet($channel_d,array('item' => array(encode_item($sync_item[0],true)))); } } diff --git a/include/text.php b/include/text.php index 1a4e2b223..d9ee40fa9 100644 --- a/include/text.php +++ b/include/text.php @@ -2930,7 +2930,7 @@ function pdl_selector($uid, $current='') { $sql_extra = item_permissions_sql($uid); - $r = q("select iconfig.*, mid from item_id left join item on iconfig.iid = item.id + $r = q("select iconfig.*, mid from iconfig left join item on iconfig.iid = item.id where item.uid = %d and iconfig.cat = 'system' and iconfig.k = 'PDL' $sql_extra order by v asc", intval($uid) ); -- cgit v1.2.3 From a342a5f8e062bf3b1d8cfebaaa64214c7dae49cb Mon Sep 17 00:00:00 2001 From: zotlabs Date: Tue, 25 Apr 2017 16:36:37 -0700 Subject: smilies - add param to only list default emoticons --- include/text.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'include') diff --git a/include/text.php b/include/text.php index d9ee40fa9..14a60f060 100644 --- a/include/text.php +++ b/include/text.php @@ -1166,7 +1166,7 @@ function get_mood_verbs() { * * @return Returns array with keys 'texts' and 'icons' */ -function list_smilies() { +function list_smilies($default_only = false) { $texts = array( '<3', @@ -1240,10 +1240,15 @@ function list_smilies() { ); $params = array('texts' => $texts, 'icons' => $icons); + + if($default_only) + return $params; + call_hooks('smilie', $params); return $params; } + /** * @brief Replaces text emoticons with graphical images. * -- cgit v1.2.3 From b88be137ca68c6b52e13ce1738fbc55651f37138 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Tue, 25 Apr 2017 20:48:38 -0700 Subject: provide a broken feed for services which require a broken feed --- include/feedutils.php | 73 ++++++++++++++++++++++++++++----------------------- include/items.php | 4 +++ 2 files changed, 44 insertions(+), 33 deletions(-) (limited to 'include') diff --git a/include/feedutils.php b/include/feedutils.php index 079d57072..36ab75287 100644 --- a/include/feedutils.php +++ b/include/feedutils.php @@ -22,24 +22,20 @@ function get_public_feed($channel, $params) { */ if(! $params) - $params = array(); + $params = []; - $params['type'] = ((x($params,'type')) ? $params['type'] : 'xml'); - $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); - $params['direction'] = ((x($params,'direction')) ? $params['direction'] : 'desc'); - $params['pages'] = ((x($params,'pages')) ? intval($params['pages']) : 0); - $params['top'] = ((x($params,'top')) ? intval($params['top']) : 0); - $params['cat'] = ((x($params,'cat')) ? $params['cat'] : ''); + $params['type'] = ((x($params,'type')) ? $params['type'] : 'xml'); + $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); + $params['direction'] = ((x($params,'direction'))? $params['direction'] : 'desc'); + $params['pages'] = ((x($params,'pages')) ? intval($params['pages']) : 0); + $params['top'] = ((x($params,'top')) ? intval($params['top']) : 0); + $params['cat'] = ((x($params,'cat')) ? $params['cat'] : ''); + $params['compat'] = ((x($params,'compat')) ? intval($params['compat']) : 0); - // put a sane lower limit on feed requests if not specified - -// if($params['begin'] <= NULL_DATE) -// $params['begin'] = datetime_convert('UTC','UTC','now - 1 month'); - switch($params['type']) { case 'json': header("Content-type: application/atom+json"); @@ -61,6 +57,7 @@ function get_public_feed($channel, $params) { * @param array $params * @return string with an atom feed */ + function get_feed_for($channel, $observer_hash, $params) { if(! $channel) @@ -74,18 +71,24 @@ function get_feed_for($channel, $observer_hash, $params) { http_status_exit(403); } + // logger('params: ' . print_r($params,true)); + $feed_template = get_markup_template('atom_feed.tpl'); $atom = ''; + $feed_author = ''; + if(intval($params['compat']) === 1) { + $feed_author = atom_author('author',$channel['channel_address'],$channel['xchan_url'],300,300,$channel['xchan_photo_mimetype'],$channel['xchan_photo_l']); + } + $atom .= replace_macros($feed_template, array( '$version' => xmlify(Zotlabs\Lib\System::get_project_version()), '$red' => xmlify(Zotlabs\Lib\System::get_platform_name()), '$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']), + '$author' => $feed_author, '$name' => xmlify($channel['channel_name']), '$profile_page' => xmlify($channel['xchan_url']), '$mimephoto' => xmlify($channel['xchan_photo_mimetype']), @@ -107,18 +110,21 @@ function get_feed_for($channel, $observer_hash, $params) { // a much simpler interface call_hooks('atom_feed', $atom); - $items = items_fetch(array( - 'wall' => '1', - 'datequery' => $params['end'], - 'datequery2' => $params['begin'], - 'start' => $params['start'], // FIXME - 'records' => $params['records'], // FIXME - 'direction' => $params['direction'], // FIXME - 'pages' => $params['pages'], - 'order' => 'post', - 'top' => $params['top'], - 'cat' => $params['cat'] - ), $channel, $observer_hash, CLIENT_MODE_NORMAL, App::$module); + $items = items_fetch( + [ + 'wall' => '1', + 'datequery' => $params['end'], + 'datequery2' => $params['begin'], + 'start' => intval($params['start']), + 'records' => intval($params['records']), + 'direction' => dbesc($params['direction']), + 'pages' => $params['pages'], + 'order' => dbesc('post'), + 'top' => $params['top'], + 'cat' => $params['cat'], + 'compat' => $params['compat'] + ], $channel, $observer_hash, CLIENT_MODE_NORMAL, App::$module + ); if($items) { $type = 'html'; @@ -1247,10 +1253,11 @@ function atom_author($tag, $name, $uri, $h, $w, $type, $photo) { $photo = xmlify($photo); $o .= "<$tag>\r\n"; - $o .= "$name\r\n"; - $o .= "$uri\r\n"; - $o .= '' . "\r\n"; - $o .= '' . "\r\n"; + $o .= " $uri\r\n"; + $o .= " $name\r\n"; + $o .= " $uri\r\n"; + $o .= ' ' . "\r\n"; + $o .= ' ' . "\r\n"; call_hooks('atom_author', $o); diff --git a/include/items.php b/include/items.php index a4862208e..1f79ee567 100755 --- a/include/items.php +++ b/include/items.php @@ -3885,6 +3885,10 @@ function items_fetch($arr,$channel = null,$observer_hash = null,$client_mode = C } } + if(intval($arr['compat']) === 1) { + $sql_extra = " AND author_xchan = owner_xchan and item_wall = 1 and item_private = 0 "; + } + if ($arr['datequery']) { $sql_extra3 .= protect_sprintf(sprintf(" AND item.created <= '%s' ", dbesc(datetime_convert('UTC','UTC',$arr['datequery'])))); } -- cgit v1.2.3 From e8ea8d203db5bdf62995f1831b1503ac11556435 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Wed, 26 Apr 2017 23:05:30 -0700 Subject: more client-side mail privacy work --- include/items.php | 15 +++++++++++++-- include/message.php | 19 +++++++++++++++---- 2 files changed, 28 insertions(+), 6 deletions(-) (limited to 'include') diff --git a/include/items.php b/include/items.php index 1f79ee567..7cad3b168 100755 --- a/include/items.php +++ b/include/items.php @@ -1333,6 +1333,8 @@ function encode_mail($item,$extended = false) { $x['body'] = $item['body']; $x['from'] = encode_item_xchan($item['from']); $x['to'] = encode_item_xchan($item['to']); + $x['raw'] = $item['mail_raw']; + $x['mimetype'] = $item['mail_mimetype']; if($item['attach']) $x['attach'] = json_decode($item['attach'],true); @@ -1366,9 +1368,16 @@ function get_mail_elements($x) { $arr = array(); - $arr['body'] = (($x['body']) ? htmlspecialchars($x['body'], ENT_COMPAT,'UTF-8',false) : ''); - $arr['title'] = (($x['title'])? htmlspecialchars($x['title'],ENT_COMPAT,'UTF-8',false) : ''); + if(intval($x['raw'])) { + $arr['mail_raw'] = intval($x['raw']); + $arr['body'] = $x['body']; + } + else { + $arr['body'] = (($x['body']) ? htmlspecialchars($x['body'], ENT_COMPAT,'UTF-8',false) : ''); + } + $arr['title'] = (($x['title'])? htmlspecialchars($x['title'],ENT_COMPAT,'UTF-8',false) : ''); + $arr['mail_mimetype'] = (($x['mimetype']) ? htmlspecialchars($x['mimetype'],ENT_COMPAT,'UTF-8',false) : 'text/bbcode'); $arr['conv_guid'] = (($x['conv_guid'])? htmlspecialchars($x['conv_guid'],ENT_COMPAT,'UTF-8',false) : ''); $arr['created'] = datetime_convert('UTC','UTC',$x['created']); @@ -2949,8 +2958,10 @@ function mail_store($arr) { $arr['parent_mid'] = ((x($arr,'parent_mid')) ? notags(trim($arr['parent_mid'])) : ''); $arr['body'] = ((x($arr,'body')) ? trim($arr['body']) : ''); $arr['conv_guid'] = ((x($arr,'conv_guid')) ? trim($arr['conv_guid']) : ''); + $arr['mail_mimetype'] = ((x($arr,'mail_mimetype')) ? trim($arr['mail_mimetype']) : 'text/bbcode'); $arr['mail_flags'] = ((x($arr,'mail_flags')) ? intval($arr['mail_flags']) : 0 ); + $arr['mail_raw'] = ((x($arr,'mail_raw')) ? intval($arr['mail_raw']) : 0 ); if(! $arr['parent_mid']) { logger('mail_store: missing parent'); diff --git a/include/message.php b/include/message.php index e7db98d7e..fd9c6ece1 100644 --- a/include/message.php +++ b/include/message.php @@ -5,10 +5,20 @@ require_once('include/crypto.php'); require_once('include/attach.php'); + +function mail_prepare_binary($item) { + + return replace_macros(get_markup_template('item_binary.tpl'), [ + '$download' => t('Download binary/encrypted content'), + '$url' => z_root() . '/mail/' . $item['id'] . '/download' + ]); +} + + // send a private message -function send_message($uid = 0, $recipient = '', $body = '', $subject = '', $replyto = '', $expires = NULL_DATE) { +function send_message($uid = 0, $recipient = '', $body = '', $subject = '', $replyto = '', $expires = NULL_DATE, $mimetype = 'text/bbcode', $raw = false) { $ret = array('success' => false); $is_reply = false; @@ -190,8 +200,8 @@ function send_message($uid = 0, $recipient = '', $body = '', $subject = '', $rep $sig = ''; // placeholder $mimetype = ''; //placeholder - $r = q("INSERT INTO mail ( account_id, conv_guid, mail_obscured, channel_id, from_xchan, to_xchan, mail_mimetype, title, body, sig, attach, mid, parent_mid, created, expires, mail_isreply ) - VALUES ( %d, '%s', %d, %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d )", + $r = q("INSERT INTO mail ( account_id, conv_guid, mail_obscured, channel_id, from_xchan, to_xchan, mail_mimetype, title, body, sig, attach, mid, parent_mid, created, expires, mail_isreply, mail_raw ) + VALUES ( %d, '%s', %d, %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d, %d )", intval($channel['channel_account_id']), dbesc($conv_guid), intval(1), @@ -207,7 +217,8 @@ function send_message($uid = 0, $recipient = '', $body = '', $subject = '', $rep dbesc($replyto), dbesc(datetime_convert()), dbescdate($expires), - intval($is_reply) + intval($is_reply), + intval($raw) ); // verify the save -- cgit v1.2.3 From 89e7e5e4fbafa9bac7263513315f89cfe7ac02fb Mon Sep 17 00:00:00 2001 From: zotlabs Date: Thu, 27 Apr 2017 20:08:38 -0700 Subject: make mail_store() safe for postgres or mysql5.7 - although this interface needs to be refactored in the future --- include/items.php | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'include') diff --git a/include/items.php b/include/items.php index 7cad3b168..30aa30048 100755 --- a/include/items.php +++ b/include/items.php @@ -2945,8 +2945,14 @@ function mail_store($arr) { $arr['body'] = escape_tags($arr['body']); } - if(array_key_exists('attach',$arr) && is_array($arr['attach'])) - $arr['attach'] = json_encode($arr['attach']); + if(array_key_exists('attach',$arr)) { + if(is_array($arr['attach'])) { + $arr['attach'] = json_encode($arr['attach']); + } + } + else { + $arr['attach'] = ''; + } $arr['account_id'] = ((x($arr,'account_id')) ? intval($arr['account_id']) : 0); $arr['mid'] = ((x($arr,'mid')) ? notags(trim($arr['mid'])) : random_string()); @@ -2957,6 +2963,7 @@ function mail_store($arr) { $arr['title'] = ((x($arr,'title')) ? trim($arr['title']) : ''); $arr['parent_mid'] = ((x($arr,'parent_mid')) ? notags(trim($arr['parent_mid'])) : ''); $arr['body'] = ((x($arr,'body')) ? trim($arr['body']) : ''); + $arr['sig'] = ((x($arr,'sig')) ? trim($arr['sig']) : ''); $arr['conv_guid'] = ((x($arr,'conv_guid')) ? trim($arr['conv_guid']) : ''); $arr['mail_mimetype'] = ((x($arr,'mail_mimetype')) ? trim($arr['mail_mimetype']) : 'text/bbcode'); -- cgit v1.2.3 From 70e17f91940cb7347d59a6b0d0f59facc2c3ce5c Mon Sep 17 00:00:00 2001 From: zotlabs Date: Thu, 27 Apr 2017 20:22:28 -0700 Subject: more work client mail crypto --- include/message.php | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) (limited to 'include') diff --git a/include/message.php b/include/message.php index fd9c6ece1..261a6a673 100644 --- a/include/message.php +++ b/include/message.php @@ -45,13 +45,15 @@ function send_message($uid = 0, $recipient = '', $body = '', $subject = '', $rep $body = cleanup_bbcode($body); $results = linkify_tags($a, $body, $uid); - - if(preg_match_all("/\[attachment\](.*?)\[\/attachment\]/",((strpos($body,'[/crypt]')) ? $_POST['media_str'] : $body),$match)) - $attaches = $match[1]; + if(! $raw) { + if(preg_match_all("/\[attachment\](.*?)\[\/attachment\]/",((strpos($body,'[/crypt]')) ? $_POST['media_str'] : $body),$match)) { + $attaches = $match[1]; + } + } $attachments = ''; - if(preg_match_all('/(\[attachment\](.*?)\[\/attachment\])/',$body,$match)) { + if((! $raw) && preg_match_all('/(\[attachment\](.*?)\[\/attachment\])/',$body,$match)) { $attachments = array(); foreach($match[2] as $mtch) { $hash = substr($mtch,0,strpos($mtch,',')); @@ -194,7 +196,7 @@ function send_message($uid = 0, $recipient = '', $body = '', $subject = '', $rep if($subject) $subject = str_rot47(base64url_encode($subject)); - if($body) + if(($body )&& (! $raw)) $body = str_rot47(base64url_encode($body)); $sig = ''; // placeholder @@ -364,6 +366,9 @@ function private_messages_list($uid, $mailbox = '', $start = 0, $numitems = 0) { if($r[$k]['body']) $r[$k]['body'] = base64url_decode(str_rot47($r[$k]['body'])); } + if($r[$k]['mail_raw']) + $r[$k]['body'] = mail_prepare_binary([ 'id' => $r[$k]['id'] ]); + } return $r; @@ -402,6 +407,8 @@ function private_messages_fetch_message($channel_id, $messageitem_id, $updatesee if($messages[$k]['body']) $messages[$k]['body'] = base64url_decode(str_rot47($messages[$k]['body'])); } + if($messages[$k]['mail_raw']) + $messages[$k]['body'] = mail_prepare_binary([ 'id' => $messages[$k]['id'] ]); } @@ -525,6 +532,9 @@ function private_messages_fetch_conversation($channel_id, $messageitem_id, $upda if($messages[$k]['body']) $messages[$k]['body'] = base64url_decode(str_rot47($messages[$k]['body'])); } + if($messages[$k]['mail_raw']) + $messages[$k]['body'] = mail_prepare_binary([ 'id' => $messages[$k]['id'] ]); + } -- cgit v1.2.3 From 033cf6138071c1707b3bb448524761f086b8a445 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Thu, 27 Apr 2017 22:37:51 -0700 Subject: profile_tabs is now channel_apps (except the original was left behind as the gitwiki addon still uses it). A couple of things were modernised but basic functionality is the same as the latest revisions to the original. --- include/nav.php | 173 +++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 171 insertions(+), 2 deletions(-) (limited to 'include') diff --git a/include/nav.php b/include/nav.php index 2d12f2950..fecf28548 100644 --- a/include/nav.php +++ b/include/nav.php @@ -2,6 +2,10 @@ use \Zotlabs\Lib as Zlib; +require_once('include/security.php'); +require_once('include/menu.php'); + + function nav() { /** @@ -38,8 +42,8 @@ EOT; $observer = App::get_observer(); require_once('include/conversation.php'); - $is_owner = (((local_channel()) && (\App::$profile['profile_uid'] == local_channel())) ? true : false); - $navapps[] = profile_tabs($a, $is_owner, \App::$profile['channel_address']); + $is_owner = (((local_channel()) && (App::$profile['profile_uid'] == local_channel())) ? true : false); + $navapps[] = channel_apps($is_owner, App::$profile['channel_address']); $myident = (($channel) ? $channel['xchan_addr'] : ''); @@ -312,3 +316,168 @@ function nav_set_selected($item){ ); App::$nav_sel[$item] = 'active'; } + + + +function channel_apps($is_owner = false, $nickname = null) { + + // Don't provide any channel apps if we're running as the sys channel + + if(App::$is_sys) + return ''; + + if(! get_pconfig($uid, 'system', 'channelapps','1')) + return ''; + + $channel = App::get_channel(); + + if($channel && is_null($nickname)) + $nickname = $channel['channel_address']; + + $uid = ((App::$profile['profile_uid']) ? App::$profile['profile_uid'] : local_channel()); + $account_id = ((App::$profile['profile_uid']) ? App::$profile['channel_account_id'] : App::$channel['channel_account_id']); + + if($uid == local_channel()) { + return; + } + else { + $cal_link = '/cal/' . $nickname; + } + + $sql_options = item_permissions_sql($uid); + + $r = q("select item.* from item left join iconfig on item.id = iconfig.iid + where item.uid = %d and iconfig.cat = 'system' and iconfig.v = '%s' + and item.item_delayed = 0 and item.item_deleted = 0 + and ( iconfig.k = 'WEBPAGE' and item_type = %d ) + $sql_options limit 1", + intval($uid), + dbesc('home'), + intval(ITEM_TYPE_WEBPAGE) + ); + + $has_webpages = (($r) ? true : false); + + if(x($_GET, 'tab')) + $tab = notags(trim($_GET['tab'])); + + $url = z_root() . '/channel/' . $nickname; + $pr = z_root() . '/profile/' . $nickname; + + $tabs = [ + [ + 'label' => t('Channel'), + 'url' => $url, + 'sel' => ((argv(0) == 'channel') ? 'active' : ''), + 'title' => t('Status Messages and Posts'), + 'id' => 'status-tab', + 'icon' => 'home' + ], + ]; + + $p = get_all_perms($uid,get_observer_hash()); + + if ($p['view_profile']) { + $tabs[] = [ + 'label' => t('About'), + 'url' => $pr, + 'sel' => ((argv(0) == 'profile') ? 'active' : ''), + 'title' => t('Profile Details'), + 'id' => 'profile-tab', + 'icon' => 'user' + ]; + } + if ($p['view_storage']) { + $tabs[] = [ + 'label' => t('Photos'), + 'url' => z_root() . '/photos/' . $nickname, + 'sel' => ((argv(0) == 'photos') ? 'active' : ''), + 'title' => t('Photo Albums'), + 'id' => 'photo-tab', + 'icon' => 'photo' + ]; + $tabs[] = [ + 'label' => t('Files'), + 'url' => z_root() . '/cloud/' . $nickname, + 'sel' => ((argv(0) == 'cloud' || argv(0) == 'sharedwithme') ? 'active' : ''), + 'title' => t('Files and Storage'), + 'id' => 'files-tab', + 'icon' => 'folder-open' + ]; + } + + if($p['view_stream'] && $cal_link) { + $tabs[] = [ + 'label' => t('Events'), + 'url' => z_root() . $cal_link, + 'sel' => ((argv(0) == 'cal' || argv(0) == 'events') ? 'active' : ''), + 'title' => t('Events'), + 'id' => 'event-tab', + 'icon' => 'calendar' + ]; + } + + + if ($p['chat'] && feature_enabled($uid,'ajaxchat')) { + $has_chats = ZLib\Chatroom::list_count($uid); + if ($has_chats) { + $tabs[] = [ + 'label' => t('Chatrooms'), + 'url' => z_root() . '/chat/' . $nickname, + 'sel' => ((argv(0) == 'chat') ? 'active' : '' ), + 'title' => t('Chatrooms'), + 'id' => 'chat-tab', + 'icon' => 'comments-o' + ]; + } + } + + $has_bookmarks = menu_list_count(local_channel(),'',MENU_BOOKMARK) + menu_list_count(local_channel(),'',MENU_SYSTEM|MENU_BOOKMARK); + if ($is_owner && $has_bookmarks) { + $tabs[] = [ + 'label' => t('Bookmarks'), + 'url' => z_root() . '/bookmarks', + 'sel' => ((argv(0) == 'bookmarks') ? 'active' : ''), + 'title' => t('Saved Bookmarks'), + 'id' => 'bookmarks-tab', + 'icon' => 'bookmark' + ]; + } + + if($has_webpages && feature_enabled($uid,'webpages')) { + $tabs[] = [ + 'label' => t('Webpages'), + 'url' => z_root() . '/page/' . $nickname . '/home', + 'sel' => ((argv(0) == 'webpages') ? 'active' : ''), + 'title' => t('View Webpages'), + 'id' => 'webpages-tab', + 'icon' => 'newspaper-o' + ]; + } + + + if ($p['view_wiki']) { + if(feature_enabled($uid,'wiki') && (get_account_techlevel($account_id) > 3)) { + $tabs[] = [ + 'label' => t('Wikis'), + 'url' => z_root() . '/wiki/' . $nickname, + 'sel' => ((argv(0) == 'wiki') ? 'active' : ''), + 'title' => t('Wiki'), + 'id' => 'wiki-tab', + 'icon' => 'pencil-square-o' + ]; + } + } + + $arr = array('is_owner' => $is_owner, 'nickname' => $nickname, 'tab' => (($tab) ? $tab : false), 'tabs' => $tabs); + call_hooks('profile_tabs', $arr); + call_hooks('channel_apps', $arr); + + return replace_macros(get_markup_template('profile_tabs.tpl'), + [ + '$tabs' => $arr['tabs'], + '$name' => App::$profile['channel_name'], + '$thumb' => App::$profile['thumb'] + ] + ); +} \ No newline at end of file -- cgit v1.2.3 From 230617208ba4ba81a7c9a289ba44da7319500397 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Sat, 29 Apr 2017 16:30:11 -0700 Subject: more work on client side e2ee --- include/message.php | 5 ----- 1 file changed, 5 deletions(-) (limited to 'include') diff --git a/include/message.php b/include/message.php index 261a6a673..61c3e8afd 100644 --- a/include/message.php +++ b/include/message.php @@ -366,9 +366,6 @@ function private_messages_list($uid, $mailbox = '', $start = 0, $numitems = 0) { if($r[$k]['body']) $r[$k]['body'] = base64url_decode(str_rot47($r[$k]['body'])); } - if($r[$k]['mail_raw']) - $r[$k]['body'] = mail_prepare_binary([ 'id' => $r[$k]['id'] ]); - } return $r; @@ -407,8 +404,6 @@ function private_messages_fetch_message($channel_id, $messageitem_id, $updatesee if($messages[$k]['body']) $messages[$k]['body'] = base64url_decode(str_rot47($messages[$k]['body'])); } - if($messages[$k]['mail_raw']) - $messages[$k]['body'] = mail_prepare_binary([ 'id' => $messages[$k]['id'] ]); } -- cgit v1.2.3 From c845d20352300e2b8a6133bbf3fe270807ba0856 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Sun, 30 Apr 2017 16:03:01 -0700 Subject: ugly postgres fixes --- include/security.php | 56 +++++++++++++++++++++++++++++++--------------------- 1 file changed, 34 insertions(+), 22 deletions(-) (limited to 'include') diff --git a/include/security.php b/include/security.php index b49ceec0d..ddbb3d806 100644 --- a/include/security.php +++ b/include/security.php @@ -597,18 +597,24 @@ function stream_perms_api_uids($perms = NULL, $limit = 0, $rand = 0 ) { $random_sql = (($rand) ? " ORDER BY " . db_getfunc('RAND') . " " : ''); if(local_channel()) $ret[] = local_channel(); - $x = q("select uid from pconfig where cat = 'perm_limits' and k = 'view_stream' and ( v & %d ) > 0 ", - intval($perms) - ); + $x = q("select uid, v from pconfig where cat = 'perm_limits' and k = 'view_stream' "); if($x) { - $ids = ids_to_querystr($x,'uid'); - $r = q("select channel_id from channel where channel_id in ( $ids ) and ( channel_pageflags & %d ) = 0 and channel_system = 0 and channel_removed = 0 $random_sql $limit_sql ", - intval(PAGE_ADULT|PAGE_CENSORED) - ); - if($r) { - foreach($r as $rr) - if(! in_array($rr['channel_id'], $ret)) - $ret[] = $rr['channel_id']; + $y = []; + foreach($x as $xv) { + if(intval($xv['v']) & $perms) { + $y[] = $xv; + } + } + if($y) { + $ids = ids_to_querystr($y,'uid'); + $r = q("select channel_id from channel where channel_id in ( $ids ) and ( channel_pageflags & %d ) = 0 and channel_system = 0 and channel_removed = 0 $random_sql $limit_sql ", + intval(PAGE_ADULT|PAGE_CENSORED) + ); + if($r) { + foreach($r as $rr) + if(! in_array($rr['channel_id'], $ret)) + $ret[] = $rr['channel_id']; + } } } @@ -635,19 +641,25 @@ function stream_perms_xchans($perms = NULL ) { if(local_channel()) $ret[] = get_observer_hash(); - $x = q("select uid from pconfig where cat = 'perm_limits' and k = 'view_stream' and ( v & %d ) > 0 ", - intval($perms) - ); + $x = q("select uid from pconfig where cat = 'perm_limits' and k = 'view_stream' "); if($x) { - $ids = ids_to_querystr($x,'uid'); - $r = q("select channel_hash from channel where channel_id in ( $ids ) and ( channel_pageflags & %d ) = 0 and channel_system = 0 and channel_removed = 0 ", - intval(PAGE_ADULT|PAGE_CENSORED) - ); + $y = []; + foreach($x as $xv) { + if(intval($xv['v']) & $perms) { + $y[] = $xv; + } + } + if($y) { + $ids = ids_to_querystr($y,'uid'); + $r = q("select channel_hash from channel where channel_id in ( $ids ) and ( channel_pageflags & %d ) = 0 and channel_system = 0 and channel_removed = 0 ", + intval(PAGE_ADULT|PAGE_CENSORED) + ); - if($r) { - foreach($r as $rr) - if(! in_array($rr['channel_hash'], $ret)) - $ret[] = $rr['channel_hash']; + if($r) { + foreach($r as $rr) + if(! in_array($rr['channel_hash'], $ret)) + $ret[] = $rr['channel_hash']; + } } } $str = ''; -- cgit v1.2.3 From 83c4dd6bda1677a3441d06247ea076094394703e Mon Sep 17 00:00:00 2001 From: zotlabs Date: Mon, 1 May 2017 22:56:11 -0700 Subject: typo --- include/bbcode.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include') diff --git a/include/bbcode.php b/include/bbcode.php index 5aa61760f..6a14b665f 100644 --- a/include/bbcode.php +++ b/include/bbcode.php @@ -1174,7 +1174,7 @@ function bbcode($Text, $preserve_nl = false, $tryoembed = true, $cache = false) $Text = preg_replace("/\[event\-start\](.*?)\[\/event\-start\]/ism",$sub,$Text); - $Text = preg_replace("/\event\](.*?)\[\/event\]/ism",'',$Text); + $Text = preg_replace("/\[event\](.*?)\[\/event\]/ism",'',$Text); $Text = preg_replace("/\[event\-summary\](.*?)\[\/event\-summary\]/ism",'',$Text); $Text = preg_replace("/\[event\-description\](.*?)\[\/event\-description\]/ism",'',$Text); $Text = preg_replace("/\[event\-finish\](.*?)\[\/event\-finish\]/ism",'',$Text); -- cgit v1.2.3 From 7acb0685904bd66cd89ef15e181148d31c6813dc Mon Sep 17 00:00:00 2001 From: zotlabs Date: Tue, 2 May 2017 18:24:18 -0700 Subject: profile_sidebar hook ignored the updated html content --- include/channel.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'include') diff --git a/include/channel.php b/include/channel.php index 890bb8bd6..6220ff179 100644 --- a/include/channel.php +++ b/include/channel.php @@ -1196,7 +1196,8 @@ function profile_sidebar($profile, $block = 0, $show_connect = true, $zcard = fa call_hooks('profile_sidebar', $arr); - return $o; + return $arr['entry']; + } -- cgit v1.2.3 From b2d2dcc7fe7af1b61e2636ed7e12c805fe67f49b Mon Sep 17 00:00:00 2001 From: zotlabs Date: Tue, 2 May 2017 20:17:47 -0700 Subject: more code refactoring to put external protocol dependencies in plugins. --- include/items.php | 36 ++++-------------------- include/network.php | 80 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 85 insertions(+), 31 deletions(-) (limited to 'include') diff --git a/include/items.php b/include/items.php index 30aa30048..a3f423836 100755 --- a/include/items.php +++ b/include/items.php @@ -801,37 +801,6 @@ function import_author_xchan($x) { } -/** - * @brief Imports an author from Diaspora. - * - * @param array $x an associative array with - * * \e string \b address - * @return boolean|string false on error, otherwise xchan_hash of the new entry - */ -function import_author_diaspora($x) { - if(! $x['address']) - return false; - - $r = q("select * from xchan where xchan_addr = '%s' limit 1", - dbesc($x['address']) - ); - if($r) { - logger('in_cache: ' . $x['address'], LOGGER_DATA); - return $r[0]['xchan_hash']; - } - - 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; - -} - /** * @brief Imports an author from a RSS feed. * @@ -889,6 +858,11 @@ function import_author_rss($x) { function import_author_unknown($x) { + $arr = [ 'author' => $x, 'result' => false ]; + call_hooks('import_author', $arr); + if($arr['result']) + return $arr['result']; + if(! $x['url']) return false; diff --git a/include/network.php b/include/network.php index 6cc53e8b5..d4b9e73ee 100644 --- a/include/network.php +++ b/include/network.php @@ -1900,3 +1900,83 @@ function probe_api_path($host) { return ''; } + + +function scrape_vcard($url) { + + require_once('library/HTML5/Parser.php'); + + $ret = array(); + + logger('url=' . $url); + + $x = z_fetch_url($url); + if(! $x['success']) + return $ret; + + $s = $x['body']; + + if(! $s) + return $ret; + + $headers = $x['header']; + $lines = explode("\n",$headers); + if(count($lines)) { + foreach($lines as $line) { + // don't try and run feeds through the html5 parser + if(stristr($line,'content-type:') && ((stristr($line,'application/atom+xml')) || (stristr($line,'application/rss+xml')))) + return ret; + } + } + + try { + $dom = HTML5_Parser::parse($s); + } catch (DOMException $e) { + logger('Parse error: ' . $e); + } + + if(! $dom) + return $ret; + + // Pull out hCard profile elements + + $largest_photo = 0; + + $items = $dom->getElementsByTagName('*'); + foreach($items as $item) { + if(attribute_contains($item->getAttribute('class'), 'vcard')) { + $level2 = $item->getElementsByTagName('*'); + foreach($level2 as $x) { + if(attribute_contains($x->getAttribute('id'),'pod_location')) + $ret['pod_location'] = $x->textContent; + if(attribute_contains($x->getAttribute('class'),'fn')) + $ret['fn'] = $x->textContent; + if(attribute_contains($x->getAttribute('class'),'uid')) + $ret['uid'] = $x->textContent; + if(attribute_contains($x->getAttribute('class'),'nickname')) + $ret['nick'] = $x->textContent; + if(attribute_contains($x->getAttribute('class'),'searchable')) + $ret['searchable'] = $x->textContent; + if(attribute_contains($x->getAttribute('class'),'key')) + $ret['public_key'] = $x->textContent; + if(attribute_contains($x->getAttribute('class'),'given_name')) + $ret['given_name'] = $x->textContent; + if(attribute_contains($x->getAttribute('class'),'family_name')) + $ret['family_name'] = $x->textContent; + if(attribute_contains($x->getAttribute('class'),'url')) + $ret['url'] = $x->textContent; + + if((attribute_contains($x->getAttribute('class'),'photo')) + || (attribute_contains($x->getAttribute('class'),'avatar'))) { + $size = intval($x->getAttribute('width')); + if(($size > $largest_photo) || (! $largest_photo)) { + $ret['photo'] = $x->getAttribute('src'); + $largest_photo = $size; + } + } + } + } + } + + return $ret; +} -- cgit v1.2.3 From 0e5d824bff18acfcaceecd8bd87664c7f1546ef7 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Tue, 2 May 2017 22:10:53 -0700 Subject: finish the red conversion of the markdown utilities considering their relation to protocol plugins. --- include/markdown.php | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) (limited to 'include') diff --git a/include/markdown.php b/include/markdown.php index 841540357..90266afc9 100644 --- a/include/markdown.php +++ b/include/markdown.php @@ -151,3 +151,55 @@ function markdown_to_bb($s, $use_zrl = false, $options = []) { } + +function bb_to_markdown($Text) { + + /* + * Transform #tags, strip off the [url] and replace spaces with underscore + */ + + $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); + + // 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); + + + call_hooks('bb_to_markdown_bb',$Text); + + // Convert it to HTML - don't try oembed + $Text = bbcode($Text, $preserve_nl, false); + + // Markdownify does not preserve previously escaped html entities such as <> and &. + + $Text = str_replace(array('<','>','&'),array('&_lt_;','&_gt_;','&_amp_;'),$Text); + + // Now convert HTML to Markdown + $md = new Converter(Converter::LINK_AFTER_CONTENT, false, false); + $Text = $md->parseString($Text); + + // The converter adds backslashes to our attempt at getting around the html entity preservation for some weird reason. + + $Text = str_replace(array('&\\_lt\\_;','&\\_gt\\_;','&\\_amp\\_;'),array('<','>','&'),$Text); + + // If the text going into bbcode() has a plain URL in it, i.e. + // with no [url] tags around it, it will come out of parseString() + // looking like: , which gets removed by strip_tags(). + // So take off the angle brackets of any such URL + $Text = preg_replace("//is", "http$1", $Text); + + // Remove empty zrl links + $Text = preg_replace("/\[zrl\=\].*?\[\/zrl\]/is", "", $Text); + + // escape all unconverted tags + $Text = escape_tags($Text); + + $Text = trim($Text); + + call_hooks('bb_to_markdown', $Text); + + return $Text; + +} \ No newline at end of file -- cgit v1.2.3 From 519aef7ff52013170b08eb89c0a95072fe8047e1 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Wed, 3 May 2017 18:50:32 -0700 Subject: abook_not_here flag created to indicate singleton connections which are connected to this channel but not on this hub. abook_instance enumerates which hubs the connections is valid, but we ultimately need something more efficiently searchable to decide what operations are supported w/r/t this connection in the context of this hub. This flag is ignored during sync to clones although the code to set it correctly during channel creation, import, and sync has not yet been implemented. --- include/zot.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'include') diff --git a/include/zot.php b/include/zot.php index 20a25ce3b..a168dff1b 100644 --- a/include/zot.php +++ b/include/zot.php @@ -3226,12 +3226,10 @@ function process_channel_sync_delivery($sender, $arr, $deliveries) { } - $disallowed = array('abook_id','abook_account','abook_channel','abook_rating','abook_rating_text'); + $disallowed = array('abook_id','abook_account','abook_channel','abook_rating','abook_rating_text','abook_not_here'); foreach($arr['abook'] as $abook) { - - $abconfig = null; if(array_key_exists('abconfig',$abook) && is_array($abook['abconfig']) && count($abook['abconfig'])) -- cgit v1.2.3 From 1e59d9ade576acbd1768303cb9e9c994b4d50392 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Wed, 3 May 2017 19:02:20 -0700 Subject: one file hadn't yet been saved when doing pull request --- include/connections.php | 1 + 1 file changed, 1 insertion(+) (limited to 'include') diff --git a/include/connections.php b/include/connections.php index a8d7d8483..8f4f84e1a 100644 --- a/include/connections.php +++ b/include/connections.php @@ -23,6 +23,7 @@ function abook_store_lowlevel($arr) { 'abook_unconnected' => ((array_key_exists('abook_unconnected',$arr)) ? $arr['abook_unconnected'] : 0), 'abook_self' => ((array_key_exists('abook_self',$arr)) ? $arr['abook_self'] : 0), 'abook_feed' => ((array_key_exists('abook_feed',$arr)) ? $arr['abook_feed'] : 0), + 'abook_not_here' => ((array_key_exists('abook_not_here',$arr)) ? $arr['abook_not_here'] : 0), 'abook_profile' => ((array_key_exists('abook_profile',$arr)) ? $arr['abook_profile'] : ''), 'abook_incl' => ((array_key_exists('abook_incl',$arr)) ? $arr['abook_incl'] : ''), 'abook_excl' => ((array_key_exists('abook_excl',$arr)) ? $arr['abook_excl'] : ''), -- cgit v1.2.3 From b08af13872a698c85bb2cf9abd6651bc5c98f7bd Mon Sep 17 00:00:00 2001 From: zotlabs Date: Wed, 3 May 2017 22:37:06 -0700 Subject: oauth2/oidc testing (please do not port - this requires several extra DB tables to work) --- include/oauth2.php | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 include/oauth2.php (limited to 'include') diff --git a/include/oauth2.php b/include/oauth2.php new file mode 100644 index 000000000..a0d65a995 --- /dev/null +++ b/include/oauth2.php @@ -0,0 +1,21 @@ +db); + $config = [ + 'use_openid_connect'] => true, + 'issuer' => \Zotlabs\Lib\System::get_site_name() + ]; + + $oauth2_server = new OAuth2\Server($storage,$config); + + $oauth2_server->addGrantType(new OAuth2\GrantType\ClientCredentials($storage)); + $oauth2_server->addGrantType(new OAuth2\GrantType\AuthorizationCode($storage)); + + $keyStorage = new OAuth2\Storage\Memory( [ + 'keys' => [ + 'public_key' => get_config('system','pubkey'), + 'private_key' => get_config('system','prvkey') + ] + ]); + + $oauth2_server->addStorage($keyStorage,'public_key'); -- cgit v1.2.3 From eeb9103e267a01ad5f076afeb02bedabfcc70db9 Mon Sep 17 00:00:00 2001 From: Klaus Weidenbach Date: Fri, 5 May 2017 00:23:57 +0200 Subject: :bulb: correct some Doxygen syntax mistakes. --- include/channel.php | 130 ++++++++++++++++++++++++++++---------------------- include/feedutils.php | 7 ++- include/import.php | 19 +++++--- include/items.php | 30 ++++++------ include/text.php | 15 +++--- 5 files changed, 114 insertions(+), 87 deletions(-) (limited to 'include') diff --git a/include/channel.php b/include/channel.php index 0a4c9009a..31dca1ae5 100644 --- a/include/channel.php +++ b/include/channel.php @@ -57,8 +57,9 @@ function identity_check_service_class($account_id) { * Plugins can set additional policies such as full name requirements, character * sets, multi-byte length, etc. * + * @hooks validate_channelname + * * \e array \b name * @param string $name - * * @returns nil return if name is valid, or string describing the error state. */ function validate_channelname($name) { @@ -69,7 +70,7 @@ function validate_channelname($name) { if (strlen($name) > 255) return t('Name too long'); - $arr = array('name' => $name); + $arr = ['name' => $name]; call_hooks('validate_channelname', $arr); if (x($arr, 'message')) @@ -463,7 +464,6 @@ function create_identity($arr) { * if true, set this default unconditionally * if $force is false only do this if there is no existing default */ - function set_default_login_identity($account_id, $channel_id, $force = true) { $r = q("select account_default_channel from account where account_id = %d limit 1", intval($account_id) @@ -478,12 +478,29 @@ function set_default_login_identity($account_id, $channel_id, $force = true) { } } - +/** + * @brief Return an array with default list of sections to export. + * + * @hooks get_default_export_sections + * * \e array \b sections + * @return array with default section names to export + */ function get_default_export_sections() { - $sections = [ 'channel', 'connections', 'config', 'apps', 'chatrooms', 'events', 'webpages', 'mail', 'wikis' ]; + $sections = [ + 'channel', + 'connections', + 'config', + 'apps', + 'chatrooms', + 'events', + 'webpages', + 'mail', + 'wikis' + ]; $cb = [ 'sections' => $sections ]; call_hooks('get_default_export_sections', $cb); + return $cb['sections']; } @@ -493,15 +510,17 @@ function get_default_export_sections() { * which would be necessary to create a nomadic identity clone. This includes * most channel resources and connection information with the exception of content. * + * @hooks identity_basic_export + * * \e int \b channel_id + * * \e array \b sections + * * \e array \b data * @param int $channel_id * Channel_id to export - * @param boolean $items - * Include channel posts (wall items), default false - * + * @param array $sections (optional) + * Which sections to include in the export, default see get_default_export_sections() * @returns array * See function for details */ - function identity_basic_export($channel_id, $sections = null) { /* @@ -511,16 +530,16 @@ function identity_basic_export($channel_id, $sections = null) { if(! $sections) { $sections = get_default_export_sections(); } - + $ret = []; // use constants here as otherwise we will have no idea if we can import from a site // with a non-standard platform and version. $ret['compatibility'] = [ - 'project' => PLATFORM_NAME, - 'version' => STD_VERSION, - 'database' => DB_UPDATE_VERSION, + 'project' => PLATFORM_NAME, + 'version' => STD_VERSION, + 'database' => DB_UPDATE_VERSION, 'server_role' => Zotlabs\Lib\System::get_server_role() ]; @@ -549,8 +568,7 @@ function identity_basic_export($channel_id, $sections = null) { if($r) $ret['profile'] = $r; - - $r = q("select mimetype, content, os_storage from photo + $r = q("select mimetype, content, os_storage from photo where imgscale = 4 and photo_usage = %d and uid = %d limit 1", intval(PHOTO_PROFILE), intval($channel_id) @@ -558,8 +576,8 @@ function identity_basic_export($channel_id, $sections = null) { if($r) { $ret['photo'] = [ - 'type' => $r[0]['mimetype'], - 'data' => (($r[0]['os_storage']) + 'type' => $r[0]['mimetype'], + 'data' => (($r[0]['os_storage']) ? base64url_encode(file_get_contents($r[0]['content'])) : base64url_encode($r[0]['content'])) ]; } @@ -605,7 +623,6 @@ function identity_basic_export($channel_id, $sections = null) { ); if($r) $ret['group_member'] = $r; - } if(in_array('config',$sections)) { @@ -614,7 +631,7 @@ function identity_basic_export($channel_id, $sections = null) { ); if($r) $ret['config'] = $r; - + // All other term types will be included in items, if requested. $r = q("select * from term where ttype in (%d,%d) and uid = %d", @@ -641,7 +658,6 @@ function identity_basic_export($channel_id, $sections = null) { if($r) $ret['likes'] = $r; - } if(in_array('apps',$sections)) { @@ -667,7 +683,6 @@ function identity_basic_export($channel_id, $sections = null) { $ret['chatroom'] = $r; } - if(in_array('events',$sections)) { $r = q("select * from event where uid = %d", intval($channel_id) @@ -697,7 +712,7 @@ function identity_basic_export($channel_id, $sections = null) { $ret['menu'][] = menu_element($ret['channel'],$m); } } - $r = q("select * from item where item_type in ( " + $r = q("select * from item where item_type in ( " . ITEM_TYPE_BLOCK . "," . ITEM_TYPE_PDL . "," . ITEM_TYPE_WEBPAGE . " ) and uid = %d", intval($channel_id) ); @@ -707,7 +722,6 @@ function identity_basic_export($channel_id, $sections = null) { $r = fetch_post_tags($r,true); foreach($r as $rr) $ret['webpages'][] = encode_item($rr,true); - } } @@ -758,7 +772,7 @@ function identity_basic_export($channel_id, $sections = null) { * Don't export linked resource items. we'll have to pull those out separately. */ - $r = q("select * from item where item_wall = 1 and item_deleted = 0 and uid = %d + $r = q("select * from item where item_wall = 1 and item_deleted = 0 and uid = %d and created > %s - INTERVAL %s and resource_type = '' order by created", intval($channel_id), db_utcnow(), @@ -1394,15 +1408,15 @@ function get_my_address() { } /** - * @brief + * @brief Add visitor's zid to our xchan and attempt authentication. * - * If somebody arrives at our site using a zid, add their xchan to our DB if we don't have it already. + * If somebody arrives at our site using a zid, add their xchan to our DB if we + * don't have it already. * And if they aren't already authenticated here, attempt reverse magic auth. * - * - * @hooks 'zid_init' - * string 'zid' - their zid - * string 'url' - the destination url + * @hooks zid_init + * * \e string \b zid - their zid + * * \e string \b url - the destination url */ function zid_init() { $tmp_str = get_my_address(); @@ -1431,12 +1445,9 @@ function zid_init() { } /** - * @brief - * - * If somebody arrives at our site using a zat, authenticate them + * @brief If somebody arrives at our site using a zat, authenticate them. * */ - function zat_init() { if(local_channel() || remote_channel()) return; @@ -1448,7 +1459,6 @@ function zat_init() { $xchan = atoken_xchan($r[0]); atoken_login($xchan); } - } @@ -1481,7 +1491,7 @@ function get_theme_uid() { * * @param int $size * one of (300, 80, 48) -* @returns string +* @returns string with path to profile photo */ function get_default_profile_photo($size = 300) { $scheme = get_config('system','default_profile_photo'); @@ -1974,7 +1984,6 @@ function channel_manual_conv_update($channel_id) { $x = get_config('system','manual_conversation_update', 1); return intval($x); - } @@ -2143,24 +2152,33 @@ function account_remove($account_id,$local = true,$unset_session=true) { } -function channel_remove($channel_id, $local = true, $unset_session=false) { +/** + * @brief Removes a channel. + * + * @hooks channel_remove + * * \e array \b entry from channel tabel for $channel_id + * @param int $channel_id + * @param boolean $local default true + * @param boolean $unset_session default false + */ +function channel_remove($channel_id, $local = true, $unset_session = false) { if(! $channel_id) return; logger('Removing channel: ' . $channel_id); - logger('channel_remove: local only: ' . intval($local)); + logger('local only: ' . intval($local)); $r = q("select * from channel where channel_id = %d limit 1", intval($channel_id)); if(! $r) { - logger('channel_remove: channel not found: ' . $channel_id); + logger('channel not found: ' . $channel_id); return; } $channel = $r[0]; - call_hooks('channel_remove',$r[0]); - + call_hooks('channel_remove', $r[0]); + if(! $local) { $r = q("update channel set channel_deleted = '%s', channel_removed = 1 where channel_id = %d", @@ -2173,12 +2191,11 @@ function channel_remove($channel_id, $local = true, $unset_session=false) { ); logger('deleting hublocs',LOGGER_DEBUG); - + $r = q("update hubloc set hubloc_deleted = 1 where hubloc_hash = '%s'", dbesc($channel['channel_hash']) ); - $r = q("update xchan set xchan_deleted = 1 where xchan_hash = '%s'", dbesc($channel['channel_hash']) ); @@ -2211,8 +2228,7 @@ function channel_remove($channel_id, $local = true, $unset_session=false) { q("DELETE FROM profile WHERE uid = %d", intval($channel_id)); q("DELETE FROM pconfig WHERE uid = %d", intval($channel_id)); - // @FIXME At this stage we need to remove the file resources located under /store/$nickname - + /// @FIXME At this stage we need to remove the file resources located under /store/$nickname q("delete from abook where abook_xchan = '%s' and abook_self = 1 ", dbesc($channel['channel_hash']) @@ -2263,16 +2279,16 @@ function channel_remove($channel_id, $local = true, $unset_session=false) { dbesc($channel['channel_hash']) ); } - + //remove from file system $r = q("select channel_address from channel where channel_id = %d limit 1", intval($channel_id) ); - + if($r) { $channel_address = $r[0]['channel_address'] ; } - if($channel_address) { + if($channel_address) { $f = 'store/' . $channel_address.'/'; logger('delete '. $f); if(is_dir($f)) { @@ -2286,22 +2302,24 @@ function channel_remove($channel_id, $local = true, $unset_session=false) { App::$session->nuke(); goaway(z_root()); } - } -/* - * This checks if a channel is allowed to publish executable code. - * It is up to the caller to determine if the observer or local_channel - * is in fact the resource owner whose channel_id is being checked +/** + * @brief This checks if a channel is allowed to publish executable code. + * + * It is up to the caller to determine if the observer or local_channel + * is in fact the resource owner whose channel_id is being checked. + * + * @param int $channel_id + * @return boolean */ - function channel_codeallowed($channel_id) { - if(! intval($channel_id)) return false; $x = channelx_by_n($channel_id); if(($x) && ($x['channel_pageflags'] & PAGE_ALLOWCODE)) return true; + return false; } diff --git a/include/feedutils.php b/include/feedutils.php index 06a342a3f..6bb7d103e 100644 --- a/include/feedutils.php +++ b/include/feedutils.php @@ -742,7 +742,7 @@ function encode_rel_links($links) { * @param $importer * The contact_record (joined to user_record) of the local user who owns this * relationship. It is this person's stuff that is going to be updated. - * @param array $contact[in,out] + * @param[in,out] array $contact * The person who is sending us stuff. If not set, we MAY be processing a "follow" activity * from an external network and MAY create an appropriate contact record. Otherwise, we MUST * have a contact record. @@ -1232,8 +1232,11 @@ function handle_feed($uid, $abook_id, $url) { /** * @brief Return a XML tag with author information. * + * @hooks \b atom_author Possibility to add further tags to returned XML string + * * \e string The created XML tag as a string without closing tag * @param string $tag The XML tag to create - * @param string $name Name of the author + * @param string $nick preferred username + * @param string $name displayed name of the author * @param string $uri * @param int $h image height * @param int $w image width diff --git a/include/import.php b/include/import.php index 224bb1803..3b5ddd1f1 100644 --- a/include/import.php +++ b/include/import.php @@ -181,7 +181,7 @@ function import_profiles($channel, $profiles) { * @param array $channel * @param array $hublocs * @param unknown $seize - * @param boolean $moving + * @param boolean $moving (optional) default false */ function import_hublocs($channel, $hublocs, $seize, $moving = false) { @@ -585,7 +585,7 @@ function sync_chatrooms($channel, $chatrooms) { * * @param array $channel where to import to * @param array $items - * @param boolean $sync + * @param boolean $sync default false * @param array $relocate default null */ function import_items($channel, $items, $sync = false, $relocate = null) { @@ -654,9 +654,13 @@ function sync_items($channel, $items, $relocate = null) { import_items($channel, $items, true, $relocate); } - - -function import_item_ids($channel,$itemids) { +/** + * @brief + * + * @param array $channel A channel array. + * @param array $itemids + */ +function import_item_ids($channel, $itemids) { if($channel && $itemids) { foreach($itemids as $i) { $r = q("select id from item where mid = '%s' and uid = %d limit 1", @@ -979,6 +983,7 @@ function import_conv($channel,$convs) { * * @param array $channel * @param array $mails + * @param boolean $sync (optional) default false */ function import_mail($channel, $mails, $sync = false) { if($channel && $mails) { @@ -1276,7 +1281,7 @@ function sync_files($channel, $files) { * * Replaces $old key with $new key in $arr. * - * @param array[in,out] $arr The array where to work on + * @param[in,out] array &$arr The array where to work on * @param string $old The old key in the array * @param string $new The new key in the array */ @@ -1444,7 +1449,7 @@ function import_webpage_element($element, $channel, $type) { // The author is either the owner or whomever was specified $arr['author_xchan'] = (($element['author_xchan']) ? $element['author_xchan'] : get_observer_hash()); // Import mimetype if it is a valid mimetype for the element - $mimetypes = [ + $mimetypes = [ 'text/bbcode', 'text/html', 'text/markdown', diff --git a/include/items.php b/include/items.php index c895a6d6e..4b90840e2 100755 --- a/include/items.php +++ b/include/items.php @@ -298,11 +298,13 @@ function add_source_route($iid, $hash) { * or other processing is performed. * * @param array $arr + * @param boolean $allow_code (optional) default false + * @param boolean $deliver (optional) default true * @returns array * * \e boolean \b success true or false * * \e array \b activity the resulting activity if successful */ -function post_activity_item($arr,$allow_code = false,$deliver = true) { +function post_activity_item($arr, $allow_code = false, $deliver = true) { $ret = array('success' => false); @@ -348,7 +350,7 @@ function post_activity_item($arr,$allow_code = false,$deliver = true) { if(($is_comment) && ($arr['obj_type'] === ACTIVITY_OBJ_NOTE)) $arr['obj_type'] = ACTIVITY_OBJ_COMMENT; - if(! ( array_key_exists('allow_cid',$arr) || array_key_exists('allow_gid',$arr) + if(! ( array_key_exists('allow_cid',$arr) || array_key_exists('allow_gid',$arr) || array_key_exists('deny_cid',$arr) || array_key_exists('deny_gid',$arr))) { $arr['allow_cid'] = $channel['channel_allow_cid']; $arr['allow_gid'] = $channel['channel_allow_gid']; @@ -648,11 +650,11 @@ function get_item_elements($x,$allow_code = false) { } } - // Check signature on the body text received. + // Check signature on the body text received. // This presents an issue that we aren't verifying the text that is actually displayed // on this site. We are however verifying the received text was exactly as received. // We have every right to strip content that poses a security risk. You are welcome to - // create a plugin to verify the content after filtering if this offends you. + // create a plugin to verify the content after filtering if this offends you. if($arr['sig']) { @@ -675,7 +677,7 @@ function get_item_elements($x,$allow_code = false) { // If we don't have a public key, strip the signature so it won't show as invalid. // This won't happen in normal use, but could happen if import_author_xchan() - // failed to load the zot-info packet due to a server failure and had + // failed to load the zot-info packet due to a server failure and had // to create an alternate xchan with network 'unknown' unset($arr['sig']); @@ -1518,7 +1520,7 @@ function item_store($arr, $allow_exec = false, $deliver = true) { if(array_key_exists('cancel',$arr) && $arr['cancel']) { logger('cancelled by plugin'); return $ret; - } + } if(! $arr['uid']) { logger('item_store: no uid'); @@ -1843,7 +1845,7 @@ logger('revision: ' . $arr['revision']); ); if($r) { - // This will gives us a fresh copy of what's now in the DB and undo the db escaping, + // This will gives us a fresh copy of what's now in the DB and undo the db escaping, // which really messes up the notifications $current_post = $r[0]['id']; @@ -1906,7 +1908,7 @@ logger('revision: ' . $arr['revision']); // update the commented timestamp on the parent - unless this is potentially a clone of an older item // which we don't wish to bring to the surface. As the queue only holds deliveries for 3 days, it's - // suspected of being an older cloned item if the creation time is older than that. + // suspected of being an older cloned item if the creation time is older than that. if($arr['created'] > datetime_convert('','','now - 4 days')) { $z = q("select max(created) as commented from item where parent_mid = '%s' and uid = %d and item_delayed = 0 ", @@ -1952,7 +1954,7 @@ function item_store_update($arr,$allow_exec = false, $deliver = true) { if(array_key_exists('cancel',$arr) && $arr['cancel']) { logger('cancelled by plugin'); return $ret; - } + } if(! intval($arr['uid'])) { logger('item_store_update: no uid'); @@ -4502,12 +4504,12 @@ function item_create_edit_activity($post) { $new_item['id'] = 0; $new_item['parent'] = 0; $new_item['mid'] = item_message_id(); - + $new_item['body'] = sprintf( t('[Edited %s]'), (($update_item['item_thread_top']) ? t('Post','edit_activity') : t('Comment','edit_activity'))); $new_item['body'] .= "\n\n"; $new_item['body'] .= $update_item['body']; - + $new_item['sig'] = ''; $new_item['verb'] = ACTIVITY_UPDATE; @@ -4533,10 +4535,10 @@ function item_create_edit_activity($post) { array('rel' => 'photo', 'type' => $item_author['xchan_photo_mimetype'], 'href' => $item_author['xchan_photo_m'])), ), )); - - $x = post_activity_item($new_item); + + $x = post_activity_item($new_item); $post_id = $x['id']; if($post_id) { @@ -4551,5 +4553,5 @@ function item_create_edit_activity($post) { } \Zotlabs\Daemon\Master::Summon(array('Notifier', 'edit_activity', $post_id)); - + } diff --git a/include/text.php b/include/text.php index 46509aabf..162d7c365 100644 --- a/include/text.php +++ b/include/text.php @@ -774,9 +774,9 @@ function activity_match($haystack,$needle) { } /** - * @brief Pull out all #hashtags and @person tags from $s. + * @brief Pull out all \#hashtags and \@person tags from $s. * - * We also get @person@domain.com - which would make + * We also get \@person\@domain.com - which would make * the regex quite complicated as tags can also * end a sentence. So we'll run through our results * and strip the period from any tags which end with one. @@ -2079,7 +2079,7 @@ function ids_to_querystr($arr,$idx = 'id',$quote = false) { * If $abook is true also include the abook info. This is needed in the API to * save extra per item lookups there. * - * @param array[in,out] &$items + * @param[in,out] array &$items * @param boolean $abook If true also include the abook info * @param number $effective_uid */ @@ -2175,10 +2175,10 @@ function magic_link($s) { } /** - * if $escape is true, dbesc() each element before adding quotes + * @brief If $escape is true, dbesc() each element before adding quotes. * - * @param array[in,out] &$arr - * @param boolean $escape default false + * @param[in,out] array &$arr + * @param boolean $escape (optional) default false */ function stringify_array_elms(&$arr, $escape = false) { for($x = 0; $x < count($arr); $x ++) @@ -2189,7 +2189,6 @@ function stringify_array_elms(&$arr, $escape = false) { * @brief Indents a flat JSON string to make it more human-readable. * * @param string $json The original JSON string to process. - * * @return string Indented version of the original JSON string. */ function jindent($json) { @@ -3140,4 +3139,4 @@ function ellipsify($s,$maxlen) { return $s; return mb_substr($s,0,$maxlen / 2) . '...' . mb_substr($s,mb_strlen($s) - ($maxlen / 2)); -} +} -- cgit v1.2.3 From faf98147882857f09ed5bdb694bebaae416b2526 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Thu, 4 May 2017 19:18:54 -0700 Subject: typo --- include/items.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include') diff --git a/include/items.php b/include/items.php index a3f423836..7b88ee7f3 100755 --- a/include/items.php +++ b/include/items.php @@ -1281,7 +1281,7 @@ function encode_item_flags($item) { $ret[] = 'consensus'; if(intval($item['item_obscured'])) $ret[] = 'obscured'; - if(intval($item['item_privat'])) + if(intval($item['item_private'])) $ret[] = 'private'; return $ret; -- cgit v1.2.3 From 977677d0051db24c6b7666a73c4dd6a48fe89377 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Thu, 4 May 2017 19:18:54 -0700 Subject: typo --- include/items.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include') diff --git a/include/items.php b/include/items.php index c895a6d6e..ffb02a8f0 100755 --- a/include/items.php +++ b/include/items.php @@ -1323,7 +1323,7 @@ function encode_item_flags($item) { $ret[] = 'consensus'; if(intval($item['item_obscured'])) $ret[] = 'obscured'; - if(intval($item['item_privat'])) + if(intval($item['item_private'])) $ret[] = 'private'; return $ret; -- cgit v1.2.3 From 67918033f94e277240a826534f03ed6d13e4be9d Mon Sep 17 00:00:00 2001 From: zotlabs Date: Thu, 4 May 2017 20:58:19 -0700 Subject: oauth2 dynamic client registration --- include/api.php | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) (limited to 'include') diff --git a/include/api.php b/include/api.php index 693967696..c91590070 100644 --- a/include/api.php +++ b/include/api.php @@ -194,15 +194,25 @@ require_once('include/api_zot.php'); else $redirect = trim($_REQUEST['redirect_uris']); $icon = trim($_REQUEST['logo_uri']); - $r = q("INSERT INTO clients (client_id, pw, clname, redirect_uri, icon, uid) - VALUES ('%s','%s','%s','%s','%s',%d)", - dbesc($key), - dbesc($secret), - dbesc($name), - dbesc($redirect), - dbesc($icon), - intval(0) - ); + if($oauth2) { + $r = q("INSERT INTO oauth_clients (client_id, client_secret, redirect_uri, grant_types, scope, user_id) + VALUES ( '%s', '%s', '%s', null, null, null ) ", + dbesc($key), + dbesc($secret), + dbesc($redirect) + ); + } + else { + $r = q("INSERT INTO clients (client_id, pw, clname, redirect_uri, icon, uid) + VALUES ('%s','%s','%s','%s','%s',%d)", + dbesc($key), + dbesc($secret), + dbesc($name), + dbesc($redirect), + dbesc($icon), + intval(0) + ); + } $ret['client_id'] = $key; $ret['client_secret'] = $secret; -- cgit v1.2.3 From f0a2747d80b29810eddeb62063c231d7178ac3db Mon Sep 17 00:00:00 2001 From: zotlabs Date: Thu, 4 May 2017 21:55:56 -0700 Subject: make service_plink pluggable --- include/network.php | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'include') diff --git a/include/network.php b/include/network.php index d4b9e73ee..5bf626908 100644 --- a/include/network.php +++ b/include/network.php @@ -1980,3 +1980,26 @@ function scrape_vcard($url) { return $ret; } + +function service_plink($contact, $guid) { + + $plink = ''; + + $m = parse_url($contact['xchan_url']); + if($m) { + $url = $m['scheme'] . '://' . $m['host'] . (($m['port']) ? ':' . $m['port'] : ''); + } + else { + $url = 'https://' . substr($contact['xchan_addr'],strpos($contact['xchan_addr'],'@')+1); + } + + $handle = substr($contact['xchan_addr'], 0, strpos($contact['xchan_addr'],'@')); + + $plink = $url . '/channel/' . $handle . '?f=&mid=' . $guid; + + $x = [ 'xchan' => $contact, 'guid' => $guid, '$url' => $url, 'plink' => $plink ]; + call_hooks('service_plink', $x); + + return $x['plink']; +} + -- cgit v1.2.3 From c70ac572fabb7e808adb58ada201aa0e7acf0c36 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Thu, 4 May 2017 22:08:12 -0700 Subject: do away with single delivery (delivery from clones to singleton networks attached to other clones) --- include/import.php | 9 --------- 1 file changed, 9 deletions(-) (limited to 'include') diff --git a/include/import.php b/include/import.php index 224bb1803..d67689290 100644 --- a/include/import.php +++ b/include/import.php @@ -631,12 +631,6 @@ function import_items($channel, $items, $sync = false, $relocate = null) { fix_attached_file_permissions($channel,$item['author_xchan'],$item['body'],$item['allow_cid'],$item['allow_gid'],$item['deny_cid'],$item['deny_gid']); - if($sync && $item['item_wall']) { - // deliver singletons if we have any - if($item_result && $item_result['success']) { - Zotlabs\Daemon\Master::Summon( [ 'Notifier','single_activity',$item_result['item_id'] ]); - } - } } } } @@ -1005,9 +999,6 @@ function import_mail($channel, $mails, $sync = false) { $m['aid'] = $channel['channel_account_id']; $m['uid'] = $channel['channel_id']; $mail_id = mail_store($m); - if($sync && $mail_id) { - Zotlabs\Daemon\Master::Summon(array('Notifier','single_mail',$mail_id)); - } } } } -- cgit v1.2.3 From 3ccefa20e8b10d0a507c6b002237664e721ca389 Mon Sep 17 00:00:00 2001 From: Mario Vavti Date: Fri, 5 May 2017 16:32:20 +0200 Subject: collapse sysapps if viewing a remote channel --- include/nav.php | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'include') diff --git a/include/nav.php b/include/nav.php index fecf28548..849e19d9a 100644 --- a/include/nav.php +++ b/include/nav.php @@ -43,7 +43,7 @@ EOT; require_once('include/conversation.php'); $is_owner = (((local_channel()) && (App::$profile['profile_uid'] == local_channel())) ? true : false); - $navapps[] = channel_apps($is_owner, App::$profile['channel_address']); + $channel_apps[] = channel_apps($is_owner, App::$profile['channel_address']); $myident = (($channel) ? $channel['xchan_addr'] : ''); @@ -258,7 +258,7 @@ EOT; usort($syslist,'Zotlabs\\Lib\\Apps::app_name_compare'); foreach($syslist as $app) { - $navapps[] = Zlib\Apps::app_render($app,'nav'); + $nav_apps[] = Zlib\Apps::app_render($app,'nav'); } $tpl = get_markup_template('nav.tpl'); @@ -276,8 +276,10 @@ EOT; '$powered_by' => $powered_by, '$help' => t('@name, #tag, ?doc, content'), '$pleasewait' => t('Please wait...'), - '$navapps' => $navapps, - '$addapps' => t('Add Apps') + '$nav_apps' => $nav_apps, + '$channel_apps' => $channel_apps, + '$addapps' => t('Add Apps'), + '$sysapps_toggle' => t('Toggle System Apps') )); if(x($_SESSION, 'reload_avatar') && $observer) { @@ -480,4 +482,4 @@ function channel_apps($is_owner = false, $nickname = null) { '$thumb' => App::$profile['thumb'] ] ); -} \ No newline at end of file +} -- cgit v1.2.3 From 1d20b2603a2846537d7c0d6861bf5d6ef4645ca0 Mon Sep 17 00:00:00 2001 From: Andrew Manning Date: Sun, 7 May 2017 08:52:26 -0400 Subject: Mail subject bug fix --- include/message.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include') diff --git a/include/message.php b/include/message.php index b56f98238..4e8e44adc 100644 --- a/include/message.php +++ b/include/message.php @@ -200,8 +200,8 @@ function send_message($uid = 0, $recipient = '', $body = '', $subject = '', $rep intval($channel['channel_id']), dbesc($channel['channel_hash']), dbesc($recipient), - dbesc($subject), dbesc(($mimetype)? $mimetype : 'text/bbcode'), + dbesc($subject), dbesc($body), dbesc($sig), dbesc($jattach), -- cgit v1.2.3 From 2e531c103f33e798d979bd9dcda168cc6cb5d3e0 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Mon, 8 May 2017 02:00:00 -0700 Subject: error --- include/network.php | 109 +--------------------------------------------------- 1 file changed, 1 insertion(+), 108 deletions(-) (limited to 'include') diff --git a/include/network.php b/include/network.php index 5bf626908..d3ccc498d 100644 --- a/include/network.php +++ b/include/network.php @@ -343,7 +343,7 @@ function z_post_url($url,$params, $redirects = 0, $opts = array()) { if (isset($url_parsed)) { curl_close($ch); if($http_code == 303) { - return z_fetch_url($newurl,false,$redirects++,$opts); + return z_fetch_url($newurl,false,++$redirects,$opts); } else { return z_post_url($newurl,$params,++$redirects,$opts); } @@ -397,31 +397,6 @@ function json_return_and_die($x, $content_type = 'application/json') { killme(); } - -/** - * @brief Generic XML return. - * - * Outputs a basic dfrn XML status structure to STDOUT, with a variable - * of $st and an optional text of $message and terminates the current - * process. - * - * @param string $st - * @param string $message - */ -function xml_status($st, $message = '') { - - $xml_message = ((strlen($message)) ? "\t" . xmlify($message) . "\r\n" : ''); - - if($st) - logger('Returning non_zero: ' . $st . " message=" . $message); - - header( "Content-type: text/xml" ); - echo ''."\r\n"; - echo "\r\n\t$st\r\n$xml_message\r\n"; - killme(); -} - - /** * @brief Send HTTP status header. * @@ -1452,88 +1427,6 @@ function scrape_feed($url) { } -function format_and_send_email($sender,$xchan,$item) { - - $title = $item['title']; - $body = $item['body']; - - $textversion = strip_tags(html_entity_decode(bbcode(str_replace(array("\\r", "\\n"), array( "", "\n"), $body)),ENT_QUOTES,'UTF-8')); - - $htmlversion = bbcode(str_replace(array("\\r","\\n"), array("","
    \n"),$body)); - - $banner = t('$Projectname Notification'); - - $product = t('$projectname'); // PLATFORM_NAME; - $siteurl = z_root(); - $thanks = t('Thank You,'); - $sitename = get_config('system','sitename'); - $site_admin = sprintf( t('%s Administrator'), $sitename); - - // load the template for private message notifications - $tpl = get_markup_template('email_notify_html.tpl'); - $email_html_body = replace_macros($tpl,array( - '$banner' => $banner, - '$notify_icon' => Zotlabs\Lib\System::get_notify_icon(), - '$product' => $product, - '$preamble' => '', - '$sitename' => $sitename, - '$siteurl' => $siteurl, - '$source_name' => $sender['xchan_name'], - '$source_link' => $sender['xchan_url'], - '$source_photo' => $sender['xchan_photo_m'], - '$username' => $xchan['xchan_name'], - '$hsitelink' => $datarray['hsitelink'], - '$hitemlink' => $datarray['hitemlink'], - '$thanks' => $thanks, - '$site_admin' => $site_admin, - '$title' => $title, - '$htmlversion' => $htmlversion, - )); - - // load the template for private message notifications - $tpl = get_markup_template('email_notify_text.tpl'); - $email_text_body = replace_macros($tpl, array( - '$banner' => $banner, - '$product' => $product, - '$preamble' => '', - '$sitename' => $sitename, - '$siteurl' => $siteurl, - '$source_name' => $sender['xchan_name'], - '$source_link' => $sender['xchan_url'], - '$source_photo' => $sender['xchan_photo_m'], - '$username' => $xchan['xchan_name'], - '$hsitelink' => $datarray['hsitelink'], - '$hitemlink' => $datarray['hitemlink'], - '$thanks' => $thanks, - '$site_admin' => $site_admin, - '$title' => $title, - '$textversion' => $textversion - )); - - $sender_name = t('Administrator'); - - $hostname = App::get_hostname(); - if(strpos($hostname,':')) - $hostname = substr($hostname,0,strpos($hostname,':')); - $sender_email = get_config('system','reply_address'); - if(! $sender_email) - $sender_email = 'noreply' . '@' . $hostname; - - // use the EmailNotification library to send the message - - Zotlabs\Lib\Enotify::send(array( - 'fromName' => $product, - 'fromEmail' => $sender_email, - 'replyTo' => $sender_email, - 'toEmail' => str_replace('mailto:','',$xchan['xchan_addr']), - 'messageSubject' => (($title) ? $title : t('No Subject')), - 'htmlVersion' => $email_html_body, - 'textVersion' => $email_text_body, - 'additionalMailHeader' => '', - )); - -} - function do_delivery($deliveries) { -- cgit v1.2.3 From e059efb4c47dec32524ee2ff61d5cd9e7ad0cb84 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Mon, 8 May 2017 19:10:08 -0700 Subject: handle mastodon urls in markdown/bbcode conversion --- include/bbcode.php | 2 +- include/markdown.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'include') diff --git a/include/bbcode.php b/include/bbcode.php index 6a14b665f..e0a19c8f0 100644 --- a/include/bbcode.php +++ b/include/bbcode.php @@ -776,7 +776,7 @@ function bbcode($Text, $preserve_nl = false, $tryoembed = true, $cache = false) // Perform URL Search - $urlchars = '[a-zA-Z0-9\:\/\-\?\&\;\.\=\@\_\~\#\%\$\!\+\,\@\(\)]'; + $urlchars = '[a-zA-Z0-9\:\/\-\?\&\;\.\=\_\~\#\%\$\!\+\,\@\(\)]'; if (strpos($Text,'http') !== false) { if($tryoembed) { diff --git a/include/markdown.php b/include/markdown.php index 90266afc9..5826cb089 100644 --- a/include/markdown.php +++ b/include/markdown.php @@ -133,10 +133,10 @@ function markdown_to_bb($s, $use_zrl = false, $options = []) { // Convert everything that looks like a link to a link if($use_zrl) { $s = str_replace(array('[img','/img]'),array('[zmg','/zmg]'),$s); - $s = preg_replace("/([^\]\=]|^)(https?\:\/\/)([a-zA-Z0-9\:\/\-\?\&\;\.\=\_\~\#\%\$\!\+\,\(\)]+)/ism", '$1[zrl=$2$3]$2$3[/zrl]',$s); + $s = preg_replace("/([^\]\=]|^)(https?\:\/\/)([a-zA-Z0-9\:\/\-\?\&\;\.\=\_\~\#\%\$\!\+\,\@\(\)]+)/ism", '$1[zrl=$2$3]$2$3[/zrl]',$s); } else { - $s = preg_replace("/([^\]\=]|^)(https?\:\/\/)([a-zA-Z0-9\:\/\-\?\&\;\.\=\_\~\#\%\$\!\+\,\(\)]+)/ism", '$1[url=$2$3]$2$3[/url]',$s); + $s = preg_replace("/([^\]\=]|^)(https?\:\/\/)([a-zA-Z0-9\:\/\-\?\&\;\.\=\_\~\#\%\$\!\+\,\@\(\)]+)/ism", '$1[url=$2$3]$2$3[/url]',$s); } // remove duplicate adjacent code tags -- cgit v1.2.3 From 76d78571d6d7a5adfc6da9e3bbad56c15056bc4a Mon Sep 17 00:00:00 2001 From: zotlabs Date: Tue, 9 May 2017 20:33:25 -0700 Subject: don't allow html in plugin comment blocks --- include/plugin.php | 1 + 1 file changed, 1 insertion(+) (limited to 'include') diff --git a/include/plugin.php b/include/plugin.php index 29474735e..db20152ea 100755 --- a/include/plugin.php +++ b/include/plugin.php @@ -356,6 +356,7 @@ function get_plugin_info($plugin){ return $info; $f = file_get_contents("addon/$plugin/$plugin.php"); + $f = escape_tags($f); $r = preg_match("|/\*.*\*/|msU", $f, $m); if ($r){ -- cgit v1.2.3 From fa94c0a65b7e35c74429ff9fb507289714c6de76 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Mon, 8 May 2017 19:10:08 -0700 Subject: handle mastodon urls in markdown/bbcode conversion --- include/bbcode.php | 2 +- include/markdown.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'include') diff --git a/include/bbcode.php b/include/bbcode.php index c0033f280..2f15cefe1 100644 --- a/include/bbcode.php +++ b/include/bbcode.php @@ -776,7 +776,7 @@ function bbcode($Text, $preserve_nl = false, $tryoembed = true, $cache = false) // Perform URL Search - $urlchars = '[a-zA-Z0-9\:\/\-\?\&\;\.\=\@\_\~\#\%\$\!\+\,\@\(\)]'; + $urlchars = '[a-zA-Z0-9\:\/\-\?\&\;\.\=\_\~\#\%\$\!\+\,\@\(\)]'; if (strpos($Text,'http') !== false) { if($tryoembed) { diff --git a/include/markdown.php b/include/markdown.php index 7e1f1c42c..a9617f72b 100644 --- a/include/markdown.php +++ b/include/markdown.php @@ -199,10 +199,10 @@ function markdown_to_bb($s, $use_zrl = false) { // Convert everything that looks like a link to a link if($use_zrl) { $s = str_replace(array('[img','/img]'),array('[zmg','/zmg]'),$s); - $s = preg_replace("/([^\]\=]|^)(https?\:\/\/)([a-zA-Z0-9\:\/\-\?\&\;\.\=\_\~\#\%\$\!\+\,\(\)]+)/ism", '$1[zrl=$2$3]$2$3[/zrl]',$s); + $s = preg_replace("/([^\]\=]|^)(https?\:\/\/)([a-zA-Z0-9\:\/\-\?\&\;\.\=\_\~\#\%\$\!\+\,\@\(\)]+)/ism", '$1[zrl=$2$3]$2$3[/zrl]',$s); } else { - $s = preg_replace("/([^\]\=]|^)(https?\:\/\/)([a-zA-Z0-9\:\/\-\?\&\;\.\=\_\~\#\%\$\!\+\,\(\)]+)/ism", '$1[url=$2$3]$2$3[/url]',$s); + $s = preg_replace("/([^\]\=]|^)(https?\:\/\/)([a-zA-Z0-9\:\/\-\?\&\;\.\=\_\~\#\%\$\!\+\,\@\(\)]+)/ism", '$1[url=$2$3]$2$3[/url]',$s); } // remove duplicate adjacent code tags -- cgit v1.2.3 From 60204becf4124a3feb1c009b645f32c7084902be Mon Sep 17 00:00:00 2001 From: zotlabs Date: Tue, 9 May 2017 20:33:25 -0700 Subject: don't allow html in plugin comment blocks --- include/plugin.php | 1 + 1 file changed, 1 insertion(+) (limited to 'include') diff --git a/include/plugin.php b/include/plugin.php index 29474735e..db20152ea 100755 --- a/include/plugin.php +++ b/include/plugin.php @@ -356,6 +356,7 @@ function get_plugin_info($plugin){ return $info; $f = file_get_contents("addon/$plugin/$plugin.php"); + $f = escape_tags($f); $r = preg_match("|/\*.*\*/|msU", $f, $m); if ($r){ -- cgit v1.2.3 From 84064b90a6ea1d968da76749a9816363462f3831 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Wed, 10 May 2017 22:15:01 -0700 Subject: disable oauth2 until I can get back to it - it's throwing typos --- include/connections.php | 2 +- include/oauth2.php | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) (limited to 'include') diff --git a/include/connections.php b/include/connections.php index 8f4f84e1a..0e9f25c8f 100644 --- a/include/connections.php +++ b/include/connections.php @@ -629,7 +629,7 @@ function get_vcard_array($vc,$id) { 'address' => $adr->getParts() ]; $last_entry = end($adrs); - if($adrs[$last_entry]['address']) + if($last_entry && $adrs[$last_entry]['address']) array_walk($adrs[$last_entry]['address'],'array_escape_tags'); } } diff --git a/include/oauth2.php b/include/oauth2.php index a0d65a995..3a71a651d 100644 --- a/include/oauth2.php +++ b/include/oauth2.php @@ -1,8 +1,9 @@ db); $config = [ - 'use_openid_connect'] => true, + 'use_openid_connect' => true, 'issuer' => \Zotlabs\Lib\System::get_site_name() ]; @@ -19,3 +20,4 @@ ]); $oauth2_server->addStorage($keyStorage,'public_key'); +*/ \ No newline at end of file -- cgit v1.2.3 From e501289a5544823eed3834a831770c07159664ff Mon Sep 17 00:00:00 2001 From: zotlabs Date: Thu, 11 May 2017 17:39:26 -0700 Subject: consolidate and simplify the generation of activitystreams persons, add a couple more fields hoping eventually Mastodon will accept legal follow activities without choking on them. Requires an update of plugins also. --- include/feedutils.php | 45 ++++++++++++++++++++++++++++++++++++++------- 1 file changed, 38 insertions(+), 7 deletions(-) (limited to 'include') diff --git a/include/feedutils.php b/include/feedutils.php index 6bb7d103e..6c411723a 100644 --- a/include/feedutils.php +++ b/include/feedutils.php @@ -79,9 +79,11 @@ function get_feed_for($channel, $observer_hash, $params) { $feed_author = ''; if(intval($params['compat']) === 1) { - $feed_author = atom_author('author',$channel['channel_address'],$channel['channel_name'],$channel['xchan_url'],300,300,$channel['xchan_photo_mimetype'],$channel['xchan_photo_l']); + $feed_author = atom_render_author('author',$channel); } + $owner = atom_render_author('zot:owner',$channel); + $atom .= replace_macros($feed_template, array( '$version' => xmlify(Zotlabs\Lib\System::get_project_version()), '$red' => xmlify(Zotlabs\Lib\System::get_platform_name()), @@ -89,6 +91,7 @@ function get_feed_for($channel, $observer_hash, $params) { '$feed_title' => xmlify($channel['channel_name']), '$feed_updated' => xmlify(datetime_convert('UTC', 'UTC', 'now', ATOM_TIME)), '$author' => $feed_author, + '$owner' => $owner, '$name' => xmlify($channel['channel_name']), '$profile_page' => xmlify($channel['xchan_url']), '$mimephoto' => xmlify($channel['xchan_photo_mimetype']), @@ -1272,6 +1275,37 @@ function atom_author($tag, $nick, $name, $uri, $h, $w, $type, $photo) { return $o; } + +function atom_render_author($tag,$xchan) { + + + $nick = xmlify(substr($xchan['xchan_addr'],0,strpos($xchan['xchan_addr'],'@'))); + $id = xmlify($xchan['xchan_url']); + $name = xmlify($xchan['xchan_name']); + $photo = xmlify($xchan['xchan_photo_l']); + $type = xmlify($xchan['xchan_photo_mimetype']); + $w = $h = 300; + + $o .= "<$tag>\r\n"; + $o .= " http://activitystrea.ms/schema/1.0/person\r\n"; + $o .= " $id\r\n"; + $o .= " $nick\r\n"; + $o .= " $id\r\n"; + $o .= ' ' . "\r\n"; + $o .= ' ' . "\r\n"; + $o .= ' ' . "\r\n"; + $o .= ' ' . $nick . '' . "\r\n"; + $o .= ' ' . $name . '' . "\r\n"; + + call_hooks('atom_render_author', $o); + + $o .= "\r\n"; + + return $o; + + +} + /** * @brief Create an item for the Atom feed. * @@ -1303,16 +1337,13 @@ function atom_entry($item, $type, $author, $owner, $comment = false, $cid = 0) { $o = "\r\n\r\n\r\n"; if(is_array($author)) { - $reddress = substr($author['xchan_addr'],0,strpos($author['xchan_addr'],'@')); - $o .= atom_author('author',$reddress,$author['xchan_name'],$author['xchan_url'],80,80,$author['xchan_photo_mimetype'],$author['xchan_photo_m']); + $o .= atom_render_author('author',$author); } else { - $reddress = substr($item['author']['xchan_addr'],0,strpos($item['author']['xchan_addr'],'@')); - $o .= atom_author('author',$reddress,$item['author']['xchan_name'],$item['author']['xchan_url'],80,80,$item['author']['xchan_photo_mimetype'], $item['author']['xchan_photo_m']); + $o .= atom_render_author('author',$item['author']); } - $reddress = substr($item['owner']['xchan_addr'],0,strpos($item['owner']['xchan_addr'],'@')); - $o .= atom_author('zot:owner',$reddress,$item['owner']['xchan_name'],$item['owner']['xchan_url'],80,80,$item['owner']['xchan_photo_mimetype'],$item['owner']['xchan_photo_m']); + $o .= atom_render_author('zot:owner',$item['owner']); if(($item['parent'] != $item['id']) || ($item['parent_mid'] !== $item['mid']) || (($item['thr_parent'] !== '') && ($item['thr_parent'] !== $item['mid']))) { $parent_item = (($item['thr_parent']) ? $item['thr_parent'] : $item['parent_mid']); -- cgit v1.2.3 From c2bd7d1e567382a72ed058ddd41a3b5fd70988f4 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Thu, 11 May 2017 18:32:34 -0700 Subject: issue #769 --- include/zot.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'include') diff --git a/include/zot.php b/include/zot.php index a168dff1b..748fe7b99 100644 --- a/include/zot.php +++ b/include/zot.php @@ -3160,8 +3160,8 @@ function process_channel_sync_delivery($sender, $arr, $deliveries) { if(array_key_exists('menu',$arr) && $arr['menu']) sync_menus($channel,$arr['menu']); - if(array_key_exists('menu',$arr) && $arr['menu']) - sync_menus($channel,$arr['menu']); + if(array_key_exists('file',$arr) && $arr['file']) + sync_files($channel,$arr['file']); if(array_key_exists('wiki',$arr) && $arr['wiki']) sync_items($channel,$arr['wiki'],((array_key_exists('relocate',$arr)) ? $arr['relocate'] : null)); -- cgit v1.2.3 From 4f577cbdebea44dfedece4eeddb99138d5f02f65 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Thu, 11 May 2017 18:32:34 -0700 Subject: issue #769 --- include/zot.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'include') diff --git a/include/zot.php b/include/zot.php index a168dff1b..748fe7b99 100644 --- a/include/zot.php +++ b/include/zot.php @@ -3160,8 +3160,8 @@ function process_channel_sync_delivery($sender, $arr, $deliveries) { if(array_key_exists('menu',$arr) && $arr['menu']) sync_menus($channel,$arr['menu']); - if(array_key_exists('menu',$arr) && $arr['menu']) - sync_menus($channel,$arr['menu']); + if(array_key_exists('file',$arr) && $arr['file']) + sync_files($channel,$arr['file']); if(array_key_exists('wiki',$arr) && $arr['wiki']) sync_items($channel,$arr['wiki'],((array_key_exists('relocate',$arr)) ? $arr['relocate'] : null)); -- cgit v1.2.3 From 1de1b58a087afbadb55b7f18b93fb0b502a2de3a Mon Sep 17 00:00:00 2001 From: zotlabs Date: Thu, 11 May 2017 19:01:04 -0700 Subject: consolidate email validation checks --- include/account.php | 2 +- include/text.php | 13 ------------- 2 files changed, 1 insertion(+), 14 deletions(-) (limited to 'include') diff --git a/include/account.php b/include/account.php index 5e57d53a8..c188ce0d7 100644 --- a/include/account.php +++ b/include/account.php @@ -31,7 +31,7 @@ function check_account_email($email) { if(! strlen($email)) return $result; - if((! valid_email($email)) || (! validate_email($email))) + if(! validate_email($email)) $result['message'] .= t('Not a valid email address') . EOL; elseif(! allowed_email($email)) $result['message'] = t('Your email domain is not among those allowed on this site'); diff --git a/include/text.php b/include/text.php index dc01f97bd..fb39313a2 100644 --- a/include/text.php +++ b/include/text.php @@ -1042,19 +1042,6 @@ function searchbox($s,$id='search-box',$url='/search',$save = false) { )); } -function valid_email_regex($x){ - if(preg_match('/^[_a-zA-Z0-9\-\+]+(\.[_a-zA-Z0-9\-\+]+)*@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)+$/',$x)) - return true; - return false; -} - -function valid_email($x){ - if(get_config('system','disable_email_validation')) - return true; - - return valid_email_regex($x); -} - /** * @brief Replace naked text hyperlink with HTML formatted hyperlink. * -- cgit v1.2.3 From 2cc1844d979a73e07efd242368ff1bf3651369c0 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Sun, 14 May 2017 20:51:15 -0700 Subject: hubzilla issue #777 --- include/bbcode.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include') diff --git a/include/bbcode.php b/include/bbcode.php index e0a19c8f0..04c5b6fdc 100644 --- a/include/bbcode.php +++ b/include/bbcode.php @@ -383,7 +383,7 @@ function bb_definitionList($match) { $eatLeadingSpaces = '(?: |[ \t])*'; // prevent spaces infront of [*= from adding another line to the previous element $listElements = preg_replace('/^(\n|
    )/', '', $match[2]); // ltrim the first newline $listElements = preg_replace( - '/' . $eatLeadingSpaces . '\[\*=([[:print:]]*?)(?$1
    ', $listElements ); -- cgit v1.2.3 From 5c8a911c9334ad9b24a5c9a2e6e928519a586b92 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Sun, 14 May 2017 21:04:34 -0700 Subject: this looks like a slightly cleaner solution to the unicode dl issue --- include/bbcode.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include') diff --git a/include/bbcode.php b/include/bbcode.php index 04c5b6fdc..d38397be7 100644 --- a/include/bbcode.php +++ b/include/bbcode.php @@ -383,7 +383,7 @@ function bb_definitionList($match) { $eatLeadingSpaces = '(?: |[ \t])*'; // prevent spaces infront of [*= from adding another line to the previous element $listElements = preg_replace('/^(\n|
    )/', '', $match[2]); // ltrim the first newline $listElements = preg_replace( - '/' . $eatLeadingSpaces . '\[\*=([\p{Any}]*?)(?$1
    ', $listElements ); -- cgit v1.2.3 From a1ba44db720abab58d8b6b13035daa25710acd03 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Tue, 16 May 2017 22:57:34 -0700 Subject: provide mechanism to arbitrarily sort the nav tray apps, currently the preferred order list needs to be manually created --- include/nav.php | 2 ++ 1 file changed, 2 insertions(+) (limited to 'include') diff --git a/include/nav.php b/include/nav.php index 849e19d9a..0fd555abf 100644 --- a/include/nav.php +++ b/include/nav.php @@ -257,6 +257,8 @@ EOT; usort($syslist,'Zotlabs\\Lib\\Apps::app_name_compare'); + $syslist = Zlib\Apps::app_order(local_channel(),$syslist); + foreach($syslist as $app) { $nav_apps[] = Zlib\Apps::app_render($app,'nav'); } -- cgit v1.2.3 From 21103f8bc4d4a54211ba4edaefc1bce694a8fa05 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Tue, 16 May 2017 22:57:34 -0700 Subject: provide mechanism to arbitrarily sort the nav tray apps, currently the preferred order list needs to be manually created --- include/nav.php | 2 ++ 1 file changed, 2 insertions(+) (limited to 'include') diff --git a/include/nav.php b/include/nav.php index 849e19d9a..0fd555abf 100644 --- a/include/nav.php +++ b/include/nav.php @@ -257,6 +257,8 @@ EOT; usort($syslist,'Zotlabs\\Lib\\Apps::app_name_compare'); + $syslist = Zlib\Apps::app_order(local_channel(),$syslist); + foreach($syslist as $app) { $nav_apps[] = Zlib\Apps::app_render($app,'nav'); } -- cgit v1.2.3 From a44c908147572646e84620a32e4ad6bf316d7147 Mon Sep 17 00:00:00 2001 From: Mario Vavti Date: Wed, 17 May 2017 11:24:27 +0200 Subject: silence php warning during install --- include/dba/dba_driver.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include') diff --git a/include/dba/dba_driver.php b/include/dba/dba_driver.php index ad1d9d194..d362f58b2 100755 --- a/include/dba/dba_driver.php +++ b/include/dba/dba_driver.php @@ -452,7 +452,7 @@ function db_getfunc($f) { function db_logger($s,$level = LOGGER_NORMAL,$syslog = LOG_INFO) { - if(\DBA::$logging) + if(\DBA::$logging || ! \DBA::$dba) return; $saved = \DBA::$dba->debug; -- cgit v1.2.3 From b62463107ce89f397aa0bd738f10cb0522bb126e Mon Sep 17 00:00:00 2001 From: Mario Vavti Date: Fri, 19 May 2017 10:47:33 +0200 Subject: smileybutton fixes --- include/text.php | 2 -- 1 file changed, 2 deletions(-) (limited to 'include') diff --git a/include/text.php b/include/text.php index 162d7c365..d352a61bf 100644 --- a/include/text.php +++ b/include/text.php @@ -1171,7 +1171,6 @@ function list_smilies($default_only = false) { $texts = array( '<3', '</3', - '<\\3', ':-)', ';-)', ':-(', @@ -1207,7 +1206,6 @@ function list_smilies($default_only = false) { $icons = array( '<3', '</3', - '<\\3', ':-)', ';-)', ':-(', -- cgit v1.2.3 From 547df2219ab4b870256f2ed90e36b97d8bf200bf Mon Sep 17 00:00:00 2001 From: Klaus Weidenbach Date: Tue, 23 May 2017 00:32:11 +0200 Subject: Replace Mardownify library with html-to-markdown library. --- include/markdown.php | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'include') diff --git a/include/markdown.php b/include/markdown.php index a9617f72b..39569a0f6 100644 --- a/include/markdown.php +++ b/include/markdown.php @@ -5,7 +5,7 @@ */ use Michelf\MarkdownExtra; -use Markdownify\Converter; +use League\HTMLToMarkdown\HtmlConverter; require_once("include/oembed.php"); require_once("include/event.php"); @@ -495,9 +495,8 @@ function bb2diaspora($Text, $preserve_nl = false, $fordiaspora = true) { $Text = str_replace(array('<','>','&'),array('&_lt_;','&_gt_;','&_amp_;'),$Text); // Now convert HTML to Markdown - $md = new Converter(Converter::LINK_AFTER_CONTENT, false, false); - $Text = $md->parseString($Text); - + $md = new HtmlConverter(); + $Text = $md->convert($Text); // It also adds backslashes to our attempt at getting around the html entity preservation for some weird reason. -- cgit v1.2.3 From 7ae0317b6a2bed323492ef987ddbaaf4f2a1a9b9 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Mon, 22 May 2017 17:07:34 -0700 Subject: apporder style improvement and add to nav menu, also add language awareness to webpages --- include/nav.php | 1 + 1 file changed, 1 insertion(+) (limited to 'include') diff --git a/include/nav.php b/include/nav.php index 0fd555abf..91bade5a7 100644 --- a/include/nav.php +++ b/include/nav.php @@ -281,6 +281,7 @@ EOT; '$nav_apps' => $nav_apps, '$channel_apps' => $channel_apps, '$addapps' => t('Add Apps'), + '$orderapps' => t('Arrange Apps'), '$sysapps_toggle' => t('Toggle System Apps') )); -- cgit v1.2.3 From 647b5d098f0985a12acbaf6fc1d3d89c2a758129 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Mon, 22 May 2017 17:07:34 -0700 Subject: apporder style improvement and add to nav menu, also add language awareness to webpages --- include/nav.php | 1 + 1 file changed, 1 insertion(+) (limited to 'include') diff --git a/include/nav.php b/include/nav.php index 0fd555abf..91bade5a7 100644 --- a/include/nav.php +++ b/include/nav.php @@ -281,6 +281,7 @@ EOT; '$nav_apps' => $nav_apps, '$channel_apps' => $channel_apps, '$addapps' => t('Add Apps'), + '$orderapps' => t('Arrange Apps'), '$sysapps_toggle' => t('Toggle System Apps') )); -- cgit v1.2.3 From 6ff16e2651e46a33c9228150a1b13476c5741901 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Sun, 14 May 2017 20:51:15 -0700 Subject: hubzilla issue #777 --- include/bbcode.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include') diff --git a/include/bbcode.php b/include/bbcode.php index 2f15cefe1..4c5ec7599 100644 --- a/include/bbcode.php +++ b/include/bbcode.php @@ -383,7 +383,7 @@ function bb_definitionList($match) { $eatLeadingSpaces = '(?: |[ \t])*'; // prevent spaces infront of [*= from adding another line to the previous element $listElements = preg_replace('/^(\n|
    )/', '', $match[2]); // ltrim the first newline $listElements = preg_replace( - '/' . $eatLeadingSpaces . '\[\*=([[:print:]]*?)(?$1
    ', $listElements ); -- cgit v1.2.3 From 508ea9153c128b0204b125911dde56d568867ad0 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Sun, 14 May 2017 21:04:34 -0700 Subject: this looks like a slightly cleaner solution to the unicode dl issue --- include/bbcode.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include') diff --git a/include/bbcode.php b/include/bbcode.php index 4c5ec7599..135368db9 100644 --- a/include/bbcode.php +++ b/include/bbcode.php @@ -383,7 +383,7 @@ function bb_definitionList($match) { $eatLeadingSpaces = '(?: |[ \t])*'; // prevent spaces infront of [*= from adding another line to the previous element $listElements = preg_replace('/^(\n|
    )/', '', $match[2]); // ltrim the first newline $listElements = preg_replace( - '/' . $eatLeadingSpaces . '\[\*=([\p{Any}]*?)(?$1
    ', $listElements ); -- cgit v1.2.3 From 3a00140797fa0d557db2434402ce20258b4ce570 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Tue, 23 May 2017 21:20:40 -0700 Subject: remove php version checks for older ( < 5.4) code incompatibilities --- include/dba/dba_driver.php | 7 ++----- include/text.php | 32 +++++++++++++------------------- 2 files changed, 15 insertions(+), 24 deletions(-) (limited to 'include') diff --git a/include/dba/dba_driver.php b/include/dba/dba_driver.php index d362f58b2..b0ad7936c 100755 --- a/include/dba/dba_driver.php +++ b/include/dba/dba_driver.php @@ -344,11 +344,8 @@ function q($sql) { if(\DBA::$dba && \DBA::$dba->connected) { $stmt = vsprintf($sql, $args); if($stmt === false) { - if(version_compare(PHP_VERSION, '5.4.0') >= 0) - db_logger('dba: vsprintf error: ' . - print_r(debug_backtrace(DEBUG_BACKTRACE_PROVIDE_OBJECT, 1), true),LOGGER_NORMAL,LOG_CRIT); - else - db_logger('dba: vsprintf error: ' . print_r(debug_backtrace(), true),LOGGER_NORMAL,LOG_CRIT); + db_logger('dba: vsprintf error: ' . + print_r(debug_backtrace(DEBUG_BACKTRACE_PROVIDE_OBJECT, 1), true),LOGGER_NORMAL,LOG_CRIT); } if(\DBA::$dba->debug) db_logger('Sql: ' . $stmt, LOGGER_DEBUG, LOG_INFO); diff --git a/include/text.php b/include/text.php index b17564b9f..2e77dca84 100644 --- a/include/text.php +++ b/include/text.php @@ -648,12 +648,8 @@ function logger($msg, $level = LOGGER_NORMAL, $priority = LOG_INFO) { $where = ''; - // We require > 5.4 but leave the version check so that install issues (including version) can be logged - - 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'] . ': '; - } + $stack = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 2); + $where = basename($stack[0]['file']) . ':' . $stack[0]['line'] . ':' . $stack[1]['function'] . ': '; $s = datetime_convert() . ':' . log_priority_str($priority) . ':' . session_id() . ':' . $where . $msg . PHP_EOL; $pluginfo = array('filename' => $logfile, 'loglevel' => $level, 'message' => $s,'priority' => $priority, 'logged' => false); @@ -687,16 +683,14 @@ function btlogger($msg, $level = LOGGER_NORMAL, $priority = LOG_INFO) { @file_put_contents(BTLOGGER_DEBUG_FILE, $s, FILE_APPEND); } - if(version_compare(PHP_VERSION, '5.4.0') >= 0) { - $stack = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS); - if($stack) { - for($x = 1; $x < count($stack); $x ++) { - $s = 'stack: ' . basename($stack[$x]['file']) . ':' . $stack[$x]['line'] . ':' . $stack[$x]['function'] . '()'; - logger($s,$level, $priority); + $stack = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS); + if($stack) { + for($x = 1; $x < count($stack); $x ++) { + $s = 'stack: ' . basename($stack[$x]['file']) . ':' . $stack[$x]['line'] . ':' . $stack[$x]['function'] . '()'; + logger($s,$level, $priority); - if(file_exists(BTLOGGER_DEBUG_FILE) && is_writable(BTLOGGER_DEBUG_FILE)) { - @file_put_contents(BTLOGGER_DEBUG_FILE, $s . PHP_EOL, FILE_APPEND); - } + if(file_exists(BTLOGGER_DEBUG_FILE) && is_writable(BTLOGGER_DEBUG_FILE)) { + @file_put_contents(BTLOGGER_DEBUG_FILE, $s . PHP_EOL, FILE_APPEND); } } } @@ -751,10 +745,10 @@ function dlogger($msg, $level = 0) { return; $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'] . ': '; - } + + $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 . PHP_EOL, FILE_APPEND); } -- cgit v1.2.3 From df8c69f73b54d33ba2bec7d227f6e6f948f4b451 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Wed, 24 May 2017 22:24:45 -0700 Subject: some minor help cleanup - add '-/foo' override of language detection --- include/help.php | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'include') diff --git a/include/help.php b/include/help.php index ab31e9400..4f9251b1b 100644 --- a/include/help.php +++ b/include/help.php @@ -116,9 +116,11 @@ function load_doc_file($s) { $b = basename($s); $d = dirname($s); - $c = find_doc_file("$d/$lang/$b"); - if($c) - return $c; + if($dirname !== '-') { + $c = find_doc_file("$d/$lang/$b"); + if($c) + return $c; + } $c = find_doc_file($s); if($c) return $c; @@ -140,8 +142,8 @@ function find_doc_file($s) { */ function search_doc_files($s) { - $itemspage = get_pconfig(local_channel(),'system','itemspage'); - \App::set_pager_itemspage(((intval($itemspage)) ? $itemspage : 20)); + + \App::set_pager_itemspage(60); $pager_sql = sprintf(" LIMIT %d OFFSET %d ", intval(\App::$pager['itemspage']), intval(\App::$pager['start'])); $regexop = db_getfunc('REGEXP'); @@ -198,6 +200,7 @@ function doc_rank_sort($s1, $s2) { * * @return string */ + function load_context_help() { $path = App::$cmd; -- cgit v1.2.3 From b4da2d35bf8084da812be0716917a0f88cf68f91 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Thu, 25 May 2017 13:37:13 -0700 Subject: start using the abook_not_here flag (requires changes in addons, not easily portable to hubzilla) --- include/follow.php | 10 +++++----- include/zot.php | 5 +++++ 2 files changed, 10 insertions(+), 5 deletions(-) (limited to 'include') diff --git a/include/follow.php b/include/follow.php index 0d7c16aa3..2c2f5e209 100644 --- a/include/follow.php +++ b/include/follow.php @@ -226,12 +226,12 @@ function new_contact($uid,$url,$channel,$interactive = false, $confirm = false) if($abook_instance) $abook_instance .= ','; $abook_instance .= z_root(); - } - $x = q("update abook set abook_instance = '%s' where abook_id = %d", - dbesc($abook_instance), - intval($r[0]['abook_id']) - ); + $x = q("update abook set abook_instance = '%s', abook_not_here = 0 where abook_id = %d", + dbesc($abook_instance), + intval($r[0]['abook_id']) + ); + } if(intval($r[0]['abook_pending'])) { $x = q("update abook set abook_pending = 0 where abook_id = %d", diff --git a/include/zot.php b/include/zot.php index 748fe7b99..d2088f272 100644 --- a/include/zot.php +++ b/include/zot.php @@ -3289,6 +3289,11 @@ function process_channel_sync_delivery($sender, $arr, $deliveries) { if(! array_key_exists('abook_xchan',$clean)) continue; + if(array_key_exists('abook_instance',$clean) && $clean['abook_instance'] && strpos($clean['abook_instance'],z_root()) === false) { + $clean['abook_not_here'] = 1; + } + + $r = q("select * from abook where abook_xchan = '%s' and abook_channel = %d limit 1", dbesc($clean['abook_xchan']), intval($channel['channel_id']) -- cgit v1.2.3 From 0f0e23445ab00c49a09d3167ca220ac314722cfd Mon Sep 17 00:00:00 2001 From: Klaus Weidenbach Date: Wed, 24 May 2017 23:47:03 +0200 Subject: :hammer::white_check_mark: Add html2markdown unit tests. A tiny refactoring to make HTML 2 markdown conversion testable. Add some unit tests to check the behavior of the now used HTML2Markdown library. There are some differences compared to the old pixel418/markdownify library. --- include/markdown.php | 50 +++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 41 insertions(+), 9 deletions(-) (limited to 'include') diff --git a/include/markdown.php b/include/markdown.php index 39569a0f6..55ae528a4 100644 --- a/include/markdown.php +++ b/include/markdown.php @@ -453,15 +453,24 @@ function bb2diaspora_itembody($item, $force_update = false, $have_channel = fals return html_entity_decode($body); } +/** + * @brief Prepare bbcode for Diaspora. + * + * @hooks bb2diaspora + * * \e string The prepared text for diaspora. + * + * @param string $Text bbcode + * @param boolean $preserve_nl (default false) preserve new lines + * @param boolean $fordiaspora (default true, but unused) + * @return string + */ function bb2diaspora($Text, $preserve_nl = false, $fordiaspora = true) { // Re-enabling the converter again. // The bbcode parser now handles youtube-links (and the other stuff) correctly. // Additionally the html code is now fixed so that lists are now working. - /* - * Transform #tags, strip off the [url] and replace spaces with underscore - */ + // Transform #tags, strip off the [url] and replace spaces with underscore $Text = preg_replace_callback('/#\[([zu])rl\=(\w+.*?)\](\w+.*?)\[\/[(zu)]rl\]/i', create_function('$match', 'return \'#\'. str_replace(\' \', \'_\', $match[3]);' ), $Text); @@ -473,7 +482,6 @@ function bb2diaspora($Text, $preserve_nl = false, $fordiaspora = true) { // strip map tags, as the rendering is performed in bbcode() and the resulting output // is not compatible with Diaspora (at least in the case of openstreetmap and probably // due to the inclusion of an html iframe) - $Text = preg_replace("/\[map\=(.*?)\]/ism", '$1', $Text); $Text = preg_replace("/\[map\](.*?)\[\/map\]/ism", '$1', $Text); @@ -491,15 +499,12 @@ function bb2diaspora($Text, $preserve_nl = false, $fordiaspora = true) { $Text = bbcode($Text, $preserve_nl, false); // Markdownify does not preserve previously escaped html entities such as <> and &. - $Text = str_replace(array('<','>','&'),array('&_lt_;','&_gt_;','&_amp_;'),$Text); // Now convert HTML to Markdown - $md = new HtmlConverter(); - $Text = $md->convert($Text); + $Text = html2markdown($Text); // It also adds backslashes to our attempt at getting around the html entity preservation for some weird reason. - $Text = str_replace(array('&\\_lt\\_;','&\\_gt\\_;','&\\_amp\\_;'),array('<','>','&'),$Text); // If the text going into bbcode() has a plain URL in it, i.e. @@ -516,7 +521,6 @@ function bb2diaspora($Text, $preserve_nl = false, $fordiaspora = true) { // 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); @@ -563,3 +567,31 @@ function format_event_diaspora($ev) { return $o; } + +/** + * @brief Convert a HTML text into Markdown. + * + * This function uses the library league/html-to-markdown for this task. + * + * If the HTML text can not get parsed it will return an empty string. + * + * @see HTMLToMarkdown + * + * @param string $html The HTML code to convert + * @return string Markdown representation of the given HTML text, empty on error + */ +function html2markdown(String $html) : String { + $markdown = ''; + $converter = new HtmlConverter(); + + try { + $markdown = $converter->convert($html); + } catch (InvalidArgumentException $e) { + logger("Invalid HTML. HTMLToMarkdown library threw an exception."); + } + + // The old html 2 markdown library "pixel418/markdownify": "^2.2", + //$md = new HtmlConverter(); + //$markdown = $md->convert($Text); + return $markdown; +} -- cgit v1.2.3 From 586c72fbe5f9293b7dfc05990eddfceb472921ef Mon Sep 17 00:00:00 2001 From: Klaus Weidenbach Date: Sat, 27 May 2017 22:44:54 +0200 Subject: Don't drop PHP5 support yet. Scalar Type Hints and Return Type Declarations were introduced in PHP7. --- include/markdown.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include') diff --git a/include/markdown.php b/include/markdown.php index 55ae528a4..f7e9d53fc 100644 --- a/include/markdown.php +++ b/include/markdown.php @@ -580,7 +580,7 @@ function format_event_diaspora($ev) { * @param string $html The HTML code to convert * @return string Markdown representation of the given HTML text, empty on error */ -function html2markdown(String $html) : String { +function html2markdown($html) { $markdown = ''; $converter = new HtmlConverter(); -- cgit v1.2.3 From b15a5f03e61eeef2086d87f497464b00ada3798e Mon Sep 17 00:00:00 2001 From: zotlabs Date: Sun, 28 May 2017 19:17:46 -0700 Subject: work through the diaspora_v2 outgoing status posts --- include/text.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'include') diff --git a/include/text.php b/include/text.php index 2e77dca84..0666a5e0d 100644 --- a/include/text.php +++ b/include/text.php @@ -3049,7 +3049,8 @@ function array2XML($obj, $array) { if(is_array($value)) { $node = $obj->addChild($key); array2XML($node, $value); - } else { + } + else { $obj->addChild($key, htmlspecialchars($value)); } } -- cgit v1.2.3 From 4fcfcc81172ebdfa4a27d3bca94bffe97356f600 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Mon, 29 May 2017 13:50:02 -0700 Subject: start deprecation of server_role --- include/account.php | 10 ++-------- include/features.php | 23 +++++++++-------------- include/nav.php | 9 +++------ include/zot.php | 7 ------- 4 files changed, 14 insertions(+), 35 deletions(-) (limited to 'include') diff --git a/include/account.php b/include/account.php index c188ce0d7..499f7303a 100644 --- a/include/account.php +++ b/include/account.php @@ -424,7 +424,7 @@ function account_allow($hash) { pop_lang(); - if(get_config('system','auto_channel_create') || get_config('system','server_role') === 'basic') + if(get_config('system','auto_channel_create')) auto_channel_create($register[0]['uid']); if ($res) { @@ -528,7 +528,7 @@ function account_approve($hash) { - if(get_config('system','auto_channel_create') || get_config('system','server_role') === 'basic') + if(get_config('system','auto_channel_create')) auto_channel_create($register[0]['uid']); else { $_SESSION['login_return_url'] = 'new_channel'; @@ -772,12 +772,6 @@ function upgrade_bool_message($bbcode = false) { function get_account_techlevel($account_id = 0) { - $role = \Zotlabs\Lib\System::get_server_role(); - if($role == 'basic') - return 0; - if($role == 'standard') - return 5; - if(! $account_id) { $x = \App::get_account(); } diff --git a/include/features.php b/include/features.php index 0fc6fbc1d..f32dbe82e 100644 --- a/include/features.php +++ b/include/features.php @@ -45,10 +45,6 @@ function feature_level($feature,$def) { function get_features($filtered = true) { - $server_role = \Zotlabs\Lib\System::get_server_role(); - - if($server_role === 'basic' && $filtered) - return array(); $arr = [ @@ -424,16 +420,15 @@ function get_features($filtered = true) { ]; - if($server_role === 'pro') { - $arr['general'][] = [ - 'premium_channel', - t('Premium Channel'), - t('Allows you to set restrictions and terms on those that connect with your channel'), - false, - get_config('feature_lock','premium_channel'), - feature_level('premium_channel',4), - ]; - } + $arr['general'][] = [ + 'premium_channel', + t('Premium Channel'), + t('Allows you to set restrictions and terms on those that connect with your channel'), + false, + get_config('feature_lock','premium_channel'), + feature_level('premium_channel',4), + ]; + $techlevel = get_account_techlevel(); diff --git a/include/nav.php b/include/nav.php index 91bade5a7..4d6c479da 100644 --- a/include/nav.php +++ b/include/nav.php @@ -65,8 +65,6 @@ EOT; //we could additionally use this to display important system notifications e.g. for updates )); - $server_role = get_config('system','server_role'); - $basic = (($server_role === 'basic') ? true : false); $techlevel = get_account_techlevel(); // nav links: array of array('href', 'text', 'extra css classes', 'title') @@ -97,7 +95,7 @@ EOT; if(local_channel()) { - if($chans && count($chans) > 1 && feature_enabled(local_channel(),'nav_channel_select') && (! $basic)) + if($chans && count($chans) > 1 && feature_enabled(local_channel(),'nav_channel_select')) $nav['channels'] = $chans; $nav['logout'] = ['logout',t('Logout'), "", t('End this session'),'logout_nav_btn']; @@ -105,7 +103,7 @@ EOT; // user menu $nav['usermenu'][] = ['profile/' . $channel['channel_address'], t('View Profile'), "", t('Your profile page'),'profile_nav_btn']; - if(feature_enabled(local_channel(),'multi_profiles') && (! $basic)) + if(feature_enabled(local_channel(),'multi_profiles')) $nav['usermenu'][] = ['profiles', t('Edit Profiles'),"", t('Manage/Edit profiles'),'profiles_nav_btn']; else $nav['usermenu'][] = ['profiles/' . $prof[0]['id'], t('Edit Profile'),"", t('Edit your profile'),'profiles_nav_btn']; @@ -201,8 +199,7 @@ EOT; $nav['all_events']['all']=array('events', t('View events'), "", ""); $nav['all_events']['mark'] = array('', t('Mark all events seen'), '',''); - if(! $basic) - $nav['manage'] = array('manage', t('Channel Manager'), "", t('Manage Your Channels'),'manage_nav_btn'); + $nav['manage'] = array('manage', t('Channel Manager'), "", t('Manage Your Channels'),'manage_nav_btn'); $nav['settings'] = array('settings', t('Settings'),"", t('Account/Channel Settings'),'settings_nav_btn'); diff --git a/include/zot.php b/include/zot.php index d2088f272..9458b1f1e 100644 --- a/include/zot.php +++ b/include/zot.php @@ -2237,9 +2237,6 @@ function check_location_move($sender_hash,$locations) { if(! $locations) return; - if(get_config('system','server_role') !== 'basic') - return; - if(count($locations) != 1) return; @@ -2935,8 +2932,6 @@ function import_site($arr, $pubkey) { function build_sync_packet($uid = 0, $packet = null, $groups_changed = false) { - if(get_config('system','server_role') === 'basic') - return; logger('build_sync_packet'); @@ -3086,8 +3081,6 @@ function build_sync_packet($uid = 0, $packet = null, $groups_changed = false) { function process_channel_sync_delivery($sender, $arr, $deliveries) { - if(get_config('system','server_role') === 'basic') - return; require_once('include/import.php'); -- cgit v1.2.3 From 6962bc5147bed48a0fd6ab31580ba9a0f8f75bf7 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Mon, 29 May 2017 21:46:38 -0700 Subject: create account_store_lowlevel() --- include/account.php | 92 +++++++++++++++++++++++++++++++++-------------------- 1 file changed, 58 insertions(+), 34 deletions(-) (limited to 'include') diff --git a/include/account.php b/include/account.php index 499f7303a..6c6fdece4 100644 --- a/include/account.php +++ b/include/account.php @@ -105,6 +105,33 @@ function account_total() { } +function account_store_lowlevel($arr) { + + $store = [ + 'account_parent' => ((array_key_exists('account_parent',$arr)) ? $arr['account_parent'] : '0'), + 'account_default_channel' => ((array_key_exists('account_default_channel',$arr)) ? $arr['account_default_channel'] : '0'), + 'account_salt' => ((array_key_exists('account_salt',$arr)) ? $arr['account_salt'] : ''), + 'account_password' => ((array_key_exists('account_password',$arr)) ? $arr['account_password'] : ''), + 'account_email' => ((array_key_exists('account_email',$arr)) ? $arr['account_email'] : ''), + 'account_external' => ((array_key_exists('account_external',$arr)) ? $arr['account_external'] : ''), + 'account_language' => ((array_key_exists('account_language',$arr)) ? $arr['account_language'] : 'en'), + 'account_created' => ((array_key_exists('account_created',$arr)) ? $arr['account_created'] : '0001-01-01 00:00:00'), + 'account_lastlog' => ((array_key_exists('account_lastlog',$arr)) ? $arr['account_lastlog'] : '0001-01-01 00:00:00'), + 'account_flags' => ((array_key_exists('account_flags',$arr)) ? $arr['account_flags'] : '0'), + 'account_roles' => ((array_key_exists('account_roles',$arr)) ? $arr['account_roles'] : '0'), + 'account_reset' => ((array_key_exists('account_reset',$arr)) ? $arr['account_reset'] : ''), + 'account_expires' => ((array_key_exists('account_expires',$arr)) ? $arr['account_expires'] : '0001-01-01 00:00:00'), + 'account_expire_notified' => ((array_key_exists('account_expire_notified',$arr)) ? $arr['account_expire_notified'] : '0001-01-01 00:00:00'), + 'account_service_class' => ((array_key_exists('account_service_class',$arr)) ? $arr['account_service_class'] : ''), + 'account_level' => ((array_key_exists('account_level',$arr)) ? $arr['account_level'] : '0'), + 'account_password_changed' => ((array_key_exists('account_password_changed',$arr)) ? $arr['account_password_changed'] : '0001-01-01 00:00:00') + ]; + + return create_table_from_array('account',$store); + +} + + function create_account($arr) { // Required: { email, password } @@ -177,21 +204,20 @@ function create_account($arr) { $salt = random_string(32); $password_encoded = hash('whirlpool', $salt . $password); - $r = q("INSERT INTO account - ( account_parent, account_salt, account_password, account_email, account_language, - account_created, account_flags, account_roles, account_level, account_expires, account_service_class ) - VALUES ( %d, '%s', '%s', '%s', '%s', '%s', %d, %d, %d, '%s', '%s' )", - intval($parent), - dbesc($salt), - dbesc($password_encoded), - dbesc($email), - dbesc(get_best_language()), - dbesc(datetime_convert()), - intval($flags), - intval($roles), - intval($techlevel), - dbesc($expires), - dbesc($default_service_class) + $r = account_store_lowlevel( + [ + 'account_parent' => intval($parent), + 'account_salt' => $salt, + 'account_password' => $password_encoded, + 'account_email' => $email, + 'account_language' => get_best_language(), + 'account_created' => datetime_convert(), + 'account_flags' => intval($flags), + 'account_roles' => intval($roles), + 'account_level' => intval($techlevel), + 'account_expires' => $expires, + 'account_service_class' => $default_service_class + ] ); if(! $r) { logger('create_account: DB INSERT failed.'); @@ -246,16 +272,18 @@ function verify_email_address($arr) { dbesc($arr['account']['account_language']) ); -//@fixme - get correct language template + push_lang(($arr['account']['account_language']) ? $arr['account']['account_language'] : 'en'); - $email_msg = replace_macros(get_intltext_template('register_verify_member.tpl'), array( - '$sitename' => get_config('system','sitename'), - '$siteurl' => z_root(), - '$email' => $arr['email'], - '$uid' => $arr['account']['account_id'], - '$hash' => $hash, - '$details' => $details - )); + $email_msg = replace_macros(get_intltext_template('register_verify_member.tpl'), + [ + '$sitename' => get_config('system','sitename'), + '$siteurl' => z_root(), + '$email' => $arr['email'], + '$uid' => $arr['account']['account_id'], + '$hash' => $hash, + '$details' => $details + ] + ); $res = z_mail( [ @@ -265,10 +293,12 @@ function verify_email_address($arr) { ] ); + pop_lang(); + if($res) $delivered ++; else - logger('send_reg_approval_email: failed to ' . $admin['email'] . 'account_id: ' . $arr['account']['account_id']); + logger('send_reg_approval_email: failed to account_id: ' . $arr['account']['account_id']); return $res; } @@ -354,9 +384,9 @@ function send_register_success_email($email,$password) { $res = z_mail( [ - 'toEmail' => $email, - 'messageSubject' => sprintf( t('Registration details for %s'), get_config('system','sitename')), - 'textVersion' => $email_msg, + 'toEmail' => $email, + 'messageSubject' => sprintf( t('Registration details for %s'), get_config('system','sitename')), + 'textVersion' => $email_msg, ] ); @@ -525,9 +555,6 @@ function account_approve($hash) { if(! $account) return $ret; - - - if(get_config('system','auto_channel_create')) auto_channel_create($register[0]['uid']); else { @@ -535,9 +562,6 @@ function account_approve($hash) { authenticate_success($account[0],null,true,true,false,true); } - - // info( t('Account verified. Please login.') . EOL ); - return true; } -- cgit v1.2.3 From 893ae17b99d1a1a720a58879e8075fc9bb1de087 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Tue, 30 May 2017 17:06:50 -0700 Subject: provide ability to search webpages (either public or which contain the observer in the acl) in addition to conversations --- include/items.php | 7 +++++++ include/security.php | 1 - 2 files changed, 7 insertions(+), 1 deletion(-) (limited to 'include') diff --git a/include/items.php b/include/items.php index a375ee3c3..707f07f4a 100755 --- a/include/items.php +++ b/include/items.php @@ -175,6 +175,13 @@ function item_normal() { and item.item_blocked = 0 "; } +function item_normal_search() { + return " and item.item_hidden = 0 and item.item_type in (0,3) and item.item_deleted = 0 + and item.item_unpublished = 0 and item.item_delayed = 0 and item.item_pending_remove = 0 + and item.item_blocked = 0 "; +} + + /** * @brief * diff --git a/include/security.php b/include/security.php index ddbb3d806..6e7b3dbb2 100644 --- a/include/security.php +++ b/include/security.php @@ -467,7 +467,6 @@ function scopes_sql($uid,$observer) { */ function public_permissions_sql($observer_hash) { - //$observer = App::get_observer(); $groups = init_groups_visitor($observer_hash); $gs = '<<>>'; // should be impossible to match -- cgit v1.2.3 From a7ecf519156c1110acbb0eadd13dee63b7adaabd Mon Sep 17 00:00:00 2001 From: zotlabs Date: Tue, 30 May 2017 17:06:50 -0700 Subject: provide ability to search webpages (either public or which contain the observer in the acl) in addition to conversations --- include/items.php | 7 +++++++ include/security.php | 1 - 2 files changed, 7 insertions(+), 1 deletion(-) (limited to 'include') diff --git a/include/items.php b/include/items.php index 328079b9d..f7fddad33 100755 --- a/include/items.php +++ b/include/items.php @@ -175,6 +175,13 @@ function item_normal() { and item.item_blocked = 0 "; } +function item_normal_search() { + return " and item.item_hidden = 0 and item.item_type in (0,3) and item.item_deleted = 0 + and item.item_unpublished = 0 and item.item_delayed = 0 and item.item_pending_remove = 0 + and item.item_blocked = 0 "; +} + + /** * @brief * diff --git a/include/security.php b/include/security.php index ddbb3d806..6e7b3dbb2 100644 --- a/include/security.php +++ b/include/security.php @@ -467,7 +467,6 @@ function scopes_sql($uid,$observer) { */ function public_permissions_sql($observer_hash) { - //$observer = App::get_observer(); $groups = init_groups_visitor($observer_hash); $gs = '<<>>'; // should be impossible to match -- cgit v1.2.3 From 062b9ecbf3a3b315097428a6d608376055d4cae5 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Tue, 30 May 2017 18:22:48 -0700 Subject: bring back html2markdown which went away in the merge --- include/markdown.php | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'include') diff --git a/include/markdown.php b/include/markdown.php index 1c42937b3..947b5c5e3 100644 --- a/include/markdown.php +++ b/include/markdown.php @@ -204,3 +204,33 @@ function bb_to_markdown($Text) { return $Text; } + + + +/** + * @brief Convert a HTML text into Markdown. + * + * This function uses the library league/html-to-markdown for this task. + * + * If the HTML text can not get parsed it will return an empty string. + * + * @see HTMLToMarkdown + * + * @param string $html The HTML code to convert + * @return string Markdown representation of the given HTML text, empty on error + */ +function html2markdown($html) { + $markdown = ''; + $converter = new HtmlConverter(); + + try { + $markdown = $converter->convert($html); + } catch (InvalidArgumentException $e) { + logger("Invalid HTML. HTMLToMarkdown library threw an exception."); + } + + // The old html 2 markdown library "pixel418/markdownify": "^2.2", + //$md = new HtmlConverter(); + //$markdown = $md->convert($Text); + return $markdown; +} -- cgit v1.2.3 From bfad624528499e27125fae18799940319fc32c6d Mon Sep 17 00:00:00 2001 From: zotlabs Date: Tue, 30 May 2017 18:36:19 -0700 Subject: re-arrange a few functions --- include/bbcode.php | 60 ++++++++++++++++++++++++++++++++++++++++++++++ include/markdown.php | 67 ---------------------------------------------------- include/text.php | 8 +++++++ 3 files changed, 68 insertions(+), 67 deletions(-) (limited to 'include') diff --git a/include/bbcode.php b/include/bbcode.php index d38397be7..d12630e23 100644 --- a/include/bbcode.php +++ b/include/bbcode.php @@ -9,6 +9,66 @@ require_once('include/event.php'); require_once('include/zot.php'); +function get_bb_tag_pos($s, $name, $occurance = 1) { + + if($occurance < 1) + $occurance = 1; + + $start_open = -1; + for($i = 1; $i <= $occurance; $i++) { + if( $start_open !== false) + $start_open = strpos($s, '[' . $name, $start_open + 1); // allow [name= type tags + } + + if( $start_open === false) + return false; + + $start_equal = strpos($s, '=', $start_open); + $start_close = strpos($s, ']', $start_open); + + if( $start_close === false) + return false; + + $start_close++; + + $end_open = strpos($s, '[/' . $name . ']', $start_close); + + if( $end_open === false) + return false; + + $res = array( 'start' => array('open' => $start_open, 'close' => $start_close), + 'end' => array('open' => $end_open, 'close' => $end_open + strlen('[/' . $name . ']')) ); + if( $start_equal !== false) + $res['start']['equal'] = $start_equal + 1; + + return $res; +} + +function bb_tag_preg_replace($pattern, $replace, $name, $s) { + + $string = $s; + + $occurance = 1; + $pos = get_bb_tag_pos($string, $name, $occurance); + while($pos !== false && $occurance < 1000) { + + $start = substr($string, 0, $pos['start']['open']); + $subject = substr($string, $pos['start']['open'], $pos['end']['close'] - $pos['start']['open']); + $end = substr($string, $pos['end']['close']); + if($end === false) + $end = ''; + + $subject = preg_replace($pattern, $replace, $subject); + $string = $start . $subject . $end; + + $occurance++; + $pos = get_bb_tag_pos($string, $name, $occurance); + } + + return $string; +} + + function tryoembed($match) { $url = ((count($match) == 2) ? $match[1] : $match[2]); diff --git a/include/markdown.php b/include/markdown.php index 947b5c5e3..9201993df 100644 --- a/include/markdown.php +++ b/include/markdown.php @@ -13,73 +13,6 @@ require_once("include/html2bbcode.php"); require_once("include/bbcode.php"); -function get_bb_tag_pos($s, $name, $occurance = 1) { - - if($occurance < 1) - $occurance = 1; - - $start_open = -1; - for($i = 1; $i <= $occurance; $i++) { - if( $start_open !== false) - $start_open = strpos($s, '[' . $name, $start_open + 1); // allow [name= type tags - } - - if( $start_open === false) - return false; - - $start_equal = strpos($s, '=', $start_open); - $start_close = strpos($s, ']', $start_open); - - if( $start_close === false) - return false; - - $start_close++; - - $end_open = strpos($s, '[/' . $name . ']', $start_close); - - if( $end_open === false) - return false; - - $res = array( 'start' => array('open' => $start_open, 'close' => $start_close), - 'end' => array('open' => $end_open, 'close' => $end_open + strlen('[/' . $name . ']')) ); - if( $start_equal !== false) - $res['start']['equal'] = $start_equal + 1; - - return $res; -} - -function bb_tag_preg_replace($pattern, $replace, $name, $s) { - - $string = $s; - - $occurance = 1; - $pos = get_bb_tag_pos($string, $name, $occurance); - while($pos !== false && $occurance < 1000) { - - $start = substr($string, 0, $pos['start']['open']); - $subject = substr($string, $pos['start']['open'], $pos['end']['close'] - $pos['start']['open']); - $end = substr($string, $pos['end']['close']); - if($end === false) - $end = ''; - - $subject = preg_replace($pattern, $replace, $subject); - $string = $start . $subject . $end; - - $occurance++; - $pos = get_bb_tag_pos($string, $name, $occurance); - } - - return $string; -} - -function share_shield($m) { - return str_replace($m[1],'!=+=+=!' . base64url_encode($m[1]) . '=+!=+!=',$m[0]); -} - -function share_unshield($m) { - $x = str_replace(array('!=+=+=!','=+!=+!='),array('',''),$m[1]); - return str_replace($m[1], base64url_decode($x), $m[0]); -} /** * @brief diff --git a/include/text.php b/include/text.php index 0666a5e0d..1a4cb7ced 100644 --- a/include/text.php +++ b/include/text.php @@ -3082,6 +3082,14 @@ function create_table_from_array($table, $arr) { return $r; } +function share_shield($m) { + return str_replace($m[1],'!=+=+=!' . base64url_encode($m[1]) . '=+!=+!=',$m[0]); +} + +function share_unshield($m) { + $x = str_replace(array('!=+=+=!','=+!=+!='),array('',''),$m[1]); + return str_replace($m[1], base64url_decode($x), $m[0]); +} function cleanup_bbcode($body) { -- cgit v1.2.3 From dfc0d4cf59a9de98bc088c80e75877d9fc9fcab9 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Tue, 30 May 2017 19:50:41 -0700 Subject: move code syntax highlighting to plugin --- include/bbcode.php | 5 +---- include/text.php | 39 ++++++--------------------------------- 2 files changed, 7 insertions(+), 37 deletions(-) (limited to 'include') diff --git a/include/bbcode.php b/include/bbcode.php index d12630e23..6805f008c 100644 --- a/include/bbcode.php +++ b/include/bbcode.php @@ -615,10 +615,7 @@ function bb_code_options($match) { } function bb_highlight($match) { - $lang = ((in_array(strtolower($match[1]),['php','css','mysql','sql','abap','diff','html','perl','ruby', - 'vbscript','avrc','dtd','java','xml','cpp','python','javascript','js','json','sh'])) - ? strtolower($match[1]) : 'php' ); - return text_highlight($match[2],$lang); + return text_highlight($match[2],strtolower($match[1])); } function bb_fixtable_lf($match) { diff --git a/include/text.php b/include/text.php index 1a4cb7ced..c791b50ee 100644 --- a/include/text.php +++ b/include/text.php @@ -2985,40 +2985,13 @@ function text_highlight($s, $lang) { $s = jindent($s); } - if(! strpos('Text_Highlighter', get_include_path())) { - set_include_path(get_include_path() . PATH_SEPARATOR . 'library/Text_Highlighter'); - } - require_once('library/Text_Highlighter/Text/Highlighter.php'); - require_once('library/Text_Highlighter/Text/Highlighter/Renderer/Html.php'); - $options = array( - 'numbers' => HL_NUMBERS_LI, - 'tabsize' => 4, - ); - $tag_added = false; - $s = trim(html_entity_decode($s, ENT_COMPAT)); - $s = str_replace(" ", "\t", $s); - - // The highlighter library insists on an opening php tag for php code blocks. If - // it isn't present, nothing is highlighted. So we're going to see if it's present. - // If not, we'll add it, and then quietly remove it after we get the processed output back. - - if($lang === 'php') { - if(strpos('setRenderer($renderer); - $o = $hl->highlight($s); - $o = str_replace([" ", "\n"], ["    ", ''], $o); + $arr = [ 'text' => $s, 'language' => $lang, 'success' => false ]; + call_hooks('text_highlight',$arr); - if($tag_added) { - $b = substr($o, 0, strpos($o, '
  • ')); - $e = substr($o, strpos($o, '
  • ')); - $o = $b . $e; - } + if($arr['success']) + $o = $arr['text']; + else + $o = $s; return('' . $o . ''); } -- cgit v1.2.3 From 98c18f416a4c809059f4cdf27a833bb9b1134280 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Wed, 31 May 2017 16:00:33 -0700 Subject: remove default for text/mediumtext sql fields --- include/connections.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include') diff --git a/include/connections.php b/include/connections.php index 0e9f25c8f..a2bc11773 100644 --- a/include/connections.php +++ b/include/connections.php @@ -629,7 +629,7 @@ function get_vcard_array($vc,$id) { 'address' => $adr->getParts() ]; $last_entry = end($adrs); - if($last_entry && $adrs[$last_entry]['address']) + if($last_entry && is_array($adrs[$last_entry]['address'])) array_walk($adrs[$last_entry]['address'],'array_escape_tags'); } } -- cgit v1.2.3 From 35debe46bc0a10f3bad21303e127cb29526c94a2 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Wed, 31 May 2017 18:14:12 -0700 Subject: a slight tweak to author_is_pmable hook to make it useful --- include/conversation.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'include') diff --git a/include/conversation.php b/include/conversation.php index b6832e22c..3f9ee5cfa 100644 --- a/include/conversation.php +++ b/include/conversation.php @@ -909,9 +909,9 @@ function thread_action_menu($item,$mode = '') { } -function author_is_pmable($xchan) { +function author_is_pmable($xchan, $abook) { - $x = [ 'xchan' => $xchan, 'result' => 'unset' ]; + $x = [ 'xchan' => $xchan, 'abook' => $abook, 'result' => 'unset' ]; call_hooks('author_is_pmable',$x); if($x['result'] !== 'unset') return $x['result']; @@ -941,7 +941,7 @@ function thread_author_menu($item, $mode = '') { } $profile_link = chanlink_hash($item['author_xchan']); - + $contact = false; if(App::$contacts && array_key_exists($item['author_xchan'],App::$contacts)) $contact = App::$contacts[$item['author_xchan']]; @@ -950,9 +950,9 @@ function thread_author_menu($item, $mode = '') { $follow_url = z_root() . '/follow/?f=&url=' . urlencode($item['author']['xchan_addr']); - if($item['uid'] > 0 && author_is_pmable($item['author'])) + if($item['uid'] > 0 && author_is_pmable($item['author'],$contact)) { $pm_url = z_root() . '/mail/new/?f=&hash=' . urlencode($item['author_xchan']); - + } if($contact) { -- cgit v1.2.3 From fc98bd1563ee71974d5d5c40d6ed8ed0c50f3c37 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Wed, 31 May 2017 20:59:36 -0700 Subject: minor export issue with mail --- include/channel.php | 4 ++-- include/message.php | 10 ++++++---- 2 files changed, 8 insertions(+), 6 deletions(-) (limited to 'include') diff --git a/include/channel.php b/include/channel.php index 77a4ba60f..b06c1994f 100644 --- a/include/channel.php +++ b/include/channel.php @@ -737,14 +737,14 @@ function identity_basic_export($channel_id, $sections = null) { $ret['conv'] = $r; } - $r = q("select * from mail where mail.uid = %d", + $r = q("select * from mail where channel_id = %d", intval($channel_id) ); if($r) { $m = array(); foreach($r as $rr) { xchan_mail_query($rr); - $m[] = mail_encode($rr,true); + $m[] = encode_mail($rr,true); } $ret['mail'] = $m; } diff --git a/include/message.php b/include/message.php index a394a411d..5458eeb0e 100644 --- a/include/message.php +++ b/include/message.php @@ -452,10 +452,12 @@ function private_messages_drop($channel_id, $messageitem_id, $drop_conversation intval($channel_id) ); if($z) { - q("delete from conv where guid = '%s' and uid = %d", - dbesc($x[0]['conv_guid']), - intval($channel_id) - ); + if($x[0]['conv_guid']) { + q("delete from conv where guid = '%s' and uid = %d", + dbesc($x[0]['conv_guid']), + intval($channel_id) + ); + } $m['mail'] = array(); foreach($z as $zz) { xchan_mail_query($zz); -- cgit v1.2.3 From 8ebb0006507e12f8570ea126c4146ea14b71fd7f Mon Sep 17 00:00:00 2001 From: zotlabs Date: Wed, 31 May 2017 20:59:36 -0700 Subject: minor export issue with mail --- include/channel.php | 4 ++-- include/message.php | 10 ++++++---- 2 files changed, 8 insertions(+), 6 deletions(-) (limited to 'include') diff --git a/include/channel.php b/include/channel.php index 31dca1ae5..2284b3004 100644 --- a/include/channel.php +++ b/include/channel.php @@ -736,14 +736,14 @@ function identity_basic_export($channel_id, $sections = null) { $ret['conv'] = $r; } - $r = q("select * from mail where mail.uid = %d", + $r = q("select * from mail where channel_id = %d", intval($channel_id) ); if($r) { $m = array(); foreach($r as $rr) { xchan_mail_query($rr); - $m[] = mail_encode($rr,true); + $m[] = encode_mail($rr,true); } $ret['mail'] = $m; } diff --git a/include/message.php b/include/message.php index 4e8e44adc..609ceb354 100644 --- a/include/message.php +++ b/include/message.php @@ -441,10 +441,12 @@ function private_messages_drop($channel_id, $messageitem_id, $drop_conversation intval($channel_id) ); if($z) { - q("delete from conv where guid = '%s' and uid = %d", - dbesc($x[0]['conv_guid']), - intval($channel_id) - ); + if($x[0]['conv_guid']) { + q("delete from conv where guid = '%s' and uid = %d", + dbesc($x[0]['conv_guid']), + intval($channel_id) + ); + } $m['mail'] = array(); foreach($z as $zz) { xchan_mail_query($zz); -- cgit v1.2.3 From cdfcb1ed24d950efa2a2054bec5267ecdae3fb68 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Wed, 31 May 2017 22:59:07 -0700 Subject: cleanup only --- include/photo/photo_driver.php | 5 ++--- include/photos.php | 14 +++++++------- 2 files changed, 9 insertions(+), 10 deletions(-) (limited to 'include') diff --git a/include/photo/photo_driver.php b/include/photo/photo_driver.php index cc1f3b5d0..0bf09e4d8 100644 --- a/include/photo/photo_driver.php +++ b/include/photo/photo_driver.php @@ -252,11 +252,10 @@ abstract class photo_driver { */ if(! $this->is_valid()) - return FALSE; - + return false; if((! function_exists('exif_read_data')) || ($this->getType() !== 'image/jpeg')) - return; + return false; $exif = @exif_read_data($filename,null,true); diff --git a/include/photos.php b/include/photos.php index 896f3e1f2..c3260d18c 100644 --- a/include/photos.php +++ b/include/photos.php @@ -492,15 +492,15 @@ function photos_albums_list($channel, $observer, $sort_key = 'display_path', $di $ret['success'] = true; $ret['albums'] = array(); foreach($albums as $k => $album) { - $entry = array( - 'text' => (($album['album']) ? $album['album'] : '/'), + $entry = [ + 'text' => (($album['album']) ? $album['album'] : '/'), 'shorttext' => (($album['album']) ? ellipsify($album['album'],28) : '/'), - 'jstext' => (($album['album']) ? addslashes($album['album']) : '/'), - 'total' => $album['total'], - 'url' => z_root() . '/photos/' . $channel['channel_address'] . '/album/' . $album['folder'], + 'jstext' => (($album['album']) ? addslashes($album['album']) : '/'), + 'total' => $album['total'], + 'url' => z_root() . '/photos/' . $channel['channel_address'] . '/album/' . $album['folder'], 'urlencode' => urlencode($album['album']), - 'bin2hex' => $album['folder'] - ); + 'bin2hex' => $album['folder'] + ]; $ret['albums'][] = $entry; } } -- cgit v1.2.3 From 0b740826c5cfac8b2feddcf9e482731ebc78c553 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Thu, 1 Jun 2017 21:21:38 -0700 Subject: include/socgraph - remove a few obsolete and long-deprecated functions --- include/socgraph.php | 71 ---------------------------------------------------- 1 file changed, 71 deletions(-) (limited to 'include') diff --git a/include/socgraph.php b/include/socgraph.php index d28531c43..a5b5d1378 100644 --- a/include/socgraph.php +++ b/include/socgraph.php @@ -237,77 +237,6 @@ function common_friends($uid,$xchan,$start = 0,$limit=100000000,$shuffle = false } -function count_common_friends_zcid($uid,$zcid) { - - $r = q("SELECT count(*) as total - FROM glink left join gcontact on glink.gcid = gcontact.id - where glink.zcid = %d - and gcontact.nurl in (select nurl from contact where uid = %d and self = 0 and blocked = 0 and hidden = 0 ) ", - intval($zcid), - intval($uid) - ); - - if(count($r)) - return $r[0]['total']; - - return 0; -} - -function common_friends_zcid($uid,$zcid,$start = 0, $limit = 9999,$shuffle = false) { - - if($shuffle) - $sql_extra = " order by rand() "; - else - $sql_extra = " order by gcontact.name asc "; - - $r = q("SELECT gcontact.* - FROM glink left join gcontact on glink.gcid = gcontact.id - where glink.zcid = %d - and gcontact.nurl in (select nurl from contact where uid = %d and self = 0 and blocked = 0 and hidden = 0 ) - $sql_extra limit %d offset %d", - intval($zcid), - intval($uid), - intval($limit), - intval($start) - ); - - return $r; -} - - -function count_all_friends($uid,$cid) { - - $r = q("SELECT count(*) as total - FROM glink left join gcontact on glink.gcid = gcontact.id - where glink.cid = %d and glink.uid = %d ", - intval($cid), - intval($uid) - ); - - if(count($r)) - return $r[0]['total']; - - return 0; -} - - -function all_friends($uid,$cid,$start = 0, $limit = 80) { - - $r = q("SELECT gcontact.* - FROM glink left join gcontact on glink.gcid = gcontact.id - where glink.cid = %d and glink.uid = %d - order by gcontact.name asc LIMIT %d OFFSET %d ", - intval($cid), - intval($uid), - intval($limit), - intval($start) - ); - - return $r; -} - - - function suggestion_query($uid, $myxchan, $start = 0, $limit = 80) { if((! $uid) || (! $myxchan)) -- cgit v1.2.3 From c4ed04fc827ec5a1039959e260702141083836c8 Mon Sep 17 00:00:00 2001 From: git-marijus Date: Sat, 3 Jun 2017 10:13:42 +0200 Subject: convert randprof to use chanlink_hash() instead of chanlink_url() and filter sys channels by xchan.xchan_system instead of xchan_addr != sys@% --- include/connections.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'include') diff --git a/include/connections.php b/include/connections.php index 8f4f84e1a..167f7e2c4 100644 --- a/include/connections.php +++ b/include/connections.php @@ -415,9 +415,9 @@ function random_profile() { for($i = 0; $i < $retryrandom; $i++) { - $r = q("select xchan_url from xchan left join hubloc on hubloc_hash = xchan_hash where xchan_addr not like '%s' and xchan_hidden = 0 and hubloc_connected > %s - interval %s order by $randfunc limit 1", - dbesc('sys@%'), - db_utcnow(), db_quoteinterval('30 day') + $r = q("select xchan_url, xchan_hash from xchan left join hubloc on hubloc_hash = xchan_hash where xchan_hidden = 0 and xchan_system = 0 and hubloc_connected > %s - interval %s order by $randfunc limit 1", + db_utcnow(), + db_quoteinterval('30 day') ); if(!$r) return ''; // Couldn't get a random channel @@ -425,12 +425,12 @@ function random_profile() { if($checkrandom) { $x = z_fetch_url($r[0]['xchan_url']); if($x['success']) - return $r[0]['xchan_url']; + return $r[0]['xchan_hash']; else logger('Random channel turned out to be bad.'); } else { - return $r[0]['xchan_url']; + return $r[0]['xchan_hash']; } } @@ -712,4 +712,4 @@ function vcard_query(&$r) { } } } -} \ No newline at end of file +} -- cgit v1.2.3 From c7f097ec849b05065f12246d2e647ead03f9592f Mon Sep 17 00:00:00 2001 From: zotlabs Date: Sat, 3 Jun 2017 16:00:14 -0700 Subject: make authenticated oembeds optional, default to false. --- include/oembed.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include') diff --git a/include/oembed.php b/include/oembed.php index 5865c95d5..e35a77fa3 100755 --- a/include/oembed.php +++ b/include/oembed.php @@ -134,7 +134,7 @@ function oembed_fetch_url($embedurl){ $txt = null; // we should try to cache this and avoid a lookup on each render - $zrl = is_matrix_url($embedurl); + $zrl = ((get_config('system','oembed_zrl')) ? is_matrix_url($embedurl) : false); $furl = ((local_channel() && $zrl) ? zid($embedurl) : $embedurl); -- cgit v1.2.3 From 10ecb6d3681788ae535f4168bd85f6f2fc22232f Mon Sep 17 00:00:00 2001 From: git-marijus Date: Sun, 4 Jun 2017 16:58:59 +0200 Subject: remove duplicate code --- include/nav.php | 12 ------------ 1 file changed, 12 deletions(-) (limited to 'include') diff --git a/include/nav.php b/include/nav.php index 91bade5a7..2eba2894c 100644 --- a/include/nav.php +++ b/include/nav.php @@ -215,18 +215,6 @@ EOT; $nav['admin'] = array('admin/', t('Admin'), "", t('Site Setup and Configuration'),'admin_nav_btn'); } - - /** - * - * Provide a banner/logo/whatever - * - */ - - $banner = get_config('system','banner'); - - if($banner === false) - $banner = get_config('system','sitename'); - $x = array('nav' => $nav, 'usermenu' => $userinfo ); call_hooks('nav', $x); -- cgit v1.2.3 From a94a42d60959bb3ff2dc1edcffa7237ac31bcc67 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Sun, 4 Jun 2017 19:09:05 -0700 Subject: ostatus feeds: extract photo information from posts and convert to enclosures as otherwise OStatus servers will strip them from the HTML in the feed and refuse to render them --- include/feedutils.php | 45 ++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 42 insertions(+), 3 deletions(-) (limited to 'include') diff --git a/include/feedutils.php b/include/feedutils.php index fe417f548..b658f6b0f 100644 --- a/include/feedutils.php +++ b/include/feedutils.php @@ -136,7 +136,7 @@ function get_feed_for($channel, $observer_hash, $params) { continue; /** @BUG $owner is undefined in this call */ - $atom .= atom_entry($item, $type, null, $owner, true); + $atom .= atom_entry($item, $type, null, $owner, true, '', $params['compat']); } } @@ -1306,6 +1306,28 @@ function atom_render_author($tag,$xchan) { } +function compat_photos_list($s) { + + $ret = []; + + $found = preg_match_all('/\[[zi]mg(.*?)\](.*?)\[/ism',$s,$matches,PREG_SET_ORDER); + + if($found) { + foreach($matches as $match) { + $ret[] = [ + 'href' => $match[2], + 'length' => 0, + 'type' => guess_image_type($match[2]) + ]; + + } + } + + return $ret; +} + + + /** * @brief Create an item for the Atom feed. * @@ -1319,7 +1341,8 @@ function atom_render_author($tag,$xchan) { * @param number $cid default 0 * @return void|string */ -function atom_entry($item, $type, $author, $owner, $comment = false, $cid = 0) { +function atom_entry($item, $type, $author, $owner, $comment = false, $cid = 0, $compat = false) { + if(! $item['parent']) return; @@ -1334,6 +1357,13 @@ function atom_entry($item, $type, $author, $owner, $comment = false, $cid = 0) { else $body = $item['body']; + if($compat) { + $compat_photos = compat_photos_list($body); + } + else { + $compat_photos = null; + } + $o = "\r\n\r\n\r\n"; if(is_array($author)) { @@ -1403,10 +1433,19 @@ function atom_entry($item, $type, $author, $owner, $comment = false, $cid = 0) { . (($enc['href']) ? 'href="' . $enc['href'] . '" ' : '') . (($enc['length']) ? 'length="' . $enc['length'] . '" ' : '') . (($enc['type']) ? 'type="' . $enc['type'] . '" ' : '') - . ' />'; + . ' />' . "\r\n"; } } } + if($compat_photos) { + foreach($compat_photos as $enc) { + $o .= '' . "\r\n"; + } + } if($item['term']) { foreach($item['term'] as $term) { -- cgit v1.2.3 From 2fea5ff8894c3f1f274a3ce67b2c023e39fdab6c Mon Sep 17 00:00:00 2001 From: zotlabs Date: Sun, 4 Jun 2017 20:07:08 -0700 Subject: always add a length to ostatus compat enclosures - even if unknown (0) --- include/feedutils.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include') diff --git a/include/feedutils.php b/include/feedutils.php index b658f6b0f..70222c124 100644 --- a/include/feedutils.php +++ b/include/feedutils.php @@ -1441,7 +1441,7 @@ function atom_entry($item, $type, $author, $owner, $comment = false, $cid = 0, $ foreach($compat_photos as $enc) { $o .= '' . "\r\n"; } -- cgit v1.2.3 From 83f8f8ebb8bc7e6cbbc3b71f664706e30dfe6c1c Mon Sep 17 00:00:00 2001 From: zotlabs Date: Mon, 5 Jun 2017 15:57:43 -0700 Subject: whitespace --- include/photo/photo_driver.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'include') diff --git a/include/photo/photo_driver.php b/include/photo/photo_driver.php index 0bf09e4d8..eb61578e1 100644 --- a/include/photo/photo_driver.php +++ b/include/photo/photo_driver.php @@ -488,8 +488,10 @@ function guess_image_type($filename, $headers = '') { $ext = pathinfo($filename, PATHINFO_EXTENSION); $ph = photo_factory(''); $types = $ph->supportedTypes(); - foreach ($types as $m=>$e){ - if ($ext==$e) $type = $m; + foreach($types as $m => $e) { + if($ext === $e) { + $type = $m; + } } } @@ -501,7 +503,7 @@ function guess_image_type($filename, $headers = '') { } } - logger('Photo: guess_image_type: type='.$type, LOGGER_DEBUG); + logger('Photo: guess_image_type: type = ' . $type, LOGGER_DEBUG); return $type; } -- cgit v1.2.3 From e917b949292fc83edb22d955251f8887544b772a Mon Sep 17 00:00:00 2001 From: zotlabs Date: Tue, 6 Jun 2017 17:38:34 -0700 Subject: hubzilla issue #810 --- include/taxonomy.php | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'include') diff --git a/include/taxonomy.php b/include/taxonomy.php index 0b4b2aa9a..dc0e439e2 100644 --- a/include/taxonomy.php +++ b/include/taxonomy.php @@ -44,6 +44,36 @@ function term_query($table,$s,$type = TERM_UNKNOWN, $type2 = '') { } +function term_item_parent_query($uid,$table,$s,$type = TERM_UNKNOWN, $type2 = '') { + + if($type2) { + $r = q("select parent from item left join term on term.oid = item.id where term.ttype in (%d, %d) and term.term = '%s' and term.uid = %d and term.otype = 1", + intval($type), + intval($type2), + dbesc($s), + intval($uid) + ); + } + else { + $r = q("select parent from item left join term on term.oid = item.id where term.ttype = %d and term.term = '%s' and term.uid = %d and term.otype = 1", + intval($type), + dbesc($s), + intval($uid) + ); + } + if($r) { + $str = ''; + foreach($r as $rv) { + if($str) + $str .= ','; + $str .= intval($rv['parent']); + } + return " AND " . (($table) ? dbesc($table) . '.' : '') . "id in ( $str ) "; + } + return " AND false "; +} + + function store_item_tag($uid,$iid,$otype,$type,$term,$url = '') { if(! $term) return false; -- cgit v1.2.3 From 59002cb87389159002ab8c426d475edb6d7883be Mon Sep 17 00:00:00 2001 From: zotlabs Date: Tue, 6 Jun 2017 22:49:45 -0700 Subject: Looks like we need the mastodon feed check in core - grrr. Will do that for now until it can be put back into plugins. --- include/feedutils.php | 3 +++ 1 file changed, 3 insertions(+) (limited to 'include') diff --git a/include/feedutils.php b/include/feedutils.php index 70222c124..10eb5bcc7 100644 --- a/include/feedutils.php +++ b/include/feedutils.php @@ -397,6 +397,9 @@ function get_atom_elements($feed, $item, &$author) { } $ostatus_protocol = (($item->get_item_tags(NAMESPACE_OSTATUS, 'conversation')) ? true : false); + $mastodon = (($item->get_item_tags('http://mastodon.social/schema/1.0','scope')) ? true : false); + if($mastodon) + $ostatus_protocol = true; $apps = $item->get_item_tags(NAMESPACE_STATUSNET, 'notice_info'); if($apps && $apps[0]['attribs']['']['source']) { -- cgit v1.2.3 From 3a2a7d05084b1f61b5167b287e9c8bf520a4ca5f Mon Sep 17 00:00:00 2001 From: zotlabs Date: Tue, 30 May 2017 18:36:19 -0700 Subject: re-arrange a few functions --- include/bbcode.php | 60 ++++++++++++++++++++++++++++++++++++++++++++++ include/markdown.php | 67 ---------------------------------------------------- include/text.php | 8 +++++++ 3 files changed, 68 insertions(+), 67 deletions(-) (limited to 'include') diff --git a/include/bbcode.php b/include/bbcode.php index 135368db9..4c551d6ab 100644 --- a/include/bbcode.php +++ b/include/bbcode.php @@ -9,6 +9,66 @@ require_once('include/event.php'); require_once('include/zot.php'); +function get_bb_tag_pos($s, $name, $occurance = 1) { + + if($occurance < 1) + $occurance = 1; + + $start_open = -1; + for($i = 1; $i <= $occurance; $i++) { + if( $start_open !== false) + $start_open = strpos($s, '[' . $name, $start_open + 1); // allow [name= type tags + } + + if( $start_open === false) + return false; + + $start_equal = strpos($s, '=', $start_open); + $start_close = strpos($s, ']', $start_open); + + if( $start_close === false) + return false; + + $start_close++; + + $end_open = strpos($s, '[/' . $name . ']', $start_close); + + if( $end_open === false) + return false; + + $res = array( 'start' => array('open' => $start_open, 'close' => $start_close), + 'end' => array('open' => $end_open, 'close' => $end_open + strlen('[/' . $name . ']')) ); + if( $start_equal !== false) + $res['start']['equal'] = $start_equal + 1; + + return $res; +} + +function bb_tag_preg_replace($pattern, $replace, $name, $s) { + + $string = $s; + + $occurance = 1; + $pos = get_bb_tag_pos($string, $name, $occurance); + while($pos !== false && $occurance < 1000) { + + $start = substr($string, 0, $pos['start']['open']); + $subject = substr($string, $pos['start']['open'], $pos['end']['close'] - $pos['start']['open']); + $end = substr($string, $pos['end']['close']); + if($end === false) + $end = ''; + + $subject = preg_replace($pattern, $replace, $subject); + $string = $start . $subject . $end; + + $occurance++; + $pos = get_bb_tag_pos($string, $name, $occurance); + } + + return $string; +} + + function tryoembed($match) { $url = ((count($match) == 2) ? $match[1] : $match[2]); diff --git a/include/markdown.php b/include/markdown.php index f7e9d53fc..3ade03971 100644 --- a/include/markdown.php +++ b/include/markdown.php @@ -13,73 +13,6 @@ require_once("include/html2bbcode.php"); require_once("include/bbcode.php"); -function get_bb_tag_pos($s, $name, $occurance = 1) { - - if($occurance < 1) - $occurance = 1; - - $start_open = -1; - for($i = 1; $i <= $occurance; $i++) { - if( $start_open !== false) - $start_open = strpos($s, '[' . $name, $start_open + 1); // allow [name= type tags - } - - if( $start_open === false) - return false; - - $start_equal = strpos($s, '=', $start_open); - $start_close = strpos($s, ']', $start_open); - - if( $start_close === false) - return false; - - $start_close++; - - $end_open = strpos($s, '[/' . $name . ']', $start_close); - - if( $end_open === false) - return false; - - $res = array( 'start' => array('open' => $start_open, 'close' => $start_close), - 'end' => array('open' => $end_open, 'close' => $end_open + strlen('[/' . $name . ']')) ); - if( $start_equal !== false) - $res['start']['equal'] = $start_equal + 1; - - return $res; -} - -function bb_tag_preg_replace($pattern, $replace, $name, $s) { - - $string = $s; - - $occurance = 1; - $pos = get_bb_tag_pos($string, $name, $occurance); - while($pos !== false && $occurance < 1000) { - - $start = substr($string, 0, $pos['start']['open']); - $subject = substr($string, $pos['start']['open'], $pos['end']['close'] - $pos['start']['open']); - $end = substr($string, $pos['end']['close']); - if($end === false) - $end = ''; - - $subject = preg_replace($pattern, $replace, $subject); - $string = $start . $subject . $end; - - $occurance++; - $pos = get_bb_tag_pos($string, $name, $occurance); - } - - return $string; -} - -function share_shield($m) { - return str_replace($m[1],'!=+=+=!' . base64url_encode($m[1]) . '=+!=+!=',$m[0]); -} - -function share_unshield($m) { - $x = str_replace(array('!=+=+=!','=+!=+!='),array('',''),$m[1]); - return str_replace($m[1], base64url_decode($x), $m[0]); -} function diaspora_mention_callback($matches) { diff --git a/include/text.php b/include/text.php index d352a61bf..784b46076 100644 --- a/include/text.php +++ b/include/text.php @@ -3065,6 +3065,14 @@ function create_table_from_array($table, $arr) { return $r; } +function share_shield($m) { + return str_replace($m[1],'!=+=+=!' . base64url_encode($m[1]) . '=+!=+!=',$m[0]); +} + +function share_unshield($m) { + $x = str_replace(array('!=+=+=!','=+!=+!='),array('',''),$m[1]); + return str_replace($m[1], base64url_decode($x), $m[0]); +} function cleanup_bbcode($body) { -- cgit v1.2.3 From 80c65ea8f3a9be9238125b7941ae7c875ea9a07c Mon Sep 17 00:00:00 2001 From: zotlabs Date: Tue, 30 May 2017 19:50:41 -0700 Subject: move code syntax highlighting to plugin --- include/bbcode.php | 5 +---- include/text.php | 39 ++++++--------------------------------- 2 files changed, 7 insertions(+), 37 deletions(-) (limited to 'include') diff --git a/include/bbcode.php b/include/bbcode.php index 4c551d6ab..0d2fb8c74 100644 --- a/include/bbcode.php +++ b/include/bbcode.php @@ -615,10 +615,7 @@ function bb_code_options($match) { } function bb_highlight($match) { - $lang = ((in_array(strtolower($match[1]),['php','css','mysql','sql','abap','diff','html','perl','ruby', - 'vbscript','avrc','dtd','java','xml','cpp','python','javascript','js','json','sh'])) - ? strtolower($match[1]) : 'php' ); - return text_highlight($match[2],$lang); + return text_highlight($match[2],strtolower($match[1])); } function bb_fixtable_lf($match) { diff --git a/include/text.php b/include/text.php index 784b46076..6f5c48679 100644 --- a/include/text.php +++ b/include/text.php @@ -2969,40 +2969,13 @@ function text_highlight($s, $lang) { $s = jindent($s); } - if(! strpos('Text_Highlighter', get_include_path())) { - set_include_path(get_include_path() . PATH_SEPARATOR . 'library/Text_Highlighter'); - } - require_once('library/Text_Highlighter/Text/Highlighter.php'); - require_once('library/Text_Highlighter/Text/Highlighter/Renderer/Html.php'); - $options = array( - 'numbers' => HL_NUMBERS_LI, - 'tabsize' => 4, - ); - $tag_added = false; - $s = trim(html_entity_decode($s, ENT_COMPAT)); - $s = str_replace(" ", "\t", $s); - - // The highlighter library insists on an opening php tag for php code blocks. If - // it isn't present, nothing is highlighted. So we're going to see if it's present. - // If not, we'll add it, and then quietly remove it after we get the processed output back. - - if($lang === 'php') { - if(strpos('setRenderer($renderer); - $o = $hl->highlight($s); - $o = str_replace([" ", "\n"], ["    ", ''], $o); + $arr = [ 'text' => $s, 'language' => $lang, 'success' => false ]; + call_hooks('text_highlight',$arr); - if($tag_added) { - $b = substr($o, 0, strpos($o, '
  • ')); - $e = substr($o, strpos($o, '
  • ')); - $o = $b . $e; - } + if($arr['success']) + $o = $arr['text']; + else + $o = $s; return('' . $o . ''); } -- cgit v1.2.3 From 324d427ac722d25067a3b296fd0705385c1a4e6a Mon Sep 17 00:00:00 2001 From: zotlabs Date: Wed, 31 May 2017 18:14:12 -0700 Subject: a slight tweak to author_is_pmable hook to make it useful --- include/conversation.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'include') diff --git a/include/conversation.php b/include/conversation.php index 0f940b1a3..c325a516f 100644 --- a/include/conversation.php +++ b/include/conversation.php @@ -917,9 +917,9 @@ function thread_action_menu($item,$mode = '') { } -function author_is_pmable($xchan) { +function author_is_pmable($xchan, $abook) { - $x = [ 'xchan' => $xchan, 'result' => 'unset' ]; + $x = [ 'xchan' => $xchan, 'abook' => $abook, 'result' => 'unset' ]; call_hooks('author_is_pmable',$x); if($x['result'] !== 'unset') return $x['result']; @@ -949,7 +949,7 @@ function thread_author_menu($item, $mode = '') { } $profile_link = chanlink_hash($item['author_xchan']); - + $contact = false; if(App::$contacts && array_key_exists($item['author_xchan'],App::$contacts)) $contact = App::$contacts[$item['author_xchan']]; @@ -958,9 +958,9 @@ function thread_author_menu($item, $mode = '') { $follow_url = z_root() . '/follow/?f=&url=' . urlencode($item['author']['xchan_addr']); - if($item['uid'] > 0 && author_is_pmable($item['author'])) + if($item['uid'] > 0 && author_is_pmable($item['author'],$contact)) { $pm_url = z_root() . '/mail/new/?f=&hash=' . urlencode($item['author_xchan']); - + } if($contact) { -- cgit v1.2.3 From c96fe2931a43614f209ce19e2cec507fc5b6c8f3 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Wed, 31 May 2017 22:59:07 -0700 Subject: cleanup only --- include/photo/photo_driver.php | 5 ++--- include/photos.php | 14 +++++++------- 2 files changed, 9 insertions(+), 10 deletions(-) (limited to 'include') diff --git a/include/photo/photo_driver.php b/include/photo/photo_driver.php index cc1f3b5d0..0bf09e4d8 100644 --- a/include/photo/photo_driver.php +++ b/include/photo/photo_driver.php @@ -252,11 +252,10 @@ abstract class photo_driver { */ if(! $this->is_valid()) - return FALSE; - + return false; if((! function_exists('exif_read_data')) || ($this->getType() !== 'image/jpeg')) - return; + return false; $exif = @exif_read_data($filename,null,true); diff --git a/include/photos.php b/include/photos.php index 8a7e49df6..de5e08646 100644 --- a/include/photos.php +++ b/include/photos.php @@ -495,15 +495,15 @@ function photos_albums_list($channel, $observer, $sort_key = 'display_path', $di $ret['success'] = true; $ret['albums'] = array(); foreach($albums as $k => $album) { - $entry = array( - 'text' => (($album['album']) ? $album['album'] : '/'), + $entry = [ + 'text' => (($album['album']) ? $album['album'] : '/'), 'shorttext' => (($album['album']) ? ellipsify($album['album'],28) : '/'), - 'jstext' => (($album['album']) ? addslashes($album['album']) : '/'), - 'total' => $album['total'], - 'url' => z_root() . '/photos/' . $channel['channel_address'] . '/album/' . $album['folder'], + 'jstext' => (($album['album']) ? addslashes($album['album']) : '/'), + 'total' => $album['total'], + 'url' => z_root() . '/photos/' . $channel['channel_address'] . '/album/' . $album['folder'], 'urlencode' => urlencode($album['album']), - 'bin2hex' => $album['folder'] - ); + 'bin2hex' => $album['folder'] + ]; $ret['albums'][] = $entry; } } -- cgit v1.2.3 From 1d3c6e7420fa0c156eb94fc1a388aa7e0c25eadc Mon Sep 17 00:00:00 2001 From: zotlabs Date: Thu, 1 Jun 2017 21:21:38 -0700 Subject: include/socgraph - remove a few obsolete and long-deprecated functions --- include/socgraph.php | 71 ---------------------------------------------------- 1 file changed, 71 deletions(-) (limited to 'include') diff --git a/include/socgraph.php b/include/socgraph.php index 69365f80f..9a6245d01 100644 --- a/include/socgraph.php +++ b/include/socgraph.php @@ -243,77 +243,6 @@ function common_friends($uid,$xchan,$start = 0,$limit=100000000,$shuffle = false } -function count_common_friends_zcid($uid,$zcid) { - - $r = q("SELECT count(*) as total - FROM glink left join gcontact on glink.gcid = gcontact.id - where glink.zcid = %d - and gcontact.nurl in (select nurl from contact where uid = %d and self = 0 and blocked = 0 and hidden = 0 ) ", - intval($zcid), - intval($uid) - ); - - if(count($r)) - return $r[0]['total']; - - return 0; -} - -function common_friends_zcid($uid,$zcid,$start = 0, $limit = 9999,$shuffle = false) { - - if($shuffle) - $sql_extra = " order by rand() "; - else - $sql_extra = " order by gcontact.name asc "; - - $r = q("SELECT gcontact.* - FROM glink left join gcontact on glink.gcid = gcontact.id - where glink.zcid = %d - and gcontact.nurl in (select nurl from contact where uid = %d and self = 0 and blocked = 0 and hidden = 0 ) - $sql_extra limit %d offset %d", - intval($zcid), - intval($uid), - intval($limit), - intval($start) - ); - - return $r; -} - - -function count_all_friends($uid,$cid) { - - $r = q("SELECT count(*) as total - FROM glink left join gcontact on glink.gcid = gcontact.id - where glink.cid = %d and glink.uid = %d ", - intval($cid), - intval($uid) - ); - - if(count($r)) - return $r[0]['total']; - - return 0; -} - - -function all_friends($uid,$cid,$start = 0, $limit = 80) { - - $r = q("SELECT gcontact.* - FROM glink left join gcontact on glink.gcid = gcontact.id - where glink.cid = %d and glink.uid = %d - order by gcontact.name asc LIMIT %d OFFSET %d ", - intval($cid), - intval($uid), - intval($limit), - intval($start) - ); - - return $r; -} - - - function suggestion_query($uid, $myxchan, $start = 0, $limit = 80) { if((! $uid) || (! $myxchan)) -- cgit v1.2.3 From 928fce875e712614e985ae2eaf8cc4f47615fe27 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Sat, 3 Jun 2017 16:00:14 -0700 Subject: make authenticated oembeds optional, default to false. --- include/oembed.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include') diff --git a/include/oembed.php b/include/oembed.php index 5865c95d5..e35a77fa3 100755 --- a/include/oembed.php +++ b/include/oembed.php @@ -134,7 +134,7 @@ function oembed_fetch_url($embedurl){ $txt = null; // we should try to cache this and avoid a lookup on each render - $zrl = is_matrix_url($embedurl); + $zrl = ((get_config('system','oembed_zrl')) ? is_matrix_url($embedurl) : false); $furl = ((local_channel() && $zrl) ? zid($embedurl) : $embedurl); -- cgit v1.2.3 From 36d40866738ca81a31002251d4ca63f1087d8054 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Sun, 4 Jun 2017 19:09:05 -0700 Subject: ostatus feeds: extract photo information from posts and convert to enclosures as otherwise OStatus servers will strip them from the HTML in the feed and refuse to render them --- include/feedutils.php | 45 ++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 42 insertions(+), 3 deletions(-) (limited to 'include') diff --git a/include/feedutils.php b/include/feedutils.php index 6c411723a..1563bdb41 100644 --- a/include/feedutils.php +++ b/include/feedutils.php @@ -136,7 +136,7 @@ function get_feed_for($channel, $observer_hash, $params) { continue; /** @BUG $owner is undefined in this call */ - $atom .= atom_entry($item, $type, null, $owner, true); + $atom .= atom_entry($item, $type, null, $owner, true, '', $params['compat']); } } @@ -1306,6 +1306,28 @@ function atom_render_author($tag,$xchan) { } +function compat_photos_list($s) { + + $ret = []; + + $found = preg_match_all('/\[[zi]mg(.*?)\](.*?)\[/ism',$s,$matches,PREG_SET_ORDER); + + if($found) { + foreach($matches as $match) { + $ret[] = [ + 'href' => $match[2], + 'length' => 0, + 'type' => guess_image_type($match[2]) + ]; + + } + } + + return $ret; +} + + + /** * @brief Create an item for the Atom feed. * @@ -1319,7 +1341,8 @@ function atom_render_author($tag,$xchan) { * @param number $cid default 0 * @return void|string */ -function atom_entry($item, $type, $author, $owner, $comment = false, $cid = 0) { +function atom_entry($item, $type, $author, $owner, $comment = false, $cid = 0, $compat = false) { + if(! $item['parent']) return; @@ -1334,6 +1357,13 @@ function atom_entry($item, $type, $author, $owner, $comment = false, $cid = 0) { else $body = $item['body']; + if($compat) { + $compat_photos = compat_photos_list($body); + } + else { + $compat_photos = null; + } + $o = "\r\n\r\n\r\n"; if(is_array($author)) { @@ -1403,10 +1433,19 @@ function atom_entry($item, $type, $author, $owner, $comment = false, $cid = 0) { . (($enc['href']) ? 'href="' . $enc['href'] . '" ' : '') . (($enc['length']) ? 'length="' . $enc['length'] . '" ' : '') . (($enc['type']) ? 'type="' . $enc['type'] . '" ' : '') - . ' />'; + . ' />' . "\r\n"; } } } + if($compat_photos) { + foreach($compat_photos as $enc) { + $o .= '' . "\r\n"; + } + } if($item['term']) { foreach($item['term'] as $term) { -- cgit v1.2.3 From cdfd42053d4920bc2c7c508d512ad3c7033d8095 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Sun, 4 Jun 2017 20:07:08 -0700 Subject: always add a length to ostatus compat enclosures - even if unknown (0) --- include/feedutils.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include') diff --git a/include/feedutils.php b/include/feedutils.php index 1563bdb41..5f86ad5a4 100644 --- a/include/feedutils.php +++ b/include/feedutils.php @@ -1441,7 +1441,7 @@ function atom_entry($item, $type, $author, $owner, $comment = false, $cid = 0, $ foreach($compat_photos as $enc) { $o .= '' . "\r\n"; } -- cgit v1.2.3 From f5b593ff42af57bed4062e86a8b8c46d0eb36e30 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Mon, 5 Jun 2017 15:57:43 -0700 Subject: whitespace --- include/photo/photo_driver.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'include') diff --git a/include/photo/photo_driver.php b/include/photo/photo_driver.php index 0bf09e4d8..eb61578e1 100644 --- a/include/photo/photo_driver.php +++ b/include/photo/photo_driver.php @@ -488,8 +488,10 @@ function guess_image_type($filename, $headers = '') { $ext = pathinfo($filename, PATHINFO_EXTENSION); $ph = photo_factory(''); $types = $ph->supportedTypes(); - foreach ($types as $m=>$e){ - if ($ext==$e) $type = $m; + foreach($types as $m => $e) { + if($ext === $e) { + $type = $m; + } } } @@ -501,7 +503,7 @@ function guess_image_type($filename, $headers = '') { } } - logger('Photo: guess_image_type: type='.$type, LOGGER_DEBUG); + logger('Photo: guess_image_type: type = ' . $type, LOGGER_DEBUG); return $type; } -- cgit v1.2.3 From 108b052e4eedc8d0002c34802d4a96faee4a7cd6 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Tue, 6 Jun 2017 17:38:34 -0700 Subject: hubzilla issue #810 --- include/taxonomy.php | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'include') diff --git a/include/taxonomy.php b/include/taxonomy.php index 0b4b2aa9a..dc0e439e2 100644 --- a/include/taxonomy.php +++ b/include/taxonomy.php @@ -44,6 +44,36 @@ function term_query($table,$s,$type = TERM_UNKNOWN, $type2 = '') { } +function term_item_parent_query($uid,$table,$s,$type = TERM_UNKNOWN, $type2 = '') { + + if($type2) { + $r = q("select parent from item left join term on term.oid = item.id where term.ttype in (%d, %d) and term.term = '%s' and term.uid = %d and term.otype = 1", + intval($type), + intval($type2), + dbesc($s), + intval($uid) + ); + } + else { + $r = q("select parent from item left join term on term.oid = item.id where term.ttype = %d and term.term = '%s' and term.uid = %d and term.otype = 1", + intval($type), + dbesc($s), + intval($uid) + ); + } + if($r) { + $str = ''; + foreach($r as $rv) { + if($str) + $str .= ','; + $str .= intval($rv['parent']); + } + return " AND " . (($table) ? dbesc($table) . '.' : '') . "id in ( $str ) "; + } + return " AND false "; +} + + function store_item_tag($uid,$iid,$otype,$type,$term,$url = '') { if(! $term) return false; -- cgit v1.2.3 From bea0a491cf319946a11c9a5b8e913e4cfc8b08d0 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Tue, 6 Jun 2017 22:49:45 -0700 Subject: Looks like we need the mastodon feed check in core - grrr. Will do that for now until it can be put back into plugins. --- include/feedutils.php | 3 +++ 1 file changed, 3 insertions(+) (limited to 'include') diff --git a/include/feedutils.php b/include/feedutils.php index 5f86ad5a4..708532013 100644 --- a/include/feedutils.php +++ b/include/feedutils.php @@ -397,6 +397,9 @@ function get_atom_elements($feed, $item, &$author) { } $ostatus_protocol = (($item->get_item_tags(NAMESPACE_OSTATUS, 'conversation')) ? true : false); + $mastodon = (($item->get_item_tags('http://mastodon.social/schema/1.0','scope')) ? true : false); + if($mastodon) + $ostatus_protocol = true; $apps = $item->get_item_tags(NAMESPACE_STATUSNET, 'notice_info'); if($apps && $apps[0]['attribs']['']['source']) { -- cgit v1.2.3 From 2e35dc648fd61ae2d39e8c46c14dbf19d31942fb Mon Sep 17 00:00:00 2001 From: zotlabs Date: Wed, 7 Jun 2017 16:26:24 -0700 Subject: provide hook when deleting a connection - we need this to clean up dangling PuSH subscriptions --- include/connections.php | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'include') diff --git a/include/connections.php b/include/connections.php index a2bc11773..c4c719ab8 100644 --- a/include/connections.php +++ b/include/connections.php @@ -341,6 +341,11 @@ function contact_remove($channel_id, $abook_id) { logger('removing contact ' . $abook_id . ' for channel ' . $channel_id,LOGGER_DEBUG); + + $x = [ 'channel_id' => $channel_id, 'abook_id' => $abook_id ]; + call_hooks('connection_remove',$x); + + $archive = get_pconfig($channel_id, 'system','archive_removed_contacts'); if($archive) { q("update abook set abook_archived = 1 where abook_id = %d and abook_channel = %d", -- cgit v1.2.3 From 2e692fca93158748f99eab651bd0782b27044b8d Mon Sep 17 00:00:00 2001 From: zotlabs Date: Wed, 7 Jun 2017 20:28:59 -0700 Subject: partial fix for failure to sync photos - appears to be memory exhaustion and dependent on filesize although an unrelated issue was found with directory creation during file sync (we didn't check ownership when looking for duplicates). This checkin provides the means for a sync process to fetch the contents for various photo scales from the original server just as is done for the attach data now. It is still missing the bit for the sync process to spawn a mob of children to fetch these suckers and update the photo table with the results. --- include/import.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'include') diff --git a/include/import.php b/include/import.php index f219bc780..a8a70a5f2 100644 --- a/include/import.php +++ b/include/import.php @@ -1084,11 +1084,12 @@ function sync_files($channel, $files) { $ext = ''; } - $r = q("select filename from attach where ( filename = '%s' OR filename like '%s' ) and folder = '%s' and hash != '%s' ", + $r = q("select filename from attach where ( filename = '%s' OR filename like '%s' ) and folder = '%s' and hash != '%s' and uid = %d ", dbesc($basename . $ext), dbesc($basename . '(%)' . $ext), dbesc($att['folder']), - dbesc($att['hash']) + dbesc($att['hash']), + intval($channel['channel_id']) ); if($r) { -- cgit v1.2.3 From 4f3b1edf9d05830a6851f4b6570b8a0ec836b6ab Mon Sep 17 00:00:00 2001 From: zotlabs Date: Wed, 7 Jun 2017 20:44:44 -0700 Subject: it appears to also work a bit better if you don't use imaginary function names --- include/import.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include') diff --git a/include/import.php b/include/import.php index a8a70a5f2..277d6618c 100644 --- a/include/import.php +++ b/include/import.php @@ -1255,7 +1255,7 @@ function sync_files($channel, $files) { $r = dbq("update photo set " . $str . " where id = " . intval($exists[0]['id']) ); } else { - create_attach_from_array('photo',$p); + create_table_from_array('photo',$p); } } } -- cgit v1.2.3 From 005baea319585299b8d12eb0b4707f44711c5210 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Wed, 7 Jun 2017 21:49:50 -0700 Subject: fall back on feed logo if an author avatar cannot be found --- include/feedutils.php | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'include') diff --git a/include/feedutils.php b/include/feedutils.php index 10eb5bcc7..c530b7be7 100644 --- a/include/feedutils.php +++ b/include/feedutils.php @@ -1185,6 +1185,10 @@ function feed_meta($xml) { } } + if(! $author['author_photo']) + $author['author_photo'] = $feed->get_image_url(); + + if(substr($author['author_link'],-1,1) == '/') $author['author_link'] = substr($author['author_link'],0,-1); -- cgit v1.2.3 From 492665a8a15454a5a409e1af3c6acaf1c7890036 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Wed, 7 Jun 2017 16:26:24 -0700 Subject: provide hook when deleting a connection - we need this to clean up dangling PuSH subscriptions --- include/connections.php | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'include') diff --git a/include/connections.php b/include/connections.php index 167f7e2c4..85b961b65 100644 --- a/include/connections.php +++ b/include/connections.php @@ -341,6 +341,11 @@ function contact_remove($channel_id, $abook_id) { logger('removing contact ' . $abook_id . ' for channel ' . $channel_id,LOGGER_DEBUG); + + $x = [ 'channel_id' => $channel_id, 'abook_id' => $abook_id ]; + call_hooks('connection_remove',$x); + + $archive = get_pconfig($channel_id, 'system','archive_removed_contacts'); if($archive) { q("update abook set abook_archived = 1 where abook_id = %d and abook_channel = %d", -- cgit v1.2.3 From 30358100ab729e7ce7bd3f05cc64a391239906e0 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Wed, 7 Jun 2017 20:28:59 -0700 Subject: partial fix for failure to sync photos - appears to be memory exhaustion and dependent on filesize although an unrelated issue was found with directory creation during file sync (we didn't check ownership when looking for duplicates). This checkin provides the means for a sync process to fetch the contents for various photo scales from the original server just as is done for the attach data now. It is still missing the bit for the sync process to spawn a mob of children to fetch these suckers and update the photo table with the results. --- include/import.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'include') diff --git a/include/import.php b/include/import.php index 3b5ddd1f1..01f356f2f 100644 --- a/include/import.php +++ b/include/import.php @@ -1093,11 +1093,12 @@ function sync_files($channel, $files) { $ext = ''; } - $r = q("select filename from attach where ( filename = '%s' OR filename like '%s' ) and folder = '%s' and hash != '%s' ", + $r = q("select filename from attach where ( filename = '%s' OR filename like '%s' ) and folder = '%s' and hash != '%s' and uid = %d ", dbesc($basename . $ext), dbesc($basename . '(%)' . $ext), dbesc($att['folder']), - dbesc($att['hash']) + dbesc($att['hash']), + intval($channel['channel_id']) ); if($r) { -- cgit v1.2.3 From 912be5a792b286f844a2c933fd5f7775a34887a4 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Wed, 7 Jun 2017 20:44:44 -0700 Subject: it appears to also work a bit better if you don't use imaginary function names --- include/import.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include') diff --git a/include/import.php b/include/import.php index 01f356f2f..faab29bc0 100644 --- a/include/import.php +++ b/include/import.php @@ -1264,7 +1264,7 @@ function sync_files($channel, $files) { $r = dbq("update photo set " . $str . " where id = " . intval($exists[0]['id']) ); } else { - create_attach_from_array('photo',$p); + create_table_from_array('photo',$p); } } } -- cgit v1.2.3 From 3563568f6f965c755323a233a99a60e3b0b85102 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Wed, 7 Jun 2017 21:49:50 -0700 Subject: fall back on feed logo if an author avatar cannot be found --- include/feedutils.php | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'include') diff --git a/include/feedutils.php b/include/feedutils.php index 708532013..f1cee4194 100644 --- a/include/feedutils.php +++ b/include/feedutils.php @@ -1185,6 +1185,10 @@ function feed_meta($xml) { } } + if(! $author['author_photo']) + $author['author_photo'] = $feed->get_image_url(); + + if(substr($author['author_link'],-1,1) == '/') $author['author_link'] = substr($author['author_link'],0,-1); -- cgit v1.2.3 From 97732f70063325ac875498a413e9ac1b6fca51f5 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Wed, 26 Apr 2017 23:05:30 -0700 Subject: more client-side mail privacy work --- include/items.php | 15 +++++++++++++-- include/message.php | 19 +++++++++++++++---- 2 files changed, 28 insertions(+), 6 deletions(-) (limited to 'include') diff --git a/include/items.php b/include/items.php index f7fddad33..5010dedb2 100755 --- a/include/items.php +++ b/include/items.php @@ -1359,6 +1359,8 @@ function encode_mail($item,$extended = false) { $x['body'] = $item['body']; $x['from'] = encode_item_xchan($item['from']); $x['to'] = encode_item_xchan($item['to']); + $x['raw'] = $item['mail_raw']; + $x['mimetype'] = $item['mail_mimetype']; if($item['attach']) $x['attach'] = json_decode($item['attach'],true); @@ -1392,9 +1394,16 @@ function get_mail_elements($x) { $arr = array(); - $arr['body'] = (($x['body']) ? htmlspecialchars($x['body'], ENT_COMPAT,'UTF-8',false) : ''); - $arr['title'] = (($x['title'])? htmlspecialchars($x['title'],ENT_COMPAT,'UTF-8',false) : ''); + if(intval($x['raw'])) { + $arr['mail_raw'] = intval($x['raw']); + $arr['body'] = $x['body']; + } + else { + $arr['body'] = (($x['body']) ? htmlspecialchars($x['body'], ENT_COMPAT,'UTF-8',false) : ''); + } + $arr['title'] = (($x['title'])? htmlspecialchars($x['title'],ENT_COMPAT,'UTF-8',false) : ''); + $arr['mail_mimetype'] = (($x['mimetype']) ? htmlspecialchars($x['mimetype'],ENT_COMPAT,'UTF-8',false) : 'text/bbcode'); $arr['conv_guid'] = (($x['conv_guid'])? htmlspecialchars($x['conv_guid'],ENT_COMPAT,'UTF-8',false) : ''); $arr['created'] = datetime_convert('UTC','UTC',$x['created']); @@ -3032,8 +3041,10 @@ function mail_store($arr) { $arr['body'] = ((x($arr,'body')) ? trim($arr['body']) : ''); $arr['sig'] = ((x($arr,'sig')) ? trim($arr['sig']) : ''); $arr['conv_guid'] = ((x($arr,'conv_guid')) ? trim($arr['conv_guid']) : ''); + $arr['mail_mimetype'] = ((x($arr,'mail_mimetype')) ? trim($arr['mail_mimetype']) : 'text/bbcode'); $arr['mail_flags'] = ((x($arr,'mail_flags')) ? intval($arr['mail_flags']) : 0 ); + $arr['mail_raw'] = ((x($arr,'mail_raw')) ? intval($arr['mail_raw']) : 0 ); if(! $arr['parent_mid']) { logger('mail_store: missing parent'); diff --git a/include/message.php b/include/message.php index 609ceb354..5458eeb0e 100644 --- a/include/message.php +++ b/include/message.php @@ -5,10 +5,20 @@ require_once('include/crypto.php'); require_once('include/attach.php'); + +function mail_prepare_binary($item) { + + return replace_macros(get_markup_template('item_binary.tpl'), [ + '$download' => t('Download binary/encrypted content'), + '$url' => z_root() . '/mail/' . $item['id'] . '/download' + ]); +} + + // send a private message -function send_message($uid = 0, $recipient = '', $body = '', $subject = '', $replyto = '', $expires = NULL_DATE) { +function send_message($uid = 0, $recipient = '', $body = '', $subject = '', $replyto = '', $expires = NULL_DATE, $mimetype = 'text/bbcode', $raw = false) { $ret = array('success' => false); $is_reply = false; @@ -192,8 +202,8 @@ function send_message($uid = 0, $recipient = '', $body = '', $subject = '', $rep $sig = ''; // placeholder $mimetype = ''; //placeholder - $r = q("INSERT INTO mail ( account_id, conv_guid, mail_obscured, channel_id, from_xchan, to_xchan, mail_mimetype, title, body, sig, attach, mid, parent_mid, created, expires, mail_isreply ) - VALUES ( %d, '%s', %d, %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d )", + $r = q("INSERT INTO mail ( account_id, conv_guid, mail_obscured, channel_id, from_xchan, to_xchan, mail_mimetype, title, body, sig, attach, mid, parent_mid, created, expires, mail_isreply, mail_raw ) + VALUES ( %d, '%s', %d, %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d, %d )", intval($channel['channel_account_id']), dbesc($conv_guid), intval(1), @@ -209,7 +219,8 @@ function send_message($uid = 0, $recipient = '', $body = '', $subject = '', $rep dbesc($replyto), dbesc(datetime_convert()), dbescdate($expires), - intval($is_reply) + intval($is_reply), + intval($raw) ); // verify the save -- cgit v1.2.3 From 3389df77cc01cb7527623efebc9a640ad1454eb3 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Tue, 18 Apr 2017 21:18:49 -0700 Subject: give the item_obscured flag a new lease on life by using it to designate third party client-side e2ee or binary content which can only be downloaded and not viewed directly on the web (as a side effect this also allows binary files to be submitted as activities/content). The content display is suppressed and replaced with a download button. This is unfinished but harmless to backport while work is in progress unless told otherwise. Future development will take care of the remaining loose ends. --- include/conversation.php | 8 -------- include/text.php | 18 +++++++++++++++++- 2 files changed, 17 insertions(+), 9 deletions(-) (limited to 'include') diff --git a/include/conversation.php b/include/conversation.php index c325a516f..3f9ee5cfa 100644 --- a/include/conversation.php +++ b/include/conversation.php @@ -353,14 +353,6 @@ function localize_item(&$item){ } */ - // if item body was obscured and we changed it, re-obscure it - // FIXME - we need a better filter than just the string 'data'; try and - // match the fact that it's json encoded - - if(intval($item['item_obscured']) - && strlen($item['body']) && (! strpos($item['body'],'data'))) { - $item['body'] = z_obscure($item['body']); - } } diff --git a/include/text.php b/include/text.php index 6f5c48679..b8914c44b 100644 --- a/include/text.php +++ b/include/text.php @@ -1562,7 +1562,12 @@ function prepare_body(&$item,$attach = false) { } } - $s .= prepare_text($item['body'],$item['mimetype'], false); + if($item['item_obscured']) { + $s .= prepare_binary($item); + } + else { + $s .= prepare_text($item['body'],$item['mimetype'], false); + } $event = (($item['obj_type'] === ACTIVITY_OBJ_EVENT) ? format_event_obj($item['obj']) : false); @@ -1625,6 +1630,17 @@ function prepare_body(&$item,$attach = false) { return $prep_arr; } + +function prepare_binary($item) { + return replace_macros(get_markup_template('item_binary.tpl'), [ + '$download' => t('Download binary/encrypted content'), + '$url' => z_root() . '/viewsrc/' . $item['id'] . '/download' + ]); +} + + + + /** * @brief Given a text string, convert from bbcode to html and add smilie icons. * -- cgit v1.2.3 From 42c9f853a7d878fef7f545b58a744c134baabc02 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Fri, 9 Jun 2017 15:24:37 -0700 Subject: auto inline embed ostatus image attachments --- include/feedutils.php | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'include') diff --git a/include/feedutils.php b/include/feedutils.php index c530b7be7..1b7c22407 100644 --- a/include/feedutils.php +++ b/include/feedutils.php @@ -613,6 +613,10 @@ function get_atom_elements($feed, $item, &$author) { if(! $type) $type = 'application/octet-stream'; + if(($ostatus_protocol) && (strpos($type,'image') === 0) && (strpos($res['body'],$link) === false) && (strpos($link,'http') === 0)) { + $res['body'] .= "\n\n" . '[img]' . $link . '[/img]'; + } + $res['attach'][] = array('href' => $link, 'length' => $len, 'type' => $type, 'title' => $title ); } } -- cgit v1.2.3 From fbb83d831beb633fa620d7e316de7879258e65c3 Mon Sep 17 00:00:00 2001 From: Mario Vavti Date: Sat, 10 Jun 2017 10:00:37 +0200 Subject: some more innodb mysql scheme adjustments --- include/items.php | 5 +---- include/text.php | 2 +- 2 files changed, 2 insertions(+), 5 deletions(-) (limited to 'include') diff --git a/include/items.php b/include/items.php index 5010dedb2..206a97c42 100755 --- a/include/items.php +++ b/include/items.php @@ -4361,10 +4361,7 @@ function sync_an_item($channel_id,$item_id) { if($r) { xchan_query($r); $sync_item = fetch_post_tags($r); - $rid = q("select * from item_id where iid = %d", - intval($item_id) - ); - build_sync_packet($channel_d,array('item' => array(encode_item($sync_item[0],true)),'item_id' => $rid)); + build_sync_packet($channel_d,array('item' => array(encode_item($sync_item[0],true)))); } } diff --git a/include/text.php b/include/text.php index b8914c44b..d8438b2b1 100644 --- a/include/text.php +++ b/include/text.php @@ -2913,7 +2913,7 @@ function pdl_selector($uid, $current='') { $sql_extra = item_permissions_sql($uid); - $r = q("select iconfig.*, mid from item_id left join item on iconfig.iid = item.id + $r = q("select iconfig.*, mid from iconfig left join item on iconfig.iid = item.id where item.uid = %d and iconfig.cat = 'system' and iconfig.k = 'PDL' $sql_extra order by v asc", intval($uid) ); -- cgit v1.2.3 From 5b3e863323a6b70651454c0972a586e677f55c3d Mon Sep 17 00:00:00 2001 From: zotlabs Date: Mon, 12 Jun 2017 16:17:23 -0700 Subject: add 'can_comment_on_post' hook so we can better deal with the complications of Diaspora policy --- include/items.php | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'include') diff --git a/include/items.php b/include/items.php index 707f07f4a..e79707aeb 100755 --- a/include/items.php +++ b/include/items.php @@ -219,6 +219,11 @@ function can_comment_on_post($observer_xchan, $item) { // logger('can_comment_on_post: comment_policy: ' . $item['comment_policy'], LOGGER_DEBUG); + $x = [ 'observer_hash' => $observer_xchan, 'item' => $item, 'allowed' => 'unset' ]; + call_hooks('can_comment_on_post',$x); + if($x['allowed'] !== 'unset') + return $x['allowed']; + if(! $observer_xchan) return false; -- cgit v1.2.3 From 8bf9b1311d8728aec7bce93c7e59ffe022a31d49 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Mon, 12 Jun 2017 19:17:50 -0700 Subject: implement feed_get_reshare to extract shared post info from atom feed and convert to bbcode --- include/feedutils.php | 259 ++++++++++++++++++++++++++++++++------------------ 1 file changed, 169 insertions(+), 90 deletions(-) (limited to 'include') diff --git a/include/feedutils.php b/include/feedutils.php index 1b7c22407..2e67208a7 100644 --- a/include/feedutils.php +++ b/include/feedutils.php @@ -278,6 +278,23 @@ function get_atom_elements($feed, $item, &$author) { $base_url = ''; + $rawcreated = $item->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'published'); + if($rawcreated) + $res['created'] = unxmlify($rawcreated[0]['data']); + + $rawedited = $item->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'updated'); + if($rawedited) + $res['edited'] = unxmlify($rawedited[0]['data']); + + if((x($res,'edited')) && (! (x($res,'created')))) + $res['created'] = $res['edited']; + + if(! $res['created']) + $res['created'] = $item->get_date('c'); + + if(! $res['edited']) + $res['edited'] = $item->get_date('c'); + $rawverb = $item->get_item_tags(NAMESPACE_ACTIVITY, 'verb'); // select between supported verbs @@ -288,112 +305,85 @@ function get_atom_elements($feed, $item, &$author) { // translate OStatus unfollow to activity streams if it happened to get selected - if((x($res,'verb')) && ($res['verb'] === 'http://ostatus.org/schema/1.0/unfollow')) + if((x($res,'verb')) && ($res['verb'] === 'http://ostatus.org/schema/1.0/unfollow')) { $res['verb'] = ACTIVITY_UNFOLLOW; + } - if(array_key_exists('verb',$res) && $res['verb'] === ACTIVITY_SHARE) { - // For Mastodon shares ("boosts"), we need to parse the original author information - // from the activity:object -> author structure - $rawobj = $item->get_item_tags(NAMESPACE_ACTIVITY, 'object'); - if($rawobj) { - $rawauthor = $rawobj->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'author'); + // look for a photo. We should check media size and find the best one, + // but for now let's just find any author photo - if($rawauthor && $rawauthor[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name']) { - $author['author_name'] = unxmlify($rawauthor[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name']); - } + $rawauthor = $item->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10,'author'); - if($rawauthor && $rawauthor[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['uri']) { - $author['author_link'] = unxmlify($rawauthor[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['uri']); + if($rawauthor && $rawauthor[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['link']) { + $base = $rawauthor[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['link']; + foreach($base as $link) { + if(!x($author, 'author_photo') || ! $author['author_photo']) { + if($link['attribs']['']['rel'] === 'photo' || $link['attribs']['']['rel'] === 'avatar') + $author['author_photo'] = unxmlify($link['attribs']['']['href']); } - if($rawauthor && $rawauthor[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['link']) { - $base = $rawauthor[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['link']; - foreach($base as $link) { - if(!x($author, 'author_photo') || ! $author['author_photo']) { - if($link['attribs']['']['rel'] === 'photo' || $link['attribs']['']['rel'] === 'avatar') - $author['author_photo'] = unxmlify($link['attribs']['']['href']); - } + } + } + $rawactor = $item->get_item_tags(NAMESPACE_ACTIVITY, 'actor'); + + if($rawactor && activity_match($rawactor[0]['child'][NAMESPACE_ACTIVITY]['obj_type'][0]['data'], ACTIVITY_OBJ_PERSON)) { + $base = $rawactor[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['link']; + if($base && count($base)) { + foreach($base as $link) { + if($link['attribs']['']['rel'] === 'alternate' && (! $res['author_link'])) + $author['author_link'] = unxmlify($link['attribs']['']['href']); + if(!x($author, 'author_photo') || ! $author['author_photo']) { + if($link['attribs']['']['rel'] === 'avatar' || $link['attribs']['']['rel'] === 'photo') + $author['author_photo'] = unxmlify($link['attribs']['']['href']); } } } } - else { - // look for a photo. We should check media size and find the best one, - // but for now let's just find any author photo - $rawauthor = $item->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10,'author'); + // check for a yahoo media element (github etc.) + if(! $author['author_photo']) { + $rawmedia = $item->get_item_tags(NAMESPACE_YMEDIA,'thumbnail'); + if($rawmedia && $rawmedia[0]['attribs']['']['url']) { + $author['author_photo'] = strip_tags(unxmlify($rawmedia[0]['attribs']['']['url'])); + } + } + + + // No photo/profile-link on the item - look at the feed level + + if((! (x($author,'author_link'))) || (! (x($author,'author_photo')))) { + $rawauthor = $feed->get_feed_tags(SIMPLEPIE_NAMESPACE_ATOM_10,'author'); if($rawauthor && $rawauthor[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['link']) { $base = $rawauthor[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['link']; foreach($base as $link) { - if(!x($author, 'author_photo') || ! $author['author_photo']) { + if($link['attribs']['']['rel'] === 'alternate' && (! $author['author_link'])) { + $author['author_link'] = unxmlify($link['attribs']['']['href']); + $author['author_is_feed'] = true; + } + if(! $author['author_photo']) { if($link['attribs']['']['rel'] === 'photo' || $link['attribs']['']['rel'] === 'avatar') $author['author_photo'] = unxmlify($link['attribs']['']['href']); } } } - $rawactor = $item->get_item_tags(NAMESPACE_ACTIVITY, 'actor'); + $rawactor = $feed->get_feed_tags(NAMESPACE_ACTIVITY, 'subject'); - if($rawactor && activity_match($rawactor[0]['child'][NAMESPACE_ACTIVITY]['obj_type'][0]['data'], ACTIVITY_OBJ_PERSON)) { + if($rawactor && activity_match($rawactor[0]['child'][NAMESPACE_ACTIVITY]['obj_type'][0]['data'],ACTIVITY_OBJ_PERSON)) { $base = $rawactor[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['link']; + if($base && count($base)) { foreach($base as $link) { if($link['attribs']['']['rel'] === 'alternate' && (! $res['author_link'])) $author['author_link'] = unxmlify($link['attribs']['']['href']); - if(!x($author, 'author_photo') || ! $author['author_photo']) { + if(! (x($author,'author_photo'))) { if($link['attribs']['']['rel'] === 'avatar' || $link['attribs']['']['rel'] === 'photo') $author['author_photo'] = unxmlify($link['attribs']['']['href']); } } } } - - // check for a yahoo media element (github etc.) - - if(! $author['author_photo']) { - $rawmedia = $item->get_item_tags(NAMESPACE_YMEDIA,'thumbnail'); - if($rawmedia && $rawmedia[0]['attribs']['']['url']) { - $author['author_photo'] = strip_tags(unxmlify($rawmedia[0]['attribs']['']['url'])); - } - } - - - // No photo/profile-link on the item - look at the feed level - - if((! (x($author,'author_link'))) || (! (x($author,'author_photo')))) { - $rawauthor = $feed->get_feed_tags(SIMPLEPIE_NAMESPACE_ATOM_10,'author'); - if($rawauthor && $rawauthor[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['link']) { - $base = $rawauthor[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['link']; - foreach($base as $link) { - if($link['attribs']['']['rel'] === 'alternate' && (! $author['author_link'])) { - $author['author_link'] = unxmlify($link['attribs']['']['href']); - $author['author_is_feed'] = true; - } - if(! $author['author_photo']) { - if($link['attribs']['']['rel'] === 'photo' || $link['attribs']['']['rel'] === 'avatar') - $author['author_photo'] = unxmlify($link['attribs']['']['href']); - } - } - } - - $rawactor = $feed->get_feed_tags(NAMESPACE_ACTIVITY, 'subject'); - - if($rawactor && activity_match($rawactor[0]['child'][NAMESPACE_ACTIVITY]['obj_type'][0]['data'],ACTIVITY_OBJ_PERSON)) { - $base = $rawactor[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['link']; - - if($base && count($base)) { - foreach($base as $link) { - if($link['attribs']['']['rel'] === 'alternate' && (! $res['author_link'])) - $author['author_link'] = unxmlify($link['attribs']['']['href']); - if(! (x($author,'author_photo'))) { - if($link['attribs']['']['rel'] === 'avatar' || $link['attribs']['']['rel'] === 'photo') - $author['author_photo'] = unxmlify($link['attribs']['']['href']); - } - } - } - } - } } $ostatus_protocol = (($item->get_item_tags(NAMESPACE_OSTATUS, 'conversation')) ? true : false); @@ -499,23 +489,6 @@ function get_atom_elements($feed, $item, &$author) { if($rawlocation) $res['location'] = unxmlify($rawlocation[0]['data']); - $rawcreated = $item->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'published'); - if($rawcreated) - $res['created'] = unxmlify($rawcreated[0]['data']); - - $rawedited = $item->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'updated'); - if($rawedited) - $res['edited'] = unxmlify($rawedited[0]['data']); - - if((x($res,'edited')) && (! (x($res,'created')))) - $res['created'] = $res['edited']; - - if(! $res['created']) - $res['created'] = $item->get_date('c'); - - if(! $res['edited']) - $res['edited'] = $item->get_date('c'); - // Disallow time travelling posts @@ -597,6 +570,7 @@ function get_atom_elements($feed, $item, &$author) { $attach = $item->get_enclosures(); if($attach) { + $res['attach'] = array(); foreach($attach as $att) { $len = intval($att->get_length()); @@ -620,6 +594,7 @@ function get_atom_elements($feed, $item, &$author) { $res['attach'][] = array('href' => $link, 'length' => $len, 'type' => $type, 'title' => $title ); } } + $rawobj = $item->get_item_tags(NAMESPACE_ACTIVITY, 'object'); @@ -697,6 +672,10 @@ function get_atom_elements($feed, $item, &$author) { $res['target'] = $obj; } + if(array_key_exists('verb',$res) && $res['verb'] === ACTIVITY_SHARE) { + feed_get_reshare($res,$item); + } + // build array to pass to hook $arr = [ 'feed' => $feed, @@ -713,6 +692,106 @@ function get_atom_elements($feed, $item, &$author) { return $arr['result']; } +function feed_get_reshare(&$res,$item) { + + $share = []; + + // For Mastodon shares ("boosts"), we need to parse the original author information + // from the activity:object -> author structure + $rawobj = $item->get_item_tags(NAMESPACE_ACTIVITY, 'object'); + + if($rawobj) { + + $rawauthor = $rawobj->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'author'); + + if($rawauthor && $rawauthor[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name']) { + $share['author'] = unxmlify($rawauthor[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name']); + } + + if($rawauthor && $rawauthor[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['uri']) { + $share['profile'] = unxmlify($rawauthor[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['uri']); + } + + if($rawauthor && $rawauthor[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['link']) { + $base = $rawauthor[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['link']; + foreach($base as $link) { + if(! (array_key_exists('avatar',$share) && $share['avatar'])) { + if($link['attribs']['']['rel'] === 'photo' || $link['attribs']['']['rel'] === 'avatar') + $share['avatar'] = unxmlify($link['attribs']['']['href']); + } + } + } + + if(! $share['author']) + $share['author'] = t('unknown'); + if(! $share['avatar']) + $share['avatar'] = z_root() . '/' . get_default_profile_photo(80); + if(! $share['profile']) + $share['profile'] = z_root(); + + $child = $rawobj[0]['child']; + + + if(x($child[SIMPLEPIE_NAMESPACE_ATOM_10], 'link') && $child[SIMPLEPIE_NAMESPACE_ATOM_10]['link']) + $share['link'] = encode_rel_links($child[SIMPLEPIE_NAMESPACE_ATOM_10]['link']); + + $rawcreated = $rawobj->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'published'); + if($rawcreated) + $share['created'] = unxmlify($rawcreated[0]['data']); + else + $share['created'] = $res['created']; + + if(x($child[SIMPLEPIE_NAMESPACE_ATOM_10], 'id') && $child[SIMPLEPIE_NAMESPACE_ATOM_10]['id'][0]['data']) + $share['message_id'] = unxmlify($child[SIMPLEPIE_NAMESPACE_ATOM_10]['id'][0]['data']); + + if(x($child[SIMPLEPIE_NAMESPACE_ATOM_10], 'content') && $child[SIMPLEPIE_NAMESPACE_ATOM_10]['content'][0]['data']) { + $body = unxmlify($child[SIMPLEPIE_NAMESPACE_ATOM_10]['content'][0]['data']); + if(! $body) + $body = unxmlify($child[SIMPLEPIE_NAMESPACE_ATOM_10]['summary'][0]['data']); + + if((strpos($body,'<') !== false) || (strpos($body,'>') !== false)) { + $body = purify_html($body); + $body = html2bbcode($body); + } + } + + $attach = $rawobj->get_enclosures(); + if($attach) { + foreach($attach as $att) { + $len = intval($att->get_length()); + $link = str_replace(array(',','"'),array('%2D','%22'),notags(trim(unxmlify($att->get_link())))); + $title = str_replace(array(',','"'),array('%2D','%22'),notags(trim(unxmlify($att->get_title())))); + $type = str_replace(array(',','"'),array('%2D','%22'),notags(trim(unxmlify($att->get_type())))); + if(strpos($type,';')) + $type = substr($type,0,strpos($type,';')); + if((! $link) || (strpos($link,'http') !== 0)) + continue; + + if(! $title) + $title = ' '; + if(! $type) + $type = 'application/octet-stream'; + + if((strpos($type,'image') === 0) && (strpos($body,$link) === false) && (strpos($link,'http') === 0)) { + $body .= "\n\n" . '[img]' . $link . '[/img]'; + } + } + } + + $res['body'] = "[share author='" . urlencode($share['author']) . + "' profile='" . $share['profile'] . + "' avatar='" . $share['avatar'] . + "' link='" . $share['link'] . + "' posted='" . $share['created'] . + "' message_id='" . $share['message_id'] . "']"; + $o .= $body; + $o .= "[/share]"; + } + +} + + + /** * @brief Encodes SimplePie_Item link arrays. * -- cgit v1.2.3 From f526b9fcfbca2cf7a23d21653da3c63ad4bc91fa Mon Sep 17 00:00:00 2001 From: zotlabs Date: Mon, 12 Jun 2017 21:12:14 -0700 Subject: ostatus is almost unrecognisable these days from its former self. In this case thr:in-reply-to has almost no meaning since it almost never refers to a top level post; which makes it quite difficult to preserve conversations --- include/feedutils.php | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) (limited to 'include') diff --git a/include/feedutils.php b/include/feedutils.php index 2e67208a7..5af6a01b0 100644 --- a/include/feedutils.php +++ b/include/feedutils.php @@ -1000,11 +1000,23 @@ function consume_feed($xml, $importer, &$contact, $pass = 0) { dbesc($parent_mid), intval($importer['channel_id']) ); - if($x) - $parent_mid = $x[0]['mid']; - $datarray['parent_mid'] = $parent_mid; + if($x) { + $pmid = $x[0]['mid']; + $datarray['parent_mid'] = $pmid; + } + else { + // immediate parent wasn't found. Turn into a top-level post if permissions allow + // but save the thread_parent in case we need to refer to it later. We should probably + // also save the ostatus:conversation_id + + if(! post_is_importable($datarray, $contact)) + continue; + $datarray['parent_mid'] = $datarray['mid']; + set_iconfig($datarray,'system','parent_mid',$parent_mid,true); + } + $datarray['aid'] = $importer['channel_account_id']; $datarray['uid'] = $importer['channel_id']; -- cgit v1.2.3 From dd8feac54070f9aefb7da034f2d15e6dce872a3b Mon Sep 17 00:00:00 2001 From: zotlabs Date: Mon, 12 Jun 2017 21:58:40 -0700 Subject: preserve the ostatus:conversation pointer also --- include/feedutils.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'include') diff --git a/include/feedutils.php b/include/feedutils.php index 5af6a01b0..41c11bce1 100644 --- a/include/feedutils.php +++ b/include/feedutils.php @@ -386,7 +386,14 @@ function get_atom_elements($feed, $item, &$author) { } } - $ostatus_protocol = (($item->get_item_tags(NAMESPACE_OSTATUS, 'conversation')) ? true : false); + $rawcnv = $item->get_item_tags(NAMESPACE_OSTATUS, 'conversation'); + if($rawcnv) { + $ostatus_conversation = unxmlify($rawcnv[0]['attribs']['']['ref']); + set_iconfig($res,'ostatus','conversation',$ostatus_conversation,true); + } + + $ostatus_protocol = (($ostatus_conversation) ? true : false); + $mastodon = (($item->get_item_tags('http://mastodon.social/schema/1.0','scope')) ? true : false); if($mastodon) $ostatus_protocol = true; -- cgit v1.2.3 From 7f374fe69f46c041221736e4940b1cb0e8809fd1 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Tue, 13 Jun 2017 18:06:45 -0700 Subject: attempt to group gnu-social and mastodon conversations by ostatus:conversation in addition to falling back on thr:in_reply_to --- include/feedutils.php | 35 +++++++++++++++++++++++++---------- 1 file changed, 25 insertions(+), 10 deletions(-) (limited to 'include') diff --git a/include/feedutils.php b/include/feedutils.php index 41c11bce1..38ad102b4 100644 --- a/include/feedutils.php +++ b/include/feedutils.php @@ -1003,20 +1003,35 @@ function consume_feed($xml, $importer, &$contact, $pass = 0) { continue; } - $x = q("select mid from item where mid = '%s' and uid = %d limit 1", - dbesc($parent_mid), - intval($importer['channel_id']) - ); - - if($x) { - $pmid = $x[0]['mid']; - $datarray['parent_mid'] = $pmid; + $pmid = ''; + $conv_id = get_iconfig($datarray,'ostatus','conversation'); + + if($conv_id) { + $c = q("select parent_mid from item left join iconfig on item.id = iconfig.iid where iconfig.cat = 'ostatus' and iconfig.k = 'conversation' and iconfig.v = '%s' and item.uid = %d order by item.id limit 1", + dbesc($conv_id), + intval($importer['channel_id']) + ); + if($c) { + $pmid = $x[0]['parent_mid']; + $datarray['parent_mid'] = $pmid; + } } else { + $x = q("select mid from item where mid = '%s' and uid = %d limit 1", + dbesc($parent_mid), + intval($importer['channel_id']) + ); + + if($x) { + $pmid = $x[0]['mid']; + $datarray['parent_mid'] = $pmid; + } + } + + if(! $pmid) { // immediate parent wasn't found. Turn into a top-level post if permissions allow - // but save the thread_parent in case we need to refer to it later. We should probably - // also save the ostatus:conversation_id + // but save the thread_parent in case we need to refer to it later. if(! post_is_importable($datarray, $contact)) continue; -- cgit v1.2.3 From fce68f1a39c73246ad449aee1bf7a4b9aba9837f Mon Sep 17 00:00:00 2001 From: zotlabs Date: Tue, 13 Jun 2017 18:29:08 -0700 Subject: add rel=noopener to all external target _blank links --- include/bbcode.php | 32 ++++++++++++++++---------------- include/text.php | 4 ++-- 2 files changed, 18 insertions(+), 18 deletions(-) (limited to 'include') diff --git a/include/bbcode.php b/include/bbcode.php index 6805f008c..c408af35d 100644 --- a/include/bbcode.php +++ b/include/bbcode.php @@ -839,7 +839,7 @@ function bbcode($Text, $preserve_nl = false, $tryoembed = true, $cache = false) if($tryoembed) { $Text = preg_replace_callback("/([^\]\='".'"'."\/]|^|\#\^)(https?\:\/\/$urlchars+)/ism", 'tryoembed', $Text); } - $Text = preg_replace("/([^\]\='".'"'."\/]|^|\#\^)(https?\:\/\/$urlchars+)/ism", '$1$2', $Text); + $Text = preg_replace("/([^\]\='".'"'."\/]|^|\#\^)(https?\:\/\/$urlchars+)/ism", '$1$2', $Text); } if (strpos($Text,'[/share]') !== false) { @@ -851,16 +851,16 @@ function bbcode($Text, $preserve_nl = false, $tryoembed = true, $cache = false) } } if (strpos($Text,'[/url]') !== false) { - $Text = preg_replace("/\#\^\[url\]([$URLSearchString]*)\[\/url\]/ism", '#^$1', $Text); - $Text = preg_replace("/\#\^\[url\=([$URLSearchString]*)\](.*?)\[\/url\]/ism", '#^$2', $Text); - $Text = preg_replace("/\[url\]([$URLSearchString]*)\[\/url\]/ism", '$1', $Text); - $Text = preg_replace("/\[url\=([$URLSearchString]*)\](.*?)\[\/url\]/ism", '$2', $Text); + $Text = preg_replace("/\#\^\[url\]([$URLSearchString]*)\[\/url\]/ism", '#^$1', $Text); + $Text = preg_replace("/\#\^\[url\=([$URLSearchString]*)\](.*?)\[\/url\]/ism", '#^$2', $Text); + $Text = preg_replace("/\[url\]([$URLSearchString]*)\[\/url\]/ism", '$1', $Text); + $Text = preg_replace("/\[url\=([$URLSearchString]*)\](.*?)\[\/url\]/ism", '$2', $Text); } if (strpos($Text,'[/zrl]') !== false) { - $Text = preg_replace("/\#\^\[zrl\]([$URLSearchString]*)\[\/zrl\]/ism", '#^$1', $Text); - $Text = preg_replace("/\#\^\[zrl\=([$URLSearchString]*)\](.*?)\[\/zrl\]/ism", '#^$2', $Text); - $Text = preg_replace("/\[zrl\]([$URLSearchString]*)\[\/zrl\]/ism", '$1', $Text); - $Text = preg_replace("/\[zrl\=([$URLSearchString]*)\](.*?)\[\/zrl\]/ism", '$2', $Text); + $Text = preg_replace("/\#\^\[zrl\]([$URLSearchString]*)\[\/zrl\]/ism", '#^$1', $Text); + $Text = preg_replace("/\#\^\[zrl\=([$URLSearchString]*)\](.*?)\[\/zrl\]/ism", '#^$2', $Text); + $Text = preg_replace("/\[zrl\]([$URLSearchString]*)\[\/zrl\]/ism", '$1', $Text); + $Text = preg_replace("/\[zrl\=([$URLSearchString]*)\](.*?)\[\/zrl\]/ism", '$2', $Text); } if (get_account_techlevel() < 2) @@ -868,8 +868,8 @@ function bbcode($Text, $preserve_nl = false, $tryoembed = true, $cache = false) // Perform MAIL Search if (strpos($Text,'[/mail]') !== false) { - $Text = preg_replace("/\[mail\]([$MAILSearchString]*)\[\/mail\]/", '$1', $Text); - $Text = preg_replace("/\[mail\=([$MAILSearchString]*)\](.*?)\[\/mail\]/", '$2', $Text); + $Text = preg_replace("/\[mail\]([$MAILSearchString]*)\[\/mail\]/", '$1', $Text); + $Text = preg_replace("/\[mail\=([$MAILSearchString]*)\](.*?)\[\/mail\]/", '$2', $Text); } @@ -1189,17 +1189,17 @@ function bbcode($Text, $preserve_nl = false, $tryoembed = true, $cache = false) // if video couldn't be embedded, link to it instead. if (strpos($Text,'[/video]') !== false) { - $Text = preg_replace("/\[video\](.*?)\[\/video\]/", '$1', $Text); + $Text = preg_replace("/\[video\](.*?)\[\/video\]/", '$1', $Text); } if (strpos($Text,'[/audio]') !== false) { - $Text = preg_replace("/\[audio\](.*?)\[\/audio\]/", '$1', $Text); + $Text = preg_replace("/\[audio\](.*?)\[\/audio\]/", '$1', $Text); } if (strpos($Text,'[/zvideo]') !== false) { - $Text = preg_replace("/\[zvideo\](.*?)\[\/zvideo\]/", '$1', $Text); + $Text = preg_replace("/\[zvideo\](.*?)\[\/zvideo\]/", '$1', $Text); } if (strpos($Text,'[/zaudio]') !== false) { - $Text = preg_replace("/\[zaudio\](.*?)\[\/zaudio\]/", '$1', $Text); + $Text = preg_replace("/\[zaudio\](.*?)\[\/zaudio\]/", '$1', $Text); } // if ($tryoembed){ @@ -1208,7 +1208,7 @@ function bbcode($Text, $preserve_nl = false, $tryoembed = true, $cache = false) // } // } else { // if (strpos($Text,'[/iframe]') !== false) { -// $Text = preg_replace("/\[iframe\](.*?)\[\/iframe\]/ism", '$1', $Text); +// $Text = preg_replace("/\[iframe\](.*?)\[\/iframe\]/ism", '$1', $Text); // } // } diff --git a/include/text.php b/include/text.php index c791b50ee..5af4f1b67 100644 --- a/include/text.php +++ b/include/text.php @@ -1531,13 +1531,13 @@ function prepare_body(&$item,$attach = false) { // if original photo width is <= 640px prepend it to item body if($object['link'][0]['width'] && $object['link'][0]['width'] <= 640) { - $s .= '
    ' . $s; + $s .= '
    ' . $s; } // if original photo width is > 640px make it a cover photo if($object['link'][0]['width'] && $object['link'][0]['width'] > 640) { $scale = ((($object['link'][1]['width'] == 1024) || ($object['link'][1]['height'] == 1024)) ? 1 : 0); - $photo = ''; + $photo = ''; } } -- cgit v1.2.3 From 364da7a57e4fea5226c83d2ef9869a084c7c0013 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Tue, 13 Jun 2017 19:52:16 -0700 Subject: support mastodon content warnings by converting into n-s-f-w tag --- include/feedutils.php | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'include') diff --git a/include/feedutils.php b/include/feedutils.php index 38ad102b4..96e5fdc6b 100644 --- a/include/feedutils.php +++ b/include/feedutils.php @@ -266,6 +266,8 @@ function get_atom_elements($feed, $item, &$author) { $res['item_rss'] = 1; + $summary = unxmlify($item->get_description(true)); + // removing the content of the title if its identically to the body // This helps with auto generated titles e.g. from tumblr @@ -486,6 +488,12 @@ function get_atom_elements($feed, $item, &$author) { ); } + // turn Mastodon content warning into a #nsfw hashtag + if($mastodon && $summary) { + $res['body'] .= "\n\n#nsfw\n"; + } + + $private = $item->get_item_tags(NAMESPACE_DFRN, 'private'); if($private && intval($private[0]['data']) > 0) $res['item_private'] = ((intval($private[0]['data'])) ? 1 : 0); -- cgit v1.2.3 From 7c363310428d8f76356eb1423554cc2de6ebd4a0 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Mon, 12 Jun 2017 16:17:23 -0700 Subject: add 'can_comment_on_post' hook so we can better deal with the complications of Diaspora policy --- include/items.php | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'include') diff --git a/include/items.php b/include/items.php index 206a97c42..fa61d71de 100755 --- a/include/items.php +++ b/include/items.php @@ -219,6 +219,11 @@ function can_comment_on_post($observer_xchan, $item) { // logger('can_comment_on_post: comment_policy: ' . $item['comment_policy'], LOGGER_DEBUG); + $x = [ 'observer_hash' => $observer_xchan, 'item' => $item, 'allowed' => 'unset' ]; + call_hooks('can_comment_on_post',$x); + if($x['allowed'] !== 'unset') + return $x['allowed']; + if(! $observer_xchan) return false; -- cgit v1.2.3 From 5d2035b729d2d0075addf19cbe29536fbff5914a Mon Sep 17 00:00:00 2001 From: zotlabs Date: Mon, 12 Jun 2017 19:17:50 -0700 Subject: implement feed_get_reshare to extract shared post info from atom feed and convert to bbcode --- include/feedutils.php | 261 ++++++++++++++++++++++++++++++++------------------ 1 file changed, 170 insertions(+), 91 deletions(-) (limited to 'include') diff --git a/include/feedutils.php b/include/feedutils.php index f1cee4194..23a065298 100644 --- a/include/feedutils.php +++ b/include/feedutils.php @@ -278,6 +278,23 @@ function get_atom_elements($feed, $item, &$author) { $base_url = ''; + $rawcreated = $item->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'published'); + if($rawcreated) + $res['created'] = unxmlify($rawcreated[0]['data']); + + $rawedited = $item->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'updated'); + if($rawedited) + $res['edited'] = unxmlify($rawedited[0]['data']); + + if((x($res,'edited')) && (! (x($res,'created')))) + $res['created'] = $res['edited']; + + if(! $res['created']) + $res['created'] = $item->get_date('c'); + + if(! $res['edited']) + $res['edited'] = $item->get_date('c'); + $rawverb = $item->get_item_tags(NAMESPACE_ACTIVITY, 'verb'); // select between supported verbs @@ -288,112 +305,85 @@ function get_atom_elements($feed, $item, &$author) { // translate OStatus unfollow to activity streams if it happened to get selected - if((x($res,'verb')) && ($res['verb'] === 'http://ostatus.org/schema/1.0/unfollow')) + if((x($res,'verb')) && ($res['verb'] === 'http://ostatus.org/schema/1.0/unfollow')) { $res['verb'] = ACTIVITY_UNFOLLOW; + } - if(array_key_exists('verb',$res) && $res['verb'] === ACTIVITY_SHARE) { - // For Mastodon shares ("boosts"), we need to parse the original author information - // from the activity:object -> author structure - $rawobj = $item->get_item_tags(NAMESPACE_ACTIVITY, 'object'); - - if($rawobj) { - $rawauthor = $rawobj->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'author'); - if($rawauthor && $rawauthor[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name']) { - $author['author_name'] = unxmlify($rawauthor[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name']); - } + // look for a photo. We should check media size and find the best one, + // but for now let's just find any author photo + + $rawauthor = $item->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10,'author'); - if($rawauthor && $rawauthor[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['uri']) { - $author['author_link'] = unxmlify($rawauthor[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['uri']); + if($rawauthor && $rawauthor[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['link']) { + $base = $rawauthor[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['link']; + foreach($base as $link) { + if(!x($author, 'author_photo') || ! $author['author_photo']) { + if($link['attribs']['']['rel'] === 'photo' || $link['attribs']['']['rel'] === 'avatar') + $author['author_photo'] = unxmlify($link['attribs']['']['href']); } - if($rawauthor && $rawauthor[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['link']) { - $base = $rawauthor[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['link']; - foreach($base as $link) { - if(!x($author, 'author_photo') || ! $author['author_photo']) { - if($link['attribs']['']['rel'] === 'photo' || $link['attribs']['']['rel'] === 'avatar') - $author['author_photo'] = unxmlify($link['attribs']['']['href']); - } + } + } + $rawactor = $item->get_item_tags(NAMESPACE_ACTIVITY, 'actor'); + + if($rawactor && activity_match($rawactor[0]['child'][NAMESPACE_ACTIVITY]['obj_type'][0]['data'], ACTIVITY_OBJ_PERSON)) { + $base = $rawactor[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['link']; + if($base && count($base)) { + foreach($base as $link) { + if($link['attribs']['']['rel'] === 'alternate' && (! $res['author_link'])) + $author['author_link'] = unxmlify($link['attribs']['']['href']); + if(!x($author, 'author_photo') || ! $author['author_photo']) { + if($link['attribs']['']['rel'] === 'avatar' || $link['attribs']['']['rel'] === 'photo') + $author['author_photo'] = unxmlify($link['attribs']['']['href']); } } } } - else { - // look for a photo. We should check media size and find the best one, - // but for now let's just find any author photo - $rawauthor = $item->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'author'); + // check for a yahoo media element (github etc.) + if(! $author['author_photo']) { + $rawmedia = $item->get_item_tags(NAMESPACE_YMEDIA,'thumbnail'); + if($rawmedia && $rawmedia[0]['attribs']['']['url']) { + $author['author_photo'] = strip_tags(unxmlify($rawmedia[0]['attribs']['']['url'])); + } + } + + + // No photo/profile-link on the item - look at the feed level + + if((! (x($author,'author_link'))) || (! (x($author,'author_photo')))) { + $rawauthor = $feed->get_feed_tags(SIMPLEPIE_NAMESPACE_ATOM_10,'author'); if($rawauthor && $rawauthor[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['link']) { $base = $rawauthor[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['link']; foreach($base as $link) { - if(!x($author, 'author_photo') || ! $author['author_photo']) { + if($link['attribs']['']['rel'] === 'alternate' && (! $author['author_link'])) { + $author['author_link'] = unxmlify($link['attribs']['']['href']); + $author['author_is_feed'] = true; + } + if(! $author['author_photo']) { if($link['attribs']['']['rel'] === 'photo' || $link['attribs']['']['rel'] === 'avatar') $author['author_photo'] = unxmlify($link['attribs']['']['href']); } } } - $rawactor = $item->get_item_tags(NAMESPACE_ACTIVITY, 'actor'); + $rawactor = $feed->get_feed_tags(NAMESPACE_ACTIVITY, 'subject'); - if($rawactor && activity_match($rawactor[0]['child'][NAMESPACE_ACTIVITY]['obj_type'][0]['data'], ACTIVITY_OBJ_PERSON)) { + if($rawactor && activity_match($rawactor[0]['child'][NAMESPACE_ACTIVITY]['obj_type'][0]['data'],ACTIVITY_OBJ_PERSON)) { $base = $rawactor[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['link']; + if($base && count($base)) { foreach($base as $link) { if($link['attribs']['']['rel'] === 'alternate' && (! $res['author_link'])) $author['author_link'] = unxmlify($link['attribs']['']['href']); - if(!x($author, 'author_photo') || ! $author['author_photo']) { + if(! (x($author,'author_photo'))) { if($link['attribs']['']['rel'] === 'avatar' || $link['attribs']['']['rel'] === 'photo') $author['author_photo'] = unxmlify($link['attribs']['']['href']); } } } } - - // check for a yahoo media element (github etc.) - - if(! $author['author_photo']) { - $rawmedia = $item->get_item_tags(NAMESPACE_YMEDIA,'thumbnail'); - if($rawmedia && $rawmedia[0]['attribs']['']['url']) { - $author['author_photo'] = strip_tags(unxmlify($rawmedia[0]['attribs']['']['url'])); - } - } - - - // No photo/profile-link on the item - look at the feed level - - if((! (x($author,'author_link'))) || (! (x($author,'author_photo')))) { - $rawauthor = $feed->get_feed_tags(SIMPLEPIE_NAMESPACE_ATOM_10,'author'); - if($rawauthor && $rawauthor[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['link']) { - $base = $rawauthor[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['link']; - foreach($base as $link) { - if($link['attribs']['']['rel'] === 'alternate' && (! $author['author_link'])) { - $author['author_link'] = unxmlify($link['attribs']['']['href']); - $author['author_is_feed'] = true; - } - if(! $author['author_photo']) { - if($link['attribs']['']['rel'] === 'photo' || $link['attribs']['']['rel'] === 'avatar') - $author['author_photo'] = unxmlify($link['attribs']['']['href']); - } - } - } - - $rawactor = $feed->get_feed_tags(NAMESPACE_ACTIVITY, 'subject'); - - if($rawactor && activity_match($rawactor[0]['child'][NAMESPACE_ACTIVITY]['obj_type'][0]['data'], ACTIVITY_OBJ_PERSON)) { - $base = $rawactor[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['link']; - - if($base && count($base)) { - foreach($base as $link) { - if($link['attribs']['']['rel'] === 'alternate' && (! $res['author_link'])) - $author['author_link'] = unxmlify($link['attribs']['']['href']); - if(! (x($author,'author_photo'))) { - if($link['attribs']['']['rel'] === 'avatar' || $link['attribs']['']['rel'] === 'photo') - $author['author_photo'] = unxmlify($link['attribs']['']['href']); - } - } - } - } - } } $ostatus_protocol = (($item->get_item_tags(NAMESPACE_OSTATUS, 'conversation')) ? true : false); @@ -499,23 +489,6 @@ function get_atom_elements($feed, $item, &$author) { if($rawlocation) $res['location'] = unxmlify($rawlocation[0]['data']); - $rawcreated = $item->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'published'); - if($rawcreated) - $res['created'] = unxmlify($rawcreated[0]['data']); - - $rawedited = $item->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'updated'); - if($rawedited) - $res['edited'] = unxmlify($rawedited[0]['data']); - - if((x($res,'edited')) && (! (x($res,'created')))) - $res['created'] = $res['edited']; - - if(! $res['created']) - $res['created'] = $item->get_date('c'); - - if(! $res['edited']) - $res['edited'] = $item->get_date('c'); - // Disallow time travelling posts @@ -597,6 +570,7 @@ function get_atom_elements($feed, $item, &$author) { $attach = $item->get_enclosures(); if($attach) { + $res['attach'] = array(); foreach($attach as $att) { $len = intval($att->get_length()); @@ -616,6 +590,7 @@ function get_atom_elements($feed, $item, &$author) { $res['attach'][] = array('href' => $link, 'length' => $len, 'type' => $type, 'title' => $title ); } } + $rawobj = $item->get_item_tags(NAMESPACE_ACTIVITY, 'object'); @@ -693,6 +668,10 @@ function get_atom_elements($feed, $item, &$author) { $res['target'] = $obj; } + if(array_key_exists('verb',$res) && $res['verb'] === ACTIVITY_SHARE) { + feed_get_reshare($res,$item); + } + // build array to pass to hook $arr = [ 'feed' => $feed, @@ -709,6 +688,106 @@ function get_atom_elements($feed, $item, &$author) { return $arr['result']; } +function feed_get_reshare(&$res,$item) { + + $share = []; + + // For Mastodon shares ("boosts"), we need to parse the original author information + // from the activity:object -> author structure + $rawobj = $item->get_item_tags(NAMESPACE_ACTIVITY, 'object'); + + if($rawobj) { + + $rawauthor = $rawobj->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'author'); + + if($rawauthor && $rawauthor[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name']) { + $share['author'] = unxmlify($rawauthor[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name']); + } + + if($rawauthor && $rawauthor[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['uri']) { + $share['profile'] = unxmlify($rawauthor[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['uri']); + } + + if($rawauthor && $rawauthor[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['link']) { + $base = $rawauthor[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['link']; + foreach($base as $link) { + if(! (array_key_exists('avatar',$share) && $share['avatar'])) { + if($link['attribs']['']['rel'] === 'photo' || $link['attribs']['']['rel'] === 'avatar') + $share['avatar'] = unxmlify($link['attribs']['']['href']); + } + } + } + + if(! $share['author']) + $share['author'] = t('unknown'); + if(! $share['avatar']) + $share['avatar'] = z_root() . '/' . get_default_profile_photo(80); + if(! $share['profile']) + $share['profile'] = z_root(); + + $child = $rawobj[0]['child']; + + + if(x($child[SIMPLEPIE_NAMESPACE_ATOM_10], 'link') && $child[SIMPLEPIE_NAMESPACE_ATOM_10]['link']) + $share['link'] = encode_rel_links($child[SIMPLEPIE_NAMESPACE_ATOM_10]['link']); + + $rawcreated = $rawobj->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'published'); + if($rawcreated) + $share['created'] = unxmlify($rawcreated[0]['data']); + else + $share['created'] = $res['created']; + + if(x($child[SIMPLEPIE_NAMESPACE_ATOM_10], 'id') && $child[SIMPLEPIE_NAMESPACE_ATOM_10]['id'][0]['data']) + $share['message_id'] = unxmlify($child[SIMPLEPIE_NAMESPACE_ATOM_10]['id'][0]['data']); + + if(x($child[SIMPLEPIE_NAMESPACE_ATOM_10], 'content') && $child[SIMPLEPIE_NAMESPACE_ATOM_10]['content'][0]['data']) { + $body = unxmlify($child[SIMPLEPIE_NAMESPACE_ATOM_10]['content'][0]['data']); + if(! $body) + $body = unxmlify($child[SIMPLEPIE_NAMESPACE_ATOM_10]['summary'][0]['data']); + + if((strpos($body,'<') !== false) || (strpos($body,'>') !== false)) { + $body = purify_html($body); + $body = html2bbcode($body); + } + } + + $attach = $rawobj->get_enclosures(); + if($attach) { + foreach($attach as $att) { + $len = intval($att->get_length()); + $link = str_replace(array(',','"'),array('%2D','%22'),notags(trim(unxmlify($att->get_link())))); + $title = str_replace(array(',','"'),array('%2D','%22'),notags(trim(unxmlify($att->get_title())))); + $type = str_replace(array(',','"'),array('%2D','%22'),notags(trim(unxmlify($att->get_type())))); + if(strpos($type,';')) + $type = substr($type,0,strpos($type,';')); + if((! $link) || (strpos($link,'http') !== 0)) + continue; + + if(! $title) + $title = ' '; + if(! $type) + $type = 'application/octet-stream'; + + if((strpos($type,'image') === 0) && (strpos($body,$link) === false) && (strpos($link,'http') === 0)) { + $body .= "\n\n" . '[img]' . $link . '[/img]'; + } + } + } + + $res['body'] = "[share author='" . urlencode($share['author']) . + "' profile='" . $share['profile'] . + "' avatar='" . $share['avatar'] . + "' link='" . $share['link'] . + "' posted='" . $share['created'] . + "' message_id='" . $share['message_id'] . "']"; + $o .= $body; + $o .= "[/share]"; + } + +} + + + /** * @brief Encodes SimplePie_Item link arrays. * -- cgit v1.2.3 From 2f8fb2b663c9b1ea1879724d8542654263085b6d Mon Sep 17 00:00:00 2001 From: zotlabs Date: Mon, 12 Jun 2017 21:12:14 -0700 Subject: ostatus is almost unrecognisable these days from its former self. In this case thr:in-reply-to has almost no meaning since it almost never refers to a top level post; which makes it quite difficult to preserve conversations --- include/feedutils.php | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) (limited to 'include') diff --git a/include/feedutils.php b/include/feedutils.php index 23a065298..22e2b5add 100644 --- a/include/feedutils.php +++ b/include/feedutils.php @@ -996,11 +996,23 @@ function consume_feed($xml, $importer, &$contact, $pass = 0) { dbesc($parent_mid), intval($importer['channel_id']) ); - if($x) - $parent_mid = $x[0]['mid']; - $datarray['parent_mid'] = $parent_mid; + if($x) { + $pmid = $x[0]['mid']; + $datarray['parent_mid'] = $pmid; + } + else { + // immediate parent wasn't found. Turn into a top-level post if permissions allow + // but save the thread_parent in case we need to refer to it later. We should probably + // also save the ostatus:conversation_id + + if(! post_is_importable($datarray, $contact)) + continue; + $datarray['parent_mid'] = $datarray['mid']; + set_iconfig($datarray,'system','parent_mid',$parent_mid,true); + } + $datarray['aid'] = $importer['channel_account_id']; $datarray['uid'] = $importer['channel_id']; -- cgit v1.2.3 From 5530833bf88342bc407375fb9c29b99b2c79e7bc Mon Sep 17 00:00:00 2001 From: zotlabs Date: Mon, 12 Jun 2017 21:58:40 -0700 Subject: preserve the ostatus:conversation pointer also --- include/feedutils.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'include') diff --git a/include/feedutils.php b/include/feedutils.php index 22e2b5add..317516c74 100644 --- a/include/feedutils.php +++ b/include/feedutils.php @@ -386,7 +386,14 @@ function get_atom_elements($feed, $item, &$author) { } } - $ostatus_protocol = (($item->get_item_tags(NAMESPACE_OSTATUS, 'conversation')) ? true : false); + $rawcnv = $item->get_item_tags(NAMESPACE_OSTATUS, 'conversation'); + if($rawcnv) { + $ostatus_conversation = unxmlify($rawcnv[0]['attribs']['']['ref']); + set_iconfig($res,'ostatus','conversation',$ostatus_conversation,true); + } + + $ostatus_protocol = (($ostatus_conversation) ? true : false); + $mastodon = (($item->get_item_tags('http://mastodon.social/schema/1.0','scope')) ? true : false); if($mastodon) $ostatus_protocol = true; -- cgit v1.2.3 From 8eccd7d47d300f569ddb06d85f1a38441610d61e Mon Sep 17 00:00:00 2001 From: zotlabs Date: Tue, 13 Jun 2017 18:06:45 -0700 Subject: attempt to group gnu-social and mastodon conversations by ostatus:conversation in addition to falling back on thr:in_reply_to --- include/feedutils.php | 35 +++++++++++++++++++++++++---------- 1 file changed, 25 insertions(+), 10 deletions(-) (limited to 'include') diff --git a/include/feedutils.php b/include/feedutils.php index 317516c74..156a78a39 100644 --- a/include/feedutils.php +++ b/include/feedutils.php @@ -999,20 +999,35 @@ function consume_feed($xml, $importer, &$contact, $pass = 0) { continue; } - $x = q("select mid from item where mid = '%s' and uid = %d limit 1", - dbesc($parent_mid), - intval($importer['channel_id']) - ); - - if($x) { - $pmid = $x[0]['mid']; - $datarray['parent_mid'] = $pmid; + $pmid = ''; + $conv_id = get_iconfig($datarray,'ostatus','conversation'); + + if($conv_id) { + $c = q("select parent_mid from item left join iconfig on item.id = iconfig.iid where iconfig.cat = 'ostatus' and iconfig.k = 'conversation' and iconfig.v = '%s' and item.uid = %d order by item.id limit 1", + dbesc($conv_id), + intval($importer['channel_id']) + ); + if($c) { + $pmid = $x[0]['parent_mid']; + $datarray['parent_mid'] = $pmid; + } } else { + $x = q("select mid from item where mid = '%s' and uid = %d limit 1", + dbesc($parent_mid), + intval($importer['channel_id']) + ); + + if($x) { + $pmid = $x[0]['mid']; + $datarray['parent_mid'] = $pmid; + } + } + + if(! $pmid) { // immediate parent wasn't found. Turn into a top-level post if permissions allow - // but save the thread_parent in case we need to refer to it later. We should probably - // also save the ostatus:conversation_id + // but save the thread_parent in case we need to refer to it later. if(! post_is_importable($datarray, $contact)) continue; -- cgit v1.2.3 From dcbc65a796facf17d2194f0c6a738f43bfe2cc40 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Tue, 13 Jun 2017 18:29:08 -0700 Subject: add rel=noopener to all external target _blank links --- include/bbcode.php | 32 ++++++++++++++++---------------- include/text.php | 4 ++-- 2 files changed, 18 insertions(+), 18 deletions(-) (limited to 'include') diff --git a/include/bbcode.php b/include/bbcode.php index 0d2fb8c74..f0ec15130 100644 --- a/include/bbcode.php +++ b/include/bbcode.php @@ -839,7 +839,7 @@ function bbcode($Text, $preserve_nl = false, $tryoembed = true, $cache = false) if($tryoembed) { $Text = preg_replace_callback("/([^\]\='".'"'."\/]|^|\#\^)(https?\:\/\/$urlchars+)/ism", 'tryoembed', $Text); } - $Text = preg_replace("/([^\]\='".'"'."\/]|^|\#\^)(https?\:\/\/$urlchars+)/ism", '$1$2', $Text); + $Text = preg_replace("/([^\]\='".'"'."\/]|^|\#\^)(https?\:\/\/$urlchars+)/ism", '$1$2', $Text); } if (strpos($Text,'[/share]') !== false) { @@ -851,16 +851,16 @@ function bbcode($Text, $preserve_nl = false, $tryoembed = true, $cache = false) } } if (strpos($Text,'[/url]') !== false) { - $Text = preg_replace("/\#\^\[url\]([$URLSearchString]*)\[\/url\]/ism", '#^$1', $Text); - $Text = preg_replace("/\#\^\[url\=([$URLSearchString]*)\](.*?)\[\/url\]/ism", '#^$2', $Text); - $Text = preg_replace("/\[url\]([$URLSearchString]*)\[\/url\]/ism", '$1', $Text); - $Text = preg_replace("/\[url\=([$URLSearchString]*)\](.*?)\[\/url\]/ism", '$2', $Text); + $Text = preg_replace("/\#\^\[url\]([$URLSearchString]*)\[\/url\]/ism", '#^$1', $Text); + $Text = preg_replace("/\#\^\[url\=([$URLSearchString]*)\](.*?)\[\/url\]/ism", '#^$2', $Text); + $Text = preg_replace("/\[url\]([$URLSearchString]*)\[\/url\]/ism", '$1', $Text); + $Text = preg_replace("/\[url\=([$URLSearchString]*)\](.*?)\[\/url\]/ism", '$2', $Text); } if (strpos($Text,'[/zrl]') !== false) { - $Text = preg_replace("/\#\^\[zrl\]([$URLSearchString]*)\[\/zrl\]/ism", '#^$1', $Text); - $Text = preg_replace("/\#\^\[zrl\=([$URLSearchString]*)\](.*?)\[\/zrl\]/ism", '#^$2', $Text); - $Text = preg_replace("/\[zrl\]([$URLSearchString]*)\[\/zrl\]/ism", '$1', $Text); - $Text = preg_replace("/\[zrl\=([$URLSearchString]*)\](.*?)\[\/zrl\]/ism", '$2', $Text); + $Text = preg_replace("/\#\^\[zrl\]([$URLSearchString]*)\[\/zrl\]/ism", '#^$1', $Text); + $Text = preg_replace("/\#\^\[zrl\=([$URLSearchString]*)\](.*?)\[\/zrl\]/ism", '#^$2', $Text); + $Text = preg_replace("/\[zrl\]([$URLSearchString]*)\[\/zrl\]/ism", '$1', $Text); + $Text = preg_replace("/\[zrl\=([$URLSearchString]*)\](.*?)\[\/zrl\]/ism", '$2', $Text); } if (get_account_techlevel() < 2) @@ -868,8 +868,8 @@ function bbcode($Text, $preserve_nl = false, $tryoembed = true, $cache = false) // Perform MAIL Search if (strpos($Text,'[/mail]') !== false) { - $Text = preg_replace("/\[mail\]([$MAILSearchString]*)\[\/mail\]/", '$1', $Text); - $Text = preg_replace("/\[mail\=([$MAILSearchString]*)\](.*?)\[\/mail\]/", '$2', $Text); + $Text = preg_replace("/\[mail\]([$MAILSearchString]*)\[\/mail\]/", '$1', $Text); + $Text = preg_replace("/\[mail\=([$MAILSearchString]*)\](.*?)\[\/mail\]/", '$2', $Text); } @@ -1189,17 +1189,17 @@ function bbcode($Text, $preserve_nl = false, $tryoembed = true, $cache = false) // if video couldn't be embedded, link to it instead. if (strpos($Text,'[/video]') !== false) { - $Text = preg_replace("/\[video\](.*?)\[\/video\]/", '$1', $Text); + $Text = preg_replace("/\[video\](.*?)\[\/video\]/", '$1', $Text); } if (strpos($Text,'[/audio]') !== false) { - $Text = preg_replace("/\[audio\](.*?)\[\/audio\]/", '$1', $Text); + $Text = preg_replace("/\[audio\](.*?)\[\/audio\]/", '$1', $Text); } if (strpos($Text,'[/zvideo]') !== false) { - $Text = preg_replace("/\[zvideo\](.*?)\[\/zvideo\]/", '$1', $Text); + $Text = preg_replace("/\[zvideo\](.*?)\[\/zvideo\]/", '$1', $Text); } if (strpos($Text,'[/zaudio]') !== false) { - $Text = preg_replace("/\[zaudio\](.*?)\[\/zaudio\]/", '$1', $Text); + $Text = preg_replace("/\[zaudio\](.*?)\[\/zaudio\]/", '$1', $Text); } // if ($tryoembed){ @@ -1208,7 +1208,7 @@ function bbcode($Text, $preserve_nl = false, $tryoembed = true, $cache = false) // } // } else { // if (strpos($Text,'[/iframe]') !== false) { -// $Text = preg_replace("/\[iframe\](.*?)\[\/iframe\]/ism", '$1', $Text); +// $Text = preg_replace("/\[iframe\](.*?)\[\/iframe\]/ism", '$1', $Text); // } // } diff --git a/include/text.php b/include/text.php index d8438b2b1..c633ba62a 100644 --- a/include/text.php +++ b/include/text.php @@ -1552,13 +1552,13 @@ function prepare_body(&$item,$attach = false) { // if original photo width is <= 640px prepend it to item body if($object['link'][0]['width'] && $object['link'][0]['width'] <= 640) { - $s .= '
    ' . $s; + $s .= '
    ' . $s; } // if original photo width is > 640px make it a cover photo if($object['link'][0]['width'] && $object['link'][0]['width'] > 640) { $scale = ((($object['link'][1]['width'] == 1024) || ($object['link'][1]['height'] == 1024)) ? 1 : 0); - $photo = ''; + $photo = ''; } } -- cgit v1.2.3 From 70e912736f10bb8eaf8978689ae0183f7970043c Mon Sep 17 00:00:00 2001 From: zotlabs Date: Tue, 13 Jun 2017 19:52:16 -0700 Subject: support mastodon content warnings by converting into n-s-f-w tag --- include/feedutils.php | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'include') diff --git a/include/feedutils.php b/include/feedutils.php index 156a78a39..c9c7522b1 100644 --- a/include/feedutils.php +++ b/include/feedutils.php @@ -266,6 +266,8 @@ function get_atom_elements($feed, $item, &$author) { $res['item_rss'] = 1; + $summary = unxmlify($item->get_description(true)); + // removing the content of the title if its identically to the body // This helps with auto generated titles e.g. from tumblr @@ -486,6 +488,12 @@ function get_atom_elements($feed, $item, &$author) { ); } + // turn Mastodon content warning into a #nsfw hashtag + if($mastodon && $summary) { + $res['body'] .= "\n\n#nsfw\n"; + } + + $private = $item->get_item_tags(NAMESPACE_DFRN, 'private'); if($private && intval($private[0]['data']) > 0) $res['item_private'] = ((intval($private[0]['data'])) ? 1 : 0); -- cgit v1.2.3 From 54e07389fa1ebe7a2d2815258b021c07d2fc4dd0 Mon Sep 17 00:00:00 2001 From: Mario Vavti Date: Wed, 14 Jun 2017 22:14:52 +0200 Subject: thr:in-reply-to seems to must not have a type set. there is no mention of this in the spec and replies will be shown as replies in mastodon this way. --- include/feedutils.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include') diff --git a/include/feedutils.php b/include/feedutils.php index c9c7522b1..d1c7a5c64 100644 --- a/include/feedutils.php +++ b/include/feedutils.php @@ -1505,7 +1505,7 @@ function atom_entry($item, $type, $author, $owner, $comment = false, $cid = 0, $ if(($item['parent'] != $item['id']) || ($item['parent_mid'] !== $item['mid']) || (($item['thr_parent'] !== '') && ($item['thr_parent'] !== $item['mid']))) { $parent_item = (($item['thr_parent']) ? $item['thr_parent'] : $item['parent_mid']); - $o .= '' . "\r\n"; + $o .= '' . "\r\n"; } if(activity_match($item['obj_type'],ACTIVITY_OBJ_EVENT) && activity_match($item['verb'],ACTIVITY_POST)) { -- cgit v1.2.3 From 3f488e98421597749a7fc8af35e48d0b11f980ae Mon Sep 17 00:00:00 2001 From: Mario Vavti Date: Wed, 14 Jun 2017 22:53:09 +0200 Subject: fix illegal offset type warning --- include/connections.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'include') diff --git a/include/connections.php b/include/connections.php index 85b961b65..56457ea10 100644 --- a/include/connections.php +++ b/include/connections.php @@ -634,8 +634,8 @@ function get_vcard_array($vc,$id) { 'address' => $adr->getParts() ]; $last_entry = end($adrs); - if($adrs[$last_entry]['address']) - array_walk($adrs[$last_entry]['address'],'array_escape_tags'); + if($last_entry['address']) + array_walk($last_entry['address'],'array_escape_tags'); } } -- cgit v1.2.3 From ec74b5700024063ea8bd3fb8d644df881c704fb3 Mon Sep 17 00:00:00 2001 From: Mario Vavti Date: Wed, 14 Jun 2017 23:21:47 +0200 Subject: re-add type since the actual culprit was the X-ZOT prefix --- include/feedutils.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include') diff --git a/include/feedutils.php b/include/feedutils.php index d1c7a5c64..eb2d3a6e1 100644 --- a/include/feedutils.php +++ b/include/feedutils.php @@ -1505,7 +1505,7 @@ function atom_entry($item, $type, $author, $owner, $comment = false, $cid = 0, $ if(($item['parent'] != $item['id']) || ($item['parent_mid'] !== $item['mid']) || (($item['thr_parent'] !== '') && ($item['thr_parent'] !== $item['mid']))) { $parent_item = (($item['thr_parent']) ? $item['thr_parent'] : $item['parent_mid']); - $o .= '' . "\r\n"; + $o .= '' . "\r\n"; } if(activity_match($item['obj_type'],ACTIVITY_OBJ_EVENT) && activity_match($item['verb'],ACTIVITY_POST)) { -- cgit v1.2.3 From fe02665f54a2bd4746757348680a2cee439c2750 Mon Sep 17 00:00:00 2001 From: Mario Vavti Date: Thu, 15 Jun 2017 00:17:26 +0200 Subject: typo --- include/feedutils.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include') diff --git a/include/feedutils.php b/include/feedutils.php index eb2d3a6e1..c9c7522b1 100644 --- a/include/feedutils.php +++ b/include/feedutils.php @@ -1505,7 +1505,7 @@ function atom_entry($item, $type, $author, $owner, $comment = false, $cid = 0, $ if(($item['parent'] != $item['id']) || ($item['parent_mid'] !== $item['mid']) || (($item['thr_parent'] !== '') && ($item['thr_parent'] !== $item['mid']))) { $parent_item = (($item['thr_parent']) ? $item['thr_parent'] : $item['parent_mid']); - $o .= '' . "\r\n"; + $o .= '' . "\r\n"; } if(activity_match($item['obj_type'],ACTIVITY_OBJ_EVENT) && activity_match($item['verb'],ACTIVITY_POST)) { -- cgit v1.2.3 From 1f075d92bc4e47ae282f811d10c31cd6f09191a6 Mon Sep 17 00:00:00 2001 From: Mario Vavti Date: Thu, 15 Jun 2017 00:19:50 +0200 Subject: sigh... x-zot prefix slipped in again --- include/feedutils.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include') diff --git a/include/feedutils.php b/include/feedutils.php index c9c7522b1..02decca69 100644 --- a/include/feedutils.php +++ b/include/feedutils.php @@ -1505,7 +1505,7 @@ function atom_entry($item, $type, $author, $owner, $comment = false, $cid = 0, $ if(($item['parent'] != $item['id']) || ($item['parent_mid'] !== $item['mid']) || (($item['thr_parent'] !== '') && ($item['thr_parent'] !== $item['mid']))) { $parent_item = (($item['thr_parent']) ? $item['thr_parent'] : $item['parent_mid']); - $o .= '' . "\r\n"; + $o .= '' . "\r\n"; } if(activity_match($item['obj_type'],ACTIVITY_OBJ_EVENT) && activity_match($item['verb'],ACTIVITY_POST)) { -- cgit v1.2.3 From 7b948bdd29e44920e4c1af9bcba26958220daca2 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Wed, 14 Jun 2017 16:06:25 -0700 Subject: use parent_mid --- include/feedutils.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'include') diff --git a/include/feedutils.php b/include/feedutils.php index 96e5fdc6b..68af88256 100644 --- a/include/feedutils.php +++ b/include/feedutils.php @@ -1025,13 +1025,13 @@ function consume_feed($xml, $importer, &$contact, $pass = 0) { } } else { - $x = q("select mid from item where mid = '%s' and uid = %d limit 1", + $x = q("select parent_mid from item where mid = '%s' and uid = %d limit 1", dbesc($parent_mid), intval($importer['channel_id']) ); if($x) { - $pmid = $x[0]['mid']; + $pmid = $x[0]['parent_mid']; $datarray['parent_mid'] = $pmid; } } -- cgit v1.2.3 From 8b3d2c02e1af80159d18bddb049e93b4fb28c249 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Wed, 14 Jun 2017 19:59:25 -0700 Subject: always transmit a valid uri --- include/feedutils.php | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'include') diff --git a/include/feedutils.php b/include/feedutils.php index f5cb12cd9..4a563ade7 100644 --- a/include/feedutils.php +++ b/include/feedutils.php @@ -1510,6 +1510,10 @@ function atom_entry($item, $type, $author, $owner, $comment = false, $cid = 0, $ if(($item['parent'] != $item['id']) || ($item['parent_mid'] !== $item['mid']) || (($item['thr_parent'] !== '') && ($item['thr_parent'] !== $item['mid']))) { $parent_item = (($item['thr_parent']) ? $item['thr_parent'] : $item['parent_mid']); + // ensure it's a legal uri and not just a message-id + if(! strpos($parent_item,':')) + $parent_item = 'X-ZOT:' . $parent_item; + $o .= '' . "\r\n"; } -- cgit v1.2.3 From 327b22d24ef62ac4057728dfa31aec6f1f76b2d0 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Wed, 14 Jun 2017 20:20:18 -0700 Subject: remove some duplicated code --- include/feedutils.php | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) (limited to 'include') diff --git a/include/feedutils.php b/include/feedutils.php index 4a563ade7..568c1e9ed 100644 --- a/include/feedutils.php +++ b/include/feedutils.php @@ -259,7 +259,7 @@ function get_atom_elements($feed, $item, &$author) { if(substr($author['author_link'],-1,1) == '/') $author['author_link'] = substr($author['author_link'],0,-1); - $res['mid'] = unxmlify($item->get_id()); + $res['mid'] = normalise_id(unxmlify($item->get_id())); $res['title'] = unxmlify($item->get_title()); $res['body'] = unxmlify($item->get_content()); $res['plink'] = unxmlify($item->get_link(0)); @@ -391,7 +391,7 @@ function get_atom_elements($feed, $item, &$author) { $rawcnv = $item->get_item_tags(NAMESPACE_OSTATUS, 'conversation'); if($rawcnv) { - $ostatus_conversation = unxmlify($rawcnv[0]['attribs']['']['ref']); + $ostatus_conversation = normalise_id(unxmlify($rawcnv[0]['attribs']['']['ref'])); set_iconfig($res,'ostatus','conversation',$ostatus_conversation,true); } @@ -943,7 +943,6 @@ function consume_feed($xml, $importer, &$contact, $pass = 0) { foreach($items as $item) { $is_reply = false; - $item_id = normalise_id($item->get_id()); logger('processing ' . $item->get_id(), LOGGER_DEBUG); @@ -960,12 +959,11 @@ function consume_feed($xml, $importer, &$contact, $pass = 0) { // Have we seen it? If not, import it. - $item_id = normalise_id($item->get_id()); $author = array(); $datarray = get_atom_elements($feed,$item,$author); - if($datarray['mid']) - $datarray['mid'] = normalise_id($item->get_id()); + if(! $datarray['mid']) + continue; if($contact['xchan_network'] === 'rss') { $datarray['public_policy'] = 'specific'; @@ -992,7 +990,7 @@ function consume_feed($xml, $importer, &$contact, $pass = 0) { $datarray['owner_xchan'] = $contact['xchan_hash']; $r = q("SELECT edited FROM item WHERE mid = '%s' AND uid = %d LIMIT 1", - dbesc($item_id), + dbesc($datarray['mid']), intval($importer['channel_id']) ); @@ -1015,6 +1013,9 @@ function consume_feed($xml, $importer, &$contact, $pass = 0) { $pmid = ''; $conv_id = get_iconfig($datarray,'ostatus','conversation'); + // match conversations - first try ostatus:conversation + // next try thr:in_reply_to + if($conv_id) { $c = q("select parent_mid from item left join iconfig on item.id = iconfig.iid where iconfig.cat = 'ostatus' and iconfig.k = 'conversation' and iconfig.v = '%s' and item.uid = %d order by item.id limit 1", dbesc($conv_id), @@ -1025,7 +1026,7 @@ function consume_feed($xml, $importer, &$contact, $pass = 0) { $datarray['parent_mid'] = $pmid; } } - else { + if(! $pmid) { $x = q("select parent_mid from item where mid = '%s' and uid = %d limit 1", dbesc($parent_mid), intval($importer['channel_id']) @@ -1061,12 +1062,11 @@ function consume_feed($xml, $importer, &$contact, $pass = 0) { // Head post of a conversation. Have we seen it? If not, import it. - $item_id = normalise_id($item->get_id()); $author = array(); $datarray = get_atom_elements($feed,$item,$author); - if($datarray['mid']) - $datarray['mid'] = normalise_id($item->get_id()); + if(! $datarray['mid']) + continue; if($contact['xchan_network'] === 'rss') { $datarray['public_policy'] = 'specific'; @@ -1121,7 +1121,7 @@ function consume_feed($xml, $importer, &$contact, $pass = 0) { $r = q("SELECT edited FROM item WHERE mid = '%s' AND uid = %d LIMIT 1", - dbesc($item_id), + dbesc($datarray['mid']), intval($importer['channel_id']) ); @@ -1141,7 +1141,7 @@ function consume_feed($xml, $importer, &$contact, $pass = 0) { continue; } - $datarray['parent_mid'] = $item_id; + $datarray['parent_mid'] = $datarray['mid']; $datarray['uid'] = $importer['channel_id']; $datarray['aid'] = $importer['channel_account_id']; -- cgit v1.2.3 From b8c77bbcfcc5f1f25ff61ac5fc9f284148955221 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Wed, 14 Jun 2017 16:06:25 -0700 Subject: use parent_mid --- include/feedutils.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'include') diff --git a/include/feedutils.php b/include/feedutils.php index 02decca69..5e5056f7c 100644 --- a/include/feedutils.php +++ b/include/feedutils.php @@ -1021,13 +1021,13 @@ function consume_feed($xml, $importer, &$contact, $pass = 0) { } } else { - $x = q("select mid from item where mid = '%s' and uid = %d limit 1", + $x = q("select parent_mid from item where mid = '%s' and uid = %d limit 1", dbesc($parent_mid), intval($importer['channel_id']) ); if($x) { - $pmid = $x[0]['mid']; + $pmid = $x[0]['parent_mid']; $datarray['parent_mid'] = $pmid; } } -- cgit v1.2.3 From 0d7e7ac657ce4d1e7d2797b565882d3a57dfd8de Mon Sep 17 00:00:00 2001 From: zotlabs Date: Wed, 14 Jun 2017 19:59:25 -0700 Subject: always transmit a valid uri --- include/feedutils.php | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'include') diff --git a/include/feedutils.php b/include/feedutils.php index 5e5056f7c..2f3927748 100644 --- a/include/feedutils.php +++ b/include/feedutils.php @@ -1505,6 +1505,10 @@ function atom_entry($item, $type, $author, $owner, $comment = false, $cid = 0, $ if(($item['parent'] != $item['id']) || ($item['parent_mid'] !== $item['mid']) || (($item['thr_parent'] !== '') && ($item['thr_parent'] !== $item['mid']))) { $parent_item = (($item['thr_parent']) ? $item['thr_parent'] : $item['parent_mid']); + // ensure it's a legal uri and not just a message-id + if(! strpos($parent_item,':')) + $parent_item = 'X-ZOT:' . $parent_item; + $o .= '' . "\r\n"; } -- cgit v1.2.3 From bb9557a9ae9bbec806ef6e91c25120df0da8a72e Mon Sep 17 00:00:00 2001 From: zotlabs Date: Wed, 14 Jun 2017 20:20:18 -0700 Subject: remove some duplicated code --- include/feedutils.php | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) (limited to 'include') diff --git a/include/feedutils.php b/include/feedutils.php index 2f3927748..0d7e1d6c2 100644 --- a/include/feedutils.php +++ b/include/feedutils.php @@ -259,7 +259,7 @@ function get_atom_elements($feed, $item, &$author) { if(substr($author['author_link'],-1,1) == '/') $author['author_link'] = substr($author['author_link'],0,-1); - $res['mid'] = unxmlify($item->get_id()); + $res['mid'] = normalise_id(unxmlify($item->get_id())); $res['title'] = unxmlify($item->get_title()); $res['body'] = unxmlify($item->get_content()); $res['plink'] = unxmlify($item->get_link(0)); @@ -390,7 +390,7 @@ function get_atom_elements($feed, $item, &$author) { $rawcnv = $item->get_item_tags(NAMESPACE_OSTATUS, 'conversation'); if($rawcnv) { - $ostatus_conversation = unxmlify($rawcnv[0]['attribs']['']['ref']); + $ostatus_conversation = normalise_id(unxmlify($rawcnv[0]['attribs']['']['ref'])); set_iconfig($res,'ostatus','conversation',$ostatus_conversation,true); } @@ -938,7 +938,6 @@ function consume_feed($xml, $importer, &$contact, $pass = 0) { foreach($items as $item) { $is_reply = false; - $item_id = normalise_id($item->get_id()); logger('processing ' . $item->get_id(), LOGGER_DEBUG); @@ -955,12 +954,11 @@ function consume_feed($xml, $importer, &$contact, $pass = 0) { // Have we seen it? If not, import it. - $item_id = normalise_id($item->get_id()); $author = array(); $datarray = get_atom_elements($feed,$item,$author); - if($datarray['mid']) - $datarray['mid'] = normalise_id($item->get_id()); + if(! $datarray['mid']) + continue; if($contact['xchan_network'] === 'rss') { $datarray['public_policy'] = 'specific'; @@ -987,7 +985,7 @@ function consume_feed($xml, $importer, &$contact, $pass = 0) { $datarray['owner_xchan'] = $contact['xchan_hash']; $r = q("SELECT edited FROM item WHERE mid = '%s' AND uid = %d LIMIT 1", - dbesc($item_id), + dbesc($datarray['mid']), intval($importer['channel_id']) ); @@ -1010,6 +1008,9 @@ function consume_feed($xml, $importer, &$contact, $pass = 0) { $pmid = ''; $conv_id = get_iconfig($datarray,'ostatus','conversation'); + // match conversations - first try ostatus:conversation + // next try thr:in_reply_to + if($conv_id) { $c = q("select parent_mid from item left join iconfig on item.id = iconfig.iid where iconfig.cat = 'ostatus' and iconfig.k = 'conversation' and iconfig.v = '%s' and item.uid = %d order by item.id limit 1", dbesc($conv_id), @@ -1020,7 +1021,7 @@ function consume_feed($xml, $importer, &$contact, $pass = 0) { $datarray['parent_mid'] = $pmid; } } - else { + if(! $pmid) { $x = q("select parent_mid from item where mid = '%s' and uid = %d limit 1", dbesc($parent_mid), intval($importer['channel_id']) @@ -1056,12 +1057,11 @@ function consume_feed($xml, $importer, &$contact, $pass = 0) { // Head post of a conversation. Have we seen it? If not, import it. - $item_id = normalise_id($item->get_id()); $author = array(); $datarray = get_atom_elements($feed,$item,$author); - if($datarray['mid']) - $datarray['mid'] = normalise_id($item->get_id()); + if(! $datarray['mid']) + continue; if($contact['xchan_network'] === 'rss') { $datarray['public_policy'] = 'specific'; @@ -1116,7 +1116,7 @@ function consume_feed($xml, $importer, &$contact, $pass = 0) { $r = q("SELECT edited FROM item WHERE mid = '%s' AND uid = %d LIMIT 1", - dbesc($item_id), + dbesc($datarray['mid']), intval($importer['channel_id']) ); @@ -1136,7 +1136,7 @@ function consume_feed($xml, $importer, &$contact, $pass = 0) { continue; } - $datarray['parent_mid'] = $item_id; + $datarray['parent_mid'] = $datarray['mid']; $datarray['uid'] = $importer['channel_id']; $datarray['aid'] = $importer['channel_account_id']; -- cgit v1.2.3 From b429576349a9a1909f1605226a246507feab1350 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Fri, 16 Jun 2017 15:28:29 -0700 Subject: some logic cleanup in feed_get_reshare --- include/feedutils.php | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) (limited to 'include') diff --git a/include/feedutils.php b/include/feedutils.php index 568c1e9ed..459cfb5ff 100644 --- a/include/feedutils.php +++ b/include/feedutils.php @@ -718,7 +718,7 @@ function feed_get_reshare(&$res,$item) { if($rawobj) { - $rawauthor = $rawobj->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'author'); + $rawauthor = $rawobj[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['author']; if($rawauthor && $rawauthor[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name']) { $share['author'] = unxmlify($rawauthor[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name']); @@ -751,7 +751,8 @@ function feed_get_reshare(&$res,$item) { if(x($child[SIMPLEPIE_NAMESPACE_ATOM_10], 'link') && $child[SIMPLEPIE_NAMESPACE_ATOM_10]['link']) $share['link'] = encode_rel_links($child[SIMPLEPIE_NAMESPACE_ATOM_10]['link']); - $rawcreated = $rawobj->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'published'); + $rawcreated = $rawobj[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['published']; + if($rawcreated) $share['created'] = unxmlify($rawcreated[0]['data']); else @@ -771,13 +772,15 @@ function feed_get_reshare(&$res,$item) { } } - $attach = $rawobj->get_enclosures(); + $attach = $share['link']; if($attach) { foreach($attach as $att) { - $len = intval($att->get_length()); - $link = str_replace(array(',','"'),array('%2D','%22'),notags(trim(unxmlify($att->get_link())))); - $title = str_replace(array(',','"'),array('%2D','%22'),notags(trim(unxmlify($att->get_title())))); - $type = str_replace(array(',','"'),array('%2D','%22'),notags(trim(unxmlify($att->get_type())))); + if($att['rel'] !== 'enclosure') + continue; + $len = intval($att['length']); + $link = str_replace(array(',','"'),array('%2D','%22'),notags(trim(unxmlify($att['href'])))); + $title = str_replace(array(',','"'),array('%2D','%22'),notags(trim(unxmlify($att['title'])))); + $type = str_replace(array(',','"'),array('%2D','%22'),notags(trim(unxmlify($att['type'])))); if(strpos($type,';')) $type = substr($type,0,strpos($type,';')); if((! $link) || (strpos($link,'http') !== 0)) @@ -823,6 +826,10 @@ function encode_rel_links($links) { $l = array(); if($link['attribs']['']['rel']) $l['rel'] = $link['attribs']['']['rel']; + if($link['attribs']['']['length']) + $l['length'] = $link['attribs']['']['length']; + if($link['attribs']['']['title']) + $l['title'] = $link['attribs']['']['title']; if($link['attribs']['']['type']) $l['type'] = $link['attribs']['']['type']; if($link['attribs']['']['href']) -- cgit v1.2.3 From 1848a221180d20d7d904a828b8969653a0f319d0 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Fri, 16 Jun 2017 19:30:02 -0700 Subject: testing mastodon boosts/reshares --- include/feedutils.php | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) (limited to 'include') diff --git a/include/feedutils.php b/include/feedutils.php index 459cfb5ff..759c8a05c 100644 --- a/include/feedutils.php +++ b/include/feedutils.php @@ -688,7 +688,10 @@ function get_atom_elements($feed, $item, &$author) { $res['target'] = $obj; } - if(array_key_exists('verb',$res) && $res['verb'] === ACTIVITY_SHARE) { + + + if(array_key_exists('verb',$res) && $res['verb'] === ACTIVITY_SHARE + && array_key_exists('obj_type',$res) && $res['obj_type'] === ACTIVITY_OBJ_NOTE) { feed_get_reshare($res,$item); } @@ -721,11 +724,11 @@ function feed_get_reshare(&$res,$item) { $rawauthor = $rawobj[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['author']; if($rawauthor && $rawauthor[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name']) { - $share['author'] = unxmlify($rawauthor[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name']); + $share['author'] = unxmlify($rawauthor[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name'][0]['data']); } if($rawauthor && $rawauthor[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['uri']) { - $share['profile'] = unxmlify($rawauthor[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['uri']); + $share['profile'] = unxmlify($rawauthor[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['uri'][0]['data']); } if($rawauthor && $rawauthor[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['link']) { @@ -749,7 +752,7 @@ function feed_get_reshare(&$res,$item) { if(x($child[SIMPLEPIE_NAMESPACE_ATOM_10], 'link') && $child[SIMPLEPIE_NAMESPACE_ATOM_10]['link']) - $share['link'] = encode_rel_links($child[SIMPLEPIE_NAMESPACE_ATOM_10]['link']); + $share['links'] = encode_rel_links($child[SIMPLEPIE_NAMESPACE_ATOM_10]['link']); $rawcreated = $rawobj[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['published']; @@ -772,9 +775,13 @@ function feed_get_reshare(&$res,$item) { } } - $attach = $share['link']; + $attach = $share['links']; if($attach) { foreach($attach as $att) { + if($att['rel'] === 'alternate') { + $share['alternate'] = str_replace(array(',','"'),array('%2D','%22'),notags(trim(unxmlify($att['href'])))); + continue; + } if($att['rel'] !== 'enclosure') continue; $len = intval($att['length']); @@ -800,11 +807,12 @@ function feed_get_reshare(&$res,$item) { $res['body'] = "[share author='" . urlencode($share['author']) . "' profile='" . $share['profile'] . "' avatar='" . $share['avatar'] . - "' link='" . $share['link'] . + "' link='" . $share['alternate'] . "' posted='" . $share['created'] . "' message_id='" . $share['message_id'] . "']"; - $o .= $body; - $o .= "[/share]"; + + $res['body'] .= $body; + $res['body'] .= "[/share]"; } } -- cgit v1.2.3 From b917cf1eccc62f5f533c0a61ffd699764b39e404 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Sun, 18 Jun 2017 22:25:41 -0700 Subject: allow moderated comments like wordpress if permissions are compatible --- include/channel.php | 66 ++++++++++++++++++++++++++++++++++++++++++++++++ include/conversation.php | 22 ++++++++++------ include/items.php | 2 +- 3 files changed, 81 insertions(+), 9 deletions(-) (limited to 'include') diff --git a/include/channel.php b/include/channel.php index b06c1994f..86fa2a63a 100644 --- a/include/channel.php +++ b/include/channel.php @@ -2306,3 +2306,69 @@ function channel_codeallowed($channel_id) { } +function anon_identity_init($reqvars) { + + $x = [ 'request_vars' => $reqvars, 'xchan' => null, 'success' => 'unset' ]; + call_hooks('anon_identity_init',$x); + if($x['success'] !== 'unset' && intval($x['success']) && $x['xchan']) + return $x['xchan']; + + // allow a captcha handler to over-ride + if($x['success'] !== 'unset' && (intval($x['success']) === 0)) + return false; + + + $anon_name = strip_tags(trim($reqvars['anonname'])); + $anon_email = strip_tags(trim($reqvars['anonmail'])); + $anon_url = strip_tags(trim($reqvars['anonurl'])); + + if(! ($anon_name && $anon_email)) { + logger('anonymous commenter did not complete form'); + return false; + } + + if(! validate_email($anon_email)) { + logger('enonymous email not valid'); + return false; + } + + if(! $anon_url) + $anon_url = z_root(); + + $x = q("select * from xchan where xchan_guid = '%s' and xchan_hash = '%s' and xchan_network = 'unknown' limit 1", + dbesc($anon_email), + dbesc($anon_email) + ); + + if(! $x) { + xchan_store_lowlevel([ + 'xchan_guid' => $anon_email, + 'xchan_hash' => $anon_email, + 'xchan_name' => $anon_name, + 'xchan_url' => $anon_url, + 'xchan_network' => 'unknown', + 'xchan_name_date' => datetime_convert() + ]); + + $x = q("select * from xchan where xchan_guid = '%s' and xchan_hash = '%s' and xchan_network = 'unknown' limit 1", + dbesc($anon_email), + dbesc($anon_email) + ); + + $photo = z_root() . '/' . get_default_profile_photo(300); + $photos = import_xchan_photo($photo,$anon_email); + $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_guid = '%s' and xchan_hash = '%s' and xchan_network = 'unknown' ", + dbesc(datetime_convert()), + dbesc($photos[0]), + dbesc($photos[1]), + dbesc($photos[2]), + dbesc($photos[3]), + dbesc($anon_email), + dbesc($anon_email) + ); + + } + + return $x[0]; + +} \ No newline at end of file diff --git a/include/conversation.php b/include/conversation.php index 3f9ee5cfa..2eac2adde 100644 --- a/include/conversation.php +++ b/include/conversation.php @@ -533,6 +533,10 @@ function conversation(&$a, $items, $mode, $update, $page_mode = 'traditional', $ $live_update_div = '' . "\r\n"; } + elseif ($mode === 'moderate') { + $profile_owner = local_channel(); + } + elseif ($mode === 'photos') { $profile_onwer = App::$profile['profile_uid']; $page_writeable = ($profile_owner == local_channel()); @@ -577,7 +581,7 @@ function conversation(&$a, $items, $mode, $update, $page_mode = 'traditional', $ if($items) { - if($mode === 'network-new' || $mode === 'search' || $mode === 'community') { + if(in_array($mode, [ 'network-new', 'search', 'community', 'moderate' ])) { // "New Item View" on network page or search page results // - just loop through the items and format them minimally for display @@ -609,14 +613,14 @@ function conversation(&$a, $items, $mode, $update, $page_mode = 'traditional', $ if(((activity_match($item['verb'],ACTIVITY_LIKE)) || (activity_match($item['verb'],ACTIVITY_DISLIKE))) && ($item['id'] != $item['parent'])) continue; - $nickname = $item['nickname']; +// $nickname = $item['nickname']; } - else - $nickname = App::$user['nickname']; +// else +// $nickname = App::$user['nickname']; - $profile_name = ((strlen($item['author-name'])) ? $item['author-name'] : $item['name']); - if($item['author-link'] && (! $item['author-name'])) - $profile_name = $item['author-link']; +// $profile_name = ((strlen($item['author-name'])) ? $item['author-name'] : $item['name']); +// if($item['author-link'] && (! $item['author-name'])) +// $profile_name = $item['author-link']; $sp = false; $profile_link = best_link_url($item,$sp); @@ -625,7 +629,7 @@ function conversation(&$a, $items, $mode, $update, $page_mode = 'traditional', $ else $profile_link = zid($profile_link); - $normalised = normalise_link((strlen($item['author-link'])) ? $item['author-link'] : $item['url']); +// $normalised = normalise_link((strlen($item['author-link'])) ? $item['author-link'] : $item['url']); $profile_name = $item['author']['xchan_name']; $profile_link = $item['author']['xchan_url']; @@ -679,6 +683,8 @@ function conversation(&$a, $items, $mode, $update, $page_mode = 'traditional', $ 'template' => $tpl, 'toplevel' => 'toplevel_item', 'mode' => $mode, + 'approve' => t('Approve'), + 'delete' => t('Delete'), 'id' => (($preview) ? 'P0' : $item['item_id']), 'linktitle' => sprintf( t('View %s\'s profile @ %s'), $profile_name, $profile_url), 'profile_url' => $profile_link, diff --git a/include/items.php b/include/items.php index e79707aeb..9e1d5c1ba 100755 --- a/include/items.php +++ b/include/items.php @@ -906,7 +906,7 @@ function import_author_unknown($x) { $photos = import_xchan_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 = 'unknown'", + $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_hash = '%s' and xchan_network = 'unknown'", dbesc(datetime_convert()), dbesc($photos[0]), dbesc($photos[1]), -- cgit v1.2.3 From b0a6a5a91e0180c0ed3de1af324e7b9567c5e108 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Sun, 18 Jun 2017 22:51:52 -0700 Subject: minor cleanup of moderated comment feature --- include/channel.php | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'include') diff --git a/include/channel.php b/include/channel.php index 86fa2a63a..433c7c52c 100644 --- a/include/channel.php +++ b/include/channel.php @@ -2335,28 +2335,31 @@ function anon_identity_init($reqvars) { if(! $anon_url) $anon_url = z_root(); + $hash = hash('md5',$anon_email); + $x = q("select * from xchan where xchan_guid = '%s' and xchan_hash = '%s' and xchan_network = 'unknown' limit 1", dbesc($anon_email), - dbesc($anon_email) + dbesc($hash) ); if(! $x) { xchan_store_lowlevel([ 'xchan_guid' => $anon_email, - 'xchan_hash' => $anon_email, + 'xchan_hash' => $hash, 'xchan_name' => $anon_name, 'xchan_url' => $anon_url, 'xchan_network' => 'unknown', 'xchan_name_date' => datetime_convert() ]); + $x = q("select * from xchan where xchan_guid = '%s' and xchan_hash = '%s' and xchan_network = 'unknown' limit 1", dbesc($anon_email), - dbesc($anon_email) + dbesc($hash) ); $photo = z_root() . '/' . get_default_profile_photo(300); - $photos = import_xchan_photo($photo,$anon_email); + $photos = import_xchan_photo($photo,$hash); $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_guid = '%s' and xchan_hash = '%s' and xchan_network = 'unknown' ", dbesc(datetime_convert()), dbesc($photos[0]), @@ -2364,7 +2367,7 @@ function anon_identity_init($reqvars) { dbesc($photos[2]), dbesc($photos[3]), dbesc($anon_email), - dbesc($anon_email) + dbesc($hash) ); } -- cgit v1.2.3 From f25e0c3829abd4a89956773b965e45d0e9db18cc Mon Sep 17 00:00:00 2001 From: zotlabs Date: Fri, 16 Jun 2017 19:30:02 -0700 Subject: testing mastodon boosts/reshares --- include/feedutils.php | 49 +++++++++++++++++++++++++++++++++++-------------- 1 file changed, 35 insertions(+), 14 deletions(-) (limited to 'include') diff --git a/include/feedutils.php b/include/feedutils.php index 0d7e1d6c2..158ecb7a3 100644 --- a/include/feedutils.php +++ b/include/feedutils.php @@ -354,6 +354,7 @@ function get_atom_elements($feed, $item, &$author) { // No photo/profile-link on the item - look at the feed level + if((! (x($author,'author_link'))) || (! (x($author,'author_photo')))) { $rawauthor = $feed->get_feed_tags(SIMPLEPIE_NAMESPACE_ATOM_10,'author'); if($rawauthor && $rawauthor[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['link']) { @@ -602,6 +603,10 @@ function get_atom_elements($feed, $item, &$author) { if(! $type) $type = 'application/octet-stream'; + if(($ostatus_protocol) && (strpos($type,'image') === 0) && (strpos($res['body'],$link) === false) && (strpos($link,'http') === 0)) { + $res['body'] .= "\n\n" . '[img]' . $link . '[/img]'; + } + $res['attach'][] = array('href' => $link, 'length' => $len, 'type' => $type, 'title' => $title ); } } @@ -683,7 +688,10 @@ function get_atom_elements($feed, $item, &$author) { $res['target'] = $obj; } - if(array_key_exists('verb',$res) && $res['verb'] === ACTIVITY_SHARE) { + + + if(array_key_exists('verb',$res) && $res['verb'] === ACTIVITY_SHARE + && array_key_exists('obj_type',$res) && $res['obj_type'] === ACTIVITY_OBJ_NOTE) { feed_get_reshare($res,$item); } @@ -713,14 +721,14 @@ function feed_get_reshare(&$res,$item) { if($rawobj) { - $rawauthor = $rawobj->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'author'); + $rawauthor = $rawobj[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['author']; if($rawauthor && $rawauthor[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name']) { - $share['author'] = unxmlify($rawauthor[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name']); + $share['author'] = unxmlify($rawauthor[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name'][0]['data']); } if($rawauthor && $rawauthor[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['uri']) { - $share['profile'] = unxmlify($rawauthor[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['uri']); + $share['profile'] = unxmlify($rawauthor[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['uri'][0]['data']); } if($rawauthor && $rawauthor[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['link']) { @@ -744,9 +752,10 @@ function feed_get_reshare(&$res,$item) { if(x($child[SIMPLEPIE_NAMESPACE_ATOM_10], 'link') && $child[SIMPLEPIE_NAMESPACE_ATOM_10]['link']) - $share['link'] = encode_rel_links($child[SIMPLEPIE_NAMESPACE_ATOM_10]['link']); + $share['links'] = encode_rel_links($child[SIMPLEPIE_NAMESPACE_ATOM_10]['link']); + + $rawcreated = $rawobj[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['published']; - $rawcreated = $rawobj->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'published'); if($rawcreated) $share['created'] = unxmlify($rawcreated[0]['data']); else @@ -766,13 +775,19 @@ function feed_get_reshare(&$res,$item) { } } - $attach = $rawobj->get_enclosures(); + $attach = $share['links']; if($attach) { foreach($attach as $att) { - $len = intval($att->get_length()); - $link = str_replace(array(',','"'),array('%2D','%22'),notags(trim(unxmlify($att->get_link())))); - $title = str_replace(array(',','"'),array('%2D','%22'),notags(trim(unxmlify($att->get_title())))); - $type = str_replace(array(',','"'),array('%2D','%22'),notags(trim(unxmlify($att->get_type())))); + if($att['rel'] === 'alternate') { + $share['alternate'] = str_replace(array(',','"'),array('%2D','%22'),notags(trim(unxmlify($att['href'])))); + continue; + } + if($att['rel'] !== 'enclosure') + continue; + $len = intval($att['length']); + $link = str_replace(array(',','"'),array('%2D','%22'),notags(trim(unxmlify($att['href'])))); + $title = str_replace(array(',','"'),array('%2D','%22'),notags(trim(unxmlify($att['title'])))); + $type = str_replace(array(',','"'),array('%2D','%22'),notags(trim(unxmlify($att['type'])))); if(strpos($type,';')) $type = substr($type,0,strpos($type,';')); if((! $link) || (strpos($link,'http') !== 0)) @@ -792,11 +807,12 @@ function feed_get_reshare(&$res,$item) { $res['body'] = "[share author='" . urlencode($share['author']) . "' profile='" . $share['profile'] . "' avatar='" . $share['avatar'] . - "' link='" . $share['link'] . + "' link='" . $share['alternate'] . "' posted='" . $share['created'] . "' message_id='" . $share['message_id'] . "']"; - $o .= $body; - $o .= "[/share]"; + + $res['body'] .= $body; + $res['body'] .= "[/share]"; } } @@ -818,6 +834,10 @@ function encode_rel_links($links) { $l = array(); if($link['attribs']['']['rel']) $l['rel'] = $link['attribs']['']['rel']; + if($link['attribs']['']['length']) + $l['length'] = $link['attribs']['']['length']; + if($link['attribs']['']['title']) + $l['title'] = $link['attribs']['']['title']; if($link['attribs']['']['type']) $l['type'] = $link['attribs']['']['type']; if($link['attribs']['']['href']) @@ -1724,3 +1744,4 @@ function asencode_person($p) { return $ret; } + -- cgit v1.2.3 From 1472f85b162ea6f1ab9e19e94b86fc4a8ef074be Mon Sep 17 00:00:00 2001 From: zotlabs Date: Sun, 18 Jun 2017 22:25:41 -0700 Subject: allow moderated comments like wordpress if permissions are compatible --- include/channel.php | 67 ++++++++++++++++++++++++++++++++++++++++++++++++ include/conversation.php | 22 ++++++++++------ include/items.php | 2 +- 3 files changed, 82 insertions(+), 9 deletions(-) (limited to 'include') diff --git a/include/channel.php b/include/channel.php index 2284b3004..50cc90178 100644 --- a/include/channel.php +++ b/include/channel.php @@ -2323,3 +2323,70 @@ function channel_codeallowed($channel_id) { return false; } + +function anon_identity_init($reqvars) { + + $x = [ 'request_vars' => $reqvars, 'xchan' => null, 'success' => 'unset' ]; + call_hooks('anon_identity_init',$x); + if($x['success'] !== 'unset' && intval($x['success']) && $x['xchan']) + return $x['xchan']; + + // allow a captcha handler to over-ride + if($x['success'] !== 'unset' && (intval($x['success']) === 0)) + return false; + + + $anon_name = strip_tags(trim($reqvars['anonname'])); + $anon_email = strip_tags(trim($reqvars['anonmail'])); + $anon_url = strip_tags(trim($reqvars['anonurl'])); + + if(! ($anon_name && $anon_email)) { + logger('anonymous commenter did not complete form'); + return false; + } + + if(! validate_email($anon_email)) { + logger('enonymous email not valid'); + return false; + } + + if(! $anon_url) + $anon_url = z_root(); + + $x = q("select * from xchan where xchan_guid = '%s' and xchan_hash = '%s' and xchan_network = 'unknown' limit 1", + dbesc($anon_email), + dbesc($anon_email) + ); + + if(! $x) { + xchan_store_lowlevel([ + 'xchan_guid' => $anon_email, + 'xchan_hash' => $anon_email, + 'xchan_name' => $anon_name, + 'xchan_url' => $anon_url, + 'xchan_network' => 'unknown', + 'xchan_name_date' => datetime_convert() + ]); + + $x = q("select * from xchan where xchan_guid = '%s' and xchan_hash = '%s' and xchan_network = 'unknown' limit 1", + dbesc($anon_email), + dbesc($anon_email) + ); + + $photo = z_root() . '/' . get_default_profile_photo(300); + $photos = import_xchan_photo($photo,$anon_email); + $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_guid = '%s' and xchan_hash = '%s' and xchan_network = 'unknown' ", + dbesc(datetime_convert()), + dbesc($photos[0]), + dbesc($photos[1]), + dbesc($photos[2]), + dbesc($photos[3]), + dbesc($anon_email), + dbesc($anon_email) + ); + + } + + return $x[0]; + +} diff --git a/include/conversation.php b/include/conversation.php index 3f9ee5cfa..2eac2adde 100644 --- a/include/conversation.php +++ b/include/conversation.php @@ -533,6 +533,10 @@ function conversation(&$a, $items, $mode, $update, $page_mode = 'traditional', $ $live_update_div = '' . "\r\n"; } + elseif ($mode === 'moderate') { + $profile_owner = local_channel(); + } + elseif ($mode === 'photos') { $profile_onwer = App::$profile['profile_uid']; $page_writeable = ($profile_owner == local_channel()); @@ -577,7 +581,7 @@ function conversation(&$a, $items, $mode, $update, $page_mode = 'traditional', $ if($items) { - if($mode === 'network-new' || $mode === 'search' || $mode === 'community') { + if(in_array($mode, [ 'network-new', 'search', 'community', 'moderate' ])) { // "New Item View" on network page or search page results // - just loop through the items and format them minimally for display @@ -609,14 +613,14 @@ function conversation(&$a, $items, $mode, $update, $page_mode = 'traditional', $ if(((activity_match($item['verb'],ACTIVITY_LIKE)) || (activity_match($item['verb'],ACTIVITY_DISLIKE))) && ($item['id'] != $item['parent'])) continue; - $nickname = $item['nickname']; +// $nickname = $item['nickname']; } - else - $nickname = App::$user['nickname']; +// else +// $nickname = App::$user['nickname']; - $profile_name = ((strlen($item['author-name'])) ? $item['author-name'] : $item['name']); - if($item['author-link'] && (! $item['author-name'])) - $profile_name = $item['author-link']; +// $profile_name = ((strlen($item['author-name'])) ? $item['author-name'] : $item['name']); +// if($item['author-link'] && (! $item['author-name'])) +// $profile_name = $item['author-link']; $sp = false; $profile_link = best_link_url($item,$sp); @@ -625,7 +629,7 @@ function conversation(&$a, $items, $mode, $update, $page_mode = 'traditional', $ else $profile_link = zid($profile_link); - $normalised = normalise_link((strlen($item['author-link'])) ? $item['author-link'] : $item['url']); +// $normalised = normalise_link((strlen($item['author-link'])) ? $item['author-link'] : $item['url']); $profile_name = $item['author']['xchan_name']; $profile_link = $item['author']['xchan_url']; @@ -679,6 +683,8 @@ function conversation(&$a, $items, $mode, $update, $page_mode = 'traditional', $ 'template' => $tpl, 'toplevel' => 'toplevel_item', 'mode' => $mode, + 'approve' => t('Approve'), + 'delete' => t('Delete'), 'id' => (($preview) ? 'P0' : $item['item_id']), 'linktitle' => sprintf( t('View %s\'s profile @ %s'), $profile_name, $profile_url), 'profile_url' => $profile_link, diff --git a/include/items.php b/include/items.php index fa61d71de..4a028be6e 100755 --- a/include/items.php +++ b/include/items.php @@ -938,7 +938,7 @@ function import_author_unknown($x) { $photos = import_xchan_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 = 'unknown'", + $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_hash = '%s' and xchan_network = 'unknown'", dbesc(datetime_convert()), dbesc($photos[0]), dbesc($photos[1]), -- cgit v1.2.3 From 3b5e1c05b78f72a31eda76b0ff90d08b58ee452d Mon Sep 17 00:00:00 2001 From: zotlabs Date: Sun, 18 Jun 2017 22:51:52 -0700 Subject: minor cleanup of moderated comment feature --- include/channel.php | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'include') diff --git a/include/channel.php b/include/channel.php index 50cc90178..e283ed940 100644 --- a/include/channel.php +++ b/include/channel.php @@ -2353,28 +2353,31 @@ function anon_identity_init($reqvars) { if(! $anon_url) $anon_url = z_root(); + $hash = hash('md5',$anon_email); + $x = q("select * from xchan where xchan_guid = '%s' and xchan_hash = '%s' and xchan_network = 'unknown' limit 1", dbesc($anon_email), - dbesc($anon_email) + dbesc($hash) ); if(! $x) { xchan_store_lowlevel([ 'xchan_guid' => $anon_email, - 'xchan_hash' => $anon_email, + 'xchan_hash' => $hash, 'xchan_name' => $anon_name, 'xchan_url' => $anon_url, 'xchan_network' => 'unknown', 'xchan_name_date' => datetime_convert() ]); + $x = q("select * from xchan where xchan_guid = '%s' and xchan_hash = '%s' and xchan_network = 'unknown' limit 1", dbesc($anon_email), - dbesc($anon_email) + dbesc($hash) ); $photo = z_root() . '/' . get_default_profile_photo(300); - $photos = import_xchan_photo($photo,$anon_email); + $photos = import_xchan_photo($photo,$hash); $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_guid = '%s' and xchan_hash = '%s' and xchan_network = 'unknown' ", dbesc(datetime_convert()), dbesc($photos[0]), @@ -2382,7 +2385,7 @@ function anon_identity_init($reqvars) { dbesc($photos[2]), dbesc($photos[3]), dbesc($anon_email), - dbesc($anon_email) + dbesc($hash) ); } -- cgit v1.2.3 From 31e08127118b81ef223c13966e80f6d448d385d3 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Tue, 20 Jun 2017 15:53:01 -0700 Subject: remove deprecated app parameter from conversation() --- include/conversation.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'include') diff --git a/include/conversation.php b/include/conversation.php index 2eac2adde..1c1a4479d 100644 --- a/include/conversation.php +++ b/include/conversation.php @@ -442,7 +442,6 @@ function is_edit_activity($item) { * figures out how to determine page owner and other contextual items * that are based on unique features of the calling module. * - * @param App &$a * @param array $items * @param string $mode * @param boolean $update @@ -450,7 +449,7 @@ function is_edit_activity($item) { * @param string $prepared_item * @return string */ -function conversation(&$a, $items, $mode, $update, $page_mode = 'traditional', $prepared_item = '') { +function conversation($items, $mode, $update, $page_mode = 'traditional', $prepared_item = '') { $content_html = ''; $o = ''; -- cgit v1.2.3 From 0233e9ad2a8c210f29c553a791b85d52cd6d5d85 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Tue, 20 Jun 2017 16:33:53 -0700 Subject: still an issue with caching import_author_zot --- include/items.php | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'include') diff --git a/include/items.php b/include/items.php index 9e1d5c1ba..126f0a174 100755 --- a/include/items.php +++ b/include/items.php @@ -803,6 +803,10 @@ function import_author_xchan($x) { $y = import_author_zot($x); } + // if we were told that it's a zot connection, don't probe/import anything else + if(array_key_exists('network',$x) && $x['network'] === 'zot') + return $y; + if($x['network'] === 'rss') { $y = import_author_rss($x); } -- cgit v1.2.3 From 08d9316d763defc0fc2f408de6baff9e79853863 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Tue, 20 Jun 2017 17:03:11 -0700 Subject: more import_author_zot fixes --- include/zot.php | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'include') diff --git a/include/zot.php b/include/zot.php index 9458b1f1e..9261b0ebb 100644 --- a/include/zot.php +++ b/include/zot.php @@ -3584,6 +3584,11 @@ function import_author_zot($x) { $hash = make_xchan_hash($x['guid'],$x['guid_sig']); + if(array_key_exists('url',$x)) { + $m = parse_url($x['url']); + $desturl = $m['scheme'] . '://' . $m['host']; + } + $r1 = q("select hubloc_url, hubloc_updated, site_dead from hubloc left join site on hubloc_url = site_url where hubloc_guid = '%s' and hubloc_guid_sig = '%s' and hubloc_primary = 1 limit 1", dbesc($x['guid']), @@ -3625,14 +3630,16 @@ function import_author_zot($x) { ); if($r) { logger('found another site that is not dead: ' . $r[0]['hubloc_url'], LOGGER_DEBUG,LOG_INFO); - $x['url'] = $r[0]['hubloc_url']; + $desturl = $r[0]['hubloc_url']; } else { return $hash; } } - $them = array('hubloc_url' => $x['url'], 'xchan_guid' => $x['guid'], 'xchan_guid_sig' => $x['guid_sig']); + + + $them = array('hubloc_url' => $desturl, 'xchan_guid' => $x['guid'], 'xchan_guid_sig' => $x['guid_sig']); if(zot_refresh($them)) return $hash; -- cgit v1.2.3 From 7e4e2f28dbc52316f4cef7c17a7c9e6ec7f607dc Mon Sep 17 00:00:00 2001 From: zotlabs Date: Tue, 20 Jun 2017 17:13:04 -0700 Subject: explain what is happening here --- include/zot.php | 3 +++ 1 file changed, 3 insertions(+) (limited to 'include') diff --git a/include/zot.php b/include/zot.php index 9261b0ebb..4c180ee59 100644 --- a/include/zot.php +++ b/include/zot.php @@ -3584,6 +3584,9 @@ function import_author_zot($x) { $hash = make_xchan_hash($x['guid'],$x['guid_sig']); + // also - this function may get passed a profile url as 'url' and zot_refresh wants a hubloc_url (site baseurl), + // so deconstruct the url (if we have one) and rebuild it with just the baseurl components. + if(array_key_exists('url',$x)) { $m = parse_url($x['url']); $desturl = $m['scheme'] . '://' . $m['host']; -- cgit v1.2.3 From 3b4f70ae83e458720f7af2446c66dcf5e0d55ace Mon Sep 17 00:00:00 2001 From: zotlabs Date: Thu, 22 Jun 2017 17:31:08 -0700 Subject: Several things about mail storage weren't quite right. --- include/items.php | 36 ++++++++++++++++++- include/message.php | 99 ++++++++++++++++++++++++++++++++++------------------- 2 files changed, 98 insertions(+), 37 deletions(-) (limited to 'include') diff --git a/include/items.php b/include/items.php index 126f0a174..b313193fb 100755 --- a/include/items.php +++ b/include/items.php @@ -8,6 +8,7 @@ use Zotlabs\Lib as Zlib; require_once('include/bbcode.php'); require_once('include/oembed.php'); require_once('include/crypto.php'); +require_once('include/message.php'); require_once('include/feedutils.php'); require_once('include/photo/photo_driver.php'); require_once('include/permissions.php'); @@ -2932,6 +2933,8 @@ function mail_store($arr) { return 0; } + $channel = channelx_by_n($arr['channel_id']); + if(! $arr['mail_obscured']) { if((strpos($arr['body'],'<') !== false) || (strpos($arr['body'],'>') !== false)) $arr['body'] = escape_tags($arr['body']); @@ -2962,11 +2965,34 @@ function mail_store($arr) { $arr['mail_flags'] = ((x($arr,'mail_flags')) ? intval($arr['mail_flags']) : 0 ); $arr['mail_raw'] = ((x($arr,'mail_raw')) ? intval($arr['mail_raw']) : 0 ); - if(! $arr['parent_mid']) { + + + if($arr['parent_mid']) { + $parent_item = q("select * from mail where mid = '%s' and channel_id = %d limit 1", + dbesc($arr['parent_mid']), + intval($arr['channel_id']) + ); + if(($parent_item) && (! $arr['conv_guid'])) { + $arr['conv_guid'] = $parent_item[0]['conv_guid']; + } + } + else { logger('mail_store: missing parent'); $arr['parent_mid'] = $arr['mid']; } + if($arr['from_xchan'] === $channel['channel_hash']) + $conversant = $arr['to_xchan']; + else + $conversant = $arr['from_xchan']; + + + if(! $arr['conv_guid']) { + $x = create_conversation($channel,$conversant,(($arr['title']) ? base64url_decode(str_rot47($arr['title'])) : '')); + $arr['conv_guid'] = (($x) ? $x['guid'] : ''); + } + + $r = q("SELECT id FROM mail WHERE mid = '%s' AND channel_id = %d LIMIT 1", dbesc($arr['mid']), intval($arr['channel_id']) @@ -3031,6 +3057,14 @@ function mail_store($arr) { Zlib\Enotify::submit($notif_params); } + if($arr['conv_guid']) { + $c = q("update conv set updated = '%s' where guid = '%s' and uid = %d", + dbesc(datetime_convert()), + dbesc($arr['conv_guid']), + intval($arr['channel_id']) + ); + } + call_hooks('post_mail_end',$arr); return $current_post; } diff --git a/include/message.php b/include/message.php index 5458eeb0e..3f003e020 100644 --- a/include/message.php +++ b/include/message.php @@ -104,38 +104,9 @@ function send_message($uid = 0, $recipient = '', $body = '', $subject = '', $rep // create a new conversation - $conv_guid = random_string(); - - $recip = q("select * from xchan where xchan_hash = '%s' limit 1", - dbesc($recipient) - ); - if($recip) - $recip_handle = $recip[0]['xchan_addr']; - - $sender_handle = channel_reddress($channel); - - $handles = $recip_handle . ';' . $sender_handle; - - if($subject) - $nsubject = str_rot47(base64url_encode($subject)); - - $r = q("insert into conv (uid,guid,creator,created,updated,subject,recips) values(%d, '%s', '%s', '%s', '%s', '%s', '%s') ", - intval(local_channel()), - dbesc($conv_guid), - dbesc($sender_handle), - dbesc(datetime_convert()), - dbesc(datetime_convert()), - dbesc($nsubject), - dbesc($handles) - ); - - $r = q("select * from conv where guid = '%s' and uid = %d limit 1", - dbesc($conv_guid), - intval(local_channel()) - ); - if($r) { - $retconv = $r[0]; - $retconv['subject'] = base64url_decode(str_rot47($retconv['subject'])); + $retconv = create_conversation($channel,$recipient,$subject); + if($retconv) { + $conv_guid = $retconv['guid']; } } @@ -146,7 +117,6 @@ function send_message($uid = 0, $recipient = '', $body = '', $subject = '', $rep ); if($r) { $retconv = $r[0]; - $retconv['subject'] = base64url_decode(str_rot47($retconv['subject'])); } } @@ -155,6 +125,12 @@ function send_message($uid = 0, $recipient = '', $body = '', $subject = '', $rep return $ret; } + $c = q("update conv set updated = '%s' where guid = '%s' and uid = %d", + dbesc(datetime_convert()), + dbesc($conv_guid), + intval(local_channel()) + ); + // generate a unique message_id do { @@ -284,6 +260,49 @@ function send_message($uid = 0, $recipient = '', $body = '', $subject = '', $rep } +function create_conversation($channel,$recipient,$subject) { + + // create a new conversation + + $conv_guid = random_string(); + + $recip = q("select * from xchan where xchan_hash = '%s' limit 1", + dbesc($recipient) + ); + if($recip) + $recip_handle = $recip[0]['xchan_addr']; + + $sender_handle = channel_reddress($channel); + + $handles = $recip_handle . ';' . $sender_handle; + + if($subject) + $nsubject = str_rot47(base64url_encode($subject)); + + $r = q("insert into conv (uid,guid,creator,created,updated,subject,recips) values(%d, '%s', '%s', '%s', '%s', '%s', '%s') ", + intval($channel['channel_id']), + dbesc($conv_guid), + dbesc($sender_handle), + dbesc(datetime_convert()), + dbesc(datetime_convert()), + dbesc($nsubject), + dbesc($handles) + ); + + $r = q("select * from conv where guid = '%s' and uid = %d limit 1", + dbesc($conv_guid), + intval($channel['channel_id']) + ); + + return $r[0]; + +} + + + + + + function private_messages_list($uid, $mailbox = '', $start = 0, $numitems = 0) { $where = ''; @@ -315,6 +334,8 @@ function private_messages_list($uid, $mailbox = '', $start = 0, $numitems = 0) { break; case 'combined': + default: + $parents = q("SELECT parent_mid FROM mail WHERE mid = parent_mid AND channel_id = %d ORDER BY created DESC", dbesc($local_channel) ); @@ -326,15 +347,21 @@ function private_messages_list($uid, $mailbox = '', $start = 0, $numitems = 0) { } + $r = null; + if($parents) { foreach($parents as $parent) { - $all[] = q("SELECT * FROM mail WHERE parent_mid = '%s' AND channel_id = %d ORDER BY created DESC", + $all = q("SELECT * FROM mail WHERE parent_mid = '%s' AND channel_id = %d ORDER BY created DESC limit 1", dbesc($parent['parent_mid']), dbesc($local_channel) ); + + if($all) { + foreach($all as $single) { + $r[] = $single; + } + } } - foreach($all as $single) - $r[] = $single[0]; } else { $r = q($sql); -- cgit v1.2.3 From 02b7bc08033b21ea5438aa667e8dbb1fd72022bb Mon Sep 17 00:00:00 2001 From: zotlabs Date: Thu, 22 Jun 2017 20:16:54 -0700 Subject: cdav migration to core --- include/event.php | 68 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) (limited to 'include') diff --git a/include/event.php b/include/event.php index 001bd7dd3..b56a5fb3e 100644 --- a/include/event.php +++ b/include/event.php @@ -1236,3 +1236,71 @@ function tasks_fetch($arr) { return $ret; } + +function cdav_principal($uri) { + $r = q("SELECT uri FROM principals WHERE uri = '%s' LIMIT 1", + dbesc($uri) + ); + + if($r[0]['uri'] === $uri) + return true; + else + return false; +} + +function cdav_perms($needle, $haystack, $check_rw = false) { + foreach ($haystack as $item) { + if($check_rw) { + if(is_array($item['id'])) { + if ($item['id'][0] == $needle && $item['share-access'] != 2) { + return $item['{DAV:}displayname']; + } + } + else { + if ($item['id'] == $needle && $item['share-access'] != 2) { + return $item['{DAV:}displayname']; + } + } + } + else { + if(is_array($item['id'])) { + if ($item['id'][0] == $needle) { + return $item['{DAV:}displayname']; + } + } + else { + if ($item['id'] == $needle) { + return $item['{DAV:}displayname']; + } + } + } + } + return false; +} + + +function translate_type($type) { + + if(!$type) + return; + + $type = strtoupper($type); + + $map = [ + 'CELL' => t('Mobile'), + 'HOME' => t('Home'), + 'HOME,VOICE' => t('Home, Voice'), + 'HOME,FAX' => t('Home, Fax'), + 'WORK' => t('Work'), + 'WORK,VOICE' => t('Work, Voice'), + 'WORK,FAX' => t('Work, Fax'), + 'OTHER' => t('Other') + ]; + + if (array_key_exists($type, $map)) { + return [$type, $map[$type]]; + } + else { + return [$type, t('Other') . ' (' . $type . ')']; + } +} -- cgit v1.2.3 From 6c771f84cedc71e7ffeecebe3e2fd7f912de3e7b Mon Sep 17 00:00:00 2001 From: zotlabs Date: Thu, 22 Jun 2017 22:43:08 -0700 Subject: remove unused page_widgets.php include and provide a general function for loading sql from file to use in the cdav migration --- include/dba/dba_driver.php | 14 +++++++++++++ include/page_widgets.php | 52 ---------------------------------------------- 2 files changed, 14 insertions(+), 52 deletions(-) delete mode 100644 include/page_widgets.php (limited to 'include') diff --git a/include/dba/dba_driver.php b/include/dba/dba_driver.php index b0ad7936c..4079bcaba 100755 --- a/include/dba/dba_driver.php +++ b/include/dba/dba_driver.php @@ -442,6 +442,20 @@ function db_getfunc($f) { return $f; } +function db_load_file($f) { + // db errors should get logged to the logfile + $str = @file_get_contents($f); + $arr = explode(';', $str); + if($arr) { + foreach($arr as $a) { + if(strlen(trim($a))) { + $r = dbq(trim($a)); + } + } + } +} + + // The logger function may make DB calls internally to query the system logging parameters. // This can cause a recursion if database debugging is enabled. // So this function preserves the current database debugging state and then turns it off diff --git a/include/page_widgets.php b/include/page_widgets.php deleted file mode 100644 index 3270de4a3..000000000 --- a/include/page_widgets.php +++ /dev/null @@ -1,52 +0,0 @@ - t('New Page'), - '$newurl' => "webpages/$who", - '$edit' => t('Edit'), - '$editurl' => "editwebpage/$who/$which" - )); -} - - - -// Chan is channel_id, $which is channel_address - we'll need to pass observer later too. - -function pagelist_widget ($owner,$which) { - - $r = q("select * from iconfig left join item on iconfig.iid = item.id where item_id.uid = %d - and iconfig.cat = 'system' and iconfig.k = 'WEBPAGE' order by item.created desc", - intval($owner) - ); - - $pages = null; - - if($r) { - $pages = array(); - foreach($r as $rr) { - $pages[$rr['iid']][] = array('url' => $rr['iid'],'pagetitle' => $rr['v'],'title' => $rr['title'],'created' => datetime_convert('UTC',date_default_timezone_get(),$rr['created']),'edited' => datetime_convert('UTC',date_default_timezone_get(),$rr['edited'])); - } - } - - //Build the base URL for edit links - $url = z_root() . "/editwebpage/" . $which; - // This isn't pretty, but it works. Until I figure out what to do with the UI, it's Good Enough(TM). - return $o . replace_macros(get_markup_template("webpagelist.tpl"), array( - '$baseurl' => $url, - '$edit' => t('Edit'), - '$pages' => $pages, - '$channel' => $which, - '$view' => t('View'), - '$preview' => t('Preview'), - '$actions_txt' => t('Actions'), - '$pagelink_txt' => t('Page Link'), - '$title_txt' => t('Title'), - '$created_txt' => t('Created'), - '$edited_txt' => t('Edited') - - )); - -} -- cgit v1.2.3 From 07d6472eea377a9be7e35cca823307382a43df46 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Sun, 25 Jun 2017 18:07:07 -0700 Subject: mastodon reshares can be either posts or comments; silence warning from guess_image_type when handed a URL to a non-existent resource. --- include/feedutils.php | 2 +- include/photo/photo_driver.php | 12 +++++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) (limited to 'include') diff --git a/include/feedutils.php b/include/feedutils.php index 158ecb7a3..cc873876a 100644 --- a/include/feedutils.php +++ b/include/feedutils.php @@ -691,7 +691,7 @@ function get_atom_elements($feed, $item, &$author) { if(array_key_exists('verb',$res) && $res['verb'] === ACTIVITY_SHARE - && array_key_exists('obj_type',$res) && $res['obj_type'] === ACTIVITY_OBJ_NOTE) { + && array_key_exists('obj_type',$res) && in_array($res['obj_type'], [ ACTIVITY_OBJ_NOTE, ACTIVITY_OBJ_COMMENT ] )) { feed_get_reshare($res,$item); } diff --git a/include/photo/photo_driver.php b/include/photo/photo_driver.php index eb61578e1..9d27ef96e 100644 --- a/include/photo/photo_driver.php +++ b/include/photo/photo_driver.php @@ -495,12 +495,22 @@ function guess_image_type($filename, $headers = '') { } } - if(is_null($type)) { + if(is_null($type) && (strpos($filename,'http:') === false)) { $size = getimagesize($filename); $ph = photo_factory(''); $types = $ph->supportedTypes(); $type = ((array_key_exists($size['mime'], $types)) ? $size['mime'] : 'image/jpeg'); } + if(is_null($type)) { + if(strpos(strtolower($filename),'jpg') !== false) + $type = 'image/jpeg'; + elseif(strpos(strtolower($filename),'jpeg') !== false) + $type = 'image/jpeg'; + elseif(strpos(strtolower($filename),'gif') !== false) + $type = 'image/gif'; + elseif(strpos(strtolower($filename),'png') !== false) + $type = 'image/png'; + } } logger('Photo: guess_image_type: type = ' . $type, LOGGER_DEBUG); -- cgit v1.2.3 From 21542d1f9e66638ff9b4012a63a0070d1abe652a Mon Sep 17 00:00:00 2001 From: zotlabs Date: Sun, 25 Jun 2017 18:09:34 -0700 Subject: guess_image_type - ignore scheme when checking for urls --- include/photo/photo_driver.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include') diff --git a/include/photo/photo_driver.php b/include/photo/photo_driver.php index 9d27ef96e..f47a9c878 100644 --- a/include/photo/photo_driver.php +++ b/include/photo/photo_driver.php @@ -495,7 +495,7 @@ function guess_image_type($filename, $headers = '') { } } - if(is_null($type) && (strpos($filename,'http:') === false)) { + if(is_null($type) && (strpos($filename,'http') === false)) { $size = getimagesize($filename); $ph = photo_factory(''); $types = $ph->supportedTypes(); -- cgit v1.2.3 From b0dd824dbc25e8ec12011cbc334471fc47a87735 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Mon, 26 Jun 2017 16:54:28 -0700 Subject: add ostatus attached photos (inline to the post body) even if there's a link to the photo in the post but it isn't wrapped in an img tag. --- include/feedutils.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include') diff --git a/include/feedutils.php b/include/feedutils.php index cc873876a..b785bd64a 100644 --- a/include/feedutils.php +++ b/include/feedutils.php @@ -603,7 +603,7 @@ function get_atom_elements($feed, $item, &$author) { if(! $type) $type = 'application/octet-stream'; - if(($ostatus_protocol) && (strpos($type,'image') === 0) && (strpos($res['body'],$link) === false) && (strpos($link,'http') === 0)) { + if(($ostatus_protocol) && (strpos($type,'image') === 0) && (strpos($res['body'], ']' . $link . '[/img]') === false) && (strpos($link,'http') === 0)) { $res['body'] .= "\n\n" . '[img]' . $link . '[/img]'; } -- cgit v1.2.3 From 4d81c498e2f9a65eac7f71b077aa3e787d53325d Mon Sep 17 00:00:00 2001 From: zotlabs Date: Mon, 26 Jun 2017 17:07:59 -0700 Subject: in gnu-social reshare objects are activities, not posts or comments --- include/feedutils.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include') diff --git a/include/feedutils.php b/include/feedutils.php index b785bd64a..7314f69a6 100644 --- a/include/feedutils.php +++ b/include/feedutils.php @@ -691,7 +691,7 @@ function get_atom_elements($feed, $item, &$author) { if(array_key_exists('verb',$res) && $res['verb'] === ACTIVITY_SHARE - && array_key_exists('obj_type',$res) && in_array($res['obj_type'], [ ACTIVITY_OBJ_NOTE, ACTIVITY_OBJ_COMMENT ] )) { + && array_key_exists('obj_type',$res) && in_array($res['obj_type'], [ ACTIVITY_OBJ_NOTE, ACTIVITY_OBJ_COMMENT, ACTIVITY_OBJ_ACTIVITY ] )) { feed_get_reshare($res,$item); } -- cgit v1.2.3 From 676481de58d078c93789f696ac003936461575d7 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Mon, 26 Jun 2017 23:06:15 -0700 Subject: support linked media (audio/video) elements in feeds as well as images --- include/feedutils.php | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) (limited to 'include') diff --git a/include/feedutils.php b/include/feedutils.php index 7314f69a6..2a0dba982 100644 --- a/include/feedutils.php +++ b/include/feedutils.php @@ -603,10 +603,17 @@ function get_atom_elements($feed, $item, &$author) { if(! $type) $type = 'application/octet-stream'; - if(($ostatus_protocol) && (strpos($type,'image') === 0) && (strpos($res['body'], ']' . $link . '[/img]') === false) && (strpos($link,'http') === 0)) { - $res['body'] .= "\n\n" . '[img]' . $link . '[/img]'; + if($ostatus_protocol) { + if((strpos($type,'image') === 0) && (strpos($res['body'], ']' . $link . '[/img]') === false) && (strpos($link,'http') === 0)) { + $res['body'] .= "\n\n" . '[img]' . $link . '[/img]'; + } + if((strpos($type,'video') === 0) && (strpos($res['body'], ']' . $link . '[/video]') === false) && (strpos($link,'http') === 0)) { + $res['body'] .= "\n\n" . '[video]' . $link . '[/video]'; + } + if((strpos($type,'audio') === 0) && (strpos($res['body'], ']' . $link . '[/audio]') === false) && (strpos($link,'http') === 0)) { + $res['body'] .= "\n\n" . '[audio]' . $link . '[/audio]'; + } } - $res['attach'][] = array('href' => $link, 'length' => $len, 'type' => $type, 'title' => $title ); } } @@ -798,9 +805,15 @@ function feed_get_reshare(&$res,$item) { if(! $type) $type = 'application/octet-stream'; - if((strpos($type,'image') === 0) && (strpos($body,$link) === false) && (strpos($link,'http') === 0)) { + if((strpos($type,'image') === 0) && (strpos($body, ']' . $link . '[/img]') === false) && (strpos($link,'http') === 0)) { $body .= "\n\n" . '[img]' . $link . '[/img]'; } + if((strpos($type,'video') === 0) && (strpos($body, ']' . $link . '[/video]') === false) && (strpos($link,'http') === 0)) { + $body .= "\n\n" . '[video]' . $link . '[/video]'; + } + if((strpos($type,'audio') === 0) && (strpos($body, ']' . $link . '[/audio]') === false) && (strpos($link,'http') === 0)) { + $body .= "\n\n" . '[audio]' . $link . '[/audio]'; + } } } -- cgit v1.2.3 From 1273ac67f40c4c45807b178a9f679efc18bcc9c2 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Tue, 27 Jun 2017 19:20:13 -0700 Subject: (untested currently) fetch conversation for GNU-Social and Mastodon when provided a comment with no local copy of the parent. --- include/feedutils.php | 48 +++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 47 insertions(+), 1 deletion(-) (limited to 'include') diff --git a/include/feedutils.php b/include/feedutils.php index 2a0dba982..8bd4673f5 100644 --- a/include/feedutils.php +++ b/include/feedutils.php @@ -971,6 +971,7 @@ function consume_feed($xml, $importer, &$contact, $pass = 0) { foreach($items as $item) { $is_reply = false; + $parent_link = ''; logger('processing ' . $item->get_id(), LOGGER_DEBUG); @@ -979,6 +980,9 @@ function consume_feed($xml, $importer, &$contact, $pass = 0) { $is_reply = true; $parent_mid = normalise_id($rawthread[0]['attribs']['']['ref']); } + if(isset($rawthread[0]['attribs']['']['href'])) { + $parent_link = $rawthread[0]['attribs']['']['href']; + } if($is_reply) { @@ -1050,7 +1054,7 @@ function consume_feed($xml, $importer, &$contact, $pass = 0) { intval($importer['channel_id']) ); if($c) { - $pmid = $x[0]['parent_mid']; + $pmid = $c[0]['parent_mid']; $datarray['parent_mid'] = $pmid; } } @@ -1065,6 +1069,20 @@ function consume_feed($xml, $importer, &$contact, $pass = 0) { $datarray['parent_mid'] = $pmid; } } + if((! $pmid) && $parent_link !== '') { + $f = feed_conversation_fetch($importer,$contact,$parent_link); + if($f) { + $x = q("select parent_mid from item where mid = '%s' and uid = %d limit 1", + dbesc($parent_mid), + intval($importer['channel_id']) + ); + + if($x) { + $pmid = $x[0]['parent_mid']; + $datarray['parent_mid'] = $pmid; + } + } + } if(! $pmid) { @@ -1195,6 +1213,34 @@ function consume_feed($xml, $importer, &$contact, $pass = 0) { } } + +function feed_conversation_fetch($importer,$contact,$parent_link) { + + $link = ''; + + // GNU-Social flavoured feeds + if(strpos($parent_link,'/notice/')) { + $link = str_replace('/notice/','/api/statuses/show',$link) . '.atom'; + } + + // Mastodon flavoured feeds + if(strpos($parent_link,'/users/') && strpos($parent_link,'/updates/')) { + $link = $parent_link . '.xml'; + } + + if(! $link) + return false; + + $fetch = z_fetch_url($link); + + if(! $fetch['success']) + return false; + + consume_feed($fetch['body'],$importer,$contact,1); + consume_feed($fetch['body'],$importer,$contact,2); + +} + /** * @brief Normalise an id. * -- cgit v1.2.3 From 2b2ea40bce41ad8d5688f42e71837a2caca8e9a8 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Tue, 27 Jun 2017 19:57:03 -0700 Subject: log conversation fetches (also a missed / char in the string replace) --- include/feedutils.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'include') diff --git a/include/feedutils.php b/include/feedutils.php index 8bd4673f5..19b4e27ae 100644 --- a/include/feedutils.php +++ b/include/feedutils.php @@ -1216,11 +1216,13 @@ function consume_feed($xml, $importer, &$contact, $pass = 0) { function feed_conversation_fetch($importer,$contact,$parent_link) { + logger('parent_link: ' . $parent_link, LOGGER_DEBUG, LOG_INFO); + $link = ''; // GNU-Social flavoured feeds if(strpos($parent_link,'/notice/')) { - $link = str_replace('/notice/','/api/statuses/show',$link) . '.atom'; + $link = str_replace('/notice/','/api/statuses/show/',$link) . '.atom'; } // Mastodon flavoured feeds -- cgit v1.2.3 From dab00a98e0b450183ef5f6ad9d6f4708e2246695 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Tue, 27 Jun 2017 20:07:48 -0700 Subject: translate 'favorite' verb to 'like' if it's an ostatus feed --- include/feedutils.php | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) (limited to 'include') diff --git a/include/feedutils.php b/include/feedutils.php index 19b4e27ae..de0cedcc0 100644 --- a/include/feedutils.php +++ b/include/feedutils.php @@ -305,12 +305,6 @@ function get_atom_elements($feed, $item, &$author) { $res['verb'] = unxmlify($rawverb[0]['data']); } - // translate OStatus unfollow to activity streams if it happened to get selected - - if((x($res,'verb')) && ($res['verb'] === 'http://ostatus.org/schema/1.0/unfollow')) { - $res['verb'] = ACTIVITY_UNFOLLOW; - } - // look for a photo. We should check media size and find the best one, // but for now let's just find any author photo @@ -406,6 +400,21 @@ function get_atom_elements($feed, $item, &$author) { $res['app'] = strip_tags(unxmlify($apps[0]['attribs']['']['source'])); } + if($ostatus_protocol) { + + // translate OStatus unfollow to activity streams if it happened to get selected + + if((x($res,'verb')) && ($res['verb'] === 'http://ostatus.org/schema/1.0/unfollow')) { + $res['verb'] = ACTIVITY_UNFOLLOW; + } + + // And OStatus 'favorite' is pretty much what we call 'like' on other networks + + if((x($res,'verb')) && ($res['verb'] === ACTIVITY_FAVORITE)) { + $res['verb'] = ACTIVITY_LIKE; + } + } + /* * If there's a copy of the body content which is guaranteed to have survived mangling in transit, use it. */ -- cgit v1.2.3 From 4c50bfebc293554d9c9a4a8c34b929b03c132d68 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Tue, 27 Jun 2017 21:55:34 -0700 Subject: provide a gender icon on the profile sidebar within reason --- include/channel.php | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'include') diff --git a/include/channel.php b/include/channel.php index 25e54003a..a6b510600 100644 --- a/include/channel.php +++ b/include/channel.php @@ -1162,6 +1162,10 @@ function profile_sidebar($profile, $block = 0, $show_connect = true, $zcard = fa $location = $reddress = $pdesc = $gender = $marital = $homepage = False; } + if($profile['gender']) { + $profile['gender_icon'] = gender_icon($profile['gender']); + } + $firstname = ((strpos($profile['channel_name'],' ')) ? 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)))); @@ -1214,6 +1218,27 @@ function profile_sidebar($profile, $block = 0, $show_connect = true, $zcard = fa } +function gender_icon($gender) { + + logger('gender: ' . $gender); + + // This can easily get throw off if the observer language is different + // than the channel owner language. + + if(strpos(strtolower($gender),strtolower(t('Female'))) !== false) + return 'venus'; + if(strpos(strtolower($gender),strtolower(t('Male'))) !== false) + return 'mars'; + if(strpos(strtolower($gender),strtolower(t('Trans'))) !== false) + return 'transgender'; + if(strpos(strtolower($gender),strtolower(t('Neuter'))) !== false) + return 'neuter'; + if(strpos(strtolower($gender),strtolower(t('Non-specific'))) !== false) + return 'genderless'; + + return ''; +} + function advanced_profile(&$a) { require_once('include/text.php'); -- cgit v1.2.3 From 118fed29b5671035d347d8f3aac50d4af39fc5f3 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Tue, 27 Jun 2017 22:05:06 -0700 Subject: remove logging statement --- include/channel.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include') diff --git a/include/channel.php b/include/channel.php index a6b510600..49da57fd6 100644 --- a/include/channel.php +++ b/include/channel.php @@ -1220,7 +1220,7 @@ function profile_sidebar($profile, $block = 0, $show_connect = true, $zcard = fa function gender_icon($gender) { - logger('gender: ' . $gender); +// logger('gender: ' . $gender); // This can easily get throw off if the observer language is different // than the channel owner language. -- cgit v1.2.3 From c2af3702828fcfa3817f84d5ff8424740b516b35 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Wed, 28 Jun 2017 15:58:14 -0700 Subject: refetch testing --- include/feedutils.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include') diff --git a/include/feedutils.php b/include/feedutils.php index de0cedcc0..a7c2b7ca8 100644 --- a/include/feedutils.php +++ b/include/feedutils.php @@ -1231,7 +1231,7 @@ function feed_conversation_fetch($importer,$contact,$parent_link) { // GNU-Social flavoured feeds if(strpos($parent_link,'/notice/')) { - $link = str_replace('/notice/','/api/statuses/show/',$link) . '.atom'; + $link = str_replace('/notice/','/api/statuses/show/',$parent_link) . '.atom'; } // Mastodon flavoured feeds -- cgit v1.2.3 From c5cff7d6377bc193a07fb9476490f71f59c7e19a Mon Sep 17 00:00:00 2001 From: zotlabs Date: Wed, 28 Jun 2017 16:02:44 -0700 Subject: more refetch testing --- include/feedutils.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include') diff --git a/include/feedutils.php b/include/feedutils.php index a7c2b7ca8..8c2a7a8d7 100644 --- a/include/feedutils.php +++ b/include/feedutils.php @@ -1236,7 +1236,7 @@ function feed_conversation_fetch($importer,$contact,$parent_link) { // Mastodon flavoured feeds if(strpos($parent_link,'/users/') && strpos($parent_link,'/updates/')) { - $link = $parent_link . '.xml'; + $link = $parent_link . '.atom'; } if(! $link) -- cgit v1.2.3 From 8ca5a65dcfd9dc5875f76cbec7b6a8601abc7128 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Wed, 28 Jun 2017 18:28:02 -0700 Subject: minor weirdness in zot finger results after deleting a clone from a channel that was on a site which was previously migrated from http to https and still had the old hubloc --- include/zot.php | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'include') diff --git a/include/zot.php b/include/zot.php index 4c180ee59..a8aecc6fa 100644 --- a/include/zot.php +++ b/include/zot.php @@ -3929,6 +3929,7 @@ function zotinfo($arr) { $ret['photo_updated'] = $e['xchan_photo_date']; $ret['url'] = $e['xchan_url']; $ret['connections_url']= (($e['xchan_connurl']) ? $e['xchan_connurl'] : z_root() . '/poco/' . $e['channel_address']); + $ret['follow_url'] = $e['xchan_follow']; $ret['target'] = $ztarget; $ret['target_sig'] = $zsig; $ret['searchable'] = $searchable; @@ -3936,19 +3937,22 @@ function zotinfo($arr) { $ret['public_forum'] = $public_forum; if($deleted) $ret['deleted'] = $deleted; + if(intval($e['channel_removed'])) $ret['deleted_locally'] = true; + + // premium or other channel desiring some contact with potential followers before connecting. // This is a template - %s will be replaced with the follow_url we discover for the return channel. - if($special_channel) - $ret['connect_url'] = z_root() . '/connect/' . $e['channel_address']; - + if($special_channel) { + $ret['connect_url'] = (($e['xchan_connpage']) ? $e['xchan_connpage'] : z_root() . '/connect/' . $e['channel_address']); + } // This is a template for our follow url, %s will be replaced with a webbie - $ret['follow_url'] = z_root() . '/follow?f=&url=%s'; - + if(! $ret['follow_url']) + $ret['follow_url'] = z_root() . '/follow?f=&url=%s'; $permissions = get_all_perms($e['channel_id'],$ztarget_hash,false); -- cgit v1.2.3 From b91d95d2418237f4344fa0906dd47815e20de2e9 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Wed, 28 Jun 2017 19:20:11 -0700 Subject: add logging --- include/feedutils.php | 3 +++ 1 file changed, 3 insertions(+) (limited to 'include') diff --git a/include/feedutils.php b/include/feedutils.php index 8c2a7a8d7..937a2d28c 100644 --- a/include/feedutils.php +++ b/include/feedutils.php @@ -1242,11 +1242,14 @@ function feed_conversation_fetch($importer,$contact,$parent_link) { if(! $link) return false; + logger('fetching: ' . $link, LOGGER_DEBUG, LOG_INFO); + $fetch = z_fetch_url($link); if(! $fetch['success']) return false; + consume_feed($fetch['body'],$importer,$contact,1); consume_feed($fetch['body'],$importer,$contact,2); -- cgit v1.2.3 From 126af3a24a0dffc705235ed083a9192f97749829 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Wed, 28 Jun 2017 19:34:49 -0700 Subject: pretend it's a real feed even though it isn't --- include/feedutils.php | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'include') diff --git a/include/feedutils.php b/include/feedutils.php index 937a2d28c..184f8ed09 100644 --- a/include/feedutils.php +++ b/include/feedutils.php @@ -1249,9 +1249,19 @@ function feed_conversation_fetch($importer,$contact,$parent_link) { if(! $fetch['success']) return false; + $data = $fetch['body']; - consume_feed($fetch['body'],$importer,$contact,1); - consume_feed($fetch['body'],$importer,$contact,2); + // We will probably receive an atom 'entry' and not an atom 'feed'. Unfortunately + // our parser is a bit strict about compliance so we'll insert just enough of a feed + // tag to trick it into believing it's a compliant feed. + + if(! strstr($data,' Date: Wed, 28 Jun 2017 20:07:53 -0700 Subject: conversation fetching is partially working - but it isn't always glueing the conversation pieces together. --- include/feedutils.php | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) (limited to 'include') diff --git a/include/feedutils.php b/include/feedutils.php index 184f8ed09..a262b9562 100644 --- a/include/feedutils.php +++ b/include/feedutils.php @@ -1081,14 +1081,27 @@ function consume_feed($xml, $importer, &$contact, $pass = 0) { if((! $pmid) && $parent_link !== '') { $f = feed_conversation_fetch($importer,$contact,$parent_link); if($f) { - $x = q("select parent_mid from item where mid = '%s' and uid = %d limit 1", - dbesc($parent_mid), - intval($importer['channel_id']) - ); + // check both potential conversation parents again + if($conv_id) { + $c = q("select parent_mid from item left join iconfig on item.id = iconfig.iid where iconfig.cat = 'ostatus' and iconfig.k = 'conversation' and iconfig.v = '%s' and item.uid = %d order by item.id limit 1", + dbesc($conv_id), + intval($importer['channel_id']) + ); + if($c) { + $pmid = $c[0]['parent_mid']; + $datarray['parent_mid'] = $pmid; + } + } + if(! $pmid) { + $x = q("select parent_mid from item where mid = '%s' and uid = %d limit 1", + dbesc($parent_mid), + intval($importer['channel_id']) + ); - if($x) { - $pmid = $x[0]['parent_mid']; - $datarray['parent_mid'] = $pmid; + if($x) { + $pmid = $x[0]['parent_mid']; + $datarray['parent_mid'] = $pmid; + } } } } -- cgit v1.2.3 From c7b4a53af2d2d73b8c0bb59cf851813163f65987 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Wed, 28 Jun 2017 20:11:03 -0700 Subject: log the conversation so we can debug this easier --- include/feedutils.php | 1 + 1 file changed, 1 insertion(+) (limited to 'include') diff --git a/include/feedutils.php b/include/feedutils.php index a262b9562..835d739df 100644 --- a/include/feedutils.php +++ b/include/feedutils.php @@ -387,6 +387,7 @@ function get_atom_elements($feed, $item, &$author) { if($rawcnv) { $ostatus_conversation = normalise_id(unxmlify($rawcnv[0]['attribs']['']['ref'])); set_iconfig($res,'ostatus','conversation',$ostatus_conversation,true); + logger('ostatus_conversation: ' . $ostatus_conversation, LOGGER_DATA, LOG_INFO); } $ostatus_protocol = (($ostatus_conversation) ? true : false); -- cgit v1.2.3 From da1b10b741ec7525b9d76b2bdfaa3b794a39dde3 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Thu, 29 Jun 2017 21:09:08 -0700 Subject: forgot to return true from the conversation_fetch routine - which triggers the rescan for potential parent posts --- include/feedutils.php | 2 ++ 1 file changed, 2 insertions(+) (limited to 'include') diff --git a/include/feedutils.php b/include/feedutils.php index 835d739df..2755a7e3f 100644 --- a/include/feedutils.php +++ b/include/feedutils.php @@ -1276,6 +1276,8 @@ function feed_conversation_fetch($importer,$contact,$parent_link) { consume_feed($data,$importer,$contact,1); consume_feed($data,$importer,$contact,2); + + return true; } -- cgit v1.2.3 From b73c844d1aec260c323715b55f2b290ce339615b Mon Sep 17 00:00:00 2001 From: zotlabs Date: Thu, 29 Jun 2017 22:38:43 -0700 Subject: use "Full Name (username)" for ostatus commenter xchans --- include/feedutils.php | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) (limited to 'include') diff --git a/include/feedutils.php b/include/feedutils.php index 2755a7e3f..27f189119 100644 --- a/include/feedutils.php +++ b/include/feedutils.php @@ -246,9 +246,17 @@ function get_atom_elements($feed, $item, &$author) { $found_author = $item->get_author(); if($found_author) { + if($rawauthor) { + if($rawauthor[0]['child'][NAMESPACE_POCO]['displayName'][0]['data']) + $author['full_name'] = unxmlify($rawauthor[0]['child'][NAMESPACE_POCO]['displayName'][0]['data']); + } $author['author_name'] = unxmlify($found_author->get_name()); $author['author_link'] = unxmlify($found_author->get_link()); $author['author_is_feed'] = false; + + $rawauthor = $feed->get_feed_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'author'); + logger('rawauthor: ' . print_r($rawauthor, true)); + } else { $author['author_name'] = unxmlify($feed->get_title()); @@ -1022,7 +1030,16 @@ function consume_feed($xml, $importer, &$contact, $pass = 0) { $datarray['author_xchan'] = ''; if($author['author_link'] != $contact['xchan_url']) { - $x = import_author_unknown(array('name' => $author['author_name'],'url' => $author['author_link'],'photo' => array('src' => $author['author_photo']))); + $name = ''; + if($author['full_name']) { + $name = $author['full_name']; + if($author['author_name']) + $name .= ' (' . $author['author_name'] . ')'; + } + else { + $name = $author['author_name']; + } + $x = import_author_unknown(array('name' => $name,'url' => $author['author_link'],'photo' => array('src' => $author['author_photo']))); if($x) $datarray['author_xchan'] = $x; } @@ -1170,7 +1187,16 @@ function consume_feed($xml, $importer, &$contact, $pass = 0) { } if($author['author_link'] != $contact['xchan_url']) { - $x = import_author_unknown(array('name' => $author['author_name'],'url' => $author['author_link'],'photo' => array('src' => $author['author_photo']))); + $name = ''; + if($author['full_name']) { + $name = $author['full_name']; + if($author['author_name']) + $name .= ' (' . $author['author_name'] . ')'; + } + else { + $name = $author['author_name']; + } + $x = import_author_unknown(array('name' => $name,'url' => $author['author_link'],'photo' => array('src' => $author['author_photo']))); if($x) $datarray['author_xchan'] = $x; } -- cgit v1.2.3 From 64cad0a041e44940f75bf351fc3755b3202f9029 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Fri, 30 Jun 2017 00:50:57 -0700 Subject: duplicated posts after conversation fetch --- include/feedutils.php | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'include') diff --git a/include/feedutils.php b/include/feedutils.php index 27f189119..b64a98a7f 100644 --- a/include/feedutils.php +++ b/include/feedutils.php @@ -1122,6 +1122,17 @@ function consume_feed($xml, $importer, &$contact, $pass = 0) { } } } + + // the conversation parent might just be the post we are trying to import. + // check existence again in case it was just delivered. + + $r = q("SELECT id FROM item WHERE mid = '%s' AND uid = %d LIMIT 1", + dbesc($datarray['mid']), + intval($importer['channel_id']) + ); + if($r) { + continue; + } } if(! $pmid) { -- cgit v1.2.3 From 27c8c74988228ed7a86d09011caed9ed57a7d91a Mon Sep 17 00:00:00 2001 From: zotlabs Date: Tue, 4 Jul 2017 22:05:17 -0700 Subject: some sites use the old style ostatus:conversation xml field, check for it. --- include/feedutils.php | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'include') diff --git a/include/feedutils.php b/include/feedutils.php index b64a98a7f..d96735c3a 100644 --- a/include/feedutils.php +++ b/include/feedutils.php @@ -393,9 +393,16 @@ function get_atom_elements($feed, $item, &$author) { $rawcnv = $item->get_item_tags(NAMESPACE_OSTATUS, 'conversation'); if($rawcnv) { + // new style $ostatus_conversation = normalise_id(unxmlify($rawcnv[0]['attribs']['']['ref'])); - set_iconfig($res,'ostatus','conversation',$ostatus_conversation,true); - logger('ostatus_conversation: ' . $ostatus_conversation, LOGGER_DATA, LOG_INFO); + if(! $ostatus_conversation) { + // old style + $ostatus_conversation = normalise_id(unxmlify($rawcnv[0]['data'])); + } + if($ostatus_conversation) { + set_iconfig($res,'ostatus','conversation',$ostatus_conversation,true); + logger('ostatus_conversation: ' . $ostatus_conversation, LOGGER_DATA, LOG_INFO); + } } $ostatus_protocol = (($ostatus_conversation) ? true : false); -- cgit v1.2.3 From c3b93de09937bbbb3fa6c5a2c620d19cefe38eb0 Mon Sep 17 00:00:00 2001 From: Mario Vavti Date: Wed, 5 Jul 2017 12:32:46 +0200 Subject: typo --- include/network.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include') diff --git a/include/network.php b/include/network.php index d3ccc498d..b85a16d21 100644 --- a/include/network.php +++ b/include/network.php @@ -1890,7 +1890,7 @@ function service_plink($contact, $guid) { $plink = $url . '/channel/' . $handle . '?f=&mid=' . $guid; - $x = [ 'xchan' => $contact, 'guid' => $guid, '$url' => $url, 'plink' => $plink ]; + $x = [ 'xchan' => $contact, 'guid' => $guid, 'url' => $url, 'plink' => $plink ]; call_hooks('service_plink', $x); return $x['plink']; -- cgit v1.2.3 From b2e5b6c977c8f8af9bfd49dac3ce41a2183025da Mon Sep 17 00:00:00 2001 From: zotlabs Date: Wed, 5 Jul 2017 20:16:40 -0700 Subject: affinitiy slider settings were being updated on any submit of of settings/featured, plus minor non-code changes --- include/zid.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include') diff --git a/include/zid.php b/include/zid.php index f5df1c611..ee43fd7c8 100644 --- a/include/zid.php +++ b/include/zid.php @@ -60,7 +60,7 @@ function zid($s,$address = '') { /** * @FIXME checking against our own channel url is no longer reliable. We may have a lot - * of urls attached to out channel. Should probably match against our site, since we + * of urls attached to our channel. Should probably match against our site, since we * will not need to remote authenticate on our own site anyway. */ -- cgit v1.2.3 From ddc454bd8260f39831f0d9cb86f797798ef73322 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Sun, 9 Jul 2017 16:02:45 -0700 Subject: regression: allow position attributes in oembedable zcards by separating allow_position from the decision to allow zrls. Should probably turn the entire zcard into a gd image as other consumers of zcards are also likely to purify the position attributes. --- include/oembed.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'include') diff --git a/include/oembed.php b/include/oembed.php index e35a77fa3..460e0244e 100755 --- a/include/oembed.php +++ b/include/oembed.php @@ -134,7 +134,9 @@ function oembed_fetch_url($embedurl){ $txt = null; // we should try to cache this and avoid a lookup on each render - $zrl = ((get_config('system','oembed_zrl')) ? is_matrix_url($embedurl) : false); + $is_matrix = is_matrix_url($embedurl); + + $zrl = ((get_config('system','oembed_zrl')) ? $is_matrix : false); $furl = ((local_channel() && $zrl) ? zid($embedurl) : $embedurl); @@ -222,7 +224,7 @@ function oembed_fetch_url($embedurl){ if($action === 'filter') { if($j['html']) { $orig = $j['html']; - $allow_position = (($zrl) ? true : false); + $allow_position = (($is_matrix) ? true : false); $j['html'] = purify_html($j['html'],$allow_position); if($j['html'] != $orig) { logger('oembed html was purified. original: ' . $orig . ' purified: ' . $j['html'], LOGGER_DEBUG, LOG_INFO); -- cgit v1.2.3 From e3734328eb7393bbdb76ce195d735ab48aa87324 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Sun, 9 Jul 2017 17:08:25 -0700 Subject: find_parent for feeds needs more debug logging. Something is still falling through the cracks and it isn't obvious why --- include/feedutils.php | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'include') diff --git a/include/feedutils.php b/include/feedutils.php index d96735c3a..8696cc867 100644 --- a/include/feedutils.php +++ b/include/feedutils.php @@ -1009,6 +1009,8 @@ function consume_feed($xml, $importer, &$contact, $pass = 0) { $parent_link = $rawthread[0]['attribs']['']['href']; } + logger('in-reply-to: ' . $parent_mid, LOGGER_DEBUG); + if($is_reply) { if($pass == 1) @@ -1088,6 +1090,7 @@ function consume_feed($xml, $importer, &$contact, $pass = 0) { intval($importer['channel_id']) ); if($c) { + logger('find_parent: matched conversation: ' . $conv_id, LOGGER_DEBUG); $pmid = $c[0]['parent_mid']; $datarray['parent_mid'] = $pmid; } @@ -1099,6 +1102,7 @@ function consume_feed($xml, $importer, &$contact, $pass = 0) { ); if($x) { + logger('find_parent: matched in-reply-to: ' . $parent_mid, LOGGER_DEBUG); $pmid = $x[0]['parent_mid']; $datarray['parent_mid'] = $pmid; } -- cgit v1.2.3 From 2d63bbb91e97d3a54440564620ef3093ecbe71fb Mon Sep 17 00:00:00 2001 From: zotlabs Date: Mon, 10 Jul 2017 20:18:33 -0700 Subject: prevent expiration of conversations you are involved with - allows you to find your own comments months from now --- include/import.php | 8 ++++++++ include/items.php | 2 +- include/zot.php | 12 +++++++++++- 3 files changed, 20 insertions(+), 2 deletions(-) (limited to 'include') diff --git a/include/import.php b/include/import.php index 277d6618c..2199400af 100644 --- a/include/import.php +++ b/include/import.php @@ -627,6 +627,14 @@ function import_items($channel, $items, $sync = false, $relocate = null) { $item_result = item_store($item,$allow_code,$deliver); } + // preserve conversations you've been involved in from being expired + + $stored = $item_result['item']; + if((is_array($stored)) && ($stored['id'] != $stored['parent']) + && ($stored['author_xchan'] === $channel['channel_hash'])) { + retain_item($stored['item']['parent']); + } + fix_attached_photo_permissions($channel['channel_id'],$item['author_xchan'],$item['body'],$item['allow_cid'],$item['allow_gid'],$item['deny_cid'],$item['deny_gid']); fix_attached_file_permissions($channel,$item['author_xchan'],$item['body'],$item['allow_cid'],$item['allow_gid'],$item['deny_cid'],$item['deny_gid']); diff --git a/include/items.php b/include/items.php index b313193fb..386c25922 100755 --- a/include/items.php +++ b/include/items.php @@ -1737,7 +1737,7 @@ logger('revision: ' . $arr['revision']); if($r[0]['owner_xchan'] !== $arr['owner_xchan']) { $arr['owner_xchan'] = $r[0]['owner_xchan']; -// $uplinked_comment = true; + // $uplinked_comment = true; } // if the parent is private, force privacy for the entire conversation diff --git a/include/zot.php b/include/zot.php index a8aecc6fa..05475d051 100644 --- a/include/zot.php +++ b/include/zot.php @@ -1761,7 +1761,7 @@ function process_delivery($sender, $arr, $deliveries, $relay, $public = false, $ $result[] = $DR->get(); } else { - update_imported_item($sender,$arr,$r[0],$channel['channel_id'],$tag_delivery); + $item_result = update_imported_item($sender,$arr,$r[0],$channel['channel_id'],$tag_delivery); $DR->update('updated'); $result[] = $DR->get(); if(! $relay) @@ -1810,6 +1810,14 @@ function process_delivery($sender, $arr, $deliveries, $relay, $public = false, $ } } + // preserve conversations with which you are involved from expiration + + $stored = (($item_result && $item_result['item']) ? $item_result['item'] : false); + if((is_array($stored)) && ($stored['id'] != $stored['parent']) + && ($stored['author_xchan'] === $channel['channel_hash'])) { + retain_item($stored['item']['parent']); + } + if($relay && $item_id) { logger('process_delivery: invoking relay'); Zotlabs\Daemon\Master::Summon(array('Notifier','relay',intval($item_id))); @@ -1946,6 +1954,8 @@ function update_imported_item($sender, $item, $orig, $uid, $tag_delivery) { logger('update_imported_item: failed: ' . $x['message']); else logger('update_imported_item'); + + return $x; } /** -- cgit v1.2.3 From ad9990e1004e58e0049768f5282d86e5e0eb2602 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Tue, 11 Jul 2017 17:31:57 -0700 Subject: even more logging of conversation parent discovery --- include/feedutils.php | 1 + 1 file changed, 1 insertion(+) (limited to 'include') diff --git a/include/feedutils.php b/include/feedutils.php index 8696cc867..a725e66e3 100644 --- a/include/feedutils.php +++ b/include/feedutils.php @@ -1085,6 +1085,7 @@ function consume_feed($xml, $importer, &$contact, $pass = 0) { // next try thr:in_reply_to if($conv_id) { + logger('find_parent: conversation_id: ' . $conv_id, LOGGER_DEBUG); $c = q("select parent_mid from item left join iconfig on item.id = iconfig.iid where iconfig.cat = 'ostatus' and iconfig.k = 'conversation' and iconfig.v = '%s' and item.uid = %d order by item.id limit 1", dbesc($conv_id), intval($importer['channel_id']) -- cgit v1.2.3 From 6db717a1a09f936f72d5c6c7643b0caa81a40667 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Wed, 12 Jul 2017 17:07:31 -0700 Subject: make websub/PuSH and salmon both use consume_feed() for item storage as there is a lot of duplication of effort and patches applied to one that haven't been applied to the other. This will require an update of addons as well or follow activities may be duplicated --- include/feedutils.php | 56 +++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 43 insertions(+), 13 deletions(-) (limited to 'include') diff --git a/include/feedutils.php b/include/feedutils.php index a725e66e3..fac2a272c 100644 --- a/include/feedutils.php +++ b/include/feedutils.php @@ -516,7 +516,7 @@ function get_atom_elements($feed, $item, &$author) { // turn Mastodon content warning into a #nsfw hashtag if($mastodon && $summary) { - $res['body'] .= "\n\n#nsfw\n"; + $res['body'] .= "\n\n#ContentWarning\n"; } @@ -1147,7 +1147,48 @@ function consume_feed($xml, $importer, &$contact, $pass = 0) { } } - if(! $pmid) { + if($pmid) { + + // check comment permissions on the parent + + $r = q("select * from item where parent_mid = '%s' and parent_mid = mid and uid = %d limit 1" + dbesc($pmid), + intval($importer['channel_id']) + ); + if($r) { + $parent_item = $r[0]; + + if(intval($parent_item['item_nocomment']) || $parent_item['comment_policy'] === 'none' + || ($parent_item['comments_closed'] > NULL_DATE && $parent_item['comments_closed'] < datetime_convert())) { + logger('comments disabled for post ' . $parent_item['mid']); + continue; + } + + $allowed = false; + + if($parent_item) { + if($parent_item['owner_xchan'] == $importer['channel_hash']) + $allowed = perm_is_allowed($importer['channel_id'],$contact['xchan_hash'],'post_comments'); + else + $allowed = true; + + if(! $allowed) { + logger('Ignoring this comment author.'); + $status = 202; + continue; + } + } + else { + if((! perm_is_allowed($importer['channel_id'],$contact['xchan_hash'],'send_stream')) && (! $importer['system'])) { + // @fixme check for and process ostatus autofriend + // otherwise + + logger('Ignoring this author.'); + continue; + } + } + } + else { // immediate parent wasn't found. Turn into a top-level post if permissions allow // but save the thread_parent in case we need to refer to it later. @@ -1198,17 +1239,6 @@ function consume_feed($xml, $importer, &$contact, $pass = 0) { $datarray['author_xchan'] = ''; - if(activity_match($datarray['verb'],ACTIVITY_FOLLOW) && $datarray['obj_type'] === ACTIVITY_OBJ_PERSON) { - $cb = array('item' => $datarray,'channel' => $importer, 'xchan' => [ 'placeholder' => '' ], 'author' => $author, 'caught' => false); - call_hooks('follow_from_feed',$cb); - if($cb['caught']) { - if($cb['return_code']) - http_status_exit($cb['return_code']); - - continue; - } - } - if($author['author_link'] != $contact['xchan_url']) { $name = ''; if($author['full_name']) { -- cgit v1.2.3 From aa70cbbf21950e37ab9b5198de76ded0f1c8351d Mon Sep 17 00:00:00 2001 From: zotlabs Date: Wed, 12 Jul 2017 17:16:21 -0700 Subject: fix typos --- include/feedutils.php | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'include') diff --git a/include/feedutils.php b/include/feedutils.php index fac2a272c..b1fcce9d3 100644 --- a/include/feedutils.php +++ b/include/feedutils.php @@ -1151,17 +1151,19 @@ function consume_feed($xml, $importer, &$contact, $pass = 0) { // check comment permissions on the parent - $r = q("select * from item where parent_mid = '%s' and parent_mid = mid and uid = %d limit 1" + $parent_item = 0; + + $r = q("select * from item where parent_mid = '%s' and parent_mid = mid and uid = %d limit 1", dbesc($pmid), intval($importer['channel_id']) ); if($r) { $parent_item = $r[0]; - - if(intval($parent_item['item_nocomment']) || $parent_item['comment_policy'] === 'none' - || ($parent_item['comments_closed'] > NULL_DATE && $parent_item['comments_closed'] < datetime_convert())) { - logger('comments disabled for post ' . $parent_item['mid']); - continue; + if(intval($parent_item['item_nocomment']) || $parent_item['comment_policy'] === 'none' + || ($parent_item['comments_closed'] > NULL_DATE && $parent_item['comments_closed'] < datetime_convert())) { + logger('comments disabled for post ' . $parent_item['mid']); + continue; + } } $allowed = false; -- cgit v1.2.3 From c940d8d7ca25691519d400ad19aa22b5611fc2e7 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Thu, 13 Jul 2017 17:04:58 -0700 Subject: implement chunked uploads on the wall; making it work painlessly on /cloud was attempted but will not be implemented today. That presents some interesting dragons to slay. --- include/attach.php | 101 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 101 insertions(+) (limited to 'include') diff --git a/include/attach.php b/include/attach.php index ac50b05b1..3a0c8b7ba 100644 --- a/include/attach.php +++ b/include/attach.php @@ -2355,3 +2355,104 @@ function attach_upgrade() { } } + +function save_chunk($channel,$start,$end,$len) { + + $result = []; + + $tmp_path = $_FILES['files']['tmp_name']; + $new_base = 'store/[data]/' . $channel['channel_address'] . '/tmp'; + os_mkdir($new_base,STORAGE_DEFAULT_PERMISSIONS,true); + + $new_path = $new_base . '/' . $_FILES['files']['name']; + + if(! file_exists($new_path)) { + rename($tmp_path,$new_path); + } + else { + $istream = fopen($tmp_path,'rb'); + $ostream = fopen($new_path,'ab'); + if($istream && $ostream) { + pipe_streams($istream,$ostream); + fclose($istream); + fclose($ostream); + } + } + if(($len - 1) == $end) { + unlink($tmp_path); + $result['name'] = $_FILES['files']['tmp_name']; + $result['type'] = $_FILES['files']['type']; + $result['tmp_name'] = $new_path; + $result['error'] = 0; + $result['size'] = $len; + $result['complete'] = true; + return $result; + } + $result['partial'] = true; + $result['length'] = intval(filesize($new_path)); + return $result; +} + + +/* + * chunkloader + * Submit handler for chunked uploads + * + */ + +function chunkloader($channel,$arr) { + + logger('request: ' . print_r($arr,true), LOGGER_DEBUG); + logger('files: ' . print_r($_FILES,true), LOGGER_DEBUG); + + + $result = []; + + + $tmp_path = $_FILES['file']['tmp_name']; + $new_base = 'store/[data]/' . $channel['channel_address'] . '/tmp'; + os_mkdir($new_base,STORAGE_DEFAULT_PERMISSIONS,true); + + $new_path = $new_base . '/' . $arr['resumableFilename']; + + rename($tmp_path,$new_path . '.' . intval($arr['resumableChunkNumber'])); + + $missing_parts = false; + for($x = 1; $x <= intval($arr['resumableTotalChunks']); $x ++) { + if(! file_exists($new_path . '.' . $x)) { + $missing_parts = true; + break; + } + } + + if($missing_parts) { + $result['partial'] = true; + return $result; + } + + if(intval($arr['resumableTotalChunks']) === 1) { + rename($new_path . '.' . '1', $new_path); + } + else { + for($x = 1; $x <= intval($arr['resumableTotalChunks']); $x ++) { + $istream = fopen($new_path . '.' . $x,'rb'); + $ostream = fopen($new_path,'ab'); + if($istream && $ostream) { + pipe_streams($istream,$ostream); + fclose($istream); + fclose($ostream); + } + unlink($new_path . '.' . $x); + } + } + + $result['name'] = $arr['resumableFilename']; + $result['type'] = $arr['resumableType']; + $result['tmp_name'] = $new_path; + $result['error'] = 0; + $result['size'] = $arr['resumableTotalSize']; + $result['complete'] = true; + return $result; + +} + -- cgit v1.2.3 From 2d119c81a44691773bacd9e545ce49bebd522098 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Thu, 13 Jul 2017 20:18:19 -0700 Subject: turn platform name and std_version into config variables --- include/dba/dba_driver.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'include') diff --git a/include/dba/dba_driver.php b/include/dba/dba_driver.php index 4079bcaba..7e925a106 100755 --- a/include/dba/dba_driver.php +++ b/include/dba/dba_driver.php @@ -163,8 +163,9 @@ abstract class dba_driver { } function get_install_script() { - if(file_exists('install/' . PLATFORM_NAME . '/' . \DBA::$install_script)) - return 'install/' . PLATFORM_NAME . '/' . \DBA::$install_script; + $platform_name = \Zotlabs\Lib\System::get_platform_name(); + if(file_exists('install/' . $platform_name . '/' . \DBA::$install_script)) + return 'install/' . $platform_name . '/' . \DBA::$install_script; return 'install/' . \DBA::$install_script; } -- cgit v1.2.3 From 77f71303f21e7690f75c33f54dc84033921102aa Mon Sep 17 00:00:00 2001 From: zotlabs Date: Thu, 13 Jul 2017 21:46:21 -0700 Subject: update some addon docs and ensure we only generate statistics once a day --- include/statistics_fns.php | 20 ++++++++++++++------ include/zot.php | 2 +- 2 files changed, 15 insertions(+), 7 deletions(-) (limited to 'include') diff --git a/include/statistics_fns.php b/include/statistics_fns.php index cbff3b0b7..d213485bf 100644 --- a/include/statistics_fns.php +++ b/include/statistics_fns.php @@ -7,7 +7,7 @@ function update_channels_total_stat() { $channels_total_stat = intval($r[0]['channels_total']); set_config('system','channels_total_stat',$channels_total_stat); } else { - set_config('system','channels_total_stat',null); + set_config('system','channels_total_stat',0); } } @@ -30,10 +30,10 @@ function update_channels_active_halfyear_stat() { $channels_active_halfyear_stat = count($x); set_config('system','channels_active_halfyear_stat',$channels_active_halfyear_stat); } else { - set_config('system','channels_active_halfyear_stat',null); + set_config('system','channels_active_halfyear_stat',0); } } else { - set_config('system','channels_active_halfyear_stat',null); + set_config('system','channels_active_halfyear_stat',0); } } @@ -56,10 +56,10 @@ function update_channels_active_monthly_stat() { $channels_active_monthly_stat = count($x); set_config('system','channels_active_monthly_stat',$channels_active_monthly_stat); } else { - set_config('system','channels_active_monthly_stat',null); + set_config('system','channels_active_monthly_stat',0); } } else { - set_config('system','channels_active_monthly_stat',null); + set_config('system','channels_active_monthly_stat',0); } } @@ -69,8 +69,16 @@ function update_local_posts_stat() { $local_posts_stat = intval($posts[0]["local_posts"]); set_config('system','local_posts_stat',$local_posts_stat); } else { - set_config('system','local_posts_stat',null); + set_config('system','local_posts_stat',0); } } +function update_local_comments_stat() { + $posts = q("SELECT COUNT(*) AS local_posts FROM item WHERE item_wall = 1 and id != parent"); + if (!is_array($posts)) + $local_posts = 0; + else + $local_posts = $posts[0]["local_posts"]; + set_config('system','local_comments_stat', $local_posts); +} \ No newline at end of file diff --git a/include/zot.php b/include/zot.php index 05475d051..677fdf6b7 100644 --- a/include/zot.php +++ b/include/zot.php @@ -2831,7 +2831,7 @@ function import_site($arr, $pubkey) { $access_policy = ACCESS_PRIVATE; if($access_policy != ACCESS_PRIVATE) { - $x = z_fetch_url($arr['url'] . '/siteinfo/json'); + $x = z_fetch_url($arr['url'] . '/siteinfo.json'); if(! $x['success']) $access_policy = ACCESS_PRIVATE; } -- cgit v1.2.3 From e891199a23eb8839f0a6baa4b5695b058793917f Mon Sep 17 00:00:00 2001 From: zotlabs Date: Sat, 15 Jul 2017 15:49:10 -0700 Subject: deal with mastodon privacy scopes - mark private and block commenting since we refuse to send private activities through the public OStatus connector. --- include/feedutils.php | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'include') diff --git a/include/feedutils.php b/include/feedutils.php index b1fcce9d3..6ee53e2f6 100644 --- a/include/feedutils.php +++ b/include/feedutils.php @@ -408,8 +408,11 @@ function get_atom_elements($feed, $item, &$author) { $ostatus_protocol = (($ostatus_conversation) ? true : false); $mastodon = (($item->get_item_tags('http://mastodon.social/schema/1.0','scope')) ? true : false); - if($mastodon) + if($mastodon) { $ostatus_protocol = true; + if(($mastodon[0]['data']) && ($mastodon[0]['data'] !== 'public')) + $res['item_private'] = 1; + } $apps = $item->get_item_tags(NAMESPACE_STATUSNET, 'notice_info'); if($apps && $apps[0]['attribs']['']['source']) { @@ -1024,6 +1027,14 @@ function consume_feed($xml, $importer, &$contact, $pass = 0) { if(! $datarray['mid']) continue; + // A Mastodon privacy tag has been found. We cannot send private comments + // through the OStatus protocol, so block commenting. + + if(array_key_exists('item_private',$datarray) && intval($datarray['item_private'])) { + $datarray['public_policy'] = 'specific'; + $datarray['comment_policy'] = 'none'; + } + if($contact['xchan_network'] === 'rss') { $datarray['public_policy'] = 'specific'; $datarray['comment_policy'] = 'none'; @@ -1220,6 +1231,14 @@ function consume_feed($xml, $importer, &$contact, $pass = 0) { if(! $datarray['mid']) continue; + // A Mastodon privacy tag has been found. We cannot send private comments + // through the OStatus protocol, so block commenting. + + if(array_key_exists('item_private',$datarray) && intval($datarray['item_private'])) { + $datarray['public_policy'] = 'specific'; + $datarray['comment_policy'] = 'none'; + } + if($contact['xchan_network'] === 'rss') { $datarray['public_policy'] = 'specific'; $datarray['comment_policy'] = 'none'; -- cgit v1.2.3 From ce3be598bb2076a20ff6d99ac051ec1667230a77 Mon Sep 17 00:00:00 2001 From: git-marijus Date: Sun, 16 Jul 2017 15:59:19 +0200 Subject: fix album link --- include/photos.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include') diff --git a/include/photos.php b/include/photos.php index c3260d18c..6ea444e2e 100644 --- a/include/photos.php +++ b/include/photos.php @@ -296,7 +296,7 @@ function photo_upload($channel, $observer, $args) { $photo_link = '[zrl=' . z_root() . '/photos/' . $channel['channel_address'] . '/image/' . $photo_hash . ']' . t('a new photo') . '[/zrl]'; - $album_link = '[zrl=' . z_root() . '/photos/' . $channel['channel_address'] . '/album/' . bin2hex($album) . ']' . ((strlen($album)) ? $album : '/') . '[/zrl]'; + $album_link = '[zrl=' . z_root() . '/photos/' . $channel['channel_address'] . '/album/' . $args['directory']['hash'] . ']' . ((strlen($album)) ? $album : '/') . '[/zrl]'; $activity_format = sprintf(t('%1$s posted %2$s to %3$s','photo_upload'), $author_link, $photo_link, $album_link); -- cgit v1.2.3 From c352047228126ab439ca4582995f83f119188588 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Sun, 16 Jul 2017 22:51:36 -0700 Subject: mis-attributed profile photo when Mastodon comment author has no profile photo --- include/feedutils.php | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'include') diff --git a/include/feedutils.php b/include/feedutils.php index 6ee53e2f6..be7c926d4 100644 --- a/include/feedutils.php +++ b/include/feedutils.php @@ -1040,6 +1040,11 @@ function consume_feed($xml, $importer, &$contact, $pass = 0) { $datarray['comment_policy'] = 'none'; } + // if we have everything but a photo, provide the default profile photo + + if($author['author_name'] && $author['author_link'] && (! $author['author_photo'])) + $author['author_photo'] = z_root() . '/' . get_default_profile_photo(80); + if((! x($author,'author_name')) || ($author['author_is_feed'])) $author['author_name'] = $contact['xchan_name']; if((! x($author,'author_link')) || ($author['author_is_feed'])) @@ -1244,6 +1249,12 @@ function consume_feed($xml, $importer, &$contact, $pass = 0) { $datarray['comment_policy'] = 'none'; } + + // if we have everything but a photo, provide the default profile photo + + if($author['author_name'] && $author['author_link'] && (! $author['author_photo'])) + $author['author_photo'] = z_root() . '/' . get_default_profile_photo(80); + if(is_array($contact)) { if((! x($author,'author_name')) || ($author['author_is_feed'])) $author['author_name'] = $contact['xchan_name']; -- cgit v1.2.3 From ecb1515e5d6cd854bd64444b9c07af50df370efb Mon Sep 17 00:00:00 2001 From: zotlabs Date: Mon, 17 Jul 2017 19:28:27 -0700 Subject: activitystreams converters updated to recent spec --- include/feedutils.php | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) (limited to 'include') diff --git a/include/feedutils.php b/include/feedutils.php index be7c926d4..5f2a06029 100644 --- a/include/feedutils.php +++ b/include/feedutils.php @@ -1890,17 +1890,17 @@ function i2asld($i) { $ret = array(); - $ret['@context'] = array( 'http://www.w3.org/ns/activitystreams', 'zot' => 'http://purl.org/zot/protocol'); + $ret['@context'] = array( 'https://www.w3.org/ns/activitystreams', 'zot' => 'http://purl.org/zot/protocol'); if($i['verb']) { if(strpos(dirname($i['verb'],'activitystrea.ms/schema/1.0'))) { - $ret['@type'] = ucfirst(basename($i['verb'])); + $ret['type'] = ucfirst(basename($i['verb'])); } elseif(strpos(dirname($i['verb'],'purl.org/zot'))) { - $ret['@type'] = 'zot:' . ucfirst(basename($i['verb'])); + $ret['type'] = 'zot:' . ucfirst(basename($i['verb'])); } } - $ret['@id'] = $i['plink']; + $ret['id'] = $i['plink']; $ret['published'] = datetime_convert('UTC','UTC',$i['created'],ATOM_TIME); @@ -1922,7 +1922,7 @@ function asencode_note($i) { $ret = array(); $ret['@type'] = 'Note'; - $ret['@id'] = $i['plink']; + $ret['id'] = $i['plink']; if($i['title']) $ret['title'] = bbcode($i['title']); @@ -1938,16 +1938,18 @@ function asencode_note($i) { function asencode_person($p) { $ret = array(); - $ret['@type'] = 'Person'; - $ret['@id'] = 'acct:' . $p['xchan_addr']; - $ret['displayName'] = $p['xchan_name']; - $ret['icon'] = array( - '@type' => 'Link', + $ret['type'] = 'Person'; + $ret['id'] = $p['xchan_url']; + $ret['name'] = $p['xchan_name']; + $ret['image'] = array( + 'type' => 'Link', 'mediaType' => $p['xchan_photo_mimetype'], - 'href' => $p['xchan_photo_m'] + 'href' => $p['xchan_photo_l'], + 'height' => 300, + 'width' => 300 ); $ret['url'] = array( - '@type' => 'Link', + 'type' => 'Link', 'mediaType' => 'text/html', 'href' => $p['xchan_url'] ); -- cgit v1.2.3 From 0d062251b6c38a71932e9875cdd777afdfff140b Mon Sep 17 00:00:00 2001 From: zotlabs Date: Mon, 17 Jul 2017 19:42:30 -0700 Subject: fix for bug 827 to provide partial backward compatibility with album names in photo items from < hubzilla 2.4 this will only work part of the time - which is why the behaviour was changed --- include/photos.php | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'include') diff --git a/include/photos.php b/include/photos.php index 6ea444e2e..b4cc89502 100644 --- a/include/photos.php +++ b/include/photos.php @@ -593,6 +593,15 @@ function photos_album_exists($channel_id, $observer_hash, $album) { intval($channel_id) ); + // partial backward compatibility with Hubzilla < 2.4 when we used the filename only + // (ambiguous which would get chosen if you had two albums of the same name in different directories) + + if(! $r) { + $r = q("SELECT folder, hash, is_dir, filename, os_path, display_path FROM attach WHERE filename = '%s' AND is_dir = 1 AND uid = %d $sql_extra limit 1", + dbesc(hex2bin($album)), + intval($channel_id) + ); + return (($r) ? $r[0] : false); } -- cgit v1.2.3 From 15e836b7dd2fed3f97f134928d88e13db1d8a7f4 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Mon, 17 Jul 2017 19:53:03 -0700 Subject: provide content-type matching ability for activitypub --- include/network.php | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) (limited to 'include') diff --git a/include/network.php b/include/network.php index b85a16d21..fe9a9aa2b 100644 --- a/include/network.php +++ b/include/network.php @@ -1896,3 +1896,41 @@ function service_plink($contact, $guid) { return $x['plink']; } +function getBestSupportedMimeType($mimeTypes = null, $acceptedTypes = false) { + // Values will be stored in this array + + if($acceptedTypes === false) + $acceptedTypes = $_SERVER['HTTP_ACCEPT']; + + $AcceptTypes = Array (); + + // Accept header is case insensitive, and whitespace isn’t important + $accept = strtolower(str_replace(' ', '', $acceptedTypes)); + // divide it into parts in the place of a "," + $accept = explode(',', $accept); + foreach ($accept as $a) { + // the default quality is 1. + $q = 1; + // check if there is a different quality + if (strpos($a, ';q=')) { + // divide "mime/type;q=X" into two parts: "mime/type" i "X" + list($a, $q) = explode(';q=', $a); + } + // mime-type $a is accepted with the quality $q + // WARNING: $q == 0 means, that mime-type isn’t supported! + $AcceptTypes[$a] = $q; + } + arsort($AcceptTypes); + + // if no parameter was passed, just return parsed data + if (!$mimeTypes) return $AcceptTypes; + + $mimeTypes = array_map('strtolower', (array)$mimeTypes); + + // let’s check our supported types: + foreach ($AcceptTypes as $mime => $q) { + if ($q && in_array($mime, $mimeTypes)) return $mime; + } + // no mime-type found + return null; +} \ No newline at end of file -- cgit v1.2.3 From 27257de995f6d2da0a180cbd20a06614deee2b33 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Mon, 17 Jul 2017 19:57:25 -0700 Subject: fix typo --- include/photos.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'include') diff --git a/include/photos.php b/include/photos.php index b4cc89502..46b833531 100644 --- a/include/photos.php +++ b/include/photos.php @@ -598,9 +598,10 @@ function photos_album_exists($channel_id, $observer_hash, $album) { if(! $r) { $r = q("SELECT folder, hash, is_dir, filename, os_path, display_path FROM attach WHERE filename = '%s' AND is_dir = 1 AND uid = %d $sql_extra limit 1", - dbesc(hex2bin($album)), - intval($channel_id) - ); + dbesc(hex2bin($album)), + intval($channel_id) + ); + } return (($r) ? $r[0] : false); } -- cgit v1.2.3 From d8c93c0d13133d336e2cc3dbf3c48e0a6350c2d6 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Mon, 17 Jul 2017 22:17:40 -0700 Subject: activitypub, cont. --- include/feedutils.php | 40 ++++++++++++++++++++++++++-------------- 1 file changed, 26 insertions(+), 14 deletions(-) (limited to 'include') diff --git a/include/feedutils.php b/include/feedutils.php index 5f2a06029..b31448d81 100644 --- a/include/feedutils.php +++ b/include/feedutils.php @@ -1937,22 +1937,34 @@ function asencode_note($i) { function asencode_person($p) { - $ret = array(); - $ret['type'] = 'Person'; - $ret['id'] = $p['xchan_url']; - $ret['name'] = $p['xchan_name']; - $ret['image'] = array( - 'type' => 'Link', + $ret = []; + $ret['type'] = 'Person'; + $ret['id'] = $p['xchan_url']; + $ret['name'] = $p['xchan_name']; + $ret['icon'] = [ $p['xchan_photo_l'] ]; + $ret['image'] = [ + 'type' => 'Link', 'mediaType' => $p['xchan_photo_mimetype'], - 'href' => $p['xchan_photo_l'], - 'height' => 300, - 'width' => 300 - ); - $ret['url'] = array( - 'type' => 'Link', + 'href' => $p['xchan_photo_l'], + 'height' => 300, + 'width' => 300 + ]; + $ret['url'] = [ + 'type' => 'Link', 'mediaType' => 'text/html', - 'href' => $p['xchan_url'] - ); + 'href' => $p['xchan_url'] + ]; + + if(array_key_exists('channel_id',$p)) { + $ret['inbox'] = z_root() . '/inbox/' . $p['channel_address']; + $ret['outbox'] = z_root() . '/outbox/' . $p['channel_address']; + } + else { + $collections = get_xconfig($p['xchan_hash'],'activitystreams','collections',[]); + if($collections) { + $ret = array_merge($ret,$collections); + } + } return $ret; } -- cgit v1.2.3 From 9daa3b85c8b3ee48222a4b6c7c7ba70a3ca57fbb Mon Sep 17 00:00:00 2001 From: zotlabs Date: Mon, 17 Jul 2017 22:52:19 -0700 Subject: some corrections to AS encoding based on the current spec (some of this work was completed long before the spec settled). --- include/feedutils.php | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) (limited to 'include') diff --git a/include/feedutils.php b/include/feedutils.php index b31448d81..daab1a741 100644 --- a/include/feedutils.php +++ b/include/feedutils.php @@ -1941,13 +1941,28 @@ function asencode_person($p) { $ret['type'] = 'Person'; $ret['id'] = $p['xchan_url']; $ret['name'] = $p['xchan_name']; - $ret['icon'] = [ $p['xchan_photo_l'] ]; - $ret['image'] = [ - 'type' => 'Link', - 'mediaType' => $p['xchan_photo_mimetype'], - 'href' => $p['xchan_photo_l'], - 'height' => 300, - 'width' => 300 + $ret['icon'] = [ + [ + 'type' => 'Image', + 'mediaType' => $p['xchan_photo_mimetype'], + 'url' => $p['xchan_photo_l'], + 'height' => 300, + 'width' => 300, + ], + [ + 'type' => 'Image', + 'mediaType' => $p['xchan_photo_mimetype'], + 'url' => $p['xchan_photo_m'], + 'height' => 80, + 'width' => 80, + ], + [ + 'type' => 'Image', + 'mediaType' => $p['xchan_photo_mimetype'], + 'url' => $p['xchan_photo_l'], + 'height' => 48, + 'width' => 48, + ] ]; $ret['url'] = [ 'type' => 'Link', -- cgit v1.2.3 From 08c0d78296d4518a5ece4d6a2c05b9be83580aa8 Mon Sep 17 00:00:00 2001 From: git-marijus Date: Tue, 18 Jul 2017 13:56:09 +0200 Subject: issue #827 provide backward compatibility for album links generated in earlier times before the ambiguity of photo album names was solved. This may provide incorrect results if two or more photo albums with the same basename exist in different directories of the file tree; but there is no easy way to solve that ambiguity - which is why the link format changed. --- include/photos.php | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'include') diff --git a/include/photos.php b/include/photos.php index 6ea444e2e..f5d5fdb48 100644 --- a/include/photos.php +++ b/include/photos.php @@ -593,6 +593,15 @@ function photos_album_exists($channel_id, $observer_hash, $album) { intval($channel_id) ); + // partial backward compatibility with Hubzilla < 2.4 when we used the filename only + // (ambiguous which would get chosen if you had two albums of the same name in different directories) + if(!$r) { + $r = q("SELECT folder, hash, is_dir, filename, os_path, display_path FROM attach WHERE filename = '%s' AND is_dir = 1 AND uid = %d $sql_extra limit 1", + dbesc(hex2bin($album)), + intval($channel_id) + ); + } + return (($r) ? $r[0] : false); } -- cgit v1.2.3 From 6103c301848105a3bca3de81e9982276b2c38d76 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Tue, 18 Jul 2017 21:16:18 -0700 Subject: provide optional salmon signatures for AP entities --- include/feedutils.php | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'include') diff --git a/include/feedutils.php b/include/feedutils.php index daab1a741..5d537553f 100644 --- a/include/feedutils.php +++ b/include/feedutils.php @@ -1973,6 +1973,14 @@ function asencode_person($p) { if(array_key_exists('channel_id',$p)) { $ret['inbox'] = z_root() . '/inbox/' . $p['channel_address']; $ret['outbox'] = z_root() . '/outbox/' . $p['channel_address']; + $ret['me:magic_keys'] = [ + [ + 'value' => salmon_key($p['channel_pubkey']), + 'key_id' => base64url_encode(hash('sha256',salmon_key($p['channel_pubkey'])),true) + ] + ]; + + } else { $collections = get_xconfig($p['xchan_hash'],'activitystreams','collections',[]); -- cgit v1.2.3 From df7f0eb9a4eb42aebd94cbdf8288f0fa8c9b3782 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Wed, 19 Jul 2017 18:32:16 -0700 Subject: hubzilla issue #832 --- include/group.php | 3 ++- include/zot.php | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) (limited to 'include') diff --git a/include/group.php b/include/group.php index 3b208ef95..e0c20b536 100644 --- a/include/group.php +++ b/include/group.php @@ -278,8 +278,9 @@ function group_side($every="connections",$each="group",$edit = false, $group_id $o = ''; - if(! (local_channel() && feature_enabled(local_channel(),'groups'))) + if(! (local_channel() && feature_enabled(local_channel(),'groups'))) { return ''; + } $groups = array(); diff --git a/include/zot.php b/include/zot.php index 677fdf6b7..8bbc4a969 100644 --- a/include/zot.php +++ b/include/zot.php @@ -3372,7 +3372,7 @@ function process_channel_sync_delivery($sender, $arr, $deliveries) { dbesc($cl['name']), intval($cl['visible']), intval($cl['deleted']), - dbesc($cl['hash']), + dbesc($cl['collection']), intval($channel['channel_id']) ); } -- cgit v1.2.3 From ceeb9836b98c8a854fe6501fd51c3de7c4c91655 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Wed, 19 Jul 2017 20:31:11 -0700 Subject: implement update_feed_item --- include/feedutils.php | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'include') diff --git a/include/feedutils.php b/include/feedutils.php index 5d537553f..9a70fdae4 100644 --- a/include/feedutils.php +++ b/include/feedutils.php @@ -1073,7 +1073,7 @@ function consume_feed($xml, $importer, &$contact, $pass = 0) { $datarray['owner_xchan'] = $contact['xchan_hash']; - $r = q("SELECT edited FROM item WHERE mid = '%s' AND uid = %d LIMIT 1", + $r = q("SELECT id, edited FROM item WHERE mid = '%s' AND uid = %d LIMIT 1", dbesc($datarray['mid']), intval($importer['channel_id']) ); @@ -1089,7 +1089,12 @@ function consume_feed($xml, $importer, &$contact, $pass = 0) { if(datetime_convert('UTC','UTC',$datarray['edited']) < $r[0]['edited']) continue; + $datarray['uid'] = $importer['channel_id']; + $datarray['aid'] = $importer['channel_account_id']; + $datarray['id'] = $r[0]['id']; + update_feed_item($importer['channel_id'],$datarray); + } continue; } @@ -1300,7 +1305,7 @@ function consume_feed($xml, $importer, &$contact, $pass = 0) { } - $r = q("SELECT edited FROM item WHERE mid = '%s' AND uid = %d LIMIT 1", + $r = q("SELECT id, edited FROM item WHERE mid = '%s' AND uid = %d LIMIT 1", dbesc($datarray['mid']), intval($importer['channel_id']) ); @@ -1315,6 +1320,10 @@ function consume_feed($xml, $importer, &$contact, $pass = 0) { if(datetime_convert('UTC','UTC',$datarray['edited']) < $r[0]['edited']) continue; + $datarray['uid'] = $importer['channel_id']; + $datarray['aid'] = $importer['channel_account_id']; + $datarray['id'] = $r[0]['id']; + update_feed_item($importer['channel_id'],$datarray); } @@ -1555,7 +1564,7 @@ function feed_meta($xml) { * @param array $datarray */ function update_feed_item($uid, $datarray) { - logger('Not implemented! ' . $uid . ' ' . print_r($datarray, true), LOGGER_DATA); + item_store_update($datarray); } /** -- cgit v1.2.3 From a346399fe6d35f9f2b3c854f515a7f302cda421b Mon Sep 17 00:00:00 2001 From: zotlabs Date: Thu, 20 Jul 2017 18:11:47 -0700 Subject: allow wildcard tag and category searches --- include/taxonomy.php | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'include') diff --git a/include/taxonomy.php b/include/taxonomy.php index dc0e439e2..46d661581 100644 --- a/include/taxonomy.php +++ b/include/taxonomy.php @@ -46,8 +46,16 @@ function term_query($table,$s,$type = TERM_UNKNOWN, $type2 = '') { function term_item_parent_query($uid,$table,$s,$type = TERM_UNKNOWN, $type2 = '') { + // Allow asterisks for wildcard search + // In theory this means '%' will also do a wildcard search, but there appear to be multiple escape + // issues with '%' in term names and trying to fix this with '\\%' here did not help. + // Ideally I think we want '*' to indicate wildcards and allow '%' literally in names, but that is being + // left for another developer on another day. + + $s = str_replace('*','%',$s); + if($type2) { - $r = q("select parent from item left join term on term.oid = item.id where term.ttype in (%d, %d) and term.term = '%s' and term.uid = %d and term.otype = 1", + $r = q("select parent from item left join term on term.oid = item.id where term.ttype in (%d, %d) and term.term like '%s' and term.uid = %d and term.otype = 1", intval($type), intval($type2), dbesc($s), @@ -55,12 +63,13 @@ function term_item_parent_query($uid,$table,$s,$type = TERM_UNKNOWN, $type2 = '' ); } else { - $r = q("select parent from item left join term on term.oid = item.id where term.ttype = %d and term.term = '%s' and term.uid = %d and term.otype = 1", + $r = q("select parent from item left join term on term.oid = item.id where term.ttype = %d and term.term like '%s' and term.uid = %d and term.otype = 1", intval($type), dbesc($s), intval($uid) ); } + if($r) { $str = ''; foreach($r as $rv) { -- cgit v1.2.3 From 89d21c08735ad9bb151acee5ee1f372a803e2213 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Thu, 20 Jul 2017 22:55:04 -0700 Subject: begin the tedious process of mapping activities between AS1, zot, and AS2 --- include/feedutils.php | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) (limited to 'include') diff --git a/include/feedutils.php b/include/feedutils.php index 9a70fdae4..4f68fdeef 100644 --- a/include/feedutils.php +++ b/include/feedutils.php @@ -2001,3 +2001,52 @@ function asencode_person($p) { return $ret; } + +function activity_mapper($verb) { + + $acts = [ + 'http://activitystrea.ms/schema/1.0/post' => 'Create', + 'http://activitystrea.ms/schema/1.0/update' => 'Update', + 'http://activitystrea.ms/schema/1.0/like' => 'Like', + 'http://activitystrea.ms/schema/1.0/favorite' => 'Like', + 'http://purl.org/zot/activity/dislike' => 'Dislike', + 'http://activitystrea.ms/schema/1.0/tag' => 'Add', + 'http://activitystrea.ms/schema/1.0/follow' => 'Follow', + 'http://activitystrea.ms/schema/1.0/unfollow' => 'Unfollow', + ]; + + + if(array_key_exists($acts[$verb])) { + return $acts[$verb]; + } + return false; +} + + +function activity_obj_mapper($obj,$reverse = false) { + + $objs = [ + 'http://activitystrea.ms/schema/1.0/note' => 'Note', + 'http://activitystrea.ms/schema/1.0/comment' => 'Note', + 'http://activitystrea.ms/schema/1.0/person' => 'Person', + 'http://purl.org/zot/activity/profile' => 'Profile', + 'http://activitystrea.ms/schema/1.0/photo' => 'Image', + 'http://activitystrea.ms/schema/1.0/profile-photo' => 'Icon', + 'http://activitystrea.ms/schema/1.0/event' => 'Event', + 'http://activitystrea.ms/schema/1.0/wiki' => 'Document', + 'http://purl.org/zot/activity/location' => 'Place', + 'http://purl.org/zot/activity/chessgame' => 'Game', + 'http://purl.org/zot/activity/tagterm' => 'zot:Tag', + 'http://purl.org/zot/activity/thing' => 'zot:Thing', + 'http://purl.org/zot/activity/file' => 'zot:File', + 'http://purl.org/zot/activity/poke' => 'zot:Action', + 'http://purl.org/zot/activity/react' => 'zot:Reaction', + 'http://purl.org/zot/activity/mood' => 'zot:Mood', + + ]; + + if(array_key_exists($objs[$verb])) { + return $objs[$verb]; + } + return false; +} -- cgit v1.2.3 From 1bdcfe5219c810758ae255427513a7a0c09ce8e1 Mon Sep 17 00:00:00 2001 From: git-marijus Date: Fri, 21 Jul 2017 10:32:21 +0200 Subject: provide a mechanism to mark apps active in the bin --- include/nav.php | 22 ++++------------------ 1 file changed, 4 insertions(+), 18 deletions(-) (limited to 'include') diff --git a/include/nav.php b/include/nav.php index b0533e4c7..f6c8aa23f 100644 --- a/include/nav.php +++ b/include/nav.php @@ -101,12 +101,12 @@ EOT; $nav['logout'] = ['logout',t('Logout'), "", t('End this session'),'logout_nav_btn']; // user menu - $nav['usermenu'][] = ['profile/' . $channel['channel_address'], t('View Profile'), "", t('Your profile page'),'profile_nav_btn']; + $nav['usermenu'][] = ['profile/' . $channel['channel_address'], t('View Profile'), ((\App::$nav_sel['active'] == 'Profile') ? 'active' : ''), t('Your profile page'),'profile_nav_btn']; if(feature_enabled(local_channel(),'multi_profiles')) - $nav['usermenu'][] = ['profiles', t('Edit Profiles'),"", t('Manage/Edit profiles'),'profiles_nav_btn']; + $nav['usermenu'][] = ['profiles', t('Edit Profiles'), ((\App::$nav_sel['active'] == 'Profiles') ? 'active' : '') , t('Manage/Edit profiles'),'profiles_nav_btn']; else - $nav['usermenu'][] = ['profiles/' . $prof[0]['id'], t('Edit Profile'),"", t('Edit your profile'),'profiles_nav_btn']; + $nav['usermenu'][] = ['profiles/' . $prof[0]['id'], t('Edit Profile'), ((\App::$nav_sel['active'] == 'Profiles') ? 'active' : ''), t('Edit your profile'),'profiles_nav_btn']; } else { @@ -290,21 +290,7 @@ EOT; * */ function nav_set_selected($item){ - App::$nav_sel = array( - 'community' => null, - 'network' => null, - 'home' => null, - 'profiles' => null, - 'intros' => null, - 'notifications' => null, - 'messages' => null, - 'directory' => null, - 'settings' => null, - 'contacts' => null, - 'manage' => null, - 'register' => null, - ); - App::$nav_sel[$item] = 'active'; + App::$nav_sel['active'] = $item; } -- cgit v1.2.3 From 5cc8837fb6605d18f09693e4ca418b8a5d38f57b Mon Sep 17 00:00:00 2001 From: git-marijus Date: Tue, 25 Jul 2017 20:06:01 +0200 Subject: make local channel (not our own) nav menus appear similar to what we are used from remote channels --- include/nav.php | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) (limited to 'include') diff --git a/include/nav.php b/include/nav.php index f6c8aa23f..4cb2e7fa6 100644 --- a/include/nav.php +++ b/include/nav.php @@ -42,7 +42,7 @@ EOT; $observer = App::get_observer(); require_once('include/conversation.php'); - $is_owner = (((local_channel()) && (App::$profile['profile_uid'] == local_channel())) ? true : false); + $is_owner = (((local_channel()) && ((App::$profile_uid == local_channel()) || (App::$profile_uid == 0))) ? true : false); $channel_apps[] = channel_apps($is_owner, App::$profile['channel_address']); $myident = (($channel) ? $channel['xchan_addr'] : ''); @@ -93,8 +93,6 @@ EOT; if(local_channel()) { - - if($chans && count($chans) > 1 && feature_enabled(local_channel(),'nav_channel_select')) $nav['channels'] = $chans; @@ -134,12 +132,12 @@ EOT; $homelink = (($observer) ? $observer['xchan_url'] : ''); } - if(! local_channel()) { + if(! $is_owner) { $nav['rusermenu'] = array( $homelink, t('Take me home'), 'logout', - t('Log me out of this site') + ((local_channel()) ? t('Logout') : t('Log me out of this site')) ); } @@ -170,7 +168,6 @@ EOT; if(local_channel()) { - $nav['network'] = array('network', t('Grid'), "", t('Your grid'),'network_nav_btn'); $nav['network']['all'] = [ 'network', t('View your network/grid'), '','' ]; $nav['network']['mark'] = array('', t('Mark all grid notifications seen'), '',''); @@ -221,7 +218,7 @@ EOT; $powered_by = ''; //app bin - if(local_channel()) { + if($is_owner) { if(get_pconfig(local_channel(), 'system','initial_import_system_apps') === false) { Zlib\Apps::import_system_apps(); set_pconfig(local_channel(), 'system','initial_import_system_apps', 1); @@ -245,7 +242,10 @@ EOT; $syslist = Zlib\Apps::app_order(local_channel(),$syslist); foreach($syslist as $app) { - $nav_apps[] = Zlib\Apps::app_render($app,'nav'); + if($is_owner) + $nav_apps[] = Zlib\Apps::app_render($app,'nav'); + elseif(! $is_owner && strpos($app['requires'], 'local_channel') === false) + $nav_apps[] = Zlib\Apps::app_render($app,'nav'); } $tpl = get_markup_template('nav.tpl'); @@ -259,6 +259,7 @@ EOT; '$emptynotifications' => t('Loading...'), '$userinfo' => $x['usermenu'], '$localuser' => local_channel(), + '$is_owner' => $is_owner, '$sel' => App::$nav_sel, '$powered_by' => $powered_by, '$help' => t('@name, #tag, ?doc, content'), -- cgit v1.2.3 From e71cdf02a8303689c933b98185e2671f49fc5a7d Mon Sep 17 00:00:00 2001 From: git-marijus Date: Wed, 26 Jul 2017 21:42:07 +0200 Subject: move the active app code to include/nav.php - it is only relevant there --- include/nav.php | 3 +++ 1 file changed, 3 insertions(+) (limited to 'include') diff --git a/include/nav.php b/include/nav.php index 4cb2e7fa6..cd32126a1 100644 --- a/include/nav.php +++ b/include/nav.php @@ -242,6 +242,9 @@ EOT; $syslist = Zlib\Apps::app_order(local_channel(),$syslist); foreach($syslist as $app) { + if(\App::$nav_sel['active'] == $app['name']) + $app['active'] = true; + if($is_owner) $nav_apps[] = Zlib\Apps::app_render($app,'nav'); elseif(! $is_owner && strpos($app['requires'], 'local_channel') === false) -- cgit v1.2.3 From d3d184192d93e614bbcf31f6149084e8489befe0 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Wed, 26 Jul 2017 17:38:34 -0700 Subject: issue with OStatus comments being propagated downstream --- include/feedutils.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'include') diff --git a/include/feedutils.php b/include/feedutils.php index 4f68fdeef..dbf60f553 100644 --- a/include/feedutils.php +++ b/include/feedutils.php @@ -999,6 +999,7 @@ function consume_feed($xml, $importer, &$contact, $pass = 0) { foreach($items as $item) { $is_reply = false; + $send_downstream = false; $parent_link = ''; logger('processing ' . $item->get_id(), LOGGER_DEBUG); @@ -1200,6 +1201,15 @@ function consume_feed($xml, $importer, &$contact, $pass = 0) { $status = 202; continue; } + + // The salmon endpoint sets this to indicate that we should send comments from + // interactive feeds (such as OStatus) downstream to our followers + // We do not want to set it for non-interactive feeds or conversations we do not own + + if(array_key_exists('send_downstream',$importer) && intval($importer['send_downstream']) + && ($parent_item['owner_xchan'] == $importer['channel_hash'])) { + $send_downstream = true; + } } else { if((! perm_is_allowed($importer['channel_id'],$contact['xchan_hash'],'send_stream')) && (! $importer['system'])) { @@ -1229,6 +1239,11 @@ function consume_feed($xml, $importer, &$contact, $pass = 0) { $xx = item_store($datarray); $r = $xx['item_id']; + + if($send_downstream) { + \Zotlabs\Daemon\Master::Summon(array('Notifier', 'comment', $r)); + } + continue; } else { -- cgit v1.2.3 From 75d63684b8c6ee7bd6ef53a1981319f3235ff7dc Mon Sep 17 00:00:00 2001 From: zotlabs Date: Wed, 26 Jul 2017 16:39:13 -0700 Subject: remove activitypub components from core --- include/feedutils.php | 182 -------------------------------------------------- 1 file changed, 182 deletions(-) (limited to 'include') diff --git a/include/feedutils.php b/include/feedutils.php index dbf60f553..eb24f9032 100644 --- a/include/feedutils.php +++ b/include/feedutils.php @@ -1883,185 +1883,3 @@ function atom_entry($item, $type, $author, $owner, $comment = false, $cid = 0, $ return $x['entry']; } -/** - * @brief - * - * @param array $items - * @return array - */ -function gen_asld($items) { - $ret = array(); - if(! $items) - return $ret; - - foreach($items as $item) { - $ret[] = i2asld($item); - } - - return $ret; -} - -/** - * @brief - * - * @param array $i - * @return array - */ -function i2asld($i) { - - if(! $i) - return array(); - - $ret = array(); - - $ret['@context'] = array( 'https://www.w3.org/ns/activitystreams', 'zot' => 'http://purl.org/zot/protocol'); - - if($i['verb']) { - if(strpos(dirname($i['verb'],'activitystrea.ms/schema/1.0'))) { - $ret['type'] = ucfirst(basename($i['verb'])); - } - elseif(strpos(dirname($i['verb'],'purl.org/zot'))) { - $ret['type'] = 'zot:' . ucfirst(basename($i['verb'])); - } - } - $ret['id'] = $i['plink']; - - $ret['published'] = datetime_convert('UTC','UTC',$i['created'],ATOM_TIME); - - // we need to pass the parent into this -// if($i['id'] != $i['parent'] && $i['obj_type'] === ACTIVITY_OBJ_NOTE) { -// $ret['inReplyTo'] = asencode_note -// } - - if($i['obj_type'] === ACTIVITY_OBJ_NOTE) - $ret['object'] = asencode_note($i); - - $ret['actor'] = asencode_person($i['author']); - - return $ret; -} - -function asencode_note($i) { - - $ret = array(); - - $ret['@type'] = 'Note'; - $ret['id'] = $i['plink']; - if($i['title']) - $ret['title'] = bbcode($i['title']); - - $ret['content'] = bbcode($i['body']); - $ret['zot:owner'] = asencode_person($i['owner']); - $ret['published'] = datetime_convert('UTC','UTC',$i['created'],ATOM_TIME); - if($i['created'] !== $i['edited']) - $ret['updated'] = datetime_convert('UTC','UTC',$i['edited'],ATOM_TIME); - - return $ret; -} - - -function asencode_person($p) { - $ret = []; - $ret['type'] = 'Person'; - $ret['id'] = $p['xchan_url']; - $ret['name'] = $p['xchan_name']; - $ret['icon'] = [ - [ - 'type' => 'Image', - 'mediaType' => $p['xchan_photo_mimetype'], - 'url' => $p['xchan_photo_l'], - 'height' => 300, - 'width' => 300, - ], - [ - 'type' => 'Image', - 'mediaType' => $p['xchan_photo_mimetype'], - 'url' => $p['xchan_photo_m'], - 'height' => 80, - 'width' => 80, - ], - [ - 'type' => 'Image', - 'mediaType' => $p['xchan_photo_mimetype'], - 'url' => $p['xchan_photo_l'], - 'height' => 48, - 'width' => 48, - ] - ]; - $ret['url'] = [ - 'type' => 'Link', - 'mediaType' => 'text/html', - 'href' => $p['xchan_url'] - ]; - - if(array_key_exists('channel_id',$p)) { - $ret['inbox'] = z_root() . '/inbox/' . $p['channel_address']; - $ret['outbox'] = z_root() . '/outbox/' . $p['channel_address']; - $ret['me:magic_keys'] = [ - [ - 'value' => salmon_key($p['channel_pubkey']), - 'key_id' => base64url_encode(hash('sha256',salmon_key($p['channel_pubkey'])),true) - ] - ]; - - - } - else { - $collections = get_xconfig($p['xchan_hash'],'activitystreams','collections',[]); - if($collections) { - $ret = array_merge($ret,$collections); - } - } - - return $ret; -} - - -function activity_mapper($verb) { - - $acts = [ - 'http://activitystrea.ms/schema/1.0/post' => 'Create', - 'http://activitystrea.ms/schema/1.0/update' => 'Update', - 'http://activitystrea.ms/schema/1.0/like' => 'Like', - 'http://activitystrea.ms/schema/1.0/favorite' => 'Like', - 'http://purl.org/zot/activity/dislike' => 'Dislike', - 'http://activitystrea.ms/schema/1.0/tag' => 'Add', - 'http://activitystrea.ms/schema/1.0/follow' => 'Follow', - 'http://activitystrea.ms/schema/1.0/unfollow' => 'Unfollow', - ]; - - - if(array_key_exists($acts[$verb])) { - return $acts[$verb]; - } - return false; -} - - -function activity_obj_mapper($obj,$reverse = false) { - - $objs = [ - 'http://activitystrea.ms/schema/1.0/note' => 'Note', - 'http://activitystrea.ms/schema/1.0/comment' => 'Note', - 'http://activitystrea.ms/schema/1.0/person' => 'Person', - 'http://purl.org/zot/activity/profile' => 'Profile', - 'http://activitystrea.ms/schema/1.0/photo' => 'Image', - 'http://activitystrea.ms/schema/1.0/profile-photo' => 'Icon', - 'http://activitystrea.ms/schema/1.0/event' => 'Event', - 'http://activitystrea.ms/schema/1.0/wiki' => 'Document', - 'http://purl.org/zot/activity/location' => 'Place', - 'http://purl.org/zot/activity/chessgame' => 'Game', - 'http://purl.org/zot/activity/tagterm' => 'zot:Tag', - 'http://purl.org/zot/activity/thing' => 'zot:Thing', - 'http://purl.org/zot/activity/file' => 'zot:File', - 'http://purl.org/zot/activity/poke' => 'zot:Action', - 'http://purl.org/zot/activity/react' => 'zot:Reaction', - 'http://purl.org/zot/activity/mood' => 'zot:Mood', - - ]; - - if(array_key_exists($objs[$verb])) { - return $objs[$verb]; - } - return false; -} -- cgit v1.2.3 From 1376e59d002a7adf84f363d00c46e5db783d5b66 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Wed, 26 Jul 2017 16:22:20 -0700 Subject: improve the formatting of shares when converting from bbcode to markdown --- include/markdown.php | 69 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) (limited to 'include') diff --git a/include/markdown.php b/include/markdown.php index 5d3c4c7df..ccd108c1b 100644 --- a/include/markdown.php +++ b/include/markdown.php @@ -84,6 +84,72 @@ function markdown_to_bb($s, $use_zrl = false, $options = []) { +function bb_to_markdown_share($match) { + + $matches = array(); + $attributes = $match[1]; + + $author = ""; + preg_match("/author='(.*?)'/ism", $attributes, $matches); + if ($matches[1] != "") + $author = urldecode($matches[1]); + + $link = ""; + preg_match("/link='(.*?)'/ism", $attributes, $matches); + if ($matches[1] != "") + $link = $matches[1]; + + $avatar = ""; + preg_match("/avatar='(.*?)'/ism", $attributes, $matches); + if ($matches[1] != "") + $avatar = $matches[1]; + + $profile = ""; + preg_match("/profile='(.*?)'/ism", $attributes, $matches); + if ($matches[1] != "") + $profile = $matches[1]; + + $posted = ""; + preg_match("/posted='(.*?)'/ism", $attributes, $matches); + if ($matches[1] != "") + $posted = $matches[1]; + + // message_id is never used, do we still need it? + $message_id = ""; + preg_match("/message_id='(.*?)'/ism", $attributes, $matches); + if ($matches[1] != "") + $message_id = $matches[1]; + + if(! $message_id) { + preg_match("/guid='(.*?)'/ism", $attributes, $matches); + if ($matches[1] != "") + $message_id = $matches[1]; + } + + + $reldate = datetime_convert('UTC', date_default_timezone_get(), $posted, 'r'); + + $headline = ''; + + if ($avatar != "") + $headline .= '[url=' . zid($profile) . '][img]' . $avatar . '[/img][/url]'; + + // Bob Smith wrote the following post 2 hours ago + + $fmt = sprintf( t('%1$s wrote the following %2$s %3$s'), + '[url=' . zid($profile) . ']' . $author . '[/url]', + '[url=' . zid($link) . ']' . t('post') . '[/url]', + $reldate + ); + + $headline .= $fmt . "\n\n"; + + $text = $headline . trim($match[2]); + + return $text; +} + + function bb_to_markdown($Text) { @@ -100,9 +166,12 @@ function bb_to_markdown($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); + $Text = preg_replace_callback("/\[share(.*?)\](.*?)\[\/share\]/ism", 'bb_to_markdown_share', $Text); + call_hooks('bb_to_markdown_bb',$Text); + // Convert it to HTML - don't try oembed $Text = bbcode($Text, $preserve_nl, false); -- cgit v1.2.3 From 3faca10efc09a2fb40cacffffda80c99fd6bace5 Mon Sep 17 00:00:00 2001 From: git-marijus Date: Sun, 30 Jul 2017 19:46:52 +0200 Subject: fix a bug where if multiple channels uploaded the same file to the same folder, the uploaded file would end up with an incremental number added to the filename for each upload even if the file did not exist yet in the channels folder --- include/attach.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'include') diff --git a/include/attach.php b/include/attach.php index 3a0c8b7ba..bd18b23f2 100644 --- a/include/attach.php +++ b/include/attach.php @@ -610,7 +610,8 @@ function attach_store($channel, $observer_hash, $options = '', $arr = null) { // A freshly uploaded file. Check for duplicate and resolve with the channel's overwrite settings. - $r = q("select filename, id, hash, filesize from attach where filename = '%s' and folder = '%s' ", + $r = q("select filename, id, hash, filesize from attach where uid = %d and filename = '%s' and folder = '%s' ", + intval($channel_id), dbesc($filename), dbesc($folder_hash) ); @@ -632,7 +633,8 @@ function attach_store($channel, $observer_hash, $options = '', $arr = null) { $ext = $def_extension; } - $r = q("select filename from attach where ( filename = '%s' OR filename like '%s' ) and folder = '%s' ", + $r = q("select filename from attach where uid = %d and ( filename = '%s' OR filename like '%s' ) and folder = '%s' ", + intval($channel_id), dbesc($basename . $ext), dbesc($basename . '(%)' . $ext), dbesc($folder_hash) -- cgit v1.2.3 From 17618be14d1b9213822643ed6af92ac04fe70767 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Sun, 30 Jul 2017 13:52:16 -0700 Subject: add options flag to bb_to_markdown so we can distinguish between diaspora use and other use and therefore filter and adjust content selectively --- include/markdown.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'include') diff --git a/include/markdown.php b/include/markdown.php index ccd108c1b..530af57a0 100644 --- a/include/markdown.php +++ b/include/markdown.php @@ -151,7 +151,7 @@ function bb_to_markdown_share($match) { -function bb_to_markdown($Text) { +function bb_to_markdown($Text, $options = []) { /* * Transform #tags, strip off the [url] and replace spaces with underscore @@ -168,9 +168,11 @@ function bb_to_markdown($Text) { $Text = preg_replace_callback("/\[share(.*?)\](.*?)\[\/share\]/ism", 'bb_to_markdown_share', $Text); + $x = [ 'bbcode' => $Text, 'options' => $options ]; - call_hooks('bb_to_markdown_bb',$Text); + call_hooks('bb_to_markdown_bb',$x); + $Text = $x['bbcode']; // Convert it to HTML - don't try oembed $Text = bbcode($Text, $preserve_nl, false); -- cgit v1.2.3 From a3fef34a3f542905247031d0dfd7ec661fbefd1c Mon Sep 17 00:00:00 2001 From: zotlabs Date: Sun, 30 Jul 2017 16:15:34 -0700 Subject: provide a better "is_commentable" default for OStatus conversations that were fetched on the fly --- include/feedutils.php | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'include') diff --git a/include/feedutils.php b/include/feedutils.php index eb24f9032..e3f899a1e 100644 --- a/include/feedutils.php +++ b/include/feedutils.php @@ -1028,6 +1028,11 @@ function consume_feed($xml, $importer, &$contact, $pass = 0) { if(! $datarray['mid']) continue; + // This probably isn't an appropriate default but we're about to change it + // if it's wrong. + + $datarray['comment_policy'] = 'authenticated'; + // A Mastodon privacy tag has been found. We cannot send private comments // through the OStatus protocol, so block commenting. @@ -1256,6 +1261,11 @@ function consume_feed($xml, $importer, &$contact, $pass = 0) { if(! $datarray['mid']) continue; + // This probably isn't an appropriate default but we're about to change it + // if it's wrong. + + $datarray['comment_policy'] = 'authenticated'; + // A Mastodon privacy tag has been found. We cannot send private comments // through the OStatus protocol, so block commenting. @@ -1270,6 +1280,7 @@ function consume_feed($xml, $importer, &$contact, $pass = 0) { } + // if we have everything but a photo, provide the default profile photo if($author['author_name'] && $author['author_link'] && (! $author['author_photo'])) @@ -1493,7 +1504,7 @@ function process_salmon_feed($xml, $importer) { // reset policies which are restricted by default for RSS connections // This item is likely coming from GNU-social via salmon and allows public interaction $datarray['public_policy'] = ''; - $datarray['comment_policy'] = ''; + $datarray['comment_policy'] = 'authenticated'; $ret['item'] = $datarray; } -- cgit v1.2.3 From 2095937c600c1770f656ac6354340815b4fde73e Mon Sep 17 00:00:00 2001 From: git-marijus Date: Mon, 31 Jul 2017 16:59:43 +0200 Subject: improve file_activity() a little --- include/attach.php | 23 +++-------------------- 1 file changed, 3 insertions(+), 20 deletions(-) (limited to 'include') diff --git a/include/attach.php b/include/attach.php index bd18b23f2..cfea047ef 100644 --- a/include/attach.php +++ b/include/attach.php @@ -1677,17 +1677,9 @@ function file_activity($channel_id, $object, $allow_cid, $allow_gid, $deny_cid, $arr['obj'] = $u_jsonobject; $arr['body'] = ''; - $post = item_store($arr); - $item_id = $post['item_id']; - if($item_id) { - Zotlabs\Daemon\Master::Summon(array('Notifier','activity',$item_id)); - } - - call_hooks('post_local_end', $arr); + post_activity_item($arr); $update = false; - - //notice( t('File activity updated') . EOL); } //don't create new activity if notify was not enabled @@ -1712,16 +1704,7 @@ function file_activity($channel_id, $object, $allow_cid, $allow_gid, $deny_cid, $arr['obj'] = (($update) ? $u_jsonobject : $jsonobject); $arr['body'] = ''; - $post = item_store($arr); - $item_id = $post['item_id']; - - if($item_id) { - Zotlabs\Daemon\Master::Summon(array('Notifier','activity',$item_id)); - } - - call_hooks('post_local_end', $arr); - - //(($verb === 'post') ? notice( t('File activity posted') . EOL) : notice( t('File activity dropped') . EOL)); + post_activity_item($arr); return; } @@ -1887,7 +1870,7 @@ function recursive_activity_recipients($arr_allow_cid, $arr_allow_gid, $arr_deny //if none is allowed restrict to self if(($r_arr_allow_gid === false) && ($r_arr_allow_cid === false)) { - $ret['allow_cid'] = $poster['xchan_hash']; + $ret['allow_cid'] = [$poster['xchan_hash']]; } else { $ret['allow_gid'] = $r_arr_allow_gid; $ret['allow_cid'] = $r_arr_allow_cid; -- cgit v1.2.3 From a4a99d2d464971b39b4806556d8687ccb8b4ef86 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Sun, 30 Jul 2017 19:04:17 -0700 Subject: ensure we can work around the $is_http var in include/follow - this is left over from when the only non-webfinger connections we could make were RSS/Atom feeds. --- include/follow.php | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) (limited to 'include') diff --git a/include/follow.php b/include/follow.php index 2c2f5e209..9e2fd6a9c 100644 --- a/include/follow.php +++ b/include/follow.php @@ -182,6 +182,11 @@ function new_contact($uid,$url,$channel,$interactive = false, $confirm = false) $hash = get_observer_hash(); $default_group = $channel['channel_default_group']; + if($hash == $xchan_hash) { + $result['message'] = t('Cannot connect to yourself.'); + return $result; + } + if($xchan['xchan_network'] === 'rss') { // check service class feed limits @@ -196,28 +201,22 @@ function new_contact($uid,$url,$channel,$interactive = false, $confirm = false) $result['message'] = upgrade_message(); return $result; } - } - if($hash == $xchan_hash) { - $result['message'] = t('Cannot connect to yourself.'); - return $result; + // Always set these "remote" permissions for feeds since we cannot interact with them + // to negotiate a suitable permission response + + set_abconfig($uid,$xchan_hash,'their_perms','view_stream',1); + set_abconfig($uid,$xchan_hash,'their_perms','republish',1); + } + $r = q("select abook_id, abook_xchan, abook_pending, abook_instance from abook where abook_xchan = '%s' and abook_channel = %d limit 1", dbesc($xchan_hash), intval($uid) ); - if($is_http) { - - // Always set these "remote" permissions for feeds since we cannot interact with them - // to negotiate a suitable permission response - - set_abconfig($uid,$xchan_hash,'their_perms','view_stream',1); - set_abconfig($uid,$xchan_hash,'their_perms','republish',1); - } - if($r) { $abook_instance = $r[0]['abook_instance']; @@ -250,7 +249,7 @@ function new_contact($uid,$url,$channel,$interactive = false, $confirm = false) 'abook_channel' => intval($uid), 'abook_closeness' => intval($closeness), 'abook_xchan' => $xchan_hash, - 'abook_feed' => intval(($is_http) ? 1 : 0), + 'abook_feed' => intval(($xchan['xchan_network'] === 'rss') ? 1 : 0), 'abook_created' => datetime_convert(), 'abook_updated' => datetime_convert(), 'abook_instance' => (($singleton) ? z_root() : '') -- cgit v1.2.3 From 2ea482d163cc3069c042ad0070a313b5353e9eec Mon Sep 17 00:00:00 2001 From: git-marijus Date: Tue, 1 Aug 2017 23:20:39 +0200 Subject: finally fix recursive attachments permissions --- include/attach.php | 133 +++++++++++++++++++++++++++++++---------------------- 1 file changed, 79 insertions(+), 54 deletions(-) (limited to 'include') diff --git a/include/attach.php b/include/attach.php index cfea047ef..50de3ac53 100644 --- a/include/attach.php +++ b/include/attach.php @@ -1598,7 +1598,10 @@ function file_activity($channel_id, $object, $allow_cid, $allow_gid, $deny_cid, $folder_hash = $object['folder']; - $r_perms = recursive_activity_recipients($arr_allow_cid, $arr_allow_gid, $arr_deny_cid, $arr_deny_gid, $folder_hash); + $r_perms = attach_recursive_perms($arr_allow_cid, $arr_allow_gid, $arr_deny_cid, $arr_deny_gid, $folder_hash); + + if($r_perms === false) //nobody has recursive perms - nobody must be notified + return; //split up returned perms $arr_allow_cid = $r_perms['allow_cid']; @@ -1761,7 +1764,7 @@ function get_file_activity_object($channel_id, $hash, $cloudpath) { } /** - * @brief Returns array of channels which have recursive permission for a file + * @brief Returns recursive permissions array or false if nobody has recursive permissions * * @param array $arr_allow_cid * @param array $arr_allow_gid @@ -1769,19 +1772,20 @@ function get_file_activity_object($channel_id, $hash, $cloudpath) { * @param array $arr_deny_gid * @param string $folder_hash */ -function recursive_activity_recipients($arr_allow_cid, $arr_allow_gid, $arr_deny_cid, $arr_deny_gid, $folder_hash) { +function attach_recursive_perms($arr_allow_cid, $arr_allow_gid, $arr_deny_cid, $arr_deny_gid, $folder_hash) { $ret = array(); $parent_arr = array(); $count_values = array(); $poster = App::get_observer(); - //turn allow_gid into allow_cid's - foreach($arr_allow_gid as $gid) { - $in_group = group_get_members($gid); + //lookup all channels in sharee group and add them to sharee $arr_allow_cid + if($arr_allow_gid) { + $in_group = expand_groups($arr_allow_gid); $arr_allow_cid = array_unique(array_merge($arr_allow_cid, $in_group)); } + //count existing parent folders - we will compare to that count later $count = 0; while($folder_hash) { $x = q("SELECT allow_cid, allow_gid, deny_cid, deny_gid, folder FROM attach WHERE hash = '%s' LIMIT 1", @@ -1790,30 +1794,20 @@ function recursive_activity_recipients($arr_allow_cid, $arr_allow_gid, $arr_deny //only process private folders if($x[0]['allow_cid'] || $x[0]['allow_gid'] || $x[0]['deny_cid'] || $x[0]['deny_gid']) { - $parent_arr['allow_cid'][] = expand_acl($x[0]['allow_cid']); $parent_arr['allow_gid'][] = expand_acl($x[0]['allow_gid']); - - /** - * @TODO should find a much better solution for the allow_cid <-> allow_gid problem. - * Do not use allow_gid for now. Instead lookup the members of the group directly and add them to allow_cid. - * */ - if($parent_arr['allow_gid']) { - foreach($parent_arr['allow_gid'][$count] as $gid) { - $in_group = group_get_members($gid); - $parent_arr['allow_cid'][$count] = array_unique(array_merge($parent_arr['allow_cid'][$count], $in_group)); - } - } - $parent_arr['deny_cid'][] = expand_acl($x[0]['deny_cid']); $parent_arr['deny_gid'][] = expand_acl($x[0]['deny_gid']); + //this is the number of all existing parent folders - we will compare to that count later $count++; } $folder_hash = $x[0]['folder']; } + //logger(EOL . 'parent_arr: ' . print_r($parent_arr,true)); + //if none of the parent folders is private just return file perms if(!$parent_arr['allow_cid'] && !$parent_arr['allow_gid'] && !$parent_arr['deny_cid'] && !$parent_arr['deny_gid']) { $ret['allow_gid'] = $arr_allow_gid; @@ -1824,7 +1818,7 @@ function recursive_activity_recipients($arr_allow_cid, $arr_allow_gid, $arr_deny return $ret; } - //if there are no perms on the file we get them from the first parent folder + //if there are no perms on the file we will work with the perms from the first parent folder if(!$arr_allow_cid && !$arr_allow_gid && !$arr_deny_cid && !$arr_deny_gid) { $arr_allow_cid = $parent_arr['allow_cid'][0]; $arr_allow_gid = $parent_arr['allow_gid'][0]; @@ -1832,52 +1826,83 @@ function recursive_activity_recipients($arr_allow_cid, $arr_allow_gid, $arr_deny $arr_deny_gid = $parent_arr['deny_gid'][0]; } - //allow_cid - $r_arr_allow_cid = false; - foreach ($parent_arr['allow_cid'] as $folder_arr_allow_cid) { - foreach ($folder_arr_allow_cid as $ac_hash) { - $count_values[$ac_hash]++; + + /*** + * + * check if sharee has perms for all parent folders + * + ***/ + + $r_arr_allow_cid = []; + + if($parent_arr['allow_cid']) { + //check sharee arr_allow_cid against allow_cid of all parent folders + foreach($parent_arr['allow_cid'] as $folder_arr_allow_cid) { + foreach($folder_arr_allow_cid as $ac_hash) { + $count_values[$ac_hash]++; + } } - } - foreach ($arr_allow_cid as $fac_hash) { - if($count_values[$fac_hash] == $count) - $r_arr_allow_cid[] = $fac_hash; + foreach($arr_allow_cid as $fac_hash) { + if($count_values[$fac_hash] == $count) + $r_arr_allow_cid[] = $fac_hash; + } + //logger(EOL . 'r_arr_allow_cid: ' . print_r($r_arr_allow_cid,true)); } - //allow_gid - $r_arr_allow_gid = false; - foreach ($parent_arr['allow_gid'] as $folder_arr_allow_gid) { - foreach ($folder_arr_allow_gid as $ag_hash) { - $count_values[$ag_hash]++; + if($parent_arr['allow_gid']) { + //check sharee arr_allow_cid against members of allow_gid of all parent folders + foreach($parent_arr['allow_gid'] as $folder_arr_allow_gid) { + //get the group members + $folder_arr_allow_cid = expand_groups($folder_arr_allow_gid); + foreach($folder_arr_allow_cid as $ac_hash) { + $count_values[$ac_hash]++; + } } - } - foreach ($arr_allow_gid as $fag_hash) { - if($count_values[$fag_hash] == $count) - $r_arr_allow_gid[] = $fag_hash; + foreach($arr_allow_cid as $fac_hash) { + if($count_values[$fac_hash] == $count) + $r_arr_allow_cid[] = $fac_hash; + } + //logger(EOL . 'groups - r_arr_allow_cid: ' . print_r($r_arr_allow_cid,true)); } - //deny_gid - foreach($parent_arr['deny_gid'] as $folder_arr_deny_gid) { - $r_arr_deny_gid = array_merge($arr_deny_gid, $folder_arr_deny_gid); - } - $r_arr_deny_gid = array_unique($r_arr_deny_gid); + + /*** + * + * check if sharee is denied somewhere in parent folders and deny him if so + * + ***/ //deny_cid - foreach($parent_arr['deny_cid'] as $folder_arr_deny_cid) { - $r_arr_deny_cid = array_merge($arr_deny_cid, $folder_arr_deny_cid); + $r_arr_deny_cid = []; + + if($parent_arr['deny_cid']) { + foreach($parent_arr['deny_cid'] as $folder_arr_deny_cid) { + $r_arr_deny_cid = array_merge($arr_deny_cid, $folder_arr_deny_cid); + } + $r_arr_deny_cid = array_unique($r_arr_deny_cid); + //logger(EOL . 'r_arr_deny_cid: ' . print_r($r_arr_deny_cid,true)); } - $r_arr_deny_cid = array_unique($r_arr_deny_cid); - //if none is allowed restrict to self - if(($r_arr_allow_gid === false) && ($r_arr_allow_cid === false)) { - $ret['allow_cid'] = [$poster['xchan_hash']]; - } else { - $ret['allow_gid'] = $r_arr_allow_gid; - $ret['allow_cid'] = $r_arr_allow_cid; - $ret['deny_gid'] = $r_arr_deny_gid; - $ret['deny_cid'] = $r_arr_deny_cid; + //deny_gid + $r_arr_deny_gid = []; + + if($parent_arr['deny_cid']) { + foreach($parent_arr['deny_gid'] as $folder_arr_deny_gid) { + $r_arr_deny_gid = array_merge($arr_deny_gid, $folder_arr_deny_gid); + } + $r_arr_deny_gid = array_unique($r_arr_deny_gid); + //logger(EOL . 'r_arr_deny_gid: ' . print_r($r_arr_dr_arr_deny_gideny_cid,true)); } + //if no channel is allowed return false + if(! $r_arr_allow_cid) + return false; + + $ret['allow_gid'] = []; // eventual group members are already collected in $r_arr_allow_cid + $ret['allow_cid'] = $r_arr_allow_cid; + $ret['deny_gid'] = $r_arr_deny_gid; + $ret['deny_cid'] = $r_arr_deny_cid; + return $ret; } -- cgit v1.2.3 From b4707705f15bda8c3bc4e21b7dd53ddcece69064 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Wed, 2 Aug 2017 22:11:46 -0700 Subject: minor activitypub rendering stuff --- include/bbcode.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include') diff --git a/include/bbcode.php b/include/bbcode.php index c408af35d..9f9b5c5e1 100644 --- a/include/bbcode.php +++ b/include/bbcode.php @@ -7,7 +7,7 @@ require_once('include/oembed.php'); require_once('include/event.php'); require_once('include/zot.php'); - +require_once('include/html2plain.php'); function get_bb_tag_pos($s, $name, $occurance = 1) { -- cgit v1.2.3 From 913046aa28740f91d5aa16f0bfa8c764a7a24c03 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Thu, 3 Aug 2017 04:55:56 -0700 Subject: some bb-to-markdown issues --- include/markdown.php | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) (limited to 'include') diff --git a/include/markdown.php b/include/markdown.php index 530af57a0..0cd9ab237 100644 --- a/include/markdown.php +++ b/include/markdown.php @@ -157,11 +157,11 @@ function bb_to_markdown($Text, $options = []) { * Transform #tags, strip off the [url] and replace spaces with underscore */ - $Text = preg_replace_callback('/#\[([zu])rl\=(\w+.*?)\](\w+.*?)\[\/[(zu)]rl\]/i', + $Text = preg_replace_callback('/#\[([zu])rl\=(.*?)\](.*?)\[\/[(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('/#\^\[([zu])rl\=(.*?)\](.*?)\[\/([zu])rl\]/i', '[$1rl=$2]$3[/$4rl]', $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); @@ -197,9 +197,6 @@ function bb_to_markdown($Text, $options = []) { // Remove empty zrl links $Text = preg_replace("/\[zrl\=\].*?\[\/zrl\]/is", "", $Text); - // escape all unconverted tags - $Text = escape_tags($Text); - $Text = trim($Text); call_hooks('bb_to_markdown', $Text); -- cgit v1.2.3 From 0085b64b2bb22cf463ec66376d06d64d5b5b5730 Mon Sep 17 00:00:00 2001 From: git-marijus Date: Sun, 6 Aug 2017 21:40:39 +0200 Subject: consolidate disable_discover_tab config if it was not yet set to either 1 or 0 in DB --- include/conversation.php | 6 ++---- include/zot.php | 4 +++- 2 files changed, 5 insertions(+), 5 deletions(-) (limited to 'include') diff --git a/include/conversation.php b/include/conversation.php index 1c1a4479d..ec887fc6c 100644 --- a/include/conversation.php +++ b/include/conversation.php @@ -1622,11 +1622,9 @@ function network_tabs() { // tabs $tabs = array(); - $d = get_config('system','disable_discover_tab'); - if($d === false) - $d = 1; + $disable_discover_tab = get_config('system','disable_discover_tab') || get_config('system','disable_discover_tab') === false; - if(! $d) { + if(! $disable_discover_tab) { $tabs[] = array( 'label' => t('Discover'), 'url' => z_root() . '/' . $cmd . '?f=&fh=1' , diff --git a/include/zot.php b/include/zot.php index 8bbc4a969..4d056ffeb 100644 --- a/include/zot.php +++ b/include/zot.php @@ -1326,8 +1326,10 @@ function public_recips($msg) { $include_sys = false; if($msg['message']['type'] === 'activity') { - if(! get_config('system','disable_discover_tab')) + $disable_discover_tab = get_config('system','disable_discover_tab') || get_config('system','disable_discover_tab') === false; + if(! $disable_discover_tab) $include_sys = true; + $perm = 'send_stream'; if(array_key_exists('flags',$msg['message']) && in_array('thread_parent', $msg['message']['flags'])) { -- cgit v1.2.3 From 037e1edb1fd2e56f776d0f86f0023141949154cf Mon Sep 17 00:00:00 2001 From: zotlabs Date: Sun, 6 Aug 2017 19:33:51 -0700 Subject: ostatus feed was missing comments --- include/feedutils.php | 2 +- include/items.php | 12 ++++-------- 2 files changed, 5 insertions(+), 9 deletions(-) (limited to 'include') diff --git a/include/feedutils.php b/include/feedutils.php index e3f899a1e..07cb79340 100644 --- a/include/feedutils.php +++ b/include/feedutils.php @@ -115,7 +115,7 @@ function get_feed_for($channel, $observer_hash, $params) { $items = items_fetch( [ - 'wall' => '1', + 'wall' => '1', 'datequery' => $params['end'], 'datequery2' => $params['begin'], 'start' => intval($params['start']), diff --git a/include/items.php b/include/items.php index 386c25922..5a0ca01c6 100755 --- a/include/items.php +++ b/include/items.php @@ -3929,8 +3929,8 @@ function items_fetch($arr,$channel = null,$observer_hash = null,$client_mode = C } } - if(intval($arr['compat']) === 1) { - $sql_extra = " AND author_xchan = owner_xchan and item_wall = 1 and item_private = 0 "; + if($channel && intval($arr['compat']) === 1) { + $sql_extra = " AND author_xchan = '" . $channel['channel_hash'] . "' and item_private = 0 "; } if ($arr['datequery']) { @@ -3940,11 +3940,6 @@ function items_fetch($arr,$channel = null,$observer_hash = null,$client_mode = C $sql_extra3 .= protect_sprintf(sprintf(" AND item.created >= '%s' ", dbesc(datetime_convert('UTC','UTC',$arr['datequery2'])))); } - if(! array_key_exists('nouveau',$arr)) { - $sql_extra2 = " AND item.parent = item.id "; -// $sql_extra3 = ''; - } - if($arr['search']) { if(strpos($arr['search'],'#') === 0) @@ -4016,7 +4011,8 @@ function items_fetch($arr,$channel = null,$observer_hash = null,$client_mode = C if($arr['item_type'] === '*') $item_restrict = ''; - if ($arr['nouveau'] && ($client_mode & CLIENT_MODE_LOAD) && $channel) { + if ((($arr['compat']) || ($arr['nouveau'] && ($client_mode & CLIENT_MODE_LOAD))) && $channel) { + // "New Item View" - show all items unthreaded in reverse created date order $items = q("SELECT item.*, item.id AS item_id FROM item -- cgit v1.2.3 From acb8eeb85323a94bed85f3118fe20c1b5c9e2e7f Mon Sep 17 00:00:00 2001 From: zotlabs Date: Wed, 9 Aug 2017 17:35:03 -0700 Subject: libxml errors --- include/conversation.php | 2 +- include/network.php | 9 +++++---- 2 files changed, 6 insertions(+), 5 deletions(-) (limited to 'include') diff --git a/include/conversation.php b/include/conversation.php index ec887fc6c..23220b390 100644 --- a/include/conversation.php +++ b/include/conversation.php @@ -537,7 +537,7 @@ function conversation($items, $mode, $update, $page_mode = 'traditional', $prepa } elseif ($mode === 'photos') { - $profile_onwer = App::$profile['profile_uid']; + $profile_owner = App::$profile['profile_uid']; $page_writeable = ($profile_owner == local_channel()); $live_update_div = '
    ' . "\r\n"; // for photos we've already formatted the top-level item (the photo) diff --git a/include/network.php b/include/network.php index fe9a9aa2b..5f814ef32 100644 --- a/include/network.php +++ b/include/network.php @@ -671,11 +671,12 @@ function parse_xml_string($s,$strict = true) { libxml_use_internal_errors(true); $x = @simplexml_load_string($s2); - if(! $x) { + if($x === false) { logger('libxml: parse: error: ' . $s2, LOGGER_DATA); - foreach(libxml_get_errors() as $err) - logger('libxml: parse: ' . $err->code." at ".$err->line.":".$err->column." : ".$err->message, LOGGER_DATA); - + foreach(libxml_get_errors() as $err) { + logger('libxml: parse: ' . $err->code . ' at ' . $err->line + . ':' . $err->column . ' : ' . $err->message, LOGGER_DATA); + } libxml_clear_errors(); } -- cgit v1.2.3 From ecfb608518df223986c95b6405314f829bbf4878 Mon Sep 17 00:00:00 2001 From: git-marijus Date: Thu, 10 Aug 2017 11:41:00 +0200 Subject: do not show channel manager and nav channel select if we are in a delegate session --- include/nav.php | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'include') diff --git a/include/nav.php b/include/nav.php index cd32126a1..2004f6ae3 100644 --- a/include/nav.php +++ b/include/nav.php @@ -34,9 +34,11 @@ EOT; intval($channel['channel_id']) ); - $chans = q("select channel_name, channel_id from channel where channel_account_id = %d and channel_removed = 0 order by channel_name ", - intval(get_account_id()) - ); + if(! $_SESSION['delegate']) { + $chans = q("select channel_name, channel_id from channel where channel_account_id = %d and channel_removed = 0 order by channel_name ", + intval(get_account_id()) + ); + } } elseif(remote_channel()) $observer = App::get_observer(); @@ -196,7 +198,9 @@ EOT; $nav['all_events']['all']=array('events', t('View events'), "", ""); $nav['all_events']['mark'] = array('', t('Mark all events seen'), '',''); - $nav['manage'] = array('manage', t('Channel Manager'), "", t('Manage Your Channels'),'manage_nav_btn'); + if(! $_SESSION['delegate']) { + $nav['manage'] = array('manage', t('Channel Manager'), "", t('Manage Your Channels'),'manage_nav_btn'); + } $nav['settings'] = array('settings', t('Settings'),"", t('Account/Channel Settings'),'settings_nav_btn'); -- cgit v1.2.3