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