function setUp()
 {
     $this->w = new GP_Builtin_Translation_Warnings();
     $this->bg = GP_Locales::by_slug('bg');
     $this->longer_than_20 = 'The little boy hid behind the counter and then came the wizard of all green wizards!';
     $this->shorter_than_5 = 'Boom';
 }
Example #2
0
 function single($project_path)
 {
     $project = GP::$project->by_path($project_path);
     if (!$project) {
         return $this->die_with_404();
     }
     $sub_projects = $project->sub_projects();
     $translation_sets = GP::$translation_set->by_project_id($project->id);
     foreach ($translation_sets as $set) {
         $locale = GP_Locales::by_slug($set->locale);
         $set->name_with_locale = $set->name_with_locale();
         $set->current_count = $set->current_count();
         $set->untranslated_count = $set->untranslated_count();
         $set->waiting_count = $set->waiting_count();
         $set->fuzzy_count = $set->fuzzy_count();
         $set->percent_translated = $set->percent_translated();
         $set->all_count = $set->all_count();
         $set->wp_locale = $locale->wp_locale;
         if ($this->api) {
             $set->last_modified = $set->current_count ? $set->last_modified() : false;
         }
     }
     usort($translation_sets, function ($a, $b) {
         return $a->current_count < $b->current_count;
     });
     $translation_sets = apply_filters('gp_translation_sets_sort', $translation_sets);
     $title = sprintf(__('%s project ', 'glotpress'), esc_html($project->name));
     $can_write = $this->can('write', 'project', $project->id);
     $this->tmpl('project', get_defined_vars());
 }
Example #3
0
 public function bulk_translate($project_path)
 {
     $project_path = urldecode($project_path);
     $url = gp_url_project($project_path);
     // If we don't have rights, just redirect back to the project.
     if (!GP::$user->current()->can('write', 'project')) {
         gp_redirect($url);
     }
     // Create a project class to use to get the project object.
     $project_class = new GP_Project();
     // Get the project object from the project path that was passed in.
     $project_obj = $project_class->by_path($project_path);
     // Get the translations sets from the project ID.
     $translation_sets = GP::$translation_set->by_project_id($project_obj->id);
     // Loop through all the sets.
     foreach ($translation_sets as $set) {
         //Array ( [action] => gtranslate [priority] => 0 [redirect_to] => http://localhost/wp40/gp/projects/sample/bg/my [row-ids] => Array ( [0] => 1 [1] => 2 ) )
         $bulk = array('action' => 'gtranslate', 'priority' => 0, 'row-ids' => array());
         $translation = new GP_Translation();
         $strings = $translation->for_translation($project_obj, $set, null, array('status' => 'untranslated'));
         foreach ($strings as $string) {
             $bulk['row-ids'][] .= $string->row_id;
         }
         $locale = GP_Locales::by_slug($set->locale);
         $this->gp_translation_set_bulk_action_post($project_obj, $locale, $set, $bulk);
     }
     $url = gp_url_project($project_path);
     gp_redirect($url);
 }
 function test_locale_factory_create()
 {
     $locale_factory = new GP_UnitTest_Factory_For_Locale();
     $locale = $locale_factory->create();
     $this->assertEquals('aa', $locale->slug);
     $this->assertEquals('Locale 1', $locale->english_name);
     $this->assertSame($locale, GP_Locales::by_slug($locale->slug));
 }
Example #5
0
 function setUp()
 {
     $this->is_baba = create_function('$o, $t, $l', 'return $t == "баба"? true : "error";');
     $this->is_equal = create_function('$o, $t, $l', 'return $t == $o? true : "error";');
     $this->w = new GP_Translation_Warnings();
     $this->with_equal = new GP_Translation_Warnings();
     $this->with_equal->add('is_equal', $this->is_equal);
     $this->standard_plural_locale = GP_Locales::by_slug('bg');
 }
Example #6
0
 function routes()
 {
     $dir = '([^/]+)';
     $path = '(.+?)';
     $projects = 'projects';
     $project = $projects . '/' . $path;
     $locale = '(' . implode('|', array_map(create_function('$x', 'return $x->slug;'), GP_Locales::locales())) . ')';
     // overall structure
     return apply_filters('routes', array('/' => array('GP_Route_Index', 'index'), 'get:/login' => array('GP_Route_Login', 'login_get'), 'post:/login' => array('GP_Route_Login', 'login_post'), 'get:/logout' => array('GP_Route_Login', 'logout'), "get:/{$project}/import-originals" => array('GP_Route_Project', 'import_originals_get'), "post:/{$project}/import-originals" => array('GP_Route_Project', 'import_originals_post'), "get:/{$project}/_edit" => array('GP_Route_Project', 'edit_get'), "post:/{$project}/_edit" => array('GP_Route_Project', 'edit_post'), "get:/{$project}/_delete" => array('GP_Route_Project', 'delete_get'), "post:/{$project}/_delete" => array('GP_Route_Project', 'delete_post'), "post:/{$project}/_personal" => array('GP_Route_Project', 'personal_options_post'), "get:/{$projects}" => array('GP_Route_Project', 'index'), "get:/{$projects}/_new" => array('GP_Route_Project', 'new_get'), "get:/{$projects}/_new" => array('GP_Route_Project', 'new_get'), "post:/{$projects}/_new" => array('GP_Route_Project', 'new_post'), "post:/{$project}/{$locale}/{$dir}/_approve" => array('GP_Route_Translation', 'approve_post'), "get:/{$project}/{$locale}/{$dir}" => array('GP_Route_Translation', 'translations_get'), "post:/{$project}/{$locale}/{$dir}" => array('GP_Route_Translation', 'translations_post'), "get:/{$project}/{$locale}/{$dir}/import-translations" => array('GP_Route_Translation', 'import_translations_get'), "post:/{$project}/{$locale}/{$dir}/import-translations" => array('GP_Route_Translation', 'import_translations_post'), "get:/{$project}/{$locale}/{$dir}/_permissions" => array('GP_Route_Translation', 'permissions_get'), "post:/{$project}/{$locale}/{$dir}/_permissions" => array('GP_Route_Translation', 'permissions_post'), "get:/{$project}/{$locale}/{$dir}/_permissions/_delete/{$dir}" => array('GP_Route_Translation', 'permissions_delete'), "post:/{$project}/{$locale}/{$dir}/_discard-warning" => array('GP_Route_Translation', 'discard_warning'), "/{$project}/{$locale}/{$dir}/export-translations" => array('GP_Route_Translation', 'export_translations_get'), "/{$project}" => array('GP_Route_Project', 'single'), "get:/sets/_new" => array('GP_Route_Translation_Set', 'new_get'), "post:/sets/_new" => array('GP_Route_Translation_Set', 'new_post')));
 }
