PluginProbe ʕ •ᴥ•ʔ
Hostinger Tools / 3.0.71
Hostinger Tools v3.0.71
3.0.71 3.0.70 3.0.69 3.0.68 3.0.67 3.0.66 1.8.1 1.8.2 1.8.3 1.9.1 1.9.4 1.9.5 1.9.6 1.9.7 1.9.8 1.9.9 2.0.0 2.0.1 2.0.4 2.0.6 2.0.7 2.0.8 2.0.9 2.1.0 2.1.1 2.1.2 2.1.4 2.1.5 2.1.6 2.1.7 2.1.8 2.1.9 2.2.0 2.2.1 2.2.2 2.2.3 2.2.4 3.0.0 3.0.10 3.0.11 3.0.12 3.0.13 3.0.14 3.0.15 3.0.16 3.0.17 3.0.18 3.0.19 3.0.2 3.0.20 3.0.21 3.0.22 3.0.23 3.0.24 3.0.25 3.0.26 3.0.27 3.0.28 3.0.29 3.0.3 3.0.30 3.0.31 3.0.32 3.0.33 3.0.34 3.0.35 3.0.36 3.0.37 3.0.38 3.0.39 3.0.4 3.0.40 3.0.41 3.0.42 3.0.43 3.0.44 3.0.45 3.0.46 3.0.47 3.0.48 3.0.49 3.0.5 3.0.50 3.0.51 3.0.52 3.0.53 3.0.54 3.0.55 3.0.56 3.0.57 3.0.58 3.0.59 3.0.6 3.0.60 3.0.61 3.0.62 3.0.65 3.0.7 3.0.8 3.0.9 trunk 1.8.0
hostinger / includes / LlmsTxtGenerator / LlmsTxtParser.php
hostinger / includes / LlmsTxtGenerator Last commit date
LlmsTxtFileHelper.php 10 months ago LlmsTxtGenerator.php 2 weeks ago LlmsTxtParser.php 10 months ago
LlmsTxtParser.php
93 lines
1 <?php
2
3 namespace Hostinger\LlmsTxtGenerator;
4
5
6 defined( 'ABSPATH' ) || exit;
7
8 class LlmsTxtParser {
9
10 public const DEFAULT_LIMIT = 100;
11 public const HOSTINGER_LLMSTXT_SIGNATURE = '[comment]: # (Generated by Hostinger Tools Plugin)';
12
13 public function get_by_post_type( string $post_type, int $limit = self::DEFAULT_LIMIT, int $offset = 0 ): array {
14 $limit = apply_filters( 'hostinger_batch_item_limit', $limit );
15 $args = array(
16 'post_type' => $post_type,
17 'post_status' => 'publish',
18 'fields' => 'ids',
19 'posts_per_page' => $limit,
20 'offset' => $offset,
21 );
22
23 return get_posts( $args );
24 }
25
26 public function get_items( array $items ): string {
27 $content = '';
28 foreach ( $items as $item ) {
29 $post = get_post( $item );
30 $title = $post->post_title;
31 $permalink = get_permalink( $post );
32 $excerpt = $this->prepare_excerpt( $post );
33
34 $content .= "- [$title]($permalink)";
35 if ( $excerpt ) {
36 $content .= ": $excerpt";
37 }
38
39 $content .= "\n";
40 }
41
42 return $content;
43 }
44
45 public function inject_site_description(): string {
46 $description = get_bloginfo( 'description' );
47
48 return $description ? "> $description\n\n" : '';
49 }
50
51 public function inject_title(): string {
52 $title = get_bloginfo( 'name' ) ? get_bloginfo( 'name' ) : site_url();
53
54 return "# $title\n\n";
55 }
56
57 public function inject_signature(): string {
58 return "\n\n" . self::HOSTINGER_LLMSTXT_SIGNATURE;
59 }
60
61 public function inject_mcp_agent_entry(): string {
62 $domain = parse_url( site_url(), PHP_URL_HOST );
63
64 return "- [Agent (MCP protocol)](websites-agents.hostinger.com/$domain/mcp)";
65 }
66
67 public function inject_items( array $items, string $title ): string {
68 if ( empty( $items ) ) {
69 return '';
70 }
71
72 $content = "\n## $title\n\n";
73 $content .= $this->get_items( $items );
74
75 return $content;
76 }
77
78 public function inject_optional_entries( array $entries ): string {
79 $output = '';
80
81 if ( ! empty( $entries ) ) {
82 $output = "\n## Optional\n\n";
83 $output .= implode( "\n", $entries );
84 }
85
86 return $output;
87 }
88
89 public function prepare_excerpt( \WP_Post $item ): string {
90 return str_replace( array( "\r", "\n" ), ' ', strip_tags( wp_trim_excerpt( $item->post_excerpt, $item ) ) );
91 }
92 }
93