Skip to content

Commit

Permalink
Added PHP example repository
Browse files Browse the repository at this point in the history
  • Loading branch information
Christian Clausner committed Oct 24, 2014
1 parent 63f7e5c commit ce46649
Show file tree
Hide file tree
Showing 5 changed files with 457 additions and 3 deletions.
80 changes: 80 additions & 0 deletions php-example-repository/config.inc.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
<?php
/*
* Copyright 2014 PRImA Research Lab, University of Salford, United Kingdom
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/*
* The following parameters will need to be retrieved from your system.
*/

//This username is sent for future use (multiuser systems that will need to
//track which changes were performed by which user)
$PARAMS['username'] = "user1";

/* Read all files in the fullview folder (JPEG images).
* The Documents array contains the document information,
* in the following structure:
* Example is for a document with ID 123:
* Documents[123][fullview] = "fullview/123.jpg"
*
* Then read all files in the attachments fonder (PAGE files).
* The Attachments array contains the attachment information,
* in the following structure:
* Example is for an attachment with ID 456 (for document ID 123):
* Attachments[456][Did] = "123"
* Attachments[456][path] = "attachments/456.xml"
*/
foreach (scandir(__DIR__."/repository/fullview") AS $key => $value) {
if ($value != "." && $value != "..") {
$Did_temp = pathinfo($value, PATHINFO_FILENAME);
$DATA['Documents'][$Did_temp]['fullview'] = "repository/fullview/" . $Did_temp . ".jpg";
}
}
foreach (scandir(__DIR__."/repository/attachments") AS $key => $value) {
if ($value != "." && $value != "..") {
//$Aid = substr(pathinfo($value, PATHINFO_FILENAME), strpos(pathinfo($value, PATHINFO_FILENAME), ".")+1);
$Aid_temp = pathinfo($value, PATHINFO_FILENAME);
$Did_temp = substr(pathinfo($value, PATHINFO_FILENAME), 0, strpos(pathinfo($value, PATHINFO_FILENAME), ".") );
$DATA['Attachments'][$Aid_temp]['Did'] = $Did_temp;
$DATA['Attachments'][$Aid_temp]['path'] = "repository/attachments/" . $value;
}
}


//The Appid is used is unique for each integration of the WebLayoutEdior tool.
//It is used by our server to recognise you and use the correct decryption key.
//It should be different for each integration application.
//This is used to log in to the PRIma Image Repository.
//If you change the example to use your own image repository,
//you might want to remove the AppId.
$PARAMS['Appid'] = "emop-dataset";

//The secret key is shared between your server and the WebLayoutEditor server.
//It is used to encrypt the authentication token passed between the two servers.
$PARAMS['secretKey'] = "CA8BC51AD641ADFAC55124FB3E000000";

/*
* The followig parameters are for the configuration of this sample website.
* The URLs have to be ready to accept query string parameters.
*/
$CONF['externalLinksBaseURL'] = "URL_TO_YOUR_SERVER/WebLayoutEditor?";

$CONF['enableLocalLinks'] = true;
$CONF['localLinksBaseURL'] = "http://localhost:8888/WebLayoutEditor.html?";


$CONF['enableDebugLinks'] = true;
$CONF['debugLinksBaseURL'] = "http://localhost:8888/WebLayoutEditor.html?gwt.codesvr=127.0.0.1:9997&";
?>
76 changes: 76 additions & 0 deletions php-example-repository/gateway.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<?php
/*
* Copyright 2014 PRImA Research Lab, University of Salford, United Kingdom
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/*
* This file takes as parameter the Aid and generates the access URL for the
* WebLayoutEditor, which is being displayed inline.
*/

include('config.inc.php');


//Retrieve Aid from the URL
$Aid = $_GET['Aid'];
$Did = $DATA['Attachments'][$Aid]['Did'];


function createAuthenticationToken($username, $secretKey)
{
$orig_json_array = json_encode(array('ip'=>$_SERVER['REMOTE_ADDR'], 'ts'=>time(), 'uid'=>$username));
$temp = $orig_json_array;
$secretKey = md5($secretKey);
$initialVector = mcrypt_create_iv(mcrypt_get_iv_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_CFB) ,MCRYPT_DEV_RANDOM);
$temp = mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $secretKey, $temp, MCRYPT_MODE_CFB, $initialVector);
$temp = $initialVector.$temp;
$temp = base64_encode($temp);
return urlencode($temp);
}


