/mod/wiki/lib/wiki_page.class.php

https://github.com/jarednipper/HSU-common-code · PHP · 431 lines · 184 code · 50 blank · 197 comment · 7 complexity · 3630386662ab5c09ed8779f305199e28 MD5 · raw file

  1. <?php
  2. //$Id: wiki_page.class.php,v 1.22 2008/03/14 13:12:46 gonzaloserrano Exp $
  3. /**
  4. * This file contains wiki_page class
  5. *
  6. * @author DFWiki LABS
  7. * @author Marc Alier i Forment
  8. * @author David Castro, Ferran Recio, Jordi Piguillem, UPC,
  9. * and members of DFWikiteam listed at http://morfeo.upc.edu/crom
  10. * @version $Id: wiki_page.class.php,v 1.22 2008/03/14 13:12:46 gonzaloserrano Exp $
  11. * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
  12. * @package Core
  13. */
  14. require_once ($CFG->dirroot.'/lib/dmllib.php');
  15. require_once ($CFG->dirroot.'/mod/wiki/locallib.php');
  16. define('WIKIPAGEID', 1);
  17. define('PAGERECORD', 2);
  18. class wiki_page {
  19. var $id;
  20. var $pagename;
  21. var $version;
  22. var $content;
  23. var $author;
  24. var $userid;
  25. var $created;
  26. var $lastmodified;
  27. var $refs;
  28. var $hits;
  29. var $editable;
  30. var $highlight;
  31. var $dfwiki;
  32. var $editor;
  33. var $groupid;
  34. var $ownerid;
  35. /**
  36. * Constructor of the class.
  37. *
  38. * @param integer $type. This param must be WIKIPAGEID or PAGERECORD. It is used to indicate
  39. * the type of the parameter $param.
  40. * @param integer / record $param
  41. */
  42. function wiki_page($type,$param){
  43. // If the parameter type is WIKIPAGEID, we need to obtain the record from the
  44. // database and inicialize all the attributes of the class with it's value.
  45. if ($type == WIKIPAGEID){
  46. // Get the record.
  47. $record = get_record("wiki_pages","id",$param);
  48. // Inicialize attributes with the value of the record.
  49. $this->id = $record->id;
  50. $this->pagename = $record->pagename;
  51. $this->version = $record->version;
  52. $this->content = $record->content;
  53. $this->author = $record->author;
  54. $this->userid = $record->userid;
  55. $this->created = $record->created;
  56. $this->lastmodified = $record->lastmodified;
  57. $this->refs = $record->refs;
  58. $this->hits = $record->hits;
  59. $this->editable = $record->editable;
  60. $this->highlight = $record->highlight;
  61. $this->dfwiki = $record->dfwiki;
  62. $this->editor = $record->editor;
  63. $this->groupid = $record->groupid;
  64. $this->ownerid = $record->ownerid;
  65. // If the parameter type is PAGERECORD, we already have the record, so we only need to
  66. // inicialize all the attributes of the class with it's value.
  67. } else if ($type == PAGERECORD){
  68. // Inicialize the attributes with the value of the record.
  69. $this->id = isset($param->id) ? $param->id : null;
  70. $this->pagename = $param->pagename;
  71. $this->version = $param->version;
  72. $this->content = $param->content;
  73. $this->author = $param->author;
  74. $this->userid = $param->userid;
  75. $this->created = $param->created;
  76. $this->lastmodified = $param->lastmodified;
  77. $this->refs = $param->refs;
  78. $this->hits = $param->hits;
  79. $this->editable = $param->editable;
  80. $this->highlight = isset($param->highlight) ? $param->highlight : 0;
  81. $this->dfwiki = $param->dfwiki;
  82. $this->editor = $param->editor;
  83. $this->groupid = $param->groupid;
  84. $this->ownerid = $param->ownerid;
  85. } else{
  86. error("The parameter type must be WIKIPAGEID or PAGERECORD");
  87. }
  88. }
  89. /// Get methods
  90. /**
  91. * Database record of the wiki page.
  92. *
  93. * @return stdClass
  94. */
  95. function wiki_page_to_record() {
  96. $record = new stdClass();
  97. $record->pagename = $this->pagename;
  98. $record->version = $this->version;
  99. $record->content = $this->content;
  100. $record->author = $this->author;
  101. $record->userid = $this->userid;
  102. $record->created = $this->created;
  103. $record->lastmodified = $this->lastmodified;
  104. $record->refs = $this->refs;
  105. $record->hits = $this->hits;
  106. $record->editable = $this->editable;
  107. $record->highlight = $this->highlight;
  108. $record->dfwiki = $this->dfwiki;
  109. $record->editor = $this->editor;
  110. $record->groupid = $this->groupid;
  111. $record->ownerid = $this->ownerid;
  112. return $record;
  113. }
  114. /**
  115. * Id of the wiki page.
  116. *
  117. * @return integer
  118. */
  119. function id() {
  120. return $this->id;
  121. }
  122. /**
  123. * Wiki page name. It strips the slashes.
  124. *
  125. * @return string
  126. */
  127. function page_name(){
  128. return stripslashes($this->pagename);
  129. }
  130. /**
  131. * Version number of the wiki page.
  132. *
  133. * @return integer
  134. */
  135. function version(){
  136. return $this->version;
  137. }
  138. /**
  139. * Integral content of the wiki page. It strips the slashes.
  140. *
  141. * @return string
  142. */
  143. function content(){
  144. return stripslashes($this->content);
  145. }
  146. /**
  147. * User name of the author of version of a wiki page.
  148. *
  149. * @return string
  150. */
  151. function author(){
  152. return $this->author;
  153. }
  154. /**
  155. * User id of the author of version of a wiki page.
  156. *
  157. * @return integer
  158. */
  159. function user_id(){
  160. return $this->userid;
  161. }
  162. /**
  163. * Absolute time in seconds since first version of the wiki page.
  164. *
  165. * @return integer
  166. */
  167. function created(){
  168. return $this->created;
  169. }
  170. /**
  171. * Absolute time in seconds of the last time wiki page has been modified. That is time of last version.
  172. *
  173. * @return integer
  174. */
  175. function last_modified(){
  176. return $this->lastmodified;
  177. }
  178. /**
  179. * List of links inside the wiki page.
  180. *
  181. * @return string. This list is save with character '|' which separates the name of the destination page.
  182. */
  183. function refs(){
  184. return $this->refs;
  185. }
  186. /**
  187. * Number of times that wiki page has been visited (hits).
  188. *
  189. * @return integer
  190. */
  191. function hits(){
  192. return $this->hits;
  193. }
  194. /**
  195. * Whether the wiki page can be edit by students.
  196. *
  197. * @return boolean
  198. */
  199. function editable(){
  200. return $this->editable != 0;
  201. }
  202. /**
  203. * Whether the wiki page is in highlight.
  204. *
  205. * @return boolean
  206. */
  207. function high_light(){
  208. return $this->highlight != 0;
  209. }
  210. /**
  211. * dfwiki number of the table 'mdl_wiki' where is the wiki intance.
  212. *
  213. * @return integer
  214. */
  215. function dfwiki(){
  216. return $this->dfwiki;
  217. }
  218. /**
  219. * Wiki page editor name. Only 3 diferent names: 'dfwiki','ewiki','htmleditor'.
  220. *
  221. * @return string
  222. */
  223. function editor(){
  224. return $this->editor;
  225. }
  226. /**
  227. * Group id which wiki page belongs.
  228. *
  229. * @return integer
  230. */
  231. function group_id(){
  232. return $this->groupid;
  233. }
  234. /**
  235. * Wiki page owner id.
  236. *
  237. * @return integer
  238. */
  239. function owner_id(){
  240. return $this->ownerid;
  241. }
  242. ///Set Methods
  243. /**
  244. * Sets the id of the wiki page
  245. *
  246. * @param integer $id. New id to asign.
  247. */
  248. function set_id($id){
  249. $this->id = $id;
  250. }
  251. /**
  252. * Sets the name of the wiki page. Adds slashes to the page name.
  253. *
  254. * @param string $page_name. New name to asign to the wiki page.
  255. */
  256. function set_page_name($page_name){
  257. $this->pagename = addslashes($page_name);
  258. }
  259. /**
  260. * Sets the version of the wiki page.
  261. *
  262. * @param int $version. New number of version of the wiki page.
  263. */
  264. function set_version($version){
  265. $this->version = $version;
  266. }
  267. /**
  268. * Adds 1 to the actual version of the wiki page.
  269. *
  270. * @return integer. Returns new number of version.
  271. */
  272. function inc_version(){
  273. $this->version = $this->version + 1;
  274. return $this->version;
  275. }
  276. /**
  277. * Sets the integral content of the wiki page.
  278. * Updates the attribute refs with the internal links of the wikipage.
  279. * Adds slashes to the page name.
  280. *
  281. * @param string $content. New content to asign to the wiki page.
  282. */
  283. function set_content($content){
  284. // clean internal links of the page
  285. $links_refs = wiki_sintax_find_internal_links($content);
  286. $links_clean = wiki_clean_internal_links($links_refs);
  287. $content = wiki_set_clean_internal_links($content, $links_refs, $links_clean);
  288. $this->refs = wiki_internal_link_to_string($links_clean);
  289. $this->content = addslashes($content);
  290. }
  291. /**
  292. * Sets the user name of the author of version of a wiki page.
  293. *
  294. * @param string $author. This param is the new name of the author of the wiki.
  295. */
  296. function set_author($author){
  297. $this->author = $author;
  298. }
  299. /**
  300. * Sets the user id of the author of version of a wiki page.
  301. *
  302. * @param integer $user_id. This param is the id to asign to the user id.
  303. */
  304. function set_user_id($user_id){
  305. $this->userid = $user_id;
  306. }
  307. /**
  308. * Sets the absolute time in seconds since first version of the wiki page.
  309. *
  310. * @param integer $created. This param is the new absolut time in seconds to asign to wiki page created time.
  311. */
  312. function set_created($created){
  313. $this->created = $created;
  314. }
  315. /**
  316. * Sets the absolute time in seconds of the last time wiki page has been modified. That is time of last version.
  317. *
  318. * @param integer $last_modified. This param is the new absolut time in seconds of the last modification of the
  319. * wiki page.
  320. */
  321. function set_last_modified($last_modified){
  322. $this->lastmodified = $last_modified;
  323. }
  324. /**
  325. * Sets the list of links inside the wiki page.
  326. *
  327. * @param string $refs. This param contains the news references of the wiki page.
  328. */
  329. function set_refs($refs){
  330. $this->refs = $refs;
  331. }
  332. /**
  333. * This function adds a reference to the list of links inside wiki page.
  334. *
  335. * @param string $ref. This param is the reference to add to the wiki page.
  336. */
  337. function add_refs($ref){
  338. $this->refs= $this->refs + "|" + $ref;
  339. }
  340. /**
  341. * This function sets number of times that wiki page has been visited (hits).
  342. *
  343. * @param integer $hits.
  344. */
  345. function set_hits($hits){
  346. $this->hits = $hits;
  347. }
  348. /**
  349. * This function sets whether the wiki page can be edit by students
  350. *
  351. * @param boolean $editable.
  352. */
  353. function set_editable($editable){
  354. $this->editable = $editable;
  355. }
  356. /**
  357. * This function sets the group id which wiki page belongs
  358. *
  359. * @param integer $group_id. This param is the new id of the wiki page group.
  360. */
  361. function set_group_id($group_id){
  362. $this->groupid = $group_id;
  363. }
  364. /**
  365. * This function sets wiki page owner id.
  366. *
  367. * @param integer $owner_id. This param is the new if of the wiki page owner.
  368. */
  369. function set_owner_id($owner_id){
  370. $this->ownerid = $owner_id;
  371. }
  372. /**
  373. * Get pageid.
  374. *
  375. * @return wiki_pageid
  376. */
  377. function pageid() {
  378. return new wiki_pageid($this->dfwiki, $this->pagename, null. $this->groupid, $this->ownerid);
  379. }
  380. }
  381. ?>