ILIAS  trunk Revision v11.0_alpha-1862-g4e205cb56d4
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
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:
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 32 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 161 of file class.ilShellUtil.php.

References escapeShellArg(), and execConvert().

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

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

◆ escapeShellArg()

static ilShellUtil::escapeShellArg ( string  $a_arg)
static

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

Referenced by convertImage(), ilFFmpeg\extractImage(), ilObjSCORMLearningModuleGUI\newModuleVersionUpload(), resizeImage(), ilVirusScannerAntiVir\scanFile(), ilVirusScannerSophos\scanFile(), ilVirusScannerICapClient\scanFile(), and ilVirusScannerClamAV\scanFile().

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

◆ escapeShellCmd()

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

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

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

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

◆ execConvert()

static ilShellUtil::execConvert ( string  $args)
static

execute convert command

Parameters
string$args

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

References execQuoted().

Referenced by ilLTIConsumeProviderIcon\convert(), convertImage(), and resizeImage().

196  : void
197  {
198  $args = self::escapeShellCmd($args);
199  ilShellUtil::execQuoted(PATH_TO_CONVERT, $args);
200  }
static execQuoted(string $cmd, ?string $args=null)
+ 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 109 of file class.ilShellUtil.php.

References $DIC, and ilUtil\isWindows().

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

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

153  : string
154  {
155  return PATH_TO_CONVERT;
156  }

◆ isConvertVersionAtLeast()

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

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

References $version, and execQuoted().

139  : bool
140  {
141  $current_version = ilShellUtil::execQuoted(PATH_TO_CONVERT, "--version");
142  $current_version = self::processConvertVersion($current_version[0]);
143  $version = self::processConvertVersion($a_version);
144  if ($current_version >= $version) {
145  return true;
146  }
147  return false;
148  }
$version
Definition: plugin.php:24
static execQuoted(string $cmd, ?string $args=null)
+ 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 78 of file class.ilShellUtil.php.

References $version.

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

◆ 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 44 of file class.ilShellUtil.php.

References escapeShellArg(), and execConvert().

50  : void {
51  if ($a_constrain_prop) {
52  $size = " -geometry " . $a_width . "x" . $a_height . " ";
53  } else {
54  $size = " -resize " . $a_width . "x" . $a_height . "! ";
55  }
56  $convert_cmd = ilShellUtil::escapeShellArg($a_from) . " " . $size . ilShellUtil::escapeShellArg($a_to);
57 
58  ilShellUtil::execConvert($convert_cmd);
59  }
static escapeShellArg(string $a_arg)
static execConvert(string $args)
execute convert command
+ Here is the call graph for this function:

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