. */ if(class_exists('WP_Widget') && function_exists('register_widget')) { add_action( 'widgets_init', 'load_constant_contact_widget' ); function load_constant_contact_widget() { register_widget( 'ConstantContactWidget' ); } class ConstantContactWidget extends WP_Widget { var $version = '2.0'; function ConstantContactWidget() { $control_options = array('width'=>400); // 600 px wide please $widget_options = array('description'=>'Add a Constant Contact form to your website', 'classname' => 'constantcontact'); parent::WP_Widget(false, $name = 'Constant Contact Widget 2.0', $widget_options, $control_options); $this->url = WP_PLUGIN_URL . "/" . basename(dirname(__FILE__)); $this->defaults = array( 'id' => '', 'title' => 'Sign up for our Email Newsletter', 'code' => '', 'preface' => '', # 'headline' => false, 'button' => 'Subscribe', 'show_cc_code' =>'yes', 'style' =>'1', 'show_safe_subscribe' =>'yes', 'show_fieldset' => '', 'credit' => '', 'email_image' => '', 'legend' => 'Sign Up', 'bg_color' => '#ffffcc', 'email_label' => 'Email:', 'border_color' => '#000000', 'border_width' => 2, 'width' => '100%', 'input_size' => '20', 'safesubscribe'=>'light', 'initial_value_email' => 'example@subscribe.com', 'https' => is_ssl(), 'target' => 'yes', 'hide' => 'no', 'show_widget' => 'yes', 'uid' => '', 'visible' => '', // Depreciated 'unit' => '', 'wrap' => '', 'form_code' => '', 'form_title' => '', 'form_preface' => '', 'form_wrap' => '' ); add_action('wp_print_styles', array(&$this, 'print_styles')); add_filter('cc_widget_style', array(&$this, 'remove_whitespace')); add_action('wp_print_footer_scripts', array(&$this, 'print_scripts')); add_action('wp_footer', array(&$this, 'footer')); add_action('admin_print_styles-widgets.php', array(&$this, 'widget_styles')); add_action('admin_print_footer_scripts', array(&$this, 'widget_scripts'), 9999); // Implement the shortcodes add_shortcode('ConstantContact', array(&$this, 'shortcode')); add_shortcode('constantcontact', array(&$this, 'shortcode')); add_shortcode('Constant Contact', array(&$this, 'shortcode')); add_shortcode('constant contact', array(&$this, 'shortcode')); } function remove_whitespace($content) { return trim(preg_replace('/\s+/ism', ' ', $content))."\n"; } function footer() { $settings = $this->get_settings(); $credit = false; foreach($settings as $s) { if($s['credit'] == 'yes') { $credit = true; } } if($credit) { echo apply_filters('constant_contact_link', $this->add_link()); } else { echo "\n".''."\n\n"; } } function widget_js() { global $pagenow; if(is_admin() && $pagenow == 'widgets.php') { } } function widget_styles() { $path = get_bloginfo('wpurl'); $style = << .cc_widget_container .accordion .section { padding:10px; } .cc_widget_container .accordion .cc-arrow { background-position: 0 -110px; } .cc_widget_container .accordion h3 { padding:0 0 0 5px; min-height:26px; line-height:26px; margin:0; color:#606060; cursor:pointer; } .cc_widget_container .accordion h3 .cc-arrow { background: url($path/wp-admin/images/menu-bits.gif) no-repeat scroll 0px -110px; float:right; height: 26px; width:24px; } .cc_widget_container .accordion h3:hover .cc-arrow, .cc_widget_container .accordion h3.open .cc-arrow { background-position:0 -207px; } .cc_widget_container fieldset { margin-left:12px; padding:10px 10px 0 10px; border:1px solid #eee; background-color:#fefefe; margin-bottom:10px; display:none; } .cc_widget_container .style_0_options, .cc_widget_container .style_1_options, .cc_widget_container .style_3_options { display:none;} .cc_widget_container legend { font-weight:bold; font-size: 1.2em; margin:0; padding:0; border:none; } EOD; echo trim(preg_replace('/\s+/ism', ' ', $style))."\n"; } function print_scripts() { // For future use return; } function print_styles() { if(is_admin()) { return; } $settings = $this->get_settings(); $usedStyles = array(); foreach($settings as $instance) { $settings = shortcode_atts($this->defaults, $instance); extract($settings); if(in_array($style, $usedStyles) || $style == 0) { continue; } $usedStyles[] = $style; // We don't need to echo the same styles twice $cssOut = ''; if($style == 1) { $cssOut .= ' .cc_style_1 { font-size:10px; color:#999999; margin:0 auto; text-align:center; padding:3px; background-color:'.$bg_color.'; border:'.$border_width.'px solid '.$border_color.';'.$width_style.' } .cc_style_1 * { font-family:Arial,Helvetica,sans-serif;text-align:center; } .cc_style_1 .cc_widget_title { font-weight: bold; font-size:12px; color:#000000;} .cc_style_1 form { margin-bottom:2px; border-top:'.$border_width.'px solid #'.$border_color.' } .cc_style_1 .cc_label_email { font-weight: normal; font-family:Arial; font-size:12px; color:#000000; } .cc_style_1 .cc_input_email { font-size:10pt; border:1px solid #999999; text-align:left; } .cc_style_1 .cc_submit {font-family:Verdana,Geneva,Arial,Helvetica,sans-serif; font-size:10pt; } .cc_safesubscribe { text-align:center; margin:0 auto; width:168px; padding-top:5px; } .cc_email_marketing { display:block; text-align:center; margin:0 auto; font-family:Arial,Helvetica,sans-serif;font-size:10px;color:#999999; } .cc_email_marketing a { text-decoration:none;font-family:Arial,Helvetica,sans-serif;font-size:10px;color:#999999; }'; } elseif($style == 2) { $cssOut .= ' .cc_style_2 { text-align:center; width:'.$this->get_width($width, $unit, $style).'; margin:0 auto; padding:0; background-color:white; } .cc_style_2 * { font-family:Arial,Helvetica,sans-serif; } .cc_style_2 table { border-collapse:separate; border-spacing: 0; width:100%;} .cc_style_2 .cc_top, .cc_style_2 .cc_bottom { background-color:#006699; } .cc_style_2 .cc_top td { vertical-align:top; } .cc_style_2 .cc_middle td.cc_main { border-left: 1px solid #006699;border-right: 1px solid #006699; background-color:#ffffff; } .cc_style_2 .cc_bottom td { vertical-align:bottom; } .cc_style_2 .cc_top img, .cc_style_2 .cc_bottom img { width:100%; max-width:11px; max-height:9px;} .cc_style_2 .cc_widget_title { font-weight: bold; font-size:18px; color:#006699; } .cc_style_2 form { margin-bottom:3px; } .cc_style_2 .cc_widget_title { font-weight: bold; font-family:Arial; font-size:18px; color:#006699; } .cc_style_2 .cc_label_email { font-weight: normal; font-size:10px; color:#000000; } .cc_style_2 .cc_input_email { font-family: Arial; font-size:10px; border:1px solid #999999; } .cc_style_2 .cc_submit {font-family:Arial,Helvetica,sans-serif; font-size:11px; } .cc_safesubscribe { padding-top:5px; } .cc_email_marketing { font-family:Arial,Helvetica,sans-serif;font-size:10px;color:#999999; } .cc_email_marketing a { text-decoration:none;font-size:10px;color:#999999; }'; } elseif($style == 3) { $cssOut .= '.cc_style_3 { width:'.$width.$unit.'; background-color: #ffffff;text-align:center; margin:0 auto; } .cc_style_3 * { font-family:Verdana,Geneva,Arial,Helvetica,sans-serif; } .cc_style_3 .cc_widget_title { font-weight: bold; font-family:Arial; font-size:16px; color:#006699; display:block; padding-bottom:.2em; } .cc_style_3 form { margin-bottom:3px; } .cc_style_3 .cc_label_email { font-weight: normal; font-family:Arial; font-size:10px; color:#000000; } .cc_style_3 .cc_input_email { font-size:10pt; border:1px solid #999999; font-size:10px; border:1px solid #999999; color: #666666; } .cc_style_3 .cc_submit { font-size:10px; } .cc_safesubscribe { padding-top:5px; } .cc_email_marketing { font-family:Arial,Helvetica,sans-serif;font-size:10px;color:#999999; } .cc_email_marketing a { text-decoration:none;font-family:Arial,Helvetica,sans-serif;font-size:10px;color:#999999; }'; } if(!empty($cssOut)) { $cssOut .= ' .cc_widget_container .cc_preface p { margin:0.25em 0; padding:0; } .cc_widget_container .cc_input_email { max-width:95%; } .cc_widget_container .cc_email_image { float:right; margin-right:5px; margin-top:3px; display:block; padding:0; overflow:hidden; } .cc_widget_container .cc_email_image img { background-color: #006699; float:right; } '; if($email_image == 1) { $cssOut .= ' .cc_widget_container .cc_email_image_1, .cc_widget_container .cc_email_image_1 img { width:19px; height:14px; }'; } elseif($email_image == 2) { $cssOut .= ' .cc_widget_container .cc_email_image_2, .cc_widget_container .cc_email_image_2 img { width:17px; height:12px; }'; } elseif($email_image == 3) { $cssOut .= ' .cc_widget_container .cc_email_image_3, .cc_widget_container .cc_email_image_3 img { width:12px; height:9px; }'; } elseif($email_image == 4) { $cssOut .= ' .cc_widget_container .cc_email_image_4, .cc_widget_container .cc_email_image_4 img { width:19px; height:14px; }'; } elseif($email_image == 5) { $cssOut .= ' .cc_widget_container .cc_email_image_5, .cc_widget_container .cc_email_image_5 img { width:19px; height:11px; }'; } $cssOut .= ' .cc_widget_container .cc_email_image img { border:0; padding:0; margin:0; }'; $cssOut = apply_filters('cc_widget_style', apply_filters('cc_widget_style_'.$this->number, '')); echo $cssOut; } } } function widget_scripts() { global $pagenow; if($pagenow == 'widgets.php') { ?> defaults, $atts)); $settings = $this->get_settings(); if(!is_numeric($id) && !empty($id)) { return; } if(empty($id) && sizeof($settings) > 0) { // For users who didn't have multiple widgets before. foreach($settings as $key => $s) { $id = $key; } } if(isset($settings[$id])) { $instance = $settings[$id]; } else { return; } return $this->process_form($instance,array()); } } function update($new_instance, $old_instance) { $instance = $new_instance; if(isset($instance['code'])) { if(preg_match('/name\=\"m\"\ value\=\"([0-9]+)\"/ism', $instance['code'], $matches)) { $instance['uid'] = $matches[1]; } else { $instance['uid'] = ''; } } return $instance; } function widget($args, $instance) { $output = ''; extract( $args ); $settings = shortcode_atts($this->defaults, $instance); extract($settings); if($hide === 'yes' || $show_widget === 'no' || empty($code)) { return; } $output .= $before_widget; $output .= $this->process_form($instance,$args); $output .= "\n\t".$form."\n\t"; $output .= $after_widget; $output = apply_filters('cc_signup_form_widget', $output); echo $output; return; } function process_color($color) { $color = str_replace('#', '', $color); // HEX if(preg_match('/#?[0-9A-Fa-f]{6}/ism', $color)) { $color = str_replace('#', '', $color); $color = strtolower('#'.$color); } // Named else { $color = strtolower($color); } return $color; } function get_width($width, $unit, $style = 0) { // We've taken out the Width Type option and switched to // typing it in. Not hard. If not yet set up, then this happens. if(empty($width) || $width == '0px') { if($style == 2) { $width = '170px'; } else { $width = '100%'; } } else if(!preg_match('/(px|per|\%)/ism', $width, $matches)) { $unit = esc_attr($unit); $unit = ($unit == 'per') ? '%' : 'px'; $width = $width.$unit; } return $width; } function process_form($instance, $args) { extract( $args ); $settings = shortcode_atts($this->defaults, $instance); extract($settings); if($safesubscribe == 'no') { $safe_subscribe_img = ''; $safe_subscribe_link = ''; } else { $safe_subscribe_img = 'SafeSubscribe with Constant Contact'; $safe_subscribe_link = ''.$safe_subscribe_img.''; } $inital_value_email = wptexturize(stripslashes($initial_value_email)); # $width = false; $unit = false; $width_style = false; # if(isset($width)) { # $width = intval(stripslashes($width)); # } $width = $this->get_width($width, $unit, $style); $fieldset = ($show_fieldset !== 'no') ? true : false; $bg_color = $this->process_color($bg_color); $border_color = $this->process_color($border_color); if(strtolower($email_label) == 'none') { $email_label = false; } if($email_image === '') { if($style == 3) { $email_image = 1;} else { $email_image = 0;} } $email_image_code = $email_image_size = ''; if(!empty($email_image)) { if($email_image == 1) { $email_image_size = ' width="19" height="14"'; } elseif($email_image == 2) { $email_image_size = ' width="17" height="12"'; } elseif($email_image == 3) { $email_image_size = ' width="12" height="9"'; } elseif($email_image == 4) { $email_image_size = ' width="19" height="14"'; } elseif($email_image == 5) { $email_image_size = ' width="19" height="11"'; } $email_image_code = 'Email icon'; } // If '0' or 'none', show no initial value JS switching if(empty($initial_value_email) || $initial_value_email == 'none') { $show_initial_value = false; } else { $show_initial_value = true; } $title = wptexturize(esc_attr($title)); if(!empty($preface)) { $preface = empty($wrap) ? wpautop($preface) : '<'.$wrap.'>'.esc_attr($preface).''; } if($style == 1) { // Basic design (Image at http://img.constantcontact.com/ui/images1/signupbox_form_basicS.gif) $pre = '
'.$email_image_code.'
'.$preface.'
'; $form = '
'; if($email_label) { $form .= ''; } $form .= '
'; $post = '
'; $safe = '
'.$safe_subscribe_link.'
'; $link = '
For Email Newsletters you can trust
'; } elseif($style == 2) { // Bubble design (Image at http://img.constantcontact.com/ui/images1/signupbox_form_bubbleS.gif) $width2 = $width - 18; $pre = '
'; $form = '
'.$email_image_code.' '; $form .= '
'.$preface.'
'; if($email_label) { $form .= ''; } $form .= '
'; $post = '
'; $safe = '
'.$safe_subscribe_link.'
'; $link = '
For Email Newsletters you can trust
'; } elseif($style == 3) { // The 'Stylish' design (Image at http://img.constantcontact.com/ui/images1/signupbox_form_stylishS.gif) if(!$width) { $width = 160; } $pre = '
'; $form = ''; $form .= '
'.$email_image_code.'
'.$preface.'
'; $post = '
'; $link = '
For Email Newsletters you can trust
'; $safe = '
'.$safe_subscribe_link.'
'; } else { // No style $pre = $before_title."\n".$title."\n".$after_title; $form = '
'; if($fieldset) { $form .= '
'; } if(htmlspecialchars(stripslashes($legend)) != '') { $form .= ''.htmlspecialchars(stripslashes($legend)).''; }; if($email_label) { $form .= ' '; } $form .= ' '; if($fieldset) { $form .= '
'; } $form .= '
'."\n"; $post = ''; $link = '

For Email Newsletters you can trust

'; $safe = $safe_subscribe_link; } $widget .= $pre; if($https === 'yes') { $form = str_replace('http://', 'https://', $form); } if($target && $target === 'yes') { $form = str_replace('%%target%%', 'target="_blank"', $form);} else { $form = str_replace('%%target%%', '', $form);} $widget .= $form; $widget .= $post; if($show_safesubscribe == 'yes' || $show_safesubscribe == '' && $show_safesubscribe != 'no' && $safesubscribe != 'no') { $widget .= $safe; } if($show_cc_code == 'yes' || $show_cc_code == '') { $widget .= $link; } $widget = apply_filters('cc_signup_form_widget', $widget); return $widget; } function form($instance = array()) { $settings = shortcode_atts($this->defaults, $instance); extract($settings); // Backward compatibility if(!empty($form_title)) { $title = $form_title; } if(!empty($form_wrap)) { $wrap = $form_wrap; } if(!empty($form_preface)) { $preface = $form_preface; } if(!empty($form_button)) { $button = $form_button; } if(!empty($form_code)) { $uid = $form_code; } $code = trim($code); if(!empty($code) && preg_match('/^([0-9]+)$/ism', $code)) { $uid = $code; } // If they enter the UID, or upgrade. if($email_image === '') { if($style == 3) { $email_image = 1;} else { $email_image = 0;} } if(is_int($this->number) || !$this->number) { $kwd_number = $this->number; } else { $kwd_number = '#';} ?>
Show/Hide HTML Form Code

'; ?>

Text & Input Settings

make_textfield($title, 'title', 'title', 'Widget TitleShown above the form.'); ?> make_textfield($headline, 'headline', 'headline', 'Form HeadlineThis is the headline shown inside the form.'); ?>

make_textfield($initial_value_email, 'initial_value_email', 'initial_value_email', 'Email field initial value:This is shown inside the email address input field and disappears when users click to enter their email address. To turn off this functionality, leave blank.'); $this->make_textfield($email_label, 'email_label', 'email_label', 'Email Label:What would you like the label to be for the email input? To hide, leave blank.'); $this->make_textfield($button, 'button', 'button', 'Button Text:'); ?>

Design Preset Settings

make_radio($style, 'style_0','style', '0', 'No StyleOutput only the form HTML, with no styling.'); ?>
Additional Settings make_checkbox($show_fieldset, 'show_fieldset','show_fieldset', 'Use <fieldset>?This groups the form elements together.'); $this->make_textfield($legend, 'legend', 'legend', 'LegendLeave empty to hide. Otherwise, it will be a form <legend>; a label for the <fieldset>.'); ?>
make_radio($style, 'style_1','style', '1', 'Basic DesignThis is also the most valid HTML of the choices.'); ?>
Additional Settings

make_textfield($bg_color, 'bg_color', 'bg_color', 'Change Background Color:If you know the HEX value for the background color you want, enter it here. Ex: F4C2C2.'); ?> make_textfield($border_color, 'border_color', 'border_color', 'Change Border Color:If you know the HEX value for the border color you want, enter it here. Ex: F4C2C2.'); ?>
make_radio($style, 'style_2','style', '2', 'Bubble DesignOnly suitable for websites with white background.'); $this->make_radio($style, 'style_3','style', '3', 'Stylish Design');?>

Visual Settings

make_textfield($width, 'width', 'width', 'Custom Width:Enter the form width in px or %. Examples: 250px or 100%. % is default. You can also leave blank.'); ?>

This image will be displayed to the right of the Widget Title.

make_radio($email_image, 'email_image_1','email_image', '1', ''); $this->make_radio($email_image, 'email_image_2','email_image', '2', ''); $this->make_radio($email_image, 'email_image_3','email_image', '3', ''); $this->make_radio($email_image, 'email_image_4','email_image', '4', ''); $this->make_radio($email_image, 'email_image_5','email_image', '5', ''); $this->make_radio($email_image, 'email_image_0','email_image', '0', 'No image'); ?>

SafeSubscribe logo re-assures potential subscribers that it will be painless to unsubscribe if they choose to. Choose which image will look best with your theme.

make_checkbox($show_cc_code, 'show_cc_code','show_cc_code', 'Show "For Email Newsletters you can trust" Showing this text lets users know that you are not a spammer and will not abuse their trust.'); ?>

Form Settings

make_checkbox($https, 'https','https', 'Make Form HTTPS If you are on a secure site (eCommerce, for example), you should check this.'); $this->make_checkbox($target, 'target','target', 'Open form in new window when submitted'); $this->make_checkbox($credit, 'credit','credit', 'Give Thanks & Credit If you want to show thanks to the widget author, this will add a text link to the website\'s footer. It is much appreciated, and you can always turn it off.'); $this->make_checkbox($hide, 'hide','hide', 'Do not display widget in sidebar. If you are exclusively using the [constantcontact id='.$kwd_number.'] shortcode, not the sidebar widget. Note: you can use a widget in both sidebar and shortcode at the same time.'); ?>
'; } function make_textfield($setting = '', $fieldid = '', $fieldname='', $title = '', $error = '') { $input = ''; $fieldid = $this->get_field_id($fieldid); $fieldname = $this->get_field_name($fieldname); if(!empty($error)) { $input .= '
'; } $input .= '

'; echo $input; } function make_checkbox($setting = '', $fieldid = '', $fieldname='', $title = '') { $fieldid = $this->get_field_id($fieldid); $fieldname = $this->get_field_name($fieldname); $checkbox = '

'; echo $checkbox; } function make_radio($setting = '', $fieldid = '', $fieldname='', $value = '', $title = '') { $fieldid = $this->get_field_id($fieldid); $fieldname = $this->get_field_name($fieldname); $checkbox = '

'; echo $checkbox; } function is_valid_url($location, $default = '') { return $location; if(preg_match('/^(http\:\/\/|https\:\/\/)(([a-z0-9]([-a-z0-9]*[a-z0-9]+)?){1,63}\.)+[a-z]{2,6}/ism', $location) && parse_url($location)) { return $location; } if(empty($default)) { return false; } else { return $default; } } function add_link($code=null) { $attr = $this->attr(); if(!is_wp_error($attr) && !empty($attr)) { $code .= $attr.$comment; } else { $code .= $link.$comment; } return $code; } function attr() { global $post;// prevents calling before if($post && !is_admin()) { $default = 'Email Newsletters with Constant Contact'; $url = 'http://www.katzwebservices.com/development/attribution.php?site='.htmlentities(substr(get_bloginfo('url'), 7)).'&from=cc_widget&version='.$this->version; // > 2.8 if(function_exists('fetch_feed')) { include_once(ABSPATH . WPINC . '/feed.php'); if ( !$rss = fetch_feed($url) ) { return false; } if(!is_wp_error($rss)) { // This list is only missing 'style', 'id', and 'class' so that those don't get stripped. // See http://simplepie.org/wiki/reference/simplepie/strip_attributes for more information. $strip = array('bgsound','expr','onclick','onerror','onfinish','onmouseover','onmouseout','onfocus','onblur','lowsrc','dynsrc'); $rss->strip_attributes($strip); $rss->set_cache_duration(60*60*24*60); // Fetch every 60 days $rss_items = $rss->get_items(0, 1); foreach ( $rss_items as $item ) { return str_replace(array("\n", "\r"), ' ', $item->get_description()); } } return $default; } else { // < 2.8 require_once(ABSPATH . WPINC . '/rss.php'); if ( !$rss = fetch_rss($url) ) return; $items = 1; if ( is_array( $rss->items ) && !empty( $rss->items ) ) { $rss->items = array_slice($rss->items, 0, $items); foreach ($rss->items as $item ) { if ( isset( $item['description'] ) && is_string( $item['description'] ) ) $summary = $item['description']; $desc = str_replace(array("\n", "\r"), ' ', $summary); $summary = ''; return $desc; } } return $default; } } } } } ?>