|
1 <?php |
|
2 /** |
|
3 * Core for Social accounts. |
|
4 * |
|
5 * @package Social |
|
6 * @subpackage services |
|
7 */ |
|
8 abstract class Social_Service_Account { |
|
9 |
|
10 /** |
|
11 * @var object user object |
|
12 */ |
|
13 protected $_user = array(); |
|
14 |
|
15 /** |
|
16 * @var object access keys |
|
17 */ |
|
18 protected $_keys = array(); |
|
19 |
|
20 /** |
|
21 * @var bool personal account flag |
|
22 */ |
|
23 protected $_personal = false; |
|
24 |
|
25 /** |
|
26 * @var bool universal account flag |
|
27 */ |
|
28 protected $_universal = false; |
|
29 |
|
30 /** |
|
31 * Populates the account object. |
|
32 * |
|
33 * @param object $account |
|
34 */ |
|
35 public function __construct($account) { |
|
36 $this->_user = $account->user; |
|
37 |
|
38 if (isset($account->keys)) { |
|
39 $this->_keys = $account->keys; |
|
40 } |
|
41 |
|
42 if (isset($account->personal)) { |
|
43 $this->_personal = $account->personal; |
|
44 } |
|
45 |
|
46 if (isset($account->universal)) { |
|
47 $this->_universal = $account->universal; |
|
48 } |
|
49 } |
|
50 |
|
51 /** |
|
52 * Returns an array object of the account. |
|
53 * |
|
54 * @return object |
|
55 */ |
|
56 public function as_object() { |
|
57 return (object) array( |
|
58 'user' => $this->_user, |
|
59 'keys' => $this->_keys, |
|
60 'personal' => $this->_personal, |
|
61 'universal' => $this->_universal, |
|
62 ); |
|
63 } |
|
64 |
|
65 /** |
|
66 * Returns whether the account is public or not. |
|
67 * |
|
68 * @abstract |
|
69 * @param bool|null $personal |
|
70 * @return Social_Service_Account|bool |
|
71 */ |
|
72 public function personal($personal = null) { |
|
73 if ($personal === null) { |
|
74 return $this->_personal; |
|
75 } |
|
76 |
|
77 $this->_personal = $personal; |
|
78 return $this; |
|
79 } |
|
80 |
|
81 /** |
|
82 * Returns whether the account is universal or not. |
|
83 * |
|
84 * @abstract |
|
85 * @param bool|null $universal |
|
86 * @return Social_Service_Account|bool |
|
87 */ |
|
88 public function universal($universal = null) { |
|
89 if ($universal === null) { |
|
90 return $this->_universal; |
|
91 } |
|
92 |
|
93 $this->_universal = $universal; |
|
94 return $this; |
|
95 } |
|
96 |
|
97 /** |
|
98 * Returns the account's public key. |
|
99 * |
|
100 * @return string |
|
101 */ |
|
102 public function public_key() { |
|
103 return $this->_keys->public; |
|
104 } |
|
105 |
|
106 /** |
|
107 * Returns the account's private key. |
|
108 * |
|
109 * @return string |
|
110 */ |
|
111 public function private_key() { |
|
112 return $this->_keys->secret; |
|
113 } |
|
114 |
|
115 /** |
|
116 * Does this account have a user object with it? |
|
117 * |
|
118 * [!!] This is for pre-2.0 accounts. Used to help keep views clean. |
|
119 * |
|
120 * @return bool |
|
121 */ |
|
122 public function has_user() { |
|
123 return $this->_user !== null; |
|
124 } |
|
125 |
|
126 /** |
|
127 * Default avatar. |
|
128 * |
|
129 * @return string |
|
130 */ |
|
131 public function _avatar() { |
|
132 return 'http://www.gravatar.com/avatar/a06082e4f876182b547f635d945e744e?s=32&d=mm'; |
|
133 } |
|
134 |
|
135 /** |
|
136 * Default name |
|
137 * |
|
138 * @return string |
|
139 */ |
|
140 public function _name() { |
|
141 return __('Removed Account', 'social'); |
|
142 } |
|
143 |
|
144 /** |
|
145 * Default username |
|
146 * |
|
147 * @return string |
|
148 */ |
|
149 public function _username() { |
|
150 return __('Removed Account', 'social'); |
|
151 } |
|
152 |
|
153 /** |
|
154 * Return child accounts (Facebook pages, for example) |
|
155 * |
|
156 * @return array |
|
157 */ |
|
158 public function child_accounts($update = false) { |
|
159 if ($update) { |
|
160 $this->fetch_child_accounts(); |
|
161 } |
|
162 return array(); |
|
163 } |
|
164 |
|
165 /** |
|
166 * Get child account list from service. |
|
167 * |
|
168 * @return void |
|
169 */ |
|
170 public function fetch_child_accounts() { |
|
171 } |
|
172 |
|
173 /** |
|
174 * Child account key. |
|
175 * |
|
176 * @return string |
|
177 */ |
|
178 public function child_account_key() { |
|
179 return ''; |
|
180 } |
|
181 |
|
182 /** |
|
183 * Child account avatar. |
|
184 * |
|
185 * @return string |
|
186 */ |
|
187 public function child_account_avatar() { |
|
188 return $this->_avatar(); |
|
189 } |
|
190 |
|
191 /** |
|
192 * Update child accounts of a service account |
|
193 * @abstract |
|
194 * @param array $enabled_child_ids - array of enabled child account ids |
|
195 */ |
|
196 abstract public function update_enabled_child_accounts($enabled_child_ids); |
|
197 |
|
198 } // End Social_Service_Account |