function populate_mbdb_book_columns($column, $post_id) { // get the book for the current row $book = MBDB()->books->get($post_id); // if the book is invalid, exit if ($book == null) { return; } // if this is the genre or series column (taxonomies) // just get the term list and display that delimited by commas // and then exit. No further processing necessary if ($column == 'mbdb_genre' || $column == 'mbdb_series') { do_action('mbdb_book_pre_' . $column . '_column'); echo apply_filters('mbdb_book_' . $column . '_column', get_the_term_list($post_id, $column, '', ', ')); do_action('mbdb_book_post_' . $column . '_column'); return; } // if the column is a property of book, grab that data if (property_exists($book, $column)) { $data = $book->{$column}; } else { $data = ''; } switch ($column) { // book cover: display as an image case 'cover': do_action('mbdb_book_pre_mbdb_cover_column', $column, $data, $book); if ($data != '') { $alt = mbdb_get_alt_text($book->cover_id, __('Book Cover:', 'mooberry-book-manager') . ' ' . get_the_title($post_id)); echo apply_filters('mbdb_book_mbdb_cover_column', '<IMG SRC="' . esc_url($data) . '" width="100" ' . $alt . ' />', $column, $data, $book); } do_action('mbdb_book_post_mbdb_cover_column', $column, $data, $book); break; // release date: use short format // release date: use short format case 'release_date': do_action('mbdb_book_pre_mbdb_published_column', $column, $data, $book); if (!empty($data)) { // TO DO validate data to be a date?? /* translators: short date format. see http://php.net/date */ echo apply_filters('mbdb_book_mbdb_published_column', date(__('m/d/Y'), strtotime($data)), $column, $data, $book); } do_action('mbdb_book_post_mbdb_published_column', $column, $data, $book); break; // publisher: display publisher name // does not come from book object // publisher: display publisher name // does not come from book object case 'publisher_id': $publisher = mbdb_get_publisher_info($data); do_action('mbdb_book_pre_mbdb_publisher_column', $column, $publisher, $book); echo apply_filters('mbdb_book_mbdb_publisher_column', $publisher['name'], $column, $publisher, $book); do_action('mbdb_book_post_mbdb_publisher_column', $column, $publisher, $book); break; default: do_action('mbdb_book_pre_mbdb_' . $column . '_column', $column, $data, $book); echo apply_filters('mbdb_book_mbdb_' . $column . '_column', $data, $book, $post_id, $column); do_action('mbdb_book_post_mbdb_' . $column . '_column', $column, $data, $book); } }
/** * Generate the HTML to display a book and its cover image * coming soon object passed as parameter because it's stored in * the options and this function is called several times * * @since 1.0 * @since 2.0 made responsive * @since 3.0 re-factored, added alt text * * @param [obj] $book book object * @param [string] $coming_soon_image coming soon image * * @return html output * * @access public */ function mbdb_output_grid_book($book, $coming_soon_image) { $image = $book->cover; $default_alt = __('Book Cover:', 'mooberry-book-manager') . ' ' . $book->post_title; $content = '<span class="mbdb_float_grid">'; if ($image) { $alt = mbdb_get_alt_text($book->cover_id, $default_alt); $content .= '<div class="mbdb_grid_image">'; $content = apply_filters('mbdb_book_grid_pre_image', $content, $book->book_id, $image); $content .= '<a class="mbm-book-grid-title-link" href="' . esc_url(get_permalink($book->book_id)) . '"><img src="' . esc_url($image) . '" ' . $alt . ' ></a>'; $content = apply_filters('mbdb_book_grid_post_image', $content, $book->book_id, $image); $content .= '</div>'; } else { if (isset($coming_soon_image)) { $alt = mbdb_get_alt_text(0, $default_alt); $content .= '<div class="mbdb_grid_image">'; $content = apply_filters('mbdb_book_grid_pre_placeholder_image', $content, $book->book_id, $coming_soon_image); $content .= '<a class="mbm-book-grid-title-link" href="' . esc_url(get_permalink($book->book_id)) . '"><img src="' . esc_url($coming_soon_image) . '" ' . $alt . ' ></a></div>'; $content = apply_filters('mbdb_book_grid_post_placeholder_image', $content, $book->book_id, $coming_soon_image); } else { $content .= '<div class="mbdb_grid_no_image">'; $content = apply_filters('mbdb_book_grid_no_image', $content, $book->book_id); $content .= '</div>'; } } $content .= '<span class="mbdb_grid_title">'; $content = apply_filters('mbdb_book_grid_pre_link', $content, $book->book_id, $book->post_title); $content .= '<a class="mbm-book-grid-title-link" href="' . esc_url(get_permalink($book->book_id)) . '">' . esc_html($book->post_title) . '</a>'; $content = apply_filters('mbdb_book_grid_post_link', $content, $book->book_id, $book->post_title); $content .= '</span></span>'; return $content; }
function mbdb_output_buylinks($mbdb_buylinks, $attr) { $classname = 'mbm-book-buy-links'; $mbdb_options = get_option('mbdb_options'); //$buy_links_html = '<UL class="' . $classname . '-list" style="list-style-type:none;">'; $buy_links_html = ''; $img_size = ''; if ($attr['align'] == 'vertical') { //$li_style = "margin: 2px 0 2px 0;"; if ($attr['size']) { $attr['width'] = $attr['size']; } } else { //$li_style = "display:inline;margin: 0 1% 0 0;"; if ($attr['size']) { $attr['height'] = $attr['size']; } } if ($attr['width']) { $img_size = "width:" . esc_attr($attr['width']); } if ($attr['height']) { $img_size = "height:" . esc_attr($attr['height']); } foreach ($mbdb_buylinks as $mbdb_buylink) { // get format info based on formatid = uniqueid if (array_key_exists('retailers', $mbdb_options)) { foreach ($mbdb_options['retailers'] as $r) { if ($r['uniqueID'] == $mbdb_buylink['_mbdb_retailerID']) { //$buy_links_html .= '<li class="' . $classname . '-listitem" style="' . $li_style . '">'; $buy_links_html .= '<A class="' . $classname . '-link" HREF="' . esc_url($mbdb_buylink['_mbdb_buylink']) . '" TARGET="_new">'; if ($r['image'] != '') { if (array_key_exists('imageID', $r)) { $imageID = $r['imageID']; } else { if (array_key_exists('image_id', $r)) { $imageID = $r['image_id']; } else { $imageID = 0; } } $alt = mbdb_get_alt_text($imageID, __('Buy Now:', 'mooberry-book-manager') . ' ' . $r['name']); $buy_links_html .= '<img class="' . $classname . '-image" style="' . esc_attr($img_size) . '" src="' . esc_url($r['image']) . '" ' . $alt . ' />'; } else { $buy_links_html .= '<span class="' . $classname . '-text">' . esc_html($r['name']) . '</span>'; } $buy_links_html .= '</a>'; //$buy_links_html .= '</li>'; } } } } //$buy_links_html .= "</ul>"; return apply_filters('mbdb_shortcode_buylinks', '<div class="' . $classname . '"><span class="' . $classname . '-label">' . esc_html($attr['label']) . '</span>' . $buy_links_html . '<span class="' . $classname . '-after">' . esc_html($attr['after']) . '</span></div>'); }
function widget($args, $instance) { extract($args); $mbdb_bookID = $instance['mbdb_bookID']; $mbdb_widget_type = apply_filters('mbdb_widget_type', $instance['mbdb_widget_type']); $book = null; do_action('mbdb_widget_pre_get_books', $instance); switch ($mbdb_widget_type) { case 'random': // get book ID of a random book $book = apply_filters('mbdb_widget_random_book_list', MBDB()->books->get_random_book(), $instance); break; case "newest": // get book ID of most recent book $book = apply_filters('mbdb_widget_newest_book_list', MBDB()->books->get_most_recent_book(), $instance); break; case "coming-soon": // get books with future or blank release dates $book = apply_filters('mbdb_widget_coming_soon_book_list', MBDB()->books->get_upcoming_book(), $instance); break; case "specific": // make sure seected book is still a valid book $book = apply_filters('mbdb_widget_specific_book_list', MBDB()->books->get($mbdb_bookID), $instance); break; } $book = apply_filters('mbdb_widget_book', $book, $instance); do_action('mbdb_widget_post_get_books', $instance, $book); //output if ($book == null) { $mbdb_bookID = 0; $mbdb_book_title = ''; } else { $mbdb_bookID = $book->book_id; $mbdb_book_title = get_the_title($mbdb_bookID); } $mbdb_widget_title = apply_filters('mbdb_widget_title', $instance['mbdb_widget_title']); $mbdb_widget_show_title = apply_filters('mbdb_widget_show_title', $instance['mbdb_widget_show_title']); $mbdb_cover_size = apply_filters('mbdb_widget_cover_size', $instance['mbdb_widget_cover_size']); $mbdb_bookID = apply_filters('mbdb_widget_bookID', $mbdb_bookID); $mbdb_book_title = apply_filters('mbdb_widget_book_title', $mbdb_book_title); do_action('mbdb_widget_pre_display'); echo $before_widget; echo $before_title . esc_html($mbdb_widget_title) . $after_title; if ($mbdb_bookID == 0) { echo apply_filters('mbdb_widget_no_books_found', '<em>' . __('No books found', 'mooberry-book-manager') . '</em>'); } else { $image_src = $book->cover; $image_id = $book->cover_id; //$image_src = get_post_meta( $mbdb_bookID, '_mbdb_cover', true ); $book_link = get_permalink($mbdb_bookID); if ($book_link != '') { do_action('mbdb_widget_pre_link', $book_link); echo '<A class="mbm-widget-link" HREF="' . esc_url($book_link) . '"> '; } if (!$image_src || $image_src == '') { // v3.0 check for placeholder image setting $show_placeholder_cover = mbdb_get_option('show_placeholder_cover'); if (is_array($show_placeholder_cover)) { if (in_array('widget', $show_placeholder_cover)) { $image_src = mbdb_get_option('coming-soon'); } } } if ($image_src && $image_src !== '') { do_action('mbdb_widget_pre_image', $image_src); $alt = mbdb_get_alt_text($image_id, __('Book Cover:', 'mooberry-book-manager') . ' ' . $mbdb_book_title); echo '<img class="mbm-widget-cover" style="width:' . esc_attr($mbdb_cover_size) . 'px;padding-top:10px;" src="' . esc_url($image_src) . '" ' . $alt . ' /> '; do_action('mbdb_widget_post_image', $image_src); } if ($mbdb_widget_show_title == 'yes') { if ($mbdb_book_title != '') { do_action('mbdb_widget_pre_book_title', $mbdb_book_title); echo '<P><span class="mbm-widget-title">' . esc_html($mbdb_book_title) . '</span></P>'; do_action('mbdb_widget_post_book_title', $mbdb_book_title); } } if ($book_link != '') { echo '</A>'; do_action('mbdb_widget_post_link'); } } //echo '</div>' . echo $after_widget; do_action('mbdb_widget_post_display'); }