#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see .
class mailing {
var $email;
var $headers;
var $subject;
var $text;
function sendMail($email, $subject, $text, $notifications = false, $admin = false, $language = false) {
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/plain; charset=UTF-8\r\n";
$headers .= "From: ".NAME." <".ADMIN_MAIL.">";
$text .= $this->bottomMail($notifications, $admin, $language);
mail($email, NAME.' // '.$subject, $text, $headers);
}
function bottomMail($notifications = false, $admin = false, $language = false) {
global $gettext_tables;
if ($language != false) {
if (file_exists(PATH.'locale/'.deflang($userInfo['language']).'/LC_MESSAGES/messages.mo')) {
$gettext_tables = new gettext_reader(
new CachedFileReader(PATH.'locale/'.deflang($userInfo['language']).'/LC_MESSAGES/messages.mo')
);
$gettext_tables->load_tables();
}
}
$return = "\n\n--\n";
if ($admin == false) {
if ($notifications) $return .= str_replace('%notifications_url', BASE.'settings/config', __('Turn off this notifications at %notifications_url'))."\n\n";
if (defined('ABUSE_MAIL')) $return .= str_replace('%admin_mail', ADMIN_MAIL, __('Have you got any problem? Contact the administrator at %admin_mail'));
if (defined('TOS') && (TOS == true)) $return .= str_replace('%tos', BASE.'tos', "\n".str_replace('%name', NAME, __('Since you got registered on %name, you agree with the Terms of Service (TOS) placed in %tos')));
}
else {
$return .= __('Thanks for using Jisko (more info at http://www.jisko.org)');
}
if ($language != false) {
if (file_exists(PATH.'includes/languages/'.deflang(LANG).'/LC_MESSAGES/messages.mo')) {
$gettext_tables = new gettext_reader(
new CachedFileReader(PATH.'includes/languages/'.deflang(LANG).'/LC_MESSAGES/messages.mo')
);
$gettext_tables->load_tables();
}
}
return $return;
}
function forgottenPassword($email, $uid, $token) {
global $gettext_tables;
global $db;
$userInfo = $db->getUserInfo($uid);
if (file_exists(PATH.'includes/languages/'.deflang($userInfo['language']).'/LC_MESSAGES/messages.mo')) {
$gettext_tables = new gettext_reader(
new CachedFileReader(PATH.'includes/languages/'.deflang($userInfo['language']).'/LC_MESSAGES/messages.mo')
);
$gettext_tables->load_tables();
}
$text = __("Someone (probably you) has just requested a password reset for your account. Because we need to know the truth, you have to confirm that clicking in the link below:\n\n%url\n\nIf not, just forget this mail!");
$text = str_replace('%url', BASE.'trouble_login?uid='.$uid.'&key='.$token, $text);
$this->sendMail($email, __('Password reset instructions'), $text, false, false, $userInfo['language']);
if (file_exists(PATH.'includes/languages/'.deflang(LANG).'/LC_MESSAGES/messages.mo')) {
$gettext_tables = new gettext_reader(
new CachedFileReader(PATH.'includes/languages/'.deflang(LANG).'/LC_MESSAGES/messages.mo')
);
$gettext_tables->load_tables();
}
}
function resetPassword($email, $new_password, $username) {
global $gettext_tables;
global $db;
$userInfo = $db->getUserInfo(false, $username);
if (file_exists(PATH.'includes/languages/'.deflang($userInfo['language']).'/LC_MESSAGES/messages.mo')) {
$gettext_tables = new gettext_reader(
new CachedFileReader(PATH.'includes/languages/'.deflang($userInfo['language']).'/LC_MESSAGES/messages.mo')
);
$gettext_tables->load_tables();
}
$text = __("Hey %username,\n\nNow, your new password is %password -- you can access now with it.\n\n--\nWe never forgot you ;-)");
$text = str_replace('%username', $username, str_replace('%password', $new_password, $text));
$this->sendMail($email, __('Password reset done'), $text, false, false, $userInfo['language']);
if (file_exists(PATH.'includes/languages/'.deflang(LANG).'/LC_MESSAGES/messages.mo')) {
$gettext_tables = new gettext_reader(
new CachedFileReader(PATH.'includes/languages/'.deflang(LANG).'/LC_MESSAGES/messages.mo')
);
$gettext_tables->load_tables();
}
}
function newFollower($me, $email, $username, $content, $language) {
global $gettext_tables;
global $_USER;
if (file_exists(PATH.'locale/'.deflang($language).'/LC_MESSAGES/messages.mo')) {
$gettext_tables = new gettext_reader(
new CachedFileReader(PATH.'locale/'.deflang($language).'/LC_MESSAGES/messages.mo')
);
$gettext_tables->load_tables();
}
$subject = __("%real_or_username is now following you");
$text = __("Hey %you!\n\n%real_or_username is now following your updates on %name.\n\nYou can see his/her profile here: %link");
$subject = str_replace('%real_or_username', $content, $subject);
$text = str_replace('%real_or_username', $content, $text);
$text = str_replace('%you', $me, str_replace('%name', NAME, $text));
$text = str_replace('%notifications_url', BASE.'settings/config', str_replace('%link', BASE.$username, $text));
$this->sendMail($email, $subject, $text, true, false, $language);
if (file_exists(PATH.'includes/languages/'.deflang(LANG).'/LC_MESSAGES/messages.mo')) {
$gettext_tables = new gettext_reader(
new CachedFileReader(PATH.'includes/languages/'.deflang(LANG).'/LC_MESSAGES/messages.mo')
);
$gettext_tables->load_tables();
}
}
function newPrivateNote($userInfo, $note, $USER) {
global $gettext_tables;
if (file_exists(PATH.'includes/languages/'.deflang($userInfo['language']).'/LC_MESSAGES/messages.mo')) {
$gettext_tables = new gettext_reader(
new CachedFileReader(PATH.'includes/languages/'.deflang($userInfo['language']).'/LC_MESSAGES/messages.mo')
);
$gettext_tables->load_tables();
}
$subject = __("Private note from %real_or_username");
$text = __('%real_or_username has sent you a private message:')."\n\n\"%note\"\n\n".__("You can see his profile at: %profile\nReply his/her message by sending a note with \"!%username \"");
if ($USER['realname']) $content = $USER['realname'].' ('.$USER['username'].')';
else $content = $USER['username'];
$subject = str_replace('%real_or_username', $content, $subject);
$text = str_replace('%real_or_username', $content, $text);
$text = str_replace('%note', $note, str_replace('%profile', BASE.$USER['username'], $text));
$text = str_replace('%notifications_url', BASE.'settings/config', str_replace('%username', $USER['username'], $text));
$this->sendMail($userInfo['email'], $subject, $text, true, false, $userInfo['language']);
if (file_exists(PATH.'includes/languages/'.deflang(LANG).'/LC_MESSAGES/messages.mo')) {
$gettext_tables = new gettext_reader(
new CachedFileReader(PATH.'includes/languages/'.deflang(LANG).'/LC_MESSAGES/messages.mo')
);
$gettext_tables->load_tables();
}
}
function confirmRegistration($email, $user_id, $token) {
global $gettext_tables;
global $db;
$userInfo = $db->getUserInfo($user_id);
if (file_exists(PATH.'includes/languages/'.deflang($userInfo['language']).'/LC_MESSAGES/messages.mo')) {
$gettext_tables = new gettext_reader(
new CachedFileReader(PATH.'includes/languages/'.deflang($userInfo['language']).'/LC_MESSAGES/messages.mo')
);
$gettext_tables->load_tables();
}
$subject = __('Confirmation for %name account');
$text = __("Hello!\n\nSomeone (probably you) has requested an account in %name. However, we need to know if you are the owner of this mail account. To confirm it, please click in the link below:\n\n%link\n\n--\nWe do this for security reasons. If you didn't request an account at %name, delete this mail and apologies.");
$subject = str_replace('%name', NAME, $subject);
$text = str_replace('%username', $username, str_replace('%name', NAME, $text));
$text = str_replace('%link', BASE.'register?uid='.$user_id.'&key='.$token, $text);
$this->sendMail($email, $subject, $text, false, false, $userInfo['language']);
if (file_exists(PATH.'includes/languages/'.deflang(LANG).'/LC_MESSAGES/messages.mo')) {
$gettext_tables = new gettext_reader(
new CachedFileReader(PATH.'includes/languages/'.deflang(LANG).'/LC_MESSAGES/messages.mo')
);
$gettext_tables->load_tables();
}
}
function emailChange($email, $user_id, $new_email, $token) {
global $gettext_tables;
global $db;
$userInfo = $db->getUserInfo($user_id);
if (file_exists(PATH.'includes/languages/'.deflang($userInfo['language']).'/LC_MESSAGES/messages.mo')) {
$gettext_tables = new gettext_reader(
new CachedFileReader(PATH.'includes/languages/'.deflang($userInfo['language']).'/LC_MESSAGES/messages.mo')
);
$gettext_tables->load_tables();
}
$text = __("Hello!\n\nSomeone (probably you) has requested a change of the email assigned to the account. Your email will change from:\n\n%current_email to %new_email\n\nIs this correct? Then, confirm the change by following this link: %link");
$text = str_replace('%current_email', $email, str_replace('%new_email', $new_email, $text));
$text = str_replace('%link', BASE.'settings/config?uid='.$user_id.'&key='.$token, $text);
$this->sendMail($email, __('Confirm email change'), $text, false, false, $userInfo['language']);
if (file_exists(PATH.'includes/languages/'.deflang(LANG).'/LC_MESSAGES/messages.mo')) {
$gettext_tables = new gettext_reader(
new CachedFileReader(PATH.'includes/languages/'.deflang(LANG).'/LC_MESSAGES/messages.mo')
);
$gettext_tables->load_tables();
}
}
function registrationSuccess($email, $username) {
global $gettext_tables;
global $db;
$userInfo = $db->getUserInfo(false, $username);
if (file_exists(PATH.'includes/languages/'.deflang($userInfo['language']).'/LC_MESSAGES/messages.mo')) {
$gettext_tables = new gettext_reader(
new CachedFileReader(PATH.'includes/languages/'.deflang($userInfo['language']).'/LC_MESSAGES/messages.mo')
);
$gettext_tables->load_tables();
}
$text = __("Hello %username!\n\nYou have just confirmed your account in %name, so now you can enjoy it!\n\n%name is based on Jisko, an open-source microblogging platform. Nowadays, Jisko is in a Beta period, but it is actually quite stable so we think you'll enjoy your stay. You can find more information about Jisko at http://www.jisko.org\n\nThank you very much for signing up in %name and for giving us a try!");
$text = str_replace('%username', $username, str_replace('%name', NAME, $text));
$this->sendMail($email, __('Welcome!'), $text, false, false, $userInfo['language']);
if (file_exists(PATH.'includes/languages/'.deflang(LANG).'/LC_MESSAGES/messages.mo')) {
$gettext_tables = new gettext_reader(
new CachedFileReader(PATH.'includes/languages/'.deflang(LANG).'/LC_MESSAGES/messages.mo')
);
$gettext_tables->load_tables();
}
}
function alertNewUser($username) {
global $gettext_tables;
$subject = __("There's a new user on %name");
$text = __("Hello admin!\n\nA new user called '%username' has joined %name. It should be empty, but if you want you can check his profile at %url");
$subject = str_replace('%name', NAME, $subject);
$text = str_replace('%username', $username, str_replace('%name', NAME, $text));
$text = str_replace('%url', BASE.$username, $text);
$this->sendMail(ADMIN_MAIL, $subject, $text, false, true);
}
function alertDelUser($uid) {
global $gettext_tables;
global $db;
$uinfo = $db->getUserInfo($uid);
$subject = __("The user %username has deleted his account from %name");
$text = __("Hello admin!\n\nThe user '%username' has deleted his account from %name. If you want to contact him, his email is %email");
$subject = str_replace('%name', NAME, str_replace('%username', $uinfo['username'], $subject));
$text = str_replace('%username', $username, str_replace('%name', NAME, $text));
$text = str_replace('%email', $uinfo['email'], $text);
$this->sendMail(ADMIN_MAIL, $subject, $text, false, true);
}
function newInvitation($email, $token) {
global $gettext_tables;
global $_USER;
$subject = __('%username has invited you to %name!');
$text = __("Hey!\n\n%username just sent an invitation for using %name! Why don't you make him/her happy and register?\n\nYou just need to follow %url to use the invitation.\n\nThank you and have fun!");
$subject = str_replace('%username', $_USER['username'], str_replace('%name', NAME, $subject));
$text = str_replace('%username', $_USER['username'], str_replace('%name', NAME, $text));
$text = str_replace('%url', BASE.'register?token='.$token, $text);
$this->sendMail($email, $subject, $text);
}
function passwordChange($email, $username) {
global $gettext_tables;
global $db;
$userInfo = $db->getUserInfo(false, $username);
if (file_exists(PATH.'includes/languages/'.deflang($userInfo['language']).'/LC_MESSAGES/messages.mo')) {
$gettext_tables = new gettext_reader(
new CachedFileReader(PATH.'includes/languages/'.deflang($userInfo['language']).'/LC_MESSAGES/messages.mo')
);
$gettext_tables->load_tables();
}
$text = __("Hello %username!\n\nWe send this mail to tell you that your password on %name has been changed -- If this wasn't requested, please contact the administrator of %name at %admin_mail");
$text = str_replace('%username', $username, str_replace('%admin_mail', ADMIN_MAIL, $text));
$text = str_replace('%name', NAME, $text);
$this->sendMail($email, __('Your password has been changed'), $text, false, false, $userInfo['language']);
if (file_exists(PATH.'includes/languages/'.deflang(LANG).'/LC_MESSAGES/messages.mo')) {
$gettext_tables = new gettext_reader(
new CachedFileReader(PATH.'includes/languages/'.deflang(LANG).'/LC_MESSAGES/messages.mo')
);
$gettext_tables->load_tables();
}
}
function confirmDrop($email, $username, $userID, $token) {
global $gettext_tables;
global $db;
$userInfo = $db->getUserInfo($userID);
if (file_exists(PATH.'includes/languages/'.deflang($userInfo['language']).'/LC_MESSAGES/messages.mo')) {
$gettext_tables = new gettext_reader(
new CachedFileReader(PATH.'includes/languages/'.deflang($userInfo['language']).'/LC_MESSAGES/messages.mo')
);
$gettext_tables->load_tables();
}
$text = __("Hello %username!\n\nAre you sure you want to delete your %name account? We can change because of you! Send your comments to %admin_mail and we'll take notes about your issues/suggestions.\n\nIf you're are completely sure of your decision (remember, this is NOT REVERSIBLE), click the link below:\n\n%drop_url\n\nYou must be logged in order to delete your account.");
$text = str_replace('%username', $username, str_replace('%admin_mail', ADMIN_MAIL, $text));
$text = str_replace('%drop_url', BASE.'settings/drop?uid='.$userID.'&key='.$token, str_replace('%name', NAME, $text));
$this->sendMail($email, __('Delete account confirmation'), $text, false, false, $userInfo['language']);
if (file_exists(PATH.'includes/languages/'.deflang(LANG).'/LC_MESSAGES/messages.mo')) {
$gettext_tables = new gettext_reader(
new CachedFileReader(PATH.'includes/languages/'.deflang(LANG).'/LC_MESSAGES/messages.mo')
);
$gettext_tables->load_tables();
}
}
function reportAbuse($reported_username) {
global $gettext_tables;
global $db;
global $_USER;
$userInfo = $db->getUserInfo(false, $reported_username);
$subject = __("%username reported the user %r_username");
$text = __("Abuse report:\n\nThe user %username (ID: %id) from the IP %ip reported the user %r_username (ID: %r_id).\n\n%username's email: %email\n%r_username's email: %r_mail");
$subject = str_replace('%username', $_USER['username'], str_replace('%r_username', $reported_username, $subject));
$text = str_replace('%username', $_USER['username'], str_replace('%id', $_USER['ID'], $text));
$text = str_replace('%ip', $_SERVER['REMOTE_ADDR'], str_replace('%r_username', $reported_username, $text));
$text = str_replace('%r_id', $userInfo['ID'], str_replace('%email', $_USER['email'], $text));
$text = str_replace('%r_mail', $userInfo['email'], $text);
$this->sendMail(ABUSE_MAIL, $subject, $text, false, true);
}
}
?>