forked from postmatic/postmatic-social
-
Notifications
You must be signed in to change notification settings - Fork 0
/
postmatic-social.php
236 lines (212 loc) · 6.73 KB
/
postmatic-social.php
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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
<?php
/*
Plugin Name: Postmatic Social Commenting
Plugin URI: https://wordpress.org/plugins/postmatic-social/
Description: A tiny, fast, and convenient way to let your readers comment using their social profiles.
Author: Postmatic, ronalfy
Author URI: https://gopostmatic.com/
Version: 1.0.2
* Text Domain: postmatic-social
* License: GPL-2.0+
* License URI: http://www.gnu.org/licenses/gpl-2.0.txt
* Domain Path: /languages
*/
class Postmatic_Social {
/**
* Holds the class instance.
*
* @since 1.0.0
* @access static
* @var Postmatic_Social $instance
*/
private static $instance = null;
/**
* Holds the URL to the admin panel page
*
* @since 1.0.0
* @access static
* @var string $url
*/
private static $url = '';
/**
* Retrieve a class instance.
*
* Retrieve a class instance.
*
* @since 5.0.0
* @access static
*
* @return MPSUM_Updates_Manager Instance of the class.
*/
public static function get_instance() {
if ( null == self::$instance ) {
self::$instance = new self;
}
return self::$instance;
} //end get_instance
/**
* Retrieve the plugin basename.
*
* Retrieve the plugin basename.
*
* @since 1.0.0
* @access static
*
* @return string plugin basename
*/
public static function get_plugin_basename() {
return plugin_basename( __FILE__ );
}
/**
* Class constructor.
*
* Set up internationalization, auto-loader, and plugin initialization.
*
* @since 1.0.0
* @access private
*
*/
private function __construct() {
/* Localization Code */
load_plugin_textdomain( 'postmatic-social', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
add_action( 'plugins_loaded', array( $this, 'plugins_loaded' ) );
add_action( 'prompt/core_loaded', array( $this, 'postmatic_loaded' ) );
} //end constructor
/**
* Return the absolute path to an asset.
*
* Return the absolute path to an asset based on a relative argument.
*
* @since 1.0.0
* @access static
*
* @param string $path Relative path to the asset.
* @return string Absolute path to the relative asset.
*/
public static function get_plugin_dir( $path = '' ) {
$dir = rtrim( plugin_dir_path( __FILE__ ), '/' );
if ( !empty( $path ) && is_string( $path ) )
$dir .= '/' . ltrim( $path, '/' );
return $dir;
}
/**
* Return the web path to an asset.
*
* Return the web path to an asset based on a relative argument.
*
* @since 1.0.0
* @access static
*
* @param string $path Relative path to the asset.
* @return string Web path to the relative asset.
*/
public static function get_plugin_url( $path = '' ) {
$dir = rtrim( plugin_dir_url( __FILE__ ), '/' );
if ( !empty( $path ) && is_string( $path ) )
$dir .= '/' . ltrim( $path, '/' );
return $dir;
}
/**
* Initialize the plugin and its dependencies.
*
* Initialize the plugin and its dependencies.
*
* @since 1.0.0
* @access public
* @see __construct
* @internal Uses plugins_loaded action
*
*/
public function plugins_loaded() {
$GLOBALS[ 'pms_post_protected' ] = false;
$GLOBALS[ 'pms_session' ] = Postmatic_Social_Comments_Session::get_instance();
$GLOBALS[ 'postmatic-social' ] = new Postmatic_Social_Comments_Plugin( array( 'wordpress', 'gplus', 'twitter', 'facebook' ) );
add_filter( 'pre_comment_author_email', array( $this, 'twitter_author' ) );
//Add settings link to plugins screen
$prefix = is_multisite() ? 'network_admin_' : '';
add_action( $prefix . 'plugin_action_links_' . Postmatic_Social::get_plugin_basename(), array( $this, 'plugin_settings_link' ) );
}
/**
* Add Postmatic comment fields if Postmatic is active and has a key.
*
* @since 1.0.0
* @access public
* @see __construct
* @internal Uses prompt/core_loaded action
*
*/
public function postmatic_loaded() {
if ( Prompt_Core::$options->get( 'prompt_key' ) ) {
add_action( 'comment_form_after_fields', array( $this, 'comment_extra_fields' ) );
}
}
/**
* Outputs admin interface for sub-menu.
*
* Outputs admin interface for sub-menu.
*
* @since 1.0.0
* @access public
* @see __construct
* @internal Uses $prefix . "plugin_action_links_$plugin_file" action
* @return array Array of settings
*/
public function plugin_settings_link( $settings ) {
$admin_anchor = sprintf( '<a href="%s">%s</a>', esc_url( $this->get_url() ), esc_html__( 'Configure', 'postmatic-social' ) );
return array_merge( array( $admin_anchor ), $settings );
}
/**
* Return the URL to the admin panel page.
*
* Return the URL to the admin panel page.
*
* @since 1.0.0
* @access static
*
* @return string URL to the admin panel page.
*/
public static function get_url() {
$url = self::$url;
if ( empty( $url ) ) {
if ( is_multisite() ) {
$url = add_query_arg( array( 'page' => 'postmatic-social' ), network_admin_url( 'options-general.php' ) );
} else {
$url = add_query_arg( array( 'page' => 'postmatic-social' ), admin_url( 'options-general.php' ) );
}
self::$url = $url;
}
return $url;
}
public function twitter_author( $email ) {
if ( empty( $_POST ) || empty( $_COOKIE ) ) return $email;
if ( !isset( $_POST[ 'email' ] ) ) return $email;
if ( isset( $_COOKIE[ 'comment_author_email' . COOKIEHASH ] ) ) {
$email = $_COOKIE[ 'comment_author_email' . COOKIEHASH ];
return $email;
} else {
$comment_cookie_lifetime = apply_filters( 'comment_cookie_lifetime', 30000000 );
setcookie( 'comment_author_email_' . COOKIEHASH, $_POST[ 'email' ], time() + $comment_cookie_lifetime, COOKIEPATH, COOKIE_DOMAIN );
setcookie( 'pms_comment_author_email', $_POST[ 'email' ], time() + $comment_cookie_lifetime, COOKIEPATH, COOKIE_DOMAIN );
return $_POST[ 'email' ];
}
return $email;
}
public function comment_extra_fields() {
echo '<div class="comment-form-pms-extra">';
echo '<div class="pms-optin">';
printf( '<input type="checkbox" name="prompt_comment_subscribe" value="1" id="pms_comment_subscribe"> ' );
printf( '<label for="pms_comment_subscribe">%s</label>', esc_html__( 'Participate in this conversation via email', 'postmatic-social' ) );
echo '</div><!-- .pms-optin -->';
echo '<div class="pms-optin-form">';
esc_html_e( 'Please enter an e-mail address', 'postmatic-social' );
echo '<input type="text" name="pms-email" value="" id="pms-email" />';
echo '</div><!-- .pms-optin-form -->';
echo '</div><!-- .pms-opttin -->';
}
}
define( 'POSTMATIC_SOCIAL_SESSION_USER', 'user' );
//todo - Update this link
define( 'POSTMATIC_SOCIAL_HELP_URL', 'http://docs.gopostmatic.com/article/185-setup' );
require_once Postmatic_Social::get_plugin_dir( '/functions/Postmatic_Social_Comments_Session.php' );
require_once Postmatic_Social::get_plugin_dir( '/functions/Postmatic_Social_Comments_Plugin.php' );
Postmatic_Social::get_instance();