PageRenderTime 42ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/src/site/tmp/install_4a925da139185/admin/plugins/dokuwiki/admin.php

https://bitbucket.org/manchas/jrobotz
PHP | 371 lines | 284 code | 53 blank | 34 comment | 46 complexity | e4855dd0595d05fcadf8b9ceb5c04c93 MD5 | raw file
Possible License(s): BSD-3-Clause, LGPL-2.1, GPL-2.0, Apache-2.0
  1. <?php
  2. /**
  3. * @package JFusion_dokuwiki
  4. * @author JFusion development team
  5. * @copyright Copyright (C) 2008 JFusion. All rights reserved.
  6. * @license http://www.gnu.org/copyleft/gpl.html GNU/GPL
  7. */
  8. // no direct access
  9. defined('_JEXEC' ) or die('Restricted access' );
  10. /**
  11. * load the JFusion framework
  12. */
  13. require_once(JPATH_ADMINISTRATOR .DS.'components'.DS.'com_jfusion'.DS.'models'.DS.'model.jfusion.php');
  14. require_once(JPATH_ADMINISTRATOR .DS.'components'.DS.'com_jfusion'.DS.'models'.DS.'model.abstractadmin.php');
  15. require_once( dirname(__FILE__).DS.'dokuwiki.php');
  16. /**
  17. * JFusion plugin class for punBB
  18. * @package JFusion_punBB
  19. */
  20. class JFusionAdmin_dokuwiki extends JFusionAdmin {
  21. function getJname()
  22. {
  23. return 'dokuwiki';
  24. }
  25. function checkConfig()
  26. {
  27. $status = array();
  28. $params = JFusionFactory::getParams($this->getJname());
  29. $share = Dokuwiki::getInstance();
  30. $source_path = $params->get('source_path');
  31. $config = $share->getConf($source_path);
  32. if (is_array($config)) {
  33. $status['config'] = 1;
  34. $status['message'] = JText::_('GOOD_CONFIG');
  35. return $status;
  36. } else {
  37. $status['config'] = 0;
  38. $status['message'] = JText::_('WIZARD_FAILURE');
  39. return $status;
  40. }
  41. }
  42. function setupFromPath($Path)
  43. {
  44. $share = Dokuwiki::getInstance();
  45. //try to open the file
  46. if ($config = $share->getConf($Path) === FALSE) {
  47. JError::raiseWarning(500,JText::_('WIZARD_FAILURE'). ": $Path " . JText::_('WIZARD_MANUAL'));
  48. return false;
  49. } else {
  50. $params = array();
  51. $params['cookie_name'] = $config['cookie_name'];
  52. $params['cookie_path'] = $config['cookie_path'];
  53. $params['cookie_domain'] = $config['cookie_domain'];
  54. $params['cookie_seed'] = $config['cookie_seed'];
  55. $params['cookie_secure'] = $config['cookie_secure'];
  56. $params['source_path'] = $Path;
  57. return $params;
  58. }
  59. }
  60. function getAvatar($userid)
  61. {
  62. return 0;
  63. }
  64. function getUserList()
  65. {
  66. $share = Dokuwiki::getInstance();
  67. $conf = $share->getConf();
  68. return $share->getUserList();
  69. }
  70. function getUserCount()
  71. {
  72. $share = Dokuwiki::getInstance();
  73. // $userlist = $this->getUserList();
  74. return $share->auth->getUserCount();
  75. }
  76. function getUsergroupList()
  77. {
  78. $default_group = new stdClass;
  79. $default_group->name = $default_group->id = JFusionAdmin_dokuwiki::getDefaultUsergroup();
  80. $UsergroupList[] = $default_group;
  81. return $UsergroupList;
  82. }
  83. function getDefaultUsergroup()
  84. {
  85. $share = Dokuwiki::getInstance();
  86. return $share->getDefaultUsergroup();
  87. }
  88. function allowRegistration()
  89. {
  90. $share = Dokuwiki::getInstance();
  91. $conf = $share->getConf();
  92. if (strpos($conf['disableactions'], 'register') !== false) {
  93. return false;
  94. } else {
  95. return true;
  96. }
  97. }
  98. function debugConfig()
  99. {
  100. $jname = $this->getJname();
  101. //get registration status
  102. $new_registration = $this->allowRegistration();
  103. //get the data about the JFusion plugins
  104. $db = & JFactory::getDBO();
  105. $query = 'SELECT * from #__jfusion WHERE name = ' . $db->Quote($jname);
  106. $db->setQuery($query );
  107. $plugin = $db->loadObject();
  108. //output a warning to the administrator if the allowRegistration setting is wrong
  109. if ($new_registration && $plugin->slave == '1'){
  110. JError::raiseNotice(0, $jname . ': ' . JText::_('DISABLE_REGISTRATION'));
  111. }
  112. if (!$new_registration && $plugin->master == '1'){
  113. JError::raiseNotice(0, $jname . ': ' . JText::_('ENABLE_REGISTRATION'));
  114. }
  115. }
  116. function generateRedirectCode()
  117. {
  118. $params = JFusionFactory::getParams($this->getJname());
  119. $joomla_params = JFusionFactory::getParams('joomla_int');
  120. $joomla_url = $joomla_params->get('source_url');
  121. $joomla_itemid = $params->get('redirect_itemid');
  122. //create the new redirection code
  123. $redirect_code = '
  124. //JFUSION REDIRECT START
  125. //SET SOME VARS
  126. $joomla_url = \''. $joomla_url . '\';
  127. $joomla_itemid = ' . $joomla_itemid .';
  128. ';
  129. $redirect_code .= '
  130. if(!defined(\'_JEXEC\'))';
  131. $redirect_code .= '
  132. {
  133. $QUERY_STRING = array_merge( $_GET,$_POST );
  134. if (!isset($QUERY_STRING[\'id\'])) $QUERY_STRING[\'id\'] = $ID;
  135. $QUERY_STRING = http_build_query($QUERY_STRING);
  136. $order = array(\'%3A\', \':\', \'/\');
  137. $QUERY_STRING = str_replace($order,\';\',$QUERY_STRING);
  138. $pattern = \'#do=(admin|login|logout)#\';
  139. if ( !preg_match( $pattern , $QUERY_STRING ) ) {
  140. $file = $_SERVER["SCRIPT_NAME"];
  141. $break = explode(\'/\', $file);
  142. $pfile = $break[count($break) - 1];
  143. $jfusion_url = $joomla_url . \'index.php?option=com_jfusion&Itemid=\' . $joomla_itemid . \'&jfile=\'.$pfile. \'&\' . $QUERY_STRING;
  144. header(\'Location: \' . $jfusion_url);
  145. exit;
  146. }
  147. }
  148. //JFUSION REDIRECT END
  149. ';
  150. return $redirect_code;
  151. }
  152. function enable_redirect_mod()
  153. {
  154. $error = 0;
  155. $error = 0;
  156. $reason = '';
  157. $mod_file = $this->getModFile('doku.php',$error,$reason);
  158. if($error == 0) {
  159. //get the joomla path from the file
  160. jimport('joomla.filesystem.file');
  161. $file_data = JFile::read($mod_file);
  162. preg_match_all('/\/\/JFUSION REDIRECT START(.*)\/\/JFUSION REDIRECT END/ms',$file_data,$matches);
  163. //remove any old code
  164. if(!empty($matches[1][0])){
  165. $search = '/\/\/JFUSION REDIRECT START(.*)\/\/JFUSION REDIRECT END/ms';
  166. $file_data = preg_replace($search,'',$file_data);
  167. }
  168. $redirect_code = $this->generateRedirectCode();
  169. $search = '/getID\(\)\;/si';
  170. $replace = 'getID();' . $redirect_code;
  171. $file_data = preg_replace($search,$replace,$file_data);
  172. JFile::write($mod_file, $file_data);
  173. }
  174. }
  175. function disable_redirect_mod()
  176. {
  177. $error = 0;
  178. $reason = '';
  179. $mod_file = $this->getModFile('doku.php',$error,$reason);
  180. if($error == 0) {
  181. //get the joomla path from the file
  182. jimport('joomla.filesystem.file');
  183. $file_data = JFile::read($mod_file);
  184. $search = '/\/\/JFUSION REDIRECT START(.*)\/\/JFUSION REDIRECT END/si';
  185. $file_data = preg_replace($search,'',$file_data);
  186. JFile::write($mod_file, $file_data);
  187. }
  188. }
  189. function outputJavascript(){
  190. ?>
  191. <script language="javascript" type="text/javascript">
  192. <!--
  193. function auth_mod(action) {
  194. var form = document.adminForm;
  195. form.customcommand.value = action;
  196. form.action.value = 'apply';
  197. submitform('saveconfig');
  198. return;
  199. }
  200. //-->
  201. </script>
  202. <?php
  203. }
  204. function show_redirect_mod($name, $value, $node, $control_name)
  205. {
  206. $error = 0;
  207. $reason = '';
  208. $mod_file = $this->getModFile('doku.php',$error,$reason);
  209. if($error == 0) {
  210. //get the joomla path from the file
  211. jimport('joomla.filesystem.file');
  212. $file_data = JFile::read($mod_file);
  213. preg_match_all('/\/\/JFUSION REDIRECT START(.*)\/\/JFUSION REDIRECT END/ms',$file_data,$matches);
  214. //compare it with our joomla path
  215. if(empty($matches[1][0])){
  216. $error = 1;
  217. $reason = JText::_('MOD_NOT_ENABLED');
  218. }
  219. }
  220. //add the javascript to enable buttons
  221. $this->outputJavascript();
  222. if ($error == 0){
  223. //return success
  224. $output = '<img src="components/com_jfusion/images/check_good.png" height="20px" width="20px">' . JText::_('REDIRECTION_MOD') . ' ' . JText::_('ENABLED');
  225. $output .= ' <a href="javascript:void(0);" onclick="return auth_mod(\'disable_redirect_mod\')">' . JText::_('MOD_DISABLE') . '</a>';
  226. $output .= ' <a href="javascript:void(0);" onclick="return auth_mod(\'enable_redirect_mod\')">' . JText::_('MOD_UPDATE') . '</a>';
  227. return $output;
  228. } else {
  229. $output = '<img src="components/com_jfusion/images/check_bad.png" height="20px" width="20px">' . JText::_('REDIRECTION_MOD') . ' ' . JText::_('DISABLED') .': ' . $reason;
  230. $output .= ' <a href="javascript:void(0);" onclick="return auth_mod(\'enable_redirect_mod\')">' . JText::_('MOD_ENABLE') . '</a>';
  231. return $output;
  232. }
  233. }
  234. function usergroup($name, $value, $node, $control_name)
  235. {
  236. $jname = $this->getJname();
  237. //get the master plugin to be throughout
  238. $master = JFusionFunction::getMaster();
  239. $advanced = 0;
  240. //detect is value is a serialized array
  241. if(substr($value, 0, 2) == 'a:'){
  242. $value = unserialize($value);
  243. //use advanced only if this plugin is not set as master
  244. if($master->name!=$this->getJname()) {
  245. $advanced = 1;
  246. }
  247. }
  248. if(JFusionFunction::validPlugin($this->getJname())) {
  249. $usergroups = $this->getUsergroupList();
  250. foreach($usergroups as $group) $g[] = $group->name;
  251. $comma_separated = implode(",", $g);
  252. $simple_value = $value;
  253. if ( is_array($simple_value)) $simple_value = $comma_separated;
  254. if (!empty($usergroups)) {
  255. $simple_usergroup = "<table style=\"width:100%; border:0\">";
  256. $simple_usergroup .= '<tr><td>'.JText::_('DEFAULT_USERGROUP') . '</td><td><input type="text" name="'.$control_name.'['.$name.']" value="'.$simple_value.'" class="inputbox" /></td></tr>';
  257. $simple_usergroup .= "</table>";
  258. } else {
  259. $simple_usergroup = '';
  260. }
  261. } else {
  262. return JText::_('SAVE_CONFIG_FIRST');
  263. }
  264. //check to see if current plugin is a slave
  265. $db = & JFactory::getDBO();
  266. $query = 'SELECT slave FROM #__jfusion WHERE name = ' . $db->Quote($jname);
  267. $db->setQuery($query);
  268. $slave = $db->loadResult();
  269. $list_box = '<select onchange="usergroupSelect(this.selectedIndex);">';
  270. if($advanced == 1){
  271. $list_box .= '<option value="0" selected="selected">Simple</option>';
  272. } else {
  273. $list_box .= '<option value="0">Simple</option>';
  274. }
  275. if ($slave == 1){
  276. //allow usergroup sync
  277. if($advanced == 1){
  278. $list_box .= '<option selected="selected" value="1">Avanced</option>';
  279. } else {
  280. $list_box .= '<option value="1">Avanced</option>';
  281. }
  282. //prepare the advanced options
  283. $JFusionMaster = JFusionFactory::getAdmin($master->name);
  284. $master_usergroups = $JFusionMaster->getUsergroupList();
  285. $advanced_usergroup = "<table class=\"usergroups\">";
  286. if($advanced == 1){
  287. foreach ($master_usergroups as $master_usergroup){
  288. $advanced_usergroup .= "<tr><td>".$master_usergroup->name . '</td>';
  289. $advanced_usergroup .= '<td><input type="text" name="'.$control_name.'['.$name.']['.$master_usergroup->id.']" value="'.$value[$master_usergroup->id].'" class="inputbox" /></td></tr>';
  290. }
  291. } else {
  292. foreach ($master_usergroups as $master_usergroup){
  293. $advanced_usergroup .= "<tr><td>".$master_usergroup->name . '</td>';
  294. $advanced_usergroup .= '<td><input type="text" name="'.$control_name.'['.$name.']['.$master_usergroup->id.']" value="'.$comma_separated.'" class="inputbox" /></td></tr>';
  295. }
  296. }
  297. $advanced_usergroup .= "</table>";
  298. } else {
  299. $advanced_usergroup = '';
  300. }
  301. $list_box .= '</select>';
  302. ?><script Language="JavaScript">
  303. function usergroupSelect(option)
  304. {
  305. var myArray = new Array();
  306. myArray[0] = '<?php echo $simple_usergroup;?>';
  307. myArray[1] = '<?php echo $advanced_usergroup;?>';
  308. document.getElementById("JFusionUsergroup").innerHTML = myArray[option];
  309. }
  310. </script>
  311. <?php
  312. if($advanced == 1){
  313. return JText::_('USERGROUP'). ' '. JText::_('MODE'). ': '.$list_box . '<br/><div id="JFusionUsergroup">'. $advanced_usergroup. '</div>';
  314. } else {
  315. return JText::_('USERGROUP'). ' '. JText::_('MODE'). ': '.$list_box . '<br/><div id="JFusionUsergroup">'. $simple_usergroup. '</div>';
  316. }
  317. }
  318. }