aboutsummaryrefslogtreecommitdiffstats
path: root/include/network.php
diff options
context:
space:
mode:
Diffstat (limited to 'include/network.php')
-rw-r--r--include/network.php228
1 files changed, 113 insertions, 115 deletions
diff --git a/include/network.php b/include/network.php
index a5c14f9d1..55eecac84 100644
--- a/include/network.php
+++ b/include/network.php
@@ -1,6 +1,8 @@
<?php
use Zotlabs\Lib\Activity;
+use Zotlabs\Lib\Config;
+use Zotlabs\Lib\Mailer;
use Zotlabs\Lib\Zotfinger;
use Zotlabs\Lib\Libzot;
use Zotlabs\Lib\Queue;
@@ -67,7 +69,7 @@ function z_fetch_url($url, $binary = false, $redirects = 0, $opts = array()) {
@curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (compatible; zot)');
@curl_setopt($ch, CURLOPT_ENCODING, '');
- $ciphers = @get_config('system','curl_ssl_ciphers');
+ $ciphers = @Config::Get('system','curl_ssl_ciphers');
if($ciphers)
@curl_setopt($ch, CURLOPT_SSL_CIPHER_LIST, $ciphers);
@@ -114,16 +116,16 @@ function z_fetch_url($url, $binary = false, $redirects = 0, $opts = array()) {
@curl_setopt($ch, CURLOPT_TIMEOUT, intval($opts['timeout']));
}
else {
- $curl_time = intval(@get_config('system','curl_timeout'));
- @curl_setopt($ch, CURLOPT_TIMEOUT, (($curl_time !== false) ? $curl_time : 60));
+ $curl_time = intval(@Config::Get('system','curl_timeout'));
+ @curl_setopt($ch, CURLOPT_TIMEOUT, (($curl_time !== 0) ? $curl_time : 60));
}
if(x($opts,'connecttimeout') && intval($opts['connecttimeout'])) {
@curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, intval($opts['connecttimeout']));
}
else {
- $curl_contime = intval(@get_config('system','curl_connecttimeout'));
- @curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, (($curl_contime !== false) ? $curl_contime : 30));
+ $curl_contime = intval(@Config::Get('system','curl_connecttimeout'));
+ @curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, (($curl_contime !== 0) ? $curl_contime : 30));
}
if(x($opts,'http_auth')) {
@@ -145,11 +147,11 @@ 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 = @Config::Get('system','proxy');
if(strlen($prx)) {
@curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, 1);
@curl_setopt($ch, CURLOPT_PROXY, $prx);
- $prxusr = @get_config('system','proxyuser');
+ $prxusr = @Config::Get('system','proxyuser');
if(strlen($prxusr))
@curl_setopt($ch, CURLOPT_PROXYUSERPWD, $prxusr);
}
@@ -263,7 +265,7 @@ function z_post_url($url, $params, $redirects = 0, $opts = array()) {
@curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (compatible; zot)");
@curl_setopt($ch, CURLOPT_ENCODING, '');
- $ciphers = @get_config('system','curl_ssl_ciphers');
+ $ciphers = @Config::Get('system','curl_ssl_ciphers');
if($ciphers)
@curl_setopt($ch, CURLOPT_SSL_CIPHER_LIST, $ciphers);
@@ -296,8 +298,8 @@ 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_setopt($ch, CURLOPT_TIMEOUT, (($curl_time !== false) ? $curl_time : 60));
+ $curl_time = intval(@Config::Get('system','curl_timeout'));
+ @curl_setopt($ch, CURLOPT_TIMEOUT, (($curl_time !== 0) ? $curl_time : 60));
}
if(x($opts,'http_auth')) {
@@ -318,11 +320,11 @@ function z_post_url($url, $params, $redirects = 0, $opts = array()) {
@curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,
((x($opts,'novalidate') && intval($opts['novalidate'])) ? false : true));
- $prx = get_config('system','proxy');
+ $prx = Config::Get('system','proxy');
if(strlen($prx)) {
@curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, 1);
@curl_setopt($ch, CURLOPT_PROXY, $prx);
- $prxusr = get_config('system','proxyuser');
+ $prxusr = Config::Get('system','proxyuser');
if(strlen($prxusr))
@curl_setopt($ch, CURLOPT_PROXYUSERPWD, $prxusr);
}
@@ -555,12 +557,15 @@ function z_dns_check($h,$check_mx = 0) {
return((@dns_get_record($h,$opts) || filter_var($h, FILTER_VALIDATE_IP)) ? true : false);
}
-function is_local_url($url) {
- if (str_starts_with($url, z_root()) || str_starts_with($url, '/')) {
- return true;
- }
-
- return false;
+/**
+ * Returns whether an URL is local to the site, or not.
+ *
+ * @param string $url The URL to check
+ *
+ * @return bool True if the URL is local, false otherwise.
+ */
+function is_local_url(string $url): bool {
+ return str_starts_with($url, z_root()) || str_starts_with($url, '/');
}
/**
@@ -603,12 +608,12 @@ function validate_url(&$url) {
*/
function validate_email(string $addr): bool {
- if(get_config('system', 'disable_email_validation'))
+ if(Config::Get('system', 'disable_email_validation'))
return true;
$matches = array();
$result = preg_match(
- '/^[A-Z0-9._%-]+@([A-Z0-9.-]+\.[A-Z0-9-]{2,})$/i',
+ '/^[A-Z0-9._%+-]+@([A-Z0-9.-]+\.[A-Z0-9-]{2,})$/i',
punify($addr),
$matches);
@@ -638,7 +643,7 @@ function allowed_url($url) {
return false;
}
- $str_allowed = get_config('system', 'allowed_sites');
+ $str_allowed = Config::Get('system', 'allowed_sites');
if(! $str_allowed)
return true;
@@ -682,8 +687,8 @@ function allowed_email($email) {
if(! $domain)
return false;
- $str_allowed = get_config('system', 'allowed_email');
- $str_not_allowed = get_config('system', 'not_allowed_email');
+ $str_allowed = Config::Get('system', 'allowed_email');
+ $str_not_allowed = Config::Get('system', 'not_allowed_email');
if(! $str_allowed && ! $str_not_allowed)
return true;
@@ -1472,7 +1477,7 @@ function do_delivery($deliveries, $force = false) {
/*
$x = q("select count(outq_hash) as total from outq where outq_delivered = 0");
- if(intval($x[0]['total']) > intval(get_config('system','force_queue_threshold',3000)) && (! $force)) {
+ if(intval($x[0]['total']) > intval(Config::Get('system','force_queue_threshold',3000)) && (! $force)) {
logger('immediate delivery deferred.', LOGGER_DEBUG, LOG_INFO);
foreach($deliveries as $d) {
Queue::update($d);
@@ -1482,13 +1487,13 @@ function do_delivery($deliveries, $force = false) {
*/
- $interval = get_config('queueworker', 'queue_interval', 500000);
+ $interval = Config::Get('queueworker', 'queue_interval', 500000);
- $deliveries_per_process = intval(get_config('system','delivery_batch_count'));
+ $deliveries_per_process = intval(Config::Get('system', 'delivery_batch_count'));
- if($deliveries_per_process <= 0)
+ if($deliveries_per_process <= 0) {
$deliveries_per_process = 1;
-
+ }
$deliver = [];
foreach($deliveries as $d) {
@@ -1542,9 +1547,9 @@ function get_site_info() {
$admin = false;
}
- $def_service_class = get_config('system','default_service_class');
+ $def_service_class = Config::Get('system','default_service_class');
if($def_service_class)
- $service_class = get_config('service_class',$def_service_class);
+ $service_class = Config::Get('service_class',$def_service_class);
else
$service_class = false;
@@ -1555,9 +1560,9 @@ function get_site_info() {
if(! isset($commit) || strlen($commit) > 16)
$commit = '';
- $site_info = get_config('system','info');
- $site_name = get_config('system','sitename');
- if(! get_config('system','hidden_version_siteinfo')) {
+ $site_info = Config::Get('system','info');
+ $site_name = Config::Get('system','sitename');
+ if(! Config::Get('system','hidden_version_siteinfo')) {
$version = Zotlabs\Lib\System::get_project_version();
$tag = Zotlabs\Lib\System::get_std_version();
@@ -1573,15 +1578,15 @@ function get_site_info() {
}
//Statistics
- $channels_total_stat = intval(get_config('system','channels_total_stat'));
- $channels_active_halfyear_stat = intval(get_config('system','channels_active_halfyear_stat'));
- $channels_active_monthly_stat = intval(get_config('system','channels_active_monthly_stat'));
- $local_posts_stat = intval(get_config('system','local_posts_stat'));
- $local_comments_stat = intval(get_config('system','local_comments_stat'));
- $hide_in_statistics = intval(get_config('system','hide_in_statistics'));
- $site_expire = intval(get_config('system', 'default_expire_days'));
-
- load_config('feature_lock');
+ $channels_total_stat = intval(Config::Get('system','channels_total_stat'));
+ $channels_active_halfyear_stat = intval(Config::Get('system','channels_active_halfyear_stat'));
+ $channels_active_monthly_stat = intval(Config::Get('system','channels_active_monthly_stat'));
+ $local_posts_stat = intval(Config::Get('system','local_posts_stat'));
+ $local_comments_stat = intval(Config::Get('system','local_comments_stat'));
+ $hide_in_statistics = intval(Config::Get('system','hide_in_statistics'));
+ $site_expire = intval(Config::Get('system', 'default_expire_days'));
+
+ Config::Load('feature_lock');
$locked_features = array();
if(is_array(App::$config['feature_lock']) && count(App::$config['feature_lock'])) {
foreach(App::$config['feature_lock'] as $k => $v) {
@@ -1602,18 +1607,18 @@ function get_site_info() {
'server_role' => Zotlabs\Lib\System::get_server_role(),
'commit' => $commit,
'plugins' => $visible_plugins,
- 'register_policy' => $register_policy[get_config('system','register_policy')],
- 'invitation_only' => (bool) intval(get_config('system','invitation_only')),
- 'directory_mode' => $directory_mode[get_config('system','directory_mode')],
- 'directory_server' => get_config('system','directory_server'),
- 'language' => get_config('system','language'),
- 'rss_connections' => (bool) intval(get_config('system','feed_contacts')),
+ 'register_policy' => $register_policy[Config::Get('system','register_policy')],
+ 'invitation_only' => (bool) intval(Config::Get('system','invitation_only')),
+ 'directory_mode' => $directory_mode[Config::Get('system','directory_mode')],
+ 'directory_server' => Config::Get('system','directory_server'),
+ 'language' => Config::Get('system','language'),
+ 'rss_connections' => (bool) intval(Config::Get('system','feed_contacts')),
'expiration' => $site_expire,
'default_service_restrictions' => $service_class,
'locked_features' => $locked_features,
'admin' => $admin,
'dbdriver' => DBA::$dba->getdriver() . ' ' . ((ACTIVE_DBTYPE == DBTYPE_POSTGRES) ? 'postgres' : 'mysql'),
- 'lastpoll' => get_config('system','lastpoll'),
+ 'lastpoll' => Config::Get('system','lastpoll'),
'info' => (($site_info) ? $site_info : ''),
'channels_total' => $channels_total_stat,
'hide_in_statistics' => $hide_in_statistics
@@ -1651,7 +1656,7 @@ function check_siteallowed($url) {
if(array_key_exists('allowed',$arr))
return $arr['allowed'];
- $bl1 = get_config('system','whitelisted_sites');
+ $bl1 = Config::Get('system','whitelisted_sites');
if(is_array($bl1) && $bl1) {
foreach($bl1 as $bl) {
if($bl1 === '*')
@@ -1660,7 +1665,7 @@ function check_siteallowed($url) {
return true;
}
}
- $bl1 = get_config('system','blacklisted_sites');
+ $bl1 = Config::Get('system','blacklisted_sites');
if(is_array($bl1) && $bl1) {
foreach($bl1 as $bl) {
if($bl1 === '*')
@@ -1696,7 +1701,7 @@ function check_channelallowed($hash) {
if(array_key_exists('allowed',$arr))
return $arr['allowed'];
- $bl1 = get_config('system','whitelisted_channels');
+ $bl1 = Config::Get('system','whitelisted_channels');
if(is_array($bl1) && $bl1) {
foreach($bl1 as $bl) {
if($bl1 === '*')
@@ -1705,7 +1710,7 @@ function check_channelallowed($hash) {
return true;
}
}
- $bl1 = get_config('system','blacklisted_channels');
+ $bl1 = Config::Get('system','blacklisted_channels');
if(is_array($bl1) && $bl1) {
foreach($bl1 as $bl) {
if($bl1 === '*')
@@ -1809,54 +1814,9 @@ function network_to_name($s) {
*/
function z_mail($params) {
- if(! $params['fromEmail']) {
- $params['fromEmail'] = get_config('system','from_email');
- if(! $params['fromEmail'])
- $params['fromEmail'] = 'Administrator' . '@' . App::get_hostname();
- }
- if(! $params['fromName']) {
- $params['fromName'] = get_config('system','from_email_name');
- if(! $params['fromName'])
- $params['fromName'] = Zotlabs\Lib\System::get_site_name();
- }
- if(! $params['replyTo']) {
- $params['replyTo'] = get_config('system','reply_address');
- if(! $params['replyTo'])
- $params['replyTo'] = 'noreply' . '@' . App::get_hostname();
- }
-
- $params['sent'] = false;
- $params['result'] = false;
-
- /**
- * @hooks email_send
- * * \e params @see z_mail()
- */
- call_hooks('email_send', $params);
-
- if($params['sent']) {
- logger('notification: z_mail returns ' . (($params['result']) ? 'success' : 'failure'), LOGGER_DEBUG);
- return $params['result'];
- }
-
- $fromName = email_header_encode(html_entity_decode($params['fromName'],ENT_QUOTES,'UTF-8'),'UTF-8');
- $messageSubject = email_header_encode(html_entity_decode($params['messageSubject'],ENT_QUOTES,'UTF-8'),'UTF-8');
-
- $messageHeader =
- $params['additionalMailHeader'] .
- "From: $fromName <{$params['fromEmail']}>" . PHP_EOL .
- "Reply-To: $fromName <{$params['replyTo']}>" . PHP_EOL .
- "Content-Type: text/plain; charset=UTF-8";
-
- // send the message
- $res = mail(
- $params['toEmail'], // send to address
- $messageSubject, // subject
- $params['textVersion'],
- $messageHeader // message headers
- );
- logger('notification: z_mail returns ' . (($res) ? 'success' : 'failure'), LOGGER_DEBUG);
- return $res;
+ // Delegate the call to the Mailer class.
+ $mailer = new Mailer($params);
+ return $mailer->deliver();
}
@@ -2141,21 +2101,59 @@ function get_request_string($url) {
/**
- * Builds a url from the result of `parse_url`.
+ * Reconstructs a URL from its parsed components.
+ *
+ * This function takes a parsed URL as an associative array and reconstructs
+ * the URL based on the specified components (scheme, host, port, user, pass, path, query, fragment).
+ * You can specify which components should be included in the final URL by passing the optional
+ * `$parts` array. The function will return the complete URL string formed by combining
+ * only the parts that exist in both the parsed URL and the `$parts` array.
+ *
+ * @param array $parsed_url The parsed URL components as an associative array.
+ * The array can include keys like 'scheme', 'host', 'port', 'user', 'pass',
+ * 'path', 'query', 'fragment'.
*
- * @param array $parsed_url An associative array as produced by `parse_url`.
+ * @param array $parts An optional array that specifies which components of the URL
+ * should be included in the final string. Defaults to:
+ * ['scheme', 'host', 'port', 'user', 'pass', 'path', 'query', 'fragment'].
+ * If any of the components are not required, they can be omitted from the array.
*
- * @return The reassembled URL as a string.
+ * @return string The reconstructed URL as a string.
*/
-function unparse_url($parsed_url) {
- $scheme = isset($parsed_url['scheme']) ? $parsed_url['scheme'] . '://' : '';
- $host = isset($parsed_url['host']) ? $parsed_url['host'] : '';
- $port = isset($parsed_url['port']) ? ':' . $parsed_url['port'] : '';
- $user = isset($parsed_url['user']) ? $parsed_url['user'] : '';
- $pass = isset($parsed_url['pass']) ? ':' . $parsed_url['pass'] : '';
- $pass = ($user || $pass) ? "$pass@" : '';
- $path = isset($parsed_url['path']) ? $parsed_url['path'] : '';
- $query = isset($parsed_url['query']) ? '?' . $parsed_url['query'] : '';
- $fragment = isset($parsed_url['fragment']) ? '#' . $parsed_url['fragment'] : '';
- return "$scheme$user$pass$host$port$path$query$fragment";
+function unparse_url(array $parsed_url, array $parts = ['scheme', 'host', 'port', 'user', 'pass', 'path', 'query', 'fragment']): string {
+ $url_parts = [];
+
+ if (in_array('scheme', $parts) && array_key_exists('scheme', $parsed_url)) {
+ $url_parts[] = $parsed_url['scheme'] . '://';
+ }
+
+ if (in_array('user', $parts) && array_key_exists('user', $parsed_url)) {
+ $url_parts[] = $parsed_url['user'];
+ if (in_array('pass', $parts) && array_key_exists('pass', $parsed_url)) {
+ $url_parts[] = ':' . $parsed_url['pass'];
+ }
+ $url_parts[] = '@';
+ }
+
+ if (in_array('host', $parts) && array_key_exists('host', $parsed_url)) {
+ $url_parts[] = $parsed_url['host'];
+ }
+
+ if (in_array('port', $parts) && array_key_exists('port', $parsed_url)) {
+ $url_parts[] = ':' . $parsed_url['port'];
+ }
+
+ if (in_array('path', $parts) && array_key_exists('path', $parsed_url)) {
+ $url_parts[] = $parsed_url['path'];
+ }
+
+ if (in_array('query', $parts) && array_key_exists('query', $parsed_url)) {
+ $url_parts[] = '?' . $parsed_url['query'];
+ }
+
+ if (in_array('fragment', $parts) && array_key_exists('fragment', $parsed_url)) {
+ $url_parts[] = '#' . $parsed_url['fragment'];
+ }
+
+ return implode('', $url_parts);
}