Skip to content

Commit

Permalink
Merge pull request #1 from katzwebservices/develop
Browse files Browse the repository at this point in the history
Version 2.0.1
  • Loading branch information
zackkatz authored Feb 2, 2017
2 parents b4bac25 + a4260df commit dff86fc
Show file tree
Hide file tree
Showing 6 changed files with 343 additions and 270 deletions.
91 changes: 48 additions & 43 deletions functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,60 +5,65 @@
function contact_form_7_modules_promo_message() {
global $pagenow;

if(!current_user_can('install_plugins')) { return; }

$message = (int)get_option('cf7_modules_hide_promo_message');

if(isset($_REQUEST['hide']) && $_REQUEST['hide'] == 'cf7_modules_promo_message') {
$message = 3;
update_option('cf7_modules_hide_promo_message', $message);
if ( ! current_user_can( 'install_plugins' ) ) {
return;
}

if($pagenow == 'admin.php' && isset($_REQUEST['page']) && $_REQUEST['page'] == 'wpcf7' && ($message !== 3 || isset($_REQUEST['show']) && $_REQUEST['show'] == 'cf7_modules_promo_message')) {
$message = contact_form_7_modules_get_remote_message();
$message = (int) get_option( 'cf7_modules_hide_promo_message' );

$message = str_replace('{hidelink}', add_query_arg('hide', 'cf7_modules_promo_message'), $message);
$message = str_replace('{showlink}', add_query_arg('show', 'cf7_modules_promo_message'), $message);
$message = str_replace('{adminurl}', admin_url(), $message);
$message = str_replace('{siteurl}', site_url(), $message);
if ( isset( $_REQUEST['hide'] ) && $_REQUEST['hide'] === 'cf7_modules_promo_message' ) {
$message = 5;
update_option( 'cf7_modules_hide_promo_message', $message );
}

echo $message;
if ( $pagenow == 'admin.php' && isset( $_REQUEST['page'] ) && $_REQUEST['page'] == 'wpcf7' && ( $message !== 5 || isset( $_REQUEST['show'] ) && $_REQUEST['show'] == 'cf7_modules_promo_message' ) ) {
echo contact_form_7_modules_get_message();
}
}

function contact_form_7_modules_get_remote_message() {

// The ad is stored locally for 30 days as a transient. See if it exists.
$cache = function_exists('get_site_transient') ? get_site_transient('contact_form_7_modules_remote_ad') : get_transient('contact_form_7_modules_remote_ad');

// If it exists, use that (so we save some request time), unless ?cache is set.
if(!empty($cache) && !isset($_REQUEST['cache'])) { return $cache; }

// Get the advertisement remotely. An encrypted site identifier, the language of the site, and the version of the cf7 plugin will be sent to katz.co
$response = wp_remote_post('http://katz.co/ads/', array('timeout' => 45,'body' => array('siteid' => sha1(site_url()), 'language' => get_bloginfo('language'), 'plugin' => 'cf7_modules', 'version' => WPCF7_VERSION)));

// If it was a successful request, process it.
if(!is_wp_error($response) && !empty($response)) {

// Basically, remove <script>, <iframe> and <object> tags for security reasons
$body = strip_tags(trim(rtrim($response['body'])), '<b><strong><em><i><span><u><ul><li><ol><div><attr><cite><a><style><blockquote><q><p><form><br><meta><option><textarea><input><select><pre><code><s><del><small><table><tbody><tr><th><td><tfoot><thead><u><dl><dd><dt><col><colgroup><fieldset><address><button><aside><article><legend><label><source><kbd><tbody><hr><noscript><link><h1><h2><h3><h4><h5><h6><img>');

// If the result is empty, cache it for 8 hours. Otherwise, cache it for 30 days.
$cache_time = empty($response['body']) ? floatval(60*60*8) : floatval(60*60*30);

if(function_exists('set_site_transient')) {
set_site_transient('contact_form_7_modules_remote_ad', $body, $cache_time);
} else {
set_transient('contact_form_7_modules_remote_ad', $body, $cache_time);
}
/**
* Display cross-promo for Contact Form 7 Newsletter plugin
* @since 2.0.1
* @return mixed|string
*/
function contact_form_7_modules_get_message() {

$message = <<<EOL
<div class="updated" style="font-size:1.2em">
<a href="{{hide_link}}" class="button alignright" style="font-style:normal; margin:.75em 0 .75em .75em;">{{hide_text}}</a>
<h2>{{want_to}}</h2>
<a href="{{ctct_url}}"><img alt="Constant Contact" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAARkAAAApCAMAAAA2w608AAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAwBQTFRFtsbaGEV8JlOM+89tUXanma7KJk98mq3FiKLDqLnOi6G5GUaA7Lhp+slcUXSgRGaN/ee2/NqOUnOZboyxhqDC/eCh/NR8fZax+9F12+LsGENyUnSd+Mtxt8TWJlOR8LhYQ2qe66AhNF6VQ2eR+spg7Lx3i6LAiqLEHURyg57AvcvdYICpNVyNi6PC8qod9a4b8agd/vTe7KMf5psjb4qpJlGFk6rI+LEa/u7M/eKp/eq+NF+Y/NyV+8xn97Aa/d+dboy0tsXYxdDc6Z4hqLjK5Jkk99us7bVZ/vDTbouuNF2R+cVT1Nzm1d7qUXWk+9Bx1Nzkt8TUYH+ljqG5t8TSYH6eK1B8+sZVNVuFYIGvdZK4YH6g/evD+ujHqLrRpbnRYIGsma7I4ZUlmqzC/evGcIyui6K++LUocYupJlCAnrPN/eStHEV1+Nec6qxN+taN+9aDssPY9sBVfZe5Q2iWGUeE/vLZ/e3JKFKF/ei6/N2bNVuJxtDdx9Db9M+QnK3BjqG3Q2mZF0iIF0eHF0eGF0eFGEN1F0aDF0aBGER5F0V/GEN2GER6F0eEGER4qLrT093pF0V+i6PExdHibo22xdHhF0eIF0aCF0aAUnGVGER3GEV7fZi9ma/MxdHg76YeQ2qggJu/9KwcG0V4GkZ+iqTEUnKWF0Z/09zoqLrSG0V6fZi8fZm9xdDexdHf55wii6K9G0Z709znfZi7GkZ8eZW7/d2Y/NeFe5i8+shZ+sdY7aMf8KcefZe3xdDf+9iMi6G8+bw2qLnQtsXaws/ggZatxNHh/u/Q/NWAqLvT6bBc+stj/NR+8MqS+OXIxtLitMTZw9Dh9+C6VnOU1Nvk8a0rwc7fsMHWb4mnUXWmGEiH+9ub9+TJ/O7Vr8HW/vXgj6fG/N6b4OfvuMTSjKPAxtHe+cBEOVuDOFyJcIyw78B2/ezF9tGPfZWv7agu8c+gVnKT5aJA5qdP561cmq/L+uvW+uzW/NiKUnWj/OOs67Jb+MJUF0iJF0iK///gFBQU3oCw6gAAAQB0Uk5T////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////AFP3ByUAAAqDSURBVHja7JoJdJTVFcc/w4QYtA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DcLxjCPPtXV1WUc5E2qV/1BZO4jw33LpBJPZlPlNKb3kCF9S4B9qs0uIVN+/i3q3aQWEChThr1LHB89sKyaNft+T42ihKbtXVbCdZKc2BRlqneW41hAprCFykiInpSU8SwSrsj0ccgEfaN7XYcL/ZXD8auK89w5j2DiV5ytaPOlpOt7yYQDnDhnm5/hkmm2JuklGLZ54n7j+gv71fmju/JrVnf/XRu35R/N79LPfEZ3B9Mr/+iEHjJJyLzUK//Orv0y3L3JYPxLg+/t4k/m3ZzM4UFd/mcW3ZoMRl/T9X9j0c1z5j/4xydvCTAA95hdN8HdFIAAAAAASUVORK5CYII=" width="281" height="41" style="margin:.75em 0 0;" /></a>
<h4 style="margin:.75em 0; font-size:1.2em; font-weight:normal;">{{dont_have}} <a href="{{ctct_url}}">{{try_free}}</a> {{15_days}}</h4>
<p>{{description}}</p>
<p class="submit"><a href="{{admin_url}}" class="button button-large button-primary thickbox" style="display:inline-block; margin-bottom:1em; font-size:1.2em;" title="{{install_title}}">{{add_support}}</a><strong class="description"> - {{its_easy}}</strong></p>
<div class="clear"></div>
</div>
EOL;

$strings = array(
'ctct_url' => 'https://katz.si/4i',
'hide_link' => esc_url_raw( add_query_arg( 'hide', 'cf7_modules_promo_message' ) ),
'hide_text' => esc_html__( 'Hide this message', 'cf7_modules' ),
'want_to' => esc_html__( 'Want to integrate your form with a newsletter?', 'cf7_modules' ),
'dont_have' => esc_html__( 'Don\'t have a Constant Contact account?', 'cf7_modules' ),
'try_free' => esc_html__( 'Try Constant Contact for free', 'cf7_modules' ),
'15_days' => esc_html__( 'for 15 days!', 'cf7_modules' ),
'description' => esc_html__( 'The Contact Form 7 Constant Contact Module makes it super-simple to add your contacts to an email newsletter. Simply sign up for a free trial at Constant Contact, enter your details, and you\'re ready to rock.', 'cf7_modules' ),
'add_support' => esc_html__( 'Add Newsletter Support', 'cf7_modules' ),
'install_title' => esc_html__( 'Install Contact Form 7 - Constant Contact Module', 'cf7_modules' ),
'its_easy' => esc_html__( 'It&rsquo;s easy!', 'cf7_modules' ),
'admin_url' => esc_url_raw( admin_url( 'plugin-install.php?tab=plugin-information&amp;plugin=contact-form-7-newsletter&amp;TB_iframe=true&amp;width=600&amp;height=800' ) ),
);

foreach ( $strings as $key => $string ) {
$message = str_replace( '{{' . $key . '}}', $string, $message );
}

// Print the results.
return $body;
}
return $message;
}

add_filter( 'wpcf7_cf7com_links', 'contact_form_7_modules_links' );

function contact_form_7_modules_links($links) {
return str_replace('</div>', ' - <a href="http://katz.si/gf?con=link" target="_blank" title="Gravity Forms is the best WordPress contact form plugin." style="font-size:1.25em;">Try Gravity Forms</a></div>', $links);
return str_replace( '</div>', ' - <a href="http://katz.si/gf?con=link" target="_blank" title="Gravity Forms is the best WordPress contact form plugin." style="font-size:1.25em;">Try Gravity Forms</a></div>', $links );
}
Loading

0 comments on commit dff86fc

Please sign in to comment.