Add PSR HTTP Message Interfaces and Dependencies

- Implemented StreamInterface, UploadedFileInterface, and UriInterface as per PSR standards.
- Added getallheaders function to retrieve HTTP headers in a compatible manner.
- Included LICENSE files for ralouphie/getallheaders and symfony/deprecation-contracts.
- Introduced function for triggering deprecation notices in Symfony.
This commit is contained in:
2025-12-28 12:44:00 +01:00
parent cf600ae727
commit cd264483f8
410 changed files with 60841 additions and 16 deletions

View File

@@ -0,0 +1,58 @@
<div class="atfpp-dashboard-ai-translations">
<div class="atfpp-dashboard-ai-translations-container">
<div class="header">
<h1><?php echo esc_html__('AI Translations', $text_domain); ?></h1>
</div>
<p class="description">
<?php echo esc_html__('Experience the power of AI for faster, more accurate translations. Choose from multiple AI providers to translate your content efficiently.', $text_domain); ?>
</p>
<div class="atfpp-dashboard-translations">
<?php
$ai_translations = [
[
'logo' => 'geminiai-logo.png',
'alt' => 'Gemini AI',
'title' => esc_html__('AI Translations', $text_domain),
'description' => esc_html__('Leverage Gemini AI for seamless and context-aware translations.', $text_domain),
'icon' => 'gemini-translate.png',
'url' => 'https://docs.coolplugins.net/doc/translate-via-gemini-ai-polylang/?utm_source=atfp_plugin&utm_medium=inside&utm_campaign=docs&utm_content=ai_translations_gemini_pro'
],
[
'logo' => 'openai-translate-logo.png',
'alt' => 'OpenAI',
'title' => esc_html__('AI Translations', $text_domain),
'description' => esc_html__('Leverage OpenAI for seamless and context-aware translations.', $text_domain),
'icon' => 'open-ai-translate.png',
'url' => 'https://docs.coolplugins.net/doc/translate-via-open-ai-polylang/?utm_source=atfp_plugin&utm_medium=inside&utm_campaign=docs&utm_content=ai_translations_openai_pro'
],
[
'logo' => 'chrome-built-in-ai-logo.png',
'alt' => 'Chrome Built-in AI',
'title' => esc_html__('Chrome Built-in AI', $text_domain),
'description' => esc_html__('Utilize Chrome\'s built-in AI for seamless translation experience.', $text_domain),
'icon' => 'chrome-ai-translate.png',
'url' => 'https://docs.coolplugins.net/doc/chrome-ai-translation-polylang/?utm_source=atfp_plugin&utm_medium=inside&utm_campaign=docs&utm_content=ai_translations_chrome_pro'
]
];
foreach ($ai_translations as $translation) {
?>
<div class="atfpp-dashboard-translation-card">
<div class="logo">
<img src="<?php echo esc_url(ATFPP_URL . 'assets/images/' . $translation['logo']); ?>"
alt="<?php echo esc_attr($translation['alt']); ?>">
</div>
<h3><?php echo esc_html($translation['title']); ?></h3>
<p><?php echo esc_html($translation['description']); ?></p>
<div class="play-btn-container">
<a href="<?php echo esc_url($translation['url']); ?>" target="_blank">
<img src="<?php echo esc_url(ATFPP_URL . 'admin/atfpp-dashboard/images/' . $translation['icon']); ?>" alt="<?php echo esc_attr($translation['alt']); ?>">
</a>
</div>
</div>
<?php
}
?>
</div>
</div>
</div>

View File

@@ -0,0 +1,119 @@
<?php
if(!defined('ABSPATH')) exit;
if(!class_exists('ATFP_Custom_Fields')) {
class ATFP_Custom_Fields {
private static $instance = null;
private $atfp_saved_fields = array();
private $atfp_allowed_fields = array();
public static function get_instance() {
if(null === self::$instance) {
self::$instance = new self();
}
return self::$instance;
}
private function __construct() {
// wp:phpcs:ignore Wordpress.security Nonce verification is not required here
$tab=isset($_GET['tab']) ? sanitize_text_field(wp_unslash($_GET['tab'])) : '';
$page=isset($_GET['page']) ? sanitize_text_field(wp_unslash($_GET['page'])) : '';
if('custom-fields' === $tab && 'polylang-atfpp-dashboard' === $page){
$this->atfpp_render_custom_fields_page();
$this->enqueue_editor_assets();
}
}
public function enqueue_editor_assets() {
wp_enqueue_script( 'atfp-datatable-script', ATFPP_URL . 'assets/js/dataTables.min.js', array(), ATFPP_V, true );
wp_enqueue_script( 'atfp-datatable-style', ATFPP_URL . 'assets/js/dataTables.min.js', array(), ATFPP_V, true );
wp_enqueue_style( 'atfp-editor-custom-fields', ATFPP_URL . 'assets/css/atfp-custom-data-table.css', array(), ATFPP_V );
wp_enqueue_script( 'atfp-editor-custom-fields', ATFPP_URL . 'assets/js/atfp-custom-data-table.js', array('atfp-datatable-script'), ATFPP_V, true );
wp_localize_script( 'atfp-editor-custom-fields', 'atfpCustomTableDataObject', array(
'admin_url' => esc_url(admin_url('admin-ajax.php')),
'save_button_handler' => 'atfp_update_custom_fields_content',
'save_button_nonce' => wp_create_nonce('atfp_save_custom_fields'),
'save_button_enabled'=>true,
'save_button_text'=>__('Save Fields', 'autopoly-ai-translation-for-polylang-pro'),
'save_button_class'=>'atfp-save-custom-fields',
) );
}
public function atfpp_render_custom_fields_page() {
$this->atfp_allowed_fields = ATFPP_Helper::get_instance()->get_allowed_custom_fields();
$s_no = 1;
?>
<div class="atfp-custom-data-table-wrapper atfp-custom-fields">
<h3><?php echo __('Custom Fields Translation Settings', 'autopoly-ai-translation-for-polylang-pro'); ?>
<br>
<p><?php echo sprintf(esc_html__('Select which custom fields will be translated by %s.', 'autopoly-ai-translation-for-polylang-pro'), 'AutoPoly'); ?></p>
</h3>
<button class="button button-primary atfp-save-custom-fields"><?php esc_html_e( 'Save Fields', 'autopoly-ai-translation-for-polylang-pro' ); ?></button>
<div class="atfp-custom-data-table-filters">
<div class="atfp-filter-tab" data-column="3" data-default="all">
<label for="atfp-fields-filter"><?php esc_html_e( 'Show Fields:', 'autopoly-ai-translation-for-polylang-pro' ); ?></label>
<select id="atfp-fields-filter" name="atfp_fields_filter">
<option value="all"><?php esc_html_e( 'All', 'autopoly-ai-translation-for-polylang-pro' ); ?></option>
<option value="supported"><?php esc_html_e( 'Translatable', 'autopoly-ai-translation-for-polylang-pro' ); ?></option>
<option value="unsupported"><?php esc_html_e( 'Non-Translatable', 'autopoly-ai-translation-for-polylang-pro' ); ?></option>
</select>
</div>
<div class="atfp-filter-tab" data-column="2" data-default="all">
<label for="atfp-fields-filter"><?php esc_html_e( 'Type:', 'autopoly-ai-translation-for-polylang-pro' ); ?></label>
<select id="atfp-fields-value-type-filter" name="atfp_fields_value_type_filter">
<option value="all"><?php esc_html_e( 'All', 'autopoly-ai-translation-for-polylang-pro' ); ?></option>
<option value="string"><?php esc_html_e( 'String', 'autopoly-ai-translation-for-polylang-pro' ); ?></option>
<option value="array"><?php esc_html_e( 'Array', 'autopoly-ai-translation-for-polylang-pro' ); ?></option>
</select>
</div>
</div>
<div class="atfp-custom-table-section">
<div class="atfp-custom-table-lists">
<table class="atfp-custom-data-table-table" id="atfp-custom-datatable">
<thead>
<tr>
<th><?php esc_html_e( 'Sr.No', 'autopoly-ai-translation-for-polylang-pro' ); ?></th>
<th><?php esc_html_e( 'Field Name', 'autopoly-ai-translation-for-polylang-pro' ); ?></th>
<th><?php esc_html_e( 'Type', 'autopoly-ai-translation-for-polylang-pro' ); ?></th>
<th><?php esc_html_e( 'Status', 'autopoly-ai-translation-for-polylang-pro' ); ?></th>
<th align="center"><?php esc_html_e( 'Translate', 'autopoly-ai-translation-for-polylang-pro' ); ?></th>
</tr>
</thead>
<tbody>
<?php
$this->get_all_meta_fields_table();
?>
</tbody>
</table>
</div>
</div>
</div>
<?php
}
public function get_all_meta_fields_table() {
$meta_fields=ATFPP_Helper::get_instance()->get_custom_fields_data();
if($meta_fields && is_array($meta_fields)) {
$s_no = 1;
foreach($meta_fields as $meta_field => $value) {
$checked=isset($this->atfp_allowed_fields[$meta_field]) && !empty($this->atfp_allowed_fields[$meta_field]['status']) ? 'checked' : '';
$status=isset($value['status']) && !empty($value['status']) ? $value['status'] : 'Unsupported';
$value_type=isset($value['type']) && !empty($value['type']) ? $value['type'] : 'string';
echo '<tr>';
echo '<td>' . $s_no++ . '</td>';
echo '<td>' . $meta_field . '</td>';
echo '<td>' . $value_type . '</td>';
echo '<td>' . $status . '</td>';
echo '<td align="center"><input type="checkbox" name="atfp_fields_status" value="' . $meta_field . '" ' . $checked . '></td>';
echo '</tr>';
}
}
}
}
}
ATFP_Custom_Fields::get_instance();

