Ejemplo n.º 1
0
 public function load($id = null, $checkSession = true)
 {
     if ($id) {
         $this->id = $id;
     } else {
         if ($this->useCookie && isset($_COOKIE[$this->name]) && preg_match('/^[0-9a-zA-Z]{32}$/', $_COOKIE[$this->name])) {
             $this->id = $_COOKIE[$this->name];
         } else {
             $this->id = StringTools::random(32);
         }
     }
     session_id($this->id);
     session_start();
     $this->isNew = !isset($_SESSION['_data']);
     if ($this->useCookie) {
         setcookie($this->name, $this->id, time() + $this->expirationTime * 4, $this->cookiePath, $this->cookieDomain, $this->cookieSecure, $this->cookieHttpOnly);
     }
     if (!$this->isNew) {
         if ($checkSession && !$this->checkSession()) {
             $this->reset();
         } else {
             $this->data = unserialize($_SESSION['_data']);
         }
     } else {
         $this->data = null;
     }
 }
Ejemplo n.º 2
0
 protected function _getNewId()
 {
     do {
         $id = StringTools::random(16, 'abcdefghijklmnopqrstuvwxyz0123456789');
     } while (is_file($this->_getPath($id)));
     return $id;
 }
Ejemplo n.º 3
0
 /** @param Event $event */
 public function onMail($event)
 {
     /** @var $mail Mail */
     $mail = $event->data;
     if (!$mail->from) {
         $mail->from = $this->moduleConfig->from;
     }
     if (!$mail->returnPath) {
         $mail->returnPath = $this->moduleConfig->returnPath;
     }
     $mode = $this->moduleConfig->mode;
     // Send mails
     if ($mode === self::MODE_SEND) {
         if ($to = $this->moduleConfig->to) {
             $mail->subject = '[DEBUG for ' . print_r($mail->recipients, true) . '] ' . $mail->subject;
             $mail->recipients = $to;
             $mail->recipientsCc = $mail->recipientsBcc = null;
         }
         $mail->send();
         // Debug to directory
     } elseif ($mode === self::MODE_DIRECTORY) {
         if (!$this->_directory) {
             $this->_directory = $this->app->parseUri($this->moduleConfig->directory);
         }
         $this->_count++;
         $t = time();
         $text = 'DATE: ' . date('Y-m-h H:i:s', $t) . chr(10) . 'TO: ' . json_encode($mail->recipients) . chr(10) . ($mail->recipientsCc ? 'CC: ' . json_encode($mail->recipientsCc) . chr(10) : '') . ($mail->recipientsBcc ? 'BCC: ' . json_encode($mail->recipientsBcc) . chr(10) : '') . 'SUBJECT: ' . $mail->subject . chr(10) . 'FROM: ' . $mail->from . chr(10) . ($mail->returnPath ? 'RETURN-PATH: ' . $mail->returnPath . chr(10) : '') . chr(10) . $mail->text;
         $file = trim($this->_directory . date('Y-m-d-H-i-s', $t) . ' - ' . str_pad($this->_count, 4, '0', STR_PAD_LEFT) . ' - ' . StringTools::toUrlPart($mail->subject));
         file_put_contents($file . '.txt', $text);
         if ($mail->htmlText) {
             file_put_contents($file . '.htm', $mail->htmlText);
         }
     }
 }
Ejemplo n.º 4
0
 public function checkServerAdmin($serverArgs)
 {
     $val = ArrayTools::get($serverArgs, 'SERVER_ADMIN');
     if ($val !== null) {
         $this->checkConfig(StringTools::camelCase(StringTools::toUrlPart($val), '-'));
     }
 }
