]> git.mxchange.org Git - friendica.git/blobdiff - include/api.php
Features to src
[friendica.git] / include / api.php
index 33624dcf6ee3d6d8d57d2c8977d913581d342f24..4055f2b4ceeee6cf5e9f35a962bb4a334ba63d62 100644 (file)
@@ -5,24 +5,34 @@
  *
  * @todo Automatically detect if incoming data is HTML or BBCode
  */
-
 use Friendica\App;
+use Friendica\Content\Features;
 use Friendica\Core\System;
 use Friendica\Core\Config;
 use Friendica\Core\NotificationsManager;
 use Friendica\Core\Worker;
 use Friendica\Database\DBM;
+use Friendica\Model\User;
+use Friendica\Network\HTTPException;
+use Friendica\Network\HTTPException\BadRequestException;
+use Friendica\Network\HTTPException\ForbiddenException;
+use Friendica\Network\HTTPException\InternalServerErrorException;
+use Friendica\Network\HTTPException\MethodNotAllowedException;
+use Friendica\Network\HTTPException\NotFoundException;
+use Friendica\Network\HTTPException\NotImplementedException;
+use Friendica\Network\HTTPException\UnauthorizedException;
+use Friendica\Network\HTTPException\TooManyRequestsException;
+use Friendica\Object\Contact;
+use Friendica\Object\Photo;
 use Friendica\Protocol\Diaspora;
 use Friendica\Util\XML;
 
-require_once 'include/HTTPExceptions.php';
 require_once 'include/bbcode.php';
 require_once 'include/datetime.php';
 require_once 'include/conversation.php';
 require_once 'include/oauth.php';
 require_once 'include/html2plain.php';
 require_once 'mod/share.php';
-require_once 'include/Photo.php';
 require_once 'mod/item.php';
 require_once 'include/security.php';
 require_once 'include/contact_selectors.php';
@@ -181,7 +191,6 @@ function api_login(App $a)
 
        $user = $_SERVER['PHP_AUTH_USER'];
        $password = $_SERVER['PHP_AUTH_PW'];
-       $encrypted = hash('whirlpool', trim($password));
 
        // allow "user@server" login (but ignore 'server' part)
        $at = strstr($user, "@", true);
@@ -209,16 +218,9 @@ function api_login(App $a)
        if (($addon_auth['authenticated']) && (count($addon_auth['user_record']))) {
                $record = $addon_auth['user_record'];
        } else {
-               // process normal login request
-               $r = q(
-                       "SELECT * FROM `user` WHERE (`email` = '%s' OR `nickname` = '%s')
-                       AND `password` = '%s' AND NOT `blocked` AND NOT `account_expired` AND NOT `account_removed` AND `verified` LIMIT 1",
-                       dbesc(trim($user)),
-                       dbesc(trim($user)),
-                       dbesc($encrypted)
-               );
-               if (DBM::is_result($r)) {
-                       $record = $r[0];
+               $user_id = User::authenticate(trim($user), trim($password));
+               if ($user_id) {
+                       $record = dba::select('user', [], ['uid' => $user_id], ['limit' => 1]);
                }
        }
 
@@ -649,7 +651,7 @@ function api_get_user(App $a, $contact_id = null, $type = "json")
                                'notifications' => false,
                                'statusnet_profile_url' => $r[0]["url"],
                                'uid' => 0,
-                               'cid' => get_contact($r[0]["url"], api_user(), true),
+                               'cid' => Contact::getIdForURL($r[0]["url"], api_user(), true),
                                'self' => 0,
                                'network' => $r[0]["network"],
                        );
@@ -737,7 +739,7 @@ function api_get_user(App $a, $contact_id = null, $type = "json")
 
        $network_name = network_to_name($uinfo[0]['network'], $uinfo[0]['url']);
 
-       $pcontact_id  = get_contact($uinfo[0]['url'], 0, true);
+       $pcontact_id  = Contact::getIdForURL($uinfo[0]['url'], 0, true);
 
        $ret = array(
                'id' => intval($pcontact_id),
@@ -901,7 +903,7 @@ function api_create_xml($data, $root_element)
 
        $data3 = array($root_element => $data2);
 
-       $ret = XML::from_array($data3, $xml, false, $namespaces);
+       $ret = XML::fromArray($data3, $xml, false, $namespaces);
        return $ret;
 }
 
