never commited
authorx2000habouzit <x2000habouzit@839d8a87-29fc-0310-9880-83ba4fa771e5>
Sat, 22 Oct 2005 12:55:04 +0000 (12:55 +0000)
committerx2000habouzit <x2000habouzit@839d8a87-29fc-0310-9880-83ba4fa771e5>
Sat, 22 Oct 2005 12:55:04 +0000 (12:55 +0000)
git-svn-id: svn+ssh://murphy/home/svn/platal/trunk@132 839d8a87-29fc-0310-9880-83ba4fa771e5

install.d/wiki/e-protect.php [new file with mode: 0644]
install.d/wiki/empty/empty.tmpl
plugins/pmwiki.platalAuth.php

diff --git a/install.d/wiki/e-protect.php b/install.d/wiki/e-protect.php
new file mode 100644 (file)
index 0000000..2bae8fb
--- /dev/null
@@ -0,0 +1,134 @@
+<?php if (!defined('PmWiki')) exit();\r
+                                                                      /*\r
+  * Copyright *\r
+  Copyright 2004, by Steven Leite (steven_leite@kitimat.net).\r
+  Changes 2004, by Karl Loncarek (Klonk)\r
+\r
+  * License *\r
+  Same as PmWiki (GNU GPL)\r
+\r
+  * Special Thanks *\r
+  Thanks to  Pm (Patrick Michaud, www.pmichaud.com), for creating\r
+  PmWiki, and for sharing his knowledge and insightfulness with the\r
+  PmWiki community.\r
+\r
+  * Description *\r
+  eProtect is an email obfuscation add-on for PmWiki. It intercepts\r
+  pages before they are saved, and rewrites email addresses in a\r
+  protected format.\r
+\r
+     Example: "[[mailto:username@domain.net]]" is automatically replaced with:\r
+     "[[hidden-email:hfre@qbznva.arg]]".\r
+\r
+  When a WikiPage is requested the [[hidden-email:]] directive is\r
+  detected, and then translated into a small javascript.  Once the page\r
+  is rendered to the in website, it's at that point which the javascript\r
+  decodes the protected address. Viewing the source-code of the page\r
+  won't reveal the true email address, nor will clicking on the link to\r
+  "Edit This Page".\r
+\r
+  Also you could give some text that is displayed instead the email address.\r
+\r
+    Example: "[[mailto:username@domain.net | Special Guy]]" is automatically\r
+     replaced with: "[[hidden-email:hfre@qbznva.arg | Special Guy]]". On the\r
+     page you only can see "Special Guy" as urllink.\r
+\r
+  But beware: giving the email address as alternative text renders this script\r
+  useless, because this alternative text is NOT encoded, and thus is also visible\r
+  in HTML source code!\r
+\r
+\r
+  * Installation Instructions *\r
+  1. Copy this script (e-protect.php) to local/scripts/\r
+  2. In your config.php file, add the following line:\r
+     include_once('scripts/e-protect.php');\r
+  3. That's it!\r
+\r
+  * History *\r
+  Apr  7 2005 - * Replaced str_rot13 with strtr to make it work with PHP <4.2.0,\r
+                  and to have the @ recoded.\r
+  Feb 18 2005 - * Added some comment signs to get valid XHTML when validating (Klonk)\r
+  Feb 15 2005 - * Modified encoding and added additional markup for handling (Klonk)\r
+                  [[text -> mailto:...]]\r
+  Jan  7 2005 - * Moved decoding script to Header, due to problem, when SideBar and Main Text\r
+                  contains addresses to decode (Klonk)\r
+\r
+  Nov 17 2004 - * Calling the decoding function as Custom Markup for PmWiki2\r
+   (by Klonk)   * made decoding of [[hidden-email:...]] working\r
+                  BONUS: [[hidden-email:... |DisplayedText]] works also now\r
+                * added class='urllink' to decoded output for same CSS formating\r
+                  as for other links in PmWiki2\r
+                * inserted own function call in array $EditFunctions before 'ReplaceOnSave'\r
+\r
+  May 11, 2004 - Working Beta.  Still a few improvements to be made, but\r
+                 the script is ready for public testing.  Please feel\r
+         free to email me your comments/suggestions.  Thanks!\r
+  May 8, 2004  - Alpha release.  Not released to public.\r
+\r
+  * Configuration *\r
+  There aren't (yet) any configuration variables for this script.    */\r
+\r
+//----------------------------------------------------------------------\r
+\r
+## [[hidden-email:target]]\r
+Markup('hidden-email','<links',\r
+  "/\\[\\[hidden-email:([^\\s$UrlExcludeChars]*)\\s*\\]\\]($SuffixPattern)/e",\r
+    "eProtectDecode('$1','')");\r
+\r
+## [[hidden-email:target | text]]\r
+Markup('hidden-email|','<hidden-email',\r
+  "/\\[\\[hidden-email:([^\\s$UrlExcludeChars]*)\\s*\\|\\s*(.*?)\\s*\\]\\]($SuffixPattern)/e",\r
+    "eProtectDecode('$1','$2')");\r
+\r
+## [[ text -> hidden-email:target]]\r
+Markup('-hidden-email','<hidden-email',\r
+  "/\\[\\[(.*?)\\s*-+&gt;\\s*hidden-email:([^\\s$UrlExcludeChars]*)\\s*\\]\\]($SuffixPattern)/e",\r
+    "eProtectDecode('$2','$1')");\r
+\r
+## Add own function in array $EditFunctions before ReplaceOnSave, so it is called, when saving is performed.\r
+array_splice ($EditFunctions, array_search('ReplaceOnSave',$EditFunctions), 1,\r
+  array('eProtectEncode','ReplaceOnSave'));\r
+\r
+## Add decoding script to Header\r
+$HTMLHeaderFmt['eProtect']= "\n<script type='text/JavaScript'>\n<!--\nNix={map:null,convert:function(a){Nix.init();var s='';for(i=0;i<a.length;i++){var b=a.charAt(i);s+=((b>='A'&&b<='Z')||(b>='a'&&b<='z')?Nix.map[b]:b);}return s;},init:function(){if(Nix.map!=null)return;var map=new Array();var s='abcdefghijklmnopqrstuvwxyz';for(i=0;i<s.length;i++)map[s.charAt(i)]=s.charAt((i+13)%26);for(i=0;i<s.length;i++)map[s.charAt(i).toUpperCase()]=s.charAt((i+13)%26).toUpperCase();Nix.map=map;},decode:function(a){document.write(Nix.convert(a));}}\n//-->\n</script>\n";\r
+\r
+//----------------------------------------------------------------------\r
+function eProtectStrRecode ($s) {\r
+/* str_rot13, extended to recode digits and @#. */\r
+//----------------------------------------------------------------------\r
+  return strtr ($s,\r
+    'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ',\r
+    'nopqrstuvwxyzabcdefghijklmNOPQRSTUVWXYZABCDEFGHIJKLM');\r
+}\r
+\r
+//----------------------------------------------------------------------\r
+function eProtectDecode ($CompressedEmailAddress,$AlternateText) {\r
+//----------------------------------------------------------------------\r
+  $email = $CompressedEmailAddress;\r
+  $html = "\n<!--eProtect-->\n";\r
+  if ($AlternateText=='')\r
+    $html .= "<script type='text/JavaScript'>\n<!--\nNix.decode" .\r
+      "(\"<n pynff='heyyvax' uers='znvygb:$email'>$email</n>\");" . "\n//-->\n</script>";\r
+  else\r
+    $html .= "<script type='text/JavaScript'>\n<!--\nNix.decode" .\r
+      "(\"<n pynff='heyyvax' uers='znvygb:$email'>\");" . "\n//-->\n</script>" . $AlternateText . "<script\r
+      type='text/JavaScript'><!--\nNix.decode" .\r
+      "(\"</n>\");" . "\n//-->\n</script>";\r
+  $html .= "\n<!--/eProtect-->\n";\r
+  return Keep($html);\r
+}\r
+\r
+//----------------------------------------------------------------------\r
+function eProtectEncode ($pagename,&$page,&$new) {\r
+//----------------------------------------------------------------------\r
+  global $KeepToken, $KPV, $UrlExcludeChars;\r
+  if (!@$_POST['post']) return; // only Encode, when posting\r
+  $text = $new['text'];\r
+  $text = preg_replace_callback("/\\[\\=(.*?)\\=\\]/s", create_function('$str', 'return Keep($str[0]);'), $text);    // extract the [= .. =] and temporarily store in $KPV[]\r
+#  $text = preg_replace_callback("/\\[\\[mailto:([^\\s$UrlExcludeChars]*)/", create_function('$m','return "[[hidden-email:".trim(eProtectStrRecode($m[1]));'), $text);\r
+  $text = preg_replace_callback("/\\[\\[(.*?)mailto:([^\\s$UrlExcludeChars]*)(.*?)\\]\\]/", create_function('$m','return "[[".$m[1]."hidden-email:".trim(eProtectStrRecode($m[2])).$m[3]."]]";'), $text);\r
+  $text = preg_replace("/$KeepToken(\\d+)$KeepToken/e",'$KPV[$1]',$text);   // put the [= .. =] back in to the text\r
+  $new['text'] = $text;\r
+}\r
+\r
+?>
\ No newline at end of file
index 06c619a..566059c 100644 (file)
@@ -1,8 +1,6 @@
 <!--HeaderText-->
 <!--/HeaderText-->
 <!--PageLeftFmt-->
