/**
  * Sends an email to all potential translators for the given job_id
  *
  * @param WPML_Translation_Job|int $job
  *
  * @return array
  */
 public function new_job_notification_mail($job)
 {
     $mails = array();
     list($manager_id, $job) = $this->get_mail_elements($job);
     if (!$job) {
         return $mails;
     }
     $job_id = $job->get_id();
     $translators = $this->blog_translators->get_blog_translators(array('to' => $job->get_language_code()));
     /** @var WPML_Element_Translation_Job $job */
     $edit_url = strtolower($job->get_type()) !== 'string' ? apply_filters('icl_job_edit_url', admin_url('admin.php?page=' . WPML_TM_FOLDER . '/menu/translations-queue.php&job_id=' . $job_id), $job_id) : "";
     foreach ($translators as $t) {
         if ($manager_id == $t->ID || !$job->user_can_translate($t)) {
             continue;
         }
         $user_language = $this->sitepress->get_user_admin_language($t->ID);
         $this->sitepress->switch_locale($user_language);
         list($lang_from, $lang_to) = $this->get_lang_to_from($job, $user_language);
         if (strtolower($job->get_type()) !== 'string') {
             /** @var WPML_Element_Translation_Job $job */
             $post_link = $job->get_url(true);
             $post_link = $post_link != "" ? sprintf(__("\nView the original document in %s here: %s\n", 'sitepress'), $lang_from, $post_link) : "";
         } else {
             $post_link = "";
         }
         $mail['to'] = $t->display_name . ' <' . $t->user_email . '>';
         $mail['subject'] = sprintf(__('New translation job from %s', 'sitepress'), get_bloginfo('name'));
         $mail['body'] = sprintf(__("New job available from %s to %s.\n%s\nStart editing: %s", 'sitepress'), $lang_from, $lang_to, $post_link, $edit_url);
         $mail['type'] = 'translator';
         $this->enqueue_mail($mail);
         $this->sitepress->switch_locale();
         $mails[] = $mail;
     }
     return $mails;
 }
コード例 #2
0
 /**
  * Checks whether the input user is allowed to edit this job
  *
  * @param stdClass|WP_User $user
  *
  * @return bool
  */
 public function user_can_translate($user)
 {
     $translator_id = $this->get_translator_id();
     $user_can_take_this_job = $translator_id === 0 || $translator_id === (int) $user->ID;
     $translator_has_job_language_pairs = $this->blog_translators->is_translator($user->ID, array('lang_from' => $this->get_source_language_code(), 'lang_to' => $this->get_language_code()));
     return $user_can_take_this_job && $translator_has_job_language_pairs || method_exists($user, 'has_cap') && $user->has_cap('manage_options') || !method_exists($user, 'has_cap') && user_can($user->ID, 'manage_options');
 }
コード例 #3
0
 public static function get_job_id_from_request()
 {
     /**
      * @var TranslationManagement $iclTranslationManagement
      * @var WPML_Post_Translation $wpml_post_translations
      */
     global $iclTranslationManagement, $wpml_post_translations, $wpml_translation_job_factory, $sitepress, $wpdb;
     $job_id = filter_input(INPUT_GET, 'job_id', FILTER_SANITIZE_NUMBER_INT);
     $trid = filter_input(INPUT_GET, 'trid', FILTER_SANITIZE_NUMBER_INT);
     $language_code = filter_input(INPUT_GET, 'language_code', FILTER_SANITIZE_FULL_SPECIAL_CHARS);
     $source_language_code = filter_input(INPUT_GET, 'source_language_code', FILTER_SANITIZE_FULL_SPECIAL_CHARS);
     if (!$job_id && $trid && $language_code) {
         $job_id = $iclTranslationManagement->get_translation_job_id($trid, $language_code);
         if (!$job_id) {
             if (!$source_language_code) {
                 $post_id = SitePress::get_original_element_id_by_trid($trid);
             } else {
                 $posts_in_trid = $wpml_post_translations->get_element_translations(false, $trid);
                 $post_id = isset($posts_in_trid[$source_language_code]) ? $posts_in_trid[$source_language_code] : false;
             }
             $blog_translators = new WPML_TM_Blog_Translators($wpdb);
             $args = array('lang_from' => $source_language_code, 'lang_to' => $language_code, 'job_id' => $job_id);
             if ($post_id && $blog_translators->is_translator($sitepress->get_current_user()->ID, $args)) {
                 $job_id = $wpml_translation_job_factory->create_local_post_job($post_id, $language_code);
             }
         }
     }
     return $job_id;
 }
コード例 #4
0
 public function translator_languages_pairs_filter($default, $user)
 {
     $result = $default;
     $user_id = $this->get_user_id($user);
     if (is_numeric($user_id)) {
         if ($this->blog_translators->is_translator($user_id)) {
             $result = $this->blog_translators->get_language_pairs($user_id);
         }
     }
     return $result;
 }
コード例 #5
0
 public function translator_languages_pairs_filter($default, $user)
 {
     $result = $default;
     $user_id = $this->get_user_id($user);
     if (is_numeric($user_id)) {
         $blog_translators = new WPML_TM_Blog_Translators($this->wpdb);
         if ($blog_translators->is_translator($user_id)) {
             $result = get_user_meta($user_id, $this->wpdb->prefix . 'language_pairs', true);
         }
     }
     return $result;
 }
コード例 #6
0
 /**
  * Adds the given language pair to the user.
  *
  * @param int    $user_id
  * @param string $target_lang
  * @param string $source_lang
  *
  * @used-by \WPML_TM_Post_Actions::save_post_actions to add language pairs to admin users automatically when saving
  *                                                   a translation in a given language pair.
  */
 private function maybe_add_as_translator($user_id, $target_lang, $source_lang)
 {
     if ($target_lang && !$this->blog_translators->is_translator($user_id, array('lang_from' => $source_lang, 'lang_to' => $target_lang, 'admin_override' => false))) {
         $this->action_helper->get_tm_instance()->add_translator($user_id, array($source_lang => array($target_lang => 1)));
     }
 }