HEX
Server: Apache/2.4.41 (Ubuntu)
System: Linux sci 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64
User: tpdc (1002)
PHP: 7.4.3-4ubuntu2.29
Disabled: pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
Upload Files
File: /var/www/html/nsci/wp-content/themes/soledad/inc/social-counter/counter-tiktok-api.php
<?php
if ( ! defined( 'ABSPATH' ) ) {
	exit;
}
if ( ! class_exists( 'Penci_Social_Counter_Tiktok_API' ) ):
	class Penci_Social_Counter_Tiktok_API {
		public static function get_count( $data, $cache_period ) {
			if ( empty( $data['name'] ) ) {
				return $data;
			}

			$user_id      = preg_replace( '/\s+/', '', $data['name'] );
			$data['icon'] = penci_icon_by_ver( 'penciicon-tik-tok-1' );

			$cache_key    = 'penci_counter_tiktok' . $user_id;
			$tiktok_count = get_transient( $cache_key );
			$data['url']  = "https://www.tiktok.com/@$user_id";

			if ( ! $tiktok_count ) {

				$count = self::get_tiktok_count( $user_id );

				set_transient( $cache_key, $count, $cache_period );
			} else {
				$count = $tiktok_count;
			}

			if ( $count ) {
				$data['count'] = $count;
			}

			return $data;
		}

		public static function get_tiktok_count( $username ): string {
			$count    = 0;
			$url      = "https://www.tiktok.com/@{$username}";
			$response = wp_remote_get( $url, array(
				'timeout' => 20,
				'user-agent' => 'Mozilla/5.0 (compatible; MSIE 6.0; Windows CE; Trident/3.0)'
			) );
			$pattern  = "/<strong title=\"Followers\" data-e2e=\"followers-count\">(.*?)<\/strong>/";
			preg_match_all( $pattern, $response['body'], $matches );

			if ( isset( $matches[0][0] ) ) {
				$count = $matches[0][0];
			}

			return $count;
		}
	}

endif;