Removed not used libraries and views

This commit is contained in:
Paolo
2019-04-26 11:38:28 +02:00
parent f0fe4bc239
commit 3a692f8a5e
8 changed files with 0 additions and 1355 deletions
-531
View File
@@ -1,531 +0,0 @@
<?php
if (! defined('BASEPATH')) exit('No direct script access allowed');
/**
* Format class
* Help convert between various formats such as XML, JSON, CSV, etc.
*
* @author Phil Sturgeon, Chris Kacerguis, @softwarespot
* @license http://www.dbad-license.org/
*/
class Format {
/**
* Array output format
*/
const ARRAY_FORMAT = 'array';
/**
* Comma Separated Value (CSV) output format
*/
const CSV_FORMAT = 'csv';
/**
* Json output format
*/
const JSON_FORMAT = 'json';
/**
* HTML output format
*/
const HTML_FORMAT = 'html';
/**
* PHP output format
*/
const PHP_FORMAT = 'php';
/**
* Serialized output format
*/
const SERIALIZED_FORMAT = 'serialized';
/**
* XML output format
*/
const XML_FORMAT = 'xml';
/**
* Default format of this class
*/
const DEFAULT_FORMAT = self::JSON_FORMAT; // Couldn't be DEFAULT, as this is a keyword
/**
* CodeIgniter instance
*
* @var object
*/
private $_CI;
/**
* Data to parse
*
* @var mixed
*/
protected $_data = [];
/**
* Type to convert from
*
* @var string
*/
protected $_from_type = NULL;
/**
* DO NOT CALL THIS DIRECTLY, USE factory()
*
* @param NULL $data
* @param NULL $from_type
* @throws Exception
*/
public function __construct($data = NULL, $from_type = NULL)
{
// Get the CodeIgniter reference
$this->_CI = &get_instance();
// Load the inflector helper
$this->_CI->load->helper('inflector');
// If the provided data is already formatted we should probably convert it to an array
if ($from_type !== NULL)
{
if (method_exists($this, '_from_' . $from_type))
{
$data = call_user_func([$this, '_from_' . $from_type], $data);
}
else
{
throw new Exception('Format class does not support conversion from "' . $from_type . '".');
}
}
// Set the member variable to the data passed
$this->_data = $data;
}
/**
* Create an instance of the format class
* e.g: echo $this->format->factory(['foo' => 'bar'])->to_csv();
*
* @param mixed $data Data to convert/parse
* @param string $from_type Type to convert from e.g. json, csv, html
*
* @return object Instance of the format class
*/
public function factory($data, $from_type = NULL)
{
// $class = __CLASS__;
// return new $class();
return new static($data, $from_type);
}
// FORMATTING OUTPUT ---------------------------------------------------------
/**
* Format data as an array
*
* @param mixed|NULL $data Optional data to pass, so as to override the data passed
* to the constructor
* @return array Data parsed as an array; otherwise, an empty array
*/
public function to_array($data = NULL)
{
// If no data is passed as a parameter, then use the data passed
// via the constructor
if ($data === NULL && func_num_args() === 0)
{
$data = $this->_data;
}
// Cast as an array if not already
if (is_array($data) === FALSE)
{
$data = (array) $data;
}
$array = [];
foreach ((array) $data as $key => $value)
{
if (is_object($value) === TRUE || is_array($value) === TRUE)
{
$array[$key] = $this->to_array($value);
}
else
{
$array[$key] = $value;
}
}
return $array;
}
/**
* Format data as XML
*
* @param mixed|NULL $data Optional data to pass, so as to override the data passed
* to the constructor
* @param NULL $structure
* @param string $basenode
* @return mixed
*/
public function to_xml($data = NULL, $structure = NULL, $basenode = 'xml')
{
if ($data === NULL && func_num_args() === 0)
{
$data = $this->_data;
}
// turn off compatibility mode as simple xml throws a wobbly if you don't.
if (ini_get('zend.ze1_compatibility_mode') == 1)
{
ini_set('zend.ze1_compatibility_mode', 0);
}
if ($structure === NULL)
{
$structure = simplexml_load_string("<?xml version='1.0' encoding='utf-8'?><$basenode />");
}
// Force it to be something useful
if (is_array($data) === FALSE && is_object($data) === FALSE)
{
$data = (array) $data;
}
foreach ($data as $key => $value)
{
//change false/true to 0/1
if (is_bool($value))
{
$value = (int) $value;
}
// no numeric keys in our xml please!
if (is_numeric($key))
{
// make string key...
$key = (singular($basenode) != $basenode) ? singular($basenode) : 'item';
}
// replace anything not alpha numeric
$key = preg_replace('/[^a-z_\-0-9]/i', '', $key);
if ($key === '_attributes' && (is_array($value) || is_object($value)))
{
$attributes = $value;
if (is_object($attributes))
{
$attributes = get_object_vars($attributes);
}
foreach ($attributes as $attribute_name => $attribute_value)
{
$structure->addAttribute($attribute_name, $attribute_value);
}
}
// if there is another array found recursively call this function
elseif (is_array($value) || is_object($value))
{
$node = $structure->addChild($key);
// recursive call.
$this->to_xml($value, $node, $key);
}
else
{
// add single node.
$value = htmlspecialchars(html_entity_decode($value, ENT_QUOTES, 'UTF-8'), ENT_QUOTES, 'UTF-8');
$structure->addChild($key, $value);
}
}
return $structure->asXML();
}
/**
* Format data as HTML
*
* @param mixed|NULL $data Optional data to pass, so as to override the data passed
* to the constructor
* @return mixed
*/
public function to_html($data = NULL)
{
// If no data is passed as a parameter, then use the data passed
// via the constructor
if ($data === NULL && func_num_args() === 0)
{
$data = $this->_data;
}
// Cast as an array if not already
if (is_array($data) === FALSE)
{
$data = (array) $data;
}
// Check if it's a multi-dimensional array
if (isset($data[0]) && count($data) !== count($data, COUNT_RECURSIVE))
{
// Multi-dimensional array
$headings = array_keys($data[0]);
}
else
{
// Single array
$headings = array_keys($data);
$data = [$data];
}
// Load the table library
$this->_CI->load->library('table');
$this->_CI->table->set_heading($headings);
foreach ($data as $row)
{
// Suppressing the "array to string conversion" notice
// Keep the "evil" @ here
$row = @array_map('strval', $row);
$this->_CI->table->add_row($row);
}
return $this->_CI->table->generate();
}
/**
* @link http://www.metashock.de/2014/02/create-csv-file-in-memory-php/
* @param mixed|NULL $data Optional data to pass, so as to override the data passed
* to the constructor
* @param string $delimiter The optional delimiter parameter sets the field
* delimiter (one character only). NULL will use the default value (,)
* @param string $enclosure The optional enclosure parameter sets the field
* enclosure (one character only). NULL will use the default value (")
* @return string A csv string
*/
public function to_csv($data = NULL, $delimiter = ',', $enclosure = '"')
{
// Use a threshold of 1 MB (1024 * 1024)
$handle = fopen('php://temp/maxmemory:1048576', 'w');
if ($handle === FALSE)
{
return NULL;
}
// If no data is passed as a parameter, then use the data passed
// via the constructor
if ($data === NULL && func_num_args() === 0)
{
$data = $this->_data;
}
// If NULL, then set as the default delimiter
if ($delimiter === NULL)
{
$delimiter = ',';
}
// If NULL, then set as the default enclosure
if ($enclosure === NULL)
{
$enclosure = '"';
}
// Cast as an array if not already
if (is_array($data) === FALSE)
{
$data = (array) $data;
}
// Check if it's a multi-dimensional array
if (isset($data[0]) && count($data) !== count($data, COUNT_RECURSIVE))
{
// Multi-dimensional array
$headings = array_keys($data[0]);
}
else
{
// Single array
$headings = array_keys($data);
$data = [$data];
}
// Apply the headings
fputcsv($handle, $headings, $delimiter, $enclosure);
foreach ($data as $record)
{
// If the record is not an array, then break. This is because the 2nd param of
// fputcsv() should be an array
if (is_array($record) === FALSE)
{
break;
}
// Suppressing the "array to string conversion" notice.
// Keep the "evil" @ here.
$record = @ array_map('strval', $record);
// Returns the length of the string written or FALSE
fputcsv($handle, $record, $delimiter, $enclosure);
}
// Reset the file pointer
rewind($handle);
// Retrieve the csv contents
$csv = stream_get_contents($handle);
// Close the handle
fclose($handle);
return $csv;
}
/**
* Encode data as json
*
* @param mixed|NULL $data Optional data to pass, so as to override the data passed
* to the constructor
* @return string Json representation of a value
*/
public function to_json($data = NULL)
{
// If no data is passed as a parameter, then use the data passed
// via the constructor
if ($data === NULL && func_num_args() === 0)
{
$data = $this->_data;
}
// Get the callback parameter (if set)
$callback = $this->_CI->input->get('callback');
if (empty($callback) === TRUE)
{
return json_encode($data);
}
// We only honour a jsonp callback which are valid javascript identifiers
elseif (preg_match('/^[a-z_\$][a-z0-9\$_]*(\.[a-z_\$][a-z0-9\$_]*)*$/i', $callback))
{
// Return the data as encoded json with a callback
return $callback . '(' . json_encode($data) . ');';
}
// An invalid jsonp callback function provided.
// Though I don't believe this should be hardcoded here
$data['warning'] = 'INVALID JSONP CALLBACK: ' . $callback;
return json_encode($data);
}
/**
* Encode data as a serialized array
*
* @param mixed|NULL $data Optional data to pass, so as to override the data passed
* to the constructor
* @return string Serialized data
*/
public function to_serialized($data = NULL)
{
// If no data is passed as a parameter, then use the data passed
// via the constructor
if ($data === NULL && func_num_args() === 0)
{
$data = $this->_data;
}
return serialize($data);
}
/**
* Format data using a PHP structure
*
* @param mixed|NULL $data Optional data to pass, so as to override the data passed
* to the constructor
* @return mixed String representation of a variable
*/
public function to_php($data = NULL)
{
// If no data is passed as a parameter, then use the data passed
// via the constructor
if ($data === NULL && func_num_args() === 0)
{
$data = $this->_data;
}
return var_export($data, TRUE);
}
// INTERNAL FUNCTIONS
/**
* @param $data XML string
* @return SimpleXMLElement XML element object; otherwise, empty array
*/
protected function _from_xml($data)
{
return $data ? (array) simplexml_load_string($data, 'SimpleXMLElement', LIBXML_NOCDATA) : [];
}
/**
* @param string $data CSV string
* @param string $delimiter The optional delimiter parameter sets the field
* delimiter (one character only). NULL will use the default value (,)
* @param string $enclosure The optional enclosure parameter sets the field
* enclosure (one character only). NULL will use the default value (")
* @return array A multi-dimensional array with the outer array being the number of rows
* and the inner arrays the individual fields
*/
protected function _from_csv($data, $delimiter = ',', $enclosure = '"')
{
// If NULL, then set as the default delimiter
if ($delimiter === NULL)
{
$delimiter = ',';
}
// If NULL, then set as the default enclosure
if ($enclosure === NULL)
{
$enclosure = '"';
}
return str_getcsv($data, $delimiter, $enclosure);
}
/**
* @param $data Encoded json string
* @return mixed Decoded json string with leading and trailing whitespace removed
*/
protected function _from_json($data)
{
return json_decode(trim($data));
}
/**
* @param string Data to unserialized
* @return mixed Unserialized data
*/
protected function _from_serialize($data)
{
return unserialize(trim($data));
}
/**
* @param $data Data to trim leading and trailing whitespace
* @return string Data with leading and trailing whitespace removed
*/
protected function _from_php($data)
{
return trim($data);
}
}
-54
View File
@@ -1,54 +0,0 @@
<style type="text/css">
.table tr th {
text-align:center;
background: -moz-linear-gradient(top, #FAFAFA 0%, #E9E9E9 100%);
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%, #FAFAFA), color-stop(100%, #E9E9E9));background: -webkit-linear-gradient(top, #FAFAFA 0%, #E9E9E9 100%);
background: -o-linear-gradient(top, #FAFAFA 0%, #E9E9E9 100%);
background: -ms-linear-gradient(top, #FAFAFA 0%, #E9E9E9 100%);
background: linear-gradient(top, #FAFAFA 0%, #E9E9E9 100%);
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr = '#FAFAFA', endColorstr = '#E9E9E9');-ms-filter: "progid:DXImageTransform.Microsoft.gradient(startColorstr='#FAFAFA', endColorstr='#E9E9E9')";
border: 1px solid #D5D5D5;
}
</style>
<div class="bootstrap-widget-header">
<i class="icon-home icon-white"></i><h3></h3>
</div>
<div class="bootstrap-widget-content">
<div class="container">
<div class="pull-left">
</div>
</div>
<table class="table table-condensed table-hover table-bordered table-striped">
<thead>
<tr>
<th class="span4">Name</th>
<th class="span4">Give Name</th>
<th class="span4">Family Name</th>
</tr>
</thead>
<tbody>
<?php
$foaf = EasyRdf_Graph::newAndLoad('http://njh.me/foaf.rdf');
$me = $foaf->primaryTopic();
?>
<tr>
<td> <?php echo $me->get('foaf:name') ?></td>
<td> <?= $me->get('foaf:givenName') ?> </td>
<td> <?= $me->get('foaf:familyName') ?></td>
</tr>
</tbody>
</table>
</div>
-74
View File
@@ -1,74 +0,0 @@
<style type="text/css">
.table tr th {
text-align:center;
background: -moz-linear-gradient(top, #FAFAFA 0%, #E9E9E9 100%);
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%, #FAFAFA), color-stop(100%, #E9E9E9));background: -webkit-linear-gradient(top, #FAFAFA 0%, #E9E9E9 100%);
background: -o-linear-gradient(top, #FAFAFA 0%, #E9E9E9 100%);
background: -ms-linear-gradient(top, #FAFAFA 0%, #E9E9E9 100%);
background: linear-gradient(top, #FAFAFA 0%, #E9E9E9 100%);
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr = '#FAFAFA', endColorstr = '#E9E9E9');-ms-filter: "progid:DXImageTransform.Microsoft.gradient(startColorstr='#FAFAFA', endColorstr='#E9E9E9')";
border: 1px solid #D5D5D5;
}
</style>
<div class="bootstrap-widget-header">
<i class="icon-home icon-white"></i><h3></h3>
</div>
<div class="bootstrap-widget-content">
<div class="container">
<div class="pull-left">
</div>
</div>
<table class="table table-condensed table-hover table-bordered table-striped">
<thead>
<tr>
<th class="span4">Label</th>
<th class="span4">Country</th>
</tr>
</thead>
<tbody>
<?php
EasyRdf_Namespace::set('category', 'http://dbpedia.org/resource/Category:');
EasyRdf_Namespace::set('dbpedia', 'http://dbpedia.org/resource/');
EasyRdf_Namespace::set('dbo', 'http://dbpedia.org/ontology/');
EasyRdf_Namespace::set('dbp', 'http://dbpedia.org/property/');
$sparql = new EasyRdf_Sparql_Client('http://dbpedia.org/sparql');
$result = $sparql->query(
'SELECT * WHERE {'.
' ?country rdf:type dbo:Country .'.
' ?country rdfs:label ?label .'.
' ?country dc:subject category:Member_states_of_the_United_Nations .'.
' FILTER ( lang(?label) = "en" )'.
'} ORDER BY ?label'
);
?>
Total number of countries: <?= $result->numRows() ?>
<?php foreach ($result as $row ): ?>
<tr>
<td> <a href="http://dbpedia.org/resource/<?php echo $row->label ?>"><?php echo $row->label ?></a></td>
<td><a href="http://dbpedia.org/resource/"> <?php echo $row->country ?></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
-112
View File
@@ -1,112 +0,0 @@
<div class="bootstrap-widget-header">
<i class="icon-home icon-white"></i><h3>Converter</h3>
</div>
<div class="bootstrap-widget-content">
<div class="container">
<div class="pull-left">
</div>
</div>
<?php
/**
* Convert RDF from one format to another
*
* The source RDF data can either be fetched from the web
* or typed into the Input box.
*
* The first thing that this script does is make a list the names of the
* supported input and output formats. These options are then
* displayed on the HTML form.
*
* The input data is loaded or parsed into an EasyRdf_Graph.
* That graph is than outputted again in the desired output format.
*
* @package EasyRdf
* @copyright Copyright (c) 2009-2013 Nicholas J Humfrey
* @license http://unlicense.org/
*/
// set_include_path(get_include_path() . PATH_SEPARATOR . '../lib/');
echo $this->load->view('rdf/html_tag_helpers');
$input_format_options = array('Guess' => 'guess');
$output_format_options = array();
foreach (EasyRdf_Format::getFormats() as $format) {
if ($format->getSerialiserClass()) {
$output_format_options[$format->getLabel()] = $format->getName();
}
if ($format->getParserClass()) {
$input_format_options[$format->getLabel()] = $format->getName();
}
}
// Stupid PHP :(
if (get_magic_quotes_gpc() and isset($_REQUEST['data'])) {
$_REQUEST['data'] = stripslashes($_REQUEST['data']);
}
// Default to Guess input and Turtle output
if (!isset($_REQUEST['output_format'])) {
$_REQUEST['output_format'] = 'turtle';
}
if (!isset($_REQUEST['input_format'])) {
$_REQUEST['input_format'] = 'guess';
}
// Display the form, if raw option isn't set
if (!isset($_REQUEST['raw'])) {
print "<html>\n";
print "<head><title>EasyRdf Converter</title></head>\n";
print "<body>\n";
print "<h1>EasyRdf Converter</h1>\n";
print "<div style='margin: 10px'>\n";
print form_tag();
print label_tag('data', 'Input Data: ').'<br />'.text_area_tag('data', '', array('cols'=>30, 'rows'=>10)) . "<br />\n";
print label_tag('uri', 'or Uri: ').text_field_tag('uri', 'http://www.dajobe.org/foaf.rdf', array('size'=>80)) . "<br />\n";
print label_tag('input_format', 'Input Format: ').select_tag('input_format', $input_format_options) . "<br />\n";
print label_tag('output_format', 'Output Format: ').select_tag('output_format', $output_format_options) . "<br />\n";
print label_tag('raw', 'Raw Output: ').check_box_tag('raw') . "<br />\n";
print reset_tag() . submit_tag();
print form_end_tag();
print "</div>\n";
}
if (isset($_REQUEST['uri']) or isset($_REQUEST['data'])) {
// Parse the input
$graph = new EasyRdf_Graph($_REQUEST['uri']);
if (empty($_REQUEST['data'])) {
$graph->load($_REQUEST['uri'], $_REQUEST['input_format']);
} else {
$graph->parse($_REQUEST['data'], $_REQUEST['input_format'], $_REQUEST['uri']);
}
// Lookup the output format
$format = EasyRdf_Format::getFormat($_REQUEST['output_format']);
// Serialise to the new output format
$output = $graph->serialise($format);
if (!is_scalar($output)) {
$output = var_export($output, true);
}
// Send the output back to the client
if (isset($_REQUEST['raw'])) {
header('Content-Type: '.$format->getDefaultMimeType());
print $output;
} else {
print '<pre>'.htmlspecialchars($output).'</pre>';
}
}
if (!isset($_REQUEST['raw'])) {
print "</body>\n";
print "</html>\n";
}
?>
</div>
-124
View File
@@ -1,124 +0,0 @@
<div class="bootstrap-widget-header">
<i class="icon-home icon-white"></i><h3></h3>
</div>
<div class="bootstrap-widget-content">
<div class="container">
<div class="pull-left">
</div>
</div>
<form name="my-form" id="my-form" action="#" method="post" enctype="multipart/form-data">
<div class="control-group">
<label class="control-label" for="kategori">FOAF</label>
<div class="controls">
<input type="text" id="uri" name="uri" class="span3" value="http://njh.me/foaf.rdf">
</div>
</div>
<div class="control-group">
<div class="controls">
<button type="submit" name="simpan" class="btn btn-info btn-small"><i class="icon-ok-circle"></i> Simpan</button>
</div>
</div>
</form>
<h3>FOAF me</h3>
<?php
echo $this->load->view('rdf/html_tag_helpers');
if (isset($_REQUEST['uri'])): ?>
<?php $graph = EasyRdf_Graph::newAndLoad($_REQUEST['uri']); ?>
<?php if ($graph->type() == 'foaf:PersonalProfileDocument'): ?>
<?php echo $person = $graph->primaryTopic(); ?>
<?php elseif ($graph->type() == 'foaf:Person'): ?>
<?php echo $person = $graph->resource(); ?>
<?php endif; ?>
<?php endif; ?>
<!-- Start -->
<?php if (isset($person)): ?>
<table class="table table-condensed table-hover table-bordered table-striped">
<thead>
<tr>
<th class="span4">Name</th>
<th class="span4">Homepage</th>
</tr>
</thead>
<tbody>
<tr>
<td><?= $person->get('foaf:name') ?> </td>
<td><a href="<?= $person->get('foaf:homepage') ?>"> <?= $person->get('foaf:homepage') ?></td>
</tr>
</tbody>
</table>
<!-- NEw Format -->
<h3>Known Person</h3>
<?php foreach ($person->all('foaf:knows') as $friend) {
$label = $friend->label();
if (!$label) {
$label = $friend->getUri();
}
?>
<table class="table table-condensed table-hover table-bordered table-striped">
<tbody>
<tr>
<?php if ($friend->isBNode()): ?>
<td><?= $label ?></td>
<?php else: ?>
<?php echo "<li>".link_to_self($label, 'uri='.urlencode($friend))."</li>"; ?>
</td>
<?php endif; ?>
</tr>
</tbody>
</table>
<?php
} ?>
</div>
<!--endif paling atas-->
<?php endif; ?>
-121
View File
@@ -1,121 +0,0 @@
<div class="bootstrap-widget-header">
<i class="icon-home icon-white"></i><h3>EasyRdf FOAF Maker Example</h3>
</div>
<div class="bootstrap-widget-content">
<div class="container">
<div class="pull-left">
</div>
</div>
<?php
/**
* Construct a FOAF document with a choice of serialisations
*
* This example is similar in concept to Leigh Dodds' FOAF-a-Matic.
* The fields in the HTML form are inserted into an empty
* EasyRdf_Graph and then serialised to the chosen format.
*
* @package EasyRdf
* @copyright Copyright (c) 2009-2013 Nicholas J Humfrey
* @license http://unlicense.org/
*/
// set_include_path(get_include_path() . PATH_SEPARATOR . '../lib/');
echo $this->load->view('rdf/html_tag_helpers');
if (isset($_REQUEST['enable_arc']) && $_REQUEST['enable_arc']) {
require_once "EasyRdf/Serialiser/Arc.php";
EasyRdf_Format::registerSerialiser('ntriples', 'EasyRdf_Serialiser_Arc');
EasyRdf_Format::registerSerialiser('posh', 'EasyRdf_Serialiser_Arc');
EasyRdf_Format::registerSerialiser('rdfxml', 'EasyRdf_Serialiser_Arc');
EasyRdf_Format::registerSerialiser('turtle', 'EasyRdf_Serialiser_Arc');
}
if (isset($_REQUEST['enable_rapper']) && $_REQUEST['enable_rapper']) {
require_once "EasyRdf/Serialiser/Rapper.php";
EasyRdf_Format::registerSerialiser('dot', 'EasyRdf_Serialiser_Rapper');
EasyRdf_Format::registerSerialiser('rdfxml', 'EasyRdf_Serialiser_Rapper');
EasyRdf_Format::registerSerialiser('turtle', 'EasyRdf_Serialiser_Rapper');
}
$format_options = array();
foreach (EasyRdf_Format::getFormats() as $format) {
if ($format->getSerialiserClass()) {
$format_options[$format->getLabel()] = $format->getName();
}
}
?>
<h1></h1>
<?= form_tag(null, array('method' => 'POST')) ?>
<h2>Your Identifier</h2>
<?= labeled_text_field_tag('uri', 'http://www.example.com/joe#me', array('size'=>40)) ?><br />
<h2>Your details</h2>
<?= labeled_text_field_tag('title', 'Mr', array('size'=>8)) ?><br />
<?= labeled_text_field_tag('given_name', 'Joseph') ?><br />
<?= labeled_text_field_tag('family_name', 'Bloggs') ?><br />
<?= labeled_text_field_tag('nickname', 'Joe') ?><br />
<?= labeled_text_field_tag('email', 'joe@example.com') ?><br />
<?= labeled_text_field_tag('homepage', 'http://www.example.com/', array('size'=>40)) ?><br />
<h2>People you know</h2>
<?= labeled_text_field_tag('person_1', 'http://www.example.com/dave#me', array('size'=>40)) ?><br />
<?= labeled_text_field_tag('person_2', '', array('size'=>40)) ?><br />
<?= labeled_text_field_tag('person_3', '', array('size'=>40)) ?><br />
<?= labeled_text_field_tag('person_4', '', array('size'=>40)) ?><br />
<h2>Output</h2>
Enable Arc 2? <?= check_box_tag('enable_arc') ?><br />
Enable Rapper? <?= check_box_tag('enable_rapper') ?><br />
<?= label_tag('format').select_tag('format', $format_options, 'rdfxml') ?><br />
<?= submit_tag() ?>
<?= form_end_tag() ?>
<?php
if (isset($_REQUEST['uri'])) {
$graph = new EasyRdf_Graph();
# 1st Technique
$me = $graph->resource($_REQUEST['uri'], 'foaf:Person');
$me->set('foaf:name', $_REQUEST['title'].' '.$_REQUEST['given_name'].' '.$_REQUEST['family_name']);
if ($_REQUEST['email']) {
$email = $graph->resource("mailto:".$_REQUEST['email']);
$me->add('foaf:mbox', $email);
}
if ($_REQUEST['homepage']) {
$homepage = $graph->resource($_REQUEST['homepage']);
$me->add('foaf:homepage', $homepage);
}
# 2nd Technique
$graph->addLiteral($_REQUEST['uri'], 'foaf:title', $_REQUEST['title']);
$graph->addLiteral($_REQUEST['uri'], 'foaf:givenname', $_REQUEST['given_name']);
$graph->addLiteral($_REQUEST['uri'], 'foaf:family_name', $_REQUEST['family_name']);
$graph->addLiteral($_REQUEST['uri'], 'foaf:nick', $_REQUEST['nickname']);
# Add friends
for ($i=1; $i<=4; $i++) {
if ($_REQUEST["person_$i"]) {
$person = $graph->resource($_REQUEST["person_$i"]);
$graph->add($me, 'foaf:knows', $person);
}
}
# Finally output the graph
$data = $graph->serialise($_REQUEST['format']);
if (!is_scalar($data)) {
$data = var_export($data, true);
}
print "<pre>".htmlspecialchars($data)."</pre>";
}
?>
</div>
-121
View File
@@ -1,121 +0,0 @@
<div class="bootstrap-widget-header">
<i class="icon-home icon-white"></i><h3>EasyRdf FOAF Maker Example</h3>
</div>
<div class="bootstrap-widget-content">
<div class="container">
<div class="pull-left">
</div>
</div>
<?php
/**
* Construct a FOAF document with a choice of serialisations
*
* This example is similar in concept to Leigh Dodds' FOAF-a-Matic.
* The fields in the HTML form are inserted into an empty
* EasyRdf_Graph and then serialised to the chosen format.
*
* @package EasyRdf
* @copyright Copyright (c) 2009-2013 Nicholas J Humfrey
* @license http://unlicense.org/
*/
set_include_path(get_include_path() . PATH_SEPARATOR . '../lib/');
echo $this->load->view('rdf/html_tag_helpers');
if (isset($_REQUEST['enable_arc']) && $_REQUEST['enable_arc']) {
require_once "EasyRdf/Serialiser/Arc.php";
EasyRdf_Format::registerSerialiser('ntriples', 'EasyRdf_Serialiser_Arc');
EasyRdf_Format::registerSerialiser('posh', 'EasyRdf_Serialiser_Arc');
EasyRdf_Format::registerSerialiser('rdfxml', 'EasyRdf_Serialiser_Arc');
EasyRdf_Format::registerSerialiser('turtle', 'EasyRdf_Serialiser_Arc');
}
if (isset($_REQUEST['enable_rapper']) && $_REQUEST['enable_rapper']) {
require_once "EasyRdf/Serialiser/Rapper.php";
EasyRdf_Format::registerSerialiser('dot', 'EasyRdf_Serialiser_Rapper');
EasyRdf_Format::registerSerialiser('rdfxml', 'EasyRdf_Serialiser_Rapper');
EasyRdf_Format::registerSerialiser('turtle', 'EasyRdf_Serialiser_Rapper');
}
$format_options = array();
foreach (EasyRdf_Format::getFormats() as $format) {
if ($format->getSerialiserClass()) {
$format_options[$format->getLabel()] = $format->getName();
}
}
?>
<h1></h1>
<?= form_tag(null, array('method' => 'POST')) ?>
<h2>Your Identifier</h2>
<?= labeled_text_field_tag('uri', 'http://www.example.com/joe#me', array('size'=>40)) ?><br />
<h2>Your details</h2>
<?= labeled_text_field_tag('title', 'Mr', array('size'=>8)) ?><br />
<?= labeled_text_field_tag('given_name', 'Joseph') ?><br />
<?= labeled_text_field_tag('family_name', 'Bloggs') ?><br />
<?= labeled_text_field_tag('nickname', 'Joe') ?><br />
<?= labeled_text_field_tag('email', 'joe@example.com') ?><br />
<?= labeled_text_field_tag('homepage', 'http://www.example.com/', array('size'=>40)) ?><br />
<h2>People you know</h2>
<?= labeled_text_field_tag('person_1', 'http://www.example.com/dave#me', array('size'=>40)) ?><br />
<?= labeled_text_field_tag('person_2', '', array('size'=>40)) ?><br />
<?= labeled_text_field_tag('person_3', '', array('size'=>40)) ?><br />
<?= labeled_text_field_tag('person_4', '', array('size'=>40)) ?><br />
<h2>Output</h2>
Enable Arc 2? <?= check_box_tag('enable_arc') ?><br />
Enable Rapper? <?= check_box_tag('enable_rapper') ?><br />
<?= label_tag('format').select_tag('format', $format_options, 'rdfxml') ?><br />
<?= submit_tag() ?>
<?= form_end_tag() ?>
<?php
if (isset($_REQUEST['uri'])) {
$graph = new EasyRdf_Graph();
# 1st Technique
$me = $graph->resource($_REQUEST['uri'], 'foaf:Person');
$me->set('foaf:name', $_REQUEST['title'].' '.$_REQUEST['given_name'].' '.$_REQUEST['family_name']);
if ($_REQUEST['email']) {
$email = $graph->resource("mailto:".$_REQUEST['email']);
$me->add('foaf:mbox', $email);
}
if ($_REQUEST['homepage']) {
$homepage = $graph->resource($_REQUEST['homepage']);
$me->add('foaf:homepage', $homepage);
}
# 2nd Technique
$graph->addLiteral($_REQUEST['uri'], 'foaf:title', $_REQUEST['title']);
$graph->addLiteral($_REQUEST['uri'], 'foaf:givenname', $_REQUEST['given_name']);
$graph->addLiteral($_REQUEST['uri'], 'foaf:family_name', $_REQUEST['family_name']);
$graph->addLiteral($_REQUEST['uri'], 'foaf:nick', $_REQUEST['nickname']);
# Add friends
for ($i=1; $i<=4; $i++) {
if ($_REQUEST["person_$i"]) {
$person = $graph->resource($_REQUEST["person_$i"]);
$graph->add($me, 'foaf:knows', $person);
}
}
# Finally output the graph
$data = $graph->serialise($_REQUEST['format']);
if (!is_scalar($data)) {
$data = var_export($data, true);
}
print "<pre>".htmlspecialchars($data)."</pre>";
}
?>
</div>
-218
View File
@@ -1,218 +0,0 @@
<?php
/**
* Rails Style html tag helpers
*
* These are used by the other examples to make the code
* more concise and simpler to read.
*
* @copyright Copyright (c) 2009-2013 Nicholas J Humfrey
* @license http://unlicense.org/
*/
/* Examples:
echo content_tag('p','Paragraph Tag', array('class'=>'foo'));
echo tag('br');
echo link_to('Hyperlink', 'http://www.example.com/?a=1&b=2');
echo tag('br');
echo form_tag();
echo label_tag('first_name').text_field_tag('first_name', 'Joe').tag('br');
echo label_tag('password').password_field_tag().tag('br');
echo label_tag('radio1_value1', 'Radio 1').radio_button_tag('radio1', 'value1').tag('br');
echo label_tag('radio1_value2', 'Radio 2').radio_button_tag('radio1', 'value2', true).tag('br');
echo label_tag('radio1_value3', 'Radio 3').radio_button_tag('radio1', 'value3').tag('br');
echo label_tag('check1', 'Check 1').check_box_tag('check1', 'value1').tag('br');
echo label_tag('check2', 'Check 2').check_box_tag('check2', 'value2', true).tag('br');
echo label_tag('check3', 'Check 3').check_box_tag('check3', 'value3').tag('br');
$options = array('Label 1' => 'value1', 'Label 2' => 'value2', 'Label 3' => 'value3');
echo label_tag('select1', 'Select Something:');
echo select_tag('select1', $options, 'value2').tag('br');
echo label_tag('textarea1', 'Type Something:');
echo text_area_tag('textarea1', "Hello World!").tag('br');
echo submit_tag();
echo form_end_tag();
*/
function tag_options($options)
{
$html = "";
foreach ($options as $key => $value) {
if ($key and $value) {
$html .= " ".htmlspecialchars($key)."=\"".
htmlspecialchars($value)."\"";
}
}
return $html;
}
function tag($name, $options = array(), $open = false)
{
return "<$name".tag_options($options).($open ? ">" : " />");
}
function content_tag($name, $content = null, $options = array())
{
return "<$name".tag_options($options).">".
htmlspecialchars($content)."</$name>";
}
function link_to($text, $uri = null, $options = array())
{
if ($uri == null) $uri = $text;
$options = array_merge(array('href' => $uri), $options);
return content_tag('a', $text, $options);
}
function link_to_self($text, $query_string, $options = array())
{
return link_to($text, $_SERVER['PHP_SELF'].'?'.$query_string, $options);
}
function image_tag($src, $options = array())
{
$options = array_merge(array('src' => $src), $options);
return tag('img', $options);
}
function input_tag($type, $name, $value = null, $options = array())
{
$options = array_merge(
array(
'type' => $type,
'name' => $name,
'id' => $name,
'value' => $value
),
$options
);
return tag('input', $options);
}
function text_field_tag($name, $default = null, $options = array())
{
$value = isset($_REQUEST[$name]) ? $_REQUEST[$name] : $default;
return input_tag('text', $name, $value, $options);
}
function text_area_tag($name, $default = null, $options = array())
{
$content = isset($_REQUEST[$name]) ? $_REQUEST[$name] : $default;
$options = array_merge(
array(
'name' => $name,
'id' => $name,
'cols' => 60,
'rows' => 5
),
$options
);
return content_tag('textarea', $content, $options);
}
function hidden_field_tag($name, $default = null, $options = array())
{
$value = isset($_REQUEST[$name]) ? $_REQUEST[$name] : $default;
return input_tag('hidden', $name, $value, $options);
}
function password_field_tag($name = 'password', $default = null, $options = array())
{
$value = isset($_REQUEST[$name]) ? $_REQUEST[$name] : $default;
return input_tag('password', $name, $value, $options);
}
function radio_button_tag($name, $value, $default = false, $options = array())
{
if ((isset($_REQUEST[$name]) and $_REQUEST[$name] == $value) or
(!isset($_REQUEST[$name]) and $default))
{
$options = array_merge(array('checked' => 'checked'), $options);
}
$options = array_merge(array('id' => $name.'_'.$value), $options);
return input_tag('radio', $name, $value, $options);
}
function check_box_tag($name, $value = '1', $default = false, $options = array())
{
if ((isset($_REQUEST[$name]) and $_REQUEST[$name] == $value) or
(!isset($_REQUEST['submit']) and $default))
{
$options = array_merge(array('checked' => 'checked'),$options);
}
return input_tag('checkbox', $name, $value, $options);
}
function submit_tag($name = '', $value = 'Submit', $options = array())
{
return input_tag('submit', $name, $value, $options);
}
function reset_tag($name = '', $value = 'Reset', $options = array())
{
return input_tag('reset', $name, $value, $options);
}
function label_tag($name, $text = null, $options = array())
{
if ($text == null) {
$text = ucwords(str_replace('_', ' ', $name)).': ';
}
$options = array_merge(
array('for' => $name, 'id' => "label_for_$name"),
$options
);
return content_tag('label', $text, $options);
}
function labeled_text_field_tag($name, $default = null, $options = array())
{
return label_tag($name).text_field_tag($name, $default, $options);
}
function select_tag($name, $options, $default = null, $html_options = array())
{
$opts = '';
foreach ($options as $key => $value) {
$arr = array('value' => $value);
if ((isset($_REQUEST[$name]) and $_REQUEST[$name] == $value) or
(!isset($_REQUEST[$name]) and $default == $value))
{
$arr = array_merge(array('selected' => 'selected'),$arr);
}
$opts .= content_tag('option', $key, $arr);
}
$html_options = array_merge(
array('name' => $name, 'id' => $name),
$html_options
);
return "<select".tag_options($html_options).">$opts</select>";
}
function form_tag($uri = null, $options = array())
{
if ($uri == null) {
$uri = $_SERVER['PHP_SELF'];
}
$options = array_merge(
array('method' => 'get', 'action' => $uri),
$options
);
return tag('form', $options, true);
}
function form_end_tag()
{
return "</form>";
}