示例#1
0
 public function check_strings_in_shortcodes($atts)
 {
     extract(shortcode_atts(array('post' => '', 'field' => '', 'value' => null, 'taxonomy' => null, 'type' => null, 'display' => null), $atts));
     if ($value !== null && !empty($value) && is_string($value)) {
         cred_translate_register_string('cred-form-' . $this->_form_data['name'] . '-' . $this->_form_data['ID'], $this->_prefix . $value, $value, false);
     }
 }
示例#2
0
 public function registerString($name, $value)
 {
     cred_translate_register_string('cred-form-' . $this->_form_data['name'] . '-' . $this->_form_data['ID'], $name, $value, false);
 }
示例#3
0
 public static function localizeCommerceForm($data)
 {
     if (!isset($data['post'])) {
         return;
     }
     $model = CREDC_Loader::get('MODEL/Main');
     $form_id = $data['post']->ID;
     $form = $model->getForm($form_id, false);
     if ($form->isCommerce) {
         // localise messages
         if (isset($form->commerce['messages']) && isset($form->commerce['messages']['checkout'])) {
             cred_translate_register_string('cred-form-' . $form_id, 'cred_commerce_checkout_message', $form->commerce['messages']['checkout'], false);
         }
         if (isset($form->commerce['messages']) && isset($form->commerce['messages']['thankyou'])) {
             cred_translate_register_string('cred-form-' . $form_id, 'cred_commerce_thankyou_message', $form->commerce['messages']['thankyou'], false);
         }
     }
 }
 public function translate_field($name, &$field, $additional_options = array())
 {
     // allow multiple submit buttons
     static $_count_ = array('submit' => 0);
     static $wpExtensions = false;
     // get refs here
     $globals =& self::friendGetStatic('CRED_Form_Builder', '&_staticGlobal');
     if (false === $wpExtensions) {
         $wpMimes = $globals['MIMES'];
         $wpExtensions = implode(',', array_keys($wpMimes));
     }
     // get refs here
     $form =& $this->friendGet($this->_formBuilder, '&_formData');
     $supported_date_formats =& $this->friendGet($this->_formBuilder, '&_supportedDateFormats');
     $out_ =& $this->friendGet($this->_formBuilder, '&out_');
     $postData =& $this->friendGet($this->_formBuilder, '&_postData');
     $zebraForm = $this->friendGet($this->_formBuilder, '_zebraForm');
     // extend additional_options with defaults
     extract(array_merge(array('preset_value' => null, 'placeholder' => null, 'value_escape' => false, 'make_readonly' => false, 'is_tax' => false, 'max_width' => null, 'max_height' => null, 'single_select' => false, 'generic_type' => null, 'urlparam' => ''), $additional_options));
     // add the "name" element
     // the "&" symbol is there so that $obj will be a reference to the object in PHP 4
     // for PHP 5+ there is no need for it
     $type = 'text';
     $attributes = array();
     $value = '';
     $name_orig = $name;
     if (!$is_tax) {
         // if not taxonomy field
         if ($placeholder && $placeholder !== null && !empty($placeholder) && is_string($placeholder)) {
             // use translated value by WPML if exists
             $placeholder = cred_translate('Value: ' . $placeholder, $placeholder, 'cred-form-' . $form->getForm()->post_title . '-' . $form->getForm()->ID);
         }
         if ($preset_value && null !== $preset_value && is_string($preset_value) && !empty($preset_value)) {
             // use translated value by WPML if exists
             $data_value = cred_translate('Value: ' . $preset_value, $preset_value, 'cred-form-' . $form->getForm()->post_title . '-' . $form->getForm()->ID);
         } elseif (is_string($urlparam) && !empty($urlparam) && isset($_GET[$urlparam])) {
             // use translated value by WPML if exists
             $data_value = urldecode($_GET[$urlparam]);
         } elseif ($postData && isset($postData->fields[$name_orig])) {
             if (is_array($postData->fields[$name_orig]) && count($postData->fields[$name_orig]) > 1) {
                 $data_value = $postData->fields[$name_orig];
             } else {
                 $data_value = $postData->fields[$name_orig][0];
             }
         } elseif ($_POST && isset($_POST) && isset($_POST[$name_orig])) {
             $data_value = $_POST[$name_orig];
         } else {
             $data_value = null;
         }
         $value = '';
         // save a map between options / actual values for these types to be used later
         if (in_array($field['type'], array('checkboxes', 'radio', 'select', 'multiselect'))) {
             //cred_log($field);
             $tmp = array();
             foreach ($field['data']['options'] as $optionKey => $optionData) {
                 //https://onthegosystems.myjetbrains.com/youtrack/issue/cred-113
                 //added !==
                 if ($optionKey !== 'default' && is_array($optionData)) {
                     $tmp[$optionKey] = isset($optionData['set_value']) && 'checkboxes' == $field['type'] ? $optionData['set_value'] : isset($optionData['value']) ? $optionData['value'] : "";
                 }
             }
             $out_['field_values_map'][$field['slug']] = $tmp;
             unset($tmp);
             unset($optionKey);
             unset($optionData);
         }
         switch ($field['type']) {
             case 'form_messages':
                 $type = 'messages';
                 break;
             case 'form_submit':
                 $type = 'submit';
                 if (null !== $data_value) {
                     $value = $data_value;
                 }
                 // allow multiple submit buttons
                 $name .= '_' . ++$_count_['submit'];
                 break;
             case 'recaptcha':
                 $type = 'recaptcha';
                 $value = '';
                 $attributes = array('error_message' => $this->getLocalisedMessage('enter_valid_captcha'), 'show_link' => $this->getLocalisedMessage('show_captcha'), 'no_keys' => __('Enter your ReCaptcha keys at the CRED Settings page in order for ReCaptcha API to work', 'wp-cred'));
                 if (false !== $globals['RECAPTCHA']) {
                     $attributes['public_key'] = $globals['RECAPTCHA']['public_key'];
                     $attributes['private_key'] = $globals['RECAPTCHA']['private_key'];
                 }
                 if (1 == $out_['count']) {
                     $attributes['open'] = true;
                 }
                 // used to load additional js script
                 $out_['has_recaptcha'] = true;
                 break;
             case 'audio':
             case 'video':
             case 'file':
                 $type = 'file';
                 if ($data_value !== null) {
                     $value = $data_value;
                 }
                 break;
             case 'image':
                 $type = 'file';
                 if ($data_value !== null) {
                     $value = $data_value;
                 }
                 // show previous post featured image thumbnail
                 if ('_featured_image' == $name) {
                     $value = '';
                     if (isset($postData->extra['featured_img_html'])) {
                         $attributes['display_featured_html'] = $value = $postData->extra['featured_img_html'];
                     }
                 }
                 break;
             case 'date':
                 $type = 'date';
                 $format = $zebraForm->getDateFormat();
                 $format .= " h:i:s";
                 $value = array();
                 $attributes['format'] = $format;
                 $attributes['readonly_element'] = false;
                 if (null !== $data_value && !empty($data_value) && (is_numeric($data_value) || is_int($data_value) || is_long($data_value))) {
                     //$value = $data_value;
                     $value['timestamp'] = $data_value;
                     $value['datepicker'] = adodb_date($format, $data_value);
                 }
                 break;
             case 'multiselect':
             case 'select':
                 $type = 'select';
                 $value = array();
                 $attributes = array();
                 $attributes['options'] = array();
                 $titles = array();
                 $default = array();
                 foreach ($field['data']['options'] as $key => $option) {
                     $index = $key;
                     //$option['value'];
                     //https://onthegosystems.myjetbrains.com/youtrack/issue/cred-113
                     //added !==
                     if ('default' === $key) {
                         if ('select' == $field['type']) {
                             $default[] = $option;
                         } else {
                             $default = (array) $option;
                         }
                     } else {
                         if (is_admin()) {
                             //register strings on form save
                             cred_translate_register_string('cred-form-' . $form->getForm()->post_title . '-' . $form->getForm()->ID, $option['title'], $option['title'], false);
                         }
                         $option = $this->translate_option($option, $key, $form, $field);
                         $attributes['options'][$index] = $option['title'];
                         if (null !== $data_value && $data_value == $option['value'] || is_array($data_value) && in_array($option['value'], $data_value)) {
                             if ('select' == $field['type']) {
                                 $titles[] = $key;
                                 $value = $key;
                             } else {
                                 $value[] = $key;
                             }
                         }
                         if (isset($option['dummy']) && $option['dummy']) {
                             $attributes['dummy'] = $key;
                         }
                     }
                 }
                 if ('select' == $field['type']) {
                     if (empty($titles) && !empty($default)) {
                         $titles = $default;
                     }
                     $attributes['actual_value'] = $titles;
                 } else {
                     $attributes['multiple'] = 'multiple';
                     if (empty($value) && !empty($default)) {
                         $value = $default;
                     }
                 }
                 if (isset($out_['field_values_map'][$field['slug']])) {
                     $attributes['actual_options'] = $out_['field_values_map'][$field['slug']];
                 }
                 break;
             case 'radio':
                 $type = 'radios';
                 $value = array();
                 $titles = array();
                 $attributes = '';
                 $default = '';
                 foreach ($field['data']['options'] as $key => $option) {
                     $index = $key;
                     //$option['display_value'];
                     if ('default' == $key) {
                         $default = $option;
                     } else {
                         if (is_admin()) {
                             //register strings on form save
                             cred_translate_register_string('cred-form-' . $form->getForm()->post_title . '-' . $form->getForm()->ID, $option['title'], $option['title'], false);
                         }
                         $option = $this->translate_option($option, $key, $form, $field);
                         $titles[$index] = $option['title'];
                         if ($data_value !== null && $data_value == $option['value']) {
                             $attributes = $key;
                             $value = $key;
                         }
                     }
                 }
                 if ($data_value === null && !empty($default)) {
                     $attributes = $default;
                 }
                 $def = $attributes;
                 $attributes = array('default' => $def);
                 $attributes['actual_titles'] = $titles;
                 if (isset($out_['field_values_map'][$field['slug']])) {
                     $attributes['actual_values'] = $out_['field_values_map'][$field['slug']];
                 }
                 break;
             case 'checkboxes':
                 $type = 'checkboxes';
                 //$name.='[]';
                 //$value=array();
                 $value = array();
                 //Fixed https://onthegosystems.myjetbrains.com/youtrack/issue/cred-211
                 if (isset($data_value) && !empty($data_value)) {
                     foreach ($data_value as $v => $v1) {
                         $value[$v] = 1;
                     }
                 }
                 $titles = array();
                 $attributes = array();
                 /* if (is_array($data_value))
                    $data_value=array_keys($data_value);
                    else */
                 if (!is_array($data_value) && null !== $data_value) {
                     $data_value = array($data_value);
                 }
                 foreach ($field['data']['options'] as $key => $option) {
                     if (is_admin()) {
                         //register strings on form save
                         cred_translate_register_string('cred-form-' . $form->getForm()->post_title . '-' . $form->getForm()->ID, $option['title'], $option['title'], false);
                     }
                     $option['title'] = cred_translate($option['title'], $option['title'], 'cred-form-' . $form->getForm()->post_title . '-' . $form->getForm()->ID);
                     $index = $key;
                     $titles[$index] = $option['title'];
                     if (empty($value)) {
                         if (isset($data_value) && !empty($data_value) && isset($data_value[$index])) {
                             $value[$index] = $data_value[$index];
                         } else {
                             $value[$index] = 0;
                         }
                     }
                     if (isset($option['checked']) && $option['checked'] && null === $data_value) {
                         $attributes[] = $index;
                     } elseif (null !== $data_value && isset($data_value[$index])) {
                         if (!('yes' == $field['data']['save_empty'] && (0 === $data_value[$index] || '0' === $data_value[$index]))) {
                             $attributes[] = $index;
                         }
                     }
                 }
                 $def = $attributes;
                 $attributes = array('default' => $def);
                 $attributes['actual_titles'] = $titles;
                 if (isset($out_['field_values_map'][$field['slug']])) {
                     $attributes['actual_values'] = $out_['field_values_map'][$field['slug']];
                 }
                 break;
             case 'checkbox':
                 $type = 'checkbox';
                 $value = $field['data']['set_value'];
                 if (null !== $data_value && $data_value == $value) {
                     $attributes = array('checked' => 'checked');
                 }
                 break;
             case 'textarea':
                 $type = 'textarea';
                 if (null !== $data_value) {
                     $value = $data_value;
                 }
                 if ($placeholder && null !== $placeholder && !empty($placeholder)) {
                     $attributes['placeholder'] = $placeholder;
                 }
                 break;
             case 'wysiwyg':
                 $type = 'wysiwyg';
                 if (null !== $data_value) {
                     $value = $data_value;
                 }
                 $attributes = array('disable_xss_filters' => true);
                 //cred_log($form->fields);
                 if ('post_content' == $name && isset($form->fields['form_settings']->form['has_media_button']) && $form->fields['form_settings']->form['has_media_button']) {
                     $attributes['has_media_button'] = true;
                 }
                 break;
             case 'numeric':
                 $type = 'numeric';
                 if (null !== $data_value) {
                     $value = $data_value;
                 }
                 break;
             case 'phone':
                 $type = 'phone';
                 if (null !== $data_value) {
                     $value = $data_value;
                 }
                 break;
             case 'embed':
             case 'url':
                 $type = 'url';
                 if (null !== $data_value) {
                     $value = $data_value;
                 }
                 break;
             case 'email':
                 $type = 'email';
                 if (null !== $data_value) {
                     $value = $data_value;
                 }
                 break;
             case 'colorpicker':
                 $type = 'colorpicker';
                 if (null !== $data_value) {
                     $value = $data_value;
                 }
                 break;
             case 'textfield':
                 $type = 'textfield';
                 if (null !== $data_value) {
                     $value = $data_value;
                 }
                 if ($placeholder && null !== $placeholder && !empty($placeholder)) {
                     $attributes['placeholder'] = $placeholder;
                 }
                 break;
             case 'password':
                 $type = 'password';
                 if (null !== $data_value) {
                     $value = $data_value;
                 }
                 if ($placeholder && null !== $placeholder && !empty($placeholder)) {
                     $attributes['placeholder'] = $placeholder;
                 }
                 break;
             case 'hidden':
                 $type = 'hidden';
                 if (null !== $data_value) {
                     $value = $data_value;
                 }
                 break;
             case 'skype':
                 $type = 'skype';
                 if (null !== $data_value && is_string($data_value)) {
                     $data_value = array('skypename' => $data_value, 'style' => '');
                 }
                 if (null !== $data_value) {
                     $value = $data_value;
                 } else {
                     $value = array('skypename' => '', 'style' => '');
                 }
                 $attributes = array('ajax_url' => admin_url('admin-ajax.php'), 'edit_skype_text' => $this->getLocalisedMessage('edit_skype_button'), 'value' => $data_value, '_nonce' => wp_create_nonce('insert_skype_button'));
                 break;
                 // everything else defaults to a simple text field
             // everything else defaults to a simple text field
             default:
                 $type = 'textfield';
                 if (null !== $data_value) {
                     $value = $data_value;
                 }
                 break;
         }
         if ($make_readonly) {
             if (!is_array($attributes)) {
                 $attributes = array();
             }
             $attributes['readonly'] = 'readonly';
         }
         // repetitive field (special care)
         if (isset($field['data']['repetitive']) && $field['data']['repetitive']) {
             $value = isset($postData->fields[$name_orig]) ? $postData->fields[$name_orig] : array();
             $objs = $zebraForm->noadd($type, $name, $value, $attributes, $field);
         } else {
             $objs = $zebraForm->noadd($type, $name, $value, $attributes, $field);
         }
     } else {
         // taxonomy field or auxilliary taxonomy field (eg popular terms etc..)
         if (!array_key_exists('master_taxonomy', $field)) {
             // taxonomy field
             if ($field['hierarchical']) {
                 if (in_array($preset_value, array('checkbox', 'select'))) {
                     $tax_display = $preset_value;
                 } else {
                     $tax_display = 'checkbox';
                 }
             }
             if ($postData && isset($postData->taxonomies[$name_orig])) {
                 if (!$field['hierarchical']) {
                     $data_value = array('terms' => $postData->taxonomies[$name_orig]['terms'], 'add_text' => $this->getLocalisedMessage('add_taxonomy'), 'remove_text' => $this->getLocalisedMessage('remove_taxonomy'), 'ajax_url' => admin_url('admin-ajax.php'), 'auto_suggest' => true, 'show_popular_text' => $this->getLocalisedMessage('show_popular'), 'hide_popular_text' => $this->getLocalisedMessage('hide_popular'));
                 } else {
                     $data_value = array('terms' => $postData->taxonomies[$name_orig]['terms'], 'all' => $field['all'], 'type' => $tax_display, 'single_select' => $single_select);
                 }
             } else {
                 if (!$field['hierarchical']) {
                     $data_value = array('add_text' => $this->getLocalisedMessage('add_taxonomy'), 'remove_text' => $this->getLocalisedMessage('remove_taxonomy'), 'ajax_url' => admin_url('admin-ajax.php'), 'auto_suggest' => true, 'show_popular_text' => $this->getLocalisedMessage('show_popular'), 'hide_popular_text' => $this->getLocalisedMessage('hide_popular'));
                 } else {
                     $data_value = array('all' => $field['all'], 'type' => $tax_display, 'single_select' => $single_select);
                 }
             }
             // if not hierarchical taxonomy
             if (!$field['hierarchical']) {
                 $objs = $zebraForm->add('taxonomy', $name, $value, $data_value);
             } else {
                 $objs = $zebraForm->add('taxonomyhierarchical', $name, $value, $data_value);
             }
             // register this taxonomy field for later use by auxilliary taxonomy fields
             $out_['taxonomy_map']['taxonomy'][$name_orig] =& $objs;
             // if a taxonomy auxiliary field exists attached to this taxonomy, add this taxonomy id to it
             if (isset($out_['taxonomy_map']['aux'][$name_orig])) {
                 $out_['taxonomy_map']['aux'][$name_orig]->set_attributes(array('master_taxonomy_id' => $objs->attributes['id']));
             }
         } else {
             // taxonomy auxilliary field (eg most popular etc..)
             if ($preset_value && null !== $preset_value) {
                 // use translated value by WPML if exists
                 $data_value = cred_translate('Value: ' . $preset_value, $preset_value, 'cred-form-' . $form->form->post_title . '-' . $form->form->ID);
             } else {
                 $data_value = null;
             }
         }
     }
     //$out_=&$this->friendGet($this->_formBuilder, '&out_');
     $count = $field['type'] == 'form_submit' ? '_' . $_count_['submit']++ : "";
     $f = "";
     if ($field['type'] == 'taxonomy_hierarchical' || $field['type'] == 'taxonomy_plain') {
         $f = "_" . $field['name'];
     } else {
         if (isset($field['master_taxonomy']) && isset($field['type'])) {
             $f = "_" . $field['master_taxonomy'] . "_" . $field['type'];
         } else {
             if (isset($field['id'])) {
                 $f = "_" . $field['id'];
             } else {
             }
         }
     }
     return array("cred_form_" . $out_['prg_id'] . $f . $count);
 }