3 # this plugin appends a class of wiki pages to the bottom of the
4 # current page this will grow/merge into or support the forums
7 # you could alternatively define EWIKI_AUTOVIEW to 0, and call the
8 # ewiki_posts() wrapper function anywhere on yoursite.php
11 $ewiki_t["en"] = array_merge($ewiki_t["en"], array(
12 "EDITTHISPOST" => "Edit This Post",
13 "INFOABOUTPOST" => "Information about post",
14 "COMPVERPOST" => "See Changes"
18 $ewiki_config['posts_action_links'] = array_merge(array(
19 "edit" => "EDITTHISPOST",
20 "info" => "INFOABOUTPOST",
21 "diff" => "COMPVERPOST",
23 ), $ewiki_config['posts_action_links']);
25 if (!defined("EWIKI_AUTOVIEW") || EWIKI_AUTOVIEW) {
26 $ewiki_plugins["view_append"]['view_append_posts'] = "ewiki_view_append_posts";
29 $ewiki_t["en"]["POSTS"] = "posts";
30 $ewiki_t["en"]["POST"] = "Post: ";
31 $ewiki_t["en"]["ADDPOST"] = "Add a post";
32 $ewiki_t["en"]["TOO_MANY_POSTS"] = 'We are sorry. The maximum number of posts has been exceeded.<br /><br />Return to [$id]';
34 $ewiki_config["action_links"]["view"]["addpost"] = $ewiki_t["en"]["ADDPOST"];
36 $ewiki_plugins["action"]["addpost"] = "ewiki_add_post";
37 $ewiki_plugins["handler"][] = 'ewiki_adjust_thread_controls';
38 $ewiki_plugins["handler"][] = 'ewiki_view_post_parent';
40 define ('EWIKI_POST_SEPARATOR','_POST');
41 define("EWIKI_POSTID_PARSE_REGEX",'#(.*)'.preg_quote(EWIKI_POST_SEPARATOR) .'(\d{3})'.'#');
42 define ('EWIKI_VIEWPOSTACTION','view');
44 function ewiki_view_post_parent($id, $data, $action){
45 global $ewiki_plugins;
47 if(!preg_match(EWIKI_POSTID_PARSE_REGEX,$id,$matches)||($action!='view'))
50 //Authentication for the new page is handled within this call.
51 $o=ewiki_page('view/'.$matches[1]);
53 //page_final plugins have been run, unset them
54 unset($ewiki_plugins["page_final"]);
59 function ewiki_adjust_thread_controls($id, $data, $action){
67 //Move add post action to first position in control links
68 $temp = $ewiki_config["action_links"]['view']['addpost'];
69 unset($ewiki_config["action_links"]['view']['addpost']);
70 $ewiki_config["action_links"]['view'] = array_merge(array('addpost'=>$temp),$ewiki_config["action_links"]['view']);
73 function ewiki_add_post($id, $data, $action){
74 global $ewiki_plugins,$ewiki_config;
76 $postNum=getPostCount($id)+1;
77 $postNum=str_pad($postNum, 3, "0", STR_PAD_LEFT);
80 $o=ewiki_format(ewiki_t("TOO_MANY_POSTS", array("id"=>$id)));
82 $id=$id.EWIKI_POST_SEPARATOR.($postNum);
83 $ewiki_config["create"] = $id;
84 //echo("Calling edit function $id");
85 $o=$ewiki_plugins["action"]["edit"]($id,array("id"=>$id) ,$action);
91 function ewiki_view_append_posts($id, $data, $action) {
92 global $ewiki_plugins,$ewiki_config;
94 ## Since this function calls ewiki_page_view it must disable itself when it is called
95 ## I do this by having it set separate view_append and view final actions for posts
96 ## but at a minimum it removes itself
98 $std_view_append=$ewiki_plugins["view_append"];
99 $std_view_final=$ewiki_plugins["view_final"];
100 $std_action_links=$ewiki_config["action_links"]["view"];
101 $thread_page_title=$GLOBALS["ewiki_title"];
103 if(!isset($ewiki_config['posts_view_append'])){
104 unset($ewiki_plugins["view_append"]['view_append_posts']);
106 $ewiki_plugins["view_append"]=$ewiki_config['posts_view_append'];
109 if(isset($ewiki_config['posts_view_final'])){
110 $ewiki_plugins["view_final"]=$ewiki_config['posts_view_final'];
113 if(!isset($ewiki_config['posts_action_links'])){
114 unset($GLOBALS['ewiki_config']["action_links"]["view"]["addpost"]);
116 $ewiki_config["action_links"]["view"]=$ewiki_config['posts_action_links'];
119 unset($_REQUEST["thankyou"]); // Prevent thank you message from appearing in the menu
123 * Code for the new database layer */
124 $result = ewiki_db::SEARCH("id", $id.'_POST');
128 while ($row = $result->get()) {
129 if(preg_match('#_POST(\d{3})#', $row["id"],$matches = array())){
130 $ord[$matches[1]] = $row['id'];
135 foreach ($ord as $postNum => $id) {
136 $GLOBALS["ewiki_title"]=ewiki_t('POST').$postNum;
138 $row = ewiki_db::GET($id);
141 if (EWIKI_PROTECTED_MODE) {
142 if (!ewiki_auth($id, $row, EWIKI_VIEWPOSTACTION, $ring=false, $force=0)) {
147 $postOut = ewiki_page_view($id, $row, EWIKI_VIEWPOSTACTION);
148 ewiki_page_css_container($postOut , $id, $row, $oo=EWIKI_VIEWPOSTACTION);
152 ## Restore normal actions
153 $ewiki_plugins["view_append"]= $std_view_append;
154 $ewiki_plugins["view_final"]= $std_view_final;
155 $ewiki_config["action_links"]["view"]=$std_action_links;
156 $GLOBALS["ewiki_title"]=$thread_page_title;
158 return("<div class='wiki aview posts'>".$o.'</div>');
161 function isPost($id){
162 return(preg_match(EWIKI_POSTID_PARSE_REGEX,$id));
164 function getPostNumber($id){
165 preg_match(EWIKI_POSTID_PARSE_REGEX,$id,$match=array());
169 function getPostCount($id){
171 * Code for the new database layer*/
175 $scan = $id.EWIKI_POST_SEPARATOR; //Should I escape $id here?
176 $result = ewiki_db::SEARCH("id", $scan);
177 while ($row = $result->get()) {
178 preg_match('#_POST(\d{3})#', $row["id"],$matches=array($matches));
179 $ord[$row["id"]] = $matches[1];
185 function posts_exist($always=false) {
186 $id = $GLOBALS["ewiki_id"];
188 $result = $always || ($id)
189 && ($result = ewiki_db::SEARCH("id", $id.'_POST'))
190 && ($result->count());
191 return( ($id) && ($id != EWIKI_PAGE_CALENDAR) && ($id != EWIKI_PAGE_YEAR_CALENDAR)
193 && empty($_REQUEST["year"]) && $result );