コード例 #1
0
 /**
  * Renders module data
  *
  * @access public
  * @param string $slug
  * @param array $optionst
  * @param array $values
  * @return void
  */
 public static function renderData($slug, $options = array(), $values = array())
 {
     $options = wp_parse_args($options, array('edit' => true, 'placeholder' => true, 'before_title' => '', 'after_title' => '', 'before_content' => '', 'after_content' => ''));
     $out = '';
     $counter = 0;
     if (self::isActive($slug)) {
         foreach (self::$data[$slug]['fields'] as $field) {
             if (!empty($field['name'])) {
                 $ID = themex_sanitize_key($field['name']);
                 $counter++;
                 if ($options['edit']) {
                     if (!empty($options['before_title']) || !empty($options['after_title'])) {
                         $out .= $options['before_title'] . $field['name'] . $options['after_title'];
                     }
                     if (!empty($options['before_content'])) {
                         $out .= $options['before_content'];
                     }
                     $args = array('id' => $ID, 'type' => $field['type'], 'value' => themex_array($ID, $values), 'wrap' => false);
                     if ($field['type'] == 'select') {
                         $args['options'] = array_merge(array('0' => '–'), explode(',', $field['options']));
                         $out .= '<div class="element-select"><span></span>';
                     } else {
                         if ($options['placeholder']) {
                             $args['attributes'] = array('placeholder' => $field['name']);
                         }
                         $out .= '<div class="field-wrap">';
                     }
                     $out .= ThemexInterface::renderOption($args);
                     $out .= '</div>';
                     if (!empty($options['after_content'])) {
                         $out .= $options['after_content'];
                     }
                 } else {
                     if (isset($values[$ID])) {
                         $out .= $options['before_title'] . $field['name'] . $options['after_title'] . $options['before_content'];
                         if ($field['type'] == 'select') {
                             $items = array_merge(array('0' => '&ndash;'), explode(',', $field['options']));
                             if (isset($items[$values[$ID]])) {
                                 $values[$ID] = $items[$values[$ID]];
                             }
                         }
                         if (empty($values[$ID])) {
                             $values[$ID] = '&ndash;';
                         }
                         $out .= $values[$ID];
                         $out .= $options['after_content'];
                     }
                 }
             }
         }
     }
     echo $out;
 }
コード例 #2
0
 /**
  * Renders page sections
  *
  * @access public
  * @return void
  */
 public static function renderSections()
 {
     $first = true;
     $out = '';
     foreach (ThemexCore::$options as $option) {
         if ($option['type'] == 'section') {
             if ($first) {
                 $first = false;
             } else {
                 $out .= '</div>';
             }
             $out .= '<div class="themex-section" id="' . themex_sanitize_key($option['name']) . '"><h2>' . $option['name'] . '</h2>';
         } else {
             $option['id'] = THEMEX_PREFIX . $option['id'];
             $out .= self::renderOption($option);
         }
     }
     $out .= '</div>';
     echo $out;
 }
コード例 #3
0
 /**
  * Updates user profile
  *
  * @access public
  * @param int $ID
  * @param array $data
  * @return void
  */
 public static function updateProfile($ID, $data)
 {
     $fields = array(array('name' => 'signature', 'type' => 'text'), array('name' => 'facebook', 'type' => 'text'), array('name' => 'twitter', 'type' => 'text'), array('name' => 'google', 'type' => 'text'), array('name' => 'tumblr', 'type' => 'text'), array('name' => 'linkedin', 'type' => 'text'), array('name' => 'flickr', 'type' => 'text'), array('name' => 'youtube', 'type' => 'text'), array('name' => 'vimeo', 'type' => 'text'));
     if (ThemexForm::isActive('profile')) {
         $fields = array_merge($fields, ThemexForm::$data['profile']['fields']);
     }
     foreach ($fields as $field) {
         $name = themex_sanitize_key($field['name']);
         if (isset($data[$name])) {
             if ($field['type'] == 'number') {
                 $data[$name] = intval($data[$name]);
             } else {
                 if ($field['type'] == 'name') {
                     $data[$name] = ucwords(strtolower($data[$name]));
                 } else {
                     $data[$name] = sanitize_text_field($data[$name]);
                 }
             }
             ThemexCore::updateUserMeta($ID, $name, $data[$name]);
         }
     }
     //first name
     if (isset($data['first_name'])) {
         update_user_meta($ID, 'first_name', sanitize_text_field($data['first_name']));
     }
     //last name
     if (isset($data['last_name'])) {
         update_user_meta($ID, 'last_name', sanitize_text_field($data['last_name']));
     }
     //description
     if (isset($data['description'])) {
         $data['description'] = wp_kses($data['description'], array('strong' => array(), 'em' => array(), 'a' => array('href' => array(), 'title' => array(), 'target' => array()), 'p' => array(), 'br' => array()));
         update_user_meta($ID, 'description', $data['description']);
     }
     if (empty(ThemexInterface::$messages)) {
         ThemexInterface::$messages[] = __('Profile has been successfully saved', 'academy');
         $_POST['success'] = true;
     }
 }
