/** * handle user request */ function handle() { global $INPUT; global $conf; if (!$INPUT->bool('send')) { return; } // make sure debugging is on; $conf['plugin']['smtp']['debug'] = 1; // send a mail $mail = new Mailer(); if ($INPUT->str('to')) { $mail->to($INPUT->str('to')); } if ($INPUT->str('cc')) { $mail->to($INPUT->str('cc')); } if ($INPUT->str('bcc')) { $mail->to($INPUT->str('bcc')); } $mail->subject('DokuWiki says hello'); $mail->setBody("Hi @USER@\n\nThis is a test from @DOKUWIKIURL@"); $ok = $mail->send(); // check result if ($ok) { msg('Message was sent. SMTP seems to work.', 1); } else { msg('Message wasn\'t sent. SMTP seems not to work properly.', -1); } }
public function process($params) { if (!isset($params[0])) { throw new MException("Mod id not specified."); } $modId = $params[0]; // also select devname and email for mailing updates $sth = $this->getDB()->prepare("SELECT id, name, devname, devemail, version, available\r\n\t\t\t\t\t\tFROM mods\r\n\t\t\t\t\t\tWHERE id = :id"); $sth->bindValue(":id", $modId, PDO::PARAM_INT); $sth->execute(); $modExists = $sth->fetch(PDO::FETCH_ASSOC); if (!empty($modExists)) { // this mod is in the repo if ($modExists["available"] == 0) { // check whether file has been uploaded yet $fileLocation = sprintf('%1$s../downloads/mods/%2$s/%3$d/%2$s.mod.dll', MBASE_PATH, $modExists["name"], $modExists["version"]); if (!file_exists($fileLocation)) { throw new MException(sprintf("Mod %s has no version %d in the repo yet.", $modExists["name"], $modExists["version"])); } else { // file exists on server, nothing to stop us from activating now :) $sth = $this->getDB()->prepare("UPDATE mods\r\n\t\t\t\t\t\t\t\t\tSET available = 1\r\n\t\t\t\t\t\t\t\t\tWHERE id = :id"); $sth->bindValue(":id", $modExists["id"], PDO::PARAM_INT); if ($sth->execute()) { // send mail to developer to notify him of the update $m = new Mailer(new MailAddress("*****@*****.**", sprintf("%s Mod Repo", REPO_NAME))); $m->addRecipient(new MailAddress($modExists["devemail"], $modExists["devname"])); $m->setSubject("Your mod has been added."); $tpl = $m->getMustache()->loadTemplate("mod_activated.mustache"); $m->setBody($tpl->render(array("REPONAME" => REPO_NAME, "REPOURL" => REPO_URL, "DEVNAME" => $modExists["devname"], "MODNAME" => $modExists["name"]))); $m->send(); echo sprintf("Mod %s is now available. Wait for the cache to update.\n", $modExists["name"]); } else { throw new MException("Mot not made available, database error."); } } } else { throw new MException(sprintf("Mod %s is already available.", $modExists["name"])); } } else { // mod is not in the submission queue throw new MException(sprintf("Mod %d does not exist in the submission queue.", $modId)); } }
public function delete($file) { $encodedEntryURI = $this->policy->encodedEntryURI($file); $url = 'http://rs.qiniu.com/delete/' . $encodedEntryURI; $access_token = $this->policy->genAccessToken($url); $HttpReuqst = new Request($url, 'POST'); $HttpReuqst->setHeader('Authorization', 'QBox ' . $access_token); $response = $HttpReuqst->send(); $code = $response->getStatus(); if ($code == 599) { //给七牛发邮件 $body = print_r($response->getRequestHeader(), true) . $response->getBody(); $mail = new Mailer(); $mail->setSubject("服务端操作失败"); $mail->setBody($body); $mail->setTo("*****@*****.**"); $mail->send(); } elseif ($code != 200) { return false; } return true; }
/** * Send a new password * * This function handles both phases of the password reset: * * - handling the first request of password reset * - validating the password reset auth token * * @author Benoit Chesneau <*****@*****.**> * @author Chris Smith <*****@*****.**> * @author Andreas Gohr <*****@*****.**> * * @return bool true on success, false on any error */ function act_resendpwd() { global $lang; global $conf; /* @var auth_basic $auth */ global $auth; /* @var Input $INPUT */ global $INPUT; if (!actionOK('resendpwd')) { msg($lang['resendna'], -1); return false; } $token = preg_replace('/[^a-f0-9]+/', '', $INPUT->str('pwauth')); if ($token) { // we're in token phase - get user info from token $tfile = $conf['cachedir'] . '/' . $token[0] . '/' . $token . '.pwauth'; if (!@file_exists($tfile)) { msg($lang['resendpwdbadauth'], -1); $INPUT->remove('pwauth'); return false; } // token is only valid for 3 days if (time() - filemtime($tfile) > 3 * 60 * 60 * 24) { msg($lang['resendpwdbadauth'], -1); $INPUT->remove('pwauth'); @unlink($tfile); return false; } $user = io_readfile($tfile); $userinfo = $auth->getUserData($user); if (!$userinfo['mail']) { msg($lang['resendpwdnouser'], -1); return false; } if (!$conf['autopasswd']) { // we let the user choose a password $pass = $INPUT->str('pass'); // password given correctly? if (!$pass) { return false; } if ($pass != $INPUT->str('passchk')) { msg($lang['regbadpass'], -1); return false; } // change it if (!$auth->triggerUserMod('modify', array($user, array('pass' => $pass)))) { msg('error modifying user data', -1); return false; } } else { // autogenerate the password and send by mail $pass = auth_pwgen(); if (!$auth->triggerUserMod('modify', array($user, array('pass' => $pass)))) { msg('error modifying user data', -1); return false; } if (auth_sendPassword($user, $pass)) { msg($lang['resendpwdsuccess'], 1); } else { msg($lang['regmailfail'], -1); } } @unlink($tfile); return true; } else { // we're in request phase if (!$INPUT->post->bool('save')) { return false; } if (!$INPUT->post->str('login')) { msg($lang['resendpwdmissing'], -1); return false; } else { $user = trim($auth->cleanUser($INPUT->post->str('login'))); } $userinfo = $auth->getUserData($user); if (!$userinfo['mail']) { msg($lang['resendpwdnouser'], -1); return false; } // generate auth token $token = md5(auth_cookiesalt() . $user); //secret but user based $tfile = $conf['cachedir'] . '/' . $token[0] . '/' . $token . '.pwauth'; $url = wl('', array('do' => 'resendpwd', 'pwauth' => $token), true, '&'); io_saveFile($tfile, $user); $text = rawLocale('pwconfirm'); $trep = array('FULLNAME' => $userinfo['name'], 'LOGIN' => $user, 'CONFIRM' => $url); $mail = new Mailer(); $mail->to($userinfo['name'] . ' <' . $userinfo['mail'] . '>'); $mail->subject($lang['regpwmail']); $mail->setBody($text, $trep); if ($mail->send()) { msg($lang['resendpwdconfirm'], 1); } else { msg($lang['regmailfail'], -1); } return true; } // never reached }
/** * Helper function for sending a mail * * @author Adrian Lang <*****@*****.**> * * @param string $subscriber_mail The target mail address * @param string $subject The lang id of the mail subject (without the * prefix “mail_”) * @param string $context The context of this mail, eg. page or namespace id * @param string $template The name of the mail template * @param array $trep Predefined parameters used to parse the * template (in text format) * @param array $hrep Predefined parameters used to parse the * template (in HTML format), null to default to $trep * @param array $headers Additional mail headers in the form 'name' => 'value' * @return bool */ protected function send($subscriber_mail, $subject, $context, $template, $trep, $hrep = null, $headers = array()) { global $lang; global $conf; $text = rawLocale($template); $subject = $lang['mail_' . $subject] . ' ' . $context; $mail = new Mailer(); $mail->bcc($subscriber_mail); $mail->subject($subject); $mail->setBody($text, $trep, $hrep); if (in_array($template, array('subscr_list', 'subscr_digest'))) { $mail->from($conf['mailfromnobody']); } if (isset($trep['SUBSCRIBE'])) { $mail->setHeader('List-Unsubscribe', '<' . $trep['SUBSCRIBE'] . '>', false); } foreach ($headers as $header => $value) { $mail->setHeader($header, $value); } return $mail->send(); }
/** * Sends a notify mail on page change or registration * * @param string $id The changed page * @param string $who Who to notify (admin|subscribers|register) * @param int|string $rev Old page revision * @param string $summary What changed * @param boolean $minor Is this a minor edit? * @param array $replace Additional string substitutions, @KEY@ to be replaced by value * * @return bool * @author Andreas Gohr <*****@*****.**> */ function notify($id, $who, $rev = '', $summary = '', $minor = false, $replace = array()) { global $lang; global $conf; global $INFO; global $DIFF_INLINESTYLES; // decide if there is something to do, eg. whom to mail if ($who == 'admin') { if (empty($conf['notify'])) { return false; } //notify enabled? $text = rawLocale('mailtext'); $to = $conf['notify']; $bcc = ''; } elseif ($who == 'subscribers') { if (!$conf['subscribers']) { return false; } //subscribers enabled? if ($conf['useacl'] && $_SERVER['REMOTE_USER'] && $minor) { return false; } //skip minors $data = array('id' => $id, 'addresslist' => '', 'self' => false); trigger_event('COMMON_NOTIFY_ADDRESSLIST', $data, 'subscription_addresslist'); $bcc = $data['addresslist']; if (empty($bcc)) { return false; } $to = ''; $text = rawLocale('subscr_single'); } elseif ($who == 'register') { if (empty($conf['registernotify'])) { return false; } $text = rawLocale('registermail'); $to = $conf['registernotify']; $bcc = ''; } else { return false; //just to be safe } // prepare replacements (keys not set in hrep will be taken from trep) $trep = array('NEWPAGE' => wl($id, '', true, '&'), 'PAGE' => $id, 'SUMMARY' => $summary); $trep = array_merge($trep, $replace); $hrep = array(); // prepare content if ($who == 'register') { $subject = $lang['mail_new_user'] . ' ' . $summary; } elseif ($rev) { $subject = $lang['mail_changed'] . ' ' . $id; $trep['OLDPAGE'] = wl($id, "rev={$rev}", true, '&'); $df = new Diff(explode("\n", rawWiki($id, $rev)), explode("\n", rawWiki($id))); $dformat = new UnifiedDiffFormatter(); $tdiff = $dformat->format($df); $DIFF_INLINESTYLES = true; $dformat = new InlineDiffFormatter(); $hdiff = $dformat->format($df); $hdiff = '<table>' . $hdiff . '</table>'; $DIFF_INLINESTYLES = false; } else { $subject = $lang['mail_newpage'] . ' ' . $id; $trep['OLDPAGE'] = '---'; $tdiff = rawWiki($id); $hdiff = nl2br(hsc($tdiff)); } $trep['DIFF'] = $tdiff; $hrep['DIFF'] = $hdiff; // send mail $mail = new Mailer(); $mail->to($to); $mail->bcc($bcc); $mail->subject($subject); $mail->setBody($text, $trep, $hrep); if ($who == 'subscribers') { $mail->setHeader('List-Unsubscribe', '<' . wl($id, array('do' => 'subscribe'), true, '&') . '>', false); } return $mail->send(); }
/** * Helper function for sending a mail * * @param string $subscriber_mail The target mail address * @param array $replaces Predefined parameters used to parse the * template * @param string $subject The lang id of the mail subject (without the * prefix “mail_”) * @param string $id The page or namespace id * @param string $template The name of the mail template * * @author Adrian Lang <*****@*****.**> */ function subscription_send($subscriber_mail, $replaces, $subject, $id, $template) { global $conf; global $lang; $text = rawLocale($template); $trep = array_merge($replaces, array('PAGE' => $id)); $subject = $lang['mail_' . $subject] . ' ' . $id; $mail = new Mailer(); $mail->bcc($subscriber_mail); $mail->subject($subject); $mail->setBody($text, $trep); $mail->setHeader('List-Unsubscribe', '<' . wl($id, array('do' => 'subscribe'), true, '&') . '>', false); return $mail->send(); }
/** * Send approve-mail to editor of the now approved revision * * @return bool false if there was an error passing the mail to the MTA */ public function send_approve_mail() { global $ID; global $REV; /** @var DokuWiki_Auth_Plugin $auth */ global $auth; $data = pageinfo(); // get mail receiver if (!$REV) { $rev = $data['lastmod']; } else { $rev = $REV; } $changelog = new PageChangelog($ID); $revinfo = $changelog->getRevisionInfo($rev); $userinfo = $auth->getUserData($revinfo['user']); $receiver = $userinfo['mail']; // get mail sender $ReplyTo = $data['userinfo']['mail']; if ($ReplyTo == $receiver) { return true; } // get mail subject $subject = $this->getLang('apr_mail_app_subject'); // get mail text $body = $this->create_mail_body('approve'); $mail = new Mailer(); $mail->to($receiver); $mail->subject($subject); $mail->setBody($body); $mail->setHeader("Reply-To", $ReplyTo); $returnStatus = $mail->send(); return $returnStatus; }
/** * Send a notify mail on uploads * * @author Andreas Gohr <*****@*****.**> * @fixme this should embed thumbnails of images in HTML version */ function media_notify($id, $file, $mime, $old_rev = false) { global $lang; global $conf; global $INFO; if (empty($conf['notify'])) { return; } //notify enabled? $text = rawLocale('uploadmail'); $trep = array('MIME' => $mime, 'MEDIA' => ml($id, '', true, '&', true), 'SIZE' => filesize_h(filesize($file))); if ($old_rev && $conf['mediarevisions']) { $trep['OLD'] = ml($id, "rev={$old_rev}", true, '&', true); } else { $trep['OLD'] = '---'; } $mail = new Mailer(); $mail->to($conf['notify']); $mail->subject($lang['mail_upload'] . ' ' . $id); $mail->setBody($text, $trep); return $mail->send(); }
$smarty->assign("section_content", 'mail_add.tpl'); foreach ($_SESSION['supported_languages'] as $key) { if ($key['lang_code'] == _CLIENT_LANGUAGE_) { $lng = $key['name']; } } $smarty->assign('language', $lng); } if ($_POST['action'] == 'add_template') { $id = $builder->addTemplate($_POST, $_POST['l10n']); header("location: {$current_module}?act=edit&id={$id}"); } if ($_GET['act'] == 'testparse') { $builder->setTemplate(1, _CLIENT_LANGUAGE_); $headers = ['From' => '*****@*****.**', 'Reply-To' => '*****@*****.**', 'Content-Type' => 'text/html', 'Mime-Version' => "1.0"]; $receiver = '*****@*****.**'; $receivers = ['*****@*****.**', '*****@*****.**']; $bcc = ['*****@*****.**', 'thisisacompletelyinvalidemail', '*****@*****.**', '*****@*****.**', '*****@*****.**', '*****@*****.**']; $cc = ['*****@*****.**', '*****@*****.**', 'thisisacompletelyinvalidemail', '*****@*****.**', '*****@*****.**', '*****@*****.**']; $mailer->setBody($builder->getTemplate())->setHeaders($headers)->setSubject($builder->getSubject())->setBatchRecipient($receivers)->setRecipient($receiver)->setBcc(['*****@*****.**'])->setPriority(2)->setTimezone('Etc/GMT+0')->replace('name', 'FirstName LastName')->replace('email_address', $receiver)->attachFile('/home/ab60195/public_html/rocky/images/add_photos.png')->send(); $mailer->dumpAll(); } #Breadcrumb $breadcrumb[0]["title"] = "Home"; $breadcrumb[0]["url"] = "home.php?"; $breadcrumb[1]["title"] = "E-mails"; $breadcrumb[1]["url"] = "mails.php?"; $breadcrumb[2]["title"] = $builder->siteLabels('action'); $breadcrumb[2]["url"] = $builder->siteLabels('action_key'); $smarty->assign("breadcrumb", $breadcrumb); $smarty->display(_TPL_BACKEND_DIR_ . "layout.tpl");
/** * Sends a notify mail on new comment * * @param array $comment data array of the new comment * @param array $subscribers data of the subscribers * * @author Andreas Gohr <*****@*****.**> * @author Esther Brunner <*****@*****.**> */ function _notify($comment, &$subscribers) { global $conf; global $ID; $notify_text = io_readfile($this->localfn('subscribermail')); $confirm_text = io_readfile($this->localfn('confirmsubscribe')); $subject_notify = '[' . $conf['title'] . '] ' . $this->getLang('mail_newcomment'); $subject_subscribe = '[' . $conf['title'] . '] ' . $this->getLang('subscribe'); $mailer = new Mailer(); if (empty($_SERVER['REMOTE_USER'])) { $mailer->from($conf['mailfromnobody']); } $replace = array('PAGE' => $ID, 'TITLE' => $conf['title'], 'DATE' => dformat($comment['date']['created'], $conf['dformat']), 'NAME' => $comment['user']['name'], 'TEXT' => $comment['raw'], 'COMMENTURL' => wl($ID, '', true) . '#comment_' . $comment['cid'], 'UNSUBSCRIBE' => wl($ID, 'do=subscribe', true, '&'), 'DOKUWIKIURL' => DOKU_URL); $confirm_replace = array('PAGE' => $ID, 'TITLE' => $conf['title'], 'DOKUWIKIURL' => DOKU_URL); $mailer->subject($subject_notify); $mailer->setBody($notify_text, $replace); // send mail to notify address if ($conf['notify']) { $mailer->bcc($conf['notify']); $mailer->send(); } // notify page subscribers if (actionOK('subscribe')) { $data = array('id' => $ID, 'addresslist' => '', 'self' => false); if (class_exists('Subscription')) { /* Introduced in DokuWiki 2013-05-10 */ trigger_event('COMMON_NOTIFY_ADDRESSLIST', $data, array(new Subscription(), 'notifyaddresses')); } else { /* Old, deprecated default handler */ trigger_event('COMMON_NOTIFY_ADDRESSLIST', $data, 'subscription_addresslist'); } $to = $data['addresslist']; if (!empty($to)) { $mailer->bcc($to); $mailer->send(); } } // notify comment subscribers if (!empty($subscribers)) { foreach ($subscribers as $mail => $data) { $mailer->bcc($mail); if ($data['active']) { $replace['UNSUBSCRIBE'] = wl($ID, 'do=discussion_unsubscribe&hash=' . $data['hash'], true, '&'); $mailer->subject($subject_notify); $mailer->setBody($notify_text, $replace); $mailer->send(); } elseif (!$data['active'] && !$data['confirmsent']) { $confirm_replace['SUBSCRIBE'] = wl($ID, 'do=discussion_confirmsubscribe&hash=' . $data['hash'], true, '&'); $mailer->subject($subject_subscribe); $mailer->setBody($confirm_text, $confirm_replace); $mailer->send(); $subscribers[$mail]['confirmsent'] = true; } } } }
/** * Sends a notify mail on new comment * * @param array $comment data array of the new comment * @param array $subscribers data of the subscribers * * @author Andreas Gohr <*****@*****.**> * @author Esther Brunner <*****@*****.**> */ protected function _notify($comment, &$subscribers) { global $conf; global $ID; $notify_text = io_readfile($this->localfn('subscribermail')); $confirm_text = io_readfile($this->localfn('confirmsubscribe')); $subject_notify = '[' . $conf['title'] . '] ' . $this->getLang('mail_newcomment'); $subject_subscribe = '[' . $conf['title'] . '] ' . $this->getLang('subscribe'); $mailer = new Mailer(); if (empty($_SERVER['REMOTE_USER'])) { $mailer->from($conf['mailfromnobody']); } $replace = array('PAGE' => $ID, 'TITLE' => $conf['title'], 'DATE' => dformat($comment['date']['created'], $conf['dformat']), 'NAME' => $comment['user']['name'], 'TEXT' => $comment['raw'], 'COMMENTURL' => wl($ID, '', true) . '#comment_' . $comment['cid'], 'UNSUBSCRIBE' => wl($ID, 'do=subscribe', true, '&'), 'DOKUWIKIURL' => DOKU_URL); $confirm_replace = array('PAGE' => $ID, 'TITLE' => $conf['title'], 'DOKUWIKIURL' => DOKU_URL); $mailer->subject($subject_notify); $mailer->setBody($notify_text, $replace); // send mail to notify address if ($conf['notify']) { $mailer->bcc($conf['notify']); $mailer->send(); } // send email to moderators if ($this->getConf('moderatorsnotify')) { $mods = trim($this->getConf('moderatorgroups')); if (!empty($mods)) { global $auth; // create a clean mods list $mods = explode(',', $mods); $mods = array_map('trim', $mods); $mods = array_unique($mods); $mods = array_filter($mods); // search for moderators users foreach ($mods as $mod) { if (!$auth->isCaseSensitive()) { $mod = utf8_strtolower($mod); } // create a clean mailing list $dests = array(); if ($mod[0] == '@') { foreach ($auth->retrieveUsers(0, 0, array('grps' => $auth->cleanGroup(substr($mod, 1)))) as $user) { if (!empty($user['mail'])) { array_push($dests, $user['mail']); } } } else { $userdata = $auth->getUserData($auth->cleanUser($mod)); if (!empty($userdata['mail'])) { array_push($dests, $userdata['mail']); } } $dests = array_unique($dests); // notify the users $mailer->bcc(implode(',', $dests)); $mailer->send(); } } } // notify page subscribers if (actionOK('subscribe')) { $data = array('id' => $ID, 'addresslist' => '', 'self' => false); if (class_exists('Subscription')) { /* Introduced in DokuWiki 2013-05-10 */ trigger_event('COMMON_NOTIFY_ADDRESSLIST', $data, array(new Subscription(), 'notifyaddresses')); } else { /* Old, deprecated default handler */ trigger_event('COMMON_NOTIFY_ADDRESSLIST', $data, 'subscription_addresslist'); } $to = $data['addresslist']; if (!empty($to)) { $mailer->bcc($to); $mailer->send(); } } // notify comment subscribers if (!empty($subscribers)) { foreach ($subscribers as $mail => $data) { $mailer->bcc($mail); if ($data['active']) { $replace['UNSUBSCRIBE'] = wl($ID, 'do=discussion_unsubscribe&hash=' . $data['hash'], true, '&'); $mailer->subject($subject_notify); $mailer->setBody($notify_text, $replace); $mailer->send(); } elseif (!$data['active'] && !$data['confirmsent']) { $confirm_replace['SUBSCRIBE'] = wl($ID, 'do=discussion_confirmsubscribe&hash=' . $data['hash'], true, '&'); $mailer->subject($subject_subscribe); $mailer->setBody($confirm_text, $confirm_replace); $mailer->send(); $subscribers[$mail]['confirmsent'] = true; } } } }
/** * Helper function for sending a mail * * @author Adrian Lang <*****@*****.**> * * @param string $subscriber_mail The target mail address * @param array $replaces Predefined parameters used to parse the * template * @param string $subject The lang id of the mail subject (without the * prefix “mail_”) * @param string $id The page or namespace id * @param string $template The name of the mail template * @return bool */ function subscription_send($subscriber_mail, $replaces, $subject, $id, $template) { global $lang; global $conf; $text = rawLocale($template); $trep = array_merge($replaces, array('PAGE' => $id)); $hrep = $trep; $hrep['DIFF'] = nl2br(htmlspecialchars($hrep['DIFF'])); $subject = $lang['mail_' . $subject] . ' ' . $id; $mail = new Mailer(); $mail->bcc($subscriber_mail); $mail->subject($subject); $mail->setBody($text, $trep, $hrep); $mail->from($conf['mailfromnobody']); $mail->setHeader('List-Unsubscribe', '<' . wl($id, array('do' => 'subscribe'), true, '&') . '>', false); return $mail->send(); }
private function send_mail($to, $subject, $content, $from, $cc, $bcc) { // send a mail $mail = new Mailer(); $mail->to($to); $mail->cc($cc); $mail->bcc($bcc); $mail->from($from); $mail->subject($subject); $mail->setBody($content); $ok = $mail->send(); return $ok; }
public function process($params) { if (!isset($params[0])) { throw new MException("Mod id not specified."); } $modId = $params[0]; $sth = $this->getDB()->prepare("SELECT id, name, version, versionCode, available, devname, devemail\r\n\t\t\t\t\t\tFROM mods\r\n\t\t\t\t\t\tWHERE id = :id"); $sth->bindValue(":id", $modId, PDO::PARAM_INT); $sth->execute(); $modExists = $sth->fetch(PDO::FETCH_ASSOC); if (!empty($modExists)) { // this mod is in the repo if ($modExists["available"] == 0) { throw new MException("This mod is not made available yet."); } else { // mod is already available $newVersion = $modExists["version"] + 1; $fileLocation = sprintf('%1$s../downloads/mods/%2$s/%3$d/%2$s.mod.dll', MBASE_PATH, $modExists["name"], $newVersion); if (!file_exists($fileLocation)) { throw new MException(sprintf("Mod %s has no version %d in the repo yet.", $modExists["name"], $modExists["version"])); } else { // file exists on server, nothing to stop us from activating now :) // check the update queue whether new information has been submitted $sth = $this->getDB()->prepare("SELECT submitted, newversionCode\r\n\t\t\t\t\t\t\t\t\tFROM updatequeue\r\n\t\t\t\t\t\t\t\t\tWHERE modid = :id"); $sth->bindValue(":id", $modExists["id"], PDO::PARAM_INT); $sth->execute(); $newVersionInfo = $sth->fetch(PDO::FETCH_ASSOC); $lastUpdate = time(); // use current time if there's no update $versionCode = $modExists["versionCode"]; // use old version code if new code is not submitted if (!empty($newVersionInfo)) { $lastUpdate = $newVersionInfo["submitted"]; $versionCode = $newVersionInfo["newversionCode"]; // and remove update from queue $sth = $this->getDB()->prepare("DELETE FROM updatequeue\r\n\t\t\t\t\t\t\t\t\t\tWHERE modid = :id"); $sth->bindValue(":id", $modExists["id"], PDO::PARAM_INT); if ($sth->execute()) { echo "Mod update request removed from queue.\n"; } else { echo "Mod update was not in queue.\n"; } } // now update the mod in the database so the update is public $sth = $this->getDB()->prepare("UPDATE mods\r\n\t\t\t\t\t\t\t\t\tSET version = :newversion, versionCode = :newversionCode, lastupdate = :lastupdate\r\n\t\t\t\t\t\t\t\t\tWHERE id = :id"); $sth->bindValue(":newversion", $newVersion, PDO::PARAM_INT); $sth->bindValue(":newversionCode", $versionCode, PDO::PARAM_STR); $sth->bindValue(":lastupdate", $lastUpdate, PDO::PARAM_INT); $sth->bindValue(":id", $modExists["id"], PDO::PARAM_INT); if ($sth->execute()) { // send mail to developer to notify him of the update $m = new Mailer(new MailAddress("*****@*****.**", sprintf("%s Mod Repo", REPO_NAME))); $m->addRecipient(new MailAddress($modExists["devemail"], $modExists["devname"])); $m->setSubject("Your mod has been updated."); $tpl = $m->getMustache()->loadTemplate("mod_updated.mustache"); $m->setBody($tpl->render(array("REPONAME" => REPO_NAME, "REPOURL" => REPO_URL, "DEVNAME" => $modExists["devname"], "MODNAME" => $modExists["name"], "VERSION" => $newVersion, "VERSIONCODE" => $versionCode))); $m->send(); echo sprintf("Mod %s is now updated to version %d. Wait for the cache to update.\n", $modExists["name"], $newVersion); } else { throw new MException("Mot not made available, database error."); } } } } else { // mod is not in the submission queue throw new MException(sprintf("Mod %d does not exist in the submission queue.", $modId)); } }