ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
ilShellUtil Class Reference

This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Learning e.V. More...

+ Collaboration diagram for ilShellUtil:

Static Public Member Functions

static resizeImage (string $a_from, string $a_to, int $a_width, int $a_height, bool $a_constrain_prop=false)
 resize image More...
 
static escapeShellArg (string $a_arg)
 
static escapeShellCmd (string $a_arg)
 
static execQuoted (string $cmd, ?string $args=null)
 
static isConvertVersionAtLeast (string $a_version)
 
static getConvertCmd ()
 
static convertImage (string $a_from, string $a_to, string $a_target_format="", string $a_geometry="", string $a_background_color="")
 
static execConvert (string $args)
 execute convert command More...
 

Static Protected Member Functions

static processConvertVersion (string $a_version)
 Parse convert version string, e.g. More...
 

Detailed Description

This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Learning e.V.

ILIAS is licensed with the GPL-3.0, see https://www.gnu.org/licenses/gpl-3.0.en.html You should have received a copy of said license along with the source code, too.

If this is not the case or you just want to try ILIAS, you'll find us at: https://www.ilias.de https://github.com/ILIAS-eLearning Util class various functions, usage as namespace

Author
Sascha Hofmann sasch.nosp@m.ahof.nosp@m.mann@.nosp@m.gmx..nosp@m.de
Alex Killing alex..nosp@m.kill.nosp@m.ing@g.nosp@m.mx.d.nosp@m.e
Deprecated:
12 This component will be removed with ILIAS 12 The 2021 Technical Board has decided to mark the ilUtil class as deprecated. The ilUtil is a historically grown helper class with many different UseCases and functions. The class is not under direct maintainership and the responsibilities are unclear. In this context, the class should no longer be used in the code and existing uses should be converted to their own service in the medium term. If you need ilUtil for the implementation of a new function in ILIAS > 7, please contact the Technical Board.

Definition at line 33 of file class.ilShellUtil.php.

Member Function Documentation

◆ convertImage()

static ilShellUtil::convertImage ( string  $a_from,
string  $a_to,
string  $a_target_format = "",
string  $a_geometry = "",
string  $a_background_color = "" 
)
static
Deprecated:
will be removed in ILIAS 10, use $DIC->fileConverters() instead

Definition at line 162 of file class.ilShellUtil.php.

168 : void {
169 $format_str = ($a_target_format != "")
170 ? strtoupper($a_target_format) . ":"
171 : "";
172 $geometry = "";
173 if ($a_geometry != "") {
174 if (is_int(strpos($a_geometry, "x"))) {
175 $geometry = " -geometry " . $a_geometry . " ";
176 } else {
177 $geometry = " -geometry " . $a_geometry . "x" . $a_geometry . " ";
178 }
179 }
180
181 $bg_color = ($a_background_color != "")
182 ? " -background color " . $a_background_color . " "
183 : "";
184 $convert_cmd = ilShellUtil::escapeShellArg($a_from) . " " . $bg_color . $geometry . ilShellUtil::escapeShellArg(
185 $format_str . $a_to
186 );
187 ilShellUtil::execConvert($convert_cmd);
188 }
static escapeShellArg(string $a_arg)
static execConvert(string $args)
execute convert command

Referenced by assMatchingQuestion\generateThumbForFile(), assOrderingQuestion\generateThumbForFile(), assOrderingQuestionImport\handleUploadedFile(), assOrderingQuestion\storeImageFile(), and assOrderingQuestion\updateImageFile().

+ Here is the caller graph for this function:

◆ escapeShellArg()

static ilShellUtil::escapeShellArg ( string  $a_arg)
static

Definition at line 62 of file class.ilShellUtil.php.

62 : string
63 {
64 setlocale(
65 LC_CTYPE,
66 "UTF8",
67 "en_US.UTF-8"
68 ); // fix for PHP escapeshellcmd bug. See: http://bugs.php.net/bug.php?id=45132
69 // see also ilias bug 5630
70 return escapeshellarg($a_arg);
71 }

Referenced by ilObjSCORMLearningModuleGUI\newModuleVersionUpload(), ilVirusScannerICapClient\scanFile(), ilVirusScannerAntiVir\scanFile(), ilVirusScannerClamAV\scanFile(), and ilVirusScannerSophos\scanFile().

+ Here is the caller graph for this function:

◆ escapeShellCmd()

static ilShellUtil::escapeShellCmd ( string  $a_arg)
static
Deprecated:

Definition at line 94 of file class.ilShellUtil.php.

94 : string
95 {
96 if (ini_get('safe_mode') == 1) {
97 return $a_arg;
98 }
99 setlocale(
100 LC_CTYPE,
101 "UTF8",
102 "en_US.UTF-8"
103 ); // fix for PHP escapeshellcmd bug. See: http://bugs.php.net/bug.php?id=45132
104 return escapeshellcmd($a_arg);
105 }

