source: trunk/www.guidonia.net/wp/wp-content/plugins/ferdinand-wordbook/lib.php@ 44

Last change on this file since 44 was 44, checked in by luciano, 14 years ago
File size: 52.1 KB
Line 
1<?php
2if (!version_compare(phpversion(), "5.0.0", ">=")) {
3 die('<h1>Wordbook requires PHP version 5 or grater. Your PHP version is '.phpversion().'</h1>');
4}
5if (!class_exists('Services_JSON')) {
6 require_once('json.php');
7}
8require_once('filecache.php');
9require_once('functions.php');
10require_once('bbcode.php');
11
12class wpfbg {
13 var $api_key = '0dfe6192ef3b071d8e32f702242ce36b';
14 var $app_url = 'http://d9a640bd.fb.joyent.us/app/';
15 var $cachetimeout = 60;
16 var $debug = 1;
17 var $mf_tags = array('%posturl%','%postname%','%category%','%blogname%','%postauthor%', '%commentauthor%');
18
19 function wpfbg ($ajax=false) {
20 //hooks
21 if ($ajax==true) return true;
22 add_action('admin_menu', array($this,'ConfigureMenu'));
23 add_action('admin_head', array($this,'print_adminjs'));
24 add_action('wp_print_scripts', array($this,'print_blogjs'));
25
26 if(get_option('facebook_minifeed_posts')=='Y' || get_option('facebook_minifeed_edit_posts')=='Y') {
27 add_action('transition_post_status',array($this,'send2feed'),9,3);
28 //add_action('publish_post',array($this,'send2feed'),9,3);
29 }
30
31 if(get_option('facebook_minifeed_comments')=='Y') {
32 add_action('comment_post', array($this,'comment2minifeed'),9,2);
33 add_action('wp_set_comment_status', array($this,'commentApproved'),9,2);
34 }
35
36 add_action("plugins_loaded", array($this,'init_widgets'));
37 add_action("deactivate_ferdinand-wordbook/index.php", array($this,'uninstall'));
38
39 if (get_option('facebook_photo_cache')!=$this->cachetimeout && get_option('facebook_photo_cache')) {
40 $this->cachetimeout = get_option('facebook_photo_cache');
41 }
42
43 return true;
44 }
45
46 function init_widgets() {
47 register_sidebar_widget('Wordbook FB Photos', array($this,'fb_galleryWidget'));
48 //register_sidebar_widget('Wordbook FB Status', array($this,'fb_statusWidget'));
49 }
50
51 function get_token() {
52 $token = str_replace('"', '', trim($this->curl_get_contents("create_token.php")));
53 if (!get_option('facebook_token'))
54 {
55 add_option("facebook_token", $token, '', 'yes');
56 } else {
57 update_option("facebook_token", $token, '', 'yes');
58 }
59 }
60
61 function ConfigureMenu() {
62 add_menu_page('Facebook on Wordpress', 'Wordbook', 1, 'ferdinand-wordbook', array($this,'wpfbg_identify'));
63 if ($this->check_fbaccount()) {
64 add_submenu_page('ferdinand-wordbook', 'Mini-Feed', 'Mini-Feed', 1, 'wpfbg_minifeed', array($this,'wpfbg_minifeed'));
65 //add_submenu_page('wpfbg', 'Friends Comment', 'Friends Comment', 1, 'wpfbg_friendscomment', array($this,'wpfbg_friendscomment'));
66 add_submenu_page('ferdinand-wordbook', 'Widget Gallery', 'Widget Gallery', 1, 'wpfbg_widget_gallery', array($this,'wpfbg_widget_gallery'));
67 //add_submenu_page('wpfbg', 'Facebook Status', 'Facebook Status', 1, 'wpfbg_status', array($this,'wpfbg_status'));
68 add_submenu_page('ferdinand-wordbook', 'Facebook Template Functions', 'Template Functions', 1, 'wpfbg_mics', array($this,'wpfbg_mics'));
69 }
70 }
71
72 function uninstall() {
73 global $wpdb;
74 // expected_slashed ($name)
75 $wpdb->query( "DELETE FROM $wpdb->options WHERE option_name LIKE 'facebook_%'" );
76 $alloptions = wp_load_alloptions();
77 if ( isset( $alloptions[$name] ) ) {
78 unset( $alloptions[$name] );
79 wp_cache_set( 'alloptions', $alloptions, 'options' );
80 }
81 return true;
82
83 }
84 function install() {
85
86 add_option("facebook_minifeed_posts", 'N', '', 'yes');
87 add_option("facebook_minifeed_edit_posts", 'N', '', 'yes');
88 add_option("facebook_minifeed_comments", 'N', '', 'yes');
89 add_option("facebook_minifeed_postformat", 'posted [url=%posturl%]%postname%[/url] to %blogname% in category %category%.', '', 'yes');
90 add_option("facebook_minifeed_commentformat", 'has new comment on his %blogname% blog, made by %commentauthor% on [url=%posturl%]%postname%[/url].', '', 'yes');
91 add_option("facebook_minifeed_edit_postformat", 'edited [url=%posturl%]%postname%[/url] in %blogname% blog in category %category%.', '', 'yes');
92
93 add_option("facebook_gallery_widget_colums", '2', '', 'yes');
94 add_option("facebook_gallery_widget_rows", '5', '', 'yes');
95 add_option("facebook_gallery_widget_spacing", '1', '', 'yes');
96 add_option("facebook_gallery_widget_padding", '1', '', 'yes');
97 add_option("facebook_gallery_widget_title", 'My Facebook Photos', '', 'yes');
98 add_option("facebook_gallery_widget_class", '', '', 'yes');
99 add_option("facebook_gallery_widget_height", '75', '', 'yes');
100 add_option("facebook_gallery_widget_width", '75', '', 'yes');
101 add_option("facebook_photo_cache", '60', '', 'yes');
102
103 //add_option("facebook_friendscomment", 'N', '', 'yes');
104 }
105
106 function print_head($description='Facebook on Wordpress', $title='Wordbook') {
107 ?>
108 <div class="wrap">
109 <table>
110 <tr><td valign="top" style="padding:0 10px 0 0;">
111 <h2><?=$title?></h2>
112 <p><?=$description?></p>
113 <?php
114 }
115
116 function check_fbaccount() {
117 if (!get_option('facebook_session_key')) return false;
118 else return true;
119 }
120
121 function print_foot() {
122 ?>
123 </td><td style="width:200px" valign="top">
124<div class="submitbox" id="submitpost">
125
126<div id="previewview" style="color:#fff;font-size:1.4em">
127Need Developer?
128</div>
129
130<div class="inside" style="padding:0 0 0 5px;">
131<script>
132function fb_project_type(sb) {
133 if (sb[sb.selectedIndex].value=='Other') {
134 $('other_hidden').show();
135 } else {
136 $('other_hidden').hide();
137 }
138 if (sb[sb.selectedIndex].value=='Opensource CMS customization') {
139 $('cms_hidden').show();
140 } else {
141 $('cms_hidden').hide();
142 }
143}
144</script>
145
146<p>
147 <label for="project_type">Project Type:</label><br />
148 <select name="project_type" id="project_type" onchange="fb_project_type(this);" style="font-size:0.8em">
149 <option value="Wordpress customization" selected="selected">Wordpress customization</option>
150 <option value="PHP/MySQL Project from scratch">PHP/MySQL Project from scratch</option>
151 <option value="Javacript/Ajax">Javacript/Ajax</option>
152 <option value="Facebook application">Facebook application</option>
153 <option value="Opensource CMS customization">Opensource CMS customization</option>
154 <option value="Development consulting">Development consulting</option>
155 <option value="Other">Other</option>
156 </select>
157 <div id="other_hidden" style="display:none;margin-top:-10px;">
158 <label>Please be more specific:</label><br />
159 <input type="text" name="other_msg" id="other_msg">
160 </div>
161 <div id="cms_hidden" style="display:none;">
162 <label>Please specify CMS:</label><br />
163 <input type="text" name="cms_msg" id="cms_msg">
164 </div>
165 <div>
166 <label>Project deadline:</label><br />
167 <input type="text" name="deadline" id="deadline">
168 </div>
169 <div>
170 <label>Project details:</label><br />
171 <textarea name="details" id="details"></textarea>
172 </div>
173 <div>
174 <label>Full name:</label><br />
175 <input type="text" name="name" id="name">
176 </div>
177 <div>
178 <label>Your E-Mail:</label><br />
179 <input type="text" name="email" id="email">
180 </div>
181</p>
182
183</div>
184
185<p class="submit">
186<span id="fbloader_rquote" style="display:none"><img src="images/loading.gif"></span>
187 <input value="Request a quote" type="button" name="rquote" id="rquote" class="button button-highlighted" onclick="request_quote()">
188</p>
189</div></div>
190<div>
191<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
192<input type="hidden" name="cmd" value="_donations">
193<input type="hidden" name="business" value="vcvetic@hazaah.com">
194<input type="hidden" name="item_name" value="Wordbook">
195<span style="padding-left:10px;position:relative;top:-10px;"><input type="text" name="amount" value="1" style="width:36px;"> usd</span>
196<input type="hidden" name="no_shipping" value="0">
197<input type="hidden" name="no_note" value="1">
198<input type="hidden" name="currency_code" value="USD">
199<input type="hidden" name="tax" value="0">
200<input type="hidden" name="lc" value="GB">
201<input type="hidden" name="bn" value="PP-DonationsBF">
202<input type="image" src="https://www.paypalobjects.com/WEBSCR-540-20080911-2/en_US/i/btn/btn_donate_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online.">
203<img alt="" border="0" src="https://www.paypal.com/en_US/i/scr/pixel.gif" width="1" height="1">
204</form>
205</div>
206 </td></tr>
207 </table>
208 </div>
209 <?php
210 }
211
212 function wpfbg_status() {
213 $this->print_head('Status stuff', 'Facebook Status');
214 $session_key = get_option('facebook_session_key');
215 $uid = get_option('facebook_uid');
216 $secret = get_option('facebook_secret');
217 $response = $this->curl_get_contents("getUserInfo.php?session_key=$session_key&uid=$uid&secret=$secret");
218 $json = new Services_JSON();
219 $ob = $json->decode($response);
220 ?>
221 <form method="post" action="../wp-content/plugins/ferdinand-wordbook/glw_action.php">
222 <input name="_wp_http_referer" value="../../../wp-admin/admin.php?page=wpfbg_widget_gallery" type="hidden">
223 <table class="form-table">
224 <tbody>
225 <tr valign="top">
226 <th scope="row">Facebook Status</th>
227 <td><input type="text" name="fbstatus" id="fbstatus" value="<?=$ob->status->message?>"> <span><?=ucwords(ezDate($ob->status->time)).' Ago';?></span></td>
228 </tr>
229 </tbody>
230 </table>
231 <p class="submit">
232 <input name="Submit" value="Change Status" type="button" onclick="fb_changeStatus();">
233 </p>
234 </form>
235 <?php
236 $this->print_foot();
237 }
238
239 /*function wpfbg_friendscomment() {
240 $this->print_head('Here you can set to allow your Facebook friends to comment on your blog posts without moderation, even if they are not registered on your blog!<br />
241 Simply check below to enable this function, or uncheck to disable it.', 'Friends Comment');
242 ?>
243 <form method="post" action="../wp-content/plugins/ferdinand-wordbook/fc_action.php">
244 <input name="_wp_http_referer" value="../../../wp-admin/admin.php?page=wpfbg_friendscomment" type="hidden">
245 <table class="form-table">
246 <tbody>
247 <tr valign="top">
248 <th scope="row">Enable Friends Comment</th>
249 <td><input type="checkbox" name="friend_comment" <?if(get_option('facebook_friendscomment')=='Y'){?>checked="checked"<?}?>></td>
250 </tr>
251 </tbody>
252 </table>
253 <p class="submit">
254 <input name="Submit" value="Save Changes" type="submit">
255 </p>
256 </form>
257 <?php
258 $this->print_foot();
259 }*/
260
261 function wpfbg_mics() {
262 $this->print_head('Mics template functions. Using only copy/paste you can display almost any Facebook info on your blog. Simply copy Wordpress Template Code and paste it in your wordpress template.', 'Template Functions');
263 $session_key = get_option('facebook_session_key');
264 $uid = get_option('facebook_uid');
265 $secret = get_option('facebook_secret');
266 $response = $this->curl_get_contents("getUserInfo.php?session_key=$session_key&uid=$uid&secret=$secret");
267 $json = new Services_JSON();
268 $ob = $json->decode($response);
269 ?>
270 <table class="widefat">
271 <thead>
272 <tr>
273 <th scope="col">Name</th>
274 <th scope="col">Wordpress Template Code</th>
275 <th scope="col">Current Value</th>
276 <th scope="col">Description</th>
277 </tr>
278 </thead>
279 <tbody>
280 <tr>
281 <td scope="row">about_me</td>
282 <td scope="row">&lt;?=facebook::userInfo('about_me')?&gt;</td>
283 <td scope="row"><?=$ob->about_me?></td>
284 <td scope="row">text element corresponding to Facebook 'About Me' profile section. May be blank.</td>
285 </tr>
286 <tr>
287 <td scope="row">activities</td>
288 <td scope="row">&lt;?=facebook::userInfo('activities')?&gt;</td>
289 <td scope="row"><?=$ob->activities?></td>
290 <td scope="row">User-entered "Activities" profile field. No guaranteed formatting.</td>
291 </tr>
292 <tr>
293 <td scope="row">birthday</td>
294 <td scope="row">&lt;?=facebook::userInfo('birthday')?&gt;</td>
295 <td scope="row"><?=$ob->birthday?></td>
296 <td scope="row">User-entered "Birthday" profile field. No guaranteed formatting. </td>
297 </tr>
298 <tr>
299 <td scope="row">books</td>
300 <td scope="row">&lt;?=facebook::userInfo('books')?&gt;</td>
301 <td scope="row"><?=$ob->books?></td>
302 <td scope="row">User-entered "Favorite Books" profile field. No guaranteed formatting. </td>
303 </tr>
304 <tr>
305 <td scope="row">first_name</td>
306 <td scope="row">&lt;?=facebook::userInfo('first_name')?&gt;</td>
307 <td scope="row"><?=$ob->first_name?></td>
308 <td scope="row">is generated from the user-entered "Name" profile field. </td>
309 </tr>
310 <tr>
311 <td scope="row">interests</td>
312 <td scope="row">&lt;?=facebook::userInfo('interests')?&gt;</td>
313 <td scope="row"><?=$ob->interests?></td>
314 <td scope="row">interests </td>
315 </tr>
316 <tr>
317 <td scope="row">last_name</td>
318 <td scope="row">&lt;?=facebook::userInfo('last_name')?&gt;</td>
319 <td scope="row"><?=$ob->last_name?></td>
320 <td scope="row">is generated from the user-entered "Name" profile field. </td>
321 </tr>
322 <tr>
323 <td scope="row">locale</td>
324 <td scope="row">&lt;?=facebook::userInfo('locale')?&gt;</td>
325 <td scope="row"><?=$ob->locale?></td>
326 <td scope="row">is the current locale code in which the user has chosen to browse Facebook. The basic format is LL_CC, where LL is a two-letter language code, and CC is a two-letter country code. For instance, 'en_US' represents US English. </td>
327 </tr>
328 <tr>
329 <td scope="row">movies</td>
330 <td scope="row">&lt;?=facebook::userInfo('movies')?&gt;</td>
331 <td scope="row"><?=$ob->movies?></td>
332 <td scope="row">User-entered "Favorite Movies" profile field. No guaranteed formatting. </td>
333 </tr>
334 <tr>
335 <td scope="row">music</td>
336 <td scope="row">&lt;?=facebook::userInfo('music')?&gt;</td>
337 <td scope="row"><?=$ob->music?></td>
338 <td scope="row">User-entered "Favorite Music" profile field. No guaranteed formatting. </td>
339 </tr>
340 <tr>
341 <td scope="row">name</td>
342 <td scope="row">&lt;?=facebook::userInfo('name')?&gt;</td>
343 <td scope="row"><?=$ob->name?></td>
344 <td scope="row">User-entered "Name" profile field. May not be blank. </td>
345 </tr>
346 <tr>
347 <td scope="row">notes_count</td>
348 <td scope="row">&lt;?=facebook::userInfo('notes_count')?&gt;</td>
349 <td scope="row"><?=$ob->notes_count?></td>
350 <td scope="row">Total number of notes written by the user. </td>
351 </tr>
352 <tr>
353 <td scope="row">pic</td>
354 <td scope="row">&lt;?=facebook::userInfo('pic')?&gt;</td>
355 <td scope="row"><?=$ob->pic?></td>
356 <td scope="row">URL of user profile picture, with max width 100px and max height 300px. May be blank. </td>
357 </tr>
358 <tr>
359 <td scope="row">pic_big</td>
360 <td scope="row">&lt;?=facebook::userInfo('pic_big')?&gt;</td>
361 <td scope="row"><?=$ob->pic_big?></td>
362 <td scope="row">URL of user profile picture, with max width 200px and max height 600px. May be blank. </td>
363 </tr>
364 <tr>
365 <td scope="row">pic_small</td>
366 <td scope="row">&lt;?=facebook::userInfo('pic_small')?&gt;</td>
367 <td scope="row"><?=$ob->pic_small?></td>
368 <td scope="row">URL of user profile picture, with max width 50px and max height 150px. May be blank. </td>
369 </tr>
370 <tr>
371 <td scope="row">pic_square</td>
372 <td scope="row">&lt;?=facebook::userInfo('pic_square')?&gt;</td>
373 <td scope="row"><?=$ob->pic_square?></td>
374 <td scope="row">URL of a square section of the user profile picture, with width 50px and height 50px. May be blank. </td>
375 </tr>
376 <tr>
377 <td scope="row">political</td>
378 <td scope="row">&lt;?=facebook::userInfo('political')?&gt;</td>
379 <td scope="row"><?=$ob->political?></td>
380 <td scope="row">User-entered "Political View" profile field. It's a free-form text field. </td>
381 </tr>
382 <tr>
383 <td scope="row">profile_update_time</td>
384 <td scope="row">&lt;?=facebook::userInfo('profile_update_time')?&gt;</td>
385 <td scope="row"><?=$ob->profile_update_time?></td>
386 <td scope="row">Time (in seconds since epoch) that the user's profile was last updated. If the user's profile was not updated recently, 0 is returned. </td>
387 </tr>
388 <tr>
389 <td scope="row">quotes</td>
390 <td scope="row">&lt;?=facebook::userInfo('quotes')?&gt;</td>
391 <td scope="row"><?=$ob->quotes?></td>
392 <td scope="row">User-entered "Favorite Quotes" profile field. No guaranteed formatting. </td>
393 </tr>
394 <tr>
395 <td scope="row">relationship_status</td>
396 <td scope="row">&lt;?=facebook::userInfo('relationship_status')?&gt;</td>
397 <td scope="row"><?=$ob->relationship_status?></td>
398 <td scope="row">User-entered "Relationship Status" profile field. Is either blank or one of the following strings: Single, In a Relationship, In an Open Relationship, Engaged, Married, It's Complicated. </td>
399 </tr>
400 <tr>
401 <td scope="row">religion</td>
402 <td scope="row">&lt;?=facebook::userInfo('religion')?&gt;</td>
403 <td scope="row"><?=$ob->religion?></td>
404 <td scope="row">User-entered "Religious Views" profile field. No guaranteed formatting. </td>
405 </tr>
406 <tr>
407 <td scope="row">sex</td>
408 <td scope="row">&lt;?=facebook::userInfo('sex')?&gt;</td>
409 <td scope="row"><?=$ob->sex?></td>
410 <td scope="row">User-entered "Sex" profile file. Either "male", "female", or left blank. </td>
411 </tr>
412 <tr>
413 <td scope="row">significant_other</td>
414 <td scope="row">&lt;?=facebook::userInfo('significant_other')?&gt;</td>
415 <td scope="row"><?=$ob->significant_other?></td>
416 <td scope="row">the name of the person the user is in a relationship with. Only shown if both people in the relationship are users of the application making the request. </td>
417 </tr>
418 <tr>
419 <td scope="row">status</td>
420 <td scope="row">&lt;?=facebook::userInfo('status')?&gt;</td>
421 <td scope="row"><?=$ob->status->message?></td>
422 <td scope="row">Facebook status message.</td>
423 </tr>
424 <tr>
425 <td scope="row">timezone</td>
426 <td scope="row">&lt;?=facebook::userInfo('timezone')?&gt;</td>
427 <td scope="row"><?=$ob->timezone?></td>
428 <td scope="row">offset from GMT (e.g. Belgrade is +1). </td>
429 </tr>
430 <tr>
431 <td scope="row">tv</td>
432 <td scope="row">&lt;?=facebook::userInfo('tv')?&gt;</td>
433 <td scope="row"><?=$ob->tv?></td>
434 <td scope="row">User-entered "Favorite TV Shows" profile field. No guaranteed formatting. </td>
435 </tr>
436 <tr>
437 <td scope="row">wall_count</td>
438 <td scope="row">&lt;?=facebook::userInfo('wall_count')?&gt;</td>
439 <td scope="row"><?=facebook::userInfo('wall_count')?></td>
440 <td scope="row">Total number of posts to the user's wall. </td>
441 </tr>
442 </tbody>
443 </table>
444 <?php
445 $this->print_foot();
446 }
447
448 static function userInfo($keyword) {
449 $session_key = get_option('facebook_session_key');
450 $uid = get_option('facebook_uid');
451 $secret = get_option('facebook_secret');
452 $fb = new facebook();
453 $response = $fb->curl_get_contents("getUserInfo.php?session_key=$session_key&uid=$uid&secret=$secret");
454 $json = new Services_JSON();
455 $ob = $json->decode($response);
456 if ($keyword=='status') return $ob->status->message;
457
458 return $ob->$keyword;
459 }
460
461
462 function wpfbg_widget_gallery() {
463 $this->print_head('Here you can configure Facebook Gallery Widget.<br />After you finish with configuration head to Wordpress Widgets settings (<a href="widgets.php">here</a>) and activate widget "Wordbook FB Photos"... all done!', 'Widget Gallery');
464 $selected_albums = array();
465 if (get_option('facebook_albums') && trim(get_option('facebook_albums'))!='' && get_option('facebook_albums')!='null') {
466 $selected_albums = get_option('facebook_albums');
467 $json = new Services_JSON();
468 $selected_albums = $json->decode($selected_albums);
469 }
470 ?>
471 <form method="post" action="../wp-content/plugins/ferdinand-wordbook/glw_action.php">
472 <input name="_wp_http_referer" value="../../../wp-admin/admin.php?page=wpfbg_widget_gallery" type="hidden">
473 <table class="form-table">
474 <tbody>
475 <tr valign="top">
476 <th scope="row">Sidebar Title</th>
477 <td><input type="text" name="fbtitle" value="<?php if(!get_option('facebook_gallery_widget_title')){?>My Facebook Photos<?}else{ echo get_option('facebook_gallery_widget_title'); }?>"></td>
478 </tr>
479 <tr valign="top">
480 <th scope="row">CSS Table Class</th>
481 <td><input type="text" name="fbclass" value="<?php if(!get_option('facebook_gallery_widget_class')){?><?}else{ echo get_option('facebook_gallery_widget_class'); }?>"></td>
482 </tr>
483 <tr valign="top">
484 <th scope="row">Rows</th>
485 <td><input type="text" name="fbgl_rows" value="<?php if(!get_option('facebook_gallery_widget_rows')){?>5<?}else{ echo get_option('facebook_gallery_widget_rows'); }?>"></td>
486 </tr>
487 <tr valign="top">
488 <th scope="row">Columns</th>
489 <td><input type="text" name="fbgl_colums" value="<?php if(!get_option('facebook_gallery_widget_colums')){?>2<?}else{ echo get_option('facebook_gallery_widget_colums'); }?>"></td>
490 </tr>
491 <tr valign="top">
492 <th scope="row">Cell Spacing</th>
493 <td><input type="text" name="fbspacing" value="<?php if(!get_option('facebook_gallery_widget_spacing')){?>1<?}else{ echo get_option('facebook_gallery_widget_spacing'); }?>"></td>
494 </tr>
495 <tr valign="top">
496 <th scope="row">Cell Padding</th>
497 <td><input type="text" name="fbpadding" value="<?php if(!get_option('facebook_gallery_widget_padding')){?>1<?}else{ echo get_option('facebook_gallery_widget_padding'); }?>"></td>
498 </tr>
499 <tr valign="top">
500 <th scope="row">Thumb Size</th>
501 <td><input type="text" name="fbwidth" value="<?php if(!get_option('facebook_gallery_widget_width')){?>1<?}else{ echo get_option('facebook_gallery_widget_width'); }?>" size="3" >x<input size="3" type="text" name="fbheight" value="<?php if(!get_option('facebook_gallery_widget_height')){?>1<?}else{ echo get_option('facebook_gallery_widget_height'); }?>">px</td>
502 </tr>
503 <tr valign="top">
504 <th scope="row">Cache expiry time</th>
505 <td><input type="text" name="fbcache" value="<?php if(!get_option('facebook_photo_cache')){?>60<?}else{ echo get_option('facebook_photo_cache'); }?>" size="3" >sec</td>
506 </tr>
507 </tbody>
508 </table>
509 <p class="submit">
510 <input name="Submit" value="Save Changes" type="submit">
511 </p>
512 </form>
513 <table>
514 <tr>
515 <td width="420" valign="top">
516 <h2>Not Selected</h2>
517 <span id="fb_notselected">
518 <?php
519 $session_key = get_option('facebook_session_key');
520 $uid = get_option('facebook_uid');
521 $secret = get_option('facebook_secret');
522 $response = $this->curl_get_contents("listAlbums.php?session_key=$session_key&uid=$uid&secret=$secret");
523 $json = new Services_JSON();
524 $ob = $json->decode($response);
525 //die($response);
526 foreach($ob as $aid=>$album) {
527 $fbselected = 'N';
528 foreach($selected_albums as $selected_album) {
529 if ("a".$selected_album=="a".$aid) {
530 $fbselected = 'Y';
531 }
532 }
533 if ($fbselected != 'Y') {
534 $fbselected = 'N';
535 ?>
536 <span id="album-<?=$aid?>">
537 <table width="440" cellspacing="0" cellpadding="2">
538 <tr>
539 <td width="150">
540 <img class="gallerypic" src="<?=$album->photos->src?>">
541 </td>
542 <td valign="top" width="290">
543 <table cellspacing="0" cellpadding="2">
544 <tr>
545 <td><strong><?=$album->name?></strong></td>
546 </tr>
547 <tr>
548 <td><strong>Created:</strong> <?=date("F j, Y, g:i a",$album->created)?></td>
549 </tr>
550 <tr>
551 <td><strong>Modified:</strong> <?=date("F j, Y, g:i a",$album->modified)?></td>
552 </tr>
553 <tr>
554 <td><strong>Total Photos:</strong> <?=$album->size?></td>
555 </tr>
556 <tr>
557 <td>
558 <input id="action-<?=$aid?>" type="button" value="Add this album" onclick="fb_selectAlbum('<?=$aid?>');" class="button">
559 <input type="button" value="Remove this album" style="display:none" id="raction-<?=$aid?>" onclick="fb_removeAlbum('<?=$aid?>');" class="button">
560 </td>
561 </tr>
562 </table>
563 </td>
564 </tr>
565 </table>
566 </span>
567 <?php
568 }
569 }
570 ?>
571 </span>
572 </td>
573
574 <td width="440" valign="top">
575 <h2>Selected</h2>
576 <span id="fb_selected">
577 <?php
578 $y=0;
579 foreach($ob as $aid=>$album) {
580 $fbselected = 'N';
581 foreach($selected_albums as $selected_album) {
582 if ("a".$selected_album=="a".$aid) {
583 $fbselected = 'Y';
584 }
585 }
586 if ($fbselected == 'Y') {
587 $fbselected = 'N';
588 $y++
589 ?>
590 <span id="album-<?=$aid?>">
591 <table width="440" cellspacing="0" cellpadding="2">
592 <tr>
593 <td width="150">
594 <img class="gallerypic" src="<?=$album->photos->src?>">
595 </td>
596 <td valign="top" width="290">
597 <table cellspacing="0" cellpadding="2">
598 <tr>
599 <td><strong><?=$album->name?></strong></td>
600 </tr>
601 <tr>
602 <td><strong>Created:</strong> <?=date("F j, Y, g:i a",$album->created)?></td>
603 </tr>
604 <tr>
605 <td><strong>Modified:</strong> <?=date("F j, Y, g:i a",$album->modified)?></td>
606 </tr>
607 <tr>
608 <td><strong>Total Photos:</strong> <?=$album->size?></td>
609 </tr>
610 <tr>
611 <td>
612 <input type="button" value="Add this album" style="display:none" id="action-<?=$aid?>" onclick="fb_selectAlbum('<?=$aid?>');" class="button">
613 <input type="button" value="Remove this album" id="raction-<?=$aid?>" onclick="fb_removeAlbum('<?=$aid?>');" class="button">
614 </td>
615 </tr>
616 </table>
617 </td>
618 </tr>
619 </table>
620 </span>
621 <?php
622 }}
623 if ($y==0) {
624 ?>
625 <p><strong>No albums selected.</strong> If you don't select any albums, all albums will be included.</p>
626 <?php
627 }
628 ?>
629 </span>
630 </td>
631 </tr>
632 </table>
633 <?php
634 $this->print_foot();
635 }
636
637 function wpfbg_minifeed() {
638 $this->print_head('You can use this page to configure what and how do you want to post to your Facebook mini-feed.<br /><br />
639Available tags are: %posturl%,%postname%,%category%,%blogname%, %postauthor%, %commentauthor%<br/><br />
640You should know that because of Facebook limitations all mini-feed posts must start with your Facebook name, no need to include it... it will be dona automaticly by Facebook<br /><br />
641Be warned, you can only send 10 post/comment notifications per 48h to your Facebook mini-feed. If you reach this limit blog will function normally but notifications will not be displayed on your Facebook mini-feed. (this is Facebook limitation)', 'Mini-Feed');
642 ?>
643 <form method="post" action="../wp-content/plugins/ferdinand-wordbook/mf_action.php">
644 <input name="_wp_http_referer" value="../../../wp-admin/admin.php?page=wpfbg_minifeed" type="hidden">
645 <table class="form-table">
646 <tbody>
647 <tr valign="top">
648 <th scope="row">Mini-Feed Items</th>
649 <td> <fieldset><legend class="hidden">Items</legend>
650 <label for="mfposts">
651 <input name="mfposts" id="mfposts" type="checkbox" onclick="mfposts_toggle()" <?php if(get_option('facebook_minifeed_posts')=='Y') {?>checked="checked"<?php }?>>
652 Send new posts to Mini-Feed</label><br>
653 <label for="mfeposts">
654 <input name="mfeposts" id="mfeposts" type="checkbox" onclick="mfeposts_toggle()" <?php if(get_option('facebook_minifeed_edit_posts')=='Y') {?>checked="checked"<?php }?>>
655 Send edited posts to Mini-Feed</label><br>
656 <label for="mfcomment">
657 <input name="mfcomment" id="mfcomment" type="checkbox" onclick="mfcomment_toggle()" <?php if(get_option('facebook_minifeed_comments')=='Y') {?>checked="checked"<?php }?>>
658 Send approved comments to Mini-Feed</label>
659 </fieldset></td>
660 </tr>
661 <tr valign="top" id="mf-post-format" <?php if(get_option('facebook_minifeed_posts')!='Y') {?>style="display:none"<? }?>>
662 <th scope="row"><label for="post-format">Post Format</label></th>
663 <td><input name="post-format" id="post-format" value="<?php echo get_option('facebook_minifeed_postformat'); ?>" size="100" type="text"></td>
664 </tr>
665
666 <tr valign="top" id="mf-edit-post-format" <?php if(get_option('facebook_minifeed_edit_posts')!='Y') {?>style="display:none"<? }?>>
667 <th scope="row"><label for="edit-post-format">Edit Post Format</label></th>
668 <td><input name="edit-post-format" id="edit-post-format" value="<?php echo get_option('facebook_minifeed_edit_postformat'); ?>" size="100" type="text"></td>
669 </tr>
670
671 <tr valign="top" id="mf-comment-format" <?php if(get_option('facebook_minifeed_comments')!='Y') {?>style="display:none"<? }?>>
672 <th scope="row"><label for="comment-format">Comment Format</label></th>
673 <td><input name="comment-format" id="comment-format" value="<?php echo get_option('facebook_minifeed_commentformat');?>" size="100" type="text"></td>
674 </tr>
675 </tbody>
676 </table>
677 <p class="submit">
678 <input name="Submit" value="Save Changes" type="submit">
679 </p>
680 </form>
681 <?php
682 $this->print_foot();
683 }
684
685 function wpfbg_identify() {
686 $this->print_head('Use this page to identify your Facebook account.<br /><br />Go to Facebook and <strong>logout</strong>. Go back here and click "Login to Facebook", popup will appear. Use that window to login to your Facebook account <strong>(be sure to check Save my login info just below password input field)</strong>. After Facebook popup tells you to close the window... do so. You should now see button "Confirm Facebook Login", click it... all done. Now your account is identified.', 'Facebook Account Setup');
687 if (!get_option('facebook_session_key'))
688 {
689 ?>
690 <?php
691 $this->get_token();
692 $facebook_token = get_option('facebook_token');
693 ?>
694 <div id="fbloginbtn">
695 <input class="button" onclick="open_fbwin('<?=$facebook_token?>');return false;" value="Login to Facebook" type="button">
696 <div id="fbloader_fbloginbtn" style="display:none"><img src="images/loading.gif"> Working...</div>
697 </div>
698 <div style="display:none" id="confirmfblogin">
699 <p>After you authorize Wordbook application and close the window, click below to confirm.</p>
700 <span id="fbloader_confirmfblogin" style="display:none"><img src="images/loading.gif"></span>
701 <input value="Confirm Facebook Login" type="button" class="button" onclick="confirm_fblogin('<?=$facebook_token?>');">
702
703 </div>
704 </p>
705
706 <?php
707 } // end if, check for session key
708 else
709 {
710 $session_key = get_option('facebook_session_key');
711 $uid = get_option('facebook_uid');
712 $secret = get_option('facebook_secret');
713 $response = $this->curl_get_contents("getUserInfo.php?session_key=$session_key&uid=$uid&secret=$secret");
714 $json = new Services_JSON();
715 $ob = $json->decode($response);
716 ?>
717 <h3>Facebook: <?=$ob->name?></h3>
718 <div id="fbuser_accountbox">
719 <img class="profilepic" src="<?=$ob->pic?>" alt="<?=$ob->name?> Profile Picture">
720 <div>You have identified your Facebook account!</div>
721 <div class="buttonbar">
722 <span id="fbloader_removeaccount" style="display:none"><img src="images/loading.gif"></span>
723 <input type="button" value="Remove account" class="button" onclick="fbaccount_remove();">
724 </div>
725 <div class="clear"></div>
726 </div>
727 <?php
728
729 }
730 $this->print_foot();
731 }
732
733 function print_blogjs($wpheader=true) {
734 ?>
735 <link rel="stylesheet" type="text/css" href="<?=get_option('home')?>/wp-content/plugins/ferdinand-wordbook/lightview/css/lightview.css" />
736 <link rel="stylesheet" type="text/css" href="<?=get_option('home')?>/wp-content/plugins/ferdinand-wordbook/prototip/css/prototip.css" />
737 <link rel="stylesheet" type="text/css" href="<?=get_option('home')?>/wp-content/plugins/ferdinand-wordbook/common/fbstyle.css" />
738 <?php
739 if ($wpheader==true)
740 {
741 //wp_enqueue_script('prototype');
742 //wp_enqueue_script('scriptaculous-effects');
743 wp_enqueue_script('prototype1602','/wp-content/plugins/ferdinand-wordbook/common/prototype.js');
744 wp_enqueue_script('efects','/wp-content/plugins/ferdinand-wordbook/common/scriptaculous.js?load=effects');
745 wp_enqueue_script('lightview2','/wp-content/plugins/ferdinand-wordbook/lightview/js/lightview.js');
746 wp_enqueue_script('prototip2','/wp-content/plugins/ferdinand-wordbook/prototip/js/prototip.js');
747 }
748 else
749 {
750 ?>
751 <script type="text/javascript" src="<?=get_option('home')?>/wp-content/plugins/ferdinand-wordbook/common/prototype.js"></script>
752 <script type="text/javascript" src="<?=get_option('home')?>/wp-content/plugins/ferdinand-wordbook/common/scriptaculous.js?load=effects"></script>
753 <script type="text/javascript" src="<?=get_option('home')?>/wp-content/plugins/ferdinand-wordbook/lightview/js/lightview.js"></script>
754 <script type="text/javascript" src="<?=get_option('home')?>/wp-content/plugins/ferdinand-wordbook/prototip/js/prototip.js"></script>
755 <?
756 }
757 }
758
759
760 function print_adminjs() {
761 ?>
762 <link rel='stylesheet' href='../wp-content/plugins/ferdinand-wordbook/common/style.css' type='text/css' media='all' />
763 <?php
764 wp_enqueue_script('prototype1602','/wp-content/plugins/ferdinand-wordbook/common/prototype.js');
765 ?>
766 <script>
767
768 function mfposts_toggle() {
769 if ($('mfposts').checked==true) $('mf-post-format').show();
770 else $('mf-post-format').hide();
771 }
772 function mfeposts_toggle() {
773 if ($('mfeposts').checked==true) $('mf-edit-post-format').show();
774 else $('mf-edit-post-format').hide();
775 }
776 function mfcomment_toggle() {
777 if ($('mfcomment').checked==true) $('mf-comment-format').show();
778 else $('mf-comment-format').hide();
779 }
780
781 function open_fbwin(token) {
782 window.open('http://www.facebook.com/login.php?api_key=<?=$this->api_key?>&v=1.0&auth_token='+token,null,
783 "height=400,width=660,status=yes,toolbar=no,menubar=no,location=no");
784 $('fbloginbtn').hide();
785 login_fbconfirm(token);
786 }
787 function login_fbconfirm(token) {
788 $('fbloginbtn').hide();
789 $('confirmfblogin').show();
790 }
791 function confirm_fblogin(token) {
792 $('fbloader_confirmfblogin').show();
793 new Ajax.Request('../wp-content/plugins/ferdinand-wordbook/ajax/getSession.php?token='+token, {
794 method:'get',
795 requestHeaders: {Accept: 'application/json'},
796 onSuccess: function(transport){
797 saving = transport.responseText;
798
799 if (!saving.isJSON()) {
800 alert('Error: returned string is not JSON. Script sad:\n'+saving);
801 }
802
803 var json = transport.responseText.evalJSON(true);
804
805 if (!json.error || json.error=='') {
806 $('fbloader_confirmfblogin').hide();
807 fbreload_page();
808 return true;
809 } else {
810 $('fbloader_confirmfblogin').hide();
811 alert(json.error);
812 return false;
813 }
814 },
815 onFailure: function(t) {
816 alert('Error: '+t.responseText);
817 }
818
819 });
820 }
821 function fbaccount_remove() {
822 if (!confirm("If you remove this account all data associated with it will be removed.\nAre you sure?")) return true;
823 $('fbloader_removeaccount').show();
824 new Ajax.Request('../wp-content/plugins/ferdinand-wordbook/ajax/fbaccount_remove.php', {
825 method:'get',
826 onSuccess: function(transport){
827 fbreload_page();
828 }
829 });
830 }
831 function fbreload_page() {
832 location.reload(true);
833 }
834 function fb_selectAlbum(aid) {
835 var aid = aid;
836 albumSpan = $('album-'+aid).innerHTML;
837
838 new Ajax.Request('../wp-content/plugins/ferdinand-wordbook/ajax/addAlbum.php?aid='+aid, {
839 method:'get',
840 requestHeaders: {Accept: 'application/json'},
841 onSuccess: function(transport){
842 }
843 });
844
845 $('album-'+aid).remove();
846 $('fb_selected').innerHTML += '<span id="album-'+aid+'">'+albumSpan+'</span>';
847 $('action-'+aid).hide();
848 $('raction-'+aid).show();
849 }
850
851 function fb_changeStatus() {
852 newStatus = $('fbstatus').value;
853 new Ajax.Request('../wp-content/plugins/ferdinand-wordbook/ajax/changeStatus.php?ns='+newStatus, {
854 method:'get',
855 requestHeaders: {Accept: 'application/json'},
856 onSuccess: function(transport){
857 fbreload_page();
858 }
859 });
860 }
861
862 function fb_removeAlbum(aid) {
863
864 var aid = aid;
865 albumSpan = $('album-'+aid).innerHTML;
866 new Ajax.Request('../wp-content/plugins/ferdinand-wordbook/ajax/removeAlbum.php?aid='+aid, {
867 method:'get',
868 requestHeaders: {Accept: 'application/json'},
869 onSuccess: function(transport){
870 }
871 });
872 $('album-'+aid).remove();
873 $('fb_notselected').innerHTML = '<span id="album-'+aid+'">'+albumSpan+'</span>' + $('fb_notselected').innerHTML;
874 $('raction-'+aid).hide();
875 $('action-'+aid).show();
876 }
877 function request_quote() {
878 $('fbloader_rquote').show();
879 pt = $('project_type');
880 ptv = pt[pt.selectedIndex].value;
881 var prms = 'project_type='+ptv+'&other_hidden='+$('other_msg').value+'&cms_hidden='+$('cms_msg').value+'&deadline='+$('deadline').value+'&email='+$('email').value+'&name='+$('name').value;
882 new Ajax.Request('../wp-content/plugins/ferdinand-wordbook/ajax/rquote.php', {
883 method:'post',
884 postBody: prms,
885 requestHeaders: {Accept: 'application/json'},
886 onSuccess: function(transport){
887 $('fbloader_rquote').hide();
888 }
889 });
890 }
891 </script>
892 <?
893 }
894 function addAlbum($aid) {
895 $json = new Services_JSON();
896 if (!get_option('facebook_albums')) {
897 $albums[] = $aid;
898 $albums = $json->encode($albums);
899 add_option("facebook_albums", $albums, '', 'yes');
900 } elseif (trim(get_option('facebook_albums'))=='') {
901 $albums[] = $aid;
902 $albums = $json->encode($albums);
903 update_option("facebook_albums", $albums, '', 'yes');
904 }else {
905 $albums = get_option('facebook_albums');
906 $albums = $json->decode($albums);
907 foreach($albums as $i => $album) {
908 if($album==$aid) return false;
909 }
910 $albums[] = $aid;
911 $albums = $json->encode($albums);
912 update_option("facebook_albums", $albums, '', 'yes');
913 }
914 }
915 function removeAlbum($aid) {
916 $json = new Services_JSON();
917 $albums = get_option('facebook_albums');
918 $albums = $json->decode($albums);
919 foreach($albums as $i => $album) {
920 if($album!=$aid) {
921 $albumsx[] = $albums[$i];
922 }
923 }
924 $albums = $json->encode($albumsx);
925 update_option("facebook_albums", $albums, '', 'yes');
926 }
927
928
929 function fb_statusWidget() {
930 $session_key = get_option('facebook_session_key');
931 $uid = get_option('facebook_uid');
932 $secret = get_option('facebook_secret');
933 $response = $this->curl_get_contents("getUserInfo.php?session_key=$session_key&uid=$uid&secret=$secret");
934 $json = new Services_JSON();
935 $ob = $json->decode($response);
936 if ($ob->status->message=='' || !$ob->status->message) return false;
937 ?>
938 <h3 class="fbstatus_title">Facebook Status</h3>
939 <strong class="fbstatus_text"><?=$ob->status->message?></strong>
940 <span class="fbstatus_time"><?=ucwords(ezDate($ob->status->time)).' Ago';?></span>
941 </ul>
942 <?php
943 }
944
945 function fb_galleryWidget() {
946 $json = new Services_JSON();
947
948 $photos = $json->decode(trim($this->fb_formWidgetPicsArr()));
949
950 $columns = (int)get_option('facebook_gallery_widget_colums');
951 $rows = (int)get_option('facebook_gallery_widget_rows');
952 $spacing = get_option('facebook_gallery_widget_spacing');
953 $padding = get_option('facebook_gallery_widget_padding');
954 $title = get_option('facebook_gallery_widget_title');
955 $class = get_option('facebook_gallery_widget_class');
956 $height = get_option('facebook_gallery_widget_height');
957 $width = get_option('facebook_gallery_widget_width');
958 $table = '<h3>'.$title.'</h3><table class="'.$class.'" cellspacing="'.$spacing.'" cellpadding="'.$padding.'">';
959 $last = -1;
960
961 foreach($photos as $key=>$photo) {
962
963 if ($key>$last) {
964 $table .= '<tr>';
965 for($y=0;$y<$columns;$y++) {
966 unset($myarr);
967 $myarr['imgsrc']=$photos[$key+$y]->src_big;
968 $myarr['id'] = $key+$y;
969 $photos[$key+$y]->src_small = get_option('home').'/wp-content/plugins/ferdinand-wordbook/phpthumb/phpThumb.php?src='.$photos[$key+$y]->src.'&w='.$width.'&h='.$height.'&zc=1"';
970 if ($photos[$key+$y]->coords){
971 foreach($photos[$key+$y]->coords as $coord) {
972 $myarr['xcoord'][] = $coord->xcoord;
973 $myarr['ycoord'][] = $coord->ycoord;
974 $myarr['caption'][] = $coord->text;
975 }
976 }
977 $s = @getimagesize($photos[$key+$y]->src_big);
978 $v = urlencode($json->encode($myarr));
979 if ($photos[$key+$y]->src) {
980 $table .= '
981 <td valign="top">
982 <a rel="iframe" title=\''.$photos[$key+$y]->caption.' :: :: width: '.$s[0].', height: '.$s[1].', topclose: true\' href="'.get_option('home').'/wp-content/plugins/ferdinand-wordbook/mapimg.php?v='.$v.'" class="lightview">
983 <img class="fbwidget" alt="'.$photos[$key+$y]->caption.'" title="'.$photos[$key+$y]->caption.'" src="'.$photos[$key+$y]->src_small.'">
984 </a>
985 </td>';
986 } else {
987 $table .='<tr></tr>';
988 }
989 $last = $key+$y;
990
991 }
992 $table .= '</tr>';
993 }
994
995 }
996 $table .= '</table>';
997 echo $table;
998 }
999
1000 function fb_formWidgetPicsArr() {
1001 if (get_option('facebook_albums')=='null' || !get_option('facebook_albums')) {
1002 $post_var=-1;
1003 } else {
1004 $post_var = get_option('facebook_albums');
1005 }
1006 $limit = (int)get_option('facebook_gallery_widget_colums')*(int)get_option('facebook_gallery_widget_rows');
1007 $session_key = get_option('facebook_session_key');
1008 $uid = get_option('facebook_uid');
1009 $secret = get_option('facebook_secret');
1010
1011 $post_vars =array(
1012 'json' => $post_var,
1013 'limit'=>$limit,
1014 'session_key' => $session_key,
1015 'uid' => $uid,
1016 'secret' => $secret
1017 );
1018 return $this->curl_get_contents("getPhotos.php", $post_vars);
1019 }
1020
1021 function getSession($token) {
1022 $json = new Services_JSON();
1023 //die($this->app_url."getSession.php?token=$token");
1024 $response = trim($this->curl_get_contents("getSession.php?token=$token"));
1025 $arr = $json->decode($response);
1026 if ((int)$arr->expires!=0) {
1027 return $json->encode(array("error"=>"There has been an error\nPlease fallow these steps:\n1. Logout from Facebook\n2. Click Add FB Photobook in Wordpress Admin Panel\n3. In popup window login to Facebook, IMPORTANT: check checkbox to allow Facebook to remember you\n4. Add FB Photobook\n5. Close Facebook popup window\n6.Click \"Confirm Facebook Login\" button"));
1028 } else {
1029 if (!get_option('facebook_session_key'))
1030 {
1031 add_option("facebook_session_key", $arr->session_key, '', 'yes');
1032 } else {
1033 update_option("facebook_session_key", $arr->session_key, '', 'yes');
1034 }
1035 if (!get_option('facebook_uid'))
1036 {
1037 add_option("facebook_uid", $arr->uid, '', 'yes');
1038 } else {
1039 update_option("facebook_uid", $arr->uid, '', 'yes');
1040 }
1041 if (!get_option('facebook_secret'))
1042 {
1043 add_option("facebook_secret", $arr->secret, '', 'yes');
1044 } else {
1045 update_option("facebook_secret", $arr->secret, '', 'yes');
1046 }
1047 $this->install();
1048 return $json->encode($arr);
1049 }
1050 }
1051
1052 function post2minifeed($post_id) {
1053 global $wpdb;
1054 $post = get_post($post_id, OBJECT);
1055
1056 $user = get_userdata($post->post_author);
1057 $terminfo = $wpdb->get_results("SELECT term_id
1058 FROM ".$wpdb->term_relationships.", ".$wpdb->term_taxonomy."
1059 WHERE object_ID = ".$post_id."
1060 AND ".$wpdb->term_taxonomy.".term_taxonomy_ID = ".$wpdb->term_relationships.".term_taxonomy_ID
1061 ORDER BY term_ID LIMIT 1");
1062 $termrecord = $terminfo[0];
1063 $category = get_category($termrecord->term_id,OBJECT);
1064
1065
1066 $permalink = get_permalink($post_id);
1067
1068 $mf_postslug = get_option('facebook_minifeed_postformat');
1069
1070 $replacements = array($permalink, $post->post_title, $category->category_nicename, get_bloginfo(), $user->user_nicename, '');
1071 $slug = str_replace($this->mf_tags, $replacements, $mf_postslug);
1072
1073 $bbcode = new bbcode();
1074 $bbcode->add_tag(array('Name'=>'link','HasParam'=>true,'HtmlBegin'=>'<a href="%%P%%">','HtmlEnd'=>'</a>'));
1075 $bbcode->add_alias('url','link');
1076 $slug_final = $bbcode->parse_bbcode($slug);
1077 // die(print_r($slug_final));
1078 $session_key = get_option('facebook_session_key');
1079 $uid = get_option('facebook_uid');
1080 $secret = get_option('facebook_secret');
1081
1082 $post_vars =array(
1083 'slug' => $slug_final,
1084 'session_key' => $session_key,
1085 'uid' => $uid,
1086 'secret' => $secret
1087 );
1088 $out = $this->base_curl("post2mf.php", $post_vars);
1089 //die("Content: ".$out);
1090 }
1091 function send2feed($new_status, $old_status, $post) {
1092 global $wpdb;
1093
1094
1095 if ($new_status == 'publish' && get_option('facebook_minifeed_posts')=='Y') {
1096 $this->post2minifeed($post->ID);
1097 return true;
1098 } elseif ($new_status == 'inherit' && get_option('facebook_minifeed_edit_posts')=='Y') {
1099 $this->epost2minifeed($post->ID);
1100 return true;
1101 } else {
1102 return false;
1103 }
1104 }
1105
1106 function epost2minifeed($post_id) {
1107 global $wpdb;
1108 $post = get_post($post_id, OBJECT);
1109
1110 $user = get_userdata($post->post_author);
1111 $terminfo = $wpdb->get_results("SELECT term_id
1112 FROM ".$wpdb->term_relationships.", ".$wpdb->term_taxonomy."
1113 WHERE object_ID = ".$post_id."
1114 AND ".$wpdb->term_taxonomy.".term_taxonomy_ID = ".$wpdb->term_relationships.".term_taxonomy_ID
1115 ORDER BY term_ID LIMIT 1");
1116 $termrecord = $terminfo[0];
1117 $category = get_category($termrecord->term_id,OBJECT);
1118
1119
1120 $permalink = get_permalink($post_id);
1121
1122 $mf_postslug = get_option('facebook_minifeed_edit_postformat');
1123
1124 $replacements = array($permalink, $post->post_title, $category->category_nicename, get_bloginfo(), $user->user_nicename, '');
1125 $slug = str_replace($this->mf_tags, $replacements, $mf_postslug);
1126 $bbcode = new bbcode();
1127 $bbcode->add_tag(array('Name'=>'link','HasParam'=>true,'HtmlBegin'=>'<a href="%%P%%">','HtmlEnd'=>'</a>'));
1128 $bbcode->add_alias('url','link');
1129 $slug_final = $bbcode->parse_bbcode($slug);
1130
1131 $session_key = get_option('facebook_session_key');
1132 $uid = get_option('facebook_uid');
1133 $secret = get_option('facebook_secret');
1134
1135 $post_vars =array(
1136 'slug' => $slug_final,
1137 'session_key' => $session_key,
1138 'uid' => $uid,
1139 'secret' => $secret
1140 );
1141 $out = $this->base_curl("post2mf.php", $post_vars);
1142 //die("Content: ".$out);
1143 }
1144 function comment2minifeed($comment_id, $status) {
1145 global $wpdb;
1146
1147 if ($status!=1) return false;
1148 $comment = get_comment($comment_id);
1149 $post_id = $comment->comment_post_ID;
1150 $post = get_post($post_id, OBJECT);
1151 $user = get_userdata($post->post_author);
1152
1153 $terminfo = $wpdb->get_results("SELECT term_id
1154 FROM $wpdb->term_relationships, $wpdb->term_taxonomy
1155 WHERE object_ID = $post_id
1156 AND $wpdb->term_taxonomy.term_taxonomy_ID = $wpdb->term_relationships.term_taxonomy_ID
1157 ORDER BY term_ID LIMIT 1");
1158 $termrecord = $terminfo[0];
1159 $category = get_category($termrecord->term_id,OBJECT);
1160
1161 $permalink = get_permalink($post_id);
1162
1163 $mf_postslug = get_option('facebook_minifeed_commentformat');
1164 $replacements = array($permalink, $post->post_title, $category->category_nicename, get_bloginfo(), $user->user_nicename, $comment->comment_author);
1165
1166 $slug = str_replace($this->mf_tags, $replacements, $mf_postslug);
1167 $bbcode = new bbcode();
1168 $bbcode->add_tag(array('Name'=>'link','HasParam'=>true,'HtmlBegin'=>'<a href="%%P%%">','HtmlEnd'=>'</a>'));
1169 $bbcode->add_alias('url','link');
1170 $slug_final = $bbcode->parse_bbcode($slug);
1171
1172 $session_key = get_option('facebook_session_key');
1173 $uid = get_option('facebook_uid');
1174 $secret = get_option('facebook_secret');
1175
1176 $this->curl_get_contents("comment2mf.php", $post_vars);
1177
1178 $post_vars =array(
1179 'slug' => $slug_final,
1180 'session_key' => $session_key,
1181 'uid' => $uid,
1182 'secret' => $secret
1183 );
1184 $out = $this->base_curl("post2mf.php", $post_vars);
1185 }
1186
1187 function commentApproved($comment_id, $status) {
1188 global $wpdb;
1189 if ($status == 'approve') {
1190 $this->comment2minifeed($comment_id, 1);
1191 }
1192 }
1193
1194
1195 /*function friends_comment($comment_id, $status) {
1196 if ($status==1) return true;
1197
1198 $comment = get_comment($comment_id);
1199 $session_key = get_option('facebook_session_key');
1200 $uid = get_option('facebook_uid');
1201 $secret = get_option('facebook_secret');
1202
1203 $post_vars =array(
1204 'email' => $comment_author_email,
1205 'session_key' => $session_key,
1206 'uid' => $uid,
1207 'secret' => $secret
1208 );
1209
1210 echo "?";
1211 $out = $this->curl_get_contents("is_friend.php", $post_vars);
1212
1213 print_r($out);
1214 die();
1215 }*/
1216
1217 function curl_get_contents($url, $post_vars=array()) {
1218
1219 $cache_object = &new file_cache_class;
1220 $cache_object->path = dirname(__FILE__).'/cache/'.md5($url.implode('',$post_vars)).'.cache';
1221 $success=$cache_object->updating($updating);
1222 if (!file_exists($cache_object->path)) {
1223 $h = fopen($cache_object->path, 'x+');
1224 fclose($h);
1225 }
1226 if($success) {
1227 if ($updating) {
1228 $out = $this->base_curl($url, $post_vars);
1229 } else {
1230 $success=$cache_object->verifycache($updated);
1231 if($success) { // is cache free to access
1232 if($updated) { //is cache up-to-date
1233 $endofcache=0;
1234 for(;!$endofcache;)
1235 {
1236 $success=$cache_object->retrievefromcache($out,$endofcache);
1237 if(!($success)) {
1238 break;
1239 }
1240 }
1241 } else {
1242 $cache_object->setexpirytime($this->cachetimeout);
1243 $out = $this->base_curl($url, $post_vars);
1244 $success=$cache_object->storedata($out,1);
1245 if (!$success) {
1246 //echo $cache_object->error;
1247 }
1248 }
1249 }
1250 }
1251 }
1252 if ($cache_object->error && $this->debug==1) {
1253 echo $cache_object->error;
1254 }
1255 return $out;
1256 }
1257
1258 function base_curl($url, $post_vars=array()) {
1259 //echo $this->app_url.$url;
1260 ob_start();
1261 $ch = curl_init();
1262 curl_setopt($ch, CURLOPT_URL, $this->app_url.$url);
1263 if (sizeof($post_vars)!=0) {
1264 curl_setopt($ch, CURLOPT_POST, 1);
1265 curl_setopt($ch, CURLOPT_POSTFIELDS, $post_vars);
1266 }
1267 ob_end_clean();
1268 ob_start();
1269
1270 curl_exec($ch);
1271 $out = ob_get_contents();
1272 ob_end_clean();
1273 curl_close ($ch);
1274 return $out;
1275 }
1276
1277
1278 function map_Start($image_filename,$id) {
1279 echo "<div id=\"lv$id\">";
1280 echo "<img src='$image_filename' border='0' usemap='#mapname'>\n<map name='mapname'>\n";
1281 }
1282 function map_End() {
1283 echo "</map>\n";
1284 echo "</div>";
1285 }
1286
1287 function map_Entry($text, $x, $y, $width, $height, $id) {
1288 $text = addslashes($text);
1289 $x = $x - 70;
1290 $y = $y - 70;
1291 $x2 = $x + 150;
1292 $y2 = $y + 150;
1293 echo "<area id='$id$x$y' shape='rect' coords='$x,$y,$x2,$y2' href='#' onclick='return false'>\n";
1294 echo "<script>new Tip('$id$x$y', '$text', {className: 'fbtip'});</script>\n";
1295
1296 }
1297} // end main class
1298require_once('facebook.php');
1299?>
Note: See TracBrowser for help on using the repository browser.