Skip to content

Commit

Permalink
Bug #6/#7, Initial pilot poem text(s); 'poem server' [iet:9820855][ie…
Browse files Browse the repository at this point in the history
…t:9702401]

* poem Web server - automatically re-generate poem images (prevent copy-paste)
* Uses Phantomjs
* Code date: 14-15 August 2017.
  • Loading branch information
nfreear committed Aug 21, 2017
1 parent eb7712b commit a84dad7
Show file tree
Hide file tree
Showing 9 changed files with 165 additions and 45 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,9 @@ node_modules
.jshint*
.env

/pix

phantomjs
rasterize.js

#End.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ before_install:

install:
- composer install
- composer npm-install-dev
- composer npm-install
- composer eslint-config
- composer jshint-config
- composer write-ignore-xml
Expand Down
27 changes: 18 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Available via IET-OU Satis:

## Purpose

To facilitate pilot studies using Moodle (e.g. for TeSLA) by:
To facilitate pilot research studies using Moodle (e.g. for TeSLA) by:

1. Enabling OpenID login using just a username, not a full URL (e.g. https://openid.example.org/{username})
2. Simple login page with custom instructions (edit via Moodle language customisations), `/index.php`,
Expand All @@ -31,8 +31,8 @@ Note: this plugin probably needs splitting into two or more plugins!
## Install

1. To integrate within Moodle, either use the composer-based method described below, or unzip the code at:
```
PATHTOMOODLE/auth/ouopenid
```sh
{PATHTOMOODLE}/auth/ouopenid
```

Then, enable the plugin in the [authentication plugins section of your Moodle's site administration][auth].
Expand All @@ -54,6 +54,17 @@ composer test
composer eslint
```
## Generate text-images
Re-create images of poetry / other text, to prevent copy-paste
(e.g. for TeSLA keystroke dynamics pilot):
```sh
composer phantom-clone
composer poem-srv
composer poem-images
```
## Site-wide Javascript and styles
### Additional HTML - development
Expand All @@ -66,19 +77,17 @@ To embed the plugin's Javascript and stylesheet on every page:
```html
<link href="/auth/ouopenid/style/ouop-styles.less" rel="stylesheet/less" />
<script src="/auth/ouopenid/user/ouop-local-fixes.js"></script>
<script src="/auth/ouopenid/user/ouop-analytics"></script>
<script src="/auth/ouopenid/user/script.js"></script>
<script src="/auth/ouopenid/dist.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/less.js/2.7.2/less.min.js"></script>
<script src="https://unpkg.com/less@2.7.2/dist/less.min.js"></script>
```
### Additional HTML - live
```html
<link href="/auth/ouopenid/style/ouop-styles.css" rel="stylesheet" />
<script src="/auth/ouopenid/ouop.min.js"></script>
<link href="/auth/ouopenid/style/ouop-styles.css?r=2017-08-16.a" rel="stylesheet" />
<script src="/auth/ouopenid/dist.min.js?r=2017-08-16.a"></script>
```
Expand Down
39 changes: 39 additions & 0 deletions bin/www-poem.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php
if ( php_sapi_name() === 'cli' ) die('Direct access not allowed. Exiting');

/**
* A quick & dirty "poem server".
*
* php -S localhost:8000 bin/www-poem.php
*
* @package auth_ouopenid
* @author Nick Freear, 16-August-2017.
* @copyright (c) 2017 The Open University.
*/

// Direct include - don't use Moodle "get_string" !
require_once __DIR__ . '/../lang/en/local_oupilot_poem.php';

define( 'STRING_ID', filter_input( INPUT_GET, 'id', FILTER_SANITIZE_STRING ));
define( 'SERIF', filter_input( INPUT_GET, 'serif', FILTER_VALIDATE_BOOLEAN ));

$poem = STRING_ID && isset($string[ STRING_ID ]) ? $string[ STRING_ID ] : null;

if (! $poem) {
header( 'HTTP/1.1 404 Not Found', 404 );
?> Poem / text not found. <?php
exit;
}

?><!doctype html> <meta charset="utf-8"> <title> Poem (<?php echo STRING_ID ?>) </title>

<style>
body { margin: 4px; color: #333; font: 1.1em <?php echo SERIF ? 'Georgia,' : 'sans-' ?>serif; }
p { margin: 0; line-height: 1.2em; letter-spacing: .01em; }
.verse { margin-top: .7em; }
.v1 { margin: 0; }
.in { text-indent: 1em; }
h1 { font: 1.5em sans-serif; margin: .5em 0; }
</style>

<?php echo $poem ?>
65 changes: 33 additions & 32 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
"composer/installers": "^1.2"
},
"require-dev": {
"moodlerooms/moodle-plugin-ci": "^1.5",
"moodlerooms/moodle-plugin-ci": "^2.0",
"jakub-onderka/php-parallel-lint": "^0.9.2",
"squizlabs/php_codesniffer": "2.8.1"
"squizlabs/php_codesniffer": "2.9.1"
},
"bin": [
"bin/ouop-query.php",
Expand All @@ -37,53 +37,54 @@
"echo '\t<library><location>node_modules/</location></library>' >> thirdpartylibs.xml",
"echo '</libraries>' >> thirdpartylibs.xml"
],
"ci-install": "vendor/bin/moodle-plugin-ci install",
"ci-install": "moodle-plugin-ci install",
"ci-test": [
"vendor/bin/moodle-plugin-ci phplint .",
"vendor/bin/moodle-plugin-ci phpcpd .",
"# vendor/bin/moodle-plugin-ci phpmd .",
"# vendor/bin/moodle-plugin-ci codechecker .",
"vendor/bin/moodle-plugin-ci csslint .",
"vendor/bin/moodle-plugin-ci shifter .",
"vendor/bin/moodle-plugin-ci jshint .",
"# N/A? vendor/bin/moodle-plugin-ci validate .",
"vendor/bin/moodle-plugin-ci phpunit . --coverage-text"
"moodle-plugin-ci phplint .",
"moodle-plugin-ci phpcpd .",
"# moodle-plugin-ci phpmd .",
"# moodle-plugin-ci codechecker .",
"moodle-plugin-ci csslint .",
"moodle-plugin-ci shifter .",
"moodle-plugin-ci jshint .",
"# N/A? moodle-plugin-ci validate .",
"moodle-plugin-ci phpunit . --coverage-text"
],
"qa": "vendor/bin/moodle-plugin-ci codechecker .",
"qa": "moodle-plugin-ci codechecker .",
"sym-links": [
"cd ../moodle-auth-openid && ln -s ../moodle-auth-ouopenid/event.php"
],
"npm-install": "npm i browserify@14 derequire@2 uglify-js@3 less@2",
"npm-install-dev": [
"composer npm-install",
"npm i eslint eslint-plugin-react semistandard@11",
"npm-install": [
"npm install",
"# npm i eslint eslint-plugin-react semistandard@11",
"npm i -g csslint && npm i -g jshint"
],
"phantom-clone": "git clone --depth=5 https://github.com/ariya/phantomjs.git && ln -s phantomjs/examples/rasterize.js",
"poem-srv": "php -S localhost:8000 bin/www-poem.php",
"poem-images": [
"phantomjs rasterize.js 'http://localhost:8000?id=poem_1&serif=1' pix/poem_1.png # '600px*716px'",
"phantomjs rasterize.js 'http://localhost:8000?id=poem_2&serif=1' pix/poem_2.png"
],
"build": [
"node_modules/.bin/uglifyjs user/*.js --comments='/^!/' -bo ouop.min.js",
"node_modules/.bin/lessc style/*.less style/ouop-styles.css"
"npm run browserify",
"npm run uglify && npm run uglify-2",
"npm run less"
],
"browserify": "node_modules/.bin/browserify src/index.js | node_modules/.bin/derequire > dist.min.js",
"jshint-config": "# echo '{ }' > .jshintrc;\necho '*.min.js\n*.dist.js' > .jshintignore",
"jshint-config": "# echo '{ }' > .jshintrc;\necho '*.min.js\ndist.js' > .jshintignore",
"eslint-config": [
"echo '---\n extends: eslint:recommended\n globals:\n window: false\n root: true\n' > .eslintrc.yaml",
"echo '{\n \"extends\": \"eslint:recommended\",\n \"globals\": { \"window\": false }\n}' > .eslintrc-XX.json"
],
"eslint-echo": "node_modules/.bin/eslint --print-config .eslintrc.yaml",
"eslint": [
"node_modules/.bin/eslint js/ user/*.js && echo eslint OK!"
],
"semistandard": "node_modules/.bin/semistandard",
"test": [
"vendor/bin/parallel-lint --exclude vendor .",
"vendor/bin/phpcs --standard=PSR2 -n db/User.php",
"parallel-lint --exclude vendor .",
"phpcs --standard=PSR2 -n db/User.php",
"composer cn",
"composer semistandard",
"composer eslint",
"# npm run semi",
"# npm run eslint",
"php -r 'simplexml_load_file(\"db/install.xml\");' && echo install.xml OK!"
],
"mcs": "vendor/bin/phpcs --standard=./moodle-core.xml --ignore=vendor --ignore=.git --extensions=php .",
"phpcs": "vendor/bin/phpcs --standard=./phpcs.xml --ignore=vendor --ignore=.git --extensions=php .",
"cn": "vendor/bin/phpcs --standard=PHPCS --sniffs=Generic.NamingConventions.ConstructorName --extensions=php --ignore=vendor ."
"mcs": "phpcs --standard=./moodle-core.xml --ignore=vendor --ignore=.git --extensions=php .",
"phpcs": "phpcs --standard=./phpcs.xml --ignore=vendor --ignore=.git --extensions=php .",
"cn": "phpcs --standard=PHPCS --sniffs=Generic.NamingConventions.ConstructorName --extensions=php --ignore=vendor ."
}
}
4 changes: 3 additions & 1 deletion db/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -315,11 +315,13 @@ public static function getConsentEmbedUrl()
/** Get language strings for Javascript / Ajax [ MOVE ]
* @return object
*/
public static function getStringsAjax()
public static function getStringsAjax($poems = false)
{
$string_ids = [ 'continuelink', 'form_warning', 'form_redirect_msg', 'wordcount', 'wordcount_title',
'continuebutton', 'question_progress', 'return_msg', 'newenrol_msg', 'testmail', 'post_survey_msg' ];

$string_ids = $poems ? array_merge($string_ids, [ 'poem_1', 'poem_2' ]) : $string_ids;

return get_strings($string_ids, 'auth_ouopenid');
}

