Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [PHP]Przerobienie skryptu, Dodanie funkcji do skryptu
toker123
post 27.09.2020, 03:43:29
Post #1





Grupa: Zarejestrowani
Postów: 1
Pomógł: 0
Dołączył: 27.09.2020

Ostrzeżenie: (0%)
-----


Witam, na wstępnie napiszę że w php jestem abslutnie zielony... no ale na potrzeby swojego projektu potrzebowałbym przerobić 1 skrypt. Tak by dodać do niego funkcje, która opózni przyznawanie nagrody o 15 sec i przyzna ją dopiero pod warunkiem wywołania js patha.

  1. <?php
  2. if ( ! defined( 'myCRED_VERSION' ) ) exit;
  3.  
  4. /**
  5.  * Hooks for Clicking on Links
  6.  * @since 1.1
  7.  * @version 1.3
  8.  */
  9. if ( ! class_exists( 'myCRED_Hook_Click_Links' ) ) :
  10. class myCRED_Hook_Click_Links extends myCRED_Hook {
  11.  
  12. /**
  13. * Construct
  14. */
  15. function __construct( $hook_prefs, $type = MYCRED_DEFAULT_TYPE_KEY ) {
  16.  
  17. parent::__construct( array(
  18. 'id' => 'link_click',
  19. 'defaults' => array(
  20. 'limit_by' => 'none',
  21. 'creds' => 1,
  22. 'log' => '%plural% for clicking on link to: %url%'
  23. )
  24. ), $hook_prefs, $type );
  25.  
  26. }
  27.  
  28. /**
  29. * Run
  30. * @since 1.1
  31. * @version 1.0
  32. */
  33. public function run() {
  34.  
  35. if ( ! is_user_logged_in() ) return;
  36.  
  37. add_action( 'mycred_register_assets', array( $this, 'register_script' ) );
  38. add_action( 'mycred_front_enqueue_footer', array( $this, 'enqueue_footer' ) );
  39. add_filter( 'mycred_parse_tags_link', array( $this, 'parse_custom_tags' ), 10, 2 );
  40.  
  41. if ( isset( $_POST['action'] ) && $_POST['action'] == 'mycred-click-points' && isset( $_POST['token'] ) && wp_verify_nonce( $_POST['token'], 'mycred-link-points' ) )
  42. $this->ajax_call_link_points();
  43.  
  44. }
  45.  
  46. /**
  47. * Customize Limit Options
  48. * @since 1.1
  49. * @version 1.0
  50. */
  51. public function custom_limit() {
  52.  
  53. return array(
  54. 'none' => __( 'No limit', 'mycred' ),
  55. 'url' => __( 'Once for each unique URL', 'mycred' ),
  56. 'id' => __( 'Once for each unique link id', 'mycred' )
  57. );
  58.  
  59. }
  60.  
  61. /**
  62. * Parse Custom Tags in Log
  63. * @since 1.1
  64. * @version 1.1.1
  65. */
  66. public function parse_custom_tags( $content, $log_entry ) {
  67.  
  68. $data = maybe_unserialize( $log_entry->data );
  69. $content = str_replace( '%url%', $data['link_url'], $content );
  70. $content = str_replace( '%id%', $data['link_id'], $content );
  71.  
  72. if ( isset( $data['link_title'] ) )
  73. $content = str_replace( '%title%', $data['link_title'], $content );
  74.  
  75. return $content;
  76.  
  77. }
  78.  
  79. /**
  80. * Register Script
  81. * @since 1.1
  82. * @version 1.0
  83. */
  84. public function register_script() {
  85.  
  86. global $mycred_link_points;
  87.  
  88. $mycred_link_points = false;
  89.  
  90. wp_register_script(
  91. 'mycred-link-points',
  92. plugins_url( 'assets/js/links.js', myCRED_THIS ),
  93. array( 'jquery' ),
  94. myCRED_VERSION . '.1',
  95. true
  96. );
  97.  
  98. }
  99.  
  100. /**
  101. * WP Fotter
  102. * @since 1.1
  103. * @version 1.1
  104. */
  105. public function enqueue_footer() {
  106.  
  107. global $mycred_link_points;
  108.  
  109. if ( $mycred_link_points === true ) {
  110.  
  111. global $post;
  112.  
  113. wp_localize_script(
  114. 'mycred-link-points',
  115. 'myCREDlink',
  116. 'ajaxurl' => esc_url( isset( $post->ID ) ? mycred_get_permalink( $post->ID ) : home_url( '/' ) ),
  117. 'token' => wp_create_nonce( 'mycred-link-points' )
  118. )
  119. );
  120. wp_enqueue_script( 'mycred-link-points' );
  121.  
  122. }
  123.  
  124. }
  125.  
  126. /**
  127. * Custom Has Entry Check
  128. * @since 1.1
  129. * @version 1.1.2
  130. */
  131. public function has_entry( $action = '', $reference = '', $user_id = '', $data = '', $type = '' ) {
  132.  
  133. global $wpdb, $mycred_log_table;
  134.  
  135. if ( $this->prefs['limit_by'] == 'url' ) {
  136. $reference = urldecode( $reference );
  137. $string = '%s:8:"link_url";s:' . strlen( $reference ) . ':"' . $reference . '";%';
  138. }
  139. elseif ( $this->prefs['limit_by'] == 'id' ) {
  140. $string = '%s:7:"link_id";s:' . strlen( $reference ) . ':"' . $reference . '";%';
  141. }
  142. else return false;
  143.  
  144. $sql = "SELECT id FROM {$mycred_log_table} WHERE ref = %s AND user_id = %d AND data LIKE %s AND ctype = %s;";
  145. $wpdb->get_results( $wpdb->prepare( $sql, $action, $user_id, $string, $this->mycred_type ) );
  146. if ( $wpdb->num_rows > 0 ) return true;
  147.  
  148. return false;
  149.  
  150. }
  151.  
  152. /**
  153. * AJAX Call Handler
  154. * @since 1.1
  155. * @version 1.5
  156. */
  157. public function ajax_call_link_points() {
  158.  
  159. // We must be logged in
  160. if ( ! is_user_logged_in() ) return;
  161.  
  162. // Make sure we only handle our own point type
  163. if ( ! isset( $_POST['ctype'] ) || $_POST['ctype'] != $this->mycred_type || ! isset( $_POST['url'] ) ) return;
  164.  
  165. // Security
  166. check_ajax_referer( 'mycred-link-points', 'token' );
  167.  
  168. // Current User
  169. $user_id = get_current_user_id();
  170.  
  171. if ( mycred_force_singular_session( $user_id, 'mycred-last-linkclick' ) )
  172. wp_send_json( 101 );
  173.  
  174. // Check if user should be excluded
  175. if ( $this->core->exclude_user( $user_id ) ) wp_send_json( 200 );
  176.  
  177. // Token
  178. if ( ! isset( $_POST['key'] ) ) wp_send_json( 300 );
  179. $token = mycred_verify_token( $_POST['key'], 4 );
  180. if ( $token === false ) wp_send_json( 305 );
  181.  
  182. list ( $amount, $point_type, $id, $url ) = $token;
  183. if ( $amount == '' || $point_type == '' || $id == '' || $url == '' ) wp_send_json( 310 );
  184.  
  185. // Make sure the token is not abused
  186. if ( $url != urlencode( $_POST['url'] ) ) wp_send_json( 315 );
  187.  
  188. // Bail now if this was not intenteded for this type
  189. if ( $point_type != $this->mycred_type ) return;
  190.  
  191. // Amount
  192. if ( $amount == 0 )
  193. $amount = $this->prefs['creds'];
  194. else
  195. $amount = $this->core->number( $amount );
  196.  
  197. if ( $amount == 0 || $amount == $this->core->zero() ) wp_send_json( 400 );
  198.  
  199. $data = array(
  200. 'ref_type' => 'link',
  201. 'link_url' => esc_url_raw( $_POST['url'] ),
  202. 'link_id' => $id,
  203. 'link_title' => ( isset( $_POST['etitle'] ) ) ? sanitize_text_field( $_POST['etitle'] ) : ''
  204. );
  205.  
  206. // Limits
  207. if ( $this->prefs['limit_by'] == 'url' ) {
  208. if ( $this->has_clicked( $user_id, 'link_url', $data['link_url'] ) ) wp_send_json( 600 );
  209. }
  210. elseif ( $this->prefs['limit_by'] == 'id' ) {
  211. if ( $this->has_clicked( $user_id, 'link_id', $data['link_id'] ) ) wp_send_json( 700 );
  212. }
  213.  
  214. // Execute
  215. $this->core->add_creds(
  216. 'link_click',
  217. $user_id,
  218. $amount,
  219. $this->prefs['log'],
  220. '',
  221. $data,
  222. $point_type
  223. );
  224.  
  225. // Report the good news
  226. wp_send_json( 'done' );
  227.  
  228. }
  229.  
  230. /**
  231. * Has Clicked
  232. * Checks if a user has received points for a link based on either
  233. * an ID or URL.
  234. * @since 1.3.3.1
  235. * @version 1.0.1
  236. */
  237. public function has_clicked( $user_id = NULL, $by = '', $check = '' ) {
  238.  
  239. global $wpdb, $mycred_log_table;
  240.  
  241. $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 ) );
  242. if ( count( $rows ) == 0 ) return false;
  243.  
  244. $reply = false;
  245. foreach ( $rows as $row ) {
  246.  
  247. $data = maybe_unserialize( $row->data );
  248. if ( ! is_array( $data ) || ! isset( $data[ $by ] ) ) continue;
  249.  
  250. if ( $data[ $by ] == $check ) {
  251. $reply = true;
  252. break;
  253. }
  254.  
  255. }
  256.  
  257. return $reply;
  258.  
  259. }
  260.  
  261. /**
  262. * Preference for Link Click Hook
  263. * @since 1.1
  264. * @version 1.1
  265. */
  266. public function preferences() {
  267.  
  268. $prefs = $this->prefs;
  269.  
  270. ?>
  271. <div class="hook-instance">
  272. <div class="row">
  273. <div class="col-lg-4 col-md-4 col-sm-12 col-xs-12">
  274. <div class="form-group">
  275. <label for="<?php echo $this->field_id( 'creds' ); ?>"><?php echo $this->core->plural(); ?></label>
  276. <input type="text" name="<?php echo $this->field_name( 'creds' ); ?>" id="<?php echo $this->field_id( 'creds' ); ?>" value="<?php echo $this->core->number( $prefs['creds'] ); ?>" class="form-control" />
  277. </div>
  278. </div>
  279. <div class="col-lg-8 col-md-8 col-sm-12 col-xs-12">
  280. <div class="form-group">
  281. <label for="<?php echo $this->field_id( 'log' ); ?>"><?php _e( 'Log Template', 'mycred' ); ?></label>
  282. <input type="text" name="<?php echo $this->field_name( 'log' ); ?>" id="<?php echo $this->field_id( 'log' ); ?>" placeholder="<?php _e( 'required', 'mycred' ); ?>" value="<?php echo esc_attr( $prefs['log'] ); ?>" class="form-control" />
  283. <span class="description"><?php echo $this->available_template_tags( array( 'general', 'user' ), '%url%, %title% or %id%' ); ?></span>
  284. </div>
  285. </div>
  286. </div>
  287. <div class="row">
  288. <div class="col-lg-6 col-md-6 col-sm-12 col-xs-12">
  289. <div class="form-group">
  290. <label for=""><?php _e( 'Limits', 'mycred' ); ?></label>
  291. <?php
  292.  
  293. add_filter( 'mycred_hook_impose_limits', array( $this, 'custom_limit' ) );
  294. $this->impose_limits_dropdown( 'limit_by', false );
  295.  
  296. ?>
  297. </div>
  298. </div>
  299. <div class="col-lg-6 col-md-6 col-sm-12 col-xs-12">
  300. <div class="form-group">
  301. <label><?php _e( 'Available Shortcode', 'mycred' ); ?></label>
  302. <p class="form-control-static"><a href="http://codex.mycred.me/shortcodes/mycred_link/" target="_blank">[mycred_link]</a></p>
  303. </div>
  304. </div>
  305. </div>
  306. </div>
  307. <?php
  308.  
  309. }
  310.  
  311. }
  312. 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ć.
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Wersja Lo-Fi Aktualny czas: 29.03.2024 - 00:21