function synved_option_render_item($id, $name, $item = null, $render = false, $params = null, $context = null) { if ($item == null) { $item = synved_option_item($id, $name); } if ($item == null) { return null; } $value = synved_option_get($id, $name); $type = synved_option_item_type($item); $style = synved_option_item_style($item); $label = synved_option_item_label($item); $tip = synved_option_item_tip($item); $hint = synved_option_item_hint($item); $default = synved_option_item_default($item); $set = synved_option_item_set($item); $set_is_linear = false; if ($set != null) { $set_is_linear = true; foreach ($set as $set_it) { if (count($set_it) > 1) { $set_is_linear = false; break; } } } $out_name = synved_option_render_field_name($id, $name); $out_id = synved_option_render_field_id($id, $name); $out = null; if (isset($params['output_name'])) { $out_name = $params['output_name']; } if (isset($params['output_id'])) { $out_id = $params['output_id']; } if (isset($params['tip'])) { $tip = $params['tip']; } if (isset($params['default'])) { $default = $params['default']; } if (isset($params['value'])) { $value = $params['value']; } $new_value = $value; $error_list = synved_option_item_validate_value($id, $name, $value, $new_value, $item); if ($new_value != $value && ($context == null || $context == 'settings')) { synved_option_set($id, $name, $new_value); $value = synved_option_get($id, $name); } if ($error_list != null) { foreach ($error_list as $error) { $out .= '<div id="message" class="error"><p>For "<i>' . $label . '</i>": ' . $error['message'] . '</p></div>'; } } if ($set_is_linear) { $out .= '<select name="' . $out_name . '" id="' . $out_id . '">'; // XXX exception...remove at some point if (isset($params['set_before'])) { $set_before = $params['set_before']; $set = array_merge($set_before, $set); } foreach ($set as $set_it) { $set_it_keys = array_keys($set_it); $selected = $set_it_keys[0] == $value ? ' selected="selected"' : null; $out .= '<option value="' . $set_it_keys[0] . '"' . $selected . '>' . $set_it[$set_it_keys[0]] . '</option>'; } $out .= '</select>'; } else { $placeholder = null; if ($hint != null) { $placeholder = ' placeholder="' . esc_attr($hint) . '"'; } switch ($type) { case 'boolean': $checked = $value == true ? ' checked="checked"' : null; $out .= '<fieldset><legend class="screen-reader-text"><span>' . $label . '</span></legend><label for="' . $out_id . '"><input type="hidden" name="' . $out_name . '" value="0" /><input name="' . $out_name . '" id="' . $out_id . '" type="checkbox" value="1" class="code" ' . $checked . $placeholder . ' /> ' . $label . '</label> <span class="description" style="vertical-align:middle;">' . $tip . '</span></fieldset>'; break; case 'text': case 'style': case 'script': case 'image': case 'video': case 'media': $atts = array('name' => $out_name, 'type' => 'text', 'id' => $out_id, 'value' => $value, 'class' => 'regular-text'); $att_style = array(); $content = null; $tag = 'input'; $extended = false; if ($style != null) { if (in_array('wide', $style)) { $atts['class'] = 'wide-text'; } if (in_array('extend', $style)) { $extended = true; } } if (in_array($type, array('style', 'script'))) { $extended = true; $att_style['width'] = '450px'; $att_style['height'] = '250px'; } if ($extended) { $tag = 'textarea'; if (isset($atts['value'])) { $content = $atts['value']; unset($atts['value']); } if ($content == null) { $content = ''; } unset($atts['type']); } if ($hint != null) { $atts['placeholder'] = $hint; } if ($att_style != null) { $att_css = null; foreach ($att_style as $style_name => $style_value) { $att_css .= $style_name . ':' . $style_value . ';'; } $atts['style'] = $att_css; } $out .= '<' . $tag; foreach ($atts as $att_name => $att_value) { $out .= ' ' . $att_name . '="' . esc_attr($att_value) . '"'; } if ($content !== null) { $out .= '>' . esc_html($content) . '</' . $tag . '>'; } else { $out .= ' />'; } if (in_array($type, array('image', 'video', 'media'))) { $out .= '<input type="hidden" name="' . esc_attr(synved_option_render_field_name($id, $name . '_info_')) . '" value="' . esc_attr($type) . '" />'; $out .= ' <input type="button" class="synved-option-upload-button" value="' . esc_attr(__('Select File', 'synved-option')) . '"' . $placeholder . ' />'; } break; case 'color': $out .= '<div style="position:relative; float: left;">'; $out .= '<input name="' . $out_name . '" id="' . $out_id . '" type="text" value="' . esc_attr($value) . '" class="code medium-text color-input"' . $placeholder . ' />'; $out .= '<div class="synved-option-color-input-picker" style="background:white;border:solid 1px #ccc;display:none;position:absolute;top:100%;left:0;z-index:10000;"></div>'; $out .= '</div>'; break; case 'integer': case 'decimal': $out .= '<input name="' . $out_name . '" id="' . $out_id . '" type="text" value="' . esc_attr($value) . '" class="code small-text"' . $placeholder . ' />'; break; case 'user': case 'author': case 'category': case 'page': $args = array('echo' => false, 'name' => $out_name, 'id' => $name, 'selected' => $value, 'show_option_all' => __('Every', 'synved-option') . ' ' . ucfirst($type)); $drop_out = null; switch ($type) { case 'author': $args['who'] = 'author'; case 'user': $drop_out = wp_dropdown_users($args); break; case 'category': $drop_out = wp_dropdown_categories($args); break; case 'page': $args['show_option_no_change'] = $args['show_option_all']; $drop_out = wp_dropdown_pages($args); break; } $out .= $drop_out; break; case 'tag-list': $out .= '<input name="' . $out_name . '" id="' . $out_id . '" type="text" value="' . esc_attr($value) . '" class="regular-text synved-option-tag-selector"' . $placeholder . ' />'; break; case 'addon': if (function_exists('synved_option_render_type_addon')) { $out .= synved_option_render_type_addon($id, $name, $item, $out_name, array('out_id' => $out_id, 'label' => $label)); } break; } if ($hint != null) { $out .= ' <span class="snvdopt"><a class="button synved-option-reset-button" title="' . __('Set value to default hinted background value', 'synved-option') . '" style="display: inline-block; padding: 0; vertical-align: middle; cursor: pointer;"><span class="ui-icon ui-icon-arrowrefresh-1-w"> </span></a></span>'; } } $item_render = synved_option_item_render($item); if ($item_render != null) { $error = null; $new_out = null; try { $params = array('output_name' => $out_name, 'output_id' => $out_id, 'output' => $out, 'set' => $set, 'label' => $label); $new_out = $item_render->Invoke(array($value, $params, $name, $id, $item)); } catch (Exception $ex) { $new_out = null; $error = $ex->getMessage(); } if ($new_out !== null) { $out = $new_out; } } if ($out != null) { if ($tip != null && $type != 'boolean') { $tip_class = ' description-' . $type; $out .= ' <span class="description' . $tip_class . '">' . $tip . '</span>'; } if ($render) { echo $out; } else { return $out; } } return null; }
function synved_social_init() { if (current_user_can('edit_posts') || current_user_can('edit_pages')) { if (get_user_option('rich_editing') == 'true') { //add_filter('mce_external_plugins', 'synved_social_wp_tinymce_plugin'); //add_filter('mce_buttons', 'synved_social_wp_tinymce_button'); } } $priority = defined('SHORTCODE_PRIORITY') ? SHORTCODE_PRIORITY : 11; if (synved_option_get('synved_social', 'shortcode_widgets')) { remove_filter('widget_text', 'do_shortcode', $priority); add_filter('widget_text', 'do_shortcode', $priority); } if (function_exists('synved_shortcode_add')) { synved_shortcode_add('feather_share', 'synved_social_share_shortcode'); synved_shortcode_add('feather_follow', 'synved_social_follow_shortcode'); $size_set = '16,24,32,48,64,96'; $size_item = synved_option_item('synved_social', 'icon_size'); if ($size_item != null) { $item_set = synved_option_item_set($size_item); if ($item_set != null) { $set_items = array(); foreach ($item_set as $set_item) { $item_keys = array_keys($set_item); $set_items[] = $item_keys[0]; } $size_set = implode(',', $set_items); } } $providers_share = array_keys(synved_social_service_provider_list('share')); $providers_follow = array_keys(synved_social_service_provider_list('follow')); $providers_params = array('show' => __('Specify a comma-separated list of %1$s providers to show and their order, possible values are %2$s', 'social-media-feather'), 'hide' => __('Specify a comma-separated list of %1$s providers to hide, possible values are %2$s', 'social-media-feather')); $common_params = array('skin' => __('Specify which skin to use for the icons', 'social-media-feather'), 'size' => sprintf(__('Specify the size for the icons, possible values are %s', 'social-media-feather'), $size_set), 'spacing' => __('Determines how much blank space there will be between the buttons, in pixels', 'social-media-feather'), 'container' => __('Determines whether to wrap the buttons in a container', 'social-media-feather'), 'container_type' => sprintf(__('Determines what type of container to use, possible values are %1$s', 'social-media-feather'), 'basic, block'), 'class' => __('Select additional CSS classes for the buttons, separated by spaces', 'social-media-feather')); $share_params = array('url' => __('URL to use for the sharing buttons, default is the current post URL', 'social-media-feather'), 'title' => __('Title to use for the sharing buttons, default is the current post title', 'social-media-feather')); $follow_params = array(); $share_params = array_merge($common_params, $share_params); $follow_params = array_merge($common_params, $follow_params); foreach ($providers_params as $param_name => $param_value) { $share_params[$param_name] = sprintf($param_value, 'share', implode(', ', $providers_share)); $follow_params[$param_name] = sprintf($param_value, 'follow', implode(', ', $providers_follow)); } synved_shortcode_item_help_set('feather_share', array('tip' => __('Creates a list of buttons for social sharing as selected in the Social Media options', 'social-media-feather'), 'parameters' => $share_params)); synved_shortcode_item_help_set('feather_follow', array('tip' => __('Creates a list of buttons for social following as selected in the Social Media options', 'social-media-feather'), 'parameters' => $follow_params)); } else { add_shortcode('feather_share', 'synved_social_share_shortcode'); add_shortcode('synved_feather_share', 'synved_social_share_shortcode'); add_shortcode('feather_follow', 'synved_social_follow_shortcode'); add_shortcode('synved_feather_follow', 'synved_social_follow_shortcode'); } //add_action('wp_ajax_synved_social', 'synved_social_ajax_callback'); //add_action('wp_ajax_nopriv_synved_social', 'synved_social_ajax_callback'); if (!is_admin()) { add_action('wp_enqueue_scripts', 'synved_social_enqueue_scripts'); add_action('wp_head', 'synved_social_print_styles'); } if (synved_option_get('synved_social', 'automatic_share') || synved_option_get('synved_social', 'automatic_follow')) { add_filter('the_content', 'synved_social_wp_the_content', 10, 2); } }
function synved_option_item_sanitize_value($id, $name, $value, array $item = null) { if ($item == null) { $item = synved_option_item($id, $name); } if ($item == null) { return null; } $type = synved_option_item_type($item); $default = synved_option_item_default($item); $set = synved_option_item_set($item); $sanitize = synved_option_item_sanitize($item); $sanitize_raw = synved_option_item_sanitize_raw($item); if ($sanitize_raw != null) { return $sanitize_raw->Invoke(array($value, $name, $id, $item)); } $value = synved_option_item_sanitize_value_basic($item, $value, $default); $is_valid = true; if ($set != null) { if (is_array($value)) { $is_valid = false; $new_value = array(); foreach ($value as $single_key => $single_value) { if (synved_option_item_set_check_value($item, $set, $single_value)) { $new_value[$single_key] = $single_value; } } if ($new_value != null) { $is_valid = true; $value = $new_value; } } else { if (!synved_option_item_set_check_value($item, $set, $value)) { $value = $default; } } } if ($is_valid) { if ($sanitize != null) { $value = $sanitize->Invoke(array($value, $name, $id, $item)); } return $value; } return null; }