function export_translations_get($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(); } $format = gp_array_get(GP::$formats, gp_get('format', 'po'), null); if (!$format) { return $this->die_with_404(); } $export_locale = apply_filters('export_locale', $locale->slug, $locale); $filename = sprintf('%s-%s.' . $format->extension, str_replace('/', '-', $project->path), $export_locale); $filename = apply_filters('export_translations_filename', $filename, $format, $locale, $project, $translation_set); $entries = GP::$translation->for_export($project, $translation_set, gp_get('filters')); if (gp_has_translation_been_updated($translation_set)) { $last_modified = gmdate('D, d M Y H:i:s', backpress_gmt_strtotime(GP::$translation->last_modified($translation_set))) . ' GMT'; $this->headers_for_download($filename, $last_modified); echo $format->print_exported_file($project, $locale, $translation_set, $entries); // As has_translation_been_updated() compared against HTTP_IF_MODIFIED_SINCE here, send an appropriate header. } else { $this->header('HTTP/1.1 304 Not Modified'); } }
?> </h3> <ul> <?php foreach ($recent_projects as $project) { ?> <li> <p><?php echo gp_link_get($project->project_url, $project->set_name) . ': '; echo gp_link_get($project->project_url . '?filters[status]=either&filters[user_login]=' . $user->user_login, sprintf(_n('%s contribution', '%s contributions', $project->count), $project->count)); ?> </p> <p class="ago"> <?php printf(__('last translation about %s ago (UTC)'), gp_time_since(backpress_gmt_strtotime($project->last_updated))); ?> </p> </li> <?php } ?> </ul> </div> <div class="validates-projects"> <h3><?php _e('Validator to'); ?> </h3> <?php
function _put_user($args = null) { $defaults = array('ID' => false, 'user_login' => '', 'user_nicename' => '', 'user_email' => '', 'user_url' => '', 'user_pass' => false, 'user_registered' => time(), 'display_name' => '', 'user_status' => 0, 'strict_user_login' => true); $fields = array_keys(nxt_parse_args($args)); $args = nxt_parse_args($args, $defaults); unset($defaults['strict_user_login']); if (isset($args['ID']) && $args['ID']) { unset($defaults['ID']); $fields = array_intersect($fields, array_keys($defaults)); } else { $fields = array_keys($defaults); } extract($args, EXTR_SKIP); $ID = (int) $ID; if (!$ID || in_array('user_login', $fields)) { $user_login = $this->sanitize_user($user_login, $strict_user_login); if (!$user_login) { return new nxt_Error('user_login', __('Invalid login name')); } if (!$ID && $this->get_user($user_login, array('by' => 'login'))) { return new nxt_Error('user_login', __('Name already exists')); } } if (!$ID || in_array('user_nicename', $fields)) { if (!($user_nicename = $this->sanitize_nicename($user_nicename ? $user_nicename : $user_login))) { return new nxt_Error('user_nicename', __('Invalid nicename')); } if (!$ID && $this->get_user($user_nicename, array('by' => 'nicename'))) { return new nxt_Error('user_nicename', __('Nicename already exists')); } } if (!$ID || in_array('user_email', $fields)) { if (!$this->is_email($user_email)) { return new nxt_Error('user_email', __('Invalid email address')); } if ($already_email = $this->get_user($user_email, array('by' => 'email'))) { // if new user, or if multiple users with that email, or if only one user with that email, but it's not the user being updated if (!$ID || is_nxt_error($already_email) || $already_email->ID != $ID) { return new nxt_Error('user_email', __('Email already exists')); } } } if (!$ID || in_array('user_url', $fields)) { $user_url = esc_url($user_url); } if (!$ID || in_array('user_pass', $fields)) { if (!$user_pass) { $user_pass = nxt_Pass::generate_password(); } $plain_pass = $user_pass; $user_pass = nxt_Pass::hash_password($user_pass); } if (!$ID || in_array('user_registered', $fields)) { if (!is_numeric($user_registered)) { $user_registered = backpress_gmt_strtotime($user_registered); } if (!$user_registered || $user_registered < 0) { return new nxt_Error('user_registered', __('Invalid registration time')); } if (!($user_registered = @gmdate('Y-m-d H:i:s', $user_registered))) { return new nxt_Error('user_registered', __('Invalid registration timestamp')); } } if (!$ID || in_array('user_display', $fields)) { if (!$display_name) { $display_name = $user_login; } } $db_return = NULL; if ($ID) { $db_return = $this->db->update($this->db->users, compact($fields), compact('ID')); } else { $db_return = $this->db->insert($this->db->users, compact($fields)); $ID = $this->db->insert_id; } if (!$db_return) { return new nxt_Error('nxt_Users::_put_user', __('Query failed')); } // Cache the result if ($ID) { nxt_cache_delete($ID, 'users'); $this->get_user($ID, array('from_cache' => false)); } $args = compact(array_keys($args)); $args['plain_pass'] = $plain_pass; do_action(__CLASS__ . '::' . __FUNCTION__, $args); return $args; }
public function export_glossary_entries_get($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(); } $glossary_entries = GP::$glossary_entry->by_glossary_id($glossary->id); $filename = sprintf('%s-%s-glossary.csv', str_replace('/', '-', $project->path), $locale->slug); $last_modified = gmdate('D, d M Y H:i:s', backpress_gmt_strtotime(GP::$glossary_entry->last_modified($glossary))) . ' GMT'; $this->headers_for_download($filename, $last_modified); $this->print_export_file($locale->slug, $glossary_entries); }
/** * Has this translation been updated since the passed timestamp? * * @param GP_Translation_Set $translation_set Translation to check * @param int $timestamp Optional; unix timestamp to compare against. Defaults to HTTP_IF_MODIFIED_SINCE if set. * @return bool */ function gp_has_translation_been_updated($translation_set, $timestamp = 0) { // If $timestamp isn't set, try to default to the HTTP_IF_MODIFIED_SINCE header. if (!$timestamp && isset($_SERVER['HTTP_IF_MODIFIED_SINCE'])) { $timestamp = backpress_gmt_strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']); } // If nothing to compare against, then always assume there's an update available if (!$timestamp) { return true; } return backpress_gmt_strtotime(GP::$translation->last_modified($translation_set)) > $timestamp; }