From 68bdd26426269ff641ef97bdecb3d2cff38fb6b5 Mon Sep 17 00:00:00 2001 From: Mario Vavti Date: Tue, 13 Dec 2016 10:09:26 +0100 Subject: simplify wikilist widget --- include/widgets.php | 93 +++++++---------------------------------------------- 1 file changed, 11 insertions(+), 82 deletions(-) (limited to 'include') diff --git a/include/widgets.php b/include/widgets.php index 4cb8f8372..f24bb488b 100644 --- a/include/widgets.php +++ b/include/widgets.php @@ -898,87 +898,17 @@ function widget_chatroom_members() { } function widget_wiki_list($arr) { - - require_once("include/wiki.php"); - $channel = null; - if (argc() < 2 && local_channel()) { - // This should not occur because /wiki should redirect to /wiki/channel ... - $channel = \App::get_channel(); - } else { - $channel = channelx_by_nick(argv(1)); // Channel being viewed by observer - } - if (!$channel) { - return ''; - } - // init() should have forced the URL to redirect to /wiki/channel so assume argc() > 1 - $nick = argv(1); - $owner = channelx_by_nick($nick); // The channel who owns the wikis being viewed - // Determine if the observer is the channel owner so the ACL dialog can be populated - if (local_channel() === intval($owner['channel_id'])) { - - // Obtain the default permission settings of the channel - $owner_acl = array( - 'allow_cid' => $owner['channel_allow_cid'], - 'allow_gid' => $owner['channel_allow_gid'], - 'deny_cid' => $owner['channel_deny_cid'], - 'deny_gid' => $owner['channel_deny_gid'] - ); - // Initialize the ACL to the channel default permissions - $x = array( - 'lockstate' => (( $owner['channel_allow_cid'] || - $owner['channel_allow_gid'] || - $owner['channel_deny_cid'] || - $owner['channel_deny_gid']) ? 'lock' : 'unlock' - ), - 'acl' => populate_acl($owner_acl), - 'allow_cid' => acl2json($owner_acl['allow_cid']), - 'allow_gid' => acl2json($owner_acl['allow_gid']), - 'deny_cid' => acl2json($owner_acl['deny_cid']), - 'deny_gid' => acl2json($owner_acl['deny_gid']), - 'bang' => '' - ); - } else { - // Not the channel owner - $owner_acl = $x = array(); - } - if(argc()>1) { - $activeWikiURLname = argv(2); - } else { - $activeWikiURLname = ''; - } - logger($activeWikiURLname, LOGGER_DEBUG); - $wikis = wiki_list($channel, get_observer_hash()); - foreach($wikis['wikis'] as &$w) { - if($w['urlName'] === $activeWikiURLname) { - $w['active'] = true; - } else { - $w['active'] = false; - } - } - if ($wikis) { - return replace_macros(get_markup_template('wikilist_widget.tpl'), array( - '$header' => t('Wiki List'), - '$channel' => $channel['channel_address'], - '$wikis' => $wikis['wikis'], - // If the observer is the local channel owner, show the wiki controls - '$owner' => ((local_channel() && local_channel() === intval(\App::$profile['uid'])) ? true : false), - '$edit' => t('Edit'), - '$download' => t('Download'), - '$view' => t('View'), - '$addnew' => t('Create new wiki'), - '$create' => t('Create'), - '$wikiName' => array('wikiName', t('Wiki name')), - '$lockstate' => $x['lockstate'], - '$acl' => $x['acl'], - '$allow_cid' => $x['allow_cid'], - '$allow_gid' => $x['allow_gid'], - '$deny_cid' => $x['deny_cid'], - '$deny_gid' => $x['deny_gid'], - '$bang' => $x['bang'], - '$notify' => array('postVisible', t('Send notification'), '', '', array(t('No'), t('Yes'))) - )); - } - return ''; + require_once("include/wiki.php"); + $channel = channelx_by_n(App::$profile_uid); + $wikis = wiki_list($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) { @@ -1573,7 +1503,6 @@ function widget_tasklist($arr) { function widget_helpindex($arr) { $o .= '
'; - //$o .= '

' . t('Documentation') . '

'; $level_0 = get_help_content('sitetoc'); if(! $level_0) -- cgit v1.2.3 From 0927af40c36083f95c5833971e07646f63d073cc Mon Sep 17 00:00:00 2001 From: Mario Vavti Date: Tue, 13 Dec 2016 11:14:22 +0100 Subject: bring lockview to wikilist --- include/wiki.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'include') diff --git a/include/wiki.php b/include/wiki.php index 30685a0bf..332d4efe0 100644 --- a/include/wiki.php +++ b/include/wiki.php @@ -14,12 +14,13 @@ function wiki_list($channel, $observer_hash) { intval($channel['channel_id']) ); if($wikis) { - foreach($wikis as &$w) { + foreach($wikis as &$w) { $w['rawName'] = get_iconfig($w, 'wiki', 'rawName'); $w['htmlName'] = get_iconfig($w, 'wiki', 'htmlName'); $w['urlName'] = get_iconfig($w, 'wiki', 'urlName'); $w['path'] = get_iconfig($w, 'wiki', 'path'); $w['mimeType'] = get_iconfig($w, 'wiki', 'mimeType'); + $w['lock'] = (($w['allow_cid'] || $w['allow_gid'] || $w['deny_cid'] || $w['deny_gid']) ? true : false); } } // TODO: query db for wikis the observer can access. Return with two lists, for read and write access -- cgit v1.2.3 From c4a9b61da6a86ca58a850967a81d7e4b39a482f6 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Tue, 13 Dec 2016 16:34:08 -0800 Subject: restructuring include/message for mail preview --- include/message.php | 76 +++++++++++++++++++++++++++++++---------------------- 1 file changed, 44 insertions(+), 32 deletions(-) (limited to 'include') diff --git a/include/message.php b/include/message.php index 7cbea3c6b..95d8d9720 100644 --- a/include/message.php +++ b/include/message.php @@ -8,7 +8,7 @@ require_once('include/attach.php'); // send a private message -function send_message($uid = 0, $recipient='', $body='', $subject='', $replyto='',$expires = ''){ +function send_message($uid = 0, $recipient = '', $body = '', $subject = '', $replyto = '', $expires = NULL_DATE) { $ret = array('success' => false); $is_reply = false; @@ -16,6 +16,49 @@ function send_message($uid = 0, $recipient='', $body='', $subject='', $replyto=' $a = get_app(); $observer_hash = get_observer_hash(); + 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)) { + $attachments = array(); + foreach($match[2] as $mtch) { + $hash = substr($mtch,0,strpos($mtch,',')); + $rev = intval(substr($mtch,strpos($mtch,','))); + $r = attach_by_hash_nodata($hash,get_observer_hash(),$rev); + if($r['success']) { + $attachments[] = array( + 'href' => z_root() . '/attach/' . $r['data']['hash'], + 'length' => $r['data']['filesize'], + 'type' => $r['data']['filetype'], + 'title' => urlencode($r['data']['filename']), + 'revision' => $r['data']['revision'] + ); + } + $body = trim(str_replace($match[1],'',$body)); + } + } + + $jattach = (($attachments) ? json_encode($attachments) : ''); + + + if($preview) { + + + + + + + + + + + } + + + + if(! $recipient) { $ret['message'] = t('No recipient provided.'); return $ret; @@ -24,12 +67,6 @@ function send_message($uid = 0, $recipient='', $body='', $subject='', $replyto=' if(! strlen($subject)) $subject = t('[no subject]'); -// if(! $expires) -// $expires = NULL_DATE; -// else -// $expires = datetime_convert(date_default_timezone_get(),'UTC',$expires); - - if($uid) { $r = q("select * from channel where channel_id = %d limit 1", intval($uid) @@ -156,31 +193,6 @@ function send_message($uid = 0, $recipient='', $body='', $subject='', $replyto=' $match = false; - 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)) { - $attachments = array(); - foreach($match[2] as $mtch) { - $hash = substr($mtch,0,strpos($mtch,',')); - $rev = intval(substr($mtch,strpos($mtch,','))); - $r = attach_by_hash_nodata($hash,get_observer_hash(),$rev); - if($r['success']) { - $attachments[] = array( - 'href' => z_root() . '/attach/' . $r['data']['hash'], - 'length' => $r['data']['filesize'], - 'type' => $r['data']['filetype'], - 'title' => urlencode($r['data']['filename']), - 'revision' => $r['data']['revision'] - ); - } - $body = trim(str_replace($match[1],'',$body)); - } - } - - $jattach = (($attachments) ? json_encode($attachments) : ''); if($subject) $subject = str_rot47(base64url_encode($subject)); -- cgit v1.2.3 From 66a53c6d3c5851d7f9db3aa9bc6bb3cb677394b7 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Tue, 13 Dec 2016 18:43:47 -0800 Subject: add plugin hook to zot_best_algorithm() --- include/zot.php | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'include') diff --git a/include/zot.php b/include/zot.php index c80081cc8..853c8eb9e 100644 --- a/include/zot.php +++ b/include/zot.php @@ -169,6 +169,11 @@ 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']) + return $x['result']; + if($methods) { $x = explode(',',$methods); if($x) { -- cgit v1.2.3 From 0394a3e93957b5bb6574ca95e290e414ed049404 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Tue, 13 Dec 2016 20:01:38 -0800 Subject: tag and mention handling in private mail (which required refactoring the bbcode cleanup stuff in mod_item) --- include/message.php | 54 ++++++++++++++++++++++------------------------------- include/text.php | 48 ++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 69 insertions(+), 33 deletions(-) (limited to 'include') diff --git a/include/message.php b/include/message.php index 95d8d9720..bde07afd8 100644 --- a/include/message.php +++ b/include/message.php @@ -16,6 +16,28 @@ function send_message($uid = 0, $recipient = '', $body = '', $subject = '', $rep $a = get_app(); $observer_hash = get_observer_hash(); + + if($uid) { + $r = q("select * from channel where channel_id = %d limit 1", + intval($uid) + ); + if($r) + $channel = $r[0]; + } + else { + $channel = App::get_channel(); + } + + if(! $channel) { + $ret['message'] = t('Unable to determine sender.'); + return $ret; + } + + + $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]; @@ -43,22 +65,6 @@ function send_message($uid = 0, $recipient = '', $body = '', $subject = '', $rep $jattach = (($attachments) ? json_encode($attachments) : ''); - if($preview) { - - - - - - - - - - - } - - - - if(! $recipient) { $ret['message'] = t('No recipient provided.'); return $ret; @@ -67,22 +73,6 @@ function send_message($uid = 0, $recipient = '', $body = '', $subject = '', $rep if(! strlen($subject)) $subject = t('[no subject]'); - if($uid) { - $r = q("select * from channel where channel_id = %d limit 1", - intval($uid) - ); - if($r) - $channel = $r[0]; - } - else { - $channel = App::get_channel(); - } - - if(! $channel) { - $ret['message'] = t('Unable to determine sender.'); - return $ret; - } - // look for any existing conversation structure diff --git a/include/text.php b/include/text.php index b25eb8e46..e014024c2 100644 --- a/include/text.php +++ b/include/text.php @@ -3061,4 +3061,50 @@ function create_table_from_array($table, $arr) { } return $r; -} \ No newline at end of file +} + + + +function cleanup_bbcode($body) { + + + /** + * fix naked links by passing through a callback to see if this is a hubzilla site + * (already known to us) which will get a zrl, otherwise link with url, add bookmark tag to both. + * First protect any url inside certain bbcode tags so we don't double link it. + */ + + $body = preg_replace_callback('/\[code(.*?)\[\/(code)\]/ism','\red_escape_codeblock',$body); + $body = preg_replace_callback('/\[url(.*?)\[\/(url)\]/ism','\red_escape_codeblock',$body); + $body = preg_replace_callback('/\[zrl(.*?)\[\/(zrl)\]/ism','\red_escape_codeblock',$body); + + + $body = preg_replace_callback("/([^\]\='".'"'."\/]|^|\#\^)(https?\:\/\/[a-zA-Z0-9\:\/\-\?\&\;\.\=\@\_\~\#\%\$\!\\ ++\,\(\)]+)/ism", 'nakedoembed', $body); + $body = preg_replace_callback("/([^\]\='".'"'."\/]|^|\#\^)(https?\:\/\/[a-zA-Z0-9\:\/\-\?\&\;\.\=\@\_\~\#\%\$\!\\ ++\,\(\)]+)/ism", '\red_zrl_callback', $body); + + $body = preg_replace_callback('/\[\$b64zrl(.*?)\[\/(zrl)\]/ism','\red_unescape_codeblock',$body); + $body = preg_replace_callback('/\[\$b64url(.*?)\[\/(url)\]/ism','\red_unescape_codeblock',$body); + $body = preg_replace_callback('/\[\$b64code(.*?)\[\/(code)\]/ism','\red_unescape_codeblock',$body); + + + // fix any img tags that should be zmg + + $body = preg_replace_callback('/\[img(.*?)\](.*?)\[\/img\]/ism','\red_zrlify_img_callback',$body); + + + $body = bb_translate_video($body); + + /** + * Fold multi-line [code] sequences + */ + + $body = preg_replace('/\[\/code\]\s*\[code\]/ism',"\n",$body); + + $body = scale_external_images($body,false); + + + return $body; + +} -- cgit v1.2.3 From cbffd32d8ea14d38da65b646c205dc6518eeb7e0 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Tue, 13 Dec 2016 20:05:36 -0800 Subject: use absolute namespace in case this gets moved --- include/text.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include') diff --git a/include/text.php b/include/text.php index e014024c2..593822bc7 100644 --- a/include/text.php +++ b/include/text.php @@ -3080,7 +3080,7 @@ function cleanup_bbcode($body) { $body = preg_replace_callback("/([^\]\='".'"'."\/]|^|\#\^)(https?\:\/\/[a-zA-Z0-9\:\/\-\?\&\;\.\=\@\_\~\#\%\$\!\\ -+\,\(\)]+)/ism", 'nakedoembed', $body); ++\,\(\)]+)/ism", '\nakedoembed', $body); $body = preg_replace_callback("/([^\]\='".'"'."\/]|^|\#\^)(https?\:\/\/[a-zA-Z0-9\:\/\-\?\&\;\.\=\@\_\~\#\%\$\!\\ +\,\(\)]+)/ism", '\red_zrl_callback', $body); -- cgit v1.2.3 From 028935a318e5848542faa551f3d39bbe8b365447 Mon Sep 17 00:00:00 2001 From: Mario Vavti Date: Wed, 14 Dec 2016 11:55:52 +0100 Subject: wiki: do not show revert buttons if we do not have write perms and minor cleanup --- include/widgets.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'include') diff --git a/include/widgets.php b/include/widgets.php index f24bb488b..919ea58a0 100644 --- a/include/widgets.php +++ b/include/widgets.php @@ -958,7 +958,8 @@ function widget_wiki_page_history($arr) { $pageHistory = wiki_page_history(array('resource_id' => $resource_id, 'pageUrlName' => $pageUrlName)); return replace_macros(get_markup_template('wiki_page_history.tpl'), array( - '$pageHistory' => $pageHistory['history'] + '$pageHistory' => $pageHistory['history'], + '$permsWrite' => $arr['permsWrite'] )); } -- cgit v1.2.3 From a7af6d8a3cabbf5fc87efe395ed3b5b6c0bfc655 Mon Sep 17 00:00:00 2001 From: Mario Vavti Date: Wed, 14 Dec 2016 13:17:33 +0100 Subject: fix regex --- include/bb2diaspora.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include') diff --git a/include/bb2diaspora.php b/include/bb2diaspora.php index e22b6a7dd..ffb157b2f 100644 --- a/include/bb2diaspora.php +++ b/include/bb2diaspora.php @@ -149,7 +149,7 @@ function markdown_to_bb($s, $use_zrl = false) { $s = html2bbcode($s); - $s = preg_replace("/\[([uz])rl=(.*?)\]\[\/[uz]rl\]/ism",'[$1rl=$2]$2[/$1rl]',$s); + $s = preg_replace("/\[([uz])rl=(.*?)\]\[\[uz]rl\]/ism",'[$1rl=$2]$2[/$1rl]',$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); -- cgit v1.2.3 From 63efbdffe6ef653e1556a7b34ea59b75b234e759 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Wed, 14 Dec 2016 14:27:00 -0800 Subject: markdown regex --- include/bb2diaspora.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'include') diff --git a/include/bb2diaspora.php b/include/bb2diaspora.php index ffb157b2f..87a8551ae 100644 --- a/include/bb2diaspora.php +++ b/include/bb2diaspora.php @@ -130,6 +130,9 @@ function markdown_to_bb($s, $use_zrl = false) { $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 $s = preg_replace_callback('/\@\{(.+?)\; (.+?)\@(.+?)\}\+/','diaspora_mention_callback',$s); @@ -149,8 +152,6 @@ function markdown_to_bb($s, $use_zrl = false) { $s = html2bbcode($s); - $s = preg_replace("/\[([uz])rl=(.*?)\]\[\[uz]rl\]/ism",'[$1rl=$2]$2[/$1rl]',$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); -- cgit v1.2.3 From 00fc66d8e8553e3c2633f04401d733547b975b82 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Wed, 14 Dec 2016 20:51:10 -0800 Subject: postgres is picky about this stuff --- include/widgets.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'include') diff --git a/include/widgets.php b/include/widgets.php index 919ea58a0..ebdb47113 100644 --- a/include/widgets.php +++ b/include/widgets.php @@ -1406,12 +1406,12 @@ function widget_forums($arr) { $xf = false; - $x1 = q("select xchan from abconfig where chan = %d and cat = 'their_perms' and k = 'send_stream' and v = 0", + $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 . ") ", + $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) -- cgit v1.2.3 From f67acc82cfd3c58f310713601ec1c67f2a5e3ca9 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Thu, 15 Dec 2016 13:45:27 -0800 Subject: html2plain warnings --- include/html2plain.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include') diff --git a/include/html2plain.php b/include/html2plain.php index 2f5be7f69..979354079 100644 --- a/include/html2plain.php +++ b/include/html2plain.php @@ -113,7 +113,7 @@ function html2plain($html, $wraplength = 75, $compact = false) $xpath = new DomXPath($doc); $list = $xpath->query("//pre"); foreach ($list as $node) { - $node->nodeValue = str_replace("\n", "\r", $node->nodeValue); + $node->nodeValue = str_replace("\n", "\r", htmlspecialchars($node->nodeValue)); } $message = $doc->saveHTML(); -- cgit v1.2.3 From 95485a0da21553a44e10a2e17fb47fc910523f89 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Thu, 15 Dec 2016 16:02:52 -0800 Subject: z_fetch_url incorrect variable --- include/network.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'include') diff --git a/include/network.php b/include/network.php index fe360c425..451ce12a1 100644 --- a/include/network.php +++ b/include/network.php @@ -59,7 +59,7 @@ function z_fetch_url($url, $binary = false, $redirects = 0, $opts = array()) { if(x($opts,'filep')) { @curl_setopt($ch, CURLOPT_FILE, $opts['filep']); - @curl_setopt($ch, CURLOPT_HEADER, $false); + @curl_setopt($ch, CURLOPT_HEADER, false); } if(x($opts,'upload')) @@ -87,7 +87,7 @@ function z_fetch_url($url, $binary = false, $redirects = 0, $opts = array()) { @curl_setopt($ch, CURLOPT_TIMEOUT, $opts['timeout']); } else { - $curl_time = intval(get_config('system','curl_timeout')); + $curl_time = intval(@get_config('system','curl_timeout')); @curl_setopt($ch, CURLOPT_TIMEOUT, (($curl_time !== false) ? $curl_time : 60)); } @@ -107,7 +107,7 @@ function z_fetch_url($url, $binary = false, $redirects = 0, $opts = array()) { @curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, ((x($opts,'novalidate') && intval($opts['novalidate'])) ? false : true)); - $prx = get_config('system','proxy'); + $prx = @get_config('system','proxy'); if(strlen($prx)) { @curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, 1); @curl_setopt($ch, CURLOPT_PROXY, $prx); @@ -226,7 +226,7 @@ function z_post_url($url,$params, $redirects = 0, $opts = array()) { if(x($opts,'filep')) { @curl_setopt($ch, CURLOPT_FILE, $opts['filep']); - @curl_setopt($ch, CURLOPT_HEADER, $false); + @curl_setopt($ch, CURLOPT_HEADER, false); } if(x($opts,'headers')) { @@ -246,7 +246,7 @@ function z_post_url($url,$params, $redirects = 0, $opts = array()) { @curl_setopt($ch, CURLOPT_TIMEOUT, $opts['timeout']); } else { - $curl_time = intval(get_config('system','curl_timeout')); + $curl_time = intval(@get_config('system','curl_timeout')); @curl_setopt($ch, CURLOPT_TIMEOUT, (($curl_time !== false) ? $curl_time : 60)); } -- cgit v1.2.3 From 6cf17c7bcc01bfb4dc0ffc96ca921c2f6baf6942 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Thu, 15 Dec 2016 16:41:01 -0800 Subject: use array_shift - it's cleaner --- 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 81a3bd590..e47f97387 100755 --- a/include/dba/dba_driver.php +++ b/include/dba/dba_driver.php @@ -337,7 +337,7 @@ function db_concat($fld, $sep) { function q($sql) { $args = func_get_args(); - unset($args[0]); + array_shift($args); if(\DBA::$dba && \DBA::$dba->connected) { $stmt = vsprintf($sql, $args); -- cgit v1.2.3 From 92f3d863fa4a8a96d4f882a91a81d888a58230e5 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Sun, 18 Dec 2016 16:26:00 -0800 Subject: re-factor item_photo_menu - there is some room for future development, currently it was made compatible with minimal template changes --- include/conversation.php | 166 ++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 165 insertions(+), 1 deletion(-) (limited to 'include') diff --git a/include/conversation.php b/include/conversation.php index d367c27a6..af64fbb90 100644 --- a/include/conversation.php +++ b/include/conversation.php @@ -689,7 +689,8 @@ function conversation(&$a, $items, $mode, $update, $page_mode = 'traditional', $ 'id' => (($preview) ? 'P0' : $item['item_id']), 'linktitle' => sprintf( t('View %s\'s profile @ %s'), $profile_name, $profile_url), 'profile_url' => $profile_link, - 'item_photo_menu' => item_photo_menu($item), + 'thread_action_menu' => thread_action_menu($item,$mode), + 'thread_author_menu' => thread_author_menu($item,$mode), 'name' => $profile_name, 'sparkle' => $sparkle, 'lock' => $lock, @@ -960,6 +961,169 @@ function item_photo_menu($item){ return $o; } + +function thread_action_menu($item,$mode = '') { + + $menu = []; + + if((local_channel()) && local_channel() == $item['uid']) { + $menu[] = [ + 'menu' => 'view_source', + 'title' => t('View Source'), + 'icon' => 'eye', + 'action' => 'viewsrc(' . $item['id'] . '); return false;', + 'href' => '#' + ]; + + if(! in_array($mode, [ 'network-new', 'search', 'community'])) { + if($item['parent'] == $item['id'] && (get_observer_hash() != $item['author_xchan'])) { + $menu[] = [ + 'menu' => 'follow_thread', + 'title' => t('Follow Thread'), + 'icon' => 'plus', + 'action' => 'dosubthread(' . $item['id'] . '); return false;', + 'href' => '#' + ]; + } + + $menu[] = [ + 'menu' => 'unfollow_thread', + 'title' => t('Unfollow Thread'), + 'icon' => 'minus', + 'action' => 'dounsubthread(' . $item['id'] . '); return false;', + 'href' => '#' + ]; + } + + } + + + + + $args = [ 'item' => $item, 'mode' => $mode, 'menu' => $menu ]; + call_hooks('thread_action_menu', $args); + + return $args['menu']; + +} + +function thread_author_menu($item, $mode = '') { + + $menu = []; + + $local_channel = local_channel(); + + if($local_channel) { + if(! count(App::$contacts)) + load_contact_links($local_channel); + $channel = App::get_channel(); + $channel_hash = (($channel) ? $channel['channel_hash'] : ''); + } + + $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']) : ''); + + if($profile_link) { + $menu[] = [ + 'menu' => 'view_profile', + 'title' => t('View Profile'), + 'icon' => 'fw', + 'action' => '', + 'href' => $profile_link + ]; + } + + if($posts_link) { + $menu[] = [ + 'menu' => 'view_posts', + 'title' => t('Activity/Posts'), + 'icon' => 'fw', + 'action' => '', + 'href' => $posts_link + ]; + } + + if($follow_url) { + $menu[] = [ + 'menu' => 'follow', + 'title' => t('Connect'), + 'icon' => 'fw', + 'action' => '', + 'href' => $follow_url + ]; + } + + if($contact_url) { + $menu[] = [ + 'menu' => 'connedit', + 'title' => t('Edit Connection'), + 'icon' => 'fw', + 'action' => '', + 'href' => $contact_url + ]; + } + + if($pm_url) { + $menu[] = [ + 'menu' => 'prv_message', + 'title' => t('Message'), + 'icon' => 'fw', + 'action' => '', + 'href' => $pm_url + ]; + } + + if($ratings_url) { + $menu[] = [ + 'menu' => 'ratings', + 'title' => t('Ratings'), + 'icon' => 'fw', + 'action' => '', + 'href' => $ratings_url + ]; + } + + if($poke_link) { + $menu[] = [ + 'menu' => 'poke', + 'title' => t('Poke'), + 'icon' => 'fw', + 'action' => '', + 'href' => $poke_link + ]; + } + + $args = [ 'item' => $item, 'mode' => $mode, 'menu' => $menu ]; + call_hooks('thread_author_menu', $args); + + return $args['menu']; + +} + + + + + /** * @brief Checks item to see if it is one of the builtin activities (like/dislike, event attendance, consensus items, etc.) * -- cgit v1.2.3 From ca2e2f5f454bda13902f9d8e26c49635b69558e2 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Sun, 18 Dec 2016 22:33:23 -0800 Subject: deprecate bb_iframe --- include/bbcode.php | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'include') diff --git a/include/bbcode.php b/include/bbcode.php index b315255f5..32354aeda 100644 --- a/include/bbcode.php +++ b/include/bbcode.php @@ -1067,15 +1067,15 @@ function bbcode($Text, $preserve_nl = false, $tryoembed = true, $cache = false) $Text = preg_replace("/\[zaudio\](.*?)\[\/zaudio\]/", '$1', $Text); } - if ($tryoembed){ - if (strpos($Text,'[/iframe]') !== false) { - $Text = preg_replace_callback("/\[iframe\](.*?)\[\/iframe\]/ism", 'bb_iframe', $Text); - } - } else { - if (strpos($Text,'[/iframe]') !== false) { - $Text = preg_replace("/\[iframe\](.*?)\[\/iframe\]/ism", '$1', $Text); - } - } +// if ($tryoembed){ +// if (strpos($Text,'[/iframe]') !== false) { +// $Text = preg_replace_callback("/\[iframe\](.*?)\[\/iframe\]/ism", 'bb_iframe', $Text); +// } +// } else { +// if (strpos($Text,'[/iframe]') !== false) { +// $Text = preg_replace("/\[iframe\](.*?)\[\/iframe\]/ism", '$1', $Text); +// } +// } // oembed tag $Text = oembed_bbcode2html($Text); -- cgit v1.2.3 From 350627988eb7813dac69450ff97f03a33e70d9f2 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Mon, 19 Dec 2016 14:35:13 -0800 Subject: zidify private mail --- include/text.php | 1 - 1 file changed, 1 deletion(-) (limited to 'include') diff --git a/include/text.php b/include/text.php index 593822bc7..d6151d8ef 100644 --- a/include/text.php +++ b/include/text.php @@ -3088,7 +3088,6 @@ function cleanup_bbcode($body) { $body = preg_replace_callback('/\[\$b64url(.*?)\[\/(url)\]/ism','\red_unescape_codeblock',$body); $body = preg_replace_callback('/\[\$b64code(.*?)\[\/(code)\]/ism','\red_unescape_codeblock',$body); - // fix any img tags that should be zmg $body = preg_replace_callback('/\[img(.*?)\](.*?)\[\/img\]/ism','\red_zrlify_img_callback',$body); -- cgit v1.2.3 From 1798ebd39524354a6955e871ce231c908f5bd0cc Mon Sep 17 00:00:00 2001 From: zotlabs Date: Mon, 19 Dec 2016 15:38:42 -0800 Subject: improve oembed cache security --- include/oembed.php | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) (limited to 'include') diff --git a/include/oembed.php b/include/oembed.php index eb7b76437..36395cfbc 100755 --- a/include/oembed.php +++ b/include/oembed.php @@ -104,7 +104,7 @@ function oembed_action($embedurl) { function oembed_process($url) { $j = oembed_fetch_url($url); - logger('oembed_process: ' . print_r($j,true)); + logger('oembed_process: ' . print_r($j,true), LOGGER_DATA, LOG_DEBUG); if($j && $j['type'] !== 'error') return '[embed]' . $url . '[/embed]'; return false; @@ -135,19 +135,15 @@ function oembed_fetch_url($embedurl){ // we should try to cache this and avoid a lookup on each render $zrl = is_matrix_url($embedurl); + $furl = ((local_channel() && $zrl) ? zid($embedurl) : $embedurl); + if($action !== 'block') { - $txt = Zlib\Cache::get('[' . App::$videowidth . '] ' . $embedurl); + $txt = Zlib\Cache::get('[' . App::$videowidth . '] ' . $furl); } if(is_null($txt)) { $txt = ""; - $furl = $embedurl; - - logger('local_channel: ' . local_channel()); - - if(local_channel() && $zrl) - $furl = zid($furl); if ($action !== 'block') { // try oembed autodiscovery @@ -206,11 +202,10 @@ function oembed_fetch_url($embedurl){ //save in cache if(! get_config('system','oembed_cache_disable')) - Zlib\Cache::set('[' . App::$videowidth . '] ' . $embedurl,$txt); + Zlib\Cache::set('[' . App::$videowidth . '] ' . $furl, $txt); } - $j = json_decode($txt,true); if(! $j) -- cgit v1.2.3 From 231b70b987bb76a27cc8c4a36b128b4fef2178ce Mon Sep 17 00:00:00 2001 From: zotlabs Date: Mon, 19 Dec 2016 16:06:49 -0800 Subject: call zidify_links() when formatting bbcode for internal consumption --- include/channel.php | 2 +- include/conversation.php | 4 ++-- include/event.php | 12 ++++++------ include/help.php | 4 ++-- include/menu.php | 2 +- 5 files changed, 12 insertions(+), 12 deletions(-) (limited to 'include') diff --git a/include/channel.php b/include/channel.php index 4fc873402..caf3ded71 100644 --- a/include/channel.php +++ b/include/channel.php @@ -1218,7 +1218,7 @@ function advanced_profile(&$a) { $profile['marital'] = array( t('Status:'), App::$profile['marital']); if(App::$profile['partner']) - $profile['marital']['partner'] = bbcode(App::$profile['partner']); + $profile['marital']['partner'] = zidify_links(bbcode(App::$profile['partner'])); if(strlen(App::$profile['howlong']) && App::$profile['howlong'] > NULL_DATE) { $profile['howlong'] = relative_date(App::$profile['howlong'], t('for %1$d %2$s')); diff --git a/include/conversation.php b/include/conversation.php index af64fbb90..1673bc9fb 100644 --- a/include/conversation.php +++ b/include/conversation.php @@ -1564,7 +1564,7 @@ function format_location($item) { if(strpos($item['location'],'#') === 0) { $location = substr($item['location'],1); - $location = ((strpos($location,'[') !== false) ? bbcode($location) : $location); + $location = ((strpos($location,'[') !== false) ? zidify_links(bbcode($location)) : $location); } else { $locate = array('location' => $item['location'], 'coord' => $item['coord'], 'html' => ''); @@ -1616,7 +1616,7 @@ function prepare_page($item) { '$author' => (($naked) ? '' : $item['author']['xchan_name']), '$auth_url' => (($naked) ? '' : zid($item['author']['xchan_url'])), '$date' => (($naked) ? '' : datetime_convert('UTC', date_default_timezone_get(), $item['created'], 'Y-m-d H:i')), - '$title' => smilies(bbcode($item['title'])), + '$title' => zidify_links(smilies(bbcode($item['title']))), '$body' => $body['html'], '$preview' => $preview, '$link' => $link, diff --git a/include/event.php b/include/event.php index cbee2b759..8fb060a40 100644 --- a/include/event.php +++ b/include/event.php @@ -25,7 +25,7 @@ function format_event_html($ev) { $o = '
' . "\r\n"; - $o .= '

 ' . bbcode($ev['summary']) . '

' . "\r\n"; + $o .= '

 ' . zidify_links(smilies(bbcode($ev['summary']))) . '

' . "\r\n"; $o .= '
' . t('Starts:') . ' ' . "\r\n"; + $o .= '
' . zidify_links(smilies(bbcode($ev['description']))) . '
' . "\r\n"; if(strlen($ev['location'])) $o .= '
' . t('Location:') . ' ' - . bbcode($ev['location']) + . zidify_links(smilies(bbcode($ev['location']))) . '
' . "\r\n"; $o .= '
' . "\r\n"; @@ -69,7 +69,7 @@ function format_event_obj($jobject) { $bd_format = t('l F d, Y \@ g:i A'); // Friday January 18, 2011 @ 8:01 AM $event['header'] = replace_macros(get_markup_template('event_item_header.tpl'),array( - '$title' => bbcode($object['title']), + '$title' => zidify_links(smilies(bbcode($object['title']))), '$dtstart_label' => t('Starts:'), '$dtstart_title' => datetime_convert('UTC', 'UTC', $object['dtstart'], (($object['adjust']) ? ATOM_TIME : 'Y-m-d\TH:i:s' )), '$dtstart_dt' => (($object['adjust']) ? day_translate(datetime_convert('UTC', date_default_timezone_get(), $object['dtstart'] , $bd_format )) : day_translate(datetime_convert('UTC', 'UTC', $object['dtstart'] , $bd_format))), @@ -80,9 +80,9 @@ function format_event_obj($jobject) { )); $event['content'] = replace_macros(get_markup_template('event_item_content.tpl'),array( - '$description' => bbcode($object['description']), + '$description' => zidify_links(smilies(bbcode($object['description']))), '$location_label' => t('Location:'), - '$location' => bbcode($object['location']) + '$location' => zidify_links(smilies(bbcode($object['location']))) )); } diff --git a/include/help.php b/include/help.php index 03d01d1a1..6e779f000 100644 --- a/include/help.php +++ b/include/help.php @@ -79,7 +79,7 @@ function get_help_content($tocpath = false) { } if($doctype === 'bbcode') { require_once('include/bbcode.php'); - $content = bbcode($text); + $content = zidify_links(bbcode($text)); // bbcode retargets external content to new windows. This content is internal. $content = str_replace(' target="_blank"', '', $content); } @@ -95,7 +95,7 @@ function preg_callback_help_include($matches) { $include = str_replace($matches[0],load_doc_file($matches[1]),$matches[0]); if(preg_match('/\.bb$/', $matches[1]) || preg_match('/\.txt$/', $matches[1])) { require_once('include/bbcode.php'); - $include = bbcode($include); + $include = zidify_links(bbcode($include)); $include = str_replace(' target="_blank"','',$include); } elseif(preg_match('/\.md$/', $matches[1])) { diff --git a/include/menu.php b/include/menu.php index b54ff7f9e..4add78c39 100644 --- a/include/menu.php +++ b/include/menu.php @@ -102,7 +102,7 @@ function menu_render($menu, $class='', $edit = false, $var = array()) { if($menu['items'][$x]['mitem_flags'] & MENU_ITEM_NEWWIN) $menu['items'][$x]['newwin'] = '1'; - $menu['items'][$x]['mitem_desc'] = bbcode($menu['items'][$x]['mitem_desc']); + $menu['items'][$x]['mitem_desc'] = zidify_links(smilies(bbcode($menu['items'][$x]['mitem_desc']))); } $wrap = (($var['wrap'] === 'none') ? false : true); -- cgit v1.2.3 From d2cc7df7db2995acf628981e24013aa02d35e999 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Mon, 19 Dec 2016 18:59:40 -0800 Subject: allow tel: links on mobile devices --- include/bbcode.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'include') diff --git a/include/bbcode.php b/include/bbcode.php index 32354aeda..c7bee6f97 100644 --- a/include/bbcode.php +++ b/include/bbcode.php @@ -1127,9 +1127,9 @@ function bbcode($Text, $preserve_nl = false, $tryoembed = true, $cache = false) $Text = preg_replace("/\<(.*?)(src|href)=(.*?)\&\;(.*?)\>/ism", '<$1$2=$3&$4>', $Text); // This is subtle - it's an XSS filter. It only accepts links with a protocol scheme and where - // the scheme begins with z (zhttp), h (http(s)), f (ftp), m (mailto), and named anchors. + // the scheme begins with z (zhttp), h (http(s)), f (ftp(s)), m (mailto), t (tel) and named anchors. - $Text = preg_replace("/\<(.*?)(src|href)=\"[^zhfm#](.*?)\>/ism", '<$1$2="">', $Text); + $Text = preg_replace("/\<(.*?)(src|href)=\"[^zhfmt#](.*?)\>/ism", '<$1$2="">', $Text); $Text = bb_replace_images($Text, $saved_images); -- cgit v1.2.3 From 4103344e482990d9d4936e82681fa8d92f1f564f Mon Sep 17 00:00:00 2001 From: zotlabs Date: Tue, 20 Dec 2016 16:45:12 -0800 Subject: abook_vcard first commit --- include/connections.php | 222 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 222 insertions(+) (limited to 'include') diff --git a/include/connections.php b/include/connections.php index b08d046b3..3d52d1a48 100644 --- a/include/connections.php +++ b/include/connections.php @@ -630,3 +630,225 @@ function random_profile() { return ''; } +function update_vcard($arr,$vcard = null) { + + $fn = $arr['fn']; + + if(! $vcard) { + $vcard = new \Sabre\VObject\Component\VCard([ + 'FN' => $fn, + 'N' => array_reverse(explode(' ', $fn)) + ]); + } + $org = $arr['org']; + if($org) { + $vcard->ORG = $org; + } + + $title = $arr['title']; + if($title) { + $vcard->TITLE = $title; + } + + $tel = $arr['tel']; + $tel_type = $arr['tel_type']; + if($tel) { + $i = 0; + foreach($tel as $item) { + if($item) { + $vcard->add('TEL', $item, ['type' => $tel_type[$i]]); + } + $i++; + } + } + + $email = $arr['email']; + $email_type = $arr['email_type']; + if($email) { + $i = 0; + foreach($email as $item) { + if($item) { + $vcard->add('EMAIL', $item, ['type' => $email_type[$i]]); + } + $i++; + } + } + + $impp = $arr['impp']; + $impp_type = $arr['impp_type']; + if($impp) { + $i = 0; + foreach($impp as $item) { + if($item) { + $vcard->add('IMPP', $item, ['type' => $impp_type[$i]]); + } + $i++; + } + } + + $url = $arr['url']; + $url_type = $arr['url_type']; + if($url) { + $i = 0; + foreach($url as $item) { + if($item) { + $vcard->add('URL', $item, ['type' => $url_type[$i]]); + } + $i++; + } + } + + $adr = $arr['adr']; + $adr_type = $arr['adr_type']; + + if($adr) { + $i = 0; + foreach($adr as $item) { + if($item) { + $vcard->add('ADR', $item, ['type' => $adr_type[$i]]); + } + $i++; + } + } + + $note = $arr['note']; + if($note) { + $vcard->NOTE = $note; + } + + return $vcard->serialize(); + +} + +function get_vcard_array($vc) { + + $photo = ''; + if($vc->PHOTO) { + $photo_value = strtolower($vc->PHOTO->getValueType()); // binary or uri + if($photo_value === 'binary') { + $photo_type = strtolower($vc->PHOTO['TYPE']); // mime jpeg, png or gif + $photo = 'data:image/' . $photo_type . ';base64,' . base64_encode((string)$vc->PHOTO); + } + else { + $url = parse_url((string)$vc->PHOTO); + $photo = 'data:' . $url['path']; + } + } + + $fn = ''; + if($vc->FN) { + $fn = (string) escape_tags($vc->FN); + } + + $org = ''; + if($vc->ORG) { + $org = (string) escape_tags($vc->ORG); + } + + $title = ''; + if($vc->TITLE) { + $title = (string) escape_tags($vc->TITLE); + } + + $tels = []; + if($vc->TEL) { + foreach($vc->TEL as $tel) { + $type = (($tel['TYPE']) ? vcard_translate_type((string)$tel['TYPE']) : ''); + $tels[] = [ + 'type' => $type, + 'nr' => (string) escape_tags($tel) + ]; + } + } + $emails = []; + if($vc->EMAIL) { + foreach($vc->EMAIL as $email) { + $type = (($email['TYPE']) ? vcard_translate_type((string)$email['TYPE']) : ''); + $emails[] = [ + 'type' => $type, + 'address' => (string) escape_tags($email) + ]; + } + } + + $impps = []; + if($vc->IMPP) { + foreach($vc->IMPP as $impp) { + $type = (($impp['TYPE']) ? vcard_translate_type((string)$impp['TYPE']) : ''); + $impps[] = [ + 'type' => $type, + 'address' => (string) escape_tags($impp) + ]; + } + } + + $urls = []; + if($vc->URL) { + foreach($vc->URL as $url) { + $type = (($url['TYPE']) ? vcard_translate_type((string)$url['TYPE']) : ''); + $urls[] = [ + 'type' => $type, + 'address' => (string) escape_tags($url) + ]; + } + } + + $adrs = []; + if($vc->ADR) { + foreach($vc->ADR as $adr) { + $type = (($adr['TYPE']) ? vcard_translate_type((string)$adr['TYPE']) : ''); + $adrs[] = [ + 'type' => $type, + 'address' => escape_tags($adr->getParts()) + ]; + } + } + + $note = ''; + if($vc->NOTE) { + $note = (string) escape_tags($vc->NOTE); + } + + $card = [ + 'photo' => $photo, + 'fn' => $fn, + 'org' => $org, + 'title' => $title, + 'tels' => $tels, + 'emails' => $emails, + 'impps' => $impps, + 'urls' => $urls, + 'adrs' => $adrs, + 'note' => $note + ]; + + return $card; + +} + + +function vcard_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 493aa9f20d3a48132a83b1da0c643f80c038e617 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Tue, 20 Dec 2016 18:43:20 -0800 Subject: progress on abook_vcard --- include/connections.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'include') diff --git a/include/connections.php b/include/connections.php index 3d52d1a48..ca6931601 100644 --- a/include/connections.php +++ b/include/connections.php @@ -720,7 +720,7 @@ function update_vcard($arr,$vcard = null) { } -function get_vcard_array($vc) { +function get_vcard_array($vc,$id) { $photo = ''; if($vc->PHOTO) { @@ -810,6 +810,7 @@ function get_vcard_array($vc) { } $card = [ + 'id' => $id, 'photo' => $photo, 'fn' => $fn, 'org' => $org, -- cgit v1.2.3 From a270ca51014e8bf98554bd5e8eda33a44aa60460 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Tue, 20 Dec 2016 19:31:50 -0800 Subject: allow update of fn and initial setting from channel name --- include/connections.php | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'include') diff --git a/include/connections.php b/include/connections.php index ca6931601..b85be33b2 100644 --- a/include/connections.php +++ b/include/connections.php @@ -640,6 +640,11 @@ function update_vcard($arr,$vcard = null) { 'N' => array_reverse(explode(' ', $fn)) ]); } + else { + $vcard->FN = $fn; + $vcard->N = array_reverse(explode(' ', $fn)); + } + $org = $arr['org']; if($org) { $vcard->ORG = $org; -- cgit v1.2.3 From 3d811a17feb9b3d0fd4dc09023e3b7b5fe1623ac Mon Sep 17 00:00:00 2001 From: zotlabs Date: Tue, 20 Dec 2016 23:26:31 -0800 Subject: provide call button on connections list if mobile|tablet and a phone number exists --- include/connections.php | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'include') diff --git a/include/connections.php b/include/connections.php index b85be33b2..44003bc93 100644 --- a/include/connections.php +++ b/include/connections.php @@ -858,3 +858,33 @@ function vcard_translate_type($type) { return [$type, t('Other') . ' (' . $type . ')']; } } + + +function vcard_query(&$r) { + + $arr = []; + + if($r && is_array($r) && count($r)) { + $uid = $r[0]['abook_channel']; + foreach($r as $rv) { + if($rv['abook_xchan'] && (! in_array("'" . dbesc($rv['abook_xchan']) . "'",$arr))) + $arr[] = "'" . dbesc($rv['abook_xchan']) . "'"; + } + } + + if($arr) { + $a = q("select * from abconfig where chan = %d and xchan in (" . protect_sprintf(implode(',', $arr)) . ") and cat = 'system' and k = 'vcard'", + intval($uid) + ); + if($a) { + foreach($a as $av) { + for($x = 0; $x < count($r); $x ++) { + if($r[$x]['abook_xchan'] == $av['xchan']) { + $vctmp = \Sabre\VObject\Reader::read($av['v']); + $r[$x]['vcard'] = (($vctmp) ? get_vcard_array($vctmp,$r[$x]['abook_id']) : [] ); + } + } + } + } + } +} \ No newline at end of file -- cgit v1.2.3 From 04472bd730f464aaee1ef79cf67c8b4f79f85652 Mon Sep 17 00:00:00 2001 From: Mario Vavti Date: Wed, 21 Dec 2016 11:51:24 +0100 Subject: fix a glitch in sticky-kit and comment out alt_pager() in widget_conversations since it will not work there --- include/widgets.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include') diff --git a/include/widgets.php b/include/widgets.php index ebdb47113..dde8e7cd0 100644 --- a/include/widgets.php +++ b/include/widgets.php @@ -778,7 +778,7 @@ function widget_conversations($arr) { '$messages' => $messages )); - $o .= alt_pager($a,count($r)); + //$o .= alt_pager($a,count($r)); } -- cgit v1.2.3 From f2bfdfdeddea86784ce2d17b3c35e46a1c582b79 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Wed, 21 Dec 2016 23:35:54 -0800 Subject: provide separate logging (if configured) for btlogger which is used to catch really subtle issues which don't always leave an audit trail. Similar to dbfail.out, the file btlogger.out (if it exists and is write-able) will only log these unusual situations with backtraces so we can find the culprits. --- include/bb2diaspora.php | 5 +++++ include/connections.php | 12 ++++++++++++ include/text.php | 15 ++++++++++++++- 3 files changed, 31 insertions(+), 1 deletion(-) (limited to 'include') diff --git a/include/bb2diaspora.php b/include/bb2diaspora.php index 87a8551ae..1759154f0 100644 --- a/include/bb2diaspora.php +++ b/include/bb2diaspora.php @@ -128,6 +128,11 @@ function markdown_to_bb($s, $use_zrl = false) { $s = str_replace(" ","\r",$s); $s = str_replace(" \n>","",$s); + if(is_array($s)) { + btlogger('markdown_to_bb called with array. ' . print_r($s,true), LOGGER_NORMAL, LOG_WARNING); + return ''; + } + $s = html_entity_decode($s,ENT_COMPAT,'UTF-8'); // if empty link text replace with the url diff --git a/include/connections.php b/include/connections.php index 44003bc93..31e941e95 100644 --- a/include/connections.php +++ b/include/connections.php @@ -634,6 +634,18 @@ function update_vcard($arr,$vcard = null) { $fn = $arr['fn']; + + // This isn't strictly correct and could be a cause for concern. + // 'N' => array_reverse(explode(' ', $fn)) + + + // What we really want is + // 'N' => Adams;John;Quincy;Reverend,Dr.;III + // which is a very difficult parsing problem especially if you allow + // the surname to contain spaces. The only way to be sure to get it + // right is to provide a form to input all the various fields and not + // try to extract it from the FN. + if(! $vcard) { $vcard = new \Sabre\VObject\Component\VCard([ 'FN' => $fn, diff --git a/include/text.php b/include/text.php index d6151d8ef..c4fafd8ef 100644 --- a/include/text.php +++ b/include/text.php @@ -656,11 +656,24 @@ function logger($msg, $level = LOGGER_NORMAL, $priority = LOG_INFO) { function btlogger($msg, $level = LOGGER_NORMAL, $priority = LOG_INFO) { logger($msg, $level, $priority); + + if(file_exists('btlogger.log') && is_writable('btlogger.log')) { + $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; + @file_put_contents('btlogger.log', $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 ++) { - logger('stack: ' . basename($stack[$x]['file']) . ':' . $stack[$x]['line'] . ':' . $stack[$x]['function'] . '()',$level, $priority); + $s = 'stack: ' . basename($stack[$x]['file']) . ':' . $stack[$x]['line'] . ':' . $stack[$x]['function'] . '()'; + logger($s,$level, $priority); + + if(file_exists('btlogger.log') && is_writable('btlogger.log')) { + @file_put_contents('btlogger.log', $s, FILE_APPEND); + } } } } -- cgit v1.2.3 From 35ed9b9b72cd2f8440c80ef395e119282bcd6383 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Sat, 24 Dec 2016 15:00:37 -0800 Subject: issue with post signatures if posted from api and logged in locally with a different identity. --- include/items.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'include') diff --git a/include/items.php b/include/items.php index 9bd256d58..57a9022da 100755 --- a/include/items.php +++ b/include/items.php @@ -1527,7 +1527,7 @@ function item_store($arr, $allow_exec = false, $deliver = true) { // 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'])); - if(local_channel() && (! $arr['sig'])) { + 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'])); @@ -1944,7 +1944,7 @@ function item_store_update($arr,$allow_exec = false, $deliver = true) { // 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'])); - if(local_channel() && (! $arr['sig'])) { + 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'])); -- cgit v1.2.3 From c38e7ee3e3a46e56a3894b2fe40b74206cdd8762 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Sun, 25 Dec 2016 14:26:27 -0800 Subject: show webpages link to visitors if a 'home' page exists. This means the nav menu must be used to edit pages. --- include/conversation.php | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) (limited to 'include') diff --git a/include/conversation.php b/include/conversation.php index 1673bc9fb..941b55159 100644 --- a/include/conversation.php +++ b/include/conversation.php @@ -1786,6 +1786,20 @@ function profile_tabs($a, $is_owner = false, $nickname = null){ $cal_link = '/cal/' . $nickname; } + require_once('include/security.php'); + $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 (get_pconfig($uid, 'system', 'noprofiletabs')) return; @@ -1870,15 +1884,16 @@ function profile_tabs($a, $is_owner = false, $nickname = null){ ); } - if ($p['write_pages'] && feature_enabled($uid,'webpages')) { + if($has_webpages && feature_enabled($uid,'webpages')) { $tabs[] = array( 'label' => t('Webpages'), - 'url' => z_root() . '/webpages/' . $nickname, + 'url' => z_root() . '/page/' . $nickname . '/home', 'sel' => ((argv(0) == 'webpages') ? 'active' : ''), - 'title' => t('Manage Webpages'), + 'title' => t('View Webpages'), 'id' => 'webpages-tab', ); - } + } + if(feature_enabled($uid,'wiki') && (get_account_techlevel($account_id) > 3)) { $tabs[] = array( -- cgit v1.2.3 From 1a5dd5c87c60f28fd799397e2aa0081f9b6c58ed Mon Sep 17 00:00:00 2001 From: Andrew Manning Date: Mon, 26 Dec 2016 08:58:40 -0500 Subject: Updated markup language support doco. Modified parseIdentityAwareHTML BBcode parsing to support the BBcode reference which is now in /help/member/bbcode.html. Add Bootstrap classes to tables for BBcode tables that have the border=0 or border=1 options set. --- include/bbcode.php | 32 +++++++++++++++++++++++++++----- 1 file changed, 27 insertions(+), 5 deletions(-) (limited to 'include') diff --git a/include/bbcode.php b/include/bbcode.php index c7bee6f97..f0cf861f3 100644 --- a/include/bbcode.php +++ b/include/bbcode.php @@ -530,7 +530,17 @@ function bb_fixtable_lf($match) { } function parseIdentityAwareHTML($Text) { - + + // Hide all [noparse] contained bbtags by spacefying them + if (strpos($Text,'[noparse]') !== false) { + $Text = preg_replace_callback("/\[noparse\](.*?)\[\/noparse\]/ism", 'bb_spacefy',$Text); + } + if (strpos($Text,'[nobb]') !== false) { + $Text = preg_replace_callback("/\[nobb\](.*?)\[\/nobb\]/ism", 'bb_spacefy',$Text); + } + if (strpos($Text,'[pre]') !== false) { + $Text = preg_replace_callback("/\[pre\](.*?)\[\/pre\]/ism", 'bb_spacefy',$Text); + } // process [observer] tags before we do anything else because we might // be stripping away stuff that then doesn't need to be worked on anymore @@ -568,9 +578,21 @@ function parseIdentityAwareHTML($Text) { $Text = str_replace('[observer.photo]','', $Text); } - $Text = str_replace(array('[baseurl]','[sitename]'),array(z_root(),get_config('system','sitename')),$Text); + $Text = str_replace(array('[baseurl]','[sitename]'),array(z_root(),get_config('system','sitename')),$Text); - return $Text; + + // Unhide all [noparse] contained bbtags unspacefying them + // and triming the [noparse] tag. + if (strpos($Text,'[noparse]') !== false) { + $Text = preg_replace_callback("/\[noparse\](.*?)\[\/noparse\]/ism", 'bb_unspacefy_and_trim', $Text); + } + if (strpos($Text,'[nobb]') !== false) { + $Text = preg_replace_callback("/\[nobb\](.*?)\[\/nobb\]/ism", 'bb_unspacefy_and_trim', $Text); + } + if (strpos($Text,'[pre]') !== false) { + $Text = preg_replace_callback("/\[pre\](.*?)\[\/pre\]/ism", 'bb_unspacefy_and_trim', $Text); + } + return $Text; } // BBcode 2 HTML was written by WAY2WEB.net @@ -891,8 +913,8 @@ function bbcode($Text, $preserve_nl = false, $tryoembed = true, $cache = false) } if (strpos($Text,'[/table]') !== false) { $Text = preg_replace("/\[table\](.*?)\[\/table\]/sm", '$1
', $Text); - $Text = preg_replace("/\[table border=1\](.*?)\[\/table\]/sm", '$1
', $Text); - $Text = preg_replace("/\[table border=0\](.*?)\[\/table\]/sm", '$1
', $Text); + $Text = preg_replace("/\[table border=1\](.*?)\[\/table\]/sm", '$1
', $Text); + $Text = preg_replace("/\[table border=0\](.*?)\[\/table\]/sm", '$1
', $Text); } $Text = str_replace('
', "\n", $Text); $Text = str_replace('[hr]', '
', $Text); -- cgit v1.2.3 From b530d1d44981df955842f4f572676db83d18084e Mon Sep 17 00:00:00 2001 From: zotlabs Date: Mon, 26 Dec 2016 13:10:24 -0800 Subject: perform input validation on xchan_store and re-enable the post method of the xchan api endpoint. --- include/api_zot.php | 4 ++-- include/hubloc.php | 8 ++++++++ 2 files changed, 10 insertions(+), 2 deletions(-) (limited to 'include') diff --git a/include/api_zot.php b/include/api_zot.php index d1979c3ae..82de85454 100644 --- a/include/api_zot.php +++ b/include/api_zot.php @@ -334,8 +334,8 @@ logger('api_xchan'); require_once('include/hubloc.php'); - if($_SERVER['REQUEST_METHOD'] === 'POST') { - // $r = xchan_store($_REQUEST); + if($_SERVER['REQUEST_METHOD'] === 'POST') { + $r = xchan_store($_REQUEST); } $r = xchan_fetch($_REQUEST); json_return_and_die($r); diff --git a/include/hubloc.php b/include/hubloc.php index 17f921f67..6f81ea31f 100644 --- a/include/hubloc.php +++ b/include/hubloc.php @@ -200,6 +200,14 @@ function xchan_store($arr) { if(! $arr['photo']) $arr['photo'] = z_root() . '/' . get_default_profile_photo(); + + if($arr['network'] === 'zot') { + if((! $arr['key']) || (! rsa_verify($arr['guid'],base64url_decode($arr['guid_sig']),$arr['key']))) { + logger('Unable to verify signature for ' . $arr['hash']); + return false; + } + } + $r = q("insert into xchan ( xchan_hash, xchan_guid, xchan_guid_sig, xchan_pubkey, xchan_addr, xchan_url, xchan_connurl, xchan_follow, xchan_connpage, xchan_name, xchan_network, xchan_instance_url, xchan_hidden, xchan_orphan, xchan_censored, xchan_selfcensored, xchan_system, xchan_pubforum, xchan_deleted, xchan_name_date ) values ('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s','%s','%s','%s',%d, %d, %d, %d, %d, %d, %d, '%s') ", dbesc($arr['hash']), dbesc($arr['guid']), -- cgit v1.2.3 From 17b7042a25da00e1e553b719001fdcabdad8a103 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Tue, 27 Dec 2016 15:26:47 -0800 Subject: issue with HTML in code blocks in markdown in wiki --- include/wiki.php | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) (limited to 'include') diff --git a/include/wiki.php b/include/wiki.php index 332d4efe0..922be6924 100644 --- a/include/wiki.php +++ b/include/wiki.php @@ -332,9 +332,35 @@ function wiki_page_history($arr) { } } +function wiki_prepare_content($s) { + + $text = preg_replace_callback('{ + (?:\n\n|\A\n?) + ( # $1 = the code block -- one or more lines, starting with a space/tab + (?> + [ ]{'.'4'.'} # Lines must start with a tab or a tab-width of spaces + .*\n+ + )+ + ) + ((?=^[ ]{0,'.'4'.'}\S)|\Z) # Lookahead for non-space at line-start, or end of doc + }xm', + 'wiki_prepare_content_callback', $s); + + return $text; +} + +function wiki_prepare_content_callback($matches) { + $codeblock = $matches[1]; + + $codeblock = htmlspecialchars($codeblock, ENT_NOQUOTES, UTF8, false); + return "\n\n" . $codeblock ; +} + + + function wiki_save_page($arr) { $pageUrlName = ((array_key_exists('pageUrlName',$arr)) ? $arr['pageUrlName'] : ''); - $content = ((array_key_exists('content',$arr)) ? purify_html($arr['content']) : ''); + $content = ((array_key_exists('content',$arr)) ? purify_html(wiki_prepare_content($arr['content'])) : ''); $resource_id = ((array_key_exists('resource_id',$arr)) ? $arr['resource_id'] : ''); $w = wiki_get_wiki($resource_id); if (!$w['path']) { -- cgit v1.2.3 From 13768fdb9b2925f31f49fb5f42de30ba0a0f3c0b Mon Sep 17 00:00:00 2001 From: Andrew Manning Date: Wed, 28 Dec 2016 14:58:25 -0500 Subject: Zot structures doco integrated into the Zot page. Added nowrap option to [code] BBcode tag. --- include/bbcode.php | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'include') diff --git a/include/bbcode.php b/include/bbcode.php index f0cf861f3..00d22d26d 100644 --- a/include/bbcode.php +++ b/include/bbcode.php @@ -511,6 +511,20 @@ function bb_code($match) { return '' . trim($match[1]) . ''; } +function bb_code_options($match) { + if(strpos($match[0], "
")) { + $class = ""; + } else { + $class = "inline-code"; + } + if(strpos($match[1], 'nowrap')) { + $style = "overflow-x: auto; white-space: pre;"; + } else { + $style = ""; + } + return '' . trim($match[2]) . ''; +} + 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'])) @@ -933,6 +947,11 @@ function bbcode($Text, $preserve_nl = false, $tryoembed = true, $cache = false) $Text = preg_replace_callback("/\[code\](.*?)\[\/code\]/ism", 'bb_code', $Text); } + // Check for [code options] text + if (strpos($Text,'[code ') !== false) { + $Text = preg_replace_callback("/\[code(.*?)\](.*?)\[\/code\]/ism", 'bb_code_options', $Text); + } + // Check for [spoiler] text $endlessloop = 0; while ((strpos($Text, "[/spoiler]")!== false) and (strpos($Text, "[spoiler]") !== false) and (++$endlessloop < 20)) { -- cgit v1.2.3 From e8a2ad43158bf94d55e64a23040c4a84a9414720 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Fri, 30 Dec 2016 02:31:53 -0800 Subject: logger typos --- include/import.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'include') diff --git a/include/import.php b/include/import.php index 0d8398acb..e3d3e7e81 100644 --- a/include/import.php +++ b/include/import.php @@ -86,7 +86,7 @@ function import_channel($channel, $account_id, $seize) { } if(! $r) { - logger('mod_import: channel clone failed. ', print_r($channel,true)); + logger('mod_import: channel clone failed. ' . print_r($channel,true)); notice( t('Channel clone failed. Import failed.') . EOL); return false; } @@ -96,7 +96,7 @@ function import_channel($channel, $account_id, $seize) { $channel['channel_guid'] // Already dbesc'd ); if(! $r) { - logger('mod_import: channel not found. ', print_r($channel,true)); + logger('mod_import: channel not found. ' . print_r($channel,true)); notice( t('Cloned channel not found. Import failed.') . EOL); return false; } -- cgit v1.2.3 From 2e2254371a0d6bdc2bb6e13b699e6353e42b1c2f Mon Sep 17 00:00:00 2001 From: zotlabs Date: Fri, 30 Dec 2016 02:45:16 -0800 Subject: move api version call back to core --- include/api_zot.php | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'include') diff --git a/include/api_zot.php b/include/api_zot.php index 82de85454..0881211d0 100644 --- a/include/api_zot.php +++ b/include/api_zot.php @@ -1,6 +1,8 @@ ' . "\r\n" . '' . Zotlabs\Lib\System::get_project_version() . '' . "\r\n"; + killme(); + } + elseif($type === 'json') { + header('Content-type: application/json'); + echo '"' . Zotlabs\Lib\System::get_project_version() . '"'; + killme(); + } + } + + + /* * Red basic channel export */ -- cgit v1.2.3 From 444e938e2d34044f1aa7d04110e0e391caafeea3 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Sat, 31 Dec 2016 13:38:19 -0800 Subject: issues #629, #635 - edited post arriving from downstream source was not being rejected --- include/zot.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'include') diff --git a/include/zot.php b/include/zot.php index 853c8eb9e..43749840a 100644 --- a/include/zot.php +++ b/include/zot.php @@ -1943,6 +1943,20 @@ function update_imported_item($sender, $item, $orig, $uid) { unset($item['item_private']); } + // Subtle issue where we might receive an edit item update from a downstream source. + // Ignore unless it comes from upstream. + + $x = q("select item_wall from item where mid = '%s' and uid = %d limit 1", + dbesc($item['mid']), + intval($uid) + ); + + if($x && $x[0]['item_wall'] == 1 && $item['item_wall'] == 0) { + notice('remote wall update ignored'); + return; + } + + $x = item_store_update($item); // If we're updating an event that we've saved locally, we store the item info first -- cgit v1.2.3 From e2eb0b2eac6f32a0e4781eabbb147f0bee0736fb Mon Sep 17 00:00:00 2001 From: zotlabs Date: Sat, 31 Dec 2016 15:56:45 -0800 Subject: better fix for #629 #635 based on ownership/authorship rather than message flags which could be forged --- include/zot.php | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) (limited to 'include') diff --git a/include/zot.php b/include/zot.php index 43749840a..96ec71112 100644 --- a/include/zot.php +++ b/include/zot.php @@ -1782,7 +1782,7 @@ function process_delivery($sender, $arr, $deliveries, $relay, $public = false, $ $result[] = $DR->get(); } else { - update_imported_item($sender,$arr,$r[0],$channel['channel_id']); + update_imported_item($sender,$arr,$r[0],$channel['channel_id'],$tag_delivery); $DR->update('updated'); $result[] = $DR->get(); if(! $relay) @@ -1930,7 +1930,7 @@ function remove_community_tag($sender, $arr, $uid) { * @param int $uid */ -function update_imported_item($sender, $item, $orig, $uid) { +function update_imported_item($sender, $item, $orig, $uid, $tag_delivery) { // If this is a comment being updated, remove any privacy information // so that item_store_update will set it from the original. @@ -1943,16 +1943,11 @@ function update_imported_item($sender, $item, $orig, $uid) { unset($item['item_private']); } - // Subtle issue where we might receive an edit item update from a downstream source. - // Ignore unless it comes from upstream. + // we need the tag_delivery check for downstream flowing posts as the stored post + // may have a different owner than the one being transmitted. - $x = q("select item_wall from item where mid = '%s' and uid = %d limit 1", - dbesc($item['mid']), - intval($uid) - ); - - if($x && $x[0]['item_wall'] == 1 && $item['item_wall'] == 0) { - notice('remote wall update ignored'); + if(($sender['hash'] != $orig['owner_xchan'] && $sender['hash'] != $orig['author_xchan']) && (! $tag_delivery)) { + notice('sender is not owner or author'); return; } -- cgit v1.2.3 From b88a735e54b233770b6772e89876fcc66b6217eb Mon Sep 17 00:00:00 2001 From: zotlabs Date: Sun, 1 Jan 2017 19:51:44 -0800 Subject: feature: allow event creation in other timezones than your own. --- include/features.php | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'include') diff --git a/include/features.php b/include/features.php index 1ccdbf015..8ff0d2d21 100644 --- a/include/features.php +++ b/include/features.php @@ -157,6 +157,15 @@ function get_features($filtered = true) { feature_level('smart_birthdays',2), ], + [ + 'event_tz_select', + t('Event Timezone Selection'), + t('Allow event creation in timezones other than your own.'), + false, + get_config('feature_lock','event_tz_select'), + feature_level('event_tz_select',2), + ], + [ 'advanced_dirsearch', t('Advanced Directory Search'), -- cgit v1.2.3 From 1ce8168d72b4bcb8a4373a6a6a4428db62a4aa3f Mon Sep 17 00:00:00 2001 From: zotlabs Date: Wed, 4 Jan 2017 11:47:08 -0800 Subject: some gnusoc fixes --- include/feedutils.php | 32 +++++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) (limited to 'include') diff --git a/include/feedutils.php b/include/feedutils.php index 1d58ec317..4a4e6ac59 100644 --- a/include/feedutils.php +++ b/include/feedutils.php @@ -388,7 +388,13 @@ function get_atom_elements($feed, $item, &$author) { $res['body'] = escape_tags($res['body']); } - if($res['plink'] && $res['title']) { + + // strip title if statusnet/gnusocial + + if(strpos($item->get_id(),'noticeId=')) { + $res['title'] = ''; + } + elseif($res['plink'] && $res['title']) { $res['body'] = '#^[url=' . $res['plink'] . ']' . $res['title'] . '[/url]' . "\n\n" . $res['body']; $terms = array(); $terms[] = array( @@ -760,11 +766,12 @@ function consume_feed($xml, $importer, &$contact, $pass = 0) { $is_reply = false; $item_id = base64url_encode($item->get_id()); - logger('consume_feed: processing ' . $item_id, LOGGER_DEBUG); + logger('consume_feed: processing ' . $raw_item_id, LOGGER_DEBUG); $rawthread = $item->get_item_tags( NAMESPACE_THREAD,'in-reply-to'); if(isset($rawthread[0]['attribs']['']['ref'])) { $is_reply = true; + $raw_parent_mid = $rawthread[0]['attribs']['']['ref']; $parent_mid = base64url_encode($rawthread[0]['attribs']['']['ref']); } @@ -779,6 +786,10 @@ function consume_feed($xml, $importer, &$contact, $pass = 0) { $author = array(); $datarray = get_atom_elements($feed,$item,$author); + +logger('raw_item_id: ' . $raw_item_id); +logger('datarray: ' . print_r($datarray,true)); + if($contact['xchan_network'] === 'rss') { $datarray['public_policy'] = 'specific'; $datarray['comment_policy'] = 'none'; @@ -824,7 +835,18 @@ function consume_feed($xml, $importer, &$contact, $pass = 0) { continue; } + $x = q("select mid from item where ( mid = '%s' || plink = '%s' || llink = '%s' ) and uid = %d limit 1", + dbesc($raw_parent_mid), + dbesc($raw_parent_mid), + dbesc($raw_parent_mid), + intval($importer['channel_id']) + ); + if($x) + $parent_mid = $x[0]['mid']; + $datarray['parent_mid'] = $parent_mid; + + $datarray['aid'] = $importer['channel_account_id']; $datarray['uid'] = $importer['channel_id']; @@ -1159,7 +1181,11 @@ 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"; + $raw_parent = @base64url_decode($parent_item); + if(strpos($raw_parent,'noticeID=')) + $parent_item = $raw_parent; + $o .= '' . "\r\n"; + } if(activity_match($item['obj_type'],ACTIVITY_OBJ_EVENT) && activity_match($item['verb'],ACTIVITY_POST)) { -- cgit v1.2.3 From ec18c3770bd1ff444713c94f8405b75692848274 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Thu, 5 Jan 2017 12:17:36 -0800 Subject: issue #639, voting setting is lost after post is edited (also the disabling of comments) --- include/conversation.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'include') diff --git a/include/conversation.php b/include/conversation.php index 941b55159..0ff368e6e 100644 --- a/include/conversation.php +++ b/include/conversation.php @@ -1396,11 +1396,11 @@ function status_editor($a, $x, $popup = false) { '$setloc' => $setloc, '$voting' => t('Toggle voting'), '$feature_voting' => $feature_voting, - '$consensus' => 0, + '$consensus' => ((array_key_exists('item',$x)) ? $x['item']['item_consensus'] : 0), '$nocommenttitle' => t('Disable comments'), '$nocommenttitlesub' => t('Toggle comments'), '$feature_nocomment' => $feature_nocomment, - '$nocomment' => 0, + '$nocomment' => ((array_key_exists('item',$x)) ? $x['item']['item_nocomment'] : 0), '$clearloc' => $clearloc, '$title' => ((x($x, 'title')) ? htmlspecialchars($x['title'], ENT_COMPAT,'UTF-8') : ''), '$placeholdertitle' => ((x($x, 'placeholdertitle')) ? $x['placeholdertitle'] : t('Title (optional)')), -- cgit v1.2.3 From dfede520481f94407ef3dd3b9d622cf6c6ab98f1 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Thu, 5 Jan 2017 13:55:04 -0800 Subject: ical import/export - provide mechanism to preserve original source formatting across zot based systems. --- include/event.php | 65 ++++++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 52 insertions(+), 13 deletions(-) (limited to 'include') diff --git a/include/event.php b/include/event.php index 8fb060a40..f3366fb69 100644 --- a/include/event.php +++ b/include/event.php @@ -127,12 +127,18 @@ function format_event_ical($ev) { $o .= "\r\nDTSTART:" . datetime_convert('UTC','UTC', $ev['dtstart'],'Ymd\\THis' . (($ev['adjust']) ? '\\Z' : '')); if($ev['dtend'] && ! $ev['nofinish']) $o .= "\r\nDTEND:" . datetime_convert('UTC','UTC', $ev['dtend'],'Ymd\\THis' . (($ev['adjust']) ? '\\Z' : '')); - if($ev['summary']) + if($ev['summary']) { $o .= "\r\nSUMMARY:" . format_ical_text($ev['summary']); - if($ev['location']) + $o .= "\r\nX-ZOT-SUMMARY:" . format_ical_sourcetext($ev['summary']); + } + if($ev['location']) { $o .= "\r\nLOCATION:" . format_ical_text($ev['location']); - if($ev['description']) + $o .= "\r\nX-ZOT-LOCATION:" . format_ical_sourcetext($ev['location']); + } + if($ev['description']) { $o .= "\r\nDESCRIPTION:" . format_ical_text($ev['description']); + $o .= "\r\nX-ZOT-DESCRIPTION:" . format_ical_sourcetext($ev['description']); + } if($ev['event_priority']) $o .= "\r\nPRIORITY:" . intval($ev['event_priority']); $o .= "\r\nUID:" . $ev['event_hash'] ; @@ -154,8 +160,10 @@ function format_todo_ical($ev) { $o .= "\r\nDTSTART:" . datetime_convert('UTC','UTC', $ev['dtstart'],'Ymd\\THis' . (($ev['adjust']) ? '\\Z' : '')); if($ev['dtend'] && ! $ev['nofinish']) $o .= "\r\nDUE:" . datetime_convert('UTC','UTC', $ev['dtend'],'Ymd\\THis' . (($ev['adjust']) ? '\\Z' : '')); - if($ev['summary']) + if($ev['summary']) { $o .= "\r\nSUMMARY:" . format_ical_text($ev['summary']); + $o .= "\r\nX-ZOT-SUMMARY:" . format_ical_sourcetext($ev['summary']); + } if($ev['event_status']) { $o .= "\r\nSTATUS:" . $ev['event_status']; if($ev['event_status'] === 'COMPLETED') @@ -165,10 +173,14 @@ function format_todo_ical($ev) { $o .= "\r\nPERCENT-COMPLETE:" . $ev['event_percent']; if(intval($ev['event_sequence'])) $o .= "\r\nSEQUENCE:" . $ev['event_sequence']; - if($ev['location']) + if($ev['location']) { $o .= "\r\nLOCATION:" . format_ical_text($ev['location']); - if($ev['description']) + $o .= "\r\nX-ZOT-LOCATION:" . format_ical_sourcetext($ev['location']); + } + if($ev['description']) { $o .= "\r\nDESCRIPTION:" . format_ical_text($ev['description']); + $o .= "\r\nX-ZOT-DESCRIPTION:" . format_ical_sourcetext($ev['description']); + } $o .= "\r\nUID:" . $ev['event_hash'] ; if($ev['event_priority']) $o .= "\r\nPRIORITY:" . intval($ev['event_priority']); @@ -178,7 +190,6 @@ function format_todo_ical($ev) { } - function format_ical_text($s) { require_once('include/bbcode.php'); require_once('include/html2plain.php'); @@ -186,6 +197,12 @@ function format_ical_text($s) { $s = html2plain(bbcode($s)); $s = str_replace(["\r\n","\n"],["",""],$s); return(wordwrap(str_replace(['\\',',',';'],['\\\\','\\,','\\;'],$s),72,"\r\n ",true)); + +} + +function format_ical_sourcetext($s) { + $s = base64_encode($s); + return(wordwrap(str_replace(['\\',',',';'],['\\\\','\\,','\\;'],$s),72,"\r\n ",true)); } @@ -623,12 +640,21 @@ function event_import_ical($ical, $uid) { $ev['edited'] = datetime_convert('UTC','UTC',$edited->format(\DateTime::W3C)); } - if(isset($ical->LOCATION)) + if(isset($ical->{'X-ZOT-LOCATION'})) + $ev['location'] = event_ical_get_sourcetext( (string) $ical->{'X-ZOT-LOCATION'}); + elseif(isset($ical->LOCATION)) $ev['location'] = (string) $ical->LOCATION; - if(isset($ical->DESCRIPTION)) + + if(isset($ical->{'X-ZOT-DESCRIPTION'})) + $ev['description'] = event_ical_get_sourcetext( (string) $ical->{'X-ZOT-DESCRIPTION'}); + elseif(isset($ical->DESCRIPTION)) $ev['description'] = (string) $ical->DESCRIPTION; - if(isset($ical->SUMMARY)) + + if(isset($ical->{'X-ZOT-SUMMARY'})) + $ev['summary'] = event_ical_get_sourcetext( (string) $ical->{'X-ZOT-SUMMARY'}); + elseif(isset($ical->SUMMARY)) $ev['summary'] = (string) $ical->SUMMARY; + if(isset($ical->PRIORITY)) $ev['event_priority'] = intval((string) $ical->PRIORITY); @@ -663,6 +689,10 @@ function event_import_ical($ical, $uid) { } +function event_ical_get_sourcetext($s) { + return base64_decode($s); +} + function event_import_ical_task($ical, $uid) { $c = q("select * from channel where channel_id = %d limit 1", @@ -718,12 +748,21 @@ function event_import_ical_task($ical, $uid) { $ev['edited'] = datetime_convert('UTC','UTC',$edited->format(\DateTime::W3C)); } - if(isset($ical->LOCATION)) + if(isset($ical->{'X-ZOT-LOCATION'})) + $ev['location'] = event_ical_get_sourcetext( (string) $ical->{'X-ZOT-LOCATION'}); + elseif(isset($ical->LOCATION)) $ev['location'] = (string) $ical->LOCATION; - if(isset($ical->DESCRIPTION)) + + if(isset($ical->{'X-ZOT-DESCRIPTION'})) + $ev['description'] = event_ical_get_sourcetext( (string) $ical->{'X-ZOT-DESCRIPTION'}); + elseif(isset($ical->DESCRIPTION)) $ev['description'] = (string) $ical->DESCRIPTION; - if(isset($ical->SUMMARY)) + + if(isset($ical->{'X-ZOT-SUMMARY'})) + $ev['summary'] = event_ical_get_sourcetext( (string) $ical->{'X-ZOT-SUMMARY'}); + elseif(isset($ical->SUMMARY)) $ev['summary'] = (string) $ical->SUMMARY; + if(isset($ical->PRIORITY)) $ev['event_priority'] = intval((string) $ical->PRIORITY); -- cgit v1.2.3 From 2312302deade5ccc2e65cd58483a4f40a8d4aea4 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Thu, 5 Jan 2017 14:17:56 -0800 Subject: setup: check disabled functions more precisely than using a string match --- include/text.php | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'include') diff --git a/include/text.php b/include/text.php index c4fafd8ef..fbf6df49e 100644 --- a/include/text.php +++ b/include/text.php @@ -3120,3 +3120,9 @@ function cleanup_bbcode($body) { return $body; } + +// callback for array_walk + +function array_trim(&$v,$k) { + $v = trim($v); +} \ No newline at end of file -- cgit v1.2.3 From 6db2561eda67d038139e885b07138706ef8af75e Mon Sep 17 00:00:00 2001 From: zotlabs Date: Fri, 6 Jan 2017 13:25:57 -0800 Subject: preserve the original message-id coming from feeds - we will have to escape them properly before calling mod_display. --- include/feedutils.php | 27 ++++++++++----------------- 1 file changed, 10 insertions(+), 17 deletions(-) (limited to 'include') diff --git a/include/feedutils.php b/include/feedutils.php index 4a4e6ac59..be59c3c38 100644 --- a/include/feedutils.php +++ b/include/feedutils.php @@ -236,7 +236,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'] = base64url_encode(unxmlify($item->get_id())); + $res['mid'] = unxmlify($item->get_id()); $res['title'] = unxmlify($item->get_title()); $res['body'] = unxmlify($item->get_content()); $res['plink'] = unxmlify($item->get_link(0)); @@ -736,7 +736,7 @@ function consume_feed($xml, $importer, &$contact, $pass = 0) { if($deleted && is_array($contact)) { $r = q("SELECT * from item where mid = '%s' and author_xchan = '%s' and uid = %d limit 1", - dbesc(base64url_encode($mid)), + dbesc($mid), dbesc($contact['xchan_hash']), intval($importer['channel_id']) ); @@ -745,7 +745,7 @@ function consume_feed($xml, $importer, &$contact, $pass = 0) { $item = $r[0]; if(! intval($item['item_deleted'])) { - logger('consume_feed: deleting item ' . $item['id'] . ' mid=' . base64url_decode($item['mid']), LOGGER_DEBUG); + logger('consume_feed: deleting item ' . $item['id'] . ' mid=' . $item['mid'], LOGGER_DEBUG); drop_item($item['id'],false); } } @@ -764,7 +764,7 @@ function consume_feed($xml, $importer, &$contact, $pass = 0) { foreach($items as $item) { $is_reply = false; - $item_id = base64url_encode($item->get_id()); + $item_id = $item->get_id(); logger('consume_feed: processing ' . $raw_item_id, LOGGER_DEBUG); @@ -772,7 +772,7 @@ function consume_feed($xml, $importer, &$contact, $pass = 0) { if(isset($rawthread[0]['attribs']['']['ref'])) { $is_reply = true; $raw_parent_mid = $rawthread[0]['attribs']['']['ref']; - $parent_mid = base64url_encode($rawthread[0]['attribs']['']['ref']); + $parent_mid = $rawthread[0]['attribs']['']['ref']; } if($is_reply) { @@ -782,14 +782,10 @@ function consume_feed($xml, $importer, &$contact, $pass = 0) { // Have we seen it? If not, import it. - $item_id = base64url_encode($item->get_id()); + $item_id = $item->get_id(); $author = array(); $datarray = get_atom_elements($feed,$item,$author); - -logger('raw_item_id: ' . $raw_item_id); -logger('datarray: ' . print_r($datarray,true)); - if($contact['xchan_network'] === 'rss') { $datarray['public_policy'] = 'specific'; $datarray['comment_policy'] = 'none'; @@ -860,7 +856,7 @@ logger('datarray: ' . print_r($datarray,true)); // Head post of a conversation. Have we seen it? If not, import it. - $item_id = base64url_encode($item->get_id()); + $item_id = $item->get_id(); $author = array(); $datarray = get_atom_elements($feed,$item,$author); @@ -1005,14 +1001,14 @@ function process_salmon_feed($xml, $importer) { foreach($items as $item) { - $item_id = base64url_encode($item->get_id()); + $item_id = $item->get_id(); logger('processing ' . $item_id, LOGGER_DEBUG); $rawthread = $item->get_item_tags( NAMESPACE_THREAD,'in-reply-to'); if(isset($rawthread[0]['attribs']['']['ref'])) { $is_reply = true; - $parent_mid = base64url_encode($rawthread[0]['attribs']['']['ref']); + $parent_mid = $rawthread[0]['attribs']['']['ref']; } if($is_reply) @@ -1181,10 +1177,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']); - $raw_parent = @base64url_decode($parent_item); - if(strpos($raw_parent,'noticeID=')) - $parent_item = $raw_parent; - $o .= '' . "\r\n"; + $o .= '' . "\r\n"; } -- cgit v1.2.3 From a3c45d47e65c0974c07ede6325c6472b64ac6049 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Fri, 6 Jan 2017 13:37:52 -0800 Subject: add the ostatus:conversation element which is now more or less required by GNU-Social to work around some short-comings of the OStatus delivery model when it comes to conversational message grouping. If this element isn't there, message replies will not get grouped with the parent specified in thr:in-reply-to, which exists to group conversations together. The reasoning being that due to the point-to-point delivery model, a reply could arrive on one site which does not have a copy of the parent specified by thr:in-reply-to. Hence further replies arriving on this site are grouped with the first arrived comment as the parent. Since this project doesn't allow comments which don't have top-level parents, we can just set it to the parent-mid and save being forced to create a new database structure for orphan children acting as parents. --- include/feedutils.php | 3 +++ 1 file changed, 3 insertions(+) (limited to 'include') diff --git a/include/feedutils.php b/include/feedutils.php index be59c3c38..6d65f9fe8 100644 --- a/include/feedutils.php +++ b/include/feedutils.php @@ -1181,6 +1181,9 @@ function atom_entry($item,$type,$author,$owner,$comment = false,$cid = 0) { } + $o .= '' . "\r\n"; + $o .= '' . xmlify($item['parent_mid']) . '' . "\r\n"; + if(activity_match($item['obj_type'],ACTIVITY_OBJ_EVENT) && activity_match($item['verb'],ACTIVITY_POST)) { $obj = ((is_array($item['obj'])) ? $item['obj'] : json_decode($item['obj'],true)); -- cgit v1.2.3 From fb059bfdc320a0760ef3de5e4e21ded198f8ceaf Mon Sep 17 00:00:00 2001 From: zotlabs Date: Fri, 6 Jan 2017 20:20:49 -0800 Subject: more feedutils cleanup --- include/feedutils.php | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) (limited to 'include') diff --git a/include/feedutils.php b/include/feedutils.php index 6d65f9fe8..b28a697fd 100644 --- a/include/feedutils.php +++ b/include/feedutils.php @@ -771,7 +771,6 @@ function consume_feed($xml, $importer, &$contact, $pass = 0) { $rawthread = $item->get_item_tags( NAMESPACE_THREAD,'in-reply-to'); if(isset($rawthread[0]['attribs']['']['ref'])) { $is_reply = true; - $raw_parent_mid = $rawthread[0]['attribs']['']['ref']; $parent_mid = $rawthread[0]['attribs']['']['ref']; } @@ -831,10 +830,8 @@ function consume_feed($xml, $importer, &$contact, $pass = 0) { continue; } - $x = q("select mid from item where ( mid = '%s' || plink = '%s' || llink = '%s' ) and uid = %d limit 1", - dbesc($raw_parent_mid), - dbesc($raw_parent_mid), - dbesc($raw_parent_mid), + $x = q("select mid from item where mid = '%s' and uid = %d limit 1", + dbesc($parent_mid), intval($importer['channel_id']) ); if($x) -- cgit v1.2.3 From 89f0ecf25d413d67fe96c1b9f0ee898d0864a49c Mon Sep 17 00:00:00 2001 From: zotlabs Date: Sat, 7 Jan 2017 04:04:11 -0800 Subject: update the atom_entry hook --- include/feedutils.php | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) (limited to 'include') diff --git a/include/feedutils.php b/include/feedutils.php index b28a697fd..dfa3feed7 100644 --- a/include/feedutils.php +++ b/include/feedutils.php @@ -1178,9 +1178,6 @@ function atom_entry($item,$type,$author,$owner,$comment = false,$cid = 0) { } - $o .= '' . "\r\n"; - $o .= '' . xmlify($item['parent_mid']) . '' . "\r\n"; - if(activity_match($item['obj_type'],ACTIVITY_OBJ_EVENT) && activity_match($item['verb'],ACTIVITY_POST)) { $obj = ((is_array($item['obj'])) ? $item['obj'] : json_decode($item['obj'],true)); @@ -1240,11 +1237,21 @@ function atom_entry($item,$type,$author,$owner,$comment = false,$cid = 0) { // if($mentioned) // $o .= $mentioned; - call_hooks('atom_entry', $o); - $o .= '' . "\r\n"; - return $o; + $x = [ + 'item' => $item, + 'type' => $type, + 'author' => $author, + 'owner' => $owner, + 'comment' => $comment, + 'abook_id => $cid, + 'entry' => $o + ]; + + call_hooks('atom_entry', $x); + + return $x['entry']; } -- cgit v1.2.3 From 6f1209ea49bf4afe80120ebeb82574866c1ffc3b Mon Sep 17 00:00:00 2001 From: zotlabs Date: Sat, 7 Jan 2017 04:51:44 -0800 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 dfa3feed7..1502ac6a4 100644 --- a/include/feedutils.php +++ b/include/feedutils.php @@ -1245,7 +1245,7 @@ function atom_entry($item,$type,$author,$owner,$comment = false,$cid = 0) { 'author' => $author, 'owner' => $owner, 'comment' => $comment, - 'abook_id => $cid, + 'abook_id' => $cid, 'entry' => $o ]; -- cgit v1.2.3 From c9f41841267db38573ff4c0401f81327ecd7c042 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Sat, 7 Jan 2017 12:47:19 -0800 Subject: allow the atom_entry hook to change the results --- 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 1502ac6a4..df56e3673 100644 --- a/include/feedutils.php +++ b/include/feedutils.php @@ -304,7 +304,7 @@ function get_atom_elements($feed, $item, &$author) { foreach($base as $link) { if($link['attribs']['']['rel'] === 'alternate' && (! $author['author_link'])) { $author['author_link'] = unxmlify($link['attribs']['']['href']); - $author['author_is_feed'] = true; +0 $author['author_is_feed'] = true; } if(! $author['author_photo']) { if($link['attribs']['']['rel'] === 'photo' || $link['attribs']['']['rel'] === 'avatar') @@ -331,6 +331,8 @@ function get_atom_elements($feed, $item, &$author) { } } + $ostatus_protocol = (($item->get_item_tags(NAMESPACE_OSTATUS,'conversation')) ? true : false); + $apps = $item->get_item_tags(NAMESPACE_STATUSNET,'notice_info'); if($apps && $apps[0]['attribs']['']['source']) { $res['app'] = strip_tags(unxmlify($apps[0]['attribs']['']['source'])); @@ -343,6 +345,8 @@ function get_atom_elements($feed, $item, &$author) { $have_real_body = false; $rawenv = $item->get_item_tags(NAMESPACE_DFRN, 'env'); + if(! $rawenv) + $rawenv = $item->get_item_tags(NAMESPACE_ZOT,'source'); if($rawenv) { $have_real_body = true; $res['body'] = $rawenv[0]['data']; @@ -389,9 +393,11 @@ function get_atom_elements($feed, $item, &$author) { } - // strip title if statusnet/gnusocial + // strip title and don't apply "title-in-body" if the feed involved + // uses the OStatus stack. We need a more generalised way for the calling + // function to specify this behaviour or for plugins to alter it. - if(strpos($item->get_id(),'noticeId=')) { + if($ostatus_protocol) { $res['title'] = ''; } elseif($res['plink'] && $res['title']) { @@ -629,14 +635,15 @@ function get_atom_elements($feed, $item, &$author) { $res['target'] = $obj; } - $arr = array('feed' => $feed, 'item' => $item, 'result' => $res); + $arr = array('feed' => $feed, 'item' => $item, 'author' => $author, 'result' => $res); call_hooks('parse_atom', $arr); - logger('get_atom_elements: author: ' . print_r($author,true),LOGGER_DATA); - logger('get_atom_elements: ' . print_r($res,true),LOGGER_DATA); + logger('get_atom_elements: author: ' . print_r($arr['author'],true),LOGGER_DATA); + + logger('get_atom_elements: ' . print_r($arr['result'],true),LOGGER_DATA); - return $res; + return $arr['result']; } function encode_rel_links($links) { -- cgit v1.2.3 From 96e668a5b940362c0f2db15fc7519d9baad88f3d Mon Sep 17 00:00:00 2001 From: zotlabs Date: Sat, 7 Jan 2017 13:29:32 -0800 Subject: add enclosures and categories to atom feed --- include/feedutils.php | 69 +++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 50 insertions(+), 19 deletions(-) (limited to 'include') diff --git a/include/feedutils.php b/include/feedutils.php index df56e3673..68ac20782 100644 --- a/include/feedutils.php +++ b/include/feedutils.php @@ -304,7 +304,7 @@ function get_atom_elements($feed, $item, &$author) { foreach($base as $link) { if($link['attribs']['']['rel'] === 'alternate' && (! $author['author_link'])) { $author['author_link'] = unxmlify($link['attribs']['']['href']); -0 $author['author_is_feed'] = true; + $author['author_is_feed'] = true; } if(! $author['author_photo']) { if($link['attribs']['']['rel'] === 'photo' || $link['attribs']['']['rel'] === 'avatar') @@ -1229,31 +1229,62 @@ function atom_entry($item,$type,$author,$owner,$comment = false,$cid = 0) { if(strlen($actarg)) $o .= $actarg; - // FIXME -// $tags = item_getfeedtags($item); -// if(count($tags)) { -// foreach($tags as $t) { -// $o .= '' . "\r\n"; -// } -// } -// FIXME -// $o .= item_getfeedattach($item); + if($item['attach']) { + $enclosures = json_decode($item['attach'],true); + if($enclosures) { + foreach($enclosures as $enc) { + $o .= ''; + } + } + } -// $mentioned = get_mentions($item,$tags); -// if($mentioned) -// $o .= $mentioned; + if($item['term']) { + foreach($item['term'] as $term) { + $scheme = ''; + $label = ''; + switch($term['ttype']) { + case TERM_UNKNOWN: + $scheme = NAMESPACE_ZOT . '/term/unknown'; + $label = $term['term']; + break; + case TERM_HASHTAG: + case TERM_COMMUNITYTAG: + $scheme = NAMESPACE_ZOT . '/term/hashtag'; + $label = '#' . $term['term']; + break; + case TERM_MENTION: + $scheme = NAMESPACE_ZOT . '/term/mention'; + $label = '@' . $term['term']; + break; + case TERM_CATEGORY: + $scheme = NAMESPACE_ZOT . '/term/category'; + $label = $term['term']; + break; + default: + break; + } + if(! $scheme) + continue; + + $o .= '' . "\r\n"; + } + } $o .= '' . "\r\n"; $x = [ - 'item' => $item, - 'type' => $type, - 'author' => $author, - 'owner' => $owner, - 'comment' => $comment, + 'item' => $item, + 'type' => $type, + 'author' => $author, + 'owner' => $owner, + 'comment' => $comment, 'abook_id' => $cid, - 'entry' => $o + 'entry' => $o ]; call_hooks('atom_entry', $x); -- cgit v1.2.3 From a6272fcf769c3fc7c3834b3183dfbe25ec738550 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Mon, 9 Jan 2017 14:37:56 -0800 Subject: channel move stuff (disabled currently because not yet complete) --- include/import.php | 19 ++++++++++++++++--- include/zot.php | 2 +- 2 files changed, 17 insertions(+), 4 deletions(-) (limited to 'include') diff --git a/include/import.php b/include/import.php index e3d3e7e81..d19d056b3 100644 --- a/include/import.php +++ b/include/import.php @@ -155,7 +155,7 @@ function import_profiles($channel,$profiles) { } -function import_hublocs($channel,$hublocs,$seize) { +function import_hublocs($channel,$hublocs,$seize,$moving = false) { if($channel && $hublocs) { foreach($hublocs as $hubloc) { @@ -173,19 +173,32 @@ function import_hublocs($channel,$hublocs,$seize) { $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'], 'guid_sig' => $hubloc['hubloc_guid_sig'], 'url' => $hubloc['hubloc_url'], - 'url_sig' => $hubloc['hubloc_url_sig'] + '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; - if(! zot_gethub($arr)) { + if(($x = zot_gethub($arr,false)) === false) { unset($hubloc['hubloc_id']); create_table_from_array('hubloc',$hubloc); } + else { + q("UPDATE hubloc set hubloc_primary = %d, hubloc_deleted = %d where hubloc_id = %d", + intval($hubloc['hubloc_primary']), + intval($hubloc['hubloc_deleted']), + intval($x['hubloc_id']) + ); + + } } } } diff --git a/include/zot.php b/include/zot.php index 96ec71112..c6d52816a 100644 --- a/include/zot.php +++ b/include/zot.php @@ -568,7 +568,7 @@ function zot_gethub($arr, $multiple = false) { } logger('zot_gethub: not found: ' . print_r($arr,true), LOGGER_DEBUG); - return null; + return false; } /** -- cgit v1.2.3 From 120afb30c15b3d3f3e68a56b4a70dfc1891e83fc Mon Sep 17 00:00:00 2001 From: zotlabs Date: Mon, 9 Jan 2017 22:12:44 -0800 Subject: obj_type on edit activity was wrong --- include/items.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'include') diff --git a/include/items.php b/include/items.php index 57a9022da..f7d8691cc 100755 --- a/include/items.php +++ b/include/items.php @@ -4463,9 +4463,9 @@ function item_create_edit_activity($post) { $new_item['verb'] = ACTIVITY_UPDATE; $new_item['item_thread_top'] = 0; $new_item['created'] = $new_item['edited'] = datetime_convert(); - + $new_item['obj_type'] = (($update_item['item_thread_top']) ? ACTIVITY_OBJ_NOTE : ACTIVITY_OBJ_COMMENT); $new_item['obj'] = json_encode(array( - 'type' => (($update_item['item_thread_top']) ? ACTIVITY_OBJ_NOTE : ACTIVITY_OBJ_COMMENT), + 'type' => $new_item['obj_type'], 'id' => $update_item['mid'], 'parent' => $update_item['parent_mid'], 'link' => array(array('rel' => 'alternate','type' => 'text/html', 'href' => $update_item['plink'])), -- cgit v1.2.3 From 5092cb75f42b7f935bb1cc9957707233df8a1373 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Tue, 10 Jan 2017 14:25:11 -0800 Subject: normalise feed id --- include/feedutils.php | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) (limited to 'include') diff --git a/include/feedutils.php b/include/feedutils.php index 68ac20782..b122a8e4b 100644 --- a/include/feedutils.php +++ b/include/feedutils.php @@ -635,6 +635,7 @@ function get_atom_elements($feed, $item, &$author) { $res['target'] = $obj; } + $arr = array('feed' => $feed, 'item' => $item, 'author' => $author, 'result' => $res); call_hooks('parse_atom', $arr); @@ -731,7 +732,7 @@ function consume_feed($xml, $importer, &$contact, $pass = 0) { foreach($del_entries as $dentry) { $deleted = false; if(isset($dentry['attribs']['']['ref'])) { - $mid = $dentry['attribs']['']['ref']; + $mid = normalise_id($dentry['attribs']['']['ref']); $deleted = true; if(isset($dentry['attribs']['']['when'])) { $when = $dentry['attribs']['']['when']; @@ -771,14 +772,14 @@ function consume_feed($xml, $importer, &$contact, $pass = 0) { foreach($items as $item) { $is_reply = false; - $item_id = $item->get_id(); + $item_id = normalise_id($item->get_id()); logger('consume_feed: processing ' . $raw_item_id, LOGGER_DEBUG); $rawthread = $item->get_item_tags( NAMESPACE_THREAD,'in-reply-to'); if(isset($rawthread[0]['attribs']['']['ref'])) { $is_reply = true; - $parent_mid = $rawthread[0]['attribs']['']['ref']; + $parent_mid = normalise_id($rawthread[0]['attribs']['']['ref']); } if($is_reply) { @@ -788,7 +789,7 @@ function consume_feed($xml, $importer, &$contact, $pass = 0) { // Have we seen it? If not, import it. - $item_id = $item->get_id(); + $item_id = normalise_id($item->get_id()); $author = array(); $datarray = get_atom_elements($feed,$item,$author); @@ -860,7 +861,7 @@ function consume_feed($xml, $importer, &$contact, $pass = 0) { // Head post of a conversation. Have we seen it? If not, import it. - $item_id = $item->get_id(); + $item_id = normalise_id($item->get_id()); $author = array(); $datarray = get_atom_elements($feed,$item,$author); @@ -965,6 +966,11 @@ function consume_feed($xml, $importer, &$contact, $pass = 0) { } +function normalise_id($id) { + return str_replace('X-ZOT:','',$id); +} + + /** * @brief Process atom feed and return the first post and structure * @@ -1005,14 +1011,14 @@ function process_salmon_feed($xml, $importer) { foreach($items as $item) { - $item_id = $item->get_id(); + $item_id = normalise_id($item->get_id()); logger('processing ' . $item_id, LOGGER_DEBUG); $rawthread = $item->get_item_tags( NAMESPACE_THREAD,'in-reply-to'); if(isset($rawthread[0]['attribs']['']['ref'])) { $is_reply = true; - $parent_mid = $rawthread[0]['attribs']['']['ref']; + $parent_mid = normalise_id($rawthread[0]['attribs']['']['ref']); } if($is_reply) @@ -1181,7 +1187,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"; } @@ -1200,7 +1206,7 @@ function atom_entry($item,$type,$author,$owner,$comment = false,$cid = 0) { $o .= '' . xmlify(prepare_text($body,$item['mimetype'])) . '' . "\r\n"; } - $o .= '' . z_root() . '/display/' . xmlify($item['mid']) . '' . "\r\n"; + $o .= '' . 'X-ZOT:' . xmlify($item['mid']) . '' . "\r\n"; $o .= '' . xmlify(datetime_convert('UTC','UTC',$item['created'] . '+00:00',ATOM_TIME)) . '' . "\r\n"; $o .= '' . xmlify(datetime_convert('UTC','UTC',$item['edited'] . '+00:00',ATOM_TIME)) . '' . "\r\n"; @@ -1287,6 +1293,7 @@ function atom_entry($item,$type,$author,$owner,$comment = false,$cid = 0) { 'entry' => $o ]; + call_hooks('atom_entry', $x); return $x['entry']; -- cgit v1.2.3 From 9ad44a2060b9f294423376f1fad43fa17d1dffe4 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Tue, 10 Jan 2017 17:37:41 -0800 Subject: btlogger trace file logging not working as desired. --- include/text.php | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'include') diff --git a/include/text.php b/include/text.php index fbf6df49e..bc1eff7db 100644 --- a/include/text.php +++ b/include/text.php @@ -655,13 +655,16 @@ function logger($msg, $level = LOGGER_NORMAL, $priority = LOG_INFO) { */ function btlogger($msg, $level = LOGGER_NORMAL, $priority = LOG_INFO) { + if(! defined('BTLOGGER_DEBUG_FILE')) + define('BTLOGGER_DEBUG_FILE','btlogger.out'); + logger($msg, $level, $priority); - if(file_exists('btlogger.log') && is_writable('btlogger.log')) { + if(file_exists(BTLOGGER_DEBUG_FILE) && is_writable(BTLOGGER_DEBUG_FILE)) { $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; - @file_put_contents('btlogger.log', $s, FILE_APPEND); + @file_put_contents(BTLOGGER_DEBUG_FILE, $s, FILE_APPEND); } if(version_compare(PHP_VERSION, '5.4.0') >= 0) { @@ -671,8 +674,8 @@ function btlogger($msg, $level = LOGGER_NORMAL, $priority = LOG_INFO) { $s = 'stack: ' . basename($stack[$x]['file']) . ':' . $stack[$x]['line'] . ':' . $stack[$x]['function'] . '()'; logger($s,$level, $priority); - if(file_exists('btlogger.log') && is_writable('btlogger.log')) { - @file_put_contents('btlogger.log', $s, FILE_APPEND); + if(file_exists(BTLOGGER_DEBUG_FILE) && is_writable(BTLOGGER_DEBUG_FILE)) { + @file_put_contents(BTLOGGER_DEBUG_FILE, $s . PHP_EOL, FILE_APPEND); } } } -- cgit v1.2.3 From 2fc47cc52b556153a17b5712e695175f87e6c1dd Mon Sep 17 00:00:00 2001 From: Mario Vavti Date: Wed, 11 Jan 2017 10:59:46 +0100 Subject: fix embedimage if an albumname contains quotes --- include/photos.php | 1 + 1 file changed, 1 insertion(+) (limited to 'include') diff --git a/include/photos.php b/include/photos.php index 5e4d755e3..8496c2c86 100644 --- a/include/photos.php +++ b/include/photos.php @@ -480,6 +480,7 @@ function photos_albums_list($channel, $observer, $sort_key = 'album', $direction foreach($albums as $k => $album) { $entry = array( 'text' => (($album['album']) ? $album['album'] : '/'), + 'jstext' => (($album['album']) ? addslashes($album['album']) : '/'), 'total' => $album['total'], 'url' => z_root() . '/photos/' . $channel['channel_address'] . '/album/' . bin2hex($album['album']), 'urlencode' => urlencode($album['album']), -- cgit v1.2.3 From bb0f3afb71add9dd8bf5cf160d1d2708a32f1119 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Thu, 12 Jan 2017 18:52:29 -0800 Subject: default cover photo support. --- include/channel.php | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) (limited to 'include') diff --git a/include/channel.php b/include/channel.php index caf3ded71..5d92b4769 100644 --- a/include/channel.php +++ b/include/channel.php @@ -1705,21 +1705,26 @@ function get_zcard($channel, $observer_hash = '', $args = array()) { $maxwidth = (($args['width']) ? intval($args['width']) : 0); $maxheight = (($args['height']) ? intval($args['height']) : 0); - if(($maxwidth > 1200) || ($maxwidth < 1)) + if(($maxwidth > 1200) || ($maxwidth < 1)) { $maxwidth = 1200; + $cover_width = 1200; + } if($maxwidth <= 425) { $width = 425; + $cover_width = 425; $size = 'hz_small'; $cover_size = PHOTO_RES_COVER_425; $pphoto = array('mimetype' => $channel['xchan_photo_mimetype'], 'width' => 80 , 'height' => 80, 'href' => $channel['xchan_photo_m']); } elseif($maxwidth <= 900) { $width = 900; + $cover_width = 850; $size = 'hz_medium'; $cover_size = PHOTO_RES_COVER_850; $pphoto = array('mimetype' => $channel['xchan_photo_mimetype'], 'width' => 160 , 'height' => 160, 'href' => $channel['xchan_photo_l']); } elseif($maxwidth <= 1200) { $width = 1200; + $cover_width = 1200; $size = 'hz_large'; $cover_size = PHOTO_RES_COVER_1200; $pphoto = array('mimetype' => $channel['xchan_photo_mimetype'], 'width' => 300 , 'height' => 300, 'href' => $channel['xchan_photo_l']); @@ -1741,7 +1746,8 @@ function get_zcard($channel, $observer_hash = '', $args = array()) { $cover = $r[0]; $cover['href'] = z_root() . '/photo/' . $r[0]['resource_id'] . '-' . $r[0]['imgscale']; } else { - $cover = $pphoto; + $default_cover = get_config('system','default_cover_photo','pexels-94622'); + $cover = [ 'href' => z_root() . '/images/default_cover_photos/' . $default_cover . '/' . $cover_width . '.jpg' ]; } $o .= replace_macros(get_markup_template('zcard.tpl'), array( @@ -1765,23 +1771,28 @@ function get_zcard_embed($channel, $observer_hash = '', $args = array()) { $maxwidth = (($args['width']) ? intval($args['width']) : 0); $maxheight = (($args['height']) ? intval($args['height']) : 0); - if(($maxwidth > 1200) || ($maxwidth < 1)) + if(($maxwidth > 1200) || ($maxwidth < 1)) { $maxwidth = 1200; + $cover_width = 1200; + } if($maxwidth <= 425) { $width = 425; + $cover_width = 425; $size = 'hz_small'; $cover_size = PHOTO_RES_COVER_425; $pphoto = array('mimetype' => $channel['xchan_photo_mimetype'], 'width' => 80 , 'height' => 80, 'href' => $channel['xchan_photo_m']); } elseif($maxwidth <= 900) { $width = 900; + $cover_width = 850; $size = 'hz_medium'; $cover_size = PHOTO_RES_COVER_850; $pphoto = array('mimetype' => $channel['xchan_photo_mimetype'], 'width' => 160 , 'height' => 160, 'href' => $channel['xchan_photo_l']); } elseif($maxwidth <= 1200) { $width = 1200; + $cover_width = 1200; $size = 'hz_large'; $cover_size = PHOTO_RES_COVER_1200; $pphoto = array('mimetype' => $channel['xchan_photo_mimetype'], 'width' => 300 , 'height' => 300, 'href' => $channel['xchan_photo_l']); @@ -1799,8 +1810,10 @@ function get_zcard_embed($channel, $observer_hash = '', $args = array()) { if($r) { $cover = $r[0]; $cover['href'] = z_root() . '/photo/' . $r[0]['resource_id'] . '-' . $r[0]['imgscale']; - } else { - $cover = $pphoto; + } + else { + $default_cover = get_config('system','default_cover_photo','pexels-94622'); + $cover = [ 'href' => z_root() . '/images/default_cover_photos/' . $default_cover . '/' . $cover_width . '.jpg' ]; } $o .= replace_macros(get_markup_template('zcard_embed.tpl'),array( -- cgit v1.2.3 From 8ef84e2aa74bdc280b6a450a553d71ba492a01cc Mon Sep 17 00:00:00 2001 From: Mario Vavti Date: Fri, 13 Jan 2017 11:22:50 +0100 Subject: possibly improve the album list query and save the result in App::$data --- include/photos.php | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'include') diff --git a/include/photos.php b/include/photos.php index 8496c2c86..7ddbe43b9 100644 --- a/include/photos.php +++ b/include/photos.php @@ -464,10 +464,15 @@ 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) + //$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", + intval($channel_id) ); // add various encodings to the array so we can just loop through and pick them out in a template @@ -490,6 +495,8 @@ function photos_albums_list($channel, $observer, $sort_key = 'album', $direction } } + App::$data['albums'] = $ret; + return $ret; } -- cgit v1.2.3 From 4f1e4ffa70f5a822367eafec914ff8853561210d Mon Sep 17 00:00:00 2001 From: zotlabs Date: Fri, 13 Jan 2017 13:22:36 -0800 Subject: several minor app nits --- include/widgets.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'include') diff --git a/include/widgets.php b/include/widgets.php index dde8e7cd0..d3bdb3313 100644 --- a/include/widgets.php +++ b/include/widgets.php @@ -104,7 +104,8 @@ function widget_appselect($arr) { '$authed' => ((local_channel()) ? true : false), '$personal' => t('Personal'), '$new' => t('New App'), - '$edit' => t('Edit App') + '$edit' => t('Edit Apps'), + '$cat' => ((array_key_exists('cat',$_REQUEST)) ? $_REQUEST['cat'] : '') )); } @@ -441,11 +442,13 @@ function widget_appcategories($arr) { if(! local_channel()) return ''; - $cat = ((x($_REQUEST,'cat')) ? htmlspecialchars($_REQUEST['cat'],ENT_COMPAT,'UTF-8') : ''); - $srchurl = App::$query_string; + $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) -- cgit v1.2.3 From a36d74dad5dbc080007ba85d841ee0f74c9c919d Mon Sep 17 00:00:00 2001 From: Mario Vavti Date: Sun, 15 Jan 2017 13:23:28 +0100 Subject: do not choke if photo_factory() returns null --- include/network.php | 4 ++++ include/photo/photo_driver.php | 4 +++- 2 files changed, 7 insertions(+), 1 deletion(-) (limited to 'include') diff --git a/include/network.php b/include/network.php index 451ce12a1..d571ec2ce 100644 --- a/include/network.php +++ b/include/network.php @@ -714,6 +714,10 @@ function scale_external_images($s, $include_link = true, $scale_replace = false) if($i['success']) { $ph = photo_factory($i['body'], $type); + + if(! is_object($ph)) + continue; + if($ph->is_valid()) { $orig_width = $ph->getWidth(); $orig_height = $ph->getHeight(); diff --git a/include/photo/photo_driver.php b/include/photo/photo_driver.php index af4fd0a30..c8b3c3782 100644 --- a/include/photo/photo_driver.php +++ b/include/photo/photo_driver.php @@ -11,8 +11,10 @@ function photo_factory($data, $type = null) { 'image/svg+xml' ); - if($type && in_array(strtolower($type),$unsupported_types)) + if($type && in_array(strtolower($type),$unsupported_types)) { + logger('photo_factory: unsupported image type'); return null; + } $ignore_imagick = get_config('system', 'ignore_imagick'); -- cgit v1.2.3 From b20cce1408445a48e8aec133b6df44bcd71c6321 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Sun, 15 Jan 2017 15:24:51 -0800 Subject: attach_delete() - remove photo resources even if the attach table row wasn't found. --- include/attach.php | 35 +++++++++++++++++++++++------------ 1 file changed, 23 insertions(+), 12 deletions(-) (limited to 'include') diff --git a/include/attach.php b/include/attach.php index ba2f60a90..dc5bfd308 100644 --- a/include/attach.php +++ b/include/attach.php @@ -1279,8 +1279,10 @@ function attach_delete($channel_id, $resource, $is_photo = 0) { intval($channel_id) ); - if(! $r) + if(! $r) { + attach_drop_photo($channel_id,$resource); return; + } $cloudpath = get_parent_cloudpath($channel_id, $channel_address, $resource); $object = get_file_activity_object($channel_id, $resource, $cloudpath); @@ -1326,19 +1328,10 @@ function attach_delete($channel_id, $resource, $is_photo = 0) { ); if($r[0]['is_photo']) { - $x = q("select id, item_hidden from item where resource_id = '%s' and resource_type = 'photo' and uid = %d", - dbesc($resource), - intval($channel_id) - ); - if($x) { - drop_item($x[0]['id'],false,(($x[0]['item_hidden']) ? DROPITEM_NORMAL : DROPITEM_PHASE1),true); - } - q("DELETE FROM photo WHERE uid = %d AND resource_id = '%s'", - intval($channel_id), - dbesc($resource) - ); + attach_drop_photo($channel_id,$resource); } + // update the parent folder's lastmodified timestamp $e = q("UPDATE attach SET edited = '%s' WHERE hash = '%s' AND uid = %d", dbesc(datetime_convert()), @@ -1351,6 +1344,24 @@ function attach_delete($channel_id, $resource, $is_photo = 0) { return; } + +function attach_drop_photo($channel_id,$resource) { + + $x = q("select id, item_hidden from item where resource_id = '%s' and resource_type = 'photo' and uid = %d", + dbesc($resource), + intval($channel_id) + ); + if($x) { + drop_item($x[0]['id'],false,(($x[0]['item_hidden']) ? DROPITEM_NORMAL : DROPITEM_PHASE1),true); + } + q("DELETE FROM photo WHERE uid = %d AND resource_id = '%s'", + intval($channel_id), + dbesc($resource) + ); + +} + + /** * @brief Returns path to file in cloud/. * -- cgit v1.2.3 From d7080defd3b9d72a6e7988ce72a0ef2cdd39bb70 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Sun, 15 Jan 2017 16:08:51 -0800 Subject: Still trying to make the documentation link just a wee bit more obvious. --- include/nav.php | 1 + 1 file changed, 1 insertion(+) (limited to 'include') diff --git a/include/nav.php b/include/nav.php index 2762e2a14..e389308ff 100644 --- a/include/nav.php +++ b/include/nav.php @@ -244,6 +244,7 @@ $powered_by = ''; App::$page['nav'] .= replace_macros($tpl, array( '$baseurl' => z_root(), + '$fulldocs' => t('Documentation'), '$sitelocation' => $sitelocation, '$nav' => $x['nav'], '$banner' => $banner, -- cgit v1.2.3 From c32bc9dda4dc08f2e4e72dc91c78457a0383244e Mon Sep 17 00:00:00 2001 From: zotlabs Date: Sun, 15 Jan 2017 19:51:14 -0800 Subject: more integration of vcard and profiles --- include/connections.php | 7 ++++++- include/text.php | 4 ++++ 2 files changed, 10 insertions(+), 1 deletion(-) (limited to 'include') diff --git a/include/connections.php b/include/connections.php index 31e941e95..8daa008c9 100644 --- a/include/connections.php +++ b/include/connections.php @@ -632,6 +632,9 @@ function random_profile() { function update_vcard($arr,$vcard = null) { + + // logger('update_vcard: ' . print_r($arr,true)); + $fn = $arr['fn']; @@ -816,8 +819,10 @@ function get_vcard_array($vc,$id) { $type = (($adr['TYPE']) ? vcard_translate_type((string)$adr['TYPE']) : ''); $adrs[] = [ 'type' => $type, - 'address' => escape_tags($adr->getParts()) + 'address' => $adr->getParts() ]; + $last_entry = end($adrs); + array_walk($adrs[$last_entry],'array_escape_tags'); } } diff --git a/include/text.php b/include/text.php index bc1eff7db..f5b1803c2 100644 --- a/include/text.php +++ b/include/text.php @@ -3128,4 +3128,8 @@ function cleanup_bbcode($body) { function array_trim(&$v,$k) { $v = trim($v); +} + +function array_escape_tags(&$v,$k) { + $v = escape_tags($v); } \ No newline at end of file -- cgit v1.2.3 From 0ef2cd871956a45cf947e976c59b1d29744959b6 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Sun, 15 Jan 2017 19:55:59 -0800 Subject: array pointer in wrong place --- 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 8daa008c9..def80441a 100644 --- a/include/connections.php +++ b/include/connections.php @@ -822,7 +822,7 @@ function get_vcard_array($vc,$id) { 'address' => $adr->getParts() ]; $last_entry = end($adrs); - array_walk($adrs[$last_entry],'array_escape_tags'); + array_walk($adrs[$last_entry]['address'],'array_escape_tags'); } } -- cgit v1.2.3 From e5662dc89367dc70f6a07282c807807261503726 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Sun, 15 Jan 2017 21:23:43 -0800 Subject: vcard export from profile --- include/channel.php | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'include') diff --git a/include/channel.php b/include/channel.php index 5d92b4769..83f48f361 100644 --- a/include/channel.php +++ b/include/channel.php @@ -1278,10 +1278,14 @@ function advanced_profile(&$a) { // logger('mod_profile: things: ' . print_r($things,true), LOGGER_DATA); + $exportlink = ((App::$profile['profile_vcard']) ? zid(z_root() . '/profile/' . App::$profile['channel_address'] . '/vcard') : ''); + return replace_macros($tpl, array( '$title' => t('Profile'), '$canlike' => (($profile['canlike'])? true : false), '$likethis' => t('Like this thing'), + '$export' => t('Export'), + '$exportlink' => $exportlink, '$profile' => $profile, '$fields' => $clean_fields, '$editmenu' => profile_edit_menu(App::$profile['profile_uid']), -- cgit v1.2.3 From b6595a44d1f6db38c104abaa3c24f42223316ec5 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Tue, 17 Jan 2017 17:41:19 -0800 Subject: native wiki stuff --- include/items.php | 25 ++++++++++++++++--------- include/widgets.php | 19 +++++++++++++++---- 2 files changed, 31 insertions(+), 13 deletions(-) (limited to 'include') diff --git a/include/items.php b/include/items.php index f7d8691cc..7fb5dc5da 100755 --- a/include/items.php +++ b/include/items.php @@ -302,7 +302,7 @@ function add_source_route($iid, $hash) { * * \e boolean \b success true or false * * \e array \b activity the resulting activity if successful */ -function post_activity_item($arr) { +function post_activity_item($arr,$allow_code = false,$deliver = true) { $ret = array('success' => false); @@ -382,11 +382,11 @@ function post_activity_item($arr) { return $ret; } - $post = item_store($arr); + $post = item_store($arr,$allow_code,$deliver); if($post['success']) $post_id = $post['item_id']; - if($post_id) { + if($post_id && $deliver) { $arr['id'] = $post_id; call_hooks('post_local_end', $arr); Zotlabs\Daemon\Master::Summon(array('Notifier','activity',$post_id)); @@ -1564,8 +1564,11 @@ function item_store($arr, $allow_exec = false, $deliver = true) { $arr['attach'] = json_encode($arr['attach']); } - $arr['aid'] = ((x($arr,'aid')) ? intval($arr['aid']) : 0); - $arr['mid'] = ((x($arr,'mid')) ? notags(trim($arr['mid'])) : random_string()); + $arr['aid'] = ((x($arr,'aid')) ? intval($arr['aid']) : 0); + $arr['mid'] = ((x($arr,'mid')) ? notags(trim($arr['mid'])) : random_string()); + $arr['revision'] = ((x($arr,'revision') && intval($arr['revision']) > 0) ? intval($arr['revision']) : 0); +logger('revision: ' . $arr['revision']); + $arr['author_xchan'] = ((x($arr,'author_xchan')) ? notags(trim($arr['author_xchan'])) : ''); $arr['owner_xchan'] = ((x($arr,'owner_xchan')) ? notags(trim($arr['owner_xchan'])) : ''); $arr['created'] = ((x($arr,'created') !== false) ? datetime_convert('UTC','UTC',$arr['created']) : datetime_convert()); @@ -1726,9 +1729,10 @@ function item_store($arr, $allow_exec = false, $deliver = true) { if($parent_deleted) $arr['item_deleted'] = 1; - $r = q("SELECT id FROM item WHERE mid = '%s' AND uid = %d LIMIT 1", + $r = q("SELECT id FROM item WHERE mid = '%s' AND uid = %d and revision = %d LIMIT 1", dbesc($arr['mid']), - intval($arr['uid']) + intval($arr['uid']), + intval($arr['revision']) ); if($r) { logger('item_store: duplicate item ignored. ' . print_r($arr,true)); @@ -1783,9 +1787,10 @@ function item_store($arr, $allow_exec = false, $deliver = true) { // find the item we just created - $r = q("SELECT * FROM item WHERE mid = '%s' AND uid = %d ORDER BY id ASC ", + $r = q("SELECT * FROM item WHERE mid = '%s' AND uid = %d and revision = %d ORDER BY id ASC ", $arr['mid'], // already dbesc'd - intval($arr['uid']) + intval($arr['uid']), + intval($arr['revision']) ); if($r && count($r)) { @@ -1996,6 +2001,8 @@ function item_store_update($arr,$allow_exec = false, $deliver = true) { $arr['edited'] = ((x($arr,'edited') !== false) ? datetime_convert('UTC','UTC',$arr['edited']) : datetime_convert()); $arr['expires'] = ((x($arr,'expires') !== false) ? datetime_convert('UTC','UTC',$arr['expires']) : $orig[0]['expires']); + $arr['revision'] = ((x($arr,'revision') && $arr['revision'] > 0) ? intval($arr['revision']) : 0); + if(array_key_exists('comments_closed',$arr) && $arr['comments_closed'] > NULL_DATE) $arr['comments_closed'] = datetime_convert('UTC','UTC',$arr['comments_closed']); else diff --git a/include/widgets.php b/include/widgets.php index d3bdb3313..94d638d77 100644 --- a/include/widgets.php +++ b/include/widgets.php @@ -903,7 +903,12 @@ function widget_chatroom_members() { function widget_wiki_list($arr) { require_once("include/wiki.php"); $channel = channelx_by_n(App::$profile_uid); - $wikis = wiki_list($channel, get_observer_hash()); + + if(defined('NATIVE_WIKI')) + $wikis = Zotlabs\Lib\NativeWiki::listwikis($channel,get_observer_hash()); + else + $wikis = wiki_list($channel, get_observer_hash()); + if($wikis) { return replace_macros(get_markup_template('wikilist_widget.tpl'), array( '$header' => t('Wiki List'), @@ -918,6 +923,8 @@ function widget_wiki_pages($arr) { require_once("include/wiki.php"); $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); @@ -925,11 +932,15 @@ function widget_wiki_pages($arr) { $not_refresh = true; } $pages = array(); - if (!array_key_exists('resource_id', $arr)) { + if (! array_key_exists('resource_id', $arr)) { $hide = true; } else { - $p = wiki_page_list($arr['resource_id']); - if ($p['pages']) { + if(defined('NATIVE_WIKI')) + $p = Zotlabs\Lib\NativeWikiPage::page_list($c['channel_id'],get_observer_hash(),$arr['resource_id']); + else + $p = wiki_page_list($arr['resource_id']); + + if($p['pages']) { $pages = $p['pages']; $w = $p['wiki']; // Wiki item record is $w['wiki'] -- cgit v1.2.3 From 7f944515dedd5c7a7d36fe5ed3b6bd884eb9be40 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Tue, 17 Jan 2017 23:39:28 -0800 Subject: more work on native wiki - revert now works; still remaining: diff, delete-page, rename-page and export wiki. --- include/widgets.php | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) (limited to 'include') diff --git a/include/widgets.php b/include/widgets.php index 94d638d77..ecbefff76 100644 --- a/include/widgets.php +++ b/include/widgets.php @@ -954,6 +954,7 @@ function widget_wiki_pages($arr) { 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, @@ -969,12 +970,23 @@ function widget_wiki_page_history($arr) { require_once("include/wiki.php"); $pageUrlName = ((array_key_exists('pageUrlName', $arr)) ? $arr['pageUrlName'] : ''); $resource_id = ((array_key_exists('resource_id', $arr)) ? $arr['resource_id'] : ''); - $pageHistory = wiki_page_history(array('resource_id' => $resource_id, 'pageUrlName' => $pageUrlName)); + if(defined('NATIVE_WIKI')) { + $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') + )); + } + else { + $pageHistory = wiki_page_history(array('resource_id' => $resource_id, 'pageUrlName' => $pageUrlName)); - return replace_macros(get_markup_template('wiki_page_history.tpl'), array( + return replace_macros(get_markup_template('wiki_page_history.tpl'), array( '$pageHistory' => $pageHistory['history'], '$permsWrite' => $arr['permsWrite'] - )); + )); + } } function widget_bookmarkedchats($arr) { -- cgit v1.2.3 From d4e58e94f6777f0a7ab5733d889f29bdb9366b14 Mon Sep 17 00:00:00 2001 From: Hubzilla Date: Wed, 18 Jan 2017 18:18:37 -0800 Subject: native wiki updates --- include/widgets.php | 39 ++++++++++++--------------------------- 1 file changed, 12 insertions(+), 27 deletions(-) (limited to 'include') diff --git a/include/widgets.php b/include/widgets.php index ecbefff76..799310908 100644 --- a/include/widgets.php +++ b/include/widgets.php @@ -901,13 +901,10 @@ function widget_chatroom_members() { } function widget_wiki_list($arr) { - require_once("include/wiki.php"); + $channel = channelx_by_n(App::$profile_uid); - if(defined('NATIVE_WIKI')) - $wikis = Zotlabs\Lib\NativeWiki::listwikis($channel,get_observer_hash()); - else - $wikis = wiki_list($channel, get_observer_hash()); + $wikis = Zotlabs\Lib\NativeWiki::listwikis($channel,get_observer_hash()); if($wikis) { return replace_macros(get_markup_template('wikilist_widget.tpl'), array( @@ -921,7 +918,6 @@ function widget_wiki_list($arr) { function widget_wiki_pages($arr) { - require_once("include/wiki.php"); $channelname = ((array_key_exists('channel',$arr)) ? $arr['channel'] : ''); $c = channelx_by_nick($channelname); @@ -935,10 +931,7 @@ function widget_wiki_pages($arr) { if (! array_key_exists('resource_id', $arr)) { $hide = true; } else { - if(defined('NATIVE_WIKI')) - $p = Zotlabs\Lib\NativeWikiPage::page_list($c['channel_id'],get_observer_hash(),$arr['resource_id']); - else - $p = wiki_page_list($arr['resource_id']); + $p = Zotlabs\Lib\NativeWikiPage::page_list($c['channel_id'],get_observer_hash(),$arr['resource_id']); if($p['pages']) { $pages = $p['pages']; @@ -967,26 +960,18 @@ function widget_wiki_pages($arr) { } function widget_wiki_page_history($arr) { - require_once("include/wiki.php"); + $pageUrlName = ((array_key_exists('pageUrlName', $arr)) ? $arr['pageUrlName'] : ''); $resource_id = ((array_key_exists('resource_id', $arr)) ? $arr['resource_id'] : ''); - if(defined('NATIVE_WIKI')) { - $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') - )); - } - else { - $pageHistory = wiki_page_history(array('resource_id' => $resource_id, 'pageUrlName' => $pageUrlName)); - return replace_macros(get_markup_template('wiki_page_history.tpl'), array( - '$pageHistory' => $pageHistory['history'], - '$permsWrite' => $arr['permsWrite'] - )); - } + $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) { -- cgit v1.2.3 From 7dfadfea4a637ce5566eb45f2d1adedf04bd04f3 Mon Sep 17 00:00:00 2001 From: Hubzilla Date: Wed, 18 Jan 2017 18:45:17 -0800 Subject: urlencode the message-id component of generated /display/ links; in most cases this will be a no-op, unless the message-id is a url of some kind from a different provider. --- include/conversation.php | 2 +- include/event.php | 4 ++-- include/items.php | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) (limited to 'include') diff --git a/include/conversation.php b/include/conversation.php index 0ff368e6e..94cd9168e 100644 --- a/include/conversation.php +++ b/include/conversation.php @@ -733,7 +733,7 @@ function conversation(&$a, $items, $mode, $update, $page_mode = 'traditional', $ 'like' => '', 'dislike' => '', 'comment' => '', - 'conv' => (($preview) ? '' : array('href'=> z_root() . '/display/' . $item['mid'], 'title'=> t('View in context'))), + 'conv' => (($preview) ? '' : array('href'=> z_root() . '/display/' . urlencode($item['mid']), 'title'=> t('View in context'))), 'previewing' => $previewing, 'wait' => t('Please wait'), 'thread_level' => 1, diff --git a/include/event.php b/include/event.php index f3366fb69..85f14c5f9 100644 --- a/include/event.php +++ b/include/event.php @@ -1016,9 +1016,9 @@ function event_store_item($arr, $event) { // otherwise we'll fallback to /display/$message_id if($wall) - $item_arr['plink'] = z_root() . '/channel/' . $z[0]['channel_address'] . '/?f=&mid=' . $item_arr['mid']; + $item_arr['plink'] = z_root() . '/channel/' . $z[0]['channel_address'] . '/?f=&mid=' . urlencode($item_arr['mid']); else - $item_arr['plink'] = z_root() . '/display/' . $item_arr['mid']; + $item_arr['plink'] = z_root() . '/display/' . urlencode($item_arr['mid']); $x = q("select * from xchan where xchan_hash = '%s' limit 1", dbesc($arr['event_xchan']) diff --git a/include/items.php b/include/items.php index 7fb5dc5da..da49df397 100755 --- a/include/items.php +++ b/include/items.php @@ -1624,7 +1624,7 @@ logger('revision: ' . $arr['revision']); if($d2 > $d1) $arr['item_delayed'] = 1; - $arr['llink'] = z_root() . '/display/' . $arr['mid']; + $arr['llink'] = z_root() . '/display/' . urlencode($arr['mid']); if(! $arr['plink']) $arr['plink'] = $arr['llink']; @@ -2279,7 +2279,7 @@ function send_status_notifications($post_id,$item) { if($unfollowed) return; - $link = z_root() . '/display/' . $item['mid']; + $link = z_root() . '/display/' . urlencode($item['mid']); $y = q("select id from notify where link = '%s' and uid = %d limit 1", dbesc($link), -- cgit v1.2.3 From 5ce96b9b95c6b3497bfb49fd086a23a2dedb4e2e Mon Sep 17 00:00:00 2001 From: Hubzilla Date: Wed, 18 Jan 2017 19:36:06 -0800 Subject: more urlencoding of message-ids which are used in links --- include/activities.php | 2 +- include/items.php | 2 +- include/photos.php | 4 +- include/wiki.php | 664 ------------------------------------------------- 4 files changed, 4 insertions(+), 668 deletions(-) delete mode 100644 include/wiki.php (limited to 'include') diff --git a/include/activities.php b/include/activities.php index 3271db993..2671e668c 100644 --- a/include/activities.php +++ b/include/activities.php @@ -27,7 +27,7 @@ function profile_activity($changed, $value) { $arr['verb'] = ACTIVITY_UPDATE; $arr['obj_type'] = ACTIVITY_OBJ_PROFILE; - $arr['plink'] = z_root() . '/channel/' . $self['channel_address'] . '/?f=&mid=' . $arr['mid']; + $arr['plink'] = z_root() . '/channel/' . $self['channel_address'] . '/?f=&mid=' . urlencode($arr['mid']); $A = '[url=' . z_root() . '/channel/' . $self['channel_address'] . ']' . $self['channel_name'] . '[/url]'; diff --git a/include/items.php b/include/items.php index da49df397..88aa098b4 100755 --- a/include/items.php +++ b/include/items.php @@ -367,7 +367,7 @@ function post_activity_item($arr,$allow_code = false,$deliver = true) { $arr['comment_policy'] = map_scope(\Zotlabs\Access\PermissionLimits::Get($channel['channel_id'],'post_comments')); if ((! $arr['plink']) && (intval($arr['item_thread_top']))) { - $arr['plink'] = z_root() . '/channel/' . $channel['channel_address'] . '/?f=&mid=' . $arr['mid']; + $arr['plink'] = z_root() . '/channel/' . $channel['channel_address'] . '/?f=&mid=' . urlencode($arr['mid']); } diff --git a/include/photos.php b/include/photos.php index 7ddbe43b9..55cc2d945 100644 --- a/include/photos.php +++ b/include/photos.php @@ -402,7 +402,7 @@ function photo_upload($channel, $observer, $args) { $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=' . $arr['mid']; + $arr['plink'] = z_root() . '/channel/' . $channel['channel_address'] . '/?f=&mid=' . urlencode($arr['mid']); $arr['body'] = $summary; @@ -671,7 +671,7 @@ function photos_create_item($channel, $creator_hash, $photo, $visible = false) { $arr['deny_cid'] = $photo['deny_cid']; $arr['deny_gid'] = $photo['deny_gid']; - $arr['plink'] = z_root() . '/channel/' . $channel['channel_address'] . '/?f=&mid=' . $arr['mid']; + $arr['plink'] = z_root() . '/channel/' . $channel['channel_address'] . '/?f=&mid=' . urlencode($arr['mid']); $arr['body'] = '[zrl=' . z_root() . '/photos/' . $channel['channel_address'] . '/image/' . $photo['resource_id'] . ']' . '[zmg]' . z_root() . '/photo/' . $photo['resource_id'] . '-' . $photo['imgscale'] . '[/zmg]' diff --git a/include/wiki.php b/include/wiki.php deleted file mode 100644 index 922be6924..000000000 --- a/include/wiki.php +++ /dev/null @@ -1,664 +0,0 @@ - $wikis); -} - -function wiki_page_list($resource_id) { - // TODO: Create item table records for pages so that metadata like title can be applied - $w = wiki_get_wiki($resource_id); - if (!$w['path']) { - return array('pages' => null, 'wiki' => null); - } - - $pages[] = [ - 'resource_id' => '', - 'title' => 'Home', - 'url' => 'Home', - 'link_id' => 'id_wiki_home_0' - ]; - - if (is_dir($w['path']) === true) { - $files = array_diff(scandir($w['path']), array('.', '..', '.git')); - // TODO: Check that the files are all text files - $i = 1; - foreach($files as $file) { - // strip the file extension and unwrap URL encoding to leave HTML encoded name - $title = substr($file, 0, strrpos($file,'.')); - if(urldecode($title) !== 'Home') { - $pages[] = [ - 'resource_id' => $resource_id, - 'title' => urldecode($title), - 'url' => $title, - 'link_id' => 'id_' . substr($resource_id, 0, 10) . '_' . $i - ]; - $i++; - } - } - } - - return array('pages' => $pages, 'wiki' => $w); -} - -function wiki_init_wiki($channel, $wiki) { - // Store the path as a relative path, but pass absolute path to mkdir - $path = 'store/[data]/git/'.$channel['channel_address'].'/wiki/'.$wiki['urlName']; - if (!os_mkdir(__DIR__ . '/../' . $path, 0770, true)) { - logger('Error creating wiki path: ' . $path); - return null; - } - // Create GitRepo object - $git = new GitRepo($channel['channel_address'], null, false, $wiki['urlName'], __DIR__ . '/../' . $path); - if(!$git->initRepo()) { - logger('Error creating new git repo in ' . $git->path); - return null; - } - - return array('path' => $path); -} - -function wiki_create_wiki($channel, $observer_hash, $wiki, $acl) { - $wikiinit = wiki_init_wiki($channel, $wiki); - if (!$wikiinit['path']) { - notice('Error creating wiki'); - return array('item' => null, 'success' => false); - } - $path = $wikiinit['path']; - // Generate unique resource_id using the same method as item_message_id() - do { - $dups = false; - $resource_id = random_string(); - $r = q("SELECT mid FROM item WHERE resource_id = '%s' AND resource_type = '%s' AND uid = %d LIMIT 1", - dbesc($resource_id), - dbesc(WIKI_ITEM_RESOURCE_TYPE), - intval($channel['channel_id']) - ); - if (count($r)) - $dups = true; - } while ($dups == true); - $ac = $acl->get(); - $mid = item_message_id(); - $arr = array(); // Initialize the array of parameters for the post - $item_hidden = ((intval($wiki['postVisible']) === 0) ? 1 : 0); - $wiki_url = z_root() . '/wiki/' . $channel['channel_address'] . '/' . $wiki['urlName']; - $arr['aid'] = $channel['channel_account_id']; - $arr['uid'] = $channel['channel_id']; - $arr['mid'] = $mid; - $arr['parent_mid'] = $mid; - $arr['item_hidden'] = $item_hidden; - $arr['resource_type'] = WIKI_ITEM_RESOURCE_TYPE; - $arr['resource_id'] = $resource_id; - $arr['owner_xchan'] = $channel['channel_hash']; - $arr['author_xchan'] = $observer_hash; - $arr['plink'] = z_root() . '/channel/' . $channel['channel_address'] . '/?f=&mid=' . $arr['mid']; - $arr['llink'] = $arr['plink']; - $arr['title'] = $wiki['htmlName']; // name of new wiki; - $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['item_wall'] = 1; - $arr['item_origin'] = 1; - $arr['item_thread_top'] = 1; - $arr['item_private'] = intval($acl->is_private()); - $arr['verb'] = ACTIVITY_CREATE; - $arr['obj_type'] = ACTIVITY_OBJ_WIKI; - $arr['body'] = '[table][tr][td][h1]New Wiki[/h1][/td][/tr][tr][td][zrl=' . $wiki_url . ']' . $wiki['htmlName'] . '[/zrl][/td][/tr][/table]'; - // Save the path using iconfig. The file path should not be shared with other hubs - if (!set_iconfig($arr, 'wiki', 'path', $path, false)) { - return array('item' => null, 'success' => false); - } - // Save the wiki name information using iconfig. This is shareable. - if (!set_iconfig($arr, 'wiki', 'rawName', $wiki['rawName'], true)) { - return array('item' => null, 'success' => false); - } - if (!set_iconfig($arr, 'wiki', 'htmlName', $wiki['htmlName'], true)) { - return array('item' => null, 'success' => false); - } - if (!set_iconfig($arr, 'wiki', 'urlName', $wiki['urlName'], true)) { - return array('item' => null, 'success' => false); - } - if (!set_iconfig($arr, 'wiki', 'mimeType', $wiki['mimeType'], true)) { - return array('item' => null, 'success' => false); - } - $post = item_store($arr); - $item_id = $post['item_id']; - - if ($item_id) { - \Zotlabs\Daemon\Master::Summon(array('Notifier', 'activity', $item_id)); - return array('item' => $post['item'], 'success' => true); - } else { - return array('item' => null, 'success' => false); - } -} - -function wiki_delete_wiki($resource_id) { - - $w = wiki_get_wiki($resource_id); - $item = $w['wiki']; - if (!$item || !$w['path']) { - return array('item' => null, 'success' => false); - } else { - $drop = drop_item($item['id'], false, DROPITEM_NORMAL, true); - $pathdel = rrmdir($w['path']); - if ($pathdel) { - info('Wiki files deleted successfully'); - } - return array('item' => $item, 'success' => (($drop === 1 && $pathdel) ? true : false)); - } -} - -function wiki_get_wiki($resource_id) { - $item = q("SELECT * FROM item WHERE resource_type = '%s' AND resource_id = '%s' AND item_deleted = 0 limit 1", - dbesc(WIKI_ITEM_RESOURCE_TYPE), - dbesc($resource_id) - ); - if (!$item) { - return array('wiki' => null, 'path' => null); - } else { - $w = $item[0]; // wiki item table record - // Get wiki metadata - $rawName = get_iconfig($w, 'wiki', 'rawName'); - $htmlName = get_iconfig($w, 'wiki', 'htmlName'); - $urlName = get_iconfig($w, 'wiki', 'urlName'); - $mimeType = get_iconfig($w, 'wiki', 'mimeType'); - - $path = get_iconfig($w, 'wiki', 'path'); - if (!realpath(__DIR__ . '/../' . $path)) { - return array('wiki' => null, 'path' => null); - } - // Path to wiki exists - $abs_path = realpath(__DIR__ . '/../' . $path); - return array( - 'wiki' => $w, - 'path' => $abs_path, - 'rawName' => $rawName, - 'htmlName' => $htmlName, - 'urlName' => $urlName, - 'mimeType' => $mimeType - ); - } -} - -function wiki_exists_by_name($uid, $urlName) { - $item = q("SELECT id,resource_id FROM item WHERE resource_type = '%s' AND title = '%s' AND uid = '%s' AND item_deleted = 0 limit 1", - dbesc(WIKI_ITEM_RESOURCE_TYPE), - dbesc(escape_tags(urldecode($urlName))), - dbesc($uid) - ); - if (!$item) { - return array('id' => null, 'resource_id' => null); - } else { - return array('id' => $item[0]['id'], 'resource_id' => $item[0]['resource_id']); - } -} - -function wiki_get_permissions($resource_id, $owner_id, $observer_hash) { - // TODO: For now, only the owner can edit - $sql_extra = item_permissions_sql($owner_id, $observer_hash); - - if(local_channel() && local_channel == $owner_id) { - return [ 'read' => true, 'write' => true, 'success' => true ]; - } - - $r = q("SELECT * FROM item WHERE uid = %d and resource_type = '%s' AND resource_id = '%s' $sql_extra LIMIT 1", - intval($owner_id), - dbesc(WIKI_ITEM_RESOURCE_TYPE), - dbesc($resource_id) - ); - - if (!$r) { - return array('read' => false, 'write' => false, 'success' => true); - } else { - // TODO: Create a new permission setting for wiki analogous to webpages. Until - // then, use webpage permissions - $write = perm_is_allowed($owner_id, $observer_hash,'write_pages'); - return array('read' => true, 'write' => $write, 'success' => true); - } -} - -function wiki_create_page($name, $resource_id) { - $w = wiki_get_wiki($resource_id); - if (!$w['path']) { - return array('page' => null, 'wiki' => null, 'message' => 'Wiki not found.', 'success' => false); - } - - $page = array('rawName' => $name, 'htmlName' => escape_tags($name), 'urlName' => urlencode(escape_tags($name)), 'fileName' => urlencode(escape_tags($name)) . wiki_get_file_ext($w)); - $page_path = $w['path'] . '/' . $page['fileName']; - if (is_file($page_path)) { - return array('page' => null, 'wiki' => null, 'message' => 'Page already exists.', 'success' => false); - } - // Create the page file in the wiki repo - if(!touch($page_path)) { - return array('page' => null, 'wiki' => null, 'message' => 'Page file cannot be created.', 'success' => false); - } else { - return array('page' => $page, 'wiki' => $w, 'message' => '', 'success' => true); - } - -} - -function wiki_rename_page($arr) { - $pageUrlName = ((array_key_exists('pageUrlName',$arr)) ? $arr['pageUrlName'] : ''); - $pageNewName = ((array_key_exists('pageNewName',$arr)) ? $arr['pageNewName'] : ''); - $resource_id = ((array_key_exists('resource_id',$arr)) ? $arr['resource_id'] : ''); - $w = wiki_get_wiki($resource_id); - if (!$w['path']) { - return array('message' => 'Wiki not found.', 'success' => false); - } - $page_path_old = $w['path'] . '/' . $pageUrlName . wiki_get_file_ext($w); - if (!is_readable($page_path_old) === true) { - return array('message' => 'Cannot read wiki page: ' . $page_path_old, 'success' => false); - } - $page = array('rawName' => $pageNewName, 'htmlName' => escape_tags($pageNewName), 'urlName' => urlencode(escape_tags($pageNewName)), 'fileName' => urlencode(escape_tags($pageNewName)) . wiki_get_file_ext($w)); - $page_path_new = $w['path'] . '/' . $page['fileName'] ; - if (is_file($page_path_new)) { - return array('message' => 'Page already exists.', 'success' => false); - } - // Rename the page file in the wiki repo - if(!rename($page_path_old, $page_path_new)) { - return array('message' => 'Error renaming page file.', 'success' => false); - } else { - return array('page' => $page, 'message' => '', 'success' => true); - } - -} - -function wiki_get_page_content($arr) { - $pageUrlName = ((array_key_exists('pageUrlName',$arr)) ? $arr['pageUrlName'] : ''); - $resource_id = ((array_key_exists('resource_id',$arr)) ? $arr['resource_id'] : ''); - $w = wiki_get_wiki($resource_id); - if (!$w['path']) { - return array('content' => null, 'message' => 'Error reading wiki', 'success' => false); - } - $page_path = $w['path'] . '/' . $pageUrlName . wiki_get_file_ext($w); - if (is_readable($page_path) === true) { - if(filesize($page_path) === 0) { - $content = ''; - } else { - $content = file_get_contents($page_path); - if(!$content) { - return array('content' => null, 'message' => 'Error reading page content', 'success' => false); - } - } - // TODO: Check that the files are all text files - return array('content' => json_encode($content), 'mimeType' => $w['mimeType'], 'message' => '', 'success' => true); - } -} - -function wiki_page_history($arr) { - $pageUrlName = ((array_key_exists('pageUrlName',$arr)) ? $arr['pageUrlName'] : ''); - $resource_id = ((array_key_exists('resource_id',$arr)) ? $arr['resource_id'] : ''); - $w = wiki_get_wiki($resource_id); - if (!$w['path']) { - return array('history' => null, 'message' => 'Error reading wiki', 'success' => false); - } - $page_path = $w['path'] . '/' . $pageUrlName . wiki_get_file_ext($w); - if (!is_readable($page_path) === true) { - return array('history' => null, 'message' => 'Cannot read wiki page: ' . $page_path, 'success' => false); - } - $reponame = ((array_key_exists('title', $w['wiki'])) ? $w['wiki']['title'] : 'repo'); - if($reponame === '') { - $reponame = 'repo'; - } - $git = new GitRepo('', null, false, $w['wiki']['title'], $w['path']); - try { - $gitlog = $git->git->log('', $page_path , array('limit' => 500)); - return array('history' => $gitlog, 'message' => '', 'success' => true); - } catch (\PHPGit\Exception\GitException $e) { - return array('history' => null, 'message' => 'GitRepo error thrown', 'success' => false); - } -} - -function wiki_prepare_content($s) { - - $text = preg_replace_callback('{ - (?:\n\n|\A\n?) - ( # $1 = the code block -- one or more lines, starting with a space/tab - (?> - [ ]{'.'4'.'} # Lines must start with a tab or a tab-width of spaces - .*\n+ - )+ - ) - ((?=^[ ]{0,'.'4'.'}\S)|\Z) # Lookahead for non-space at line-start, or end of doc - }xm', - 'wiki_prepare_content_callback', $s); - - return $text; -} - -function wiki_prepare_content_callback($matches) { - $codeblock = $matches[1]; - - $codeblock = htmlspecialchars($codeblock, ENT_NOQUOTES, UTF8, false); - return "\n\n" . $codeblock ; -} - - - -function wiki_save_page($arr) { - $pageUrlName = ((array_key_exists('pageUrlName',$arr)) ? $arr['pageUrlName'] : ''); - $content = ((array_key_exists('content',$arr)) ? purify_html(wiki_prepare_content($arr['content'])) : ''); - $resource_id = ((array_key_exists('resource_id',$arr)) ? $arr['resource_id'] : ''); - $w = wiki_get_wiki($resource_id); - if (!$w['path']) { - return array('message' => 'Error reading wiki', 'success' => false); - } - - $fileName = $pageUrlName . wiki_get_file_ext($w); - $page_path = $w['path'] . '/' . $fileName; - if (is_writable($page_path) === true) { - if(!file_put_contents($page_path, $content)) { - return array('message' => 'Error writing to page file', 'success' => false); - } - return array('message' => '', 'filename' => $filename, 'success' => true); - } else { - return array('message' => 'Page file not writable', 'success' => false); - } -} - -function wiki_delete_page($arr) { - $pageUrlName = ((array_key_exists('pageUrlName',$arr)) ? $arr['pageUrlName'] : ''); - $resource_id = ((array_key_exists('resource_id',$arr)) ? $arr['resource_id'] : ''); - $w = wiki_get_wiki($resource_id); - if (!$w['path']) { - return array('message' => 'Error reading wiki', 'success' => false); - } - $page_path = $w['path'] . '/' . $pageUrlName . wiki_get_file_ext($w); - if (is_writable($page_path) === true) { - if(!unlink($page_path)) { - return array('message' => 'Error deleting page file', 'success' => false); - } - return array('message' => '', 'success' => true); - } else { - return array('message' => 'Page file not writable', 'success' => false); - } -} - -function wiki_revert_page($arr) { - $pageUrlName = ((array_key_exists('pageUrlName',$arr)) ? $arr['pageUrlName'] : ''); - $resource_id = ((array_key_exists('resource_id',$arr)) ? $arr['resource_id'] : ''); - $commitHash = ((array_key_exists('commitHash',$arr)) ? $arr['commitHash'] : null); - if (! $commitHash) { - return array('content' => $content, 'message' => 'No commit was provided', 'success' => false); - } - $w = wiki_get_wiki($resource_id); - if (!$w['path']) { - return array('content' => $content, 'message' => 'Error reading wiki', 'success' => false); - } - $page_path = $w['path'] . '/' . $pageUrlName . wiki_get_file_ext($w); - if (is_writable($page_path) === true) { - - $reponame = ((array_key_exists('title', $w['wiki'])) ? urlencode($w['wiki']['title']) : 'repo'); - if($reponame === '') { - $reponame = 'repo'; - } - $git = new GitRepo($observer['xchan_addr'], null, false, $w['wiki']['title'], $w['path']); - $content = null; - try { - $git->setIdentity($observer['xchan_name'], $observer['xchan_addr']); - foreach ($git->git->tree($commitHash) as $object) { - if ($object['type'] == 'blob' && $object['file'] === $pageUrlName . wiki_get_file_ext($w)) { - $content = $git->git->cat->blob($object['hash']); - } - } - } catch (\PHPGit\Exception\GitException $e) { - return array('content' => $content, 'message' => 'GitRepo error thrown', 'success' => false); - } - return array('content' => $content, 'message' => '', 'success' => true); - } else { - return array('content' => $content, 'message' => 'Page file not writable', 'success' => false); - } -} - -function wiki_compare_page($arr) { - $pageUrlName = ((array_key_exists('pageUrlName',$arr)) ? $arr['pageUrlName'] : ''); - $resource_id = ((array_key_exists('resource_id',$arr)) ? $arr['resource_id'] : ''); - $currentCommit = ((array_key_exists('currentCommit',$arr)) ? $arr['currentCommit'] : 'HEAD'); - $compareCommit = ((array_key_exists('compareCommit',$arr)) ? $arr['compareCommit'] : null); - if (! $compareCommit) { - return array('message' => 'No compare commit was provided', 'success' => false); - } - $w = wiki_get_wiki($resource_id); - if (!$w['path']) { - return array('message' => 'Error reading wiki', 'success' => false); - } - $page_path = $w['path'] . '/' . $pageUrlName . wiki_get_file_ext($w); - if (is_readable($page_path) === true) { - $reponame = ((array_key_exists('title', $w['wiki'])) ? urlencode($w['wiki']['title']) : 'repo'); - if($reponame === '') { - $reponame = 'repo'; - } - $git = new GitRepo('', null, false, $w['wiki']['title'], $w['path']); - $compareContent = $currentContent = ''; - try { - foreach ($git->git->tree($currentCommit) as $object) { - if ($object['type'] == 'blob' && $object['file'] === $pageUrlName . wiki_get_file_ext($w)) { - $currentContent = $git->git->cat->blob($object['hash']); - } - } - foreach ($git->git->tree($compareCommit) as $object) { - if ($object['type'] == 'blob' && $object['file'] === $pageUrlName . wiki_get_file_ext($w)) { - $compareContent = $git->git->cat->blob($object['hash']); - } - } - require_once('library/class.Diff.php'); - $diff = Diff::toTable(Diff::compare($currentContent, $compareContent)); - } catch (\PHPGit\Exception\GitException $e) { - return array('message' => 'GitRepo error thrown', 'success' => false); - } - return array('diff' => $diff, 'message' => '', 'success' => true); - } else { - return array('message' => 'Page file not writable', 'success' => false); - } -} - -function wiki_git_commit($arr) { - $files = ((array_key_exists('files', $arr)) ? $arr['files'] : null); - $all = ((array_key_exists('all', $arr)) ? $arr['all'] : false); - $commit_msg = ((array_key_exists('commit_msg', $arr)) ? $arr['commit_msg'] : 'Repo updated'); - if(array_key_exists('resource_id', $arr)) { - $resource_id = $arr['resource_id']; - } else { - return array('message' => 'Wiki resource_id required for git commit', 'success' => false); - } - if(array_key_exists('observer', $arr)) { - $observer = $arr['observer']; - } else { - return array('message' => 'Observer required for git commit', 'success' => false); - } - $w = wiki_get_wiki($resource_id); - if (!$w['path']) { - return array('message' => 'Error reading wiki', 'success' => false); - } - $reponame = ((array_key_exists('title', $w['wiki'])) ? urlencode($w['wiki']['title']) : 'repo'); - if($reponame === '') { - $reponame = 'repo'; - } - $git = new GitRepo($observer['xchan_addr'], null, false, $w['wiki']['title'], $w['path']); - try { - $git->setIdentity($observer['xchan_name'], $observer['xchan_addr']); - if ($files === null) { - $options = array('all' => true); // git commit option to include all changes - } else { - $options = array('all' => $all); // git commit options\ - foreach ($files as $file) { - if (!$git->git->add($file)) { // add specified files to the git repo stage - if (!$git->git->reset->hard()) { - return array('message' => 'Error adding file to git stage: ' . $file . '. Error resetting git repo.', 'success' => false); - } - return array('message' => 'Error adding file to git stage: ' . $file, 'success' => false); - } - } - } - if ($git->commit($commit_msg, $options)) { - return array('message' => 'Wiki repo commit succeeded', 'success' => true); - } else { - return array('message' => 'Wiki repo commit failed', 'success' => false); - } - } catch (\PHPGit\Exception\GitException $e) { - return array('message' => 'GitRepo error thrown', 'success' => false); - } -} - -function wiki_convert_links($s, $wikiURL) { - - if (strpos($s,'[[') !== false) { - preg_match_all("/\[\[(.*?)\]\]/", $s, $match); - $pages = $pageURLs = array(); - foreach ($match[1] as $m) { - // TODO: Why do we need to double urlencode for this to work? - $pageURLs[] = urlencode(urlencode(escape_tags($m))); - $pages[] = $m; - } - $idx = 0; - while(strpos($s,'[[') !== false) { - $replace = ''.$pages[$idx].''; - $s = preg_replace("/\[\[(.*?)\]\]/", $replace, $s, 1); - $idx++; - } - } - return $s; -} - -/** - * Replace the instances of the string [toc] with a list element that will be populated by - * a table of contents by the JavaScript library - * @param string $s - * @return string - */ -function wiki_generate_toc($s) { - if (strpos($s,'[toc]') !== false) { - //$toc_md = wiki_toc($s); // Generate Markdown-formatted list prior to HTML render - $toc_md = '
    '; // use the available jQuery plugin http://ndabas.github.io/toc/ - $s = preg_replace("/\[toc\]/", $toc_md, $s, -1); - } - return $s; -} - -/** - * Converts a select set of bbcode tags. Much of the code is copied from include/bbcode.php - * @param string $s - * @return string - */ -function wiki_bbcode($s) { - - $s = str_replace(array('[baseurl]', '[sitename]'), array(z_root(), get_config('system', 'sitename')), $s); - - $observer = App::get_observer(); - if ($observer) { - $s1 = ''; - $s2 = ''; - $obsBaseURL = $observer['xchan_connurl']; - $obsBaseURL = preg_replace("/\/poco\/.*$/", '', $obsBaseURL); - $s = str_replace('[observer.baseurl]', $obsBaseURL, $s); - $s = str_replace('[observer.url]', $observer['xchan_url'], $s); - $s = str_replace('[observer.name]', $s1 . $observer['xchan_name'] . $s2, $s); - $s = str_replace('[observer.address]', $s1 . $observer['xchan_addr'] . $s2, $s); - $s = str_replace('[observer.webname]', substr($observer['xchan_addr'], 0, strpos($observer['xchan_addr'], '@')), $s); - $s = str_replace('[observer.photo]', '', $s); - } else { - $s = str_replace('[observer.baseurl]', '', $s); - $s = str_replace('[observer.url]', '', $s); - $s = str_replace('[observer.name]', '', $s); - $s = str_replace('[observer.address]', '', $s); - $s = str_replace('[observer.webname]', '', $s); - $s = str_replace('[observer.photo]', '', $s); - } - - return $s; -} - -function wiki_get_file_ext($arr) { - if($arr['mimeType'] == 'text/bbcode') - return '.bb'; - else - return '.md'; -} - -// This function is derived from -// http://stackoverflow.com/questions/32068537/generate-table-of-contents-from-markdown-in-php -function wiki_toc($content) { - // ensure using only "\n" as line-break - $source = str_replace(["\r\n", "\r"], "\n", $content); - - // look for markdown TOC items - preg_match_all( - '/^(?:=|-|#).*$/m', - $source, - $matches, - PREG_PATTERN_ORDER | PREG_OFFSET_CAPTURE - ); - - // preprocess: iterate matched lines to create an array of items - // where each item is an array(level, text) - $file_size = strlen($source); - foreach ($matches[0] as $item) { - $found_mark = substr($item[0], 0, 1); - if ($found_mark == '#') { - // text is the found item - $item_text = $item[0]; - $item_level = strrpos($item_text, '#') + 1; - $item_text = substr($item_text, $item_level); - } else { - // text is the previous line (empty if
    ) - $item_offset = $item[1]; - $prev_line_offset = strrpos($source, "\n", -($file_size - $item_offset + 2)); - $item_text = - substr($source, $prev_line_offset, $item_offset - $prev_line_offset - 1); - $item_text = trim($item_text); - $item_level = $found_mark == '=' ? 1 : 2; - } - if (!trim($item_text) OR strpos($item_text, '|') !== FALSE) { - // item is an horizontal separator or a table header, don't mind - continue; - } - $raw_toc[] = ['level' => $item_level, 'text' => trim($item_text)]; - } - $o = ''; - foreach($raw_toc as $t) { - $level = intval($t['level']); - $text = $t['text']; - switch ($level) { - case 1: - $li = '* '; - break; - case 2: - $li = ' * '; - break; - case 3: - $li = ' * '; - break; - case 4: - $li = ' * '; - break; - default: - $li = '* '; - break; - } - $o .= $li . $text . "\n"; - } - return $o; -} -- cgit v1.2.3 From 96f196febda488e1db2d9a677fd5eb736aa76ae6 Mon Sep 17 00:00:00 2001 From: Hubzilla Date: Thu, 19 Jan 2017 15:37:30 -0800 Subject: add gen_link_id() function to selectively encode/decode the message-id component of /display/ links for message-ids that contain troublesome characters --- include/conversation.php | 2 +- include/event.php | 2 +- include/items.php | 4 ++-- include/text.php | 9 ++++++++- 4 files changed, 12 insertions(+), 5 deletions(-) (limited to 'include') diff --git a/include/conversation.php b/include/conversation.php index 94cd9168e..285ee752f 100644 --- a/include/conversation.php +++ b/include/conversation.php @@ -733,7 +733,7 @@ function conversation(&$a, $items, $mode, $update, $page_mode = 'traditional', $ 'like' => '', 'dislike' => '', 'comment' => '', - 'conv' => (($preview) ? '' : array('href'=> z_root() . '/display/' . urlencode($item['mid']), 'title'=> t('View in context'))), + 'conv' => (($preview) ? '' : array('href'=> z_root() . '/display/' . gen_link_id($item['mid']), 'title'=> t('View in context'))), 'previewing' => $previewing, 'wait' => t('Please wait'), 'thread_level' => 1, diff --git a/include/event.php b/include/event.php index 85f14c5f9..cf1cc331d 100644 --- a/include/event.php +++ b/include/event.php @@ -1018,7 +1018,7 @@ function event_store_item($arr, $event) { if($wall) $item_arr['plink'] = z_root() . '/channel/' . $z[0]['channel_address'] . '/?f=&mid=' . urlencode($item_arr['mid']); else - $item_arr['plink'] = z_root() . '/display/' . urlencode($item_arr['mid']); + $item_arr['plink'] = z_root() . '/display/' . gen_link_id($item_arr['mid']); $x = q("select * from xchan where xchan_hash = '%s' limit 1", dbesc($arr['event_xchan']) diff --git a/include/items.php b/include/items.php index 88aa098b4..e4ead28c8 100755 --- a/include/items.php +++ b/include/items.php @@ -1624,7 +1624,7 @@ logger('revision: ' . $arr['revision']); if($d2 > $d1) $arr['item_delayed'] = 1; - $arr['llink'] = z_root() . '/display/' . urlencode($arr['mid']); + $arr['llink'] = z_root() . '/display/' . gen_link_id($arr['mid']); if(! $arr['plink']) $arr['plink'] = $arr['llink']; @@ -2279,7 +2279,7 @@ function send_status_notifications($post_id,$item) { if($unfollowed) return; - $link = z_root() . '/display/' . urlencode($item['mid']); + $link = z_root() . '/display/' . gen_link_id($item['mid']); $y = q("select id from notify where link = '%s' and uid = %d limit 1", dbesc($link), diff --git a/include/text.php b/include/text.php index f5b1803c2..1beefc6eb 100644 --- a/include/text.php +++ b/include/text.php @@ -3124,6 +3124,12 @@ function cleanup_bbcode($body) { } +function gen_link_id($mid) { + if(strpbrk($mid,':/&?<>"\'') !== false) + return 'b64.' . base64url_encode($mid); + return $mid; +} + // callback for array_walk function array_trim(&$v,$k) { @@ -3132,4 +3138,5 @@ function array_trim(&$v,$k) { function array_escape_tags(&$v,$k) { $v = escape_tags($v); -} \ No newline at end of file +} + -- cgit v1.2.3 From ece1dd1d7edc800085def93e50efc25a3dda55a7 Mon Sep 17 00:00:00 2001 From: Hubzilla Date: Fri, 20 Jan 2017 12:03:46 -0800 Subject: js errors with raw message-id, string update --- include/connections.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'include') diff --git a/include/connections.php b/include/connections.php index def80441a..f90644ec5 100644 --- a/include/connections.php +++ b/include/connections.php @@ -822,7 +822,8 @@ function get_vcard_array($vc,$id) { 'address' => $adr->getParts() ]; $last_entry = end($adrs); - array_walk($adrs[$last_entry]['address'],'array_escape_tags'); + if($adrs[$last_entry]['address']) + array_walk($adrs[$last_entry]['address'],'array_escape_tags'); } } -- cgit v1.2.3 From 0368b6730fcb16ec66a0cb2bdc692ce85d26d633 Mon Sep 17 00:00:00 2001 From: Hubzilla Date: Fri, 20 Jan 2017 13:36:37 -0800 Subject: language aware content --- include/bbcode.php | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'include') diff --git a/include/bbcode.php b/include/bbcode.php index 00d22d26d..8b78034f2 100644 --- a/include/bbcode.php +++ b/include/bbcode.php @@ -473,11 +473,26 @@ function bb_sanitize_style($input) { return '' . $input[2] . ''; } +function oblanguage_callback($matches) { + if(strlen($matches[1]) == 2) { + $compare = strtolower(substr(\App::$language,0,2)); + } + else { + $compare = strtolower(\App::$language); + } + + if($compare === strtolower($matches[1])) + return $matches[2]; + + return ''; +} + function bb_observer($Text) { $observer = App::get_observer(); if ((strpos($Text,'[/observer]') !== false) || (strpos($Text,'[/rpost]') !== false)) { + if ($observer) { $Text = preg_replace("/\[observer\=1\](.*?)\[\/observer\]/ism", '$1', $Text); $Text = preg_replace("/\[observer\=0\].*?\[\/observer\]/ism", '', $Text); @@ -561,6 +576,9 @@ function parseIdentityAwareHTML($Text) { $observer = App::get_observer(); if ((strpos($Text,'[/observer]') !== false) || (strpos($Text,'[/rpost]') !== false)) { + + $Text = preg_replace_callback("/\[observer\.language\=(.*?)\](.*?)\[\/observer\]/ism",'oblanguage_callback', $Text); + if ($observer) { $Text = preg_replace("/\[observer\=1\](.*?)\[\/observer\]/ism", '$1', $Text); $Text = preg_replace("/\[observer\=0\].*?\[\/observer\]/ism", '', $Text); @@ -643,6 +661,8 @@ function bbcode($Text, $preserve_nl = false, $tryoembed = true, $cache = false) $observer = App::get_observer(); if ((strpos($Text,'[/observer]') !== false) || (strpos($Text,'[/rpost]') !== false)) { + $Text = preg_replace_callback("/\[observer\.language\=(.*?)\](.*?)\[\/observer\]/ism",'oblanguage_callback', $Text); + if ($observer) { $Text = preg_replace("/\[observer\=1\](.*?)\[\/observer\]/ism", '$1', $Text); $Text = preg_replace("/\[observer\=0\].*?\[\/observer\]/ism", '', $Text); -- cgit v1.2.3 From 9acd3ebd42733cc089cf2192451617e0b05a0fbc Mon Sep 17 00:00:00 2001 From: Hubzilla Date: Fri, 20 Jan 2017 15:30:08 -0800 Subject: observer.language!={something} for completeness --- include/bbcode.php | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'include') diff --git a/include/bbcode.php b/include/bbcode.php index 8b78034f2..b8d732443 100644 --- a/include/bbcode.php +++ b/include/bbcode.php @@ -487,6 +487,20 @@ function oblanguage_callback($matches) { return ''; } +function oblanguage_necallback($matches) { + if(strlen($matches[1]) == 2) { + $compare = strtolower(substr(\App::$language,0,2)); + } + else { + $compare = strtolower(\App::$language); + } + + if($compare !== strtolower($matches[1])) + return $matches[2]; + + return ''; +} + function bb_observer($Text) { $observer = App::get_observer(); @@ -579,6 +593,8 @@ function parseIdentityAwareHTML($Text) { $Text = preg_replace_callback("/\[observer\.language\=(.*?)\](.*?)\[\/observer\]/ism",'oblanguage_callback', $Text); + $Text = preg_replace_callback("/\[observer\.language\!\=(.*?)\](.*?)\[\/observer\]/ism",'oblanguage_necallback', $Text); + if ($observer) { $Text = preg_replace("/\[observer\=1\](.*?)\[\/observer\]/ism", '$1', $Text); $Text = preg_replace("/\[observer\=0\].*?\[\/observer\]/ism", '', $Text); @@ -662,6 +678,7 @@ function bbcode($Text, $preserve_nl = false, $tryoembed = true, $cache = false) if ((strpos($Text,'[/observer]') !== false) || (strpos($Text,'[/rpost]') !== false)) { $Text = preg_replace_callback("/\[observer\.language\=(.*?)\](.*?)\[\/observer\]/ism",'oblanguage_callback', $Text); + $Text = preg_replace_callback("/\[observer\.language\!\=(.*?)\](.*?)\[\/observer\]/ism",'oblanguage_necallback', $Text); if ($observer) { $Text = preg_replace("/\[observer\=1\](.*?)\[\/observer\]/ism", '$1', $Text); -- cgit v1.2.3 From d2226c0e9b6e943510bff01ff8ccc62e0d9cfea7 Mon Sep 17 00:00:00 2001 From: Mario Vavti Date: Sun, 22 Jan 2017 10:20:39 +0100 Subject: whitespace cleanup --- include/nav.php | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) (limited to 'include') diff --git a/include/nav.php b/include/nav.php index e389308ff..94547b20e 100644 --- a/include/nav.php +++ b/include/nav.php @@ -12,8 +12,8 @@ function nav(&$a) { App::$page['nav'] = ''; $base = z_root(); - App::$page['htmlhead'] .= <<< EOT + App::$page['htmlhead'] .= <<< EOT EOT; - - if(local_channel()) { $channel = App::get_channel(); $observer = App::get_observer(); @@ -234,11 +232,11 @@ EOT; $x = array('nav' => $nav, 'usermenu' => $userinfo ); call_hooks('nav', $x); -// Not sure the best place to put this on the page. So I'm implementing it but leaving it -// turned off until somebody discovers this and figures out a good location for it. -$powered_by = ''; + // Not sure the best place to put this on the page. So I'm implementing it but leaving it + // turned off until somebody discovers this and figures out a good location for it. + $powered_by = ''; -// $powered_by = 'redr#matrix'; + // $powered_by = 'redr#matrix'; $tpl = get_markup_template('nav.tpl'); @@ -257,7 +255,6 @@ $powered_by = ''; '$pleasewait' => t('Please wait...') )); - if(x($_SESSION, 'reload_avatar') && $observer) { // The avatar has been changed on the server but the browser doesn't know that, // force the browser to reload the image from the server instead of its cache. -- cgit v1.2.3 From 9e509aa25b334fc6a7145262dfdf6cb192337acc Mon Sep 17 00:00:00 2001 From: Mario Vavti Date: Sun, 22 Jan 2017 10:21:01 +0100 Subject: $a is deprecated --- include/nav.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include') diff --git a/include/nav.php b/include/nav.php index 94547b20e..b7203b996 100644 --- a/include/nav.php +++ b/include/nav.php @@ -1,6 +1,6 @@ Date: Sun, 22 Jan 2017 13:45:34 +0100 Subject: some work on app_bin - just to get it going --- include/nav.php | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) (limited to 'include') diff --git a/include/nav.php b/include/nav.php index b7203b996..6ad43c909 100644 --- a/include/nav.php +++ b/include/nav.php @@ -1,5 +1,7 @@ redr#matrix'; + + //app bin + $navapps = ''; + if(get_config('system','experimental_app_bin')) { + if(local_channel()) { + //Zlib\Apps::import_system_apps(); + $syslist = array(); + $list = Zlib\Apps::app_list(local_channel(), false, $_GET['cat']); + if($list) { + foreach($list as $li) { + $syslist[] = Zlib\Apps::app_encode($li); + } + } + Zlib\Apps::translate_system_apps($syslist); + } + else { + $syslist = Zlib\Apps::get_system_apps(true); + } + + $navapps = replace_macros(get_markup_template('navapps.tpl'), array( + '$apps' => $syslist + )); + } + $tpl = get_markup_template('nav.tpl'); App::$page['nav'] .= replace_macros($tpl, array( @@ -252,7 +278,8 @@ EOT; '$sel' => App::$nav_sel, '$powered_by' => $powered_by, '$help' => t('@name, #tag, ?doc, content'), - '$pleasewait' => t('Please wait...') + '$pleasewait' => t('Please wait...'), + '$navapps' => $navapps )); if(x($_SESSION, 'reload_avatar') && $observer) { -- cgit v1.2.3 From 17f1d39fcf973ac35f14a36faa2b92867fbb11e9 Mon Sep 17 00:00:00 2001 From: Hubzilla Date: Sun, 22 Jan 2017 18:48:45 -0800 Subject: basic support for clone syncing of wikis and wiki pages --- include/channel.php | 11 +++++++++++ include/items.php | 1 + include/zot.php | 7 +++++-- 3 files changed, 17 insertions(+), 2 deletions(-) (limited to 'include') diff --git a/include/channel.php b/include/channel.php index 83f48f361..247d3d358 100644 --- a/include/channel.php +++ b/include/channel.php @@ -671,6 +671,17 @@ function identity_basic_export($channel_id, $items = false) { $ret['mail'] = $m; } + $r = q("select * from item where resource_type like 'nwiki%%' and uid = %d order by created", + intval($channel_id) + ); + if($r) { + $ret['wiki'] = array(); + xchan_query($r); + $r = fetch_post_tags($r,true); + foreach($r as $rv) { + $ret['wiki'][] = encode_item($rv,true); + } + } /** @warning this may run into memory limits on smaller systems */ diff --git a/include/items.php b/include/items.php index e4ead28c8..3b7307239 100755 --- a/include/items.php +++ b/include/items.php @@ -391,6 +391,7 @@ function post_activity_item($arr,$allow_code = false,$deliver = true) { call_hooks('post_local_end', $arr); Zotlabs\Daemon\Master::Summon(array('Notifier','activity',$post_id)); $ret['success'] = true; + $ret['item_id'] = $post_id; $ret['activity'] = $post['item']; } diff --git a/include/zot.php b/include/zot.php index c6d52816a..06996f47f 100644 --- a/include/zot.php +++ b/include/zot.php @@ -3174,8 +3174,11 @@ 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('file',$arr) && $arr['file']) - sync_files($channel,$arr['file']); + if(array_key_exists('menu',$arr) && $arr['menu']) + sync_menus($channel,$arr['menu']); + + if(array_key_exists('wiki',$arr) && $arr['wiki']) + sync_items($channel,$arr['wiki']); if(array_key_exists('channel',$arr) && is_array($arr['channel']) && count($arr['channel'])) { -- cgit v1.2.3 From cda284424f3be310424772b319efcb8b602e1792 Mon Sep 17 00:00:00 2001 From: Hubzilla Date: Sun, 22 Jan 2017 18:56:14 -0800 Subject: synced wikis should be relocated --- 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 06996f47f..24b50cc12 100644 --- a/include/zot.php +++ b/include/zot.php @@ -3178,7 +3178,7 @@ function process_channel_sync_delivery($sender, $arr, $deliveries) { sync_menus($channel,$arr['menu']); if(array_key_exists('wiki',$arr) && $arr['wiki']) - sync_items($channel,$arr['wiki']); + sync_items($channel,$arr['wiki'],((array_key_exists('relocate',$arr)) ? $arr['relocate'] : null)); if(array_key_exists('channel',$arr) && is_array($arr['channel']) && count($arr['channel'])) { -- cgit v1.2.3 From cb47354a4f76e033485e9818b137742c01466dbe Mon Sep 17 00:00:00 2001 From: zotlabs Date: Mon, 23 Jan 2017 16:31:40 -0800 Subject: put login form into the nav bar. Proof of concept - needs a bit of UI tweaks. --- include/channel.php | 14 ++++++++++++++ include/nav.php | 2 ++ 2 files changed, 16 insertions(+) (limited to 'include') diff --git a/include/channel.php b/include/channel.php index 247d3d358..d66ed7abe 100644 --- a/include/channel.php +++ b/include/channel.php @@ -1908,4 +1908,18 @@ function channel_manual_conv_update($channel_id) { return intval($x); +} + + +function remote_login() { + + $o = replace_macros(get_markup_template('remote_login.tpl'),array( + '$title' => t('Remote Authentication'), + '$desc' => t('Enter your channel address (e.g. channel@example.com)'), + '$submit' => t('Authenticate') + )); + return $o; + + + } \ No newline at end of file diff --git a/include/nav.php b/include/nav.php index 6ad43c909..ce259255e 100644 --- a/include/nav.php +++ b/include/nav.php @@ -112,6 +112,7 @@ EOT; } else { if(! get_account_id()) { + $nav['login'] = login(); $nav['loginmenu'][] = Array('login',t('Login'),'',t('Sign in'),'login_nav_btn'); } else @@ -128,6 +129,7 @@ EOT; } elseif(! $_SESSION['authenticated']) { + $nav['remote_login'] = remote_login(); $nav['loginmenu'][] = Array('rmagic',t('Remote authentication'),'',t('Click to authenticate to your home hub'),'rmagic_nav_btn'); } -- cgit v1.2.3 From d96a7bc1fae81dbf7b569a7aac757efc25a533b9 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Tue, 24 Jan 2017 18:33:41 -0800 Subject: block well-known from oembed --- include/oembed.php | 3 +++ 1 file changed, 3 insertions(+) (limited to 'include') diff --git a/include/oembed.php b/include/oembed.php index 36395cfbc..58ad29291 100755 --- a/include/oembed.php +++ b/include/oembed.php @@ -34,6 +34,9 @@ function oembed_action($embedurl) { $action = 'block'; } } + if(strpos($embedurl,'.well-known') !== false) + $action = 'block'; + // site white/black list -- cgit v1.2.3 From 33aa373b3f864867e36f78095c3a4fdc89c26ad5 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Tue, 24 Jan 2017 19:44:24 -0800 Subject: minor --- include/network.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'include') diff --git a/include/network.php b/include/network.php index d571ec2ce..4391f1bfe 100644 --- a/include/network.php +++ b/include/network.php @@ -51,7 +51,7 @@ function z_fetch_url($url, $binary = false, $redirects = 0, $opts = array()) { @curl_setopt($ch, CURLOPT_CAINFO, get_capath()); @curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true); @curl_setopt($ch, CURLOPT_RETURNTRANSFER,true); - @curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (compatible; Red)"); + @curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (compatible; zot)"); $ciphers = @get_config('system','curl_ssl_ciphers'); if($ciphers) @@ -84,7 +84,7 @@ function z_fetch_url($url, $binary = false, $redirects = 0, $opts = array()) { @curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $opts['custom']); if(x($opts,'timeout') && intval($opts['timeout'])) { - @curl_setopt($ch, CURLOPT_TIMEOUT, $opts['timeout']); + @curl_setopt($ch, CURLOPT_TIMEOUT, intval($opts['timeout'])); } else { $curl_time = intval(@get_config('system','curl_timeout')); @@ -218,7 +218,7 @@ function z_post_url($url,$params, $redirects = 0, $opts = array()) { @curl_setopt($ch, CURLOPT_RETURNTRANSFER,true); @curl_setopt($ch, CURLOPT_POST,1); @curl_setopt($ch, CURLOPT_POSTFIELDS,$params); - @curl_setopt($ch, CURLOPT_USERAGENT, "Red"); + @curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (compatible; zot)"); $ciphers = @get_config('system','curl_ssl_ciphers'); if($ciphers) -- cgit v1.2.3 From 1db57c498d0edceac705ba027790cfa9d4e04c6d Mon Sep 17 00:00:00 2001 From: Mario Vavti Date: Wed, 25 Jan 2017 19:41:47 +0100 Subject: fixes for wiki create/delete page --- 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 3b7307239..3a3fd6029 100755 --- a/include/items.php +++ b/include/items.php @@ -383,15 +383,18 @@ function post_activity_item($arr,$allow_code = false,$deliver = true) { } $post = item_store($arr,$allow_code,$deliver); - if($post['success']) + + if($post['success']) { $post_id = $post['item_id']; + $ret['item_id'] = $post_id; + } if($post_id && $deliver) { $arr['id'] = $post_id; call_hooks('post_local_end', $arr); Zotlabs\Daemon\Master::Summon(array('Notifier','activity',$post_id)); $ret['success'] = true; - $ret['item_id'] = $post_id; + //$ret['item_id'] = $post_id; $ret['activity'] = $post['item']; } -- cgit v1.2.3 From 7804ae6a7889baab8af87d518fb5a61b30cb20ff Mon Sep 17 00:00:00 2001 From: zotlabs Date: Wed, 25 Jan 2017 11:43:54 -0800 Subject: initialise item['postopts'] for mysql >= 5.7 --- include/items.php | 1 + 1 file changed, 1 insertion(+) (limited to 'include') diff --git a/include/items.php b/include/items.php index 3b7307239..4813cfb64 100755 --- a/include/items.php +++ b/include/items.php @@ -1512,6 +1512,7 @@ function item_store($arr, $allow_exec = false, $deliver = true) { $arr['allow_gid'] = ((x($arr,'allow_gid')) ? trim($arr['allow_gid']) : ''); $arr['deny_cid'] = ((x($arr,'deny_cid')) ? trim($arr['deny_cid']) : ''); $arr['deny_gid'] = ((x($arr,'deny_gid')) ? trim($arr['deny_gid']) : ''); + $arr['postopts'] = ((x($arr,'postopts')) ? trim($arr['postopts']) : ''); $arr['item_private'] = ((x($arr,'item_private')) ? intval($arr['item_private']) : 0 ); $arr['item_wall'] = ((x($arr,'item_wall')) ? intval($arr['item_wall']) : 0 ); $arr['item_type'] = ((x($arr,'item_type')) ? intval($arr['item_type']) : 0 ); -- cgit v1.2.3 From 45dbd31d286838254cd1ae60e4ebb39c112526be Mon Sep 17 00:00:00 2001 From: zotlabs Date: Wed, 25 Jan 2017 12:21:52 -0800 Subject: only allow wiki owner to delete pages --- include/items.php | 4 ++-- include/widgets.php | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-) (limited to 'include') diff --git a/include/items.php b/include/items.php index 5986038bc..66ec2ffea 100755 --- a/include/items.php +++ b/include/items.php @@ -3311,7 +3311,7 @@ function retain_item($id) { ); } -function drop_items($items) { +function drop_items($items,$interactive = false,$stage = DROPITEM_NORMAL,$force = false) { $uid = 0; if(! local_channel() && ! remote_channel()) @@ -3319,7 +3319,7 @@ function drop_items($items) { if(count($items)) { foreach($items as $item) { - $owner = drop_item($item,false); + $owner = drop_item($item,$interactive,$stage,$force); if($owner && ! $uid) $uid = $owner; } diff --git a/include/widgets.php b/include/widgets.php index 799310908..98ea4e6a1 100644 --- a/include/widgets.php +++ b/include/widgets.php @@ -945,6 +945,8 @@ function widget_wiki_pages($arr) { } $can_create = perm_is_allowed(\App::$profile['uid'],get_observer_hash(),'write_pages'); + $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'], @@ -954,6 +956,7 @@ function widget_wiki_pages($arr) { '$wikiname' => $wikiname, '$pages' => $pages, '$canadd' => $can_create, + '$candel' => $can_delete, '$addnew' => t('Add new page'), '$pageName' => array('pageName', t('Page name')), )); -- cgit v1.2.3 From 5bc6941b577f59784dd2eb46c7dae32862b52576 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Wed, 25 Jan 2017 14:40:04 -0800 Subject: resolve the linked item delete issue by declaring what types of linked items cannot be deleted --- include/items.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'include') diff --git a/include/items.php b/include/items.php index 66ec2ffea..8213ab161 100755 --- a/include/items.php +++ b/include/items.php @@ -3343,6 +3343,11 @@ function drop_items($items,$interactive = false,$stage = DROPITEM_NORMAL,$force function drop_item($id,$interactive = true,$stage = DROPITEM_NORMAL,$force = false) { + // These resource types have linked items that should only be removed at the same time + // as the linked resource; if we encounter one set it to item_hidden rather than item_deleted. + + $linked_resource_types = [ 'photo' ]; + // locate item to be deleted $r = q("SELECT * FROM item WHERE id = %d LIMIT 1", @@ -3358,7 +3363,7 @@ function drop_item($id,$interactive = true,$stage = DROPITEM_NORMAL,$force = fal $item = $r[0]; - $linked_item = (($item['resource_id']) ? true : false); + $linked_item = (($item['resource_id'] && $item['resource_type'] && in_array($linked_resource_types,$item['resource_type'])) ? true : false); $ok_to_delete = false; -- cgit v1.2.3 From d64dcd298ec2267256a7ff8784a4c036ab6c11f7 Mon Sep 17 00:00:00 2001 From: Mario Vavti Date: Thu, 26 Jan 2017 11:03:41 +0100 Subject: haystack/needle mixup --- 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 8213ab161..0c76fd4ee 100755 --- a/include/items.php +++ b/include/items.php @@ -3363,7 +3363,7 @@ function drop_item($id,$interactive = true,$stage = DROPITEM_NORMAL,$force = fal $item = $r[0]; - $linked_item = (($item['resource_id'] && $item['resource_type'] && in_array($linked_resource_types,$item['resource_type'])) ? true : false); + $linked_item = (($item['resource_id'] && $item['resource_type'] && in_array($item['resource_type'], $linked_resource_types)) ? true : false); $ok_to_delete = false; -- cgit v1.2.3 From 22839e48d013abdc46b609cd50b45b3bce6626f9 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Thu, 26 Jan 2017 15:16:41 -0800 Subject: better handling of html special chars in wiki and wikipage names --- include/items.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'include') diff --git a/include/items.php b/include/items.php index 0c76fd4ee..0d9fb02a4 100755 --- a/include/items.php +++ b/include/items.php @@ -386,18 +386,18 @@ function post_activity_item($arr,$allow_code = false,$deliver = true) { if($post['success']) { $post_id = $post['item_id']; + $ret['success'] = true; $ret['item_id'] = $post_id; + $ret['activity'] = $post['item']; + call_hooks('post_local_end', $ret['activity']); } if($post_id && $deliver) { - $arr['id'] = $post_id; - call_hooks('post_local_end', $arr); Zotlabs\Daemon\Master::Summon(array('Notifier','activity',$post_id)); - $ret['success'] = true; - //$ret['item_id'] = $post_id; - $ret['activity'] = $post['item']; } + + $ret['success'] = true; return $ret; } -- cgit v1.2.3 From 8b5793e629baaf2084909d310d967abda277ae81 Mon Sep 17 00:00:00 2001 From: Mario Vavti Date: Fri, 27 Jan 2017 17:51:49 +0100 Subject: more work on app-bin --- include/nav.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'include') diff --git a/include/nav.php b/include/nav.php index ce259255e..d7b006c6d 100644 --- a/include/nav.php +++ b/include/nav.php @@ -249,7 +249,7 @@ EOT; if(local_channel()) { //Zlib\Apps::import_system_apps(); $syslist = array(); - $list = Zlib\Apps::app_list(local_channel(), false, $_GET['cat']); + $list = Zlib\Apps::app_list(local_channel(), false, 'featured'); if($list) { foreach($list as $li) { $syslist[] = Zlib\Apps::app_encode($li); @@ -262,7 +262,8 @@ EOT; } $navapps = replace_macros(get_markup_template('navapps.tpl'), array( - '$apps' => $syslist + '$apps' => $syslist, + '$localuser' => local_channel(), )); } -- cgit v1.2.3 From 5aa0017e91cac135ef8b84c138becb09decb1d58 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Sat, 28 Jan 2017 15:01:19 -0800 Subject: provide lowlevel xchan storage function to ensure that all non-null rows are initialised --- include/channel.php | 36 ++++++------- include/hubloc.php | 104 -------------------------------------- include/items.php | 34 +++++++------ include/network.php | 35 +++++++++---- include/security.php | 23 ++++----- include/xchan.php | 139 +++++++++++++++++++++++++++++++++++++++++++++++++++ include/zot.php | 44 ++++++++-------- 7 files changed, 235 insertions(+), 180 deletions(-) create mode 100644 include/xchan.php (limited to 'include') diff --git a/include/channel.php b/include/channel.php index d66ed7abe..d2ef89cc8 100644 --- a/include/channel.php +++ b/include/channel.php @@ -311,23 +311,25 @@ function create_identity($arr) { $newuid = $ret['channel']['channel_id']; - $r = q("insert into xchan ( xchan_hash, xchan_guid, xchan_guid_sig, xchan_pubkey, xchan_photo_l, xchan_photo_m, xchan_photo_s, xchan_addr, xchan_url, xchan_follow, xchan_connurl, xchan_name, xchan_network, xchan_photo_date, xchan_name_date, xchan_system ) values ('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d)", - dbesc($hash), - dbesc($guid), - dbesc($sig), - dbesc($key['pubkey']), - dbesc(z_root() . "/photo/profile/l/{$newuid}"), - dbesc(z_root() . "/photo/profile/m/{$newuid}"), - dbesc(z_root() . "/photo/profile/s/{$newuid}"), - dbesc(channel_reddress($ret['channel'])), - dbesc(z_root() . '/channel/' . $ret['channel']['channel_address']), - dbesc(z_root() . '/follow?f=&url=%s'), - dbesc(z_root() . '/poco/' . $ret['channel']['channel_address']), - dbesc($ret['channel']['channel_name']), - dbesc('zot'), - dbesc(datetime_convert()), - dbesc(datetime_convert()), - intval($system) + $r = xchan_store_lowlevel( + [ + 'xchan_hash' => $hash, + 'xchan_guid' => $guid, + 'xchan_guid_sig' => $sig, + 'xchan_pubkey' => $key['pubkey'], + 'xchan_photo_l' => z_root() . "/photo/profile/l/{$newuid}", + 'xchan_photo_m' => z_root() . "/photo/profile/m/{$newuid}", + 'xchan_photo_s' => z_root() . "/photo/profile/s/{$newuid}", + 'xchan_addr' => channel_reddress($ret['channel']), + 'xchan_url' => z_root() . '/channel/' . $ret['channel']['channel_address'], + 'xchan_follow' => z_root() . '/follow?f=&url=%s', + 'xchan_connurl' => z_root() . '/poco/' . $ret['channel']['channel_address'], + 'xchan_name' => $ret['channel']['channel_name'], + 'xchan_network' => 'zot', + 'xchan_photo_date' => datetime_convert(), + 'xchan_name_date' => datetime_convert(), + 'xchan_system' => $system + ] ); // Not checking return value. diff --git a/include/hubloc.php b/include/hubloc.php index 6f81ea31f..4da92ae72 100644 --- a/include/hubloc.php +++ b/include/hubloc.php @@ -176,110 +176,6 @@ function hubloc_mark_as_down($posturl) { } -function xchan_store($arr) { - - logger('xchan_store: ' . print_r($arr,true)); - - if(! $arr['hash']) - $arr['hash'] = $arr['guid']; - if(! $arr['hash']) - return false; - - $r = q("select * from xchan where xchan_hash = '%s' limit 1", - dbesc($arr['hash']) - ); - if($r) - return true; - - if(! $arr['network']) - $arr['network'] = 'unknown'; - if(! $arr['name']) - $arr['name'] = 'unknown'; - if(! $arr['url']) - $arr['url'] = z_root(); - if(! $arr['photo']) - $arr['photo'] = z_root() . '/' . get_default_profile_photo(); - - - if($arr['network'] === 'zot') { - if((! $arr['key']) || (! rsa_verify($arr['guid'],base64url_decode($arr['guid_sig']),$arr['key']))) { - logger('Unable to verify signature for ' . $arr['hash']); - return false; - } - } - - $r = q("insert into xchan ( xchan_hash, xchan_guid, xchan_guid_sig, xchan_pubkey, xchan_addr, xchan_url, xchan_connurl, xchan_follow, xchan_connpage, xchan_name, xchan_network, xchan_instance_url, xchan_hidden, xchan_orphan, xchan_censored, xchan_selfcensored, xchan_system, xchan_pubforum, xchan_deleted, xchan_name_date ) values ('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s','%s','%s','%s',%d, %d, %d, %d, %d, %d, %d, '%s') ", - dbesc($arr['hash']), - dbesc($arr['guid']), - dbesc($arr['guid_sig']), - dbesc($arr['pubkey']), - dbesc($arr['address']), - dbesc($arr['url']), - dbesc($arr['connurl']), - dbesc($arr['follow']), - dbesc($arr['connpage']), - dbesc($arr['name']), - dbesc($arr['network']), - dbesc($arr['instance_url']), - intval($arr['hidden']), - intval($arr['orphan']), - intval($arr['censored']), - intval($arr['selfcensored']), - intval($arr['system']), - intval($arr['pubforum']), - intval($arr['deleted']), - dbesc(datetime_convert()) - ); - if(! $r) - return $r; - - $photos = import_xchan_photo($arr['photo'],$arr['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_hash = '%s'", - dbesc(datetime_convert()), - dbesc($photos[0]), - dbesc($photos[1]), - dbesc($photos[2]), - dbesc($photos[3]), - dbesc($arr['hash']) - ); - return $r; - -} - - -function xchan_fetch($arr) { - - $key = ''; - if($arr['hash']) { - $key = 'xchan_hash'; - $v = $arr['hash']; - } - elseif($arr['guid']) { - $key = 'xchan_guid'; - $v = $arr['guid']; - } - elseif($arr['address']) { - $key = 'xchan_addr'; - $v = $arr['address']; - } - - if(! $key) - return false; - - $r = q("select * from xchan where $key = '$v' limit 1"); - if(! $r) - return false; - - $ret = array(); - foreach($r[0] as $k => $v) { - if($k === 'xchan_addr') - $ret['address'] = $v; - else - $ret[str_replace('xchan_','',$k)] = $v; - } - return $ret; -} - function ping_site($url) { diff --git a/include/items.php b/include/items.php index 0d9fb02a4..559992b7f 100755 --- a/include/items.php +++ b/include/items.php @@ -833,13 +833,15 @@ function import_author_rss($x) { } $name = trim($x['name']); - $r = q("insert into xchan ( xchan_hash, xchan_guid, xchan_url, xchan_name, xchan_network ) - values ( '%s', '%s', '%s', '%s', '%s' )", - dbesc($x['guid']), - dbesc($x['guid']), - dbesc($x['url']), - dbesc(($name) ? $name : t('(Unknown)')), - dbesc('rss') + $r = xchan_store_lowlevel( + [ + 'xchan_hash' => $x['guid'], + 'xchan_guid' => $x['guid'], + 'xchan_url' => $x['url'], + 'xchan_name' => (($name) ? $name : t('(Unknown)')), + 'xchan_name_date' => datetime_convert(), + 'xchan_network' => 'rss' + ] ); if($r && $x['photo']) { @@ -878,14 +880,17 @@ function import_author_unknown($x) { $name = trim($x['name']); - $r = q("insert into xchan ( xchan_hash, xchan_guid, xchan_url, xchan_name, xchan_network ) - values ( '%s', '%s', '%s', '%s', '%s' )", - dbesc($x['url']), - dbesc($x['url']), - dbesc($x['url']), - dbesc(($name) ? $name : t('(Unknown)')), - dbesc('unknown') + $r = xchan_store_lowlevel( + [ + 'xchan_hash' => $x['url'], + 'xchan_guid' => $x['url'], + 'xchan_url' => $x['url'], + 'xchan_name' => (($name) ? $name : t('(Unknown)')), + 'xchan_name_date' => datetime_convert(), + 'xchan_network' => 'unknown' + ] ); + if($r && $x['photo']) { $photos = import_xchan_photo($x['photo']['src'],$x['url']); @@ -1516,6 +1521,7 @@ function item_store($arr, $allow_exec = false, $deliver = true) { $arr['deny_cid'] = ((x($arr,'deny_cid')) ? trim($arr['deny_cid']) : ''); $arr['deny_gid'] = ((x($arr,'deny_gid')) ? trim($arr['deny_gid']) : ''); $arr['postopts'] = ((x($arr,'postopts')) ? trim($arr['postopts']) : ''); + $arr['route'] = ((x($arr,'route')) ? trim($arr['route']) : ''); $arr['item_private'] = ((x($arr,'item_private')) ? intval($arr['item_private']) : 0 ); $arr['item_wall'] = ((x($arr,'item_wall')) ? intval($arr['item_wall']) : 0 ); $arr['item_type'] = ((x($arr,'item_type')) ? intval($arr['item_type']) : 0 ); diff --git a/include/network.php b/include/network.php index 4391f1bfe..73fd417ea 100644 --- a/include/network.php +++ b/include/network.php @@ -1121,16 +1121,17 @@ function discover_by_url($url,$arr = null) { if(! $photo) $photo = z_root() . '/images/rss_icon.png'; - $r = q("insert into xchan ( xchan_hash, xchan_guid, xchan_pubkey, xchan_addr, xchan_url, xchan_name, xchan_network, xchan_instance_url, xchan_name_date ) values ('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s') ", - dbesc($guid), - dbesc($guid), - dbesc($pubkey), - dbesc($addr), - dbesc($profile), - dbesc($name), - dbesc($network), - dbesc(z_root()), - dbesc(datetime_convert()) + $r = xchan_store_lowlevel( + [ + 'xchan_hash' => $guid, + 'xchan_guid' => $guid, + 'xchan_pubkey' => $pubkey, + 'xchan_addr' => $addr, + 'xchan_url' => $profile, + 'xchan_name' => $name, + 'xchan_name_date' => datetime_convert(), + 'xchan_network' => $network + ] ); $photos = import_xchan_photo($photo,$guid); @@ -1449,6 +1450,20 @@ function discover_by_webbie($webbie) { ); } 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("insert into xchan ( xchan_hash, xchan_guid, xchan_pubkey, xchan_addr, xchan_url, xchan_name, xchan_network, xchan_name_date ) values ('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s') ", dbesc($address), dbesc(($diaspora_guid) ? $diaspora_guid : $location), diff --git a/include/security.php b/include/security.php index 2f5de54c7..57b33251f 100644 --- a/include/security.php +++ b/include/security.php @@ -171,19 +171,16 @@ function atoken_create_xchan($xchan) { if($r) return; - $r = q("insert into xchan ( xchan_hash, xchan_guid, xchan_addr, xchan_url, xchan_name, xchan_network, xchan_photo_mimetype, xchan_photo_l, xchan_photo_m, xchan_photo_s ) - values ('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s') ", - dbesc($xchan['xchan_hash']), - dbesc($xchan['xchan_hash']), - dbesc($xchan['xchan_addr']), - dbesc($xchan['xchan_url']), - dbesc($xchan['xchan_name']), - dbesc($xchan['xchan_network']), - dbesc($xchan['xchan_photo_mimetype']), - dbesc($xchan['xchan_photo_l']), - dbesc($xchan['xchan_photo_m']), - dbesc($xchan['xchan_photo_s']) - ); + $xchan['xchan_guid'] = $xchan['xchan_hash']; + + $store = []; + foreach($xchan as $k => $v) { + if(strpos($k,'xchan_') === 0) { + $store[$k] = $v; + } + } + + $r = xchan_store_lowlevel($store); return true; } diff --git a/include/xchan.php b/include/xchan.php new file mode 100644 index 000000000..12eb674fa --- /dev/null +++ b/include/xchan.php @@ -0,0 +1,139 @@ + ((array_key_exists('xchan_hash',$arr)) ? $arr['xchan_hash'] : ''), + 'xchan_guid' => ((array_key_exists('xchan_guid',$arr)) ? $arr['xchan_guid'] : ''), + 'xchan_guid_sig' => ((array_key_exists('xchan_guid_sig',$arr)) ? $arr['xchan_guid_sig'] : ''), + 'xchan_pubkey' => ((array_key_exists('xchan_pubkey',$arr)) ? $arr['xchan_pubkey'] : ''), + 'xchan_photo_mimetype' => ((array_key_exists('xchan_photo_mimetype',$arr)) ? $arr['xchan_photo_mimetype'] : ''), + 'xchan_photo_l' => ((array_key_exists('xchan_photo_l',$arr)) ? $arr['xchan_photo_l'] : ''), + 'xchan_photo_m' => ((array_key_exists('xchan_photo_m',$arr)) ? $arr['xchan_photo_m'] : ''), + 'xchan_photo_s' => ((array_key_exists('xchan_photo_s',$arr)) ? $arr['xchan_photo_s'] : ''), + 'xchan_addr' => ((array_key_exists('xchan_addr',$arr)) ? $arr['xchan_addr'] : ''), + 'xchan_url' => ((array_key_exists('xchan_url',$arr)) ? $arr['xchan_url'] : ''), + 'xchan_connurl' => ((array_key_exists('xchan_connurl',$arr)) ? $arr['xchan_connurl'] : ''), + 'xchan_follow' => ((array_key_exists('xchan_follow',$arr)) ? $arr['xchan_follow'] : ''), + 'xchan_connpage' => ((array_key_exists('xchan_connpage',$arr)) ? $arr['xchan_connpage'] : ''), + 'xchan_name' => ((array_key_exists('xchan_name',$arr)) ? $arr['xchan_name'] : ''), + 'xchan_network' => ((array_key_exists('xchan_network',$arr)) ? $arr['xchan_network'] : ''), + 'xchan_instance_url' => ((array_key_exists('xchan_instance_url',$arr)) ? $arr['xchan_instance_url'] : ''), + 'xchan_flags' => ((array_key_exists('xchan_flags',$arr)) ? intval($arr['xchan_flags']) : 0), + 'xchan_photo_date' => ((array_key_exists('xchan_photo_date',$arr)) ? datetime_convert('UTC','UTC',$arr['xchan_photo_date']) : NULL_DATE), + 'xchan_name_date' => ((array_key_exists('xchan_name_date',$arr)) ? datetime_convert('UTC','UTC',$arr['xchan_name_date']) : NULL_DATE), + 'xchan_hidden' => ((array_key_exists('xchan_hidden',$arr)) ? intval($arr['xchan_hidden']) : 0), + 'xchan_orphan' => ((array_key_exists('xchan_orphan',$arr)) ? intval($arr['xchan_orphan']) : 0), + 'xchan_censored' => ((array_key_exists('xchan_censored',$arr)) ? intval($arr['xchan_censored']) : 0), + 'xchan_selfcensored' => ((array_key_exists('xchan_selfcensored',$arr)) ? intval($arr['xchan_selfcensored']) : 0), + 'xchan_system' => ((array_key_exists('xchan_system',$arr)) ? intval($arr['xchan_system']) : 0), + 'xchan_pubforum' => ((array_key_exists('xchan_pubforum',$arr)) ? intval($arr['xchan_pubforum']) : 0), + 'xchan_deleted' => ((array_key_exists('xchan_deleted',$arr)) ? intval($arr['xchan_deleted']) : 0) + ]; + + return create_table_from_array('xchan',$store); +} + + + +function xchan_store($arr) { + + logger('xchan_store: ' . print_r($arr,true)); + + if(! $arr['hash']) + $arr['hash'] = $arr['guid']; + if(! $arr['hash']) + return false; + + $r = q("select * from xchan where xchan_hash = '%s' limit 1", + dbesc($arr['hash']) + ); + if($r) + return true; + + if(! $arr['network']) + $arr['network'] = 'unknown'; + if(! $arr['name']) + $arr['name'] = 'unknown'; + if(! $arr['url']) + $arr['url'] = z_root(); + if(! $arr['photo']) + $arr['photo'] = z_root() . '/' . get_default_profile_photo(); + + + if($arr['network'] === 'zot') { + if((! $arr['key']) || (! rsa_verify($arr['guid'],base64url_decode($arr['guid_sig']),$arr['key']))) { + logger('Unable to verify signature for ' . $arr['hash']); + return false; + } + } + + $x = []; + foreach($arr as $k => $v) { + if($k === 'key') { + $x['xchan_pubkey'] = $v; + continue; + } + if($k === 'photo') { + continue; + } + + $x['xchan_' . $k] = $v; + } + + $x['xchan_name_date'] = datetime_convert(); + + $r = xchan_store_lowlevel($x); + + if(! $r) + return $r; + + $photos = import_xchan_photo($arr['photo'],$arr['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_hash = '%s'", + dbesc(datetime_convert()), + dbesc($photos[0]), + dbesc($photos[1]), + dbesc($photos[2]), + dbesc($photos[3]), + dbesc($arr['hash']) + ); + return $r; + +} + + +function xchan_fetch($arr) { + + $key = ''; + if($arr['hash']) { + $key = 'xchan_hash'; + $v = $arr['hash']; + } + elseif($arr['guid']) { + $key = 'xchan_guid'; + $v = $arr['guid']; + } + elseif($arr['address']) { + $key = 'xchan_addr'; + $v = $arr['address']; + } + + if(! $key) + return false; + + $r = q("select * from xchan where $key = '$v' limit 1"); + if(! $r) + return false; + + $ret = array(); + foreach($r[0] as $k => $v) { + if($k === 'xchan_addr') + $ret['address'] = $v; + else + $ret[str_replace('xchan_','',$k)] = $v; + } + return $ret; +} + + diff --git a/include/zot.php b/include/zot.php index 24b50cc12..1538e956e 100644 --- a/include/zot.php +++ b/include/zot.php @@ -759,28 +759,28 @@ function import_xchan($arr,$ud_flags = UPDATE_FLAGS_UPDATED, $ud_arr = null) { && ($arr['site']['url'] != z_root())) $arr['searchable'] = false; - $x = q("insert into xchan ( xchan_hash, xchan_guid, xchan_guid_sig, xchan_pubkey, xchan_photo_mimetype, - xchan_photo_l, xchan_addr, xchan_url, xchan_connurl, xchan_follow, xchan_connpage, xchan_name, xchan_network, xchan_photo_date, xchan_name_date, xchan_hidden, xchan_selfcensored, xchan_deleted, xchan_pubforum ) - values ( '%s', '%s', '%s', '%s' , '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d, %d, %d, %d) ", - dbesc($xchan_hash), - dbesc($arr['guid']), - dbesc($arr['guid_sig']), - dbesc($arr['key']), - dbesc($arr['photo_mimetype']), - dbesc($arr['photo']), - dbesc($arr['address']), - dbesc($arr['url']), - dbesc($arr['connections_url']), - dbesc($arr['follow_url']), - dbesc($arr['connect_url']), - dbesc(($arr['name']) ? $arr['name'] : '-'), - dbesc('zot'), - dbescdate($arr['photo_updated']), - dbescdate($arr['name_updated']), - intval(1 - intval($arr['searchable'])), - intval($arr['adult_content']), - intval($arr['deleted']), - intval($arr['public_forum']) + $x = xchan_store_lowlevel( + [ + 'xchan_hash' => $xchan_hash, + 'xchan_guid' => $arr['guid'], + 'xchan_guid_sig' => $arr['guid_sig'], + 'xchan_pubkey' => $arr['key'], + 'xchan_photo_mimetype' => $arr['photo_mimetype'], + 'xchan_photo_l' => $arr['photo'], + 'xchan_addr' => $arr['address'], + 'xchan_url' => $arr['url'], + 'xchan_connurl' => $arr['connections_url'], + 'xchan_follow' => $arr['follow_url'], + 'xchan_connpage' => $arr['connect_url'], + 'xchan_name' => (($arr['name']) ? $arr['name'] : '-'), + 'xchan_network' => 'zot', + 'xchan_photo_date' => $arr['photo_updated'], + 'xchan_name_date' => $arr['name_updated'], + 'xchan_hidden' => intval(1 - intval($arr['searchable'])), + 'xchan_selfcensored' => $arr['adult_content'], + 'xchan_deleted' => $arr['deleted'], + 'xchan_pubforum' => $arr['public_forum'] + ] ); $what .= 'new_xchan'; -- cgit v1.2.3 From d5d67708ac912fa863a062e3469eb4ac17e84cdf Mon Sep 17 00:00:00 2001 From: zotlabs Date: Sun, 29 Jan 2017 14:45:25 -0800 Subject: Alter the queue so that each queue item stores the scheduled time of the next delivery. This keeps the query for queued items simple. We no longer group by posturl; as the queue update function will only keep one item per destination scheduled for shorter term processing. Others (multiple queued items for a single destination) will be scheduled for delivery far into the future and only delivered if the hub responds to the "active" or short term queue item. --- include/queue_fn.php | 46 ++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 42 insertions(+), 4 deletions(-) (limited to 'include') diff --git a/include/queue_fn.php b/include/queue_fn.php index 0950faf85..74dde5de2 100644 --- a/include/queue_fn.php +++ b/include/queue_fn.php @@ -2,9 +2,42 @@ function update_queue_item($id, $add_priority = 0) { logger('queue: requeue item ' . $id,LOGGER_DEBUG); - q("UPDATE outq SET outq_updated = '%s', outq_priority = outq_priority + %d WHERE outq_hash = '%s'", + $x = q("select outq_created, outq_posturl from outq where outq_hash = '%s' limit 1", + dbesc($id) + ); + if(! $x) + return; + + // Set all other records for this destination way into the future. + // The queue delivers by destination. We'll keep one queue item for + // this destination (this one) with a shorter delivery. If we succeed + // once, we'll try to deliver everything for that destination. + // The delivery will be set to at most once per hour, and if the + // queue item is less than 12 hours old, we'll schedule for fifteen + // minutes. + + $r = q("UPDATE outq SET outq_scheduled = '%s' WHERE outq_posturl = '%s'", + dbesc(datetime_convert('UTC','UTC','now + 5 days')), + dbesc($x[0]['outq_posturl']) + ); + + $since = datetime_convert('UTC','UTC',$x[0]['outq_created']); + + if($since < datetime_convert('UTC','UTC','now - 12 hour')) { + $next = datetime_convert('UTC','UTC','now + 1 hour'); + } + else { + $next = datetime_convert('UTC','UTC','now + 15 minutes'); + } + + q("UPDATE outq SET outq_updated = '%s', + outq_priority = outq_priority + %d, + outq_scheduled = '%s' + WHERE outq_hash = '%s'", + dbesc(datetime_convert()), intval($add_priority), + dbesc($next), dbesc($id) ); } @@ -33,8 +66,12 @@ function queue_set_delivered($id,$channel = 0) { logger('queue: set delivered ' . $id,LOGGER_DEBUG); $sql_extra = (($channel_id) ? " and outq_channel = " . intval($channel_id) . " " : ''); - q("update outq set outq_delivered = 1, outq_updated = '%s' where outq_hash = '%s' $sql_extra ", + // Set the next scheduled run date so far in the future that it will be expired + // long before it ever makes it back into the delivery chain. + + q("update outq set outq_delivered = 1, outq_updated = '%s', outq_scheduled = '%s' where outq_hash = '%s' $sql_extra ", dbesc(datetime_convert()), + dbesc(datetime_convert('UTC','UTC','now + 5 days')), dbesc($id) ); } @@ -44,8 +81,8 @@ function queue_set_delivered($id,$channel = 0) { function queue_insert($arr) { $x = q("insert into outq ( outq_hash, outq_account, outq_channel, outq_driver, outq_posturl, outq_async, outq_priority, - outq_created, outq_updated, outq_notify, outq_msg ) - values ( '%s', %d, %d, '%s', '%s', %d, %d, '%s', '%s', '%s', '%s' )", + outq_created, outq_updated, outq_scheduled, outq_notify, outq_msg ) + values ( '%s', %d, %d, '%s', '%s', %d, %d, '%s', '%s', '%s', '%s', '%s' )", dbesc($arr['hash']), intval($arr['account_id']), intval($arr['channel_id']), @@ -55,6 +92,7 @@ function queue_insert($arr) { intval(($arr['priority']) ? $arr['priority'] : 0), dbesc(datetime_convert()), dbesc(datetime_convert()), + dbesc(datetime_convert()), dbesc($arr['notify']), dbesc(($arr['msg']) ? $arr['msg'] : '') ); -- cgit v1.2.3 From 9addcfe827e02ca1d738c29018372db0ba8c09d6 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Sun, 29 Jan 2017 15:25:24 -0800 Subject: finish remaining places where xchan_store_lowlevel needs to be used --- include/network.php | 12 ------------ 1 file changed, 12 deletions(-) (limited to 'include') diff --git a/include/network.php b/include/network.php index 73fd417ea..9049d016b 100644 --- a/include/network.php +++ b/include/network.php @@ -1450,7 +1450,6 @@ function discover_by_webbie($webbie) { ); } else { - $r = xchan_store_lowlevel( [ 'xchan_hash' => $address, @@ -1463,17 +1462,6 @@ function discover_by_webbie($webbie) { 'xchan_network' => $network ] ); - - $r = q("insert into xchan ( xchan_hash, xchan_guid, xchan_pubkey, xchan_addr, xchan_url, xchan_name, xchan_network, xchan_name_date ) values ('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s') ", - dbesc($address), - dbesc(($diaspora_guid) ? $diaspora_guid : $location), - dbesc($pubkey), - dbesc($address), - dbesc($location), - dbesc($fullname), - dbesc($network), - dbescdate(datetime_convert()) - ); } $r = q("select * from hubloc where hubloc_hash = '%s' limit 1", -- cgit v1.2.3 From 3424c7dc878ecf5b1f1c021737e3d7eba2443299 Mon Sep 17 00:00:00 2001 From: Andrew Manning Date: Sun, 29 Jan 2017 19:53:29 -0500 Subject: Add affinity slider tool settings for min and max defaults in settings/featured --- include/widgets.php | 82 +++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 79 insertions(+), 3 deletions(-) (limited to 'include') diff --git a/include/widgets.php b/include/widgets.php index 98ea4e6a1..94c00dba8 100644 --- a/include/widgets.php +++ b/include/widgets.php @@ -521,9 +521,16 @@ function widget_affinity($arr) { if(! local_channel()) return ''; - - $cmin = ((x($_REQUEST,'cmin')) ? intval($_REQUEST['cmin']) : 0); - $cmax = ((x($_REQUEST,'cmax')) ? intval($_REQUEST['cmax']) : 99); + + // 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')) { @@ -900,6 +907,75 @@ function widget_chatroom_members() { return $o; } +/* + * $arr input array: + * room_id + * + */ +function widget_chatroom_panel($arr) { + + // This widget is only intended for use on the page of a local channel + if(local_channel()) { + $channel = \App::get_channel(); + $observer = get_observer_hash(); + if(! $observer) { + // This should never fail because the observer should be a local channel + return; + } + } else { + return; + } + + $room_id = $arr['room_id']; + + $x = \Zotlabs\Lib\Chatroom::enter($observer,$room_id,'online',$_SERVER['REMOTE_ADDR']); + if(! $x) + return; + $x = q("select * from chatroom where cr_id = %d and cr_uid = %d $sql_extra limit 1", + intval($room_id), + intval(\App::$profile['profile_uid']) + ); + + if($x) { + $acl = new \Zotlabs\Access\AccessList(false); + $acl->set($x[0]); + + $private = $acl->is_private(); + $room_name = $x[0]['cr_name']; + if($bookmark_link) + $bookmark_link .= '&url=' . z_root() . '/chat/' . argv(1) . '/' . argv(2) . '&title=' . urlencode($x[0]['cr_name']) . (($private) ? '&private=1' : '') . '&ischat=1'; + } + else { + logger('Room not found'); + return; + } + + $cipher = get_pconfig(local_channel(),'system','default_cipher'); + if(! $cipher) + $cipher = 'aes256'; + + $o = replace_macros(get_markup_template('chat.tpl'),array( + '$is_owner' => ((local_channel() && local_channel() == $x[0]['cr_uid']) ? true : false), + '$room_name' => $room_name, + '$room_id' => $room_id, + '$baseurl' => z_root(), + '$nickname' => argv(1), + '$submit' => t('Submit'), + '$leave' => t('Leave Room'), + '$drop' => t('Delete Room'), + '$away' => t('I am away right now'), + '$online' => t('I am online'), + '$bookmark_link' => $bookmark_link, + '$bookmark' => t('Bookmark this room'), + '$feature_encrypt' => ((feature_enabled(local_channel(),'content_encrypt')) ? true : false), + '$cipher' => $cipher, + '$linkurl' => t('Please enter a link URL:'), + '$encrypt' => t('Encrypt text'), + '$insert' => t('Insert web link') + )); + return $o; +} + function widget_wiki_list($arr) { $channel = channelx_by_n(App::$profile_uid); -- cgit v1.2.3 From 17011a7637565839f4dde917568ca12daf87de66 Mon Sep 17 00:00:00 2001 From: Andrew Manning Date: Sun, 29 Jan 2017 19:56:19 -0500 Subject: Remove unrelated chatroom panel stuff that was included accidentally --- include/widgets.php | 69 ----------------------------------------------------- 1 file changed, 69 deletions(-) (limited to 'include') diff --git a/include/widgets.php b/include/widgets.php index 94c00dba8..27eae7d6f 100644 --- a/include/widgets.php +++ b/include/widgets.php @@ -907,75 +907,6 @@ function widget_chatroom_members() { return $o; } -/* - * $arr input array: - * room_id - * - */ -function widget_chatroom_panel($arr) { - - // This widget is only intended for use on the page of a local channel - if(local_channel()) { - $channel = \App::get_channel(); - $observer = get_observer_hash(); - if(! $observer) { - // This should never fail because the observer should be a local channel - return; - } - } else { - return; - } - - $room_id = $arr['room_id']; - - $x = \Zotlabs\Lib\Chatroom::enter($observer,$room_id,'online',$_SERVER['REMOTE_ADDR']); - if(! $x) - return; - $x = q("select * from chatroom where cr_id = %d and cr_uid = %d $sql_extra limit 1", - intval($room_id), - intval(\App::$profile['profile_uid']) - ); - - if($x) { - $acl = new \Zotlabs\Access\AccessList(false); - $acl->set($x[0]); - - $private = $acl->is_private(); - $room_name = $x[0]['cr_name']; - if($bookmark_link) - $bookmark_link .= '&url=' . z_root() . '/chat/' . argv(1) . '/' . argv(2) . '&title=' . urlencode($x[0]['cr_name']) . (($private) ? '&private=1' : '') . '&ischat=1'; - } - else { - logger('Room not found'); - return; - } - - $cipher = get_pconfig(local_channel(),'system','default_cipher'); - if(! $cipher) - $cipher = 'aes256'; - - $o = replace_macros(get_markup_template('chat.tpl'),array( - '$is_owner' => ((local_channel() && local_channel() == $x[0]['cr_uid']) ? true : false), - '$room_name' => $room_name, - '$room_id' => $room_id, - '$baseurl' => z_root(), - '$nickname' => argv(1), - '$submit' => t('Submit'), - '$leave' => t('Leave Room'), - '$drop' => t('Delete Room'), - '$away' => t('I am away right now'), - '$online' => t('I am online'), - '$bookmark_link' => $bookmark_link, - '$bookmark' => t('Bookmark this room'), - '$feature_encrypt' => ((feature_enabled(local_channel(),'content_encrypt')) ? true : false), - '$cipher' => $cipher, - '$linkurl' => t('Please enter a link URL:'), - '$encrypt' => t('Encrypt text'), - '$insert' => t('Insert web link') - )); - return $o; -} - function widget_wiki_list($arr) { $channel = channelx_by_n(App::$profile_uid); -- cgit v1.2.3 From eebea700193155b176ee9a9b338f1a0ad4b6aa40 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Sun, 29 Jan 2017 17:16:06 -0800 Subject: queue optimisations for sites that have lingered in the queue for more than a couple of days. --- include/queue_fn.php | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'include') diff --git a/include/queue_fn.php b/include/queue_fn.php index 74dde5de2..ede6c8f11 100644 --- a/include/queue_fn.php +++ b/include/queue_fn.php @@ -8,6 +8,21 @@ function update_queue_item($id, $add_priority = 0) { if(! $x) return; + + $y = q("select min(outq_created) as earliest from outq where outq_posturl = '%s'", + dbesc($x[0]['outq_posturl']) + ); + + // look for the oldest queue entry with this destination URL. If it's older than a couple of days, + // the destination is considered to be down and only scheduled once an hour, regardless of the + // age of the current queue item. + + $might_be_down = false; + + if($y) + $might_be_down = ((datetime_convert('UTC','UTC',$y[0]['earliest']) < datetime_convert('UTC','UTC','now - 2 days')) ? true : false); + + // Set all other records for this destination way into the future. // The queue delivers by destination. We'll keep one queue item for // this destination (this one) with a shorter delivery. If we succeed @@ -23,7 +38,7 @@ function update_queue_item($id, $add_priority = 0) { $since = datetime_convert('UTC','UTC',$x[0]['outq_created']); - if($since < datetime_convert('UTC','UTC','now - 12 hour')) { + if(($might_be_down) || ($since < datetime_convert('UTC','UTC','now - 12 hour'))) { $next = datetime_convert('UTC','UTC','now + 1 hour'); } else { -- cgit v1.2.3 From 7b065365e0d64a06ddfb7ade55e713a4b6a0f802 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Mon, 30 Jan 2017 15:01:22 -0800 Subject: consolidate hubloc storage --- include/Import/refimport.php | 1 - include/api_zot.php | 1 - include/bbcode.php | 2 +- include/bookmarks.php | 1 - include/channel.php | 29 ++++++++++---------- include/hubloc.php | 31 +++++++++++++++++++++ include/network.php | 21 ++++++++------ include/oembed.php | 2 -- include/text.php | 2 +- include/zid.php | 4 +-- include/zot.php | 65 ++++++++++++++++++++++++-------------------- 11 files changed, 97 insertions(+), 62 deletions(-) (limited to 'include') diff --git a/include/Import/refimport.php b/include/Import/refimport.php index 3ef8870ac..04540a9bd 100644 --- a/include/Import/refimport.php +++ b/include/Import/refimport.php @@ -1,7 +1,6 @@ $guid, + 'hubloc_guid_sig' => $sig, + 'hubloc_hash' => $hash, + 'hubloc_addr' => channel_reddress($ret['channel']), + 'hubloc_primary' => $primary, + 'hubloc_url' => z_root(), + 'hubloc_url_sig' => base64url_encode(rsa_sign(z_root(),$ret['channel']['channel_prvkey'])), + 'hubloc_host' => App::get_hostname(), + 'hubloc_callback' => z_root() . '/post', + 'hubloc_sitekey' => get_config('system','pubkey'), + 'hubloc_network' => 'zot', + 'hubloc_updated' => datetime_convert() + ] ); if(! $r) logger('create_identity: Unable to store hub location'); diff --git a/include/hubloc.php b/include/hubloc.php index 4da92ae72..e17be028c 100644 --- a/include/hubloc.php +++ b/include/hubloc.php @@ -1,5 +1,36 @@ ((array_key_exists('hubloc_guid',$arr)) ? $arr['hubloc_guid'] : ''), + 'hubloc_guid_sig' => ((array_key_exists('hubloc_guid_sig',$arr)) ? $arr['hubloc_guid_sig'] : ''), + 'hubloc_hash' => ((array_key_exists('hubloc_hash',$arr)) ? $arr['hubloc_hash'] : ''), + 'hubloc_addr' => ((array_key_exists('hubloc_addr',$arr)) ? $arr['hubloc_addr'] : ''), + 'hubloc_network' => ((array_key_exists('hubloc_network',$arr)) ? $arr['hubloc_network'] : ''), + 'hubloc_flags' => ((array_key_exists('hubloc_flags',$arr)) ? $arr['hubloc_flags'] : 0), + 'hubloc_status' => ((array_key_exists('hubloc_status',$arr)) ? $arr['hubloc_status'] : 0), + 'hubloc_url' => ((array_key_exists('hubloc_url',$arr)) ? $arr['hubloc_url'] : ''), + 'hubloc_url_sig' => ((array_key_exists('hubloc_url_sig',$arr)) ? $arr['hubloc_url_sig'] : ''), + 'hubloc_host' => ((array_key_exists('hubloc_host',$arr)) ? $arr['hubloc_host'] : ''), + 'hubloc_callback' => ((array_key_exists('hubloc_callback',$arr)) ? $arr['hubloc_callback'] : ''), + 'hubloc_connect' => ((array_key_exists('hubloc_connect',$arr)) ? $arr['hubloc_connect'] : ''), + 'hubloc_sitekey' => ((array_key_exists('hubloc_sitekey',$arr)) ? $arr['hubloc_sitekey'] : ''), + 'hubloc_updated' => ((array_key_exists('hubloc_updated',$arr)) ? $arr['hubloc_updated'] : NULL_DATE), + 'hubloc_connected' => ((array_key_exists('hubloc_connected',$arr)) ? $arr['hubloc_connected'] : NULL_DATE), + 'hubloc_primary' => ((array_key_exists('hubloc_primary',$arr)) ? $arr['hubloc_primary'] : 0), + 'hubloc_orphancheck' => ((array_key_exists('hubloc_orphancheck',$arr)) ? $arr['hubloc_orphancheck'] : 0), + 'hubloc_error' => ((array_key_exists('hubloc_error',$arr)) ? $arr['hubloc_error'] : 0), + 'hubloc_deleted' => ((array_key_exists('hubloc_deleted',$arr)) ? $arr['hubloc_deleted'] : 0) + ]; + + return create_table_from_array('hubloc',$store); + +} + + + function prune_hub_reinstalls() { $r = q("select site_url from site where site_type = %d", diff --git a/include/network.php b/include/network.php index 9049d016b..66716ef9e 100644 --- a/include/network.php +++ b/include/network.php @@ -1469,15 +1469,18 @@ function discover_by_webbie($webbie) { ); if(! $r) { - $r = q("insert into hubloc ( hubloc_guid, hubloc_hash, hubloc_addr, hubloc_network, hubloc_url, hubloc_host, hubloc_callback, hubloc_updated, hubloc_primary ) values ('%s','%s','%s','%s','%s','%s','%s','%s', 1)", - dbesc(($diaspora_guid) ? $diaspora_guid : $location), - dbesc($address), - dbesc($address), - dbesc($network), - dbesc($base), - dbesc($host), - dbesc($notify), - dbescdate(datetime_convert()) + $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); diff --git a/include/oembed.php b/include/oembed.php index 58ad29291..aac7d15b4 100755 --- a/include/oembed.php +++ b/include/oembed.php @@ -2,8 +2,6 @@ use Zotlabs\Lib as Zlib; -require_once('include/hubloc.php'); - function oembed_replacecb($matches){ diff --git a/include/text.php b/include/text.php index 1beefc6eb..4f0dc869b 100644 --- a/include/text.php +++ b/include/text.php @@ -4,7 +4,7 @@ */ require_once("include/bbcode.php"); -require_once('include/hubloc.php'); + // random string, there are 86 characters max in text mode, 128 for hex // output is urlsafe diff --git a/include/zid.php b/include/zid.php index ac6433e4c..f5df1c611 100644 --- a/include/zid.php +++ b/include/zid.php @@ -170,7 +170,7 @@ function zidify_text($s) { * @return string */ function red_zrl_callback($matches) { - require_once('include/hubloc.php'); + $zrl = is_matrix_url($matches[2]); $t = strip_zids($matches[2]); @@ -215,7 +215,7 @@ function red_unescape_codeblock($m) { function red_zrlify_img_callback($matches) { - require_once('include/hubloc.php'); + $zrl = is_matrix_url($matches[2]); $t = strip_zids($matches[2]); diff --git a/include/zot.php b/include/zot.php index 1538e956e..094b50b72 100644 --- a/include/zot.php +++ b/include/zot.php @@ -10,7 +10,6 @@ require_once('include/crypto.php'); require_once('include/items.php'); -require_once('include/hubloc.php'); require_once('include/queue_fn.php'); require_once('include/perm_upgrade.php'); @@ -2469,22 +2468,25 @@ function sync_locations($sender, $arr, $absolute = false) { ); } logger('sync_locations: new hub: ' . $location['url']); - $r = q("insert into hubloc ( hubloc_guid, hubloc_guid_sig, hubloc_hash, hubloc_addr, hubloc_network, hubloc_primary, hubloc_url, hubloc_url_sig, hubloc_host, hubloc_callback, hubloc_sitekey, hubloc_updated, hubloc_connected) - values ( '%s','%s','%s','%s', '%s', %d ,'%s','%s','%s','%s','%s','%s','%s')", - dbesc($sender['guid']), - dbesc($sender['guid_sig']), - dbesc($sender['hash']), - dbesc($location['address']), - dbesc('zot'), - intval($location['primary']), - dbesc($location['url']), - dbesc($location['url_sig']), - dbesc($location['host']), - dbesc($location['callback']), - dbesc($location['sitekey']), - dbesc(datetime_convert()), - dbesc(datetime_convert()) + + $r = hubloc_store_lowlevel( + [ + 'hubloc_guid' => $sender['guid'], + 'hubloc_guid_sig' => $sender['guid_sig'], + 'hubloc_hash' => $sender['hash'], + 'hubloc_addr' => $location['address'], + 'hubloc_network' => 'zot', + 'hubloc_primary' => $location['primary'], + 'hubloc_url' => $location['url'], + 'hubloc_url_sig' => $location['url_sig'], + 'hubloc_host' => $location['host'], + 'hubloc_callback' => $location['callback'], + 'hubloc_sitekey' => $location['sitekey'], + 'hubloc_updated' => datetime_convert(), + 'hubloc_connected' => datetime_convert() + ] ); + $what .= 'newhub '; $changed = true; @@ -4057,21 +4059,24 @@ function check_zotinfo($channel,$locations,&$ret) { q("delete from hubloc where hubloc_hash = '%s'", dbesc($channel['channel_hash']) ); - $r = q("insert into hubloc ( hubloc_guid, hubloc_guid_sig, hubloc_hash, hubloc_addr, hubloc_primary, - hubloc_url, hubloc_url_sig, hubloc_host, hubloc_callback, hubloc_sitekey, hubloc_network ) - values ( '%s', '%s', '%s', '%s', %d, '%s', '%s', '%s', '%s', '%s', '%s' )", - dbesc($channel['channel_guid']), - dbesc($channel['channel_guid_sig']), - dbesc($channel['channel_hash']), - dbesc(channel_reddress($channel)), - intval(1), - dbesc(z_root()), - dbesc(base64url_encode(rsa_sign(z_root(),$channel['channel_prvkey']))), - dbesc(App::get_hostname()), - dbesc(z_root() . '/post'), - dbesc(get_config('system','pubkey')), - dbesc('zot') + + $r = hubloc_store_lowelevel( + [ + 'hubloc_guid' => $channel['channel_guid'], + 'hubloc_guid_sig' => $channel['channel_guid_sig'], + 'hubloc_hash' => $channel['channel_hash'], + 'hubloc_addr' => channel_reddress($channel), + 'hubloc_network' => 'zot', + 'hubloc_primary' => 1, + 'hubloc_url' => z_root(), + 'hubloc_url_sig' => base64url_encode(rsa_sign(z_root(),$channel['channel_prvkey'])), + 'hubloc_host' => App::get_hostname(), + 'hubloc_callback' => z_root() . '/post', + 'hubloc_sitekey' => get_config('system','pubkey'), + 'hubloc_updated' => datetime_convert(), + ] ); + if($r) { $x = zot_encode_locations($channel); if($x) { -- cgit v1.2.3 From e1b54b684383557159cc25839637c35329fce3cd Mon Sep 17 00:00:00 2001 From: Mario Vavti Date: Tue, 31 Jan 2017 09:43:58 +0100 Subject: fix typos --- 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 094b50b72..8bad4fde5 100644 --- a/include/zot.php +++ b/include/zot.php @@ -4060,7 +4060,7 @@ function check_zotinfo($channel,$locations,&$ret) { dbesc($channel['channel_hash']) ); - $r = hubloc_store_lowelevel( + $r = hubloc_store_lowlevel( [ 'hubloc_guid' => $channel['channel_guid'], 'hubloc_guid_sig' => $channel['channel_guid_sig'], -- cgit v1.2.3 From a6cbebe03c4c1ca66b4b55c340ebb1d369d93c3a Mon Sep 17 00:00:00 2001 From: Mario Vavti Date: Tue, 31 Jan 2017 12:53:33 +0100 Subject: hide featured app category in the app category widget --- include/nav.php | 2 +- include/widgets.php | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) (limited to 'include') diff --git a/include/nav.php b/include/nav.php index d7b006c6d..25f2a1df4 100644 --- a/include/nav.php +++ b/include/nav.php @@ -249,7 +249,7 @@ EOT; if(local_channel()) { //Zlib\Apps::import_system_apps(); $syslist = array(); - $list = Zlib\Apps::app_list(local_channel(), false, 'featured'); + $list = Zlib\Apps::app_list(local_channel(), false, 'nav_featured_app'); if($list) { foreach($list as $li) { $syslist[] = Zlib\Apps::app_encode($li); diff --git a/include/widgets.php b/include/widgets.php index 27eae7d6f..408ba5d24 100644 --- a/include/widgets.php +++ b/include/widgets.php @@ -456,6 +456,7 @@ function widget_appcategories($arr) { 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) -- cgit v1.2.3 From 732065bf13af96f680bc9874afee71c07f74e40a Mon Sep 17 00:00:00 2001 From: zotlabs Date: Tue, 31 Jan 2017 15:28:25 -0800 Subject: channel export - use a selected list of functional data categories to export; this allows one to export single data sets instead of always exporting everything we know about --- include/api_zot.php | 9 +- include/channel.php | 388 ++++++++++++++++++++++++++++++---------------------- include/text.php | 1 + 3 files changed, 234 insertions(+), 164 deletions(-) (limited to 'include') diff --git a/include/api_zot.php b/include/api_zot.php index 0b10555a6..aaa9ee497 100644 --- a/include/api_zot.php +++ b/include/api_zot.php @@ -69,8 +69,13 @@ logger('api_export_basic: no user'); return false; } - - json_return_and_die(identity_basic_export(api_user(),(($_REQUEST['posts']) ? intval($_REQUEST['posts']) : 0 ))); + $sections = (($_REQUEST['sections']) ? explode(',',$_REQUEST['sections']) : ''); + if($_REQUEST['posts']) { + $sections = get_default_export_sections(); + $sections[] = 'items'; + } + + json_return_and_die(identity_basic_export(api_user(),$sections)); } diff --git a/include/channel.php b/include/channel.php index 10c38a5ac..83cf97305 100644 --- a/include/channel.php +++ b/include/channel.php @@ -476,6 +476,16 @@ function set_default_login_identity($account_id, $channel_id, $force = true) { } } + +function get_default_export_sections() { + $sections = [ 'channel', 'connections', 'config', 'apps', 'chatrooms', 'events', 'webpages', 'mail', 'wikis' ]; + + $cb = [ 'sections' => $sections ]; + call_hooks('get_default_export_sections', $cb); + return $cb['sections']; +} + + /** * @brief Create an array representing the important channel information * which would be necessary to create a nomadic identity clone. This includes @@ -489,225 +499,279 @@ function set_default_login_identity($account_id, $channel_id, $force = true) { * @returns array * See function for details */ -function identity_basic_export($channel_id, $items = false) { +function identity_basic_export($channel_id, $sections = null) { /* - * Red basic channel export + * basic channel export */ - $ret = array(); + 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'] = array('project' => PLATFORM_NAME, 'version' => STD_VERSION, 'database' => DB_UPDATE_VERSION, 'server_role' => Zotlabs\Lib\System::get_server_role()); + + $ret['compatibility'] = [ + 'project' => PLATFORM_NAME, + 'version' => STD_VERSION, + 'database' => DB_UPDATE_VERSION, + 'server_role' => Zotlabs\Lib\System::get_server_role() + ]; + + /* + * Process channel information regardless of it is one of the sections desired + * because we need the channel relocation information in all export files/streams. + */ $r = q("select * from channel where channel_id = %d limit 1", intval($channel_id) ); if($r) { translate_channel_perms_outbound($r[0]); - $ret['channel'] = $r[0]; $ret['relocate'] = [ 'channel_address' => $r[0]['channel_address'], 'url' => z_root()]; - } - - $r = q("select * from profile where uid = %d", - intval($channel_id) - ); - if($r) - $ret['profile'] = $r; - - $xchans = array(); - $r = q("select * from abook where abook_channel = %d ", - intval($channel_id) - ); - if($r) { - $ret['abook'] = $r; - - for($x = 0; $x < count($ret['abook']); $x ++) { - $xchans[] = $ret['abook'][$x]['abook_xchan']; - $abconfig = load_abconfig($channel_id,$ret['abook'][$x]['abook_xchan']); - if($abconfig) - $ret['abook'][$x]['abconfig'] = $abconfig; - translate_abook_perms_outbound($ret['abook'][$x]); + if(in_array('channel',$sections)) { + $ret['channel'] = $r[0]; } - stringify_array_elms($xchans); } - if($xchans) { - $r = q("select * from xchan where xchan_hash in ( " . implode(',',$xchans) . " ) "); + if(in_array('channel',$sections)) { + $r = q("select * from profile where uid = %d", + intval($channel_id) + ); if($r) - $ret['xchan'] = $r; + $ret['profile'] = $r; - $r = q("select * from hubloc where hubloc_hash in ( " . implode(',',$xchans) . " ) "); - if($r) - $ret['hubloc'] = $r; - } - $r = q("select * from groups where uid = %d ", - intval($channel_id) - ); + $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) + ); - if($r) - $ret['group'] = $r; + if($r) { + $ret['photo'] = [ + 'type' => $r[0]['mimetype'], + 'data' => (($r[0]['os_storage']) + ? base64url_encode(file_get_contents($r[0]['content'])) : base64url_encode($r[0]['content'])) + ]; + } + } - $r = q("select * from group_member where uid = %d ", - intval($channel_id) - ); - if($r) - $ret['group_member'] = $r; + if(in_array('connections',$sections)) { + $xchans = array(); + $r = q("select * from abook where abook_channel = %d ", + intval($channel_id) + ); + if($r) { + $ret['abook'] = $r; + + for($x = 0; $x < count($ret['abook']); $x ++) { + $xchans[] = $ret['abook'][$x]['abook_xchan']; + $abconfig = load_abconfig($channel_id,$ret['abook'][$x]['abook_xchan']); + if($abconfig) + $ret['abook'][$x]['abconfig'] = $abconfig; + translate_abook_perms_outbound($ret['abook'][$x]); + } + stringify_array_elms($xchans); + } - $r = q("select * from pconfig where uid = %d", - intval($channel_id) - ); - if($r) - $ret['config'] = $r; + if($xchans) { + $r = q("select * from xchan where xchan_hash in ( " . implode(',',$xchans) . " ) "); + if($r) + $ret['xchan'] = $r; - $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) - ); + $r = q("select * from hubloc where hubloc_hash in ( " . implode(',',$xchans) . " ) "); + if($r) + $ret['hubloc'] = $r; + } - if($r) { - $ret['photo'] = array('type' => $r[0]['mimetype'], 'data' => (($r[0]['os_storage']) ? base64url_encode(file_get_contents($r[0]['content'])) : base64url_encode($r[0]['content']))); - } + $r = q("select * from groups where uid = %d ", + intval($channel_id) + ); - // All other term types will be included in items, if requested. + if($r) + $ret['group'] = $r; - $r = q("select * from term where ttype in (%d,%d) and uid = %d", - intval(TERM_SAVEDSEARCH), - intval(TERM_THING), - intval($channel_id) - ); - if($r) - $ret['term'] = $r; + $r = q("select * from group_member where uid = %d ", + intval($channel_id) + ); + if($r) + $ret['group_member'] = $r; - // add psuedo-column obj_baseurl to aid in relocations + } - $r = q("select obj.*, '%s' as obj_baseurl from obj where obj_channel = %d", - dbesc(z_root()), - intval($channel_id) - ); + if(in_array('config',$sections)) { + $r = q("select * from pconfig where uid = %d", + intval($channel_id) + ); + 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", + intval(TERM_SAVEDSEARCH), + intval(TERM_THING), + intval($channel_id) + ); + if($r) + $ret['term'] = $r; - if($r) - $ret['obj'] = $r; + // add psuedo-column obj_baseurl to aid in relocations - $r = q("select * from app where app_channel = %d and app_system = 0", - intval($channel_id) - ); - if($r) { - for($x = 0; $x < count($r); $x ++) { - $r[$x]['term'] = q("select * from term where otype = %d and oid = %d", - intval(TERM_OBJ_APP), - intval($r[$x]['id']) - ); - } - $ret['app'] = $r; - } + $r = q("select obj.*, '%s' as obj_baseurl from obj where obj_channel = %d", + dbesc(z_root()), + intval($channel_id) + ); - $r = q("select * from chatroom where cr_uid = %d", - intval($channel_id) - ); - if($r) - $ret['chatroom'] = $r; + if($r) + $ret['obj'] = $r; - $r = q("select * from event where uid = %d", - intval($channel_id) - ); - if($r) - $ret['event'] = $r; + $r = q("select * from likes where channel_id = %d", + intval($channel_id) + ); + + if($r) + $ret['likes'] = $r; - $r = q("select * from item where resource_type = 'event' and uid = %d", - intval($channel_id) - ); - if($r) { - $ret['event_item'] = array(); - xchan_query($r); - $r = fetch_post_tags($r,true); - foreach($r as $rr) - $ret['event_item'][] = encode_item($rr,true); } - $x = menu_list($channel_id); - if($x) { - $ret['menu'] = array(); - for($y = 0; $y < count($x); $y ++) { - $m = menu_fetch($x[$y]['menu_name'],$channel_id,$ret['channel']['channel_hash']); - if($m) - $ret['menu'][] = menu_element($ret['channel'],$m); + if(in_array('apps',$sections)) { + $r = q("select * from app where app_channel = %d and app_system = 0", + intval($channel_id) + ); + if($r) { + for($x = 0; $x < count($r); $x ++) { + $r[$x]['term'] = q("select * from term where otype = %d and oid = %d", + intval(TERM_OBJ_APP), + intval($r[$x]['id']) + ); + } + $ret['app'] = $r; } } - $addon = array('channel_id' => $channel_id,'data' => $ret); - call_hooks('identity_basic_export',$addon); - $ret = $addon['data']; + if(in_array('chatrooms',$sections)) { + $r = q("select * from chatroom where cr_uid = %d", + intval($channel_id) + ); + if($r) + $ret['chatroom'] = $r; + } - if(! $items) - return $ret; - $r = q("select * from likes where channel_id = %d", - intval($channel_id) - ); + if(in_array('events',$sections)) { + $r = q("select * from event where uid = %d", + intval($channel_id) + ); + if($r) + $ret['event'] = $r; - if($r) - $ret['likes'] = $r; + $r = q("select * from item where resource_type = 'event' and uid = %d", + intval($channel_id) + ); + if($r) { + $ret['event_item'] = array(); + xchan_query($r); + $r = fetch_post_tags($r,true); + foreach($r as $rr) + $ret['event_item'][] = encode_item($rr,true); + } + } + if(in_array('webpages',$sections)) { + $x = menu_list($channel_id); + if($x) { + $ret['menu'] = array(); + for($y = 0; $y < count($x); $y ++) { + $m = menu_fetch($x[$y]['menu_name'],$channel_id,$ret['channel']['channel_hash']); + if($m) + $ret['menu'][] = menu_element($ret['channel'],$m); + } + } + $r = q("select * from item where item_type in ( " + . ITEM_TYPE_BLOCK . "," . ITEM_TYPE_PDL . "," . ITEM_TYPE_WEBPAGE . " ) and uid = %d", + intval($channel_id) + ); + if($r) { + $ret['webpages'] = array(); + xchan_query($r); + $r = fetch_post_tags($r,true); + foreach($r as $rr) + $ret['webpages'][] = encode_item($rr,true); - $r = q("select * from conv where uid = %d", - intval($channel_id) - ); - if($r) { - for($x = 0; $x < count($r); $x ++) { - $r[$x]['subject'] = base64url_decode(str_rot47($r[$x]['subject'])); } - $ret['conv'] = $r; } - $r = q("select * from mail where mail.uid = %d", - intval($channel_id) - ); - if($r) { - $m = array(); - foreach($r as $rr) { - xchan_mail_query($rr); - $m[] = mail_encode($rr,true); + if(in_array('mail',$sections)) { + $r = q("select * from conv where uid = %d", + intval($channel_id) + ); + if($r) { + for($x = 0; $x < count($r); $x ++) { + $r[$x]['subject'] = base64url_decode(str_rot47($r[$x]['subject'])); + } + $ret['conv'] = $r; } - $ret['mail'] = $m; - } - $r = q("select * from item where resource_type like 'nwiki%%' and uid = %d order by created", - intval($channel_id) - ); - if($r) { - $ret['wiki'] = array(); - xchan_query($r); - $r = fetch_post_tags($r,true); - foreach($r as $rv) { - $ret['wiki'][] = encode_item($rv,true); + $r = q("select * from mail where mail.uid = %d", + intval($channel_id) + ); + if($r) { + $m = array(); + foreach($r as $rr) { + xchan_mail_query($rr); + $m[] = mail_encode($rr,true); + } + $ret['mail'] = $m; } } - /** @warning this may run into memory limits on smaller systems */ + if(in_array('wikis',$sections)) { + $r = q("select * from item where resource_type like 'nwiki%%' and uid = %d order by created", + intval($channel_id) + ); + if($r) { + $ret['wiki'] = array(); + xchan_query($r); + $r = fetch_post_tags($r,true); + foreach($r as $rv) { + $ret['wiki'][] = encode_item($rv,true); + } + } + } + if(in_array('items',$sections)) { + /** @warning this may run into memory limits on smaller systems */ - /** export three months of posts. If you want to export and import all posts you have to start with - * the first year and export/import them in ascending order. - * - * Don't export linked resource items. we'll have to pull those out separately. - */ + /** export three months of posts. If you want to export and import all posts you have to start with + * the first year and export/import them in ascending order. + * + * 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 and created > %s - INTERVAL %s and resource_type = '' order by created", - intval($channel_id), - db_utcnow(), - db_quoteinterval('3 MONTH') - ); - if($r) { - $ret['item'] = array(); - xchan_query($r); - $r = fetch_post_tags($r,true); - foreach($r as $rr) - $ret['item'][] = encode_item($rr,true); + $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(), + db_quoteinterval('3 MONTH') + ); + if($r) { + $ret['item'] = array(); + xchan_query($r); + $r = fetch_post_tags($r,true); + foreach($r as $rr) + $ret['item'][] = encode_item($rr,true); + } } + $addon = [ 'channel_id' => $channel_id, 'sections' => $sections, 'data' => $ret]; + call_hooks('identity_basic_export',$addon); + $ret = $addon['data']; + return $ret; } diff --git a/include/text.php b/include/text.php index 4f0dc869b..8c01ed1d2 100644 --- a/include/text.php +++ b/include/text.php @@ -3130,6 +3130,7 @@ function gen_link_id($mid) { return $mid; } + // callback for array_walk function array_trim(&$v,$k) { -- cgit v1.2.3 From f4aca35a889753be85cb0db5fbfb19824b882fdb Mon Sep 17 00:00:00 2001 From: zotlabs Date: Tue, 31 Jan 2017 16:01:47 -0800 Subject: move diaspora account import to the diaspora plugin --- include/Import/import_diaspora.php | 148 ------------------------------------- 1 file changed, 148 deletions(-) delete mode 100644 include/Import/import_diaspora.php (limited to 'include') diff --git a/include/Import/import_diaspora.php b/include/Import/import_diaspora.php deleted file mode 100644 index c6dae0117..000000000 --- a/include/Import/import_diaspora.php +++ /dev/null @@ -1,148 +0,0 @@ - escape_tags($data['user']['name']), - 'nickname' => $address, - 'account_id' => $account['account_id'], - 'permissions_role' => 'social' - )); - - if(! $c['success']) - return; - - $channel_id = $c['channel']['channel_id']; - - // Hubzilla only: Turn on the Diaspora protocol so that follow requests will be sent. - - set_pconfig($channel_id,'system','diaspora_allowed','1'); - - // todo - add auto follow settings, (and strip exif in hubzilla) - - $location = escape_tags($data['user']['profile']['location']); - if(! $location) - $location = ''; - - - q("update channel set channel_location = '%s' where channel_id = %d", - dbesc($location), - intval($channel_id) - ); - - if($data['user']['profile']['nsfw']) { - q("update channel set channel_pageflags = (channel_pageflags | %d) where channel_id = %d", - intval(PAGE_ADULT), - intval($channel_id) - ); - } - - if($data['user']['profile']['image_url']) { - $p = z_fetch_url($data['user']['profile']['image_url'],true); - if($p['success']) { - $rawbytes = $p['body']; - $type = guess_image_type('dummyfile',$p['header']); - import_channel_photo($rawbytes,$type,$c['channel']['channel_account_id'],$channel_id); - } - } - - $gender = escape_tags($data['user']['profile']['gender']); - $about = markdown_to_bb($data['user']['profile']['bio']); - $publish = intval($data['user']['profile']['searchable']); - if($data['user']['profile']['birthday']) - $dob = datetime_convert('UTC','UTC',$data['user']['profile']['birthday'],'Y-m-d'); - else - $dob = '0000-00-00'; - - // we're relying on the fact that this channel was just created and will only - // have the default profile currently - - $r = q("update profile set gender = '%s', about = '%s', dob = '%s', publish = %d where uid = %d", - dbesc($gender), - dbesc($about), - dbesc($dob), - dbesc($publish), - intval($channel_id) - ); - - if($data['user']['aspects']) { - foreach($data['user']['aspects'] as $aspect) { - group_add($channel_id,escape_tags($aspect['name']),intval($aspect['contacts_visible'])); - } - } - - // now add connections and send friend requests - - - if($data['user']['contacts']) { - foreach($data['user']['contacts'] as $contact) { - $result = new_contact($channel_id, $contact['person_diaspora_handle'], $c['channel']); - if($result['success']) { - if($contact['aspects']) { - foreach($contact['aspects'] as $aspect) { - group_add_member($channel_id,$aspect['name'],$result['abook']['xchan_hash']); - } - } - } - } - } - - - // Then add items - note this can't be done until Diaspora adds guids to exported - // items and comments - - - - // This will indirectly perform a refresh_all *and* update the directory - - proc_run('php', 'include/directory.php', $channel_id); - - notice( t('Import completed.') . EOL); - - change_channel($channel_id); - - goaway(z_root() . '/network' ); - -} \ No newline at end of file -- cgit v1.2.3 From 4f99d641c5168c30ff402209bc6eea08d87c1caf Mon Sep 17 00:00:00 2001 From: zotlabs Date: Tue, 31 Jan 2017 17:32:52 -0800 Subject: superfluous whitespace cleanup --- include/channel.php | 2 +- include/import.php | 707 ++++++++++++++++++++++++++-------------------------- 2 files changed, 358 insertions(+), 351 deletions(-) (limited to 'include') diff --git a/include/channel.php b/include/channel.php index 83cf97305..bc36a5707 100644 --- a/include/channel.php +++ b/include/channel.php @@ -846,7 +846,7 @@ function channel_export_items($channel_id, $start, $finish) { $ret['relocate'] = [ 'channel_address' => $ch['channel_address'], 'url' => z_root()]; } - $r = q("select * from item where ( item_wall = 1 or item_type != %d ) and item_deleted = 0 and uid = %d and created >= '%s' and created < '%s' and resource_type = '' order by created", + $r = q("select * from item where ( item_wall = 1 or item_type != %d ) and item_deleted = 0 and uid = %d and created >= '%s' and created <= '%s' and resource_type = '' order by created", intval(ITEM_TYPE_POST), intval($channel_id), dbesc($start), diff --git a/include/import.php b/include/import.php index d19d056b3..d48995a79 100644 --- a/include/import.php +++ b/include/import.php @@ -1187,413 +1187,420 @@ function convert_oldfields(&$arr,$old,$new) { } function scan_webpage_elements($path, $type, $cloud = false) { - $channel = \App::get_channel(); - $dirtoscan = $path; - switch ($type) { - case 'page': - $dirtoscan .= '/pages/'; - $json_filename = 'page.json'; - break; - case 'layout': - $dirtoscan .= '/layouts/'; - $json_filename = 'layout.json'; - break; - case 'block': - $dirtoscan .= '/blocks/'; - $json_filename = 'block.json'; - break; - default : - return array(); - } - if($cloud) { - $dirtoscan = get_dirpath_by_cloudpath($channel, $dirtoscan); - } - $elements = []; - if (is_dir($dirtoscan)) { - $dirlist = scandir($dirtoscan); - if ($dirlist) { - foreach ($dirlist as $element) { - if ($element === '.' || $element === '..') { - continue; + $channel = \App::get_channel(); + $dirtoscan = $path; + switch ($type) { + case 'page': + $dirtoscan .= '/pages/'; + $json_filename = 'page.json'; + break; + case 'layout': + $dirtoscan .= '/layouts/'; + $json_filename = 'layout.json'; + break; + case 'block': + $dirtoscan .= '/blocks/'; + $json_filename = 'block.json'; + break; + default : + return array(); + } + if($cloud) { + $dirtoscan = get_dirpath_by_cloudpath($channel, $dirtoscan); + } + $elements = []; + if(is_dir($dirtoscan)) { + $dirlist = scandir($dirtoscan); + if($dirlist) { + foreach($dirlist as $element) { + if($element === '.' || $element === '..') { + continue; + } + $folder = $dirtoscan . '/' . $element; + if(is_dir($folder)) { + if($cloud) { + $jsonfilepath = $folder . '/' . get_filename_by_cloudname($json_filename, $channel, $folder); } - $folder = $dirtoscan . '/' . $element; - if (is_dir($folder)) { + else { + $jsonfilepath = $folder . '/' . $json_filename; + } + if(is_file($jsonfilepath)) { + $metadata = json_decode(file_get_contents($jsonfilepath), true); if($cloud) { - $jsonfilepath = $folder . '/' . get_filename_by_cloudname($json_filename, $channel, $folder); - } else { - $jsonfilepath = $folder . '/' . $json_filename; + $contentfilename = get_filename_by_cloudname($metadata['contentfile'], $channel, $folder); + $metadata['path'] = $folder . '/' . $contentfilename; + } + else { + $contentfilename = $metadata['contentfile']; + $metadata['path'] = $folder . '/' . $contentfilename; + } + if($metadata['contentfile'] === '') { + logger('Invalid ' . $type . ' content file'); + return false; } - if (is_file($jsonfilepath)) { - $metadata = json_decode(file_get_contents($jsonfilepath), true); - if($cloud) { - $contentfilename = get_filename_by_cloudname($metadata['contentfile'], $channel, $folder); - $metadata['path'] = $folder . '/' . $contentfilename; - } else { - $contentfilename = $metadata['contentfile']; - $metadata['path'] = $folder . '/' . $contentfilename; + $content = file_get_contents($folder . '/' . $contentfilename); + if(!$content) { + if(is_readable($folder . '/' . $contentfilename)) { + $content = ''; } - if ($metadata['contentfile'] === '') { - logger('Invalid ' . $type . ' content file'); + else { + logger('Failed to get file content for ' . $metadata['contentfile']); return false; } - $content = file_get_contents($folder . '/' . $contentfilename); - if (!$content) { - if(is_readable($folder . '/' . $contentfilename)) { - $content = ''; - } else { - logger('Failed to get file content for ' . $metadata['contentfile']); - return false; - } - } - $elements[] = $metadata; } + $elements[] = $metadata; } } } } - return $elements; } + return $elements; +} - function import_webpage_element($element, $channel, $type) { +function import_webpage_element($element, $channel, $type) { - $arr = array(); // construct information for the webpage element item table record + $arr = array(); // construct information for the webpage element item table record - switch ($type) { - // - // PAGES - // - case 'page': - $arr['item_type'] = ITEM_TYPE_WEBPAGE; - $namespace = 'WEBPAGE'; - $name = $element['pagelink']; - if($name) { - require_once('library/urlify/URLify.php'); - $name = strtolower(\URLify::transliterate($name)); - } - $arr['title'] = $element['title']; - $arr['term'] = $element['term']; - $arr['layout_mid'] = ''; // by default there is no layout associated with the page - // If a layout was specified, find it in the database and get its info. If - // it does not exist, leave layout_mid empty - if($element['layout'] !== '') { - $liid = q("select iid from iconfig where k = 'PDL' and v = '%s' and cat = 'system'", - dbesc($element['layout']) - ); - if($liid) { - $linfo = q("select mid from item where id = %d", - intval($liid[0]['iid']) - ); - $arr['layout_mid'] = $linfo[0]['mid']; - } - } - break; - // - // LAYOUTS - // - case 'layout': - $arr['item_type'] = ITEM_TYPE_PDL; - $namespace = 'PDL'; - $name = $element['name']; - $arr['title'] = $element['description']; - $arr['term'] = $element['term']; - break; - // - // BLOCKS - // - case 'block': - $arr['item_type'] = ITEM_TYPE_BLOCK; - $namespace = 'BUILDBLOCK'; - $name = $element['name']; - $arr['title'] = $element['title']; + switch($type) { + // + // PAGES + // + case 'page': + $arr['item_type'] = ITEM_TYPE_WEBPAGE; + $namespace = 'WEBPAGE'; + $name = $element['pagelink']; + if($name) { + require_once('library/urlify/URLify.php'); + $name = strtolower(\URLify::transliterate($name)); + } + $arr['title'] = $element['title']; + $arr['term'] = $element['term']; + $arr['layout_mid'] = ''; // by default there is no layout associated with the page + // If a layout was specified, find it in the database and get its info. If + // it does not exist, leave layout_mid empty + if($element['layout'] !== '') { + $liid = q("select iid from iconfig where k = 'PDL' and v = '%s' and cat = 'system'", + dbesc($element['layout']) + ); + if($liid) { + $linfo = q("select mid from item where id = %d", + intval($liid[0]['iid']) + ); + $arr['layout_mid'] = $linfo[0]['mid']; + } + } + break; + // + // LAYOUTS + // + case 'layout': + $arr['item_type'] = ITEM_TYPE_PDL; + $namespace = 'PDL'; + $name = $element['name']; + $arr['title'] = $element['description']; + $arr['term'] = $element['term']; + break; + // + // BLOCKS + // + case 'block': + $arr['item_type'] = ITEM_TYPE_BLOCK; + $namespace = 'BUILDBLOCK'; + $name = $element['name']; + $arr['title'] = $element['title']; - break; - default : - return null; // return null if invalid element type - } + break; + default : + return null; // return null if invalid element type + } - $arr['uid'] = $channel['channel_id']; - $arr['aid'] = $channel['channel_account_id']; + $arr['uid'] = $channel['channel_id']; + $arr['aid'] = $channel['channel_account_id']; - // Check if an item already exists based on the name - $iid = q("select iid from iconfig where k = '" . $namespace . "' and v = '%s' and cat = 'system'", - dbesc($name) + // Check if an item already exists based on the name + $iid = q("select iid from iconfig where k = '" . $namespace . "' and v = '%s' and cat = 'system'", + dbesc($name) + ); + if($iid) { // If the item does exist, get the item metadata + $iteminfo = q("select mid,created,edited from item where id = %d", + intval($iid[0]['iid']) ); - if($iid) { // If the item does exist, get the item metadata - $iteminfo = q("select mid,created,edited from item where id = %d", - intval($iid[0]['iid']) - ); - $arr['mid'] = $arr['parent_mid'] = $iteminfo[0]['mid']; - $arr['created'] = $iteminfo[0]['created']; - } else { // otherwise, generate the creation times and unique id - $arr['created'] = datetime_convert('UTC', 'UTC'); - $arr['mid'] = $arr['parent_mid'] = item_message_id(); - } - // Update the edited time whether or not the element already exists - $arr['edited'] = datetime_convert('UTC', 'UTC'); - // Import the actual element content - $arr['body'] = file_get_contents($element['path']); - // The element owner is the channel importing the elements - $arr['owner_xchan'] = get_observer_hash(); - // 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', - 'text/html', - 'text/markdown', - 'text/plain', - 'application/x-pdl', - 'application/x-php' - ]; - // Blocks and pages can have any of the valid mimetypes, but layouts must be text/bbcode - if((in_array($element['mimetype'], $mimetypes)) && ($type === 'page' || $type === 'block') ) { - $arr['mimetype'] = $element['mimetype']; - } else { - $arr['mimetype'] = 'text/bbcode'; - } + $arr['mid'] = $arr['parent_mid'] = $iteminfo[0]['mid']; + $arr['created'] = $iteminfo[0]['created']; + } + else { // otherwise, generate the creation times and unique id + $arr['created'] = datetime_convert('UTC', 'UTC'); + $arr['mid'] = $arr['parent_mid'] = item_message_id(); + } + // Update the edited time whether or not the element already exists + $arr['edited'] = datetime_convert('UTC', 'UTC'); + // Import the actual element content + $arr['body'] = file_get_contents($element['path']); + // The element owner is the channel importing the elements + $arr['owner_xchan'] = get_observer_hash(); + // 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', + 'text/html', + 'text/markdown', + 'text/plain', + 'application/x-pdl', + 'application/x-php' + ]; + // Blocks and pages can have any of the valid mimetypes, but layouts must be text/bbcode + if((in_array($element['mimetype'], $mimetypes)) && ($type === 'page' || $type === 'block') ) { + $arr['mimetype'] = $element['mimetype']; + } + else { + $arr['mimetype'] = 'text/bbcode'; + } - // 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()) - ); + // 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; - } + 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) - ); + $z = q("select * from iconfig where v = '%s' and k = '%s' and cat = 'system' limit 1", + dbesc($name), + dbesc($namespace) + ); - $i = q("select id, edited, item_deleted from item where mid = '%s' and uid = %d limit 1", - dbesc($arr['mid']), - intval(local_channel()) - ); - $remote_id = 0; - if ($z && $i) { - $remote_id = $z[0]['id']; - $arr['id'] = $i[0]['id']; - // don't update if it has the same timestamp as the original - if ($arr['edited'] > $i[0]['edited']) - $x = item_store_update($arr, $execflag); - } else { - if (($i) && (intval($i[0]['item_deleted']))) { - // was partially deleted already, finish it off - q("delete from item where mid = '%s' and uid = %d", - dbesc($arr['mid']), - intval(local_channel()) - ); - } - $x = item_store($arr, $execflag); - } - if ($x['success']) { - $item_id = $x['item_id']; - update_remote_id($channel, $item_id, $arr['item_type'], $name, $namespace, $remote_id, $arr['mid']); - $element['import_success'] = 1; - } else { - $element['import_success'] = 0; + $i = q("select id, edited, item_deleted from item where mid = '%s' and uid = %d limit 1", + dbesc($arr['mid']), + intval(local_channel()) + ); + $remote_id = 0; + if($z && $i) { + $remote_id = $z[0]['id']; + $arr['id'] = $i[0]['id']; + // don't update if it has the same timestamp as the original + if($arr['edited'] > $i[0]['edited']) + $x = item_store_update($arr, $execflag); + } + else { + if(($i) && (intval($i[0]['item_deleted']))) { + // was partially deleted already, finish it off + q("delete from item where mid = '%s' and uid = %d", + dbesc($arr['mid']), + intval(local_channel()) + ); } + $x = item_store($arr, $execflag); + } + if($x['success']) { + $item_id = $x['item_id']; + update_remote_id($channel, $item_id, $arr['item_type'], $name, $namespace, $remote_id, $arr['mid']); + $element['import_success'] = 1; + } + else { + $element['import_success'] = 0; + } - return $element; - + return $element; } function get_webpage_elements($channel, $type = 'all') { - $elements = array(); - if(!$channel['channel_id']) { - return null; - } - switch ($type) { - case 'all': - // If all, execute all the pages, layouts, blocks case statements - case 'pages': - $elements['pages'] = null; - $owner = $channel['channel_id']; + $elements = array(); + if(!$channel['channel_id']) { + return null; + } + switch($type) { + case 'all': + // If all, execute all the pages, layouts, blocks case statements + case 'pages': + $elements['pages'] = null; + $owner = $channel['channel_id']; - $sql_extra = item_permissions_sql($owner); + $sql_extra = item_permissions_sql($owner); - $r = q("select * from iconfig left join item on iconfig.iid = item.id - where item.uid = %d and iconfig.cat = 'system' and iconfig.k = 'WEBPAGE' and item_type = %d - $sql_extra order by item.created desc", - intval($owner), - intval(ITEM_TYPE_WEBPAGE) - ); + $r = q("select * from iconfig left join item on iconfig.iid = item.id + where item.uid = %d and iconfig.cat = 'system' and iconfig.k = 'WEBPAGE' and item_type = %d + $sql_extra order by item.created desc", + intval($owner), + intval(ITEM_TYPE_WEBPAGE) + ); - $pages = null; + $pages = null; - if($r) { - $elements['pages'] = array(); - $pages = array(); - foreach($r as $rr) { - unobscure($rr); - - //$lockstate = (($rr['allow_cid'] || $rr['allow_gid'] || $rr['deny_cid'] || $rr['deny_gid']) ? 'lock' : 'unlock'); - - $element_arr = array( - 'type' => 'webpage', - 'title' => $rr['title'], - 'body' => $rr['body'], - 'created' => $rr['created'], - 'edited' => $rr['edited'], - 'mimetype' => $rr['mimetype'], - 'pagetitle' => $rr['v'], - 'mid' => $rr['mid'], - 'layout_mid' => $rr['layout_mid'] - ); - $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']), - 'bb_element' => '[element]' . base64url_encode(json_encode($element_arr)) . '[/element]', - //'lockstate' => $lockstate - ); - $elements['pages'][] = $element_arr; - } + if($r) { + $elements['pages'] = array(); + $pages = array(); + foreach($r as $rr) { + unobscure($rr); + + //$lockstate = (($rr['allow_cid'] || $rr['allow_gid'] || $rr['deny_cid'] || $rr['deny_gid']) ? 'lock' : 'unlock'); + + $element_arr = array( + 'type' => 'webpage', + 'title' => $rr['title'], + 'body' => $rr['body'], + 'created' => $rr['created'], + 'edited' => $rr['edited'], + 'mimetype' => $rr['mimetype'], + 'pagetitle' => $rr['v'], + 'mid' => $rr['mid'], + 'layout_mid' => $rr['layout_mid'] + ); + $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']), + 'bb_element' => '[element]' . base64url_encode(json_encode($element_arr)) . '[/element]', + //'lockstate' => $lockstate + ); + $elements['pages'][] = $element_arr; + } - } - if($type !== 'all') { - break; - } + } + if($type !== 'all') { + break; + } - case 'layouts': - $elements['layouts'] = null; - $owner = $channel['channel_id']; + case 'layouts': + $elements['layouts'] = null; + $owner = $channel['channel_id']; - $sql_extra = item_permissions_sql($owner); + $sql_extra = item_permissions_sql($owner); - $r = q("select * from iconfig left join item on iconfig.iid = item.id - where item.uid = %d and iconfig.cat = 'system' and iconfig.k = 'PDL' and item_type = %d - $sql_extra order by item.created desc", - intval($owner), - intval(ITEM_TYPE_PDL) - ); + $r = q("select * from iconfig left join item on iconfig.iid = item.id + where item.uid = %d and iconfig.cat = 'system' and iconfig.k = 'PDL' and item_type = %d + $sql_extra order by item.created desc", + intval($owner), + intval(ITEM_TYPE_PDL) + ); - $layouts = null; + $layouts = null; - if($r) { - $elements['layouts'] = array(); - $layouts = array(); - foreach($r as $rr) { - unobscure($rr); - - $elements['layouts'][] = array( - 'type' => 'layout', - 'description' => $rr['title'], // description of the layout - 'body' => $rr['body'], - 'created' => $rr['created'], - 'edited' => $rr['edited'], - 'mimetype' => $rr['mimetype'], - 'name' => $rr['v'], // name of reference for the layout - 'mid' => $rr['mid'], - ); - } - - } + if($r) { + $elements['layouts'] = array(); + $layouts = array(); + foreach($r as $rr) { + unobscure($rr); + + $elements['layouts'][] = array( + 'type' => 'layout', + 'description' => $rr['title'], // description of the layout + 'body' => $rr['body'], + 'created' => $rr['created'], + 'edited' => $rr['edited'], + 'mimetype' => $rr['mimetype'], + 'name' => $rr['v'], // name of reference for the layout + 'mid' => $rr['mid'], + ); + } + } - if($type !== 'all') { - break; - } + if($type !== 'all') { + break; + } - case 'blocks': - $elements['blocks'] = null; - $owner = $channel['channel_id']; + case 'blocks': + $elements['blocks'] = null; + $owner = $channel['channel_id']; - $sql_extra = item_permissions_sql($owner); + $sql_extra = item_permissions_sql($owner); - $r = q("select iconfig.iid, iconfig.k, iconfig.v, mid, title, body, mimetype, created, edited from iconfig - left join item on iconfig.iid = item.id - where uid = %d and iconfig.cat = 'system' and iconfig.k = 'BUILDBLOCK' - and item_type = %d order by item.created desc", - intval($owner), - intval(ITEM_TYPE_BLOCK) - ); + $r = q("select iconfig.iid, iconfig.k, iconfig.v, mid, title, body, mimetype, created, edited from iconfig + left join item on iconfig.iid = item.id + where uid = %d and iconfig.cat = 'system' and iconfig.k = 'BUILDBLOCK' + and item_type = %d order by item.created desc", + intval($owner), + intval(ITEM_TYPE_BLOCK) + ); - $blocks = null; + $blocks = null; - if($r) { - $elements['blocks'] = array(); - $blocks = array(); - foreach($r as $rr) { - unobscure($rr); - - $elements['blocks'][] = array( - 'type' => 'block', - 'title' => $rr['title'], - 'body' => $rr['body'], - 'created' => $rr['created'], - 'edited' => $rr['edited'], - 'mimetype' => $rr['mimetype'], - 'name' => $rr['v'], - 'mid' => $rr['mid'] - ); - } + if($r) { + $elements['blocks'] = array(); + $blocks = array(); + foreach($r as $rr) { + unobscure($rr); + + $elements['blocks'][] = array( + 'type' => 'block', + 'title' => $rr['title'], + 'body' => $rr['body'], + 'created' => $rr['created'], + 'edited' => $rr['edited'], + 'mimetype' => $rr['mimetype'], + 'name' => $rr['v'], + 'mid' => $rr['mid'] + ); + } - } + } - if($type !== 'all') { - break; - } + if($type !== 'all') { + break; + } - default: - break; - } - return $elements; + default: + break; + } + return $elements; } /* creates a compressed zip file */ function create_zip_file($files = array(), $destination = '', $overwrite = false) { - //if the zip file already exists and overwrite is false, return false - if (file_exists($destination) && !$overwrite) { - return false; + // if the zip file already exists and overwrite is false, return false + if(file_exists($destination) && !$overwrite) { + return false; + } + //vars + $valid_files = array(); + // if files were passed in... + if(is_array($files)) { + // cycle through each file + foreach($files as $file) { + // make sure the file exists + if(file_exists($file)) { + $valid_files[] = $file; + } } - //vars - $valid_files = array(); - //if files were passed in... - if (is_array($files)) { - //cycle through each file - foreach ($files as $file) { - //make sure the file exists - if (file_exists($file)) { - $valid_files[] = $file; - } - } - } - - //if we have good files... - if (count($valid_files)) { - //create the archive - $zip = new ZipArchive(); - if ($zip->open($destination, $overwrite ? ZIPARCHIVE::OVERWRITE : ZIPARCHIVE::CREATE) !== true) { - return false; - } - //add the files - foreach ($valid_files as $file) { - $zip->addFile($file, $file); - } - //debug - //echo 'The zip archive contains ',$zip->numFiles,' files with a status of ',$zip->status; - //close the zip -- done! - $zip->close(); - - //check to make sure the file exists - return file_exists($destination); - } else { - return false; + } + + // if we have good files... + if(count($valid_files)) { + //create the archive + $zip = new ZipArchive(); + if($zip->open($destination, $overwrite ? ZIPARCHIVE::OVERWRITE : ZIPARCHIVE::CREATE) !== true) { + return false; } + // add the files + foreach($valid_files as $file) { + $zip->addFile($file, $file); + } + //debug + //echo 'The zip archive contains ',$zip->numFiles,' files with a status of ',$zip->status; + //close the zip -- done! + $zip->close(); + + // check to make sure the file exists + return file_exists($destination); + } + else { + return false; + } } -- cgit v1.2.3 From bf820beb791d8a5c0c504c5e1b2704d56c5b78a1 Mon Sep 17 00:00:00 2001 From: Mario Vavti Date: Wed, 1 Feb 2017 12:59:56 +0100 Subject: remove experimental_app_bin config conditional --- include/nav.php | 36 +++++++++++++++++------------------- 1 file changed, 17 insertions(+), 19 deletions(-) (limited to 'include') diff --git a/include/nav.php b/include/nav.php index 25f2a1df4..1adc352a7 100644 --- a/include/nav.php +++ b/include/nav.php @@ -244,29 +244,27 @@ EOT; //app bin - $navapps = ''; - if(get_config('system','experimental_app_bin')) { - if(local_channel()) { - //Zlib\Apps::import_system_apps(); - $syslist = array(); - $list = Zlib\Apps::app_list(local_channel(), false, 'nav_featured_app'); - if($list) { - foreach($list as $li) { - $syslist[] = Zlib\Apps::app_encode($li); - } + if(local_channel()) { + //Zlib\Apps::import_system_apps(); + $syslist = array(); + $list = Zlib\Apps::app_list(local_channel(), false, 'nav_featured_app'); + if($list) { + foreach($list as $li) { + $syslist[] = Zlib\Apps::app_encode($li); } - Zlib\Apps::translate_system_apps($syslist); - } - else { - $syslist = Zlib\Apps::get_system_apps(true); } - - $navapps = replace_macros(get_markup_template('navapps.tpl'), array( - '$apps' => $syslist, - '$localuser' => local_channel(), - )); + Zlib\Apps::translate_system_apps($syslist); + } + else { + $syslist = Zlib\Apps::get_system_apps(true); } + $navapps = replace_macros(get_markup_template('navapps.tpl'), array( + '$apps' => $syslist, + '$localuser' => local_channel(), + )); + + $tpl = get_markup_template('nav.tpl'); App::$page['nav'] .= replace_macros($tpl, array( -- cgit v1.2.3 From db710cd2dfc67f4bb4c6dfde5ff62cf0a11d9f08 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Wed, 1 Feb 2017 14:45:52 -0800 Subject: fix a few style issues with nav login panel --- include/nav.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include') diff --git a/include/nav.php b/include/nav.php index 25f2a1df4..7d6877600 100644 --- a/include/nav.php +++ b/include/nav.php @@ -112,7 +112,7 @@ EOT; } else { if(! get_account_id()) { - $nav['login'] = login(); + $nav['login'] = login(true,'main-login',false,false); $nav['loginmenu'][] = Array('login',t('Login'),'',t('Sign in'),'login_nav_btn'); } else -- cgit v1.2.3 From 8220a6584ca78e8db01d1bd1ea8720cec6952d12 Mon Sep 17 00:00:00 2001 From: Mario Vavti Date: Thu, 2 Feb 2017 11:19:06 +0100 Subject: remove apps from usermenu --- include/nav.php | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) (limited to 'include') diff --git a/include/nav.php b/include/nav.php index 894b30b45..98b6ebe3f 100644 --- a/include/nav.php +++ b/include/nav.php @@ -85,30 +85,30 @@ EOT; $nav['logout'] = Array('logout',t('Logout'), "", t('End this session'),'logout_nav_btn'); // user menu - $nav['usermenu'][] = Array('channel/' . $channel['channel_address'], t('Home'), "", t('Your posts and conversations'),'channel_nav_btn'); + //$nav['usermenu'][] = Array('channel/' . $channel['channel_address'], t('Home'), "", t('Your posts and conversations'),'channel_nav_btn'); $nav['usermenu'][] = Array('profile/' . $channel['channel_address'], t('View Profile'), "", t('Your profile page'),'profile_nav_btn'); if(feature_enabled(local_channel(),'multi_profiles') && (! $basic)) $nav['usermenu'][] = Array('profiles', t('Edit Profiles'),"", t('Manage/Edit profiles'),'profiles_nav_btn'); else $nav['usermenu'][] = Array('profiles/' . $prof[0]['id'], t('Edit Profile'),"", t('Edit your profile'),'profiles_nav_btn'); - $nav['usermenu'][] = Array('photos/' . $channel['channel_address'], t('Photos'), "", t('Your photos'),'photos_nav_btn'); - $nav['usermenu'][] = Array('cloud/' . $channel['channel_address'],t('Files'),"",t('Your files'),'cloud_nav_btn'); + //$nav['usermenu'][] = Array('photos/' . $channel['channel_address'], t('Photos'), "", t('Your photos'),'photos_nav_btn'); + //$nav['usermenu'][] = Array('cloud/' . $channel['channel_address'],t('Files'),"",t('Your files'),'cloud_nav_btn'); - if((! $basic) && feature_enabled(local_channel(),'ajaxchat')) - $nav['usermenu'][] = Array('chat/' . $channel['channel_address'], t('Chat'),"",t('Your chatrooms'),'chat_nav_btn'); + //if((! $basic) && feature_enabled(local_channel(),'ajaxchat')) + // $nav['usermenu'][] = Array('chat/' . $channel['channel_address'], t('Chat'),"",t('Your chatrooms'),'chat_nav_btn'); - require_once('include/menu.php'); - $has_bookmarks = menu_list_count(local_channel(),'',MENU_BOOKMARK) + menu_list_count(local_channel(),'',MENU_SYSTEM|MENU_BOOKMARK); - if(($has_bookmarks) && (! $basic)) { - $nav['usermenu'][] = Array('bookmarks', t('Bookmarks'), "", t('Your bookmarks'),'bookmarks_nav_btn'); - } + //require_once('include/menu.php'); + //$has_bookmarks = menu_list_count(local_channel(),'',MENU_BOOKMARK) + menu_list_count(local_channel(),'',MENU_SYSTEM|MENU_BOOKMARK); + //if(($has_bookmarks) && (! $basic)) { + // $nav['usermenu'][] = Array('bookmarks', t('Bookmarks'), "", t('Your bookmarks'),'bookmarks_nav_btn'); + //} - if(feature_enabled($channel['channel_id'],'webpages') && (! $basic)) - $nav['usermenu'][] = Array('webpages/' . $channel['channel_address'],t('Webpages'),"",t('Your webpages'),'webpages_nav_btn'); - if(feature_enabled($channel['channel_id'],'wiki') && (! $basic)) - $nav['usermenu'][] = Array('wiki/' . $channel['channel_address'],t('Wikis'),"",t('Your wikis'),'wiki_nav_btn'); + //if(feature_enabled($channel['channel_id'],'webpages') && (! $basic)) + // $nav['usermenu'][] = Array('webpages/' . $channel['channel_address'],t('Webpages'),"",t('Your webpages'),'webpages_nav_btn'); + //if(feature_enabled($channel['channel_id'],'wiki') && (! $basic)) + // $nav['usermenu'][] = Array('wiki/' . $channel['channel_address'],t('Wikis'),"",t('Your wikis'),'wiki_nav_btn'); } else { if(! get_account_id()) { -- cgit v1.2.3 From 2daafe80a5cc9af9fb40712135490c86155fb9cf Mon Sep 17 00:00:00 2001 From: zotlabs Date: Thu, 2 Feb 2017 14:49:51 -0800 Subject: move opensearch to plugins --- include/plugin.php | 32 +++++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) (limited to 'include') diff --git a/include/plugin.php b/include/plugin.php index 80c303b42..3a64f67cc 100755 --- a/include/plugin.php +++ b/include/plugin.php @@ -556,21 +556,47 @@ function head_add_css($src, $media = 'screen') { function head_remove_css($src, $media = 'screen') { $index = array_search(array($src, $media), App::$css_sources); - if ($index !== false) + if($index !== false) unset(App::$css_sources[$index]); } function head_get_css() { $str = ''; $sources = App::$css_sources; - if (count($sources)) { - foreach ($sources as $source) + if(count($sources)) { + foreach($sources as $source) $str .= format_css_if_exists($source); } return $str; } +function head_add_link($arr) { + if($arr) { + App::$linkrel[] = $arr; + } +} + +function head_get_links() { + $str = ''; + $sources = App::$linkrel; + if(count($sources)) { + foreach($sources as $source) { + if(is_array($source) && count($source)) { + $str .= ' $v) { + $str .= ' ' . $k . '="' . $v . '"'; + } + $str .= ' />' . "\r\n"; + + } + } + } + + return $str; +} + + function format_css_if_exists($source) { $path_prefix = script_path() . '/'; -- cgit v1.2.3 From 7e1e9ac94a1cf2fb01a3052f7fd9d0f2049079b5 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Thu, 2 Feb 2017 19:12:48 -0800 Subject: rename bb2diaspora.php to markdown.php --- include/bb2diaspora.php | 532 ------------------------------------------------ include/items.php | 2 +- include/markdown.php | 532 ++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 533 insertions(+), 533 deletions(-) delete mode 100644 include/bb2diaspora.php create mode 100644 include/markdown.php (limited to 'include') diff --git a/include/bb2diaspora.php b/include/bb2diaspora.php deleted file mode 100644 index 1759154f0..000000000 --- a/include/bb2diaspora.php +++ /dev/null @@ -1,532 +0,0 @@ - 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) { - - $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]' ; - -} - - -/** - * @brief - * - * We don't want to support a bbcode specific markdown interpreter - * and the markdown library we have is pretty good, but provides HTML output. - * So we'll use that to convert to HTML, then convert the HTML back to bbcode, - * and then clean up a few Diaspora specific constructs. - * - * @param string $s - * @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); - - if(is_array($s)) { - btlogger('markdown_to_bb called with array. ' . print_r($s,true), LOGGER_NORMAL, LOG_WARNING); - return ''; - } - - $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 - - $s = preg_replace_callback('/\@\{(.+?)\; (.+?)\@(.+?)\}\+/','diaspora_mention_callback',$s); - - $s = preg_replace_callback('/\@\{(.+?)\; (.+?)\@(.+?)\}/','diaspora_mention_callback',$s); - - // Escaping the hash tags - doesn't always seem to work - // $s = preg_replace('/\#([^\s\#])/','\\#$1',$s); - // This seems to work - $s = preg_replace('/\#([^\s\#])/','#$1',$s); - - $s = Markdown($s); - - $s = str_replace("\r","",$s); - - $s = str_replace('#','#',$s); - - $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); - $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); - } - - // remove duplicate adjacent code tags - $s = preg_replace("/(\[code\])+(.*?)(\[\/code\])+/ism","[code]$2[/code]", $s); - - // Don't show link to full picture (until it is fixed) - $s = scale_external_images($s, false); - - call_hooks('markdown_to_bb',$s); - - return $s; -} - - -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 - - - $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(); - - 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; - - 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 Markdownify(false, 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; -} diff --git a/include/items.php b/include/items.php index 559992b7f..139c637e5 100755 --- a/include/items.php +++ b/include/items.php @@ -2191,7 +2191,7 @@ function store_diaspora_comment_sig($datarray, $channel, $parent_item, $post_id, // since Diaspora doesn't handle edits we can only do this for the original text and not update it. - require_once('include/bb2diaspora.php'); + require_once('include/markdown.php'); $signed_body = bb2diaspora_itembody($datarray,$walltowall); if($walltowall) { diff --git a/include/markdown.php b/include/markdown.php new file mode 100644 index 000000000..b4656f769 --- /dev/null +++ b/include/markdown.php @@ -0,0 +1,532 @@ + 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) { + + $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]' ; + +} + + +/** + * @brief + * + * We don't want to support a bbcode specific markdown interpreter + * and the markdown library we have is pretty good, but provides HTML output. + * So we'll use that to convert to HTML, then convert the HTML back to bbcode, + * and then clean up a few Diaspora specific constructs. + * + * @param string $s + * @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); + + if(is_array($s)) { + btlogger('markdown_to_bb called with array. ' . print_r($s,true), LOGGER_NORMAL, LOG_WARNING); + return ''; + } + + $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 + + $s = preg_replace_callback('/\@\{(.+?)\; (.+?)\@(.+?)\}\+/','diaspora_mention_callback',$s); + + $s = preg_replace_callback('/\@\{(.+?)\; (.+?)\@(.+?)\}/','diaspora_mention_callback',$s); + + // Escaping the hash tags - doesn't always seem to work + // $s = preg_replace('/\#([^\s\#])/','\\#$1',$s); + // This seems to work + $s = preg_replace('/\#([^\s\#])/','#$1',$s); + + $s = Markdown($s); + + $s = str_replace("\r","",$s); + + $s = str_replace('#','#',$s); + + $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); + $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); + } + + // remove duplicate adjacent code tags + $s = preg_replace("/(\[code\])+(.*?)(\[\/code\])+/ism","[code]$2[/code]", $s); + + // Don't show link to full picture (until it is fixed) + $s = scale_external_images($s, false); + + call_hooks('markdown_to_bb',$s); + + return $s; +} + + +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 + + + $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(); + + 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; + + 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 Markdownify(false, 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 dce9a70ff59658249abeb58af46144eea16c721b Mon Sep 17 00:00:00 2001 From: Mario Vavti Date: Fri, 3 Feb 2017 12:12:05 +0100 Subject: check for app-icons in app_list() instead of app_render() --- include/nav.php | 1 - 1 file changed, 1 deletion(-) (limited to 'include') diff --git a/include/nav.php b/include/nav.php index 98b6ebe3f..356c0643b 100644 --- a/include/nav.php +++ b/include/nav.php @@ -264,7 +264,6 @@ EOT; '$localuser' => local_channel(), )); - $tpl = get_markup_template('nav.tpl'); App::$page['nav'] .= replace_macros($tpl, array( -- cgit v1.2.3 From fc4083346eb6d7010e018b3dab92711f777f8572 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Fri, 3 Feb 2017 15:31:01 -0800 Subject: more work on nav-modal --- include/nav.php | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) (limited to 'include') diff --git a/include/nav.php b/include/nav.php index 7d6877600..846ede717 100644 --- a/include/nav.php +++ b/include/nav.php @@ -76,6 +76,20 @@ EOT; $userinfo = null; $nav['loginmenu']=array(); + if($observer) { + $userinfo = array( + 'icon' => $observer['xchan_photo_m'], + 'name' => $observer['xchan_addr'], + ); + } + + elseif(! $_SESSION['authenticated']) { + $nav['remote_login'] = remote_login(); + $nav['loginmenu'][] = Array('rmagic',t('Remote authentication'),'',t('Click to authenticate to your home hub'),'rmagic_nav_btn'); + } + + + if(local_channel()) { @@ -114,6 +128,13 @@ EOT; if(! get_account_id()) { $nav['login'] = login(true,'main-login',false,false); $nav['loginmenu'][] = Array('login',t('Login'),'',t('Sign in'),'login_nav_btn'); + App::$page['content'] .= replace_macros(get_markup_template('nav_login.tpl'), + [ + '$nav' => $nav, + 'userinfo' => $userinfo + ] + ); + } else $nav['alogout'] = Array('logout',t('Logout'), "", t('End this session'),'logout_nav_btn'); @@ -121,17 +142,6 @@ EOT; } - if($observer) { - $userinfo = array( - 'icon' => $observer['xchan_photo_m'], - 'name' => $observer['xchan_addr'], - ); - } - - elseif(! $_SESSION['authenticated']) { - $nav['remote_login'] = remote_login(); - $nav['loginmenu'][] = Array('rmagic',t('Remote authentication'),'',t('Click to authenticate to your home hub'),'rmagic_nav_btn'); - } $homelink = get_my_url(); if(! $homelink) { -- cgit v1.2.3 From eb3685f5377be06615de66aba104aad6f4927495 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Sun, 5 Feb 2017 18:47:35 -0800 Subject: remove per-page login css (home, login); add support for alternative markdown mention format --- include/markdown.php | 37 ++++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) (limited to 'include') diff --git a/include/markdown.php b/include/markdown.php index b4656f769..7afdc6c54 100644 --- a/include/markdown.php +++ b/include/markdown.php @@ -110,6 +110,39 @@ function diaspora_mention_callback($matches) { } +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 @@ -141,9 +174,11 @@ function markdown_to_bb($s, $use_zrl = false) { // first try plustags $s = preg_replace_callback('/\@\{(.+?)\; (.+?)\@(.+?)\}\+/','diaspora_mention_callback',$s); - $s = preg_replace_callback('/\@\{(.+?)\; (.+?)\@(.+?)\}/','diaspora_mention_callback',$s); + $s = preg_replace_callback('/\@\{(.+?)\@(.+?)\}\+/','diaspora_mention_callback2',$s); + $s = preg_replace_callback('/\@\{(.+?)\@(.+?)\}/','diaspora_mention_callback2',$s); + // Escaping the hash tags - doesn't always seem to work // $s = preg_replace('/\#([^\s\#])/','\\#$1',$s); // This seems to work -- cgit v1.2.3 From 8059260c185aa267d15f2a7d9d0df0c21140ad69 Mon Sep 17 00:00:00 2001 From: Mario Vavti Date: Mon, 6 Feb 2017 13:45:46 +0100 Subject: import system apps on initial load --- include/nav.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'include') diff --git a/include/nav.php b/include/nav.php index 3c97d42da..70e9bfc59 100644 --- a/include/nav.php +++ b/include/nav.php @@ -255,7 +255,11 @@ EOT; //app bin if(local_channel()) { - //Zlib\Apps::import_system_apps(); + 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); + } + $syslist = array(); $list = Zlib\Apps::app_list(local_channel(), false, 'nav_featured_app'); if($list) { -- cgit v1.2.3 From 70edcabca1e9341b857c469760c88e5c9d318c53 Mon Sep 17 00:00:00 2001 From: Mario Vavti Date: Mon, 6 Feb 2017 20:10:10 +0100 Subject: move icon stuff back to app_render() and send navapps through app_render() --- include/nav.php | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'include') diff --git a/include/nav.php b/include/nav.php index 70e9bfc59..a6e59a91f 100644 --- a/include/nav.php +++ b/include/nav.php @@ -273,10 +273,9 @@ EOT; $syslist = Zlib\Apps::get_system_apps(true); } - $navapps = replace_macros(get_markup_template('navapps.tpl'), array( - '$apps' => $syslist, - '$localuser' => local_channel(), - )); + foreach($syslist as $app) { + $navapps[] = Zlib\Apps::app_render($app,'nav'); + } $tpl = get_markup_template('nav.tpl'); -- cgit v1.2.3 From 6a083e845233475edaa711f4752e64eb42159c33 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Mon, 6 Feb 2017 14:32:50 -0800 Subject: bring back view links for all notification types (esp: network, channel) for easy access --- include/nav.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'include') diff --git a/include/nav.php b/include/nav.php index a6e59a91f..35cf80340 100644 --- a/include/nav.php +++ b/include/nav.php @@ -192,9 +192,11 @@ EOT; $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'), '',''); $nav['home'] = array('channel/' . $channel['channel_address'], t('Channel Home'), "", t('Channel home'),'home_nav_btn'); + $nav['home']['all'] = [ 'channel/' . $channel['channel_address'], t('View your channel home'), '' , '' ]; $nav['home']['mark'] = array('', t('Mark all channel notifications seen'), '',''); @@ -202,11 +204,11 @@ EOT; $nav['notifications'] = array('notifications/system', t('Notices'), "", t('Notifications'),'notifications_nav_btn'); - $nav['notifications']['all']=array('notifications/system', t('See all notifications'), "", ""); + $nav['notifications']['all']=array('notifications/system', t('View all notifications'), "", ""); $nav['notifications']['mark'] = array('', t('Mark all system notifications seen'), '',''); $nav['messages'] = array('mail/combined', t('Mail'), "", t('Private mail'),'mail_nav_btn'); - $nav['messages']['all']=array('mail/combined', t('See all private messages'), "", ""); + $nav['messages']['all']=array('mail/combined', t('View your private messages'), "", ""); $nav['messages']['mark'] = array('', t('Mark all private messages seen'), '',''); $nav['messages']['inbox'] = array('mail/inbox', t('Inbox'), "", t('Inbox')); $nav['messages']['outbox']= array('mail/outbox', t('Outbox'), "", t('Outbox')); @@ -214,7 +216,7 @@ EOT; $nav['all_events'] = array('events', t('Events'), "", t('Event Calendar'),'events_nav_btn'); - $nav['all_events']['all']=array('events', t('See all events'), "", ""); + $nav['all_events']['all']=array('events', t('View events'), "", ""); $nav['all_events']['mark'] = array('', t('Mark all events seen'), '',''); if(! $basic) -- cgit v1.2.3 From 1bb56309a62697f6549f159a6ed0d35fbf8f668b Mon Sep 17 00:00:00 2001 From: Mario Vavti Date: Tue, 7 Feb 2017 20:45:13 +0100 Subject: default to manual conversation updates --- include/channel.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'include') diff --git a/include/channel.php b/include/channel.php index bc36a5707..8880c7f45 100644 --- a/include/channel.php +++ b/include/channel.php @@ -1972,6 +1972,8 @@ function channel_manual_conv_update($channel_id) { $x = get_pconfig($channel_id, 'system','manual_conversation_update'); if($x === false) $x = get_config('system','manual_conversation_update'); + if($x === false) + $x = 1; return intval($x); @@ -1989,4 +1991,4 @@ function remote_login() { -} \ No newline at end of file +} -- cgit v1.2.3 From 1cef3f15d5174636b59c86bb816a0009940201ef Mon Sep 17 00:00:00 2001 From: Mario Vavti Date: Tue, 7 Feb 2017 22:32:25 +0100 Subject: sort the apps --- include/nav.php | 2 ++ 1 file changed, 2 insertions(+) (limited to 'include') diff --git a/include/nav.php b/include/nav.php index 35cf80340..43c7771ec 100644 --- a/include/nav.php +++ b/include/nav.php @@ -275,6 +275,8 @@ EOT; $syslist = Zlib\Apps::get_system_apps(true); } + usort($syslist,'Zotlabs\\Lib\\Apps::app_name_compare'); + foreach($syslist as $app) { $navapps[] = Zlib\Apps::app_render($app,'nav'); } -- cgit v1.2.3 From 28f083323750e3083c5ba07f685d30b44e1d2482 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Wed, 8 Feb 2017 11:24:21 -0800 Subject: fix immediate issue with multiple login forms until I can figure out an elegant way to "popup" the modal login form already on the page. We still may need this fix for the actual login module which should always be callable and present a login form even if the nav is completely borked. --- include/auth.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include') diff --git a/include/auth.php b/include/auth.php index fdcecec36..c7be69583 100644 --- a/include/auth.php +++ b/include/auth.php @@ -300,7 +300,7 @@ else { // (i.e. expire when the browser is closed), even when there's a time expiration // on the cookie - if($_POST['remember_me']) { + if(($_POST['remember_me']) || ($_POST['remember'])) { $_SESSION['remember_me'] = 1; App::$session->new_cookie(31449600); // one year } -- cgit v1.2.3 From 91819bfc2d475e1b16d3f5e9ca685ca2531a9084 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Wed, 8 Feb 2017 17:21:32 -0800 Subject: bringer - all basic functionality is implemented --- include/features.php | 9 +++++++++ include/widgets.php | 8 ++++++++ 2 files changed, 17 insertions(+) (limited to 'include') diff --git a/include/features.php b/include/features.php index 8ff0d2d21..0fc6fbc1d 100644 --- a/include/features.php +++ b/include/features.php @@ -148,6 +148,15 @@ function get_features($filtered = true) { feature_level('ajaxchat',1), ], + [ + 'permcats', + t('Permission Groups'), + t('Provide alternate connection permission roles.'), + false, + get_config('feature_lock','permcats'), + feature_level('permcats',2), + ], + [ 'smart_birthdays', t('Smart Birthdays'), diff --git a/include/widgets.php b/include/widgets.php index 408ba5d24..52f8fd655 100644 --- a/include/widgets.php +++ b/include/widgets.php @@ -661,6 +661,14 @@ function widget_settings_menu($arr) { ); } + if(feature_enabled(local_channel(),'permcats')) { + $tabs[] = array( + 'label' => t('Permission Categories'), + 'url' => z_root() . '/settings/permcats', + 'selected' => ((argv(1) === 'permcats') ? 'active' : ''), + ); + } + if($role === false || $role === 'custom') { $tabs[] = array( -- cgit v1.2.3 From 16f27d000460725d26eb875e8522c768100c1715 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Thu, 9 Feb 2017 17:29:24 -0800 Subject: more work on permcats and consolidating calls that try to discover connect permissions, also create lowlevel store functions for abook and profile - since these currently may have issues with sql strict mode. --- include/channel.php | 99 ++++++++++++++++++++++++++++++++++++++----------- include/connections.php | 32 ++++++++++++++++ include/follow.php | 76 +++++++++++++------------------------ include/zot.php | 54 +++++++++++---------------- 4 files changed, 157 insertions(+), 104 deletions(-) (limited to 'include') diff --git a/include/channel.php b/include/channel.php index 8880c7f45..856fb6303 100644 --- a/include/channel.php +++ b/include/channel.php @@ -336,17 +336,18 @@ function create_identity($arr) { // Not checking return value. // It's ok for this to fail if it's an imported channel, and therefore the hash is a duplicate - $r = q("INSERT INTO profile ( aid, uid, profile_guid, profile_name, is_default, publish, fullname, photo, thumb) - VALUES ( %d, %d, '%s', '%s', %d, %d, '%s', '%s', '%s') ", - intval($ret['channel']['channel_account_id']), - intval($newuid), - dbesc(random_string()), - t('Default Profile'), - 1, - $publish, - dbesc($ret['channel']['channel_name']), - dbesc(z_root() . "/photo/profile/l/{$newuid}"), - dbesc(z_root() . "/photo/profile/m/{$newuid}") + $r = profile_store_lowlevel( + [ + 'aid' => intval($ret['channel']['channel_account_id']), + 'uid' => intval($newuid), + 'profile_guid' => random_string(), + 'profile_name' => t('Default Profile'), + 'is_default' => 1, + 'publish' => $publish, + 'fullname' => $ret['channel']['channel_name'], + 'photo' => z_root() . "/photo/profile/l/{$newuid}", + 'thumb' => z_root() . "/photo/profile/m/{$newuid}" + ] ); if($role_permissions) { @@ -357,15 +358,16 @@ function create_identity($arr) { $myperms = $x['perms_connect']; } - $r = q("insert into abook ( abook_account, abook_channel, abook_xchan, abook_closeness, abook_created, abook_updated, abook_self ) - values ( %d, %d, '%s', %d, '%s', '%s', %d ) ", - intval($ret['channel']['channel_account_id']), - intval($newuid), - dbesc($hash), - intval(0), - dbesc(datetime_convert()), - dbesc(datetime_convert()), - intval(1) + $r = abook_store_lowlevel( + [ + 'abook_account' => intval($ret['channel']['channel_account_id']), + 'abook_channel' => intval($newuid), + 'abook_xchan' => $hash, + 'abook_closeness' => 0, + 'abook_created' => datetime_convert(), + 'abook_updated' => datetime_convert(), + 'abook_self' => 1 + ] ); $x = \Zotlabs\Access\Permissions::FilledPerms($myperms); @@ -390,6 +392,7 @@ function create_identity($arr) { set_pconfig($newuid,'autoperms',$k,$v); } } + // as this is a new channel, this shouldn't do anything and probaby is not needed else { $r = q("delete from pconfig where uid = %d and cat = 'autoperms'", intval($newuid) @@ -462,6 +465,7 @@ 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) @@ -499,6 +503,7 @@ function get_default_export_sections() { * @returns array * See function for details */ + function identity_basic_export($channel_id, $sections = null) { /* @@ -1989,6 +1994,58 @@ function remote_login() { )); return $o; +} -} + +function profile_store_lowlevel($arr) { + + $store = [ + 'profile_guid' => ((array_key_exists('profile_guid',$arr)) ? $arr['profile_guid'] : ''), + 'aid' => ((array_key_exists('aid',$arr)) ? $arr['aid'] : 0), + 'uid' => ((array_key_exists('uid',$arr)) ? $arr['uid'] : 0), + 'profile_name' => ((array_key_exists('profile_name',$arr)) ? $arr['profile_name'] : ''), + 'is_default' => ((array_key_exists('is_default',$arr)) ? $arr['is_default'] : 0), + 'hide_friends' => ((array_key_exists('hide_friends',$arr)) ? $arr['hide_friends'] : 0), + 'fullname' => ((array_key_exists('fullname',$arr)) ? $arr['fullname'] : ''), + 'pdesc' => ((array_key_exists('pdesc',$arr)) ? $arr['pdesc'] : ''), + 'chandesc' => ((array_key_exists('chandesc',$arr)) ? $arr['chandesc'] : ''), + 'dob' => ((array_key_exists('dob',$arr)) ? $arr['dob'] : ''), + 'dob_tz' => ((array_key_exists('dob_tz',$arr)) ? $arr['dob_tz'] : ''), + 'address' => ((array_key_exists('address',$arr)) ? $arr['address'] : ''), + 'locality' => ((array_key_exists('locality',$arr)) ? $arr['locality'] : ''), + 'region' => ((array_key_exists('region',$arr)) ? $arr['region'] : ''), + 'postal_code' => ((array_key_exists('postal_code',$arr)) ? $arr['postal_code'] : ''), + 'country_name' => ((array_key_exists('country_name',$arr)) ? $arr['country_name'] : ''), + 'hometown' => ((array_key_exists('hometown',$arr)) ? $arr['hometown'] : ''), + 'gender' => ((array_key_exists('gender',$arr)) ? $arr['gender'] : ''), + 'marital' => ((array_key_exists('marital',$arr)) ? $arr['marital'] : ''), + 'partner' => ((array_key_exists('partner',$arr)) ? $arr['partner'] : ''), + 'howlong' => ((array_key_exists('howlong',$arr)) ? $arr['howlong'] : NULL_DATE), + 'sexual' => ((array_key_exists('sexual',$arr)) ? $arr['sexual'] : ''), + 'politic' => ((array_key_exists('politic',$arr)) ? $arr['politic'] : ''), + 'religion' => ((array_key_exists('religion',$arr)) ? $arr['religion'] : ''), + 'keywords' => ((array_key_exists('keywords',$arr)) ? $arr['keywords'] : ''), + 'likes' => ((array_key_exists('likes',$arr)) ? $arr['likes'] : ''), + 'dislikes' => ((array_key_exists('dislikes',$arr)) ? $arr['dislikes'] : ''), + 'about' => ((array_key_exists('about',$arr)) ? $arr['about'] : ''), + 'summary' => ((array_key_exists('summary',$arr)) ? $arr['summary'] : ''), + 'music' => ((array_key_exists('music',$arr)) ? $arr['music'] : ''), + 'book' => ((array_key_exists('book',$arr)) ? $arr['book'] : ''), + 'tv' => ((array_key_exists('tv',$arr)) ? $arr['tv'] : ''), + 'film' => ((array_key_exists('film',$arr)) ? $arr['film'] : ''), + 'interest' => ((array_key_exists('interest',$arr)) ? $arr['interest'] : ''), + 'romance' => ((array_key_exists('romance',$arr)) ? $arr['romance'] : ''), + 'employment' => ((array_key_exists('employment',$arr)) ? $arr['employment'] : ''), + 'education' => ((array_key_exists('education',$arr)) ? $arr['education'] : ''), + 'contact' => ((array_key_exists('contact',$arr)) ? $arr['contact'] : ''), + 'channels' => ((array_key_exists('channels',$arr)) ? $arr['channels'] : ''), + 'homepage' => ((array_key_exists('homepage',$arr)) ? $arr['homepage'] : ''), + 'photo' => ((array_key_exists('photo',$arr)) ? $arr['photo'] : ''), + 'thumb' => ((array_key_exists('thumb',$arr)) ? $arr['thumb'] : ''), + 'publish' => ((array_key_exists('publish',$arr)) ? $arr['publish'] : 0), + 'profile_vcard' => ((array_key_exists('profile_vcard',$arr)) ? $arr['profile_vcard'] : '') + ]; + + return create_table_from_array('profile',$store); +} \ No newline at end of file diff --git a/include/connections.php b/include/connections.php index f90644ec5..e26943b68 100644 --- a/include/connections.php +++ b/include/connections.php @@ -1,6 +1,38 @@ ((array_key_exists('abook_account',$arr)) ? $arr['abook_account'] : 0), + 'abook_channel' => ((array_key_exists('abook_channel',$arr)) ? $arr['abook_channel'] : 0), + 'abook_xchan' => ((array_key_exists('abook_xchan',$arr)) ? $arr['abook_xchan'] : ''), + 'abook_my_perms' => ((array_key_exists('abook_my_perms',$arr)) ? $arr['abook_my_perms'] : 0), + 'abook_their_perms' => ((array_key_exists('abook_their_perms',$arr)) ? $arr['abook_their_perms'] : 0), + 'abook_closeness' => ((array_key_exists('abook_closeness',$arr)) ? $arr['abook_closeness'] : 99), + 'abook_created' => ((array_key_exists('abook_created',$arr)) ? $arr['abook_created'] : NULL_DATE), + 'abook_updated' => ((array_key_exists('abook_updated',$arr)) ? $arr['abook_updated'] : NULL_DATE), + 'abook_connected' => ((array_key_exists('abook_connected',$arr)) ? $arr['abook_connected'] : NULL_DATE), + 'abook_dob' => ((array_key_exists('abook_dob',$arr)) ? $arr['abook_dob'] : NULL_DATE), + 'abook_flags' => ((array_key_exists('abook_flags',$arr)) ? $arr['abook_flags'] : 0), + 'abook_blocked' => ((array_key_exists('abook_blocked',$arr)) ? $arr['abook_blocked'] : 0), + 'abook_ignored' => ((array_key_exists('abook_ignored',$arr)) ? $arr['abook_ignored'] : 0), + 'abook_hidden' => ((array_key_exists('abook_hidden',$arr)) ? $arr['abook_hidden'] : 0), + 'abook_archived' => ((array_key_exists('abook_archived',$arr)) ? $arr['abook_archived'] : 0), + 'abook_pending' => ((array_key_exists('abook_pending',$arr)) ? $arr['abook_pending'] : 0), + '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_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'] : ''), + 'abook_instance' => ((array_key_exists('abook_instance',$arr)) ? $arr['abook_instance'] : '') + ]; + + return create_table_from_array('abook',$store); + +} + function rconnect_url($channel_id,$xchan) { diff --git a/include/follow.php b/include/follow.php index fa198e402..751d86db1 100644 --- a/include/follow.php +++ b/include/follow.php @@ -13,12 +13,11 @@ require_once('include/zot.php'); function new_contact($uid,$url,$channel,$interactive = false, $confirm = false) { + $result = [ 'success' => false, 'message' => '' ]; - - $result = array('success' => false,'message' => ''); - - $is_red = false; - $is_http = ((strpos($url,'://') !== false) ? true : false); + $my_perms = false; + $is_zot = false; + $is_http = ((strpos($url,'://') !== false) ? true : false); if($is_http && substr($url,-1,1) === '/') $url = substr($url,0,-1); @@ -58,20 +57,14 @@ function new_contact($uid,$url,$channel,$interactive = false, $confirm = false) $ret = Zotlabs\Zot\Finger::run($url,$channel); if($ret && is_array($ret) && $ret['success']) { - $is_red = true; + $is_zot = true; $j = $ret; } - $my_perms = get_channel_default_perms($uid); + $p = \Zotlabs\Access\Permissions::connect_perms($uid); + $my_perms = $p['perms']; - $role = get_pconfig($uid,'system','permissions_role'); - if($role) { - $x = \Zotlabs\Access\PermissionRoles::role_perms($role); - if($x['perms_connect']) - $my_perms = $x['perms_connect']; - } - - if($is_red && $j) { + if($is_zot && $j) { logger('follow: ' . $url . ' ' . print_r($j,true), LOGGER_DEBUG); @@ -166,14 +159,13 @@ function new_contact($uid,$url,$channel,$interactive = false, $confirm = false) } } - if(! $xchan_hash) { $result['message'] = t('Channel discovery failed.'); logger('follow: ' . $result['message']); return $result; } - $allowed = (($is_red || $r[0]['xchan_network'] === 'rss') ? 1 : 0); + $allowed = (($is_zot || $r[0]['xchan_network'] === 'rss') ? 1 : 0); $x = array('channel_id' => $uid, 'follow_address' => $url, 'xchan' => $r[0], 'allowed' => $allowed, 'singleton' => 0); @@ -211,7 +203,8 @@ function new_contact($uid,$url,$channel,$interactive = false, $confirm = false) return $result; } - $r = q("select abook_id, abook_xchan, abook_pending, abook_instance from abook where abook_xchan = '%s' and abook_channel = %d limit 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) ); @@ -226,6 +219,7 @@ function new_contact($uid,$url,$channel,$interactive = false, $confirm = false) } if($r) { + $abook_instance = $r[0]['abook_instance']; if(($singleton) && strpos($abook_instance,z_root()) === false) { @@ -240,21 +234,6 @@ function new_contact($uid,$url,$channel,$interactive = false, $confirm = false) ); if(intval($r[0]['abook_pending'])) { - - $abook_my_perms = get_channel_default_perms($uid); - $role = get_pconfig($uid,'system','permissions_role'); - if($role) { - $x = \Zotlabs\Access\PermissionRoles::role_perms($role); - if($x['perms_connect']) { - $abook_my_perms = $x['perms_connect']; - } - } - - $filled_perms = \Zotlabs\Access\Permissions::FilledPerms($abook_my_perms); - foreach($filled_perms as $k => $v) { - set_abconfig($uid,$r[0]['abook_xchan'],'my_perms',$k,$v); - } - $x = q("update abook set abook_pending = 0 where abook_id = %d", intval($r[0]['abook_id']) ); @@ -265,29 +244,26 @@ function new_contact($uid,$url,$channel,$interactive = false, $confirm = false) if($closeness === false) $closeness = 80; - $r = q("insert into abook ( abook_account, abook_channel, abook_closeness, abook_xchan, abook_feed, abook_created, abook_updated, abook_instance ) - values( %d, %d, %d, '%s', %d, '%s', '%s', '%s' ) ", - intval($aid), - intval($uid), - intval($closeness), - dbesc($xchan_hash), - intval(($is_http) ? 1 : 0), - dbesc(datetime_convert()), - dbesc(datetime_convert()), - dbesc(($singleton) ? z_root() : '') + $r = abook_store_lowlevel( + [ + 'abook_account' => intval($aid), + 'abook_channel' => intval($uid), + 'abook_closeness' => intval($closeness), + 'abook_xchan' => $xchan_hash, + 'abook_feed' => intval(($is_http) ? 1 : 0), + 'abook_created' => datetime_convert(), + 'abook_updated' => datetime_convert(), + 'abook_instance' => (($singleton) ? z_root() : '') + ] ); } if(! $r) logger('mod_follow: abook creation failed'); - $all_perms = \Zotlabs\Access\Permissions::Perms(); - if($all_perms) { - foreach($all_perms as $k => $v) { - if(in_array($k,$my_perms)) - set_abconfig($uid,$xchan_hash,'my_perms',$k,1); - else - set_abconfig($uid,$xchan_hash,'my_perms',$k,0); + if($my_perms) { + foreach($my_perms as $k => $v) { + set_abconfig($uid,$xchan_hash,'my_perms',$k,$v); } } diff --git a/include/zot.php b/include/zot.php index 8bad4fde5..736712c81 100644 --- a/include/zot.php +++ b/include/zot.php @@ -417,28 +417,12 @@ function zot_refresh($them, $channel = null, $force = false) { } else { - // new connection - - $my_perms = null; - $automatic = false; + $p = \Zotlabs\Access\Permissions::connect_perms($channel['channel_id']); - $role = get_pconfig($channel['channel_id'],'system','permissions_role'); - if($role) { - $xx = \Zotlabs\Access\PermissionRoles::role_perms($role); - if($xx['perms_auto']) { - $automatic = true; - $default_perms = $xx['perms_connect']; - $my_perms = \Zotlabs\Access\Permissions::FilledPerms($default_perms); - } - } + $my_perms = $p['perms']; + $automatic = $p['automatic']; - if(! $my_perms) { - $m = \Zotlabs\Access\Permissions::FilledAutoperms($channel['channel_id']); - if($m) { - $automatic = true; - $my_perms = $m; - } - } + // new connection if($my_perms) { foreach($my_perms as $k => $v) { @@ -450,15 +434,17 @@ function zot_refresh($them, $channel = null, $force = false) { if($closeness === false) $closeness = 80; - $y = q("insert into abook ( abook_account, abook_channel, abook_closeness, abook_xchan, abook_created, abook_updated, abook_dob, abook_pending ) values ( %d, %d, %d, '%s', '%s', '%s', '%s', %d )", - intval($channel['channel_account_id']), - intval($channel['channel_id']), - intval($closeness), - dbesc($x['hash']), - dbesc(datetime_convert()), - dbesc(datetime_convert()), - dbesc($next_birthday), - intval(($automatic) ? 0 : 1) + $y = abook_store_lowlevel( + [ + 'abook_account' => intval($channel['channel_account_id']), + 'abook_channel' => intval($channel['channel_id']), + 'abook_closeness' => intval($closeness), + 'abook_xchan' => $x['hash'], + 'abook_created' => datetime_convert(), + 'abook_updated' => datetime_convert(), + 'abook_dob' => $next_birthday, + 'abook_pending' => intval(($automatic) ? 0 : 1) + ] ); if($y) { @@ -3323,10 +3309,12 @@ function process_channel_sync_delivery($sender, $arr, $deliveries) { logger('process_channel_sync_delivery: total_feeds service class limit exceeded'); continue; } - q("insert into abook ( abook_xchan, abook_account, abook_channel ) values ('%s', %d, %d ) ", - dbesc($clean['abook_xchan']), - intval($channel['channel_account_id']), - intval($channel['channel_id']) + abook_store_lowlevel( + [ + 'abook_xchan' => $clean['abook_xchan'], + 'abook_account' => $channel['channel_account_id'], + 'abook_channel' => $channel['channel_id'] + ] ); $total_friends ++; if(intval($clean['abook_feed'])) -- cgit v1.2.3 From 8ff9ad76365eced6dd466c491148381dae677a6c Mon Sep 17 00:00:00 2001 From: Andrew Manning Date: Sat, 11 Feb 2017 20:52:06 -0500 Subject: Webpage import tool works again after setting iconfig properly and following the Impel class function example. More testing is needed. --- include/import.php | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) (limited to 'include') diff --git a/include/import.php b/include/import.php index d48995a79..07215264e 100644 --- a/include/import.php +++ b/include/import.php @@ -1295,6 +1295,7 @@ function import_webpage_element($element, $channel, $type) { // LAYOUTS // case 'layout': + logger('Importing layout...', LOGGER_DEBUG); $arr['item_type'] = ITEM_TYPE_PDL; $namespace = 'PDL'; $name = $element['name']; @@ -1315,7 +1316,7 @@ function import_webpage_element($element, $channel, $type) { return null; // return null if invalid element type } - $arr['uid'] = $channel['channel_id']; + $arr['uid'] = local_channel(); $arr['aid'] = $channel['channel_account_id']; // Check if an item already exists based on the name @@ -1376,36 +1377,40 @@ function import_webpage_element($element, $channel, $type) { } } - $z = q("select * from iconfig where v = '%s' and k = '%s' and cat = 'system' limit 1", - dbesc($name), - dbesc($namespace) - ); +// $z = q("select * from iconfig where v = '%s' and k = '%s' and cat = 'system' limit 1", +// dbesc($name), +// dbesc($namespace) +// ); $i = q("select id, edited, item_deleted from item where mid = '%s' and uid = %d limit 1", dbesc($arr['mid']), intval(local_channel()) ); - $remote_id = 0; - if($z && $i) { - $remote_id = $z[0]['id']; + + \Zotlabs\Lib\IConfig::Set($arr,'system',$namespace,(($name) ? $name : substr($arr['mid'],0,16)),true); + + + if($i) { $arr['id'] = $i[0]['id']; // don't update if it has the same timestamp as the original if($arr['edited'] > $i[0]['edited']) - $x = item_store_update($arr, $execflag); + $x = item_store_update($arr,$execflag); } else { if(($i) && (intval($i[0]['item_deleted']))) { // was partially deleted already, finish it off - q("delete from item where mid = '%s' and uid = %d", - dbesc($arr['mid']), + q("delete from item where mid = '%s' and uid = %d", + dbesc($arr['mid']), intval(local_channel()) ); } - $x = item_store($arr, $execflag); + else + $x = item_store($arr,$execflag); } - if($x['success']) { + + if($x && $x['success']) { $item_id = $x['item_id']; - update_remote_id($channel, $item_id, $arr['item_type'], $name, $namespace, $remote_id, $arr['mid']); + //update_remote_id($channel, $item_id, $arr['item_type'], $name, $namespace, $remote_id, $arr['mid']); $element['import_success'] = 1; } else { -- cgit v1.2.3 From 0017de46e4e696aaa2180ca47aac9b4996493cc8 Mon Sep 17 00:00:00 2001 From: Andrew Manning Date: Sat, 11 Feb 2017 20:54:09 -0500 Subject: remove logger lines --- include/import.php | 1 - 1 file changed, 1 deletion(-) (limited to 'include') diff --git a/include/import.php b/include/import.php index 07215264e..5c73b7ca3 100644 --- a/include/import.php +++ b/include/import.php @@ -1295,7 +1295,6 @@ function import_webpage_element($element, $channel, $type) { // LAYOUTS // case 'layout': - logger('Importing layout...', LOGGER_DEBUG); $arr['item_type'] = ITEM_TYPE_PDL; $namespace = 'PDL'; $name = $element['name']; -- cgit v1.2.3 From ccdfbc721fa0cf6710cce262cbaa219e2803e8c2 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Sun, 12 Feb 2017 15:56:33 -0800 Subject: Create virtual privacy groups for private profile member lists --- include/attach.php | 58 ++++++++++++++++++++++---------------------- include/group.php | 68 +++++++++++++++++++++++++++++++++++++++++++--------- include/photos.php | 53 ++++++++++++++++++++++++++++++++++++++-- include/security.php | 16 ++++++++++++- 4 files changed, 153 insertions(+), 42 deletions(-) (limited to 'include') diff --git a/include/attach.php b/include/attach.php index dc5bfd308..937d33ea3 100644 --- a/include/attach.php +++ b/include/attach.php @@ -28,29 +28,31 @@ function z_mime_content_type($filename) { $mime_types = array( - 'txt' => 'text/plain', - 'htm' => 'text/html', + 'txt' => 'text/plain', + 'htm' => 'text/html', 'html' => 'text/html', - 'php' => 'text/html', - 'css' => 'text/css', - 'js' => 'application/javascript', + 'php' => 'text/html', + 'css' => 'text/css', + 'md' => 'text/markdown', + 'bb' => 'text/bbcode', + 'js' => 'application/javascript', 'json' => 'application/json', - 'xml' => 'application/xml', - 'swf' => 'application/x-shockwave-flash', - 'flv' => 'video/x-flv', + 'xml' => 'application/xml', + 'swf' => 'application/x-shockwave-flash', + 'flv' => 'video/x-flv', 'epub' => 'application/epub+zip', // images - 'png' => 'image/png', - 'jpe' => 'image/jpeg', + 'png' => 'image/png', + 'jpe' => 'image/jpeg', 'jpeg' => 'image/jpeg', - 'jpg' => 'image/jpeg', - 'gif' => 'image/gif', - 'bmp' => 'image/bmp', - 'ico' => 'image/vnd.microsoft.icon', + 'jpg' => 'image/jpeg', + 'gif' => 'image/gif', + 'bmp' => 'image/bmp', + 'ico' => 'image/vnd.microsoft.icon', 'tiff' => 'image/tiff', - 'tif' => 'image/tiff', - 'svg' => 'image/svg+xml', + 'tif' => 'image/tiff', + 'svg' => 'image/svg+xml', 'svgz' => 'image/svg+xml', // archives @@ -61,27 +63,27 @@ function z_mime_content_type($filename) { 'cab' => 'application/vnd.ms-cab-compressed', // audio/video - 'mp3' => 'audio/mpeg', - 'wav' => 'audio/wav', - 'qt' => 'video/quicktime', - 'mov' => 'video/quicktime', - 'ogg' => 'audio/ogg', - 'ogv' => 'video/ogg', - 'ogx' => 'application/ogg', + 'mp3' => 'audio/mpeg', + 'wav' => 'audio/wav', + 'qt' => 'video/quicktime', + 'mov' => 'video/quicktime', + 'ogg' => 'audio/ogg', + 'ogv' => 'video/ogg', + 'ogx' => 'application/ogg', 'flac' => 'audio/flac', 'opus' => 'audio/ogg', 'webm' => 'video/webm', // 'webm' => 'audio/webm', - 'mp4' => 'video/mp4', -// 'mp4' => 'audio/mp4', - 'mkv' => 'video/x-matroska', + 'mp4' => 'video/mp4', +// 'mp4' => 'audio/mp4', + 'mkv' => 'video/x-matroska', // adobe 'pdf' => 'application/pdf', 'psd' => 'image/vnd.adobe.photoshop', - 'ai' => 'application/postscript', + 'ai' => 'application/postscript', 'eps' => 'application/postscript', - 'ps' => 'application/postscript', + 'ps' => 'application/postscript', // ms office 'doc' => 'application/msword', diff --git a/include/group.php b/include/group.php index 38d9d190f..3b208ef95 100644 --- a/include/group.php +++ b/include/group.php @@ -227,6 +227,26 @@ function group_get_members_xchan($gid) { return $ret; } +function group_get_profile_members_xchan($uid,$gid) { + $ret = []; + + if(intval($gid)) { + $r = q("SELECT abook_xchan as xchan from abook left join profile on abook_profile = profile_guid where profile.id = %d and profile.uid = %d", + intval($gid), + intval($uid) + ); + if($r) { + foreach($r as $rr) { + $ret[] = $rr['xchan']; + } + } + } + return $ret; +} + + + + function mini_group_select($uid,$group = '') { $grps = array(); @@ -320,20 +340,46 @@ function group_side($every="connections",$each="group",$edit = false, $group_id return $o; } -function expand_groups($a) { - if(! (is_array($a) && count($a))) +function expand_groups($g) { + if(! (is_array($g) && count($g))) return array(); - $x = $a; - stringify_array_elms($x,true); - $groups = implode(',', $x); - if($groups) - $r = q("SELECT xchan FROM group_member WHERE gid IN ( select id from groups where hash in ( $groups ))"); - $ret = array(); + $ret = []; + $x = []; - if($r) - foreach($r as $rr) - $ret[] = $rr['xchan']; + // private profile linked virtual groups + + foreach($g as $gv) { + if(substr($gv,0,3) === 'vp.') { + $profile_hash = substr($gv,3); + if($profile_hash) { + $r = q("select abook_xchan from abook where abook_profile = '%s'", + dbesc($profile_hash) + ); + if($r) { + foreach($r as $rv) { + $ret[] = $rv['abook_xchan']; + } + } + } + } + else { + $x[] = $gv; + } + } + + if($x) { + stringify_array_elms($x,true); + $groups = implode(',', $x); + if($groups) { + $r = q("SELECT xchan FROM group_member WHERE gid IN ( select id from groups where hash in ( $groups ))"); + if($r) { + foreach($r as $rr) { + $ret[] = $rr['xchan']; + } + } + } + } return $ret; } diff --git a/include/photos.php b/include/photos.php index 55cc2d945..4cd5952f9 100644 --- a/include/photos.php +++ b/include/photos.php @@ -718,10 +718,59 @@ function gps2Num($coordPart) { return floatval($parts[0]) / floatval($parts[1]); } + +function photo_profile_setperms($channel_id,$resource_id,$profile_id) { + + if(! $profile_id) + return; + + $r = q("select profile_guid, is_default from profile where id = %d and uid = %d limit 1", + dbesc($profile_id), + intval($channel_id) + ); + + if(! $r) + return; + + $is_default = $r[0]['is_default']; + $profile_guid = $r[0]['profile_guid']; + + if($is_default) { + $r = q("update photo set allow_cid = '', allow_gid = '', deny_cid = '', deny_gid = '' + where resource_id = '%s' and uid = %d", + dbesc($resource_id), + intval($channel_id) + ); + $r = q("update attach set allow_cid = '', allow_gid = '', deny_cid = '', deny_gid = '' + where hash = '%s' and uid = %d", + dbesc($resource_id), + intval($channel_id) + ); + } + else { + $r = q("update photo set allow_cid = '', allow_gid = '%s', deny_cid = '', deny_gid = '' + where resource_id = '%s' and uid = %d", + dbesc('vp.' . $profile_guid), + dbesc($resource_id), + intval($channel_id) + ); + + $r = q("update attach set allow_cid = '', allow_gid = '%s', deny_cid = '', deny_gid = '' + where hash = '%s' and uid = %d", + dbesc('vp.' . $profile_guid), + dbesc($resource_id), + intval($channel_id) + ); + } +} + function profile_photo_set_profile_perms($uid, $profileid = 0) { - $allowcid = ''; - if($profileid) { + $allowcid = ''; + + + if($profileid) { + $r = q("SELECT photo, profile_guid, id, is_default, uid FROM profile WHERE uid = %d and ( profile.id = %d OR profile.profile_guid = '%s') LIMIT 1", intval($uid), diff --git a/include/security.php b/include/security.php index 57b33251f..b49ceec0d 100644 --- a/include/security.php +++ b/include/security.php @@ -553,7 +553,21 @@ function check_form_security_token_ForbiddenOnErr($typename = '', $formname = 'f // var $contact_id = xchan_hash of connection function init_groups_visitor($contact_id) { - $groups = array(); + $groups = []; + + // private profiles are treated as a virtual group + + $r = q("SELECT abook_profile from abook where abook_xchan = '%s' and abook_profile != '' ", + dbesc($contact_id) + ); + if($r) { + foreach($r as $rv) { + $groups[] = 'vp.' . $rv['abook_profile']; + } + } + + // physical groups this channel is a member of + $r = q("SELECT hash FROM groups left join group_member on groups.id = group_member.gid WHERE xchan = '%s' ", dbesc($contact_id) ); -- cgit v1.2.3 From 2a525922929d5d9d54fd898e6f1658f0b959e667 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Sun, 12 Feb 2017 17:40:18 -0800 Subject: testing and bug fixes virtual profile groups --- include/acl_selectors.php | 10 ++++++++++ include/photos.php | 4 ++-- 2 files changed, 12 insertions(+), 2 deletions(-) (limited to 'include') diff --git a/include/acl_selectors.php b/include/acl_selectors.php index dcf0fe9a2..09c24f82c 100644 --- a/include/acl_selectors.php +++ b/include/acl_selectors.php @@ -174,6 +174,16 @@ function populate_acl($defaults = null,$show_jotnets = true, $emptyACL_descripti $custom = false; } + $r = q("SELECT id, profile_guid, profile_name from profile where is_default = 0 and uid = %d order by profile_name", + intval(local_channel()) + ); + if($r) { + foreach($r as $rv) { + $selected = (($single_group && 'vp.' . $rr['hash'] === $allow_gid[0]) ? ' selected = "selected" ' : ''); + $groups .= '' . "\r\n"; + } + } + $r = q("SELECT id, hash, gname FROM groups WHERE deleted = 0 AND uid = %d ORDER BY gname ASC", intval(local_channel()) ); diff --git a/include/photos.php b/include/photos.php index 4cd5952f9..c0f7dc8c4 100644 --- a/include/photos.php +++ b/include/photos.php @@ -750,14 +750,14 @@ function photo_profile_setperms($channel_id,$resource_id,$profile_id) { else { $r = q("update photo set allow_cid = '', allow_gid = '%s', deny_cid = '', deny_gid = '' where resource_id = '%s' and uid = %d", - dbesc('vp.' . $profile_guid), + dbesc(''), dbesc($resource_id), intval($channel_id) ); $r = q("update attach set allow_cid = '', allow_gid = '%s', deny_cid = '', deny_gid = '' where hash = '%s' and uid = %d", - dbesc('vp.' . $profile_guid), + dbesc(''), dbesc($resource_id), intval($channel_id) ); -- cgit v1.2.3 From f63aaa54293acd2f524872f5d45da099082a48fa Mon Sep 17 00:00:00 2001 From: zotlabs Date: Sun, 12 Feb 2017 18:42:43 -0800 Subject: be consistent with the name --- include/widgets.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include') diff --git a/include/widgets.php b/include/widgets.php index 52f8fd655..cb8a6133e 100644 --- a/include/widgets.php +++ b/include/widgets.php @@ -663,7 +663,7 @@ function widget_settings_menu($arr) { if(feature_enabled(local_channel(),'permcats')) { $tabs[] = array( - 'label' => t('Permission Categories'), + 'label' => t('Permission Groups'), 'url' => z_root() . '/settings/permcats', 'selected' => ((argv(1) === 'permcats') ? 'active' : ''), ); -- cgit v1.2.3 From 07d92796d263d5add84793064e03108eec85db94 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Tue, 14 Feb 2017 20:57:14 -0800 Subject: provide HTTP header parser which honours continuation lines and despite the fact that continuation lines have been deprecated - as they still exist in the wild. --- include/text.php | 5 ----- 1 file changed, 5 deletions(-) (limited to 'include') diff --git a/include/text.php b/include/text.php index 8c01ed1d2..cfec1ddf6 100644 --- a/include/text.php +++ b/include/text.php @@ -1581,11 +1581,6 @@ function prepare_body(&$item,$attach = false) { $photo = $prep_arr['photo']; $event = $prep_arr['event']; -// q("update item set html = '%s' where id = %d", -// dbesc($s), -// intval($item['id']) -// ); - if(! $attach) { return $s; } -- cgit v1.2.3 From 5db3b71c6aad7b27e440dcf32978b9a5d39b97b3 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Wed, 15 Feb 2017 11:35:36 -0800 Subject: strip possible quotes from attribute_contains() haystacks --- include/text.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'include') diff --git a/include/text.php b/include/text.php index cfec1ddf6..eb8147f9a 100644 --- a/include/text.php +++ b/include/text.php @@ -586,8 +586,10 @@ function photo_new_resource() { * @return boolean true if found */ function attribute_contains($attr, $s) { + // remove quotes + $attr = str_replace([ '"',"'" ],['',''],$attr); $a = explode(' ', $attr); - if(count($a) && in_array($s, $a)) + if($a && in_array($s, $a)) return true; return false; -- cgit v1.2.3 From 16a8416495a12c2662d29352cbefb0e1c74dfb93 Mon Sep 17 00:00:00 2001 From: Mario Vavti Date: Fri, 17 Feb 2017 15:07:20 +0100 Subject: css fixes and rename link to full docs to help since its app is also called help --- include/nav.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include') diff --git a/include/nav.php b/include/nav.php index 43c7771ec..d31473cc0 100644 --- a/include/nav.php +++ b/include/nav.php @@ -285,7 +285,7 @@ EOT; App::$page['nav'] .= replace_macros($tpl, array( '$baseurl' => z_root(), - '$fulldocs' => t('Documentation'), + '$fulldocs' => t('Help'), '$sitelocation' => $sitelocation, '$nav' => $x['nav'], '$banner' => $banner, -- cgit v1.2.3 From 573846707ceade4d00a4dfe3184d9f8004a3112b Mon Sep 17 00:00:00 2001 From: zotlabs Date: Sun, 19 Feb 2017 16:50:41 -0800 Subject: fix several places where head_add_(css|js) functions have been used incorrectly. It appears that mistakes were made going back a long time and propagated. Here's the way it should work: - if there is no preceding / character, we look for the file within all the appropriate theme directories. - otherwise the file should have a preceding /, which means use this path relative to the hubzilla basedir - files beginning with // are considered to be schemeless URLs. Therefore 'foo.css' means find the best theme-able representation of foo.css. '/library/foo.css' means only use the version of foo.css that is in /library. --- include/plugin.php | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) (limited to 'include') diff --git a/include/plugin.php b/include/plugin.php index 3a64f67cc..068e482d6 100755 --- a/include/plugin.php +++ b/include/plugin.php @@ -598,16 +598,23 @@ function head_get_links() { function format_css_if_exists($source) { - $path_prefix = script_path() . '/'; - if (strpos($source[0], '/') !== false) { - // The source is a URL - $path = $source[0]; + // script_path() returns https://yoursite.tld + + $path_prefix = script_path(); + + $script = $source[0]; + + if(strpos($script, '/') !== false) { + // The script is a path relative to the server root + $path = $script; // If the url starts with // then it's an absolute URL - if($source[0][0] === '/' && $source[0][1] === '/') $path_prefix = ''; + if(substr($script,0,2) === '//') { + $path_prefix = ''; + } } else { // It's a file from the theme - $path = theme_include($source[0]); + $path = '/' . theme_include($script); } if($path) { @@ -697,16 +704,19 @@ function head_get_main_js() { } function format_js_if_exists($source) { - $path_prefix = script_path() . '/'; + $path_prefix = script_path(); if(strpos($source,'/') !== false) { - // The source is a URL + // The source is a known path on the system $path = $source; // If the url starts with // then it's an absolute URL - if($source[0] === '/' && $source[1] === '/') $path_prefix = ''; - } else { + if(substr($source,0,2) === '//') { + $path_prefix = ''; + } + } + else { // It's a file from the theme - $path = theme_include($source); + $path = '/' . theme_include($source); } if($path) { $qstring = ((parse_url($path, PHP_URL_QUERY)) ? '&' : '?') . 'v=' . STD_VERSION; -- cgit v1.2.3 From 6f811fd7f9032efdbe473afd422bb24a691c4e79 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Sun, 19 Feb 2017 17:04:37 -0800 Subject: bug in adding main.js as a js source --- include/plugin.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include') diff --git a/include/plugin.php b/include/plugin.php index 068e482d6..045efb805 100755 --- a/include/plugin.php +++ b/include/plugin.php @@ -684,7 +684,7 @@ function head_get_js() { foreach(App::$js_sources as $sources) { if(count($sources)) { foreach($sources as $source) { - if($src === 'main.js') + if($source === 'main.js') continue; $str .= format_js_if_exists($source); } -- cgit v1.2.3 From bc1812840a443407db38a86831bb48dde5523e47 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Mon, 20 Feb 2017 15:06:17 -0800 Subject: don't search on empty filename - we shouldn't find it. The reason why this change is being made is because we actually did find it due to a development glitch --- include/attach.php | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'include') diff --git a/include/attach.php b/include/attach.php index 937d33ea3..5f0fa4ff8 100644 --- a/include/attach.php +++ b/include/attach.php @@ -1479,10 +1479,12 @@ function find_folder_hash_by_path($channel_id, $path) { $filename = end(explode('/', $path)); - $r = q("SELECT hash FROM attach WHERE uid = %d AND filename = '%s' LIMIT 1", - intval($channel_id), - dbesc($filename) - ); + if($filename) { + $r = q("SELECT hash FROM attach WHERE uid = %d AND filename = '%s' LIMIT 1", + intval($channel_id), + dbesc($filename) + ); + } $hash = ''; if($r && $r[0]['hash']) { -- cgit v1.2.3 From 1c1d1f11851722db3c8c7e6bb1d814b42399f67e Mon Sep 17 00:00:00 2001 From: zotlabs Date: Mon, 20 Feb 2017 18:46:51 -0800 Subject: update fr translation --- 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 139c637e5..e667c0348 100755 --- a/include/items.php +++ b/include/items.php @@ -361,8 +361,8 @@ function post_activity_item($arr,$allow_code = false,$deliver = true) { $arr['allow_cid'] = ((x($arr,'allow_cid')) ? $arr['allow_cid'] : $channel['channel_allow_cid']); $arr['allow_gid'] = ((x($arr,'allow_gid')) ? $arr['allow_gid'] : $channel['channel_allow_gid']); - $arr['deny_cid'] = ((x($arr,'deny_cid')) ? $arr['deny_cid'] : $channel['channel_deny_cid']); - $arr['deny_gid'] = ((x($arr,'deny_gid')) ? $arr['deny_gid'] : $channel['channel_deny_gid']); + $arr['deny_cid'] = ((x($arr,'deny_cid')) ? $arr['deny_cid'] : $channel['channel_deny_cid']); + $arr['deny_gid'] = ((x($arr,'deny_gid')) ? $arr['deny_gid'] : $channel['channel_deny_gid']); $arr['comment_policy'] = map_scope(\Zotlabs\Access\PermissionLimits::Get($channel['channel_id'],'post_comments')); @@ -424,7 +424,7 @@ function validate_item_elements($message,$arr) { /** - * @brief Limit lenght on imported system messages. + * @brief Limit length on imported system messages. * * The purpose of this function is to apply system message length limits to * imported messages without including any embedded photos in the length. -- cgit v1.2.3 From e54ba7ecbc7391069b38d9f911bf77623d0ee582 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Mon, 20 Feb 2017 23:03:48 -0800 Subject: fix find_folder_hash_by_path() which was not safe against multiple attach structures with the same filename but in different directories --- include/attach.php | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) (limited to 'include') diff --git a/include/attach.php b/include/attach.php index 5f0fa4ff8..79313ab1a 100644 --- a/include/attach.php +++ b/include/attach.php @@ -1477,20 +1477,34 @@ function find_folder_hash_by_attach_hash($channel_id, $attachHash, $recurse = fa function find_folder_hash_by_path($channel_id, $path) { - $filename = end(explode('/', $path)); + if(! $path) + return ''; - if($filename) { - $r = q("SELECT hash FROM attach WHERE uid = %d AND filename = '%s' LIMIT 1", + $comps = explode('/',$path); + $errors = false; + $parent_hash = ''; + + for($x = 0; $x < count($comps); $x ++) { + $element = $comps[$x]; + $r = q("SELECT hash FROM attach WHERE uid = %d AND filename = '%s' AND folder = '%s' LIMIT 1", intval($channel_id), - dbesc($filename) + dbesc($element), + dbesc($parent_hash) ); + if($r) { + $parent_hash = $r[0]['hash']; + } + else { + $errors ++; + break; + } } - $hash = ''; - if($r && $r[0]['hash']) { - $hash = $r[0]['hash']; - } - return $hash; + if($errors) + return ''; + + return $parent_hash; + } /** -- cgit v1.2.3 From 5ad5a0fa07e018b2216b38f0a3e31df763491982 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Mon, 20 Feb 2017 23:13:27 -0800 Subject: detect no acl --- include/items.php | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'include') diff --git a/include/items.php b/include/items.php index e667c0348..6d21953a9 100755 --- a/include/items.php +++ b/include/items.php @@ -359,10 +359,12 @@ 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; - $arr['allow_cid'] = ((x($arr,'allow_cid')) ? $arr['allow_cid'] : $channel['channel_allow_cid']); - $arr['allow_gid'] = ((x($arr,'allow_gid')) ? $arr['allow_gid'] : $channel['channel_allow_gid']); - $arr['deny_cid'] = ((x($arr,'deny_cid')) ? $arr['deny_cid'] : $channel['channel_deny_cid']); - $arr['deny_gid'] = ((x($arr,'deny_gid')) ? $arr['deny_gid'] : $channel['channel_deny_gid']); + if(! ($arr['allow_cid'] || $arr['allow_gid'] || $arr['deny_cid'] || $arr['deny_gid'])) { + $arr['allow_cid'] = $channel['channel_allow_cid']; + $arr['allow_gid'] = $channel['channel_allow_gid']; + $arr['deny_cid'] = $channel['channel_deny_cid']; + $arr['deny_gid'] = $channel['channel_deny_gid']; + } $arr['comment_policy'] = map_scope(\Zotlabs\Access\PermissionLimits::Get($channel['channel_id'],'post_comments')); -- cgit v1.2.3 From 81d556d32e2a36c62078184848391b0f9b85c3e1 Mon Sep 17 00:00:00 2001 From: Mario Vavti Date: Tue, 21 Feb 2017 10:34:40 +0100 Subject: wrong permission --- include/widgets.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include') diff --git a/include/widgets.php b/include/widgets.php index cb8a6133e..bff2f0ab8 100644 --- a/include/widgets.php +++ b/include/widgets.php @@ -959,7 +959,7 @@ function widget_wiki_pages($arr) { } } } - $can_create = perm_is_allowed(\App::$profile['uid'],get_observer_hash(),'write_pages'); + $can_create = perm_is_allowed(\App::$profile['uid'],get_observer_hash(),'write_wiki'); $can_delete = ((local_channel() && (local_channel() == \App::$profile['uid'])) ? true : false); -- cgit v1.2.3 From 3e144baacde6b3b313942d5b318354e2668223e8 Mon Sep 17 00:00:00 2001 From: Andrew Manning Date: Tue, 21 Feb 2017 20:32:13 -0500 Subject: Change Add Apps to Manage Apps and support translation. --- include/nav.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'include') diff --git a/include/nav.php b/include/nav.php index d31473cc0..808549444 100644 --- a/include/nav.php +++ b/include/nav.php @@ -296,7 +296,8 @@ EOT; '$powered_by' => $powered_by, '$help' => t('@name, #tag, ?doc, content'), '$pleasewait' => t('Please wait...'), - '$navapps' => $navapps + '$navapps' => $navapps, + '$editapps' => t('Manage Apps') )); if(x($_SESSION, 'reload_avatar') && $observer) { -- cgit v1.2.3 From 6644dc4861272273acf683dd6e06ceb586f2e4db Mon Sep 17 00:00:00 2001 From: zotlabs Date: Tue, 21 Feb 2017 18:58:51 -0800 Subject: use head_add_link() for feed discovery --- include/channel.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'include') diff --git a/include/channel.php b/include/channel.php index 856fb6303..71ba2476f 100644 --- a/include/channel.php +++ b/include/channel.php @@ -1976,9 +1976,7 @@ function channel_manual_conv_update($channel_id) { $x = get_pconfig($channel_id, 'system','manual_conversation_update'); if($x === false) - $x = get_config('system','manual_conversation_update'); - if($x === false) - $x = 1; + $x = get_config('system','manual_conversation_update', 1); return intval($x); -- cgit v1.2.3 From 956f0043fc73c290d9154ab06337b995ddfd1a1c Mon Sep 17 00:00:00 2001 From: zotlabs Date: Tue, 21 Feb 2017 23:16:05 -0800 Subject: change text back to 'add apps' --- include/nav.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include') diff --git a/include/nav.php b/include/nav.php index 808549444..144509cd0 100644 --- a/include/nav.php +++ b/include/nav.php @@ -297,7 +297,7 @@ EOT; '$help' => t('@name, #tag, ?doc, content'), '$pleasewait' => t('Please wait...'), '$navapps' => $navapps, - '$editapps' => t('Manage Apps') + '$addapps' => t('Add Apps') )); if(x($_SESSION, 'reload_avatar') && $observer) { -- cgit v1.2.3 From 55924f5c5b147412fda350a3b7c2ecfaef523e19 Mon Sep 17 00:00:00 2001 From: Mario Vavti Date: Wed, 22 Feb 2017 11:22:43 +0100 Subject: apps improvements --- include/widgets.php | 14 -------------- 1 file changed, 14 deletions(-) (limited to 'include') diff --git a/include/widgets.php b/include/widgets.php index bff2f0ab8..04cf0d30b 100644 --- a/include/widgets.php +++ b/include/widgets.php @@ -96,20 +96,6 @@ function widget_collections($args) { return group_side($every, $each, $edit, $current, $abook_id, $wmode); } - -function widget_appselect($arr) { - return replace_macros(get_markup_template('app_select.tpl'),array( - '$title' => t('Apps'), - '$system' => t('System'), - '$authed' => ((local_channel()) ? true : false), - '$personal' => t('Personal'), - '$new' => t('New App'), - '$edit' => t('Edit Apps'), - '$cat' => ((array_key_exists('cat',$_REQUEST)) ? $_REQUEST['cat'] : '') - )); -} - - function widget_suggestions($arr) { if((! local_channel()) || (! feature_enabled(local_channel(),'suggest'))) -- cgit v1.2.3 From 3d0c6700db4ed28600ba2182eae4cdfd8e1a9a20 Mon Sep 17 00:00:00 2001 From: Mario Vavti Date: Thu, 23 Feb 2017 12:24:42 +0100 Subject: yet one more place to use chanlink_hash() instead of chanlink_url() --- include/conversation.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'include') diff --git a/include/conversation.php b/include/conversation.php index 285ee752f..a1acc456a 100644 --- a/include/conversation.php +++ b/include/conversation.php @@ -1175,8 +1175,8 @@ function builtin_activity_puller($item, &$conv_responses) { if((activity_match($item['verb'], $verb)) && ($item['id'] != $item['parent'])) { $name = (($item['author']['xchan_name']) ? $item['author']['xchan_name'] : t('Unknown')); - $url = (($item['author']['xchan_url'] && $item['author']['xchan_photo_s']) - ? '' . '' . urlencode($name) . '' . $name . '' + $url = (($item['author_xchan'] && $item['author']['xchan_photo_s']) + ? '' . '' . urlencode($name) . '' . $name . '' : '' . $name . '' ); -- cgit v1.2.3 From 8e3e90ddd243011828b9dbb44e7c4abc00655b28 Mon Sep 17 00:00:00 2001 From: Mario Vavti Date: Mon, 27 Feb 2017 10:13:08 +0100 Subject: set minversion and maxversion for themes in view/theme/themename/php/theme.php instead of separate file. --- include/plugin.php | 2 ++ 1 file changed, 2 insertions(+) (limited to 'include') diff --git a/include/plugin.php b/include/plugin.php index 045efb805..29474735e 100755 --- a/include/plugin.php +++ b/include/plugin.php @@ -471,6 +471,8 @@ function get_theme_info($theme){ 'description' => '', 'author' => array(), 'version' => '', + 'minversion' => '', + 'maxversion' => '', 'compat' => '', 'credits' => '', 'maintainer' => array(), -- cgit v1.2.3 From 751c4c3169df6238aad561d00b8c8b92bb9b676e Mon Sep 17 00:00:00 2001 From: zotlabs Date: Mon, 6 Mar 2017 15:33:10 -0800 Subject: correct fix for wiki anonymous read issue (items_permissions_sql checks item.public_policy which was set for posts, not wikis) --- include/items.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'include') diff --git a/include/items.php b/include/items.php index 6d21953a9..a297a1090 100755 --- a/include/items.php +++ b/include/items.php @@ -328,7 +328,8 @@ function post_activity_item($arr,$allow_code = false,$deliver = true) { return $ret; } - $arr['public_policy'] = ((x($_REQUEST,'public_policy')) ? escape_tags($_REQUEST['public_policy']) : map_scope(\Zotlabs\Access\PermissionLimits::Get($channel['channel_id'],'view_stream'),true)); + $arr['public_policy'] = ((array_key_exists('public_policy',$arr)) ? escape_tags($arr['public_policy']) : map_scope(\Zotlabs\Access\PermissionLimits::Get($channel['channel_id'],'view_stream'),true)); + if($arr['public_policy']) $arr['item_private'] = 1; -- cgit v1.2.3 From 92996e550c5e96495f2caa109b051ed9e04bc93e Mon Sep 17 00:00:00 2001 From: zotlabs Date: Mon, 6 Mar 2017 21:01:17 -0800 Subject: allow post_activity_item to be passed an empty ACL without resetting to channel default --- include/items.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'include') diff --git a/include/items.php b/include/items.php index a297a1090..36445a46b 100755 --- a/include/items.php +++ b/include/items.php @@ -360,7 +360,8 @@ 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(! ($arr['allow_cid'] || $arr['allow_gid'] || $arr['deny_cid'] || $arr['deny_gid'])) { + 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']; $arr['deny_cid'] = $channel['channel_deny_cid']; -- cgit v1.2.3