Commit inicial - WordPress Análisis de Precios Unitarios

- WordPress core y plugins
- Tema Twenty Twenty-Four configurado
- Plugin allow-unfiltered-html.php simplificado
- .gitignore configurado para excluir wp-config.php y uploads

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
root
2025-11-03 21:04:30 -06:00
commit a22573bf0b
24068 changed files with 4993111 additions and 0 deletions

View File

@@ -0,0 +1,58 @@
@import url(//fonts.googleapis.com/css?family=Source+Sans+Pro:400,300,700,300italic);
.font-manager-settings {
background: #fff;
border: 1px solid #E1E1E1;
margin: 0 20px 0 0;
padding: 25px;
color: #323232;
font-family: 'Source Sans Pro', sans-serif;
}
.font-manager-settings h3 {
border-bottom: 1px solid #e1e1e1;
font-weight: 300;
font-style: italic;
font-size: 25px;
padding-bottom: 10px;
padding-top: 0px;
margin: 0;
}
#ttfm-custom-css {
width: 100%;
}
.tvd-fm-color {
border: 1px solid #5c5c5c;
display: inline-block;
height: 20px;
width: 20px;
}
.form-table.postEdit {
max-width: 100%;
}
.form-table th {
color: #323232;
font-weight: 400;
font-size: 18px;
}
.form-table td, th {
border-bottom: 1px dashed #efefef;
padding-top: 15px;
padding-bottom: 15px;
}
.form-table label.btn {
border: 1px solid #f5f5f5;
margin: 0px;
padding: 6px;
}
.tvd-btn i {
font-size: 14px !important;
margin-right: 5px;
}

View File

