public function metaform()
 {
     $attributes = $this->getAttr();
     $form = array();
     $markup = '';
     $wpml_action = $this->getWPMLAction();
     if (is_admin()) {
         $markup .= '<div class="form-item form-item-markup">';
         $extra_markup = '';
         if (defined('WPML_TM_VERSION') && intval($wpml_action) === 1 && function_exists('wpcf_wpml_post_is_original') && !wpcf_wpml_post_is_original() && function_exists('wpcf_wpml_have_original') && wpcf_wpml_have_original()) {
             $attributes['readonly'] = 'readonly';
             $extra_markup .= sprintf('<img src="%s/images/locked.png" alt="%s" title="%s" style="position:relative;left:2px;top:2px;" />', WPCF_EMBEDDED_RES_RELPATH, __('This field is locked for editing because WPML will copy its value from the original language.', 'wpcf'), __('This field is locked for editing because WPML will copy its value from the original language.', 'wpcf'));
         }
         $markup .= sprintf('<label class="wpt-form-label wpt-form-textfield-label">%1$s%2$s</label>', stripcslashes($this->getTitle()), $extra_markup);
     }
     if (is_admin()) {
         $markup .= '<div class="description wpt-form-description wpt-form-description-textfield description-textfield">' . stripcslashes($this->getDescription()) . '</div>';
     } else {
         $markup .= stripcslashes($this->getDescription());
     }
     $markup .= $this->_editor($attributes);
     if (is_admin()) {
         $markup .= '</div>';
     }
     $form[] = array('#type' => 'markup', '#markup' => $markup);
     return $form;
 }
Esempio n. 2
0
 public function metaform()
 {
     $value = wp_parse_args($this->getValue(), $this->_defaults);
     $attributes = $this->getAttr();
     $wpml_action = $this->getWPMLAction();
     if (isset($attributes['class'])) {
         $attributes['class'] .= ' ';
     } else {
         $attributes['class'] = '';
     }
     $attributes['class'] = 'js-wpt-skypename js-wpt-cond-trigger regular-text';
     // What is this js-wpt-cond-trigger classname for?
     $form = array();
     $form[] = array('#type' => 'textfield', '#title' => $this->getTitle(), '#description' => $this->getDescription(), '#name' => $this->getName() . "[skypename]", '#attributes' => array(), '#value' => $value['skypename'], '#validate' => $this->getValidationData(), '#attributes' => $attributes, '#repetitive' => $this->isRepetitive(), 'wpml_action' => $wpml_action);
     /**
      * action
      */
     $form[] = array('#type' => 'hidden', '#value' => $value['action'], '#name' => $this->getName() . '[action]', '#attributes' => array('class' => 'js-wpt-skype-action'));
     /**
      * color
      */
     $form[] = array('#type' => 'hidden', '#value' => $value['color'], '#name' => $this->getName() . '[color]', '#attributes' => array('class' => 'js-wpt-skype-color'));
     /**
      * size
      */
     $form[] = array('#type' => 'hidden', '#value' => $value['size'], '#name' => $this->getName() . '[size]', '#attributes' => array('class' => 'js-wpt-skype-size'));
     if (!is_admin()) {
         return $form;
     }
     $button_element = array('#name' => '', '#type' => 'button', '#value' => esc_attr(__('Edit Skype', 'wpv-views')), '#attributes' => array('class' => 'js-wpt-skype-edit-button button button-small button-secondary'));
     if (is_admin() && defined('WPML_TM_VERSION') && intval($wpml_action) === 1 && function_exists('wpcf_wpml_post_is_original') && !wpcf_wpml_post_is_original() && function_exists('wpcf_wpml_have_original') && wpcf_wpml_have_original()) {
         $button_element['#attributes']['disabled'] = 'disabled';
     }
     foreach ($value as $key => $val) {
         $button_element['#attributes']['data-' . esc_attr($key)] = $val;
     }
     $form[] = $button_element;
     return $form;
 }
