PATH:
var
/
www
/
clients
/
client1
/
web1
/
web
/
wp-content
/
plugins
/
vxcash
/
admin
<?php /** * Created by PhpStorm. * User: te * Date: 09.03.2016 * Time: 15:48 */ class Vxcash_Vx_Dataprovider { const URL_IDS = 'http://%s:%s@www.visit-x.net/VXREST/v1/affiliate/actors'; const URL_DETAILS = 'http://%s:%s@www.visit-x.net/VXREST/v1/affiliate/actors/details?filter=%s&fsk=%s'; const URL_REMOVED = 'http://www.visit-x.net/VXCASHREST/v1/wp/active?ids=[%s]&w=%s&key=%s'; const URL_CALLBACK = 'http://www.visit-x.net/VXCASHREST/v1/wp/changes?ids=%s&w=%s&key=%s&action=%s&actor=%s&url=%s&ver=%s'; const PAGE_SIZE = 50; /** * @var Vxcash_Config */ private $config; /** * @var wpdb */ private $wpdb; /** * @var Vxcash_Visitx_Graphql_Client */ private $graphqlClient; /** * @var string */ private $version; /** * Vxcash_Vx_Host_Dataprovider constructor. * * @param Vxcash_Config $config * @param wpdb $wpdb * @param $graphqlClient * @param string $version */ public function __construct(Vxcash_Config $config, wpdb $wpdb, Vxcash_Visitx_Graphql_Client $graphqlClient, $version) { $this->config = $config; $this->wpdb = $wpdb; $this->graphqlClient = $graphqlClient; $this->version = $version; } public function updateOnlineHostsFromRemote() { $online = $this->graphqlClient->getOnlineHostIds(); if (count($online) > 0) { $tableName = $this->wpdb->prefix . Vxcash_Tablename_Enum::VX_ONLINE_HOSTS; $this->wpdb->query("DELETE FROM $tableName WHERE 1"); $values = array(); foreach ($online as $val) { $values[] = $this->wpdb->prepare('(%d)', $val); } $query = "INSERT INTO $tableName (id) VALUES "; $query .= implode(',', $values); $this->wpdb->query($query); } return $online; } /** * @param array $command * @param int $amount * * @return array */ public function getHostsFromRemote(array $command, $amount = 50) { $theUrl = sprintf(self::URL_IDS, $this->config->getWmid(), $this->config->getVisitxApiKey()); $filter = array(); if (isset($command['rubrik']) && !empty($command['rubrik'])) { $filter['categories'] = array($command['rubrik']); } if (isset($command['fsk']) && !empty($command['fsk'])) { $filter['fsk'] = $command['fsk']; } else { $filter['fsk'] = 'DE16'; } if (isset($command['minAge']) && !empty($command['minAge']) && is_numeric($command['minAge'])) { $filter['ageMin'] = (int) $command['minAge']; } if (isset($command['maxAge']) && !empty($command['maxAge']) && is_numeric($command['maxAge'])) { $filter['ageMax'] = (int) $command['maxAge']; } if (isset($command['haarfarbe']) && is_array($command['haarfarbe']) && count($command['haarfarbe']) > 0) { $filter['hair'] = $command['haarfarbe']; } if (isset($command['figur']) && is_array($command['figur']) && count($command['figur']) > 0) { $filter['shapes'] = $command['figur']; } $theUrl .= '?filter=' . json_encode($filter); $tablename = $this->wpdb->prefix . Vxcash_Tablename_Enum::LIVECAMS; $knownHosts = $this->wpdb->get_col("SELECT id FROM $tablename WHERE 1"); // Add Lucy-Cat and Lexyroxx to known hosts, so they never appear! Requeste by StSt, see https://phabricator.x/T13828 //$knownHosts[] = 5613624; //$knownHosts[] = 3926584; $continue = true; $start = 0; $limit = self::PAGE_SIZE; $newHostIds = array(); do { set_time_limit(300); // Force longer time limit $result = wp_remote_get($theUrl . sprintf('&start=%s&limit=%s', $start, $limit)); $data = json_decode($result['body'], true); if (isset($data['data']) && is_array($data['data']) && count($data['data']) > 0) { $unknown = array_diff($data['data'], $knownHosts); $newHostIds = array_merge($newHostIds, $unknown); } else { $continue = false; } if (count($newHostIds) >= $amount) { $continue = false; $newHostIds = array_slice($newHostIds, 0, $amount); } $start += $limit; } while ($continue === true); if (count($newHostIds) === 0) { return array(); } return $this->getHostProfilesForIds($newHostIds, $filter['fsk']); } /** * Checks current host IDs against Content Partner Api to see if some have been turned off */ public function findRemovedHostIds() { $tableName = $this->wpdb->prefix . Vxcash_Tablename_Enum::LIVECAMS; // Must be smarter, not just take every shit... or does it? $allIds = $this->wpdb->get_col("SELECT id FROM $tableName WHERE 1"); $chunked = array_chunk($allIds, 50); $deleted = array(); foreach ($chunked as $chunk) { $url = sprintf(self::URL_REMOVED, implode(',', $chunk), $this->config->getWmid(), $this->config->getVisitxApiKey()); $result = wp_remote_get($url); $data = json_decode($result['body'], true); if (is_array($data) && is_array($data['data'])) { $deleted = array_merge($deleted, $data['data']); } } $notDeleted = array_diff($allIds, $deleted); return array($deleted, $notDeleted); } /** * @param int $id * @param string $login * @param int $pageId * @param string $status */ public function saveHostIdAndName($id, $login, $pageId, $status) { if ($status === 'publish') { $action = Vxcash_Vxhost_State_Enum::IMPORTED_AND_PUBLISHED; } else { $action = Vxcash_Vxhost_State_Enum::IMPORTED_AND_DRAFT; } $this->wpdb->replace($this->wpdb->prefix . Vxcash_Tablename_Enum::LIVECAMS, array('id' => $id, 'name' => $login, 'page' => $pageId, 'last_action' => $action)); } /** * @param int $id * @param string $title * @param int $pageId * @param string $status */ public function saveVideoIdAndTitle($id, $title, $pageId, $status) { if ($status === 'publish') { $action = Vxcash_Vxhost_State_Enum::IMPORTED_AND_PUBLISHED; } else { $action = Vxcash_Vxhost_State_Enum::IMPORTED_AND_DRAFT; } $this->wpdb->replace($this->wpdb->prefix . Vxcash_Tablename_Enum::VX_VIDEOS, array('id' => $id, 'title' => $title, 'page' => $pageId, 'last_action' => $action)); } /** * @return int */ public function getHostCount() { $tablename = $this->wpdb->prefix . Vxcash_Tablename_Enum::LIVECAMS; return (int) $this->wpdb->get_var("SELECT COUNT(*) FROM $tablename WHERE 1"); } /** * @param int[] $albumIds */ public function unpublishRemovedAlbums($albumIds) { $tableName = $this->wpdb->get_blog_prefix() . Vxcash_Tablename_Enum::LIVECAMS; $deletedString = implode(',', $albumIds); $sql1 = "SELECT * FROM $tableName WHERE id IN ($deletedString)"; /** @var array $turnOff */ $turnOff = $this->wpdb->get_results($sql1, ARRAY_A); $changed = get_option('vxcash_vxvideos_state_changes', array()); foreach ($turnOff as $item) { $pageId = $item['page']; $videoId = $item['id']; $changed[] = $videoId; // Remember that we did that! $this->wpdb->update($tableName, array('last_action' => Vxcash_Vxhost_State_Enum::SET_TO_DRAFT_BY_CRON), array('id' => $videoId)); // Sometimes we have no page Id, then we can do nothing anyway if ($pageId === 0) { continue; } // Set the post to draft wp_update_post(array('ID' => $pageId, 'post_status' => 'draft')); } $changed = array_unique($changed, SORT_NUMERIC); update_option('vxcash_vxvideos_state_changes', $changed, false); $chunked = array_chunk($albumIds, 30); foreach ($chunked as $item) { $this->sendCallbackToVXCash($item, 'draft', 'cron'); } } /** * Sets all pages that have deleted hosts and were automatically set to published to * draft status. * * @param $hostIds */ public function unpublishRemovedHosts($hostIds) { $tableName = $this->wpdb->get_blog_prefix() . Vxcash_Tablename_Enum::LIVECAMS; $deletedString = implode(',', $hostIds); $sql1 = "SELECT * FROM $tableName WHERE id IN ($deletedString)"; /** @var array $turnOff */ $turnOff = $this->wpdb->get_results($sql1, ARRAY_A); $changed = get_option('vxcash_livecams_state_changes', array()); foreach ($turnOff as $item) { $pageId = $item['page']; $hostId = $item['id']; $changed[] = $hostId; // Remember that we did that! $this->wpdb->update($tableName, array('last_action' => Vxcash_Vxhost_State_Enum::SET_TO_DRAFT_BY_CRON), array('id' => $hostId)); // Sometimes we have no page Id, then we can do nothing anyway if ($pageId === 0) { continue; } // Set the post to draft wp_update_post(array('ID' => $pageId, 'post_status' => 'draft')); } $changed = array_unique($changed, SORT_NUMERIC); update_option('vxcash_livecams_state_changes', $changed, false); $chunked = array_chunk($hostIds, 30); foreach ($chunked as $item) { $this->sendCallbackToVXCash($item, 'draft', 'cron'); } } /** * Re-publish hosts that have been automatically set to draft mode before by cron (and nobody else!) * * @param $notDeleted */ public function reinstateActiveHosts($notDeleted) { // Alle die in notDeleted sind müssen wieder online gestellt werden, wenn sie diesen Status haben // Vxcash_Vxhost_State_Enum::SET_TO_DRAFT_BY_CRON $tableName = $this->wpdb->get_blog_prefix() . Vxcash_Tablename_Enum::LIVECAMS; $notDeletedString = implode(',', $notDeleted); $sql1 = $this->wpdb->prepare("SELECT * FROM $tableName WHERE id IN ($notDeletedString) AND (last_action = %d)", Vxcash_Vxhost_State_Enum::SET_TO_DRAFT_BY_CRON); /** @var array $turnOn */ $turnOn = $this->wpdb->get_results($sql1, ARRAY_A); $checked = []; foreach ($turnOn as $item) { $pageId = $item['page']; $hostId = $item['id']; // Remember that we did that! $this->wpdb->update($tableName, array('last_action' => Vxcash_Vxhost_State_Enum::SET_TO_PUBLISHED_BY_CRON), array('id' => $hostId)); if ($pageId === 0) { continue; } // Set the post back to published wp_update_post(array('ID' => $pageId, 'post_status' => 'publish')); $checked[] = $hostId; } $changed = get_option('vxcash_livecams_state_changes', array()); $changed = array_diff($changed, $notDeleted); update_option('vxcash_livecams_state_changes', $changed); $this->sendCallbackToVXCash($checked, 'published', 'cron'); } /** * Re-publish Videos that have been automatically set to draft mode before by cron (and nobody else!) * * @param $notDeleted */ public function reinstateActiveVideos($notDeleted) { // Alle die in notDeleted sind müssen wieder online gestellt werden, wenn sie diesen Status haben // Vxcash_Vxhost_State_Enum::SET_TO_DRAFT_BY_CRON $tableName = $this->wpdb->get_blog_prefix() . Vxcash_Tablename_Enum::VX_VIDEOS; $notDeletedString = implode(',', $notDeleted); $sql1 = $this->wpdb->prepare("SELECT * FROM $tableName WHERE id IN ($notDeletedString) AND (last_action = %d)", Vxcash_Vxhost_State_Enum::SET_TO_DRAFT_BY_CRON); /** @var array $turnOn */ $turnOn = $this->wpdb->get_results($sql1, ARRAY_A); $checked = []; foreach ($turnOn as $item) { $pageId = $item['page']; $videoId = $item['id']; // Remember that we did that! $this->wpdb->update($tableName, array('last_action' => Vxcash_Vxhost_State_Enum::SET_TO_PUBLISHED_BY_CRON), array('id' => $videoId)); if ($pageId === 0) { continue; } // Set the post back to published wp_update_post(array('ID' => $pageId, 'post_status' => 'publish')); $checked[] = $videoId; } $changed = get_option('vxcash_vxvideos_state_changes', array()); $changed = array_diff($changed, $notDeleted); update_option('vxcash_vxvideos_state_changes', $changed); $this->sendCallbackToVXCash($checked, 'published', 'cron'); } /** * @param array $newHostIds * @param string $fsk * * @return array */ private function getHostProfilesForIds(array $newHostIds, $fsk = 'DE16') { $filter = array( 'fsk' => $fsk, ); $chunks = array_chunk($newHostIds, 10); $complete = array(); foreach ($chunks as $chunk) { $filter['ids'] = $chunk; $url = sprintf(self::URL_DETAILS, $this->config->getWmid(), $this->config->getVisitxApiKey(), json_encode($filter), $fsk); $result = wp_remote_get($url); $data = json_decode($result['body'], true); $filtered = array_filter($data['data'], function ($item) { return isset($item['pic']) && !empty($item['pic']); }); $complete = array_merge($complete, $filtered); } return array_values($complete); } public function getHostInfo() { $tablename = $this->wpdb->prefix . Vxcash_Tablename_Enum::LIVECAMS; $data = $this->wpdb->get_results("SELECT id, name FROM $tablename WHERE 1"); $reply = []; foreach ($data as $datum) { $reply[$datum->id] = $datum->name; } return $reply; } public function getKnownVideoIds() { $table = $this->wpdb->prefix . Vxcash_Tablename_Enum::VX_VIDEOS; $known = $this->wpdb->get_col("SELECT id from $table WHERE 1"); return array_map('intval', $known); } /** * @param int $modelId * * @return bool */ public function hasModelPage($modelId) { $table = $this->wpdb->prefix . Vxcash_Tablename_Enum::LIVECAMS; $known = $this->wpdb->get_var($this->wpdb->prepare("SELECT COUNT(*) from $table WHERE id = %d", $modelId)); return $known > 0; } /** * @return array('modelIds' => int[], 'albumIds' => int[]) */ public function getDeletedHostAndAlbumIds() { return $this->graphqlClient->getDeletedHostAndAlbumIds(); } /** * @return int[] */ public function getAutoDraftedHostIds() { $table = $this->wpdb->prefix . Vxcash_Tablename_Enum::LIVECAMS; $ids = $this->wpdb->get_col($this->wpdb->prepare("SELECT id FROM $table WHERE last_action = %d", Vxcash_Vxhost_State_Enum::SET_TO_DRAFT_BY_CRON)); return $ids; } /** * @return int[] */ public function getAutoDraftedVideoIds() { $table = $this->wpdb->prefix . Vxcash_Tablename_Enum::VX_VIDEOS; $ids = $this->wpdb->get_col($this->wpdb->prepare("SELECT id FROM $table WHERE last_action = %d", Vxcash_Vxhost_State_Enum::SET_TO_DRAFT_BY_CRON)); return $ids; } /** * @param int[] $draftedHostIds * * @return int[] */ public function checkForReinstatedHosts($draftedHostIds) { return $this->graphqlClient->getReturnedHostIds($draftedHostIds); } /** * @param int[] $draftedVideoIds * * @return int[] */ public function checkForReinstatedVideos($draftedVideoIds) { return $this->graphqlClient->getReturnedVideoIds($draftedVideoIds); } /** * @param array $items * @param string $action 'draft'|'live' * @param string $actor 'admin'|'cron'|'external' */ public function sendCallbackToVXCash($items, $action, $actor) { $url = sprintf( self::URL_CALLBACK, implode(',', $items), $this->config->getWmid(), $this->config->getVisitxApiKey(), $action, $actor, get_site_url(), $this->version ); wp_remote_get($url); } }
[-] index.php
[edit]
[+]
js
[-] class-vxcash-debug-admin.php
[edit]
[-] class-vxcash-visitx-video-admin.php
[edit]
[-] class-vxcash-auto-import-dataprovider.php
[edit]
[-] class-vxcash-config.php
[edit]
[+]
partials
[-] class-vxcash-admin.php
[edit]
[-] class-vxcash-host-category-handler.php
[edit]
[-] class-vxcash-notifier.php
[edit]
[+]
..
[+]
css
[-] class-vxcash-visitx-host-admin.php
[edit]
[-] class-vxcash-visitx-graphql-client.php
[edit]
[-] class-vxcash-pornme-video-admin.php
[edit]
[-] class-vxcash-vx-dataprovider.php
[edit]