@@ -2375,7 +2377,7 @@ function api_get_attachments(&$body)
        $attachments = array();
 
        foreach ($images[1] as $image) {
-               $imagedata = get_photo_info($image);
+               $imagedata = Photo::getInfoFromURL($image);
 
                if ($imagedata) {
                        $attachments[] = array("url" => $image, "mimetype" => $imagedata["mime"], "size" => $imagedata["size"]);
@@ -2507,7 +2509,7 @@ function api_get_entitities(&$text, $bbcode)
 
                $start = iconv_strpos($text, $url, $offset, "UTF-8");
                if (!($start === false)) {
-                       $image = get_photo_info($url);
+                       $image = Photo::getInfoFromURL($url);
                        if ($image) {
                                // If image cache is activated, then use the following sizes:
                                // thumb  (150), small (340), medium (600) and large (1024)
@@ -2515,19 +2517,19 @@ function api_get_entitities(&$text, $bbcode)
                                        $media_url = proxy_url($url);
 
                                        $sizes = array();
-                                       $scale = scale_image($image[0], $image[1], 150);
+                                       $scale = Photo::scaleImageTo($image[0], $image[1], 150);
                                        $sizes["thumb"] = array("w" => $scale["width"], "h" => $scale["height"], "resize" => "fit");
 
                                        if (($image[0] > 150) || ($image[1] > 150)) {
-                                               $scale = scale_image($image[0], $image[1], 340);
+                                               $scale = Photo::scaleImageTo($image[0], $image[1], 340);
                                                $sizes["small"] = array("w" => $scale["width"], "h" => $scale["height"], "resize" => "fit");
                                        }
 
-                                       $scale = scale_image($image[0], $image[1], 600);
+                                       $scale = Photo::scaleImageTo($image[0], $image[1], 600);
                                        $sizes["medium"] = array("w" => $scale["width"], "h" => $scale["height"], "resize" => "fit");
 
                                        if (($image[0] > 600) || ($image[1] > 600)) {
-                                               $scale = scale_image($image[0], $image[1], 1024);
+                                               $scale = Photo::scaleImageTo($image[0], $image[1], 1024);
                                                $sizes["large"] = array("w" => $scale["width"], "h" => $scale["height"], "resize" => "fit");
                                        }
                                } else {
@@ -3434,11 +3436,7 @@ function api_fr_photoalbum_delete($type)
        }
 
        // now let's delete all photos from the album
-       $result = q(
-               "DELETE FROM `photo` WHERE `uid` = %d AND `album` = '%s'",
-               intval(api_user()),
-               dbesc($album)
-       );
+       $result = dba::delete('photo', array('uid' => api_user(), 'album' => $album));
 
        // return success of deletion or error message
        if ($result) {
@@ -3721,11 +3719,7 @@ function api_fr_photo_delete($type)
                throw new BadRequestException("photo not available");
        }
        // now we can perform on the deletion of the photo
-       $result = q(
-               "DELETE FROM `photo` WHERE `uid` = %d AND `resource-id` = '%s'",
-               intval(api_user()),
-               dbesc($photo_id)
-       );
+       $result = dba::delete('photo', array('uid' => api_user(), 'resource-id' => $photo_id));
 
        // return success of deletion or error message
        if ($result) {
@@ -3870,10 +3864,10 @@ function api_account_update_profile_image($type)
        //$user = api_get_user(get_app());
        $url = System::baseUrl() . '/profile/' . get_app()->user['nickname'];
        if ($url && strlen(Config::get('system', 'directory'))) {
-               Worker::add(PRIORITY_LOW, "directory", $url);
+               Worker::add(PRIORITY_LOW, "Directory", $url);
        }
 
-       Worker::add(PRIORITY_LOW, 'profile_update', api_user());
+       Worker::add(PRIORITY_LOW, 'ProfileUpdate', api_user());
 
        // output for client
        if ($data) {
@@ -3952,7 +3946,7 @@ function save_media_to_database($mediatype, $media, $type, $album, $allow_cid, $
        }
 
        if ($filetype == "") {
-               $filetype=guess_image_type($filename);
+               $filetype=Photo::guessImageType($filename);
        }
        $imagedata = getimagesize($src);
        if ($imagedata) {
@@ -3977,7 +3971,7 @@ function save_media_to_database($mediatype, $media, $type, $album, $allow_cid, $
        // create Photo instance with the data of the image
        $imagedata = @file_get_contents($src);
        $ph = new Photo($imagedata, $filetype);
-       if (! $ph->is_valid()) {
+       if (! $ph->isValid()) {
                throw new InternalServerErrorException("unable to process image data");
        }
 
@@ -4298,7 +4292,7 @@ function api_share_as_retweet(&$item)
 {
        $body = trim($item["body"]);
 
-       if (Diaspora::is_reshare($body, false)===false) {
+       if (Diaspora::isReshare($body, false)===false) {
                return false;
        }
 
@@ -4306,7 +4300,7 @@ function api_share_as_retweet(&$item)
        $attributes = preg_replace("/\[share(.*?)\]\s?(.*?)\s?\[\/share\]\s?/ism", "$1", $body);
        /*
                * Skip if there is no shared message in there
-               * we already checked this in diaspora::is_reshare()
+               * we already checked this in diaspora::isReshare()
                * but better one more than one less...
                */
        if ($body == $attributes) {
@@ -5107,7 +5101,7 @@ function api_friendica_profile_show($type)
        $profileid = (x($_REQUEST, 'profile_id') ? $_REQUEST['profile_id'] : 0);
 
        // retrieve general information about profiles for user
-       $multi_profiles = feature_enabled(api_user(), 'multi_profiles');
+       $multi_profiles = Features::isEnabled(api_user(), 'multi_profiles');
        $directory = Config::get('system', 'directory');
 
        // get data of the specified profile id or all profiles of the user if not specified