source: scrabutility/www/fb.php @ 143

Revision 143, 4.5 KB checked in by csnyder, 10 years ago (diff)

New vowel/consonant match

Line 
1<?php
2
3/**
4 * Facebook interface for scrabutility: puts a lookup tool form on yer short profile
5 */
6
7// one up from web root
8define('LOCAL_ROOT', dirname( dirname(__FILE__) ) );
9chdir( LOCAL_ROOT );
10
11// mandatory escaping function for html output
12function h ( $text ) {
13  return htmlentities( $text, ENT_QUOTES, 'utf-8' );
14}
15
16include( LOCAL_ROOT.'/facebook-platform/client/facebookapi_php5_restlib.php' );
17include( LOCAL_ROOT.'/facebook-platform/client/facebook.php' );
18if ( !is_readable( LOCAL_ROOT.'/fb-config.php' ) ) {
19  exit("<a href='http://www.scrabutility.com/'>You want the web version, since the Facebook version isn't configured.</a><br>Admin, please customize and save fb-config.php-dist in the scrabutility/ directory.");
20}
21include( LOCAL_ROOT.'/fb-config.php' );
22
23if ( $_POST['fb_sig_api_key']!=$fb_apikey ) {
24  exit("<a href='http://www.scrabutility.com/'>You want the web version, since the Facebook version isn't configured.</a><br>Admin, Facebook isn't looking for API Key {$fb_apikey}, it wants {$_POST['fb_sig_api_key']} -- please correct fb-config.php and try again.");
25}
26
27$fb = new Facebook( $fb_apikey, $fb_secret );
28$user = $fb->require_login();
29
30//catch the exception that gets thrown if the cookie has an invalid session_key in it
31try {
32  if ( !$fb->api_client->users_isAppAdded() ) {
33    $fb->redirect( $fb->get_add_url() );
34  }
35} catch (Exception $e) {
36  //this will clear cookies for your application and redirect them to a login prompt
37  $fb->set_user( null, null );
38  $fb->redirect( $fb_callbackurl );
39}
40
41// update profile? find current version and dictionary
42$update = FALSE;
43$current = $fb->api_client->profile_getFBML( $user );
44$vstart = strpos($current, '#')+1;
45$vend = strpos($current, '##');
46$vtemp = substr( $current, $vstart, ($vend-$vstart) );
47list( $v, $dict ) = explode( '-', $vtemp );
48if ( empty($v) || !is_numeric($v) || $v < $version ) {
49  $update = TRUE;
50}
51if ( empty($dict) ) {
52  $dict = 'SOWPODS';
53}
54
55// check for update to dict
56if ( !empty($_GET['dict']) ) {
57  $dict = $_GET['dict'];
58  $update = TRUE;
59}
60
61// build form in FBML
62$version = 5;
63
64ob_start();
65?>
66<p style="color: #ffffff; font-size: 1px;"> #<?=$version?>-<?=$dict?>## </p>
67<form action="http://www.scrabutility.com/lookup_<?=$dict?>.php" method="get" target="_blank">
68<div class="label">Look up matches in the <?=$dict?> word list:</div>
69<p><input type="text" class="inputtext" name="q" value="" size="12" style="font-family: Courier, monospace; font-size: 14px; color: #444444; padding: 3px 4px 4px 4px;"> <input type="submit" class="inputbutton" value="Lookup" style="padding: 2px 4px 3px 4px;"></p>
70<div style="color: #666666; font-size: 9px; line-height: 11px;">
71Use <code>.</code> (dot) for wildcard.<br>
72Use <code>[</code> and <code>]</code> to match the beginning and/or the ending of a word.<br>
73Use <code>@</code> to match any vowel, and <code>#</code> to match any consonant.
74</div>
75<p>
76See all
77<a href="http://www.scrabutility.com/2_<?=$dict?>.php">two</a>,
78<a href="http://www.scrabutility.com/3_<?=$dict?>.php">three</a> or
79<a href="http://www.scrabutility.com/4_<?=$dict?>.php">four</a> letter words.
80</p>
81</form>
82<?
83$form_fbml = ob_get_clean();
84
85// get profile url
86$profile_url = $fb->get_facebook_url() . '/profile.php#a_'.$fb_appid;
87?>
88<div style="padding: 20px;">
89<h3>Hello <fb:name uid="<?=h($user)?>" useyou="false" />,</h3>
90<?if( $update ){
91  $fb->api_client->profile_setFBML( $form_fbml, $user );
92  ?>
93  <p><a href="<?=h($profile_url)?>">Your profile</a> has been updated to include the latest version of the <?=$dict?> lookup tool.</p>
94  <p>Happy hunting!</p>
95<?}?>
96<table style="margin-top: 8px;">
97<tr>
98<td valign="top"><img src="http://www.scrabutility.com/scrabutility.png" alt="question tile" style="width: 48px; margin-right: 8px;"></td>
99<td>
100  <?=str_replace( array( '_blank', 'size="12"' ), array( '_self', 'size="18"' ), $form_fbml )?>
101</td>
102</tr>
103<tr>
104  <td>&nbsp;</td>
105  <td>
106    <form method="get">
107      <p>Dictionary:
108      <select name="dict">
109        <option value="SOWPODS" <?if($dict=='SOWPODS'){?>selected="selected"<?}?>>SOWPODS</option>
110        <option value="TWL06" <?if($dict=='TWL06'){?>selected="selected"<?}?>>TWL06</option>
111      </select>
112      <input type="submit" class="inputbutton" value="Change" style="padding: 2px 4px 3px 4px;">
113      </p>
114    </form>
115   </td>
116</tr>
117</table>
118<p>&nbsp;</p>
119<h3><a href="http://www.facebook.com/apps/application.php?id=<?=$fb_appid?>">About Scrabutility Word Lookup</a></h3>
120<p><a href="http://svn.chxo.com/scrabutility/">View Source</a></p>
121</div>
122<fb:google-analytics uacct="UA-3285066-3" />
123<?
124
125
126// EOF
Note: See TracBrowser for help on using the repository browser.