View File

@@ -0,0 +1,59 @@
<div class="atfpp-dashboard-left-section">
<!-- Welcome Section -->
<div class="atfpp-dashboard-welcome">
<div class="atfpp-dashboard-welcome-video">
<a href="https://docs.coolplugins.net/doc/ai-translation-polylang-video-tutorials/?utm_source=atfp_plugin&utm_medium=inside&utm_campaign=docs&utm_content=dashboard_pro" target="_blank" class="atfpp-dashboard-video-link">
<img decoding="async" src="<?php echo esc_url(ATFPP_URL . 'admin/atfpp-dashboard/images/youtube-icon.svg'); ?>" class="play-icon" alt="play-icon">
<picture>
<source srcset="<?php echo esc_url(ATFPP_URL . 'admin/atfpp-dashboard/images/polylang-addon-video.png'); ?>" type="image/webp">
<img src="<?php echo esc_url(ATFPP_URL . 'admin/atfpp-dashboard/images/polylang-addon-video.png'); ?>" class="loco-video" alt="loco translate addon preview">
</picture>
</a>
</div>
</div>
<!-- Translation Providers -->
<div class="atfpp-dashboard-translation-providers">
<h3><?php echo esc_html__('Translation Providers', $text_domain); ?></h3>
<div class="atfpp-dashboard-providers-grid">
<?php
$providers = [
["Gemini AI", "geminiai-logo.png", "Pro", ["Unlimited Translations", "Fast Translations via AI", "Gemini API Key Required"], esc_url('https://docs.coolplugins.net/doc/translate-via-gemini-open-ai-openrouter/?utm_source=atfp_plugin&utm_medium=inside&utm_campaign=docs&utm_content=dashboard_gemini_pro'), esc_url('admin.php?page=polylang-atfpp-dashboard&tab=settings')],
["OpenAI", "openai-translate-logo.png", "Pro", ["Unlimited Translations", "Fast Translations via AI", "OpenAI API Key Required"], esc_url('https://docs.coolplugins.net/doc/translate-via-gemini-open-ai-openrouter/?utm_source=atfp_plugin&utm_medium=inside&utm_campaign=docs&utm_content=dashboard_openai_pro'), esc_url('admin.php?page=polylang-atfpp-dashboard&tab=settings')],
// ["Openrouter AI", "openrouter-translate-logo.png", "Pro", ["Unlimited Translations", "Fast Translations via AI", "Openrouter API Key Required"], esc_url('#'), esc_url('admin.php?page=polylang-atfpp-dashboard&tab=settings')],
["Google Translate", "google-translate-logo.png", "Pro", ["Unlimited Free Translations", "Fast & No API Key Required"], esc_url('https://docs.coolplugins.net/doc/google-translate-for-polylang/?utm_source=atfp_plugin&utm_medium=inside&utm_campaign=docs&utm_content=dashboard_google_pro')],
["Chrome Built-in AI", "chrome-built-in-ai-logo.png", "Free", ["Fast AI Translations in Browser", "Unlimited Free Translations", "Use Translation Modals"], esc_url('https://docs.coolplugins.net/docs/ai-translation-for-polylang/how-to-automatically-translate-your-website-content-via-chrome-ai/?utm_source=atfp_plugin&utm_medium=inside&utm_campaign=docs&utm_content=dashboard_chrome_pro')],
["Yandex Translate", "yandex-translate-logo.png", "Free", ["Unlimited Free Translations", "No API & No Extra Cost"], esc_url('https://docs.coolplugins.net/docs/ai-translation-for-polylang/how-to-automatically-translate-your-website-content-via-yandex/?utm_source=atfp_plugin&utm_medium=inside&utm_campaign=docs&utm_content=dashboard_yandex_pro')],
];
foreach ($providers as $index => $provider) {
?>
<div class="atfpp-dashboard-provider-card">
<div class="atfpp-dashboard-provider-header">
<a href="<?php echo esc_url($provider[4]); ?>" target="_blank">
<img src="<?php echo esc_url(ATFPP_URL . 'assets/images/' . $provider[1]); ?>"
alt="<?php echo esc_html($provider[0]); ?>">
</a>
</div>
<h4><?php echo esc_html($provider[0]); ?></h4>
<ul>
<?php foreach ($provider[3] as $feature) { ?>
<li>✅ <?php echo esc_html($feature); ?></li>
<?php } ?>
</ul>
<div class="atfpp-dashboard-provider-buttons">
<a href="<?php echo esc_url($provider[4]); ?>" class="atfpp-dashboard-btn" target="_blank">Docs</a>
<?php if (isset($provider[5])) { ?>
<a href="<?php echo esc_url($provider[5]); ?>" class="atfpp-dashboard-btn">Settings</a>
<?php } ?>
</div>
</div>
<?php
}
?>
</div>
</div>
</div>

View File

@@ -0,0 +1,29 @@
<div class="atfpp-dashboard-info">
<div class="atfpp-dashboard-info-links">
<p>
<?php echo esc_html__('Made with ❤️ by', $text_domain); ?>
<span class="logo">
<a href="https://coolplugins.net/?utm_source=atfp_plugin&utm_medium=inside&utm_campaign=author_page&utm_content=dashboard_footer_pro" target="_blank">
<img src="<?php echo esc_url(ATFPP_URL . 'admin/atfpp-dashboard/images/cool-plugins-logo-black.svg'); ?>" alt="<?php esc_attr_e('Cool Plugins Logo', $text_domain); ?>">
</a>
</span>
</p>
<a href="https://coolplugins.net/support/?utm_source=atfp_plugin&utm_medium=inside&utm_campaign=support&utm_content=dashboard_footer_pro" target="_blank"><?php echo esc_html__('Support', $text_domain); ?></a> |
<a href="https://docs.coolplugins.net/docs/ai-translation-for-polylang/?utm_source=atfp_plugin&utm_medium=inside&utm_campaign=docs&utm_content=dashboard_footer_pro" target="_blank"><?php echo esc_html__('Docs', $text_domain); ?></a>
<div class="atfpp-dashboard-social-icons">
<?php
$social_links = [
['https://www.facebook.com/coolplugins/', 'facebook.svg', esc_html__('Facebook', $text_domain)],
['https://linkedin.com/company/coolplugins', 'linkedin.svg', esc_html__('Linkedin', $text_domain)],
['https://x.com/cool_plugins', 'twitter.svg', esc_html__('Twitter', $text_domain)],
['https://www.youtube.com/@cool_plugins', 'youtube.svg', esc_html__('YouTube Channel', $text_domain)]
];
foreach ($social_links as $link) {
echo '<a href="' . esc_url($link[0]) . '" target="_blank">
<img src="' . esc_url(ATFPP_URL . 'admin/atfpp-dashboard/images/' . $link[1]) . '" alt="' . esc_attr($link[2]) . '">
</a>';
}
?>
</div>
</div>
</div>

View File

@@ -0,0 +1,505 @@
<?php
$glossary_data = get_option('atfpp_glossary_data', []);
if (!is_array($glossary_data)) {
$glossary_data = [];
}
// --- Build $languages array ONCE at the top and reuse everywhere ---
$pll_languages_serialized = get_option('_transient_pll_languages_list');
$pll_languages = [];
if ($pll_languages_serialized) {
$pll_languages = maybe_unserialize($pll_languages_serialized);
}
$languages = [];
if (is_array($pll_languages)) {
foreach ($pll_languages as $pll_lang) {
$languages[] = [
'code' => $pll_lang['slug'],
'img' => $pll_lang['flag_url'],
'alt' => $pll_lang['name'],
'flag' => isset($pll_lang['flag']) ? $pll_lang['flag'] : '',
];
}
}
// Build a map for quick lookup by code
$language_map = [];
foreach ($languages as $lang) {
$language_map[$lang['code']] = $lang;
}
$grouped_entries = [];
foreach ($glossary_data as $entry) {
$term = $entry['original_term'];
$lang = $entry['original_language_code'];
$key = $term . '||' . $lang; // Composite key
if (!isset($grouped_entries[$key])) {
$grouped_entries[$key] = [
'term' => $term,
'original_language_code' => $lang,
'desc' => $entry['description'],
'type' => $entry['kind'],
'type_label' => ucfirst($entry['kind']),
'translations' => [],
];
}
if (!empty($entry['translations']) && is_array($entry['translations'])) {
foreach ($entry['translations'] as $translation) {
if (
$translation['target_language_code'] !== $lang &&
!empty($translation['translated_term']) &&
trim($translation['translated_term']) !== ''
) {
$grouped_entries[$key]['translations'][$translation['target_language_code']] = trim($translation['translated_term']);
}
}
}
}
// Sort glossary entries alphabetically by term (case-insensitive)
uksort($grouped_entries, 'strnatcasecmp');
// Collect unique original_language_codes and their counts
$language_codes = [];
foreach ($glossary_data as $entry) {
if (!empty($entry['original_language_code'])) {
$code = $entry['original_language_code'];
if (!isset($language_codes[$code])) {
$language_codes[$code] = 0;
}
$language_codes[$code]++;
}
}
$unique_language_codes = array_keys($language_codes);
// Compute the unique original language code
$unique_original_language_code = '';
if (count($unique_language_codes) === 1) {
$unique_original_language_code = reset($unique_language_codes);
}
// Add this for default selected language (first in the list)
$default_selected_lang = $unique_language_codes[0] ?? '';
// --- ADD THIS BLOCK ---
$term_original_lang = [];
foreach ($glossary_data as $entry) {
$term = $entry['original_term'];
$lang = $entry['original_language_code'];
// Initialize as array if not already
if (!isset($term_original_lang[$term])) {
$term_original_lang[$term] = [];
}
// Add only if not already present
if (!in_array($lang, $term_original_lang[$term])) {
$term_original_lang[$term][] = $lang;
}
}
// --- END ADD ---
// Count how many languages have entries
$language_codes_with_entries = [];
foreach ($grouped_entries as $entry) {
$code = $entry['original_language_code'];
if (!in_array($code, $language_codes_with_entries, true)) {
$language_codes_with_entries[] = $code;
}
}
$single_language_mode = count($language_codes_with_entries) === 1;
$single_language_code = $single_language_mode ? $language_codes_with_entries[0] : '';
?>
<style>
<?php foreach ($languages as $lang):
$code = esc_attr($lang['code']);
?>
.atfpp-glossary-table.atfpp-hide-lang-<?php echo $code; ?> th[data-lang="<?php echo $code; ?>"],
.atfpp-glossary-table.atfpp-hide-lang-<?php echo $code; ?> td[data-lang="<?php echo $code; ?>"] {
display: none !important;
}
<?php endforeach; ?>
</style>
<div class="atfpp-glossary">
<div class="atfpp-glossary-container">
<?php wp_nonce_field('atfpp_glossary_nonce', 'atfpp_glossary_nonce'); ?>
<header class="atfpp-header">
<h1><?php esc_html_e('Glossary', $text_domain); ?></h1>
<p><?php esc_html_e('Define how you want to translate or not translate important words and phrases.', $text_domain); ?></p>
<ul>
<li><?php esc_html_e('Specific translations you want to use;', $text_domain); ?></li>
<li><?php esc_html_e('Terms you want to exclude from being translated;', $text_domain); ?></li>
<li><?php esc_html_e('Additional context for each term.', $text_domain); ?></li>
</ul>
<a href="#"><?php esc_html_e('Learn more about adding and managing glossary terms.', $text_domain); ?></a>
</header>
<div class="atfpp-controls">
<input type="text" class="atfpp-search" placeholder="<?php esc_attr_e('Search', $text_domain); ?>" />
<select class="atfpp-glossary-type" name="glossary_type">
<option value=""><?php esc_html_e('Glossary Type', $text_domain); ?></option>
<option value="name"><?php esc_html_e('Name', $text_domain); ?></option>
<option value="general"><?php esc_html_e('General', $text_domain); ?></option>
</select>
<button class="atfpp-add-btn button button-primary">
<?php esc_html_e('Add glossary entry', $text_domain); ?>
</button>
<button class="atfpp-import-btn button button-primary">
<?php esc_html_e('Import glossary', $text_domain); ?>
</button>
<button class="atfpp-export-btn button button-primary">
<?php esc_html_e('Export glossary', $text_domain); ?>
</button>
<!-- Modal -->
<div id="atfpp-glossary-modal-add" class="atfpp-glossary-modal atfpp-hidden">
<div class="atfpp-glossary-modal-content-wrapper">
<button type="button" class="atfpp-modal-close-btn" aria-label="Close">&times;</button>
<div class="atfpp-glossary-modal-content">
<h2><?php esc_html_e('Add New Glossary Term', $text_domain); ?></h2>
<form id="atfpp-add-glossary-form">
<label for="atfpp-add-term"><?php esc_html_e('Term', $text_domain); ?></label>
<textarea id="atfpp-add-term" name="term" class="atfpp-add-term" required placeholder="<?php esc_attr_e('Enter the term to be translated', $text_domain); ?>"></textarea>
<div class="atfpp-translation-error"></div>
<label for="atfpp-add-desc"><?php esc_html_e('Description', $text_domain); ?></label>
<textarea id="atfpp-add-desc" name="description" class="atfpp-add-desc" rows="3" placeholder="<?php esc_attr_e('Add a description to provide context for translators', $text_domain); ?>"></textarea>
<div class="atfpp-translation-error"></div>
<label for="atfpp-add-source-lang"><?php esc_html_e('Original Language', $text_domain); ?></label>
<select id="atfpp-add-source-lang" name="source_lang" class="atfpp-add-source-lang" required>
<option value=""><?php esc_html_e('Select language', $text_domain); ?></option>
<?php foreach ($languages as $lang): ?>
<option value="<?php echo esc_attr($lang['code']); ?>">
<?php echo esc_html($lang['alt']); ?>
</option>
<?php endforeach; ?>
</select>
<label for="atfpp-add-type"><?php esc_html_e('Type', $text_domain); ?></label>
<select id="atfpp-add-type" name="type" class="atfpp-add-type" required>
<option value="general"><?php esc_html_e('General', $text_domain); ?></option>
<option value="name"><?php esc_html_e('Name', $text_domain); ?></option>
</select>
<div class="atfpp-add-translations atfpp-translations-grid">
<?php foreach ($languages as $lang): ?>
<div class="atfpp-translation-field atfpp-translation-field-<?php echo esc_attr($lang['code']); ?>">
<label>
<div class="atfpp-translation-label-row">
<?php if (!empty($lang['img'])): ?>
<img src="<?php echo esc_attr($lang['img']); ?>" alt="<?php echo esc_attr($lang['alt']); ?>" class="atfpp-lang-flag">
<?php endif; ?>
<span class="atfpp-lang-name"><?php echo esc_html($lang['alt']); ?></span>
<span class="atfpp-lang-translation-label"><?php esc_html_e('Translation', $text_domain); ?></span>
</div>
<textarea name="translation_<?php echo esc_attr($lang['code']); ?>" class="atfpp-add-translation" rows="2" placeholder="<?php esc_attr_e('Custom Translation', $text_domain); ?>"></textarea>
<div class="atfpp-translation-error"><?php esc_html_e('Too long, must be less than 240 characters', $text_domain); ?></div>
</label>
</div>
<?php endforeach; ?>
</div>
<div class="atfpp-glossary-modal-actions" style="margin-top: 18px;">
<span class="atfpp-glossary-modal-actions-left" style="cursor:pointer;"><?php esc_html_e('Cancel', $text_domain); ?></span>
<button type="submit" id="add-glossary-term-btn" class="button button-primary"><?php esc_html_e('Add Term', $text_domain); ?></button>
</div>
</form>
<div id="add-glossary-success" class="atfpp-import-success atfpp-hidden">
<div class="import-success-icon">
<img src="<?php echo ATFPP_URL . 'admin/atfpp-dashboard/images/success.svg'; ?>" alt="Success Icon" />
</div>
<div class="atfpp-import-success-message">
<?php esc_html_e('Glossary term added successfully!', $text_domain); ?>
</div>
<button id="atfpp-glossary-success-close" class="atfpp-close-button" type="button"><?php esc_html_e('Close', $text_domain); ?></button>
</div>
</div>
</div>
</div>
<!-- End Modal -->
<div id="atfpp-glossary-modal-import" class="atfpp-glossary-modal atfpp-hidden">
<div class="atfpp-glossary-modal-content-wrapper">
<button type="button" class="atfpp-modal-close-btn" aria-label="Close">&times;</button>
<div class="atfpp-glossary-modal-content">
<div class="atfpp-import-glossary" id="atfpp-import-glossary-ui">
<h2 class="atfpp-title"><?php esc_html_e( 'Import glossary', $text_domain ); ?></h2>
<label class="atfpp-upload-box" id="upload-label">
<input type="file" accept=".csv" id="atfpp-csv-upload" hidden>
<div class="atfpp-upload-area">
<img src="<?php echo ATFPP_URL . 'admin/atfpp-dashboard/images/csv.svg'; ?>" alt="CSV Icon" />
<span id="file-name-display"><?php esc_html_e( 'Select a CSV file to upload', $text_domain ); ?></span>
</div>
</label>
<a
href="<?php echo esc_url( ATFPP_URL . 'admin/atfpp-dashboard/sample-glossary.csv' ); ?>"
class="atfpp-download-link"
download="sample-glossary.csv">
<?php esc_html_e( 'Download sample glossary CSV file', $text_domain ); ?>
</a>
</div>
<!-- Success UI (hidden by default) -->
<div id="atfpp-import-success-ui" class="atfpp-hidden">
<div id="atfpp-import-success" class="atfpp-import-success">
<div class="import-success-icon">
<img src="<?php echo ATFPP_URL . 'admin/atfpp-dashboard/images/success.svg'; ?>" alt="Success Icon" />
</div>
<div class="import-success-file">
<span id="importing-file-label"><?php esc_html_e('Importing:', $text_domain); ?></span>
<span id="importing-file-name"></span>
</div>
<div class="atfpp-import-success-message">
<?php esc_html_e('Glossary terms imported successfully', $text_domain); ?>
</div>
<button class="atfpp-import-close-btn atfpp-close-button" type="button">Close</button>
</div>
</div>
</div>
</div>
</div>
</div>
<nav class="atfpp-alphabet" aria-label="<?php esc_attr_e('Glossary Alphabet Navigation', $text_domain); ?>">
<?php
$alphabet = array_merge(['123'], range('A', 'Z'), ['#&à']);
// Build a set of enabled letters based on $glossary_data
$enabled_letters = [];
foreach ($glossary_data as $entry) {
if (!empty($entry['original_term'])) {
$first = mb_substr(trim($entry['original_term']), 0, 1, 'UTF-8');
if (is_numeric($first)) {
$enabled_letters['123'] = true;
} elseif (preg_match('/[A-Za-z]/u', $first)) {
$enabled_letters[strtoupper($first)] = true;
} else {
$enabled_letters['#&à'] = true;
}
}
}
$first_active_set = false;
foreach ($alphabet as $char) {
$enabled = isset($enabled_letters[$char]) ? '' : 'disabled';
$active = '';
if ($enabled === '' && !$first_active_set) {
$first_active_set = true;
}
printf(
'<button class="atfpp-alphabet-btn%s" %s data-letter="%s">%s</button>',
$active,
$enabled,
esc_attr($char),
esc_html($char)
);
}
?>
</nav>
<!-- Language Filter Buttons -->
<?php
if (count($language_codes_with_entries) > 1): ?>
<div class="atfpp-language-filters">
<?php foreach ($language_codes_with_entries as $i => $code): ?>
<?php
// Skip if language code not in map
if (!isset($language_map[$code])) {
continue;
}
$lang = $language_map[$code];
?>
<button class="atfpp-lang-filter-btn<?php echo $i === 0 ? ' active' : ''; ?>" data-lang="<?php echo esc_attr($code); ?>">
<?php if (!empty($lang['img'])): ?>
<img src="<?php echo esc_url($lang['img']); ?>" alt="<?php echo esc_attr($lang['alt']); ?>" />
<?php endif; ?>
<?php echo esc_html($lang['alt']) . ' Terms'; ?>
</button>
<?php endforeach; ?>
</div>
<?php endif; ?>
<div class="atfpp-glossary-table-wrapper">
<?php if (!empty($grouped_entries)): ?>
<table class="atfpp-glossary-table" data-default-lang="<?php echo esc_attr($default_selected_lang); ?>">
<thead>
<tr>
<th colspan="2"></th>
<?php foreach ($languages as $lang): ?>
<?php if ($single_language_mode && $lang['code'] === $single_language_code) continue; ?>
<th colspan="2" title="<?php echo esc_attr($lang['alt']); ?>"
class="atfpp-lang-header atfpp-lang-col-<?php echo esc_attr($lang['code']); ?>"
data-lang="<?php echo esc_attr($lang['code']); ?>">
<?php
echo !empty($lang['flag'])
? $lang['flag']
: '<img src="' . esc_attr($lang['img']) . '" alt="' . esc_attr($lang['alt']) . '" />';
?>
</th>
<?php endforeach; ?>
<th class="atfpp-actions-cell">
<div class="atfpp-action-buttons-header">
<button class="atfpp-actions-header-btn" id="atfpp-actions-header-btn-left" title="Scroll Left">
<img src="<?php echo ATFPP_URL . 'admin/atfpp-dashboard/images/arrow-left.svg'; ?>" />
</button>
<button class="atfpp-actions-header-btn" id="atfpp-actions-header-btn-right" title="Scroll Right">
<img src="<?php echo ATFPP_URL . 'admin/atfpp-dashboard/images/arrow-right.svg'; ?>" />
</button>
</div>
</th>
</tr>
<tr>
<th>Glossary Entry</th>
<th>Type</th>
<?php foreach ($languages as $lang): ?>
<?php if ($single_language_mode && $lang['code'] === $single_language_code) continue; ?>
<th colspan="2" data-lang="<?php echo esc_attr($lang['code']); ?>">
<?php echo esc_html($lang['alt']); ?>
</th>
<?php endforeach; ?>
<th colspan="2">Actions</th>
</tr>
</thead>
<tbody>
<?php
// UTF-8 safe truncate helper
if ( ! function_exists('atfpp_truncate')) {
function atfpp_truncate( $str, $limit = 10 ) {
$str = (string) $str;
if (mb_strlen($str, 'UTF-8') > $limit) {
return mb_substr($str, 0, $limit, 'UTF-8') . '…';
}
return $str;
}
}
$editing_term = isset($_GET['edit']) ? $_GET['edit'] : null;
foreach ($grouped_entries as $composite_key => $data):
list($term, $original_language_code) = explode('||', $composite_key);
$first = mb_substr(trim($term), 0, 1, 'UTF-8');
$row_letter = is_numeric($first) ? '123' :
(preg_match('/[A-Za-z]/u', $first) ? strtoupper($first) : '#&à');
?>
<tr data-type="<?php echo esc_attr($data['type']); ?>"
data-original-language="<?php echo esc_attr($original_language_code); ?>"
data-term="<?php echo esc_attr($term); ?>"
data-letter="<?php echo esc_attr($row_letter); ?>">
<td>
<div class="atfpp-entry-title">
<?php echo esc_html($term); ?>
</div>
<div class="atfpp-entry-desc">
<?php echo esc_html($data['desc']); ?>
</div>
</td>
<td>
<span class="atfpp-type-badge <?php echo esc_attr($data['type']); ?>">
<?php echo esc_html(ucfirst($data['type'])); ?>
</span>
</td>
<?php
foreach ($languages as $lang):
if ($single_language_mode && $lang['code'] === $single_language_code) continue;
$translation = '';
$is_source = ($lang['code'] === $original_language_code);
?>
<td colspan="2" class="atfpp-lang-col-<?php echo esc_attr($lang['code']); ?>"
data-lang="<?php echo esc_attr($lang['code']); ?>"
data-is-source="<?php echo $is_source ? 'true' : 'false'; ?>">
<?php if ($is_source): ?>
<span class="atfpp-source-term">
<?php echo esc_html($term); ?>
</span>
<?php else: ?>
<?php
// Get translation from the new data structure
$translation = isset($data['translations'][$lang['code']]) ? $data['translations'][$lang['code']] : '';
?>
<?php if (!empty($translation) && trim($translation) !== ''): ?>
<?php $truncated = atfpp_truncate($translation, 7); ?>
<span class="atfpp-translated-term"
title="<?php echo esc_attr($translation); ?>"
data-full-text="<?php echo esc_attr($translation); ?>">
<?php echo esc_html($truncated); ?>
</span>
<?php else: ?>
<span class="atfpp-no-translation">
<button type="button" class="atfpp-edit-btn-svg"
data-term="<?php echo esc_attr(sanitize_text_field($term)); ?>"
data-source-lang="<?php echo esc_attr(sanitize_key($original_language_code)); ?>">
<img src="<?php echo ATFPP_URL . 'admin/atfpp-dashboard/images/file.svg'; ?>"
alt="<?php esc_attr_e('No translation', $text_domain); ?>" />
</button>
</span>
<?php endif; ?>
<?php endif; ?>
</td>
<?php endforeach; ?>
<td class="atfpp-actions-cell">
<div class="atfpp-action-buttons">
<button type="button" class="atfpp-edit-btn"
data-term="<?php echo esc_attr(sanitize_text_field($term)); ?>"
data-source-lang="<?php echo esc_attr(sanitize_key($original_language_code)); ?>">
<?php esc_html_e('Edit', $text_domain); ?>
</button>
<button type="button" class="atfpp-delete-btn"
data-term="<?php echo esc_attr(sanitize_text_field($term)); ?>"
data-source-lang="<?php echo esc_attr(sanitize_key($original_language_code)); ?>">
<?php esc_html_e('Delete', $text_domain); ?>
</button>
</div>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<?php else: ?>
<div id="atfpp-no-results">No glossary entries found.</div>
<?php endif; ?>
</div>
<!-- Move the template outside the table wrapper so it is always present -->
<script type="text/template" id="atfpp-glossary-edit-row-template">
<tr class="atfpp-glossary-edit-row">
<td>
<textarea class="atfpp-edit-term" rows="3" placeholder="<?php esc_attr_e('String Translation', $text_domain); ?>"><%= term %></textarea>
<textarea class="atfpp-edit-desc" rows="4" placeholder="<?php esc_attr_e('Example: The name of the add-on that allows translating strings', $text_domain); ?>"><%= desc %></textarea>
</td>
<td>
<select class="atfpp-edit-type">
<option value="general" <%= type === 'general' ? 'selected' : '' %>><?php esc_html_e('General', $text_domain); ?></option>
<option value="name" <%= type === 'name' ? 'selected' : '' %>><?php esc_html_e('Name', $text_domain); ?></option>
</select>
</td>
<% for (var i = 0; i < languages.length; i++) {
if (languages[i].code === source_lang) continue;
%>
<td colspan="2">
<textarea class="atfpp-edit-translation" data-lang="<%= languages[i].code %>" placeholder="<?php esc_attr_e('Custom Translation', $text_domain); ?>" rows="9"><%= translations[languages[i].code] || '' %></textarea>
<div class="atfpp-translation-error"><?php esc_html_e('Too long, must be less than 220 characters', $text_domain); ?></div>
</td>
<% } %>
<td colspan="2" class="atfpp-actions-cell">
<div class="atfpp-action-buttons">
<button type="button" class="atfpp-save-edit-btn button button-primary">
<?php esc_html_e('Save', $text_domain); ?>
</button>
<button type="button" class="atfpp-cancel-edit-btn">
<?php esc_html_e('Cancel', $text_domain); ?>
</button>
</div>
</td>
</tr>
</script>
</div>
</div>

View File

@@ -0,0 +1,287 @@
<?php
/**
* Renders the license activation page
*/
function atfpp_render_license_page() {
$text_domain = 'autopoly-ai-translation-for-polylang-pro';
$purchase_email = get_option('AIAutomaticTranslationsForPolylang_lic_email', get_bloginfo('admin_email'));
// Escape early for security
$admin_url = esc_url(admin_url('admin-post.php'));
$purchase_email_escaped = esc_attr($purchase_email);
?>
<div class="atfpp-dashboard-license">
<div class="atfpp-dashboard-license-container">
<div class="header">
<h1>🔑 <?php echo esc_html__('Activate License', $text_domain); ?></h1>
</div>
<div class="atfpp-dashboard-license-form">
<form method="post" action="<?php echo $admin_url; ?>">
<input type="hidden" name="action" value="AIAutomaticTranslationsForPolylang_el_activate_license"/>
<?php wp_nonce_field('el-atfpp-license'); ?>
<div class="atfpp-dashboard-license-field">
<label for="license_code"><?php esc_html_e('License Key', $text_domain); ?></label>
<input type="text" name="license_code" id="license_code" required
placeholder="<?php esc_attr_e('xxxxxxxx-xxxxxxxx-xxxxxxxx-xxxxxxxx', $text_domain); ?>">
</div>
<div class="atfpp-dashboard-license-field">
<label for="email"><?php esc_html_e('Email Address', $text_domain); ?></label>
<input type="email" name="email" id="email" required
value="<?php echo $purchase_email_escaped; ?>">
<small class="atfpp-dashboard-activation-note"><?php esc_html_e("Plugin updates news will be sent to this email. Don't worry, we hate spam.", $text_domain); ?></small>
</div>
<button type="submit" class="button button-primary">
<?php echo esc_html__('Activate License', $text_domain); ?>
</button>
</form>
<p class="activation-note">
<?php echo esc_html__('Activate to receive automatic plugin updates and support.', $text_domain); ?>
</p>
<?php atfpp_render_license_help_buttons($text_domain); ?>
</div>
</div>
</div>
<?php
}
/**
* Renders the license information page for Pro users
*
* @param object|null $license_info License information object
*/
function atfpp_render_license_page_pro($license_info = null) {
$text_domain = 'autopoly-ai-translation-for-polylang-pro';
// Early return if invalid license info
if (!$license_info) {
$license_info = AI_Automatic_Translations_For_Polylang_Base::GetRegisterInfo();
}
if (!is_object($license_info) || !isset($license_info->is_valid) || !isset($license_info->license_title) || !isset($license_info->expire_date)) {
wp_die(__('Error: Invalid license information', $text_domain));
return;
}
// Sanitize license key before masking
$license_key = sanitize_text_field(get_option('AIAutomaticTranslationsForPolylang_lic_Key', ''));
$masked_key = !empty($license_key) ?
esc_html(substr($license_key, 0, 8) . '-XXXXXXXX-XXXXXXXX-' . substr($license_key, -8)) :
'';
$admin_url = esc_url(admin_url('admin-post.php'));
?>
<div class="atfpp-dashboard-license">
<div class="atfpp-dashboard-license-pro-container">
<div class="atfpp-dashboard-license-header-container" style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px;">
<h1>🔒 <?php esc_html_e('Your License Info', $text_domain); ?></h1>
<?php if (atfpp_needs_refresh($license_info)): ?>
<button type="button" class="atfpp-refresh-btn" id="atfpp-refresh-license-btn">
<?php esc_html_e('🔄Check license status', $text_domain); ?>
</button>
<?php endif; ?>
</div>
<ul>
<li><strong><?php esc_html_e('Status:', $text_domain); ?></strong>
<span class="validity">
<?php if ($license_info->is_valid): ?>
<?php if (atfpp_is_license_expired($license_info)): ?>
<strong>❌ <?php esc_html_e('License Expired', $text_domain); ?></strong>
<?php elseif (atfpp_is_support_expired($license_info)): ?>
<strong>❌ <?php esc_html_e('Support Expired', $text_domain); ?></strong>
<?php else: ?>
<strong class="valid">✅ <?php esc_html_e('Valid', $text_domain); ?></strong>
<?php endif; ?>
<?php else: ?>
<strong>❌ <?php esc_html_e('Invalid', $text_domain); ?></strong>
<?php endif; ?>
</span>
</li>
<li><strong><?php esc_html_e('License Type:', $text_domain); ?></strong> <span class="license-type"><?php echo esc_html($license_info->license_title); ?></span></li>
<li><strong><?php esc_html_e('Plugin Updates & Support Validity:', $text_domain); ?></strong> <span class="validity">
<?php
$current_time = time();
// Handle "No expiry" case for expire_date
$expire_date_expired = false;
if (strtolower($license_info->expire_date) !== 'no expiry') {
$expire_date_timestamp = strtotime($license_info->expire_date);
$expire_date_expired = $expire_date_timestamp && $expire_date_timestamp < $current_time;
}
// Handle "no support" case for support_end
if (strtolower($license_info->support_end) === 'no support') {
esc_html_e('No Support', $text_domain);
} else {
// Handle "unlimited" case for support_end
$support_end_expired = false;
if (strtolower($license_info->support_end) !== 'unlimited') {
$support_end_timestamp = strtotime($license_info->support_end);
$support_end_expired = $support_end_timestamp && $support_end_timestamp < $current_time;
}
if ($expire_date_expired) {
echo esc_html(atfpp_pro_formatLicenseDate($license_info->expire_date));
} elseif ($support_end_expired) {
echo esc_html(atfpp_pro_formatLicenseDate($license_info->support_end));
} else {
echo esc_html(atfpp_pro_formatLicenseDate($license_info->expire_date));
}
}
?>
</span>
</li>
<li><strong><?php echo esc_html__('Your License Key:', $text_domain); ?></strong> <span class="license-key"><?php echo esc_html($masked_key); ?></span></li>
</ul>
<div class="atfpp-dashboard-license-pro-container-deactivate-btn">
<p><?php esc_html_e('Want to deactivate the license for any reason?', $text_domain); ?></p>
<form method="post" action="<?php echo esc_url(admin_url('admin-post.php')); ?>">
<input type="hidden" name="action" value="AIAutomaticTranslationsForPolylang_el_deactivate_license" />
<?php wp_nonce_field('el-atfpp-license'); ?>
<button type="submit" class="deactivate-btn">
<?php echo esc_html__('Deactivate License', $text_domain); ?>
</button>
</form>
</div>
<?php if (atfpp_is_license_expired($license_info)): ?>
<div class="notice notice-error" style="margin-top: 10px; color: #d63638;">
<?php atfpp_render_expiry_message($license_info, 'license'); ?>
</div>
<?php elseif (atfpp_is_support_expired($license_info)): ?>
<div class="notice notice-error" style="margin-top: 10px; color: #d63638;">
<?php atfpp_render_expiry_message($license_info, 'support'); ?>
</div>
<?php endif; ?>
<?php atfpp_render_license_help_buttons($text_domain); ?>
</div>
</div>
<?php
}
/**
* Renders the license buttons section
* @param string $text_domain The text domain for translations
*/
function atfpp_render_license_help_buttons($text_domain) {
?>
<div class="atfpp-dashboard-license-pro-container-buttons">
<p><?php esc_html_e('Want to know more about the license key?', $text_domain); ?></p>
<div class="btns">
<a href="https://my.coolplugins.net/account/" target="_blank" class="atfpp-dashboard-btn">
<?php echo esc_html__('Check Account', $text_domain); ?>
</a>
<a href="https://coolplugins.net/support/?utm_source=atfp_plugin&utm_medium=inside&utm_campaign=support&utm_content=dashboard_license" target="_blank" class="atfpp-dashboard-btn">
<?php echo esc_html__('Contact Support', $text_domain); ?>
</a>
</div>
</div>
<?php
}
function atfpp_is_license_expired($license_info) {
return $license_info->is_valid === 'license_expired';
}
function atfpp_is_support_expired($license_info) {
return $license_info->support_end === 'no support' ||
($license_info->is_valid === 'support_expired' ||
(strtolower($license_info->support_end) !== 'unlimited' &&
strtotime($license_info->support_end) < time()));
}
function atfpp_needs_refresh($license_info) {
return atfpp_is_license_expired($license_info) || atfpp_is_support_expired($license_info);
}
function atfpp_render_expiry_message($license_info, $type = 'license') {
$text_domain = 'autopoly-ai-translation-for-polylang-pro';
// Generate version available message using common helper
$version_available_message = AutoPolyPro::atfppGetVersionAvailableMessage();
if ($license_info->msg === 'limit_reached') {
$support_link = sprintf('<a href="%s" target="_blank" rel="noopener noreferrer">%s</a>', esc_url('https://my.coolplugins.net/account/support-tickets/'), esc_html__('clicking here', 'atfpp'));
echo wp_kses_post(sprintf(
/* translators: %s: link to support ticket page */
__('There was an issue with your account. Please contact our plugin support team by %s.', 'atfpp'),
$support_link
));
return;
}
$message = $type === 'license'
? __('Your license has expired,', 'atfpp')
: __('Your support has expired,', 'atfpp');
$renew_link = isset($license_info->market) && $license_info->market === 'E'
? ''
: ' <a href="'.esc_url('https://my.coolplugins.net/account/subscriptions/').'" target="_blank" rel="noopener noreferrer">'.esc_html__('Renew now', 'atfpp').'</a>';
$final_message = '';
// Add version message if available
if (!empty($version_available_message)) {
wp_enqueue_script('thickbox');
wp_enqueue_style('thickbox');
$final_message .= wp_kses_post($version_available_message) . ' ';
}
// Add license expiry message
$final_message .= esc_html($message) . $renew_link . esc_html__(' to continue receiving updates and priority support.', 'atfpp');
echo $final_message;
}
function atfpp_pro_formatLicenseDate($dateString) {
if (!empty($dateString) && strtolower($dateString) !== 'no expiry') {
$date = new DateTime($dateString);
return $date->format('d M Y');
}
return $dateString;
}