-<!--wiki:$Group.SideBar $SiteGroup.SideBar-->
 <!--/PageLeftFmt-->
-<!--wiki:$Group.PageActions $SiteGroup.PageActions-->
+<!--wiki: $SiteGroup.PageActions -->
 <!--PageText-->
-
index 1dc2ebc..3d9d94c 100644 (file)
@@ -1,8 +1,14 @@
 <?php
 
-$AuthFunction = "AuthPlatal";
+$AuthFunction = 'AuthPlatal';
 
-function authPerms($pagename,$key,$could=false)
+$Conditions['logged']      = logged();
+$Conditions['identified']  = identified();
+$Conditions['has_perms']   = has_perms();
+$Conditions['public']      = 'true';
+$Conditions['only_public'] = !identified();
+
+function authPerms($pagename, $key, $could=false)
 {
     $words = explode(' ', $key);
     $auth  = false;
@@ -16,10 +22,10 @@ function authPerms($pagename,$key,$could=false)
         $parts = explode(':', $word);
         $cond = $parts[0];
         $param = $parts[1];
-        if ($cond == "identified" && $could) {
-            $cond = "logged";
+        if ($cond == 'identified' && $could) {
+            $cond = 'logged';
         }
-        $iauth = CondText($pagename, "if ".$cond." ".$param, true);
+        $iauth = CondText($pagename, 'if '.$cond.' '.$param, true);
         if ($and) {
             $auth &= $iauth;
         } else {
@@ -86,7 +92,7 @@ function AuthPlatal($pagename, $level, $authprompt, $since)
     global $page;
     new_skinned_page('', AUTH_MDP); 
     if (has_perms()) {
-        $page->trig("Erreur : page Wiki inutilisable sur plat/al");
+        $page->trig('Erreur : page Wiki inutilisable sur plat/al');
     } else {
         $page->trig("Tu n'as pas le droit d'accéder à ce service");
     }
@@ -94,10 +100,4 @@ function AuthPlatal($pagename, $level, $authprompt, $since)
     return 1;
 }
 
-$Conditions['logged'] = 'logged()';
-$Conditions['identified'] = 'identified()';
-$Conditions['has_perms'] = 'has_perms()';
-$Conditions['public'] = 'true';
-$Conditions['only_public'] = '!identified()';
-
 ?>