Guest User

Untitled

a guest
Dec 5th, 2017
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 22.87 KB | None | 0 0
  1. <?php
  2.  
  3. class User extends Controller {
  4.  
  5. function User()
  6. {
  7. parent::Controller();
  8. $this->load->library('Openid');
  9. $this->load->library('Form_validation');
  10. $this->load->library('table');
  11.  
  12. $this->load->helper('form');
  13. $this->load->helper('simian_view_helper');
  14. $this->load->helper('simian_openid_helper');
  15. $this->load->helper('simian_facebook_helper');
  16.  
  17. $this->lang->load('simian_grid', get_language() );
  18. }
  19.  
  20. function _me_or_admin($uuid)
  21. {
  22. $my_uuid = $this->sg_auth->get_uuid();
  23. $is_admin = $this->sg_auth->is_admin();
  24. if ( $my_uuid == $uuid || $is_admin ) {
  25. return true;
  26. } else {
  27. return false;
  28. }
  29. }
  30.  
  31. function identities($uuid, $action=null)
  32. {
  33. if ( ! $this->_me_or_admin($uuid) ) {
  34. return redirect('user/index');
  35. }
  36. if ( $action == 'remove' ) {
  37. return $this->_remove_identity($uuid);
  38. } elseif ( $action == 'add_openid' ) {
  39. return $this->_add_openid($uuid);
  40. } elseif ( $action == 'add_facebook' ) {
  41. return $this->_add_facebook($uuid);
  42. }
  43. return $this->_list_identities($uuid);
  44. }
  45.  
  46. function _add_facebook($uuid)
  47. {
  48. if ( ! empty($_SERVER['QUERY_STRING']) ) {
  49. parse_str($_SERVER['QUERY_STRING'],$_GET);
  50. if ( ! empty($_GET['code']) ) {
  51. $token = process_facebook_verification($_GET['code'], site_url("user/identities/$uuid/add_facebook"));
  52. $fb_id = facebook_get_id($this, $token);
  53. if ( ! $this->sg_auth->facebook_exists($fb_id) ) {
  54. if ( ! $this->simiangrid->identity_set($uuid, 'facebook', $fb_id) ) {
  55. push_message(lang('sg_auth_fb_error_assoc'), 'error');
  56. }
  57. }
  58. }
  59. }
  60. return redirect("user/view/$uuid");
  61. }
  62.  
  63. function _add_openid($uuid)
  64. {
  65. $callback_url = site_url("user/identities/$uuid/add_openid");
  66. if ($this->input->post('action') == 'verify') {
  67. return openid_process_verify($this, $callback_url);
  68. } else if ( $this->session->flashdata('openid_identifier') OR openid_check($this, $callback_url, $data) ) {
  69. $openid = null;
  70. if ($this->session->flashdata('openid_identifier')) {
  71. $openid = $this->session->flashdata('openid_identifier');
  72. $data['openid_identifier'] = $openid;
  73. $this->session->keep_flashdata('openid_identifier');
  74. } else {
  75. $openid = $data['openid_identifier'];
  76. $this->session->set_flashdata('openid_identifier', $openid);
  77. }
  78.  
  79. if ( ! $this->sg_auth->openid_exists($openid) ) {
  80. if ( ! $this->simiangrid->identity_set($uuid, 'openid', $openid) ) {
  81. push_message(lang('sg_auth_open_error_assoc'), 'error');
  82. }
  83. }
  84. }
  85. return redirect("user/view/$uuid/identities");
  86. }
  87.  
  88. function _remove_identity($uuid)
  89. {
  90. $val = $this->form_validation;
  91. $val->set_rules('type', 'Type', 'trim|required|xss_clean');
  92. $val->set_rules('identifier', 'Identifier', 'trim|required|xss_clean');
  93.  
  94. if ( $val->run() ) {
  95. $type = $val->set_value('type');
  96. $identifier = $val->set_value('identifier');
  97. if ( ! $this->simiangrid->identity_remove($uuid, $type, $identifier) ) {
  98. push_message(set_message('sg_auth_ident_remove_error', $type), 'error');
  99. }
  100. }
  101. return redirect("user/view/$uuid");
  102. }
  103.  
  104. function _render_remove_identity($user_id, $type, $identifier)
  105. {
  106. $form = form_open(site_url("user/identities/$user_id/remove"));
  107. $form = $form . form_hidden('type', $type);
  108. $form = $form . form_hidden('identifier', $identifier);
  109. $form = $form . form_submit('remove','Remove', 'class="button"');
  110. $form = $form . form_close();
  111. return $form;
  112. }
  113.  
  114. function _list_identities($uuid) {
  115. $data = array();
  116. $data['uuid'] = $uuid;
  117. $data['identities'] = $this->simiangrid->get_user_identities($uuid);
  118.  
  119. $this->table->set_heading(lang('sg_type'), lang('sg_user_identifier'), lang('sg_actions') );
  120.  
  121. $data['has_openid'] = false;
  122. $data['has_facebook'] = false;
  123.  
  124. foreach ( $data['identities'] as $identity ) {
  125. $type = $identity['Type'];
  126. $enabled = (bool) $identity['Enabled'];
  127. $real_identifier = $identity['Identifier'];
  128. $ident = $real_identifier;
  129. if ( $type == "openid" ) {
  130. $this->has_openid = true;
  131. $url = parse_url($real_identifier);
  132. $ident = $url['host'];
  133. } elseif ( $type == "facebook" ) {
  134. $data['has_facebook'] = true;
  135. }
  136. if ( $type != "md5hash" && $type != "a1hash" ) {
  137. $actions = $this->_render_remove_identity($uuid, $type, $real_identifier);
  138. } else {
  139. $actions = '';
  140. }
  141. $this->table->add_row($type, $ident, $actions);
  142. }
  143. return parse_template('user/identities', $data, true);
  144. }
  145.  
  146. function index()
  147. {
  148. $data = array();
  149. $data['page'] = 'users';
  150. parse_template('user/index', $data);
  151. }
  152.  
  153. function profile_pic($uuid)
  154. {
  155. if ( $this->config->item('use_imagick') && extension_loaded('imagick') ) {
  156. $grid_user = $this->simiangrid->get_user($uuid);
  157. if ( isset($grid_user['LLAbout']) && isset($grid_user['LLAbout']['Image']) ) {
  158. $image = $this->simiangrid->get_texture($grid_user['LLAbout']['Image'], 200, 200);
  159. if ( $image == null ){
  160. return show_404($uuid);
  161. } else {
  162. header('Content-type: image/jpeg');
  163. echo $image;
  164. }
  165. }
  166. } else {
  167. return show_404($uuid);
  168. }
  169. }
  170.  
  171. function profile($uuid)
  172. {
  173. $data = array();
  174. $data['user_id'] = $uuid;
  175. $data['my_uuid'] = $this->sg_auth->get_uuid();
  176. $grid_user = $this->simiangrid->get_user($uuid);
  177. if ( $grid_user == null ) {
  178. return show_404($uuid);
  179. }
  180. if ( isset($grid_user['LastLocation'] ) ) {
  181. $last_scene_id = $grid_user['LastLocation']['SceneID'];
  182. if ( $last_scene_id != null ) {
  183. $data['last_scene'] = $this->simiangrid->get_scene($last_scene_id);
  184. }
  185. }
  186. $data['user_info'] = array(
  187. 'name' => $grid_user['Name'],
  188. 'email' => $grid_user['Email']
  189. );
  190. if ( isset($grid_user['LLAbout']) ) {
  191. if ( isset($grid_user['LLAbout']['About']) ) {
  192. $data['user_info']['about'] = $grid_user['LLAbout']['About'];
  193. }
  194. if ( $this->config->item('use_imagick') && extension_loaded('imagick') && isset($grid_user['LLAbout']['Image']) ) {
  195. $data['avatar_image'] = $uuid;
  196. }
  197. }
  198. parse_template('user/profile', $data, true);
  199. }
  200.  
  201. function _truncate_search($search_results, $offset, $page_count)
  202. {
  203. $results = array();
  204. $offset_count = 0;
  205. $result_count = 0;
  206. foreach ( $search_results as $search_result ) {
  207. if ( $offset_count >= $offset && $result_count < $page_count ) {
  208. $user_id = $search_result['id'];
  209. if ( $this->sg_auth->is_user_searchable($user_id) ) {
  210. $search_item = array(
  211. render_user_link($user_id)
  212. );
  213. array_push($results, $search_item);
  214. $result_count = $result_count + 1;
  215. }
  216. } else if ( $offset_count < $offset ) {
  217. $offset_count = $offset_count + 1;
  218. }
  219. }
  220. return $results;
  221. }
  222.  
  223. function search()
  224. {
  225. parse_str($_SERVER['QUERY_STRING'],$_GET);
  226. $offset = $_GET['iDisplayStart'];
  227. $limit = $_GET['iDisplayLength'];
  228. $search = $_GET['sSearch'];
  229. if ( $search == '' || $search == ' ' ) {
  230. $trunc_count = 0;
  231. $trunc_results = array();
  232. } else {
  233. $search_results = $this->simiangrid->search_user($search);
  234. $trunc_results = $this->_truncate_search($search_results, $offset, $limit);
  235. $trunc_count = count($search_results);
  236. }
  237. $result = array(
  238. "sEcho" => $_GET['sEcho'],
  239. "iTotalRecords" => $this->simiangrid->total_user_count(),
  240. "iTotalDisplayRecords" => $trunc_count,
  241. "aaData" => $trunc_results
  242. );
  243. echo json_encode($result);
  244. return;
  245. }
  246.  
  247. function self()
  248. {
  249. $uuid = $this->sg_auth->get_uuid();
  250. if ( $uuid == null ) {
  251. return redirect('user/', 'location');
  252. } else {
  253. return redirect('user/view/' . $uuid, 'location');
  254. }
  255. }
  256.  
  257. function view($uuid, $extra=null)
  258. {
  259. $data = array();
  260. $user = $this->simiangrid->get_user($uuid);
  261. if ( $user == null ) {
  262. $user = $this->simiangrid->get_user_by_name($uuid);
  263. if ( $user != null ) {
  264. $data['uuid'] = $user['UserID'];
  265. } else {
  266. push_message(set_message('sg_user_not_found', $uuid), 'error');
  267. return redirect('user/');
  268. }
  269. } else {
  270. $data['uuid'] = $uuid;
  271. }
  272. $my_uuid = $this->sg_auth->get_uuid();
  273. $data['page'] = 'users';
  274. if ( $my_uuid != null ) {
  275. $data['my_uuid'] = $my_uuid;
  276. if ( $my_uuid == $uuid ) {
  277. $data['page'] = 'account';
  278. }
  279. }
  280. $data['tab'] = '';
  281. if ( $extra == "actions" ) {
  282. $data['tab'] = 'actions';
  283. } else if ( $extra == 'identities' ) {
  284. $data['tab'] = 'identities';
  285. } else if ( $extra == 'admin_actions' ) {
  286. $data['tab'] = 'admin_actions';
  287. }
  288. $data['title'] = $user['Name'];
  289. parse_template('user/view', $data);
  290. }
  291.  
  292. function me($extra=null)
  293. {
  294. $data = array();
  295. $my_uuid = $this->sg_auth->get_uuid();
  296. $user = $this->simiangrid->get_user($my_uuid);
  297. $data['uuid'] = $my_uuid;
  298. $data['page'] = 'users';
  299. $data['my_uuid'] = $my_uuid;
  300. $data['page'] = 'account';
  301. $data['tab'] = '';
  302. if ( $extra == "actions" ) {
  303. $data['tab'] = 'actions';
  304. } else if ( $extra == 'identities' ) {
  305. $data['tab'] = 'identities';
  306. } else if ( $extra == 'admin_actions' ) {
  307. $data['tab'] = 'admin_actions';
  308. }
  309. $data['title'] = $user['Name'];
  310. parse_template('user/me', $data);
  311. }
  312.  
  313. function empty_trash()
  314. {
  315. $data = array();
  316. $my_uuid = $this->sg_auth->get_uuid();
  317. $user = $this->simiangrid->get_user($my_uuid);
  318. $data['uuid'] = $my_uuid;
  319. $data['my_uuid'] = $my_uuid;
  320. parse_template('user/empty_trash', $data);
  321. }
  322.  
  323. function purge_appearance()
  324. {
  325. $data = array();
  326. $my_uuid = $this->sg_auth->get_uuid();
  327. $user = $this->simiangrid->get_user($my_uuid);
  328. $data['uuid'] = $my_uuid;
  329. $data['my_uuid'] = $my_uuid;
  330. parse_template('user/purge_appearance', $data);
  331. }
  332.  
  333.  
  334. function currently_inworld()
  335. {
  336. $data = array();
  337. $my_uuid = $this->sg_auth->get_uuid();
  338. $user = $this->simiangrid->get_user($my_uuid);
  339. $data['uuid'] = $my_uuid;
  340. $data['my_uuid'] = $my_uuid;
  341. parse_template('user/currently_inworld', $data);
  342. }
  343.  
  344.  
  345. function raw($uuid)
  346. {
  347. if ( ! $this->_me_or_admin($uuid) ) {
  348. return redirect('user/index');
  349. }
  350. $data['user_data'] = $this->simiangrid->get_user($uuid);
  351. parse_template('user/raw', $data, true);
  352. }
  353.  
  354. function _change_password($uuid)
  355. {
  356. # $success = false;
  357.  
  358. $val = $this->form_validation;
  359. $val->set_rules('password', 'Password', 'trim|required|xss_clean|min_length[6]|max_length[30]');
  360.  
  361. if ( $val->run() ) {
  362. $password = $val->set_value('password');
  363. $user_data = $this->simiangrid->get_user($uuid);
  364. if ( $this->simiangrid->identity_set($uuid, 'md5hash', $user_data['Name'], '$1$' . md5($password)) ) {
  365. if ( $this->simiangrid->identity_set($uuid, 'a1hash', $user_data['Name'], md5($user_data['Name'] . ':Inventory:' . $password)) ) {
  366. $success = true;
  367. }
  368. }
  369. }
  370. $result = json_encode(array('success'=>$success));
  371. echo $result;
  372. return;
  373. }
  374.  
  375. function _change_access_level($uuid)
  376. {
  377. $val = $this->form_validation;
  378. $val->set_rules('value', 'access_level', 'trim|required|xss_clean|numeric');
  379.  
  380. if ( $val->run() ) {
  381. $level = $val->set_value('value');
  382. $levels = $this->sg_auth->access_level_map();
  383. if ( ! empty($levels[$level]) ) {
  384. if ( $this->simiangrid->set_access_level($uuid, $level) ) {
  385. echo $levels[$level];
  386. }
  387. }
  388. }
  389. return;
  390. }
  391.  
  392. function _load_access_level($uuid)
  393. {
  394. $user = $this->simiangrid->get_user($uuid);
  395. if ( $user != null ) {
  396. echo json_access_levels($user['AccessLevel']);
  397. }
  398. }
  399.  
  400. function _change_ban_status($uuid)
  401. {
  402. $val = $this->form_validation;
  403. $val->set_rules('value', 'access_level', 'trim|required|xss_clean');
  404.  
  405. if ( $val->run() ) {
  406. $real_val = $val->set_value('value');
  407.  
  408. if ( $real_val == 'true' ) {
  409. $status = true;
  410. } else if ( $real_val == 'false' ) {
  411. $status = false;
  412. } else {
  413. return;
  414. }
  415. if ( $status ) {
  416. $result = $this->sg_auth->ban_user($uuid);
  417. } else {
  418. $result = $this->sg_auth->unban_user($uuid);
  419. }
  420. if ( $result ) {
  421. if ( $status ) {
  422. echo lang('sg_auth_banned');
  423. } else {
  424. echo lang('sg_auth_not_banned');
  425. }
  426. }
  427. }
  428. return;
  429. }
  430.  
  431. function _load_ban_status($uuid)
  432. {
  433. $ban_data = array(
  434. 'true' => lang('sg_auth_banned'),
  435. 'false' => lang('sg_auth_not_banned')
  436. );
  437. if ( $this->sg_auth->is_banned($uuid) ) {
  438. $ban_data['selected'] = 'true';
  439. } else {
  440. $ban_data['selected'] = 'false';
  441. }
  442. echo json_encode($ban_data);
  443. }
  444.  
  445. function _change_validation_status($uuid)
  446. {
  447. $val = $this->form_validation;
  448. $val->set_rules('value', 'validation_status', 'trim|required|xss_clean');
  449.  
  450. if ( $val->run() ) {
  451. $real_val = $val->set_value('value');
  452.  
  453. if ( $real_val == 'true' ) {
  454. $status = true;
  455. } else if ( $real_val == 'false' ) {
  456. $status = false;
  457. } else {
  458. return;
  459. }
  460. if ( $status ) {
  461. $result = $this->sg_auth->set_valid($uuid);
  462. } else {
  463. $result = $this->sg_auth->reset_validation($uuid);
  464. }
  465. if ( $result ) {
  466. if ( $status ) {
  467. echo lang('sg_auth_validated');
  468. } else {
  469. echo lang('sg_auth_not_validated');
  470. }
  471. }
  472. }
  473. return;
  474. }
  475.  
  476. function _load_validation_status($uuid)
  477. {
  478. $validation_data = array(
  479. 'true' => lang('sg_auth_validated'),
  480. 'false' => lang('sg_auth_not_validated')
  481. );
  482. if ( $this->sg_auth->is_validated($uuid) ) {
  483. $validation_data['selected'] = 'true';
  484. } else {
  485. $validation_data['selected'] = 'false';
  486. }
  487. echo json_encode($validation_data);
  488. }
  489.  
  490. function _get_language($uuid)
  491. {
  492. return get_language($uuid);
  493. }
  494.  
  495. function _load_language($uuid)
  496. {
  497. $current_language = $this->_get_language($uuid);
  498. $languages = $this->config->item('languages');
  499. $result = array();
  500. foreach ( $languages as $language ) {
  501. $language_name = lang("sg_lang_$language");
  502. if ( $language_name == null ) {
  503. $language_name = $language;
  504. }
  505. $result[$language] = $language_name;
  506. }
  507. echo json_encode($result);
  508. }
  509.  
  510. function _change_language($uuid)
  511. {
  512. $val = $this->form_validation;
  513. $val->set_rules('value', '', 'trim|required|xss_clean');
  514.  
  515. if ( $val->run() ) {
  516. $language = $val->set_value('value');
  517. $languages = $this->config->item('languages');
  518. if ( array_search($language, $languages) !== false ) {
  519. $this->user_settings->set_language($uuid, $language);
  520. }
  521. }
  522. }
  523.  
  524. function _get_search_flag($uuid)
  525. {
  526. $user = $this->simiangrid->get_user($uuid);
  527. $search_flag = $this->config->item('user_search_default');
  528. if ( isset($user['AllowPublish']) ) {
  529. $search_flag = $user['AllowPublish'];
  530. }
  531. return $search_flag;
  532. }
  533.  
  534. function _change_search_flag($uuid)
  535. {
  536. $val = $this->form_validation;
  537. $val->set_rules('value', '', 'trim|required|xss_clean');
  538.  
  539. if ( $val->run() ) {
  540. $raw_flag = $val->set_value('value');
  541. if ( $raw_flag == "true" ) {
  542. $flag = true;
  543. } else if ( $raw_flag == "false" ) {
  544. $flag = false;
  545. } else {
  546. log_message('error', "_change_search_flag unknown flag $flag");
  547. return;
  548. }
  549. $this->simiangrid->set_user_data($uuid, 'AllowPublish', $flag);
  550. if ( $flag ) {
  551. echo lang('sg_user_search_public');
  552. } else {
  553. echo lang('sg_user_search_private');
  554. }
  555. }
  556. }
  557.  
  558. function _load_search_flag($uuid)
  559. {
  560. $search_flags = array(
  561. 'true' => lang('sg_user_search_public'),
  562. 'false' => lang('sg_user_search_private')
  563. );
  564. if ( $this->_get_search_flag($uuid) ) {
  565. $search_flags['selected'] = 'true';
  566. } else {
  567. $search_flags['selected'] = 'false';
  568. }
  569. echo json_encode($search_flags);
  570. }
  571.  
  572. function _reset_avatar($uuid)
  573. {
  574. if ( ! $this->simiangrid->create_avatar($uuid, "DefaultAvatar") ) {
  575. push_message(set_message('sg_avatar_reset_fail', 'Backend Failure'), 'error');
  576. }
  577. return redirect('user/view/' . $uuid, 'location');
  578. }
  579.  
  580. function admin_actions($uuid, $action=null)
  581. {
  582. if ( ! $this->sg_auth->is_admin($uuid) ) {
  583. return redirect('user/index');
  584. }
  585. $user = $this->simiangrid->get_user($uuid);
  586. if ( $user == null ) {
  587. push_message(set_message('sg_user_not_found', $uuid), 'error');
  588. return redirect('user/');
  589. }
  590. if ( $action == "change_access_level" && $this->sg_auth->is_admin() ) {
  591. return $this->_change_access_level($uuid);
  592. } else if ( $action == "load_access_level" && $this->sg_auth->is_admin() ) {
  593. return $this->_load_access_level($uuid);
  594. } else if ( $action == "change_ban_status" && $this->sg_auth->is_admin() ) {
  595. return $this->_change_ban_status($uuid);
  596. } else if ( $action == "load_ban_status" ) {
  597. return $this->_load_ban_status($uuid);
  598. } else if ( $action == "change_validation_status" && $this->sg_auth->is_admin() ) {
  599. return $this->_change_validation_status($uuid);
  600. } else if ( $action == "load_validation_status" ) {
  601. return $this->_load_validation_status($uuid);
  602. } else if ( $action == "reset_avatar" ) {
  603. return $this->_reset_avatar($uuid);
  604. } else {
  605. $data['user_id'] = $uuid;
  606. $data['user_data'] = $this->simiangrid->get_user($uuid);
  607. $data['my_uuid'] = $this->sg_auth->get_uuid();
  608. if ( $this->sg_auth->is_banned($uuid) ) {
  609. $data['banned'] = lang('sg_auth_banned');
  610. } else {
  611. $data['banned'] = lang('sg_auth_not_banned');
  612. }
  613. if ( $this->sg_auth->is_validated($uuid) ) {
  614. $data['validation'] = lang('sg_auth_validated');
  615. } else {
  616. $data['validation'] = lang('sg_auth_not_validated');
  617. }
  618. return parse_template('user/admin_actions', $data, true);
  619. }
  620. }
  621.  
  622. function actions($uuid, $action=null)
  623. {
  624. if ( ! $this->_me_or_admin($uuid) ) {
  625. return redirect('about');
  626. }
  627. $user = $this->simiangrid->get_user($uuid);
  628. if ( $user == null ) {
  629. push_message(set_message('sg_user_not_found', $uuid), 'error');
  630. return redirect('user/');
  631. }
  632. if ( $action == "change_password" ) {
  633. return $this->_change_password($uuid);
  634. } else if ( $action == "change_language" ) {
  635. return $this->_change_language($uuid);
  636. } else if ( $action == "load_language") {
  637. return $this->_load_language($uuid);
  638. } else if ( $action == "change_search_flag" ) {
  639. return $this->_change_search_flag($uuid);
  640. } else if ( $action == "load_search_flag" ) {
  641. return $this->_load_search_flag($uuid);
  642. } else {
  643. $data['user_id'] = $uuid;
  644. $data['user_data'] = $this->simiangrid->get_user($uuid);
  645. $data['my_uuid'] = $this->sg_auth->get_uuid();
  646. $data['language'] = $this->_get_language($uuid);
  647. if ( $this->_get_search_flag($uuid) ) {
  648. $data['search_visibility'] = lang('sg_user_search_public');
  649. } else {
  650. $data['search_visibility'] = lang('sg_user_search_private');
  651. }
  652. return parse_template('user/actions', $data, true);
  653. }
  654. }
  655. }
Add Comment
Please, Sign In to add comment