@@ -0,0 +1,260 @@
<?php
/**
* Thrive Themes - https://thrivethemes.com
*
* @package thrive-dashboard
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Silence is golden!
}
/* Display font manager admin interface */
function tve_dash_font_manager_main_page() {
$font_options = is_array( json_decode( get_option( 'thrive_font_manager_options' ), true ) ) ? json_decode( get_option( 'thrive_font_manager_options' ), true ) : array();
$last_option = end( $font_options );
$font_id = intval( $last_option['font_id'] ) + 1;
include 'views/admin-font-manager.php';
}
add_action( 'admin_enqueue_scripts', 'tve_dash_font_manager_include_scripts' );
function tve_dash_font_manager_include_scripts( $hook ) {
$allowed = array(
'admin_page_tve_dash_font_manager',
'admin_page_tve_dash_font_import_manager',
);
if ( ! in_array( $hook, $allowed ) ) {
return;
}
tve_dash_enqueue();
if ( $hook == 'admin_page_tve_dash_font_import_manager' && ! empty( $_POST['attachment_id'] ) && $_POST['attachment_id'] != "-1" && count( $_POST ) == 1 ) {
/**
* we don't want to load dash style.css when WP FTP form is displayed
*/
wp_deregister_style( 'tve-dash-styles-css' );
}
if ( $hook == 'admin_page_tve_dash_font_import_manager' ) {
wp_enqueue_media();
tve_dash_enqueue_style( 'tve-dash-font-import-manager-css', TVE_DASH_URL . '/inc/font-import-manager/views/css/manager.css' );
tve_dash_enqueue_script( 'tve-dash-font-import-manager-js', TVE_DASH_URL . '/inc/font-import-manager/views/js/manager.js', array(
'jquery',
'media-upload',
'thickbox',
) );
}
if ( $hook == 'admin_page_tve_dash_font_manager' ) {
add_thickbox();
wp_enqueue_script( 'wp-color-picker' );
wp_enqueue_style( 'wp-color-picker' );
tve_dash_enqueue_style( 'tve-dash-font-manager', TVE_DASH_URL . '/inc/font-manager/css/style.css' );
}
}
add_action( "wp_ajax_tve_dash_font_manager_update_posts_fonts", "tve_dash_font_manager_update_posts_fonts" );
function tve_dash_font_manager_update_posts_fonts() {
check_ajax_referer( 'tve-dash' );
if ( ! current_user_can( TVE_DASH_CAPABILITY ) ) {
wp_die( '' );
}
$posts = get_posts( array( 'posts_per_page' => - 1 ) );
foreach ( $posts as $post ) {
$post_id = $post->ID;
$post_content = $post->post_content;
preg_match_all( "/thrive_custom_font id='\d+'/", $post_content, $font_ids );
$post_fonts = array();
foreach ( $font_ids[0] as $font_id ) {
$parts = explode( "'", $font_id );
$id = $parts[1];
$font = thrive_get_font_options( $id );
if ( tve_dash_font_manager_is_safe_font( $font->font_name ) ) {
continue;
}
if ( Tve_Dash_Font_Import_Manager::isImportedFont( $font->font_name ) ) {
$post_fonts[] = Tve_Dash_Font_Import_Manager::getCssFile();
continue;
}
$post_fonts[] = "//fonts.googleapis.com/css?family=" . str_replace( " ", "+", $font->font_name ) . ( $font->font_style != 0 ? ":" . $font->font_style : "" ) . ( $font->font_italic ? "" . $font->font_italic : "" ) . ( $font->font_bold != 0 ? "," . $font->font_bold : "" ) . ( $font->font_character_set != 0 ? "&subset=" . $font->font_character_set : "" );
}
$post_fonts = array_unique( $post_fonts );
update_post_meta( $post_id, 'thrive_post_fonts', sanitize_text_field( json_encode( $post_fonts ) ) );
}
die;
}
function tve_dash_font_manager_get_safe_fonts() {
return $safe_fonts = array(
array(
'family' => 'Georgia, serif',
'variants' => array( 'regular', 'italic', '600' ),
'subsets' => array( 'latin' ),
),
array(
'family' => 'Palatino Linotype, Book Antiqua, Palatino, serif',
'variants' => array( 'regular', 'italic', '600' ),
'subsets' => array( 'latin' ),
),
array(
'family' => 'Times New Roman, Times, serif',
'variants' => array( 'regular', 'italic', '600' ),
'subsets' => array( 'latin' ),
),
array(
'family' => 'Arial, Helvetica, sans-serif',
'variants' => array( 'regular', 'italic', '600' ),
'subsets' => array( 'latin' ),
),
array(
'family' => 'Arial Black, Gadget, sans-serif',
'variants' => array( 'regular', 'italic', '600' ),
'subsets' => array( 'latin' ),
),
array(
'family' => 'Comic Sans MS, cursive, sans-serif',
'variants' => array( 'regular', 'italic', '600' ),
'subsets' => array( 'latin' ),
),
array(
'family' => 'Impact, Charcoal, sans-serif',
'variants' => array( 'regular', 'italic', '600' ),
'subsets' => array( 'latin' ),
),
array(
'family' => 'Lucida Sans Unicode, Lucida Grande, sans-serif',
'variants' => array( 'regular', 'italic', '600' ),
'subsets' => array( 'latin' ),
),
array(
'family' => 'Tahoma, Geneva, sans-serif',
'variants' => array( 'regular', 'italic', '600' ),
'subsets' => array( 'latin' ),
),
array(
'family' => 'Trebuchet MS, Helvetica, sans-serif',
'variants' => array( 'regular', 'italic', '600' ),
'subsets' => array( 'latin' ),
),
array(
'family' => 'Verdana, Geneva, sans-serif',
'variants' => array( 'regular', 'italic', '600' ),
'subsets' => array( 'latin' ),
),
array(
'family' => 'Courier New, Courier, monospace',
'variants' => array( 'regular', 'italic', '600' ),
'subsets' => array( 'latin' ),
),
array(
'family' => 'Lucida Console, Monaco, monospace',
'variants' => array( 'regular', 'italic', '600' ),
'subsets' => array( 'latin' ),
),
);
}
function tve_dash_font_manager_is_safe_font( $font_family ) {
foreach ( tve_dash_font_manager_get_safe_fonts() as $font ) {
if ( $font_family === $font['family'] ) {
return true;
}
}
return false;
}
function tve_dash_font_manager_get_safe_font( $font_family ) {
foreach ( tve_dash_font_manager_get_safe_fonts() as $font ) {
if ( $font['family'] === $font_family ) {
return $font;
}
}
return array();
}
function tve_dash_get_font_family_array( $font_name = null ) {
if ( $font_name === false ) {
return false;
}
$font_name = str_replace( " ", "", trim( $font_name ) );
$fonts = array(
'AbrilFatface' => "font-family: 'Abril Fatface', cursive;",
'Amatic SC' => "font-family: 'Amatic SC', cursive;",
'Archivo Black' => "font-family: 'Archivo Black', sans-serif;",
'Arbutus Slab' => "font-family: 'Arbutus Slab', serif;",
'Archivo Narrow' => "font-family: 'Archivo Narrow', sans-serif;",
'Arial' => "font-family: 'Arial';",
'Arimo' => "font-family: 'Arimo', sans-serif;",
'Arvo' => "font-family: 'Arvo', serif;",
'Boogaloo' => "font-family: 'Boogaloo', cursive;",
'Calligraffitti' => "font-family: 'Calligraffitti', cursive;",
'CantataOne' => "font-family: 'Cantata One', serif;",
'Cardo' => "font-family: 'Cardo', serif;",
'Cutive' => "font-family: 'Cutive', serif;",
'DaysOne' => "font-family: 'Days One', sans-serif;",
'Dosis' => "font-family: 'Dosis', sans-serif;",
'Droid Sans' => "font-family: 'Droid Sans', sans-serif;",
'Droid Serif' => "font-family: 'Droid Serif', sans-serif;",
'FjallaOne' => "font-family: 'Fjalla One', sans-serif;",
'FrancoisOne' => "font-family: 'Francois One', sans-serif;",
'Georgia' => "font-family: 'Georgia';",
'GravitasOne' => "font-family: 'Gravitas One', cursive;",
'Helvetica' => "font-family: 'Helvetica';",
'JustAnotherHand' => "font-family: 'Just Another Hand', cursive;",
'Josefin Sans' => "font-family: 'Josefin Sans', sans-serif;",
'Josefin Slab' => "font-family: 'Josefin Slab', serif;",
'Lobster' => "font-family: 'Lobster', cursive;",
'Lato' => "font-family: 'Lato', sans-serif;",
'Montserrat' => "font-family: 'Montserrat', sans-serif;",
'NotoSans' => "font-family: 'Noto Sans', sans-serif;",
'OleoScript' => "font-family: 'Oleo Script', cursive;",
'Old Standard TT' => "font-family: 'Old Standard TT', serif;",
'Open Sans' => "font-family: 'Open Sans', sans-serif;",
'Oswald' => "font-family: 'Oswald', sans-serif;",
'OpenSansCondensed' => "font-family: 'Open Sans Condensed', sans-serif;",
'Oxygen' => "font-family: 'Oxygen', sans-serif;",
'Pacifico' => "font-family: 'Pacifico', cursive;",
'Playfair Display' => "font-family: 'Playfair Display', serif;",
'Poiret One' => "font-family: 'Poiret One', cursive;",
'PT Sans' => "font-family: 'PT Sans', sans-serif;",
'PT Serif' => "font-family: 'PT Serif', sans-serif;",
'Raleway' => "font-family: 'Raleway', sans-serif;",
'Roboto' => "font-family: 'Roboto', sans-serif;",
'Roboto Condensed' => "font-family: 'Roboto Condensed', sans-serif;",
'Roboto Slab' => "font-family: 'Roboto Slab', serif;",
'ShadowsIntoLightTwo' => "font-family: 'Shadows Into Light Two', cursive;",
'Source Sans Pro' => "font-family: 'Source Sans Pro', sans-serif;",
'Sorts Mill Gaudy' => "font-family: 'Sorts Mill Gaudy', cursive;",
'SpecialElite' => "font-family: 'Special Elite', cursive;",
'Tahoma' => "font-family: 'Tahoma';",
'TimesNewRoman' => "font-family: 'Times New Roman';",
'Ubuntu' => "font-family: 'Ubuntu', sans-serif;",
'Ultra' => "font-family: 'Ultra', serif;",
'VarelaRound' => "font-family: 'Varela Round', sans-serif;",
'Verdana' => "font-family: 'Verdana';",
'Vollkorn' => "font-family: 'Vollkorn', serif;",
);
if ( $font_name ) {
if ( isset( $fonts[ $font_name ] ) ) {
return $fonts[ $font_name ];
} else {
return false;
}
}
return $fonts;
}

