PageRenderTime 45ms CodeModel.GetById 0ms RepoModel.GetById 0ms app.codeStats 0ms

/components/com_jfusionplugins/efront/admin.php

http://jfusion.googlecode.com/
PHP | 247 lines | 138 code | 20 blank | 89 comment | 30 complexity | cbe4bc13c8ab7de2f146de047340eb02 MD5 | raw file
Possible License(s): Apache-2.0
  1. <?php
  2. /**
  3. * file containing administrator function for the jfusion plugin
  4. *
  5. * PHP version 5
  6. *
  7. * @category JFusion
  8. * @package JFusionPlugins
  9. * @subpackage eFront
  10. * @author JFusion Team <webmaster@jfusion.org>
  11. * @copyright 2009 JFusion. All rights reserved.
  12. * @license http://www.gnu.org/copyleft/gpl.html GNU/GPL
  13. * @link http://www.jfusion.org
  14. */
  15. // no direct access
  16. defined('_JEXEC') or die('Restricted access');
  17. require_once JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_jfusion' . DS . 'models' . DS . 'model.abstractuser.php';
  18. if (!class_exists('JFusionEfrontHelper')) {
  19. require_once 'efronthelper.php';
  20. }
  21. /**
  22. * JFusion Admin Class for eFront 3.5+
  23. * For detailed descriptions on these functions please check the model.abstractadmin.php
  24. *
  25. * @category JFusion
  26. * @package JFusionPlugins
  27. * @subpackage eFront
  28. * @author JFusion Team <webmaster@jfusion.org>
  29. * @copyright 2009 JFusion. All rights reserved.
  30. * @license http://www.gnu.org/copyleft/gpl.html GNU/GPL
  31. * @link http://www.jfusion.org
  32. */
  33. class JFusionAdmin_efront extends JFusionAdmin
  34. {
  35. /*
  36. * The following functions are available but do not need to be subclassed for this plugin
  37. * function hasDatabaseBackend()
  38. * function checkConfig()
  39. * function checkConfigExtra()
  40. * function debugConfig()
  41. * function getUsergroupAssignments($source_usergroups, $value)
  42. * function getModFile($filename, &$error,&$reason)
  43. * function getProfileAssignments($source_fields, $value)
  44. * function import($name, $value, $node, $control_name)
  45. * function headermap($name, $value, $node, $control_name)
  46. * function bodymap($name, $value, $node, $control_name)
  47. * function pair($name, $value, $node, $control_name,$type)
  48. *
  49. **/
  50. /**
  51. * returns the name of this JFusion plugin
  52. * @return string name of current JFusion plugin
  53. */
  54. function getJname()
  55. {
  56. return 'efront';
  57. }
  58. /**
  59. * Returns the a list of users of the integrated software
  60. * @return array List of usernames/emails
  61. */
  62. function getUserList() {
  63. //getting the connection to the db
  64. $db = JFusionFactory::getDatabase($this->getJname());
  65. $query = 'SELECT login AS username, email from #__users';
  66. $db->setQuery($query);
  67. //getting the results
  68. $userlist = $db->loadObjectList();
  69. return $userlist;
  70. }
  71. /**
  72. * Returns the the number of users in the integrated software. Allows for fast retrieval total number of users for the usersync
  73. * @return integer Number of registered users
  74. */
  75. function getUserCount() {
  76. //getting the connection to the db
  77. $db = JFusionFactory::getDatabase($this->getJname());
  78. // eFront does not have a single user id field in its userdatabase.
  79. // jFusion needs one, so add it here. This routine runs once
  80. // when configuring the eFront plugin
  81. // Also we need an indication that the module initialisation neds to be performed for this user
  82. // because we cannot run this from outside eFront (unless we load the whole framework on top of Joomla)
  83. $tableFields = $db->getTableFields('users',false);
  84. if (!array_key_exists('id',$tableFields['users']))
  85. {
  86. $query = "ALTER TABLE users ADD id int(11) NOT null AUTO_INCREMENT FIRST, ADD UNIQUE (id)";
  87. $db->Execute($query);
  88. }
  89. if (!array_key_exists('need_mod_init',$tableFields['users']))
  90. {
  91. $query = "ALTER TABLE users ADD need_mod_init int(11) NOT null DEFAULT 0";
  92. $db->Execute($query);
  93. }
  94. $query = 'SELECT count(*) from #__users';
  95. $db->setQuery($query);
  96. //getting the results
  97. $no_users = $db->loadResult();
  98. return $no_users;
  99. }
  100. /**
  101. * Returns the a list of usersgroups of the integrated software
  102. * @param $grouptype optional parameter to differentiate groups
  103. * @return array List of usergroups
  104. */
  105. function getUsergroupList() {
  106. return JFusionEfrontHelper::getUsergroupList();
  107. }
  108. /**
  109. * Checks if the software allows new users to register
  110. * @return boolean True if new user registration is allowed, otherwise returns false
  111. */
  112. function allowRegistration() {
  113. $db = JFusionFactory::getDatabase($this->getJname());
  114. $query = "SELECT value FROM #__configuration WHERE name = 'signup'";
  115. $db->setQuery($query);
  116. $signup = $db->loadResult();
  117. if ($signup == 0){
  118. $result = false;
  119. return $result;
  120. } else {
  121. $result = true;
  122. return $result;
  123. }
  124. }
  125. /**
  126. * returns the name of user table of integrated software
  127. * @return string table name
  128. */
  129. function getTablename() {
  130. return 'users';
  131. }
  132. /**
  133. * Function finds config file of integrated software and automatically configures the JFusion plugin
  134. * @param string $softwarePath path to root of integrated software
  135. * @return object JParam JParam objects with ne newly found configuration
  136. */
  137. function setupFromPath($forumPath) {
  138. //check for trailing slash and generate file path
  139. if (substr($forumPath, -1) == DS) {
  140. $myfile = $forumPath . 'libraries'. DS. 'configuration.php';
  141. } else {
  142. $myfile = $forumPath . DS .'libraries'. DS .'configuration.php';
  143. }
  144. if (($file_handle = @fopen($myfile, 'r')) === false) {
  145. JError::raiseWarning(500, JText::_('WIZARD_FAILURE') . ": $myfile " . JText::_('WIZARD_MANUAL'));
  146. return false;
  147. } else {
  148. //parse the file line by line to get only the config variables
  149. $file_handle = fopen($myfile, 'r');
  150. while (!feof($file_handle)) {
  151. $line = trim(fgets($file_handle));
  152. if (strpos($line, 'define') !== false) {
  153. if (strpos($line, 'define') == 0){
  154. eval($line);
  155. }
  156. }
  157. }
  158. fclose($file_handle);
  159. // need more defines from eFront
  160. if (substr($forumPath, -1) == DS) {
  161. $myfile = $forumPath . 'libraries'. DS. 'globals.php';
  162. } else {
  163. $myfile = $forumPath . DS .'libraries'. DS .'globals.php';
  164. }
  165. if (($file_handle = @fopen($myfile, 'r')) === false) {
  166. JError::raiseWarning(500, JText::_('WIZARD_FAILURE') . ": $myfile " . JText::_('WIZARD_MANUAL'));
  167. return false;
  168. } else {
  169. //parse the file line by line to get only the config variables
  170. $file_handle = fopen($myfile, 'r');
  171. while (!feof($file_handle)) {
  172. $line = trim(fgets($file_handle));
  173. if (strpos($line, 'define') !== false) {
  174. if (strpos($line, 'define') == 0){
  175. eval($line);
  176. }
  177. }
  178. }
  179. }
  180. fclose($file_handle);
  181. //save the parameters into array
  182. $params = array();
  183. $params['database_host'] = G_DBHOST;
  184. $params['database_name'] = G_DBNAME;
  185. $params['database_user'] = G_DBUSER;
  186. $params['database_password'] = G_DBPASSWD;
  187. $params['database_type'] = G_DBTYPE;
  188. $params['source_path'] = $forumPath;
  189. $params['usergroup'] = '0'; #make sure we do not assign roles with more capabilities automatically
  190. $params['md5_key'] = G_MD5KEY;
  191. $params['uploadpath'] = G_UPLOADPATH;
  192. return $params;
  193. }
  194. }
  195. function allow_empty_cookie_path(){
  196. return true;
  197. }
  198. function allow_empty_cookie_domain() {
  199. return true;
  200. }
  201. function debugConfigExtra() {
  202. // see if we have an api user in Magento
  203. $jname = $this->getJname();
  204. $db = JFusionFactory::getDataBase($this->getJname());
  205. // check if we have valid parameters for apiuser and api key
  206. $params = JFusionFactory::getParams($this->getJname());
  207. $apiuser = $params->get('apiuser');
  208. $apikey = $params->get('apikey');
  209. if (!$apiuser || !$apikey) {
  210. JError::raiseWarning(0, $jname . '-plugin: ' . JText::_('EFRONT_NO_API_DATA'));
  211. } else {
  212. //check if the apiuser and apikey are valid
  213. $query = 'SELECT password FROM #__users WHERE login = ' . $db->Quote($apiuser);
  214. $db->setQuery($query);
  215. $api_key = $db->loadResult();
  216. $md5_key = $params->get('md5_key');
  217. $params_hash = md5($apikey.$md5_key);
  218. if ($params_hash != $api_key) {
  219. JError::raiseWarning(0, $jname . '-plugin: ' . JText::_('EFRONT_WRONG_APIUSER_APIKEY_COMBINATION'));
  220. }
  221. }
  222. // we need to have the curl library installed
  223. if (!extension_loaded('curl')) {
  224. JError::raiseWarning(0, $jname . ': ' . JText::_('CURL_NOTINSTALLED'));
  225. }
  226. }
  227. }