$authenticationToken = createAuthenticationToken($PARAMS['username'], $PARAMS['secretKey']);

$urlBase = $CONF['externalLinksBaseURL'];

//Check if we want to use local host (for development only)
isset($_GET['uselocal']) ? $uselocal = $_GET['uselocal'] : $uselocal = "0";
if ($uselocal==1) $urlBase = $CONF['localLinksBaseURL'];

//Check if we want to use debug (for development only)
isset($_GET['usedebug']) ? $usedebug = $_GET['usedebug'] : $usedebug = "0";
if ($usedebug==1) $urlBase = $CONF['debugLinksBaseURL'];

$targeturl = $urlBase . "Did=$Did&Aid=$Aid&Appid=".$PARAMS['Appid']."&a=$authenticationToken";

if ($usedebug==1) {


echo "<p><a href='$targeturl'>$targeturl</a></p>";
//header("Location: ". $targeturl);
}


echo "<body style=\"overflow: hidden;\">";
echo '<p><a href="javascript:history.go(-1);">Back</a></p>';

echo '<object data="'.$targeturl.'" type="text/html" style="width:100%; height:100%; margin:0px; padding: 0px;">';
echo "<p style=\"background: MistyRose; border: DeepPink 1px solid; font: 0.8em Verdana; color: darkred; padding: 10px; \"><span style=\"text-decoration: underline; font-weight: bold;\">Notice</span><br />If you are seeing this, there is an error!</p>";
echo '</object>';
echo "</body>";

exit(0);
?>

82 changes: 82 additions & 0 deletions php-example-repository/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
<?php
/*
* Copyright 2014 PRImA Research Lab, University of Salford, United Kingdom
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/*
* This file is a sample index page, for the EMOP project.
* The purpose of this mock website is to provide access to the WebLayoutEditor.
*
* Important information
* - Each document has an ID. This is referred to as Did.
* - For each document, there can be any number of PAGE files. Each PAGE file
* has it's own ID, referred to as Aid.
* - This index page, for every document contains links to specific attachments
* (different versions of PAGE files perhaps).
* - This is implemented in such a way, so that it is possible to keep track of
* changes/updates to the PAGE file, by storing each differen version as a
* new attachment (that has a different Aid, but is linked to the same Did.
* - The link to the gateway web page, includes the Aid, so that it can display
* the correct version of the PAGE file. If the Did for the particular
* document is required, you should ensure that your supporting database can
* provide that.
*
* Under production circumstances, a lot of the data required for this page
* would be retrieved from a database. In order to simplify this example, all
* required data is stored in config.inc.php in various arrays.
*
*/

header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past
header("Cache-Control: no-store, no-cache, must-revalidate"); // HTTP/1.1
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");



include('config.inc.php');
?>

<h1>Welcome to the WebLayoutEditor integration example</h1>


<? foreach ($DATA['Documents'] AS $Did => $Document): ?>
<h2>This section contains links to the WebLayoutEditor for image <?= $Did ?></h2>
<table border="1">
<thead>
<tr><th rowspan="2">Aid</th><th colspan="3">WebLayoutEditor</th></tr>
<tr><th>[hosted on PRImA]</th><th>[using localhost]</th><th>[using localhost and debug]</th></tr>
</thead>
<tbody>
<? foreach ($DATA['Attachments'] AS $Aid => $Attachment): ?>
<tr>
<td><?= $Aid ?></td>
<td><a href="gateway.php?Aid=<?= $Aid; ?>">Click</a></td>
<td>
<? if ($CONF['enableLocalLinks'] == TRUE): ?>
<a href="gateway.php?&uselocal=1&Aid=<?= $Aid; ?>">Click</a>
<? endif; ?>
</td>
<td>
<? if ($CONF['enableDebugLinks'] == TRUE): ?>
<a href="gateway.php?&usedebug=1&Aid=<?= $Aid; ?>">Click</a>
<? endif; ?>
</td>
</tr>
<? endforeach; ?>
</tbody>
</table>
<? endforeach; ?>

Loading

0 comments on commit ce46649

Please sign in to comment.