';
}
add_filter('the_content', 'advset_author_bio');
}
# author_bio
if( advset_option('author_bio_html') )
remove_filter('pre_user_description', 'wp_filter_kses');
# auto post thumbnails
if( advset_option('auto_thumbs') ) {
// based on "auto posts plugin" 3.3.2
// check post status
function advset_check_post_status( $new_status='' ) {
global $post_ID;
if ('publish' == $new_status)
advset_publish_post($post_ID);
}
//
function advset_publish_post( $post_id ) {
global $wpdb;
// First check whether Post Thumbnail is already set for this post.
if (get_post_meta($post_id, '_thumbnail_id', true) || get_post_meta($post_id, 'skip_post_thumb', true))
return;
$post = $wpdb->get_results("SELECT * FROM {$wpdb->posts} WHERE id = $post_id");
// Initialize variable used to store list of matched images as per provided regular expression
$matches = array();
// Get all images from post's body
preg_match_all('/<\s*img [^\>]*src\s*=\s*[\""\']?([^\""\'>]*)/i', $post[0]->post_content, $matches);
if (count($matches)) {
foreach ($matches[0] as $key => $image) {
/**
* If the image is from wordpress's own media gallery, then it appends the thumbmail id to a css class.
* Look for this id in the IMG tag.
*/
preg_match('/wp-image-([\d]*)/i', $image, $thumb_id);
$thumb_id = $thumb_id[1];
// If thumb id is not found, try to look for the image in DB. Thanks to "Erwin Vrolijk" for providing this code.
if (!$thumb_id) {
$image = substr($image, strpos($image, '"')+1);
$result = $wpdb->get_results("SELECT ID FROM {$wpdb->posts} WHERE guid = '".$image."'");
$thumb_id = $result[0]->ID;
}
// Ok. Still no id found. Some other way used to insert the image in post. Now we must fetch the image from URL and do the needful.
if (!$thumb_id) {
$thumb_id = advset_generate_post_thumbnail($matches, $key, $post[0]->post_content, $post_id);
}
// If we succeed in generating thumg, let's update post meta
if ($thumb_id) {
update_post_meta( $post_id, '_thumbnail_id', $thumb_id );
break;
}
}
}
}
function advset_generate_post_thumbnail( $matches, $key, $post_content, $post_id ) {
// Make sure to assign correct title to the image. Extract it from img tag
$imageTitle = '';
preg_match_all('/<\s*img [^\>]*title\s*=\s*[\""\']?([^\""\'>]*)/i', $post_content, $matchesTitle);
if (count($matchesTitle) && isset($matchesTitle[1])) {
$imageTitle = $matchesTitle[1][$key];
}
// Get the URL now for further processing
$imageUrl = $matches[1][$key];
// Get the file name
$filename = substr($imageUrl, (strrpos($imageUrl, '/'))+1);
if ( !(($uploads = wp_upload_dir(current_time('mysql')) ) && false === $uploads['error']) )
return null;
// Generate unique file name
$filename = wp_unique_filename( $uploads['path'], $filename );
// Move the file to the uploads dir
$new_file = $uploads['path'] . "/$filename";
if (!ini_get('allow_url_fopen'))
$file_data = curl_get_file_contents($imageUrl);
else
$file_data = @file_get_contents($imageUrl);
if (!$file_data) {
return null;
}
file_put_contents($new_file, $file_data);
// Set correct file permissions
$stat = stat( dirname( $new_file ));
$perms = $stat['mode'] & 0000666;
@ chmod( $new_file, $perms );
// Get the file type. Must to use it as a post thumbnail.
$wp_filetype = wp_check_filetype( $filename, $mimes );
extract( $wp_filetype );
// No file type! No point to proceed further
if ( ( !$type || !$ext ) && !current_user_can( 'unfiltered_upload' ) ) {
return null;
}
// Compute the URL
$url = $uploads['url'] . "/$filename";
// Construct the attachment array
$attachment = array(
'post_mime_type' => $type,
'guid' => $url,
'post_parent' => null,
'post_title' => $imageTitle,
'post_content' => '',
);
$thumb_id = wp_insert_attachment($attachment, $file, $post_id);
if ( !is_wp_error($thumb_id) ) {
require_once(ABSPATH . '/wp-admin/includes/image.php');
// Added fix by misthero as suggested
wp_update_attachment_metadata( $thumb_id, wp_generate_attachment_metadata( $thumb_id, $new_file ) );
update_attached_file( $thumb_id, $new_file );
return $thumb_id;
}
return null;
}
add_action('transition_post_status', 'advset_check_post_status');
if( !function_exists('curl_get_file_contents') ) {
function curl_get_file_contents($URL) {
$c = curl_init();
curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($c, CURLOPT_URL, $URL);
$contents = curl_exec($c);
curl_close($c);
if ($contents) {
return $contents;
}
return FALSE;
}
}
}
# author_bio
if( $_POST && (advset_option('max_image_size_w')>0 || advset_option('max_image_size_h')>0) ) {
// From "Resize at Upload Plus" 1.3
/* This function will apply changes to the uploaded file */
function advset_resize_image( $array ) {
// $array contains file, url, type
if ($array['type'] == 'image/jpeg' OR $array['type'] == 'image/gif' OR $array['type'] == 'image/png') {
// there is a file to handle, so include the class and get the variables
require_once( dirname(__FILE__).'/class.resize.php' );
$maxwidth = advset_option('max_image_size_w');
$maxheight = advset_option('max_image_size_h');
$imagesize = getimagesize($array['file']); // $imagesize[0] = width, $imagesize[1] = height
if ( $maxwidth == 0 OR $maxheight == 0) {
if ($maxwidth==0) {
$objResize = new RVJ_ImageResize($array['file'], $array['file'], 'H', $maxheight);
}
if ($maxheight==0) {
$objResize = new RVJ_ImageResize($array['file'], $array['file'], 'W', $maxwidth);
}
} else {
if ( ($imagesize[0] >= $imagesize[1]) AND ($maxwidth * $imagesize[1] / $imagesize[0] <= $maxheight) ) {
$objResize = new RVJ_ImageResize($array['file'], $array['file'], 'W', $maxwidth);
} else {
$objResize = new RVJ_ImageResize($array['file'], $array['file'], 'H', $maxheight);
}
}
} // if
return $array;
} // function
add_action('wp_handle_upload', 'advset_resize_image');
}
# remove filters if not in filters admin page
$remove_filters = advset_option( 'remove_filters' );
if( !isset($_GET['page'])
|| $_GET['page']!='advanced-settings-filters' && is_array($remove_filters) ) {
if( isset($remove_filters) && is_array($remove_filters) )
foreach( $remove_filters as $tag=>$array )
if( is_array($array) )
foreach( $array as $function=>$_ )
//echo "$tag=>".$function.' ';
remove_filter( $tag, $function );
}
// translate to pt_BR
if( is_admin() && defined('WPLANG') && WPLANG=='pt_BR' ) {
add_filter( 'gettext', 'advset_translate', 10, 3 );
global $advset_ptbr;
$advset_ptbr = array(
'Be careful, removing a filter can destabilize your system. For security reasons, no filter removal has efects over this page.' => 'Cuidado! Remover um filtro pode desestabilizar seu sistema. Por segurança, nenhum filtro removido terá efeito nesta página.',
'Filters/Actions' => 'Filtros/Ações',
'Save changes' => 'Salvar alterações',
'width' => 'largura',
'height' => 'altura',
'Contents' => 'Conteúdo',
'System' => 'Sistema',
'HTML Code output' => 'Saída do código HTML',
'Hide top admin menu' => 'Esconde menu de administrador do topo',
'Automatically add a FavIcon' => 'Adicionar um FavIcon automático para a página',
'when there is a favicon.ico or favicon.png file in the template folder' => 'sempre que houver um arquivo favicon.ico ou favicon.png na pasta do modelo',
'Add a description meta tag using the blog description' => 'Adicionar uma meta tag de descrição usando a descrição do blog',
'Add description and keywords meta tags in each posts' => 'Adicionar uma meta tags de descrição e palavras-chave em cada post',
'Remove header WordPress generator meta tag' => 'Remover meta tag de "gerado pelo WordPress"',
'Remove header WLW Manifest meta tag' => 'Remover meta tag WLW Manifest',
'Current theme already has post thumbnail support' => 'Tema atual já tem suporte a imagem destacada (thumbnails)',
'Automatically generate the Post Thumbnail' => 'Gerar imagem destacada automaticamente',
'from the first image in post' => 'gera a partir da primeira imagem encontrada no post',
'Set JPEG quality to' => 'Alterar qualidade do JPEG para',
'when send and resize images' => 'no momento em que envia ou redimensiona imagens',
'Resize image at upload to max size' => 'Redimensionar a imagem no upload no tamanho máximo',
'if zero resize to max height or dont resize if both is zero' => 'Se zero, redimenciona para largura máxima ou nada faz se os dois valores forem zero',
'if zero resize to max width or dont resize if both is zero' => 'Se zero, redimenciona para altura máxima ou nada faz se os dois valores forem zero',
'Insert author bio in each post' => 'Adicionar descrição do autor em cada post',
'Remove comments system' => 'Remover sistema de comentários',
'Fix post type pagination' => 'Corrige paginação de "post types"',
'Disable Posts Auto Saving' => 'Desabilita função de auto-salvar',
'Compress all code' => 'Comprime todo o código',
'transformations of quotes to smart quotes, apostrophes, dashes, ellipses, the trademark symbol, and the multiplication symbol' => 'estilização de áspas, apóstrofos, elípses, traços, e multiplicação dos símbolos',
'Remove all HTML comments' => 'Remover todos os comentários em HTML',
'Display total number of executed SQL queries and page loading time' => 'Mostrar o total de SQLs executadas e o tempo de carregamento da página',
'only admin users can see this' => 'apenas administradores poderão ver',
'inserts a javascript code in the footer' => 'adicionar um código em javascript no final do código HTML',
'Allow HTML in user profiles' => 'Permitir códigos HTML na descrição de perfil dos usuários',
//'' => '',
);
}
function advset_translate( $text ) {
global $advset_ptbr;
$array = $advset_ptbr;
if( isset($array[$text]) )
return $array[$text];
else
return $text;
}
// -----------------------------------------------------------------------
add_action('wp_ajax_advset_filters', 'prefix_ajax_advset_filters');
function prefix_ajax_advset_filters() {
//echo $_POST['tag'].' - '.$_POST['function'];
// security
if( !current_user_can('manage_options') )
return false;
$remove_filters = (array) advset_option( 'remove_filters' );
$tag = (string)$_POST['tag'];
$function = (string)$_POST['function'];
if( $_POST['enable']=='true' )
unset($remove_filters[$tag][$function]);
else if ( $_POST['enable']=='false' )
$remove_filters[$tag][$function] = 1;
advset_save_option( 'remove_filters', $remove_filters );
//echo $_POST['enable'];
return true;
}
# THE ADMIN FILTERS PAGE
function advset_page_filters() { ?>