static function make_field($type, $id, $default, $label, $defaults = array()) { $rawid = $id; $idLabel = ''; if (GFDirectory::is_gravity_page('gf_settings')) { $id = 'gf_addons_directory_defaults[' . $id . ']'; $idLabel = " <span style='color:#868686'>(<pre style='display:inline'>{$rawid}</pre>)</span>"; } $checked = ''; $label = str_replace('<code>', '<code>', str_replace('</code>', '</code>', $label)); $output = '<li class="setting-container" style="width:90%; clear:left; border-bottom: 1px solid #cfcfcf; padding:.25em .25em .4em; margin-bottom:.25em;">'; $default = maybe_unserialize($default); $class = ''; if ($type == 'date') { $type = 'text'; $class = ' class="gf_addons_datepicker datepicker"'; } if ($type == "checkbox") { if (!empty($defaults["{$rawid}"]) || ($defaults["{$rawid}"] === '1' || $defaults["{$rawid}"] === 1)) { $checked = ' checked="checked"'; } $output .= '<label for="gf_settings_' . $rawid . '"><input type="hidden" value="" name="' . $id . '" /><input type="checkbox" id="gf_settings_' . $rawid . '"' . $checked . ' name="' . $id . '" /> ' . $label . $idLabel . '</label>' . "\n"; } elseif ($type == "text") { $default = $defaults["{$rawid}"]; $output .= '<label for="gf_settings_' . $rawid . '"><input type="text" id="gf_settings_' . $rawid . '" value="' . htmlspecialchars(stripslashes($default)) . '" style="width:40%;" name="' . $id . '"' . $class . ' /> <span class="howto">' . $label . $idLabel . '</span></label>' . "\n"; } elseif ($type == 'radio' || $type == 'checkboxes') { if (is_array($default)) { $output .= $label . $idLabel . '<ul class="ul-disc">'; foreach ($default as $opt) { if ($type == 'radio') { $id_opt = $id . '_' . sanitize_title($opt['value']); if (!empty($defaults["{$rawid}"]) && $defaults["{$rawid}"] == $opt['value']) { $checked = ' checked="checked"'; } else { $checked = ''; } $inputtype = 'radio'; $name = $id; $value = $opt['value']; $output .= ' <li><label for="gf_settings_' . $id_opt . '">'; } else { $id_opt = $rawid . '_' . sanitize_title($opt['value']); if (!empty($defaults["{$rawid}"][sanitize_title($opt['value'])])) { $checked = ' checked="checked"'; } else { $checked = ''; } $inputtype = 'checkbox'; $name = $id . '[' . sanitize_title($opt['value']) . ']'; $value = 1; $output .= ' <li><label for="gf_settings_' . $id_opt . '"> <input type="hidden" value="0" name="' . $name . '" />'; } $output .= ' <input type="' . $inputtype . '"' . $checked . ' value="' . $value . '" id="gf_settings_' . $id_opt . '" name="' . $name . '" /> ' . $opt['label'] . " <span style='color:#868686'>(<pre style='display:inline'>" . sanitize_title($opt['value']) . "</pre>)</span>" . ' </label> </li>' . "\n"; } $output .= "</ul>"; } } elseif ($type == 'select') { if (is_array($default)) { $output .= ' <label for="gf_settings_' . $rawid . '">' . $label . ' <select name="' . $id . '" id="gf_settings_' . $rawid . '">'; foreach ($default as $opt) { if (!empty($defaults["{$rawid}"]) && $defaults["{$rawid}"] == $opt['value']) { $checked = ' selected="selected"'; } else { $checked = ''; } $id_opt = $id . '_' . sanitize_title($opt['value']); $output .= '<option' . $checked . ' value="' . $opt['value'] . '"> ' . $opt['label'] . '</option>' . "\n"; } $output .= '</select>' . $idLabel . ' </label> '; } else { $output = ''; } } if (!empty($output)) { $output .= '</li>' . "\n"; echo $output; } }
private static function is_gravity_page($page = array()) { return GFDirectory::is_gravity_page($page); }