1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183
<?php
namespace hji\membership\controllers;
use hji\membership\Membership;
use hji\common\utils\GFHelper;
use hji\common\models\GForms as GFormsModel;
class GForms
{
protected $gFormsModel;
function __construct()
{
$this->gFormsModel = new GFormsModel();
}
function setWPActions()
{
add_action('init', array($this, 'setActions'));
}
function setActions()
{
if (!GFHelper::gravityFormsExists())
{
return;
}
if (is_admin())
{
add_filter('gform_form_settings', array($this, 'gformFormSettings'), 10, 2);
add_filter('gform_pre_form_settings_save', array($this, 'saveCustomFormSetting'));
add_filter('gform_tooltips', array($this, 'formSettingsTooltips'));
add_action('gform_field_advanced_settings',array($this, "fieldsSettings"), 10, 2);
add_action('gform_editor_js', array($this, "gfEditorScript"));
}
else
{
add_filter("gform_field_content", array($this, "parseDataTagsViaPostObject"), 10, 5);
}
}
function gformFormSettings($settings, $form)
{
$settings['Form Basics'][GFormsModel::HJI_FORM_KEY] = "\n" .
"<tr>\n" .
" <th>" .
" <label for=\"" . GFormsModel::HJI_FORM_KEY . "\">Form Key</label> \n" .
gform_tooltip(GFormsModel::HJI_FORM_KEY, '', true) . "\n" .
" </th>\n" .
" <td>\n" .
' <input value="' . rgar($form, GFormsModel::HJI_FORM_KEY) . '" name="' .
GFormsModel::HJI_FORM_KEY . '" class="fieldwidth-3">' . "\n" .
" </td>\n" .
"</tr>\n";
return $settings;
}
function saveCustomFormSetting($form)
{
$form[GFormsModel::HJI_FORM_KEY] = rgpost(GFormsModel::HJI_FORM_KEY);
return $form;
}
function formSettingsTooltips($tooltips)
{
$tooltips[GFormsModel::HJI_FORM_KEY] = "Form key by which HJI products identify forms. Changing existing key can stop HJI plugins from finding the right forms.";
$tooltips["form_field_" . GFormsModel::HJI_FIELD_KEY] = "Field key is used by HJI plugins instead of field IDs to identify fields.";
return $tooltips;
}
function fieldsSettings($position, $form_id)
{
$form = \GFFormsModel::get_form_meta($form_id);
if ($this->gFormsModel->isHJIform($form))
{
if($position == 50){
?>
<li class="<?php echo GFormsModel::HJI_FIELD_KEY; ?> field_setting">
<label for="field_<?php echo GFormsModel::HJI_FIELD_KEY; ?>">
<?php _e("HJI Field Key", "gravityforms"); ?>
<?php gform_tooltip("form_field_" . GFormsModel::HJI_FIELD_KEY) ?>
</label>
<input type="text" id="field_<?php echo GFormsModel::HJI_FIELD_KEY; ?>" size="30" onkeyup="SetFieldProperty('<?php echo GFormsModel::HJI_FIELD_KEY; ?>', this.value);"/>
</li>
<?php
}
}
}
function gfEditorScript()
{
?>
<script type='text/javascript'>
for(var i in fieldSettings)
{
fieldSettings[i] += ", .<?php echo GFormsModel::HJI_FIELD_KEY; ?>";
}
jQuery(document).bind("gform_load_field_settings", function(event, field, form){
if (field["<?php echo GFormsModel::HJI_FIELD_KEY; ?>"] != 'undefined')
{
jQuery('#field_<?php echo GFormsModel::HJI_FIELD_KEY; ?>').val(field["<?php echo GFormsModel::HJI_FIELD_KEY; ?>"]);
}
});
</script>
<?php
}
function parseDataTagsViaPostObject($content, $field, $value, $lead_id, $form_id)
{
if (is_string($value))
{
$json = json_decode($value);
if (json_last_error() == JSON_ERROR_NONE)
{
return $content;
}
}
$content = preg_replace_callback(
'/\{([-a-zA-z0-9_.^\}]+)\}/',
function($matches) {
global $post;
$parts = explode('.', $matches[1]);
if (count($parts) == 2)
{
if (isset($post->$parts[0]->$parts[1]))
{
return $post->$parts[0]->$parts[1];
}
}
else if (count($parts) == 3)
{
if (isset($post->$parts[0]->$parts[1]->$parts[2]))
{
return $post->$parts[0]->$parts[1]->$parts[2];
}
}
return $matches[0];
}, $content);
return $content;
}
}