/**
 * Adds Babble's components as global variables.
 */
function babble_globals()
{
    global $bbl_log;
    $bbl_log = Babble::get('log');
    global $bbl_jobs;
    $bbl_jobs = Babble::get('jobs');
    global $bbl_languages;
    $bbl_languages = Babble::get('languages');
    global $bbl_locale;
    $bbl_locale = Babble::get('locale');
    global $bbl_post_public;
    $bbl_post_public = Babble::get('post_public');
    global $bbl_comment;
    $bbl_comment = Babble::get('comment');
    global $bbl_taxonomies;
    $bbl_taxonomies = Babble::get('taxonomies');
    global $bbl_switcher_menu;
    $bbl_switcher_menu = Babble::get('switcher_menu');
    global $bbl_switcher_interface;
    $bbl_switcher_interface = Babble::get('switcher_interface');
    global $bbl_admin_bar;
    $bbl_admin_bar = Babble::get('admin_bar');
    global $bbl_translator;
    $bbl_translator = Babble::get('translator');
}
 public function test_get_object_jobs_after_creating_job()
 {
     $bbl_jobs = Babble::get('jobs');
     $post_id = $this->factory->post->create();
     $jobs = $bbl_jobs->create_post_jobs($post_id, array('fr_FR'));
     $job_id = $jobs[0];
     $jobs = $bbl_jobs->get_object_jobs($post_id, 'post', 'post', array('new'));
     $this->assertTrue(isset($jobs['fr_FR']));
     $this->assertEquals(1, count($jobs));
     $bbl_jobs->create_post_jobs($post_id, array('en_GB'));
     $jobs = $bbl_jobs->get_object_jobs($post_id, 'post', 'post', array('new'));
     $this->assertTrue(isset($jobs['fr_FR']));
     $this->assertTrue(isset($jobs['en_GB']));
     $this->assertEquals(2, count($jobs));
 }
 /**
  * Hooks the WP save_post action
  *
  * @param int $post_id The ID of the post being saved
  * @param object $post The WordPress post object being saved
  * @return void
  **/
 function save_post($post_id, $post)
 {
     if (!in_array($post->post_status, array('draft', 'publish'))) {
         return;
     }
     if (!isset($_POST['_bbl_reconnect_nonce'])) {
         return;
     }
     $posted_id = isset($_POST['post_ID']) ? absint($_POST['post_ID']) : 0;
     if ($posted_id != $post_id) {
         return;
     }
     // While we're at it, let's check the nonce
     check_admin_referer("bbl_reconnect_translation_{$post_id}", '_bbl_reconnect_nonce');
     // Check the user has set a transid
     if (!($transid = isset($_POST['bbl_transid']) ? (int) $_POST['bbl_transid'] : false)) {
         return;
     }
     // Check the transid the user has set actually exists
     if (!term_exists($transid, 'post_translation')) {
         $this->set_admin_error(__('The TransID you want to reconnect this content to does not exist. Please check the Translation Group information and try again.', 'babble'));
         return;
     }
     Babble::get('post_public')->set_transid($post, $transid);
 }
Exemplo n.º 4
0
/**
 * Whether Babble is logging right now.
 *
 * @return boolean True for yes, natch
 **/
