Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 99 lines (73 sloc) 3.605 kb
889e041 @craig552uk Renamed primary scripts
authored
1 <?php
2 /****************************************
3 Author: Craig Russell
4 Date: 11 Jan 2011
5
6 Plugin for Raportive http://rapportive.com/
7 API development docs and discussion at http://groups.google.com/group/raplet-dev
8
9 Searches for user in LDAP Directory based upon email address.
10 Returns various attributes for display alongside GMail thread.
11
12 Requires LDAP and JSON modules for PHP
13 http://php.net/manual/en/book.ldap.php
14 http://php.net/manual/en/book.json.php
15
16 ****************************************/
17
18 include_once('settings.php');
19 include_once('lib-ldap.php');
20
21 // Get data from query String
22 $get_data['email'] = (isset($_GET['email'])) ? $_GET['email'] : "";
23 $get_data['name'] = (isset($_GET['name'])) ? $_GET['name'] : "";
24 $get_data['twitter_username'] = (isset($_GET['twitter_username'])) ? $_GET['twitter_username'] : "";
25 $get_data['callback'] = (isset($_GET['callback'])) ? $_GET['callback'] : "";
26 $get_data['show'] = (isset($_GET['show'])) ? $_GET['show'] : "";
27 $get_data['oauth_token'] = (isset($_GET['oauth_token'])) ? $_GET['oauth_token'] : "";
28
29 if ($get_data['show'] == "metadata"){
30
31 // Set required metadata values
32 $json_data['name'] = $rapplet_meta['name'];
33 $json_data['description'] = $rapplet_meta['description'];
34 $json_data['welcome_text'] = $rapplet_meta['welcome_text'];
35 $json_data['icon_url'] = $rapplet_meta['icon_url'];
36 $json_data['config_url'] = $rapplet_meta['config_url'];
37 $json_data['preview_url'] = $rapplet_meta['preview_url'];
38 $json_data['provider_name'] = $rapplet_meta['provider_name'];
39 $json_data['provider_url'] = $rapplet_meta['provider_url'];
40
41 // Set optional metadata values
42 if ($rapplet_meta['data_provider_name'] != "") $json_data['data_provider_name'] = $rapplet_meta['data_provider_name'];
43 if ($rapplet_meta['data_provider_url'] != "") $json_data['dat_provider_url'] = $rapplet_meta['data_provider_url'];
44
45 }else{ // ($get_data['show'] != "metadata")
46
47 // Found_info flag defaults to true
48 $found_info = true;
49
50 $conn = my_ldap_connect();
51
52 // If connected to server and provided valid token
53 if (is_resource($conn) && my_ldap_verify_token($conn, $get_data['oauth_token'])) {
54 // Search for users with matching email address
55 $search_result = my_ldap_search($conn, "mail=".$get_data['email']);
56
57 // No matching users found
58 if (count($search_result) == 0) { $found_info = false; }
59 }else{
60 // Bind to LDAP server failed
61 $found_info = false;
62 }
63
64 // If user information has been found...
65 if ($found_info){
66
67 // Build HTML list of user information
68 $html = "<ul>";
69 foreach ($search_result as $k => $v){
70 $html = $html."<li><span>".htmlspecialchars($k)."</span>".htmlspecialchars($v)."</li>";
71 }
72 $html = $html."</ul>";
73 // Set return status
74 $status = 200;
75
76 }else{
77
78 // No user info to return
79 $html = "";
80 $status = 404;
81
82 }
83 $json_data = array('html'=>$html, 'css'=>$css, 'js'=>$js, 'status'=>$status);
84
85 } // End if($get_data['show'] == "metadata")
86
87 // Repair escape slash bug in json_encode()
88 // http://bugs.php.net/bug.php?id=49366
89 $json_return = str_replace('\\/', '/', json_encode($json_data));
90
91
92 // Set Content-type
93 header('Content-type: text/javascript');
94
95 // Return Callback and JSON for Rapportive
96 echo $get_data['callback']."(".$json_return.")";
97
98 ?>
Something went wrong with that request. Please try again.