functions.php 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649
  1. <?php
  2. $dname = 'Yusi';
  3. add_action( 'after_setup_theme', 'deel_setup' );
  4. include('admin/Yusi.php');
  5. include('widgets/index.php');
  6. function deel_setup(){
  7. //去除头部冗余代码
  8. remove_action( 'wp_head', 'feed_links_extra', 3 );
  9. remove_action( 'wp_head', 'rsd_link' );
  10. remove_action( 'wp_head', 'wlwmanifest_link' );
  11. remove_action( 'wp_head', 'index_rel_link' );
  12. remove_action( 'wp_head', 'start_post_rel_link', 10, 0 );
  13. remove_action( 'wp_head', 'wp_generator' );
  14. //
  15. add_theme_support( 'custom-background' );
  16. //隐藏admin Bar
  17. //add_filter('show_admin_bar','hide_admin_bar');
  18. //关键字
  19. add_action('wp_head','deel_keywords');
  20. //页面描述
  21. add_action('wp_head','deel_description');
  22. //阻止站内PingBack
  23. if( dopt('d_pingback_b') ){
  24. add_action('pre_ping','deel_noself_ping');
  25. }
  26. //评论回复邮件通知
  27. add_action('comment_post','comment_mail_notify');
  28. //自动勾选评论回复邮件通知,不勾选则注释掉
  29. // add_action('comment_form','deel_add_checkbox');
  30. //评论表情改造,如需更换表情,img/smilies/下替换
  31. add_filter('smilies_src','deel_smilies_src',1,10);
  32. //文章末尾增加版权
  33. add_filter('the_content','deel_copyright');
  34. //移除自动保存和修订版本
  35. if( dopt('d_autosave_b') ){
  36. add_action('wp_print_scripts','deel_disable_autosave' );
  37. remove_action('pre_post_update','wp_save_post_revision' );
  38. }
  39. //去除自带js
  40. wp_deregister_script( 'l10n' );
  41. //修改默认发信地址
  42. add_filter('wp_mail_from', 'deel_res_from_email');
  43. add_filter('wp_mail_from_name', 'deel_res_from_name');
  44. //缩略图设置
  45. add_theme_support('post-thumbnails');
  46. set_post_thumbnail_size(220, 150, true);
  47. add_editor_style('editor-style.css');
  48. //头像缓存
  49. if( dopt('d_avatar_b') ){
  50. add_filter('get_avatar','deel_avatar');
  51. }
  52. //定义菜单
  53. if (function_exists('register_nav_menus')){
  54. register_nav_menus( array(
  55. 'nav' => __('网站导航'),
  56. 'pagemenu' => __('页面导航')
  57. ));
  58. }
  59. }
  60. if (function_exists('register_sidebar')){
  61. register_sidebar(array(
  62. 'name' => '全站侧栏',
  63. 'id' => 'widget_sitesidebar',
  64. 'before_widget' => '<div class="widget %2$s">',
  65. 'after_widget' => '</div>',
  66. 'before_title' => '<div class="title"><h2>',
  67. 'after_title' => '</h2></div>'
  68. ));
  69. register_sidebar(array(
  70. 'name' => '首页侧栏',
  71. 'id' => 'widget_sidebar',
  72. 'before_widget' => '<div class="widget %2$s">',
  73. 'after_widget' => '</div>',
  74. 'before_title' => '<div class="title"><h2>',
  75. 'after_title' => '</h2></div>'
  76. ));
  77. register_sidebar(array(
  78. 'name' => '分类/标签/搜索页侧栏',
  79. 'id' => 'widget_othersidebar',
  80. 'before_widget' => '<div class="widget %2$s">',
  81. 'after_widget' => '</div>',
  82. 'before_title' => '<div class="title"><h2>',
  83. 'after_title' => '</h2></div>'
  84. ));
  85. register_sidebar(array(
  86. 'name' => '文章页侧栏',
  87. 'id' => 'widget_postsidebar',
  88. 'before_widget' => '<div class="widget %2$s">',
  89. 'after_widget' => '</div>',
  90. 'before_title' => '<div class="title"><h2>',
  91. 'after_title' => '</h2></div>'
  92. ));
  93. register_sidebar(array(
  94. 'name' => '页面侧栏',
  95. 'id' => 'widget_pagesidebar',
  96. 'before_widget' => '<div class="widget %2$s">',
  97. 'after_widget' => '</div>',
  98. 'before_title' => '<div class="title"><h2>',
  99. 'after_title' => '</h2></div>'
  100. ));
  101. }
  102. function deel_breadcrumbs(){
  103. if( !is_single() ) return false;
  104. $categorys = get_the_category();
  105. $category = $categorys[0];
  106. return '<a title="返回首页" href="'.get_bloginfo('url').'"><i class="fa fa-home"></i></a> <small>></small> '.get_category_parents($category->term_id, true, ' <small>></small> ').'<span class="muted">'.get_the_title().'</span>';
  107. }
  108. // 取消原有jQuery
  109. function footerScript() {
  110. if ( !is_admin() ) {
  111. wp_deregister_script( 'jquery' );
  112. wp_register_script( 'jquery','https://code.jquery.com/jquery-1.8.3.min.js', false,'1.0');
  113. wp_enqueue_script( 'jquery' );
  114. wp_register_script( 'default', get_template_directory_uri() . '/js/jquery.js', false, '1.0', dopt('d_jquerybom_b') ? true : false );
  115. wp_enqueue_script( 'default' );
  116. wp_register_style( 'style', get_template_directory_uri() . '/style.css',false,'1.0' );
  117. wp_enqueue_style( 'style' );
  118. }
  119. }
  120. add_action( 'wp_enqueue_scripts', 'footerScript' );
  121. if ( ! function_exists( 'deel_paging' ) ) :
  122. function deel_paging() {
  123. $p = 4;
  124. if ( is_singular() ) return;
  125. global $wp_query, $paged;
  126. $max_page = $wp_query->max_num_pages;
  127. if ( $max_page == 1 ) return;
  128. echo '<div class="pagination"><ul>';
  129. if ( empty( $paged ) ) $paged = 1;
  130. // echo '<span class="pages">Page: ' . $paged . ' of ' . $max_page . ' </span> ';
  131. echo '<li class="prev-page">'; previous_posts_link('上一页'); echo '</li>';
  132. if ( $paged > $p + 1 ) p_link( 1, '<li>第一页</li>' );
  133. if ( $paged > $p + 2 ) echo "<li><span>···</span></li>";
  134. for( $i = $paged - $p; $i <= $paged + $p; $i++ ) {
  135. if ( $i > 0 && $i <= $max_page ) $i == $paged ? print "<li class=\"active\"><span>{$i}</span></li>" : p_link( $i );
  136. }
  137. if ( $paged < $max_page - $p - 1 ) echo "<li><span> ... </span></li>";
  138. //if ( $paged < $max_page - $p ) p_link( $max_page, '&raquo;' );
  139. echo '<li class="next-page">'; next_posts_link('下一页'); echo '</li>';
  140. // echo '<li><span>共 '.$max_page.' 页</span></li>';
  141. echo '</ul></div>';
  142. }
  143. function p_link( $i, $title = '' ) {
  144. if ( $title == '' ) $title = "第 {$i} 页";
  145. echo "<li><a href='", esc_html( get_pagenum_link( $i ) ), "'>{$i}</a></li>";
  146. }
  147. endif;
  148. function deel_strimwidth($str ,$start , $width ,$trimmarker ){
  149. $output = preg_replace('/^(?:[\x00-\x7F]|[\xC0-\xFF][\x80-\xBF]+){0,'.$start.'}((?:[\x00-\x7F]|[\xC0-\xFF][\x80-\xBF]+){0,'.$width.'}).*/s','\1',$str);
  150. return $output.$trimmarker;
  151. }
  152. function dopt($e){
  153. return stripslashes(get_option($e));
  154. }
  155. if ( ! function_exists( 'deel_views' ) ) :
  156. function deel_record_visitors(){
  157. if (is_singular())
  158. {
  159. global $post;
  160. $post_ID = $post->ID;
  161. if($post_ID)
  162. {
  163. $post_views = (int)get_post_meta($post_ID, 'views', true);
  164. if(!update_post_meta($post_ID, 'views', ($post_views+1)))
  165. {
  166. add_post_meta($post_ID, 'views', 1, true);
  167. }
  168. }
  169. }
  170. }
  171. add_action('wp_head', 'deel_record_visitors');
  172. function deel_views($after=''){
  173. global $post;
  174. $post_ID = $post->ID;
  175. $views = (int)get_post_meta($post_ID, 'views', true);
  176. echo $views, $after;
  177. }
  178. endif;
  179. //baidu分享
  180. $dHasShare = false;
  181. function deel_share(){
  182. if( !dopt('d_bdshare_b') ) return false;
  183. echo '<span class="action action-share bdsharebuttonbox"><i class="fa fa-share-alt"></i>分享 (<span class="bds_count" data-cmd="count" title="累计分享0次">0</span>)<div class="action-popover"><div class="popover top in"><div class="arrow"></div><div class="popover-content"><a href="#" class="sinaweibo fa fa-weibo" data-cmd="tsina" title="分享到新浪微博"></a><a href="#" class="bds_qzone fa fa-star" data-cmd="qzone" title="分享到QQ空间"></a><a href="#" class="tencentweibo fa fa-tencent-weibo" data-cmd="tqq" title="分享到腾讯微博"></a><a href="#" class="qq fa fa-qq" data-cmd="sqq" title="分享到QQ好友"></a><a href="#" class="bds_renren fa fa-renren" data-cmd="renren" title="分享到人人网"></a><a href="#" class="bds_weixin fa fa-weixin" data-cmd="weixin" title="分享到微信"></a><a href="#" class="bds_more fa fa-ellipsis-h" data-cmd="more"></a></div></div></div></span>';
  184. global $dHasShare;
  185. $dHasShare = true;
  186. }
  187. function deel_avatar_default(){
  188. return get_bloginfo('template_directory').'/img/default.png';
  189. }
  190. //评论头像缓存
  191. function deel_avatar($avatar) {
  192. $tmp = strpos($avatar, 'http');
  193. $g = substr($avatar, $tmp, strpos($avatar, "'", $tmp) - $tmp);
  194. $tmp = strpos($g, 'avatar/') + 7;
  195. $f = substr($g, $tmp, strpos($g, "?", $tmp) - $tmp);
  196. $w = get_bloginfo('wpurl');
  197. $e = ABSPATH .'avatar/'. $f .'.png';
  198. $t = dopt('d_avatarDate')*24*60*60;
  199. if ( !is_file($e) || (time() - filemtime($e)) > $t )
  200. copy(htmlspecialchars_decode($g), $e);
  201. else
  202. $avatar = strtr($avatar, array($g => $w.'/avatar/'.$f.'.png'));
  203. if ( filesize($e) < 500 )
  204. copy(get_bloginfo('template_directory').'/img/default.png', $e);
  205. return $avatar;
  206. }
  207. //关键字
  208. function deel_keywords() {
  209. global $s, $post;
  210. $keywords = '';
  211. if ( is_single() ) {
  212. if ( get_the_tags( $post->ID ) ) {
  213. foreach ( get_the_tags( $post->ID ) as $tag ) $keywords .= $tag->name . ', ';
  214. }
  215. foreach ( get_the_category( $post->ID ) as $category ) $keywords .= $category->cat_name . ', ';
  216. $keywords = substr_replace( $keywords , '' , -2);
  217. } elseif ( is_home () ) { $keywords = dopt('d_keywords');
  218. } elseif ( is_tag() ) { $keywords = single_tag_title('', false);
  219. } elseif ( is_category() ) { $keywords = single_cat_title('', false);
  220. } elseif ( is_search() ) { $keywords = esc_html( $s, 1 );
  221. } else { $keywords = trim( wp_title('', false) );
  222. }
  223. if ( $keywords ) {
  224. echo "<meta name=\"keywords\" content=\"$keywords\">\n";
  225. }
  226. }
  227. //网站描述
  228. function deel_description() {
  229. global $s, $post;
  230. $description = '';
  231. $blog_name = get_bloginfo('name');
  232. if ( is_singular() ) {
  233. if( !empty( $post->post_excerpt ) ) {
  234. $text = $post->post_excerpt;
  235. } else {
  236. $text = $post->post_content;
  237. }
  238. $description = trim( str_replace( array( "\r\n", "\r", "\n", " ", " "), " ", str_replace( "\"", "'", strip_tags( $text ) ) ) );
  239. if ( !( $description ) ) $description = $blog_name . "-" . trim( wp_title('', false) );
  240. } elseif ( is_home () ) { $description = dopt('d_description'); // 首頁要自己加
  241. } elseif ( is_tag() ) { $description = $blog_name . "'" . single_tag_title('', false) . "'";
  242. } elseif ( is_category() ) { $description = trim(strip_tags(category_description()));
  243. } elseif ( is_archive() ) { $description = $blog_name . "'" . trim( wp_title('', false) ) . "'";
  244. } elseif ( is_search() ) { $description = $blog_name . ": '" . esc_html( $s, 1 ) . "' 的搜索結果";
  245. } else { $description = $blog_name . "'" . trim( wp_title('', false) ) . "'";
  246. }
  247. $description = mb_substr( $description, 0, 220, 'utf-8' );
  248. echo "<meta name=\"description\" content=\"$description\">\n";
  249. }
  250. function hide_admin_bar($flag) {
  251. return false;
  252. }
  253. //最新发布加new 单位'小时'
  254. function deel_post_new($timer='48'){
  255. $t=( strtotime( date("Y-m-d H:i:s") )-strtotime( $post->post_date ) )/3600;
  256. if( $t < $timer ) echo "<i>new</i>";
  257. }
  258. //修改评论表情调用路径
  259. function deel_smilies_src ($img_src, $img, $siteurl){
  260. return get_bloginfo('template_directory').'/img/smilies/'.$img;
  261. }
  262. //阻止站内文章Pingback
  263. function deel_noself_ping( &$links ) {
  264. $home = get_option( 'home' );
  265. foreach ( $links as $l => $link )
  266. if ( 0 === strpos( $link, $home ) )
  267. unset($links[$l]);
  268. }
  269. //移除自动保存
  270. function deel_disable_autosave() {
  271. wp_deregister_script('autosave');
  272. }
  273. //修改默认发信地址
  274. function deel_res_from_email($email) {
  275. $wp_from_email = get_option('admin_email');
  276. return $wp_from_email;
  277. }
  278. function deel_res_from_name($email){
  279. $wp_from_name = get_option('blogname');
  280. return $wp_from_name;
  281. }
  282. //评论回应邮件通知
  283. function comment_mail_notify($comment_id) {
  284. $admin_notify = '1'; // admin 要不要收回复通知 ( '1'=要 ; '0'=不要 )
  285. $admin_email = get_bloginfo ('admin_email'); // $admin_email 可改为你指定的 e-mail.
  286. $comment = get_comment($comment_id);
  287. $comment_author_email = trim($comment->comment_author_email);
  288. $parent_id = $comment->comment_parent ? $comment->comment_parent : '';
  289. global $wpdb;
  290. if ($wpdb->query("Describe {$wpdb->comments} comment_mail_notify") == '')
  291. $wpdb->query("ALTER TABLE {$wpdb->comments} ADD COLUMN comment_mail_notify TINYINT NOT NULL DEFAULT 0;");
  292. if (($comment_author_email != $admin_email && isset($_POST['comment_mail_notify'])) || ($comment_author_email == $admin_email && $admin_notify == '1'))
  293. $wpdb->query("UPDATE {$wpdb->comments} SET comment_mail_notify='1' WHERE comment_ID='$comment_id'");
  294. $notify = $parent_id ? get_comment($parent_id)->comment_mail_notify : '0';
  295. $spam_confirmed = $comment->comment_approved;
  296. if ($parent_id != '' && $spam_confirmed != 'spam' && $notify == '1') {
  297. $wp_email = 'no-reply@' . preg_replace('#^www\.#', '', strtolower($_SERVER['SERVER_NAME'])); // e-mail 发出点, no-reply 可改为可用的 e-mail.
  298. $to = trim(get_comment($parent_id)->comment_author_email);
  299. $subject = 'Hi,您在 [' . get_option("blogname") . '] 的留言有人回复啦!';
  300. $message = '
  301. <div style="color:#333;font:100 14px/24px microsoft yahei;">
  302. <p>' . trim(get_comment($parent_id)->comment_author) . ', 您好!</p>
  303. <p>您曾在《' . get_the_title($comment->comment_post_ID) . '》的留言:<br /> &nbsp;&nbsp;&nbsp;&nbsp; '
  304. . trim(get_comment($parent_id)->comment_content) . '</p>
  305. <p>' . trim($comment->comment_author) . ' 给您的回应:<br /> &nbsp;&nbsp;&nbsp;&nbsp; '
  306. . trim($comment->comment_content) . '<br /></p>
  307. <p>点击 <a href="' . htmlspecialchars(get_comment_link($parent_id)) . '">查看回应完整內容</a></p>
  308. <p>欢迎再次光临 <a href="' . get_option('home') . '">' . get_option('blogname') . '</a></p>
  309. <p style="color:#999">(此邮件由系统自动发出,请勿回复.)</p>
  310. </div>';
  311. $from = "From: \"" . get_option('blogname') . "\" <$wp_email>";
  312. $headers = "$from\nContent-Type: text/html; charset=" . get_option('blog_charset') . "\n";
  313. wp_mail( $to, $subject, $message, $headers );
  314. //echo 'mail to ', $to, '<br/> ' , $subject, $message; // for testing
  315. }
  316. }
  317. //自动勾选
  318. function deel_add_checkbox() {
  319. echo '<label for="comment_mail_notify" class="checkbox inline" style="padding-top:0"><input type="checkbox" name="comment_mail_notify" id="comment_mail_notify" value="comment_mail_notify" checked="checked"/>有人回复时邮件通知我</label>';
  320. }
  321. //文章(包括feed)末尾加版权说明
  322. function deel_copyright($content) {
  323. if( !is_page() ){
  324. $pid = get_the_ID();
  325. $name = get_post_meta($pid, 'from.name', true);
  326. $link = get_post_meta($pid, 'from.link', true);
  327. $show = false;
  328. if( $name ){
  329. $show = $name;
  330. if( $link ){
  331. $show = '<a target="_blank" href="'.$link.'">'.$show.'</a>';
  332. }
  333. }else if( $link ){
  334. $show = '<a target="_blank" href="'.$link.'">'.$link.'</a>';
  335. }
  336. if( $show ){
  337. $content.= '<p>来源:'.$show.'</p>';
  338. }
  339. $content.= '<p>转载请注明:<a href="'.get_bloginfo('url').'">'.get_bloginfo('name').'</a> &raquo; <a href="'.get_permalink().'">'.get_the_title().'</a></p>';
  340. }
  341. return $content;
  342. }
  343. //时间显示方式‘xx以前’
  344. function time_ago( $type = 'commennt', $day = 7 ) {
  345. $d = $type == 'post' ? 'get_post_time' : 'get_comment_time';
  346. if (time() - $d('U') > 60*60*24*$day) return;
  347. echo ' (', human_time_diff($d('U'), strtotime(current_time('mysql', 0))), '前)';
  348. }
  349. function timeago( $ptime ) {
  350. $ptime = strtotime($ptime);
  351. $etime = time() - $ptime;
  352. if($etime < 1) return '刚刚';
  353. $interval = array (
  354. 12 * 30 * 24 * 60 * 60 => '年前 ('.date('Y-m-d', $ptime).')',
  355. 30 * 24 * 60 * 60 => '个月前 ('.date('m-d', $ptime).')',
  356. 7 * 24 * 60 * 60 => '周前 ('.date('m-d', $ptime).')',
  357. 24 * 60 * 60 => '天前',
  358. 60 * 60 => '小时前',
  359. 60 => '分钟前',
  360. 1 => '秒前'
  361. );
  362. foreach ($interval as $secs => $str) {
  363. $d = $etime / $secs;
  364. if ($d >= 1) {
  365. $r = round($d);
  366. return $r . $str;
  367. }
  368. };
  369. }
  370. //评论样式
  371. function deel_comment_list($comment, $args, $depth) {
  372. echo '<li '; comment_class(); echo ' id="comment-'.get_comment_ID().'">';
  373. //头像
  374. echo '<div class="c-avatar">';
  375. echo str_replace(' src=', ' data-original=', get_avatar( $comment->comment_author_email, $size = '54' , deel_avatar_default()));
  376. //内容
  377. echo '<div class="c-main" id="div-comment-'.get_comment_ID().'">';
  378. echo str_replace(' src=', ' data-original=', convert_smilies(get_comment_text()));
  379. if ($comment->comment_approved == '0'){
  380. echo '<span class="c-approved">您的评论正在排队审核中,请稍后!</span><br />';
  381. }
  382. //信息
  383. echo '<div class="c-meta">';
  384. echo '<span class="c-author">'.get_comment_author_link().'</span>';
  385. echo get_comment_time('Y-m-d H:i '); echo time_ago();
  386. if ($comment->comment_approved !== '0'){
  387. echo comment_reply_link( array_merge( $args, array('add_below' => 'div-comment', 'depth' => $depth, 'max_depth' => $args['max_depth'] ) ) );
  388. echo edit_comment_link(__('(编辑)'),' - ','');
  389. }
  390. echo '</div>';
  391. echo '</div></div>';
  392. }
  393. //remove google fonts
  394. if (!function_exists('remove_wp_open_sans')) :
  395. function remove_wp_open_sans() {
  396. wp_deregister_style( 'open-sans' );
  397. wp_register_style( 'open-sans', false );
  398. }
  399. add_action('admin_enqueue_scripts', 'remove_wp_open_sans');
  400. add_action('login_init', 'remove_wp_open_sans');
  401. endif;
  402. //欲思@添加钮Download
  403. function DownloadUrl($atts, $content = null) {
  404. extract(shortcode_atts(array("href" => 'http://'), $atts));
  405. return '<a class="dl" href="'.$href.'" target="_blank" rel="nofollow"><i class="fa fa-cloud-download"></i>'.$content.'</a>';
  406. }
  407. add_shortcode("dl", "DownloadUrl");
  408. //欲思@添加钮git
  409. function GithubUrl($atts, $content=null) {
  410. extract(shortcode_atts(array("href" => 'http://'), $atts));
  411. return '<a class="dl" href="'.$href.'" target="_blank" rel="nofollow"><i class="fa fa-github-alt"></i>'.$content.'</a>';
  412. }
  413. add_shortcode('gt' , 'GithubUrl' );
  414. //欲思@添加钮Demo
  415. function DemoUrl($atts, $content=null) {
  416. extract(shortcode_atts(array("href" => 'http://'), $atts));
  417. return '<a class="dl" href="'.$href.'" target="_blank" rel="nofollow"><i class="fa fa-external-link"></i>'.$content.'</a>';
  418. }
  419. add_shortcode('dm' , 'DemoUrl' );
  420. //欲思@添加编辑器快捷按钮
  421. add_action('admin_print_scripts', 'my_quicktags');
  422. function my_quicktags() {
  423. wp_enqueue_script(
  424. 'my_quicktags',
  425. get_stylesheet_directory_uri().'/js/my_quicktags.js',
  426. array('quicktags')
  427. );
  428. };
  429. //评论过滤
  430. function refused_spam_comments( $comment_data ) {
  431. $pattern = '/[一-龥]/u';
  432. $jpattern ='/[ぁ-ん]+|[ァ-ヴ]+/u';
  433. if(!preg_match($pattern,$comment_data['comment_content'])) {
  434. err('写点汉字吧,博主外语很捉急!You should type some Chinese word!');
  435. }
  436. if(preg_match($jpattern, $comment_data['comment_content'])){
  437. err('日文滚粗!Japanese Get out!日本語出て行け! You should type some Chinese word!');
  438. }
  439. return( $comment_data );
  440. }
  441. if( dopt('d_spamComments_b') ){
  442. add_filter('preprocess_comment','refused_spam_comments');
  443. }
  444. //点赞
  445. add_action('wp_ajax_nopriv_bigfa_like', 'bigfa_like');
  446. add_action('wp_ajax_bigfa_like', 'bigfa_like');
  447. function bigfa_like(){
  448. global $wpdb,$post;
  449. $id = $_POST["um_id"];
  450. $action = $_POST["um_action"];
  451. if ( $action == 'ding'){
  452. $bigfa_raters = get_post_meta($id,'bigfa_ding',true);
  453. $expire = time() + 99999999;
  454. $domain = ($_SERVER['HTTP_HOST'] != 'localhost') ? $_SERVER['HTTP_HOST'] : false; // make cookies work with localhost
  455. setcookie('bigfa_ding_'.$id,$id,$expire,'/',$domain,false);
  456. if (!$bigfa_raters || !is_numeric($bigfa_raters)) {
  457. update_post_meta($id, 'bigfa_ding', 1);
  458. }
  459. else {
  460. update_post_meta($id, 'bigfa_ding', ($bigfa_raters + 1));
  461. }
  462. echo get_post_meta($id,'bigfa_ding',true);
  463. }
  464. die;
  465. }
  466. //最热排行
  467. function hot_posts_list($days=7, $nums=10) {
  468. global $wpdb;
  469. $today = date("Y-m-d H:i:s");
  470. $daysago = date( "Y-m-d H:i:s", strtotime($today) - ($days * 24 * 60 * 60) );
  471. $result = $wpdb->get_results("SELECT comment_count, ID, post_title, post_date FROM $wpdb->posts WHERE post_date BETWEEN '$daysago' AND '$today' ORDER BY comment_count DESC LIMIT 0 , $nums");
  472. $output = '';
  473. if(empty($result)) {
  474. $output = '<li>None data.</li>';
  475. } else {
  476. $i = 1;
  477. foreach ($result as $topten) {
  478. $postid = $topten->ID;
  479. $title = $topten->post_title;
  480. $commentcount = $topten->comment_count;
  481. if ($commentcount != 0) {
  482. $output .= '<li><p><span class="post-comments">评论 ('.$commentcount.')</span><span class="muted"><a href="javascript:;" data-action="ding" data-id="'.$postid.'" id="Addlike" class="action';
  483. if(isset($_COOKIE['bigfa_ding_'.$postid])) $output .=' actived';
  484. $output .='"><i class="fa fa-heart-o"></i><span class="count">';
  485. if( get_post_meta($postid,'bigfa_ding',true) ){
  486. $output .=get_post_meta($postid,'bigfa_ding',true);
  487. } else {$output .='0';}
  488. $output .='</span>喜欢</a></span></p><span class="label label-'.$i.'">'.$i.'</span><a href="'.get_permalink($postid).'" title="'.$title.'">'.$title.'</a></li>';
  489. $i++;
  490. }
  491. }
  492. }
  493. echo $output;
  494. }
  495. //在 WordPress 编辑器添加“下一页”按钮
  496. add_filter('mce_buttons','add_next_page_button');
  497. function add_next_page_button($mce_buttons) {
  498. $pos = array_search('wp_more',$mce_buttons,true);
  499. if ($pos !== false) {
  500. $tmp_buttons = array_slice($mce_buttons, 0, $pos+1);
  501. $tmp_buttons[] = 'wp_page';
  502. $mce_buttons = array_merge($tmp_buttons, array_slice($mce_buttons, $pos+1));
  503. }
  504. return $mce_buttons;
  505. }
  506. //判断手机广告
  507. function Yusi_is_mobile() {
  508. if ( empty($_SERVER['HTTP_USER_AGENT']) ) {
  509. return false;
  510. } elseif ( ( strpos($_SERVER['HTTP_USER_AGENT'], 'Mobile') !== false && strpos($_SERVER['HTTP_USER_AGENT'], 'iPad') === false) // many mobile devices (all iPh, etc.)
  511. || strpos($_SERVER['HTTP_USER_AGENT'], 'Android') !== false
  512. || strpos($_SERVER['HTTP_USER_AGENT'], 'Silk/') !== false
  513. || strpos($_SERVER['HTTP_USER_AGENT'], 'Kindle') !== false
  514. || strpos($_SERVER['HTTP_USER_AGENT'], 'BlackBerry') !== false
  515. || strpos($_SERVER['HTTP_USER_AGENT'], 'Opera Mini') !== false
  516. || strpos($_SERVER['HTTP_USER_AGENT'], 'Opera Mobi') !== false ) {
  517. return true;
  518. } else {
  519. return false;
  520. }
  521. }
  522. //欲思@搜索结果排除所有页面
  523. function search_filter_page($query) {
  524. if ($query->is_search) {
  525. $query->set('post_type', 'post');
  526. }
  527. return $query;
  528. }
  529. add_filter('pre_get_posts','search_filter_page');
  530. // 更改后台字体
  531. function Bing_admin_lettering(){
  532. echo'<style type="text/css">
  533. * { font-family: "Microsoft YaHei" !important; }
  534. i, .ab-icon, .mce-close, i.mce-i-aligncenter, i.mce-i-alignjustify, i.mce-i-alignleft, i.mce-i-alignright, i.mce-i-blockquote, i.mce-i-bold, i.mce-i-bullist, i.mce-i-charmap, i.mce-i-forecolor, i.mce-i-fullscreen, i.mce-i-help, i.mce-i-hr, i.mce-i-indent, i.mce-i-italic, i.mce-i-link, i.mce-i-ltr, i.mce-i-numlist, i.mce-i-outdent, i.mce-i-pastetext, i.mce-i-pasteword, i.mce-i-redo, i.mce-i-removeformat, i.mce-i-spellchecker, i.mce-i-strikethrough, i.mce-i-underline, i.mce-i-undo, i.mce-i-unlink, i.mce-i-wp-media-library, i.mce-i-wp_adv, i.mce-i-wp_fullscreen, i.mce-i-wp_help, i.mce-i-wp_more, i.mce-i-wp_page, .qt-fullscreen, .star-rating .star { font-family: dashicons !important; }
  535. .mce-ico { font-family: tinymce, Arial !important; }
  536. .fa { font-family: FontAwesome !important; }
  537. .genericon { font-family: "Genericons" !important; }
  538. .appearance_page_scte-theme-editor #wpbody *, .ace_editor * { font-family: Monaco, Menlo, "Ubuntu Mono", Consolas, source-code-pro, monospace !important; }
  539. </style>';
  540. }
  541. add_action('admin_head', 'Bing_admin_lettering');
  542. //欲思@添加相关文章图片文章
  543. if ( function_exists('add_theme_support') )add_theme_support('post-thumbnails');
  544. //输出缩略图地址
  545. function post_thumbnail_src(){
  546. global $post;
  547. if( $values = get_post_custom_values("thumb") ) { //输出自定义域图片地址
  548. $values = get_post_custom_values("thumb");
  549. $post_thumbnail_src = $values [0];
  550. } elseif( has_post_thumbnail() ){ //如果有特色缩略图,则输出缩略图地址
  551. $thumbnail_src = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID),'full');
  552. $post_thumbnail_src = $thumbnail_src [0];
  553. } else {
  554. $post_thumbnail_src = '';
  555. ob_start();
  556. ob_end_clean();
  557. $output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $post->post_content, $matches);
  558. $post_thumbnail_src = $matches [1] [0]; //获取该图片 src
  559. if(empty($post_thumbnail_src)){ //如果日志中没有图片,则显示随机图片
  560. $random = mt_rand(1, 10);
  561. echo get_bloginfo('template_url');
  562. echo '/img/pic/'.$random.'.jpg';
  563. //如果日志中没有图片,则显示默认图片
  564. //echo '/img/thumbnail.png';
  565. }
  566. };
  567. echo $post_thumbnail_src;
  568. }
  569. //替换google图片地址
  570. function replace($matches){
  571. return get_bloginfo("template_url")."/timthumb.php?src=".$matches[0]."&h=&w=".$matches['size']."&q=100&zc=1&ct=1";
  572. }
  573. function replace_pic($content){
  574. $content = apply_filters( 'the_content', $content);
  575. $content = str_replace( ']]>', ']]&gt;', $content );
  576. //$pattern_1 = "/(http|https)\:\/\/\S+(googleusercontent|ggpht)\S+\/s(?<size>\d+)[\-c]*?\/\S+\.(jpg|png|gif)/i";
  577. $pattern_1 = "/(http|https)\:\/\/\S+(googleusercontent|ggpht)\S+\/s(?<size>\d+)[\-\S+]*?\/\S+\.(jpg|png|gif)/i";
  578. $pattern_2 = "/(http|https)\:\/\/\S+(googleusercontent|ggpht)\S+\.(jpg|png|gif)\?imgmax=(?<size>\d+)/i";
  579. $content = preg_replace_callback($pattern_1, 'replace', $content);
  580. $content = preg_replace_callback($pattern_2, 'replace', $content);
  581. echo $content;
  582. }
  583. add_filter('pre_option_link_manager_enabled','__return_true');
  584. ?>