示例#1
0
 public function load(Job $job)
 {
     $excludeFilters = $job->configuration->get('excludes', null);
     $includeFilters = $job->configuration->get('includes', null);
     /** @var Sprite[] $loadSprites */
     $loadSprites = [];
     foreach ($this->folders as $folder) {
         $files = FileTools::listDirectory($folder, false, true);
         foreach ($files as $file) {
             $originalSpriteName = pathinfo(str_replace('/', '-', $file), PATHINFO_FILENAME);
             $filteredSpriteName = preg_replace('/\\{[^\\}]+\\}/', '', $originalSpriteName);
             // Strip {tags}
             $included = true;
             if ($excludeFilters !== null) {
                 $included = !Tools::matches($excludeFilters, $originalSpriteName) && !Tools::matches($excludeFilters, $filteredSpriteName);
             } elseif ($includeFilters !== null) {
                 $included = false;
             }
             if (!$included && $includeFilters !== null) {
                 $included = Tools::matches($includeFilters, $originalSpriteName) || Tools::matches($includeFilters, $filteredSpriteName);
             }
             if (!$included) {
                 continue;
             }
             $sprite = new Sprite();
             $sprite->originalName = $sprite->name = $originalSpriteName;
             $sprite->name = $filteredSpriteName;
             $sprite->path = $folder . $file;
             $loadSprites[$sprite->name] = $sprite;
         }
     }
     foreach ($loadSprites as $sprite) {
         $sprite->configuration->extend($job->configuration->configuration);
         $this->extendSpriteSettings($job, $sprite);
         if (!$sprite->configuration->getBool('enabled', true)) {
             continue;
         }
         $image = ImageTools::checkFile($sprite->path);
         if ($image->success) {
             $sprite->image = $image->image;
             $sprite->calculateDimensions();
             $job->sprites[$sprite->name] = $sprite;
         }
     }
 }
示例#2
0
 public function cleanUp()
 {
     if (!$this->filesExpire) {
         return;
     }
     $t = time();
     $directories = FileTools::listDirectory($this->directory, true, false);
     array_unshift($directories, '');
     foreach ($directories as $directory) {
         $files = glob($this->directory . $directory . $this->idPrefix . '*' . $this->idSuffix . $this->extension, GLOB_NOSORT);
         if ($files) {
             foreach ($files as $file) {
                 if (filemtime($file) < $t) {
                     unlink($file);
                     if ($this->storeMetadata) {
                         unlink($file . '.dat');
                     }
                 }
             }
         }
     }
 }
示例#3
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);
    }