aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorzotlabs <mike@macgirvin.com>2016-11-13 20:22:01 -0800
committerzotlabs <mike@macgirvin.com>2016-11-13 20:22:01 -0800
commit3c302bae5ac71c1853d33117f9bbcfc0e5d81651 (patch)
tree008ba03057e4b22312724155d8c45b7559eb4ca5 /include
parent103cd2b7a15caaadd5ddf8a6b69c8e3de7a2982b (diff)
downloadvolse-hubzilla-3c302bae5ac71c1853d33117f9bbcfc0e5d81651.tar.gz
volse-hubzilla-3c302bae5ac71c1853d33117f9bbcfc0e5d81651.tar.bz2
volse-hubzilla-3c302bae5ac71c1853d33117f9bbcfc0e5d81651.zip
move all the zid related stuff to one file
Diffstat (limited to 'include')
-rw-r--r--include/channel.php54
-rw-r--r--include/hubloc.php24
-rwxr-xr-xinclude/items.php72
-rw-r--r--include/text.php75
-rw-r--r--include/zid.php232
5 files changed, 232 insertions, 225 deletions
diff --git a/include/channel.php b/include/channel.php
index e35f453de..de685ab4c 100644
--- a/include/channel.php
+++ b/include/channel.php
@@ -1371,60 +1371,6 @@ function zat_init() {
-/**
- * @brief Adds a zid parameter to a url.
- *
- * @param string $s
- * The url to accept the zid
- * @param boolean $address
- * $address to use instead of session environment
- * @return string
- *
- * @hooks 'zid'
- * string url - url to accept zid
- * string zid - urlencoded zid
- * string result - the return string we calculated, change it if you want to return something else
- */
-function zid($s,$address = '') {
- if (! strlen($s) || strpos($s,'zid='))
- return $s;
-
- $m = parse_url($s);
- $fragment = ((array_key_exists('fragment',$m) && $m['fragment']) ? $m['fragment'] : false);
- if($fragment !== false)
- $s = str_replace('#' . $fragment,'',$s);
-
- $has_params = ((strpos($s,'?')) ? true : false);
- $num_slashes = substr_count($s, '/');
- if (! $has_params)
- $has_params = ((strpos($s, '&')) ? true : false);
-
- $achar = strpos($s,'?') ? '&' : '?';
-
- $mine = get_my_url();
- $myaddr = (($address) ? $address : get_my_address());
-
- /**
- * @FIXME checking against our own channel url is no longer reliable. We may have a lot
- * of urls attached to out channel. Should probably match against our site, since we
- * will not need to remote authenticate on our own site anyway.
- */
-
- if ($mine && $myaddr && (! link_compare($mine,$s)))
- $zurl = $s . (($num_slashes >= 3) ? '' : '/') . $achar . 'zid=' . urlencode($myaddr);
- else
- $zurl = $s;
-
- // put fragment at the end
-
- if($fragment)
- $zurl .= '#' . $fragment;
-
- $arr = array('url' => $s, 'zid' => urlencode($myaddr), 'result' => $zurl);
- call_hooks('zid', $arr);
-
- return $arr['result'];
-}
// Used from within PCSS themes to set theme parameters. If there's a
// puid request variable, that is the "page owner" and normally their theme
diff --git a/include/hubloc.php b/include/hubloc.php
index b660c1019..17f921f67 100644
--- a/include/hubloc.php
+++ b/include/hubloc.php
@@ -1,29 +1,5 @@
<?php /** @file */
-function is_matrix_url($url) {
-
- static $remembered = [];
-
- $m = @parse_url($url);
- if($m['host']) {
-
- if(array_key_exists($m['host'],$remembered))
- return $remembered[$m['host']];
-
- $r = q("select hubloc_url from hubloc where hubloc_host = '%s' and hubloc_network = 'zot' limit 1",
- dbesc($m['host'])
- );
- if($r) {
- $remembered[$m['host']] = true;
- return true;
- }
- $remembered[$m['host']] = false;
- }
- return false;
-}
-
-
-
function prune_hub_reinstalls() {
$r = q("select site_url from site where site_type = %d",
diff --git a/include/items.php b/include/items.php
index b1a83dfc2..4ac4d6049 100755
--- a/include/items.php
+++ b/include/items.php
@@ -291,78 +291,6 @@ function add_source_route($iid, $hash) {
/**
- * @brief preg_match function when fixing 'naked' links in mod item.php.
- *
- * Check if we've got a hubloc for the site and use a zrl if we do, a url if we don't.
- * Remove any existing zid= param which may have been pasted by mistake - and will have
- * the author's credentials. zid's are dynamic and can't really be passed around like
- * that.
- *
- * @param array $matches
- * @return string
- */
-function red_zrl_callback($matches) {
- require_once('include/hubloc.php');
- $zrl = is_matrix_url($matches[2]);
-
- $t = strip_zids($matches[2]);
- if($t !== $matches[2]) {
- $zrl = true;
- $matches[2] = $t;
- }
-
- if($matches[1] === '#^')
- $matches[1] = '';
- if($zrl)
- return $matches[1] . '#^[zrl=' . $matches[2] . ']' . $matches[2] . '[/zrl]';
-
- return $matches[1] . '#^[url=' . $matches[2] . ']' . $matches[2] . '[/url]';
-}
-
-/**
- * If we've got a url or zrl tag with a naked url somewhere in the link text,
- * escape it with quotes unless the naked url is a linked photo.
- *
- * @param array $matches
- * @return string
- */
-function red_escape_zrl_callback($matches) {
-
- // Uncertain why the url/zrl forms weren't picked up by the non-greedy regex.
-
- if((strpos($matches[3], 'zmg') !== false) || (strpos($matches[3], 'img') !== false) || (strpos($matches[3],'zrl') !== false) || (strpos($matches[3],'url') !== false))
- return $matches[0];
-
- return '[' . $matches[1] . 'rl' . $matches[2] . ']' . $matches[3] . '"' . $matches[4] . '"' . $matches[5] . '[/' . $matches[6] . 'rl]';
-}
-
-function red_escape_codeblock($m) {
- return '[$b64' . $m[2] . base64_encode($m[1]) . '[/' . $m[2] . ']';
-}
-
-function red_unescape_codeblock($m) {
- return '[' . $m[2] . base64_decode($m[1]) . '[/' . $m[2] . ']';
-}
-
-
-function red_zrlify_img_callback($matches) {
- require_once('include/hubloc.php');
- $zrl = is_matrix_url($matches[2]);
-
- $t = strip_zids($matches[2]);
- if($t !== $matches[2]) {
- $zrl = true;
- $matches[2] = $t;
- }
-
- if($zrl)
- return '[zmg' . $matches[1] . ']' . $matches[2] . '[/zmg]';
-
- return $matches[0];
-}
-
-
-/**
* @brief Post an activity.
*
* In its simplest form one needs only to set $arr['body'] to post a note to the logged in channel's wall.
diff --git a/include/text.php b/include/text.php
index fa16a16a1..12b37222b 100644
--- a/include/text.php
+++ b/include/text.php
@@ -837,14 +837,6 @@ function tag_sort_length($a,$b) {
-function strip_zids($s) {
- return preg_replace('/[\?&]zid=(.*?)(&|$)/ism','$2',$s);
-}
-
-function strip_zats($s) {
- return preg_replace('/[\?&]zat=(.*?)(&|$)/ism','$2',$s);
-}
-
/**
* @brief Quick and dirty quoted_printable encoding.
*
@@ -1701,73 +1693,6 @@ function create_export_photo_body(&$item) {
}
/**
- * zidify_callback() and zidify_links() work together to turn any HTML a tags with class="zrl" into zid links
- * These will typically be generated by a bbcode '[zrl]' tag. This is done inside prepare_text() rather than bbcode()
- * because the latter is used for general purpose conversions and the former is used only when preparing text for
- * immediate display.
- *
- * Issues: Currently the order of HTML parameters in the text is somewhat rigid and inflexible.
- * We assume it looks like \<a class="zrl" href="xxxxxxxxxx"\> and will not work if zrl and href appear in a different order.
- *
- * @param array $match
- * @return string
- */
-function zidify_callback($match) {
- $is_zid = ((feature_enabled(local_channel(),'sendzid')) || (strpos($match[1],'zrl')) ? true : false);
- $replace = '<a' . $match[1] . ' href="' . (($is_zid) ? zid($match[2]) : $match[2]) . '"';
- $x = str_replace($match[0],$replace,$match[0]);
-
- return $x;
-}
-
-function zidify_img_callback($match) {
- $is_zid = ((feature_enabled(local_channel(),'sendzid')) || (strpos($match[1],'zrl')) ? true : false);
- $replace = '<img' . $match[1] . ' src="' . (($is_zid) ? zid($match[2]) : $match[2]) . '"';
-
- $x = str_replace($match[0],$replace,$match[0]);
-
- return $x;
-}
-
-
-function zidify_links($s) {
- $s = preg_replace_callback('/\<a(.*?)href\=\"(.*?)\"/ism','zidify_callback',$s);
- $s = preg_replace_callback('/\<img(.*?)src\=\"(.*?)\"/ism','zidify_img_callback',$s);
-
- return $s;
-}
-
-
-
-
-function zidify_text_callback($match) {
- $is_zid = is_matrix_url($match[2]);
- $replace = '<a' . $match[1] . ' href="' . (($is_zid) ? zid($match[2]) : $match[2]) . '"';
- $x = str_replace($match[0],$replace,$match[0]);
-
- return $x;
-}
-
-function zidify_text_img_callback($match) {
- $is_zid = is_matrix_url($match[2]);
- $replace = '<img' . $match[1] . ' src="' . (($is_zid) ? zid($match[2]) : $match[2]) . '"';
-
- $x = str_replace($match[0],$replace,$match[0]);
-
- return $x;
-}
-
-function zidify_text($s) {
-
- $s = preg_replace_callback('/\<a(.*?)href\=\"(.*?)\"/ism','zidify_text_callback',$s);
- $s = preg_replace_callback('/\<img(.*?)src\=\"(.*?)\"/ism','zidify_text_img_callback',$s);
-
- return $s;
-
-
-}
-
-/**
* @brief Return atom link elements for all of our hubs.
*
* @return string
diff --git a/include/zid.php b/include/zid.php
new file mode 100644
index 000000000..ac6433e4c
--- /dev/null
+++ b/include/zid.php
@@ -0,0 +1,232 @@
+<?php
+
+
+function is_matrix_url($url) {
+
+ // in-memory cache to avoid repeated queries for the same host
+ static $remembered = [];
+
+ $m = @parse_url($url);
+ if($m['host']) {
+
+ if(array_key_exists($m['host'],$remembered))
+ return $remembered[$m['host']];
+
+ $r = q("select hubloc_url from hubloc where hubloc_host = '%s' and hubloc_network = 'zot' limit 1",
+ dbesc($m['host'])
+ );
+ if($r) {
+ $remembered[$m['host']] = true;
+ return true;
+ }
+ $remembered[$m['host']] = false;
+ }
+ return false;
+}
+
+/**
+ * @brief Adds a zid parameter to a url.
+ *
+ * @param string $s
+ * The url to accept the zid
+ * @param boolean $address
+ * $address to use instead of session environment
+ * @return string
+ *
+ * @hooks 'zid'
+ * string url - url to accept zid
+ * string zid - urlencoded zid
+ * string result - the return string we calculated, change it if you want to return something else
+ */
+
+function zid($s,$address = '') {
+ if (! strlen($s) || strpos($s,'zid='))
+ return $s;
+
+ $m = parse_url($s);
+ $fragment = ((array_key_exists('fragment',$m) && $m['fragment']) ? $m['fragment'] : false);
+ if($fragment !== false)
+ $s = str_replace('#' . $fragment,'',$s);
+
+ $has_params = ((strpos($s,'?')) ? true : false);
+ $num_slashes = substr_count($s, '/');
+ if (! $has_params)
+ $has_params = ((strpos($s, '&')) ? true : false);
+
+ $achar = strpos($s,'?') ? '&' : '?';
+
+ $mine = get_my_url();
+ $myaddr = (($address) ? $address : get_my_address());
+
+ /**
+ * @FIXME checking against our own channel url is no longer reliable. We may have a lot
+ * of urls attached to out channel. Should probably match against our site, since we
+ * will not need to remote authenticate on our own site anyway.
+ */
+
+ if ($mine && $myaddr && (! link_compare($mine,$s)))
+ $zurl = $s . (($num_slashes >= 3) ? '' : '/') . $achar . 'zid=' . urlencode($myaddr);
+ else
+ $zurl = $s;
+
+ // put fragment at the end
+
+ if($fragment)
+ $zurl .= '#' . $fragment;
+
+ $arr = array('url' => $s, 'zid' => urlencode($myaddr), 'result' => $zurl);
+ call_hooks('zid', $arr);
+
+ return $arr['result'];
+}
+
+
+function strip_zids($s) {
+ return preg_replace('/[\?&]zid=(.*?)(&|$)/ism','$2',$s);
+}
+
+function strip_zats($s) {
+ return preg_replace('/[\?&]zat=(.*?)(&|$)/ism','$2',$s);
+}
+
+
+/**
+ * zidify_callback() and zidify_links() work together to turn any HTML a tags with class="zrl" into zid links
+ * These will typically be generated by a bbcode '[zrl]' tag. This is done inside prepare_text() rather than bbcode()
+ * because the latter is used for general purpose conversions and the former is used only when preparing text for
+ * immediate display.
+ *
+ * Issues: Currently the order of HTML parameters in the text is somewhat rigid and inflexible.
+ * We assume it looks like \<a class="zrl" href="xxxxxxxxxx"\> and will not work if zrl and href appear in a different order.
+ *
+ * @param array $match
+ * @return string
+ */
+function zidify_callback($match) {
+ $is_zid = ((feature_enabled(local_channel(),'sendzid')) || (strpos($match[1],'zrl')) ? true : false);
+ $replace = '<a' . $match[1] . ' href="' . (($is_zid) ? zid($match[2]) : $match[2]) . '"';
+ $x = str_replace($match[0],$replace,$match[0]);
+
+ return $x;
+}
+
+function zidify_img_callback($match) {
+ $is_zid = ((feature_enabled(local_channel(),'sendzid')) || (strpos($match[1],'zrl')) ? true : false);
+ $replace = '<img' . $match[1] . ' src="' . (($is_zid) ? zid($match[2]) : $match[2]) . '"';
+
+ $x = str_replace($match[0],$replace,$match[0]);
+
+ return $x;
+}
+
+
+function zidify_links($s) {
+ $s = preg_replace_callback('/\<a(.*?)href\=\"(.*?)\"/ism','zidify_callback',$s);
+ $s = preg_replace_callback('/\<img(.*?)src\=\"(.*?)\"/ism','zidify_img_callback',$s);
+
+ return $s;
+}
+
+
+
+
+function zidify_text_callback($match) {
+ $is_zid = is_matrix_url($match[2]);
+ $replace = '<a' . $match[1] . ' href="' . (($is_zid) ? zid($match[2]) : $match[2]) . '"';
+ $x = str_replace($match[0],$replace,$match[0]);
+
+ return $x;
+}
+
+function zidify_text_img_callback($match) {
+ $is_zid = is_matrix_url($match[2]);
+ $replace = '<img' . $match[1] . ' src="' . (($is_zid) ? zid($match[2]) : $match[2]) . '"';
+
+ $x = str_replace($match[0],$replace,$match[0]);
+
+ return $x;
+}
+
+function zidify_text($s) {
+
+ $s = preg_replace_callback('/\<a(.*?)href\=\"(.*?)\"/ism','zidify_text_callback',$s);
+ $s = preg_replace_callback('/\<img(.*?)src\=\"(.*?)\"/ism','zidify_text_img_callback',$s);
+
+ return $s;
+
+
+}
+
+
+/**
+ * @brief preg_match function when fixing 'naked' links in mod item.php.
+ *
+ * Check if we've got a hubloc for the site and use a zrl if we do, a url if we don't.
+ * Remove any existing zid= param which may have been pasted by mistake - and will have
+ * the author's credentials. zid's are dynamic and can't really be passed around like
+ * that.
+ *
+ * @param array $matches
+ * @return string
+ */
+function red_zrl_callback($matches) {
+ require_once('include/hubloc.php');
+ $zrl = is_matrix_url($matches[2]);
+
+ $t = strip_zids($matches[2]);
+ if($t !== $matches[2]) {
+ $zrl = true;
+ $matches[2] = $t;
+ }
+
+ if($matches[1] === '#^')
+ $matches[1] = '';
+ if($zrl)
+ return $matches[1] . '#^[zrl=' . $matches[2] . ']' . $matches[2] . '[/zrl]';
+
+ return $matches[1] . '#^[url=' . $matches[2] . ']' . $matches[2] . '[/url]';
+}
+
+/**
+ * If we've got a url or zrl tag with a naked url somewhere in the link text,
+ * escape it with quotes unless the naked url is a linked photo.
+ *
+ * @param array $matches
+ * @return string
+ */
+
+function red_escape_zrl_callback($matches) {
+
+ // Uncertain why the url/zrl forms weren't picked up by the non-greedy regex.
+
+ if((strpos($matches[3], 'zmg') !== false) || (strpos($matches[3], 'img') !== false) || (strpos($matches[3],'zrl') !== false) || (strpos($matches[3],'url') !== false))
+ return $matches[0];
+
+ return '[' . $matches[1] . 'rl' . $matches[2] . ']' . $matches[3] . '"' . $matches[4] . '"' . $matches[5] . '[/' . $matches[6] . 'rl]';
+}
+
+function red_escape_codeblock($m) {
+ return '[$b64' . $m[2] . base64_encode($m[1]) . '[/' . $m[2] . ']';
+}
+
+function red_unescape_codeblock($m) {
+ return '[' . $m[2] . base64_decode($m[1]) . '[/' . $m[2] . ']';
+}
+
+
+function red_zrlify_img_callback($matches) {
+ require_once('include/hubloc.php');
+ $zrl = is_matrix_url($matches[2]);
+
+ $t = strip_zids($matches[2]);
+ if($t !== $matches[2]) {
+ $zrl = true;
+ $matches[2] = $t;
+ }
+
+ if($zrl)
+ return '[zmg' . $matches[1] . ']' . $matches[2] . '[/zmg]';
+
+ return $matches[0];
+}
+