| 1 |
<?php |
| 2 |
/* |
| 3 |
* Followig class handling select input control and their |
| 4 |
* dependencies. Do not make changes in code |
| 5 |
* Create on: 9 November, 2013 |
| 6 |
*/ |
| 7 |
|
| 8 |
class NM_Select extends NM_Inputs_wpcomment{ |
| 9 |
|
| 10 |
/* |
| 11 |
* input control settings |
| 12 |
*/ |
| 13 |
var $title, $desc, $settings; |
| 14 |
|
| 15 |
/* |
| 16 |
* this var is pouplated with current plugin meta |
| 17 |
*/ |
| 18 |
var $plugin_meta; |
| 19 |
|
| 20 |
function __construct(){ |
| 21 |
|
| 22 |
$this -> plugin_meta = get_plugin_meta_wpcomment(); |
| 23 |
|
| 24 |
$this -> title = __ ( 'Select-box Input', 'nm-wpcomments' ); |
| 25 |
$this -> desc = __ ( 'regular select-box input', 'nm-wpcomments' ); |
| 26 |
$this -> settings = self::get_settings(); |
| 27 |
|
| 28 |
} |
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
private function get_settings(){ |
| 34 |
|
| 35 |
return array ( |
| 36 |
'title' => array ( |
| 37 |
'type' => 'text', |
| 38 |
'title' => __ ( 'Title', 'nm-wpcomments' ), |
| 39 |
'desc' => __ ( 'It will be shown as field label', 'nm-wpcomments' ) |
| 40 |
), |
| 41 |
'data_name' => array ( |
| 42 |
'type' => 'text', |
| 43 |
'title' => __ ( 'Data name', 'nm-wpcomments' ), |
| 44 |
'desc' => __ ( 'REQUIRED: The identification name of this field, that you can insert into body email configuration. Note:Use only lowercase characters and underscores.', 'nm-wpcomments' ) |
| 45 |
), |
| 46 |
'description' => array ( |
| 47 |
'type' => 'text', |
| 48 |
'title' => __ ( 'Description', 'nm-wpcomments' ), |
| 49 |
'desc' => __ ( 'Small description, it will be diplay near name title.', 'nm-wpcomments' ) |
| 50 |
), |
| 51 |
'error_message' => array ( |
| 52 |
'type' => 'text', |
| 53 |
'title' => __ ( 'Error message', 'nm-wpcomments' ), |
| 54 |
'desc' => __ ( 'Insert the error message for validation.', 'nm-wpcomments' ) |
| 55 |
), |
| 56 |
|
| 57 |
'options' => array ( |
| 58 |
'type' => 'textarea', |
| 59 |
'title' => __ ( 'Add options', 'nm-wpcomments' ), |
| 60 |
'desc' => __ ( 'Type each option per line', 'nm-wpcomments' ) |
| 61 |
), |
| 62 |
'selected' => array ( |
| 63 |
'type' => 'text', |
| 64 |
'title' => __ ( 'Selected option', 'nm-wpcomments' ), |
| 65 |
'desc' => __ ( 'Type option name (given above) if you want already selected.', 'nm-wpcomments' ) |
| 66 |
), |
| 67 |
|
| 68 |
'required' => array ( |
| 69 |
'type' => 'checkbox', |
| 70 |
'title' => __ ( 'Required', 'nm-wpcomments' ), |
| 71 |
'desc' => __ ( 'Select this if it must be required.', 'nm-wpcomments' ), |
| 72 |
), |
| 73 |
|
| 74 |
'class' => array ( |
| 75 |
'type' => 'text', |
| 76 |
'title' => __ ( 'Class', 'nm-wpcomments' ), |
| 77 |
'desc' => __ ( 'Insert an additional class(es) (separateb by comma) for more personalization.', 'nm-wpcomments' ) |
| 78 |
), |
| 79 |
|
| 80 |
'width' => array ( |
| 81 |
'type' => 'select', |
| 82 |
'default' => '6', |
| 83 |
'options' => array('12'=>'12 Columns','6'=>'6 Columns', '4'=>'4 Columns', '3'=>'3 Columns',), |
| 84 |
'title' => __ ( 'Width', 'nm-wpcomments' ), |
| 85 |
'desc' => __ ( 'Select column for this field (12 Columns Grid)', 'nm-wpcomments' ) |
| 86 |
), |
| 87 |
|
| 88 |
); |
| 89 |
} |
| 90 |
|
| 91 |
|
| 92 |
/* |
| 93 |
* @params: $options |
| 94 |
*/ |
| 95 |
function render_input($args, $options="", $default=""){ |
| 96 |
|
| 97 |
$_html = '<select '; |
| 98 |
|
| 99 |
foreach ($args as $attr => $value){ |
| 100 |
|
| 101 |
$_html .= $attr.'="'.stripslashes( $value ).'"'; |
| 102 |
} |
| 103 |
|
| 104 |
$_html .= '>'; |
| 105 |
|
| 106 |
$_html .= '<option value="">'.__('Select option', $this -> plugin_meta['shortname']).'</option>'; |
| 107 |
|
| 108 |
foreach($options as $opt) |
| 109 |
{ |
| 110 |
|
| 111 |
$selected = ($opt == $default) ? 'selected="selected"' : ''; |
| 112 |
$output = stripslashes(trim($opt)); |
| 113 |
|
| 114 |
$_html .= '<option value="'.$opt.'" '. $selected.'>'; |
| 115 |
$_html .= $output; |
| 116 |
$_html .= '</option>'; |
| 117 |
} |
| 118 |
|
| 119 |
$_html .= '</select>'; |
| 120 |
|
| 121 |
echo $_html; |
| 122 |
} |
| 123 |
} |