Skip to content

Commit

Permalink
Dev Fixed PHP compatibility issues
Browse files Browse the repository at this point in the history
  • Loading branch information
c-schmitz committed May 10, 2021
2 parents 294ae97 + fdd6435 commit d132a02
Show file tree
Hide file tree
Showing 707 changed files with 16,763 additions and 12,503 deletions.
1 change: 0 additions & 1 deletion .gitignore
Expand Up @@ -115,7 +115,6 @@ third_party/bin/phpcbf
third_party/bin/phpcs
third_party/squizlabs/**/*
third_party/facebook/**/*
third_party/symfony/**/*
third_party/composer/installed\.json


Expand Down
2 changes: 1 addition & 1 deletion .scrutinizer.yml
Expand Up @@ -45,7 +45,7 @@ tools:
php_cs_fixer:
enabled: true
config:
level: psr2
level: psr12
lowercase_keywords: false
filter:
excluded_paths:
Expand Down
5 changes: 3 additions & 2 deletions .travis.yml
Expand Up @@ -42,11 +42,12 @@ before_script:
- chmod -R 777 upload
- chmod -R 777 themes # Need 777 so both console and web server can cd into the folder.
- chmod -R 777 tests/tmp
- chmod +x tests/bin/lint-*
- php application/commands/console.php install admin password TravisLS no@email.com verbose
- cp application/config/config-sample-mysql.php application/config/config.php
# Enable debug=2 in config file. OBS: This assumes debug is on line 61.
# TODO: Disable, a lines was added to config file and some tests started to fail.
# - sed -i '61s/.*/ "debug"=>2,/' application/config/config.php
- sed -i '61s/.*/ "debug"=>2,/' application/config/config.php

# Install Apache.
# Code fetched from https://docs.travis-ci.com/user/languages/php/#Apache-%2B-PHP
Expand Down Expand Up @@ -85,6 +86,6 @@ before_script:

script:
# Run tests.
- DOMAIN=localhost ./third_party/bin/phpunit
- DOMAIN=localhost ./third_party/bin/phpunit --testdox --stop-on-failure


9 changes: 0 additions & 9 deletions application/config/internal.php
Expand Up @@ -51,15 +51,6 @@
// yiiwheels configuration
'yiiwheels' => realpath(__DIR__.'/../extensions/yiiwheels'),
'vendor.twbs.bootstrap.dist',

// Twig aliases. We don't want to change the file ETwigViewRenderer, so we can update it without difficulties
// However, LimeSurvey directory tree is not a standard Yii Application tree.
// we use 'third_party' instead of 'vendor'
// This line just point application.vendor.Twig to application/third_party/Twig
// @see: ETwigViewRenderer::$twigPathAlias
'application.vendor.Twig'=>'application.third_party.Twig',
// 'CaptchaExtendedAction' => realpath(__DIR__ . '/../extensions/captchaExtended/CaptchaExtendedAction.php'),
// 'CaptchaExtendedValidator' => realpath(__DIR__ . '/../extensions/captchaExtended/CaptchaExtendedValidator.php')
),

'modules'=>array(
Expand Down
40 changes: 22 additions & 18 deletions application/controllers/InstallerController.php
Expand Up @@ -718,18 +718,19 @@ public function is_writable_recursive($sDirectory)
}

/**
* check for a specific PHPFunction, return HTML image
* Check for a specific PHP Function or class, updates HTML image
*
* @param string $sFunctionName
* @param string $sImage return
* @return bool result
* @param string $sFunctionName Function or class name
* @param string $sImage HTML string for related image to show
* @return bool True if exists, otherwise false
*/
public function checkPHPFunction($sFunctionName, &$sImage)
public function checkPHPFunctionOrClass($sFunctionName, &$sImage)
{
$bExists = function_exists($sFunctionName);
$bExists = function_exists($sFunctionName) || class_exists($sFunctionName);
$sImage = $this->check_HTML_image($bExists);
return $bExists;
}


