Changeset 483


Ignore:
Timestamp:
08/06/2010 01:12:07 AM (18 months ago)
Author:
ofer
Message:

Fix #114 - phrase was incorrectly spelled, spilt third party support functions to their own file

Location:
trunk/WordPress/plugin/transposh
Files:
1 added
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/WordPress/plugin/transposh/core/parser.php

    r480 r483  
    282282 
    283283    /** 
    284      * Create a pharse tag in the html dom tree 
    285      * @param int $start - beginning of pharse in element 
    286      * @param int $end - end of pharse in element 
     284     * Create a phrase tag in the html dom tree 
     285     * @param int $start - beginning of phrase in element 
     286     * @param int $end - end of phrase in element 
    287287     */ 
    288288    function tag_phrase($string, $start, $end) { 
  • trunk/WordPress/plugin/transposh/transposh.php

    r479 r483  
    4646require_once("wp/transposh_postpublish.php"); 
    4747require_once("wp/transposh_backup.php"); 
     48require_once("wp/transposh_3rdparty.php"); 
    4849 
    4950/** 
     
    6364    /** @var transposh_postpublish Happens after editing */ 
    6465    public $postpublish; 
     66    /** @var transposh_3rdparty Happens after editing */ 
     67    private $third_party; 
    6568 
    6669    // list of properties 
     
    9699        $this->widget = new transposh_plugin_widget($this); 
    97100        $this->postpublish = new transposh_postpublish($this); 
     101        $this->third_party = new transposh_3rdparty($this); 
    98102 
    99103        // "global" vars 
     
    132136        add_action('wp_print_scripts', array(&$this, 'add_transposh_js')); 
    133137//        add_action('wp_head', array(&$this,'add_transposh_async')); 
    134         add_action("sm_addurl", array(&$this, 'add_sm_transposh_urls')); 
    135138        add_action('transposh_backup_event', array(&$this, 'run_backup')); 
    136139        add_action('comment_post', array(&$this, 'add_comment_meta_settings'), 1); 
     
    140143        add_filter('the_title', array(&$this, 'post_wrap')); 
    141144 
    142         // buddypress compatability 
    143         add_filter('bp_uri', array(&$this, 'bp_uri_filter')); 
    144         add_filter('bp_get_activity_content_body', array(&$this, 'bp_get_activity_content_body'), 10, 2); 
    145         add_action('bp_activity_after_save', array(&$this, 'bp_activity_after_save')); 
    146         add_action('transposh_human_translation', array(&$this, 'transposh_buddypress_stream'), 10, 3); 
    147  
    148145        //TODO add_action('manage_comments_nav', array(&$this,'manage_comments_nav')); 
    149146        //TODO comment_row_actions (filter) 
     147        // toying around the mo/po stuff 
     148        add_filter('gettext', array(&$this, 'transposh_gettext_filter'), 10, 3); 
     149        add_filter('locale', array(&$this, 'transposh_locale_filter')); 
     150 
    150151 
    151152        register_activation_hook(__FILE__, array(&$this, 'plugin_activate')); 
     
    706707 
    707708    /** 
    708      * This function integrates with google sitemap generator, and adds for each viewable language, the rest of the languages url 
    709      * Also - priority is reduced by 0.2 
    710      * And this requires the following line at the sitemap-core.php, add-url function (line 1509 at version 3.2.2) 
    711      * do_action('sm_addurl', &$page); 
    712      * @param GoogleSitemapGeneratorPage $sm_page Object containing the page information 
    713      */ 
    714     function add_sm_transposh_urls(&$sm_page) { 
    715         logger("in sitemap add url: " . $sm_page->GetUrl() . " " . $sm_page->GetPriority()); 
    716         // we need the generator object (we know it must exist...) 
    717         $generatorObject = &GoogleSitemapGenerator::GetInstance(); 
    718         // we reduce the priorty by 0.2, but not below zero 
    719         $sm_page->SetProprity(max($sm_page->GetPriority() - 0.2, 0)); 
    720  
    721         $viewable_langs = explode(',', $this->options->get_viewable_langs()); 
    722         $orig_url = $sm_page->GetUrl(); 
    723         foreach ($viewable_langs as $lang) { 
    724             if (!$this->options->is_default_language($lang)) { 
    725                 $newloc = $orig_url; 
    726                 if ($this->options->get_enable_url_translate()) { 
    727                     $newloc = translate_url($newloc, $this->home_url, $lang, array(&$this->database, 'fetch_translation')); 
    728                 } 
    729                 $newloc = rewrite_url_lang_param($newloc, $this->home_url, $this->enable_permalinks_rewrite, $lang, false); 
    730                 $sm_page->SetUrl($newloc); 
    731                 $generatorObject->AddElement($sm_page); 
    732             } 
    733         } 
    734     } 
    735  
    736     /** 
    737709     * Runs a scheduled backup 
    738710     */ 
     
    766738        return $url; 
    767739    } 
    768  
    769     /** 
    770      * This filter method helps buddypress understand the transposh generated URLs 
    771      * @param string $uri The url that was originally received 
    772      * @return string The url that buddypress should see 
    773      */ 
    774     function bp_uri_filter($uri) { 
    775         $lang = get_language_from_url($uri, $this->home_url); 
    776         $uri = cleanup_url($uri, $this->home_url); 
    777         if ($this->options->get_enable_url_translate()) { 
    778             $uri = get_original_url($uri, '', $lang, array($this->database, 'fetch_original')); 
    779         } 
    780         return $uri; 
    781     } 
    782  
    783     /** 
    784      * After saving action, makes sure activity has proper language 
    785      * @param BP_Activity_Activity $params 
    786      */ 
    787     function bp_activity_after_save($params) { 
    788         // we don't need to modify our own activity stream 
    789         if ($params->type == 'new_translation') return; 
    790         if (get_language_from_url($_SERVER['HTTP_REFERER'], $this->home_url)) 
    791                 bp_activity_update_meta($params->id, 'tp_language', get_language_from_url($_SERVER['HTTP_REFERER'], $this->home_url)); 
    792     } 
    793  
    794     /** 
    795      * Change the display of activity content using the transposh meta 
    796      * @param string $content 
    797      * @param BP_Activity_Activity $activity 
    798      * @return string modified content 
    799      */ 
    800     function bp_get_activity_content_body($content, $activity) { 
    801         $activity_lang = bp_activity_get_meta($activity->id, 'tp_language'); 
    802         if ($activity_lang) { 
    803             $content = "<span lang =\"$activity_lang\">" . $content . "</span>"; 
    804         } 
    805         return $content; 
    806     } 
    807  
    808     /** 
    809      * Add an item to the activity string upon translation 
    810      * @global object $bp the global buddypress 
    811      * @param string $translation 
    812      * @param string $original 
    813      * @param string $lang 
    814      */ 
    815     function transposh_buddypress_stream($translation, $original, $lang) { 
    816         global $bp; 
    817  
    818         // we must have buddypress... 
    819         if (!function_exists('bp_activity_add')) return false; 
    820  
    821         // we only log translation for logged on users 
    822         if (!$bp->loggedin_user->id) return; 
    823  
    824         /* Because blog, comment, and blog post code execution happens before anything else 
    825           we may need to manually instantiate the activity component globals */ 
    826         if (!$bp->activity && function_exists('bp_activity_setup_globals')) 
    827                 bp_activity_setup_globals(); 
    828  
    829         // just got this from buddypress, changed action and content 
    830         $values = array( 
    831             'user_id' => $bp->loggedin_user->id, 
    832             'action' => sprintf(__('%s translated a pharse to %s with transposh:', 'buddypress'), bp_core_get_userlink($bp->loggedin_user->id), substr($GLOBALS['languages'][$lang], 0, strpos($GLOBALS['languages'][$lang], ','))), 
    833             'content' => "Original: <span class=\"no_translate\">$original</span>\nTranslation: <span class=\"no_translate\">$translation</span>", 
    834             'primary_link' => '', 
    835             'component' => $bp->blogs->id, 
    836             'type' => 'new_translation', 
    837             'item_id' => false, 
    838             'secondary_item_id' => false, 
    839             'recorded_time' => gmdate("Y-m-d H:i:s"), 
    840             'hide_sitewide' => false 
    841         ); 
    842  
    843         return bp_activity_add($values); 
    844     } 
    845  
    846740    /** 
    847741     * Modify comments to include the relevant language span 
     
    867761        global $id; 
    868762        $lang = get_post_meta($id, 'tp_language',true); 
    869         if ($lang) { 
    870             $text = "<span lang =\"$lang\">" . $text . "</span>"; 
    871         } 
     763            if ($lang) { 
     764                $text = "<span lang =\"$lang\">" . $text . "</span>"; 
     765            } 
    872766        return $text; 
    873767    } 
     
    898792    } 
    899793 
     794    function transposh_gettext_filter($a, $orig, $domain) { 
     795        //logger("$a $orig $domain"); 
     796        return $a; 
     797    } 
     798 
     799    function transposh_locale_filter($locale) { 
     800        //logger($locale); 
     801        return $locale; 
     802    } 
     803 
    900804} 
    901805 
  • trunk/WordPress/plugin/transposh/wp/transposh_ajax.php

    r458 r483  
    4646//  the case of posted translation 
    4747if (isset($_POST['translation_posted'])) { 
    48     // supercache invalidation of pages - first lets find if supercache is here 
    49     if (function_exists('wp_super_cache_init')) { 
    50         //Now, we are actually using the referrer and not the request, with some precautions 
    51         $GLOBALS['wp_cache_request_uri'] = substr($_SERVER['HTTP_REFERER'], stripos($_SERVER['HTTP_REFERER'], $_SERVER['HTTP_HOST']) + strlen($_SERVER[''] . $_SERVER['HTTP_HOST'])); 
    52         $GLOBALS['wp_cache_request_uri'] = preg_replace('/[ <>\'\"\r\n\t\(\)]/', '', str_replace('/index.php', '/', str_replace('..', '', preg_replace("/(\?.*)?$/", '', $GLOBALS['wp_cache_request_uri'])))); 
    53         // get some supercache variables 
    54         extract(wp_super_cache_init()); 
    55         logger(wp_super_cache_init()); 
    56         // this is hackery for logged in users, a cookie is added to the request somehow and gzip is not correctly set, so we forcefully fix this 
    57         if (!$cache_file) { 
    58             $GLOBALS['wp_cache_gzip_encoding'] = gzip_accepted(); 
    59             unset($_COOKIE[key($_COOKIE)]); 
    60             extract(wp_super_cache_init()); 
    61             logger(wp_super_cache_init()); 
    62         } 
    63  
    64         $dir = get_current_url_supercache_dir(); 
    65         // delete possible files that we can figure out, not deleting files for other cookies for example, but will do the trick in most cases 
    66         $cache_fname = "{$dir}index.html"; 
    67         logger("attempting delete of supercache: $cache_fname"); 
    68         @unlink($cache_fname); 
    69         $cache_fname = "{$dir}index.html.gz"; 
    70         logger("attempting delete of supercache: $cache_fname"); 
    71         @unlink($cache_fname); 
    72         logger("attempting delete of wp_cache: $cache_file"); 
    73         @unlink($cache_file); 
    74         logger("attempting delete of wp_cache_meta: $meta_pathname"); 
    75         @unlink($meta_pathname); 
    76  
    77         // go at edit pages too 
    78         $GLOBALS['wp_cache_request_uri'] .="?edit=1"; 
    79         extract(wp_super_cache_init()); 
    80         logger(wp_super_cache_init()); 
    81         logger("attempting delete of edit_wp_cache: $cache_file"); 
    82         @unlink($cache_file); 
    83         logger("attempting delete of edit_wp_cache_meta: $meta_pathname"); 
    84         @unlink($meta_pathname); 
    85     } 
    86  
    87     if ($_POST['translation_posted'] == 2) { 
    88         $my_transposh_plugin->database->update_translation(); 
    89     } 
     48    do_action('transposh_translation_posted'); 
     49    $my_transposh_plugin->database->update_translation(); 
    9050} 
    9151// getting translation history 
     
    12484    if (!function_exists('curl_init')) return; 
    12585    // we want to avoid unneeded work or dos attacks on languages we don't support 
    126     if (!in_array($_GET['tgl'], $google_proxied_languages) || !$my_transposh_plugin->options->is_editable_language($_GET['tgl'])) return; 
     86    if (!in_array($_GET['tgl'], $google_proxied_languages) || !$my_transposh_plugin->options->is_editable_language($_GET['tgl'])) 
     87            return; 
    12788    $url = 'http://translate.google.com/translate_a/t?client=a&text=' . urlencode($_GET['tgp']) . '&tl=' . $_GET['tgl'] . '&sl=auto'; 
    12889    $ch = curl_init(); 
  • trunk/WordPress/plugin/transposh/wp/transposh_postpublish.php

    r455 r483  
    102102        $phrases = array_merge($phrases, $phrases2); 
    103103 
    104         // Add pharses from permalink 
     104        // Add phrases from permalink 
    105105        if ($this->transposh->options->get_enable_url_translate()) { 
    106106            $permalink = get_permalink($postID); 
Note: See TracChangeset for help on using the changeset viewer.