Changeset 696 for trunk


Ignore:
Timestamp:
12/11/2011 07:58:43 PM (5 months ago)
Author:
ofer
Message:

Allow CORS (Cross Origin Ajax)

Location:
trunk/WordPress/plugin/transposh
Files:
2 edited

Legend:

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

    r667 r696  
    396396        //            | ( "1" [ "." 0*3("0") ] ) 
    397397        preg_match_all("/([[:alpha:]]{1,8})(-([[:alpha:]|-]{1,8}))?" . 
    398                 "(\s*;\s*q\s*=\s*(1\.0{0,3}|0\.\d{0,3}))?\s*(,|$)/i", 
    399                 $http_accept_language, $hits, PREG_SET_ORDER); 
     398                "(\s*;\s*q\s*=\s*(1\.0{0,3}|0\.\d{0,3}))?\s*(,|$)/i", $http_accept_language, $hits, PREG_SET_ORDER); 
    400399 
    401400        // default language (in case of no hits) is the first in the array 
     
    433432    } 
    434433 
     434    public static function allow_cors() { 
     435        header('Access-Control-Allow-Origin: *'); 
     436        header('Access-Control-Allow-Methods: GET, POST, OPTIONS'); 
     437        header('Access-Control-Allow-Headers: X-Requested-With'); 
     438        header('Access-Control-Max-Age: 86400'); 
     439    } 
     440 
    435441} 
    436442 
  • trunk/WordPress/plugin/transposh/transposh.php

    r682 r696  
    709709    function add_transposh_js() { 
    710710        //not in any translation mode - no need for any js. 
    711         if (!($this->edit_mode || $this->is_auto_translate_permitted() || is_admin())) return; // TODO, check just for settings page admin and pages with our translate 
     711        if (!($this->edit_mode || $this->is_auto_translate_permitted() || is_admin())) 
     712                return; // TODO, check just for settings page admin and pages with our translate 
    712713 
    713714        wp_enqueue_script('transposh', $this->transposh_plugin_url . '/' . TRANSPOSH_DIR_JS . '/transposh.js', array('jquery'), TRANSPOSH_PLUGIN_VER); 
     
    12001201        // we need curl for this proxy 
    12011202        if (!function_exists('curl_init')) return; 
     1203        transposh_utils::allow_cors(); 
    12021204        $tl = $_GET['tl']; 
    12031205        // we want to avoid unneeded work or dos attacks on languages we don't support 
     
    12471249        // we need curl for this proxy 
    12481250        if (!function_exists('curl_init')) return; 
     1251        transposh_utils::allow_cors(); 
    12491252        // target language 
    12501253        $tl = $_GET['tl']; 
     
    13431346    function on_ajax_nopriv_tp_history() { 
    13441347        // deleting 
     1348        transposh_utils::allow_cors(); 
    13451349        if (isset($_GET['timestamp'])) { 
    13461350            $this->database->del_translation_history($_GET['token'], $_GET['lang'], $_GET['timestamp']); 
     
    13521356    //  the case of posted translation 
    13531357    function on_ajax_nopriv_tp_translation() { 
     1358        transposh_utils::allow_cors(); 
    13541359        do_action('transposh_translation_posted'); 
    13551360        $this->database->update_translation(); 
     
    13591364    // getting translation alternates 
    13601365    function on_ajax_nopriv_tp_trans_alts() { 
     1366        transposh_utils::allow_cors(); 
    13611367        $this->database->get_translation_alt($_GET['token']); 
    13621368        die(); 
Note: See TracChangeset for help on using the changeset viewer.