/**
* check if file or directory exists and is writeable, returns via parameters by reference
Expand Down Expand Up @@ -808,29 +809,32 @@ private function _check_requirements(&$aData)
// proceed variable check if all requirements are true. If any of them is false, proceed is set false.
$bProceed = true; //lets be optimistic!


// version check
// version check for minimum
if (version_compare(PHP_VERSION, '5.5.9', '<')) {
$bProceed = !$aData['verror'] = true;
$bProceed = !$aData['versions_status'] = 'error';
}

// version check for maximum version
if (version_compare(PHP_VERSION, '8.0', '>=')) {
$aData['versions_status'] = 'warning';
}

if (convertPHPSizeToBytes(ini_get('memory_limit')) / 1024 / 1024 < 128 && ini_get('memory_limit') != -1) {
$bProceed = !$aData['bMemoryError'] = true;
}


// mbstring library check
if (!$this->checkPHPFunction('mb_convert_encoding', $aData['mbstringPresent'])) {
if (!$this->checkPHPFunctionOrClass('mb_convert_encoding', $aData['mbstringPresent'])) {
$bProceed = false;
}

// zlib library check
if (!$this->checkPHPFunction('zlib_get_coding_type', $aData['zlibPresent'])) {
if (!$this->checkPHPFunctionOrClass('zlib_get_coding_type', $aData['zlibPresent'])) {
$bProceed = false;
}

// JSON library check
if (!$this->checkPHPFunction('json_encode', $aData['bJSONPresent'])) {
if (!$this->checkPHPFunctionOrClass('json_encode', $aData['bJSONPresent'])) {
$bProceed = false;
}

Expand Down Expand Up @@ -871,18 +875,18 @@ private function _check_requirements(&$aData)
$aData['gdPresent'] = $this->check_HTML_image(false);
}
// ldap library check
$this->checkPHPFunction('ldap_connect', $aData['ldapPresent']);
$this->checkPHPFunctionOrClass('ldap_connect', $aData['ldapPresent']);

// php zip library check
$this->checkPHPFunction('zip_open', $aData['zipPresent']);
$this->checkPHPFunctionOrClass('ZipArchive', $aData['zipPresent']);

// zlib php library check
$this->checkPHPFunction('zlib_get_coding_type', $aData['zlibPresent']);
$this->checkPHPFunctionOrClass('zlib_get_coding_type', $aData['zlibPresent']);

// imap php library check
$this->checkPHPFunction('imap_open', $aData['bIMAPPresent']);
$this->checkPHPFunctionOrClass('imap_open', $aData['bIMAPPresent']);

// Silently check some default PHP extensions
// Silently check some default PHP extensions
$this->checkDefaultExtensions();

return $bProceed;
Expand Down
2 changes: 1 addition & 1 deletion application/controllers/RegisterController.php
Expand Up @@ -496,7 +496,7 @@ public function getStartDate($iSurveyId)
* @param $iSurveyId
* @param string $registerContent
*/
private function display($iSurveyId, $iTokenId = null, $registerContent)
private function display($iSurveyId, $iTokenId, $registerContent)
{
$sLanguage = Yii::app()->language;
$this->aGlobalData['surveyid'] = $surveyid = $iSurveyId;
Expand Down
2 changes: 1 addition & 1 deletion application/controllers/admin/questions.php
Expand Up @@ -138,7 +138,7 @@ public function view($surveyid, $gid, $qid)
/**
* Display import view
*/
public function importView($groupid = null, $surveyid)
public function importView($groupid , $surveyid)
{
$iSurveyID = (int) $surveyid;
if (!Permission::model()->hasSurveyPermission($iSurveyID, 'surveycontent', 'import')) {
Expand Down
27 changes: 13 additions & 14 deletions application/controllers/admin/surveyadmin.php
Expand Up @@ -1808,10 +1808,10 @@ private function _pluginTabSurvey($survey)
/**
* survey::_tabPresentationNavigation()
* Load "Presentation & navigation" tab.
* @param mixed $esrow
* @param mixed $survey
* @return array
*/
private function _tabPresentationNavigation($esrow)
private function _tabPresentationNavigation($survey)
{
global $showxquestions, $showgroupinfo, $showqnumcode;

Expand All @@ -1820,7 +1820,7 @@ private function _tabPresentationNavigation($esrow)
$shownoanswer = getGlobalSetting('shownoanswer') ? getGlobalSetting('shownoanswer') : 'Y';

$aData = [];
$aData['esrow'] = $esrow;
$aData['esrow'] = $survey;
$aData['shownoanswer'] = $shownoanswer;
$aData['showxquestions'] = $showxquestions;
$aData['showgroupinfo'] = $showgroupinfo;
Expand All @@ -1846,26 +1846,26 @@ private function _tabPublicationAccess($survey)
/**
* survey::_tabNotificationDataManagement()
* Load "Notification & data management" tab.
* @param mixed $esrow
* @param mixed $survey
* @return array
*/
private function _tabNotificationDataManagement($esrow)
private function _tabNotificationDataManagement($survey)
{
$aData = [];
$aData['esrow'] = $esrow;
$aData['esrow'] = $survey;
return $aData;
}

/**
* survey::_tabTokens()
* Load "Tokens" tab.
* @param mixed $esrow
* @param mixed $survey
* @return array
*/
private function _tabTokens($esrow)
private function _tabTokens($survey)
{
$aData = [];
$aData['esrow'] = $esrow;
$aData['esrow'] = $survey;
return $aData;
}

Expand Down Expand Up @@ -1915,21 +1915,20 @@ private function _tabPanelIntegration($survey, $sLang = null)
/**
* survey::_tabResourceManagement()
* Load "Resources" tab.
* @param Survey $survey survey
* @param Survey $survey survey
* @return mixed
*/
private function _tabResourceManagement($oSurvey)
private function _tabResourceManagement($survey)
{
global $sCKEditorURL;

// TAB Uploaded Resources Management
$ZIPimportAction = " onclick='if (window.LS.validatefilename(this.form,\"".gT('Please select a file to import!', 'js')."\")) { this.form.submit();}'";
if (!function_exists("zip_open")) {
$ZIPimportAction = " onclick='alert(\"".gT("The ZIP library is not activated in your PHP configuration thus importing ZIP files is currently disabled.", "js")."\");'";
}

$disabledIfNoResources = '';
if (hasResources($oSurvey->sid, 'survey') === false) {
if (hasResources($survey->sid, 'survey') === false) {
$disabledIfNoResources = " disabled='disabled'";
}
$aData = [];
Expand All @@ -1939,7 +1938,7 @@ private function _tabResourceManagement($oSurvey)
$aData['noform'] = true;

//KCFINDER SETTINGS
Yii::app()->session['FileManagerContext'] = "edit:survey:{$oSurvey->sid}";
Yii::app()->session['FileManagerContext'] = "edit:survey:{$survey->sid}";
Yii::app()->loadHelper('admin.htmleditor');
initKcfinder();

Expand Down
2 changes: 1 addition & 1 deletion application/controllers/admin/themeoptions.php
Expand Up @@ -152,7 +152,7 @@ public function updatesurvey($sid)
* If update is successful, the browser will be redirected to the 'view' page.
* @param integer $id the ID of the model to be updated
*/
public function updatesurveygroup($id = null, $gsid, $l = null)
public function updatesurveygroup($id, $gsid, $l = null)
{
if (Permission::model()->hasGlobalPermission('templates', 'update')) {
// @todo : review permission : template permission or group permission ?
Expand Down
15 changes: 7 additions & 8 deletions application/core/web/LSYii_SecurityManager.php
Expand Up @@ -122,17 +122,16 @@ public function isZipBomb($zip_filename)
public function get_zip_originalsize($filename)
{

if ( function_exists ('zip_entry_filesize') ){
if (class_exists('ZipArchive')) {
$size = 0;
$resource = zip_open($filename);
$zip = new ZipArchive;
$zip->open($filename);

if ( ! is_int($resource) ) {
while ($dir_resource = zip_read($resource)) {
$size += zip_entry_filesize($dir_resource);
}
zip_close($resource);
for ($i = 0; $i < $zip->numFiles; $i++) {
$aEntry = $zip->statIndex($i);
$size += $aEntry['size'];
}

$zip->close();
return $size;
}else{
if ( YII_DEBUG ){
Expand Down
2 changes: 1 addition & 1 deletion application/helpers/admin/statistics_helper.php
Expand Up @@ -26,7 +26,7 @@
* @param string $sQuestionType The question type
* @return false|string
*/
function createChart($iQuestionID, $iSurveyID, $type = null, $lbl, $gdata, $grawdata, $cache, $sLanguageCode, $sQuestionType)
function createChart($iQuestionID, $iSurveyID, $type, $lbl, $gdata, $grawdata, $cache, $sLanguageCode, $sQuestionType)
{
/* This is a lazy solution to bug #6389. A better solution would be to find out how
the "T" gets passed to this function from the statistics.js file in the first place! */
Expand Down
28 changes: 15 additions & 13 deletions application/helpers/common_helper.php
Expand Up @@ -3433,7 +3433,9 @@ function includeKeypad()
*/
function translateInsertansTags($newsid, $oldsid, $fieldnames)
{
uksort($fieldnames, function($a, $b) {return strlen($a) < strlen($b); });
uksort($fieldnames, function ($a, $b) {
return strlen($b)-strlen($a);
});

Yii::app()->loadHelper('database');
$newsid = (int) $newsid;
Expand Down Expand Up @@ -4461,7 +4463,7 @@ function doFooter()
* @param int $surveyid
* @return string
*/
function getSurveyUserList($bIncludeSuperAdmins = true, $surveyid)
function getSurveyUserList($bIncludeSuperAdmins, $surveyid)
{

$surveyid = (int) $surveyid;
Expand Down Expand Up @@ -4505,11 +4507,11 @@ function getSurveyUserList($bIncludeSuperAdmins = true, $surveyid)

/**
* Return HTML <option> list of user groups
* @param string $outputformat
* @param string $outputformat 'htmloptions' or 'simpleugidarray' (todo: check if this is correct)
* @param int $surveyid
* @return string|array
*/
function getSurveyUserGroupList($outputformat = 'htmloptions', $surveyid)
function getSurveyUserGroupList($outputformat, $surveyid)
{

$surveyid = sanitize_int($surveyid);
Expand Down Expand Up @@ -5032,19 +5034,19 @@ function isZipBomb($zip_filename)
* @param string $filename
* @return int
*/
function get_zip_originalsize($filename) {
function get_zip_originalsize($filename)
{

if ( function_exists ('zip_entry_filesize') ){
if (class_exists('ZipArchive')) {
$size = 0;
$resource = zip_open($filename);
$zip = new ZipArchive;
$zip->open($filename);

if ( ! is_int($resource) ) {
while ($dir_resource = zip_read($resource)) {
$size += zip_entry_filesize($dir_resource);
}
zip_close($resource);
for ($i = 0; $i < $zip->numFiles; $i++) {
$aEntry = $zip->statIndex($i);
$size += $aEntry['size'];
}

$zip->close();
return $size;
}else{
if ( YII_DEBUG ){
Expand Down
2 changes: 1 addition & 1 deletion application/helpers/export_helper.php
Expand Up @@ -261,7 +261,7 @@ function SPSSExportData($iSurveyID, $iLength, $na = '', $q = '\'', $header = fal
* @param string $language
* @return array|bool
*/
function SPSSGetValues($field = array(), $qidattributes = null, $language)
function SPSSGetValues($field, $qidattributes, $language)
{
$language = sanitize_languagecode($language);

Expand Down
9 changes: 4 additions & 5 deletions application/helpers/frontend_helper.php
Expand Up @@ -760,9 +760,8 @@ function buildsurveysession($surveyid, $preview = false)
// NOTE: All of this is already done in survey controller.
// We keep it here only for Travis Tested thar are still not using Selenium
// As soon as the tests are rewrote to use selenium, those lines can be removed
$lang = $_SESSION['survey_'.$surveyid]['s_lang'];
if (empty($lang)){

$lang = isset($_SESSION['survey_' . $surveyid]['s_lang']) ? $_SESSION['survey_' . $surveyid]['s_lang'] : '';
if (empty($lang)) {
// Multi lingual support order : by REQUEST, if not by Token->language else by survey default language

if (returnGlobal('lang', true)) {
Expand Down Expand Up @@ -1424,15 +1423,15 @@ function breakOutAndCrash($sTemplateViewPath, $totalquestions, $iTotalGroupsWith
/**
* @param string $sTemplateViewPath
*/
function renderError($sTitle = '', $sMessage, $thissurvey, $sTemplateViewPath)
function renderError($sTitle, $sMessage, $thissurvey, $sTemplateViewPath)
{
// Template settings
$surveyid = $thissurvey['sid'];
//$oTemplate = Template::model()->getInstance('', $surveyid);
//$oTemplate->registerAssets();

$aError = array();
$aError['title'] = ($sTitle != '') ? $sTitle : gT("This survey cannot be tested or completed for the following reason(s):");
$aError['title'] = (!empty(trim($sTitle))) ? $sTitle : gT("This survey cannot be tested or completed for the following reason(s):");
$aError['message'] = $sMessage;
$thissurvey['aError'] = $aError;

Expand Down

0 comments on commit d132a02

Please sign in to comment.