Ejemplo n.º 5
0
 public function e($text, $context = null, $echo = null)
 {
     if ($context === null) {
         $context = $this->defaultEscapingContext;
     }
     if ($echo === null) {
         $echo = $this->defaultEcho;
     }
     if ($context == 'html') {
         $text = StringTools::escapeHtml($text);
     } else {
         if ($context == 'js') {
             $text = StringTools::escapeJs($text);
         } else {
             if ($context == 'url') {
                 $text = urlencode($text);
             }
         }
     }
     if ($echo) {
         echo $text;
         return null;
     } else {
         return $text;
     }
 }
Ejemplo n.º 6
0
    public function parseTask()
    {
        /** @var $m LoggingModule */
        $m = $this->task->module;
        $mode = $this->request()->get->get('mode');
        $status = null;
        if ($mode == 'clear') {
            file_put_contents($m->moduleConfig->file, '');
            $status = 'All logs have been cleared.';
        }
        $logs = is_file($m->moduleConfig->file) ? file_get_contents($m->moduleConfig->file) : '';
        $logs = StringTools::escapeHtml($logs);
        $content = <<<CNT
<!DOCTYPE html>
<body>
<div>
<a href="?">Show logs</a>
<a href="?mode=clear">Clear logs</a>
</div>
<div><strong>
{$status}
</strong></div>
<hr>
<pre>
{$logs}
</pre>
</body>
CNT;
        $this->task->response->postContent($content, ContentType::TYPE_HTML_UTF8);
    }
    public function parseTask()
    {
        /** @var $m ErrorReportingModule */
        $m = $this->task->module;
        $mode = $this->request()->get->get('mode');
        $status = null;
        if ($mode == 'clear') {
            file_put_contents($m->moduleConfig->file, '');
            $status = 'All errors have been cleared.';
        } elseif ($mode == 'trigger') {
            $this->app->events->trigger('logException', new \Exception('A test error has been triggered.'));
            $status = 'The test error has been triggered.';
        } elseif ($mode == 'toggle') {
            if (!is_file($m->moduleConfig->file)) {
                file_put_contents($m->moduleConfig->file, 'disabled');
                $status = 'Error reporting has been disabled.';
            } else {
                $f = fopen($m->moduleConfig->file, 'r+');
                if (fread($f, 8) == 'disabled') {
                    ftruncate($f, 0);
                    $status = 'Error reporting has been enabled.';
                } else {
                    ftruncate($f, 0);
                    fseek($f, 0);
                    fwrite($f, 'disabled');
                    $status = 'Error reporting has been disabled.';
                }
                fclose($f);
            }
        }
        $errors = is_file($m->moduleConfig->file) ? file_get_contents($m->moduleConfig->file) : '';
        if (substr($errors, 0, 8) == 'disabled') {
            $toggleLabel = 'Enable reporting';
        } else {
            $toggleLabel = 'Disable reporting';
        }
        $errors = StringTools::escapeHtml($errors);
        $content = <<<CNT
<!DOCTYPE html>
<body style="margin:0;padding:0">
<div style="position:fixed;width:100%;background:white;padding:10px;border-bottom:solid 1px black">
<a href="?">Show errors</a>
<a href="?mode=clear">Clear errors</a>
<a href="?mode=trigger">Trigger error</a>
<a href="?mode=toggle">{$toggleLabel}</a>
<br />
<strong>
{$status}
</strong>
</div>
<div style="padding-top: 100px;">
<pre>
{$errors}
</pre>
</div>
</body>
CNT;
        $this->task->response->postContent($content, ContentType::TYPE_HTML_UTF8);
    }
Ejemplo n.º 8
0
 public function render($mode)
 {
     if ($mode == Set::MODE_EXPORT || !$this->escapeContent) {
         return $this->content;
     } else {
         return StringTools::escapeHtml($this->content);
     }
 }
Ejemplo n.º 9
0
 public function render($mode)
 {
     $date = $this->_data ? $this->_data->format($this->format) : '';
     if ($mode == Set::MODE_EXPORT) {
         return $date;
     } else {
         return '<p>' . StringTools::escapeHtml($date) . '</p>';
     }
 }
