]> git.mxchange.org Git - friendica.git/blobdiff - include/api.php
Class file relocations
[friendica.git] / include / api.php
index 153e6c7eeb25f1a48048364494a6bd509a9913b4..c304538af7fd335fe03408f517337c88d2458534 100644 (file)
@@ -9,7 +9,9 @@
 use Friendica\App;
 use Friendica\Core\System;
 use Friendica\Core\Config;
+use Friendica\Core\NotificationsManager;
 use Friendica\Core\Worker;
+use Friendica\Database\DBM;
 
 require_once 'include/HTTPExceptions.php';
 require_once 'include/bbcode.php';
@@ -28,7 +30,6 @@ require_once 'mod/proxy.php';
 require_once 'include/message.php';
 require_once 'include/group.php';
 require_once 'include/like.php';
-require_once 'include/NotificationsManager.php';
 require_once 'include/plaintext.php';
 require_once 'include/xml.php';
 
@@ -211,7 +212,7 @@ $called_api = null;
                                dbesc(trim($user)),
                                dbesc($encrypted)
                        );
-                       if (dbm::is_result($r)) {
+                       if (DBM::is_result($r)) {
                                $record = $r[0];
                        }
                }
@@ -297,7 +298,7 @@ $called_api = null;
                                        $duration = (float) (microtime(true) - $stamp);
                                        logger("API call duration: " . round($duration, 2) . "\t" . $a->query_string, LOGGER_DEBUG);
 
