1<?php 2/* 3 * e107 website system 4 * 5 * Copyright (C) 2001-2009 e107 Inc (e107.org) 6 * Released under the terms and conditions of the 7 * GNU General Public License (http://www.gnu.org/licenses/gpl.txt) 8 * 9 * Plugin configuration module - gsitemap 10 * 11 * $Source: /cvs_backup/e107_0.8/e107_plugins/pm/e_cron.php,v $ 12 * $Revision$ 13 * $Date$ 14 * $Author$ 15 * 16*/ 17 18/** 19 * e107 Private Messenger plugin 20 * 21 * @package e107_plugins 22 * @subpackage pm 23 * @version $Id$; 24 */ 25 26if (!defined('e107_INIT')) { exit; } 27 28 29e107::includeLan(e_PLUGIN.'/pm/languages/English_mailer.php'); 30 31class pm_cron // include plugin-folder in the name. 32{ 33 private $logRequirement = 0; // Flag to determine logging level 34 private $debugLevel = 0; // Used for internal debugging 35 private $logHandle = NULL; 36 private $pmClass; // Calendar library routines 37 private $e107; 38 private $mailManager; 39 private $ourDB; // Used for some things 40 41 42 public function __construct() 43 { 44 $this->e107 = e107::getInstance(); 45 $this->ourDB = new db; 46 //$this->debugLevel = 2; 47 } 48 49 50 51 /** 52 * Cron configuration 53 * 54 * Defines one or more cron tasks to be performed 55 * 56 * @return array of task arrays 57 */ 58 public function config() 59 { 60 $cron = array(); 61 $cron[] = array( 62 'name' => LAN_EC_PM_04, 63 'category' => 'plugin', 64 'function' => 'processPM', 65 'description' => LAN_EC_PM_05 66 ); 67 return $cron; 68 } 69 70 71 72 /** 73 * Logging routine - writes lines to a text file 74 * 75 * Auto-opens log file (if necessary) on first call 76 * 77 * @param string $logText - body of text to write 78 * @param boolean $closeAfter - if TRUE, log file closed before exit; otherwise left open 79 * 80 * @return none 81 */ 82 function logLine($logText, $closeAfter = FALSE, $addTimeDate = FALSE) 83 { 84 if ($this->logRequirement == 0) return; 85 86 $logFilename = e_LOG.'pm_bulk.txt'; 87 if ($this->logHandle == NULL) 88 { 89 if (!($this->logHandle = fopen($logFilename, "a"))) 90 { // Problem creating file? 91 echo "File open failed!<br />"; 92 $this->logRequirement = 0; 93 return; 94 } 95 } 96 97 if (fwrite($this->logHandle,($addTimeDate ? date('D j M Y G:i:s').': ' : '').$logText."\r\n") == FALSE) 98 { 99 $this->logRequirement = 0; 100 echo 'File write failed!<br />'; 101 } 102 103 if ($closeAfter) 104 { 105 fclose($this->logHandle); 106 $this->logHandle = NULL; 107 } 108 } 109 110 111 112 /** 113 * Called to process outstanding PMs (which are always bulk lists) 114 * 115 * Emails are added to the queue. 116 * Various events are logged in a text file 117 * 118 * @return none 119 */ 120 public function processPM() 121 { 122 global $pref; 123 124 require_once(e_PLUGIN.'pm/pm_class.php'); 125 126 $this->startTime = mktime(0, 0, 0, date('n'), date('d'), date('Y')); // Date for start processing 127 128 $this->logRequirement = varset($pref['eventpost_emaillog'], 0); 129 if ($this->debugLevel >= 2) $this->logRequirement = 2; // Force full logging if debug 130 131 132 // Start of the 'real' code 133 134 if ($this->ourDB->select('generic', '*', "`gen_type` = 'pm_bulk' LIMIT 1")) 135 { 136 $pmRow = $this->ourDB->fetch(); 137 $this->logLine("\r\n\r\n".str_replace('[y]',$pmRow['gen_intdata'],LAN_EC_PM_06).date('D j M Y G:i:s')); 138 139 $this->ourDB->delete('generic', "`gen_type` = 'pm_bulk' AND `gen_id` = ".$pmRow['gen_id']); 140 141 $pmData = e107::unserialize($pmRow['gen_chardata']); 142 unset($pmRow); 143 $this->pmClass = new private_message; 144 $this->pmClass->add($pmData); 145 $this->logLine(' .. Run completed',TRUE, TRUE); 146 } 147 return TRUE; 148 } 149 150 151 152 153 private function checkMailManager() 154 { 155 if ($this->mailManager == NULL) 156 { 157 require_once(e_HANDLER .'mail_manager_class.php'); 158 $this->mailManager = new e107MailManager(); 159 } 160 } 161 162} 163 164 165 166