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_Video_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_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_Vx_Dataprovider $dataprovider * @param Vxcash_Auto_Import_Dataprovider $importDataprovider */ public function __construct( $parentPluginName, $version, Vxcash_Loader $loader, Vxcash_Config $config, Vxcash_Vx_Dataprovider $dataprovider, Vxcash_Auto_Import_Dataprovider $importDataprovider ) { $this->parent_plugin_name = $parentPluginName; $this->plugin_name = $parentPluginName . 'pornos'; $this->version = $version; $this->loader = $loader; $this->dataprovider = $dataprovider; $this->importDataprovider = $importDataprovider; $this->config = $config; $this->defineAdminHooks(); } private function defineAdminHooks() { $this->loader->add_action('admin_menu', $this, 'add_sub_menu_page'); $this->loader->add_action('update_vxcash_content', $this, 'cron_update_pornos'); $this->loader->add_action('wp_ajax_import_videos', $this, 'ajax_import_videos'); $this->loader->add_action('wp_ajax_add_auto_load_video', $this, 'ajax_add_autoload'); $this->loader->add_action('wp_ajax_get_auto_video_list', $this, 'ajax_get_video_autoloader_list'); } /** * Updates vx videos, but only if we are not already above the max threshold */ public function cron_update_pornos() { $max = $this->config->getVxVideoMaxNum(); $known = $this->dataprovider->getKnownVideoIds(); $have = count($known); if ($max === 0 || $have < $max) { $client = new Vxcash_Visitx_Graphql_Client($this->config); $autos = $this->importDataprovider->getAutoVxVideoList(true); foreach ($autos as $auto) { $filter = []; if ($auto['settings']['darsteller'] !== '') { $filter[] = $client->createFilter('darsteller', $auto['settings']['darsteller']); } else if ($auto['settings']['geschlecht'] !== '') { $filter[] = $client->createFilter('geschlecht', $auto['settings']['geschlecht']); } if ($auto['settings']['tag'] !== '') { $filter[] = $client->createFilter('tag', $auto['settings']['tag']); } if ($auto['settings']['preis'] !== '') { $filter[] = $client->createFilter('preis', $auto['settings']['preis']); } if ($auto['settings']['maxAlter'] !== '') { $filter[] = $client->createFilter('alter', $auto['settings']['maxAlter']); } $videos = $client->getVideos($filter, $known, $auto['settings']['fsk'], $auto['settings']['maxLoad']); $known = array_merge($known, array_map(function($item) { return $item['id']; }, $videos)); $this->importVideoList($videos, $auto['settings']['author'], $auto['settings']['status'], $auto['settings']['category']); $this->importDataprovider->updateCountOnAutoload($auto['id'], count($videos)); } } } /** * Gives back a list of the autoloaders for videos */ public function ajax_get_video_autoloader_list() { check_ajax_referer('vxcash-video-ajax', 'security'); if (!current_user_can('manage_options')) { die(); } $data = $this->importDataprovider->getAutoVxVideoList(false); $jsonEncode = json_encode($data); echo $jsonEncode; wp_die(); } /** * Ajax receiver for new autoload settings */ public function ajax_add_autoload() { check_ajax_referer('vxcash-video-ajax', 'security'); if (!current_user_can('manage_options')) { die(); } $maxLoad = (int) $_POST['maxLoad']; if ($maxLoad < 0) { $maxLoad = 1; } elseif ($maxLoad > 30) { $maxLoad = 30; } $geschlecht = $_POST['geschlecht']; $darsteller = $_POST['darsteller']; $category = $_POST['category']; $tag = $_POST['tag']; $preis = $_POST['preis']; $fsk = $_POST['fsk']; $maxAlter = $_POST['maxAlter']; $settings = [ 'geschlecht' => ($darsteller === '') ? $geschlecht : '', 'darsteller' => $darsteller, 'tag' => $tag, 'preis' => $preis, 'maxAlter' => $maxAlter, 'author' => $_POST['author'], 'status' => $_POST['status'], 'fsk' => $fsk, 'category' => $category, 'maxLoad' => $maxLoad, ]; $data = [ 'type' => 'VXVIDEO', 'settings' => json_encode($settings), ]; $this->importDataprovider->saveAutoLoader($data); echo 'ok'; wp_die(); } /** * */ public function add_sub_menu_page() { add_submenu_page( $this->parent_plugin_name, 'Video Import', 'Video Import', 'manage_options', $this->plugin_name, [$this, 'display_video_admin_page'] ); } /** * */ public function display_video_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-video', plugin_dir_url(__FILE__) . 'js/vxcash-vx-video.js', ['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->getVxVideoMaxNum(); $hosts = $this->dataprovider->getHostInfo(); $token = $this->config->getVisitxApiKey(); $knownVideoIds = $this->dataprovider->getKnownVideoIds(); $have = count($knownVideoIds); $warning = ''; if ($max <= $have && $max > 0) { $warning = sprintf( '<div class="notice notice-warning"> <p> <b>Achtung:</b> Sie haben bisher %d VISIT-X Videos importiert, aber einen maximal-import von %d Videos eingestellt.<br> Es werden deshalb keine weiteren Videos automatisch importiert! Sie können trotzdem weiterhin direkt neue Videos importieren. </p> </div>', $have, $max ); } include_once __DIR__ . '/partials/vxcash-visitx-video-display.php'; } /** * @return array */ private function validateInput() { $videos = isset($_POST['videos']) ? $_POST['videos'] : []; if (!is_array($videos)) { $videos = []; } $author = (int) $_POST['author']; $status = $_POST['status']; $category = $_POST['category']; if (!in_array($status, ['draft', 'publish'], true)) { $status = 'draft'; } return [$videos, $author, $status, $category]; } public function ajax_import_videos() { check_ajax_referer('vxcash-video-ajax', 'security'); if (!current_user_can('manage_options')) { die(); } $upload = wp_upload_dir(); if (isset($upload['error']) && $upload['error'] !== false) { echo json_encode( [ 'result' => 403, 'error' => $upload['error'], ] ); } else { list($videos, $author, $status, $category) = $this->validateInput(); $success = $this->importVideoList($videos, $author, $status, $category); echo json_encode( [ 'result' => 200, 'added' => $success, ] ); } wp_die(); } public function importVideoList($videos, $author, $status, $category) { $success = array(); $upload = wp_upload_dir(); foreach ($videos as $videoData) { if (is_string($videoData)) { $videoData = stripslashes($videoData); $video = json_decode($videoData, true); } else { $video = $videoData; } set_time_limit(300); // force longer time limit $id = $video['id']; $link = $video['linkVX'] . sprintf('?w=%s&ws=%s', $this->config->getWmid(), $this->config->getVxCampaignId() . '.wp'); $title = $video['title']; $description = $video['description']; $preview = $video['preview']['url']; $content = "<a href='$link' target='_blank' rel='nofollow' class='bigVideoLink'><img src=\"$preview\" alt='$title'><span class='playbutton big'><i class=\"fa fa-playbtn-vx\"></i></span></a><p>$description</p>"; $postArr = array( 'post_author' => $author, 'post_date' => $video['released'], 'post_content' => $content, 'post_title' => $title, 'post_status' => $status, 'post_type' => Vxcash_Posttypes_Enum::VX_VIDEOS, 'post_category' => [$category], 'comment_status' => 'closed' ); $result = wp_insert_post($postArr); if ($result !== 0) { // Force type Tag, if not set by categories wp_add_post_tags($result, $video['tags']); $this->saveCustomFields($result, $video, $link); $this->dataprovider->saveVideoIdAndTitle($id, $title, $result, $status); // Check if we need to add a model page $modelId = $video['model']['id']; if (!$this->dataprovider->hasModelPage($modelId)) { $client = new Vxcash_Visitx_Graphql_Client($this->config); $model = $client->getModel($modelId); if (isset($model['id'])) { $this->saveModel($model, $author, $status); } } $success[] = $id; } } return $success; } /** * @param int $result * @param array $video * @param string $url */ private function saveCustomFields($result, $video, $url) { add_post_meta($result, 'vxcash_preview_image', $video['preview']['url']); add_post_meta($result, '_thumbnail_id', 'by_url'); add_post_meta($result, 'videoId', $video['id']); add_post_meta($result, 'duration', $video['duration']); add_post_meta($result, 'released', $video['released']); add_post_meta($result, 'ageRating', $video['ageRating']); add_post_meta($result, 'prive_value', $video['price']['value']); add_post_meta($result, 'prive_currency', $video['price']['currency']); add_post_meta($result, 'preview_image', $video['preview']['url']); add_post_meta($result, 'preview_stream', $video['previewVideo']['url']); add_post_meta($result, 'preview_stream_mimetype', $video['previewVideo']['mimeType']); add_post_meta($result, 'model_id', $video['model']['id']); add_post_meta($result, 'model_name', $video['model']['name']); add_post_meta($result, 'likes', mt_rand(20,100)); add_post_meta($result, 'dislikes', mt_rand(1,19)); add_post_meta($result, 'views', mt_rand(40,300)); add_post_meta($result, 'link', $url); } /** * @param string $localPath * @param string $basename * @param string $localUrl * @param string $result */ private function setThumbnail($localPath, $basename, $localUrl, $result) { $filename = $localPath . DIRECTORY_SEPARATOR . $basename; $filetype = wp_check_filetype($filename); // Prepare an array of post data for the attachment. $attachment = [ 'guid' => $localUrl . '/' . $basename, 'post_mime_type' => $filetype['type'], 'post_title' => sanitize_file_name($basename), 'post_content' => '', 'post_status' => 'inherit', ]; // Insert the attachment. $attach_id = wp_insert_attachment($attachment, $filename, $result); // Make sure that this file is included, as wp_generate_attachment_metadata() depends on it. require_once ABSPATH . 'wp-admin/includes/image.php'; // Generate the metadata for the attachment, and update the database record. $attach_data = wp_generate_attachment_metadata($attach_id, $filename); wp_update_attachment_metadata($attach_id, $attach_data); set_post_thumbnail($result, $attach_id); } private function saveModel(array $model, $author, $status) { set_time_limit(300); // force longer time limit $id = $model['id']; $preview = $model['avatar']['url']; $content = "<a href='[vxlinking id=$id]' target='_blank' rel='nofollow'><img src=\"$preview\" alt=''></a>"; $postArr = array( 'post_author' => $author, 'post_content' => $content, 'post_title' => $model['name'], 'post_status' => $status, 'post_type' => Vxcash_Posttypes_Enum::VX_HOSTS, 'comment_status' => 'closed' ); $result = wp_insert_post($postArr); if ($result !== 0) { // Calculate body mass index $size = $model['profile']['size']; $weight = $model['profile']['weight']; $bmi = $weight / ($size * $size / 10000); if ($bmi < 18.5) { $figur = 'Schlank'; } else if ($bmi > 25 && $bmi < 30) { $figur = 'Mollig'; } else if ($bmi > 30) { $figur = 'Dick'; } else { $figur = 'Durchschnittlich'; } wp_set_object_terms($result, $model['profile']['hairColor'], 'haarfarbe'); wp_set_object_terms($result, $figur, 'figur'); if ($model['profile']['female']) { $type = 'Frau'; } else if ($model['profile']['male']) { $type = 'Mann'; } else { $type = 'Paar'; } // Force type Tag, if not set by categories wp_add_post_tags($result, ucfirst($type)); $age = $model['profile']['age']; $now = new DateTime(); $now->sub(new DateInterval('P' . $age . 'Y')); add_post_meta($result, 'vxcash_preview_image', $model['avatar']['url']); add_post_meta($result, '_thumbnail_id', 'by_url'); add_post_meta($result, 'birthday', $now->format('Y-m-d')); add_post_meta($result, 'cupsize', $model['profile']['cupSize']); add_post_meta($result, 'weight', $weight); add_post_meta($result, 'size', $size); add_post_meta($result, 'sexuality', $model['profile']['sexuality']); add_post_meta($result, 'relationship', $model['profile']['texts']['questionRelationshipStatus']['answer']); add_post_meta($result, 'pubichair', $model['profile']['texts']['questionWomanPubicHair']['answer']); add_post_meta($result, 'gender', $type); add_post_meta($result, 'hobbies', $model['profile']['texts']['questionHobbiesText']['answer']); add_post_meta($result, 'job', $model['profile']['texts']['questionJob']['answer']); add_post_meta($result, 'lookingfor', $model['profile']['texts']['questionLookingFor']['answer']); add_post_meta($result, 'motto', $model['profile']['showText']); add_post_meta($result, 'link', do_shortcode('[vxlinking id=' . $id . ']')); add_post_meta($result, 'hostId', $id); $this->dataprovider->saveHostIdAndName($id, $model['name'], $result, $status); } } }
[-] 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]