]> git.mxchange.org Git - friendica.git/commitdiff
Rename selectOne to selectFirst
authorHypolite Petovan <mrpetovan@gmail.com>
Wed, 10 Jan 2018 13:36:02 +0000 (08:36 -0500)
committerHypolite Petovan <mrpetovan@gmail.com>
Wed, 10 Jan 2018 17:57:21 +0000 (12:57 -0500)
51 files changed:
include/api.php
include/contact_widgets.php
include/conversation.php
include/dba.php
include/enotify.php
include/identity.php
include/items.php
include/message.php
include/nav.php
include/session.php
include/tags.php
index.php
mod/admin.php
mod/cal.php
mod/common.php
mod/contacts.php
mod/display.php
mod/hovercard.php
mod/network.php
mod/noscrape.php
mod/proxy.php
mod/receive.php
mod/settings.php
mod/unfollow.php
mod/xrd.php
src/Content/OEmbed.php
src/Core/Cache.php
src/Core/Config.php
src/Core/PConfig.php
src/Core/Worker.php
src/Model/Contact.php
src/Model/GContact.php
src/Model/Group.php
src/Model/Photo.php
src/Model/User.php
src/Module/Login.php
src/Network/FKOAuth1.php
src/Network/FKOAuthDataStore.php
src/Network/Probe.php
src/Object/Post.php
src/Protocol/Diaspora.php
src/Protocol/Feed.php
src/Protocol/OStatus.php
src/Protocol/PortableContact.php
src/Util/ExAuth.php
src/Util/Lock.php
src/Worker/Expire.php
src/Worker/Notifier.php
src/Worker/OnePoll.php
src/Worker/Queue.php
util/global_community_silence.php

index 16d18a37ca162785701c041ff0b09d2ef2ce382b..36e38a86e1eff7f6c69ca5fe58075928deff53e8 100644 (file)
@@ -222,7 +222,7 @@ function api_login(App $a)
        } else {
                $user_id = User::authenticate(trim($user), trim($password));
                if ($user_id) {
-                       $record = dba::selectOne('user', [], ['uid' => $user_id]);
+                       $record = dba::selectFirst('user', [], ['uid' => $user_id]);
                }
        }
 
