send ostatus follow/share notifications via notification()

remove unused templates
This commit is contained in:
fabrixxm 2014-09-06 18:15:18 +02:00
parent 1bdddebd44
commit 0e628f840f
29 changed files with 192 additions and 509 deletions

View File

@ -15,6 +15,33 @@ function notification($params) {
push_lang($params['language']); push_lang($params['language']);
$banner = t('Friendica Notification');
$product = FRIENDICA_PLATFORM;
$siteurl = $a->get_baseurl(true);
$thanks = t('Thank You,');
$sitename = $a->config['sitename'];
$site_admin = sprintf( t('%s Administrator'), $sitename);
$sender_name = $product;
$hostname = $a->get_hostname();
if(strpos($hostname,':'))
$hostname = substr($hostname,0,strpos($hostname,':'));
$sender_email = t('noreply') . '@' . $hostname;
// with $params['show_in_notification_page'] == false, the notification isn't inserted into
// the database, and an email is sent if applicable.
// default, if not specified: true
$show_in_notification_page = ((x($params,'show_in_notification_page')) ? $params['show_in_notification_page']:True);
$additional_mail_header = "";
$additional_mail_header .= "Precedence: list\n";
$additional_mail_header .= "X-Friendica-Host: ".$hostname."\n";
$additional_mail_header .= "X-Friendica-Platform: ".FRIENDICA_PLATFORM."\n";
$additional_mail_header .= "X-Friendica-Version: ".FRIENDICA_VERSION."\n";
$additional_mail_header .= "List-ID: <notification.".$hostname.">\n";
$additional_mail_header .= "List-Archive: <".$a->get_baseurl()."/notifications/system>\n";
if(array_key_exists('item',$params)) { if(array_key_exists('item',$params)) {
$title = $params['item']['title']; $title = $params['item']['title'];
@ -204,6 +231,29 @@ function notification($params) {
$tsitelink = sprintf( $sitelink, $siteurl ); $tsitelink = sprintf( $sitelink, $siteurl );
$hsitelink = sprintf( $sitelink, '<a href="' . $siteurl . '">' . $sitename . '</a>'); $hsitelink = sprintf( $sitelink, '<a href="' . $siteurl . '">' . $sitename . '</a>');
$itemlink = $params['link']; $itemlink = $params['link'];
switch ($params['verb']) {
case ACTIVITY_FRIEND:
// someone started to share with user (mostly OStatus)
$subject = sprintf( t('[Friendica:Notify] A new person is sharing with you'));
$preamble = sprintf( t('%1$s is sharing with you at %2$s'), $params['source_name'], $sitename);
$epreamble = sprintf( t('%1$s is sharing with you at %2$s'),
'[url=' . $params['source_link'] . ']' . $params['source_name'] . '[/url]',
$sitename);
break;
case ACTIVITY_FOLLOW:
// someone started to follow the user (mostly OStatus)
$subject = sprintf( t('[Friendica:Notify] You have a new follower'));
$preamble = sprintf( t('You have a new follower at %2$s : %1$s'), $params['source_name'], $sitename);
$epreamble = sprintf( t('You have a new follower at %2$s : %1$s'),
'[url=' . $params['source_link'] . ']' . $params['source_name'] . '[/url]',
$sitename);
break;
default:
break;
}
} }
if($params['type'] == NOTIFY_SUGGEST) { if($params['type'] == NOTIFY_SUGGEST) {
@ -225,40 +275,49 @@ function notification($params) {
} }
if($params['type'] == NOTIFY_CONFIRM) { if($params['type'] == NOTIFY_CONFIRM) {
if ($params['verb'] == ACTIVITY_FRIEND ){ // mutual connection
$subject = sprintf( t('[Friendica:Notify] Connection accepted'));
$preamble = sprintf( t('\'%1$s\' has acepted your connection request at %2$s'), $params['source_name'], $sitename);
$epreamble = sprintf( t('%2$s has accepted your [url=%1$s]connection request[/url].'),
$itemlink,
'[url=' . $params['source_link'] . ']' . $params['source_name'] . '[/url]');
$body = t('You are now mutual friends and may exchange status updates, photos, and email
without restriction.');
$sitelink = t('Please visit %s if you wish to make any changes to this relationship.');
$tsitelink = sprintf( $sitelink, $siteurl );
$hsitelink = sprintf( $sitelink, '<a href="' . $siteurl . '">' . $sitename . '</a>');
$itemlink = $params['link'];
} else { // ACTIVITY_FOLLOW
$subject = sprintf( t('[Friendica:Notify] Connection accepted'));
$preamble = sprintf( t('\'%1$s\' has acepted your connection request at %2$s'), $params['source_name'], $sitename);
$epreamble = sprintf( t('%2$s has accepted your [url=%1$s]connection request[/url].'),
$itemlink,
'[url=' . $params['source_link'] . ']' . $params['source_name'] . '[/url]');
$body = sprintf(t('\'%1$s\' has chosen to accept you a "fan", which restricts some forms of communication - such as private messaging and some profile interactions. If this is a celebrity or community page, these settings were applied automatically.'), $params['source_name']);
$body .= "\n\n";
$body .= sprintf(t('\'%1$s\' may choose to extend this into a two-way or more permissive relationship in the future. '), $params['source_name']);
$sitelink = t('Please visit %s if you wish to make any changes to this relationship.');
$tsitelink = sprintf( $sitelink, $siteurl );
$hsitelink = sprintf( $sitelink, '<a href="' . $siteurl . '">' . $sitename . '</a>');
$itemlink = $params['link'];
}
} }
if($params['type'] == NOTIFY_SYSTEM) { if($params['type'] == NOTIFY_SYSTEM) {
$subject = $params['subject'];
$preamble = $params['preamble'];
$epreamble = $params['epreamble'];
$body = $params['body'];
$sitelink = "";
$tsitelink = "";
$hsitelink = "";
$itemlink = "";
} }
/*$email = prepare_notificaion_mail($params, $subject, $preamble, $body, $sitelink, $tsitelink, $hsitelink, $itemlink);
if ($email) Emailer::send($email);
pop_lang();*/
$banner = t('Friendica Notification');
$product = FRIENDICA_PLATFORM;
$siteurl = $a->get_baseurl(true);
$thanks = t('Thank You,');
$sitename = $a->config['sitename'];
$site_admin = sprintf( t('%s Administrator'), $sitename);
$sender_name = $product;
$hostname = $a->get_hostname();
if(strpos($hostname,':'))
$hostname = substr($hostname,0,strpos($hostname,':'));
$sender_email = t('noreply') . '@' . $hostname;
$additional_mail_header = "";
$additional_mail_header .= "Precedence: list\n";
$additional_mail_header .= "X-Friendica-Host: ".$hostname."\n";
$additional_mail_header .= "X-Friendica-Platform: ".FRIENDICA_PLATFORM."\n";
$additional_mail_header .= "X-Friendica-Version: ".FRIENDICA_VERSION."\n";
$additional_mail_header .= "List-ID: <notification.".$hostname.">\n";
$additional_mail_header .= "List-Archive: <".$a->get_baseurl()."/notifications/system>\n";
$h = array( $h = array(
'params' => $params, 'params' => $params,
@ -284,103 +343,104 @@ function notification($params) {
$itemlink = $h['itemlink']; $itemlink = $h['itemlink'];
if ($show_in_notification_page) {
do { do {
$dups = false; $dups = false;
$hash = random_string(); $hash = random_string();
$r = q("SELECT `id` FROM `notify` WHERE `hash` = '%s' LIMIT 1", $r = q("SELECT `id` FROM `notify` WHERE `hash` = '%s' LIMIT 1",
dbesc($hash)); dbesc($hash));
if(count($r)) if(count($r))
$dups = true; $dups = true;
} while($dups == true); } while($dups == true);
$datarray = array(); $datarray = array();
$datarray['hash'] = $hash; $datarray['hash'] = $hash;
$datarray['name'] = $params['source_name']; $datarray['name'] = $params['source_name'];
$datarray['url'] = $params['source_link']; $datarray['url'] = $params['source_link'];
$datarray['photo'] = $params['source_photo']; $datarray['photo'] = $params['source_photo'];
$datarray['date'] = datetime_convert(); $datarray['date'] = datetime_convert();
$datarray['uid'] = $params['uid']; $datarray['uid'] = $params['uid'];
$datarray['link'] = $itemlink; $datarray['link'] = $itemlink;
$datarray['parent'] = $parent_id; $datarray['parent'] = $parent_id;
$datarray['type'] = $params['type']; $datarray['type'] = $params['type'];
$datarray['verb'] = $params['verb']; $datarray['verb'] = $params['verb'];
$datarray['otype'] = $params['otype']; $datarray['otype'] = $params['otype'];
$datarray['abort'] = false; $datarray['abort'] = false;
call_hooks('enotify_store', $datarray); call_hooks('enotify_store', $datarray);
if($datarray['abort']) { if($datarray['abort']) {
pop_lang();
return False;
}
// create notification entry in DB
$r = q("insert into notify (hash,name,url,photo,date,uid,link,parent,type,verb,otype)
values('%s','%s','%s','%s','%s',%d,'%s',%d,%d,'%s','%s')",
dbesc($datarray['hash']),
dbesc($datarray['name']),
dbesc($datarray['url']),
dbesc($datarray['photo']),
dbesc($datarray['date']),
intval($datarray['uid']),
dbesc($datarray['link']),
intval($datarray['parent']),
intval($datarray['type']),
dbesc($datarray['verb']),
dbesc($datarray['otype'])
);
$r = q("select id from notify where hash = '%s' and uid = %d limit 1",
dbesc($hash),
intval($params['uid'])
);
if($r)
$notify_id = $r[0]['id'];
else {
pop_lang();
return False;
}
// we seem to have a lot of duplicate comment notifications due to race conditions, mostly from forums
// After we've stored everything, look again to see if there are any duplicates and if so remove them
$p = null;
$p = q("select id from notify where ( type = %d or type = %d ) and link = '%s' and uid = %d order by id",
intval(NOTIFY_TAGSELF),
intval(NOTIFY_COMMENT),
dbesc($params['link']),
intval($params['uid'])
);
if($p && (count($p) > 1)) {
for ($d = 1; $d < count($p); $d ++) {
q("delete from notify where id = %d",
intval($p[$d]['id'])
);
}
// only continue on if we stored the first one
if($notify_id != $p[0]['id']) {
pop_lang(); pop_lang();
return False; return False;
} }
// create notification entry in DB
$r = q("insert into notify (hash,name,url,photo,date,uid,link,parent,type,verb,otype)
values('%s','%s','%s','%s','%s',%d,'%s',%d,%d,'%s','%s')",
dbesc($datarray['hash']),
dbesc($datarray['name']),
dbesc($datarray['url']),
dbesc($datarray['photo']),
dbesc($datarray['date']),
intval($datarray['uid']),
dbesc($datarray['link']),
intval($datarray['parent']),
intval($datarray['type']),
dbesc($datarray['verb']),
dbesc($datarray['otype'])
);
$r = q("select id from notify where hash = '%s' and uid = %d limit 1",
dbesc($hash),
intval($params['uid'])
);
if($r)
$notify_id = $r[0]['id'];
else {
pop_lang();
return False;
}
// we seem to have a lot of duplicate comment notifications due to race conditions, mostly from forums
// After we've stored everything, look again to see if there are any duplicates and if so remove them
$p = null;
$p = q("select id from notify where ( type = %d or type = %d ) and link = '%s' and uid = %d order by id",
intval(NOTIFY_TAGSELF),
intval(NOTIFY_COMMENT),
dbesc($params['link']),
intval($params['uid'])
);
if($p && (count($p) > 1)) {
for ($d = 1; $d < count($p); $d ++) {
q("delete from notify where id = %d",
intval($p[$d]['id'])
);
}
// only continue on if we stored the first one
if($notify_id != $p[0]['id']) {
pop_lang();
return False;
}
}
$itemlink = $a->get_baseurl() . '/notify/view/' . $notify_id;
$msg = replace_macros($epreamble,array('$itemlink' => $itemlink));
$r = q("update notify set msg = '%s' where id = %d and uid = %d",
dbesc($msg),
intval($notify_id),
intval($params['uid'])
);
} }
$itemlink = $a->get_baseurl() . '/notify/view/' . $notify_id;
$msg = replace_macros($epreamble,array('$itemlink' => $itemlink));
$r = q("update notify set msg = '%s' where id = %d and uid = %d",
dbesc($msg),
intval($notify_id),
intval($params['uid'])
);
// send email notification if notification preferences permit // send email notification if notification preferences permit
if((intval($params['notify_flags']) & intval($params['type'])) || $params['type'] == NOTIFY_SYSTEM) { if((intval($params['notify_flags']) & intval($params['type'])) || $params['type'] == NOTIFY_SYSTEM) {
logger('notification: sending notification email'); logger('notification: sending notification email');

View File

@ -3828,6 +3828,7 @@ function new_follower($importer,$contact,$datarray,$item,$sharing = false) {
dbesc(datetime_convert()) dbesc(datetime_convert())
); );
} }
$r = q("SELECT * FROM `user` WHERE `uid` = %d LIMIT 1", $r = q("SELECT * FROM `user` WHERE `uid` = %d LIMIT 1",
intval($importer['uid']) intval($importer['uid'])
); );
@ -3841,20 +3842,24 @@ function new_follower($importer,$contact,$datarray,$item,$sharing = false) {
if(($r[0]['notify-flags'] & NOTIFY_INTRO) && if(($r[0]['notify-flags'] & NOTIFY_INTRO) &&
(($r[0]['page-flags'] == PAGE_NORMAL) OR ($r[0]['page-flags'] == PAGE_SOAPBOX))) { (($r[0]['page-flags'] == PAGE_NORMAL) OR ($r[0]['page-flags'] == PAGE_SOAPBOX))) {
$email_tpl = get_intltext_template('follow_notify_eml.tpl');
$email = replace_macros($email_tpl, array(
'$requestor' => ((strlen($name)) ? $name : t('[Name Withheld]')),
'$url' => $url, notification(array(
'$myname' => $r[0]['username'], 'type' => NOTIFY_INTRO,
'$siteurl' => $a->get_baseurl(), 'notify_flags' => $r[0]['notify-flags'],
'$sitename' => $a->config['sitename'] 'language' => $r[0]['language'],
'to_name' => $r[0]['username'],
'to_email' => $r[0]['email'],
'uid' => $r[0]['uid'],
'link' => $a->get_baseurl() . '/notifications/intro',
'source_name' => ((strlen(stripslashes($contact_record['name']))) ? stripslashes($contact_record['name']) : t('[Name Withheld]')),
'source_link' => $contact_record['url'],
'source_photo' => $contact_record['photo'],
'verb' => ($sharing ? ACTIVITY_FRIEND : ACTIVITY_FOLLOW),
'otype' => 'intro'
)); ));
$res = mail($r[0]['email'],
email_header_encode((($sharing) ? t('A new person is sharing with you at ') : t("You have a new follower at ")) . $a->config['sitename'],'UTF-8'),
$email,
'From: ' . 'Administrator' . '@' . $_SERVER['SERVER_NAME'] . "\n"
. 'Content-type: text/plain; charset=UTF-8' . "\n"
. 'Content-transfer-encoding: 8bit' );
} }
} }

View File

@ -1,13 +0,0 @@
Apreciat/da $myname,
Tens un nou seguidor en $sitename - '$requestor'.
Pots visitar el seu perfil en $url.
Iniciï sessió en el seu lloc per a aprovar o rebutjar/cancelar la sol·licitud.
$siteurl
$sitename

View File

@ -1,14 +0,0 @@
Apreciat/da {{$myname}},
Tens un nou seguidor en {{$sitename}} - '{{$requestor}}'.
Pots visitar el seu perfil en {{$url}}.
Iniciï sessió en el seu lloc per a aprovar o rebutjar/cancelar la sol·licitud.
{{$siteurl}}
{{$sitename}}

View File

@ -1,14 +0,0 @@
Drahý/Drahá $[myname],
Máte nového následovatele na $[sitename] - '$[requestor]'.
Můžete si zobrazit jeho profil na $[url].
Prosím, přihlaste se na Vašem webu pro odsouhlasení nebo ignorování/zrušení této žádosti
$[siteurl]
S pozdravem
$[sitename] administrátor

View File

@ -1,15 +0,0 @@
Milý/Milá {{$username}},
Máte nového následovatele na {{$sitename}} - '{{$requestor}}'.
Můžete si prohlédnout jeho/její profil na {{$url}}.
Přihlaste se na váš server k odsouhlasení nebo ignorování/zrušení žádosti.
{{$siteurl}}
S pozdravem,
{{$sitename}} administrátor

View File

@ -1,14 +0,0 @@
Hallo $[myname],
Du hast einen neuen Anhänger auf $[sitename] - '$[requestor]'.
Du kannst das Profil unter $[url] besuchen.
Bitte melde dich an um die Anfrage zu bestätigen oder sie zu ignorieren bzw. abzulehnen.
$[siteurl]
beste Grüße,
$[sitename] Administrator

View File

@ -1,15 +0,0 @@
Hallo {{$myname}},
Du hast einen neuen Anhänger auf {{$sitename}} - '{{$requestor}}'.
Du kannst das Profil unter {{$url}} besuchen.
Bitte melde dich an um die Anfrage zu bestätigen oder sie zu ignorieren bzw. abzulehnen.
{{$siteurl}}
beste Grüße,
{{$sitename}} Administrator

View File

@ -1,14 +0,0 @@
Dear $[myname],
You have a new follower at $[sitename] - '$[requestor]'.
You may visit their profile at $[url].
Please login to your site to approve or ignore/cancel the request.
$[siteurl]
Regards,
$[sitename] administrator

View File

@ -1,15 +0,0 @@
Dear {{$myname}},
You have a new follower at {{$sitename}} - '{{$requestor}}'.
You may visit their profile at {{$url}}.
Please login to your site to approve or ignore/cancel the request.
{{$siteurl}}
Regards,
{{$sitename}} administrator

View File

@ -1,14 +0,0 @@
Kara $[myname],
Vi havas novan abonanton ĉe $[sitename] - '$[requestor]'.
Vi povas viziti ilian profilon ĉe $[url].
Bonvolu ensaluti en vian retejon por aprobi au malaprobi/nuligi la peton.
$[siteurl]
Salutoj,
[$sitename] administranto

View File

@ -1,15 +0,0 @@
Kara {{$myname}},
Vi havas novan abonanton ĉe {{$sitename}} - '{{$requestor}}'.
Vi povas viziti ilian profilon ĉe {{$url}}.
Bonvolu ensaluti en vian retejon por aprobi au malaprobi/nuligi la peton.
{{$siteurl}}
Salutoj,
[{{$sitename}}] administranto

View File

@ -1,13 +0,0 @@
Estimado/a $myname,
Tienes un nuevo seguidor en $sitename - '$requestor'.
Puedes visitar su perfil en $url.
Inicie sesión en su sitio para aprobar o rechazar/cancelar la solicitud.
$siteurl
$sitename

View File

@ -1,14 +0,0 @@
Estimado/a {{$myname}},
Tienes un nuevo seguidor en {{$sitename}} - '{{$requestor}}'.
Puedes visitar su perfil en {{$url}}.
Inicie sesión en su sitio para aprobar o rechazar/cancelar la solicitud.
{{$siteurl}}
{{$sitename}}

View File

@ -1,14 +0,0 @@
Cher(e) $myname,
Une nouvelle personne - $requestor - vous suit désormais sur $sitename.
Vous pouvez consulter son profil sur $url.
Merci de vous connecter à votre site pour approuver ou ignorer/annuler cette demande.
$siteurl
Cordialement,
l'administrateur de $sitename

View File

@ -1,15 +0,0 @@
Cher(e) {{$myname}},
Une nouvelle personne - {{$requestor}} - vous suit désormais sur {{$sitename}}.
Vous pouvez consulter son profil sur {{$url}}.
Merci de vous connecter à votre site pour approuver ou ignorer/annuler cette demande.
{{$siteurl}}
Cordialement,
l'administrateur de {{$sitename}}

View File

@ -1,14 +0,0 @@
Góðan daginn $[myname],
Þú hefur nýjan aðdáanda frá $[sitename] - '$[requestor]'.
Þú getur heimsótt þeirra heimasvæði á $[url].
Vinsamlegast innskráðu þig til að samþykkja eða hunsa/hætta við beiðni.
$[siteurl]
Bestu kveðjur,
Kerfisstjóri $[sitename]

View File

@ -1,15 +0,0 @@
Góðan daginn {{$myname}},
Þú hefur nýjan aðdáanda frá {{$sitename}} - '{{$requestor}}'.
Þú getur heimsótt þeirra heimasvæði á {{$url}}.
Vinsamlegast innskráðu þig til að samþykkja eða hunsa/hætta við beiðni.
{{$siteurl}}
Bestu kveðjur,
Kerfisstjóri {{$sitename}}

View File

@ -1,14 +0,0 @@
Ciao {{$myname}},
Un nuovo utente ha iniziato a seguirti su {{$sitename}} - '{{$requestor}}'.
Puoi vedere il suo profilo su {{$url}}.
Accedi sul tuo sito per approvare o ignorare la richiesta.
{{$siteurl}}
Saluti,
L'amministratore di {{$sitename}}

View File

@ -1,14 +0,0 @@
Kjære $[myname],
Du har en ny følgesvenn på $[sitename] - '$[requestor]'.
Du kan besøke profilen deres på $[url].
Vennligst logg inn på ditt sted for å godkjenne eller ignorere/avbryte forespørselen.
$[siteurl]
Med vennlig hilsen,
$[sitename] administrator

View File

@ -1,15 +0,0 @@
Kjære {{$myname}},
Du har en ny følgesvenn på {{$sitename}} - '{{$requestor}}'.
Du kan besøke profilen deres på {{$url}}.
Vennligst logg inn på ditt sted for å godkjenne eller ignorere/avbryte forespørselen.
{{$siteurl}}
Med vennlig hilsen,
{{$sitename}} administrator

View File

@ -1,14 +0,0 @@
Beste $[myname]
U heeft een nieuw contact op $[sitename] - '$[requestor]'.
U kunt het profiel bezoeken op $[url]
U moet op uw Friendica-site inloggen om het verzoek goed te keuren, te negeren of the annuleren.
$[siteurl]
Vriendelijke groet,
Beheerder $[sitename]

View File

@ -1,14 +0,0 @@
Drogi $[myname],
Masz nowego obserwującego na $[sitename] - '$[requestor]'.
Możesz odwiedzić jego profil na $[url].
Zaloguj się na swoją stronę by potwierdzić lub zignorować/anulować prośbę.
$[siteurl]
Pozdrawiam,
$[sitename] Administrator

View File

@ -1,15 +0,0 @@
Drogi {{$myname}},
Masz nowego obserwującego na {{$sitename}} - '{{$requestor}}'.
Możesz odwiedzić jego profil na {{$url}}.
Zaloguj się na swoją stronę by potwierdzić lub zignorować/anulować prośbę.
{{$siteurl}}
Pozdrawiam,
{{$sitename}} Administrator

View File

@ -1,14 +0,0 @@
Dragă $[myname],
Aveţi un nou urmăritoe la $[sitename] - '$[requestor]'.
Puteţi vizita profilul lor la $[url].
Vă rugăm să vă logaţi pe site-ul dvs. pentru a aproba sau ignora / anula cererea.
$[siteurl]
Cu respect,
$[sitename] administrator

View File

@ -1,12 +0,0 @@
$myname,
'$requestor' på $sitename vill följa dina uppdateringar här på Friendica.
Besök dennes profil på $url.
Logga in för att godkänna eller avslå förfrågan.
$siteurl
Hälsningar,
$sitename admin

View File

@ -1,13 +0,0 @@
{{$myname}},
'{{$requestor}}' på {{$sitename}} vill följa dina uppdateringar här på Friendica.
Besök dennes profil på {{$url}}.
Logga in för att godkänna eller avslå förfrågan.
{{$siteurl}}
Hälsningar,
{{$sitename}} admin

View File

@ -1,14 +0,0 @@
尊敬的$[myname],
您有新关注的在$[sitename]-「$[requestor]」。
您能看他的简介在$[url]。
请再您的网页登记为确认或取消要求。
$[siteurl]
谨上,
$[sitename]行政人员

View File

@ -1,15 +0,0 @@
尊敬的{{$myname}},
您有新关注的在{{$sitename}}-「{{$requestor}}」。
您能看他的简介在{{$url}}
请再您的网页登记为确认或取消要求。
{{$siteurl}}
谨上,
{{$sitename}}行政人员