Ejemplo n.º 10
0
 public function email($options = null)
 {
     if ($this->stopOnError && !$this->hasValidated($this->_currentId)) {
         return $this;
     }
     if (!StringTools::isEmailAddress($this->_currentValue)) {
         $this->_addError('email', ArrayTools::get($options, 'message'));
     }
     return $this;
 }
Ejemplo n.º 11
0
 public function queryTask(Task $t)
 {
     if ($t->id === null) {
         $t->id = StringTools::random(16);
     }
     $t->manager = null;
     $t->onSerialize();
     $file = $this->directory . str_pad($t->priority, 3, '0', STR_PAD_LEFT) . '_' . $t->id . '.tsk';
     file_put_contents($file, serialize($t));
     if ($t->executeAt) {
         touch($file, $t->executeAt);
     }
     /** @var $t Task */
     $t->manager = $this;
 }
Ejemplo n.º 12
0
 public function render($mode)
 {
     $isChecked = $this->_data == $this->value;
     if ($mode == Set::MODE_EXPORT) {
         return $isChecked ? $this->label : '';
     }
     $attributes = $isChecked ? ' checked="checked"' : '';
     if ($mode == Set::MODE_SHOW || $mode == Set::MODE_LIST || $mode == Set::MODE_DELETE || !$this->editable) {
         $attributes .= ' disabled="disabled"';
     }
     $id = 'c' . StringTools::random(15);
     $c = '<input id="' . $id . '" type="checkbox" name="' . $this->name . '" value="' . StringTools::escapeHtml($this->value) . '"' . $attributes . ' />';
     if ($this->label != '') {
         $c .= '<label for="' . $id . '">' . StringTools::escapeHtml($this->label) . '</label>';
     }
     return $c;
 }
Ejemplo n.º 13
0
 /** @return string */
 public function prepareQuery($query, $args = null, $isInternalCall = false)
 {
     if (!is_array($args)) {
         $args = array($args);
     }
     $query = StringTools::parse($query, array_merge($this->globalQueryArgs, $args), array($this, 'prepareQueryFilterCallback'));
     if ($isInternalCall) {
         Database::$countQueries++;
         $this->countQueries++;
         if ($this->_backupLastQuery) {
             $this->_lastQuery = $query;
         }
         if ($this->debug && $this->events) {
             $this->events->trigger('log', '[' . $this->id . '] Query: ' . $query);
         }
     }
     return $query;
 }
Ejemplo n.º 14
0
 public function render($mode)
 {
     if ($mode == Set::MODE_EXPORT) {
         return $this->options[$this->_data];
     }
     if ($mode == Set::MODE_SHOW || $mode == Set::MODE_DELETE || $mode == Set::MODE_LIST || !$this->editable) {
         return '<p>' . StringTools::escapeHtml($this->options[$this->_data]) . '</p>';
     } elseif ($mode == Set::MODE_EDIT || $mode == Set::MODE_ADD) {
         $c = '<select name="' . $this->name . '">';
         $data = strval($this->_data);
         foreach ($this->options as $key => $value) {
             $selected = strval($key) === $data ? ' selected="selected"' : '';
             $c .= '<option value="' . StringTools::escapeHtml($key) . '"' . $selected . '>' . StringTools::escapeHtml($value) . '</option>';
         }
         $c .= '</select>';
         return $c;
     }
     return $this->options[$this->_data];
 }
