/** * myCRED Finished * @since 1.6 * @version 1.0 */ public function mycred_finished($reply, $request, $mycred) { if ($reply === false || $this->notifications['template'] == '') { return $reply; } // Parse template $template = str_replace('%entry%', $request['entry'], $this->notifications['template']); $template = str_replace('%amount%', $request['amount'], $template); // Attempt to parse the template tags now that we have the entire request. // This way we just need to display it and we are done. $template = $mycred->template_tags_amount($template, $request['amount']); $template = $mycred->parse_template_tags($template, $this->request_to_entry($request)); // Let others play $template = apply_filters('mycred_notifications_note', $template, $request, $mycred); // If template is not empty, add it now. if (strlen($template) > 0) { mycred_add_new_notice(array('user_id' => $request['user_id'], 'message' => $template), $this->notifications['life']); } return $reply; }
/** * AJAX Call Handler * @since 1.2 * @version 1.2.1 */ public function ajax_call_video_points() { // We must be logged in if (!is_user_logged_in()) { die; } // Security check_ajax_referer('mycred-video-points', 'token'); // We are only interested in handling our own point type // We can not die here since then the hook will not fire for the correct point type. if (!isset($_POST['type']) || $this->mycred_type != sanitize_key($_POST['type'])) { return; } // Get user id $user_id = get_current_user_id(); // Decode the key giving us the video shortcode setup // This will prevent users from manipulating the shortcode output $setup = mycred_verify_token($_POST['setup'], 5); if ($setup === false) { die(0); } list($source, $video_id, $amount, $logic, $interval) = $setup; // Required if (empty($source) || empty($video_id)) { die; } // Prep $amount = $this->core->number($amount); $interval = abs($interval / 1000); // Get playback details $actions = sanitize_text_field($_POST['video_a']); $seconds = abs($_POST['video_b']); $duration = abs($_POST['video_c']); $state = absint($_POST['video_d']); // Apply Leniency $leniency = $duration * ($this->prefs['leniency'] / 100); $leniency = floor($leniency); $watched = $seconds + $leniency; $status = 'silence'; switch ($logic) { // Award points when video starts case 'play': if ($state == 1) { if (!$this->has_entry('watching_video', '', $user_id, $video_id, $this->mycred_type)) { // Execute $this->core->add_creds('watching_video', $user_id, $amount, $this->prefs['log'], 0, $video_id, $this->mycred_type); $status = 'added'; } else { $status = 'max'; } } break; // Award points when video is viewed in full // Award points when video is viewed in full case 'full': // Check for skipping or if we watched more (with leniency) then the video length if (!preg_match('/22/', $actions, $matches) || $watched >= $duration) { if ($state == 0) { if (!$this->has_entry('watching_video', '', $user_id, $video_id, $this->mycred_type)) { // Execute $this->core->add_creds('watching_video', $user_id, $amount, $this->prefs['log'], 0, $video_id, $this->mycred_type); $status = 'added'; } else { $status = 'max'; } } } break; // Award points in intervals // Award points in intervals case 'interval': // The maximum points a video can earn you $num_intervals = floor($duration / $interval); $max = abs($num_intervals * $amount); $users_log = $this->get_users_video_log($video_id, $user_id); // Film is playing and we just started if ($state == 1 && $users_log === NULL) { // Add points without using mycred_add to prevent // notifications from being sent as this amount will change. $this->core->update_users_balance($user_id, $amount); $this->core->add_to_log('watching_video', $user_id, $amount, $this->prefs['log'], 0, $video_id, $this->mycred_type); $status = 'added'; } elseif ($state == 1 && isset($users_log->creds) && $users_log->creds + $amount <= $max) { $this->update_creds($users_log->id, $user_id, $users_log->creds + $amount); $this->core->update_users_balance($user_id, $amount); $amount = $users_log->creds + $amount; $status = 'added'; } elseif ($state == 0 && isset($users_log->creds) && $users_log->creds + $amount <= $max) { $this->update_creds($users_log->id, $user_id, $users_log->creds + $amount); $this->core->update_users_balance($user_id, $amount); $amount = $users_log->creds + $amount; $status = 'max'; // If enabled, add notification if (function_exists('mycred_add_new_notice')) { if ($amount < 0) { $color = '<'; } else { $color = '>'; } $message = str_replace('%amount%', $amount, $this->prefs['template']); if (!empty($message)) { mycred_add_new_notice(array('user_id' => $user_id, 'message' => $message, 'color' => $color)); } } } break; } wp_send_json(array('status' => $status, 'video_id' => $video_id, 'amount' => $amount, 'duration' => $duration, 'seconds' => $seconds, 'watched' => $watched, 'actions' => $actions, 'state' => $state, 'logic' => $logic, 'interval' => $interval)); }
/** * myCRED Add * @since 1.2.3 * @version 1.2 */ public function mycred_add($reply, $request) { if ($reply === false) { return $reply; } $mycred = mycred($request['type']); $template = $this->notifications['template']; $template = str_replace('%entry%', $request['entry'], $template); $template = str_replace('%amount%', $request['amount'], $template); $template = $mycred->template_tags_amount($template, $request['amount']); $template = $mycred->parse_template_tags($template, (object) $request); $template = apply_filters('mycred_notifications_note', $template, $request, $mycred); if (!empty($template)) { mycred_add_new_notice(array('user_id' => $request['user_id'], 'message' => $template), $this->notifications['life']); } return $reply; }