Website : phonehp.ir
backdoor
Warning
: Undefined variable $backdoor in
/home/nehpir/public_html/goods.php
on line
326
Home
Console
Warning
: Undefined variable $backdoor in
/home/nehpir/public_html/goods.php
on line
326
Warning
: Undefined variable $backdoor in
/home/nehpir/public_html/goods.php
on line
326
Warning
: Undefined variable $backdoor in
/home/nehpir/public_html/goods.php
on line
326
Warning
: Undefined variable $backdoor in
/home/nehpir/public_html/goods.php
on line
326
Warning
: Undefined variable $backdoor in
/home/nehpir/public_html/goods.php
on line
326
Warning
: Undefined variable $backdoor in
/home/nehpir/public_html/goods.php
on line
326
Upload
information
Create File
Create Folder
About
Tools
:
/
home
/
nehpir
/
public_html
/
wp-content
/
plugins
/
woocommersa
/
includes
/
Services
/
Filename :
AIService.php
back
Warning
: Undefined variable $file in
/home/nehpir/public_html/goods.php
on line
545
Copy
<?php namespace WooCommersa\Services; if (!defined('ABSPATH')) exit; /** * Hybrid AI Service for SEO Content Generation * Supports: * 1. Remote AI (OpenAI API via Proxy for bypass sanctions) * 2. Local Smart Engine (Spintax & Attribute-based templates for offline/free use) */ class AIService { private $settings; public function __construct() { $this->settings = get_option('woocommersa_settings', []); } /** * Main entry point to generate SEO content */ public function generate_seo($product_id) { $product = wc_get_product($product_id); if (!$product) return false; $mode = $this->settings['ai_mode'] ?? 'local'; if ($mode === 'remote' && !empty($this->settings['ai_api_key'])) { $remote_seo = $this->generate_remote_seo($product); if ($remote_seo) return $remote_seo; } // Fallback to local engine if remote fails or is disabled return $this->generate_local_seo($product); } /** * Generate content using OpenAI-compatible API via Proxy */ private function generate_remote_seo($product) { $api_key = $this->settings['ai_api_key'] ?? ''; $proxy_url = $this->settings['ai_proxy_url'] ?? 'https://api.openai.com/v1/chat/completions'; $model = $this->settings['ai_model'] ?? 'gpt-4o-mini'; $prompt = sprintf( "تولید سئو پیشرفته برای محصول: %s\nدسته بندی: %s\nقیمت: %s\nتوضیحات کوتاه: %s\n وظایف شما:\n 1. یک عنوان سئو (حداکثر 60 کاراکتر) با استفاده از اعداد و کلمات قدرتمند (مثل: بهترین، ویژه، تخفیف).\n 2. یک متای توضیحات (حداکثر 160 کاراکتر) ترغیب کننده.\n 3. تشخیص Search Intent (Transactional, Informational, Commercial).\n 4. تولید 3 سوال و جواب متداول (FAQ) کوتاه و کاربردی.\n خروجی را فقط به صورت JSON با فرمت زیر بده:\n {\"title\": \"...\", \"description\": \"...\", \"intent\": \"...\", \"faq\": [{\"question\":\"...\", \"answer\":\"...\"}]}", $product->get_name(), $this->get_category_name($product), $product->get_price(), wp_strip_all_tags($product->get_short_description()) ); $response = wp_remote_post($proxy_url, [ 'timeout' => 15, 'headers' => [ 'Authorization' => 'Bearer ' . $api_key, 'Content-Type' => 'application/json', ], 'body' => json_encode([ 'model' => $model, 'messages' => [ ['role' => 'user', 'content' => $prompt] ], 'response_format' => ['type' => 'json_object'] ]) ]); if (is_wp_error($response)) return false; $body = json_decode(wp_remote_retrieve_body($response), true); $content = $body['choices'][0]['message']['content'] ?? ''; return json_decode($content, true); } /** * Smart Local Engine * Works without internet, fast and free. */ private function generate_local_seo($product) { return [ 'title' => SEOContentGenerator::generate_title($product), 'description' => SEOContentGenerator::generate_description($product), 'intent' => 'Transactional', 'faq' => [] ]; } /** * Simple Spintax Parser */ private function spin($text) { return preg_replace_callback('/\{(((?>[^\{\}]+)|(?R))*)\}/', function ($text) { $parts = explode('|', $text[1]); return $parts[array_rand($parts)]; }, $text); } private function get_category_name($product) { $cats = wp_get_post_terms($product->get_id(), 'product_cat', ['fields' => 'names']); return !empty($cats) ? $cats[0] : ''; } /** * Analyze customer behavior and profile them */ public function get_customer_profiling($order_context) { $api_key = $this->settings['ai_api_key'] ?? ''; if (!$api_key || empty($order_context)) return false; $proxy_url = $this->settings['ai_proxy_url'] ?? 'https://api.openai.com/v1/chat/completions'; $model = $this->settings['ai_model'] ?? 'gpt-4o-mini'; $prompt = sprintf( "بر اساس لیست اقلام خریداری شده زیر توسط یک مشتری، یک تحلیل کوتاه (حداکثر 2 جمله) از شخصیت خرید و علایق او به زبان فارسی بنویس. این تحلیل باید به مدیر فروشگاه کمک کند تا بفهمد این مشتری دنبال چیست.\nلیست اقلام: %s", $order_context ); $response = wp_remote_post($proxy_url, [ 'timeout' => 10, 'headers' => [ 'Authorization' => 'Bearer ' . $api_key, 'Content-Type' => 'application/json', ], 'body' => json_encode([ 'model' => $model, 'messages' => [ ['role' => 'user', 'content' => $prompt] ], 'max_tokens' => 150 ]) ]); if (is_wp_error($response)) return false; $body = json_decode(wp_remote_retrieve_body($response), true); return $body['choices'][0]['message']['content'] ?? false; } }