View File

@@ -0,0 +1,141 @@
<!-- Right Sidebar -->
<div class="atfpp-dashboard-sidebar">
<div class="atfpp-dashboard-status">
<h3><?php echo esc_html__('Auto Translation Status', $text_domain); ?></h3>
<div class="atfpp-dashboard-sts-top">
<?php
$service_providers = array();
$all_data = get_option('cpt_dashboard_data', array());
$avilable_service_providers = array('google'=>'Google', 'yandex'=>'Yandex', 'localAiTranslator'=>'Chrome AI Translator', 'google_ai'=>'Gemini', 'openai_ai'=>'OpenAI', 'deepl_ai'=>'DeepL');
if (!is_array($all_data) || !isset($all_data['atfp'])) {
$all_data['atfp'] = []; // Ensure $all_data['atfp'] is an array
}
$totals = array_reduce($all_data['atfp'] ?? [], function($carry, $translation) use (&$service_providers, $avilable_service_providers) {
// Ensure $translation['string_count'] is numeric
// Ensure all values are properly handled
$carry['string_count'] += intval($translation['string_count'] ?? 0);
$carry['character_count'] += intval($translation['character_count'] ?? 0);
$carry['time_taken'] += intval($translation['time_taken'] ?? 0);
if(isset($translation['service_provider']) && !empty($translation['service_provider']) && !in_array($translation['service_provider'], $service_providers) && in_array($translation['service_provider'], array_keys($avilable_service_providers))){
$service_providers[] = $translation['service_provider'];
}
// Count total translations instead of unique post IDs
if (!empty($translation['post_id'])) {
$carry['translation_count']++;
}
return $carry;
}, ['string_count' => 0, 'character_count' => 0, 'time_taken' => 0, 'translation_count' => 0]);
// Update the time taken string using the new function
$time_taken_str = atfp_format_time_taken($totals['time_taken'] ,$text_domain);
?>
<span><?php echo esc_html(atfp_format_number($totals['character_count'], $text_domain)); ?></span>
<span><?php echo esc_html__('Total Characters Translated!', $text_domain); ?></span>
</div>
<ul class="atfpp-dashboard-sts-btm">
<li><span><?php echo esc_html__('Total Strings', $text_domain); ?></span> <span><?php echo esc_html(atfp_format_number($totals['string_count'], $text_domain)); ?></span></li>
<li><span><?php echo esc_html__('Total Pages / Posts', $text_domain); ?></span> <span><?php echo esc_html($totals['translation_count']); ?></span></li>
<li><span><?php echo esc_html__('Time Taken', $text_domain); ?></span> <span><?php echo esc_html($time_taken_str); ?></span></li>
<?php if(count($service_providers) > 0): ?>
<li class="atfpp-dashboard-sts-btm-service-providers"><span><?php echo esc_html__('Service Providers', $text_domain); ?></span> <div class="atfpp-dashboard-sts-btm-service-providers-list"><?php foreach($service_providers as $service_provider): ?>
<span><?php echo esc_html($avilable_service_providers[$service_provider]); ?></span>
<?php endforeach; ?></div></li>
<?php endif; ?>
</ul>
</div>
<div class="atfpp-dashboard-translate-full">
<h3><?php echo esc_html__('Automatically Translate Plugins & Themes', $text_domain); ?></h3>
<div class="atfpp-dashboard-addon first">
<div class="atfpp-dashboard-addon-l">
<strong><?php echo esc_html(atfp_get_plugin_display_name('automatic-translator-addon-for-loco-translate', $text_domain)); ?></strong>
<span class="addon-desc"><?php echo esc_html__('Loco addon to translate plugins and themes.', $text_domain); ?></span>
<?php if (atfp_is_plugin_installed('automatic-translator-addon-for-loco-translate')): ?>
<span class="installed"><?php echo esc_html__('Installed', $text_domain); ?></span>
<?php else: ?>
<a href="<?php echo esc_url(admin_url('plugin-install.php?s=LocoAI++Auto+Translate+for+Loco+Translate+by+CoolPlugins&tab=search&type=term') ); ?>" class="atfpp-dashboard-btn" target="_blank"><?php _e('Install', $text_domain); ?></a>
<?php endif; ?>
</div>
<div class="atfpp-dashboard-addon-r">
<img src="<?php echo esc_url(ATFPP_URL . 'admin/atfpp-dashboard/images/atlt-logo.png'); ?>" alt="<?php echo esc_html__('TranslatePress Addon', $text_domain); ?>">
</div>
</div>
</div>
<div class="atfpp-dashboard-rate-us">
<h3><?php echo esc_html__('Rate Us ⭐⭐⭐⭐⭐', $text_domain); ?></h3>
<p><?php echo esc_html__('We\'d love your feedback! Hope this addon made auto-translations easier for you.', $text_domain); ?></p>
<a href="https://wordpress.org/support/plugin/automatic-translations-for-polylang/reviews/#new-post" class="review-link" target="_blank"><?php echo esc_html__('Submit a Review →', $text_domain); ?></a>
</div>
</div>
<?php
function atfp_format_time_taken($time_taken, $text_domain) {
if ($time_taken === 0) return esc_html__('0', $text_domain);
if ($time_taken < 60) return sprintf(esc_html__('%d sec', $text_domain), $time_taken);
if ($time_taken < 3600) {
$min = floor($time_taken / 60);
$sec = $time_taken % 60;
return sprintf(esc_html__('%d min %d sec', $text_domain), $min, $sec);
}
$hours = floor($time_taken / 3600);
$min = floor(($time_taken % 3600) / 60);
return sprintf(esc_html__('%d hours %d min', $text_domain), $hours, $min);
}
function atfp_is_plugin_installed($plugin_slug) {
$plugins = get_plugins();
// Check if the plugin is installed
if ($plugin_slug === 'automatic-translator-addon-for-loco-translate') {
return isset($plugins['automatic-translator-addon-for-loco-translate/automatic-translator-addon-for-loco-translate.php']) || isset($plugins['loco-automatic-translate-addon-pro/loco-automatic-translate-addon-pro.php']);
}
return false; // Return false if no match found
}
function atfp_get_plugin_display_name($plugin_slug, $text_domain) {
$plugins = get_plugins();
// Define free and pro plugin paths
$plugin_paths = [
'automatic-translator-addon-for-loco-translate' => [
'free' => 'automatic-translator-addon-for-loco-translate/automatic-translator-addon-for-loco-translate.php',
'pro' => 'loco-automatic-translate-addon-pro/loco-automatic-translate-addon-pro.php',
'free_name' => esc_html__('LocoAI Auto Translate For Loco Translate', $text_domain),
'pro_name' => esc_html__('LocoAI Auto Translate for Loco Translate (Pro)', $text_domain),
],
];
// Check if the provided plugin slug exists
if (!isset($plugin_paths[$plugin_slug])) {
return $plugin_slug['free_name'];
}
$free_installed = isset($plugins[$plugin_paths[$plugin_slug]['free']]);
$pro_installed = isset($plugins[$plugin_paths[$plugin_slug]['pro']]);
// Determine which version is installed
if ($pro_installed) {
return $plugin_paths[$plugin_slug]['pro_name'];
} elseif ($free_installed) {
return $plugin_paths[$plugin_slug]['free_name'];
} else {
return $plugin_paths[$plugin_slug]['free_name'];
}
}
function atfp_format_number($number, $text_domain) {
if ($number >= 1000000000) {
return round($number / 1000000000, 1) . esc_html__('B', $text_domain);
} elseif ($number >= 1000000) {
return round($number / 1000000, 1) . esc_html__('M', $text_domain);
} elseif ($number >= 1000) {
return round($number / 1000, 1) . esc_html__('K', $text_domain);
}
return $number;
}

