Plugin Directory

Changeset 2789383


Ignore:
Timestamp:
09/23/2022 03:25:21 PM (4 years ago)
Author:
masterhomepage
Message:

Addign Turkish, Ukrainian and Indonesian languages

Location:
automatic-translation/trunk
Files:
3 added
10 edited

Legend:

Unmodified
Added
Removed
  • automatic-translation/trunk/assets/languages.json

    r2760104 r2789383  
    155155        "code": "zh",
    156156        "image" : "zh.svg"
     157    },
     158    "tr": {
     159        "name": "Turkish",
     160        "original_name": "Türkçe",
     161        "code": "tr"
     162    },
     163    "id": {
     164        "name": "Indonesian",
     165        "original_name": "Indonesian",
     166        "code": "id"
     167    },
     168    "uk": {
     169        "name": "Ukrainian",
     170        "original_name": "Українська",
     171        "code": "uk"
    157172    }
    158 
    159173}
  • automatic-translation/trunk/readme.txt

    r2780020 r2789383  
    66Tested up to: 6.0
    77Requires PHP: 7.0
    8 Stable tag: 1.0.1
     8Stable tag: 1.0.3
    99License: GPLv2 or later
    1010License URI: https://www.gnu.org/licenses/gpl-2.0.html
     
    8383== Changelog ==
    8484
     85= 1.0.3 =
     86* Addign Turkish, Ukrainian and Indonesian languages
     87
     88= 1.0.2 =
     89* Translation cache refactoring
     90
    8591= 1.0.1 =
    8692* Bugfix : Fixed an issue
  • automatic-translation/trunk/src/admin/scripts.php

    r2760104 r2789383  
    224224    $options = translatorGetOptions();
    225225    if(isset($options["translator_api_token"])){
    226    
    227 
    228226        if(isset($post->post_type) && ($post->post_type == "page" || $post->post_type == "post")){
    229 
    230            $link =  get_permalink($post->ID);
    231 
    232            if(isset($options["languages_enabled"])){
    233                 foreach ($options["languages_enabled"] as $key => $languages_enabled) {
    234 
    235 
    236                         $uri_path =  str_replace(home_url(), "", $link);
    237 
    238                         global $wpdb;
    239 
    240                         $translator_urls_table= $wpdb->prefix."translator_urls";
    241 
    242                         $urlls = $wpdb->get_results("select translation,source from `$translator_urls_table` where source = '$uri_path' AND language = '$languages_enabled'");
    243 
    244                         if(empty($urlls)){
    245 
    246                             $uri_path =  str_replace(home_url(), "", $link);
    247 
    248                             $uri_path =  rtrim($uri_path,"/");
    249 
    250                             $urlls = $wpdb->get_results("select translation,source from `$translator_urls_table` where source = '$uri_path' AND language = '$languages_enabled'");
    251 
    252                         }
    253 
    254 
    255                        
    256 
    257 
    258                        
    259 
    260 
    261 
    262                         foreach ($urlls as $key => $urll) {
    263                            
    264                             if(isset($options["translator_api_token"])){
    265 
    266                                 $translated_url1 = $urll->translation;
    267                                 $translated_hash_path =  $languages_enabled."_".md5(trim($translated_url1));
    268 
    269 
    270                                
    271 
    272                            
    273                                 $token_hash = md5('data'.$options["translator_api_token"]);
    274                                 $file_hash =  TRANSLATOR_PLUGIN_PATH."vendor/translator/script-php/".$token_hash."/cache/".$translated_hash_path.".php";
    275                                 if(file_exists($file_hash)){
    276 
    277                                     unlink($file_hash);
    278                                     $success++;
    279                                     /*$files = glob($file_hash . '*.php');
    280                                     foreach($files as $file) {
    281                                         unlink($file);
    282                                     }*/
    283                                 }
    284 
    285 
    286                                 $translated_url2 = "/".$languages_enabled.$urll->source;
    287                                 $translated_hash_path2 =  $languages_enabled."_".md5(trim($translated_url2));
    288                                
    289 
    290                                  $file_hash2 =  TRANSLATOR_PLUGIN_PATH."vendor/translator/script-php/".$token_hash."/cache/".$translated_hash_path2.".php";
    291                                  if(file_exists($file_hash2)){
    292                                    
    293                                     unlink($file_hash2);
    294                                     $success++;
    295                                     /*$files = glob($file_hash . '*.php');
    296                                     foreach($files as $file) {
    297                                         unlink($file);
    298                                     }*/
    299                                  }
    300 
    301 
    302 
    303                             }
    304 
    305                         } 
    306                    
    307                 }
    308             }
    309 
    310             if($success != 0){
     227            $link = get_permalink($post->ID);
     228            $uri_path = str_replace(home_url(), "", $link);
     229            $opstat = TranslatorConfiguration::sourceDeleteCacheComp($uri_path);
     230            if (!isset($opstat['removed']) || !$opstat['removed']) {
     231                $opstat = TranslatorConfiguration::sourceDeleteCacheComp(rtrim($uri_path, "/"));
     232            }
     233            if ((isset($opstat['removed']) && $opstat['removed'])) {
    311234                deleteCacheApiHit("Cache clear from page save");
    312235            }
    313236        }else{
    314        
    315             $token_hash = md5('data'.$options["translator_api_token"]);
    316             $file_hash =  TRANSLATOR_PLUGIN_PATH."vendor/translator/script-php/".$token_hash."/cache/";
    317             if(file_exists($file_hash)){
    318                 $files = glob($file_hash . '*.php');
    319                 foreach($files as $file) {
    320                     $success++;
    321                     unlink($file);
    322                 }
    323             }
    324             if($success != 0){
    325                 deleteCacheApiHit("Cache clear from save data");
    326             }
     237            \Translator\Vendor\Translator\Script\Core\Cache::getInstance()->clear_cache();
     238            deleteCacheApiHit("Cache clear from save data");
    327239        }
    328240    }
  • automatic-translation/trunk/src/configuration.php

    r2760104 r2789383  
    225225
    226226    public function deleteCache($url_id){
    227 
    228         $message = "";
    229         if($url_id != ""){
    230 
     227        $message = '';
     228        if(!empty($url_id)){
    231229            global $wpdb;
    232230            $translator_urls_table= $wpdb->prefix."translator_urls";
     
    235233                $url_id
    236234            );
    237 
    238235            $source = $wpdb->get_row($query1);
    239236
    240 
    241             if($source){
    242 
    243                 $this->sourceDeleteCacheComp($source->source);
    244 
    245                 $query2 = $wpdb->prepare(
    246                     "select translation,language from `$translator_urls_table` where `source` = %s",
    247                     $source->source
    248                 );
    249 
    250                 $urlss = $wpdb->get_results($query2);
    251                
    252                 $this->deleteCacheComp($urlss);
    253 
    254                 $url_hit = home_url().$source->source;
    255 
    256                 $message = "Delete Cache from url (". $url_hit.")";
    257 
     237            if(isset($source->source)){
     238                self::sourceDeleteCacheComp($source->source);
     239                $message = "Delete Cache from url (". home_url().$source->source.")";
    258240                $this->deleteCacheFromCompHit($message);
    259 
    260241                $message = "Cache clear successfully!";
    261 
    262 
    263                
    264             }
    265         }   
    266 
     242            }
     243        }
    267244        return $message;
    268245    }
    269246
    270     public function sourceDeleteCacheComp($urll){
    271 
    272 
    273 
     247    public static function sourceDeleteCacheComp($urll){
    274248        $options = translatorGetOptions();
    275249
    276 
    277 
    278 
    279 
    280 
    281         if(isset($options["languages_enabled"])){
    282             foreach ($options["languages_enabled"] as $key => $languages_enabled) {
    283 
    284 
    285 
    286                    
    287 
    288                         $url2 = "/".$languages_enabled.$urll;
    289                  
    290 
    291                         $translated_hash_path =  $languages_enabled."_".md5(trim($url2));
    292                        
    293 
    294                         if(isset($options["translator_api_token"])){
    295                              $token_hash = md5('data'.$options["translator_api_token"]);
    296                              $file_hash =  TRANSLATOR_PLUGIN_PATH."vendor/translator/script-php/".$token_hash."/cache/".$translated_hash_path.".php";
    297                              if(file_exists($file_hash)){
    298                                
    299                                 unlink($file_hash);
    300 
    301                              }
    302                         }
    303 
    304                    
    305                
    306             }
    307         }
    308                  
    309                
     250        $opstat = ['removed'=>0, 'failed'=>0];
     251        if(isset($options["translator_api_token"])){
     252            $token_hash = md5('data'.$options["translator_api_token"]);
     253
     254            $folder = TRANSLATOR_PLUGIN_PATH."vendor/translator/script-php/".$token_hash."/cache/". md5(trim($urll));
     255            $files = glob($folder . '/*.php');
     256            foreach($files as $file) {
     257                if(@unlink($file)) {
     258                    $opstat['removed']++;
     259                } else {
     260                    $opstat['failed']++;
     261                }
     262            }
     263            if(@rmdir($folder)) {
     264                $opstat['removed']++;
     265            } else {
     266                $opstat['failed']++;
     267            }
     268        }
     269        return $opstat;
    310270    }
    311271
  • automatic-translation/trunk/translator.php

    r2780021 r2789383  
    44 * Plugin URI: https://automatic-translation.online/
    55 * Description: Automatic translation plugin used to translate frontend website content with Deepl machine translator.
    6  * Version: 1.0.1
     6 * Version: 1.0.3
    77 * Text Domain: automatic-translation.online
    88 * Author: masterhomepage
     
    3838}
    3939
    40 define('TRANSLATOR_VERSION', '1.0.1');
     40define('TRANSLATOR_VERSION', '1.0.3');
    4141define('TRANSLATOR_PLUGIN_URL', plugin_dir_url(__FILE__));
    4242define('TRANSLATOR_PLUGIN_PATH', plugin_dir_path(__FILE__));
  • automatic-translation/trunk/vendor/translator/script-php/composer.json

    r2760104 r2789383  
    66  "authors": [
    77    {
    8       "name": "Translator",
    9       "email": "dev@translator.com"
     8      "name": "Automatic Translation",
     9      "email": "info@automatic-translation.online"
    1010    }
    1111  ],
     
    1818    "preferred-install": {
    1919      "*": "dist"
    20     },
    21     "platform-check": false
     20    }
    2221  },
    2322  "require": {
  • automatic-translation/trunk/vendor/translator/script-php/src/Cache.php

    r2760104 r2789383  
    5656    }
    5757
     58    private function getHash($request_url, $language=null) {
     59        if (!$language) {
     60            $language = Request::getInstance()->getLanguage();
     61        }
     62        $url = '/'.ltrim($request_url, '/' . $language);
     63        $folder = $this->getCacheFolder($url);
     64        $params = [];
     65
     66        sort($params);
     67
     68        return $folder . DIRECTORY_SEPARATOR . $language . '_' . md5(implode('', $params));
     69    }
     70
     71    private function getCacheFolder($request_url) {
     72        return md5(trim($request_url));
     73    }
     74
    5875    public function serve() {
    5976
     
    6986        $request_url = Request::getInstance()->getRequestedUrl();
    7087        $request_url = str_replace(home_url(), "", $request_url);
    71         $this->_hash = md5(trim($request_url));
     88//        $this->_hash = md5(trim($request_url));
     89        $this->_hash = $this->getHash($request_url);
    7290
    7391      //  $this->_hash = md5(trim(Request::getInstance()->getRequestedUrl()));
     
    117135
    118136                $tr_url = "/".$language.$urls_d1->source;
    119                 $this->_hash = md5(trim($tr_url));
    120 
     137//                $this->_hash = md5(trim($tr_url));
     138                $this->_hash = $this->getHash(trim($tr_url));
    121139                if (!$this->load()) {
    122140                   
     
    200218        }*/
    201219
    202         $cache_file = Configuration::getInstance()->get('data_dir') . DIRECTORY_SEPARATOR . 'cache' . DIRECTORY_SEPARATOR . $this->_language . '_' . $this->_hash . '.php';
    203 
     220        $cache_file = $this->getPath() . $this->_hash . '.php';
    204221        if (!file_exists($cache_file)) {
    205222            return false;
     
    230247        }
    231248
    232         $cache_path = $this->getPath();
    233         $cache_file = $cache_path . $this->_language . '_' . $this->_hash . '.php';
     249        $cache_file = $this->getPath() . $this->_hash . '.php';
     250        $cache_path = pathinfo($cache_file, PATHINFO_DIRNAME);
    234251
    235252        if (!file_exists($cache_path)) {
     
    265282        $cache_path = $this->getPath();
    266283
    267         $files = glob($cache_path . '*.php');
    268 
    269         usort($files, function($x, $y) {
    270             return filemtime($x) < filemtime($y);
    271         });
    272 
    273         $max_size = Configuration::getInstance()->get('cache_max_size') * 1024 * 1024;
     284        $folders = scandir($cache_path);
     285        if (!count($folders)) return;
     286        $folders = array_diff($folders, ['.', '..']);
     287        if (!count($folders)) return;
     288
    274289        $total_size = 0;
    275290        $total_cleared = 0;
    276         foreach($files as $file) {
    277             if ($total_size > $max_size) {
    278                 unlink($file);
    279                 continue;
     291        foreach($folders as $folder) {
     292            $files = glob($cache_path . $folder . '/*.php');
     293            foreach($files as $file) {
     294                $size = filesize($file);
     295                $total_cleared += $size;
     296                $total_size += $size;
     297                @unlink($file);
    280298            }
    281             $size = filesize($file);
    282             $total_cleared += $size;
    283             $total_size += $size;
     299            @rmdir($cache_path . $folder);
    284300        }
    285301
     
    293309    public function clear_cache(){
    294310        $cache_path = $this->getPath();
    295         $files = glob($cache_path . '*.php');
    296 
    297         usort($files, function($x, $y) {
    298             return filemtime($x) < filemtime($y);
    299         });
    300 
    301         foreach($files as $file) {
    302           //  unlink($file);
     311
     312        $folders = scandir($cache_path);
     313        if (!count($folders)) return;
     314        $folders = array_diff($folders, ['.', '..']);
     315        if (!count($folders)) return;
     316
     317        foreach($folders as $folder) {
     318            $files = glob($cache_path . $folder . '/*.php');
     319            foreach($files as $file) {
     320                $x = $file;
     321                @unlink($file);
     322            }
     323            @rmdir($cache_path . $folder);
    303324        }
    304325    }
  • automatic-translation/trunk/vendor/translator/script-php/src/Databases/Mysql.php

    r2760104 r2789383  
    139139            $elements = array();
    140140            foreach ($urlll as $source => $translation) {
     141                if (trim($source)==trim($translation)) continue; // source identical to target is not allowed
    141142                $source = str_replace($requested_path, '', $source);
    142143                $translation = str_replace($requested_path, '', $translation);
    143144                $elements[] = '("'.mysqli_real_escape_string($this->_database, Request::getInstance()->getLanguage()).'", "'.mysqli_real_escape_string($this->_database, $source).'", "'.mysqli_real_escape_string($this->_database, $translation).'", "'.md5($source).'", "'.md5($translation).'")';
    144145            }
    145             $query .= implode(',', $elements);
    146             $query .= ' ON DUPLICATE KEY UPDATE source=VALUES(source), translation=VALUES(translation), hash_source=VALUES(hash_source), hash_translation=VALUES(hash_translation)';
    147             $this->_database->query($query);
     146            if(count($elements)) {
     147                $query .= implode(',', $elements);
     148                $query .= ' ON DUPLICATE KEY UPDATE source=VALUES(source), translation=VALUES(translation), hash_source=VALUES(hash_source), hash_translation=VALUES(hash_translation)';
     149                $this->_database->query($query);
     150            }
    148151        }
    149152    }
  • automatic-translation/trunk/vendor/translator/script-php/src/Processor.php

    r2760104 r2789383  
    5151        }
    5252
     53    // Normalize language in request url to avoid duplicate content and redirect loop
     54        $norm_url = Request::getInstance()->getLanguageNormalizedURL();
     55        if (strlen($norm_url['url'])!=strlen(rtrim($norm_url['normurl'],'/'))) {
     56            Response::getInstance()->setRedirect($norm_url['normurl']);
     57            Response::getInstance()->end();
     58        }
     59
    5360        Debug::log('$_SERVER: ' . print_r(array_merge($_SERVER, ['PHP_AUTH_PW' => '', 'HTTP_AUTHORIZATION' =>  '', 'HTTP_COOKIE' => '']), true), 5);
    5461
     
    7986        $contents = Response::getInstance()->getContent();
    8087        $contents = str_replace('&nbsp;','<nbsp></nbsp>',$contents);
     88
     89        //HOTFIX: invalid html closing tag in javascript
     90        $matches = [];
     91        preg_match_all('/<script([\S\s]*?)<\/script>/i', $contents, $matches, PREG_SET_ORDER, 0);
     92        foreach($matches as $match) {
     93            if(count($match)==2) {
     94                $script = trim(array_shift($match));
     95                $inner_script = trim(array_shift($match));
     96                $replacement = str_replace('</', '<\/',$inner_script);
     97                $contents = str_replace($script, str_replace($inner_script, $replacement, $script), $contents);
     98            }
     99        }
     100
    81101        Response::getInstance()->setContent($contents);
    82102
  • automatic-translation/trunk/vendor/translator/script-php/src/Request.php

    r2760104 r2789383  
    132132
    133133    /**
     134     * Retrieve language normalized url
     135     */
     136    public function getLanguageNormalizedURL() {
     137        $url = $this->getPathname(true);
     138        // Detect nested language request and redirect to source
     139        $options = translatorGetOptions();
     140        if(isset($options["languages_enabled"])){
     141            $paths = explode('/', $url);
     142            $paths_count = count($paths);
     143            foreach($paths as $key=>$value) {
     144                if (empty($value) || in_array(strtolower($value), $options["languages_enabled"])) {
     145                    unset($paths[$key]);
     146                } else {
     147                    break;
     148                }
     149            }
     150            if (count($paths)!=$paths_count) {
     151                $url = rtrim((count($paths)?implode('/', $paths):''), '/');
     152            }
     153        }
     154        return ['url'=> '/' . $this->getLanguage() . $this->getPathname(false),'normurl'=>'/' . $this->getLanguage() . '/' . $url];
     155    }
     156
     157    /**
    134158     * Retrieve current multilingual non translated url
    135159     *
Note: See TracChangeset for help on using the changeset viewer.