From c54bb2303d23695906eff6616b5962c8740ce3c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20=C3=96sterreicher?= Date: Mon, 15 Jan 2018 18:00:41 +0100 Subject: [PATCH] Fixed some PHP 5.3 incompatible Codeparts --- application/libraries/DocumentLib.php | 11 +++- application/libraries/ExtensionsLib.php | 52 ++++++++++--------- application/libraries/LogLib.php | 26 +++++----- application/libraries/REST_Controller.php | 21 ++++---- .../models/system/MessageToken_model.php | 21 ++++---- 5 files changed, 73 insertions(+), 58 deletions(-) diff --git a/application/libraries/DocumentLib.php b/application/libraries/DocumentLib.php index ba76eca6c..204b1d30f 100644 --- a/application/libraries/DocumentLib.php +++ b/application/libraries/DocumentLib.php @@ -15,8 +15,17 @@ class DocumentLib $this->ci =& get_instance(); exec('unoconv --version', $ret_arr); + if(isset($ret_arr[0])) - $this->unoconv_version = explode(' ', $ret_arr[0])[1]; + { + $hlp = explode(' ', $ret_arr[0]); + if(isset($hlp[1])) + { + $this->unoconv_version = $hlp[1]; + } + else + show_error('Could not get Unoconv Version'); + } else show_error('Unoconv not found - Please install Unoconv'); } diff --git a/application/libraries/ExtensionsLib.php b/application/libraries/ExtensionsLib.php index 0008ba087..25e9c666a 100644 --- a/application/libraries/ExtensionsLib.php +++ b/application/libraries/ExtensionsLib.php @@ -11,16 +11,16 @@ class ExtensionsLib const SQL_FILE_EXTENSION = '.sql'; // SQL scripts file extension const FILE_INPUT_NAME = 'extension'; // name of the HTTP parameter containing the archive data - const ARCHIVE_EXTENSIONS = array('.tgz', '.tbz2'); // accepted file extensions for an uploaded extension const EXTENSION_JSON_NAME = 'extension.json'; // file that contains extension data - - const UPLOAD_PATH = APPPATH.'tmp/'; // temporary directory to store the upload file and checks the archive - const EXTENSIONS_PATH = APPPATH.'extensions/'; // directory where all the extensions are const EXTENSIONS_DIR_NAME = 'extensions'; // name of the directories where will be created the symlinks + private $ARCHIVE_EXTENSIONS = array('.tgz', '.tbz2'); // accepted file extensions for an uploaded extension + private $UPLOAD_PATH; // temporary directory to store the upload file and checks the archive + private $EXTENSIONS_PATH; // directory where all the extensions are + // Directories that are part of the extension archive - const SOFTLINK_TARGET_DIRECTORIES = array('config', 'controllers', 'helpers', 'hooks', 'libraries', 'models', 'views', 'widgets'); + private $SOFTLINK_TARGET_DIRECTORIES = array('config', 'controllers', 'helpers', 'hooks', 'libraries', 'models', 'views', 'widgets'); private $_errorOccurred; // boolean, true if an error occurred while installing an extension private $_currentInstalledExtensionVersion; // contains the version of the current installation of an extension @@ -29,9 +29,11 @@ class ExtensionsLib * Class constructor */ public function __construct() - { + { + $this->UPLOAD_PATH = APPPATH.'tmp/'; + $this->EXTENSIONS_PATH = APPPATH.'extensions/'; // Get code igniter instance - $this->ci =& get_instance(); + $this->ci =& get_instance(); // Loads message configurationx $this->ci->config->load('message'); @@ -60,7 +62,7 @@ class ExtensionsLib $this->_printInfo('WARNING!!! Please do not change page or stop this procedure before it is finished'); - $this->_loadUploadLibrary(); // loads CI upload library + $this->_loadUploadLibrary(); // loads CI upload library $uploadData = $this->_uploadExtension(); // perform the upload of the file and returns info about it @@ -99,7 +101,7 @@ class ExtensionsLib { // Loads and executes neede SQL scripts $this->_loadSQLs( - ExtensionsLib::UPLOAD_PATH.$extensionJson->name.'/'.ExtensionsLib::SQL_DIRECTORY, + $this->UPLOAD_PATH.$extensionJson->name.'/'.ExtensionsLib::SQL_DIRECTORY, $extensionJson ); } @@ -157,7 +159,7 @@ class ExtensionsLib $extensionName = $result->retval[0]->name; // extension name $this->_delSoftLinks($extensionName); // not to be checked, could fail if the extension is disabled // remove the extension from the extensions installation directory - $delExtension = $this->_rrm(ExtensionsLib::EXTENSIONS_PATH.$extensionName); + $delExtension = $this->_rrm($this->EXTENSIONS_PATH.$extensionName); // Select all the version of this extension $this->ci->ExtensionsModel->addSelect('extension_id'); @@ -215,7 +217,7 @@ class ExtensionsLib $this->ci->load->library( 'upload', array( - 'upload_path' => ExtensionsLib::UPLOAD_PATH, + 'upload_path' => $this->UPLOAD_PATH, 'allowed_types' => '*', 'overwrite' => true ) @@ -237,7 +239,7 @@ class ExtensionsLib $uploadData = $this->ci->upload->data(); // retrives data about the uploaded file // Checks the file extension $uploadedFileExtension = '.'.pathinfo($uploadData['full_path'], PATHINFO_EXTENSION); - if (!in_array($uploadedFileExtension, ExtensionsLib::ARCHIVE_EXTENSIONS)) + if (!in_array($uploadedFileExtension, $this->ARCHIVE_EXTENSIONS)) { $this->_printFailure('file extension must be tgz OR tbz2'); @@ -251,7 +253,7 @@ class ExtensionsLib { // Returns the extension name and the full path of the uploaded file $_uploadExtension = new stdClass(); - $_uploadExtension->extensionName = str_replace(ExtensionsLib::ARCHIVE_EXTENSIONS, '', $uploadData['file_name']); + $_uploadExtension->extensionName = str_replace($this->ARCHIVE_EXTENSIONS, '', $uploadData['file_name']); $_uploadExtension->fullPath = $uploadData['full_path']; } } @@ -279,7 +281,7 @@ class ExtensionsLib // Extracts the uploaded file $pd = new PharData($uploadPath); - $pd->extractTo(ExtensionsLib::UPLOAD_PATH, null, true); + $pd->extractTo($this->UPLOAD_PATH, null, true); } catch (UnexpectedValueException $uva) { @@ -342,10 +344,10 @@ class ExtensionsLib $this->_printStart('Checking extension file system structure'); // Checks if the root directory of this archive has the same name of the extension - if (is_dir(ExtensionsLib::UPLOAD_PATH.$extensionName)) + if (is_dir($this->UPLOAD_PATH.$extensionName)) { // Checks if file extension.json exists inside the uploaded archive - if (!file_exists(ExtensionsLib::UPLOAD_PATH.$extensionName.'/'.ExtensionsLib::EXTENSION_JSON_NAME)) + if (!file_exists($this->UPLOAD_PATH.$extensionName.'/'.ExtensionsLib::EXTENSION_JSON_NAME)) { $this->_errorOccurred = true; $this->_printFailure('missing extension.json'); @@ -371,7 +373,7 @@ class ExtensionsLib // Decodes extension.json $extensionJson = json_decode( - file_get_contents(ExtensionsLib::UPLOAD_PATH.$extensionName.'/'.ExtensionsLib::EXTENSION_JSON_NAME) + file_get_contents($this->UPLOAD_PATH.$extensionName.'/'.ExtensionsLib::EXTENSION_JSON_NAME) ); // Checks if the parameter name of the extension.json has the same value of the extension name @@ -608,10 +610,10 @@ class ExtensionsLib { $this->_printStart('Moving the upload extension from upload folder to extension folder'); - $this->_printMessage('Current extension directory: '.ExtensionsLib::UPLOAD_PATH.$extensionName); - $this->_printMessage('Directory where it will be moved: '.ExtensionsLib::EXTENSIONS_PATH.$extensionName); + $this->_printMessage('Current extension directory: '.$this->UPLOAD_PATH.$extensionName); + $this->_printMessage('Directory where it will be moved: '.$this->EXTENSIONS_PATH.$extensionName); - if (rename(ExtensionsLib::UPLOAD_PATH.$extensionName.'/', ExtensionsLib::EXTENSIONS_PATH.$extensionName)) + if (rename($this->UPLOAD_PATH.$extensionName.'/', $this->EXTENSIONS_PATH.$extensionName)) { $this->_printSuccess(true); } @@ -652,7 +654,7 @@ class ExtensionsLib { $_delSoftLinks = false; - foreach (ExtensionsLib::SOFTLINK_TARGET_DIRECTORIES as $key => $targetDirectory) + foreach ($this->SOFTLINK_TARGET_DIRECTORIES as $key => $targetDirectory) { if (file_exists(APPPATH.$targetDirectory.'/'.ExtensionsLib::EXTENSIONS_DIR_NAME.'/'.$extensionName)) { @@ -700,10 +702,10 @@ class ExtensionsLib private function _addSoftLinks($extensionName) { $_addSoftLinks = false; - $extensionPath = ExtensionsLib::EXTENSIONS_PATH.$extensionName.'/'; + $extensionPath = $this->EXTENSIONS_PATH.$extensionName.'/'; // For every target directory - foreach (ExtensionsLib::SOFTLINK_TARGET_DIRECTORIES as $key => $targetDirectory) + foreach ($this->SOFTLINK_TARGET_DIRECTORIES as $key => $targetDirectory) { // If destination of the symlink does not exist if (!file_exists(APPPATH.$targetDirectory.'/'.ExtensionsLib::EXTENSIONS_DIR_NAME.'/'.$extensionName)) @@ -746,9 +748,9 @@ class ExtensionsLib $this->_printMessage('Removing the extracted data from the upload directory'); if ($uploadData != null && isset($uploadData->extensionName) - && file_exists(ExtensionsLib::UPLOAD_PATH.$uploadData->extensionName)) + && file_exists($this->UPLOAD_PATH.$uploadData->extensionName)) { - $this->_rrm(ExtensionsLib::UPLOAD_PATH.$uploadData->extensionName); + $this->_rrm($this->UPLOAD_PATH.$uploadData->extensionName); } // If the upload of the file is a success and the extension name is present and no previous installation were found diff --git a/application/libraries/LogLib.php b/application/libraries/LogLib.php index be401f208..222ed7cc7 100644 --- a/application/libraries/LogLib.php +++ b/application/libraries/LogLib.php @@ -10,29 +10,29 @@ class LogLib const DEBUG = 'debug'; const ERROR = 'error'; const INFO = 'info'; - + const CALLER_PREFIX = '['; const CALLER_POSTFIX = ']'; const CLASS_POSTFIX = '->'; const LINE_SEPARATOR = ':'; - + /** * format */ private function format($class, $function, $line) { $formatted = LogLib::CALLER_PREFIX; - + if (!is_null($class) && $class != '') { $formatted .= $class.LogLib::CLASS_POSTFIX; } - + $formatted .= $function.LogLib::LINE_SEPARATOR.$line.LogLib::CALLER_POSTFIX.' '; - + return $formatted; } - + /** * getCaller */ @@ -44,20 +44,20 @@ class LogLib $class = ''; $function = ''; $line = ''; - - if (isset(debug_backtrace()[$classIndex]['class']) && debug_backtrace()[$classIndex]['class'] != '') + $backtrace_arr = debug_backtrace(); + if (isset($backtrace_arr[$classIndex]['class']) && $backtrace_arr[$classIndex]['class'] != '') { - $class = debug_backtrace()[$classIndex]['class']; + $class = $backtrace_arr[$classIndex]['class']; } - if (isset(debug_backtrace()[$functionIndex]['function']) && debug_backtrace()[$functionIndex]['function'] != '') + if (isset($backtrace_arr[$functionIndex]['function']) && $backtrace_arr[$functionIndex]['function'] != '') { - $function = debug_backtrace()[$functionIndex]['function']; + $function = $backtrace_arr[$functionIndex]['function']; } - if (isset(debug_backtrace()[$lineIndex]['line']) && debug_backtrace()[$lineIndex]['line'] != '') + if (isset($backtrace_arr[$lineIndex]['line']) && $backgrace_arr[$lineIndex]['line'] != '') { - $line = debug_backtrace()[$lineIndex]['line']; + $line = $backtrace_arr[$lineIndex]['line']; } return $this->format($class, $function, $line); diff --git a/application/libraries/REST_Controller.php b/application/libraries/REST_Controller.php index d1bd334c6..e32cf75f7 100644 --- a/application/libraries/REST_Controller.php +++ b/application/libraries/REST_Controller.php @@ -351,7 +351,7 @@ abstract class REST_Controller extends CI_Controller { self::HTTP_INTERNAL_SERVER_ERROR => 'INTERNAL SERVER ERROR', self::HTTP_NOT_IMPLEMENTED => 'NOT IMPLEMENTED' ]; - + /** * Extend this function to apply additional checking early on in the process * @@ -361,7 +361,7 @@ abstract class REST_Controller extends CI_Controller { protected function early_checks() { } - + /** * Constructor for the REST API * @@ -385,7 +385,8 @@ abstract class REST_Controller extends CI_Controller { } // Check to see if this is CI 3.x - if (explode('.', CI_VERSION, 2)[0] < 3) + $ci_version_number = explode('.', CI_VERSION, 2); + if ($ci_version_number[0] < 3) { throw new Exception('REST Server requires CodeIgniter 3.x'); } @@ -528,7 +529,7 @@ abstract class REST_Controller extends CI_Controller { { $this->_allow = $this->_detect_api_key(); } - + // Only allow ajax requests if ($this->input->is_ajax_request() === FALSE && $this->config->item('rest_ajax_only')) { @@ -607,7 +608,7 @@ abstract class REST_Controller extends CI_Controller { //$controller_method = $object_called . '_' . $this->request->method; // CamelCase compliant $controller_method = $this->request->method.ucfirst($object_called); - + // Do we want to log this method (if allowed by config)? $log_method = !(isset($this->methods[$controller_method]['log']) && $this->methods[$controller_method]['log'] === FALSE); @@ -737,7 +738,7 @@ abstract class REST_Controller extends CI_Controller { // Set the format header $this->output->set_content_type($this->_supported_formats[$this->response->format], strtolower($this->config->item('charset'))); $output = $this->format->factory($data)->{'to_' . $this->response->format}(); - + // An array must be parsed as a string, so as not to cause an array to string error // Json is the most appropriate form for such a datatype if ($this->response->format === 'array') @@ -967,7 +968,7 @@ abstract class REST_Controller extends CI_Controller { $this->rest->level = NULL; $this->rest->user_id = NULL; $this->rest->ignore_limits = FALSE; - + // Find the key from server or arguments if (($key = isset($this->_args[$api_key_variable]) ? $this->_args[$api_key_variable] : $this->input->server($key_name))) { @@ -1899,7 +1900,7 @@ abstract class REST_Controller extends CI_Controller { ], self::HTTP_UNAUTHORIZED); } } - + /** * Prepares for basic authentication * @@ -1977,7 +1978,7 @@ abstract class REST_Controller extends CI_Controller { preg_match_all('@(username|nonce|uri|nc|cnonce|qop|response)=[\'"]?([^\'",]+)@', $digest_string, $matches); $digest = (empty($matches[1]) || empty($matches[2])) ? [] : array_combine($matches[1], $matches[2]); - // For digest authentication the library function should return + // For digest authentication the library function should return // already stored password for that username, even if it is hashed $username = $this->_check_login($digest['username'], TRUE); // If there no password @@ -2154,4 +2155,4 @@ abstract class REST_Controller extends CI_Controller { ->get($this->config->item('rest_access_table')) ->num_rows() > 0; } -} \ No newline at end of file +} diff --git a/application/models/system/MessageToken_model.php b/application/models/system/MessageToken_model.php index 24b9f05ca..fb7f81a0a 100644 --- a/application/models/system/MessageToken_model.php +++ b/application/models/system/MessageToken_model.php @@ -88,10 +88,11 @@ class MessageToken_model extends CI_Model // If no errors occurred if ($msgs) { + $msgs_result = $msgs->result(); // If at least a record is present - if (count($msgs->result()) > 0) + if (count($msgs_result) > 0) { - $msg = $msgs->result()[0]; + $msg = $msgs_result[0]; $msgStatusResult = false; // pessimistic expectation @@ -133,7 +134,7 @@ class MessageToken_model extends CI_Model } } - return success($msgs->result()); + return success($msgs_result); } else { @@ -193,7 +194,8 @@ class MessageToken_model extends CI_Model // If data are present if (is_array($result->result()) && count($result->result()) > 0) { - $person = $result->result()[0]; + $personresults = $result->result(); + $person = $personresults[0]; // If it is an employee if ($person->mitarbeiter_uid != null) @@ -236,13 +238,14 @@ class MessageToken_model extends CI_Model $result = $this->db->query($sql, array($oe_kurzbz)); if ($result) // If no errors occurred { + $result_arr = $result->result(); // If data are present - if (is_array($result->result()) - && count($result->result()) > 0 - && is_object($result->result()[0]) - && isset($result->result()[0]->oe_kurzbz)) + if (is_array($result_arr) + && count($result_arr) > 0 + && is_object($result_arr[0]) + && isset($result_arr[0]->oe_kurzbz)) { - return success($result->result()[0]->oe_kurzbz); + return success($result_arr[0]->oe_kurzbz); } else {