<?php /** * Hooks for Clicking on Links * @since 1.1 * @version 1.3 */ if ( ! class_exists( 'myCRED_Hook_Click_Links' ) ) : class myCRED_Hook_Click_Links extends myCRED_Hook { /** * Construct */ function __construct( $hook_prefs, $type = MYCRED_DEFAULT_TYPE_KEY ) { 'id' => 'link_click', 'limit_by' => 'none', 'creds' => 1, 'log' => '%plural% for clicking on link to: %url%' ) ), $hook_prefs, $type ); } /** * Run * @since 1.1 * @version 1.0 */ public function run() { if ( ! is_user_logged_in() ) return; $this->ajax_call_link_points(); } /** * Customize Limit Options * @since 1.1 * @version 1.0 */ public function custom_limit() { 'none' => __( 'No limit', 'mycred' ), 'url' => __( 'Once for each unique URL', 'mycred' ), 'id' => __( 'Once for each unique link id', 'mycred' ) ); } /** * Parse Custom Tags in Log * @since 1.1 * @version 1.1.1 */ public function parse_custom_tags( $content, $log_entry ) { $data = maybe_unserialize( $log_entry->data ); return $content; } /** * Register Script * @since 1.1 * @version 1.0 */ public function register_script() { $mycred_link_points = false; wp_register_script( 'mycred-link-points', plugins_url( 'assets/js/links.js', myCRED_THIS ), myCRED_VERSION . '.1', true ); } /** * WP Fotter * @since 1.1 * @version 1.1 */ public function enqueue_footer() { if ( $mycred_link_points === true ) { wp_localize_script( 'mycred-link-points', 'myCREDlink', 'token' => wp_create_nonce( 'mycred-link-points' ) ) ); wp_enqueue_script( 'mycred-link-points' ); } } /** * Custom Has Entry Check * @since 1.1 * @version 1.1.2 */ public function has_entry( $action = '', $reference = '', $user_id = '', $data = '', $type = '' ) { if ( $this->prefs['limit_by'] == 'url' ) { } elseif ( $this->prefs['limit_by'] == 'id' ) { } else return false; $sql = "SELECT id FROM {$mycred_log_table} WHERE ref = %s AND user_id = %d AND data LIKE %s AND ctype = %s;"; $wpdb->get_results( $wpdb->prepare( $sql, $action, $user_id, $string, $this->mycred_type ) ); if ( $wpdb->num_rows > 0 ) return true; return false; } /** * AJAX Call Handler * @since 1.1 * @version 1.5 */ public function ajax_call_link_points() { // We must be logged in if ( ! is_user_logged_in() ) return; // Make sure we only handle our own point type // Security check_ajax_referer( 'mycred-link-points', 'token' ); // Current User $user_id = get_current_user_id(); if ( mycred_force_singular_session( $user_id, 'mycred-last-linkclick' ) ) wp_send_json( 101 ); // Check if user should be excluded if ( $this->core->exclude_user( $user_id ) ) wp_send_json( 200 ); // Token $token = mycred_verify_token( $_POST['key'], 4 ); if ( $token === false ) wp_send_json( 305 ); list ( $amount, $point_type, $id, $url ) = $token; if ( $amount == '' || $point_type == '' || $id == '' || $url == '' ) wp_send_json( 310 ); // Make sure the token is not abused // Bail now if this was not intenteded for this type if ( $point_type != $this->mycred_type ) return; // Amount if ( $amount == 0 ) $amount = $this->prefs['creds']; else $amount = $this->core->number( $amount ); if ( $amount == 0 || $amount == $this->core->zero() ) wp_send_json( 400 ); 'ref_type' => 'link', 'link_url' => esc_url_raw( $_POST['url'] ), 'link_id' => $id, ); // Limits if ( $this->prefs['limit_by'] == 'url' ) { if ( $this->has_clicked( $user_id, 'link_url', $data['link_url'] ) ) wp_send_json( 600 ); } elseif ( $this->prefs['limit_by'] == 'id' ) { if ( $this->has_clicked( $user_id, 'link_id', $data['link_id'] ) ) wp_send_json( 700 ); } // Execute $this->core->add_creds( 'link_click', $user_id, $amount, $this->prefs['log'], '', $data, $point_type ); // Report the good news wp_send_json( 'done' ); } /** * Has Clicked * Checks if a user has received points for a link based on either * an ID or URL. * @since 1.3.3.1 * @version 1.0.1 */ public function has_clicked( $user_id = NULL, $by = '', $check = '' ) { $rows = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$mycred_log_table} WHERE ref = %s AND user_id = %d AND ctype = %s", 'link_click', $user_id, $this->mycred_type ) ); $reply = false; foreach ( $rows as $row ) { $data = maybe_unserialize( $row->data ); if ( $data[ $by ] == $check ) { $reply = true; break; } } return $reply; } /** * Preference for Link Click Hook * @since 1.1 * @version 1.1 */ public function preferences() { $prefs = $this->prefs; ?> <div class="hook-instance"> <div class="row"> <div class="col-lg-4 col-md-4 col-sm-12 col-xs-12"> <div class="form-group"> </div> </div> <div class="col-lg-8 col-md-8 col-sm-12 col-xs-12"> <div class="form-group"> <label for="<?php echo $this->field_id( 'log' ); ?>"><?php _e( 'Log Template', 'mycred' ); ?></label> </div> </div> </div> <div class="row"> <div class="col-lg-6 col-md-6 col-sm-12 col-xs-12"> <div class="form-group"> <label for=""><?php _e( 'Limits', 'mycred' ); ?></label> <?php $this->impose_limits_dropdown( 'limit_by', false ); ?> </div> </div> <div class="col-lg-6 col-md-6 col-sm-12 col-xs-12"> <div class="form-group"> <label><?php _e( 'Available Shortcode', 'mycred' ); ?></label> <p class="form-control-static"><a href="http://codex.mycred.me/shortcodes/mycred_link/" target="_blank">[mycred_link]</a></p> </div> </div> </div> </div> <?php } } endif;
Js path: document.querySelector("#fg-root > div.fg-click2play > div.fg-click2play-stage > div.fg-gameDetails > div.btn-play")
Nie liczę na gotowy skrypt w odpowieni, no ale na rady jak mam się do tego zabrać.