Changeset 1124222
- Timestamp:
- 03/31/2015 07:50:43 AM (11 years ago)
- Location:
- sudo-oauth/trunk
- Files:
-
- 3 edited
-
SudoOauth.php (modified) (1 diff)
-
index.php (modified) (5 diffs)
-
readme.txt (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
sudo-oauth/trunk/SudoOauth.php
r1122972 r1124222 132 132 }else { 133 133 echo $info['message']; 134 echo '<br />'; 134 135 die('Lỗi kết nối !'); 135 136 } -
sudo-oauth/trunk/index.php
r1122972 r1124222 5 5 Description: 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. 6 6 Author: caotu 7 Version: 1.0. 47 Version: 1.0.5 8 8 Author URI: http://sudo.vn 9 9 */ … … 35 35 register_setting( 'sudooauth-settings-group', 'sudooauth_option_pwd' ); 36 36 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' ); 38 39 } 39 40 … … 60 61 61 62 /* 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' ); 63 add_filter( 'list_terms_exclusions', 'sudo_exclusions_terms' ); 64 function 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 } 99 80 /* End Restrict cat */ 100 81 101 function sudooauth_settings_page() { 82 /* One post per day */ 83 add_action( 'admin_init', 'sudo_post_per_day_limit' ); 84 function 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 128 function sudooauth_settings_page() { 102 129 ?> 103 130 <div class="wrap"> … … 125 152 </tr> 126 153 <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> 128 159 <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> 150 193 </td> 151 194 </tr> … … 154 197 </form> 155 198 </div> 156 <?php } ?> 199 <?php 200 } 201 202 203 class 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 31 31 32 32 == Changelog == 33 = 1.0.5 = 34 Update set restrict multi category and add limit posts per day with user connect from id system 35 33 36 = 1.0.4 = 34 37 Fixed bug can't set restrict category
Note: See TracChangeset
for help on using the changeset viewer.