From 3a692f8a5ea16ae23f9b7735701576b50a02f374 Mon Sep 17 00:00:00 2001 From: Paolo Date: Fri, 26 Apr 2019 11:38:28 +0200 Subject: [PATCH] Removed not used libraries and views --- application/libraries/Format.php | 531 --------------------- application/views/rdf/basic.php | 54 --- application/views/rdf/basic_sparql.php | 74 --- application/views/rdf/converter.php | 112 ----- application/views/rdf/foafinfo.php | 124 ----- application/views/rdf/foafmaker.php | 121 ----- application/views/rdf/form.php | 121 ----- application/views/rdf/html_tag_helpers.php | 218 --------- 8 files changed, 1355 deletions(-) delete mode 100644 application/libraries/Format.php delete mode 100644 application/views/rdf/basic.php delete mode 100644 application/views/rdf/basic_sparql.php delete mode 100644 application/views/rdf/converter.php delete mode 100644 application/views/rdf/foafinfo.php delete mode 100644 application/views/rdf/foafmaker.php delete mode 100644 application/views/rdf/form.php delete mode 100644 application/views/rdf/html_tag_helpers.php diff --git a/application/libraries/Format.php b/application/libraries/Format.php deleted file mode 100644 index 0f7ea4a87..000000000 --- a/application/libraries/Format.php +++ /dev/null @@ -1,531 +0,0 @@ -_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("<$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); - } - -} diff --git a/application/views/rdf/basic.php b/application/views/rdf/basic.php deleted file mode 100644 index 2fd6ed3f7..000000000 --- a/application/views/rdf/basic.php +++ /dev/null @@ -1,54 +0,0 @@ - -
-

-
-
-
-
- -
-
- - - - - - - - - - - - - - - primaryTopic(); -?> - - - - - - - - - - -
NameGive NameFamily Name
get('foaf:name') ?> get('foaf:givenName') ?> get('foaf:familyName') ?>
- - - -
\ No newline at end of file diff --git a/application/views/rdf/basic_sparql.php b/application/views/rdf/basic_sparql.php deleted file mode 100644 index 91ca04e85..000000000 --- a/application/views/rdf/basic_sparql.php +++ /dev/null @@ -1,74 +0,0 @@ - -
-

-
-
-
-
- -
-
- - - - - - - - - - - - - - - - -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: numRows() ?> - - - - - - - - - - - - -
LabelCountry
label ?> country ?>
- - - -
diff --git a/application/views/rdf/converter.php b/application/views/rdf/converter.php deleted file mode 100644 index b8c0b9ae3..000000000 --- a/application/views/rdf/converter.php +++ /dev/null @@ -1,112 +0,0 @@ -
-

Converter

-
-
-
-
- -
-
- - - -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 "\n"; - print "EasyRdf Converter\n"; - print "\n"; - print "

EasyRdf Converter

\n"; - - print "
\n"; - print form_tag(); - print label_tag('data', 'Input Data: ').'
'.text_area_tag('data', '', array('cols'=>30, 'rows'=>10)) . "
\n"; - print label_tag('uri', 'or Uri: ').text_field_tag('uri', 'http://www.dajobe.org/foaf.rdf', array('size'=>80)) . "
\n"; - print label_tag('input_format', 'Input Format: ').select_tag('input_format', $input_format_options) . "
\n"; - print label_tag('output_format', 'Output Format: ').select_tag('output_format', $output_format_options) . "
\n"; - print label_tag('raw', 'Raw Output: ').check_box_tag('raw') . "
\n"; - print reset_tag() . submit_tag(); - print form_end_tag(); - print "
\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 '
'.htmlspecialchars($output).'
'; - } - } - - if (!isset($_REQUEST['raw'])) { - print "\n"; - print "\n"; - } - -?> -
\ No newline at end of file diff --git a/application/views/rdf/foafinfo.php b/application/views/rdf/foafinfo.php deleted file mode 100644 index 54cceec9b..000000000 --- a/application/views/rdf/foafinfo.php +++ /dev/null @@ -1,124 +0,0 @@ - -
-

-
-
-
-
- -
-
- - -
- -
- -
- -
-
-
-
- -
-
-
-

FOAF me

-load->view('rdf/html_tag_helpers'); - - - if (isset($_REQUEST['uri'])): ?> - - - - - - - type() == 'foaf:PersonalProfileDocument'): ?> - primaryTopic(); ?> - type() == 'foaf:Person'): ?> - resource(); ?> - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameHomepage
get('foaf:name') ?> get('foaf:homepage') ?>
- - - - -

Known Person

- - all('foaf:knows') as $friend) { - $label = $friend->label(); - - if (!$label) { - $label = $friend->getUri(); - } - ?> - - - - - - - - - - isBNode()): ?> - - - - ".link_to_self($label, 'uri='.urlencode($friend)).""; ?> - - - - - - - - - -
- - - - - - -
- - - - - - \ No newline at end of file diff --git a/application/views/rdf/foafmaker.php b/application/views/rdf/foafmaker.php deleted file mode 100644 index c79f9f838..000000000 --- a/application/views/rdf/foafmaker.php +++ /dev/null @@ -1,121 +0,0 @@ -
-

EasyRdf FOAF Maker Example

-
-
-
-
- -
-
-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(); - } - } -?> - -

- - 'POST')) ?> - -

Your Identifier

-40)) ?>
- -

Your details

-8)) ?>
-
-
-
-
-40)) ?>
- -

People you know

-40)) ?>
-40)) ?>
-40)) ?>
-40)) ?>
- -

Output

-Enable Arc 2?
-Enable Rapper?
-
- - - - - -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 "
".htmlspecialchars($data)."
"; - } - -?> - -
\ No newline at end of file diff --git a/application/views/rdf/form.php b/application/views/rdf/form.php deleted file mode 100644 index ad0c704b5..000000000 --- a/application/views/rdf/form.php +++ /dev/null @@ -1,121 +0,0 @@ -
-

EasyRdf FOAF Maker Example

-
-
-
-
- -
-
-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(); - } - } -?> - -

- - 'POST')) ?> - -

Your Identifier

-40)) ?>
- -

Your details

-8)) ?>
-
-
-
-
-40)) ?>
- -

People you know

-40)) ?>
-40)) ?>
-40)) ?>
-40)) ?>
- -

Output

-Enable Arc 2?
-Enable Rapper?
-
- - - - - -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 "
".htmlspecialchars($data)."
"; - } - -?> - -
\ No newline at end of file diff --git a/application/views/rdf/html_tag_helpers.php b/application/views/rdf/html_tag_helpers.php deleted file mode 100644 index 0cdcdddac..000000000 --- a/application/views/rdf/html_tag_helpers.php +++ /dev/null @@ -1,218 +0,0 @@ -'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).""; -} - -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 "$opts"; -} - -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 ""; -}