| 1 |
<?php |
| 2 |
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly |
| 3 |
|
| 4 |
function mbt_getnoticed_init() { |
| 5 |
add_action('after_setup_theme', 'mbt_getnoticed_compat', 20); |
| 6 |
add_filter('mbt_importers', 'mbt_add_getnoticed_importer'); |
| 7 |
} |
| 8 |
add_action('mbt_init', 'mbt_getnoticed_init'); |
| 9 |
|
| 10 |
function mbt_getnoticed_compat() { |
| 11 |
if(function_exists('getnoticed_setup')) { |
| 12 |
remove_action('init', 'getnoticed_types_book_init'); |
| 13 |
add_filter('pre_get_posts', 'mbt_getnoticed_post_types_unindex', 20); |
| 14 |
add_action('wp_head', 'mbt_add_getnoticed_css'); |
| 15 |
} |
| 16 |
} |
| 17 |
|
| 18 |
function mbt_getnoticed_post_types_unindex($query) { |
| 19 |
if((is_home() || (is_archive() && !is_post_type_archive())) && $query->is_main_query()) { |
| 20 |
$post_type = $query->get('post_type'); |
| 21 |
if(is_array($post_type) and in_array('book', $post_type)) { unset($post_type[array_search('book', $post_type)]); } |
| 22 |
else if($post_type === 'book') { $post_type = 'mbt_books'; } |
| 23 |
$query->set('post_type', $post_type); |
| 24 |
} |
| 25 |
} |
| 26 |
|
| 27 |
function mbt_add_getnoticed_css() { |
| 28 |
global $_THEME; |
| 29 |
$image_size = mbt_get_setting('image_size'); |
| 30 |
echo('<style type="text/css">'); |
| 31 |
echo('.mybooktable h1 {'); |
| 32 |
echo(' font-family: '.wp_kses_post($_THEME->get_fontstack($_THEME->getord('family', 'title-font'))).';'); |
| 33 |
echo(' font-size: '.wp_kses_post($_THEME->getord('size', 'title-font')).';'); |
| 34 |
echo(' line-height: '.wp_kses_post($_THEME->getord('line-height', 'title-font')).';'); |
| 35 |
$values = $_THEME->getord('options', 'title-font'); |
| 36 |
if(in_array('bold', $values)) { echo('font-weight: bold;'); } |
| 37 |
if(in_array('italic', $values)) { echo('font-style: italic;'); } |
| 38 |
echo(' color: '.wp_kses_post($_THEME->getord('title-color')).';'); |
| 39 |
echo('}'); |
| 40 |
echo('.mbt-featured-book-widget {'); |
| 41 |
echo(' padding: 0px;'); |
| 42 |
echo('}'); |
| 43 |
echo('.mbt-featured-book-widget .mbt-featured-book-widget-book {'); |
| 44 |
echo(' padding: 20px;'); |
| 45 |
echo(' border-bottom: 1px solid #d6d6d6;'); |
| 46 |
echo('}'); |
| 47 |
echo('.mbt-featured-book-widget .mbt-featured-book-widget-book:last-child {'); |
| 48 |
echo(' border-bottom: none;'); |
| 49 |
echo('}'); |
| 50 |
echo('</style>'); |
| 51 |
} |
| 52 |
|
| 53 |
function mbt_add_getnoticed_importer($importers) { |
| 54 |
$exists = function_exists('getnoticed_setup'); |
| 55 |
|
| 56 |
$importers['getnoticed'] = array( |
| 57 |
'name' => __('GetNoticed', 'mybooktable'), |
| 58 |
'desc' => __('Import your books from the GetNoticed theme.', 'mybooktable'), |
| 59 |
'page_title' => __('GetNoticed Import', 'mybooktable'), |
| 60 |
'get_book_list' => 'mbt_getnoticed_get_books', |
| 61 |
'disabled' => ($exists ? '' : 'GetNoticed theme not detected'), |
| 62 |
); |
| 63 |
return $importers; |
| 64 |
} |
| 65 |
|
| 66 |
function mbt_getnoticed_get_books() { |
| 67 |
$books = array(); |
| 68 |
$query = new WP_Query(array('post_type' => 'book', 'posts_per_page' => -1)); |
| 69 |
foreach($query->posts as $book) { |
| 70 |
$book_meta = get_post_meta($book->ID, 'getnoticed_meta_book', true); |
| 71 |
|
| 72 |
$new_book = array(); |
| 73 |
$new_book['source_id'] = $book->ID; |
| 74 |
$new_book['title'] = $book->post_title; |
| 75 |
$new_book['content'] = $book->post_content; |
| 76 |
$new_book['excerpt'] = $book->post_excerpt; |
| 77 |
$new_book['authors'] = array(); |
| 78 |
if(!empty($book_meta['bookauthor'])) { $new_book['authors'][] = $book_meta['bookauthor']; } |
| 79 |
$new_book['unique_id_asin'] = $book_meta['asin']; |
| 80 |
$new_book['buybuttons'] = array(); |
| 81 |
if(!empty($book_meta['link'])) { $new_book['buybuttons'][] = array('display' => 'button', 'store' => 'amazon', 'url' => $book_meta['link']); } |
| 82 |
$new_book['publisher_name'] = $book_meta['publisher']; |
| 83 |
$new_book['publication_year'] = $book_meta['year']; |
| 84 |
$new_book['image_id'] = get_post_meta($book->ID, '_thumbnail_id', true); |
| 85 |
$new_book['imported_book_id'] = get_post_meta($book->ID, 'mbt_imported_book_id', true); |
| 86 |
|
| 87 |
$books[] = $new_book; |
| 88 |
} |
| 89 |
|
| 90 |
return $books; |
| 91 |
} |
| 92 |
|