File size: 7,382 Bytes
70a185d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 |
<?php
/**
* Phi Shampoo Analyzer Diagnostic Tool
*
* This file can be accessed directly to test API connectivity and plugin functionality.
* URL: your-site.com/wp-content/plugins/phi-shampoo-plugin/diagnostic.php
*/
// Test if WordPress is loaded
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.');
}
// Security check - only admins can access
if (!current_user_can('manage_options')) {
die('You do not have permission to access this page.');
}
// Load plugin constants
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.');
}
}
// Set up the page
?>
<!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: #333;
}
pre {
background-color: #f5f5f5;
padding: 10px;
border-radius: 4px;
overflow-x: auto;
}
.test-section {
margin-bottom: 30px;
padding: 15px;
border: 1px solid #ddd;
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> |