6bd730b604c63d2abc54ef2614e2078709015f8f
[atutor.git] / mods / wiki / plugins / meta / block_chinese.php
1 <?php
2 /*
3    This plugin blocks any contribution that contains chinese characters
4    (as HTML entities). This is not meant to be impolite or discriminate
5    Chinese, but because there are a few very aggressive web/link spammers
6    this is currently the best workaround for primarily English sites.
7    
8    IMPORTANT: this plugin must be loaded together with (before) the 
9    'fragments/head/meta.php' code snippets.
10 */
11
12 $ewiki_plugins["handler"][] = "ewiki_block_cjk_spam";
13 $ewiki_plugins["view_final"][] = "ewiki_warn_cjk_spam";
14
15
16 function ewiki_cjk_entities($html) {
17    if (preg_match_all("/&#(x?[0-9a-f]+)/i", $html, $uu))
18    foreach ($uu[1] as $char) {
19       $char = strtolower($char);
20       if ($char[0]=="x") {
21          $char = hexdec(substr($char, 1));
22       }
23       $char = (int) $char;
24       if ( ($char >= 0x3200) && ($char <= 0x9999)  // CJK A+Unified+..
25         or ($char >= 0x2E80) && ($char <= 0x303F) )
26       {
27          return(true);
28       }
29    }
30    return(false);
31 }
32
33
34 function ewiki_block_cjk_spam($id, &$data, $action) {
35    global $ewiki_cjk;
36    $ewiki_cjk = 0;
37    if (ewiki_cjk_entities($data["content"])) {
38       $ewiki_cjk = 1;
39       $data["meta"]["meta"]["robots"] = "NOINDEX,NOFOLLOW,NOPAGERANK,NOCOUNT,NOARCHIVE";
40    }
41 }
42
43 function ewiki_warn_cjk_spam(&$o, $id, &$data, $action) {
44    global $ewiki_cjk;
45    if ($ewiki_cjk) {
46       $o = <<<END
47 <div class="system-message" style="background:#883333; color:#ffffff; border:2px solid #554444; padding:3px; margin:5px;">
48   <big><b style="color:#ffffcc">&lt;META name="ROBOTS" content="<blink>NOINDEX</blink>,NOFOLLOW"&gt;</b></big>
49   <br>
50   <b>ATTENTION</b>: This page will <u>no longer be indexed by Google</u> and other
51   search engines. This is because it contains Chinese characters, and we have
52   been link-spammed too much in the last time. Apologies if you just wanted
53   to check it out.
54 </div>\n
55 $o
56 END;
57    }
58 }
59
60 ?>