PageRenderTime 27ms CodeModel.GetById 10ms RepoModel.GetById 1ms app.codeStats 0ms

/components/com_jfusionplugins/universal/map.php

http://jfusion.googlecode.com/
PHP | 413 lines | 382 code | 22 blank | 9 comment | 35 complexity | e2b41bef0e31707ee6d3dde315019365 MD5 | raw file
Possible License(s): Apache-2.0
  1. <?php
  2. /**
  3. * @package JFusion
  4. * @subpackage Models
  5. * @author JFusion development team -- Morten Hundevad
  6. * @copyright Copyright (C) 2008 JFusion -- Morten Hundevad. All rights reserved.
  7. * @license http://www.gnu.org/copyleft/gpl.html GNU/GPL
  8. */
  9. if ( !class_exists('JFusionMap') ) {
  10. class JFusionMap {
  11. var $_jname = null;
  12. var $_map = null;
  13. var $_mapraw = null;
  14. function JFusionMap($jname)
  15. {
  16. $this->_jname = $jname;
  17. }
  18. function getTablename($type='user')
  19. {
  20. $params = JFusionFactory::getParams($this->getJname());
  21. $database_prefix = $params->get('database_prefix');
  22. $map = JFusionMap::getInstance($this->getJname());
  23. $maped = $map->getMapRaw($type);
  24. return $maped['table'];
  25. }
  26. function getJname()
  27. {
  28. return $this->_jname;
  29. }
  30. function &getInstance( $jname )
  31. {
  32. static $instances;
  33. if (!isset( $instances[$jname] )) {
  34. $instance = new JFusionMap($jname);
  35. $instances[$jname] = & $instance;
  36. }
  37. return $instances[$jname];
  38. }
  39. function getMapRaw($type='user') {
  40. if( !is_array($this->_mapraw) ) {
  41. $params = JFusionFactory::getParams($this->getJname());
  42. $map = $params->get('map');
  43. if(is_array($map)) {
  44. $this->_mapraw = $map;
  45. }
  46. }
  47. if( is_array($this->_mapraw) ) {
  48. if( isset($this->_mapraw[$type]) && is_array($this->_mapraw[$type]) ) {
  49. return $this->_mapraw[$type];
  50. }
  51. }
  52. }
  53. function getMap($type='user') {
  54. if( !is_array($this->_map) ) {
  55. $params = JFusionFactory::getParams($this->getJname());
  56. $map = $params->get('map');
  57. if(is_array($map)) {
  58. $this->_map = $map;
  59. $temp = array();
  60. foreach ($this->_map as $keytype => $value) {
  61. $temp[$keytype] = array();
  62. if( isset($value['field']) ) {
  63. foreach ($value['field'] as $key => $val) {
  64. $obj = new stdClass;
  65. $obj->table = $value['table'];
  66. $obj->field = $key;
  67. $obj->type = $val;
  68. if (isset($value['value'][$key])) {
  69. $obj->value = $value['value'][$key];
  70. }
  71. if (isset($value['type'][$key])) {
  72. $obj->fieldtype = $value['type'][$key];
  73. }
  74. $temp[$keytype][$key] = $obj;
  75. $this->_map = $temp;
  76. }
  77. }
  78. }
  79. }
  80. }
  81. if( is_array($this->_map) ) {
  82. if( isset($this->_map[$type]) && is_array($this->_map[$type]) ) {
  83. return $this->_map[$type];
  84. }
  85. }
  86. }
  87. function getFieldUserID() {
  88. $userid = $this->getFieldType('USERID');
  89. if(empty($userid)) $userid = $this->getFieldType('USERNAMEID');
  90. return $userid;
  91. }
  92. function getFieldEmail() {
  93. $email = $this->getFieldType('USERNAMEEMAIL');
  94. if (empty($email)) {
  95. $email = $this->getFieldType('EMAIL');
  96. }
  97. return $email;
  98. }
  99. function getFieldUsername() {
  100. $username = $this->getFieldType('USERNAME');
  101. if (empty($username)) {
  102. $username = $this->getFieldType('USERNAMEEMAIL');
  103. }
  104. if(empty($username)) {
  105. $username = $this->getFieldType('USERNAMEID');
  106. }
  107. return $username;
  108. }
  109. function getQuery($include=null,$type='user') {
  110. // a.validation_code as activation, a.is_activated, NULL as reason, a.lastLogin as lastvisit '.
  111. $query = array();
  112. $map = $this->getMap($type);
  113. foreach ($map as $key => $value) {
  114. if ( $include == null || in_array($value->type, $include) ) {
  115. switch ($value->type) {
  116. case 'LASTVISIT':
  117. $query[] = $value->field.' as lastvisit';
  118. break;
  119. case 'GROUP':
  120. $query[] = $value->field.' as group_id';
  121. break;
  122. case 'SALT':
  123. $query[] = $value->field.' as password_salt';
  124. break;
  125. case 'PASSWORD':
  126. $query[] = $value->field.' as password';
  127. break;
  128. case 'REALNAME':
  129. $query[] = $value->field.' as name';
  130. break;
  131. case 'FIRSTNAME':
  132. $query[] = $value->field.' as firstname';
  133. break;
  134. case 'LASTNAME':
  135. $query[] = $value->field.' as lastname';
  136. break;
  137. case 'USERID':
  138. $query[] = $value->field.' as userid';
  139. break;
  140. case 'USERNAME':
  141. $query[] = $value->field.' as username';
  142. break;
  143. case 'USERNAMEID':
  144. $query[] = $value->field.' as username';
  145. $query[] = $value->field.' as userid';
  146. break;
  147. case 'EMAIL':
  148. $query[] = $value->field.' as email';
  149. break;
  150. case 'USERNAMEEMAIL':
  151. $query[] = $value->field.' as username';
  152. $query[] = $value->field.' as email';
  153. break;
  154. case 'ACTIVE':
  155. $query[] = $value->field.' as active';
  156. break;
  157. case 'INACTIVE':
  158. $query[] = $value->field.' as inactive';
  159. break;
  160. case 'ACTIVECODE':
  161. $query[] = $value->field.' as activation';
  162. break;
  163. case 'USERNAMEREALNAME':
  164. $query[] = $value->field.' as name';
  165. $query[] = $value->field.' as username';
  166. break;
  167. case 'USERNAMEIDREALNAME':
  168. $query[] = $value->field.' as name';
  169. $query[] = $value->field.' as username';
  170. $query[] = $value->field.' as userid';
  171. break;
  172. case 'USERNAMEEMAILREALNAME':
  173. $query[] = $value->field.' as name';
  174. $query[] = $value->field.' as username';
  175. $query[] = $value->field.' as email';
  176. break;
  177. }
  178. }
  179. }
  180. $query = implode ( ', ' , $query );
  181. return $query;
  182. }
  183. function getFieldType($field=null,$type='user') {
  184. $maped = $this->getMap($type);
  185. if ($maped && is_array($maped)) {
  186. foreach ($maped as $key => $value) {
  187. if ( $field == $value->type ) {
  188. return $value;
  189. }
  190. }
  191. }
  192. return null;
  193. }
  194. function getType($t=null) {
  195. static $types = null;
  196. if ( !is_array($types) ) {
  197. $types = array();
  198. $type = new stdClass;
  199. $type->id = 'MD5';
  200. $type->name = 'MD5';
  201. $types['MD5'] = $type;
  202. $type = new stdClass;
  203. $type->id = 'CUSTOM';
  204. $type->name = 'CUSTOM';
  205. $types['CUSTOM'] = $type;
  206. $type = new stdClass;
  207. $type->id = 'SALT';
  208. $type->name = 'SALT';
  209. $types['SALT'] = $type;
  210. $type = new stdClass;
  211. $type->id = 'NULL';
  212. $type->name = 'NULL';
  213. $types['NULL'] = $type;
  214. $type = new stdClass;
  215. $type->id = 'TIME';
  216. $type->name = 'TIME';
  217. $types['TIME'] = $type;
  218. $type = new stdClass;
  219. $type->id = 'DATE';
  220. $type->name = 'DATE';
  221. $types['DATE'] = $type;
  222. $type = new stdClass;
  223. $type->id = 'VALUE';
  224. $type->name = 'VALUE';
  225. $types['VALUE'] = $type;
  226. $type = new stdClass;
  227. $type->id = 'ONOFF';
  228. $type->name = 'ONOFF';
  229. $types['ONOFF'] = $type;
  230. }
  231. if ( $t ) {
  232. return $types[$t];
  233. }
  234. return $types;
  235. }
  236. function getField($field=null) {
  237. static $fields;
  238. if ( !is_array($fields) ) {
  239. $defaulttype = new stdClass;
  240. $defaulttype->id = '';
  241. $defaulttype->name = 'Change Me';
  242. $fields = array();
  243. $type = new stdClass;
  244. $type->id = 'IGNORE';
  245. $type->name = 'IGNORE';
  246. $fields[$type->id] = $type;
  247. $type = new stdClass;
  248. $type->id = 'USERID';
  249. $type->name = 'USERID';
  250. $fields[$type->id] = $type;
  251. $type = new stdClass;
  252. $type->id = 'USERNAME';
  253. $type->name = 'USERNAME';
  254. $fields[$type->id] = $type;
  255. $type = new stdClass;
  256. $type->id = 'USERNAMEID';
  257. $type->name = 'USERNAMEID';
  258. $fields[$type->id] = $type;
  259. $type = new stdClass;
  260. $type->id = 'EMAIL';
  261. $type->name = 'EMAIL';
  262. $fields[$type->id] = $type;
  263. $type = new stdClass;
  264. $type->id = 'USERNAMEEMAIL';
  265. $type->name = 'USERNAMEEMAIL';
  266. $fields[$type->id] = $type;
  267. $type = new stdClass;
  268. $type->id = 'REALNAME';
  269. $type->name = 'REALNAME';
  270. $fields[$type->id] = $type;
  271. $type = new stdClass;
  272. $type->id = 'USERNAMEREALNAME';
  273. $type->name = 'USERNAMEREALNAME';
  274. $fields[$type->id] = $type;
  275. $type = new stdClass;
  276. $type->id = 'USERNAMEIDREALNAME';
  277. $type->name = 'USERNAMEIDREALNAME';
  278. $fields[$type->id] = $type;
  279. $type = new stdClass;
  280. $type->id = 'USERNAMEEMAILREALNAME';
  281. $type->name = 'USERNAMEEMAILREALNAME';
  282. $fields[$type->id] = $type;
  283. $type = new stdClass;
  284. $type->id = 'FIRSTNAME';
  285. $type->name = 'FIRSTNAME';
  286. $fields[$type->id] = $type;
  287. $type = new stdClass;
  288. $type->id = 'LASTNAME';
  289. $type->name = 'LASTNAME';
  290. $fields[$type->id] = $type;
  291. $type = new stdClass;
  292. $type->id = 'GROUP';
  293. $type->name = 'GROUP';
  294. $fields[$type->id] = $type;
  295. $type = new stdClass;
  296. $type->id = 'LASTVISIT';
  297. $type->name = 'LASTVISIT';
  298. // $fields[$type->id] = $type;
  299. $type = new stdClass;
  300. $type->id = 'ACTIVE';
  301. $type->name = 'ACTIVE';
  302. $type->types[] = $defaulttype;
  303. $type->types[] = $this->getType('ONOFF');
  304. $fields[$type->id] = $type;
  305. $type = new stdClass;
  306. $type->id = 'INACTIVE';
  307. $type->name = 'INACTIVE';
  308. $type->types[] = $defaulttype;
  309. $type->types[] = $this->getType('ONOFF');
  310. $fields[$type->id] = $type;
  311. $type = new stdClass;
  312. $type->id = 'ACTIVECODE';
  313. $type->name = 'ACTIVECODE';
  314. $type->types[] = $defaulttype;
  315. $type->types[] = $this->getType('SALT');
  316. $type->types[] = $this->getType('CUSTOM');
  317. $type->types[] = $this->getType('VALUE');
  318. $fields[$type->id] = $type;
  319. $type = new stdClass;
  320. $type->id = 'PASSWORD';
  321. $type->name = 'PASSWORD';
  322. $type->types[] = $defaulttype;
  323. $type->types[] = $this->getType('MD5');
  324. $type->types[] = $this->getType('CUSTOM');
  325. $fields[$type->id] = $type;
  326. $type = new stdClass;
  327. $type->id = 'SALT';
  328. $type->name = 'SALT';
  329. $type->types[] = $defaulttype;
  330. $type->types[] = $this->getType('SALT');
  331. $type->types[] = $this->getType('CUSTOM');
  332. $fields[$type->id] = $type;
  333. $type = new stdClass;
  334. $type->id = 'DEFAULT';
  335. $type->name = 'DEFAULT';
  336. $type->types[] = $defaulttype;
  337. $type->types[] = $this->getType('NULL');
  338. $type->types[] = $this->getType('TIME');
  339. $type->types[] = $this->getType('DATE');
  340. $type->types[] = $this->getType('CUSTOM');
  341. $type->types[] = $this->getType('VALUE');
  342. $fields[$type->id] = $type;
  343. }
  344. if ( $field ) {
  345. return $fields[$field];
  346. }
  347. return $fields;
  348. }
  349. function getValue($type,$value, $userinfo=null ) {
  350. $out = '';
  351. $value = html_entity_decode($value);
  352. switch ($type) {
  353. case 'CUSTOM':
  354. $value = rtrim(trim($value),';');
  355. ob_start();
  356. $out = eval("return $value;");
  357. $error = ob_get_contents();
  358. ob_end_clean();
  359. if ($testcrypt===false && strlen($error)) {
  360. die($error);
  361. }
  362. break;
  363. case 'TIME':
  364. $out = time();
  365. break;
  366. case 'DATE':
  367. $out = date($value);
  368. break;
  369. case 'VALUE':
  370. $out = $value;
  371. break;
  372. case 'SALT':
  373. $len = 4;
  374. $base='ABCDEFGHKLMNOPQRSTWXYZabcdefghjkmnpqrstwxyz123456789';
  375. $max=strlen($base)-1;
  376. $activatecode='';
  377. mt_srand((double)microtime()*1000000);
  378. while (strlen($activatecode)<$len+1) $out.=$base{mt_rand(0,$max)};
  379. break;
  380. case 'MD5':
  381. $out = md5($value);
  382. break;
  383. case 'NULL':
  384. $out = null;
  385. break;
  386. }
  387. return $out;
  388. }
  389. }
  390. }
  391. ?>