1 | <?php
|
---|
2 | /**
|
---|
3 | * @author: Javier Reyes Gomez (http://www.sociable.es)
|
---|
4 | * @date: 05/10/2008
|
---|
5 | * @license: GPLv2
|
---|
6 | */
|
---|
7 |
|
---|
8 | include_once 'fbConfig.php';
|
---|
9 |
|
---|
10 | if (!class_exists('WPfbConnect_Interface')):
|
---|
11 | class WPfbConnect_Interface {
|
---|
12 |
|
---|
13 | /**
|
---|
14 | * Enqueue required javascript libraries.
|
---|
15 | *
|
---|
16 | * @action: init
|
---|
17 | **/
|
---|
18 | function js_setup() {
|
---|
19 | }
|
---|
20 |
|
---|
21 | /**
|
---|
22 | * Add Facebook Share
|
---|
23 | *
|
---|
24 | * @action: the_content
|
---|
25 | **/
|
---|
26 | function add_fbshare($content) {
|
---|
27 | global $post;
|
---|
28 | $content .= '<p class="fbconnect_share"><fb:share-button class="url" href="'.get_permalink($post->ID).'" /></p>';
|
---|
29 | return $content;
|
---|
30 | }
|
---|
31 |
|
---|
32 | /**
|
---|
33 | * Include internal stylesheet.
|
---|
34 | *
|
---|
35 | * @action: wp_head, login_head
|
---|
36 | **/
|
---|
37 | function style() {
|
---|
38 | if ( file_exists( TEMPLATEPATH . '/fbconnect.css') ){
|
---|
39 | $css_path = get_template_directory_uri() . '/fbconnect.css?ver='.FBCONNECT_PLUGIN_REVISION;
|
---|
40 | }else{
|
---|
41 | //$css_path = get_option('siteurl') . '/' . PLUGINDIR . '/fbconnect/fbconnect.css?ver='.FBCONNECT_PLUGIN_REVISION;
|
---|
42 | $css_path = FBCONNECT_PLUGIN_URL . '/fbconnect.css?ver='.FBCONNECT_PLUGIN_REVISION;
|
---|
43 | }
|
---|
44 | echo '<link rel="stylesheet" type="text/css" href="'.$css_path.'" />';
|
---|
45 |
|
---|
46 | }
|
---|
47 |
|
---|
48 |
|
---|
49 | /**
|
---|
50 | * Modify comment form.
|
---|
51 | *
|
---|
52 | * @action: comment_form
|
---|
53 | **/
|
---|
54 | function comment_form() {
|
---|
55 | $fb_user = fb_get_loggedin_user();
|
---|
56 | if (is_user_logged_in() && $fb_user) {
|
---|
57 | echo '<img class="icon-text-middle" src="'.FBCONNECT_PLUGIN_URL .'/images/facebook_24.png"/>';
|
---|
58 | echo '<input style="width:20px;" type="checkbox" name="sendToFacebook" id="sendToFacebook" checked="checked" />'.__('Publish this comment to Facebook', 'fbconnect');
|
---|
59 | }
|
---|
60 | }
|
---|
61 |
|
---|
62 |
|
---|
63 | /**
|
---|
64 | * Spam up the admin interface with warnings.
|
---|
65 | **/
|
---|
66 | function admin_notices_plugin_problem_warning() {
|
---|
67 | echo'<div class="error"><p><strong>'.__('The WordPress fbconnect plugin is not active.', 'fbconnect').'</strong>';
|
---|
68 | printf(_('Check %sfbconnect Options%s for a full diagnositic report.', 'fbconnect'), '<a href="options-general.php?page=global-fbconnect-options">', '</a>');
|
---|
69 | echo '</p></div>';
|
---|
70 | }
|
---|
71 |
|
---|
72 |
|
---|
73 | /**
|
---|
74 | * Setup admin menus for fbconnect options and ID management.
|
---|
75 | *
|
---|
76 | * @action: admin_menu
|
---|
77 | **/
|
---|
78 | function add_admin_panels() {
|
---|
79 | $hookname = add_options_page(__('fbconnect options', 'fbconnect'), __('Facebook Connector', 'fbconnect'), 8, 'global-fbconnect-options',
|
---|
80 | array( 'WPfbConnect_Interface', 'options_page') );
|
---|
81 | add_action("admin_head-$hookname", array( 'WPfbConnect_Interface', 'js_setup' ));
|
---|
82 | add_action("admin_head-$hookname", array( 'WPfbConnect_Interface', 'style' ));
|
---|
83 |
|
---|
84 | }
|
---|
85 |
|
---|
86 |
|
---|
87 | function register_feed_forms($fb_online_stories,$fb_short_stories_title,$fb_short_stories_body,$fb_full_stories_title,$fb_full_stories_body) {
|
---|
88 | $one_line_stories = $short_stories = $full_stories = array();
|
---|
89 |
|
---|
90 | $one_line_stories[] = $fb_online_stories;
|
---|
91 | $short_stories[] = array('template_title' => $fb_short_stories_title,
|
---|
92 | 'template_body' => $fb_short_stories_body);
|
---|
93 | $full_stories = array('template_title' => $fb_full_stories_title,
|
---|
94 | 'template_body' => $fb_full_stories_body);
|
---|
95 | $form_id = fb_feed_registerTemplateBundle($one_line_stories,$short_stories,$full_stories);
|
---|
96 |
|
---|
97 | return $form_id;
|
---|
98 | }
|
---|
99 |
|
---|
100 | /*
|
---|
101 | * Display and handle updates from the Admin screen options page.
|
---|
102 | *
|
---|
103 | * @options_page
|
---|
104 | */
|
---|
105 | function options_page() {
|
---|
106 | global $wp_version, $fbconnect;
|
---|
107 |
|
---|
108 | // if we're posted back an update, let's set the values here
|
---|
109 | if ( isset($_POST['info_update']) ) {
|
---|
110 | check_admin_referer('wp-fbconnect-info_update');
|
---|
111 |
|
---|
112 | $error = '';
|
---|
113 | update_option( 'fb_api_key', $_POST['fb_api_key'] );
|
---|
114 | update_option( 'fb_api_secret', $_POST['fb_api_secret'] );
|
---|
115 | update_option( 'fb_enable_commentform', isset($_POST['enable_commentform']) ? true : false );
|
---|
116 | update_option( 'fb_enable_approval', isset($_POST['enable_approval']) ? true : false );
|
---|
117 | update_option( 'fb_add_post_share', isset($_POST['fb_add_post_share']) ? true : false );
|
---|
118 | update_option( 'fb_use_ssl', isset($_POST['fb_use_ssl']) ? true : false );
|
---|
119 | update_option( 'fb_use_fbml', isset($_POST['fb_use_fbml']) ? true : false );
|
---|
120 |
|
---|
121 | if ($error !== '') {
|
---|
122 | echo '<div class="error"><p><strong>'.__('At least one of Facebook Connector options was NOT updated', 'fbconnect').'</strong>'.$error.'</p></div>';
|
---|
123 | } else {
|
---|
124 | echo '<div class="updated"><p><strong>'.__('Facebook Connector options updated', 'fbconnect').'</strong></p></div>';
|
---|
125 | }
|
---|
126 |
|
---|
127 |
|
---|
128 | }elseif (isset($_POST['template_update'])){
|
---|
129 | check_admin_referer('wp-fbconnect-info_update');
|
---|
130 |
|
---|
131 | $error = '';
|
---|
132 |
|
---|
133 | update_option( 'fb_online_stories', $_POST['fb_online_stories'] );
|
---|
134 | update_option( 'fb_short_stories_title', $_POST['fb_short_stories_title'] );
|
---|
135 | update_option( 'fb_short_stories_body', $_POST['fb_short_stories_body'] );
|
---|
136 | update_option( 'fb_full_stories_title', $_POST['fb_full_stories_title'] );
|
---|
137 | update_option( 'fb_full_stories_body', $_POST['fb_full_stories_body'] );
|
---|
138 | $templatesId = WPfbConnect_Interface::register_feed_forms($_POST['fb_online_stories'],$_POST['fb_short_stories_title'],$_POST['fb_short_stories_body'], $_POST['fb_full_stories_title'], $_POST['fb_full_stories_body']);
|
---|
139 | if ($templatesId!=""){
|
---|
140 | update_option( 'fb_templates_id', $templatesId );
|
---|
141 | }else{
|
---|
142 | $error = " ";
|
---|
143 | }
|
---|
144 | if ($error !== '') {
|
---|
145 | echo '<div class="error"><p><strong>'.__('Error updating Facebook templates!', 'fbconnect').'</strong>'.$error.'</p></div>';
|
---|
146 | } else {
|
---|
147 | echo '<div class="updated"><p><strong>'.__('Facebook templates updated! Templates ID:'.$templatesId, 'fbconnect').'</strong></p></div>';
|
---|
148 | }
|
---|
149 |
|
---|
150 | }elseif ( isset($_REQUEST['action']) ) {
|
---|
151 | switch($_REQUEST['action']) {
|
---|
152 | case 'delete_template' :
|
---|
153 | check_admin_referer('wp-fbconnect-info_delete_template');
|
---|
154 | fb_feed_deactivateTemplateBundleByID($_REQUEST['template_id']);
|
---|
155 |
|
---|
156 | $fb_templates_id = get_option('fb_templates_id');
|
---|
157 | if ($_REQUEST['template_id'] == $fb_templates_id){
|
---|
158 | update_option( 'fb_templates_id', "" );
|
---|
159 | }
|
---|
160 | echo '<div class="updated"><p><strong>Facebook template removed:'.$_REQUEST['template_id'].'</strong></p></div>';
|
---|
161 | break;
|
---|
162 | case 'activate_template' :
|
---|
163 | check_admin_referer('wp-fbconnect-info_activate_template');
|
---|
164 | $template = fb_feed_getRegisteredTemplateBundleByID($_REQUEST['template_id']);
|
---|
165 |
|
---|
166 | if (isset($template) && $template!="" ){
|
---|
167 | update_option( 'fb_templates_id', $_REQUEST['template_id'] );
|
---|
168 | update_option( 'fb_online_stories', $template["one_line_story_templates"][0] );
|
---|
169 | update_option( 'fb_short_stories_title', $template["short_story_templates"][0]["template_title"] );
|
---|
170 | update_option( 'fb_short_stories_body', $template["short_story_templates"][0]["template_body"] );
|
---|
171 | update_option( 'fb_full_stories_title', $template["full_story_templates"][0]["template_title"] );
|
---|
172 | update_option( 'fb_full_stories_body', $template["full_story_templates"][0]["template_body"] );
|
---|
173 | }
|
---|
174 |
|
---|
175 | break;
|
---|
176 | }
|
---|
177 | }
|
---|
178 |
|
---|
179 | // Display the options page form
|
---|
180 | $siteurl = get_option('home');
|
---|
181 | if( substr( $siteurl, -1, 1 ) !== '/' ) $siteurl .= '/';
|
---|
182 | ?>
|
---|
183 | <div class="wrap">
|
---|
184 | <h2><?php _e('Facebook Connector Options', 'fbconnect') ?></h2>
|
---|
185 |
|
---|
186 | <form method="post">
|
---|
187 |
|
---|
188 |
|
---|
189 | <h3><?php _e('Facebook Application Configuration', 'fbconnect') ?></h3>
|
---|
190 | <table class="form-table" cellspacing="2" cellpadding="5" width="100%">
|
---|
191 | <tr valign="top">
|
---|
192 | <th style="width: 33%" scope="row"><?php _e('Facebook App. Config.', 'fbconnect') ?></th>
|
---|
193 | <td>
|
---|
194 | <a href="http://www.facebook.com/developers/" target="_blank"><?php _e('Go to Facebook Developer App', 'fbconnect') ?></a>
|
---|
195 | </td>
|
---|
196 | </tr>
|
---|
197 |
|
---|
198 | <tr valign="top">
|
---|
199 | <th style="width: 33%" scope="row"><label for="fb_api_key"><?php _e('Facebook API Key:', 'fbconnect') ?></label></th>
|
---|
200 | <td>
|
---|
201 | <input type="text" name="fb_api_key" id="fb_api_key" size="50" value="<?php echo get_option('fb_api_key');?>"/>
|
---|
202 | </td>
|
---|
203 | </tr>
|
---|
204 | <tr valign="top">
|
---|
205 | <th style="width: 33%" scope="row"><label for="fb_api_secret"><?php _e('Facebook API Secret:', 'fbconnect') ?></label></th>
|
---|
206 | <td>
|
---|
207 | <input type="text" name="fb_api_secret" size="50" id="fb_api_secret" value="<?php echo get_option('fb_api_secret');?>"/>
|
---|
208 | </td>
|
---|
209 | </tr>
|
---|
210 | <tr valign="top">
|
---|
211 | <th style="width: 33%" scope="row"><label for="enable_approval"><?php _e('Automatic Approval:', 'fbconnect') ?></label></th>
|
---|
212 | <td>
|
---|
213 | <p><input type="checkbox" name="enable_approval" id="enable_approval" <?php
|
---|
214 | echo get_option('fb_enable_approval') ? 'checked="checked"' : ''; ?> />
|
---|
215 | <label for="enable_approval"><?php _e('Enable comment auto-approval', 'fbconnect') ?></label>
|
---|
216 | </td>
|
---|
217 | </tr>
|
---|
218 | <tr valign="top">
|
---|
219 | <th style="width: 33%" scope="row"><label for="fb_add_post_share"><?php _e('Add share button:', 'fbconnect') ?></label></th>
|
---|
220 | <td>
|
---|
221 | <p><input type="checkbox" name="fb_add_post_share" id="fb_add_post_share" <?php
|
---|
222 | echo get_option('fb_add_post_share') ? 'checked="checked"' : ''; ?> />
|
---|
223 | <label for="fb_add_post_share"><?php _e('Add Facebook share button', 'fbconnect') ?></label>
|
---|
224 | </td>
|
---|
225 | </tr>
|
---|
226 | <tr valign="top">
|
---|
227 | <th style="width: 33%" scope="row"><?php _e('Comment Form:', 'fbconnect') ?></th>
|
---|
228 | <td>
|
---|
229 | <p><input type="checkbox" name="enable_commentform" id="enable_commentform" <?php
|
---|
230 | if( get_option('fb_enable_commentform') ) echo 'checked="checked"'
|
---|
231 | ?> />
|
---|
232 | <label for="enable_commentform"><?php _e('Allow send user comments to Facebook.', 'fbconnect') ?></label></p>
|
---|
233 |
|
---|
234 | </td>
|
---|
235 | </tr>
|
---|
236 | <tr valign="top">
|
---|
237 | <th style="width: 33%" scope="row"><?php _e('Secure login:', 'fbconnect') ?></th>
|
---|
238 | <td>
|
---|
239 | <p><input type="checkbox" name="fb_use_ssl" id="fb_use_ssl" <?php
|
---|
240 | if( get_option('fb_use_ssl') ) echo 'checked="checked"'
|
---|
241 | ?> />
|
---|
242 | <label for="fb_use_ssl"><?php _e('Facebook Connect Via SSL.', 'fbconnect') ?></label></p>
|
---|
243 |
|
---|
244 | </td>
|
---|
245 | </tr>
|
---|
246 | </table>
|
---|
247 |
|
---|
248 |
|
---|
249 | <?php wp_nonce_field('wp-fbconnect-info_update'); ?>
|
---|
250 |
|
---|
251 | <p class="submit"><input class="button-primary" type="submit" name="info_update" value="<?php _e('Update Configuration', 'fbconnect') ?> »" /></p>
|
---|
252 | </form>
|
---|
253 |
|
---|
254 |
|
---|
255 | <form method="post">
|
---|
256 |
|
---|
257 | <h3><?php _e('Comment templates', 'fbconnect') ?></h3>
|
---|
258 | <?php
|
---|
259 | $fb_templates_id = get_option('fb_templates_id');
|
---|
260 | $templates = fb_feed_getRegisteredTemplateBundles();
|
---|
261 |
|
---|
262 | //print_r($templates);
|
---|
263 | if ($fb_templates_id == '' && isset($templates) && $templates!="" ){
|
---|
264 | echo '<div class="error"><p><strong>'.__('No active Facebook template, please activate a template or create a new one!', 'fbconnect').'</strong>'.$error.'</p></div>';
|
---|
265 | }else if ($fb_templates_id == ''){
|
---|
266 | echo '<div class="error"><p><strong>'.__('Templates not synchronized with Facebook, write the templates text and press create templates!', 'fbconnect').'</strong>'.$error.'</p></div>';
|
---|
267 | } else {
|
---|
268 | echo '<div class="updated"><p><strong>'.__('Active Facebook template ID:', 'fbconnect').$fb_templates_id.'</strong></p></div>';
|
---|
269 | }
|
---|
270 |
|
---|
271 |
|
---|
272 |
|
---|
273 | if (isset($templates) && $templates!="" ){
|
---|
274 | foreach ($templates as $template){
|
---|
275 | echo "<br/><b>".__('Template ID:', 'fbconnect').$template["template_bundle_id"].'</b> <a href="'.wp_nonce_url(sprintf('?page=%s&action=activate_template&template_id=%s', $_REQUEST['page'],$template["template_bundle_id"]), 'wp-fbconnect-info_activate_template').'">'.__('Activate template', 'fbconnect').'</a> ';
|
---|
276 | echo '<a href="'.wp_nonce_url(sprintf('?page=%s&action=delete_template&template_id=%s', $_REQUEST['page'],$template["template_bundle_id"]), 'wp-fbconnect-info_delete_template').'">'.__('Delete template', 'fbconnect').'</a>';
|
---|
277 | if ($fb_templates_id == $template["template_bundle_id"]){
|
---|
278 | echo '<b style="color:red;"> <-'.__('Active Facebook template', 'fbconnect').'</b>';
|
---|
279 | }
|
---|
280 |
|
---|
281 | echo "<br/>".__('One line story:', 'fbconnect').$template["one_line_story_templates"][0];
|
---|
282 | echo "<br/>".__('Short story title:', 'fbconnect').$template["short_story_templates"][0]["template_title"];
|
---|
283 | echo "<br/>".__('Short story body:', 'fbconnect').$template["short_story_templates"][0]["template_body"];
|
---|
284 | echo "<br/>".__('Full story title:', 'fbconnect').$template["full_story_template"]["template_title"];
|
---|
285 | echo "<br/>".__('Full story body:', 'fbconnect').$template["full_story_template"]["template_body"];
|
---|
286 | echo "<br/>";
|
---|
287 | }
|
---|
288 | }
|
---|
289 | //print_r($templates);
|
---|
290 | $fb_online_stories = get_option('fb_online_stories');
|
---|
291 | if (!$fb_online_stories){
|
---|
292 | $fb_online_stories = '{*actor*} commented on {*blogname*}, post title: {*post_title*}, {*body_short*} ';
|
---|
293 | }
|
---|
294 |
|
---|
295 | $fb_short_stories_title = get_option('fb_short_stories_title');
|
---|
296 | if (!$fb_short_stories_title){
|
---|
297 | $fb_short_stories_title = '{*actor*} commented on {*blogname*}, post title: {*post_title*} ';
|
---|
298 | }
|
---|
299 | $fb_short_stories_body = get_option('fb_short_stories_body');
|
---|
300 | if (!$fb_short_stories_body){
|
---|
301 | $fb_short_stories_body = '{*body_short*}';
|
---|
302 | }
|
---|
303 | $fb_full_stories_title = get_option('fb_full_stories_title');
|
---|
304 | if (!$fb_full_stories_title){
|
---|
305 | $fb_full_stories_title = '{*actor*} commented on {*blogname*}, post title: {*post_title*} ';
|
---|
306 | }
|
---|
307 | $fb_full_stories_body = get_option('fb_full_stories_body');
|
---|
308 | if (!$fb_full_stories_body){
|
---|
309 | $fb_full_stories_body = '{*body*}';
|
---|
310 | }
|
---|
311 | ?>
|
---|
312 |
|
---|
313 | <table class="form-table" cellspacing="2" cellpadding="5" width="100%">
|
---|
314 | <tr valign="top">
|
---|
315 | <th style="width: 33%" scope="row"><label for="fb_online_stories"><?php _e('One line stories template:', 'fbconnect') ?></label></th>
|
---|
316 | <td>
|
---|
317 | <textarea rows="3" cols="50" name="fb_online_stories" id="fb_online_stories"><?php echo htmlspecialchars(stripslashes($fb_online_stories)); ?></textarea>
|
---|
318 | </td>
|
---|
319 | </tr>
|
---|
320 | <tr valign="top">
|
---|
321 | <th style="width: 33%" scope="row"><?php _e('Short stories template:', 'fbconnect') ?></th>
|
---|
322 | <td>
|
---|
323 | <label for="fb_short_stories_title"><?php _e('Title', 'fbconnect') ?></label><br/>
|
---|
324 | <textarea rows="3" cols="50" name="fb_short_stories_title" id="fb_short_stories_title"><?php echo htmlspecialchars(stripslashes($fb_short_stories_title));?></textarea> <br/>
|
---|
325 | <label for="fb_short_stories_body"><?php _e('Body', 'fbconnect') ?></label><br/>
|
---|
326 | <textarea rows="3" cols="50" name="fb_short_stories_body" id="fb_short_stories_body"><?php echo htmlspecialchars(stripslashes($fb_short_stories_body));?></textarea>
|
---|
327 | </td>
|
---|
328 | </tr>
|
---|
329 | <tr valign="top">
|
---|
330 | <th style="width: 33%" scope="row"><?php _e('Full stories template:', 'fbconnect') ?></th>
|
---|
331 | <td>
|
---|
332 | <label for="fb_full_stories_title"><?php _e('Title', 'fbconnect') ?></label><br/>
|
---|
333 | <textarea rows="3" cols="50" name="fb_full_stories_title" id="fb_full_stories_title"><?php echo htmlspecialchars(stripslashes($fb_full_stories_title));?></textarea> <br/>
|
---|
334 | <label for="fb_full_stories_body"><?php _e('Body', 'fbconnect') ?></label><br/>
|
---|
335 | <textarea rows="3" cols="50" name="fb_full_stories_body" id="fb_full_stories_body"><?php echo htmlspecialchars(stripslashes($fb_full_stories_body));?></textarea>
|
---|
336 | </td>
|
---|
337 | </tr>
|
---|
338 |
|
---|
339 | </table>
|
---|
340 |
|
---|
341 | <?php wp_nonce_field('wp-fbconnect-info_update'); ?>
|
---|
342 | <p class="submit"><input class="button-primary" type="submit" name="template_update" value="<?php _e('Create Template', 'fbconnect') ?> »" /></p>
|
---|
343 | </form>
|
---|
344 | </div>
|
---|
345 | <?php
|
---|
346 | } // end function options_page
|
---|
347 |
|
---|
348 |
|
---|
349 | }
|
---|
350 | endif;
|
---|
351 |
|
---|
352 | ?>
|
---|