Ejemplo n.º 15
0
 public function __toString()
 {
     $cnt = '';
     if ($this->tag) {
         $cnt = '<' . $this->tag;
         if ($this->attributes) {
             foreach ($this->attributes as $atbName => $atbValue) {
                 if ($atbValue !== null) {
                     $cnt .= ' ' . $atbName . '="' . StringTools::escapeHtml($atbValue) . '"';
                 }
             }
         }
     }
     if ($this->contents !== null) {
         if ($this->tag) {
             $cnt .= '>';
         }
         if (is_string($this->contents)) {
             $cnt .= $this->escapeContent ? StringTools::escapeHtml($this->contents) : $this->contents;
         } else {
             if (is_array($this->contents)) {
                 $c = '';
                 foreach ($this->contents as $content) {
                     $c .= $content;
                 }
                 $cnt .= $this->escapeContent ? StringTools::escapeHtml($c) : $c;
             }
         }
         if ($this->tag) {
             $cnt .= '</' . $this->tag . '>';
         }
     } else {
         if ($this->tag) {
             if ($this->quickClose) {
                 $cnt .= ' />';
             } else {
                 $cnt .= '></' . $this->tag . '>';
             }
         }
     }
     return $cnt;
 }
Ejemplo n.º 16
0
 public static function onProjectCreated(Event $e)
 {
     $io = $e->getIO();
     //        return;
     $folder = 'modules/AppModule/';
     if (!is_dir($folder)) {
         $io->write("Couldn't find AppModule. Configuration will be stopped.");
         return;
     }
     $io->write('Configurating AppBaseConfig.php');
     $file = $folder . 'Configs/AppBaseConfig.php';
     $content = file_get_contents($file);
     $content = str_replace('###ACCESS_KEY###', StringTools::random(32), $content);
     file_put_contents($file, $content);
     $io->write('Configurating AppModule.php');
     $file = $folder . 'AppModule.php';
     $content = file_get_contents($file);
     $content = str_replace(array('###AUTH_USER###', '###AUTH_PASS###'), array('console_' . mt_rand(1000, 9999), StringTools::random(16)), $content);
     file_put_contents($file, $content);
     $io->write('Your grout application has been configured.');
 }
    public function parseTask()
    {
        /** @var BasicLoginModule $module */
        $module = $this->task->module;
        $name = StringTools::escapeHtml($this->task->route->data->get('name', $module->moduleConfig->realm));
        $url = $this->task->url;
        $content = <<<HTML
<!doctype html>
<html>
<body>
<h1>Access denied</h1>
<p>Login to access “{$name}”.</p>
<form action="{$url}" method="post">
Username: <input type="text" name="username"><br>
Password: <input type="password" name="password"><br>
<input type="submit" name="login" value="Login">
</form>
</body>
</html>
HTML;
        $this->setResult($content, null, ResponseCode::CODE_401);
    }
Ejemplo n.º 18
0
 public function render($mode)
 {
     $url = $this->_getImageUrl();
     if ($mode == Set::MODE_EXPORT) {
         return $url ? $url : $this->_data;
     }
     if ($this->editable && ($mode == Set::MODE_ADD || $mode == Set::MODE_EDIT)) {
         $c = '<input type="file" name="' . $this->name . '" />';
     } else {
         $c = '';
     }
     if ($this->_data) {
         if ($c) {
             $c .= '<br /><br />';
         }
         if ($url) {
             $c .= '<img id="' . $this->name . '_preview" src="' . StringTools::escapeHtml($url) . '" alt="" />';
         } else {
             $c .= StringTools::escapeHtml($this->_data);
         }
     }
     return $c;
 }
Ejemplo n.º 19
0
 public function render($mode)
 {
     $url = $this->_getFileUrl();
     if ($mode == Set::MODE_EXPORT) {
         return $url ? $url : $this->_data;
     }
     if ($this->editable && ($mode == Set::MODE_ADD || $mode == Set::MODE_EDIT)) {
         $c = '<input type="file" name="' . $this->name . '" />';
     } else {
         $c = '';
     }
     if ($this->_data) {
         if ($c != '') {
             $c .= '<br /><br />';
         }
         if ($url) {
             $c .= '<a href="' . StringTools::escapeHtml($url) . '" target="_blank">' . StringTools::escapeHtml($url) . '</a>';
         } else {
             $c .= StringTools::escapeHtml($this->_data);
         }
     }
     return $c;
 }
