The Hubzilla
 All Classes Namespaces Files Functions Variables Pages
network.php File Reference

Network related functions. More...

Functions

 get_capath ()
 Returns path to CA file. More...
 
 z_fetch_url ($url, $binary=false, $redirects=0, $opts=array())
 fetches an URL. More...
 
 z_post_url ($url, $params, $redirects=0, $opts=array())
 Does a curl post request. More...
 
 z_post_url_json ($url, $params, $redirects=0, $opts=array())
 Like z_post_url() but with an application/json HTTP header. More...
 
 json_return_and_die ($x, $content_type= 'application/json')
 
 http_status ($val, $msg= '')
 Send HTTP status header. More...
 
 http_status_exit ($val, $msg= '')
 Send HTTP status header and exit. More...
 
 convert_xml_element_to_array ($xml_element, &$recursion_depth=0)
 Convert an XML document to a normalised, case-corrected array used by webfinger. More...
 
 z_dns_check ($h, $check_mx=0)
 
 validate_url (&$url)
 Validates a given URL. More...
 
 validate_email ($addr)
 Checks that email is an actual resolvable internet address. More...
 
 allowed_url ($url)
 Check $url against our list of allowed sites. More...
 
 allowed_email ($email)
 Check if email address is allowed to register here. More...
 
 parse_xml_string ($s, $strict=true)
 
 scale_external_images ($s, $include_link=true, $scale_replace=false)
 Scales an external image. More...
 
 xml2array ($contents, $namespaces=true, $get_attributes=1, $priority= 'attribute')
 xml2array() will convert the given XML text to an array in the XML structure. More...
 
 email_header_encode ($in_str, $charset= 'UTF-8')
 
 discover_by_url ($url, $arr=null)
 Creates an xchan entry for URL. More...
 
 discover_by_webbie ($webbie, $protocol= '')
 
 webfinger_rfc7033 ($webbie, $zot=false)
 Fetch and return a webfinger for a webbie. More...
 
 old_webfinger ($webbie)
 
 fetch_lrdd_template ($host)
 
 fetch_xrd_links ($url)
 
 scrape_feed ($url)
 
 do_delivery ($deliveries, $force=false)
 
 get_site_info ()
 
 check_siteallowed ($url)
 
 check_channelallowed ($hash)
 
 deliverable_singleton ($channel_id, $xchan)
 
 get_repository_version ($branch= 'master')
 
 network_to_name ($s)
 Get translated network name. More...
 
 z_mail ($params)
 Send a text email message. More...
 
 probe_api_path ($host)
 Discover the best API path available for redmatrix/hubzilla servers. More...
 
 scrape_vcard ($url)
 
 service_plink ($contact, $guid)
 
 getBestSupportedMimeType ($mimeTypes=null, $acceptedTypes=false)
 
 jsonld_document_loader ($url)
 Perform caching for jsonld normaliser. More...
 

Detailed Description

Network related functions.

Function Documentation

allowed_email (   $email)

Check if email address is allowed to register here.

Compare against our list (wildcards allowed).

Parameters
string$email
Returns
boolean Returns false if not allowed, true if allowed or if allowed list is not configured.

Referenced by check_account_email().

allowed_url (   $url)

Check $url against our list of allowed sites.

Wildcards allowed. If allowed_sites is unset return true.

Parameters
string$url
Returns
boolean Return true if url is allowed, otherwise return false

Referenced by new_contact().

check_channelallowed (   $hash)
Parameters
string$hash
Returns
boolean
Hooks:
check_channelallowed Used to over-ride or bypass the channel black/white block lists.
  • string hash
  • boolean allowed - optional return value set in hook

Referenced by process_delivery(), and process_mail_delivery().

check_siteallowed (   $url)
Parameters
string$url
Returns
boolean
Hooks:
check_siteallowed Used to over-ride or bypass the site black/white block lists.
  • string url
  • boolean allowed - optional return value set in hook

Referenced by Zotlabs\Lib\ActivityStreams\fetch_property(), Zotlabs\Module\Well_known\init(), Zotlabs\Daemon\Externals\run(), and zot_gethub().

convert_xml_element_to_array (   $xml_element,
$recursion_depth = 0 
)

Convert an XML document to a normalised, case-corrected array used by webfinger.

Parameters
string | array | SimpleXMLElement$xml_element
[in,out]int$recursion_depth
Returns
NULL|string|array

Referenced by fetch_xrd_links().

deliverable_singleton (   $channel_id,
  $xchan 
)
discover_by_url (   $url,
  $arr = null 
)

Creates an xchan entry for URL.

Parameters
string$urlURL to discover
array$arrfallback values if scrape_feed() is empty
Returns
boolean

Referenced by new_contact().

discover_by_webbie (   $webbie,
  $protocol = '' 
)
Parameters
string$webbie
string$protocol(optional) default empty
Returns
boolean
Hooks:
discover_channel_webfinger Called when performing a webfinger lookup.
  • string address - The webbie
  • string protocol
  • array webfinger - The result from webfinger_rfc7033()
  • boolean success - The return value, default false

Referenced by Zotlabs\Module\Chanview\get(), and new_contact().

do_delivery (   $deliveries,
  $force = false 
)
email_header_encode (   $in_str,
  $charset = 'UTF-8' 
)
fetch_lrdd_template (   $host)

Referenced by old_webfinger().

fetch_xrd_links (   $url)
get_capath ( )

Returns path to CA file.

Returns
string

Referenced by z_fetch_url(), and z_post_url().

get_repository_version (   $branch = 'master')
get_site_info ( )
getBestSupportedMimeType (   $mimeTypes = null,
  $acceptedTypes = false 
)
Parameters
array$mimeTypes
string$acceptedTypesby default false will use $_SERVER['HTTP_ACCEPT']
Returns
array|NULL
http_status (   $val,
  $msg = '' 
)

Send HTTP status header.

Parameters
int$valinteger HTTP status result value
string$msgoptional message

Referenced by http_status_exit(), and system_down().

http_status_exit (   $val,
  $msg = '' 
)

Send HTTP status header and exit.

Parameters
int$valinteger HTTP status result value
string$msgoptional message
Returns
void does not return, process is terminated

Referenced by get_feed_for(), Zotlabs\Module\Well_known\init(), Zotlabs\Module\Oep\init(), and poco().

json_return_and_die (   $x,
  $content_type = 'application/json' 
)

Referenced by api_albums(), api_attach_list(), api_channel_stream(), api_client_register(), api_export_basic(), api_file_data(), api_file_detail(), api_file_export(), api_file_meta(), api_group(), api_group_members(), api_network_stream(), api_photo_detail(), api_photos(), api_red_xchan(), api_zot_abconfig(), api_zot_abook_xchan(), api_zot_perm_allowed(), Zotlabs\Zot\Receiver\Dispatch(), Zotlabs\Zot\Auth\Finalise(), Zotlabs\Module\Smilies\get(), Zotlabs\Module\Theme_info\get(), Zotlabs\Module\Search\get(), Zotlabs\Module\Dirsearch\get(), Zotlabs\Module\Oexchange\get(), Zotlabs\Module\Settings\Permcats\get(), Zotlabs\Module\Chatsvc\get(), Zotlabs\Module\Chat\get(), Zotlabs\Module\Notes\init(), Zotlabs\Module\Online\init(), Zotlabs\Module\Prate\init(), Zotlabs\Module\Siteinfo\init(), Zotlabs\Module\Zfinger\init(), Zotlabs\Module\Ratingsearch\init(), Zotlabs\Module\Register\init(), Zotlabs\Module\Wfinger\init(), Zotlabs\Module\Zotfeed\init(), Zotlabs\Module\Tasks\init(), Zotlabs\Module\Impel\init(), Zotlabs\Module\New_channel\init(), Zotlabs\Module\Permcat\init(), Zotlabs\Module\Chatsvc\init(), Zotlabs\Module\Owa\init(), Zotlabs\Module\Regdir\init(), Zotlabs\Module\File_upload\post(), Zotlabs\Module\Admin\Plugins\post(), Zotlabs\Module\Wall_attach\post(), Zotlabs\Module\Embedphotos\post(), Zotlabs\Module\Prate\post(), Zotlabs\Module\Chatsvc\post(), Zotlabs\Module\Tasks\post(), Zotlabs\Module\Photos\post(), Zotlabs\Module\Webpages\post(), Zotlabs\Module\Wiki\post(), red_item(), Zotlabs\Zot\Receiver\ValidateSender(), zot_item_update(), zot_rekey_request(), zot_reply_auth_check(), zot_reply_message_request(), zot_reply_notify(), zot_reply_pickup(), zot_reply_ping(), zot_reply_purge(), and zot_reply_refresh().

jsonld_document_loader (   $url)

Perform caching for jsonld normaliser.

Parameters
string$url
Returns
mixed|boolean|array
network_to_name (   $s)

Get translated network name.

Parameters
string$sNetwork string, see boot.php
Returns
string Translated name of the network
Hooks:
network_to_name
Deprecated:

Referenced by Zotlabs\Module\Connections\get().

old_webfinger (   $webbie)
parse_xml_string (   $s,
  $strict = true 
)

Referenced by fetch_xrd_links().

probe_api_path (   $host)

Discover the best API path available for redmatrix/hubzilla servers.

Parameters
string$host
Returns
string

Referenced by Zotlabs\Module\Import\import_account().

scale_external_images (   $s,
  $include_link = true,
  $scale_replace = false 
)

Scales an external image.

Parameters
string$s
string$include_linkdefault true
string$scale_replacedefault false
Returns
string

Referenced by cleanup_bbcode(), and markdown_to_bb().

scrape_feed (   $url)
Parameters
string$urlThe URL to scrape
Returns
array

Referenced by discover_by_url().

scrape_vcard (   $url)
service_plink (   $contact,
  $guid 
)
Hooks:
service_plink
  • array xchan
  • string guid
  • string url
  • string plink will get returned
validate_email (   $addr)

Checks that email is an actual resolvable internet address.

Parameters
string$addr
Returns
boolean

Referenced by anon_identity_init(), check_account_email(), Zotlabs\Module\Settings\Account\post(), Zotlabs\Module\Invite\post(), and zid_init().

validate_url ( $url)

Validates a given URL.

Take a URL from the wild, prepend http:// if necessary and check DNS to see if it's real (or check if is a valid IP address).

See Also
z_dns_check()
Parameters
[in,out]string$urlURL to check
Returns
boolean Return true if it's OK, false if something is wrong with it

Referenced by Zotlabs\Storage\GitRepo\cloneRepo(), and Zotlabs\Storage\GitRepo\isValidGitRepoURL().

webfinger_rfc7033 (   $webbie,
  $zot = false 
)

Fetch and return a webfinger for a webbie.

Parameters
string$webbie- The webbie
boolean$zot(optional) default false
Returns
boolean|string false or associative array from result JSON

Referenced by discover_by_webbie(), and Zotlabs\Module\Webfinger\get().

xml2array (   $contents,
  $namespaces = true,
  $get_attributes = 1,
  $priority = 'attribute' 
)

xml2array() will convert the given XML text to an array in the XML structure.

Link: http://www.bin-co.com/php/scripts/xml2array/ Portions significantly re-written by mike@.nosp@m.macg.nosp@m.irvin.nosp@m..com for Friendica (namespaces, lowercase tags, get_attribute default changed, more...)

Examples: $array = xml2array(file_get_contents('feed.xml')); $array = xml2array(file_get_contents('feed.xml', true, 1, 'attribute'));

Parameters
string$contentsThe XML text
boolean$namespacestrue or false include namespace information in the returned array as array elements
int$get_attributes1 or 0. If this is 1 the function will get the attributes as well as the tag values - this results in a different array structure in the return value.
string$priorityCan be 'tag' or 'attribute'. This will change the way the resulting array sturcture. For 'tag', the tags are given more importance.
Returns
array The parsed XML in an array form. Use print_r() to see the resulting array structure.
z_dns_check (   $h,
  $check_mx = 0 
)
z_fetch_url (   $url,
  $binary = false,
  $redirects = 0,
  $opts = array() 
)

fetches an URL.

Parameters
string$urlURL to fetch
boolean$binarydefault false TRUE if asked to return binary results (file download)
int$redirectsdefault 0 internal use, recursion counter
array$opts(optional parameters) associative array with:
  • timeout => int seconds, default system config value or 60 seconds
  • headers => array of additional header fields
  • http_auth => username:password
  • novalidate => do not validate SSL certs, default is to validate using our CA list
  • nobody => only return the header
  • filep => stream resource to write body to. header and body are not returned when using this option.
  • custom => custom request method: e.g. 'PUT', 'DELETE'
  • cookiejar => cookie file (write)
  • cookiefile => cookie file (read)
  • session => boolean; append session cookie if $url is our own site
