public function gp_logo_url($url) { if (gp_const_get('GP_REMOVE_PROJECTS_FROM_BREADCRUMS_LOGO_URL')) { $url = $url . GP_REMOVE_PROJECTS_FROM_BREADCRUMS_LOGO_URL; } return $url; }
function setUp() { global $gpdb; $gpdb->suppress_errors = false; $gpdb->show_errors = false; if (defined('GP_DEBUG') && GP_DEBUG) { if (defined('E_DEPRECATED')) { error_reporting(E_ALL & ~E_DEPRECATED & ~E_STRICT); } else { error_reporting(E_ALL); } } ini_set('display_errors', 1); if (!gp_const_get('GP_IS_TEST_DB_INSTALLED')) { $gpdb->query('DROP DATABASE ' . GPDB_NAME . ";"); $gpdb->query('CREATE DATABASE ' . GPDB_NAME . ";"); $gpdb->select(GPDB_NAME, $gpdb->dbh); $gpdb->query('SET storage_engine = INNODB;'); $errors = gp_install(); if ($errors) { gp_error_log_dump($errors); die('ERROR: gp_install() returned errors! Check the error_log for complete SQL error message'); } define('GP_IS_TEST_DB_INSTALLED', true); } $this->factory = new GP_UnitTest_Factory(); $this->clean_up_global_scope(); $this->start_transaction(); ini_set('display_errors', 1); $this->url_filter = returner($this->url); add_filter('gp_get_option_uri', $this->url_filter); }
public function __construct() { if (!gp_const_get('GP_FORCE_SSL')) { return; } parent::__construct(); $this->add_action('plugins_loaded', array('priority' => 1)); }
public function __construct() { if (!gp_const_get('GP_USE_SLUG_FOR_DOWNLOADS')) { return; } parent::__construct(); $this->add_action('export_filename', array('args' => 5)); }
public function __construct() { if (!gp_const_get('GP_NEW_WINDOW_FOR_EXTERNAL_LINKS')) { return; } parent::__construct(); $this->add_action('pre_tmpl_load', array('args' => 2)); }
public function __construct() { if (!gp_const_get('GP_REMOVE_POWERED_BY')) { return; } parent::__construct(); $this->add_action('pre_tmpl_load', array('args' => 2)); $this->add_action('gp_footer', array('args' => 0, 'priority' => 1)); }
public function __construct() { if (!gp_const_get('GP_WORDPRESS_SINGLE_SIGN_ON')) { return; } parent::__construct(); $this->add_action('gp_logout_link', array('args' => 1)); $this->add_action('gp_login_link', array('args' => 1)); }
public function __construct() { $this->key = gp_const_get('GP_GOOGLE_TRANSLATE_KEY'); if (!$this->key) { return; } parent::__construct(); $this->add_action('pre_tmpl_load', array('args' => 2)); $this->add_filter('gp_entry_actions'); $this->add_action('gp_translation_set_bulk_action'); $this->add_action('gp_translation_set_bulk_action_post', array('args' => 4)); }
public function __construct() { // Get the date format we're going to use. $this->dateformat = gp_const_get('GP_LAST_UPDATE_FORMAT', 'M j Y @ g:i a'); // If for some reason the date format is empty, use the default. if ($this->dateformat == '') { $this->dateformat = 'M j Y @ g:i a'; } // Get the required permission to see the last update info, make sure it's all lower case. $reqperm = strtolower(gp_const_get('GP_LAST_UPDATE_REQUIRED_PERMISSION', false)); // If it's not recognized as read or approve, force it to admin. if ($reqperm != 'read' || $reqperm != 'approve') { $reqperm = 'admin'; } // Check to see the current user has permissions. if (GP::$permission->current_user_can($reqperm, 'project')) { // Add the hook. add_action('gp_project_template_translation_set_extra', array($this, 'gp_project_template_translation_set_extra'), 10, 2); } }
function gp_url_base_path() { return apply_filters('gp_url_base_path', user_trailingslashit('/' . gp_const_get('GP_URL_BASE', 'glotpress'))); }
public function bulk_export($project_path) { // The project path is url encoded, so decode before we do anything with it. $project_path = urldecode($project_path); // Loop through the supported format options and determine which ones we're exporting. $include_formats = array(); foreach (GP::$formats as $slug => $format) { if (gp_const_get('GP_BULK_DOWNLOAD_TRANSLATIONS_FORMAT_' . strtoupper(str_replace('.', '-', $slug)), false) == true) { $include_formats[] = $slug; } } // If we didn't have any formats set for export, use PO files by default. if (count($include_formats) == 0) { $include_formats = array('po'); } // Determine our temporary directory. $temp_dir = gp_const_get('GP_BULK_DOWNLOAD_TRANSLATIONS_TEMP_DIR', sys_get_temp_dir()); // Get a temporary file, use bdt as the first three letters of it. $temp_dir = tempnam($temp_dir, 'bdt'); // Now delete the file and recreate it as a directory. unlink($temp_dir); mkdir($temp_dir); // 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); // Setup an array to use to track the file names we're creating. $files = array(); // Loop through all the sets. foreach ($translation_sets as $set) { // Loop through all the formats we're exporting foreach ($include_formats as $format) { // Export the PO file for this translation set. $files[] .= $this->_export_to_file($format, $temp_dir, $project_obj, $locale, $set); } } // Setup the zip file name to use, it's the project name + .zip. $zip_file = $temp_dir . '/' . $project_path . '.zip'; // Create the new archive. $zip = new ZipArchive(); if ($zip->open($zip_file, ZipArchive::CREATE) === TRUE) { // Loop through all of the files we created and add them to the zip file. foreach ($files as $file) { // The first parameter is the full path to the local file, the second is the name as it will appear in the zip file. // Note this does not actually write data to the zip file. $zip->addFile($temp_dir . '/' . $file, $file); } // Close the zip file, this does the actual writing of the data. $zip->close(); } // Since we can't delete the export files until after we close the zip, loop through the files once more // and delete them. foreach ($files as $file) { unlink($temp_dir . '/' . $file); } // Generate our headers for the file download. $last_modified = gmdate('D, d M Y H:i:s') . ' GMT'; header('Content-Description: File Transfer'); header('Pragma: public'); header('Expires: 0'); header('Last-Modified: ' . $last_modified); header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); header('Content-Disposition: attachment; filename=' . $project_path . '.zip'); header('Content-Type: application/octet-stream'); header('Connection: close'); // Write the zip file out to the client. readfile($zip_file); // Delete the zip file. unlink($zip_file); // Remove the temporary directory and we're done! rmdir($temp_dir); }
public function generate_export_files($project, $path) { // Loop through the supported format options and determine which ones we're exporting. $include_formats = array(); foreach (GP::$formats as $slug => $format) { if (gp_const_get('GP_BULK_DOWNLOAD_TRANSLATIONS_FORMAT_' . strtoupper(str_replace('.', '-', $slug)), false) == true) { $include_formats[] = $slug; } } // If we didn't have any formats set for export, use PO files by default. if (count($include_formats) == 0) { $include_formats = array('po'); } // Get the translations sets from the project ID. $translation_sets = GP::$translation_set->by_project_id($project->id); // Setup an array to use to track the file names we're creating. $files = array(); // Loop through all the sets. foreach ($translation_sets as $set) { // Loop through all the formats we're exporting foreach ($include_formats as $format) { // Export the PO file for this translation set. $files[] .= $this->_export_to_file($format, $path, $project, $set->locale, $set); } } return $files; }
function gp_url_base_path() { /** * Filter the base path of a GlotPress URL. * * @since 1.0.0 * * @param string $url The url. */ return apply_filters('gp_url_base_path', user_trailingslashit('/' . gp_const_get('GP_URL_BASE', 'glotpress'))); }
define('WP_AUTH_COOKIE_VERSION', 2); } // WP_Pass if (!class_exists('WP_Pass')) { require_once BACKPRESS_PATH . 'class.wp-pass.php'; } // We assume all variables set in this file will be global. // If the file is inovked inside a function, we will lose them all. // So, make all local variables, global gp_set_globals(get_defined_vars()); if (!class_exists('WP_Auth')) { require_once BACKPRESS_PATH . 'class.wp-auth.php'; $cookies = array(); $cookies['auth'][] = array('domain' => isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : '', 'path' => gp_url_path(), 'name' => gp_const_get('GP_AUTH_COOKIE', 'glotpress_auth')); $cookies['secure_auth'][] = array('domain' => isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : '', 'path' => gp_url_path(), 'name' => gp_const_get('GP_SECURE_AUTH_COOKIE', 'glotpress_sec_auth'), 'secure' => 'true'); $cookies['logged_in'][] = array('domain' => isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : '', 'path' => gp_url_path(), 'name' => gp_const_get('GP_LOGGED_IN_COOKIE', 'glotpress_logged_in')); $wp_auth_object = new WP_Auth($gpdb, $wp_users_object, $cookies); unset($cookies); } require_once GP_PATH . GP_INC . 'warnings.php'; require_once GP_PATH . GP_INC . 'validation.php'; require_once GP_PATH . GP_INC . 'thing.php'; foreach (glob(GP_PATH . GP_INC . 'things/*.php') as $thing) { require_once $thing; } require_once GP_PATH . GP_INC . 'routes.php'; foreach (glob(GP_PATH . GP_INC . 'routes/*.php') as $route) { require_once $route; } GP::$translation_warnings = new GP_Translation_Warnings(); GP::$builtin_translation_warnings = new GP_Builtin_Translation_Warnings();
function gp_url_public_root() { return gp_const_get('GP_URL', gp_url_base_root()); }
/** * It is possible to define this in wp-config.php and it will be used as the domain for all cookies. * Set it carefully for sharing cookies amonst subdomains * * @link http://curl.haxx.se/rfc/cookie_spec.html */ if (!defined('GP_COOKIE_DOMAIN')) { define('GP_COOKIE_DOMAIN', false); } $_auth_class_name = gp_const_get('AUTH_CLASS', 'WP_Auth'); if (!class_exists($_auth_class_name)) { require_once gp_const_get('AUTH_CLASS_FILE', BACKPRESS_PATH . 'class.wp-auth.php'); $cookies = array(); $cookies['auth'][] = array('domain' => GP_COOKIE_DOMAIN, 'path' => gp_url_path(), 'name' => gp_const_get('GP_AUTH_COOKIE', 'glotpress_auth')); $cookies['secure_auth'][] = array('domain' => GP_COOKIE_DOMAIN, 'path' => gp_url_path(), 'name' => gp_const_get('GP_SECURE_AUTH_COOKIE', 'glotpress_sec_auth'), 'secure' => 'true'); $cookies['logged_in'][] = array('domain' => GP_COOKIE_DOMAIN, 'path' => gp_url_path(), 'name' => gp_const_get('GP_LOGGED_IN_COOKIE', 'glotpress_logged_in')); $wp_auth_object = new $_auth_class_name($gpdb, $wp_users_object, $cookies); unset($cookies); } unset($_auth_class_name); require_once GP_PATH . GP_INC . 'warnings.php'; require_once GP_PATH . GP_INC . 'validation.php'; require_once GP_PATH . GP_INC . 'advanced-permissions.php'; require_once GP_PATH . GP_INC . 'thing.php'; require_once GP_PATH . GP_INC . 'things/original.php'; require_once GP_PATH . GP_INC . 'things/permission.php'; require_once GP_PATH . GP_INC . 'things/project.php'; require_once GP_PATH . GP_INC . 'things/translation-set.php'; require_once GP_PATH . GP_INC . 'things/translation.php'; require_once GP_PATH . GP_INC . 'things/user.php'; require_once GP_PATH . GP_INC . 'things/validator-permission.php';
public function gp_translation_set_bulk_action_post($project, $locale, $translation_set, $bulk) { if ('gtranslate' != $bulk['action']) { return; } if (GP::$user->logged_in() && !$this->key) { $user_obj = GP::$user->current(); $user = strtoupper($user_obj->user_login); $user_key = gp_const_get('GP_GOOGLE_TRANSLATE_KEY_' . $user); if ($user_key) { $this->key = $user_key; } } if (!$this->key) { return; } $google_errors = 0; $insert_errors = 0; $ok = 0; $skipped = 0; $singulars = array(); $original_ids = array(); foreach ($bulk['row-ids'] as $row_id) { if (gp_in('-', $row_id)) { $skipped++; continue; } $original_id = gp_array_get(explode('-', $row_id), 0); $original = GP::$original->get($original_id); if (!$original || $original->plural) { $skipped++; continue; } $singulars[] = $original->singular; $original_ids[] = $original_id; } $results = $this->google_translate_batch($locale, $singulars); if (is_wp_error($results)) { error_log(print_r($results, true)); $this->errors[] = $results->get_error_message(); return; } $items = gp_array_zip($original_ids, $singulars, $results); if (!$items) { return; } foreach ($items as $item) { list($original_id, $singular, $translation) = $item; if (is_wp_error($translation)) { $google_errors++; error_log($translation->get_error_message()); continue; } $data = compact('original_id'); $data['user_id'] = GP::$user->current()->id; $data['translation_set_id'] = $translation_set->id; $data['translation_0'] = $translation; $data['status'] = 'fuzzy'; $data['warnings'] = GP::$translation_warnings->check($singular, null, array($translation), $locale); $inserted = GP::$translation->create($data); $inserted ? $ok++ : $insert_errors++; } if ($google_errors > 0 || $insert_errors > 0) { $message = array(); if ($ok) { $message[] = sprintf(__('Added: %d.'), $ok); } if ($google_errors) { $message[] = sprintf(__('Error from Google Translate: %d.'), $google_errors); } if ($insert_errors) { $message[] = sprintf(__('Error adding: %d.'), $insert_errors); } if ($skipped) { $message[] = sprintf(__('Skipped: %d.'), $skipped); } $this->errors[] = implode('', $message); } else { $this->notices[] = sprintf(__('%d fuzzy translation from Google Translate were added.'), $ok); } }