changed git call from https to git readonly
[atutor.git] / mods / wiki / plugins / aview / threads.php
1 <?php
2
3 /*
4     Thread plugin for ewiki
5     
6     Add this plugin after aview_posts to enable threads.  Threads are sub pages 
7     which are named as $id.EWIKI_THREAD_SEPARATOR.{thread name}.  Threads may or
8     may not be edited but should definately have posts added to them.  This 
9     plugin is incomplete.  It still lacks a title_transform for threads and 
10     other features.
11     
12     by AndyFundinger (http://erfurtwiki.sourceforge.net/?id=AndyFundinger)
13 */
14
15 $ewiki_plugins["view_append"][]="ewiki_view_append_threads";
16 $ewiki_plugins["action"]["addthread"] = "ewiki_add_thread";
17
18 $ewiki_t["en"]["THREADS"]= "Threads";
19 $ewiki_t["en"]["NEWTHREAD"]= "Create new thread";
20 define ('EWIKI_THREAD_SEPARATOR','_THREAD_');
21
22 function isThread($id){
23     return((strpos($id,EWIKI_THREAD_SEPARATOR)!==FALSE)&&!isPost($id));
24 }
25
26 function ewiki_view_append_threads($id, $data, $action) {
27     if(isThread($id)) return("");
28
29     $result = ewiki_db::SEARCH("id", $id.EWIKI_THREAD_SEPARATOR);
30     while ($row = $result->get()) {
31             if(!isPost($row["id"])){
32                 $pages[$row["id"]] = "";
33                 }
34     }
35     
36     if(0!=count($pages)){ 
37         $o = "<div class='wiki_threads'><small>".ewiki_t('THREADS').":</small><br />";
38         $o .= ewiki_list_pages($pages)."</div>\n";    
39     }
40
41     $o .="<form action='".ewiki_script('addthread', $id)."' method='POST'>".
42         ewiki_t("NEWTHREAD").":  <input type='text' name='threadname'>".
43         "<input type='submit' value='Add Thread'>".
44         "</form>";
45         
46     return("<div class='wiki aview threads'>".$o.'</div>');
47 }
48
49
50 //Adding a thread is just creating a specially named page.
51 //We create a blank page and then edit a post off of it
52 function ewiki_add_thread($id, $data, $action){
53         global $ewiki_plugins;
54
55         $id=$id.EWIKI_THREAD_SEPARATOR.$_REQUEST['threadname'];
56
57         $save = array(
58                 "id" => $id,
59                 "version" => 1,
60                 "flags" => '',
61                 "content" => "   ",
62                 "author" => ewiki_author(),
63                 "lastmodified" => time(),
64                 "created" => time(),
65                 "meta" => array('isThread'=>'1'),
66                 "hits" => 0,
67                 "refs" => ""
68         );
69
70         if (!ewiki_db::WRITE($save)) {
71                 return(ewiki_t("ERRORSAVING"));
72         }
73
74         return(ewiki_add_post($id, array(), 'addpost'));
75 }
76
77 ?>