-                                       if (get_config("system", "profiler")) {
+                                       if (Config::get("system", "profiler")) {
                                                $duration = microtime(true)-$a->performance["start"];
 
                                                /// @TODO round() really everywhere?
@@ -312,7 +313,7 @@ $called_api = null;
                                                        LOGGER_DEBUG
                                                );
 
-                                               if (get_config("rendertime", "callstack")) {
+                                               if (Config::get("rendertime", "callstack")) {
                                                        $o = "Database Read:\n";
                                                        foreach ($a->callstack["database"] AS $func => $time) {
                                                                $time = round($time, 3);
@@ -460,7 +461,7 @@ $called_api = null;
        function api_unique_id_to_url($id) {
                $r = dba::select('contact', array('url'), array('uid' => 0, 'id' => $id), array('limit' => 1));
 
-               if (dbm::is_result($r)) {
+               if (DBM::is_result($r)) {
                        return $r["url"];
                } else {
                        return false;
@@ -591,14 +592,14 @@ $called_api = null;
                api_best_nickname($uinfo);
 
                // if the contact wasn't found, fetch it from the contacts with uid = 0
-               if (!dbm::is_result($uinfo)) {
+               if (!DBM::is_result($uinfo)) {
                        $r = array();
 
                        if ($url != "") {
                                $r = q("SELECT * FROM `contact` WHERE `uid` = 0 AND `nurl` = '%s' LIMIT 1", dbesc(normalise_link($url)));
                        }
 
-                       if (dbm::is_result($r)) {
+                       if (DBM::is_result($r)) {
                                $network_name = network_to_name($r[0]['network'], $r[0]['url']);
 
                                // If no nick where given, extract it from the address
@@ -1084,7 +1085,7 @@ $called_api = null;
                        $_REQUEST['type'] = 'net-comment';
                } else {
                        // Check for throttling (maximum posts per day, week and month)
-                       $throttle_day = get_config('system','throttle_limit_day');
+                       $throttle_day = Config::get('system','throttle_limit_day');
                        if ($throttle_day > 0) {
                                $datefrom = date("Y-m-d H:i:s", time() - 24*60*60);
 
@@ -1092,7 +1093,7 @@ $called_api = null;
                                        AND `created` > '%s' AND `id` = `parent`",
                                        intval(api_user()), dbesc($datefrom));
 
-                               if (dbm::is_result($r)) {
+                               if (DBM::is_result($r)) {
                                        $posts_day = $r[0]["posts_day"];
                                } else {
                                        $posts_day = 0;
@@ -1105,7 +1106,7 @@ $called_api = null;
                                }
                        }
 
-                       $throttle_week = get_config('system','throttle_limit_week');
+                       $throttle_week = Config::get('system','throttle_limit_week');
                        if ($throttle_week > 0) {
                                $datefrom = date("Y-m-d H:i:s", time() - 24*60*60*7);
 
@@ -1113,7 +1114,7 @@ $called_api = null;
                                        AND `created` > '%s' AND `id` = `parent`",
                                        intval(api_user()), dbesc($datefrom));
 
-                               if (dbm::is_result($r)) {
+                               if (DBM::is_result($r)) {
                                        $posts_week = $r[0]["posts_week"];
                                } else {
                                        $posts_week = 0;
@@ -1126,7 +1127,7 @@ $called_api = null;
                                }
                        }
 
-                       $throttle_month = get_config('system','throttle_limit_month');
+                       $throttle_month = Config::get('system','throttle_limit_month');
                        if ($throttle_month > 0) {
                                $datefrom = date("Y-m-d H:i:s", time() - 24*60*60*30);
 
@@ -1134,7 +1135,7 @@ $called_api = null;
                                        AND `created` > '%s' AND `id` = `parent`",
                                        intval(api_user()), dbesc($datefrom));
 
-                               if (dbm::is_result($r)) {
+                               if (DBM::is_result($r)) {
                                        $posts_month = $r[0]["posts_month"];
                                } else {
                                        $posts_month = 0;
@@ -1163,7 +1164,7 @@ $called_api = null;
                if (requestdata('media_ids')) {
                        $r = q("SELECT `resource-id`, `scale`, `nickname`, `type` FROM `photo` INNER JOIN `user` ON `user`.`uid` = `photo`.`uid` WHERE `resource-id` IN (SELECT `resource-id` FROM `photo` WHERE `id` = %d) AND `scale` > 0 AND `photo`.`uid` = %d ORDER BY `photo`.`width` DESC LIMIT 1",
                                intval(requestdata('media_ids')), api_user());
-                       if (dbm::is_result($r)) {
+                       if (DBM::is_result($r)) {
                                $phototypes = Photo::supportedTypes();
                                $ext = $phototypes[$r[0]['type']];
                                $_REQUEST['body'] .= "\n\n" . '[url=' . System::baseUrl() . '/photos/' . $r[0]['nickname'] . '/image/' . $r[0]['resource-id'] . ']';
@@ -1258,7 +1259,7 @@ $called_api = null;
                                dbesc(normalise_link($user_info['url']))
                );
 
-               if (dbm::is_result($lastwall)) {
+               if (DBM::is_result($lastwall)) {
                        $lastwall = $lastwall[0];
 
                        $in_reply_to = api_in_reply_to($lastwall);
@@ -1356,7 +1357,7 @@ $called_api = null;
                                dbesc(normalise_link($user_info['url']))
                );
 
-               if (dbm::is_result($lastwall)) {
+               if (DBM::is_result($lastwall)) {
                        $lastwall = $lastwall[0];
 
                        $in_reply_to = api_in_reply_to($lastwall);
@@ -1428,11 +1429,11 @@ $called_api = null;
                if (x($_GET, 'q')) {
                        $r = q("SELECT id FROM `contact` WHERE `uid` = 0 AND `name` = '%s'", dbesc($_GET["q"]));
 
-                       if (!dbm::is_result($r)) {
+                       if (!DBM::is_result($r)) {
                                $r = q("SELECT `id` FROM `contact` WHERE `uid` = 0 AND `nick` = '%s'", dbesc($_GET["q"]));
                        }
 
-                       if (dbm::is_result($r)) {
+                       if (DBM::is_result($r)) {
                                $k = 0;
                                foreach ($r AS $user) {
                                        $user_info = api_get_user($a, $user["id"], "json");
@@ -1681,7 +1682,7 @@ $called_api = null;
                );
 
                /// @TODO How about copying this to above methods which don't check $r ?
-               if (!dbm::is_result($r)) {
+               if (!DBM::is_result($r)) {
                        throw new BadRequestException("There is no status with this id.");
                }
 
@@ -1736,7 +1737,7 @@ $called_api = null;
                logger('API: api_conversation_show: '.$id);
 
                $r = q("SELECT `parent` FROM `item` WHERE `id` = %d", intval($id));
-               if (dbm::is_result($r)) {
+               if (DBM::is_result($r)) {
                        $id = $r[0]["parent"];
                }
 
@@ -1769,7 +1770,7 @@ $called_api = null;
                        intval($start), intval($count)
                );
 
-               if (!dbm::is_result($r)) {
+               if (!DBM::is_result($r)) {
                        throw new BadRequestException("There is no status with this id.");
                }
 
@@ -1827,7 +1828,7 @@ $called_api = null;
                );
 
                /// @TODO other style than above functions!
-               if (dbm::is_result($r) && $r[0]['body'] != "") {
+               if (DBM::is_result($r) && $r[0]['body'] != "") {
                        if (strpos($r[0]['body'], "[/share]") !== false) {
                                $pos = strpos($r[0]['body'], "[share");
                                $post = substr($r[0]['body'], $pos);
@@ -2093,7 +2094,7 @@ $called_api = null;
                $item = q("SELECT * FROM `item` WHERE `id`=%d AND `uid`=%d LIMIT 1",
                                $itemid, api_user());
 
-               if (!dbm::is_result($item) || count($item) == 0) {
+               if (!DBM::is_result($item) || count($item) == 0) {
                        throw new BadRequestException("Invalid item.");
                }
 
@@ -2464,7 +2465,7 @@ $called_api = null;
                                if ($image) {
                                        // If image cache is activated, then use the following sizes:
                                        // thumb  (150), small (340), medium (600) and large (1024)
-                                       if (!get_config("system", "proxy_disabled")) {
+                                       if (!Config::get("system", "proxy_disabled")) {
                                                $media_url = proxy_url($url);
 
                                                $sizes = array();
@@ -3004,7 +3005,7 @@ $called_api = null;
                        intval(api_user())
                );
 
-               if (!dbm::is_result($r)) {
+               if (!DBM::is_result($r)) {
                        return;
                }
 
@@ -3138,7 +3139,7 @@ $called_api = null;
                        intval($id));
 
                // error message if specified id is not in database
-               if (!dbm::is_result($r)) {
+               if (!DBM::is_result($r)) {
                        if ($verbose == "true") {
                                $answer = array('result' => 'error', 'message' => 'message id not in database');
                                return api_format_data("direct_messages_delete", $type, array('$result' => $answer));
@@ -3229,7 +3230,7 @@ $called_api = null;
                                intval($since_id),
                                intval($start), intval($count)
                );
-               if ($verbose == "true" && !dbm::is_result($r)) {
+               if ($verbose == "true" && !DBM::is_result($r)) {
                        $answer = array('result' => 'error', 'message' => 'no mails available');
                        return api_format_data("direct_messages_all", $type, array('$result' => $answer));
                }
@@ -3334,7 +3335,7 @@ $called_api = null;
                $r = q("SELECT DISTINCT `resource-id` FROM `photo` WHERE `uid` = %d AND `album` = '%s'",
                                intval(api_user()),
                                dbesc($album));
-               if (!dbm::is_result($r))
+               if (!DBM::is_result($r))
                        throw new BadRequestException("album not available");
 
                // function for setting the items to "deleted = 1" which ensures that comments, likes etc. are not shown anymore
@@ -3345,7 +3346,7 @@ $called_api = null;
                                                dbesc($rr['resource-id'])
                                                );
 
-                       if (!dbm::is_result($photo_item)) {
+                       if (!DBM::is_result($photo_item)) {
                                throw new InternalServerErrorException("problem with deleting items occured");
                        }
                        drop_item($photo_item[0]['id'],false);
@@ -3391,7 +3392,7 @@ $called_api = null;
                $r = q("SELECT `id` FROM `photo` WHERE `uid` = %d AND `album` = '%s'",
                                intval(api_user()),
                                dbesc($album));
-               if (!dbm::is_result($r)) {
+               if (!DBM::is_result($r)) {
                        throw new BadRequestException("album not available");
                }
                // now let's update all photos to the albumname
@@ -3431,7 +3432,7 @@ $called_api = null;
                        'image/gif' => 'gif'
                );
                $data = array('photo'=>array());
-               if (dbm::is_result($r)) {
+               if (DBM::is_result($r)) {
                        foreach ($r as $rr) {
                                $photo = array();
                                $photo['id'] = $rr['resource-id'];
@@ -3500,7 +3501,7 @@ $called_api = null;
                                        intval(api_user()),
                                        dbesc($photo_id),
                                        dbesc($album));
-                       if (!dbm::is_result($r)) {
+                       if (!DBM::is_result($r)) {
                                throw new BadRequestException("photo not available");
                        }
                }
@@ -3620,7 +3621,7 @@ $called_api = null;
                                intval(api_user()),
                                dbesc($photo_id)
                        );
-               if (!dbm::is_result($r)) {
+               if (!DBM::is_result($r)) {
                        throw new BadRequestException("photo not available");
                }
                // now we can perform on the deletion of the photo
@@ -3636,7 +3637,7 @@ $called_api = null;
                                dbesc($photo_id)
                                );
 
-                       if (!dbm::is_result($photo_item)) {
+                       if (!DBM::is_result($photo_item)) {
                                throw new InternalServerErrorException("problem with deleting items occured");
                        }
                        // function for setting the items to "deleted = 1" which ensures that comments, likes etc. are not shown anymore
@@ -3699,7 +3700,7 @@ $called_api = null;
                                intval(api_user()),
                                intval($profileid));
                        // error message if specified profile id is not in database
-                       if (!dbm::is_result($r)) {
+                       if (!DBM::is_result($r)) {
                                throw new BadRequestException("profile_id not available");
                        }
                        $is_default_profile = $r['profile'];
@@ -3761,7 +3762,7 @@ $called_api = null;
                // Update global directory in background
                //$user = api_get_user(get_app());
                $url = System::baseUrl() . '/profile/' . get_app()->user['nickname'];
-               if ($url && strlen(get_config('system', 'directory'))) {
+               if ($url && strlen(Config::get('system', 'directory'))) {
                        Worker::add(PRIORITY_LOW, "directory", $url);
                }
 
@@ -3804,7 +3805,7 @@ $called_api = null;
                        $contact = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d",
                                                        intval($cid),
                                                        intval(api_user()));
-                       $contact_not_found |= !dbm::is_result($contact);
+                       $contact_not_found |= !DBM::is_result($contact);
                }
                return $contact_not_found;
        }
@@ -3854,7 +3855,7 @@ $called_api = null;
                        throw new InternalServerErrorException("image size exceeds PHP config settings, file was rejected by server");
                }
                // check against max upload size within Friendica instance
-               $maximagesize = get_config('system', 'maximagesize');
+               $maximagesize = Config::get('system', 'maximagesize');
                if (($maximagesize) && ($filesize > $maximagesize)) {
                        $formattedBytes = formatBytes($maximagesize);
                        throw new InternalServerErrorException("image size exceeds Friendica config setting (uploaded size: $formattedBytes)");
@@ -3872,7 +3873,7 @@ $called_api = null;
                @unlink($src);
 
                // check max length of images on server
-               $max_length = get_config('system', 'max_image_length');
+               $max_length = Config::get('system', 'max_image_length');
                if (! $max_length) {
                        $max_length = MAX_IMAGE_LENGTH;
                }
@@ -4020,7 +4021,7 @@ $called_api = null;
                );
 
                // prepare output data for photo
-               if (dbm::is_result($r)) {
+               if (DBM::is_result($r)) {
                        $data = array('photo' => $r[0]);
                        $data['photo']['id'] = $data['photo']['resource-id'];
                        if ($scale !== false) {
@@ -4129,7 +4130,7 @@ $called_api = null;
                        intval(api_user())
                );
 
-               if ((! dbm::is_result($r)) || ($r[0]['network'] !== NETWORK_DFRN)) {
+               if ((! DBM::is_result($r)) || ($r[0]['network'] !== NETWORK_DFRN)) {
                        throw new BadRequestException("Unknown contact");
                }
 
@@ -4276,7 +4277,7 @@ $called_api = null;
                $r = q("SELECT `nick` FROM `contact` WHERE `uid` = 0 AND `nurl` = '%s'",
                        dbesc(normalise_link($profile)));
 
-               if (dbm::is_result($r)) {
+               if (DBM::is_result($r)) {
                        $nick = $r[0]["nick"];
                }
 
@@ -4284,7 +4285,7 @@ $called_api = null;
                        $r = q("SELECT `nick` FROM `contact` WHERE `uid` = 0 AND `nurl` = '%s'",
                                dbesc(normalise_link($profile)));
 
-                       if (dbm::is_result($r)) {
+                       if (DBM::is_result($r)) {
                                $nick = $r[0]["nick"];
                        }
                }
@@ -4355,7 +4356,7 @@ $called_api = null;
                                intval($item['uid']),
                                dbesc($item['thr-parent']));
 
-                       if (dbm::is_result($r)) {
+                       if (DBM::is_result($r)) {
                                $in_reply_to['status_id'] = intval($r[0]['id']);
                        } else {
                                $in_reply_to['status_id'] = intval($item['parent']);
@@ -4369,7 +4370,7 @@ $called_api = null;
                                intval($in_reply_to['status_id'])
                        );
 
-                       if (dbm::is_result($r)) {
+                       if (DBM::is_result($r)) {
                                if ($r[0]['nick'] == "") {
                                        $r[0]['nick'] = api_get_nick($r[0]["url"]);
                                }
@@ -4503,7 +4504,7 @@ $called_api = null;
                                intval($uid),
                                intval($gid));
                        // error message if specified gid is not in database
-                       if (!dbm::is_result($r))
+                       if (!DBM::is_result($r))
                                throw new BadRequestException("gid not available");
                }
                else
@@ -4558,7 +4559,7 @@ $called_api = null;
                        intval($uid),
                        intval($gid));
                // error message if specified gid is not in database
-               if (!dbm::is_result($r))
+               if (!DBM::is_result($r))
                        throw new BadRequestException('gid not available');
 
                // get data of the specified group id and group name
@@ -4567,7 +4568,7 @@ $called_api = null;
                        intval($gid),
                        dbesc($name));
                // error message if specified gid is not in database
-               if (!dbm::is_result($rname))
+               if (!DBM::is_result($rname))
                        throw new BadRequestException('wrong group name');
 
                // delete group
@@ -4606,7 +4607,7 @@ $called_api = null;
                        intval($uid),
                        dbesc($name));
                // error message if specified group name already exists
-               if (dbm::is_result($rname))
+               if (DBM::is_result($rname))
                        throw new BadRequestException('group name already exists');
 
                // check if specified group name is a deleted group
@@ -4614,7 +4615,7 @@ $called_api = null;
                        intval($uid),
                        dbesc($name));
                // error message if specified group name already exists
-               if (dbm::is_result($rname))
+               if (DBM::is_result($rname))
                        $reactivate_group = true;
 
                // create group
@@ -4845,7 +4846,7 @@ $called_api = null;
                        intval($uid));
 
                // error message if specified id is not in database
-               if (!dbm::is_result($r)) {
+               if (!DBM::is_result($r)) {
                        $answer = array('result' => 'error', 'message' => 'message id not in database');
                        return api_format_data("direct_messages_setseen", $type, array('$result' => $answer));
                }
@@ -4903,7 +4904,7 @@ $called_api = null;
                $profile_url = $user_info["url"];
 
                // message if nothing was found
-               if (!dbm::is_result($r)) {
+               if (!DBM::is_result($r)) {
                        $success = array('success' => false, 'search_results' => 'problem with query');
                } elseif (count($r) == 0) {
                        $success = array('success' => false, 'search_results' => 'nothing found');
@@ -4947,7 +4948,7 @@ $called_api = null;
 
                // retrieve general information about profiles for user
                $multi_profiles = feature_enabled(api_user(),'multi_profiles');
-               $directory = get_config('system', 'directory');
+               $directory = Config::get('system', 'directory');
 
                // get data of the specified profile id or all profiles of the user if not specified
                if ($profileid != 0) {
@@ -4956,7 +4957,7 @@ $called_api = null;
                                intval($profileid));
 
                        // error message if specified gid is not in database
-                       if (!dbm::is_result($r)) {
+                       if (!DBM::is_result($r)) {
                                throw new BadRequestException("profile_id not available");
                        }
                } else {