PageRenderTime 40ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

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

https://bitbucket.org/manchas/jrobotz
PHP | 304 lines | 218 code | 49 blank | 37 comment | 22 complexity | 31731b121ceaaf18390e3c0945b3405e MD5 | raw file
Possible License(s): BSD-3-Clause, LGPL-2.1, GPL-2.0, Apache-2.0
  1. <?php
  2. /**
  3. * @package JFusion_SMF
  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. /**
  16. * JFusion Admin Class for SMF 1.1.x
  17. * For detailed descriptions on these functions please check the model.abstractadmin.php
  18. * @package JFusion_SMF
  19. */
  20. class JFusionAdmin_smf extends JFusionAdmin{
  21. function getJname()
  22. {
  23. return 'smf';
  24. }
  25. function getTablename()
  26. {
  27. return 'members';
  28. }
  29. function setupFromPath($forumPath)
  30. {
  31. //check for trailing slash and generate file path
  32. if (substr($forumPath, -1) == DS) {
  33. $myfile = $forumPath . 'Settings.php';
  34. } else {
  35. $myfile = $forumPath . DS. 'Settings.php';
  36. }
  37. //try to open the file
  38. if (($file_handle = @fopen($myfile, 'r')) === FALSE) {
  39. JError::raiseWarning(500,JText::_('WIZARD_FAILURE'). ": $myfile " . JText::_('WIZARD_MANUAL'));
  40. //get the default parameters object
  41. $params = JFusionFactory::getParams($this->getJname());
  42. return $params;
  43. } else {
  44. //parse the file line by line to get only the config variables
  45. $file_handle = fopen($myfile, 'r');
  46. while (!feof($file_handle)) {
  47. $line = fgets($file_handle);
  48. if (strpos($line, '$') === 0) {
  49. $vars = split("'", $line);
  50. if(isset($vars[1]) && isset($vars[0])){
  51. $name = trim($vars[0], ' $=');
  52. $value = trim($vars[1], ' $=');
  53. $config[$name] = $value;
  54. }
  55. }
  56. }
  57. fclose($file_handle);
  58. //Save the parameters into the standard JFusion params format
  59. $params = array();
  60. $params['database_host'] = $config['db_server'];
  61. $params['database_type'] = 'mysql';
  62. $params['database_name'] = $config['db_name'];
  63. $params['database_user'] = $config['db_user'];
  64. $params['database_password'] = $config['db_passwd'];
  65. $params['database_prefix'] = $config['db_prefix'];
  66. $params['source_url'] = $config['boardurl'];
  67. $params['cookie_name'] = $config['cookiename'];
  68. $params['source_path'] = $forumPath;
  69. return $params;
  70. }
  71. }
  72. function getUserList()
  73. {
  74. // initialise some objects
  75. $db = JFusionFactory::getDatabase($this->getJname());
  76. $query = 'SELECT memberName as username, emailAddress as email from #__members';
  77. $db->setQuery($query );
  78. $userlist = $db->loadObjectList();
  79. return $userlist;
  80. }
  81. function getUserCount()
  82. {
  83. //getting the connection to the db
  84. $db = JFusionFactory::getDatabase($this->getJname());
  85. $query = 'SELECT count(*) from #__members';
  86. $db->setQuery($query );
  87. //getting the results
  88. return $db->loadResult();
  89. }
  90. function getUsergroupList()
  91. {
  92. //getting the connection to the db
  93. $db = JFusionFactory::getDatabase($this->getJname());
  94. $query = 'SELECT ID_GROUP as id, groupName as name FROM #__membergroups WHERE minPosts = -1';
  95. $db->setQuery($query );
  96. $usergrouplist = $db->loadObjectList();
  97. //append the default usergroup
  98. $default_group = new stdClass;
  99. $default_group->id = 0;
  100. $default_group->name = 'Default User';
  101. $usergrouplist[] = $default_group;
  102. return $usergrouplist;
  103. }
  104. function getDefaultUsergroup()
  105. {
  106. $params = JFusionFactory::getParams($this->getJname());
  107. $usergroup_id = $params->get('usergroup');
  108. if ($usergroup_id==0) return "Default Usergroup";
  109. //we want to output the usergroup name
  110. $db = JFusionFactory::getDatabase($this->getJname());
  111. $query = 'SELECT groupName FROM #__membergroups WHERE ID_GROUP = ' . $usergroup_id;
  112. $db->setQuery($query );
  113. return $db->loadResult();
  114. }
  115. function getUserpostgroupList()
  116. {
  117. //getting the connection to the db
  118. $db = JFusionFactory::getDatabase($this->getJname());
  119. $query = 'SELECT ID_GROUP as id, groupName as name FROM #__membergroups WHERE minPosts != -1';
  120. $db->setQuery($query);
  121. return $db->loadObjectList();
  122. }
  123. function allowRegistration()
  124. {
  125. $db = JFusionFactory::getDatabase($this->getJname());
  126. $query = "SELECT value FROM #__settings WHERE variable ='registration_method';";
  127. $db->setQuery($query );
  128. $new_registration = $db->loadResult();
  129. if ($new_registration == 3) {
  130. $result = false;
  131. return $result;
  132. } else {
  133. $result = true;
  134. return $result;
  135. }
  136. }
  137. function generateRedirectCode()
  138. {
  139. $params = JFusionFactory::getParams($this->getJname());
  140. $joomla_params = JFusionFactory::getParams('joomla_int');
  141. $joomla_url = $joomla_params->get('source_url');
  142. $joomla_itemid = $params->get('redirect_itemid');
  143. //create the new redirection code
  144. /*
  145. $pattern = \'#action=(login|admin|profile|featuresettings|news|packages|detailedversion|serversettings|theme|manageboards|postsettings|managecalendar|managesearch|smileys|manageattachments|viewmembers|membergroups|permissions|regcenter|ban|maintain|reports|viewErrorLog|optimizetables|detailedversion|repairboards|boardrecount|convertutf8|helpadmin|packageget)#\';
  146. */
  147. $redirect_code = '
  148. //JFUSION REDIRECT START
  149. //SET SOME VARS
  150. $joomla_url = \''. $joomla_url . '\';
  151. $joomla_itemid = ' . $joomla_itemid .';
  152. ';
  153. $redirect_code .= '
  154. if(!defined(\'_JEXEC\') && strpos($_SERVER[\'QUERY_STRING\'], \'dlattach\') === false && strpos($_SERVER[\'QUERY_STRING\'], \'verificationcode\') === false)';
  155. $redirect_code .= '
  156. {
  157. $pattern = \'#action=(login|logout)#\';
  158. if ( !preg_match( $pattern , $_SERVER[\'QUERY_STRING\'] ) ) {
  159. $file = $_SERVER["SCRIPT_NAME"];
  160. $break = explode(\'/\', $file);
  161. $pfile = $break[count($break) - 1];
  162. $jfusion_url = $joomla_url . \'index.php?option=com_jfusion&Itemid=\' . $joomla_itemid . \'&jfile=\'.$pfile. \'&\' . $_SERVER[\'QUERY_STRING\'];
  163. header(\'Location: \' . $jfusion_url);
  164. exit;
  165. }
  166. }
  167. //JFUSION REDIRECT END
  168. ';
  169. return $redirect_code;
  170. }
  171. function enable_redirect_mod()
  172. {
  173. $error = 0;
  174. $error = 0;
  175. $reason = '';
  176. $mod_file = $this->getModFile('index.php',$error,$reason);
  177. if($error == 0) {
  178. //get the joomla path from the file
  179. jimport('joomla.filesystem.file');
  180. $file_data = JFile::read($mod_file);
  181. preg_match_all('/\/\/JFUSION REDIRECT START(.*)\/\/JFUSION REDIRECT END/ms',$file_data,$matches);
  182. //remove any old code
  183. if(!empty($matches[1][0])){
  184. $search = '/\/\/JFUSION REDIRECT START(.*)\/\/JFUSION REDIRECT END/ms';
  185. $file_data = preg_replace($search,'',$file_data);
  186. }
  187. $redirect_code = $this->generateRedirectCode();
  188. $search = '/\<\?php/si';
  189. $replace = '<?php' . $redirect_code;
  190. $file_data = preg_replace($search,$replace,$file_data);
  191. JFile::write($mod_file, $file_data);
  192. }
  193. }
  194. function disable_redirect_mod()
  195. {
  196. $error = 0;
  197. $reason = '';
  198. $mod_file = $this->getModFile('index.php',$error,$reason);
  199. if($error == 0) {
  200. //get the joomla path from the file
  201. jimport('joomla.filesystem.file');
  202. $file_data = JFile::read($mod_file);
  203. $search = '/\/\/JFUSION REDIRECT START(.*)\/\/JFUSION REDIRECT END/si';
  204. $file_data = preg_replace($search,'',$file_data);
  205. JFile::write($mod_file, $file_data);
  206. }
  207. }
  208. function outputJavascript(){
  209. ?>
  210. <script language="javascript" type="text/javascript">
  211. <!--
  212. function auth_mod(action) {
  213. var form = document.adminForm;
  214. form.customcommand.value = action;
  215. form.action.value = 'apply';
  216. submitform('saveconfig');
  217. return;
  218. }
  219. //-->
  220. </script>
  221. <?php
  222. }
  223. function show_redirect_mod($name, $value, $node, $control_name)
  224. {
  225. $error = 0;
  226. $reason = '';
  227. $mod_file = $this->getModFile('index.php',$error,$reason);
  228. if($error == 0) {
  229. //get the joomla path from the file
  230. jimport('joomla.filesystem.file');
  231. $file_data = JFile::read($mod_file);
  232. preg_match_all('/\/\/JFUSION REDIRECT START(.*)\/\/JFUSION REDIRECT END/ms',$file_data,$matches);
  233. //compare it with our joomla path
  234. if(empty($matches[1][0])){
  235. $error = 1;
  236. $reason = JText::_('MOD_NOT_ENABLED');
  237. }
  238. }
  239. //add the javascript to enable buttons
  240. $this->outputJavascript();
  241. if ($error == 0){
  242. //return success
  243. $output = '<img src="components/com_jfusion/images/check_good.png" height="20px" width="20px">' . JText::_('REDIRECTION_MOD') . ' ' . JText::_('ENABLED');
  244. $output .= ' <a href="javascript:void(0);" onclick="return auth_mod(\'disable_redirect_mod\')">' . JText::_('MOD_DISABLE') . '</a>';
  245. $output .= ' <a href="javascript:void(0);" onclick="return auth_mod(\'enable_redirect_mod\')">' . JText::_('MOD_UPDATE') . '</a>';
  246. return $output;
  247. } else {
  248. $output = '<img src="components/com_jfusion/images/check_bad.png" height="20px" width="20px">' . JText::_('REDIRECTION_MOD') . ' ' . JText::_('DISABLED') .': ' . $reason;
  249. $output .= ' <a href="javascript:void(0);" onclick="return auth_mod(\'enable_redirect_mod\')">' . JText::_('MOD_ENABLE') . '</a>';
  250. return $output;
  251. }
  252. }
  253. }