]> git.mxchange.org Git - friendica.git/blobdiff - include/api.php
Standards stuff should make Hypolite happy.
[friendica.git] / include / api.php
index 04d614d02966e21e5935534d64502ed7df605d1c..3543a38362d995a38dabcab6c86f72e15b60b26d 100644 (file)
         * @hook 'logged_in'
         *              array $user     logged user record
         */
-       function api_login(&$a){
+       function api_login(App &$a){
                // login with oauth
                try{
                        $oauth = new FKOAuth1();
                                dbesc(trim($user)),
                                dbesc($encrypted)
                        );
-                       if(count($r))
+                       if (dbm::is_result($r))
                                $record = $r[0];
                }
 
         * @param App $a
         * @return string API call result
         */
-       function api_call(&$a){
-               GLOBAL $API, $called_api;
+       function api_call(App &$a){
+               global $API, $called_api;
 
                $type="json";
                if (strpos($a->query_string, ".xml")>0) $type="xml";
                if (is_null($user_info)) $user_info = api_get_user($a);
                $arr['$user'] = $user_info;
                $arr['$rss'] = array(
-                       'alternate' => $user_info['url'],
-                       'self' => $a->get_baseurl(). "/". $a->query_string,
-                       'base' => $a->get_baseurl(),
-                       'updated' => api_date(null),
+                       'alternate'    => $user_info['url'],
+                       'self'         => App::get_baseurl(). "/". $a->query_string,
+                       'base'         => App::get_baseurl(),
+                       'updated'      => api_date(null),
                        'atom_updated' => datetime_convert('UTC','UTC','now',ATOM_TIME),
-                       'language' => $user_info['language'],
-                       'logo'  => $a->get_baseurl()."/images/friendica-32.png",
+                       'language'     => $user_info['language'],
+                       'logo'         => App::get_baseurl()."/images/friendica-32.png",
                );
 
                return $arr;
                        'follow_request_sent' => false,
                        'statusnet_blocking' => false,
                        'notifications' => false,
-                       //'statusnet_profile_url' => $a->get_baseurl()."/contacts/".$uinfo[0]['cid'],
+                       //'statusnet_profile_url' => App::get_baseurl()."/contacts/".$uinfo[0]['cid'],
                        'statusnet_profile_url' => $uinfo[0]['url'],
                        'uid' => intval($uinfo[0]['uid']),
                        'cid' => intval($uinfo[0]['cid']),
                        if ($r) {
                                $phototypes = Photo::supportedTypes();
                                $ext = $phototypes[$r[0]['type']];
-                               $_REQUEST['body'] .= "\n\n".'[url='.$a->get_baseurl().'/photos/'.$r[0]['nickname'].'/image/'.$r[0]['resource-id'].']';
-                               $_REQUEST['body'] .= '[img]'.$a->get_baseurl()."/photo/".$r[0]['resource-id']."-".$r[0]['scale'].".".$ext."[/img][/url]";
+                               $_REQUEST['body'] .= "\n\n".'[url='.App::get_baseurl().'/photos/'.$r[0]['nickname'].'/image/'.$r[0]['resource-id'].']';
+                               $_REQUEST['body'] .= '[img]'.App::get_baseurl()."/photo/".$r[0]['resource-id']."-".$r[0]['scale'].".".$ext."[/img][/url]";
                        }
                }
 
 
                if (isset($_GET["q"])) {
                        $r = q("SELECT id FROM `contact` WHERE `uid` = 0 AND `name` = '%s'", dbesc($_GET["q"]));
-                       if (!count($r))
+                       if (!dbm::is_result($r))
                                $r = q("SELECT `id` FROM `contact` WHERE `uid` = 0 AND `nick` = '%s'", dbesc($_GET["q"]));
 
-                       if (count($r)) {
+                       if (dbm::is_result($r)) {
                                $k = 0;
                                foreach ($r AS $user) {
                                        $user_info = api_get_user($a, $user["id"], "json");
                $start = $page*$count;
 
                // Ugly code - should be changed
-               $myurl = $a->get_baseurl() . '/profile/'. $a->user['nickname'];
+               $myurl = App::get_baseurl() . '/profile/'. $a->user['nickname'];
                $myurl = substr($myurl,strpos($myurl,'://')+3);
                //$myurl = str_replace(array('www.','.'),array('','\\.'),$myurl);
                $myurl = str_replace('www.','',$myurl);
                $text = preg_replace_callback(
                                "|data:image/([^;]+)[^=]+=*|m",
                                function($match) use ($item) {
-                                       return $a->get_baseurl()."/display/".$item['guid'];
+                                       return App::get_baseurl()."/display/".$item['guid'];
                                },
                                $text);
                return $text;
 
                $name = $a->config['sitename'];
                $server = $a->get_hostname();
-               $logo = $a->get_baseurl() . '/images/friendica-64.png';
+               $logo = App::get_baseurl() . '/images/friendica-64.png';
                $email = $a->config['admin_email'];
                $closed = (($a->config['register_policy'] == REGISTER_CLOSED) ? 'true' : 'false');
                $private = (($a->config['system']['block_public']) ? 'true' : 'false');
                if($a->config['api_import_size'])
                        $texlimit = string($a->config['api_import_size']);
                $ssl = (($a->config['system']['have_ssl']) ? 'true' : 'false');
-               $sslserver = (($ssl === 'true') ? str_replace('http:','https:',$a->get_baseurl()) : '');
+               $sslserver = (($ssl === 'true') ? str_replace('http:','https:',App::get_baseurl()) : '');
 
                $config = array(
                        'site' => array('name' => $name,'server' => $server, 'theme' => 'default', 'path' => '',
                        intval(api_user())
                );
 
-               if(!dbm::is_result($r))
+               if (!dbm::is_result($r))
                        return;
 
                $ids = array();
                'image/gif' => 'gif'
                );
                $data = array('photo'=>array());
-               if($r) {
-                       foreach($r as $rr) {
+               if ($r) {
+                       foreach ($r as $rr) {
                                $photo = array();
                                $photo['id'] = $rr['resource-id'];
                                $photo['album'] = $rr['album'];
                                $photo['filename'] = $rr['filename'];
                                $photo['type'] = $rr['type'];
-                               $thumb = $a->get_baseurl()."/photo/".$rr['resource-id']."-".$rr['scale'].".".$typetoext[$rr['type']];
+                               $thumb = App::get_baseurl()."/photo/".$rr['resource-id']."-".$rr['scale'].".".$typetoext[$rr['type']];
 
                                if ($type == "xml")
                                        $data['photo'][] = array("@attributes" => $photo, "1" => $thumb);
                                for ($k=intval($data['photo']['minscale']); $k<=intval($data['photo']['maxscale']); $k++)
                                        $data['photo']['links'][$k.":link"]["@attributes"] = array("type" => $data['photo']['type'],
                                                                                        "scale" => $k,
-                                                                                       "href" => $a->get_baseurl()."/photo/".$data['photo']['resource-id']."-".$k.".".$typetoext[$data['photo']['type']]);
+                                                                                       "href" => App::get_baseurl()."/photo/".$data['photo']['resource-id']."-".$k.".".$typetoext[$data['photo']['type']]);
                        } else {
                                $data['photo']['link'] = array();
                                for ($k=intval($data['photo']['minscale']); $k<=intval($data['photo']['maxscale']); $k++) {
-                                       $data['photo']['link'][$k] = $a->get_baseurl()."/photo/".$data['photo']['resource-id']."-".$k.".".$typetoext[$data['photo']['type']];
+                                       $data['photo']['link'][$k] = App::get_baseurl()."/photo/".$data['photo']['resource-id']."-".$k.".".$typetoext[$data['photo']['type']];
                                }
                        }
                        unset($data['photo']['resource-id']);
                        intval(api_user())
                );
 
-               if ((! count($r)) || ($r[0]['network'] !== NETWORK_DFRN))
+               if ((! dbm::is_result($r)) || ($r[0]['network'] !== NETWORK_DFRN))
                        throw new BadRequestException("Unknown contact");
 
                $cid = $r[0]['id'];
        function api_share_as_retweet(&$item) {
                $body = trim($item["body"]);
 
-               if (diaspora::is_reshare($body, false)===false) {
+               if (Diaspora::is_reshare($body, false)===false) {
                        return false;
                }
 
                                intval($uid),
                                intval($gid));
                        // error message if specified gid is not in database
-                       if (count($r) == 0)
+                       if (!dbm::is_result($r))
                                throw new BadRequestException("gid not available");
                }
                else
                        intval($uid),
                        intval($gid));
                // error message if specified gid is not in database
-               if (count($r) == 0)
+               if (!dbm::is_result($r))
                        throw new BadRequestException('gid not available');
 
                // get data of the specified group id and group name
                        intval($gid),
                        dbesc($name));
                // error message if specified gid is not in database
-               if (count($rname) == 0)
+               if (!dbm::is_result($rname))
                        throw new BadRequestException('wrong group name');
 
                // delete group
                        intval($uid),
                        dbesc($name));
                // error message if specified group name already exists
-               if (count($rname) != 0)
+               if (dbm::is_result($rname))
                        throw new BadRequestException('group name already exists');
 
                // check if specified group name is a deleted group
                        intval($uid),
                        dbesc($name));
                // error message if specified group name already exists
-               if (count($rname) != 0)
+               if (dbm::is_result($rname))
                        $reactivate_group = true;
 
                // create group
 
                $profile_url = $user_info["url"];
                // message if nothing was found
-               if (count($r) == 0) 
+               if (!dbm::is_result($r))
+                       $success = array('success' => false, 'search_results' => 'problem with query');
+               else if (count($r) == 0) 
                        $success = array('success' => false, 'search_results' => 'nothing found');
                else {
                        $ret = Array();
        }
        api_register_func('api/friendica/direct_messages_search', 'api_friendica_direct_messages_search', true);
 
-
        /**
         * @brief return data of all the profiles a user has to the client
         *
                                intval(api_user()),
                                intval($profileid));
                        // error message if specified gid is not in database
-                       if (count($r) == 0)
+                       if (!dbm::is_result($r))
                                throw new BadRequestException("profile_id not available");
                }
                else