Ampliado a 280 caracteres el límite para los mensajes de Twitter y nuevo icono para GitHub

This commit is contained in:
Manuel Cillero 2018-04-08 12:31:46 +02:00
parent e90481b6a2
commit 76858efe9c
2 changed files with 374 additions and 355 deletions

View file

@ -8,16 +8,16 @@
if ( !function_exists( 'write_log' ) ) { if ( !function_exists( 'write_log' ) ) {
function write_log( $log ) { function write_log( $log ) {
# if ( true === WP_DEBUG ) { # if ( true === WP_DEBUG ) {
if ( is_array( $log ) || is_object( $log ) ) { if ( is_array( $log ) || is_object( $log ) ) {
error_log( print_r( $log, true ), 3, '/tmp/manuel.cillero.errors.log' ); error_log( print_r( $log, true ), 3, '/tmp/manuel.cillero.errors.log' );
} }
else { else {
error_log( "$log\n", 3, '/tmp/manuel.cillero.errors.log' ); error_log( "$log\n", 3, '/tmp/manuel.cillero.errors.log' );
} }
# } # }
} }
} }
/* /*
@ -26,10 +26,10 @@ if ( !function_exists( 'write_log' ) ) {
*/ */
add_filter( 'wp_calculate_image_srcset', 'ssl_srcset' ); add_filter( 'wp_calculate_image_srcset', 'ssl_srcset' );
function ssl_srcset( $sources ) { function ssl_srcset( $sources ) {
foreach ( $sources as &$source ) { foreach ( $sources as &$source ) {
$source['url'] = set_url_scheme( $source['url'], 'https' ); $source['url'] = set_url_scheme( $source['url'], 'https' );
} }
return $sources; return $sources;
} }
/* /*
@ -38,10 +38,10 @@ function ssl_srcset( $sources ) {
*/ */
add_filter( 'the_content', 'add_exif_data' ); add_filter( 'the_content', 'add_exif_data' );
function add_exif_data( $content ) { function add_exif_data( $content ) {
if ( function_exists('exifography_display_exif') && is_single() && has_category( 976 ) ) { if ( function_exists('exifography_display_exif') && is_single() && has_category( 976 ) ) {
$content .= exifography_display_exif(); $content .= exifography_display_exif();
} }
return $content; return $content;
} }
/* /*
@ -58,7 +58,7 @@ function custom_tag_cloud_widget( $args ) {
} }
add_filter( 'wp_generate_tag_cloud', 'xf_tag_cloud', 10, 3 ); add_filter( 'wp_generate_tag_cloud', 'xf_tag_cloud', 10, 3 );
function xf_tag_cloud( $tag_string ) { function xf_tag_cloud( $tag_string ) {
return preg_replace( "/style='font-size:.+px/", "$0 !important", $tag_string ); return preg_replace( "/style='font-size:.+px/", "$0 !important", $tag_string );
} }
/* /*
@ -77,8 +77,8 @@ function remove_pingbacks_recent_comments( $array ) {
*/ */
add_filter( 'avia_post_nav_settings', 'avia_same_category_filter', 10, 1 ); add_filter( 'avia_post_nav_settings', 'avia_same_category_filter', 10, 1 );
function avia_same_category_filter( $settings ) { function avia_same_category_filter( $settings ) {
$settings['same_category'] = true; $settings['same_category'] = true;
return $settings; return $settings;
} }
/* /*
@ -88,14 +88,14 @@ function avia_same_category_filter( $settings ) {
*/ */
add_filter( 'avf_title_args', 'fix_single_post_title', 10, 2 ); add_filter( 'avf_title_args', 'fix_single_post_title', 10, 2 );
function fix_single_post_title( $args, $id ) { function fix_single_post_title( $args, $id ) {
$category = get_the_category(); $category = get_the_category();
if ( ! empty( $category ) && is_single() && get_post_type() == 'post' ) { if ( ! empty( $category ) && is_single() && get_post_type() == 'post' ) {
// Social title for Twitter, Facebook & LinkedIn categories: // Social title for Twitter, Facebook & LinkedIn categories:
$args['title'] = in_array( $category[0]->name, array( 'Twitter', 'Facebook', 'LinkedIn' ) ) ? 'Social' : $category[0]->name; $args['title'] = in_array( $category[0]->name, array( 'Twitter', 'Facebook', 'LinkedIn' ) ) ? 'Social' : $category[0]->name;
$args['link'] = NULL; $args['link'] = NULL;
$args['heading'] = 'h1'; $args['heading'] = 'h1';
} }
return $args; return $args;
} }
/* /*
@ -104,10 +104,25 @@ function fix_single_post_title( $args, $id ) {
*/ */
add_filter( 'avf_blog_style', 'avia_change_tag_page_layout', 10, 2 ); add_filter( 'avf_blog_style', 'avia_change_tag_page_layout', 10, 2 );
function avia_change_tag_page_layout( $layout, $context ) { function avia_change_tag_page_layout( $layout, $context ) {
if ( is_tag() ) { if ( is_tag() ) {
$layout = 'single-small'; $layout = 'single-small';
} }
return $layout; return $layout;
}
/*
* Register new icon as a theme icon fot Github.
* See https://kriesi.at/documentation/enfold/custom-social-icons/
*/
add_filter( 'avf_default_icons', 'avia_add_custom_icon', 10, 1 );
function avia_add_custom_icon( $icons ) {
$icons['github'] = array( 'font' =>'fontello', 'icon' => 'uf09b' );
return $icons;
}
add_filter( 'avf_social_icons_options', 'avia_add_custom_social_icon', 10, 1 );
function avia_add_custom_social_icon( $icons ) {
$icons['GitHub'] = 'github';
return $icons;
} }
/* /*
@ -116,11 +131,11 @@ function avia_change_tag_page_layout( $layout, $context ) {
*/ */
add_filter( 'post_class', 'add_social_class' ); add_filter( 'post_class', 'add_social_class' );
function add_social_class( $classes ) { function add_social_class( $classes ) {
$category = get_the_category(); $category = get_the_category();
if ( !empty( $category ) && in_array( $category[0]->term_id, array( 1561, 1562, 1563, 1564 ) ) ) { if ( !empty( $category ) && in_array( $category[0]->term_id, array( 1561, 1562, 1563, 1564 ) ) ) {
$classes[] = 'post-entry-social'; $classes[] = 'post-entry-social';
} }
return $classes; return $classes;
} }
/* /*
@ -129,32 +144,32 @@ function add_social_class( $classes ) {
*/ */
add_filter( 'avia_breadcrumbs_trail', 'avia_change_breadcrumb', 50, 2 ); add_filter( 'avia_breadcrumbs_trail', 'avia_change_breadcrumb', 50, 2 );
function avia_change_breadcrumb( $trail, $args ) { function avia_change_breadcrumb( $trail, $args ) {
if ( is_single() ) { if ( is_single() ) {
$category = get_the_category(); $category = get_the_category();
if ( !empty( $category ) ) { if ( !empty( $category ) ) {
// Correct breadcrumb for Blog, Bloc de notas & Fotoblog single posts: // Correct breadcrumb for Blog, Bloc de notas & Fotoblog single posts:
if ( in_array( $category[0]->term_id, array( 982, 978, 976 ) ) && strpos( $trail[1], 'social' ) ) { if ( in_array( $category[0]->term_id, array( 982, 978, 976 ) ) && strpos( $trail[1], 'social' ) ) {
switch ( $category[0]->term_id ) { switch ( $category[0]->term_id ) {
case 982: // Blog case 982: // Blog
array_splice( $trail, 1, 2, array( '<a href="/blog/category/blog">Blog</a>' ) ); array_splice( $trail, 1, 2, array( '<a href="/blog/category/blog">Blog</a>' ) );
break; break;
case 978: // Bloc de notas case 978: // Bloc de notas
array_splice( $trail, 1, 2, array( '<a href="/blog/category/notebook">Bloc de notas</a>' ) ); array_splice( $trail, 1, 2, array( '<a href="/blog/category/notebook">Bloc de notas</a>' ) );
break; break;
case 976: // Fotoblog case 976: // Fotoblog
array_splice( $trail, 1, 2, array( '<a href="/blog/category/photoblog">Fotoblog</a>' ) ); array_splice( $trail, 1, 2, array( '<a href="/blog/category/photoblog">Fotoblog</a>' ) );
} }
} }
// Social breadcrumb for Twitter, Facebook & LinkedIn content: // Social breadcrumb for Twitter, Facebook & LinkedIn content:
elseif ( in_array( $category[0]->term_id, array( 1562, 1563, 1564 ) ) ) { elseif ( in_array( $category[0]->term_id, array( 1562, 1563, 1564 ) ) ) {
unset ( $trail[2] ); unset ( $trail[2] );
} }
} }
} }
elseif ( is_tag() || is_category( array( 982, 978, 976 ) ) ) { elseif ( is_tag() || is_category( array( 982, 978, 976 ) ) ) {
// Posts breadcrumb for Blog, Bloc de notas & Fotoblog categories: // Posts breadcrumb for Blog, Bloc de notas & Fotoblog categories:
array_splice( $trail, 1, 0, array( '<a href="/posts" title="Todas las entradas">Entradas</a>' ) ); array_splice( $trail, 1, 0, array( '<a href="/posts" title="Todas las entradas">Entradas</a>' ) );
} }
return $trail; return $trail;
} }
@ -163,21 +178,21 @@ function avia_change_breadcrumb( $trail, $args ) {
*/ */
add_filter( 'wp_insert_post_data', 'autogenerate_title', 1, 2 ); add_filter( 'wp_insert_post_data', 'autogenerate_title', 1, 2 );
function autogenerate_title( $data, $postarr ) { function autogenerate_title( $data, $postarr ) {
$title = preg_replace( '!\s+!', ' ', str_replace( '&nbsp;', ' ', $data['post_title'] ) ); $title = preg_replace( '!\s+!', ' ', str_replace( '&nbsp;', ' ', $data['post_title'] ) );
$text_title = trim( strip_tags( $title ) ); $text_title = trim( strip_tags( $title ) );
if ( empty( $text_title ) ) { if ( empty( $text_title ) ) {
$content = preg_replace( '!\s+!', ' ', str_replace( '&nbsp;', ' ', $data['post_content'] ) ); $content = preg_replace( '!\s+!', ' ', str_replace( '&nbsp;', ' ', $data['post_content'] ) );
$text_content = trim( strip_tags( $content ) ); $text_content = trim( strip_tags( $content ) );
if ( ! empty( $text_content ) ) { if ( ! empty( $text_content ) ) {
$content_words = explode( ' ', $text_content ); $content_words = explode( ' ', $text_content );
$text_title = implode( ' ', array_slice( $content_words, 0, 4 ) ); $text_title = implode( ' ', array_slice( $content_words, 0, 4 ) );
$data['post_title'] = count( $content_words ) > 4 ? "$text_title" : $text_title; $data['post_title'] = count( $content_words ) > 4 ? "$text_title" : $text_title;
} }
} }
return $data; return $data;
} }
/* /*
@ -185,86 +200,86 @@ function autogenerate_title( $data, $postarr ) {
*/ */
add_action( 'save_post', 'share_post', 1, 2 ); add_action( 'save_post', 'share_post', 1, 2 );
function share_post( $post_id, $post ) { function share_post( $post_id, $post ) {
// Count post categories: // Count post categories:
$post_categories = get_the_category( $post_id ); $post_categories = get_the_category( $post_id );
$categories = array_values( array_column( $post_categories, 'name' ) ); $categories = array_values( array_column( $post_categories, 'name' ) );
$num_categories = count( $categories ); $num_categories = count( $categories );
// Review post only for Social, Twitter, Facebook & LinkedIn categories: // Review post only for Social, Twitter, Facebook & LinkedIn categories:
$num_social_categories = count( array_intersect( array( 'Social', 'Twitter', 'Facebook', 'LinkedIn' ), $categories ) ); $num_social_categories = count( array_intersect( array( 'Social', 'Twitter', 'Facebook', 'LinkedIn' ), $categories ) );
// Nothing to do if there aren't social categories: // Nothing to do if there aren't social categories:
if ( $num_social_categories > 0 ) { if ( $num_social_categories > 0 ) {
// Get cleaned post title: // Get cleaned post title:
$title = preg_replace( '!\s+!', ' ', str_replace( '&nbsp;', ' ', $post->post_title ) ); $title = preg_replace( '!\s+!', ' ', str_replace( '&nbsp;', ' ', $post->post_title ) );
$text_title = trim( strip_tags( $title ) ); $text_title = trim( strip_tags( $title ) );
if ( mb_strrpos( $text_title, ' …' ) == mb_strlen( $text_title ) - 2 ) { if ( mb_strrpos( $text_title, ' …' ) == mb_strlen( $text_title ) - 2 ) {
$text_title = mb_substr( $text_title, 0, mb_strlen( $text_title ) - 2 ); $text_title = mb_substr( $text_title, 0, mb_strlen( $text_title ) - 2 );
} }
// Get cleaned post content: // Get cleaned post content:
$content = preg_replace( '!\s+!', ' ', str_replace( '&nbsp;', ' ', $post->post_content ) ); $content = preg_replace( '!\s+!', ' ', str_replace( '&nbsp;', ' ', $post->post_content ) );
$text_content = trim( strip_tags( $content ) ); $text_content = trim( strip_tags( $content ) );
// Adapting content for pure social posts: // Adapting content for pure social posts:
if ( $num_categories == $num_social_categories ) { if ( $num_categories == $num_social_categories ) {
$post_content = trim( strip_tags( $content, '<p><a><strong><b><em><i><br />' ) ); $post_content = trim( strip_tags( $content, '<p><a><strong><b><em><i><br />' ) );
/* /*
Remove html attributes except for anchor tag: Remove html attributes except for anchor tag:
/ Start Pattern / Start Pattern
< Match '<' at beginning of tags < Match '<' at beginning of tags
( Start Capture Group $1 - Tag Name ( Start Capture Group $1 - Tag Name
[a-z] Match 'a' through 'z' [a-z] Match 'a' through 'z'
[a-z0-9]+ Match 'a' through 'z' or '0' through '9' one or more times [a-z0-9]+ Match 'a' through 'z' or '0' through '9' one or more times
) End Capture Group ) End Capture Group
[^>]*? Match anything other than '>', Zero or More times, not-greedy (wont eat the /) [^>]*? Match anything other than '>', Zero or More times, not-greedy (wont eat the /)
(\/?) Capture Group $2 - '/' if it is there (\/?) Capture Group $2 - '/' if it is there
> Match '>' > Match '>'
/i End Pattern - Case Insensitive /i End Pattern - Case Insensitive
*/ */
$post_content = preg_replace( "/<([a-z][a-z0-9]+)[^>]*?(\/?)>/i", '<$1$2>', $post_content ); $post_content = preg_replace( "/<([a-z][a-z0-9]+)[^>]*?(\/?)>/i", '<$1$2>', $post_content );
$post->post_content = str_replace( array( '<b>', '</b>', '<i>', '</i>' ), array( '<strong>', '</strong>', '<em>', '</em>' ), $post_content ); $post->post_content = str_replace( array( '<b>', '</b>', '<i>', '</i>' ), array( '<strong>', '</strong>', '<em>', '</em>' ), $post_content );
} }
// Preparing post excerpt for Twitter: // Preparing post excerpt for Twitter:
$text_excerpt = $text_content; $text_excerpt = $text_content;
if ( mb_strpos( $text_content, $text_title ) !== 0 ) { if ( mb_strpos( $text_content, $text_title ) !== 0 ) {
$post_excerpt = $text_title; $post_excerpt = $text_title;
$post_excerpt .= empty( $text_content ) ? '.' : ". $text_content"; $post_excerpt .= empty( $text_content ) ? '.' : ". $text_content";
} }
$post_excerpt = html_entity_decode( $text_excerpt ); $post_excerpt = html_entity_decode( $text_excerpt );
$limit = has_post_thumbnail( $post ) ? 140 - 25 : 140; $limit = has_post_thumbnail( $post ) ? 280 - 25 : 280;
if ( mb_strlen( $post_excerpt ) > $limit ) { if ( mb_strlen( $post_excerpt ) > $limit ) {
preg_match_all( '#\bhttps?://[^\s()<>]+(?:\([\w\d]+\)|([^[:punct:]\s]|/))#', $post_excerpt, $matches ); preg_match_all( '#\bhttps?://[^\s()<>]+(?:\([\w\d]+\)|([^[:punct:]\s]|/))#', $post_excerpt, $matches );
for ( $i = 0; $i < count( $matches[0] ); $i++ ) { for ( $i = 0; $i < count( $matches[0] ); $i++ ) {
$post_excerpt = str_replace( $matches[0][$i], shorten_url( $matches[0][$i] ), $post_excerpt ); $post_excerpt = str_replace( $matches[0][$i], shorten_url( $matches[0][$i] ), $post_excerpt );
} }
if ( mb_strlen( $post_excerpt ) > $limit ) { if ( mb_strlen( $post_excerpt ) > $limit ) {
$post_excerpt = mb_substr( $post_excerpt, 0, $limit - 25 ); $post_excerpt = mb_substr( $post_excerpt, 0, $limit - 25 );
$post_excerpt = mb_substr( $post_excerpt, 0, mb_strrpos( $post_excerpt, ' ' ) ) . '… '; $post_excerpt = mb_substr( $post_excerpt, 0, mb_strrpos( $post_excerpt, ' ' ) ) . '… ';
$permalink = get_permalink( $post ); $permalink = get_permalink( $post );
$post_excerpt .= ( mb_strlen( $post_excerpt ) + mb_strlen( $permalink ) ) <= $limit ? $permalink : shorten_url( $permalink ); $post_excerpt .= ( mb_strlen( $post_excerpt ) + mb_strlen( $permalink ) ) <= $limit ? $permalink : shorten_url( $permalink );
} }
} }
$post->post_excerpt = $post_excerpt; $post->post_excerpt = $post_excerpt;
// Unhook this function so it doesn't loop infinitely: // Unhook this function so it doesn't loop infinitely:
remove_action( 'save_post', 'share_post', 1, 2 ); remove_action( 'save_post', 'share_post', 1, 2 );
// Update the post, which calls save_post again: // Update the post, which calls save_post again:
wp_update_post( $post ); wp_update_post( $post );
// Re-hook this function: // Re-hook this function:
add_action( 'save_post', 'share_post', 1, 2 ); add_action( 'save_post', 'share_post', 1, 2 );
} }
} }
function shorten_url( $long_url ) { function shorten_url( $long_url ) {
$bitly_login = 'o_7sko9rcpp7'; $bitly_login = 'o_7sko9rcpp7';
$bitly_apikey = 'R_f414bf78d22443c6a6bad3c58921fd96'; $bitly_apikey = 'R_f414bf78d22443c6a6bad3c58921fd96';
$bitly_shorten = "http://api.bit.ly/v3/shorten?login=" . $bitly_login . "&apiKey=" . $bitly_apikey . "&longUrl=" . $long_url . "&format=json"; $bitly_shorten = "http://api.bit.ly/v3/shorten?login=" . $bitly_login . "&apiKey=" . $bitly_apikey . "&longUrl=" . $long_url . "&format=json";
return json_decode( file_get_contents( $bitly_shorten ) )->data->url; return json_decode( file_get_contents( $bitly_shorten ) )->data->url;
} }
/* /*
@ -273,20 +288,20 @@ function shorten_url( $long_url ) {
* *
# add_filter( 'post_thumbnail_html', 'social_post_defautl_thumbnail', 20, 5 ); # add_filter( 'post_thumbnail_html', 'social_post_defautl_thumbnail', 20, 5 );
function social_post_defautl_thumbnail( $html, $post_id, $post_thumbnail_id, $size, $attr ) { function social_post_defautl_thumbnail( $html, $post_id, $post_thumbnail_id, $size, $attr ) {
global $wpdb; global $wpdb;
if ( empty( $html ) ) { if ( empty( $html ) ) {
// Return you Yoast SEO default image if the post thumbnail html is empty: // Return you Yoast SEO default image if the post thumbnail html is empty:
$opt = get_option( 'wpseo_social' ); $opt = get_option( 'wpseo_social' );
$url = $opt['og_default_image']; $url = $opt['og_default_image'];
if ( $id !== '' ) { if ( $id !== '' ) {
// Retrieves the attachment ID from the file URL: // Retrieves the attachment ID from the file URL:
$attachment = $wpdb->get_col( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE guid = '%s';", $url ) ); $attachment = $wpdb->get_col( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE guid = '%s';", $url ) );
$id = $attachment[0]; $id = $attachment[0];
return wp_get_attachment_image( $id, $size ); return wp_get_attachment_image( $id, $size );
} }
} }
return $html; return $html;
} */ } */
/* /*
@ -297,54 +312,54 @@ function social_post_defautl_thumbnail( $html, $post_id, $post_thumbnail_id, $si
add_action( 'admin_head-post.php', 'char_counter_js' ); add_action( 'admin_head-post.php', 'char_counter_js' );
add_action( 'admin_head-post-new.php', 'char_counter_js' ); add_action( 'admin_head-post-new.php', 'char_counter_js' );
function char_counter_js() { function char_counter_js() {
if ( get_post_type() == 'post' ) { echo ' if ( get_post_type() == 'post' ) { echo '
<script> <script>
jQuery(document).ready(function(){ jQuery(document).ready(function(){
var urls_regexp = new RegExp(/https?:\/\/(www\.)?[-a-zA-Z0-9@:%_\+.~#?&//=]{2,256}\.[a-z]{2,4}\b(\/[-a-zA-Z0-9@:%_\+.~#?&//=]*)?/gi); var urls_regexp = new RegExp(/https?:\/\/(www\.)?[-a-zA-Z0-9@:%_\+.~#?&//=]{2,256}\.[a-z]{2,4}\b(\/[-a-zA-Z0-9@:%_\+.~#?&//=]*)?/gi);
function htmlDecode(input){ function htmlDecode(input){
input = input.replace(/(<[a-zA-Z\/][^<>]*>|\[([^\]]+)\])/ig,""); input = input.replace(/(<[a-zA-Z\/][^<>]*>|\[([^\]]+)\])/ig,"");
// https://stackoverflow.com/a/34064434 // https://stackoverflow.com/a/34064434
var doc = new DOMParser().parseFromString(input, "text/html"); var doc = new DOMParser().parseFromString(input, "text/html");
return doc.documentElement.textContent; return doc.documentElement.textContent;
} }
function get_content_length(){ function get_content_length(){
var title_length = htmlDecode(jQuery("#title").val()).length; var title_length = htmlDecode(jQuery("#title").val()).length;
var content = ""; var content = "";
// Are we using visual editor? // Are we using visual editor?
if ((typeof tinyMCE != "undefined") && tinyMCE.activeEditor && !tinyMCE.activeEditor.isHidden()){ if ((typeof tinyMCE != "undefined") && tinyMCE.activeEditor && !tinyMCE.activeEditor.isHidden()){
content = htmlDecode(tinyMCE.activeEditor.getContent()); content = htmlDecode(tinyMCE.activeEditor.getContent());
} }
// Or html editor? // Or html editor?
else { else {
content = htmlDecode(jQuery("#content").val()); content = htmlDecode(jQuery("#content").val());
} }
var content_length = content.length; var content_length = content.length;
var tuit_length = content_length; var tuit_length = content_length;
var urls = content.match(urls_regexp); var urls = content.match(urls_regexp);
if (urls) for (i = 0; i < urls.length; i++) tuit_length = tuit_length - urls[i].length + 23; if (urls) for (i = 0; i < urls.length; i++) tuit_length = tuit_length - urls[i].length + 23;
var return_text = "El título tiene " + title_length.toString() + " caracteres."; var return_text = "El título tiene " + title_length.toString() + " caracteres.";
return_text += " Y el contenido " + content_length.toString(); return_text += " Y el contenido " + content_length.toString();
return_text += content_length != tuit_length ? " (" + tuit_length.toString() + " en Twitter)." : "."; return_text += content_length != tuit_length ? " (" + tuit_length.toString() + " en Twitter)." : ".";
return return_text; return return_text;
} }
jQuery("#wp-content-media-buttons").after("<button id=\"content-counter\" class=\"button\" title=\"Número de caracteres\" href=\"javascript:;\"><strong>#</strong></button>"); jQuery("#wp-content-media-buttons").after("<button id=\"content-counter\" class=\"button\" title=\"Número de caracteres\" href=\"javascript:;\"><strong>#</strong></button>");
jQuery("#content-counter").click(function(e){ alert(get_content_length()); e.preventDefault(); }); jQuery("#content-counter").click(function(e){ alert(get_content_length()); e.preventDefault(); });
function get_excerpt_length(){ function get_excerpt_length(){
var excerpt_length = jQuery("#excerpt").val().length; var excerpt_length = jQuery("#excerpt").val().length;
var tuit_length = excerpt_length; var tuit_length = excerpt_length;
var urls = jQuery("#excerpt").val().match(urls_regexp); var urls = jQuery("#excerpt").val().match(urls_regexp);
if (urls) for (i = 0; i < urls.length; i++) tuit_length = tuit_length - urls[i].length + 23; if (urls) for (i = 0; i < urls.length; i++) tuit_length = tuit_length - urls[i].length + 23;
tuit_length = 140 - tuit_length; tuit_length = 280 - tuit_length;
return excerpt_length.toString() + " / " + tuit_length.toString() + " (Twitter)"; return excerpt_length.toString() + " / " + tuit_length.toString() + " (Twitter)";
} }
jQuery("#postexcerpt .handlediv").after("<div style=\"position:absolute;top:12px;right:34px;color:#666;\"><span id=\"excerpt_counter\"></span></div>"); jQuery("#postexcerpt .handlediv").after("<div style=\"position:absolute;top:12px;right:34px;color:#666;\"><span id=\"excerpt_counter\"></span></div>");
jQuery("span#excerpt_counter").text(get_excerpt_length()); jQuery("span#excerpt_counter").text(get_excerpt_length());
jQuery("#excerpt").keyup(function(){ jQuery("span#excerpt_counter").text(get_excerpt_length()); }); jQuery("#excerpt").keyup(function(){ jQuery("span#excerpt_counter").text(get_excerpt_length()); });
}); });
</script>'; </script>';
} }
} }
/* /*
@ -352,18 +367,18 @@ jQuery(document).ready(function(){
* *
add_action( 'publish_post', 'publish_social_post', 10, 2 ); add_action( 'publish_post', 'publish_social_post', 10, 2 );
function publish_social_post( $ID, $post ) { function publish_social_post( $ID, $post ) {
$auto_post = $_POST['asap_auto_post']; $auto_post = $_POST['asap_auto_post'];
if ( $auto_post == 'yes' || $auto_post == '' ) { if ( $auto_post == 'yes' || $auto_post == '' ) {
$plugin_asap_dir = ABSPATH . 'wp-content/plugins/accesspress-social-auto-post/'; $plugin_asap_dir = ABSPATH . 'wp-content/plugins/accesspress-social-auto-post/';
// Only Facebook and LinkedIn: // Only Facebook and LinkedIn:
include_once( $plugin_asap_dir . 'api/facebook/facebook.php' ); include_once( $plugin_asap_dir . 'api/facebook/facebook.php' );
# include_once( $plugin_asap_dir . 'api/twitter/codebird.php' ); # include_once( $plugin_asap_dir . 'api/twitter/codebird.php' );
# include_once( $plugin_asap_dir . 'api/tumblr/TumblrAPIClient.php' ); # include_once( $plugin_asap_dir . 'api/tumblr/TumblrAPIClient.php' );
include_once( $plugin_asap_dir . 'api/linkedin/liOAuth.php' ); include_once( $plugin_asap_dir . 'api/linkedin/liOAuth.php' );
include( $plugin_asap_dir . 'inc/cores/auto-post.php' ); include( $plugin_asap_dir . 'inc/cores/auto-post.php' );
$check = update_post_meta( $post->ID, 'asap_auto_post', 'no' ); $check = update_post_meta( $post->ID, 'asap_auto_post', 'no' );
$_POST['asap_auto_post'] = 'no'; $_POST['asap_auto_post'] = 'no';
} }
} */ } */
/* /*
@ -371,154 +386,154 @@ function publish_social_post( $ID, $post ) {
* title and meta info. * title and meta info.
*/ */
add_action( 'widgets_init', function() { add_action( 'widgets_init', function() {
register_widget( 'enfold_post_header_widget' ); register_widget( 'enfold_post_header_widget' );
}); });
class enfold_post_header_widget extends WP_Widget { class enfold_post_header_widget extends WP_Widget {
function __construct() { function __construct() {
parent::__construct( parent::__construct(
// Base ID: // Base ID:
'enfold_post_header_widget', 'enfold_post_header_widget',
// Widget name will appear in UI: // Widget name will appear in UI:
__( 'Enfold Cille Post Header', 'avia_framework' ), __( 'Enfold Cille Post Header', 'avia_framework' ),
// Widget description: // Widget description:
array( 'description' => __( 'Display the single post header with the slider, title and meta info', 'avia_framework' ) ) array( 'description' => __( 'Display the single post header with the slider, title and meta info', 'avia_framework' ) )
); );
} }
public function widget( $args, $instance ) { public function widget( $args, $instance ) {
global $avia_config; global $avia_config;
echo $args['before_widget']; echo $args['before_widget'];
$blog_style = avia_get_option( 'single_post_style', 'single-big' ); $blog_style = avia_get_option( 'single_post_style', 'single-big' );
$blog_global_style = avia_get_option( 'blog_global_style', '' ); $blog_global_style = avia_get_option( 'blog_global_style', '' );
$the_id = get_the_ID(); $the_id = get_the_ID();
// Get the current post id, the current post class and current post format: // Get the current post id, the current post class and current post format:
$url = ''; $url = '';
$current_post = array(); $current_post = array();
$current_post['the_id'] = $the_id; $current_post['the_id'] = $the_id;
$current_post['post_type'] = get_post_type( $current_post['the_id'] ); $current_post['post_type'] = get_post_type( $current_post['the_id'] );
$current_post['post_class'] = 'post-entry-' . $current_post['the_id'] . ' ' . $blog_style; $current_post['post_class'] = 'post-entry-' . $current_post['the_id'] . ' ' . $blog_style;
$current_post['post_class'] .= $current_post['post_type'] == 'post' ? '' : ' post'; $current_post['post_class'] .= $current_post['post_type'] == 'post' ? '' : ' post';
$current_post['post_format'] = get_post_format() ? get_post_format() : 'standard'; $current_post['post_format'] = get_post_format() ? get_post_format() : 'standard';
$current_post['post_layout'] = avia_layout_class( 'main', false ); $current_post['post_layout'] = avia_layout_class( 'main', false );
// Retrieve slider and title for this post... // Retrieve slider and title for this post...
$size = strpos( $blog_style, 'big' ) ? strpos( $current_post['post_layout'], 'sidebar' ) !== false ? 'entry_with_sidebar' : 'entry_without_sidebar' : 'square'; $size = strpos( $blog_style, 'big' ) ? strpos( $current_post['post_layout'], 'sidebar' ) !== false ? 'entry_with_sidebar' : 'entry_without_sidebar' : 'square';
if ( ! empty( $avia_config['preview_mode'] ) && ! empty( $avia_config['image_size'] ) && $avia_config['preview_mode'] == 'custom' ) { if ( ! empty( $avia_config['preview_mode'] ) && ! empty( $avia_config['image_size'] ) && $avia_config['preview_mode'] == 'custom' ) {
$size = $avia_config['image_size']; $size = $avia_config['image_size'];
} }
$current_post['slider'] = get_the_post_thumbnail( $current_post['the_id'], $size ); $current_post['slider'] = get_the_post_thumbnail( $current_post['the_id'], $size );
if ( get_post_meta( $current_post['the_id'], '_avia_hide_featured_image', true ) ) { if ( get_post_meta( $current_post['the_id'], '_avia_hide_featured_image', true ) ) {
$current_post['slider'] = ''; $current_post['slider'] = '';
} }
$current_post['title'] = get_the_title(); $current_post['title'] = get_the_title();
// Now apply a filter, based on the post type... (filter function is located in includes/helper-post-format.php): // Now apply a filter, based on the post type... (filter function is located in includes/helper-post-format.php):
$current_post = apply_filters( 'post-format-' . $current_post['post_format'], $current_post ); $current_post = apply_filters( 'post-format-' . $current_post['post_format'], $current_post );
// Extract the variables so that $current_post['slider'] becomes $slider, $current_post['title'] becomes $title, etc... // Extract the variables so that $current_post['slider'] becomes $slider, $current_post['title'] becomes $title, etc...
extract( $current_post ); extract( $current_post );
// Default link and preview image description: // Default link and preview image description:
$link = avia_image_by_id( get_post_thumbnail_id(), 'large', 'url' ); $link = avia_image_by_id( get_post_thumbnail_id(), 'large', 'url' );
$desc = get_post( get_post_thumbnail_id() ); $desc = get_post( get_post_thumbnail_id() );
if ( is_object( $desc ) ) { if ( is_object( $desc ) ) {
$desc = $desc->post_excerpt; $desc = $desc->post_excerpt;
} }
$featured_img_desc = $desc != '' ? $desc : the_title_attribute( 'echo=0' ); $featured_img_desc = $desc != '' ? $desc : the_title_attribute( 'echo=0' );
// Echo preview image: // Echo preview image:
if ( strpos( $blog_global_style, 'elegant-blog' ) === false ) { if ( strpos( $blog_global_style, 'elegant-blog' ) === false ) {
if ( strpos( $blog_style, 'big' ) !== false ) { if ( strpos( $blog_style, 'big' ) !== false ) {
if ( $slider ) $slider = "<a href=\"$link\" title=\"$featured_img_desc\">$slider</a>"; if ( $slider ) $slider = "<a href=\"$link\" title=\"$featured_img_desc\">$slider</a>";
if ( $slider ) echo "<div class=\"big-preview $blog_style\">$slider</div>"; if ( $slider ) echo "<div class=\"big-preview $blog_style\">$slider</div>";
} }
} }
echo '<div class="blog-meta">'; echo '<div class="blog-meta">';
if ( strpos( $blog_style, 'multi' ) !== false ) { if ( strpos( $blog_style, 'multi' ) !== false ) {
$author_name = apply_filters( 'avf_author_name', get_the_author_meta( 'display_name', $post->post_author ), $post->post_author ); $author_name = apply_filters( 'avf_author_name', get_the_author_meta( 'display_name', $post->post_author ), $post->post_author );
$author_email = apply_filters( 'avf_author_email', get_the_author_meta( 'email', $post->post_author ), $post->post_author ); $author_email = apply_filters( 'avf_author_email', get_the_author_meta( 'email', $post->post_author ), $post->post_author );
$link = get_author_posts_url( $post->post_author ); $link = get_author_posts_url( $post->post_author );
} }
echo '</div>'; echo '</div>';
echo '<header class="entry-content-header">'; echo '<header class="entry-content-header">';
$taxonomies = get_object_taxonomies( get_post_type( $the_id ) ); $taxonomies = get_object_taxonomies( get_post_type( $the_id ) );
$cats = ''; $cats = '';
$excluded_taxonomies = array_merge( get_taxonomies( array( 'public' => false ) ), array( 'post_tag', 'post_format' ) ); $excluded_taxonomies = array_merge( get_taxonomies( array( 'public' => false ) ), array( 'post_tag', 'post_format' ) );
$excluded_taxonomies = apply_filters( 'avf_exclude_taxonomies', $excluded_taxonomies, get_post_type( $the_id ), $the_id ); $excluded_taxonomies = apply_filters( 'avf_exclude_taxonomies', $excluded_taxonomies, get_post_type( $the_id ), $the_id );
if ( ! empty( $taxonomies ) ) { if ( ! empty( $taxonomies ) ) {
foreach ( $taxonomies as $taxonomy ) { foreach ( $taxonomies as $taxonomy ) {
if ( ! in_array( $taxonomy, $excluded_taxonomies ) ) { if ( ! in_array( $taxonomy, $excluded_taxonomies ) ) {
$cats .= get_the_term_list( $the_id, $taxonomy, '', ', ', '') . ' '; $cats .= get_the_term_list( $the_id, $taxonomy, '', ', ', '') . ' ';
} }
} }
} }
if ( strpos( $blog_global_style, 'elegant-blog' ) !== false ) { if ( strpos( $blog_global_style, 'elegant-blog' ) !== false ) {
$cat_output = ''; $cat_output = '';
if ( ! empty( $cats ) ) { if ( ! empty( $cats ) ) {
$cat_output .= '<span class="blog-categories minor-meta">'; $cat_output .= '<span class="blog-categories minor-meta">';
$cat_output .= $cats; $cat_output .= $cats;
$cat_output .= '</span>'; $cat_output .= '</span>';
$cats = ''; $cats = '';
} }
echo strpos( $blog_global_style, 'modern-blog' ) === false ? $cat_output . $title : $title . $cat_output; echo strpos( $blog_global_style, 'modern-blog' ) === false ? $cat_output . $title : $title . $cat_output;
echo '<span class="av-vertical-delimiter"></span>'; echo '<span class="av-vertical-delimiter"></span>';
if ( strpos( $blog_style, 'big' ) !== false ) { if ( strpos( $blog_style, 'big' ) !== false ) {
if ( $slider ) $slider = "<a href=\"$link\" title=\"$featured_img_desc\">$slider</a>"; if ( $slider ) $slider = "<a href=\"$link\" title=\"$featured_img_desc\">$slider</a>";
if ( $slider ) echo "<div class=\"big-preview $blog_style\">$slider</div>"; if ( $slider ) echo "<div class=\"big-preview $blog_style\">$slider</div>";
} }
$cats = ''; $cats = '';
$title = ''; $title = '';
} }
echo $title; echo $title;
echo '<span class="post-meta-infos">'; echo '<span class="post-meta-infos">';
echo '<time class="date-container minor-meta updated">' . get_the_time( get_option( 'date_format' ) ) . '</time>'; echo '<time class="date-container minor-meta updated">' . get_the_time( get_option( 'date_format' ) ) . '</time>';
echo '<span class="text-sep text-sep-date">/</span>'; echo '<span class="text-sep text-sep-date">/</span>';
if ( get_comments_number() != '0' || comments_open() ) { if ( get_comments_number() != '0' || comments_open() ) {
echo '<span class="comment-container minor-meta">'; echo '<span class="comment-container minor-meta">';
comments_popup_link( '0 ' . __( 'Comments', 'avia_framework' ), comments_popup_link( '0 ' . __( 'Comments', 'avia_framework' ),
'1 ' . __( 'Comment' , 'avia_framework' ), '1 ' . __( 'Comment' , 'avia_framework' ),
'% ' . __( 'Comments', 'avia_framework' ), 'comments-link', '% ' . __( 'Comments', 'avia_framework' ), 'comments-link',
'' . __( 'Comments Disabled', 'avia_framework' ) ); '' . __( 'Comments Disabled', 'avia_framework' ) );
echo '</span>'; echo '</span>';
echo '<span class="text-sep text-sep-comment">/</span>'; echo '<span class="text-sep text-sep-comment">/</span>';
} }
if ( ! empty( $cats ) ) { if ( ! empty( $cats ) ) {
echo '<span class="blog-categories minor-meta">' . __( 'in', 'avia_framework' ) . ' '; echo '<span class="blog-categories minor-meta">' . __( 'in', 'avia_framework' ) . ' ';
echo $cats; echo $cats;
echo '</span><span class="text-sep text-sep-cat">/</span>'; echo '</span><span class="text-sep text-sep-cat">/</span>';
} }
echo '<span class="blog-author minor-meta">' . __( 'by', 'avia_framework' ) . ' '; echo '<span class="blog-author minor-meta">' . __( 'by', 'avia_framework' ) . ' ';
echo '<span class="entry-author-link">'; echo '<span class="entry-author-link">';
echo '<span class="vcard author"><span class="fn">'; echo '<span class="vcard author"><span class="fn">';
the_author_posts_link(); the_author_posts_link();
echo '</span></span>'; echo '</span></span>';
echo '</span>'; echo '</span>';
echo '</span>'; echo '</span>';
echo '</span>'; echo '</span>';
echo '</header>'; echo '</header>';
echo $args['after_widget']; echo $args['after_widget'];
} }
} }
/* /*
@ -527,34 +542,34 @@ class enfold_post_header_widget extends WP_Widget {
* See http://www.wpbeginner.com/wp-tutorials/how-to-create-a-custom-wordpress-widget/ * See http://www.wpbeginner.com/wp-tutorials/how-to-create-a-custom-wordpress-widget/
*/ */
add_action( 'widgets_init', function() { add_action( 'widgets_init', function() {
register_widget( 'enfold_post_footer_widget' ); register_widget( 'enfold_post_footer_widget' );
}); });
class enfold_post_footer_widget extends WP_Widget { class enfold_post_footer_widget extends WP_Widget {
function __construct() { function __construct() {
parent::__construct( parent::__construct(
// Base ID: // Base ID:
'enfold_post_footer_widget', 'enfold_post_footer_widget',
// Widget name will appear in UI: // Widget name will appear in UI:
__( 'Enfold Cille Post Footer', 'avia_framework' ), __( 'Enfold Cille Post Footer', 'avia_framework' ),
// Widget description: // Widget description:
array( 'description' => __( 'Display the single post footer with the tags, social share links and related posts', 'avia_framework' ) ) array( 'description' => __( 'Display the single post footer with the tags, social share links and related posts', 'avia_framework' ) )
); );
} }
public function widget( $args, $instance ) { public function widget( $args, $instance ) {
echo $args['before_widget']; echo $args['before_widget'];
echo '<footer class="entry-footer">'; echo '<footer class="entry-footer">';
if ( has_tag() ) { if ( has_tag() ) {
echo '<span class="blog-tags minor-meta">'; echo '<span class="blog-tags minor-meta">';
echo the_tags( '<strong>' . __( 'Tags:', 'avia_framework' ) . '</strong><span> ' ); echo the_tags( '<strong>' . __( 'Tags:', 'avia_framework' ) . '</strong><span> ' );
echo '</span></span>'; echo '</span></span>';
} }
avia_social_share_links(); avia_social_share_links();
echo '</footer>'; echo '</footer>';
echo '<div style="margin-top: 172px;">'; echo '<div style="margin-top: 172px;">';
echo get_template_part( '../enfold/includes/related-posts'); echo get_template_part( '../enfold/includes/related-posts');
echo '</div>'; echo '</div>';
echo $args['after_widget']; echo $args['after_widget'];
} }
} }
/* /*
@ -563,7 +578,7 @@ class enfold_post_footer_widget extends WP_Widget {
*/ */
add_action( 'init', 'avia_remove_debug' ); add_action( 'init', 'avia_remove_debug' );
function avia_remove_debug() { function avia_remove_debug() {
remove_action( 'wp_head', 'avia_debugging_info', 1000 ); remove_action( 'wp_head', 'avia_debugging_info', 1000 );
} }
/* /*

View file

@ -634,6 +634,10 @@ a.dpe-flexible-photos-link:hover {
.av-share-box ul li a { .av-share-box ul li a {
font-size: 18px; font-size: 18px;
} }
#top #wrap_all .av-social-link-github:hover a {
color: #fff;
background-color: #bd2c00;
}
/* Search box adjustment */ /* Search box adjustment */
#top #s, #top #s,
#top #searchsubmit { #top #searchsubmit {