Example #7
0
 function edit_get($glossary_id)
 {
     $glossary = GP::$glossary->get($glossary_id);
     if (!$glossary) {
         $this->redirect_with_error(__('Cannot find glossary.'));
     }
     $translation_set = GP::$translation_set->get($glossary->translation_set_id);
     $locale = GP_Locales::by_slug($translation_set->locale);
     $project = GP::$project->get($translation_set->project_id);
     $this->tmpl('glossary-edit', get_defined_vars());
 }
Example #8
0
 function new_get()
 {
     $set = new GP_Translation_Set();
     $set->project_id = gp_get('project_id');
     if ($set->project_id) {
         $this->can_or_redirect('write', 'project', $set->project_id, gp_url_project(GP::$project->get($set->project_id)));
     }
     $all_project_options = self::_options_from_projects(GP::$project->all());
     $all_locale_options = self::_options_from_locales(GP_Locales::locales());
     gp_tmpl_load('translation-set-new', get_defined_vars());
 }
Example #9
0
 private function locales_known($user)
 {
     global $wpdb;
     $translations = GP::$translation_set->many_no_map("\n\t\t\tSELECT ts.locale, count(*) AS count\n\t\t\tFROM {$wpdb->gp_translations} as t\n\t\t\tINNER JOIN {$wpdb->gp_translation_sets} AS ts ON ts.id = t.translation_set_id\n\t\t\tWHERE user_id = %s\n\t\t\tGROUP BY ts.locale\n\t\t\tORDER BY count DESC\n\t\t", $user->ID);
     $locales = array();
     foreach ($translations as $data) {
         $locale = GP_Locales::by_slug($data->locale);
         $locales[$locale->english_name] = array('locale' => $data->locale, 'count' => (int) $data->count);
     }
     return $locales;
 }
Example #10
0
 function import($translations)
 {
     $this->set_memory_limit('256M');
     if (!isset($this->project) || !$this->project) {
         $this->project = GP::$project->get($this->project_id);
     }
     $locale = GP_Locales::by_slug($this->locale);
     $user = wp_get_current_user();
     $current_translations_list = GP::$translation->for_translation($this->project, $this, 'no-limit', array('status' => 'current', 'translated' => 'yes'));
     $current_translations = new Translations();
     foreach ($current_translations_list as $entry) {
         $current_translations->add_entry($entry);
     }
     unset($current_translations_list);
     $translations_added = 0;
     foreach ($translations->entries as $entry) {
         if (empty($entry->translations)) {
             continue;
         }
         $is_fuzzy = in_array('fuzzy', $entry->flags);
         if ($is_fuzzy && !apply_filters('gp_translation_set_import_fuzzy_translations', true, $entry, $translations)) {
             continue;
         }
         $create = false;
         if ($translated = $current_translations->translate_entry($entry)) {
             // we have the same string translated
             // create a new one if they don't match
             $entry->original_id = $translated->original_id;
             $translated_is_different = array_pad($entry->translations, $locale->nplurals, null) != $translated->translations;
             $create = apply_filters('gp_translation_set_import_over_existing', $translated_is_different);
         } else {
             // we don't have the string translated, let's see if the original is there
             $original = GP::$original->by_project_id_and_entry($this->project->id, $entry, '+active');
             if ($original) {
                 $entry->original_id = $original->id;
                 $create = true;
             }
         }
         if ($create) {
             if ($user) {
                 $entry->user_id = $user->ID;
             }
             $entry->translation_set_id = $this->id;
             $entry->status = apply_filters('gp_translation_set_import_status', $is_fuzzy ? 'fuzzy' : 'current');
             // check for errors
             $translation = GP::$translation->create($entry);
             $translation->set_status($entry->status);
             $translations_added += 1;
         }
     }
     gp_clean_translation_set_cache($this->id);
     do_action('gp_translations_imported', $this->id);
     return $translations_added;
 }
