'; /** * Client instance (reserved for future use) * @var mixed */ private $client = null; /** * Notices array * @var array */ public $notices = []; /** * Stories per page limit * @var int */ public $limit = 50; /** * Plan limit * @var mixed */ private $plan_limit_aiautotool; /** * Plan name * @var string */ public $name_plan; /** * Configuration array * @var array */ public $config = array(); /** * Notice message * @var string */ public $notice; /** * Constructor * * Initializes the Web Stories feature: * - Loads settings from database * - Sets default logo if not configured * - Checks if feature is active * - Registers AJAX handlers * * @since 1.0.0 */ public function __construct() { $this->name_plan = __('Webstories', 'ai-auto-tool'); $this->setting = get_option($this->namesetting, array()); // Set default logo if not configured if (!isset($this->setting['logo'])) { // Use local plugin logo as fallback instead of external URL $this->setting['logo'] = defined('AIAUTOTOOL_URI') ? AIAUTOTOOL_URI . 'images/logo.svg' : plugins_url('../../images/logo.svg', __FILE__); } $this->active = get_option($this->active_option_name, false); // Initialize if active if ($this->active == 'true') { $this->init(); } // Register AJAX handlers add_action('wp_ajax_update_active_option_canonical_' . $this->active_option_name, array($this, 'update_active_option_callback')); } /** * AJAX callback to update active option * * Handles the activation/deactivation of the feature. * Verifies nonce for security. * * @since 1.0.0 * @return void Dies after output */ public function update_active_option_callback() { check_ajax_referer('aiautotool_nonce', 'security'); if (!current_user_can('manage_options')) { wp_die(__('Permission denied', 'ai-auto-tool'), '', array('response' => 403)); } if (isset($_POST['active'])) { $active = sanitize_text_field($_POST['active']); update_option($this->active_option_name, $active, null, 'no'); // Flush rewrite rules on activation if ($active === 'true') { delete_option($this->aiautotool_rewriter_flushed); } echo $active; } wp_die(); } /** * Initialize the feature * * Registers all necessary hooks: * - Custom rewrite rules * - Query vars * - Template include * - Settings registration * * @since 1.0.0 * @return void */ public function init() { // Hook into WordPress to register the custom URL add_action('init', array($this, 'add_custom_rewrite_rule')); // Hook into WordPress to add custom rewrite rules add_filter('query_vars', array($this, 'custom_rewrite_query_vars')); // Hook into WordPress to handle the custom template add_filter('template_include', array($this, 'custom_rewrite_rule_template')); // Register settings register_setting('aiautotool_webstories_config_group', $this->namesetting, array( 'type' => 'array', 'sanitize_callback' => array($this, 'sanitize_webstories_setting'), )); } /** * Sanitize webstories setting * * @param mixed $value Input value * @return array Sanitized array */ public function sanitize_webstories_setting($value) { if (!is_array($value)) { return array(); } return map_deep($value, 'sanitize_text_field'); } /** * Render settings page * * Displays the configuration interface for: * - Publisher logo (96x96px) * - Background audio files (MP3) * - Story link in posts option * - Google Analytics ID * * @since 1.0.0 * @return void */ public function render_setting() { ?>
active == 'true') { echo ''; } } /** * Render feature box * * Displays the feature card in the main plugin dashboard. * Loads description from feature-descriptions.php * * @since 1.0.0 * @return void */ public function render_feature() { // Load feature descriptions require_once plugin_dir_path(dirname(__FILE__)) . 'lib/feature-descriptions.php'; $autoToolBox = new AutoToolBox( $this->icon . " " . esc_html__('Web Stories Generator', 'ai-auto-tool'), AiAutoTool_Feature_Descriptions::get('webstories'), "https://doc.aiautotool.com/features/webstories", $this->active_option_name, $this->active, defined('AIAUTOTOOL_URI') ? AIAUTOTOOL_URI . 'images/logo.svg' : plugins_url('../../images/logo.svg', __FILE__) ); echo $autoToolBox->generateHTML(); } /** * Custom rewrite rule handler * * Displays the stories listing page with pagination. * Shows posts with featured images in a grid layout. * * Output: * - Bootstrap-styled grid * - Post thumbnails and titles * - Pagination * - Links to individual stories * * @since 1.0.0 * @return void */ public function custom_rewrite_rule_handler() { ?>' . esc_html(get_bloginfo('name')) . ''; ?>
' . esc_html__('View all stories', 'ai-auto-tool') . '
'; exit; } // Get post data $post_id = $page->ID; $post_title = get_the_title($post_id); $post_url = get_permalink($post_id); $post_content = get_the_content(null, false, $post_id); $url_thumb = get_the_post_thumbnail_url($post_id, 'large'); $post_date = get_post_time('Y-m-d\TH:i:sP', true, $post_id); $post_author = get_the_author_meta('display_name', get_post_field('post_author', $post_id)); // Extract images from content $image_urls = array(); $dom = new DOMDocument(); libxml_use_internal_errors(true); $dom->loadHTML(mb_convert_encoding($post_content, 'HTML-ENTITIES', 'UTF-8')); libxml_clear_errors(); $images = $dom->getElementsByTagName('img'); foreach ($images as $image) { $src = $image->getAttribute('src'); if ($src && filter_var($src, FILTER_VALIDATE_URL)) { $image_urls[] = $src; } } // Fallback to featured image if (empty($url_thumb) && !empty($image_urls)) { $url_thumb = $image_urls[0]; } // Split content into paragraphs $contenttext = strip_tags($post_content); $paragraphs = array_filter(explode('.', $contenttext), function($p) { return !empty(trim($p)); }); // Prepare structured data $article_body_content = implode("\n", $paragraphs); $article_body_unicode = json_encode($article_body_content, JSON_UNESCAPED_UNICODE); ?>