Overview

Packages

  • CONTENIDO
  • Core
    • Authentication
    • Backend
    • Cache
    • CEC
    • Chain
    • ContentType
    • Database
    • Debug
    • Exception
    • Frontend
      • Search
      • URI
      • Util
    • GenericDB
      • Model
    • GUI
      • HTML
    • I18N
    • LayoutHandler
    • Log
    • Security
    • Session
    • Util
    • Validation
    • Versioning
    • XML
  • Module
    • ContentSitemapHtml
    • ContentSitemapXml
    • ContentUserForum
    • NavigationTop
    • ScriptCookieDirective
  • mpAutoloaderClassMap
  • None
  • PHP
  • Plugin
    • ContentAllocation
    • CronjobOverview
    • FormAssistant
    • FrontendLogic
    • FrontendUsers
    • Linkchecker
    • ModRewrite
    • Newsletter
    • Repository
      • FrontendNavigation
      • KeywordDensity
    • SmartyWrapper
    • UrlShortener
    • UserForum
    • Workflow
  • PluginManager
  • Setup
    • Form
    • GUI
    • Helper
      • Environment
      • Filesystem
      • MySQL
      • PHP
    • UpgradeJob

Classes

  • Cronjobs
  • Overview
  • Package
  • Class
  • Tree
  • Deprecated
  • Todo
  1: <?php
  2: /**
  3:  * This file contains the main class for the plugin content allocation.
  4:  *
  5:  * @package    Plugin
  6:  * @subpackage CronjobOverview
  7:  * @author     Rusmir Jusufovic
  8:  * @copyright  four for business AG <www.4fb.de>
  9:  * @license    http://www.contenido.org/license/LIZENZ.txt
 10:  * @link       http://www.4fb.de
 11:  * @link       http://www.contenido.org
 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:  * Main class for cronjob overview
 20:  *
 21:  * @package    Plugin
 22:  * @subpackage CronjobOverview
 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:      * @var string
 33:      */
 34:     protected $_phpFile = '';
 35: 
 36:     /**
 37:      * Filename without the mimetype
 38:      * @var string
 39:      */
 40:     private $_fileName = '';
 41: 
 42:     /**
 43:      * Path to the cronjob Directory
 44:      * @var string (path)
 45:      */
 46:     protected $_cronjobDirectory = '';
 47: 
 48:     /**
 49:      * Path to the cronlog Directory
 50:      * @var string (path)
 51:      */
 52:     protected $_cronlogDirectory = '';
 53: 
 54: 
 55:     public function __construct($phpFile = '') {
 56:         $this->_phpFile = $phpFile;
 57: 
 58:         //get the name of the file withouth the mime type
 59:         if ($phpFile != '') {
 60:             $this->_fileName = cString::getPartOfString($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:      * Return the name of file
 71:      * @return string filename
 72:      */
 73:     public function getFile() {
 74:         return $this->_phpFile;
 75:     }
 76: 
 77:     /**
 78:      *
 79:      * Get the directory path of cronjobs
 80:      * @return string
 81:      */
 82:     public function getCronjobDirectory() {
 83:         return $this->_cronjobDirectory;
 84:     }
 85: 
 86: 
 87:     /**
 88:      * Get the directory path of cronlog
 89:      * @return string
 90:      */
 91:     public function getCronlogDirectory() {
 92:         return $this->_cronlogDirectory;
 93:     }
 94: 
 95:     /**
 96:      *
 97:      * Get date of last execution of cronjob
 98:      * @return string date
 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:      * Get the contents of the crontab.txt file
113:      *
114:      * @return string, contents of the file or ''
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:      * Save the data to crontab.txt file
127:      *
128:      * @param string $data
129:      *
130:      * @return mixed file_put_contents
131:      */
132:     public function saveCrontabFile($data) {
133:         return cFileHandler::write($this->_cronlogDirectory . self::$CRONTAB_FILE, $data);
134:     }
135: 
136:     /**
137:      * Set the execute-time to $this->_phpFile.job file.
138:      *
139:      * @param int $timestamp
140:      */
141:     public function setRunTime($timestamp) {
142:         cFileHandler::write($this->_cronlogDirectory . $this->_phpFile . self::$JOB_ENDING, $timestamp);
143:     }
144:     
145:     /**
146:      * Get the last lines of log file
147:      *
148:      * @param int $lines
149:      *
150:      * @return string, the lines
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:      * Exist the file and is it a php file
170:      *
171:      * @return bool if exist
172:      */
173:     public function existFile() {
174:         if (cFileHandler::exists($this->_cronjobDirectory . $this->_phpFile) && !is_dir($this->_cronjobDirectory . $this->_phpFile)) {
175:             if (cString::getPartOfString($this->_phpFile, -4) == '.php') {
176:                 return true;
177:             } else {
178:                 return false;
179:             }
180:         } else {
181:             return false;
182:         }
183:     }
184: 
185:     /**
186:      *
187:      * Get all Cronjobs in directory cronjobs from contenido
188:      */
189:     public function getAllCronjobs() {
190:         $retArray = array();
191:         
192:         if (is_dir($this->_cronjobDirectory)) {
193:             // get only files
194:             if (false !== ($handle = cDirHandler::read($this->_cronjobDirectory, false, false, true))) {
195:                 foreach ($handle as $file) {
196:                     if (cFileHandler::fileNameIsDot($file) === false
197:                         && cString::getPartOfString($file, -4) == '.php' && $file != 'index.php') {
198:                         $retArray[] = $file;
199:                     }
200:                 }
201:             }
202:         }
203: 
204:         return $retArray;
205:     }
206: }
207: 
208: ?>
CMS CONTENIDO 4.10.0 API documentation generated by ApiGen 2.8.0