]> git.mxchange.org Git - friendica.git/blobdiff - src/Core/NotificationsManager.php
Replace html2plain calls by HTML::toPlaintext
[friendica.git] / src / Core / NotificationsManager.php
index 6efd17ddf257438d4f5ff4cac90510eb0a3b7163..aaf6933f0299759b934448a632df3afba363fa29 100644 (file)
@@ -1,23 +1,25 @@
 <?php
-
 /**
  * @file src/Core/NotificationsManager.php
  * @brief Methods for read and write notifications from/to database
  *  or for formatting notifications
  */
-
 namespace Friendica\Core;
 
 use Friendica\BaseObject;
+use Friendica\Content\Text\BBCode;
+use Friendica\Core\L10n;
 use Friendica\Core\PConfig;
 use Friendica\Core\System;
 use Friendica\Database\DBM;
 use Friendica\Model\Contact;
+use Friendica\Model\Profile;
+use Friendica\Util\DateTimeFormat;
+use Friendica\Util\Temporal;
+use Friendica\Util\XML;
 
 require_once 'include/dba.php';
 require_once 'include/html2plain.php';
-require_once 'include/datetime.php';
-require_once 'include/bbcode.php';
 
 /**
  * @brief Methods for read and write notifications from/to database
@@ -39,13 +41,13 @@ class NotificationsManager extends BaseObject
         */
        private function _set_extra($notes)
        {
-               $rets = array();
+               $rets = [];
                foreach ($notes as $n) {
-                       $local_time = datetime_convert('UTC', date_default_timezone_get(), $n['date']);
+                       $local_time = DateTimeFormat::local($n['date']);
                        $n['timestamp'] = strtotime($local_time);
-                       $n['date_rel'] = relative_date($n['date']);
-                       $n['msg_html'] = bbcode($n['msg'], false, false, false, false);
-                       $n['msg_plain'] = explode("\n", trim(html2plain($n['msg_html'], 0)))[0];
+                       $n['date_rel'] = Temporal::getRelativeDate($n['date']);
+                       $n['msg_html'] = BBCode::convert($n['msg'], false);
+                       $n['msg_plain'] = explode("\n", trim(Friendica\Content\Text\HTML::toPlaintext($n['msg_html'], 0)))[0];
 
                        $rets[] = $n;
                }
@@ -62,9 +64,9 @@ class NotificationsManager extends BaseObject
         *
         * @return array of results or false on errors
         */
-       public function getAll($filter = array(), $order = "-date", $limit = "")
+       public function getAll($filter = [], $order = "-date", $limit = "")
        {
-               $filter_str = array();
+               $filter_str = [];
                $filter_sql = "";
                foreach ($filter as $column => $value) {
                        $filter_str[] = sprintf("`%s` = '%s'", $column, dbesc($value));
@@ -74,7 +76,7 @@ class NotificationsManager extends BaseObject
                }
 
                $aOrder = explode(" ", $order);
-               $asOrder = array();
+               $asOrder = [];
                foreach ($aOrder as $o) {
                        $dir = "asc";
                        if ($o[0] === "-") {
@@ -164,43 +166,43 @@ class NotificationsManager extends BaseObject
         */
        public function getTabs()
        {
-               $tabs = array(
-                       array(
-                               'label' => t('System'),
+               $tabs = [
+                       [
+                               'label' => L10n::t('System'),
                                'url'   => 'notifications/system',
                                'sel'   => ((self::getApp()->argv[1] == 'system') ? 'active' : ''),
                                'id'    => 'system-tab',
                                'accesskey' => 'y',
-                       ),
-                       array(
-                               'label' => t('Network'),
+                       ],
+                       [
+                               'label' => L10n::t('Network'),
                                'url'   => 'notifications/network',
                                'sel'   => ((self::getApp()->argv[1] == 'network') ? 'active' : ''),
                                'id'    => 'network-tab',
                                'accesskey' => 'w',
-                       ),
-                       array(
-                               'label' => t('Personal'),
+                       ],
+                       [
+                               'label' => L10n::t('Personal'),
                                'url'   => 'notifications/personal',
                                'sel'   => ((self::getApp()->argv[1] == 'personal') ? 'active' : ''),
                                'id'    => 'personal-tab',
                                'accesskey' => 'r',
-                       ),
-                       array(
-                               'label' => t('Home'),
+                       ],
+                       [
+                               'label' => L10n::t('Home'),
                                'url'   => 'notifications/home',
                                'sel'   => ((self::getApp()->argv[1] == 'home') ? 'active' : ''),
                                'id'    => 'home-tab',
                                'accesskey' => 'h',
-                       ),
-                       array(
-                               'label' => t('Introductions'),
+                       ],
+                       [
+                               'label' => L10n::t('Introductions'),
                                'url'   => 'notifications/intros',
                                'sel'   => ((self::getApp()->argv[1] == 'intros') ? 'active' : ''),
                                'id'    => 'intro-tab',
                                'accesskey' => 'i',
-                       ),
-               );
+                       ],
+               ];
 
                return $tabs;
        }
@@ -222,8 +224,8 @@ class NotificationsManager extends BaseObject
         */
        private function formatNotifs($notifs, $ident = "")
        {
-               $notif = array();
-               $arr = array();
+               $notif = [];
+               $arr = [];
 
                if (DBM::is_result($notifs)) {
                        foreach ($notifs as $it) {
@@ -241,9 +243,9 @@ class NotificationsManager extends BaseObject
                                                $default_item_link = System::baseUrl(true) . '/notify/view/' . $it['id'];
                                                $default_item_image = proxy_url($it['photo'], false, PROXY_SIZE_MICRO);
                                                $default_item_url = $it['url'];
-                                               $default_item_text = strip_tags(bbcode($it['msg']));
-                                               $default_item_when = datetime_convert('UTC', date_default_timezone_get(), $it['date'], 'r');
-                                               $default_item_ago = relative_date($it['date']);
+                                               $default_item_text = strip_tags(BBCode::convert($it['msg']));
+                                               $default_item_when = DateTimeFormat::local($it['date'], 'r');
+                                               $default_item_ago = Temporal::getRelativeDate($it['date']);
                                                break;
 
                                        case 'home':
@@ -251,9 +253,9 @@ class NotificationsManager extends BaseObject
                                                $default_item_link = System::baseUrl(true) . '/display/' . $it['pguid'];
                                                $default_item_image = proxy_url($it['author-avatar'], false, PROXY_SIZE_MICRO);
                                                $default_item_url = $it['author-link'];
-                                               $default_item_text = sprintf(t("%s commented on %s's post"), $it['author-name'], $it['pname']);
-                                               $default_item_when = datetime_convert('UTC', date_default_timezone_get(), $it['created'], 'r');
-                                               $default_item_ago = relative_date($it['created']);
+                                               $default_item_text = L10n::t("%s commented on %s's post", $it['author-name'], $it['pname']);
+                                               $default_item_when = DateTimeFormat::local($it['created'], 'r');
+                                               $default_item_ago = Temporal::getRelativeDate($it['created']);
                                                break;
 
                                        default:
@@ -262,98 +264,98 @@ class NotificationsManager extends BaseObject
                                                $default_item_image = proxy_url($it['author-avatar'], false, PROXY_SIZE_MICRO);
                                                $default_item_url = $it['author-link'];
                                                $default_item_text = (($it['id'] == $it['parent'])
-                                                                       ? sprintf(t("%s created a new post"), $it['author-name'])
-                                                                       : sprintf(t("%s commented on %s's post"), $it['author-name'], $it['pname']));
-                                               $default_item_when = datetime_convert('UTC', date_default_timezone_get(), $it['created'], 'r');
-                                               $default_item_ago = relative_date($it['created']);
+                                                                       ? L10n::t("%s created a new post", $it['author-name'])
+                                                                       : L10n::t("%s commented on %s's post", $it['author-name'], $it['pname']));
+                                               $default_item_when = DateTimeFormat::local($it['created'], 'r');
+                                               $default_item_ago = Temporal::getRelativeDate($it['created']);
                                }
 
                                // Transform the different types of notification in an usable array
                                switch ($it['verb']) {
                                        case ACTIVITY_LIKE:
-                                               $notif = array(
+                                               $notif = [
                                                        'label' => 'like',
                                                        'link' => System::baseUrl(true) . '/display/' . $it['pguid'],
                                                        'image' => proxy_url($it['author-avatar'], false, PROXY_SIZE_MICRO),
                                                        'url' => $it['author-link'],
-                                                       'text' => sprintf(t("%s liked %s's post"), $it['author-name'], $it['pname']),
+                                                       'text' => L10n::t("%s liked %s's post", $it['author-name'], $it['pname']),
                                                        'when' => $default_item_when,
                                                        'ago' => $default_item_ago,
                                                        'seen' => $it['seen']
-                                               );
+                                               ];
                                                break;
 
                                        case ACTIVITY_DISLIKE:
-                                               $notif = array(
+                                               $notif = [
                                                        'label' => 'dislike',
                                                        'link' => System::baseUrl(true) . '/display/' . $it['pguid'],
                                                        'image' => proxy_url($it['author-avatar'], false, PROXY_SIZE_MICRO),
                                                        'url' => $it['author-link'],
-                                                       'text' => sprintf(t("%s disliked %s's post"), $it['author-name'], $it['pname']),
+                                                       'text' => L10n::t("%s disliked %s's post", $it['author-name'], $it['pname']),
                                                        'when' => $default_item_when,
                                                        'ago' => $default_item_ago,
                                                        'seen' => $it['seen']
-                                               );
+                                               ];
                                                break;
 
                                        case ACTIVITY_ATTEND:
-                                               $notif = array(
+                                               $notif = [
                                                        'label' => 'attend',
                                                        'link' => System::baseUrl(true) . '/display/' . $it['pguid'],
                                                        'image' => proxy_url($it['author-avatar'], false, PROXY_SIZE_MICRO),
                                                        'url' => $it['author-link'],
-                                                       'text' => sprintf(t("%s is attending %s's event"), $it['author-name'], $it['pname']),
+                                                       'text' => L10n::t("%s is attending %s's event", $it['author-name'], $it['pname']),
                                                        'when' => $default_item_when,
                                                        'ago' => $default_item_ago,
                                                        'seen' => $it['seen']
-                                               );
+                                               ];
                                                break;
 
                                        case ACTIVITY_ATTENDNO:
-                                               $notif = array(
+                                               $notif = [
                                                        'label' => 'attendno',
                                                        'link' => System::baseUrl(true) . '/display/' . $it['pguid'],
                                                        'image' => proxy_url($it['author-avatar'], false, PROXY_SIZE_MICRO),
                                                        'url' => $it['author-link'],
-                                                       'text' => sprintf(t("%s is not attending %s's event"), $it['author-name'], $it['pname']),
+                                                       'text' => L10n::t("%s is not attending %s's event", $it['author-name'], $it['pname']),
                                                        'when' => $default_item_when,
                                                        'ago' => $default_item_ago,
                                                        'seen' => $it['seen']
-                                               );
+                                               ];
                                                break;
 
                                        case ACTIVITY_ATTENDMAYBE:
-                                               $notif = array(
+                                               $notif = [
                                                        'label' => 'attendmaybe',
                                                        'link' => System::baseUrl(true) . '/display/' . $it['pguid'],
                                                        'image' => proxy_url($it['author-avatar'], false, PROXY_SIZE_MICRO),
                                                        'url' => $it['author-link'],
-                                                       'text' => sprintf(t("%s may attend %s's event"), $it['author-name'], $it['pname']),
+                                                       'text' => L10n::t("%s may attend %s's event", $it['author-name'], $it['pname']),
                                                        'when' => $default_item_when,
                                                        'ago' => $default_item_ago,
                                                        'seen' => $it['seen']
-                                               );
+                                               ];
                                                break;
 
                                        case ACTIVITY_FRIEND:
                                                $xmlhead = "<" . "?xml version='1.0' encoding='UTF-8' ?" . ">";
-                                               $obj = parse_xml_string($xmlhead . $it['object']);
+                                               $obj = XML::parseString($xmlhead . $it['object']);
                                                $it['fname'] = $obj->title;
 
-                                               $notif = array(
+                                               $notif = [
                                                        'label' => 'friend',
                                                        'link' => System::baseUrl(true) . '/display/' . $it['pguid'],
                                                        'image' => proxy_url($it['author-avatar'], false, PROXY_SIZE_MICRO),
                                                        'url' => $it['author-link'],
-                                                       'text' => sprintf(t("%s is now friends with %s"), $it['author-name'], $it['fname']),
+                                                       'text' => L10n::t("%s is now friends with %s", $it['author-name'], $it['fname']),
                                                        'when' => $default_item_when,
                                                        'ago' => $default_item_ago,
                                                        'seen' => $it['seen']
-                                               );
+                                               ];
                                                break;
 
                                        default:
-                                               $notif = array(
+                                               $notif = [
                                                        'label' => $default_item_label,
                                                        'link' => $default_item_link,
                                                        'image' => $default_item_image,
@@ -362,7 +364,7 @@ class NotificationsManager extends BaseObject
                                                        'when' => $default_item_when,
                                                        'ago' => $default_item_ago,
                                                        'seen' => $it['seen']
-                                               );
+                                               ];
                                }
 
                                $arr[] = $notif;
@@ -419,7 +421,7 @@ class NotificationsManager extends BaseObject
        {
                $ident = 'network';
                $total = $this->networkTotal($seen);
-               $notifs = array();
+               $notifs = [];
                $sql_seen = "";
 
                if ($seen === 0) {
@@ -495,7 +497,7 @@ class NotificationsManager extends BaseObject
        {
                $ident = 'system';
                $total = $this->systemTotal($seen);
-               $notifs = array();
+               $notifs = [];
                $sql_seen = "";
 
                if ($seen === 0) {
@@ -531,7 +533,7 @@ class NotificationsManager extends BaseObject
        {
                $myurl = System::baseUrl(true) . '/profile/' . self::getApp()->user['nickname'];
                $myurl = substr($myurl, strpos($myurl, '://') + 3);
-               $myurl = str_replace(array('www.', '.'), array('', '\\.'), $myurl);
+               $myurl = str_replace(['www.', '.'], ['', '\\.'], $myurl);
                $diasp_url = str_replace('/profile/', '/u/', $myurl);
                $sql_extra = sprintf(
                        " AND ( `item`.`author-link` regexp '%s' OR `item`.`tag` regexp '%s' OR `item`.`tag` regexp '%s' ) ",
@@ -593,7 +595,7 @@ class NotificationsManager extends BaseObject
                $ident = 'personal';
                $total = $this->personalTotal($seen);
                $sql_extra = $this->personalSqlExtra();
-               $notifs = array();
+               $notifs = [];
                $sql_seen = "";
 
                if ($seen === 0) {
@@ -618,11 +620,11 @@ class NotificationsManager extends BaseObject
                        $notifs = $this->formatNotifs($r, $ident);
                }
 
-               $arr = array(
+               $arr = [
                        'notifications' => $notifs,
                        'ident' => $ident,
                        'total' => $total,
-               );
+               ];
 
                return $arr;
        }
@@ -673,7 +675,7 @@ class NotificationsManager extends BaseObject
        {
                $ident = 'home';
                $total = $this->homeTotal($seen);
-               $notifs = array();
+               $notifs = [];
                $sql_seen = "";
 
                if ($seen === 0) {
@@ -751,7 +753,7 @@ class NotificationsManager extends BaseObject
        {
                $ident = 'introductions';
                $total = $this->introTotal($all);
-               $notifs = array();
+               $notifs = [];
                $sql_extra = "";
 
                if (!$all) {
@@ -806,21 +808,21 @@ class NotificationsManager extends BaseObject
                        if ($it['fid']) {
                                $return_addr = bin2hex(self::getApp()->user['nickname'] . '@' . self::getApp()->get_hostname() . ((self::getApp()->path) ? '/' . self::getApp()->path : ''));
 
-                               $intro = array(
+                               $intro = [
                                        'label' => 'friend_suggestion',
-                                       'notify_type' => t('Friend Suggestion'),
+                                       'notify_type' => L10n::t('Friend Suggestion'),
                                        'intro_id' => $it['intro_id'],
                                        'madeby' => $it['name'],
                                        'contact_id' => $it['contact-id'],
                                        'photo' => ((x($it, 'fphoto')) ? proxy_url($it['fphoto'], false, PROXY_SIZE_SMALL) : "images/person-175.jpg"),
                                        'name' => $it['fname'],
-                                       'url' => zrl($it['furl']),
+                                       'url' => Profile::zrl($it['furl']),
                                        'hidden' => $it['hidden'] == 1,
                                        'post_newfriend' => (intval(PConfig::get(local_user(), 'system', 'post_newfriend')) ? '1' : 0),
                                        'knowyou' => $knowyou,
                                        'note' => $it['note'],
                                        'request' => $it['frequest'] . '?addr=' . $return_addr,
-                               );
+                               ];
 
                                // Normal connection requests
                        } else {
@@ -832,28 +834,28 @@ class NotificationsManager extends BaseObject
                                        $it['gabout'] = "";
                                        $it['ggender'] = "";
                                }
-                               $intro = array(
+                               $intro = [
                                        'label' => (($it['network'] !== NETWORK_OSTATUS) ? 'friend_request' : 'follower'),
-                                       'notify_type' => (($it['network'] !== NETWORK_OSTATUS) ? t('Friend/Connect Request') : t('New Follower')),
+                                       'notify_type' => (($it['network'] !== NETWORK_OSTATUS) ? L10n::t('Friend/Connect Request') : L10n::t('New Follower')),
                                        'dfrn_id' => $it['issued-id'],
                                        'uid' => $_SESSION['uid'],
                                        'intro_id' => $it['intro_id'],
                                        'contact_id' => $it['contact-id'],
                                        'photo' => ((x($it, 'photo')) ? proxy_url($it['photo'], false, PROXY_SIZE_SMALL) : "images/person-175.jpg"),
                                        'name' => $it['name'],
-                                       'location' => bbcode($it['glocation'], false, false),
-                                       'about' => bbcode($it['gabout'], false, false),
+                                       'location' => BBCode::convert($it['glocation'], false),
+                                       'about' => BBCode::convert($it['gabout'], false),
                                        'keywords' => $it['gkeywords'],
                                        'gender' => $it['ggender'],
                                        'hidden' => $it['hidden'] == 1,
                                        'post_newfriend' => (intval(PConfig::get(local_user(), 'system', 'post_newfriend')) ? '1' : 0),
                                        'url' => $it['url'],
-                                       'zrl' => zrl($it['url']),
+                                       'zrl' => Profile::zrl($it['url']),
                                        'addr' => $it['gaddr'],
                                        'network' => $it['gnetwork'],
                                        'knowyou' => $it['knowyou'],
                                        'note' => $it['note'],
-                               );
+                               ];
                        }
 
                        $arr[] = $intro;