Skip to content

Commit

Permalink
refactored domain field into separate config.ini file
Browse files Browse the repository at this point in the history
  • Loading branch information
robstewart57 committed Nov 23, 2012
1 parent d5401cf commit 1987610
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 28 deletions.
3 changes: 3 additions & 0 deletions config.ini
@@ -0,0 +1,3 @@
; Setting the domain of this instance
[general]
domain=http://serena.macs.hw.ac.uk/serena/discover-me-semantically/
31 changes: 12 additions & 19 deletions generateRDF.php
Expand Up @@ -29,21 +29,22 @@
include( RDFAPI_INCLUDE_DIR . 'vocabulary/RDFS_C.php'); include( RDFAPI_INCLUDE_DIR . 'vocabulary/RDFS_C.php');
include( RDFAPI_INCLUDE_DIR . 'vocabulary/DC_C.php'); include( RDFAPI_INCLUDE_DIR . 'vocabulary/DC_C.php');
include( RDFAPI_INCLUDE_DIR . 'vocabulary/FOAF_C.php'); include( RDFAPI_INCLUDE_DIR . 'vocabulary/FOAF_C.php');
include("readConf.php");


$domain="http://serena.macs.hw.ac.uk/serena/discover-me-semantically/"; $domain=getDomain("config.ini");


function toAscii($str, $replace = array(), $delimiter = '-') { function toAscii($str, $replace = array(), $delimiter = '-') {
if (!empty($replace)) { if (!empty($replace)) {
$str = str_replace((array) $replace, ' ', $str); $str = str_replace((array) $replace, ' ', $str);
} }


$clean = iconv('UTF-8', 'ASCII//TRANSLIT', $str); $clean = iconv('UTF-8', 'ASCII//TRANSLIT', $str);
$clean = preg_replace("/[^a-zA-Z0-9\/_|+ -]/", '', $clean); $clean = preg_replace("/[^a-zA-Z0-9\/_|+ -]/", '', $clean);
$clean = strtolower(trim($clean, '-')); $clean = strtolower(trim($clean, '-'));
$clean = preg_replace("/[\/_|+ -]+/", $delimiter, $clean); $clean = preg_replace("/[\/_|+ -]+/", $delimiter, $clean);


return $clean; return $clean;
} }


function generateFileName($name) { function generateFileName($name) {
$i = 0; $i = 0;
Expand Down Expand Up @@ -78,8 +79,6 @@ function mapGoalFields($userURI, $varJS) {
$goalPredicate = $_POST[$elem['goalType']]; $goalPredicate = $_POST[$elem['goalType']];
$propRes = new resource($goalPredicate); $propRes = new resource($goalPredicate);
$goalURI = $_POST[$elem['field']]; $goalURI = $_POST[$elem['field']];
$goalURI = str_replace('(', "%28", $goalURI);
$goalURI = str_replace(')', "%29", $goalURI);
if ($goalURI != ''){ if ($goalURI != ''){
if (startsWith($goalURI, "http://")) { if (startsWith($goalURI, "http://")) {
$stmt = new Statement($userRes, $propRes, new resource($goalURI)); $stmt = new Statement($userRes, $propRes, new resource($goalURI));
Expand All @@ -102,8 +101,6 @@ function mapSingleFormField($userURI, $varJS, $property, $prepend, $isURI) {
$obj = $_POST[$varJS]; $obj = $_POST[$varJS];


$objURI = $prepend . $obj; $objURI = $prepend . $obj;
$objURI = str_replace('(', "%28", $objURI);
$objURI = str_replace(')', "%29", $objURI);
if ($objURI != '') { if ($objURI != '') {
if ($isURI){ if ($isURI){
if (startsWith($objURI, "http://") || startsWith($objURI, "https://")) { if (startsWith($objURI, "http://") || startsWith($objURI, "https://")) {
Expand All @@ -129,11 +126,7 @@ function mapSerializedFormField($userURI, $varJS, $property) {
$propRes = new resource($property); $propRes = new resource($property);


foreach ($json as $elem) { foreach ($json as $elem) {
// Reason for this nonsense:
// http://www.proxml.be/users/paul/weblog/e67ab/Some_SPARQL_extension_function_tricks.html
$objURI = $_POST[$elem['field']]; $objURI = $_POST[$elem['field']];
$objURI = str_replace('(', "%28", $objURI);
$objURI = str_replace(')', "%29", $objURI);


if ($objURI != ''){ if ($objURI != ''){
if (startsWith($objURI, "http://")) { if (startsWith($objURI, "http://")) {
Expand Down
17 changes: 9 additions & 8 deletions publish-me.php
Expand Up @@ -46,17 +46,18 @@
</head> </head>


<?php <?php
error_reporting(E_ALL);


$domain = "http://serena.macs.hw.ac.uk/serena/discover-me-semantically/"; include("readConf.php");
error_reporting(E_ALL);
$domain=getDomain("config.ini");


function saveToFile($rawRDF, $fileName) { function saveToFile($rawRDF, $fileName) {


$myFile = "rdf/" . $fileName; $myFile = "rdf/" . $fileName;
$fh = fopen($myFile, 'w') or die("can't open file"); $fh = fopen($myFile, 'w') or die("can't open file");
fwrite($fh, urldecode($rawRDF)); fwrite($fh, urldecode($rawRDF));
fclose($fh); fclose($fh);
} }


saveToFile($_POST['rawRDF'], $_POST['fileName']); saveToFile($_POST['rawRDF'], $_POST['fileName']);


Expand Down
20 changes: 20 additions & 0 deletions readConf.php
@@ -0,0 +1,20 @@
<?php

function getDomain($file){
$domain = "";

if (file_exists($file) && is_readable($file))
{
$settings=parse_ini_file($file);
$domain=$settings["domain"];

}
else
{
// If the configuration file does not exist or is not readable, DIE php DIE!
die("Sorry, the $file file doesnt seem to exist or is not readable!");
}
return $domain;
}

?>
4 changes: 3 additions & 1 deletion remove-me.php
Expand Up @@ -47,8 +47,10 @@


<?php <?php


include("readConf.php");

error_reporting(E_ALL); error_reporting(E_ALL);
$domain="http://serena.macs.hw.ac.uk/serena/discover-me-semantically/"; $domain=getDomain("config.ini");


function fromURI($uri){ function fromURI($uri){
global $domain; global $domain;
Expand Down

0 comments on commit 1987610

Please sign in to comment.