Video post type complete

parent 1d64494d
......@@ -80,6 +80,7 @@ if(!class_exists('SH_MetaBox')) {
$video = new SH_Video();
$video->post_id = $post->ID;
$video->post = $post;
$video->get_guests(true);
}
sh_get_template("admin/metabox_model.php", array('video' => $video, 'post' => $post));
}
......
......@@ -94,6 +94,9 @@ if(!class_exists('SH_Query')) {
{$fields}
WHERE
id = {$video->id};";
$sqlarr[] = "DELETE FROM {$wpdb->prefix}".SH_PREFIX."videoguests_assoc
WHERE
video_id = {$video->id};";
$sqlarr[] = "DELETE FROM {$wpdb->prefix}".SH_PREFIX."videotags_assoc
WHERE
video_id = {$video->id};";
......@@ -140,6 +143,13 @@ if(!class_exists('SH_Query')) {
}
}
foreach($video->get_guests() as $guest)
{
$sqlarr[] = "INSERT INTO {$wpdb->prefix}".SH_PREFIX."videoguests_assoc
(user_id, video_id)
VALUES
('{$guest->ID}', '{$video->id}');";
}
foreach($sqlarr as $sql)
{
//sexhack_log($sql);
......@@ -148,6 +158,8 @@ if(!class_exists('SH_Query')) {
}
do_action("sh_save_video_after_query", $video);
//sexhack_log($video);
//sexhack_log($sqlarr);
return $video;
}
......@@ -169,6 +181,9 @@ if(!class_exists('SH_Query')) {
$sqlarr = array();
$sqlarr[] = "DELETE FROM {$wpdb->prefix}".SH_PREFIX."videoguests_assoc WHERE video_id IN (
SELECT id FROM {$wpdb->prefix}".SH_PREFIX."videos
WHERE {$idtype}=".intval($id)." );";
$sqlarr[] = "DELETE FROM {$wpdb->prefix}".SH_PREFIX."videotags_assoc WHERE video_id IN (
SELECT id FROM {$wpdb->prefix}".SH_PREFIX."videos
WHERE {$idtype}=".intval($id)." );";
......@@ -277,6 +292,41 @@ if(!class_exists('SH_Query')) {
return false;
}
public static function get_Video_Guests($vid)
{
global $wpdb;
$sql = "SELECT user_id FROM {$wpdb->prefix}".SH_PREFIX."videoguests_assoc WHERE video_id=".intval($vid)." ;";
$dbres = $wpdb->get_results( $sql );
$guests = array();
if($dbres && count($dbres) > 0)
{
foreach($dbres as $ures)
{
$udata = get_userdata($ures->user_id);
if($udata) $guests[$uid] = $udata;
}
}
if(count($guests) > 0) return $guests;
return false;
}
public static function delete_Guests_assoc($id, $idtype)
{
global $wpdb;
if(!is_integer($id))
return;
$idtype=sanitize_idtype($idtype);
if(!in_array($idtype, array('id', 'user_id', 'video_id'))) return false;
$sql = "DELETE FROM {$wpdb->prefix}".SH_PREFIX."videoguests_assoc WHERE {$idtpe}={$id}";
return $wpdb->query( $sql );
}
public static function get_Video_Categories($vid)
{
global $wpdb;
......
......@@ -174,6 +174,31 @@ if(!class_exists('SH_Video')) {
return true;
}
public function add_guest($guest)
{
if(!is_object($guest)) return false;
if(!isset($this->attributes['guests'])) $this->attributes['guests'] = array();
$this->attributes['guests'][$guest->ID] = $guest;
}
public function get_guests($usedb=true)
{
if(isset($this->attributes['guests'])) return $this->guests;
sexhack_log("(TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT");
$this->attributes['guests'] = array();
if($usedb)
{
$guests = sh_get_video_guests($this->id);
if($guests)
{
foreach($guests as $guest)
$this->attributes['guests'][$guest->ID] = $cat;
}
}
return $this->guests;
}
public function get_categories($usedb=true)
{
if(isset($this->attributes['categories'])) return $this->categories;
......@@ -239,7 +264,7 @@ if(!class_exists('SH_Video')) {
foreach($this->attributes as $k => $v)
{
if(($v!==false) && !in_array($k, array('id','post','product','tags',
'categories','tagsnames','created','updated','sells',
'categories','tagsnames','created','updated','sells','guests',
'views_public','views_members','views_premium')) ) $r[$k] = $v;
}
return $r;
......
......@@ -183,6 +183,22 @@ function save_sexhack_video_meta_box_data( $post_id )
}
// Video Guests
if(array_key_exists('vguests', $_POST) && is_array($_POST['vguests']))
{
foreach($_POST['vguests'] as $guest_id)
{
if(is_numeric($guest_id) && intval($guest_id) > 0)
{
$guest = get_userdata(intval($guest_id));
if($guest) $video->add_guest($guest);
}
}
}
// Make sure the guestss array is initialized
$video->get_guests(false);
// Video Categories
if(array_key_exists('vcategory', $_POST) && is_array($_POST['vcategory']))
{
......
......@@ -47,6 +47,10 @@ function sanitize_idtype($idt=false)
{
case 'post':
case 'product':
case 'cat':
case 'video':
case 'user':
case 'tag':
return $idt."_id";
break;
case 'id':
......
......@@ -31,6 +31,7 @@ function sh_save_video($video)
// Get from database active if not cached already.
$video->get_categories(true);
$video->get_tags(true);
$video->get_guests(true);
return SH_Query::save_Video($video);
}
return false;
......@@ -94,6 +95,14 @@ function sh_get_video_categories($v)
return false;
}
function sh_get_video_guests($v)
{
if(is_numeric($v) and $v > 0) return SH_Query::get_Video_Guests($v);
else if(is_object($v)) return SH_Query::get_Video_Guests($v->ID);
return false;
}
function sh_get_video_tags($v)
{
if(is_numeric($v) and $v > 0) return SH_Query::get_Video_Tags($v);
......@@ -109,14 +118,22 @@ function sh_get_tag_by_name($name, $create=false)
function sh_delete_tags_from_video($v)
{
if(is_numeric($v) and $v > 0) return SH_Query::delete_Tags_assoc($v, 'video_id');
else if(is_object($v)) return SH_Query::get_Video_Tags($v->id, 'video_id');
else if(is_object($v)) return SH_Query::get_delete_Tags_assoc($v->id, 'video_id');
return false;
}
function sh_delete_guests_from_video($v)
{
if(is_numeric($v) and $v > 0) return SH_Query::delete_Guests_assoc($v, 'video_id');
else if(is_object($v)) return SH_Query::delete_Guests_assoc($v->id, 'video_id');
return false;
}
function sh_delete_categories_from_video($v)
{
if(is_numeric($v) and $v > 0) return SH_Query::delete_Categories_assoc($v, 'video_id');
else if(is_object($v)) return SH_Query::get_Categories_Tags($v->id, 'video_id');
else if(is_object($v)) return SH_Query::delete_Categories_assoc($v->id, 'video_id');
return false;
}
......
......@@ -2,6 +2,7 @@ jQuery(document).ready(function($) {
$("#sh_admin_tabs .hidden").removeClass('hidden');
$("#sh_admin_tabs").tabs({'active': 0});
// ::: TAGS BOX
$("#shvtags input").on({
focusout : function() {
......
......@@ -649,8 +649,8 @@ if(!class_exists('SexHackMe_Plugin')) {
if( WP_DEBUG === true ){
// only matched?
//add_action("the_post", 'wp_SexHackMe\debug_rewrite_rules');
sexhack_log("REQUEST: ".$_SERVER['REQUEST_URI']." QUERY: ".$_SERVER['QUERY_STRING']. "POST:");
sexhack_log($_POST);
//sexhack_log("REQUEST: ".$_SERVER['REQUEST_URI']." QUERY: ".$_SERVER['QUERY_STRING']. "POST:");
//sexhack_log($_POST);
}
......
......@@ -22,11 +22,26 @@
// Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) exit;
?>
<script type="text/javascript">
window.guestChange = function(trig)
{
if(trig.value > 0)
{
var newsel = $('.guest_selection').clone();
newsel.insertAfter($('.guest_list p').last());
newsel.show()
newsel.removeClass('guest_selection');
} else {
$('.guest_list p').last().remove();
}
}
</script>
<div class="wrap">
<table class="form-table">
<tr align="top">
<td>
<p><label>Select user</label></p>
<p><label>Select Model user</label></p>
<?php // XXX When this will be with thousands of model will definely not scale! ?>
<select name='video_model'>
<?php
......@@ -40,6 +55,55 @@ if ( ! defined( 'ABSPATH' ) ) exit;
</select>
</td>
</tr>
<tr align="top">
<td class='guest_list'>
<p style="display:none" class="guest_selection">
<select name='vguests[]' onchange='javascript:guestChange(this);'>
<option value="0">NO GUEST</option>
<?php
foreach($models as $user)
{
echo "<option value='".$user->ID."' ";
echo '>'.$user->user_login." (id:".$user->ID.")</option>";
}
?>
</select>
</p>
<p>
<p><label>Add guest model</label></p>
<?php // XXX When this will be with thousands of model will definely not scale! ?>
<select name='vguests[]' onchange='javascript:guestChange(this);'>
<option value="0">NO GUEST</option>
<?php
foreach($models as $user)
{
echo "<option value='".$user->ID."' ";
echo '>'.$user->user_login." (id:".$user->ID.")</option>";
} ?>
</select>
</p>
<?php
foreach($video->get_guests(true) as $uid => $guest)
{
?>
<p>
<select name='vguests[]' onchange='javascript:guestChange(this);'>
<option value="0">NO GUEST</option>
<?php
foreach($models as $user)
{
echo "<option value='".$user->ID."' ";
if($uid==$user->ID) echo "selected";
echo '>'.$user->user_login." (id:".$user->ID.")</option>";
} ?>
</select>
</p>
<?php
}
?>
</td>
</tr>
</table>
</div>
......@@ -24,6 +24,18 @@ if ( ! defined( 'ABSPATH' ) ) exit;
// This is a dirty trick to hide the Visibility section in the publish metabox.
echo '<style>div#visibility.misc-pub-section.misc-pub-visibility{display:none}</style>';
if($video->product_id > 0)
{
//$prod = wc_get_product($video->product_id);
$wcprodlink = site_url()."/wp-admin/post.php?post=".$video->product_id."&action=edit";
?>
<p>
<label>WooCommerce Product: </label>
<a href='<?php echo $wcprodlink; ?>'><?php echo $wcprodlink; ?></a>
</p>
<?php
}
?>
<p>
<h4>Video description</h4>
......
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