';
echo '
'.__( 'You currently have the "Theme Blvd String Swap" plugin activated, however you are not using a theme with Theme Blvd Framework v2.0+, and so this plugin will not do anything.', 'tb_string_swap' ).'
';
echo '';
}
/*-----------------------------------------------------------------------------------*/
/* Setup Default Text Strings and Options
/*-----------------------------------------------------------------------------------*/
/**
* Get text strings
*
* This function only gets used if the user is using a theme with
* Theme Blvd framework prior to 2.1. So, it's essentially a fail-safe.
*/
function tb_string_swap_get_strings() {
$locals = array (
'404' => 'Apologies, but the page you\'re looking for can\'t be found.',
'404_title' => '404 Error',
'archive_no_posts' => 'Apologies, but there are no posts to display.',
'archive' => 'Archive',
'cancel_reply_link' => 'Cancel reply',
'categories' => 'Categories',
'category' => 'Category',
'comment_navigation' => 'Comment navigation',
'comments' => 'Comments',
'comments_closed' => 'Comments are closed.',
'comments_newer' => 'Newer Comments →',
'comments_no_password' => 'This post is password protected. Enter the password to view any comments.',
'comments_older' => '← Older Comments',
'comments_title_single' => 'One comment on “%2$s”',
'comments_title_multiple' => '%1$s comments on “%2$s”',
'contact_us' => 'Contact Us',
'crumb_404' => 'Error 404',
'crumb_author' => 'Articles posted by',
'crumb_search' => 'Search results for',
'crumb_tag' => 'Posts tagged',
'edit_page' => 'Edit Page',
'email' => 'Email',
'home' => 'Home',
'invalid_layout' => 'Invalid Layout ID',
'label_submit' => 'Post Comment',
'last_30' => 'The Last 30 Posts',
'monthly_archives' => 'Monthly Archives',
'name' => 'Name',
'page' => 'Page',
'pages' => 'Pages',
'page_num' => 'Page %s',
'posts_per_category' => 'Posts per category',
'navigation' => 'Navigation',
'no_slider' => 'Slider does not exist.',
'no_slider_selected' => 'Oops! You have not selected a slider in your layout.',
'no_video' => 'The video url could not retrieve a video.',
'read_more' => 'Read More',
'search' => 'Search the site...',
'search_no_results' => 'Sorry, but nothing matched your search criteria. Please try again with some different keywords.',
'tag' => 'Tag',
'title_reply' => 'Leave a Reply',
'title_reply_to' => 'Leave a Reply to %s',
'website' => 'Website'
);
return $locals;
}
/**
* Get Options to pass into Option Framework's function to generate form.
*/
function tb_string_swap_get_options() {
// This is temporary fix until Theme Blvd framework
// v2.2 officially gets released. When v2.2 gets released,
// we'll replace all this with a warning admin notice
// telling the user to update their theme.
$old_file = TEMPLATEPATH . '/framework/frontend/functions/locals.php';
$new_file = TEMPLATEPATH . '/framework/api/locals.php';
if( ! file_exists( $new_file ) )
include_once( $old_file );
// Retrieve current local text strings -- This will also
// be modified later to tell the user they need to
// update their theme.
if( function_exists('themeblvd_get_all_locals') ) {
// Dynamically pull from theme with
// filters applied.
$locals = themeblvd_get_all_locals();
} else {
// Old method for people using Theme Blvd
// framework prior to 2.1
$locals = tb_string_swap_get_strings();
}
// Configure options array
$options[] = array(
'name' => __( 'Standard Text Strings', 'tb_string_swap' ),
'desc' => __( 'Here you can find most of the text strings that you will typically find on the frontend of your site when using a Theme Blvd theme. Simply enter in a new value for each one that you want to change.
Note: This is a general plugin aimed at working with all Theme Blvd themes, however it\'s impossible to guarantee that this will effect every theme in the exact same way.', 'tb_string_swap' ),
'type' => 'section_start'
);
foreach( $locals as $id => $string ) {
$options[] = array(
'desc' => ''.__( 'Internal ID', 'tb_string_swap' ).': '.$id.'
'.__( 'Original String', 'tb_string_swap' ).': '.$string,
'id' => $id,
'std' => $string,
'type' => 'textarea'
);
}
$options[] = array(
'type' => 'section_end'
);
$options[] = array(
'name' => __( 'Post List Meta', 'tb_string_swap' ),
'desc' => __( 'This last option isn\'t technically part of the framework\'s frontend localization filter. However, if you were trying to translate all the frontend strings of the theme, it would be unfortunate for there to be no way to translate the meta info that appears in your blog. So, I\'ve gotten creative and tried to give you the ability to edit this. Keep in mind there is no way to guarentee that this will work in all themes, but play around with and see if it works for you. Also the down side to using this is that I couldn\'t figure out a good way for you to input the number of comments in this string.
Note: Save this option as blank to allow the theme to show it\'s normal meta info.', 'tb_string_swap' ),
'type' => 'section_start'
);
$options[] = array(
'desc' => __( 'Designate how you\'d like the meta info to display in your blog. This typically will show below the title of blog posts in most theme designs.
You can use the following macros:
%date% - Date post was published.
%author% - Author that wrote the post.
%categories% - Categories post belongs to.', 'tb_string_swap' ),
'id' => 'blog_meta',
'std' => __( 'Posted on %date% by %author% in %categories%', 'tb_string_swap' ),
'type' => 'textarea'
);
return $options;
}
/*-----------------------------------------------------------------------------------*/
/* Setup Admin Page
/*-----------------------------------------------------------------------------------*/
/**
* Hook everything in to being the process only if the user can
* edit theme options, or else no use running this plugin.
*/
function tb_string_swap_admin() {
// Check to make sure Theme Blvd Framework 2.0+ is running
if( ! defined( 'TB_FRAMEWORK_VERSION' ) || version_compare( TB_FRAMEWORK_VERSION, '2.0.0', '<' ) ) {
add_action( 'admin_notices', 'tb_string_swap_warning' );
return;
}
// If using framework v2.2+, we can use the framework's
// internal options system and if not, we can do it the
// old-fashioned way.
if( class_exists( 'Theme_Blvd_Options_Page' ) ) {
// Use new options system incorporated in v2.2.
global $_tb_string_swap_admin;
$options = tb_string_swap_get_options();
$args = array(
'parent' => 'tools.php',
'page_title' => __( 'Theme Blvd String Swap', 'tb_string_swap' ),
'menu_title' => __( 'TB String Swap', 'tb_string_swap' ),
'cap' => apply_filters( 'tb_string_swap_cap', 'edit_theme_options' )
);
$_tb_string_swap_admin = new Theme_Blvd_Options_Page( 'tb_string_swap', $options, $args );
} else {
// Initiate old-school method for framewok v2.0-2.1
add_action( 'init', 'tb_string_swap_rolescheck' );
}
}
add_action( 'after_setup_theme', 'tb_string_swap_admin' );
/**
* Hook everything in to being the process only if the user can
* edit theme options, or else no use running this plugin.
*
* NOTE: This only is used if we're using framework v2.0-2.1.
*/
function tb_string_swap_rolescheck() {
if ( current_user_can( 'edit_theme_options' ) ) {
add_action( 'admin_init', 'tb_string_swap_init' );
add_action( 'admin_menu', 'tb_string_swap_add_page');
}
}
/**
* Add a menu page for this plugin.
*
* NOTE: This only is used if we're using framework v2.0-2.1.
*/
function tb_string_swap_add_page() {
// Create sub menu page
$string_swap_page = add_submenu_page( 'tools.php', 'TB String Swap', 'TB String Swap', 'administrator', 'tb_string_swap', 'tb_string_swap_page' );
// Adds actions to hook in the required css and javascript
add_action( "admin_print_styles-$string_swap_page", 'optionsframework_load_styles' );
add_action( "admin_print_scripts-$string_swap_page", 'optionsframework_load_scripts' );
add_action( "admin_print_styles-$string_swap_page", 'optionsframework_mlu_css', 0 );
add_action( "admin_print_scripts-$string_swap_page", 'optionsframework_mlu_js', 0 );
}
/**
* Inititate anything needed for the plugin.
*
* NOTE: This only is used if we're using framework v2.0-2.1.
*/
function tb_string_swap_init() {
// Register settings
register_setting( 'tb_string_swap_settings', 'tb_string_swap', 'tb_string_swap_validate' );
}
/**
* Validate settings when updated.
*
* Note: This function realistically has more than it needs.
* In this specific plugin, we're only working with one kind
* of option, which is the "textarea" type of option, however
* I'm keeping all validation types in this plugin as to setup
* a nice model for making more plugins in the future that
* may also include different kinds of options.
*
* NOTE: This only is used if we're using framework v2.0-2.1.
*/
function tb_string_swap_validate( $input ) {
// Reset Settings
if( isset( $_POST['reset'] ) ) {
$empty = array();
add_settings_error( 'tb_string_swap', 'restore_defaults', __( 'Default options restored.', 'tb_string_swap' ), 'updated fade' );
return $empty;
}
// Save Options
if ( isset( $_POST['update'] ) && isset( $_POST['options'] ) ) {
$clean = array();
$options = tb_string_swap_get_options();
foreach ( $options as $option ) {
// Verify we have what need from options
if ( ! isset( $option['id'] ) ) continue;
if ( ! isset( $option['type'] ) ) continue;
$id = preg_replace( '/\W/', '', strtolower( $option['id'] ) );
// Set checkbox to false if it wasn't sent in the $_POST['options']
if ( 'checkbox' == $option['type'] && ! isset( $_POST['options'][$id] ) ) {
$_POST['options'][$id] = '0';
}
// Set each item in the multicheck to false if it wasn't sent in the $_POST['options']
if ( 'multicheck' == $option['type'] && ! isset( $_POST['options'][$id] ) ) {
foreach ( $option['options'] as $key => $value ) {
$_POST['options'][$id][$key] = '0';
}
}
// For a value to be submitted to database it must pass through a sanitization filter
if ( has_filter( 'of_sanitize_' . $option['type'] ) ) {
$clean[$id] = apply_filters( 'of_sanitize_' . $option['type'], $_POST['options'][$id], $option );
}
}
add_settings_error( 'tb_string_swap', 'save_options', __( 'Options saved.', 'tb_string_swap' ), 'updated fade' );
return $clean;
}
}
/*-----------------------------------------------------------------------------------*/
/* Display Admin Page
/*-----------------------------------------------------------------------------------*/
/**
* Builds out the full admin page.
*
* NOTE: This only is used if we're using framework v2.0-2.1.
*/
function tb_string_swap_page() {
// DEBUG
// $settings = get_option('tb_string_swap');
// echo ''; print_r($settings); echo '
';
// Build form
$options = tb_string_swap_get_options();
$settings = get_option('tb_string_swap');
$form = optionsframework_fields( 'options', $options, $settings, false );
settings_errors();
?>
$string ) {
if( isset( $new_locals[$id] ) )
$locals[$id] = $new_locals[$id];
}
return $locals;
}
add_filter( 'themeblvd_frontend_locals', 'tb_string_swap_apply_changes', 999 );
/**
* Blog Meta action
*/
function tb_string_swap_blog_meta() {
// Grab parts
$new_locals = get_option('tb_string_swap');
$meta = $new_locals['blog_meta'];
$author_string = ''.get_the_author().'';
// Macro replacements
$meta = str_replace( '%date%', get_the_time( get_option('date_format') ), $meta );
$meta = str_replace( '%author%', $author_string, $meta );
$meta = str_replace( '%categories%', get_the_category_list(', '), $meta );
// Display it
echo ''.$meta.'
';
}
/**
* Add/Remove actions
*
* Only if the user inputted something for the blog
* meta option and after theme has been setup,
* remove all current actions on the themeblvd_blog_meta
* hook, and add in this one.
*/
function tb_string_swap_add_actions() {
$new_locals = get_option('tb_string_swap');
if( isset( $new_locals['blog_meta'] ) && $new_locals['blog_meta'] ) {
remove_all_actions( 'themeblvd_blog_meta' );
add_action( 'themeblvd_blog_meta', 'tb_string_swap_blog_meta' );
}
}
add_action( 'after_setup_theme', 'tb_string_swap_add_actions', 999 );