changed git call from https to git readonly
[atutor.git] / mods / wiki / plugins / linking / new_nofollow.php
1 <?php
2 /*
3    With a rel="NOFOLLOW" attribute on hyperlinks <a> tag, you'll prevent
4    additional page rank bonus and thus any interest for link spammers to
5    target your Wiki (see [doc/LinkSpammers]). This plugin is a bit more
6    clueful in only adding this flag to fresh/new links.
7
8    It looks up the (at least) two weeks older version of a page to make
9    a decision. That isn't all too slow actually, but you could use the
10    dumber variant "plugins/linking/a_nofollow" alternatively.
11 */
12
13 $ewiki_plugins["fromat_prepare_linking"][] = "ewiki_prepare_linking_find_old_links";
14 $ewiki_plugins["link_final"][] = "ewiki_linking_nofollow_flag_fresh_urls";
15
16
17 #-- searches links from older page version
18 function ewiki_prepare_linking_find_old_links(&$src) {
19    global $ewiki_config, $ewiki_id, $ewiki_data;
20       
21    #-- prepare
22    $ewiki_config["old_version_links"] = array();
23    $max_time = time() - 2*7 * 24*60*60;
24    if ($ewiki_data["lastmodified"] <= $max_time) {
25       return;
26    }
27    
28    #-- search version which is at least two weeks older
29    $version = $ewiki_data["version"] - 1;
30    while ($version > 1) {
31       $data = ewiki_db::GET($ewiki_id, $version-1);
32       if ($data && ($data["lastmodified"] <= $max_time)) {
33          break;
34       }
35    }
36    if ($data) {
37       $ewiki_config["old_version_links"] = explode("\n", trim($data["refs"]));
38    }
39 }
40
41
42 #-- adds NOFOLLOW attribute to "fresh" urls
43 function ewiki_linking_nofollow_flag_fresh_urls(&$str, $type, $href, $title, &$states) {
44    global $ewiki_config;
45    if (strpos($href, "://") && !in_array($href, $ewiki_config["old_version_links"])) {
46       $states["xhtml"]["rel"] = "NOFOLLOW , NOPAGERANK , NOCOUNT";
47    }
48 }
49
50 ?>