Continue developement of video page

parent d38c3330
......@@ -31,36 +31,30 @@ if(!class_exists('SH_MetaBox')) {
public static function add_video_metaboxes($post=false)
{
add_meta_box( 'sh-mbox-videodescription', 'Video Description', array(__CLASS__, '::load_metabox_videodescription'), 'sexhack_video', 'normal','default');
add_meta_box( 'sh-mbox-video', 'Video locations', array( __CLASS__, '::load_metabox_videolocations' ), 'sexhack_video', 'normal', 'default' );
//remove_meta_box( 'postimagediv', 'sexhack_video', 'side' );
add_meta_box( 'sh-mbox-videodescription', 'Videos', 'wp_SexHackMe\SH_MetaBox::load_metabox_video', 'sexhack_video', 'normal','default');
remove_meta_box( 'postimagediv', 'sexhack_video', 'side' );
add_meta_box('postimagediv', 'Video Thumbnail', 'post_thumbnail_meta_box', 'sexhack_video', 'side', 'default');
}
public static function load_metabox_videodescription($post)
public static function load_metabox_video($post)
{
wp_nonce_field('video_description_nonce','sh_video_description_nonce');
$value = get_post_meta( $post->ID, 'video_description', true );
echo '<textarea style="width:100%" id="video_description" name="video_description">' . esc_attr( $value ) . '</textarea>';
}
public static function load_metabox_videolocations($post) //($object, $box)
{
wp_nonce_field( 'global_notice_nonce', 'global_notice_nonce' );
$value = get_post_meta( $post->ID, '_global_notice', true );
$video = sh_get_video_from_post($post->ID);
if(!$video) $video = new SH_Video();
$video->post_id = $post->ID;
$video->post = $post;
sh_get_template("admin/metabox_video.php", array('video' => $video, 'post' => $post));
echo '<textarea style="width:100%" id="global_notice" name="global_notice">' . esc_attr( $value ) . '</textarea>';
}
public static function save_meta_box_data($post_id)
{
return $this->save_sexhack_video_meta_box_data($post_id);
return SH_MetaBox::save_sexhack_video_meta_box_data($post_id);
}
public function save_sexhack_video_meta_box_data( $post_id )
public static function save_sexhack_video_meta_box_data( $post_id )
{
......@@ -95,15 +89,27 @@ if(!class_exists('SH_MetaBox')) {
return;
}
$video = sh_get_video_from_post($post_id);
if(!$video) $video = new SH_Video();
$video->post_id = $post_id;
$post = $video->get_post();
$video->title = $post->post_title;
$video->slug = $post->post_name;
sexhack_log($post);
// Sanitize user input.
$my_data = sanitize_text_field( $_POST['video_description'] );
$video->description = sanitize_text_field( $_POST['video_description'] );
// Update the meta field in the database.
update_post_meta( $post_id, 'video_description', $my_data );
//update_post_meta( $post_id, 'video_description', $my_data );
sh_save_video($video);
}
}
add_action('save_post', array('wp_SexHackMe\SH_MetaBox', '::save_meta_box_data' ));
add_action('save_post', 'wp_SexHackMe\SH_MetaBox::save_meta_box_data' );
}
......
......@@ -90,7 +90,7 @@ if(!class_exists('SH_PostTypes')) {
'query_var' => true,
'has_archive' => true,
'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%/';
......
......@@ -28,8 +28,97 @@ if ( ! defined( 'ABSPATH' ) ) exit;
if(!class_exists('SH_Query')) {
class SH_Query
{
public static function save_Video($video)
{
global $wpdb;
if(is_object($video))
{
$fieldsarray = $video->get_sql_array();
$fields = "";
$keys = "";
$values = "";
$count=0;
foreach($fieldsarray as $k => $v)
{
$v = $wpdb->_real_escape($v);
$adds = "\n";
$fields .= $k." = '$v'";
$keys .= $k;
$values .= "'$v'";
if($count < count($fieldsarray)-1) $adds = ",\n";
$fields .= $adds;
$keys .= $adds;
$values .= $adds;
$count++;
}
if($video->id || (is_long($video->id) && $video->id > 0))
{
// Save an already existing video entry
$sql = "UPDATE {$wpdb->prefix}".SH_PREFIX."videos SET
{$fields}
WHERE
id = {$video->id};";
$wpdb->query( $sql );
}
else
{
// Save a new video
$sql = "INSERT INTO {$wpdb->prefix}".SH_PREFIX."videos
({$keys})
VALUES
({$values});";
$wpdb->query( $sql );
$video->id = $wpdb->insert_id;
}
return $video;
}
}
public static function get_Video($id, $idtype='')
{
global $wpdb;
switch($idtype)
{
case "product":
case "post":
$idtype=$idtype."_id";
break;
default:
$idtype="id";
}
// TODO sanitize query
$sql = "SELECT * from {$wpdb->prefix}".SH_PREFIX."videos WHERE {$idtype}=".intval($id);
$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_Videos($vcat=false)
{
global $wpdb;
// XXX TODO This filtering using a $_GET in the query class is SHIT.
// Move it in the gallery interface, and pass a fucking argument
$filter=false;
if(isset($_GET['sexhack_vselect']))
{
......@@ -44,8 +133,36 @@ if(!class_exists('SH_Query')) {
}
}
$queryarr = array(
$result = array();
//$sql = $wpdb->prepare("SELECT * from {$wpdb->prefix}{$prefix}videos");
$sql = "SELECT * from {$wpdb->prefix}".SH_PREFIX."videos";
$dbres = $wpdb->get_results( $sql );
foreach($dbres as $row)
{
$result[] = new SH_Video($row);
}
}
public static function get_Products($vcat=false)
{
$filter=false;
if(isset($_GET['sexhack_vselect']))
{
switch($_GET['sexhack_vselect'])
{
case 'premium':
case 'members':
case 'public':
case 'preview':
$filter=$_GET['sexhack_vselect'];
break;
}
}
$queryarr = array(
/*
* We're limiting the results to 100 products, change this as you
* see fit. -1 is for unlimted but could introduce performance issues.
......@@ -103,8 +220,9 @@ if(!class_exists('SH_Query')) {
//sexhack_log(var_dump($products));
return $products;
}
}
}
......
......@@ -123,6 +123,7 @@ if(!class_exists('SH_Shortcodes')) {
), $attr));
$html = "<div class='sexhack_gallery'>"; //<h3>SexHack VideoGallery</h3>";
if(isset($_GET['SHDEV'])) $html .= '<h3>DEVELOPEMENT MODE</h3>';
$html .= '<ul class="products columns-4">';
$products = $sh_videogallery->getProducts();
while( $products->have_posts() ) {
......
<?php
/**
* Copyright: 2022 (c)Franco (nextime) Lanza <franco@nexlab.it>
* License: GNU/GPL version 3.0
*
* This file is part of SexHackMe Wordpress Plugin.
*
* SexHackMe Wordpress Plugin is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published
* by the Free Software Foundation, either version 3 of the License,
* or (at your option) any later version.
*
* SexHackMe Wordpress Plugin is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with SexHackMe Wordpress Plugin. If not, see <https://www.gnu.org/licenses/>.
*/
namespace wp_SexHackMe;
// Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) exit;
if(!class_exists('SH_Video')) {
class SH_Video
{
protected $attributes = array(
'id' => 0,
'user_id' => 0,
'post_id' => 0,
'product_id' => 0,
'status' => 'creating',
'private' => 'N',
'visible' => 'Y',
'title' => '',
'description' => '',
'uploaded' => false,
'slug' => '',
'price' => 0,
'video_type' => 'FLAT',
'vr_projection' => 'VR180_LR',
'preview' => false,
'hls_public' => false,
'hls_members' => false,
'hls_premium' => false,
'thumbnail' => false,
'gif' => false,
'download_public' => false,
'download_members' => false,
'download_premium' => false,
'size_public' => false,
'size_members' => false,
'size_premium' => false,
'format_public' => false,
'format_members' => false,
'format_premium' => false,
'duration_public' => false,
'duration_members' => false,
'duration_premium' => false,
'resolution_public' => false,
'resolution_members' => false,
'resolution_premium' => false,
'views_public' => 0,
'views_members' => 0,
'views_premium' => 0,
'sells' => 0
);
public function __construct($attr=false)
{
$this->attributes['uploaded'] = date('Y-m-d H:i:s');
if(is_array($attr)) $this->setAttributes($attr);
}
function setAttributes($attr, $post=false, $wcprod=false)
{
// XXX TODO Validate the $attr array
if(!is_array($attr)) return false;
foreach($attr as $k => $v)
{
if(array_key_exists($k, $this->attributes)) $this->attributes[$k] = $v;
}
if($post && is_object($post)) $this->__set('post', $post);
else if($post && is_array($post) && (count($post) > 0) && is_object($post[0])) $this->__set('post', $post[0]);
//else if(array_key_exists('post_id', $attributes) && is_integer($attributes['post_id']) && ($attributes['post_id'] > 0))
// $this->__set('post', get_post($attributes['post_id']);
if($wcprod && is_object($wcprod)) $this->__set('product', $wcprod);
else if($wcprod && is_array($wcprod) && (count($wcprod) > 0) && is_object($wcprod[0])) $this->__set('product', $wcprod[0]);
//else if(array_key_exists('product_id', $attributes) && is_integer($attributes['product_id']) && ($attributes['product_id'] > 0))
// $this->__set('product', wc_get_product($attributes['product_id']);
}
public function __get($key){
if (!array_key_exists($key, $this->attributes)) return null;
return $this->attributes[$key];
}
public function __set($key, $value=false)
{
$this->attributes[$key] = $value;
}
public function __unset($key)
{
unset($this->attributes[$key]);
}
public function __isset($key)
{
return isset($this->attributes['key']);
}
public function get_post()
{
if(isset($this->attributes['post'])) return $this->post;
if(array_key_exists('post_id', $this->attributes))
{
$this->__set('post', get_post($this->post_id));
return $this->post;
}
return false;
}
public function get_product()
{
if(isset($this->attributes['product'])) return $this->product;
if(array_key_exists('product', $this->attributes))
{
$this->__set('product', wc_get_product($this->post_id));
return $this->product;
}
return false;
}
// Repopulate the object from $post or $post->ID
public function update_video_from_post($p)
{
$post = false;
if(is_object($p)) $post = $p;
else if(is_integer($p)) $post = get_post($post);
if($post)
{
$this->post = clone $post;
}
return false;
}
public function get_sql_array()
{
$r = array();
foreach($this->attributes as $k => $v)
{
if(($v) && !in_array($k, array('post', 'product')) ) $r[$k] = $v;
}
return $r;
}
}
$GLOBALS['sh_video'] = new SH_Video();
do_action('sh_video_ready');
}
?>
......@@ -59,7 +59,7 @@ if(!class_exists('SH_VideoGallery')) {
public function sexhack_video_template($template)
{
$template='video.php';
if(isset($_GET['SEXHACKDEBUG'])) $template='newvideo.php';
if(isset($_GET['SHDEV'])) $template='newvideo.php';
$is_sexhack_video = get_query_var('wooprod', false);
if($is_sexhack_video ) {
set_query_var( 'post_type', 'sexhack_video' );
......@@ -86,8 +86,8 @@ if(!class_exists('SH_VideoGallery')) {
public function getProducts($vcat=false) {
if(!$this->productlist && !$vcat) $this->productlist = SH_Query::get_Videos($vcat); //$this->_getProducts($vcat);
else if($vcat) return SH_Query::get_Videos($vcat); //$this->_getProducts($vcat);
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);
return $this->productlist;
......
......@@ -33,6 +33,35 @@ function sh_get_template($tmpl, $args=array())
}
function sh_save_video($video)
{
return SH_Query::save_Video($video);
}
function sh_get_videos($vcat=false)
{
return SH_Query::get_Videos($vcat);
}
function sh_get_video($id)
{
return SH_Query::get_Video($id);
}
function sh_get_video_from_post($p)
{
if(is_int($p) && $p > 0) return SH_Query::get_Video($p, 'post');
else if(is_object($p)) return SH_Query::get_Video($p->ID, 'post');
return false;
}
function sh_get_video_from_product($p)
{
if(is_int($p) and $p > 0) return SH_Query::get_Video($p, 'product');
else if(is_object($p)) return SH_Query::get_Video($p->get_id(), 'product');
return false;
}
function sh_get_subscription_plans()
{
return pms_get_subscription_plans();
......
......@@ -54,6 +54,7 @@ if(!class_exists('SexHackMe_Plugin')) {
// The prefix of the plugin
$this->prefix = 'sh_';
define( 'SH_PREFIX', $this->prefix);
// Install needed components on plugin activation
register_activation_hook( __FILE__, array( $this, 'install' ) );
......@@ -166,7 +167,7 @@ if(!class_exists('SexHackMe_Plugin')) {
$sql_query = "CREATE TABLE {$wpdb->prefix}{$this->prefix}videos (
id bigint(20) AUTO_INCREMENT NOT NULL,
user_id bigint(20) NOT NULL,
post_id biting(20) NOT NULL,
post_id bigint(20) NOT NULL,
product_id bigint(20) NOT NULL DEFAULT '0',
status ENUM('creating', 'uploading', 'queue', 'processing', 'ready','published','error') NOT NULL DEFAULT 'creating',
private ENUM('Y', 'N') NOT NULL DEFAULT 'N',
......@@ -195,7 +196,7 @@ if(!class_exists('SexHackMe_Plugin')) {
format_premium varchar(256) DEFAULT NULL,
duration_public varchar(256) DEFAULT NULL,
duration_members varchar(256) DEFAULT NULL,
duration_premiunt varchar(256) DEFAULT NULL,
duration_premium varchar(256) DEFAULT NULL,
resolution_public varchar(256) DEFAULT NULL,
resolution_members varchar(256) DEFAULT NULL,
resolution_premium varchar(256) DEFAULT NULL,
......@@ -298,6 +299,22 @@ if(!class_exists('SexHackMe_Plugin')) {
}
private function file_include($file)
{
if(isset($_GET['SHDEV']) || isset($_POST['SHDEV']))
{
$devar = explode('/', $file);
$devar[count($devar)-1] = 'dev-'.$devar[count($devar)-1];
$devfile = implode('/', $devar);
if (file_exists( SH_PLUGIN_DIR_PATH . $devfile ))
return include_once SH_PLUGIN_DIR_PATH . $devfile;
}
if(file_exists( SH_PLUGIN_DIR_PATH . $file ) )
return include_once SH_PLUGIN_DIR_PATH . $file;
return false;
}
/*
* Function to include the files needed
*
......@@ -305,91 +322,69 @@ if(!class_exists('SexHackMe_Plugin')) {
public function include_dependencies()
{
/*
if( file_exists( SH_PLUGIN_DIR_PATH . 'includes/' ) )
include_once( SH_PLUGIN_DIR_PATH . 'includes/' );
*/
/* Manage Plugin Dependencies */
if( file_exists( SH_PLUGIN_DIR_PATH . 'includes/class-tgm-plugin-activation.php' ) )
include_once SH_PLUGIN_DIR_PATH . 'includes/class-tgm-plugin-activation.php';
$this->file_include('includes/class-tgm-plugin-activation.php');
/* Utils */
if( file_exists( SH_PLUGIN_DIR_PATH . 'includes/functions-utils.php' ) )
include_once SH_PLUGIN_DIR_PATH . 'includes/functions-utils.php';
$this->file_include('includes/functions-utils.php');
/* Core functions */
if( file_exists( SH_PLUGIN_DIR_PATH . 'includes/functions-core.php' ) )
include_once SH_PLUGIN_DIR_PATH . 'includes/functions-core.php';
$this->file_include('includes/functions-core.php');
/* Custom Post Types declarations */
if( file_exists( SH_PLUGIN_DIR_PATH . 'includes/class-post_types.php') )
include_once SH_PLUGIN_DIR_PATH . 'includes/class-post_types.php';
$this->file_include('includes/class-post_types.php');
/* Meta Boxes */
if( file_exists( SH_PLUGIN_DIR_PATH . 'includes/class-meta-box.php') )
include_once SH_PLUGIN_DIR_PATH . 'includes/class-meta-box.php';
$this->file_include('includes/class-meta-box.php');
/* DB Query */
if( file_exists( SH_PLUGIN_DIR_PATH . 'includes/class-query.php') )
include_once SH_PLUGIN_DIR_PATH . 'includes/class-query.php';
$this->file_include('includes/class-query.php');
/* Admin interface */
if( file_exists( SH_PLUGIN_DIR_PATH . 'includes/class-admin.php' ) )
include_once SH_PLUGIN_DIR_PATH . 'includes/class-admin.php';
$this->file_include('includes/class-admin.php');
/* Hooks compatibility/translation */
if( file_exists( SH_PLUGIN_DIR_PATH . 'includes/functions-hooks.php') )
include_once SH_PLUGIN_DIR_PATH . 'includes/functions-hooks.php';
$this->file_include('includes/functions-hooks.php');
/* Cryptocurrencies utils */
if( file_exists( SH_PLUGIN_DIR_PATH . 'includes/functions-crypto.php' ) )
include_once SH_PLUGIN_DIR_PATH . 'includes/functions-crypto.php';
$this->file_include('includes/functions-crypto.php');
/* Paid Member Subscription utils */
if( file_exists( SH_PLUGIN_DIR_PATH . 'includes/class-paid-member-subscriptions-integration.php' ) )
include_once SH_PLUGIN_DIR_PATH . 'includes/class-paid-member-subscriptions-integration.php';
$this->file_include('includes/class-paid-member-subscriptions-integration.php');
/* Video Players */
if( file_exists( SH_PLUGIN_DIR_PATH . 'includes/class-video-players.php' ) )
include_once SH_PLUGIN_DIR_PATH . 'includes/class-video-players.php';
$this->file_include('includes/class-video-players.php');
/* Advertising support */
if(file_exists( SH_PLUGIN_DIR_PATH . 'includes/functions-advert.php' ) )
include_once SH_PLUGIN_DIR_PATH . 'includes/functions-advert.php';
$this->file_include('includes/functions-advert.php');
/* Cam4 and Chaturbate support */
if( file_exists( SH_PLUGIN_DIR_PATH . 'includes/class-livecam-site-support.php') )
include_once SH_PLUGIN_DIR_PATH . 'includes/class-livecam-site-support.php';
$this->file_include('includes/class-livecam-site-support.php');
/* WooCommerce support functions */
if( file_exists( SH_PLUGIN_DIR_PATH . 'includes/functions-woocommerce-support.php') )
include_once SH_PLUGIN_DIR_PATH . 'includes/functions-woocommerce-support.php';
$this->file_include('includes/functions-woocommerce-support.php');
/* WooCommerce support class */
if( file_exists( SH_PLUGIN_DIR_PATH . 'includes/class-woocommerce-support.php') )
include_once SH_PLUGIN_DIR_PATH . 'includes/class-woocommerce-support.php';
$this->file_include('includes/class-woocommerce-support.php');
/* Storefront customization support */
if( file_exists( SH_PLUGIN_DIR_PATH . 'includes/class-storefront.php') )
include_once SH_PLUGIN_DIR_PATH . 'includes/class-storefront.php';
$this->file_include('includes/class-storefront.php');
/* Unlock integration class */
if( file_exists( SH_PLUGIN_DIR_PATH . 'includes/class-unlock-support.php') )
include_once SH_PLUGIN_DIR_PATH . 'includes/class-unlock-support.php';
$this->file_include('includes/class-unlock-support.php');
/* Video */
$this->file_include('includes/class-video.php');
/* Video Gallery */
if( file_exists( SH_PLUGIN_DIR_PATH . 'includes/class-videogallery.php') )
include_once SH_PLUGIN_DIR_PATH . 'includes/class-videogallery.php';
$this->file_include('includes/class-videogallery.php');
/* Shortcodes */
if( file_exists( SH_PLUGIN_DIR_PATH . 'includes/class-shortcodes.php' ) )
include_once SH_PLUGIN_DIR_PATH . 'includes/class-shortcodes.php';
$this->file_include('includes/class-shortcodes.php');
/* Widgets */
if( file_exists( SH_PLUGIN_DIR_PATH . 'includes/class-widgets.php' ) )
include_once SH_PLUGIN_DIR_PATH . 'includes/class-widgets.php';
$this->file_include('includes/class-widgets.php');
/* Hook to include needed files */
do_action( 'pms_include_files' );
......
<?php
/**
* Copyright: 2022 (c)Franco (nextime) Lanza <franco@nexlab.it>
* License: GNU/GPL version 3.0
*
* This file is part of SexHackMe Wordpress Plugin.
*
* SexHackMe Wordpress Plugin is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published
* by the Free Software Foundation, either version 3 of the License,
* or (at your option) any later version.
*
* SexHackMe Wordpress Plugin is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with SexHackMe Wordpress Plugin. If not, see <https://www.gnu.org/licenses/>.
*/
// Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) exit;
?>
<textarea style="width:100%" id="video_description" name="video_description"><?php echo esc_attr( $video->description ); ?></textarea>
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