Advertisement
Guest User

Untitled

a guest
Feb 5th, 2016
249
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 57.20 KB | None | 0 0
  1. <?php
  2. /**
  3. * Themex User
  4. *
  5. * Handles users data
  6. *
  7. * @class ThemexUser
  8. * @author Themex
  9. */
  10.  
  11. class ThemexUser {
  12.  
  13. /** @var array Contains module data. */
  14. public static $data;
  15.  
  16. /**
  17. * Adds actions and filters
  18. *
  19. * @access public
  20. * @return void
  21. */
  22. public static function init() {
  23.  
  24. //refresh module data
  25. add_action('wp', array(__CLASS__, 'refresh'), 1);
  26.  
  27. //update user actions
  28. add_action('wp', array(__CLASS__, 'updateUser'), 99);
  29. add_action('wp_ajax_themex_update_user', array(__CLASS__, 'updateUser'));
  30. add_action('wp_ajax_nopriv_themex_update_user', array(__CLASS__, 'updateUser'));
  31. add_action('template_redirect', array(__CLASS__, 'activateUser'));
  32.  
  33. //remove user action
  34. add_action('delete_user', array(__CLASS__, 'removeUser'));
  35.  
  36. //add messages filter
  37. add_filter('comments_clauses', array( __CLASS__, 'filterMessages'));
  38.  
  39. //add avatar filter
  40. add_filter('get_avatar', array(__CLASS__, 'getAvatar'), 10, 5);
  41.  
  42. //render gifts template
  43. add_action('wp_footer', array(__CLASS__,'renderGifts'));
  44.  
  45. //filter user statuses
  46. add_action('wp', array(__CLASS__, 'filterStatuses'));
  47.  
  48. //filter usernames
  49. add_filter('validate_username', array(__CLASS__, 'filterUsername'), 10, 2);
  50.  
  51. //membership actions
  52. add_action('template_redirect', array(__CLASS__, 'filterMembership'));
  53. add_filter('save_post', array(__CLASS__, 'saveMembership'));
  54.  
  55. //render admin profile
  56. add_filter('show_user_profile', array(__CLASS__,'renderAdminProfile'));
  57. add_filter('edit_user_profile', array(__CLASS__,'renderAdminProfile'));
  58.  
  59. //update admin profile
  60. add_action('edit_user_profile_update', array(__CLASS__,'updateAdminProfile'));
  61. add_action('personal_options_update', array(__CLASS__,'updateAdminProfile'));
  62.  
  63. //add admin columns
  64. add_filter('manage_users_columns', array(__CLASS__, 'addAdminColumns'));
  65. add_action('manage_users_custom_column', array(__CLASS__, 'renderAdminColumns'), 10, 3);
  66. add_filter('manage_users_sortable_columns', array(__CLASS__, 'updateAdminColumns'));
  67. add_action('pre_user_query', array(__CLASS__, 'filterAdminColumns'));
  68.  
  69. //render admin toolbar
  70. add_filter('show_admin_bar', array(__CLASS__,'renderToolbar'));
  71. }
  72.  
  73. /**
  74. * Refreshes module data
  75. *
  76. * @access public
  77. * @return void
  78. */
  79. public static function refresh() {
  80. $ID=get_current_user_id();
  81. self::$data['user']=self::getUser($ID, true);
  82.  
  83. $user=0;
  84. if(($var=get_query_var('author')) || ($var=get_query_var('message')) || ($var=get_query_var('chat'))) {
  85. $user=intval($var);
  86. }
  87.  
  88. if($user!=0) {
  89. self::$data['active_user']=self::getUser($user, true);
  90. } else {
  91. self::$data['active_user']=self::$data['user'];
  92. }
  93. }
  94.  
  95. /**
  96. * Gets user data
  97. *
  98. * @access public
  99. * @param int $ID
  100. * @return array
  101. */
  102. public static function getUser($ID, $extended=false) {
  103. $data=get_userdata($ID);
  104. if($data!=false) {
  105. $user['login']=$data->user_login;
  106. $user['email']=$data->user_email;
  107. $user['role']=reset($data->roles);
  108. }
  109.  
  110. $user['ID']=$ID;
  111. $user['status']=self::getStatus($ID);
  112.  
  113. $user['profile_url']=get_author_posts_url($ID);
  114. $user['message_url']=ThemexCore::getUrl('message', $ID);
  115. $user['chat_url']=ThemexCore::getUrl('chat', $ID);
  116. $user['profile']=self::getProfile($ID);
  117.  
  118. if($extended) {
  119. $user['memberships_url']=ThemexCore::getUrl('memberships', $ID);
  120. $user['settings_url']=ThemexCore::getUrl('settings', $ID);
  121. $user['messages_url']=ThemexCore::getUrl('messages', $ID);
  122.  
  123. $user['favorites']=themex_keys(ThemexCore::getUserMeta($ID, 'favorites', array()));
  124. $user['ignores']=themex_keys(ThemexCore::getUserMeta($ID, 'ignores', array()));
  125. $user['photos']=themex_keys(ThemexCore::getUserMeta($ID, 'photos', array()));
  126. $user['gifts']=ThemexCore::getUserMeta($ID, 'gifts', array());
  127. $user['membership']=self::getMembership($ID, $user['profile']['gender']);
  128. $user['settings']=self::getSettings($ID);
  129. }
  130.  
  131. return $user;
  132. }
  133.  
  134. /**
  135. * Gets users data
  136. *
  137. * @access public
  138. * @param array $args
  139. * @return array
  140. */
  141. public static function getUsers($args=array()) {
  142.  
  143. global $wpdb;
  144. $wpdb->query('SET SQL_BIG_SELECTS=1');
  145.  
  146. $args['exclude']=self::$data['user']['ID'];
  147. $args['orderby']='registered';
  148. $args['order']='DESC';
  149. $args['role']='subscriber';
  150.  
  151. $order=ThemexCore::getOption('user_order', 'date');
  152. if($order=='name') {
  153. $args['orderby']='display_name';
  154. $args['order']='ASC';
  155. }
  156.  
  157. if(ThemexCore::checkOption('user_name')) {
  158. $args['meta_query']=array(
  159. array(
  160. 'key' => '_'.THEMEX_PREFIX.'updated',
  161. 'value' => '',
  162. 'compare' => '!=',
  163. ),
  164. );
  165. } else {
  166. $args['meta_query']=array(
  167. array(
  168. 'key' => 'first_name',
  169. 'value' => '',
  170. 'compare' => '!=',
  171. ),
  172. );
  173. }
  174.  
  175. if(ThemexCore::checkOption('user_avatar')) {
  176. $args['meta_query']=array(
  177. array(
  178. 'key' => '_'.THEMEX_PREFIX.'avatar',
  179. 'value' => '',
  180. 'compare' => '!=',
  181. ),
  182. );
  183. }
  184.  
  185. if(self::isUserFilter()) {
  186. if(isset($_GET['gender'])) {
  187. $args['meta_query'][]=array(
  188. 'key' => '_'.THEMEX_PREFIX.'seeking',
  189. 'value' => sanitize_title($_GET['gender']),
  190. );
  191. }
  192.  
  193. if(isset($_GET['seeking'])) {
  194. $args['meta_query'][]=array(
  195. 'key' => '_'.THEMEX_PREFIX.'gender',
  196. 'value' => sanitize_title($_GET['seeking']),
  197. );
  198. }
  199.  
  200. if(isset($_GET['country']) && !empty($_GET['country'])) {
  201. $args['meta_query'][]=array(
  202. 'key' => '_'.THEMEX_PREFIX.'country',
  203. 'value' => sanitize_title($_GET['country']),
  204. );
  205. }
  206.  
  207. if(isset($_GET['city']) && !empty($_GET['city'])) {
  208. $args['meta_query'][]=array(
  209. 'key' => '_'.THEMEX_PREFIX.'city',
  210. 'value' => sanitize_text_field($_GET['city']),
  211. );
  212. }
  213.  
  214. if(isset($_GET['age_from'])) {
  215. $args['meta_query'][]=array(
  216. 'key' => '_'.THEMEX_PREFIX.'age',
  217. 'type' => 'NUMERIC',
  218. 'value' => intval($_GET['age_from']),
  219. 'compare' => '>=',
  220. );
  221. }
  222.  
  223. if(isset($_GET['age_to'])) {
  224. $args['meta_query'][]=array(
  225. 'key' => '_'.THEMEX_PREFIX.'age',
  226. 'type' => 'NUMERIC',
  227. 'value' => intval($_GET['age_to']),
  228. 'compare' => '<=',
  229. );
  230. }
  231.  
  232. if(isset(ThemexForm::$data['profile']) && is_array(ThemexForm::$data['profile'])) {
  233. foreach(ThemexForm::$data['profile'] as $field) {
  234. if(isset($field['search'])) {
  235. $name=themex_sanitize_key($field['name']);
  236. if(isset($_GET[$name]) && !empty($_GET[$name])) {
  237. if(in_array($field['type'], array('text', 'textarea'))) {
  238. $args['meta_query'][]=array(
  239. 'key' => '_'.THEMEX_PREFIX.$name,
  240. 'value' => sanitize_text_field($_GET[$name]),
  241. 'compare' => 'LIKE',
  242. );
  243. } else {
  244. $args['meta_query'][]=array(
  245. 'key' => '_'.THEMEX_PREFIX.$name,
  246. 'value' => sanitize_text_field($_GET[$name]),
  247. );
  248. }
  249. }
  250. }
  251. }
  252. }
  253. }
  254.  
  255. if($order=='status' && isset($_SESSION['users']) && !empty($_SESSION['users'])) {
  256. $online=$_SESSION['users'];
  257. if(isset($online[self::$data['user']['ID']])) {
  258. unset($online[self::$data['user']['ID']]);
  259. }
  260.  
  261. $online=array_keys($online);
  262. if(!empty($online) && isset($args['number']) && isset($args['offset'])) {
  263. $number=$args['number'];
  264. $args['number']=null;
  265.  
  266. $offset=$args['offset'];
  267. $args['offset']=null;
  268.  
  269. $args['exclude']=array_merge(array(self::$data['user']['ID']), $online);
  270. $users=get_users($args);
  271.  
  272. $args['include']=$online;
  273. $users=array_slice(array_merge(get_users($args), $users), $offset, $number);
  274. } else {
  275. $users=get_users($args);
  276. }
  277. } else {
  278. $users=get_users($args);
  279. }
  280.  
  281. return $users;
  282. }
  283.  
  284. /**
  285. * Removes user
  286. *
  287. * @access public
  288. * @param int $ID
  289. * @return void
  290. */
  291. public static function removeUser($ID) {
  292. global $wpdb;
  293.  
  294. $search='s:2:"ID";s:'.strlen(strval($ID)).':"'.$ID.'";';
  295. $replace='s:2:"ID";s:1:"0";';
  296. $wpdb->query($wpdb->prepare("
  297. UPDATE {$wpdb->usermeta}
  298. SET meta_value = REPLACE(meta_value, %s, %s)
  299. WHERE meta_key = '_".THEMEX_PREFIX."favorites'
  300. AND meta_value LIKE %s
  301. ", $search, $replace, '%'.$search.'%'));
  302.  
  303. $wpdb->query($wpdb->prepare("
  304. DELETE FROM {$wpdb->comments}
  305. WHERE (user_id = %d
  306. OR comment_parent = %d)
  307. AND comment_type = 'message'
  308. ", $ID, $ID));
  309. }
  310.  
  311. /**
  312. * Updates user data
  313. *
  314. * @access public
  315. * @return void
  316. */
  317. public static function updateUser() {
  318.  
  319.  
  320. $data=$_POST;
  321. if(isset($_POST['data'])) {
  322. parse_str($_POST['data'], $data);
  323. $data['nonce']=$_POST['nonce'];
  324. check_ajax_referer(THEMEX_PREFIX.'nonce', 'nonce');
  325. self::refresh();
  326. }
  327.  
  328. if(isset($data['user_action']) && wp_verify_nonce($data['nonce'], THEMEX_PREFIX.'nonce')) {
  329. $redirect=false;
  330.  
  331. switch(sanitize_title($data['user_action'])) {
  332. case 'register_user':
  333. self::registerUser($data);
  334. break;
  335.  
  336. case 'login_user':
  337. self::loginUser($data);
  338. break;
  339.  
  340. case 'reset_password':
  341. self::resetPassword($data);
  342. break;
  343.  
  344. case 'update_profile':
  345. self::updateProfile(self::$data['user']['ID'], $data);
  346. break;
  347.  
  348. case 'remove_profile':
  349. self::removeProfile(self::$data['user']['ID']);
  350. break;
  351.  
  352. case 'update_avatar':
  353. self::updateAvatar(self::$data['user']['ID'], $_FILES['user_avatar']);
  354. break;
  355.  
  356. case 'add_photo':
  357. self::addPhoto(self::$data['user']['ID'], $_FILES['user_photo']);
  358. break;
  359.  
  360. case 'remove_photo':
  361. self::removePhoto(self::$data['user']['ID'], $data['user_photo']);
  362. $redirect=true;
  363. break;
  364.  
  365. case 'feature_photo':
  366. self::featurePhoto(self::$data['user']['ID'], $data['user_photo']);
  367. break;
  368.  
  369. case 'unfeature_photo':
  370. self::featurePhoto(self::$data['user']['ID'], $data['user_photo'], false);
  371. break;
  372.  
  373. case 'add_favorite':
  374. self::addFavorite(self::$data['user']['ID'], $data['user_favorite']);
  375. break;
  376.  
  377. case 'remove_favorite':
  378. self::removeFavorite(self::$data['user']['ID'], $data['user_favorite']);
  379. $redirect=true;
  380. break;
  381.  
  382. case 'ignore_user':
  383. self::ignoreUser(self::$data['user']['ID'], $data['user_ignore']);
  384. $redirect=true;
  385. break;
  386.  
  387. case 'unignore_user':
  388. self::unignoreUser(self::$data['user']['ID'], $data['user_ignore']);
  389. $redirect=true;
  390. break;
  391.  
  392. case 'add_gift':
  393. self::addGift(self::$data['user']['ID'], $data['user_recipient'], $data['user_gift']);
  394. break;
  395.  
  396. case 'update_settings':
  397. self::updateSettings(self::$data['user']['ID'], $data);
  398. break;
  399.  
  400. case 'add_membership':
  401. self::addMembership(self::$data['user']['ID'], $data['user_membership']);
  402. $redirect=true;
  403. break;
  404.  
  405. case 'add_message':
  406. self::addMessage(self::$data['user']['ID'], $data['user_recipient'], $data['user_message']);
  407. break;
  408.  
  409. case 'update_status':
  410. self::updateStatus(self::$data['user']['ID']);
  411. break;
  412.  
  413. case 'update_chat':
  414. self::updateChat(self::$data['user']['ID'], $data['user_recipient'], $data['user_message']);
  415. break;
  416. }
  417.  
  418. if($redirect) {
  419. wp_redirect(themex_url());
  420. exit();
  421. }
  422. }
  423. }
  424.  
  425. /**
  426. * Registers user
  427. *
  428. * @access public
  429. * @param array $data
  430. * @return void
  431. */
  432. public static function registerUser($data) {
  433. if(ThemexCore::checkOption('user_captcha')) {
  434. session_start();
  435. if(isset($data['captcha']) && isset($_SESSION['captcha'])) {
  436. $posted_code=md5($data['captcha']);
  437. $session_code=$_SESSION['captcha'];
  438.  
  439. if($session_code!=$posted_code) {
  440. ThemexInterface::$messages[]=__('Verification code is incorrect', 'lovestory');
  441. }
  442. } else {
  443. ThemexInterface::$messages[]=__('Verification code is empty', 'lovestory');
  444. }
  445. }
  446.  
  447. if(empty($data['user_email']) || empty($data['user_login']) || empty($data['user_password']) || empty($data['user_password_repeat'])) {
  448. ThemexInterface::$messages[]=__('Please fill in all fields', 'lovestory');
  449. } else {
  450. if(!is_email($data['user_email'])) {
  451. ThemexInterface::$messages[]=__('Invalid email address', 'lovestory');
  452. } else if(email_exists($data['user_email'])) {
  453. ThemexInterface::$messages[]=__('This email is already in use', 'lovestory');
  454. }
  455.  
  456. if(!validate_username($data['user_login'])) {
  457. ThemexInterface::$messages[]=__('Invalid character used in username', 'lovestory');
  458. } else if(username_exists($data['user_login'])) {
  459. ThemexInterface::$messages[]=__('This username is already taken', 'lovestory');
  460. }
  461.  
  462. if(strlen($data['user_password'])<4) {
  463. ThemexInterface::$messages[]=__('Password must be at least 4 characters long', 'lovestory');
  464. } else if(strlen($data['user_password'])>16) {
  465. ThemexInterface::$messages[]=__('Password must be not more than 16 characters long', 'lovestory');
  466. } else if(preg_match("/^([a-zA-Z0-9@#-_$%^&+=!?]{1,20})$/", $data['user_password'])==0) {
  467. ThemexInterface::$messages[]=__('Password contains invalid characters', 'lovestory');
  468. } else if($data['user_password']!=$data['user_password_repeat']) {
  469. ThemexInterface::$messages[]=__('Passwords do not match', 'lovestory');
  470. }
  471. }
  472.  
  473. if(empty(ThemexInterface::$messages)){
  474. $user=wp_create_user($data['user_login'], $data['user_password'], $data['user_email']);
  475. $message=ThemexCore::getOption('email_registration', 'Hi, %username%! Welcome to '.get_bloginfo('name').'.');
  476. wp_new_user_notification($user);
  477.  
  478. $keywords=array(
  479. 'username' => $data['user_login'],
  480. 'password' => $data['user_password'],
  481. );
  482.  
  483. if(ThemexCore::checkOption('user_activation')) {
  484. ThemexInterface::$messages[]=__('Registration complete! Check your mailbox to activate the account', 'lovestory');
  485. $subject=__('Account Confirmation', 'lovestory');
  486. $activation_key=md5(uniqid(rand(), 1));
  487.  
  488. $user=new WP_User($user);
  489. $user->remove_role(get_option('default_role'));
  490. $user->add_role('inactive');
  491. ThemexCore::updateUserMeta($user->ID, 'activation_key', $activation_key);
  492.  
  493. if(strpos($message, '%link%')===false) {
  494. $message.=' Click this link to activate your account %link%';
  495. }
  496.  
  497. $link=ThemexCore::getURL('register');
  498. if(intval(substr($link, -1))==1) {
  499. $link.='&';
  500. } else {
  501. $link.='?';
  502. }
  503.  
  504. $keywords['link']=$link.'activate='.urlencode($activation_key).'&user='.$user->ID;
  505. } else {
  506. wp_signon($data, false);
  507. $subject=__('Registration Complete', 'lovestory');
  508. ThemexInterface::$messages[]='<a href="'.get_author_posts_url($user).'" class="redirect"></a>';
  509. }
  510.  
  511. themex_mail($data['user_email'], $subject, $message, $keywords);
  512. ThemexInterface::renderMessages(true);
  513. } else {
  514. ThemexInterface::renderMessages();
  515. }
  516.  
  517. die();
  518. }
  519.  
  520. /**
  521. * Activates user
  522. *
  523. * @access public
  524. * @return void
  525. */
  526. public static function activateUser() {
  527. if(isset($_GET['activate']) && isset($_GET['user']) && intval($_GET['user'])!=0) {
  528. $users=get_users(array(
  529. 'meta_key' => '_'.THEMEX_PREFIX.'activation_key',
  530. 'meta_value' => sanitize_text_field($_GET['activate']),
  531. 'include' => intval($_GET['user']),
  532. ));
  533.  
  534. if(!empty($users)) {
  535. $user=reset($users);
  536. $user=new WP_User($user->ID);
  537. $user->remove_role('inactive');
  538. $user->add_role(get_option('default_role'));
  539. wp_set_auth_cookie($user->ID, true);
  540. ThemexCore::updateUserMeta($user->ID, 'activation_key', '');
  541.  
  542. wp_redirect(get_author_posts_url($user->ID));
  543. exit();
  544. }
  545. }
  546. }
  547.  
  548. /**
  549. * Logins user
  550. *
  551. * @access public
  552. * @param array $data
  553. * @return void
  554. */
  555. public static function loginUser($data) {
  556. $data['remember']=true;
  557. $user=wp_signon($data, false);
  558.  
  559. if(is_wp_error($user) || empty($data['user_login']) || empty($data['user_password'])){
  560. ThemexInterface::$messages[]=__('Incorrect username or password', 'lovestory');
  561. } else {
  562. $role=array_shift($user->roles);
  563. if($role=='inactive') {
  564. ThemexInterface::$messages[]=__('This account is not activated', 'lovestory');
  565. }
  566. }
  567.  
  568. if(empty(ThemexInterface::$messages)) {
  569. ThemexInterface::$messages[]='<a href="'.get_author_posts_url($user->ID).'" class="redirect"></a>';
  570. } else {
  571. wp_logout();
  572. }
  573.  
  574. ThemexInterface::renderMessages();
  575. die();
  576. }
  577.  
  578. /**
  579. * Resets password
  580. *
  581. * @access public
  582. * @param array $data
  583. * @return void
  584. */
  585. public static function resetPassword($data) {
  586. global $wpdb, $wp_hasher;
  587.  
  588. if(email_exists(sanitize_email($data['user_email']))) {
  589. $user=get_user_by('email', sanitize_email($data['user_email']));
  590. do_action('lostpassword_post');
  591.  
  592. $login=$user->user_login;
  593. $email=$user->user_email;
  594.  
  595. do_action('retrieve_password', $login);
  596. $allow=apply_filters('allow_password_reset', true, $user->ID);
  597.  
  598. if(!$allow || is_wp_error($allow)) {
  599. ThemexInterface::$messages[]=__('Password recovery not allowed', 'lovestory');
  600. } else {
  601. $key=wp_generate_password(20, false);
  602. do_action('retrieve_password_key', $login, $key);
  603.  
  604. if(empty($wp_hasher)){
  605. require_once ABSPATH.'wp-includes/class-phpass.php';
  606. $wp_hasher=new PasswordHash(8, true);
  607. }
  608.  
  609. $hashed=time().':'.$wp_hasher->HashPassword($key);
  610. $wpdb->update($wpdb->users, array('user_activation_key' => $hashed), array('user_login' => $login));
  611.  
  612. $link=network_site_url('wp-login.php?action=rp&key='.$key.'&login='.rawurlencode($login), 'login');
  613. $message=ThemexCore::getOption('email_password', 'Hi, %username%! To reset your password, visit the following link: %link%.');
  614. $keywords=array(
  615. 'username' => $user->user_login,
  616. 'link' => $link,
  617. );
  618.  
  619. if(themex_mail($email, __('Password Recovery', 'lovestory'), $message, $keywords)) {
  620. ThemexInterface::$messages[]=__('Password reset link is sent', 'lovestory');
  621. } else {
  622. ThemexInterface::$messages[]=__('Error sending email', 'lovestory');
  623. }
  624. }
  625. } else {
  626. ThemexInterface::$messages[]=__('Incorrect email address', 'lovestory');
  627. }
  628.  
  629. ThemexInterface::renderMessages();
  630. die();
  631. }
  632.  
  633. /**
  634. * Filters username
  635. *
  636. * @access public
  637. * @param bool $valid
  638. * @param string $username
  639. * @return bool
  640. */
  641. public static function filterUsername($valid, $username) {
  642.  
  643. if(preg_match('/[@\s]/', $username)) {
  644. $valid=false;
  645. }
  646.  
  647. return $valid;
  648. }
  649.  
  650. /**
  651. * Gets user profile
  652. *
  653. * @access public
  654. * @param int $ID
  655. * @return array
  656. */
  657. public static function getProfile($ID) {
  658. global $wp_embed;
  659.  
  660. $profile=array();
  661. $meta=get_user_meta($ID);
  662.  
  663. $profile['name']=themex_array_value('first_name', $meta);
  664. $profile['nickname']=themex_array_value('nickname', $meta);
  665.  
  666. if(ThemexCore::checkOption('user_name') || empty($profile['name'])) {
  667. $profile['first_name']=$profile['nickname'];
  668. $profile['last_name']='';
  669. $profile['full_name']=$profile['first_name'];
  670. } else {
  671. $profile['first_name']=$profile['name'];
  672. $profile['last_name']=themex_array_value('last_name', $meta);
  673. $profile['full_name']=trim($profile['first_name'].' '.$profile['last_name']);
  674. }
  675.  
  676. if(!ThemexCore::checkOption('user_location')) {
  677. $profile['country']=themex_array_value('_'.THEMEX_PREFIX.'country', $meta);
  678. $profile['city']=themex_array_value('_'.THEMEX_PREFIX.'city', $meta);
  679. }
  680.  
  681. $profile['description']=themex_array_value('description', $meta);
  682. $profile['gender']=themex_array_value('_'.THEMEX_PREFIX.'gender', $meta);
  683. $profile['seeking']=themex_array_value('_'.THEMEX_PREFIX.'seeking', $meta);
  684. $profile['age']=themex_array_value('_'.THEMEX_PREFIX.'age', $meta);
  685.  
  686. if(isset(ThemexForm::$data['profile']) && is_array(ThemexForm::$data['profile'])) {
  687. foreach(ThemexForm::$data['profile'] as $field) {
  688. $name=themex_sanitize_key($field['name']);
  689. if(!isset($profile[$name])) {
  690. $profile[$name]=themex_array_value('_'.THEMEX_PREFIX.$name, $meta);
  691. }
  692. }
  693. }
  694.  
  695. return $profile;
  696. }
  697.  
  698. /**
  699. * Updates user profile
  700. *
  701. * @access public
  702. * @param int $ID
  703. * @param array $data
  704. * @return void
  705. */
  706. public static function updateProfile($ID, $data) {
  707.  
  708. $fields=array();
  709. $filters=self::getFilters();
  710.  
  711. if(!ThemexCore::checkOption('user_name')) {
  712. $fields[]=array(
  713. 'label' => __('First Name', 'lovestory'),
  714. 'name' => 'first_name',
  715. 'type' => 'text',
  716. 'default' => true,
  717. );
  718.  
  719. $fields[]=array(
  720. 'label' => __('Last Name', 'lovestory'),
  721. 'name' => 'last_name',
  722. 'type' => 'text',
  723. 'default' => true,
  724. );
  725. }
  726.  
  727. if(!ThemexCore::checkOption('user_gender')) {
  728. $fields[]=array(
  729. 'label' => __('Gender', 'lovestory'),
  730. 'name' => 'gender',
  731. 'type' => 'text',
  732. );
  733.  
  734. $fields[]=array(
  735. 'label' => __('Seeking', 'lovestory'),
  736. 'name' => 'seeking',
  737. 'type' => 'text',
  738. );
  739. }
  740.  
  741. if(!ThemexCore::checkOption('user_age')) {
  742. $fields[]=array(
  743. 'label' => __('Age', 'lovestory'),
  744. 'name' => 'age',
  745. 'type' => 'number',
  746. );
  747. }
  748.  
  749. if(!ThemexCore::checkOption('user_location')) {
  750. $fields[]=array(
  751. 'label' => __('Country', 'lovestory'),
  752. 'name' => 'country',
  753. 'type' => 'select',
  754. );
  755.  
  756. $fields[]=array(
  757. 'label' => __('City', 'lovestory'),
  758. 'name' => 'city',
  759. 'type' => 'name',
  760. );
  761. }
  762.  
  763. if(isset(ThemexForm::$data['profile'])) {
  764. $fields=array_merge($fields, ThemexForm::$data['profile']);
  765. }
  766.  
  767. foreach($fields as $field) {
  768. $name=themex_sanitize_key($field['name']);
  769. if(isset($field['default'])) {
  770. $name=$field['name'];
  771. }
  772.  
  773. if(isset($field['label'])) {
  774. $field['name']=$field['label'];
  775. }
  776.  
  777. if(isset($data[$name])) {
  778. if($field['type']=='number') {
  779. $data[$name]=intval($data[$name]);
  780. } else if($field['type']=='name') {
  781. $data[$name]=ucwords(strtolower(trim($data[$name])));
  782. } else {
  783. $data[$name]=sanitize_text_field($data[$name]);
  784. }
  785.  
  786. if(!isset($field['optional']) && ($data[$name]=='' || ($field['type']=='select' && $data[$name]=='0'))) {
  787. ThemexInterface::$messages[]='"'.$field['name'].'" '.__('field is required', 'lovestory');
  788. } else {
  789. if(isset($field['default'])) {
  790. update_user_meta($ID, $name, $data[$name]);
  791. } else {
  792. ThemexCore::updateUserMeta($ID, $name, $data[$name]);
  793. }
  794. }
  795. }
  796. }
  797.  
  798. if(isset($data['description'])) {
  799. $data['description']=trim(preg_replace($filters, '', $data['description']));
  800. $data['description']=wp_kses($data['description'], array(
  801. 'strong' => array(),
  802. 'em' => array(),
  803. 'a' => array(
  804. 'href' => array(),
  805. 'title' => array(),
  806. 'target' => array(),
  807. ),
  808. 'p' => array(),
  809. 'br' => array(),
  810. ));
  811.  
  812. update_user_meta($ID, 'description', $data['description']);
  813. }
  814.  
  815. self::$data['user']['profile']=self::getProfile($ID);
  816. if(empty(ThemexInterface::$messages)) {
  817. if(isset($data['update'])) {
  818. ThemexCore::updateUserMeta($ID, 'updated', date('Y-m-d'));
  819. }
  820.  
  821. ThemexInterface::$messages[]=__('Profile has been successfully saved', 'lovestory');
  822. $_POST['success']=true;
  823. } else if(!ThemexCore::checkOption('user_name')) {
  824. update_user_meta($ID, 'first_name', '');
  825. self::$data['user']['profile']['first_name']=$data['first_name'];
  826. }
  827. }
  828.  
  829. /**
  830. * Removes user profile
  831. *
  832. * @access public
  833. * @param int $ID
  834. * @return void
  835. */
  836. public static function removeProfile($ID) {
  837. wp_logout();
  838. wp_update_user(array(
  839. 'ID' => $ID,
  840. 'role' => 'inactive',
  841. ));
  842.  
  843. wp_redirect(SITE_URL);
  844. exit();
  845. }
  846.  
  847. /**
  848. * Filters default avatar
  849. *
  850. * @access public
  851. * @param string $avatar
  852. * @param int $user_id
  853. * @param int $size
  854. * @param string $default
  855. * @param string $alt
  856. * @return string
  857. */
  858. public static function getAvatar($avatar, $user, $size, $default, $alt) {
  859. if(isset($user->user_id)) {
  860. $user=$user->user_id;
  861. }
  862.  
  863. $avatar_id=ThemexCore::getUserMeta($user, 'avatar');
  864. $default=wp_get_attachment_image_src( $avatar_id, 'preview');
  865. $image=THEME_URI.'images/avatar.png';
  866.  
  867. if(isset($default[0])) {
  868. $image=themex_resize($default[0], $size, $size, true, true);
  869. }
  870.  
  871. return '<img src="'.$image.'" class="avatar" width="'.$size.'" alt="'.$alt.'" />';
  872. }
  873.  
  874. /**
  875. * Updates user avatar
  876. *
  877. * @access public
  878. * @param int $ID
  879. * @param array $file
  880. * @return void
  881. */
  882. public static function updateAvatar($ID, $file) {
  883. wp_delete_attachment(ThemexCore::getUserMeta($ID, 'avatar'));
  884. $attachment=ThemexCore::uploadImage($file);
  885.  
  886. if(isset($attachment['ID']) && $attachment['ID']!=0) {
  887. ThemexCore::updateUserMeta($ID, 'avatar', $attachment['ID']);
  888. }
  889. }
  890.  
  891. /**
  892. * Gets user excerpt
  893. *
  894. * @access public
  895. * @param int $ID
  896. * @return string
  897. */
  898. public static function getExcerpt($profile) {
  899. $out='';
  900. if(!empty($profile['age'])) {
  901. $out.=$profile['age'].' '.__('years old', 'lovestory');
  902. }
  903.  
  904. if(!empty($profile['gender'])) {
  905. $out.=' '.themex_array_value($profile['gender'], ThemexCore::$components['genders']);
  906. }
  907.  
  908. if(!empty($profile['country']) || !empty($profile['city'])) {
  909. $out.=' '.__('from', 'lovestory').' ';
  910.  
  911. if(!empty($profile['city'])) {
  912. $out.=$profile['city'].', ';
  913. }
  914.  
  915. if(!empty($profile['country'])) {
  916. $out.=themex_array_value($profile['country'], ThemexCore::$components['countries']);
  917. }
  918. }
  919.  
  920. return $out;
  921. }
  922.  
  923. /**
  924. * Checks featured photo
  925. *
  926. * @access public
  927. * @param int $ID
  928. * @return bool
  929. */
  930. public static function isFeaturedPhoto($ID) {
  931. if(isset(self::$data['user']['photos'][$ID]) && self::$data['user']['photos'][$ID]['featured']) {
  932. return true;
  933. }
  934.  
  935. return false;
  936. }
  937.  
  938. /**
  939. * Features photo
  940. *
  941. * @access public
  942. * @param int $ID
  943. * @param bool $feature
  944. * @return void
  945. */
  946. public static function featurePhoto($ID, $attachment, $feature=true) {
  947. if(isset(self::$data['user']['photos'][$attachment])) {
  948. self::$data['user']['photos'][$attachment]['featured']=$feature;
  949. ThemexCore::updateUserMeta($ID, 'photos', self::$data['user']['photos']);
  950. }
  951. }
  952.  
  953. /**
  954. * Sorts user photos
  955. *
  956. * @access public
  957. * @param array $photos
  958. * @return array
  959. */
  960. public static function sortPhotos($photos) {
  961. $photos=array_reverse($photos);
  962. usort($photos, array(__CLASS__, 'comparePhotos'));
  963. return $photos;
  964. }
  965.  
  966. /**
  967. * Compares user photos
  968. *
  969. * @access public
  970. * @param array $a
  971. * @param array $b
  972. * @return int
  973. */
  974. public static function comparePhotos($a, $b) {
  975. $out=0;
  976.  
  977. if($a['featured']<$b['featured']) {
  978. $out=1;
  979. } else {
  980. $out=-1;
  981. }
  982.  
  983. return $out;
  984. }
  985.  
  986. /**
  987. * Adds user photo
  988. *
  989. * @access public
  990. * @param int $ID
  991. * @param array $file
  992. * @return void
  993. */
  994. public static function addPhoto($ID, $file) {
  995. $attachment=ThemexCore::uploadImage($file);
  996.  
  997. if(self::$data['user']['membership']['photos']>0 && $attachment['ID']!=0) {
  998. array_unshift(self::$data['user']['photos'], array(
  999. 'ID' => $attachment['ID'],
  1000. 'date' => current_time('timestamp'),
  1001. 'featured' => '0',
  1002. ));
  1003.  
  1004. self::updateMembership($ID, 'photos', -1);
  1005. ThemexCore::updateUserMeta($ID, 'photos', self::$data['user']['photos']);
  1006. wp_redirect(themex_url());
  1007. }
  1008. }
  1009.  
  1010. /**
  1011. * Removes user photo
  1012. *
  1013. * @access public
  1014. * @param int $ID
  1015. * @param int $attachment
  1016. * @return void
  1017. */
  1018. public static function removePhoto($ID, $attachment) {
  1019. if(isset(self::$data['user']['photos'][$attachment])) {
  1020. unset(self::$data['user']['photos'][$attachment]);
  1021. wp_delete_attachment($attachment);
  1022. ThemexCore::updateUserMeta($ID, 'photos', self::$data['user']['photos']);
  1023. }
  1024. }
  1025.  
  1026. /**
  1027. * Checks user favorite
  1028. *
  1029. * @access public
  1030. * @param int $ID
  1031. * @return bool
  1032. */
  1033. public static function isFavorite($ID) {
  1034. if(isset(self::$data['user']['favorites'][$ID])) {
  1035. return true;
  1036. }
  1037.  
  1038. return false;
  1039. }
  1040.  
  1041. /**
  1042. * Adds user favorite
  1043. *
  1044. * @access public
  1045. * @param int $ID
  1046. * @param int $user
  1047. * @return void
  1048. */
  1049. public static function addFavorite($ID, $user) {
  1050. if(!isset(self::$data['user']['favorites'][$user])) {
  1051. array_unshift(self::$data['user']['favorites'], array(
  1052. 'ID' => $user,
  1053. 'date' => current_time('timestamp'),
  1054. ));
  1055.  
  1056. ThemexCore::updateUserMeta($ID, 'favorites', self::$data['user']['favorites']);
  1057. }
  1058. }
  1059.  
  1060. /**
  1061. * Removes user favorite
  1062. *
  1063. * @access public
  1064. * @param int $ID
  1065. * @param int $user
  1066. * @return void
  1067. */
  1068. public static function removeFavorite($ID, $user) {
  1069. if(isset(self::$data['user']['favorites'][$user])) {
  1070. unset(self::$data['user']['favorites'][$user]);
  1071. ThemexCore::updateUserMeta($ID, 'favorites', self::$data['user']['favorites']);
  1072. }
  1073. }
  1074.  
  1075. /**
  1076. * Renders gifts template
  1077. *
  1078. * @access public
  1079. * @return void
  1080. */
  1081. public static function renderGifts() {
  1082. if(!ThemexCore::checkOption('user_gifts')) {
  1083. get_template_part('template', 'gifts');
  1084. }
  1085. }
  1086.  
  1087. /**
  1088. * Adds user gift
  1089. *
  1090. * @access public
  1091. * @param int $ID
  1092. * @param int $user
  1093. * @param int $gift
  1094. * @return void
  1095. */
  1096. public static function addGift($ID, $user, $gift) {
  1097. if(self::$data['user']['membership']['gifts']>0) {
  1098. $gifts=ThemexCore::getUserMeta($user, 'gifts', array());
  1099. array_unshift($gifts, array(
  1100. 'ID' => $gift,
  1101. 'sender' => $ID,
  1102. 'date' => current_time('timestamp'),
  1103. ));
  1104.  
  1105. ThemexCore::updateUserMeta($user, 'gifts', $gifts);
  1106. self::updateMembership($ID, 'gifts', -1);
  1107.  
  1108. if(!ThemexCore::checkOption('user_notice')) {
  1109. $recipient=self::getUser($user, true);
  1110. if(in_array($recipient['settings']['notices'], array(1, 3))) {
  1111. $message=ThemexCore::getOption('email_gift', 'Hi, %username%! You have received a new gift from %sender% %link%.');
  1112. $keywords=array(
  1113. 'username' => $recipient['login'],
  1114. 'sender' => self::$data['user']['profile']['full_name'],
  1115. 'link' => $recipient['profile_url'],
  1116. );
  1117.  
  1118. themex_mail($recipient['email'], __('New Gift', 'lovestory'), $message, $keywords);
  1119. }
  1120. }
  1121.  
  1122. ThemexInterface::$messages[]=__('Selected gift has been successfully sent', 'lovestory');
  1123. ThemexInterface::renderMessages(true);
  1124. } else {
  1125. ThemexInterface::$messages[]=__('You have exceeded the number of gifts', 'lovestory');
  1126. ThemexInterface::renderMessages();
  1127. }
  1128.  
  1129. die();
  1130. }
  1131.  
  1132. /**
  1133. * Ignores user
  1134. *
  1135. * @access public
  1136. * @param int $ID
  1137. * @param int $user
  1138. * @return void
  1139. */
  1140. public static function ignoreUser($ID, $user) {
  1141. if(!isset(self::$data['user']['ignores'][$user])) {
  1142. array_unshift(self::$data['user']['ignores'], array(
  1143. 'ID' => $user,
  1144. 'date' => current_time('timestamp'),
  1145. ));
  1146.  
  1147. ThemexCore::updateUserMeta($ID, 'ignores', self::$data['user']['ignores']);
  1148. }
  1149. }
  1150.  
  1151. /**
  1152. * Unignores user
  1153. *
  1154. * @access public
  1155. * @param int $ID
  1156. * @param int $user
  1157. * @return void
  1158. */
  1159. public static function unignoreUser($ID, $user) {
  1160. if(isset(self::$data['user']['ignores'][$user])) {
  1161. unset(self::$data['user']['ignores'][$user]);
  1162. ThemexCore::updateUserMeta($ID, 'ignores', self::$data['user']['ignores']);
  1163. }
  1164. }
  1165.  
  1166. /**
  1167. * Checks ignored user
  1168. *
  1169. * @access public
  1170. * @param int $ID
  1171. * @param bool $current
  1172. * @return bool
  1173. */
  1174. public static function isIgnored($ID, $current=true) {
  1175. $ignores=self::$data['user']['ignores'];
  1176. if(!$current) {
  1177. $ignores=self::$data['active_user']['ignores'];
  1178. }
  1179.  
  1180. if(isset($ignores[$ID])) {
  1181. return true;
  1182. }
  1183.  
  1184. return false;
  1185. }
  1186.  
  1187. /**
  1188. * Gets user membership
  1189. *
  1190. * @access public
  1191. * @param int $ID
  1192. * @param string $gender
  1193. * @return array
  1194. */
  1195. public static function getMembership($ID, $gender) {
  1196. global $wpdb;
  1197. $filter=ThemexCore::getOption('user_membership');
  1198.  
  1199. if($filter=='none' || ($filter=='woman' && $gender=='woman')) {
  1200. $membership=array(
  1201. 'ID' => -1,
  1202. 'name' => __('Free', 'lovestory'),
  1203. 'date' => current_time('timestamp')+60,
  1204. 'messages' => 1,
  1205. 'photos' => 1,
  1206. 'gifts' => 1,
  1207. 'chat' => 1,
  1208. );
  1209. } else {
  1210. $membership=ThemexCore::getUserMeta($ID, 'membership');
  1211.  
  1212. if(function_exists('wcs_get_users_subscriptions')) {
  1213. $subscriptions=wcs_get_users_subscriptions($ID);
  1214. } else {
  1215. $subscriptions=get_user_meta($ID, $wpdb->prefix.'woocommerce_subscriptions', true);
  1216. }
  1217.  
  1218. if(!empty($membership)) {
  1219. if(is_array($subscriptions) && !empty($subscriptions)) {
  1220. $product=intval(ThemexCore::getPostMeta($membership['ID'], 'product'));
  1221.  
  1222. if($product!=0) {
  1223. foreach($subscriptions as $key=>$subscription) {
  1224. if(function_exists('wcs_get_users_subscriptions')) {
  1225. $first=reset($subscription->order->get_items());
  1226.  
  1227. if(is_array($first) && isset($first['product_id']) && $first['product_id']==$product) {
  1228. $time=strtotime($subscription->end_date);
  1229.  
  1230. if(empty($time)) {
  1231. $time=strtotime($subscription->next_payment_date)+84600;
  1232. }
  1233.  
  1234. $membership['date']=$time;
  1235.  
  1236. break;
  1237. }
  1238. } else if($subscription['product_id']==$product) {
  1239. $time=strtotime($subscription['expiry_date']);
  1240.  
  1241. if($time!==false) {
  1242. $membership['date']=$time;
  1243. } else {
  1244. $time=wp_next_scheduled('scheduled_subscription_payment', array(
  1245. 'user_id' => $ID,
  1246. 'subscription_key' => $key,
  1247. ));
  1248.  
  1249. if($time!=false) {
  1250. $membership['date']=$time+84600;
  1251. }
  1252. }
  1253.  
  1254. break;
  1255. }
  1256. }
  1257. }
  1258. }
  1259.  
  1260. $period=intval(ThemexCore::getPostMeta($membership['ID'], 'period'));
  1261. if(isset($membership['date']) && empty($period)) {
  1262. unset($membership['date']);
  1263. }
  1264. }
  1265.  
  1266. if(is_array($membership) && !isset($membership['chat'])) {
  1267. $membership['chat']=1;
  1268. }
  1269. }
  1270.  
  1271. if(empty($membership) || (isset($membership['date']) && $membership['date']<current_time('timestamp'))) {
  1272. $date=intval(ThemexCore::getOption('user_membership_date', 31))*86400+current_time('timestamp');
  1273. $messages=intval(ThemexCore::getOption('user_membership_messages', 100));
  1274. $photos=intval(ThemexCore::getOption('user_membership_photos', 10));
  1275. $gifts=intval(ThemexCore::getOption('user_membership_gifts', 5));
  1276. $chat=intval(ThemexCore::getOption('user_membership_chat', 1));
  1277.  
  1278. if(isset($membership['date'])) {
  1279. $messages=0;
  1280. $photos=0;
  1281. $gifts=0;
  1282. $chat=0;
  1283. }
  1284.  
  1285. $membership=array(
  1286. 'ID' => 0,
  1287. 'name' => __('Free', 'lovestory'),
  1288. 'date' => $date,
  1289. 'messages' => $messages,
  1290. 'photos' => $photos,
  1291. 'gifts' => $gifts,
  1292. 'chat' => $chat,
  1293. );
  1294.  
  1295. ThemexCore::updateUserMeta($ID, 'membership', $membership);
  1296. }
  1297.  
  1298. return $membership;
  1299. }
  1300.  
  1301. /**
  1302. * Adds user membership
  1303. *
  1304. * @access public
  1305. * @param int $ID
  1306. * @param int $membership
  1307. * @param bool $checkout
  1308. * @return void
  1309. */
  1310. public static function addMembership($ID, $membership, $checkout=true) {
  1311.  
  1312. if($checkout && ThemexWoo::isActive()) {
  1313. $product=intval(ThemexCore::getPostMeta($membership, 'product'));
  1314. if($product!=0) {
  1315. ThemexWoo::addProduct($product);
  1316. }
  1317. } else {
  1318. $title=get_the_title($membership);
  1319. $date=intval(ThemexCore::getPostMeta($membership, 'period'))*86400+current_time('timestamp');
  1320. $messages=intval(ThemexCore::getPostMeta($membership, 'messages'));
  1321. $photos=intval(ThemexCore::getPostMeta($membership, 'photos'));
  1322. $gifts=intval(ThemexCore::getPostMeta($membership, 'gifts'));
  1323. $chat=intval(ThemexCore::getPostMeta($membership, 'chat'));
  1324.  
  1325. $membership=array(
  1326. 'ID' => $membership,
  1327. 'name' => $title,
  1328. 'date' => $date,
  1329. 'messages' => $messages,
  1330. 'photos' => $photos,
  1331. 'gifts' => $gifts,
  1332. 'chat' => $chat,
  1333. );
  1334.  
  1335. ThemexCore::updateUserMeta($ID, 'membership', $membership);
  1336. }
  1337. }
  1338.  
  1339. /**
  1340. * Removes user membership
  1341. *
  1342. * @access public
  1343. * @param int $ID
  1344. * @param int $membership
  1345. * @return void
  1346. */
  1347. public static function removeMembership($ID) {
  1348.  
  1349. $date=intval(ThemexCore::getOption('user_membership_date', 31))*86400+current_time('timestamp');
  1350. $membership=array(
  1351. 'ID' => 0,
  1352. 'name' => __('Free', 'lovestory'),
  1353. 'date' => $date,
  1354. 'messages' => 0,
  1355. 'photos' => 0,
  1356. 'gifts' => 0,
  1357. 'chat' => 0,
  1358. );
  1359.  
  1360. ThemexCore::updateUserMeta($ID, 'membership', $membership);
  1361. }
  1362.  
  1363. /**
  1364. * Updates user membership
  1365. *
  1366. * @access public
  1367. * @param int $ID
  1368. * @param string $name
  1369. * @param int $value
  1370. * @return array
  1371. */
  1372. public static function updateMembership($ID, $name, $value) {
  1373. self::$data['user']['membership'][$name]=intval(self::$data['user']['membership'][$name])+$value;
  1374. ThemexCore::updateUserMeta($ID, 'membership', self::$data['user']['membership']);
  1375. }
  1376.  
  1377. /**
  1378. * Filters user membership
  1379. *
  1380. * @access public
  1381. * @return void
  1382. */
  1383. public static function filterMembership() {
  1384. if(get_query_var('chat') && !self::$data['user']['membership']['chat']) {
  1385. wp_redirect(SITE_URL);
  1386. exit();
  1387. }
  1388.  
  1389. if(!is_user_logged_in() && get_query_var('author') && ThemexCore::checkOption('user_guest')) {
  1390. wp_redirect(ThemexCore::getURL('register'));
  1391. exit();
  1392. }
  1393. }
  1394.  
  1395. /**
  1396. * Saves membership users
  1397. *
  1398. * @param int $ID
  1399. * @access public
  1400. * @return void
  1401. */
  1402. public static function saveMembership($ID) {
  1403. if(current_user_can('edit_posts') && isset($_POST['post_type']) && $_POST['post_type']=='membership') {
  1404. if(isset($_POST['add_user']) && isset($_POST['add_user_id'])) {
  1405. self::addMembership(intval($_POST['add_user_id']), $ID, false);
  1406. } else if(isset($_POST['remove_user']) && isset($_POST['remove_user_id'])) {
  1407. self::removeMembership(intval($_POST['remove_user_id']));
  1408. }
  1409. }
  1410. }
  1411.  
  1412. /**
  1413. * Gets user settings
  1414. *
  1415. * @access public
  1416. * @param int $ID
  1417. * @return array
  1418. */
  1419. public static function getSettings($ID) {
  1420. $settings=ThemexCore::getUserMeta($ID, 'settings', array(
  1421. 'favorites' => ThemexCore::getOption('user_settings_favorites', 1),
  1422. 'photos' => ThemexCore::getOption('user_settings_photos', 1),
  1423. 'gifts' => ThemexCore::getOption('user_settings_gifts', 1),
  1424. 'notices' => 1,
  1425. ));
  1426.  
  1427. return $settings;
  1428. }
  1429.  
  1430. /**
  1431. * Updates user settings
  1432. *
  1433. * @access public
  1434. * @param int $ID
  1435. * @param array $data
  1436. * @return void
  1437. */
  1438. public static function updateSettings($ID, $data) {
  1439.  
  1440. $settings=array();
  1441. $current=get_user_by('id', $ID);
  1442. $required=false;
  1443.  
  1444. $user=array(
  1445. 'ID' => $ID,
  1446. );
  1447.  
  1448. //favorites
  1449. if(isset($data['user_favorites'])) {
  1450. $settings['favorites']=intval($data['user_favorites']);
  1451. }
  1452.  
  1453. //photos
  1454. if(isset($data['user_photos'])) {
  1455. $settings['photos']=intval($data['user_photos']);
  1456. }
  1457.  
  1458. //gifts
  1459. if(isset($data['user_gifts'])) {
  1460. $settings['gifts']=intval($data['user_gifts']);
  1461. }
  1462.  
  1463. //notices
  1464. if(isset($data['user_notices'])) {
  1465. $settings['notices']=intval($data['user_notices']);
  1466. }
  1467.  
  1468. //password
  1469. $new_password=trim(themex_array_value('user_password_new', $data));
  1470. if(!empty($new_password)) {
  1471. $confirm_password=trim(themex_array_value('user_password_confirm', $data));
  1472. $user['user_pass']=$new_password;
  1473. $required=true;
  1474.  
  1475. if(strlen($new_password)<4) {
  1476. ThemexInterface::$messages[]=__('Password must be at least 4 characters long', 'lovestory');
  1477. } else if(strlen($new_password)>16) {
  1478. ThemexInterface::$messages[]=__('Password must be not more than 16 characters long', 'lovestory');
  1479. } else if(preg_match("/^([a-zA-Z0-9@#-_$%^&+=!?]{1,20})$/", $new_password)==0) {
  1480. ThemexInterface::$messages[]=__('Password contains invalid characters', 'lovestory');
  1481. } else if($new_password!=$confirm_password) {
  1482. ThemexInterface::$messages[]=__('Passwords do not match', 'lovestory');
  1483. }
  1484. }
  1485.  
  1486. //email
  1487. $email=trim(themex_array_value('user_email', $data));
  1488. if($email!=$current->user_email) {
  1489. self::$data['user']['email']=$email;
  1490. $user['user_email']=$email;
  1491. $required=true;
  1492.  
  1493. if(!is_email($email)) {
  1494. ThemexInterface::$messages[]=__('Email address is invalid', 'lovestory');
  1495. }
  1496. }
  1497.  
  1498. $current_password=trim(themex_array_value('user_password', $data));
  1499. if($required && !wp_check_password($current_password, $current->user_pass, $current->ID)) {
  1500. ThemexInterface::$messages[]=__('Current password is incorrect', 'lovestory');
  1501. }
  1502.  
  1503. ThemexCore::updateUserMeta($ID, 'settings', $settings);
  1504. self::$data['user']['settings']=self::getSettings($ID);
  1505.  
  1506. if(empty(ThemexInterface::$messages)) {
  1507. wp_update_user($user);
  1508.  
  1509. ThemexInterface::$messages[]=__('Settings have been successfully saved', 'lovestory');
  1510. $_POST['success']=true;
  1511. }
  1512. }
  1513.  
  1514. /**
  1515. * Checks user access
  1516. *
  1517. * @access public
  1518. * @param int $ID
  1519. * @param string $type
  1520. * @return bool
  1521. */
  1522. public static function checkAccess($ID, $user, $type) {
  1523. $settings=self::getSettings($user);
  1524. $access=false;
  1525.  
  1526. if(isset($settings[$type])) {
  1527. $level=intval($settings[$type]);
  1528. if($ID==$user || $level==1 || ($level==2 && isset(self::$data['active_user']['favorites'][$ID]))) {
  1529. $access=true;
  1530. }
  1531. }
  1532.  
  1533. return $access;
  1534. }
  1535.  
  1536. /**
  1537. * Gets user recipients
  1538. *
  1539. * @access public
  1540. * @param int $ID
  1541. * @return array
  1542. */
  1543. public static function getRecipients($ID) {
  1544. global $wpdb;
  1545. $recipients=array();
  1546.  
  1547. $messages=$wpdb->get_results($wpdb->prepare("
  1548. SELECT c.user_id as user_id, c.comment_karma as comment_karma, c.comment_parent as comment_parent FROM {$wpdb->comments} c
  1549. WHERE (c.user_id = %d
  1550. OR c.comment_parent = %d)
  1551. AND c.comment_type = 'message'
  1552. ORDER BY c.comment_date DESC
  1553. ", $ID, $ID));
  1554.  
  1555. foreach($messages as $message) {
  1556. if(!isset($recipients[$message->user_id])) {
  1557. $recipients[$message->user_id]=array(
  1558. 'ID' => $message->user_id,
  1559. 'unread' => 0,
  1560. );
  1561. }
  1562.  
  1563. if(!isset($recipients[$message->comment_parent])) {
  1564. $recipients[$message->comment_parent]=array(
  1565. 'ID' => $message->comment_parent,
  1566. 'unread' => 0,
  1567. );
  1568. }
  1569.  
  1570. if($message->comment_karma==0) {
  1571. $recipients[$message->user_id]['unread']++;
  1572. }
  1573. }
  1574.  
  1575. unset($recipients[$ID]);
  1576. $recipients=array_reverse($recipients);
  1577. usort($recipients, array(__CLASS__, 'compareRecipients'));
  1578.  
  1579. return $recipients;
  1580. }
  1581.  
  1582. /**
  1583. * Compares user recipients
  1584. *
  1585. * @access public
  1586. * @param array $a
  1587. * @param array $b
  1588. * @return int
  1589. */
  1590. public static function compareRecipients($a, $b) {
  1591. $out=0;
  1592.  
  1593. if($a['unread']<$b['unread']) {
  1594. $out=1;
  1595. } else {
  1596. $out=-1;
  1597. }
  1598.  
  1599. return $out;
  1600. }
  1601.  
  1602. /**
  1603. * Gets user messages
  1604. *
  1605. * @access public
  1606. * @param int $ID
  1607. * @param int $user
  1608. * @param int $page
  1609. * @return array
  1610. */
  1611. public static function getMessages($ID, $user, $page=null) {
  1612. global $wpdb;
  1613.  
  1614. $offset=0;
  1615. $number=999999;
  1616. if(!is_null($page)) {
  1617. $offset=(intval($page)-1)*5;
  1618. $number=5;
  1619. }
  1620.  
  1621. $messages=$wpdb->get_results($wpdb->prepare("
  1622. SELECT c.comment_ID as comment_ID, c.user_id as user_id,
  1623. c.comment_date as comment_date, c.comment_content as comment_content FROM {$wpdb->comments} c
  1624. WHERE ((c.comment_parent = %d
  1625. AND c.user_id = %d)
  1626. OR (c.user_id = %d
  1627. AND c.comment_parent = %d))
  1628. AND c.comment_type = 'message'
  1629. ORDER BY c.comment_date DESC
  1630. LIMIT %d, %d
  1631. ", $ID, $user, $ID, $user, $offset, $number));
  1632.  
  1633. if(!empty($messages)) {
  1634. $wpdb->query($wpdb->prepare("
  1635. UPDATE {$wpdb->comments} c
  1636. SET c.comment_karma = '1'
  1637. WHERE c.comment_parent = %d
  1638. AND c.user_id = %d
  1639. AND c.comment_type = 'message'
  1640. ", $ID, $user));
  1641. }
  1642.  
  1643. $messages=array_reverse($messages);
  1644. return $messages;
  1645. }
  1646.  
  1647. /**
  1648. * Filters user messages
  1649. *
  1650. * @access public
  1651. * @param mixed $query
  1652. * @return mixed
  1653. */
  1654. public static function filterMessages($query) {
  1655. if(isset($query['where'])) {
  1656. $query['where'].=" AND comment_type <> 'message'";
  1657. }
  1658.  
  1659. return $query;
  1660. }
  1661.  
  1662. /**
  1663. * Counts unread messages
  1664. *
  1665. * @access public
  1666. * @param int $ID
  1667. * @return array
  1668. */
  1669. public static function countMessages($ID) {
  1670. global $wpdb;
  1671.  
  1672. $messages=$wpdb->get_results( $wpdb->prepare("
  1673. SELECT c.user_id as user_id FROM {$wpdb->comments} c
  1674. WHERE c.comment_parent = %d
  1675. AND c.comment_type = 'message'
  1676. AND c.comment_karma = '0'
  1677. ORDER BY c.comment_date DESC
  1678. ", $ID, $ID));
  1679.  
  1680. $number=count($messages);
  1681. if($number==0) {
  1682. $number='';
  1683. }
  1684.  
  1685. return $number;
  1686. }
  1687.  
  1688. /**
  1689. * Adds user message
  1690. *
  1691. * @access public
  1692. * @param int $ID
  1693. * @param int $user
  1694. * @param string $message
  1695. * @return void
  1696. */
  1697. public static function addMessage($ID, $user, $message) {
  1698. if(self::$data['user']['membership']['messages']>0) {
  1699. $filters=self::getFilters();
  1700. $message=trim(preg_replace($filters, '', $message));
  1701.  
  1702. if(!empty($message)) {
  1703. if(!self::isIgnored($ID, false)) {
  1704. $sender=self::$data['user'];
  1705. $message=wp_insert_comment(array(
  1706. 'comment_post_ID' => 0,
  1707. 'comment_karma' => 0,
  1708. 'comment_type' => 'message',
  1709. 'comment_parent' => $user,
  1710. 'user_id' => $sender['ID'],
  1711. 'comment_author' => $sender['login'],
  1712. 'comment_author_email' => $sender['email'],
  1713. 'comment_content' => wp_kses($message, array(
  1714. 'strong' => array(),
  1715. 'em' => array(),
  1716. 'a' => array(
  1717. 'href' => array(),
  1718. 'title' => array(),
  1719. 'target' => array(),
  1720. ),
  1721. 'p' => array(),
  1722. 'br' => array(),
  1723. )),
  1724. ));
  1725.  
  1726. if(!ThemexCore::checkOption('user_notice')) {
  1727. $recipient=self::$data['active_user'];
  1728. if(in_array($recipient['settings']['notices'], array(1, 2))) {
  1729. $message=ThemexCore::getOption('email_message', 'Hi, %username%! You have received a new message from %sender% %link%.');
  1730. $keywords=array(
  1731. 'username' => $recipient['login'],
  1732. 'sender' => self::$data['user']['profile']['full_name'],
  1733. 'link' => self::$data['user']['message_url'],
  1734. );
  1735.  
  1736. themex_mail($recipient['email'], __('New Message', 'lovestory'), $message, $keywords);
  1737. }
  1738. }
  1739.  
  1740. self::updateMembership($ID, 'messages', -1);
  1741. } else {
  1742. ThemexInterface::$messages[]=__("You've been added to the ignore list", 'lovestory');
  1743. }
  1744. } else {
  1745. ThemexInterface::$messages[]=__('Message field must not be empty', 'lovestory');
  1746. }
  1747. } else {
  1748. ThemexInterface::$messages[]=__('You have exceeded the number of messages', 'lovestory');
  1749. }
  1750.  
  1751. if(empty(ThemexInterface::$messages)) {
  1752. wp_redirect(themex_url());
  1753. exit();
  1754. }
  1755. }
  1756.  
  1757. /**
  1758. * Gets message filters
  1759. *
  1760. * @access public
  1761. * @return array
  1762. */
  1763. public static function getFilters() {
  1764. $filters=explode(',', ThemexCore::getOption('user_message_filters'));
  1765. $filters=array_merge($filters, array(self::$data['user']['email']));
  1766.  
  1767. foreach($filters as &$filter) {
  1768. $filter='/\b'.preg_quote(trim($filter), '/').'\b/';
  1769. }
  1770.  
  1771. return $filters;
  1772. }
  1773.  
  1774. /**
  1775. * Updates user chat
  1776. *
  1777. * @access public
  1778. * @param int $ID
  1779. * @param int $user
  1780. * @param string $message
  1781. * @return void
  1782. */
  1783. public static function updateChat($ID, $user, $message) {
  1784. $out='';
  1785.  
  1786. if(!isset($_SESSION['filters'])) {
  1787. $_SESSION['filters']=self::getFilters();
  1788. }
  1789.  
  1790. if(!empty($_SESSION['messages'][$ID][$user]) && !self::isIgnored($user)) {
  1791. foreach($_SESSION['messages'][$ID][$user] as $key=>$chat) {
  1792. $GLOBALS['chat']=$chat;
  1793. $GLOBALS['chat']['author']=$user;
  1794.  
  1795. ob_start();
  1796. get_template_part('content', 'chat');
  1797. $out.=ob_get_contents();
  1798. ob_end_clean();
  1799.  
  1800. unset($_SESSION['messages'][$ID][$user][$key]);
  1801. }
  1802. }
  1803.  
  1804. if(!empty($message)) {
  1805. $message=trim(preg_replace($_SESSION['filters'], '', sanitize_text_field($message)));
  1806. if(!empty($message)) {
  1807. $chat=array(
  1808. 'time' => current_time('timestamp'),
  1809. 'content' => $message,
  1810. );
  1811.  
  1812. if(isset($_SESSION['messages'][$user][$ID]) && count($_SESSION['messages'][$user][$ID])>2) {
  1813. array_shift($_SESSION['messages'][$user][$ID]);
  1814. }
  1815.  
  1816. $_SESSION['messages'][$user][$ID][]=$chat;
  1817. $GLOBALS['chat']=$chat;
  1818. $GLOBALS['chat']['author']=$ID;
  1819.  
  1820. ob_start();
  1821. get_template_part('content', 'chat');
  1822. $out.=ob_get_contents();
  1823. ob_end_clean();
  1824. }
  1825. }
  1826.  
  1827. echo $out;
  1828. die();
  1829. }
  1830.  
  1831. /**
  1832. * Gets user status
  1833. *
  1834. * @access public
  1835. * @param int $ID
  1836. * @return array
  1837. */
  1838. public static function getStatus($ID) {
  1839. $status['name']=__('Offline', 'lovestory');
  1840. $status['value']='offline';
  1841.  
  1842. if(isset($_SESSION['users'][$ID])) {
  1843. $status['name']=__('Online', 'lovestory');
  1844. $status['value']='online';
  1845. }
  1846.  
  1847. return $status;
  1848. }
  1849.  
  1850. /**
  1851. * Updates user status
  1852. *
  1853. * @access public
  1854. * @param int $ID
  1855. * @return void
  1856. */
  1857. public static function updateStatus($ID) {
  1858. if(isset($_SESSION['messages'][$ID]) && !empty($_SESSION['messages'][$ID])) {
  1859. foreach($_SESSION['messages'][$ID] as $user=>$messages) {
  1860. if(!empty($messages) && !self::isIgnored($user)) {
  1861. $latest=count($messages)-1;
  1862. if(!isset($messages[$latest]['read'])) {
  1863. $_SESSION['messages'][$ID][$user][$latest]['read']=true;
  1864.  
  1865. $name=get_user_meta($user, 'first_name', true);
  1866. if(ThemexCore::checkOption('user_name') || empty($name)) {
  1867. $name=get_user_meta($user, 'nickname', true);
  1868. } else {
  1869. $name=trim($name.' '.get_user_meta($user, 'last_name', true));
  1870. }
  1871.  
  1872. $out=__('New chat message from', 'lovestory');
  1873. $out.=' <a href="'.ThemexCore::getURL('chat', $user).'">'.$name.'</a>';
  1874. ThemexInterface::$messages[]=$out;
  1875. }
  1876. }
  1877. }
  1878.  
  1879. ThemexInterface::renderMessages(true);
  1880. }
  1881.  
  1882. if(!isset($_SESSION['users'][$ID])) {
  1883. $_SESSION['users'][$ID]=time()+120;
  1884. }
  1885.  
  1886. die();
  1887. }
  1888.  
  1889. /**
  1890. * Filters user statuses
  1891. *
  1892. * @access public
  1893. * @return void
  1894. */
  1895. public static function filterStatuses() {
  1896. $limit=time();
  1897. if(isset($_SESSION['users']) && (!isset($_SESSION['time']) || $_SESSION['time']<$limit)) {
  1898. $_SESSION['time']=$limit+150;
  1899. foreach($_SESSION['users'] as $ID=>$time) {
  1900. if($time<$limit) {
  1901. unset($_SESSION['users'][$ID]);
  1902. }
  1903. }
  1904. }
  1905. }
  1906.  
  1907. /**
  1908. * Renders admin profile
  1909. *
  1910. * @access public
  1911. * @param mixed $user
  1912. * @return void
  1913. */
  1914. public static function renderAdminProfile($user) {
  1915. $profile=self::getProfile($user->ID);
  1916. $out='<table class="form-table themex-profile"><tbody>';
  1917.  
  1918. if(current_user_can('edit_users')) {
  1919.  
  1920. //profile image
  1921. $out.='<tr><th><label for="avatar">'.__('Photo', 'lovestory').'</label></th>';
  1922. $out.='<td><div class="themex-image-uploader">';
  1923. $out.=get_avatar($user->ID);
  1924. $out.=ThemexInterface::renderOption(array(
  1925. 'id' => 'avatar',
  1926. 'type' => 'uploader',
  1927. 'value' => '',
  1928. 'wrap' => false,
  1929. ));
  1930. $out.='</div></td></tr>';
  1931. }
  1932.  
  1933. //default fields
  1934. if(!ThemexCore::checkOption('user_gender')) {
  1935. $out.='<tr><th><label for="gender">'.__('Gender', 'lovestory').'</label></th><td>';
  1936. $out.=ThemexInterface::renderOption(array(
  1937. 'id' => 'gender',
  1938. 'type' => 'select',
  1939. 'value' => !empty($profile['gender'])?$profile['gender']:'man',
  1940. 'options' => ThemexCore::$components['genders'],
  1941. 'wrap' => false,
  1942. ));
  1943. $out.='</td></tr>';
  1944.  
  1945. $out.='<tr><th><label for="seeking">'.__('Seeking', 'lovestory').'</label></th><td>';
  1946. $out.=ThemexInterface::renderOption(array(
  1947. 'id' => 'seeking',
  1948. 'type' => 'select',
  1949. 'value' => !empty($profile['seeking'])?$profile['seeking']:'woman',
  1950. 'options' => ThemexCore::$components['genders'],
  1951. 'wrap' => false,
  1952. ));
  1953. $out.='</td></tr>';
  1954. }
  1955.  
  1956. if(!ThemexCore::checkOption('user_age')) {
  1957. $out.='<tr><th><label for="age">'.__('Age', 'lovestory').'</label></th><td>';
  1958. $out.=ThemexInterface::renderOption(array(
  1959. 'id' => 'age',
  1960. 'type' => 'select_age',
  1961. 'value' => $profile['age'],
  1962. 'wrap' => false,
  1963. ));
  1964. $out.='</td></tr>';
  1965. }
  1966.  
  1967. if(!ThemexCore::checkOption('user_location')) {
  1968. $out.='<tr><th><label for="country">'.__('Country', 'lovestory').'</label></th><td>';
  1969. $out.=ThemexInterface::renderOption(array(
  1970. 'id' => 'country',
  1971. 'type' => 'select',
  1972. 'options' => array_merge(array('0' => '&ndash;'), ThemexCore::$components['countries']),
  1973. 'value' => !empty($profile['country'])?$profile['country']:null,
  1974. 'wrap' => false,
  1975. ));
  1976. $out.='</td></tr>';
  1977.  
  1978. $out.='<tr><th><label for="city">'.__('City', 'lovestory').'</label></th><td>';
  1979. $out.='<input type="text" name="city" size="50" value="'.$profile['city'].'" />';
  1980. $out.='</td></tr>';
  1981. }
  1982.  
  1983. //custom fields
  1984. ob_start();
  1985. ThemexForm::renderData('profile', array(
  1986. 'edit' => true,
  1987. 'before_title' => '<tr><th><label>',
  1988. 'after_title' => '</th></label>',
  1989. 'before_content' => '<td>',
  1990. 'after_content' => '</td></tr>',
  1991. ), $profile);
  1992. $out.=ob_get_contents();
  1993. ob_end_clean();
  1994.  
  1995. //profile text
  1996. $out.='<tr><th><label for="description">'.__('Profile Text', 'lovestory').'</label></th><td>';
  1997. ob_start();
  1998. ThemexInterface::renderEditor('description', wpautop($profile['description']));
  1999. $out.=ob_get_contents();
  2000. ob_end_clean();
  2001. $out.='</td></tr>';
  2002.  
  2003. $out.='<input type="hidden" name="update" value="1" />';
  2004.  
  2005. $out.='</tbody></table>';
  2006. echo $out;
  2007. }
  2008.  
  2009. /**
  2010. * Updates admin profile
  2011. *
  2012. * @param mixed $user
  2013. * @access public
  2014. * @return void
  2015. */
  2016. public static function updateAdminProfile($user) {
  2017. global $wpdb;
  2018.  
  2019. //custom fields
  2020. self::updateProfile($user, $_POST);
  2021.  
  2022. if(current_user_can('edit_users')) {
  2023.  
  2024. //profile image
  2025. if(isset($_POST['avatar']) && !empty($_POST['avatar'])) {
  2026. $url=esc_url($_POST['avatar']);
  2027. $avatar=$wpdb->get_var("SELECT ID FROM ".$wpdb->posts." WHERE guid = '".$url."'");
  2028.  
  2029. if(!empty($avatar)) {
  2030. ThemexCore::updateUserMeta($user, 'avatar', $avatar);
  2031. }
  2032. }
  2033. }
  2034. }
  2035.  
  2036. /**
  2037. * Adds admin columns
  2038. *
  2039. * @param array $columns
  2040. * @access public
  2041. * @return array
  2042. */
  2043. function addAdminColumns($columns) {
  2044. $columns['updated']=__('Updated', 'lovestory');
  2045. return $columns;
  2046. }
  2047.  
  2048. /**
  2049. * Renders admin columns
  2050. *
  2051. * @param string $value
  2052. * @param string $column
  2053. * @param int $user
  2054. * @access public
  2055. * @return string
  2056. */
  2057. function renderAdminColumns($value, $column, $user) {
  2058. if($column=='updated') {
  2059. $data=get_userdata($user);
  2060. $registered=date('Y-m-d', strtotime($data->user_registered));
  2061. $updated=ThemexCore::getUserMeta($user, 'updated', $registered);
  2062.  
  2063. return $updated;
  2064. }
  2065.  
  2066. return $value;
  2067. }
  2068.  
  2069. /**
  2070. * Updates admin columns
  2071. *
  2072. * @param array $columns
  2073. * @access public
  2074. * @return array
  2075. */
  2076. function updateAdminColumns($columns) {
  2077. $custom=array(
  2078. 'updated' => 'updated',
  2079. );
  2080.  
  2081. return wp_parse_args($custom, $columns);
  2082. }
  2083.  
  2084. /**
  2085. * Filters admin columns
  2086. *
  2087. * @param mixed $query
  2088. * @access public
  2089. * @return array
  2090. */
  2091. function filterAdminColumns($query) {
  2092. global $wpdb, $pagenow;
  2093.  
  2094. if($pagenow=='users.php') {
  2095. $vars=$query->query_vars;
  2096. if($vars['orderby']=='updated') {
  2097. $order='DESC';
  2098. if($vars['order']=='DESC') {
  2099. $order='ASC';
  2100. }
  2101.  
  2102. $query->query_from.=" LEFT JOIN {$wpdb->usermeta} m1 ON {$wpdb->users}.ID=m1.user_id AND (m1.meta_key='_".THEMEX_PREFIX."updated')";
  2103. $query->query_orderby=" ORDER BY m1.meta_value ".$order;
  2104. }
  2105. }
  2106. }
  2107.  
  2108. /**
  2109. * Renders user toolbar
  2110. *
  2111. * @access public
  2112. * @return bool
  2113. */
  2114. public static function renderToolbar() {
  2115. if(current_user_can('edit_posts') && get_user_option('show_admin_bar_front', get_current_user_id())!='false') {
  2116. return true;
  2117. }
  2118.  
  2119. return false;
  2120. }
  2121.  
  2122. /**
  2123. * Checks profile page
  2124. *
  2125. * @access public
  2126. * @param int $ID
  2127. * @return bool
  2128. */
  2129. public static function isProfile() {
  2130. if(is_user_logged_in() && self::$data['active_user']['ID']==self::$data['user']['ID']) {
  2131. return true;
  2132. }
  2133.  
  2134. return false;
  2135. }
  2136.  
  2137. /**
  2138. * Checks user filter
  2139. *
  2140. * @access public
  2141. * @return bool
  2142. */
  2143. public static function isUserFilter() {
  2144. if(isset($_GET['s']) && empty($_GET['s'])) {
  2145. return true;
  2146. }
  2147.  
  2148. return false;
  2149. }
  2150. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement