Kabano is a PHP web application listing alpine huts. https://kabano.org/
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

d.wiki.php 7.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. <?
  2. namespace Kabano;
  3. /**********************************************************
  4. ***********************************************************
  5. **
  6. ** This class is to manage a wiki page object
  7. **
  8. ***********************************************************
  9. **********************************************************/
  10. require_once($config['third_folder']."Md/MarkdownExtra.inc.php");
  11. class WikiPage
  12. {
  13. public $id = 0;
  14. public $permalink = 0;
  15. public $version = 0;
  16. public $locale = NULL;
  17. public $creation_date = NULL;
  18. public $update_date = NULL;
  19. public $author = NULL;
  20. public $is_public = NULL;
  21. public $is_archive = NULL;
  22. public $is_commentable = NULL;
  23. public $type = "wiki";
  24. public $name = NULL;
  25. public $content = NULL;
  26. /*****
  27. ** Checks if a page at this ermalink exists and return the populated element
  28. *****/
  29. public function checkPermalink($permalink, $withArchive=0, $elementNb=0) {
  30. global $config;
  31. $con = pg_connect("host=".$config['SQL_host']." dbname=".$config['SQL_db']." user=".$config['SQL_user']." password=".$config['SQL_pass'])
  32. or die ("Could not connect to server\n");
  33. $query = "SELECT * FROM contents WHERE permalink=$1 AND type='wiki'";
  34. if($withArchive==0) {
  35. $query .= " AND is_archive=FALSE AND is_public=TRUE";
  36. }
  37. $query .= " ORDER BY update_date DESC LIMIT 1 OFFSET $2";
  38. pg_prepare($con, "prepare1", $query)
  39. or die ("Cannot prepare statement\n");
  40. $result = pg_execute($con, "prepare1", array($permalink, $elementNb))
  41. or die ("Cannot execute statement\n");
  42. pg_close($con);
  43. if(pg_num_rows($result) == 1) {
  44. $row = pg_fetch_assoc($result);
  45. $this->populate($row);
  46. return 1;
  47. }
  48. else {
  49. return 0;
  50. }
  51. }
  52. /*****
  53. ** Populate the object using raw data from SQL
  54. *****/
  55. public function populate($row) {
  56. $this->id = $row['id'];
  57. $this->permalink = $row['permalink'];
  58. $this->version = $row['version'];
  59. $this->locale = $row['locale'];
  60. $this->creation_date = $row['creation_date'];
  61. $this->update_date = $row['update_date'];
  62. $this->author = $row['author'];
  63. $this->is_public = $row['is_public'];
  64. $this->is_archive = $row['is_archive'];
  65. $this->is_commentable = $row['is_commentable'];
  66. $this->type = $row['type'];
  67. $this->name = $row['name'];
  68. $this->content = $row['content'];
  69. }
  70. /*****
  71. ** Edit a page by archiving the current one and inserting a new one ID
  72. *****/
  73. public function update() {
  74. global $config;
  75. global $user;
  76. $this->version++;
  77. $con = pg_connect("host=".$config['SQL_host']." dbname=".$config['SQL_db']." user=".$config['SQL_user']." password=".$config['SQL_pass'])
  78. or die ("Could not connect to server\n");
  79. $query = "UPDATE contents SET is_archive = TRUE WHERE permalink = $1 AND type='wiki'";
  80. pg_prepare($con, "prepare1", $query)
  81. or die ("Cannot prepare statement\n");
  82. $result = pg_execute($con, "prepare1", array($this->permalink))
  83. or die ("Cannot execute statement\n");
  84. $query = "INSERT INTO contents (permalink, version, locale, creation_date, update_date, author, is_public, is_archive, is_commentable, type, name, content) VALUES
  85. ($1, $2, $3, $4, $5, $6, TRUE, FALSE, FALSE, 'wiki', $7, $8)";
  86. pg_prepare($con, "prepare2", $query)
  87. or die ("Cannot prepare statement\n");
  88. $result = pg_execute($con, "prepare2", array($this->permalink, $this->version, $this->locale, $this->creation_date, date('r'), $this->author, $this->name, $this->content))
  89. or die ("Cannot execute statement\n");
  90. pg_close($con);
  91. error_log(
  92. date('r')." \t".$user->name." (".$user->id.") \tUPDATE \tEdit wiki page '".$this->permalink."'\r\n",
  93. 3,
  94. $config['logs_folder'].'wiki.log');
  95. }
  96. /*****
  97. ** Delete a page by archiving it
  98. *****/
  99. public function delete() {
  100. global $config;
  101. global $user;
  102. $con = pg_connect("host=".$config['SQL_host']." dbname=".$config['SQL_db']." user=".$config['SQL_user']." password=".$config['SQL_pass'])
  103. or die ("Could not connect to server\n");
  104. $query = "UPDATE contents SET is_public=FALSE WHERE permalink=$1 AND type='wiki'";
  105. pg_prepare($con, "prepare1", $query)
  106. or die ("Cannot prepare statement\n");
  107. $result = pg_execute($con, "prepare1", array($this->permalink))
  108. or die ("Cannot execute statement\n");
  109. pg_close($con);
  110. error_log(
  111. date('r')." \t".$user->name." (".$user->id.") \tDELETE \tUnpublish wiki page '".$this->permalink."'\r\n",
  112. 3,
  113. $config['logs_folder'].'wiki.log');
  114. }
  115. /*****
  116. ** Restore a page from unpublishing it
  117. *****/
  118. public function restore() {
  119. global $config;
  120. global $user;
  121. $con = pg_connect("host=".$config['SQL_host']." dbname=".$config['SQL_db']." user=".$config['SQL_user']." password=".$config['SQL_pass'])
  122. or die ("Could not connect to server\n");
  123. $query = "UPDATE contents SET is_public=TRUE WHERE permalink=$1 AND type='wiki'";
  124. pg_prepare($con, "prepare1", $query)
  125. or die ("Cannot prepare statement\n");
  126. $result = pg_execute($con, "prepare1", array($this->permalink))
  127. or die ("Cannot execute statement\n");
  128. pg_close($con);
  129. error_log(
  130. date('r')." \t".$user->name." (".$user->id.") \tRESTORE \tPublish wiki page '".$this->permalink."'\r\n",
  131. 3,
  132. $config['logs_folder'].'wiki.log');
  133. }
  134. /*****
  135. ** Create a page by archiving the current one and inserting a new one ID
  136. *****/
  137. public function insert() {
  138. global $config;
  139. global $user;
  140. $con = pg_connect("host=".$config['SQL_host']." dbname=".$config['SQL_db']." user=".$config['SQL_user']." password=".$config['SQL_pass'])
  141. or die ("Could not connect to server\n");
  142. $query = "INSERT INTO contents (permalink, version, locale, creation_date, update_date, author, is_public, is_archive, is_commentable, type, name, content) VALUES
  143. ($1, '0', $2, $3, $4, $5, TRUE, FALSE, FALSE, 'wiki', $6, $7)";
  144. pg_prepare($con, "prepare1", $query)
  145. or die ("Cannot prepare statement\n");
  146. $result = pg_execute($con, "prepare1", array($this->permalink, $this->locale, date('r'), date('r'), $user->id, $this->name, $this->content))
  147. or die ("Cannot execute statement\n");
  148. pg_close($con);
  149. error_log(
  150. date('r')." \t".$user->name." (".$user->id.") \tINSERT \tCreate new wiki page '".$this->permalink."'\r\n",
  151. 3,
  152. $config['logs_folder'].'wiki.log');
  153. }
  154. /*****
  155. ** Converts the Markdown content to HTML
  156. *****/
  157. public function md2html() {
  158. $this->content_html = \Michelf\MarkdownExtra::defaultTransform($this->content);
  159. }
  160. }
  161. /**********************************************************
  162. ***********************************************************
  163. **
  164. ** This class is to manage a wiki page object
  165. **
  166. ***********************************************************
  167. **********************************************************/
  168. class WikiPages
  169. {
  170. public $objs = array();
  171. public $number = NULL;
  172. /*****
  173. ** Checks if a page at this URL exists and return the ID
  174. *****/
  175. public function getHistory($url) {
  176. global $config;
  177. $con = pg_connect("host=".$config['SQL_host']." dbname=".$config['SQL_db']." user=".$config['SQL_user']." password=".$config['SQL_pass'])
  178. or die ("Could not connect to server\n");
  179. $query = "SELECT * FROM contents WHERE permalink=$1 AND type='wiki' ORDER BY update_date DESC";
  180. pg_prepare($con, "prepare1", $query)
  181. or die ("Cannot prepare statement\n");
  182. $result = pg_execute($con, "prepare1", array($url))
  183. or die ("Cannot execute statement\n");
  184. pg_close($con);
  185. $this->number = pg_num_rows($result);
  186. for($i = 0; $i < $this->number; $i++) {
  187. $row = pg_fetch_assoc($result, $i);
  188. $this->objs[$i] = new WikiPage;
  189. $this->objs[$i]->populate($row);
  190. }
  191. }
  192. }
  193. ?>