Example #11
0
 private function default_routes()
 {
     $dir = '([^_/][^/]*)';
     $path = '(.+?)';
     $projects = 'projects';
     $project = $projects . '/' . $path;
     $id = '(\\d+)';
     $locale = '(' . implode('|', wp_list_pluck(GP_Locales::locales(), 'slug')) . ')';
     $set = "{$project}/{$locale}/{$dir}";
     // overall structure
     return array('/' => array('GP_Route_Index', 'index'), 'get:/profile' => array('GP_Route_Profile', 'profile_get'), "get:/profile/{$path}" => array('GP_Route_Profile', 'profile_view'), 'post:/profile' => array('GP_Route_Profile', 'profile_post'), 'get:/languages' => array('GP_Route_Locale', 'locales_get'), "get:/languages/{$locale}/{$path}" => array('GP_Route_Locale', 'single'), "get:/languages/{$locale}" => array('GP_Route_Locale', 'single'), "get:/{$set}/glossary" => array('GP_Route_Glossary_Entry', 'glossary_entries_get'), "post:/{$set}/glossary" => array('GP_Route_Glossary_Entry', 'glossary_entries_post'), "post:/{$set}/glossary/-new" => array('GP_Route_Glossary_Entry', 'glossary_entry_add_post'), "post:/{$set}/glossary/-delete" => array('GP_Route_Glossary_Entry', 'glossary_entry_delete_post'), "get:/{$set}/glossary/-export" => array('GP_Route_Glossary_Entry', 'export_glossary_entries_get'), "get:/{$set}/glossary/-import" => array('GP_Route_Glossary_Entry', 'import_glossary_entries_get'), "post:/{$set}/glossary/-import" => array('GP_Route_Glossary_Entry', 'import_glossary_entries_post'), "get:/{$project}/import-originals" => array('GP_Route_Project', 'import_originals_get'), "post:/{$project}/import-originals" => array('GP_Route_Project', 'import_originals_post'), "get:/{$project}/-edit" => array('GP_Route_Project', 'edit_get'), "post:/{$project}/-edit" => array('GP_Route_Project', 'edit_post'), "post:/{$project}/-personal" => array('GP_Route_Project', 'personal_options_post'), "get:/{$project}/-permissions" => array('GP_Route_Project', 'permissions_get'), "post:/{$project}/-permissions" => array('GP_Route_Project', 'permissions_post'), "get:/{$project}/-permissions/-delete/{$dir}" => array('GP_Route_Project', 'permissions_delete'), "get:/{$project}/-mass-create-sets" => array('GP_Route_Project', 'mass_create_sets_get'), "post:/{$project}/-mass-create-sets" => array('GP_Route_Project', 'mass_create_sets_post'), "post:/{$project}/-mass-create-sets/preview" => array('GP_Route_Project', 'mass_create_sets_preview_post'), "get:/{$project}/-branch" => array('GP_Route_Project', 'branch_project_get'), "post:/{$project}/-branch" => array('GP_Route_Project', 'branch_project_post'), "get:/{$projects}" => array('GP_Route_Project', 'index'), "get:/{$projects}/-new" => array('GP_Route_Project', 'new_get'), "post:/{$projects}/-new" => array('GP_Route_Project', 'new_post'), "post:/{$set}/-bulk" => array('GP_Route_Translation', 'bulk_post'), "get:/{$set}/import-translations" => array('GP_Route_Translation', 'import_translations_get'), "post:/{$set}/import-translations" => array('GP_Route_Translation', 'import_translations_post'), "post:/{$set}/-discard-warning" => array('GP_Route_Translation', 'discard_warning'), "post:/{$set}/-set-status" => array('GP_Route_Translation', 'set_status'), "/{$set}/export-translations" => array('GP_Route_Translation', 'export_translations_get'), "get:/{$set}" => array('GP_Route_Translation', 'translations_get'), "post:/{$set}" => array('GP_Route_Translation', 'translations_post'), "/{$project}" => array('GP_Route_Project', 'single'), "get:/sets/-new" => array('GP_Route_Translation_Set', 'new_get'), "post:/sets/-new" => array('GP_Route_Translation_Set', 'new_post'), "get:/sets/{$id}" => array('GP_Route_Translation_Set', 'single'), "get:/sets/{$id}/-edit" => array('GP_Route_Translation_Set', 'edit_get'), "post:/sets/{$id}/-edit" => array('GP_Route_Translation_Set', 'edit_post'), "get:/glossaries/-new" => array('GP_Route_Glossary', 'new_get'), "post:/glossaries/-new" => array('GP_Route_Glossary', 'new_post'), "get:/glossaries/{$id}/-edit" => array('GP_Route_Glossary', 'edit_get'), "post:/glossaries/{$id}/-edit" => array('GP_Route_Glossary', 'edit_post'), "post:/originals/{$id}/set_priority" => array('GP_Route_Original', 'set_priority'));
 }
Example #12
0
 function clean_up_global_scope()
 {
     parent::clean_up_global_scope();
     $locales =& GP_Locales::instance();
     $locales->locales = array();
     $_GET = array();
     $_POST = array();
     /**
      * @todo re-initialize all thing objects
      */
     GP::$translation_set = new GP_Translation_Set();
     GP::$original = new GP_Original();
 }
 function action_on_translation_set($translation_set)
 {
     $project = GP::$project->get($translation_set->project_id);
     $locale = GP_Locales::by_slug($translation_set->locale);
     foreach (GP::$translation->for_translation($project, $translation_set, 'no-limit') as $entry) {
         $warnings = GP::$translation_warnings->check($entry->singular, $entry->plural, $entry->translations, $locale);
         if ($warnings != $entry->warnings) {
             $translation = new GP_Translation(array('id' => $entry->id));
             echo sprintf(__("Updating warnings for %s"), $entry->id) . "\n";
             $translation->update(array('warnings' => $warnings));
         }
     }
 }
Example #14
0
 function clean_up_global_scope()
 {
     GP::$user->reintialize_wp_users_object();
     $locales =& GP_Locales::instance();
     $locales->locales = array();
     $_GET = array();
     $_POST = array();
     $this->flush_cache();
     /**
      * @todo re-initialize all thing objects
      */
     GP::$translation_set = new GP_Translation_Set();
     GP::$original = new GP_Original();
 }
Example #15
0
 /**
  * Get the slug from a WPorg slug
  *
  * ## OPTIONS
  *
  * <wporg-locale>
  * : WP.org locale slug
  */
 public function __invoke($args)
 {
     $wporg_slug = $args[0];
     $slug = null;
     foreach (GP_Locales::locales() as $locale) {
         if ($locale->wp_locale == $wporg_slug) {
             $slug = $locale->slug;
             break;
         }
     }
     if (!$slug) {
         WP_CLI::error(sprintf(__('No slug match for %s.', 'glotpress'), $wporg_slug));
     }
     WP_CLI::line($slug);
 }
