Skip to content

Commit

Permalink
Merge branch 'hotfix/v0.17.14'
Browse files Browse the repository at this point in the history
  • Loading branch information
cyriltata committed Jun 14, 2018
2 parents 0477b7d + 139a972 commit 84a8ceb
Show file tree
Hide file tree
Showing 9 changed files with 63 additions and 23 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/).

## [0.17.14] - 14.06.2018
### Added
* Logout action for RUNs

## [0.17.13] - 12.06.2018
### Fixed
* Show-ifs: Use previous show-if value for paginated survey
Expand Down
10 changes: 9 additions & 1 deletion application/Controller/RunController.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ protected function settingsAction() {
}

// People who have no session in the run need not set anything
$session = new RunSession($this->fdb, $run->id, 'cron', $this->user->user_code);
$session = new RunSession($this->fdb, $run->id, 'cron', $this->user->user_code, $run);
if (!$session->id) {
formr_error(401, 'Unauthorized', 'You cannot create settings in a study you have not participated in.');
}
Expand Down Expand Up @@ -93,6 +93,14 @@ protected function settingsAction() {
));
}

protected function logoutAction() {
$run = $this->getRun();
Session::destroy();
$hint = 'Session Ended';
$text = 'Your session was successfully closed! You can restart a new session by clicking the link below.';
formr_error(200, 'OK', $text, $hint, run_url($run->name), 'Start New Session');
}

protected function monkeyBarAction($action = '') {
$action = str_replace('ajax_', '', $action);
$allowed_actions = array('send_to_position', 'remind', 'next_in_run', 'delete_user', 'snip_unit_session');
Expand Down
39 changes: 38 additions & 1 deletion application/Library/Functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,13 +135,17 @@ function bad_request_header() {
header('HTTP/1.0 500 Bad Request');
}

function formr_error($code = 500, $title = 'Bad Request', $text = 'Request could not be processed', $hint = null, $link = null) {
function formr_error($code = 500, $title = 'Bad Request', $text = 'Request could not be processed', $hint = null, $link = null, $link_text = null) {
$code = $code ? $code : 500;
header("HTTP/1.0 {$code} {$title}");
if ($link === null) {
$link = site_url();
}

if ($link_text === null) {
$link_text = 'Go to Site';
}

if (php_sapi_name() == 'cli') {
echo date('r') . " Error {$code}: {$text} \n";
exit;
Expand All @@ -152,6 +156,7 @@ function formr_error($code = 500, $title = 'Bad Request', $text = 'Request could
'title' => $hint ? $hint : $title,
'text' => $text,
'link' => $link,
'link_text' => $link_text,
));
exit;
}
Expand Down Expand Up @@ -1615,3 +1620,35 @@ function fwrite_json($handle, $data) {
}
}
}

function do_run_shortcodes($text, $run_name, $sess_code) {
$link_tpl = '<a href="%{url}">%{text}</a>';
if ($run_name) {
$login_url = run_url($run_name, null, array('code' => $sess_code));
$logout_url = run_url($run_name, 'logout', array('code' => $sess_code));
$settings_url = run_url($run_name, 'settings', array('code' => $sess_code));
} else {
$login_url = $settings_url = site_url();
$logout_url = site_url('logout');
//alert("Generated a login link, but no run was specified", 'alert-danger');
}


$settings_link = Template::replace($link_tpl, array('url' => $settings_url, 'text' => 'Settings Link'));
$login_link = Template::replace($link_tpl, array('url' => $login_url, 'text' => 'Login Link'));
$logout_link = Template::replace($link_tpl, array('url' => $logout_url, 'text' => 'Logout Link'));

$text = str_replace("{{login_link}}", $login_link, $text);
$text = str_replace("{{login_url}}", $login_url, $text);
$text = str_replace("{{login_code}}", urlencode($sess_code), $text);
$text = str_replace("{{settings_link}}", $settings_link, $text);
$text = str_replace("{{settings_url}}", $settings_url, $text);
$text = str_replace("{{logout_link}}", $logout_link, $text);
$text = str_replace("{{logout_url}}", $logout_url, $text);
$text = str_replace(urlencode("{{login_url}}"), $login_url, $text);
$text = str_replace(urlencode("{{login_code}}"), urlencode($sess_code), $text);
$text = str_replace(urlencode("{{settings_url}}"), $settings_url, $text);
$text = str_replace(urlencode("{{logout_url}}"), $logout_url, $text);

return $text;
}
1 change: 1 addition & 0 deletions application/Library/Session.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public static function start() {
}

