PATH:
var
/
www
/
clients
/
client1
/
web1
/
web
/
wp-content
/
plugins
/
vxcash
/
public
<?php /** * Created by PhpStorm. * User: te * Date: 20.06.2016 * Time: 10:54 */ class Vxcash_Bas_Dataprovider { //const BASE_NUMBERS = 'http://te.vxcall.x/rest/vxcash/metadata?w=%s&key=%s'; const BASE_NUMBERS = 'http://beianrufsex.com/rest/vxcash/metadata?w=%s&key=%s'; const ONLINE_HOSTS = 'https://beianrufsex.com/rest/vxcash/senderlist/online?w=%s&key=%s'; const CHAT_START = 'https://beianrufsex.com/rest/vxcash/videochat/url?w=%s&ws=%s&key=%s&videoCode=%s&exitUrl=%s&adtv=%s'; const OFFLINE_HOSTS = 'https://beianrufsex.com/rest/vxcash/senderlist/offline?w=%s&key=%s'; const SINGLE_HOST = 'https://beianrufsex.com/rest/sender/%s'; const ONLINE_CHECK = 'https://beianrufsex.com/rest/vxcash/sender/%s/online?w=%s&key=%s'; /** * @var Vxcash_Config */ private $config; /** * @var wpdb */ private $wpdb; /** * @var array|null */ private $numbersCache; /** * @var array */ private $hostCache = array(); /** * Vxcash_Bas_Dataprovider constructor. * * @param Vxcash_Config $config * @param wpdb $wpdb */ public function __construct(Vxcash_Config $config, wpdb $wpdb) { $this->config = $config; $this->wpdb = $wpdb; } /** * @return bool */ public function updateNumbersFromRemote() { if ($this->config->getBasApiKey() === '') { return false; } $url = sprintf(self::BASE_NUMBERS, $this->config->getWmid(), $this->config->getBasApiKey()); $result = wp_remote_get($url); if (!$result instanceof WP_Error && isset($result['response']['code']) && $result['response']['code'] === 200) { $data = json_decode($result['body'], true); $countries = null; if (isset($data['data'][0]['countries']) && count($data['data'][0]['countries']) > 1) { $countries = $data['data'][0]['countries']; } else if (isset($data['data'][0]) && count($data['data'][0]) > 1) { $countries = $data['data'][0]; } if ($countries === null) { return false; } $table = $this->wpdb->prefix . Vxcash_Tablename_Enum::BAS_NUMBERS; $this->wpdb->query("DELETE FROM $table WHERE 1"); foreach ($countries as $language => $content) { $this->wpdb->insert($table, array('lang' => $language, 'content' => json_encode($content))); } return true; } return false; } /** * @param $hostId * * @return Vxcash_Bas_Host | null */ public function getInfoForHost($hostId) { $numbers = $this->getNumbers(); if (count($numbers) === 0) { return null; } $transientKey = 'vxbas_host_' . $hostId; $host = get_transient($transientKey); if ($host === false) { $url = sprintf(self::SINGLE_HOST, $hostId); $result = wp_remote_get($url); if ( ! $result instanceof WP_Error && isset( $result['response']['code'] ) && $result['response']['code'] === 200 ) { $decode = json_decode($result['body'], true); $host = new Vxcash_Bas_Host($decode['data'], $decode['data']['status']); set_transient($transientKey, $host,300); } } return $host; } /** * @return Vxcash_Bas_Host[] */ public function getHostList() { $url = sprintf( self::ONLINE_HOSTS, $this->config->getWmid(), $this->config->getBasApiKey() ); $result = wp_remote_get( $url ); $hostArray = []; if ( ! $result instanceof WP_Error && isset( $result['response']['code'] ) && $result['response']['code'] === 200 ) { $data = json_decode( $result['body'], true ); foreach ( $data['data'] as $host ) { $hostArray[] = new Vxcash_Bas_Host( $host, $host['status'] ); } } $url2 = sprintf( self::OFFLINE_HOSTS, $this->config->getWmid(), $this->config->getBasApiKey() ); $result2 = wp_remote_get( $url2 ); if ( ! $result2 instanceof WP_Error && isset( $result2['response']['code'] ) && $result2['response']['code'] === 200 ) { $data2 = json_decode( $result2['body'], true ); foreach ( $data2['data'] as $host ) { $hostArray[] = new Vxcash_Bas_Host( $host, $host['status'] ); } } return $hostArray; } /** * @param int $code * @param string $exitUrl * * @return array */ public function getChatInfo($code, $exitUrl) { $url = sprintf( self::CHAT_START, $this->config->getWmid(), $this->config->getBasCampaignId() . '.wp', $this->config->getBasApiKey(), $code, urlencode($exitUrl), Vxcash::createAdtv() ); $result = wp_remote_get($url); $reply = array( 'status' => 200, 'text' => '', 'url' => '' ); if ($result instanceof WP_Error) { $reply['status'] = 400; $reply['text'] = 'Konnte Chat nicht öffnen. Bitte versuchen Sie es später noch einmal.'; return $reply; } $body = json_decode($result['body'], true); if (isset($result['response']['code'])) { if ($result['response']['code'] == 200) { $reply['url'] = $body['data']['chatUrl']; } else { $reply['status'] = 400; switch ($body['data']['api-code']) { case 101: // Video Code stimmt nicht $reply['text'] = 'Der Video-Code ist leider ungültig.'; break; case 100: // WMID und Key sind nicht passend case 102: // Fehler bei VX default: // ??? Unbekannte Fehler $reply['text'] = 'Konnte Chat nicht öffnen. Bitte versuchen Sie es später noch einmal.'; break; } } } else { $reply['status'] = 400; $reply['text'] = 'Konnte Chat nicht öffnen. Bitte versuchen Sie es später noch einmal.'; } return $reply; } /** * @return array|null|object */ public function getNumbers() { if ($this->numbersCache === null) { $numbersTable = $this->wpdb->prefix . Vxcash_Tablename_Enum::BAS_NUMBERS; $this->numbersCache = $this->wpdb->get_results("SELECT * FROM $numbersTable WHERE 1", ARRAY_A); } return $this->numbersCache; } /** * @return bool */ public function hasNumbers() { $numbers = $this->getNumbers(); return count($numbers) > 0; } public function getSingleHostFromRemote( $id ) { $url = sprintf( self::SINGLE_HOST, $id ); $result = wp_remote_get( $url ); $host = []; if ( ! $result instanceof WP_Error && isset( $result['response']['code'] ) && $result['response']['code'] === 200 ) { $data = json_decode( $result['body'], true ); $host = new Vxcash_Bas_Host( $data['data'], $data['data']['status'] ); } return $host; } }
[+]
img
[-] class-vxcash-bas-dataprovider.php
[edit]
[-] class-vxcash-bas-country.php
[edit]
[-] class-vxcash-public.php
[edit]
[-] index.php
[edit]
[+]
js
[+]
partials
[-] class-vxcash-bas-host.php
[edit]
[-] class-vxcash-bas.php
[edit]
[+]
..
[+]
css
[-] class-vxcash-crosselling.php
[edit]