Changeset 483
- Timestamp:
- 08/06/2010 01:12:07 AM (18 months ago)
- Location:
- trunk/WordPress/plugin/transposh
- Files:
-
- 1 added
- 4 edited
-
core/parser.php (modified) (1 diff)
-
transposh.php (modified) (9 diffs)
-
wp/transposh_3rdparty.php (added)
-
wp/transposh_ajax.php (modified) (2 diffs)
-
wp/transposh_postpublish.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/WordPress/plugin/transposh/core/parser.php
r480 r483 282 282 283 283 /** 284 * Create a ph arse tag in the html dom tree285 * @param int $start - beginning of ph arse in element286 * @param int $end - end of ph arse in element284 * 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 287 287 */ 288 288 function tag_phrase($string, $start, $end) { -
trunk/WordPress/plugin/transposh/transposh.php
r479 r483 46 46 require_once("wp/transposh_postpublish.php"); 47 47 require_once("wp/transposh_backup.php"); 48 require_once("wp/transposh_3rdparty.php"); 48 49 49 50 /** … … 63 64 /** @var transposh_postpublish Happens after editing */ 64 65 public $postpublish; 66 /** @var transposh_3rdparty Happens after editing */ 67 private $third_party; 65 68 66 69 // list of properties … … 96 99 $this->widget = new transposh_plugin_widget($this); 97 100 $this->postpublish = new transposh_postpublish($this); 101 $this->third_party = new transposh_3rdparty($this); 98 102 99 103 // "global" vars … … 132 136 add_action('wp_print_scripts', array(&$this, 'add_transposh_js')); 133 137 // add_action('wp_head', array(&$this,'add_transposh_async')); 134 add_action("sm_addurl", array(&$this, 'add_sm_transposh_urls'));135 138 add_action('transposh_backup_event', array(&$this, 'run_backup')); 136 139 add_action('comment_post', array(&$this, 'add_comment_meta_settings'), 1); … … 140 143 add_filter('the_title', array(&$this, 'post_wrap')); 141 144 142 // buddypress compatability143 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 148 145 //TODO add_action('manage_comments_nav', array(&$this,'manage_comments_nav')); 149 146 //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 150 151 151 152 register_activation_hook(__FILE__, array(&$this, 'plugin_activate')); … … 706 707 707 708 /** 708 * This function integrates with google sitemap generator, and adds for each viewable language, the rest of the languages url709 * Also - priority is reduced by 0.2710 * 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 information713 */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 zero719 $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 /**737 709 * Runs a scheduled backup 738 710 */ … … 766 738 return $url; 767 739 } 768 769 /**770 * This filter method helps buddypress understand the transposh generated URLs771 * @param string $uri The url that was originally received772 * @return string The url that buddypress should see773 */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 language785 * @param BP_Activity_Activity $params786 */787 function bp_activity_after_save($params) {788 // we don't need to modify our own activity stream789 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 meta796 * @param string $content797 * @param BP_Activity_Activity $activity798 * @return string modified content799 */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 translation810 * @global object $bp the global buddypress811 * @param string $translation812 * @param string $original813 * @param string $lang814 */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 users822 if (!$bp->loggedin_user->id) return;823 824 /* Because blog, comment, and blog post code execution happens before anything else825 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 content830 $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' => false841 );842 843 return bp_activity_add($values);844 }845 846 740 /** 847 741 * Modify comments to include the relevant language span … … 867 761 global $id; 868 762 $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 } 872 766 return $text; 873 767 } … … 898 792 } 899 793 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 900 804 } 901 805 -
trunk/WordPress/plugin/transposh/wp/transposh_ajax.php
r458 r483 46 46 // the case of posted translation 47 47 if (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(); 90 50 } 91 51 // getting translation history … … 124 84 if (!function_exists('curl_init')) return; 125 85 // 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; 127 88 $url = 'http://translate.google.com/translate_a/t?client=a&text=' . urlencode($_GET['tgp']) . '&tl=' . $_GET['tgl'] . '&sl=auto'; 128 89 $ch = curl_init(); -
trunk/WordPress/plugin/transposh/wp/transposh_postpublish.php
r455 r483 102 102 $phrases = array_merge($phrases, $phrases2); 103 103 104 // Add ph arses from permalink104 // Add phrases from permalink 105 105 if ($this->transposh->options->get_enable_url_translate()) { 106 106 $permalink = get_permalink($postID);
Note: See TracChangeset
for help on using the changeset viewer.