@@ -473,7 +473,7 @@ function api_rss_extra(App $a, $arr, $user_info)
  */
 function api_unique_id_to_nurl($id)
 {
-       $r = dba::selectOne('contact', array('nurl'), array('uid' => 0, 'id' => $id));
+       $r = dba::selectFirst('contact', array('nurl'), array('uid' => 0, 'id' => $id));
 
        if (DBM::is_result($r)) {
                return $r["nurl"];
@@ -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::selectOne('user', ['theme'], ['uid' => $ret['uid']]);
+               $theme_info = dba::selectFirst('user', ['theme'], ['uid' => $ret['uid']]);
                if ($theme_info['theme'] === 'frio') {
                        $schema = PConfig::get($ret['uid'], 'frio', 'schema');
                        if ($schema && ($schema != '---')) {
@@ -4870,7 +4870,7 @@ function api_friendica_remoteauth()
 
        // traditional DFRN
 
-       $r = dba::selectOne('contact', [], ['uid' => api_user(), 'nurl' => $c_url]);
+       $r = dba::selectFirst('contact', [], ['uid' => api_user(), 'nurl' => $c_url]);
 
        if (!DBM::is_result($r) || ($r['network'] !== NETWORK_DFRN)) {
                throw new BadRequestException("Unknown contact");
index 4f84ce103949aff8ecbd9daf289c163b3c461858..cc25c88ed52bfccf2b3d74efba259e688f710a05 100644 (file)
@@ -224,12 +224,12 @@ function common_friends_visitor_widget($profile_uid)
 
        if (!$cid) {
                if (get_my_url()) {
-                       $r = dba::selectOne('contact', ['id'],
+                       $r = dba::selectFirst('contact', ['id'],
                                        ['nurl' => normalise_link(get_my_url()), 'uid' => $profile_uid]);
                        if (DBM::is_result($r)) {
                                $cid = $r['id'];
                        } else {
-                               $r = dba::selectOne('gcontact', ['id'], ['nurl' => normalise_link(get_my_url())]);
+                               $r = dba::selectFirst('gcontact', ['id'], ['nurl' => normalise_link(get_my_url())]);
                                if (DBM::is_result($r)) {
                                        $zcid = $r['id'];
                                }
index 746a8a89134cd9970230874b8b4952eb3bca2f87..228e90598b7626b615fda89f186c21c9ebd21efb 100644 (file)
@@ -968,7 +968,7 @@ function best_link_url($item, &$sparkle, $url = '') {
        $clean_url = normalise_link($item['author-link']);
 
        if (local_user()) {
-               $r = dba::selectOne('contact', ['id'],
+               $r = dba::selectFirst('contact', ['id'],
                        ['network' => NETWORK_DFRN, 'uid' => local_user(), 'nurl' => normalise_link($clean_url), 'pending' => false]);
                if (DBM::is_result($r)) {
                        $best_url = 'redir/' . $r['id'];
@@ -1019,7 +1019,7 @@ function item_photo_menu($item) {
        $cid = 0;
        $network = '';
        $rel = 0;
-       $r = dba::selectOne('contact', array('id', 'network', 'rel'), array('uid' => local_user(), 'nurl' => normalise_link($item['author-link'])));
+       $r = dba::selectFirst('contact', array('id', 'network', 'rel'), array('uid' => local_user(), 'nurl' => normalise_link($item['author-link'])));
        if (DBM::is_result($r)) {
                $cid = $r['id'];
                $network = $r['network'];
index 2b8d3d7fc722d785526138806132c8fe85d51fc0..293bfdc00233f7005ec43b1c850c31ecaeceae44 100644 (file)
@@ -1047,7 +1047,7 @@ class dba {
                if (is_bool($old_fields)) {
                        $do_insert = $old_fields;
 
-                       $old_fields = self::selectOne($table, [], $condition);
+                       $old_fields = self::selectFirst($table, [], $condition);
 
                        if (is_bool($old_fields)) {
                                if ($do_insert) {
@@ -1095,7 +1095,7 @@ class dba {
         * @return bool|array
         * @see dba::select
         */
-       public static function selectOne($table, array $fields = [], array $condition = [], $params = [])
+       public static function selectFirst($table, array $fields = [], array $condition = [], $params = [])
        {
                $params['limit'] = 1;
                $result = self::select($table, $fields, $condition, $params);
index 70f1c3131ceacab4a2e5abfb7420aa79f78a63c6..e128ae9bedf4213e7e8eb2359503e25b3611018d 100644 (file)
@@ -106,7 +106,7 @@ function notification($params)
        }
 
        if ($params['type'] == NOTIFY_COMMENT) {
-               $p = dba::selectOne('thread', ['ignored'], ['iid' => $parent_id]);
+               $p = dba::selectFirst('thread', ['ignored'], ['iid' => $parent_id]);
                if (DBM::is_result($p) && $p["ignored"]) {
                        logger("Thread ".$parent_id." will be ignored", LOGGER_DEBUG);
                        return;
@@ -131,7 +131,7 @@ function notification($params)
                $p = null;
 
                if ($params['otype'] === 'item' && $parent_id) {
-                       $p = dba::selectOne('item', [], ['id' => $parent_id]);
+                       $p = dba::selectFirst('item', [], ['id' => $parent_id]);
                }
 
                $item_post_type = item_post_type($p);
@@ -672,12 +672,12 @@ function check_item_notification($itemid, $uid, $defaulttype = "") {
        $profiles = $notification_data["profiles"];
 
        $fields = ['notify-flags', 'language', 'username', 'email', 'nickname'];
-       $user = dba::selectOne('user', $fields, ['uid' => $uid]);
+       $user = dba::selectFirst('user', $fields, ['uid' => $uid]);
        if (!DBM::is_result($user)) {
                return false;
        }
 
-       $owner = dba::selectOne('contact', ['url'], ['self' => true, 'uid' => $uid]);
+       $owner = dba::selectFirst('contact', ['url'], ['self' => true, 'uid' => $uid]);
        if (!DBM::is_result($owner)) {
                return false;
        }
index 91080b90c766dfb00b41d134374ede84375d251d..0c6224594234814b32cc32ec30447899fd507b20 100644 (file)
@@ -162,7 +162,7 @@ function get_profiledata_by_nick($nickname, $uid = 0, $profile = 0)
        if (remote_user() && count($_SESSION['remote'])) {
                foreach ($_SESSION['remote'] as $visitor) {
                        if ($visitor['uid'] == $uid) {
-                               $r = dba::selectOne('contact', ['profile-id'], ['id' => $visitor['cid']]);
+                               $r = dba::selectFirst('contact', ['profile-id'], ['id' => $visitor['cid']]);
                                if (DBM::is_result($r)) {
                                        $profile = $r['profile-id'];
                                }
index 6bc3e205182bf2e22c24b8ca712582a2c7c25c1f..f1ce70d46bade40dc26ae731fa837944488c74e7 100644 (file)
@@ -562,7 +562,7 @@ function item_store($arr, $force_parent = false, $notify = false, $dontcache = f
        // check for create date and expire time
        $expire_interval = Config::get('system', 'dbclean-expire-days', 0);
 
-       $user = dba::selectOne('user', ['expire'], ['uid' => $uid]);
+       $user = dba::selectFirst('user', ['expire'], ['uid' => $uid]);
        if (DBM::is_result($user) && ($user['expire'] > 0) && (($user['expire'] < $expire_interval) || ($expire_interval == 0))) {
                $expire_interval = $user['expire'];
        }
@@ -1149,14 +1149,14 @@ function item_store($arr, $force_parent = false, $notify = false, $dontcache = f
  */
 function item_set_last_item($arr) {
        // Unarchive the author
-       $contact = dba::selectOne('contact', [], ['id' => $arr["author-link"]]);
+       $contact = dba::selectFirst('contact', [], ['id' => $arr["author-link"]]);
        if ($contact['term-date'] > NULL_DATE) {
                 Contact::unmarkForArchival($contact);
        }
 
        // Unarchive the contact if it is a toplevel posting
        if ($arr["parent-uri"] === $arr["uri"]) {
-               $contact = dba::selectOne('contact', [], ['id' => $arr["contact-id"]]);
+               $contact = dba::selectFirst('contact', [], ['id' => $arr["contact-id"]]);
                if ($contact['term-date'] > NULL_DATE) {
                         Contact::unmarkForArchival($contact);
                }
index ef798a39e7fbf9aee0cd5a328416930b36e8c09f..189de2aef9fffc08009fda553d728e3308afb365 100644 (file)
@@ -69,7 +69,7 @@ function send_message($recipient = 0, $body = '', $subject = '', $replyto = '')
                        'subject' => $subject, 'recips' => $handles);
                dba::insert('conv', $fields);
 
-               $r = dba::selectOne('conv', ['id'], ['guid' => $conv_guid, 'uid' => local_user()]);
+               $r = dba::selectFirst('conv', ['id'], ['guid' => $conv_guid, 'uid' => local_user()]);
                if (DBM::is_result($r)) {
                        $convid = $r['id'];
                }
@@ -188,7 +188,7 @@ function send_wallmessage($recipient = '', $body = '', $subject = '', $replyto =
                'subject' => $subject, 'recips' => $handles);
        dba::insert('conv', $fields);
 
-       $r = dba::selectOne('conv', ['id'], ['guid' => $conv_guid, 'uid' => $recipient['uid']]);
+       $r = dba::selectFirst('conv', ['id'], ['guid' => $conv_guid, 'uid' => $recipient['uid']]);
        if (!DBM::is_result($r)) {
                logger('send message: conversation not found.');
                return -4;
index 8f2f5dd70ba1a49d09fb0a1d74e95de00a666b55..ac76dd5aaa250da317257e3ab8280fb9741935d4 100644 (file)
@@ -94,7 +94,7 @@ function nav_info(App $a)
                $nav['usermenu'][] = array('notes/', t('Personal notes'), '', t('Your personal notes'));
 
                // user info
-               $r = dba::selectOne('contact', ['micro'], ['uid' => $a->user['uid'], 'self' => true]);
+               $r = dba::selectFirst('contact', ['micro'], ['uid' => $a->user['uid'], 'self' => true]);
                $userinfo = array(
                        'icon' => (DBM::is_result($r) ? $a->remove_baseurl($r['micro']) : 'images/person-48.jpg'),
                        'name' => $a->user['username'],
index ba9ef46b26b7a58af261840fe91f21ffe5657f77..cf51518f20203621ca12be650264a2e94d8946e9 100644 (file)
@@ -33,7 +33,7 @@ function ref_session_read($id)
                return '';
        }
 
-       $r = dba::selectOne('session', ['data'], ['sid' => $id]);
+       $r = dba::selectFirst('session', ['data'], ['sid' => $id]);
        if (DBM::is_result($r)) {
                $session_exists = true;
                return $r['data'];
index 96e8192be76077fe118aef420445d5923ff680f9..02091f169d3e75f6456d23530df232f32ea7993d 100644 (file)
@@ -226,7 +226,7 @@ function wtagblock($uid, $count = 0, $owner_id = 0, $flags = '', $type = TERM_HA
        $o = '';
        $r = tagadelic($uid, $count, $owner_id, $flags, $type);
        if (count($r)) {
-               $contact = dba::selectOne('contact', ['url'], ['id' => $uid]);
+               $contact = dba::selectFirst('contact', ['url'], ['id' => $uid]);
                $url = System::removedBaseUrl($contact['url']);
 
                foreach ($r as $rr) {
index 7f286f9a14ec0ca9fa606185b07b20c57d1eb56d..f966279940ac87e53e349803d227538097bf26fb 100644 (file)
--- a/index.php
+++ b/index.php
@@ -108,7 +108,7 @@ if (!$a->is_backend()) {
  */
 if (x($_SESSION, 'authenticated') && !x($_SESSION, 'language')) {
        // we didn't loaded user data yet, but we need user language
-       $r = dba::selectOne('user', ['language'], ['uid' => $_SESSION['uid']]);
+       $r = dba::selectFirst('user', ['language'], ['uid' => $_SESSION['uid']]);
        $_SESSION['language'] = $lang;
        if (DBM::is_result($r)) {
                $_SESSION['language'] = $r['language'];
index 0146b954f7a0d37c0e425a18522a846580247260..e7463a3609e5873d5101cbc3b7743732de794ba0 100644 (file)
@@ -1551,7 +1551,7 @@ function admin_page_users(App $a)
 {
        if ($a->argc > 2) {
                $uid = $a->argv[3];
-               $user = dba::selectOne('user', ['username', 'blocked'], ['uid' => $uid]);
+               $user = dba::selectFirst('user', ['username', 'blocked'], ['uid' => $uid]);
                if (DBM::is_result($user)) {
                        notice('User not found' . EOL);
                        goaway('admin/users');
index cc1708352e2c011e4e0946ba4aa3dbce8359e525..51a66613ee107221552cfd0ebae6964f1ac386f7 100644 (file)
@@ -32,7 +32,7 @@ function cal_init(App $a)
 
        if ($a->argc > 1) {
                $nick = $a->argv[1];
-               $user = dba::selectOne('user', [], ['nickname' => $nick, 'blocked' => false]);
+               $user = dba::selectFirst('user', [], ['nickname' => $nick, 'blocked' => false]);
                if (!DBM::is_result($user)) {
                        return;
                }
index 9521b61af63d627f8306d710b12670389e25a465..11bddf6b539e64cf474ba10f8d8eb749e63b94d9 100644 (file)
@@ -63,11 +63,11 @@ function common_content(App $a)
        }
 
        if (!$cid && get_my_url()) {
-               $contact = dba::selectOne('contact', ['id'], ['nurl' => normalise_link(get_my_url()), 'uid' => $uid]);
+               $contact = dba::selectFirst('contact', ['id'], ['nurl' => normalise_link(get_my_url()), 'uid' => $uid]);
                if (DBM::is_result($contact)) {
                        $cid = $contact['id'];
                } else {
-                       $gcontact = dba::selectOne('gcontact', ['id'], ['nurl' => normalise_link(get_my_url())]);
+                       $gcontact = dba::selectFirst('gcontact', ['id'], ['nurl' => normalise_link(get_my_url())]);
                        if (DBM::is_result($gcontact)) {
                                $zcid = $gcontact['id'];
                        }
index ab4641a99b0c9ce009cfdb51fecd0266a26c0e62..90c4af7d1bcbe967d4cd2fd267245dfdc6969fd4 100644 (file)
@@ -33,7 +33,7 @@ function contacts_init(App $a)
        $contact = [];
        if ((($a->argc == 2) && intval($a->argv[1])) || (($a->argc == 3) && intval($a->argv[1]) && ($a->argv[2] == "posts"))) {
                $contact_id = intval($a->argv[1]);
-               $contact = dba::selectOne('contact', [], ['id' => $contact_id, 'uid' => local_user()]);
+               $contact = dba::selectFirst('contact', [], ['id' => $contact_id, 'uid' => local_user()]);
        }
 
        if (DBM::is_result($contact)) {
@@ -222,7 +222,7 @@ function contacts_post(App $a)
                notice(t('Failed to update contact record.') . EOL);
        }
 
-       $contact = dba::selectOne('contact', [], ['id' => $contact_id, 'uid' => local_user()]);
+       $contact = dba::selectFirst('contact', [], ['id' => $contact_id, 'uid' => local_user()]);
        if (DBM::is_result($contact)) {
                $a->data['contact'] = $contact;
        }
@@ -233,7 +233,7 @@ function contacts_post(App $a)
 
 function _contact_update($contact_id)
 {
-       $contact = dba::selectOne('contact', ['uid', 'url', 'network'], ['id' => $contact_id, 'uid' => local_user()]);
+       $contact = dba::selectFirst('contact', ['uid', 'url', 'network'], ['id' => $contact_id, 'uid' => local_user()]);
        if (!DBM::is_result($contact)) {
                return;
        }
@@ -254,7 +254,7 @@ function _contact_update($contact_id)
 
 function _contact_update_profile($contact_id)
 {
-       $contact = dba::selectOne('contact', ['uid', 'url', 'network'], ['id' => $contact_id, 'uid' => local_user()]);
+       $contact = dba::selectFirst('contact', ['uid', 'url', 'network'], ['id' => $contact_id, 'uid' => local_user()]);
        if (!DBM::is_result($contact)) {
                return;
        }
@@ -389,7 +389,7 @@ function contacts_content(App $a)
 
                $cmd = $a->argv[2];
 
-               $orig_record = dba::selectOne('contact', [], ['id' => $contact_id, 'uid' => local_user(), 'self' => false]);
+               $orig_record = dba::selectFirst('contact', [], ['id' => $contact_id, 'uid' => local_user(), 'self' => false]);
                if (!DBM::is_result($orig_record)) {
                        notice(t('Could not access contact record.') . EOL);
                        goaway('contacts');
@@ -904,7 +904,7 @@ function contact_posts($a, $contact_id)
 {
        $o = contacts_tab($a, $contact_id, 1);
 
-       $contact = dba::selectOne('contact', ['url'], ['id' => $contact_id]);
+       $contact = dba::selectFirst('contact', ['url'], ['id' => $contact_id]);
        if (DBM::is_result($contact)) {
                $a->page['aside'] = "";
                profile_load($a, "", 0, Contact::getDetailsByURL($contact["url"]));
index 8739af084c2e53a06ca19b631c503c9abdaebdee..25dd9b3afab8f5ef5374784531be9e47ec47de17 100644 (file)
@@ -202,7 +202,7 @@ function display_content(App $a, $update = false, $update_uid = 0) {
 
        if ($update) {
                $item_id = $_REQUEST['item_id'];
-               $item = dba::selectOne('item', ['uid', 'parent'], ['id' => $item_id]);
+               $item = dba::selectFirst('item', ['uid', 'parent'], ['id' => $item_id]);
                $a->profile = array('uid' => intval($item['uid']), 'profile_uid' => intval($item['uid']));
                $item_parent = $item['parent'];
        } else {
@@ -345,7 +345,7 @@ function display_content(App $a, $update = false, $update_uid = 0) {
        $s = dba::inArray($r);
 
        if (local_user() && (local_user() == $a->profile['uid'])) {
-               $unseen = dba::selectOne('item', ['id'], ['parent' => $s[0]['parent'], 'unseen' => true]);
+               $unseen = dba::selectFirst('item', ['id'], ['parent' => $s[0]['parent'], 'unseen' => true]);
                if (DBM::is_result($unseen)) {
                        dba::update('item', array('unseen' => false), array('parent' => $s[0]['parent'], 'unseen' => true));
                }
index d6164ffb643877f1e52aab32a48aa709a59f9f12..a9cd95f58753c75ca8da80009545967d5c0eaccc 100644 (file)
@@ -44,7 +44,7 @@ function hovercard_content()
        $cid = 0;
        if (local_user() && strpos($profileurl, 'redir/') === 0) {
                $cid = intval(substr($profileurl, 6));
-               $r = dba::selectOne('contact', ['nurl'], ['id' => $cid]);
+               $r = dba::selectFirst('contact', ['nurl'], ['id' => $cid]);
                $profileurl = defaults($r, 'nurl', '');
        }
 
index 80ae9c539a4f0153371764239377e6e49a8ce519..84dc9255e2df5ec235e15cc07352211e22f6c632 100644 (file)
@@ -581,7 +581,7 @@ function networkThreadedView(App $a, $update = 0) {
                if ($cid) {
                        // If $cid belongs to a communitity forum or a privat goup,.add a mention to the status editor
                        $condition = ["`id` = ? AND (`forum` OR `prv`)", $cid];
-                       $contact = dba::selectOne('contact', ['addr', 'nick'], $condition);
+                       $contact = dba::selectFirst('contact', ['addr', 'nick'], $condition);
                        if (DBM::is_result($contact)) {
                                if ($contact["addr"] != '') {
                                        $content = "!".$contact["addr"];
@@ -632,7 +632,7 @@ function networkThreadedView(App $a, $update = 0) {
        $sql_nets = (($nets) ? sprintf(" and $sql_table.`network` = '%s' ", dbesc($nets)) : '');
 
        if ($group) {
-               $r = dba::selectOne('group', ['name'], ['id' => $group, 'uid' => $_SESSION['uid']]);
+               $r = dba::selectFirst('group', ['name'], ['id' => $group, 'uid' => $_SESSION['uid']]);
                if (!DBM::is_result($r)) {
                        if ($update)
                                killme();
@@ -647,7 +647,7 @@ function networkThreadedView(App $a, $update = 0) {
                        $contact_str_self = "";
 
                        $contact_str = implode(',',$contacts);
-                       $self = dba::selectOne('contact', ['id'], ['uid' => $_SESSION['uid'], 'self' => true]);
+                       $self = dba::selectFirst('contact', ['id'], ['uid' => $_SESSION['uid'], 'self' => true]);
                        if (DBM::is_result($self)) {
                                $contact_str_self = $self["id"];
                        }
@@ -668,7 +668,7 @@ function networkThreadedView(App $a, $update = 0) {
                $fields = ['id', 'name', 'network', 'writable', 'nurl',
                                'forum', 'prv', 'contact-type', 'addr', 'thumb', 'location'];
                $condition = ["`id` = ? AND (NOT `blocked` OR `pending`)", $cid];
-               $r = dba::selectOne('contact', $fields, $condition);
+               $r = dba::selectFirst('contact', $fields, $condition);
                if (DBM::is_result($r)) {
                        $sql_extra = " AND ".$sql_table.".`contact-id` = ".intval($cid);
 
index 88ac52920ef352bd48c96975055b52544180b87a..fb5dea872b325f6770797b0b0a73579b6b877c85 100644 (file)
@@ -68,13 +68,13 @@ function noscrape_init(App $a) {
        // We display the last activity (post or login), reduced to year and week number
        $last_active = 0;
        $condition = ['uid' => $a->profile['uid'], 'self' => true];
-       $contact = dba::selectOne('contact', ['last-item'], $condition);
+       $contact = dba::selectFirst('contact', ['last-item'], $condition);
        if (DBM::is_result($contact)) {
                $last_active = strtotime($contact['last-item']);
        }
 
        $condition = ['uid' => $a->profile['uid']];
-       $user = dba::selectOne('user', ['login_date'], $condition);
+       $user = dba::selectFirst('user', ['login_date'], $condition);
        if (DBM::is_result($user)) {
                if ($last_active < strtotime($user['login_date'])) {
                        $last_active = strtotime($user['login_date']);
index 792d0ffbcab7ef00968dc7f569f092285a3fc339..80a84a165fc3cf84a38d7849a45b432bf0fe72cb 100644 (file)
@@ -148,7 +148,7 @@ function proxy_init(App $a) {
        $r = array();
 
        if (!$direct_cache && ($cachefile == '')) {
-               $r = dba::selectOne('photo', ['data', 'desc'], ['resource-id' => $urlhash]);
+               $r = dba::selectFirst('photo', ['data', 'desc'], ['resource-id' => $urlhash]);
                if (DBM::is_result($r)) {
                        $img_str = $r['data'];
                        $mime = $r['desc'];
index 01ba3be7535c7ce32ef5ca574daa25b0fd11dcdc..0c7a7e095391f8ae4201539741300761e56d8d52 100644 (file)
@@ -32,7 +32,7 @@ function receive_post(App $a)
                }
                $guid = $a->argv[2];
 
-               $importer = dba::selectOne('user', [], ['guid' => $guid, 'account_expired' => false, 'account_removed' => false]);
+               $importer = dba::selectFirst('user', [], ['guid' => $guid, 'account_expired' => false, 'account_removed' => false]);
                if (!DBM::is_result($importer)) {
                        http_status_exit(500);
                }
index 6138463593a0f1f6300797a9b313ad56b11c0e49..8fd890804f136f0fc1e4d5c755f311558bc8fdea 100644 (file)
@@ -997,7 +997,7 @@ function settings_content(App $a)
 
        require_once('include/acl_selectors.php');
 
-       $profile = dba::selectOne('profile', [], ['is-default' => true, 'uid' => local_user()]);
+       $profile = dba::selectFirst('profile', [], ['is-default' => true, 'uid' => local_user()]);
        if (!DBM::is_result($profile)) {
                notice(t('Unable to find your profile. Please contact your admin.') . EOL);
                return;
index 51439a9d0e80528ac808a32e6cdb354cb10d24d2..a68c4de90ef2a6ae57ba6ca7ae1aa9118618cf2f 100644 (file)
@@ -26,7 +26,7 @@ function unfollow_post(App $a) {
        $condition = ["`uid` = ? AND `rel` = ? AND (`nurl` = ? OR `alias` = ? OR `alias` = ?) AND `network` != ?",
                        $uid, CONTACT_IS_FRIEND, normalise_link($url),
                        normalise_link($url), $url, NETWORK_STATUSNET];
-       $contact = dba::selectOne('contact', [], $condition);
+       $contact = dba::selectFirst('contact', [], $condition);
 
        if (!DBM::is_result($contact)) {
                notice(t("Contact wasn't found or can't be unfollowed."));
@@ -65,7 +65,7 @@ function unfollow_content(App $a) {
        $condition = ["`uid` = ? AND `rel` = ? AND (`nurl` = ? OR `alias` = ? OR `alias` = ?) AND `network` != ?",
                        local_user(), CONTACT_IS_FRIEND, normalise_link($url),
                        normalise_link($url), $url, NETWORK_STATUSNET];
-       $contact = dba::selectOne('contact', ['url', 'network', 'addr', 'name'], $condition);
+       $contact = dba::selectFirst('contact', ['url', 'network', 'addr', 'name'], $condition);
 
        if (!DBM::is_result($contact)) {
                notice(t("You aren't a friend of this contact.").EOL);
index 871f24481db1fae7296a2c8ef07a23d2399e65c5..af1167581f080ac34fac7e511e605420de031e61 100644 (file)
@@ -36,7 +36,7 @@ function xrd_init(App $a)
                $name = substr($local, 0, strpos($local, '@'));
        }
 
-       $r = dba::selectOne('user', [], ['nickname' => $name]);
+       $r = dba::selectFirst('user', [], ['nickname' => $name]);
        if (!DBM::is_result($r)) {
                killme();
        }
index 814fd68b6ffd4010f32253a05a70ab5311f0f046..5a3f07b536382be6bc501cac72b4b4aa387aeac0 100644 (file)
-<?php\r
-\r
-/**\r
- * @file src/Content/OEmbed.php\r
- */\r
-\r
-namespace Friendica\Content;\r
-\r
-use Friendica\Core\Cache;\r
-use Friendica\Core\System;\r
-use Friendica\Core\Config;\r
-use Friendica\Database\DBM;\r
-use Friendica\Util\ParseUrl;\r
-use dba;\r
-use DOMDocument;\r
-use DOMXPath;\r
-use DOMNode;\r
-use Exception;\r
-\r
-require_once 'include/dba.php';\r
-require_once 'mod/proxy.php';\r
-\r
-/**\r
- * Handles all OEmbed content fetching and replacement\r
- *\r
- * OEmbed is a standard used to allow an embedded representation of a URL on\r
- * third party sites\r
- *\r
- * @see https://oembed.com\r
- *\r
- * @author Hypolite Petovan <mrpetovan@gmail.com>\r
- */\r
-class OEmbed\r
-{\r
-       public static function replaceCallback($matches)\r
-       {\r
-               $embedurl = $matches[1];\r
-               $j = self::fetchURL($embedurl);\r
-               $s = self::formatObject($j);\r
-\r
-               return $s;\r
-       }\r
-\r
-       /**\r
-        * @brief Get data from an URL to embed its content.\r
-        *\r
-        * @param string $embedurl The URL from which the data should be fetched.\r
-        * @param bool $no_rich_type If set to true rich type content won't be fetched.\r
-        *\r
-        * @return bool|object Returns object with embed content or false if no embedable\r
-        *       content exists\r
-        */\r
-       public static function fetchURL($embedurl, $no_rich_type = false)\r
-       {\r
-               $embedurl = trim($embedurl, "'");\r
-               $embedurl = trim($embedurl, '"');\r
-\r
-               $a = get_app();\r
-\r
-               $condition = ['url' => normalise_link($embedurl)];\r
-               $r = dba::selectOne('oembed', ['content'], $condition);\r
-               if (DBM::is_result($r)) {\r
-                       $txt = $r["content"];\r
-               } else {\r
-                       $txt = Cache::get($a->videowidth . $embedurl);\r
-               }\r
-               // These media files should now be caught in bbcode.php\r
-               // left here as a fallback in case this is called from another source\r
-\r
-               $noexts = array("mp3", "mp4", "ogg", "ogv", "oga", "ogm", "webm");\r
-               $ext = pathinfo(strtolower($embedurl), PATHINFO_EXTENSION);\r
-\r
-\r
-               if (is_null($txt)) {\r
-                       $txt = "";\r
-\r
-                       if (!in_array($ext, $noexts)) {\r
-                               // try oembed autodiscovery\r
-                               $redirects = 0;\r
-                               $html_text = fetch_url($embedurl, false, $redirects, 15, "text/*");\r
-                               if ($html_text) {\r
-                                       $dom = @DOMDocument::loadHTML($html_text);\r
-                                       if ($dom) {\r
-                                               $xpath = new DOMXPath($dom);\r
-                                               $entries = $xpath->query("//link[@type='application/json+oembed']");\r
-                                               foreach ($entries as $e) {\r
-                                                       $href = $e->getAttributeNode("href")->nodeValue;\r
-                                                       $txt = fetch_url($href . '&maxwidth=' . $a->videowidth);\r
-                                                       break;\r
-                                               }\r
-                                               $entries = $xpath->query("//link[@type='text/json+oembed']");\r
-                                               foreach ($entries as $e) {\r
-                                                       $href = $e->getAttributeNode("href")->nodeValue;\r
-                                                       $txt = fetch_url($href . '&maxwidth=' . $a->videowidth);\r
-                                                       break;\r
-                                               }\r
-                                       }\r
-                               }\r
-                       }\r
-\r
-                       $txt = trim($txt);\r
-\r
-                       if (!$txt || $txt[0] != "{") {\r
-                               $txt = '{"type":"error"}';\r
-                       } else { //save in cache\r
-                               $j = json_decode($txt);\r
-                               if ($j->type != "error") {\r
-                                       dba::insert('oembed', array('url' => normalise_link($embedurl),\r
-                                               'content' => $txt, 'created' => datetime_convert()), true);\r
-                               }\r
-\r
-                               Cache::set($a->videowidth . $embedurl, $txt, CACHE_DAY);\r
-                       }\r
-               }\r
-\r
-               $j = json_decode($txt);\r
-\r
-               if (!is_object($j)) {\r
-                       return false;\r
-               }\r
-\r
-               // Always embed the SSL version\r
-               if (isset($j->html)) {\r
-                       $j->html = str_replace(array("http://www.youtube.com/", "http://player.vimeo.com/"), array("https://www.youtube.com/", "https://player.vimeo.com/"), $j->html);\r
-               }\r
-\r
-               $j->embedurl = $embedurl;\r
-\r
-               // If fetching information doesn't work, then improve via internal functions\r
-               if (($j->type == "error") || ($no_rich_type && ($j->type == "rich"))) {\r
-                       $data = ParseUrl::getSiteinfoCached($embedurl, true, false);\r
-                       $j->type = $data["type"];\r
-\r
-                       if ($j->type == "photo") {\r
-                               $j->url = $data["url"];\r
-                               //$j->width = $data["images"][0]["width"];\r
-                               //$j->height = $data["images"][0]["height"];\r
-                       }\r
-\r
-                       if (isset($data["title"])) {\r
-                               $j->title = $data["title"];\r
-                       }\r
-\r
-                       if (isset($data["text"])) {\r
-                               $j->description = $data["text"];\r
-                       }\r
-\r
-                       if (is_array($data["images"])) {\r
-                               $j->thumbnail_url = $data["images"][0]["src"];\r
-                               $j->thumbnail_width = $data["images"][0]["width"];\r
-                               $j->thumbnail_height = $data["images"][0]["height"];\r
-                       }\r
-               }\r
-\r
-               call_hooks('oembed_fetch_url', $embedurl, $j);\r
-\r
-               return $j;\r
-       }\r
-\r
-       public static function formatObject($j)\r
-       {\r
-               $embedurl = $j->embedurl;\r
-               $jhtml = $j->html;\r
-               $ret = '<div class="oembed ' . $j->type . '">';\r
-               switch ($j->type) {\r
-                       case "video":\r
-                               if (isset($j->thumbnail_url)) {\r
-                                       $tw = (isset($j->thumbnail_width) && intval($j->thumbnail_width)) ? $j->thumbnail_width : 200;\r
-                                       $th = (isset($j->thumbnail_height) && intval($j->thumbnail_height)) ? $j->thumbnail_height : 180;\r
-                                       // make sure we don't attempt divide by zero, fallback is a 1:1 ratio\r
-                                       $tr = (($th) ? $tw / $th : 1);\r
-\r
-                                       $th = 120;\r
-                                       $tw = $th * $tr;\r
-                                       $tpl = get_markup_template('oembed_video.tpl');\r
-                                       $ret .= replace_macros($tpl, array(\r
-                                               '$baseurl' => System::baseUrl(),\r
-                                               '$embedurl' => $embedurl,\r
-                                               '$escapedhtml' => base64_encode($jhtml),\r
-                                               '$tw' => $tw,\r
-                                               '$th' => $th,\r
-                                               '$turl' => $j->thumbnail_url,\r
-                                       ));\r
-                               } else {\r
-                                       $ret = $jhtml;\r
-                               }\r
-                               break;\r
-                       case "photo":\r
-                               $ret .= '<img width="' . $j->width . '" src="' . proxy_url($j->url) . '">';\r
-                               break;\r
-                       case "link":\r
-                               break;\r
-                       case "rich":\r
-                               if (self::isAllowedURL($embedurl)) {\r
-                                       $ret .= proxy_parse_html($jhtml);\r
-                               }\r
-                               break;\r
-               }\r
-\r
-               $ret .= '</div>';\r
-               // add link to source if not present in "rich" type\r
-               if ($j->type != 'rich' || !strpos($j->html, $embedurl)) {\r
-                       $ret .= '<h4>';\r
-                       if (isset($j->title)) {\r
-                               if (isset($j->provider_name)) {\r
-                                       $ret .= $j->provider_name . ": ";\r
-                               }\r
-\r
-                               $embedlink = (isset($j->title)) ? $j->title : $embedurl;\r
-                               $ret .= '<a href="' . $embedurl . '" rel="oembed">' . $embedlink . '</a>';\r
-                               if (isset($j->author_name)) {\r
-                                       $ret .= ' (' . $j->author_name . ')';\r
-                               }\r
-                       } elseif (isset($j->provider_name) || isset($j->author_name)) {\r
-                               $embedlink = "";\r
-                               if (isset($j->provider_name)) {\r
-                                       $embedlink .= $j->provider_name;\r
-                               }\r
-\r
-                               if (isset($j->author_name)) {\r
-                                       if ($embedlink != "") {\r
-                                               $embedlink .= ": ";\r
-                                       }\r
-\r
-                                       $embedlink .= $j->author_name;\r
-                               }\r
-                               if (trim($embedlink) == "") {\r
-                                       $embedlink = $embedurl;\r
-                               }\r
-\r
-                               $ret .= '<a href="' . $embedurl . '" rel="oembed">' . $embedlink . '</a>';\r
-                       }\r
-                       $ret .= "</h4>";\r
-               } elseif (!strpos($j->html, $embedurl)) {\r
-                       // add <a> for html2bbcode conversion\r
-                       $ret .= '<a href="' . $embedurl . '" rel="oembed">' . $j->title . '</a>';\r
-               }\r
-\r
-               $ret = str_replace("\n", "", $ret);\r
-               return mb_convert_encoding($ret, 'HTML-ENTITIES', mb_detect_encoding($ret));\r
-       }\r
-\r
-       public static function BBCode2HTML($text)\r
-       {\r
-               $stopoembed = Config::get("system", "no_oembed");\r
-               if ($stopoembed == true) {\r
-                       return preg_replace("/\[embed\](.+?)\[\/embed\]/is", "<!-- oembed $1 --><i>" . t('Embedding disabled') . " : $1</i><!-- /oembed $1 -->", $text);\r
-               }\r
-               return preg_replace_callback("/\[embed\](.+?)\[\/embed\]/is", ['self', 'replaceCallback'], $text);\r
-       }\r
-\r
-       /**\r
-        * Find <span class='oembed'>..<a href='url' rel='oembed'>..</a></span>\r
-        * and replace it with [embed]url[/embed]\r
-        */\r
-       public static function HTML2BBCode($text)\r
-       {\r
-               // start parser only if 'oembed' is in text\r
-               if (strpos($text, "oembed")) {\r
-\r
-                       // convert non ascii chars to html entities\r
-                       $html_text = mb_convert_encoding($text, 'HTML-ENTITIES', mb_detect_encoding($text));\r
-\r
-                       // If it doesn't parse at all, just return the text.\r
-                       $dom = @DOMDocument::loadHTML($html_text);\r
-                       if (!$dom) {\r
-                               return $text;\r
-                       }\r
-                       $xpath = new DOMXPath($dom);\r
-\r
-                       $xattr = self::buildXPath("class", "oembed");\r
-                       $entries = $xpath->query("//div[$xattr]");\r
-\r
-                       $xattr = "@rel='oembed'"; //oe_build_xpath("rel","oembed");\r
-                       foreach ($entries as $e) {\r
-                               $href = $xpath->evaluate("a[$xattr]/@href", $e)->item(0)->nodeValue;\r
-                               if (!is_null($href)) {\r
-                                       $e->parentNode->replaceChild(new DOMText("[embed]" . $href . "[/embed]"), $e);\r
-                               }\r
-                       }\r
-                       return self::getInnerHTML($dom->getElementsByTagName("body")->item(0));\r
-               } else {\r
-                       return $text;\r
-               }\r
-       }\r
-\r
-       /**\r
-        * Determines if rich content OEmbed is allowed for the provided URL\r
-        *\r
-        * @brief Determines if rich content OEmbed is allowed for the provided URL\r
-        * @param string $url\r
-        * @return boolean\r
-        */\r
-       public static function isAllowedURL($url)\r
-       {\r
-               if (!Config::get('system', 'no_oembed_rich_content')) {\r
-                       return true;\r
-               }\r
-\r
-               $domain = parse_url($url, PHP_URL_HOST);\r
-               if (!x($domain)) {\r
-                       return false;\r
-               }\r
-\r
-               $str_allowed = Config::get('system', 'allowed_oembed', '');\r
-               if (!x($str_allowed)) {\r
-                       return false;\r
-               }\r
-               \r
-               $allowed = explode(',', $str_allowed);\r
-\r
-               return allowed_domain($domain, $allowed);\r
-       }\r
-\r
-       public static function getHTML($url, $title = null)\r
-       {\r
-               // Always embed the SSL version\r
-               $url = str_replace(array("http://www.youtube.com/", "http://player.vimeo.com/"),\r
-                                       array("https://www.youtube.com/", "https://player.vimeo.com/"), $url);\r
-\r
-               $o = OEmbed::fetchURL($url);\r
-\r
-               if (!is_object($o) || $o->type == 'error') {\r
-                       throw new Exception('OEmbed failed for URL: ' . $url);\r
-               }\r
-\r
-               if (x($title)) {\r
-                       $o->title = $title;\r
-               }\r
-\r
-               $html = OEmbed::formatObject($o);\r
-\r
-               return $html;\r
-       }\r
-\r
-       /**\r
-        * @brief Generates the iframe HTML for an oembed attachment.\r
-        *\r
-        * Width and height are given by the remote, and are regularly too small for\r
-        * the generated iframe.\r
-        *\r
-        * The width is entirely discarded for the actual width of the post, while fixed\r
-        * height is used as a starting point before the inevitable resizing.\r
-        *\r
-        * Since the iframe is automatically resized on load, there are no need for ugly\r
-        * and impractical scrollbars.\r
-        *\r
-        * @todo This function is currently unused until someoneâ„¢ adds support for a separate OEmbed domain\r
-        *\r
-        * @param string $src Original remote URL to embed\r
-        * @param string $width\r
-        * @param string $height\r
-        * @return string formatted HTML\r
-        *\r
-        * @see oembed_format_object()\r
-        */\r
-       private static function iframe($src, $width, $height)\r
-       {\r
-               $a = get_app();\r
-\r
-               if (!$height || strstr($height, '%')) {\r
-                       $height = '200';\r
-               }\r
-               $width = '100%';\r
-\r
-               $src = System::baseUrl() . '/oembed/' . base64url_encode($src);\r
-               return '<iframe onload="resizeIframe(this);" class="embed_rich" height="' . $height . '" width="' . $width . '" src="' . $src . '" allowfullscreen scrolling="no" frameborder="no">' . t('Embedded content') . '</iframe>';\r
-       }\r
-\r
-       /**\r
-        * Generates an XPath query to select elements whose provided attribute contains\r
-        * the provided value in a space-separated list.\r
-        *\r
-        * @brief Generates attribute search XPath string\r
-        *\r
-        * @param string $attr Name of the attribute to seach\r
-        * @param string $value Value to search in a space-separated list\r
-        * @return string\r
-        */\r
-       private static function buildXPath($attr, $value)\r
-       {\r
-               // https://www.westhoffswelt.de/blog/2009/6/9/select-html-elements-with-more-than-one-css-class-using-xpath\r
-               return "contains(normalize-space(@$attr), ' $value ') or substring(normalize-space(@$attr), 1, string-length('$value') + 1) = '$value ' or substring(normalize-space(@$attr), string-length(@$attr) - string-length('$value')) = ' $value' or @$attr = '$value'";\r
-       }\r
-\r
-       /**\r
-        * Returns the inner XML string of a provided DOMNode\r
-        *\r
-        * @brief Returns the inner XML string of a provided DOMNode\r
-        *\r
-        * @param DOMNode $node\r
-        * @return string\r
-        */\r
-       private static function getInnerHTML(DOMNode $node)\r
-       {\r
-               $innerHTML = '';\r
-               $children = $node->childNodes;\r
-               foreach ($children as $child) {\r
-                       $innerHTML .= $child->ownerDocument->saveXML($child);\r
-               }\r
-               return $innerHTML;\r
-       }\r
-\r
-}\r
+<?php
+
+/**
+ * @file src/Content/OEmbed.php
+ */
+
+namespace Friendica\Content;
+
+use Friendica\Core\Cache;
+use Friendica\Core\System;
+use Friendica\Core\Config;
+use Friendica\Database\DBM;
+use Friendica\Util\ParseUrl;
+use dba;
+use DOMDocument;
+use DOMXPath;
+use DOMNode;
+use Exception;
+
+require_once 'include/dba.php';
+require_once 'mod/proxy.php';
+
+/**
+ * Handles all OEmbed content fetching and replacement
+ *
+ * OEmbed is a standard used to allow an embedded representation of a URL on
+ * third party sites
+ *
+ * @see https://oembed.com
+ *
+ * @author Hypolite Petovan <mrpetovan@gmail.com>
+ */
+class OEmbed
+{
+       public static function replaceCallback($matches)
+       {
+               $embedurl = $matches[1];
+               $j = self::fetchURL($embedurl);
+               $s = self::formatObject($j);
+
+               return $s;
+       }
+
+       /**
+        * @brief Get data from an URL to embed its content.
+        *
+        * @param string $embedurl The URL from which the data should be fetched.
+        * @param bool $no_rich_type If set to true rich type content won't be fetched.
+        *
+        * @return bool|object Returns object with embed content or false if no embedable
+        *       content exists
+        */
+       public static function fetchURL($embedurl, $no_rich_type = false)
+       {
+               $embedurl = trim($embedurl, "'");
+               $embedurl = trim($embedurl, '"');
+
+               $a = get_app();
+
+               $condition = ['url' => normalise_link($embedurl)];
+               $r = dba::selectFirst('oembed', ['content'], $condition);
+               if (DBM::is_result($r)) {
+                       $txt = $r["content"];
+               } else {
+                       $txt = Cache::get($a->videowidth . $embedurl);
+               }
+               // These media files should now be caught in bbcode.php
+               // left here as a fallback in case this is called from another source
+
+               $noexts = array("mp3", "mp4", "ogg", "ogv", "oga", "ogm", "webm");
+               $ext = pathinfo(strtolower($embedurl), PATHINFO_EXTENSION);
+
+
+               if (is_null($txt)) {
+                       $txt = "";
+
+                       if (!in_array($ext, $noexts)) {
+                               // try oembed autodiscovery
+                               $redirects = 0;
+                               $html_text = fetch_url($embedurl, false, $redirects, 15, "text/*");
+                               if ($html_text) {
+                                       $dom = @DOMDocument::loadHTML($html_text);
+                                       if ($dom) {
+                                               $xpath = new DOMXPath($dom);
+                                               $entries = $xpath->query("//link[@type='application/json+oembed']");
+                                               foreach ($entries as $e) {
+                                                       $href = $e->getAttributeNode("href")->nodeValue;
+                                                       $txt = fetch_url($href . '&maxwidth=' . $a->videowidth);
+                                                       break;
+                                               }
+                                               $entries = $xpath->query("//link[@type='text/json+oembed']");
+                                               foreach ($entries as $e) {
+                                                       $href = $e->getAttributeNode("href")->nodeValue;
+                                                       $txt = fetch_url($href . '&maxwidth=' . $a->videowidth);
+                                                       break;
+                                               }
+                                       }
+                               }
+                       }
+
+                       $txt = trim($txt);
+
+                       if (!$txt || $txt[0] != "{") {
+                               $txt = '{"type":"error"}';
+                       } else { //save in cache
+                               $j = json_decode($txt);
+                               if ($j->type != "error") {
+                                       dba::insert('oembed', array('url' => normalise_link($embedurl),
+                                               'content' => $txt, 'created' => datetime_convert()), true);
+                               }
+
+                               Cache::set($a->videowidth . $embedurl, $txt, CACHE_DAY);
+                       }
+               }
+
+               $j = json_decode($txt);
+
+               if (!is_object($j)) {
+                       return false;
+               }
+
+               // Always embed the SSL version
+               if (isset($j->html)) {
+                       $j->html = str_replace(array("http://www.youtube.com/", "http://player.vimeo.com/"), array("https://www.youtube.com/", "https://player.vimeo.com/"), $j->html);
+               }
+
+               $j->embedurl = $embedurl;
+
+               // If fetching information doesn't work, then improve via internal functions
+               if (($j->type == "error") || ($no_rich_type && ($j->type == "rich"))) {
+                       $data = ParseUrl::getSiteinfoCached($embedurl, true, false);
+                       $j->type = $data["type"];
+
+                       if ($j->type == "photo") {
+                               $j->url = $data["url"];
+                               //$j->width = $data["images"][0]["width"];
+                               //$j->height = $data["images"][0]["height"];
+                       }
+
+                       if (isset($data["title"])) {
+                               $j->title = $data["title"];
+                       }
+
+                       if (isset($data["text"])) {
+                               $j->description = $data["text"];
+                       }
+
+                       if (is_array($data["images"])) {
+                               $j->thumbnail_url = $data["images"][0]["src"];
+                               $j->thumbnail_width = $data["images"][0]["width"];
+                               $j->thumbnail_height = $data["images"][0]["height"];
+                       }
+               }
+
+               call_hooks('oembed_fetch_url', $embedurl, $j);
+
+               return $j;
+       }
+
+       public static function formatObject($j)
+       {
+               $embedurl = $j->embedurl;
+               $jhtml = $j->html;
+               $ret = '<div class="oembed ' . $j->type . '">';
+               switch ($j->type) {
+                       case "video":
+                               if (isset($j->thumbnail_url)) {
+                                       $tw = (isset($j->thumbnail_width) && intval($j->thumbnail_width)) ? $j->thumbnail_width : 200;
+                                       $th = (isset($j->thumbnail_height) && intval($j->thumbnail_height)) ? $j->thumbnail_height : 180;
+                                       // make sure we don't attempt divide by zero, fallback is a 1:1 ratio
+                                       $tr = (($th) ? $tw / $th : 1);
+
+                                       $th = 120;
+                                       $tw = $th * $tr;
+                                       $tpl = get_markup_template('oembed_video.tpl');
+                                       $ret .= replace_macros($tpl, array(
+                                               '$baseurl' => System::baseUrl(),
+                                               '$embedurl' => $embedurl,
+                                               '$escapedhtml' => base64_encode($jhtml),
+                                               '$tw' => $tw,
+                                               '$th' => $th,
+                                               '$turl' => $j->thumbnail_url,
+                                       ));
+                               } else {
+                                       $ret = $jhtml;
+                               }
+                               break;
+                       case "photo":
+                               $ret .= '<img width="' . $j->width . '" src="' . proxy_url($j->url) . '">';
+                               break;
+                       case "link":
+                               break;
+                       case "rich":
+                               if (self::isAllowedURL($embedurl)) {
+                                       $ret .= proxy_parse_html($jhtml);
+                               }
+                               break;
+               }
+
+               $ret .= '</div>';
+               // add link to source if not present in "rich" type
+               if ($j->type != 'rich' || !strpos($j->html, $embedurl)) {
+                       $ret .= '<h4>';
+                       if (isset($j->title)) {
+                               if (isset($j->provider_name)) {
+                                       $ret .= $j->provider_name . ": ";
+                               }
+
+                               $embedlink = (isset($j->title)) ? $j->title : $embedurl;
+                               $ret .= '<a href="' . $embedurl . '" rel="oembed">' . $embedlink . '</a>';
+                               if (isset($j->author_name)) {
+                                       $ret .= ' (' . $j->author_name . ')';
+                               }
+                       } elseif (isset($j->provider_name) || isset($j->author_name)) {
+                               $embedlink = "";
+                               if (isset($j->provider_name)) {
+                                       $embedlink .= $j->provider_name;
+                               }
+
+                               if (isset($j->author_name)) {
+                                       if ($embedlink != "") {
+                                               $embedlink .= ": ";
+                                       }
+
+                                       $embedlink .= $j->author_name;
+                               }
+                               if (trim($embedlink) == "") {
+                                       $embedlink = $embedurl;
+                               }
+
+                               $ret .= '<a href="' . $embedurl . '" rel="oembed">' . $embedlink . '</a>';
+                       }
+                       $ret .= "</h4>";
+               } elseif (!strpos($j->html, $embedurl)) {
+                       // add <a> for html2bbcode conversion
+                       $ret .= '<a href="' . $embedurl . '" rel="oembed">' . $j->title . '</a>';
+               }
+
+               $ret = str_replace("\n", "", $ret);
+               return mb_convert_encoding($ret, 'HTML-ENTITIES', mb_detect_encoding($ret));
+       }
+
+       public static function BBCode2HTML($text)
+       {
+               $stopoembed = Config::get("system", "no_oembed");
+               if ($stopoembed == true) {
+                       return preg_replace("/\[embed\](.+?)\[\/embed\]/is", "<!-- oembed $1 --><i>" . t('Embedding disabled') . " : $1</i><!-- /oembed $1 -->", $text);
+               }
+               return preg_replace_callback("/\[embed\](.+?)\[\/embed\]/is", ['self', 'replaceCallback'], $text);
+       }
+
+       /**
+        * Find <span class='oembed'>..<a href='url' rel='oembed'>..</a></span>
+        * and replace it with [embed]url[/embed]
+        */
+       public static function HTML2BBCode($text)
+       {
+               // start parser only if 'oembed' is in text
+               if (strpos($text, "oembed")) {
+
+                       // convert non ascii chars to html entities
+                       $html_text = mb_convert_encoding($text, 'HTML-ENTITIES', mb_detect_encoding($text));
+
+                       // If it doesn't parse at all, just return the text.
+                       $dom = @DOMDocument::loadHTML($html_text);
+                       if (!$dom) {
+                               return $text;
+                       }
+                       $xpath = new DOMXPath($dom);
+
+                       $xattr = self::buildXPath("class", "oembed");
+                       $entries = $xpath->query("//div[$xattr]");
+
+                       $xattr = "@rel='oembed'"; //oe_build_xpath("rel","oembed");
+                       foreach ($entries as $e) {
+                               $href = $xpath->evaluate("a[$xattr]/@href", $e)->item(0)->nodeValue;
+                               if (!is_null($href)) {
+                                       $e->parentNode->replaceChild(new DOMText("[embed]" . $href . "[/embed]"), $e);
+                               }
+                       }
+                       return self::getInnerHTML($dom->getElementsByTagName("body")->item(0));
+               } else {
+                       return $text;
+               }
+       }
+
+       /**
+        * Determines if rich content OEmbed is allowed for the provided URL
+        *
+        * @brief Determines if rich content OEmbed is allowed for the provided URL
+        * @param string $url
+        * @return boolean
+        */
+       public static function isAllowedURL($url)
+       {
+               if (!Config::get('system', 'no_oembed_rich_content')) {
+                       return true;
+               }
+
+               $domain = parse_url($url, PHP_URL_HOST);
+               if (!x($domain)) {
+                       return false;
+               }
+
+               $str_allowed = Config::get('system', 'allowed_oembed', '');
+               if (!x($str_allowed)) {
+                       return false;
+               }
+               
+               $allowed = explode(',', $str_allowed);
+
+               return allowed_domain($domain, $allowed);
+       }
+
+       public static function getHTML($url, $title = null)
+       {
+               // Always embed the SSL version
+               $url = str_replace(array("http://www.youtube.com/", "http://player.vimeo.com/"),
+                                       array("https://www.youtube.com/", "https://player.vimeo.com/"), $url);
+
+               $o = OEmbed::fetchURL($url);
+
+               if (!is_object($o) || $o->type == 'error') {
+                       throw new Exception('OEmbed failed for URL: ' . $url);
+               }
+
+               if (x($title)) {
+                       $o->title = $title;
+               }
+
+               $html = OEmbed::formatObject($o);
+
+               return $html;
+       }
+
+       /**
+        * @brief Generates the iframe HTML for an oembed attachment.
+        *
+        * Width and height are given by the remote, and are regularly too small for
+        * the generated iframe.
+        *
+        * The width is entirely discarded for the actual width of the post, while fixed
+        * height is used as a starting point before the inevitable resizing.
+        *
+        * Since the iframe is automatically resized on load, there are no need for ugly
+        * and impractical scrollbars.
+        *
+        * @todo This function is currently unused until someoneâ„¢ adds support for a separate OEmbed domain
+        *
+        * @param string $src Original remote URL to embed
+        * @param string $width
+        * @param string $height
+        * @return string formatted HTML
+        *
+        * @see oembed_format_object()
+        */
+       private static function iframe($src, $width, $height)
+       {
+               $a = get_app();
+
+               if (!$height || strstr($height, '%')) {
+                       $height = '200';
+               }
+               $width = '100%';
+
+               $src = System::baseUrl() . '/oembed/' . base64url_encode($src);
+               return '<iframe onload="resizeIframe(this);" class="embed_rich" height="' . $height . '" width="' . $width . '" src="' . $src . '" allowfullscreen scrolling="no" frameborder="no">' . t('Embedded content') . '</iframe>';
+       }
+
+       /**
+        * Generates an XPath query to select elements whose provided attribute contains
+        * the provided value in a space-separated list.
+        *
+        * @brief Generates attribute search XPath string
+        *
+        * @param string $attr Name of the attribute to seach
+        * @param string $value Value to search in a space-separated list
+        * @return string
+        */
+       private static function buildXPath($attr, $value)
+       {
+               // https://www.westhoffswelt.de/blog/2009/6/9/select-html-elements-with-more-than-one-css-class-using-xpath
+               return "contains(normalize-space(@$attr), ' $value ') or substring(normalize-space(@$attr), 1, string-length('$value') + 1) = '$value ' or substring(normalize-space(@$attr), string-length(@$attr) - string-length('$value')) = ' $value' or @$attr = '$value'";
+       }
+
+       /**
+        * Returns the inner XML string of a provided DOMNode
+        *
+        * @brief Returns the inner XML string of a provided DOMNode
+        *
+        * @param DOMNode $node
+        * @return string
+        */
+       private static function getInnerHTML(DOMNode $node)
+       {
+               $innerHTML = '';
+               $children = $node->childNodes;
+               foreach ($children as $child) {
+                       $innerHTML .= $child->ownerDocument->saveXML($child);
+               }
+               return $innerHTML;
+       }
+
+}
index c65f416d7985cd98497e896e5872da0a1fa4a3da..dfb6591b9d5f0371fb4d78a5c43f50bb5c072c39 100644 (file)
@@ -109,7 +109,7 @@ class Cache
                // Frequently clear cache
                self::clear();
 
-               $r = dba::selectOne('cache', ['v'], ['k' => $key]);
+               $r = dba::selectFirst('cache', ['v'], ['k' => $key]);
 
                if (DBM::is_result($r)) {
                        $cached = $r['v'];
index 459433852e18e58d834db8c4f58f28acf0e46570..3b08dee6b659aee9c71879d2e405bf1816cba329 100644 (file)
@@ -97,7 +97,7 @@ class Config
                        }
                }
 
-               $ret = dba::selectOne('config', ['v'], ['cat' => $family, 'k' => $key]);
+               $ret = dba::selectFirst('config', ['v'], ['cat' => $family, 'k' => $key]);
                if (DBM::is_result($ret)) {
                        // manage array value
                        $val = (preg_match("|^a:[0-9]+:{.*}$|s", $ret['v']) ? unserialize($ret['v']) : $ret['v']);
index 0acb930b742ec7c4a2132a863049e7b81a9ec486..50fea0446914f437170d410286ec8bafd1fe5c13 100644 (file)
@@ -90,7 +90,7 @@ class PConfig
                        }
                }
 
-               $ret = dba::selectOne('pconfig', ['v'], ['uid' => $uid, 'cat' => $family, 'k' => $key]);
+               $ret = dba::selectFirst('pconfig', ['v'], ['uid' => $uid, 'cat' => $family, 'k' => $key]);
                if (DBM::is_result($ret)) {
                        $val = (preg_match("|^a:[0-9]+:{.*}$|s", $ret['v']) ? unserialize($ret['v']) : $ret['v']);
                        $a->config[$uid][$family][$key] = $val;
index 116d64e7cb6cd588e9eed15584464f342cf42da7..96e4a5bb16f9cc0d6a84174e0e43945ac1b2ec67 100644 (file)
@@ -165,7 +165,7 @@ class Worker
        private static function highestPriority()
        {
                $condition = array("`executed` <= ? AND NOT `done`", NULL_DATE);
-               $s = dba::selectOne('workerqueue', ['priority'], $condition, ['order' => ['priority']]);
+               $s = dba::selectFirst('workerqueue', ['priority'], $condition, ['order' => ['priority']]);
                if (DBM::is_result($s)) {
                        return $s["priority"];
                } else {
index bb8302e31de769703204a2eebb94cba02412deb2..a78c796edcbb7ec5c2a483ce076b9bf5ffcbb65b 100644 (file)
@@ -103,7 +103,7 @@ class Contact extends BaseObject
                        return true;
                }
 
-               $user = dba::selectOne('user', ['uid', 'username', 'nickname'], ['uid' => $uid]);
+               $user = dba::selectFirst('user', ['uid', 'username', 'nickname'], ['uid' => $uid]);
                if (!DBM::is_result($user)) {
                        return false;
                }
@@ -145,7 +145,7 @@ class Contact extends BaseObject
        public static function remove($id)
        {
                // We want just to make sure that we don't delete our "self" contact
-               $r = dba::selectOne('contact', ['uid'], ['id' => $id, 'self' => false]);
+               $r = dba::selectFirst('contact', ['uid'], ['id' => $id, 'self' => false]);
 
                if (!DBM::is_result($r) || !intval($r['uid'])) {
                        return;
@@ -490,7 +490,7 @@ class Contact extends BaseObject
                                return $menu;
                        }
 
-                       $r = dba::selectOne('contact', [], ['nurl' => $contact['nurl'], 'network' => $contact['network'], 'uid' => $uid]);
+                       $r = dba::selectFirst('contact', [], ['nurl' => $contact['nurl'], 'network' => $contact['network'], 'uid' => $uid]);
                        if ($r) {
                                return self::photoMenu($r, $uid);
                        } else {
@@ -653,18 +653,18 @@ class Contact extends BaseObject
 
                /// @todo Verify if we can't use Contact::getDetailsByUrl instead of the following
                // We first try the nurl (http://server.tld/nick), most common case
-               $contact = dba::selectOne('contact', ['id', 'avatar-date'], ['nurl' => normalise_link($url), 'uid' => $uid]);
+               $contact = dba::selectFirst('contact', ['id', 'avatar-date'], ['nurl' => normalise_link($url), 'uid' => $uid]);
 
                // Then the addr (nick@server.tld)
                if (!DBM::is_result($contact)) {
-                       $contact = dba::selectOne('contact', ['id', 'avatar-date'], ['addr' => $url, 'uid' => $uid]);
+                       $contact = dba::selectFirst('contact', ['id', 'avatar-date'], ['addr' => $url, 'uid' => $uid]);
                }
 
                // Then the alias (which could be anything)
                if (!DBM::is_result($contact)) {
                        // The link could be provided as http although we stored it as https
                        $ssl_url = str_replace('http://', 'https://', $url);
-                       $r = dba::selectOne('contact', ['id', 'avatar', 'avatar-date'], ['`alias` IN (?, ?, ?) AND `uid` = ?', $url, normalise_link($url), $ssl_url, $uid]);
+                       $r = dba::selectFirst('contact', ['id', 'avatar', 'avatar-date'], ['`alias` IN (?, ?, ?) AND `uid` = ?', $url, normalise_link($url), $ssl_url, $uid]);
                        $contact = dba::fetch($r);
                        dba::close($r);
                }
@@ -697,7 +697,7 @@ class Contact extends BaseObject
                        }
 
                        // Get data from the gcontact table
-                       $gcontacts = dba::selectOne('gcontact', ['name', 'nick', 'url', 'photo', 'addr', 'alias', 'network'], ['nurl' => normalise_link($url)]);
+                       $gcontacts = dba::selectFirst('gcontact', ['name', 'nick', 'url', 'photo', 'addr', 'alias', 'network'], ['nurl' => normalise_link($url)]);
                        if (!DBM::is_result($gcontacts)) {
                                return 0;
                        }
@@ -735,7 +735,7 @@ class Contact extends BaseObject
                        $contact_id = $contacts[0]["id"];
 
                        // Update the newly created contact from data in the gcontact table
-                       $gcontact = dba::selectOne('gcontact', ['location', 'about', 'keywords', 'gender'], ['nurl' => normalise_link($data["url"])]);
+                       $gcontact = dba::selectFirst('gcontact', ['location', 'about', 'keywords', 'gender'], ['nurl' => normalise_link($data["url"])]);
                        if (DBM::is_result($gcontact)) {
                                // Only use the information when the probing hadn't fetched these values
                                if ($data['keywords'] != '') {
@@ -759,7 +759,7 @@ class Contact extends BaseObject
                self::updateAvatar($data["photo"], $uid, $contact_id);
 
                $fields = ['url', 'nurl', 'addr', 'alias', 'name', 'nick', 'keywords', 'location', 'about', 'avatar-date', 'pubkey'];
-               $contact = dba::selectOne('contact', $fields, ['id' => $contact_id]);
+               $contact = dba::selectFirst('contact', $fields, ['id' => $contact_id]);
 
                // This condition should always be true
                if (!DBM::is_result($contact)) {
@@ -817,7 +817,7 @@ class Contact extends BaseObject
                        return false;
                }
 
-               $blocked = dba::selectOne('contact', ['blocked'], ['id' => $cid]);
+               $blocked = dba::selectFirst('contact', ['blocked'], ['id' => $cid]);
                if (!DBM::is_result($blocked)) {
                        return false;
                }
@@ -837,7 +837,7 @@ class Contact extends BaseObject
                        return false;
                }
 
-               $hidden = dba::selectOne('contact', ['hidden'], ['id' => $cid]);
+               $hidden = dba::selectFirst('contact', ['hidden'], ['id' => $cid]);
                if (!DBM::is_result($hidden)) {
                        return false;
                }
@@ -980,7 +980,7 @@ class Contact extends BaseObject
        public static function updateAvatar($avatar, $uid, $cid, $force = false)
        {
                // Limit = 1 returns the row so no need for dba:inArray()
-               $r = dba::selectOne('contact', ['avatar', 'photo', 'thumb', 'micro', 'nurl'], ['id' => $cid]);
+               $r = dba::selectFirst('contact', ['avatar', 'photo', 'thumb', 'micro', 'nurl'], ['id' => $cid]);
                if (!DBM::is_result($r)) {
                        return false;
                } else {
@@ -999,7 +999,7 @@ class Contact extends BaseObject
 
                                // Update the public contact (contact id = 0)
                                if ($uid != 0) {
-                                       $pcontact = dba::selectOne('contact', ['id'], ['nurl' => $r[0]['nurl']]);
+                                       $pcontact = dba::selectFirst('contact', ['id'], ['nurl' => $r[0]['nurl']]);
                                        if (DBM::is_result($pcontact)) {
                                                self::updateAvatar($avatar, 0, $pcontact['id'], $force);
                                        }
@@ -1023,7 +1023,7 @@ class Contact extends BaseObject
                This will reliably kill your communication with Friendica contacts.
                */
 
-               $r = dba::selectOne('contact', ['url', 'nurl', 'addr', 'alias', 'batch', 'notify', 'poll', 'poco', 'network'], ['id' => $id]);
+               $r = dba::selectFirst('contact', ['url', 'nurl', 'addr', 'alias', 'batch', 'notify', 'poll', 'poco', 'network'], ['id' => $id]);
                if (!DBM::is_result($r)) {
                        return false;
                }
@@ -1246,7 +1246,7 @@ class Contact extends BaseObject
                        );
                }
 
-               $r = dba::selectOne('contact', ['url' => $ret['url'], 'network' => $ret['network'], 'uid' => $uid]);
+               $r = dba::selectFirst('contact', ['url' => $ret['url'], 'network' => $ret['network'], 'uid' => $uid]);
 
                if (!DBM::is_result($r)) {
                        $result['message'] .= t('Unable to retrieve contact information.') . EOL;
index b09af6998775c3ceca3a2cee7213e989869ae41f..510afdf164c0ccf9a4bf847044fb40c2537781f4 100644 (file)
@@ -888,7 +888,7 @@ class GContact
                                                'network', 'bd', 'gender',
                                                'keywords', 'alias', 'contact-type',
                                                'url', 'location', 'about');
-                               $old_contact = dba::selectOne('contact', $fields, ['id' => $r[0]["id"]]);
+                               $old_contact = dba::selectFirst('contact', $fields, ['id' => $r[0]["id"]]);
 
                                // Update it with the current values
                                $fields = array('name' => $contact['name'], 'nick' => $contact['nick'],
index 345a055eb4d9f426f350443240ba9a4215092ca7..1746a3962ec94547ed487136eae9ce2897cce28f 100644 (file)
@@ -39,7 +39,7 @@ class Group extends BaseObject
                                // all the old members are gone, but the group remains so we don't break any security
                                // access lists. What we're doing here is reviving the dead group, but old content which
                                // was restricted to this group may now be seen by the new group members.
-                               $group = dba::selectOne('group', ['deleted'], ['id' => $gid]);
+                               $group = dba::selectFirst('group', ['deleted'], ['id' => $gid]);
                                if (DBM::is_result($group) && $group['deleted']) {
                                        dba::update('group', ['deleted' => 0], ['gid' => $gid]);
                                        notice(t('A deleted group with this name was revived. Existing item permissions <strong>may</strong> apply to this group and any future members. If this is not what you intended, please create another group with a different name.') . EOL);
@@ -120,7 +120,7 @@ class Group extends BaseObject
                        return false;
                }
 
-               $group = dba::selectOne('group', ['id'], ['uid' => $uid, 'name' => $name]);
+               $group = dba::selectFirst('group', ['id'], ['uid' => $uid, 'name' => $name]);
                if (DBM::is_result($group)) {
                        return $group['id'];
                }
@@ -139,13 +139,13 @@ class Group extends BaseObject
                        return false;
                }
 
-               $group = dba::selectOne('group', ['uid'], ['gid' => $gid]);
+               $group = dba::selectFirst('group', ['uid'], ['gid' => $gid]);
                if (!DBM::is_result($group)) {
                        return false;
                }
 
                // remove group from default posting lists
-               $user = dba::selectOne('user', ['def_gid', 'allow_gid', 'deny_gid'], ['uid' => $group['uid']]);
+               $user = dba::selectFirst('user', ['def_gid', 'allow_gid', 'deny_gid'], ['uid' => $group['uid']]);
                if (DBM::is_result($user)) {
                        $change = false;
 
index 3156f5782bda4363126f580ebfff63c53066be2c..a91636b6726e6c0556432e433acc628d0cdd3b25 100644 (file)
@@ -38,14 +38,14 @@ class Photo
         */
        public static function store(Image $Image, $uid, $cid, $rid, $filename, $album, $scale, $profile = 0, $allow_cid = '', $allow_gid = '', $deny_cid = '', $deny_gid = '', $desc = '')
        {
-               $r = dba::selectOne('photo', ['guid'], ["`resource-id` = ? AND `guid` != ?", $rid, '']);
+               $r = dba::selectFirst('photo', ['guid'], ["`resource-id` = ? AND `guid` != ?", $rid, '']);
                if (DBM::is_result($r)) {
                        $guid = $r['guid'];
                } else {
                        $guid = get_guid();
                }
 
-               $x = dba::selectOne('photo', ['id'], ['resource-id' => $rid, 'uid' => $uid, 'contact-id' => $cid, 'scale' => $scale]);
+               $x = dba::selectFirst('photo', ['id'], ['resource-id' => $rid, 'uid' => $uid, 'contact-id' => $cid, 'scale' => $scale]);
 
                $fields = array(
                        'uid' => $uid,
@@ -88,7 +88,7 @@ class Photo
         */
        public static function importProfilePhoto($photo, $uid, $cid, $quit_on_error = false)
        {
-               $r = dba::selectOne(
+               $r = dba::selectFirst(
                        'photo', ['resource-id'], ['uid' => $uid, 'contact-id' => $cid, 'scale' => 4, 'album' => 'Contact Photos']
                );
 
index 927bcaa75f9bc5f9d4c4178287a30f7d2f2118f5..7a6faaf66bbf2f545daab34d82a98b0280b9c8e0 100644 (file)
@@ -84,7 +84,7 @@ class User
                        return $default_group;
                }
 
-               $user = dba::selectOne('user', ['def_gid'], ['uid' => $uid]);
+               $user = dba::selectFirst('user', ['def_gid'], ['uid' => $uid]);
 
                if (DBM::is_result($user)) {
                        $default_group = $user["def_gid"];
@@ -112,7 +112,7 @@ class User
                if (is_object($user_info)) {
                        $user = (array) $user_info;
                } elseif (is_int($user_info)) {
-                       $user = dba::selectOne('user', ['uid', 'password'],
+                       $user = dba::selectFirst('user', ['uid', 'password'],
                                [
                                        'uid' => $user_info,
                                        'blocked' => 0,
@@ -328,7 +328,7 @@ class User
 
                if ($insert_result) {
                        $uid = dba::lastInsertId();
-                       $user = dba::selectOne('user', [], ['uid' => $uid]);
+                       $user = dba::selectFirst('user', [], ['uid' => $uid]);
                } else {
                        throw new Exception(t('An error occurred during registration. Please try again.'));
                }
@@ -530,7 +530,7 @@ class User
 
                logger('Removing user: ' . $uid);
 
-               $user = dba::selectOne('user', [], ['uid' => $uid]);
+               $user = dba::selectFirst('user', [], ['uid' => $uid]);
 
                call_hooks('remove_user', $user);
 
index 5ab8bb904d1f9390328feb503aa64b270accbbc8..8ba4f1035fa8067b23b281b275599496d7053a04 100644 (file)
-<?php\r
-\r
-namespace Friendica\Module;\r
-\r
-use Friendica\BaseModule;\r
-use Friendica\Core\Config;\r
-use Friendica\Database\DBM;\r
-use Friendica\Model\User;\r
-use dba;\r
-\r
-require_once 'boot.php';\r
-require_once 'include/datetime.php';\r
-require_once 'include/pgettext.php';\r
-require_once 'include/security.php';\r
-require_once 'include/text.php';\r
-\r
-/**\r
- * Login module\r
- *\r
- * @author Hypolite Petovan mrpetovan@gmail.com\r
- */\r
-class Login extends BaseModule\r
-{\r
-       public static function content()\r
-       {\r
-               $a = self::getApp();\r
-\r
-               if (x($_SESSION, 'theme')) {\r
-                       unset($_SESSION['theme']);\r
-               }\r
-\r
-               if (x($_SESSION, 'mobile-theme')) {\r
-                       unset($_SESSION['mobile-theme']);\r
-               }\r
-\r
-               if (local_user()) {\r
-                       goaway(self::getApp()->get_baseurl());\r
-               }\r
-\r
-               return self::form(self::getApp()->get_baseurl(), $a->config['register_policy'] != REGISTER_CLOSED);\r
-       }\r
-\r
-       public static function post()\r
-       {\r
-               session_unset();\r
-               // OpenId Login\r
-               if (\r
-                       !x($_POST, 'password')\r
-                       && (\r
-                               x($_POST, 'openid_url')\r
-                               || x($_POST, 'username')\r
-                       )\r
-               ) {\r
-                       $noid = Config::get('system', 'no_openid');\r
-\r
-                       $openid_url = trim($_POST['openid_url'] ? : $_POST['username']);\r
-\r
-                       // if it's an email address or doesn't resolve to a URL, fail.\r
-                       if ($noid || strpos($openid_url, '@') || !validate_url($openid_url)) {\r
-                               notice(t('Login failed.') . EOL);\r
-                               goaway(self::getApp()->get_baseurl());\r
-                               // NOTREACHED\r
-                       }\r
-\r
-                       // Otherwise it's probably an openid.\r
-                       try {\r
-                               require_once 'library/openid.php';\r
-                               $openid = new LightOpenID;\r
-                               $openid->identity = $openid_url;\r
-                               $_SESSION['openid'] = $openid_url;\r
-                               $_SESSION['remember'] = $_POST['remember'];\r
-                               $openid->returnUrl = self::getApp()->get_baseurl(true) . '/openid';\r
-                               goaway($openid->authUrl());\r
-                       } catch (Exception $e) {\r
-                               notice(t('We encountered a problem while logging in with the OpenID you provided. Please check the correct spelling of the ID.') . '<br /><br >' . t('The error message was:') . ' ' . $e->getMessage());\r
-                       }\r
-                       // NOTREACHED\r
-               }\r
-\r
-               if (x($_POST, 'auth-params') && $_POST['auth-params'] === 'login') {\r
-                       $record = null;\r
-\r
-                       $addon_auth = array(\r
-                               'username' => trim($_POST['username']),\r
-                               'password' => trim($_POST['password']),\r
-                               'authenticated' => 0,\r
-                               'user_record' => null\r
-                       );\r
-\r
-                       /*\r
-                        * A plugin indicates successful login by setting 'authenticated' to non-zero value and returning a user record\r
-                        * Plugins should never set 'authenticated' except to indicate success - as hooks may be chained\r
-                        * and later plugins should not interfere with an earlier one that succeeded.\r
-                        */\r
-                       call_hooks('authenticate', $addon_auth);\r
-\r
-                       if ($addon_auth['authenticated'] && count($addon_auth['user_record'])) {\r
-                               $record = $addon_auth['user_record'];\r
-                       } else {\r
-                               $user_id = User::authenticate(trim($_POST['username']), trim($_POST['password']));\r
-                               if ($user_id) {\r
-                                       $record = dba::selectOne('user', [], ['uid' => $user_id]);\r
-                               }\r
-                       }\r
-\r
-                       if (!$record || !count($record)) {\r
-                               logger('authenticate: failed login attempt: ' . notags(trim($_POST['username'])) . ' from IP ' . $_SERVER['REMOTE_ADDR']);\r
-                               notice(t('Login failed.') . EOL);\r
-                               goaway(self::getApp()->get_baseurl());\r
-                       }\r
-\r
-                       if (!$_POST['remember']) {\r
-                               new_cookie(0); // 0 means delete on browser exit\r
-                       }\r
-\r
-                       // if we haven't failed up this point, log them in.\r
-                       $_SESSION['remember'] = $_POST['remember'];\r
-                       $_SESSION['last_login_date'] = datetime_convert('UTC', 'UTC');\r
-                       authenticate_success($record, true, true);\r
-\r
-                       if (x($_SESSION, 'return_url')) {\r
-                               $return_url = $_SESSION['return_url'];\r
-                               unset($_SESSION['return_url']);\r
-                       } else {\r
-                               $return_url = '';\r
-                       }\r
-\r
-                       goaway($return_url);\r
-               }\r
-       }\r
-\r
-       /**\r
-        * @brief Tries to auth the user from the cookie or session\r
-        *\r
-        * @todo Should be moved to Friendica\Core\Session when it's created\r
-        */\r
-       public static function sessionAuth()\r
-       {\r
-               // When the "Friendica" cookie is set, take the value to authenticate and renew the cookie.\r
-               if (isset($_COOKIE["Friendica"])) {\r
-                       $data = json_decode($_COOKIE["Friendica"]);\r
-                       if (isset($data->uid)) {\r
-\r
-                               $user = dba::selectOne('user', [],\r
-                                       [\r
-                                               'uid'             => $data->uid,\r
-                                               'blocked'         => false,\r
-                                               'account_expired' => false,\r
-                                               'account_removed' => false,\r
-                                               'verified'        => true,\r
-                                       ]\r
-                               );\r
-                               if (DBM::is_result($user)) {\r
-                                       if ($data->hash != cookie_hash($user)) {\r
-                                               logger("Hash for user " . $data->uid . " doesn't fit.");\r
-                                               nuke_session();\r
-                                               goaway(self::getApp()->get_baseurl());\r
-                                       }\r
-\r
-                                       // Renew the cookie\r
-                                       // Expires after 7 days by default,\r
-                                       // can be set via system.auth_cookie_lifetime\r
-                                       $authcookiedays = Config::get('system', 'auth_cookie_lifetime', 7);\r
-                                       new_cookie($authcookiedays * 24 * 60 * 60, $user);\r
-\r
-                                       // Do the authentification if not done by now\r
-                                       if (!isset($_SESSION) || !isset($_SESSION['authenticated'])) {\r
-                                               authenticate_success($user);\r
-\r
-                                               if (Config::get('system', 'paranoia')) {\r
-                                                       $_SESSION['addr'] = $data->ip;\r
-                                               }\r
-                                       }\r
-                               }\r
-                       }\r
-               }\r
-\r
-               if (isset($_SESSION) && x($_SESSION, 'authenticated')) {\r
-                       if (x($_SESSION, 'visitor_id') && !x($_SESSION, 'uid')) {\r
-                               $r = q("SELECT * FROM `contact` WHERE `id` = %d LIMIT 1",\r
-                                       intval($_SESSION['visitor_id'])\r
-                               );\r
-                               if (DBM::is_result($r)) {\r
-                                       $a->contact = $r[0];\r
-                               }\r
-                       }\r
-\r
-                       if (x($_SESSION, 'uid')) {\r
-                               // already logged in user returning\r
-                               $check = Config::get('system', 'paranoia');\r
-                               // extra paranoia - if the IP changed, log them out\r
-                               if ($check && ($_SESSION['addr'] != $_SERVER['REMOTE_ADDR'])) {\r
-                                       logger('Session address changed. Paranoid setting in effect, blocking session. ' .\r
-                                               $_SESSION['addr'] . ' != ' . $_SERVER['REMOTE_ADDR']);\r
-                                       nuke_session();\r
-                                       goaway(self::getApp()->get_baseurl());\r
-                               }\r
-\r
-                               $user = dba::selectOne('user', [],\r
-                                       [\r
-                                               'uid'             => $_SESSION['uid'],\r
-                                               'blocked'         => false,\r
-                                               'account_expired' => false,\r
-                                               'account_removed' => false,\r
-                                               'verified'        => true,\r
-                                       ]\r
-                               );\r
-                               if (!DBM::is_result($user)) {\r
-                                       nuke_session();\r
-                                       goaway(self::getApp()->get_baseurl());\r
-                               }\r
-\r
-                               // Make sure to refresh the last login time for the user if the user\r
-                               // stays logged in for a long time, e.g. with "Remember Me"\r
-                               $login_refresh = false;\r
-                               if (!x($_SESSION['last_login_date'])) {\r
-                                       $_SESSION['last_login_date'] = datetime_convert('UTC', 'UTC');\r
-                               }\r
-                               if (strcmp(datetime_convert('UTC', 'UTC', 'now - 12 hours'), $_SESSION['last_login_date']) > 0) {\r
-                                       $_SESSION['last_login_date'] = datetime_convert('UTC', 'UTC');\r
-                                       $login_refresh = true;\r
-                               }\r
-                               authenticate_success($user, false, false, $login_refresh);\r
-                       }\r
-               }\r
-       }\r
-\r
-       /**\r
-        * @brief Wrapper for adding a login box.\r
-        *\r
-        * @param string $return_url The url relative to the base the user should be sent\r
-        *                                                       back to after login completes\r
-        * @param bool $register If $register == true provide a registration link.\r
-        *                                               This will most always depend on the value of $a->config['register_policy'].\r
-        * @param array $hiddens  optional\r
-        *\r
-        * @return string Returns the complete html for inserting into the page\r
-        *\r
-        * @hooks 'login_hook' string $o\r
-        */\r
-       public static function form($return_url = null, $register = false, $hiddens = [])\r
-       {\r
-               $a = self::getApp();\r
-               $o = '';\r
-               $reg = false;\r
-               if ($register) {\r
-                       $reg = array(\r
-                               'title' => t('Create a New Account'),\r
-                               'desc' => t('Register')\r
-                       );\r
-               }\r
-\r
-               $noid = Config::get('system', 'no_openid');\r
-\r
-               if (is_null($return_url)) {\r
-                       $return_url = $a->query_string;\r
-               }\r
-\r
-               if (local_user()) {\r
-                       $tpl = get_markup_template('logout.tpl');\r
-               } else {\r
-                       $a->page['htmlhead'] .= replace_macros(\r
-                               get_markup_template('login_head.tpl'),\r
-                               [\r
-                                       '$baseurl' => $a->get_baseurl(true)\r
-                               ]\r
-                       );\r
-\r
-                       $tpl = get_markup_template('login.tpl');\r
-                       $_SESSION['return_url'] = $return_url;\r
-               }\r
-\r
-               $o .= replace_macros(\r
-                       $tpl,\r
-                       [\r
-                               '$dest_url'     => self::getApp()->get_baseurl(true) . '/login',\r
-                               '$logout'       => t('Logout'),\r
-                               '$login'        => t('Login'),\r
-\r
-                               '$lname'        => array('username', t('Nickname or Email: ') , '', ''),\r
-                               '$lpassword'    => array('password', t('Password: '), '', ''),\r
-                               '$lremember'    => array('remember', t('Remember me'), 0,  ''),\r
-\r
-                               '$openid'       => !$noid,\r
-                               '$lopenid'      => array('openid_url', t('Or login using OpenID: '),'',''),\r
-\r
-                               '$hiddens'      => $hiddens,\r
-\r
-                               '$register'     => $reg,\r
-\r
-                               '$lostpass'     => t('Forgot your password?'),\r
-                               '$lostlink'     => t('Password Reset'),\r
-\r
-                               '$tostitle'     => t('Website Terms of Service'),\r
-                               '$toslink'      => t('terms of service'),\r
-\r
-                               '$privacytitle' => t('Website Privacy Policy'),\r
-                               '$privacylink'  => t('privacy policy'),\r
-                       ]\r
-               );\r
-\r
-               call_hooks('login_hook', $o);\r
-\r
-               return $o;\r
-       }\r
-}\r
+<?php
+
+namespace Friendica\Module;
+
+use Friendica\BaseModule;
+use Friendica\Core\Config;
+use Friendica\Database\DBM;
+use Friendica\Model\User;
+use dba;
+
+require_once 'boot.php';
+require_once 'include/datetime.php';
+require_once 'include/pgettext.php';
+require_once 'include/security.php';
+require_once 'include/text.php';
+
+/**
+ * Login module
+ *
+ * @author Hypolite Petovan mrpetovan@gmail.com
+ */
+class Login extends BaseModule
+{
+       public static function content()
+       {
+               $a = self::getApp();
+
+               if (x($_SESSION, 'theme')) {
+                       unset($_SESSION['theme']);
+               }
+
+               if (x($_SESSION, 'mobile-theme')) {
+                       unset($_SESSION['mobile-theme']);
+               }
+
+               if (local_user()) {
+                       goaway(self::getApp()->get_baseurl());
+               }
+
+               return self::form(self::getApp()->get_baseurl(), $a->config['register_policy'] != REGISTER_CLOSED);
+       }
+
+       public static function post()
+       {
+               session_unset();
+               // OpenId Login
+               if (
+                       !x($_POST, 'password')
+                       && (
+                               x($_POST, 'openid_url')
+                               || x($_POST, 'username')
+                       )
+               ) {
+                       $noid = Config::get('system', 'no_openid');
+
+                       $openid_url = trim($_POST['openid_url'] ? : $_POST['username']);
+
+                       // if it's an email address or doesn't resolve to a URL, fail.
+                       if ($noid || strpos($openid_url, '@') || !validate_url($openid_url)) {
+                               notice(t('Login failed.') . EOL);
+                               goaway(self::getApp()->get_baseurl());
+                               // NOTREACHED
+                       }
+
+                       // Otherwise it's probably an openid.
+                       try {
+                               require_once 'library/openid.php';
+                               $openid = new LightOpenID;
+                               $openid->identity = $openid_url;
+                               $_SESSION['openid'] = $openid_url;
+                               $_SESSION['remember'] = $_POST['remember'];
+                               $openid->returnUrl = self::getApp()->get_baseurl(true) . '/openid';
+                               goaway($openid->authUrl());
+                       } catch (Exception $e) {
+                               notice(t('We encountered a problem while logging in with the OpenID you provided. Please check the correct spelling of the ID.') . '<br /><br >' . t('The error message was:') . ' ' . $e->getMessage());
+                       }
+                       // NOTREACHED
+               }
+
+               if (x($_POST, 'auth-params') && $_POST['auth-params'] === 'login') {
+                       $record = null;
+
+                       $addon_auth = array(
+                               'username' => trim($_POST['username']),
+                               'password' => trim($_POST['password']),
+                               'authenticated' => 0,
+                               'user_record' => null
+                       );
+
+                       /*
+                        * A plugin indicates successful login by setting 'authenticated' to non-zero value and returning a user record
+                        * Plugins should never set 'authenticated' except to indicate success - as hooks may be chained
+                        * and later plugins should not interfere with an earlier one that succeeded.
+                        */
+                       call_hooks('authenticate', $addon_auth);
+
+                       if ($addon_auth['authenticated'] && count($addon_auth['user_record'])) {
+                               $record = $addon_auth['user_record'];
+                       } else {
+                               $user_id = User::authenticate(trim($_POST['username']), trim($_POST['password']));
+                               if ($user_id) {
+                                       $record = dba::selectFirst('user', [], ['uid' => $user_id]);
+                               }
+                       }
+
+                       if (!$record || !count($record)) {
+                               logger('authenticate: failed login attempt: ' . notags(trim($_POST['username'])) . ' from IP ' . $_SERVER['REMOTE_ADDR']);
+                               notice(t('Login failed.') . EOL);
+                               goaway(self::getApp()->get_baseurl());
+                       }
+
+                       if (!$_POST['remember']) {
+                               new_cookie(0); // 0 means delete on browser exit
+                       }
+
+                       // if we haven't failed up this point, log them in.
+                       $_SESSION['remember'] = $_POST['remember'];
+                       $_SESSION['last_login_date'] = datetime_convert('UTC', 'UTC');
+                       authenticate_success($record, true, true);
+
+                       if (x($_SESSION, 'return_url')) {
+                               $return_url = $_SESSION['return_url'];
+                               unset($_SESSION['return_url']);
+                       } else {
+                               $return_url = '';
+                       }
+
+                       goaway($return_url);
+               }
+       }
+
+       /**
+        * @brief Tries to auth the user from the cookie or session
+        *
+        * @todo Should be moved to Friendica\Core\Session when it's created
+        */
+       public static function sessionAuth()
+       {
+               // When the "Friendica" cookie is set, take the value to authenticate and renew the cookie.
+               if (isset($_COOKIE["Friendica"])) {
+                       $data = json_decode($_COOKIE["Friendica"]);
+                       if (isset($data->uid)) {
+
+                               $user = dba::selectFirst('user', [],
+                                       [
+                                               'uid'             => $data->uid,
+                                               'blocked'         => false,
+                                               'account_expired' => false,
+                                               'account_removed' => false,
+                                               'verified'        => true,
+                                       ]
+                               );
+                               if (DBM::is_result($user)) {
+                                       if ($data->hash != cookie_hash($user)) {
+                                               logger("Hash for user " . $data->uid . " doesn't fit.");
+                                               nuke_session();
+                                               goaway(self::getApp()->get_baseurl());
+                                       }
+
+                                       // Renew the cookie
+                                       // Expires after 7 days by default,
+                                       // can be set via system.auth_cookie_lifetime
+                                       $authcookiedays = Config::get('system', 'auth_cookie_lifetime', 7);
+                                       new_cookie($authcookiedays * 24 * 60 * 60, $user);
+
+                                       // Do the authentification if not done by now
+                                       if (!isset($_SESSION) || !isset($_SESSION['authenticated'])) {
+                                               authenticate_success($user);
+
+                                               if (Config::get('system', 'paranoia')) {
+                                                       $_SESSION['addr'] = $data->ip;
+                                               }
+                                       }
+                               }
+                       }
+               }
+
+               if (isset($_SESSION) && x($_SESSION, 'authenticated')) {
+                       if (x($_SESSION, 'visitor_id') && !x($_SESSION, 'uid')) {
+                               $r = q("SELECT * FROM `contact` WHERE `id` = %d LIMIT 1",
+                                       intval($_SESSION['visitor_id'])
+                               );
+                               if (DBM::is_result($r)) {
+                                       $a->contact = $r[0];
+                               }
+                       }
+
+                       if (x($_SESSION, 'uid')) {
+                               // already logged in user returning
+                               $check = Config::get('system', 'paranoia');
+                               // extra paranoia - if the IP changed, log them out
+                               if ($check && ($_SESSION['addr'] != $_SERVER['REMOTE_ADDR'])) {
+                                       logger('Session address changed. Paranoid setting in effect, blocking session. ' .
+                                               $_SESSION['addr'] . ' != ' . $_SERVER['REMOTE_ADDR']);
+                                       nuke_session();
+                                       goaway(self::getApp()->get_baseurl());
+                               }
+
+                               $user = dba::selectFirst('user', [],
+                                       [
+                                               'uid'             => $_SESSION['uid'],
+                                               'blocked'         => false,
+                                               'account_expired' => false,
+                                               'account_removed' => false,
+                                               'verified'        => true,
+                                       ]
+                               );
+                               if (!DBM::is_result($user)) {
+                                       nuke_session();
+                                       goaway(self::getApp()->get_baseurl());
+                               }
+
+                               // Make sure to refresh the last login time for the user if the user
+                               // stays logged in for a long time, e.g. with "Remember Me"
+                               $login_refresh = false;
+                               if (!x($_SESSION['last_login_date'])) {
+                                       $_SESSION['last_login_date'] = datetime_convert('UTC', 'UTC');
+                               }
+                               if (strcmp(datetime_convert('UTC', 'UTC', 'now - 12 hours'), $_SESSION['last_login_date']) > 0) {
+                                       $_SESSION['last_login_date'] = datetime_convert('UTC', 'UTC');
+                                       $login_refresh = true;
+                               }
+                               authenticate_success($user, false, false, $login_refresh);
+                       }
+               }
+       }
+
+       /**
+        * @brief Wrapper for adding a login box.
+        *
+        * @param string $return_url The url relative to the base the user should be sent
+        *                                                       back to after login completes
+        * @param bool $register If $register == true provide a registration link.
+        *                                               This will most always depend on the value of $a->config['register_policy'].
+        * @param array $hiddens  optional
+        *
+        * @return string Returns the complete html for inserting into the page
+        *
+        * @hooks 'login_hook' string $o
+        */
+       public static function form($return_url = null, $register = false, $hiddens = [])
+       {
+               $a = self::getApp();
+               $o = '';
+               $reg = false;
+               if ($register) {
+                       $reg = array(
+                               'title' => t('Create a New Account'),
+                               'desc' => t('Register')
+                       );
+               }
+
+               $noid = Config::get('system', 'no_openid');
+
+               if (is_null($return_url)) {
+                       $return_url = $a->query_string;
+               }
+
+               if (local_user()) {
+                       $tpl = get_markup_template('logout.tpl');
+               } else {
+                       $a->page['htmlhead'] .= replace_macros(
+                               get_markup_template('login_head.tpl'),
+                               [
+                                       '$baseurl' => $a->get_baseurl(true)
+                               ]
+                       );
+
+                       $tpl = get_markup_template('login.tpl');
+                       $_SESSION['return_url'] = $return_url;
+               }
+
+               $o .= replace_macros(
+                       $tpl,
+                       [
+                               '$dest_url'     => self::getApp()->get_baseurl(true) . '/login',
+                               '$logout'       => t('Logout'),
+                               '$login'        => t('Login'),
+
+                               '$lname'        => array('username', t('Nickname or Email: ') , '', ''),
+                               '$lpassword'    => array('password', t('Password: '), '', ''),
+                               '$lremember'    => array('remember', t('Remember me'), 0,  ''),
+
+                               '$openid'       => !$noid,
+                               '$lopenid'      => array('openid_url', t('Or login using OpenID: '),'',''),
+
+                               '$hiddens'      => $hiddens,
+
+                               '$register'     => $reg,
+
+                               '$lostpass'     => t('Forgot your password?'),
+                               '$lostlink'     => t('Password Reset'),
+
+                               '$tostitle'     => t('Website Terms of Service'),
+                               '$toslink'      => t('terms of service'),
+
+                               '$privacytitle' => t('Website Privacy Policy'),
+                               '$privacylink'  => t('privacy policy'),
+                       ]
+               );
+
+               call_hooks('login_hook', $o);
+
+               return $o;
+       }
+}
index 080e488ad55f2fa15ebc3b49edc1ee79243d3839..07e15ad51ee72a2fd0f8659a7a27b8beea092f74 100644 (file)
@@ -40,7 +40,7 @@ class FKOAuth1 extends OAuthServer
        {
                logger("FKOAuth1::loginUser $uid");
                $a = get_app();
-               $record = dba::selectOne('user', [], ['uid' => $uid, 'blocked' => 0, 'account_expired' => 0, 'account_removed' => 0, 'verified' => 1]);
+               $record = dba::selectFirst('user', [], ['uid' => $uid, 'blocked' => 0, 'account_expired' => 0, 'account_removed' => 0, 'verified' => 1]);
 
                if (!DBM::is_result($record)) {
                        logger('FKOAuth1::loginUser failure: ' . print_r($_SERVER, true), LOGGER_DEBUG);
@@ -63,7 +63,7 @@ class FKOAuth1 extends OAuthServer
                        $a->timezone = $a->user['timezone'];
                }
 
-               $r = dba::selectOne('contact', [], ['uid' => $_SESSION['uid'], 'self' => 1]);
+               $r = dba::selectFirst('contact', [], ['uid' => $_SESSION['uid'], 'self' => 1]);
                
                if (DBM::is_result($r)) {
                        $a->contact = $r;
index fe4dbdc1630c28dd2b76ab32bc7f7d6b44413e0f..ccb08ccbbaa3b0302939af4d35688f182737bbd8 100644 (file)
@@ -88,7 +88,7 @@ class FKOAuthDataStore extends OAuthDataStore
         */
        public function lookup_nonce($consumer, $token, $nonce, $timestamp)
        {
-               $r = dba::selectOne('tokens', ['id', 'secret'], ['client_id' => $consumer->key, 'id' => $nonce, 'expires' => $timestamp]);
+               $r = dba::selectFirst('tokens', ['id', 'secret'], ['client_id' => $consumer->key, 'id' => $nonce, 'expires' => $timestamp]);
 
                if (DBM::is_result($r)) {
                        return new \OAuthToken($r['id'], $r['secret']);
index fb2e09161966218a85ab01be698e7d05ce52b4f9..57c1ed284c9945c69066a0ae3263c32017547b76 100644 (file)
@@ -406,7 +406,7 @@ class Probe
 
                                $condition = array('nurl' => normalise_link($data["url"]));
 
-                               $old_fields = dba::selectOne('gcontact', $fieldnames, $condition);
+                               $old_fields = dba::selectFirst('gcontact', $fieldnames, $condition);
 
                                dba::update('gcontact', $fields, $condition, $old_fields);
 
@@ -439,7 +439,7 @@ class Probe
 
                                $condition = array('nurl' => normalise_link($data["url"]), 'self' => false, 'uid' => 0);
 
-                               $old_fields = dba::selectOne('contact', $fieldnames, $condition);
+                               $old_fields = dba::selectFirst('contact', $fieldnames, $condition);
 
                                dba::update('contact', $fields, $condition, $old_fields);
                        }
index 0997f45afbb89dac4edfb320e1d97dbb664e197a..2675fe2fc202be25f9d72232ed686e4d517beba3 100644 (file)
@@ -261,7 +261,7 @@ class Post extends BaseObject
                                        'classundo' => $item['starred'] ? "" : "hidden",
                                        'starred'   => t('starred'),
                                );
-                               $r = dba::selectOne('thread', ['ignored'], ['uid' => $item['uid'], 'iid' => $item['id']]);
+                               $r = dba::selectFirst('thread', ['ignored'], ['uid' => $item['uid'], 'iid' => $item['id']]);
                                if (DBM::is_result($r)) {
                                        $ignore = array(
                                                'do'        => t("ignore thread"),
index 7eae2373a32646e1788f15fa3948b5fb5dddf7c5..23220d04cd0ed2981a3c796f3878f494aac6e9e9 100644 (file)
@@ -2015,7 +2015,7 @@ class Diaspora
 
                // like on comments have the comment as parent. So we need to fetch the toplevel parent
                if ($parent_item["id"] != $parent_item["parent"]) {
-                       $toplevel = dba::selectOne('item', ['origin'], ['id' => $parent_item["parent"]]);
+                       $toplevel = dba::selectFirst('item', ['origin'], ['id' => $parent_item["parent"]]);
                        $origin = $toplevel["origin"];
                } else {
                        $origin = $parent_item["origin"];
@@ -2317,7 +2317,7 @@ class Diaspora
 
                                $arr["last-child"] = 1;
 
-                               $user = dba::selectOne('user', ['allow_cid', 'allow_gid', 'deny_cid', 'deny_gid'], ['uid' => $importer["uid"]]);
+                               $user = dba::selectFirst('user', ['allow_cid', 'allow_gid', 'deny_cid', 'deny_gid'], ['uid' => $importer["uid"]]);
 
                                $arr["allow_cid"] = $user["allow_cid"];
                                $arr["allow_gid"] = $user["allow_gid"];
@@ -2741,7 +2741,7 @@ class Diaspora
 
                while ($item = dba::fetch($r)) {
                        // Fetch the parent item
-                       $parent = dba::selectOne('item', ['author-link', 'origin'], ['id' => $item["parent"]]);
+                       $parent = dba::selectFirst('item', ['author-link', 'origin'], ['id' => $item["parent"]]);
 
                        // Only delete it if the parent author really fits
                        if (!link_compare($parent["author-link"], $contact["url"]) && !link_compare($item["author-link"], $contact["url"])) {
@@ -3255,7 +3255,7 @@ class Diaspora
                // If the item belongs to a user, we take this user id.
                if ($item['uid'] == 0) {
                        $condition = ['verified' => true, 'blocked' => false, 'account_removed' => false, 'account_expired' => false];
-                       $first_user = dba::selectOne('user', ['uid'], $condition);
+                       $first_user = dba::selectFirst('user', ['uid'], $condition);
                        $owner = User::getOwnerDataById($first_user['uid']);
                } else {
                        $owner = User::getOwnerDataById($item['uid']);
index 1bc8f513e0982e9629a0713126d1b3900712b8cd..af57ced7d4623a4e274bd5a1be700ea21d0815a4 100644 (file)
@@ -254,7 +254,7 @@ class Feed {
                        if (!$simulate) {
                                $condition = ["`uid` = ? AND `uri` = ? AND `network` IN (?, ?)",
                                        $importer["uid"], $item["uri"], NETWORK_FEED, NETWORK_DFRN];
-                               $previous = dba::selectOne('item', ['id'], $condition);
+                               $previous = dba::selectFirst('item', ['id'], $condition);
                                if (DBM::is_result($previous)) {
                                        logger("Item with uri ".$item["uri"]." for user ".$importer["uid"]." already existed under id ".$previous["id"], LOGGER_DEBUG);
                                        continue;
index e5786f517b4c75c48e8296653581d4f2f0c7aa77..242af46045ec983525035e32f50727f41c2897fe 100644 (file)
@@ -72,7 +72,7 @@ class OStatus
                if ($aliaslink != '') {
                        $condition = ["`uid` = ? AND `alias` = ? AND `network` != ?",
                                        $importer["uid"], $aliaslink, NETWORK_STATUSNET];
-                       $r = dba::selectOne('contact', [], $condition);
+                       $r = dba::selectFirst('contact', [], $condition);
 
                        if (DBM::is_result($r)) {
                                $found = true;
@@ -91,7 +91,7 @@ class OStatus
 
                        $condition = ["`uid` = ? AND `nurl` IN (?, ?) AND `network` != ?", $importer["uid"],
                                        normalise_link($author["author-link"]), normalise_link($aliaslink), NETWORK_STATUSNET];
-                       $r = dba::selectOne('contact', [], $condition);
+                       $r = dba::selectFirst('contact', [], $condition);
 
                        if (DBM::is_result($r)) {
                                $found = true;
@@ -106,7 +106,7 @@ class OStatus
                if (!$found && ($addr != "")) {
                        $condition = ["`uid` = ? AND `addr` = ? AND `network` != ?",
                                        $importer["uid"], $addr, NETWORK_STATUSNET];
-                       $r = dba::selectOne('contact', [], $condition);
+                       $r = dba::selectFirst('contact', [], $condition);
 
                        if (DBM::is_result($r)) {
                                $found = true;
@@ -208,7 +208,7 @@ class OStatus
 
                        if ($cid) {
                                $fields = ['url', 'nurl', 'name', 'nick', 'alias', 'about', 'location'];
-                               $old_contact = dba::selectOne('contact', $fields, ['id' => $cid]);
+                               $old_contact = dba::selectFirst('contact', $fields, ['id' => $cid]);
 
                                // Update it with the current values
                                $fields = array('url' => $author["author-link"], 'name' => $contact["name"],
@@ -542,7 +542,7 @@ class OStatus
        private static function deleteNotice($item)
        {
                $condition = ['uid' => $item['uid'], 'author-link' => $item['author-link'], 'uri' => $item['uri']];
-               $deleted = dba::selectOne('item', ['id', 'parent-uri'], $condition);
+               $deleted = dba::selectFirst('item', ['id', 'parent-uri'], $condition);
                if (!DBM::is_result($deleted)) {
                        logger('Item from '.$item['author-link'].' with uri '.$item['uri'].' for user '.$item['uid']." wasn't found. We don't delete it. ");
                        return;
@@ -896,7 +896,7 @@ class OStatus
        private static function fetchRelated($related, $related_uri, $importer)
        {
                $condition = ['`item-uri` = ? AND `protocol` IN (?, ?)', $related_uri, PROTOCOL_DFRN, PROTOCOL_OSTATUS_SALMON];
-               $conversation = dba::selectOne('conversation', ['source', 'protocol'], $condition);
+               $conversation = dba::selectFirst('conversation', ['source', 'protocol'], $condition);
                if (DBM::is_result($conversation)) {
                        $stored = true;
                        $xml = $conversation['source'];
@@ -976,7 +976,7 @@ class OStatus
                // Finally we take the data that we fetched from "ostatus:conversation"
                if ($xml == '') {
                        $condition = ['item-uri' => $related_uri, 'protocol' => PROTOCOL_SPLITTED_CONV];
-                       $conversation = dba::selectOne('conversation', ['source'], $condition);
+                       $conversation = dba::selectFirst('conversation', ['source'], $condition);
                        if (DBM::is_result($conversation)) {
                                $stored = true;
                                logger('Got cached XML from conversation for URI '.$related_uri, LOGGER_DEBUG);
index 7685826ba1ec761c4c18fe8597c2443d672a9c14..f579a40190814feab791e73cb75f524da7344a09 100644 (file)
@@ -66,7 +66,7 @@ class PortableContact
 
                if ($cid) {
                        if (!$url || !$uid) {
-                               $r = dba::selectOne('contact', ['poco', 'uid'], ['id' => $cid]);
+                               $r = dba::selectFirst('contact', ['poco', 'uid'], ['id' => $cid]);
                                if (DBM::is_result($r)) {
                                        $url = $r['poco'];
                                        $uid = $r['uid'];
@@ -813,7 +813,7 @@ class PortableContact
                        return false;
                }
 
-               $servers = dba::selectOne('gserver', [], ['nurl' => normalise_link($server_url)]);
+               $servers = dba::selectFirst('gserver', [], ['nurl' => normalise_link($server_url)]);
                if (DBM::is_result($servers)) {
                        if ($servers["created"] <= NULL_DATE) {
                                $fields = ['created' => datetime_convert()];
index 777d4105515c1b1d9988e16a5fc4a3f456343ee6..5ae24534ac3e87f96fb2923529bfc08fa4b5dde1 100644 (file)
@@ -226,7 +226,7 @@ class ExAuth
                if ($a->get_hostname() == $aCommand[2]) {
                        $this->writeLog(LOG_INFO, 'internal auth for ' . $sUser . '@' . $aCommand[2]);
 
-                       $aUser = dba::selectOne('user', ['uid', 'password'], ['nickname' => $sUser]);
+                       $aUser = dba::selectFirst('user', ['uid', 'password'], ['nickname' => $sUser]);
                        if (DBM::is_result($aUser)) {
                                $uid = $aUser['uid'];
                                $success = User::authenticate($aUser, $aCommand[3]);
index 166239a78eae55c76d585d095819cf7f8c292a82..66a568811d62c80ee093ff6e3a889915dd95f015 100644 (file)
@@ -126,7 +126,7 @@ class Lock
 
                do {
                        dba::lock('locks');
-                       $lock = dba::selectOne('locks', ['locked', 'pid'], ['name' => $fn_name]);
+                       $lock = dba::selectFirst('locks', ['locked', 'pid'], ['name' => $fn_name]);
 
                        if (DBM::is_result($lock)) {
                                if ($lock['locked']) {
index f48680fb58b1da26a8b24f0a35b665d573e057e1..9b2308da374155a02d46fcee8ac1a49138615c9b 100644 (file)
@@ -39,7 +39,7 @@ class Expire {
                        }
                        return;
                } elseif (intval($param) > 0) {
-                       $user = dba::selectOne('user', ['uid', 'username', 'expire'], ['uid' => $param]);
+                       $user = dba::selectFirst('user', ['uid', 'username', 'expire'], ['uid' => $param]);
                        if (DBM::is_result($user)) {
                                logger('Expire items for user '.$user['uid'].' ('.$user['username'].') - interval: '.$user['expire'], LOGGER_DEBUG);
                                item_expire($user['uid'], $user['expire']);
index 50ac15200c6b900063f6f5fdb88d508037d8b7a9..710bcfa13b55f6ad89d9eb87e7f341d5715569b5 100644 (file)
@@ -267,7 +267,7 @@ class Notifier {
 
                                $fields = ['forum', 'prv'];
                                $condition = ['id' => $target_item['contact-id']];
-                               $contact = dba::selectOne('contact', $fields, $condition);
+                               $contact = dba::selectFirst('contact', $fields, $condition);
                                if (!DBM::is_result($contact)) {
                                        // Should never happen
                                        return false;
index f53c392c5a461d5352f70d10270a7a46eebceec6..08dd23ad8b86a6106fe3aaf08071d1097673bd0f 100644 (file)
@@ -42,7 +42,7 @@ Class OnePoll
 
                $d = datetime_convert();
 
-               $contact = dba::selectOne('contact', [], ['id' => $contact_id]);
+               $contact = dba::selectFirst('contact', [], ['id' => $contact_id]);
                if (!DBM::is_result($contact)) {
                        logger('Contact not found or cannot be used.');
                        return;
@@ -339,10 +339,10 @@ Class OnePoll
                        logger("Mail: Enabled", LOGGER_DEBUG);
 
                        $mbox = null;
-                       $user = dba::selectOne('user', ['prvkey'], ['uid' => $importer_uid]);
+                       $user = dba::selectFirst('user', ['prvkey'], ['uid' => $importer_uid]);
 
                        $condition = ["`server` != '' AND `uid` = ?", $importer_uid];
-                       $mailconf = dba::selectOne('mailacct', [], $condition);
+                       $mailconf = dba::selectFirst('mailacct', [], $condition);
                        if (DBM::is_result($user) && DBM::is_result($mailconf)) {
                                $mailbox = Email::constructMailboxName($mailconf);
                                $password = '';
@@ -384,7 +384,7 @@ Class OnePoll
                                                        // Have we seen it before?
                                                        $fields = ['deleted', 'id'];
                                                        $condition = ['uid' => $importer_uid, 'uri' => $datarray['uri']];
-                                                       $r = dba::selectOne('item', $fields, $condition);
+                                                       $r = dba::selectFirst('item', $fields, $condition);
 
                                                        if (DBM::is_result($r)) {
                                                                logger("Mail: Seen before ".$msg_uid." for ".$mailconf['user']." UID: ".$importer_uid." URI: ".$datarray['uri'],LOGGER_DEBUG);
index 6adc32b834cdf1ac4b65abebef8df309e80e978e..1b8620a9d396dadd2b48f0d131f98dde0594652b 100644 (file)
@@ -80,7 +80,7 @@ class Queue
 
                $q_item = $r[0];
 
-               $contact = dba::selectOne('contact', [], ['id' => $q_item['cid']]);
+               $contact = dba::selectFirst('contact', [], ['id' => $q_item['cid']]);
                if (!DBM::is_result($contact)) {
                        remove_queue_item($q_item['id']);
                        return;
@@ -113,7 +113,7 @@ class Queue
                        }
                }
 
-               $user = dba::selectOne('user', [], ['uid' => $contact['uid']]);
+               $user = dba::selectFirst('user', [], ['uid' => $contact['uid']]);
                if (!DBM::is_result($user)) {
                        remove_queue_item($q_item['id']);
                        return;
index 4a324dd7448e8fd01f1ca823265abaeedc3962ca..14cd06e7aa458ae5611f880f447a6b0d92c59503 100755 (executable)
@@ -57,7 +57,7 @@ if (in_array($net['network'], array(NETWORK_PHANTOM, NETWORK_MAIL))) {
        exit(1);
 }
 $nurl = normalise_link($net['url']);
-$r = dba::selectOne("contact", ["id"], ["nurl" => $nurl, "uid" => 0]);
+$r = dba::selectFirst("contact", ["id"], ["nurl" => $nurl, "uid" => 0]);
 if (DBM::is_result($r)) {
        dba::update("contact", array("hidden" => true), array("id" => $r["id"]));
        echo "NOTICE: The account should be silenced from the global community page\r\n";