PageRenderTime 26ms CodeModel.GetById 9ms RepoModel.GetById 0ms app.codeStats 0ms

/elgg/mod/dokuwiki/start.php

https://bitbucket.org/rhizomatik/lorea_production/
PHP | 204 lines | 172 code | 15 blank | 17 comment | 64 complexity | 0b3dbce61f751cdeee129830a6621def MD5 | raw file
Possible License(s): GPL-3.0, GPL-2.0, BSD-3-Clause, LGPL-2.1
  1. <?php
  2. /**
  3. * Elgg dokuwiki plugin
  4. *
  5. * @package
  6. * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU Public License version 2
  7. * @author lorea
  8. * @copyright lorea
  9. * @link http://lorea.cc
  10. */
  11. function current_dokuwiki_entity($create = true) {
  12. $page_owner = page_owner();
  13. $user = get_loggedin_user();
  14. //error_log($page_owner->guid);
  15. //error_log($user->guid);
  16. if (!$page_owner)
  17. $page_owner = 0;
  18. $entities = elgg_get_entities(array('types' => 'object', 'subtypes' => 'dokuwiki', 'limit' => 1, 'owner_guid' => $page_owner));
  19. if ($entities) {
  20. $doku = $entities[0];
  21. return $doku;
  22. }
  23. elseif ($user && $create) {
  24. elgg_set_ignore_access(true);
  25. $newdoku = new ElggObject();
  26. $newdoku->access_id = ACCESS_PUBLIC;
  27. $newdoku->owner_guid = $page_owner;
  28. $newdoku->subtype = 'dokuwiki';
  29. $newdoku->container_guid = $page_owner;
  30. $newdoku->save();
  31. $acl = array();
  32. $acl[] = "# acl.auth.php";
  33. $acl[] = '# <?php exit()?\>';
  34. $acl[] = "* @ALL 0";
  35. $acl[] = "* @user 1";
  36. $acl[] = "* @member 8";
  37. $acl[] = "* @admin 16";
  38. $acl[] = "* @root 255";
  39. $newdoku->wiki_acl = implode("\n", $acl)."\n";
  40. elgg_set_ignore_access(false);
  41. return $newdoku;
  42. }
  43. }
  44. function elggdoku_recurse_copy($src,$dst) {
  45. $dir = opendir($src);
  46. @mkdir($dst);
  47. while(false !== ( $file = readdir($dir)) ) {
  48. if (( $file != '.' ) && ( $file != '..' )) {
  49. if ( is_dir($src . '/' . $file) ) {
  50. elggdoku_recurse_copy($src . '/' . $file,$dst . '/' . $file);
  51. }
  52. else {
  53. copy($src . '/' . $file,$dst . '/' . $file);
  54. }
  55. }
  56. }
  57. closedir($dir);
  58. }
  59. function elggdokuwiki_create_datafolder($path) {
  60. global $CONFIG;
  61. if (is_dir($path)) // if it exists must be already created
  62. return;
  63. mkdir($path, 0700, true);
  64. $orig = $CONFIG->pluginspath.'dokuwiki/lib/dokuwiki/data';
  65. elggdoku_recurse_copy($orig, $path);
  66. }
  67. function elggdokuwiki_page_handler($page) {
  68. global $CONFIG;
  69. if ($page[0] === "index") {
  70. set_context("search");
  71. include($CONFIG->pluginspath.'dokuwiki/index.php');
  72. return;
  73. }
  74. set_context("dokuwiki");
  75. $dokuwiki_path = $CONFIG->pluginspath.'dokuwiki/lib/dokuwiki/';
  76. $doku = current_dokuwiki_entity();
  77. if (!$doku) // can fail if there is no user and wiki doesnt exist
  78. forward();
  79. $parsed_url = parse_url($CONFIG->wwwroot.'pg/dokuwiki/');
  80. $url_base = $parsed_url['path'];
  81. if (is_numeric($page[0])) {
  82. $entity_guid = $page[0];
  83. $ent = get_entity($entity_guid);
  84. if (($ent && $ent instanceof ElggGroup) && $ent->dokuwiki_enable !== 'yes') {
  85. // wiki not activated for this group. bail out.
  86. forward();
  87. }
  88. if ($ent && (/*$ent instanceof ElggUser ||*/ $ent instanceof ElggGroup)) {
  89. set_page_owner($entity_guid);
  90. $data_path = $CONFIG->dataroot.'wikis/'.$entity_guid;
  91. } else {
  92. // can't see the group
  93. forward();
  94. }
  95. $page = array_slice($page, 1); // pop first element
  96. define('DOKU_REL', $url_base.$entity_guid."/");
  97. define('DOKU_BASE', $url_base.$entity_guid."/");
  98. define('DOKU_URL', $CONFIG->wwwroot.'pg/dokuwiki/'.$entity_guid."/");
  99. }
  100. else {
  101. $data_path = $CONFIG->dataroot.'wiki';
  102. define('DOKU_REL', $url_base);
  103. define('DOKU_BASE', $url_base);
  104. define('DOKU_URL', $CONFIG->wwwroot.'pg/dokuwiki/');
  105. }
  106. define('DOKU_INC', $dokuwiki_path);
  107. define('DOKU_MEDIA', $CONFIG->wwwroot.'mod/dokuwiki/lib/dokuwiki/');
  108. define('DOKU_CONF', $dokuwiki_path."conf/");
  109. elggdokuwiki_create_datafolder($data_path);
  110. define('DOKU_ELGGDATA',$data_path);
  111. if (empty($page) || (count($page)==1 && $page[0] == 'acl')) {
  112. $page = array('doku.php');
  113. }
  114. else if ((count($page)==1 && $page[0] == 'usermanager')) {
  115. $page = array('doku.php');
  116. }
  117. else if ((count($page)==1 && $page[0] == 'plugin')) {
  118. $page = array('doku.php');
  119. }
  120. else if ((count($page)==1 && $page[0] == 'config')) {
  121. $page = array('doku.php');
  122. }
  123. else if ((count($page)==1 && $page[0] == 'revert')) {
  124. $page = array('doku.php');
  125. }
  126. else if ((count($page)==1 && $page[0] == 'popularity')) {
  127. $page = array('doku.php');
  128. }
  129. if (empty($page) || (count($page)==1 && !$page[0])) {
  130. $page = array('doku.php');
  131. }
  132. $_SERVER['PHP_AUTH_USER'] = get_loggedin_user()->username;
  133. $_SERVER['PHP_AUTH_PW'] = get_loggedin_user()->password;
  134. if (count($page) == 1) {
  135. $doku_body = elgg_view('dokuwiki/index',array('page'=>$page[0]));
  136. echo $doku_body;
  137. }
  138. else {
  139. // avoid inclusion over root
  140. $dest = realpath($dokuwiki_path.implode("/",$page));
  141. if (strpos($dest, $dokuwiki_path) == 0)
  142. $doku_body = elgg_view('dokuwiki/index',array('page'=>implode("/",$page)));
  143. echo $doku_body;
  144. }
  145. return;
  146. }
  147. function elggdokuwiki_pagesetup() {
  148. global $CONFIG;
  149. if (page_owner()) {
  150. $page_owner = page_owner_entity();
  151. if ($page_owner instanceof ElggGroup && $page_owner->dokuwiki_enable == 'yes')
  152. $title = elgg_echo("dokuwiki:groupwiki");
  153. if ($title && get_context() == "groups") {
  154. add_submenu_item($title, $CONFIG->wwwroot . "pg/dokuwiki/" . page_owner());
  155. }
  156. }
  157. }
  158. function elggdokuwiki_icon_hook($hook, $entity_type, $returnvalue, $params) {
  159. global $CONFIG;
  160. if ($hook == 'entity:icon:url' && $params['entity']->getSubtype() == 'dokuwiki') {
  161. $owner = get_entity($params['entity']->container_guid);
  162. if ($owner)
  163. return $owner->getIcon($params['size']);
  164. }
  165. return $returnvalue;
  166. }
  167. function elggdokuwiki_url($entity) {
  168. global $CONFIG;
  169. return $CONFIG->url . "pg/dokuwiki/".$entity->container_guid;
  170. }
  171. function elggdokuwiki_init(){
  172. global $CONFIG;
  173. register_entity_type('object','dokuwiki');
  174. register_plugin_hook('entity:icon:url', 'object', 'elggdokuwiki_icon_hook');
  175. register_entity_url_handler('elggdokuwiki_url','object', 'dokuwiki');
  176. register_elgg_event_handler('pagesetup','system','elggdokuwiki_pagesetup');
  177. register_page_handler('dokuwiki','elggdokuwiki_page_handler');
  178. add_group_tool_option('dokuwiki',elgg_echo('groups:enabledokuwiki'),false);
  179. add_group_tool_option('dokuwiki_frontsidebar',elgg_echo('groups:enabledokuwiki_frontsidebar'),false);
  180. add_group_tool_option('dokuwiki_frontpage',elgg_echo('groups:enabledokuwiki_frontpage'),false);
  181. elgg_extend_view('groups/forum_latest','dokuwiki/grouppage');
  182. elgg_extend_view('groups/left_column','dokuwiki/sidebar');
  183. /*if (isloggedin()) {
  184. add_menu(elgg_echo('dokuwiki'), $CONFIG->wwwroot . "pg/dokuwiki/index");
  185. }*/
  186. elgg_extend_view("metatags", "dokuwiki/metatags");
  187. }
  188. register_elgg_event_handler('init','system','elggdokuwiki_init');
  189. ?>