]> git.mxchange.org Git - friendica.git/blobdiff - include/api.php
Update functions and calls
[friendica.git] / include / api.php
index bf038de90d5375d8c6a5f7e62ba453a00c20a58e..da7a83f51c421e5401e287f96dad7f3dd20a56a8 100644 (file)
@@ -6,6 +6,7 @@
  * @todo Automatically detect if incoming data is HTML or BBCode
  */
 use Friendica\App;
+use Friendica\Content\ContactSelector;
 use Friendica\Content\Feature;
 use Friendica\Core\System;
 use Friendica\Core\Config;
@@ -15,6 +16,7 @@ use Friendica\Core\Worker;
 use Friendica\Database\DBM;
 use Friendica\Model\Contact;
 use Friendica\Model\Group;
+use Friendica\Model\Mail;
 use Friendica\Model\Photo;
 use Friendica\Model\User;
 use Friendica\Network\FKOAuth1;
@@ -38,11 +40,9 @@ require_once 'include/html2plain.php';
 require_once 'mod/share.php';
 require_once 'mod/item.php';
 require_once 'include/security.php';
-require_once 'include/contact_selectors.php';
 require_once 'include/html2bbcode.php';
 require_once 'mod/wall_upload.php';
 require_once 'mod/proxy.php';
-require_once 'include/message.php';
 require_once 'include/like.php';
 require_once 'include/plaintext.php';
 
@@ -222,11 +222,11 @@ function api_login(App $a)
        } else {
                $user_id = User::authenticate(trim($user), trim($password));
                if ($user_id) {
-                       $record = dba::select('user', [], ['uid' => $user_id], ['limit' => 1]);
+                       $record = dba::selectFirst('user', [], ['uid' => $user_id]);
                }
        }
 
-       if (!$record || !count($record)) {
+       if (!DBM::is_result($record)) {
                logger('API_login failure: ' . print_r($_SERVER, true), LOGGER_DEBUG);
                header('WWW-Authenticate: Basic realm="Friendica"');
                //header('HTTP/1.0 401 Unauthorized');
@@ -473,7 +473,7 @@ function api_rss_extra(App $a, $arr, $user_info)
  */
 function api_unique_id_to_nurl($id)
 {
-       $r = dba::select('contact', array('nurl'), array('uid' => 0, 'id' => $id), array('limit' => 1));
+       $r = dba::selectFirst('contact', array('nurl'), array('uid' => 0, 'id' => $id));
 
        if (DBM::is_result($r)) {
                return $r["nurl"];
@@ -610,7 +610,7 @@ function api_get_user(App $a, $contact_id = null)
                }
 
                if (DBM::is_result($r)) {
-                       $network_name = network_to_name($r[0]['network'], $r[0]['url']);
+                       $network_name = ContactSelector::networkToName($r[0]['network'], $r[0]['url']);
 
                        // If no nick where given, extract it from the address
                        if (($r[0]['nick'] == "") || ($r[0]['name'] == $r[0]['nick'])) {
@@ -734,7 +734,7 @@ function api_get_user(App $a, $contact_id = null)
                $uinfo[0]['nick'] = api_get_nick($uinfo[0]["url"]);
        }
 
-       $network_name = network_to_name($uinfo[0]['network'], $uinfo[0]['url']);
+       $network_name = ContactSelector::networkToName($uinfo[0]['network'], $uinfo[0]['url']);
 
        $pcontact_id  = Contact::getIdForURL($uinfo[0]['url'], 0, true);
 
@@ -792,7 +792,7 @@ function api_get_user(App $a, $contact_id = null)
 
        // If this is a local user and it uses Frio, we can get its color preferences.
        if ($ret['self']) {
-               $theme_info = dba::select('user', ['theme'], ['uid' => $ret['uid']], ['limit' => 1]);
+               $theme_info = dba::selectFirst('user', ['theme'], ['uid' => $ret['uid']]);
                if ($theme_info['theme'] === 'frio') {
                        $schema = PConfig::get($ret['uid'], 'frio', 'schema');
                        if ($schema && ($schema != '---')) {
@@ -1111,6 +1111,8 @@ function api_statuses_update($type)
                throw new ForbiddenException();
        }
 
+       api_get_user($a);
+
        // convert $_POST array items to the form we use for web posts.
        if (requestdata('htmlstatus')) {
                $txt = requestdata('htmlstatus');
@@ -1286,6 +1288,8 @@ function api_media_upload()
                throw new ForbiddenException();
        }
 
+       api_get_user($a);
+
        if (!x($_FILES, 'media')) {
                // Output error
                throw new BadRequestException("No media.");
@@ -1401,9 +1405,9 @@ function api_status_show($type)
                }
 
                if (($lastwall['item_network'] != "") && ($status["source"] == 'web')) {
-                       $status_info["source"] = network_to_name($lastwall['item_network'], $user_info['url']);
-               } elseif (($lastwall['item_network'] != "") && (network_to_name($lastwall['item_network'], $user_info['url']) != $status_info["source"])) {
-                       $status_info["source"] = trim($status_info["source"].' ('.network_to_name($lastwall['item_network'], $user_info['url']).')');
+                       $status_info["source"] = ContactSelector::networkToName($lastwall['item_network'], $user_info['url']);
+               } elseif (($lastwall['item_network'] != "") && (ContactSelector::networkToName($lastwall['item_network'], $user_info['url']) != $status_info["source"])) {
+                       $status_info["source"] = trim($status_info["source"].' ('.ContactSelector::networkToName($lastwall['item_network'], $user_info['url']).')');
                }
 
                // "uid" and "self" are only needed for some internal stuff, so remove it from here
@@ -1492,11 +1496,11 @@ function api_users_show($type)
                }
 
                if (($lastwall['item_network'] != "") && ($user_info["status"]["source"] == 'web')) {
-                       $user_info["status"]["source"] = network_to_name($lastwall['item_network'], $user_info['url']);
+                       $user_info["status"]["source"] = ContactSelector::networkToName($lastwall['item_network'], $user_info['url']);
                }
 
-               if (($lastwall['item_network'] != "") && (network_to_name($lastwall['item_network'], $user_info['url']) != $user_info["status"]["source"])) {
-                       $user_info["status"]["source"] = trim($user_info["status"]["source"] . ' (' . network_to_name($lastwall['item_network'], $user_info['url']) . ')');
+               if (($lastwall['item_network'] != "") && (ContactSelector::networkToName($lastwall['item_network'], $user_info['url']) != $user_info["status"]["source"])) {
+                       $user_info["status"]["source"] = trim($user_info["status"]["source"] . ' (' . ContactSelector::networkToName($lastwall['item_network'], $user_info['url']) . ')');
                }
        }
 
@@ -2112,6 +2116,8 @@ function api_statuses_repeat($type)
                throw new ForbiddenException();
        }
 
+       api_get_user($a);
+
        // params
        $id = intval($a->argv[3]);
 
@@ -2190,6 +2196,8 @@ function api_statuses_destroy($type)
                throw new ForbiddenException();
        }
 
+       api_get_user($a);
+
        // params
        $id = intval($a->argv[3]);
 
@@ -3123,9 +3131,9 @@ function api_format_items($r, $user_info, $filter_user = false, $type = "json")
                }
 
                if (($item['item_network'] != "") && ($status["source"] == 'web')) {
-                       $status["source"] = network_to_name($item['item_network'], $user_info['url']);
-               } elseif (($item['item_network'] != "") && (network_to_name($item['item_network'], $user_info['url']) != $status["source"])) {
-                       $status["source"] = trim($status["source"].' ('.network_to_name($item['item_network'], $user_info['url']).')');
+                       $status["source"] = ContactSelector::networkToName($item['item_network'], $user_info['url']);
+               } elseif (($item['item_network'] != "") && (ContactSelector::networkToName($item['item_network'], $user_info['url']) != $status["source"])) {
+                       $status["source"] = trim($status["source"].' ('.ContactSelector::networkToName($item['item_network'], $user_info['url']).')');
                }
 
 
@@ -3524,6 +3532,8 @@ function api_ff_ids($type)
                throw new ForbiddenException();
        }
 
+       api_get_user($a);
+
        $stringify_ids = defaults($_REQUEST, 'stringify_ids', false);
 
        $r = q(
@@ -3634,7 +3644,7 @@ function api_direct_messages_new($type)
                }
        }
 
