|
|
<?php |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (file_exists('../../../../wp-load.php')) { |
|
|
require_once('../../../../wp-load.php'); |
|
|
} else { |
|
|
die('Could not find WordPress. Make sure this file is in the plugin directory.'); |
|
|
} |
|
|
|
|
|
|
|
|
if (!current_user_can('manage_options')) { |
|
|
die('You do not have permission to access this page.'); |
|
|
} |
|
|
|
|
|
|
|
|
if (!defined('PHI_SHAMPOO_TEXT_MODEL')) { |
|
|
if (file_exists('./phi-shampoo-analyzer.php')) { |
|
|
include_once('./phi-shampoo-analyzer.php'); |
|
|
} else { |
|
|
die('Could not find the main plugin file.'); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
?> |
|
|
<!DOCTYPE html> |
|
|
<html> |
|
|
<head> |
|
|
<meta charset="utf-8"> |
|
|
<meta name="viewport" content="width=device-width, initial-scale=1"> |
|
|
<title>Phi Shampoo Analyzer Diagnostic</title> |
|
|
<style> |
|
|
body { |
|
|
font-family: Arial, sans-serif; |
|
|
line-height: 1.6; |
|
|
margin: 20px; |
|
|
max-width: 900px; |
|
|
margin: 0 auto; |
|
|
padding: 20px; |
|
|
} |
|
|
h1, h2 { |
|
|
color: |
|
|
} |
|
|
pre { |
|
|
background-color: |
|
|
padding: 10px; |
|
|
border-radius: 4px; |
|
|
overflow-x: auto; |
|
|
} |
|
|
.test-section { |
|
|
margin-bottom: 30px; |
|
|
padding: 15px; |
|
|
border: 1px solid |
|
|
border-radius: 4px; |
|
|
} |
|
|
.success { |
|
|
color: green; |
|
|
font-weight: bold; |
|
|
} |
|
|
.error { |
|
|
color: red; |
|
|
font-weight: bold; |
|
|
} |
|
|
</style> |
|
|
</head> |
|
|
<body> |
|
|
<h1>Phi Shampoo Analyzer Diagnostic Tool</h1> |
|
|
|
|
|
<div class="test-section"> |
|
|
<h2>Plugin Information</h2> |
|
|
<p><strong>Plugin Version:</strong> <?php echo defined('PHI_SHAMPOO_VERSION') ? PHI_SHAMPOO_VERSION : 'Not defined'; ?></p> |
|
|
<p><strong>Text Model:</strong> <?php echo defined('PHI_SHAMPOO_TEXT_MODEL') ? PHI_SHAMPOO_TEXT_MODEL : 'Not defined'; ?></p> |
|
|
<p><strong>Vision Model:</strong> <?php echo defined('PHI_SHAMPOO_VISION_MODEL') ? PHI_SHAMPOO_VISION_MODEL : 'Not defined'; ?></p> |
|
|
<p><strong>Text API URL:</strong> <?php echo defined('PHI_SHAMPOO_HF_TEXT_API_URL') ? PHI_SHAMPOO_HF_TEXT_API_URL : 'Not defined'; ?></p> |
|
|
<p><strong>Vision API URL:</strong> <?php echo defined('PHI_SHAMPOO_HF_VISION_API_URL') ? PHI_SHAMPOO_HF_VISION_API_URL : 'Not defined'; ?></p> |
|
|
<p><strong>API Token:</strong> <?php |
|
|
$api_token = function_exists('phi_shampoo_get_api_token') ? phi_shampoo_get_api_token() : ''; |
|
|
echo !empty($api_token) ? 'Configured' : '<span class="error">Not configured</span>'; |
|
|
?></p> |
|
|
</div> |
|
|
|
|
|
<div class="test-section"> |
|
|
<h2>WordPress Environment</h2> |
|
|
<p><strong>WordPress Version:</strong> <?php echo get_bloginfo('version'); ?></p> |
|
|
<p><strong>PHP Version:</strong> <?php echo phpversion(); ?></p> |
|
|
<p><strong>Analyzer Page:</strong> |
|
|
<?php |
|
|
$page_id = get_option('phi_shampoo_analyzer_page_id'); |
|
|
if ($page_id) { |
|
|
echo 'Created (ID: ' . $page_id . ') - <a href="' . get_permalink($page_id) . '" target="_blank">View Page</a>'; |
|
|
} else { |
|
|
echo '<span class="error">Not created</span>'; |
|
|
} |
|
|
?> |
|
|
</p> |
|
|
</div> |
|
|
|
|
|
<div class="test-section"> |
|
|
<h2>API Connection Test</h2> |
|
|
|
|
|
<h3>Text Model Test</h3> |
|
|
<?php |
|
|
// Test the text model API |
|
|
if (!defined('PHI_SHAMPOO_HF_TEXT_API_URL') || !function_exists('phi_shampoo_get_api_token')) { |
|
|
echo '<p class="error">API functions not defined.</p>'; |
|
|
} else { |
|
|
$api_url = PHI_SHAMPOO_HF_TEXT_API_URL; |
|
|
$api_token = phi_shampoo_get_api_token(); |
|
|
|
|
|
if (empty($api_token)) { |
|
|
echo '<p class="error">API token not configured. Please go to the <a href="' . admin_url('admin.php?page=phi-shampoo-settings') . '">Settings Page</a> to configure your token.</p>'; |
|
|
} else { |
|
|
$response = wp_remote_post($api_url, array( |
|
|
'headers' => array( |
|
|
'Authorization' => 'Bearer ' . $api_token, |
|
|
'Content-Type' => 'application/json' |
|
|
), |
|
|
'body' => json_encode(array( |
|
|
'inputs' => 'Test prompt: Analyze these ingredients: Water, Glycerin', |
|
|
'parameters' => array( |
|
|
'max_new_tokens' => 50, |
|
|
'temperature' => 0.7 |
|
|
) |
|
|
)), |
|
|
'timeout' => 30 |
|
|
)); |
|
|
|
|
|
if (is_wp_error($response)) { |
|
|
echo '<p class="error">Error: ' . $response->get_error_message() . '</p>'; |
|
|
} else { |
|
|
$status = wp_remote_retrieve_response_code($response); |
|
|
$body = wp_remote_retrieve_body($response); |
|
|
|
|
|
echo '<p><strong>Status Code:</strong> ' . $status . '</p>'; |
|
|
|
|
|
if ($status === 200) { |
|
|
echo '<p class="success">Text API connection successful!</p>'; |
|
|
echo '<p><strong>Response Preview:</strong></p>'; |
|
|
echo '<pre>' . htmlspecialchars(substr($body, 0, 300)) . '...</pre>'; |
|
|
} else { |
|
|
echo '<p class="error">API returned non-200 status code.</p>'; |
|
|
echo '<p><strong>Response:</strong></p>'; |
|
|
echo '<pre>' . htmlspecialchars($body) . '</pre>'; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
?> |
|
|
|
|
|
<h3>Vision Model Test</h3> |
|
|
<p>Note: Vision model test requires an image upload. To test, please use the main plugin interface.</p> |
|
|
</div> |
|
|
|
|
|
<div class="test-section"> |
|
|
<h2>File Structure Check</h2> |
|
|
<?php |
|
|
$required_files = array( |
|
|
'phi-shampoo-analyzer.php' => 'Main plugin file', |
|
|
'assets/css/style.css' => 'CSS styles', |
|
|
'assets/js/phi-shampoo.js' => 'JavaScript functionality' |
|
|
); |
|
|
|
|
|
$all_files_exist = true; |
|
|
|
|
|
foreach ($required_files as $file => $description) { |
|
|
$file_path = dirname(__FILE__) . '/' . $file; |
|
|
$exists = file_exists($file_path); |
|
|
|
|
|
echo '<p>'; |
|
|
echo '<strong>' . $file . ':</strong> '; |
|
|
if ($exists) { |
|
|
echo '<span class="success">Found</span>'; |
|
|
} else { |
|
|
echo '<span class="error">Missing</span>'; |
|
|
$all_files_exist = false; |
|
|
} |
|
|
echo ' - ' . $description; |
|
|
echo '</p>'; |
|
|
} |
|
|
|
|
|
if ($all_files_exist) { |
|
|
echo '<p class="success">All required files are present.</p>'; |
|
|
} else { |
|
|
echo '<p class="error">Some required files are missing.</p>'; |
|
|
} |
|
|
?> |
|
|
</div> |
|
|
</body> |
|
|
</html> |