aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorzotlabs <mike@macgirvin.com>2017-04-05 19:08:43 -0700
committerzotlabs <mike@macgirvin.com>2017-04-05 19:08:43 -0700
commit9fb08fb5022c9eaf6368a9d3ac07bb1dcf856c20 (patch)
treec83aec69b20bcee45b022dd343faa1155835a5c1
parent6710a77c26b9f5d621ad839cadeefb08fa066aa2 (diff)
downloadvolse-hubzilla-9fb08fb5022c9eaf6368a9d3ac07bb1dcf856c20.tar.gz
volse-hubzilla-9fb08fb5022c9eaf6368a9d3ac07bb1dcf856c20.tar.bz2
volse-hubzilla-9fb08fb5022c9eaf6368a9d3ac07bb1dcf856c20.zip
make legal_webbie() pluggable - * this should not be merged with federated projects unless the federation drivers make use of the hooks.
-rw-r--r--doc/hook/legal_webbie.bb10
-rw-r--r--doc/hook/legal_webbie_text.bb7
-rw-r--r--doc/hooklist.bb6
-rw-r--r--include/text.php38
4 files changed, 44 insertions, 17 deletions
diff --git a/doc/hook/legal_webbie.bb b/doc/hook/legal_webbie.bb
new file mode 100644
index 000000000..8c7d32d56
--- /dev/null
+++ b/doc/hook/legal_webbie.bb
@@ -0,0 +1,10 @@
+[h2]legal_webbie[/h2]
+
+Called when validating a channel address. By default the valid characters are
+a-z,0-9,-,_, and . Uppercase ASCII characters are folded to lower and any invalid characters are stripped.
+
+Some federated networks require more restrictive rules.
+
+The hook is called with an array [ 'input' => (supplied text), 'output' => (validated text) ]
+
+A plugin will generally perform a regex filter or text operation on 'input' and provide the results in 'output'. \ No newline at end of file
diff --git a/doc/hook/legal_webbie_text.bb b/doc/hook/legal_webbie_text.bb
new file mode 100644
index 000000000..32c74c93b
--- /dev/null
+++ b/doc/hook/legal_webbie_text.bb
@@ -0,0 +1,7 @@
+[h2]legal_webbie_text[/h2]
+
+Returns a string describing the text rules applied to legal_webbie().
+
+Called with an array [ 'text' => (descriptive text describing text character limitations) ]
+
+A plugin should return the description of the allowed characters and operation performed in the 'legal_webbie' hook to assist people when creating a new channel. \ No newline at end of file
diff --git a/doc/hooklist.bb b/doc/hooklist.bb
index 6933edad2..0b74a4df2 100644
--- a/doc/hooklist.bb
+++ b/doc/hooklist.bb
@@ -317,6 +317,12 @@ Hooks allow plugins/addons to "hook into" the code at many points and alter the
[zrl=[baseurl]/help/hook/jot_tool]jot_tool[/zrl]
Deprecated and possibly obsolete. Allows one to add action buttons to the post editor.
+[zrl=[baseurl]/help/hook/legal_webbie]legal_webbie[/zrl]
+ Called to validate a channel address
+
+[zrl=[baseurl]/help/hook/legal_webbie_text]legal_webbie_text[/zrl]
+ Provides an explanation of text/character restrictions for legal_webbie()
+
[zrl=[baseurl]/help/hook/load_pdl]load_pdl[/zrl]
Called when we load a PDL file or description
diff --git a/include/text.php b/include/text.php
index e02becf31..bbf0b5b98 100644
--- a/include/text.php
+++ b/include/text.php
@@ -2000,30 +2000,34 @@ function legal_webbie($s) {
if(! strlen($s))
return '';
+ // WARNING: This regex will not work in a federated environment.
+ // You will probably want something like
+ // preg_replace('/([^a-z0-9\_])/','',strtolower($s));
- // Has to start with a lowercase alphabetic character - not a number.
- // This is so we can differentiate between something like channel=123
- // and channel=foo and lookup the first by numeric id and the second
- // by nickname.
+ $r = preg_replace('/([^a-z0-9\-\_\.])/','',strtolower($s));
- $x = $s;
- do {
- $s = $x;
- $x = preg_replace('/^([^a-z])(.*?)/',"$2",$s);
- } while($x != $s);
+ $x = [ 'input' => $s, 'output' => $r ];
+ call_hooks('legal_webbie',$x);
+ return $x['output'];
- // Use the lowest common denominator rules (letters, numbers, and underscore)
- // if the site configuration allows federation with other networks
+}
+
+function legal_webbie_text() {
+
+ // WARNING: This will not work in a federated environment.
+
+ $s = t('a-z, 0-9, -, _, and . only');
+
+ $x = [ 'text' => $s ];
+ call_hooks('legal_webbie_text',$x);
+ return $x['text'];
- if(Zlib\System::get_server_role() === 'pro') {
- return preg_replace('/([^a-z0-9\-\_\.])/','',$x);
- }
- else {
- return preg_replace('/([^a-z0-9\_])/','',$x);
- }
}
+
+
+
function check_webbie($arr) {