Permalink
Browse files

refactored domain field into separate config.ini file

  • Loading branch information...
1 parent d5401cf commit 1987610b95821b55614b0eb3505711efe8bfcd23 @robstewart57 committed Nov 23, 2012
Showing with 47 additions and 28 deletions.
  1. +3 −0 config.ini
  2. +12 −19 generateRDF.php
  3. +9 −8 publish-me.php
  4. +20 −0 readConf.php
  5. +3 −1 remove-me.php
View
3 config.ini
@@ -0,0 +1,3 @@
+; Setting the domain of this instance
+[general]
+domain=http://serena.macs.hw.ac.uk/serena/discover-me-semantically/
View
31 generateRDF.php
@@ -29,21 +29,22 @@
include( RDFAPI_INCLUDE_DIR . 'vocabulary/RDFS_C.php');
include( RDFAPI_INCLUDE_DIR . 'vocabulary/DC_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 = '-') {
- if (!empty($replace)) {
- $str = str_replace((array) $replace, ' ', $str);
- }
+function toAscii($str, $replace = array(), $delimiter = '-') {
+ if (!empty($replace)) {
+ $str = str_replace((array) $replace, ' ', $str);
+ }
- $clean = iconv('UTF-8', 'ASCII//TRANSLIT', $str);
- $clean = preg_replace("/[^a-zA-Z0-9\/_|+ -]/", '', $clean);
- $clean = strtolower(trim($clean, '-'));
- $clean = preg_replace("/[\/_|+ -]+/", $delimiter, $clean);
+ $clean = iconv('UTF-8', 'ASCII//TRANSLIT', $str);
+ $clean = preg_replace("/[^a-zA-Z0-9\/_|+ -]/", '', $clean);
+ $clean = strtolower(trim($clean, '-'));
+ $clean = preg_replace("/[\/_|+ -]+/", $delimiter, $clean);
- return $clean;
- }
+ return $clean;
+}
function generateFileName($name) {
$i = 0;
@@ -78,8 +79,6 @@ function mapGoalFields($userURI, $varJS) {
$goalPredicate = $_POST[$elem['goalType']];
$propRes = new resource($goalPredicate);
$goalURI = $_POST[$elem['field']];
- $goalURI = str_replace('(', "%28", $goalURI);
- $goalURI = str_replace(')', "%29", $goalURI);
if ($goalURI != ''){
if (startsWith($goalURI, "http://")) {
$stmt = new Statement($userRes, $propRes, new resource($goalURI));
@@ -102,8 +101,6 @@ function mapSingleFormField($userURI, $varJS, $property, $prepend, $isURI) {
$obj = $_POST[$varJS];
$objURI = $prepend . $obj;
- $objURI = str_replace('(', "%28", $objURI);
- $objURI = str_replace(')', "%29", $objURI);
if ($objURI != '') {
if ($isURI){
if (startsWith($objURI, "http://") || startsWith($objURI, "https://")) {
@@ -129,11 +126,7 @@ function mapSerializedFormField($userURI, $varJS, $property) {
$propRes = new resource($property);
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 = str_replace('(', "%28", $objURI);
- $objURI = str_replace(')', "%29", $objURI);
if ($objURI != ''){
if (startsWith($objURI, "http://")) {
View
17 publish-me.php
@@ -46,17 +46,18 @@
</head>
<?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;
- $fh = fopen($myFile, 'w') or die("can't open file");
- fwrite($fh, urldecode($rawRDF));
- fclose($fh);
- }
+ $myFile = "rdf/" . $fileName;
+ $fh = fopen($myFile, 'w') or die("can't open file");
+ fwrite($fh, urldecode($rawRDF));
+ fclose($fh);
+}
saveToFile($_POST['rawRDF'], $_POST['fileName']);
View
20 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;
+}
+
+?>
View
4 remove-me.php
@@ -47,8 +47,10 @@
<?php
+include("readConf.php");
+
error_reporting(E_ALL);
-$domain="http://serena.macs.hw.ac.uk/serena/discover-me-semantically/";
+$domain=getDomain("config.ini");
function fromURI($uri){
global $domain;

0 comments on commit 1987610

Please sign in to comment.