Esempio n. 1
0
function mbdb_book_metaboxes()
{
    $mbdb_options = get_option('mbdb_options');
    // SUMMARY
    $mbdb_summary_metabox = new_cmb2_box(array('id' => 'mbdb_summary_metabox', 'title' => __('Summary', 'mooberry-book-manager'), 'object_types' => array('mbdb_book'), 'context' => 'normal', 'priority' => 'high', 'show_names' => false));
    $mbdb_summary_metabox->add_field(array('name' => __('Summary', 'mooberry-book-manager'), 'id' => '_mbdb_summary', 'type' => 'wysiwyg', 'options' => array('wpautop' => true, 'media_buttons' => true, 'textarea_rows' => 10, 'tabindex' => '', 'editor_css' => '', 'editor_class' => '', 'teeny' => false, 'dfw' => false, 'tinymce' => true, 'quicktags' => true)));
    // EXCERPT
    $mbdb_excerpt_metabox = new_cmb2_box(array('id' => 'mbdb_excerpt_metabox', 'title' => __('Excerpt', 'mooberry-book-manager'), 'object_types' => array('mbdb_book'), 'context' => 'normal', 'priority' => 'high', 'show_names' => false));
    $mbdb_excerpt_metabox->add_field(array('name' => __('Excerpt', 'mooberry-book-manager'), 'id' => '_mbdb_excerpt', 'type' => 'wysiwyg', 'options' => array('wpautop' => true, 'media_buttons' => true, 'textarea_rows' => 15, 'tabindex' => '', 'editor_css' => '', 'editor_class' => '', 'teeny' => false, 'dfw' => false, 'tinymce' => true, 'quicktags' => true)));
    // REVIEWS
    $mbdb_reviews_metabox = new_cmb2_box(array('id' => 'mbdb_reviews_metabox', 'title' => _x('Reviews', 'noun: book reviews', 'mooberry-book-manager'), 'object_types' => array('mbdb_book'), 'context' => 'normal', 'priority' => 'high', 'show_names' => true));
    $mbdb_reviews_metabox->add_field(array('id' => '_mbdb_reviews', 'type' => 'group', 'description' => __('Add reviews of your book', 'mooberry-book-manager'), 'options' => array('group_title' => _x('Reviews', 'noun', 'mooberry-book-manager') . ' {#}', 'add_button' => __('Add Review', 'mooberry-book-manager'), 'remove_button' => __('Remove Review', 'mooberry-book-manager'), 'sortable' => true)));
    $mbdb_reviews_metabox->add_group_field('_mbdb_reviews', array('name' => __('Reviewer Name', 'mooberry-book-manager'), 'id' => 'mbdb_reviewer_name', 'type' => 'text_medium', 'sanitization_cb' => 'mbdb_validate_reviews'));
    $mbdb_reviews_metabox->add_group_field('_mbdb_reviews', array('name' => _x('Review Link', 'noun: URL to book review', 'mooberry-book-manager'), 'id' => 'mbdb_review_url', 'type' => 'text_url', 'desc' => 'http://www.someWebsite.com/', 'attributes' => array('pattern' => '^(https?:\\/\\/)?([\\da-zA-Z\\.-]+)\\.([a-zA-Z\\.]{2,6}).*')));
    $mbdb_reviews_metabox->add_group_field('_mbdb_reviews', array('name' => _x('Review Website Name', 'noun: name of website of book review', 'mooberry-book-manager'), 'id' => 'mbdb_review_website', 'type' => 'text_medium'));
    $mbdb_reviews_metabox->add_group_field('_mbdb_reviews', array('name' => _x('Review', 'noun: book review', 'mooberry-book-manager'), 'id' => 'mbdb_review', 'type' => 'textarea'));
    // EDITIONS
    $mbdb_editions_metabox = new_cmb2_box(array('id' => 'mbdb_editions_metabox', 'title' => __('Formats and Editions', 'mooberry-book-manager'), 'object_types' => array('mbdb_book'), 'context' => 'normal', 'priority' => 'high', 'show_names' => true));
    $mbdb_editions_metabox->add_field(array('id' => '_mbdb_editions', 'type' => 'group', 'description' => __("List the details of your book's hardcover, paperback, and e-book editions. Everything is optional except the format.", 'mooberry-book-manager'), 'options' => array('group_title' => __('Edition', 'mooberry-book-manager') . ' {#}', 'add_button' => __('Add New Edition', 'mooberry-book-manager'), 'remove_button' => __('Remove Edition', 'mooberry-book-manager'), 'sortable' => true)));
    $mbdb_editions_metabox->add_group_field('_mbdb_editions', array('name' => _x('Format', 'noun: format of a book', 'mooberry-book-manager'), 'id' => '_mbdb_format', 'type' => 'select', 'sanitization_cb' => 'mbdb_validate_editions', 'options' => mbdb_get_editions(), 'description' => __('Add more formats in Settings', 'mooberry-book-manager')));
    $mbdb_editions_metabox->add_group_field('_mbdb_editions', array('name' => __('EAN/ISBN', 'mooberry-book-manager'), 'id' => '_mbdb_isbn', 'type' => 'text_medium'));
    $mbdb_editions_metabox->add_group_field('_mbdb_editions', array('name' => __('Language', 'mooberry-book-manager'), 'id' => '_mbdb_language', 'type' => 'select', 'options' => mbdb_get_language_array(), 'default' => mbdb_get_default_language($mbdb_options)));
    $mbdb_editions_metabox->add_group_field('_mbdb_editions', array('name' => __('Number of Pages', 'mooberry-book-manager'), 'id' => '_mbdb_length', 'type' => 'text_small', 'attributes' => array('type' => 'number', 'pattern' => '\\d*', 'min' => 1)));
    $mbdb_editions_metabox->add_group_field('_mbdb_editions', array('name' => __('Height', 'mooberry-book-manager'), 'id' => '_mbdb_height', 'type' => 'text_small', 'attributes' => array('type' => 'number', 'step' => 'any', 'min' => 0)));
    $mbdb_editions_metabox->add_group_field('_mbdb_editions', array('name' => __('Width', 'mooberry-book-manager'), 'id' => '_mbdb_width', 'type' => 'text_small', 'attributes' => array('type' => 'number', 'step' => 'any', 'min' => 0)));
    $mbdb_editions_metabox->add_group_field('_mbdb_editions', array('name' => _x('Unit', 'units of measurement', 'mooberry-book-manager'), 'id' => '_mbdb_unit', 'type' => 'select', 'options' => mbdb_get_units_array(), 'default' => mbdb_get_default_unit($mbdb_options)));
    $mbdb_editions_metabox->add_group_field('_mbdb_editions', array('name' => __('Suggested Retail Price', 'mooberry-book-manager'), 'id' => '_mbdb_retail_price', 'type' => 'text_small', 'attributes' => array('pattern' => '^\\d*([.,]\\d{2}$)?', 'min' => 0)));
    $mbdb_editions_metabox->add_group_field('_mbdb_editions', array('name' => __('Currency', 'mooberry-book-manager'), 'id' => '_mbdb_currency', 'type' => 'select', 'options' => mbdb_get_currency_array(), 'default' => mbdb_get_default_currency($mbdb_options)));
    $mbdb_editions_metabox->add_group_field('_mbdb_editions', array('name' => __('Edition Title', 'mooberry-book-manager'), 'id' => '_mbdb_edition_title', 'type' => 'text_medium', 'desc' => __('First Edition, Second Edition, etc.', 'mooberry-book-mananger')));
    // ADDITIONAL INFORMATION
    $mbdb_additional_info_metabox = new_cmb2_box(array('id' => 'mbdb_additional_info_metabox', 'title' => __('Additional Information', 'mooberry-book-manager'), 'object_types' => array('mbdb_book'), 'context' => 'normal', 'priority' => 'high', 'show_names' => false));
    $mbdb_additional_info_metabox->add_field(array('name' => __('Additional Information', 'mooberry-book-manager'), 'id' => '_mbdb_additional_info', 'type' => 'wysiwyg', 'description' => __('Any additional information you want to display on the page. Will be shown at the bottom of the page, after the reviews.', 'mooberry-book-manager'), 'options' => array('wpautop' => true, 'media_buttons' => true, 'textarea_rows' => 15, 'tabindex' => '', 'editor_css' => '', 'editor_class' => '', 'teeny' => false, 'dfw' => false, 'tinymce' => true, 'quicktags' => true)));
    // COVER
    $mbdb_cover_image_metabox = new_cmb2_box(array('id' => 'mbdb_cover_image_metabox', 'title' => _x('Cover', 'noun', 'mooberry-book-manager'), 'object_types' => array('mbdb_book'), 'context' => 'side', 'priority' => 'default', 'show_names' => false, 'allow' => array('attachment')));
    $mbdb_cover_image_metabox->add_field(array('name' => _x('Book Cover', 'noun', 'mooberry-book-manager'), 'id' => '_mbdb_cover', 'type' => 'file', 'allow' => array('attachment')));
    // BOOK INFO
    $mbdb_bookinfo_metabox = new_cmb2_box(array('id' => 'mbdb_bookinfo_metabox', 'title' => __('Book Details', 'mooberry-book-manager'), 'object_types' => array('mbdb_book'), 'context' => 'side', 'priority' => 'default', 'show_names' => true));
    $mbdb_bookinfo_metabox->add_field(array('name' => __('Subtitle', 'mooberry-book-manager'), 'id' => '_mbdb_subtitle', 'type' => 'text_small'));
    $mbdb_bookinfo_metabox->add_field(array('name' => __('Release Date', 'mooberry-book-manager'), 'id' => '_mbdb_published', 'type' => 'text_date', 'desc' => 'yyyy/mm/dd', 'date_format' => 'Y/m/d', 'sanitization_cb' => 'mbdb_format_date'));
    $mbdb_bookinfo_metabox->add_field(array('name' => __('Publisher', 'mooberry-book-manager'), 'id' => '_mbdb_publisherID', 'type' => 'select', 'options' => mbdb_get_publishers(), 'desc' => __('Set up Publishers in Settings.', 'mooberry-book-manager')));
    $mbdb_bookinfo_metabox->add_field(array('name' => __('Goodreads Link', 'mooberry-book-manager'), 'id' => '_mbdb_goodreads', 'type' => 'text_url', 'desc' => 'http://www.goodreads.com/your/Unique/Text/', 'attributes' => array('pattern' => '^(https?:\\/\\/)?www.goodreads.com.*')));
    $mbdb_bookinfo_metabox->add_field(array('name' => __('Series Order', 'mooberry-book-manager'), 'id' => '_mbdb_series_order', 'desc' => __('(leave blank if not part of a series)', 'mooberry-book-manager'), 'type' => 'text_small', 'attributes' => array('type' => 'number', 'step' => 'any', 'min' => 0)));
    // BUYLINKS
    $mbdb_buylinks_metabox = new_cmb2_box(array('id' => 'mbdb_buylinks_metabox', 'title' => _x('Retailer Links', 'noun: URLs to book retailers', 'mooberry-book-manager'), 'object_types' => array('mbdb_book'), 'context' => 'side', 'priority' => 'default', 'show_names' => true));
    $mbdb_buylinks_metabox->add_field(array('id' => '_mbdb_buylinks', 'type' => 'group', 'description' => __('Add links where readers can purchase your book', 'mooberry-book-manager'), 'options' => array('group_title' => _x('Retailer Link', 'noun', 'mooberry-book-manager') . ' {#}', 'add_button' => __('Add Retailer Link', 'mooberry-book-manager'), 'remove_button' => __('Remove Retailer Link', 'mooberry-book-manager'), 'sortable' => true)));
    $mbdb_buylinks_metabox->add_group_field('_mbdb_buylinks', array('name' => __('Retailer', 'mooberry-book-manager'), 'id' => '_mbdb_retailerID', 'type' => 'select', 'options' => mbdb_get_retailers(), 'sanitization_cb' => 'mbdb_validate_retailers', 'description' => __('Add more retailers in Settings', 'mooberry-book-manager')));
    $mbdb_buylinks_metabox->add_group_field('_mbdb_buylinks', array('name' => _x('Link', 'noun: URL', 'mooberry-book-manager'), 'id' => '_mbdb_buylink', 'type' => 'text_url', 'desc' => 'http://www.someWebsite.com/', 'attributes' => array('pattern' => mbdb_url_validation_pattern())));
    // DOWNLOAD LINKS
    $mbdb_downloadlinks_metabox = new_cmb2_box(array('id' => 'mbdb_downloadlinks_metabox', 'title' => _x('Download Links', 'noun', 'mooberry-book-manager'), 'object_types' => array('mbdb_book'), 'context' => 'side', 'priority' => 'low', 'show_names' => true));
    $mbdb_downloadlinks_metabox->add_field(array('id' => '_mbdb_downloadlinks', 'type' => 'group', 'description' => __('If your book is available to download for free, add the links for each format.', 'mooberry-book-manager'), 'options' => array('group_title' => _x('Download Link', 'noun', 'mooberry-book-manager') . ' {#}', 'add_button' => __('Add Download Link', 'mooberry-book-manager'), 'remove_button' => __('Remove Download Link', 'mooberry-book-manager'), 'sortable' => true)));
    $mbdb_downloadlinks_metabox->add_group_field('_mbdb_downloadlinks', array('name' => _x('Format', 'noun', 'mooberry-book-manager'), 'id' => '_mbdb_formatID', 'type' => 'select', 'options' => mbdb_get_formats(), 'sanitization_cb' => 'mbdb_validate_downloadlinks', 'description' => __('Add more formats in Settings', 'mooberry-book-manager')));
    $mbdb_downloadlinks_metabox->add_group_field('_mbdb_downloadlinks', array('name' => _x('Link', 'noun', 'mooberry-book-manager'), 'id' => '_mbdb_downloadlink', 'type' => 'text_url', 'attributes' => array('pattern' => mbdb_url_validation_pattern())));
    $mbdb_summary_metabox = apply_filters('mbdb_summary_metabox', $mbdb_summary_metabox);
    $mbdb_editions_metabox = apply_filters('mbdb_editions_metabox', $mbdb_editions_metabox);
    $mbdb_excerpt_metabox = apply_filters('mbdb_excerpt_metabox', $mbdb_excerpt_metabox);
    $mbdb_reviews_metabox = apply_filters('mbdb_reviews_metabox', $mbdb_reviews_metabox);
    $mbdb_additional_info_metabox = apply_filters('mbdb_additional_info_metabox', $mbdb_additional_info_metabox);
    $mbdb_cover_image_metabox = apply_filters('mbdb_cover_image_metabox', $mbdb_cover_image_metabox);
    $mbdb_bookinfo_metabox = apply_filters('mbdb_bookinfo_metabox', $mbdb_bookinfo_metabox);
    $mbdb_buylinks_metabox = apply_filters('mbdb_buylinks_metabox', $mbdb_buylinks_metabox);
    $mbdb_downloadlinks_metabox = apply_filters('mbdb_downloadlinks_metabox', $mbdb_downloadlinks_metabox);
}
 function mbdb_book_page_settings($mbdb_settings_metabox)
 {
     $mbdb_settings_metabox->add_field(array('id' => 'mbdb_book_book_page_settings_title', 'name' => __('BOOK PAGE SETTINGS', 'mooberry-book-manager'), 'type' => 'title'));
     $mbdb_settings_metabox->add_field(array('id' => 'mbdb_default_template', 'name' => __('Page Template', 'mooberry-book-manager'), 'type' => 'select', 'default' => 'default', 'options' => mbdb_get_template_list()));
     $mbdb_settings_metabox->add_field(array('id' => 'mbdb_reset_meta_boxes', 'name' => __('Reset Book Edit Page', 'mooberry-book-manager'), 'type' => 'text', 'after_row' => "<span style='font-style:italic'>" . __("If you've reordered the boxes on the Book Edit page, this will revert them to their default positions.", "mooberry-book-manager") . "</span>", 'before' => '<a href="#" class="button" id="reset_meta_boxes">' . __('Reset', 'mooberry-book-manager') . '</a><img id="reset_progress" src="' . MBDB_PLUGIN_URL . 'includes/assets/ajax-loader.gif" style="display:none;padding-left:10px;"/><img id="reset_complete" src="' . MBDB_PLUGIN_URL . 'includes/assets/check.png" style="display:none;padding-left:10px;"/>', 'attributes' => array('type' => 'hidden')));
     $mbdb_settings_metabox->add_field(array('id' => 'mbdb_book_default_settings_title', 'name' => __('DEFAULT SETTINGS', 'mooberry-book-manager'), 'type' => 'title'));
     $mbdb_settings_metabox->add_field(array('id' => 'mbdb_default_unit', 'name' => __('Default Unit of Measurement', 'mooberry-book-manager'), 'type' => 'select', 'default' => 'in', 'options' => mbdb_get_units_array()));
     $mbdb_settings_metabox->add_field(array('id' => 'mbdb_default_currency', 'name' => __('Default Currency', 'mooberry-book-manager'), 'type' => 'select', 'default' => 'USD', 'options' => mbdb_get_currency_array()));
     $mbdb_settings_metabox->add_field(array('id' => 'mbdb_default_language', 'name' => __('Default Language', 'mooberry-book-manager'), 'type' => 'select', 'default' => 'EN', 'options' => mbdb_get_language_array()));
     return apply_filters('mbdb_settings_book_page_settings', $mbdb_settings_metabox);
 }
function mbdb_get_language_name($language_code)
{
    $language = mbdb_get_language_array();
    if (array_key_exists($language_code, $language)) {
        return $language[$language_code];
    } else {
        return '';
    }
}