Skip to content

Commit e68b959

Browse files
committed
Merge branch 'release/v0.21.0'
2 parents 4650bf4 + dcad053 commit e68b959

File tree

2,341 files changed

+799039
-667
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

2,341 files changed

+799039
-667
lines changed

.gitignore

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ nohup.out
3030
webroot/*.html
3131
webroot/assets/*.mp4
3232
webroot/assets/*.html
33-
webroot/assets/bower_components
3433
webroot/assets/lib/bower_components
3534
/bin/migra.php
3635
/*.key
36+
formr.feature_dockerprep.version
3737
webroot/study
38-
bin/create-named-sessions.php
38+
bin/create-named-sessions.php

.zenodo.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"upload_type": "software",
44
"creators": [
55
{
6-
"affiliation": "Center for Adaptive Rationality, Max Planck Institute for Human Development",
6+
"affiliation": "Wilhelm Wundt Institute of Psychology, University of Leipzig",
77
"name": "Ruben C. Arslan",
88
"orcid": "0000-0002-6670-5658"
99
},

application/Controller/AdminAccountController.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public function __construct(Site &$site) {
1313
public function indexAction() {
1414
if (!$this->user->loggedIn()) {
1515
alert('You need to be logged in to go here.', 'alert-info');
16-
$this->request->redirect('login');
16+
$this->request->redirect('admin/account/login');
1717
}
1818

1919
$vars = array('showform' => false);
@@ -128,7 +128,7 @@ public function registerAction() {
128128
if ($this->request->isHTTPPostRequest() && $site->request->str('email') && filter_var($this->request->str('email'), FILTER_VALIDATE_EMAIL)) {
129129
if (!Session::canValidateRequestToken($site->request) || Site::getSettings('signup:allow', 'true') !== 'true') {
130130
alert('Could not process your request please try again later', 'alert-danger');
131-
return $this->request->redirect('register');
131+
return $this->request->redirect('admin/account/register');
132132
}
133133

134134

@@ -156,13 +156,13 @@ public function verifyEmailAction() {
156156

157157
if ($this->request->isHTTPGetRequest() && $this->request->str('token')) {
158158
$user->resendVerificationEmail($this->request->str('token'));
159-
$this->request->redirect('login');
159+
$this->request->redirect('admin/account/login');
160160
} elseif (!$verification_token || !$email) {
161161
alert("You need to follow the link you received in your verification mail.");
162-
$this->request->redirect('login');
162+
$this->request->redirect('admin/account/login');
163163
} else {
164164
$user->verifyEmail($email, $verification_token);
165-
$this->request->redirect('login');
165+
$this->request->redirect('admin/account/login');
166166
};
167167
}
168168

@@ -188,7 +188,7 @@ public function resetPasswordAction() {
188188

189189
if ($this->request->isHTTPGetRequest() && (!$this->request->str('email') || !$this->request->str('reset_token')) && !$this->request->str('ok')) {
190190
alert('You need to follow the link you received in your password reset mail');
191-
$this->request->redirect('forgot_password');
191+
$this->request->redirect('admin/account/forgot-password');
192192
} elseif ($this->request->isHTTPPostRequest()) {
193193
$postRequest = new Request($_POST);
194194
$info = array(
@@ -198,7 +198,7 @@ public function resetPasswordAction() {
198198
'new_password_confirm' => $postRequest->str('new_password_c'),
199199
);
200200
if (($done = $user->resetPassword($info))) {
201-
$this->request->redirect('forgot_password');
201+
$this->request->redirect('admin/account/forgot-password');
202202
}
203203
}
204204

application/Controller/AdminController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ protected function setView($template, $vars = array()) {
9393
protected function header() {
9494
if (!($cookie = Session::getAdminCookie())) {
9595
alert('You need to login to access the admin section', 'alert-warning');
96-
$this->request->redirect('login');
96+
$this->request->redirect('admin/account/login');
9797
}
9898

9999
$this->user = new User($cookie[0], $cookie[1]);

application/Controller/ApiController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ public function osfAction($do = '') {
8282
$user = Site::getCurrentUser();
8383
if (!$user->loggedIn()) {
8484
alert('You need to login to access this section', 'alert-warning');
85-
redirect_to('login');
85+
redirect_to('admin/account/login');
8686
}
8787

8888
$osfconfg = Config::get('osf');

application/Functions.php

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,11 @@ function formr_log_exception(Exception $e, $prefix = '', $debug_data = null) {
2727
}
2828

2929
function get_log_file($filename) {
30-
return APPLICATION_ROOT . "tmp/logs/$filename";
30+
if(Config::get('error_to_stderr') == 1) {
31+
return "php://stderr";
32+
} else {
33+
return APPLICATION_ROOT . "tmp/logs/$filename";
34+
}
3135
}
3236

3337
function alert($msg, $class = 'alert-warning', $dismissable = true) { // shorthand
@@ -756,15 +760,17 @@ function run_url($name = '', $action = '', $params = array()) {
756760
return site_url('run/' . $name . '/' . $action);
757761
}
758762

759-
$protocol = Config::get('define_root.protocol');
760-
$domain = trim(Config::get('define_root.doc_root', ''), "\/\\");
763+
$protocol = Config::get('protocol');
764+
# use different domain for studies if set, independent of wildcard subdomain setting
765+
$domain = trim(Config::get('study_domain', ''), "*\/\\");
761766
$subdomain = null;
767+
762768
if (Config::get('use_study_subdomains')) {
763-
$domain = Config::get('define_root.study_domain', $domain); # use different domain for studies if set
764-
$subdomain = strtolower($name) . '.';
769+
$subdomain = strtolower($name);
765770
} else {
766771
$domain .= '/' . $name;
767772
}
773+
768774
$url = $protocol . $subdomain . $domain;
769775
if ($action) {
770776
$action = trim($action, "\/\\");
@@ -1348,7 +1354,7 @@ function opencpu_debug($session, OpenCPU $ocpu = null, $rtype = 'json') {
13481354
}
13491355
}
13501356

1351-
$urls = $session->getResponsePathsAsLinks();
1357+
$urls = $session->getFiles();
13521358
if (!$session->hasError() AND!empty($urls)) {
13531359
$locations = '';
13541360
foreach ($urls AS $path => $link) {

application/Services/OpenCPU.php

Lines changed: 43 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
<?php
2-
2+
// todo:
3+
// differentiate calls into those that need auth and those that don't
4+
// in the call function, check whether opencpu server was set up with auth
5+
//
36
class OpenCPU {
47

5-
protected $baseUrl = 'https://public.opencpu.org';
8+
protected $localUrl = null;
9+
protected $publicUrl = null;
610
protected $libUri = '/ocpu/library';
711
protected $last_message = null;
812
protected $rLibPath = '/usr/local/lib/R/site-library';
@@ -52,40 +56,35 @@ protected function __construct($instance) {
5256
foreach ($config as $key => $value) {
5357
$property = lcfirst(preg_replace('/\s+/', '', ucwords(str_replace('_', ' ', $key))));
5458
if (property_exists($this, $property)) {
55-
$this->{$property} = $value;
59+
$this->{$property} = rtrim($value, "/");
5660
}
5761
}
62+
63+
if(!empty($config["base_url"]) && empty($config['public_url'])
64+
&& empty($config['local_url'])) {
65+
$this->localUrl = $config["base_url"];
66+
$this->publicUrl = $config["base_url"];
67+
}
5868

5969
$this->curl_opts = $this->curl_opts + array_val($config, 'curl_opts', array());
6070
}
6171

62-
/**
63-
* @param string $baseUrl
64-
*/
65-
public function setBaseUrl($baseUrl) {
66-
if ($baseUrl) {
67-
$baseUrl = rtrim($baseUrl, "/");
68-
$this->baseUrl = $baseUrl;
69-
}
72+
public function getPublicUrl() {
73+
return $this->publicUrl;
7074
}
7175

72-
public function getBaseUrl() {
73-
return $this->baseUrl;
76+
public function getLocalUrl() {
77+
return $this->localUrl;
7478
}
7579

7680
public function getRLibPath() {
7781
return $this->rLibPath;
7882
}
7983

80-
public function getRTempBaseUrl() {
84+
public function getRTempPublicUrl() {
8185
return self::TEMP_BASE_URL;
8286
}
8387

84-
public function setLibUrl($libUri) {
85-
$libUri = trim($libUri, "/");
86-
$this->libUri = '/' . $libUri;
87-
}
88-
8988
public function getLibUri() {
9089
return $this->libUri;
9190
}
@@ -135,9 +134,9 @@ public function getRequestInfo($item = null) {
135134
* @throws OpenCPU_Exception
136135
*/
137136
private function call($uri = '', $params = array(), $method = CURL::HTTP_METHOD_GET) {
138-
if ($uri && strstr($uri, $this->baseUrl) === false) {
137+
if ($uri && strstr($uri, $this->localUrl) === false) {
139138
$uri = "/" . ltrim($uri, "/");
140-
$url = $this->baseUrl . $this->libUri . $uri;
139+
$url = $this->localUrl . $this->libUri . $uri;
141140
} else {
142141
$url = $uri;
143142
}
@@ -168,7 +167,7 @@ private function call($uri = '', $params = array(), $method = CURL::HTTP_METHOD_
168167
return new OpenCPU_Session(null, null, $results, $this);
169168
} elseif ($this->curl_info['http_code'] < 200 || $this->curl_info['http_code'] > 302) {
170169
if (!$results) {
171-
$results = "OpenCPU server '{$this->baseUrl}' could not be contacted";
170+
$results = "OpenCPU server '{$this->publicUrl}' could not be contacted";
172171
}
173172
throw new OpenCPU_Exception($results, $this->curl_info['http_code']);
174173
}
@@ -307,14 +306,19 @@ public function getKey() {
307306
* Get an array of files present in current session
308307
*
309308
* @param string $match You can match only files with some slug in the path name
310-
* @param string $baseURL URL segment to prepend to paths
309+
* @param string $localUrl URL segment to prepend to paths
311310
* @return array
312311
*/
313-
public function getFiles($match = '/files/', $baseURL = null) {
312+
public function getFiles($match = '/files/', $baseUrl = null) {
314313
if (!$this->key) {
315314
return null;
316315
}
317316

317+
if($baseUrl !== null) {
318+
$baseUrl = str_replace($this->caller()->getLocalUrl(),
319+
$this->caller()->getPublicUrl(), $baseUrl);
320+
}
321+
318322
$files = array();
319323
$result = explode("\n", $this->raw_result);
320324
foreach ($result as $path) {
@@ -323,38 +327,7 @@ public function getFiles($match = '/files/', $baseURL = null) {
323327
}
324328

325329
$id = basename($path);
326-
$files[$id] = $baseURL ? $baseURL . $path : $this->getResponsePath($path);
327-
}
328-
return $files;
329-
}
330-
331-
/**
332-
* Get absolute URLs of all resources in the response
333-
*
334-
* @return array
335-
*/
336-
public function getResponsePaths() {
337-
if (!$this->key || $this->isJSONResult()) {
338-
return null;
339-
}
340-
341-
$result = explode("\n", $this->raw_result);
342-
$files = array();
343-
foreach ($result as $id => $path) {
344-
$files[$id] = $this->getResponsePath($path);
345-
}
346-
return $files;
347-
}
348-
349-
public function getResponsePathsAsLinks() {
350-
if (!$this->key || $this->isJSONResult()) {
351-
return null;
352-
}
353-
354-
$result = explode("\n", $this->raw_result);
355-
$files = array();
356-
foreach ($result as $path) {
357-
$files[$path] = $this->getResponsePath($path);
330+
$files[$id] = $baseUrl ? $baseUrl . $path : $this->getResponsePath($path);
358331
}
359332
return $files;
360333
}
@@ -363,8 +336,9 @@ public function getLocation() {
363336
return $this->location;
364337
}
365338

366-
public function getFileURL($path) {
367-
return $this->getResponsePath('/files/' . $path);
339+
public function getPublicLocation() {
340+
return str_replace($this->caller()->getLocalUrl(),
341+
$this->caller()->getPublicUrl(), $this->location);
368342
}
369343

370344
public function getObject($name = 'json', $params = array()) {
@@ -379,8 +353,8 @@ public function getObject($name = 'json', $params = array()) {
379353
$object = $this->getJSONObject($object);
380354
}
381355
if (is_string($object)) {
382-
$object = str_replace($this->ocpu->getRLibPath(), $this->getBaseUrl() . $this->ocpu->getLibUri(), $object);
383-
return str_replace($this->ocpu->getRTempBaseUrl(), $this->getLocation() . 'files/', $object);
356+
$object = str_replace($this->ocpu->getRLibPath(), $this->getPublicUrl() . $this->ocpu->getLibUri(), $object);
357+
return str_replace($this->ocpu->getRTempPublicUrl(), $this->getPublicLocation() . 'files/', $object);
384358
}
385359

386360
return $object;
@@ -399,8 +373,8 @@ public function getJSONObject($string = null, $as_assoc = true) {
399373
// if decoded object is a non-empty array, get it's first element
400374
if (is_array($json) && array_key_exists(0, $json)) {
401375
if (is_string($json[0])) {
402-
$string = str_replace($this->ocpu->getRLibPath(), $this->getBaseUrl() . $this->ocpu->getLibUri(), $json[0]);
403-
return str_replace($this->ocpu->getRTempBaseUrl(), $this->getLocation() . 'files/', $string);
376+
$string = str_replace($this->ocpu->getRLibPath(), $this->getLocalUrl() . $this->ocpu->getLibUri(), $json[0]);
377+
return str_replace($this->ocpu->getRTempPublicUrl(), $this->getPublicLocation() . 'files/', $string);
404378
}
405379
return $json[0];
406380
}
@@ -464,12 +438,16 @@ public function getResponseHeaders() {
464438
return $this->caller()->getResponseHeaders();
465439
}
466440

467-
public function getBaseUrl() {
468-
return $this->caller()->getBaseUrl();
441+
public function getPublicUrl() {
442+
return $this->caller()->getPublicUrl();
443+
}
444+
445+
public function getLocalUrl() {
446+
return $this->caller()->getLocalUrl();
469447
}
470448

471449
protected function getResponsePath($path) {
472-
return $this->caller()->getBaseUrl() . $path;
450+
return $this->caller()->getPublicUrl() . $path;
473451
}
474452

475453
}

0 commit comments

Comments
 (0)