krot

SEO tag WP

Dec 1st, 2015
79
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <html><head><title>Meta tag</title><meta charset="utf-8"></head>
  2. <body><form method="post">
  3. <table border="1">
  4. <tr>
  5. <td>URL:<input type="text" name="url" value="/url"></td>
  6. <td>Title:<input type="text" name="title" value=""></td>
  7. <td>Description:<input type="text" name="des" value=""></td>
  8. <td>Keywords:<input type="text" name="kw" value=""></td>
  9. <td><input type="submit"></td>
  10. </tr>
  11. </table>
  12. </form>
  13. <script>
  14. <?php
  15. if(!empty($_POST)){
  16. mysql_connect('localhost','root','');
  17. mysql_select_db('wp');
  18. mysql_query("SET NAMES 'utf8'");
  19. mysql_query("SET CHARACTER SET 'utf8'");
  20. mysql_query("SET SESSION collation_connection = 'utf8_general_ci'");
  21.  
  22. if(empty($_POST['url']))print('alert("Должен быть указан url!");');
  23. else{
  24. $url=mysql_real_escape_string( ((string)$_POST['url']));
  25.  
  26. $title= mysql_real_escape_string((string)$_POST['title']);
  27. $des= mysql_real_escape_string((string)$_POST['des']);
  28. $kw= mysql_real_escape_string((string)$_POST['kw']);
  29. mysql_query("INSERT INTO seo_tag  VALUES (null,'$url','$title','$des','$kw') ON DUPLICATE KEY UPDATE title='$title',des='$des',kw='$kw';");
  30. if(mysql_affected_rows())
  31. print('alert("ОК");');
  32. else print('alert("Error");');
  33. }
  34. }
  35. ?>
  36. </script>
  37. </body>
  38. </html>
  39.  
  40. ////////function wp
  41.  
  42. add_action('template_redirect', 'before_header', 0);
  43. add_action('wp_head', 'after_header', 900);
  44. function before_header (){
  45.     ob_start('change_tag');
  46. }
  47. function change_tag($head) {
  48.     //[REQUEST_URI] => /inurl?hjjhjh
  49.     // [SCRIPT_URL] => /inurl
  50.      $url=mysql_real_escape_string(urldecode(((string)$_SERVER['REQUEST_URI'])));
  51.     $rurl=mysql_fetch_assoc(mysql_query("select * from seo_tag where url='$url'"));
  52.     if(empty($rurl)){
  53.     $url=mysql_real_escape_string(((string)$_SERVER['SCRIPT_URL']));
  54.     $rurl=mysql_fetch_assoc(mysql_query("select * from seo_tag where url='$url'"));
  55.     if(empty($rurl))return $head;
  56.     }
  57.     $title =$rurl['title'];
  58.     if (!$title) return $head;
  59.     $head=preg_replace('#<title>[^<]*</title>#', '<title>'.$title.'</title>', $head);
  60.    
  61.     $des =$rurl['des'];
  62.     $kw =$rurl['kw'];
  63.    
  64.     if($des){
  65.     if(stripos($head,'description')!==false){
  66.     $head=preg_replace('#<meta[^>]*name=[\"|\']description[\"|\'][^>]*content=[\"]([^\"]*)[\"][^>]*>#i', '<meta name="description" content="'.$des.'"/>', $head);
  67.     }else{
  68.     $head.= '<meta name="description" content="'.$des.'"/>';
  69.         }
  70.     }
  71.     if($kw){
  72.     if(stripos($head,'keywords')!==false){
  73.     $head=preg_replace('#<meta[^>]*name=[\"|\']keywords[\"|\'][^>]*content=[\"]([^\"]*)[\"][^>]*>#i', '<meta name="keywords" content="'.$kw.'"/>', $head);
  74.     }else{
  75.     $head.= '<meta name="keywords" content="'.$kw.'"/>';
  76.     }
  77.     }
  78. return $head;
  79. }
  80. function after_header() {
  81.     ob_end_flush();
  82. }
RAW Paste Data