/** * get the single breadcrumbs * @param $post_title * @return string */ static function get_single_breadcrumbs($post_title) { if (td_util::get_option('tds_breadcrumbs_show') == 'hide') { return; } $category_1_name = ''; $category_1_url = ''; $category_2_name = ''; $category_2_url = ''; $primary_category_id = td_global::get_primary_category_id(); $primary_category_obj = get_category($primary_category_id); //print_r($primary_category_obj); if (!empty($primary_category_obj)) { if (!empty($primary_category_obj->name)) { $category_1_name = $primary_category_obj->name; } else { $category_1_name = ''; } if (!empty($primary_category_obj->cat_ID)) { $category_1_url = get_category_link($primary_category_obj->cat_ID); } if (!empty($primary_category_obj->parent) and $primary_category_obj->parent != 0) { $parent_category_obj = get_category($primary_category_obj->parent); if (!empty($parent_category_obj)) { $category_2_name = $parent_category_obj->name; $category_2_url = get_category_link($parent_category_obj->cat_ID); } } } if (!empty($category_1_name)) { //parent category (only if we have one and if the theme is set to show it) if (!empty($category_2_name) and td_util::get_option('tds_breadcrumbs_show_parent') != 'hide') { $breadcrumbs_array[] = array('title_attribute' => __td('View all posts in', TD_THEME_NAME) . ' ' . htmlspecialchars($category_2_name), 'url' => $category_2_url, 'display_name' => $category_2_name); } //child category $breadcrumbs_array[] = array('title_attribute' => __td('View all posts in', TD_THEME_NAME) . ' ' . htmlspecialchars($category_1_name), 'url' => $category_1_url, 'display_name' => $category_1_name); //article title (only if the theme is set to show it) if (td_util::get_option('tds_breadcrumbs_show_article') != 'hide') { //child category $breadcrumbs_array[] = array('title_attribute' => $post_title, 'url' => '', 'display_name' => td_util::excerpt($post_title, 13)); } } if (isset($breadcrumbs_array) and is_array($breadcrumbs_array)) { //the breadcrumbs may be empty due to settings return self::get_breadcrumbs($breadcrumbs_array); //generate the breadcrumbs } else { return ''; } }
function get_title($excerpt_lenght = '') { $buffy = ''; $buffy .= '<h4 itemprop="name" class="entry-title">'; $buffy .= '<a itemprop="url" href="' . $this->href . '" rel="bookmark" title="' . $this->title_attribute . '">'; if (!empty($excerpt_lenght)) { $buffy .= td_util::excerpt($this->title, $excerpt_lenght, 'show_shortcodes'); } else { $buffy .= $this->title; } $buffy .= '</a>'; $buffy .= '</h4>'; return $buffy; }
function get_title_sec_item() { //get the excerpt from panel $tds_big_slide_small_image_title_excerpt = td_util::get_option('tds_big_slide_small_image_title_excerpt'); $buffy = ''; $buffy .= '<div class="td-sbig-title-wrap">'; $buffy .= '<a class="noSwipe" itemprop="url" href="' . $this->current_post->href . '" rel="bookmark" title="' . $this->current_post->title_attribute . '">'; //make the title if (intval($tds_big_slide_small_image_title_excerpt) > 0) { $buffy .= td_util::excerpt($this->current_post->title, $tds_big_slide_small_image_title_excerpt); } else { $buffy .= $this->current_post->title; } $buffy .= '</a>'; $buffy .= '</div>'; return $buffy; }
/** * returns the item scope meta. It returns an empty string if the module is used in a loop (not on a single page) * 16 march 2015 * @return string */ function get_item_scope_meta() { if (!is_single()) { return ''; } $buffy = ''; //the vampire slayer $author_id = $this->post->post_author; $buffy .= '<meta itemprop="author" content = "' . get_the_author_meta('display_name', $author_id) . '">'; $buffy .= '<meta itemprop="interactionCount" content="UserComments:' . get_comments_number($this->post->ID) . '"/>'; if (td_review::has_review($this->td_review)) { $td_article_date_unix = get_the_time('U', $this->post->ID); $buffy .= '<meta itemprop="itemReviewed " content = "' . $this->title . '">'; if (!empty($this->td_review['review'])) { $buffy .= '<meta itemprop="about" content = "' . esc_attr($this->td_review['review']) . '">'; } else { //we have no review :| //get a damn excerpt for the metatag if ($this->post->post_excerpt != '') { $td_post_excerpt = $this->post->post_excerpt; } else { $td_post_excerpt = td_util::excerpt($this->post->post_content, 25); } $buffy .= '<meta itemprop="about" content = "' . esc_attr($td_post_excerpt) . '">'; } $buffy .= '<meta itemprop="datePublished" content="' . date(DATE_W3C, $td_article_date_unix) . '">'; $buffy .= '<span class="td-page-meta" itemprop="reviewRating" itemscope itemtype="' . td_global::$http_or_https . '://schema.org/Rating">'; $buffy .= '<meta itemprop="worstRating" content = "1">'; $buffy .= '<meta itemprop="bestRating" content = "5">'; $buffy .= '<meta itemprop="ratingValue" content = "' . td_review::calculate_total_stars($this->td_review) . '">'; $buffy .= ' </span>'; } return $buffy; }
/** * This method is used by modules to get content that has to be excerpted (cut) * IT RETURNS THE EXCERPT FROM THE POST IF IT'S ENTERED IN THE EXCERPT CUSTOM POST FIELD BY THE USER * @param string $cut_at - if provided the method will just cat at that point * @return string */ function get_excerpt($cut_at = '') { //If the user supplied the excerpt in the post excerpt custom field, we just return that if ($this->post->post_excerpt != '') { return $this->post->post_excerpt; } $buffy = ''; if ($cut_at != '') { // simple, $cut_at and return $buffy .= td_util::excerpt($this->post->post_content, $cut_at); } else { $current_module_class = get_class($this); //see if we have a default setting for this module, and if so only apply it if we don't get other things form theme panel. if (td_api_module::_check_excerpt_content($current_module_class)) { $db_content_excerpt = td_util::get_option($current_module_class . '_content_excerpt'); if ($db_content_excerpt != '') { //cut from the database settings $buffy .= td_util::excerpt($this->post->post_content, $db_content_excerpt); } else { //cut at the default size $module_api = td_api_module::get_by_id($current_module_class); $buffy .= td_util::excerpt($this->post->post_content, $module_api['excerpt_content']); } } else { /** * no $cut_at provided and no setting in td_config -> return the full $this->post->post_content * @see td_global::$modules_list */ $buffy .= $this->post->post_content; } } return $buffy; }
/** * This method outputs the item scope for SINGLE templates. If you are looking for the modules @see td_module::get_item_scope_meta() * @updated 23 july 2015 * - if the module that uses this class is not on a single page, we use the @see td_module::get_item_scope_meta() this allows * us to output normal module item scope insted of no item scope like it was before this update * @return string */ function get_item_scope_meta() { if (!is_single()) { return parent::get_item_scope_meta(); // get a normal item scope if we're in a loop - like on a blog style loop } $buffy = ''; //the vampire slayer $buffy .= parent::get_item_scope_meta(); // if we have a review, we must add additional stuff if (td_review::has_review($this->td_review)) { // the item that is reviewd $buffy .= '<meta itemprop="itemReviewed " content = "' . $this->title_attribute . '">'; if (!empty($this->td_review['review'])) { $buffy .= '<meta itemprop="about" content = "' . esc_attr($this->td_review['review']) . '">'; } else { //we have no review text :| get a excerpt for the about meta thing if ($this->post->post_excerpt != '') { $td_post_excerpt = $this->post->post_excerpt; } else { $td_post_excerpt = td_util::excerpt($this->post->post_content, 25); } $buffy .= '<meta itemprop="about" content = "' . esc_attr($td_post_excerpt) . '">'; } // review rating $buffy .= '<span class="td-page-meta" itemprop="reviewRating" itemscope itemtype="' . td_global::$http_or_https . '://schema.org/Rating">'; $buffy .= '<meta itemprop="worstRating" content = "1">'; $buffy .= '<meta itemprop="bestRating" content = "5">'; $buffy .= '<meta itemprop="ratingValue" content = "' . td_review::calculate_total_stars($this->td_review) . '">'; $buffy .= ' </span>'; } return $buffy; }
/** * Used only on slide big to cut the title to make it wrap * * @param $cut_parms * @param $title * @return string */ static function cut_title($cut_parms, $title) { //trim and get the excerpt $title = trim($title); $title = td_util::excerpt($title, $cut_parms['excerpt']); //get an array of chars $title_chars = str_split($title); //$title_chars = preg_split('/(?=(.{16})*$)/u', $title); $buffy = ''; $current_char_on_line = 0; $has_to_cut = false; //when true, the string will be cut foreach ($title_chars as $title_char) { //check if we reached the limit if ($cut_parms['char_per_line'] == $current_char_on_line) { $has_to_cut = true; $current_char_on_line = 0; } else { $current_char_on_line++; } if ($title_char == ' ' and $has_to_cut === true) { //we have to cut, it's a white space so we ignore it (not added to buffy) $buffy .= $cut_parms['line_wrap_end'] . $cut_parms['line_wrap_start']; $has_to_cut = false; } else { //normal loop $buffy .= $title_char; } } //wrap the string return $cut_parms['line_wrap_start'] . $buffy . $cut_parms['line_wrap_end']; }
/** * here we generate the breadcrumbs for custom post types * - we favor terms that have a parent so: parent > child will always show up instead of single terms that don't have parents * @return string */ private static function get_custom_post_type_breadcrumbs() { global $post; // use the global breadcrumb setting to show or hide them if (td_util::get_option('tds_breadcrumbs_show') == 'hide') { return ''; } $breadcrumbs_array = array(); // get the taxonomy that was set for breadcrumbs $breadcrumbs_taxonomy = td_util::get_ctp_option($post->post_type, 'tds_breadcrumbs_taxonomy'); // get terms (alphabetically) $terms = wp_get_post_terms($post->ID, $breadcrumbs_taxonomy); if (!empty($terms)) { // add the first term by default // this default will be overwritten ! - if in foreach we find a term that has a parent if (isset($terms[0])) { $first_term_url = get_term_link($terms[0], $breadcrumbs_taxonomy); if (!is_wp_error($first_term_url)) { $breadcrumbs_array[0] = array('title_attribute' => '', 'url' => $first_term_url, 'display_name' => $terms[0]->name); } } // start the search for terms that have parents BUT only if the global settings allow us if (td_util::get_option('tds_breadcrumbs_show_parent') != 'hide') { foreach ($terms as $term) { // check if the term has a parent if ($term->parent != 0) { $parent_term_in_category_spot = get_term($term->parent, $breadcrumbs_taxonomy); // add the parent $parent_url = get_term_link($parent_term_in_category_spot, $breadcrumbs_taxonomy); if (!is_wp_error($parent_url)) { $breadcrumbs_array[0] = array('title_attribute' => '', 'url' => $parent_url, 'display_name' => $parent_term_in_category_spot->name); } // add the child $child_url = get_term_link($term, $breadcrumbs_taxonomy); if (!is_wp_error($child_url)) { $breadcrumbs_array[] = array('title_attribute' => '', 'url' => $child_url, 'display_name' => $term->name); } break; //we found a parent > child } } // end foreach } } //article title if (td_util::get_option('tds_breadcrumbs_show_article') != 'hide') { //child category $breadcrumbs_array[] = array('title_attribute' => $post->post_title, 'url' => '', 'display_name' => td_util::excerpt($post->post_title, 13)); } return self::get_breadcrumbs($breadcrumbs_array); }
function get_excerpt($lenght = 25, $show_shortcodes = '') { if ($this->post->post_excerpt != '') { return $this->post->post_excerpt; } if (empty($lenght)) { $lenght = 25; } $buffy = ''; //print_r($this->post); //remove [caption .... [/caption] from $this->post->post_content $post_content = preg_replace("/\\[caption(.*)\\[\\/caption\\]/i", '', $this->post->post_content); $buffy .= td_util::excerpt($post_content, $lenght, $show_shortcodes); return $buffy; }
/** * This method outputs the item scope for SINGLE templates. If you are looking for the modules @see td_module::get_item_scope_meta() * @updated 23 july 2015 * - if the module that uses this class is not on a single page, we use the @see td_module::get_item_scope_meta() this allows * us to output normal module item scope insted of no item scope like it was before this update * @updated 16 december 2015 * - removed structured data from modules, now it displays only on single and it returns the current post data * - no more interference with the itemprop's coming from modules * - all single structured data is now gathered here * @return string */ function get_item_scope_meta() { // don't display meta on pages if (!is_single()) { return ''; } // determine publisher name - use author name if there's no blog name $td_publisher_name = get_bloginfo('name'); if (empty($td_publisher_name)) { $td_publisher_name = esc_attr(get_the_author_meta('display_name', $this->post->post_author)); } // determine publisher logo $td_publisher_logo = td_util::get_option('tds_logo_upload'); $buffy = ''; //the vampire slayer // author $buffy .= '<span style="display: none;" itemprop="author" itemscope itemtype="https://schema.org/Person">'; $buffy .= '<meta itemprop="name" content="' . esc_attr(get_the_author_meta('display_name', $this->post->post_author)) . '">'; $buffy .= '</span>'; // datePublished $td_article_date_unix = get_the_time('U', $this->post->ID); $buffy .= '<meta itemprop="datePublished" content="' . date(DATE_W3C, $td_article_date_unix) . '">'; // dateModified $buffy .= '<meta itemprop="dateModified" content="' . the_modified_date('c', '', '', false) . '">'; // mainEntityOfPage $buffy .= '<meta itemscope itemprop="mainEntityOfPage" itemType="https://schema.org/WebPage" itemid="' . get_permalink($this->post->ID) . '"/>'; // publisher $buffy .= '<span style="display: none;" itemprop="publisher" itemscope itemtype="https://schema.org/Organization">'; $buffy .= '<span style="display: none;" itemprop="logo" itemscope itemtype="https://schema.org/ImageObject">'; $buffy .= '<meta itemprop="url" content="' . $td_publisher_logo . '">'; $buffy .= '</span>'; $buffy .= '<meta itemprop="name" content="' . $td_publisher_name . '">'; $buffy .= '</span>'; // headline @todo we may improve this one to use the subtitle or excerpt? - We could not find specs about what it should be. $buffy .= '<meta itemprop="headline " content="' . esc_attr($this->post->post_title) . '">'; // featured image $td_image = array(); if (!is_null($this->post_thumb_id)) { /** * from google documentation: * A URL, or list of URLs pointing to the representative image file(s). Images must be * at least 160x90 pixels and at most 1920x1080 pixels. * We recommend images in .jpg, .png, or. gif formats. * https://developers.google.com/structured-data/rich-snippets/articles */ $td_image = wp_get_attachment_image_src($this->post_thumb_id, 'full'); } else { // when the post has no image use the placeholder $td_image[0] = get_template_directory_uri() . '/images/no-thumb/td_meta_replacement.png'; $td_image[1] = '1068'; $td_image[2] = '580'; } // ImageObject meta if (!empty($td_image[0])) { $buffy .= '<span style="display: none;" itemprop="image" itemscope itemtype="https://schema.org/ImageObject">'; $buffy .= '<meta itemprop="url" content="' . $td_image[0] . '">'; $buffy .= '<meta itemprop="width" content="' . $td_image[1] . '">'; $buffy .= '<meta itemprop="height" content="' . $td_image[2] . '">'; $buffy .= '</span>'; } // if we have a review, we must add additional stuff if ($this->is_review) { // the item that is reviewd $buffy .= '<span style="display: none;" itemprop="itemReviewed" itemscope itemtype="https://schema.org/Thing">'; $buffy .= '<meta itemprop="name " content = "' . $this->title_attribute . '">'; $buffy .= '</span>'; if (!empty($this->td_review['review'])) { $buffy .= '<meta itemprop="reviewBody" content = "' . esc_attr($this->td_review['review']) . '">'; } else { //we have no review text :| get a excerpt for the about meta thing if ($this->post->post_excerpt != '') { $td_post_excerpt = $this->post->post_excerpt; } else { $td_post_excerpt = td_util::excerpt($this->post->post_content, 45); } $buffy .= '<meta itemprop="reviewBody" content = "' . esc_attr($td_post_excerpt) . '">'; } // review rating $buffy .= '<span style="display: none;" class="td-page-meta" itemprop="reviewRating" itemscope itemtype="' . td_global::$http_or_https . '://schema.org/Rating">'; $buffy .= '<meta itemprop="worstRating" content = "1">'; $buffy .= '<meta itemprop="bestRating" content = "5">'; $buffy .= '<meta itemprop="ratingValue" content = "' . td_review::calculate_total_stars($this->td_review) . '">'; $buffy .= ' </span>'; } return $buffy; }
function get_bread_crumbs() { $primary_category_id = ''; //read the post setting $td_post_theme_settings = get_post_meta($this->post->ID, 'td_post_theme_settings', true); if (!empty($td_post_theme_settings['td_primary_cat'])) { $primary_category_id = $td_post_theme_settings['td_primary_cat']; } else { $categories = get_the_category($this->post->ID); foreach ($categories as $category) { if ($category->name != TD_FEATURED_CAT) { //ignore the featured category name $primary_category_id = $category->cat_ID; break; } } } $category_1_name = ''; $category_1_url = ''; $category_2_name = ''; $category_2_url = ''; $primary_category_obj = get_category($primary_category_id); //print_r($primary_category_obj); if (!empty($primary_category_obj)) { if (!empty($primary_category_obj->name)) { $category_1_name = $primary_category_obj->name; } else { $category_1_name = ''; } if (!empty($primary_category_obj->cat_ID)) { $category_1_url = get_category_link($primary_category_obj->cat_ID); } if (!empty($primary_category_obj->parent) and $primary_category_obj->parent != 0) { $parent_category_obj = get_category($primary_category_obj->parent); if (!empty($parent_category_obj)) { $category_2_name = $parent_category_obj->name; $category_2_url = get_category_link($parent_category_obj->cat_ID); } } } //print_r($primary_category_obj); $td_separator = ' <span class="td-sp td-sp-breadcrumb-arrow td-bread-sep"></span> '; $buffy = ''; if (!empty($category_1_name)) { $buffy .= '<div itemscope="" itemtype="' . td_global::$http_or_https . '://schema.org/WebPage" class="entry-crumbs">'; //home if (td_util::get_option('tds_breadcrumbs_show_home') != 'hide') { $buffy .= '<a class="entry-crumb" itemprop="breadcrumb" href="' . get_home_url() . '">' . __td('Home') . '</a>'; } //parent category if (!empty($category_2_name) and td_util::get_option('tds_breadcrumbs_show_parent') != 'hide') { if (td_util::get_option('tds_breadcrumbs_show_home') != 'hide') { $buffy .= $td_separator; } $buffy .= '<a class="entry-crumb" itemprop="breadcrumb" href="' . $category_2_url . '" title="' . __td('View all posts in') . ' ' . htmlspecialchars($category_2_name) . '">' . $category_2_name . '</a>'; $buffy .= $td_separator; } else { if (td_util::get_option('tds_breadcrumbs_show_home') != 'hide') { $buffy .= $td_separator; } } $buffy .= '<a class="entry-crumb" itemprop="breadcrumb" href="' . $category_1_url . '" title="' . __td('View all posts in') . ' ' . htmlspecialchars($category_1_name) . '">' . $category_1_name . '</a>'; //article title if (td_util::get_option('tds_breadcrumbs_show_article') != 'hide') { $buffy .= $td_separator; $buffy .= '<span>' . td_util::excerpt($this->title, 13) . '</span>'; } $buffy .= '</div>'; } return $buffy; }
function get_excerpt($cut_excerpt_default = '') { //returns the uncut excerpt if ($this->post->post_excerpt != '') { return $this->post->post_excerpt; } $buffy = ''; if ($cut_excerpt_default != '') { $db_content_excerpt = td_util::get_option(get_class($this) . '_content_excerpt'); if ($db_content_excerpt != '') { //cut from the database settings $buffy .= td_util::excerpt($this->post->post_content, $db_content_excerpt); } else { //cut at the default size $buffy .= td_util::excerpt($this->post->post_content, $cut_excerpt_default); } } else { $buffy .= $this->post->post_content; } return $buffy; }