google drive support complete!

parent 4fce81ab
......@@ -32,10 +32,94 @@ if(!class_exists('SH_GDrive')) {
function __construct()
{
add_filter('sh_download_url_filter', array($this, 'get_download_url'));
{
}
function get_download_url($file)
{
if ( function_exists( 'igd_fs' ) )
{
// Integrate Google Drive Plugin is installed and active, so, filter it!
if((strlen($file) > 9) && (strncmp($file, "gdrive://", 9) === 0))
{
$gpath=substr($file, 9);
if(strncmp($gpath, '/', 1)===0) $gpath=substr($file, 10);
$gparts = explode('/', $gpath);
if(count($gparts) > 0)
{
$parent=false;
$gfile=false;
$success=false;
$igd = \IGD\App::instance();
// Try root first
foreach($gparts as $k => $part)
{
if($k == 0)
{
$gdo = $igd->get_files(array('q'=> "{$part} in name"), 'root', false);
} else {
$gdo = $igd->get_files(array('q'=> "name='{$part}"), $parent, false);
}
if(!is_array($gdo) || (count($gdo) < 1) || array_key_exists('error', $gdo)) break;
$parent=false;
foreach($gdo as $g)
{
if($g['name']==$part)
{
$parent=$g['id'];
$gf=$g;
}
}
if(!$parent) break;
if(count($gparts)-1 == $k) $success=true;
}
// Then try on the shared with me folder
if(!$success)
{
foreach($gparts as $k => $part)
{
if($k == 0)
{
$gdo = $igd->get_files(array('q'=> "parents='' and sharedWithMe=true and '{$part}' in name"), 'shared', false);
} else {
$gdo = $igd->get_files(array('q'=> "name='{$part}"), $parent, false);
}
sexhack_log($gdo);
if(!is_array($gdo) || (count($gdo) < 1) || array_key_exists('error', $gdo)) break;
$parent=false;
foreach($gdo as $g)
{
if($g['name']==$part)
{
$parent=$g['id'];
$gf=$g;
}
}
}
}
if(count($gparts)-1 == $k) $success=true;
if($success) $gfile = $gf;
if($gfile && ($gfile['type'] != 'application/vnd.google-apps.folder'))
{
$file="https://drive.google.com/open?action=igd-wc-download&id=".$gfile['id'];
}
}
}
}
return $file;
}
}
......
......@@ -52,7 +52,7 @@ if(!class_exists('SH_Query')) {
if(is_object($video))
{
sexhack_log($video);
//sexhack_log($video);
$fieldsarrayraw = $video->get_sql_array();
$fieldsarray = array();
$fields = "";
......@@ -110,9 +110,12 @@ if(!class_exists('SH_Query')) {
$updateid = true;
}
do_action("sh_save_video_before_query", $video);
$wpdb->query( $sql );
if($updateid) $video->id = $wpdb->insert_id;
sexhack_log($sql);
//sexhack_log($sql);
foreach($video->get_categories() as $cat)
{
......@@ -122,24 +125,26 @@ if(!class_exists('SH_Query')) {
({$cat->id}, {$video->id});\n";
}
foreach($video->get_tags_names() as $tagname)
{
{
$tagname = $wpdb->_real_escape($tagname);
$q = "INSERT IGNORE INTO {$wpdb->prefix}".SH_PREFIX."videotags
(tag) VALUES ('{$tagname}');";
$wpdb->query($q);
$sqlarr[] = "INSERT INTO {$wpdb->prefix}".SH_PREFIX."videotags_assoc
$tag = sh_get_tag_by_name($tagname, true);
if($tag)
{
$sqlarr[] = "INSERT INTO {$wpdb->prefix}".SH_PREFIX."videotags_assoc
(tag_id, video_id)
VALUES
((SELET id FROM {$wpdb->prefix}".SH_PREFIX."videotags WHERE tag='{$tagname}'), {$video->id});";
('{$tag->id}', '{$video->id}');";
}
}
foreach($sqlarr as $sql)
{
sexhack_log($sql);
//sexhack_log($sql);
if($sql)
$wpdb->query( $sql );
}
do_action("sh_save_video_after_query", $video);
return $video;
......@@ -245,11 +250,27 @@ if(!class_exists('SH_Query')) {
if(!$id) return $dbres;
if(is_array($dbres) && count($dbres) > 0) return $dbres[0];
}
public static function get_Tag_By_Name($name, $create=false)
{
global $wpdb;
$sql = "SELECT * FROM {$wpdb->prefix}".SH_PREFIX."videotags WHERE tag='{$name}'";
$res = $wpdb->get_results($sql);
if(is_array($res))
{
if(count($res) > 0) return $res[0];
if(count($res) == 0 && $create)
{
$sql = "INSERT IGNORE INTO {$wpdb->prefix}".SH_PREFIX."videotags (tag) VALUES ('{$name}')";
$wpdb->query($sql);
return SH_Query::get_Tag_By_Name($name);
}
}
return false;
}
public static function get_Video_Categories($vid)
{
global $wpdb;
......
......@@ -53,6 +53,7 @@ if(!class_exists('SH_Video')) {
'hls_premium' => false,
'thumbnail' => false,
'gif' => false,
'gif_small' => false,
'download_public' => false,
'download_members' => false,
'download_premium' => false,
......@@ -128,17 +129,20 @@ if(!class_exists('SH_Video')) {
return isset($this->attributes['key']);
}
public function get_tags()
public function get_tags($usedb=true)
{
if(isset($this->attributes['tags'])) return $this->tags;
$tags = sh_get_video_tags($this->id);
$this->attributes['tags'] = array();
$this->attributes['tagsnames'] = array();
if($tags)
if($usedb)
{
foreach($tags as $tag) {
$this->attributes['tags'][$tag->id] = $tag;
$this->attributes['tagsnames'][] = $tag->tag;
$tags = sh_get_video_tags($this->id);
if($tags)
{
foreach($tags as $tag) {
$this->attributes['tags'][$tag->id] = $tag;
$this->attributes['tagsnames'][] = $tag->tag;
}
}
}
return $this->tags;
......@@ -160,6 +164,16 @@ if(!class_exists('SH_Video')) {
}
public function add_tag($tag)
{
if(!is_object($tag)) return false;
if(!isset($this->attributes['tags'])) $this->attributes['tags'] = array();
if(!isset($this->attributes['tagsnames'])) $this->attributes['tagsnames'] = array();
$this->attributes['tags'][$tag->id] = $tag;
$this->attributes['tagsnames'][] = $tag->tag;
return true;
}
public function get_categories($usedb=true)
{
if(isset($this->attributes['categories'])) return $this->categories;
......
......@@ -24,6 +24,31 @@ namespace wp_SexHackMe;
// Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) exit;
/* Sync Video Pages and Products */
if(!class_exists("SH_VideoProducts")) {
class SH_VideoProducts
{
public function __construct()
{
add_action('sh_save_video_after_query', array($this, 'sync_product_from_video'), 1, 10);
}
public function sync_product_from_video($video)
{
sexhack_log("PRODUUUUUUCT");
sexhack_log($video);
$download = apply_filters('sh_download_url_filter', $video->download_public);
sexhack_log($download);
}
}
new SH_VideoProducts;
}
/* Class to add Video to product page instead of image */
if(!class_exists('SexhackWoocommerceProductVideos')) {
......@@ -33,6 +58,7 @@ if(!class_exists('SexhackWoocommerceProductVideos')) {
{
add_action( 'woocommerce_before_single_product', array($this, 'video_remove_default_woocommerce_image' ));
add_filter( 'query_vars', array($this, 'themeslug_query_vars' ));
}
public function themeslug_query_vars( $qvars ) {
......
......@@ -82,8 +82,8 @@ function save_sexhack_video_meta_box_data( $post_id )
sexhack_log($_POST);
// Model
if(array_key_exists('video_model', $_POST) && is_integer($_POST['video_model']) && intval($_POST['video_model']) > 0)
$video->model = intval($_POST['video_model']);
if(array_key_exists('video_model', $_POST) && is_numeric($_POST['video_model']) && intval($_POST['video_model']) > 0)
$video->user_id = intval($_POST['video_model']);
// Video description
$video->description = sanitize_text_field( $_POST['video_description'] );
......@@ -138,6 +138,13 @@ function save_sexhack_video_meta_box_data( $post_id )
else
$video->gif = false;
// Small Animated gif path
if(array_key_exists('video_gif_small', $_POST) && check_url_or_path(sanitize_text_field($_POST['video_gif_small'])))
$video->gif_small = sanitize_text_field($_POST['video_gif_small']);
else
$video->gif_small = false;
// Differenciated content for access levels
foreach(array('public','members','premium') as $vt)
{
......@@ -183,6 +190,26 @@ function save_sexhack_video_meta_box_data( $post_id )
// Make sure the categories array is initialized
$video->get_categories(false);
// Video Tags
if(array_key_exists('video_tags', $_POST) && is_array($_POST['video_tags']))
{
foreach($_POST['video_tags'] as $tag_name)
{
$vtags = $video->get_tags(false);
if(sanitize_text_field(strtolower($tag_name)))
{
$tag_name = sanitize_text_field(strtolower($tag_name));
$tag = sh_get_tag_by_name($tag_name, true);
if($tag) $video->add_tag($tag);
}
}
}
// Make sure the tags array is initialized
$video->get_tags(false);
// Save the video data in the database.
sh_save_video($video);
......
......@@ -249,6 +249,8 @@ function check_url_or_path($url)
{
if (strncmp($url, "/", 1) === 0)
return 'path';
else if(strncmp($url, 'gdrive://', 9) === 0)
return 'gdrive';
else if(filter_var($url, FILTER_VALIDATE_URL))
return 'uri';
......
......@@ -26,7 +26,14 @@ if ( ! defined( 'ABSPATH' ) ) exit;
function sh_save_video($video)
{
return SH_Query::save_Video($video);
if(is_object($video)) {
// Initialize categories and tags is they are not.
// Get from database active if not cached already.
$video->get_categories(true);
$video->get_tags(true);
return SH_Query::save_Video($video);
}
return false;
}
function sh_delete_video($v)
......@@ -94,6 +101,11 @@ function sh_get_video_tags($v)
return false;
}
function sh_get_tag_by_name($name, $create=false)
{
return SH_Query::get_Tag_By_Name($name, $create);
}
function sh_delete_tags_from_video($v)
{
if(is_numeric($v) and $v > 0) return SH_Query::delete_Tags_assoc($v, 'video_id');
......
......@@ -185,7 +185,8 @@ if(!class_exists('SexHackMe_Plugin')) {
hls_members varchar(1024) DEFAULT NULL,
hls_premium varchar(1024) DEFAULT NULL,
thumbnail varchar(1024) DEFAULT NULL,
gif varchar(1024) DEFAULT NULL,
gif varchar(256) DEFAULT NULL,
gif_small varchar(256) DEFAULT NULL,
download_public varchar(1024) DEFAULT NULL,
download_members varchar(1024) DEFAULT NULL,
download_premium varchar(1024) DEFAULT NULL,
......
......@@ -64,6 +64,10 @@ echo '<style>div#visibility.misc-pub-section.misc-pub-visibility{display:none}</
<label> * Animated GIF (URI or PATH):</label>
<input type='text' name="video_gif" value='<?php echo esc_attr( $video->gif ); ?>' />
</p>
<p>
<label> * small preview GIF (URI or PATH):</label>
<input type='text' name="video_gif_small" value='<?php echo esc_attr( $video->gif_small ); ?>' />
</p>
<p>
<label> * Video preview/teaser (max 1 min)</label>
<input type='text' name="video_preview" value='<?php echo esc_attr( $video->preview ); ?>' />
......
......@@ -40,6 +40,12 @@ foreach($video->get_tags() as $tag)
</div>
</p>
<div id="vtagsdata"></div>
<?php
foreach($video->get_tags() as $tag)
{
echo " <input type='hidden' name='video_tags[]' data='".$tag->tag."' value='".$tag->tag."' />\n";
}
?>
<!--
<p class="hide-if-no-js"><button type="button" class="button-link tagcloud-link" id="link-video_tags" aria-expanded="false">Choose from the most used tags</button></p>
-->
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