PageRenderTime 35ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 1ms

/cp/expressionengine/modules/member/mod.member.php

https://bitbucket.org/sbeuken/artelux
PHP | 2909 lines | 1878 code | 562 blank | 469 comment | 296 complexity | bbe0cc74ec60d51121bfe81aac759ac0 MD5 | raw file
  1. <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
  2. /**
  3. * ExpressionEngine - by EllisLab
  4. *
  5. * @package ExpressionEngine
  6. * @author EllisLab Dev Team
  7. * @copyright Copyright (c) 2003 - 2012, EllisLab, Inc.
  8. * @license http://ellislab.com/expressionengine/user-guide/license.html
  9. * @link http://ellislab.com
  10. * @since Version 2.0
  11. * @filesource
  12. */
  13. // --------------------------------------------------------------------
  14. /**
  15. * Member Management Class
  16. *
  17. * @package ExpressionEngine
  18. * @subpackage Modules
  19. * @category Modules
  20. * @author EllisLab Dev Team
  21. * @link http://ellislab.com
  22. */
  23. /*
  24. Multi Site Login
  25. The login routine can set cookies for multiple domains if needed.
  26. This allows users who run separate domains for each channel to have
  27. a way to enable users to log-in once and remain logged-in across
  28. domains. In order to use this feature this array index must be
  29. added to the config file:
  30. $config['multi_login_sites'] = "http://www.siteone.com/|http://www.sitetwo.com";
  31. Separate each domain with a pipe.
  32. */
  33. class Member {
  34. var $trigger = 'member';
  35. var $theme_class = 'profile_theme';
  36. var $request = 'public_profile';
  37. var $no_menu = array(
  38. 'public_profile', 'memberlist', 'do_member_search',
  39. 'member_search', 'register', 'smileys', 'login',
  40. 'unpw_update', 'email_console', 'send_email',
  41. 'aim_console', 'icq_console', 'forgot_password',
  42. 'delete', 'member_mini_search', 'do_member_mini_search'
  43. );
  44. var $no_login = array(
  45. 'public_profile', 'memberlist', 'do_member_search',
  46. 'member_search', 'register', 'forgot_password', 'unpw_update'
  47. );
  48. var $id_override = array(
  49. 'edit_subscriptions', 'memberlist', 'member_search',
  50. 'browse_avatars', 'messages', 'unpw_update'
  51. );
  52. var $no_breadcrumb = array(
  53. 'email_console', 'send_email', 'aim_console',
  54. 'icq_console', 'member_mini_search', 'do_member_mini_search'
  55. );
  56. var $simple_page = array(
  57. 'email_console', 'send_email', 'aim_console',
  58. 'icq_console', 'smileys', 'member_mini_search', 'do_member_mini_search'
  59. );
  60. var $page_title = '';
  61. var $basepath = '';
  62. var $forum_path = '';
  63. var $image_url = '';
  64. var $theme_path = '';
  65. var $cur_id = '';
  66. var $uri_extra = '';
  67. var $return_data = '';
  68. var $javascript = '';
  69. var $head_extra = '';
  70. var $var_single = '';
  71. var $var_pair = '';
  72. var $var_cond = '';
  73. var $css_file_path = '';
  74. var $board_id = '';
  75. var $show_headings = TRUE;
  76. var $in_forum = FALSE;
  77. var $is_admin = FALSE;
  78. var $breadcrumb = TRUE;
  79. var $us_datecodes = array('long' => '%F %d, %Y &nbsp;%h:%i %A');
  80. var $eu_datecodes = array('long' => '%d %F, %Y &nbsp;%H:%i');
  81. var $crumb_map = array(
  82. 'profile' => 'your_control_panel',
  83. 'delete' => 'mbr_delete',
  84. 'forgot_password' => 'mbr_forgotten_password',
  85. 'login' => 'mbr_login',
  86. 'unpw_update' => 'settings_update',
  87. 'register' => 'mbr_member_registration',
  88. 'email' => 'mbr_email_member',
  89. 'send_email' => 'mbr_send_email',
  90. 'aim' => 'mbr_aim_console',
  91. 'icq' => 'mbr_icq_console',
  92. 'profile_main' => 'mbr_my_account',
  93. 'edit_profile' => 'mbr_edit_your_profile',
  94. 'edit_email' => 'email_settings',
  95. 'edit_userpass' => 'username_and_password',
  96. 'edit_localization' => 'localization_settings',
  97. 'edit_subscriptions' => 'subscriptions',
  98. 'edit_ignore_list' => 'ignore_list',
  99. 'edit_notepad' => 'notepad',
  100. 'edit_avatar' => 'edit_avatar',
  101. 'edit_photo' => 'edit_photo',
  102. 'edit_preferences' => 'edit_preferences',
  103. 'update_preferences' => 'update_preferences',
  104. 'upload_photo' => 'update_photo',
  105. 'browse_avatars' => 'browse_avatars',
  106. 'update_profile' => 'profile_updated',
  107. 'update_email' => 'mbr_email_updated',
  108. 'update_userpass' => 'username_and_password',
  109. 'update_localization' => 'localization_settings',
  110. 'update_subscriptions' => 'subscription_manager',
  111. 'update_ignore_list' => 'ignore_list',
  112. 'update_notepad' => 'notepad',
  113. 'select_avatar' => 'update_avatar',
  114. 'upload_avatar' => 'upload_avatar',
  115. 'update_avatar' => 'update_avatar',
  116. 'pm_view' => 'private_messages',
  117. 'pm' => 'compose_message',
  118. 'view_folder' => 'view_folder',
  119. 'view_message' => 'view_message',
  120. 'edit_signature' => 'edit_signature',
  121. 'update_signature' => 'update_signature',
  122. 'compose' => 'compose_message',
  123. 'deleted' => 'deleted_messages',
  124. 'folders' => 'edit_folders',
  125. 'buddies' => 'buddy_list',
  126. 'blocked' => 'blocked_list',
  127. 'edit_folders' => 'edit_folders',
  128. 'inbox' => 'view_folder',
  129. 'edit_list' => 'edit_list',
  130. 'send_message' => 'view_folder',
  131. 'modify_messages' => 'private_messages',
  132. 'bulletin_board' => 'bulletin_board',
  133. 'send_bulletin' => 'send_bulletin',
  134. 'sending_bulletin' => 'sending_bulletin'
  135. );
  136. /**
  137. * Constructor
  138. */
  139. function __construct()
  140. {
  141. $this->EE =& get_instance();
  142. $this->EE->lang->loadfile('myaccount');
  143. $this->EE->lang->loadfile('member');
  144. $this->EE->functions->template_type = 'webpage';
  145. $this->EE->db->cache_off();
  146. }
  147. // --------------------------------------------------------------------
  148. /**
  149. * Prep the Request String
  150. */
  151. public function _prep_request()
  152. {
  153. // Typcially the profile page URLs will be something like:
  154. //
  155. // index.php/member/123/
  156. // index.php/member/memberlist/
  157. // index.php/member/profile/
  158. // etc...
  159. //
  160. // The second segment will be assigned to the $this->request variable.
  161. // This determines what page is shown. Anything after that will normally
  162. // be an ID number, so we'll assign it to the $this->cur_id variable.
  163. $this->EE->load->helper('string');
  164. $this->request = trim_slashes($this->EE->uri->uri_string);
  165. if (FALSE !== ($pos = strpos($this->request, $this->trigger.'/')))
  166. {
  167. $this->request = substr($this->request, $pos);
  168. }
  169. if (preg_match("#/simple#", $this->request))
  170. {
  171. $this->request = str_replace("/simple", '', $this->request);
  172. $this->show_headings = FALSE;
  173. }
  174. if ($this->request == $this->trigger)
  175. {
  176. $this->request = '';
  177. }
  178. elseif (strpos($this->request, '/') !== FALSE)
  179. {
  180. $xr = explode("/", $this->request);
  181. $this->request = str_replace(current($xr).'/', '', $this->request);
  182. }
  183. // Determine the ID number, if any
  184. $this->cur_id = '';
  185. if (strpos($this->request, '/') !== FALSE)
  186. {
  187. $x = explode("/", $this->request);
  188. if (count($x) > 2)
  189. {
  190. $this->request = $x[0];
  191. $this->cur_id = $x[1];
  192. $this->uri_extra = $x[2];
  193. }
  194. else
  195. {
  196. $this->request = $x[0];
  197. $this->cur_id = $x[1];
  198. }
  199. }
  200. // Is this a public profile request?
  201. // Public member profiles are found at:
  202. //
  203. // index.php/member/123/
  204. //
  205. // Since the second segment contains a number instead of the
  206. // normal text string we know it's a public profile request.
  207. // We'll do a little reassignment...
  208. if (is_numeric($this->request))
  209. {
  210. $this->cur_id = $this->request;
  211. $this->request = 'public_profile';
  212. }
  213. if ($this->request == '')
  214. {
  215. $this->request = 'public_profile';
  216. }
  217. // Disable the full page view
  218. if (in_array($this->request, $this->simple_page))
  219. {
  220. $this->show_headings = FALSE;
  221. }
  222. if (in_array($this->request, $this->no_breadcrumb))
  223. {
  224. $this->breadcrumb = FALSE;
  225. }
  226. // Validate ID number
  227. // The $this->cur_id variable can only contain a number.
  228. // There are a few exceptions like the memberlist page and the
  229. // subscriptions page
  230. if ( ! in_array($this->request, $this->id_override) &&
  231. $this->cur_id != '' && ! is_numeric($this->cur_id))
  232. {
  233. return FALSE;
  234. }
  235. return TRUE;
  236. }
  237. // --------------------------------------------------------------------
  238. /**
  239. * Run the Member Class
  240. */
  241. public function manager()
  242. {
  243. // Prep the request
  244. if ( ! $this->_prep_request())
  245. {
  246. $this->_show_404_template();
  247. }
  248. // -------------------------------------------
  249. // 'member_manager' hook.
  250. // - Seize control over any Member Module user side request
  251. // - Added: 1.5.2
  252. //
  253. if ($this->EE->extensions->active_hook('member_manager') === TRUE)
  254. {
  255. $edata = $this->EE->extensions->universal_call('member_manager', $this);
  256. if ($this->EE->extensions->end_script === TRUE) return $edata;
  257. }
  258. //
  259. // -------------------------------------------
  260. // Is the user logged in?
  261. if ($this->request != 'login' &&
  262. ! in_array($this->request, $this->no_login) &&
  263. $this->EE->session->userdata('member_id') == 0)
  264. {
  265. return $this->_final_prep($this->profile_login_form('self'));
  266. }
  267. // Left-side Menu
  268. $left = ( ! in_array($this->request, $this->no_menu)) ? $this->profile_menu() : '';
  269. // Validate the request
  270. $methods = array(
  271. 'public_profile',
  272. 'memberlist',
  273. 'member_search',
  274. 'do_member_search',
  275. 'login',
  276. 'unpw_update',
  277. 'register',
  278. 'profile',
  279. 'edit_preferences',
  280. 'update_preferences',
  281. 'edit_profile',
  282. 'update_profile',
  283. 'edit_email',
  284. 'update_email',
  285. 'edit_userpass',
  286. 'update_userpass',
  287. 'edit_localization',
  288. 'update_localization',
  289. 'edit_notepad',
  290. 'update_notepad',
  291. 'edit_signature',
  292. 'update_signature',
  293. 'edit_avatar',
  294. 'browse_avatars',
  295. 'select_avatar',
  296. 'upload_avatar',
  297. 'edit_photo',
  298. 'upload_photo',
  299. 'edit_subscriptions',
  300. 'update_subscriptions',
  301. 'edit_ignore_list',
  302. 'update_ignore_list',
  303. 'member_mini_search',
  304. 'do_member_mini_search',
  305. 'email_console',
  306. 'aim_console',
  307. 'icq_console',
  308. 'send_email',
  309. 'forgot_password',
  310. 'smileys',
  311. 'messages',
  312. 'delete'
  313. );
  314. if ( ! in_array($this->request, $methods))
  315. {
  316. $this->_show_404_template();
  317. }
  318. // Call the requested function
  319. if ($this->request == 'profile') $this->request = 'profile_main';
  320. if ($this->request == 'register') $this->request = 'registration_form';
  321. if ($this->cur_id == 'member_search') {$left = ''; $this->breadcrumb = FALSE; $this->show_headings = FALSE;}
  322. if ($this->cur_id == 'do_member_search') {$left = ''; $this->breadcrumb = FALSE; $this->show_headings = FALSE;}
  323. if ($this->cur_id == 'buddy_search') {$left = ''; $this->breadcrumb = FALSE; $this->show_headings = FALSE;}
  324. if ($this->cur_id == 'do_buddy_search') {$left = ''; $this->breadcrumb = FALSE; $this->show_headings = FALSE;}
  325. $function = $this->request;
  326. if (in_array($function, array('upload_photo', 'upload_avatar', 'upload_signature_image', '_upload_image')))
  327. {
  328. require_once PATH_MOD.'member/mod.member_images.php';
  329. $MI = new Member_images();
  330. foreach(get_object_vars($this) as $key => $value)
  331. {
  332. $MI->{$key} = $value;
  333. }
  334. $content = $MI->$function();
  335. }
  336. else
  337. {
  338. $content = $this->$function();
  339. }
  340. if ($this->cur_id == 'edit_folders') {$left = $this->profile_menu();}
  341. if ($this->cur_id == 'send_message') {$left = $this->profile_menu();}
  342. // Parse the template the template
  343. if ($left == '')
  344. {
  345. $out = $this->_var_swap($this->_load_element('basic_profile'),
  346. array(
  347. 'include:content' => $content
  348. )
  349. );
  350. }
  351. else
  352. {
  353. $out = $this->_var_swap($this->_load_element('full_profile'),
  354. array(
  355. 'include:menu' => $left,
  356. 'include:content' => $content
  357. )
  358. );
  359. }
  360. // Output the finalized request
  361. return $this->_final_prep($out);
  362. }
  363. // --------------------------------------------------------------------
  364. /**
  365. * Private Messages
  366. */
  367. public function messages()
  368. {
  369. if (($this->EE->session->userdata('can_send_private_messages') != 'y' &&
  370. $this->EE->session->userdata('group_id') != '1') OR
  371. $this->EE->session->userdata('accept_messages') != 'y')
  372. {
  373. return $this->profile_main();
  374. }
  375. if ( ! class_exists('EE_Messages'))
  376. {
  377. require APPPATH.'libraries/Messages.php';
  378. }
  379. $MESS = new EE_Messages;
  380. $MESS->base_url = $this->_member_path('messages').'/';
  381. $MESS->allegiance = 'user';
  382. $MESS->theme_path = $this->theme_path;
  383. $MESS->request = $this->cur_id;
  384. $MESS->cur_id = $this->uri_extra;
  385. $MESS->MS =& $this;
  386. $MESS->manager();
  387. $this->page_title = $MESS->title;
  388. $this->head_extra = $MESS->header_javascript;
  389. return $MESS->return_data;
  390. }
  391. // --------------------------------------------------------------------
  392. /**
  393. * Member Profile - Menu
  394. */
  395. public function profile_menu()
  396. {
  397. if ( ! class_exists('Member_settings'))
  398. {
  399. require PATH_MOD.'member/mod.member_settings.php';
  400. }
  401. $MS = new Member_settings();
  402. foreach(get_object_vars($this) as $key => $value)
  403. {
  404. $MS->{$key} = $value;
  405. }
  406. return $MS->profile_menu();
  407. }
  408. // --------------------------------------------------------------------
  409. /**
  410. * Private Messages - Menu
  411. */
  412. public function pm_menu()
  413. {
  414. if (($this->EE->session->userdata('can_send_private_messages') != 'y' &&
  415. $this->EE->session->userdata('group_id') != '1') OR
  416. $this->EE->session->userdata('accept_messages') != 'y')
  417. {
  418. return;
  419. }
  420. if ( ! class_exists('EE_Messages'))
  421. {
  422. require APPPATH.'libraries/Messages.php';
  423. }
  424. $MESS = new EE_Messages;
  425. $MESS->base_url = $this->_member_path('messages');
  426. $MESS->allegiance = 'user';
  427. $MESS->theme_path = $this->theme_path;
  428. $MESS->MS =& $this;
  429. $MESS->create_menu();
  430. return $MESS->menu;
  431. }
  432. // --------------------------------------------------------------------
  433. /**
  434. * Member Profile Main Page
  435. */
  436. public function profile_main()
  437. {
  438. if ( ! class_exists('Member_settings'))
  439. {
  440. require PATH_MOD.'member/mod.member_settings.php';
  441. }
  442. $MS = new Member_settings();
  443. foreach(get_object_vars($this) as $key => $value)
  444. {
  445. $MS->{$key} = $value;
  446. }
  447. return $MS->profile_main();
  448. }
  449. // --------------------------------------------------------------------
  450. /**
  451. * Member Public Profile
  452. */
  453. public function public_profile()
  454. {
  455. if ( ! class_exists('Member_settings'))
  456. {
  457. require PATH_MOD.'member/mod.member_settings.php';
  458. }
  459. $MS = new Member_settings();
  460. foreach(get_object_vars($this) as $key => $value)
  461. {
  462. $MS->{$key} = $value;
  463. }
  464. return $MS->public_profile();
  465. }
  466. // --------------------------------------------------------------------
  467. /**
  468. * Login Page
  469. */
  470. public function profile_login_form($return = '-2')
  471. {
  472. if ( ! class_exists('Member_auth'))
  473. {
  474. require PATH_MOD.'member/mod.member_auth.php';
  475. }
  476. $MA = new Member_auth();
  477. foreach(get_object_vars($this) as $key => $value)
  478. {
  479. $MA->{$key} = $value;
  480. }
  481. return $MA->profile_login_form($return);
  482. }
  483. // --------------------------------------------------------------------
  484. /**
  485. * Member Profile Edit Page
  486. */
  487. public function edit_profile()
  488. {
  489. if ( ! class_exists('Member_settings'))
  490. {
  491. require PATH_MOD.'member/mod.member_settings.php';
  492. }
  493. $MS = new Member_settings();
  494. foreach(get_object_vars($this) as $key => $value)
  495. {
  496. $MS->{$key} = $value;
  497. }
  498. return $MS->edit_profile();
  499. }
  500. // --------------------------------------------------------------------
  501. /**
  502. * Profile Update
  503. */
  504. public function update_profile()
  505. {
  506. if ( ! class_exists('Member_settings'))
  507. {
  508. require PATH_MOD.'member/mod.member_settings.php';
  509. }
  510. $MS = new Member_settings();
  511. foreach(get_object_vars($this) as $key => $value)
  512. {
  513. $MS->{$key} = $value;
  514. }
  515. return $MS->update_profile();
  516. }
  517. // --------------------------------------------------------------------
  518. /**
  519. * Forum Preferences
  520. */
  521. public function edit_preferences()
  522. {
  523. if ( ! class_exists('Member_settings'))
  524. {
  525. require PATH_MOD.'member/mod.member_settings.php';
  526. }
  527. $MS = new Member_settings();
  528. foreach(get_object_vars($this) as $key => $value)
  529. {
  530. $MS->{$key} = $value;
  531. }
  532. return $MS->edit_preferences();
  533. }
  534. // --------------------------------------------------------------------
  535. /**
  536. * Update Preferences
  537. */
  538. public function update_preferences()
  539. {
  540. if ( ! class_exists('Member_settings'))
  541. {
  542. require PATH_MOD.'member/mod.member_settings.php';
  543. }
  544. $MS = new Member_settings();
  545. foreach(get_object_vars($this) as $key => $value)
  546. {
  547. $MS->{$key} = $value;
  548. }
  549. return $MS->update_preferences();
  550. }
  551. // --------------------------------------------------------------------
  552. /**
  553. * Email Settings
  554. */
  555. public function edit_email()
  556. {
  557. if ( ! class_exists('Member_settings'))
  558. {
  559. require PATH_MOD.'member/mod.member_settings.php';
  560. }
  561. $MS = new Member_settings();
  562. foreach(get_object_vars($this) as $key => $value)
  563. {
  564. $MS->{$key} = $value;
  565. }
  566. return $MS->edit_email();
  567. }
  568. // --------------------------------------------------------------------
  569. /**
  570. * Email Update
  571. */
  572. public function update_email()
  573. {
  574. if ( ! class_exists('Member_settings'))
  575. {
  576. require PATH_MOD.'member/mod.member_settings.php';
  577. }
  578. $MS = new Member_settings();
  579. foreach(get_object_vars($this) as $key => $value)
  580. {
  581. $MS->{$key} = $value;
  582. }
  583. return $MS->update_email();
  584. }
  585. // --------------------------------------------------------------------
  586. /**
  587. * Username/Password Preferences
  588. */
  589. public function edit_userpass()
  590. {
  591. if ( ! class_exists('Member_settings'))
  592. {
  593. require PATH_MOD.'member/mod.member_settings.php';
  594. }
  595. $MS = new Member_settings();
  596. foreach(get_object_vars($this) as $key => $value)
  597. {
  598. $MS->{$key} = $value;
  599. }
  600. return $MS->edit_userpass();
  601. }
  602. // --------------------------------------------------------------------
  603. /**
  604. * Username/Password Update
  605. */
  606. public function update_userpass()
  607. {
  608. if ( ! class_exists('Member_settings'))
  609. {
  610. require PATH_MOD.'member/mod.member_settings.php';
  611. }
  612. $MS = new Member_settings();
  613. foreach(get_object_vars($this) as $key => $value)
  614. {
  615. $MS->{$key} = $value;
  616. }
  617. return $MS->update_userpass();
  618. }
  619. // --------------------------------------------------------------------
  620. /**
  621. * Localization Edit Form
  622. */
  623. public function edit_localization()
  624. {
  625. if ( ! class_exists('Member_settings'))
  626. {
  627. require PATH_MOD.'member/mod.member_settings.php';
  628. }
  629. $MS = new Member_settings();
  630. foreach(get_object_vars($this) as $key => $value)
  631. {
  632. $MS->{$key} = $value;
  633. }
  634. return $MS->edit_localization();
  635. }
  636. // --------------------------------------------------------------------
  637. /**
  638. * Update Localization Prefs
  639. */
  640. public function update_localization()
  641. {
  642. if ( ! class_exists('Member_settings'))
  643. {
  644. require PATH_MOD.'member/mod.member_settings.php';
  645. }
  646. $MS = new Member_settings();
  647. foreach(get_object_vars($this) as $key => $value)
  648. {
  649. $MS->{$key} = $value;
  650. }
  651. return $MS->update_localization();
  652. }
  653. // --------------------------------------------------------------------
  654. /**
  655. * Signature Edit Form
  656. */
  657. public function edit_signature()
  658. {
  659. if ( ! class_exists('Member_images'))
  660. {
  661. require PATH_MOD.'member/mod.member_images.php';
  662. }
  663. $MI = new Member_images();
  664. foreach(get_object_vars($this) as $key => $value)
  665. {
  666. $MI->{$key} = $value;
  667. }
  668. return $MI->edit_signature();
  669. }
  670. // --------------------------------------------------------------------
  671. /**
  672. * Update Signature
  673. */
  674. public function update_signature()
  675. {
  676. if ( ! class_exists('Member_images'))
  677. {
  678. require PATH_MOD.'member/mod.member_images.php';
  679. }
  680. $MI = new Member_images();
  681. foreach(get_object_vars($this) as $key => $value)
  682. {
  683. $MI->{$key} = $value;
  684. }
  685. return $MI->update_signature();
  686. }
  687. // --------------------------------------------------------------------
  688. /**
  689. * Avatar Edit Form
  690. */
  691. public function edit_avatar()
  692. {
  693. if ( ! class_exists('Member_images'))
  694. {
  695. require PATH_MOD.'member/mod.member_images.php';
  696. }
  697. $MI = new Member_images();
  698. foreach(get_object_vars($this) as $key => $value)
  699. {
  700. $MI->{$key} = $value;
  701. }
  702. return $MI->edit_avatar();
  703. }
  704. // --------------------------------------------------------------------
  705. /**
  706. * Browse Avatars
  707. */
  708. public function browse_avatars()
  709. {
  710. if ( ! class_exists('Member_images'))
  711. {
  712. require PATH_MOD.'member/mod.member_images.php';
  713. }
  714. $MI = new Member_images();
  715. foreach(get_object_vars($this) as $key => $value)
  716. {
  717. $MI->{$key} = $value;
  718. }
  719. return $MI->browse_avatars();
  720. }
  721. // --------------------------------------------------------------------
  722. /**
  723. * Select Avatar From Library
  724. */
  725. public function select_avatar()
  726. {
  727. if ( ! class_exists('Member_images'))
  728. {
  729. require PATH_MOD.'member/mod.member_images.php';
  730. }
  731. $MI = new Member_images();
  732. foreach(get_object_vars($this) as $key => $value)
  733. {
  734. $MI->{$key} = $value;
  735. }
  736. return $MI->select_avatar();
  737. }
  738. // --------------------------------------------------------------------
  739. /**
  740. * Photo Edit Form
  741. */
  742. public function edit_photo()
  743. {
  744. if ( ! class_exists('Member_images'))
  745. {
  746. require PATH_MOD.'member/mod.member_images.php';
  747. }
  748. $MI = new Member_images();
  749. foreach(get_object_vars($this) as $key => $value)
  750. {
  751. $MI->{$key} = $value;
  752. }
  753. return $MI->edit_photo();
  754. }
  755. // --------------------------------------------------------------------
  756. /**
  757. * Notepad Edit Form
  758. */
  759. public function edit_notepad()
  760. {
  761. if ( ! class_exists('Member_settings'))
  762. {
  763. require PATH_MOD.'member/mod.member_settings.php';
  764. }
  765. $MS = new Member_settings();
  766. foreach(get_object_vars($this) as $key => $value)
  767. {
  768. $MS->{$key} = $value;
  769. }
  770. return $MS->edit_notepad();
  771. }
  772. // --------------------------------------------------------------------
  773. /**
  774. * Update Notepad
  775. */
  776. public function update_notepad()
  777. {
  778. if ( ! class_exists('Member_settings'))
  779. {
  780. require PATH_MOD.'member/mod.member_settings.php';
  781. }
  782. $MS = new Member_settings();
  783. foreach(get_object_vars($this) as $key => $value)
  784. {
  785. $MS->{$key} = $value;
  786. }
  787. return $MS->update_notepad();
  788. }
  789. // --------------------------------------------------------------------
  790. /**
  791. * Member Login
  792. */
  793. public function member_login()
  794. {
  795. if ( ! class_exists('Member_auth'))
  796. {
  797. require PATH_MOD.'member/mod.member_auth.php';
  798. }
  799. $MA = new Member_auth();
  800. foreach(get_object_vars($this) as $key => $value)
  801. {
  802. $MA->{$key} = $value;
  803. }
  804. $MA->member_login();
  805. }
  806. // --------------------------------------------------------------------
  807. /**
  808. * Member Logout
  809. */
  810. public function member_logout()
  811. {
  812. if ( ! class_exists('Member_auth'))
  813. {
  814. require PATH_MOD.'member/mod.member_auth.php';
  815. }
  816. $MA = new Member_auth();
  817. foreach(get_object_vars($this) as $key => $value)
  818. {
  819. $MA->{$key} = $value;
  820. }
  821. $MA->member_logout();
  822. }
  823. // --------------------------------------------------------------------
  824. /**
  825. * Member Forgot Password Form
  826. */
  827. public function forgot_password($ret = '-3')
  828. {
  829. if ( ! class_exists('Member_auth'))
  830. {
  831. require PATH_MOD.'member/mod.member_auth.php';
  832. }
  833. $MA = new Member_auth();
  834. foreach(get_object_vars($this) as $key => $value)
  835. {
  836. $MA->{$key} = $value;
  837. }
  838. return $MA->forgot_password($ret);
  839. }
  840. // --------------------------------------------------------------------
  841. /**
  842. * Retreive Forgotten Password
  843. */
  844. public function retrieve_password()
  845. {
  846. if ( ! class_exists('Member_auth'))
  847. {
  848. require PATH_MOD.'member/mod.member_auth.php';
  849. }
  850. $MA = new Member_auth();
  851. foreach(get_object_vars($this) as $key => $value)
  852. {
  853. $MA->{$key} = $value;
  854. }
  855. $MA->retrieve_password();
  856. }
  857. // --------------------------------------------------------------------
  858. /**
  859. * Reset the user's password
  860. */
  861. public function reset_password()
  862. {
  863. if ( ! class_exists('Member_auth'))
  864. {
  865. require PATH_MOD.'member/mod.member_auth.php';
  866. }
  867. $MA = new Member_auth();
  868. foreach(get_object_vars($this) as $key => $value)
  869. {
  870. $MA->{$key} = $value;
  871. }
  872. $MA->reset_password();
  873. }
  874. // --------------------------------------------------------------------
  875. /**
  876. * Subscriptions Edit Form
  877. */
  878. public function edit_subscriptions()
  879. {
  880. if ( ! class_exists('Member_subscriptions'))
  881. {
  882. require PATH_MOD.'member/mod.member_subscriptions.php';
  883. }
  884. $MS = new Member_subscriptions();
  885. foreach(get_object_vars($this) as $key => $value)
  886. {
  887. $MS->{$key} = $value;
  888. }
  889. return $MS->edit_subscriptions();
  890. }
  891. // --------------------------------------------------------------------
  892. /**
  893. * Update Subscriptions
  894. */
  895. public function update_subscriptions()
  896. {
  897. if ( ! class_exists('Member_subscriptions'))
  898. {
  899. require PATH_MOD.'member/mod.member_subscriptions.php';
  900. }
  901. $MS = new Member_subscriptions();
  902. foreach(get_object_vars($this) as $key => $value)
  903. {
  904. $MS->{$key} = $value;
  905. }
  906. return $MS->update_subscriptions();
  907. }
  908. // --------------------------------------------------------------------
  909. /**
  910. * Edit Ignore List Form
  911. */
  912. public function edit_ignore_list()
  913. {
  914. if ( ! class_exists('Member_settings'))
  915. {
  916. require PATH_MOD.'member/mod.member_settings.php';
  917. }
  918. $MS = new Member_settings();
  919. foreach(get_object_vars($this) as $key => $value)
  920. {
  921. $MS->{$key} = $value;
  922. }
  923. return $MS->edit_ignore_list();
  924. }
  925. // --------------------------------------------------------------------
  926. /**
  927. * Update Ignore List
  928. */
  929. public function update_ignore_list()
  930. {
  931. if ( ! class_exists('Member_settings'))
  932. {
  933. require PATH_MOD.'member/mod.member_settings.php';
  934. }
  935. $MS = new Member_settings();
  936. foreach(get_object_vars($this) as $key => $value)
  937. {
  938. $MS->{$key} = $value;
  939. }
  940. return $MS->update_ignore_list();
  941. }
  942. // --------------------------------------------------------------------
  943. /**
  944. * Member Mini Search
  945. */
  946. public function member_mini_search()
  947. {
  948. if ( ! class_exists('Member_settings'))
  949. {
  950. require PATH_MOD.'member/mod.member_settings.php';
  951. }
  952. $MS = new Member_settings();
  953. foreach(get_object_vars($this) as $key => $value)
  954. {
  955. $MS->{$key} = $value;
  956. }
  957. $this->_set_page_title($this->EE->lang->line('member_search'));
  958. return $MS->member_mini_search();
  959. }
  960. // --------------------------------------------------------------------
  961. /**
  962. * Do Member Mini Search
  963. */
  964. public function do_member_mini_search()
  965. {
  966. if ( ! class_exists('Member_settings'))
  967. {
  968. require PATH_MOD.'member/mod.member_settings.php';
  969. }
  970. $MS = new Member_settings();
  971. foreach(get_object_vars($this) as $key => $value)
  972. {
  973. $MS->{$key} = $value;
  974. }
  975. $this->_set_page_title($this->EE->lang->line('member_search'));
  976. return $MS->do_member_mini_search();
  977. }
  978. // --------------------------------------------------------------------
  979. /**
  980. * Member Registration Form
  981. */
  982. public function registration_form()
  983. {
  984. if ( ! class_exists('Member_register'))
  985. {
  986. require PATH_MOD.'member/mod.member_register.php';
  987. }
  988. $MR = new Member_register();
  989. foreach(get_object_vars($this) as $key => $value)
  990. {
  991. $MR->{$key} = $value;
  992. }
  993. return $MR->registration_form();
  994. }
  995. // --------------------------------------------------------------------
  996. /**
  997. * Register Member
  998. */
  999. public function register_member()
  1000. {
  1001. if ( ! class_exists('Member_register'))
  1002. {
  1003. require PATH_MOD.'member/mod.member_register.php';
  1004. }
  1005. $MR = new Member_register();
  1006. foreach(get_object_vars($this) as $key => $value)
  1007. {
  1008. $MR->{$key} = $value;
  1009. }
  1010. $MR->register_member();
  1011. }
  1012. // --------------------------------------------------------------------
  1013. /**
  1014. * Member Self-Activation
  1015. */
  1016. public function activate_member()
  1017. {
  1018. if ( ! class_exists('Member_register'))
  1019. {
  1020. require PATH_MOD.'member/mod.member_register.php';
  1021. }
  1022. $MR = new Member_register();
  1023. foreach(get_object_vars($this) as $key => $value)
  1024. {
  1025. $MR->{$key} = $value;
  1026. }
  1027. $MR->activate_member();
  1028. }
  1029. // --------------------------------------------------------------------
  1030. /**
  1031. * Delete Page
  1032. */
  1033. public function delete()
  1034. {
  1035. return $this->confirm_delete_form();
  1036. }
  1037. // --------------------------------------------------------------------
  1038. /**
  1039. * Self-delete confirmation form
  1040. */
  1041. public function confirm_delete_form()
  1042. {
  1043. if ($this->EE->session->userdata('can_delete_self') !== 'y')
  1044. {
  1045. return $this->EE->output->show_user_error('general', $this->EE->lang->line('cannot_delete_self'));
  1046. }
  1047. else
  1048. {
  1049. $delete_form = $this->_load_element('delete_confirmation_form');
  1050. $data['hidden_fields']['ACT'] = $this->EE->functions->fetch_action_id('Member', 'member_delete');
  1051. $data['onsubmit'] = "if( ! confirm('{lang:final_delete_confirm}')) return false;";
  1052. $data['id'] = 'member_delete_form';
  1053. $this->_set_page_title($this->EE->lang->line('member_delete'));
  1054. return $this->_var_swap($delete_form, array('form_declaration' => $this->EE->functions->form_declaration($data)));
  1055. }
  1056. }
  1057. // --------------------------------------------------------------------
  1058. /**
  1059. * Member self-delete
  1060. */
  1061. public function member_delete()
  1062. {
  1063. // Make sure they got here via a form
  1064. if ( ! $this->EE->input->post('ACT'))
  1065. {
  1066. // No output for you, Mr. URL Hax0r
  1067. return FALSE;
  1068. }
  1069. $this->EE->lang->loadfile('login');
  1070. // No sneakiness - we'll do this in case the site administrator
  1071. // has foolishly turned off secure forms and some monkey is
  1072. // trying to delete their account from an off-site form or
  1073. // after logging out.
  1074. if ($this->EE->session->userdata('member_id') == 0 OR
  1075. $this->EE->session->userdata('can_delete_self') !== 'y')
  1076. {
  1077. return $this->EE->output->show_user_error('general', $this->EE->lang->line('not_authorized'));
  1078. }
  1079. // If the user is a SuperAdmin, then no deletion
  1080. if ($this->EE->session->userdata('group_id') == 1)
  1081. {
  1082. return $this->EE->output->show_user_error('general', $this->EE->lang->line('cannot_delete_super_admin'));
  1083. }
  1084. // Is IP and User Agent required for login? Then, same here.
  1085. if ($this->EE->config->item('require_ip_for_login') == 'y')
  1086. {
  1087. if ($this->EE->session->userdata('ip_address') == '' OR
  1088. $this->EE->session->userdata('user_agent') == '')
  1089. {
  1090. return $this->EE->output->show_user_error('general', $this->EE->lang->line('unauthorized_request'));
  1091. }
  1092. }
  1093. // Check password lockout status
  1094. if ($this->EE->session->check_password_lockout($this->EE->session->userdata('username')) === TRUE)
  1095. {
  1096. $this->EE->lang->loadfile('login');
  1097. return $this->EE->output->show_user_error(
  1098. 'general',
  1099. sprintf(lang('password_lockout_in_effect'), $this->EE->config->item('password_lockout_interval'))
  1100. );
  1101. }
  1102. // Are you who you say you are, or someone sitting at someone
  1103. // else's computer being mean?!
  1104. $this->EE->load->library('auth');
  1105. if ( ! $this->EE->auth->authenticate_id($this->EE->session->userdata('member_id'),
  1106. $this->EE->input->post('password')))
  1107. {
  1108. $this->EE->session->save_password_lockout($this->EE->session->userdata('username'));
  1109. return $this->EE->output->show_user_error('general', $this->EE->lang->line('invalid_pw'));
  1110. }
  1111. // No turning back, get to deletin'!
  1112. $this->EE->load->model('member_model');
  1113. $this->EE->member_model->delete_member($this->EE->session->userdata('member_id'));
  1114. // Email notification recipients
  1115. if ($this->EE->session->userdata('mbr_delete_notify_emails') != '')
  1116. {
  1117. $notify_address = $this->EE->session->userdata('mbr_delete_notify_emails');
  1118. $swap = array(
  1119. 'name' => $this->EE->session->userdata('screen_name'),
  1120. 'email' => $this->EE->session->userdata('email'),
  1121. 'site_name' => stripslashes($this->EE->config->item('site_name'))
  1122. );
  1123. $email_subject = $this->EE->functions->var_swap($this->EE->lang->line('mbr_delete_notify_title'), $swap);
  1124. $email_msg = $this->EE->functions->var_swap($this->EE->lang->line('mbr_delete_notify_message'), $swap);
  1125. // No notification for the user themselves, if they're in the list
  1126. if (strpos($notify_address, $this->EE->session->userdata('email')) !== FALSE)
  1127. {
  1128. $notify_address = str_replace($this->EE->session->userdata('email'), "", $notify_address);
  1129. }
  1130. $this->EE->load->helper('string');
  1131. // Remove multiple commas
  1132. $notify_address = reduce_multiples($notify_address, ',', TRUE);
  1133. if ($notify_address != '')
  1134. {
  1135. // Send email
  1136. $this->EE->load->library('email');
  1137. // Load the text helper
  1138. $this->EE->load->helper('text');
  1139. foreach (explode(',', $notify_address) as $addy)
  1140. {
  1141. $this->EE->email->EE_initialize();
  1142. $this->EE->email->wordwrap = FALSE;
  1143. $this->EE->email->from($this->EE->config->item('webmaster_email'), $this->EE->config->item('webmaster_name'));
  1144. $this->EE->email->to($addy);
  1145. $this->EE->email->reply_to($this->EE->config->item('webmaster_email'));
  1146. $this->EE->email->subject($email_subject);
  1147. $this->EE->email->message(entities_to_ascii($email_msg));
  1148. $this->EE->email->send();
  1149. }
  1150. }
  1151. }
  1152. $this->EE->db->where('session_id', $this->EE->session->userdata('session_id'))
  1153. ->delete('sessions');
  1154. $this->EE->functions->set_cookie($this->EE->session->c_session);
  1155. $this->EE->functions->set_cookie($this->EE->session->c_expire);
  1156. $this->EE->functions->set_cookie($this->EE->session->c_anon);
  1157. $this->EE->functions->set_cookie('read_topics');
  1158. $this->EE->functions->set_cookie('tracker');
  1159. // Build Success Message
  1160. $url = $this->EE->config->item('site_url');
  1161. $name = stripslashes($this->EE->config->item('site_name'));
  1162. $data = array( 'title' => $this->EE->lang->line('mbr_delete'),
  1163. 'heading' => $this->EE->lang->line('thank_you'),
  1164. 'content' => $this->EE->lang->line('mbr_account_deleted'),
  1165. 'redirect' => '',
  1166. 'link' => array($url, $name)
  1167. );
  1168. $this->EE->output->show_message($data);
  1169. }
  1170. // --------------------------------------------------------------------
  1171. /**
  1172. * Login Page
  1173. */
  1174. public function login()
  1175. {
  1176. return $this->profile_login_form();
  1177. }
  1178. // --------------------------------------------------------------------
  1179. /**
  1180. * Manual Login Form
  1181. *
  1182. * This lets users create a stand-alone login form in any template
  1183. */
  1184. public function login_form()
  1185. {
  1186. if ($this->EE->config->item('user_session_type') != 'c')
  1187. {
  1188. $this->EE->TMPL->tagdata = preg_replace("/{if\s+auto_login}.*?{".'\/'."if}/s", '', $this->EE->TMPL->tagdata);
  1189. }
  1190. else
  1191. {
  1192. $this->EE->TMPL->tagdata = preg_replace("/{if\s+auto_login}(.*?){".'\/'."if}/s", "\\1", $this->EE->TMPL->tagdata);
  1193. }
  1194. // Create form
  1195. $data['hidden_fields'] = array(
  1196. 'ACT' => $this->EE->functions->fetch_action_id('Member', 'member_login'),
  1197. 'RET' => ($this->EE->TMPL->fetch_param('return') && $this->EE->TMPL->fetch_param('return') != "") ? $this->EE->TMPL->fetch_param('return') : '-2'
  1198. );
  1199. if ($this->EE->TMPL->fetch_param('name') !== FALSE &&
  1200. preg_match("#^[a-zA-Z0-9_\-]+$#i", $this->EE->TMPL->fetch_param('name'), $match))
  1201. {
  1202. $data['name'] = $this->EE->TMPL->fetch_param('name');
  1203. $this->EE->TMPL->log_item('Member Login Form: The \'name\' parameter has been deprecated. Please use form_name');
  1204. }
  1205. elseif ($this->EE->TMPL->fetch_param('form_name') && $this->EE->TMPL->fetch_param('form_name') != "")
  1206. {
  1207. $data['name'] = $this->EE->TMPL->fetch_param('form_name');
  1208. }
  1209. if ($this->EE->TMPL->fetch_param('id') !== FALSE &&
  1210. preg_match("#^[a-zA-Z0-9_\-]+$#i", $this->EE->TMPL->fetch_param('id')))
  1211. {
  1212. $data['id'] = $this->EE->TMPL->fetch_param('id');
  1213. $this->EE->TMPL->log_item('Member Login Form: The \'id\' parameter has been deprecated. Please use form_id');
  1214. }
  1215. else
  1216. {
  1217. $data['id'] = $this->EE->TMPL->form_id;
  1218. }
  1219. $data['class'] = $this->EE->TMPL->form_class;
  1220. $res = $this->EE->functions->form_declaration($data);
  1221. $res .= stripslashes($this->EE->TMPL->tagdata);
  1222. $res .= "</form>";
  1223. return $res;
  1224. }
  1225. // --------------------------------------------------------------------
  1226. /**
  1227. * Username/password update
  1228. */
  1229. public function unpw_update()
  1230. {
  1231. if ( ! class_exists('Member_settings'))
  1232. {
  1233. require PATH_MOD.'member/mod.member_settings.php';
  1234. }
  1235. $MS = new Member_settings();
  1236. foreach(get_object_vars($this) as $key => $value)
  1237. {
  1238. $MS->{$key} = $value;
  1239. }
  1240. return $MS->unpw_update();
  1241. }
  1242. // --------------------------------------------------------------------
  1243. /**
  1244. * Update the username/password
  1245. */
  1246. public function update_un_pw()
  1247. {
  1248. if ( ! class_exists('Member_settings'))
  1249. {
  1250. require PATH_MOD.'member/mod.member_settings.php';
  1251. }
  1252. $MS = new Member_settings();
  1253. foreach(get_object_vars($this) as $key => $value)
  1254. {
  1255. $MS->{$key} = $value;
  1256. }
  1257. $MS->update_un_pw();
  1258. }
  1259. // --------------------------------------------------------------------
  1260. /**
  1261. * Member Email Form
  1262. */
  1263. public function email_console()
  1264. {
  1265. if ( ! class_exists('Member_memberlist'))
  1266. {
  1267. require PATH_MOD.'member/mod.member_memberlist.php';
  1268. }
  1269. $MM = new Member_memberlist();
  1270. foreach(get_object_vars($this) as $key => $value)
  1271. {
  1272. $MM->{$key} = $value;
  1273. }
  1274. return $MM->email_console();
  1275. }
  1276. // --------------------------------------------------------------------
  1277. /**
  1278. * Send Member Email
  1279. */
  1280. public function send_email()
  1281. {
  1282. if ( ! class_exists('Member_memberlist'))
  1283. {
  1284. require PATH_MOD.'member/mod.member_memberlist.php';
  1285. }
  1286. $MM = new Member_memberlist();
  1287. foreach(get_object_vars($this) as $key => $value)
  1288. {
  1289. $MM->{$key} = $value;
  1290. }
  1291. return $MM->send_email();
  1292. }
  1293. // --------------------------------------------------------------------
  1294. /**
  1295. * AIM Console
  1296. */
  1297. public function aim_console()
  1298. {
  1299. if ( ! class_exists('Member_memberlist'))
  1300. {
  1301. require PATH_MOD.'member/mod.member_memberlist.php';
  1302. }
  1303. $MM = new Member_memberlist();
  1304. foreach(get_object_vars($this) as $key => $value)
  1305. {
  1306. $MM->{$key} = $value;
  1307. }
  1308. return $MM->aim_console();
  1309. }
  1310. // --------------------------------------------------------------------
  1311. /**
  1312. * ICQ Console
  1313. */
  1314. public function icq_console()
  1315. {
  1316. if ( ! class_exists('Member_memberlist'))
  1317. {
  1318. require PATH_MOD.'member/mod.member_memberlist.php';
  1319. }
  1320. $MM = new Member_memberlist();
  1321. foreach(get_object_vars($this) as $key => $value)
  1322. {
  1323. $MM->{$key} = $value;
  1324. }
  1325. return $MM->icq_console();
  1326. }
  1327. // --------------------------------------------------------------------
  1328. /**
  1329. * Member List
  1330. */
  1331. public function memberlist()
  1332. {
  1333. if ( ! class_exists('Member_memberlist'))
  1334. {
  1335. require PATH_MOD.'member/mod.member_memberlist.php';
  1336. }
  1337. $MM = new Member_memberlist();
  1338. foreach(get_object_vars($this) as $key => $value)
  1339. {
  1340. $MM->{$key} = $value;
  1341. }
  1342. return $MM->memberlist();
  1343. }
  1344. // --------------------------------------------------------------------
  1345. /**
  1346. * Member Search Results
  1347. */
  1348. public function member_search()
  1349. {
  1350. if ( ! class_exists('Member_memberlist'))
  1351. {
  1352. require PATH_MOD.'member/mod.member_memberlist.php';
  1353. }
  1354. $MM = new Member_memberlist();
  1355. foreach(get_object_vars($this) as $key => $value)
  1356. {
  1357. $MM->{$key} = $value;
  1358. }
  1359. return $MM->memberlist();
  1360. }
  1361. // --------------------------------------------------------------------
  1362. /**
  1363. * Do A Member Search
  1364. */
  1365. public function do_member_search()
  1366. {
  1367. if ( ! class_exists('Member_memberlist'))
  1368. {
  1369. require PATH_MOD.'member/mod.member_memberlist.php';
  1370. }
  1371. $MM = new Member_memberlist();
  1372. foreach(get_object_vars($this) as $key => $value)
  1373. {
  1374. $MM->{$key} = $value;
  1375. }
  1376. return $MM->do_member_search();
  1377. }
  1378. // --------------------------------------------------------------------
  1379. /**
  1380. * Emoticons
  1381. */
  1382. public function smileys()
  1383. {
  1384. if ($this->EE->session->userdata('member_id') == 0)
  1385. {
  1386. return $this->EE->output->fatal_error($this->EE->lang->line('must_be_logged_in'));
  1387. }
  1388. $class_path = PATH_MOD.'emoticon/emoticons.php';
  1389. if ( ! is_file($class_path) OR ! @include_once($class_path))
  1390. {
  1391. return $this->EE->output->fatal_error('Unable to locate the smiley images');
  1392. }
  1393. if ( ! is_array($smileys))
  1394. {
  1395. return;
  1396. }
  1397. $path = $this->EE->config->slash_item('emoticon_url');
  1398. ob_start();
  1399. ?>
  1400. <script type="text/javascript">
  1401. <!--
  1402. function add_smiley(smiley)
  1403. {
  1404. var el = opener.document.getElementById('submit_post').body;
  1405. if ('selectionStart' in el) {
  1406. newStart = el.selectionStart + smiley.length;
  1407. el.value = el.value.substr(0, el.selectionStart) +
  1408. smiley +
  1409. el.value.substr(el.selectionEnd, el.value.length);
  1410. el.setSelectionRange(newStart, newStart);
  1411. }
  1412. else if (opener.document.selection) {
  1413. el.focus();
  1414. opener.document.selection.createRange().text = smiley;
  1415. }
  1416. else {
  1417. el.value += " " + smiley + " ";
  1418. }
  1419. el.focus();
  1420. window.close();
  1421. }
  1422. //-->
  1423. </script>
  1424. <?php
  1425. $javascript = ob_get_contents();
  1426. ob_end_clean();
  1427. $r = $javascript;
  1428. $i = 1;
  1429. $dups = array();
  1430. foreach ($smileys as $key => $val)
  1431. {
  1432. if ($i == 1)
  1433. {
  1434. $r .= "<tr>\n";
  1435. }
  1436. if (in_array($smileys[$key]['0'], $dups))
  1437. continue;
  1438. $r .= "<td class='tableCellOne' align='center'><a href=\"#\" onclick=\"return add_smiley('".$key."');\"><img src=\"".$path.$smileys[$key]['0']."\" width=\"".$smileys[$key]['1']."\" height=\"".$smileys[$key]['2']."\" alt=\"".$smileys[$key]['3']."\" border=\"0\" /></a></td>\n";
  1439. $dups[] = $smileys[$key]['0'];
  1440. if ($i == 10)
  1441. {
  1442. $r .= "</tr>\n";
  1443. $i = 1;
  1444. }
  1445. else
  1446. {
  1447. $i++;
  1448. }
  1449. }
  1450. $r = rtrim($r);
  1451. if (substr($r, -5) != "</tr>")
  1452. {
  1453. $r .= "</tr>\n";
  1454. }
  1455. $this->_set_page_title($this->EE->lang->line('smileys'));
  1456. return str_replace('{include:smileys}', $r, $this->_load_element('emoticon_page'));
  1457. }
  1458. // --------------------------------------------------------------------
  1459. /**
  1460. * Convet special characters
  1461. */
  1462. function _convert_special_chars($str)
  1463. {
  1464. return str_replace(array('<', '>', '{', '}', '\'', '"', '?'), array('&lt;', '&gt;', '&#123;', '&#125;', '&apos;', '&quot;', '&#63;'), $str);
  1465. }
  1466. // --------------------------------------------------------------------
  1467. /**
  1468. * Parse the index template
  1469. */
  1470. function _parse_index_template($str)
  1471. {
  1472. $req = ($this->request == '') ? 'profile' : $this->request;
  1473. // We have to call this before putting it into the array
  1474. $breadcrumb = $this->breadcrumb();
  1475. return $this->_var_swap($this->EE->TMPL->tagdata,
  1476. array(
  1477. 'stylesheet' => "<style type='text/css'>\n\n".$this->_load_element('stylesheet')."\n\n</style>",
  1478. 'javascript' => $this->javascript,
  1479. 'heading' => $this->page_title,
  1480. 'breadcrumb' => $breadcrumb,
  1481. 'content' => $str,
  1482. 'copyright' => $this->_load_element('copyright')
  1483. )
  1484. );
  1485. }
  1486. // --------------------------------------------------------------------
  1487. /**
  1488. * Member Home Page
  1489. */
  1490. function _member_page($str)
  1491. {
  1492. $template = $this->_load_element('member_page');
  1493. if ($this->show_headings == TRUE)
  1494. {
  1495. $template = $this->_allow_if('show_headings', $template);
  1496. }
  1497. else
  1498. {
  1499. $template = $this->_deny_if('show_headings', $template);
  1500. }
  1501. // We have to call this before putting it into the array
  1502. $breadcrumb = $this->breadcrumb();
  1503. $header = $this->_load_element('html_header');
  1504. $css = $this->_load_element('stylesheet');
  1505. $header = str_replace('{include:stylesheet}', $css, $header);
  1506. $header = str_replace('{include:head_extra}', $this->head_extra, $header);
  1507. return $this->_var_swap($template,
  1508. array(
  1509. 'include:html_header' => $header,
  1510. 'include:page_header' => $this->_load_element('page_header'),
  1511. 'include:page_subheader' => $this->_load_element('page_subheader'),
  1512. 'include:member_manager' => $str,
  1513. 'include:breadcrumb' => $breadcrumb,
  1514. 'include:html_footer' => $this->_load_element('html_footer')
  1515. )
  1516. );
  1517. }
  1518. // --------------------------------------------------------------------
  1519. /**
  1520. * Load theme element
  1521. */
  1522. function _load_element($which)
  1523. {
  1524. if ($this->theme_path == '')
  1525. {
  1526. $theme = ($this->EE->config->item('member_theme') == '') ? 'default' : $this->EE->config->item('member_theme');
  1527. $this->theme_path = PATH_MBR_THEMES."{$theme}/";
  1528. }
  1529. if ( ! file_exists($this->theme_path.$which.'.html'))
  1530. {
  1531. $data = array( 'title' => $this->EE->lang->line('error'),
  1532. 'heading' => $this->EE->lang->line('general_error'),
  1533. 'content' => $this->EE->lang->line('nonexistent_page'),
  1534. 'redirect' => '',
  1535. 'link' => array($this->EE->config->item('site_url'), stripslashes($this->EE->config->item('site_name')))
  1536. );
  1537. return $this->EE->output->show_message($data, 0);
  1538. }
  1539. return $this->_prep_element(trim(file_get_contents($this->theme_path.$which.'.html')));
  1540. }
  1541. // --------------------------------------------------------------------
  1542. /**
  1543. * Trigger Error Template
  1544. */
  1545. function _trigger_error($heading, $message = '', $use_lang = TRUE)
  1546. {
  1547. return $this->_var_swap($this->_load_element('error'),
  1548. array(
  1549. 'lang:heading' => $this->EE->lang->line($heading),
  1550. 'lang:message' => ($use_lang == TRUE) ? $this->EE->lang->line($message) : $message
  1551. )
  1552. );
  1553. }
  1554. // --------------------------------------------------------------------
  1555. /**
  1556. * Sets the title of the page
  1557. */
  1558. function _set_page_title($title)
  1559. {
  1560. if ($this->page_title == '')
  1561. {
  1562. $this->page_title = $title;
  1563. }
  1564. }
  1565. // --------------------------------------------------------------------
  1566. /**
  1567. * Member Breadcrumb
  1568. */
  1569. public function breadcrumb()
  1570. {
  1571. if ($this->breadcrumb == FALSE)
  1572. {
  1573. return '';
  1574. }
  1575. $crumbs = $this->_crumb_trail(
  1576. array(
  1577. 'link' => $this->EE->config->item('site_url'),
  1578. 'title' => stripslashes($this->EE->config->item('site_name'))
  1579. )
  1580. );
  1581. if ($this->EE->uri->segment(2) == '')
  1582. {
  1583. return $this->_build_crumbs($this->EE->lang->line('member_profile'), $crumbs, $this->EE->lang->line('member_profile'));
  1584. }
  1585. if ($this->EE->uri->segment(2) == 'messages')
  1586. {
  1587. $crumbs .= $this->_crumb_trail(array(
  1588. 'link' => $this->_member_path('/profile'),
  1589. 'title' => $this->EE->lang->line('control_panel_home')
  1590. )
  1591. );
  1592. $pm_page = (FALSE !== ($mbr_crumb = $this->_fetch_member_crumb($this->EE->uri->segment(3)))) ? $this->EE->lang->line($mbr_crumb) : $this->EE->lang->line('view_folder');
  1593. return $this->_build_crumbs($pm_page, $crumbs, $pm_page);
  1594. }
  1595. if (is_numeric($this->EE->uri->segment(2)))
  1596. {
  1597. $query = $this->EE->db->query("SELECT screen_name FROM exp_members WHERE member_id = '".$this->EE->uri->segment(2)."'");
  1598. $crumbs .= $this->_crumb_trail(array(
  1599. 'link' => $this->_member_path('/memberlist'),
  1600. 'title' => $this->EE->lang->line('mbr_memberlist')
  1601. )
  1602. );
  1603. return $this->_build_crumbs($query->row('screen_name') , $crumbs, $query->row('screen_name') );
  1604. }
  1605. else
  1606. {
  1607. if ($this->EE->uri->segment(2) == 'memberlist')
  1608. {
  1609. return $this->_build_crumbs($this->EE->lang->line('mbr_memberlist'), $crumbs, $this->EE->lang->line('mbr_memberlist'));
  1610. }
  1611. elseif ($this->EE->uri->segment(2) == 'member_search' OR $this->EE->uri->segment(2) == 'do_member_search')
  1612. {
  1613. return $this->_build_crumbs($this->EE->lang->line('member_search'), $crumbs, $this->EE->lang->line('member_search'));
  1614. }
  1615. elseif ($this->EE->uri->segment(2) != 'profile' AND ! in_array($this->EE->uri->segment(2), $this->no_menu))
  1616. {
  1617. $crumbs .= $this->_crumb_trail(array(
  1618. 'link' => $this->_member_path('/profile'),
  1619. 'title' => $this->EE->lang->line('control_panel_home')
  1620. )
  1621. );
  1622. }
  1623. }
  1624. if (FALSE !== ($mbr_crumb = $this->_fetch_member_crumb($this->EE->uri->segment(2))))
  1625. {
  1626. return $this->_build_crumbs($this->EE->lang->line($mbr_crumb), $crumbs, $this->EE->lang->line($mbr_crumb));
  1627. }
  1628. }
  1629. // --------------------------------------------------------------------
  1630. /**
  1631. * Breadcrumb trail links
  1632. */
  1633. function _crumb_trail($data)
  1634. {
  1635. $trail = $this->_load_element('breadcrumb_trail');
  1636. $crumbs = '';
  1637. $crumbs .= $this->_var_swap($trail,
  1638. array(
  1639. 'crumb_link' => $data['link'],
  1640. 'crumb_title' => $data['title']
  1641. )
  1642. );
  1643. return $crumbs;
  1644. }
  1645. // --------------------------------------------------------------------
  1646. /**
  1647. * Finalize the Crumbs
  1648. */
  1649. function _build_crumbs($title, $crumbs, $str)
  1650. {
  1651. $this->_set_page_title(($title == '') ? 'Powered By ExpressionEngine' : $title);
  1652. $crumbs .= str_replace('{crumb_title}', $str, $this->_load_element('breadcrumb_current_page'));
  1653. $breadcrumb = $this->_load_element('breadcrumb');
  1654. $breadcrumb = str_replace('{name}', $this->EE->session->userdata('screen_name'), $breadcrumb);
  1655. return str_replace('{breadcrumb_links}', $crumbs, $breadcrumb);
  1656. }
  1657. // --------------------------------------------------------------------
  1658. /**
  1659. * Fetch member profile crumb item
  1660. */
  1661. function _fetch_member_crumb($item = '')
  1662. {
  1663. if ($item == '')
  1664. return FALSE;
  1665. return ( ! isset($this->crumb_map[$item])) ? FALSE : $this->crumb_map[$item];
  1666. }
  1667. // --------------------------------------------------------------------
  1668. /**
  1669. * Create the "year" pull-down menu
  1670. */
  1671. function _birthday_year($year = '')
  1672. {
  1673. $r = "<select name='bday_y' class='select'>\n";
  1674. $selected = ($year == '') ? " selected='selected'" : '';
  1675. $r .= "<option value=''{$selected}>".$this->EE->lang->line('year')."</option>\n";
  1676. for ($i = date('Y', $this->EE->localize->now); $i > 1904; $i--)
  1677. {
  1678. $selected = ($year == $i) ? " selected='selected'" : '';
  1679. $r .= "<option value='{$i}'{$selected}>".$i."</option>\n";
  1680. }
  1681. $r .= "</select>\n";
  1682. return $r;
  1683. }
  1684. // --------------------------------------------------------------------
  1685. /**
  1686. * Create the "month" pull-down menu
  1687. */
  1688. function _birthday_month($month = '')
  1689. {
  1690. $months = array('01' => 'January','02' => 'February','03' => 'March', '04' => 'April', '05' => 'May', '06' => 'June', '07' => 'July', '08' => 'August', '09' => 'September', '10' => 'October', '11' => 'November', '12' => 'December');
  1691. $r = "<select name='bday_m' class='select'>\n";
  1692. $selected = ($month == '') ? " selected='selected'" : '';
  1693. $r .= "<option value=''{$selected}>".$this->EE->lang->line('month')."</option>\n";
  1694. for ($i = 1; $i < 13; $i++)
  1695. {
  1696. if (strlen($i) == 1)
  1697. $i = '0'.$i;
  1698. $selected = ($month == $i) ? " selected='selected'" : '';
  1699. $r .= "<option value='{$i}'{$selected}>".$this->EE->lang->line($months[$i])."</option>\n";
  1700. }
  1701. $r .= "</select>\n";
  1702. return $r;
  1703. }
  1704. // --------------------------------------------------------------------
  1705. /**
  1706. * Create the "day" pull-down menu
  1707. */
  1708. function _birthday_day($day = '')
  1709. {
  1710. $r = "<select name='bday_d' class='select'>\n";
  1711. $selected = ($day == '') ? " selected='selected'" : '';
  1712. $r .= "<option value=''{$selected}>".$this->EE->lang->line('day')."</option>\n";
  1713. for ($i = 1; $i <= 31; $i++)
  1714. {
  1715. $selected = ($day == $i) ? " selected='selected'" : '';
  1716. $r .= "<option value='{$i}'{$selected}>".$i."</option>\n";
  1717. }
  1718. $r .= "</select>\n";
  1719. return $r;
  1720. }
  1721. // --------------------------------------------------------------------
  1722. /**
  1723. * Prep Element Data
  1724. *
  1725. * Right now we only use this to parse the logged-in/logged-out vars
  1726. */
  1727. function _prep_element($str)
  1728. {
  1729. if ($str == '')
  1730. {
  1731. return '';
  1732. }
  1733. if ($this->EE->session->userdata('member_id') == 0)
  1734. {
  1735. $str = $this->_deny_if('logged_in', $str);
  1736. $str = $this->_allow_if('logged_out', $str);
  1737. }
  1738. else
  1739. {
  1740. $str = $this->_allow_if('logged_in', $str);
  1741. $str = $this->_deny_if('logged_out', $str);
  1742. }
  1743. // Parse the forum conditional
  1744. if ($this->EE->config->item('forum_is_installed') == "y")
  1745. {
  1746. $str = $this->_allow_if('forum_installed', $str);
  1747. }
  1748. else
  1749. {
  1750. $str = $this->_deny_if('forum_installed', $str);
  1751. }
  1752. // Parse the self deletion conditional
  1753. if ($this->EE->session->userdata('can_delete_self') == 'y' &&
  1754. $this->EE->session->userdata('group_id') != 1)
  1755. {
  1756. $str = $this->_allow_if('can_delete', $str);
  1757. }
  1758. else
  1759. {
  1760. $str = $this->_deny_if('can_delete', $str);
  1761. }
  1762. return $str;
  1763. }
  1764. // --------------------------------------------------------------------
  1765. /**
  1766. * Finalize a few things
  1767. */
  1768. function _final_prep($str)
  1769. {
  1770. // Which mode are we in?
  1771. // This class can either be run in "stand-alone" mode or through the template engine.
  1772. $template_parser = FALSE;
  1773. if (class_exists('Template'))
  1774. {
  1775. if ($this->EE->TMPL->tagdata != '')
  1776. {
  1777. $str = $this->_parse_index_template($str);
  1778. $template_parser = TRUE;
  1779. $this->EE->TMPL->disable_caching = TRUE;
  1780. }
  1781. }
  1782. if ($template_parser == FALSE AND $this->in_forum == FALSE)
  1783. {
  1784. $str = $this->_member_page($str);
  1785. }
  1786. // Parse the language text
  1787. if (preg_match_all("/{lang:(.+?)\}/i", $str, $matches))
  1788. {
  1789. for ($j = 0; $j < count($matches['0']); $j++)
  1790. {
  1791. $line = ($this->EE->lang->line($matches['1'][$j]) == $matches['1'][$j]) ? $this->EE->lang->line('mbr_'.$matches['1'][$j]) : $this->EE->lang->line($matches['1'][$j]);
  1792. $str = str_replace($matches['0'][$j], $line, $str);
  1793. }
  1794. }
  1795. // Parse old style path variables
  1796. // This is here for backward compatibility for people with older templates
  1797. $str = preg_replace_callback("/".LD."\s*path=(.*?)".RD."/", array(&$this->EE->functions, 'create_url'), $str);
  1798. if (preg_match_all("#".LD."\s*(profile_path\s*=.*?)".RD."#", $str, $matches))
  1799. {
  1800. $i = 0;
  1801. foreach ($matches['1'] as $val)
  1802. {
  1803. $path = $this->EE->functions->create_url($this->EE->functions->extract_path($val).'/'.$this->EE->session->userdata('member_id'));
  1804. $str = preg_replace("#".$matches['0'][$i++]."#", $path, $str, 1);
  1805. }
  1806. }
  1807. // -------
  1808. // Set some paths
  1809. $theme_images = $this->EE->config->slash_item('theme_folder_url', 1).'profile_themes/'.$this->EE->config->item('member_theme').'/images/';
  1810. if ($this->EE->session->userdata('profile_theme') != '')
  1811. {
  1812. $img_path = $this->EE->config->slash_item('theme_folder_url').'profile_themes/'.$this->EE->session->userdata('profile_theme').'/images/';
  1813. }
  1814. else
  1815. {
  1816. $img_path = $this->EE->config->slash_item('theme_folder_url', 1).'profile_themes/'.$this->EE->config->item('member_theme').'/images/';
  1817. }
  1818. $simple = ($this->show_headings == FALSE) ? '/simple' : '';
  1819. if ($this->css_file_path == '')
  1820. {
  1821. $this->css_file_path = $this->EE->config->slash_item('theme_folder_url', 1).'profile_themes/'.$this->EE->config->item('member_theme').'profile.css';
  1822. }
  1823. // Parse {switch="foo|bar"} variables
  1824. if (preg_match_all("/".LD."(switch\s*=.+?)".RD."/i", $str, $matches, PREG_SET_ORDER))
  1825. {
  1826. foreach ($matches as $match)
  1827. {
  1828. $sparam = $this->EE->functions->assign_parameters($match[1]);
  1829. if (isset($sparam['switch']))
  1830. {
  1831. $sopt = explode("|", $sparam['switch']);
  1832. $i = 1;
  1833. while (($pos = strpos($str, LD.$match[1].RD)) !== FALSE)
  1834. {
  1835. $str = substr_replace($str, $sopt[($i++ + count($sopt) - 1) % count($sopt)], $pos, strlen(LD.$match[1].RD));
  1836. }
  1837. }
  1838. }
  1839. }
  1840. // Finalize the output
  1841. $str = $this->EE->functions->prep_conditionals($str, array('current_request' => $this->request));
  1842. $str = $this->_var_swap($str,
  1843. array(
  1844. 'lang' => $this->EE->config->item('xml_lang'),
  1845. 'charset' => $this->EE->config->item('output_charset'),
  1846. 'path:image_url' => ($this->image_url == '') ? $theme_images : $this->image_url,
  1847. 'path:your_control_panel' => $this->_member_path('profile'),
  1848. 'path:your_profile' => $this->_member_path($this->EE->session->userdata('member_id')),
  1849. 'path:edit_preferences' => $this->_member_path('edit_preferences'),
  1850. 'path:register' => $this->_member_path('register'.$simple),
  1851. 'path:private_messages' => $this->_member_path('messages'),
  1852. 'path:memberlist' => $this->_member_path('memberlist'),
  1853. 'path:signature' => $this->_member_path('edit_signature'),
  1854. 'path:avatar' => $this->_member_path('edit_avatar'),
  1855. 'path:photo' => $this->_member_path('edit_photo'),
  1856. 'path:smileys' => $this->_member_path('smileys'),
  1857. 'path:forgot' => $this->_member_path('forgot_password'.$simple),
  1858. 'path:login' => $this->_member_path('login'.$simple),
  1859. 'path:delete' => $this->_member_path('delete'),
  1860. 'page_title' => $this->page_title,
  1861. 'site_name' => stripslashes($this->EE->config->item('site_name')),
  1862. 'path:theme_css' => $this->css_file_path,
  1863. 'current_request' => $this->request
  1864. )
  1865. );
  1866. // parse regular global vars
  1867. $this->EE->load->library('template', NULL, 'TMPL');
  1868. // load up any Snippets
  1869. $this->EE->db->select('snippet_name, snippet_contents');
  1870. $this->EE->db->where('(site_id = '.$this->EE->db->escape_str($this->EE->config->item('site_id')).' OR site_id = 0)');
  1871. $fresh = $this->EE->db->get('snippets');
  1872. if ($fresh->num_rows() > 0)
  1873. {
  1874. $snippets = array();
  1875. foreach ($fresh->result() as $var)
  1876. {
  1877. $snippets[$var->snippet_name] = $var->snippet_contents;
  1878. }
  1879. $this->EE->config->_global_vars = array_merge($this->EE->config->_global_vars, $snippets);
  1880. unset($snippets);
  1881. unset($fresh);
  1882. }
  1883. if ( ! $this->in_forum)
  1884. {
  1885. $this->EE->TMPL->parse($str);
  1886. $str = $this->EE->TMPL->parse_globals($this->EE->TMPL->final_template);
  1887. }
  1888. // Add security hashes to forms
  1889. if ( ! class_exists('Template'))
  1890. {
  1891. $str = $this->EE->functions->insert_action_ids($this->EE->functions->add_form_security_hash($str));
  1892. }
  1893. $str = preg_replace("/".LD."if\s+.*?".RD.".*?".LD.'\/if'.RD."/s", "", $str);
  1894. return $str;
  1895. }
  1896. // --------------------------------------------------------------------
  1897. /**
  1898. * Set base values of class vars
  1899. */
  1900. function _set_properties($props = array())
  1901. {
  1902. if (count($props) > 0)
  1903. {
  1904. foreach ($props as $key => $val)
  1905. {
  1906. $this->$key = $val;
  1907. }
  1908. }
  1909. }
  1910. // --------------------------------------------------------------------
  1911. /**
  1912. * Sets the member basepath
  1913. */
  1914. function _member_set_basepath()
  1915. {
  1916. $this->basepath = $this->EE->functions->create_url($this->trigger);
  1917. }
  1918. // --------------------------------------------------------------------
  1919. /**
  1920. * Compiles a path string
  1921. */
  1922. function _member_path($uri = '')
  1923. {
  1924. if ($this->basepath == '')
  1925. {
  1926. $this->_member_set_basepath();
  1927. }
  1928. return $this->EE->functions->remove_double_slashes($this->basepath.'/'.$uri);
  1929. }
  1930. // --------------------------------------------------------------------
  1931. /**
  1932. * Helpers for "if" conditions
  1933. */
  1934. function _deny_if($cond, $str, $replace = '')
  1935. {
  1936. return preg_replace("/\{if\s+".$cond."\}.+?\{\/if\}/si", $replace, $str);
  1937. }
  1938. function _allow_if($cond, $str)
  1939. {
  1940. return preg_replace("/\{if\s+".$cond."\}(.+?)\{\/if\}/si", "\\1", $str);
  1941. }
  1942. // --------------------------------------------------------------------
  1943. /**
  1944. * Replace variables
  1945. */
  1946. function _var_swap($str, $data)
  1947. {
  1948. if ( ! is_array($data))
  1949. {
  1950. return FALSE;
  1951. }
  1952. foreach ($data as $key => $val)
  1953. {
  1954. $str = str_replace('{'.$key.'}', $val, $str);
  1955. }
  1956. return $str;
  1957. }
  1958. // --------------------------------------------------------------------
  1959. /**
  1960. * Swap single variables with final value
  1961. */
  1962. function _var_swap_single($search, $replace, $source)
  1963. {
  1964. return str_replace(LD.$search.RD, $replace, $source);
  1965. }
  1966. // --------------------------------------------------------------------
  1967. /**
  1968. * Show 404 Template
  1969. *
  1970. * Show the real 404 template instead of an ACT error when we cannot
  1971. * find the page that was requested.
  1972. *
  1973. * @access protected
  1974. */
  1975. protected function _show_404_template()
  1976. {
  1977. // 404 it
  1978. $this->EE->load->library('template', NULL, 'TMPL');
  1979. $template = explode('/', $this->EE->config->item('site_404'));
  1980. if (isset($template[1]))
  1981. {
  1982. $this->EE->TMPL->template_type = "404";
  1983. $this->EE->TMPL->fetch_and_parse($template[0], $template[1]);
  1984. $out = $this->EE->TMPL->parse_globals($this->EE->TMPL->final_template);
  1985. }
  1986. else
  1987. {
  1988. $out = $this->EE->TMPL->_404();
  1989. }
  1990. $this->EE->output->out_type = '404';
  1991. $this->EE->output->set_output($out);
  1992. $this->EE->output->_display();
  1993. exit;
  1994. }
  1995. // --------------------------------------------------------------------
  1996. /**
  1997. * Custom Member Profile Data
  1998. */
  1999. function custom_profile_data()
  2000. {
  2001. $member_id = ( ! $this->EE->TMPL->fetch_param('member_id')) ? $this->EE->session->userdata('member_id') : $this->EE->TMPL->fetch_param('member_id');
  2002. // Default Member Data
  2003. $this->EE->db->select('m.member_id, m.group_id, m.username, m.screen_name, m.email, m.signature,
  2004. m.avatar_filename, m.avatar_width, m.avatar_height,
  2005. m.photo_filename, m.photo_width, m.photo_height,
  2006. m.url, m.location, m.occupation, m.interests,
  2007. m.bio,
  2008. m.join_date, m.last_visit, m.last_activity, m.last_entry_date, m.last_comment_date,
  2009. m.last_forum_post_date, m.total_entries, m.total_comments, m.total_forum_topics, m.total_forum_posts,
  2010. m.language, m.timezone, m.daylight_savings, m.bday_d, m.bday_m, m.bday_y,
  2011. g.group_title');
  2012. $this->EE->db->from(array('members m', 'member_groups g'));
  2013. $this->EE->db->where('m.member_id', $member_id);
  2014. $this->EE->db->where('g.site_id', $this->EE->config->item('site_id'));
  2015. $this->EE->db->where('m.group_id = g.group_id');
  2016. $query = $this->EE->db->get();
  2017. if ($query->num_rows() == 0)
  2018. {
  2019. return $this->EE->TMPL->tagdata = '';
  2020. }
  2021. $default_fields = $query->row_array();
  2022. // Is there an avatar?
  2023. if ($this->EE->config->item('enable_avatars') == 'y' AND $query->row('avatar_filename') != '')
  2024. {
  2025. $avatar_path = $this->EE->config->item('avatar_url').$query->row('avatar_filename');
  2026. $avatar_width = $query->row('avatar_width');
  2027. $avatar_height = $query->row('avatar_height');
  2028. $avatar = 'TRUE';
  2029. }
  2030. else
  2031. {
  2032. $avatar_path = '';
  2033. $avatar_width = '';
  2034. $avatar_height = '';
  2035. $avatar = 'FALSE';
  2036. }
  2037. // Is there a member photo?
  2038. if ($this->EE->config->item('enable_photos') == 'y' AND $query->row('photo_filename') != '')
  2039. {
  2040. $photo_path = $this->EE->config->item('photo_url').$query->row('photo_filename');
  2041. $photo_width = $query->row('photo_width');
  2042. $photo_height = $query->row('photo_height');
  2043. $photo = 'TRUE';
  2044. }
  2045. else
  2046. {
  2047. $photo_path = '';
  2048. $photo_width = '';
  2049. $photo_height = '';
  2050. $photo = 'FALSE';
  2051. }
  2052. // Is there a signature image?
  2053. if ($this->EE->config->item('enable_signatures') == 'y' AND $query->row('sig_img_filename') != '')
  2054. {
  2055. $sig_img_path = $this->EE->config->item('sig_img_url').$query->row('sig_img_filename');
  2056. $sig_img_width = $query->row('sig_img_width');
  2057. $sig_img_height = $query->row('sig_img_height');
  2058. $sig_img_image = 'TRUE';
  2059. }
  2060. else
  2061. {
  2062. $sig_img_path = '';
  2063. $sig_img_width = '';
  2064. $sig_img_height = '';
  2065. $sig_img = 'FALSE';
  2066. }
  2067. // Parse variables
  2068. if ($this->in_forum == TRUE)
  2069. {
  2070. $search_path = $this->forum_path.'member_search/'.$this->cur_id.'/';
  2071. }
  2072. else
  2073. {
  2074. $search_path = $this->EE->functions->fetch_site_index(0, 0).QUERY_MARKER.'ACT='.$this->EE->functions->fetch_action_id('Search', 'do_search').'&amp;mbr='.urlencode($query->row('member_id'));
  2075. }
  2076. $more_fields = array(
  2077. 'send_private_message' => $this->_member_path('messages/pm/'.$member_id),
  2078. 'search_path' => $search_path,
  2079. 'avatar_url' => $avatar_path,
  2080. 'avatar_filename' => $query->row('avatar_filename'),
  2081. 'avatar_width' => $avatar_width,
  2082. 'avatar_height' => $avatar_height,
  2083. 'photo_url' => $photo_path,
  2084. 'photo_filename' => $query->row('photo_filename'),
  2085. 'photo_width' => $photo_width,
  2086. 'photo_height' => $photo_height,
  2087. 'signature_image_url' => $sig_img_path,
  2088. 'signature_image_filename' => $query->row('sig_img_filename'),
  2089. 'signature_image_width' => $sig_img_width,
  2090. 'signature_image_height' => $sig_img_height
  2091. );
  2092. $default_fields = array_merge($default_fields, $more_fields);
  2093. // Fetch the custom member field definitions
  2094. $fields = array();
  2095. $this->EE->db->select('m_field_id, m_field_name, m_field_fmt');
  2096. $query = $this->EE->db->get('member_fields');
  2097. if ($query->num_rows() > 0)
  2098. {
  2099. foreach ($query->result_array() as $row)
  2100. {
  2101. $fields[$row['m_field_name']] = array($row['m_field_id'], $row['m_field_fmt']);
  2102. }
  2103. }
  2104. $this->EE->db->where('member_id', $member_id);
  2105. $query = $this->EE->db->get('member_data');
  2106. if ($query->num_rows() == 0)
  2107. {
  2108. foreach ($fields as $key => $val)
  2109. {
  2110. $this->EE->TMPL->tagdata = $this->EE->TMPL->swap_var_single($key, '', $this->EE->TMPL->tagdata);
  2111. }
  2112. return $this->EE->TMPL->tagdata;
  2113. }
  2114. $this->EE->load->library('typography');
  2115. $this->EE->typography->initialize();
  2116. $cond = $default_fields;
  2117. foreach ($query->result_array() as $row)
  2118. {
  2119. $cond['avatar'] = $avatar;
  2120. $cond['photo'] = $photo;
  2121. foreach($fields as $key => $value)
  2122. {
  2123. $cond[$key] = $this->EE->typography->parse_type($row['m_field_id_'.$value['0']],
  2124. array(
  2125. 'text_format' => $value['1'],
  2126. 'html_format' => 'safe',
  2127. 'auto_links' => 'y',
  2128. 'allow_img_url' => 'n'
  2129. )
  2130. );
  2131. }
  2132. $this->EE->TMPL->tagdata = $this->EE->functions->prep_conditionals($this->EE->TMPL->tagdata, $cond);
  2133. // Swap Variables
  2134. foreach ($this->EE->TMPL->var_single as $key => $val)
  2135. {
  2136. // parse default member data
  2137. // Format URLs
  2138. if ($key == 'url')
  2139. {
  2140. if (substr($default_fields['url'], 0, 4) != "http" && strpos($default_fields['url'], '://') === FALSE)
  2141. {
  2142. $default_fields['url'] = "http://".$default_fields['url'];
  2143. }
  2144. }
  2145. // "last_visit"
  2146. if (strncmp($key, 'last_visit', 10) == 0)
  2147. {
  2148. $this->EE->TMPL->tagdata = $this->_var_swap_single($key, ($default_fields['last_visit'] > 0) ? $this->EE->localize->decode_date($val, $default_fields['last_visit']) : '', $this->EE->TMPL->tagdata);
  2149. }
  2150. // "last_activity"
  2151. if (strncmp($key, 'last_activity', 10) == 0)
  2152. {
  2153. $this->EE->TMPL->tagdata = $this->_var_swap_single($key, ($default_fields['last_activity'] > 0) ? $this->EE->localize->decode_date($val, $default_fields['last_activity']) : '', $this->EE->TMPL->tagdata);
  2154. }
  2155. // "join_date"
  2156. if (strncmp($key, 'join_date', 9) == 0)
  2157. {
  2158. $this->EE->TMPL->tagdata = $this->_var_swap_single($key, ($default_fields['join_date'] > 0) ? $this->EE->localize->decode_date($val, $default_fields['join_date']) : '', $this->EE->TMPL->tagdata);
  2159. }
  2160. // "last_entry_date"
  2161. if (strncmp($key, 'last_entry_date', 15) == 0)
  2162. {
  2163. $this->EE->TMPL->tagdata = $this->_var_swap_single($key, ($default_fields['last_entry_date'] > 0) ? $this->EE->localize->decode_date($val, $default_fields['last_entry_date']) : '', $this->EE->TMPL->tagdata);
  2164. }
  2165. // "last_forum_post_date"
  2166. if (strncmp($key, 'last_forum_post_date', 20) == 0)
  2167. {
  2168. $this->EE->TMPL->tagdata = $this->_var_swap_single($key, ($default_fields['last_forum_post_date'] > 0) ? $this->EE->localize->decode_date($val, $default_fields['last_forum_post_date']) : '', $this->EE->TMPL->tagdata);
  2169. }
  2170. // parse "recent_comment"
  2171. if (strncmp($key, 'last_comment_date', 17) == 0)
  2172. {
  2173. $this->EE->TMPL->tagdata = $this->_var_swap_single($key, ($default_fields['last_comment_date'] > 0) ? $this->EE->localize->decode_date($val, $default_fields['last_comment_date']) : '', $this->EE->TMPL->tagdata);
  2174. }
  2175. // {name}
  2176. $name = ( ! $default_fields['screen_name']) ? $default_fields['username'] : $default_fields['screen_name'];
  2177. $name = $this->_convert_special_chars($name);
  2178. if ($key == "name")
  2179. {
  2180. $this->EE->TMPL->tagdata = $this->_var_swap_single($val, $name, $this->EE->TMPL->tagdata);
  2181. }
  2182. // {member_group}
  2183. if ($key == "member_group")
  2184. {
  2185. $this->EE->TMPL->tagdata = $this->_var_swap_single($val, $default_fields['group_title'], $this->EE->TMPL->tagdata);
  2186. }
  2187. // {email}
  2188. if ($key == "email")
  2189. {
  2190. $this->EE->TMPL->tagdata = $this->_var_swap_single($val, $this->EE->typography->encode_email($default_fields['email']), $this->EE->TMPL->tagdata);
  2191. }
  2192. // {birthday}
  2193. if ($key == "birthday")
  2194. {
  2195. $birthday = '';
  2196. if ($default_fields['bday_m'] != '' AND $default_fields['bday_m'] != 0)
  2197. {
  2198. $month = (strlen($default_fields['bday_m']) == 1) ? '0'.$default_fields['bday_m'] : $default_fields['bday_m'];
  2199. $m = $this->EE->localize->localize_month($month);
  2200. $birthday .= $this->EE->lang->line($m['1']);
  2201. if ($default_fields['bday_d'] != '' AND $default_fields['bday_d'] != 0)
  2202. {
  2203. $birthday .= ' '.$default_fields['bday_d'];
  2204. }
  2205. }
  2206. if ($default_fields['bday_y'] != '' AND $default_fields['bday_y'] != 0)
  2207. {
  2208. if ($birthday != '')
  2209. {
  2210. $birthday .= ', ';
  2211. }
  2212. $birthday .= $default_fields['bday_y'];
  2213. }
  2214. if ($birthday == '')
  2215. {
  2216. $birthday = '';
  2217. }
  2218. $this->EE->TMPL->tagdata = $this->_var_swap_single($val, $birthday, $this->EE->TMPL->tagdata);
  2219. }
  2220. // {timezone}
  2221. if ($key == "timezone")
  2222. {
  2223. $timezone = ($default_fields['timezone'] != '') ? $this->EE->lang->line($default_fields['timezone']) : '';
  2224. $this->EE->TMPL->tagdata = $this->_var_swap_single($val, $timezone, $this->EE->TMPL->tagdata);
  2225. }
  2226. // {local_time}
  2227. if (strncmp($key, 'local_time', 10) == 0)
  2228. {
  2229. $time = $this->EE->localize->now;
  2230. if ($this->EE->session->userdata('member_id') != $this->cur_id)
  2231. {
  2232. // Default is UTC?
  2233. $zone = ($default_fields['timezone'] == '') ? 'UTC' : $default_fields['timezone'];
  2234. $time = $this->EE->localize->set_localized_time($time, $zone, $default_fields['daylight_savings']);
  2235. }
  2236. $this->EE->TMPL->tagdata = $this->_var_swap_single(
  2237. $key,
  2238. $this->EE->localize->decode_date($val, $time, FALSE),
  2239. $this->EE->TMPL->tagdata
  2240. );
  2241. }
  2242. // {bio}
  2243. if ($key == 'bio')
  2244. {
  2245. $bio = $this->EE->typography->parse_type($default_fields[$val],
  2246. array(
  2247. 'text_format' => 'xhtml',
  2248. 'html_format' => 'safe',
  2249. 'auto_links' => 'y',
  2250. 'allow_img_url' => 'n'
  2251. )
  2252. );
  2253. $this->EE->TMPL->tagdata = $this->_var_swap_single($key, $bio, $this->EE->TMPL->tagdata);
  2254. }
  2255. // Special condideration for {total_forum_replies}, and
  2256. // {total_forum_posts} whose meanings do not match the
  2257. // database field names
  2258. if ($key == 'total_forum_replies')
  2259. {
  2260. $this->EE->TMPL->tagdata = $this->_var_swap_single($key, $default_fields['total_forum_posts'], $this->EE->TMPL->tagdata);
  2261. }
  2262. if ($key == 'total_forum_posts')
  2263. {
  2264. $total_posts = $default_fields['total_forum_topics'] + $default_fields['total_forum_posts'];
  2265. $this->EE->TMPL->tagdata = $this->_var_swap_single($key, $total_posts, $this->EE->TMPL->tagdata);
  2266. }
  2267. // parse basic fields (username, screen_name, etc.)
  2268. if (array_key_exists($key, $default_fields))
  2269. {
  2270. $this->EE->TMPL->tagdata = $this->_var_swap_single($val, $default_fields[$val], $this->EE->TMPL->tagdata);
  2271. }
  2272. // parse custom member fields
  2273. if (isset($fields[$val]) && array_key_exists('m_field_id_'.$fields[$val]['0'], $row))
  2274. {
  2275. $this->EE->TMPL->tagdata = $this->EE->TMPL->swap_var_single(
  2276. $val,
  2277. $this->EE->typography->parse_type(
  2278. $row['m_field_id_'.$fields[$val]['0']],
  2279. array(
  2280. 'text_format' => $fields[$val]['1'],
  2281. 'html_format' => 'safe',
  2282. 'auto_links' => 'y',
  2283. 'allow_img_url' => 'n'
  2284. )
  2285. ),
  2286. $this->EE->TMPL->tagdata
  2287. );
  2288. }
  2289. //else { echo 'm_field_id_'.$fields[$val]['0']; }
  2290. }
  2291. }
  2292. return $this->EE->TMPL->tagdata;
  2293. }
  2294. // --------------------------------------------------------------------
  2295. /**
  2296. * Ignore List
  2297. */
  2298. function ignore_list()
  2299. {
  2300. $pre = 'ignore_';
  2301. $prelen = strlen($pre);
  2302. if ($member_id = $this->EE->TMPL->fetch_param('member_id'))
  2303. {
  2304. $query = $this->EE->db->query("SELECT ignore_list FROM exp_members WHERE member_id = '{$member_id}'");
  2305. if ($query->num_rows() == 0)
  2306. {
  2307. return $this->EE->TMPL->no_results();
  2308. }
  2309. $ignored = ($query->row('ignore_list') == '') ? array() : explode('|', $query->row('ignore_list') );
  2310. }
  2311. else
  2312. {
  2313. $ignored = $this->EE->session->userdata('ignore_list');
  2314. }
  2315. $query = $this->EE->db->query("SELECT m.member_id, m.group_id, m.username, m.screen_name, m.email, m.ip_address, m.location, m.total_entries, m.total_comments, m.private_messages, m.total_forum_topics, m.total_forum_posts AS total_forum_replies, m.total_forum_topics + m.total_forum_posts AS total_forum_posts,
  2316. g.group_title AS group_description FROM exp_members AS m, exp_member_groups AS g
  2317. WHERE g.group_id = m.group_id
  2318. AND g.site_id = '".$this->EE->db->escape_str($this->EE->config->item('site_id'))."'
  2319. AND m.member_id IN ('".implode("', '", $ignored)."')");
  2320. if ($query->num_rows() == 0)
  2321. {
  2322. return $this->EE->TMPL->no_results();
  2323. }
  2324. $tagdata = $this->EE->TMPL->tagdata;
  2325. $out = '';
  2326. foreach($query->result_array() as $row)
  2327. {
  2328. $temp = $tagdata;
  2329. foreach ($this->EE->TMPL->var_single as $key => $val)
  2330. {
  2331. $val = substr($val, $prelen);
  2332. if (isset($row[$val]))
  2333. {
  2334. $temp = $this->EE->TMPL->swap_var_single($pre.$val, $row[$val], $temp);
  2335. }
  2336. }
  2337. $out .= $temp;
  2338. }
  2339. return $this->EE->TMPL->tagdata = $out;
  2340. }
  2341. }
  2342. // END CLASS
  2343. /* End of file mod.member.php */
  2344. /* Location: ./system/expressionengine/modules/member/mod.member.php */