Plugin Directory

Changeset 3228872


Ignore:
Timestamp:
01/26/2025 04:15:45 PM (14 months ago)
Author:
skeletai
Message:

Added the ability to export articles directly from Skelet to WordPress blog

Location:
skelet-ai/trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • skelet-ai/trunk/inc/ajax.php

    r3208329 r3228872  
    2020
    2121                $api_key = sanitize_text_field(wp_unslash($_POST['api_key']));
    22                 $response = wp_remote_get("https://skelet.ai/skeletapi/verify-api-key?apiKey=$api_key", array(
     22                $response = wp_remote_get("https://skelet.ai/api/endpoints/skelet-api/verify-api-key?apiKey=$api_key", array(
    2323                    'timeout' => 300, // Set timeout to 5 minutes
    2424                ));
     
    7979                $api_key = Skelet_Plugin_Status::get();
    8080
    81                 $args = array('timeout' => 500,);
    82                 $url = "https://skelet.ai/skeletapi/generate-content?apiKey=$api_key&keyword=$keywords&title=$title&goal=$goal&tone=$tone";
     81                $args = array('timeout' => 800,);
     82                $url = "https://skelet.ai/api/endpoints/skelet-api/generate-content?apiKey=$api_key&keyword=$keywords&title=$title&goal=$goal&tone=$tone";
    8383                $response = wp_remote_get($url, $args);
    8484
     
    154154add_action('wp_ajax_nopriv_skelet_generate_content', 'skelet_generate_content');
    155155
     156function skelet_publish_exported_article(WP_REST_Request $request) {
     157    $wordpress_api_key = Skelet_Plugin_Status::get();
     158    $request_data = $request->get_json_params();
     159    $api_key = isset($request_data['api_key']) ? sanitize_text_field($request_data['api_key']) : null;
     160
     161    if ($api_key !== $wordpress_api_key) {
     162        return new WP_REST_Response('Invalid API key', 403);
     163    }
     164
     165    $post_title = isset($request_data['post_title']) ? sanitize_text_field($request_data['post_title']) : null;
     166    $post_content = isset($request_data['post_content']) ? sanitize_textarea_field($request_data['post_content']) : null;
     167
     168    if (empty($post_title) || empty($post_content)) {
     169        return new WP_REST_Response('Post title and content are required', 400);
     170    }
     171
     172    $post_data = [
     173        'post_title'   => $post_title,
     174        'post_content' => $post_content,
     175        'post_status'  => 'draft',  // Set post status to draft
     176        'post_author'  => get_current_user_id(),  // Set the author of the post
     177        'post_type'    => 'post',  // Default post type
     178    ];
     179
     180    $post_id = wp_insert_post($post_data);
     181    if (is_wp_error($post_id)) {
     182        return new WP_REST_Response('Error creating the post', 500);
     183    }
     184
     185    $post_image_url = isset($request_data['post_image']) ? esc_url_raw($request_data['post_image']) : null;
     186    if (!empty($post_image_url)) {
     187        $image_data = file_get_contents($post_image_url);
     188   
     189        if ($image_data === false) {
     190            return new WP_REST_Response('Error downloading the image', 500);
     191        }
     192   
     193        $upload_dir = wp_upload_dir();
     194        $upload_path = $upload_dir['path'] . '/' . basename($post_image_url);
     195   
     196        if (file_put_contents($upload_path, $image_data) === false) {
     197            return new WP_REST_Response('Error saving the image', 500);
     198        }
     199   
     200        $filetype = wp_check_filetype($upload_path, null);
     201        if (!$filetype['type']) {
     202            return new WP_REST_Response('Invalid file type', 400);
     203        }
     204   
     205        $attachment = [
     206            'post_mime_type' => $filetype['type'],
     207            'post_title'     => sanitize_file_name(basename($upload_path)),
     208            'post_content'   => '',
     209            'post_status'    => 'inherit',
     210        ];
     211   
     212        $attachment_id = wp_insert_attachment($attachment, $upload_path, $post_id);
     213        if (is_wp_error($attachment_id)) {
     214            return new WP_REST_Response('Error inserting the attachment: ' . $attachment_id->get_error_message(), 500);
     215        }
     216   
     217        require_once ABSPATH . 'wp-admin/includes/image.php';
     218        $attachment_metadata = wp_generate_attachment_metadata($attachment_id, $upload_path);
     219   
     220        if (is_wp_error($attachment_metadata)) {
     221            return new WP_REST_Response('Error generating attachment metadata: ' . $attachment_metadata->get_error_message(), 500);
     222        }
     223   
     224        wp_update_attachment_metadata($attachment_id, $attachment_metadata);
     225        set_post_thumbnail($post_id, $attachment_id);
     226    }
     227
     228    return new WP_REST_Response('Post created successfully in draft', 200);
     229}
     230
    156231?>
  • skelet-ai/trunk/inc/functions.php

    r3208329 r3228872  
    11<?php
    22if ( ! defined( 'ABSPATH' ) ) exit;
    3 
    4 /**
    5  * Enqueue stylesheets
    6  *
    7 * @author Skelet Ai
    8 * @version 1.0
    9 * @since 17 Jul 2024
    10  */
    113
    124// Css
     
    2820add_action('admin_enqueue_scripts', 'skelet_custom_scripts');
    2921
     22add_action('rest_api_init', function () {
     23    register_rest_route('skelet/v1', '/publish_post', array(
     24        'methods'             => 'POST',
     25        'callback'            => 'skelet_publish_exported_article',
     26    ));
     27});
     28
     29add_action('rest_pre_serve_request', function () {
     30    $allowed_origins = [
     31        'http://localhost:3000',
     32        'https://skelet.ai',
     33        'https://skeletai.vercel.app',
     34    ];
     35
     36    // Get the origin of the request
     37    $origin = isset($_SERVER['HTTP_ORIGIN']) ? $_SERVER['HTTP_ORIGIN'] : '';
     38
     39    // Check if the origin is in the allowed origins list
     40    if (in_array($origin, $allowed_origins)) {
     41        // Set the Access-Control-Allow-Origin header only if the origin is allowed
     42        header('Access-Control-Allow-Origin: ' . $origin);
     43    }
     44
     45    // Allow specific methods (POST, GET, etc.)
     46    header('Access-Control-Allow-Methods: POST'); // Allow POST requests
     47
     48    // Allow specific headers
     49    header('Access-Control-Allow-Headers: api_key, Content-Type, Authorization'); // Added Authorization header for security
     50
     51    // Allow credentials (if necessary, e.g., for cookies or authentication)
     52    header('Access-Control-Allow-Credentials: true');
     53
     54    // Handle preflight OPTIONS request
     55    if ($_SERVER['REQUEST_METHOD'] === 'OPTIONS') {
     56        status_header(200); // Send a 200 OK response for OPTIONS request
     57        exit;
     58    }
     59});
     60
  • skelet-ai/trunk/readme.txt

    r3208329 r3228872  
    11=== Skelet Ai ===
    22Contributors: skeletai
    3 Tags: AI content, SEO, blog, content generation, automation
     3Tags: AI content, ai, SEO, blog, content generation, automation, post generator, blog generator, artificial intelligence, export blog, article export, best content generator, AI writing, content creator
    44Requires at least: 5.0
    55Tested up to: 6.6.1
    66Requires PHP: 7.4
    7 Stable tag: 1.3
     7Stable tag: 1.4
    88License: GPLv2 or later
    99License URI: https://www.gnu.org/licenses/gpl-2.0.html
     
    1111== Description ==
    1212
    13 Transform Your Content Creation Process with Skelet Ai
     13Effortlessly create high-quality content with our AI Content Generator plugin for WordPress.
    1414
    15 Skelet Ai is an advanced AI-powered WordPress plugin designed to create high-quality, fully-optimized blog posts with just a few clicks. Whether you're a blogger, marketer, or business owner, this plugin is your all-in-one solution for generating engaging content that ranks well on search engines.
     15Generate blog posts, social media copy, product descriptions, and more in seconds using advanced AI technology. Save time, boost creativity, and improve SEO directly from your WordPress dashboard!
    1616
    1717== Key Features ==
     
    4848* Updates and enhancements for improved functionality.
    4949
     50= 1.4 =
     51* Added the ability to export articles directly from Skelet to your WordPress blog.
     52
    5053== Upgrade Notice ==
    5154
    5255= 1.3 =
    53 This version includes updates and enhancements for improved functionality.
     56* This version includes updates and enhancements for improved functionality.
     57
     58= 1.4 =
     59* Added the ability to export articles directly from Skelet to your WordPress blog.
    5460
    5561== License ==
  • skelet-ai/trunk/skelet-ai.php

    r3208329 r3228872  
    44 * Plugin URI: https://skelet.ai
    55 * Description: Tap into ever-growing creativity with our AI Generator library.
    6  * Version: 1.3
     6 * Version: 1.4
    77 * Author: skeletai
    88 * Author URI: https://profiles.wordpress.org/skeletai
Note: See TracChangeset for help on using the changeset viewer.