aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Zotlabs/Lib/Enotify.php (renamed from include/enotify.php)203
-rw-r--r--Zotlabs/Module/Item.php6
-rw-r--r--Zotlabs/Module/Ping.php5
-rw-r--r--include/dir_fns.php3
-rwxr-xr-xinclude/items.php15
-rw-r--r--include/network.php4
-rw-r--r--include/notify.php37
-rw-r--r--include/zot.php3
8 files changed, 136 insertions, 140 deletions
diff --git a/include/enotify.php b/Zotlabs/Lib/Enotify.php
index bd8698606..c6405dac2 100644
--- a/include/enotify.php
+++ b/Zotlabs/Lib/Enotify.php
@@ -1,95 +1,99 @@
<?php
-/**
- * @file include/enotify.php
- *
- * @brief File with functions and a class for email notifications.
- */
+
+namespace Zotlabs\Lib;
/**
- * @brief
- *
- * @param array $params an assoziative array with:
- * * \e string \b from_xchan sender xchan hash
- * * \e string \b to_xchan recipient xchan hash
- * * \e array \b item an assoziative array
- * * \e int \b type one of the NOTIFY_* constants from boot.php
- * * \e string \b link
- * * \e string \b parent_mid
- * * \e string \b otype
- * * \e string \b verb
- * * \e string \b activity
+ * @brief File with functions and a class for generating system and email notifications.
*/
-function notification($params) {
- logger('notification: entry', LOGGER_DEBUG);
- // throw a small amount of entropy into the system to breakup duplicates arriving at the same precise instant.
- usleep(mt_rand(0, 10000));
+class Enotify {
- $a = get_app();
+ /**
+ * @brief
+ *
+ * @param array $params an assoziative array with:
+ * * \e string \b from_xchan sender xchan hash
+ * * \e string \b to_xchan recipient xchan hash
+ * * \e array \b item an assoziative array
+ * * \e int \b type one of the NOTIFY_* constants from boot.php
+ * * \e string \b link
+ * * \e string \b parent_mid
+ * * \e string \b otype
+ * * \e string \b verb
+ * * \e string \b activity
+ */
- if ($params['from_xchan']) {
- $x = q("select * from xchan where xchan_hash = '%s' limit 1",
- dbesc($params['from_xchan'])
- );
- }
- if ($params['to_xchan']) {
- $y = q("select channel.*, account.* from channel left join account on channel_account_id = account_id
- where channel_hash = '%s' and channel_removed = 0 limit 1",
- dbesc($params['to_xchan'])
- );
- }
- if ($x & $y) {
- $sender = $x[0];
- $recip = $y[0];
- } else {
- logger('notification: no sender or recipient.');
- logger('sender: ' . $params['from_xchan']);
- logger('recip: ' . $params['to_xchan']);
- return;
- }
+ static public function submit($params) {
- // from here on everything is in the recipients language
+ logger('notification: entry', LOGGER_DEBUG);
- push_lang($recip['account_language']); // should probably have a channel language
+ // throw a small amount of entropy into the system to breakup duplicates arriving at the same precise instant.
+ usleep(mt_rand(0, 10000));
- $banner = t('$Projectname Notification');
- $product = t('$projectname'); // PLATFORM_NAME;
- $siteurl = z_root();
- $thanks = t('Thank You,');
- $sitename = get_config('system','sitename');
- $site_admin = sprintf( t('%s Administrator'), $sitename);
+ if ($params['from_xchan']) {
+ $x = q("select * from xchan where xchan_hash = '%s' limit 1",
+ dbesc($params['from_xchan'])
+ );
+ }
+ if ($params['to_xchan']) {
+ $y = q("select channel.*, account.* from channel left join account on channel_account_id = account_id
+ where channel_hash = '%s' and channel_removed = 0 limit 1",
+ dbesc($params['to_xchan'])
+ );
+ }
+ if ($x & $y) {
+ $sender = $x[0];
+ $recip = $y[0];
+ } else {
+ logger('notification: no sender or recipient.');
+ logger('sender: ' . $params['from_xchan']);
+ logger('recip: ' . $params['to_xchan']);
+ return;
+ }
- $sender_name = $product;
- $hostname = App::get_hostname();
- if(strpos($hostname,':'))
- $hostname = substr($hostname,0,strpos($hostname,':'));
+ // from here on everything is in the recipients language
- // Do not translate 'noreply' as it must be a legal 7-bit email address
- $sender_email = 'noreply' . '@' . $hostname;
+ push_lang($recip['account_language']); // should probably have a channel language
- $additional_mail_header = "";
+ $banner = t('$Projectname Notification');
+ $product = t('$projectname'); // PLATFORM_NAME;
+ $siteurl = z_root();
+ $thanks = t('Thank You,');
+ $sitename = get_config('system','sitename');
+ $site_admin = sprintf( t('%s Administrator'), $sitename);
- if (array_key_exists('item', $params)) {
- require_once('include/conversation.php');
- // if it's a normal item...
- if (array_key_exists('verb', $params['item'])) {
- // localize_item() alters the original item so make a copy first
- $i = $params['item'];
- logger('calling localize');
- localize_item($i);
- $title = $i['title'];
- $body = $i['body'];
- $private = (($i['item_private']) || intval($i['item_obscured']));
- }
+ $sender_name = $product;
+ $hostname = \App::get_hostname();
+ if(strpos($hostname,':'))
+ $hostname = substr($hostname,0,strpos($hostname,':'));
+
+ // Do not translate 'noreply' as it must be a legal 7-bit email address
+ $sender_email = 'noreply' . '@' . $hostname;
+
+ $additional_mail_header = "";
+
+ if(array_key_exists('item', $params)) {
+ require_once('include/conversation.php');
+ // if it's a normal item...
+ if (array_key_exists('verb', $params['item'])) {
+ // localize_item() alters the original item so make a copy first
+ $i = $params['item'];
+ logger('calling localize');
+ localize_item($i);
+ $title = $i['title'];
+ $body = $i['body'];
+ $private = (($i['item_private']) || intval($i['item_obscured']));
+ }
+ else {
+ $title = $params['item']['title'];
+ $body = $params['item']['body'];
+ }
+ }
else {
- $title = $params['item']['title'];
- $body = $params['item']['body'];
+ $title = $body = '';
}
- } else {
- $title = $body = '';
- }
// e.g. "your post", "David's photo", etc.
@@ -424,7 +428,7 @@ function notification($params) {
// wretched hack, but we don't want to duplicate all the preamble variations and we also don't want to screw up a translation
- if ((App::$language === 'en' || (! App::$language)) && strpos($msg,', '))
+ if ((\App::$language === 'en' || (! \App::$language)) && strpos($msg,', '))
$msg = substr($msg,strpos($msg,', ')+1);
$r = q("update notify set msg = '%s' where id = %d and uid = %d",
@@ -441,7 +445,7 @@ function notification($params) {
logger('notification: sending notification email');
$hn = get_pconfig($recip['channel_id'],'system','email_notify_host');
- if($hn && (! stristr(App::get_hostname(),$hn))) {
+ if($hn && (! stristr(\App::get_hostname(),$hn))) {
// this isn't the email notification host
pop_lang();
return;
@@ -455,7 +459,7 @@ function notification($params) {
// use $_SESSION['zid_override'] to force zid() to use
// the recipient address instead of the current observer
- $_SESSION['zid_override'] = $recip['channel_address'] . '@' . App::get_hostname();
+ $_SESSION['zid_override'] = $recip['channel_address'] . '@' . \App::get_hostname();
$_SESSION['zrl_override'] = z_root() . '/channel/' . $recip['channel_address'];
$textversion = zidify_links($textversion);
@@ -529,7 +533,7 @@ function notification($params) {
$tpl = get_markup_template('email_notify_html.tpl');
$email_html_body = replace_macros($tpl,array(
'$banner' => $datarray['banner'],
- '$notify_icon' => Zotlabs\Lib\System::get_notify_icon(),
+ '$notify_icon' => \Zotlabs\Lib\System::get_notify_icon(),
'$product' => $datarray['product'],
'$preamble' => $datarray['preamble'],
'$sitename' => $datarray['sitename'],
@@ -570,7 +574,7 @@ function notification($params) {
// use the EmailNotification library to send the message
- enotify::send(array(
+ self::send(array(
'fromName' => $sender_name,
'fromEmail' => $sender_email,
'replyTo' => $sender_email,
@@ -587,12 +591,6 @@ function notification($params) {
}
-/**
- * @brief A class for sending email notifications.
- *
- * @fixme Class names start mostly with capital letter to distinguish them easier.
- */
-class enotify {
/**
* @brief Send a multipart/alternative message with Text and HTML versions.
*
@@ -649,4 +647,39 @@ class enotify {
);
logger("notification: enotify::send returns " . $res, LOGGER_DEBUG);
}
+
+ static public function forma($item) {
+
+ $ret = '';
+
+ require_once('include/conversation.php');
+
+ // Call localize_item with the "brief" flag to get a one line status for activities.
+ // This should set $item['localized'] to indicate we have a brief summary.
+
+ localize_item($item);
+
+ if($item_localize) {
+ $itemem_text = $item['localize'];
+ }
+ else {
+ $itemem_text = (($item['item_thread_top'])
+ ? t('created a new post')
+ : sprintf( t('commented on %s\'s post'), $item['owner']['xchan_name']));
+ }
+
+ // convert this logic into a json array just like the system notifications
+
+ return array(
+ 'notify_link' => $item['llink'],
+ 'name' => $item['author']['xchan_name'],
+ 'url' => $item['author']['xchan_url'],
+ 'photo' => $item['author']['xchan_photo_s'],
+ 'when' => relative_date($item['created']),
+ 'class' => (intval($item['item_unseen']) ? 'notify-unseen' : 'notify-seen'),
+ 'message' => strip_tags(bbcode($itemem_text))
+ );
+
+ }
+
}
diff --git a/Zotlabs/Module/Item.php b/Zotlabs/Module/Item.php
index b4f493e5b..041939ad8 100644
--- a/Zotlabs/Module/Item.php
+++ b/Zotlabs/Module/Item.php
@@ -17,10 +17,10 @@ namespace Zotlabs\Module;
*/
require_once('include/crypto.php');
-require_once('include/enotify.php');
require_once('include/items.php');
require_once('include/attach.php');
+use \Zotlabs\Lib as Zlib;
class Item extends \Zotlabs\Web\Controller {
@@ -925,7 +925,7 @@ class Item extends \Zotlabs\Web\Controller {
// otherwise it will happen during delivery
if(($datarray['owner_xchan'] != $datarray['author_xchan']) && (intval($parent_item['item_wall']))) {
- notification(array(
+ Zlib\Enotify::submit(array(
'type' => NOTIFY_COMMENT,
'from_xchan' => $datarray['author_xchan'],
'to_xchan' => $datarray['owner_xchan'],
@@ -943,7 +943,7 @@ class Item extends \Zotlabs\Web\Controller {
$parent = $post_id;
if(($datarray['owner_xchan'] != $datarray['author_xchan']) && ($datarray['item_type'] == ITEM_TYPE_POST)) {
- notification(array(
+ Zlib\Enotify::submit(array(
'type' => NOTIFY_WALL,
'from_xchan' => $datarray['author_xchan'],
'to_xchan' => $datarray['owner_xchan'],
diff --git a/Zotlabs/Module/Ping.php b/Zotlabs/Module/Ping.php
index bea4a08b7..f0caa4373 100644
--- a/Zotlabs/Module/Ping.php
+++ b/Zotlabs/Module/Ping.php
@@ -1,12 +1,13 @@
<?php
namespace Zotlabs\Module;
+
/**
* @file mod/ping.php
*
*/
require_once('include/bbcode.php');
-require_once('include/notify.php');
+
/**
* @brief do several updates when pinged.
@@ -285,7 +286,7 @@ class Ping extends \Zotlabs\Web\Controller {
foreach($r as $item) {
if((argv(1) === 'home') && (! intval($item['item_wall'])))
continue;
- $result[] = format_notification($item);
+ $result[] = \Zotlbas\Lib\Enotify::format($item);
}
}
// logger('ping (network||home): ' . print_r($result, true), LOGGER_DATA);
diff --git a/include/dir_fns.php b/include/dir_fns.php
index 4e300663c..9f1be1a42 100644
--- a/include/dir_fns.php
+++ b/include/dir_fns.php
@@ -94,6 +94,9 @@ function get_directory_setting($observer, $setting) {
if($ret === false)
$ret = get_config('directory', $setting);
+
+ // 'safemode' is the default if there is no observer or no established preference.
+
if($setting == 'safemode' && $ret === false)
$ret = 1;
diff --git a/include/items.php b/include/items.php
index de0941c3c..a60c10bdd 100755
--- a/include/items.php
+++ b/include/items.php
@@ -6,6 +6,8 @@
// uncertain if this line is needed and why
use Sabre\HTTP\URLUtil;
+use Zotlabs\Lib as Zlib;
+
require_once('include/bbcode.php');
require_once('include/oembed.php');
require_once('include/crypto.php');
@@ -2284,8 +2286,8 @@ function send_status_notifications($post_id,$item) {
if(! $notify)
return;
- require_once('include/enotify.php');
- notification(array(
+
+ Zlib\Enotify::submit(array(
'type' => NOTIFY_COMMENT,
'from_xchan' => $item['author_xchan'],
'to_xchan' => $r[0]['channel_hash'],
@@ -2378,8 +2380,7 @@ function tag_deliver($uid, $item_id) {
$verb = urldecode(substr($item['verb'],strpos($item['verb'],'#')+1));
if($poke_notify) {
- require_once('include/enotify.php');
- notification(array(
+ Zlib\Enotify::submit(array(
'to_xchan' => $u[0]['channel_hash'],
'from_xchan' => $item['author_xchan'],
'type' => NOTIFY_POKE,
@@ -2544,8 +2545,7 @@ function tag_deliver($uid, $item_id) {
* Kill two birds with one stone. As long as we're here, send a mention notification.
*/
- require_once('include/enotify.php');
- notification(array(
+ Zlib\Enotify::submit(array(
'to_xchan' => $u[0]['channel_hash'],
'from_xchan' => $item['author_xchan'],
'type' => NOTIFY_TAGSELF,
@@ -3046,7 +3046,6 @@ function mail_store($arr) {
);
}
else {
- require_once('include/enotify.php');
$notif_params = array(
'from_xchan' => $arr['from_xchan'],
@@ -3057,7 +3056,7 @@ function mail_store($arr) {
'otype' => 'mail'
);
- notification($notif_params);
+ Zlib\Enotify::submit($notif_params);
}
call_hooks('post_mail_end',$arr);
diff --git a/include/network.php b/include/network.php
index 3e5263d3e..9fe0fd9cf 100644
--- a/include/network.php
+++ b/include/network.php
@@ -1819,8 +1819,6 @@ function service_plink($contact, $guid) {
function format_and_send_email($sender,$xchan,$item) {
- require_once('include/enotify.php');
-
$title = $item['title'];
$body = $item['body'];
@@ -1885,7 +1883,7 @@ function format_and_send_email($sender,$xchan,$item) {
// use the EmailNotification library to send the message
- enotify::send(array(
+ Zotlabs\Lib\Enotify::send(array(
'fromName' => $product,
'fromEmail' => $sender_email,
'replyTo' => $sender_email,
diff --git a/include/notify.php b/include/notify.php
deleted file mode 100644
index 2b032b56b..000000000
--- a/include/notify.php
+++ /dev/null
@@ -1,37 +0,0 @@
-<?php /** @file */
-
-
-function format_notification($item) {
-
- $ret = '';
-
- require_once('include/conversation.php');
-
- // Call localize_item with the "brief" flag to get a one line status for activities.
- // This should set $item['localized'] to indicate we have a brief summary.
-
- localize_item($item);
-
- if($item_localize) {
- $itemem_text = $item['localize'];
- }
- else {
- $itemem_text = (($item['item_thread_top'])
- ? t('created a new post')
- : sprintf( t('commented on %s\'s post'), $item['owner']['xchan_name']));
- }
-
- // convert this logic into a json array just like the system notifications
-
- return array(
- 'notify_link' => $item['llink'],
- 'name' => $item['author']['xchan_name'],
- 'url' => $item['author']['xchan_url'],
- 'photo' => $item['author']['xchan_photo_s'],
- 'when' => relative_date($item['created']),
- 'class' => (intval($item['item_unseen']) ? 'notify-unseen' : 'notify-seen'),
- 'message' => strip_tags(bbcode($itemem_text))
- );
-
-}
-
diff --git a/include/zot.php b/include/zot.php
index 8ba03ff5c..64f1c0c0e 100644
--- a/include/zot.php
+++ b/include/zot.php
@@ -505,8 +505,7 @@ function zot_refresh($them, $channel = null, $force = false) {
if($new_connection) {
if($new_perms != $previous_perms)
Zotlabs\Daemon\Master::Summon(array('Notifier','permission_create',$new_connection[0]['abook_id']));
- require_once('include/enotify.php');
- notification(array(
+ Zotlabs\Lib\Enotify::submit(array(
'type' => NOTIFY_INTRO,
'from_xchan' => $x['hash'],
'to_xchan' => $channel['channel_hash'],