Plugin Directory

Changeset 1124222


Ignore:
Timestamp:
03/31/2015 07:50:43 AM (11 years ago)
Author:
caotu
Message:

Update set restrict multi category and add limit posts per day with user connect from id system

Location:
sudo-oauth/trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • sudo-oauth/trunk/SudoOauth.php

    r1122972 r1124222  
    132132   }else {
    133133      echo $info['message'];
     134      echo '<br />';
    134135      die('Lỗi kết nối !');
    135136   }
  • sudo-oauth/trunk/index.php

    r1122972 r1124222  
    55Description: Free Plugin supported connect to system id.sudo.vn - a system manager account. If you want build a system manager account for SEO, Manager staff please contact me.
    66Author: caotu
    7 Version: 1.0.4
     7Version: 1.0.5
    88Author URI: http://sudo.vn
    99*/
     
    3535        register_setting( 'sudooauth-settings-group', 'sudooauth_option_pwd' );
    3636        register_setting( 'sudooauth-settings-group', 'sudooauth_option_host' );
    37         register_setting( 'sudooauth-settings-group', 'sudooauth_option_cat' );
     37        register_setting( 'sudooauth-settings-group', 'sudooauth_option_multicat' );
     38        register_setting( 'sudooauth-settings-group', 'sudooauth_option_limitpost' );
    3839}
    3940 
     
    6061
    6162/* Restrict cat */
    62 function sudo_restrict_save_data( $user_id ) {
    63     if ( ! current_user_can( 'add_users' ) )
    64         return false;
    65     update_user_meta( $user_id, '_sudo_access', get_option('sudooauth_option_cat') );
    66 }
    67 
    68 // check author có bị hạn chế ko ?
    69 function sudo_is_restrict() {
    70     if ( get_user_meta(get_current_user_id(), '_sudo_access', true) > 0 )
    71             return true;
    72     else
    73             return false;
    74 }
    75 /* tự động lưu danh mục hạn chế cho post của author */
    76 add_action( 'save_post', 'sudo_save_restrict_post' );
    77 function sudo_save_restrict_post( $post_id ) {
    78     if ( ! wp_is_post_revision( $post_id ) && sudo_is_restrict() ){
    79     remove_action('save_post', 'sudo_save_restrict_post');
    80         wp_set_post_categories( $post_id, get_user_meta( get_current_user_id() , '_sudo_access', true) );
    81     add_action('save_post', 'sudo_save_restrict_post');
    82     }
    83 }
    84 /* cảnh báo */
    85 add_action( 'edit_form_after_title', 'sudo_restrict_warning' );
    86 function sudo_restrict_warning( $post_data = false ) {
    87     if (sudo_is_restrict()) {
    88         $c = get_user_meta( get_current_user_id() , '_sudo_access', true);
    89         $data = get_category($c);
    90         echo 'Bạn chỉ được phép đăng bài trong danh mục: <strong>'. $data->name .'</strong><br /><br />';
    91     }
    92 }
    93 /* Xóa box chọn cate */
    94 function sudo_restrict_remove_meta_boxes() {
    95     if (sudo_is_restrict() )
    96         remove_meta_box('categorydiv', 'post', 'normal');
    97 }
    98 add_action( 'admin_menu', 'sudo_restrict_remove_meta_boxes' );
     63add_filter( 'list_terms_exclusions', 'sudo_exclusions_terms' );
     64function sudo_exclusions_terms() {
     65   $excluded = '';
     66   $current_user = wp_get_current_user();
     67   if(strpos($current_user->user_email,'@sudo.vn')) {
     68      $multicat_settings = get_option('sudooauth_option_multicat');
     69      if ( $multicat_settings != false ) {
     70         $str_cat_list = '';
     71         foreach($multicat_settings as $value) {
     72            $str_cat_list .= $value.',';
     73         }
     74         $str_cat_list = rtrim($str_cat_list,',');
     75         $excluded = " AND ( t.term_id IN ( $str_cat_list ) OR tt.taxonomy NOT IN ( 'category' ) )";
     76      }
     77   }
     78   return $excluded;
     79}
    9980/* End Restrict cat */
    10081
    101 function sudooauth_settings_page() {
     82/* One post per day */
     83add_action( 'admin_init', 'sudo_post_per_day_limit' );
     84function sudo_post_per_day_limit() {
     85   $current_user = wp_get_current_user();
     86   if(strpos($current_user->user_email,'@sudo.vn')) {
     87      global $wpdb;
     88      $tz = new DateTimeZone('Asia/Bangkok');
     89      $time_current_sv = new DateTime();
     90      $time_current_sv_str = $time_current_sv->format('Y-m-d H:i:s');
     91      $time_current_sv_int = $time_current_sv->getTimestamp();
     92     
     93      $time_current_sv->setTimeZone($tz);
     94      $time_current_tz_str = $time_current_sv->format('Y-m-d H:i:s');
     95      $time_current_tz = new DateTime($time_current_tz_str);
     96      $time_current_tz_int = $time_current_tz->getTimestamp();
     97     
     98      $time_start_tz_str = $time_current_sv->format('Y-m-d 00:00:01');
     99      $time_start_tz = new DateTime($time_start_tz_str);
     100      $time_start_tz_int = $time_start_tz->getTimestamp();
     101     
     102      $time_start_sv_int = $time_current_sv_int - $time_current_tz_int + $time_start_tz_int;
     103      $time_start_sv_str = date('Y-m-d H:i:s',$time_start_sv_int);
     104      $time_start_sv = new DateTime($time_start_sv_str);
     105     
     106      $count_post_today = $wpdb->get_var("SELECT COUNT(ID)
     107                                          FROM $wpdb->posts
     108                                          WHERE post_status = 'publish'
     109                                          AND post_author = $current_user->ID
     110                                          AND post_type NOT IN('attachment','revision')
     111                                          AND post_date_gmt >= '$time_start_sv_str'");
     112                                         
     113      if($count_post_today >= get_option('sudooauth_option_limitpost',1)) {
     114         global $pagenow;
     115         /* Check current admin page. */
     116         if($pagenow == 'post-new.php'){
     117            echo '<meta http-equiv="Content-Type" content="text/html"; charset="utf-8">';
     118            echo "<center>";
     119            echo '<br /><br />Giới hạn '.get_option('sudooauth_option_limitpost',1).' bài 1 ngày.<br /><br /> Hôm nay bạn đã đăng đủ bài trên trang này rồi.<br /><br /> Vui lòng quay lại vào ngày mai, xin cám ơn!';
     120            echo "</center>";
     121            exit();
     122         }
     123      }
     124   }
     125}
     126/* End One post per day */
     127
     128function sudooauth_settings_page() {   
    102129?>
    103130<div class="wrap">
     
    125152        </tr>
    126153        <tr valign="top">
    127          <th scope="row">Hạn chế danh mục post</th>
     154         <th scope="row">Tài khoản kết nối được đăng bao nhiêu bài một ngày</th>
     155         <td><input type="text" name="sudooauth_option_limitpost" value="<?php echo get_option('sudooauth_option_limitpost') != '' ? get_option('sudooauth_option_limitpost') : '1'; ?>" /></td>
     156        </tr>
     157        <tr valign="top">
     158         <th scope="row">Chọn danh mục tài khoản kết nối được phép post bài</th>
    128159         <td>
    129             <?php wp_dropdown_categories(array(
    130                                                 'show_option_all'    => '',
    131                                                 'show_option_none'   => '== Không hạn chế ==',
    132                                                 'orderby'            => 'ID',
    133                                                 'order'              => 'ASC',
    134                                                 'show_count'         => 0,
    135                                                 'hide_empty'         => 0,
    136                                                 'child_of'           => 0,
    137                                                 'exclude'            => '',
    138                                                 'echo'               => 1,
    139                                                 'selected'           => get_option('sudooauth_option_cat'),
    140                                                 'hierarchical'       => 0,
    141                                                 'name'               => 'sudooauth_option_cat',
    142                                                 'id'                 => '',
    143                                                 'class'              => 'postform',
    144                                                 'depth'              => 0,
    145                                                 'tab_index'          => 0,
    146                                                 'taxonomy'           => 'category',
    147                                                 'hide_if_empty'      => false,
    148                                                 'walker'             => ''
    149                                             )); ?>
     160         <?php
     161         $walker = new Sudo_Walker_Category_Checklist();
     162         $settings = get_option('sudooauth_option_multicat');
     163         if ( isset( $settings) && is_array( $settings) )
     164                $selected = $settings;
     165            else
     166                $selected = array();
     167         ?>
     168            <div id="side-sortables" class="metabox-holder" style="float:left; padding:5px;">
     169                <div class="postbox">
     170                    <h3 class="hndle"><span>Giới hạn đa danh mục</span></h3>
     171   
     172                <div class="inside" style="padding:0 10px;">
     173                        <div class="taxonomydiv">
     174                            <div id="id-all" class="tabs-panel tabs-panel-active">
     175                                <ul class="categorychecklist form-no-clear">
     176                                <?php
     177                                    wp_list_categories(
     178                                        array(
     179                                        'selected_cats'  => $selected,
     180                                        'options_name'   => 'sudooauth_option_multicat',
     181                                        'hide_empty'     => 0,
     182                                        'title_li'       => '',
     183                                        'walker'         => $walker
     184                                        )
     185                                    );
     186                                ?>
     187                         </ul>
     188                            </div>
     189                        </div>
     190                    </div>
     191                </div>
     192            </div>
    150193         </td>
    151194        </tr>
     
    154197</form>
    155198</div>
    156 <?php } ?>
     199<?php
     200}
     201
     202
     203class Sudo_Walker_Category_Checklist extends Walker {
     204    var $tree_type = 'category';
     205    var $db_fields = array ('parent' => 'parent', 'id' => 'term_id'); //TODO: decouple this
     206
     207    function start_lvl( &$output, $depth = 0, $args = array() ) {
     208        $indent = str_repeat("\t", $depth);
     209        $output .= "$indent<ul class='children'>\n";
     210    }
     211
     212    function end_lvl( &$output, $depth = 0, $args = array() ) {
     213        $indent = str_repeat("\t", $depth);
     214        $output .= "$indent</ul>\n";
     215    }
     216
     217    function start_el( &$output, $category, $depth = 0, $args = array(), $current_object_id = 0 ) {
     218        extract($args);
     219
     220        if ( empty( $taxonomy ) )
     221            $taxonomy = 'category';
     222
     223        $output .= sprintf(
     224            '<li id="category-%1$d"><label class="selectit"><input value="%1$s" type="checkbox" name="sudooauth_option_multicat[]" %2$s /> %3$s</label>',
     225            $category->term_id,
     226            checked( in_array( $category->term_id, $selected_cats ), true, false ),
     227            esc_html( apply_filters( 'the_category', $category->name ) )
     228        );
     229    }
     230
     231    function end_el( &$output, $category, $depth = 0, $args= array() ) {
     232        $output .= "</li>\n";
     233    }
     234}
     235?>
  • sudo-oauth/trunk/readme.txt

    r1122972 r1124222  
    3131
    3232== Changelog ==
     33= 1.0.5 =
     34Update set restrict multi category and add limit posts per day with user connect from id system
     35
    3336= 1.0.4 =
    3437Fixed bug can't set restrict category
Note: See TracChangeset for help on using the changeset viewer.