GNU/Weeb Mailing List <[email protected]>
 help / color / mirror / Atom feed
From: Ammar Faizi <[email protected]>
To: Ammar Faizi <[email protected]>
Cc: Michael William Jonathan <[email protected]>,
	GNU/Weeb FB Team <[email protected]>,
	GNU/Weeb Mailing List <[email protected]>
Subject: [PATCH fb v1 2/3] fb: helper: Introduce `build_url()` function
Date: Sat, 13 May 2023 01:44:10 +0700	[thread overview]
Message-ID: <[email protected]> (raw)
In-Reply-To: <[email protected]>

Introduce build_url() function to construct a URL based on the return
value of parse_url(). Currently, the only purpose of this function is to
easily change the hostname without inventing our own URL parser.

This function is taken from an answer on the stackoverflow site.

Link: https://stackoverflow.com/a/35207936/7275114
Signed-off-by: Ammar Faizi <[email protected]>
---
 src/Facebook/helpers.php | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/src/Facebook/helpers.php b/src/Facebook/helpers.php
index 224ec45d70755407..ae50775908ceb71f 100644
--- a/src/Facebook/helpers.php
+++ b/src/Facebook/helpers.php
@@ -66,3 +66,21 @@ function full_html_clean(string $m): string
 
 	return trim(implode("\n", $m));
 }
+
+/**
+ * @param array $parts
+ * @return string
+ */
+function build_url(array $parts): string
+{
+	return (isset($parts['scheme']) ? "{$parts['scheme']}:" : '') .
+		((isset($parts['user']) || isset($parts['host'])) ? '//' : '') .
+		(isset($parts['user']) ? "{$parts['user']}" : '') .
+		(isset($parts['pass']) ? ":{$parts['pass']}" : '') .
+		(isset($parts['user']) ? '@' : '') .
+		(isset($parts['host']) ? "{$parts['host']}" : '') .
+		(isset($parts['port']) ? ":{$parts['port']}" : '') . 
+		(isset($parts['path']) ? "{$parts['path']}" : '') .
+		(isset($parts['query']) ? "?{$parts['query']}" : '') .
+		(isset($parts['fragment']) ? "#{$parts['fragment']}" : '');
+}
-- 
Ammar Faizi


  parent reply	other threads:[~2023-05-12 18:44 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-12 18:44 [PATCH fb v1 0/3] Facebook Onion assets optimization Ammar Faizi
2023-05-12 18:44 ` [PATCH fb v1 1/3] fb: web: Don't use proxy if the host isn't an onion domain Ammar Faizi
2023-05-12 18:44 ` Ammar Faizi [this message]
2023-05-12 18:44 ` [PATCH fb v1 3/3] fb: web: Replace Facebook onion asset endpoint with non-onion Ammar Faizi
2023-05-12 19:10 ` [PATCH fb v1 0/3] Facebook Onion assets optimization GNU/Weeb Facebook Team

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    [email protected] \
    [email protected] \
    [email protected] \
    [email protected] \
    [email protected] \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox