changed git call from https to git readonly
[atutor.git] / mods / wiki / plugins / feature / appendwrite.php
1 <?php
2
3 /*
4    If a page has the _APPENDONLY and _WRITEABLE flags set, then this plugin
5    allows users to edit anything after the 16+-minus-signs or double
6    horizontal bar. Moderators and admins can however still edit the full
7    page.
8    (One could also call this plugin the "PartialLock support".)
9 */
10
11 define("EWIKI_APPENDWRITE_AUTOLOCK", 1);
12
13 $ewiki_plugins["handler"][] = "ewiki_handler_appendwrite";
14 $ewiki_plugins["edit_hook"][] = "ewiki_edit_hook_appendwrite";
15 $ewiki_plugins["edit_save"][] = "ewiki_edit_save_appendwrite";
16
17
18
19 /* 
20    merges the double horizontal bar,
21    this was too late for ["format_source"]
22 */
23 function ewiki_handler_appendwrite($id, &$data, $action) {
24
25    define("EWIKI_DB_F_APPENDWRITE", EWIKI_DB_F_APPENDONLY|EWIKI_DB_F_WRITEABLE);
26
27    if (($action=="view") && ($data["flags"] & EWIKI_DB_F_APPENDWRITE)) {
28       $data["content"] = preg_replace("/----\n----/", "--------", $data["content"], 1);
29    }
30 }
31
32
33
34 /*
35    searches for the page separator and returns its position,
36    and eventually adds one
37 */
38 function ewiki_appendwrite_split(&$content) {
39    
40    if ($end = strpos($content, "----------------")) {
41       $end += 10;
42    }
43    if ($end1 = strpos($content, "----\n----")) {
44       $end1 += 5;
45       if ($end1 < $end) {
46          $end = $end1;
47       }
48    }
49
50    if ($end !== false) {
51       if (!($end = strpos($content, "\n", $end))) {
52          $content .= "\n";
53          $end = strlen($content);
54       }
55    }
56    elseif (EWIKI_APPENDWRITE_AUTOLOCK) {
57       $content .= "\n----------------\n\n";
58       $end = strlen($content);
59    }
60
61    return($end);
62 }
63
64
65 /*
66    makes users only see the editable part in
67    edit/ pages
68 */
69 function ewiki_edit_hook_appendwrite($id, &$data, &$hpdata) {
70
71    global $ewiki_t, $ewiki_ring;
72    
73    if (($data["flags"] & EWIKI_DB_F_APPENDWRITE) && (!EWIKI_PROTECTED_MODE || ($ewiki_ring >= 2))) {
74       if ($data["version"] && strlen($data["content"]) && !$_REQUEST["content"]) {
75          if ($end = ewiki_appendwrite_split($data["content"])) {
76
77             #-- only show the editable part in the edit box
78             $data["content"] = substr($data["content"], $end);
79
80             # change "edit" title to "append"
81             foreach (array_keys($ewiki_t) as $LANG) {
82                if ($ewiki_t[$LANG]["APPENDTOPAGE"]) {
83                   $ewiki_t[$LANG]["EDITTHISPAGE"] = &$ewiki_t[$LANG]["APPENDTOPAGE"];
84                }
85             }
86    }  }  }
87 }
88
89
90
91 /*
92    merges the not-editable part, with the submitted
93    changes to the appendonly/writable part
94 */
95 function ewiki_edit_save_appendwrite(&$save, &$old) {
96
97    global $ewiki_ring;
98
99    if (($old["flags"] & EWIKI_DB_F_APPENDWRITE) && (!EWIKI_PROTECTED_MODE || ($ewiki_ring >= 2))) {
100       if ($old["version"] && strlen($old["content"])) {
101          if ($end = ewiki_appendwrite_split($old["content"])) {
102
103             #-- merge the old not-editable-part with the new append-part
104             $save["content"] = substr($old["content"], 0, $end+1)
105                              . $save["content"];
106
107    }  }  }
108 }
109
110
111
112 ?>