Version Description
Download this release
Release Info
Developer | nextendweb |
Plugin | Nextend Social Login and Register (Facebook, Google, Twitter) |
Version | 1.0 |
Comparing to | |
See all releases |
Version 1.0
- index.html +0 -0
- licence.txt +339 -0
- nextend-fb-connect.php +145 -0
- nextend-fb-settings.php +144 -0
- readme.txt +24 -0
- sdk/base_facebook.php +1425 -0
- sdk/facebook.php +160 -0
- sdk/index.html +0 -0
- sdk/init.php +28 -0
index.html
ADDED
File without changes
|
licence.txt
ADDED
@@ -0,0 +1,339 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
GNU GENERAL PUBLIC LICENSE
|
2 |
+
Version 2, June 1991
|
3 |
+
|
4 |
+
Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
|
5 |
+
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
6 |
+
Everyone is permitted to copy and distribute verbatim copies
|
7 |
+
of this license document, but changing it is not allowed.
|
8 |
+
|
9 |
+
Preamble
|
10 |
+
|
11 |
+
The licenses for most software are designed to take away your
|
12 |
+
freedom to share and change it. By contrast, the GNU General Public
|
13 |
+
License is intended to guarantee your freedom to share and change free
|
14 |
+
software--to make sure the software is free for all its users. This
|
15 |
+
General Public License applies to most of the Free Software
|
16 |
+
Foundation's software and to any other program whose authors commit to
|
17 |
+
using it. (Some other Free Software Foundation software is covered by
|
18 |
+
the GNU Lesser General Public License instead.) You can apply it to
|
19 |
+
your programs, too.
|
20 |
+
|
21 |
+
When we speak of free software, we are referring to freedom, not
|
22 |
+
price. Our General Public Licenses are designed to make sure that you
|
23 |
+
have the freedom to distribute copies of free software (and charge for
|
24 |
+
this service if you wish), that you receive source code or can get it
|
25 |
+
if you want it, that you can change the software or use pieces of it
|
26 |
+
in new free programs; and that you know you can do these things.
|
27 |
+
|
28 |
+
To protect your rights, we need to make restrictions that forbid
|
29 |
+
anyone to deny you these rights or to ask you to surrender the rights.
|
30 |
+
These restrictions translate to certain responsibilities for you if you
|
31 |
+
distribute copies of the software, or if you modify it.
|
32 |
+
|
33 |
+
For example, if you distribute copies of such a program, whether
|
34 |
+
gratis or for a fee, you must give the recipients all the rights that
|
35 |
+
you have. You must make sure that they, too, receive or can get the
|
36 |
+
source code. And you must show them these terms so they know their
|
37 |
+
rights.
|
38 |
+
|
39 |
+
We protect your rights with two steps: (1) copyright the software, and
|
40 |
+
(2) offer you this license which gives you legal permission to copy,
|
41 |
+
distribute and/or modify the software.
|
42 |
+
|
43 |
+
Also, for each author's protection and ours, we want to make certain
|
44 |
+
that everyone understands that there is no warranty for this free
|
45 |
+
software. If the software is modified by someone else and passed on, we
|
46 |
+
want its recipients to know that what they have is not the original, so
|
47 |
+
that any problems introduced by others will not reflect on the original
|
48 |
+
authors' reputations.
|
49 |
+
|
50 |
+
Finally, any free program is threatened constantly by software
|
51 |
+
patents. We wish to avoid the danger that redistributors of a free
|
52 |
+
program will individually obtain patent licenses, in effect making the
|
53 |
+
program proprietary. To prevent this, we have made it clear that any
|
54 |
+
patent must be licensed for everyone's free use or not licensed at all.
|
55 |
+
|
56 |
+
The precise terms and conditions for copying, distribution and
|
57 |
+
modification follow.
|
58 |
+
|
59 |
+
GNU GENERAL PUBLIC LICENSE
|
60 |
+
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
61 |
+
|
62 |
+
0. This License applies to any program or other work which contains
|
63 |
+
a notice placed by the copyright holder saying it may be distributed
|
64 |
+
under the terms of this General Public License. The "Program", below,
|
65 |
+
refers to any such program or work, and a "work based on the Program"
|
66 |
+
means either the Program or any derivative work under copyright law:
|
67 |
+
that is to say, a work containing the Program or a portion of it,
|
68 |
+
either verbatim or with modifications and/or translated into another
|
69 |
+
language. (Hereinafter, translation is included without limitation in
|
70 |
+
the term "modification".) Each licensee is addressed as "you".
|
71 |
+
|
72 |
+
Activities other than copying, distribution and modification are not
|
73 |
+
covered by this License; they are outside its scope. The act of
|
74 |
+
running the Program is not restricted, and the output from the Program
|
75 |
+
is covered only if its contents constitute a work based on the
|
76 |
+
Program (independent of having been made by running the Program).
|
77 |
+
Whether that is true depends on what the Program does.
|
78 |
+
|
79 |
+
1. You may copy and distribute verbatim copies of the Program's
|
80 |
+
source code as you receive it, in any medium, provided that you
|
81 |
+
conspicuously and appropriately publish on each copy an appropriate
|
82 |
+
copyright notice and disclaimer of warranty; keep intact all the
|
83 |
+
notices that refer to this License and to the absence of any warranty;
|
84 |
+
and give any other recipients of the Program a copy of this License
|
85 |
+
along with the Program.
|
86 |
+
|
87 |
+
You may charge a fee for the physical act of transferring a copy, and
|
88 |
+
you may at your option offer warranty protection in exchange for a fee.
|
89 |
+
|
90 |
+
2. You may modify your copy or copies of the Program or any portion
|
91 |
+
of it, thus forming a work based on the Program, and copy and
|
92 |
+
distribute such modifications or work under the terms of Section 1
|
93 |
+
above, provided that you also meet all of these conditions:
|
94 |
+
|
95 |
+
a) You must cause the modified files to carry prominent notices
|
96 |
+
stating that you changed the files and the date of any change.
|
97 |
+
|
98 |
+
b) You must cause any work that you distribute or publish, that in
|
99 |
+
whole or in part contains or is derived from the Program or any
|
100 |
+
part thereof, to be licensed as a whole at no charge to all third
|
101 |
+
parties under the terms of this License.
|
102 |
+
|
103 |
+
c) If the modified program normally reads commands interactively
|
104 |
+
when run, you must cause it, when started running for such
|
105 |
+
interactive use in the most ordinary way, to print or display an
|
106 |
+
announcement including an appropriate copyright notice and a
|
107 |
+
notice that there is no warranty (or else, saying that you provide
|
108 |
+
a warranty) and that users may redistribute the program under
|
109 |
+
these conditions, and telling the user how to view a copy of this
|
110 |
+
License. (Exception: if the Program itself is interactive but
|
111 |
+
does not normally print such an announcement, your work based on
|
112 |
+
the Program is not required to print an announcement.)
|
113 |
+
|
114 |
+
These requirements apply to the modified work as a whole. If
|
115 |
+
identifiable sections of that work are not derived from the Program,
|
116 |
+
and can be reasonably considered independent and separate works in
|
117 |
+
themselves, then this License, and its terms, do not apply to those
|
118 |
+
sections when you distribute them as separate works. But when you
|
119 |
+
distribute the same sections as part of a whole which is a work based
|
120 |
+
on the Program, the distribution of the whole must be on the terms of
|
121 |
+
this License, whose permissions for other licensees extend to the
|
122 |
+
entire whole, and thus to each and every part regardless of who wrote it.
|
123 |
+
|
124 |
+
Thus, it is not the intent of this section to claim rights or contest
|
125 |
+
your rights to work written entirely by you; rather, the intent is to
|
126 |
+
exercise the right to control the distribution of derivative or
|
127 |
+
collective works based on the Program.
|
128 |
+
|
129 |
+
In addition, mere aggregation of another work not based on the Program
|
130 |
+
with the Program (or with a work based on the Program) on a volume of
|
131 |
+
a storage or distribution medium does not bring the other work under
|
132 |
+
the scope of this License.
|
133 |
+
|
134 |
+
3. You may copy and distribute the Program (or a work based on it,
|
135 |
+
under Section 2) in object code or executable form under the terms of
|
136 |
+
Sections 1 and 2 above provided that you also do one of the following:
|
137 |
+
|
138 |
+
a) Accompany it with the complete corresponding machine-readable
|
139 |
+
source code, which must be distributed under the terms of Sections
|
140 |
+
1 and 2 above on a medium customarily used for software interchange; or,
|
141 |
+
|
142 |
+
b) Accompany it with a written offer, valid for at least three
|
143 |
+
years, to give any third party, for a charge no more than your
|
144 |
+
cost of physically performing source distribution, a complete
|
145 |
+
machine-readable copy of the corresponding source code, to be
|
146 |
+
distributed under the terms of Sections 1 and 2 above on a medium
|
147 |
+
customarily used for software interchange; or,
|
148 |
+
|
149 |
+
c) Accompany it with the information you received as to the offer
|
150 |
+
to distribute corresponding source code. (This alternative is
|
151 |
+
allowed only for noncommercial distribution and only if you
|
152 |
+
received the program in object code or executable form with such
|
153 |
+
an offer, in accord with Subsection b above.)
|
154 |
+
|
155 |
+
The source code for a work means the preferred form of the work for
|
156 |
+
making modifications to it. For an executable work, complete source
|
157 |
+
code means all the source code for all modules it contains, plus any
|
158 |
+
associated interface definition files, plus the scripts used to
|
159 |
+
control compilation and installation of the executable. However, as a
|
160 |
+
special exception, the source code distributed need not include
|
161 |
+
anything that is normally distributed (in either source or binary
|
162 |
+
form) with the major components (compiler, kernel, and so on) of the
|
163 |
+
operating system on which the executable runs, unless that component
|
164 |
+
itself accompanies the executable.
|
165 |
+
|
166 |
+
If distribution of executable or object code is made by offering
|
167 |
+
access to copy from a designated place, then offering equivalent
|
168 |
+
access to copy the source code from the same place counts as
|
169 |
+
distribution of the source code, even though third parties are not
|
170 |
+
compelled to copy the source along with the object code.
|
171 |
+
|
172 |
+
4. You may not copy, modify, sublicense, or distribute the Program
|
173 |
+
except as expressly provided under this License. Any attempt
|
174 |
+
otherwise to copy, modify, sublicense or distribute the Program is
|
175 |
+
void, and will automatically terminate your rights under this License.
|
176 |
+
However, parties who have received copies, or rights, from you under
|
177 |
+
this License will not have their licenses terminated so long as such
|
178 |
+
parties remain in full compliance.
|
179 |
+
|
180 |
+
5. You are not required to accept this License, since you have not
|
181 |
+
signed it. However, nothing else grants you permission to modify or
|
182 |
+
distribute the Program or its derivative works. These actions are
|
183 |
+
prohibited by law if you do not accept this License. Therefore, by
|
184 |
+
modifying or distributing the Program (or any work based on the
|
185 |
+
Program), you indicate your acceptance of this License to do so, and
|
186 |
+
all its terms and conditions for copying, distributing or modifying
|
187 |
+
the Program or works based on it.
|
188 |
+
|
189 |
+
6. Each time you redistribute the Program (or any work based on the
|
190 |
+
Program), the recipient automatically receives a license from the
|
191 |
+
original licensor to copy, distribute or modify the Program subject to
|
192 |
+
these terms and conditions. You may not impose any further
|
193 |
+
restrictions on the recipients' exercise of the rights granted herein.
|
194 |
+
You are not responsible for enforcing compliance by third parties to
|
195 |
+
this License.
|
196 |
+
|
197 |
+
7. If, as a consequence of a court judgment or allegation of patent
|
198 |
+
infringement or for any other reason (not limited to patent issues),
|
199 |
+
conditions are imposed on you (whether by court order, agreement or
|
200 |
+
otherwise) that contradict the conditions of this License, they do not
|
201 |
+
excuse you from the conditions of this License. If you cannot
|
202 |
+
distribute so as to satisfy simultaneously your obligations under this
|
203 |
+
License and any other pertinent obligations, then as a consequence you
|
204 |
+
may not distribute the Program at all. For example, if a patent
|
205 |
+
license would not permit royalty-free redistribution of the Program by
|
206 |
+
all those who receive copies directly or indirectly through you, then
|
207 |
+
the only way you could satisfy both it and this License would be to
|
208 |
+
refrain entirely from distribution of the Program.
|
209 |
+
|
210 |
+
If any portion of this section is held invalid or unenforceable under
|
211 |
+
any particular circumstance, the balance of the section is intended to
|
212 |
+
apply and the section as a whole is intended to apply in other
|
213 |
+
circumstances.
|
214 |
+
|
215 |
+
It is not the purpose of this section to induce you to infringe any
|
216 |
+
patents or other property right claims or to contest validity of any
|
217 |
+
such claims; this section has the sole purpose of protecting the
|
218 |
+
integrity of the free software distribution system, which is
|
219 |
+
implemented by public license practices. Many people have made
|
220 |
+
generous contributions to the wide range of software distributed
|
221 |
+
through that system in reliance on consistent application of that
|
222 |
+
system; it is up to the author/donor to decide if he or she is willing
|
223 |
+
to distribute software through any other system and a licensee cannot
|
224 |
+
impose that choice.
|
225 |
+
|
226 |
+
This section is intended to make thoroughly clear what is believed to
|
227 |
+
be a consequence of the rest of this License.
|
228 |
+
|
229 |
+
8. If the distribution and/or use of the Program is restricted in
|
230 |
+
certain countries either by patents or by copyrighted interfaces, the
|
231 |
+
original copyright holder who places the Program under this License
|
232 |
+
may add an explicit geographical distribution limitation excluding
|
233 |
+
those countries, so that distribution is permitted only in or among
|
234 |
+
countries not thus excluded. In such case, this License incorporates
|
235 |
+
the limitation as if written in the body of this License.
|
236 |
+
|
237 |
+
9. The Free Software Foundation may publish revised and/or new versions
|
238 |
+
of the General Public License from time to time. Such new versions will
|
239 |
+
be similar in spirit to the present version, but may differ in detail to
|
240 |
+
address new problems or concerns.
|
241 |
+
|
242 |
+
Each version is given a distinguishing version number. If the Program
|
243 |
+
specifies a version number of this License which applies to it and "any
|
244 |
+
later version", you have the option of following the terms and conditions
|
245 |
+
either of that version or of any later version published by the Free
|
246 |
+
Software Foundation. If the Program does not specify a version number of
|
247 |
+
this License, you may choose any version ever published by the Free Software
|
248 |
+
Foundation.
|
249 |
+
|
250 |
+
10. If you wish to incorporate parts of the Program into other free
|
251 |
+
programs whose distribution conditions are different, write to the author
|
252 |
+
to ask for permission. For software which is copyrighted by the Free
|
253 |
+
Software Foundation, write to the Free Software Foundation; we sometimes
|
254 |
+
make exceptions for this. Our decision will be guided by the two goals
|
255 |
+
of preserving the free status of all derivatives of our free software and
|
256 |
+
of promoting the sharing and reuse of software generally.
|
257 |
+
|
258 |
+
NO WARRANTY
|
259 |
+
|
260 |
+
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
|
261 |
+
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
|
262 |
+
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
|
263 |
+
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
|
264 |
+
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
265 |
+
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
|
266 |
+
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
|
267 |
+
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
|
268 |
+
REPAIR OR CORRECTION.
|
269 |
+
|
270 |
+
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
271 |
+
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
|
272 |
+
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
|
273 |
+
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
|
274 |
+
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
|
275 |
+
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
|
276 |
+
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
|
277 |
+
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
|
278 |
+
POSSIBILITY OF SUCH DAMAGES.
|
279 |
+
|
280 |
+
END OF TERMS AND CONDITIONS
|
281 |
+
|
282 |
+
How to Apply These Terms to Your New Programs
|
283 |
+
|
284 |
+
If you develop a new program, and you want it to be of the greatest
|
285 |
+
possible use to the public, the best way to achieve this is to make it
|
286 |
+
free software which everyone can redistribute and change under these terms.
|
287 |
+
|
288 |
+
To do so, attach the following notices to the program. It is safest
|
289 |
+
to attach them to the start of each source file to most effectively
|
290 |
+
convey the exclusion of warranty; and each file should have at least
|
291 |
+
the "copyright" line and a pointer to where the full notice is found.
|
292 |
+
|
293 |
+
<one line to give the program's name and a brief idea of what it does.>
|
294 |
+
Copyright (C) <year> <name of author>
|
295 |
+
|
296 |
+
This program is free software; you can redistribute it and/or modify
|
297 |
+
it under the terms of the GNU General Public License as published by
|
298 |
+
the Free Software Foundation; either version 2 of the License, or
|
299 |
+
(at your option) any later version.
|
300 |
+
|
301 |
+
This program is distributed in the hope that it will be useful,
|
302 |
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
303 |
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
304 |
+
GNU General Public License for more details.
|
305 |
+
|
306 |
+
You should have received a copy of the GNU General Public License along
|
307 |
+
with this program; if not, write to the Free Software Foundation, Inc.,
|
308 |
+
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
309 |
+
|
310 |
+
Also add information on how to contact you by electronic and paper mail.
|
311 |
+
|
312 |
+
If the program is interactive, make it output a short notice like this
|
313 |
+
when it starts in an interactive mode:
|
314 |
+
|
315 |
+
Gnomovision version 69, Copyright (C) year name of author
|
316 |
+
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
317 |
+
This is free software, and you are welcome to redistribute it
|
318 |
+
under certain conditions; type `show c' for details.
|
319 |
+
|
320 |
+
The hypothetical commands `show w' and `show c' should show the appropriate
|
321 |
+
parts of the General Public License. Of course, the commands you use may
|
322 |
+
be called something other than `show w' and `show c'; they could even be
|
323 |
+
mouse-clicks or menu items--whatever suits your program.
|
324 |
+
|
325 |
+
You should also get your employer (if you work as a programmer) or your
|
326 |
+
school, if any, to sign a "copyright disclaimer" for the program, if
|
327 |
+
necessary. Here is a sample; alter the names:
|
328 |
+
|
329 |
+
Yoyodyne, Inc., hereby disclaims all copyright interest in the program
|
330 |
+
`Gnomovision' (which makes passes at compilers) written by James Hacker.
|
331 |
+
|
332 |
+
<signature of Ty Coon>, 1 April 1989
|
333 |
+
Ty Coon, President of Vice
|
334 |
+
|
335 |
+
This General Public License does not permit incorporating your program into
|
336 |
+
proprietary programs. If your program is a subroutine library, you may
|
337 |
+
consider it more useful to permit linking proprietary applications with the
|
338 |
+
library. If this is what you want to do, use the GNU Lesser General
|
339 |
+
Public License instead of this License.
|
nextend-fb-connect.php
ADDED
@@ -0,0 +1,145 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/*
|
3 |
+
Plugin Name: Nextend Facebook Connect
|
4 |
+
Plugin URI: http://nextendweb.com/
|
5 |
+
Description: This plugins helps you create Facebook login and register buttons. The login and register process only takes one click.
|
6 |
+
Version: 1.0
|
7 |
+
Author: Roland Soos
|
8 |
+
License: GPL2
|
9 |
+
*/
|
10 |
+
|
11 |
+
/* Copyright 2012 Roland Soos - Nextend (email : roland@nextendweb.com)
|
12 |
+
|
13 |
+
This program is free software; you can redistribute it and/or modify
|
14 |
+
it under the terms of the GNU General Public License, version 2, as
|
15 |
+
published by the Free Software Foundation.
|
16 |
+
|
17 |
+
This program is distributed in the hope that it will be useful,
|
18 |
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
19 |
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
20 |
+
GNU General Public License for more details.
|
21 |
+
|
22 |
+
You should have received a copy of the GNU General Public License
|
23 |
+
along with this program; if not, write to the Free Software
|
24 |
+
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
25 |
+
*/
|
26 |
+
|
27 |
+
define( 'NEW_FB_LOGIN', 1 );
|
28 |
+
if ( ! defined( 'NEW_FB_LOGIN_PLUGIN_BASENAME' ) )
|
29 |
+
define( 'NEW_FB_LOGIN_PLUGIN_BASENAME', plugin_basename( __FILE__ ) );
|
30 |
+
|
31 |
+
register_activation_hook(__FILE__, 'nextend_fb_connect_install');
|
32 |
+
|
33 |
+
function nextend_fb_connect_install(){
|
34 |
+
global $wpdb;
|
35 |
+
|
36 |
+
$table_name = $wpdb->prefix . "social_users";
|
37 |
+
|
38 |
+
$sql = "CREATE TABLE $table_name (
|
39 |
+
`ID` int(11) NOT NULL,
|
40 |
+
`type` varchar(20) NOT NULL,
|
41 |
+
`identifier` varchar(100) NOT NULL,
|
42 |
+
KEY `ID` (`ID`,`type`)
|
43 |
+
);";
|
44 |
+
|
45 |
+
require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
|
46 |
+
dbDelta($sql);
|
47 |
+
|
48 |
+
}
|
49 |
+
|
50 |
+
add_action('parse_request', new_fb_login);
|
51 |
+
function new_fb_login(){
|
52 |
+
global $wp, $wpdb;
|
53 |
+
if($wp->request == 'loginFacebook'){
|
54 |
+
require(dirname(__FILE__).'/sdk/init.php');
|
55 |
+
|
56 |
+
$user = $facebook->getUser();
|
57 |
+
|
58 |
+
if ($user && is_user_logged_in()) {
|
59 |
+
header( 'Location: '.$_GET['redirect'] ) ;
|
60 |
+
exit;
|
61 |
+
}else{
|
62 |
+
$loginUrl = $facebook->getLoginUrl(array('redirect_uri' => site_url('loginFacebook/doauth')) );
|
63 |
+
$_SESSION['redirect'] = isset($_GET['redirect']) ? $_GET['redirect'] : site_url();
|
64 |
+
header( 'Location: '.$loginUrl ) ;
|
65 |
+
exit;
|
66 |
+
}
|
67 |
+
}elseif($wp->request == 'loginFacebook/doauth'){
|
68 |
+
require(dirname(__FILE__).'/sdk/init.php');
|
69 |
+
$user = $facebook->getUser();
|
70 |
+
if($user){
|
71 |
+
// Register or Login
|
72 |
+
try {
|
73 |
+
// Proceed knowing you have a logged in user who's authenticated.
|
74 |
+
$user_profile = $facebook->api('/me');
|
75 |
+
$ID = $wpdb->get_var($wpdb->prepare('
|
76 |
+
SELECT ID FROM '.$wpdb->prefix.'social_users WHERE type = "fb" AND identifier = "'.$user_profile['id'].'"
|
77 |
+
'));
|
78 |
+
if($ID == NULL){ // Register
|
79 |
+
$ID = email_exists($user_profile['email']);
|
80 |
+
if($ID == false){ // Real register
|
81 |
+
$random_password = wp_generate_password( $length=12, $include_standard_special_chars=false );
|
82 |
+
$ID = wp_create_user( 'Facebook - '.$user_profile['name'], $random_password, $user_profile['email'] );
|
83 |
+
}
|
84 |
+
$wpdb->insert(
|
85 |
+
$wpdb->prefix.'social_users',
|
86 |
+
array(
|
87 |
+
'ID' => $ID,
|
88 |
+
'type' => 'fb',
|
89 |
+
'identifier' => $user_profile['id']
|
90 |
+
),
|
91 |
+
array(
|
92 |
+
'%d',
|
93 |
+
'%s',
|
94 |
+
'%s'
|
95 |
+
)
|
96 |
+
);
|
97 |
+
}
|
98 |
+
|
99 |
+
if($ID){ // Login
|
100 |
+
wp_set_auth_cookie($ID, true, false);
|
101 |
+
header( 'Location: '.$_SESSION['redirect'] );
|
102 |
+
unset($_SESSION['redirect']);
|
103 |
+
exit;
|
104 |
+
}
|
105 |
+
exit;
|
106 |
+
} catch (FacebookApiException $e) {
|
107 |
+
echo '<pre>'.htmlspecialchars(print_r($e, true)).'</pre>';
|
108 |
+
$user = null;
|
109 |
+
}
|
110 |
+
exit;
|
111 |
+
}else{
|
112 |
+
echo "There was an error with the FB auth!\n";
|
113 |
+
exit;
|
114 |
+
}
|
115 |
+
}
|
116 |
+
}
|
117 |
+
|
118 |
+
function new_fb_login_url(){
|
119 |
+
return site_url('loginFacebook');
|
120 |
+
}
|
121 |
+
|
122 |
+
|
123 |
+
/* Options Page */
|
124 |
+
require_once(trailingslashit(dirname(__FILE__)) . "nextend-fb-settings.php");
|
125 |
+
|
126 |
+
if(class_exists('NextendFBSettings')) {
|
127 |
+
$nextendfbsettings = new NextendFBSettings();
|
128 |
+
|
129 |
+
if(isset($nextendfbsettings)) {
|
130 |
+
add_action('admin_menu', array(&$nextendfbsettings, 'NextendFB_Menu'), 1);
|
131 |
+
}
|
132 |
+
}
|
133 |
+
|
134 |
+
add_filter( 'plugin_action_links', 'nextend_fb_plugin_action_links', 10, 2 );
|
135 |
+
|
136 |
+
function nextend_fb_plugin_action_links( $links, $file ) {
|
137 |
+
if ( $file != NEW_FB_LOGIN_PLUGIN_BASENAME )
|
138 |
+
return $links;
|
139 |
+
$settings_link = '<a href="' . menu_page_url( 'nextend-fb-connect', false ) . '">'
|
140 |
+
. esc_html( __( 'Settings', 'nextend-fb-connect' ) ) . '</a>';
|
141 |
+
|
142 |
+
array_unshift( $links, $settings_link );
|
143 |
+
|
144 |
+
return $links;
|
145 |
+
}
|
nextend-fb-settings.php
ADDED
@@ -0,0 +1,144 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/*
|
3 |
+
Nextend FB Connect Settings Page
|
4 |
+
*/
|
5 |
+
|
6 |
+
$newfb_status = "normal";
|
7 |
+
|
8 |
+
if(isset($_POST['newfb_update_options'])) {
|
9 |
+
if($_POST['newfb_update_options'] == 'Y') {
|
10 |
+
update_option("nextend_fb_connect", maybe_serialize($_POST));
|
11 |
+
$newfb_status = 'update_success';
|
12 |
+
}
|
13 |
+
}
|
14 |
+
|
15 |
+
if(!class_exists('NextendFBSettings')) {
|
16 |
+
class NextendFBSettings {
|
17 |
+
function NextendFB_Options_Page() {
|
18 |
+
$domain = get_option('siteurl');
|
19 |
+
$domain = str_replace(array('http://', 'https://'), array('',''), $domain);
|
20 |
+
$domain = str_replace('www.', '', $domain);
|
21 |
+
$a = explode("/",$domain);
|
22 |
+
$domain = $a[0];
|
23 |
+
?>
|
24 |
+
|
25 |
+
<div class="wrap">
|
26 |
+
<div id="newfb-options">
|
27 |
+
<div id="newfb-title"><h2>Nextend Facebook Connect Settings</h2></div>
|
28 |
+
<?php
|
29 |
+
global $newfb_status;
|
30 |
+
if($newfb_status == 'update_success')
|
31 |
+
$message =__('Configuration updated', 'nextend-fb-connect') . "<br />";
|
32 |
+
else if($newfb_status == 'update_failed')
|
33 |
+
$message =__('Error while saving options', 'nextend-fb-connect') . "<br />";
|
34 |
+
else
|
35 |
+
$message = '';
|
36 |
+
|
37 |
+
if($message != "") {
|
38 |
+
?>
|
39 |
+
<div class="updated"><strong><p><?php
|
40 |
+
echo $message;
|
41 |
+
?></p></strong></div><?php
|
42 |
+
} ?>
|
43 |
+
<div id="newfb-desc">
|
44 |
+
<p><?php _e('This plugins helps you create Facebook login and register buttons. The login and register process only takes one click and you can fully customize the buttons with images and other assets.', 'nextend-fb-connect'); ?></p>
|
45 |
+
<h3><?php _e('Setup', 'nextend-fb-connect'); ?></h3>
|
46 |
+
<p>
|
47 |
+
<?php _e('<ol><li><a href="https://developers.facebook.com/apps/?action=create" target="_blank">Create a facebook app!</a></li>', 'nextend-fb-connect'); ?>
|
48 |
+
<?php _e('<li>Choose an App Name, it can be anything you like</li>', 'nextend-fb-connect'); ?>
|
49 |
+
<?php _e('<li>Click on <b>Continue</b></li>', 'nextend-fb-connect'); ?>
|
50 |
+
<?php _e('<li>Go to the newly created <b>App settings page</b> and click <b>Edit Settings</b></li>', 'nextend-fb-connect'); ?>
|
51 |
+
<?php _e('<li>Fill out <b>App Domains</b> field with: <b>'.$domain.'</b></li>', 'nextend-fb-connect'); ?>
|
52 |
+
<?php _e('<li>Click on <b>Website with Facebook Login</b> tab abd fill out <b>Site URL</b> field with: <b>'.get_option('siteurl').'</b></li>', 'nextend-fb-connect'); ?>
|
53 |
+
<?php _e('<li>Click on <b>Save changes</b> and the top of the page contains the <b>App Id</b> and <b>App secret</b> which you have to copy and past below.</li>', 'nextend-fb-connect'); ?>
|
54 |
+
<?php _e('<li><b>Save changes!</b></li></ol>', 'nextend-fb-connect'); ?>
|
55 |
+
|
56 |
+
|
57 |
+
</p>
|
58 |
+
<h3><?php _e('Usage', 'nextend-fb-connect'); ?></h3>
|
59 |
+
<h4><?php _e('Simple link', 'nextend-fb-connect'); ?></h4>
|
60 |
+
<p><?php _e('<a href="'.get_option('siteurl').'/loginFacebook?redirect='.get_option('siteurl').'" onclick="window.location = \''.get_option('siteurl').'/loginFacebook?redirect=\'+window.location.href; return false;">Click here to login or register with Facebook</a>', 'nextend-fb-connect'); ?></p>
|
61 |
+
|
62 |
+
<h4><?php _e('Image button', 'nextend-fb-connect'); ?></h4>
|
63 |
+
<p><?php _e('<a href="'.get_option('siteurl').'/loginFacebook?redirect='.get_option('siteurl').'" onclick="window.location = \''.get_option('siteurl').'/loginFacebook?redirect=\'+window.location.href; return false;"> <img src="HereComeTheImage" /> </a>', 'nextend-fb-connect'); ?></p>
|
64 |
+
|
65 |
+
<h3><?php _e('Note', 'nextend-fb-connect'); ?></h3>
|
66 |
+
<p><?php _e('If the Facebook user\'s email address already used by another member of your site, the facebook profile will be automatically linked to the existing profile!', 'nextend-fb-connect'); ?></p>
|
67 |
+
|
68 |
+
</div>
|
69 |
+
|
70 |
+
<!--right-->
|
71 |
+
<div class="postbox-container" style="float:right;width:30%;">
|
72 |
+
<div class="metabox-holder">
|
73 |
+
<div class="meta-box-sortables">
|
74 |
+
|
75 |
+
<!--about-->
|
76 |
+
<div id="newfb-about" class="postbox">
|
77 |
+
<h3 class="hndle"><?php _e('About this plugin', 'nextend-fb-connect'); ?></h3>
|
78 |
+
<div class="inside"><ul>
|
79 |
+
<li><a href="http://wordpress.org/extend/plugins/nextend-facebook-connect/"><?php _e('Plugin URI', 'nextend-fb-connect'); ?></a></li>
|
80 |
+
<li><a href="http://profiles.wordpress.org/nextendweb" target="_blank"><?php _e('Author URI', 'nextend-fb-connect'); ?></a></li>
|
81 |
+
</ul></div>
|
82 |
+
</div>
|
83 |
+
<!--about end-->
|
84 |
+
|
85 |
+
<!--others-->
|
86 |
+
<!--others end-->
|
87 |
+
|
88 |
+
</div></div></div>
|
89 |
+
<!--right end-->
|
90 |
+
|
91 |
+
<!--left-->
|
92 |
+
<div class="postbox-container" style="float:left;width: 69%;">
|
93 |
+
<div class="metabox-holder">
|
94 |
+
<div class="meta-box-sortabless">
|
95 |
+
|
96 |
+
<!--setting-->
|
97 |
+
<div id="newfb-setting" class="postbox">
|
98 |
+
<h3 class="hndle"><?php _e('Settings', 'nextend-fb-connect'); ?></h3>
|
99 |
+
<?php $nextend_fb_connect = maybe_unserialize(get_option('nextend_fb_connect')); ?>
|
100 |
+
|
101 |
+
<form method="post" action="<?php echo get_bloginfo("wpurl"); ?>/wp-admin/options-general.php?page=nextend-fb-connect">
|
102 |
+
<input type="hidden" name="newfb_update_options" value="Y">
|
103 |
+
|
104 |
+
<table class="form-table">
|
105 |
+
<tr>
|
106 |
+
<th scope="row"><?php _e('Facebook App ID:', 'nextend-fb-connect'); ?></th>
|
107 |
+
<td>
|
108 |
+
<input type="text" name="fb_appid" value="<?php echo $nextend_fb_connect['fb_appid']; ?>" />
|
109 |
+
</td>
|
110 |
+
</tr>
|
111 |
+
|
112 |
+
<tr>
|
113 |
+
<th scope="row"><?php _e('Facebook App Secret:', 'nextend-fb-connect'); ?></th>
|
114 |
+
<td>
|
115 |
+
<input type="text" name="fb_secret" value="<?php echo $nextend_fb_connect['fb_secret']; ?>" />
|
116 |
+
</td>
|
117 |
+
</tr>
|
118 |
+
</table>
|
119 |
+
|
120 |
+
<p class="submit">
|
121 |
+
<input style="margin-left: 10%;" type="submit" name="Submit" value="<?php _e('Save Changes', 'nextend-fb-connect'); ?>" />
|
122 |
+
</p>
|
123 |
+
</form>
|
124 |
+
</div>
|
125 |
+
<!--setting end-->
|
126 |
+
|
127 |
+
<!--others-->
|
128 |
+
<!--others end-->
|
129 |
+
|
130 |
+
</div></div></div>
|
131 |
+
<!--left end-->
|
132 |
+
|
133 |
+
</div>
|
134 |
+
</div>
|
135 |
+
<?php
|
136 |
+
}
|
137 |
+
|
138 |
+
function NextendFB_Menu() {
|
139 |
+
add_options_page(__('Nextend FB Connect'), __('Nextend FB Connect'), 'manage_options', 'nextend-fb-connect', array(__CLASS__,'NextendFB_Options_Page'));
|
140 |
+
}
|
141 |
+
|
142 |
+
}
|
143 |
+
}
|
144 |
+
?>
|
readme.txt
ADDED
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
=== Nextend Facebook Connect ===
|
2 |
+
Contributors: nextendweb
|
3 |
+
Tags: facebook, register, login, social connect, social
|
4 |
+
Requires at least: 3.0
|
5 |
+
Tested up to: 3.4
|
6 |
+
Stable tag: 1.0
|
7 |
+
|
8 |
+
This plugins helps you create Facebook login and register buttons. The login and register process only takes one click.
|
9 |
+
|
10 |
+
== Description ==
|
11 |
+
|
12 |
+
This plugins helps you create Facebook login and register buttons. The login and register process only takes one click and you can fully customize the buttons with images and other assets.
|
13 |
+
|
14 |
+
== Installation ==
|
15 |
+
|
16 |
+
Extract the zip file and just drop the contents in the wp-content/plugins/ directory of your WordPress installation and then activate the Plugin from Plugins page.
|
17 |
+
Create a facebook app => https://developers.facebook.com/apps/?action=create
|
18 |
+
Choose an App Name, it can be anything you like
|
19 |
+
Click on Continue
|
20 |
+
Go to the newly created App settings page and click Edit Settings
|
21 |
+
Fill out App Domains field with: your domain name
|
22 |
+
Click on Website with Facebook Login tab abd fill out Site URL field with: http://yoursiteurl.com
|
23 |
+
Click on Save changes and the top of the page contains the App Id and App secret which you have to copy and past below.
|
24 |
+
Save changes!
|
sdk/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 FacebookApiException 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 BaseFacebook
|
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 BaseFacebook
|
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 BaseFacebook
|
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 BaseFacebook
|
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 BaseFacebook
|
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 BaseFacebook
|
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 (FacebookApiException $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 BaseFacebook 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 BaseFacebook 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 (FacebookApiException $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 (FacebookApiException $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 FacebookApiException
|
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 FacebookApiException
|
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 FacebookApiException
|
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 FacebookApiException(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 FacebookApiException($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 BaseFacebook::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 |
+
}
|
sdk/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 "base_facebook.php";
|
19 |
+
|
20 |
+
/**
|
21 |
+
* Extends the BaseFacebook class with the intent of using
|
22 |
+
* PHP sessions to store user ids and access tokens.
|
23 |
+
*/
|
24 |
+
class Facebook extends BaseFacebook
|
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 BaseFacebook::__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 |
+
}
|
sdk/index.html
ADDED
File without changes
|
sdk/init.php
ADDED
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/* Copyright 2012 Roland Soos - Nextend (email : roland@nextendweb.com)
|
3 |
+
|
4 |
+
This program is free software; you can redistribute it and/or modify
|
5 |
+
it under the terms of the GNU General Public License, version 2, as
|
6 |
+
published by the Free Software Foundation.
|
7 |
+
|
8 |
+
This program is distributed in the hope that it will be useful,
|
9 |
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
10 |
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
11 |
+
GNU General Public License for more details.
|
12 |
+
|
13 |
+
You should have received a copy of the GNU General Public License
|
14 |
+
along with this program; if not, write to the Free Software
|
15 |
+
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
16 |
+
*/
|
17 |
+
if ( !defined( 'NEW_FB_LOGIN' ) ) {
|
18 |
+
return;
|
19 |
+
}
|
20 |
+
|
21 |
+
require(dirname(__FILE__).'/facebook.php');
|
22 |
+
|
23 |
+
$settings = maybe_unserialize(get_option('nextend_fb_connect'));
|
24 |
+
|
25 |
+
$facebook = new Facebook(array(
|
26 |
+
'appId' => $settings['fb_appid'],
|
27 |
+
'secret' => $settings['fb_secret'],
|
28 |
+
));
|