public static function destroy() {
setcookie(session_name(), '', time() - 3600);
session_unset();
session_destroy();
}
Expand Down
20 changes: 3 additions & 17 deletions application/Model/Email.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,27 +111,13 @@ public function getSubject() {

protected function substituteLinks($body) {
$sess = null;
$run_name = null;
if (isset($this->run_name)) {
$run_name = $this->run_name;
$sess = isset($this->session) ? $this->session : "TESTCODE";
$login_link = run_url($this->run_name, null, array('code' => $sess));
} else {
$login_link = site_url();
alert("Generated a login link, but no run was specified", 'alert-danger');
}

$settings_link = run_url($this->run_name, 'settings', array('code' => $sess));
$settings_link_html = '<a href="'. $settings_link . '">Settings link</a>';

$login_link_html = '<a href="'. $login_link . '">Login link</a>';

$body = str_replace("{{login_link}}", $login_link_html, $body);
$body = str_replace("{{login_url}}", $login_link, $body);
$body = str_replace("{{login_code}}", urlencode($sess), $body);
$body = str_replace("{{settings_link}}", $settings_link_html, $body);
$body = str_replace("{{settings_url}}", $settings_link, $body);
$body = str_replace(urlencode("{{login_url}}"), $login_link, $body);
$body = str_replace(urlencode("{{login_code}}"), urlencode($sess), $body);
$body = str_replace(urlencode("{{settings_url}}"), $settings_link, $body);
$body = do_run_shortcodes($body, $run_name, $sess);
return $body;
}

Expand Down
6 changes: 5 additions & 1 deletion application/Model/Page.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,10 @@ public function exec() {
return true; // never show to the cronjob
endif;

$run_name = $sess_code = null;
if ($this->run_session) {
$run_name = $this->run_session->run_name;
$sess_code = $this->run_session->session;
$this->run_session->end();
}

Expand All @@ -111,9 +114,10 @@ public function exec() {
return true; // wait for openCPU to be fixed!
}

$body = do_run_shortcodes($this->body_parsed, $run_name, $sess_code);
return array(
// 'title' => $this->title,
'body' => $this->body_parsed
'body' => $body,
);
}

Expand Down
2 changes: 1 addition & 1 deletion application/View/public/error.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

<p><?php echo $text; ?></p>
<?php if ($link): ?>
<p class="back"> <a href="<?= $link ?>">Go to Site</a> </p>
<p class="back"> <a href="<?= $link ?>"><?= $link_text ?></a> </p>
<?php endif; ?>
</div>
<div>
Expand Down
2 changes: 1 addition & 1 deletion application/View/public/run/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<?php Template::load('public/head') ?>
</head>

<body class="<?php echo isset($bodyClass) ? $bodyClass : ''; ?>">
<body class="<?php echo isset($bodyClass) ? $bodyClass : ''; ?>" data-url="<?php echo run_url($run->name); ?>">

<div id="fmr-page" class="fmr-about">
<div class="container run-container">
Expand Down
2 changes: 1 addition & 1 deletion setup.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
}

// Set current formr version (bumped on release)
$settings['version'] = 'v0.17.13';
$settings['version'] = 'v0.17.14';

// Load application autoloader
$autoloader = require_once APPLICATION_PATH . 'Library/Autoloader.php';
Expand Down

0 comments on commit 84a8ceb

Please sign in to comment.