changed git call from https to git readonly
[atutor.git] / mods / wiki / plugins / meta / meta.php
1 <?php
2
3 /*
4    This makes the core of the wiki page meta/ data framework, as it
5    represents the main user interface. It places a smaller <textarea>
6    below the edit/ box, which allows to add meta data for the edited
7    page.
8    Such meta data is evaluated by other plugins to group pages together
9    or provide additional hints for users or for handling them in a
10    specialized way.
11 */
12
13
14 #-- settings
15 $ewiki_config["meta"]["rename_tag"] = array(
16    "description"=>"teaser",  "desc"=>"teaser",
17    "cat"=>"category",
18    "back"=>"prev",
19    "forward"=>"next",  "forw"=>"next",
20    "up"=>"parent",
21 #  "pageno"=>"num",  "no"=>"num",  "number"=>"num",  "n"=>"num",
22 );
23 $ewiki_config["meta"]["keep_string"] = array(
24    "teaser", "title",
25 );
26
27
28 define("EWIKI_UP_METABOX", "edit_meta_data");
29 $ewiki_t["de"]["meta data"] = "Meta-Data";
30
31
32 #-- meta <textarea> 
33 $ewiki_plugins["edit_form_append"][] = "ewiki_aedit_metadata_box";
34 function ewiki_aedit_metadata_box($id, &$data, $action) {
35
36    global $ewiki_config;
37
38    #-- retrieve {meta} data
39    $val = "";
40    if ($m = $data["meta"]["meta"]) foreach ($m as $id => $line) {
41       if (!in_array($id, $ewiki_config["meta"]["keep_string"])) {
42          $line = preg_replace("/,\s*/", ", ", $line);
43       }
44       $val .= "$id: " . $line . "\n";
45    }
46
47    #-- show it up in an edit box
48    $var = EWIKI_UP_METABOX;
49    $val = htmlentities($val);
50    return(ewiki_t(<<< EOT
51 <br />
52  _{meta data}:<br /><textarea rows="4" cols="50" name="$var">$val</textarea>
53 <br />
54 EOT
55    ));
56 }
57
58
59 #-- save into db {meta}{meta} field
60 $ewiki_plugins["edit_save"][] = "ewiki_edit_save_metadata";
61 function ewiki_edit_save_metadata(&$save, &$old_data) {
62
63    global $ewiki_config;
64
65    #-- clean old meta array (to allow for entry removal)
66    unset($save["meta"]["meta"]);
67
68    if ($val = trim($_REQUEST[EWIKI_UP_METABOX])) {
69
70       #-- walk through specified entries
71       preg_match_all('/^(\w+):(.+(?:(?:\n[^:\n]+)*\n)?)/m', $val, $uu);
72       if (count($uu[1])) {
73          foreach ($uu[1] as $i=>$name) {
74
75             #-- entry name
76             $name = strtolower($name);
77             if ($new = $ewiki_config["meta"]["rename_tag"][$name]) {
78                $name = $new;
79             }
80
81             #-- clean up
82             if (!in_array($id, $ewiki_config["meta"]["keep_string"])) {
83                $str = preg_replace("/\s*,\s*/", ",", trim($uu[2][$i]));
84             }
85
86             #-- store (also empty strings)
87             $save["meta"]["meta"][$name] = $str;
88       }  }
89    }
90 }
91
92
93 ?>