Add base template for gdrive

parent d1bb18dd
<?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_GDrive')) {
class SH_GDrive
{
function __construct()
{
add_filter('sh_download_url_filter', array($this, 'get_download_url'));
{
function get_download_url($file)
{
return $file;
}
}
new SH_Gdrive;
}
?>
......@@ -51,6 +51,8 @@ if(!class_exists('SH_Query')) {
if(is_object($video))
{
sexhack_log($video);
$fieldsarrayraw = $video->get_sql_array();
$fieldsarray = array();
$fields = "";
......@@ -240,7 +242,11 @@ if(!class_exists('SH_Query')) {
if($id && is_numeric($id))
$sql .= " WHERE id='".intval($id)."'";
$dbres = $wpdb->get_results( $sql );
return $dbres;
if(!$id) return $dbres;
if(is_array($dbres) && count($dbres) > 0) return $dbres[0];
}
......
......@@ -132,18 +132,14 @@ if(!class_exists('SH_Video')) {
{
if(isset($this->attributes['tags'])) return $this->tags;
$tags = sh_get_video_tags($this->id);
$this->tags = array();
$this->tagsnames = array();
$tags_indexed = array();
$tagsnames = array();
$this->attributes['tags'] = array();
$this->attributes['tagsnames'] = array();
if($tags)
{
foreach($tags as $tag) {
$tags_indexed[$tag->id] = $tag;
$tagsnames[] = $tag->tag;
$this->attributes['tags'][$tag->id] = $tag;
$this->attributes['tagsnames'][] = $tag->tag;
}
$this->tags = $tags_indexed;
$this->tagsnames = $tagsnames;
}
return $this->tags;
}
......@@ -155,17 +151,27 @@ if(!class_exists('SH_Video')) {
return $this->tagsnames;
}
public function get_categories()
public function add_category($cat)
{
if(!is_object($cat)) return false;
if(!isset($this->attributes['categories'])) $this->attributes['categories'] = array();
$this->attributes['categories'][$cat->id] = $cat;
return true;
}
public function get_categories($usedb=true)
{
if(isset($this->attributes['categories'])) return $this->categories;
$this->attributes['categories'] = array();
if($usedb)
{
$cats = sh_get_video_categories($this->id);
$this->categories = array();
$cats_indexed = array();
if($cats)
{
foreach($cats as $cat)
$cats_indexed[$cat->id] = $cat;
$this->categories = $cats_indexed;
$this->attributes['categories'][$cat->id] = $cat;
}
}
return $this->categories;
}
......@@ -218,7 +224,9 @@ if(!class_exists('SH_Video')) {
$r = array();
foreach($this->attributes as $k => $v)
{
if(($v) && !in_array($k, array('id', 'post', 'product', 'tags','categories', 'tagsnames')) ) $r[$k] = $v;
if(($v!==false) && !in_array($k, array('id','post','product','tags',
'categories','tagsnames','created','updated','sells',
'views_public','views_members','views_premium')) ) $r[$k] = $v;
}
return $r;
}
......
......@@ -86,7 +86,6 @@ function save_sexhack_video_meta_box_data( $post_id )
$video->model = intval($_POST['video_model']);
// Video description
if(array_key_exists('video_description', $_POST) && sanitize_text_field($_POST['video_description']))
$video->description = sanitize_text_field( $_POST['video_description'] );
// Video thumbnail
......@@ -112,11 +111,12 @@ function save_sexhack_video_meta_box_data( $post_id )
// Video visible
if(array_key_exists('video_visible', $_POST) && in_array($_POST['video_visible'], array('Y','N')))
$video->private = $_POST['video_visible'];
$video->visible = $_POST['video_visible'];
// Video price
if(array_key_exists('video_price', $_POST) && is_numeric($_POST['video_price']) && (floatval($_POST['video_price']) > 0))
if(array_key_exists('video_price', $_POST) && is_numeric($_POST['video_price']) && (floatval($_POST['video_price']) >= 0))
$video->price = floatval($_POST['video_price']);
else $video->price = 0;
// Video type
if(array_key_exists('video_type', $_POST) && in_array($_POST['video_type'], array('VR', 'FLAT')))
......@@ -129,10 +129,14 @@ function save_sexhack_video_meta_box_data( $post_id )
// Preview video
if(array_key_exists('video_preview', $_POST) && check_url_or_path(sanitize_text_field($_POST['video_preview'])))
$video->preview = sanitize_text_field($_POST['video_preview']);
else
$video->preview = false;
// Animated gif path
if(array_key_exists('video_gif', $_POST) && check_url_or_path(sanitize_text_field($_POST['video_gif'])))
$video->gif = sanitize_text_field($_POST['video_gif']);
else
$video->gif = false;
// Differenciated content for access levels
foreach(array('public','members','premium') as $vt)
......@@ -143,14 +147,14 @@ function save_sexhack_video_meta_box_data( $post_id )
(strncasecmp(strrev(sanitize_text_field($_POST['video_hls_'.$vt])), '8u3m', 4) === 0))
{
$video->__set('hls_'.$vt, sanitize_text_field($_POST['video_hls_'.$vt]));
}
} else $video->__set('hls_'.$vt, false);
// Download
if(array_key_exists('video_download_'.$vt, $_POST) &&
check_url_or_path(sanitize_text_field($_POST['video_download_'.$vt])))
{
$video->__set('download_'.$vt, sanitize_text_field($_POST['video_download_'.$vt]));
}
} else $video->__set('download_'.$vt, false);
// Text only data
foreach(array('size','format','codec','acodec','duration','resolution') as $key)
......@@ -159,10 +163,25 @@ function save_sexhack_video_meta_box_data( $post_id )
sanitize_text_field($_POST['video_'.$key.'_'.$vt]))
{
$video->__set($key.'_'.$vt, sanitize_text_field($_POST['video_'.$key.'_'.$vt]));
} else $video->__set($key.'_'.$vt, false);
}
}
// Video Categories
if(array_key_exists('vcategory', $_POST) && is_array($_POST['vcategory']))
{
foreach($_POST['vcategory'] as $cat_id)
{
if(is_numeric($cat_id) && intval($cat_id) > 0)
{
$cat = sh_get_categories(intval($cat_id));
if($cat) $video->add_category($cat);
}
}
}
// Make sure the categories array is initialized
$video->get_categories(false);
// Save the video data in the database.
sh_save_video($video);
......
......@@ -394,6 +394,9 @@ if(!class_exists('SexHackMe_Plugin')) {
/* Unlock integration class */
$this->file_include('includes/class-unlock-support.php');
/* integrate google drive plugin database support */
$this->file_include('includes/class-integrate-google-drive.php');
/* Video */
$this->file_include('includes/class-video.php');
$this->file_include('includes/functions-video.php');
......
......@@ -58,15 +58,15 @@ echo '<style>div#visibility.misc-pub-section.misc-pub-visibility{display:none}</
<h4>Preview</h4>
<p>
<label> * Thumbnail (URI,PATH or thumbail ID):</label>
<input type='text' nane="video_thumbnail" value='<?php echo esc_attr( $video->thumbnail ); ?>' > (Override featured image)</input>
<input type='text' name="video_thumbnail" value='<?php echo esc_attr( $video->thumbnail ); ?>' > (Override featured image)</input>
</p>
<p>
<label> * Animated GIF (URI or PATH):</label>
<input type='text' nane="video_gif" value='<?php echo esc_attr( $video->gif ); ?>' />
<input type='text' name="video_gif" value='<?php echo esc_attr( $video->gif ); ?>' />
</p>
<p>
<label> * Video preview/teaser (max 1 min)</label>
<input type='text' nane="video_preview" value='<?php echo esc_attr( $video->preview ); ?>' />
<input type='text' name="video_preview" value='<?php echo esc_attr( $video->preview ); ?>' />
<p>
</p>
......@@ -80,8 +80,8 @@ echo '<style>div#visibility.misc-pub-section.misc-pub-visibility{display:none}</
<p>
<label> * VR Projection</label>
<select name='video_vr_projection'>
<option value='VR180_LR' <?php if($video->video_vr_projection=='VR180_LR') echo "selected"; ?>>Equirectangular 180 LR</option>
<option value='VR360_LR' <?php if($video->video_vr_projection=='VR360_LR') echo "selected"; ?>>Equirectangular 360 LR</option>
<option value='VR180_LR' <?php if($video->vr_projection=='VR180_LR') echo "selected"; ?>>Equirectangular 180 LR</option>
<option value='VR360_LR' <?php if($video->vr_projection=='VR360_LR') echo "selected"; ?>>Equirectangular 360 LR</option>
</select>
<label>(ignored for non VR videos)</option>
</p>
......@@ -89,7 +89,7 @@ echo '<style>div#visibility.misc-pub-section.misc-pub-visibility{display:none}</
<p>
<h4>Price:</h4>
<label>USD:</label>
<input type='text' nane="video_price" value='<?php echo esc_attr( $video->price ); ?>' />
<input type='text' name="video_price" value='<?php echo esc_attr( $video->price ); ?>' />
</p>
<p>
<?php
......@@ -119,35 +119,35 @@ echo '<style>div#visibility.misc-pub-section.misc-pub-visibility{display:none}</
<h4> <?php echo ucfirst($vt); ?> files</h4>
<p>
<label> * Download (URI or PATH):</label>
<input type='text' nane="video_download_<?php echo $vt;?>" value='<?php echo esc_attr( $video->__get($vtdown) ); ?>' />
<input type='text' name="video_download_<?php echo $vt;?>" value='<?php echo esc_attr( $video->__get($vtdown) ); ?>' />
</p>
</p>
<label> * HLS playlist (URI or PATH):</label>
<input type='text' nane="video_hls_<?php echo $vt;?>" value='<?php echo esc_attr( $video->__get($vthls ) ); ?>' />
<input type='text' name="video_hls_<?php echo $vt;?>" value='<?php echo esc_attr( $video->__get($vthls ) ); ?>' />
</p>
</p>
<label> * Duration:</label>
<input type='text' nane="video_duration_<?php echo $vt;?>" value='<?php echo esc_attr( $video->__get($vtduration ) ); ?>' />
<input type='text' name="video_duration_<?php echo $vt;?>" value='<?php echo esc_attr( $video->__get($vtduration ) ); ?>' />
</p>
</p>
<label> * File size:</label>
<input type='text' nane="video_size_<?php echo $vt;?>" value='<?php echo esc_attr( $video->__get($vtsize ) ); ?>' />
<input type='text' name="video_size_<?php echo $vt;?>" value='<?php echo esc_attr( $video->__get($vtsize ) ); ?>' />
</p>
</p>
<label> * Resolution:</label>
<input type='text' nane="video_resolution_<?php echo $vt;?>" value='<?php echo esc_attr( $video->__get($vtresolution ) ); ?>' />
<input type='text' name="video_resolution_<?php echo $vt;?>" value='<?php echo esc_attr( $video->__get($vtresolution ) ); ?>' />
</p>
</p>
<label> * Format:</label>
<input type='text' nane="video_format_<?php echo $vt;?>" value='<?php echo esc_attr( $video->__get($vtformat ) ); ?>' />
<input type='text' name="video_format_<?php echo $vt;?>" value='<?php echo esc_attr( $video->__get($vtformat ) ); ?>' />
</p>
</p>
<label> * Codec:</label>
<input type='text' nane="video_codec_<?php echo $vt;?>" value='<?php echo esc_attr( $video->__get($vtcodec ) ); ?>' />
<input type='text' name="video_codec_<?php echo $vt;?>" value='<?php echo esc_attr( $video->__get($vtcodec ) ); ?>' />
</p>
</p>
<label> * Audio codec:</label>
<input type='text' nane="video_acodec_<?php echo $vt;?>" value='<?php echo esc_attr( $video->__get($vtacodec ) ); ?>' />
<input type='text' name="video_acodec_<?php echo $vt;?>" value='<?php echo esc_attr( $video->__get($vtacodec ) ); ?>' />
</p>
</div>
......
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