PATH:
var
/
www
/
clients
/
client1
/
web1
/
web
/
wp-content
/
plugins
/
vxcash
/
admin
<?php /** * Created by PhpStorm. * User: te * Date: 29.02.2016 * Time: 15:25 */ class Vxcash_Visitx_Host_Admin { /** * @var string */ private $plugin_name; /** * @var string */ private $version; /** * @var Vxcash_Loader */ private $loader; /** * @var string */ private $parent_plugin_name; /** * @var Vxcash_Vx_Dataprovider */ private $dataprovider; /** * @var Vxcash_Host_Category_Handler */ private $categoryHandler; /** * @var Vxcash_Auto_Import_Dataprovider */ private $importDataprovider; /** * @var Vxcash_Config */ private $config; /** * Vxcash_Visitx_Host_Admin constructor. * * @param $parentPluginName * @param $version * @param Vxcash_Loader $loader * @param Vxcash_Config $config * @param Vxcash_Host_Category_Handler $categoryHandler * @param Vxcash_Vx_Dataprovider $dataprovider * @param Vxcash_Auto_Import_Dataprovider $importDataprovider * * @throws Exception */ public function __construct( $parentPluginName, $version, Vxcash_Loader $loader, Vxcash_Config $config, Vxcash_Host_Category_Handler $categoryHandler, Vxcash_Vx_Dataprovider $dataprovider, Vxcash_Auto_Import_Dataprovider $importDataprovider ) { $this->parent_plugin_name = $parentPluginName; $this->plugin_name = $parentPluginName . 'liveCams'; $this->version = $version; $this->loader = $loader; $this->dataprovider = $dataprovider; $this->categoryHandler = $categoryHandler; $this->importDataprovider = $importDataprovider; $this->config = $config; $this->defineAdminHooks(); $myOptions = get_option($this->plugin_name); $lastUpdate = isset($myOptions['lastUpdate']) ? $myOptions['lastUpdate'] : null; $now = new DateTime(); $diff = null; if ($lastUpdate instanceof DateTime) { $diff = $now->diff($lastUpdate); } if ($lastUpdate === null || $diff->y > 0 || $diff->m > 0 || $diff->d > 0 || $diff->h > 0 || $diff->i > 15) { $this->dataprovider->updateOnlineHostsFromRemote(); update_option($this->plugin_name, array('lastUpdate' => $now)); } } /** * @param array $hosts * @param int $author * @param string $status * @param string $type Frau|Mann|Couple etc. * @param string $seoText * * @return array */ public function importHostList($hosts, $author, $status, $type, $seoText) { $success = array(); foreach ($hosts as $hostData) { $currentSeo = $seoText; if (is_string($hostData)) { $hostData = stripslashes($hostData); $host = json_decode($hostData, true); } else { $host = $hostData; } // Ignore special test account of mscp if ((int) $hosts['id'] === 1352087) { continue; } $currentSeo = str_replace('{{name}}', $host['login'], $currentSeo); while(preg_match('!{{(\w+)}}!', $currentSeo, $matches)) { $currentMatch = $matches[1]; if (isset($host[$currentMatch])) { $currentSeo = str_replace('{{' . $currentMatch . '}}', $host[$currentMatch], $currentSeo); } else { $currentSeo = str_replace('{{' . $currentMatch . '}}', '', $currentSeo); } } set_time_limit(300); // force longer time limit $id = $host['id']; $categories = $host['categories']; $preview = $host['pic']; $content = "<a href='[vxlinking id=$id]' target='_blank' rel='nofollow'><img src=\"$preview\"><br/></a>$currentSeo"; $postArr = array( 'post_author' => $author, 'post_content' => $content, 'post_title' => $host['login'], 'post_status' => $status, 'post_type' => Vxcash_Posttypes_Enum::VX_HOSTS, 'comment_status' => 'closed' ); $result = wp_insert_post($postArr); if ($result !== 0) { $this->saveTerms($result, $host, $categories); // Force type Tag, if not set by categories wp_add_post_tags($result, ucfirst($type)); $this->saveCustomFields($result, $host, do_shortcode('[vxlinking id=' . $id . ']')); if ($currentSeo !== '') { add_post_meta($result, 'vxcash_has_seo', 1); } $this->dataprovider->saveHostIdAndName($id, $host['login'], $result, $status); $success[] = $id; } } return $success; } private function defineAdminHooks() { $this->loader->add_action('admin_menu', $this, 'add_sub_menu_page'); $this->loader->add_action('update_vxcash_content', $this, 'cron_update_livecams'); $this->loader->add_action('wp_ajax_get_filtered_hosts', $this, 'ajax_get_filtered_hosts'); $this->loader->add_action('wp_ajax_import_hosts', $this, 'ajax_import_hosts'); $this->loader->add_action('wp_ajax_add_auto_load_host', $this, 'ajax_add_autoload'); $this->loader->add_action('wp_ajax_get_auto_host_list', $this, 'ajax_get_host_autoloader_list'); $this->loader->add_action('wp_ajax_change_autoloader', $this, 'ajax_change_autoloader'); $this->loader->add_action('delete_post', $this, 'delete_post_from_hostlist'); } /** * Updates vx Hosts, but only if we are not already above the max threshold */ public function cron_update_livecams() { $max = $this->config->getVxMaxNum(); $have = $this->dataprovider->getHostCount(); if ($max === 0 || $have < $max) { $autos = $this->importDataprovider->getAutoHostList(true); foreach ($autos as $auto) { $hosts = $this->dataprovider->getHostsFromRemote($auto['settings'], $auto['settings']['maxLoad']); $seo = isset($auto['settings']['seo']) ? $auto['settings']['seo'] : ''; $this->importHostList($hosts, $auto['settings']['author'], $auto['settings']['status'], $auto['settings']['rubrik'], $seo); $this->importDataprovider->updateCountOnAutoload($auto['id'], count($hosts)); } } } /** * Notice - this will also be used by pornme Videos!!! */ public function ajax_change_autoloader() { if (!current_user_can('manage_options')) { die(); } $id = (int) $_POST['id']; $action = $_POST['subaction']; switch ($action) { case 'deactivate': $this->importDataprovider->deactivateAutoloader($id); break; case 'activate': $this->importDataprovider->activateAutoloader($id); break; case 'delete': $this->importDataprovider->deleteAutoloader($id); break; } } /** * Ajax receiver for new autoload settings */ public function ajax_add_autoload() { check_ajax_referer('vxcash-host-ajax', 'security'); if (!current_user_can('manage_options')) { die(); } $maxLoad = (int) $_POST['maxLoad']; if ($maxLoad < 0) { $maxLoad = 1; } else if ($maxLoad > 30) { $maxLoad = 30; } $settings = array( 'rubrik' => $_POST['rubrik'], 'author' => $_POST['author'], 'status' => $_POST['status'], 'haarfarbe' => $_POST['haarfarbe'], 'figur' => $_POST['figur'], 'fsk' => $_POST['fsk'], 'seo' => $_POST['seo'], 'maxLoad' => $maxLoad ); if (isset($_POST['minAge']) && !empty($_POST['minAge'])) { $settings['minAge'] = (int) $_POST['minAge']; } if (isset($_POST['maxAge']) && !empty($_POST['maxAge'])) { $settings['maxAge'] = (int) $_POST['maxAge']; } $data = array( 'type' => 'HOST', 'settings' => json_encode($settings) ); $this->importDataprovider->saveAutoLoader($data); echo 'ok'; wp_die(); } /** * Gives back a list of the autoloaders for hosts */ public function ajax_get_host_autoloader_list() { check_ajax_referer('vxcash-host-ajax', 'security'); if (!current_user_can('manage_options')) { die(); } echo json_encode($this->importDataprovider->getAutoHostList(false)); wp_die(); } /** * Echos a list of hosts. wp_die is intentional and necessary when using ajax! */ public function ajax_get_filtered_hosts() { check_ajax_referer('vxcash-host-ajax', 'security'); if (!current_user_can('manage_options')) { die(); } $data = $this->dataprovider->getHostsFromRemote($_POST); echo json_encode($data); wp_die(); } /** * */ public function ajax_import_hosts() { check_ajax_referer('vxcash-host-ajax', 'security'); if (!current_user_can('manage_options')) { die(); } $upload = wp_upload_dir(); if (isset($upload['error']) && $upload['error'] !== false) { echo json_encode(array( 'result' => 403, 'error' => $upload['error'] )); } else { list($hosts, $author, $status, $type, $seo) = $this->validateInput(); $success = $this->importHostList($hosts, $author, $status, $type, $seo); echo json_encode(array( 'result' => 200, 'added' => $success )); } wp_die(); } /** * @param int $pid * * Removes elements from our tables */ public function delete_post_from_hostlist($pid) { global $wpdb; $tableVx = $wpdb->prefix . Vxcash_Tablename_Enum::LIVECAMS; $tableVxVid = $wpdb->prefix . Vxcash_Tablename_Enum::VX_VIDEOS; $tablePm = $wpdb->prefix . Vxcash_Tablename_Enum::PORNME_IMPORTED_VIDEOS; $wpdb->query($wpdb->prepare("DELETE FROM $tableVx WHERE page = %d", $pid)); $wpdb->query($wpdb->prepare("DELETE FROM $tableVxVid WHERE page = %d", $pid)); $wpdb->query($wpdb->prepare("DELETE FROM $tablePm WHERE postId = %d", $pid)); } /** * */ public function add_sub_menu_page() { add_submenu_page($this->parent_plugin_name, 'Darsteller Import', 'Darsteller Import', 'manage_options', $this->plugin_name, array($this, 'display_vxhost_admin_page')); } /** * */ public function display_vxhost_admin_page() { wp_enqueue_script('jquery-ui-core'); wp_enqueue_script('jquery-ui-tabs'); wp_enqueue_style('jquery-ui-demo', plugin_dir_url(__FILE__) . 'css/jquery-ui-demo.css'); wp_enqueue_script('vxcash-vx-host', plugin_dir_url(__FILE__) . 'js/vxcash-vx-host.js', array('jquery', 'vxcash-admin'), $this->version, false); if ('classic' === get_user_option('admin_color')) { wp_enqueue_style('jquery-ui-css', plugin_dir_url(__FILE__) . 'css/jquery-ui-classic.css'); } else { wp_enqueue_style('jquery-ui-css', plugin_dir_url(__FILE__) . 'css/jquery-ui-fresh.css'); } $max = $this->config->getVxMaxNum(); $have = $this->dataprovider->getHostCount(); $warning = ''; if ($max <= $have && $max > 0) { $warning = sprintf('<div class="notice notice-warning"> <p> <b>Achtung:</b> Sie haben bisher %d VISIT-X Sender importiert, aber einen maximal-import von %d Sendern eingestellt.<br> Es werden deshalb keine weiteren Sender automatisch importiert! Sie können weiterhin direkt neue Sender importieren. </p> </div>', $have, $max); } include_once __DIR__ . '/partials/vxcash-visitx-host-display.php'; } /** * @return array */ private function validateInput() { $hosts = isset($_POST['hosts']) ? $_POST['hosts'] : array(); if (!is_array($hosts)) { $hosts = array(); } $author = (int) $_POST['author']; $status = $_POST['status']; if (!in_array($status, array('draft', 'publish'), true)) { $status = 'draft'; } $type = ''; if (isset($_POST['rubrik'])) { $type = $this->translateRubrik($_POST['rubrik']); } $seo = ''; if (isset($_POST['seo'])) { $seo = $_POST['seo']; } return array($hosts, $author, $status, $type, $seo); } private function translateRubrik($rubrik = '') { $type = ''; $rubriken = array( 'girls' => 'Frau', 'boys' => 'Mann', 'couples' => 'Paar', 'trans' => 'Trans' ); if (isset($rubriken[$rubrik])) { $type = $rubriken[$rubrik]; } return $type; } /** * @param $result * @param $host * @param $categories */ private function saveTerms($result, $host, $categories) { wp_set_object_terms($result, $host['hairColor'], 'haarfarbe'); wp_set_object_terms($result, $host['figure'], 'figur'); $cats = array(); foreach ($categories as $cat) { $cats = array_merge($cats, $this->categoryHandler->getCategories($cat)); } wp_add_post_tags($result, array_unique($cats)); } /** * @param int $result * @param array $host * @param string $url */ private function saveCustomFields($result, $host, $url) { add_post_meta($result, 'vxcash_preview_image', $host['pic']); add_post_meta($result, '_thumbnail_id', 'by_url'); add_post_meta($result, 'birthday', $host['birthday']); add_post_meta($result, 'cupsize', $host['cupSize']); add_post_meta($result, 'eyecolor', $host['eyeColor']); add_post_meta($result, 'weight', $host['weight']); add_post_meta($result, 'skintype', $host['skinType']); add_post_meta($result, 'size', $host['size']); add_post_meta($result, 'sexuality', $host['sexuality']); add_post_meta($result, 'relationship', $host['relationshipStatus']); add_post_meta($result, 'pubichair', $host['pubicHair']); add_post_meta($result, 'gender', $host['gender']); add_post_meta($result, 'hairlength', $host['hairLength']); add_post_meta($result, 'hobbies', $host['hobbies']); add_post_meta($result, 'job', $host['job']); add_post_meta($result, 'lookingfor', $host['lookingFor']); add_post_meta($result, 'motto', $host['motto']); add_post_meta($result, 'link', $url); add_post_meta($result, 'hostId', $host['id']); add_post_meta($result, 'pmId', $host['pornmeid']); } }
[-] 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]