View File

@@ -0,0 +1,80 @@
<?php
/**
* Thrive Themes - https://thrivethemes.com
*
* @package thrive-dashboard
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Silence is golden!
}
include TVE_DASH_PATH . '/templates/header.phtml'; ?>
<div class="tvd-v-spacer vs-2"></div>
<div class="font-manager-settings">
<h3><?php echo esc_html__( "Custom Font Manager", 'thrive-dash' ); ?></h3>
<?php if ( 1 === 2 ) : ?>
<p>
<?php echo esc_html__( "By default, Thrive Themes integrates with Google Fonts. This allows you to choose from 600+ fonts for use in your content. However, you can also use the blue import font button below to import your own fonts files using a service called Font Squirrel" ); ?>
<a href="https://thrivethemes.com/tkb_item/how-to-use-the-font-import-manager/" target="_blank"><?php echo esc_html__( "Learn more about how to import your own fonts", 'thrive' ) ?></a>
</p>
<div class="tvd-row">
<a class="tvd-waves-effect tvd-waves-light tvd-btn-small tvd-btn-blue" href="<?php echo esc_url( admin_url( "admin.php?page=tve_dash_font_import_manager" ) ) ?>">
<?php echo esc_html__( "Import custom font manager", 'thrive-dash' ) ?>
</a>
</div>
<?php endif; ?>
<div>
<div class="tvd-row">
<h3 class="tvd-col tvd-m2 tvd-s1">
<?php echo esc_html__( "Font name", 'thrive-dash' ) ?>
</h3>
<h3 class="tvd-col tvd-m2 tvd-s1">
<?php echo esc_html__( "Size", 'thrive-dash' ) ?>
</h3>
<h3 class="tvd-col tvd-m2 tvd-s1">
<?php echo esc_html__( "Color", 'thrive-dash' ) ?>
</h3>
<h3 class="tvd-col tvd-m6 tvd-s1">
<?php echo esc_html__( "CSS Class Name", 'thrive-dash' ) ?>
</h3>
</div>
<?php foreach ( $font_options as $font ): ?>
<div class="tvd-row">
<div class="tvd-col tvd-m2 tvd-s1"><?php echo esc_html( $font['font_name'] ); ?></div>
<div class="tvd-col tvd-m2 tvd-s1"><?php echo esc_html( $font['font_size'] ); ?></div>
<div class="tvd-col tvd-m2 tvd-s1">
<span class="tvd-fm-color" style="background-color: <?php echo esc_attr( $font['font_color'] ); ?>;">&nbsp;</span>
<?php echo empty( $font['font_color'] ) ? esc_html__( 'white', 'thrive-dash' ) : esc_html( $font['font_color'] ); ?>
</div>
<div class="tvd-col tvd-m2 tvd-s1">
<input type="text" readonly value="<?php echo esc_attr( $font['font_class'] ); ?>">
</div>
</div>
<?php endforeach; ?>
</div>
<div class="tvd-row" style="margin-top: 5px;">
<div class="tvd-col tvd-m6">
<a href="<?php echo esc_url( admin_url( 'admin.php?page=tve_dash_section' ) ); ?>" class="tvd-waves-effect tvd-waves-light tvd-btn-small tvd-btn-gray">
<?php echo esc_html__( "Back To Dashboard", 'thrive-dash' ); ?>
</a>
</div>
<div class="tvd-col tvd-m6">
<input type="hidden" value="<?php echo esc_attr( $font_id ); ?>" id='new-font-id'/>
<a style="margin-right: 5px;" class="tvd-waves-effect tvd-waves-light tvd-btn-small tvd-btn-blue tvd-right" id="thrive-update-posts" href="javascript:void(0)">
<i style="display: none;" class="tvd-icon-spinner mdi-pulse"></i> <?php echo esc_html__( "Update Posts", 'thrive-dash' ); ?>
</a>
</div>
</div>
</div>
<script type="text/javascript">
jQuery( document ).ready( function () {
jQuery( '#thrive-update-posts' ).click( function () {
var loading = jQuery( this ).find( 'i' );
loading.show();
jQuery.post( 'admin-ajax.php?action=tve_dash_font_manager_update_posts_fonts' + '&_wpnonce=' + TVE_Dash_Const.nonce, function ( response ) {
loading.hide();
} );
} );
} );
</script>

View File

@@ -0,0 +1,499 @@
<?php
/**
* Thrive Themes - https://thrivethemes.com
*
* @package thrive-dashboard
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Silence is golden!
}
$all_fonts = tve_dash_get_font_family_array();
$link = 'https://www.googleapis.com/webfonts/v1/webfonts?key=';
$key = '[REDACTED]';
$request = wp_remote_get( $link . $key, array( 'sslverify' => false ) );
$response = json_decode( wp_remote_retrieve_body( $request ), true );
$google_fonts = $response['items'];
$safe_fonts = tve_dash_font_manager_get_safe_fonts();
$imported_fonts = Tve_Dash_Font_Import_Manager::getImportedFonts();
$imported_fonts_css = Tve_Dash_Font_Import_Manager::getCssFile();
$prefered_fonts = array();
if ( ! empty( $google_fonts ) ) {
foreach ( $google_fonts as $key => $f ) {
if ( array_key_exists( $f['family'], $all_fonts ) ) {
$prefered_fonts[] = $f;
}
}
}
$font_id = ! empty( $_GET['font_id'] ) ? sanitize_text_field( $_GET['font_id'] ) : null;
if ( isset( $_GET['font_action'] ) && sanitize_text_field( $_GET['font_action'] ) === 'update' ) {
$options = json_decode( get_option( 'thrive_font_manager_options' ), true );
foreach ( $options as $option ) {
if ( $option['font_id'] == $font_id ) {
$font = $option;
}
}
$admin_font_manager_link = "admin-ajax.php?action=tve_dash_font_manager_edit";
} else {
$admin_font_manager_link = "admin-ajax.php?action=tve_dash_font_manager_add";
}
?>
<div class="font-manager-settings" style="margin: 20px">
<div id="fontPreview" style="font-size: 20px; margin-bottom: 10px;">
Grumpy wizards make toxic brew for the evil Queen and Jack.
</div>
<hr>
<div>
<div>
<input type="radio" name="display_fonts" id="ttfm_google_fonts" value="google_fonts"/>
<label for="ttfm_google_fonts"> <?php echo esc_html__( "Show all fonts", 'thrive-dash' ); ?></label>
</div>
<div>
<input type="radio" name="display_fonts" id="ttfm_prefered_fonts" value="prefered_fonts" checked/>
<label
for="ttfm_prefered_fonts"><?php echo esc_html__( "Recommended Fonts Only", 'thrive-dash' ); ?></label>
</div>
<div>
<input type="radio" name="display_fonts" id="ttfm_safe_fonts" value="safe_fonts"/>
<label for="ttfm_safe_fonts"><?php echo esc_html__( "Web Safe Fonts", 'thrive-dash' ); ?></label>
</div>
<div>
<input type="radio" name="display_fonts" id="ttfm_imported_fonts" value="imported_fonts"/>
<label for="ttfm_imported_fonts"><?php echo esc_html__( "Imported Fonts", 'thrive-dash' ); ?></label>
</div>
<div class="tvd-row">
<a target="_blank" href="//www.google.com/fonts" class="tvd-right">
<?php echo esc_html__( "View All Google Font Previews", 'thrive-dash' ); ?>
</a>
</div>
</div>
<div class="tvd-row input-field">
<select id="ttfm_fonts">
<option value="none" disabled
selected><?php echo esc_html__( "- Select Font -", 'thrive-dash' ); ?></option>
<?php foreach ( $prefered_fonts as $name => $f ): ?>
<option data-url='<?php echo esc_url( json_encode( $f['files'] ) ); ?>'
<?php if ( isset( $f['font_name'] ) && $f['family'] == $f['font_name'] ) {
echo 'selected';
} ?>
value="<?php echo esc_attr( $f['family'] ); ?>">
<?php echo esc_html( $f['family'] ); ?>
</option>
<?php endforeach; ?>
</select>
</div>
<div class="tvd-row">
<div id="ttfm-font-regular" class="tvd-col tvd-m4 tvd-s12"></div>
<div id="ttfm-font-bold" class="tvd-col tvd-m4 tvd-s12"></div>
<div id="ttfm-font-subsets" class="tvd-col tvd-m4 tvd-s12"></div>
</div>
<div style="clear: both"></div>
<hr>
<div>
<div class="tvd-row">
<div class="tvd-col tvd-m4"><?php echo esc_html__( "Class", 'thrive-dash' ); ?></div>
<div class="tvd-col tvd-m8">
<input id="ttfm-font-class" type="text" readonly value="ttfm<?php echo esc_attr( $font_id ); ?>">
</div>
</div>
<div id="ttfm-font-size" class="tvd-row">
<div class="tvd-col tvd-m4 tvd-s12"><?php echo esc_html__( "Size", 'thrive-dash' ); ?></div>
<div class="tvd-col tvd-m4 tvd-s12">
<input min="0"
type="number" <?php if ( ! empty( $font['font_size'] ) && $font['font_size'] != (int) $font['font_size'] ): ?> step="0.1" <?php endif; ?>
value="<?php echo empty( $font['font_size'] ) ? '1.6' : floatval( $font['font_size'] ); ?>">
</div>
<div class="tvd-col tvd-m4 tvd-s12 input-field">
<select>
<option <?php if ( isset( $font['font_size'] ) && strpos( $font['font_size'], 'em' ) > 0 ) {
echo 'selected';
} ?>>
em
</option>
<option <?php if ( isset( $font['font_size'] ) && strpos( $font['font_size'], 'px' ) > 0 ) {
echo 'selected';
} ?>>
px
</option>
<option <?php if ( isset( $font['font_size'] ) && strpos( $font['font_size'], '%' ) > 0 ) {
echo 'selected';
} ?>>
%
</option>
</select>
</div>
</div>
<div id="ttfm-font-height" class="tvd-row">
<div class="tvd-col tvd-m4 tvd-s12"><?php echo esc_html__( "Line Height", 'thrive-dash' ); ?></div>
<div class="tvd-col tvd-m4 tvd-s12">
<input min="0"
type="number" <?php if ( ! empty( $font['font_height'] ) && $font['font_height'] != (int) $font['font_height'] ): ?> step="0.1" <?php endif; ?>
value="<?php echo empty( $font['font_height'] ) ? '1.6' : floatval( $font['font_height'] ); ?>">
</div>
<div class="tvd-col tvd-m4 tvd-s12 input-field">
<select>
<option <?php if ( isset( $font['font_height'] ) && strpos( $font['font_height'], 'em' ) > 0 ) {
echo 'selected';
} ?>>
em
</option>
<option <?php if ( isset( $font['font_height'] ) && strpos( $font['font_height'], 'px' ) > 0 ) {
echo 'selected';
} ?>>
px
</option>
<option <?php if ( isset( $font['font_height'] ) && strpos( $font['font_height'], '%' ) > 0 ) {
echo 'selected';
} ?>>
%
</option>
</select>
</div>
</div>
<div class="tvd-row">
<div class="tvd-col tvd-m4"><?php echo esc_html__( "Color", 'thrive-dash' ); ?></div>
<div class="tvd-col tvd-m8">
<input type="text" value="<?php if ( isset( $font['font_color'] ) ) {
echo esc_attr( $font['font_color'] );
} ?>"
class="wp-color-picker-field" data-default-color="#ffffff"/>
</div>
</div>
<div class="tvd-row">
<div class="tvd-col tvd-m4"><?php echo esc_html__( "Custom CSS", 'thrive-dash' ); ?></div>
<div class="tvd-col tvd-m8">
<textarea
id="ttfm-custom-css"><?php if ( isset( $font['custom_css'] ) ) {
echo esc_textarea( $font['custom_css'] );
} ?></textarea>
</div>
</div>
</div>
<hr>
<button id="ttfm_save_font_options"
class="tvd-waves-effect tvd-waves-light tvd-btn-small tvd-btn-green tvd-right"><?php echo esc_html__( "Save", 'thrive-dash' ) ?></button>
<div class="clear"></div>
</div>
<script type="text/javascript">
jQuery( '#TB_window' ).addClass( 'fmp' );
jQuery( document ).ready( function ( $ ) {
$( 'select' ).select2();
$( '.wp-color-picker-field' ).wpColorPicker();
window.prefered_fonts = <?php echo json_encode( $prefered_fonts ); ?>;
window.google_fonts = <?php echo json_encode( $google_fonts ); ?>;
window.safe_fonts = <?php echo json_encode( $safe_fonts ); ?>;
window.imported_fonts = <?php echo json_encode( $imported_fonts ); ?>;
window.imported_fonts_css = '<?php echo $imported_fonts_css; ?>';
window.selected_fonts_set = jQuery( 'input[name="display_fonts"]:checked' ).val();
var update_font = '<?php echo empty( $font['font_name'] ) ? 0 : esc_js( $font['font_name'] ); ?>',
current_font = <?php echo json_encode( empty( $font ) ? array() : $font ) ?>,
font_variants;
rewriteSettings( current_font );
jQuery( '#ttfm_fonts' ).change( function () {
jQuery( '#ttfm-font-regular' ).html( '<b>Regular Style</b> <br />' );
jQuery( '#ttfm-font-bold' ).html( '<b>Bold Style</b> <br />' );
jQuery( '#ttfm-font-subsets' ).html( '<b>Character Set</b><br/>' );
for ( var i in window[selected_fonts_set] ) {
if ( window[selected_fonts_set][i].family == jQuery( this ).val() ) {
font_variants = window[selected_fonts_set][i].variants;
for ( var j in window[selected_fonts_set][i].variants ) {
jQuery( '<input>' ).attr( {
id: 'tve-dash-regular-' + font_variants[j],
type: 'radio',
name: 'ttfm-font-style',
value: font_variants[j],
checked: font_variants[j] == current_font.font_style
} ).appendTo( '#ttfm-font-regular' );
jQuery( '#ttfm-font-regular' ).append( '<label for="tve-dash-regular-' + font_variants[j] + '">' + font_variants[j] + '</label><br/>' );
if ( window[selected_fonts_set][i].variants[j] > 400 ) {
jQuery( '<input>' ).attr( {
id: 'tve-dash-bold-' + font_variants[j],
type: 'radio',
name: 'ttfm-font-bold',
value: font_variants[j],
checked: font_variants[j] == current_font.font_bold
} ).appendTo( '#ttfm-font-bold' );
jQuery( '#ttfm-font-bold' ).append( '<label for="tve-dash-bold-' + font_variants[j] + '">' + font_variants[j] + '</label><br/>' );
}
}
for ( j in window[selected_fonts_set][i].subsets ) {
jQuery( '<input/>' ).attr( {
id: 'tve-dash-character-' + window[selected_fonts_set][i].subsets[j],
type: 'radio',
name: 'ttfm-font-character-sets',
value: window[selected_fonts_set][i].subsets[j],
checked: window[selected_fonts_set][i].subsets[j] == current_font.font_character_set
} ).appendTo( '#ttfm-font-subsets' );
jQuery( '#ttfm-font-subsets' ).append( '<label for="tve-dash-character-' + window[selected_fonts_set][i].subsets[j] + '">' + window[selected_fonts_set][i].subsets[j] + '</label><br/>' );
}
/* check default values for new fonts */
if ( current_font.length == 0 ) {
jQuery( 'input[name="ttfm-font-style"]' ).filter( function () {
return this.value == 'regular'
} ).prop( 'checked', true );
jQuery( 'input[name="ttfm-font-character-sets"]' ).filter( function () {
return this.value == 'latin'
} ).prop( 'checked', true );
}
}
}
importFont();
} );
jQuery( document ).on( 'change', 'input#ttfm_google_fonts', function () {
add_fonts( google_fonts );
window.selected_fonts_set = this.value;
$( 'select' ).select2();
} );
jQuery( document ).on( 'change', 'input#ttfm_prefered_fonts', function () {
add_fonts( prefered_fonts );
window.selected_fonts_set = this.value;
$( 'select' ).select2();
} );
jQuery( document ).on( 'change', 'input#ttfm_safe_fonts', function () {
add_fonts( safe_fonts );
window.selected_fonts_set = this.value;
$( 'select' ).select2();
} );
jQuery( document ).on( 'change', 'input#ttfm_imported_fonts', function () {
add_fonts( imported_fonts );
window.selected_fonts_set = this.value;
$( 'select' ).select2();
} );
function isSafeFont( font ) {
var _isSafeFont = false;
jQuery( safe_fonts ).each( function ( index, safe_font ) {
if ( font === safe_font.family ) {
_isSafeFont = true;
return;
}
} );
return _isSafeFont;
}
function isImportedFont( font ) {
var _isImportedFont = false;
jQuery( imported_fonts ).each( function ( index, imported_font ) {
if ( font === imported_font.family ) {
_isImportedFont = true;
return;
}
} );
return _isImportedFont;
}
function add_fonts( fonts ) {
jQuery( '#ttfm_fonts option' ).remove();
var select = jQuery( '#ttfm_fonts' );
for ( var i in fonts ) {
select.append( $( '<option>', {
text: fonts[i].family,
value: fonts[i].family,
selected: fonts[i].family == current_font.font_name
} ) );
}
setTimeout( function () {
select.trigger( 'change' );
}, 100 );
}
jQuery( document ).on( 'change', 'input[name="ttfm-font-style"]', function () {
if ( jQuery( '#ttfm_fonts' ).val() != 'none' ) {
importFont();
}
} );
jQuery( '#ttfm_save_font_options' ).click( function () {
if ( jQuery( '#ttfm_fonts' ).val() == 'none' ) {
alert( 'Please select a font!' );
return;
}
if ( ! jQuery( 'input[name="ttfm-font-style"]' ).is( ':checked' ) ) {
alert( 'Plese select a font style!' );
return;
}
if ( ! jQuery( 'input[name="ttfm-font-character-sets"]' ).is( ':checked' ) ) {
alert( 'Plese select a font character set!' );
return;
}
var style = jQuery( 'input[name="ttfm-font-style"]:checked' ).val(),
bold = jQuery( 'input[name="ttfm-font-bold"]:checked' ).val(),
subset = jQuery( 'input[name="ttfm-font-character-sets"]:checked' ).val(),
italic = '';
if ( style == 'regular' ) {
style = 400;
if ( jQuery.inArray( 'italic', font_variants ) !== - 1 ) {
italic = ',400italic';
}
} else if ( style == 'italic' ) {
style = '400italic';
}
if ( style == bold ) {
bold = 0;
}
if ( jQuery.inArray( bold + 'italic', font_variants ) > - 1 ) {
italic += ',' + bold + 'italic';
}
if ( jQuery.inArray( style + 'italic', font_variants ) > - 1 ) {
italic += ',' + style + 'italic';
}
if ( bold == undefined ) {
jQuery.each( font_variants, function ( key, value ) {
var _value = parseInt( value );
if ( bold == undefined && ! isNaN( _value ) && _value > 400 && (
isNaN( style ) || (
! isNaN( style ) && _value > style
)
) ) {
bold = value;
}
} );
}
if ( typeof bold === 'undefined' ) {
bold = 0;
}
if ( italic == '' ) {
italic = 0;
}
if ( subset == 'latin' ) {
subset = 0;
}
var font_manager_link = '<?php echo esc_js( $admin_font_manager_link ); ?>',
postData = {
_wpnonce: TVE_Dash_Const.nonce,
<?php if ( isset( $font_id ) ) {
echo 'font_id:' . esc_js( $font_id ) . ',';
} ?>
font_name: jQuery( '#ttfm_fonts' ).val() + '',
font_style: style + '',
font_bold: bold + '',
font_italic: italic + '',
font_character_set: subset + '',
font_class: jQuery( '#ttfm-font-class' ).val() + '',
font_size: jQuery( '#ttfm-font-size input' ).val() + jQuery( '#ttfm-font-size select' ).val(),
font_height: jQuery( '#ttfm-font-height input' ).val() + jQuery( '#ttfm-font-height select' ).val(),
font_color: jQuery( '.wp-color-picker-field' ).val(),
custom_css: jQuery( '#ttfm-custom-css' ).val()
};
jQuery.post( font_manager_link, postData, function ( response ) {
location.reload();
} );
} );
if ( update_font != 0 ) {
if ( isSafeFont( update_font ) ) {
jQuery( 'input#ttfm_safe_fonts' ).click();
} else if ( isImportedFont( update_font ) ) {
jQuery( 'input#ttfm_imported_fonts' ).click();
} else {
jQuery( 'input#ttfm_google_fonts' ).click();
}
jQuery( '#ttfm_fonts' ).val( update_font ).trigger( 'change' );
jQuery( 'input[name="ttfm-font-style"]' ).trigger( 'change' ).filter( function () {
return this.value === '<?php echo isset( $font["font_style"] ) ? esc_js( $font["font_style"] ) : ""; ?>' || (
this.value === 'italic' && current_font.font_style === '400italic'
);
} ).prop( 'checked', true );
jQuery( 'input[name="ttfm-font-bold"]' ).filter( function () {
return this.value == '<?php echo isset( $font["font_bold"] ) ? esc_js( $font["font_bold"] ) : ""; ?>';
} ).prop( 'checked', true );
jQuery( 'input[name="ttfm-font-character-sets"]' ).filter( function () {
return this.value == '<?php echo isset( $font["font_character_set"] ) ? esc_js( $font["font_character_set"] ) : ""; ?>';
} ).prop( 'checked', true );
}
} );
function prepareFontFamily( font_family ) {
var chunks = font_family.split( "," ),
length = chunks.length,
font = '';
jQuery( chunks ).each( function ( i, value ) {
font += "'" + value.trim() + "'";
font += i + 1 != length ? ", " : '';
} );
return font;
}
function importFont() {
var font = jQuery( '#ttfm_fonts' ).val(),
style = jQuery( 'input[name="ttfm-font-style"]:checked' ).val(),
subset = jQuery( 'input[name="ttfm-font-character-sets"]:checked' ).val();
if ( style == 'regular' ) {
style = undefined;
} else if ( style == 'italic' ) {
style = '400italic';
}
if ( subset == 'latin' ) {
subset = undefined;
}
if ( window.selected_fonts_set === 'google_fonts' || window.selected_fonts_set === 'prefered_fonts' ) {
var font_link = "//fonts.googleapis.com/css?family=" + font.replace( " ", "+" ) + (
style !== undefined ? ":" + style : ""
) + (
subset !== undefined ? "&subset=" + subset : ""
);
jQuery( '.imported-font' ).remove();
jQuery( "head" ).prepend( "<link class='imported-font' href='" + font_link + "' rel='stylesheet' type='text/css'>" );
jQuery( '#fontPreview' ).css( {'font-family': font} );
} else if ( window.selected_fonts_set === 'imported_fonts' ) {
jQuery( '.imported-font' ).remove();
jQuery( "head" ).prepend( "<link class='imported-font' href='" + window.imported_fonts_css + "' rel='stylesheet' type='text/css'>" );
jQuery( '#fontPreview' ).css( {
'font-family': prepareFontFamily( font )
} );
} else {
var _css = {
'font-family': prepareFontFamily( font ),
'font-style': 'normal',
'font-weight': 'normal'
};
if ( style === '400italic' ) {
_css['font-style'] = 'italic';
}
if ( ! isNaN( style ) ) {
_css['font-weight'] = style;
}
jQuery( '#fontPreview' ).css( _css );
}
}
function rewriteSettings( font ) {
if ( font.font_bold == 0 ) {
font.font_bold = font.font_style;
}
if ( font.font_style == 400 ) {
font.font_style = 'regular';
}
if ( font.font_style == '400italic' ) {
font.font_style = 'italic';
}
if ( font.font_character_set == 0 ) {
font.font_character_set = 'latin';
}
}
</script>