Example #1
0
/**
 * Populate the link editing modal.
 *
 * @since 0.4.0
 */
function ev_link_modal_load()
{
    if (!ev_is_post_nonce_valid('ev_link')) {
        die;
    }
    if (!isset($_POST['data'])) {
        die;
    }
    $data = $_POST['data'];
    $url = isset($data['url']) ? $data['url'] : '';
    $target = isset($data['target']) ? $data['target'] : '';
    $rel = isset($data['rel']) ? $data['rel'] : '';
    $title = isset($data['title']) ? $data['title'] : '';
    $class = isset($data['class']) ? $data['class'] : '';
    $content = '';
    $content = '<div class="ev-link-ctrls-wrapper">';
    $content .= '<div class="ev-link-url-wrapper">';
    $content .= sprintf('<select name="url" data-nonce="%s">', esc_attr(wp_create_nonce('ev_link_search_entries')));
    if ($url != '') {
        $content .= sprintf('<option value="%s" data-data="%s" selected></option>', esc_attr($url), htmlspecialchars(json_encode(ev_find_single_entry($url)), ENT_QUOTES, 'UTF-8'));
    }
    $content .= '</select>';
    // $content .= sprintf( '<span class="ev-link-trigger"><span>%s</span></span>', esc_html( __( 'Tab', 'ev_framework' ) ) );
    $content .= '</div>';
    $content .= '<div class="ev-link-inner-wrapper">';
    $content .= '<div class="ev-link-radio-wrapper">';
    $content .= sprintf('<p>%s</p>', esc_html(__('Open in', 'ev_framework')));
    $content .= ev_radio('target', array('' => __('Same tab', 'ev_framework'), '_blank' => __('New tab', 'ev_framework')), $target, array('switch', 'small'), false);
    $content .= '</div>';
    $content .= '<div class="ev-link-input-wrapper">';
    $label = __('Rel attribute', 'ev_framework');
    $content .= sprintf('<input type="text" name="rel" value="%s" placeholder="rel">', esc_attr($rel), esc_attr($label));
    $content .= sprintf('<span>%s</span>', $label);
    $content .= '</div>';
    $content .= '<div class="ev-link-input-wrapper">';
    $label = __('Title attribute', 'ev_framework');
    $content .= sprintf('<input type="text" name="title" value="%s" placeholder="title">', esc_attr($title), esc_attr($label));
    $content .= sprintf('<span>%s</span>', $label);
    $content .= '</div>';
    $content .= '<div class="ev-link-input-wrapper">';
    $label = __('Class attribute', 'ev_framework');
    $content .= sprintf('<input type="text" name="class" value="%s" placeholder="class">', esc_attr($class), esc_attr($label));
    $content .= sprintf('<span>%s</span>', $label);
    $content .= '</div>';
    $content .= '</div>';
    $content .= '</div>';
    $m = new Ev_SimpleModal('ev-link');
    $m->render($content);
    die;
}
 /**
  * When the page is refreshed, save the custom data contained in the admin page.
  *
  * @since 0.1.0
  * @param string $group The group of the page that is being saved.
  */
 public function save($group = '')
 {
     /* This should run on admin only. */
     if (!is_admin()) {
         return;
     }
     /* Verify that we're submitting any data. */
     if (empty($_POST)) {
         return;
     }
     /* Verify the validity of the supplied nonce. */
     $is_valid_nonce = ev_is_post_nonce_valid('ev_admin_page');
     /* Check the user has the capability to save the page. */
     $is_valid_cap = current_user_can($this->capability());
     /* Exit if the nonce is invalid or the user doesn't have the required capability to save the page. */
     if (!$is_valid_nonce || !$is_valid_cap) {
         return;
     }
     $elements = $this->elements();
     if (!empty($elements)) {
         foreach ($elements as $index => $element) {
             if ($element['type'] === 'group' && $element['handle'] === $group) {
                 foreach ($element['fields'] as $field) {
                     if (!ev_is_skipped_on_saving($field['type'])) {
                         if (!isset($_POST[$field['handle']])) {
                             $this->_delete_single_field($field['handle']);
                         } else {
                             $this->_save_single_field($field, $_POST[$field['handle']]);
                         }
                     }
                 }
                 break;
             } else {
                 if (!ev_is_skipped_on_saving($element['type'])) {
                     if (!isset($_POST[$element['handle']])) {
                         $this->_delete_single_field($element['handle']);
                     } else {
                         $this->_save_single_field($element, $_POST[$element['handle']]);
                     }
                 }
             }
         }
         $type = 'success';
         $message = apply_filters('ev_save_options_tab_response_message', __('All saved!', 'ev_framework'), $type);
         $heading = apply_filters('ev_save_options_tab_response_heading', '', $type);
         $args = apply_filters("ev_save_options_tab_response_args[tab:{$group}]", array());
         ev_ajax_message($message, $type, $heading, $args);
     }
 }
