/** * Update tables. * * @since 1.21.0 Checking for new table version. * @since 2.4.0 Checking for missing table. */ function wpmtst_update_db_check() { global $wpdb; $table_name = $wpdb->prefix . 'strong_views'; if (get_option('wpmtst_db_version') != WPMST()->get_db_version() || $wpdb->get_var("SHOW TABLES LIKE '{$table_name}'") != $table_name) { wpmtst_update_tables(); } }
/** * Enqueue styles and scripts after theme. * * @since 1.15.0 */ function wpmtst_scripts_after_theme() { wpmtst_register_cycle(); $styles = WPMST()->get_styles(); if ($styles) { foreach ($styles['later'] as $key => $style) { wp_enqueue_style($style); } } $scripts = WPMST()->get_scripts(); if ($scripts) { foreach ($scripts['later'] as $key => $script) { wp_enqueue_script($script); } } }
/** * Custom CSS for Views only. * * @param $view * @param $background * @param $handle */ private static function custom_background($view = null, $background, $handle = 'wpmtst-custom-style') { if (!$view || !isset($background['type'])) { return; } $c1 = ''; $c2 = ''; switch ($background['type']) { case 'preset': $preset = WPMST()->get_background_presets($background['preset']); $c1 = $preset['color']; if (isset($preset['color2'])) { $c2 = $preset['color2']; } break; case 'gradient': $c1 = $background['gradient1']; $c2 = $background['gradient2']; break; case 'single': $c1 = $background['color']; break; default: } if (!wp_style_is($handle)) { wp_enqueue_style($handle); } if ($c1 && $c2) { $gradient = self::gradient_rules($c1, $c2); wp_add_inline_style($handle, ".strong-view-id-{$view} .testimonial-inner { {$gradient} }"); } elseif ($c1) { wp_add_inline_style($handle, ".strong-view-id-{$view} .testimonial-inner { background: {$c1}; }"); } }
/** * Notify admin upon testimonial submission. * * @param array $post * @param string $form_name * @since 1.7.0 * @since 2.4.0 Logging mail failure. */ function wpmtst_notify_admin($post, $form_name = 'custom') { $fields = wpmtst_get_form_fields($form_name); $options = get_option('wpmtst_options'); $form_options = get_option('wpmtst_form_options'); if ($form_options['sender_site_email']) { $sender_email = get_bloginfo('admin_email'); } else { $sender_email = $form_options['sender_email']; } $sender_name = $form_options['sender_name']; if ($form_options['admin_notify']) { foreach ($form_options['recipients'] as $recipient) { if (isset($recipient['admin_site_email']) && $recipient['admin_site_email']) { $admin_email = get_bloginfo('admin_email'); } else { $admin_email = $recipient['admin_email']; } $admin_name = $recipient['admin_name']; $to = sprintf('%s <%s>', $admin_name, $admin_email); // Subject line $subject = $form_options['email_subject']; $subject = str_replace('%BLOGNAME%', get_bloginfo('name'), $subject); $subject = str_replace('%TITLE%', $post['post_title'], $subject); $subject = str_replace('%STATUS%', $post['post_status'], $subject); // custom fields foreach ($fields as $field) { $replace = isset($post[$field['name']]) ? $post[$field['name']] : '(blank)'; $field_as_tag = '%' . strtoupper($field['name']) . '%'; $subject = str_replace($field_as_tag, $replace, $subject); } // Message text $message = $form_options['email_message']; $message = str_replace('%BLOGNAME%', get_bloginfo('name'), $message); $message = str_replace('%TITLE%', $post['post_title'], $message); $message = str_replace('%CONTENT%', $post['post_content'], $message); $message = str_replace('%STATUS%', $post['post_status'], $message); // custom fields foreach ($fields as $field) { $replace = isset($post[$field['name']]) ? $post[$field['name']] : '(blank)'; $field_as_tag = '%' . strtoupper($field['name']) . '%'; $message = str_replace($field_as_tag, $replace, $message); } $headers = sprintf('From: %s <%s>', $sender_name, $sender_email); // @TODO More info here? A copy of testimonial? A link to admin page? A link to approve directly from email? $mail_sent = wp_mail($to, $subject, $message, $headers); // Log email action if (isset($options['email_log_level']) && $options['email_log_level']) { // for both levels, log failure only // for level 2, log both success and failure if (!$mail_sent || 2 == $options['email_log_level']) { $log_entry = array('response' => $mail_sent ? 'mail successful' : 'mail failed', 'to' => $to, 'subject' => $subject, 'message' => $message, 'headers' => $headers); WPMST()->log($log_entry, __FUNCTION__); } } } // for each recipient } // if notify }
/** * The form. * * @param $atts * * @return mixed|string|void */ function wpmtst_form_view($atts) { global $strong_templates; if (isset($_GET['success'])) { // Load stylesheet do_action('wpmtst_form_rendered', $atts); return apply_filters('wpmtst_form_success_message', '<div class="testimonial-success">' . wpmtst_get_form_message('submission-success') . '</div>'); } // TODO no need to extract extract(normalize_empty_atts($atts)); $fields = wpmtst_get_form_fields($form_id); $form_values = array('category' => $category); foreach ($fields as $key => $field) { $form_values[$field['name']] = ''; } $previous_values = WPMST()->get_form_values(); if ($previous_values) { $form_values = array_merge($form_values, $previous_values); } WPMST()->set_form_values($form_values); /** * Add filters here. */ /** * Load template */ $template_file = $strong_templates->get_template_attr($atts, 'template'); ob_start(); /** @noinspection PhpIncludeInspection */ include $template_file; $html = ob_get_contents(); ob_end_clean(); /** * Remove filters here. */ do_action('wpmtst_form_rendered', $atts); $html = apply_filters('strong_view_form_html', $html); return $html; }
/** * Sanitize and validate a View. * TODO break down into separate validators * * @since 1.21.0 * @since 2.5.7 Strip CSS from CSS Class Names field. * * @param $input * * @return array */ function wpmtst_sanitize_view($input) { ksort($input); $view_data = array(); $view_data['mode'] = sanitize_text_field($input['mode']); // Compatibility $view_data['compat'] = 'compat_on' == $input['compat'] ? 1 : 0; // Read more target if (isset($input['read_more']) && isset($input['read_more_to'])) { // Target: the post if ('more_post' == $input['read_more_to']) { $view_data['more_post'] = 1; } else { // Target: a page // Check the "ID or slug" field first if ($input['more_page_id']) { // is post ID? $id = (int) sanitize_text_field($input['more_page_id']); if ($id) { if (!get_posts(array('p' => $id, 'post_type' => 'page', 'post_status' => 'publish'))) { $id = null; } } else { // is post slug? $target = get_posts(array('name' => $input['more_page_id'], 'post_type' => 'page', 'post_status' => 'publish')); if ($target) { $id = $target[0]->ID; } } $view_data['more_page'] = $id; } else { $view_data['more_page'] = (int) sanitize_text_field($input['more_page']); } $view_data['more_page_id'] = ''; } } $view_data['more_text'] = sanitize_text_field($input['more_text']); /** * Single testimonial */ // Clear single ID if "multiple" selected if ('multiple' == $input['select']) { $view_data['id'] = 0; // must be zero not empty or false //$view_data['post_id'] = ''; } else { // Check the "ID or slug" field first if (!$input['post_id']) { $view_data['id'] = (int) sanitize_text_field($input['id']); } else { // is post ID? $id = (int) $input['post_id']; if ($id) { if (!get_posts(array('p' => $id, 'post_type' => 'wpm-testimonial', 'post_status' => 'publish'))) { $id = null; } } else { // is post slug? $target = get_posts(array('name' => $input['post_id'], 'post_type' => 'wpm-testimonial', 'post_status' => 'publish')); if ($target) { $id = $target[0]->ID; } } $view_data['id'] = $id; $view_data['post_id'] = ''; } } $view_data['form_ajax'] = isset($input['form_ajax']) ? 1 : 0; // Template if ('form' == $view_data['mode']) { $view_data['template'] = isset($input['form-template']) ? sanitize_text_field($input['form-template']) : ''; } else { $view_data['template'] = isset($input['template']) ? sanitize_text_field($input['template']) : ''; } // Category if ('form' == $view_data['mode']) { if (isset($input['category-form'])) { $view_data['category'] = sanitize_text_field(implode(',', $input['category-form'])); } else { $view_data['category'] = ''; } } else { if ('allcats' == $input['category_all']) { $view_data['category'] = 'all'; } elseif (!isset($input['category'])) { $view_data['category'] = 'all'; } elseif ('somecats' == $input['category_all'] && !isset($input['category'])) { $view_data['category'] = 'all'; } else { $view_data['category'] = sanitize_text_field(implode(',', $input['category'])); } } $view_data['order'] = sanitize_text_field($input['order']); $view_data['all'] = sanitize_text_field($input['all']); $view_data['count'] = (int) sanitize_text_field($input['count']); $view_data['pagination'] = isset($input['pagination']) ? 1 : 0; $view_data['per_page'] = (int) sanitize_text_field($input['per_page']); $view_data['nav'] = str_replace(' ', '', sanitize_text_field($input['nav'])); $view_data['title'] = isset($input['title']) ? 1 : 0; $view_data['content'] = sanitize_text_field($input['content']); $view_data['length'] = (int) sanitize_text_field($input['length']); $view_data['thumbnail'] = isset($input['thumbnail']) ? 1 : 0; $view_data['thumbnail_size'] = sanitize_text_field($input['thumbnail_size']); $view_data['thumbnail_width'] = sanitize_text_field($input['thumbnail_width']); $view_data['thumbnail_height'] = sanitize_text_field($input['thumbnail_height']); $view_data['lightbox'] = isset($input['lightbox']) ? 1 : 0; $view_data['gravatar'] = sanitize_text_field($input['gravatar']); /** * CSS Class Names * This field is being confused with custom CSS rules like `.testimonial { border: none; }` * so strip periods and anything between and including curly braces. */ $view_data['class'] = sanitize_text_field(trim(preg_replace('/\\{.*?\\}|\\./', '', $input['class']))); // Background $view_data['background'] = WPMST()->get_background_defaults(); if (!isset($input['background']['type']) || 'none' == $input['background']['type']) { $view_data['background']['type'] = ''; } else { $view_data['background']['type'] = sanitize_text_field($input['background']['type']); } $view_data['background']['color'] = sanitize_text_field($input['background']['color']); $view_data['background']['gradient1'] = sanitize_text_field($input['background']['gradient1']); $view_data['background']['gradient2'] = sanitize_text_field($input['background']['gradient2']); $view_data['background']['preset'] = sanitize_text_field($input['background']['preset']); $view_data['background']['example-font-color'] = sanitize_text_field($input['background']['example-font-color']); // Layout input may have been disabled by selecting the widget template so no value is posted. if (!isset($input['layout'])) { $view_data['layout'] = ''; } else { // pagination and Masonry are incompatible $view_data['layout'] = sanitize_text_field($input['layout']); if (isset($input['pagination']) && 'masonry' == $view_data['layout']) { $view_data['layout'] = ''; } } $view_data['column_count'] = sanitize_text_field($input['column_count']); // Slideshow $view_data['show_for'] = floatval(sanitize_text_field($input['show_for'])); $view_data['effect_for'] = floatval(sanitize_text_field($input['effect_for'])); $view_data['no_pause'] = isset($input['no_pause']) ? 0 : 1; // Custom fields if (isset($input['client_section'])) { foreach ($input['client_section'] as $key => $field) { if (empty($field['field'])) { break; } $view_data['client_section'][$key]['field'] = sanitize_text_field($field['field']); $view_data['client_section'][$key]['type'] = sanitize_text_field($field['type']); $view_data['client_section'][$key]['class'] = sanitize_text_field($field['class']); switch ($field['type']) { case 'link': case 'link2': $view_data['client_section'][$key]['url'] = sanitize_text_field($field['url']); $view_data['client_section'][$key]['link_text'] = sanitize_text_field($field['link_text']); $view_data['client_section'][$key]['link_text_custom'] = sanitize_text_field($field['link_text_custom']); $view_data['client_section'][$key]['new_tab'] = isset($field['new_tab']) ? 1 : 0; break; case 'date': $format = isset($field['format']) ? sanitize_text_field($field['format']) : ''; $view_data['client_section'][$key]['format'] = $format; break; default: } } } else { $view_data['client_section'] = null; } // Multiple Forms add-on if (isset($input['form_id'])) { $view_data['form_id'] = $input['form_id']; } else { $view_data['form_id'] = $input['_form_id']; } $view_data = apply_filters('wpmtst_sanitized_view', $view_data, $input); ksort($view_data); return $view_data; }
/** * Build class list based on view attributes. */ public function build_classes() { $content_class_list = array(); $post_class_list = array('testimonial'); // excerpt overrides length if ($this->atts['excerpt']) { $post_class_list[] = 'excerpt'; } elseif ($this->atts['length']) { $post_class_list[] = 'truncated'; } /** * Slideshow */ if ($this->atts['slideshow']) { // add slideshow signature $args = array('fx' => 'fade', 'speed' => $this->atts['effect_for'] * 1000, 'timeout' => $this->atts['show_for'] * 1000, 'pause' => $this->atts['no_pause'] ? 0 : 1); $content_class_list[] = 'strong_cycle'; $content_class_list[] = 'strong_cycle_' . hash('md5', serialize($args)); $post_class_list[] = 't-slide'; } else { if ($this->atts['per_page'] && $this->post_count > $this->atts['per_page'] && 'masonry' != $this->atts['layout']) { $content_class_list[] = 'strong-paginated'; } // layouts $content_class_list[] = 'strong-' . ($this->atts['layout'] ? $this->atts['layout'] : 'normal'); $content_class_list[] = 'columns-' . ($this->atts['layout'] ? $this->atts['column_count'] : '1'); } /** * Filter classes and store updated atts. */ $this->atts['content_class'] = join(' ', apply_filters('wpmtst_view_content_class', $content_class_list)); $this->atts['post_class'] = join(' ', apply_filters('wpmtst_view_post_class', $post_class_list)); WPMST()->set_atts($this->atts); }
function wpmtst_post_class() { echo apply_filters('wpmtst_post_class', WPMST()->atts('post_class') . ' post-' . get_the_ID()); }
echo $view['background']['gradient2']; ?> " class="wp-color-picker-field gradient"> </div> </div> </div> </div> </div> <div class="background-description bg-preset"> <div class="background-description-inner"> <label for="view-background-preset"> <select id="view-background-preset" name="view[data][background][preset]"> <?php $presets = WPMST()->get_background_presets(); $current_preset = isset($view['background']['preset']) && $view['background']['preset'] ? $view['background']['preset'] : ''; echo '<option value="" ' . selected($current_preset, '', false) . '>—</option>'; foreach ($presets as $key => $preset) { echo '<option value="' . $key . '" ' . selected($current_preset, $key, false) . '>' . $preset['label'] . '</option>'; } ?> </select> </label> </div> </div> </div> <div class="view-background-info-inner background-preview-wrap">
function wpmtst_get_background_preset_colors() { $preset = WPMST()->get_background_presets($_REQUEST['key']); echo json_encode($preset); die; }
function wpmtst_form_captcha() { $errors = WPMST()->get_form_errors(); $form_options = get_option('wpmtst_form_options'); if ($form_options['captcha']) { // Only display Captcha label if properly configured. $captcha_html = apply_filters('wpmtst_captcha', $form_options['captcha']); if ($captcha_html) { ?> <div class="wpmtst-captcha"> <label for="wpmtst_captcha"><?php wpmtst_form_message('captcha'); ?> </label><span class="required symbol"></span> <div> <?php echo $captcha_html; ?> <?php if (isset($errors['captcha'])) { ?> <p><label class="error"><?php echo $errors['captcha']; ?> </label></p> <?php } ?> </div> </div> <?php } } }