Skip to content

Commit

Permalink
Merge branch 'release/v0.21.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
rubenarslan committed Mar 7, 2024
2 parents 4650bf4 + dcad053 commit e68b959
Show file tree
Hide file tree
Showing 2,341 changed files with 799,039 additions and 667 deletions.
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ nohup.out
webroot/*.html
webroot/assets/*.mp4
webroot/assets/*.html
webroot/assets/bower_components
webroot/assets/lib/bower_components
/bin/migra.php
/*.key
formr.feature_dockerprep.version
webroot/study
bin/create-named-sessions.php
bin/create-named-sessions.php
2 changes: 1 addition & 1 deletion .zenodo.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"upload_type": "software",
"creators": [
{
"affiliation": "Center for Adaptive Rationality, Max Planck Institute for Human Development",
"affiliation": "Wilhelm Wundt Institute of Psychology, University of Leipzig",
"name": "Ruben C. Arslan",
"orcid": "0000-0002-6670-5658"
},
Expand Down
14 changes: 7 additions & 7 deletions application/Controller/AdminAccountController.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public function __construct(Site &$site) {
public function indexAction() {
if (!$this->user->loggedIn()) {
alert('You need to be logged in to go here.', 'alert-info');
$this->request->redirect('login');
$this->request->redirect('admin/account/login');
}

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


Expand Down Expand Up @@ -156,13 +156,13 @@ public function verifyEmailAction() {

if ($this->request->isHTTPGetRequest() && $this->request->str('token')) {
$user->resendVerificationEmail($this->request->str('token'));
$this->request->redirect('login');
$this->request->redirect('admin/account/login');
} elseif (!$verification_token || !$email) {
alert("You need to follow the link you received in your verification mail.");
$this->request->redirect('login');
$this->request->redirect('admin/account/login');
} else {
$user->verifyEmail($email, $verification_token);
$this->request->redirect('login');
$this->request->redirect('admin/account/login');
};
}

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

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

Expand Down
2 changes: 1 addition & 1 deletion application/Controller/AdminController.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ protected function setView($template, $vars = array()) {
protected function header() {
if (!($cookie = Session::getAdminCookie())) {
alert('You need to login to access the admin section', 'alert-warning');
$this->request->redirect('login');
$this->request->redirect('admin/account/login');
}

$this->user = new User($cookie[0], $cookie[1]);
Expand Down
2 changes: 1 addition & 1 deletion application/Controller/ApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public function osfAction($do = '') {
$user = Site::getCurrentUser();
if (!$user->loggedIn()) {
alert('You need to login to access this section', 'alert-warning');
redirect_to('login');
redirect_to('admin/account/login');
}

$osfconfg = Config::get('osf');
Expand Down
18 changes: 12 additions & 6 deletions application/Functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@ function formr_log_exception(Exception $e, $prefix = '', $debug_data = null) {
}

function get_log_file($filename) {
return APPLICATION_ROOT . "tmp/logs/$filename";
if(Config::get('error_to_stderr') == 1) {
return "php://stderr";
} else {
return APPLICATION_ROOT . "tmp/logs/$filename";
}
}

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

$protocol = Config::get('define_root.protocol');
$domain = trim(Config::get('define_root.doc_root', ''), "\/\\");
$protocol = Config::get('protocol');
# use different domain for studies if set, independent of wildcard subdomain setting
$domain = trim(Config::get('study_domain', ''), "*\/\\");
$subdomain = null;

if (Config::get('use_study_subdomains')) {
$domain = Config::get('define_root.study_domain', $domain); # use different domain for studies if set
$subdomain = strtolower($name) . '.';
$subdomain = strtolower($name);
} else {
$domain .= '/' . $name;
}

$url = $protocol . $subdomain . $domain;
if ($action) {
$action = trim($action, "\/\\");
Expand Down Expand Up @@ -1348,7 +1354,7 @@ function opencpu_debug($session, OpenCPU $ocpu = null, $rtype = 'json') {
}
}

$urls = $session->getResponsePathsAsLinks();
$urls = $session->getFiles();
if (!$session->hasError() AND!empty($urls)) {
$locations = '';
foreach ($urls AS $path => $link) {
Expand Down
108 changes: 43 additions & 65 deletions application/Services/OpenCPU.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
<?php

// todo:
// differentiate calls into those that need auth and those that don't
// in the call function, check whether opencpu server was set up with auth
//
class OpenCPU {

protected $baseUrl = 'https://public.opencpu.org';
protected $localUrl = null;
protected $publicUrl = null;
protected $libUri = '/ocpu/library';
protected $last_message = null;
protected $rLibPath = '/usr/local/lib/R/site-library';
Expand Down Expand Up @@ -52,40 +56,35 @@ protected function __construct($instance) {
foreach ($config as $key => $value) {
$property = lcfirst(preg_replace('/\s+/', '', ucwords(str_replace('_', ' ', $key))));
if (property_exists($this, $property)) {
$this->{$property} = $value;
$this->{$property} = rtrim($value, "/");
}
}

if(!empty($config["base_url"]) && empty($config['public_url'])
&& empty($config['local_url'])) {
$this->localUrl = $config["base_url"];
$this->publicUrl = $config["base_url"];
}

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

/**
* @param string $baseUrl
*/
public function setBaseUrl($baseUrl) {
if ($baseUrl) {
$baseUrl = rtrim($baseUrl, "/");
$this->baseUrl = $baseUrl;
}
public function getPublicUrl() {
return $this->publicUrl;
}

public function getBaseUrl() {
return $this->baseUrl;
public function getLocalUrl() {
return $this->localUrl;
}

public function getRLibPath() {
return $this->rLibPath;
}

public function getRTempBaseUrl() {
public function getRTempPublicUrl() {
return self::TEMP_BASE_URL;
}

public function setLibUrl($libUri) {
$libUri = trim($libUri, "/");
$this->libUri = '/' . $libUri;
}

public function getLibUri() {
return $this->libUri;
}
Expand Down Expand Up @@ -135,9 +134,9 @@ public function getRequestInfo($item = null) {
* @throws OpenCPU_Exception
*/
private function call($uri = '', $params = array(), $method = CURL::HTTP_METHOD_GET) {
if ($uri && strstr($uri, $this->baseUrl) === false) {
if ($uri && strstr($uri, $this->localUrl) === false) {
$uri = "/" . ltrim($uri, "/");
$url = $this->baseUrl . $this->libUri . $uri;
$url = $this->localUrl . $this->libUri . $uri;
} else {
$url = $uri;
}
Expand Down Expand Up @@ -168,7 +167,7 @@ private function call($uri = '', $params = array(), $method = CURL::HTTP_METHOD_
return new OpenCPU_Session(null, null, $results, $this);
} elseif ($this->curl_info['http_code'] < 200 || $this->curl_info['http_code'] > 302) {
if (!$results) {
$results = "OpenCPU server '{$this->baseUrl}' could not be contacted";
$results = "OpenCPU server '{$this->publicUrl}' could not be contacted";
}
throw new OpenCPU_Exception($results, $this->curl_info['http_code']);
}
Expand Down Expand Up @@ -307,14 +306,19 @@ public function getKey() {
* Get an array of files present in current session
*
* @param string $match You can match only files with some slug in the path name
* @param string $baseURL URL segment to prepend to paths
* @param string $localUrl URL segment to prepend to paths
* @return array
*/
public function getFiles($match = '/files/', $baseURL = null) {
public function getFiles($match = '/files/', $baseUrl = null) {
if (!$this->key) {
return null;
}

if($baseUrl !== null) {
$baseUrl = str_replace($this->caller()->getLocalUrl(),
$this->caller()->getPublicUrl(), $baseUrl);
}

$files = array();
$result = explode("\n", $this->raw_result);
foreach ($result as $path) {
Expand All @@ -323,38 +327,7 @@ public function getFiles($match = '/files/', $baseURL = null) {
}

$id = basename($path);
$files[$id] = $baseURL ? $baseURL . $path : $this->getResponsePath($path);
}
return $files;
}

/**
* Get absolute URLs of all resources in the response
*
* @return array
*/
public function getResponsePaths() {
if (!$this->key || $this->isJSONResult()) {
return null;
}

$result = explode("\n", $this->raw_result);
$files = array();
foreach ($result as $id => $path) {
$files[$id] = $this->getResponsePath($path);
}
return $files;
}

public function getResponsePathsAsLinks() {
if (!$this->key || $this->isJSONResult()) {
return null;
}

$result = explode("\n", $this->raw_result);
$files = array();
foreach ($result as $path) {
$files[$path] = $this->getResponsePath($path);
$files[$id] = $baseUrl ? $baseUrl . $path : $this->getResponsePath($path);
}
return $files;
}
Expand All @@ -363,8 +336,9 @@ public function getLocation() {
return $this->location;
}

public function getFileURL($path) {
return $this->getResponsePath('/files/' . $path);
public function getPublicLocation() {
return str_replace($this->caller()->getLocalUrl(),
$this->caller()->getPublicUrl(), $this->location);
}

public function getObject($name = 'json', $params = array()) {
Expand All @@ -379,8 +353,8 @@ public function getObject($name = 'json', $params = array()) {
$object = $this->getJSONObject($object);
}
if (is_string($object)) {
$object = str_replace($this->ocpu->getRLibPath(), $this->getBaseUrl() . $this->ocpu->getLibUri(), $object);
return str_replace($this->ocpu->getRTempBaseUrl(), $this->getLocation() . 'files/', $object);
$object = str_replace($this->ocpu->getRLibPath(), $this->getPublicUrl() . $this->ocpu->getLibUri(), $object);
return str_replace($this->ocpu->getRTempPublicUrl(), $this->getPublicLocation() . 'files/', $object);
}

return $object;
Expand All @@ -399,8 +373,8 @@ public function getJSONObject($string = null, $as_assoc = true) {
// if decoded object is a non-empty array, get it's first element
if (is_array($json) && array_key_exists(0, $json)) {
if (is_string($json[0])) {
$string = str_replace($this->ocpu->getRLibPath(), $this->getBaseUrl() . $this->ocpu->getLibUri(), $json[0]);
return str_replace($this->ocpu->getRTempBaseUrl(), $this->getLocation() . 'files/', $string);
$string = str_replace($this->ocpu->getRLibPath(), $this->getLocalUrl() . $this->ocpu->getLibUri(), $json[0]);
return str_replace($this->ocpu->getRTempPublicUrl(), $this->getPublicLocation() . 'files/', $string);
}
return $json[0];
}
Expand Down Expand Up @@ -464,12 +438,16 @@ public function getResponseHeaders() {
return $this->caller()->getResponseHeaders();
}

public function getBaseUrl() {
return $this->caller()->getBaseUrl();
public function getPublicUrl() {
return $this->caller()->getPublicUrl();
}

public function getLocalUrl() {
return $this->caller()->getLocalUrl();
}

protected function getResponsePath($path) {
return $this->caller()->getBaseUrl() . $path;
return $this->caller()->getPublicUrl() . $path;
}

}
Expand Down
Loading

0 comments on commit e68b959

Please sign in to comment.