-       $id = send_message($recipient['cid'], $_POST['text'], $sub, $replyto);
+       $id = Mail::send($recipient['cid'], $_POST['text'], $sub, $replyto);
 
        if ($id > -1) {
                $r = q("SELECT * FROM `mail` WHERE id=%d", intval($id));
@@ -4860,22 +4870,22 @@ function api_friendica_remoteauth()
 
        // traditional DFRN
 
-       $r = dba::select('contact', [], ['uid' => api_user(), 'nurl' => $c_url], ['limit' => 1]);
+       $contact = dba::selectFirst('contact', [], ['uid' => api_user(), 'nurl' => $c_url]);
 
-       if (!DBM::is_result($r) || ($r['network'] !== NETWORK_DFRN)) {
+       if (!DBM::is_result($contact) || ($contact['network'] !== NETWORK_DFRN)) {
                throw new BadRequestException("Unknown contact");
        }
 
-       $cid = $r['id'];
+       $cid = $contact['id'];
 
-       $dfrn_id = defaults($r, 'issued-id', $r['dfrn-id']);
+       $dfrn_id = defaults($contact, 'issued-id', $contact['dfrn-id']);
 
-       if ($r['duplex'] && $r['issued-id']) {
-               $orig_id = $r['issued-id'];
+       if ($contact['duplex'] && $contact['issued-id']) {
+               $orig_id = $contact['issued-id'];
                $dfrn_id = '1:' . $orig_id;
        }
-       if ($r['duplex'] && $r['dfrn-id']) {
-               $orig_id = $r['dfrn-id'];
+       if ($contact['duplex'] && $contact['dfrn-id']) {
+               $orig_id = $contact['dfrn-id'];
                $dfrn_id = '0:' . $orig_id;
        }
 
@@ -4891,10 +4901,10 @@ function api_friendica_remoteauth()
                intval(time() + 45)
        );
 
-       logger($r['name'] . ' ' . $sec, LOGGER_DEBUG);
+       logger($contact['name'] . ' ' . $sec, LOGGER_DEBUG);
        $dest = ($url ? '&destination_url=' . $url : '');
        goaway(
-               $r['poll'] . '?dfrn_id=' . $dfrn_id
+               $contact['poll'] . '?dfrn_id=' . $dfrn_id
                . '&dfrn_version=' . DFRN_PROTOCOL_VERSION
                . '&type=profile&sec=' . $sec . $dest . $quiet
        );