Plugin Directory


Ignore:
Timestamp:
10/09/2026 12:22:35 PM (3 weeks ago)
Author:
avakodeforge
Message:

Release 1.2.0 (trunk + tag; see readme changelog)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • langforge/trunk/admin/class-admin.php

    r3732047 r3736621  
    16261626            update_option('langforge_url_format', $url_format);
    16271627
    1628             // Translation model — plugin just records the choice; forge-api
    1629             // picks the actual OpenAI GPT backend (mini / gpt-4o) server-side.
    16301628            if (isset($_POST['langforge_translation_model'])) {
    16311629                // Switcher hidden (2026-04-20) — only openai-mini is exposed. The
    … …  
    17651763   
    17661764    /**
    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.
    17681768 */
    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
    18101774    /**
    18111775 * Render string translation page
    … …  
    18141778        $languages = LANGFORGE_Core::instance()->get_active_languages();
    18151779        $default_lang = LANGFORGE_Core::instance()->get_default_language();
    1816 
    1817         // Auto-scan theme for strings on page load
    1818         $this->scan_theme_for_strings();
    18191780
    18201781        // Handle save
    … …  
    22442205                    </div>
    22452206
    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 ?>
    22472208 // warn before navigating away with unsaved changes
    22482209                    (function(){
    … …  
    23702331                        jQuery(document).on('keydown', function(e){ if (e.key === 'Escape' && $modal.is(':visible')) closeModal(); });
    23712332                    })();
    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); ?>
    23732334                </form>
    23742335            <?php endif; ?>
    … …  
    24022363            <h2><?php esc_html_e('Usage in Theme', 'langforge'); ?></h2>
    24032364            <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>
    24132366            <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>
    24142367        </div>
    24152368       
    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 ?>
    24172370            .lf-string-filters { margin: 20px 0; padding: 15px; background: #f5f5f5; }
    24182371            .lf-string-filters form { display: flex; align-items: center; flex-wrap: wrap; gap: 4px; }
    … …  
    25242477            .lf-domain-badge { background: #f0f0f0; color: #555; padding: 2px 8px; border-radius: 4px; font-size: 14px; }
    25252478            .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); ?>
    25272480        <?php
    25282481    }
    … …  
    26992652 */
    27002653    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);
    27042661    }
    27052662
    … …  
    33043261                        </tbody>
    33053262                    </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 ?>
    33073264 // wire per-row Re-translate to the existing
    33083265                    // langforge_ai_translate_post AJAX. On success the PHP
    … …  
    33623319                        });
    33633320                    })();
    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); ?>
    33653322                <?php endif; ?>
    33663323            <?php else: ?>
    … …  
    36103567            </table>
    36113568
    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 ?>
    36133570            jQuery(function($) {
    36143571                var restBase = '<?php echo esc_url(rest_url('langforge/v1/glossary')); ?>';
    … …  
    36973654                });
    36983655            });
    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); ?>
    37003657
    37013658            <!-- Add term form -->
    … …  
    40073964            </table>
    40083965        </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 ?>
    40103967        jQuery(function($){
    40113968            $('.lf-removed-lang-notice').on('click', 'button[data-action]', function(){
    … …  
    40353992            });
    40363993        });
    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); ?>
    40383995        <?php
    40393996    }
Note: See TracChangeset for help on using the changeset viewer.