From fe5f1e4d67d999ed3c6ef78dc4d49f5dd1a93056 Mon Sep 17 00:00:00 2001 From: Klaus Weidenbach Date: Tue, 24 Oct 2017 16:33:58 +0200 Subject: :white_check_mark: Some unit test for include/language.php Unfortunately not so much unit testable, but added in preparation to update LanguageDetect and Intl library. --- include/language.php | 2 ++ 1 file changed, 2 insertions(+) (limited to 'include') diff --git a/include/language.php b/include/language.php index efe9397fb..a59823757 100644 --- a/include/language.php +++ b/include/language.php @@ -322,6 +322,8 @@ function get_language_name($s, $l = null) { $language = $languageRepository->get($s, $l); } catch (CommerceGuys\Intl\Exception\UnknownLanguageException $e) { return $s; // Give up + } catch (CommerceGuys\Intl\Exception\UnknownLocaleException $e) { + return $s; // Give up } } -- cgit v1.2.3 From 8e4c5db766ce23d05b8507991b04fece743147de Mon Sep 17 00:00:00 2001 From: Klaus Weidenbach Date: Wed, 25 Oct 2017 01:57:18 +0200 Subject: :arrow_up: Update Text_LanguageDetect. Update from v0.3.0 (2012) to v1.0.0 (2017) which should remove some warnings and improve PHP7 support. Using composer to handle this PEAR library now. Fix a problem in FeedutilsTest. --- include/help.php | 28 +++++++++++++++++----------- include/language.php | 16 +++++++--------- 2 files changed, 24 insertions(+), 20 deletions(-) (limited to 'include') diff --git a/include/help.php b/include/help.php index 02c3cb8e4..0dc37e517 100644 --- a/include/help.php +++ b/include/help.php @@ -28,7 +28,7 @@ function get_help_content($tocpath = false) { } if($path) { - + $title = basename($path); if(! $tocpath) \App::$page['title'] = t('Help:') . ' ' . ucwords(str_replace('-',' ',notags($title))); @@ -38,10 +38,10 @@ function get_help_content($tocpath = false) { // available and so default back to the English TOC at /doc/toc.{html,bb,md} // TODO: This is incompatible with the hierarchical TOC construction // defined in /Zotlabs/Widget/Helpindex.php. - if($tocpath !== false && - load_doc_file('doc/' . $path . '.md') === '' && - load_doc_file('doc/' . $path . '.bb') === '' && - load_doc_file('doc/' . $path . '.html') === '' + if($tocpath !== false && + load_doc_file('doc/' . $path . '.md') === '' && + load_doc_file('doc/' . $path . '.bb') === '' && + load_doc_file('doc/' . $path . '.html') === '' ) { $path = $title; } @@ -120,22 +120,28 @@ function preg_callback_help_include($matches) { } +/** + * @brief + * + * @return boolean|array + */ function determine_help_language() { - require_once('Text/LanguageDetect.php'); $lang_detect = new Text_LanguageDetect(); // Set this mode to recognize language by the short code like "en", "ru", etc. $lang_detect->setNameMode(2); - // If the language was specified in the URL, override the language preference + // If the language was specified in the URL, override the language preference // of the browser. Default to English if both of these are absent. if($lang_detect->languageExists(argv(1))) { $lang = argv(1); $from_url = true; } else { $lang = \App::$language; - if(! isset($lang)) + if(! isset($lang)) $lang = 'en'; + $from_url = false; } + return array('language' => $lang, 'from_url' => $from_url); } @@ -145,14 +151,14 @@ function load_doc_file($s) { $x = determine_help_language(); $lang = $x['language']; $url_idx = ($x['from_url'] ? 1 : 0); - // The English translation is at the root of /doc/. Other languages are in + // The English translation is at the root of /doc/. Other languages are in // subfolders named by the language code such as "de", "es", etc. if($lang !== 'en') { - $path .= '/' . $lang; + $path .= '/' . $lang; } $b = basename($s); - + for($i=1+$url_idx; $i t('Select an alternate language'), '$langs' => array($lang_options, $selected), - + )); return $o; -- cgit v1.2.3 From 66832c41e9fff481c20ca219b3cc0a4e53b8b551 Mon Sep 17 00:00:00 2001 From: Klaus Weidenbach Date: Wed, 25 Oct 2017 23:21:07 +0200 Subject: :arrow_up: Update intl library. Update intl library from v0.4? (2014) to v0.7.4 (2016). Use global composer autoloader now. --- include/language.php | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'include') diff --git a/include/language.php b/include/language.php index eb286231a..f6f266685 100644 --- a/include/language.php +++ b/include/language.php @@ -8,6 +8,7 @@ * language related tasks. */ +use CommerceGuys\Intl\Language\LanguageRepository; /** * @brief Get the browser's submitted preferred languages. @@ -298,11 +299,7 @@ function detect_language($s) { * @param string $s Language code to look up * @param string $l (optional) In which language to return the name * @return string with the language name, or $s if unrecognized - * - * @todo include CommerceGuys\Intl through composer like SabreDAV. */ -require_once(__DIR__ . '/../library/intl/vendor/autoload.php'); -use CommerceGuys\Intl\Language\LanguageRepository; function get_language_name($s, $l = null) { // get() expects the second part to be in upper case if (strpos($s, '-') !== false) $s = substr($s, 0, 2) . strtoupper(substr($s, 2)); -- cgit v1.2.3 From 1be98d7b7fea30a929d27e7aa0b1412da3276b2c Mon Sep 17 00:00:00 2001 From: Klaus Weidenbach Date: Sat, 28 Oct 2017 01:22:59 +0200 Subject: :white_check_mark: Some more work on unit tests. Some small improvements for coverage report. Add more functions from include/text.php Update composer dev libraries for phpunit. --- include/feedutils.php | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) (limited to 'include') diff --git a/include/feedutils.php b/include/feedutils.php index 217da8188..62fa4849a 100644 --- a/include/feedutils.php +++ b/include/feedutils.php @@ -1662,8 +1662,6 @@ function handle_feed($uid, $abook_id, $url) { /** * @brief Return a XML tag with author information. * - * @hooks \b atom_author Possibility to add further tags to returned XML string - * * \e string The created XML tag as a string without closing tag * @param string $tag The XML tag to create * @param string $nick preferred username * @param string $name displayed name of the author @@ -1672,7 +1670,7 @@ function handle_feed($uid, $abook_id, $url) { * @param int $w image width * @param string $type profile photo mime type * @param string $photo Fully qualified URL to a profile/avator photo - * @return string + * @return string XML tag */ function atom_author($tag, $nick, $name, $uri, $h, $w, $type, $photo) { $o = ''; @@ -1695,6 +1693,11 @@ function atom_author($tag, $nick, $name, $uri, $h, $w, $type, $photo) { $o .= ' ' . $nick . '' . "\r\n"; $o .= ' ' . $name . '' . "\r\n"; + /** + * @hooks atom_author + * Possibility to add further tags to returned XML string. + * * \e string The created XML tag as a string without closing tag + */ call_hooks('atom_author', $o); $o .= "\r\n"; @@ -1703,17 +1706,23 @@ function atom_author($tag, $nick, $name, $uri, $h, $w, $type, $photo) { } -function atom_render_author($tag,$xchan) { +/** + * @brief Return an atom tag with author information from an xchan. + * + * @param string $tag + * @param array $xchan + * @return string + */ +function atom_render_author($tag, $xchan) { - - $nick = xmlify(substr($xchan['xchan_addr'],0,strpos($xchan['xchan_addr'],'@'))); + $nick = xmlify(substr($xchan['xchan_addr'], 0, strpos($xchan['xchan_addr'], '@'))); $id = xmlify($xchan['xchan_url']); $name = xmlify($xchan['xchan_name']); $photo = xmlify($xchan['xchan_photo_l']); $type = xmlify($xchan['xchan_photo_mimetype']); $w = $h = 300; - $o .= "<$tag>\r\n"; + $o = "<$tag>\r\n"; $o .= " http://activitystrea.ms/schema/1.0/person\r\n"; $o .= " $id\r\n"; $o .= " $nick\r\n"; @@ -1724,13 +1733,16 @@ function atom_render_author($tag,$xchan) { $o .= ' ' . $nick . '' . "\r\n"; $o .= ' ' . $name . '' . "\r\n"; + /** + * @hooks atom_render_author + * Possibility to add further tags to returned XML string. + * * \e string The created XML tag as a string without closing tag + */ call_hooks('atom_render_author', $o); $o .= "\r\n"; return $o; - - } function compat_photos_list($s) { -- cgit v1.2.3 From 1159dd59edc40b753b9f4fe55165b4ee3c22285d Mon Sep 17 00:00:00 2001 From: zotlabs Date: Fri, 3 Nov 2017 14:07:00 -0700 Subject: fix cloud redirects with owt tokens --- include/zid.php | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'include') diff --git a/include/zid.php b/include/zid.php index ce9f70385..5ade6b0f8 100644 --- a/include/zid.php +++ b/include/zid.php @@ -89,10 +89,35 @@ function strip_zids($s) { return preg_replace('/[\?&]zid=(.*?)(&|$)/ism','$2',$s); } +function strip_owt($s) { + return preg_replace('/[\?&]owt=(.*?)(&|$)/ism','$2',$s); +} + function strip_zats($s) { return preg_replace('/[\?&]zat=(.*?)(&|$)/ism','$2',$s); } +function strip_auth_query_params() { + + $_SERVER['QUERY_STRING'] = str_replace(array('?f=', '&f='), array('', ''), $_SERVER['QUERY_STRING']); + $_SERVER['QUERY_STRING'] = strip_zids($_SERVER['QUERY_STRING']); + $_SERVER['QUERY_STRING'] = strip_owt($_SERVER['QUERY_STRING']); + + $_SERVER['REQUEST_URI'] = str_replace(array('?f=', '&f='), array('', ''), $_SERVER['REQUEST_URI']); + $_SERVER['REQUEST_URI'] = strip_zids($_SERVER['REQUEST_URI']); + $_SERVER['REQUEST_URI'] = strip_owt($_SERVER['REQUEST_URI']); + + + $_ENV['QUERY_STRING'] = str_replace(array('?f=', '&f='), array('', ''), $_ENV['QUERY_STRING']); + $_ENV['QUERY_STRING'] = strip_zids($_ENV['QUERY_STRING']); + $_ENV['QUERY_STRING'] = strip_owt($_ENV['QUERY_STRING']); + + $_ENV['REQUEST_URI'] = str_replace(array('?f=', '&f='), array('', ''), $_ENV['REQUEST_URI']); + $_ENV['REQUEST_URI'] = strip_zids($_ENV['REQUEST_URI']); + $_ENV['REQUEST_URI'] = strip_owt($_ENV['REQUEST_URI']); + +} + /** * zidify_callback() and zidify_links() work together to turn any HTML a tags with class="zrl" into zid links -- cgit v1.2.3 From fae9c236371ba70b2ac7624d6020c76a77c1944d Mon Sep 17 00:00:00 2001 From: zotlabs Date: Fri, 3 Nov 2017 14:20:49 -0700 Subject: imagedata not set correctly if large photo AND imagick is not installed --- include/photos.php | 3 +++ 1 file changed, 3 insertions(+) (limited to 'include') diff --git a/include/photos.php b/include/photos.php index 5de68f162..503a725cd 100644 --- a/include/photos.php +++ b/include/photos.php @@ -75,6 +75,9 @@ function photo_upload($channel, $observer, $args) { $imagedata = @file_get_contents($tmp_name); @unlink($tmp_name); } + else { + $imagedata = @file_get_contents($args['os_syspath']); + } } else { $imagedata = @file_get_contents($args['os_syspath']); -- cgit v1.2.3 From 9abb061e7185a29cb85ebbad04deba715e1a6a06 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Fri, 3 Nov 2017 16:47:05 -0700 Subject: provide short localised summary for likes that will end up in displayed notifications --- include/conversation.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'include') diff --git a/include/conversation.php b/include/conversation.php index f395b2cbe..5ff8b3864 100644 --- a/include/conversation.php +++ b/include/conversation.php @@ -162,6 +162,18 @@ function localize_item(&$item){ elseif(activity_match($item['verb'],ACTIVITY_DISLIKE)) { $bodyverb = t('%1$s doesn\'t like %2$s\'s %3$s'); } + + // short version, in notification strings the author will be displayed separately + + if(activity_match($item['verb'],ACTIVITY_LIKE)) { + $shortbodyverb = t('likes %1$s\'s %2$s'); + } + elseif(activity_match($item['verb'],ACTIVITY_DISLIKE)) { + $shortbodyverb = t('doesn\'t like %1$s\'s %2$s'); + } + + $item['shortlocalize'] = sprintf($bodyverb, $objauthor, $plink); + $item['body'] = $item['localize'] = sprintf($bodyverb, $author, $objauthor, $plink); if($Bphoto != "") $item['body'] .= "\n\n\n" . '[zrl=' . chanlink_url($author_link) . '][zmg=80x80]' . $Bphoto . '[/zmg][/zrl]'; -- cgit v1.2.3