示例#1
0
function fetch_latest_version()
{
    $last_update_timestamp = WT_Site::preference('LATEST_WT_VERSION_TIMESTAMP');
    if ($last_update_timestamp < WT_TIMESTAMP - 24 * 60 * 60) {
        $row = WT_DB::prepare("SHOW VARIABLES LIKE 'version'")->fetchOneRow();
        $params = '?w=' . WT_VERSION . '&p=' . PHP_VERSION . '&m=' . $row->value . '&o=' . (DIRECTORY_SEPARATOR == '/' ? 'u' : 'w');
        $latest_version_txt = WT_File::fetchUrl('http://svn.webtrees.net/build/latest-version.txt' . $params);
        if ($latest_version_txt) {
            WT_Site::preference('LATEST_WT_VERSION', $latest_version_txt);
            WT_Site::preference('LATEST_WT_VERSION_TIMESTAMP', WT_TIMESTAMP);
            return $latest_version_txt;
        } else {
            // Cannot connect to server - use cached version (if we have one)
            return WT_Site::preference('LATEST_WT_VERSION');
        }
    } else {
        return WT_Site::preference('LATEST_WT_VERSION');
    }
}
示例#2
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);
     }
 }
示例#3
0
    echo '<br>', WT_I18N::translate('The file %s was deleted.', '<span dir="ltr">' . $lock_file . '</span>'), $icon_success;
} else {
    echo '<br>', WT_I18N::translate('The file %s could not be deleted.', '<span dir="ltr">' . $lock_file . '</span>'), $icon_failure;
}
echo '</li>';
flush();
////////////////////////////////////////////////////////////////////////////////
// Clean up
////////////////////////////////////////////////////////////////////////////////
echo '<li>', WT_I18N::translate('Delete temporary files…');
reset_timeout();
if (WT_File::delete($zip_dir)) {
    echo '<br>', WT_I18N::translate('The folder %s was deleted.', '<span dir="auto">' . $zip_dir . '</span>'), $icon_success;
} else {
    echo '<br>', WT_I18N::translate('The folder %s could not be deleted.', '<span dir="auto">' . $zip_dir . '</span>'), $icon_failure;
}
if (WT_File::delete($zip_file)) {
    echo '<br>', WT_I18N::translate('The file %s was deleted.', '<span dir="auto">' . $zip_file . '</span>'), $icon_success;
} else {
    echo '<br>', WT_I18N::translate('The file %s could not be deleted.', '<span dir="auto">' . $zip_file . '</span>'), $icon_failure;
}
echo '</li>';
echo '</ul>';
echo '<p>', WT_I18N::translate('The upgrade is complete.'), '</p>';
// Reset the time limit, as timeouts in this script could leave the upgrade incomplete.
function reset_timeout()
{
    if (!ini_get('safe_mode') && strpos(ini_get('disable_functions'), 'set_time_limit') === false) {
        set_time_limit(ini_get('max_execution_time'));
    }
}
示例#4
0
文件: I18N.php 项目: sadr110/webtrees
 /**
  * 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;
 }
        // 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');
            header('Content-Disposition: attachment; filename="' . $zip_file . '"');
            header('Content-length: ' . filesize($temp_dir . $zip_file));
            readfile($temp_dir . $zip_file);
            WT_File::delete($temp_dir);
        }
    } else {
        Zend_Session::writeClose();
        header('Content-Type: text/plain; charset=UTF-8');
        header('Content-Disposition: attachment; filename="' . $download_filename . '"');
        // Stream the GEDCOM file straight to the browser.
        // We could open "php://compress.zlib" to create a .gz file or "php://compress.bzip2" to create a .bz2 file
        $stream = fopen('php://output', 'w');
        export_gedcom(WT_GEDCOM, $stream, $exportOptions);
        fclose($stream);
    }
    exit;
}
$controller->pageHeader();
?>
示例#6
0
require WT_ROOT . 'includes/functions/functions_edit.php';
$controller = new WT_Controller_Page();
$controller->restrictAccess(Auth::isManager())->addInlineJavascript('jQuery("#x").accordion({heightStyle: "content"});')->addInlineJavascript('jQuery("#tree_stats").accordion();')->addInlineJavascript('jQuery("#changes").accordion();')->addInlineJavascript('jQuery("#content_container").css("visibility", "visible");')->setPageTitle(WT_I18N::translate('Administration'))->pageHeader();
// Check for updates
$latest_version_txt = fetch_latest_version();
if (preg_match('/^[0-9.]+\\|[0-9.]+\\|/', $latest_version_txt)) {
    list($latest_version, $earliest_version, $download_url) = explode('|', $latest_version_txt);
} else {
    // Cannot determine the latest version
    $latest_version = '';
}
// Delete old files (if we can).
$old_files = array();
foreach (old_paths() as $path) {
    if (file_exists($path)) {
        if (!WT_File::delete($path)) {
            // We may be unable to delete it.  If so, tell the user to delete it manually.
            $old_files[] = $path;
        }
    }
}
// Total number of users
$total_users = User::count();
// Total number of administrators
$total_administrators = WT_DB::prepare("SELECT COUNT(*) FROM `##user_setting` WHERE setting_name='canadmin' AND setting_value=1")->fetchOne();
// Total numbers of managers
$total_managers = WT_DB::prepare("SELECT gs.setting_value, COUNT(*)" . " FROM `##gedcom_setting` gs" . " JOIN `##user_gedcom_setting` ugs USING (gedcom_id)" . " WHERE ugs.setting_name = 'canedit' AND ugs.setting_value='admin'" . " AND   gs.setting_name ='title'" . " GROUP BY gedcom_id" . " ORDER BY gs.setting_value")->fetchAssoc();
// Number of users who have not verified their email address
$unverified = WT_DB::prepare("SELECT COUNT(*) FROM `##user_setting` WHERE setting_name='verified' AND setting_value=0")->fetchOne();
// Number of users whose accounts are not approved by an administrator
$unapproved = WT_DB::prepare("SELECT COUNT(*) FROM `##user_setting` WHERE setting_name='verified_by_admin' AND setting_value=0")->fetchOne();