Expand Down
3 changes: 3 additions & 0 deletions lang/en/auth_ouopenid.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
$string[ 'pluginname' ] = 'OU-OpenID';
$string[ 'auth_ouopeniddescription' ] = 'This plugin is a wrapper around the OpenID authentication plugin';

// A hack!
require_once __DIR__ . '/local_oupilot_poem.php';

// Used via Javascript / Ajax.
$string[ 'testmail' ] = 'tesla.ouuk+{$a}@gmail.com';
$string[ 'continuelink' ] = 'Continue to your pilot course &rarr;';
Expand Down
60 changes: 60 additions & 0 deletions lang/en/local_oupilot_poem.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?php
/**
* POEMs! Language strings.
*
* @package auth_ouopenid
* @author Nick Freear, 16-August-2017.
* @copyright (c) 2017 The Open University.
*/

// Poem 1 ~~ 'IF'.
$string[ 'poem_1_title' ] = 'If—, by Rudyard Kipling';
$string[ 'poem_1_url' ] = 'https://www.poetryfoundation.org/poems/46473/if---';
$string[ 'poem_1' ] = <<<EOT
<h1> If—, by Rudyard Kipling </h1>
<p class="verse v1">If you can keep your head when all about you
<p class="in">Are losing theirs and blaming it on you,
<p> If you can trust yourself when all men doubt you,
<p class="in">But make allowance for their doubting too;
<p> If you can wait and not be tired by waiting,
<p class="in">Or being lied about, don’t deal in lies,
<p> Or being hated, don’t give way to hating,
<p class="in">And yet don’t look too good, nor talk too wise:
<p class="verse">If you can dream—and not make dreams your master;
<p class="in">If you can think—and not make thoughts your aim;
<p> If you can meet with Triumph and Disaster
<p class="in">And treat those two impostors just the same;
<p> If you can bear to hear the truth you’ve spoken
<p class="in">Twisted by knaves to make a trap for fools,
<p> Or watch the things you gave your life to, broken,
<p class="in">And stoop and build ’em up with worn-out tools:
<p class="verse">If you can make one heap of all your winnings
<p class="in">And risk it on one turn of pitch-and-toss,
<p> And lose, and start again at your beginnings
<p class="in">And never breathe a word about your loss;
<p> If you can force your heart and nerve and sinew
<p class="in">To serve your turn long after they are gone,
<p> And so hold on when there is nothing in you
<p class="in">Except the Will which says to them: ‘Hold on!’
<p class="verse">If you can talk with crowds and keep your virtue,
<p class="in">Or walk with Kings—nor lose the common touch,
<p> If neither foes nor loving friends can hurt you,
<p class="in">If all men count with you, but none too much;
<p> If you can fill the unforgiving minute
<p class="in">With sixty seconds’ worth of distance run,
<p> Yours is the Earth and everything that’s in it,
<p class="in">And—which is more—you’ll be a Man, my son!
EOT;