Example #16
0
 function import($translations)
 {
     @ini_set('memory_limit', '256M');
     if (!isset($this->project) || !$this->project) {
         $this->project = GP::$project->get($this->project_id);
     }
     $locale = GP_Locales::by_slug($this->locale);
     $current_translations_list = GP::$translation->for_translation($this->project, $this, 'no-limit', array('status' => 'current', 'translated' => 'yes'));
     $current_translations = new Translations();
     foreach ($current_translations_list as $entry) {
         $current_translations->add_entry($entry);
     }
     unset($current_translations_list);
     $translations_added = 0;
     foreach ($translations->entries as $entry) {
         if (empty($entry->translations)) {
             continue;
         }
         if (in_array('fuzzy', $entry->flags)) {
             continue;
         }
         $create = false;
         if ($translated = $current_translations->translate_entry($entry)) {
             // we have the same string translated
             // create a new one if they don't match
             $entry->original_id = $translated->original_id;
             $create = array_pad($entry->translations, $locale->nplurals, null) != $translated->translations;
         } else {
             // we don't have the string translated, let's see if the original is there
             $original = GP::$original->by_project_id_and_entry($this->project->id, $entry);
             if ($original) {
                 $entry->original_id = $original->id;
                 $create = true;
             }
         }
         if ($create) {
             $entry->translation_set_id = $this->id;
             $entry->status = 'current';
             // check for errors
             $translation = GP::$translation->create($entry);
             $translation->set_as_current();
             $translations_added += 1;
         }
     }
     wp_cache_delete($this->id, 'translation_set_status_breakdown');
     return $translations_added;
 }
 function run()
 {
     if (!isset($this->args[0])) {
         $this->usage();
     }
     $wporg_slug = $this->args[0];
     $slug = null;
     foreach (GP_Locales::locales() as $locale) {
         if ($locale->wp_locale == $wporg_slug) {
             $slug = $locale->slug;
             break;
         }
     }
     if (!$slug) {
         $this->to_stderr("No slug match for {$wporg_slug}.");
     } else {
         echo $slug;
     }
 }
Example #18
0
 public function run()
 {
     if (!isset($this->options['l']) || !isset($this->options['p'])) {
         $this->usage();
     }
     $this->project = GP::$project->by_path($this->options['p']);
     if (!$this->project) {
         $this->error(__('Project not found!', 'glotpress'));
     }
     $this->locale = GP_Locales::by_slug($this->options['l']);
     if (!$this->locale) {
         $this->error(__('Locale not found!', 'glotpress'));
     }
     $this->options['t'] = gp_array_get($this->options, 't', 'default');
     $this->translation_set = GP::$translation_set->by_project_id_slug_and_locale($this->project->id, $this->options['t'], $this->locale->slug);
     if (!$this->translation_set) {
         $this->error(__('Translation set not found!', 'glotpress'));
     }
     $this->action_on_translation_set($this->translation_set);
 }
Example #19
0
 public function single($project_path)
 {
     $project = GP::$project->by_path($project_path);
     if (!$project) {
         return $this->die_with_404();
     }
     $sub_projects = $project->sub_projects();
     $translation_sets = GP::$translation_set->by_project_id($project->id);
     foreach ($translation_sets as $set) {
         $locale = GP_Locales::by_slug($set->locale);
         $set->name_with_locale = $set->name_with_locale();
         $set->current_count = $set->current_count();
         $set->untranslated_count = $set->untranslated_count();
         $set->waiting_count = $set->waiting_count();
         $set->fuzzy_count = $set->fuzzy_count();
         $set->percent_translated = $set->percent_translated();
         $set->all_count = $set->all_count();
         $set->wp_locale = $locale->wp_locale;
         if ($this->api) {
             $set->last_modified = $set->current_count ? $set->last_modified() : false;
         }
     }
     usort($translation_sets, function ($a, $b) {
         return $a->current_count < $b->current_count;
     });
     /**
      * Filter the list of translation sets of a project.
      *
      * Can also be used to sort the sets to a custom order.
      *
      * @since 1.0.0
      *
      * @param GP_Translation_Sets[] $translation_sets An array of translation sets.
      */
     $translation_sets = apply_filters('gp_translation_sets_sort', $translation_sets);
     $title = sprintf(__('%s project ', 'glotpress'), esc_html($project->name));
     $can_write = $this->can('write', 'project', $project->id);
     $this->tmpl('project', get_defined_vars());
 }
 function get_cap_key($locale_slug)
 {
     global $gpdb;
     static $ros_blogs, $ros_locale_assoc;
     $gp_locale = GP_Locales::by_slug($locale_slug);
     if (!$gp_locale || !isset($gp_locale->wp_locale)) {
         return false;
     }
     $wp_locale = $gp_locale->wp_locale;
     if (!isset($ros_blogs)) {
         $ros_locale_assoc = $gpdb->get_results("SELECT locale, subdomain FROM locales", OBJECT_K);
         $ros_blogs = $gpdb->get_results("SELECT domain, blog_id FROM ros_blogs", OBJECT_K);
     }
     if (isset($ros_locale_assoc[$wp_locale])) {
         $subdomain = $ros_locale_assoc[$wp_locale]->subdomain;
     } else {
         return false;
     }
     if (isset($ros_blogs["{$subdomain}.wordpress.org"])) {
         return 'ros_' . $ros_blogs["{$subdomain}.wordpress.org"]->blog_id . '_capabilities';
     }
     return false;
 }
