- return true;
- }
-
- function onStartAvatarFormData($action)
- {
- $user = common_current_user();
- $hasGravatar = $this->hasGravatar($user->id);
-
- if($hasGravatar) {
- return false;
- }
- }
-
- function onEndAvatarFormData($action)
- {
- $user = common_current_user();
- $hasGravatar = $this->hasGravatar($user->id);
-
- if(!empty($user->email) && !$hasGravatar) { //and not gravatar already set
- $action->elementStart('form', array('method' => 'post',
- 'id' => 'form_settings_gravatar_add',
- 'class' => 'form_settings',
- 'action' =>
- common_local_url('avatarsettings')));
- $action->elementStart('fieldset', array('id' => 'settings_gravatar_add'));
- $action->element('legend', null, _m('Set Gravatar'));
- $action->hidden('token', common_session_token());
- $action->element('p', 'form_guide',
- _m('If you want to use your Gravatar image, click "Add".'));
- $action->element('input', array('type' => 'submit',
- 'id' => 'settings_gravatar_add_action-submit',
- 'name' => 'add',
- 'class' => 'submit',
- 'value' => _m('Add')));
- $action->elementEnd('fieldset');
- $action->elementEnd('form');
- } elseif($hasGravatar) {
- $action->elementStart('form', array('method' => 'post',
- 'id' => 'form_settings_gravatar_remove',
- 'class' => 'form_settings',
- 'action' =>
- common_local_url('avatarsettings')));
- $action->elementStart('fieldset', array('id' => 'settings_gravatar_remove'));
- $action->element('legend', null, _m('Remove Gravatar'));
- $action->hidden('token', common_session_token());
- $action->element('p', 'form_guide',
- _m('If you want to remove your Gravatar image, click "Remove".'));
- $action->element('input', array('type' => 'submit',
- 'id' => 'settings_gravatar_remove_action-submit',
- 'name' => 'remove',
- 'class' => 'submit',
- 'value' => _m('Remove')));
- $action->elementEnd('fieldset');
- $action->elementEnd('form');
- } else {
- $action->element('p', 'form_guide',
- _m('To use a Gravatar first enter in an email address.'));
- }
- }
-
- function onStartAvatarSaveForm($action)
- {
- if ($action->arg('add')) {
- $result = $this->gravatar_save();
-
- if($result['success']===true) {
- common_broadcast_profile(common_current_user()->getProfile());
- }
-
- $action->showForm($result['message'], $result['success']);
-
- return false;
- } else if ($action->arg('remove')) {
- $result = $this->gravatar_remove();
-
- if($result['success']===true) {
- common_broadcast_profile(common_current_user()->getProfile());
- }
-
- $action->showForm($result['message'], $result['success']);
-
- return false;
- } else {
- return true;
- }
- }
-
- function hasGravatar($id) {
- $avatar = new Avatar();
- $avatar->profile_id = $id;
- if ($avatar->find()) {
- while ($avatar->fetch()) {
- if($avatar->filename == null) {
- return true;