1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Copyright 2017 Facebook, Inc. |
4
|
|
|
* |
5
|
|
|
* You are hereby granted a non-exclusive, worldwide, royalty-free license to |
6
|
|
|
* use, copy, modify, and distribute this software in source code or binary |
7
|
|
|
* form for use in connection with the web services and APIs provided by |
8
|
|
|
* Facebook. |
9
|
|
|
* |
10
|
|
|
* As with any software that integrates with the Facebook platform, your use |
11
|
|
|
* of this software is subject to the Facebook Developer Principles and |
12
|
|
|
* Policies [http://developers.facebook.com/policy/]. This copyright notice |
13
|
|
|
* shall be included in all copies or substantial portions of the software. |
14
|
|
|
* |
15
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
16
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
17
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
18
|
|
|
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
19
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
20
|
|
|
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
21
|
|
|
* DEALINGS IN THE SOFTWARE. |
22
|
|
|
*/ |
23
|
|
|
namespace Facebook\Helper; |
24
|
|
|
|
25
|
|
|
use Facebook\Application; |
26
|
|
|
use Facebook\Client; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @package Facebook |
30
|
|
|
*/ |
31
|
|
|
class PageTabHelper extends CanvasHelper |
32
|
|
|
{ |
33
|
|
|
/** |
34
|
|
|
* @var null|array |
35
|
|
|
*/ |
36
|
|
|
protected $pageData; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Initialize the helper and process available signed request data. |
40
|
|
|
* |
41
|
|
|
* @param Application $app the Application entity |
42
|
|
|
* @param Client $client the client to make HTTP requests |
43
|
|
|
* @param string $graphVersion the version of Graph to use |
44
|
|
|
*/ |
45
|
1 |
|
public function __construct(Application $app, Client $client, $graphVersion) |
46
|
|
|
{ |
47
|
1 |
|
parent::__construct($app, $client, $graphVersion); |
48
|
|
|
|
49
|
1 |
|
if (!$this->signedRequest) { |
50
|
|
|
return; |
51
|
|
|
} |
52
|
|
|
|
53
|
1 |
|
$this->pageData = $this->signedRequest->get('page'); |
54
|
1 |
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* Returns a value from the page data. |
58
|
|
|
* |
59
|
|
|
* @param string $key |
60
|
|
|
* @param null|mixed $default |
61
|
|
|
* |
62
|
|
|
* @return null|mixed |
63
|
|
|
*/ |
64
|
1 |
|
public function getPageData($key, $default = null) |
65
|
|
|
{ |
66
|
1 |
|
if (isset($this->pageData[$key])) { |
67
|
1 |
|
return $this->pageData[$key]; |
68
|
|
|
} |
69
|
|
|
|
70
|
1 |
|
return $default; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* Returns true if the user is an admin. |
75
|
|
|
* |
76
|
|
|
* @return bool |
77
|
|
|
*/ |
78
|
1 |
|
public function isAdmin() |
79
|
|
|
{ |
80
|
1 |
|
return $this->getPageData('admin') === true; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* Returns the page id if available. |
85
|
|
|
* |
86
|
|
|
* @return null|string |
87
|
|
|
*/ |
88
|
1 |
|
public function getPageId() |
89
|
|
|
{ |
90
|
1 |
|
return $this->getPageData('id'); |
91
|
|
|
} |
92
|
|
|
} |
93
|
|
|
|