function jetpack_og_tags()
{
    /**
     * Allow Jetpack to output Open Graph Meta Tags.
     *
     * @module sharedaddy, publicize
     *
     * @since 2.0.0
     * @deprecated 2.0.3 Duplicative filter. Use `jetpack_enable_open_graph`.
     *
     * @param bool true Should Jetpack's Open Graph Meta Tags be enabled. Default to true.
     */
    if (false === apply_filters('jetpack_enable_opengraph', true)) {
        _deprecated_function('jetpack_enable_opengraph', '2.0.3', 'jetpack_enable_open_graph');
        return;
    }
    // Disable the widont filter on WP.com to avoid stray &nbsps
    $disable_widont = remove_filter('the_title', 'widont');
    $og_output = "\n<!-- Jetpack Open Graph Tags -->\n";
    $tags = array();
    /**
     * Filter the minimum width of the images used in Jetpack Open Graph Meta Tags.
     *
     * @module sharedaddy, publicize
     *
     * @since 2.0.0
     *
     * @param int 200 Minimum image width used in Jetpack Open Graph Meta Tags.
     */
    $image_width = absint(apply_filters('jetpack_open_graph_image_width', 200));
    /**
     * Filter the minimum height of the images used in Jetpack Open Graph Meta Tags.
     *
     * @module sharedaddy, publicize
     *
     * @since 2.0.0
     *
     * @param int 200 Minimum image height used in Jetpack Open Graph Meta Tags.
     */
    $image_height = absint(apply_filters('jetpack_open_graph_image_height', 200));
    $description_length = 197;
    if (is_home() || is_front_page()) {
        $site_type = get_option('open_graph_protocol_site_type');
        $tags['og:type'] = !empty($site_type) ? $site_type : 'website';
        $tags['og:title'] = get_bloginfo('name');
        $tags['og:description'] = get_bloginfo('description');
        $front_page_id = get_option('page_for_posts');
        if ($front_page_id && is_home()) {
            $tags['og:url'] = get_permalink($front_page_id);
        } else {
            $tags['og:url'] = home_url('/');
        }
        // Associate a blog's root path with one or more Facebook accounts
        $facebook_admins = get_option('facebook_admins');
        if (!empty($facebook_admins)) {
            $tags['fb:admins'] = $facebook_admins;
        }
    } else {
        if (is_author()) {
            $tags['og:type'] = 'profile';
            $author = get_queried_object();
            $tags['og:title'] = $author->display_name;
            if (!empty($author->user_url)) {
                $tags['og:url'] = $author->user_url;
            } else {
                $tags['og:url'] = get_author_posts_url($author->ID);
            }
            $tags['og:description'] = $author->description;
            $tags['profile:first_name'] = get_the_author_meta('first_name', $author->ID);
            $tags['profile:last_name'] = get_the_author_meta('last_name', $author->ID);
        } else {
            if (is_singular()) {
                global $post;
                $data = $post;
                // so that we don't accidentally explode the global
                $tags['og:type'] = 'article';
                if (empty($data->post_title)) {
                    $tags['og:title'] = ' ';
                } else {
                    /** This filter is documented in core/src/wp-includes/post-template.php */
                    $tags['og:title'] = wp_kses(apply_filters('the_title', $data->post_title, $data->ID), array());
                }
                $tags['og:url'] = get_permalink($data->ID);
                if (!post_password_required()) {
                    if (!empty($data->post_excerpt)) {
                        $tags['og:description'] = preg_replace('@https?://[\\S]+@', '', strip_shortcodes(wp_kses($data->post_excerpt, array())));
                    } else {
                        $exploded_content_on_more_tag = explode('<!--more-->', $data->post_content);
                        $tags['og:description'] = wp_trim_words(preg_replace('@https?://[\\S]+@', '', strip_shortcodes(wp_kses($exploded_content_on_more_tag[0], array()))));
                    }
                }
                if (empty($tags['og:description'])) {
                    /**
                     * Filter the fallback `og:description` used when no excerpt information is provided.
                     *
                     * @module sharedaddy, publicize
                     *
                     * @since 3.9.0
                     *
                     * @param string $var  Fallback og:description. Default is translated `Visit the post for more'.
                     * @param object $data Post object for the current post.
                     */
                    $tags['og:description'] = apply_filters('jetpack_open_graph_fallback_description', __('Visit the post for more.', 'jetpack'), $data);
                } else {
                    // Intentionally not using a filter to prevent pollution. @see https://github.com/Automattic/jetpack/pull/2899#issuecomment-151957382
                    $tags['og:description'] = wp_kses(trim(convert_chars(wptexturize($tags['og:description']))), array());
                }
                $tags['article:published_time'] = date('c', strtotime($data->post_date_gmt));
                $tags['article:modified_time'] = date('c', strtotime($data->post_modified_gmt));
                if (post_type_supports(get_post_type($data), 'author') && isset($data->post_author)) {
                    $publicize_facebook_user = get_post_meta($data->ID, '_publicize_facebook_user', true);
                    if (!empty($publicize_facebook_user)) {
                        $tags['article:author'] = esc_url($publicize_facebook_user);
                    }
                }
            }
        }
    }
    /**
     * Allow plugins to inject additional template-specific Open Graph tags.
     *
     * @module sharedaddy, publicize
     *
     * @since 3.0.0
     *
     * @param array $tags Array of Open Graph Meta tags.
     * @param array $args Array of image size parameters.
     */
    $tags = apply_filters('jetpack_open_graph_base_tags', $tags, compact('image_width', 'image_height'));
    // Re-enable widont if we had disabled it
    if ($disable_widont) {
        add_filter('the_title', 'widont');
    }
    /**
     * Do not return any Open Graph Meta tags if we don't have any info about a post.
     *
     * @module sharedaddy, publicize
     *
     * @since 3.0.0
     *
     * @param bool true Do not return any Open Graph Meta tags if we don't have any info about a post.
     */
    if (empty($tags) && apply_filters('jetpack_open_graph_return_if_empty', true)) {
        return;
    }
    $tags['og:site_name'] = get_bloginfo('name');
    // Get image info and build tags
    if (!post_password_required()) {
        $image_info = jetpack_og_get_image($image_width, $image_height);
        $tags['og:image'] = $image_info['src'];
        if (!empty($image_info['width'])) {
            $tags['og:image:width'] = $image_info['width'];
        }
        if (!empty($image_info['height'])) {
            $tags['og:image:height'] = $image_info['height'];
        }
    }
    // Facebook whines if you give it an empty title
    if (empty($tags['og:title'])) {
        $tags['og:title'] = __('(no title)', 'jetpack');
    }
    // Shorten the description if it's too long
    if (isset($tags['og:description'])) {
        $tags['og:description'] = strlen($tags['og:description']) > $description_length ? mb_substr($tags['og:description'], 0, $description_length) . '…' : $tags['og:description'];
    }
    // Try to add OG locale tag if the WP->FB data mapping exists
    if (defined('JETPACK__GLOTPRESS_LOCALES_PATH') && file_exists(JETPACK__GLOTPRESS_LOCALES_PATH)) {
        require_once JETPACK__GLOTPRESS_LOCALES_PATH;
        $_locale = get_locale();
        // We have to account for w.org vs WP.com locale divergence
        if (defined('IS_WPCOM') && IS_WPCOM) {
            $gp_locale = GP_Locales::by_field('slug', $_locale);
        } else {
            $gp_locale = GP_Locales::by_field('wp_locale', $_locale);
        }
    }
    if (isset($gp_locale->facebook_locale) && !empty($gp_locale->facebook_locale)) {
        $tags['og:locale'] = $gp_locale->facebook_locale;
    }
    /**
     * Allow the addition of additional Open Graph Meta tags, or modify the existing tags.
     *
     * @module sharedaddy, publicize
     *
     * @since 2.0.0
     *
     * @param array $tags Array of Open Graph Meta tags.
     * @param array $args Array of image size parameters.
     */
    $tags = apply_filters('jetpack_open_graph_tags', $tags, compact('image_width', 'image_height'));
    // secure_urls need to go right after each og:image to work properly so we will abstract them here
    $secure = $tags['og:image:secure_url'] = empty($tags['og:image:secure_url']) ? '' : $tags['og:image:secure_url'];
    unset($tags['og:image:secure_url']);
    $secure_image_num = 0;
    foreach ((array) $tags as $tag_property => $tag_content) {
        // to accommodate multiple images
        $tag_content = (array) $tag_content;
        $tag_content = array_unique($tag_content);
        foreach ($tag_content as $tag_content_single) {
            if (empty($tag_content_single)) {
                continue;
            }
            // Don't ever output empty tags
            $og_tag = sprintf('<meta property="%s" content="%s" />', esc_attr($tag_property), esc_attr($tag_content_single));
            /**
             * Filter the HTML Output of each Open Graph Meta tag.
             *
             * @module sharedaddy, publicize
             *
             * @since 2.0.0
             *
             * @param string $og_tag HTML HTML Output of each Open Graph Meta tag.
             */
            $og_output .= apply_filters('jetpack_open_graph_output', $og_tag);
            $og_output .= "\n";
            if ('og:image' == $tag_property) {
                if (is_array($secure) && !empty($secure[$secure_image_num])) {
                    $og_tag = sprintf('<meta property="og:image:secure_url" content="%s" />', esc_url($secure[$secure_image_num]));
                    /** This filter is documented in functions.opengraph.php */
                    $og_output .= apply_filters('jetpack_open_graph_output', $og_tag);
                    $og_output .= "\n";
                } else {
                    if (!is_array($secure) && !empty($secure)) {
                        $og_tag = sprintf('<meta property="og:image:secure_url" content="%s" />', esc_url($secure));
                        /** This filter is documented in functions.opengraph.php */
                        $og_output .= apply_filters('jetpack_open_graph_output', $og_tag);
                        $og_output .= "\n";
                    }
                }
                $secure_image_num++;
            }
        }
    }
    echo $og_output;
}
Example #22
0
 public static function by_field($field_name, $field_value)
 {
     $instance = GP_Locales::instance();
     $result = false;
     foreach ($instance->locales() as $locale) {
         if (isset($locale->{$field_name}) && $locale->{$field_name} == $field_value) {
             $result = $locale;
             break;
         }
     }
     return $result;
 }