Referenced by ilVirusScannerICapClient\scanFile(), ilVirusScannerAntiVir\scanFile(), ilVirusScannerClamAV\scanFile(), and ilVirusScannerSophos\scanFile().

+ Here is the caller graph for this function:

◆ execConvert()

static ilShellUtil::execConvert ( string  $args)
static

execute convert command

Parameters
string$args

Definition at line 197 of file class.ilShellUtil.php.

197 : void
198 {
199 $args = self::escapeShellCmd($args);
200 ilShellUtil::execQuoted(PATH_TO_CONVERT, $args);
201 }
static escapeShellCmd(string $a_arg)
static execQuoted(string $cmd, ?string $args=null)

References execQuoted().

Referenced by ilLTIConsumeProviderIcon\convert().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ execQuoted()

static ilShellUtil::execQuoted ( string  $cmd,
?string  $args = null 
)
static
Deprecated:

Definition at line 110 of file class.ilShellUtil.php.

110 : array
111 {
112 global $DIC;
113
114 if (ilUtil::isWindows() && strpos($cmd, " ") !== false && substr($cmd, 0, 1) !== '"') {
115 // cmd won't work without quotes
116 $cmd = '"' . $cmd . '"';
117 if ($args) {
118 // args are also quoted, workaround is to quote the whole command AGAIN
119 // was fixed in php 5.2 (see php bug #25361)
120 if (version_compare(phpversion(), "5.2", "<") && strpos($args, '"') !== false) {
121 $cmd = '"' . $cmd . " " . $args . '"';
122 } // args are not quoted or php is fixed, just append
123 else {
124 $cmd .= " " . $args;
125 }
126 }
127 } // nothing todo, just append args
128 elseif ($args) {
129 $cmd .= " " . $args;
130 }
131 $arr = [];
132 exec($cmd, $arr);
133 $DIC->logger()->root()->debug("ilUtil::execQuoted: " . $cmd . ".");
134 return $arr;
135 }
static isWindows()
global $DIC
Definition: shib_login.php:26

References $DIC, and ilUtil\isWindows().

Referenced by ilGitInformation\detect(), execConvert(), ilCountPDFPages\extractAmountOfPagesByPath(), isConvertVersionAtLeast(), ilVirusScannerICapClient\scanFile(), ilVirusScannerAntiVir\scanFile(), and ilVirusScannerClamAV\scanFile().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getConvertCmd()

static ilShellUtil::getConvertCmd ( )
static
Deprecated:
, will be removed in ILIAS 10

Definition at line 154 of file class.ilShellUtil.php.

154 : string
155 {
156 return PATH_TO_CONVERT;
157 }

◆ isConvertVersionAtLeast()

static ilShellUtil::isConvertVersionAtLeast ( string  $a_version)
static
Deprecated:
, will be removed in ILIAS 10

Definition at line 140 of file class.ilShellUtil.php.

140 : bool
141 {
142 $current_version = ilShellUtil::execQuoted(PATH_TO_CONVERT, "--version");
143 $current_version = self::processConvertVersion($current_version[0]);
145 if ($current_version >= $version) {
146 return true;
147 }
148 return false;
149 }
$version
Definition: plugin.php:24
static processConvertVersion(string $a_version)
Parse convert version string, e.g.

References $version, and execQuoted().

+ Here is the call graph for this function:

◆ processConvertVersion()

static ilShellUtil::processConvertVersion ( string  $a_version)
staticprotected

Parse convert version string, e.g.

6.3.8-3, into integer

Parameters
string$a_versionw.x.y-z
Returns
int

Definition at line 79 of file class.ilShellUtil.php.

79 : int
80 {
81 if (preg_match("/([0-9]+)\.([0-9]+)\.([0-9]+)([\.|\-]([0-9]+))?/", $a_version, $match)) {
82 $version = str_pad($match[1], 2, "0", STR_PAD_LEFT) .
83 str_pad($match[2], 2, "0", STR_PAD_LEFT) .
84 str_pad($match[3], 2, "0", STR_PAD_LEFT) .
85 str_pad($match[5], 2, "0", STR_PAD_LEFT);
86 return (int) $version;
87 }
88 return 0;
89 }

References $version.

◆ resizeImage()

static ilShellUtil::resizeImage ( string  $a_from,
string  $a_to,
int  $a_width,
int  $a_height,
bool  $a_constrain_prop = false 
)
static

resize image

Parameters
string$a_fromsource file
string$a_totarget file
int$a_widthtarget width
int$a_heighttarget height

Definition at line 45 of file class.ilShellUtil.php.

51 : void {
52 if ($a_constrain_prop) {
53 $size = " -geometry " . $a_width . "x" . $a_height . " ";
54 } else {
55 $size = " -resize " . $a_width . "x" . $a_height . "! ";
56 }
57 $convert_cmd = ilShellUtil::escapeShellArg($a_from) . " " . $size . ilShellUtil::escapeShellArg($a_to);
58
59 ilShellUtil::execConvert($convert_cmd);
60 }

The documentation for this class was generated from the following file: