Cache.php 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. <?php
  2. namespace Sakura\API;
  3. class Cache
  4. {
  5. public static function search_json() {
  6. global $more;
  7. $vowels = array("[", "{", "]", "}", "<", ">", "\r\n", "\r", "\n", "-", "'", '"', '`', " ", ":", ";", '\\', " ", "toc");
  8. $regex = <<<EOS
  9. /<\/?[a-zA-Z]+("[^"]*"|'[^']*'|[^'">])*>|begin[\S\s]*\/begin|hermit[\S\s]*\/hermit|img[\S\s]*\/img|{{.*?}}|:.*?:/m
  10. EOS;
  11. $more = 1;
  12. $output = array();
  13. $posts = new \WP_Query('posts_per_page=-1&post_status=publish&post_type=post');
  14. while ($posts->have_posts()): $posts->the_post();
  15. $output[] = array(
  16. "type" => "post",
  17. "link" => get_permalink(),
  18. "title" => get_the_title(),
  19. "comments" => get_comments_number('0', '1', '%'),
  20. "text" => str_replace($vowels, " ", preg_replace($regex, ' ', apply_filters('the_content', get_the_content())))
  21. );
  22. endwhile;
  23. wp_reset_postdata();
  24. $pages = new \WP_Query('posts_per_page=-1&post_status=publish&post_type=page');
  25. while ($pages->have_posts()): $pages->the_post();
  26. $output[] = array(
  27. "type" => "page",
  28. "link" => get_permalink(),
  29. "title" => get_the_title(),
  30. "comments" => get_comments_number('0', '1', '%'),
  31. "text" => str_replace($vowels, " ", preg_replace($regex, ' ', apply_filters('the_content', get_the_content())))
  32. );
  33. endwhile;
  34. wp_reset_postdata();
  35. $tags = get_tags();
  36. foreach ($tags as $tag) {
  37. $output[] = array(
  38. "type" => "tag",
  39. "link" => get_term_link($tag),
  40. "title" => $tag->name,
  41. "comments" => "",
  42. "text" => ""
  43. );
  44. }
  45. $categories = get_categories();
  46. foreach ($categories as $category) {
  47. $output[] = array(
  48. "type" => "category",
  49. "link" => get_term_link($category),
  50. "title" => $category->name,
  51. "comments" => "",
  52. "text" => ""
  53. );
  54. }
  55. if (iro_opt('live_search_comment')) {
  56. $comments = get_comments();
  57. foreach ($comments as $comment) {
  58. $is_private = get_comment_meta($comment->comment_ID, '_private', true);
  59. $output[] = array(
  60. "type" => "comment",
  61. "link" => get_comment_link($comment),
  62. "title" => get_the_title($comment->comment_post_ID),
  63. "comments" => "",
  64. "text" => $is_private ? ($comment->comment_author . ": " . __('The comment is private', 'sakurairo')) : str_replace($vowels, ' ', preg_replace($regex, ' ', $comment->comment_author . ":" . $comment->comment_content))
  65. );
  66. }
  67. }
  68. return $output;
  69. }
  70. // public static function update_database() {
  71. // global $wpdb;
  72. // $sakura_table_name = $wpdb->base_prefix . 'sakurairo';
  73. // $img_domain = iro_opt('random_graphs_link') ? iro_opt('random_graphs_link') : get_template_directory();
  74. // $manifest = file_get_contents($img_domain . "/manifest/manifest.json");
  75. // if(iro_opt('random_graphs_mts')){
  76. // $manifest_mobile = file_get_contents($img_domain . "/manifest/manifest_mobile.json");
  77. // if($manifest && $manifest_mobile){
  78. // $manifest = array(
  79. // "mate_key" => "manifest_json",
  80. // "mate_value" => $manifest
  81. // );
  82. // $manifest_mobile = array(
  83. // "mate_key" => "mobile_manifest_json",
  84. // "mate_value" => $manifest_mobile
  85. // );
  86. // $time = array(
  87. // "mate_key" => "json_time",
  88. // "mate_value" => date("Y-m-d H:i:s", time())
  89. // );
  90. // $wpdb->query("DELETE FROM $sakura_table_name WHERE `mate_key` ='manifest_json'");
  91. // $wpdb->query("DELETE FROM $sakura_table_name WHERE `mate_key` ='mobile_manifest_json'");
  92. // $wpdb->query("DELETE FROM $sakura_table_name WHERE `mate_key` ='json_time'");
  93. // $wpdb->insert($sakura_table_name, $manifest);
  94. // $wpdb->insert($sakura_table_name, $manifest_mobile);
  95. // $wpdb->insert($sakura_table_name, $time);
  96. // $output = "manifest.json&&mainfest_mobile.json has been stored into database.";
  97. // } else {
  98. // $output = "manifest.json or mainfest_mobile.json not found, please ensure your url ($img_domain) is corrent.";
  99. // }
  100. // }
  101. // elseif ($manifest) {
  102. // $manifest = array(
  103. // "mate_key" => "manifest_json",
  104. // "mate_value" => $manifest
  105. // );
  106. // $time = array(
  107. // "mate_key" => "json_time",
  108. // "mate_value" => date("Y-m-d H:i:s", time())
  109. // );
  110. // $wpdb->query("DELETE FROM $sakura_table_name WHERE `mate_key` ='manifest_json'");
  111. // $wpdb->query("DELETE FROM $sakura_table_name WHERE `mate_key` ='json_time'");
  112. // $wpdb->insert($sakura_table_name, $manifest);
  113. // $wpdb->insert($sakura_table_name, $time);
  114. // $output = "manifest.json has been stored into database.";
  115. // } else {
  116. // $output = "manifest.json not found, please ensure your url ($img_domain) is corrent.";
  117. // }
  118. // return $output;
  119. // }
  120. }