Skip to content
This repository has been archived by the owner on Apr 26, 2022. It is now read-only.

Commit

Permalink
added PHP 7 compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
denisdulici committed Apr 11, 2016
1 parent f2012ad commit 47d51b0
Show file tree
Hide file tree
Showing 26 changed files with 201 additions and 105 deletions.
9 changes: 6 additions & 3 deletions Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ public function configure(array $properties = null)
$method_reference = array();

foreach ($available as $method) {

$method_reference[strtolower($method)] = $method;
}

Expand All @@ -45,9 +44,13 @@ public function configure(array $properties = null)
/*If the appropriate class has a "set" method for the property provided, then
it is called instead or setting the property directly.*/
if (isset($method_reference["set" . $property])) {
$this->$method_reference["set" . $property]($value);
$func = $method_reference["set" . $property];

$this->$func($value);
} elseif (isset($property_reference[$property])) {
$this->$property_reference[$property] = $value;
$prop = $property_reference[$property];

$this->$prop = $value;
} else {
/*Entries that don't match an available class property are stored in the attributes
property if applicable. Typically, these entries will be element attributes such as
Expand Down
4 changes: 2 additions & 2 deletions Element.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,9 @@ public function jQueryOptions()
/*Many of the included elements make use of the <input> tag for display. These include the Hidden, Textbox,
Password, Date, Color, Button, Email, and File element classes. The project's other element classes will
override this method with their own implementation.*/
public function render()
public function getInput()
{
echo '<input', $this->getAttributes(), '/>';
return '<input' . $this->getAttributes() . '/>';
}

/*If an element requires inline stylesheet definitions, this method is used send them to the browser before
Expand Down
12 changes: 9 additions & 3 deletions Element/CKEditor.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,17 @@ class CKEditor extends Textarea

public function render()
{
echo "<textarea", $this->getAttributes(array("value", "required")), ">";
$html = '';

$html .= "<textarea" . $this->getAttributes(array("value", "required")) . ">";

if (!empty($this->attributes["value"])) {
echo $this->attributes["value"];
$html .= $this->attributes["value"];
}
echo "</textarea>";

$html .= "</textarea>";

return $html;
}

public function renderJS()
Expand Down
4 changes: 2 additions & 2 deletions Element/Captcha.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ public function __construct($label = "", array $properties = null)
parent::__construct($label, "recaptcha_response_field", $properties);
}

public function render()
public function getInput()
{
$this->validation[] = new ValidationCaptcha($this->privateKey);

require_once(__DIR__ . "/../Resources/recaptchalib.php");

echo recaptcha_get_html($this->publicKey);
return recaptcha_get_html($this->publicKey);
}
}
14 changes: 9 additions & 5 deletions Element/Checkbox.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@ class Checkbox extends OptionElement
protected $attributes = array("type" => "checkbox");
protected $inline;

public function render()
public function getInput()
{
$html = '';

if (isset($this->attributes["value"])) {
if (!is_array($this->attributes["value"])) {
$this->attributes["value"] = array($this->attributes["value"]);
Expand All @@ -41,18 +43,20 @@ public function render()
foreach ($this->options as $value => $text) {
$value = $this->getOptionValue($value);

echo '<label class="' . $labelClass . '">
$html .= '<label class="' . $labelClass . '">
<input id="' . $this->attributes["id"] . '-' . $count . '"' .
$this->getAttributes(array("id", "value", "checked", "required")) .
' value="' . $this->filter($value) . '"';

if (in_array($value, $this->attributes["value"])) {
echo ' checked="checked"';
$html .= ' checked="checked"';
}
echo '/> ' . $text . ' </label> ';

$html .= '/> ' . $text . ' </label> ';

++$count;
}

return $html;
}
}
20 changes: 12 additions & 8 deletions Element/Checksort.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@ class Checksort extends Sort
protected $attributes = array("type" => "checkbox");
protected $inline;

public function render()
public function getInput()
{
$html = '';

if (isset($this->attributes["value"])) {
if (!is_array($this->attributes["value"])) {
$this->attributes["value"] = array($this->attributes["value"]);
Expand All @@ -41,19 +43,19 @@ public function render()
$value = $this->getOptionValue($value);

if (!empty($this->inline) && $count > 0) {
echo ' ';
$html .= ' ';
}
echo '<label class="' . $labelClass . '">

$html .= '<label class="' . $labelClass . '">
<input id="' . $this->attributes["id"] . '-' . $count . '"' .
$this->getAttributes(array("id", "value", "checked", "name", "onclick", "required")) .
' value="' . $this->filter($value) . '"';

if (in_array($value, $this->attributes["value"])) {
echo ' checked="checked"';
$html .= ' checked="checked"';
}
echo ' onclick="updateChecksort(this, \'' .

$html .= ' onclick="updateChecksort(this, \'' .
str_replace(array('"', "'"), array('&quot;', "\'"), $text) . '\');"/>' . $text . '</label>';

if (in_array($value, $this->attributes["value"])) {
Expand All @@ -65,7 +67,9 @@ public function render()
++$count;
}

echo '<ul id="' . $this->attributes["id"] . '">' . $existing . '</ul>';
$html .= '<ul id="' . $this->attributes["id"] . '">' . $existing . '</ul>';

return $html;
}

public function renderJS()
Expand Down
6 changes: 5 additions & 1 deletion Element/Color.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,17 @@ class Color extends Textbox

public function render()
{
$html = '';

$this->attributes["pattern"] = "#[a-g0-9]{6}";
$this->attributes["title"] = "6-digit hexidecimal color (e.g. #000000)";

$msg = "Error: The %element% field must contain a " . $this->attributes["title"];

$this->validation[] = new RegExp("/" . $this->attributes["pattern"] . "/", $msg);

parent::render();
$html .= parent::getInput();

return $html;
}
}
8 changes: 6 additions & 2 deletions Element/Date.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,16 @@ public function __construct($label, $name, array $properties = null)
parent::__construct($label, $name, $properties);
}

public function render()
public function getInput()
{
$html = '';

$msg = "Error: The %element% field must match the following date format: " . $this->attributes["title"];

$this->validation[] = new RegExp("/" . $this->attributes["pattern"] . "/", $msg);

parent::render();
$html .= parent::getInput();

return $html;
}
}
6 changes: 5 additions & 1 deletion Element/Email.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,12 @@ class Email extends Textbox

public function render()
{
$html = '';

$this->validation[] = new ValidationEmail();

parent::render();
$html .= parent::getInput();

return $html;
}
}
4 changes: 2 additions & 2 deletions Element/HTML.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ public function __construct($value)
parent::__construct("", "", $properties);
}

public function render()
public function getInput()
{
echo $this->attributes["value"];
return $this->attributes["value"];
}
}
8 changes: 6 additions & 2 deletions Element/JQueryUIDate.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,14 @@ public function jQueryDocumentReady()
echo 'jQuery("#', $this->attributes["id"], '").datepicker(', $this->jQueryOptions(), ');';
}

public function render()
public function getInput()
{
$html = '';

$this->validation[] = new Date;

parent::render();
$html .= parent::getInput();

return $html;
}
}
10 changes: 7 additions & 3 deletions Element/Month.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,16 @@ public function __construct($label, $name, array $properties = null)
parent::__construct($label, $name, $properties);
}

public function render()
public function getInput()
{
$msg = "Error: The %element% field must match the following date format: " . $this->attributes["title"];
$html = '';

$msg = "Error: The %element% field must match the following date format: " . $this->attributes["title"];

$this->validation[] = new RegExp("/" . $this->attributes["pattern"] . "/", $msg);

parent::render();
$html .= parent::getInput();

return $html;
}
}
6 changes: 5 additions & 1 deletion Element/Number.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,12 @@ class Number extends Textbox

public function render()
{
$html = '';

$this->validation[] = new Numeric;

parent::render();
$html .= parent::getInput();

return $html;
}
}
12 changes: 8 additions & 4 deletions Element/Radio.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@ class Radio extends OptionElement
protected $attributes = array("type" => "radio", "labelclass" => "");
protected $inline;

public function render()
public function getInput()
{
$html = '';

$labelClass = $this->attributes["type"];
$labelClass .= " " . $this->attributes["labelclass"];

Expand All @@ -30,17 +32,19 @@ public function render()
foreach ($this->options as $value => $text) {
$value = $this->getOptionValue($value);

echo '<label class="' . $labelClass . '">
$html .= '<label class="' . $labelClass . '">
<input id="' . $this->attributes["id"] . '-' . $count . '"' .
$this->getAttributes(array("id", "value", "checked")) . ' value="' . $this->filter($value) . '"';

if (isset($this->attributes["value"]) && $this->attributes["value"] == $value) {
echo ' checked="checked"';
$html .= ' checked="checked"';
}

echo '/> ' . $text . ' </label> ';
$html .= '/> ' . $text . ' </label> ';

++$count;
}

return $html;
}
}
18 changes: 11 additions & 7 deletions Element/Select.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@ class Select extends OptionElement

protected $attributes = array();

public function render()
public function getInput()
{
$html = '';

if (isset($this->attributes["value"])) {
if (!is_array($this->attributes["value"])) {
$this->attributes["value"] = array($this->attributes["value"]);
Expand All @@ -29,23 +31,25 @@ public function render()
$this->attributes["name"] .= "[]";
}

echo '<select', $this->getAttributes(array("value", "selected")), '>';
$html .= '<select' . $this->getAttributes(array("value", "selected")) . '>';

$selected = false;

foreach ($this->options as $value => $text) {
$value = $this->getOptionValue($value);
echo '<option value="', $this->filter($value), '"';

$html .= '<option value="' . $this->filter($value) . '"';

if (!$selected && in_array($value, $this->attributes["value"])) {
echo ' selected="selected"';
$html .= ' selected="selected"';
$selected = true;
}

echo '>', $text, '</option>';
$html .= '>' . $text . '</option>';
}

echo '</select>';
$html .= '</select>';

return $html;
}
}
13 changes: 9 additions & 4 deletions Element/Sort.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,22 +35,27 @@ public function jQueryDocumentReady()
echo 'jQuery("#' . $this->attributes["id"] . '").disableSelection();';
}

public function render()
public function getInput()
{
$html = '';

if (substr($this->attributes["name"], -2) != "[]") {
$this->attributes["name"] .= "[]";
}

echo '<ul id="' . $this->attributes["id"] . '">';
$html .= '<ul id="' . $this->attributes["id"] . '">';

foreach ($this->options as $value => $text) {
$value = $this->getOptionValue($value);

echo '<li class="ui-state-default">
$html .= '<li class="ui-state-default">
<input type="hidden" name="' . $this->attributes["name"] . '" value="' . $value . '"/>' . $text .
'</li>';
}
echo "</ul>";

$html .= "</ul>";

return $html;
}

public function renderCSS()
Expand Down
Loading

0 comments on commit 47d51b0

Please sign in to comment.