function bbl_is_logging()
{
    return Babble::get('log')->logging;
}
 /**
  * Returns the current language object, respecting any
  * language switches; i.e. if your request was for
  * Arabic, but the language is currently switched to
  * French, this will return French.
  *
  * @return object|boolean A Babble language object
  **/
 public function get_current_lang()
 {
     return $this->get_lang(Babble::get('locale')->get_lang());
 }
 /**
  * Create empty translations of a post for all languages. Called via WP-Cron on the `babble_create_empty_translation` hook.
  *
  * @param  array  $args Args array containing a `post_id` element.
  */
 public function create_empty_translation(array $args)
 {
     if (!($post = get_post($args['post_id']))) {
         return;
     }
     $bbl_post_public = Babble::get('post_public');
     foreach (bbl_get_active_langs() as $lang) {
         if (!($trans = $bbl_post_public->get_post_in_lang($post, $lang->code, false))) {
             $trans = $bbl_post_public->initialise_translation($post, $lang->code);
         }
         $post_data = array('ID' => $trans->ID, 'post_status' => $post->post_status, 'post_name' => $post->post_name);
         $this->no_recursion = true;
         wp_update_post($post_data, true);
         $this->no_recursion = false;
     }
 }
 /**
  * Set the content language code and URL prefix for any 
  * subsequent requests.
  *
  * @param string $code A language code
  * @return void
  **/
 protected function set_content_lang($code)
 {
     // Set the content language in the application
     $url_prefix = Babble::get('languages')->get_url_prefix_from_code($code);
     if (!$url_prefix) {
         return false;
     }
     $this->content_lang = $code;
     $this->url_prefix = $url_prefix;
     return true;
 }
    public static function set($name, $instance)
    {
        self::$registry[$name] = $instance;
    }
    public static function get($name)
    {
        if (array_key_exists($name, self::$registry)) {
            return self::$registry[$name];
        } else {
            return null;
        }
    }
}
function babble_init()
{
    load_plugin_textdomain('babble', false, dirname(plugin_basename(__FILE__)) . '/locale');
}
add_action('init', 'babble_init');
// Registry
Babble::set('log', new Babble_Log());
Babble::set('jobs', new Babble_Jobs());
Babble::set('languages', new Babble_Languages());
Babble::set('locale', new Babble_Locale());
Babble::set('post_public', new Babble_Post_Public());
Babble::set('comment', new Babble_Comment());
Babble::set('taxonomies', new Babble_Taxonomies());
Babble::set('switcher_menu', new Babble_Switcher_Menu());
Babble::set('switcher_interface', new Babble_Switcher_Interface());
Babble::set('admin_bar', new Babble_Admin_bar());
Babble::set('translator', new Babble_Translator());
 /**
  * Add a link to a language specific front page.
  *
  * @TODO: Is this any different from a regular post link?
  *
  * @param object $lang A Babble language object for this link
  * @return void
  **/
 protected function add_front_page_link($lang)
 {
     $bbl_locale = Babble::get('locale');
     $classes = array();
     remove_filter('home_url', array($bbl_locale, 'home_url'), null, 2);
     $href = home_url("{$lang->url_prefix}/");
     add_filter('home_url', array($bbl_locale, 'home_url'), null, 2);
     $href = apply_filters('bbl_switch_front_page_link', $href, $lang);
     $title = sprintf(__('Switch to %s', 'babble'), $lang->display_name);
     $classes[] = sanitize_html_class("bbl-lang-{$lang->code}");
     $classes[] = sanitize_html_class("bbl-lang-{$lang->url_prefix}");
     $classes[] = 'bbl-existing';
     $classes[] = 'bbl-front-page';
     $classes[] = 'bbl-lang';
     if ($lang->code == bbl_get_current_lang_code()) {
         $classes[] = 'bbl-active';
     }
     $this->links[$lang->code] = array('classes' => $classes, 'id' => $lang->url_prefix, 'href' => $href, 'meta' => array('class' => strtolower(join(' ', array_unique($classes)))), 'title' => $title, 'lang' => $lang);
 }
 protected function install_languages()
 {
     if (file_exists($file = ABSPATH . 'wp-admin/includes/translation-install.php')) {
         require_once $file;
     }
     if (!function_exists('wp_download_language_pack')) {
         $this->markTestSkipped('The wp_download_language_pack() function does not exist.');
         return;
     }
     $languages = array('fr' => 'fr_FR', 'uk' => 'en_GB', 'ar' => 'ar');
     foreach ($languages as $url_prefix => $lang) {
         $download = wp_download_language_pack($lang);
         $this->assertNotEmpty($download);
         $this->langs[$lang] = $download;
     }
     $active_langs = array_merge(array('en' => 'en_US'), $languages);
     $public_langs = array_values($active_langs);
     $lang_prefs = array();
     $langs = array();
     $lang_prefs['en'] = (object) array('display_name' => 'en_US', 'url_prefix' => 'en');
     $langs['en_US'] = (object) array('name' => 'en_US', 'code' => 'en_US', 'url_prefix' => 'en', 'text_direction' => 'ltr', 'display_name' => 'en_US');
     foreach ($languages as $url_prefix => $lang) {
         $lang_prefs[$url_prefix] = (object) array('display_name' => $lang, 'url_prefix' => $url_prefix);
         $langs[$lang] = (object) array('name' => $lang, 'code' => $lang, 'url_prefix' => $url_prefix, 'text_direction' => 'ltr', 'display_name' => $lang);
     }
     $default_lang = 'en_US';
     $option = get_option('babble-languages', array());
     $option['langs'] = $langs;
     $option['active_langs'] = $active_langs;
     $option['public_langs'] = $public_langs;
     $option['lang_prefs'] = $lang_prefs;
     $option['default_lang'] = $default_lang;
     update_option('babble-languages', $option);
     Babble::get('languages')->initiate();
 }