]> git.mxchange.org Git - friendica.git/commitdiff
Merge remote-tracking branch 'upstream/develop' into 1701-curl-range
authorMichael <heluecht@pirati.ca>
Thu, 12 Jan 2017 07:25:44 +0000 (07:25 +0000)
committerMichael <heluecht@pirati.ca>
Thu, 12 Jan 2017 07:25:44 +0000 (07:25 +0000)
Conflicts:
mod/oexchange.php
mod/uimport.php

1  2 
include/network.php
mod/oexchange.php
mod/uexport.php
mod/uimport.php

diff --combined include/network.php
index 6bec9934edd921b169cbac1700fd6ca9daff6a5d,969f583828851a59ceb55c97d072a6bae5ef325a..b7839de218e213d0462ecd72eef24f507125d4bf
@@@ -4,9 -4,6 +4,8 @@@
   * @file include/network.php
   */
  
- use \Friendica\Core\PConfig;
 +use \Friendica\Core\Config;
 +
  require_once("include/xml.php");
  require_once('include/Probe.php');
  
@@@ -96,10 -93,7 +95,10 @@@ function z_fetch_url($url,$binary = fal
        @curl_setopt($ch, CURLOPT_RETURNTRANSFER,true);
        @curl_setopt($ch, CURLOPT_USERAGENT, $a->get_useragent());
  
 -
 +      $range = intval(Config::get('system', 'curl_range_bytes', 0));
 +      if ($range > 0) {
 +              @curl_setopt($ch, CURLOPT_RANGE, '0-'.$range);
 +      }
  
        if(x($opts,'headers')){
                @curl_setopt($ch, CURLOPT_HTTPHEADER, $opts['headers']);
diff --combined mod/oexchange.php
index 28a9f4a2418b97e6ee342233b9fd4f86cad031be,47547e691ceec4728bc0a4cab06a612e8fd8713d..4f2d7e0eb8449e97a0c48f8e1332367b05f46d97
@@@ -1,17 -1,20 +1,16 @@@
  <?php
--
- function oexchange_init(App &$a) {
 -
+ function oexchange_init(App $a) {
  
 -      if(($a->argc > 1) && ($a->argv[1] === 'xrd')) {
 +      if (($a->argc > 1) && ($a->argv[1] === 'xrd')) {
                $tpl = get_markup_template('oexchange_xrd.tpl');
  
                $o = replace_macros($tpl, array('$base' => App::get_baseurl()));
                echo $o;
                killme();
        }
 -
 -
  }
  
- function oexchange_content(App &$a) {
+ function oexchange_content(App $a) {
  
        if (! local_user()) {
                $o = login(false);
@@@ -34,9 -37,8 +33,9 @@@
  
        $s = fetch_url(App::get_baseurl() . '/parse_url?f=&url=' . $url . $title . $description . $tags);
  
 -      if(! strlen($s))
 +      if (! strlen($s)) {
                return;
 +      }
  
        require_once('include/html2bbcode.php');
  
@@@ -50,4 -52,7 +49,4 @@@
        $_REQUEST = $post;
        require_once('mod/item.php');
        item_post($a);
 -
  }
 -
 -
diff --combined mod/uexport.php
index 8b487380ece4b6296118ed85575d28d95344fea2,d886e13b27f115d06d8538854e83592cfa1c72b8..cada539bcd251071f4d7ce3fedbb27c87aebb4ee
@@@ -1,6 -1,6 +1,6 @@@
  <?php
  
- function uexport_init(App &$a){
+ function uexport_init(App $a) {
        if (! local_user()) {
                killme();
        }
  }
  
  /// @TODO Change space -> tab where wanted
- function uexport_content(App &$a){
+ function uexport_content(App $a) {
  
 -    if ($a->argc > 1) {
 -        header("Content-type: application/json");
 -        header('Content-Disposition: attachment; filename="'.$a->user['nickname'].'.'.$a->argv[1].'"');
 -        switch($a->argv[1]) {
 -            case "backup": uexport_all($a); killme(); break;
 -            case "account": uexport_account($a); killme(); break;
 -            default:
 -                killme();
 -        }
 -    }
 -
 -    /**
 -      * options shown on "Export personal data" page
 -      * list of array( 'link url', 'link text', 'help text' )
 -      */
 -    $options = array(
 -            array('uexport/account',t('Export account'),t('Export your account info and contacts. Use this to make a backup of your account and/or to move it to another server.')),
 -            array('uexport/backup',t('Export all'),t('Export your accout info, contacts and all your items as json. Could be a very big file, and could take a lot of time. Use this to make a full backup of your account (photos are not exported)')),
 -    );
 -    call_hooks('uexport_options', $options);
 -
 -    $tpl = get_markup_template("uexport.tpl");
 -    return replace_macros($tpl, array(
 -        '$baseurl' => App::get_baseurl(),
 -        '$title' => t('Export personal data'),
 -        '$options' => $options
 -    ));
 -
 +      if ($a->argc > 1) {
 +              header("Content-type: application/json");
 +              header('Content-Disposition: attachment; filename="'.$a->user['nickname'].'.'.$a->argv[1].'"');
 +              switch($a->argv[1]) {
 +                      case "backup":
 +                              uexport_all($a);
 +                              killme();
 +                              break;
 +                      case "account":
 +                              uexport_account($a);
 +                              killme();
 +                              break;
 +                      default:
 +                              killme();
 +              }
 +      }
  
 +      /**
 +       * options shown on "Export personal data" page
 +       * list of array( 'link url', 'link text', 'help text' )
 +       */
 +      $options = array(
 +              array('uexport/account',t('Export account'),t('Export your account info and contacts. Use this to make a backup of your account and/or to move it to another server.')),
 +              array('uexport/backup',t('Export all'),t('Export your accout info, contacts and all your items as json. Could be a very big file, and could take a lot of time. Use this to make a full backup of your account (photos are not exported)')),
 +      );
 +      call_hooks('uexport_options', $options);
 +
 +      $tpl = get_markup_template("uexport.tpl");
 +      return replace_macros($tpl, array(
 +              '$baseurl' => App::get_baseurl(),
 +              '$title' => t('Export personal data'),
 +              '$options' => $options
 +      ));
  }
  
  function _uexport_multirow($query) {
        $result = array();
        $r = q($query);
 -//    if (dbm::is_result($r)) {
 -      if ($r){
 +      if (dbm::is_result($r)) {
                foreach($r as $rr){
 -            $p = array();
 -                      foreach($rr as $k => $v)
 +                      $p = array();
 +                      foreach($rr as $k => $v) {
                                $p[$k] = $v;
 -            $result[] = $p;
 -        }
 +                      }
 +                      $result[] = $p;
 +              }
        }
 -    return $result;
 +      return $result;
  }
  
  function _uexport_row($query) {
        $result = array();
        $r = q($query);
 -      if ($r) {
 -              foreach($r as $rr)
 -                      foreach($rr as $k => $v)
 +      if (dbm::is_result($r)) {
 +              foreach($r as $rr) {
 +                      foreach($rr as $k => $v) {
                                $result[$k] = $v;
 -
 +                      }
 +              }
        }
 -    return $result;
 +      return $result;
  }
  
  
  function uexport_account($a){
  
        $user = _uexport_row(
 -        sprintf( "SELECT * FROM `user` WHERE `uid` = %d LIMIT 1", intval(local_user()) )
 +              sprintf( "SELECT * FROM `user` WHERE `uid` = %d LIMIT 1", intval(local_user()) )
        );
  
        $contact = _uexport_multirow(
 -        sprintf( "SELECT * FROM `contact` WHERE `uid` = %d ",intval(local_user()) )
 +              sprintf( "SELECT * FROM `contact` WHERE `uid` = %d ",intval(local_user()) )
        );
  
  
        $profile =_uexport_multirow(
 -        sprintf( "SELECT * FROM `profile` WHERE `uid` = %d ", intval(local_user()) )
 +              sprintf( "SELECT * FROM `profile` WHERE `uid` = %d ", intval(local_user()) )
        );
  
 -    $photo = _uexport_multirow(
 -        sprintf( "SELECT * FROM `photo` WHERE uid = %d AND profile = 1", intval(local_user()) )
 -    );
 -    foreach ($photo as &$p) $p['data'] = bin2hex($p['data']);
 +      $photo = _uexport_multirow(
 +              sprintf( "SELECT * FROM `photo` WHERE uid = %d AND profile = 1", intval(local_user()) )
 +      );
 +      foreach ($photo as &$p) {
 +              $p['data'] = bin2hex($p['data']);
 +      }
  
 -    $pconfig = _uexport_multirow(
 -        sprintf( "SELECT * FROM `pconfig` WHERE uid = %d",intval(local_user()) )
 -    );
 +      $pconfig = _uexport_multirow(
 +              sprintf( "SELECT * FROM `pconfig` WHERE uid = %d",intval(local_user()) )
 +      );
  
 -    $group = _uexport_multirow(
 -        sprintf( "SELECT * FROM `group` WHERE uid = %d",intval(local_user()) )
 -    );
 +      $group = _uexport_multirow(
 +              sprintf( "SELECT * FROM `group` WHERE uid = %d",intval(local_user()) )
 +      );
  
 -    $group_member = _uexport_multirow(
 -        sprintf( "SELECT * FROM `group_member` WHERE uid = %d",intval(local_user()) )
 -    );
 +      $group_member = _uexport_multirow(
 +              sprintf( "SELECT * FROM `group_member` WHERE uid = %d",intval(local_user()) )
 +      );
  
        $output = array(
 -        'version' => FRIENDICA_VERSION,
 -        'schema' => DB_UPDATE_VERSION,
 -        'baseurl' => App::get_baseurl(),
 -        'user' => $user,
 -        'contact' => $contact,
 -        'profile' => $profile,
 -        'photo' => $photo,
 -        'pconfig' => $pconfig,
 -        'group' => $group,
 -        'group_member' => $group_member,
 -    );
 -
 -    //echo "<pre>"; var_dump(json_encode($output)); killme();
 -      echo json_encode($output);
 +              'version' => FRIENDICA_VERSION,
 +              'schema' => DB_UPDATE_VERSION,
 +              'baseurl' => App::get_baseurl(),
 +              'user' => $user,
 +              'contact' => $contact,
 +              'profile' => $profile,
 +              'photo' => $photo,
 +              'pconfig' => $pconfig,
 +              'group' => $group,
 +              'group_member' => $group_member,
 +      );
  
 +      //echo "<pre>"; var_dump(json_encode($output)); killme();
 +      echo json_encode($output);
  }
  
  /**
   * echoes account data and items as separated json, one per line
   */
- function uexport_all(App &$a) {
+ function uexport_all(App $a) {
  
        uexport_account($a);
        echo "\n";
        $r = q("SELECT count(*) as `total` FROM `item` WHERE `uid` = %d ",
                intval(local_user())
        );
 -      if (dbm::is_result($r))
 +      if (dbm::is_result($r)) {
                $total = $r[0]['total'];
 -
 +      }
        // chunk the output to avoid exhausting memory
  
 -      for($x = 0; $x < $total; $x += 500) {
 +      for ($x = 0; $x < $total; $x += 500) {
                $item = array();
                $r = q("SELECT * FROM `item` WHERE `uid` = %d LIMIT %d, %d",
                        intval(local_user()),
                $output = array('item' => $r);
                echo json_encode($output)."\n";
        }
 -
  }
diff --combined mod/uimport.php
index 55e04c5338785b46564b14bfe820d4ef196b1474,e9934393e8a29e41435d32453f709124bbd872a0..336ec1c2dd74e131b4e12af37b22d5ce979023cf
@@@ -6,47 -6,47 +6,47 @@@
  \r
  require_once("include/uimport.php");\r
  \r
- function uimport_post(App &$a) {\r
+ function uimport_post(App $a) {\r
        switch($a->config['register_policy']) {\r
 -        case REGISTER_OPEN:\r
 -            $blocked = 0;\r
 -            $verified = 1;\r
 -            break;\r
 +      case REGISTER_OPEN:\r
 +              $blocked = 0;\r
 +              $verified = 1;\r
 +              break;\r
  \r
 -        case REGISTER_APPROVE:\r
 -            $blocked = 1;\r
 -            $verified = 0;\r
 -            break;\r
 +      case REGISTER_APPROVE:\r
 +              $blocked = 1;\r
 +              $verified = 0;\r
 +              break;\r
  \r
 -        default:\r
 -        case REGISTER_CLOSED:\r
 -            if((! x($_SESSION,'authenticated') && (! x($_SESSION,'administrator')))) {\r
 -                notice( t('Permission denied.') . EOL );\r
 -                return;\r
 -            }\r
 -            $blocked = 1;\r
 -            $verified = 0;\r
 -            break;\r
 +      default:\r
 +      case REGISTER_CLOSED:\r
 +              if ((! x($_SESSION,'authenticated') && (! x($_SESSION,'administrator')))) {\r
 +                      notice( t('Permission denied.') . EOL );\r
 +                      return;\r
 +              }\r
 +              $blocked = 1;\r
 +              $verified = 0;\r
 +              break;\r
        }\r
  \r
 -    if (x($_FILES,'accountfile')){\r
 -        /// @TODO Pass $blocked / $verified, send email to admin on REGISTER_APPROVE\r
 -        import_account($a, $_FILES['accountfile']);\r
 -        return;\r
 -    }\r
 +      if (x($_FILES,'accountfile')){\r
 +              /// @TODO Pass $blocked / $verified, send email to admin on REGISTER_APPROVE\r
 +              import_account($a, $_FILES['accountfile']);\r
 +              return;\r
 +      }\r
  }\r
  \r
- function uimport_content(App &$a) {\r
+ function uimport_content(App $a) {\r
  \r
 -      if((! local_user()) && ($a->config['register_policy'] == REGISTER_CLOSED)) {\r
 +      if ((! local_user()) && ($a->config['register_policy'] == REGISTER_CLOSED)) {\r
                notice("Permission denied." . EOL);\r
                return;\r
        }\r
  \r
        $max_dailies = intval(get_config('system','max_daily_registrations'));\r
 -      if($max_dailies) {\r
 +      if ($max_dailies) {\r
                $r = q("select count(*) as total from user where register_date > UTC_TIMESTAMP - INTERVAL 1 day");\r
 -              if($r && $r[0]['total'] >= $max_dailies) {\r
 +              if ($r && $r[0]['total'] >= $max_dailies) {\r
                        logger('max daily registrations exceeded.');\r
                        notice( t('This site has exceeded the number of allowed daily account registrations. Please try again tomorrow.') . EOL);\r
                        return;\r
        }\r
  \r
  \r
 -      if(x($_SESSION,'theme'))\r
 +      if (x($_SESSION,'theme')) {\r
                unset($_SESSION['theme']);\r
 -      if(x($_SESSION,'mobile-theme'))\r
 +      }\r
 +      if (x($_SESSION,'mobile-theme')) {\r
                unset($_SESSION['mobile-theme']);\r
 +      }\r
  \r
 -\r
 -    $tpl = get_markup_template("uimport.tpl");\r
 -    return replace_macros($tpl, array(\r
 -        '$regbutt' => t('Import'),\r
 -        '$import' => array(\r
 -            'title' => t("Move account"),\r
 -                      'intro' => t("You can import an account from another Friendica server."),\r
 -                      'instruct' => t("You need to export your account from the old server and upload it here. We will recreate your old account here with all your contacts. We will try also to inform your friends that you moved here."),\r
 -                      'warn' => t("This feature is experimental. We can't import contacts from the OStatus network (GNU Social/Statusnet) or from Diaspora"),\r
 -            'field' => array('accountfile', t('Account file'),'<input id="id_accountfile" name="accountfile" type="file">', t('To export your account, go to "Settings->Export your personal data" and select "Export account"')),\r
 -        ),\r
 -    ));\r
 +      $tpl = get_markup_template("uimport.tpl");\r
 +      return replace_macros($tpl, array(\r
 +              '$regbutt' => t('Import'),\r
 +              '$import' => array(\r
 +              'title' => t("Move account"),\r
 +              'intro' => t("You can import an account from another Friendica server."),\r
 +              'instruct' => t("You need to export your account from the old server and upload it here. We will recreate your old account here with all your contacts. We will try also to inform your friends that you moved here."),\r
 +              'warn' => t("This feature is experimental. We can't import contacts from the OStatus network (GNU Social/Statusnet) or from Diaspora"),\r
 +              'field' => array('accountfile', t('Account file'),'<input id="id_accountfile" name="accountfile" type="file">', t('To export your account, go to "Settings->Export your personal data" and select "Export account"')),\r
 +              ),\r
 +      ));\r
  }\r