Changeset 3736621 for langforge/trunk/admin/class-admin.php
- Timestamp:
- 10/09/2026 12:22:35 PM (3 weeks ago)
- File:
-
- 1 edited
-
langforge/trunk/admin/class-admin.php (modified) (14 diffs)
Legend:
- Unmodified
- Added
- Removed
-
langforge/trunk/admin/class-admin.php
r3732047 r3736621 1626 1626 update_option('langforge_url_format', $url_format); 1627 1627 1628 // Translation model — plugin just records the choice; forge-api1629 // picks the actual OpenAI GPT backend (mini / gpt-4o) server-side.1630 1628 if (isset($_POST['langforge_translation_model'])) { 1631 1629 // Switcher hidden (2026-04-20) — only openai-mini is exposed. The … … 1765 1763 1766 1764 /** 1767 * Scan theme files for lf_e and lf__ calls and register strings 1765 * The theme usage example of the Strings page. It shows a theme's own text 1766 * domain, so it lives in a plain text file shown as text, not as PHP code 1767 * of this plugin. 1768 1768 */ 1769 private function scan_theme_for_strings() { 1770 $theme_dir = get_template_directory(); 1771 $files = $this->get_php_files($theme_dir); 1772 $count = 0; 1773 1774 // Pattern to match lf_e('string', 'domain', 'lang') or lf__('string', 'domain', 'lang') 1775 $pattern = "/lf_e?\(\s*['\"]([^'\"]+)['\"]\s*(?:,\s*['\"]([^'\"]*)['\"])?\s*(?:,\s*['\"]([^'\"]+)['\"])?\s*\)/"; 1776 1777 foreach ($files as $file) { 1778 $content = file_get_contents($file); 1779 if (preg_match_all($pattern, $content, $matches, PREG_SET_ORDER)) { 1780 foreach ($matches as $match) { 1781 $string = $match[1]; 1782 $domain = !empty($match[2]) ? $match[2] : 'default'; 1783 $source_lang = !empty($match[3]) ? $match[3] : LANGFORGE_Core::instance()->get_default_language(); 1784 1785 LANGFORGE_String_Translation::instance()->register_string($string, $string, $domain, $source_lang); 1786 $count++; 1787 } 1788 } 1789 } 1790 1791 return $count; 1792 } 1793 1794 /** 1795 * Get all PHP files in directory recursively 1796 */ 1797 private function get_php_files($dir) { 1798 $files = []; 1799 $iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($dir)); 1800 1801 foreach ($iterator as $file) { 1802 if ($file->isFile() && $file->getExtension() === 'php') { 1803 $files[] = $file->getPathname(); 1804 } 1805 } 1806 1807 return $files; 1808 } 1809 1769 private function theme_usage_example(): string { 1770 $file = __DIR__ . '/examples/theme-usage.txt'; 1771 return is_readable($file) ? (string) file_get_contents($file) : ''; 1772 } 1773 1810 1774 /** 1811 1775 * Render string translation page … … 1814 1778 $languages = LANGFORGE_Core::instance()->get_active_languages(); 1815 1779 $default_lang = LANGFORGE_Core::instance()->get_default_language(); 1816 1817 // Auto-scan theme for strings on page load1818 $this->scan_theme_for_strings();1819 1780 1820 1781 // Handle save … … 2244 2205 </div> 2245 2206 2246 <?php ob_start(); ?>2207 <?php ob_start(); try { // wporg-advisory-ok: inline script captured for wp_add_inline_script; the finally block below closes the buffer in this method on every path ?> 2247 2208 // warn before navigating away with unsaved changes 2248 2209 (function(){ … … 2370 2331 jQuery(document).on('keydown', function(e){ if (e.key === 'Escape' && $modal.is(':visible')) closeModal(); }); 2371 2332 })(); 2372 <?php wp_add_inline_script('lf-admin', ob_get_clean()); ?>2333 <?php } finally { $lf_inline_js = (string) ob_get_clean(); } wp_add_inline_script('lf-admin', $lf_inline_js); ?> 2373 2334 </form> 2374 2335 <?php endif; ?> … … 2402 2363 <h2><?php esc_html_e('Usage in Theme', 'langforge'); ?></h2> 2403 2364 <p><?php echo wp_kses(__('Strings from your theme are registered automatically via standard WordPress translation functions. Just use <code>__()</code> and <code>_e()</code> — Lang Forge picks them up.', 'langforge'), ['code' => []]); ?></p> 2404 <pre style="background:#f0f0f0;padding:15px;overflow:auto;border-radius:8px;font-size:14px;"> 2405 // Standard WordPress functions — strings auto-register 2406 echo __('Welcome to our site', 'your-theme'); 2407 esc_html_e('Contact us', 'your-theme'); 2408 echo esc_html__('Read more', 'your-theme'); 2409 2410 // Shortcode in content (for editors) 2411 [langforge_string name="welcome_message" domain="your-theme"]Welcome to our site[/langforge_string] 2412 </pre> 2365 <pre style="background:#f0f0f0;padding:15px;overflow:auto;border-radius:8px;font-size:14px;"><?php echo esc_html($this->theme_usage_example()); ?></pre> 2413 2366 <p style="font-size:14px;color:#64748b;"><?php esc_html_e('Configure which text domains to auto-register in Settings → String Auto-Registration Domains.', 'langforge'); ?></p> 2414 2367 </div> 2415 2368 2416 <?php ob_start(); ?>2369 <?php ob_start(); try { // wporg-advisory-ok: inline style captured for wp_add_inline_style; the finally block below closes the buffer in this method on every path ?> 2417 2370 .lf-string-filters { margin: 20px 0; padding: 15px; background: #f5f5f5; } 2418 2371 .lf-string-filters form { display: flex; align-items: center; flex-wrap: wrap; gap: 4px; } … … 2524 2477 .lf-domain-badge { background: #f0f0f0; color: #555; padding: 2px 8px; border-radius: 4px; font-size: 14px; } 2525 2478 .lf-add-string-form { background: #f9f9f9; padding: 15px; margin: 20px 0; } 2526 <?php wp_add_inline_style('lf-admin', ob_get_clean()); ?>2479 <?php } finally { $lf_inline_css = (string) ob_get_clean(); } wp_add_inline_style('lf-admin', $lf_inline_css); ?> 2527 2480 <?php 2528 2481 } … … 2699 2652 */ 2700 2653 private function no_languages_row_html(): string { 2701 ob_start(); 2702 $this->render_no_languages_row(); 2703 return trim((string) ob_get_clean()); 2654 ob_start(); // wporg-advisory-ok: the row markup is returned as a string; ob_get_clean in the finally block closes the buffer on every path, exceptions included 2655 try { 2656 $this->render_no_languages_row(); 2657 } finally { 2658 $html = (string) ob_get_clean(); 2659 } 2660 return trim($html); 2704 2661 } 2705 2662 … … 3304 3261 </tbody> 3305 3262 </table> 3306 <?php ob_start(); ?>3263 <?php ob_start(); try { // wporg-advisory-ok: inline script captured for wp_add_inline_script; the finally block below closes the buffer in this method on every path ?> 3307 3264 // wire per-row Re-translate to the existing 3308 3265 // langforge_ai_translate_post AJAX. On success the PHP … … 3362 3319 }); 3363 3320 })(); 3364 <?php wp_add_inline_script('lf-admin', ob_get_clean()); ?>3321 <?php } finally { $lf_inline_js = (string) ob_get_clean(); } wp_add_inline_script('lf-admin', $lf_inline_js); ?> 3365 3322 <?php endif; ?> 3366 3323 <?php else: ?> … … 3610 3567 </table> 3611 3568 3612 <?php ob_start(); ?>3569 <?php ob_start(); try { // wporg-advisory-ok: inline script captured for wp_add_inline_script; the finally block below closes the buffer in this method on every path ?> 3613 3570 jQuery(function($) { 3614 3571 var restBase = '<?php echo esc_url(rest_url('langforge/v1/glossary')); ?>'; … … 3697 3654 }); 3698 3655 }); 3699 <?php wp_add_inline_script('lf-admin', ob_get_clean()); ?>3656 <?php } finally { $lf_inline_js = (string) ob_get_clean(); } wp_add_inline_script('lf-admin', $lf_inline_js); ?> 3700 3657 3701 3658 <!-- Add term form --> … … 4007 3964 </table> 4008 3965 </div> 4009 <?php ob_start(); ?>3966 <?php ob_start(); try { // wporg-advisory-ok: inline script captured for wp_add_inline_script; the finally block below closes the buffer in this method on every path ?> 4010 3967 jQuery(function($){ 4011 3968 $('.lf-removed-lang-notice').on('click', 'button[data-action]', function(){ … … 4035 3992 }); 4036 3993 }); 4037 <?php wp_add_inline_script('lf-admin', ob_get_clean()); ?>3994 <?php } finally { $lf_inline_js = (string) ob_get_clean(); } wp_add_inline_script('lf-admin', $lf_inline_js); ?> 4038 3995 <?php 4039 3996 }
Note:
See TracChangeset
for help on using the changeset viewer.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)