コード例 #4
0
ファイル: themex.form.php プロジェクト: haythameyd/powrly
 /**
  * Submits form data
  *
  * @access public
  * @return void
  */
 public static function submitData()
 {
     self::refresh();
     parse_str($_POST['data'], $data);
     if (isset($data['slug']) && self::isActive($data['slug'])) {
         if (isset(self::$data[$data['slug']]['captcha'])) {
             session_start();
             $posted_code = md5($data['captcha']);
             $session_code = $_SESSION['captcha'];
             if ($session_code != $posted_code) {
                 ThemexInterface::$messages[] = __('The verification code is incorrect', 'academy');
             }
         }
         foreach (self::$data[$data['slug']]['fields'] as $field) {
             $ID = themex_sanitize_key($field['name']);
             $field['name'] = themex_get_string($ID, 'name', $field['name']);
             if ((!isset($data[$ID]) || trim($data[$ID]) == '') && !isset($field['optional']) && $field['type'] != 'checkbox') {
                 ThemexInterface::$messages[] = '"' . $field['name'] . '" ' . __('field is required', 'academy');
             } else {
                 if ($field['type'] == 'number' && !is_numeric($data[$ID])) {
                     ThemexInterface::$messages[] = '"' . $field['name'] . '" ' . __('field can only contain numbers', 'academy');
                 }
                 if ($field['type'] == 'email' && !is_email($data[$ID])) {
                     ThemexInterface::$messages[] = __('You have entered an invalid email address', 'academy');
                 }
             }
         }
         if (!empty(ThemexInterface::$messages)) {
             ThemexInterface::renderMessages();
         } else {
             $email = get_option('admin_email');
             $subject = __('Contact', 'academy');
             $message = '';
             foreach (self::$data[$data['slug']]['fields'] as $field) {
                 $ID = themex_sanitize_key($field['name']);
                 $field['name'] = themex_get_string($ID, 'name', $field['name']);
                 if ($field['type'] == 'select') {
                     $field['options'] = themex_get_string($ID, 'options', $field['options']);
                     $items = explode(',', $field['options']);
                     if (isset($items[$data[$ID] - 1])) {
                         $data[$ID] = $items[$data[$ID] - 1];
                     } else {
                         $data[$ID] = '&ndash;';
                     }
                 } else {
                     if ($field['type'] == 'textarea') {
                         $data[$ID] = nl2br($data[$ID]);
                     }
                 }
                 $message .= '<strong>' . $field['name'] . '</strong>: ' . $data[$ID] . '<br />';
             }
             if (themex_mail($email, $subject, $message) && isset(self::$data[$data['slug']]['message'])) {
                 $message = themex_get_string($data['slug'], 'message', self::$data[$data['slug']]['message']);
                 ThemexInterface::$messages[] = $message;
             }
             ThemexInterface::renderMessages(true);
         }
     }
     die;
 }
コード例 #5
0
 /**
  * Updates user profile
  *
  * @access public
  * @param int $ID
  * @param array $data
  * @return void
  */
 public static function updateProfile($ID, $data)
 {
     $shop = self::getShop($ID);
     if (!empty($shop)) {
         if (isset($data['billing_country'])) {
             $country = trim(sanitize_text_field($data['billing_country']));
             ThemexCore::updatePostMeta($shop, 'country', $country);
         }
         if (isset($data['billing_city'])) {
             $city = trim(sanitize_text_field($data['billing_city']));
             $city = ucwords(strtolower($city));
             ThemexCore::updatePostMeta($shop, 'city', $city);
         }
     }
     foreach (ThemexCore::$components['forms'] as $form => $fields) {
         if ($form == 'profile' && ThemexForm::isActive('profile')) {
             $customs = ThemexForm::$data['profile']['fields'];
             foreach ($customs as &$custom) {
                 $custom['name'] = themex_sanitize_key($custom['name']);
             }
             $fields = array_merge($fields, $customs);
         }
         foreach ($fields as $field) {
             if (isset($field['name']) && isset($data[$field['name']])) {
                 $name = $field['name'];
                 $alias = themex_value('alias', $field);
                 $type = themex_value('type', $field);
                 $value = $data[$name];
                 if ($type == 'text') {
                     $value = trim(sanitize_text_field($value));
                 } else {
                     if ($type == 'number') {
                         $value = intval($value);
                     }
                 }
                 if ($name == 'billing_city') {
                     $value = ucwords(strtolower($value));
                 }
                 if (isset($field['required']) && $field['required'] && ($value == '' || $type == 'select' && $value == '0')) {
                     ThemexInterface::$messages[] = '"' . $field['label'] . '" ' . __('field is required', 'makery');
                 } else {
                     if (!isset($field['prefix']) || $field['prefix']) {
                         ThemexCore::updateUserMeta($ID, $name, $value);
                     } else {
                         update_user_meta($ID, $name, $value);
                         if (!empty($alias)) {
                             update_user_meta($ID, $alias, $value);
                         }
                     }
                 }
             }
         }
     }
     if (isset($data['description'])) {
         $data['description'] = trim($data['description']);
         $data['description'] = wp_kses($data['description'], array('strong' => array(), 'em' => array(), 'a' => array('href' => array(), 'title' => array(), 'target' => array()), 'p' => array(), 'br' => array()));
         update_user_meta($ID, 'description', $data['description']);
     }
     if (empty(ThemexInterface::$messages)) {
         ThemexInterface::$messages[] = __('Profile has been successfully saved', 'makery');
         $_POST['success'] = true;
     }
 }
コード例 #6
0
function themex_tabs_panes($atts, $content = null)
{
    extract(shortcode_atts(array('title' => ''), $atts));
    $out = '<div class="pane" id="' . themex_sanitize_key($title) . '-tab">' . do_shortcode($content) . '</div>';
    return $out;
}