Returns
array an associative array with:
  • int return_code => HTTP return code or 0 if timeout or failure
  • boolean success => boolean true (if HTTP 2xx result) or false
  • string header => HTTP headers
  • string body => fetched content

Referenced by Zotlabs\Module\Setup\check_htaccess(), Zotlabs\Storage\CalDAVClient\ctag_fetch(), Zotlabs\Storage\CalDAVClient\detail_fetch(), discover_by_url(), discover_by_webbie(), Zotlabs\Lib\SuperCurl\exec(), feed_conversation_fetch(), Zotlabs\Lib\ActivityStreams\fetch_property(), fetch_xrd_links(), Zotlabs\Module\Pubsites\get(), Zotlabs\Module\Linkinfo\get(), Zotlabs\Module\Oexchange\get(), Zotlabs\Module\Rpost\get(), Zotlabs\Module\Directory\get(), Zotlabs\Module\Connedit\get(), get_repository_version(), handle_feed(), Zotlabs\Module\Import\import_account(), import_channel_photo_from_url(), import_site(), import_xchan(), import_xchan_photo(), Zotlabs\Module\Sslify\init(), Zotlabs\Module\Magic\init(), Zotlabs\Module\Ratings\init(), Zotlabs\Module\Acl\navbar_complete(), oembed_fetch_url(), Zotlabs\Module\Linkinfo\parseurl_getsiteinfo(), poco_load(), Zotlabs\Module\Import_items\post(), Zotlabs\Module\Setup\post(), probe_api_path(), random_profile(), reflect_photo_callback(), remote_online_status(), Zotlabs\Daemon\Cron_weekly\run(), Zotlabs\Daemon\Onepoll\run(), Zotlabs\Daemon\Ratenotif\run(), Zotlabs\Daemon\Externals\run(), Zotlabs\Zot\Finger\run(), scale_external_images(), scrape_feed(), scrape_vcard(), sync_directories(), update_suggestions(), webfinger_rfc7033(), z_check_cert(), z_post_url(), and zot_register_hub().

z_mail (   $params)

Send a text email message.

Parameters
array$paramsan associative array with:
  • string fromName name of the sender
  • string fromEmail email of the sender
  • string replyTo replyTo address to direct responses
  • string toEmail destination email address
  • string messageSubject subject of the message
  • string htmlVersion html version of the message
  • string textVersion text only version of the message
  • string additionalMailHeader additions to the smtp mail header
Hooks:
email_send

Referenced by Zotlabs\Lib\DB_Upgrade\__construct(), account_allow(), cert_bad_email(), check_cron_broken(), Zotlabs\Module\Lostpass\get(), Zotlabs\Module\Lostpass\post(), Zotlabs\Module\Invite\post(), send_reg_approval_email(), send_register_success_email(), and verify_email_address().

z_post_url (   $url,
  $params,
  $redirects = 0,
  $opts = array() 
)

Does a curl post request.

Parameters
string$urlURL to post
mixed$paramsThe full data to post in a HTTP "POST" operation. This parameter can either be passed as a urlencoded string like 'para1=val1&para2=val2&...' or as an array with the field name as key and field data as value. If value is an array, the Content-Type header will be set to multipart/form-data.
int$redirects= 0 internal use, recursion counter
array$opts(optional parameters) 'timeout' => int seconds, default system config value or 60 seconds 'http_auth' => username:password 'novalidate' => do not validate SSL certs, default is to validate using our CA list 'filep' => stream resource to write body to. header and body are not returned when using this option. 'custom' => custom request method: e.g. 'PUT', 'DELETE'
Returns
array an associative array with:
  • int return_code => HTTP return code or 0 if timeout or failure
  • boolean success => boolean true (if HTTP 2xx result) or false
  • string header => HTTP headers
  • string body => content
  • string debug => from curl_info()

Referenced by Zotlabs\Module\Oexchange\get(), Zotlabs\Module\Share\init(), queue_deliver(), Zotlabs\Zot\Finger\run(), sync_files(), z_post_url_json(), zot_refresh(), and zot_zot().

z_post_url_json (   $url,
  $params,
  $redirects = 0,
  $opts = array() 
)

Like z_post_url() but with an application/json HTTP header.

Add a "Content-Type: application/json" HTTP-header to $opts and call z_post_url().

See Also
z_post_url()
Parameters
string$url
array$params
number$redirectsdefault 0
array$opts(optional) curl options
Returns
z_post_url()