$5$7';
$content = preg_replace($pattern, $replacement, $content, 1);
}
return $content;
}
add_filter('the_content', 'dropcap_the_content_filter', 90);
/**
* Adds end-mark filter to the_content() method; only applies to columns and articles.
*
* @param type $content
* @return type
*/
function endmark_the_content_filter($content = '')
{
if (get_post_type() == 'columns' || get_post_type() == 'articles') {
$pattern = '
';
$replacement = ' ';
$content = substr_replace($content, $replacement, strrpos($content, $pattern), strlen($pattern));
}
return $content;
}
/* add_filter('the_content', 'endmark_the_content_filter', 91); */
$impSearch = new ImprovedSearch();
/**
* Allows categories to be searched. Based off of SearchEverything.
*
* IMPORTANT: "Why some queries need to be run twice to return proper results."
*
* WordPress primarily distributes it's classes by global variables and expects
* plugins to use these global variables. This is becomes a problem when you're
* trying to extend the functionality of said objects (such as WP_Query, in this
* case). Since the $wp_query variable does not get assigned until after
* class instantiation, data such as search query vars run stagnant from the last
* query run.
*
* This could probably be fixed by making ImprovedSearch extend or composite the
* WP_Query object.
*
* The methods saveQueryState() and restoreQueryState() are also involved in this
* hackjob. Assuming a proper implementation is created, these can be removed.
* Furthermore, things like the 'enabled' and 'isSearch' functionality is bound
* to this problem as well. If things get hairy down the road, it might be a good
* idea to just refactor this class to composite the WP_Query object.
*
* - robzienert 2.22.11
*/
class ImprovedSearch
{
private $queryState;
private static $enabled = false;
private static $searchTerms;
/**
* Add hooks to the query building process.
*
*/
public function __construct()
{
add_filter('parse_query', array(&$this, 'saveQueryState'), 10);
add_filter('pre_get_posts', array(&$this, 'restoreQueryState'), 10);
add_filter('posts_groupby', array(&$this, 'queryGroup'), 900);
add_filter('posts_join', array(&$this, 'queryJoin'), 900);
add_filter('posts_search', array(&$this, 'queryWhere'), 900);
}
/**
* Just a handy little debugging method for various hooks.
*/
public function debug()
{
var_dump(func_get_args());
}
/**
* Saves the original $wp_query state into the object. I'm not sure why, but
* when filters get added to the `posts_search` hook, things just start
* disappearing. This lets us add various query values back into the query
* in our filters.
*
* @param object $wp_query
* @return void
*/
public function saveQueryState($wp_query)
{
if ($this->isSearch())
$this->queryState = $wp_query->query_vars;
}
/**
* Restores the saved $wp_query state from before into the newest $wp_query
* object. Fancy stuff.
*
* @param object $wp_query
* @return void
*/
public function restoreQueryState($wp_query)
{
if ($this->isSearch())
$wp_query->query_vars['post_type'] = $this->queryState['post_type'];
}
/**
* Groups posts by their ID.
*
* @global object $wpdb
* @param string $query
* @return string
*/
public function queryGroup($query)
{
global $wpdb;
if ($this->isSearch() && empty($group)) {
$group = " {$wpdb->posts}.ID";
}
return $group;
}
/**
* If the 's' GET parameter is present, append category taxonomy tables to
* the query.
*
* @global object $wp_query
* @global object $wpdb
* @param string $join
* @return string
*/
public function queryJoin($join)
{
global $wp_query, $wpdb;
$s = $this->getSearchTerms();
if ($this->isEnabled() && $this->isSearch() && !empty($s)) {
$join .= " INNER JOIN $wpdb->term_relationships AS trel ON ($wpdb->posts.ID = trel.object_id)
INNER JOIN $wpdb->term_taxonomy AS ttax ON (ttax.taxonomy = 'category' AND trel.term_taxonomy_id = ttax.term_taxonomy_id)
INNER JOIN $wpdb->terms AS tter ON (ttax.term_id = tter.term_id) ";
}
return $join;
}
/**
* If search terms have been defined, append where clauses for selecting
* categories by slug and/or description.
*
* @global object $wp_query
* @global object $wpdb
* @param string $where
* @return string
*/
public function queryWhere($where)
{
global $wp_query, $wpdb;
$s = $wp_query->query_vars['s'];
$searchTerms = $this->getSearchTerms();
if ($this->isEnabled() && !empty($searchTerms)) {
$search = '';
$n = $wp_query->query_vars['exact'] ? '' : '%';
$searchAnd = '';
$searchSlug = '';
foreach ($searchTerms as $term) {
$term = addslashes_gpc($term);
$searchSlug .= "{$searchAnd}(tter.slug LIKE '{$n}". sanitize_title_with_dashes($term) . "{$n}')";
$searchAnd = ' OR ';
}
if (!empty($searchSlug)) $search = " OR ({$searchSlug}) ";
if (!empty($this->queryState['post_type']) && 'any' != $this->queryState['post_type']) {
$typeWhere = "{$wpdb->posts}.post_type = '{$this->queryState['post_type']}'";
if (false === strpos($where, $typeWhere)) {
$search .= " AND ({$typeWhere}) ";
}
}
if (!empty($search)) {
// These additional where clauses need to be inserted in with the
// default search terms, and not appended to the whole query. The
// first case (with 3 ending parathesis) happens when there is
// only a single term in the search terms. The second is for
// multiple terms.
if (false !== strpos($where, ')))')) {
$where = str_replace(')))', "){$search}))", $where);
} else {
$where = substr($where, 0, -3) . "){$search})";
}
}
}
return $where;
}
/**
* Creates a list of search keywords from the 's' parameter.
*
* @global object $wp_query
* @global object $wpdb
* @return array
*/
private function getSearchTerms()
{
global $wp_query, $wpdb;
$search_terms = array();
if ($this->isSearch()) {
$s = $wp_query->query_vars['s'];
$s = stripslashes($s);
$sentence = $wp_query->query_vars['sentence'];
if ($sentence) {
$search_terms = array($s);
} else {
preg_match_all('/".*?("|$)|((?<=[\\s",+])|^)[^\\s",+]+/', $s, $matches);
$search_terms = array_map(create_function('$a', 'return trim($a, "\\"\'\\n\\r ");'), $matches[0]);
}
}
return $search_terms;
}
/**
* Is this a query or what?
*
* @global object $wp_query
* @return bool
*/
private function isSearch()
{
global $wp_query;
return !empty($wp_query->query_vars['s']);
}
/**
* Returns whether or not the class will do anything to the query.
*
* @return bool
*/
public static function isEnabled()
{
return self::$enabled;
}
/**
* Enable the class.
*
* @return void
*/
public static function enable($searchTerms = null)
{
self::$enabled = true;
self::$searchTerms = $searchTerms;
}
/**
* Disable the class.
*
* @return void
*/
public static function disable()
{
self::$enabled = false;
}
}
function myfeed_request($qv) {
if (isset($qv['feed']) && !isset($qv['post_type']))
$qv['post_type'] = array('articles', 'columns', 'infographics');
return $qv;
}
add_filter('request', 'myfeed_request');
function catch_that_image() {
global $post, $posts;
$first_img = '';
ob_start();
ob_end_clean();
$output = preg_match_all('//i', $post->post_content, $matches);
$first_img = $matches [1] [0];
if(empty($first_img)){ //Defines a default image
$first_img = "/images/default.jpg";
}
return $first_img;
}
// get the first image attached to the current post
function infographs_get_post_image($size = 'thumbnail') {
global $post;
$photos = get_children( array('post_parent' => $post->ID, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => 'ASC', 'orderby' => 'menu_order ID') );
if ($photos) {
$photo = array_shift($photos);
$default_attr = array('style' => "float:left;margin-right: 10px;");
return wp_get_attachment_image($photo->ID, $size, 0, $default_attr);
}
return false;
}
// Function to make keywords ready for insertion into ad code
function ad_targeting_keywords() {
global $post; // VERY important!
// Retrieve keyword meta data from the SEO Pack
$seokeywords = stripslashes(get_post_meta($post->ID, '_aioseop_keywords', true));
// Default keywords in case none are specified for the page
if (empty($seokeywords)) $seokeywords = "marketing, zeus, strategies, small business";
// Output the html code
$seokeywords = str_replace(", ", "+", $seokeywords);
$seokeywords = str_replace(",", "+", $seokeywords);
$seokeywords_output = str_replace(" ", "+", $seokeywords);
return $seokeywords_output;
}
Banner/Display | Marketing Zeus