Example #1
0
 public static function mkdir($path)
 {
     if (is_dir($path)) {
         return true;
     } else {
         if (!is_dir(dirname($path))) {
             WT_File::mkdir(dirname($path));
         }
         @mkdir($path);
         return is_dir($path);
     }
 }
Example #2
0
 /**
  * Initialise the translation adapter with a locale setting.
  *
  * @param string|null $locale If no locale specified, choose one automatically
  *
  * @return string $string
  */
 public static function init($locale = null)
 {
     global $WT_SESSION;
     // The translation libraries only work with a cache.
     $cache_options = array('automatic_serialization' => true, 'cache_id_prefix' => md5(WT_SERVER_NAME . WT_SCRIPT_PATH));
     if (ini_get('apc.enabled')) {
         self::$cache = Zend_Cache::factory('Core', 'Apc', $cache_options, array());
     } elseif (WT_File::mkdir(WT_DATA_DIR . 'cache')) {
         self::$cache = Zend_Cache::factory('Core', 'File', $cache_options, array('cache_dir' => WT_DATA_DIR . 'cache'));
     } else {
         self::$cache = Zend_Cache::factory('Core', 'Zend_Cache_Backend_BlackHole', $cache_options, array(), false, true);
     }
     Zend_Locale::setCache(self::$cache);
     Zend_Translate::setCache(self::$cache);
     $installed_languages = self::installed_languages();
     if (is_null($locale) || !array_key_exists($locale, $installed_languages)) {
         // Automatic locale selection.
         $locale = WT_Filter::get('lang');
         if ($locale && array_key_exists($locale, $installed_languages)) {
             // Requested in the URL?
             if (Auth::id()) {
                 Auth::user()->setSetting('language', $locale);
             }
         } elseif (array_key_exists($WT_SESSION->locale, $installed_languages)) {
             // Rembered from a previous visit?
             $locale = $WT_SESSION->locale;
         } else {
             // Browser preference takes priority over gedcom default
             if (!empty($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
                 $prefs = explode(',', str_replace(' ', '', $_SERVER['HTTP_ACCEPT_LANGUAGE']));
             } else {
                 $prefs = array();
             }
             if (WT_GED_ID) {
                 // Add the tree’s default language as a low-priority
                 $locale = get_gedcom_setting(WT_GED_ID, 'LANGUAGE');
                 $prefs[] = $locale . ';q=0.2';
             }
             $prefs2 = array();
             foreach ($prefs as $pref) {
                 list($l, $q) = explode(';q=', $pref . ';q=1.0');
                 $l = preg_replace_callback('/_[a-z][a-z]$/', function ($x) {
                     return strtoupper($x[0]);
                 }, str_replace('-', '_', $l));
                 // en-gb => en_GB
                 if (array_key_exists($l, $prefs2)) {
                     $prefs2[$l] = max((double) $q, $prefs2[$l]);
                 } else {
                     $prefs2[$l] = (double) $q;
                 }
             }
             // Ensure there is a fallback.
             if (!array_key_exists('en_US', $prefs2)) {
                 $prefs2['en_US'] = 0.01;
             }
             arsort($prefs2);
             foreach (array_keys($prefs2) as $pref) {
                 if (array_key_exists($pref, $installed_languages)) {
                     $locale = $pref;
                     break;
                 }
             }
         }
     }
     // Load the translation file
     self::$translation_adapter = new Zend_Translate('gettext', WT_ROOT . 'language/' . $locale . '.mo', $locale);
     // Deprecated - some custom modules use this to add translations
     Zend_Registry::set('Zend_Translate', self::$translation_adapter);
     // Load any local user translations
     if (is_dir(WT_DATA_DIR . 'language')) {
         if (file_exists(WT_DATA_DIR . 'language/' . $locale . '.mo')) {
             self::addTranslation(new Zend_Translate('gettext', WT_DATA_DIR . 'language/' . $locale . '.mo', $locale));
         }
         if (file_exists(WT_DATA_DIR . 'language/' . $locale . '.php')) {
             self::addTranslation(new Zend_Translate('array', WT_DATA_DIR . 'language/' . $locale . '.php', $locale));
         }
         if (file_exists(WT_DATA_DIR . 'language/' . $locale . '.csv')) {
             self::addTranslation(new Zend_Translate('csv', WT_DATA_DIR . 'language/' . $locale . '.csv', $locale));
         }
     }
     // Extract language settings from the translation file
     global $DATE_FORMAT;
     // I18N: This is the format string for full dates.  See http://php.net/date for codes
     $DATE_FORMAT = self::noop('%j %F %Y');
     global $TIME_FORMAT;
     // I18N: This is the format string for the time-of-day.  See http://php.net/date for codes
     $TIME_FORMAT = self::noop('%H:%i:%s');
     // Alphabetic sorting sequence (upper-case letters), used by webtrees to sort strings
     list(, self::$alphabet_upper) = explode('=', self::noop('ALPHABET_upper=ABCDEFGHIJKLMNOPQRSTUVWXYZ'));
     // Alphabetic sorting sequence (lower-case letters), used by webtrees to sort strings
     list(, self::$alphabet_lower) = explode('=', self::noop('ALPHABET_lower=abcdefghijklmnopqrstuvwxyz'));
     global $WEEK_START;
     // I18N: This is the first day of the week on calendars. 0=Sunday, 1=Monday...
     list(, $WEEK_START) = explode('=', self::noop('WEEK_START=0'));
     global $TEXT_DIRECTION;
     $TEXT_DIRECTION = self::scriptDirection(self::languageScript($locale));
     self::$locale = $locale;
     self::$dir = $TEXT_DIRECTION;
     // I18N: This punctuation is used to separate lists of items.
     self::$list_separator = self::translate(', ');
     // I18N: This is the name of the MySQL collation that applies to your language.  A list is available at http://dev.mysql.com/doc/refman/5.0/en/charset-unicode-sets.html
     self::$collation = self::translate('utf8_unicode_ci');
     // Non-latin numbers may require non-latin digits
     try {
         self::$numbering_system = Zend_Locale_Data::getContent($locale, 'defaultnumberingsystem');
     } catch (Zend_Locale_Exception $ex) {
         // The latest CLDR database omits some languges such as Tatar (tt)
         self::$numbering_system = 'latin';
     }
     return $locale;
 }
} else {
    echo $icon_failure;
    // Guess why we might have failed...
    if (preg_match('/^https:/', $download_url) && !in_array('ssl', stream_get_transports())) {
        echo '<br>', WT_I18N::translate('This server does not support secure downloads using HTTPS.');
    }
}
echo '</li>';
flush();
////////////////////////////////////////////////////////////////////////////////
// Unzip the file - this checks we have enough free disk space, that the .zip
// file is valid, etc.
////////////////////////////////////////////////////////////////////////////////
echo '<li>', WT_I18N::translate('Unzip %s to a temporary folder…', basename($download_url));
WT_File::delete($zip_dir);
WT_File::mkdir($zip_dir);
$archive = new PclZip($zip_file);
$res = $archive->properties();
if (!is_array($res) || $res['status'] != 'ok') {
    echo '<br>', WT_I18N::translate('An error occurred when unzipping the file.'), $icon_failure;
    echo '</li></ul></form>';
    exit;
}
$num_files = $res['nb'];
reset_timeout();
$start_time = microtime(true);
$res = $archive->extract(PCLZIP_OPT_PATH, $zip_dir, PCLZIP_OPT_REMOVE_PATH, 'webtrees', PCLZIP_OPT_REPLACE_NEWER);
$end_time = microtime(true);
if (is_array($res)) {
    foreach ($res as $result) {
        // Note that we're stripping the initial "webtrees/", so the top folder will fail.
$convert = WT_Filter::get('convert', 'yes|no', 'no');
$zip = WT_Filter::get('zip', 'yes|no', 'no');
$conv_path = WT_Filter::get('conv_path');
$privatize_export = WT_Filter::get('privatize_export', 'none|visitor|user|gedadmin');
if ($action == 'download') {
    $exportOptions = array('privatize' => $privatize_export, 'toANSI' => $convert, 'path' => $conv_path);
    // What to call the downloaded file
    $download_filename = WT_GEDCOM;
    if (strtolower(substr($download_filename, -4, 4)) != '.ged') {
        $download_filename .= '.ged';
    }
    if ($zip == "yes") {
        require WT_ROOT . 'library/pclzip.lib.php';
        $temp_dir = WT_DATA_DIR . 'tmp-' . WT_GEDCOM . '-' . date("YmdHis") . '/';
        $zip_file = $download_filename . ".zip";
        if (!WT_File::mkdir($temp_dir)) {
            echo "Error : Could not create temporary path!";
            exit;
        }
        // Create the unzipped GEDCOM on disk, so we can ZIP it.
        $stream = fopen($temp_dir . $download_filename, "w");
        export_gedcom(WT_GEDCOM, $stream, $exportOptions);
        fclose($stream);
        // Create a ZIP file containing the GEDCOM file.
        $comment = "Created by " . WT_WEBTREES . " " . WT_VERSION . " on " . date("r") . ".";
        $archive = new PclZip($temp_dir . $zip_file);
        $v_list = $archive->add($temp_dir . $download_filename, PCLZIP_OPT_COMMENT, $comment, PCLZIP_OPT_REMOVE_PATH, $temp_dir);
        if ($v_list == 0) {
            echo "Error : " . $archive->errorInfo(true);
        } else {
            header('Content-Type: application/zip');