Plugin Directory

Changeset 1917788


Ignore:
Timestamp:
07/31/2018 06:20:10 PM (7 years ago)
Author:
ammar.shahraki
Message:

fancy new feature: now you can filter sticky posts

Location:
blog-post-filter
Files:
2 added
5 edited

Legend:

Unmodified
Added
Removed
  • blog-post-filter/trunk/adminPage.php

    r1263008 r1917788  
    33    function BlogPostFilterAdminPage(){
    44        add_action('admin_init', array(&$this, 'registerOptionSetting'));
    5        
    6         add_posts_page ( 
    7             __('post filtering', 'blog-post-filter'), //string $page_title, 
    8             __('post filtering', 'blog-post-filter'), //string $menu_title, 
    9             'manage_options',           //string $capability, 
    10             'blog-post-filter-setting', //string $menu_slug, 
    11             array(&$this, 'setting') //callback $function = '' 
     5
     6        add_posts_page (
     7            __('post filtering', 'blog-post-filter'), //string $page_title,
     8            __('post filtering', 'blog-post-filter'), //string $menu_title,
     9            'manage_options',           //string $capability,
     10            'blog-post-filter-setting', //string $menu_slug,
     11            array(&$this, 'setting') //callback $function = ''
    1212            );
    1313    }
    14    
     14
    1515    private $optionValues;
     16
    1617    function showCategories($parentid = ''){
    1718        $categories = get_categories(array('parent' => $parentid, 'hide_empty' => 0));
    1819        if(count($categories)<1) return;
    19        
     20
    2021        echo '<ol>';
    2122            foreach($categories as $category){
    2223                echo '<li>';
    23                     echo '<input type="checkbox" name="blogPostFilterCategories['.$category->cat_ID.']" value="1" '.($this->optionValues[$category->cat_ID]=='0'? '': 'checked').' >';
    24                     echo $category->name;
    25                     echo '('.$category->category_count.')';
     24                    echo '<input type="checkbox" name="blogPostFilterCategories['.$category->cat_ID.']" id="blogPostFilterCategories_'.$category->cat_ID.'" value="1" '.($this->optionValues[$category->cat_ID]=='0'? '': 'checked').' >';
     25                    echo '<label for="blogPostFilterCategories_'.$category->cat_ID.'">' . $category->name;
     26                    echo '('.$category->category_count.')' . '</label>';
    2627                    $this->showCategories($category->cat_ID);
    2728                echo '</li>';
     
    2930        echo '</ol>';
    3031    }
    31    
     32
     33    function showFilterStickyPost() {
     34        $filterSticky = get_option('blogPostFilterStickyPosts');
     35        $checkedYes = ($filterSticky == 1)? 'checked': '';
     36        $checkedNo  = ($filterSticky == 0)? 'checked': '';
     37        echo '<p>';
     38            echo '<span>'.__('Would you like to filter sticky posts', 'blog-post-filter').'?</span>';
     39            echo '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
     40            echo '<input type="radio" name="blogPostFilterStickyPosts" value="1" id="bpfsp_yes" ' .$checkedYes. ' />';
     41            echo '<label for="bpfsp_yes">' .__('Yes'). '</label>';
     42            echo '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
     43            echo '<input type="radio" name="blogPostFilterStickyPosts" value="0" id="bpfsp_no"  ' .$checkedNo.  ' />';
     44            echo '<label for="bpfsp_no">' .__('No').' ('. __('Default').') '. '</label>';
     45        echo '</p>';
     46    }
     47
    3248    function setting(){
    3349        echo '<div class="wrap">';
    34             echo '<h2>'.__('Please select the categories that you would like show their posts on the front page', 'blog-post-filter').'.</h2>';
     50        echo '<h1>'.__('Post Filtering', 'blog-post-filter').'</h1>';
     51        echo '<form method="post" action="options.php">';
     52            settings_fields('blog-post-filter-option-group');
     53            //do_settings_section('blog-post-filter-option-group');
     54
     55            echo '<h2>'.__('Sticky Post Filtering', 'blog-post-filter').'</h2>';
     56            echo '<p>'.__('By default, sticky posts will not be filtered. Select "Yes" below, to filter them', 'blog-post-filter').'.</p>';
     57            $this->showFilterStickyPost();
     58
     59            echo '<h2>'.__('Select Categories', 'blog-post-filter').'</h2>';
     60            echo '<p>'.__('Please select the categories that you would like show their posts on the front page', 'blog-post-filter').'.</p>';
    3561            echo '<p>'.__('Only posts that are at least in one of selected categories will be shown on the front page', 'blog-post-filter').'.</p>';
    36             echo '<form method="post" action="options.php">';
    37                 settings_fields('blog-post-filter-option-group');
    38                 //do_settings_section('blog-post-filter-option-group');
    39                
     62
    4063                $this->optionValues = get_option('blogPostFilterCategories');
    41                
     64
    4265                $this->showCategories(0);
    43                
     66
    4467                submit_button();
    4568            echo '</form>';
    4669        echo '</div>';
    4770    }
    48    
     71
    4972    function registerOptionSetting(){
    5073        register_setting(
    51             'blog-post-filter-option-group', 
     74            'blog-post-filter-option-group',
    5275            'blogPostFilterCategories',
    53             array(&$this, 'validateOption')
     76            array(
     77                'sanitize_callback'=>array(&$this, 'validateOption') )
     78            );
     79        register_setting(
     80            'blog-post-filter-option-group',
     81            'blogPostFilterStickyPosts',
     82            array('default'=> '0')
    5483            );
    5584    }
    56    
     85
    5786    function validateOption($values){
    5887        $input = array();
     
    6291        return $input;
    6392    }
    64    
     93
    6594}
  • blog-post-filter/trunk/blog-post-filter.php

    r1263008 r1917788  
    44 * Plugin URI: http://www.sloth.ir/
    55 * Description: Blog Post Filter filters frontpage posts by their categories.
    6  * Version: 1.0.0
     6 * Version: 1.1.0
    77 * Author: ammar.shahraki
    88 * Author URI: http://www.sloth.ir/ammar-shahraki
     
    1515    public function __construct(){
    1616        add_action('plugins_loaded', array(&$this, 'loadTextDomain') );
    17         add_action('admin_menu',    array(&$this, 'settingPage'));
     17        add_action('admin_menu',        array(&$this, 'settingPage'));
    1818        add_action('pre_get_posts',  array(&$this, 'filterCategories'));
    1919    }
    20    
     20
     21    function getDirectPosts($categoryList){
     22        $directPostIds = array();
     23        foreach ($categoryList as $category) {
     24            $children = get_term_children($category, 'category');
     25            $chilePostIDs = array();
     26            if(count($children)>0)
     27                $chilePostIDs = get_posts(array(
     28                    'fields'          => 'ids', // Only get post IDs
     29                    'category'        => implode(',', $children),
     30                    'posts_per_page'  => -1,
     31                    'numberposts'       => -1
     32                ));
     33            $allPostIDs = get_posts(array(
     34                'fields'          => 'ids', // Only get post IDs
     35                'category'        => $category,
     36                'posts_per_page'  => -1,
     37                'numberposts'       => -1
     38            ));
     39
     40            $directPostIds=array_merge($directPostIds, array_diff($allPostIDs, $chilePostIDs));
     41        }
     42        return $directPostIds;
     43    }
     44
    2145    function filterCategories($query) {
    2246        if ($query->is_main_query() && is_home()) {
    23            
     47
     48            $filterSticky = get_option('blogPostFilterStickyPosts');
     49            $allowed = get_option('blogPostFilterCategories');
     50
    2451            $categoryList = array();
    25             $allowed = get_option('blogPostFilterCategories');
     52            $hiddenCategories = array();
     53
    2654            foreach($allowed as $id=>$status)
    27                 if($status==1){
    28                     $categoryList[] = $id;
    29                 }
    30             $query->set('cat', implode(',', $categoryList));
     55                if($status == 1)
     56                    $visibleCategories[] = $id;
     57                else
     58                    $hiddenCategories[] = $id;
     59
     60            if ($filterSticky == 0) {
     61                $query->set('category__in', $visibleCategories);
     62                // //$query->set('cat', implode(',', $visibleCategories));
     63                // //$query->set('ignore_sticky_posts', 'true');
     64            } else if(count($hiddenCategories)>0) {
     65                // $visiblePostIDs = get_posts(array(
     66                //  'fields'          => 'ids', // Only get post IDs
     67                //  'category'        => implode(',', $visibleCategories),
     68                //  'posts_per_page'  => -1,
     69                //  'numberposts'       => -1,
     70                //  'include_children' => false
     71                // ));
     72                //
     73                // $hiddenPostIDs = get_posts(array(
     74                //  'fields'          => 'ids', // Only get post IDs
     75                //  'category'        => implode(',', $hiddenCategories),
     76                //  'posts_per_page'  => -1,
     77                //  'numberposts'       => -1
     78                // ));
     79                //
     80                // $postIDs = array_diff($hiddenPostIDs,$visiblePostIDs);
     81
     82                $postIDs = $this->getDirectPosts($hiddenCategories);
     83
     84                $query->set('post__not_in', $postIDs);
     85            }
    3186        }
    3287    }
    33    
     88
    3489    function settingPage(){
    3590        //load_textdomain('blog-post-filter', plugin_dir_path( __FILE__ ) . '/languages/fa_IR.mo');
    3691        new BlogPostFilterAdminPage();
    3792    }
    38    
     93
    3994    function loadTextDomain(){
    4095        //load_plugin_textdomain('blog-post-filter', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
    41         load_plugin_textdomain('blog-post-filter', false, basename( dirname( __FILE__ ) ) . '/languages' ); 
     96        load_plugin_textdomain('blog-post-filter', false, basename( dirname( __FILE__ ) ) . '/languages' );
    4297    }
    4398}
  • blog-post-filter/trunk/languages/blog-post-filter-fa_IR.po

    r1263008 r1917788  
    44# Ammar Shahraki Ebrahimi <[email protected]>, 2015.
    55#
    6 #, fuzzy
    76msgid ""
    87msgstr ""
    98"Project-Id-Version: blog-post-filter\n"
    109"POT-Creation-Date: 2015-08-10 15:20+0430\n"
    11 "PO-Revision-Date: 2015-08-10 15:27+0430\n"
     10"PO-Revision-Date: 2018-07-31 17:22+0000\n"
    1211"Last-Translator: Ammar Shahraki Ebrahimi\n"
    1312"Language-Team: \n"
     
    1514"Content-Type: text/plain; charset=UTF-8\n"
    1615"Content-Transfer-Encoding: 8bit\n"
    17 "X-Generator: Poedit 1.8.4\n"
     16"X-Generator: Poedit 1.8.7.1\n"
    1817"X-Poedit-Basepath: .\n"
    1918"Plural-Forms: nplurals=1; plural=0;\n"
    2019"Language: fa_IR\n"
    2120
    22 ## ............................................................................
     21# # ............................................................................
     22# @ blog-post-filter
     23msgid "Blog Post Filter"
     24msgstr "غربالگری نوشته‌های بلاگ"
    2325
    24 #@ blog-post-filter
    25 msgid "Blog Post Filter"
    26 msgstr "غربالگری نوشته های بلاگ"
     26# @ blog-post-filter
     27msgid "Blog Post Filter filters frontpage posts by their categories."
     28msgstr "نوشته‌های صفحه نخست را بر اساس دسته آن‌ها غربال می‌کند."
    2729
    28 #@ blog-post-filter
    29 msgid "Blog Post Filter filters frontpage posts by their categories."
    30 msgstr "نوشته های صفحه نخست را بر اساس دسته آنها غربال می کند."
    31 
    32 #@ blog-post-filter
     30# @ blog-post-filter
    3331msgid "ammar.shahraki"
    3432msgstr "عمار شهرکی ابراهیمی"
     
    3634#: adminPage.php:8
    3735msgid "post filtering"
    38 msgstr "غربالگری نوشته ها"
     36msgstr "غربالگری نوشتهها"
    3937
    40 #: adminPage.php: 35
     38#: adminPage.php:50
     39msgid "Post Filtering"
     40msgstr "غربالگری نوشته‌ها"
     41
     42#: adminPage.php:55
     43msgid "Sticky Post Filtering"
     44msgstr "غربالگری نوشته‌های چسبنده"
     45
     46#: adminPage.php:56
     47msgid "By default, sticky posts will not be filtered. Select \"Yes\" below, to filter them"
     48msgstr "به طور پیش‌فرض، نوشته‌های چسبنده غربال نمی‌شوند. برای غربالگری آن‌ها گزینه «بلی» را انتخاب کنید"
     49
     50#: adminPage.php:0
     51msgid "Select Categories"
     52msgstr "دسته‌ها را انتخاب کنید"
     53
     54#: adminPage.php:38
     55msgid "Would you like to filter sticky posts"
     56msgstr "آیا می‌خواهید نوشته‌های چسبنده را غربال کنید"
     57
     58#: adminPage.php:60
    4159msgid "Please select the categories that you would like show their posts on the front page"
    42 msgstr "دسته هایی که می خواهید نوشته های آنها در صفحه نخست نمایش داده شود را انتخاب کنید"
     60msgstr "دسته‌هایی که می‌خواهید نوشته های آنها در صفحه نخست نمایش داده شود را انتخاب کنید"
    4361
    44 #: adminPage.php: 36
     62#: adminPage.php:61
    4563msgid "Only posts that are at least in one of selected categories will be shown on the front page"
    46 msgstr "فقط نوشته هایی که دستکم در یکی از دسته های انتخاب شده باشند در صفحه نخست نمایش داده خواهند شد"
     64msgstr "فقط نوشته‌هایی که دستکم در یکی از دسته‌های انتخاب شده باشند در صفحه نخست نمایش داده خواهند شد"
  • blog-post-filter/trunk/readme.txt

    r1815917 r1917788  
    44Tags: filter, categories, category, frontpage, post
    55Requires at least: 4.2.4
    6 Tested up to: 4.9.2
    7 Stable tag: trunk
     6Tested up to: 4.9.7
     7Requires PHP: 5.2.4
     8Stable tag: 1.0.1
    89License: GPLv2 or later
    910License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    4041== Screenshots ==
    4142
    42 1. Preview of the Blog Post Filter's admin page.
     431. Preview of the Blog Post Filter's admin page (v1.0.1).
     442. Preview of the Blog Post Filter's admin page (v1.1.0).
     453. Persian translation of the plugin (v1.1.0).
    4346
    4447== Changelog ==
     48
     49= 1.1.0 =
     50* Added an option to filter sticky posts.
     51
     52= 1.0.1 =
     53* Minor bug fix.
    4554
    4655= 1.0.0 =
Note: See TracChangeset for help on using the changeset viewer.