entry-census.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. <?php
  2. function get_edit_html(): string
  3. {
  4. $url = get_edit_post_link();
  5. if ($url) {
  6. return ' <a href="' . $url . '">' . __("EDIT", "sakurairo") . '</a>';
  7. }
  8. return '';
  9. }
  10. function __wrap_with_span($content): string
  11. {
  12. return " <span>$content</span>";
  13. }
  14. function get_entry_census_meta_html($has_splitter)
  15. {
  16. $post = get_post();
  17. $meta_display = iro_opt("article_meta_show_in_head", array("last_edit_time_relative", "post_views"));
  18. if (!is_array($meta_display) && !is_object($meta_display)) {
  19. $meta_display = array("last_edit_time_relative", "post_views");
  20. }
  21. foreach ($meta_display as $meta_key) {
  22. $content = false;
  23. switch ($meta_key) {
  24. case "author":
  25. require_once get_stylesheet_directory() . '/tpl/meta-author.php';
  26. ob_start();
  27. render_author_meta();
  28. $content = ob_get_contents();
  29. ob_end_clean();
  30. break;
  31. case "category":
  32. require_once get_stylesheet_directory() . '/tpl/meta-category.php';
  33. $content = get_meta_category_html();
  34. break;
  35. case "comment_count":
  36. require_once get_stylesheet_directory() . '/tpl/meta-comments.php';
  37. ob_start();
  38. render_meta_comments();
  39. $content = ob_get_contents();
  40. ob_end_clean();
  41. break;
  42. case "post_views":
  43. $content = get_post_views(get_the_ID()) . ' ' . _n('View', 'Views', get_post_views(get_the_ID()), 'sakurairo');/*次阅读*/
  44. if ($has_splitter) {
  45. $content = __wrap_with_span($content);
  46. } else {
  47. $content = ' ' . $content;
  48. }
  49. break;
  50. case "post_words_count":
  51. require_once get_stylesheet_directory() . '/tpl/meta-words-count.php';
  52. $content = get_meta_words_count();
  53. if ($has_splitter) {
  54. $content = __wrap_with_span($content);
  55. } else {
  56. $content = ' ' . $content;
  57. }
  58. break;
  59. case "reading_time":
  60. require_once get_stylesheet_directory() . '/tpl/meta-ert.php';
  61. $content = __("Estimate Reading Time", "sakurairo") . ": " . get_meta_estimate_reading_time();
  62. if ($has_splitter) {
  63. $content = __wrap_with_span($content);
  64. } else {
  65. $content = ' ' . $content;
  66. }
  67. break;
  68. case "publish_time_relative":
  69. $content = poi_time_since(strtotime($post->post_date));
  70. if ($has_splitter) {
  71. $content = __wrap_with_span($content);
  72. } else {
  73. $content = ' ' . $content;
  74. }
  75. break;
  76. case "last_edit_time_relative":
  77. $content = poi_time_since(strtotime($post->post_modified), false, __('Last updated on ', 'sakurairo'));
  78. if ($has_splitter) {
  79. $content = __wrap_with_span(__("Last updated on", "sakurairo") . ' ' . $content);
  80. } else {
  81. $content = ' ' . __("Last updated on", "sakurairo") . ' ' . $content;
  82. }
  83. break;
  84. case "EDIT":
  85. $content = get_edit_html();
  86. break;
  87. }
  88. if ($content) {
  89. yield $content;
  90. }
  91. }
  92. }
  93. function get_entry_census_html($has_splitter = false)
  94. {
  95. $additional_class = $has_splitter ? " has-splitter" : "";
  96. $content = iterator_to_string(get_entry_census_meta_html($has_splitter));
  97. return "<p class=\"entry-census$additional_class\">$content</p>";
  98. }