Ejemplo n.º 20
0
 public function getUrl($path = '', $absoluteURL = true, $parameters = null)
 {
     if ($parameters != null) {
         $path .= StringTools::getQueryString($parameters);
     }
     if ($absoluteURL) {
         return $this->url . $path;
     }
     return $path;
 }
 public function showHeadline($title, $rawTitle = false, $level = 2)
 {
     $this->show('<h' . $level . '>' . ($rawTitle ? $title : StringTools::escapeHtml($title)) . '</h' . $level . '>', true);
 }
Ejemplo n.º 22
0
 public static function createConfigChain($primaryConfig, $defaultConfig, $namespace = '', $useServerAdmin = true, $useServerName = true, $prefix = '')
 {
     $chain = array();
     if ($primaryConfig) {
         $chain[] = $namespace . '\\' . $prefix . $primaryConfig . 'Config';
     }
     if ($useServerAdmin) {
         $chain[] = $namespace . '\\' . $prefix . StringTools::camelCase(StringTools::toURLPart(ArrayTools::get($_SERVER, 'SERVER_ADMIN')), '-') . 'Config';
     }
     if ($useServerName) {
         $chain[] = $namespace . '\\' . $prefix . StringTools::camelCase(StringTools::toURLPart(ArrayTools::get($_SERVER, 'HTTP_HOST')), '-') . 'Config';
     }
     if ($defaultConfig) {
         $chain[] = $namespace . '\\' . $prefix . $defaultConfig . 'Config';
     }
     return $chain;
 }
Ejemplo n.º 23
0
 public function isValid($value)
 {
     return StringTools::isEmailAddress($value);
 }
Ejemplo n.º 24
0
 public function getUrl($arguments = null, $absoluteURL = true, $parameters = null, $escapeArguments = true)
 {
     $url = $this->permaUrl;
     $url = AppTools::encodePageUrlString($url, $arguments, $escapeArguments);
     if ($parameters != null) {
         $url .= StringTools::getQueryString($parameters);
     }
     if ($absoluteURL) {
         $url = $this->module->app->url . $url;
     }
     return $url;
 }
Ejemplo n.º 25
0
 public function isValid($value)
 {
     return StringTools::isUrl($value);
 }
Ejemplo n.º 26
0
 public static function createId()
 {
     return StringTools::random(32);
 }
Ejemplo n.º 27
0
 public function render($mode)
 {
     if ($mode == Set::MODE_EXPORT) {
         return $this->_data;
     }
     if ($mode == Set::MODE_SHOW || $mode == Set::MODE_DELETE || $mode == Set::MODE_LIST || !$this->editable) {
         return '<p>' . StringTools::escapeHtml($this->_data) . '</p>';
     }
     $additionalAttributes = '';
     $attributes = $this->config->get('attributes');
     if ($attributes) {
         foreach ($attributes as $key => $value) {
             $additionalAttributes .= " {$key}=\"" . StringTools::escapeHtml($value) . "\"";
         }
     }
     if ($this->password) {
         return '<input type="password" name="' . $this->name . '" value=""' . $additionalAttributes . ' />';
     }
     if ($this->multiline) {
         return '<textarea name="' . $this->name . '"' . $additionalAttributes . '>' . StringTools::escapeHtml($this->_data) . '</textarea>';
     }
     return '<input type="text" name="' . $this->name . '" value="' . StringTools::escapeHtml($this->_data) . '"' . $additionalAttributes . ' />';
 }
Ejemplo n.º 28
0
 public function createFromContent($content, $expirationDate = 86400, $id = null, $metadata = null, $originalFilename = null)
 {
     if ($this->filesExpire) {
         $t = time();
         if ($expirationDate < 1000000000) {
             $expirationDate += $t;
         }
     } else {
         $t = $expirationDate = 0;
     }
     $f = new TemporaryFile();
     $f->storeMetadata = $this->storeMetadata;
     if ($id !== null) {
         $f->id = $id;
         $f->path = $this->getPathById($id, false);
     } else {
         do {
             $f->id = $this->idPrefix . StringTools::random($this->idLength, $this->idChars) . $this->idSuffix;
             $f->path = $this->getPathById($f->id, false);
             $exists = is_file($f->path) && (!$this->filesExpire || filemtime($f->path) > $t);
         } while ($exists);
     }
     $f->originalFilename = $originalFilename;
     $f->expires = $expirationDate;
     $f->url = $this->baseUrl . $f->id . $this->extension;
     $f->metadata = $metadata;
     if ($this->pathChunkSize) {
         $dir = dirname($f->path);
         if (!is_dir($dir)) {
             FileTools::createDirectory($dir);
         }
     }
     file_put_contents($f->path, $content);
     $f->save();
     return $f;
 }
Ejemplo n.º 29
0
    public function parseTask()
    {
        /** @var $m MailModule */
        $m = $this->task->module;
        $mode = $this->request()->get->get('mode');
        $status = null;
        if ($m->moduleConfig->mode != MailModule::MODE_DIRECTORY) {
            $this->setResult('Directory logging is disabled.');
            return;
        }
        $directory = $m->moduleConfig->directory;
        $content = '';
        if ($mode == 'clear') {
            FileTools::deleteContents($directory);
            $status = 'All mails have been cleared.';
        } elseif ($mode == 'showhtml') {
            $id = $this->task->request->get->asString('mail')->asInput(128)->value;
            if (preg_match('!^[a-zA-Z0-9_+ -]+$!', $id) && is_file($directory . $id . '.htm')) {
                $this->setResult(file_get_contents($directory . $id . '.htm'), ContentType::TYPE_HTML_UTF8);
                return;
            } else {
                $content = 'Mail does not exist';
            }
        } elseif ($mode == 'show') {
            $id = $this->task->request->get->asString('mail')->asInput(128)->value;
            if (preg_match('!^[a-zA-Z0-9_+ -]+$!', $id)) {
                if ($id != 'latest' && !is_file($directory . $id . '.txt')) {
                    $content = 'Mail does not exist.';
                } else {
                    if ($id == 'latest') {
                        $files = scandir($directory);
                        $id = null;
                        foreach ($files as $file) {
                            if ($file == '.' || $file == '..' || !preg_match('!^(.*)\\.txt$!', $file, $fileData)) {
                                continue;
                            }
                            $id = $fileData[1];
                        }
                    }
                    if (!$id) {
                        $content = 'Mail does not exist';
                    } else {
                        $content = StringTools::escapeHtml(file_get_contents($directory . $id . '.txt'));
                        $content = preg_replace('![a-zA-Z0-9]+://[^\\s\\(\\)]+!', '<a href="\\0" target="_blank">\\0</a>', $content);
                        $content = '<pre>' . $content . '</pre>';
                        if (is_file($directory . $id . '.htm')) {
                            $content .= '<iframe src="?mode=showhtml&amp;mail=' . rawurlencode($id) . '" width="900" height="600"></iframe>';
                        }
                    }
                }
            } else {
                $content = 'Please enter a valid id.';
            }
        } else {
            $files = FileTools::listDirectory($directory, false);
            $mailList = array();
            foreach ($files as $file) {
                if (preg_match('!^(.+)\\.([a-zA-Z0-9]+)$!', $file, $fileData)) {
                    if (in_array($fileData[2], array('txt', 'htm'))) {
                        $mailList[$fileData[1]] = true;
                    }
                }
            }
            krsort($mailList);
            $ui = new Ui();
            $content = '<ul>';
            foreach ($mailList as $mailId => $foo) {
                $content .= '<li>' . $ui->link('?mode=show&mail=' . rawurlencode($mailId), $mailId) . '</li>';
            }
            $content .= '</ul>';
        }
        $content = <<<CNT
<!DOCTYPE html>
<body>
<div>
<a href="?">Show mails</a>
<a href="?mode=show&amp;mail=latest">Show latest mail</a>
<a href="?mode=clear">Clear mails</a>
</div>
<div><strong>
{$status}
</strong></div>
<hr>
{$content}
</table>
</pre>
</body>
CNT;
        $this->task->response->postContent($content, ContentType::TYPE_HTML_UTF8);
    }
