/**
  * Validates lesson question
  *
  * @access public
  * @param array $comment
  * @return array
  */
 public static function validateQuestion($comment)
 {
     if (get_post_type() == 'lesson') {
         if ($comment['comment_parent'] == 0 && (!isset($_POST['title']) || empty($_POST['title']))) {
             wp_die('<strong>' . __('ERROR', 'academy') . '</strong>: ' . __('please type a question.', 'academy'));
         }
         $message = ThemexCore::getOption('email_question');
         if ($comment['comment_parent'] !== 0 && !empty($message)) {
             $question = get_comment($comment['comment_parent'], ARRAY_A);
             $replies = get_comments(array('parent' => $comment['comment_parent']));
             $emails = wp_list_pluck($replies, 'comment_author_email');
             if (!empty($question)) {
                 $emails[] = $question['comment_author_email'];
             }
             $emails = array_unique(array_filter($emails));
             foreach ($emails as $email) {
                 if ($email != $comment['comment_author_email']) {
                     $data = get_user_by('email', $email);
                     if ($data !== false) {
                         $keywords = array('username' => $data->user_login, 'title' => get_comment_meta($comment['comment_parent'], 'title', true), 'link' => get_comment_link($comment['comment_parent']));
                         themex_mail($emails, __('Question Answered', 'academy'), themex_keywords($message, $keywords));
                     }
                 }
             }
         }
     }
     return $comment;
 }
 /**
  * Gets course certificate
  *
  * @access public
  * @param int $ID
  * @param int $user
  * @return array
  */
 public static function getCertificate($ID, $user)
 {
     $certificate['content'] = ThemexCore::getPostMeta($ID, 'course_certificate_content');
     $certificate['progress'] = self::getProgress($ID, $user);
     if (!empty($certificate['content']) && $certificate['progress'] == 100) {
         $username = trim(get_user_meta($user, 'first_name', true) . ' ' . get_user_meta($user, 'last_name', true));
         $title = get_the_title($ID);
         $grade = self::getGrade($ID, $user) . '%';
         $number = themex_encode($ID, $user);
         $time = ThemexCore::getUserRelations($user, $ID, 'certificate', true);
         $date = date_i18n(get_option('date_format'), $time);
         if ($time == 0) {
             $date = date_i18n(get_option('date_format'));
         }
         $keywords = array('username' => $username, 'title' => $title, 'grade' => $grade, 'number' => $number, 'date' => $date);
         $certificate['user'] = $user;
         $certificate['background'] = ThemexCore::getPostMeta($ID, 'course_certificate_background');
         $certificate['content'] = wpautop(themex_keywords($certificate['content'], $keywords));
     }
     return $certificate;
 }
Beispiel #3
0
 /**
  * Logins Facebook user
  *
  * @access public
  * @return void
  */
 public static function loginUser()
 {
     if (isset($_GET['facebook_login']) && !is_user_logged_in() && isset($_COOKIE['fbsr_' . ThemexCore::getOption('facebook_id')])) {
         $cookie = self::decodeCookie();
         if (isset($cookie['code'])) {
             $profile = self::getProfile($cookie['user_id'], array('fields' => 'first_name,last_name,email', 'code' => $cookie['code'], 'sslverify' => 0));
             if (isset($profile['email'])) {
                 $user = get_user_by('email', sanitize_email($profile['email']));
                 if ($user !== false) {
                     $ID = $user->ID;
                     wp_set_auth_cookie($user->ID, true);
                 } else {
                     if (isset($profile['first_name'])) {
                         $profile['username'] = $profile['first_name'];
                     } else {
                         if (isset($profile['last_name'])) {
                             $profile['username'] = $profile['last_name'];
                         }
                     }
                     $profile['username'] = sanitize_user($profile['username']);
                     $profile['password'] = wp_generate_password(8);
                     while (username_exists($profile['username'])) {
                         $profile['username'] .= rand(0, 9);
                     }
                     $ID = wp_create_user($profile['username'], $profile['password'], $profile['email']);
                     if (!is_wp_error($ID)) {
                         wp_new_user_notification($ID);
                         add_user_meta($ID, 'facebook_id', $profile['id'], true);
                         self::updateImage($profile['id'], $ID);
                         if (isset($profile['first_name'])) {
                             update_user_meta($ID, 'first_name', $profile['first_name']);
                         }
                         if (isset($profile['last_name'])) {
                             update_user_meta($ID, 'last_name', $profile['last_name']);
                         }
                         $subject = __('Registration Complete', 'academy');
                         $message = ThemexCore::getOption('email_registration', 'Hi, %username%! Welcome to ' . get_bloginfo('name') . '. ');
                         $keywords = array('username' => $profile['username'], 'password' => $profile['password'], 'link' => home_url());
                         wp_set_auth_cookie($ID, true);
                         themex_mail($profile['email'], $subject, themex_keywords($message, $keywords));
                     } else {
                         self::logoutUser();
                     }
                 }
                 //redirect here
                 if (isset($_GET['user_redirect']) && !empty($_GET['user_redirect'])) {
                     $redirect = ThemexCore::getURL('redirect', intval($_GET['user_redirect']));
                 } else {
                     $redirect = get_author_posts_url($ID);
                 }
                 wp_redirect($redirect);
                 exit;
             }
         }
         wp_redirect(SITE_URL);
         exit;
     }
 }
 /**
  * Resets password
  *
  * @access public
  * @param array $data
  * @return void
  */
 public static function resetPassword($data)
 {
     global $wpdb, $wp_hasher;
     if (email_exists(sanitize_email($data['user_email']))) {
         $user = get_user_by('email', sanitize_email($data['user_email']));
         do_action('lostpassword_post');
         $login = $user->user_login;
         $email = $user->user_email;
         do_action('retrieve_password', $login);
         $allow = apply_filters('allow_password_reset', true, $user->ID);
         if (!$allow || is_wp_error($allow)) {
             ThemexInterface::$messages[] = __('Password recovery not allowed', 'academy');
         } else {
             $key = wp_generate_password(20, false);
             do_action('retrieve_password_key', $login, $key);
             if (empty($wp_hasher)) {
                 require_once ABSPATH . 'wp-includes/class-phpass.php';
                 $wp_hasher = new PasswordHash(8, true);
             }
             $hashed = $wp_hasher->HashPassword($key);
             $wpdb->update($wpdb->users, array('user_activation_key' => $hashed), array('user_login' => $login));
             $link = network_site_url('wp-login.php?action=rp&key=' . $key . '&login='******'login');
             $message = ThemexCore::getOption('email_password', 'Hi, %username%! Click this link to reset your password %link%');
             $keywords = array('username' => $user->user_login, 'link' => $link);
             if (themex_mail($email, __('Password Recovery', 'academy'), themex_keywords($message, $keywords))) {
                 ThemexInterface::$messages[] = __('Password reset link is sent', 'academy');
             } else {
                 ThemexInterface::$messages[] = __('Error sending email', 'academy');
             }
         }
     } else {
         ThemexInterface::$messages[] = __('Invalid email address', 'academy');
     }
     ThemexInterface::renderMessages();
     die;
 }