Example #23
0
 function guess_locale_from_lang($lang)
 {
     if ('en' == $lang || 'en_US' == $lang || !$lang) {
         return 'en_US';
     }
     if (!class_exists('GP_Locales')) {
         if (!defined('JETPACK__GLOTPRESS_LOCALES_PATH') || !file_exists(JETPACK__GLOTPRESS_LOCALES_PATH)) {
             return false;
         }
         require JETPACK__GLOTPRESS_LOCALES_PATH;
     }
     if (defined('IS_WPCOM') && IS_WPCOM) {
         // WP.com: get_locale() returns 'it'
         $locale = GP_Locales::by_slug($lang);
     } else {
         // Jetpack: get_locale() returns 'it_IT';
         $locale = GP_Locales::by_field('wp_locale', $lang);
     }
     if (!$locale) {
         return false;
     }
     if (empty($locale->facebook_locale)) {
         if (empty($locale->wp_locale)) {
             return false;
         } else {
             // Facebook SDK is smart enough to fall back to en_US if a
             // locale isn't supported. Since supported Facebook locales
             // can fall out of sync, we'll attempt to use the known
             // wp_locale value and rely on said fallback.
             return $locale->wp_locale;
         }
     }
     return $locale->facebook_locale;
 }
Example #24
0
    /**
     * This function needs to get loaded after the scripts get added to the page.
     *
     */
    function likes_master()
    {
        $protocol = 'http';
        if (is_ssl()) {
            $protocol = 'https';
        }
        $_locale = get_locale();
        // We have to account for WP.org vs WP.com locale divergence
        if ($this->in_jetpack) {
            if (!defined('JETPACK__GLOTPRESS_LOCALES_PATH') || !file_exists(JETPACK__GLOTPRESS_LOCALES_PATH)) {
                return false;
            }
            require_once JETPACK__GLOTPRESS_LOCALES_PATH;
            $gp_locale = GP_Locales::by_field('wp_locale', $_locale);
            $_locale = isset($gp_locale->slug) ? $gp_locale->slug : '';
        }
        $likes_locale = '' == $_locale || 'en' == $_locale ? '' : '&amp;lang=' . strtolower($_locale);
        $src = sprintf('%1$s://widgets.wp.com/likes/master.html?ver=%2$s#ver=%2$s%3$s', $protocol, $this->version, $likes_locale);
        $likersText = wp_kses(__('<span>%d</span> bloggers like this:', 'jetpack'), array('span' => array()));
        ?>
		<iframe src='<?php 
        echo $src;
        ?>
' scrolling='no' id='likes-master' name='likes-master' style='display:none;'></iframe>
		<div id='likes-other-gravatars'><div class="likes-text"><?php 
        echo $likersText;
        ?>
</div><ul class="wpl-avatars sd-like-gravatars"></ul></div>
		<?php 
    }
 /**
  * Builds a URL to the Jetpack connection auth page
  *
  * @since 3.9.5
  *
  * @param bool $raw If true, URL will not be escaped.
  * @param bool|string $redirect If true, will redirect back to Jetpack wp-admin landing page after connection.
  *                              If string, will be a custom redirect.
  * @param bool|string $from If not false, adds 'from=$from' param to the connect URL.
  *
  * @return string Connect URL
  */
 function build_connect_url($raw = false, $redirect = false, $from = false)
 {
     if (!Jetpack_Options::get_option('blog_token') || !Jetpack_Options::get_option('id')) {
         $url = Jetpack::nonce_url_no_esc(Jetpack::admin_url('action=register'), 'jetpack-register');
         if (is_network_admin()) {
             $url = add_query_arg('is_multisite', network_admin_url('admin.php?page=jetpack-settings'), $url);
         }
     } else {
         require_once JETPACK__GLOTPRESS_LOCALES_PATH;
         $role = $this->translate_current_user_to_role();
         $signed_role = $this->sign_role($role);
         $user = wp_get_current_user();
         $redirect = $redirect ? esc_url_raw($redirect) : esc_url_raw(menu_page_url('jetpack', false));
         $gp_locale = GP_Locales::by_field('wp_locale', get_locale());
         if (isset($_REQUEST['is_multisite'])) {
             $redirect = Jetpack_Network::init()->get_url('network_admin_page');
         }
         $secrets = Jetpack::init()->generate_secrets('authorize');
         @(list($secret) = explode(':', $secrets));
         $site_icon = function_exists('has_site_icon') && has_site_icon() ? get_site_icon_url() : false;
         $args = urlencode_deep(array('response_type' => 'code', 'client_id' => Jetpack_Options::get_option('id'), 'redirect_uri' => add_query_arg(array('action' => 'authorize', '_wpnonce' => wp_create_nonce("jetpack-authorize_{$role}_{$redirect}"), 'redirect' => urlencode($redirect)), menu_page_url('jetpack', false)), 'state' => $user->ID, 'scope' => $signed_role, 'user_email' => $user->user_email, 'user_login' => $user->user_login, 'is_active' => Jetpack::is_active(), 'jp_version' => JETPACK__VERSION, 'auth_type' => 'calypso', 'secret' => $secret, 'locale' => isset($gp_locale->slug) ? $gp_locale->slug : '', 'blogname' => get_option('blogname'), 'site_url' => site_url(), 'home_url' => home_url(), 'site_icon' => $site_icon));
         $url = add_query_arg($args, Jetpack::api_url('authorize'));
     }
     if ($from) {
         $url = add_query_arg('from', $from, $url);
     }
     if (isset($_GET['calypso_env'])) {
         $url = add_query_arg('calypso_env', $_GET['calypso_env'], $url);
     }
     return $raw ? $url : esc_url($url);
 }
 function guess_locale_from_lang($lang)
 {
     if ('en' == $lang || 'en_US' == $lang || !$lang) {
         return 'en_US';
     }
     if (!class_exists('GP_Locales')) {
         if (!defined('JETPACK__GLOTPRESS_LOCALES_PATH') || !file_exists(JETPACK__GLOTPRESS_LOCALES_PATH)) {
             return false;
         }
         require JETPACK__GLOTPRESS_LOCALES_PATH;
     }
     if (defined('IS_WPCOM') && IS_WPCOM) {
         // WP.com: get_locale() returns 'it'
         $locale = GP_Locales::by_slug($lang);
     } else {
         // Jetpack: get_locale() returns 'it_IT';
         $locale = GP_Locales::by_field('facebook_locale', $lang);
     }
     if (!$locale || empty($locale->facebook_locale)) {
         return 'en_US';
         // Facebook requires a locale when pulling their SDK.
     }
     return $locale->facebook_locale;
 }
Example #27
0
function gp_locales_dropdown($name_and_id, $selected_slug = null, $attrs = array())
{
    $locales = GP_Locales::locales();
    ksort($locales);
    $options = array('' => __('&mdash; Locale &mdash;'));
    foreach ($locales as $key => $locale) {
        $options[$key] = sprintf('%s &mdash; %s', $locale->slug, $locale->english_name);
    }
    return gp_select($name_and_id, $options, $selected_slug, $attrs);
}
Example #28
0
 /**
  * Builds a URL to the Jetpack connection auth page
  *
  * @since 3.9.5
  *
  * @param bool $raw If true, URL will not be escaped.
  * @param bool|string $redirect If true, will redirect back to Jetpack wp-admin landing page after connection.
  *                              If string, will be a custom redirect.
  * @param bool|string $from If not false, adds 'from=$from' param to the connect URL.
  *
  * @return string Connect URL
  */
 function build_connect_url($raw = false, $redirect = false, $from = false)
 {
     if (!Jetpack_Options::get_option('blog_token') || !Jetpack_Options::get_option('id')) {
         $url = Jetpack::nonce_url_no_esc(Jetpack::admin_url('action=register'), 'jetpack-register');
         if (is_network_admin()) {
             $url = add_query_arg('is_multisite', network_admin_url('admin.php?page=jetpack-settings'), $url);
         }
     } else {
         if (defined('JETPACK__GLOTPRESS_LOCALES_PATH') && (include_once JETPACK__GLOTPRESS_LOCALES_PATH)) {
             $gp_locale = GP_Locales::by_field('wp_locale', get_locale());
         }
         $role = self::translate_current_user_to_role();
         $signed_role = self::sign_role($role);
         $user = wp_get_current_user();
         $jetpack_admin_page = esc_url_raw(admin_url('admin.php?page=jetpack'));
         $redirect = $redirect ? wp_validate_redirect(esc_url_raw($redirect), $jetpack_admin_page) : $jetpack_admin_page;
         if (isset($_REQUEST['is_multisite'])) {
             $redirect = Jetpack_Network::init()->get_url('network_admin_page');
         }
         $secrets = Jetpack::init()->generate_secrets('authorize');
         @(list($secret) = explode(':', $secrets));
         $site_icon = function_exists('has_site_icon') && has_site_icon() ? get_site_icon_url() : false;
         /**
          * Filter the type of authorization.
          * 'calypso' completes authorization on wordpress.com/jetpack/connect
          * while 'jetpack' ( or any other value ) completes the authorization at jetpack.wordpress.com.
          *
          * @since 4.3.3
          *
          * @param string $auth_type Defaults to 'calypso', can also be 'jetpack'.
          */
         $auth_type = apply_filters('jetpack_auth_type', 'calypso');
         $args = urlencode_deep(array('response_type' => 'code', 'client_id' => Jetpack_Options::get_option('id'), 'redirect_uri' => add_query_arg(array('action' => 'authorize', '_wpnonce' => wp_create_nonce("jetpack-authorize_{$role}_{$redirect}"), 'redirect' => urlencode($redirect)), esc_url(admin_url('admin.php?page=jetpack'))), 'state' => $user->ID, 'scope' => $signed_role, 'user_email' => $user->user_email, 'user_login' => $user->user_login, 'is_active' => Jetpack::is_active(), 'jp_version' => JETPACK__VERSION, 'auth_type' => $auth_type, 'secret' => $secret, 'locale' => isset($gp_locale) && isset($gp_locale->slug) ? $gp_locale->slug : '', 'blogname' => get_option('blogname'), 'site_url' => site_url(), 'home_url' => home_url(), 'site_icon' => $site_icon));
         $url = add_query_arg($args, Jetpack::api_url('authorize'));
     }
     if ($from) {
         $url = add_query_arg('from', $from, $url);
     }
     if (isset($_GET['calypso_env'])) {
         $url = add_query_arg('calypso_env', sanitize_key($_GET['calypso_env']), $url);
     }
     return $raw ? $url : esc_url($url);
 }
