| | 154 | * action: admin_header |
| | 155 | * |
| | 156 | * @access public |
| | 157 | * @param object $theme |
| | 158 | * @return void |
| | 159 | */ |
| | 160 | public function action_admin_header($theme) |
| | 161 | { |
| | 162 | if ($theme->page != 1) return; |
| | 163 | Stack::add('admin_header_javascript', $this->get_url() . '/js/admin.js'); |
| | 164 | Stack::add('admin_stylesheet', array($this->get_url() . '/css/admin.css', 'screen')); |
| | 165 | } |
| | 166 | |
| | 167 | /** |
| | 168 | * action: before_act_admin_ajax |
| | 169 | * |
| | 170 | * @access public |
| | 171 | * @return void |
| | 172 | */ |
| | 173 | public function action_before_act_admin_ajax() |
| | 174 | { |
| | 175 | $handler_vars = Controller::get_handler_vars(); |
| | 176 | switch ($handler_vars['context']) { |
| | 177 | case 'fireeagle_update': |
| | 178 | $user = User::identify(); |
| | 179 | $access_token = Options::get('fireeagle__access_token_' . $user->id); |
| | 180 | $access_token_secret = Options::get('fireeagle__access_token_secret_' . $user->id); |
| | 181 | if (empty($access_token) || empty($access_token_secret)) { |
| | 182 | echo json_encode(array('errorMessage' => _t('Authorize is not done!', 'fireeagle'))); |
| | 183 | die(); |
| | 184 | } |
| | 185 | |
| | 186 | $fireeagle = new FireEagleAPI($this->consumer_key, $this->consumer_secret, $access_token, $access_token_secret); |
| | 187 | try { |
| | 188 | $result = $fireeagle->update(array('address' => $handler_vars['location'])); |
| | 189 | } catch (FireEagleException $e) { |
| | 190 | echo json_encode(array('errorMessage' => $e->getMessage())); |
| | 191 | die(); |
| | 192 | } |
| | 193 | if (!is_object($result) || $result->stat != 'ok') { |
| | 194 | echo json_encode(array('errorMessage' => _t('Update failed.', 'fireeagle'))); |
| | 195 | die(); |
| | 196 | } |
| | 197 | |
| | 198 | // refresh location |
| | 199 | if (!$this->update((int)$user->id)) { |
| | 200 | echo json_encode(array('errorMessage' => _t('Update failed.', 'fireeagle'))); |
| | 201 | die(); |
| | 202 | } |
| | 203 | |
| | 204 | $location = ''; |
| | 205 | if (isset($user->info->fireeagle_location)) { |
| | 206 | $location = $user->info->fireeagle_location; |
| | 207 | } |
| | 208 | |
| | 209 | echo json_encode(array('location' => $location, 'message' => sprintf(_t('Your present place was updated to "%s".', 'fireeagle'), $location))); |
| | 210 | die(); |
| | 211 | default: |
| | 212 | break; |
| | 213 | } |
| | 214 | } |
| | 215 | |
| | 216 | /** |
| | 238 | * filter: dash_modules |
| | 239 | * |
| | 240 | * @access public |
| | 241 | * @param array $modules |
| | 242 | * @return array |
| | 243 | */ |
| | 244 | public function filter_dash_modules($modules) |
| | 245 | { |
| | 246 | $modules[] = _t('Fire Eagle', 'fireeagle'); |
| | 247 | $this->add_template('dash_fireeagle', dirname(__FILE__) . '/dash_fireeagle.php'); |
| | 248 | return $modules; |
| | 249 | } |
| | 250 | |
| | 251 | /** |
| | 252 | * filter: dash_module_fire_eagle |
| | 253 | * |
| | 254 | * @access public |
| | 255 | * @param array $module |
| | 256 | * @param string $module_id |
| | 257 | * @param object $theme |
| | 258 | * @return array |
| | 259 | */ |
| | 260 | public function filter_dash_module_fire_eagle($module, $module_id, $theme) |
| | 261 | { |
| | 262 | $module['title'] = _t('Fire Eagle', 'fireeagle'); |
| | 263 | |
| | 264 | $form = new FormUI('dash_fireeagle'); |
| | 265 | $form->append('text', 'location', 'null:unused', _t('Location: ', 'fireeagle')); |
| | 266 | $user = User::identify(); |
| | 267 | if (isset($user->info->fireeagle_location)) { |
| | 268 | $form->location->value = $user->info->fireeagle_location; |
| | 269 | } |
| | 270 | $form->append('submit', 'submit', _t('Update', 'fireeagle')); |
| | 271 | $form->properties['onsubmit'] = 'fireeagle.update(); return false;'; |
| | 272 | $theme->fireeagle_form = $form->get(); |
| | 273 | |
| | 274 | $module['content'] = $theme->fetch('dash_fireeagle'); |
| | 275 | return $module; |
| | 276 | } |
| | 277 | |
| | 278 | /** |
| | 319 | |
| | 320 | if (!isset($result->user->best_guess)) return false; |
| | 321 | $location = $result->user->best_guess; |
| | 322 | |
| | 323 | $user->info->fireeagle_longitude = $location->longitude; |
| | 324 | $user->info->fireeagle_latitude = $location->latitude; |
| | 325 | if (isset($location->name)) { |
| | 326 | $user->info->fireeagle_location = $location->name; |
| | 327 | } else { |
| | 328 | $user->info->fireeagle_location = ''; |
| | 329 | } |
| | 330 | $user->info->commit(); |
| | 331 | Plugins::act('fireeagle_after_update', $location); |
| | 332 | |
| | 333 | return true; |