예제 #1
0
function wpt_filter_comment_info($comment)
{
    $filters = get_option('wpt_filters');
    if (is_array($filters)) {
        foreach ($filters as $filter => $rule) {
            $comparison = $rule['type'];
            $field = $rule['field'];
            switch ($field) {
                case 'postTitle':
                    $value = get_the_title($comment->comment_post_ID);
                    break;
                case 'postLink':
                    $value = get_the_permalink($comment->comment_post_ID);
                    break;
                case 'shortUrl':
                    $short = wpt_short_url($comment->comment_post_ID);
                    break;
                case 'postStatus':
                    $value = 'publish';
                    break;
                    // comments are only on published posts.
                // comments are only on published posts.
                case 'postType':
                    $value = get_post_type($comment->comment_post_ID);
                    break;
                case 'id':
                    $value = $comment->comment_post_ID;
                    break;
                case 'authId':
                    $value = $comment->user_id;
                    break;
                case 'postExcerpt':
                    wpt_get_excerpt_by_id($comment->comment_post_ID);
                    break;
            }
            switch ($comparison) {
                case 'equals':
                    if ($value == $rule['value']) {
                        return true;
                    }
                    break;
                case 'notin':
                    if (strpos($value, $rule['value']) === false) {
                        return true;
                    }
                    break;
                case 'in':
                    if (strpos($value, $rule['value']) !== false) {
                        return true;
                    }
                    break;
                case 'notequals':
                    if ($value != $rule['value']) {
                        return true;
                    }
                    break;
                default:
                    return true;
            }
        }
        return false;
    }
    return false;
}
예제 #2
0
function jd_post_info($post_ID)
{
    $encoding = get_option('blog_charset');
    if ($encoding == '') {
        $encoding = 'UTF-8';
    }
    $post = get_post($post_ID);
    $category_ids = false;
    $values = array();
    $values['id'] = $post_ID;
    // get post author
    $values['postinfo'] = $post;
    $values['authId'] = $post->post_author;
    $postdate = $post->post_date;
    $altformat = "Y-m-d H:i:s";
    $dateformat = get_option('jd_date_format') == '' ? get_option('date_format') : get_option('jd_date_format');
    $thisdate = mysql2date($dateformat, $postdate);
    $altdate = mysql2date($altformat, $postdate);
    $values['_postDate'] = $altdate;
    $values['postDate'] = $thisdate;
    $moddate = $post->post_modified;
    $values['_postModified'] = mysql2date($altformat, $moddate);
    $values['postModified'] = mysql2date($dateformat, $moddate);
    // get first category
    $category = $cat_desc = null;
    $categories = get_the_category($post_ID);
    if (is_array($categories)) {
        if (count($categories) > 0) {
            $category = $categories[0]->cat_name;
            $cat_desc = $categories[0]->description;
        }
        foreach ($categories as $cat) {
            $category_ids[] = $cat->term_id;
        }
    } else {
        $category = '';
        $cat_desc = '';
        $category_ids = array();
    }
    $values['categoryIds'] = $category_ids;
    $values['category'] = html_entity_decode($category, ENT_COMPAT, $encoding);
    $values['cat_desc'] = html_entity_decode($cat_desc, ENT_COMPAT, $encoding);
    $excerpt_length = get_option('jd_post_excerpt');
    $post_excerpt = trim($post->post_excerpt) == "" ? @mb_substr(strip_tags(strip_shortcodes($post->post_content)), 0, $excerpt_length) : @mb_substr(strip_tags(strip_shortcodes($post->post_excerpt)), 0, $excerpt_length);
    $values['postExcerpt'] = html_entity_decode($post_excerpt, ENT_COMPAT, $encoding);
    $thisposttitle = stripcslashes(strip_tags($post->post_title));
    if ($thisposttitle == "" && isset($_POST['title'])) {
        $thisposttitle = stripcslashes(strip_tags($_POST['title']));
    }
    $values['postTitle'] = html_entity_decode($thisposttitle, ENT_COMPAT, $encoding);
    $values['postLink'] = wpt_link($post_ID);
    $values['blogTitle'] = get_bloginfo('name');
    $values['shortUrl'] = wpt_short_url($post_ID);
    $values['postStatus'] = $post->post_status;
    $values['postType'] = $post->post_type;
    $values = apply_filters('wpt_post_info', $values, $post_ID);
    return $values;
}
예제 #3
0
/**
 * Builds array of post info for use in Tweet functions.
 * 
 * @param integer $post_ID Post ID.
 *
 * @return array Post data used in Tweet functions. 
 */