$string[ 'poem_2' ] = <<<EOT
<p> Poem 2 ...
EOT;
// End.
5 changes: 3 additions & 2 deletions user/ajax.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
require_once __DIR__ . '/../../../config.php';
require_once __DIR__ . '/../../../vendor/autoload.php';

define('DEBUG', filter_input(INPUT_GET, 'debug'));
define('DEBUG', filter_input(INPUT_GET, 'debug', FILTER_VALIDATE_BOOLEAN));
define('POEMS', filter_input(INPUT_GET, 'poems', FILTER_VALIDATE_BOOLEAN));
define('USER_LOGGED_IN', isloggedin()); // Was: ( 0 !== $USER->id )

if (DEBUG) {
Expand Down Expand Up @@ -51,7 +52,7 @@
'survey_urls'=> $prof->survey_urls,
'user_roles' => OuUser::getRoles(),
'redirect_url' => USER_LOGGED_IN ? $prof->redirect_url : null,
'strings' => USER_LOGGED_IN ? OuUser::getStringsAjax() : [],
'strings' => USER_LOGGED_IN ? OuUser::getStringsAjax(POEMS) : [],
'config' => USER_LOGGED_IN && $config ? $config : [ 'ga' => $config[ 'ga' ] ],
], DEBUG ? JSON_PRETTY_PRINT : null);

Expand Down

0 comments on commit a84dad7

Please sign in to comment.