';
$tabs = afcStrings::getString( 'manageFonts' );
echo '
' . __( 'Advanced Font Changer', 'afc_textdomain' ) . '
';
settings_errors('afc_uploadfontPageSettings');
echo '';
$current = 'afc_fontupload';
foreach( $tabs as $tab => $name ){
$classnames = ( $tab == $current ) ? ' nav-tab-active' : '';
echo "$name";
}
echo '
';
?>
Note1: We use font filename as fontname.
Note2: you can only use this characters in a font name: [A-Z] and [a-z] and [0-9] and [-]. ', 'afc_textdomain' );
}
/*
* This function checks values intered in upload font page
*/
function afc_validate_fonts( $input ){
$formats = array( 'eot', 'ttf', 'woff', 'svg' );
$firstFileInfo = array();
$fileName = '';
$afcFonts = new afcfonts();
$uploaddir = wp_upload_dir();
if( isset( $input['afc_eot_file'] ) && trim( $input['afc_eot_file'] ) != '' ){
$firstFileInfo = pathinfo( trim( $input['afc_eot_file'] ) );
$fileName = $firstFileInfo['filename'];
$message = '';
$type = '';
if( preg_match( '/^[A-Za-z0-9-_]+$/', $fileName ) ){
$allFonts = $afcFonts->getFonts('name');
$alreadyExists = 0;
if( is_array( $allFonts ) ){
foreach( $allFonts as $key ){
if( $key['name'] == $fileName ){
$alreadyExists = 1;
break;
}
}
}
if( !$alreadyExists ){
foreach( $formats as $format ){
$thisfile = trim( $input['afc_' . $format . '_file'] );
if( $thisfile != '' ){
$info = pathinfo( $thisfile );
$fileaddress = $uploaddir['path'] . '/' . $info['basename'];
if( $fileName == $info['filename'] ){
if( $info['extension'] == $format ){
if( !is_file( $fileaddress ) ){
$message .= __( 'Link address of file with this format is incorrect : ', 'afc_textdomain' ) . $format . '
';
$type = 'error';
}
}
else{
$message .= __( 'You have inserted incorrect file format in field : ', 'afc_textdomain' ) . $format . '
';
$type = 'error';
}
}
else{
$message .= __( 'Name of file with format eot is diffrent than file with format : ', 'afc_textdomain' ) . $format . '
';
$type = 'error';
}
}
else{
$message .= __( 'Field for this file format is empty : ', 'afc_textdomain' ) . $format . '
';
$type = 'error';
}
}
}
else{
$message .= __( 'A font with this name already exists.', 'afc_textdomain' );
$type = 'error';
}
}
else{
$message .= __( 'Name of file with format eot has wrong characters.', 'afc_textdomain' );
$type = 'error';
}
}
else{
$message .= __( 'Please insert a eot file in field with format eot.', 'afc_textdomain' );
$type = 'error';
}
$fontsFolder = $uploaddir['basedir'] . '/afc-local-fonts';
if( !file_exists( $fontsFolder ) ){
mkdir( $fontsFolder, 0755, true );
if (!file_exists( $fontsFolder ))
{
$message .= __( 'My fonts folder not exists and i am unable to create it. please go to your wp uploads directory and create a folder with this name: afc-local-fonts.', 'afc_textdomain' );
$type = 'error';
}
}
if( $message == '' ){
foreach( $formats as $format ){
$thisfile = trim( $input['afc_' . $format . '_file'] );
$info = pathinfo( $thisfile );
$fileaddress = $uploaddir['path'] . '/' . $info['basename'];
rename( $uploaddir['path'] . '/' . $info['basename'], $fontsFolder . '/' . $info['basename'] );
wp_delete_attachment( $input['afc_' . $format . '_file_id'] );
}
$afcFonts = new afcfonts();
$afcFonts->addFonts(
array(
array(
'name' => $fileName ,
'status' => 'local',
'metadata' => array()
)
)
);
$message = __('Your font successfully saved.', 'afc_textdomain' );
$type = 'updated';
}
if( $message != '')
add_settings_error( 'afc_uploadfontPageSettings', 'afc', $message, $type );
}
?>