]> git.mxchange.org Git - friendica.git/blobdiff - include/like.php
Merge pull request #4312 from zeroadam/feature/L10n
[friendica.git] / include / like.php
index 05bb758c2a08b8e0c136edf469f2d1c64a8901da..ae344d4269a3358ea03e7304832697efa6eeaef8 100644 (file)
@@ -1,6 +1,10 @@
 <?php
-
+/**
+ * @file include/like.php
+ */
 use Friendica\App;
+use Friendica\Core\Addon;
+use Friendica\Core\L10n;
 use Friendica\Core\System;
 use Friendica\Core\Worker;
 use Friendica\Database\DBM;
@@ -30,31 +34,31 @@ function do_like($item_id, $verb) {
 
        switch ($verb) {
                case 'like':
-                       $bodyverb = t('%1$s likes %2$s\'s %3$s');
+                       $bodyverb = L10n::t('%1$s likes %2$s\'s %3$s');
                        $activity = ACTIVITY_LIKE;
                        break;
                case 'unlike':
-                       $bodyverb = t('%1$s doesn\'t like %2$s\'s %3$s');
+                       $bodyverb = L10n::t('%1$s doesn\'t like %2$s\'s %3$s');
                        $activity = ACTIVITY_LIKE;
                        break;
                case 'dislike':
                case 'undislike':
-                       $bodyverb = t('%1$s doesn\'t like %2$s\'s %3$s');
+                       $bodyverb = L10n::t('%1$s doesn\'t like %2$s\'s %3$s');
                        $activity = ACTIVITY_DISLIKE;
                        break;
                case 'attendyes':
                case 'unattendyes':
-                       $bodyverb = t('%1$s is attending %2$s\'s %3$s');
+                       $bodyverb = L10n::t('%1$s is attending %2$s\'s %3$s');
                        $activity = ACTIVITY_ATTEND;
                        break;
                case 'attendno':
                case 'unattendno':
-                       $bodyverb = t('%1$s is not attending %2$s\'s %3$s');
+                       $bodyverb = L10n::t('%1$s is not attending %2$s\'s %3$s');
                        $activity = ACTIVITY_ATTENDNO;
                        break;
                case 'attendmaybe':
                case 'unattendmaybe':
-                       $bodyverb = t('%1$s may attend %2$s\'s %3$s');
+                       $bodyverb = L10n::t('%1$s may attend %2$s\'s %3$s');
                        $activity = ACTIVITY_ATTENDMAYBE;
                        break;
                default:
@@ -79,27 +83,28 @@ function do_like($item_id, $verb) {
        }
 
        $item = $items[0];
+       $uid = $item['uid'];
 
-       if (!can_write_wall($a, $item['uid']) && ($item['uid'] != 0)) {
-               logger('like: unable to write on wall ' . $item['uid']);
+       if (($uid == 0) && local_user()) {
+               $uid = local_user();
+       }
+
+       if (!can_write_wall($uid)) {
+               logger('like: unable to write on wall ' . $uid);
                return false;
        }
 
        // Retrieves the local post owner
-       if ($item['uid'] != 0) {
-               $owners = q("SELECT `contact`.* FROM `contact`
-                       WHERE `contact`.`self`
-                       AND `contact`.`uid` = %d",
-                       intval($item['uid'])
-               );
-               if (DBM::is_result($owners)) {
-                       $owner_self_contact = $owners[0];
-               } else {
-                       logger('like: unknown owner ' . $item['uid']);
-                       return false;
-               }
+       $owners = q("SELECT `contact`.* FROM `contact`
+               WHERE `contact`.`self`
+               AND `contact`.`uid` = %d",
+               intval($uid)
+       );
+       if (DBM::is_result($owners)) {
+               $owner_self_contact = $owners[0];
        } else {
-               $owner_self_contact = ['uid' => 0, 'nick' => 'feed-item'];
+               logger('like: unknown owner ' . $uid);
+               return false;
        }
 
        // Retrieve the current logged in user's public contact
@@ -116,11 +121,11 @@ function do_like($item_id, $verb) {
        }
 
        // Contact-id is the uid-dependant author contact
-       if (local_user() == $item['uid']) {
+       if (local_user() == $uid) {
                $item_contact_id = $owner_self_contact['id'];
                $item_contact = $owner_self_contact;
        } else {
-               $item_contact_id = Contact::getIdForURL($author_contact['url'], $item['uid']);
+               $item_contact_id = Contact::getIdForURL($author_contact['url'], $uid);
 
                $contacts = q("SELECT * FROM `contact` WHERE `id` = %d",
                        intval($item_contact_id)
@@ -167,7 +172,7 @@ function do_like($item_id, $verb) {
                // Clean up the Diaspora signatures for this like
                // Go ahead and do it even if Diaspora support is disabled. We still want to clean up
                // if it had been enabled in the past
-               dba::delete('sign', array('iid' => $like_item['id']));
+               dba::delete('sign', ['iid' => $like_item['id']]);
 
                $like_item_id = $like_item['id'];
                Worker::add(PRIORITY_HIGH, "Notifier", "like", $like_item_id);
@@ -183,9 +188,9 @@ function do_like($item_id, $verb) {
        }
 
        // Else or if event verb different from existing row, create a new item row
-       $post_type = (($item['resource-id']) ? t('photo') : t('status'));
+       $post_type = (($item['resource-id']) ? L10n::t('photo') : L10n::t('status'));
        if ($item['object-type'] === ACTIVITY_OBJ_EVENT) {
-               $post_type = t('event');
+               $post_type = L10n::t('event');
        }
        $objtype = $item['resource-id'] ? ACTIVITY_OBJ_IMAGE : ACTIVITY_OBJ_NOTE ;
        $link = xmlify('<link rel="alternate" type="text/html" href="' . System::baseUrl() . '/display/' . $owner_self_contact['nick'] . '/' . $item['id'] . '" />' . "\n") ;
@@ -207,7 +212,7 @@ EOT;
        $alink = '[url=' . $item['author-link'] . ']' . $item['author-name'] . '[/url]';
        $plink = '[url=' . System::baseUrl() . '/display/' . $owner_self_contact['nick'] . '/' . $item['id'] . ']' . $post_type . '[/url]';
 
-       $new_item = array(
+       $new_item = [
                'guid'          => get_guid(32),
                'uri'           => item_new_uri($a->get_hostname(), $item['uid']),
                'uid'           => $item['uid'],
@@ -237,16 +242,14 @@ EOT;
                'deny_gid'      => $item['deny_gid'],
                'visible'       => 1,
                'unseen'        => 1,
-               'last-child'    => 0
-       );
+       ];
 
        $new_item_id = item_store($new_item);
 
        // @todo: Explain this block
        if (! $item['visible']) {
-               q("UPDATE `item` SET `visible` = 1 WHERE `id` = %d AND `uid` = %d",
-                       intval($item['id']),
-                       intval($item['uid'])
+               q("UPDATE `item` SET `visible` = 1 WHERE `id` = %d",
+                       intval($item['id'])
                );
        }
 
@@ -255,7 +258,7 @@ EOT;
 
        $new_item['id'] = $new_item_id;
 
-       call_hooks('post_local_end', $new_item);
+       Addon::callHooks('post_local_end', $new_item);
 
        Worker::add(PRIORITY_HIGH, "Notifier", "like", $new_item_id);