<?php
/*
Theme Name: Blocksy Child
Theme URI: https://creativethemes.com/blocksy/
Template: blocksy
Author: CreativeThemes
Author URI: https://creativethemes.com
Description: Blocksy is a fast, modern WordPress theme with advanced WooCommerce support and full compatibility with the block editor.
Tags: accessibility-ready,blog,block-patterns,e-commerce,wide-blocks,block-styles,grid-layout,one-column,two-columns,three-columns,four-columns,right-sidebar,left-sidebar,translation-ready,custom-colors,custom-logo,custom-menu,featured-images,footer-widgets,full-width-template,theme-options,threaded-comments
Version: 2.1.34.1774398047
Updated: 2026-03-25 00:20:47
*/

// LINXACK - Endpoint AJAX para listar y buscar posts
function linxack_get_posts() {
  $search = isset($_GET['search']) ? sanitize_text_field($_GET['search']) : '';
  $args = array(
    'post_type'      => 'post',
    'post_status'    => 'publish',
    'posts_per_page' => -1,
    'orderby'        => 'date',
    'order'          => 'DESC',
    's'              => $search,
  );
  $query = new WP_Query($args);
  $posts = array();
  if ($query->have_posts()) {
    while ($query->have_posts()) {
      $query->the_post();
      $cats = get_the_category();
      $cat_name = !empty($cats) ? $cats[0]->name : 'sin-categoria';
      $content = get_the_content();
      $size = round(mb_strlen(strip_tags($content)) / 100) . 'kb';
      $posts[] = array(
        'title'    => get_the_title(),
        'url'      => get_permalink(),
        'date'     => get_the_date('M d H:i'),
        'category' => $cat_name,
        'size'     => $size,
        'slug'     => sanitize_title(get_the_title()) . '.txt',
      );
    }
    wp_reset_postdata();
  }
  wp_send_json($posts);
}
add_action('wp_ajax_linxack_posts', 'linxack_get_posts');
add_action('wp_ajax_nopriv_linxack_posts', 'linxack_get_posts');

// LINXACK - Pasar la URL de AJAX al frontend
function linxack_ajax_script() {
  echo '<script>var linxackAjax = "' . admin_url('admin-ajax.php') . '";</script>';
}
add_action('wp_head', 'linxack_ajax_script');