]> git.mxchange.org Git - friendica.git/blobdiff - include/api.php
Central item expiration routine for external items
[friendica.git] / include / api.php
index b30442cd8133d36f6f50152ba4a79b8e6f56f9c9..64afa8c14833f7a68814babbc3f1f1b84d5ab3da 100644 (file)
@@ -6,7 +6,8 @@
  * @todo Automatically detect if incoming data is HTML or BBCode
  */
 
-use \Friendica\Core\Config;
+use Friendica\App;
+use Friendica\Core\Config;
 
 require_once 'include/HTTPExceptions.php';
 require_once 'include/bbcode.php';
@@ -455,10 +456,13 @@ $called_api = null;
         *              Contact url or False if contact id is unknown
         */
        function api_unique_id_to_url($id) {
-               $r = q("SELECT `url` FROM `contact` WHERE `uid` = 0 AND `id` = %d LIMIT 1",
-                       intval($id));
+               $r = dba::select('contact', array('url'), array('uid' => 0, 'id' => $id), array('limit' => 1));
 
-               return (dbm::is_result($r) && $r[0]["url"]);
+               if (dbm::is_result($r)) {
+                       return $r["url"];
+               } else {
+                       return false;
+               }
        }
 
        /**
@@ -525,6 +529,15 @@ $called_api = null;
                        }
                }
 
+               if (is_null($user) && x($_GET, 'profileurl')) {
+                       $user = dbesc(normalise_link($_GET['profileurl']));
+                       $nick = $user;
+                       $extra_query = "AND `contact`.`nurl` = '%s' ";
+                       if (api_user() !== false) {
+                               $extra_query .= "AND `contact`.`uid`=".intval(api_user());
+                       }
+               }
+
                if (is_null($user) AND ($a->argc > (count($called_api) - 1)) AND (count($called_api) > 0)) {
                        $argid = count($called_api);
                        list($user, $null) = explode(".", $a->argv[$argid]);
@@ -1400,6 +1413,7 @@ $called_api = null;
 
        /// @TODO move to top of file or somewhere better
        api_register_func('api/users/show','api_users_show');
+       api_register_func('api/externalprofile/show','api_users_show');
 
        function api_users_search($type) {
 
@@ -3016,8 +3030,9 @@ $called_api = null;
                        api_best_nickname($r);
 
                        $recipient = api_get_user($a, $r[0]['nurl']);
-               } else
+               } else {
                        $recipient = api_get_user($a, $_POST['user_id']);
+               }
 
                $replyto = '';
                $sub     = '';
@@ -3325,7 +3340,7 @@ $called_api = null;
                        $answer = array('result' => 'deleted', 'message' => 'album `' . $album . '` with all containing photos has been deleted.');
                        return api_format_data("photoalbum_delete", $type, array('$result' => $answer));
                } else {
-                       throw new BadRequestException("unknown error - deleting from database failed");
+                       throw new InternalServerErrorException("unknown error - deleting from database failed");
                }
 
        }
@@ -3352,7 +3367,7 @@ $called_api = null;
                        throw new BadRequestException("no new albumname specified");
                }
                // check if album is existing
-               $r = q("SELECT * FROM `photo` WHERE `uid` = %d AND `album` = '%s'",
+               $r = q("SELECT `id` FROM `photo` WHERE `uid` = %d AND `album` = '%s'",
                                intval(api_user()),
                                dbesc($album));
                if (!dbm::is_result($r)) {
@@ -3369,7 +3384,7 @@ $called_api = null;
                        $answer = array('result' => 'updated', 'message' => 'album `' . $album . '` with all containing photos has been renamed to `' . $album_new . '`.');
                        return api_format_data("photoalbum_update", $type, array('$result' => $answer));
                } else {
-                       throw new BadRequestException("unknown error - updating in database failed");
+                       throw new InternalServerErrorException("unknown error - updating in database failed");
                }
        }
 
@@ -3390,9 +3405,9 @@ $called_api = null;
                        intval(local_user())
                );
                $typetoext = array(
-               'image/jpeg' => 'jpg',
-               'image/png' => 'png',
-               'image/gif' => 'gif'
+                       'image/jpeg' => 'jpg',
+                       'image/png' => 'png',
+                       'image/gif' => 'gif'
                );
                $data = array('photo'=>array());
                if (dbm::is_result($r)) {
@@ -3460,7 +3475,7 @@ $called_api = null;
                        $mode = "update";
 
                        // check if photo is existing in database
-                       $r = q("SELECT * FROM `photo` WHERE `uid` = %d AND `resource-id` = '%s' AND `album` = '%s'",
+                       $r = q("SELECT `id` FROM `photo` WHERE `uid` = %d AND `resource-id` = '%s' AND `album` = '%s'",
                                        intval(api_user()),
                                        dbesc($photo_id),
                                        dbesc($album));
@@ -3487,7 +3502,7 @@ $called_api = null;
                        if (!is_null($data)) {
                                return api_format_data("photo_create", $type, $data);
                        } else {
-                               throw new BadRequestException("unknown error - uploading photo failed, see Friendica log for more information");
+                               throw new InternalServerErrorException("unknown error - uploading photo failed, see Friendica log for more information");
                        }
                }
 
@@ -3554,10 +3569,10 @@ $called_api = null;
                                        $answer = array('result' => 'cancelled', 'message' => 'Nothing to update for image id `' . $photo_id . '`.');
                                        return api_format_data("photo_update", $type, array('$result' => $answer));
                                }
-                               throw new BadRequestException("unknown error - update photo entry in database failed");
+                               throw new InternalServerErrorException("unknown error - update photo entry in database failed");
                        }
                }
-               throw new BadRequestException("unknown error - this error on uploading or updating a photo should never happen");
+               throw new InternalServerErrorException("unknown error - this error on uploading or updating a photo should never happen");
        }
 
 
@@ -3580,7 +3595,7 @@ $called_api = null;
                        throw new BadRequestException("no photo_id specified");
                }
                // check if photo is existing in database
-               $r = q("SELECT * FROM `photo` WHERE `uid` = %d AND `resource-id` = '%s'",
+               $r = q("SELECT `id` FROM `photo` WHERE `uid` = %d AND `resource-id` = '%s'",
                                intval(api_user()),
                                dbesc($photo_id)
                        );
@@ -3659,7 +3674,7 @@ $called_api = null;
 
                // check if specified profile id is valid
                if ($profileid != 0) {
-                       $r = q("SELECT * FROM `profile` WHERE `uid` = %d AND `id` = %d",
+                       $r = q("SELECT `id` FROM `profile` WHERE `uid` = %d AND `id` = %d",
                                intval(api_user()),
                                intval($profileid));
                        // error message if specified profile id is not in database
@@ -3706,7 +3721,7 @@ $called_api = null;
                                intval(local_user())
                        );
                } else {
-                       $r = q("update profile set photo = '%s', thumb = '%s' where id = %d and uid = %d",
+                       $r = q("UPDATE `profile` SET `photo` = '%s', `thumb` = '%s' WHERE `id` = %d AND `uid` = %d",
                                dbesc(App::get_baseurl() . '/photo/' . $data['photo']['id'] . '-4.' . $filetype),
                                dbesc(App::get_baseurl() . '/photo/' . $data['photo']['id'] . '-5.' . $filetype),
                                intval($_REQUEST['profile']),