/** * Set the site’s configuration settings. * * @param string $setting_name * @param string|int|bool $setting_value * * @return void */ public static function setPreference($setting_name, $setting_value) { // Only need to update the database if the setting has actually changed. if (self::getPreference($setting_name) != $setting_value) { WT_DB::prepare("REPLACE INTO `##site_setting` (setting_name, setting_value) VALUES (?, LEFT(?, 255))")->execute(array($setting_name, $setting_value)); self::$setting[$setting_name] = $setting_value; Log::addConfigurationLog('Site setting "' . $setting_name . '" set to "' . $setting_value . '"'); } }
public static function preference($setting_name, $setting_value = null) { // There are lots of settings, and we need to fetch lots of them on every page // so it is quicker to fetch them all in one go. if (self::$setting === null) { self::$setting = WT_DB::prepare("SELECT SQL_CACHE setting_name, setting_value FROM `##site_setting`")->fetchAssoc(); } // If $setting_value is null, then GET the setting if ($setting_value === null) { // If parameter two is not specified, GET the setting if (!array_key_exists($setting_name, self::$setting)) { self::$setting[$setting_name] = null; } return self::$setting[$setting_name]; } else { // If parameter two is specified, then SET the setting if (self::preference($setting_name) != $setting_value) { // Audit log of changes Log::addConfigurationLog('Site setting "' . $setting_name . '" set to "' . $setting_value . '"'); } WT_DB::prepare("REPLACE INTO `##site_setting` (setting_name, setting_value) VALUES (?, LEFT(?, 255))")->execute(array($setting_name, $setting_value)); self::$setting[$setting_name] = $setting_value; } }
private static function getActiveModulesByComponent($component, $ged_id, $access_level) { $module_names = WT_DB::prepare("SELECT SQL_CACHE module_name" . " FROM `##module`" . " JOIN `##module_privacy` USING (module_name)" . " WHERE gedcom_id=? AND component=? AND status='enabled' AND access_level>=?" . " ORDER BY CASE component WHEN 'menu' THEN menu_order WHEN 'sidebar' THEN sidebar_order WHEN 'tab' THEN tab_order ELSE 0 END, module_name")->execute(array($ged_id, $component, $access_level))->fetchOneColumn(); $array = array(); foreach ($module_names as $module_name) { if (file_exists(WT_ROOT . WT_MODULES_DIR . $module_name . '/module.php')) { require_once WT_ROOT . WT_MODULES_DIR . $module_name . '/module.php'; $class = $module_name . '_WT_Module'; $array[$module_name] = new $class(); } else { // Module has been deleted from disk? Disable it. Log::addConfigurationLog("Module {$module_name} has been deleted from disk - disabling it"); WT_DB::prepare("UPDATE `##module` SET status='disabled' WHERE module_name=?")->execute(array($module_name)); } } if ($component != 'menu' && $component != 'sidebar' && $component != 'tab') { uasort($array, create_function('$x,$y', 'return WT_I18N::strcasecmp((string)$x, (string)$y);')); } return $array; }
private function config() { require WT_ROOT . 'includes/functions/functions_edit.php'; $action = WT_Filter::post('action'); $controller = new WT_Controller_Page(); $controller->restrictAccess(Auth::isAdmin())->setPageTitle(WT_I18N::translate('Google Maps™'))->pageHeader()->addInlineJavascript('jQuery("#tabs").tabs();'); if ($action == 'update') { $this->setSetting('GM_MAP_TYPE', WT_Filter::post('NEW_GM_MAP_TYPE')); $this->setSetting('GM_USE_STREETVIEW', WT_Filter::post('NEW_GM_USE_STREETVIEW')); $this->setSetting('GM_MIN_ZOOM', WT_Filter::post('NEW_GM_MIN_ZOOM')); $this->setSetting('GM_MAX_ZOOM', WT_Filter::post('NEW_GM_MAX_ZOOM')); $this->setSetting('GM_XSIZE', WT_Filter::post('NEW_GM_XSIZE')); $this->setSetting('GM_YSIZE', WT_Filter::post('NEW_GM_YSIZE')); $this->setSetting('GM_PRECISION_0', WT_Filter::post('NEW_GM_PRECISION_0')); $this->setSetting('GM_PRECISION_1', WT_Filter::post('NEW_GM_PRECISION_1')); $this->setSetting('GM_PRECISION_2', WT_Filter::post('NEW_GM_PRECISION_2')); $this->setSetting('GM_PRECISION_3', WT_Filter::post('NEW_GM_PRECISION_3')); $this->setSetting('GM_PRECISION_4', WT_Filter::post('NEW_GM_PRECISION_4')); $this->setSetting('GM_PRECISION_5', WT_Filter::post('NEW_GM_PRECISION_5')); $this->setSetting('GM_COORD', WT_Filter::post('NEW_GM_COORD')); $this->setSetting('GM_PLACE_HIERARCHY', WT_Filter::post('NEW_GM_PLACE_HIERARCHY')); $this->setSetting('GM_PH_XSIZE', WT_Filter::post('NEW_GM_PH_XSIZE')); $this->setSetting('GM_PH_YSIZE', WT_Filter::post('NEW_GM_PH_YSIZE')); $this->setSetting('GM_PH_MARKER', WT_Filter::post('NEW_GM_PH_MARKER')); $this->setSetting('GM_DISP_SHORT_PLACE', WT_Filter::post('NEW_GM_DISP_SHORT_PLACE')); for ($i = 1; $i <= 9; $i++) { $this->setSetting('GM_PREFIX_' . $i, WT_Filter::post('NEW_GM_PREFIX_' . $i)); $this->setSetting('GM_POSTFIX_' . $i, WT_Filter::post('NEW_GM_POSTFIX_' . $i)); } Log::addConfigurationLog('Googlemap config updated'); } ?> <table id="gm_config"> <tr> <th> <a class="current" href="module.php?mod=googlemap&mod_action=admin_config"> <?php echo WT_I18N::translate('Google Maps™ preferences'); ?> </a> </th> <th> <a href="module.php?mod=googlemap&mod_action=admin_places"> <?php echo WT_I18N::translate('Geographic data'); ?> </a> </th> <th> <a href="module.php?mod=googlemap&mod_action=admin_placecheck"> <?php echo WT_I18N::translate('Place check'); ?> </a> </th> </tr> </table> <form method="post" name="configform" action="module.php?mod=googlemap&mod_action=admin_config"> <input type="hidden" name="action" value="update"> <div id="tabs"> <ul> <li><a href="#gm_basic"><span><?php echo WT_I18N::translate('Basic'); ?> </span></a></li> <li><a href="#gm_advanced"><span><?php echo WT_I18N::translate('Advanced'); ?> </span></a></li> <li><a href="#gm_ph"><span><?php echo WT_I18N::translate('Place hierarchy'); ?> </span></a></li> </ul> <div id="gm_basic"> <table class="gm_edit_config"> <tr> <th><?php echo WT_I18N::translate('Default map type'); ?> </th> <td> <select name="NEW_GM_MAP_TYPE"> <option value="ROADMAP" <?php if ($this->getSetting('GM_MAP_TYPE') == 'ROADMAP') { echo "selected=\"selected\""; } ?> ><?php echo WT_I18N::translate('Map'); ?> </option> <option value="SATELLITE" <?php if ($this->getSetting('GM_MAP_TYPE') == 'SATELLITE') { echo "selected=\"selected\""; } ?> ><?php echo WT_I18N::translate('Satellite'); ?> </option> <option value="HYBRID" <?php if ($this->getSetting('GM_MAP_TYPE') == 'HYBRID') { echo "selected=\"selected\""; } ?> ><?php echo WT_I18N::translate('Hybrid'); ?> </option> <option value="TERRAIN" <?php if ($this->getSetting('GM_MAP_TYPE') == 'TERRAIN') { echo "selected=\"selected\""; } ?> ><?php echo WT_I18N::translate('Terrain'); ?> </option> </select> </td> </tr> <tr> <th><?php echo WT_I18N::translate('Google Street View™'); ?> </th> <td><?php echo radio_buttons('NEW_GM_USE_STREETVIEW', array(false => WT_I18N::translate('hide'), true => WT_I18N::translate('show')), $this->getSetting('GM_USE_STREETVIEW')); ?> </td> </tr> <tr> <th><?php echo WT_I18N::translate('Size of map (in pixels)'); ?> </th> <td> <?php echo WT_I18N::translate('Width'); ?> <input type="text" name="NEW_GM_XSIZE" value="<?php echo $this->getSetting('GM_XSIZE'); ?> " size="10"> <?php echo WT_I18N::translate('Height'); ?> <input type="text" name="NEW_GM_YSIZE" value="<?php echo $this->getSetting('GM_YSIZE'); ?> " size="10"> </td> </tr> <tr> <th><?php echo WT_I18N::translate('Zoom level of map'), help_link('GM_MAP_ZOOM', 'googlemap'); ?> </th> <td> <?php echo WT_I18N::translate('minimum'); ?> : <select name="NEW_GM_MIN_ZOOM"> <?php for ($j = 1; $j < 15; $j++) { ?> <option value="<?php echo $j, "\""; if ($this->getSetting('GM_MIN_ZOOM') == $j) { echo " selected=\"selected\""; } echo ">", $j; ?> </option> <?php } ?> </select> <?php echo WT_I18N::translate('maximum'); ?> : <select name="NEW_GM_MAX_ZOOM"> <?php for ($j = 1; $j < 21; $j++) { ?> <option value="<?php echo $j, "\""; if ($this->getSetting('GM_MAX_ZOOM') == $j) { echo " selected=\"selected\""; } echo ">", $j; ?> </option> <?php } ?> </select> </td> </tr> </table> </div> <div id="gm_advanced"> <table class="gm_edit_config"> <tr> <th colspan="2"><?php echo WT_I18N::translate('Precision of the latitude and longitude'), help_link('GM_PRECISION', 'googlemap'); ?> </th> <td> <table> <tr> <td><?php echo WT_I18N::translate('Country'); ?> </td> <td><select name="NEW_GM_PRECISION_0"> <?php for ($j = 0; $j < 10; $j++) { ?> <option value="<?php echo $j; ?> "<?php if ($this->getSetting('GM_PRECISION_0') == $j) { echo " selected=\"selected\""; } echo ">", $j; ?> </option> <?php } ?> </select> <?php echo WT_I18N::translate('digits'); ?> </td> </tr> <tr> <td><?php echo WT_I18N::translate('State'); ?> </td> <td><select name="NEW_GM_PRECISION_1"> <?php for ($j = 0; $j < 10; $j++) { ?> <option value="<?php echo $j; ?> "<?php if ($this->getSetting('GM_PRECISION_1') == $j) { echo " selected=\"selected\""; } echo ">", $j; ?> </option> <?php } ?> </select> <?php echo WT_I18N::translate('digits'); ?> </td> </tr> <tr> <td><?php echo WT_I18N::translate('City'); ?> </td> <td><select name="NEW_GM_PRECISION_2"> <?php for ($j = 0; $j < 10; $j++) { ?> <option value="<?php echo $j; ?> "<?php if ($this->getSetting('GM_PRECISION_2') == $j) { echo " selected=\"selected\""; } echo ">", $j; ?> </option> <?php } ?> </select> <?php echo WT_I18N::translate('digits'); ?> </td> </tr> <tr><td><?php echo WT_I18N::translate('Neighborhood'); ?> </td> <td><select name="NEW_GM_PRECISION_3"> <?php for ($j = 0; $j < 10; $j++) { ?> <option value="<?php echo $j; ?> "<?php if ($this->getSetting('GM_PRECISION_3') == $j) { echo " selected=\"selected\""; } echo ">", $j; ?> </option> <?php } ?> </select> <?php echo WT_I18N::translate('digits'); ?> </td> </tr> <tr><td><?php echo WT_I18N::translate('House'); ?> </td> <td><select name="NEW_GM_PRECISION_4"> <?php for ($j = 0; $j < 10; $j++) { ?> <option value="<?php echo $j; ?> "<?php if ($this->getSetting('GM_PRECISION_4') == $j) { echo " selected=\"selected\""; } echo ">", $j; ?> </option> <?php } ?> </select> <?php echo WT_I18N::translate('digits'); ?> </td> </tr> <tr><td><?php echo WT_I18N::translate('Max'); ?> </td> <td><select name="NEW_GM_PRECISION_5"> <?php for ($j = 0; $j < 10; $j++) { ?> <option value="<?php echo $j; ?> "<?php if ($this->getSetting('GM_PRECISION_5') == $j) { echo " selected=\"selected\""; } echo ">", $j; ?> </option> <?php } ?> </select> <?php echo WT_I18N::translate('digits'); ?> </td> </tr> </table> </td> <td> </td> </tr> <th class="gm_prefix" colspan="3"><?php echo WT_I18N::translate('Optional prefixes and suffixes'), help_link('GM_NAME_PREFIX_SUFFIX', 'googlemap'); ?> </th> </tr> <tr id="gm_level_titles"> <th> </th> <th><?php echo WT_I18N::translate('Prefixes'); ?> </th> <th><?php echo WT_I18N::translate('Suffixes'); ?> </th> <?php for ($level = 1; $level < 10; $level++) { ?> <tr class="gm_levels"> <th> <?php if ($level == 1) { echo WT_I18N::translate('Country'); } else { echo WT_I18N::translate('Level'), " ", $level; } ?> </th> <td><input type="text" size="30" name="NEW_GM_PREFIX_<?php echo $level; ?> " value="<?php echo $this->getSetting('GM_PREFIX_' . $level); ?> "></td> <td><input type="text" size="30" name="NEW_GM_POSTFIX_<?php echo $level; ?> " value="<?php echo $this->getSetting('GM_POSTFIX_' . $level); ?> "></td> </tr> <?php } ?> </table> </div> <div id="gm_ph"> <table class="gm_edit_config"> <tr> <th><?php echo WT_I18N::translate('Use Google Maps™ for the place hierarchy'); ?> </th> <td><?php echo edit_field_yes_no('NEW_GM_PLACE_HIERARCHY', $this->getSetting('GM_PLACE_HIERARCHY')); ?> </td> </tr> <tr> <th><?php echo WT_I18N::translate('Size of map (in pixels)'); ?> </th> <td> <?php echo WT_I18N::translate('Width'); ?> <input type="text" name="NEW_GM_PH_XSIZE" value="<?php echo $this->getSetting('GM_PH_XSIZE'); ?> " size="10"> <?php echo WT_I18N::translate('Height'); ?> <input type="text" name="NEW_GM_PH_YSIZE" value="<?php echo $this->getSetting('GM_PH_YSIZE'); ?> " size="10"> </td> </tr> <tr> <th><?php echo WT_I18N::translate('Type of place markers in Place Hierarchy'); ?> </th> <td> <select name="NEW_GM_PH_MARKER"> <option value="G_DEFAULT_ICON" <?php if ($this->getSetting('GM_PH_MARKER') == "G_DEFAULT_ICON") { echo "selected=\"selected\""; } ?> ><?php echo WT_I18N::translate('Standard'); ?> </option> <option value="G_FLAG" <?php if ($this->getSetting('GM_PH_MARKER') == "G_FLAG") { echo "selected=\"selected\""; } ?> ><?php echo WT_I18N::translate('Flag'); ?> </option> </select> </td> </tr> <tr> <th><?php echo WT_I18N::translate('Display short placenames'), help_link('GM_DISP_SHORT_PLACE', 'googlemap'); ?> </th> <td><?php echo edit_field_yes_no('NEW_GM_DISP_SHORT_PLACE', $this->getSetting('GM_DISP_SHORT_PLACE')); ?> </td> </tr> <tr> <th><?php echo WT_I18N::translate('Display map coordinates'), help_link('GM_COORD', 'googlemap'); ?> </th> <td><?php echo edit_field_yes_no('NEW_GM_COORD', $this->getSetting('GM_COORD')); ?> </td> </tr> </table> </div> </div> <p> <input type="submit" value="<?php echo WT_I18N::translate('save'); ?> "> </p> </form> <?php }
public function userPreference($user_id, $setting_name, $setting_value = null) { // There are lots of settings, and we need to fetch lots of them on every page // so it is quicker to fetch them all in one go. if (!array_key_exists($user_id, $this->user_preference)) { $this->user_preference[$user_id] = WT_DB::prepare("SELECT SQL_CACHE setting_name, setting_value FROM `##user_gedcom_setting` WHERE user_id=? AND gedcom_id=?")->execute(array($user_id, $this->tree_id))->fetchAssoc(); } // If $setting_value is null, then GET the setting if ($setting_value === null) { // If parameter two is not specified, GET the setting if (!array_key_exists($setting_name, $this->user_preference[$user_id])) { $this->user_preference[$user_id][$setting_name] = null; } return $this->user_preference[$user_id][$setting_name]; } else { // If parameter two is specified, then SET the setting. if ($this->preference($setting_name) != $setting_value) { // Audit log of changes Log::addConfigurationLog('Gedcom setting "' . $setting_name . '" set to "' . $setting_value . '"'); } WT_DB::prepare("REPLACE INTO `##user_gedcom_setting` (user_id, gedcom_id, setting_name, setting_value) VALUES (?, ?, ?, LEFT(?, 255))")->execute(array($user_id, $this->tree_id, $setting_name, $setting_value)); return $this; } }
private function admin() { $mod_name = $this->getName(); $preApproved = unserialize($this->getSetting('preapproved')); if (WT_Filter::post('saveAPI') && WT_Filter::checkCsrf()) { $this->setSetting('app_id', WT_Filter::post('app_id', WT_REGEX_ALPHANUM)); $this->setSetting('app_secret', WT_Filter::post('app_secret', WT_REGEX_ALPHANUM)); $this->setSetting('require_verified', WT_Filter::post('require_verified', WT_REGEX_INTEGER, false)); $this->setSetting('hide_standard_forms', WT_Filter::post('hide_standard_forms', WT_REGEX_INTEGER, false)); Log::addConfigurationLog("Facebook: API settings changed"); WT_FlashMessages::addMessage(WT_I18N::translate('Settings saved')); } else { if (WT_Filter::post('addLink') && WT_Filter::checkCsrf()) { $user_id = WT_Filter::post('user_id', WT_REGEX_INTEGER); $facebook_username = $this->cleanseFacebookUsername(WT_Filter::post('facebook_username', WT_REGEX_USERNAME)); if ($user_id && $facebook_username && !$this->get_user_id_from_facebook_username($facebook_username)) { $user = User::find($user_id); $user->setPreference(self::user_setting_facebook_username, $facebook_username); if (isset($preApproved[$facebook_username])) { // Delete a pre-approval for the Facebook username. unset($preApproved[$facebook_username]); $this->setSetting('preapproved', serialize($preApproved)); } Log::addConfigurationLog("Facebook: User {$user_id} linked to Facebook user {$facebook_username}"); WT_FlashMessages::addMessage(WT_I18N::translate('User %1$s linked to Facebook user %2$s', $user_id, $facebook_username)); } else { WT_FlashMessages::addMessage(WT_I18N::translate('The user could not be linked')); } } else { if (WT_Filter::post('deleteLink') && WT_Filter::checkCsrf()) { $user_id = WT_Filter::post('deleteLink', WT_REGEX_INTEGER); if ($user_id) { $user = User::find($user_id); $user->deletePreference(self::user_setting_facebook_username); Log::addConfigurationLog("Facebook: User {$user_id} unlinked from a Facebook user"); WT_FlashMessages::addMessage(WT_I18N::translate('User unlinked')); } else { WT_FlashMessages::addMessage(WT_I18N::translate('The link could not be deleted')); } } else { if (WT_Filter::post('savePreapproved') && WT_Filter::checkCsrf()) { $table = WT_Filter::post('preApproved'); if ($facebook_username = $this->cleanseFacebookUsername(WT_Filter::post('preApproved_new_facebook_username', WT_REGEX_USERNAME))) { // Process additions $row = $table['new']; $this->appendPreapproved($preApproved, $facebook_username, $row); $this->setSetting('preapproved', serialize($preApproved)); Log::addConfigurationLog("Facebook: Pre-approved Facebook user: {$facebook_username}"); WT_FlashMessages::addMessage(WT_I18N::translate('Pre-approved user "%s" added', $facebook_username)); } unset($table['new']); // Process changes foreach ($table as $facebook_username => $row) { $this->appendPreapproved($preApproved, $facebook_username, $row); } $this->setSetting('preapproved', serialize($preApproved)); Log::addConfigurationLog("Facebook: Pre-approved Facebook users changed"); WT_FlashMessages::addMessage(WT_I18N::translate('Changes to pre-approved users saved')); } else { if (WT_Filter::post('deletePreapproved') && WT_Filter::checkCsrf()) { $facebook_username = trim(WT_Filter::post('deletePreapproved', WT_REGEX_USERNAME)); if ($facebook_username && isset($preApproved[$facebook_username])) { unset($preApproved[$facebook_username]); $this->setSetting('preapproved', serialize($preApproved)); Log::addConfigurationLog("Facebook: Pre-approved Facebook user deleted: {$facebook_username}"); WT_FlashMessages::addMessage(WT_I18N::translate('Pre-approved user "%s" deleted', $facebook_username)); } else { WT_FlashMessages::addMessage(WT_I18N::translate('The pre-approved user "%s" could not be deleted', $facebook_username)); } } } } } } $controller = new WT_Controller_Page(); $controller->restrictAccess(\WT\Auth::isAdmin())->setPageTitle($this->getTitle())->pageHeader(); $linkedUsers = array(); $unlinkedUsers = array(); $users = $this->get_users_with_module_settings(); foreach ($users as $userid => $user) { if (empty($user[0]->facebook_username)) { $unlinkedUsers[$userid] = $user[0]; } else { $linkedUsers[$userid] = $user[0]; } } $unlinkedOptions = $this->user_options($unlinkedUsers); require_once WT_ROOT . 'includes/functions/functions_edit.php'; require 'templates/admin.php'; }