コード例 #1
0
 function mycred_verify_token($string = '', $length = 1)
 {
     $reply = false;
     $protect = mycred_protect();
     if ($protect !== false) {
         $decoded = $protect->do_decode($string);
         $array = explode(':', $decoded);
         if (count($array) == $length) {
             $reply = $array;
         }
     } else {
         $reply = $string;
     }
     return apply_filters('mycred_verify_token', $reply, $string, $length);
 }
コード例 #2
0
ファイル: mycred.php プロジェクト: songlequang/myclass
 function mycred_reset_key()
 {
     $protect = mycred_protect();
     if ($protect !== false) {
         $protect->reset_key();
     }
 }
コード例 #3
0
ファイル: mycred.php プロジェクト: nfer/mycred
 function mycred_reset_key()
 {
     $protect = mycred_protect();
     $protect->reset_key();
 }
コード例 #4
0
ファイル: mycred-module-hooks.php プロジェクト: nfer/mycred
 /**
  * AJAX Call Handler
  * @since 1.2
  * @version 1.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');
     // 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
     $protect = mycred_protect();
     $setup = mycred_verify_token($_POST['setup'], 5);
     if ($setup === false) {
         die;
     }
     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 = trim($_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'], '', $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'], '', $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'], '', $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));
 }