Advertisement
arie_cristianD

class.jnews-initial-counter

Jan 22nd, 2024
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.54 KB | None | 0 0
  1. <?php
  2. /**
  3.  * @author : Jegtheme
  4.  */
  5.  
  6. if ( ! defined( 'ABSPATH' ) ) {
  7.     exit;
  8. }
  9.  
  10. /**
  11.  * Class JNews Initial Counter
  12.  */
  13. class JNews_Initial_Counter {
  14.  
  15.     /**
  16.      * @var JNews_Initial_Counter
  17.      */
  18.     private static $instance;
  19.  
  20.     /**
  21.      * @return JNews_Initial_Counter
  22.      */
  23.     public static function getInstance() {
  24.         if ( null === static::$instance ) {
  25.             static::$instance = new static();
  26.         }
  27.         return static::$instance;
  28.     }
  29.  
  30.  
  31.     /**
  32.      * Total fake view
  33.      *
  34.      * @param null    $total
  35.      * @param $post_id
  36.      * @param string  $range
  37.      * @return mixed|null
  38.      */
  39.     public function get_total_fake_view( $total = null, $post_id = null, $range = 'all' ) {
  40.         if ( null !== $total ) {
  41.             $total = str_replace( ',', '', $total );
  42.             $total = str_replace( '.', '', $total );
  43.             $total = str_replace( '٬', '', $total );
  44.             $total = intval( $total );
  45.         }
  46.  
  47.         if ( ! $total ) {
  48.             $total = apply_filters( 'jnews_get_total_view', 0, $post_id, $range );
  49.         }
  50.  
  51.         $view_initial_value = apply_filters( 'jnews_view_initial_counter', jnews_get_option( 'single_view_initial_value', 0 ), $post_id );
  52.         $total              = (int) $total + (int) $view_initial_value;
  53.  
  54.         return $total;
  55.     }
  56.  
  57.  
  58.     /**
  59.      * Fake share
  60.      *
  61.      * @param $post_id
  62.      * @return float
  63.      */
  64.     public function fake_share( $post_id ) {
  65.         $percentage = (int) jnews_get_option( 'single_social_share_view_percentage', 0 );
  66.         $view       = $this->get_total_fake_view( null, $post_id );
  67.  
  68.         return (int) round( $view * $percentage / 100 );
  69.     }
  70.  
  71.     /**
  72.      * Total fake share
  73.      *
  74.      * @param $total
  75.      * @param $post_id
  76.      * @return mixed
  77.      */
  78.     public function get_total_fake_share( $total, $post_id ) {
  79.         $fake_share = apply_filters( 'jnews_share_initial_counter', $this->fake_share( $post_id ), $post_id );
  80.         $totalshare = (int) $total + (int) $fake_share;
  81.         return $totalshare;
  82.     }
  83.  
  84.     /**
  85.      * @param $social
  86.      * @return int|mixed
  87.      */
  88.     public function social_fake_percentage( $social ) {
  89.         $percentage = 0;
  90.  
  91.         switch ( $social ) {
  92.             case 'facebook':
  93.                 $percentage = apply_filters( 'jnews_share_fake_percentage', 40, $social );
  94.                 break;
  95.             case 'twitter':
  96.                 $percentage = apply_filters( 'jnews_share_fake_percentage', 25, $social );
  97.                 break;
  98.             case 'pinterest':
  99.                 $percentage = apply_filters( 'jnews_share_fake_percentage', 9, $social );
  100.                 break;
  101.             case 'linkedin':
  102.                 $percentage = apply_filters( 'jnews_share_fake_percentage', 7, $social );
  103.                 break;
  104.             case 'vk':
  105.                 $percentage = apply_filters( 'jnews_share_fake_percentage', 5, $social );
  106.                 break;
  107.             case 'buffer':
  108.                 $percentage = apply_filters( 'jnews_share_fake_percentage', 3, $social );
  109.                 break;
  110.             case 'stumbleupon':
  111.                 $percentage = apply_filters( 'jnews_share_fake_percentage', 1, $social );
  112.                 break;
  113.         }
  114.  
  115.         return $percentage;
  116.     }
  117.  
  118.     /**
  119.      * Social Share
  120.      *
  121.      * @param $totalshare
  122.      * @param $post_id
  123.      * @param string     $social
  124.      * @return mixed
  125.      */
  126.     public function social_share( $totalshare, $post_id, $social = 'facebook' ) {
  127.         $socialshare = round( $this->fake_share( $post_id ) * $this->social_fake_percentage( $social ) / 100 );
  128.         $totalshare  = (int) $totalshare + (int) $socialshare;
  129.         return $totalshare;
  130.     }
  131.  
  132.     /**
  133.      * Fake like
  134.      *
  135.      * @param $post_id
  136.      * @param string  $type
  137.      * @return int
  138.      */
  139.     public function fake_like( $post_id, $type = 'like' ) {
  140.         $percentage = (int) jnews_get_option( 'single_like_view_percentage', 0 );
  141.  
  142.         $max_dislike     = apply_filters( 'jnews_max_dislike', 8 );
  143.         $title_length    = str_word_count( get_the_title( $post_id ) );
  144.         $like_percentage = 100 - ( $title_length % $max_dislike );
  145.         $like_percentage = min( $like_percentage, 99 );
  146.  
  147.         $real_view  = $total = apply_filters( 'jnews_get_total_view', 0, $post_id, 'all' );
  148.         $total_view = $this->get_total_fake_view( $real_view, $post_id );
  149.  
  150.         $fake_like    = round( $total_view * $percentage * $like_percentage / 10000 );
  151.         $fake_dislike = round( $total_view * $percentage / 100 ) - $fake_like;
  152.  
  153.         if ( $type === 'like' ) {
  154.             return (int) $fake_like;
  155.         } else {
  156.             return $fake_dislike;
  157.         }
  158.     }
  159.  
  160.     /**
  161.      * Get total like with fake like
  162.      *
  163.      * @param $total
  164.      * @param $post_id
  165.      * @return int
  166.      */
  167.     public function total_like( $total, $post_id ) {
  168.         $like = (int) $total + (int) $this->fake_like( $post_id );
  169.         return $like;
  170.     }
  171.  
  172.     /**
  173.      * Get total dislike
  174.      *
  175.      * @param $total
  176.      * @param $post_id
  177.      * @return int
  178.      */
  179.     public function total_dislike( $total, $post_id ) {
  180.         $dislike = (int) $total + (int) $this->fake_like( $post_id, 'dislike' );
  181.         return $dislike;
  182.     }
  183. }
  184.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement