Changeset 1925069
- Timestamp:
- 08/15/2018 09:26:39 AM (7 years ago)
- Location:
- polylang-theme-strings
- Files:
-
- 23 added
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
polylang-theme-strings/trunk/css/admin.css
r1727898 r1925069 25 25 display: block; 26 26 font-size: 12px; 27 line-height: 1. 2;27 line-height: 1.3; 28 28 } 29 29 … … 67 67 font-weight: bold; 68 68 } 69 70 #polylang-theme-strings .link-pll-strings.warning, /* For WP < 4.5 */ 71 [data-slug="polylang-theme-strings"] .link-pll-strings.warning /* For WP >= 4.5 */ { 72 color: #a00000; 73 font-weight: bold; 74 } -
polylang-theme-strings/trunk/js/admin.js
r1727898 r1925069 3 3 attr: { 4 4 prefix: '', 5 settings: [], 5 6 urls: [] 6 7 }, … … 26 27 html += '<span>' + _this.lng[20] + ': <i><a href="' + _this.attr.urls['polylang_strings_theme_current'] + '">' + _this.lng[21] + '</a></i></span>'; 27 28 html += '<span>' + _this.lng[30] + ': <i><a href="' + _this.attr.urls['polylang_strings'] + '">' + _this.lng[31] + '</a></i></span>'; 29 30 if (_this.attr.settings['search_plugins_strings']){ 31 html += '<span>' + _this.lng[35] + ': <i><a href="' + _this.attr.urls['polylang_plugins'] + '">' + _this.lng[36] + '</a></i></span>'; 32 } 33 28 34 html += '<span class="links">'; 29 35 html += '<a href="https://modeewine.com/en-polylang-theme-strings" target="_blank">' + _this.lng[40] + '</a>'; … … 54 60 if (tr.length && pll_tr.length) 55 61 { 62 jQuery('<div class="link-pll-strings"><a href="' + _this.attr.urls['polylang_theme_strings_settings'] + '">' + _this.lng[71] + '</a></div>').insertAfter(jQuery('.plugin-description', tr)); 56 63 jQuery('<div class="link-pll-strings"><a href="' + _this.attr.urls['polylang_strings'] + '">' + _this.lng[70] + '</a></div>').insertAfter(jQuery('.plugin-description', tr)); 64 } 65 else 66 if (tr.length && !pll_tr.length){ 67 jQuery('<div class="link-pll-strings warning">' + _this.lng[80] + ' «<a href="https://wordpress.org/plugins/polylang" target="_blank">' + _this.lng[81] + '</a>»</div>').insertAfter(jQuery('.plugin-description', tr)); 57 68 } 58 69 } -
polylang-theme-strings/trunk/mw-polylang-theme-strings.php
r1727898 r1925069 5 5 Plugin URI: http://modeewine.com/en-polylang-theme-strings 6 6 Description: Automatic scanning of strings translation in the theme and registration of them in Polylang plugin. Extension for Polylang plugin. 7 Version: 3.57 Version: 4.0 8 8 Author: Modeewine 9 9 Author URI: http://modeewine.com … … 13 13 new MW_Polylang_Theme_Strings(); 14 14 15 class MW_Polylang_Theme_Strings 16 { 15 class MW_Polylang_Theme_Strings { 17 16 static $prefix = 'mw_polylang_strings_'; 18 static $plugin_version = ' 3.5';17 static $plugin_version = '4.0'; 19 18 static $pll_f = 'pll_register_string'; 19 static $pll_d = 'pll_string'; 20 20 static $php_file_size_limit = 2097152; 21 22 private $db; 21 23 private $paths; 22 24 private $var = array(); 23 24 public function __construct() 25 {25 private $settings = array(); 26 27 public function __construct(){ 26 28 $this->Init(); 27 29 } 28 30 29 public static function Install() 30 { 31 if (!version_compare(phpversion(), '5', '>=')) 32 { 33 ?> 34 Your PHP version (<?php echo phpversion(); ?>) is incompatible with the plug-in code.<br /> 35 Minimum supported PHP version is 5.0. 36 <?php 37 38 die(); 39 } 40 else 41 { 42 self::Themes_PLL_Strings_Scan(); 43 } 44 } 45 46 public function Uninstall() 47 { 31 public function Install(){ 32 if (!version_compare(phpversion(), '5', '>=')){ 33 die('Your PHP version (' . phpversion() . ') is incompatible with the plug-in code.<br />Minimum supported PHP version is 5.0.'); 34 } 35 else{ 36 $this->Settings_Defaults_Setup(); 37 $this->Themes_PLL_Strings_Scan(); 38 $this->Plugins_PLL_Strings_Scan(); 39 } 40 } 41 42 public function Uninstall(){ 43 $this->db->query("DELETE FROM `" . $this->db->prefix . "options` WHERE `option_name` LIKE '" . self::$prefix . "%'"); 44 } 45 46 public function Plugin_Upgrade($upgrader_object, $options){ 47 if ( 48 $options['action'] == 'update' 49 && $options['type'] == 'plugin' 50 && isset( $options['plugins']) 51 ){ 52 $plugin_bn = plugin_basename(__FILE__); 53 54 foreach( $options['plugins'] as $plugin){ 55 if ($plugin == $plugin_bn){ 56 // upgrading for v.4.0 57 $this->db->query("DELETE FROM `" . $this->db->prefix . "options` WHERE `option_name` LIKE '" . self::$prefix . "%_data' AND `option_name` NOT LIKE '" . self::$prefix . "theme_%_data' AND `option_name` != '" . self::$prefix . "plugins_data'"); 58 //// 59 } 60 } 61 } 62 } 63 64 public function Init(){ 48 65 global $wpdb; 49 50 $wpdb->query("DELETE FROM `" . $wpdb->prefix . "options` WHERE `option_name` LIKE '" . self::$prefix . "%'"); 51 } 52 53 public function Init() 54 { 66 $this->db = $wpdb; 67 55 68 $this->Paths_Init(); 56 69 $this->Plugin_Install_Hooks_Init(); 57 58 add_action('init', array($this, 'Plugin_Hooks_Init')); 70 $this->Plugin_Hooks_Init(); 71 } 72 73 private function Paths_Init(){ 74 $theme = realpath(get_template_directory()); 75 $theme_dir_name = preg_split("/[\/\\\]/uis", $theme); 76 $theme_dir_name = (string)$theme_dir_name[count($theme_dir_name) - 1]; 77 78 $this->paths = array(); 79 $this->paths['plugin_file_index'] = __FILE__; 80 $this->paths['plugin_path'] = plugin_dir_path(__FILE__); 81 $this->paths['plugin_url'] = plugins_url(DIRECTORY_SEPARATOR, __FILE__); 82 $this->paths['theme'] = $theme; 83 $this->paths['theme_dir_name'] = $theme_dir_name; 84 $this->paths['theme_name'] = wp_get_theme()->Name; 85 $this->paths['plugin_templates_path'] = $this->paths['plugin_path'] . 'templates' . DIRECTORY_SEPARATOR; 86 } 87 88 private function Plugin_Install_Hooks_Init(){ 89 register_activation_hook($this->Path_Get('plugin_file_index'), array($this, 'Install')); 90 register_uninstall_hook($this->Path_Get('plugin_file_index'), array($this, 'Uninstall')); 91 add_action('upgrader_process_complete', array($this, 'Plugin_Upgrade'), 10, 2); 92 } 93 94 public function Plugin_Hooks_Init(){ 95 add_action('init', array($this, 'Actions_Init')); 96 add_action('init', array($this, 'Plugin_TS_Init')); 59 97 add_action('init', array($this, 'PLL_Exists_Check')); 60 98 add_action('admin_enqueue_scripts', array($this, 'Styles_Scripts_Admin_Init')); 61 99 add_action('admin_head', array($this, 'Head_Admin_Init')); 62 } 63 64 private function Paths_Init() 65 { 66 $theme = realpath(get_template_directory()); 67 $theme_dir_name = preg_split("/[\/\\\]/uis", $theme); 68 $theme_dir_name = (string)$theme_dir_name[count($theme_dir_name) - 1]; 69 70 $this->paths = array( 71 'plugin_file_index' => __FILE__, 72 'plugin_url' => plugins_url('/', __FILE__), 73 'theme' => $theme, 74 'theme_dir_name' => $theme_dir_name, 75 'theme_name' => wp_get_theme()->Name 100 add_action('admin_menu', array($this, 'Admin_Menus_Init'), 99); 101 102 if ($this->Setting_Get('search_native_wp_functions', 'bool')){ 103 add_filter('gettext', array($this, 'Str_Filter'), 20, 3); 104 } 105 } 106 107 public function Actions_Init(){ 108 if ( 109 isset($_REQUEST['_handler']) 110 && $_REQUEST['_handler'] == self::$prefix 111 && isset($_REQUEST['_action']) 112 ){ 113 $inc = $this->Path_Get('plugin_path') . 'actions.php'; 114 if (file_exists($inc)) include_once($inc); 115 die(); 116 } 117 } 118 119 public function Plugin_TS_Init(){ 120 if ( 121 !is_admin() 122 && function_exists(self::$pll_f) 123 ){ 124 $this->Theme_Current_PLL_Strings_Init(); 125 $this->Plugins_PLL_Strings_Init(); 126 } 127 else if ($this->Is_PLL_Strings_Settings_Page()){ 128 $this->Themes_PLL_Strings_Scan(); 129 $this->Plugins_PLL_Strings_Scan(); 130 131 if (!pll_default_language()){ 132 if ( 133 defined('POLYLANG_VERSION') 134 && version_compare(POLYLANG_VERSION, '2.1', '<') 135 ){ 136 wp_redirect(admin_url('options-general.php?page=mlang')); 137 } 138 else{ // for Polylang >= 2.1 139 wp_redirect(admin_url('admin.php?page=mlang')); 140 } 141 142 die(); 143 } 144 145 $this->Themes_PLL_Strings_Init(); 146 $this->Plugins_PLL_Strings_Init(); 147 } 148 } 149 150 public function Settings_Defaults_Setup(){ 151 $defaults = array( 152 self::$prefix . 'settings_search_native_wp_functions' => 1, 153 self::$prefix . 'settings_search_plugins_strings' => 0 76 154 ); 77 } 78 79 private function Plugin_Install_Hooks_Init() 80 { 81 register_activation_hook($this->Path_Get('plugin_file_index'), array(__CLASS__, 'Install')); 82 register_uninstall_hook($this->Path_Get('plugin_file_index'), array(__CLASS__, 'Uninstall')); 83 } 84 85 public function Plugin_Hooks_Init() 86 { 87 if (!is_admin() && function_exists(self::$pll_f)) 88 { 89 $this->Theme_Current_PLL_Strings_Init(); 90 } 91 else 92 if (self::Is_PLL_Strings_Settings_Page()) 93 { 94 $this->Themes_PLL_Strings_Scan(); 95 96 if (!pll_default_language()) 97 { 98 if (defined('POLYLANG_VERSION') && version_compare(POLYLANG_VERSION, '2.1', '<')) 99 { 100 wp_redirect(admin_url('options-general.php?page=mlang')); 101 } 102 else // for Polylang >= 2.1 103 { 104 wp_redirect(admin_url('admin.php?page=mlang')); 105 } 106 107 exit; 108 } 109 110 $this->Themes_PLL_Strings_Init(); 111 } 112 } 113 114 public function Styles_Scripts_Admin_Init() 115 { 116 if (self::Is_PLL_Strings_Settings_Page() || self::Is_WP_Plugins_Page()) 117 { 155 156 foreach ($defaults as $k => $v){ 157 if (get_option($k) === false) update_option($k, $v); 158 } 159 } 160 161 public function Styles_Scripts_Admin_Init(){ 162 if ( 163 $this->Is_PLL_Strings_Settings_Page() 164 || $this->Is_WP_Plugins_Page() 165 ){ 118 166 wp_enqueue_style(self::$prefix . 'admin', $this->Path_Get('plugin_url') . 'css/admin.css', array(), self::$plugin_version, 'all'); 119 167 wp_enqueue_script(self::$prefix . 'admin', $this->Path_Get('plugin_url') . 'js/admin.js', array('jquery'), self::$plugin_version); … … 121 169 } 122 170 123 public function Head_Admin_Init() 124 { 125 if (self::Is_PLL_Strings_Settings_Page()) 126 { 171 public function Head_Admin_Init(){ 172 if ($this->Is_PLL_Strings_Settings_Page()){ 127 173 ?> 128 174 <script type="text/javascript"> 129 if (typeof(window.<?php echo self::$prefix; ?>admin) == 'object') 130 { 175 if (typeof(window.<?php echo self::$prefix; ?>admin) == 'object'){ 131 176 window.<?php echo self::$prefix; ?>admin.attr.prefix = '<?php echo self::$prefix; ?>'; 132 177 window.<?php echo self::$prefix; ?>admin.attr.settings['search_plugins_strings'] = <?php echo ($this->Setting_Get('search_plugins_strings', 'bool') ? 'true' : 'false'); ?>; 133 178 <?php 134 179 135 if (defined('POLYLANG_VERSION') && (float)POLYLANG_VERSION < 2.1) 136 { 180 if ( 181 defined('POLYLANG_VERSION') 182 && (float)POLYLANG_VERSION < 2.1 183 ){ 137 184 ?> 138 185 window.<?php echo self::$prefix; ?>admin.attr.urls['polylang_strings'] = '<?php echo admin_url('options-general.php?page=mlang&tab=strings'); ?>'; 139 window.<?php echo self::$prefix; ?>admin.attr.urls['polylang_strings_theme_current'] = '<?php echo admin_url('options-general.php?page=mlang&tab=strings&s&group=' . __('Theme') . ': ' . wp_get_theme()->Name . '&paged=1'); ?>'; 186 window.<?php echo self::$prefix; ?>admin.attr.urls['polylang_strings_theme_current'] = '<?php echo admin_url('options-general.php?page=mlang&tab=strings&s&group=' . __('Theme', self::$prefix) . ': ' . wp_get_theme()->Name . '&paged=1'); ?>'; 187 window.<?php echo self::$prefix; ?>admin.attr.urls['polylang_plugins'] = '<?php echo admin_url('options-general.php?page=mlang&tab=strings&s&group=' . __('Plugins', self::$prefix) . '&paged=1'); ?>'; 140 188 <?php 141 189 } 142 else // for Polylang >= 2.1 143 { 190 else{ // for Polylang >= 2.1 144 191 ?> 145 192 window.<?php echo self::$prefix; ?>admin.attr.urls['polylang_strings'] = '<?php echo admin_url('admin.php?page=mlang_strings'); ?>'; 146 window.<?php echo self::$prefix; ?>admin.attr.urls['polylang_strings_theme_current'] = '<?php echo admin_url('admin.php?page=mlang_strings&s&group=' . __('Theme') . ': ' . wp_get_theme()->Name . '&paged=1'); ?>'; 193 window.<?php echo self::$prefix; ?>admin.attr.urls['polylang_strings_theme_current'] = '<?php echo admin_url('admin.php?page=mlang_strings&s&group=' . __('Theme', self::$prefix) . ': ' . wp_get_theme()->Name . '&paged=1'); ?>'; 194 window.<?php echo self::$prefix; ?>admin.attr.urls['polylang_plugins'] = '<?php echo admin_url('admin.php?page=mlang_strings&s&group=' . __('Plugins', self::$prefix) . '&paged=1'); ?>'; 147 195 <?php 148 196 } 149 197 150 198 ?> 151 152 window.<?php echo self::$prefix; ?>admin.lng[10] = '<?php _e('Polylang Theme Strings'); ?>'; 153 window.<?php echo self::$prefix; ?>admin.lng[11] = '<?php _e('works'); ?>'; 199 window.<?php echo self::$prefix; ?>admin.lng[10] = '<?php _e('Polylang Theme Strings', self::$prefix); ?>'; 200 window.<?php echo self::$prefix; ?>admin.lng[11] = '<?php _e('works', self::$prefix); ?>'; 154 201 window.<?php echo self::$prefix; ?>admin.lng[12] = '<?php echo self::$plugin_version; ?>'; 155 window.<?php echo self::$prefix; ?>admin.lng[20] = '<?php _e('Current theme polylang-strings detected' ); ?>';202 window.<?php echo self::$prefix; ?>admin.lng[20] = '<?php _e('Current theme polylang-strings detected', self::$prefix); ?>'; 156 203 window.<?php echo self::$prefix; ?>admin.lng[21] = '<?php echo $this->var['theme-strings-count'][$this->Path_Get('theme_dir_name')]; ?>'; 157 window.<?php echo self::$prefix; ?>admin.lng[30] = '<?php _e('All themes polylang-strings detected' ); ?>';204 window.<?php echo self::$prefix; ?>admin.lng[30] = '<?php _e('All themes polylang-strings detected', self::$prefix); ?>'; 158 205 window.<?php echo self::$prefix; ?>admin.lng[31] = '<?php echo array_sum($this->var['theme-strings-count']); ?>'; 159 window.<?php echo self::$prefix; ?>admin.lng[40] = '<?php _e('Plugin web-page'); ?>'; 160 window.<?php echo self::$prefix; ?>admin.lng[50] = '<?php _e('Donation'); ?>'; 161 window.<?php echo self::$prefix; ?>admin.lng[60] = '<?php _e('Please, give plugin feedback'); ?>'; 206 window.<?php echo self::$prefix; ?>admin.lng[35] = '<?php _e('All plugins polylang-strings detected', self::$prefix); ?>'; 207 window.<?php echo self::$prefix; ?>admin.lng[36] = '<?php echo $this->var['plugins-strings-count']; ?>'; 208 window.<?php echo self::$prefix; ?>admin.lng[40] = '<?php _e('Plugin web-page', self::$prefix); ?>'; 209 window.<?php echo self::$prefix; ?>admin.lng[50] = '<?php _e('Donation', self::$prefix); ?>'; 210 window.<?php echo self::$prefix; ?>admin.lng[60] = '<?php _e('Please, give plugin feedback', self::$prefix); ?>'; 162 211 163 212 jQuery(document).ready(function(){ … … 169 218 } 170 219 171 if (self::Is_WP_Plugins_Page()) 172 { 220 if ($this->Is_WP_Plugins_Page()){ 173 221 ?> 174 222 <script type="text/javascript"> 175 if (typeof(window.<?php echo self::$prefix; ?>admin) == 'object') 176 { 223 if (typeof(window.<?php echo self::$prefix; ?>admin) == 'object'){ 177 224 window.<?php echo self::$prefix; ?>admin.attr.urls['polylang_strings'] = '<?php 178 225 179 if (defined('POLYLANG_VERSION') && (float)POLYLANG_VERSION < 2.1) 180 { 226 if ( 227 defined('POLYLANG_VERSION') 228 && (float)POLYLANG_VERSION < 2.1 229 ){ 181 230 echo admin_url('options-general.php?page=mlang&tab=strings'); 182 231 } 183 else // for Polylang >= 2.1 184 { 232 else{ // for Polylang >= 2.1 185 233 echo admin_url('admin.php?page=mlang_strings'); 186 234 } … … 188 236 ?>'; 189 237 190 window.<?php echo self::$prefix; ?>admin.lng[70] = '<?php _e('Go to polylang-strings settings page'); ?>'; 238 window.<?php echo self::$prefix; ?>admin.attr.urls['polylang_theme_strings_settings'] = '<?php echo admin_url('admin.php?page=' . self::$prefix . 'settings'); ?>'; 239 240 window.<?php echo self::$prefix; ?>admin.lng[70] = '<?php _e('Go to strings translate page', self::$prefix); ?>'; 241 window.<?php echo self::$prefix; ?>admin.lng[71] = '<?php _e('Go to settings page', self::$prefix); ?>'; 242 window.<?php echo self::$prefix; ?>admin.lng[80] = '<?php _e('Required to install and activate the plugin', self::$prefix); ?>'; 243 window.<?php echo self::$prefix; ?>admin.lng[81] = '<?php _e('Polylang', self::$prefix); ?>'; 191 244 192 245 jQuery(document).ready(function(){ … … 199 252 } 200 253 201 public function Path_Get($key) 202 { 203 if (isset($this->paths[$key])) 204 { 254 public function Admin_Menus_Init(){ 255 if (is_admin()){ 256 add_submenu_page( 257 'mlang', 258 __('Settings', self::$prefix) . ' :: ' . __('Polylang Theme Strings', self::$prefix), 259 __('Polylang Theme Strings', self::$prefix), 260 'manage_options', 261 self::$prefix . 'settings', 262 array($this, 'Admin_Page_Settings') 263 ); 264 } 265 } 266 267 public function Admin_Page_Settings(){ 268 $tpl = $this->Path_Get('plugin_templates_path') . 'admin-page-settings.php'; 269 if (file_exists($tpl)) include_once($tpl); 270 } 271 272 public function Str_Filter($t_text, $ut_text, $domain){ 273 if ($domain != self::$pll_d){ 274 return __($ut_text, self::$pll_d); 275 } 276 else{ 277 return $t_text; 278 } 279 } 280 281 public function Setting_Get($key, $as = null){ 282 if (!isset($this->settings[$key])){ 283 $this->settings[$key] = get_option(self::$prefix . 'settings_' . $key); 284 285 switch (strtolower($as)){ 286 case 'bool': 287 $this->settings[$key] = ((int)$this->settings[$key] > 0 ? true : false); 288 break; 289 } 290 } 291 292 return $this->settings[$key]; 293 } 294 295 public function Path_Get($key){ 296 if (isset($this->paths[$key])){ 205 297 return $this->paths[$key]; 206 298 } 207 299 } 208 300 209 public static function Files_Recursive_Get($dir) 210 { 301 public function Files_Recursive_Get($dir){ 211 302 $files = array(); 212 303 213 if ($h = opendir($dir)) 214 { 215 while (($item = readdir($h)) !== false) 216 { 304 if ($h = opendir($dir)){ 305 while (($item = readdir($h)) !== false){ 217 306 $f = $dir . '/' . $item; 218 307 219 if (is_file($f) && filesize($f) <= self::$php_file_size_limit) 220 { 308 if ( 309 is_file($f) 310 && filesize($f) <= self::$php_file_size_limit 311 ){ 221 312 $files[] = $f; 222 313 } 223 else 224 if (is_dir($f) && !preg_match("/^[\.]{1,2}$/uis", $item)) 225 { 226 $files = array_merge($files, self::Files_Recursive_Get($f)); 314 else if ( 315 is_dir($f) 316 && !preg_match("/^[\.]{1,2}$/uis", $item) 317 ){ 318 $files = array_merge($files, $this->Files_Recursive_Get($f)); 227 319 } 228 320 } … … 234 326 } 235 327 236 public static function PLL_Exists_Check() 237 { 238 if (is_admin() && !function_exists(self::$pll_f)) 239 { 240 add_action('admin_notices', array(__CLASS__, 'Notice_PLL_Not_Exists')); 241 } 242 } 243 244 public static function Notice_PLL_Not_Exists() 245 { 246 ?> 247 <div class="notice notice-warning"> 248 <p> 249 <b><?php printf(__('Base plugin %1$s is not defined'), '"Polylang"'); ?></b>.<br /> 250 <?php printf(__('You need install and activate base plugin %1$s for works of plugin %2$s'), '<a href="https://wordpress.org/plugins/polylang" target="_blank">Polylang</a>', '<a href="https://wordpress.org/plugins/polylang-theme-strings" target="_blank">Polylang Theme Strings</a>'); ?>. 251 </p> 252 </div> 253 <?php 254 } 255 256 public static function Is_PLL_Strings_Settings_Page() 257 { 258 if 259 ( 260 is_admin() && 261 function_exists(self::$pll_f) && 262 isset($_REQUEST['page']) && 263 ( 264 ($_REQUEST['page'] == 'mlang' && isset($_REQUEST['tab']) && $_REQUEST['tab'] == 'strings') || 265 $_REQUEST['page'] == 'mlang_strings' // for Polylang >= 2.1 266 ) 267 ) 268 { 269 return true; 270 } 271 } 272 273 public static function Is_WP_Plugins_Page() 274 { 275 if (preg_match("/\/plugins.php[^a-z0-9]?/uis", $_SERVER['REQUEST_URI'])) 276 { 277 return true; 278 } 279 } 280 281 private static function Themes_PLL_Strings_Scan() 282 { 283 $themes = wp_get_themes(); 284 285 if (count($themes)) 286 { 287 foreach ($themes as $theme_dir_name => $theme) 288 { 289 $data = array( 290 'name' => $theme->Name, 291 'strings' => array() 292 ); 293 294 $theme_path = $theme->theme_root . '/' . $theme_dir_name; 295 296 if (file_exists($theme_path)) 297 { 298 $files = self::Files_Recursive_Get($theme_path); 299 300 foreach($files as $v) 301 { 302 if (preg_match("/\/.*?\.(php[0-9]?|inc)$/uis", $v)) 303 { 304 preg_match_all("/(?:\<\?.*?\?\>)|(?:\<\?.*?[^\?]+[^\>]+)/uis", file_get_contents($v), $p); 305 306 if (count($p[0])) 307 { 308 foreach ($p[0] as $pv) 309 { 310 preg_match_all("/pll_[_e][\s]*\([\s]*[\'\"](.*?)[\'\"][\s]*[\),]/uis", $pv, $m); 311 312 if (count($m[0])) 313 { 314 foreach ($m[1] as $mv) 315 { 316 if (!in_array($mv, $data)) 317 { 318 $data['strings'][] = $mv; 319 } 320 } 328 public function Files_PLL_Strings_Parse($dir){ 329 $strings = array(); 330 $files = $this->Files_Recursive_Get($dir); 331 332 if (is_array($files) && count($files)){ 333 foreach($files as $v){ 334 if (preg_match("/\/.*?\.(php[0-9]?|inc)$/uis", $v)){ 335 preg_match_all("/(?:\<\?.*?\?\>)|(?:\<\?.*?[^\?]+[^\>]+)/uis", file_get_contents($v), $p); 336 337 if (count($p[0])){ 338 foreach ($p[0] as $pv){ 339 if ($this->Setting_Get('search_native_wp_functions', 'bool')){ 340 $pattern = "/[\s]+(?:pll|)_[_e][\s]*\([\s]*[\'\"](.*?)[\'\"][\s]*[\),]/uis"; 341 } 342 else{ 343 $pattern = "/pll_[_e][\s]*\([\s]*[\'\"](.*?)[\'\"][\s]*[\),]/uis"; 344 } 345 346 preg_match_all($pattern, $pv, $m); 347 348 if ( 349 is_array($m) 350 && isset($m[1]) 351 && count($m[1]) 352 ){ 353 foreach ($m[1] as $mv){ 354 if (!in_array($mv, $strings)){ 355 $strings[] = $mv; 321 356 } 322 357 } … … 324 359 } 325 360 } 326 327 update_option(self::$prefix . $theme_dir_name . '_data', $data); 328 } 329 } 330 } 331 } 332 333 public function Theme_Current_PLL_Strings_Init() 334 { 335 $data = get_option(self::$prefix . $this->Path_Get('theme_dir_name') . '_data'); 336 337 if (is_array($data) && is_array($data['strings']) && count($data['strings'])) 338 { 339 foreach ($data['strings'] as $v) 340 { 341 pll_register_string($v, $v, __('Theme') . ': ' . $data['name']); 342 } 343 } 344 } 345 346 public function Themes_PLL_Strings_Init() 347 { 361 } 362 } 363 } 364 365 return $strings; 366 } 367 368 public function PLL_Exists_Check(){ 369 if ( 370 is_admin() 371 && !function_exists(self::$pll_f) 372 ){ 373 add_action('admin_notices', array($this, 'Notice_PLL_Not_Exists')); 374 } 375 } 376 377 public function Notice_PLL_Not_Exists(){ 378 ?> 379 <div class="notice notice-warning"> 380 <p> 381 <b><?php printf(__('Base plugin %1$s is not defined', self::$prefix), '"Polylang"'); ?></b>.<br /> 382 <?php printf(__('You need install and activate base plugin %1$s for works plugin %2$s', self::$prefix), '<a href="https://wordpress.org/plugins/polylang" target="_blank">Polylang</a>', '<a href="https://wordpress.org/plugins/polylang-theme-strings" target="_blank">Polylang Theme Strings</a>'); ?>. 383 </p> 384 </div> 385 <?php 386 } 387 388 public function Is_PLL_Strings_Settings_Page(){ 389 if ( 390 is_admin() 391 && function_exists(self::$pll_f) 392 && isset($_REQUEST['page']) 393 && ( 394 ($_REQUEST['page'] == 'mlang' && isset($_REQUEST['tab']) && $_REQUEST['tab'] == 'strings') 395 || $_REQUEST['page'] == 'mlang_strings' // for Polylang >= 2.1 396 ) 397 ){ 398 return true; 399 } 400 } 401 402 public function Is_WP_Plugins_Page(){ 403 if (preg_match("/\/plugins.php[^a-z0-9]?/uis", $_SERVER['REQUEST_URI'])){ 404 return true; 405 } 406 } 407 408 private function Themes_PLL_Strings_Scan(){ 348 409 $themes = wp_get_themes(); 349 410 350 if (count($themes)) 351 { 352 foreach ($themes as $theme_dir_name => $theme) 353 { 354 $data = get_option(self::$prefix . $theme_dir_name . '_data'); 411 if (count($themes)){ 412 foreach ($themes as $theme_dir_name => $theme){ 413 $data = array( 414 'name' => $theme->Name, 415 'strings' => array() 416 ); 417 418 $theme_path = $theme->theme_root . '/' . $theme_dir_name; 419 420 if (file_exists($theme_path)){ 421 $data['strings'] = $this->Files_PLL_Strings_Parse($theme_path); 422 update_option(self::$prefix . 'theme_' . $theme_dir_name . '_data', $data); 423 } 424 } 425 } 426 } 427 428 private function Plugins_PLL_Strings_Scan(){ 429 if ( 430 $this->Setting_Get('search_plugins_strings', 'bool') 431 && defined('WP_PLUGIN_DIR') 432 && file_exists(WP_PLUGIN_DIR) 433 ){ 434 $data = array('strings' => $this->Files_PLL_Strings_Parse(WP_PLUGIN_DIR)); 435 update_option(self::$prefix . 'plugins_data', $data); 436 } 437 } 438 439 public function Theme_Current_PLL_Strings_Init(){ 440 $data = get_option(self::$prefix . 'theme_' . $this->Path_Get('theme_dir_name') . '_data'); 441 442 if ( 443 is_array($data) 444 && is_array($data['strings']) 445 && count($data['strings']) 446 ){ 447 foreach ($data['strings'] as $v){ 448 pll_register_string($v, $v, __('Theme', self::$prefix) . ': ' . $data['name']); 449 } 450 } 451 } 452 453 public function Themes_PLL_Strings_Init(){ 454 $themes = wp_get_themes(); 455 456 if (count($themes)){ 457 foreach ($themes as $theme_dir_name => $theme){ 458 $data = get_option(self::$prefix . 'theme_' . $theme_dir_name . '_data'); 355 459 $tsc = &$this->var['theme-strings-count'][$theme_dir_name]; 356 460 $tsc = 0; 357 461 358 if (is_array($data) && is_array($data['strings']) && count($data['strings'])) 359 { 360 foreach ($data['strings'] as $v) 361 { 362 pll_register_string($v, $v, __('Theme') . ': ' . $data['name']); 462 if ( 463 is_array($data) 464 && is_array($data['strings']) 465 && count($data['strings']) 466 ){ 467 foreach ($data['strings'] as $v){ 468 pll_register_string($v, $v, __('Theme', self::$prefix) . ': ' . $data['name']); 363 469 } 364 470 … … 368 474 } 369 475 } 476 477 public function Plugins_PLL_Strings_Init(){ 478 if ($this->Setting_Get('search_plugins_strings', 'bool')){ 479 $data = get_option(self::$prefix . 'plugins_data'); 480 $tsc = &$this->var['plugins-strings-count']; 481 $tsc = 0; 482 483 if ( 484 is_array($data) 485 && is_array($data['strings']) 486 && count($data['strings']) 487 ){ 488 foreach ($data['strings'] as $v){ 489 pll_register_string($v, $v, __('Plugins', self::$prefix)); 490 } 491 492 $tsc = count($data['strings']); 493 } 494 } 495 } 370 496 } -
polylang-theme-strings/trunk/readme.txt
r1727898 r1925069 3 3 Donate link: http://modeewine.com/en-donation 4 4 Tags: extension, polylang, multilingual, translate, translation, language, multilanguage, international, localization 5 Requires at least: 3.86 Tested up to: 4. 8.17 Stable tag: 3.55 Requires at least: 4.0 6 Tested up to: 4.9.8 7 Stable tag: 4.0 8 8 License: GPL2 9 9 … … 14 14 = What is «Polylang Theme Strings» and what for is it? = 15 15 16 This plugin gives additional features to the plugin Polylang. It automatically scans all templates files and scripts of the active WP theme for available strings that can be translated. For example:16 This plugin gives additional features to the plugin Polylang. It automatically scans all templates files and scripts of the active WP theme (and all plugins) for available strings that can be translated. For example: 17 17 18 18 * `pll__('...');` … … 27 27 28 28 Like you can see, the «Polylang Theme Strings» is perfectly integrate with the «Polylang» plugin and works in automatically mode – it is comfortable, simple, and useful! 29 30 From version 4.0 «Polylang Theme Strings» got settings page where you can configure the search strings-translations more deeply. 29 31 30 32 Learn more in <http://modeewine.com/en-polylang-theme-strings>. … … 45 47 46 48 == Changelog == 49 50 = 4.0 (2018-08-15) = 51 52 * Integrated new feature: include the search for native string functions of WordPress (configurable on setting page). 53 * Integrated new feature: include the search of strings-translation for WordPress plugins (configurable on setting page). 54 * Merged the menu of «Polylang» and «Polylang Theme Strings». 55 * Own plugin settings page. 56 * Fixed small bug in the theme-files search-system. 57 * Tested and optimized compatibility up to WordPress 4.9.8. 58 * Tested and optimized compatibility up to Polylang 2.3.9. 59 * Improved code. 47 60 48 61 = 3.5 (2017-09-11) =
Note: See TracChangeset
for help on using the changeset viewer.