Boa noite amigos, essa é minha primeira postagem no forum. Estou construindo um site adulto e não tenho experiencia em php, criei funções e estou tendo erros com as funções e não sei como proceder para sanar esses erros.
Estou usando uma função que pega a url do vide em alguns sites adultos e recupera o id do embeed, até ai tudo certo e funcionando perfeitamente em sintonia com um formulário Gravity forms para envio dos videos (urls), fui alem atras de um codigo que pudesse pegar o endereço url e roda-lo e encontrar o endereço do thumb dentro da pagina, ao encontrar trazer, fazer uplload para o meu servidor. Feito isso setar a imagem como de destaque, até ai tudo funcionando perfeitamente. O que está me ocorrendo é que as funções estão dentro do functions.php do meu tema Sahifa, e cada vez que é rodado a pagina do video uma nova imagem é enviada ao servidor. Queria juda para impedir que esssa imagem seja carregada, ja pensei em uma função que condicionasse o envio a alguma coisa, no entanto não sei faze-la. Ou então ao encontrar a imagem de nome igual no servidor não enviar outra. Segue a função que está dentro da pagina functions. Desde já agradeço se puderem me ajudar.
function vid_sc($atts, $content=null) {
extract(shortcode_atts(array(
'site' => 'youtube',
'id' => '',
'autoplay' => ''
), $atts) );
if ( $site == "youtube" ) { $src = 'http://www.youtube.com/embed/'.$id; }
elseif ( $site == "xvideos" ) {
$src = $id;
$video = substr(@parse_url($src, PHP_URL_PATH), 6);
$video_id = strtok($video, '/');
$endereco = file_get_contents($id);
$pegar = preg_match_all('/<meta property="og:image" content=(.+)\/>/', $endereco, $conteudo);
if ( $site == "xvideos" ) {
$image_s1 = $conteudo[1][0]; // Define the image URL here
$image_s2 = substr($image_s1, 1);
$image_s3 = strtok($image_s2, '"');
$image_url = $image_s3;
$image_name = $video_id.'.jpg';
$upload_dir = wp_upload_dir(); // Set upload folder
$image_data = file_get_contents($image_url); // Get image data
$unique_file_name = wp_unique_filename( $upload_dir['path'], $image_name ); // Generate unique name
$filename = basename( $unique_file_name ); // Create image file name
$file_path = get_site_url() . '/wp-content/uploads/' . $image_name; // Get the futur file path of the image
if( !file_exists($file_path) ){ // Check if image is already in upload_dir
// Check folder permission and define file location
if( wp_mkdir_p( $upload_dir['path'] ) ) {
$file = $upload_dir['path'] . '/' . $filename;
} else {
$file = $upload_dir['basedir'] . '/' . $filename;
}
// Create the image file on the server
file_put_contents( $file, $image_data );
// Check image file type
$wp_filetype = wp_check_filetype( $filename, null );
// Set attachment data
$attachment = array(
'post_mime_type' => $wp_filetype['type'],
'post_title' => sanitize_file_name( $filename ),
'post_content' => '',
'post_status' => 'inherit'
);
// Create the attachment
$attach_id = wp_insert_attachment( $attachment, $file, $post_id );
// Include image.php
require_once(ABSPATH . 'wp-admin/includes/media.php');
require_once(ABSPATH . 'wp-admin/includes/file.php');
require_once(ABSPATH . 'wp-admin/includes/image.php');
// Define attachment metadata
$attach_data = wp_generate_attachment_metadata( $attach_id, $file );
// Assign metadata to attachment
wp_update_attachment_metadata( $attach_id, $attach_data );
// And finally assign featured image to post
set_post_thumbnail( $post_id, $attach_id );
add_action('after_switch_theme', 'my_theme_activation');
}
} else { }
}
elseif ( $site == "redtube" ) {
$src = $id;
$video = (int) substr(@parse_url($src, PHP_URL_PATH), 1);
$endereco = file_get_contents($id);
$pegar = preg_match_all('/<meta property="og:image" content=(.+)\/>/', $endereco, $conteudo);
if ( $site == "redtube" ) {
$image_s1 = $conteudo[1][0]; // Define the image URL here
$image_s2 = substr($image_s1, 1);
$image_s3 = strtok($image_s2, '"');
$image_url = "http:".$image_s3;
$image_name = $video_id.'.jpg';
$upload_dir = wp_upload_dir(); // Set upload folder
$image_data = file_get_contents($image_url); // Get image data
$unique_file_name = wp_unique_filename( $upload_dir['path'], $image_name ); // Generate unique name
$filename = basename( $unique_file_name ); // Create image file name
$file_path = get_site_url() . '/wp-content/uploads/' . $image_name; // Get the futur file path of the image
if( !file_exists($file_path) ){ // Check if image is already in upload_dir
// Check folder permission and define file location
if( wp_mkdir_p( $upload_dir['path'] ) ) {
$file = $upload_dir['path'] . '/' . $filename;
} else {
$file = $upload_dir['basedir'] . '/' . $filename;
}
// Create the image file on the server
file_put_contents( $file, $image_data );
// Check image file type
$wp_filetype = wp_check_filetype( $filename, null );
// Set attachment data
$attachment = array(
'post_mime_type' => $wp_filetype['type'],
'post_title' => sanitize_file_name( $filename ),
'post_content' => '',
'post_status' => 'inherit'
);
// Create the attachment
$attach_id = wp_insert_attachment( $attachment, $file, $post_id );
// Include image.php
require_once(ABSPATH . 'wp-admin/includes/media.php');
require_once(ABSPATH . 'wp-admin/includes/file.php');
require_once(ABSPATH . 'wp-admin/includes/image.php');
// Define attachment metadata
$attach_data = wp_generate_attachment_metadata( $attach_id, $file );
// Assign metadata to attachment
wp_update_attachment_metadata( $attach_id, $attach_data );
// And finally assign featured image to post
set_post_thumbnail( $post_id, $attach_id );
}
} else { }
}
elseif ( $site == "xhamster" ) {
$src = $id;
$video = substr(@parse_url($src, PHP_URL_PATH), 8);
$video_id = strtok($video, '/');
$endereco = file_get_contents($id);
$pegar = preg_match_all('/<link itemprop="thumbnailUrl" href="(.+)/', $endereco, $conteudo);
if ( $site == "xhamster" ) {
$image_s1 = $conteudo[1][0]; // Define the image URL here
$image_s2 = substr($image_s1, 0);
$image_s3 = strtok($image_s2, '"');
$image_url = $image_s3;
$image_name = $video_id.'.jpg';
$upload_dir = wp_upload_dir(); // Set upload folder
$image_data = file_get_contents($image_url); // Get image data
$unique_file_name = wp_unique_filename( $upload_dir['path'], $image_name ); // Generate unique name
$filename = basename( $unique_file_name ); // Create image file name
$file_path = get_site_url() . '/wp-content/uploads/' . $image_name; // Get the futur file path of the image
if( !file_exists($file_path) ){ // Check if image is already in upload_dir
// Check folder permission and define file location
if( wp_mkdir_p( $upload_dir['path'] ) ) {
$file = $upload_dir['path'] . '/' . $filename;
} else {
$file = $upload_dir['basedir'] . '/' . $filename;
}
// Create the image file on the server
file_put_contents( $file, $image_data );
// Check image file type
$wp_filetype = wp_check_filetype( $filename, null );
// Set attachment data
$attachment = array(
'post_mime_type' => $wp_filetype['type'],
'post_title' => sanitize_file_name( $filename ),
'post_content' => '',
'post_status' => 'inherit'
);
// Create the attachment
$attach_id = wp_insert_attachment( $attachment, $file, $post_id );
// Include image.php
require_once(ABSPATH . 'wp-admin/includes/media.php');
require_once(ABSPATH . 'wp-admin/includes/file.php');
require_once(ABSPATH . 'wp-admin/includes/image.php');
// Define attachment metadata
$attach_data = wp_generate_attachment_metadata( $attach_id, $file );
// Assign metadata to attachment
wp_update_attachment_metadata( $attach_id, $attach_data );
// And finally assign featured image to post
set_post_thumbnail( $post_id, $attach_id );
}
} else { }
}
elseif ( $site == "pornhub" ) {
$src = $id;
$posicao = strpos($src, '=');
$video = substr($src, $posicao+1);
$endereco = file_get_contents($id);
$pegar = preg_match_all('/<meta property="og:image" content=(.*)\/>/', $endereco, $conteudo);
if ( $site == "pornhub" ) {
$image_s1 = $conteudo[1][0]; // Define the image URL here
$image_s2 = substr($image_s1, 1);
$image_s3 = strtok($image_s2, '"');
$image_url = $image_s3;
$image_name = $video_id.'.jpg';
$upload_dir = wp_upload_dir(); // Set upload folder
$image_data = file_get_contents($image_url); // Get image data
$unique_file_name = wp_unique_filename( $upload_dir['path'], $image_name ); // Generate unique name
$filename = basename( $unique_file_name ); // Create image file name
$file_path = get_site_url() . '/wp-content/uploads/' . $image_name; // Get the futur file path of the image
if( !file_exists($file_path) ){ // Check if image is already in upload_dir
// Check folder permission and define file location
if( wp_mkdir_p( $upload_dir['path'] ) ) {
$file = $upload_dir['path'] . '/' . $filename;
} else {
$file = $upload_dir['basedir'] . '/' . $filename;
}
// Create the image file on the server
file_put_contents( $file, $image_data );
// Check image file type
$wp_filetype = wp_check_filetype( $filename, null );
// Set attachment data
$attachment = array(
'post_mime_type' => $wp_filetype['type'],
'post_title' => sanitize_file_name( $filename ),
'post_content' => '',
'post_status' => 'inherit'
);
// Create the attachment
$attach_id = wp_insert_attachment( $attachment, $file, $post_id );
// Include image.php
require_once(ABSPATH . 'wp-admin/includes/media.php');
require_once(ABSPATH . 'wp-admin/includes/file.php');
require_once(ABSPATH . 'wp-admin/includes/image.php');
// Define attachment metadata
$attach_data = wp_generate_attachment_metadata( $attach_id, $file );
// Assign metadata to attachment
wp_update_attachment_metadata( $attach_id, $attach_data );
// And finally assign featured image to post
set_post_thumbnail( $post_id, $attach_id );
}
} else { }
}
elseif ( $site == "pornocarioca" ) {
$src = $id;
$posicao = strpos($src, 'video/');
$video = substr($src, $posicao+6);
$video_id = strtok($video, '"');
}
elseif ( $site == "yourporn" ) {
$src = $id;
$video = substr(@parse_url($src, PHP_URL_PATH), 7);
$video_id = strtok($video, '/');
$endereco = file_get_contents($id);
$pegar = preg_match_all('/<meta property="og:image" content=(.*)\/>/', $endereco, $conteudo);
if ( $site == "yourporn" ) {
$image_s1 = $conteudo[1][0]; // Define the image URL here
$image_s2 = substr($image_s1, 1);
$image_s3 = strtok($image_s2, '"');
$image_url = $image_s3;
$image_name = $video_id.'.jpg';
$upload_dir = wp_upload_dir(); // Set upload folder
$image_data = file_get_contents($image_url); // Get image data
$unique_file_name = wp_unique_filename( $upload_dir['path'], $image_name ); // Generate unique name
$filename = basename( $unique_file_name ); // Create image file name
$file_path = get_site_url() . '/wp-content/uploads/' . $image_name; // Get the futur file path of the image
if( !file_exists($file_path) ){ // Check if image is already in upload_dir
// Check folder permission and define file location
if( wp_mkdir_p( $upload_dir['path'] ) ) {
$file = $upload_dir['path'] . '/' . $filename;
} else {
$file = $upload_dir['basedir'] . '/' . $filename;
}
// Create the image file on the server
file_put_contents( $file, $image_data );
// Check image file type
$wp_filetype = wp_check_filetype( $filename, null );
// Set attachment data
$attachment = array(
'post_mime_type' => $wp_filetype['type'],
'post_title' => sanitize_file_name( $filename ),
'post_content' => '',
'post_status' => 'inherit'
);
// Create the attachment
$attach_id = wp_insert_attachment( $attachment, $file, $post_id );
// Include image.php
require_once(ABSPATH . 'wp-admin/includes/media.php');
require_once(ABSPATH . 'wp-admin/includes/file.php');
require_once(ABSPATH . 'wp-admin/includes/image.php');
// Define attachment metadata
$attach_data = wp_generate_attachment_metadata( $attach_id, $file );
// Assign metadata to attachment
wp_update_attachment_metadata( $attach_id, $attach_data );
// And finally assign featured image to post
set_post_thumbnail( $post_id, $attach_id );
}
} else { }
}
elseif ( $site == "tube8" ) {
$src = $id;
$video = substr(@parse_url($src, PHP_URL_PATH), 1);
$endereco = file_get_contents($id);
$pegar = preg_match_all('/<meta property="og:image" content=(.*)\/>/', $endereco, $conteudo);
if ( $site == "tube8" ) {
$image_s1 = $conteudo[1][0]; // Define the image URL here
$image_s2 = substr($image_s1, 1);
$image_s3 = strtok($image_s2, '"');
$image_url = $image_s3;
$image_name = $video_id.'.jpg';
$upload_dir = wp_upload_dir(); // Set upload folder
$image_data = file_get_contents($image_url); // Get image data
$unique_file_name = wp_unique_filename( $upload_dir['path'], $image_name ); // Generate unique name
$filename = basename( $unique_file_name ); // Create image file name
$file_path = get_site_url() . '/wp-content/uploads/' . $image_name; // Get the futur file path of the image
if( !file_exists($file_path) ){ // Check if image is already in upload_dir
// Check folder permission and define file location
if( wp_mkdir_p( $upload_dir['path'] ) ) {
$file = $upload_dir['path'] . '/' . $filename;
} else {
$file = $upload_dir['basedir'] . '/' . $filename;
}
// Create the image file on the server
file_put_contents( $file, $image_data );
// Check image file type
$wp_filetype = wp_check_filetype( $filename, null );
// Set attachment data
$attachment = array(
'post_mime_type' => $wp_filetype['type'],
'post_title' => sanitize_file_name( $filename ),
'post_content' => '',
'post_status' => 'inherit'
);
// Create the attachment
$attach_id = wp_insert_attachment( $attachment, $file, $post_id );
// Include image.php
require_once(ABSPATH . 'wp-admin/includes/media.php');
require_once(ABSPATH . 'wp-admin/includes/file.php');
require_once(ABSPATH . 'wp-admin/includes/image.php');
// Define attachment metadata
$attach_data = wp_generate_attachment_metadata( $attach_id, $file );
// Assign metadata to attachment
wp_update_attachment_metadata( $attach_id, $attach_data );
// And finally assign featured image to post
set_post_thumbnail( $post_id, $attach_id );
}
} else { }
}
elseif ( $site == "xtube" ) {
$src = $id;
$video = substr(@parse_url($src, PHP_URL_PATH), 13);
$endereco = file_get_contents($id);
$pegar = preg_match_all('/<meta property="og:image" content=(.*)\/>/', $endereco, $conteudo);
if ( $site == "xtube" ) {
$image_s1 = $conteudo[1][0]; // Define the image URL here
$image_s2 = substr($image_s1, 1);
$image_s3 = strtok($image_s2, '"');
$image_url = $image_s3;
$image_name = $video_id.'.jpg';
$upload_dir = wp_upload_dir(); // Set upload folder
$image_data = file_get_contents($image_url); // Get image data
$unique_file_name = wp_unique_filename( $upload_dir['path'], $image_name ); // Generate unique name
$filename = basename( $unique_file_name ); // Create image file name
$file_path = get_site_url() . '/wp-content/uploads/' . $image_name; // Get the futur file path of the image
if( !file_exists($file_path) ){ // Check if image is already in upload_dir
// Check folder permission and define file location
if( wp_mkdir_p( $upload_dir['path'] ) ) {
$file = $upload_dir['path'] . '/' . $filename;
} else {
$file = $upload_dir['basedir'] . '/' . $filename;
}
// Create the image file on the server
file_put_contents( $file, $image_data );
// Check image file type
$wp_filetype = wp_check_filetype( $filename, null );
// Set attachment data
$attachment = array(
'post_mime_type' => $wp_filetype['type'],
'post_title' => sanitize_file_name( $filename ),
'post_content' => '',
'post_status' => 'inherit'
);
// Create the attachment
$attach_id = wp_insert_attachment( $attachment, $file, $post_id );
// Include image.php
require_once(ABSPATH . 'wp-admin/includes/media.php');
require_once(ABSPATH . 'wp-admin/includes/file.php');
require_once(ABSPATH . 'wp-admin/includes/image.php');
// Define attachment metadata
$attach_data = wp_generate_attachment_metadata( $attach_id, $file );
// Assign metadata to attachment
wp_update_attachment_metadata( $attach_id, $attach_data );
// And finally assign featured image to post
set_post_thumbnail( $post_id, $attach_id );
}
} else { }
}
if ($site == "youtube") {
return '<div class="embed-container youtube" itemprop="video" itemscope itemtype="http://schema.org/VideoObject"><iframe width="'. $w .'" height="'. $h .'" src="'. $src .'" class="vid iframe-'. $site .'"></iframe></div>';
}
elseif ($site == "xvideos") {
return '<div class="embed-container xvideos" itemprop="video" itemscope itemtype="http://schema.org/VideoObject"><iframe width="'. $w .'" height="'. $h .'" src="https://flashservice.xvideos.com/embedframe/'. $video_id .'" class="vid iframe-'. $site .'" scrolling="no" allowfullscreen></iframe></div><br>';
}
elseif ($site == "redtube") {
return '<div class="embed-container vimeo" itemprop="video" itemscope itemtype="http://schema.org/VideoObject"><iframe width="'. $w .'" height="'. $h .'" src="https://embed.redtube.com?id='. $video .'" class="vid iframe-'. $site .'" scrolling="no" allowfullscreen></iframe></div>';
}
elseif ($site == "xhamster") {
return '<div class="embed-container myspace" itemprop="video" itemscope itemtype="http://schema.org/VideoObject"><iframe width="'. $w .'" height="'. $h .'" src="http://xhamster.com/xembed.php?video='. $video_id .'" class="vid iframe-'. $site .'" scrolling="no" allowfullscreen></iframe></div>';
}
elseif ($site == "pornhub") {
return '<div class="embed-container myspace" itemprop="video" itemscope itemtype="http://schema.org/VideoObject"><iframe width="'. $w .'" height="'. $h .'" src="https://www.pornhub.com/embed/'. $video .'" class="vid iframe-'. $site .'" scrolling="no" allowfullscreen></iframe></div>';
}
elseif ($site == "pornocarioca") {
return '<div class="embed-container myspace" itemprop="video" itemscope itemtype="http://schema.org/VideoObject"><iframe width="'. $w .'" height="'. $h .'" src="http://embed.pornocarioca.com/video/'. $video_id .'" class="vid iframe-'. $site .'" scrolling="no" allowfullscreen></iframe></div>';
}
elseif ($site == "yourporn") {
return '<div class="embed-container myspace" itemprop="video" itemscope itemtype="http://schema.org/VideoObject"><iframe width="'. $w .'" height="'. $h .'" src="http://www.youporn.com/embed/'. $video_id .'" class="vid iframe-'. $site .'" scrolling="no" allowfullscreen></iframe></div>';
}
elseif ($site == "tube8") {
return '<div class="embed-container myspace" itemprop="video" itemscope itemtype="http://schema.org/VideoObject"><iframe width="'. $w .'" height="'. $h .'" src="https://www.tube8.com/embed/'. $video .'" class="vid iframe-'. $site .'" scrolling="no" allowfullscreen></iframe></div>';
}
elseif ($site == "xtube") {
return '<div class="embed-container myspace" itemprop="video" itemscope itemtype="http://schema.org/VideoObject"><iframe width="'. $w .'" height="'. $h .'" src="http://www.xtube.com/video-watch/embedded/'. $video .'?autoplay='. $autoplay .'" class="vid iframe-'. $site .'" scrolling="no" allowfullscreen></iframe></div>';
}
else {
return '<div class="embed-container"><iframe width="'. $w .'" height="'. $h .'" src="'. $src .'" class="vid iframe-'. $site .'"></iframe></div>';
}
}
add_shortcode('videoin','vid_sc');
Simplificando o que estou tentando fazer.
Quero condicionar a função de fazer upload das imagens a alguma coisa que vá fazer com que a cada vez que a pagina carregar não vá mandar outra imagem para o servidor. Da forma como está, <?if ($site == 'xvideos'... nas postagens do xvideos, mand a foto daquela postagem novamente ao servidor. talvez se fosse retirado parte da função de envio que cria novo nomes se o arquivo ja existir, pudesse suprir minhas necessidades. Segue o código simplificado abaixo.
<?
// shortcode vídeos
function vid_sc($atts, $content=null) {
extract(shortcode_atts(array(
'site' => 'xvideos',
'id' => '',
'autoplay' => ''
), $atts) );
if ( $site == "xvideos" ) {
$src = $id;
$video = substr(@parse_url($src, PHP_URL_PATH), 6);
$video_id = strtok($video, '/');
if( !empty( $site == 'xvideos' ) ){
$endereco = file_get_contents($id);
$pegar = preg_match_all('/<meta property="og:image" content=(.+)\/>/', $endereco, $conteudo);
$image_s1 = $conteudo[1][0]; // Define the image URL here
$image_s2 = substr($image_s1, 1);
$image_s3 = strtok($image_s2, '"');
$image_url = $image_s3;
$image_name = $video_id.'.jpg';
$upload_dir = wp_upload_dir(); // Set upload folder
$image_data = file_get_contents($image_url); // Get image data
$unique_file_name = wp_unique_filename( $upload_dir['path'], $image_name ); // Generate unique name
$filename = basename( $unique_file_name ); // Create image file name
$file_path = get_site_url() . '/wp-content/uploads/' . $image_name; // Get the futur file path of the image
if( !file_exists($file_path) ){ // Check if image is already in upload_dir
// Check folder permission and define file location
if( wp_mkdir_p( $upload_dir['path'] ) ) {
$file = $upload_dir['path'] . '/' . $filename;
} else {
$file = $upload_dir['basedir'] . '/' . $filename;
}
// Create the image file on the server
file_put_contents( $file, $image_data );
// Check image file type
$wp_filetype = wp_check_filetype( $filename, null );
// Set attachment data
$attachment = array(
'post_mime_type' => $wp_filetype['type'],
'post_title' => sanitize_file_name( $filename ),
'post_content' => '',
'post_status' => 'inherit'
);
// Create the attachment
$attach_id = wp_insert_attachment( $attachment, $file, $post_id );
// Include image.php
require_once(ABSPATH . 'wp-admin/includes/media.php');
require_once(ABSPATH . 'wp-admin/includes/file.php');
require_once(ABSPATH . 'wp-admin/includes/image.php');
// Define attachment metadata
$attach_data = wp_generate_attachment_metadata( $attach_id, $file );
// Assign metadata to attachment
wp_update_attachment_metadata( $attach_id, $attach_data );
// And finally assign featured image to post
set_post_thumbnail( $post_id, $attach_id );
}
} else { }
}
}
if ($site == "xvideos") {
return '<div class="embed-container xvideos" itemprop="video" itemscope itemtype="http://schema.org/VideoObject"><iframe width="'. $w .'" height="'. $h .'" src="https://flashservice.xvideos.com/embedframe/'. $video_id .'" class="vid iframe-'. $site .'" scrolling="no" allowfullscreen></iframe></div><br>';
}
add_shortcode('videoin','vid_sc');
?>



Postagens
Não informado