Esempio n. 3
0
/**
 * Checks if field is copied on post edit screen.
 *
 * @global type $sitepress
 * @param type $field
 * @param type $post
 * @return boolean
 */
function wpcf_wpml_field_is_copied($field, $post = null)
{
    if (defined('ICL_SITEPRESS_VERSION') && defined('WPML_TM_VERSION') && !defined('DOING_AJAX')) {
        if (!wpcf_wpml_post_is_original($post)) {
            return wpcf_wpml_have_original($post) && wpcf_wpml_field_is_copy($field);
        }
    }
    return false;
}
Esempio n. 4
0
 /**
  *
  * @global object $wpdb
  *
  */
 public function metaform()
 {
     $value = $this->getValue();
     $type = $this->getType();
     $translated_type = '';
     $form = array();
     $preview = '';
     $wpml_action = $this->getWPMLAction();
     // Get attachment by guid
     if (!empty($value)) {
         global $wpdb;
         $attachment_id = $wpdb->get_var($wpdb->prepare("SELECT ID FROM {$wpdb->posts} WHERE post_type = 'attachment' AND guid=%s", $value));
     }
     // Set preview
     if (!empty($attachment_id)) {
         $attributes = array();
         $full = wp_get_attachment_image_src($attachment_id, 'full');
         if (!empty($full)) {
             $attributes['data-full-src'] = esc_attr($full[0]);
         }
         $preview = wp_get_attachment_image($attachment_id, 'thumbnail', false, $attributes);
     } else {
         // If external image set preview
         $file_path = parse_url($value);
         if ($file_path && isset($file_path['path'])) {
             $file = pathinfo($file_path['path']);
         } else {
             $file = pathinfo($value);
         }
         if (isset($file['extension']) && in_array(strtolower($file['extension']), array('jpg', 'jpeg', 'gif', 'png'))) {
             $preview = '<img alt="" src="' . $value . '" />';
         }
     }
     // Set button
     switch ($type) {
         case 'audio':
             $translated_type = __('audio', 'wpv-views');
             break;
         case 'image':
             $translated_type = __('image', 'wpv-views');
             break;
         case 'video':
             $translated_type = __('video', 'wpv-views');
             break;
         default:
             $translated_type = __('file', 'wpv-views');
             break;
     }
     $button_status = '';
     if (is_admin() && defined('WPML_TM_VERSION') && intval($wpml_action) === 1 && function_exists('wpcf_wpml_post_is_original') && !wpcf_wpml_post_is_original() && function_exists('wpcf_wpml_have_original') && wpcf_wpml_have_original()) {
         $button_status = ' disabled="disabled"';
     }
     $button = sprintf('<button class="js-wpt-file-upload button button-secondary" data-wpt-type="%s"%s>%s</button>', $type, $button_status, sprintf(__('Select %s', 'wpv-views'), $translated_type));
     // Set form
     $form[] = array('#type' => 'textfield', '#name' => $this->getName(), '#title' => $this->getTitle(), '#description' => $this->getDescription(), '#value' => $value, '#suffix' => '&nbsp;' . $button, '#validate' => $this->getValidationData(), '#repetitive' => $this->isRepetitive(), '#attributes' => $this->getAttr(), 'wpml_action' => $wpml_action);
     $form[] = array('#type' => 'markup', '#markup' => '<div class="js-wpt-file-preview wpt-file-preview">' . $preview . '</div>');
     return $form;
 }
 public function metaform()
 {
     $time_value = $this->getValue();
     $datepicker = $hour = $minute = null;
     $timestamp = null;
     $readonly = false;
     $wpml_action = $this->getWPMLAction();
     if (is_admin()) {
         if (is_array($time_value) && array_key_exists('timestamp', $time_value) && $time_value) {
             $timestamp = $time_value['timestamp'];
         }
         $datepicker = self::timetodate($timestamp);
         $hour = self::timetodate($timestamp, 'H');
         $minute = self::timetodate($timestamp, 'i');
     } else {
         // We are on a CRED form, on frontend, so getVAlue returns nothing or a string or an array of the kind array( 'datepicker' =>, 'hour' =>, 'minute' => )
         // Note that even if the array is passed, 'hour' and 'minute' will only be passed if there are any
         if (!empty($time_value)) {
             if (is_array($time_value)) {
                 if (isset($time_value['timestamp']) && is_numeric($time_value['timestamp']) && self::_isTimestampInRange($time_value['timestamp'])) {
                     $timestamp = $time_value['timestamp'];
                     $datepicker = self::timetodate($timestamp);
                 } elseif (isset($time_value['datepicker']) && $time_value['datepicker'] !== false && is_numeric($time_value['datepicker']) && self::_isTimestampInRange($time_value['datepicker'])) {
                     $timestamp = $time_value['datepicker'];
                     $datepicker = self::timetodate($timestamp);
                 }
                 $hour = self::timetodate($timestamp, 'H');
                 if (isset($time_value['hour']) && is_numeric($time_value['hour'])) {
                     $hour = $time_value['hour'];
                 }
                 $minute = self::timetodate($timestamp, 'i');
                 if (isset($time_value['minute']) && is_numeric($time_value['minute'])) {
                     $minute = $time_value['minute'];
                 }
             } else {
                 if (is_numeric($time_value) && self::_isTimestampInRange($time_value)) {
                     $timestamp = $time_value;
                     $datepicker = self::timetodate($timestamp);
                 } else {
                     $timestamp = self::strtotime($time_value);
                     $datepicker = $time_value;
                 }
                 $hour = self::timetodate($timestamp, 'H');
                 $minute = self::timetodate($timestamp, 'i');
             }
         }
     }
     $data = $this->getData();
     $field_disable = false;
     $def_class_aux = 'js-wpt-date-auxiliar';
     if (is_admin() && defined('WPML_TM_VERSION') && intval($wpml_action) === 1 && function_exists('wpcf_wpml_post_is_original') && !wpcf_wpml_post_is_original() && function_exists('wpcf_wpml_have_original') && wpcf_wpml_have_original()) {
         $field_disable = true;
         // this will stop js validation of date field value (as it will get duplicated)
         $def_class_aux = '';
     }
     if (!$timestamp) {
         // If there is no timestamp, we need to make it an empty string
         // A false value would render the hidden field with a value of 1
         $timestamp = '';
         $datepicker = null;
     }
     $def_class = 'js-wpt-date';
     if ($field_disable || isset($data['attribute']) && isset($data['attribute']['readonly']) && $data['attribute']['readonly'] == 'readonly') {
         $def_class .= ' js-wpv-date-readonly';
         $def_class_aux .= ' js-wpt-date-readonly';
         $readonly = true;
     }
     $form = array();
     $validate = $this->getValidationData();
     $title = $this->getTitle();
     if (isset($validate['required']) && !empty($title)) {
         // Asterisk
         $title .= '&#42;';
     }
     $attr_visible = array('class' => $def_class, 'style' => 'display:inline;width:150px;position:relative;', 'readonly' => 'readonly', 'title' => esc_attr(__('Select', 'wpv-views')) . " Date");
     $attr_hidden = array('class' => $def_class_aux, 'data-ts' => $timestamp, 'data-wpt-type' => 'date');
     if (isset($data['attribute']) && isset($data['attribute']['placeholder'])) {
         $attr_visible['placeholder'] = $data['attribute']['placeholder'];
     }
     $form[] = array('#type' => 'textfield', '#title' => $title, '#description' => $this->getDescription(), '#attributes' => $attr_visible, '#name' => $this->getName() . '[display-only]', '#value' => $datepicker, '#inline' => true, 'wpml_action' => $wpml_action);
     $form[] = array('#type' => 'hidden', '#title' => $title, '#attributes' => $attr_hidden, '#name' => $this->getName() . '[datepicker]', '#value' => $timestamp, '#validate' => $validate, '#repetitive' => $this->isRepetitive());
     /*
      // This was the old implementaton
      // We have implemented the above one because we need a hidden field to hold the timestamp
      // And the visible text input field to display the date string to the user
      $form[] = array(
      '#type' => 'textfield',
      '#title' => $this->getTitle(),
      '#attributes' => array('class' => $def_class, 'style' => 'width:150px;'),
      '#name' => $this->getName() . '[datepicker]',
      '#value' => $timestamp,
      '#validate' => $this->getValidationData(),
      '#repetitive' => $this->isRepetitive(),
      );
     */
     if (!empty($data['add_time'])) {
         // Shared attributes
         $attributes_hour_minute = array();
         if ($readonly) {
             $attributes_hour_minute['disabled'] = 'disabled';
         }
         if (array_key_exists('use_bootstrap', $this->_data) && $this->_data['use_bootstrap']) {
             $attributes_hour_minute['style'] = 'display:inline;width:auto;';
         }
         // Hour
         $hours = 24;
         $options = array();
         for ($index = 0; $index < $hours; $index++) {
             $prefix = $index < 10 ? '0' : '';
             $options[$index] = array('#title' => $prefix . strval($index), '#value' => $index);
         }
         if ($readonly) {
             $form[] = array('#type' => 'hidden', '#value' => $hour, '#name' => $this->getName() . '[hour]', '#inline' => true);
             $hour_element = array('#type' => 'select', '#before' => '<span class="wpt-form-label">' . __('Hour', 'wpv-views') . '</span>', '#options' => $options, '#default_value' => $hour, '#name' => '_' . $this->getName() . '[hour]', '#inline' => true, '#attributes' => array('title' => esc_attr(__('Select', 'wpv-views')) . " Date"));
         } else {
             $hour_element = array('#type' => 'select', '#before' => '<span class="wpt-form-label">' . __('Hour', 'wpv-views') . '</span>', '#options' => $options, '#default_value' => $hour, '#name' => $this->getName() . '[hour]', '#inline' => true, '#attributes' => array('title' => esc_attr(__('Select', 'wpv-views')) . " Date"));
         }
         if (!empty($attributes_hour_minute)) {
             $hour_element['#attributes'] = $attributes_hour_minute;
         }
         $form[] = $hour_element;
         // Minutes
         $minutes = 60;
         $options = array();
         for ($index = 0; $index < $minutes; $index++) {
             $prefix = $index < 10 ? '0' : '';
             $options[$index] = array('#title' => $prefix . strval($index), '#value' => $index);
         }
         if ($readonly) {
             $form[] = array('#type' => 'hidden', '#value' => $minute, '#name' => $this->getName() . '[minute]', '#inline' => true);
             $minute_element = array('#type' => 'select', '#before' => '<span class="wpt-form-label">' . __('Minute', 'wpv-views') . '</span>', '#options' => $options, '#default_value' => $minute, '#name' => '_' . $this->getName() . '[minute]', '#inline' => true, '#attributes' => array('title' => esc_attr(__('Select minute', 'wpv-views'))));
         } else {
             $minute_element = array('#type' => 'select', '#before' => '<span class="wpt-form-label">' . __('Minute', 'wpv-views') . '</span>', '#options' => $options, '#default_value' => $minute, '#name' => $this->getName() . '[minute]', '#inline' => true, '#attributes' => array('title' => esc_attr(__('Select minute', 'wpv-views'))));
         }
         if (!empty($attributes_hour_minute)) {
             $minute_element['#attributes'] = $attributes_hour_minute;
         }
         $form[] = $minute_element;
     }
     $form[] = array('#type' => 'markup', '#inline' => true, '#markup' => sprintf('<input type="button" class="button button-secondary js-wpt-date-clear wpt-date-clear" value="%s" %s/>', esc_attr(__('Clear', 'wpv-views')) . " Date", empty($time_value) || !isset($time_value['timestamp']) || isset($time_value['timestamp']) && empty($time_value['timestamp']) || $readonly ? 'style="display:none" ' : ''));
     return $form;
 }