Example #3
0
/**
 * Contents for the icon selection modal.
 *
 * @since 0.4.0
 */
function ev_icon_modal_load()
{
    if (!ev_is_post_nonce_valid('ev_icon')) {
        die;
    }
    if (!isset($_POST['data'])) {
        die;
    }
    $data = $_POST['data'];
    $prefix = isset($data['prefix']) ? $data['prefix'] : '';
    $set = isset($data['set']) ? $data['set'] : '';
    $icon = isset($data['icon']) ? $data['icon'] : '';
    $color = isset($data['color']) ? $data['color'] : '';
    $size = isset($data['size']) ? $data['size'] : '';
    $icon_fonts = ev_get_icon_fonts();
    $content = '<div class="ev-icon-sets-external-wrapper ev-active">';
    $content .= '<div class="ev-icon-search-wrapper">';
    $content .= sprintf('<input type="text" placeholder="%s" data-icon-search>', esc_attr(_x('Search&hellip;', 'icon search', 'ev_framework')));
    $content .= '<p class="ev-icon-search-results"></p>';
    $content .= '</div>';
    $content .= '<div class="ev-icon-sets-controls-external-wrapper">';
    $content .= '<div class="ev-icon-sets-controls-wrapper">';
    $content .= '<div class="ev-icon-sets-controls-field-wrapper">';
    $content .= sprintf('<label>%s</label>', esc_html(__('Color', 'ev_framework')));
    $content .= ev_color('color', $color, false, false, false);
    $content .= '</div>';
    $content .= '<div class="ev-icon-sets-controls-field-wrapper">';
    $content .= sprintf('<label>%s</label>', esc_html(__('Size', 'ev_framework')));
    $content .= sprintf('<input type="text" name="size" value="%s" data-icon-size>', esc_attr($size));
    $content .= '</div>';
    $content .= sprintf('<input type="hidden" name="prefix" value="%s" data-icon-prefix>', esc_attr($prefix));
    $content .= sprintf('<input type="hidden" name="set" value="%s" data-icon-set>', esc_attr($set));
    $content .= sprintf('<input type="hidden" name="icon" value="%s" data-icon-name>', esc_attr($icon));
    $content .= '</div>';
    $content .= '<div class="ev-icon-sets-preview-wrapper">';
    $content .= sprintf('<span class="ev-icon-sets-preview-label">%s</span>', esc_html(__('Preview', 'ev_framework')));
    $content .= sprintf('<span class="ev-selected-icon-preview ev-icon ev-component %s %s" style="color: %s;font-size: %s"></span>', esc_attr($prefix), esc_attr($icon), esc_attr($color), esc_attr($size));
    $content .= '</div>';
    $content .= '</div>';
    $content .= '<div class="ev-icon-sets-inner-wrapper">';
    $content .= '<div class="ev-icon-sets">';
    foreach ($icon_fonts as $index => $font) {
        $set_class = 'ev-on ev-icon-set-' . $font['name'];
        $content .= sprintf('<div class="%s">', esc_attr($set_class));
        $content .= sprintf('<h2>%s</h2>', esc_html($font['label']));
        foreach ($font['mapping'] as $set_icon) {
            $icon_class = $font['prefix'] . ' ' . $set_icon . ' ev-icon ev-component';
            if ($font['name'] == $set && $font['prefix'] == $prefix && $set_icon == $icon) {
                $icon_class .= ' ev-selected';
            }
            $set_icon_stripped = strstr($set_icon, '-');
            $content .= sprintf('<i data-prefix="%s" data-set="%s" data-icon-name="%s" data-icon-stripped="%s" class="%s" aria-hidden="true"></i>', esc_attr($font['prefix']), esc_attr($font['name']), esc_attr($set_icon), esc_attr($set_icon_stripped), esc_attr($icon_class));
        }
        $content .= '</div>';
    }
    $content .= '</div>';
    $content .= '</div>';
    $content .= '</div>';
    $m = new Ev_SimpleModal('ev-icon', array('title' => __('Icon', 'ev_framework')));
    $m->render($content);
    die;
}
Example #4
0
/**
 * Populate the color presets editing modal.
 *
 * @since 0.4.0
 */
