Changeset 3228872
- Timestamp:
- 01/26/2025 04:15:45 PM (14 months ago)
- Location:
- skelet-ai/trunk
- Files:
-
- 4 edited
-
inc/ajax.php (modified) (3 diffs)
-
inc/functions.php (modified) (2 diffs)
-
readme.txt (modified) (3 diffs)
-
skelet-ai.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
skelet-ai/trunk/inc/ajax.php
r3208329 r3228872 20 20 21 21 $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( 23 23 'timeout' => 300, // Set timeout to 5 minutes 24 24 )); … … 79 79 $api_key = Skelet_Plugin_Status::get(); 80 80 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"; 83 83 $response = wp_remote_get($url, $args); 84 84 … … 154 154 add_action('wp_ajax_nopriv_skelet_generate_content', 'skelet_generate_content'); 155 155 156 function 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 156 231 ?> -
skelet-ai/trunk/inc/functions.php
r3208329 r3228872 1 1 <?php 2 2 if ( ! defined( 'ABSPATH' ) ) exit; 3 4 /**5 * Enqueue stylesheets6 *7 * @author Skelet Ai8 * @version 1.09 * @since 17 Jul 202410 */11 3 12 4 // Css … … 28 20 add_action('admin_enqueue_scripts', 'skelet_custom_scripts'); 29 21 22 add_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 29 add_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 1 1 === Skelet Ai === 2 2 Contributors: skeletai 3 Tags: AI content, SEO, blog, content generation, automation3 Tags: 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 4 4 Requires at least: 5.0 5 5 Tested up to: 6.6.1 6 6 Requires PHP: 7.4 7 Stable tag: 1. 37 Stable tag: 1.4 8 8 License: GPLv2 or later 9 9 License URI: https://www.gnu.org/licenses/gpl-2.0.html … … 11 11 == Description == 12 12 13 Transform Your Content Creation Process with Skelet Ai 13 Effortlessly create high-quality content with our AI Content Generator plugin for WordPress. 14 14 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. 15 Generate 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! 16 16 17 17 == Key Features == … … 48 48 * Updates and enhancements for improved functionality. 49 49 50 = 1.4 = 51 * Added the ability to export articles directly from Skelet to your WordPress blog. 52 50 53 == Upgrade Notice == 51 54 52 55 = 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. 54 60 55 61 == License == -
skelet-ai/trunk/skelet-ai.php
r3208329 r3228872 4 4 * Plugin URI: https://skelet.ai 5 5 * Description: Tap into ever-growing creativity with our AI Generator library. 6 * Version: 1. 36 * Version: 1.4 7 7 * Author: skeletai 8 8 * Author URI: https://profiles.wordpress.org/skeletai
Note: See TracChangeset
for help on using the changeset viewer.