PluginProbe
LoftLoader / 1.0.1
LoftLoader v1.0.1
trunk 1.0.0 1.0.1 1.0.2 2.0.0 2.1.0 2.1.1 2.1.10 2.1.11 2.1.12 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.1.7 2.1.8 2.1.9 2.2.0 2.2.1 2.2.2 2.3 2.3.1 2.3.2 2.3.3 All 34 releases
loftloader / settings / form / class-loftloader-form-base.php

class-loftloader-form-base.php in LoftLoader 1.0.1, at settings/form/class-loftloader-form-base.php

107 lines 3.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 // Not allowed by directly accessing.
3 if(!defined('ABSPATH')){
4 die('Access not allowed!');
5 }
6 /**
7 * Plugin option form element class
8 * The base class of each type of form element
9 *
10 * @package LoftLoader
11 * @version 1.0
12 * @link http://www.loftocean.com/
13 * @author Suihai Huang from Loft Ocean Team
14
15 * @since version 1.0
16 */
17
18 if(!class_exists('LoftLoader_Form_Base')){
19 abstract class LoftLoader_Form_Base{
20 protected $name; // Form element name
21 protected $title; // Field title
22 protected $description; // Field description
23 protected $extra; // Extra arguments, may include the class infos
24 protected $options; // Option for some type of form element, radio/select/check
25 protected $values; // Form element value
26 public function __construct($name, $title, $description, $options, $values, $extra = array()){
27 $this->name = $name;
28 $this->title = $title;
29 $this->extra = $extra;
30 $this->values = $values;
31 $this->options = $options;
32 $this->description = $description;
33 }
34 /**
35 * @description show the html of each form element
36 */
37 public function render(){
38 if($this->options){
39 $replace = array('[[TITLE]]' => $this->title, '[[DESCRIPTION]]' => $this->description(), '[[INFO]]' => $this->field_info(), '[[LINKS]]' => $this->links(), '[[CONTENT]]' => $this->content());
40 echo strtr($this->template(), $replace);
41 }
42 }
43 /**
44 * @description form element HTML template
45 */
46 protected function template(){
47 $class = (isset($this->extra['wrapperClass']) && $this->extra['wrapperClass'])? ' ' . $this->extra['wrapperClass'] : '';
48 $html = <<<ETO
49 <div class="list-title">
50 <h4>[[TITLE]]</h4>
51 [[DESCRIPTION]][[INFO]][[LINKS]]
52 </div>
53 <div class="list-content$class">
54 <fieldset><legend class="screen-reader-text"><span>[[TITLE]]</span></legend>[[CONTENT]]</fieldset>
55 </div>
56 ETO;
57 return $html;
58 }
59 /**
60 * @description get field content
61 */
62 protected function content(){
63 $html = '';
64 if($this->options){
65 foreach($this->options as $val=>$text){
66 $checked = ($default_value[$this->name] == $val)?' checked':'';
67 $html .= '<label><input type="checkbox" name="' . $this->name . '" value="' . $val . '"' . $checked . '>' . $text['label'] . '</label>';
68 }
69 }
70 return $html;
71 }
72 /**
73 * @description get field info if any, normally this should be the tips
74 */
75 protected function field_info(){
76 $html = '';
77 if(isset($this->extra['info'])){
78 $html .= '<p><i class="fa fa-info-circle"></i> ' . $this->extra['info'] . '</p>';
79 }
80 return $html;
81 }
82 /**
83 * @description field description if any
84 */
85 protected function description(){
86 $html = '';
87 if(isset($this->description) && !empty($this->description)){
88 $html .= '<span class="description">' . $this->description . '</span>';
89 }
90 return $html;
91 }
92 /**
93 * @description fields links if any
94 */
95 protected function links(){
96 $html = '';
97 if(isset($this->extra['links']) && is_array($this->extra['links'])){
98 $html .= '<ul>';
99 foreach($this->extra['links'] as $text=>$link){
100 $html .= '<li><a href="' . $link . '">' . $text . '</a></li>';
101 }
102 $html .= '</ul>';
103 }
104 return $html;
105 }
106 }
107 }