function ev_color_presets_modal_load()
{
    if (!ev_is_post_nonce_valid('ev_color_presets')) {
        die;
    }
    $user_presets = ev_get_user_color_presets();
    $default_presets = ev_get_default_color_presets();
    $content = '';
    $content .= '<div class="ev-color-presets-manager-wrapper">';
    $content .= '<input type="hidden" name="hex" value="" data-hex-value-input>';
    $content .= '<div class="ev-color-presets-wrapper">';
    /* User presets */
    $user_presets_class = '';
    if (!empty($user_presets)) {
        $user_presets_class .= 'ev-color-has-user-presets';
    }
    $content .= sprintf('<div class="ev-color-user-presets %s">', $user_presets_class);
    $content .= sprintf('<h3>%s</h3>', esc_html(__('User-defined presets', 'ev_framework')));
    if (!empty($user_presets)) {
        foreach ($user_presets as $index => $preset) {
            $content .= sprintf('<span data-id="%s" class="ev-color-preset ev-tooltip" data-hex="%s" data-title="%s" style="background-color: %s"><span data-nonce="%s" data-color-delete-preset><span class="screen-reader-text">%s</span></span></span>', isset($preset['id']) ? esc_attr($preset['id']) : '', isset($preset['hex']) ? esc_attr($preset['hex']) : '', isset($preset['label']) ? esc_attr($preset['label']) : '', isset($preset['hex']) ? esc_attr($preset['hex']) : '', esc_attr(wp_create_nonce('ev_color_delete_preset')), esc_html(__('Delete preset', 'ev_framework')));
        }
    }
    $content .= '<p class="ev-no-user-color-presets-warning">' . __("You haven't saved any color presets yet!", 'ev_framework') . '</p>';
    $content .= '</div>';
    /* Default presets */
    $content .= '<div class="ev-color-default-presets">';
    $content .= sprintf('<h3>%s</h3>', esc_html(__('Default presets', 'ev_framework')));
    if (!empty($default_presets)) {
        foreach ($default_presets as $set) {
            $content .= sprintf('<h4>%s</h4>', esc_html($set['label']));
            foreach ($set['presets'] as $preset) {
                $content .= sprintf('<span class="ev-color-preset ev-tooltip" data-hex="%s" data-title="%s" style="background-color: %s"></span>', isset($preset['hex']) ? esc_attr($preset['hex']) : '', isset($preset['label']) ? esc_attr($preset['label']) : '', isset($preset['hex']) ? esc_attr($preset['hex']) : '');
            }
        }
    }
    $content .= '</div>';
    $content .= '</div>';
    $content .= '</div>';
    $m = new Ev_SimpleModal('ev-color-presets', array('title' => __('Color presets', 'ev_framework')));
    $m->render($content);
    die;
}
Example #5
0
/**
 * Determines whether or not the current user has the ability to save meta data
 * associated with this post.
 * Thanks to Tom McFarlin: https://gist.github.com/tommcfarlin/4468321
 *
 * @since 0.1.0
 * @param int $post_id The ID of the post being saved.
 * @param string $action The submitted nonce action.
 * @param string $nonce The submitted nonce key.
 * @return boolean Whether or not the user has the ability to save this post.
 */
function ev_user_can_save($post_id, $action = '', $nonce = 'ev')
{
    /* Verify the validity of the supplied nonce. */
    $is_valid_nonce = ev_is_post_nonce_valid($action, $nonce);
    /* Preventing to do anything when autosaving, editing a revision or performing an AJAX request. */
    $is_autosave = wp_is_post_autosave($post_id);
    $is_revision = wp_is_post_revision($post_id);
    $is_ajax = defined('DOING_AJAX') && DOING_AJAX;
    /* Check the user has the capability to edit posts. */
    $is_valid_cap = current_user_can(get_post_type_object(get_post_type($post_id))->cap->edit_post, $post_id);
    /* Return true if the user is able to save; otherwise, false. */
    return !($is_autosave || $is_revision || $is_ajax) && $is_valid_nonce && $is_valid_cap;
}
 /**
  * Determines whether or not the current user has the ability to save meta data
  * associated with this term.
  *
  * @since 0.4.0
  * @param string $action The submitted nonce action.
  * @param string $nonce The submitted nonce key.
  * @return boolean Whether or not the user has the ability to save this term information.
  */
 private function user_can_save_taxonomy_meta($action = '', $nonce = 'ev')
 {
     /* Verify the validity of the supplied nonce. */
     $is_valid_nonce = ev_is_post_nonce_valid($action, $nonce);
     /* Check the user has the capability to edit the taxonomy data. */
     $is_valid_cap = current_user_can('manage_categories');
     /* Return true if the user is able to save; otherwise, false. */
     return $is_valid_nonce && $is_valid_cap;
 }