PluginProbe
Contact Forms by Cimatti / 2.1.2
Contact Forms by Cimatti v2.1.2
2.3.6 2.3.5 2.3.0 2.2.32 2.2.4 2.2.0 2.1.2 2.1.1 trunk 1.0 1.1 1.2 1.2.1 1.3 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.3.7 1.3.8 1.3.9 1.4.0 1.4.1 All 62 releases
contact-forms / PFBC / Base.php

Base.php in Contact Forms by Cimatti 2.1.2, at PFBC/Base.php

74 lines 2.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * PFBC (PHP Form Builder Class) - Third-party library
4 * @package PFBC
5 */
6
7 // phpcs:disable WordPress.Security.EscapeOutput, WordPress.PHP.DevelopmentFunctions, WordPress.NamingConventions.PrefixAllGlobals, PluginCheck.CodeAnalysis.Heredoc -- Third-party library
8
9 abstract class Base {
10 public function configure(?array $properties = null) {
11 if(!empty($properties)) {
12 $class = get_class($this);
13
14 /*The property_reference lookup array is created so that properties can be set
15 case-insensitively.*/
16 $available = array_keys(get_object_vars($this));
17 $property_reference = array();
18 foreach($available as $property)
19 $property_reference[strtolower($property)] = $property;
20
21 /*The method reference lookup array is created so that "set" methods can be called
22 case-insensitively.*/
23 $available = get_class_methods($class);
24 $method_reference = array();
25 foreach($available as $method)
26 $method_reference[strtolower($method)] = $method;
27
28 foreach($properties as $property => $value) {
29 $property = strtolower($property);
30 /*The attributes property cannot be set directly.*/
31 if($property != "attributes") {
32 /*If the appropriate class has a "set" method for the property provided, then
33 it is called instead or setting the property directly.*/
34 if(isset($method_reference["set" . $property]))
35 $this->{$method_reference["set" . $property]}($value);
36 elseif(isset($property_reference[$property]))
37 $this->{$property_reference[$property]} = $value;
38 /*Entries that don't match an available class property are stored in the attributes
39 property if applicable. Typically, these entries will be element attributes such as
40 class, value, onkeyup, etc.*/
41 elseif(isset($property_reference["attributes"]))
42 $this->attributes[$property] = $value;
43 }
44 }
45 }
46 return $this;
47 }
48
49 /*This method can be used to view a class' state.*/
50 public function debug() {
51 echo "<pre>", print_r($this, true), "</pre>";
52 }
53
54 /*This method prevents double/single quotes in html attributes from breaking the markup.*/
55 protected function filter($str) {
56 return htmlspecialchars($str);
57 }
58
59 /*This method is used by the Form class and all Element classes to return a string of html
60 attributes. There is an ignore parameter that allows special attributes from being included.*/
61 public function getAttributes($ignore = "") {
62 $str = "";
63 if(!empty($this->attributes)) {
64 if(!is_array($ignore))
65 $ignore = array($ignore);
66 $attributes = array_diff(array_keys($this->attributes), $ignore);
67 foreach($attributes as $attribute)
68 $str .= ' ' . $attribute . '="' . $this->filter($this->attributes[$attribute]) . '"';
69 }
70 return $str;
71 }
72 }
73 ?>
74