Initial commit

This commit is contained in:
Caribana
2017-05-26 11:41:26 +02:00
commit 61c24500af
6264 changed files with 645934 additions and 0 deletions

134
vendor/stefangabos/zebra_form/README.md vendored Normal file
View File

@@ -0,0 +1,134 @@
# Zebra_Form
#### A jQuery augmented PHP library for creating and validating HTML forms
----
[Packagist](https://packagist.org/) stats
[![Latest Stable Version](https://poser.pugx.org/stefangabos/zebra_form/v/stable)](https://packagist.org/packages/stefangabos/zebra_form) [![Total Downloads](https://poser.pugx.org/stefangabos/zebra_form/downloads)](https://packagist.org/packages/stefangabos/zebra_form) [![Monthly Downloads](https://poser.pugx.org/stefangabos/zebra_form/d/monthly)](https://packagist.org/packages/stefangabos/zebra_form) [![Daily Downloads](https://poser.pugx.org/stefangabos/zebra_form/d/daily)](https://packagist.org/packages/stefangabos/zebra_form) [![License](https://poser.pugx.org/stefangabos/zebra_form/license)](https://packagist.org/packages/stefangabos/zebra_form)
Zebra_Form is a PHP library that greatly simplifies the process of creating and validating HTML forms. Its object-oriented structure promotes rapid HTML forms development and encourages developers to write clean and easily maintainable code and it frees the developers from the repetitive task of writing the code for validating forms by offering powerful built-in client-side and server-side validation.
Zebra_Form has integrated [cross-site scripting](http://en.wikipedia.org/wiki/Cross-site_scripting) (XSS) prevention mechanism that automatically strips out potentially malicious code from the submitted data, and also features protection against [cross-site request forgery](http://en.wikipedia.org/wiki/Cross-site_request_forgery) (CSRF) attacks. It also prevents automated SPAM posts, out of the box and without relying on CAPTCHA by using [honeypots](http://haacked.com/archive/2007/09/11/honeypot-captcha.aspx).
Forms layout can be generated either automatically or manually using templates. When generated automatically, the generated output validates as HTML 4.01 Strict, XHTML 1.0 Strict or HTML5, and has the same look & feel across all major browsers like Firefox, Chrome, Opera, Safari and Internet Explorer 6+.
It provides all the controls youd expect in an HTML form and, additionally, date/time pickers, CAPTCHA and advanced AJAX-like file upload controls see the [documentation](http://stefangabos.ro/wp-content/docs/Zebra_Form/Generic/Zebra_Form_Control.html#methodset_rule) for validation rules that can be used out of the box.
The client-side validation is done using jQuery 1.5.2+
Zebra\_Form's code is heavily commented and generates no warnings/errors/notices when PHPs error reporting level is set to E_ALL.
##Features
- provides protection against cross-site scripting (XSS) and cross-site request forgery (CSRF) attacks out of the box
it automatically prevents automated SPAM posts using the “honeypot” technique (CAPTCHAs can also be used for even stronger protection)
- provides both server-side and client-side validation (client-side validation is done using jQuery 1.5.2+) and has a lot of predefined rules that can be used out of the box; custom validation rules (including AJAX-based) can easily be added
- forms layout can be generated either automatically or manually using templates
- generated output validates as HTML 4.01 Strict, XHTML 1.0 Strict or HTML5
- works in all major browsers like Firefox, Chrome, Opera, Safari and Internet Explorer 6+
- code is heavily commented and generates no warnings/errors/notices when PHPs error reporting level is set to E_ALL
- has comprehensive documentation
## Requirements
PHP 5.0.2+ (preferably PHP 5.3.0 compiled with the “fileinfo” extension for more secure file uploads read more at the change log for version 2.7.3)
jQuery 1.5.2+
## How to use
#####The HTML
```html
<!-- must be in strict mode! -->
<!DOCTYPE html>
<html>
<head>
<title>Zebra_Form Example</title>
<meta charset="utf-8">
<!-- load Zebra_Form's stylesheet file -->
<link rel="stylesheet" href="path/to/zebra_form.css">
</head>
<body>
<!-- the PHP code below goes here -->
<!-- load jQuery -->
<script src="path/to/jquery.js"></script>
<!-- load Zebra_Form's JavaScript file -->
<script src="path/to/zebra_form.js"></script>
</body>
</html>
```
#####The PHP
```php
<?php
// include the Zebra_Form class
require 'path/to/Zebra_Form.php';
// instantiate a Zebra_Form object
$form = new Zebra_Form('form');
// the label for the "email" field
$form->add('label', 'label_email', 'email', 'Email');
// add the "email" field
$obj = $form->add('text', 'email', '', array('autocomplete' => 'off'));
// set rules
$obj->set_rule(array(
// error messages will be sent to a variable called "error", usable in custom templates
'required' => array('error', 'Email is required!'),
'email' => array('error', 'Email address seems to be invalid!'),
));
// "password"
$form->add('label', 'label_password', 'password', 'Password');
$obj = $form->add('password', 'password', '', array('autocomplete' => 'off'));
$obj->set_rule(array(
'required' => array('error', 'Password is required!'),
'length' => array(6, 10, 'error', 'The password must have between 6 and 10 characters'),
));
// "remember me"
$form->add('checkbox', 'remember_me', 'yes');
$form->add('label', 'label_remember_me_yes', 'remember_me_yes', 'Remember me');
// "submit"
$form->add('submit', 'btnsubmit', 'Submit');
// validate the form
if ($form->validate()) {
// do stuff here
}
// auto generate output, labels above form elements
$form->render();
?>
```
For demos and more information visit the **[project's homepage](http://stefangabos.ro/php-libraries/zebra-form/)**

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1 @@
See http://stefangabos.ro/php-libraries/zebra-form/#changelog

View File

@@ -0,0 +1,25 @@
{
"name": "stefangabos/zebra_form",
"type": "library",
"description": "A jQuery augmented PHP library for creating and validating HTML forms",
"keywords": ["form","validation", "csrf", "xss", "honeypot", "validate", "jquery validation", "client side validation", "server side validation"],
"homepage": "http://stefangabos.ro/php-libraries/zebra-form/",
"license": "LGPL-3.0",
"authors": [
{
"name": "Stefan Gabos",
"email": "contact@stefangabos.ro",
"homepage": "http://stefangabos.ro/",
"role": "Developer"
}
],
"require": {
"php": ">=5.3.0"
},
"version": "2.9.8",
"autoload": {
"classmap": [
"Zebra_Form.php"
]
}
}

View File

@@ -0,0 +1 @@
See http://stefangabos.ro/php-libraries/zebra-form/#documentation

View File

@@ -0,0 +1,76 @@
<h2>A contact form</h2>
<p>Note the uneditable prefixes (text and images) for some of the fields.</p>
<p>Check the "Template source" tab to see how it's done!</p>
<?php
// include the Zebra_Form class
require '../Zebra_Form.php';
// instantiate a Zebra_Form object
$form = new Zebra_Form('form');
// the label for the "name" element
$form->add('label', 'label_name', 'name', 'Your name:');
// add the "name" element
$obj = $form->add('text', 'name', '', array('style' => 'width: 195px', 'data-prefix' => 'img:public/images/user.png'));
// set rules
$obj->set_rule(array(
// error messages will be sent to a variable called "error", usable in custom templates
'required' => array('error', 'Name is required!')
));
// "email"
$form->add('label', 'label_email', 'email', 'Your email address:');
$obj = $form->add('text', 'email', '', array('style' => 'width: 195px', 'data-prefix' => 'img:public/images/letter.png'));
$obj->set_rule(array(
'required' => array('error', 'Email is required!'),
'email' => array('error', 'Email address seems to be invalid!'),
));
$form->add('note', 'note_email', 'email', 'Your email address will not be published.');
// "website"
$form->add('label', 'label_website', 'website', 'Your website:');
$obj = $form->add('text', 'website', '', array('style' => 'width: 400px', 'data-prefix' => 'http://'));
$obj->set_rule(array(
'url' => array(true, 'error', 'Invalid URL specified!'),
));
$form->add('note', 'note_website', 'website', 'Enter the URL of your website, if you have one.');
// "subject"
$form->add('label', 'label_subject', 'subject', 'Subject');
$obj = $form->add('text', 'subject', '', array('style' => 'width: 400px', 'data-prefix' => 'img:public/images/comment.png'));
$obj->set_rule(array(
'required' => array('error', 'Subject is required!')
));
// "message"
$form->add('label', 'label_message', 'message', 'Message:');
$obj = $form->add('textarea', 'message');
$obj->set_rule(array(
'required' => array('error', 'Message is required!'),
'length' => array(0, 140, 'error', 'Maximum length is 140 characters!', true),
));
// "submit"
$form->add('submit', 'btnsubmit', 'Submit');
// if the form is valid
if ($form->validate()) {
// show results
show_results();
// otherwise
} else
// generate output using a custom template
$form->render('includes/custom-templates/contact.php');
?>

View File

@@ -0,0 +1,74 @@
<h2>A contact form</h2>
<p>Note the uneditable prefixes (text and images) for some of the fields.</p>
<?php
// include the Zebra_Form class
require '../Zebra_Form.php';
// instantiate a Zebra_Form object
$form = new Zebra_Form('form');
// the label for the "name" element
$form->add('label', 'label_name', 'name', 'Your name:');
// add the "name" element
$obj = $form->add('text', 'name', '', array('data-prefix' => 'img:public/images/user.png'));
// set rules
$obj->set_rule(array(
// error messages will be sent to a variable called "error", usable in custom templates
'required' => array('error', 'Name is required!')
));
// "email"
$form->add('label', 'label_email', 'email', 'Your email address:');
$obj = $form->add('text', 'email', '', array('data-prefix' => 'img:public/images/letter.png'));
$obj->set_rule(array(
'required' => array('error', 'Email is required!'),
'email' => array('error', 'Email address seems to be invalid!'),
));
$form->add('note', 'note_email', 'email', 'Your email address will not be published.');
// "website"
$form->add('label', 'label_website', 'website', 'Your website:');
$obj = $form->add('text', 'website', '', array('data-prefix' => 'http://'));
$obj->set_rule(array(
'url' => array(true, 'error', 'Invalid URL specified!'),
));
$form->add('note', 'note_website', 'website', 'Enter the URL of your website, if you have one.');
// "subject"
$form->add('label', 'label_subject', 'subject', 'Subject');
$obj = $form->add('text', 'subject', '', array('data-prefix' => 'img:public/images/comment.png'));
$obj->set_rule(array(
'required' => array('error', 'Subject is required!')
));
// "message"
$form->add('label', 'label_message', 'message', 'Message:');
$obj = $form->add('textarea', 'message');
$obj->set_rule(array(
'required' => array('error', 'Message is required!'),
'length' => array(0, 140, 'error', 'Maximum length is 140 characters!', true),
));
// "submit"
$form->add('submit', 'btn_submit', 'Submit');
// if the form is valid
if ($form->validate()) {
// show results
show_results();
// otherwise
} else
// generate output using a custom template
$form->render('*horizontal');
?>

View File

@@ -0,0 +1,74 @@
<h2>A contact form</h2>
<p>Note the uneditable prefixes (text and images) for some of the fields.</p>
<?php
// include the Zebra_Form class
require '../Zebra_Form.php';
// instantiate a Zebra_Form object
$form = new Zebra_Form('form');
// the label for the "name" element
$form->add('label', 'label_name', 'name', 'Your name:');
// add the "name" element
$obj = $form->add('text', 'name', '', array('data-prefix' => 'img:public/images/user.png'));
// set rules
$obj->set_rule(array(
// error messages will be sent to a variable called "error", usable in custom templates
'required' => array('error', 'Name is required!')
));
// "email"
$form->add('label', 'label_email', 'email', 'Your email address:');
$obj = $form->add('text', 'email', '', array('data-prefix' => 'img:public/images/letter.png'));
$obj->set_rule(array(
'required' => array('error', 'Email is required!'),
'email' => array('error', 'Email address seems to be invalid!'),
));
$form->add('note', 'note_email', 'email', 'Your email address will not be published.');
// "website"
$form->add('label', 'label_website', 'website', 'Your website:');
$obj = $form->add('text', 'website', '', array('data-prefix' => 'http://'));
$obj->set_rule(array(
'url' => array(true, 'error', 'Invalid URL specified!'),
));
$form->add('note', 'note_website', 'website', 'Enter the URL of your website, if you have one.');
// "subject"
$form->add('label', 'label_subject', 'subject', 'Subject');
$obj = $form->add('text', 'subject', '', array('style' => 'width:400px', 'data-prefix' => 'img:public/images/comment.png'));
$obj->set_rule(array(
'required' => array('error', 'Subject is required!')
));
// "message"
$form->add('label', 'label_message', 'message', 'Message:');
$obj = $form->add('textarea', 'message');
$obj->set_rule(array(
'required' => array('error', 'Message is required!'),
'length' => array(0, 140, 'error', 'Maximum length is 140 characters!', true)
));
// "submit"
$form->add('submit', 'btnsubmit', 'Submit');
// if the form is valid
if ($form->validate()) {
// show results
show_results();
// otherwise
} else
// generate output using a custom template
$form->render();
?>

View File

@@ -0,0 +1,36 @@
<!-- must be in strict mode! -->
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Zebra_Form Example</title>
<!-- load Zebra_Form's stylesheet file -->
<link rel="stylesheet" href="path/to/zebra_form.css">
</head>
<body>
<!--
the content from the "PHP Source" tab goes here
-->
<!-- we're loading the JavaScript files at the bottom of the page so we don't delay page rendering -->
<!-- try to load jQuery from CDN server and fallback to local source if not available -->
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script>window.jQuery || document.write('<script src="path/to/jquery-1.9.1.min.js"><\/script>')</script>
<!-- load Zebra_Form's JavaScript file -->
<script src="path/to/zebra_form.js"></script>
</body>
</html>

View File

@@ -0,0 +1,27 @@
<?php
// don't forget about this for custom templates, or errors will not show for server-side validation
// $zf_error is automatically created by the library and it holds messages about SPAM or CSRF errors
// $error is the name of the variable used with the set_rule method
echo (isset($zf_error) ? $zf_error : (isset($error) ? $error : ''));
?>
<!-- elements are grouped in "rows" -->
<div class="row">
<!-- things that need to be side-by-side go in "cells" and will be floated to the left -->
<div class="cell"><?php echo $label_name . $name?></div>
<div class="cell"><?php echo $label_email . $email . $note_email?></div>
</div>
<!-- notice the "even" class which is used to highlight even rows differently
from the odd rows -->
<div class="row even"><?php echo $label_website . $website . $note_website?></div>
<div class="row"><?php echo $label_subject . $subject?></div>
<div class="row even"><?php echo $label_message . $message?></div>
<!-- the submit button goes in the last row; also, notice the "last" class which
removes the bottom border which is otherwise present for any row -->
<div class="row last"><?php echo $btnsubmit?></div>

View File

@@ -0,0 +1,28 @@
<?php
// don't forget about this for custom templates, or errors will not show for server-side validation
// $zf_error is automatically created by the library and it holds messages about SPAM or CSRF errors
// $error is the name of the variable used with the set_rule method
echo (isset($zf_error) ? $zf_error : (isset($error) ? $error : ''));
?>
<!-- elements are grouped in "rows" -->
<div class="row">
<!-- things that need to be side-by-side go in "cells" and will be floated to the left -->
<div class="cell"><?php echo $label_email . $email?></div>
<div class="cell"><?php echo $label_password . $password?></div>
<div class="clear" style="margin-bottom:10px"></div>
<!-- on the same row, but beneath the email and the password fields,
we place the "remember me" checkbox and attached label -->
<div class="cell"><?php echo $remember_me_yes?></div>
<div class="cell"><?php echo $label_remember_me_yes?></div>
</div>
<!-- the submit button goes in the last row; notice the "even" class which
is used to highlight even rows differently from the odd rows; also, notice
the "last" class which removes the bottom border which is otherwise present
for any row -->
<div class="row even last"><?php echo $btnsubmit?></div>

View File

@@ -0,0 +1,73 @@
<!--
in reality you'd have this in an external stylesheet;
i am using it like this for the sake of the example
-->
<style type="text/css">
.Zebra_Form .optional { padding: 10px 50px; display: none }
</style>
<!--
again, in reality you'd have this in an external JavaScript file;
i am using it like this for the sake of the example
-->
<script type="text/javascript">
var mycallback = function(value, segment) {
$segment = $('.optional' + segment);
if (value) $segment.show();
else $segment.hide();
}
</script>
<?php echo (isset($zf_error) ? $zf_error : (isset($error) ? $error : ''))?>
<div class="row">
<?php echo $label_name . $name?>
</div>
<div class="row">
<?php echo $label_notifications?>
<div class="cell"><?php echo $notifications_yes?></div>
<div class="cell"><?php echo $label_notifications_yes?></div>
<div class="clear"></div>
<div class="optional optional1">
<?php echo $label_method?>
<div class="cell"><?php echo $method_email?></div>
<div class="cell"><?php echo $label_method_email?></div>
<div class="clear"></div>
<div class="optional optional2">
<?php echo $label_email . $email . $note_email?>
</div>
<div class="cell"><?php echo $method_phone?></div>
<div class="cell"><?php echo $label_method_phone?></div>
<div class="clear"></div>
<div class="optional optional3">
<?php echo $label_phone . $phone . $note_phone?>
</div>
<div class="cell"><?php echo $method_post?></div>
<div class="cell"><?php echo $label_method_post?></div>
<div class="clear"></div>
<div class="optional optional4">
<?php echo $label_post . $post . $note_post?>
</div>
</div>
<div class="cell"><?php echo $notifications_no?></div>
<div class="cell"><?php echo $label_notifications_no?></div>
<div class="clear"></div>
<div class="optional optional5">
<?php echo $label_why . $why?>
</div>
</div>
<div class="row last"><?php echo $btnsubmit?></div>

View File

@@ -0,0 +1,15 @@
<?php echo (isset($zf_error) ? $zf_error : (isset($error) ? $error : ''))?>
<div class="row">
<div class="cell"><?php echo $label_name . $name?></div>
<div class="cell"><?php echo $label_surname . $surname?></div>
</div>
<div class="row even">
<h6><strong>Add new person</strong></h6><br>
<div class="cell"><?php echo $label_add_name . $add_name?></div>
<div class="cell"><?php echo $label_add_surname . $add_surname?></div>
<div class="cell"><br><?php echo $btnadd?></div>
</div>
<div class="row last"><?php echo $btnsubmit?></div>

View File

@@ -0,0 +1,32 @@
<?php
// don't forget about this for custom templates, or errors will not show for server-side validation
// $zf_error is automatically created by the library and it holds messages about SPAM or CSRF errors
// $error is the name of the variable used with the set_rule method
echo (isset($zf_error) ? $zf_error : (isset($error) ? $error : ''));
?>
<!-- elements are grouped in "rows" -->
<div class="row">
<!-- things that need to be side-by-side go in "cells" and will be floated to the left -->
<div class="cell"><?php echo $label_firstname . $firstname?></div>
<div class="cell"><?php echo $label_lastname . $lastname?></div>
</div>
<!-- notice the "even" class which is used to highlight even rows differently
from the odd rows -->
<div class="row even"><?php echo $label_email . $email . $note_email?></div>
<div class="row">
<div class="cell"><?php echo $label_password . $password . $note_password?></div>
<div class="cell"><?php echo $label_confirm_password . $confirm_password?></div>
</div>
<div class="row even">
<?php echo $captcha_image . $label_captcha_code . $captcha_code . $note_captcha?>
</div>
<!-- the submit button goes in the last row; also, notice the "last" class which
removes the bottom border which is otherwise present for any row -->
<div class="row even last"><?php echo $btnsubmit?></div>

View File

@@ -0,0 +1,72 @@
<?php
// don't forget about this for custom templates, or errors will not show for server-side validation
// $zf_error is automatically created by the library and it holds messages about SPAM or CSRF errors
// $error is the name of the variable used with the set_rule method
echo (isset($zf_error) ? $zf_error : (isset($error) ? $error : ''));
?>
<!-- elements are grouped in "rows" -->
<div class="row">
<!-- things that need to be side-by-side go in "cells" and will be floated to the left -->
<div class="cell"><?php echo $label_name . $name?></div>
<div class="cell"><?php echo $label_email . $email?></div>
</div>
<!-- notice the "even" class which is used to highlight even rows differently
from the odd rows -->
<div class="row even">
<?php echo $label_department . $department . $department_other?>
</div>
<div class="row">
<div class="cell">
<?php echo $label_room?>
<!-- this is the preffered way of displaying checkboxes and
radio buttons and their associated label -->
<div class="cell"><?php echo $room_A?></div>
<div class="cell"><?php echo $label_room_A?></div>
<div class="clear"></div>
<div class="cell"><?php echo $room_B?></div>
<div class="cell"><?php echo $label_room_B?></div>
<div class="clear"></div>
<div class="cell"><?php echo $room_C?></div>
<div class="cell"><?php echo $label_room_C?></div>
<div class="clear"></div>
</div>
<div class="cell" style="margin-left: 20px">
<?php echo $label_extra?>
<div class="cell"><?php echo $extra_flipchard?></div>
<div class="cell"><?php echo $label_extra_flipchard?></div>
<div class="clear"></div>
<div class="cell"><?php echo $extra_plasma?></div>
<div class="cell"><?php echo $label_extra_plasma?></div>
<div class="clear"></div>
<div class="cell"><?php echo $extra_beverages?></div>
<div class="cell"><?php echo $label_extra_beverages?></div>
<div class="clear"></div>
</div>
</div>
<div class="row even">
<div class="cell"><?php echo $label_date . $date?></div>
<div class="cell" style="margin-left: 10px"><?php echo $label_time . $time?></div>
</div>
<!-- the submit button goes in the last row; also, notice the "last" class which
removes the bottom border which is otherwise present for any row -->
<div class="row last"><?php echo $btnsubmit?></div>

View File

@@ -0,0 +1,45 @@
<?php
// don't forget about this for custom templates, or errors will not show for server-side validation
// $zf_error is automatically created by the library and it holds messages about SPAM or CSRF errors
// $error is the name of the variable used with the set_rule method
echo (isset($zf_error) ? $zf_error : (isset($error) ? $error : ''));
?>
<table cellspacing="0" cellpadding="0">
<!-- elements are grouped in "rows" -->
<tr class="row">
<td><?php echo $label_email?></td>
<td><?php echo $email?></td>
</tr>
<!-- notice the "even" class which is used to highlight even rows differently
from the odd rows -->
<tr class="row even">
<td><?php echo $label_password?></td>
<td><?php echo $password?></td>
</tr>
<tr class="row">
<td></td>
<td>
<!-- this is the preffered way of displaying checkboxes and
radio buttons and their associated label -->
<div class="cell"><?php echo $remember_me_yes?></div>
<div class="cell"><?php echo $label_remember_me_yes?></div>
<!-- once we're done with "cells" we *must* place a "clear" div -->
<div class="clear"></div>
</td>
</tr>
<!-- the submit button goes in the last row; also, notice the "last" class which
removes the bottom border which is otherwise present for any row -->
<tr class="row even last">
<td></td>
<td><?php echo $btnsubmit?></td>
</tr>
</table>

View File

@@ -0,0 +1,106 @@
<h2>Dependencies</h2>
<p>Showcasing how elements can be validated only if other elements meet certain conditions and how callback functions for the "dependencies" rule work.</p>
<?php
// include the Zebra_Form class
require '../Zebra_Form.php';
// instantiate a Zebra_Form object
$form = new Zebra_Form('form');
// add the "name" element
$form->add('label', 'label_name', 'name', 'Your name');
$obj = $form->add('text', 'name');
// set rules
$obj->set_rule(array(
'required' => array('error', 'Name is required!'),
));
// "notifications"
$form->add('label', 'label_notifications', 'notifications', 'Would you like to be informed about promotional offers?');
$obj = $form->add('radios', 'notifications', array(
'yes' => 'Yes',
'no' => 'No',
));
$obj->set_rule(array(
'required' => array('error', 'Please select an answer!'),
));
// "method"
$form->add('label', 'label_method', 'method', 'Please specify how you would like to be notified about promotional offers:');
$obj = $form->add('checkboxes', 'method[]', array(
'email' => 'By e-mail',
'phone' => 'By phone',
'post' => 'By land mail',
));
$obj->set_rule(array(
'required' => array('error', 'Please specify how you would like to be notified about promotional offers!'),
'dependencies' => array(array(
'notifications' => 'yes',
// whenever the value of "notification" changes, call this function and pass as second argument the value "1"
), 'mycallback, 1'),
));
// "email"
$form->add('label', 'label_email', 'email', 'Your email address:');
$obj = $form->add('text', 'email');
$obj->set_rule(array(
'required' => array('error', 'Email is required!'),
'email' => array('error', 'Email address seems to be invalid!'),
'dependencies' => array(array(
'method' => 'email',
), 'mycallback, 2'),
));
$form->add('note', 'note_email', 'email', 'Your email address will not be published.');
// "phone"
$form->add('label', 'label_phone', 'phone', 'Your telephone number:');
$obj = $form->add('text', 'phone');
$obj->set_rule(array(
'required' => array('error', 'Phone number is required!'),
'digits' => array('', 'error', 'Phone number must contain only digits!'),
'dependencies' => array(array(
'method' => 'phone',
), 'mycallback, 3'),
));
$form->add('note', 'note_phone', 'phone', 'Enter your phone number using digits only');
// "post"
$form->add('label', 'label_post', 'post', 'Your postal address:');
$obj = $form->add('text', 'post');
$obj->set_rule(array(
'required' => array('error', 'Postal address is required!'),
'dependencies' => array(array(
'method' => 'post',
), 'mycallback, 4'),
));
$form->add('note', 'note_post', 'post', 'Enter the address where the notifications about promotional offers should be delivered');
// "why"
$form->add('label', 'label_why', 'why', 'Please tell us why:');
$obj = $form->add('textarea', 'why');
$obj->set_rule(array(
'required' => array('error', 'Please leave us a message!'),
'dependencies' => array(array(
'notifications' => 'no',
), 'mycallback, 5'),
));
// "submit"
$form->add('submit', 'btnsubmit', 'Submit');
// if the form is valid
if ($form->validate()) {
// show results
show_results();
// otherwise
} else
$form->render('includes/custom-templates/example1-dependencies.php');
?>

View File

@@ -0,0 +1,75 @@
<h2>Dependencies</h2>
<p>Notice how the elements from the "Add new person" section are validated *only* when the "Add new" button is clicked</p>
<?php
// include the Zebra_Form class
require '../Zebra_Form.php';
// instantiate a Zebra_Form object
$form = new Zebra_Form('form');
// add the "name" element
$form->add('label', 'label_name', 'name', 'Name');
$obj = $form->add('text', 'name');
// set rules
$obj->set_rule(array(
'required' => array('error', 'Name is required!'),
));
// add the "surname" element
$form->add('label', 'label_surname', 'surname', 'Surname');
$obj = $form->add('text', 'surname');
// set rules
$obj->set_rule(array(
'required' => array('error', 'Surname is required!'),
));
// elements for adding a new person
// add the "name" element
$form->add('label', 'label_add_name', 'add_name', 'Name');
$obj = $form->add('text', 'add_name');
// set rules
// validate *only* if the "Add new" button is clicked
$obj->set_rule(array(
'required' => array('error', 'Name is required!'),
'dependencies' => array(
'btnadd' => 'click',
),
));
// add the "surname" element
$form->add('label', 'label_add_surname', 'add_surname', 'Surame');
$obj = $form->add('text', 'add_surname');
// set rules
$obj->set_rule(array(
'required' => array('error', 'Surname is required!'),
'dependencies' => array(
'btnadd' => 'click',
),
));
// "add"
$form->add('submit', 'btnadd', 'Add new');
// "submit"
$form->add('submit', 'btnsubmit', 'Finish');
// if the form is valid
if ($form->validate()) {
// show results
show_results();
// otherwise
} else
$form->render('includes/custom-templates/example2-dependencies.php');
?>

View File

@@ -0,0 +1,52 @@
<h2>Basic image upload</h2>
<p>We're checking for file types </p>
<?php
// include the Zebra_Form class
require '../Zebra_Form.php';
// instantiate a Zebra_Form object
$form = new Zebra_Form('form');
// the label for the "file" element
$form->add('label', 'label_file', 'file', 'Upload an image');
// add the "file" element
$obj = $form->add('file', 'file');
// set rules
$obj->set_rule(array(
// error messages will be sent to a variable called "error", usable in custom templates
'required' => array('error', 'An image is required!'),
'upload' => array('tmp', ZEBRA_FORM_UPLOAD_RANDOM_NAMES, 'error', 'Could not upload file!<br>Check that the "tmp" folder exists inside the "examples" folder and that it is writable'),
// notice how we use the "image" rule instead of the "filetype" rule (used in previous example);
// the "image" rule does a thorough checking aimed specially for images
'image' => array('error', 'File must be a jpg, png or gif image!'),
'filesize' => array(102400, 'error', 'File size must not exceed 100Kb!'),
));
// attach a note
$form->add('note', 'note_file', 'file', 'File must have the .jpg, .jpeg, png or .gif extension, and no more than 100Kb!');
// "submit"
$form->add('submit', 'btnsubmit', 'Submit');
// validate the form
if ($form->validate()) {
// do stuff here
print_r('<pre>');
print_r($form->file_upload);
die();
}
// auto generate output, labels above form elements
$form->render();
?>

View File

@@ -0,0 +1,49 @@
<h2>Basic file upload</h2>
<p>Once you upload the file, don't forget to look into the "tmp" folder inside the "examples" folder for the result.</p>
<?php
// include the Zebra_Form class
require '../Zebra_Form.php';
// instantiate a Zebra_Form object
$form = new Zebra_Form('form');
// the label for the "file" element
$form->add('label', 'label_file', 'file', 'Upload Microsoft Word document');
// add the "file" element
$obj = $form->add('file', 'file');
// set rules
$obj->set_rule(array(
// error messages will be sent to a variable called "error", usable in custom templates
'required' => array('error', 'A Microsoft Word document is required!'),
'upload' => array('tmp', ZEBRA_FORM_UPLOAD_RANDOM_NAMES, 'error', 'Could not upload file!<br>Check that the "tmp" folder exists inside the "examples" folder and that it is writable'),
'filetype' => array('doc, docx', 'error', 'File must be a Microsoft Word document!'),
'filesize' => array(102400, 'error', 'File size must not exceed 100Kb!'),
));
// attach a note
$form->add('note', 'note_file', 'file', 'File must have the .doc or .docx extension, and no more than 100Kb!');
// "submit"
$form->add('submit', 'btnsubmit', 'Submit');
// validate the form
if ($form->validate()) {
// do stuff here
print_r('<pre>');
print_r($form->file_upload);
die();
}
// auto generate output, labels above form elements
$form->render();
?>

View File

@@ -0,0 +1,62 @@
<h2>A login form</h2>
<p>In this demo we're creating a custom template using only divs; this is suitable for creating "vertical" templates (when
a control's label is above the control), but when we want some elements to be side-by-side. Don't forget to check the
"Template source" tab to see how it's done.</p>
<?php
// include the Zebra_Form class
require '../Zebra_Form.php';
// instantiate a Zebra_Form object
$form = new Zebra_Form('form', 'post', '', array('autocomplete' => 'off'));
// the label for the "email" element
$form->add('label', 'label_email', 'email', 'Email');
// add the "email" element
$obj = $form->add('text', 'email');
// set rules
$obj->set_rule(array(
// error messages will be sent to a variable called "error", usable in custom templates
'required' => array('error', 'Email is required!'),
'email' => array('error', 'Email address seems to be invalid!'),
));
// "password"
$form->add('label', 'label_password', 'password', 'Password');
$obj = $form->add('password', 'password');
$obj->set_rule(array(
'required' => array('error', 'Password is required!'),
'length' => array(6, 10, 'error', 'The password must have between 6 and 10 characters!'),
));
// "remember me"
$form->add('checkbox', 'remember_me', 'yes');
$form->add('label', 'label_remember_me_yes', 'remember_me_yes', 'Remember me', array('style' => 'font-weight:normal'));
// "submit"
$form->add('submit', 'btnsubmit', 'Submit');
// if the form is valid
if ($form->validate()) {
// show results
show_results();
// otherwise
} else
// generate output using a custom template
$form->render('includes/custom-templates/divs-login.php');
?>

View File

@@ -0,0 +1,53 @@
<h2>A login form</h2>
<?php
// include the Zebra_Form class
require '../Zebra_Form.php';
// instantiate a Zebra_Form object
$form = new Zebra_Form('form', 'post', '', array('autocomplete' => 'off'));
// the label for the "email" element
$form->add('label', 'label_email', 'email', 'Email');
// add the "email" element
$obj = $form->add('text', 'email');
// set rules
$obj->set_rule(array(
// error messages will be sent to a variable called "error", usable in custom templates
'required' => array('error', 'Email is required!'),
'email' => array('error', 'Email address seems to be invalid!'),
));
// "password"
$form->add('label', 'label_password', 'password', 'Password');
$obj = $form->add('password', 'password');
$obj->set_rule(array(
'required' => array('error', 'Password is required!'),
'length' => array(6, 10, 'error', 'The password must have between 6 and 10 characters!'),
));
// "remember me"
$form->add('checkbox', 'remember_me', 'yes');
$form->add('label', 'label_remember_me_yes', 'remember_me_yes', 'Remember me', array('style' => 'font-weight:normal'));
// "submit"
$form->add('submit', 'btnsubmit', 'Submit');
// if the form is valid
if ($form->validate()) {
// show results
show_results();
// otherwise
} else
// generate output using a custom template
$form->render('*horizontal');
?>

View File

@@ -0,0 +1,53 @@
<h2>A login form</h2>
<?php
// include the Zebra_Form class
require '../Zebra_Form.php';
// instantiate a Zebra_Form object
$form = new Zebra_Form('form', 'post', '', array('autocomplete' => 'off'));
// the label for the "email" element
$form->add('label', 'label_email', 'email', 'Email address', array('inside' => true));
// add the "email" element
$obj = $form->add('text', 'email');
// set rules
$obj->set_rule(array(
// error messages will be sent to a variable called "error", usable in custom templates
'required' => array('error', 'Email is required!'),
'email' => array('error', 'Email address seems to be invalid!'),
));
// "password"
$form->add('label', 'label_password', 'password', 'Password', array('inside' => true));
$obj = $form->add('password', 'password');
$obj->set_rule(array(
'required' => array('error', 'Password is required!'),
'length' => array(6, 10, 'error', 'The password must have between 6 and 10 characters!'),
));
// "remember me"
$form->add('checkbox', 'remember_me', 'yes');
$form->add('label', 'label_remember_me_yes', 'remember_me_yes', 'Remember me', array('style' => 'font-weight:normal'));
// "submit"
$form->add('submit', 'btnsubmit', 'Submit');
// if the form is valid
if ($form->validate()) {
// show results
show_results();
// otherwise
} else
// generate output using a custom template
$form->render();
?>

View File

@@ -0,0 +1,56 @@
<h2>A login form</h2>
<p>In this demo we're creating a custom template using tables; this is suitable for creating "horizontal" templates (when
a control's label is to the left of the control). Don't forget to check the "Template source" tab to see how it's done.</p>
<?php
// include the Zebra_Form class
require '../Zebra_Form.php';
// instantiate a Zebra_Form object
$form = new Zebra_Form('form', 'post', '', array('autocomplete' => 'off'));
// the label for the "email" element
$form->add('label', 'label_email', 'email', 'Email');
// add the "email" element
$obj = $form->add('text', 'email');
// set rules
$obj->set_rule(array(
// error messages will be sent to a variable called "error", usable in custom templates
'required' => array('error', 'Email is required!'),
'email' => array('error', 'Email address seems to be invalid!'),
));
// "password"
$form->add('label', 'label_password', 'password', 'Password');
$obj = $form->add('password', 'password');
$obj->set_rule(array(
'required' => array('error', 'Password is required!'),
'length' => array(6, 10, 'error', 'The password must have between 6 and 10 characters!'),
));
// "remember me"
$form->add('checkbox', 'remember_me', 'yes');
$form->add('label', 'label_remember_me_yes', 'remember_me_yes', 'Remember me', array('style' => 'font-weight:normal'));
// "submit"
$form->add('submit', 'btnsubmit', 'Submit');
// if the form is valid
if ($form->validate()) {
// show results
show_results();
// otherwise
} else
// generate output using a custom template
$form->render('includes/custom-templates/tables-login.php');
?>

View File

@@ -0,0 +1,53 @@
<h2>A login form</h2>
<?php
// include the Zebra_Form class
require '../Zebra_Form.php';
// instantiate a Zebra_Form object
$form = new Zebra_Form('form', 'post', '', array('autocomplete' => 'off'));
// the label for the "email" element
$form->add('label', 'label_email', 'email', 'Email');
// add the "email" element
$obj = $form->add('text', 'email');
// set rules
$obj->set_rule(array(
// error messages will be sent to a variable called "error", usable in custom templates
'required' => array('error', 'Email is required!'),
'email' => array('error', 'Email address seems to be invalid!'),
));
// "password"
$form->add('label', 'label_password', 'password', 'Password');
$obj = $form->add('password', 'password');
$obj->set_rule(array(
'required' => array('error', 'Password is required!'),
'length' => array(6, 10, 'error', 'The password must have between 6 and 10 characters!'),
));
// "remember me"
$form->add('checkbox', 'remember_me', 'yes');
$form->add('label', 'label_remember_me_yes', 'remember_me_yes', 'Remember me', array('style' => 'font-weight:normal'));
// "submit"
$form->add('submit', 'btnsubmit', 'Submit');
// if the form is valid
if ($form->validate()) {
// show results
show_results();
// otherwise
} else
// auto generate output, labels above form elements
$form->render();
?>

View File

@@ -0,0 +1,88 @@
<h2>A registration form</h2>
<p>Check the "Template source" tab to see how it's done!</p>
<?php
// include the Zebra_Form class
require '../Zebra_Form.php';
// instantiate a Zebra_Form object
$form = new Zebra_Form('form', 'post', '', array('autocomplete' => 'off'));
// the label for the "first name" element
$form->add('label', 'label_firstname', 'firstname', 'First name:');
// add the "first name" element
$obj = $form->add('text', 'firstname');
// set rules
$obj->set_rule(array(
// error messages will be sent to a variable called "error", usable in custom templates
'required' => array('error', 'First name is required!'),
));
// "last name"
$form->add('label', 'label_lastname', 'lastname', 'Last name:');
$obj = $form->add('text', 'lastname');
$obj->set_rule(array(
'required' => array('error', 'Last name is required!')
));
// "email"
$form->add('label', 'label_email', 'email', 'Email address:');
$obj = $form->add('text', 'email');
$obj->set_rule(array(
'required' => array('error', 'Email is required!'),
'email' => array('error', 'Email address seems to be invalid!')
));
// attach a note to the email element
$form->add('note', 'note_email', 'email', 'Please enter a valid email address. An email will be sent to this
address with a link you need to click on in order to activate your account', array('style'=>'width:200px'));
// "password"
$form->add('label', 'label_password', 'password', 'Choose a password:');
$obj = $form->add('password', 'password');
$obj->set_rule(array(
'required' => array('error', 'Password is required!'),
'length' => array(6, 10, 'error', 'The password must have between 6 and 10 characters'),
));
$form->add('note', 'note_password', 'password', 'Password must be have between 6 and 10 characters.', array('style' => 'width: 180px'));
// "confirm password"
$form->add('label', 'label_confirm_password', 'confirm_password', 'Confirm password:');
$obj = $form->add('password', 'confirm_password');
$obj->set_rule(array(
'compare' => array('password', 'error', 'Password not confirmed correctly!')
));
// "captcha"
$form->add('captcha', 'captcha_image', 'captcha_code');
$form->add('label', 'label_captcha_code', 'captcha_code', 'Are you human?');
$obj = $form->add('text', 'captcha_code');
$form->add('note', 'note_captcha', 'captcha_code', 'You must enter the characters with black color that stand
out from the other characters', array('style'=>'width: 200px'));
$obj->set_rule(array(
'required' => array('error', 'Enter the characters from the image above!'),
'captcha' => array('error', 'Characters from image entered incorrectly!')
));
// "submit"
$form->add('submit', 'btnsubmit', 'Submit');
// if the form is valid
if ($form->validate()) {
// show results
show_results();
// otherwise
} else
// generate output using a custom template
$form->render('includes/custom-templates/registration.php');
?>

View File

@@ -0,0 +1,86 @@
<h2>A registration form</h2>
<?php
// include the Zebra_Form class
require '../Zebra_Form.php';
// instantiate a Zebra_Form object
$form = new Zebra_Form('form', 'post', '', array('autocomplete' => 'off'));
// the label for the "first name" element
$form->add('label', 'label_firstname', 'firstname', 'First name:');
// add the "first name" element
$obj = $form->add('text', 'firstname');
// set rules
$obj->set_rule(array(
// error messages will be sent to a variable called "error", usable in custom templates
'required' => array('error', 'First name is required!'),
));
// "last name"
$form->add('label', 'label_lastname', 'lastname', 'Last name:');
$obj = $form->add('text', 'lastname');
$obj->set_rule(array(
'required' => array('error', 'Last name is required!')
));
// "email"
$form->add('label', 'label_email', 'email', 'Email address:');
$obj = $form->add('text', 'email');
$obj->set_rule(array(
'required' => array('error', 'Email is required!'),
'email' => array('error', 'Email address seems to be invalid!')
));
// attach a note to the email element
$form->add('note', 'note_email', 'email', 'Please enter a valid email address. An email will be sent to this
address with a link you need to click on in order to activate your account', array('style'=>'width:200px'));
// "password"
$form->add('label', 'label_password', 'password', 'Choose a password:');
$obj = $form->add('password', 'password');
$obj->set_rule(array(
'required' => array('error', 'Password is required!'),
'length' => array(6, 10, 'error', 'The password must have between 6 and 10 characters'),
));
$form->add('note', 'note_password', 'password', 'Password must be have between 6 and 10 characters.');
// "confirm password"
$form->add('label', 'label_confirm_password', 'confirm_password', 'Confirm password:');
$obj = $form->add('password', 'confirm_password');
$obj->set_rule(array(
'compare' => array('password', 'error', 'Password not confirmed correctly!')
));
// "captcha"
$form->add('captcha', 'captcha_image', 'captcha_code');
$form->add('label', 'label_captcha_code', 'captcha_code', 'Are you human?');
$obj = $form->add('text', 'captcha_code');
$form->add('note', 'note_captcha', 'captcha_code', 'You must enter the characters with black color that stand
out from the other characters', array('style'=>'width: 200px'));
$obj->set_rule(array(
'required' => array('error', 'Enter the characters from the image above!'),
'captcha' => array('error', 'Characters from image entered incorrectly!')
));
// "submit"
$form->add('submit', 'btnsubmit', 'Submit');
// if the form is valid
if ($form->validate()) {
// show results
show_results();
// otherwise
} else
// generate output using a custom template
$form->render('*horizontal');
?>

View File

@@ -0,0 +1,86 @@
<h2>A registration form</h2>
<?php
// include the Zebra_Form class
require '../Zebra_Form.php';
// instantiate a Zebra_Form object
$form = new Zebra_Form('form', 'post', '', array('autocomplete' => 'off'));
// the label for the "first name" element
$form->add('label', 'label_firstname', 'firstname', 'First name:');
// add the "first name" element
$obj = $form->add('text', 'firstname');
// set rules
$obj->set_rule(array(
// error messages will be sent to a variable called "error", usable in custom templates
'required' => array('error', 'First name is required!'),
));
// "last name"
$form->add('label', 'label_lastname', 'lastname', 'Last name:');
$obj = $form->add('text', 'lastname');
$obj->set_rule(array(
'required' => array('error', 'Last name is required!')
));
// "email"
$form->add('label', 'label_email', 'email', 'Email address:');
$obj = $form->add('text', 'email');
$obj->set_rule(array(
'required' => array('error', 'Email is required!'),
'email' => array('error', 'Email address seems to be invalid!')
));
// attach a note to the email element
$form->add('note', 'note_email', 'email', 'Please enter a valid email address. An email will be sent to this
address with a link you need to click on in order to activate your account', array('style'=>'width:200px'));
// "password"
$form->add('label', 'label_password', 'password', 'Choose a password:');
$obj = $form->add('password', 'password');
$obj->set_rule(array(
'required' => array('error', 'Password is required!'),
'length' => array(6, 10, 'error', 'The password must have between 6 and 10 characters'),
));
$form->add('note', 'note_password', 'password', 'Password must be have between 6 and 10 characters.');
// "confirm password"
$form->add('label', 'label_confirm_password', 'confirm_password', 'Confirm password:');
$obj = $form->add('password', 'confirm_password');
$obj->set_rule(array(
'compare' => array('password', 'error', 'Password not confirmed correctly!')
));
// "captcha"
$form->add('captcha', 'captcha_image', 'captcha_code');
$form->add('label', 'label_captcha_code', 'captcha_code', 'Are you human?');
$obj = $form->add('text', 'captcha_code');
$form->add('note', 'note_captcha', 'captcha_code', 'You must enter the characters with black color that stand
out from the other characters', array('style'=>'width: 200px'));
$obj->set_rule(array(
'required' => array('error', 'Enter the characters from the image above!'),
'captcha' => array('error', 'Characters from image entered incorrectly!')
));
// "submit"
$form->add('submit', 'btnsubmit', 'Submit');
// if the form is valid
if ($form->validate()) {
// show results
show_results();
// otherwise
} else
// generate output using a custom template
$form->render();
?>

View File

@@ -0,0 +1,116 @@
<h2>A meeting room reservation form</h2>
<p>All fields will be automatically filled with random values - very useful for when debugging forms. The random values will obey the rules set for each element!</p>
<?php
// include the Zebra_Form class
require '../Zebra_Form.php';
// instantiate a Zebra_Form object
$form = new Zebra_Form('form');
// auto-fill fields with random values
// very useful for when debugging forms
$form->auto_fill();
// the label for the "name" element
$form->add('label', 'label_name', 'name', 'Your name:');
// add the "name" element
$obj = $form->add('text', 'name');
// set rules
$obj->set_rule(array(
// error messages will be sent to a variable called "error", usable in custom templates
'required' => array('error', 'Name is required!')
));
// "email"
$form->add('label', 'label_email', 'email', 'Your email address:');
$obj = $form->add('text', 'email');
$obj->set_rule(array(
'required' => array('error', 'Email is required!'),
'email' => array('error', 'Email address seems to be invalid!'),
));
// "department"
$form->add('label', 'label_department', 'department', 'Department:');
$obj = $form->add('select', 'department', '', array('other' => true));
$obj->add_options(array(
'Marketing',
'Operations',
'Customer Service',
'Human Resources',
'Sales Department',
'Accounting Department',
'Legal Department',
));
$obj->set_rule(array(
'required' => array('error', 'Department is required!')
));
// "room"
$form->add('label', 'label_room', 'room', 'Which room would you like to reserve:');
$obj = $form->add('radios', 'room', array(
'A' => 'Room A',
'B' => 'Room B',
'C' => 'Room C',
));
$obj->set_rule(array(
'required' => array('error', 'Room selection is required!')
));
// "extra"
$form->add('label', 'label_extra', 'extra', 'Extra requirements:');
$obj = $form->add('checkboxes', 'extra[]', array(
'flipchard' => 'Flipchard and pens',
'plasma' => 'Plasma TV screen',
'beverages' => 'Coffee, tea and mineral water',
));
// "date"
$form->add('label', 'label_date', 'date', 'Reservation date');
$date = $form->add('date', 'date');
$date->set_rule(array(
'required' => array('error', 'Date is required!'),
'date' => array('error', 'Date is invalid!'),
));
// date format
// don't forget to use $date->get_date() if the form is valid to get the date in YYYY-MM-DD format ready to be used
// in a database or with PHP's strtotime function!
$date->format('M d, Y');
$form->add('note', 'note_date', 'date', 'Date format is M d, Y');
// "time"
$form->add('label', 'label_time', 'time', 'Reservation time :');
$obj = $form->add('time', 'time', '', array(
'format' => 'hm',
'hours' => array(9, 10, 11, 12, 13, 14, 15, 16, 17),
'minutes' => array(0, 30),
));
$obj->set_rule(array(
'required' => array('error', 'Time is required!'),
));
// "submit"
$form->add('submit', 'btnsubmit', 'Submit');
// if the form is valid
if ($form->validate()) {
// show results
show_results();
// otherwise
} else
// generate output using a custom template
$form->render();
?>

View File

@@ -0,0 +1,110 @@
<h2>A meeting room reservation form</h2>
<p>Check the "Template source" tab to see how it's done!</p>
<?php
// include the Zebra_Form class
require '../Zebra_Form.php';
// instantiate a Zebra_Form object
$form = new Zebra_Form('form');
// the label for the "name" element
$form->add('label', 'label_name', 'name', 'Your name:');
// add the "name" element
$obj = $form->add('text', 'name');
// set rules
$obj->set_rule(array(
// error messages will be sent to a variable called "error", usable in custom templates
'required' => array('error', 'Name is required!')
));
// "email"
$form->add('label', 'label_email', 'email', 'Your email address:');
$obj = $form->add('text', 'email');
$obj->set_rule(array(
'required' => array('error', 'Email is required!'),
'email' => array('error', 'Email address seems to be invalid!'),
));
// "department"
$form->add('label', 'label_department', 'department', 'Department:');
$obj = $form->add('select', 'department', '', array('other' => true));
$obj->add_options(array(
'Marketing',
'Operations',
'Customer Service',
'Human Resources',
'Sales Department',
'Accounting Department',
'Legal Department',
));
$obj->set_rule(array(
'required' => array('error', 'Department is required!')
));
// "room"
$form->add('label', 'label_room', 'room', 'Which room would you like to reserve:');
$obj = $form->add('radios', 'room', array(
'A' => 'Room A',
'B' => 'Room B',
'C' => 'Room C',
));
$obj->set_rule(array(
'required' => array('error', 'Room selection is required!')
));
// "extra"
$form->add('label', 'label_extra', 'extra', 'Extra requirements:');
$obj = $form->add('checkboxes', 'extra[]', array(
'flipchard' => 'Flipchard and pens',
'plasma' => 'Plasma TV screen',
'beverages' => 'Coffee, tea and mineral water',
));
// "date"
$form->add('label', 'label_date', 'date', 'Reservation date');
$date = $form->add('date', 'date');
$date->set_rule(array(
'required' => array('error', 'Date is required!'),
'date' => array('error', 'Date is invalid!'),
));
// date format
// don't forget to use $date->get_date() if the form is valid to get the date in YYYY-MM-DD format ready to be used
// in a database or with PHP's strtotime function!
$date->format('M d, Y');
// selectable dates are starting with the current day
$date->direction(1);
$form->add('note', 'note_date', 'date', 'Date format is M d, Y');
// "time"
$form->add('label', 'label_time', 'time', 'Reservation time :');
$form->add('time', 'time', '', array(
'hours' => array(9, 10, 11, 12, 13, 14, 15, 16, 17),
'minutes' => array(0, 30),
));
// "submit"
$form->add('submit', 'btnsubmit', 'Submit');
// if the form is valid
if ($form->validate()) {
// show results
show_results();
// otherwise
} else
// generate output using a custom template
$form->render('includes/custom-templates/reservation.php');
?>

View File

@@ -0,0 +1,108 @@
<h2>A meeting room reservation form</h2>
<?php
// include the Zebra_Form class
require '../Zebra_Form.php';
// instantiate a Zebra_Form object
$form = new Zebra_Form('form');
// the label for the "name" element
$form->add('label', 'label_name', 'name', 'Your name:');
// add the "name" element
$obj = $form->add('text', 'name');
// set rules
$obj->set_rule(array(
// error messages will be sent to a variable called "error", usable in custom templates
'required' => array('error', 'Name is required!')
));
// "email"
$form->add('label', 'label_email', 'email', 'Your email address:');
$obj = $form->add('text', 'email');
$obj->set_rule(array(
'required' => array('error', 'Email is required!'),
'email' => array('error', 'Email address seems to be invalid!'),
));
// "department"
$form->add('label', 'label_department', 'department', 'Department:');
$obj = $form->add('select', 'department', '', array('other' => true));
$obj->add_options(array(
'Marketing',
'Operations',
'Customer Service',
'Human Resources',
'Sales Department',
'Accounting Department',
'Legal Department',
));
$obj->set_rule(array(
'required' => array('error', 'Department is required!')
));
// "room"
$form->add('label', 'label_room', 'room', 'Which room would you like to reserve:');
$obj = $form->add('radios', 'room', array(
'A' => 'Room A',
'B' => 'Room B',
'C' => 'Room C',
));
$obj->set_rule(array(
'required' => array('error', 'Room selection is required!')
));
// "extra"
$form->add('label', 'label_extra', 'extra', 'Extra requirements:');
$obj = $form->add('checkboxes', 'extra[]', array(
'flipchard' => 'Flipchard and pens',
'plasma' => 'Plasma TV screen',
'beverages' => 'Coffee, tea and mineral water',
));
// "date"
$form->add('label', 'label_date', 'date', 'Reservation date');
$date = $form->add('date', 'date');
$date->set_rule(array(
'required' => array('error', 'Date is required!'),
'date' => array('error', 'Date is invalid!'),
));
// date format
// don't forget to use $date->get_date() if the form is valid to get the date in YYYY-MM-DD format ready to be used
// in a database or with PHP's strtotime function!
$date->format('M d, Y');
// selectable dates are starting with the current day
$date->direction(1);
$form->add('note', 'note_date', 'date', 'Date format is M d, Y');
// "time"
$form->add('label', 'label_time', 'time', 'Reservation time :');
$form->add('time', 'time', '', array(
'hours' => array(9, 10, 11, 12, 13, 14, 15, 16, 17),
'minutes' => array(0, 30),
));
// "submit"
$form->add('submit', 'btnsubmit', 'Submit');
// if the form is valid
if ($form->validate()) {
// show results
show_results();
// otherwise
} else
// generate output using a custom template
$form->render('*horizontal');
?>

View File

@@ -0,0 +1,110 @@
<h2>A meeting room reservation form</h2>
<?php
// include the Zebra_Form class
require '../Zebra_Form.php';
// instantiate a Zebra_Form object
$form = new Zebra_Form('form');
// the label for the "name" element
$form->add('label', 'label_name', 'name', 'Your name:');
// add the "name" element
$obj = $form->add('text', 'name');
// set rules
$obj->set_rule(array(
// error messages will be sent to a variable called "error", usable in custom templates
'required' => array('error', 'Name is required!')
));
// "email"
$form->add('label', 'label_email', 'email', 'Your email address:');
$obj = $form->add('text', 'email');
$obj->set_rule(array(
'required' => array('error', 'Email is required!'),
'emails' => array('error', 'Email address seems to be invalid!'),
));
// "department"
$form->add('label', 'label_department', 'department', 'Department:');
$obj = $form->add('select', 'department', '', array('other' => true));
$obj->add_options(array(
'Marketing',
'Operations',
'Customer Service',
'Human Resources',
'Sales Department',
'Accounting Department',
'Legal Department',
));
$obj->set_rule(array(
'required' => array('error', 'Department is required!')
));
// "room"
$form->add('label', 'label_room', 'room', 'Which room would you like to reserve:');
$obj = $form->add('radios', 'room', array(
'A' => 'Room A',
'B' => 'Room B',
'C' => 'Room C',
));
$obj->set_rule(array(
'required' => array('error', 'Room selection is required!')
));
// "extra"
$form->add('label', 'label_extra', 'extra', 'Extra requirements:');
$obj = $form->add('checkboxes', 'extra[]', array(
'flipchard' => 'Flipchard and pens',
'plasma' => 'Plasma TV screen',
'beverages' => 'Coffee, tea and mineral water',
));
// "date"
$form->add('label', 'label_date', 'date', 'Reservation date');
$date = $form->add('date', 'date');
$date->set_rule(array(
'required' => array('error', 'Date is required!'),
'date' => array('error', 'Date is invalid!'),
));
// date format
// don't forget to use $date->get_date() if the form is valid to get the date in YYYY-MM-DD format ready to be used
// in a database or with PHP's strtotime function!
$date->format('M d, Y');
$form->add('note', 'note_date', 'date', 'Date format is M d, Y');
// "time"
$form->add('label', 'label_time', 'time', 'Reservation time :');
$obj = $form->add('time', 'time', '', array(
'format' => 'hm',
'hours' => array(9, 10, 11, 12, 13, 14, 15, 16, 17),
'minutes' => array(0, 30),
));
$obj->set_rule(array(
'required' => array('error', 'Time is required!'),
));
// "submit"
$form->add('submit', 'btnsubmit', 'Submit');
// if the form is valid
if ($form->validate()) {
// show results
show_results();
// otherwise
} else
// generate output using a custom template
$form->render();
?>

View File

@@ -0,0 +1,107 @@
<h2>More validation rules</h2>
<?php
// include the Zebra_Form class
require '../Zebra_Form.php';
// instantiate a Zebra_Form object
$form = new Zebra_Form('form');
// "alphabet"
$form->add('label', 'label_alphabet', 'alphabet', 'Alphabet:');
$obj = $form->add('text', 'alphabet');
// set rules
$obj->set_rule(array(
// error messages will be sent to a variable called "error", usable in custom templates
'required' => array('error', 'This field is required!'),
'alphabet' => array('', 'error', 'Accepts only characters from the alphabet (case-insensitive a to z)')
));
// attach a note
$form->add('note', 'note_alphabet', 'alphabet', 'Accepts only characters from the alphabet (case-insensitive a to z)');
// "alphanumeric"
$form->add('label', 'label_alphanumeric', 'alphanumeric', 'Alphanumeric:');
$obj = $form->add('text', 'alphanumeric');
$obj->set_rule(array(
'required' => array('error', 'This field is required!'),
'alphanumeric' => array('', 'error', 'Accepts only characters from the alphabet (case-insensitive a to z) and digits (0 to 9)')
));
$form->add('note', 'note_alphanumeric', 'alphanumeric', 'Accepts only characters from the alphabet (case-insensitive a to z) and digits (0 to 9)');
// "digits"
$form->add('label', 'label_digits', 'digits', 'Digits:');
$obj = $form->add('text', 'digits');
$obj->set_rule(array(
'required' => array('error', 'This field is required!'),
'digits' => array('', 'error', 'Accepts only digits (0 to 9)')
));
$form->add('note', 'note_digits', 'digits', 'Accepts only digits (0 to 9)');
// "float"
$form->add('label', 'label_float', 'float', 'Float:');
$obj = $form->add('text', 'float');
$obj->set_rule(array(
'required' => array('error', 'This field is required!'),
'float' => array('', 'error', 'Accepts only digits (0 to 9) and/or one dot (but not as the very first character) and/or one minus sign (but only if it is the very first character)')
));
$form->add('note', 'note_float', 'float', 'Accepts only digits (0 to 9) and/or one dot (but not as the very first character) and/or one minus sign (but only if it is the very first character)');
// "length"
$form->add('label', 'label_length', 'length', 'Length:');
$obj = $form->add('text', 'length');
$obj->set_rule(array(
'required' => array('error', 'This field is required!'),
'length' => array(6, 12, 'error', 'Must contain between 6 and 12 characters!')
));
$form->add('note', 'note_length', 'length', 'Must contain between 6 and 12 characters');
// "number"
$form->add('label', 'label_number', 'number', 'Number:');
$obj = $form->add('text', 'number');
$obj->set_rule(array(
'required' => array('error', 'This field is required!'),
'number' => array('', 'error', 'Accepts only digits (0 to 9) and/or one minus sign (but only if it is the very first character)')
));
$form->add('note', 'note_number', 'number', 'Accepts only digits (0 to 9) and/or one minus sign (but only if it is the very first character)');
// "regular expression"
$form->add('label', 'label_regexp', 'regexp', 'Regular expression:');
$obj = $form->add('text', 'regexp');
$obj->set_rule(array(
'required' => array('error', 'This field is required!'),
'regexp' => array('^07[0-9]{8}$', 'error', 'Validates only if the value matches the following regular expression: ^07[0-9]{8}$')
));
$form->add('note', 'note_regexp', 'regexp', 'Validates if the value satisfies the following regular expression: ^07[0-9]{8}$');
// "change case"
$form->add('label', 'label_case', 'case', 'Change case:');
$obj = $form->add('text', 'case');
$obj->set_rule(array(
'required' => array('error', 'This field is required!'),
));
// force all characters to be upper-case
$obj->change_case('upper');
$form->add('note', 'note_case', 'case', 'All entered characters will be upper-case');
// "submit"
$form->add('submit', 'btnsubmit', 'Submit');
// if the form is valid
if ($form->validate()) {
// show results
show_results();
// otherwise
} else
// generate output using a custom template
$form->render();
?>

View File

@@ -0,0 +1,8 @@
<html>
<head>
<title>403 Forbidden</title>
</head>
<body>
<p>Directory access is forbidden.</p>
</body>
</html>

View File

@@ -0,0 +1,310 @@
<?php
error_reporting(E_ALL);
session_start()
?>
<?php
/**
* Dumps information about a variable in a human readable format
*
* @param mixed $variable Variable to print information about
*
* @param boolean $stop Whether to stop script execution after outputting the variable.
*
* Default is FALSE
*
* @return void
*/
function dump()
{
// get the arguments passed to the function
$arguments = func_get_args();
// if last argument is boolean TRUE
if ($arguments[count($arguments) - 1] === true)
// set a flag telling the script that it needs to die() after output
$stop = array_pop($arguments);
// iterate through the arguments
foreach ($arguments as $argument) {
// print each argument
print_r('<pre style="text-align:left">');
print_r($argument);
print_r('</pre>');
}
// if script needs to die() after output, die
if (isset($stop)) die();
}
?>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Zebra_Form, a jQuery augmented PHP library for HTML form building and validation</title>
<link rel="stylesheet" href="libraries/highlight/public/css/ir_black.css" type="text/css">
<link rel="stylesheet" href="public/css/reset.css" type="text/css">
<link rel="stylesheet" href="public/css/style.css" type="text/css">
<link rel="stylesheet" href="../public/css/zebra_form.css" type="text/css">
</head>
<body>
<div class="header"><a href="http://stefangabos.ro/">Stefan Gabos | <span>webdeveloper</span></a></div>
<div class="example">
Example for: <a href="http://stefangabos.ro/php-libraries/zebra-form/">Zebra_Form, a jQuery augmented PHP
library for HTML form building and validation</a>
</div>
<table>
<tr>
<td valign="top">
<?php
function show_results() {
echo '<table class="results"><thead><tr><td colspan="2">Submitted values</td></tr></thead>';
foreach ($_POST as $key => $value) {
if (strpos($key, 'name_') !== 0 && strpos($key, 'timer_') !== 0 && strpos($key, 'response_') !== 0)
echo '<tr><th>' . $key . '</th><td>' . (is_array($value) ? '<pre>' . print_r($value, true) . '</pre>' : $value) . '</td></tr>';
}
echo '</table>';
}
$demos = array(
'A login form' => array('login', array(
'Auto template, vertical' => 'vertical',
'Auto template, horizontal' => 'horizontal',
'Auto template, labels inside' => 'labels-inside',
'Custom template - divs' => 'divs-custom',
'Custom template - tables' => 'tables-custom',
)),
'A contact form' => array('contact', array(
'Auto template, vertical' => 'vertical',
'Auto template, horizontal' => 'horizontal',
'Custom template' => 'custom',
)),
'A registration form' => array('registration', array(
'Auto template, vertical' => 'vertical',
'Auto template, horizontal' => 'horizontal',
'Custom template' => 'custom',
)),
'A reservation form' => array('reservation', array(
'Auto template, vertical' => 'vertical',
'Auto template, horizontal' => 'horizontal',
'Custom template' => 'custom',
'Auto-fill' => 'autofill-vertical',
)),
'Dependencies' => array('dependencies', array(
'Example 1' => 'example1-custom',
'Example 2' => 'example2-custom',
)),
'File upload' => array('fileupload', array(
'Basic file upload' => 'basic-vertical',
'Basic image upload' => 'basic-image-vertical',
)),
'More rules' => array('validation', array(
'Auto template, vertical' => 'vertical',
)),
);
$current_template = isset($_GET['template']) ? strtolower($_GET['template']) : '';
if (isset($_GET['example']) && is_file('includes/' . $_GET['example'] . '-' . $current_template . '.php')) {
$current_example = strtolower($_GET['example']);
} else {
$current_template = 'vertical';
$current_example = 'login';
}
?>
<ul class="navigation default">
<?php foreach ($demos as $title => $values):?>
<li><?php echo $title?>
<ul>
<?php foreach ($values[1] as $example => $template):?>
<li>
<a href="?example=<?php echo $values[0]?>&amp;template=<?php echo $template?>"<?php echo ($current_example == $values[0] && $current_template == $template ? ' class="selected"' : '')?>><?php echo $example?></a>
</li>
<?php endforeach?>
</ul>
</li>
<?php endforeach?>
</ul>
</td>
<td valign="top">
<?php if ($example != ''):?>
<ul class="tabs float clearfix">
<li><a href="javascript:void(0)" class="selected">Demo</a></li>
<li><a href="javascript:void(0)">PHP source</a></li>
<li><a href="javascript:void(0)">Template source</a></li>
<li><a href="javascript:void(0)">Container HTML</a></li>
</ul>
<?php for ($i = 0; $i < 5; $i++):?>
<div class="tab clearfix"<?php echo $i == 0 ? ' style="display:block"' : ''?>>
<?php if ($i == 0):?>
<?php require 'includes/' . $current_example . '-' . $current_template . '.php'?>
<?php elseif ($i == 1):?>
<?php
$php_source = file_get_contents('includes/' . $current_example . '-' . $current_template . '.php');
$patterns = array(
'/^.*?\<\?php/is',
'/require \'.*?Zebra\_Form\.php\'/',
'/\$form\-\>render\(\'includes\/custom\-templates\/.*?\'\)\;/',
);
$replacements = array(
'<?php',
'require \'path/to/Zebra_Form.php\'',
'$form->render(\'path/to/custom-template.php\');',
);
$php_source = preg_replace($patterns, $replacements, $php_source);
?>
<pre><code><?php
echo trim(htmlentities($php_source));
?></code></pre>
<?php elseif ($i == 2):?>
<?php if (strpos($current_template, 'custom') === false):?>
<p>In this example, the output is automatically generated by Zebra_Form's <strong>render</strong> method.</p>
<?php elseif (is_file('includes/custom-templates/' . str_replace('custom-', '', $current_template . '-' . $current_example) . '.php')):?>
<pre><code><?php
echo trim(htmlentities(file_get_contents('includes/custom-templates/' . str_replace('custom-', '', $current_template . '-' . $current_example) . '.php')));
?></code></pre>
<?php else:?>
<?php echo 'includes/custom-templates/' . str_replace('custom-', '', $current_template . '-' . $current_example) . '.php' ?>
<?php endif?>
<?php elseif ($i == 3):?>
<?php
$html_container_source = file_get_contents('includes/container-html/container.html');
?>
<pre><code><?php
echo trim(htmlentities($html_container_source));
?></code></pre>
<?php endif?>
<?php if ($i == 0):?>
<ul class="notes default">
<li>
try clicking on the submit button without filling the form and then, as you fill the form, to see the
JavaScript validation in action
</li>
<li>for each example, notice how the PHP code of the form remains basically unchanged, despite the template variations</li>
<li>
disable JavaScript to see the server-side validation in action
</li>
<li>
although in all my examples I use HTML output, you can switch to XHTML output by using the
<strong>doctye</strong> method
</li>
<li>
try the example in another browser and see that it works, out of the box. including IE6!
</li>
</ul>
<?php endif?>
</div>
<?php endfor?>
<?php else:?>
Use the links to the left to navigate between examples.
<?php endif?>
</td>
</tr>
</table>
<div class="clear"></div>
<script type="text/javascript" src="libraries/highlight/public/javascript/highlight.js"></script>
<script type="text/javascript" src="public/javascript/jquery-1.12.0.js"></script>
<script type="text/javascript" src="../public/javascript/zebra_form.js"></script>
<script type="text/javascript" src="public/javascript/core.js"></script>
</body>
</html>

View File

@@ -0,0 +1,38 @@
Syntax highlighting with language autodetection.
URL: http://softwaremaniacs.org/soft/highlight/en/
Original author and current maintainer:
Ivan Sagalaev <Maniac@SoftwareManiacs.Org>
Contributors:
- Peter Leonov <gojpeg@gmail.com>
- Victor Karamzin <Victor.Karamzin@enterra-inc.com>
- Vsevolod Solovyov <vsevolod.solovyov@gmail.com>
- Anton Kovalyov <anton@kovalyov.net>
- Nikita Ledyaev <lenikita@yandex.ru>
- Konstantin Evdokimenko <qewerty@gmail.com>
- Dmitri Roudakov <dmitri@roudakov.ru>
- Yuri Ivanov <ivanov@supersoft.ru>
- Vladimir Ermakov <vooon341@mail.ru>
- Vladimir Gubarkov <xonixx@gmail.com>
- Brian Beck <exogen@gmail.com>
- MajestiC <majestic2k@gmail.com>
- Vasily Polovnyov <vast@whiteants.net>
- Vladimir Epifanov <voldmar@voldmar.ru>
- Alexander Makarov (http://rmcreative.ru/)
- Vah <vahtenberg@gmail.com>
- Shuen-Huei Guan <drake.guan@gmail.com>
- Jason Diamond <jason@diamond.name>
- Michal Gabrukiewicz <mgabru@gmail.com>
- Ruslan Keba <rukeba@gmail.com>
- Sergey Baranov <segyrn@yandex.ru>
- Zaripov Yura <yur4ik7@ukr.net>
- Oleg Volchkov <oleg@volchkov.net>
- Vasily Mikhailitchenko <vaskas@programica.ru>
- Jan Berkel <jan.berkel@gmail.com>
- Vladimir Moskva <vladmos@gmail.com>
- Loren Segal <lsegal@soen.ca>
- Andrew Fedorov <dmmdrs@mail.ru>
- Igor Kalnitsky <igor.kalnitsky@gmail.com>

View File

@@ -0,0 +1,24 @@
Copyright (c) 2006, Ivan Sagalaev
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of highlight.js nor the names of its contributors
may be used to endorse or promote products derived from this software
without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

View File

@@ -0,0 +1,100 @@
/*
Dark style from softwaremaniacs.org (c) Ivan Sagalaev <Maniac@SoftwareManiacs.Org>
*/
pre code {
display: block; padding: 0.5em;
background: #444;
}
pre .keyword,
pre .literal,
pre .change,
pre .winutils,
pre .flow,
pre .lisp .title,
pre .tex .special {
color: white;
}
pre code,
pre .ruby .subst {
color: #DDD;
}
pre .string,
pre .function .title,
pre .class .title,
pre .ini .title,
pre .tag .value,
pre .css .rules .value,
pre .preprocessor,
pre .ruby .symbol,
pre .ruby .symbol .string,
pre .ruby .symbol .keyword,
pre .ruby .symbol .keymethods,
pre .ruby .instancevar,
pre .ruby .class .parent,
pre .built_in,
pre .sql .aggregate,
pre .django .template_tag,
pre .django .variable,
pre .smalltalk .class,
pre .javadoc,
pre .ruby .string,
pre .django .filter .argument,
pre .smalltalk .localvars,
pre .smalltalk .array,
pre .attr_selector,
pre .pseudo,
pre .addition,
pre .stream,
pre .envvar,
pre .apache .tag,
pre .apache .cbracket,
pre .tex .command {
color: #D88;
}
pre .comment,
pre .java .annotation,
pre .python .decorator,
pre .template_comment,
pre .pi,
pre .doctype,
pre .deletion,
pre .shebang,
pre .apache .sqbracket,
pre .tex .formula {
color: #777;
}
pre .keyword,
pre .literal,
pre .css .id,
pre .phpdoc,
pre .function .title,
pre .class .title,
pre .vbscript .built_in,
pre .sql .aggregate,
pre .rsl .built_in,
pre .smalltalk .class,
pre .xml .tag .title,
pre .diff .header,
pre .chunk,
pre .winutils,
pre .bash .variable,
pre .lisp .title,
pre .apache .tag,
pre .tex .special {
font-weight: bold;
}
pre .html .css,
pre .html .javascript,
pre .html .vbscript,
pre .tex .formula {
opacity: 0.5;
}

View File

@@ -0,0 +1,115 @@
/*
Original style from softwaremaniacs.org (c) Ivan Sagalaev <Maniac@SoftwareManiacs.Org>
*/
pre code {
display: block; padding: 0.5em;
background: #F0F0F0;
}
pre code,
pre .ruby .subst,
pre .tag .title,
pre .lisp .title {
color: black;
}
pre .string,
pre .title,
pre .constant,
pre .parent,
pre .tag .value,
pre .rules .value,
pre .rules .value .number,
pre .preprocessor,
pre .ruby .symbol,
pre .ruby .symbol .string,
pre .ruby .symbol .keyword,
pre .ruby .symbol .keymethods,
pre .instancevar,
pre .aggregate,
pre .template_tag,
pre .django .variable,
pre .smalltalk .class,
pre .addition,
pre .flow,
pre .stream,
pre .bash .variable,
pre .apache .tag,
pre .apache .cbracket,
pre .tex .command,
pre .tex .special {
color: #800;
}
pre .comment,
pre .annotation,
pre .template_comment,
pre .diff .header,
pre .chunk {
color: #888;
}
pre .number,
pre .date,
pre .regexp,
pre .literal,
pre .smalltalk .symbol,
pre .smalltalk .char,
pre .change {
color: #080;
}
pre .label,
pre .javadoc,
pre .ruby .string,
pre .decorator,
pre .filter .argument,
pre .localvars,
pre .array,
pre .attr_selector,
pre .important,
pre .pseudo,
pre .pi,
pre .doctype,
pre .deletion,
pre .envvar,
pre .shebang,
pre .apache .sqbracket,
pre .nginx .built_in,
pre .tex .formula {
color: #88F;
}
pre .javadoctag,
pre .phpdoc,
pre .yardoctag {
font-weight: bold;
}
pre .keyword,
pre .id,
pre .phpdoc,
pre .title,
pre .built_in,
pre .aggregate,
pre .smalltalk .class,
pre .winutils,
pre .bash .variable,
pre .apache .tag,
pre .tex .command {
font-weight: bold;
}
pre .nginx .built_in {
font-weight: normal;
}
pre .html .css,
pre .html .javascript,
pre .html .vbscript,
pre .tex .formula {
opacity: 0.5;
}

View File

@@ -0,0 +1,103 @@
/*
IR_Black style (c) Vasily Mikhailitchenko <vaskas@programica.ru>
*/
pre code {
display: block; padding: 0.5em;
background: #222; color: #f8f8f8;
font-size: 11px
}
pre .shebang,
pre .comment,
pre .template_comment,
pre .javadoc {
color: #7c7c7c;
}
pre .keyword,
pre .tag,
pre .ruby .function .keyword,
pre .tex .command {
color: #96CBFE;
}
pre .function .keyword,
pre .sub .keyword,
pre .method,
pre .list .title {
color: #FFFFB6;
}
pre .string,
pre .tag .value,
pre .cdata,
pre .filter .argument,
pre .attr_selector,
pre .apache .cbracket,
pre .date {
color: #A8FF60;
}
pre .subst {
color: #DAEFA3;
}
pre .regexp {
color: #E9C062;
}
pre .function .title,
pre .sub .identifier,
pre .pi,
pre .decorator,
pre .ini .title,
pre .tex .special {
color: #FFFFB6;
}
pre .class .title,
pre .constant,
pre .smalltalk .class,
pre .javadoctag,
pre .yardoctag,
pre .phpdoc,
pre .nginx .built_in {
color: #FFFFB6;
}
pre .symbol,
pre .ruby .symbol .string,
pre .ruby .symbol .keyword,
pre .ruby .symbol .keymethods,
pre .number,
pre .variable,
pre .vbscript,
pre .literal {
color: #C6C5FE;
}
pre .css .keyword {
color: #96CBFE;
}
pre .css .rule .keyword,
pre .css .id {
color: #FFFFB6;
}
pre .css .class {
color: #FFF;
}
pre .hexcolor {
color: #C6C5FE;
}
pre .number {
color:#FF73FD;
}
pre .tex .formula {
opacity: 0.7;
}

View File

@@ -0,0 +1,145 @@
/*
Sunburst-like style (c) Vasily Polovnyov <vast@whiteants.net>
*/
pre code {
display: block; padding: 0.5em;
font: 1em / 1.3em 'Lucida Console', 'courier new', monospace;
background: #000; color: #f8f8f8;
}
pre .comment,
pre .template_comment,
pre .javadoc {
color: #aeaeae;
font-style: italic;
}
pre .keyword,
pre .ruby .function .keyword {
color: #E28964;
}
pre .function .keyword,
pre .sub .keyword,
pre .method,
pre .list .title {
color: #99CF50;
}
pre .string,
pre .tag .value,
pre .cdata,
pre .filter .argument,
pre .attr_selector,
pre .apache .cbracket,
pre .date,
pre .tex .command {
color: #65B042;
}
pre .subst {
color: #DAEFA3;
}
pre .regexp {
color: #E9C062;
}
pre .function .title,
pre .sub .identifier,
pre .pi,
pre .tag,
pre .tag .keyword,
pre .decorator,
pre .ini .title,
pre .shebang {
color: #89BDFF;
}
pre .class .title,
pre .smalltalk .class,
pre .javadoctag,
pre .yardoctag,
pre .phpdoc {
text-decoration: underline;
}
pre .symbol,
pre .ruby .symbol .string,
pre .ruby .symbol .keyword,
pre .ruby .symbol .keymethods,
pre .number {
color: #3387CC;
}
pre .params,
pre .variable {
color: #3E87E3;
}
pre .css .keyword,
pre .pseudo,
pre .tex .special {
color: #CDA869;
}
pre .css .class {
color: #9B703F;
}
pre .rules .keyword {
color: #C5AF75;
}
pre .rules .value {
color: #CF6A4C;
}
pre .css .id {
color: #8B98AB;
}
pre .annotation,
pre .apache .sqbracket,
pre .nginx .built_in {
color: #9B859D;
}
pre .preprocessor {
color: #8996A8;
}
pre .hexcolor,
pre .css .value .number {
color: #DD7B3B;
}
pre .css .function {
color: #DAD085;
}
pre .diff .header,
pre .chunk,
pre .tex .formula {
background-color: #0E2231;
color: #F8F8F8;
font-style: italic;
}
pre .diff .change {
background-color: #4A410D;
color: #F8F8F8;
}
pre .addition {
background-color: #253B22;
color: #F8F8F8;
}
pre .deletion {
background-color: #420E09;
color: #F8F8F8;
}

View File

@@ -0,0 +1,112 @@
/*
Zenburn style from voldmar.ru (c) Vladimir Epifanov <voldmar@voldmar.ru>
based on dark.css by Ivan Sagalaev
*/
pre code {
display: block; padding: 0.5em;
background: #3F3F3F;
color: #DCDCDC;
}
pre .keyword,
pre .tag,
pre .django .tag,
pre .django .keyword,
pre .css .class,
pre .css .id,
pre .lisp .title {
color: #E3CEAB;
}
pre .django .template_tag,
pre .django .variable,
pre .django .filter .argument {
color: #DCDCDC;
}
pre .number,
pre .date {
color: #8CD0D3;
}
pre .dos .envvar,
pre .dos .stream,
pre .variable,
pre .apache .sqbracket {
color: #EFDCBC;
}
pre .dos .flow,
pre .diff .change,
pre .python .exception,
pre .python .built_in,
pre .literal,
pre .tex .special {
color: #EFEFAF;
}
pre .diff .chunk,
pre .ruby .subst {
color: #8F8F8F;
}
pre .dos .keyword,
pre .python .decorator,
pre .class .title,
pre .function .title,
pre .ini .title,
pre .diff .header,
pre .ruby .class .parent,
pre .apache .tag,
pre .nginx .built_in,
pre .tex .command {
color: #efef8f;
}
pre .dos .winutils,
pre .ruby .symbol,
pre .ruby .symbol .string,
pre .ruby .symbol .keyword,
pre .ruby .symbol .keymethods,
pre .ruby .string,
pre .ruby .instancevar {
color: #DCA3A3;
}
pre .diff .deletion,
pre .string,
pre .tag .value,
pre .preprocessor,
pre .built_in,
pre .sql .aggregate,
pre .javadoc,
pre .smalltalk .class,
pre .smalltalk .localvars,
pre .smalltalk .array,
pre .css .rules .value,
pre .attr_selector,
pre .pseudo,
pre .apache .cbracket,
pre .tex .formula {
color: #CC9393;
}
pre .shebang,
pre .diff .addition,
pre .comment,
pre .java .annotation,
pre .template_comment,
pre .pi,
pre .doctype {
color: #7F9F7F;
}
pre .html .css,
pre .html .javascript,
pre .tex .formula {
opacity: 0.5;
}

View File

@@ -0,0 +1,90 @@
/*
Language: CSS
Requires: html-xml.js
*/
hljs.LANGUAGES.css = {
defaultMode: {
contains: ['at_rule', 'id', 'class', 'attr_selector', 'pseudo', 'rules', 'comment'],
keywords: hljs.HTML_TAGS,
lexems: [hljs.IDENT_RE],
illegal: '='
},
case_insensitive: true,
modes: [
{
className: 'at_rule',
begin: '@', end: '[{;]',
excludeEnd: true,
lexems: [hljs.IDENT_RE],
keywords: {'import': 1, 'page': 1, 'media': 1, 'charset': 1, 'font-face': 1},
contains: ['function', 'string', 'number', 'pseudo']
},
{
className: 'id',
begin: '\\#[A-Za-z0-9_-]+', end: hljs.IMMEDIATE_RE
},
{
className: 'class',
begin: '\\.[A-Za-z0-9_-]+', end: hljs.IMMEDIATE_RE,
relevance: 0
},
{
className: 'attr_selector',
begin: '\\[', end: '\\]',
illegal: '$'
},
{
className: 'pseudo',
begin: ':(:)?[a-zA-Z0-9\\_\\-\\+\\(\\)\\"\\\']+', end: hljs.IMMEDIATE_RE
},
{
className: 'rules',
begin: '{', end: '}',
contains: [
{
className: 'rule',
begin: '[A-Z\\_\\.\\-]+\\s*:', end: ';', endsWithParent: true,
lexems: ['[A-Za-z-]+'],
keywords: {'play-during': 1, 'counter-reset': 1, 'counter-increment': 1, 'min-height': 1, 'quotes': 1, 'border-top': 1, 'pitch': 1, 'font': 1, 'pause': 1, 'list-style-image': 1, 'border-width': 1, 'cue': 1, 'outline-width': 1, 'border-left': 1, 'elevation': 1, 'richness': 1, 'speech-rate': 1, 'border-bottom': 1, 'border-spacing': 1, 'background': 1, 'list-style-type': 1, 'text-align': 1, 'page-break-inside': 1, 'orphans': 1, 'page-break-before': 1, 'text-transform': 1, 'line-height': 1, 'padding-left': 1, 'font-size': 1, 'right': 1, 'word-spacing': 1, 'padding-top': 1, 'outline-style': 1, 'bottom': 1, 'content': 1, 'border-right-style': 1, 'padding-right': 1, 'border-left-style': 1, 'voice-family': 1, 'background-color': 1, 'border-bottom-color': 1, 'outline-color': 1, 'unicode-bidi': 1, 'max-width': 1, 'font-family': 1, 'caption-side': 1, 'border-right-width': 1, 'pause-before': 1, 'border-top-style': 1, 'color': 1, 'border-collapse': 1, 'border-bottom-width': 1, 'float': 1, 'height': 1, 'max-height': 1, 'margin-right': 1, 'border-top-width': 1, 'speak': 1, 'speak-header': 1, 'top': 1, 'cue-before': 1, 'min-width': 1, 'width': 1, 'font-variant': 1, 'border-top-color': 1, 'background-position': 1, 'empty-cells': 1, 'direction': 1, 'border-right': 1, 'visibility': 1, 'padding': 1, 'border-style': 1, 'background-attachment': 1, 'overflow': 1, 'border-bottom-style': 1, 'cursor': 1, 'margin': 1, 'display': 1, 'border-left-width': 1, 'letter-spacing': 1, 'vertical-align': 1, 'clip': 1, 'border-color': 1, 'list-style': 1, 'padding-bottom': 1, 'pause-after': 1, 'speak-numeral': 1, 'margin-left': 1, 'widows': 1, 'border': 1, 'font-style': 1, 'border-left-color': 1, 'pitch-range': 1, 'background-repeat': 1, 'table-layout': 1, 'margin-bottom': 1, 'speak-punctuation': 1, 'font-weight': 1, 'border-right-color': 1, 'page-break-after': 1, 'position': 1, 'white-space': 1, 'text-indent': 1, 'background-image': 1, 'volume': 1, 'stress': 1, 'outline': 1, 'clear': 1, 'z-index': 1, 'text-decoration': 1, 'margin-top': 1, 'azimuth': 1, 'cue-after': 1, 'left': 1, 'list-style-position': 1},
contains: [
{
className: 'value',
begin: hljs.IMMEDIATE_RE, endsWithParent: true, excludeEnd: true,
contains: ['function', 'number', 'hexcolor', 'string', 'important', 'comment']
}
]
},
'comment'
],
illegal: '[^\\s]'
},
hljs.C_BLOCK_COMMENT_MODE,
{
className: 'number',
begin: hljs.NUMBER_RE, end: hljs.IMMEDIATE_RE
},
{
className: 'hexcolor',
begin: '\\#[0-9A-F]+', end: hljs.IMMEDIATE_RE
},
{
className: 'function',
begin: hljs.IDENT_RE + '\\(', end: '\\)',
contains: [
{
className: 'params',
begin: hljs.IMMEDIATE_RE, endsWithParent: true, excludeEnd: true,
contains: ['number', 'string']
}
]
},
{
className: 'important',
begin: '!important', end: hljs.IMMEDIATE_RE
},
hljs.APOS_STRING_MODE,
hljs.QUOTE_STRING_MODE,
hljs.BACKSLASH_ESCAPE
]
};

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,164 @@
/*
Language: HTML, XML
*/
(function(){
var XML_IDENT_RE = '[A-Za-z0-9\\._:-]+';
var PI = {
className: 'pi',
begin: '<\\?', end: '\\?>',
relevance: 10
};
var DOCTYPE = {
className: 'doctype',
begin: '<!DOCTYPE', end: '>',
relevance: 10
};
var COMMENT = {
className: 'comment',
begin: '<!--', end: '-->'
};
var TAG = {
className: 'tag',
begin: '</?', end: '/?>',
contains: ['title', 'tag_internal']
};
var TITLE = {
className: 'title',
begin: XML_IDENT_RE, end: hljs.IMMEDIATE_RE
};
var TAG_INTERNAL = {
className: 'tag_internal',
begin: hljs.IMMEDIATE_RE, endsWithParent: true, noMarkup: true,
contains: ['attribute', 'value_container'],
relevance: 0
};
var ATTR = {
className: 'attribute',
begin: XML_IDENT_RE, end: hljs.IMMEDIATE_RE,
relevance: 0
};
var VALUE_CONTAINER_QUOT = {
className: 'value_container',
begin: '="', returnBegin: true, end: '"', noMarkup: true,
contains: [{
className: 'value',
begin: '"', endsWithParent: true
}]
};
var VALUE_CONTAINER_APOS = {
className: 'value_container',
begin: '=\'', returnBegin: true, end: '\'', noMarkup: true,
contains: [{
className: 'value',
begin: '\'', endsWithParent: true
}]
};
hljs.LANGUAGES.xml = {
defaultMode: {
contains: ['pi', 'doctype', 'comment', 'cdata', 'tag']
},
case_insensitive: true,
modes: [
{
className: 'cdata',
begin: '<\\!\\[CDATA\\[', end: '\\]\\]>',
relevance: 10
},
PI,
DOCTYPE,
COMMENT,
TAG,
hljs.inherit(TITLE, {relevance: 1.75}),
TAG_INTERNAL,
ATTR,
VALUE_CONTAINER_QUOT,
VALUE_CONTAINER_APOS
]
};
var HTML_TAGS = {
'code': 1, 'kbd': 1, 'font': 1, 'noscript': 1, 'style': 1, 'img': 1,
'title': 1, 'menu': 1, 'tt': 1, 'tr': 1, 'param': 1, 'li': 1, 'tfoot': 1,
'th': 1, 'input': 1, 'td': 1, 'dl': 1, 'blockquote': 1, 'fieldset': 1,
'big': 1, 'dd': 1, 'abbr': 1, 'optgroup': 1, 'dt': 1, 'button': 1,
'isindex': 1, 'p': 1, 'small': 1, 'div': 1, 'dir': 1, 'em': 1, 'frame': 1,
'meta': 1, 'sub': 1, 'bdo': 1, 'label': 1, 'acronym': 1, 'sup': 1, 'body': 1,
'basefont': 1, 'base': 1, 'br': 1, 'address': 1, 'strong': 1, 'legend': 1,
'ol': 1, 'script': 1, 'caption': 1, 's': 1, 'col': 1, 'h2': 1, 'h3': 1,
'h1': 1, 'h6': 1, 'h4': 1, 'h5': 1, 'table': 1, 'select': 1, 'noframes': 1,
'span': 1, 'area': 1, 'dfn': 1, 'strike': 1, 'cite': 1, 'thead': 1,
'head': 1, 'option': 1, 'form': 1, 'hr': 1, 'var': 1, 'link': 1, 'b': 1,
'colgroup': 1, 'ul': 1, 'applet': 1, 'del': 1, 'iframe': 1, 'pre': 1,
'frameset': 1, 'ins': 1, 'tbody': 1, 'html': 1, 'samp': 1, 'map': 1,
'object': 1, 'a': 1, 'xmlns': 1, 'center': 1, 'textarea': 1, 'i': 1, 'q': 1,
'u': 1, 'section': 1, 'nav': 1, 'article': 1, 'aside': 1, 'hgroup': 1,
'header': 1, 'footer': 1, 'figure': 1, 'figurecaption': 1, 'time': 1,
'mark': 1, 'wbr': 1, 'embed': 1, 'video': 1, 'audio': 1, 'source': 1,
'canvas': 1, 'datalist': 1, 'keygen': 1, 'output': 1, 'progress': 1,
'meter': 1, 'details': 1, 'summary': 1, 'command': 1
};
hljs.LANGUAGES.html = {
defaultMode: {
contains: ['comment', 'pi', 'doctype', 'vbscript', 'tag']
},
case_insensitive: true,
modes: [
{
className: 'tag',
begin: '<style', end: '>',
lexems: [hljs.IDENT_RE], keywords: {'style': 1},
contains: ['tag_internal'],
starts: 'css'
},
{
className: 'tag',
begin: '<script', end: '>',
lexems: [hljs.IDENT_RE], keywords: {'script': 1},
contains: ['tag_internal'],
starts: 'javascript'
},
{
className: 'css',
end: '</style>', returnEnd: true,
subLanguage: 'css'
},
{
className: 'javascript',
end: '</script>', returnEnd: true,
subLanguage: 'javascript'
},
{
className: 'vbscript',
begin: '<%', end: '%>',
subLanguage: 'vbscript'
},
COMMENT,
PI,
DOCTYPE,
hljs.inherit(TAG),
hljs.inherit(TITLE, {
lexems: [hljs.IDENT_RE], keywords: HTML_TAGS
}),
hljs.inherit(TAG_INTERNAL),
ATTR,
VALUE_CONTAINER_QUOT,
VALUE_CONTAINER_APOS,
{
className: 'value_container',
begin: '=', end: hljs.IMMEDIATE_RE,
contains: [
{
className: 'unquoted_value', displayClassName: 'value',
begin: '[^\\s/>]+', end: hljs.IMMEDIATE_RE
}
]
}
]
};
})();

View File

@@ -0,0 +1,53 @@
/*
Language: Javascript
*/
hljs.LANGUAGES.javascript = {
defaultMode: {
lexems: [hljs.UNDERSCORE_IDENT_RE],
contains: ['string', 'comment', 'number', 'regexp_container', 'function'],
keywords: {
'keyword': {'in': 1, 'if': 1, 'for': 1, 'while': 1, 'finally': 1, 'var': 1, 'new': 1, 'function': 1, 'do': 1, 'return': 1, 'void': 1, 'else': 1, 'break': 1, 'catch': 1, 'instanceof': 1, 'with': 1, 'throw': 1, 'case': 1, 'default': 1, 'try': 1, 'this': 1, 'switch': 1, 'continue': 1, 'typeof': 1, 'delete': 1},
'literal': {'true': 1, 'false': 1, 'null': 1}
}
},
modes: [
hljs.C_LINE_COMMENT_MODE,
hljs.C_BLOCK_COMMENT_MODE,
hljs.C_NUMBER_MODE,
hljs.APOS_STRING_MODE,
hljs.QUOTE_STRING_MODE,
hljs.BACKSLASH_ESCAPE,
{
className: 'regexp_container',
begin: '(' + hljs.RE_STARTERS_RE + '|case|return|throw)\\s*', end: hljs.IMMEDIATE_RE, noMarkup: true,
lexems: [hljs.IDENT_RE],
keywords: {'return': 1, 'throw': 1, 'case': 1},
contains: [
'comment',
{
className: 'regexp',
begin: '/.*?[^\\\\/]/[gim]*', end: hljs.IMMEDIATE_RE
}
],
relevance: 0
},
{
className: 'function',
begin: '\\bfunction\\b', end: '{',
lexems: [hljs.UNDERSCORE_IDENT_RE],
keywords: {'function': 1},
contains: [
{
className: 'title',
begin: '[A-Za-z$_][0-9A-Za-z$_]*', end: hljs.IMMEDIATE_RE
},
{
className: 'params',
begin: '\\(', end: '\\)',
contains: ['string', 'comment']
}
]
}
]
};

View File

@@ -0,0 +1,68 @@
/*
Language: PHP
Author: Victor Karamzin <Victor.Karamzin@enterra-inc.com>
*/
hljs.LANGUAGES.php = {
defaultMode: {
lexems: [hljs.IDENT_RE],
contains: ['comment', 'number', 'string', 'variable', 'preprocessor'],
keywords: {
'and': 1, 'include_once': 1, 'list': 1, 'abstract': 1, 'global': 1,
'private': 1, 'echo': 1, 'interface': 1, 'as': 1, 'static': 1,
'endswitch': 1, 'array': 1, 'null': 1, 'if': 1, 'endwhile': 1, 'or': 1,
'const': 1, 'for': 1, 'endforeach': 1, 'self': 1, 'var': 1, 'while': 1,
'isset': 1, 'public': 1, 'protected': 1, 'exit': 1, 'foreach': 1,
'throw': 1, 'elseif': 1, 'extends': 1, 'include': 1, '__FILE__': 1,
'empty': 1, 'require_once': 1, 'function': 1, 'do': 1, 'xor': 1,
'return': 1, 'implements': 1, 'parent': 1, 'clone': 1, 'use': 1,
'__CLASS__': 1, '__LINE__': 1, 'else': 1, 'break': 1, 'print': 1,
'eval': 1, 'new': 1, 'catch': 1, '__METHOD__': 1, 'class': 1, 'case': 1,
'exception': 1, 'php_user_filter': 1, 'default': 1, 'die': 1,
'require': 1, '__FUNCTION__': 1, 'enddeclare': 1, 'final': 1, 'try': 1,
'this': 1, 'switch': 1, 'continue': 1, 'endfor': 1, 'endif': 1,
'declare': 1, 'unset': 1, 'true': 1, 'false': 1, 'namespace': 1
}
},
case_insensitive: true,
modes: [
hljs.C_LINE_COMMENT_MODE,
hljs.HASH_COMMENT_MODE,
{
className: 'comment',
begin: '/\\*', end: '\\*/',
contains: [{
className: 'phpdoc',
begin: '\\s@[A-Za-z]+', end: hljs.IMMEDIATE_RE,
relevance: 10
}]
},
hljs.C_NUMBER_MODE,
{
className: 'string',
begin: '\'', end: '\'',
contains: ['escape'],
relevance: 0
},
{
className: 'string',
begin: '"', end: '"',
contains: ['escape'],
relevance: 0
},
hljs.BACKSLASH_ESCAPE,
{
className: 'variable',
begin: '\\$[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*', end: hljs.IMMEDIATE_RE
},
{
className: 'preprocessor',
begin: '<\\?php', end: hljs.IMMEDIATE_RE,
relevance: 10
},
{
className: 'preprocessor',
begin: '\\?>', end: hljs.IMMEDIATE_RE
}
]
};

View File

@@ -0,0 +1,508 @@
# Highlight.js
Highlight.js highlights syntax in code examples on blogs, forums and
in fact on any web pages. It's very easy to use because it works
automatically: finds blocks of code, detects a language, highlights it.
Autodetection can be fine tuned when it fails by itself (see "Heuristics").
## Installation and usage
Downloaded package includes file "highlight.pack.js" which is a full compressed
version of the library intended to use in production. All uncompressed source
files are also available, feel free to look into them!
The script is installed by linking to a single file and making a single
initialization call:
<script type="text/javascript" src="highlight.pack.js"></script>
<script type="text/javascript">
hljs.initHighlightingOnLoad();
</script>
Also you can replaces TAB ('\x09') characters used for indentation in your code
with some fixed number of spaces or with a `<span>` to set them special styling:
<script type="text/javascript">
hljs.tabReplace = ' '; // 4 spaces
// ... or
hljs.tabReplace = '<span class="indent">\t</span>';
hljs.initHighlightingOnLoad();
</script>
Then the script looks in your page for fragments `<pre><code>...</code></pre>`
that are used traditionally to mark up code examples. Their content is
marked up by logical pieces with defined class names.
### Custom initialization
If you use different markup for code blocks you can initialize them manually
with `highlightBlock(code, tabReplace)` function. It takes a DOM element
containing the code to highlight and optionally a string with which to replace
TAB characters.
Initialization using for example jQuery might look like this:
$(document).ready(function() {
$('pre code').each(function(i, e) {hljs.highlightBlock(e, ' ')});
});
If your code container relies on `<br>` tags instead of line breaks (i.e. if
it's not `<pre>`) pass `true` into third parameter of `highlightBlock`:
$('div.code').each(function(i, e) {hljs.highlightBlock(e, null, true)});
### Styling
Elements of code marked up with classes can be styled as desired:
.comment {
color: gray;
}
.keyword {
font-weight: bold;
}
.python .string {
color: blue;
}
.html .atribute .value {
color: green;
}
Highligt.js comes with several style themes located in "styles" directory that
can be used directly or as a base for your own experiments.
A full list of available classes is below ("Languages").
## Export
File export.html contains a little program that shows and allows to copy and paste
an HTML code generated by the highlighter for any code snippet. This can be useful
in situations when one can't use the script itself on a site.
## Languages
This is a full list of available classes corresponding to languages'
syntactic structures. In parentheses after language names are identifiers
used as class names in `<code>` element.
Python ("python"):
keyword keyword
built_in built-in objects (None, False, True and Ellipsis)
number number
string string (of any type)
comment comment
decorator @-decorator for functions
function function header "def some_name(...):"
class class header "class SomeName(...):"
title name of a function or a class inside a header
params everything inside parentheses in a function's or class' header
Python profiler results ("profile"):
number number
string string
builtin builtin function entry
filename filename in an entry
summary profiling summary
header header of table of results
keyword column header
function function name in an entry (including parentheses)
title actual name of a function in an entry (excluding parentheses)
Ruby ("ruby"):
keyword keyword
string string
subst in-string substitution (#{...})
comment comment
yardoctag YARD tag
function function header "def some_name(...):"
class class header "class SomeName(...):"
title name of a function or a class inside a header
parent name of a parent class
symbol symbol
instancevar instance variable
Perl ("perl"):
keyword keyword
comment comment
number number
string string
regexp regular expression
sub subroutine header (from "sub" till "{")
variable variable starting with "$", "%", "@"
operator operator
pod plain old doc
PHP ("php"):
keyword keyword
number number
string string (of any type)
comment comment
phpdoc phpdoc params in comments
variable variable starting with "$"
preprocessor preprocessor marks: "<?php" and "?>"
Scala ("scala"):
keyword keyword
number number
string string
comment comment
annotaion annotation
javadoc javadoc comment
javadoctag @-tag in javadoc
class class header
title class name inside a header
params everything in parentheses inside a class header
inheritance keywords "extends" and "with" inside class header
XML ("xml"):
tag any tag from "<" till ">"
comment comment
pi processing instruction (<? ... ?>)
cdata CDATA section
attribute attribute
value attribute's value
HTML ("html"):
keyword HTML tag
tag any tag from "<" till ">"
comment comment
doctype <!DOCTYPE ... > declaration
attribute tag's attribute with or without value
value attribute's value
CSS ("css"):
keyword HTML tag when in selectors, CSS keyword when in rules
id #some_name in selectors
class .some_name in selectors
at_rule @-rule till first "{" or ";"
attr_selector attribute selector (square brackets in a[href^=http://])
pseudo pseudo classes and elemens (:after, ::after etc.)
comment comment
rules everything from "{" till "}"
value property's value inside a rule, from ":" till ";" or
till the end of rule block
number number within a value
string string within a value
hexcolor hex color (#FFFFFF) within a value
function CSS function within a value
params everything between "(" and ")" within a function
important "!important" symbol
Django ("django"):
keyword HTML tag in HTML, default tags and default filters in templates
tag any tag from "<" till ">"
comment comment
doctype <!DOCTYPE ... > declaration
attribute tag's attribute with or withou value
value attribute's value
template_tag template tag {% .. %}
variable template variable {{ .. }}
template_comment template comment, both {# .. #} and {% comment %}
filter filter from "|" till the next filter or the end of tag
argument filter argument
Javascript ("javascript"):
keyword keyword
comment comment
number number
literal special literal: "true", "false" and "null"
string string
regexp regular expression
function header of a function
title name of a function inside a header
params everything inside parentheses in a function's header
VBScript ("vbscript"):
keyword keyword
number number
string string
comment comment
built_in built-in function
Lua ("lua"):
keyword keyword
number number
string string
comment comment
built_in built-in operator
function header of a function
title name of a function inside a header
params everything inside parentheses in a function's header
long_brackets multiline string in [=[ .. ]=]
Delphi ("delphi"):
keyword keyword
comment comment (of any type)
number number
string string
function header of a function, procedure, constructor and destructor
title name of a function, procedure, constructor or destructor
inside a header
params everything inside parentheses in a function's header
class class' body from "= class" till "end;"
Java ("java"):
keyword keyword
number number
string string
comment commment
annotaion annotation
javadoc javadoc comment
class class header from "class" till "{"
title class name inside a header
params everything in parentheses inside a class header
inheritance keywords "extends" and "implements" inside class header
C++ ("cpp"):
keyword keyword
number number
string string and character
comment comment
preprocessor preprocessor directive
stl_container instantiation of STL containers ("vector<...>")
C# ("cs"):
keyword keyword
number number
string string
comment commment
xmlDocTag xmldoc tag ("///", "<!--", "-->", "<..>")
RenderMan RSL ("rsl"):
keyword keyword
number number
string string (including @"..")
comment comment
preprocessor preprocessor directive
shader sahder keywords
shading shading keywords
built_in built-in function
RenderMan RIB ("rib"):
keyword keyword
number number
string string
comment comment
commands command
Maya Embedded Language ("mel"):
keyword keyword
number number
string string
comment comment
variable variable
SQL ("sql"):
keyword keyword (mostly SQL'92 and SQL'99)
number number
string string (of any type: "..", '..', `..`)
comment comment
aggregate aggregate function
Smalltalk ("smalltalk"):
keyword keyword
number number
string string
comment commment
symbol symbol
array array
class name of a class
char char
localvars block of local variables
Lisp ("lisp"):
keyword keyword
number number
string string
comment commment
variable variable
literal b, t and nil
list non-quoted list
title first symbol in a non-quoted list
body remainder of the non-quoted list
quoted_list quoted list, both "(quote .. )" and "'(..)"
Ini ("ini"):
title title of a section
value value of a setting of any type
string string
number number
keyword boolean value keyword
Apache ("apache"):
keyword keyword
number number
comment commment
literal On and Off
sqbracket variables in rewrites "%{..}"
cbracket options in rewrites "[..]"
tag begin and end of a configuration section
Nginx ("nginx"):
keyword keyword
string string
number number
comment comment
built_in built-in constant
variable $-variable
Diff ("diff"):
header file header
chunk chunk header within a file
addition added lines
deletion deleted lines
change changed lines
DOS ("dos"):
keyword keyword
flow batch control keyword
stream DOS special files ("con", "prn", ...)
winutils some commands (see dos.js specifically)
envvar environment variables
Bash ("bash"):
keyword keyword
string string
number number
comment comment
literal special literal: "true" и "false"
variable variable
shebang script interpreter header
CMake ("cmake")
keyword keyword
number number
string string
comment commment
envvar $-variable
Axapta ("axapta"):
keyword keyword
number number
string string
comment commment
class class header from "class" till "{"
title class name inside a header
params everything in parentheses inside a class header
inheritance keywords "extends" and "implements" inside class header
preprocessor preprocessor directive
1C ("1c"):
keyword keyword
number number
date date
string string
comment commment
function header of function or procudure
title function name inside a header
params everything in parentheses inside a function header
preprocessor preprocessor directive
AVR assembler ("avrasm"):
keyword keyword
built_in pre-defined register
number number
string string
comment commment
label label
preprocessor preprocessor directive
localvars substitution in .macro
VHDL ("vhdl")
keyword keyword
number number
string string
comment commment
literal signal logical value
Parser3 ("parser3"):
keyword keyword
number number
comment commment
variable variable starting with "$"
preprocessor preprocessor directive
title user-defined name starting with "@"
TeX ("tex"):
comment comment
number number
command command
parameter parameter
formula formula
special special symbol
## Heuristics
Autodetection of a code's language is done with a simple heuristics:
the program tries to highlight a fragment with all available languages and
counts all syntactic structures that it finds along the way. The language
with greatest count wins.
This means that in short fragments the probability of an error is high
(and it really happens sometimes). In this cases you can set the fragment's
language explicitly by assigning a class to the `<code>` element:
<pre><code class="html">...</code></pre>
You can use class names recommended in HTML5: "language-html",
"language-php". Classes also can be assigned to the `<pre>` element.
To disable highlighting of a fragment altogether use "no-highlight" class:
<pre><code class="no-highlight">...</code></pre>
## Contacts
Version: 5.16
URL: http://softwaremaniacs.org/soft/highlight/en/
Author: Ivan Sagalaev (Maniac@SoftwareManiacs.Org)
For the license terms see LICENSE files.
For the list of contributors see AUTHORS.en.txt file.

View File

@@ -0,0 +1,102 @@
/* = FONT STACKS
----------------------------------------------------------------------------------------------------------------------*/
body { font-family: Geneva, 'Lucida Sans', 'Lucida Grande', 'Lucida Sans Unicode', Verdana, sans-serif } /* "wide" sans serif */
/*body { font-family: Tahoma, Arial, Helvetica, sans-serif } /* "narrow" sans serif */
/*body { font-family: Georgia, Utopia, Palatino, 'Palatino Linotype', serif } /* "wide" serif */
/*body { font-family: 'Times New Roman', Times, serif } /* "narrow" serif */
/* transform the font size so that 1em is 10px so that you can use em's
but think in pixels as now 1em is 10px, 1.2em is 12px and so on */
html { font-size: 62.5% }
body {
font-size: 1.3em;
margin: 0;
padding: 0;
outline: 0;
border: 0;
text-align: center; /* this is for IE6 so that it will center the main wrapper */
line-height: 1.2; /* unit-less line-height does not inherit a percentage value of its parent element */
/* but instead is based on a multiplier of the font-size */
}
div, span, applet, object, iframe, h1, h2, h3, h4, h5, h6, p, blockquote, pre, aabbr, acronym, address,
big, cite, code, del, dfn, em, font, img, ins, kbd, q, s, samp, small, strike, strong, sub, sup, tt, var, b, u, i,
center, dl, dt, dd, ol, ul, li, fieldset, form, label, legend, table, caption, tbody, tfoot, thead, tr, th, td {
margin: 0;
padding: 0;
outline: 0;
border: 0;
font-family: inherit;
font-weight: inherit;
font-style: inherit;
line-height: inherit;
}
a, blockquote, dd, div, dl, dt, fieldset, form, h1, h2, h3, h4, h5, h6, img, input, label, li, ol, p, pre, span, table, ul {
position: relative
}
h1, h2, h3, h4, h5, h6 { font-weight: normal; line-height: 1 }
p { font-size: 100% }
h1 { font-size: 220% }
h2 { font-size: 200% }
h3 { font-size: 180% }
h4 { font-size: 160% }
h5 { font-size: 140% }
h6 { font-size: 120% }
small,
sup,
sub { font-size: 70% }
p small { display: block; line-height: 1 }
strong, b { font-weight: bold }
em, i { font-style: italic }
/* = CLEARFIX
----------------------------------------------------------------------------------------------------------------------*/
.clearfix:before,
.clearfix:after { content: "\0020"; display: block; height: 0; visibility: hidden; font-size: 0 }
.clearfix:after { clear: both }
.clearfix { *zoom: 1 } /* for IE only */
/* = TABLES
----------------------------------------------------------------------------------------------------------------------*/
table {
border-collapse: collapse;
border-spacing: 0;
/* tables still need cellspacing="0" */
}
/* = LISTS
----------------------------------------------------------------------------------------------------------------------*/
ul, ol { list-style: none }
ul.float li,
ol.float li { float: left }
ul.default,
ol.default,
ol.default ul,
ul.default ul,
ul.default ol,
ol.default ol { padding-left: 1.5em }
ul.default,
ol.default ul,
ul.default ul { list-style-type: square }
ol.default,
ul.default ol,
ol.default ol { list-style-type: decimal }

View File

@@ -0,0 +1,62 @@
body { text-align: left; margin: 20px }
.header { background: #888; padding: 10px 5px; font-weight: bold }
.header a { color: #FFF; text-decoration: none }
.header span { font-weight: normal }
.example { background: #ABCDEF; padding: 10px 5px; font-weight: bold; margin: 0 0 20px }
.example a { color: #123456; font-weight: normal }
h1 { margin-bottom: 1em }
h1 span { display: block; font-size: 11px; color: #666 }
.navigation { border-right: 1px solid #DEDEDE; padding-right: 20px; margin-right: 20px }
.navigation li { font-weight: bold; margin: 0 }
.navigation li ul { color: #AAA; margin: 10px 0 }
.navigation a { color: #000066; white-space: nowrap; font-weight: normal; text-decoration: none; display: block; padding: 2px }
.navigation a.selected { color: #DDD; background: #222 }
.tabs { }
.tabs a { display: block; background: #000; color: #FFF; padding: 4px 10px; text-decoration: none; margin-right: 1px; font-weight: bold }
.tabs a:hover,
.tabs a.selected { background: #DEDEDE; color: #222 }
.tab { border: 1px solid #DEDEDE; padding: 20px; display: none }
.tab h2 { font-weight: bold; margin: 0 0 20px }
.tab p { color: #999; margin: 0 0 20px; font-size: 12px }
ul.notes { color: #999; font-size: 11px; margin: 20px 0 0 }
table.results { border-collapse: collapse }
table.results th,
table.results td { padding: 5px; border: 1px solid #DEDEDE }
table.results th { font-weight: bold }
table.results thead td { background: #666; color: #FFF; font-weight: bold }
img.Zebra_Form_Input_Prefix { width: 16px; height: 16px }
.tab a { color: #0000FF; text-decoration: none }
/* = MISCELLANEOUS
----------------------------------------------------------------------------------------------------------------------*/
.align-center { text-align: center }
.align-left { text-align: left }
.align-right { text-align: right }
.block { display: block }
.bottom { margin-bottom: 0; padding-bottom: 0 }
.center { text-align: center }
.clear { clear: both }
.first { margin-left: 0; padding-left: 0 }
.hidden { visibility: hidden }
.highlight { background: #ccf }
.inline { display: inline }
.last { margin-right: 0; padding-right: 0 }
.left { float: left }
.none { display: none }
.nowrap { white-space: nowrap }
.right { float: right }
.stretch { width: 100% }
.top { margin-top: 0; padding-top: 0 }
.visible { visibility: visible }
img.Zebra_Form_prefix { width: 16px; height: 16px }

Binary file not shown.

After

Width:  |  Height:  |  Size: 469 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 303 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 416 B

View File

@@ -0,0 +1,25 @@
$(document).ready(function() {
hljs.initHighlightingOnLoad();
$('a').bind('click', function() { this.blur() });
var tab_selectors = $('.tabs a');
var tabs = $('.tab');
tab_selectors.each(function(index, selector) {
$(selector).bind('click', function(e) {
e.preventDefault();
tab_selectors.removeClass('selected');
$(this).addClass('selected');
tabs.css('display', 'none');
$(tabs[index]).css({
'opacity': 0,
'display': 'block'
});
$(tabs[index]).animate({'opacity': 1}, 250);
});
});
});

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,150 @@
<?php
/**
* Class for button controls.
*
* @author Stefan Gabos <contact@stefangabos.ro>
* @copyright (c) 2006 - 2016 Stefan Gabos
* @package Controls
*/
class Zebra_Form_Button extends Zebra_Form_Control
{
/**
* Constructor of the class
*
* Adds an <button> control to the form.
*
* <b>Do not instantiate this class directly! Use the {@link Zebra_Form::add() add()} method instead!</b>
*
* <code>
* // create a new form
* $form = new Zebra_Form('my_form');
*
* // add a submit button to the form
* $obj = $form->add('button', 'my_button', 'Click me!', 'submit');
*
* // don't forget to always call this method before rendering the form
* if ($form->validate()) {
* // put code here
* }
*
* // output the form using an automatically generated template
* $form->render();
* </code>
*
* @param string $id Unique name to identify the control in the form.
*
* The control's <b>name</b> attribute will be the same as the <b>id</b> attribute!
*
* This is the name to be used when referring to the control's value in the
* POST/GET superglobals, after the form is submitted.
*
* This is also the name of the variable to be used in custom template files, in
* order to display the control.
*
* <code>
* // in a template file, in order to print the generated HTML
* // for a control named "my_button", one would use:
* echo $my_button;
* </code>
*
* @param string $caption Caption of the button control.
*
* Can be HTML markup.
*
* @param string $type (Optional) Type of the button: button, submit or reset.
*
* Default is "button".
*
* @param array $attributes (Optional) An array of attributes valid for
* {@link http://www.w3.org/TR/REC-html40/interact/forms.html#h-17.4 input}
* controls (size, readonly, style, etc)
*
* Must be specified as an associative array, in the form of <i>attribute => value</i>.
* <code>
* // setting the "disabled" attribute
* $obj = $form->add(
* 'button',
* 'my_button',
* 'Click me!',
* 'submit' // <- make this a submit button
* array(
* 'disabled' => 'disabled'
* )
* );
* </code>
*
* See {@link Zebra_Form_Control::set_attributes() set_attributes()} on how to set
* attributes, other than through the constructor.
*
* The following attributes are automatically set when the control is created and
* should not be altered manually:<br>
* <b>id</b>, <b>name</b>, <b>class</b>
*
* @return void
*/
function __construct($id, $caption, $type = 'button', $attributes = '')
{
// call the constructor of the parent class
parent::__construct();
// set the private attributes of this control
// these attributes are private for this control and are for internal use only
// and will not be rendered by the _render_attributes() method
$this->private_attributes = array(
'disable_xss_filters',
'locked',
'value',
);
// set the default attributes for the button control
// put them in the order you'd like them rendered
$this->set_attributes(
array(
'type' => $type,
'name' => $id,
'id' => $id,
'value' => $caption,
'class' => 'button' . ($type != 'button' ? ' ' . $type : ''),
)
);
// if "class" is amongst user specified attributes
if (is_array($attributes) && isset($attributes['class'])) {
// we need to set the "class" attribute like this, so it doesn't overwrite previous values
$this->set_attributes(array('class' => $attributes['class']), false);
// make sure we don't set it again below
unset($attributes['class']);
}
// sets user specified attributes for the control
$this->set_attributes($attributes);
}
/**
* Generates the control's HTML code.
*
* <i>This method is automatically called by the {@link Zebra_Form::render() render()} method!</i>
*
* @return string The control's HTML code
*/
function toHTML()
{
return '<button ' . $this->_render_attributes() . ($this->form_properties['doctype'] == 'xhtml' ? '/' : '') . '>' . $this->attributes['value'] . '</button>';
}
}
?>

View File

@@ -0,0 +1,123 @@
<?php
/**
* Class for CAPTCHA controls.
*
* @author Stefan Gabos <contact@stefangabos.ro>
* @copyright (c) 2006 - 2016 Stefan Gabos
* @package Controls
*/
class Zebra_Form_Captcha extends Zebra_Form_Control
{
/**
* Adds a CAPTCHA image to the form.
*
* <b>Do not instantiate this class directly! Use the {@link Zebra_Form::add() add()} method instead!</b>
*
* <b>You must also place a {@link Zebra_Form_Text textbox} control on the form and set the "captcha" rule to it!
* (through {@link set_rule()})</b>
*
* Properties of the CAPTCHA image can be altered by editing the file includes/captcha.php.
*
* By default, captcha values are triple md5 hashed and stored in cookies, and when the user enters the captcha
* value the value is also triple md5 hashed and the two values are then compared. Sometimes, your users may have
* a very restrictive cookie policy and so cookies will not be set, and therefore they will never be able to get
* past the CAPTCHA control. If it's the case, call the {@link Zebra_Form::captcha_storage() captcha_storage}
* method and set the storage method to "session".
*
* <code>
* // create a new form
* $form = new Zebra_Form('my_form');
*
* // add a CAPTCHA image
* $form->add('captcha', 'my_captcha', 'my_text');
*
* // add a label for the textbox
* $form->add('label', 'label_my_text', 'my_text', 'Are you human?');
*
* // add a CAPTCHA to the form
* $obj = $form->add('text', 'my_text');
*
* // set the "captcha" rule to the textbox
* $obj->set_rule(array(
* 'captcha' => array('error', 'Characters not entered correctly!')
* ));
*
* // don't forget to always call this method before rendering the form
* if ($form->validate()) {
* // put code here
* }
*
* // output the form using an automatically generated template
* $form->render();
* </code>
*
* @param string $id Unique name to identify the control in the form.
*
* This is the name of the variable to be used in the template file, containing
* the generated HTML for the control.
*
* <code>
* // in a template file, in order to print the generated HTML
* // for a control named "my_captcha", one would use:
* echo $my_captcha;
* </code>
*
* @param string $attach_to The <b>id</b> attribute of the {@link Zebra_Form_Text textbox} control to attach
* the CAPTCHA image to.
*
* @return void
*/
function __construct($id, $attach_to, $storage = 'cookie')
{
// call the constructor of the parent class
parent::__construct();
// set the private attributes of this control
// these attributes are private for this control and are for internal use only
// and will not be rendered by the _render_attributes() method
$this->private_attributes = array(
'disable_xss_filters',
'for',
'locked',
);
// set the default attributes for the text control
// put them in the order you'd like them rendered
$this->set_attributes(
array(
'type' => 'captcha',
'name' => $id,
'id' => $id,
'for' => $attach_to,
)
);
}
/**
* Generates the control's HTML code.
*
* <i>This method is automatically called by the {@link Zebra_Form::render() render()} method!</i>
*
* @return string The control's HTML code
*/
function toHTML()
{
return '<div class="captcha-container"><img src="' . $this->form_properties['assets_url'] . 'process.php?captcha=' . ($this->form_properties['captcha_storage'] == 'session' ? 2 : 1) . '&amp;nocache=' . time() . '" alt=""' . ($this->form_properties['doctype'] == 'xhtml' ? '/' : '') . '><a href="javascript:void(0)" title="' . $this->form_properties['language']['new_captcha'] . '">' . $this->form_properties['language']['new_captcha'] . '</a></div>';
}
}
?>

View File

@@ -0,0 +1,243 @@
<?php
/**
* Class for checkbox controls.
*
* @author Stefan Gabos <contact@stefangabos.ro>
* @copyright (c) 2006 - 2016 Stefan Gabos
* @package Controls
*/
class Zebra_Form_Checkbox extends Zebra_Form_Control
{
/**
* Constructor of the class
*
* Adds an <input type="checkbox"> control to the form.
*
* <b>Do not instantiate this class directly! Use the {@link Zebra_Form::add() add()} method instead!</b>
*
* <code>
* // create a new form
* $form = new Zebra_Form('my_form');
*
* // single checkbox
* $obj = $form->add('checkbox', 'my_checkbox', 'my_checkbox_value');
*
* // multiple checkboxes
* // notice that is "checkboxes" instead of "checkbox"
* // checkboxes values will be "0", "1" and "2", respectively, and will be available in a custom template like
* // "mycheckbox_0", "mycheckbox_1" and "mycheckbox_2".
* // label controls will be automatically created having the names "label_mycheckbox_0", "label_mycheckbox_1" and
* // "label_mycheckbox_2" (label + underscore + control name + underscore + value with anything else other than
* // letters and numbers replaced with underscores - also, note that multiple consecutive underscores will be
* // replaced by a single one)
* // $obj is a reference to the first checkbox
* $obj = $form->add('checkboxes', 'mycheckbox',
* array(
* 'Value 1',
* 'Value 2',
* 'Value 3'
* )
* );
*
* // multiple checkboxes with specific indexes
* // checkboxes values will be "v1", "v2" and "v3", respectively, and will be available in a custom template like
* // "mycheckbox_v1", "mycheckbox_v2" and "mycheckbox_v3".
* // label controls will be automatically created having the names "label_mycheckbox_v1", "label_mycheckbox_v2" and
* // "label_mycheckbox_v3" (label + underscore + control name + underscore + value with anything else other than
* // letters and numbers replaced with underscores - also, note that multiple consecutive underscores will be
* // replaced by a single one)
* $obj = $form->add('checkboxes', 'mycheckbox',
* array(
* 'v1' => 'Value 1',
* 'v2' => 'Value 2',
* 'v3' => 'Value 3'
* )
* );
*
* // multiple checkboxes with preselected value
* // "Value 2" will be the preselected value
* // note that for preselecting values you must use the actual indexes of the values, if available, (like
* // in the current example) or the default, zero-based index, otherwise (like in the next example)
* $obj = $form->add('checkboxes', 'mycheckbox',
* array(
* 'v1' => 'Value 1',
* 'v2' => 'Value 2',
* 'v3' => 'Value 3'
* ),
* 'v2' // note the index!
* );
*
* // "Value 2" will be the preselected value.
* // note that for preselecting values you must use the actual indexes of the values, if available, (like
* // in the example above) or the default, zero-based index, otherwise (like in the current example)
* $obj = $form->add('checkboxes', 'mycheckbox',
* array(
* 'Value 1',
* 'Value 2',
* 'Value 3'
* ),
* 1 // note the index!
* );
*
* // multiple checkboxes with multiple preselected values
* $obj = $form->add('checkboxes', 'mycheckbox[]',
* array(
* 'v1' => 'Value 1',
* 'v2' => 'Value 2',
* 'v3' => 'Value 3'
* ),
* array('v1', 'v2')
* );
*
* // custom classes (or other attributes) can also be added to all of the elements by specifying a 4th argument;
* // this needs to be specified in the same way as you would by calling {@link set_attributes()} method:
* $obj = $form->add('checkboxes', 'mycheckbox[]',
* array(
* '1' => 'Value 1',
* '2' => 'Value 2',
* '3' => 'Value 3',
* ),
* '', // no default value
* array('class' => 'my_custom_class')
* );
*
* // don't forget to always call this method before rendering the form
* if ($form->validate()) {
* // put code here
* }
*
* // output the form using an automatically generated template
* $form->render();
* </code>
*
* <samp>By default, for checkboxes, radio buttons and select boxes, the library will prevent the submission of other
* values than those declared when creating the form, by triggering the error: "SPAM attempt detected!". Therefore,
* if you plan on adding/removing values dynamically, from JavaScript, you will have to call the
* {@link Zebra_Form_Control::disable_spam_filter() disable_spam_filter()} method to prevent that from happening!</samp>
*
* @param string $id Unique name to identify the control in the form.
*
* <b>$id needs to be suffixed with square brackets if there are more checkboxes
* sharing the same name, so that PHP treats them as an array!</b>
*
* The control's <b>name</b> attribute will be as indicated by <i>$id</i>
* argument while the control's <b>id</b> attribute will be <i>$id</i>, stripped of
* square brackets (if any), followed by an underscore and followed by <i>$value</i>
* with all the spaces replaced by <i>underscores</i>.
*
* So, if the <i>$id</i> arguments is "my_checkbox" and the <i>$value</i> argument
* is "value 1", the control's <b>id</b> attribute will be <b>my_checkbox_value_1</b>.
*
* This is the name to be used when referring to the control's value in the
* POST/GET superglobals, after the form is submitted.
*
* This is also the name of the variable to be used in custom template files, in
* order to display the control.
*
* <code>
* // in a template file, in order to print the generated HTML
* // for a control named "my_checkbox" and having the value of "value 1",
* // one would use:
* echo $my_checkbox_value_1;
* </code>
*
* <i>Note that when adding the required rule to a group of checkboxes (checkboxes
* sharing the same name), it is sufficient to add the rule to the first checkbox!</i>
*
* @param mixed $value Value of the checkbox.
*
* @param array $attributes (Optional) An array of attributes valid for
* {@link http://www.w3.org/TR/REC-html40/interact/forms.html#h-17.4 input}
* controls (disabled, readonly, style, etc)
*
* Must be specified as an associative array, in the form of <i>attribute => value</i>.
* <code>
* // setting the "checked" attribute
* $obj = $form->add(
* 'checkbox',
* 'my_checkbox',
* 'v1',
* array(
* 'checked' => 'checked'
* )
* );
* </code>
*
* See {@link Zebra_Form_Control::set_attributes() set_attributes()} on how to set
* attributes, other than through the constructor.
*
* The following attributes are automatically set when the control is created and
* should not be altered manually:<br>
*
* <b>type</b>, <b>id</b>, <b>name</b>, <b>value</b>, <b>class</b>
*
* @return void
*/
function __construct($id, $value, $attributes = '')
{
// call the constructor of the parent class
parent::__construct();
// set the private attributes of this control
// these attributes are private for this control and are for internal use only
// and will not be rendered by the _render_attributes() method
$this->private_attributes = array(
'disable_spam_filter',
'disable_xss_filters',
'locked',
);
// set the default attributes for the checkbox control
// put them in the order you'd like them rendered
$this->set_attributes(
array(
'type' => 'checkbox',
'name' => $id,
'id' => str_replace(array(' ', '[', ']'), array('_', ''), $id) . '_' . str_replace(' ', '_', $value),
'value' => $value,
'class' => 'control checkbox',
)
);
// if "class" is amongst user specified attributes
if (is_array($attributes) && isset($attributes['class'])) {
// we need to set the "class" attribute like this, so it doesn't overwrite previous values
$this->set_attributes(array('class' => $attributes['class']), false);
// make sure we don't set it again below
unset($attributes['class']);
}
// sets user specified attributes for the control
$this->set_attributes($attributes);
}
/**
* Generates the control's HTML code.
*
* <i>This method is automatically called by the {@link Zebra_Form::render() render()} method!</i>
*
* @return string The control's HTML code
*/
function toHTML()
{
return '<input ' . $this->_render_attributes() . ($this->form_properties['doctype'] == 'xhtml' ? '/' : '') . '>';
}
}
?>

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,185 @@
<?php
/**
* Class for file upload controls.
*
* @author Stefan Gabos <contact@stefangabos.ro>
* @copyright (c) 2006 - 2016 Stefan Gabos
* @package Controls
*/
class Zebra_Form_File extends Zebra_Form_Control
{
/**
* Adds an <input type="file"> control to the form.
*
* <b>Do not instantiate this class directly! Use the {@link Zebra_Form::add() add()} method instead!</b>
*
* <code>
* // create a new form
* $form = new Zebra_Form('my_form');
*
* // add a file upload control to the form
* $obj = $form->add('file', 'my_file_upload');
*
* // don't forget to always call this method before rendering the form
* if ($form->validate()) {
*
* // all the information about the uploaded file will be
* // available in the "file_upload" property
* print_r('<pre>');
* print_r($form->file_upload['my_file_upload']);
*
* }
*
* // output the form using an automatically generated template
* $form->render();
* </code>
*
* @param string $id Unique name to identify the control in the form.
*
* The control's <b>name</b> attribute will be the same as the <b>id</b> attribute!
*
* This is the name to be used when referring to the control's value in the
* POST/GET superglobals, after the form is submitted.
*
* This is also the name of the variable to be used in custom template files, in
* order to display the control.
*
* <code>
* // in a template file, in order to print the generated HTML
* // for a control named "my_file_upload", one would use:
* echo $my_file_upload;
* </code>
*
* @param array $attributes (Optional) An array of attributes valid for
* {@link http://www.w3.org/TR/REC-html40/interact/forms.html#h-17.4 input}
* controls (size, readonly, style, etc)
*
* Must be specified as an associative array, in the form of <i>attribute => value</i>.
* <code>
* // setting the "disabled" attribute
* $obj = $form->add(
* 'file',
* 'my_file_upload',
* '',
* array(
* 'disabled' => 'disabled'
* )
* );
* </code>
*
* See {@link Zebra_Form_Control::set_attributes() set_attributes()} on how to set
* attributes, other than through the constructor.
*
* The following attributes are automatically set when the control is created and
* should not be altered manually:<br>
*
* <b>type</b>, <b>id</b>, <b>name</b>, <b>class</b>
*
* @return void
*/
function __construct($id, $attributes = '')
{
// call the constructor of the parent class
parent::__construct();
// set the private attributes of this control
// these attributes are private for this control and are for internal use only
// and will not be rendered by the _render_attributes() method
$this->private_attributes = array(
'disable_xss_filters',
'locked',
'files',
);
// set the default attributes for the text control
// put them in the order you'd like them rendered
$this->set_attributes(
array(
'type' => 'file',
'name' => $id,
'id' => $id,
'class' => 'control file',
)
);
// if "class" is amongst user specified attributes
if (is_array($attributes) && isset($attributes['class'])) {
// we need to set the "class" attribute like this, so it doesn't overwrite previous values
$this->set_attributes(array('class' => $attributes['class']), false);
// make sure we don't set it again below
unset($attributes['class']);
}
// sets user specified attributes for the control
$this->set_attributes($attributes);
}
/**
* Generates the control's HTML code.
*
* <i>This method is automatically called by the {@link Zebra_Form::render() render()} method!</i>
*
* @return string The control's HTML code
*/
function toHTML()
{
// all file upload controls must have the "upload" rule set or we trigger an error
if (!isset($this->rules['upload'])) _zebra_form_show_error('The control named <strong>"' . $this->attributes['name'] . '"</strong> in form <strong>"' . $this->form_properties['name'] . '"</strong> must have the <em>"upload"</em> rule set', E_USER_ERROR);
// if the "image" rule is set
if (isset($this->rules['image']))
// these are the allowed file extensions
$allowed_file_types = array('jpe', 'jpg', 'jpeg', 'png', 'gif');
// if the "filetype" rule is set
elseif (isset($this->rules['filetype']))
// get the array of allowed file extensions
$allowed_file_types = array_map(create_function('$value', 'return trim($value);'), explode(',', $this->rules['filetype'][0]));
// if file selection should be restricted to certain file types
if (isset($allowed_file_types)) {
$mimes = array();
// iterate through allowed extensions
foreach ($allowed_file_types as $extension)
// get the mime type for each extension
if (isset($this->form_properties['mimes'][$extension]))
$mimes = array_merge($mimes, (array)$this->form_properties['mimes'][$extension]);
// set the "accept" attribute
// see http://www.whatwg.org/specs/web-apps/current-work/multipage/states-of-the-type-attribute.html#file-upload-state-%28type=file%29
// at the time of writing, on December 30, 2012, this was only working on Chrome 23 and IE 10
$this->set_attributes(array('accept' => '.' . implode(',.', $allowed_file_types) . ',' . implode(',', $mimes)));
}
// show the file upload control
$output = '<input ' . $this->_render_attributes() . ($this->form_properties['doctype'] == 'xhtml' ? '/' : '') . '>';
// return the generated output
return $output;
}
}
?>

View File

@@ -0,0 +1,102 @@
<?php
/**
* Class for hidden controls.
*
* @author Stefan Gabos <contact@stefangabos.ro>
* @copyright (c) 2006 - 2016 Stefan Gabos
* @package Controls
*/
class Zebra_Form_Hidden extends Zebra_Form_Control
{
/**
* Adds an <input type="hidden"> control to the form.
*
* <b>Do not instantiate this class directly! Use the {@link Zebra_Form::add() add()} method instead!</b>
*
* <code>
* // create a new form
* $form = new Zebra_Form('my_form');
*
* // add a hidden control to the form
* $obj = $form->add('hidden', 'my_hidden', 'Secret value');
*
* // don't forget to always call this method before rendering the form
* if ($form->validate()) {
* // put code here
* }
*
* // output the form using an automatically generated template
* $form->render();
* </code>
*
* @param string $id Unique name to identify the control in the form.
*
* The control's <b>name</b> attribute will be the same as the <b>id</b> attribute!
*
* This is the name to be used when referring to the control's value in the
* POST/GET superglobals, after the form is submitted.
*
* <b>Hidden controls are automatically rendered when the {@link Zebra_Form::render() render()}
* method is called!</b><br>
* <b>Do not print them in template files!</b>
*
* @param string $default (Optional) Default value of the text box.
*
* @return void
*/
function __construct($id, $default = '')
{
// call the constructor of the parent class
parent::__construct();
// set the private attributes of this control
// these attributes are private for this control and are for internal use only
// and will not be rendered by the _render_attributes() method
$this->private_attributes = array(
'disable_xss_filters',
'locked',
);
// set the default attributes for the hidden control
// put them in the order you'd like them rendered
// notice that if control's name is 'MAX_FILE_SIZE' we'll generate a random ID attribute for the control
// as, with multiple forms having upload controls on them, this hidden control appears as many times as the
// forms do and we don't want to have the same ID assigned to multiple controls
$this->set_attributes(
array(
'type' => 'hidden',
'name' => $id,
'id' => ($id != 'MAX_FILE_SIZE' ? $id : 'mfs_' . rand(0, 100000)),
'value' => $default,
)
);
}
/**
* Generates the control's HTML code.
*
* <i>This method is automatically called by the {@link Zebra_Form::render() render()} method!</i>
*
* @return string The control's HTML code
*/
function toHTML()
{
return '<input ' . $this->_render_attributes() . ($this->form_properties['doctype'] == 'xhtml' ? '/' : '') . '>';
}
}
?>

View File

@@ -0,0 +1,144 @@
<?php
/**
* Class for image controls.
*
* @author Stefan Gabos <contact@stefangabos.ro>
* @copyright (c) 2006 - 2016 Stefan Gabos
* @package Controls
*/
class Zebra_Form_Image extends Zebra_Form_Control
{
/**
* Adds an <input type="image"> control to the form.
*
* <b>Do not instantiate this class directly! Use the {@link Zebra_Form::add() add()} method instead!</b>
*
* <code>
* // create a new form
* $form = new Zebra_Form('my_form');
*
* // add an image control to the form
* $obj = $form->add('image', 'my_image', 'path/to/image');
*
* // don't forget to always call this method before rendering the form
* if ($form->validate()) {
* // put code here
* }
*
* // output the form using an automatically generated template
* $form->render();
* </code>
*
* @param string $id Unique name to identify the control in the form.
*
* The control's <b>name</b> attribute will be the same as the <b>id</b> attribute!
*
* This is the name to be used when referring to the control's value in the
* POST/GET superglobals, after the form is submitted.
*
* This is also the name of the variable to be used in custom template files, in
* order to display the control.
*
* <code>
* // in a template file, in order to print the generated HTML
* // for a control named "my_image", one would use:
* echo $my_image;
* </code>
*
* @param string $src (Optional) Path to an image file.
*
* @param array $attributes (Optional) An array of attributes valid for
* {@link http://www.w3.org/TR/REC-html40/interact/forms.html#h-17.4 input}
* controls (size, readonly, style, etc)
*
* Must be specified as an associative array, in the form of <i>attribute => value</i>.
* <code>
* // setting the "alt" attribute
* $obj = $form->add(
* 'image',
* 'my_image',
* 'path/to/image',
* array(
* 'alt' => 'Click to submit form'
* )
* );
* </code>
*
* See {@link Zebra_Form_Control::set_attributes() set_attributes()} on how to set
* attributes, other than through the constructor.
*
* The following attributes are automatically set when the control is created and
* should not be altered manually:<br>
*
* <b>type</b>, <b>id</b>, <b>name</b>, <b>src</b>, <b>class</b>
*
* @return void
*/
function __construct($id, $src, $attributes = '')
{
// call the constructor of the parent class
parent::__construct();
// set the private attributes of this control
// these attributes are private for this control and are for internal use only
// and will not be rendered by the _render_attributes() method
$this->private_attributes = array(
'disable_xss_filters',
'locked',
);
// set the default attributes for the image control
// put them in the order you'd like them rendered
$this->set_attributes(
array(
'alt' => $id,
'class' => 'image',
'id' => $id,
'name' => $id,
'src' => $src,
'type' => 'image',
)
);
// if "class" is amongst user specified attributes
if (is_array($attributes) && isset($attributes['class'])) {
// we need to set the "class" attribute like this, so it doesn't overwrite previous values
$this->set_attributes(array('class' => $attributes['class']), false);
// make sure we don't set it again below
unset($attributes['class']);
}
// sets user specified attributes for the table cell
$this->set_attributes($attributes);
}
/**
* Generates the control's HTML code.
*
* <i>This method is automatically called by the {@link Zebra_Form::render() render()} method!</i>
*
* @return string The control's HTML code
*/
function toHTML()
{
return '<input ' . $this->_render_attributes() . ($this->form_properties['doctype'] == 'xhtml' ? '/' : '') . '>';
}
}
?>

View File

@@ -0,0 +1,192 @@
<?php
/**
* Class for labels
*
* @author Stefan Gabos <contact@stefangabos.ro>
* @copyright (c) 2006 - 2016 Stefan Gabos
* @package Controls
*/
class Zebra_Form_Label extends Zebra_Form_Control
{
/**
* Add an <label> control to the form.
*
* <b>Do not instantiate this class directly! Use the {@link Zebra_Form::add() add()} method instead!</b>
*
* <code>
* // create a new form
* $form = new Zebra_Form('my_form');
*
* // add a label, attached to a textbox control
* $form->add('label', 'label_my_text', 'my_text', 'Enter some text:');
*
* // add a text control to the form
* $obj = $form->add('text', 'my_text');
*
* // don't forget to always call this method before rendering the form
* if ($form->validate()) {
* // put code here
* }
*
* // output the form using an automatically generated template
* $form->render();
* </code>
*
* @param string $id Unique name to identify the control in the form.
*
* This is the name of the variable to be used in the template file, containing
* the generated HTML for the control.
*
* <code>
* // in a template file, in order to print the generated HTML
* // for a control named "my_label", one would use:
* echo $my_label;
* </code>
*
* @param string $attach_to The <b>id</b> attribute of the control to attach the note to.
*
* <i>Notice that this must be the "id" attribute of the control you are attaching
* the label to, and not the "name" attribute!</i>
*
* This is important as while most of the controls have their <b>id</b> attribute
* set to the same value as their <b>name</b> attribute, for {@link Zebra_Form_Checkbox checkboxes},
* {@link Zebra_Form_Select selects} and {@link Zebra_Form_Radio radio&nbsp;buttons} this
* is different.
*
* <b>Exception to the rule:</b>
*
* Just like in the case of {@link Zebra_Form_Note notes}, if you want a <b>master</b>
* label, a label that is attached to a <b>group</b> of checkboxes/radio buttons
* rather than individual controls, this attribute must instead refer to the <b>name</b>
* of the controls (which, for groups of checkboxes/radio buttons, is one and the same).
* This is important because if the group of checkboxes/radio buttons have the
* <i>required</i> rule set, this is the only way in which the "required" symbol
* (the red asterisk) will be attached to the master label instead of being attached
* to the first checkbox/radio button from the group.
*
* @param mixed $caption Caption of the label.
*
* <i>Putting a $ (dollar) sign before a character will turn that specific character into
* the accesskey.</i><br>
* <i>If you need the dollar sign in the label, escape it with</i> \ <i>(backslash)</i>
*
* @param array $attributes (Optional) An array of attributes valid for
* {@link http://www.w3.org/TR/REC-html40/interact/forms.html#edef-LABEL label}
* elements (style, etc)
*
* Must be specified as an associative array, in the form of <i>attribute => value</i>.
* <code>
* // setting the "style" attribute
* $obj = $form->add(
* 'label',
* 'label_my_text',
* 'my_text',
* 'My Label:'
* array(
* 'style' => 'font-weight: normal'
* )
* );
* </code>
*
* <b>Special attribute:</b>
*
* When setting the special attribute <b>inside</b> to <b>true</b>, the label will
* appear inside the control is attached to (if the control the label is attached to
* is a {@link Zebra_Form_Text textbox} or a {@link Zebra_Form_Textarea textarea}) and
* will disappear when the control will receive focus. When the "inside" attribute is
* set to TRUE, the label will not be available in the template file as it will be
* contained by the control the label is attached to!
*
* <code>
* $form->add('label', 'my_label', 'my_control', 'My Label:', array('inside' => true));
* </code>
*
* <samp>Sometimes, when using floats, the inside-labels will not be correctly positioned
* as jQuery will return invalid numbers for the parent element's position; If this is
* the case, make sure you enclose the form in a div with position:relative to fix
* this issue.</samp>
*
* See {@link Zebra_Form_Control::set_attributes() set_attributes()} on how to set
* attributes, other than through the constructor.
*
* The following attributes are automatically set when the control is created and
* should not be altered manually:<br>
* <b>id</b>, <b>for</b>
*
* @return void
*/
function __construct($id, $attach_to, $caption, $attributes = '')
{
// call the constructor of the parent class
parent::__construct();
// set the private attributes of this control
// these attributes are private for this control and are for internal use only
// set the private attributes of this control
// these attributes are private for this control and are for internal use only
$this->private_attributes = array(
'disable_xss_filters',
'for_group',
'inside',
'label',
'locked',
'name',
'type',
);
// set the default attributes for the label
$this->set_attributes(
array(
'for' => $attach_to,
'id' => $id,
'label' => $caption,
'name' => $id,
'type' => 'label',
)
);
// sets user specified attributes for the table cell
$this->set_attributes($attributes);
}
/**
* Generates the control's HTML code.
*
* <i>This method is automatically called by the {@link Zebra_Form::render() render()} method!</i>
*
* @return string The control's HTML code
*/
function toHTML()
{
// get private attributes
$attributes = $this->get_attributes('label');
// if access key needs to be showed
if (preg_match('/(?<!\\\)\$(.{1})/', $attributes['label'], $matches) > 0) {
// set the requested accesskey
$this->set_attributes(array('accesskey' => strtolower($matches[1])));
// make the accesskey visible
$attributes['label'] = preg_replace('/\$(.{1})/', '<span class="underline">$1</span>', $attributes['label']);
}
return '<label ' . $this->_render_attributes() . '>' . preg_replace('/\\\\\$/', '$', $attributes['label']) . '</label>';
}
}
?>

View File

@@ -0,0 +1,163 @@
<?php
/**
* Class for notes attached to controls
*
* @author Stefan Gabos <contact@stefangabos.ro>
* @copyright (c) 2006 - 2016 Stefan Gabos
* @package Controls
*/
class Zebra_Form_Note extends Zebra_Form_Control
{
/**
* Adds a "note" to the form, attached to a control.
*
* <b>Do not instantiate this class directly! Use the {@link Zebra_Form::add() add()} method instead!</b>
*
* <code>
* // create a new form
* $form = new Zebra_Form('my_form');
*
* // add a text control to the form
* $obj = $form->add('text', 'my_text');
*
* // attach a note to the textbox control
* $form->add('note', 'note_my_text', 'my_text', 'Enter some text in the field above');
*
* // don't forget to always call this method before rendering the form
* if ($form->validate()) {
* // put code here
* }
*
* // output the form using an automatically generated template
* $form->render();
* </code>
*
* @param string $id Unique name to identify the control in the form.
*
* This is the name of the variable to be used in the template file, containing
* the generated HTML for the control.
*
* <code>
* // in a template file, in order to print the generated HTML
* // for a control named "my_note", one would use:
* echo $my_note;
* </code>
*
* @param string $attach_to The <b>id</b> attribute of the control to attach the note to.
*
* <i>Notice that this must be the "id" attribute of the control you are attaching
* the label to, and not the "name" attribute!</i>
*
* This is important as while most of the controls have their <b>id</b> attribute
* set to the same value as their <b>name</b> attribute, for {@link Zebra_Form_Checkbox checkboxes},
* {@link Zebra_Form_Select selects} and {@link Zebra_Form_Radio radio&nbsp;buttons} this
* is different.
*
* <b>Exception to the rule:</b>
*
* Just like in the case of {@link Zebra_Form_Label labels}, if you want a <b>master</b>
* note, a note that is attached to a <b>group</b> of checkboxes/radio buttons rather than
* individual controls, this attribute must instead refer to the <b>name</b> of the
* controls (which, for groups of checkboxes/radio buttons, is one and the same).
*
* @param string $caption Content of the note (can be both plain text and/or HTML)
*
* @param array $attributes (Optional) An array of attributes valid for
* {@link http://www.w3.org/TR/REC-html40/struct/global.html#h-7.5.4 div}
* elements (style, etc)
*
* Must be specified as an associative array, in the form of <i>attribute => value</i>.
* <code>
* // setting the "style" attribute
* $obj = $form->add(
* 'note',
* 'note_my_text',
* 'my_text',
* array(
* 'style' => 'width:250px'
* )
* );
* </code>
*
* See {@link Zebra_Form_Control::set_attributes() set_attributes()} on how to set
* attributes, other than through the constructor.
*
* The following attributes are automatically set when the control is created and
* should not be altered manually:<br>
* <b>class</b>
*
* @return void
*/
function __construct($id, $attach_to, $caption, $attributes = '')
{
// call the constructor of the parent class
parent::__construct();
// set the private attributes of this control
// these attributes are private for this control and are for internal use only
$this->private_attributes = array(
'caption',
'disable_xss_filters',
'locked',
'for',
'name',
'type',
);
// set the default attributes for the HTML control
$this->set_attributes(
array(
'class' => 'note',
'caption' => $caption,
'for' => $attach_to,
'id' => $id,
'name' => $id,
'type' => 'note',
)
);
// if "class" is amongst user specified attributes
if (is_array($attributes) && isset($attributes['class'])) {
// we need to set the "class" attribute like this, so it doesn't overwrite previous values
$this->set_attributes(array('class' => $attributes['class']), false);
// make sure we don't set it again below
unset($attributes['class']);
}
// sets user specified attributes for the control
$this->set_attributes($attributes);
}
/**
* Generates the control's HTML code.
*
* <i>This method is automatically called by the {@link Zebra_Form::render() render()} method!</i>
*
* @return string The control's HTML code
*/
function toHTML()
{
$attributes = $this->get_attributes('caption');
return '<div ' . $this->_render_attributes() . '>' . $attributes['caption'] . '</div>';
}
}
?>

View File

@@ -0,0 +1,178 @@
<?php
/**
* Class for password controls.
*
* @author Stefan Gabos <contact@stefangabos.ro>
* @copyright (c) 2006 - 2016 Stefan Gabos
* @package Controls
*/
class Zebra_Form_Password extends Zebra_Form_Control
{
/**
* Adds an <input type="password"> control to the form.
*
* <b>Do not instantiate this class directly! Use the {@link Zebra_Form::add() add()} method instead!</b>
*
* <code>
* // create a new form
* $form = new Zebra_Form('my_form');
*
* // add a password control to the form
* $obj = $form->add('password', 'my_password');
*
* // don't forget to always call this method before rendering the form
* if ($form->validate()) {
* // put code here
* }
*
* // output the form using an automatically generated template
* $form->render();
* </code>
*
* @param string $id Unique name to identify the control in the form.
*
* The control's <b>name</b> attribute will be the same as the <b>id</b> attribute!
*
* This is the name to be used when referring to the control's value in the
* POST/GET superglobals, after the form is submitted.
*
* This is also the name of the variable to be used in custom template files, in
* order to display the control.
*
* <code>
* // in a template file, in order to print the generated HTML
* // for a control named "my_password", one would use:
* echo $my_password;
* </code>
*
* @param string $default (Optional) Default value of the password field.
*
* @param array $attributes (Optional) An array of attributes valid for
* {@link http://www.w3.org/TR/REC-html40/interact/forms.html#h-17.4 input}
* controls (size, readonly, style, etc)
*
* Must be specified as an associative array, in the form of <i>attribute => value</i>.
* <code>
* // setting the "disabled" attribute
* $obj = $form->add(
* 'password',
* 'my_password',
* '',
* array(
* 'disabled' => 'disabled'
* )
* );
* </code>
*
* There's a special <b>data-prefix</b> attribute that you can use to add <i>uneditable
* prefixes</i> to input fields (text, images, or plain HTML), as seen in the image
* below. It works by injecting an absolutely positioned element into the DOM, right
* after the parent element, and then positioning it on the left side of the parent
* element and adjusting the width and the left padding of the parent element, so it
* looks like the prefix is part of the parent element.
*
* <i>If the prefix is plain text or HTML code, it will be contained in a <div> tag
* having the class </i> <b>Zebra_Form_Input_Prefix</b><i>; if the prefix is a path to an
* image, it will be an <img> tag having the class </i> <b>Zebra_Form_Input_Prefix</b><i>.</i>
*
* <samp>For anything other than plain text, you must use CSS to set the width and
* height of the prefix, or it will not be correctly positioned because when the image
* is not cached by the browser the code taking care of centering the image will
* be executed before the image is loaded by the browser and it will not know the
* image's width and height!</samp>
*
* {@img src=../media/zebra-form-prefix.jpg class=graphic}
*
* <code>
* // add simple text
* // style the text through the Zebra_Form_Input_Prefix class
* $form->add('password', 'my_password', '', array('data-prefix' => 'Hash:'));
*
* // add images
* // set the image's width and height through the img.Zebra_Form_Input_Prefix class
* // in your CSS or the image will not be correctly positioned!
* $form->add('password', 'my_password', '', array('data-prefix' => 'img:path/to/image'));
*
* // add html - useful when using sprites
* // again, make sure that you set somewhere the width and height of the prefix!
* $form->add('password', 'my_password', '', array('data-prefix' => '<div class="sprite image1"></div>'));
* $form->add('password', 'my_password', '', array('data-prefix' => '<div class="sprite image2"></div>'));
* </code>
*
* See {@link Zebra_Form_Control::set_attributes() set_attributes()} on how to set
* attributes, other than through the constructor.
*
* The following attributes are automatically set when the control is created and
* should not be altered manually:<br>
*
* <b>type</b>, <b>id</b>, <b>name</b>, <b>value</b>, <b>class</b>
*
* @return void
*/
function __construct($id, $default = '', $attributes = '')
{
// call the constructor of the parent class
parent::__construct();
// set the private attributes of this control
// these attributes are private for this control and are for internal use only
// and will not be rendered by the _render_attributes() method
$this->private_attributes = array(
'default_value',
'disable_xss_filters',
'locked',
);
// set the default attributes for the button control
$this->set_attributes(
array(
'type' => 'password',
'name' => $id,
'id' => $id,
'value' => $default,
'class' => 'control password',
)
);
// if "class" is amongst user specified attributes
if (is_array($attributes) && isset($attributes['class'])) {
// we need to set the "class" attribute like this, so it doesn't overwrite previous values
$this->set_attributes(array('class' => $attributes['class']), false);
// make sure we don't set it again below
unset($attributes['class']);
}
// sets user specified attributes for the control
$this->set_attributes($attributes);
}
/**
* Generates the control's HTML code.
*
* <i>This method is automatically called by the {@link Zebra_Form::render() render()} method!</i>
*
* @return string The control's HTML code
*/
function toHTML()
{
return '<input ' . $this->_render_attributes() . ($this->form_properties['doctype'] == 'xhtml' ? '/' : '') . '>';
}
}
?>

View File

@@ -0,0 +1,229 @@
<?php
/**
* Class for radio button controls.
*
* @author Stefan Gabos <contact@stefangabos.ro>
* @copyright (c) 2006 - 2016 Stefan Gabos
* @package Controls
*/
class Zebra_Form_Radio extends Zebra_Form_Control
{
/**
* Adds an <input type="radio"> control to the form.
*
* <b>Do not instantiate this class directly! Use the {@link Zebra_Form::add() add()} method instead!</b>
*
* <code>
* // create a new form
* $form = new Zebra_Form('my_form');
*
* // single radio button
* $obj = $form->add('radio', 'myradio', 'my_radio_value');
*
* // multiple radio buttons
* // notice that is "radios" instead of "radio"
* // radio buttons' values will be "0", "1" and "2", respectively, and will be available in a custom template like
* // "myradio_0", "myradio_1" and "myradio_2".
* // label controls will be automatically created having the names "label_myradio_0", "label_myradio_1" and
* // "label_myradio_2" (label + underscore + control name + underscore + value with anything else other than
* // letters and numbers replaced with underscores - also, note that multiple consecutive underscores will be
* // replaced by a single one)
* // $obj is a reference to the first radio button
* $obj = $form->add('radios', 'myradio',
* array(
* 'Value 1',
* 'Value 2',
* 'Value 3'
* )
* );
*
* // multiple radio buttons with specific indexes
* // radio buttons' values will be "v1", "v2" and "v3", respectively, and will be available in a custom template
* // like "myradio_v1", "myradio_v2" and "myradio_v3".
* // label controls will be automatically created having the names "label_myradio_v1", "label_myradio_v2" and
* // "label_myradio_v3" (label + underscore + control name + underscore + value with anything else other than
* // letters and numbers replaced with underscores - also, note that multiple consecutive underscores will be
* // replaced by a single one)
* $obj = $form->add('radios', 'myradio',
* array(
* 'v1' => 'Value 1',
* 'v2' => 'Value 2',
* 'v3' => 'Value 3'
* )
* );
*
* // multiple radio buttons with preselected value
* // "Value 2" will be the preselected value
* // note that for preselecting values you must use the actual indexes of the values, if available, (like
* // in the current example) or the default, zero-based index, otherwise (like in the next example)
* $obj = $form->add('radios', 'myradio',
* array(
* 'v1' => 'Value 1',
* 'v2' => 'Value 2',
* 'v3' => 'Value 3'
* ),
* 'v2' // note the index!
* );
*
* // "Value 2" will be the preselected value.
* // note that for preselecting values you must use the actual indexes of the values, if available, (like
* // in the example above) or the default, zero-based index, otherwise (like in the current example)
* $obj = $form->add('radios', 'myradio',
* array(
* 'Value 1',
* 'Value 2',
* 'Value 3'
* ),
* 1 // note the index!
* );
*
* // custom classes (or other attributes) can also be added to all of the elements by specifying a 4th argument;
* // this needs to be specified in the same way as you would by calling {@link set_attributes()} method:
* $obj = $form->add('radios', 'myradio',
* array(
* '1' => 'Value 1',
* '2' => 'Value 2',
* '3' => 'Value 3',
* ),
* '', // no default value
* array('class' => 'my_custom_class')
* );
*
* // don't forget to always call this method before rendering the form
* if ($form->validate()) {
* // put code here
* }
*
* // output the form using an automatically generated template
* $form->render();
* </code>
*
* <samp>By default, for checkboxes, radio buttons and select boxes, the library will prevent the submission of other
* values than those declared when creating the form, by triggering the error: "SPAM attempt detected!". Therefore,
* if you plan on adding/removing values dynamically, from JavaScript, you will have to call the
* {@link Zebra_Form_Control::disable_spam_filter() disable_spam_filter()} method to prevent that from happening!</samp>
*
* @param string $id Unique name to identify the control in the form.
*
* The control's <b>name</b> attribute will be as indicated by <i>$id</i>
* argument while the control's <b>id</b> attribute will be <i>$id</i> followd by an
* underscore and followed by <i>$value</i> with all the spaces replaced by
* <i>underscores</i>.
*
* So, if the <i>$id</i> arguments is "my_radio" and the <i>$value</i> argument
* is "value 1", the control's <b>id</b> attribute will be <b>my_radio_value_1</b>.
*
* This is the name to be used when referring to the control's value in the
* POST/GET superglobals, after the form is submitted.
*
* This is also the name of the variable to be used in custom template files, in
* order to display the control.
*
* <code>
* // in a template file, in order to print the generated HTML
* // for a control named "my_radio" and having the value of "value 1",
* // one would use:
* echo $my_radio_value_1;
* </code>
*
* <i>Note that when adding the required rule to a group of radio buttons (radio
* buttons sharing the same name), it is sufficient to add the rule to the first
* radio button!</i>
*
* @param mixed $value Value of the radio button.
*
* @param array $attributes (Optional) An array of attributes valid for
* {@link http://www.w3.org/TR/REC-html40/interact/forms.html#h-17.4 input}
* controls (disabled, readonly, style, etc)
*
* Must be specified as an associative array, in the form of <i>attribute => value</i>.
* <code>
* // setting the "checked" attribute
* $obj = $form->add(
* 'radio',
* 'my_radio',
* 'v1',
* array(
* 'checked' => 'checked'
* )
* );
* </code>
*
* See {@link Zebra_Form_Control::set_attributes() set_attributes()} on how to set
* attributes, other than through the constructor.
*
* The following attributes are automatically set when the control is created and
* should not be altered manually:<br>
*
* <b>type</b>, <b>id</b>, <b>name</b>, <b>value</b>, <b>class</b>
*
* @return void
*/
function __construct($id, $value, $attributes = '')
{
// call the constructor of the parent class
parent::__construct();
// set the private attributes of this control
// these attributes are private for this control and are for internal use only
// and will not be rendered by the _render_attributes() method
$this->private_attributes = array(
'disable_spam_filter',
'disable_xss_filters',
'locked',
);
// set the default attributes for the radio button control
// put them in the order you'd like them rendered
$this->set_attributes(
array(
'type' => 'radio',
'name' => $id,
'id' => str_replace(' ', '_', $id) . '_' . str_replace(' ', '_', $value),
'value' => $value,
'class' => 'control radio',
)
);
// if "class" is amongst user specified attributes
if (is_array($attributes) && isset($attributes['class'])) {
// we need to set the "class" attribute like this, so it doesn't overwrite previous values
$this->set_attributes(array('class' => $attributes['class']), false);
// make sure we don't set it again below
unset($attributes['class']);
}
// sets user specified attributes for the control
$this->set_attributes($attributes);
}
/**
* Generates the control's HTML code.
*
* <i>This method is automatically called by the {@link Zebra_Form::render() render()} method!</i>
*
* @return string The control's HTML code
*/
function toHTML()
{
return '<input ' . $this->_render_attributes() . ($this->form_properties['doctype'] == 'xhtml' ? '/' : '') . '>';
}
}
?>

View File

@@ -0,0 +1,142 @@
<?php
/**
* Class for reset button controls.
*
* @author Stefan Gabos <contact@stefangabos.ro>
* @copyright (c) 2006 - 2016 Stefan Gabos
* @package Controls
*/
class Zebra_Form_Reset extends Zebra_Form_Control
{
/**
* Adds an <input type="reset"> control to the form.
*
* <b>Do not instantiate this class directly! Use the {@link Zebra_Form::add() add()} method instead!</b>
*
* <code>
* // create a new form
* $form = new Zebra_Form('my_form');
*
* // add a reset control to the form
* $obj = $form->add('reset', 'my_reset', 'Reset');
*
* // don't forget to always call this method before rendering the form
* if ($form->validate()) {
* // put code here
* }
*
* // output the form using an automatically generated template
* $form->render();
* </code>
*
* @param string $id Unique name to identify the control in the form.
*
* The control's <b>name</b> attribute will be the same as the <b>id</b> attribute!
*
* This is the name to be used when referring to the control's value in the
* POST/GET superglobals, after the form is submitted.
*
* This is also the name of the variable to be used in custom template files, in
* order to display the control.
*
* <code>
* // in a template file, in order to print the generated HTML
* // for a control named "my_reset", one would use:
* echo $my_reset;
* </code>
*
* @param string $caption Caption of the reset button control.
*
* @param array $attributes (Optional) An array of attributes valid for
* {@link http://www.w3.org/TR/REC-html40/interact/forms.html#h-17.4 input}
* controls (size, readonly, style, etc)
*
* Must be specified as an associative array, in the form of <i>attribute => value</i>.
* <code>
* // setting the "alt" attribute
* $obj = $form->add(
* 'reset',
* 'my_reset',
* 'Reset',
* array(
* 'alt' => 'Click to reset values'
* )
* );
* </code>
*
* See {@link Zebra_Form_Control::set_attributes() set_attributes()} on how to set
* attributes, other than through the constructor.
*
* The following attributes are automatically set when the control is created and
* should not be altered manually:<br>
* <b>type</b>, <b>id</b>, <b>name</b>, <b>value</b>, <b>class</b>
*
* @return void
*/
function __construct($id, $caption, $attributes = '')
{
// call the constructor of the parent class
parent::__construct();
// set the private attributes of this control
// these attributes are private for this control and are for internal use only
// and will not be rendered by the _render_attributes() method
$this->private_attributes = array(
'disable_xss_filters',
'locked',
);
// set the default attributes for the reset button control
// put them in the order you'd like them rendered
$this->set_attributes(
array(
'type' => 'reset',
'name' => $id,
'id' => $id,
'value' => $caption,
'class' => 'reset',
)
);
// if "class" is amongst user specified attributes
if (is_array($attributes) && isset($attributes['class'])) {
// we need to set the "class" attribute like this, so it doesn't overwrite previous values
$this->set_attributes(array('class' => $attributes['class']), false);
// make sure we don't set it again below
unset($attributes['class']);
}
// sets user specified attributes for the control
$this->set_attributes($attributes);
}
/**
* Generates the control's HTML code.
*
* <i>This method is automatically called by the {@link Zebra_Form::render() render()} method!</i>
*
* @return string The control's HTML code
*/
function toHTML()
{
return '<input ' . $this->_render_attributes() . ($this->form_properties['doctype'] == 'xhtml' ? '/' : '') . '>';
}
}
?>

View File

@@ -0,0 +1,385 @@
<?php
/**
* Class for select box controls.
*
* @author Stefan Gabos <contact@stefangabos.ro>
* @copyright (c) 2006 - 2016 Stefan Gabos
* @package Controls
*/
class Zebra_Form_Select extends Zebra_Form_Control
{
/**
* Adds an <select> control to the form.
*
* <b>Do not instantiate this class directly! Use the {@link Zebra_Form::add() add()} method instead!</b>
*
* By default, unless the <b>multiple</b> attribute is set, the control will have a default first option added
* automatically inviting users to select one of the available options. Default value for English is
* "<i>-&nbsp;select&nbsp;-</i>" taken from the language file - see the {@link Zebra_Form::language() language()}
* method. If you don't want it or want to set it at runtime, set the <i>overwrite</i> argument to TRUE when calling
* the {@link add_options()} method.
*
* <code>
* // create a new form
* $form = new Zebra_Form('my_form');
*
* // single-option select box
* $obj = $form->add('select', 'my_select');
*
* // add selectable values with default indexes
* // values will be "0", "1" and "2", respectively
* // a default first value, "- select -" (language dependent) will also be added
* $obj->add_options(array(
* 'Value 1',
* 'Value 2',
* 'Value 3'
* ));
*
* // single-option select box
* $obj = $form->add('select', 'my_select2');
*
* // add selectable values with specific indexes
* // values will be "v1", "v2" and "v3", respectively
* // a default first value, "- select -" (language dependent) will also be added
* $obj->add_options(array(
* 'v1' => 'Value 1',
* 'v2' => 'Value 2',
* 'v3' => 'Value 3'
* ));
*
* // single-option select box with the second value selected
* $obj = $form->add('select', 'my_select3', 'v2');
*
* // add selectable values with specific indexes
* // values will be "v1", "v2" and "v3", respectively
* // also, overwrite the language-specific default first value (notice the boolean TRUE at the end)
* $obj->add_options(array(
* '' => '- select a value -',
* 'v1' => 'Value 1',
* 'v2' => 'Value 2',
* 'v3' => 'Value 3'
* ), true);
*
* // multi-option select box with the first two options selected
* $obj = $form->add('select', 'my_select4[]', array('v1', 'v2'), array('multiple' => 'multiple'));
*
* // add selectable values with specific indexes
* // values will be "v1", "v2" and "v3", respectively
* $obj->add_options(array(
* 'v1' => 'Value 1',
* 'v2' => 'Value 2',
* 'v3' => 'Value 3'
* ));
*
* // don't forget to always call this method before rendering the form
* if ($form->validate()) {
* // put code here
* }
*
* // output the form using an automatically generated template
* $form->render();
* </code>
*
* <samp>By default, for checkboxes, radio buttons and select boxes, the library will prevent the submission of other
* values than those declared when creating the form, by triggering the error: "SPAM attempt detected!". Therefore,
* if you plan on adding/removing values dynamically, from JavaScript, you will have to call the
* {@link Zebra_Form_Control::disable_spam_filter() disable_spam_filter()} method to prevent that from happening!</samp>
*
* @param string $id Unique name to identify the control in the form.
*
* The control's <b>name</b> attribute will be as specified by the <i>$id</i>
* argument.<br>
* The <b>id</b> attribute will be as specified by the <i>$id</i> argument but with
* square brackets trimmed off (if any).
*
* This is the name to be used when referring to the control's value in the
* POST/GET superglobals, after the form is submitted.
*
* This is also the name of the variable (again, with square brackets trimmed off
* if it's the case) to be used in the template file, containing the generated HTML
* for the control.
*
* <code>
* // in a template file, in order to print the generated HTML
* // for a control named "my_select", one would use:
* echo $my_select;
* </code>
*
* @param mixed $default (Optional) Default selected option.
*
* This argument can also be an array in case the <b>multiple</b> attribute is set
* and multiple options need to be preselected by default.
*
* @param array $attributes (Optional) An array of attributes valid for
* {@link http://www.w3.org/TR/REC-html40/interact/forms.html#edef-SELECT select}
* controls (multiple, readonly, style, etc)
*
* Must be specified as an associative array, in the form of <i>attribute => value</i>.
* <code>
* // setting the "multiple" attribute
* $obj = $form->add(
* 'select',
* 'my_select',
* '',
* array(
* 'multiple' => 'multiple'
* )
* );
* </code>
*
* <b>Special attribute:</b>
*
* When setting the special attribute <b>other</b> to <b>true</b>, a
* {@link Zebra_Form_Text textbox} control will be automatically created having the
* name <i>[id]_other</i> where [id] is the select control's <b>id</b> attribute.
* The text box will be hidden until the user selects the automatically added
* <i>Other...</i> option (language dependent) from the selectable options. The
* option's value will be <b>other</b>. If the template is not automatically
* generated you will have to manually add the automatically generated control to
* the template.
*
* See {@link Zebra_Form_Control::set_attributes() set_attributes()} on how to set
* attributes, other than through the constructor.
*
* The following attributes are automatically set when the control is created and
* should not be altered manually:<br>
*
* <b>id</b>, <b>name</b>
*
* @param string $default_other The default value in the "other" field (if the "other" attribute is set to true,
* see above)
*
* @return void
*/
function __construct($id, $default = '', $attributes = '', $default_other = '')
{
// call the constructor of the parent class
parent::__construct();
// set the private attributes of this control
// these attributes are private for this control and are for internal use only
// and will not be rendered by the _render_attributes() method
$this->private_attributes = array(
'default_other',
'disable_spam_filter',
'disable_xss_filters',
'locked',
'options',
'other',
'type',
'value',
);
// set the default attributes for the textarea control
// put them in the order you'd like them rendered
$this->set_attributes(
array(
'name' => $id,
'id' => str_replace(array('[', ']'), '', $id),
'class' => 'control',
'options' => array(),
'type' => 'select',
'value' => $default,
'default_other' => $default_other,
)
);
// if "class" is amongst user specified attributes
if (is_array($attributes) && isset($attributes['class'])) {
// we need to set the "class" attribute like this, so it doesn't overwrite previous values
$this->set_attributes(array('class' => $attributes['class']), false);
// make sure we don't set it again below
unset($attributes['class']);
}
// sets user specified attributes for the control
$this->set_attributes($attributes);
}
/**
* Adds options to the select box control
*
* <b>If the "multiple" attribute is not set, the first option will be always considered as the "nothing is selected"
* state of the control!</b>
*
* @param array $options An associative array of options where the key is the value of the option and the
* value is the actual text to be displayed for the option.
*
* <b>Option groups</b> can be set by giving an array of associative arrays as argument:
*
* <code>
* // add as groups:
* $obj->add_options(array(
* 'group' => array('option 1', 'option 2')
* ));
* </code>
*
* @param boolean $overwrite (Optional) By default, succesive calls of this method will appended the options
* given as arguments to the already existing options.
*
* Setting this argument to TRUE will instead overwrite the previously existing options.
*
* Default is FALSE
*
* @return void
*/
function add_options($options, $overwrite = false)
{
// continue only if parameter is an array
if (is_array($options)) {
// get some properties of the select control
$attributes = $this->get_attributes(array('options', 'multiple'));
// if there are no options so far AND
// we're not overwriting existing options AND
// the "multiple" attribute is not set
if (empty($attributes['options']) && $overwrite === false && !isset($attributes['multiple']))
// add the default value
// we'll replace the value with the appropriate language
$options = array('' => $this->form_properties['language']['select']) + $options;
// set the options attribute of the control
$this->set_attributes(
array(
'options' => ($overwrite ? $options : $attributes['options'] + $options)
)
);
// if options are not specified as an array
} else {
// trigger an error message
_zebra_form_show_error('
Selectable values for the <strong>' . $this->attributes['id'] . '</strong> control must be specified as
an array
');
}
}
/**
* Generates the control's HTML code.
*
* <i>This method is automatically called by the {@link Zebra_Form::render() render()} method!</i>
*
* @return string The control's HTML code
*/
function toHTML()
{
// get the options of the select control
$attributes = $this->get_attributes(array('options', 'value', 'multiple', 'other'));
// if select box is not "multi-select" and the "other" attribute is set
if (!isset($attributes['multiple']) && isset($attributes['other']))
// add an extra options to the already existing ones
$attributes['options'] += array('other' => $this->form_properties['language']['other']);
// if the default value, as added when instantiating the object is still there
// or if no options were specified
if (($key = array_search('#replace-with-language#', $attributes['options'])) !== false || empty($attributes['options']))
// put the label from the language file
$attributes['options'][$key] = $this->form_properties['language']['select'];
// use a private, recursive method to generate the select's content
$optContent = $this->_generate($attributes['options'], $attributes['value']);
// return generated HTML
return '<select '. $this->_render_attributes() . '>' . $optContent . '</select>';
}
/**
* Takes the options array and recursively generates options and optiongroups
*
* @return string Resulted HTML code
*
* @access private
*/
private function _generate(&$options, &$selected, $level = 0)
{
$content = '';
// character(s) used for indenting levels
$indent = '&nbsp;&nbsp;';
// iterate through the available options
foreach ($options as $value => $caption) {
// if option has child options
if (is_array($caption)) {
// create a dummy option group (for valid HTML/XHTML we are not allowed to create nested option groups
// and also empty optiongroups are not allowed)
// BUT because in IE7 the "disabled" attribute is not supported and in all versions of IE these
// can't be styled, we will remove them from JavaScript
// having a dummy option in them (the option is disabled and, from CSS, rendered invisible)
$content .= '
<optgroup label="' . str_repeat($indent, $level) . $value . '">
<option disabled="disabled" class="dummy"></option>
</optgroup>
';
// call the method recursively to generate the output for the children options
$content .= $this->_generate($caption, $selected, $level + 1);
// if entry is a standard option
} else {
// create the appropriate code
$content .= '<option value="' . $value . '"' .
// if anything was selected
($selected !== '' && $value !== '' &&
(
// and the current option is selected
(is_array($selected) && in_array($value, $selected)) ||
(!is_array($selected) && (string)$value === (string)$selected)
// set the appropriate attribute
) ? ' selected="selected"' : ''
) . '>' .
// indent appropriately
str_repeat($indent, $level) . $caption . '</option>';
}
}
// return generated content
return $content;
}
}
?>

View File

@@ -0,0 +1,142 @@
<?php
/**
* Class for submit controls.
*
* @author Stefan Gabos <contact@stefangabos.ro>
* @copyright (c) 2006 - 2016 Stefan Gabos
* @package Controls
*/
class Zebra_Form_Submit extends Zebra_Form_Control
{
/**
* Adds an <input type="submit"> control to the form.
*
* <b>Do not instantiate this class directly! Use the {@link Zebra_Form::add() add()} method instead!</b>
*
* <code>
* // create a new form
* $form = new Zebra_Form('my_form');
*
* // add a submit control to the form
* $obj = $form->add('submit', 'my_submit', 'Submit');
*
* // don't forget to always call this method before rendering the form
* if ($form->validate()) {
* // put code here
* }
*
* // output the form using an automatically generated template
* $form->render();
* </code>
*
* @param string $id Unique name to identify the control in the form.
*
* The control's <b>name</b> attribute will be the same as the <b>id</b> attribute!
*
* This is the name to be used when referring to the control's value in the
* POST/GET superglobals, after the form is submitted.
*
* This is also the name of the variable to be used in custom template files, in
* order to display the control.
*
* <code>
* // in a template file, in order to print the generated HTML
* // for a control named "my_submit", one would use:
* echo $my_submit;
* </code>
*
* @param string $caption Caption of the submit button control.
*
* @param array $attributes (Optional) An array of attributes valid for
* {@link http://www.w3.org/TR/REC-html40/interact/forms.html#h-17.4 input}
* controls (size, readonly, style, etc)
*
* Must be specified as an associative array, in the form of <i>attribute => value</i>.
* <code>
* // setting the "alt" attribute
* $obj = $form->add(
* 'submit',
* 'my_submit',
* 'Submit',
* array(
* 'alt' => 'Click to submit values'
* )
* );
* </code>
*
* See {@link Zebra_Form_Control::set_attributes() set_attributes()} on how to set
* attributes, other than through the constructor.
*
* The following attributes are automatically set when the control is created and
* should not be altered manually:<br>
* <b>type</b>, <b>id</b>, <b>name</b>, <b>value</b>, <b>class</b>
*
* @return void
*/
function __construct($id, $caption, $attributes = '')
{
// call the constructor of the parent class
parent::__construct();
// set the private attributes of this control
// these attributes are private for this control and are for internal use only
// and will not be rendered by the _render_attributes() method
$this->private_attributes = array(
'disable_xss_filters',
'locked',
);
// set the default attributes for the submit button control
// put them in the order you'd like them rendered
$this->set_attributes(
array(
'type' => 'submit',
'name' => $id,
'id' => $id,
'value' => $caption,
'class' => 'submit',
)
);
// if "class" is amongst user specified attributes
if (is_array($attributes) && isset($attributes['class'])) {
// we need to set the "class" attribute like this, so it doesn't overwrite previous values
$this->set_attributes(array('class' => $attributes['class']), false);
// make sure we don't set it again below
unset($attributes['class']);
}
// sets user specified attributes for the control
$this->set_attributes($attributes);
}
/**
* Generates the control's HTML code.
*
* <i>This method is automatically called by the {@link Zebra_Form::render() render()} method!</i>
*
* @return string The control's HTML code
*/
function toHTML()
{
return '<input ' . $this->_render_attributes() . ($this->form_properties['doctype'] == 'xhtml' ? '/' : '') . '>';
}
}
?>

View File

@@ -0,0 +1,181 @@
<?php
/**
* Class for text controls.
*
* @author Stefan Gabos <contact@stefangabos.ro>
* @copyright (c) 2006 - 2016 Stefan Gabos
* @package Controls
*/
class Zebra_Form_Text extends Zebra_Form_Control
{
/**
* Adds an <input type="text"> control to the form.
*
* <b>Do not instantiate this class directly! Use the {@link Zebra_Form::add() add()} method instead!</b>
*
* <code>
* // create a new form
* $form = new Zebra_Form('my_form');
*
* // add a text control to the form
* $obj = $form->add('text', 'my_text');
*
* // don't forget to always call this method before rendering the form
* if ($form->validate()) {
* // put code here
* }
*
* // output the form using an automatically generated template
* $form->render();
* </code>
*
* @param string $id Unique name to identify the control in the form.
*
* The control's <b>name</b> attribute will be the same as the <b>id</b> attribute!
*
* This is the name to be used when referring to the control's value in the
* POST/GET superglobals, after the form is submitted.
*
* This is also the name of the variable to be used in custom template files, in
* order to display the control.
*
* <code>
* // in a template file, in order to print the generated HTML
* // for a control named "my_text", one would use:
* echo $my_text;
* </code>
*
* @param string $default (Optional) Default value of the text box.
*
* @param array $attributes (Optional) An array of attributes valid for
* {@link http://www.w3.org/TR/REC-html40/interact/forms.html#h-17.4 input}
* controls (size, readonly, style, etc)
*
* Must be specified as an associative array, in the form of <i>attribute => value</i>.
* <code>
* // setting the "readonly" attribute
* $obj = $form->add(
* 'text',
* 'my_text',
* '',
* array(
* 'readonly' => 'readonly'
* )
* );
* </code>
*
* There's a special <b>data-prefix</b> attribute that you can use to add <i>uneditable
* prefixes</i> to input fields (text, images, or plain HTML), as seen in the image
* below. It works by injecting an absolutely positioned element into the DOM, right
* after the parent element, and then positioning it on the left side of the parent
* element and adjusting the width and the left padding of the parent element, so it
* looks like the prefix is part of the parent element.
*
* <i>If the prefix is plain text or HTML code, it will be contained in a <div> tag
* having the class </i> <b>Zebra_Form_Input_Prefix</b><i>; if the prefix is a path to an
* image, it will be an <img> tag having the class </i> <b>Zebra_Form_Input_Prefix</b><i>.</i>
*
* <samp>For anything other than plain text, you must use CSS to set the width and
* height of the prefix, or it will not be correctly positioned because when the image
* is not cached by the browser the code taking care of centering the image will
* be executed before the image is loaded by the browser and it will not know the
* image's width and height!</samp>
*
* {@img src=../media/zebra-form-prefix.jpg class=graphic}
*
* <code>
* // add simple text
* // style the text through the Zebra_Form_Input_Prefix class
* $form->add('text', 'my_text', '', array('data-prefix' => 'http://'));
* $form->add('text', 'my_text', '', array('data-prefix' => '(+1 917)'));
*
* // add images
* // set the image's width and height through the img.Zebra_Form_Input_Prefix class
* // in your CSS or the image will not be correctly positioned!
* $form->add('text', 'my_text', '', array('data-prefix' => 'img:path/to/image'));
*
* // add html - useful when using sprites
* // again, make sure that you set somewhere the width and height of the prefix!
* $form->add('text', 'my_text', '', array('data-prefix' => '<div class="sprite image1"></div>'));
* $form->add('text', 'my_text', '', array('data-prefix' => '<div class="sprite image2"></div>'));
* </code>
*
* See {@link Zebra_Form_Control::set_attributes() set_attributes()} on how to set
* attributes, other than through the constructor.
*
* The following attributes are automatically set when the control is created and
* should not be altered manually:<br>
*
* <b>type</b>, <b>id</b>, <b>name</b>, <b>value</b>, <b>class</b>
*
* @return void
*/
function __construct($id, $default = '', $attributes = '')
{
// call the constructor of the parent class
parent::__construct();
// set the private attributes of this control
// these attributes are private for this control and are for internal use only
// and will not be rendered by the _render_attributes() method
$this->private_attributes = array(
'disable_xss_filters',
'default_value',
'locked',
);
// set the default attributes for the text control
// put them in the order you'd like them rendered
$this->set_attributes(
array(
'type' => 'text',
'name' => $id,
'id' => $id,
'value' => $default,
'class' => 'control text',
)
);
// if "class" is amongst user specified attributes
if (is_array($attributes) && isset($attributes['class'])) {
// we need to set the "class" attribute like this, so it doesn't overwrite previous values
$this->set_attributes(array('class' => $attributes['class']), false);
// make sure we don't set it again below
unset($attributes['class']);
}
// sets user specified attributes for the control
$this->set_attributes($attributes);
}
/**
* Generates the control's HTML code.
*
* <i>This method is automatically called by the {@link Zebra_Form::render() render()} method!</i>
*
* @return string The control's HTML code
*/
function toHTML()
{
return '<input ' . $this->_render_attributes() . ($this->form_properties['doctype'] == 'xhtml' ? '/' : '') . '>';
}
}
?>

View File

@@ -0,0 +1,151 @@
<?php
/**
* Class for textarea controls
*
* @author Stefan Gabos <contact@stefangabos.ro>
* @copyright (c) 2006 - 2016 Stefan Gabos
* @package Controls
*/
class Zebra_Form_Textarea extends Zebra_Form_Control
{
/**
* Adds an <textarea> control to the form.
*
* <b>Do not instantiate this class directly! Use the {@link Zebra_Form::add() add()} method instead!</b>
*
* <code>
* // create a new form
* $form = new Zebra_Form('my_form');
*
* // add a textarea control to the form
* $obj = $form->add('textarea', 'my_textarea');
*
* // don't forget to always call this method before rendering the form
* if ($form->validate()) {
* // put code here
* }
*
* // output the form using an automatically generated template
* $form->render();
* </code>
*
* @param string $id Unique name to identify the control in the form.
*
* The control's <b>name</b> attribute will be the same as the <b>id</b> attribute!
*
* This is the name to be used when referring to the control's value in the
* POST/GET superglobals, after the form is submitted.
*
* This is also the name of the variable to be used in custom template files, in
* order to display the control.
*
* <code>
* // in a template file, in order to print the generated HTML
* // for a control named "my_textarea", one would use:
* echo $my_textarea;
* </code>
*
* @param string $default (Optional) Default value of the textarea.
*
* @param array $attributes (Optional) An array of attributes valid for
* <b>{@link http://www.w3.org/TR/REC-html40/interact/forms.html#h-17.7 textarea}</b>
* controls (rows, cols, style, etc)
*
* Must be specified as an associative array, in the form of <i>attribute => value</i>.
* <code>
* // setting the "rows" attribute
* $obj = $form->add(
* 'textarea',
* 'my_textarea',
* '',
* array(
* 'rows' => 10
* )
* );
* </code>
*
* See {@link Zebra_Form_Control::set_attributes() set_attributes()} on how to set
* attributes, other than through the constructor.
*
* The following attributes are automatically set when the control is created and
* should not be altered manually:<br>
*
* <b>id</b>, <b>name</b>, <b>class</b>
*
* @return void
*/
function __construct($id, $default = '', $attributes = '')
{
// call the constructor of the parent class
parent::__construct();
// set the private attributes of this control
// these attributes are private for this control and are for internal use only
// and will not be rendered by the _render_attributes() method
$this->private_attributes = array(
'default_value',
'disable_xss_filters',
'locked',
'type',
'value',
);
// set the default attributes for the textarea control
// put them in the order you'd like them rendered
$this->set_attributes(
array(
'name' => $id,
'id' => $id,
'rows' => 5,
'cols' => '80', // used only for passing W3C validation
'class' => 'control',
'type' => 'textarea',
'value' => $default,
)
);
// if "class" is amongst user specified attributes
if (is_array($attributes) && isset($attributes['class'])) {
// we need to set the "class" attribute like this, so it doesn't overwrite previous values
$this->set_attributes(array('class' => $attributes['class']), false);
// make sure we don't set it again below
unset($attributes['class']);
}
// sets user specified attributes for the control
$this->set_attributes($attributes);
}
/**
* Generates the control's HTML code.
*
* <i>This method is automatically called by the {@link Zebra_Form::render() render()} method!</i>
*
* @return string The control's HTML code
*/
function toHTML()
{
// get private attributes
$attributes = $this->get_attributes('value');
return '<textarea ' . $this->_render_attributes() . '>' . (isset($attributes['value']) ? $attributes['value'] : '') . '</textarea>';
}
}
?>

View File

@@ -0,0 +1,292 @@
<?php
/**
* Class for time picker controls.
*
* @author Stefan Gabos <contact@stefangabos.ro>
* @copyright (c) 2006 - 2016 Stefan Gabos
* @package Controls
*/
class Zebra_Form_Time extends Zebra_Form_Control
{
/**
* Adds a time picker control to the form.
*
* <b>Do not instantiate this class directly! Use the {@link Zebra_Form::add() add()} method instead!</b>
*
* The output of this control will be one, two, three or four {@link Zebra_Form_Select select} controls for hour,
* minutes, seconds and AM/PM respectively, according to the given format as set by the <i>$attributes</i> argument.
*
* Note that even though there will be more select boxes, the submitted values will be available as a single merged
* value (in the form of hh:mm:ss AM/PM, depending on the format), with the name as given by the <i>id</i> argument.
*
* <code>
* // create a new form
* $form = new Zebra_Form('my_form');
*
* // add a time picker control for hour and minutes
* $obj = $form->add('time', 'my_time', date('H:i'), array('format' => 'hm'));
*
* // don't forget to always call this method before rendering the form
* if ($form->validate()) {
*
* // note that even though there will be more select boxes, the submitted
* // values will be available as a single merged value (in the form of
* // mm:mm:ss AM/PM, depending on the format), with the name as given by
* // the "id" argument:
* echo $_POST['my_time'];
*
* }
*
* // output the form using an automatically generated template
* $form->render();
* </code>
*
* @param string $id Unique name to identify the control in the form.
*
* The control's <b>name</b> attribute will be the same as the <b>id</b> attribute!
*
* This is the name to be used when referring to the control's value in the
* POST/GET superglobals, after the form is submitted.
*
* This is also the name of the variable to be used in custom template files, in
* order to display the control.
*
* <code>
* // in a template file, in order to print the generated HTML
* // for a control named "my_time", one would use:
* echo $my_time;
* </code>
*
* @param string $default (Optional) String representing the default time to be shown. Must be set according
* to the format of the time, as specified in <i>$attributes</i>. For example, for a
* time format of "hm", one would set the default time in the form of "hh:mm" while
* for a time format of "hms", one would set the time in the form of "hh:mm:ss".
*
* Default is current system time.
*
* @param array $attributes (Optional) An array of user specified attributes valid for an time picker
* control (format, hours, minutes, seconds, am/pm).
*
* Must be specified as an associative array, in the form of <i>attribute => value</i>.
*
* Available attributes are:
*
* - format - format of time; a string containing one, or a combination of the four
* allowed characters: "h" (hours), "m" (minutes) and "s" (seconds) and "g" for
* using 12-hours format instead of the default 23-hours format; (i.e. setting the
* format to "hm" would allow the selection of hours and minutes, setting the
* format to "hms" would allow the selection of hours, minutes and seconds, and
* setting the format to "hmg" would allow the selection of hours and minutes
* using the 12-hours format instead of the 24-hours format)
*
* - hours - an array of selectable hours (i.e. array(10, 11, 12))
*
* - minutes - an array of selectable minutes (i.e. array(15, 30, 45))
*
* - seconds - an array of selectable seconds
*
* See {@link Zebra_Form_Control::set_attributes() set_attributes()} on how to set
* attributes, other than through the constructor.
*
* @return void
*/
function __construct($id, $default = '', $attributes = '')
{
// call the constructor of the parent class
parent::__construct();
// these will hold the default selectable hours, minutes and seconds
$hours = $minutes = $seconds = array();
// all the 24 hours are available by default
for ($i = 0; $i < 24; $i++) $hours[] = $i;
// all the minutes and seconds are available by default
for ($i = 0; $i < 60; $i++) $minutes[] = $seconds[] = $i;
// set the private attributes of this control
// these attributes are private for this control and are for internal use only
// and will not be rendered by the _render_attributes() method
$this->private_attributes = array(
'disable_xss_filters',
'locked',
'type',
'name',
'id',
'format',
'hours',
'minutes',
'seconds',
'value',
);
// set the default attributes for the text control
// put them in the order you'd like them rendered
$this->set_attributes(
array(
'type' => 'time',
'name' => $id,
'id' => $id,
'value' => $default,
'class' => 'control time',
'format' => 'hm',
'hours' => $hours,
'minutes' => $minutes,
'seconds' => $seconds,
)
);
// sets user specified attributes for the control
$this->set_attributes($attributes);
}
/**
* Generates and returns the control's HTML code.
*
* <i>This method is automatically called by the {@link Zebra_Form::render() render()} method!</i>
*
* @return string The control's HTML code
*/
function toHTML()
{
// get some attributes of the control
$attributes = $this->get_attributes(array('name', 'value', 'class', 'format', 'hours', 'minutes', 'seconds'));
// make sure format is in lower characters
$attributes['format'] = strtolower($attributes['format']);
// if invalid format specified, revert to the default "hm"
if (preg_match('/^[hmsg]+$/i', $attributes['format']) == 0 || strlen(preg_replace('/([a-z]{2,})/i', '$1', $attributes['format'])) != strlen($attributes['format'])) $attributes['format'] = 'hm';
// see what have we sepcified as default time
$time = array_diff(explode(':', trim(str_replace(array('am', 'pm'), '', strtolower($attributes['value'])))), array(''));
// if, according to the time format, we have to show the hours, and the hour is given in the default time
if (($hour_position = strpos($attributes['format'], 'h')) !== false && isset($time[$hour_position]))
// the default selected hour
$selected_hour = $time[$hour_position];
// if, according to the time format, we have to show the minutes, and the minutes are given in the default time
if (($minutes_position = strpos($attributes['format'], 'm')) !== false && isset($time[$minutes_position]))
// the default selected minute
$selected_minute = $time[$minutes_position];
// if, according to the time format, we have to show the seconds, and the seconds are given in the default time
if (($seconds_position = strpos($attributes['format'], 's')) !== false && isset($time[$seconds_position]))
// the default selected minute
$selected_second = $time[$seconds_position];
// if 12-hours format is to be used
if (strpos($attributes['format'], 'g')) {
// set a flag
$ampm = true;
// if this is also present in the default time
if (preg_match('/\bam\b|\bpm\b/i', $attributes['value'], $matches))
// extract the format from the default time
$ampm = strtolower($matches[0]);
}
$output = '';
// if the hour picker is to be shown
if ($hour_position !== false) {
// generate the hour picker
$output .= '
<select name="' . $attributes['name'] . '_hours" id="' . $attributes['name'] . '_hours" ' . $this->_render_attributes() . '>
<option value="">-</option>';
foreach ($attributes['hours'] as $hour)
// show 12 or 24 hours depending on the format
if (!isset($ampm) || ($hour > 0 && $hour < 13))
$output .= '<option value="' . str_pad($hour, 2, '0', STR_PAD_LEFT) . '"' . (isset($selected_hour) && ltrim($selected_hour, '0') == ltrim($hour, '0') ? ' selected="selected"' : '') . '>' . str_pad($hour, 2, '0', STR_PAD_LEFT) . '</option>';
$output .= '
</select>
';
}
// if the minute picker is to be shown
if ($minutes_position !== false) {
// generate the minute picker
$output .= '
<select name="' . $attributes['name'] . '_minutes" id="' . $attributes['name'] . '_minutes" ' . $this->_render_attributes() . '>
<option value="">-</option>';
foreach ($attributes['minutes'] as $minute)
$output .= '<option value="' . str_pad($minute, 2, '0', STR_PAD_LEFT) . '"' . (isset($selected_minute) && ltrim($selected_minute, '0') == ltrim($minute, '0') ? ' selected="selected"' : '') . '>' . str_pad($minute, 2, '0', STR_PAD_LEFT) . '</option>';
$output .= '
</select>
';
}
// if the seconds picker is to be shown
if ($seconds_position !== false) {
// generate the seconds picker
$output .= '
<select name="' . $attributes['name'] . '_seconds" id="' . $attributes['name'] . '_seconds" ' . $this->_render_attributes() . '>
<option value="">-</option>';
foreach ($attributes['seconds'] as $second)
$output .= '<option value="' . str_pad($second, 2, '0', STR_PAD_LEFT) . '"' . (isset($selected_second) && ltrim($selected_second, '0') == ltrim($second, '0') ? ' selected="selected"' : '') . '>' . str_pad($second, 2, '0', STR_PAD_LEFT) . '</option>';
$output .= '
</select>
';
}
// if am/pm picker is to be shown
if (isset($ampm)) {
// generate the AM/PM picker
$output .= '
<select name="' . $attributes['name'] . '_ampm" id="' . $attributes['name'] . '_ampm" ' . $this->_render_attributes() . '>
<option value="">-</option>';
$output .= '<option value="AM"' . ($ampm === 'am' ? ' selected="selected"' : '') . '>AM</option>';
$output .= '<option value="PM"' . ($ampm === 'pm' ? ' selected="selected"' : '') . '>PM</option>';
$output .= '
</select>
';
}
$output .= '<div class="clear"></div>';
return $output;
}
}
?>

View File

@@ -0,0 +1,605 @@
<?php
/**
* Sanitizes data so that Cross Site Scripting Hacks can be prevented.
*
* @package XSS_Clean
* @author EllisLab Dev Team
* @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/)
* @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
* @link http://codeigniter.com
*/
class XSS_Clean
{
/**
* Random Hash for protecting URLs
*
* @var string
*
* @access private
*/
var $_xss_hash = '';
/**
* List of never allowed strings
*
* @var array
*
* @access private
*/
var $_never_allowed_str = array(
'document.cookie' => '[removed]',
'document.write' => '[removed]',
'.parentNode' => '[removed]',
'.innerHTML' => '[removed]',
'window.location' => '[removed]',
'-moz-binding' => '[removed]',
'<!--' => '&lt;!--',
'-->' => '--&gt;',
'<![CDATA[' => '&lt;![CDATA[',
'<comment>' => '&lt;comment&gt;'
);
/**
* List of never allowed regex replacement
*
* @var array
*
* @access private
*/
var $_never_allowed_regex = array(
'javascript\s*:',
'expression\s*(\(|&\#40;)', // CSS and IE
'vbscript\s*:', // IE, surprise!
'Redirect\s+302',
"([\"'])?data\s*:[^\\1]*?base64[^\\1]*?,[^\\1]*?\\1?"
);
/**
* Sanitizes submitted data so that Cross Site Scripting Hacks can be prevented.
*
* This class is taken from the {@link http://codeigniter.com/ CodeIgniter PHP Framework},
* version 2.1.2.
*
* <i>This method is automatically run for each control when calling {@link Zebra_Form::validate() validate()}, unless
* specifically disabled by {@link Zebra_Form_Control::disable_xss_filters() disable_xss_filters()})!</i>
*
* <b>Following is the original documentation of the class, as found in CodeIgniter:</b>
*
* Sanitizes data so that Cross Site Scripting Hacks can be prevented. This function does a fair amount of work but
* it is extremely thorough, designed to prevent even the most obscure XSS attempts. Nothing is ever 100% foolproof,
* of course, but I haven't been able to get anything passed the filter.
*
* Note: This function should only be used to deal with data upon submission. It's not something that should be used
* for general runtime processing.
*
* This function was based in part on some code and ideas I got from Bitflux:
* {@link http://blog.bitflux.ch/wiki/XSS_Prevention}
*
* To help develop this script I used this great list of vulnerabilities along with a few other hacks I've
* harvested from examining vulnerabilities in other programs: {@link http://ha.ckers.org/xss.html}
*
* @param string $str String to be filtered
*
* @return string Returns filtered string
*/
function sanitize($str, $rawurldecode = true)
{
// Remove Invisible Characters
$str = $this->_remove_invisible_characters($str);
/*
* URL Decode
*
* Just in case stuff like this is submitted:
*
* <a href="http://%77%77%77%2E%67%6F%6F%67%6C%65%2E%63%6F%6D">Google</a>
*
* Note: Use rawurldecode() so it does not remove plus signs
*/
if ($rawurldecode) $str = rawurldecode($str);
/*
* Convert character entities to ASCII
*
* This permits our tests below to work reliably.
* We only convert entities that are within tags since
* these are the ones that will pose security problems.
*/
$str = preg_replace_callback("/[a-z]+=([\'\"]).*?\\1/si", array($this, '_convert_attribute'), $str);
$str = preg_replace_callback('/<\w+.*?(?=>|<|$)/si', array($this, '_decode_entity'), $str);
// Remove Invisible Characters Again!
$str = $this->_remove_invisible_characters($str);
/*
* Convert all tabs to spaces
*
* This prevents strings like this: ja vascript
* NOTE: we deal with spaces between characters later.
* NOTE: preg_replace was found to be amazingly slow here on
* large blocks of data, so we use str_replace.
*/
$str = str_replace("\t", ' ', $str);
// Capture converted string for later comparison
$converted_string = $str;
// Remove Strings that are never allowed
$str = $this->_do_never_allowed($str);
/*
* Makes PHP tags safe
*
* Note: XML tags are inadvertently replaced too:
*
* <?xml
*
* But it doesn't seem to pose a problem.
*/
$str = str_replace(array('<?', '?'.'>'), array('&lt;?', '?&gt;'), $str);
/*
* Compact any exploded words
*
* This corrects words like: j a v a s c r i p t
* These words are compacted back to their correct state.
*/
$words = array(
'javascript', 'expression', 'vbscript', 'script', 'base64',
'applet', 'alert', 'document', 'write', 'cookie', 'window'
);
foreach ($words as $word)
{
$word = implode('\s*', str_split($word)).'\s*';
// We only want to do this when it is followed by a non-word character
// That way valid stuff like "dealer to" does not become "dealerto"
$str = preg_replace_callback('#('.substr($word, 0, -3).')(\W)#is', array($this, '_compact_exploded_words'), $str);
}
/*
* Remove disallowed Javascript in links or img tags
* We used to do some version comparisons and use of stripos for PHP5,
* but it is dog slow compared to these simplified non-capturing
* preg_match(), especially if the pattern exists in the string
*/
do
{
$original = $str;
if (preg_match('/<a/i', $str))
{
$str = preg_replace_callback('#<a\s+([^>]*?)(?:>|$)#si', array($this, '_js_link_removal'), $str);
}
if (preg_match('/<img/i', $str))
{
$str = preg_replace_callback('#<img\s+([^>]*?)(?:\s?/?\>|$)#si', array($this, '_js_img_removal'), $str);
}
if (preg_match('/script|xss/i', $str))
{
$str = preg_replace('#</*(?:script|xss).*?\>#si', '[removed]', $str);
}
}
while ($original !== $str);
unset($original);
// Remove evil attributes such as style, onclick and xmlns
$str = $this->_remove_evil_attributes($str, false);
/*
* Sanitize naughty HTML elements
*
* If a tag containing any of the words in the list
* below is found, the tag gets converted to entities.
*
* So this: <blink>
* Becomes: &lt;blink&gt;
*/
$naughty = 'alert|applet|audio|basefont|base|behavior|bgsound|blink|body|embed|expression|form|frameset|frame|head|html|ilayer|iframe|input|isindex|layer|link|meta|object|plaintext|style|script|textarea|title|video|xml|xss';
$str = preg_replace_callback('#<(/*\s*)('.$naughty.')([^><]*)([><]*)#is', array($this, '_sanitize_naughty_html'), $str);
/*
* Sanitize naughty scripting elements
*
* Similar to above, only instead of looking for
* tags it looks for PHP and JavaScript commands
* that are disallowed. Rather than removing the
* code, it simply converts the parenthesis to entities
* rendering the code un-executable.
*
* For example: eval('some code')
* Becomes: eval&#40;'some code'&#41;
*/
$str = preg_replace('#(alert|cmd|passthru|eval|exec|expression|system|fopen|fsockopen|file|file_get_contents|readfile|unlink)(\s*)\((.*?)\)#si',
'\\1\\2&#40;\\3&#41;',
$str);
// Final clean up
// This adds a bit of extra precaution in case
// something got through the above filters
$str = $this->_do_never_allowed($str);
return $str;
}
// --------------------------------------------------------------------
/**
* Random Hash for protecting URLs
*
* @return string
*
* @access private
*/
function xss_hash()
{
if ($this->_xss_hash === '')
{
mt_srand();
$this->_xss_hash = md5(time() + mt_rand(0, 1999999999));
}
return $this->_xss_hash;
}
// --------------------------------------------------------------------
/**
* HTML Entities Decode
*
* This function is a replacement for html_entity_decode()
*
* The reason we are not using html_entity_decode() by itself is because
* while it is not technically correct to leave out the semicolon
* at the end of an entity most browsers will still interpret the entity
* correctly. html_entity_decode() does not convert entities without
* semicolons, so we are left with our own little solution here. Bummer.
*
* @param string
* @param string
* @return string
*
* @access private
*/
function entity_decode($str, $charset = NULL)
{
if (strpos($str, '&') === FALSE)
{
return $str;
}
if (empty($charset))
{
$charset = 'UTF-8';
}
$str = html_entity_decode($str, ENT_COMPAT, $charset);
$str = preg_replace('~&#x(0*[0-9a-f]{2,5})~ei', 'chr(hexdec("\\1"))', $str);
return preg_replace('~&#([0-9]{2,4})~e', 'chr(\\1)', $str);
}
// ----------------------------------------------------------------
/**
* Compact Exploded Words
*
* Callback function for xss_clean() to remove whitespace from
* things like j a v a s c r i p t
*
* @param array
* @return string
*
* @access private
*/
function _compact_exploded_words($matches)
{
return preg_replace('/\s+/s', '', $matches[1]).$matches[2];
}
// --------------------------------------------------------------------
/**
* Remove Evil HTML Attributes (like event handlers and style)
*
* It removes the evil attribute and either:
* - Everything up until a space
* For example, everything between the pipes:
* <a |style=document.write('hello');alert('world');| class=link>
* - Everything inside the quotes
* For example, everything between the pipes:
* <a |style="document.write('hello'); alert('world');"| class="link">
*
* @param string $str The string to check
* @param boolean $is_image TRUE if this is an image
* @return string The string with the evil attributes removed
*
* @access private
*/
function _remove_evil_attributes($str, $is_image)
{
// All javascript event handlers (e.g. onload, onclick, onmouseover), style, and xmlns
$evil_attributes = array('on\w*', 'style', 'xmlns', 'formaction');
if ($is_image === TRUE)
{
/*
* Adobe Photoshop puts XML metadata into JFIF images,
* including namespacing, so we have to allow this for images.
*/
unset($evil_attributes[array_search('xmlns', $evil_attributes)]);
}
do {
$count = 0;
$attribs = array();
// find occurrences of illegal attribute strings without quotes
preg_match_all('/('.implode('|', $evil_attributes).')\s*=\s*([^\s>]*)/is', $str, $matches, PREG_SET_ORDER);
foreach ($matches as $attr)
{
$attribs[] = preg_quote($attr[0], '/');
}
// find occurrences of illegal attribute strings with quotes (042 and 047 are octal quotes)
preg_match_all('/('.implode('|', $evil_attributes).')\s*=\s*(\042|\047)([^\\2]*?)(\\2)/is', $str, $matches, PREG_SET_ORDER);
foreach ($matches as $attr)
{
$attribs[] = preg_quote($attr[0], '/');
}
// replace illegal attribute strings that are inside an html tag
if (count($attribs) > 0)
{
$str = preg_replace('/<(\/?[^><]+?)([^A-Za-z<>\-])(.*?)('.implode('|', $attribs).')(.*?)([\s><])([><]*)/i', '<$1 $3$5$6$7', $str, -1, $count);
}
} while ($count);
return $str;
}
// --------------------------------------------------------------------
/**
* Sanitize Naughty HTML
*
* Callback function for xss_clean() to remove naughty HTML elements
*
* @param array
* @return string
*
* @access private
*/
function _sanitize_naughty_html($matches)
{
return '&lt;'.$matches[1].$matches[2].$matches[3] // encode opening brace
// encode captured opening or closing brace to prevent recursive vectors:
.str_replace(array('>', '<'), array('&gt;', '&lt;'), $matches[4]);
}
// --------------------------------------------------------------------
/**
* JS Link Removal
*
* Callback function for xss_clean() to sanitize links
* This limits the PCRE backtracks, making it more performance friendly
* and prevents PREG_BACKTRACK_LIMIT_ERROR from being triggered in
* PHP 5.2+ on link-heavy strings
*
* @param array
* @return string
*
* @access private
*/
function _js_link_removal($match)
{
return str_replace($match[1],
preg_replace('#href=.*?(?:alert\(|alert&\#40;|javascript:|livescript:|mocha:|charset=|window\.|document\.|\.cookie|<script|<xss|data\s*:)#si',
'',
$this->_filter_attributes(str_replace(array('<', '>'), '', $match[1]))
),
$match[0]);
}
// --------------------------------------------------------------------
/**
* JS Image Removal
*
* Callback function for xss_clean() to sanitize image tags
* This limits the PCRE backtracks, making it more performance friendly
* and prevents PREG_BACKTRACK_LIMIT_ERROR from being triggered in
* PHP 5.2+ on image tag heavy strings
*
* @param array
* @return string
*
* @access private
*/
function _js_img_removal($match)
{
return str_replace($match[1],
preg_replace('#src=.*?(?:alert\(|alert&\#40;|javascript:|livescript:|mocha:|charset=|window\.|document\.|\.cookie|<script|<xss|base64\s*,)#si',
'',
$this->_filter_attributes(str_replace(array('<', '>'), '', $match[1]))
),
$match[0]);
}
// --------------------------------------------------------------------
/**
* Attribute Conversion
*
* Used as a callback for XSS Clean
*
* @param array
* @return string
*
* @access private
*/
function _convert_attribute($match)
{
return str_replace(array('>', '<', '\\'), array('&gt;', '&lt;', '\\\\'), $match[0]);
}
// --------------------------------------------------------------------
/**
* Filter Attributes
*
* Filters tag attributes for consistency and safety
*
* @param string
* @return string
*
* @access private
*/
function _filter_attributes($str)
{
$out = '';
if (preg_match_all('#\s*[a-z\-]+\s*=\s*(\042|\047)([^\\1]*?)\\1#is', $str, $matches))
{
foreach ($matches[0] as $match)
{
$out .= preg_replace('#/\*.*?\*/#s', '', $match);
}
}
return $out;
}
// --------------------------------------------------------------------
/**
* HTML Entity Decode Callback
*
* Used as a callback for XSS Clean
*
* @param array
* @return string
*
* @access private
*/
function _decode_entity($match)
{
return $this->entity_decode($match[0], strtoupper('UTF-8'));
}
// --------------------------------------------------------------------
/**
* Validate URL entities
*
* Called by xss_clean()
*
* @param string
* @return string
*
* @access private
*/
function _validate_entities($str)
{
/*
* Protect GET variables in URLs
*/
// 901119URL5918AMP18930PROTECT8198
$str = preg_replace('|\&([a-z\_0-9\-]+)\=([a-z\_0-9\-]+)|i', $this->xss_hash().'\\1=\\2', $str);
/*
* Validate standard character entities
*
* Add a semicolon if missing. We do this to enable
* the conversion of entities to ASCII later.
*/
$str = preg_replace('#(&\#?[0-9a-z]{2,})([\x00-\x20])*;?#i', '\\1;\\2', $str);
/*
* Validate UTF16 two byte encoding (x00)
*
* Just as above, adds a semicolon if missing.
*/
$str = preg_replace('#(&\#x?)([0-9A-F]+);?#i', '\\1\\2;', $str);
/*
* Un-Protect GET variables in URLs
*/
return str_replace($this->xss_hash(), '&', $str);
}
// ----------------------------------------------------------------------
/**
* Do Never Allowed
*
* A utility function for xss_clean()
*
* @param string
* @return string
*
* @access private
*/
function _do_never_allowed($str)
{
$str = str_replace(array_keys($this->_never_allowed_str), $this->_never_allowed_str, $str);
foreach ($this->_never_allowed_regex as $regex)
{
$str = preg_replace('#'.$regex.'#is', '[removed]', $str);
}
return $str;
}
/**
* Remove Invisible Characters
*
* This prevents sandwiching null characters
* between ascii characters, like Java\0script.
*
* @access private
* @param string
* @return string
*/
function _remove_invisible_characters($str)
{
static $non_displayables;
if ( ! isset($non_displayables))
{
// every control character except newline (dec 10), carriage return (dec 13), and horizontal tab (dec 09),
$non_displayables = array(
'/%0[0-8bcef]/', // url encoded 00-08, 11, 12, 14, 15
'/%1[0-9a-f]/', // url encoded 16-31
'/[\x00-\x08]/', // 00-08
'/\x0b/', '/\x0c/', // 11, 12
'/[\x0e-\x1f]/' // 14-31
);
}
do
{
$cleaned = $str;
$str = preg_replace($non_displayables, '', $str);
}
while ($cleaned != $str);
return $str;
}
}
?>

Binary file not shown.

View File

@@ -0,0 +1,8 @@
<html>
<head>
<title>403 Forbidden</title>
</head>
<body>
<p>Directory access is forbidden.</p>
</body>
</html>

View File

@@ -0,0 +1,8 @@
<html>
<head>
<title>403 Forbidden</title>
</head>
<body>
<p>Directory access is forbidden.</p>
</body>
</html>

View File

@@ -0,0 +1,25 @@
<?php
/**
* Afrikaans language file
*
* @author Shaun Adlam <ashaun@vodamail.co.za>
*/
$this->language = array(
'clear_date' => 'Maak datum skoon',
'csrf_detected' => 'Daar was "n probleem met jou voorlegging ! <br> Moontlike oorsake kan wees dat die voorlegging te lank geneem het , of dit word dubbel versoek. <br> Probeer asseblief weer..',
'days' => array('Sondag','Maandag','Dinsdag','Woensdag','Donderdag','Vrydag','Saterdag'),
'days_abbr' => false, // sal die eerste 2 letters te gebruik van die volle naam
'months' => array('Januarie','Februarie','Maart','April','Mei','Junie','Julie','Augustus','September','Oktober','November','Desember'),
'months_abbr' => false, // sal gebruik om die eerste 3 letters van die volle naam
'new_captcha' => 'Kry nuwe kode',
'other' => 'Ander...',
'select' => '- Kies Opsie -',
'spam_detected' => 'Moontlike plapos poging opgemerk . Die geposte vorm data is verwerp.',
'today' => 'Vandag',
);
?>

View File

@@ -0,0 +1,25 @@
<?php
/**
* Albanian language file
*
* @author Faton Sopa <fatonsopa@gmail.com>
*/
$this->language = array(
'clear_date' => 'Clear',
'csrf_detected' => 'There was a problem with your submission!<br>Possible causes may be that the submission has taken too long, or it represents a duplicate request.<br>Please try again.',
'days' => array('Diele','Hene','Marte','Merkure','Enjte','Premte','Shtune'),
'days_abbr' => false, // will use the first 2 letters from the full name
'months' => array('Janar','Shkurt','Mars','Prill','Maj','Qershor','Korrik','Gusht','Shtator','Tetor','Nentor','Dhjetor'),
'months_abbr' => false, // will use the first 3 letters from the full name
'new_captcha' => 'Get a new code',
'other' => 'Te tjere...',
'select' => '- zgjedh opcionin -',
'spam_detected' => 'Possible spam attempt detected. The posted form data was rejected.',
'today' => 'Sot',
);
?>

View File

@@ -0,0 +1,26 @@
<?php
/**
* Catalan language file
*
* @version 1.0
* @author WaKeMaTTa
*/
$this->language = array(
'clear_date' => 'Netejar',
'csrf_detected' => 'Hi va haver un problema amb el teu enviament! <br> Probablement l\'enviament és massa gran o és una petició duplicada. <br> Si us plau, torneu a provar.',
'days' => array('Diumenge','Dilluns','Dimarts','Dimecres','Dijous','Divendres','Dissabte'),
'days_abbr' => false, // will use the first 2 letters from the full name
'months' => array('Gener','Febrer','Març','Abril','Maig','Juny','Julio','Agost','Setembre','Octubre','Novembre','Desembre'),
'months_abbr' => false, // will use the first 3 letters from the full name
'new_captcha' => 'Obtenir nou codi',
'other' => 'Altres...',
'select' => '- Seleccionar -',
'spam_detected' => 'Possible intent d\'spam detectat. El formulari enviat va ser rebutjat.',
'today' => 'Avui',
);
?>

View File

@@ -0,0 +1,24 @@
<?php
/**
* Deutsch (German) language file
*
* @author Chris Banford
*/
$this->language = array(
'clear_date' => 'Löschen',
'csrf_detected' => 'Beim Absenden des Formulars ist ein Problem aufgetreten.<br>Es kann sein, dass zu viel Zeit vergangen ist, oder dass Ihre Anfrage bereits gesendet wurde.<br>Bitte versuchen Sie es später noch einmal.',
'days' => array ('Sonntag', 'Montag', 'Dienstag', 'Mittwoch', 'Donnerstag', 'Freitag', 'Samstag'),
'days_abbr' => false, // will use the first 2 letters from the full name
'months' => array('Januar','Februar', 'März', 'April', 'Mai', 'Juni', 'Juli', 'August', 'September', 'Oktober', 'November', 'Dezember'),
'months_abbr' => false, // will use the first 3 letters from the full name
'new_captcha' => 'Einen neuen Code erhalten',
'other' => 'Sonstige...',
'select' => '- wählen -',
'spam_detected' => 'Es besteht der Verdacht auf einen Spamversuch. Ihre Anfrage wird ignoriert.',
'today' => 'Heute',
);
?>

View File

@@ -0,0 +1,25 @@
<?php
/**
* Dutch language file
*
* @author Alexander Martens <martens@podium.nl>
*/
$this->language = array(
'clear_date' => 'Wissen',
'csrf_detected' => 'Er was een probleem met het verzenden van het formulier<br>Of het versturen duurde te lang of uw formulier was inmiddels al verstuurd.<br>Probeer het later nog een keer.',
'days' => array('Zondag','Maandag','Dinsdag','Woensdag','Donderdag','Vrijdag','Zaterdag'),
'days_abbr' => true, // will use the first 2 letters from the full name
'months' => array('Januari','Februari','Maart','April','Mei','Juni','Juli','Augustus','September','Oktober','November','December'),
'months_abbr' => false, // will use the first 3 letters from the full name
'new_captcha' => 'Toon een nieuwe code',
'other' => 'Anders...',
'select' => '- maak een keuze -',
'spam_detected' => 'Er is mogelijk spam gedetecteerd, uw ingevoerde gegevens zijn geweigerd',
'today' => 'Vandaag',
);
?>

View File

@@ -0,0 +1,25 @@
<?php
/**
* English language file
*
* @author Stefan Gabos <contact@stefangabos.ro>
*/
$this->language = array(
'clear_date' => 'Clear date',
'csrf_detected' => 'There was a problem with your submission!<br>Possible causes may be that the submission has taken too long, or it represents a duplicate request.<br>Please try again.',
'days' => array('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday'),
'days_abbr' => false, // will use the first 2 letters from the full name
'months' => array('January','February','March','April','May','June','July','August','September','October','November','December'),
'months_abbr' => false, // will use the first 3 letters from the full name
'new_captcha' => 'Get a new code',
'other' => 'Other...',
'select' => '- select -',
'spam_detected' => 'Possible spam attempt detected. The posted form data was rejected.',
'today' => 'Today',
);
?>

View File

@@ -0,0 +1,26 @@
<?php
/**
* Spanish language file
*
* @version 1.1.1
* @author D3iti, WaKeMaTTa
*/
$this->language = array(
'clear_date' => 'Limpiar',
'csrf_detected' => '¡Hubo un problema con tu envio!<br>Probablemente el envio es demasido grande o es una petición duplicada. <br> Por favor, inténtalo de nuevo.',
'days' => array('Domingo','Lunes','Martes','Miércoles','Jueves','Viernes','Sábado'),
'days_abbr' => false, // will use the first 2 letters from the full name
'months' => array('Enero','Febrero','Marzo','Abril','Mayo','Junio','Julio','Agosto','Septiembre','Octubre','Noviembre','Diciembre'),
'months_abbr' => false, // will use the first 3 letters from the full name
'new_captcha' => 'Obtener nuevo codigo',
'other' => 'Otro...',
'select' => '- Seleccionar -',
'spam_detected' => 'Posible intento de spam detectado. El formulario enviado fue rechazado.',
'today' => 'Hoy',
);
?>

View File

@@ -0,0 +1,26 @@
<?php
/**
* French language file
*
* @version 1.0
* @author Sébastien GASTARD aka Gafa
*/
$this->language = array(
'clear_date' => 'Vider',
'csrf_detected' =>' Il y a eu un problème avec cette requête<br>Cela peut être causé par une inactivité de votre part, ou par un double envoi du formulaire.<br>Merci de réessayer plus tard. ',
'days' => array('Dimanche','Lundi','Mardi','Mercredi','Jeudi','Vendredi','Samedi'),
'days_abbr' => false, // will use the first 2 letters from the full name
'months' => array('Janvier','Février','Mars','Avril','Mai','Juin','Juillet','Août','Septembre','Octobre','Novembre','Décembre'),
'months_abbr' => false, // will use the first 3 letters from the full name
'new_captcha' => 'Obtenir un nouveau code',
'other' => 'Autre...',
'select' => '- Sélectionner -',
'spam_detected' => 'Une tentative de SPAM à été détectée. Votre requête est ignorée. ',
'today' => 'Aujourd\'hui',
);
?>

View File

@@ -0,0 +1,8 @@
<html>
<head>
<title>403 Forbidden</title>
</head>
<body>
<p>Directory access is forbidden.</p>
</body>
</html>

View File

@@ -0,0 +1,25 @@
<?php
/**
* Italian language file
*
* @author Nicola Tuveri <nic.tuv@gmail.com>
*/
$this->language = array(
'clear_date' => 'Rimuovi',
'csrf_detected' => 'Si è presentato un problema col vostro invio!<br>Tra le possibili cause l\'invio può aver richiesto troppo tempo, o la richiesta è stata duplicata.<br>Riprovare, per favore.',
'days' => array('Domenica','Lunedì','Martedì','Mercoledì','Giovedì','Venerdì','Sabato'),
'days_abbr' => array('D','L','Ma','Me','G','V','S'),
'months' => array('Gennaio','Febbraio','Marzo','Aprile','Maggio','Giugno','Luglio','Agosto','Settembre','Ottobre','Novembre','Dicembre'),
'months_abbr' => false, // will use the first 3 letters from the full name
'new_captcha' => 'Genera un nuovo codice',
'other' => 'Altro...',
'select' => '- Selezionare -',
'spam_detected' => 'Rilevato possibile tentativo di spam. Il modulo inviato è stato rifiutato.',
'today' => 'Oggi',
);
?>

View File

@@ -0,0 +1,26 @@
<?php
/**
* Romanian language file
*
* @version 1.1
* @author Stefan Gabos <contact@stefangabos.ro>
*/
$this->language = array(
'clear_date' => 'Sterge',
'csrf_detected' => 'A existat o problema la trimitearea formularului!<br>Posibile cauze pot fi durata prea mare de timp folosita pentru completarea formularului sau incercarea de retrimitere a formularului.<br>Te rugam sa incerci din nou.',
'days' => array('Duminica','Luni','Marti','Miercuri','Joi','Vineri','Sambata'),
'days_abbr' => false, // will use the first 2 letters from the full name
'months' => array('Ianuarie','Februarie','Martie','Aprilie','Mai','Iunie','Iulie','August','Septembrie','Octombrie','Noiembrie','Decembrie'),
'months_abbr' => false, // will use the first 3 letters from the full name
'new_captcha' => 'Genereaza un cod nou',
'other' => 'Alta...',
'select' => '- alege -',
'spam_detected' => 'Posibila incercare de spam detectata. Datele trimise in formular au fost respinse.',
'today' => 'Astazi',
);
?>

View File

@@ -0,0 +1,25 @@
<?php
/**
* Russian language file
*
* @author Maxim Hodyrev <maximkou@gmail.com>
*/
$this->language = array(
'clear_date' => 'Дата очистки',
'csrf_detected' => 'При выполнении вашего запроса возникла проблема.<br>Возможно, ваш запрос занял слишком много времени или дублируется.<br>Попробуйте еще раз.',
'days' => array('Воскресенье','Понедельник','Вторник','Среда','Четверг','Пятница','Суббота'),
'days_abbr' => false,
'months' => array('Январь','Февраль','Март','Апрель','Май','Июнь','Июль','Август','Сентябрь','Октябрь','Ноябрь','Декабрь'),
'months_abbr' => false,
'new_captcha' => 'Обновить капчу',
'other' => 'Еще...',
'select' => '- не выбрано -',
'spam_detected' => 'Выявлена возможная попытка отправить спам-сообщение. Отправленные в форме данные отклонены.',
'today' => 'Сегодня',
);
?>

View File

@@ -0,0 +1,25 @@
<?php
/**
* Turkish language file
*
* @author Bülent Özden
*/
$this->language = array(
'clear_date' => 'Temizle',
'csrf_detected' => 'Gönderinizle ilgili bir sorun çıktı!<br>Olası nedenler arasında form gönderiminin çok uzun sürmesi ya da aynı işlemden ikinci kere yapılması olabilir.<br>Lütfen yeniden deneyiniz.',
'days' => array('Pazar','Pazartesi','Salı','Çarsamba','Perşembe','Cuma','Cumartesi'),
'days_abbr' => false, // will use the first 2 letters from the full name
'months' => array('Ocak','Şubat','Mart','Nisan','Mayıs','Haziran','Temmuz','Ağustos','Eylül','Ekim','Kasım','Aralık'),
'months_abbr' => false, // will use the first 3 letters from the full name
'new_captcha' => 'Yeni bir kod',
'other' => 'Diğer...',
'select' => '- seçiniz -',
'spam_detected' => 'SPAM denemesi olabilir. Gönderilen form verisi reddedildi.',
'today' => 'Bugün',
);
?>

View File

@@ -0,0 +1,165 @@
GNU LESSER GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
This version of the GNU Lesser General Public License incorporates
the terms and conditions of version 3 of the GNU General Public
License, supplemented by the additional permissions listed below.
0. Additional Definitions.
As used herein, "this License" refers to version 3 of the GNU Lesser
General Public License, and the "GNU GPL" refers to version 3 of the GNU
General Public License.
"The Library" refers to a covered work governed by this License,
other than an Application or a Combined Work as defined below.
An "Application" is any work that makes use of an interface provided
by the Library, but which is not otherwise based on the Library.
Defining a subclass of a class defined by the Library is deemed a mode
of using an interface provided by the Library.
A "Combined Work" is a work produced by combining or linking an
Application with the Library. The particular version of the Library
with which the Combined Work was made is also called the "Linked
Version".
The "Minimal Corresponding Source" for a Combined Work means the
Corresponding Source for the Combined Work, excluding any source code
for portions of the Combined Work that, considered in isolation, are
based on the Application, and not on the Linked Version.
The "Corresponding Application Code" for a Combined Work means the
object code and/or source code for the Application, including any data
and utility programs needed for reproducing the Combined Work from the
Application, but excluding the System Libraries of the Combined Work.
1. Exception to Section 3 of the GNU GPL.
You may convey a covered work under sections 3 and 4 of this License
without being bound by section 3 of the GNU GPL.
2. Conveying Modified Versions.
If you modify a copy of the Library, and, in your modifications, a
facility refers to a function or data to be supplied by an Application
that uses the facility (other than as an argument passed when the
facility is invoked), then you may convey a copy of the modified
version:
a) under this License, provided that you make a good faith effort to
ensure that, in the event an Application does not supply the
function or data, the facility still operates, and performs
whatever part of its purpose remains meaningful, or
b) under the GNU GPL, with none of the additional permissions of
this License applicable to that copy.
3. Object Code Incorporating Material from Library Header Files.
The object code form of an Application may incorporate material from
a header file that is part of the Library. You may convey such object
code under terms of your choice, provided that, if the incorporated
material is not limited to numerical parameters, data structure
layouts and accessors, or small macros, inline functions and templates
(ten or fewer lines in length), you do both of the following:
a) Give prominent notice with each copy of the object code that the
Library is used in it and that the Library and its use are
covered by this License.
b) Accompany the object code with a copy of the GNU GPL and this license
document.
4. Combined Works.
You may convey a Combined Work under terms of your choice that,
taken together, effectively do not restrict modification of the
portions of the Library contained in the Combined Work and reverse
engineering for debugging such modifications, if you also do each of
the following:
a) Give prominent notice with each copy of the Combined Work that
the Library is used in it and that the Library and its use are
covered by this License.
b) Accompany the Combined Work with a copy of the GNU GPL and this license
document.
c) For a Combined Work that displays copyright notices during
execution, include the copyright notice for the Library among
these notices, as well as a reference directing the user to the
copies of the GNU GPL and this license document.
d) Do one of the following:
0) Convey the Minimal Corresponding Source under the terms of this
License, and the Corresponding Application Code in a form
suitable for, and under terms that permit, the user to
recombine or relink the Application with a modified version of
the Linked Version to produce a modified Combined Work, in the
manner specified by section 6 of the GNU GPL for conveying
Corresponding Source.
1) Use a suitable shared library mechanism for linking with the
Library. A suitable mechanism is one that (a) uses at run time
a copy of the Library already present on the user's computer
system, and (b) will operate properly with a modified version
of the Library that is interface-compatible with the Linked
Version.
e) Provide Installation Information, but only if you would otherwise
be required to provide such information under section 6 of the
GNU GPL, and only to the extent that such information is
necessary to install and execute a modified version of the
Combined Work produced by recombining or relinking the
Application with a modified version of the Linked Version. (If
you use option 4d0, the Installation Information must accompany
the Minimal Corresponding Source and Corresponding Application
Code. If you use option 4d1, you must provide the Installation
Information in the manner specified by section 6 of the GNU GPL
for conveying Corresponding Source.)
5. Combined Libraries.
You may place library facilities that are a work based on the
Library side by side in a single library together with other library
facilities that are not Applications and are not covered by this
License, and convey such a combined library under terms of your
choice, if you do both of the following:
a) Accompany the combined library with a copy of the same work based
on the Library, uncombined with any other library facilities,
conveyed under the terms of this License.
b) Give prominent notice with the combined library that part of it
is a work based on the Library, and explaining where to find the
accompanying uncombined form of the same work.
6. Revised Versions of the GNU Lesser General Public License.
The Free Software Foundation may publish revised and/or new versions
of the GNU Lesser General Public License from time to time. Such new
versions will be similar in spirit to the present version, but may
differ in detail to address new problems or concerns.
Each version is given a distinguishing version number. If the
Library as you received it specifies that a certain numbered version
of the GNU Lesser General Public License "or any later version"
applies to it, you have the option of following the terms and
conditions either of that published version or of any later version
published by the Free Software Foundation. If the Library as you
received it does not specify a version number of the GNU Lesser
General Public License, you may choose any version of the GNU Lesser
General Public License ever published by the Free Software Foundation.
If the Library as you received it specifies that a proxy can decide
whether future versions of the GNU Lesser General Public License shall
apply, that proxy's public statement of acceptance of any version is
permanent authorization for you to choose that version for the
Library.

140
vendor/stefangabos/zebra_form/mimes.json vendored Normal file
View File

@@ -0,0 +1,140 @@
{
"3g2" : "video\/3gpp2",
"3gp" : "video\/3gp",
"7zip" : ["application\/x-compressed", "application\/x-zip-compressed", "application\/zip", "multipart\/x-zip"],
"aac" : "audio\/x-acc",
"ac3" : "audio\/ac3",
"ai" : ["application\/pdf", "application\/postscript"],
"aif" : ["audio\/x-aiff", "audio\/aiff"],
"aifc" : "audio\/x-aiff",
"aiff" : ["audio\/x-aiff", "audio\/aiff"],
"au" : "audio\/x-au",
"avi" : ["video\/x-msvideo", "video\/msvideo", "video\/avi", "application\/x-troff-msvideo"],
"bin" : ["application\/macbinary", "application\/mac-binary", "application\/octet-stream", "application\/x-binary", "application\/x-macbinary"],
"bmp" : ["image\/bmp", "image\/x-windows-bmp"],
"cdr" : ["application\/cdr", "application\/coreldraw", "application\/x-cdr", "application\/x-coreldraw", "image\/cdr", "image\/x-cdr", "zz-application\/zz-winassoc-cdr"],
"cer" : ["application\/pkix-cert", "application\/x-x509-ca-cert"],
"class" : "application\/octet-stream",
"crl" : ["application\/pkix-crl", "application\/pkcs-crl"],
"crt" : ["application\/x-x509-ca-cert", "application\/x-x509-user-cert", "application\/pkix-cert"],
"csr" : "application\/octet-stream",
"css" : ["text\/css", "text\/plain"],
"csv" : ["text\/x-comma-separated-values", "text\/comma-separated-values", "application\/octet-stream", "application\/vnd.ms-excel", "application\/x-csv", "text\/x-csv", "text\/csv", "application\/csv", "application\/excel", "application\/vnd.msexcel", "text\/plain"],
"dcr" : "application\/x-director",
"der" : "application\/x-x509-ca-cert",
"dir" : "application\/x-director",
"dll" : "application\/octet-stream",
"dms" : "application\/octet-stream",
"doc" : ["application\/msword", "application\/vnd.ms-office"],
"docx" : ["application\/vnd.openxmlformats-officedocument.wordprocessingml.document", "application\/zip", "application\/msword", "application\/x-zip"],
"dot" : ["application\/msword", "application\/vnd.ms-office"],
"dotx" : ["application\/vnd.openxmlformats-officedocument.wordprocessingml.document", "application\/zip", "application\/msword"],
"dvi" : "application\/x-dvi",
"dxr" : "application\/x-director",
"eml" : "message\/rfc822",
"eps" : "application\/postscript",
"exe" : ["application\/octet-stream", "application\/x-msdownload"],
"f4v" : "video\/mp4",
"flac" : "audio\/x-flac",
"gif" : "image\/gif",
"gpg" : "application\/gpg-keys",
"gtar" : "application\/x-gtar",
"gz" : "application\/x-gzip",
"gzip" : "application\/x-gzip",
"htm" : ["text\/html", "text\/plain"],
"html" : ["text\/html", "text\/plain"],
"ics" : "text\/calendar",
"jar" : ["application\/java-archive", "application\/x-java-application", "application\/x-jar", "application\/x-compressed"],
"jpe" : ["image\/jpeg", "image\/pjpeg"],
"jpeg" : ["image\/jpeg", "image\/pjpeg"],
"jpg" : ["image\/jpeg", "image\/pjpeg"],
"js" : ["application\/x-javascript", "text\/plain"],
"json" : ["application\/json", "text\/json"],
"kdb" : "application\/octet-stream",
"kml" : ["application\/vnd.google-earth.kml+xml", "application\/xml", "text\/xml"],
"kmz" : ["application\/vnd.google-earth.kmz", "application\/zip", "application\/x-zip"],
"lha" : "application\/octet-stream",
"log" : ["text\/plain", "text\/x-log"],
"lzh" : "application\/octet-stream",
"m3u" : "text\/plain",
"m4a" : "audio\/x-m4a",
"m4u" : "application\/vnd.mpegurl",
"mid" : "audio\/midi",
"midi" : "audio\/midi",
"mif" : "application\/vnd.mif",
"mov" : "video\/quicktime",
"movie" : "video\/x-sgi-movie",
"mp2" : "audio\/mpeg",
"mp3" : ["audio\/mpeg", "audio\/mpg", "audio\/mpeg3", "audio\/mp3"],
"mp4" : "video\/mp4",
"mpe" : "video\/mpeg",
"mpeg" : "video\/mpeg",
"mpg" : "video\/mpeg",
"mpga" : "audio\/mpeg",
"oda" : "application\/oda",
"ogg" : "audio\/ogg",
"p10" : ["application\/x-pkcs10", "application\/pkcs10"],
"p12" : "application\/x-pkcs12",
"p7a" : "application\/x-pkcs7-signature",
"p7c" : ["application\/pkcs7-mime", "application\/x-pkcs7-mime"],
"p7m" : ["application\/pkcs7-mime", "application\/x-pkcs7-mime"],
"p7r" : "application\/x-pkcs7-certreqresp",
"p7s" : "application\/pkcs7-signature",
"pdf" : ["application\/pdf", "application\/force-download", "application\/x-download", "binary\/octet-stream", "application\/x-pdf"],
"pem" : ["application\/x-x509-user-cert", "application\/x-pem-file", "application\/octet-stream"],
"pgp" : "application\/pgp",
"php" : ["application\/x-httpd-php", "application\/php", "application\/x-php", "text\/php", "text\/x-php", "application\/x-httpd-php-source"],
"php3" : "application\/x-httpd-php",
"php4" : "application\/x-httpd-php",
"phps" : "application\/x-httpd-php-source",
"phtml" : "application\/x-httpd-php",
"png" : ["image\/png", "image\/x-png"],
"ppt" : ["application\/powerpoint", "application\/vnd.ms-powerpoint"],
"pptx" : ["application\/vnd.openxmlformats-officedocument.presentationml.presentation", "application\/x-zip", "application\/zip"],
"ps" : "application\/postscript",
"psd" : ["application\/x-photoshop", "image\/vnd.adobe.photoshop"],
"qt" : "video\/quicktime",
"ra" : "audio\/x-realaudio",
"ram" : "audio\/x-pn-realaudio",
"rar" : ["application\/x-rar", "application\/rar", "application\/x-rar-compressed"],
"rm" : "audio\/x-pn-realaudio",
"rpm" : "audio\/x-pn-realaudio-plugin",
"rsa" : "application\/x-pkcs7",
"rtf" : "text\/rtf",
"rtx" : "text\/richtext",
"rv" : "video\/vnd.rn-realvideo",
"sea" : "application\/octet-stream",
"shtml" : ["text\/html", "text\/plain"],
"sit" : "application\/x-stuffit",
"smi" : "application\/smil",
"smil" : "application\/smil",
"so" : "application\/octet-stream",
"sst" : "application\/octet-stream",
"swf" : "application\/x-shockwave-flash",
"tar" : "application\/x-tar",
"text" : "text\/plain",
"tgz" : ["application\/x-tar", "application\/x-gzip-compressed"],
"tif" : "image\/tiff",
"tiff" : "image\/tiff",
"txt" : "text\/plain",
"vlc" : "application\/videolan",
"wav" : ["audio\/x-wav", "audio\/wave", "audio\/wav"],
"wbxml" : "application\/wbxml",
"webm" : "video\/webm",
"wma" : ["audio\/x-ms-wma", "video\/x-ms-asf"],
"wmlc" : "application\/wmlc",
"wmv" : ["video\/x-ms-wmv", "video\/x-ms-asf"],
"word" : ["application\/msword", "application\/octet-stream"],
"xht" : "application\/xhtml+xml",
"xhtml" : "application\/xhtml+xml",
"xl" : "application\/excel",
"xls" : ["application\/vnd.ms-excel", "application\/msexcel", "application\/x-msexcel", "application\/x-ms-excel", "application\/x-excel", "application\/x-dos_ms_excel", "application\/xls", "application\/x-xls", "application\/excel", "application\/download", "application\/vnd.ms-office", "application\/msword"],
"xlsx" : ["application\/vnd.openxmlformats-officedocument.spreadsheetml.sheet", "application\/zip", "application\/vnd.ms-excel", "application\/msword", "application\/x-zip"],
"xml" : ["application\/xml", "text\/xml", "text\/plain"],
"xsl" : ["application\/xml", "text\/xsl", "text\/xml"],
"xspf" : "application\/xspf+xml",
"zip" : ["application\/x-zip", "application\/zip", "application\/x-zip-compressed", "application\/s-compressed", "multipart\/x-zip"],
"zsh" : "text\/x-scriptzsh"
}

View File

@@ -0,0 +1,248 @@
<?php
// if we have to generate a CAPTCHA image
if (isset($_GET['captcha']) && ($_GET['captcha'] == 1 || $_GET['captcha'] == 2)) {
// storage method
$storage = ($_GET['captcha'] == 2 ? 'session' : 'cookie');
// if storage method is "session", start a session
if ($storage == 'session') session_start();
// as this file actually generates an image we set the headers accordingly
header('Content-type:image/jpeg');
$font_path = rtrim(implode(DIRECTORY_SEPARATOR, array_slice(explode(DIRECTORY_SEPARATOR, __FILE__), 0, -2)), DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . basename(dirname(__FILE__)) . DIRECTORY_SEPARATOR . 'includes/';
// the number of characters to be used in the generated image
$charactersNumber = 5;
// spacing between characters (this can also be a negative number)
// you should leave this as it is (unless you want to increase it)
// decreasing this value may result in characters overlapping and being hardly distinguishable
$characterSpacing = -2;
// each character's size will be randomly selected from this range
$fontSizeVariation = array(20, 40);
// each character's angle will be randomly selected from this range
// (remember to also change the character spacing if you change these to avoid character overlapping)
$fontAngleVariation = array(-10, 10);
// if you changed anything above, you should probably change this too si that all the characters fit into the image
// and there's not too much of blank space
$imageWidth = 140;
// if you changed anything above, you should probably change this too si that all the characters fit into the image
// and there's not too much of blank space
$imageHeight = 50;
// the quality, in percents, of the generated image
$imageQuality = 70;
// list of characters from which to choose
// (notice that characters that can be (in some circumstances) confused with others, are missing)
// you should not alter this setting
$charList = 'bcdkmpsx345678';
$captcha = array();
$resultString = '';
$totalWidth = 0;
// this is the used font
$font = $font_path . 'babelsans-bold.ttf';
// first we figure out how much space the character would take
for ($i = 0; $i < $charactersNumber; $i++) {
// get a random character
$char = $charList[rand(0, strlen($charList) - 1)];
$resultString .= $char;
// get a random size for the character
$charSize = rand($fontSizeVariation[0], $fontSizeVariation[1]);
// get a random angle for the character
$charAngle = rand($fontAngleVariation[0], $fontAngleVariation[1]);
// get the bounding box of the character
$bbox = imagettfbbox($charSize, $charAngle, $font, $char);
// resolve the returned measurements
$bbox['left'] = abs(min($bbox[0], $bbox[2], $bbox[4], $bbox[6]));
$bbox['top'] = abs(min($bbox[1], $bbox[3], $bbox[5], $bbox[7]));
$bbox['width'] = max($bbox[0], $bbox[2], $bbox[4], $bbox[6]) - min($bbox[0], $bbox[2], $bbox[4], $bbox[6]);
$bbox['height'] = max($bbox[1], $bbox[3], $bbox[5], $bbox[7]) - min($bbox[1], $bbox[3], $bbox[5], $bbox[7]);
// this will be the total width of the random generated word
$totalWidth += $bbox['width'] + $characterSpacing;
// save info about the current character
$captcha[] = array(
'char' => $char,
'size' => $charSize,
'angle' => $charAngle,
'box' => $bbox
);
}
// encode value
$value = md5(md5(md5($resultString)));
// if storage is "session", store the value in session
if ($storage == 'session') $_SESSION['captcha'] = $value;
// otherwise, store the value in a cookie
else setcookie('captcha', $value, time() + 3600, '/');
// either ways, the value will later be read by the form generator
// and used to see if the user entered the correct characters
// create the image
$img = imagecreatetruecolor($imageWidth, $imageHeight);
// allocate some colors
$white = imagecolorallocate($img, 255, 255, 255);
$black = imagecolorallocate($img, 0, 0, 0);
// fill the canvas to white
imagefilledrectangle($img, 0, 0, $imageWidth, $imageHeight, $white);
// write some random characters in the background
for ($i = 0; $i <10; $i++) {
// ...having random washed-out colors
$color = imagecolorallocate($img, rand(150, 200), rand(150, 200), rand(150, 200));
imagettftext(
$img,
20,
rand($fontAngleVariation[0],
$fontAngleVariation[1]),
rand(0, $imageWidth),
rand(20, $imageHeight) ,
$color,
$font,
chr(rand(65, 90))
);
}
// draw a bounding rectangle
// imagerectangle($img, 0, 0, $imageWidth - 1, $imageHeight - 1, $black);
// this is to keep the word centered in the box
$left = (($imageWidth - $totalWidth) / 2);
// iterate through the chosen characters
foreach ($captcha as $values) {
// print each character
imagettftext(
$img,
$values['size'],
$values['angle'],
$left ,
($imageHeight + $values['box']['height']) / 2 ,
$black,
$font,
$values['char']
);
// compute the position of the next character
$left += $values['box']['width'] + $characterSpacing;
}
// and finally output the image at the specified quality
imagejpeg($img, null, $imageQuality);
// free memory
imagedestroy($img);
// if we're performing a file upload
} elseif (
isset($_FILES) &&
is_array($_FILES) &&
!empty($_FILES) &&
isset($_GET['form']) &&
isset($_GET['control']) &&
isset($_FILES[$_GET['control']])
) {
function process() {
// the form that initiated the request
$form = $_GET['form'];
// the file upload control on the form that initiated the request
$control = $_GET['control'];
// if file could be uploaded
if (isset($_FILES[$_GET['control']])) {
// save some information about the uploaded file
$file['name'] = $_FILES[$control]['name'];
$file['type'] = $_FILES[$control]['type'];
$file['error'] = $_FILES[$control]['error'];
$file['size'] = $_FILES[$control]['size'];
// if there were problems uploading the file
} elseif (empty($_POST) && empty($_FILES) && isset($_SERVER['CONTENT_LENGTH']) && isset($_SERVER['CONTENT_TYPE']) && (strpos($_SERVER['CONTENT_TYPE'], 'multipart/form-data') !== false || strpos($_SERVER['CONTENT_TYPE'], 'application/x-www-form-urlencoded') !== false)) {
// send these values
$file['name'] = '';
$file['type'] = 'unknown';
$file['error'] = 1;
$file['size'] = $_SERVER['CONTENT_LENGTH'];
}
ob_start();
?>
<script type="text/javascript">
var f=parent.window.$('#<?php echo $form?>');
if(undefined!=f){
f.data('Zebra_Form').end_file_upload('<?php echo $control . '\'' . (isset($file) ? ',[\'' . addcslashes($file['name'], '\'') . '\',\'' . $file['type'] . '\',\'' . $file['error'] . '\',\'' . $file['size'] . '\']' : '')?>)
}
</script>
<?php
$contents = ob_get_contents();
ob_end_clean();
$patterns = array(
'/^\s*/m',
'/\r/m',
'/\n/m',
'/\r\n/m',
);
$replacements = array(
'',
);
echo preg_replace($patterns, $replacements, $contents);
}
register_shutdown_function('process');
}
?>

Binary file not shown.

After

Width:  |  Height:  |  Size: 145 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 218 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 238 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 672 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 894 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

Some files were not shown because too many files have changed in this diff Show More