Exemplo n.º 1
1
function alaya_recent_comment($number)
{
    $commentNum = 1;
    // Get the comments
    $recent_comments = get_comments(array('number' => $number, 'status' => 'approve', 'type' => 'comment'));
    $commentList = '<ul>';
    foreach ($recent_comments as $comment) {
        $commentList .= '<li>
	             <header class="clearfix">
	                	<figure>
	                        <a href="' . get_permalink($comment->comment_post_ID) . '">
	                            ' . get_avatar($comment->comment_author_email, '40') . '
	                        </a>
	                        <span class="comment-author-name">
	                        ' . $comment->comment_author . '
	                        </span>
	                        <div class="comment-order">' . $commentNum . '</div>
	                    </figure>
	                    
	                    <a class="comment-post" href="' . esc_url(get_permalink($comment->comment_post_ID)) . '#comment-' . esc_attr($comment->comment_ID) . '">
	                       ' . esc_attr(get_the_title($comment->comment_post_ID)) . '
	                    </a>
	                </header>
	                
	                <div class="comment-text">
	                    <div class="up-arrow"></div>
	                	' . wp_trim_words($comment->comment_content, 30) . '
	                </div>
				</li>';
        $commentNum++;
    }
    $commentList .= '</ul>';
    return $commentList;
}
/**
* We're going to override the_content through a filter.
*/
function cap_podcast_player($id = null, $player_type = 'default')
{
    if (empty($id)) {
        $post_id = get_the_ID();
    } else {
        $post_id = $id;
    }
    $episode_number = get_post_meta($post_id, 'episode_number', true);
    // Get Episode Media Source
    $episode_attachment_id = get_post_meta($post_id, 'episode_file', true);
    $episode_external_file = get_post_meta($post_id, 'external_episode_file', true);
    if (!empty($episode_attachment_id)) {
        $player_src = wp_get_attachment_url($episode_attachment_id);
    } elseif (!empty($episode_external_file)) {
        $player_src = $episode_external_file;
    }
    $attr = array('src' => '' . $player_src . '', 'loop' => '', 'autoplay' => '', 'preload' => 'metadata');
    $player = wp_audio_shortcode($attr);
    $download_link = '<small><a href="' . $player_src . '" download="episode' . $episode_number . '.mp3">Download this Episode</a></small>';
    // Get Episode Artwork //
    $episode_artwork_id = get_post_thumbnail_id($post_id);
    $episode_artwork = wp_get_attachment_image_src($episode_artwork_id, 'cap-podcast-thumbnail');
    $episode_artwork_src = $episode_artwork[0];
    if ('default' == $player_type) {
        $episode_title = '
        <div class="episode-info">
            <h4>Episode #' . $episode_number . '</h4>
            <h2>' . get_the_title($post_id) . '</h2>
        </div>
        ';
    } elseif ('large' == $player_type) {
        $post_object = get_post($post_id);
        $episode_title = '
        <a href="' . get_permalink($post_id) . '" class="episode-info">
            <h4>Episode #' . $episode_number . '</h4>
            <h2>' . get_the_title($post_id) . '</h2>
            <span class="description">' . wp_trim_words($post_object->post_content, '60') . '</span>
        </a>
        ';
    } elseif ('mini' == $player_type) {
        $episode_title = '';
    }
    // Construct Markup
    $markup = '
    <div class="episode-header">
        <div class="episode-artwork-container">
            <div class="episode-artwork" style="background-image: url(' . $episode_artwork_src . ');">
                <div id="play-episode" class="maintain-ratio">
                    <span class="dashicons"></span>
                </div>
            </div>
        </div>
        ' . $episode_title . '
    </div>';
    $script = "\n    <script type='text/javascript'>\n    var playerID = jQuery('#episode-" . $episode_number . "-" . $post_id . " audio').attr('id');\n    var player" . $post_id . " = document.getElementById(playerID);\n    jQuery('#episode-" . $episode_number . "-" . $post_id . " #play-episode').click(function(){\n        jQuery('#episode-" . $episode_number . "-" . $post_id . " #play-episode .dashicons').toggleClass('paused');\n    });\n\n    jQuery('#episode-" . $episode_number . "-" . $post_id . " #play-episode').click(function() {\n\n        if ( jQuery('#episode-" . $episode_number . "-" . $post_id . " #play-episode .dashicons').hasClass('paused') ) {\n            player" . $post_id . ".play();\n        }\n\n        if ( !jQuery('#episode-" . $episode_number . "-" . $post_id . " #play-episode .dashicons').hasClass('paused') ) {\n            player" . $post_id . ".pause();\n        }\n\n    });\n    </script>\n    ";
    if (function_exists('cap_podcast_player_colors')) {
        $player .= cap_podcast_player_colors($post_id);
    }
    return '<div id="episode-' . $episode_number . '-' . $post_id . '" class="podcast-player ' . $player_type . '">' . $markup . $player . $download_link . $script . '</div>';
}
/**
 * Function to retrive most downloaded software list for the home page
 *
 * @return array
 *
 */
function get_top_downloads_home()
{
    $limit = 5;
    $json_path = ABSPATH . "../top.json";
    $baixades_json = json_decode(file_get_contents($json_path));
    $programari = array();
    if ($baixades_json) {
        foreach ($baixades_json as $key => $operating_system) {
            $programari[$key] = array();
            $i = 0;
            foreach ($operating_system as $pkey => $program) {
                if ($i < $limit) {
                    $link = get_program_link($program);
                    if ($link) {
                        $programari[$key][$pkey]['title'] = wp_trim_words(str_replace('_', ' ', get_the_title($program->wordpress_id)), 8);
                        $programari[$key][$pkey]['link'] = $link;
                        $programari[$key][$pkey]['total_downloads'] = $program->total;
                    }
                    $i++;
                }
            }
        }
    }
    return $programari;
}
Exemplo n.º 4
0
 function uw_blogroll_shortcode($atts = array())
 {
     //allow pagebuilder widgets to run the shortcode, block all other posts to prevent infinite loops
     if (get_post_type() == 'post' && !is_home()) {
         return '';
     }
     $params = array_merge(array('excerpt' => 'true', 'trim' => 'false', 'image' => 'hide', 'author' => 'show', 'titletag' => 'h2', 'number' => 5), $atts);
     if (!array_key_exists('numberposts', $params)) {
         $params['numberposts'] = $params['number'];
     }
     $posts = get_posts($params);
     foreach ($posts as $post) {
         if (!stripos($post->post_content, '[blogroll')) {
             //to prevent infinite loops in pagebuilder widgets
             $postID = $post->ID;
             $link = get_permalink($postID);
             if (in_array($params['excerpt'], array('show', 'true'))) {
                 $excerpt = strlen($post->post_excerpt) > 0 ? $post->post_excerpt : apply_filters('widget_text', $post->post_content);
                 if (in_array($params['trim'], array('show', 'true'))) {
                     $excerpt = wp_trim_words($excerpt);
                 }
                 $excerpt = wpautop($excerpt);
                 //using apply_filters('the_content', $excerpt) causes an infinite loop
                 if (in_array($params['image'], array('show', 'true'))) {
                     $image = get_the_post_thumbnail($postID, 'thumbnail', array('style' => 'float:left;padding-right:10px;'));
                     $class = 'class="pull-left"';
                 }
             }
             $author = $params['author'] === 'show' ? '<p class="author-info">' . get_the_author_meta('display_name', $post->post_author) . '</p>' : '';
             $postDate = get_the_time(get_option('date_format'), $postID);
             $html .= "<li {$class}>{$image}<span><p class=\"date\">{$postDate}</p><" . $params['titletag'] . "><a href=\"{$link}\">{$post->post_title}</a></" . $params['titletag'] . ">{$author}{$excerpt}</span></li>";
         }
     }
     return "<ul class=\"shortcode-blogroll\">{$html}</ul>";
 }
Exemplo n.º 5
0
function tgp_get_products()
{
    // Connect to the database
    $db = new wpdb(get_option('db_user'), get_option('db_pass'), get_option('db_name'), get_option('db_host'));
    // Get values
    $store_url = get_option('store_url');
    $img_folder = get_option('img_folder');
    $num_products = get_option('num_products');
    // Get Products
    $products = $db->get_results("SELECT * FROM products LIMIT " . $num_products);
    // Build Output
    $output = '';
    if ($products) {
        foreach ($products as $product) {
            $output .= '<div class="tgp_product">';
            $output .= '<h3>' . $product->title . '</h3>';
            $output .= '<img src="' . $store_url . '/' . $img_folder . '/' . $product->image . '" alt="' . $product->title . '">';
            $output .= '<div class="price">' . $product->price . '</div>';
            $output .= '<div class="desc">' . wp_trim_words($product->description, 10) . '</div>';
            $output .= '<a href="' . $store_url . 'products/details/' . $product->id . '">Buy Now</a>';
        }
    } else {
        $output .= 'No products to list';
    }
    return $output;
}
Exemplo n.º 6
0
 function get_fb_posts($num, $truncate_words = false, $divs = true)
 {
     $posts = get_facebook_posts();
     $i = 1;
     foreach ($posts as $post) {
         if ($i > $num) {
             break;
         }
         if ($i < $num) {
             $i++;
             continue;
         }
         if (empty($post['content'])) {
             $post_content = $post['link_description'];
         } elseif (!empty($post['content'])) {
             $post_content = $post['content'];
         } else {
             $post_content = 'Enclothed - Men\'s bespoke outfitters';
         }
         $post_content = utf8_decode($post_content);
         $post_content = wp_trim_words($post_content, $truncate_words);
         $post_content = make_clickable($post_content);
         if ($divs) {
             echo "<div class='fb_post' style='padding-bottom:20px'>";
             echo "<div class='fb_post_content'>{$post_content}</div>";
             echo "</div>";
         } else {
             echo $post_content;
         }
         $i++;
     }
 }
Exemplo n.º 7
0
function ubermenu_recent_posts($atts)
{
    global $uberMenu;
    extract(shortcode_atts(array('num' => 3, 'img' => 'on', 'img_size' => 'inherit', 'img_width' => 45, 'img_height' => 45, 'excerpt' => 'off', 'category' => '', 'default_img' => false, 'offset' => 0), $atts));
    $args = array('numberposts' => $num, 'offset' => $offset, 'suppress_filters' => false);
    if (!empty($category)) {
        if (is_numeric($category)) {
            $args['category'] = $category;
        } else {
            $args['category_name'] = $category;
        }
    }
    $posts = get_posts($args);
    $class = 'ubermenu-postlist';
    if ($img == 'on') {
        $class .= ' ubermenu-postlist-w-img';
    }
    $html = '<ul class="' . $class . '">';
    foreach ($posts as $post) {
        $ex = $post->post_excerpt;
        if ($ex == '' && function_exists('wp_trim_words')) {
            //wp_trim_words is a WP3.3 function
            $ex = $post->post_content;
            $ex = strip_shortcodes($ex);
            $ex = str_replace(']]>', ']]&gt;', $ex);
            $excerpt_length = apply_filters('excerpt_length', 55);
            $excerpt_more = apply_filters('excerpt_more', ' ' . '[...]');
            $ex = wp_trim_words($ex, $excerpt_length, $excerpt_more);
        }
        //$ex = apply_filters('get_the_excerpt', $post->post_excerpt);
        $post_url = get_permalink($post->ID);
        $image = '';
        $w = $img_width;
        $h = $img_height;
        $content_styles = array();
        //if($img == 'on') $image = $uberMenu->getPostImage($post->ID, $w, $h, $default_img);
        if ($img == 'on') {
            $img_data = ubermenu_get_image(false, $post->ID, true, array('img_w' => $w, 'img_h' => $h, 'img_size' => $img_size, 'default_img' => $default_img));
            if (isset($img_data['img'])) {
                $image = $img_data['img'];
                $content_styles['padding-left'] = $img_data['w'] + 10 . 'px';
            }
        }
        $_content_styles = '';
        if (!empty($content_styles)) {
            $_content_styles = 'style="';
            foreach ($content_styles as $prop => $val) {
                $_content_styles .= $prop . ':' . $val . ';';
            }
            $_content_styles .= '"';
        }
        $html .= '<li class="ubermenu-postlist-item">' . $image . '<div class="ubermenu-postlist-title" ' . $_content_styles . '><a href="' . $post_url . '">' . $post->post_title . '</a></div>';
        if ($excerpt == 'on') {
            $html .= '<div class="ubermenu-postlist-content" ' . $_content_styles . '>' . $ex . '</div>';
        }
        $html .= '</li>';
    }
    $html .= '</ul>';
    return $html;
}
Exemplo n.º 8
0
function wp_aatags_run($post_ID)
{
    $tags = get_option('wp_aatags_opts');
    $number = get_option('wp_aatags_aadnumber');
    global $wpdb;
    if (get_post($post_ID)->post_type == 'post' && !wp_is_post_revision($post_ID) && !get_the_tags($post_ID)) {
        $post_title = get_post($post_ID)->post_title;
        $post_content = get_post($post_ID)->post_content;
        switch ($tags) {
            case 3:
                $requix = strtolower($post_title . ' ' . wp_trim_words($post_content, 333, ''));
                break;
            case 2:
                $requix = strtolower($post_title . ' ' . wp_trim_words($post_content, 999, ''));
                break;
            default:
                $requix = strtolower($post_title);
                break;
        }
        $body = wp_aatags_keycontents(wp_aatags_html2text($requix), $number);
        if ($body != 'rEr') {
            $keywords = wp_aatags_kwsiconv($body);
            wp_add_post_tags($post_ID, $keywords);
        } else {
            wp_aatags_alts($post_ID, $post_title, $post_content);
        }
    }
}
Exemplo n.º 9
0
 /**
  * Returns shortened string
  *
  * @since     1.0
  */
 protected function get_shortened_string($string = '', $num_words = 55, $more = null)
 {
     if (!$string) {
         return false;
     }
     return wp_trim_words($string, $num_words, $more);
 }
Exemplo n.º 10
0
 function vcex_get_excerpt($length = 30, $readmore = false, $read_more_text = '', $post_id = '')
 {
     global $post;
     $id = $post_id ? $post_id : $post->ID;
     $custom_excerpt = apply_filters('the_content', $post->post_excerpt);
     if ($custom_excerpt) {
         $output = $custom_excerpt;
     } else {
         $meta_excerpt = get_post_meta($id, 'vcex_excerpt_length', true);
         $length = $meta_excerpt ? $meta_excerpt : $length;
         $read_more_text = $read_more_text ? $read_more_text : __('view post', 'vcex');
         $excerpt = get_the_content('');
         $excerpt = do_shortcode($excerpt);
         $excerpt = apply_filters('the_content', $excerpt);
         $excerpt = str_replace(']]>', ']]>', $excerpt);
         $excerpt = apply_filters('the_content', $excerpt);
         $excerpt = wp_trim_words($excerpt, $length);
         $excerpt = wp_kses($excerpt, array('a' => array('href' => array(), 'title' => array()), 'br' => array(), 'em' => array(), 'strong' => array()));
         $output = '<p>' . html_entity_decode($excerpt) . '</p>';
     }
     if ($readmore == true) {
         $readmore_link = '<a href="' . get_permalink($id) . '" title="' . __('View Post', 'vcex') . '" rel="bookmark" class="vcex-readmore theme-button">' . $read_more_text . ' <span class="vcex-readmore-rarr">&rarr;</span></a>';
         $output .= apply_filters('vcex_readmore_link', $readmore_link);
     }
     return $output;
 }
 function evision_corporate_words_count($length = 25, $evision_corporate_content = null)
 {
     $length = absint($length);
     $source_content = preg_replace('`\\[[^\\]]*\\]`', '', $evision_corporate_content);
     $trimmed_content = wp_trim_words($source_content, $length, '...');
     return $trimmed_content;
 }
 /**
  * Add a shortcode to display the product content
  *
  * @since 1.0
  */
 public function product_content_shortcode($atts, $content = null)
 {
     // Get our shortcode attributes
     $atts = shortcode_atts(array('id' => '', 'length' => ''), $atts, 'product_content');
     extract($atts);
     // Get our post content
     $product = get_post($id);
     // If there is no product found, stop
     if (!$product) {
         return;
     }
     $content = wpautop($product->post_content);
     // Assume zer is nussing
     $output = '';
     // If our content returns something, display it
     if ($content) {
         // If we have a length set, apply it
         if ('' !== $length) {
             $excerpt_length = $length;
             $excerpt_more = '&hellip;';
             $output .= '<p>' . wp_trim_words($content, $excerpt_length, $excerpt_more) . ' <a href="' . get_permalink($id) . '" class="more-link">' . __('Continue reading', 'etsy_importer') . ' <span class="screen-reader-text">' . $product->post_title . '</span></a></p>';
         } else {
             $output .= $content;
         }
     }
     return apply_filters('etsy_importer_product_content_shortcode', $output, $atts);
 }
Exemplo n.º 13
0
					<p>
						<?php 
        //var_dump(get_the_content().'---'.$length);
        echo wp_trim_words(get_the_content(), $length, '&hellip; <a href="' . get_permalink() . '">' . __('Read more', 'yatheme') . '</a>');
        ?>
						
					</p>
                    </div>
				</div>
			</div>
		<?php 
    }
    ?>
		</div>
		<?php 
}
function tabs_popular_posts($posts, $length)
{
    $popular = new WP_Query('orderby=comment_count&posts_per_page=' . $posts);
    //$popular_post_num = 1;
    ?>
		<div class="row-fluid tab-post">
		<?php 
    while ($popular->have_posts()) {
        $popular->the_post();
        ?>
			<div class="tab-item">
				<div class="row-fluid">
						<div class="comment">
							<?php 
        if ((int) get_post()->comment_count > 1) {
            echo get_post()->comment_count . ' ';
        } else {
Exemplo n.º 14
0
 public static function save_report_item()
 {
     if (!isset($_POST[DLN_ABE_NONCE]) || !wp_verify_nonce($_POST[DLN_ABE_NONCE], DLN_ABE_NONCE)) {
         $item_id = isset($_POST['report_item_id']) ? $_POST['report_item_id'] : '';
         $category = isset($_POST['report_category']) ? (int) $_POST['report_category'] : '';
         $message = isset($_POST['report_reason']) ? $_POST['report_reason'] : '';
         $user_id = get_current_user_id();
         $message = esc_html($message);
         $title = wp_trim_words($message, 20, '...');
         if ($user_id && $item_id && $category && $message && $title) {
             $args = array('post_title' => $title, 'post_status' => 'pending', 'post_type' => 'dln_report', 'post_author' => $user_id, 'post_content' => $message, 'post_category' => array($category), 'comment_status' => 'open');
             $post_id = wp_insert_post($args);
             if ($post_id) {
                 // Get current user ip
                 $ip = !empty($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : '';
                 update_post_meta($post_id, 'dln_report_post_id', $item_id);
                 update_post_meta($post_id, 'dln_report_user_ip', $ip);
                 // Update count to post
                 $count = (int) get_post_meta($item_id, 'dln_count_report', true);
                 if ($count) {
                     update_post_meta($item_id, 'dln_count_report', $count + 1);
                 }
             }
         }
         exit($post_id);
     }
     exit('0');
 }
/**
 * Based (with preserved compatibility) on Storefront Blog Excerpts plugin.
 */
function pbosfc_post_excerpt()
{
    if (!pbosfc_get_option('post_excerpt')) {
        storefront_post_content();
    } else {
        ?>
		<div class="entry-content" itemprop="articleBody">
			<?php 
        if (has_post_thumbnail()) {
            $thumb_size = pbosfc_get_option('excerpt_image_size');
            if ($thumb_size !== 'none') {
                $img_class = $thumb_size == 'thumbnail' ? apply_filters('woa_sf_blog_excerpt_image_float', pbosfc_get_option('excerpt_image_float')) : '';
                the_post_thumbnail($thumb_size, array('itemprop' => 'image', 'class' => "attachment-{$thumb_size} {$img_class}"));
            }
        }
        $content = do_shortcode(has_excerpt(get_the_ID()) ? get_the_excerpt() : get_the_content());
        $content = wp_trim_words($content, pbosfc_get_option('excerpt_word_count'), __('...', 'pbosfc'));
        echo apply_filters('the_excerpt', $content);
        ?>
			<p class="read-more"><a class="button"
			                        href="<?php 
        the_permalink();
        ?>
"><?php 
        echo __('Continue reading', 'pbosfc');
        ?>
</a>
			</p>
		</div><!-- .entry-content -->
		<?php 
    }
}
Exemplo n.º 16
0
 /**
  * Fetches an instance of Exporter.
  *
  * @return Exporter
  * @access public
  */
 public function fetch_exporter()
 {
     do_action('apple_news_do_fetch_exporter', $this->id);
     // Fetch WP_Post object, and all required post information to fill up the
     // Exporter_Content instance.
     $post = get_post($this->id);
     // Build the excerpt if required
     if (empty($post->post_excerpt)) {
         $excerpt = wp_trim_words(strip_tags(strip_shortcodes($post->post_content)), 55, '...');
     } else {
         $excerpt = strip_tags($post->post_excerpt);
     }
     // Get the post thumbnail
     $post_thumb = wp_get_attachment_url(get_post_thumbnail_id($this->id)) ?: null;
     // Build the byline
     $byline = $this->format_byline($post);
     // Filter each of our items before passing into the exporter class.
     $title = apply_filters('apple_news_exporter_title', $post->post_title, $post->ID);
     $excerpt = apply_filters('apple_news_exporter_excerpt', $excerpt, $post->ID);
     $post_thumb = apply_filters('apple_news_exporter_post_thumb', $post_thumb, $post->ID);
     $byline = apply_filters('apple_news_exporter_byline', $byline, $post->ID);
     // The post_content is not raw HTML, as WordPress editor cleans up
     // paragraphs and new lines, so we need to transform the content to
     // HTML. We use 'the_content' filter for that.
     $content = apply_filters('apple_news_exporter_content_pre', $post->post_content, $post->ID);
     $content = apply_filters('the_content', $content);
     $content = apply_filters('apple_news_exporter_content', $content, $post->ID);
     // Now pass all the variables into the Exporter_Content array.
     $base_content = new Exporter_Content($post->ID, $title, $content, $excerpt, $post_thumb, $byline, $this->fetch_content_settings());
     return new Exporter($base_content, null, $this->settings);
 }
Exemplo n.º 17
0
 public function register_meta_tags()
 {
     add_action('wp_head', function () {
         if (is_singular() && false == post_password_required()) {
             if ('' == ($description = get_the_excerpt())) {
                 $description = wp_trim_words(esc_html(strip_shortcodes(get_the_content())), 20, '...');
             }
         } elseif (is_category() && '' != category_description()) {
             $description = category_description();
         } elseif (is_tag() && '' != term_description()) {
             $description = term_description();
         } else {
             $description = get_bloginfo('description');
         }
         $description = esc_attr($description);
         echo "<meta name=\"description\" content=\"{$description}\" />\n";
         echo "<meta name=\"og:description\" content=\"{$description}\" />\n";
         if (is_singular() && false == post_password_required() && has_post_thumbnail()) {
             list($image, $width, $height) = wp_get_attachment_image_src(get_post_thumbnail_id(), 'facebook');
         } else {
             $image = apply_filters('', $this->get_theme_assets_url() . '/images/logo-fb.png');
         }
         $image = esc_url($image);
         echo "<meta name=\"og:image\" content=\"{$image}\" />\n";
         echo "<meta name=\"twitter:image\" content=\"{$image}\" />\n";
     });
 }
Exemplo n.º 18
0
/**
 * Reduce the length of custom excerpt (if specified manually) for widgets.
 *
 * @param string $excerpt Current excerpt
 *
 * @since 1.0.0
 *
 * @return string
 */
function appica_widget_trim_excerpt($excerpt)
{
    if (false === strpos($excerpt, '...') && str_word_count($excerpt) > 9) {
        $excerpt = wp_trim_words($excerpt, 9, ' ...');
    }
    return $excerpt;
}
Exemplo n.º 19
0
/**
 * Function to create an excerpt for the post.
 *
 * @since 1.6
 *
 * @param int        $id Post ID
 * @param int|string $excerpt_length Length of the excerpt in words
 * @return string Excerpt
 */
function crp_excerpt($id, $excerpt_length = 0, $use_excerpt = true)
{
    $content = $excerpt = '';
    if ($use_excerpt) {
        $content = get_post($id)->post_excerpt;
    }
    if ('' == $content) {
        $content = get_post($id)->post_content;
    }
    $output = strip_tags(strip_shortcodes($content));
    if ($excerpt_length > 0) {
        $output = wp_trim_words($output, $excerpt_length);
    }
    /**
     * Filters excerpt generated by CRP.
     *
     * @since	1.9
     *
     * @param	array	$output			Formatted excerpt
     * @param	int		$id				Post ID
     * @param	int		$excerpt_length	Length of the excerpt
     * @param	boolean	$use_excerpt	Use the excerpt?
     */
    return apply_filters('crp_excerpt', $output, $id, $excerpt_length, $use_excerpt);
}
/**
 * Created by PhpStorm.
 * User: cleavesp
 * Date: 3/30/15
 * Time: 10:20 AM
 */
function ms_ajax_search_articles()
{
    global $api_access_keys;
    $target_env = $_POST['env'];
    $article_search_type = $_POST['searchtype'];
    $search_term = $_POST['searchterm'];
    $results_order_by = $_POST['orderby'];
    $args = array('post_type' => $article_search_type, 's' => $search_term, 'posts_per_page' => -1);
    $the_query = new WP_Query($args);
    $output = array();
    if ($the_query->have_posts()) {
        while ($the_query->have_posts()) {
            $the_query->the_post();
            //$html_item = ms_format_content_item_html(get_the_ID());
            //$html_item = esc_html($html_item);
            $image_attributes = wp_get_attachment_image_src(get_post_thumbnail_id(get_the_ID()));
            $content_categories = wp_get_post_categories(get_the_ID());
            $isCuratedLink = false;
            foreach ($content_categories as $c) {
                $cat = get_category($c);
                if ($cat->slug == 'curatedlink') {
                    $isCuratedLink = true;
                    break;
                }
            }
            array_push($output, array('title' => get_the_title(), 'body' => wp_trim_words(get_the_content(), 18), 'byline' => get_post_meta(get_the_ID(), 'byLine', true), 'sourcePubName' => get_post_meta(get_the_ID(), 'sourcePublicationName', true), 'articlePlacementId' => get_post_meta(get_the_ID(), 'articlePlacementId_en_' . $target_env, true), 'origin_url' => get_post_meta(get_the_ID(), 'originUrl', true), 'sourceId' => get_post_meta(get_the_ID(), 'sourceId', true), 'lastPublished' => get_post_meta(get_the_ID(), 'LastPublished' . $target_env, true), 'thumbnail' => $image_attributes[0], 'editlink' => get_admin_url(null, '/post.php?post=' . get_the_ID() . '&action=edit'), 'mansionid' => get_the_ID(), 'previewLink' => get_permalink(get_the_ID()), 'wordpress_post_id' => get_the_ID(), 'externalid' => get_post_meta(get_the_ID(), 'sourceId', true), 'curatedLinkId' => get_post_meta(get_the_ID(), 'curated_link_id_' . $target_env, true), 'quote' => get_post_meta(get_the_ID(), 'Quote', true), 'headline' => get_post_meta(get_the_ID(), 'Headline', true), 'sub_headline' => get_post_meta(get_the_ID(), 'Subtitle', true), 'action_url' => get_post_meta(get_the_ID(), 'Url', true), 'credit' => get_post_meta(get_the_ID(), 'credit', true), 'isCuratedLink' => $isCuratedLink));
        }
    }
    $response = array('res' => $output, 'httpCode' => '200');
    $json = json_encode($response);
    echo $json;
    die;
}
Exemplo n.º 21
0
function rpr_post_updated_send_email($post_id)
{
    // If this is just a revision, don't send the email.
    if (wp_is_post_revision($post_id)) {
        return;
    }
    if (get_option('readygraph_application_id') && strlen(get_option('readygraph_application_id')) > 0 && get_option('readygraph_send_blog_updates') == "true") {
        $post_title = get_the_title($post_id);
        $post_url = get_permalink($post_id);
        $post_content = get_post($post_id);
        if (get_option('readygraph_send_real_time_post_updates') == 'true') {
            $url = 'http://readygraph.com/api/v1/post.json/';
            $response = wp_remote_post($url, array('body' => array('is_wordpress' => 1, 'is_realtime' => 1, 'message' => $post_title, 'message_link' => $post_url, 'message_excerpt' => wp_trim_words($post_content->post_content, 100), 'client_key' => get_option('readygraph_application_id'), 'email' => get_option('readygraph_email'))));
        } else {
            $response = wp_remote_post($url, array('body' => array('is_wordpress' => 1, 'message' => $post_title, 'message_link' => $post_url, 'message_excerpt' => wp_trim_words($post_content->post_content, 100), 'client_key' => get_option('readygraph_application_id'), 'email' => get_option('readygraph_email'))));
        }
        if (is_wp_error($response)) {
            $error_message = $response->get_error_message();
            //echo "Something went wrong: $error_message";
        } else {
            //echo 'Response:<pre>';
            //print_r( $response );
            //echo '</pre>';
        }
        $app_id = get_option('readygraph_application_id');
        wp_remote_get("http://readygraph.com/api/v1/tracking?event=post_created&app_id={$app_id}");
    } else {
    }
}
Exemplo n.º 22
0
/**
 * Fetches a list of tweets
 */
function fsp_fetch_twitter()
{
    // Require the Twitter PHP API
    require_once 'twitter-api-php/TwitterAPIExchange.php';
    // set access tokens
    $settings = array('oauth_access_token' => SSF_TWITTER_OAUTH_TOKEN, 'oauth_access_token_secret' => SSF_TWITTER_OAUTH_SECRET, 'consumer_key' => SSF_TWITTER_CONSUMER_KEY, 'consumer_secret' => SSF_TWITTER_CONSUMER_SECRET);
    $twitter = new TwitterAPIExchange($settings);
    $params = "?screen_name=" . SSF_TWITTER_USERNAME;
    $response = $twitter->setGetfield($params)->buildOauth('https://api.twitter.com/1.1/statuses/user_timeline.json', 'GET')->performRequest();
    $response = json_decode($response);
    $items = array();
    foreach ($response as $tweet) {
        $item = array();
        $item['type'] = 'twitter';
        $item['source'] = 'https://twitter.com/' . $tweet->user->screen_name . '/status/' . $tweet->id;
        $item['uid'] = $tweet->id;
        $item['created'] = strtotime($tweet->created_at);
        $item['title'] = wp_trim_words($tweet->text, 6);
        $item['content'] = $tweet->text;
        // tweet might have an image
        if (isset($tweet->extended_entities->media) && $tweet->extended_entities->media[0]->type == 'photo') {
            $item['image'] = $tweet->extended_entities->media[0]->media_url_https;
        }
        $items[] = $item;
    }
    return $items;
}
Exemplo n.º 23
0
 /**
  * The front-end view of the widget
  *
  * @param array $args Base widget data such as before_title.
  * @param arry $instance Widget data.
  * @return string Widget HTML.
  */
 public function view($args, $instance)
 {
     $html = $cat = '';
     if (isset($instance['num_posts']) && !empty($instance['num_posts'])) {
         $posts_per = absint($instance['num_posts']);
     } else {
         $posts_per = 1;
     }
     // If user specifies specific categories, declare. Otherwise use all cats
     if (isset($instance['category'])) {
         $cat = esc_attr($instance['category']);
     } else {
         $categories = get_categories();
         foreach ($categories as $category) {
             $cat .= $category->slug . ",";
         }
     }
     // Our loop arguments
     $query = array('posts_per_page' => $posts_per, 'category_name' => $cat, 'order' => 'DESC', 'orderby' => 'date');
     $objects = new \WP_Query($query);
     if ($objects->have_posts()) {
         $html .= $this->get_widget_title($args, $instance);
         while ($objects->have_posts()) {
             $objects->the_post();
             $html .= "<h3>" . get_the_title() . "</h3>";
             $html .= apply_filters('the_content', wp_trim_words(get_the_content(), '50'));
             $html .= "<a href='" . get_permalink() . "' class='button'>Read More</a>";
         }
     }
     return $html;
 }
Exemplo n.º 24
0
 function rs_set_meta()
 {
     if (isset($this->program->text)) {
         echo '<meta property="og:description" content="' . wp_trim_words($this->program->text, 100, '...') . '" />';
     }
     echo '<meta property="og:title" content="' . $this->rs_set_title() . '" />';
 }
Exemplo n.º 25
0
function fb_strip_and_format_desc($post)
{
    $desc_no_html = "";
    $desc_no_html = strip_shortcodes($desc_no_html);
    // Strip shortcodes first in case there is HTML inside the shortcode
    $desc_no_html = wp_strip_all_tags($desc_no_html);
    // Strip all html
    $desc_no_html = trim($desc_no_html);
    // Trim the final string, we may have stripped everything out of the post so this will make the value empty if that's the case
    // Check if empty, may be that the strip functions above made excerpt empty, doubhtful but we want to be 100% sure.
    if (empty($desc_no_html)) {
        $desc_no_html = $post->post_content;
        // Start over, this time with the post_content
        $desc_no_html = strip_shortcodes($desc_no_html);
        // Strip shortcodes first in case there is HTML inside the shortcode
        $desc_no_html = str_replace(']]>', ']]&gt;', $desc_no_html);
        // Angelo Recommendation, if for some reason ]]> happens to be in the_content, rare but We've seen it happen
        $desc_no_html = wp_strip_all_tags($desc_no_html);
        $excerpt_length = apply_filters('excerpt_length', 55);
        $excerpt_more = apply_filters('excerpt_more', ' ' . '[...]');
        $desc_no_html = wp_trim_words($desc_no_html, $excerpt_length, $excerpt_more);
        $desc_no_html = trim($desc_no_html);
        // Trim the final string, we may have stripped everything out of the post so this will make the value empty if that's the case
    }
    $desc_no_html = str_replace(array("\r\n", "\r", "\n"), ' ', $desc_no_html);
    // I take it Facebook doesn't like new lines?
    return $desc_no_html;
}
/**
 * Created by PhpStorm.
 * User: cleavesp
 * Date: 3/30/15
 * Time: 3:13 PM
 */
function ms_format_content_item_html($post_id)
{
    $output = '<li class=\'article-item clear\'>';
    if (has_post_thumbnail()) {
        $output .= '<a class=\'alignleft\' href=\'' . the_permalink() . '\' title=\'' . the_title_attribute() . '\'>';
        $output .= get_the_post_thumbnail($post_id);
    }
    $output .= '<div class=\'article-body\'><h3><a href=\'' . the_permalink() . '\'>' . the_title() . '</a></h3>';
    $output .= '<p class=\'entry-content\'>';
    $trimmed_content = wp_trim_words(get_the_content(), 18, '<a class=\'read-more\' href=\'' . get_permalink() . '\'>... Read More</a>');
    $output .= $trimmed_content;
    $output .= '</p>';
    if (get_post_meta(get_the_ID(), 'sourcePub', true)) {
        $output .= '<div class=\'source-flag\'>';
        $output .= '<a href=\'' . get_post_meta(get_the_ID(), 'originUrl', true) . '\'></a></div>';
        $sourcePub = get_post_meta(get_the_ID(), 'sourcePub', true);
        if ($sourcePub === 'WSJ') {
            $output .= '<img src=\'' . get_bloginfo('template_directory') . '/img/wsj_logo.png' . '\' alt=\'Source Logo\' />';
        } elseif ($sourcePub === 'NEWSAUS') {
            $output .= '<img src=\'' . get_bloginfo('template_directory') . '/img/newsaus_logo.png' . '\' alt=\'Source Logo\' />';
        } elseif ($sourcePub === 'NEWSUK') {
            $output .= '<img src=\'' . get_bloginfo('template_directory') . '/img/newsuk_logo.png' . '\' alt=\'Source Logo\' />';
        } elseif ($sourcePub === 'NYPOST') {
            $output .= '<img src=\'' . get_bloginfo('template_directory') . '/img/nypost_logo.png' . '\' alt=\'Source Logo\' />';
        }
    }
    $output .= '</li>';
    return $output;
}
function nest_custom_excerpt($length_callback = '', $more_callback = '')
{
    global $post;
    $content = get_the_content();
    $trimmed_content = wp_trim_words($content, $length_callback, '... <a class="more" href="' . get_permalink() . '">' . $more_callback . '</a>');
    echo $trimmed_content;
}
/** 
 * Example of adjusting restricted content (v1.6.0+)
 * 	Changes excerpts to use 120 words instead of WordPress default
 *
 * @param string $content the content being restricted
 * @param bool $restricted true if the content is restricted for the viewer
 * @param string $message the restricted content notice HTML
 * @param object $post the post object being restricted
 * @return string - the updated restricted content
 */
function sv_wc_memberships_filter_restricted_content($content, $restricted, $message, $post)
{
    if (true === $restricted) {
        return wp_trim_words($content, 120) . $message;
    }
    return $content;
}
Exemplo n.º 29
0
 public function ya_trim_words($text, $num_words = 30, $more = null)
 {
     $text = strip_shortcodes($text);
     $text = apply_filters('the_content', $text);
     $text = str_replace(']]>', ']]&gt;', $text);
     return wp_trim_words($text, $num_words, $more);
 }
Exemplo n.º 30
0
 /**
  * Reduce the length of custom excerpt (if specified manually).
  *
  * @since 1.0.0
  *
  * @param string $excerpt Current excerpt
  *
  * @return string
  */
 public static function trim_excerpt($excerpt)
 {
     if (false === strpos($excerpt, '...') && str_word_count($excerpt) > 9) {
         $excerpt = wp_trim_words($excerpt, 9, ' ...');
     }
     return $excerpt;
 }