Example #29
0
 private function edit_single_translation($project_path, $locale_slug, $translation_set_slug, $edit_function)
 {
     $project = GP::$project->by_path($project_path);
     $locale = GP_Locales::by_slug($locale_slug);
     if (!$project || !$locale) {
         return $this->die_with_404();
     }
     $translation_set = GP::$translation_set->by_project_id_slug_and_locale($project->id, $translation_set_slug, $locale_slug);
     if (!$translation_set) {
         return $this->die_with_404();
     }
     $translation = GP::$translation->get(gp_post('translation_id'));
     if (!$translation) {
         return $this->die_with_error('Translation doesn&#8217;t exist!');
     }
     $this->can_approve_translation_or_forbidden($translation);
     call_user_func($edit_function, $project, $locale, $translation_set, $translation);
     $translations = GP::$translation->for_translation($project, $translation_set, 'no-limit', array('translation_id' => $translation->id, 'status' => 'either'), array());
     if ($translations) {
         $t = $translations[0];
         $can_edit = $this->can('edit', 'translation-set', $translation_set->id);
         $can_write = $this->can('write', 'project', $project->id);
         $can_approve = $this->can('approve', 'translation-set', $translation_set->id);
         $this->tmpl('translation-row', get_defined_vars());
     } else {
         return $this->die_with_error('Error in retrieving translation!');
     }
 }
Example #30
0
 public function import_glossary_entries_post($project_path, $locale_slug, $translation_set_slug)
 {
     $project = GP::$project->by_path($project_path);
     $locale = GP_Locales::by_slug($locale_slug);
     if (!$project || !$locale) {
         return $this->die_with_404();
     }
     $translation_set = GP::$translation_set->by_project_id_slug_and_locale($project->id, $translation_set_slug, $locale_slug);
     if (!$translation_set) {
         return $this->die_with_404();
     }
     $glossary = GP::$glossary->by_set_id($translation_set->id);
     if (!$glossary) {
         return $this->die_with_404();
     }
     if ($this->cannot_and_redirect('approve', 'translation-set', $translation_set->id)) {
         return;
     }
     if (!is_uploaded_file($_FILES['import-file']['tmp_name'])) {
         $this->redirect_with_error(__('Error uploading the file.', 'glotpress'));
         return;
     }
     $glossary_entries_added = $this->read_glossary_entries_from_file($_FILES['import-file']['tmp_name'], $glossary->id, $locale->slug);
     if (empty($this->errors) && is_int($glossary_entries_added)) {
         $this->notices[] = sprintf(__('%s glossary entries were added', 'glotpress'), $glossary_entries_added);
     }
     $this->redirect(gp_url_join(gp_url_project_locale($project_path, $locale_slug, $translation_set_slug), array('glossary')));
 }