WP Facebook Auto Publish - Version 1.0

Version Description

Download this release

Release Info

Developer f1logic
Plugin Icon 128x128 WP Facebook Auto Publish
Version 1.0
Comparing to
See all releases

Version 1.0

admin/about.php ADDED
@@ -0,0 +1,231 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ ?>
3
+ <style>
4
+ </style>
5
+
6
+ <h1 style="visibility: visible;">Facebook Auto Publish (V <?php echo xyz_fbap_plugin_get_version(); ?>)</h1>
7
+
8
+ <div style="width: 99%">
9
+ <p style="text-align: justify">
10
+ Facebook Auto Publish automatically publishes posts from your blog to your Facebook pages. It allows you to filter posts based on post-types and categories.
11
+ Facebook Auto Publish is developed and maintained by <a href="http://xyzscripts.com">xyzscripts</a>.</p>
12
+
13
+
14
+
15
+ <p style="text-align: justify">
16
+ If you would like to have more features , please try <a
17
+ href="http://xyzscripts.com/wordpress-plugins/facebook-auto-publish/features"
18
+ target="_blank">XYZ Social Media Auto Publish</a> which is a premium version of this
19
+ plugin. We have included a quick comparison of the free and premium
20
+ plugins for your reference.
21
+ </p>
22
+ </div>
23
+ <table class="xyz-premium-comparison" cellspacing=0 style="width: 99%;">
24
+ <tr style="background-color: #EDEDED">
25
+ <td><h2>Feature group</h2></td>
26
+ <td><h2>Feature</h2></td>
27
+ <td><h2>FBAP Free</h2>
28
+ </td>
29
+ <td><h2>SMAP Premium</h2></td>
30
+ </tr>
31
+ <!-- Supported Media -->
32
+ <tr>
33
+ <td rowspan="5"><h4>Supported Media</h4></td>
34
+ <td>Facebook</td>
35
+ <td><img src="<?php echo plugins_url("images/tick.png",__FILE__);?>">
36
+ </td>
37
+ <td><img src="<?php echo plugins_url("images/tick.png",__FILE__);?>">
38
+ </td>
39
+ </tr>
40
+
41
+ <tr>
42
+ <td>Twitter</td>
43
+ <td><img src="<?php echo plugins_url("images/cross.png",__FILE__);?>">
44
+ </td>
45
+ <td><img src="<?php echo plugins_url("images/tick.png",__FILE__);?>">
46
+ </td>
47
+ </tr>
48
+ <tr>
49
+ <td>LinkedIn</td>
50
+ <td><img src="<?php echo plugins_url("images/cross.png",__FILE__);?>">
51
+ </td>
52
+ <td><img src="<?php echo plugins_url("images/tick.png",__FILE__);?>">
53
+ </td>
54
+ </tr>
55
+ <tr>
56
+ <td>Pinterest<span style="color: #FF8000;font-size: 14px;font-weight: bold;">*</span></td>
57
+ <td><img src="<?php echo plugins_url("images/cross.png",__FILE__);?>">
58
+ </td>
59
+ <td><img src="<?php echo plugins_url("images/tick.png",__FILE__);?>">
60
+ </td>
61
+ </tr>
62
+ <tr>
63
+ <td>Google Plus<span style="color: #FF8000;font-size: 14px;font-weight: bold;">*</span></td>
64
+ <td><img src="<?php echo plugins_url("images/cross.png",__FILE__);?>">
65
+ </td>
66
+ <td><img src="<?php echo plugins_url("images/tick.png",__FILE__);?>">
67
+ </td>
68
+ </tr>
69
+ <!-- Posting Options -->
70
+ <tr>
71
+ <td rowspan="15"><h4>Posting Options</h4></td>
72
+ <td>Publish to facebook profile/pages</td>
73
+ <td><img src="<?php echo plugins_url("images/tick.png",__FILE__);?>">
74
+ </td>
75
+ <td><img src="<?php echo plugins_url("images/tick.png",__FILE__);?>">
76
+ </td>
77
+ </tr>
78
+
79
+ <tr>
80
+ <td>Publish to twitter profile</td>
81
+ <td><img src="<?php echo plugins_url("images/cross.png",__FILE__);?>">
82
+ </td>
83
+ <td><img src="<?php echo plugins_url("images/tick.png",__FILE__);?>">
84
+ </td>
85
+ </tr>
86
+
87
+ <tr>
88
+ <td>Publish to linkedin profile</td>
89
+ <td><img src="<?php echo plugins_url("images/cross.png",__FILE__);?>">
90
+ </td>
91
+ <td><img src="<?php echo plugins_url("images/tick.png",__FILE__);?>">
92
+ </td>
93
+ </tr>
94
+
95
+ <tr>
96
+ <td>Publish to pinterest boards</td>
97
+ <td><img src="<?php echo plugins_url("images/cross.png",__FILE__);?>">
98
+ </td>
99
+ <td><img src="<?php echo plugins_url("images/tick.png",__FILE__);?>">
100
+ </td>
101
+ </tr>
102
+
103
+ <tr>
104
+ <td>Publish to google plus profile/pages</td>
105
+ <td><img src="<?php echo plugins_url("images/cross.png",__FILE__);?>">
106
+ </td>
107
+ <td><img src="<?php echo plugins_url("images/tick.png",__FILE__);?>">
108
+ </td>
109
+ </tr>
110
+ <tr>
111
+ <td>Publish images along with post content</td>
112
+ <td><img src="<?php echo plugins_url("images/tick.png",__FILE__);?>">
113
+ </td>
114
+ <td><img src="<?php echo plugins_url("images/tick.png",__FILE__);?>">
115
+ </td>
116
+ </tr>
117
+
118
+ <tr>
119
+ <td>Option to republish existing posts</td>
120
+ <td><img src="<?php echo plugins_url("images/cross.png",__FILE__);?>">
121
+ </td>
122
+ <td><img src="<?php echo plugins_url("images/tick.png",__FILE__);?>">
123
+ </td>
124
+ </tr>
125
+
126
+ <tr>
127
+ <td>Filter posts to publish based on categories</td>
128
+ <td><img src="<?php echo plugins_url("images/tick.png",__FILE__);?>">
129
+ </td>
130
+ <td><img src="<?php echo plugins_url("images/tick.png",__FILE__);?>">
131
+ </td>
132
+ </tr>
133
+
134
+ <tr>
135
+ <td>Filter posts to publish based on custom post types</td>
136
+ <td><img src="<?php echo plugins_url("images/tick.png",__FILE__);?>">
137
+ </td>
138
+ <td><img src="<?php echo plugins_url("images/tick.png",__FILE__);?>">
139
+ </td>
140
+ </tr>
141
+
142
+ <tr>
143
+ <td>Publish to multiple social media accounts</td>
144
+ <td><img src="<?php echo plugins_url("images/cross.png",__FILE__);?>">
145
+ </td>
146
+ <td><img src="<?php echo plugins_url("images/tick.png",__FILE__);?>">
147
+ </td>
148
+ </tr>
149
+
150
+ <tr>
151
+ <td>Seperate message formats for publishing to multiple social media accounts</td>
152
+ <td><img src="<?php echo plugins_url("images/cross.png",__FILE__);?>">
153
+ </td>
154
+ <td><img src="<?php echo plugins_url("images/tick.png",__FILE__);?>">
155
+ </td>
156
+ </tr>
157
+
158
+ <tr>
159
+ <td>Seperate image url for publishing to multiple social media accounts</td>
160
+ <td><img src="<?php echo plugins_url("images/cross.png",__FILE__);?>">
161
+ </td>
162
+ <td><img src="<?php echo plugins_url("images/tick.png",__FILE__);?>">
163
+ </td>
164
+ </tr>
165
+
166
+ <tr>
167
+ <td>Instantaneous post publishing</td>
168
+ <td><img src="<?php echo plugins_url("images/tick.png",__FILE__);?>">
169
+ </td>
170
+ <td><img src="<?php echo plugins_url("images/tick.png",__FILE__);?>">
171
+ </td>
172
+ </tr>
173
+ <tr>
174
+ <td>Scheduled post publishing using cron</td>
175
+ <td><img src="<?php echo plugins_url("images/cross.png",__FILE__);?>">
176
+ </td>
177
+ <td><img src="<?php echo plugins_url("images/tick.png",__FILE__);?>">
178
+ </td>
179
+ </tr>
180
+
181
+
182
+ <tr>
183
+ <td>Configurable auto publishing time interval</td>
184
+ <td><img src="<?php echo plugins_url("images/cross.png",__FILE__);?>">
185
+ </td>
186
+ <td><img src="<?php echo plugins_url("images/tick.png",__FILE__);?>">
187
+ </td>
188
+ </tr>
189
+
190
+
191
+ <!-- Publishing History -->
192
+ <tr>
193
+ <td rowspan="2"><h4>Publishing History</h4></td>
194
+ <td>View auto publish history</td>
195
+ <td><img src="<?php echo plugins_url("images/cross.png",__FILE__);?>">
196
+ </td>
197
+ <td><img src="<?php echo plugins_url("images/tick.png",__FILE__);?>">
198
+ </td>
199
+ </tr>
200
+ <tr>
201
+ <td>View auto publish error logs</td>
202
+ <td><img src="<?php echo plugins_url("images/cross.png",__FILE__);?>">
203
+ </td>
204
+ <td><img src="<?php echo plugins_url("images/tick.png",__FILE__);?>">
205
+ </td>
206
+ </tr>
207
+
208
+ <!-- Installation and Support -->
209
+ <tr>
210
+ <td rowspan="2"><h4>Installation and Support</h4></td>
211
+ <td>Free Installation</td>
212
+ <td><img src="<?php echo plugins_url("images/tick.png",__FILE__);?>">
213
+ </td>
214
+ <td><img src="<?php echo plugins_url("images/tick.png",__FILE__);?>">
215
+ </td>
216
+ </tr>
217
+ <tr>
218
+ <td>Privilege customer support</td>
219
+ <td><img src="<?php echo plugins_url("images/cross.png",__FILE__);?>">
220
+ </td>
221
+ <td><img src="<?php echo plugins_url("images/tick.png",__FILE__);?>">
222
+ </td>
223
+ </tr>
224
+
225
+ </table>
226
+ <br/>
227
+ <div style="clear: both;"></div>
228
+ <span style="color: #FF8000;font-size: 14px;font-weight: bold;"> * </span> Pinterest and Google Plus are added on experimental basis.
229
+ <?php
230
+
231
+ ?>
admin/ajax-backlink.php ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ add_action('wp_ajax_xyz_fbap_ajax_backlink', 'xyz_fbap_ajax_backlink_call');
4
+
5
+ function xyz_fbap_ajax_backlink_call() {
6
+
7
+
8
+ global $wpdb;
9
+
10
+ if($_POST){
11
+
12
+ update_option('xyz_credit_link','fbap');
13
+ }
14
+ die();
15
+ }
16
+
17
+
18
+ ?>
admin/authorization.php ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ $app_id = get_option('xyz_fbap_application_id');
4
+ $app_secret = get_option('xyz_fbap_application_secret');
5
+ $redirecturl=admin_url('admin.php?page=facebook-auto-publish-settings&auth=1');
6
+ $lnredirecturl=admin_url('admin.php?page=facebook-auto-publish-settings&auth=3');
7
+
8
+ $my_url=urlencode($redirecturl);
9
+
10
+ session_start();
11
+ $code="";
12
+ if(isset($_REQUEST['code']))
13
+ $code = $_REQUEST["code"];
14
+
15
+ if(isset($_POST['fb_auth']))
16
+ {
17
+
18
+ $xyz_fbap_session_state = md5(uniqid(rand(), TRUE));
19
+ setcookie("xyz_fbap_session_state",$xyz_fbap_session_state,"0","/");
20
+
21
+ $dialog_url = "https://www.facebook.com/dialog/oauth?client_id="
22
+ . $app_id . "&redirect_uri=" . $my_url . "&state="
23
+ . $xyz_fbap_session_state . "&scope=read_stream,publish_stream,offline_access,manage_pages";
24
+
25
+ header("Location: " . $dialog_url);
26
+ }
27
+
28
+
29
+ if(isset($_COOKIE['xyz_fbap_session_state']) && isset($_REQUEST['state']) && ($_COOKIE['xyz_fbap_session_state'] === $_REQUEST['state']) && get_option("xyz_fbap_af")==1) {
30
+
31
+ $token_url = "https://graph.facebook.com/oauth/access_token?"
32
+ . "client_id=" . $app_id . "&redirect_uri=" . $my_url
33
+ . "&client_secret=" . $app_secret . "&code=" . $code;
34
+
35
+ $params = null;$access_token="";
36
+ $response = wp_remote_get($token_url);
37
+
38
+ if(is_array($response))
39
+ {
40
+ if(isset($response['body']))
41
+ {
42
+ parse_str($response['body'], $params);
43
+ if(isset($params['access_token']))
44
+ $access_token = $params['access_token'];
45
+ }
46
+ }
47
+ if($access_token!="")
48
+ {
49
+ update_option('xyz_fbap_fb_token',$access_token);
50
+ update_option('xyz_fbap_af',0);
51
+ }
52
+ }
53
+ else {
54
+ //echo("The state does not match. You may be a victim of CSRF.");
55
+ }
56
+
57
+
58
+ ?>
admin/destruction.php ADDED
@@ -0,0 +1,53 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ function fbap_free_network_destroy($networkwide) {
4
+ global $wpdb;
5
+
6
+ if (function_exists('is_multisite') && is_multisite()) {
7
+ // check if it is a network activation - if so, run the activation function for each blog id
8
+ if ($networkwide) {
9
+ $old_blog = $wpdb->blogid;
10
+ // Get all blog ids
11
+ $blogids = $wpdb->get_col("SELECT blog_id FROM $wpdb->blogs");
12
+ foreach ($blogids as $blog_id) {
13
+ switch_to_blog($blog_id);
14
+ fbap_free_destroy();
15
+ }
16
+ switch_to_blog($old_blog);
17
+ return;
18
+ }
19
+ }
20
+ fbap_free_destroy();
21
+ }
22
+
23
+ function fbap_free_destroy()
24
+ {
25
+ global $wpdb;
26
+
27
+ if(get_option('xyz_credit_link')=="fbap")
28
+ {
29
+ update_option("xyz_credit_link", '0');
30
+ }
31
+
32
+ delete_option('xyz_fbap_application_id');
33
+ delete_option('xyz_fbap_application_secret');
34
+ delete_option('xyz_fbap_fb_id');
35
+ delete_option('xyz_fbap_message');
36
+ delete_option('xyz_fbap_po_method');
37
+ delete_option('xyz_fbap_post_permission');
38
+ delete_option('xyz_fbap_current_appln_token');
39
+ delete_option('xyz_fbap_af');
40
+ delete_option('xyz_fbap_pages_ids');
41
+
42
+ delete_option('xyz_fbap_free_version');
43
+
44
+ delete_option('xyz_fbap_include_pages');
45
+ delete_option('xyz_fbap_include_categories');
46
+ delete_option('xyz_fbap_include_customposttypes');
47
+
48
+ }
49
+
50
+ register_uninstall_hook(XYZ_FBAP_PLUGIN_FILE,'fbap_free_network_destroy');
51
+
52
+
53
+ ?>
admin/footer.php ADDED
@@ -0,0 +1,167 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ <div id="xyz-wp-fbap-premium">
3
+
4
+ <div style="float: left; padding: 0 5px">
5
+ <h2 style="vertical-align: middle;">
6
+ <a target="_blank"
7
+ href="http://xyzscripts.com/wordpress-plugins/social-media-auto-publish/features">Fully
8
+ Featured XYZ WP SMAP Premium Plugin</a> - Just 29 USD
9
+ </h2>
10
+ </div>
11
+ <div style="float: left; margin-top: 3px">
12
+ <a target="_blank"
13
+ href="http://xyzscripts.com/members/product/purchase/XYZWPSMPPRE"><img class="hoverImages"
14
+ src="<?php echo plugins_url("facebook-auto-publish/admin/images/orange_buynow.png"); ?>">
15
+ </a>
16
+ </div>
17
+ <div style="float: left; padding: 0 5px">
18
+ <h2 style="vertical-align: middle;text-shadow: 1px 1px 1px #686868">
19
+ ( <a href="<?php echo admin_url('admin.php?page=facebook-auto-publish-about');?>">Compare Features</a> )
20
+ </h2>
21
+ </div>
22
+ </div>
23
+
24
+
25
+ <div style="clear: both;"></div>
26
+
27
+
28
+ <p></p>
29
+
30
+ <div style="width: 100%">
31
+
32
+ <div class="xyz_feedback">
33
+
34
+
35
+ <a target="_blank" href="http://xyzscripts.com/donate/1" class="xyz_donate">Donate a dollar</a> ★
36
+ <a target="_blank" href="http://wordpress.org/support/view/plugin-reviews/facebook-auto-publish" class="xyz_star">Rate this plugin</a> ★
37
+ <a target="_blank" href="http://xyzscripts.com/support/" class="xyz_suggest">Suggestions</a> ★
38
+ <a target="_blank" href="http://facebook.com/xyzscripts" class="xyz_fbook">Like us on facebook</a> ★
39
+ <a target="_blank" href="http://twitter.com/xyzscripts" class="xyz_twitt">Follow us on twitter</a> ★
40
+ <a target="_blank" href="https://plus.google.com/101215320403235276710/" class="xyz_gplus">+1 us on Google+</a>
41
+
42
+
43
+ </div>
44
+
45
+ <p></p>
46
+
47
+ <div class="xyz_subscribe">
48
+
49
+ <script language="javascript">
50
+ function check_email(emailString)
51
+ {
52
+ var mailPattern = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
53
+ var matchArray = emailString.match(mailPattern);
54
+ if (emailString.length == 0)
55
+ return false;
56
+
57
+ if (matchArray == null) {
58
+ return false;
59
+ }else{
60
+ return true;
61
+ }
62
+ }
63
+
64
+
65
+ function verify_lists(form)
66
+ {
67
+
68
+ var total=0;
69
+ var checkBox=form['chk[]'];
70
+
71
+ if(checkBox.length){
72
+
73
+ for(var i=0;i<checkBox.length;i++){
74
+ checkBox[i].checked?total++:null;
75
+ }
76
+ }else{
77
+
78
+ checkBox.checked?total++:null;
79
+
80
+ }
81
+ if(total>0){
82
+ return true;
83
+ }else{
84
+ return false;
85
+ }
86
+
87
+ }
88
+
89
+ function verify_fields()
90
+ {
91
+
92
+ if(check_email(document.email_subscription.email.value) == false){
93
+ alert("Please check whether the email is correct.");
94
+ document.email_subscription.email.select();
95
+ return false;
96
+ }else if(verify_lists(document.email_subscription)==false){
97
+ alert("Select atleast one list.");
98
+ }
99
+ else{
100
+ document.email_subscription.submit();
101
+ }
102
+
103
+ }
104
+ </script>
105
+ <?php global $current_user; get_currentuserinfo(); ?>
106
+ <form action=http://xyzscripts.com/newsletter/index.php?page=list/subscribe method="post" name="email_subscription" id="email_subscription" >
107
+ <input type="hidden" name="fieldNameIds" value="1,">
108
+ <input type="hidden" name="redirActive" value="http://xyzscripts.com/subscription/pending/XYZWPSMPPRE">
109
+ <input type="hidden" name="redirPending" value="http://xyzscripts.com/subscription/active/XYZWPSMPPRE">
110
+ <input type="hidden" name="mode" value="1">
111
+
112
+ <b>Stay tuned to our updates :</b>
113
+ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
114
+
115
+ Name :
116
+ <input style="border: 1px solid #3fafe3; margin-right:10px;" type="text" name="field1" value="<?php
117
+ if ($current_user->user_firstname != "" || $current_user->user_lastname != "")
118
+ {
119
+ echo $current_user->user_firstname . " " . $current_user->user_lastname;
120
+ }
121
+ else if (strcasecmp($current_user->display_name, 'admin')!=0 && strcasecmp($current_user->display_name , "administrator")!=0 )
122
+ {
123
+ echo $current_user->display_name;
124
+ }
125
+ else if (strcasecmp($current_user->user_login ,"admin")!=0 && strcasecmp($current_user->user_login , "administrator")!=0 )
126
+ {
127
+ echo $current_user->user_login;
128
+ }
129
+ ?>" >
130
+
131
+ Email Address :
132
+ <input style="border: 1px solid #3fafe3;" name="email"
133
+ type="text" value="<?php echo $current_user->user_email; ?>" /><span style="color:#FF0000">*</span>
134
+
135
+ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
136
+ <input class="submit_fbap" type="submit" value="Subscribe" name="Submit" onclick="javascript: if(!verify_fields()) return false; " />
137
+
138
+ <input type="hidden" name="listName" value="7,1,"/>
139
+ </form>
140
+
141
+
142
+
143
+ </div>
144
+
145
+
146
+ <p></p>
147
+
148
+ <div style="padding-top: ;" class="xyz_plugins">
149
+ See Also :
150
+
151
+ <a target="_blank" href="http://wordpress.org/extend/plugins/lightbox-pop/">Lightbox Pop</a> ★
152
+ <a target="_blank" href="http://wordpress.org/extend/plugins/full-screen-popup/">Full Screen Popup</a> ★
153
+ <a target="_blank" href="http://wordpress.org/extend/plugins/popup-dialog-box/">Popup Dialog Box</a> ★
154
+ <a target="_blank" href="http://wordpress.org/extend/plugins/quick-bar/">Quick Bar</a> ★
155
+ <a target="_blank" href="http://wordpress.org/extend/plugins/quick-box-popup/">Quick Box Popup</a> ★
156
+ <a target="_blank" href="http://wordpress.org/extend/plugins/insert-html-snippet/">Insert HTML Snippet</a> ★
157
+ <a target="_blank" href="http://wordpress.org/extend/plugins/newsletter-manager/">Newsletter Manager</a>★
158
+ <a target="_blank" href="http://wordpress.org/extend/plugins/contact-form-manager/">Contact Form Manager</a>
159
+ </div>
160
+
161
+ <div style="padding-top: 10px;text-align: center;">
162
+ Powered by <a href="http://xyzscripts.com" target="_blank">XYZScripts</a>
163
+ </div>
164
+
165
+ <div style="clear: both;"></div>
166
+
167
+ </div>
admin/header.php ADDED
@@ -0,0 +1,100 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <div id="xyz-wp-fbap-premium">
2
+
3
+ <div style="float: left; padding: 0 5px">
4
+ <h2 style="vertical-align: middle;">
5
+ <a target="_blank"
6
+ href="http://xyzscripts.com/wordpress-plugins/social-media-auto-publish/features">Fully
7
+ Featured XYZ WP SMAP Premium Plugin</a> - Just 29 USD
8
+ </h2>
9
+ </div>
10
+ <div style="float: left; margin-top: 3px">
11
+ <a target="_blank"
12
+ href="http://xyzscripts.com/members/product/purchase/XYZWPSMPPRE"><img class="hoverImages"
13
+ src="<?php echo plugins_url("facebook-auto-publish/admin/images/orange_buynow.png"); ?>">
14
+ </a>
15
+ </div>
16
+ <div style="float: left; padding: 0 5px">
17
+ <h2 style="vertical-align: middle;text-shadow: 1px 1px 1px #686868">
18
+ ( <a href="<?php echo admin_url('admin.php?page=facebook-auto-publish-about');?>">Compare Features</a> )
19
+ </h2>
20
+ </div>
21
+ </div>
22
+
23
+
24
+ <?php
25
+ if($_POST && isset($_POST['xyz_credit_link']))
26
+ {
27
+
28
+ $xyz_credit_link=$_POST['xyz_credit_link'];
29
+
30
+ update_option('xyz_credit_link', $xyz_credit_link);
31
+ ?>
32
+ <div class="system_notice_area_style1" id="system_notice_area">
33
+ Settings updated successfully. &nbsp;&nbsp;&nbsp;<span id="system_notice_area_dismiss">Dismiss</span>
34
+ </div>
35
+ <?php
36
+ }?>
37
+
38
+
39
+ <?php
40
+
41
+ if(get_option('xyz_credit_link')=="0"){
42
+ ?>
43
+ <div style="float:left;background-color: #FFECB3;border-radius:5px;padding: 0px 5px;margin-top: 10px;border: 1px solid #E0AB1B" id="xyz_backlink_div">
44
+
45
+ Please do a favour by enabling backlink to our site. <a id="xyz_fbap_backlink" style="cursor: pointer;" >Okay, Enable</a>.
46
+ <script type="text/javascript">
47
+ jQuery(document).ready(function() {
48
+
49
+ jQuery('#xyz_fbap_backlink').click(function() {
50
+
51
+
52
+ var dataString = {
53
+ action: 'xyz_fbap_ajax_backlink',
54
+ enable: 1
55
+ };
56
+
57
+ jQuery.post(ajaxurl, dataString, function(response) {
58
+ jQuery("#xyz_backlink_div").html('Thank you for enabling backlink !');
59
+ jQuery("#xyz_backlink_div").css('background-color', '#D8E8DA');
60
+ jQuery("#xyz_backlink_div").css('border', '1px solid #0F801C');
61
+ });
62
+
63
+ });
64
+ });
65
+ </script>
66
+ </div>
67
+ <?php
68
+ }
69
+
70
+
71
+
72
+ ?>
73
+
74
+
75
+
76
+ <div style="margin-top: 10px">
77
+ <table style="float:right; ">
78
+ <tr>
79
+ <td style="float:right;">
80
+ <a title="Please help us to keep this plugin free forever by donating a dollar" class="xyz_fbap_link" style="margin-right:12px;" target="_blank" href="http://xyzscripts.com/donate/1">Donate</a>
81
+ </td>
82
+ <td style="float:right;">
83
+ <a class="xyz_fbap_link" target="_blank" href="http://kb.xyzscripts.com/wordpress-plugins/facebook-auto-publish/">FAQ</a> |
84
+ </td>
85
+ <td style="float:right;">
86
+ <a class="xyz_fbap_link" target="_blank" href="http://docs.xyzscripts.com/wordpress-plugins/facebook-auto-publish/">Readme</a> |
87
+ </td>
88
+ <td style="float:right;">
89
+ <a class="xyz_fbap_link" target="_blank" href="http://xyzscripts.com/wordpress-plugins/facebook-auto-publish/details">About</a> |
90
+ </td>
91
+ <td style="float:right;">
92
+ <a class="xyz_fbap_link" target="_blank" href="http://xyzscripts.com">XYZScripts</a> |
93
+ </td>
94
+
95
+ </tr>
96
+ </table>
97
+ </div>
98
+
99
+
100
+ <div style="clear: both"></div>
admin/images/cross.png ADDED
Binary file
admin/images/donate.png ADDED
Binary file
admin/images/facebook-logo.png ADDED
Binary file
admin/images/facebook.png ADDED
Binary file
admin/images/gplus.png ADDED
Binary file
admin/images/linkedin.png ADDED
Binary file
admin/images/orange_buynow.png ADDED
Binary file
admin/images/star.png ADDED
Binary file
admin/images/suggest.png ADDED
Binary file
admin/images/support.png ADDED
Binary file
admin/images/tick.png ADDED
Binary file
admin/images/twitter-logo.png ADDED
Binary file
admin/images/twitter.png ADDED
Binary file
admin/images/xyz_logo.png ADDED
Binary file
admin/install.php ADDED
@@ -0,0 +1,56 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ function fbap_free_network_install($networkwide) {
3
+ global $wpdb;
4
+
5
+ if (function_exists('is_multisite') && is_multisite()) {
6
+ // check if it is a network activation - if so, run the activation function for each blog id
7
+ if ($networkwide) {
8
+ $old_blog = $wpdb->blogid;
9
+ // Get all blog ids
10
+ $blogids = $wpdb->get_col("SELECT blog_id FROM $wpdb->blogs");
11
+ foreach ($blogids as $blog_id) {
12
+ switch_to_blog($blog_id);
13
+ fbap_install_free();
14
+ }
15
+ switch_to_blog($old_blog);
16
+ return;
17
+ }
18
+ }
19
+ fbap_install_free();
20
+ }
21
+
22
+ function fbap_install_free()
23
+ {
24
+
25
+ global $current_user;
26
+ get_currentuserinfo();
27
+ if(get_option('xyz_credit_link')=="")
28
+ {
29
+ add_option("xyz_credit_link", '0');
30
+ }
31
+
32
+ add_option('xyz_fbap_application_id','');
33
+ add_option('xyz_fbap_application_secret', '');
34
+ add_option('xyz_fbap_fb_id', '');
35
+ add_option('xyz_fbap_message', 'New post added at {BLOG_TITLE} - {POST_TITLE}');
36
+ add_option('xyz_fbap_po_method', '2');
37
+ add_option('xyz_fbap_post_permission', '1');
38
+ add_option('xyz_fbap_current_appln_token', '');
39
+ add_option('xyz_fbap_af', '1'); //authorization flag
40
+ add_option('xyz_fbap_pages_ids','-1');
41
+
42
+
43
+
44
+ $version=get_option('xyz_fbap_free_version');
45
+ $currentversion=xyz_fbap_plugin_get_version();
46
+ update_option('xyz_fbap_free_version', $currentversion);
47
+
48
+ add_option('xyz_fbap_include_pages', '0');
49
+ add_option('xyz_fbap_include_categories', 'All');
50
+ add_option('xyz_fbap_include_customposttypes', '');
51
+
52
+ }
53
+
54
+
55
+ register_activation_hook(XYZ_FBAP_PLUGIN_FILE,'fbap_free_network_install');
56
+ ?>
admin/menu.php ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ if ( is_admin() )
3
+ {
4
+
5
+ add_action('admin_menu', 'xyz_fbap_menu');
6
+ //add_action('admin_print_styles', 'xyz_fbap_admin_style');
7
+
8
+ wp_enqueue_script('jquery');
9
+ wp_register_script( 'xyz_notice_script', plugins_url('facebook-auto-publish/js/notice.js') );
10
+ wp_enqueue_script( 'xyz_notice_script' );
11
+
12
+ wp_register_style('xyz_fbap_style', plugins_url('facebook-auto-publish/admin/style.css'));
13
+ wp_enqueue_style('xyz_fbap_style');
14
+
15
+ }
16
+
17
+ function xyz_fbap_menu()
18
+ {
19
+ add_menu_page('Facebook Auto Publish - Manage settings', 'Facebook Auto Publish', 'manage_options', 'facebook-auto-publish-settings', 'xyz_fbap_settings');
20
+ $page=add_submenu_page('facebook-auto-publish-settings', 'Facebook Auto Publish - Manage settings', ' Settings', 'manage_options', 'facebook-auto-publish-settings' ,'xyz_fbap_settings'); // 8 for admin
21
+ add_submenu_page('facebook-auto-publish-settings', 'Facebook Auto Publish - About', 'About', 'manage_options', 'facebook-auto-publish-about' ,'xyz_fbap_about'); // 8 for admin
22
+ }
23
+
24
+
25
+ function xyz_fbap_settings()
26
+ {
27
+ $_POST = stripslashes_deep($_POST);
28
+ $_GET = stripslashes_deep($_GET);
29
+ $_POST = xyz_trim_deep($_POST);
30
+ $_GET = xyz_trim_deep($_GET);
31
+
32
+ require( dirname( __FILE__ ) . '/header.php' );
33
+ require( dirname( __FILE__ ) . '/settings.php' );
34
+ require( dirname( __FILE__ ) . '/footer.php' );
35
+ }
36
+
37
+
38
+
39
+ function xyz_fbap_about()
40
+ {
41
+ require( dirname( __FILE__ ) . '/header.php' );
42
+ require( dirname( __FILE__ ) . '/about.php' );
43
+ require( dirname( __FILE__ ) . '/footer.php' );
44
+ }
45
+
46
+ ?>
admin/metabox.php ADDED
@@ -0,0 +1,152 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ add_action( 'add_meta_boxes', 'xyz_fbap_add_custom_box' );
3
+ function xyz_fbap_add_custom_box()
4
+ {
5
+ $posttype="";
6
+ if(isset($_GET['post_type']))
7
+ $posttype=$_GET['post_type'];
8
+
9
+ if(isset($_GET['action']) && $_GET['action']=="edit")
10
+ {
11
+ $postid=$_GET['post'];
12
+ $get_post_meta=get_post_meta($postid,"xyz_fbap",true);
13
+ if($get_post_meta==1)
14
+ return ;
15
+ global $wpdb;
16
+ $table='posts';
17
+ $accountCount = $wpdb->query( 'SELECT * FROM '.$wpdb->prefix.$table.' WHERE id="'.$postid.'" and post_status!="draft" LIMIT 0,1' ) ;
18
+ if($accountCount>0)
19
+ return ;
20
+ }
21
+
22
+ if($posttype=="")
23
+ $posttype="post";
24
+
25
+ if ($posttype=="page")
26
+ {
27
+
28
+ $xyz_fbap_include_pages=get_option('xyz_fbap_include_pages');
29
+ if($xyz_fbap_include_pages==0)
30
+ return;
31
+ }
32
+ else if($posttype!="post")
33
+ {
34
+
35
+ $xyz_fbap_include_customposttypes=get_option('xyz_fbap_include_customposttypes');
36
+
37
+
38
+ $carr=explode(',', $xyz_fbap_include_customposttypes);
39
+ if(!in_array($posttype,$carr))
40
+ return;
41
+
42
+ }
43
+
44
+
45
+
46
+
47
+ if(get_option('xyz_fbap_af')==0 && get_option('xyz_fbap_fb_token')!="")
48
+ add_meta_box( "xyz_fbap", '<strong>Facebook Auto Publish - Post Options</strong>', 'xyz_fbap_addpostmetatags') ;
49
+ }
50
+
51
+ function xyz_fbap_addpostmetatags()
52
+ {
53
+ $imgpath= plugins_url()."/facebook-auto-publish/admin/images/";
54
+ $heimg=$imgpath."support.png";
55
+ ?>
56
+ <script>
57
+
58
+ function displaycheck_fbap()
59
+ {
60
+
61
+ var fcheckid=document.getElementById("xyz_fbap_post_permission").value;
62
+ if(fcheckid==1)
63
+ {
64
+ document.getElementById("fpabpmd").style.display='';
65
+ document.getElementById("fpabpmf").style.display='';
66
+ }
67
+ else
68
+ {
69
+ document.getElementById("fpabpmd").style.display='none';
70
+ document.getElementById("fpabpmf").style.display='none';
71
+ }
72
+
73
+
74
+ }
75
+
76
+
77
+ </script>
78
+ <script type="text/javascript">
79
+ function detdisplay_fbap(id)
80
+ {
81
+ document.getElementById(id).style.display='';
82
+ }
83
+ function dethide_fbap(id)
84
+ {
85
+ document.getElementById(id).style.display='none';
86
+ }
87
+
88
+
89
+ </script>
90
+ <table>
91
+
92
+ <tr valign="top">
93
+ <td>Enable auto publish post to my facebook account
94
+ </td>
95
+ <td><select id="xyz_fbap_post_permission" name="xyz_fbap_post_permission"
96
+ onchange="displaycheck_fbap()"><option value="0"
97
+ <?php if(get_option('xyz_fbap_post_prmission')==0) echo 'selected';?>>
98
+ No</option>
99
+ <option value="1"
100
+ <?php if(get_option('xyz_fbap_post_permission')==1) echo 'selected';?>>Yes</option>
101
+ </select>
102
+ </td>
103
+ </tr>
104
+ <tr valign="top" id="fpabpmd">
105
+ <td>Posting method
106
+ </td>
107
+ <td><select id="xyz_fbap_po_method" name="xyz_fbap_po_method">
108
+ <option value="3"
109
+ <?php if(get_option('xyz_fbap_po_method')==3) echo 'selected';?>>Simple text message</option>
110
+
111
+ <optgroup label="Text message with image">
112
+ <option value="4"
113
+ <?php if(get_option('xyz_fbap_po_method')==4) echo 'selected';?>>Upload image to app album</option>
114
+ <option value="5"
115
+ <?php if(get_option('xyz_fbap_po_method')==5) echo 'selected';?>>Upload image to timeline album</option>
116
+ </optgroup>
117
+
118
+ <optgroup label="Text message with attached link">
119
+ <option value="1"
120
+ <?php if(get_option('xyz_fbap_po_method')==1) echo 'selected';?>>Attach
121
+ your blog post</option>
122
+ <option value="2"
123
+ <?php if(get_option('xyz_fbap_po_method')==2) echo 'selected';?>>
124
+ Share a link to your blog post</option>
125
+ </optgroup>
126
+ </select>
127
+ </td>
128
+ </tr>
129
+ <tr valign="top" id="fpabpmf">
130
+ <td>Message format for posting <img src="<?php echo $heimg?>"
131
+ onmouseover="detdisplay_fbap('xyz_fbap')" onmouseout="dethide_fbap('xyz_fbap')">
132
+ <div id="xyz_fbap" class="informationdiv" style="display: none;">
133
+ {POST_TITLE} - Insert the title of your post.<br />{PERMALINK} -
134
+ Insert the URL where your post is displayed.<br />{POST_EXCERPT}
135
+ - Insert the excerpt of your post.<br />{POST_CONTENT} - Insert
136
+ the description of your post.<br />{BLOG_TITLE} - Insert the name
137
+ of your blog.<br />{USER_NICENAME} - Insert the nicename
138
+ of the author.
139
+ </div>
140
+ </td>
141
+ <td>
142
+ <textarea id="xyz_fbap_message" name="xyz_fbap_message"><?php echo esc_textarea(get_option('xyz_fbap_message'));?></textarea>
143
+ </td>
144
+ </tr>
145
+
146
+ </table>
147
+ <script type="text/javascript">
148
+ displaycheck_fbap();
149
+ </script>
150
+ <?php
151
+ }
152
+ ?>
admin/publish.php ADDED
@@ -0,0 +1,297 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ add_action('publish_post', 'xyz_fbap_link_publish');
4
+ add_action('publish_page', 'xyz_fbap_link_publish');
5
+
6
+
7
+
8
+ $xyz_fbap_include_customposttypes=get_option('xyz_fbap_include_customposttypes');
9
+ $carr=explode(',', $xyz_fbap_include_customposttypes);
10
+ foreach ($carr as $cstyps ) {
11
+ add_action('publish_'.$cstyps, 'xyz_fbap_link_publish');
12
+
13
+ }
14
+
15
+
16
+ function xyz_fbap_string_limit($string, $limit) {
17
+
18
+ $space=" ";$appendstr=" ...";
19
+ if(mb_strlen($string) <= $limit) return $string;
20
+ if(mb_strlen($appendstr) >= $limit) return '';
21
+ $string = mb_substr($string, 0, $limit-mb_strlen($appendstr));
22
+ $rpos = mb_strripos($string, $space);
23
+ if ($rpos===false)
24
+ return $string.$appendstr;
25
+ else
26
+ return mb_substr($string, 0, $rpos).$appendstr;
27
+ }
28
+
29
+ function xyz_fbap_getimage($post_ID,$description_org)
30
+ {
31
+ $attachmenturl="";
32
+ $post_thumbnail_id = get_post_thumbnail_id( $post_ID );
33
+ if($post_thumbnail_id!="")
34
+ {
35
+ $attachmenturl=wp_get_attachment_url($post_thumbnail_id);
36
+ $attachmentimage=wp_get_attachment_image_src( $post_thumbnail_id, full );
37
+
38
+ }
39
+ else {
40
+ $first_img = '';
41
+ preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $description_org, $matches);
42
+ if(isset($matches[1][0]))
43
+ $attachmenturl = $matches[1][0];
44
+
45
+
46
+ }
47
+ return $attachmenturl;
48
+ }
49
+ function xyz_fbap_link_publish($post_ID) {
50
+
51
+
52
+ $get_post_meta=get_post_meta($post_ID,"xyz_fbap",true);
53
+ if($get_post_meta!=1)
54
+ add_post_meta($post_ID, "xyz_fbap", "1");
55
+ else
56
+ return;
57
+ global $current_user;
58
+ get_currentuserinfo();
59
+
60
+ ////////////fb///////////
61
+ $appid=get_option('xyz_fbap_application_id');
62
+ $appsecret=get_option('xyz_fbap_application_secret');
63
+ $useracces_token=get_option('xyz_fbap_fb_token');
64
+
65
+
66
+ $message=get_option('xyz_fbap_message');
67
+ if(isset($_POST['xyz_fbap_message']))
68
+ $message=$_POST['xyz_fbap_message'];
69
+
70
+ $fbid=get_option('xyz_fbap_fb_id');
71
+
72
+ $posting_method=get_option('xyz_fbap_po_method');
73
+ if(isset($_POST['xyz_fbap_po_method']))
74
+ $posting_method=$_POST['xyz_fbap_po_method'];
75
+
76
+ $post_permissin=get_option('xyz_fbap_post_permission');
77
+ if(isset($_POST['xyz_fbap_post_permission']))
78
+ $post_permissin=$_POST['xyz_fbap_post_permission'];
79
+
80
+ $af=get_option('xyz_fbap_af');
81
+
82
+ //////////////////////////////
83
+
84
+ $postpp= get_post($post_ID);global $wpdb;
85
+ $entries0 = $wpdb->get_results( 'SELECT user_nicename FROM '.$wpdb->prefix.'users WHERE ID='.$postpp->post_author);
86
+
87
+ foreach( $entries0 as $entry ) {
88
+ $user_nicename=$entry->user_nicename;}
89
+
90
+ if ($postpp->post_status == 'publish')
91
+ {
92
+ $posttype=$postpp->post_type;
93
+
94
+ if ($posttype=="page")
95
+ {
96
+
97
+ $xyz_fbap_include_pages=get_option('xyz_fbap_include_pages');
98
+ if($xyz_fbap_include_pages==0)
99
+ return;
100
+ }
101
+
102
+ if($posttype=="post")
103
+ {
104
+ $xyz_fbap_include_categories=get_option('xyz_fbap_include_categories');
105
+ if($xyz_fbap_include_categories!="All")
106
+ {
107
+ $carr1=explode(',', $xyz_fbap_include_categories);
108
+
109
+ $defaults = array('fields' => 'ids');
110
+ $carr2=wp_get_post_categories( $post_ID, $defaults );
111
+ $retflag=1;
112
+ foreach ($carr2 as $key=>$catg_ids)
113
+ {
114
+ if(in_array($catg_ids, $carr1))
115
+ $retflag=0;
116
+ }
117
+
118
+
119
+ if($retflag==1)
120
+ return;
121
+ }
122
+ }
123
+
124
+ $link = get_permalink($postpp->ID);
125
+
126
+
127
+
128
+ $content = $postpp->post_content;apply_filters('the_content', $content);
129
+
130
+ $excerpt = $postpp->post_excerpt;apply_filters('the_excerpt', $excerpt);
131
+ if($excerpt=="")
132
+ {
133
+ if($content!="")
134
+ {
135
+ $content1=$content;
136
+ $content1=strip_tags($content1);
137
+ $content1=strip_shortcodes($content1);
138
+
139
+ $excerpt=implode(' ', array_slice(explode(' ', $content1), 0, 50));
140
+ }
141
+ }
142
+ else
143
+ {
144
+ $excerpt=strip_tags($excerpt);
145
+ $excerpt=strip_shortcodes($excerpt);
146
+ }
147
+ $description = $content;
148
+
149
+ $description_org=$description;
150
+ $attachmenturl=xyz_fbap_getimage($post_ID, $description_org);
151
+ if($attachmenturl!="")
152
+ $image_found=1;
153
+ else
154
+ $image_found=0;
155
+
156
+
157
+ $name = html_entity_decode(get_the_title($postpp->ID), ENT_QUOTES, get_bloginfo('charset'));
158
+ $caption = html_entity_decode(get_bloginfo('title'), ENT_QUOTES, get_bloginfo('charset'));
159
+ apply_filters('the_title', $name);
160
+
161
+ $name=strip_tags($name);
162
+ $name=strip_shortcodes($name);
163
+
164
+ $description=strip_tags($description);
165
+ $description=strip_shortcodes($description);
166
+
167
+
168
+ if($useracces_token!="" && $appsecret!="" && $appid!="" && $post_permissin==1)
169
+ {
170
+
171
+ $user_page_id=get_option('xyz_fbap_fb_numericid');
172
+
173
+ $xyz_fbap_pages_ids=get_option('xyz_fbap_pages_ids');
174
+ if($xyz_fbap_pages_ids=="")
175
+ $xyz_fbap_pages_ids=-1;
176
+
177
+ $xyz_fbap_pages_ids1=explode(",",$xyz_fbap_pages_ids);
178
+
179
+
180
+ foreach ($xyz_fbap_pages_ids1 as $key=>$value)
181
+ {
182
+ if($value!=-1)
183
+ {
184
+ $value1=explode("-",$value);
185
+ $acces_token=$value1[1];$page_id=$value1[0];
186
+ }
187
+ else
188
+ {
189
+ $acces_token=$useracces_token;$page_id=$user_page_id;
190
+ }
191
+
192
+
193
+ $fb=new FBAPFacebook();
194
+ $message1=str_replace('{POST_TITLE}', $name, $message);
195
+ $message2=str_replace('{BLOG_TITLE}', $caption,$message1);
196
+ $message3=str_replace('{PERMALINK}', $link, $message2);
197
+ $message4=str_replace('{POST_EXCERPT}', $excerpt, $message3);
198
+ $message5=str_replace('{POST_CONTENT}', $description, $message4);
199
+ $message5=str_replace('{USER_NICENAME}', $user_nicename, $message5);
200
+
201
+ $disp_type="feed";
202
+ if($posting_method==1) //attach
203
+ {
204
+ $attachment = array('message' => $message5,
205
+ 'access_token' => $acces_token,
206
+ 'link' => $link,
207
+ 'name' => $name,
208
+ 'caption' => $caption,
209
+ 'description' => $description,
210
+ 'actions' => array(array('name' => $name,
211
+ 'link' => $link))
212
+
213
+ );
214
+ }
215
+ else if($posting_method==2) //share link
216
+ {
217
+ $attachment = array('message' => $message5,
218
+ 'access_token' => $acces_token,
219
+ 'link' => $link,
220
+ 'name' => $name,
221
+ 'caption' => $caption,
222
+ 'description' => $description
223
+
224
+
225
+ );
226
+ }
227
+ else if($posting_method==3) //simple text message
228
+ {
229
+ //$message6=xyz_fbap_string_limit($message5, 900);
230
+ //$description_li=xyz_fbap_string_limit($description, 900);
231
+
232
+ $attachment = array('message' => $message5,
233
+ 'access_token' => $acces_token
234
+
235
+ );
236
+
237
+ }
238
+ else if($posting_method==4 || $posting_method==5) //text message with image 4 - app album, 5-timeline
239
+ {
240
+ //$message6=xyz_fbap_string_limit($message5, 900);
241
+ //$description_li=xyz_fbap_string_limit($description, 900);
242
+ if($attachmenturl!="")
243
+ {
244
+
245
+ if($posting_method==5)
246
+ {
247
+ try{
248
+ $albums = $fb->api("/$page_id/albums", "get", array('access_token' => $acces_token));
249
+ }
250
+ catch(Exception $e)
251
+ {
252
+ //echo $e->getmessage();
253
+ }
254
+ foreach ($albums["data"] as $album) {
255
+ if ($album["type"] == "wall") {
256
+ $timeline_album = $album; break;
257
+ }
258
+ }
259
+ if (isset($timeline_album) && isset($timeline_album["id"])) $page_id = $timeline_album["id"];
260
+ }
261
+
262
+
263
+ $disp_type="photos";
264
+ $attachment = array('message' => $message5,
265
+ 'access_token' => $acces_token,
266
+ 'url' => $attachmenturl
267
+
268
+ );
269
+ }
270
+ else
271
+ {
272
+ $attachment = array('message' => $message5,
273
+ 'access_token' => $acces_token
274
+
275
+ );
276
+ }
277
+
278
+ }
279
+ try{
280
+ $result = $fb->api('/'.$page_id.'/'.$disp_type.'/', 'post', $attachment);}
281
+ catch(Exception $e)
282
+ {
283
+ //echo $e->getmessage();
284
+ }
285
+
286
+ }
287
+
288
+
289
+
290
+ }
291
+
292
+ }
293
+
294
+
295
+ }
296
+
297
+ ?>
admin/settings.php ADDED
@@ -0,0 +1,620 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ global $current_user;
4
+ $auth_varble=0;
5
+ get_currentuserinfo();
6
+ $imgpath= plugins_url()."/facebook-auto-publish/admin/images/";
7
+ $heimg=$imgpath."support.png";
8
+ $ms1="";
9
+ $ms2="";
10
+ $ms3="";
11
+ $ms4="";
12
+ $redirecturl=admin_url('admin.php?page=facebook-auto-publish-settings&auth=1');
13
+
14
+
15
+ require( dirname( __FILE__ ) . '/authorization.php' );
16
+
17
+ $erf=0;
18
+ if(isset($_POST['fb']))
19
+ {
20
+
21
+ $ss=array();
22
+ if(isset($_POST['fbap_pages_list']))
23
+ $ss=$_POST['fbap_pages_list'];
24
+
25
+ $fbap_pages_list_ids="";
26
+
27
+
28
+ if($ss!="" && count($ss)>0)
29
+ {
30
+ for($i=0;$i<count($ss);$i++)
31
+ {
32
+ $fbap_pages_list_ids.=$ss[$i].",";
33
+ }
34
+
35
+ }
36
+ else
37
+ $fbap_pages_list_ids.=-1;
38
+
39
+ $fbap_pages_list_ids=rtrim($fbap_pages_list_ids,',');
40
+
41
+
42
+ update_option('xyz_fbap_pages_ids',$fbap_pages_list_ids);
43
+
44
+
45
+
46
+ $applidold=get_option('xyz_fbap_application_id');
47
+ $applsecretold=get_option('xyz_fbap_application_secret');
48
+ $fbidold=get_option('xyz_fbap_fb_id');
49
+
50
+ $posting_method=$_POST['xyz_fbap_po_method'];
51
+ $posting_permission=$_POST['xyz_fbap_post_permission'];
52
+ $appid=$_POST['xyz_fbap_application_id'];
53
+ $appsecret=$_POST['xyz_fbap_application_secret'];
54
+ $messagetopost=$_POST['xyz_fbap_message'];
55
+ $fbid=$_POST['xyz_fbap_fb_id'];
56
+ if($appid=="" && $posting_permission==1)
57
+ {
58
+ $ms1="Please fill facebook application id.";
59
+ $erf=1;
60
+ }
61
+ elseif($appsecret=="" && $posting_permission==1)
62
+ {
63
+ $ms2="Please fill facebook application secret.";
64
+ $erf=1;
65
+ }
66
+ elseif($fbid=="" && $posting_permission==1)
67
+ {
68
+ $ms3="Please fill facebook user id.";
69
+ $erf=1;
70
+ }
71
+ elseif($messagetopost=="" && $posting_permission==1)
72
+ {
73
+ $ms4="Please fill message format for posting.";
74
+ $erf=1;
75
+ }
76
+ else
77
+ {
78
+ $erf=0;
79
+ if($appid!=$applidold || $appsecret!=$applsecretold || $fbidold!=$fbid)
80
+ {
81
+ update_option('xyz_fbap_af',1);
82
+ update_option('xyz_fbap_fb_token','');
83
+ }
84
+ if($messagetopost=="")
85
+ {
86
+ $messagetopost="New post added at {BLOG_TITLE} - {POST_TITLE}";
87
+ }
88
+
89
+ update_option('xyz_fbap_application_id',$appid);
90
+ update_option('xyz_fbap_post_permission',$posting_permission);
91
+ update_option('xyz_fbap_application_secret',$appsecret);
92
+ update_option('xyz_fbap_fb_id',$fbid);
93
+ update_option('xyz_fbap_po_method',$posting_method);
94
+ update_option('xyz_fbap_message',$messagetopost);
95
+
96
+ $url = 'https://graph.facebook.com/'.$fbid;
97
+ $contentget=wp_remote_get($url);$page_id="";
98
+ if(is_array($contentget))
99
+ {
100
+ $result1=$contentget['body'];
101
+ $pagearray = json_decode($result1);
102
+ if(isset($pagearray->id))
103
+ $page_id=$pagearray->id;
104
+ }
105
+
106
+
107
+
108
+ update_option('xyz_fbap_fb_numericid',$page_id);
109
+
110
+ }
111
+ }
112
+
113
+
114
+
115
+ if(isset($_POST['fb']) && $erf==0)
116
+ {
117
+ ?>
118
+
119
+ <div class="system_notice_area_style1" id="system_notice_area">
120
+ Settings updated successfully. &nbsp;&nbsp;&nbsp;<span
121
+ id="system_notice_area_dismiss">Dismiss</span>
122
+ </div>
123
+ <?php }
124
+ if(isset($_GET['msg']) && $_GET['msg']==1)
125
+ {
126
+ ?>
127
+ <div class="system_notice_area_style0" id="system_notice_area">
128
+ Unable to authorize the linkedin application. Please check the details. &nbsp;&nbsp;&nbsp;<span
129
+ id="system_notice_area_dismiss">Dismiss</span>
130
+ </div>
131
+ <?php
132
+ }
133
+ if(isset($_POST['fb']) && $erf==1)
134
+ {
135
+ ?>
136
+ <div class="system_notice_area_style0" id="system_notice_area">
137
+ <?php
138
+ if(isset($_POST['fb']))
139
+ {
140
+ echo $ms1;echo $ms2;echo $ms3;echo $ms4;
141
+ }
142
+ ?>
143
+ &nbsp;&nbsp;&nbsp;<span id="system_notice_area_dismiss">Dismiss</span>
144
+ </div>
145
+ <?php } ?>
146
+ <script type="text/javascript">
147
+ function detdisplay(id)
148
+ {
149
+ document.getElementById(id).style.display='';
150
+ }
151
+ function dethide(id)
152
+ {
153
+ document.getElementById(id).style.display='none';
154
+ }
155
+
156
+ </script>
157
+
158
+ <div style="width: 100%">
159
+
160
+ <h2>
161
+ <img src="<?php echo plugins_url()?>/facebook-auto-publish/admin/images/facebook-logo.png" height="16px"> Facebook Settings
162
+ </h2>
163
+ <?php
164
+ $af=get_option('xyz_fbap_af');
165
+ $appid=esc_html(get_option('xyz_fbap_application_id'));
166
+ $appsecret=esc_html(get_option('xyz_fbap_application_secret'));
167
+ $fbid=esc_html(get_option('xyz_fbap_fb_id'));
168
+ $posting_method=get_option('xyz_fbap_po_method');
169
+ $posting_message=esc_textarea(get_option('xyz_fbap_message'));
170
+ if($af==1 && $appid!="" && $appsecret!="" && $fbid!="")
171
+ {
172
+ ?>
173
+ <span style="color: red;">Application needs authorisation</span> <br>
174
+ <form method="post">
175
+
176
+ <input type="submit" class="submit_fbap_new" name="fb_auth"
177
+ value="Authorize" /><br><br>
178
+
179
+ </form>
180
+ <?php }
181
+
182
+
183
+ if(isset($_GET['auth']) && $_GET['auth']==1 && get_option("xyz_fbap_fb_token")!="")
184
+ {
185
+ ?>
186
+
187
+ <span style="color: green;">Application is authorized, go posting.
188
+ </span><br>
189
+
190
+ <?php
191
+ }
192
+ ?>
193
+
194
+
195
+ <table class="widefat" style="width: 99%;background-color: #FFFBCC">
196
+ <tr>
197
+ <td id="bottomBorderNone">
198
+
199
+ <div>
200
+
201
+
202
+ <b>Note :</b> You have to create a Facebook application before filling the following details.
203
+ <b><a href="https://developers.facebook.com/apps" target="_blank">Click here</a></b> to create new Facebook application.
204
+ <br>In the application page in facebook, navigate to <b>Apps > Settings > Edit settings > Website > Site URL</b>. Set the site url as :
205
+ <span style="color: red;"><?php echo (is_ssl() ? 'https://' : 'http://' ) . $_SERVER['HTTP_HOST']; ?></span>
206
+ <br>For detailed step by step instructions <b><a href="http://docs.xyzscripts.com/wordpress-plugins/facebook-auto-publish/creating-facebook-application/" target="_blank">Click here</a></b>.
207
+ </div>
208
+
209
+ </td>
210
+ </tr>
211
+ </table>
212
+
213
+ <form method="post">
214
+ <input type="hidden" value="config">
215
+
216
+
217
+
218
+
219
+
220
+ <div style="font-weight: bold;padding: 3px;">All fields given below are mandatory</div>
221
+ <table class="widefat" style="width: 99%">
222
+ <tr valign="top">
223
+ <td width="50%">Application id
224
+ </td>
225
+ <td><input id="xyz_fbap_application_id"
226
+ name="xyz_fbap_application_id" type="text"
227
+ value="<?php if($ms1=="") {echo esc_html(get_option('xyz_fbap_application_id'));}?>" />
228
+ </td>
229
+ </tr>
230
+
231
+ <tr valign="top">
232
+ <td>Application secret<?php $apsecret=esc_html(get_option('xyz_fbap_application_secret'));?>
233
+
234
+ </td>
235
+ <td><input id="xyz_fbap_application_secret"
236
+ name="xyz_fbap_application_secret" type="text"
237
+ value="<?php if($ms2=="") {echo $apsecret; }?>" />
238
+ </td>
239
+ </tr>
240
+ <tr valign="top">
241
+ <td>Facebook user id
242
+ </td>
243
+ <td><input id="xyz_fbap_fb_id" name="xyz_fbap_fb_id" type="text"
244
+ value="<?php if($ms3=="") {echo esc_html(get_option('xyz_fbap_fb_id'));}?>" />
245
+ </td>
246
+ </tr>
247
+ <tr valign="top">
248
+ <td>Message format for posting <img src="<?php echo $heimg?>"
249
+ onmouseover="detdisplay('xyz_fb')" onmouseout="dethide('xyz_fb')">
250
+ <div id="xyz_fb" class="informationdiv" style="display: none;">
251
+ {POST_TITLE} - Insert the title of your post.<br />{PERMALINK} -
252
+ Insert the URL where your post is displayed.<br />{POST_EXCERPT}
253
+ - Insert the excerpt of your post.<br />{POST_CONTENT} - Insert
254
+ the description of your post.<br />{BLOG_TITLE} - Insert the name
255
+ of your blog.<br />{USER_NICENAME} - Insert the nicename
256
+ of the author.
257
+ </div></td>
258
+ <td><textarea id="xyz_fbap_message" name="xyz_fbap_message"><?php if($ms4==""){
259
+ echo esc_textarea(get_option('xyz_fbap_message'));}?></textarea>
260
+ </td>
261
+ </tr>
262
+ <tr valign="top">
263
+ <td>Posting method
264
+ </td>
265
+ <td>
266
+ <select id="xyz_fbap_po_method" name="xyz_fbap_po_method">
267
+ <option value="3"
268
+ <?php if(get_option('xyz_fbap_po_method')==3) echo 'selected';?>>Simple text message</option>
269
+
270
+ <optgroup label="Text message with image">
271
+ <option value="4"
272
+ <?php if(get_option('xyz_fbap_po_method')==4) echo 'selected';?>>Upload image to app album</option>
273
+ <option value="5"
274
+ <?php if(get_option('xyz_fbap_po_method')==5) echo 'selected';?>>Upload image to timeline album</option>
275
+ </optgroup>
276
+
277
+ <optgroup label="Text message with attached link">
278
+ <option value="1"
279
+ <?php if(get_option('xyz_fbap_po_method')==1) echo 'selected';?>>Attach
280
+ your blog post</option>
281
+ <option value="2"
282
+ <?php if(get_option('xyz_fbap_po_method')==2) echo 'selected';?>>
283
+ Share a link to your blog post</option>
284
+ </optgroup>
285
+ </select>
286
+ </td>
287
+ </tr>
288
+ <tr valign="top">
289
+ <td>Enable auto publish post to my facebook account
290
+ </td>
291
+ <td><select id="xyz_fbap_post_permission"
292
+ name="xyz_fbap_post_permission"><option value="0"
293
+ <?php if(get_option('xyz_fbap_post_prmission')==0) echo 'selected';?>>
294
+ No</option>
295
+ <option value="1"
296
+ <?php if(get_option('xyz_fbap_post_permission')==1) echo 'selected';?>>Yes</option>
297
+ </select>
298
+ </td>
299
+ </tr>
300
+ <?php
301
+
302
+ $xyz_acces_token=get_option('xyz_fbap_fb_token');
303
+ if($xyz_acces_token!=""){
304
+
305
+ $offset=0;$limit=100;$data=array();
306
+ $fbid=get_option('xyz_fbap_fb_id');
307
+ do
308
+ {
309
+ $result1="";$pagearray1="";
310
+ $pp=wp_remote_get("https://graph.facebook.com/$fbid/accounts?access_token=$xyz_acces_token&limit=$limit&offset=$offset");
311
+ if(is_array($pp))
312
+ {
313
+ $result1=$pp['body'];
314
+ $pagearray1 = json_decode($result1);
315
+ $data = array_merge($data, $pagearray1->data);
316
+ }
317
+ $offset += $limit;
318
+ }while(array_key_exists("next", $pagearray1->paging));
319
+
320
+
321
+
322
+
323
+ $count=count($data);
324
+
325
+ $fbap_pages_ids1=get_option('xyz_fbap_pages_ids');
326
+ $fbap_pages_ids0=array();
327
+ if($fbap_pages_ids1!="")
328
+ $fbap_pages_ids0=explode(",",$fbap_pages_ids1);
329
+
330
+ $fbap_pages_ids=array();
331
+ for($i=0;$i<count($fbap_pages_ids0);$i++)
332
+ {
333
+ if($fbap_pages_ids0[$i]!="-1")
334
+ $fbap_pages_ids[$i]=trim(substr($fbap_pages_ids0[$i],0,strpos($fbap_pages_ids0[$i],"-")));
335
+ else
336
+ $fbap_pages_ids[$i]=$fbap_pages_ids0[$i];
337
+ }
338
+
339
+ //$data[$i]->id."-".$data[$i]->access_token
340
+ ?>
341
+
342
+ <tr valign="top">
343
+ <td>Select facebook pages for auto publish
344
+ </td>
345
+ <td><select name="fbap_pages_list[]" multiple="multiple">
346
+ <option value="-1"
347
+ <?php if(in_array(-1, $fbap_pages_ids)) echo "selected" ?>>Profile Page</option>
348
+ <?php
349
+ for($i=0;$i<$count;$i++)
350
+ {
351
+ ?>
352
+ <option
353
+ value="<?php echo $data[$i]->id."-".$data[$i]->access_token;?>"
354
+ <?php
355
+
356
+
357
+ if(in_array($data[$i]->id, $fbap_pages_ids)) echo "selected" ?>>
358
+
359
+ <?php echo $data[$i]->name; ?>
360
+ </option>
361
+ <?php }?>
362
+ </select>
363
+ </td>
364
+ </tr>
365
+
366
+
367
+ <?php
368
+ }?>
369
+ <tr><td id="bottomBorderNone"></td>
370
+ <td id="bottomBorderNone"><div style="height: 50px;">
371
+ <input type="submit" class="submit_fbap_new"
372
+ style=" margin-top: 10px; "
373
+ name="fb" value="Save" /></div>
374
+ </td>
375
+ </tr>
376
+ </table>
377
+
378
+ </form>
379
+
380
+
381
+
382
+ <?php
383
+
384
+ if(isset($_POST['bsettngs']))
385
+ {
386
+
387
+
388
+ $xyz_fbap_include_pages=$_POST['xyz_fbap_include_pages'];
389
+
390
+ if($_POST['xyz_fbap_cat_all']=="All")
391
+ $fbap_category_ids=$_POST['xyz_fbap_cat_all'];//redio btn name
392
+ else
393
+ $fbap_category_ids=$_POST['xyz_fbap_sel_cat'];//dropdown
394
+
395
+ $xyz_customtypes="";
396
+
397
+ if(isset($_POST['post_types']))
398
+ $xyz_customtypes=$_POST['post_types'];
399
+
400
+
401
+ $fbap_customtype_ids="";
402
+
403
+ if($xyz_customtypes!="")
404
+ {
405
+ for($i=0;$i<count($xyz_customtypes);$i++)
406
+ {
407
+ $fbap_customtype_ids.=$xyz_customtypes[$i].",";
408
+ }
409
+
410
+ }
411
+ $fbap_customtype_ids=rtrim($fbap_customtype_ids,',');
412
+
413
+
414
+ update_option('xyz_fbap_include_pages',$xyz_fbap_include_pages);
415
+ update_option('xyz_fbap_include_categories',$fbap_category_ids);
416
+ update_option('xyz_fbap_include_customposttypes',$fbap_customtype_ids);
417
+
418
+ }
419
+
420
+ $xyz_credit_link=get_option('xyz_credit_link');
421
+ $xyz_fbap_include_pages=get_option('xyz_fbap_include_pages');
422
+ $xyz_fbap_include_categories=get_option('xyz_fbap_include_categories');
423
+ $xyz_fbap_include_customposttypes=get_option('xyz_fbap_include_customposttypes');
424
+
425
+
426
+ ?>
427
+ <h2>Basic Settings</h2>
428
+
429
+
430
+ <form method="post">
431
+
432
+ <table class="widefat" style="width: 99%">
433
+
434
+ <tr valign="top">
435
+
436
+ <td colspan="1" width="50%">Publish wordpress `pages` to social media
437
+ </td>
438
+ <td><select name="xyz_fbap_include_pages">
439
+
440
+ <option value="1"
441
+ <?php if($xyz_fbap_include_pages=='1') echo 'selected'; ?>>Yes</option>
442
+
443
+ <option value="0"
444
+ <?php if($xyz_fbap_include_pages!='1') echo 'selected'; ?>>No</option>
445
+ </select>
446
+ </td>
447
+ </tr>
448
+
449
+ <tr valign="top">
450
+
451
+ <td colspan="1">Select wordpress categories for auto publish
452
+ </td>
453
+ <td><input type="hidden"
454
+ value="<?php echo $xyz_fbap_include_categories;?>"
455
+ name="xyz_fbap_sel_cat" id="xyz_fbap_sel_cat"> <input type="radio"
456
+ name="xyz_fbap_cat_all" id="xyz_fbap_cat_all" value="All"
457
+ onchange="rd_cat_chn(1,-1)"
458
+ <?php if($xyz_fbap_include_categories=="All") echo "checked"?>>All<font
459
+ style="padding-left: 10px;"></font><input type="radio"
460
+ name="xyz_fbap_cat_all" id="xyz_fbap_cat_all" value=""
461
+ onchange="rd_cat_chn(1,1)"
462
+ <?php if($xyz_fbap_include_categories!="All") echo "checked"?>>Specific
463
+
464
+ <span id="cat_dropdown_span"><br /> <br /> <?php
465
+
466
+
467
+ $args = array(
468
+ 'show_option_all' => '',
469
+ 'show_option_none' => '',
470
+ 'orderby' => 'name',
471
+ 'order' => 'ASC',
472
+ 'show_last_update' => 0,
473
+ 'show_count' => 0,
474
+ 'hide_empty' => 0,
475
+ 'child_of' => 0,
476
+ 'exclude' => '',
477
+ 'echo' => 0,
478
+ 'selected' => '1 3',
479
+ 'hierarchical' => 1,
480
+ 'name' => 'xyz_fbap_catlist',
481
+ 'id' => 'xyz_fbap_catlist',
482
+ 'class' => 'postform',
483
+ 'depth' => 0,
484
+ 'tab_index' => 0,
485
+ 'taxonomy' => 'category',
486
+ 'hide_if_empty' => false );
487
+
488
+ if(count(get_categories($args))>0)
489
+ echo str_replace( "<select", "<select multiple onClick=setcat(this) style='width:200px;height:100px;border:1px solid #cccccc;'", wp_dropdown_categories($args));
490
+ else
491
+ echo "NIL";
492
+
493
+ ?><br /> <br /> </span>
494
+ </td>
495
+ </tr>
496
+
497
+
498
+ <tr valign="top">
499
+
500
+ <td colspan="1">Select wordpress custom post types for auto publish</td>
501
+ <td><?php
502
+
503
+ $args=array(
504
+ 'public' => true,
505
+ '_builtin' => false
506
+ );
507
+ $output = 'names'; // names or objects, note names is the default
508
+ $operator = 'and'; // 'and' or 'or'
509
+ $post_types=get_post_types($args,$output,$operator);
510
+
511
+ $ar1=explode(",",$xyz_fbap_include_customposttypes);
512
+ $cnt=count($post_types);
513
+ foreach ($post_types as $post_type ) {
514
+
515
+ echo '<input type="checkbox" name="post_types[]" value="'.$post_type.'" ';
516
+ if(in_array($post_type, $ar1))
517
+ {
518
+ echo 'checked="checked"/>';
519
+ }
520
+ else
521
+ echo '/>';
522
+
523
+ echo $post_type.'<br/>';
524
+
525
+ }
526
+ if($cnt==0)
527
+ echo 'NA';
528
+ ?>
529
+ </td>
530
+ </tr>
531
+
532
+
533
+
534
+ <tr valign="top" id="xyz_fbap">
535
+
536
+ <td colspan="1">Enable credit link to author
537
+ </td>
538
+ <td><select name="xyz_credit_link" id="xyz_fbap_credit_link">
539
+
540
+ <option value="fbap"
541
+ <?php if($xyz_credit_link=='fbap') echo 'selected'; ?>>Yes</option>
542
+
543
+ <option
544
+ value="<?php echo $xyz_credit_link!='fbap'?$xyz_credit_link:0;?>"
545
+ <?php if($xyz_credit_link!='fbap') echo 'selected'; ?>>No</option>
546
+ </select>
547
+ </td>
548
+ </tr>
549
+
550
+
551
+ <tr>
552
+
553
+ <td id="bottomBorderNone">
554
+
555
+
556
+ </td>
557
+
558
+
559
+ <td id="bottomBorderNone"><div style="height: 50px;">
560
+ <input type="submit" class="submit_fbap_new" style="margin-top: 10px;" value=" Update Settings" name="bsettngs" /></div></td>
561
+ </tr>
562
+
563
+ </table>
564
+ </form>
565
+
566
+
567
+ </div>
568
+
569
+ <script type="text/javascript">
570
+ //drpdisplay();
571
+ var catval='<?php echo $xyz_fbap_include_categories; ?>';
572
+ var custtypeval='<?php echo $xyz_fbap_include_customposttypes; ?>';
573
+ jQuery(document).ready(function() {
574
+ if(catval=="All")
575
+ jQuery("#cat_dropdown_span").hide();
576
+ else
577
+ jQuery("#cat_dropdown_span").show();
578
+
579
+ });
580
+
581
+ function setcat(obj)
582
+ {
583
+ var sel_str="";
584
+ for(k=0;k<obj.options.length;k++)
585
+ {
586
+ if(obj.options[k].selected)
587
+ sel_str+=obj.options[k].value+",";
588
+ }
589
+
590
+
591
+ var l = sel_str.length;
592
+ var lastChar = sel_str.substring(l-1, l);
593
+ if (lastChar == ",") {
594
+ sel_str = sel_str.substring(0, l-1);
595
+ }
596
+
597
+ document.getElementById('xyz_fbap_sel_cat').value=sel_str;
598
+
599
+ }
600
+
601
+ var d1='<?php echo $xyz_fbap_include_categories;?>';
602
+ splitText = d1.split(",");
603
+ jQuery.each(splitText, function(k,v) {
604
+ jQuery("#xyz_fbap_catlist").children("option[value="+v+"]").attr("selected","selected");
605
+ });
606
+
607
+ function rd_cat_chn(val,act)
608
+ {//xyz_fbap_cat_all xyz_fbap_cust_all
609
+ if(val==1)
610
+ {
611
+ if(act==-1)
612
+ jQuery("#cat_dropdown_span").hide();
613
+ else
614
+ jQuery("#cat_dropdown_span").show();
615
+ }
616
+
617
+ }
618
+ </script>
619
+ <?php
620
+ ?>
admin/style.css ADDED
@@ -0,0 +1,259 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #system_notice_area {
2
+ position: fixed;
3
+ margin-bottom:40px;
4
+ left:25%;
5
+ width:50%;
6
+ height:20px;
7
+ border-radius:5px;
8
+ -moz-border-radius:5px;
9
+ -webkit-border-radius:5px;
10
+ font-weight:bold;
11
+ display:none;
12
+ padding:3px;
13
+ color: #000000;
14
+ text-align: center;
15
+ top: 0px;
16
+ z-index: 100000;
17
+
18
+
19
+ }
20
+
21
+
22
+ .xyz_suggest,.xyz_star,.xyz_donate,.xyz_fbook,.xyz_support,.xyz_twitt,.xyz_gplus{
23
+ height:16px;
24
+ background-repeat: no-repeat;
25
+ background-position: left center;
26
+ padding-left: 15px;
27
+ text-decoration: none;
28
+
29
+ vertical-align: middle;
30
+ display: inline-block;
31
+
32
+ }
33
+
34
+ .xyz_suggest{
35
+
36
+ background-image: url('images/suggest.png');
37
+ }
38
+
39
+ .xyz_star{
40
+ background-image: url('images/star.png');
41
+ }
42
+
43
+ .xyz_donate{
44
+
45
+ background-image: url('images/donate.png');
46
+ }
47
+
48
+
49
+ .xyz_fbook{
50
+
51
+ background-image: url('images/facebook.png');
52
+ }
53
+ .xyz_support{
54
+
55
+ background-image: url('images/support.png');
56
+ }
57
+ .xyz_twitt{
58
+
59
+ background-image: url('images/twitter.png');
60
+ }
61
+ .xyz_gplus{
62
+
63
+ background-image: url('images/gplus.png');
64
+ }
65
+
66
+
67
+ #facebook-auto-publish .xyz_gplus{
68
+ margin-left: 3px;
69
+ }
70
+
71
+ #facebook-auto-publish .plugin-version-author-uri {
72
+
73
+ background-color: #F4F4F4;
74
+ min-height:16px;
75
+ border-radius:5px;
76
+ margin-bottom: 10px;
77
+ font-weight:bold;
78
+ padding: 5px;
79
+ color: #111111;
80
+
81
+ -webkit-box-shadow: 0 8px 6px -6px black;
82
+ -moz-box-shadow: 0 8px 6px -6px black;
83
+ box-shadow: 0 8px 6px -6px black;
84
+
85
+ }
86
+ #facebook-auto-publish{
87
+ background: #a9e8f5; /* Old browsers */
88
+
89
+ background: -moz-linear-gradient(top, #ffffff 0%, #a9e8f5 100%); /* FF3.6+ */
90
+ background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#ffffff), color-stop(100%,#a9e8f5)); /* Chrome,Safari4+ */
91
+ background: -webkit-linear-gradient(top, #ffffff 0%,#a9e8f5 100%); /* Chrome10+,Safari5.1+ */
92
+ background: -o-linear-gradient(top, #ffffff 0%,#a9e8f5 100%); /* Opera 11.10+ */
93
+ background: -ms-linear-gradient(top, #ffffff 0%,#a9e8f5 100%); /* IE10+ */
94
+ background: linear-gradient(top, #ffffff 0%,#a9e8f5 100%); /* W3C */
95
+
96
+
97
+ }
98
+ #facebook-auto-publish .plugin-version-author-uri a,
99
+ #facebook-auto-publish .plugin-version-author-uri a:link,
100
+ #facebook-auto-publish .plugin-version-author-uri a:hover,
101
+ #facebook-auto-publish .plugin-version-author-uri a:active,
102
+ #facebook-auto-publish .plugin-version-author-uri a:visited{
103
+
104
+
105
+ color: #111111;
106
+ text-decoration: none;
107
+
108
+ }
109
+ #facebook-auto-publish .plugin-version-author-uri a:hover{
110
+
111
+ color:#cc811a;
112
+ }
113
+ #facebook-auto-publish .plugin-title{
114
+
115
+ background-image: url('images/xyz_logo.png');
116
+ background-repeat: no-repeat;
117
+ background-position: left bottom;
118
+
119
+ }
120
+
121
+ .xyz-premium-comparison
122
+ {
123
+ width: 99%;
124
+ padding:0px;
125
+ border: 1px solid #CCCCCC;
126
+ border-radius:3px;
127
+ }
128
+ .xyz-premium-comparison td
129
+ {
130
+ padding: 1px;
131
+ border: 1px solid #CCCCCC;
132
+ height: 25px;
133
+ }
134
+
135
+ /* Buy Now - button bounce style*/
136
+ img.hoverImages {
137
+ margin-bottom:20px;
138
+ -webkit-transition: margin 0.2s ease-out;
139
+ -moz-transition: margin 0.2s ease-out;
140
+ -o-transition: margin 0.2s ease-out;
141
+ }
142
+ img.hoverImages:hover {
143
+ cursor:pointer;
144
+ margin-top: 5px;
145
+ }
146
+
147
+
148
+ #system_notice_area_dismiss{
149
+ color: #FFFFFF;
150
+ cursor: pointer;
151
+ }
152
+ .system_notice_area_style1 {
153
+ background: #00C348;
154
+ border: 1px solid green;
155
+ }
156
+
157
+ .system_notice_area_style0 {
158
+ background: #FA5A6A;
159
+ border: 1px solid brown;
160
+ }
161
+
162
+ .submit_fbap_new{
163
+ background:#25A6E1;
164
+ background:-moz-linear-gradient(top,#25A6E1 0%,#188BC0 100%);
165
+ background:-webkit-gradient(linear,left top,left bottom,color-stop(0%,#25A6E1),color-stop(100%,#188BC0));
166
+ background:-webkit-linear-gradient(top,#25A6E1 0%,#188BC0 100%);
167
+ background:-o-linear-gradient(top,#25A6E1 0%,#188BC0 100%);
168
+ background:-ms-linear-gradient(top,#25A6E1 0%,#188BC0 100%);
169
+ background:linear-gradient(top,#25A6E1 0%,#188BC0 100%);
170
+ filter:progid:DXImageTransform.Microsoft.gradient(startColorstr="#25A6E1",endColorstr="#188BC0",GradientType=0);
171
+ padding:1px 13px;
172
+ color:#ffffff !important;
173
+ border-radius: 4px !important; border: 1px solid #1A87B9 !important;
174
+ font-family:"Helvetica Neue",sans-serif;
175
+ font-size:13px;
176
+ cursor:pointer;height: 25px;
177
+ }
178
+
179
+ .informationdiv {
180
+ background: none repeat scroll 0 0 #9FDAEE;
181
+ border: 1px solid #209BD4;
182
+ border-radius: 5px 5px 5px 5px;
183
+ box-shadow: 5px 5px 5px rgba(0, 0, 0, 0.1);
184
+ float: left;
185
+ padding: 10px;
186
+ position: absolute;
187
+ z-index: 1200;
188
+ }
189
+ .xyz_feedback{
190
+ background: #CEEAF7; /* Old browsers */
191
+ border: 1px solid #64cfe8;
192
+ border-radius:3px;
193
+ width: 98%;
194
+ height:28px;
195
+ padding:5px 5px;
196
+ font-weight: bold;
197
+ line-height: 20px;
198
+
199
+ }
200
+
201
+
202
+ .xyz_feedback a{
203
+ text-decoration: none
204
+ }
205
+
206
+ .xyz_subscribe{
207
+ background: #bae598; /* Old browsers */
208
+ border: 1px solid #4d8a1d;
209
+ border-radius:3px;
210
+ width: 98%;
211
+ padding:5px 5px;
212
+ height:28px;
213
+
214
+ }
215
+ .xyz_subscribe td{
216
+ padding:0;
217
+ }
218
+
219
+ .xyz_plugins{
220
+ background: #EDEDED; /* Old browsers */
221
+ border: 1px solid #cccccc;
222
+ border-radius:3px;
223
+ width: 98%;
224
+ padding:5px 5px;
225
+ height:28px;
226
+ line-height: 25px;
227
+
228
+ }
229
+
230
+
231
+ .submit_fbap{
232
+ background:#25A6E1;
233
+ background:-moz-linear-gradient(top,#25A6E1 0%,#188BC0 100%);
234
+ background:-webkit-gradient(linear,left top,left bottom,color-stop(0%,#25A6E1),color-stop(100%,#188BC0));
235
+ background:-webkit-linear-gradient(top,#25A6E1 0%,#188BC0 100%);
236
+ background:-o-linear-gradient(top,#25A6E1 0%,#188BC0 100%);
237
+ background:-ms-linear-gradient(top,#25A6E1 0%,#188BC0 100%);
238
+ background:linear-gradient(top,#25A6E1 0%,#188BC0 100%);
239
+ filter:progid:DXImageTransform.Microsoft.gradient(startColorstr="#25A6E1",endColorstr="#188BC0",GradientType=0);
240
+ padding:1px 13px;
241
+ color:#ffffff;
242
+ font-family:"Helvetica Neue",sans-serif;
243
+ font-size:13px;
244
+ cursor:pointer;
245
+ color:#FFFFFF !important;border-radius:4px !important;
246
+ border:1px solid #1A87B9;height: 25px;
247
+ }
248
+ #xyz-wp-fbap-premium {
249
+ border: 1px solid #FCC328;
250
+ margin-bottom: 20px;
251
+ margin-top: 20px;
252
+ background-color: #FFF6D6;
253
+ height: 50px;
254
+ padding: 5px;
255
+ width: 98%;
256
+ border-radius:3px;
257
+ }
258
+ a.xyz_fbap_link:hover{text-decoration:underline;}
259
+ .xyz_fbap_link{text-decoration:none;font-weight: bold;margin-left:8px;}
api/base_facebook.php ADDED
@@ -0,0 +1,1425 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Copyright 2011 Facebook, Inc.
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may
6
+ * not use this file except in compliance with the License. You may obtain
7
+ * a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14
+ * License for the specific language governing permissions and limitations
15
+ * under the License.
16
+ */
17
+
18
+ if (!function_exists('curl_init')) {
19
+ throw new Exception('Facebook needs the CURL PHP extension.');
20
+ }
21
+ if (!function_exists('json_decode')) {
22
+ throw new Exception('Facebook needs the JSON PHP extension.');
23
+ }
24
+
25
+ /**
26
+ * Thrown when an API call returns an exception.
27
+ *
28
+ * @author Naitik Shah <naitik@facebook.com>
29
+ */
30
+ class FBAPFacebookApiException extends Exception
31
+ {
32
+ /**
33
+ * The result from the API server that represents the exception information.
34
+ */
35
+ protected $result;
36
+
37
+ /**
38
+ * Make a new API Exception with the given result.
39
+ *
40
+ * @param array $result The result from the API server
41
+ */
42
+ public function __construct($result) {
43
+ $this->result = $result;
44
+
45
+ $code = isset($result['error_code']) ? $result['error_code'] : 0;
46
+
47
+ if (isset($result['error_description'])) {
48
+ // OAuth 2.0 Draft 10 style
49
+ $msg = $result['error_description'];
50
+ } else if (isset($result['error']) && is_array($result['error'])) {
51
+ // OAuth 2.0 Draft 00 style
52
+ $msg = $result['error']['message'];
53
+ } else if (isset($result['error_msg'])) {
54
+ // Rest server style
55
+ $msg = $result['error_msg'];
56
+ } else {
57
+ $msg = 'Unknown Error. Check getResult()';
58
+ }
59
+
60
+ parent::__construct($msg, $code);
61
+ }
62
+
63
+ /**
64
+ * Return the associated result object returned by the API server.
65
+ *
66
+ * @return array The result from the API server
67
+ */
68
+ public function getResult() {
69
+ return $this->result;
70
+ }
71
+
72
+ /**
73
+ * Returns the associated type for the error. This will default to
74
+ * 'Exception' when a type is not available.
75
+ *
76
+ * @return string
77
+ */
78
+ public function getType() {
79
+ if (isset($this->result['error'])) {
80
+ $error = $this->result['error'];
81
+ if (is_string($error)) {
82
+ // OAuth 2.0 Draft 10 style
83
+ return $error;
84
+ } else if (is_array($error)) {
85
+ // OAuth 2.0 Draft 00 style
86
+ if (isset($error['type'])) {
87
+ return $error['type'];
88
+ }
89
+ }
90
+ }
91
+
92
+ return 'Exception';
93
+ }
94
+
95
+ /**
96
+ * To make debugging easier.
97
+ *
98
+ * @return string The string representation of the error
99
+ */
100
+ public function __toString() {
101
+ $str = $this->getType() . ': ';
102
+ if ($this->code != 0) {
103
+ $str .= $this->code . ': ';
104
+ }
105
+ return $str . $this->message;
106
+ }
107
+ }
108
+
109
+ /**
110
+ * Provides access to the Facebook Platform. This class provides
111
+ * a majority of the functionality needed, but the class is abstract
112
+ * because it is designed to be sub-classed. The subclass must
113
+ * implement the four abstract methods listed at the bottom of
114
+ * the file.
115
+ *
116
+ * @author Naitik Shah <naitik@facebook.com>
117
+ */
118
+ abstract class FBAPBaseFacebook
119
+ {
120
+ /**
121
+ * Version.
122
+ */
123
+ const VERSION = '3.2.0';
124
+
125
+ /**
126
+ * Signed Request Algorithm.
127
+ */
128
+ const SIGNED_REQUEST_ALGORITHM = 'HMAC-SHA256';
129
+
130
+ /**
131
+ * Default options for curl.
132
+ */
133
+ public static $CURL_OPTS = array(
134
+ CURLOPT_CONNECTTIMEOUT => 10,
135
+ CURLOPT_RETURNTRANSFER => true,
136
+ CURLOPT_TIMEOUT => 60,
137
+ CURLOPT_USERAGENT => 'facebook-php-3.2',
138
+ );
139
+
140
+ /**
141
+ * List of query parameters that get automatically dropped when rebuilding
142
+ * the current URL.
143
+ */
144
+ protected static $DROP_QUERY_PARAMS = array(
145
+ 'code',
146
+ 'state',
147
+ 'signed_request',
148
+ );
149
+
150
+ /**
151
+ * Maps aliases to Facebook domains.
152
+ */
153
+ public static $DOMAIN_MAP = array(
154
+ 'api' => 'https://api.facebook.com/',
155
+ 'api_video' => 'https://api-video.facebook.com/',
156
+ 'api_read' => 'https://api-read.facebook.com/',
157
+ 'graph' => 'https://graph.facebook.com/',
158
+ 'graph_video' => 'https://graph-video.facebook.com/',
159
+ 'www' => 'https://www.facebook.com/',
160
+ );
161
+
162
+ /**
163
+ * The Application ID.
164
+ *
165
+ * @var string
166
+ */
167
+ protected $appId;
168
+
169
+ /**
170
+ * The Application App Secret.
171
+ *
172
+ * @var string
173
+ */
174
+ protected $appSecret;
175
+
176
+ /**
177
+ * The ID of the Facebook user, or 0 if the user is logged out.
178
+ *
179
+ * @var integer
180
+ */
181
+ protected $user;
182
+
183
+ /**
184
+ * The data from the signed_request token.
185
+ */
186
+ protected $signedRequest;
187
+
188
+ /**
189
+ * A CSRF state variable to assist in the defense against CSRF attacks.
190
+ */
191
+ protected $state;
192
+
193
+ /**
194
+ * The OAuth access token received in exchange for a valid authorization
195
+ * code. null means the access token has yet to be determined.
196
+ *
197
+ * @var string
198
+ */
199
+ protected $accessToken = null;
200
+
201
+ /**
202
+ * Indicates if the CURL based @ syntax for file uploads is enabled.
203
+ *
204
+ * @var boolean
205
+ */
206
+ protected $fileUploadSupport = false;
207
+
208
+ /**
209
+ * Indicates if we trust HTTP_X_FORWARDED_* headers.
210
+ *
211
+ * @var boolean
212
+ */
213
+ protected $trustForwarded = false;
214
+
215
+ /**
216
+ * Initialize a Facebook Application.
217
+ *
218
+ * The configuration:
219
+ * - appId: the application ID
220
+ * - secret: the application secret
221
+ * - fileUpload: (optional) boolean indicating if file uploads are enabled
222
+ *
223
+ * @param array $config The application configuration
224
+ */
225
+ public function __construct($config) {
226
+ $this->setAppId($config['appId']);
227
+ $this->setAppSecret($config['secret']);
228
+ if (isset($config['fileUpload'])) {
229
+ $this->setFileUploadSupport($config['fileUpload']);
230
+ }
231
+ if (isset($config['trustForwarded']) && $config['trustForwarded']) {
232
+ $this->trustForwarded = true;
233
+ }
234
+ $state = $this->getPersistentData('state');
235
+ if (!empty($state)) {
236
+ $this->state = $state;
237
+ }
238
+ }
239
+
240
+ /**
241
+ * Set the Application ID.
242
+ *
243
+ * @param string $appId The Application ID
244
+ * @return FBAPBaseFacebook
245
+ */
246
+ public function setAppId($appId) {
247
+ $this->appId = $appId;
248
+ return $this;
249
+ }
250
+
251
+ /**
252
+ * Get the Application ID.
253
+ *
254
+ * @return string the Application ID
255
+ */
256
+ public function getAppId() {
257
+ return $this->appId;
258
+ }
259
+
260
+ /**
261
+ * Set the App Secret.
262
+ *
263
+ * @param string $apiSecret The App Secret
264
+ * @return FBAPBaseFacebook
265
+ * @deprecated
266
+ */
267
+ public function setApiSecret($apiSecret) {
268
+ $this->setAppSecret($apiSecret);
269
+ return $this;
270
+ }
271
+
272
+ /**
273
+ * Set the App Secret.
274
+ *
275
+ * @param string $appSecret The App Secret
276
+ * @return FBAPBaseFacebook
277
+ */
278
+ public function setAppSecret($appSecret) {
279
+ $this->appSecret = $appSecret;
280
+ return $this;
281
+ }
282
+
283
+ /**
284
+ * Get the App Secret.
285
+ *
286
+ * @return string the App Secret
287
+ * @deprecated
288
+ */
289
+ public function getApiSecret() {
290
+ return $this->getAppSecret();
291
+ }
292
+
293
+ /**
294
+ * Get the App Secret.
295
+ *
296
+ * @return string the App Secret
297
+ */
298
+ public function getAppSecret() {
299
+ return $this->appSecret;
300
+ }
301
+
302
+ /**
303
+ * Set the file upload support status.
304
+ *
305
+ * @param boolean $fileUploadSupport The file upload support status.
306
+ * @return FBAPBaseFacebook
307
+ */
308
+ public function setFileUploadSupport($fileUploadSupport) {
309
+ $this->fileUploadSupport = $fileUploadSupport;
310
+ return $this;
311
+ }
312
+
313
+ /**
314
+ * Get the file upload support status.
315
+ *
316
+ * @return boolean true if and only if the server supports file upload.
317
+ */
318
+ public function getFileUploadSupport() {
319
+ return $this->fileUploadSupport;
320
+ }
321
+
322
+ /**
323
+ * DEPRECATED! Please use getFileUploadSupport instead.
324
+ *
325
+ * Get the file upload support status.
326
+ *
327
+ * @return boolean true if and only if the server supports file upload.
328
+ */
329
+ public function useFileUploadSupport() {
330
+ return $this->getFileUploadSupport();
331
+ }
332
+
333
+ /**
334
+ * Sets the access token for api calls. Use this if you get
335
+ * your access token by other means and just want the SDK
336
+ * to use it.
337
+ *
338
+ * @param string $access_token an access token.
339
+ * @return FBAPBaseFacebook
340
+ */
341
+ public function setAccessToken($access_token) {
342
+ $this->accessToken = $access_token;
343
+ return $this;
344
+ }
345
+
346
+ /**
347
+ * Extend an access token, while removing the short-lived token that might
348
+ * have been generated via client-side flow. Thanks to http://bit.ly/b0Pt0H
349
+ * for the workaround.
350
+ */
351
+ public function setExtendedAccessToken() {
352
+ try {
353
+ // need to circumvent json_decode by calling _oauthRequest
354
+ // directly, since response isn't JSON format.
355
+ $access_token_response = $this->_oauthRequest(
356
+ $this->getUrl('graph', '/oauth/access_token'),
357
+ $params = array(
358
+ 'client_id' => $this->getAppId(),
359
+ 'client_secret' => $this->getAppSecret(),
360
+ 'grant_type' => 'fb_exchange_token',
361
+ 'fb_exchange_token' => $this->getAccessToken(),
362
+ )
363
+ );
364
+ }
365
+ catch (FBAPFacebookApiException $e) {
366
+ // most likely that user very recently revoked authorization.
367
+ // In any event, we don't have an access token, so say so.
368
+ return false;
369
+ }
370
+
371
+ if (empty($access_token_response)) {
372
+ return false;
373
+ }
374
+
375
+ $response_params = array();
376
+ parse_str($access_token_response, $response_params);
377
+
378
+ if (!isset($response_params['access_token'])) {
379
+ return false;
380
+ }
381
+
382
+ $this->destroySession();
383
+
384
+ $this->setPersistentData(
385
+ 'access_token', $response_params['access_token']
386
+ );
387
+ }
388
+
389
+ /**
390
+ * Determines the access token that should be used for API calls.
391
+ * The first time this is called, $this->accessToken is set equal
392
+ * to either a valid user access token, or it's set to the application
393
+ * access token if a valid user access token wasn't available. Subsequent
394
+ * calls return whatever the first call returned.
395
+ *
396
+ * @return string The access token
397
+ */
398
+ public function getAccessToken() {
399
+ if ($this->accessToken !== null) {
400
+ // we've done this already and cached it. Just return.
401
+ return $this->accessToken;
402
+ }
403
+
404
+ // first establish access token to be the application
405
+ // access token, in case we navigate to the /oauth/access_token
406
+ // endpoint, where SOME access token is required.
407
+ $this->setAccessToken($this->getApplicationAccessToken());
408
+ $user_access_token = $this->getUserAccessToken();
409
+ if ($user_access_token) {
410
+ $this->setAccessToken($user_access_token);
411
+ }
412
+
413
+ return $this->accessToken;
414
+ }
415
+
416
+ /**
417
+ * Determines and returns the user access token, first using
418
+ * the signed request if present, and then falling back on
419
+ * the authorization code if present. The intent is to
420
+ * return a valid user access token, or false if one is determined
421
+ * to not be available.
422
+ *
423
+ * @return string A valid user access token, or false if one
424
+ * could not be determined.
425
+ */
426
+ protected function getUserAccessToken() {
427
+ // first, consider a signed request if it's supplied.
428
+ // if there is a signed request, then it alone determines
429
+ // the access token.
430
+ $signed_request = $this->getSignedRequest();
431
+ if ($signed_request) {
432
+ // apps.facebook.com hands the access_token in the signed_request
433
+ if (array_key_exists('oauth_token', $signed_request)) {
434
+ $access_token = $signed_request['oauth_token'];
435
+ $this->setPersistentData('access_token', $access_token);
436
+ return $access_token;
437
+ }
438
+
439
+ // the JS SDK puts a code in with the redirect_uri of ''
440
+ if (array_key_exists('code', $signed_request)) {
441
+ $code = $signed_request['code'];
442
+ $access_token = $this->getAccessTokenFromCode($code, '');
443
+ if ($access_token) {
444
+ $this->setPersistentData('code', $code);
445
+ $this->setPersistentData('access_token', $access_token);
446
+ return $access_token;
447
+ }
448
+ }
449
+
450
+ // signed request states there's no access token, so anything
451
+ // stored should be cleared.
452
+ $this->clearAllPersistentData();
453
+ return false; // respect the signed request's data, even
454
+ // if there's an authorization code or something else
455
+ }
456
+
457
+ $code = $this->getCode();
458
+ if ($code && $code != $this->getPersistentData('code')) {
459
+ $access_token = $this->getAccessTokenFromCode($code);
460
+ if ($access_token) {
461
+ $this->setPersistentData('code', $code);
462
+ $this->setPersistentData('access_token', $access_token);
463
+ return $access_token;
464
+ }
465
+
466
+ // code was bogus, so everything based on it should be invalidated.
467
+ $this->clearAllPersistentData();
468
+ return false;
469
+ }
470
+
471
+ // as a fallback, just return whatever is in the persistent
472
+ // store, knowing nothing explicit (signed request, authorization
473
+ // code, etc.) was present to shadow it (or we saw a code in $_REQUEST,
474
+ // but it's the same as what's in the persistent store)
475
+ return $this->getPersistentData('access_token');
476
+ }
477
+
478
+ /**
479
+ * Retrieve the signed request, either from a request parameter or,
480
+ * if not present, from a cookie.
481
+ *
482
+ * @return string the signed request, if available, or null otherwise.
483
+ */
484
+ public function getSignedRequest() {
485
+ if (!$this->signedRequest) {
486
+ if (isset($_REQUEST['signed_request'])) {
487
+ $this->signedRequest = $this->parseSignedRequest(
488
+ $_REQUEST['signed_request']);
489
+ } else if (isset($_COOKIE[$this->getSignedRequestCookieName()])) {
490
+ $this->signedRequest = $this->parseSignedRequest(
491
+ $_COOKIE[$this->getSignedRequestCookieName()]);
492
+ }
493
+ }
494
+ return $this->signedRequest;
495
+ }
496
+
497
+ /**
498
+ * Get the UID of the connected user, or 0
499
+ * if the Facebook user is not connected.
500
+ *
501
+ * @return string the UID if available.
502
+ */
503
+ public function getUser() {
504
+ if ($this->user !== null) {
505
+ // we've already determined this and cached the value.
506
+ return $this->user;
507
+ }
508
+
509
+ return $this->user = $this->getUserFromAvailableData();
510
+ }
511
+
512
+ /**
513
+ * Determines the connected user by first examining any signed
514
+ * requests, then considering an authorization code, and then
515
+ * falling back to any persistent store storing the user.
516
+ *
517
+ * @return integer The id of the connected Facebook user,
518
+ * or 0 if no such user exists.
519
+ */
520
+ protected function getUserFromAvailableData() {
521
+ // if a signed request is supplied, then it solely determines
522
+ // who the user is.
523
+ $signed_request = $this->getSignedRequest();
524
+ if ($signed_request) {
525
+ if (array_key_exists('user_id', $signed_request)) {
526
+ $user = $signed_request['user_id'];
527
+ $this->setPersistentData('user_id', $signed_request['user_id']);
528
+ return $user;
529
+ }
530
+
531
+ // if the signed request didn't present a user id, then invalidate
532
+ // all entries in any persistent store.
533
+ $this->clearAllPersistentData();
534
+ return 0;
535
+ }
536
+
537
+ $user = $this->getPersistentData('user_id', $default = 0);
538
+ $persisted_access_token = $this->getPersistentData('access_token');
539
+
540
+ // use access_token to fetch user id if we have a user access_token, or if
541
+ // the cached access token has changed.
542
+ $access_token = $this->getAccessToken();
543
+ if ($access_token &&
544
+ $access_token != $this->getApplicationAccessToken() &&
545
+ !($user && $persisted_access_token == $access_token)) {
546
+ $user = $this->getUserFromAccessToken();
547
+ if ($user) {
548
+ $this->setPersistentData('user_id', $user);
549
+ } else {
550
+ $this->clearAllPersistentData();
551
+ }
552
+ }
553
+
554
+ return $user;
555
+ }
556
+
557
+ /**
558
+ * Get a Login URL for use with redirects. By default, full page redirect is
559
+ * assumed. If you are using the generated URL with a window.open() call in
560
+ * JavaScript, you can pass in display=popup as part of the $params.
561
+ *
562
+ * The parameters:
563
+ * - redirect_uri: the url to go to after a successful login
564
+ * - scope: comma separated list of requested extended perms
565
+ *
566
+ * @param array $params Provide custom parameters
567
+ * @return string The URL for the login flow
568
+ */
569
+ public function getLoginUrl($params=array()) {
570
+ $this->establishCSRFTokenState();
571
+ $currentUrl = $this->getCurrentUrl();
572
+
573
+ // if 'scope' is passed as an array, convert to comma separated list
574
+ $scopeParams = isset($params['scope']) ? $params['scope'] : null;
575
+ if ($scopeParams && is_array($scopeParams)) {
576
+ $params['scope'] = implode(',', $scopeParams);
577
+ }
578
+
579
+ return $this->getUrl(
580
+ 'www',
581
+ 'dialog/oauth',
582
+ array_merge(array(
583
+ 'client_id' => $this->getAppId(),
584
+ 'redirect_uri' => $currentUrl, // possibly overwritten
585
+ 'state' => $this->state),
586
+ $params));
587
+ }
588
+
589
+ /**
590
+ * Get a Logout URL suitable for use with redirects.
591
+ *
592
+ * The parameters:
593
+ * - next: the url to go to after a successful logout
594
+ *
595
+ * @param array $params Provide custom parameters
596
+ * @return string The URL for the logout flow
597
+ */
598
+ public function getLogoutUrl($params=array()) {
599
+ return $this->getUrl(
600
+ 'www',
601
+ 'logout.php',
602
+ array_merge(array(
603
+ 'next' => $this->getCurrentUrl(),
604
+ 'access_token' => $this->getUserAccessToken(),
605
+ ), $params)
606
+ );
607
+ }
608
+
609
+ /**
610
+ * Get a login status URL to fetch the status from Facebook.
611
+ *
612
+ * The parameters:
613
+ * - ok_session: the URL to go to if a session is found
614
+ * - no_session: the URL to go to if the user is not connected
615
+ * - no_user: the URL to go to if the user is not signed into facebook
616
+ *
617
+ * @param array $params Provide custom parameters
618
+ * @return string The URL for the logout flow
619
+ */
620
+ public function getLoginStatusUrl($params=array()) {
621
+ return $this->getUrl(
622
+ 'www',
623
+ 'extern/login_status.php',
624
+ array_merge(array(
625
+ 'api_key' => $this->getAppId(),
626
+ 'no_session' => $this->getCurrentUrl(),
627
+ 'no_user' => $this->getCurrentUrl(),
628
+ 'ok_session' => $this->getCurrentUrl(),
629
+ 'session_version' => 3,
630
+ ), $params)
631
+ );
632
+ }
633
+
634
+ /**
635
+ * Make an API call.
636
+ *
637
+ * @return mixed The decoded response
638
+ */
639
+ public function api(/* polymorphic */) {
640
+ $args = func_get_args();
641
+ if (is_array($args[0])) {
642
+ return $this->_restserver($args[0]);
643
+ } else {
644
+ return call_user_func_array(array($this, '_graph'), $args);
645
+ }
646
+ }
647
+
648
+ /**
649
+ * Constructs and returns the name of the cookie that
650
+ * potentially houses the signed request for the app user.
651
+ * The cookie is not set by the FBAPBaseFacebook class, but
652
+ * it may be set by the JavaScript SDK.
653
+ *
654
+ * @return string the name of the cookie that would house
655
+ * the signed request value.
656
+ */
657
+ protected function getSignedRequestCookieName() {
658
+ return 'fbsr_'.$this->getAppId();
659
+ }
660
+
661
+ /**
662
+ * Constructs and returns the name of the coookie that potentially contain
663
+ * metadata. The cookie is not set by the FBAPBaseFacebook class, but it may be
664
+ * set by the JavaScript SDK.
665
+ *
666
+ * @return string the name of the cookie that would house metadata.
667
+ */
668
+ protected function getMetadataCookieName() {
669
+ return 'fbm_'.$this->getAppId();
670
+ }
671
+
672
+ /**
673
+ * Get the authorization code from the query parameters, if it exists,
674
+ * and otherwise return false to signal no authorization code was
675
+ * discoverable.
676
+ *
677
+ * @return mixed The authorization code, or false if the authorization
678
+ * code could not be determined.
679
+ */
680
+ protected function getCode() {
681
+ if (isset($_REQUEST['code'])) {
682
+ if ($this->state !== null &&
683
+ isset($_REQUEST['state']) &&
684
+ $this->state === $_REQUEST['state']) {
685
+
686
+ // CSRF state has done its job, so clear it
687
+ $this->state = null;
688
+ $this->clearPersistentData('state');
689
+ return $_REQUEST['code'];
690
+ } else {
691
+ self::errorLog('CSRF state token does not match one provided.');
692
+ return false;
693
+ }
694
+ }
695
+
696
+ return false;
697
+ }
698
+
699
+ /**
700
+ * Retrieves the UID with the understanding that
701
+ * $this->accessToken has already been set and is
702
+ * seemingly legitimate. It relies on Facebook's Graph API
703
+ * to retrieve user information and then extract
704
+ * the user ID.
705
+ *
706
+ * @return integer Returns the UID of the Facebook user, or 0
707
+ * if the Facebook user could not be determined.
708
+ */
709
+ protected function getUserFromAccessToken() {
710
+ try {
711
+ $user_info = $this->api('/me');
712
+ return $user_info['id'];
713
+ } catch (FBAPFacebookApiException $e) {
714
+ return 0;
715
+ }
716
+ }
717
+
718
+ /**
719
+ * Returns the access token that should be used for logged out
720
+ * users when no authorization code is available.
721
+ *
722
+ * @return string The application access token, useful for gathering
723
+ * public information about users and applications.
724
+ */
725
+ protected function getApplicationAccessToken() {
726
+ return $this->appId.'|'.$this->appSecret;
727
+ }
728
+
729
+ /**
730
+ * Lays down a CSRF state token for this process.
731
+ *
732
+ * @return void
733
+ */
734
+ protected function establishCSRFTokenState() {
735
+ if ($this->state === null) {
736
+ $this->state = md5(uniqid(mt_rand(), true));
737
+ $this->setPersistentData('state', $this->state);
738
+ }
739
+ }
740
+
741
+ /**
742
+ * Retrieves an access token for the given authorization code
743
+ * (previously generated from www.facebook.com on behalf of
744
+ * a specific user). The authorization code is sent to graph.facebook.com
745
+ * and a legitimate access token is generated provided the access token
746
+ * and the user for which it was generated all match, and the user is
747
+ * either logged in to Facebook or has granted an offline access permission.
748
+ *
749
+ * @param string $code An authorization code.
750
+ * @return mixed An access token exchanged for the authorization code, or
751
+ * false if an access token could not be generated.
752
+ */
753
+ protected function getAccessTokenFromCode($code, $redirect_uri = null) {
754
+ if (empty($code)) {
755
+ return false;
756
+ }
757
+
758
+ if ($redirect_uri === null) {
759
+ $redirect_uri = $this->getCurrentUrl();
760
+ }
761
+
762
+ try {
763
+ // need to circumvent json_decode by calling _oauthRequest
764
+ // directly, since response isn't JSON format.
765
+ $access_token_response =
766
+ $this->_oauthRequest(
767
+ $this->getUrl('graph', '/oauth/access_token'),
768
+ $params = array('client_id' => $this->getAppId(),
769
+ 'client_secret' => $this->getAppSecret(),
770
+ 'redirect_uri' => $redirect_uri,
771
+ 'code' => $code));
772
+ } catch (FBAPFacebookApiException $e) {
773
+ // most likely that user very recently revoked authorization.
774
+ // In any event, we don't have an access token, so say so.
775
+ return false;
776
+ }
777
+
778
+ if (empty($access_token_response)) {
779
+ return false;
780
+ }
781
+
782
+ $response_params = array();
783
+ parse_str($access_token_response, $response_params);
784
+ if (!isset($response_params['access_token'])) {
785
+ return false;
786
+ }
787
+
788
+ return $response_params['access_token'];
789
+ }
790
+
791
+ /**
792
+ * Invoke the old restserver.php endpoint.
793
+ *
794
+ * @param array $params Method call object
795
+ *
796
+ * @return mixed The decoded response object
797
+ * @throws FBAPFacebookApiException
798
+ */
799
+ protected function _restserver($params) {
800
+ // generic application level parameters
801
+ $params['api_key'] = $this->getAppId();
802
+ $params['format'] = 'json-strings';
803
+
804
+ $result = json_decode($this->_oauthRequest(
805
+ $this->getApiUrl($params['method']),
806
+ $params
807
+ ), true);
808
+
809
+ // results are returned, errors are thrown
810
+ if (is_array($result) && isset($result['error_code'])) {
811
+ $this->throwAPIException($result);
812
+ // @codeCoverageIgnoreStart
813
+ }
814
+ // @codeCoverageIgnoreEnd
815
+
816
+ $method = strtolower($params['method']);
817
+ if ($method === 'auth.expiresession' ||
818
+ $method === 'auth.revokeauthorization') {
819
+ $this->destroySession();
820
+ }
821
+
822
+ return $result;
823
+ }
824
+
825
+ /**
826
+ * Return true if this is video post.
827
+ *
828
+ * @param string $path The path
829
+ * @param string $method The http method (default 'GET')
830
+ *
831
+ * @return boolean true if this is video post
832
+ */
833
+ protected function isVideoPost($path, $method = 'GET') {
834
+ if ($method == 'POST' && preg_match("/^(\/)(.+)(\/)(videos)$/", $path)) {
835
+ return true;
836
+ }
837
+ return false;
838
+ }
839
+
840
+ /**
841
+ * Invoke the Graph API.
842
+ *
843
+ * @param string $path The path (required)
844
+ * @param string $method The http method (default 'GET')
845
+ * @param array $params The query/post data
846
+ *
847
+ * @return mixed The decoded response object
848
+ * @throws FBAPFacebookApiException
849
+ */
850
+ protected function _graph($path, $method = 'GET', $params = array()) {
851
+ if (is_array($method) && empty($params)) {
852
+ $params = $method;
853
+ $method = 'GET';
854
+ }
855
+ $params['method'] = $method; // method override as we always do a POST
856
+
857
+ if ($this->isVideoPost($path, $method)) {
858
+ $domainKey = 'graph_video';
859
+ } else {
860
+ $domainKey = 'graph';
861
+ }
862
+
863
+ $result = json_decode($this->_oauthRequest(
864
+ $this->getUrl($domainKey, $path),
865
+ $params
866
+ ), true);
867
+
868
+ // results are returned, errors are thrown
869
+ if (is_array($result) && isset($result['error'])) {
870
+ $this->throwAPIException($result);
871
+ // @codeCoverageIgnoreStart
872
+ }
873
+ // @codeCoverageIgnoreEnd
874
+
875
+ return $result;
876
+ }
877
+
878
+ /**
879
+ * Make a OAuth Request.
880
+ *
881
+ * @param string $url The path (required)
882
+ * @param array $params The query/post data
883
+ *
884
+ * @return string The decoded response object
885
+ * @throws FBAPFacebookApiException
886
+ */
887
+ protected function _oauthRequest($url, $params) {
888
+ if (!isset($params['access_token'])) {
889
+ $params['access_token'] = $this->getAccessToken();
890
+ }
891
+
892
+ // json_encode all params values that are not strings
893
+ foreach ($params as $key => $value) {
894
+ if (!is_string($value)) {
895
+ $params[$key] = json_encode($value);
896
+ }
897
+ }
898
+
899
+ return $this->makeRequest($url, $params);
900
+ }
901
+
902
+ /**
903
+ * Makes an HTTP request. This method can be overridden by subclasses if
904
+ * developers want to do fancier things or use something other than curl to
905
+ * make the request.
906
+ *
907
+ * @param string $url The URL to make the request to
908
+ * @param array $params The parameters to use for the POST body
909
+ * @param CurlHandler $ch Initialized curl handle
910
+ *
911
+ * @return string The response text
912
+ */
913
+ protected function makeRequest($url, $params, $ch=null) {
914
+ if (!$ch) {
915
+ $ch = curl_init();
916
+ }
917
+
918
+ $opts = self::$CURL_OPTS;
919
+ if ($this->getFileUploadSupport()) {
920
+ $opts[CURLOPT_POSTFIELDS] = $params;
921
+ } else {
922
+ $opts[CURLOPT_POSTFIELDS] = http_build_query($params, null, '&');
923
+ }
924
+ $opts[CURLOPT_URL] = $url;
925
+
926
+ // disable the 'Expect: 100-continue' behaviour. This causes CURL to wait
927
+ // for 2 seconds if the server does not support this header.
928
+ if (isset($opts[CURLOPT_HTTPHEADER])) {
929
+ $existing_headers = $opts[CURLOPT_HTTPHEADER];
930
+ $existing_headers[] = 'Expect:';
931
+ $opts[CURLOPT_HTTPHEADER] = $existing_headers;
932
+ } else {
933
+ $opts[CURLOPT_HTTPHEADER] = array('Expect:');
934
+ }
935
+
936
+ curl_setopt_array($ch, $opts);
937
+ $result = curl_exec($ch);
938
+
939
+ if (curl_errno($ch) == 60) { // CURLE_SSL_CACERT
940
+ self::errorLog('Invalid or no certificate authority found, '.
941
+ 'using bundled information');
942
+ curl_setopt($ch, CURLOPT_CAINFO,
943
+ dirname(__FILE__) . '/fb_ca_chain_bundle.crt');
944
+ $result = curl_exec($ch);
945
+ }
946
+
947
+ // With dual stacked DNS responses, it's possible for a server to
948
+ // have IPv6 enabled but not have IPv6 connectivity. If this is
949
+ // the case, curl will try IPv4 first and if that fails, then it will
950
+ // fall back to IPv6 and the error EHOSTUNREACH is returned by the
951
+ // operating system.
952
+ if ($result === false && empty($opts[CURLOPT_IPRESOLVE])) {
953
+ $matches = array();
954
+ $regex = '/Failed to connect to ([^:].*): Network is unreachable/';
955
+ if (preg_match($regex, curl_error($ch), $matches)) {
956
+ if (strlen(@inet_pton($matches[1])) === 16) {
957
+ self::errorLog('Invalid IPv6 configuration on server, '.
958
+ 'Please disable or get native IPv6 on your server.');
959
+ self::$CURL_OPTS[CURLOPT_IPRESOLVE] = CURL_IPRESOLVE_V4;
960
+ curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
961
+ $result = curl_exec($ch);
962
+ }
963
+ }
964
+ }
965
+
966
+ if ($result === false) {
967
+ $e = new FBAPFacebookApiException(array(
968
+ 'error_code' => curl_errno($ch),
969
+ 'error' => array(
970
+ 'message' => curl_error($ch),
971
+ 'type' => 'CurlException',
972
+ ),
973
+ ));
974
+ curl_close($ch);
975
+ throw $e;
976
+ }
977
+ curl_close($ch);
978
+ return $result;
979
+ }
980
+
981
+ /**
982
+ * Parses a signed_request and validates the signature.
983
+ *
984
+ * @param string $signed_request A signed token
985
+ * @return array The payload inside it or null if the sig is wrong
986
+ */
987
+ protected function parseSignedRequest($signed_request) {
988
+ list($encoded_sig, $payload) = explode('.', $signed_request, 2);
989
+
990
+ // decode the data
991
+ $sig = self::base64UrlDecode($encoded_sig);
992
+ $data = json_decode(self::base64UrlDecode($payload), true);
993
+
994
+ if (strtoupper($data['algorithm']) !== self::SIGNED_REQUEST_ALGORITHM) {
995
+ self::errorLog(
996
+ 'Unknown algorithm. Expected ' . self::SIGNED_REQUEST_ALGORITHM);
997
+ return null;
998
+ }
999
+
1000
+ // check sig
1001
+ $expected_sig = hash_hmac('sha256', $payload,
1002
+ $this->getAppSecret(), $raw = true);
1003
+ if ($sig !== $expected_sig) {
1004
+ self::errorLog('Bad Signed JSON signature!');
1005
+ return null;
1006
+ }
1007
+
1008
+ return $data;
1009
+ }
1010
+
1011
+ /**
1012
+ * Makes a signed_request blob using the given data.
1013
+ *
1014
+ * @param array The data array.
1015
+ * @return string The signed request.
1016
+ */
1017
+ protected function makeSignedRequest($data) {
1018
+ if (!is_array($data)) {
1019
+ throw new InvalidArgumentException(
1020
+ 'makeSignedRequest expects an array. Got: ' . print_r($data, true));
1021
+ }
1022
+ $data['algorithm'] = self::SIGNED_REQUEST_ALGORITHM;
1023
+ $data['issued_at'] = time();
1024
+ $json = json_encode($data);
1025
+ $b64 = self::base64UrlEncode($json);
1026
+ $raw_sig = hash_hmac('sha256', $b64, $this->getAppSecret(), $raw = true);
1027
+ $sig = self::base64UrlEncode($raw_sig);
1028
+ return $sig.'.'.$b64;
1029
+ }
1030
+
1031
+ /**
1032
+ * Build the URL for api given parameters.
1033
+ *
1034
+ * @param $method String the method name.
1035
+ * @return string The URL for the given parameters
1036
+ */
1037
+ protected function getApiUrl($method) {
1038
+ static $READ_ONLY_CALLS =
1039
+ array('admin.getallocation' => 1,
1040
+ 'admin.getappproperties' => 1,
1041
+ 'admin.getbannedusers' => 1,
1042
+ 'admin.getlivestreamvialink' => 1,
1043
+ 'admin.getmetrics' => 1,
1044
+ 'admin.getrestrictioninfo' => 1,
1045
+ 'application.getpublicinfo' => 1,
1046
+ 'auth.getapppublickey' => 1,
1047
+ 'auth.getsession' => 1,
1048
+ 'auth.getsignedpublicsessiondata' => 1,
1049
+ 'comments.get' => 1,
1050
+ 'connect.getunconnectedfriendscount' => 1,
1051
+ 'dashboard.getactivity' => 1,
1052
+ 'dashboard.getcount' => 1,
1053
+ 'dashboard.getglobalnews' => 1,
1054
+ 'dashboard.getnews' => 1,
1055
+ 'dashboard.multigetcount' => 1,
1056
+ 'dashboard.multigetnews' => 1,
1057
+ 'data.getcookies' => 1,
1058
+ 'events.get' => 1,
1059
+ 'events.getmembers' => 1,
1060
+ 'fbml.getcustomtags' => 1,
1061
+ 'feed.getappfriendstories' => 1,
1062
+ 'feed.getregisteredtemplatebundlebyid' => 1,
1063
+ 'feed.getregisteredtemplatebundles' => 1,
1064
+ 'fql.multiquery' => 1,
1065
+ 'fql.query' => 1,
1066
+ 'friends.arefriends' => 1,
1067
+ 'friends.get' => 1,
1068
+ 'friends.getappusers' => 1,
1069
+ 'friends.getlists' => 1,
1070
+ 'friends.getmutualfriends' => 1,
1071
+ 'gifts.get' => 1,
1072
+ 'groups.get' => 1,
1073
+ 'groups.getmembers' => 1,
1074
+ 'intl.gettranslations' => 1,
1075
+ 'links.get' => 1,
1076
+ 'notes.get' => 1,
1077
+ 'notifications.get' => 1,
1078
+ 'pages.getinfo' => 1,
1079
+ 'pages.isadmin' => 1,
1080
+ 'pages.isappadded' => 1,
1081
+ 'pages.isfan' => 1,
1082
+ 'permissions.checkavailableapiaccess' => 1,
1083
+ 'permissions.checkgrantedapiaccess' => 1,
1084
+ 'photos.get' => 1,
1085
+ 'photos.getalbums' => 1,
1086
+ 'photos.gettags' => 1,
1087
+ 'profile.getinfo' => 1,
1088
+ 'profile.getinfooptions' => 1,
1089
+ 'stream.get' => 1,
1090
+ 'stream.getcomments' => 1,
1091
+ 'stream.getfilters' => 1,
1092
+ 'users.getinfo' => 1,
1093
+ 'users.getloggedinuser' => 1,
1094
+ 'users.getstandardinfo' => 1,
1095
+ 'users.hasapppermission' => 1,
1096
+ 'users.isappuser' => 1,
1097
+ 'users.isverified' => 1,
1098
+ 'video.getuploadlimits' => 1);
1099
+ $name = 'api';
1100
+ if (isset($READ_ONLY_CALLS[strtolower($method)])) {
1101
+ $name = 'api_read';
1102
+ } else if (strtolower($method) == 'video.upload') {
1103
+ $name = 'api_video';
1104
+ }
1105
+ return self::getUrl($name, 'restserver.php');
1106
+ }
1107
+
1108
+ /**
1109
+ * Build the URL for given domain alias, path and parameters.
1110
+ *
1111
+ * @param $name string The name of the domain
1112
+ * @param $path string Optional path (without a leading slash)
1113
+ * @param $params array Optional query parameters
1114
+ *
1115
+ * @return string The URL for the given parameters
1116
+ */
1117
+ protected function getUrl($name, $path='', $params=array()) {
1118
+ $url = self::$DOMAIN_MAP[$name];
1119
+ if ($path) {
1120
+ if ($path[0] === '/') {
1121
+ $path = substr($path, 1);
1122
+ }
1123
+ $url .= $path;
1124
+ }
1125
+ if ($params) {
1126
+ $url .= '?' . http_build_query($params, null, '&');
1127
+ }
1128
+
1129
+ return $url;
1130
+ }
1131
+
1132
+ protected function getHttpHost() {
1133
+ if ($this->trustForwarded && isset($_SERVER['HTTP_X_FORWARDED_HOST'])) {
1134
+ return $_SERVER['HTTP_X_FORWARDED_HOST'];
1135
+ }
1136
+ return $_SERVER['HTTP_HOST'];
1137
+ }
1138
+
1139
+ protected function getHttpProtocol() {
1140
+ if ($this->trustForwarded && isset($_SERVER['HTTP_X_FORWARDED_PROTO'])) {
1141
+ if ($_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https') {
1142
+ return 'https';
1143
+ }
1144
+ return 'http';
1145
+ }
1146
+ if (isset($_SERVER['HTTPS']) &&
1147
+ ($_SERVER['HTTPS'] === 'on' || $_SERVER['HTTPS'] == 1)) {
1148
+ return 'https';
1149
+ }
1150
+ return 'http';
1151
+ }
1152
+
1153
+ /**
1154
+ * Get the base domain used for the cookie.
1155
+ */
1156
+ protected function getBaseDomain() {
1157
+ // The base domain is stored in the metadata cookie if not we fallback
1158
+ // to the current hostname
1159
+ $metadata = $this->getMetadataCookie();
1160
+ if (array_key_exists('base_domain', $metadata) &&
1161
+ !empty($metadata['base_domain'])) {
1162
+ return trim($metadata['base_domain'], '.');
1163
+ }
1164
+ return $this->getHttpHost();
1165
+ }
1166
+
1167
+ /**
1168
+
1169
+ /**
1170
+ * Returns the Current URL, stripping it of known FB parameters that should
1171
+ * not persist.
1172
+ *
1173
+ * @return string The current URL
1174
+ */
1175
+ protected function getCurrentUrl() {
1176
+ $protocol = $this->getHttpProtocol() . '://';
1177
+ $host = $this->getHttpHost();
1178
+ $currentUrl = $protocol.$host.$_SERVER['REQUEST_URI'];
1179
+ $parts = parse_url($currentUrl);
1180
+
1181
+ $query = '';
1182
+ if (!empty($parts['query'])) {
1183
+ // drop known fb params
1184
+ $params = explode('&', $parts['query']);
1185
+ $retained_params = array();
1186
+ foreach ($params as $param) {
1187
+ if ($this->shouldRetainParam($param)) {
1188
+ $retained_params[] = $param;
1189
+ }
1190
+ }
1191
+
1192
+ if (!empty($retained_params)) {
1193
+ $query = '?'.implode($retained_params, '&');
1194
+ }
1195
+ }
1196
+
1197
+ // use port if non default
1198
+ $port =
1199
+ isset($parts['port']) &&
1200
+ (($protocol === 'http://' && $parts['port'] !== 80) ||
1201
+ ($protocol === 'https://' && $parts['port'] !== 443))
1202
+ ? ':' . $parts['port'] : '';
1203
+
1204
+ // rebuild
1205
+ return $protocol . $parts['host'] . $port . $parts['path'] . $query;
1206
+ }
1207
+
1208
+ /**
1209
+ * Returns true if and only if the key or key/value pair should
1210
+ * be retained as part of the query string. This amounts to
1211
+ * a brute-force search of the very small list of Facebook-specific
1212
+ * params that should be stripped out.
1213
+ *
1214
+ * @param string $param A key or key/value pair within a URL's query (e.g.
1215
+ * 'foo=a', 'foo=', or 'foo'.
1216
+ *
1217
+ * @return boolean
1218
+ */
1219
+ protected function shouldRetainParam($param) {
1220
+ foreach (self::$DROP_QUERY_PARAMS as $drop_query_param) {
1221
+ if (strpos($param, $drop_query_param.'=') === 0) {
1222
+ return false;
1223
+ }
1224
+ }
1225
+
1226
+ return true;
1227
+ }
1228
+
1229
+ /**
1230
+ * Analyzes the supplied result to see if it was thrown
1231
+ * because the access token is no longer valid. If that is
1232
+ * the case, then we destroy the session.
1233
+ *
1234
+ * @param $result array A record storing the error message returned
1235
+ * by a failed API call.
1236
+ */
1237
+ protected function throwAPIException($result) {
1238
+ $e = new FBAPFacebookApiException($result);
1239
+ switch ($e->getType()) {
1240
+ // OAuth 2.0 Draft 00 style
1241
+ case 'OAuthException':
1242
+ // OAuth 2.0 Draft 10 style
1243
+ case 'invalid_token':
1244
+ // REST server errors are just Exceptions
1245
+ case 'Exception':
1246
+ $message = $e->getMessage();
1247
+ if ((strpos($message, 'Error validating access token') !== false) ||
1248
+ (strpos($message, 'Invalid OAuth access token') !== false) ||
1249
+ (strpos($message, 'An active access token must be used') !== false)
1250
+ ) {
1251
+ $this->destroySession();
1252
+ }
1253
+ break;
1254
+ }
1255
+
1256
+ throw $e;
1257
+ }
1258
+
1259
+
1260
+ /**
1261
+ * Prints to the error log if you aren't in command line mode.
1262
+ *
1263
+ * @param string $msg Log message
1264
+ */
1265
+ protected static function errorLog($msg) {
1266
+ // disable error log if we are running in a CLI environment
1267
+ // @codeCoverageIgnoreStart
1268
+ if (php_sapi_name() != 'cli') {
1269
+ error_log($msg);
1270
+ }
1271
+ // uncomment this if you want to see the errors on the page
1272
+ // print 'error_log: '.$msg."\n";
1273
+ // @codeCoverageIgnoreEnd
1274
+ }
1275
+
1276
+ /**
1277
+ * Base64 encoding that doesn't need to be urlencode()ed.
1278
+ * Exactly the same as base64_encode except it uses
1279
+ * - instead of +
1280
+ * _ instead of /
1281
+ * No padded =
1282
+ *
1283
+ * @param string $input base64UrlEncoded string
1284
+ * @return string
1285
+ */
1286
+ protected static function base64UrlDecode($input) {
1287
+ return base64_decode(strtr($input, '-_', '+/'));
1288
+ }
1289
+
1290
+ /**
1291
+ * Base64 encoding that doesn't need to be urlencode()ed.
1292
+ * Exactly the same as base64_encode except it uses
1293
+ * - instead of +
1294
+ * _ instead of /
1295
+ *
1296
+ * @param string $input string
1297
+ * @return string base64Url encoded string
1298
+ */
1299
+ protected static function base64UrlEncode($input) {
1300
+ $str = strtr(base64_encode($input), '+/', '-_');
1301
+ $str = str_replace('=', '', $str);
1302
+ return $str;
1303
+ }
1304
+
1305
+ /**
1306
+ * Destroy the current session
1307
+ */
1308
+ public function destroySession() {
1309
+ $this->accessToken = null;
1310
+ $this->signedRequest = null;
1311
+ $this->user = null;
1312
+ $this->clearAllPersistentData();
1313
+
1314
+ // Javascript sets a cookie that will be used in getSignedRequest that we
1315
+ // need to clear if we can
1316
+ $cookie_name = $this->getSignedRequestCookieName();
1317
+ if (array_key_exists($cookie_name, $_COOKIE)) {
1318
+ unset($_COOKIE[$cookie_name]);
1319
+ if (!headers_sent()) {
1320
+ $base_domain = $this->getBaseDomain();
1321
+ setcookie($cookie_name, '', 1, '/', '.'.$base_domain);
1322
+ } else {
1323
+ // @codeCoverageIgnoreStart
1324
+ self::errorLog(
1325
+ 'There exists a cookie that we wanted to clear that we couldn\'t '.
1326
+ 'clear because headers was already sent. Make sure to do the first '.
1327
+ 'API call before outputing anything.'
1328
+ );
1329
+ // @codeCoverageIgnoreEnd
1330
+ }
1331
+ }
1332
+ }
1333
+
1334
+ /**
1335
+ * Parses the metadata cookie that our Javascript API set
1336
+ *
1337
+ * @return an array mapping key to value
1338
+ */
1339
+ protected function getMetadataCookie() {
1340
+ $cookie_name = $this->getMetadataCookieName();
1341
+ if (!array_key_exists($cookie_name, $_COOKIE)) {
1342
+ return array();
1343
+ }
1344
+
1345
+ // The cookie value can be wrapped in "-characters so remove them
1346
+ $cookie_value = trim($_COOKIE[$cookie_name], '"');
1347
+
1348
+ if (empty($cookie_value)) {
1349
+ return array();
1350
+ }
1351
+
1352
+ $parts = explode('&', $cookie_value);
1353
+ $metadata = array();
1354
+ foreach ($parts as $part) {
1355
+ $pair = explode('=', $part, 2);
1356
+ if (!empty($pair[0])) {
1357
+ $metadata[urldecode($pair[0])] =
1358
+ (count($pair) > 1) ? urldecode($pair[1]) : '';
1359
+ }
1360
+ }
1361
+
1362
+ return $metadata;
1363
+ }
1364
+
1365
+ protected static function isAllowedDomain($big, $small) {
1366
+ if ($big === $small) {
1367
+ return true;
1368
+ }
1369
+ return self::endsWith($big, '.'.$small);
1370
+ }
1371
+
1372
+ protected static function endsWith($big, $small) {
1373
+ $len = strlen($small);
1374
+ if ($len === 0) {
1375
+ return true;
1376
+ }
1377
+ return substr($big, -$len) === $small;
1378
+ }
1379
+
1380
+ /**
1381
+ * Each of the following four methods should be overridden in
1382
+ * a concrete subclass, as they are in the provided Facebook class.
1383
+ * The Facebook class uses PHP sessions to provide a primitive
1384
+ * persistent store, but another subclass--one that you implement--
1385
+ * might use a database, memcache, or an in-memory cache.
1386
+ *
1387
+ * @see Facebook
1388
+ */
1389
+
1390
+ /**
1391
+ * Stores the given ($key, $value) pair, so that future calls to
1392
+ * getPersistentData($key) return $value. This call may be in another request.
1393
+ *
1394
+ * @param string $key
1395
+ * @param array $value
1396
+ *
1397
+ * @return void
1398
+ */
1399
+ abstract protected function setPersistentData($key, $value);
1400
+
1401
+ /**
1402
+ * Get the data for $key, persisted by FBAPBaseFacebook::setPersistentData()
1403
+ *
1404
+ * @param string $key The key of the data to retrieve
1405
+ * @param boolean $default The default value to return if $key is not found
1406
+ *
1407
+ * @return mixed
1408
+ */
1409
+ abstract protected function getPersistentData($key, $default = false);
1410
+
1411
+ /**
1412
+ * Clear the data with $key from the persistent storage
1413
+ *
1414
+ * @param string $key
1415
+ * @return void
1416
+ */
1417
+ abstract protected function clearPersistentData($key);
1418
+
1419
+ /**
1420
+ * Clear all data from the persistent storage
1421
+ *
1422
+ * @return void
1423
+ */
1424
+ abstract protected function clearAllPersistentData();
1425
+ }
api/facebook.php ADDED
@@ -0,0 +1,160 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Copyright 2011 Facebook, Inc.
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may
6
+ * not use this file except in compliance with the License. You may obtain
7
+ * a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14
+ * License for the specific language governing permissions and limitations
15
+ * under the License.
16
+ */
17
+
18
+ require_once( dirname( __FILE__ ) . '/base_facebook.php' );
19
+
20
+ /**
21
+ * Extends the FBAPBaseFacebook class with the intent of using
22
+ * PHP sessions to store user ids and access tokens.
23
+ */
24
+ class FBAPFacebook extends FBAPBaseFacebook
25
+ {
26
+ const FBSS_COOKIE_NAME = 'fbss';
27
+
28
+ // We can set this to a high number because the main session
29
+ // expiration will trump this.
30
+ const FBSS_COOKIE_EXPIRE = 31556926; // 1 year
31
+
32
+ // Stores the shared session ID if one is set.
33
+ protected $sharedSessionID;
34
+
35
+ /**
36
+ * Identical to the parent constructor, except that
37
+ * we start a PHP session to store the user ID and
38
+ * access token if during the course of execution
39
+ * we discover them.
40
+ *
41
+ * @param Array $config the application configuration. Additionally
42
+ * accepts "sharedSession" as a boolean to turn on a secondary
43
+ * cookie for environments with a shared session (that is, your app
44
+ * shares the domain with other apps).
45
+ * @see FBAPBaseFacebook::__construct in facebook.php
46
+ */
47
+ public function __construct($config) {
48
+ if (!session_id()) {
49
+ session_start();
50
+ }
51
+ parent::__construct($config);
52
+ if (!empty($config['sharedSession'])) {
53
+ $this->initSharedSession();
54
+ }
55
+ }
56
+
57
+ protected static $kSupportedKeys =
58
+ array('state', 'code', 'access_token', 'user_id');
59
+
60
+ protected function initSharedSession() {
61
+ $cookie_name = $this->getSharedSessionCookieName();
62
+ if (isset($_COOKIE[$cookie_name])) {
63
+ $data = $this->parseSignedRequest($_COOKIE[$cookie_name]);
64
+ if ($data && !empty($data['domain']) &&
65
+ self::isAllowedDomain($this->getHttpHost(), $data['domain'])) {
66
+ // good case
67
+ $this->sharedSessionID = $data['id'];
68
+ return;
69
+ }
70
+ // ignoring potentially unreachable data
71
+ }
72
+ // evil/corrupt/missing case
73
+ $base_domain = $this->getBaseDomain();
74
+ $this->sharedSessionID = md5(uniqid(mt_rand(), true));
75
+ $cookie_value = $this->makeSignedRequest(
76
+ array(
77
+ 'domain' => $base_domain,
78
+ 'id' => $this->sharedSessionID,
79
+ )
80
+ );
81
+ $_COOKIE[$cookie_name] = $cookie_value;
82
+ if (!headers_sent()) {
83
+ $expire = time() + self::FBSS_COOKIE_EXPIRE;
84
+ setcookie($cookie_name, $cookie_value, $expire, '/', '.'.$base_domain);
85
+ } else {
86
+ // @codeCoverageIgnoreStart
87
+ self::errorLog(
88
+ 'Shared session ID cookie could not be set! You must ensure you '.
89
+ 'create the Facebook instance before headers have been sent. This '.
90
+ 'will cause authentication issues after the first request.'
91
+ );
92
+ // @codeCoverageIgnoreEnd
93
+ }
94
+ }
95
+
96
+ /**
97
+ * Provides the implementations of the inherited abstract
98
+ * methods. The implementation uses PHP sessions to maintain
99
+ * a store for authorization codes, user ids, CSRF states, and
100
+ * access tokens.
101
+ */
102
+ protected function setPersistentData($key, $value) {
103
+ if (!in_array($key, self::$kSupportedKeys)) {
104
+ self::errorLog('Unsupported key passed to setPersistentData.');
105
+ return;
106
+ }
107
+
108
+ $session_var_name = $this->constructSessionVariableName($key);
109
+ $_SESSION[$session_var_name] = $value;
110
+ }
111
+
112
+ protected function getPersistentData($key, $default = false) {
113
+ if (!in_array($key, self::$kSupportedKeys)) {
114
+ self::errorLog('Unsupported key passed to getPersistentData.');
115
+ return $default;
116
+ }
117
+
118
+ $session_var_name = $this->constructSessionVariableName($key);
119
+ return isset($_SESSION[$session_var_name]) ?
120
+ $_SESSION[$session_var_name] : $default;
121
+ }
122
+
123
+ protected function clearPersistentData($key) {
124
+ if (!in_array($key, self::$kSupportedKeys)) {
125
+ self::errorLog('Unsupported key passed to clearPersistentData.');
126
+ return;
127
+ }
128
+
129
+ $session_var_name = $this->constructSessionVariableName($key);
130
+ unset($_SESSION[$session_var_name]);
131
+ }
132
+
133
+ protected function clearAllPersistentData() {
134
+ foreach (self::$kSupportedKeys as $key) {
135
+ $this->clearPersistentData($key);
136
+ }
137
+ if ($this->sharedSessionID) {
138
+ $this->deleteSharedSessionCookie();
139
+ }
140
+ }
141
+
142
+ protected function deleteSharedSessionCookie() {
143
+ $cookie_name = $this->getSharedSessionCookieName();
144
+ unset($_COOKIE[$cookie_name]);
145
+ $base_domain = $this->getBaseDomain();
146
+ setcookie($cookie_name, '', 1, '/', '.'.$base_domain);
147
+ }
148
+
149
+ protected function getSharedSessionCookieName() {
150
+ return self::FBSS_COOKIE_NAME . '_' . $this->getAppId();
151
+ }
152
+
153
+ protected function constructSessionVariableName($key) {
154
+ $parts = array('fb', $this->getAppId(), $key);
155
+ if ($this->sharedSessionID) {
156
+ array_unshift($parts, $this->sharedSessionID);
157
+ }
158
+ return implode('_', $parts);
159
+ }
160
+ }
facebook-auto-publish.php ADDED
@@ -0,0 +1,59 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ Plugin Name: Facebook Auto Publish
4
+ Plugin URI: http://xyzscripts.com/wordpress-plugins/facebook-auto-publish/
5
+ Description: Publish posts automatically from your blog to Facebook social media. You can publish your posts to Facebook as simple text message, text message with image or as attached link to your blog. The plugin supports filtering posts by custom post-types and categories.
6
+ Version: 1.0
7
+ Author: xyzscripts.com
8
+ Author URI: http://xyzscripts.com/
9
+ License: GPLv2 or later
10
+ */
11
+
12
+ /*
13
+ This program is free software; you can redistribute it and/or
14
+ modify it under the terms of the GNU General Public License
15
+ as published by the Free Software Foundation; either version 2
16
+ of the License, or (at your option) any later version.
17
+
18
+ This program is distributed in the hope that it will be useful,
19
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
20
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21
+ GNU General Public License for more details.
22
+
23
+ You should have received a copy of the GNU General Public License
24
+ along with this program; if not, write to the Free Software
25
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
26
+ */
27
+
28
+ if ( !function_exists( 'add_action' ) ) {
29
+ echo "Hi there! I'm just a plugin, not much I can do when called directly.";
30
+ exit;
31
+ }
32
+ ob_start();
33
+ //error_reporting(E_ALL);
34
+ define('XYZ_FBAP_PLUGIN_FILE',__FILE__);
35
+
36
+ mysql_query('SET SQL_MODE=""');
37
+
38
+ require_once( dirname( __FILE__ ) . '/admin/install.php' );
39
+ require_once( dirname( __FILE__ ) . '/xyz-functions.php' );
40
+ require_once( dirname( __FILE__ ) . '/admin/menu.php' );
41
+ require_once( dirname( __FILE__ ) . '/admin/destruction.php' );
42
+
43
+ require_once( dirname( __FILE__ ) . '/api/facebook.php' );
44
+
45
+ require_once( dirname( __FILE__ ) . '/admin/ajax-backlink.php' );
46
+ require_once( dirname( __FILE__ ) . '/admin/metabox.php' );
47
+ require_once( dirname( __FILE__ ) . '/admin/publish.php' );
48
+ if(get_option('xyz_credit_link')=="fbap"){
49
+
50
+ add_action('wp_footer', 'xyz_fbap_credit');
51
+
52
+ }
53
+ function xyz_fbap_credit() {
54
+ $content = '<div style="clear:both;width:100%;text-align:center; font-size:11px; "><a target="_blank" title="Facebook Auto Publish" href="http://xyzscripts.com/wordpress-plugins/facebook-auto-publish/details" >Facebook Auto Publish</a> Powered By : <a target="_blank" title="PHP Scripts & Programs" href="http://www.xyzscripts.com" >XYZScripts.com</a></div>';
55
+ echo $content;
56
+ }
57
+ if(!function_exists('get_post_thumbnail_id'))
58
+ add_theme_support( 'post-thumbnails' );
59
+ ?>
js/notice.js ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ jQuery(document).ready(function() {
2
+ jQuery('#system_notice_area').animate({
3
+ opacity : 'show',
4
+ height : 'show'
5
+ }, 500);
6
+
7
+ jQuery('#system_notice_area_dismiss').click(function() {
8
+ jQuery('#system_notice_area').animate({
9
+ opacity : 'hide',
10
+ height : 'hide'
11
+ }, 500);
12
+
13
+ });
14
+
15
+ });
readme.txt ADDED
@@ -0,0 +1,141 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ === Facebook Auto Publish ===
2
+ Contributors: f1logic
3
+ Donate link: http://xyzscripts.com/donate/
4
+ Tags: facebook, facebook auto publish, publish post to facebook, add link to facebook, facebook publishing, post to facebook, post to fb, social media auto publish, social media publishing, social network auto publish, social media, social network
5
+ Requires at least: 2.8
6
+ Tested up to: 3.6
7
+ Stable tag: 1.0
8
+ License: GPLv2 or later
9
+
10
+ Publish posts automatically to Facebook page or profile.
11
+
12
+ == Description ==
13
+
14
+ A quick look into Facebook Auto Publish :
15
+
16
+ ★ Publish message to Facebook with image
17
+ ★ Attach post or share link to Facebook
18
+ ★ Filter items to be published based on categories
19
+ ★ Filter items to be published based on custom post types
20
+ ★ Enable or disable wordpress page publishing
21
+ ★ Customizable message formats for Facebook
22
+
23
+
24
+ = Facebook Auto Publish Features in Detail =
25
+
26
+ The Facebook Auto Publish lets you publish posts automatically from your blog to Facebook. You can publish your posts to Facebook as simple text message, text message with image or as attached link to your blog. The plugin supports filtering posts based on custom post-types as well as categories.
27
+
28
+ The prominent features of the Facebook Auto Publish plugin are highlighted below.
29
+
30
+ = Supported Mechanisms =
31
+
32
+ The various mechanisms of posting to Facebook are listed below.
33
+
34
+ Simple text message
35
+ Text message with image
36
+ Share a link to your blog post
37
+ Attach your blog post
38
+ Post to Facebook profile page
39
+ Post to specific pages on Facebook
40
+
41
+ = Filter Settings =
42
+
43
+ The plugin offers multiple kinds of filters for contents to be published automatically.
44
+
45
+ Enable or disable publishing of wordpress pages
46
+ Filter posts to be published based on categories
47
+ Filtering based on custom post types
48
+
49
+ = Message Format Settings =
50
+
51
+ The supported post elements which can be published are given below.
52
+
53
+ Post title
54
+ Post description
55
+ Post excerpt
56
+ Permalink
57
+ Blog title
58
+ User nicename
59
+
60
+
61
+ = About =
62
+
63
+ Facebook Auto Publish is developed and maintained by [XYZScripts](http://xyzscripts.com/ "xyzscripts.com"). For any support, you may [contact us](http://xyzscripts.com/support/ "XYZScripts Support").
64
+
65
+ ★ [Facebook Auto Publish User Guide](http://docs.xyzscripts.com/wordpress-plugins/facebook-auto-publish/ "Facebook Auto Publish User Guide")
66
+ ★ [Facebook Auto Publish FAQ](http://kb.xyzscripts.com/wordpress-plugins/facebook-auto-publish/ "Facebook Auto Publish FAQ")
67
+
68
+ == Installation ==
69
+
70
+ ★ [Facebook Auto Publish User Guide](http://docs.xyzscripts.com/wordpress-plugins/facebook-auto-publish/ "Facebook Auto Publish User Guide")
71
+ ★ [Facebook Auto Publish FAQ](http://kb.xyzscripts.com/wordpress-plugins/facebook-auto-publish/ "Facebook Auto Publish FAQ")
72
+
73
+ 1. Extract `facebook-auto-publish.zip` to your `/wp-content/plugins/` directory.
74
+ 2. In the admin panel under plugins activate Facebook Auto Publish.
75
+ 3. You can configure the settings from Facebook Auto Publish menu. (Make sure to Authorize Facebook application after saving the settings.)
76
+ 4. Once these are done, posts should get automatically published based on your filter settings.
77
+
78
+ If you need any further help, you may contact our [support desk](http://xyzscripts.com/support/ "XYZScripts Support").
79
+
80
+ == Frequently Asked Questions ==
81
+
82
+ ★ [Facebook Auto Publish User Guide](http://docs.xyzscripts.com/wordpress-plugins/facebook-auto-publish/ "Facebook Auto Publish User Guide")
83
+ ★ [Facebook Auto Publish FAQ](http://kb.xyzscripts.com/wordpress-plugins/facebook-auto-publish/ "Facebook Auto Publish FAQ")
84
+
85
+ = 1. The Facebook Auto Publish is not working properly. =
86
+
87
+ Please check the wordpress version you are using. Make sure it meets the minimum version recommended by us. Make sure all files of the `facebook auto publish` plugin are uploaded to the folder `wp-content/plugins/`
88
+
89
+
90
+ = 2. Can I post to Facebook pages instead of profile ? =
91
+
92
+ Yes, you can select the pages to which you need to publish after authorizing Facebook application.
93
+
94
+
95
+ = 3. How do I restrict auto publish to certain categories ? =
96
+
97
+ Yes, you can specify the categories which need to be auto published from settings page.
98
+
99
+
100
+ = 4. Why do I have to create applications in Facebook ? =
101
+
102
+ When you create your own applications, it ensures that the posts to Facebook are not shared with any message like "shared via xxx"
103
+
104
+
105
+ = 5. Which all data fields can I send to Facebook ? =
106
+
107
+ You may use post title, content, excerpt, permalink, site title and user nicename for auto publishing.
108
+
109
+
110
+ More questions ? [Drop a mail](http://xyzscripts.com/members/support/ "XYZScripts Support") and we shall get back to you with the answers.
111
+
112
+
113
+ == Screenshots ==
114
+
115
+ 1. This is the Facebook configuration section.
116
+ 2. Publishing options while creating a post.
117
+
118
+ == Changelog ==
119
+
120
+ = Facebook Auto Publish 1.0 =
121
+ * First official launch.
122
+
123
+ == Upgrade Notice ==
124
+
125
+ == More Information ==
126
+
127
+ ★ [Facebook Auto Publish User Guide](http://docs.xyzscripts.com/wordpress-plugins/facebook-auto-publish/ "Facebook Auto Publish User Guide")
128
+ ★ [Facebook Auto Publish FAQ](http://kb.xyzscripts.com/wordpress-plugins/facebook-auto-publish/ "Facebook Auto Publish FAQ")
129
+
130
+ = Troubleshooting =
131
+
132
+ Please read the FAQ first if you are having problems.
133
+
134
+ = Requirements =
135
+
136
+ WordPress 2.8+
137
+ PHP 5+
138
+
139
+ = Feedback =
140
+
141
+ We would like to receive your feedback and suggestions about Facebook Auto Publish plugin. You may submit them at our [support desk](http://xyzscripts.com/support/ "XYZScripts Support").
xyz-functions.php ADDED
@@ -0,0 +1,61 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+
4
+ if(!function_exists('xyz_trim_deep'))
5
+ {
6
+
7
+ function xyz_trim_deep($value) {
8
+ if ( is_array($value) ) {
9
+ $value = array_map('xyz_trim_deep', $value);
10
+ } elseif ( is_object($value) ) {
11
+ $vars = get_object_vars( $value );
12
+ foreach ($vars as $key=>$data) {
13
+ $value->{$key} = xyz_trim_deep( $data );
14
+ }
15
+ } else {
16
+ $value = trim($value);
17
+ }
18
+
19
+ return $value;
20
+ }
21
+
22
+ }
23
+
24
+ if(!function_exists('esc_textarea'))
25
+ {
26
+ function esc_textarea($text)
27
+ {
28
+ $safe_text = htmlspecialchars( $text, ENT_QUOTES );
29
+ return $safe_text;
30
+ }
31
+ }
32
+
33
+ if(!function_exists('xyz_fbap_plugin_get_version'))
34
+ {
35
+ function xyz_fbap_plugin_get_version()
36
+ {
37
+ if ( ! function_exists( 'get_plugins' ) )
38
+ require_once( ABSPATH . 'wp-admin/includes/plugin.php' );
39
+ $plugin_folder = get_plugins( '/' . plugin_basename( dirname( XYZ_FBAP_PLUGIN_FILE ) ) );
40
+ // print_r($plugin_folder);
41
+ return $plugin_folder['facebook-auto-publish.php']['Version'];
42
+ }
43
+ }
44
+
45
+
46
+ if(!function_exists('xyz_fbap_links')){
47
+ function xyz_fbap_links($links, $file) {
48
+ $base = plugin_basename(XYZ_FBAP_PLUGIN_FILE);
49
+ if ($file == $base) {
50
+
51
+ $links[] = '<a href="http://xyzscripts.com/support/" class="xyz_support" title="Support"></a>';
52
+ $links[] = '<a href="http://twitter.com/xyzscripts" class="xyz_twitt" title="Follow us on twitter"></a>';
53
+ $links[] = '<a href="https://www.facebook.com/xyzscripts" class="xyz_fbook" title="Facebook"></a>';
54
+ $links[] = '<a href="https://plus.google.com/101215320403235276710/" class="xyz_gplus" title="+1"></a>';
55
+ }
56
+ return $links;
57
+ }
58
+ }
59
+ add_filter( 'plugin_row_meta','xyz_fbap_links',10,2);
60
+
61
+ ?>