1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12:
13:
14: defined('CON_FRAMEWORK') || die('Illegal call: Missing framework initialization - request aborted.');
15:
16: plugin_include('repository', 'custom/FrontendNavigation.php');
17:
18: 19: 20: 21: 22: 23:
24: class Cronjobs {
25: public static $CRONTAB_FILE = 'crontab.txt';
26:
27: public static $JOB_ENDING = '.job';
28:
29: public static $LOG_ENDING = '.log';
30:
31: 32: 33:
34: protected $_phpFile = '';
35:
36: 37: 38: 39:
40: private $_fileName = '';
41:
42: 43: 44: 45:
46: protected $_cronjobDirectory = '';
47:
48: 49: 50: 51:
52: protected $_cronlogDirectory = '';
53:
54:
55: public function __construct($phpFile = '') {
56: $this->_phpFile = $phpFile;
57:
58:
59: if ($phpFile != '') {
60: $this->_fileName = substr($phpFile, 0, -4);
61: }
62:
63: $cfg = cRegistry::getConfig();
64: $this->_cronjobDirectory = $cfg['path']['contenido'] . $cfg['path']['cronjobs'];
65: $this->_cronlogDirectory = $cfg['path']['contenido_cronlog'];
66: }
67:
68: 69: 70: 71: 72:
73: public function getFile() {
74: return $this->_phpFile;
75: }
76:
77: 78: 79: 80: 81:
82: public function getCronjobDirectory() {
83: return $this->_cronjobDirectory;
84: }
85:
86:
87: 88: 89: 90:
91: public function getCronlogDirectory() {
92: return $this->_cronlogDirectory;
93: }
94:
95: 96: 97: 98: 99:
100: public function getDateLastExecute() {
101: $timestamp = '';
102: if (cFileHandler::exists($this->_cronlogDirectory . $this->_phpFile . self::$JOB_ENDING)) {
103: if (($timestamp = cFileHandler::read($this->_cronlogDirectory . $this->_phpFile . self::$JOB_ENDING))) {
104: return date("d.m.Y H:i:s", $timestamp);
105: }
106: }
107:
108: return $timestamp;
109: }
110:
111: 112: 113: 114: 115:
116: public function getContentsCrontabFile() {
117: if (cFileHandler::exists($this->_cronlogDirectory . self::$CRONTAB_FILE)) {
118: return cFileHandler::read($this->_cronlogDirectory . self::$CRONTAB_FILE);
119: } else {
120: return '';
121: }
122: }
123:
124: 125: 126: 127: 128: 129: 130: 131:
132: public function saveCrontabFile($data) {
133: return cFileHandler::write($this->_cronlogDirectory . self::$CRONTAB_FILE, $data);
134: }
135:
136: 137: 138: 139: 140:
141: public function setRunTime($timestamp) {
142: cFileHandler::write($this->_cronlogDirectory . $this->_phpFile . self::$JOB_ENDING, $timestamp);
143: }
144:
145: 146: 147: 148: 149: 150: 151:
152: public function getLastLines($lines = 25) {
153: if (cFileHandler::exists($this->_cronlogDirectory . $this->_phpFile . self::$LOG_ENDING)) {
154: $content = explode("\n", cFileHandler::read($this->_cronlogDirectory . $this->_phpFile . self::$LOG_ENDING));
155: $number = count($content);
156: $pos = $number - $lines;
157: if ($pos < 0) {
158: $lines += $pos;
159: $pos = 0;
160: }
161:
162: return implode('<br>', array_slice($content, $pos, $lines));
163: }
164:
165: return '';
166: }
167:
168: 169: 170: 171: 172:
173: public function existFile() {
174: if (cFileHandler::exists($this->_cronjobDirectory . $this->_phpFile) && !is_dir($this->_cronjobDirectory . $this->_phpFile)) {
175: if (substr($this->_phpFile, -4) == '.php') {
176: return true;
177: } else {
178: return false;
179: }
180: } else {
181: return false;
182: }
183: }
184:
185: 186: 187: 188:
189: public function getAllCronjobs() {
190: $retArray = array();
191:
192: if (is_dir($this->_cronjobDirectory)) {
193:
194: if (false !== ($handle = cDirHandler::read($this->_cronjobDirectory, false, false, true))) {
195: foreach ($handle as $file) {
196: if (cFileHandler::fileNameIsDot($file) === false
197: && substr($file, -4) == '.php' && $file != 'index.php') {
198: $retArray[] = $file;
199: }
200: }
201: }
202: }
203:
204: return $retArray;
205: }
206: }
207:
208: ?>