本文整理汇总了PHP中WT_Site类的典型用法代码示例。如果您正苦于以下问题:PHP WT_Site类的具体用法?PHP WT_Site怎么用?PHP WT_Site使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了WT_Site类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: fetch_latest_version
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: transport
public static function transport()
{
switch (WT_Site::getPreference('SMTP_ACTIVE')) {
case 'internal':
return new Zend_Mail_Transport_Sendmail();
case 'external':
$config = array('name' => WT_Site::getPreference('SMTP_HELO'), 'port' => WT_Site::getPreference('SMTP_PORT'));
if (WT_Site::getPreference('SMTP_AUTH')) {
$config['auth'] = 'login';
$config['username'] = WT_Site::getPreference('SMTP_AUTH_USER');
$config['password'] = WT_Site::getPreference('SMTP_AUTH_PASS');
}
if (WT_Site::getPreference('SMTP_SSL') !== 'none') {
$config['ssl'] = WT_Site::getPreference('SMTP_SSL');
}
return new Zend_Mail_Transport_Smtp(WT_Site::getPreference('SMTP_HOST'), $config);
default:
// For testing
return new Zend_Mail_Transport_File();
}
}
示例3: getBlock
public function getBlock($block_id, $template = true, $cfg = null)
{
global $controller;
$indi_xref = $controller->getSignificantIndividual()->getXref();
$id = $this->getName() . $block_id;
$class = $this->getName() . '_block';
$title = '<span dir="auto">' . WT_TREE_TITLE . '</span>';
$content = '<table><tr>';
$content .= '<td><a href="pedigree.php?rootid=' . $indi_xref . '&ged=' . WT_GEDURL . '"><i class="icon-pedigree"></i><br>' . WT_I18N::translate('Default chart') . '</a></td>';
$content .= '<td><a href="individual.php?pid=' . $indi_xref . '&ged=' . WT_GEDURL . '"><i class="icon-indis"></i><br>' . WT_I18N::translate('Default individual') . '</a></td>';
if (WT_Site::preference('USE_REGISTRATION_MODULE') && WT_USER_ID == false) {
$content .= '<td><a href="' . WT_LOGIN_URL . '?action=register"><i class="icon-user_add"></i><br>' . WT_I18N::translate('Request new user account') . '</a></td>';
}
$content .= "</tr>";
$content .= "</table>";
if ($template) {
require WT_THEME_DIR . 'templates/block_main_temp.php';
} else {
return $content;
}
}
示例4: color_theme_dropdown
function color_theme_dropdown()
{
global $COLOR_THEME_LIST, $WT_SESSION, $subColor;
$menu = new WT_Menu(WT_I18N::translate('Palette'), '#', 'menu-color');
uasort($COLOR_THEME_LIST, array('WT_I18N', 'strcasecmp'));
foreach ($COLOR_THEME_LIST as $colorChoice => $colorName) {
$submenu = new WT_Menu($colorName, get_query_url(array('themecolor' => $colorChoice), '&'), 'menu-color-' . $colorChoice);
if (isset($WT_SESSION->subColor)) {
if ($WT_SESSION->subColor == $colorChoice) {
$submenu->addClass('', '', 'theme-active');
}
} elseif (WT_Site::preference('DEFAULT_COLOR_PALETTE') == $colorChoice) {
/* here when visitor changes palette from default */
$submenu->addClass('', '', 'theme-active');
} elseif ($subColor == 'ash') {
/* here when site has different theme as default and user switches to colors */
if ($subColor == $colorChoice) {
$submenu->addClass('', '', 'theme-active');
}
}
$menu->addSubMenu($submenu);
}
return $menu->getMenuAsList();
}
示例5: IN
}
// TODO May need to set 'DATA_DIRECTORY' to $INDEX_DIRECTORY when dealing with media??
@WT_Site::preference('USE_REGISTRATION_MODULE', $USE_REGISTRATION_MODULE);
@WT_Site::preference('REQUIRE_ADMIN_AUTH_REGISTRATION', $REQUIRE_ADMIN_AUTH_REGISTRATION);
@WT_Site::preference('ALLOW_USER_THEMES', $ALLOW_USER_THEMES);
@WT_Site::preference('ALLOW_CHANGE_GEDCOM', $ALLOW_CHANGE_GEDCOM);
@WT_Site::preference('SESSION_TIME', $PGV_SESSION_TIME);
@WT_Site::preference('SMTP_ACTIVE', $PGV_SMTP_ACTIVE ? 'external' : 'internal');
@WT_Site::preference('SMTP_HOST', $PGV_SMTP_HOST);
@WT_Site::preference('SMTP_HELO', $PGV_SMTP_HELO);
@WT_Site::preference('SMTP_PORT', $PGV_SMTP_PORT);
@WT_Site::preference('SMTP_AUTH', $PGV_SMTP_AUTH);
@WT_Site::preference('SMTP_AUTH_USER', $PGV_SMTP_AUTH_USER);
@WT_Site::preference('SMTP_AUTH_PASS', $PGV_SMTP_AUTH_PASS);
@WT_Site::preference('SMTP_SSL', $PGV_SMTP_SSL);
@WT_Site::preference('SMTP_FROM_NAME', $PGV_SMTP_FROM_NAME);
////////////////////////////////////////////////////////////////////////////////
echo '<p>pgv_site_setting => wt_site_setting ...</p>';
flush();
if (ini_get('output_buffering')) {
ob_flush();
}
WT_DB::prepare("REPLACE INTO `##site_setting` (setting_name, setting_value)" . " SELECT site_setting_name, site_setting_value FROM `{$DBNAME}`.`{$TBLPREFIX}site_setting`" . " WHERE site_setting_name IN ('DEFAULT_GEDCOM', 'LAST_CHANGE_EMAIL')")->execute();
////////////////////////////////////////////////////////////////////////////////
if ($PGV_SCHEMA_VERSION >= 12) {
echo '<p>pgv_gedcom => wt_gedcom ...</p>';
flush();
if (ini_get('output_buffering')) {
ob_flush();
}
WT_DB::prepare("INSERT INTO `##gedcom` (gedcom_id, gedcom_name)" . " SELECT gedcom_id, gedcom_name FROM `{$DBNAME}`.`{$TBLPREFIX}gedcom`")->execute();
示例6: edit_field_yes_no_inline
</dt>
<dd><?php
echo edit_field_yes_no_inline('site_setting-USE_REGISTRATION_MODULE', WT_Site::preference('USE_REGISTRATION_MODULE'), $controller);
?>
</dd>
<dt><?php
echo WT_I18N::translate('Require an administrator to approve new user registrations'), help_link('REQUIRE_ADMIN_AUTH_REGISTRATION');
?>
</dt>
<dd><?php
echo edit_field_yes_no_inline('site_setting-REQUIRE_ADMIN_AUTH_REGISTRATION', WT_Site::preference('REQUIRE_ADMIN_AUTH_REGISTRATION'), $controller);
?>
</dd>
<dt><?php
echo WT_I18N::translate('Show acceptable use agreement on “Request new user account” page'), help_link('SHOW_REGISTER_CAUTION');
?>
</dt>
<dd><?php
echo edit_field_yes_no_inline('site_setting-SHOW_REGISTER_CAUTION', WT_Site::preference('SHOW_REGISTER_CAUTION'), $controller);
?>
</dd>
</dl>
</td>
</tr>
</table>
</div>
</div>
</div>
示例7: getBlock
public function getBlock($block_id, $template = true, $cfg = null)
{
global $ctype, $WEBTREES_EMAIL;
$changes = WT_DB::prepare("SELECT 1" . " FROM `##change`" . " WHERE status='pending'" . " LIMIT 1")->fetchOne();
$days = get_block_setting($block_id, 'days', 1);
$sendmail = get_block_setting($block_id, 'sendmail', true);
$block = get_block_setting($block_id, 'block', true);
if ($cfg) {
foreach (array('days', 'sendmail', 'block') as $name) {
if (array_key_exists($name, $cfg)) {
${$name} = $cfg[$name];
}
}
}
if ($changes && $sendmail == 'yes') {
// There are pending changes - tell moderators/managers/administrators about them.
if (WT_TIMESTAMP - WT_Site::getPreference('LAST_CHANGE_EMAIL') > 60 * 60 * 24 * $days) {
// Which users have pending changes?
foreach (User::all() as $user) {
if ($user->getSetting('contactmethod') !== 'none') {
foreach (WT_Tree::getAll() as $tree) {
if (exists_pending_change($user, $tree)) {
WT_I18N::init($user->getSetting('language'));
WT_Mail::systemMessage($tree, $user, WT_I18N::translate('Pending changes'), WT_I18N::translate('There are pending changes for you to moderate.') . WT_Mail::EOL . WT_MAIL::EOL . '<a href="' . WT_SERVER_NAME . WT_SCRIPT_PATH . 'index.php?ged=' . WT_GEDURL . '">' . WT_SERVER_NAME . WT_SCRIPT_PATH . 'index.php?ged=' . WT_GEDURL . '</a>');
WT_I18N::init(WT_LOCALE);
}
}
}
}
WT_Site::setPreference('LAST_CHANGE_EMAIL', WT_TIMESTAMP);
}
if (WT_USER_CAN_EDIT) {
$id = $this->getName() . $block_id;
$class = $this->getName() . '_block';
if ($ctype == 'gedcom' && WT_USER_GEDCOM_ADMIN || $ctype == 'user' && WT_USER_ID) {
$title = '<i class="icon-admin" title="' . WT_I18N::translate('Configure') . '" onclick="modalDialog(\'block_edit.php?block_id=' . $block_id . '\', \'' . $this->getTitle() . '\');"></i>';
} else {
$title = '';
}
$title .= $this->getTitle() . help_link('review_changes', $this->getName());
$content = '';
if (WT_USER_CAN_ACCEPT) {
$content .= "<a href=\"#\" onclick=\"window.open('edit_changes.php','_blank', chan_window_specs); return false;\">" . WT_I18N::translate('There are pending changes for you to moderate.') . "</a><br>";
}
if ($sendmail == "yes") {
$content .= WT_I18N::translate('Last email reminder was sent ') . format_timestamp(WT_Site::getPreference('LAST_CHANGE_EMAIL')) . "<br>";
$content .= WT_I18N::translate('Next email reminder will be sent after ') . format_timestamp(WT_Site::getPreference('LAST_CHANGE_EMAIL') + 60 * 60 * 24 * $days) . "<br><br>";
}
$changes = WT_DB::prepare("SELECT xref" . " FROM `##change`" . " WHERE status='pending'" . " AND gedcom_id=?" . " GROUP BY xref")->execute(array(WT_GED_ID))->fetchAll();
foreach ($changes as $change) {
$record = WT_GedcomRecord::getInstance($change->xref);
if ($record->canShow()) {
$content .= '<b>' . $record->getFullName() . '</b>';
$content .= $block ? '<br>' : ' ';
$content .= '<a href="' . $record->getHtmlUrl() . '">' . WT_I18N::translate('View the changes') . '</a>';
$content .= '<br>';
}
}
if ($template) {
if ($block) {
require WT_THEME_DIR . 'templates/block_small_temp.php';
} else {
require WT_THEME_DIR . 'templates/block_main_temp.php';
}
} else {
return $content;
}
}
}
}
示例8: get_gedcom_setting
$THEME_DIR = $WT_SESSION->theme_dir;
}
} else {
$THEME_DIR = '';
}
if (!$THEME_DIR) {
// User cannot choose (or has not chosen) a theme.
// 1) gedcom setting
// 2) site setting
// 3) webtrees
// 4) first one found
if (WT_GED_ID) {
$THEME_DIR = get_gedcom_setting(WT_GED_ID, 'THEME_DIR');
}
if (!in_array($THEME_DIR, get_theme_names())) {
$THEME_DIR = WT_Site::preference('THEME_DIR');
}
if (!in_array($THEME_DIR, get_theme_names())) {
$THEME_DIR = 'webtrees';
}
if (!in_array($THEME_DIR, get_theme_names())) {
list($THEME_DIR) = get_theme_names();
}
}
define('WT_THEME_DIR', WT_THEMES_DIR . $THEME_DIR . '/');
// Remember this setting
if (WT_THEME_DIR != WT_THEMES_DIR . '_administration/') {
$WT_SESSION->theme_dir = $THEME_DIR;
}
}
// If we have specified a CDN, use it for static theme resources
示例9: updateSchema
/**
* Run a series of scripts to bring the database schema up to date.
*
* @param $schema_dir
* @param $schema_name
* @param $target_version
*
* @return void
* @throws Exception
*/
public static function updateSchema($schema_dir, $schema_name, $target_version)
{
try {
$current_version = (int) WT_Site::getPreference($schema_name);
} catch (PDOException $e) {
// During initial installation, this table won’t exist.
// It will only be a problem if we can’t subsequently create it.
$current_version = 0;
}
// During installation, the current version is set to a special value of
// -1 (v1.2.5 to v1.2.7) or -2 (v1.3.0 onwards). This indicates that the tables have
// been created, and we are already at the latest version.
switch ($current_version) {
case -1:
// Due to a bug in webtrees 1.2.5 - 1.2.7, the setup value of "-1"
// wasn't being updated.
$current_version = 12;
WT_Site::setPreference($schema_name, $current_version);
break;
case -2:
// Because of the above bug, we now set the version to -2 during setup.
$current_version = $target_version;
WT_Site::setPreference($schema_name, $current_version);
break;
}
// Update the schema, one version at a time.
while ($current_version < $target_version) {
$next_version = $current_version + 1;
require $schema_dir . 'db_schema_' . $current_version . '_' . $next_version . '.php';
// The updatescript should update the version or throw an exception
$current_version = (int) WT_Site::getPreference($schema_name);
if ($current_version != $next_version) {
throw new Exception("Internal error while updating {$schema_name} to {$next_version}");
}
}
}
示例10: header
<div>
<label for="user_password">', WT_I18N::translate('Password'), '</label>
<input type="password" id="user_password" name="user_password" value="" autofocus>
</div>
<div>
<label for="user_hashcode">', WT_I18N::translate('Verification code:'), '</label>
<input type="text" id="user_hashcode" name="user_hashcode" value="', $user_hashcode, '">
</div>
<div>
<input type="submit" value="', WT_I18N::translate('Send'), '">
</div>
</form>
</div>';
break;
case 'verify_hash':
if (!WT_Site::preference('USE_REGISTRATION_MODULE')) {
header('Location: ' . WT_SERVER_NAME . WT_SCRIPT_PATH);
exit;
}
// switch language to webmaster settings
$webmaster = User::find(get_gedcom_setting(WT_GED_ID, 'WEBMASTER_USER_ID'));
WT_I18N::init($webmaster->getSetting('language'));
$user = User::findByIdentifier($user_name);
$mail1_body = WT_I18N::translate('Hello administrator…') . WT_Mail::EOL . WT_Mail::EOL . WT_I18N::translate('A new user (%1$s) has requested an account (%2$s) and verified an email address (%3$s).', $user->getRealName(), $user->getUserName(), $user->getEmail()) . WT_Mail::EOL . WT_Mail::EOL;
if ($REQUIRE_ADMIN_AUTH_REGISTRATION && !$user->getSetting('verified_by_admin')) {
$mail1_body .= WT_I18N::translate('You now need to review the account details, and set the “approved” status to “yes”.');
} else {
$mail1_body .= WT_I18N::translate('You do not have to take any action; the user can now login.');
}
$mail1_body .= WT_Mail::EOL . '<a href="' . WT_SERVER_NAME . WT_SCRIPT_PATH . "admin_users.php?filter=" . rawurlencode($user->getUserName()) . '">' . WT_SERVER_NAME . WT_SCRIPT_PATH . "admin_users.php?filter=" . rawurlencode($user->getUserName()) . '</a>' . WT_Mail::auditFooter();
$mail1_subject = WT_I18N::translate('New user at %s', WT_SERVER_NAME . WT_SCRIPT_PATH . ' ' . $WT_TREE->tree_title);
示例11: modalDialog
$in_progress = WT_DB::prepare("SELECT 1 FROM `##gedcom_chunk` WHERE gedcom_id=? AND imported=1 LIMIT 1")->execute(array($tree->tree_id))->fetchOne();
if (!$in_progress) {
echo '<div id="import', $tree->tree_id, '"><div id="progressbar', $tree->tree_id, '"><div style="position:absolute;">', WT_I18N::translate('Deleting old genealogy data…'), '</div></div></div>';
$controller->addInlineJavascript('jQuery("#progressbar' . $tree->tree_id . '").progressbar({value: 0});');
} else {
echo '<div id="import', $tree->tree_id, '"></div>';
}
$controller->addInlineJavascript('jQuery("#import' . $tree->tree_id . '").load("import.php?gedcom_id=' . $tree->tree_id . '&keep_media' . $tree->tree_id . '=' . WT_Filter::get('keep_media' . $tree->tree_id) . '");');
echo '<table border="0" width="100%" id="actions', $tree->tree_id, '" style="display:none">';
} else {
echo '<table border="0" width="100%" id="actions', $tree->tree_id, '">';
}
echo '<tr align="center">', '<td><a href="admin_trees_export.php?ged=', $tree->tree_name_url, '" onclick="return modalDialog(\'admin_trees_export.php?ged=', $tree->tree_name_url, '\', \'', WT_I18N::translate('Export'), '\');">', WT_I18N::translate('Export'), '</a>', help_link('export_gedcom'), '</td>', '<td><a href="', WT_SCRIPT_NAME, '?action=importform&gedcom_id=', $tree->tree_id, '">', WT_I18N::translate('Import'), '</a>', help_link('import_gedcom'), '</td>', '<td><a href="admin_trees_download.php?ged=', $tree->tree_name_url, '">', WT_I18N::translate('Download'), '</a>', help_link('download_gedcom'), '</td>', '<td><a href="', WT_SCRIPT_NAME, '?action=uploadform&gedcom_id=', $tree->tree_id, '">', WT_I18N::translate('Upload'), '</a>', help_link('upload_gedcom'), '</td>', '<td>', '<a href="#" onclick="if (confirm(\'' . WT_Filter::escapeJs(WT_I18N::translate('Are you sure you want to delete “%s”?', $tree->tree_name)), '\')) document.delete_form', $tree->tree_id, '.submit(); return false;">', WT_I18N::translate('Delete'), '</a>', '<form name="delete_form', $tree->tree_id, '" method="post" action="', WT_SCRIPT_NAME, '">', '<input type="hidden" name="action" value="delete">', '<input type="hidden" name="gedcom_id" value="', $tree->tree_id, '">', WT_Filter::getCsrf(), '</form>', '</td></tr></table></td></tr></table><br>';
}
}
// Options for creating new gedcoms and setting defaults
if (Auth::isAdmin()) {
echo '<table class="gedcom_table2"><tr>';
if (count(WT_Tree::GetAll()) > 1) {
echo '<th>', WT_I18N::translate('Default family tree'), help_link('default_gedcom'), '</th>';
}
echo '<th>', WT_I18N::translate('Create a new family tree'), help_link('add_new_gedcom'), '</th></tr><tr>';
if (count(WT_Tree::GetAll()) > 1) {
echo '<td><form name="defaultform" method="post" action="', WT_SCRIPT_NAME, '">', '<input type="hidden" name="action" value="setdefault">', WT_Filter::getCsrf(), select_edit_control('default_ged', WT_Tree::getNameList(), '', WT_Site::preference('DEFAULT_GEDCOM'), 'onchange="document.defaultform.submit();"'), '</form></td>';
}
echo '<td class="button">', '<form name="createform" method="post" action="', WT_SCRIPT_NAME, '">', WT_Filter::getCsrf(), '<input type="hidden" name="action" value="new_tree">', '<input name="ged_name">', ' <input type="submit" value="', WT_I18N::translate('save'), '">', '</form>', '</td>', '</tr></table><br>';
// display link to PGV-WT transfer wizard on first visit to this page, before any GEDCOM is loaded
if (count(WT_Tree::GetAll()) == 0 && count(User::all()) == 1) {
echo '<div class="center">', '<a style="color:green; font-weight:bold;" href="admin_pgv_to_wt.php">', WT_I18N::translate('Click here for PhpGedView to <b>webtrees</b> transfer wizard'), '</a>', help_link('PGV_WIZARD'), '</div>';
}
}
示例12: header
}
} else {
header('HTTP/1.0 406 Not Acceptable');
}
break;
case 'reject-changes':
// Reject all the pending changes for a record
$record = WT_GedcomRecord::getInstance(WT_Filter::post('xref', WT_REGEX_XREF));
if ($record && WT_USER_CAN_ACCEPT && $record->canShow() && $record->canEdit()) {
WT_FlashMessages::addMessage(WT_I18N::translate('The changes to “%s” have been rejected.', $record->getFullName()));
reject_all_changes($record->getXref(), $record->getGedcomId());
} else {
header('HTTP/1.0 406 Not Acceptable');
}
break;
case 'theme':
// Change the current theme
$theme_dir = WT_Filter::post('theme');
if (WT_Site::getPreference('ALLOW_USER_THEMES') && in_array($theme_dir, get_theme_names())) {
$WT_SESSION->theme_dir = $theme_dir;
if (Auth::id()) {
// Remember our selection
Auth::user()->setSetting('theme', $theme_dir);
}
} else {
// Request for a non-existant theme.
header('HTTP/1.0 406 Not Acceptable');
}
break;
}
Zend_Session::writeClose();
示例13: array
$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();
$exportOptions['privatize'] = $privatize_export;
$exportOptions['toANSI'] = $convert;
$exportOptions['path'] = $conv_path;
}
$fileName = WT_GEDCOM;
if ($action == "download" && $zip == "yes") {
require WT_ROOT . 'library/pclzip.lib.php';
$temppath = WT_Site::preference('INDEX_DIRECTORY') . "tmp/";
$zipname = "dl" . date("YmdHis") . $fileName . ".zip";
$zipfile = WT_Site::preference('INDEX_DIRECTORY') . $zipname;
$gedname = $temppath . $fileName;
$removeTempDir = false;
if (!is_dir($temppath)) {
$res = mkdir($temppath);
if ($res !== true) {
echo "Error : Could not create temporary path!";
exit;
}
$removeTempDir = true;
}
$gedout = fopen($gedname, "w");
export_gedcom($GEDCOM, $gedout, $exportOptions);
fclose($gedout);
$comment = "Created by " . WT_WEBTREES . " " . WT_VERSION . " on " . date("r") . ".";
$archive = new PclZip($zipfile);
示例14: updateSchema
public static function updateSchema($schema_dir, $schema_name, $target_version)
{
try {
$current_version = (int) WT_Site::preference($schema_name);
} catch (PDOException $e) {
// During initial installation, this table won’t exist.
// It will only be a problem if we can’t subsequently create it.
$current_version = 0;
}
// The update scripts can set these to indicate that we need to run a
// "post update" script. It saves from having to store/maintain lots
// of separate versions at each schema version.
$need_to_delete_old_files = false;
$need_to_update_config_data = false;
$need_to_update_stored_procedures = false;
// During installation, the current version is set to a special value of
// -1 (v1.2.5 to v1.2.7) or -2 (v1.3.0 onwards). This indicates that the tables have
// been created, but that we still need to install/update configuration data
// and/or stored procedures.
switch ($current_version) {
case -1:
// Due to a bug in webtrees 1.2.5 - 1.2.7, the setup value of "-1"
// wasn't being updated.
$current_version = 12;
WT_Site::preference($schema_name, $current_version);
break;
case -2:
// Because of the above bug, we now set the version to -2 during setup.
$current_version = $target_version;
WT_Site::preference($schema_name, $current_version);
break;
}
// Update the schema, one version at a time.
while ($current_version < $target_version) {
$next_version = $current_version + 1;
require $schema_dir . 'db_schema_' . $current_version . '_' . $next_version . '.php';
// The updatescript should update the version or throw an exception
$current_version = (int) WT_Site::preference($schema_name);
if ($current_version != $next_version) {
die("Internal error while updating {$schema_name} to {$next_version}");
}
}
if ($need_to_delete_old_files) {
require $schema_dir . 'delete_old_files.php';
}
if ($need_to_update_config_data) {
require $schema_dir . 'config_data.php';
}
if ($need_to_update_stored_procedures) {
require $schema_dir . 'stored_procedures.php';
}
}
示例15: login_or_register
/**
* If the Facebook username or email is associated with an account, login to it. Otherwise, register a new account.
*
* @param object $facebookUser Facebook user
* @param string $url (optional) URL to redirect to afterwards.
*/
private function login_or_register(&$facebookUser, $url = '')
{
$REQUIRE_ADMIN_AUTH_REGISTRATION = WT_Site::getPreference('REQUIRE_ADMIN_AUTH_REGISTRATION');
if ($this->getSetting('require_verified', 1) && empty($facebookUser->verified)) {
$this->error_page(WT_I18N::translate('Only verified Facebook accounts are authorized. Please verify your account on Facebook and then try again'));
}
if (empty($facebookUser->username)) {
$facebookUser->username = $facebookUser->id;
}
$user_id = $this->get_user_id_from_facebook_username($facebookUser->username);
if (!$user_id) {
if (!isset($facebookUser->email)) {
$this->error_page(WT_I18N::translate('You must grant access to your email address via Facebook in order to use this website. Please uninstall the application on Facebook and try again.'));
}
$user = User::findByIdentifier($facebookUser->email);
if ($user) {
$user_id = $user->getUserId();
}
}
if ($user_id) {
// This is an existing user so log them in if they are approved
$login_result = $this->login($user_id);
$message = '';
switch ($login_result) {
case -1:
// not validated
$message = WT_I18N::translate('This account has not been verified. Please check your email for a verification message.');
break;
case -2:
// not approved
$message = WT_I18N::translate('This account has not been approved. Please wait for an administrator to approve it.');
break;
default:
$user = User::find($user_id);
$user->setPreference(self::user_setting_facebook_username, $this->cleanseFacebookUsername($facebookUser->username));
// redirect to the homepage/$url
header('Location: ' . WT_SCRIPT_PATH . $url);
return;
}
$this->error_page($message);
} else {
// This is a new Facebook user who may or may not already have a manual account
if (!WT_Site::getPreference('USE_REGISTRATION_MODULE')) {
$this->error_page('<p>' . WT_I18N::translate('The administrator has disabled registrations.') . '</p>');
}
// check if the username is already in use
$username = $this->cleanseFacebookUsername($facebookUser->username);
$wt_username = substr($username, 0, 32);
// Truncate the username to 32 characters to match the DB.
if (User::findByIdentifier($wt_username)) {
// fallback to email as username since we checked above that a user with the email didn't exist.
$wt_username = $facebookUser->email;
$wt_username = substr($wt_username, 0, 32);
// Truncate the username to 32 characters to match the DB.
}
// Generate a random password since the user shouldn't need it and can always reset it.
$password = md5(uniqid(rand(), TRUE));
$hashcode = md5(uniqid(rand(), true));
$preApproved = unserialize($this->getSetting('preapproved'));
// From login.php:
Log::addAuthenticationLog('User registration requested for: ' . $wt_username);
if ($user = User::create($wt_username, $facebookUser->name, $facebookUser->email, $password)) {
$verifiedByAdmin = !$REQUIRE_ADMIN_AUTH_REGISTRATION || isset($preApproved[$username]);
$user->setPreference(self::user_setting_facebook_username, $this->cleanseFacebookUsername($facebookUser->username))->setPreference('language', WT_LOCALE)->setPreference('verified', '1')->setPreference('verified_by_admin', $verifiedByAdmin ? '1' : '0')->setPreference('reg_timestamp', date('U'))->setPreference('reg_hashcode', $hashcode)->setPreference('contactmethod', 'messaging2')->setPreference('visibleonline', '1')->setPreference('editaccount', '1')->setPreference('auto_accept', '0')->setPreference('canadmin', '0')->setPreference('sessiontime', $verifiedByAdmin ? WT_TIMESTAMP : '0')->setPreference('comment', @$facebookUser->birthday . "\n " . "https://www.facebook.com/" . $this->cleanseFacebookUsername($facebookUser->username));
// Apply pre-approval settings
if (isset($preApproved[$username])) {
$userSettings = $preApproved[$username];
foreach ($userSettings as $gedcom => $userGedcomSettings) {
foreach (array('gedcomid', 'rootid', 'canedit') as $userPref) {
if (empty($userGedcomSettings[$userPref])) {
continue;
}
// Use a direct DB query instead of $tree->setUserPreference since we
// can't get a reference to the WT_Tree since it checks permissions but
// we are trying to give the permissions.
WT_DB::prepare("REPLACE INTO `##user_gedcom_setting` (user_id, gedcom_id, setting_name, setting_value) VALUES (?, ?, ?, LEFT(?, 255))")->execute(array($user->getUserId(), $gedcom, $userPref, $userGedcomSettings[$userPref]));
}
}
// Remove the pre-approval record
unset($preApproved[$username]);
$this->setSetting('preapproved', serialize($preApproved));
}
// We need jQuery below
global $controller;
$controller = new WT_Controller_Page();
$controller->setPageTitle($this->getTitle())->pageHeader();
echo '<form id="verify-form" name="verify-form" method="post" action="', WT_LOGIN_URL, '" class="ui-autocomplete-loading" style="width:16px;height:16px;padding:0">';
echo $this->hidden_input("action", "verify_hash");
echo $this->hidden_input("user_name", $wt_username);
echo $this->hidden_input("user_password", $password);
echo $this->hidden_input("user_hashcode", $hashcode);
echo WT_Filter::getCsrf();
echo '</form>';
if ($verifiedByAdmin) {
//.........这里部分代码省略.........