1 <?php
2
3 4 5 6 7 8 9
10
11 class rex_cronjob_phpcode extends rex_cronjob
12 {
13 public function execute()
14 {
15 $code = preg_replace('/^\<\?(?:php)?/', '', $this->getParam('code'));
16 $is = ini_set('display_errors', true);
17 ob_start();
18 $return = eval($code);
19 $output = ob_get_clean();
20 ini_set('display_errors', $is);
21 if ($output) {
22 $output = str_replace(["\r\n\r\n", "\n\n"], "\n", trim(strip_tags($output)));
23 $output = preg_replace('@in ' . preg_quote(__FILE__, '@') . "\([0-9]*\) : eval\(\)'d code @", '', $output);
24 $this->setMessage($output);
25 }
26 if ($return !== false) {
27 return true;
28 }
29 return false;
30 }
31
32 public function getTypeName()
33 {
34 return rex_i18n::msg('cronjob_type_phpcode');
35 }
36
37 public function getParamFields()
38 {
39 return [
40 [
41 'label' => rex_i18n::msg('cronjob_type_phpcode'),
42 'name' => 'code',
43 'type' => 'textarea',
44 'attributes' => ['rows' => 20, 'class' => 'form-control rex-code rex-js-code', 'spellcheck' => 'false'],
45 ],
46 ];
47 }
48 }
49