/** * Constructor * * @param array $prefs - pref settings for PM plugin * @return none */ public function __construct($prefs, $manager) { $this->pmManager = $manager; parent::__construct($prefs); }
public function __construct() { $pm_prefs = e107::getPlugPref('pm'); $this->pmManager = new pmbox_manager($pm_prefs); $this->pmPrefs = $pm_prefs; // print_a($pm_prefs); require_once e_PLUGIN . "pm/pm_class.php"; $pmClass = new private_message($pm_prefs); $blocks = $pmClass->block_get_user(); foreach ($blocks as $usr) { if ($usr['pm_block_to'] == USERID) { $this->pmBlocks[] = $usr['pm_block_from']; } } }
/** * Do PM DB maintenance * @param array $opts of tasks key = sent|rec|blocked|expired (one or more present). ATM value not used * @return array where key is message type (E_MESSAGE_SUCCESS|E_MESSAGE_ERROR|E_MESSAGE_INFO etc), data is array of messages of that type (key = timestamp) */ function doMaint($opts, $pmPrefs) { if (!count($opts)) { return array(E_MESSAGE_ERROR => array(ADLAN_PM_66)); } $results = array(E_MESSAGE_INFO => array(ADLAN_PM_67)); // 'Maintenance started' - primarily for a log entry to mark start time $logResults = array(); $e107 = e107::getInstance(); $e107->admin_log->log_event('PM_ADM_04', implode(', ', array_keys($opts))); $pmHandler = new private_message($pmPrefs); $db2 = new db(); // Will usually need a second DB object to avoid over load $start = 0; // Use to ensure we get different log times if (isset($opts['sent'])) { $cnt = 0; if ($res = $db2->gen("SELECT pm.pm_id FROM `#private_msg` AS pm LEFT JOIN `#user` AS u ON pm.`pm_from` = `#user`.`user_id`\n\t\t\t\t\tWHERE (pm.`pm_read_del = 1) AND `#user`.`user_id` IS NULL")) { while ($row = $db2->fetch(MYSQL_ASSOC)) { if ($pmHandler->del($row['pm_id']) !== FALSE) { $cnt++; } } } $start = time(); $results[E_MESSAGE_SUCCESS][$start] = str_replace('--COUNT--', $cnt, ADLAN_PM_74); } if (isset($opts['rec'])) { $cnt = 0; if ($res = $db2->gen("SELECT pm.pm_id FROM `#private_msg` AS pm LEFT JOIN `#user` AS u ON pm.`pm_to` = `#user`.`user_id`\n\t\t\t\t\tWHERE (pm.`pm_sent_del = 1) AND `#user`.`user_id` IS NULL")) { while ($row = $db2->fetch(MYSQL_ASSOC)) { if ($pmHandler->del($row['pm_id']) !== FALSE) { $cnt++; } } } $start = max($start + 1, time()); $results[E_MESSAGE_SUCCESS][$start] = str_replace('--COUNT--', $cnt, ADLAN_PM_75); } if (isset($opts['blocked'])) { if ($res = $db2->gen("DELETE `#private_msg_block` FROM `#private_msg_block` LEFT JOIN `#user` ON `#private_msg_block`.`pm_block_from` = `#user`.`user_id`\n\t\t\t\t\tWHERE `#user`.`user_id` IS NULL")) { $start = max($start + 1, time()); $results[E_MESSAGE_ERROR][$start] = str_replace(array('--NUM--', '--TEXT--'), array($this->sql->getLastErrorNum, $this->sql->getLastErrorText), ADLAN_PM_70); } else { $start = max($start + 1, time()); $results[E_MESSAGE_SUCCESS][$start] = str_replace('--COUNT--', $res, ADLAN_PM_69); } if ($res = $db2->gen("DELETE `#private_msg_block` FROM `#private_msg_block` LEFT JOIN `#user` ON `#private_msg_block`.`pm_block_to` = `#user`.`user_id`\n\t\t\t\t\tWHERE `#user`.`user_id` IS NULL")) { $start = max($start + 1, time()); $results[E_MESSAGE_ERROR][$start] = str_replace(array('--NUM--', '--TEXT--'), array($this->sql->getLastErrorNum, $this->sql->getLastErrorText), ADLAN_PM_70); } else { $start = max($start + 1, time()); $results[E_MESSAGE_SUCCESS][$start] = str_replace('--COUNT--', $res, ADLAN_PM_68); } } if (isset($opts['expired'])) { $del_qry = array(); $read_timeout = intval($pmPrefs['read_timeout']); $unread_timeout = intval($pmPrefs['unread_timeout']); if ($read_timeout > 0) { $timeout = time() - $read_timeout * 86400; $del_qry[] = "(pm_sent < {$timeout} AND pm_read > 0)"; } if ($unread_timeout > 0) { $timeout = time() - $unread_timeout * 86400; $del_qry[] = "(pm_sent < {$timeout} AND pm_read = 0)"; } if (count($del_qry) > 0) { $qry = implode(' OR ', $del_qry); $cnt = 0; if ($db2->db_Select('private_msg', 'pm_id', $qry)) { while ($row = $db2->db_Fetch(MYSQL_ASSOC)) { if ($pmHandler->del($row['pm_id']) !== FALSE) { $cnt++; } } } $start = max($start + 1, time()); $results[E_MESSAGE_SUCCESS][$start] = str_replace('--COUNT--', $cnt, ADLAN_PM_73); } else { $start = max($start + 1, time()); $results[E_MESSAGE_ERROR][$start] = ADLAN_PM_72; } } if (isset($opts['attach'])) { // Check for orphaned and missing attachments require_once e_HANDLER . 'file_class.php'; $fl = new e_file(); $missing = array(); $orphans = array(); $fileArray = $fl->get_files(e_PLUGIN . 'pm/attachments'); if ($db2->select('private_msg', 'pm_id, pm_attachments', "pm_attachments != ''")) { while ($row = $db2->fetch(MYSQL_ASSOC)) { $attachList = explode(chr(0), $row['pm_attachments']); foreach ($attachList as $a) { $found = FALSE; foreach ($fileArray as $k => $fd) { if ($fd['fname'] == $a) { $found = TRUE; unset($fileArray[$k]); break; } } if (!$found) { $missing[] = $row['pm_id'] . ':' . $a; } } } } // Any files left in $fileArray now are unused if (count($fileArray)) { foreach ($fileArray as $k => $fd) { unlink($fd['path'] . $fd['fname']); $orphans[] = $fd['fname']; } } $attachMessage = str_replace(array('--ORPHANS--', '--MISSING--'), array(count($orphans), count($missing)), ADLAN_PM_79); if (TRUE) { // Mostly for testing - probably disable this if (count($orphans)) { $attachMessage .= '[!br!]Orphans:[!br!]' . implode('[!br!]', $orphans); } if (count($missing)) { $attachMessage .= '[!br!]Missing:[!br!]' . implode('[!br!]', $missing); } } $start = max($start + 1, time()); $results[E_MESSAGE_SUCCESS][$start] = $attachMessage; } $e107->admin_log->logArrayAll('PM_ADM_03', makeLogEntry($results)); foreach ($results as $k => $r) { foreach ($r as $sk => $s) { $results[$k][$sk] = str_replace('[!br!]', '<br />', $s); } } return $results; }
/** * Send a notification to one or more users. * <p>Current implementation just sends a Private Message, so the PM plugin must be enabled.</p> * @param sendto an array of userid(s) or a sinle userclass (not array) to send notifications to * @param subject the subject of the message * @param message the message itself * @param fromid id of user sending PM (they will get a copy in theor outbox), defaults to 0 (no user) * @return TBC * @TODO add option to PM multiple users * @TODO add option to PM a userclass * @TODO proper return values * @TODO localization */ function sendNotification($sendto, $subject, $message, $fromid = 0) { global $sql, $pm_prefs, $pm, $pref, $sysprefs, $tp; // Include Private Message class if not already defined if (!class_exists("private_message")) { if (file_exists(e_PLUGIN . "pm/pm_class.php")) { require_once e_PLUGIN . "pm/pm_class.php"; include_lan(e_PLUGIN . 'pm/languages/' . e_LANGUAGE . '.php'); } else { return; } } //fm: Remove this comment to use PMs preferences (email notification userclass...) //$pm_prefs = $sysprefs->getArray("pm_prefs"); /* // Check user is allowed to send PMs if (!check_class($pm_prefs['pm_class'])) { return NOT_AUTHORIZED; } */ /* // Annotate message with senders details if (USERID !== false) { $message = "Notification from ".USERNAME."\n\n".$message; } else { $message = "Notification from Guest\n\n".$message; } */ $pm = new private_message(); // Array of userids to PM if (!$sql->db_Select("user", "user_id, user_name, user_class, user_email", "user_id={$sendto}")) { return USER_NOT_FOUND; } $touser = $sql->db_Fetch(); $vars = array("pm_subject" => $subject, "pm_message" => $message, "from_id" => $fromid, "to_info" => array("user_id" => $touser["user_id"], "user_name" => $touser["user_name"], "user_class" => $touser["user_class"], "user_email" => $touser["user_email"])); return $pm->add($vars); }