View File

@@ -0,0 +1,213 @@
<?php
/**
* Do not access the page directly
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
if ( ! class_exists( 'ATFP_Supported_Blocks' ) ) {
/**
* Class ATFP_Supported_Blocks
*
* This class handles the supported blocks for the AutoPoly - AI Translation For Polylang plugin.
*
* @package ATFPP
*/
class ATFP_Supported_Blocks {
/**
* Singleton instance.
*
* @var ATFP_Supported_Blocks
*/
private static $instance = null;
/**
* ATFPP plugin category.
*
* @var array
*/
private $atfpp_plugin_category = array();
/**
* Get the singleton instance of the class.
*
* @return ATFP_Supported_Blocks
*/
public static function get_instance() {
if ( null === self::$instance ) {
self::$instance = new self();
}
return self::$instance;
}
/**
* Constructor for the ATFP_Supported_Blocks class.
*/
private function __construct() {
// wp:phpcs:ignore Wordpress.security Nonce verification is not required here
$tab=isset($_GET['tab']) ? sanitize_text_field(wp_unslash($_GET['tab'])) : '';
$page=isset($_GET['page']) ? sanitize_text_field(wp_unslash($_GET['page'])) : '';
if('support-blocks' === $tab && 'polylang-atfpp-dashboard' === $page){
$this->atfpp_render_support_blocks_page();
$this->enqueue_editor_assets();
}
}
/**
* Enqueue editor CSS for the supported blocks page.
*/
public function enqueue_editor_assets( ) {
wp_enqueue_script( 'atfp-datatable-script', ATFPP_URL . 'assets/js/dataTables.min.js', array(), ATFPP_V, true );
wp_enqueue_script( 'atfp-datatable-style', ATFPP_URL . 'assets/js/dataTables.min.js', array(), ATFPP_V, true );
wp_enqueue_style( 'atfp-custom-data-table', ATFPP_URL . 'assets/css/atfp-custom-data-table.min.css', array(), ATFPP_V );
wp_enqueue_script( 'atfp-custom-data-table', ATFPP_URL . 'assets/js/atfp-custom-data-table.min.js', array('atfp-datatable-script'), ATFPP_V, true );
}
/**
* Add submenu page under the Polylang menu.
*/
public function atfpp_add_submenu_page() {
add_submenu_page(
'mlang', // Parent slug
__( 'Support Blocks', 'autopoly-ai-translation-for-polylang-pro' ), // Page title
__( '↳ Support Blocks', 'autopoly-ai-translation-for-polylang-pro' ), // Menu title
'manage_options', // Capability
'atfp-supported-blocks', // Menu slug
array( $this, 'atfpp_render_support_blocks_page' ) // Callback function
);
}
/**
* Render the support blocks page.
*/
public function atfpp_render_support_blocks_page() {
?>
<div class="atfp-custom-data-table-wrapper">
<h3><?php echo __('Supported Blocks Translation Settings', 'autopoly-ai-translation-for-polylang-pro'); ?>
<br>
<p><?php echo sprintf(esc_html__('Manage Gutenberg blocks to make them translation-ready with %s.', 'autopoly-ai-translation-for-polylang-pro'), 'AutoPoly'); ?></p>
</h3>
<div class="atfp-custom-data-table-filters">
<div class="atfp-filter-tab" data-column="1" data-default="all">
<label for="atfp-blocks-category"><?php esc_html_e( 'Block Type Category:', 'autopoly-ai-translation-for-polylang-pro' ); ?></label>
<select id="atfp-blocks-category" name="atfp_blocks_category">
<option value="all"><?php esc_html_e( 'All', 'autopoly-ai-translation-for-polylang-pro' ); ?></option>
<option value="core">Core</option>
<?php $this->atfpp_get_blocks_category(); ?>
</select>
</div>
<div class="atfp-filter-tab" data-column="3" data-default="all">
<label for="atfp-blocks-filter"><?php esc_html_e( 'Show Blocks:', 'autopoly-ai-translation-for-polylang-pro' ); ?></label>
<select id="atfp-blocks-filter" name="atfp_blocks_filter">
<option value="all"><?php esc_html_e( 'All', 'autopoly-ai-translation-for-polylang-pro' ); ?></option>
<option value="supported"><?php esc_html_e( 'Supported Blocks', 'autopoly-ai-translation-for-polylang-pro' ); ?></option>
<option value="unsupported"><?php esc_html_e( 'Unsupported Blocks', 'autopoly-ai-translation-for-polylang-pro' ); ?></option>
</select>
</div>
</div>
<div class="atfp-custom-table-section">
<div class="atfp-custom-table-lists">
<table class="atfp-custom-data-table-table" id="atfp-custom-datatable">
<thead>
<tr>
<th><?php esc_html_e( 'Sr.No', 'autopoly-ai-translation-for-polylang-pro' ); ?></th>
<th><?php esc_html_e( 'Block Name', 'autopoly-ai-translation-for-polylang-pro' ); ?></th>
<th><?php esc_html_e( 'Block Title', 'autopoly-ai-translation-for-polylang-pro' ); ?></th>
<th><?php esc_html_e( 'Status', 'autopoly-ai-translation-for-polylang-pro' ); ?></th>
<th><?php esc_html_e( 'Modify', 'autopoly-ai-translation-for-polylang-pro' ); ?></th>
</tr>
</thead>
<tbody>
<?php
$this->atfpp_get_supported_blocks_table()
?>
</tbody>
</table>
</div>
</div>
</div>
<?php
}
/**
* Get the blocks category.
*/
public function atfpp_get_blocks_category() {
$blocks_data = WP_Block_Type_Registry::get_instance()->get_all_registered();
$filter_blocks_data = array_filter( $blocks_data, function( $block ) {
return !in_array($block->category, array( 'media', 'reusable' ));
} );
foreach ( $filter_blocks_data as $block ) {
$plugin_name = explode('/', $block->name);
$plugin_name = isset($plugin_name[0]) ? $plugin_name[0] : '';
if(!empty($plugin_name)){
$filter_plugin_name = $this->atfpp_supported_block_name($plugin_name);
$filter_plugin_name=str_replace('-',' ',$filter_plugin_name);
$filter_plugin_name=ucwords($filter_plugin_name);
if(in_array($plugin_name, $this->atfpp_plugin_category) || $plugin_name === 'core'){
continue;
}
$this->atfpp_plugin_category[] = $plugin_name;
echo '<option value="' . esc_attr( $plugin_name ) . '">' . esc_html( $filter_plugin_name ) . '</option>';
}
}
}
/**
* Get the supported blocks.
*/
public function atfpp_get_supported_blocks_table() {
if ( class_exists( 'WP_Block_Type_Registry' ) && method_exists( 'WP_Block_Type_Registry', 'get_all_registered' ) ) {
$atfp_block_parse_rules = ATFPP_Helper::get_instance()->get_block_parse_rules();
$blocks_data = WP_Block_Type_Registry::get_instance()->get_all_registered();
$atfp_supported_blocks = isset($atfp_block_parse_rules['AtfpBlockParseRules']) ? $atfp_block_parse_rules['AtfpBlockParseRules'] : array();
$atfp_supported_blocks_names = array_keys( $atfp_supported_blocks );
$s_no = 1;
$atfp_post_id = ATFPP_Helper::get_custom_block_post_id();
$filter_blocks_data=$blocks_data;
foreach ( $filter_blocks_data as $block ) {
$block_name = esc_html( $block->name );
$block_title = esc_html( $block->title );
$status = ! in_array( $block_name, $atfp_supported_blocks_names ) ? 'Unsupported' : 'Supported'; // You can modify this logic based on your requirements
$modify_text = ! in_array( $block_name, $atfp_supported_blocks_names ) ? esc_html__( 'Add', 'autopoly-ai-translation-for-polylang-pro' ) : esc_html__( 'Edit', 'autopoly-ai-translation-for-polylang-pro' );
$modify_link = '<a href="' . esc_url( admin_url( 'post.php?post=' . esc_attr( $atfp_post_id ) . '&action=edit&atfp_new_block=' ) . esc_attr( $block_name ) ) . '">' . $modify_text . '</a>'; // Modify link
$modify_link = '<a href="' . esc_url( admin_url( 'post.php?post=' . esc_attr( $atfp_post_id ) . '&action=edit&atfp_new_block=' ) . esc_attr( $block_name ) ) . '">' . $modify_text . '</a>'; // Modify link
echo '<tr data-block-name="' . esc_attr( strtolower( $block_name ) ) . '" data-block-status="' . esc_attr( strtolower( $status ) ) . '" >';
echo '<td>' . esc_html($s_no++) . '</td>';
echo '<td>' . esc_html($block_name) . '</td>';
echo '<td>' . esc_html($block_title) . '</td>';
echo '<td>' . esc_html($status) . '</td>';
echo '<td>' . wp_kses($modify_link, array('a' => array('href' => array(), 'target' => array(), 'rel' => array()))) . '</td>';
echo '</tr>';
}
}
}
private function atfpp_supported_block_name($block_name){
$predfined_blocks = array(
'ub' => 'Ultimate Blocks',
'uagb' => 'Spectra',
'themeisle-blocks' => 'Otter Blocks'
);
if(array_key_exists($block_name, $predfined_blocks)){
return $predfined_blocks[$block_name];
}
return $block_name;
}
}
ATFP_Supported_Blocks::get_instance();
}