Beispiel #5
0
 /**
  * Submits user message
  *
  * @access public
  * @param int $ID
  * @param array $data
  * @return void
  */
 public static function submitMessage($ID, $data)
 {
     $user = intval(themex_value('user_id', $data));
     if (!empty($user)) {
         $message = sanitize_text_field(themex_value('message', $data));
         if (empty($message)) {
             ThemexInterface::$messages[] = '"' . __('Message', 'makery') . '" ' . __('field is required', 'makery');
         }
         if (empty(ThemexInterface::$messages)) {
             $subject = __('New Message', 'makery');
             $content = ThemexCore::getOption('email_message', 'Sender: %user%<br />Message: %message%');
             $receiver = get_userdata($user);
             $sender = get_userdata($ID);
             $keywords = array('user' => '<a href="' . get_author_posts_url($sender->ID) . '">' . $sender->user_login . '</a>', 'message' => wpautop($message));
             $content = themex_keywords($content, $keywords);
             themex_mail($receiver->user_email, $subject, $content, $sender->user_email);
             ThemexInterface::$messages[] = __('Message has been successfully sent', 'makery');
             ThemexInterface::renderMessages(true);
         } else {
             ThemexInterface::renderMessages();
         }
     }
     die;
 }
Beispiel #6
0
 /**
  * Adds order
  *
  * @access public
  * @param int $ID
  * @return void
  */
 public static function addOrder($ID)
 {
     $order = wc_get_order($ID);
     $products = $order->get_items();
     //set author
     if (!empty($products)) {
         $product = reset($products);
         $post = get_post($product['product_id']);
         //set affiliate
         $referral = get_current_user_id();
         $affiliate = self::getAffiliate();
         if (!empty($affiliate) && $affiliate != $referral) {
             ThemexCore::updatePostMeta($ID, 'affiliate', $affiliate);
             self::removeAffiliate();
             //send email
             $content = ThemexCore::getOption('email_order_referral');
             if (!empty($content)) {
                 $user = get_userdata($affiliate);
                 if ($user !== false) {
                     $subject = __('New Referral', 'makery');
                     $keywords = array('username' => $user->user_login, 'order' => '<a href="' . ThemexCore::getURL('profile-referrals') . '">' . $order->get_order_number() . '</a>');
                     $content = themex_keywords($content, $keywords);
                     themex_mail($user->user_email, $subject, $content);
                 }
             }
         }
         if (!empty($post)) {
             wp_update_post(array('ID' => $ID, 'post_author' => $post->post_author));
             //send email
             $content = ThemexCore::getOption('email_order_received');
             if (!empty($content)) {
                 $user = get_userdata($post->post_author);
                 $subject = __('New Order', 'makery');
                 $keywords = array('username' => $user->user_login, 'order' => '<a href="' . ThemexCore::getURL('shop-order', $order->id) . '">' . $order->get_order_number() . '</a>');
                 $content = themex_keywords($content, $keywords);
                 themex_mail($user->user_email, $subject, $content);
             }
         }
     }
 }
 /**
  * Submits shop report
  *
  * @access public
  * @param array $data
  * @return void
  */
 public static function submitReport($data)
 {
     $shop = intval(themex_value('shop_id', $data));
     if (!empty($shop)) {
         $reason = sanitize_text_field(themex_value('reason', $data));
         if (empty($reason)) {
             ThemexInterface::$messages[] = '"' . __('Reason', 'makery') . '" ' . __('field is required', 'makery');
         }
         if (empty(ThemexInterface::$messages)) {
             $subject = __('Shop Report', 'makery');
             $content = ThemexCore::getOption('email_shop_report', 'Sender: %user%<br />Shop: %shop%<br />Reason: %reason%');
             $user = get_userdata(get_current_user_id());
             $keywords = array('user' => '<a href="' . get_author_posts_url($user->ID) . '">' . $user->user_login . '</a>', 'shop' => '<a href="' . get_permalink($shop) . '">' . get_the_title($shop) . '</a>', 'reason' => wpautop($reason));
             $content = themex_keywords($content, $keywords);
             themex_mail(get_option('admin_email'), $subject, $content, $user->user_email);
             ThemexInterface::$messages[] = __('Report has been successfully sent', 'makery');
             ThemexInterface::renderMessages(true);
         } else {
             ThemexInterface::renderMessages();
         }
     }
     die;
 }