function wpt_post_info($post_ID)
{
    $encoding = get_option('blog_charset');
    if ($encoding == '') {
        $encoding = 'UTF-8';
    }
    $post = get_post($post_ID);
    $category_ids = false;
    $values = array();
    $values['id'] = $post_ID;
    // get post author
    $values['postinfo'] = $post;
    $values['postContent'] = $post->post_content;
    $values['authId'] = $post->post_author;
    $postdate = $post->post_date;
    $altformat = "Y-m-d H:i:s";
    $dateformat = get_option('jd_date_format') == '' ? get_option('date_format') : get_option('jd_date_format');
    $thisdate = mysql2date($dateformat, $postdate);
    $altdate = mysql2date($altformat, $postdate);
    $values['_postDate'] = $altdate;
    $values['postDate'] = $thisdate;
    $moddate = $post->post_modified;
    $values['_postModified'] = mysql2date($altformat, $moddate);
    $values['postModified'] = mysql2date($dateformat, $moddate);
    // get first category
    $category = $cat_desc = null;
    $categories = get_the_category($post_ID);
    $cats = $cat_descs = array();
    if (is_array($categories)) {
        if (count($categories) > 0) {
            $category = $categories[0]->cat_name;
            $cat_desc = $categories[0]->description;
        }
        foreach ($categories as $cat) {
            $category_ids[] = $cat->term_id;
            $cats[] = $cat->cat_name;
            $cat_descs[] = $cat->description;
        }
        $cat_names = implode(' ', apply_filters('wpt_twitter_category_names', $cats));
        $cat_descs = implode(' ', apply_filters('wpt_twitter_category_descs', $cat_descs));
    } else {
        $category = '';
        $cat_desc = '';
        $category_ids = array();
    }
    $values['cats'] = $cat_names;
    $values['cat_descs'] = $cat_descs;
    $values['categoryIds'] = $category_ids;
    $values['category'] = html_entity_decode($category, ENT_COMPAT, $encoding);
    $values['cat_desc'] = html_entity_decode($cat_desc, ENT_COMPAT, $encoding);
    $excerpt_length = get_option('jd_post_excerpt');
    $post_excerpt = trim($post->post_excerpt) == "" ? @mb_substr(strip_tags(strip_shortcodes($post->post_content)), 0, $excerpt_length) : @mb_substr(strip_tags(strip_shortcodes($post->post_excerpt)), 0, $excerpt_length);
    $values['postExcerpt'] = html_entity_decode($post_excerpt, ENT_COMPAT, $encoding);
    $thisposttitle = $post->post_title;
    if ($thisposttitle == "" && isset($_POST['title'])) {
        $thisposttitle = $_POST['title'];
    }
    $thisposttitle = strip_tags(apply_filters('the_title', stripcslashes($thisposttitle)));
    // These are common sequences that may not be fixed by html_entity_decode due to double encoding
    $search = array(''', ''', '"', '"', '&', '&');
    $replace = array("'", "'", '"', '"', '&', '&');
    $thisposttitle = str_replace($search, $replace, $thisposttitle);
    $values['postTitle'] = html_entity_decode($thisposttitle, ENT_QUOTES, $encoding);
    $values['postLink'] = wpt_link($post_ID);
    $values['blogTitle'] = get_bloginfo('name');
    $values['shortUrl'] = wpt_short_url($post_ID);
    $values['postStatus'] = $post->post_status;
    $values['postType'] = $post->post_type;
    /**
     * Filters post array to insert custom data that can be used in Tweet process.
     * 
     * @param array $values
     * @param integer $post_ID
     * @return array $values
     */
    $values = apply_filters('wpt_post_info', $values, $post_ID);
    return $values;
}