Overview

Packages

  • Core
    • Authentication
    • Backend
    • Cache
    • CEC
    • Chain
    • ContentType
    • Database
    • Datatype
    • Debug
    • Exception
    • Frontend
      • Search
      • URI
      • Util
    • GenericDB
      • Model
    • GUI
      • HTML
    • I18N
    • LayoutHandler
    • Log
    • Security
    • Session
    • Util
    • Validation
    • Versioning
    • XML
  • Module
    • ContentSitemapHtml
    • ContentSitemapXml
    • ContentUserForum
    • NavigationTop
  • mpAutoloaderClassMap
  • None
  • Plugin
    • ContentAllocation
    • CronjobOverview
    • FormAssistant
    • FrontendLogic
    • FrontendUsers
    • Linkchecker
    • ModRewrite
    • Newsletter
    • Repository
      • FrontendNavigation
      • KeywordDensity
    • SearchSolr
    • 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:  * TODO: this file needs refactoring.
  6:  *
  7:  * @package    Plugin
  8:  * @subpackage CronjobOverview
  9:  * @version    SVN Revision $Rev:$
 10:  *
 11:  * @author     Rusmir Jusufovic
 12:  * @copyright  four for business AG <www.4fb.de>
 13:  * @license    http://www.contenido.org/license/LIZENZ.txt
 14:  * @link       http://www.4fb.de
 15:  * @link       http://www.contenido.org
 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:  * Main class for cronjob overview
 24:  *
 25:  * @package    Plugin
 26:  * @subpackage CronjobOverview
 27:  */
 28: class Cronjobs {
 29: 
 30: 
 31:     /**
 32:      *
 33:      * All Contenido vars (contenido,lang,cfg,cfgClients ...)
 34:      * @var array
 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:      * Filename without the mimetype
 50:      * @var string
 51:      */
 52:     private $_fileName = '';
 53: 
 54:     protected $_cfg = array();
 55: 
 56:     /**
 57:      * Path to the cronjob Directory
 58:      * @var string (path)
 59:      */
 60:     protected $_cronjobDirectory = '';
 61: 
 62:     /**
 63:      * Path to the cronlog Directory
 64:      * @var string (path)
 65:      */
 66:     protected $_cronlogDirectory = '';
 67: 
 68: 
 69:     public function __construct(array $contenidoVars, $phpFile = '') {
 70:         $this->_conVars = $contenidoVars;
 71:         $this->_phpFile = $phpFile;
 72: 
 73:         //get the name of the file withouth the mime type
 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:      * Return the name of file
 86:      * @return string filename
 87:      */
 88:     public function getFile() {
 89: 
 90:         return $this->_phpFile;
 91:     }
 92: 
 93:     /**
 94:      *
 95:      * Get the directory path of cronjobs
 96:      * @return string
 97:      */
 98:     public function getCronjobDirectory() {
 99:         return $this->_cronjobDirectory;
100:     }
101: 
102: 
103:     /**
104:      * Get the directory path of cronlog
105:      * @return string
106:      */
107:     public function getCronlogDirectory() {
108:         return $this->_cronlogDirectory;
109:     }
110: 
111:     /**
112:      *
113:      * Get date of last execution of cronjob
114:      * @return string date
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:      * Get the contents of the crontab.txt file
130:      *
131:      * @return string, contents of the file or ''
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:      * Save the data to crontab.txt file
144:      *
145:      * @param string $data
146:      *
147:      * @return mixed file_put_contents
148:      */
149:     public function saveCrontabFile($data) {
150: 
151:         return cFileHandler::write($this->_cronlogDirectory . self::$CRONTAB_FILE, $data);
152: 
153:     }
154: 
155:     /**
156:      *
157:      * Set the execute-time to $this->_phpFile.job file.
158:      *
159:      * @param int $timestamp
160:      */
161:     public function setRunTime($timestamp) {
162: 
163:         cFileHandler::write($this->_cronlogDirectory . $this->_phpFile . self::$JOB_ENDING, $timestamp);
164:     }
165: 
166: 
167:     /**
168:      * Get the last lines of log file
169:      *
170:      * @param int $lines
171:      *
172:      * @return string, the lines
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:      * Exist the file and is it a php file
192:      *
193:      * @return bool if exist
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:      * Get all Cronjobs in directory cronjobs from contenido
210:      */
211:     public function getAllCronjobs() {
212: 
213:         $retArray = array();
214:         if (is_dir($this->_cronjobDirectory)) {
215:             if ($dh = opendir($this->_cronjobDirectory)) {
216:                 while (($file = readdir($dh)) !== false) {
217:                     #is file a dir or not
218:                     if ($file != ".." && $file != "." && !is_dir($this->_cronjobDirectory . $file) && substr($file, -4) == '.php' && $file != 'index.php') {
219: 
220:                         $retArray[] = $file;
221:                     }
222:                 }
223:             }
224:         }
225: 
226:         return $retArray;
227: 
228:     }
229: 
230: }
231: 
232: ?>
CMS CONTENIDO 4.9.3 API documentation generated by ApiGen 2.8.0