Released version 0.0.2

parent bf0f01e3
== Sat 16 July 2022, 11:35am == == Sat 16 July 2022, 11:35am ==
- Released version 0.0.1 - Released version 0.0.1
== Mon 25 July 2022, 00:26am ==
- Released version 0.0.2
* Proper functioning Video post type page for Videos (with initial rough admin editing interface).
* use WC products only for downloads and memberships.
* Database table dedicated for Video pages.
* Support Gdrive download links through the plugin "Integrate Google Drive"
This is a very rough plan for this plugin This is a very rough plan for this plugin
based on the ideas I planned for www.sexhack.me: based on the ideas I planned for www.sexhack.me:
- Version 0.0.2:
* Proper functioning Video post type page for Videos (with initial rough admin editing interface).
* use WC products only for downloads and memberships.
* Database table dedicated for Video pages.
- Version 0.0.3: - Version 0.0.3:
* Integration of Ultimate Members plugin for user and model profiles * Integration of Ultimate Members plugin for user and model profiles
* Show thumbnail in video post list in admin * Show thumbnail in video post list in admin
* 404 Not Found page with gallery instead of WC products * 404 Not Found page with gallery instead of WC products
* Fix caching problems with "integrate google drive"
- Version 0.0.4: - Version 0.0.4:
* Upload Videos page for models * Upload Videos page for models
...@@ -21,6 +14,10 @@ based on the ideas I planned for www.sexhack.me: ...@@ -21,6 +14,10 @@ based on the ideas I planned for www.sexhack.me:
- Version 0.0.5: - Version 0.0.5:
* Better Video Page * Better Video Page
* Tag filtering/support * Tag filtering/support
* Proper installation dependencies management,
- Version 0.0.9:
* Remove integrate google drive plugin support and implement internal gdrive api
- Version 0.1.0: - Version 0.1.0:
* Fixes of all the features on the previous versions * Fixes of all the features on the previous versions
......
...@@ -72,10 +72,42 @@ if(!class_exists('SH_Admin')) { ...@@ -72,10 +72,42 @@ if(!class_exists('SH_Admin')) {
{ {
include_once SH_PLUGIN_DIR_PATH . 'includes/admin/functions-gallery.php'; include_once SH_PLUGIN_DIR_PATH . 'includes/admin/functions-gallery.php';
add_settings_section('sexhackme-gallery-settings', ' ','wp_SexHackMe\gallery_settings_section', 'sexhackme-gallery-settings'); add_settings_section('sexhackme-gallery-settings', ' ','wp_SexHackMe\gallery_settings_section', 'sexhackme-gallery-settings');
register_setting('sexhackme-gallery-settings', 'sexhack_gallery_slug'); register_setting('sexhackme-gallery-settings', 'sexhack_video_page');
register_setting('sexhackme-gallery-settings', 'sexhack_gallery_page');
register_setting('sexhackme-gallery-settings', 'sexhack_video404_page');
add_action('update_option', '\wp_SexHackMe\SH_Admin::update_gallery_slug', 10, 3);
//register_setting('sexhackme-gallery-settings', 'sexhack_gallery_slug');
} }
} }
public static function update_gallery_slug($option, $old, $new)
{
switch($option)
{
case 'sexhack_video_page':
if(!is_int($new)) break;
$page = get_post($new);
set_option('sexhack_gallery_slug', $page->post_name);
update_option('need_rewrite_flush', 1);
break;
case 'sexhack_gallery_page':
update_option('need_rewrite_flush', 1);
break;
case 'sexhack_video404_page':
update_option('need_rewrite_flush', 1);
break;
default:
break;
}
sexhack_log("UPDATE OPTIONS: ".$option." OLD $old NEW $new");
sexhack_log(get_option('neew_rewrite_flush', 'NOT SET'));
}
public static function menu() public static function menu()
{ {
......
<?php
/**
*
* This Google Drive API handler class is a custom PHP library to handle the Google Drive API calls.
*
* @class GoogleDriveApi
* @author CodexWorld
* @link http://www.codexworld.com
* @version 1.0
*/
class GoogleDriveApi {
const OAUTH2_TOKEN_URI = 'https://oauth2.googleapis.com/token';
const DRIVE_FILE_UPLOAD_URI = 'https://www.googleapis.com/upload/drive/v3/files';
const DRIVE_FILES_URI = 'https://www.googleapis.com/drive/v3/files/';
function __construct($params = array()) {
if (count($params) > 0){
$this->initialize($params);
}
}
function initialize($params = array()) {
if (count($params) > 0){
foreach ($params as $key => $val){
if (isset($this->$key)){
$this->$key = $val;
}
}
}
}
public function GetAccessToken($client_id, $redirect_uri, $client_secret, $code) {
$curlPost = 'client_id=' . $client_id . '&redirect_uri=' . $redirect_uri . '&client_secret=' . $client_secret . '&code='. $code . '&grant_type=authorization_code';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, self::OAUTH2_TOKEN_URI);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_POSTFIELDS, $curlPost);
$data = json_decode(curl_exec($ch), true);
$http_code = curl_getinfo($ch,CURLINFO_HTTP_CODE);
if ($http_code != 200) {
$error_msg = 'Failed to receieve access token';
if (curl_errno($ch)) {
$error_msg = curl_error($ch);
}else{
$error_msg = !empty($data['error']['message'])?$data['error']['message']:'';
}
throw new Exception('Error '.$http_code.': '.$error_msg);
}
return $data;
}
public function DeleteFile($access_token, $file_id, $googleOauthURL = '') {
$apiURL = self::DRIVE_FILES_URI . $file_id;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $apiURL);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json', 'Authorization: Bearer '. $access_token));
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'DELETE');
$data = json_decode(curl_exec($ch), true);
$http_code = curl_getinfo($ch,CURLINFO_HTTP_CODE);
if($http_code != 200 && $http_code != 204){
$error_msg = 'Failed to delete file.';
if (curl_errno($ch)) {
$error_msg = curl_error($ch);
}else{
$error_msg = !empty($data['error']['message'])?$data['error']['message']:'';
}
if($http_code == 401 && !empty($googleOauthURL)){
unset($_SESSION['google_access_token']);
$error_msg .= '<br/>Click to <a href="'.$googleOauthURL.'">authenticate with Google Drive</a>';
}
throw new Exception('Error '.$http_code.': '.$error_msg);
}else{
return true;
}
}
}
?>
...@@ -21,6 +21,10 @@ ...@@ -21,6 +21,10 @@
namespace wp_SexHackMe; namespace wp_SexHackMe;
use \IGD\Account;
use \IGD\App;
// Exit if accessed directly // Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) exit; if ( ! defined( 'ABSPATH' ) ) exit;
...@@ -36,6 +40,11 @@ if(!class_exists('SH_GDrive')) { ...@@ -36,6 +40,11 @@ if(!class_exists('SH_GDrive')) {
function get_download_url($file) function get_download_url($file)
{ {
$active = Account::get_active_account();
if(!$active) return $file;
$account_id = $active['id'];
if(!($file && is_string($file) && strlen($file)>3)) return $file; if(!($file && is_string($file) && strlen($file)>3)) return $file;
if ( function_exists( 'igd_fs' ) ) if ( function_exists( 'igd_fs' ) )
{ {
...@@ -52,7 +61,7 @@ if(!class_exists('SH_GDrive')) { ...@@ -52,7 +61,7 @@ if(!class_exists('SH_GDrive')) {
$parent=false; $parent=false;
$gfile=false; $gfile=false;
$success=false; $success=false;
$igd = \IGD\App::instance(); $igd = App::instance($account_id);
// Try root first // Try root first
foreach($gparts as $k => $part) foreach($gparts as $k => $part)
{ {
...@@ -92,6 +101,16 @@ if(!class_exists('SH_GDrive')) { ...@@ -92,6 +101,16 @@ if(!class_exists('SH_GDrive')) {
} else { } else {
$gdo = $igd->get_files(array('q'=> "name='{$part}"), $parent, false); $gdo = $igd->get_files(array('q'=> "name='{$part}"), $parent, false);
} }
if(!is_array($gdo) || (count($gdo) < 1) || array_key_exists('error', $gdo))
{
if($k == 0)
{
$gdo = $igd->get_files(array('q'=> "parents='' and sharedWithMe=true and '{$part}' in name"), 'shared', true);
} else {
$gdo = $igd->get_files(array('q'=> "name='{$part}"), $parent, true);
}
}
if(!is_array($gdo) || (count($gdo) < 1) || array_key_exists('error', $gdo)) break; if(!is_array($gdo) || (count($gdo) < 1) || array_key_exists('error', $gdo)) break;
$parent=false; $parent=false;
......
...@@ -94,25 +94,57 @@ if(!class_exists('SH_PostTypes')) { ...@@ -94,25 +94,57 @@ if(!class_exists('SH_PostTypes')) {
'supports' => array('title', 'thumbnail'), //'editor','excerpt','trackbacks','custom-fields','comments','revisions','author','page-attributes'), 'supports' => array('title', 'thumbnail'), //'editor','excerpt','trackbacks','custom-fields','comments','revisions','author','page-attributes'),
'taxonomies' => array(), //'category','post_tag'), // TODO Shouldn't we have a "video_type" taxonomy for VR or flat? 'taxonomies' => array(), //'category','post_tag'), // TODO Shouldn't we have a "video_type" taxonomy for VR or flat?
)); ));
$DEFAULTSLUG = get_option('sexhack_gallery_slug', 'v');
$projects_structure = '/'.$DEFAULTSLUG.'/%wooprod%/';
$rules = $wp_rewrite->wp_rewrite_rules(); $rules = $wp_rewrite->wp_rewrite_rules();
$DEFAULTSLUG = get_option('sexhack_gallery_slug', 'v');
//sexhack_log($rules);
if(!array_key_exists($DEFAULTSLUG.'/([^/]+)/?$', $rules)) { if(!array_key_exists($DEFAULTSLUG.'/([^/]+)/?$', $rules)) {
// sexhack_log("REWRITE: rules OK: ".$DEFAULTSLUG.'/([^/]+)/?$ => '.$rules[$DEFAULTSLUG.'/([^/]+)/?$']); update_option('need_rewrite_flush', 1);
//} else { sexhack_log("REWRITE: Need to add and flush our rules!");
sexhack_log("REWRITE: Need to add and flush our rules!"); }
$wp_rewrite->add_rewrite_tag("%wooprod%", '([^/]+)', "post_type=sexhack_video&wooprod="); }
$wp_rewrite->add_rewrite_tag("%videoaccess%", '([^/]+)', "videoaccess=");
$wp_rewrite->add_permastruct($DEFAULTSLUG, $projects_structure, false);
$wp_rewrite->add_permastruct($DEFAULTSLUG, $projects_structure."%videoaccess%/", false);
update_option('need_rewrite_flush', 1);
} public static function add_rewrites()
{
global $wp_rewrite;
} $DEFAULTSLUG = get_option('sexhack_gallery_slug', 'v');
sexhack_log("REWRITE: ADDING RULES");
//flush_rewrite_rules();
$pid = get_option('sexhack_video_page', false);
if($pid) $redir = "page_id=$pid";
else
$redir = "pagename=$DEFAULTSLUG";
add_rewrite_rule($DEFAULTSLUG.'/([^/]+)/([^/]+)/page/?([0-9]{1,})/?$',
'index.php?'.$redir.'&sh_video=$matches[1]&videoaccess=$matches[2]&paged=$matches[3]', 'top');
add_rewrite_rule($DEFAULTSLUG.'/([^/]+)/([^/]+)/?$',
'index.php?'.$redir.'&sh_video=$matches[1]&videoaccess=$matches[2]', 'top');
add_rewrite_rule($DEFAULTSLUG.'/([^/]+)/page/?([0-9]{1,})/?$',
'index.php?'.$redir.'&sh_video=$matches[1]&paged=$matches[2]', 'top');
add_rewrite_rule($DEFAULTSLUG.'/([^/]+)/?$',
'index.php?'.$redir.'&sh_video=$matches[1]','top');
$vg_id = get_option('sexhack_video404_page', false);
//if(is_int($vg_id) && $vg_id>0)
add_rewrite_rule($DEFAULTSLUG.'/?$',
'index.php?page_id='.strval($vg_id), 'top');
//update_option('need_rewrite_flush', 1);
sexhack_log($wp_rewrite->wp_rewrite_rules());
}
} }
} }
......
...@@ -198,6 +198,21 @@ if(!class_exists('SH_Query')) { ...@@ -198,6 +198,21 @@ if(!class_exists('SH_Query')) {
} }
public static function get_VideoFromSlug($slug)
{
global $wpdb;
$slug = $wpdb->_real_escape($slug);
$sql = "SELECT * FROM {$wpdb->prefix}".SH_PREFIX."videos WHERE slug='".$slug."'";
$dbres = $wpdb->get_results( $sql );
if(is_array($dbres) && count($dbres) > 0)
{
return new SH_Video((array)$dbres[0]);
}
return false;
}
public static function get_Video($id, $idtype='') public static function get_Video($id, $idtype='')
{ {
global $wpdb; global $wpdb;
...@@ -247,13 +262,13 @@ if(!class_exists('SH_Query')) { ...@@ -247,13 +262,13 @@ if(!class_exists('SH_Query')) {
$results = array(); $results = array();
//$sql = $wpdb->prepare("SELECT * from {$wpdb->prefix}{$prefix}videos"); //$sql = $wpdb->prepare("SELECT * from {$wpdb->prefix}{$prefix}videos");
$sql = "SELECT * FROM {$wpdb->prefix}".SH_PREFIX."videos"; $sql = "SELECT * FROM {$wpdb->prefix}".SH_PREFIX."videos";
$dbres = $wpdb->get_results( $sql ); $dbres = $wpdb->get_results( $sql, ARRAY_A );
sexhack_log($dbres);
foreach($dbres as $row) foreach($dbres as $row)
{ {
$results[] = new SH_Video($row); $results[] = new SH_Video($row);
} }
sexhack_log($results);
return $results; return $results;
......
...@@ -125,10 +125,15 @@ if(!class_exists('SH_Shortcodes')) { ...@@ -125,10 +125,15 @@ if(!class_exists('SH_Shortcodes')) {
$html = "<div class='sexhack_gallery'>"; //<h3>SexHack VideoGallery</h3>"; $html = "<div class='sexhack_gallery'>"; //<h3>SexHack VideoGallery</h3>";
if(isset($_GET['SHDEV'])) $html .= '<h3>DEVELOPEMENT MODE</h3>'; if(isset($_GET['SHDEV'])) $html .= '<h3>DEVELOPEMENT MODE</h3>';
$html .= '<ul class="products columns-4">'; $html .= '<ul class="products columns-4">';
$products = $sh_videogallery->getProducts(); $videos = $sh_videogallery->get_videos();
while( $products->have_posts() ) { foreach($videos as $video)
$products->the_post(); {
$html .= $sh_videogallery->get_video_thumb(); if($video->status == 'published')
{
$post = $video->get_post();
if($post) setup_postdata($post);
$html .= $sh_videogallery->get_video_thumb($video);
}
} }
wp_reset_postdata(); wp_reset_postdata();
$html .= "</ul></div>"; $html .= "</ul></div>";
......
...@@ -66,9 +66,9 @@ if(!class_exists('SH_Video')) { ...@@ -66,9 +66,9 @@ if(!class_exists('SH_Video')) {
'codec_public' => 'h264', 'codec_public' => 'h264',
'codec_members' => 'h264', 'codec_members' => 'h264',
'codec_premium' => 'h264', 'codec_premium' => 'h264',
'acodec_public' => 'h264', 'acodec_public' => 'AAC',
'acodec_members' => 'h264', 'acodec_members' => 'AAC',
'acodec_premium' => 'h264', 'acodec_premium' => 'AAC',
'duration_public' => false, 'duration_public' => false,
'duration_members' => false, 'duration_members' => false,
'duration_premium' => false, 'duration_premium' => false,
...@@ -87,6 +87,18 @@ if(!class_exists('SH_Video')) { ...@@ -87,6 +87,18 @@ if(!class_exists('SH_Video')) {
} }
public function get_title()
{
return $this->attributes['title'];
}
public function has_downloads()
{
if($this->download_public OR $this->download_members OR $this->download_premium) return true;
return false;
}
function setAttributes($attr, $post=false, $wcprod=false) function setAttributes($attr, $post=false, $wcprod=false)
{ {
......
...@@ -37,11 +37,11 @@ if(!class_exists('SH_VideoGallery')) { ...@@ -37,11 +37,11 @@ if(!class_exists('SH_VideoGallery')) {
// TODO What an horrible and inefficient way to cache the query result. // TODO What an horrible and inefficient way to cache the query result.
// Think about moving it in session and with a better data structure. // Think about moving it in session and with a better data structure.
$this->productlist = false; $this->videolist = false;
// Register Query Vars // Register Query Vars
add_filter("query_vars", array($this, "query_vars")); add_filter("query_vars", array($this, "query_vars"));
//add_filter('page_template', array($this, 'sexhack_video_template')); add_filter('page_template', array($this, 'sexhack_video_template'));
add_filter('archive_template', array($this, 'sexhack_video_template')); add_filter('archive_template', array($this, 'sexhack_video_template'));
add_action('pre_get_posts', array($this, 'fix_video_query'), 1, 1); add_action('pre_get_posts', array($this, 'fix_video_query'), 1, 1);
...@@ -51,31 +51,32 @@ if(!class_exists('SH_VideoGallery')) { ...@@ -51,31 +51,32 @@ if(!class_exists('SH_VideoGallery')) {
public function query_vars($vars) public function query_vars($vars)
{ {
$vars[] = 'wooprod'; $vars[] = 'sh_video';
$vars[] = 'videoaccess'; $vars[] = 'videoaccess';
return $vars; return $vars;
} }
public function sexhack_video_template($template) public function sexhack_video_template($template)
{ {
$template='video.php'; if(isset($_GET['SHDEV'])) $templ='newvideo.php';
if(isset($_GET['SHDEV'])) $template='newvideo.php'; $is_sexhack_video = get_query_var('sh_video', false);
$is_sexhack_video = get_query_var('wooprod', false);
if($is_sexhack_video ) { if($is_sexhack_video ) {
$templ='video.php';
set_query_var( 'post_type', 'sexhack_video' ); set_query_var( 'post_type', 'sexhack_video' );
if ( file_exists( plugin_dir_path(__DIR__) . '/templates/'.$template)) { if ( file_exists( plugin_dir_path(__DIR__) . '/templates/'.$templ)) {
return plugin_dir_path(__DIR__) . '/templates/'.$template; return plugin_dir_path(__DIR__) . '/templates/'.$templ;
} }
} }
return $template;
return $template;
} }
public function fix_video_query($query) public function fix_video_query($query)
{ {
if($query->get('post_type')=='sexhack_video') { if($query->get('post_type')=='sexhack_video') {
$wooprod = $query->get('wooprod', false); $sh_video = $query->get('sh_video', false);
if($wooprod) { if($sh_video) {
$query->query['post_type'] = 'sexhack_video'; $query->query['post_type'] = 'sexhack_video';
$query->set('name', esc_sql($wooprod)); $query->set('name', esc_sql($wooprod));
$query->set('post_type', 'any'); $query->set('post_type', 'any');
...@@ -84,58 +85,65 @@ if(!class_exists('SH_VideoGallery')) { ...@@ -84,58 +85,65 @@ if(!class_exists('SH_VideoGallery')) {
} }
} }
public function getProducts($vcat=false) { public function get_videos($vcat=false) {
// XXX TODO Only published videos!
if(!$this->productlist && !$vcat) $this->productlist = SH_Query::get_Products($vcat); //$this->_getProducts($vcat);
else if($vcat) return SH_Query::get_Products($vcat); //$this->_getProducts($vcat); if(!$this->videolist && !$vcat) $this->videolist = sh_get_videos($vcat); //SH_Query::get_Videos($vcat); //$this->_getProducts($vcat);
else if($vcat) return sh_get_videos($vcat); //SH_Query::get_Videos($vcat); //$this->_getProducts($vcat);
return $this->productlist; return $this->videolist;
} }
public function get_video_thumb() public function get_video_thumb($video=false)
{ {
$DEFAULTSLUG = get_option('sexhack_gallery_slug', 'v'); $DEFAULTSLUG = get_option('sexhack_gallery_slug', 'v');
$id = get_the_ID(); $post_id = get_the_ID();
$prod = wc_get_product($id); if(!$video) $video=sh_get_video_from_post($post_id);
$image = get_the_post_thumbnail($id, "medium", array("class" => "sexhack_thumbnail")); //array("class" => "alignleft sexhack_thumbnail")); if(is_numeric($video->thumbnail))
{
//$image = get_post_thumbnail_id($video->thumbnail);
//$image = wp_get_attachment_link($video->thumbnail);
$image=wp_get_attachment_image($video->thumbnail, "320x160"); // XXX Seriously fixed size?
}
else
$image = $video->thumbnail;
$hls_public = $video->hls_public;
$hls_member = $video->hls_members;
$hls_premium = $video->hls_premium;
$video_preview = $video->video_preview;
$gif_preview = $video->gif_small;
sexhack_log($video);
$hls = $prod->get_attribute("hls_public"); $categories = $video->get_categories(true);
$hls_member = $prod->get_attribute("hls_members");
$hls_premium = $prod->get_attribute("hls_premium");
$video_preview = $prod->get_attribute("video_preview");
$gif_preview = $prod->get_attribute("gif_preview");
$vr_premium = $prod->get_attribute("vr_premium");
$vr_member = $prod->get_attribute("vr_members");
$vr_public = $prod->get_attribute("vr_public");
$vr_preview = $prod->get_attribute("vr_preview");
$categories = explode(", ", html2text( wc_get_product_category_list($id)));
//print_r($categories); //print_r($categories);
$gif = $prod->get_attribute("gif_thumbnail"); $gif = $video->gif;
if(!$gif) $gif = $gif_preview;
if($gif) $image .= "<img src='$gif' class='alignleft sexhack_thumb_hover' loading='lazy' />"; if(!$gif_preview) $gif_preview = $gif;
if($gif_preview) $image .= "<img src='$gif_preview' class='alignleft sexhack_thumb_hover' loading='lazy' />";
$html = '<li class="product type-product sexhack_thumbli">'; $html = '<li class="product type-product sexhack_thumbli">';
$vurl = str_replace("/product/", "/".$DEFAULTSLUG."/", esc_url( get_the_permalink() ));
$vtitle = esc_html( get_the_title() ); $vurl = site_url().esc_url( "/".$DEFAULTSLUG."/".$video->slug )."/";
if(isset($_GET['SHDEV'])) $vurl.="?SHDEV=true";
$vtitle = $video->get_title();
$vtags=array(); $vtags=array();
$downtag =''; $downtag ='';
if((!$hls) AND (!$hls_member) AND (!$hls_premium) AND (($video_preview) OR ($vr_preview))) $vtags[] = '<label class="sexhack_vtag sexhack_preview" style="*LEFT*">preview</label>'; if((!$hls_public) AND (!$hls_member) AND (!$hls_premium) AND ($video_preview) ) $vtags[] = '<label class="sexhack_vtag sexhack_preview" style="*LEFT*">preview</label>';
if(($hls) OR ($vr_public)) $vtags[] = '<label class="sexhack_vtag sexhack_public" style="*LEFT*">public</label>'; if($hls_public) $vtags[] = '<label class="sexhack_vtag sexhack_public" style="*LEFT*">public</label>';
if(($hls_member) OR ($vr_member))$vtags[] = '<label class="sexhack_vtag sexhack_members" style="*LEFT*">members</label>'; if($hls_member)$vtags[] = '<label class="sexhack_vtag sexhack_members" style="*LEFT*">members</label>';
if(($hls_premium) OR ($vr_premium))$vtags[] = '<label class="sexhack_vtag sexhack_premium" style="*LEFT*">premium</label>'; if($hls_premium)$vtags[] = '<label class="sexhack_vtag sexhack_premium" style="*LEFT*">premium</label>';
if(count($prod->get_downloads()) > 0) $html .= '<label class="sexhack_vtag sexhack_download"">download</label>'; if($video->has_downloads()) $html .= '<label class="sexhack_vtag sexhack_download"">download</label>';
if(($vr_premium) OR ($vr_member) OR ($vr_public) OR ($vr_preview) if($video->video_type == 'VR') $html .= '<label class="sexhack_vtag sexhack_VR"">VR/3D</label>';
OR ((count($prod->get_downloads()) > 0)
AND (in_array("VR180", $categories)
OR in_array("VR360", $categories)))) $html .= '<label class="sexhack_vtag sexhack_VR"">VR/3D</label>';
$html .= "<a href=\"$vurl\" class=\"woocommerce-LoopProduct-link woocommerce-loop-product__link\">"; $html .= "<a href=\"$vurl\" class=\"woocommerce-LoopProduct-link woocommerce-loop-product__link\">";
$html .= "<div class='sexhack_thumb_cont'>".$image."</div>"; $html .= "<div class='sexhack_thumb_cont'>".$image."</div>";
......
...@@ -34,7 +34,7 @@ if(!class_exists("SH_VideoProducts")) { ...@@ -34,7 +34,7 @@ if(!class_exists("SH_VideoProducts")) {
//add_action('sh_save_video_after_query', array($this, 'sync_product_from_video'), 1, 10); //add_action('sh_save_video_after_query', array($this, 'sync_product_from_video'), 1, 10);
add_filter('video_before_save', array($this, 'sync_product_from_video')); add_filter('video_before_save', array($this, 'sync_product_from_video'));
add_action('sh_delete_video', array($this, 'delete_video_product'), 1, 10); add_action('sh_delete_video', array($this, 'delete_video_product'), 9, 1);
} }
public function delete_video_product($video) public function delete_video_product($video)
......
...@@ -54,6 +54,7 @@ function sanitize_idtype($idt=false) ...@@ -54,6 +54,7 @@ function sanitize_idtype($idt=false)
return $idt."_id"; return $idt."_id";
break; break;
case 'id': case 'id':
case 'slug':
return $idt; return $idt;
break; break;
default: default:
......
...@@ -83,6 +83,11 @@ function sh_get_video_from_product($p) ...@@ -83,6 +83,11 @@ function sh_get_video_from_product($p)
return false; return false;
} }
function sh_get_video_from_slug($slug)
{
return SH_Query::get_VideoFromSlug($slug);
}
function sh_get_categories($id=false) function sh_get_categories($id=false)
{ {
return SH_Query::get_Categories($id); return SH_Query::get_Categories($id);
......
...@@ -463,8 +463,8 @@ if(!class_exists('SexHackMe_Plugin')) { ...@@ -463,8 +463,8 @@ if(!class_exists('SexHackMe_Plugin')) {
// Check if we need to flush rewrite rules // Check if we need to flush rewrite rules
add_action('init', array($this, 'register_flush'), 10); add_action('init', array($this, 'register_flush'), 10 );
add_action('init', array($this, 'flush_rewrite'), 900); add_action('init', array($this, 'flush_rewrite'), 11);
// Enqueue scripts on the front end side. Priority 200 because of WooCommerce. // Enqueue scripts on the front end side. Priority 200 because of WooCommerce.
add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_front_end_scripts' ), 200 ); add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_front_end_scripts' ), 200 );
...@@ -477,6 +477,7 @@ if(!class_exists('SexHackMe_Plugin')) { ...@@ -477,6 +477,7 @@ if(!class_exists('SexHackMe_Plugin')) {
// Initialize Custom post_types // Initialize Custom post_types
add_action( 'init', array( 'wp_SexHackMe\SH_PostTypes', 'init')); add_action( 'init', array( 'wp_SexHackMe\SH_PostTypes', 'init'));
add_action( 'sh_rewrite_flushed', array( 'wp_SexHackMe\SH_PostTypes', 'add_rewrites') );
// Initialize shortcodes // Initialize shortcodes
add_action( 'init', array( 'wp_SexHackMe\SH_Shortcodes', 'init' ) ); add_action( 'init', array( 'wp_SexHackMe\SH_Shortcodes', 'init' ) );
...@@ -531,6 +532,7 @@ if(!class_exists('SexHackMe_Plugin')) { ...@@ -531,6 +532,7 @@ if(!class_exists('SexHackMe_Plugin')) {
public function register_flush() public function register_flush()
{ {
register_setting('sexhackme-settings', 'need_rewrite_flush'); register_setting('sexhackme-settings', 'need_rewrite_flush');
register_setting('sexhackme-settings', 'rewrite_flush_done');
} }
public function flush_rewrite() public function flush_rewrite()
...@@ -538,8 +540,10 @@ if(!class_exists('SexHackMe_Plugin')) { ...@@ -538,8 +540,10 @@ if(!class_exists('SexHackMe_Plugin')) {
if( get_option('need_rewrite_flush')) if( get_option('need_rewrite_flush'))
{ {
sexhack_log("FLUSHING REWRITE RULES"); sexhack_log("FLUSHING REWRITE RULES");
flush_rewrite_rules(false); //flush_rewrite_rules(false);
flush_rewrite_rules();
update_option('need_rewrite_flush', 0); update_option('need_rewrite_flush', 0);
do_action('sh_rewrite_flushed');
} }
} }
...@@ -644,13 +648,12 @@ if(!class_exists('SexHackMe_Plugin')) { ...@@ -644,13 +648,12 @@ if(!class_exists('SexHackMe_Plugin')) {
} }
//if(isset($_GET['SHDEV'])) {
// DEBUG REWRITE RULES
if( WP_DEBUG === true ){ if( WP_DEBUG === true ){
// only matched? // only matched?
//add_action("the_post", 'wp_SexHackMe\debug_rewrite_rules'); //add_action("the_post", 'wp_SexHackMe\debug_rewrite_rules');
//sexhack_log("REQUEST: ".$_SERVER['REQUEST_URI']." QUERY: ".$_SERVER['QUERY_STRING']. "POST:"); sexhack_log("REQUEST: ".$_SERVER['REQUEST_URI']." QUERY: ".$_SERVER['QUERY_STRING']. "POST:");
//sexhack_log($_POST); sexhack_log($_POST);
} }
......
...@@ -29,10 +29,50 @@ if ( ! defined( 'ABSPATH' ) ) exit; ...@@ -29,10 +29,50 @@ if ( ! defined( 'ABSPATH' ) ) exit;
<table class="form-table"> <table class="form-table">
<tr align="top"> <tr align="top">
<td> <td>
<label>Slug for gallery</label> <select id="sexhack_video_page" name="sexhack_video_page" class="widefat">
<input type="text" name="sexhack_gallery_slug" value="<?php echo get_option( 'sexhack_gallery_slug', "v" ) ?>" /> <option value="-1">Choose...</option>
<?php
$opt=get_option("sexhack_video_page");
foreach( get_pages() as $page ) {
echo '<option value="' . esc_attr( $page->ID ) . '"';
if ($opt == $page->ID) { echo "selected";}
echo '>' . esc_html( $page->post_title ) . ' ( ID: ' . esc_attr( $page->ID ) . ')' . '</option>';
} ?>
</select>
<p class="description">Select Video page</p>
</td> </td>
</tr> </tr>
<tr align="top">
<td>
<select id="sexhack_gallery_page" name="sexhack_gallery_page" class="widefat">
<option value="-1">Choose...</option>
<?php
$opt=get_option("sexhack_gallery_page");
foreach( get_pages() as $page ) {
echo '<option value="' . esc_attr( $page->ID ) . '"';
if ($opt == $page->ID) { echo "selected";}
echo '>' . esc_html( $page->post_title ) . ' ( ID: ' . esc_attr( $page->ID ) . ')' . '</option>';
} ?>
</select>
<p class="description">Select Gallery page</p>
</td>
</tr>
<tr align="top">
<td>
<select id="sexhack_video404_page" name="sexhack_video404_page" class="widefat">
<option value="-1">Choose...</option>
<?php
$opt=get_option("sexhack_video404_page");
foreach( get_pages() as $page ) {
echo '<option value="' . esc_attr( $page->ID ) . '"';
if ($opt == $page->ID) { echo "selected";}
echo '>' . esc_html( $page->post_title ) . ' ( ID: ' . esc_attr( $page->ID ) . ')' . '</option>';
} ?>
</select>
<p class="description">Select Gallery page</p>
</td>
</tr>
</table> </table>
<?php submit_button(); ?> <?php submit_button(); ?>
</form> </form>
......
...@@ -19,9 +19,24 @@ ...@@ -19,9 +19,24 @@
* along with SexHackMe Wordpress Plugin. If not, see <https://www.gnu.org/licenses/>. * along with SexHackMe Wordpress Plugin. If not, see <https://www.gnu.org/licenses/>.
*/ */
namespace wp_SexHackMe;
// Exit if accessed directly // Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) exit; if ( ! defined( 'ABSPATH' ) ) exit;
sexhack_log("PORCALAPUPAZZA");
sexhack_log(get_query_var('sh_video', 'NONEEEEEEEEEEEEEE!!!'));
$sh_video = get_query_var('sh_video', false);
if(!$sh_video) {
wp_redirect(get_permalink(get_option('sexhack_video404_page', '0')));
exit ;
}
$video = sh_get_video_from_slug($sh_video);
get_header(); ?> get_header(); ?>
<div id="primary" class="content-area"> <div id="primary" class="content-area">
...@@ -31,7 +46,7 @@ get_header(); ?> ...@@ -31,7 +46,7 @@ get_header(); ?>
<header class="page-header"> <header class="page-header">
<?php <?php
//the_archive_title( '<h1 class="page-title">', '</h1>' ); //the_archive_title( '<h1 class="page-title">', '</h1>' );
the_archive_description( '<div class="taxonomy-description">', '</div>' ); // XXX Check it? what it does? //the_archive_description( '<div class="taxonomy-description">', '</div>' ); // XXX Check it? what it does
?> ?>
</header><!-- .page-header --> </header><!-- .page-header -->
...@@ -47,54 +62,48 @@ get_header(); ?> ...@@ -47,54 +62,48 @@ get_header(); ?>
$htmltags = '<span><b>TAGS: </b></span>'; $htmltags = '<span><b>TAGS: </b></span>';
$tags = get_the_terms( get_the_ID(), 'product_tag' ); $tags = $video->get_tags();
if ( ! empty( $tags ) && ! is_wp_error( $tags ) ) if ( ! empty( $tags ) && ! is_wp_error( $tags ) )
{ {
foreach($tags as $tag) { foreach($tags as $tag) {
$htmltags.="<span>#".$tag->name . '</span> '; $htmltags.="<span>#".$tag->tag . '</span> ';
} }
} }
$videoslug = get_option('sexhack_gallery_slug', 'v'); $videoslug = get_option('sexhack_gallery_slug', 'v');
$vurl = str_replace("/product/", "/".$videoslug."/", esc_url( get_the_permalink() )); $vurl = "/".$videoslug."/".$sh_video."/";
$prod = wc_get_product(get_the_ID()); $prod = $video->get_product();
$hls = $prod->get_attribute("hls_public");
$hls_members = $prod->get_attribute("hls_members"); $hls_public = $video->hls_public;
$hls_premium = $prod->get_attribute("hls_premium"); $hls_members = $video->hls_members;
$video_preview = $prod->get_attribute("video_preview"); $hls_premium = $video->hls_premium;
$gif_preview = $prod->get_attribute("gif_preview"); $video_preview = $video->video_preview;
$vr_premium = $prod->get_attribute("vr_premium"); $gif_preview = $video->gif_small;
$vr_members = $prod->get_attribute("vr_members"); $gif = $video->gif;
$vr_public = $prod->get_attribute("vr_public");
$vr_preview = $prod->get_attribute("vr_preview");
$categories = explode(", ", wp_SexHackMe\html2text( wc_get_product_category_list($id))); $categories = $video->get_categories(true);
if(($hls) AND wp_SexHackMe\starts_with('/', $hls)) $hls = site_url().$hls; if(($hls_public) AND starts_with('/', $hls_public)) $hls_public = site_url().$hls_public;
if(($hls_members) AND wp_SexHackMe\starts_with('/', $hls_members)) $hls_members = site_url().$hls_members; if(($hls_members) AND starts_with('/', $hls_members)) $hls_members = site_url().$hls_members;
if(($hls_premium) AND wp_SexHackMe\starts_with('/', $hls_premium)) $hls_premium = site_url().$hls_premium; if(($hls_premium) AND starts_with('/', $hls_premium)) $hls_premium = site_url().$hls_premium;
if(($video_preview) AND wp_SexHackMe\starts_with('/', $video_preview)) $video_preview = site_url().$video_preview; if(($video_preview) AND starts_with('/', $video_preview)) $video_preview = site_url().$video_preview;
if(($vr_public) AND wp_SexHackMe\starts_with('/', $vr_public)) $vr_public = site_url().$vr_public;
if(($vr_members) AND wp_SexHackMe\starts_with('/', $vr_members)) $vr_members = site_url().$vr_members; $t = $video->thumbnail;
if(($vr_premium) AND wp_SexHackMe\starts_with('/', $vr_premium)) $vr_premium = site_url().$vr_premium; if(is_numeric($t) )
if(($vr_preview) AND wp_SexHackMe\starts_with('/', $vr_preview)) $vr_preview = site_url().$vr_preview; $thumb = wp_get_attachment_url($video->thumbnail);
else
$thumb = wp_get_attachment_url($prod->get_image_id()); $thumb = $t;
$avail = array(); $avail = array();
$tabtext = array('subscribers' => 'Subscribers', $tabtext = array('subscribers' => 'Subscribers',
'vrsub' => 'Subscribers',
'members' => 'Members', 'members' => 'Members',
'vrmem' => 'Members',
'vrpub' => 'Public',
'public' => 'Public'); 'public' => 'Public');
if($hls || $video_preview ) $avail[] = 'public'; if($hls_public || $video_preview ) $avail[] = 'public';
if($vr_public || $vr_preview) $avail[] = 'vrpub';
if($hls_members) $avail[] = 'members'; if($hls_members) $avail[] = 'members';
if($vr_members) $avail[] = 'vrmem';
if($hls_premium) $avail[] = 'subscribers'; if($hls_premium) $avail[] = 'subscribers';
if($vr_premium) $avail[] = 'vrsub';
$videoaccess = get_query_var('videoaccess', false); $videoaccess = get_query_var('videoaccess', false);
if($videoaccess && in_array($videoaccess, $avail)) if($videoaccess && in_array($videoaccess, $avail))
...@@ -103,32 +112,26 @@ get_header(); ?> ...@@ -103,32 +112,26 @@ get_header(); ?>
} }
else else
{ {
if(wp_SexHackMe\user_has_premium_access()) { if(user_has_premium_access()) {
if($hls_premium) $tab = 'subscribers'; if($hls_premium) $tab = 'subscribers';
elseif($vr_premium) $tab = 'vrsub';
elseif($hls_members) $tab = 'members'; elseif($hls_members) $tab = 'members';
elseif($vr_members) $tab = 'vrmem';
elseif($vr_public || $vr_preview) $tab = 'vrpub';
else $tab = 'public'; else $tab = 'public';
} }
elseif(wp_SexHackMe\user_has_member_access()) // free membership elseif(user_has_member_access()) // free membership
{ {
if($hls_members) $tab = 'members'; if($hls_members) $tab = 'members';
elseif($vr_members) $tab = 'vrmem';
elseif($vr_public) $tab = 'vrpub';
else $tab = 'public'; else $tab = 'public';
} }
else // public else // public
{ {
if($vr_public) $tab = 'vrpub'; $tab = 'public';
else $tab = 'public';
} }
} }
?> ?>
<article id="post-<?php echo get_the_ID();?>" class="post-<?php echo get_the_ID();?> product type-product"> <article id="post-<?php echo get_the_ID();?>" class="post-<?php echo get_the_ID();?> product type-product">
<header class="entry-header"> <header class="entry-header">
<h2 class="alpha entry-title sexhack_video_title"> <h2 class="alpha entry-title sexhack_video_title">
<?php the_title(); echo " (".$tabtext[$tab]." version)"; ?> <?php echo $video->get_title(); echo " (".$tabtext[$tab]." version)"; ?>
</h2> </h2>
</header><!-- .entry-header --> </header><!-- .entry-header -->
<div class="sexhack-video-container"> <div class="sexhack-video-container">
...@@ -140,11 +143,10 @@ get_header(); ?> ...@@ -140,11 +143,10 @@ get_header(); ?>
{ {
case "members": case "members":
case "vrmem": if(user_has_member_access())
if(wp_SexHackMe\user_has_member_access())
{ {
if($hls_members) echo do_shortcode( "[sexhls url=\"".$hls_members."\" posters=\"".$thumb."\"]" ); if($hls_members && $video->video_type=="VR" ) echo do_shortcode( "[sexvideo url=\"".$hls_members."\" posters=\"".$thumb."\"]" );
else if($vr_members) echo do_shortcode( "[sexvideo url=\"".$vr_members."\" posters=\"".$thumb."\"]" ); else if($hls_members) echo do_shortcode( "[sexhls url=\"".$hls_members."\" posters=\"".$thumb."\"]" );
else echo "<h3 class='sexhack-videonotify'>SOMETHING WENT BADLY WRONG. I CAN'T FIND THE VIDEO</h3>"; else echo "<h3 class='sexhack-videonotify'>SOMETHING WENT BADLY WRONG. I CAN'T FIND THE VIDEO</h3>";
} }
else else
...@@ -157,11 +159,10 @@ get_header(); ?> ...@@ -157,11 +159,10 @@ get_header(); ?>
break; break;
case "subscribers": case "subscribers":
case "vrsub": if(user_has_premium_access())
if(wp_SexHackMe\user_has_premium_access())
{ {
if($hls_premium) echo do_shortcode( "[sexhls url=\"".$hls_premium."\" posters=\"".$thumb."\"]" ); if($hls_premium && $video->video_type=="VR") echo do_shortcode( "[sexvideo url=\"".$hlt_premium."\" posters=\"".$thumb."\"]" );
else if($vr_premium) echo do_shortcode( "[sexvideo url=\"".$vr_premium."\" posters=\"".$thumb."\"]" ); else if($hls_premium) echo do_shortcode( "[sexhls url=\"".$hls_premium."\" posters=\"".$thumb."\"]" );
else echo "<h3 class='sexhack-videonotify'>SOMETHING WENT BADLY WRONG. I CAN'T FIND THE VIDEO</h3>"; else echo "<h3 class='sexhack-videonotify'>SOMETHING WENT BADLY WRONG. I CAN'T FIND THE VIDEO</h3>";
} }
...@@ -173,12 +174,9 @@ get_header(); ?> ...@@ -173,12 +174,9 @@ get_header(); ?>
} }
break; break;
case "vrpub":
default: // public too! default: // public too!
if($hls) echo do_shortcode( "[sexhls url=\"".$hls."\" posters=\"".$thumb."\"]" ); if($hls_public && $video->video_type=='VR') echo do_shortcode( "[sexvideo url=\"".$hls_public."\" posters=\"".$thumb."\"]" );
else if($vr_public) echo do_shortcode( "[sexvideo url=\"".$vr_public."\" posters=\"".$thumb."\"]" ); else if($hls_public) echo do_shortcode( "[sexhls url=\"".$hls."\" posters=\"".$thumb."\"]" );
else if($video_preview) echo '<video src='."'$video_preview'".' controls autoplay muted playsinline loop poster="'.$thumb.'"></video>';
else if($vr_preview) echo do_shortcode( "[sexvideo url=\"".$vr_preview."\" posters=\"".$thumb."\"]" );
else if($gif_preview) echo '<img class="sexhack_videopreview" src="'.$gif_preview.'" loading="lazy"></img>'; else if($gif_preview) echo '<img class="sexhack_videopreview" src="'.$gif_preview.'" loading="lazy"></img>';
else echo '<img class="sexhack_videopreview" src="'.$thumb.'" loading="lazy"></img>'; else echo '<img class="sexhack_videopreview" src="'.$thumb.'" loading="lazy"></img>';
} }
...@@ -186,7 +184,6 @@ get_header(); ?> ...@@ -186,7 +184,6 @@ get_header(); ?>
else // if(in_array($tab, $avail)) else // if(in_array($tab, $avail))
{ {
if($video_preview) echo '<video src='."'$video_preview'".' controls autoplay muted playsinline loop poster="'.$thumb.'"></video>'; if($video_preview) echo '<video src='."'$video_preview'".' controls autoplay muted playsinline loop poster="'.$thumb.'"></video>';
else if($vr_preview) echo do_shortcode( "[sexvideo url=\"".$vr_preview."\" posters=\"".$thumb."\"]" );
else if($gif_preview) echo '<img class="sexhack_videopreview" src="'.$gif_preview.'" loading="lazy"></img>'; else if($gif_preview) echo '<img class="sexhack_videopreview" src="'.$gif_preview.'" loading="lazy"></img>';
else echo '<img class="sexhack_videopreview" src="'.$thumb.'" loading="lazy"></img>'; else echo '<img class="sexhack_videopreview" src="'.$thumb.'" loading="lazy"></img>';
?> ?>
...@@ -221,7 +218,7 @@ get_header(); ?> ...@@ -221,7 +218,7 @@ get_header(); ?>
echo $htmltags; echo $htmltags;
?> ?>
<h3><a href="<?php echo get_the_permalink(); ?>">Download the full lenght hi-res version of this video</a><h3> <h3><a href="<?php echo get_permalink($video->product_id); ?>">Download the full lenght hi-res version of this video</a><h3>
<hr> <hr>
<?php <?php
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment