changed git call from https to git readonly
[atutor.git] / mods / wiki / plugins / admin / page_searchcache.php
1 <?php
2
3 /*
4   This plugin allows to generate text database entries for static/internal
5   pages, so those can later be found by the PageSearch or PowerSearch
6   functions. It may be useful to run it on a regular time period. You
7   certainly need to set 'max_execution_time' limit in the php.ini up.
8
9   The function is crippled to run in $ewiki_ring==0 only (if an admin is
10   logged in). Either edit yoursite.php to detect the admin user or change
11   that line of code herein to make this admin function available to the
12   public.
13 */
14  
15
16 $ewiki_plugins["page"]["SearchCache"] = "ewiki_cache_generated_pages";
17
18
19 function ewiki_cache_generated_pages($id, &$data, $action) {
20
21    global $ewiki_plugins, $ewiki_ring;
22
23    $o = ewiki_make_title($id, $id, 1);
24
25    if (empty($_REQUEST["generate_cache"])) {
26
27       $o .= "Use this page plugin/tool to generate text database entries for
28 all generated ('internal' or 'static') pages available, so those can later
29 be found using the search functions.<br /><br />";
30
31       $o .= '<form action="'.ewiki_script("",$id).'" method="POST" enctype="text/html">'
32           . '<input type="hidden" name="id" value="'.$id.'">'
33           . '<input type="submit" value="generate cache" name="generate_cache">'
34           . '</form>';
35
36    }
37    elseif (!ewiki_auth($id, $data, $action, $ring=0, "_FORCE_AUTH=1") || !isset($ewiki_ring) || ($ewiki_ring > 0)) {
38
39       if (is_array($data)) {
40          $data = "You'll need to be admin. See ewiki_auth() and _PROTECTED_MODE in the README.";
41       }
42       $o .= $data;
43
44    }
45    else {
46       unset($_REQUEST["generate_cache"]);
47
48       $o .= "generating cache versions from:<ul>\n";
49
50       foreach ($ewiki_plugins["page"] as $pid=>$pf) {
51
52 #echo "$pid:";
53
54          $d = ewiki_db::GET($pid);
55          if (empty($d) || empty($d["content"])) {
56             $d = array(
57                "id" => $pid,
58                "version" => 1,
59                "flags" => EWIKI_DB_F_TEXT,
60                "created" => time(),
61                "content" => "",
62                "meta" => "",
63                "hits" => 0,
64                "refs" => "",
65             );
66          }
67
68          $d["last_modified"] = time();
69          $d["hits"]++;
70          $d["content"] = $pf($pid, $d, "view");
71
72          //@ADD - transform <html> back to wikimarkup
73          //       here?
74
75          if (ewiki_db::WRITE($d, true)) {
76            $o .= "<li>$pid</li>\n";
77          }
78
79          unset($d);
80       }
81
82       $o .= "</ul>";
83       ewiki_log("page search cache was updated", 2);
84    }
85
86    return($o);
87 }
88
89
90 ?>