Ejemplo n.º 30
0
 public static function drawText($text, $ttfFont, $size, $textColor = 0xff, $backgroundColor = 0x0, $additionalConfigs = null)
 {
     $text = StringTools::toNumericEntities($text);
     $box = imagettfbbox($size, 0, $ttfFont, $text);
     $yOffset = $box[1];
     $width = round($box[2] - $box[0] + $size * 0.2);
     $height = round($box[1] - $box[7] + $size * 0.2);
     $xOffset = $width > 50 ? 50 : round($width / 2);
     $image = imagecreate($width, $height);
     $cropCol = imagecolorallocate($image, 255, 0, 255);
     imagefilledrectangle($image, 0, 0, $width, $height, $cropCol);
     imagettftext($image, $size, 0, $xOffset, $height - $yOffset, imagecolorallocate($image, 255, 255, 255), $ttfFont, $text);
     $croppingPrecision = ArrayTools::get($additionalConfigs, 'croppingPrecision', 2);
     // Crop left
     $cropLeft = -1;
     for ($x = 0; $x < 50 + $width / 2; $x += $croppingPrecision) {
         if ($x >= $width) {
             $cropLeft = $x - 1;
             break;
         }
         for ($y = 0; $y < $height; $y += $croppingPrecision) {
             $col = imagecolorat($image, $x, $y);
             if ($col != 0) {
                 $cropLeft = $x - 1;
                 break 1;
             }
         }
         if ($cropLeft >= 0) {
             break;
         }
     }
     $xOffset = $xOffset - $cropLeft - 1;
     $yOffset = 0;
     $temp = imagettftext($image, $size, 0, 0, 0, $cropCol, $ttfFont, $text);
     if (ArrayTools::get($additionalConfigs, 'slim')) {
         $offset = $temp;
     } else {
         $offset = imagettftext($image, $size, 0, 0, 0, $cropCol, $ttfFont, 'BTj&#' . ord(utf8_decode('`')) . ';');
     }
     $width = $temp[2] - $temp[0];
     $height = abs($offset[5] - $offset[1]);
     if ($margin = ArrayTools::get($additionalConfigs, 'safeMargin')) {
         if (is_array($margin)) {
             $width += $margin[1] + $margin[3];
             $xOffset += $margin[3];
             $height += $margin[0] + $margin[2];
             $yOffset += $margin[0];
         } else {
             $width += $margin * 2;
             $height += $margin * 2;
             $xOffset += $margin;
             $yOffset += $margin;
         }
     }
     imagedestroy($image);
     $image = imagecreatetruecolor($width, $height);
     imagealphablending($image, false);
     imagesavealpha($image, true);
     $backgroundColor = self::colorHexToRgba($backgroundColor);
     $backgroundColor = imagecolorallocatealpha($image, $backgroundColor['r'], $backgroundColor['g'], $backgroundColor['b'], 127 - floor($backgroundColor['a'] / 2));
     $textColor = self::colorHexToRgba($textColor);
     $textColor = imagecolorallocatealpha($image, $textColor['r'], $textColor['g'], $textColor['b'], 127 - floor($textColor['a'] / 2));
     imagefilledrectangle($image, 0, 0, $width, $height, $backgroundColor);
     imagealphablending($image, true);
     imagettftext($image, $size, 0, $xOffset, -$offset[5] + $yOffset, $textColor, $ttfFont, $text);
     return $image;
 }