tougao.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <?php
  2. require( dirname(__FILE__).'/../../../../wp-load.php' );
  3. if( !dopt('d_tougao_b') ) die('off');
  4. global $wpdb;
  5. $last_post = $wpdb->get_var("SELECT post_date FROM $wpdb->posts WHERE post_type = 'post' ORDER BY post_date DESC LIMIT 1");
  6. if ( current_time('timestamp') - strtotime($last_post) < (dopt('d_tougao_time')?dopt('d_tougao_time'):240) ){
  7. die('sofast');
  8. }
  9. $title = check_chart( $_POST['title'] );
  10. $url = check_chart( $_POST['url'] );
  11. $content = check_chart( $_POST['content'] );
  12. if ( empty($title) || mb_strlen($title) > 100 ) {
  13. die('title');
  14. }
  15. if ( empty($url) || mb_strlen($url) > 100 ) {
  16. die('url');
  17. }
  18. if ( empty($content) || mb_strlen($content) > 5000 || mb_strlen($content) < 200) {
  19. die('content');
  20. }
  21. if( $url ) $url = '<p>来源:<a href="'.$url.'" target="_blank">'.$url.'</a></p>';
  22. $post_content = $content.$url;
  23. $submit = array(
  24. 'post_title' => $title,
  25. 'post_author' => 1,
  26. 'post_content' => $post_content
  27. );
  28. $status = wp_insert_post( $submit );
  29. if ($status != 0) {
  30. if( dopt('d_tougao_mailto') ) wp_mail(dopt('d_tougao_mailto'), "站长,有新投稿! ".$title, $post_content);
  31. die('success');
  32. }else{
  33. die('fail');
  34. }
  35. function check_chart($t){
  36. return isset( $t ) ? trim(htmlspecialchars($t, ENT_QUOTES)) : '';
  37. }
  38. ?>