]> git.mxchange.org Git - friendica.git/blobdiff - mod/dfrn_poll.php
removed tabsi, removed some blank lines.
[friendica.git] / mod / dfrn_poll.php
index 91cd33f49abf66e1475448aaec6a630914da2594..1e07242875086506355f90822dd338d5122f4fd1 100644 (file)
@@ -1,12 +1,18 @@
 <?php
-require_once('include/items.php');
-require_once('include/auth.php');
-require_once('include/dfrn.php');
-
-
-function dfrn_poll_init(&$a) {
-
-
+/**
+ * @file mod/dfrn_poll.php
+ */
+use Friendica\App;
+use Friendica\Core\Config;
+use Friendica\Core\System;
+use Friendica\Database\DBM;
+use Friendica\Protocol\DFRN;
+use Friendica\Protocol\OStatus;
+
+require_once 'include/items.php';
+require_once 'include/auth.php';
+
+function dfrn_poll_init(App $a) {
        $dfrn_id         = ((x($_GET,'dfrn_id'))         ? $_GET['dfrn_id']              : '');
        $type            = ((x($_GET,'type'))            ? $_GET['type']                 : 'data');
        $last_update     = ((x($_GET,'last_update'))     ? $_GET['last_update']          : '');
@@ -17,6 +23,14 @@ function dfrn_poll_init(&$a) {
        $perm            = ((x($_GET,'perm'))            ? $_GET['perm']                 : 'r');
        $quiet                   = ((x($_GET,'quiet'))                   ? true                                                  : false);
 
+       // Possibly it is an OStatus compatible server that requests a user feed
+       if (($a->argc > 1) && ($dfrn_id == '') && !strstr($_SERVER["HTTP_USER_AGENT"], 'Friendica')) {
+               $nickname = $a->argv[1];
+               header("Content-type: application/atom+xml");
+               echo OStatus::feed($a, $nickname, $last_update, 10);
+               killme();
+       }
+
        $direction = (-1);
 
 
@@ -28,7 +42,7 @@ function dfrn_poll_init(&$a) {
        $hidewall = false;
 
        if(($dfrn_id === '') && (! x($_POST,'dfrn_id'))) {
-               if((get_config('system','block_public')) && (! local_user()) && (! remote_user())) {
+               if((Config::get('system','block_public')) && (! local_user()) && (! remote_user())) {
                        http_status_exit(403);
                }
 
@@ -47,7 +61,7 @@ function dfrn_poll_init(&$a) {
 
                logger('dfrn_poll: public feed request from ' . $_SERVER['REMOTE_ADDR'] . ' for ' . $user);
                header("Content-type: application/atom+xml");
-               echo dfrn::feed('', $user,$last_update, 0, $hidewall);
+               echo DFRN::feed('', $user,$last_update, 0, $hidewall);
                killme();
        }
 
@@ -68,7 +82,7 @@ function dfrn_poll_init(&$a) {
                                $my_id = '0:' . $dfrn_id;
                                break;
                        default:
-                               goaway(z_root());
+                               goaway(System::baseUrl());
                                break; // NOTREACHED
                }
 
@@ -79,7 +93,7 @@ function dfrn_poll_init(&$a) {
                        dbesc($a->argv[1])
                );
 
-               if (dbm::is_result($r)) {
+               if (DBM::is_result($r)) {
 
                        $s = fetch_url($r[0]['poll'] . '?dfrn_id=' . $my_id . '&type=profile-check');
 
@@ -112,9 +126,9 @@ function dfrn_poll_init(&$a) {
                                }
                        }
                        $profile = $r[0]['nickname'];
-                       goaway((strlen($destination_url)) ? $destination_url : $a->get_baseurl() . '/profile/' . $profile);
+                       goaway((strlen($destination_url)) ? $destination_url : System::baseUrl() . '/profile/' . $profile);
                }
-               goaway(z_root());
+               goaway(System::baseUrl());
 
        }
 
@@ -126,7 +140,7 @@ function dfrn_poll_init(&$a) {
                        $r = q("SELECT * FROM `profile_check` WHERE `sec` = '%s' ORDER BY `expire` DESC LIMIT 1",
                                dbesc($sec)
                        );
-                       if(! dbm::is_result($r)) {
+                       if (! DBM::is_result($r)) {
                                xml_status(3, 'No ticket');
                                // NOTREACHED
                        }
@@ -137,7 +151,7 @@ function dfrn_poll_init(&$a) {
                        $c = q("SELECT * FROM `contact` WHERE `id` = %d LIMIT 1",
                                intval($r[0]['cid'])
                        );
-                       if(! count($c)) {
+                       if (! DBM::is_result($c)) {
                                xml_status(3, 'No profile');
                        }
                        $contact = $c[0];
@@ -163,7 +177,7 @@ function dfrn_poll_init(&$a) {
 
                        if($final_dfrn_id != $orig_id) {
                                logger('profile_check: ' . $final_dfrn_id . ' != ' . $orig_id, LOGGER_DEBUG);
-                               // did not decode properly - cannot trust this site 
+                               // did not decode properly - cannot trust this site
                                xml_status(3, 'Bad decryption');
                        }
 
@@ -190,7 +204,7 @@ function dfrn_poll_init(&$a) {
                        q("DELETE FROM `profile_check` WHERE `expire` < " . intval(time()));
                        $r = q("SELECT * FROM `profile_check` WHERE `dfrn_id` = '%s' ORDER BY `expire` DESC",
                                dbesc($dfrn_id));
-                       if (dbm::is_result($r)) {
+                       if (DBM::is_result($r)) {
                                xml_status(1);
                                return; // NOTREACHED
                        }
@@ -203,7 +217,7 @@ function dfrn_poll_init(&$a) {
 
 
 
-function dfrn_poll_post(&$a) {
+function dfrn_poll_post(App $a) {
 
        $dfrn_id      = ((x($_POST,'dfrn_id'))      ? $_POST['dfrn_id']              : '');
        $challenge    = ((x($_POST,'challenge'))    ? $_POST['challenge']            : '');
@@ -223,7 +237,7 @@ function dfrn_poll_post(&$a) {
                        $r = q("SELECT * FROM `profile_check` WHERE `sec` = '%s' ORDER BY `expire` DESC LIMIT 1",
                                dbesc($sec)
                        );
-                       if(! dbm::is_result($r)) {
+                       if (! DBM::is_result($r)) {
                                xml_status(3, 'No ticket');
                                // NOTREACHED
                        }
@@ -234,7 +248,7 @@ function dfrn_poll_post(&$a) {
                        $c = q("SELECT * FROM `contact` WHERE `id` = %d LIMIT 1",
                                intval($r[0]['cid'])
                        );
-                       if(! count($c)) {
+                       if (! DBM::is_result($c)) {
                                xml_status(3, 'No profile');
                        }
                        $contact = $c[0];
@@ -260,7 +274,7 @@ function dfrn_poll_post(&$a) {
 
                        if($final_dfrn_id != $orig_id) {
                                logger('profile_check: ' . $final_dfrn_id . ' != ' . $orig_id, LOGGER_DEBUG);
-                               // did not decode properly - cannot trust this site 
+                               // did not decode properly - cannot trust this site
                                xml_status(3, 'Bad decryption');
                        }
 
@@ -284,8 +298,9 @@ function dfrn_poll_post(&$a) {
                dbesc($challenge)
        );
 
-       if(! dbm::is_result($r))
+       if (! DBM::is_result($r)) {
                killme();
+       }
 
        $type = $r[0]['type'];
        $last_update = $r[0]['last_update'];
@@ -311,7 +326,7 @@ function dfrn_poll_post(&$a) {
                        $my_id = '0:' . $dfrn_id;
                        break;
                default:
-                       goaway(z_root());
+                       goaway(System::baseUrl());
                        break; // NOTREACHED
        }
 
@@ -319,8 +334,9 @@ function dfrn_poll_post(&$a) {
        $r = q("SELECT * FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 $sql_extra LIMIT 1");
 
 
-       if(! dbm::is_result($r))
+       if (! DBM::is_result($r)) {
                killme();
+       }
 
        $contact = $r[0];
        $owner_uid = $r[0]['uid'];
@@ -335,7 +351,7 @@ function dfrn_poll_post(&$a) {
                $reputation = 0;
                $text = '';
 
-               if (dbm::is_result($r)) {
+               if (DBM::is_result($r)) {
                        $reputation = $r[0]['rating'];
                        $text = $r[0]['reason'];
 
@@ -374,14 +390,14 @@ function dfrn_poll_post(&$a) {
                }
 
                header("Content-type: application/atom+xml");
-               $o = dfrn::feed($dfrn_id, $a->argv[1], $last_update, $direction);
+               $o = DFRN::feed($dfrn_id, $a->argv[1], $last_update, $direction);
                echo $o;
                killme();
 
        }
 }
 
-function dfrn_poll_content(&$a) {
+function dfrn_poll_content(App $a) {
 
        $dfrn_id         = ((x($_GET,'dfrn_id'))         ? $_GET['dfrn_id']              : '');
        $type            = ((x($_GET,'type'))            ? $_GET['type']                 : 'data');
@@ -435,7 +451,7 @@ function dfrn_poll_content(&$a) {
                                $my_id = '0:' . $dfrn_id;
                                break;
                        default:
-                               goaway(z_root());
+                               goaway(System::baseUrl());
                                break; // NOTREACHED
                }
 
@@ -448,7 +464,7 @@ function dfrn_poll_content(&$a) {
                        dbesc($nickname)
                );
 
-               if (dbm::is_result($r)) {
+               if (DBM::is_result($r)) {
 
                        $challenge = '';
                        $encrypted_id = '';
@@ -495,21 +511,22 @@ function dfrn_poll_content(&$a) {
                                ));
                        }
 
-                       $profile = ((dbm::is_result($r) && $r[0]['nickname']) ? $r[0]['nickname'] : $nickname);
+                       $profile = ((DBM::is_result($r) && $r[0]['nickname']) ? $r[0]['nickname'] : $nickname);
 
                        switch($destination_url) {
                                case 'profile':
-                                       $dest = $a->get_baseurl() . '/profile/' . $profile . '?f=&tab=profile';
+                                       $dest = System::baseUrl() . '/profile/' . $profile . '?f=&tab=profile';
                                        break;
                                case 'photos':
-                                       $dest = $a->get_baseurl() . '/photos/' . $profile;
+                                       $dest = System::baseUrl() . '/photos/' . $profile;
                                        break;
                                case 'status':
                                case '':
-                                       $dest = $a->get_baseurl() . '/profile/' . $profile;
+                                       $dest = System::baseUrl() . '/profile/' . $profile;
                                        break;
                                default:
-                                       $dest = $destination_url . '?f=&redir=1';
+                                       $appendix = (strstr($destination_url, '?') ? '&f=&redir=1' : '?f=&redir=1');
+                                       $dest = $destination_url . $appendix;
                                        break;
                        }