jetpack_sharedaddy_override.php
8.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
<?php
/**
* Plugin Name: Fgc Override Jetpack Sharedaddy
* Plugin URI: http://fgc.vn
* Description: Fgc Override Jetpack Sharedaddy.
* Author: Phuong An.
* Author URI: http://fgc.vn
* Version: 1.0
*
* Copyright 2016 Prospress, Inc. (email : freedoms@prospress.com)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @package Jetpack
* @author Phuong An <phuongantt.na@gmail.com>
* @since 1.0
*/
require_once 'email-header.php';
add_action('sharing_email_send_post', 'fgc_sharing_email_send_post');
function fgc_sharing_email_send_post($data) {
$current_page = $data['post'];
$page_template = get_post_meta($current_page->ID, '_wp_page_template', true);
$subject = '[' . __('Shared Post', 'jetpack') . '] ' . $data['post']->post_title;
if ($page_template == 'challenge_results.php') {
$content = sharing_email_send_post_content_ourlink_page($data);
$headers[] = 'Content-Type: text/html; charset=UTF-8';
$subject = 'Your friend has invited you to take the Energy Drink Challenge';
} else if (strpos($_SERVER["REQUEST_URI"], '/my-account') !== false) {
$content = sharing_email_send_post_content_affiliates_links($data);
fgc_add_referee_tag_active_campaign($data['target']);
$subject = 'Your friend has invited you to the REIZE Club';
$headers[] = 'Content-Type: text/html; charset=UTF-8';
} else if (strpos($_SERVER["REQUEST_URI"], 'checkout') !== false) {
$content = sharing_email_send_post_content_affiliates_links($data);
fgc_add_referee_tag_active_campaign($data['target']);
$subject = 'Your friend has invited you to the REIZE Club';
$headers[] = 'Content-Type: text/html; charset=UTF-8';
} else {
$content = fgc_sharing_email_send_post_content($data);
}
// Borrowed from wp_mail();
$sitename = strtolower($_SERVER['SERVER_NAME']);
if (substr($sitename, 0, 4) == 'www.') {
$sitename = substr($sitename, 4);
}
/** This filter is documented in core/src/wp-includes/pluggable.php */
$from_email = apply_filters('wp_mail_from', 'wordpress@' . $sitename);
$headers[] = sprintf('From: %1$s <%2$s>', $data['name'], $from_email);
$headers[] = sprintf('Reply-To: %1$s <%2$s>', $data['name'], $data['source']);
wp_mail($data['target'], $subject, $content, $headers);
}
function fgc_sharing_email_send_post_content($data) {
/* translators: included in e-mail when post is shared via e-mail. First item is sender's name. Second is sender's e-mail address. */
$content = sprintf(__('%1$s (%2$s) thinks you may be interested in the following post:', 'jetpack'), $data['name'], $data['source']);
$content .= "\n\n";
$content .= $data['post']->post_title . "\n";
$content .= get_permalink($data['post']->ID) . "\n";
return $content;
}
/**
* Author: Phuong An
*
* Create content email to share affiliates link
* @param type $data
* @return string
*/
function sharing_email_send_post_content_affiliates_links($data) {
/* translators: included in e-mail when post is shared via e-mail. First item is sender's name. Second is sender's e-mail address. */
// $content = sprintf(__('<p>Hi,</p><p>I’m saving bucket loads of cash since I switched to REIZE! I highly recommend you give it a go.\nIf you join up today you' . "'" . 'll get 25% off your first month ', 'jetpack'), $data['name'], $data['source']);
// $content = "Hi,<br/>I'm saving bucket loads of cash since I switched to REIZE! I highly recommend you give it a go.<br/>If you join up today you'll get 25% off your first month ";
// $content .= '<a href="' . do_shortcode('[affiliates_url]') . '">' . do_shortcode('[affiliates_url]') . '</a>';
$content = fgc_get_content_email(do_shortcode('[affiliates_url]'), 'CONGRATULATIONS!', 'Your friend has invited you to join the REIZE Club.', 'REIZE Energy Drink is new from Australia. The boost is AMAZING and you can mix it anyway you like. Best of all it’s ridiculously cheap. Seriously, you will save bucketloads of cash!', 'Join today using this link and get 25% off your first month.', 'There’s no hidden fees, no commitment, and no contracts. No kidding! And when you try the Club using the link in this email your friend gets $15. Yo `lil bewdy!', 'Welcome aboard,<br/>Marty & Steve', 'TRY THE CLUB');
return $content;
}
/**
* Author: Ho Ngoc Hang
* content email for only ourlink page
* @param type $data
* @return string
*/
function sharing_email_send_post_content_ourlink_page($data) {
/* translators: included in e-mail when post is shared via e-mail. First item is sender's name. Second is sender's e-mail address. */
$our_link_page = get_page_by_title('OUR DRINK', OBJECT, 'page');
$link_page = get_permalink($our_link_page->ID);
// $string = "<p>I just found out how much I could saving on energy drinks. <a href='$link_page'>Click here</a> and you can take the challenge too.</p>";
// $content = sprintf(__('%1$s (%2$s) thinks you may be interested in the following post:', 'jetpack'), $data['name'], $data['source']);
// $content .= "\n\n";
// $content .= $string . "\n";
$content = fgc_get_content_email($link_page, 'TAKE THE CHALLENGE', 'Your friend has invited you to take the Energy Drink Challenge', 'Check this out... find out how much money you can save by switching to REIZE Energy Drink. REIZE is new from Australia. The boost is AMAZING and you can mix it anyway you like. Best of all it’s ridiculously cheap. Seriously, you will save bucketloads of cash!', '', '', '', 'CHALLENGE ME!');
return $content;
}
/**
* Author: Hung Tran
* Override Jetpack plugin to set Twitter sharing text before javascript running
* @param type $title
* @return string
*/
function fgc_custom_sharing_title() {
$post = get_post($post_id);
if (empty($post)) {
return;
} else {
// Create sharing title
$uri = $_SERVER['REQUEST_URI'];
$url = get_option('siteurl');
$url_replaced_link = str_replace(array('http://', 'http://wwww.'), array('', ''), $url);
// $aff_code = str_replace('https:', 'http:', do_shortcode('[affiliates_url]'));
$aff_code = do_shortcode('[affiliates_url]');
if ((strpos($uri, 'checkout') == true || strpos($uri, 'my-account') == true) && strpos($uri, 'twitter') == true) {
$sharing_title = 'I`m LOVING @reizeenergy! Home delivered #energydrinks. Save 25% with this link ' . $aff_code . ' #energydrink pic.twitter.com/irO6DrDLOt';
} else if ((strpos($uri, 'challenge-results') == true) && strpos($uri, 'twitter') == true) {
$sharing_title = 'Take the REIZE Energy Drink Challenge! ' . $url_replaced_link . '/our-drink/ pic.twitter.com/irO6DrDLOt';
} else {
$sharing_title = $post->post_title;
}
return $sharing_title;
}
}
add_filter('sharing_title', 'fgc_custom_sharing_title', 10, 3);
/*
* Make Twitter sharing url empty.
*/
function fgc_custom_sharing_permalink() {
$post = get_post();
if (empty($post)) {
return;
} else {
// Create sharing permalink
$uri = $_SERVER[REQUEST_URI];
if ((strpos($uri, 'checkout') == true || strpos($uri, 'my-account') == true || strpos($uri, 'challenge-results') == true) && strpos($uri, 'twitter') == true) {
$sharing_permalink = '';
} else if ((strpos($uri, 'checkout') == true || strpos($uri, 'my-account') == true || strpos($uri, 'challenge-results') == true) && strpos($uri, 'facebook') == true) {
$sharing_permalink = do_shortcode('[affiliates_url]');
} else {
$sharing_permalink = get_permalink($post_id);
}
return $sharing_permalink;
}
}
add_filter('sharing_permalink', 'fgc_custom_sharing_permalink', 10, 3);
function fgc_add_referee_tag_active_campaign($email) {
if (class_exists('FGC_ActiveCampaign')) {
FGC_ActiveCampaign::sync_contact_by_email($email, array('tags' => 'AFFILIATE: Referee', "p[8]" => 8));
}
}