/**
  *
  * Change notifications form
  *
  */
 public function init()
 {
     $cname = explode('_', get_class());
     $this->preInit(end($cname));
     // use template file
     $this->setDecorators(array(array('ViewScript', array('viewScript' => 'forms/Notifications.phtml'))));
     // fields
     $ProfilesMeta = new Application_Model_ProfilesMeta();
     $notifications_meta = json_decode($ProfilesMeta->getMetaValue('bulk_notifications'), true);
     $n1 = new Zend_Form_Element_Checkbox('notification_email_1');
     $n1->setDecorators(array('ViewHelper', 'Errors'))->setValue(isset($notifications_meta['notification_email_1']) && $notifications_meta['notification_email_1'] == 1 ? 1 : 0)->setLabel($this->translator->translate('Email when someone posts a new comment'))->setCheckedValue("1")->setUncheckedValue("0");
     $n2 = new Zend_Form_Element_Checkbox('notification_email_2');
     $n2->setDecorators(array('ViewHelper', 'Errors'))->setValue(isset($notifications_meta['notification_email_2']) && $notifications_meta['notification_email_2'] == 1 ? 1 : 0)->setLabel($this->translator->translate('Email when someone likes your post'))->setCheckedValue("1")->setUncheckedValue("0");
     $n3 = new Zend_Form_Element_Checkbox('notification_email_3');
     $n3->setDecorators(array('ViewHelper', 'Errors'))->setValue(isset($notifications_meta['notification_email_3']) && $notifications_meta['notification_email_3'] == 1 ? 1 : 0)->setLabel($this->translator->translate('Email when someone follows you'))->setCheckedValue("1")->setUncheckedValue("0");
     $n4 = new Zend_Form_Element_Checkbox('notification_email_4');
     $n4->setDecorators(array('ViewHelper', 'Errors'))->setValue(isset($notifications_meta['notification_email_4']) && $notifications_meta['notification_email_4'] == 1 ? 1 : 0)->setLabel($this->translator->translate('Email on new friends'))->setCheckedValue("1")->setUncheckedValue("0");
     $n6 = new Zend_Form_Element_Checkbox('notification_email_6');
     $n6->setDecorators(array('ViewHelper', 'Errors'))->setValue(isset($notifications_meta['notification_email_6']) && $notifications_meta['notification_email_6'] == 1 ? 1 : 0)->setLabel($this->translator->translate('Email when you lose a follower'))->setCheckedValue("1")->setUncheckedValue("0");
     $n7 = new Zend_Form_Element_Checkbox('notification_email_7');
     $n7->setDecorators(array('ViewHelper', 'Errors'))->setValue(isset($notifications_meta['notification_email_7']) && $notifications_meta['notification_email_7'] == 1 ? 1 : 0)->setLabel($this->translator->translate('Email when someone posts on your wall'))->setCheckedValue("1")->setUncheckedValue("0");
     $n8 = new Zend_Form_Element_Checkbox('notification_email_8');
     $n8->setDecorators(array('ViewHelper', 'Errors'))->setValue(isset($notifications_meta['notification_email_8']) && $notifications_meta['notification_email_8'] == 1 ? 1 : 0)->setLabel($this->translator->translate('Email when someone sends you a private message'))->setCheckedValue("1")->setUncheckedValue("0");
     $submit = new Zend_Form_Element_Submit('submitbtn');
     $submit->setDecorators(array('ViewHelper'))->setLabel($this->translator->translate('Update'))->setAttrib('class', 'submit btn btn-default');
     $this->addElements(array($n1, $n2, $n3, $n4, $n6, $n7, $n8, $submit));
     $this->postInit();
 }
Beispiel #2
0
 /**
  *
  * Edit Group form
  *
  */
 public function init()
 {
     $cname = explode('_', get_class());
     $this->preInit(end($cname));
     // use template file
     $this->setDecorators(array(array('ViewScript', array('viewScript' => 'forms/EditGroup.phtml'))));
     // get group from database
     $request = Zend_Controller_Front::getInstance()->getRequest();
     $group = $request->getParam('name');
     $Profiles = new Application_Model_Profiles();
     $ProfilesMeta = new Application_Model_ProfilesMeta();
     $profile = $Profiles->getProfile($group, false, true);
     $owners_profile = $Profiles->getProfileByField('id', $profile->owner);
     $username_minchars = Zend_Registry::get('config')->get('username_minchars');
     $username_maxchars = Zend_Registry::get('config')->get('username_maxchars');
     // fields
     $id = new Zend_Form_Element_Hidden('id');
     $id->setValue($profile->id);
     $name = new Zend_Form_Element_Text('name');
     $name->setDecorators(array('ViewHelper', 'Errors'))->setLabel($this->translator->translate('Group Name'))->setValue($profile->name)->setIgnore(true)->setAttrib('readonly', true)->setAttrib('class', 'form-control');
     $screenname = new Zend_Form_Element_Text('screen_name');
     $screenname->setDecorators(array('ViewHelper', 'Errors'))->addFilter('StringTrim')->setValue($profile->screen_name)->addValidator('alnum', false, array('allowWhiteSpace' => true))->addValidator('stringLength', false, array($username_minchars, $username_maxchars))->setErrorMessages(array(sprintf($this->translator->translate('Please choose a valid name between %d and %d characters'), $username_minchars, $username_maxchars)))->setLabel($this->translator->translate('Screen Name'))->setRequired(true)->setAttrib('class', 'form-control');
     $description = new Zend_Form_Element_Textarea('description');
     $description->setDecorators(array('ViewHelper', 'Errors'))->setAttrib('COLS', '')->setAttrib('ROWS', '4')->addFilter('StripTags')->setValue($ProfilesMeta->getMetaValue('description', $profile->id))->setLabel($this->translator->translate('About this group'))->setAttrib('class', 'form-control');
     $profile_privacy = new Zend_Form_Element_Select('profile_privacy');
     $profile_privacy->setDecorators(array('ViewHelper', 'Errors'))->setMultiOptions(Zend_Registry::get('group_privacy_array'))->setErrorMessages(array($this->translator->translate('Select group visibility')))->setLabel($this->translator->translate('Select group visibility'))->setRequired(true)->setValue($profile->profile_privacy)->setAttrib('class', 'form-control');
     $is_hidden = new Zend_Form_Element_Checkbox('is_hidden');
     $is_hidden->setDecorators(array('ViewHelper', 'Errors'))->setValue(isset($profile->is_hidden) && $profile->is_hidden == 1 ? 1 : 0)->setLabel($this->translator->translate('Remove?'))->setCheckedValue("1")->setUncheckedValue("0");
     $submit = new Zend_Form_Element_Submit('formsubmit');
     $submit->setDecorators(array('ViewHelper'))->setLabel($this->translator->translate('Save'))->setAttrib('class', 'submit btn btn-default');
     $this->addElements(array($id, $name, $screenname, $profile_privacy, $description, $is_hidden, $submit));
     $this->postInit();
 }
 /**
  * Read / Compose a new message (via ajax)
  */
 public function newAction()
 {
     $current_user = Zend_Auth::getInstance()->getIdentity();
     $request = $this->getRequest();
     $to_user = $request->getParam('to', false);
     $offset = $request->getParam('offset', false);
     $Profiles = new Application_Model_Profiles();
     $ProfilesMeta = new Application_Model_ProfilesMeta();
     $Connections = new Application_Model_Connections();
     $Messages = new Application_Model_Messages();
     $Notifications = new Application_Model_Notifications();
     $message_form = new Application_Form_Message();
     $this->view->message_form = $message_form;
     $user = $Profiles->getProfile($to_user);
     $json_ret = array('errors' => '', 'html' => '', 'offset' => '');
     if (!$user || !isset($user->id) || $user->type != 'user') {
         $json_ret['errors'] = $this->view->translate('This user does not exist');
         // exit
         $this->getHelper('json')->sendJson($json_ret);
     }
     $users_meta = $ProfilesMeta->getMetaValues($user->id);
     // check private message privacy
     if ($current_user->role != 'admin' && $current_user->role != 'reviewer' && isset($users_meta['contact_privacy']) && $users_meta['contact_privacy'] == 'f' && !$Connections->areFriends($current_user->id, $user->id)) {
         $json_ret['errors'] = $this->view->translate('Private profile (friends only)');
         // exit
         $this->getHelper('json')->sendJson($json_ret);
     }
     $this->view->to_screen_name = $user->screen_name;
     if ($request->isPost() && $message_form->isValid($_POST)) {
         $content = $message_form->getValue('content');
         $result = $Messages->sendMessage($user->id, $content);
         if (!$result) {
             $json_ret['errors'] = $this->view->translate('Server-side error');
             // exit
             $this->getHelper('json')->sendJson($json_ret);
         }
         // mark as read
         $Messages->markAsRead($user->id);
     }
     // get new messages
     $messages = $Messages->getMessages($user->id, $offset);
     // clear email notifications since you are looking at them right now
     $Notifications->clearEmailNotifications(8);
     if (!empty($messages)) {
         // send last visible message
         $last = end($messages);
         $json_ret['offset'] = $last['message_id'];
         foreach ($messages as $message) {
             $this->view->message = $message;
             $json_ret['html'] .= $this->view->render('/partial/message.phtml');
         }
     }
     $this->getHelper('json')->sendJson($json_ret);
 }
Beispiel #4
0
 /**
  * Login user
  */
 public static function loginUser($user_data, $authAdapter, $authStorage)
 {
     $Profiles = new Application_Model_Profiles();
     $ProfilesMeta = new Application_Model_ProfilesMeta();
     // everything ok, login user
     $user_data = $authAdapter->getResultRowObject();
     // update fields
     $Profiles->updateField($user_data->name, 'relogin_request', 0);
     $authStorage->write($user_data);
     // update last login date
     $ProfilesMeta->metaUpdate('last_login', Application_Plugin_Common::now(), $user_data->id);
     // set user specific language after login
     $session = new Zend_Session_Namespace('Default');
     $session->language = $user_data->language;
     return;
 }
Beispiel #5
0
 /**
  *
  * Edit Profile form
  *
  */
 public function init()
 {
     $cname = explode('_', get_class());
     $this->preInit(end($cname));
     // use template file
     $this->setDecorators(array(array('ViewScript', array('viewScript' => 'forms/Profile.phtml'))));
     // get user from database
     $Profiles = new Application_Model_Profiles();
     $ProfilesMeta = new Application_Model_ProfilesMeta();
     $profile = $Profiles->getProfile(Zend_Auth::getInstance()->getIdentity()->name, true);
     $all_meta = $ProfilesMeta->getMetaValues($profile->id);
     $username_minchars = Zend_Registry::get('config')->get('username_minchars');
     $username_maxchars = Zend_Registry::get('config')->get('username_maxchars');
     // fields
     $id = new Zend_Form_Element_Hidden('id');
     $id->setValue($profile->id);
     $name = new Zend_Form_Element_Text('name');
     $name->setDecorators(array('ViewHelper', 'Errors'))->setLabel($this->translator->translate('Username'))->setValue($profile->name)->setIgnore(true)->setAttrib('readonly', true)->setAttrib('class', 'form-control');
     $email = new Zend_Form_Element_Text('email');
     $email->setDecorators(array('ViewHelper', 'Errors'))->setLabel($this->translator->translate('Email'))->setValue($profile->email)->setIgnore(true)->setAttrib('readonly', true)->setAttrib('class', 'form-control');
     $screenname = new Zend_Form_Element_Text('screen_name');
     $screenname->setDecorators(array('ViewHelper', 'Errors'))->addFilter('StringTrim')->setValue($profile->screen_name)->addValidator('alnum', false, array('allowWhiteSpace' => true))->addValidator('stringLength', false, array($username_minchars, $username_maxchars))->setErrorMessages(array(sprintf($this->translator->translate('Please choose a valid name between %d and %d characters'), $username_minchars, $username_maxchars)))->setLabel($this->translator->translate('Screen Name'))->setRequired(true)->setAttrib('class', 'form-control');
     $description = new Zend_Form_Element_Textarea('description');
     $description->setDecorators(array('ViewHelper', 'Errors'))->setAttrib('COLS', '')->setAttrib('ROWS', '4')->addFilter('StripTags')->setValue(isset($all_meta['description']) ? $all_meta['description'] : '')->setLabel($this->translator->translate('About you'))->setAttrib('class', 'form-control');
     $profile_privacy = new Zend_Form_Element_Select('profile_privacy');
     $profile_privacy->setDecorators(array('ViewHelper', 'Errors'))->setMultiOptions(Zend_Registry::get('profile_privacy_array'))->setErrorMessages(array($this->translator->translate('Select profile visibility')))->setLabel($this->translator->translate('Profile visibility'))->setRequired(true)->setValue($profile->profile_privacy)->setAttrib('class', 'form-control');
     $birthday = new Application_Form_Element_Date('birthday');
     $birthday->setDecorators(array('ViewHelper', 'Errors'))->setAttrib('class', 'form-control')->setLabel($this->translator->translate('Date of birth'))->setErrorMessages(array($this->translator->translate('Please enter a valid date')))->setYearSpan(1920, date('Y') - 1);
     if (isset($all_meta['birthday'])) {
         $timestamp = strtotime($all_meta['birthday']);
         $birthday->setValue(array('day' => date('d', $timestamp), 'month' => date('m', $timestamp), 'year' => date('Y', $timestamp)));
     }
     $gender = new Zend_Form_Element_Select('gender');
     $gender->setDecorators(array('ViewHelper', 'Errors'))->setMultiOptions(Zend_Registry::get('genders_array'))->setErrorMessages(array($this->translator->translate('Please select something')))->setLabel($this->translator->translate('Gender'))->setRequired(true)->setValue(isset($all_meta['gender']) ? $all_meta['gender'] : '')->setAttrib('class', 'form-control');
     $online_status = new Zend_Form_Element_Select('show_online_status');
     $online_status->setDecorators(array('ViewHelper', 'Errors'))->setMultiOptions(Zend_Registry::get('onlinestatus_array'))->setErrorMessages(array($this->translator->translate('Select profile visibility')))->setLabel($this->translator->translate('Online Status'))->setRequired(true)->setValue(isset($all_meta['show_online_status']) ? $all_meta['show_online_status'] : 's')->setAttrib('class', 'form-control');
     $contact_privacy = new Zend_Form_Element_Select('contact_privacy');
     $contact_privacy->setDecorators(array('ViewHelper', 'Errors'))->setMultiOptions(Zend_Registry::get('contactprivacy_array'))->setErrorMessages(array($this->translator->translate('Please select something')))->setLabel($this->translator->translate('Who can contact me?'))->setRequired(true)->setValue(isset($all_meta['contact_privacy']) ? $all_meta['contact_privacy'] : 'e')->setAttrib('class', 'form-control');
     $location = new Zend_Form_Element_Text('location');
     $location->setDecorators(array('ViewHelper', 'Errors'))->setRequired(false)->setLabel($this->translator->translate('Location'))->setAttrib('class', 'form-control')->addFilter('StripTags')->setValue(isset($all_meta['location']) ? $all_meta['location'] : '')->setErrorMessages(array($this->translator->translate('Enter a valid location')));
     $website = new Zend_Form_Element_Text('website');
     $website->setDecorators(array('ViewHelper', 'Errors'))->setRequired(false)->setLabel($this->translator->translate('Website'))->setAttrib('class', 'form-control')->addFilter('StripTags')->setValue(isset($all_meta['website']) ? $all_meta['website'] : '')->setErrorMessages(array($this->translator->translate('Enter a valid website')));
     $submit = new Zend_Form_Element_Submit('formsubmit');
     $submit->setDecorators(array('ViewHelper'))->setLabel($this->translator->translate('Save'))->setAttrib('class', 'submit btn btn-default form-control');
     $this->addElements(array($id, $name, $email, $screenname, $gender, $profile_privacy, $online_status, $contact_privacy, $description, $location, $website, $birthday, $submit));
     $this->postInit();
 }
 /**
  * heartbeat actions (via continuous ajax call)
  */
 public function heartbeatAction()
 {
     $Notifications = new Application_Model_Notifications();
     $notifications = $Notifications->getNotifications(true, 10);
     $notifications_count = $Notifications->getUnreadNotificationsCount();
     $this->view->notifications = $notifications;
     $notifications_html = $this->view->render('/partial/notifications_popover.phtml');
     // new messages count
     $Messages = new Application_Model_Messages();
     $new_messages_count = $Messages->getMessagesCount(false, true);
     $ProfilesMeta = new Application_Model_ProfilesMeta();
     // we will use timestamp format here since it's easier to calculate diff with ANSI SQL
     $ProfilesMeta->metaUpdate('last_heartbeat', time());
     $out = array('notification_count' => $notifications_count, 'notification_html' => $notifications_html, 'new_messages' => $new_messages_count);
     // trigger hooks
     Zend_Registry::get('hooks')->trigger('hook_app_heartbeat', $out);
     $this->_helper->json($out);
 }
 /**
  *
  * Change network background
  *
  */
 public function init()
 {
     $cname = explode('_', get_class());
     $this->preInit(end($cname));
     // use template file
     $this->setDecorators(array(array('ViewScript', array('viewScript' => 'forms/CustomBackground.phtml'))));
     // load settings
     $Profiles = new Application_Model_Profiles();
     $ProfilesMeta = new Application_Model_ProfilesMeta();
     $request = Zend_Controller_Front::getInstance()->getRequest();
     $request_profile_id = $request->getParam('id', false);
     $profile = $Profiles->getProfileByField('id', $request_profile_id);
     if (Zend_Auth::getInstance()->getIdentity()->role == 'admin' && $request_profile_id || $request_profile_id && $Profiles->getProfile($profile->name, false, true)) {
         // admin or own group & page
         $profile_id = $request_profile_id;
     } else {
         // editing profile
         $profile_id = Zend_Auth::getInstance()->getIdentity()->id;
     }
     $all_meta = $ProfilesMeta->getMetaValues($profile_id);
     // fields
     $background_image = new Zend_Form_Element_File('background');
     $background_image->setDecorators(array('File', 'Errors'))->setLabel($this->translator->translate('Choose Picture (jpg, png or gif)'))->addValidator('Count', false, 1)->addValidator('Size', false, Zend_Registry::get('config')->get('max_file_upload_size'))->addValidator('Extension', false, 'jpg,jpeg,png,gif');
     $background_image->getValidator('Count')->setMessage($this->translator->translate('File not allowed or too big'));
     $background_image->getValidator('Size')->setMessage($this->translator->translate('File not allowed or too big'));
     $background_image->getValidator('Extension')->setMessage($this->translator->translate('File not allowed or too big'));
     $background_repeat = new Zend_Form_Element_Checkbox('background_repeat');
     $background_repeat->setDecorators(array('ViewHelper', 'Errors'))->setValue(isset($all_meta['background_repeat']) && $all_meta['background_repeat'] == 1 ? 1 : 0)->setLabel($this->translator->translate('Repeat background'))->setCheckedValue("1")->setUncheckedValue("0");
     $background_scroll = new Zend_Form_Element_Checkbox('background_scroll');
     $background_scroll->setDecorators(array('ViewHelper', 'Errors'))->setValue(isset($all_meta['background_scroll']) && $all_meta['background_scroll'] == 1 ? 1 : 0)->setLabel($this->translator->translate('Scroll background'))->setCheckedValue("1")->setUncheckedValue("0");
     $background_stretch = new Zend_Form_Element_Checkbox('background_stretch');
     $background_stretch->setDecorators(array('ViewHelper', 'Errors'))->setValue(isset($all_meta['background_stretch']) && $all_meta['background_stretch'] == 1 ? 1 : 0)->setLabel($this->translator->translate('Stretch background'))->setCheckedValue("1")->setUncheckedValue("0");
     $disable_image = new Zend_Form_Element_Checkbox('background_noimage');
     $disable_image->setDecorators(array('ViewHelper', 'Errors'))->setValue(isset($all_meta['background_noimage']) && $all_meta['background_noimage'] == 1 ? 1 : 0)->setLabel($this->translator->translate('Disable custom image'))->setCheckedValue("1")->setUncheckedValue("0");
     $submit = new Zend_Form_Element_Submit('formsubmit');
     $submit->setDecorators(array('ViewHelper'))->setLabel($this->translator->translate('Save'))->setAttrib('class', 'submit btn btn-default');
     $this->addElements(array($background_image, $background_repeat, $background_scroll, $background_stretch, $disable_image, $submit));
     $this->postInit();
 }
 /**
  *
  * Edit Page form (admin only)
  *
  */
 public function init()
 {
     $cname = explode('_', get_class());
     $this->preInit(end($cname));
     // use template file
     $this->setDecorators(array(array('ViewScript', array('viewScript' => 'forms/AdminPage.phtml'))));
     // get group from database
     $request = Zend_Controller_Front::getInstance()->getRequest();
     $request_profile_id = $request->getParam('id');
     $Profiles = new Application_Model_Profiles();
     $ProfilesMeta = new Application_Model_ProfilesMeta();
     $profile = $Profiles->getProfileByField('id', $request_profile_id);
     $owners_profile = $Profiles->getProfileByField('id', $profile->owner);
     // fields
     $profile_id = new Zend_Form_Element_Text('id');
     $profile_id->setDecorators(array('ViewHelper', 'Errors'))->setLabel($this->translator->translate('Id'))->setValue($profile->id)->setIgnore(true)->setAttrib('readonly', true)->setAttrib('class', 'form-control');
     $username_minchars = Zend_Registry::get('config')->get('username_minchars');
     $username_maxchars = Zend_Registry::get('config')->get('username_maxchars');
     // lowercase, alnum without whitespaces
     $name = new Zend_Form_Element_Text('name');
     $name->setDecorators(array('ViewHelper', 'Errors'))->setRequired(true)->addFilter('StringToLower')->addValidator('alnum', false, array('allowWhiteSpace' => false))->addValidator('stringLength', false, array($username_minchars, $username_maxchars))->setErrorMessages(array(sprintf($this->translator->translate('Please choose a valid username between %d and %d characters'), $username_minchars, $username_maxchars)))->setAttrib('class', 'form-control alnum-only')->setValue($profile->name)->setLabel($this->translator->translate('Username'));
     $screenname = new Zend_Form_Element_Text('screen_name');
     $screenname->setDecorators(array('ViewHelper', 'Errors'))->addFilter('StringTrim')->setValue($profile->screen_name)->addValidator('alnum', false, array('allowWhiteSpace' => true))->addValidator('stringLength', false, array($username_minchars, $username_maxchars))->setErrorMessages(array(sprintf($this->translator->translate('Please choose a valid name between %d and %d characters'), $username_minchars, $username_maxchars)))->setLabel($this->translator->translate('Screen Name'))->setRequired(true)->setAttrib('class', 'form-control');
     $owner_name = isset($owners_profile->name) ? $owners_profile->name : '-';
     $owner = new Zend_Form_Element_Text('owner');
     $owner->setDecorators(array('ViewHelper', 'Errors'))->setLabel($this->translator->translate('Owner') . ' (' . $this->translator->translate('Current') . ': ' . $owner_name . ')')->setValue($owner_name)->setRequired(true)->setAttrib('class', 'form-control');
     $badges = new Zend_Form_Element_Text('badges');
     $badges->setDecorators(array('ViewHelper', 'Errors'))->setLabel($this->translator->translate('Badges based on Glyphicon font separated by comma (e.g. "bullhorn,earphone")'))->setValue($ProfilesMeta->getMetaValue('badges', $profile->id))->setAttrib('class', 'form-control');
     $description = new Zend_Form_Element_Textarea('description');
     $description->setDecorators(array('ViewHelper', 'Errors'))->setAttrib('COLS', '')->setAttrib('ROWS', '4')->addFilter('StripTags')->setValue($ProfilesMeta->getMetaValue('description', $profile->id))->setLabel($this->translator->translate('About this page'))->setAttrib('class', 'form-control');
     $is_hidden = new Zend_Form_Element_Checkbox('is_hidden');
     $is_hidden->setDecorators(array('ViewHelper', 'Errors'))->setValue(isset($profile->is_hidden) && $profile->is_hidden == 1 ? 1 : 0)->setLabel($this->translator->translate('Hide?'))->setCheckedValue("1")->setUncheckedValue("0");
     $submit = new Zend_Form_Element_Submit('formsubmit');
     $submit->setDecorators(array('ViewHelper'))->setLabel($this->translator->translate('Save'))->setAttrib('class', 'submit btn btn-default');
     $this->addElements(array($profile_id, $owner, $name, $screenname, $badges, $description, $is_hidden, $submit));
     $this->postInit();
 }
Beispiel #9
0
 /**
  * Delete all user's images
  */
 public function removeUsersImages($user_id)
 {
     $Profiles = new Application_Model_Profiles();
     $ProfilesMeta = new Application_Model_ProfilesMeta();
     $profile = $Profiles->getProfileByField('id', $user_id);
     if (!$profile) {
         return false;
     }
     $Storage = new Application_Model_Storage();
     $StorageAdapter = $Storage->getAdapter();
     $user_id = (int) $user_id;
     $sql = "\r\n\t\tSELECT\r\n\t\t*\r\n\t\tFROM images\r\n\t\tWHERE uploaded_by = {$user_id}\r\n\t\t";
     $images = $this->getAdapter()->fetchAll($sql);
     if (!empty($images)) {
         foreach ($images as $image) {
             $StorageAdapter->deleteFileFromStorage($image['file_name'], 'posts');
             if ($image['original']) {
                 $StorageAdapter->deleteFileFromStorage($image['original'], 'posts');
             }
             $result = $this->delete(array('id = ?' => $image['id']));
         }
     }
     // remove user avatar, cover and background
     $background_file = $ProfilesMeta->getMetaValue('background_file', $user_id);
     if ($background_file) {
         $ret = $StorageAdapter->deleteFileFromStorage($background_file, 'cover');
     }
     $avatar_file = $profile->avatar;
     if (strpos($avatar_file, 'default') === false) {
         $ret = $StorageAdapter->deleteFileFromStorage($avatar_file, 'avatar');
     }
     $cover_file = $profile->cover;
     if (strpos($cover_file, 'default') === false) {
         $ret = $StorageAdapter->deleteFileFromStorage($cover_file, 'cover');
     }
     return;
 }
 /**
  * Edit page
  */
 public function pageAction()
 {
     $Profiles = new Application_Model_Profiles();
     $request = $this->getRequest();
     $profile_id = $request->getParam('id', null);
     $profile = $Profiles->getProfileByField('id', $profile_id);
     $this->view->sidebar_editprofile = $profile;
     // attach sidebar box
     Zend_Registry::get('hooks')->attach('hook_view_sidebar', 5, function () {
         echo Zend_Controller_Action_HelperBroker::getStaticHelper('viewRenderer')->view->render('/_sidebar/editprofile.phtml');
     });
     $edit_form = new Application_Form_AdminPage();
     $this->view->edit_form = $edit_form;
     if ($request->isPost() && $profile_id && $edit_form->isValid($_POST)) {
         $owner_profile = $Profiles->getProfileByField('name', $edit_form->getValue('owner'));
         $profile->owner = $owner_profile->id;
         $profile->name = $edit_form->getValue('name');
         $profile->screen_name = $edit_form->getValue('screen_name');
         $profile->is_hidden = $edit_form->getValue('is_hidden');
         $profile->save();
         $ProfilesMeta = new Application_Model_ProfilesMeta();
         $ProfilesMeta->metaUpdate('description', $edit_form->getValue('description'), $profile_id);
         $ProfilesMeta->metaUpdate('badges', $edit_form->getValue('badges'), $profile_id);
         Application_Plugin_Alerts::success($this->view->translate('Page updated'));
         // flush url
         $this->redirect('admin/page/id/' . $profile_id);
     }
 }
 /**
  * logged in user actions on each page load, username row db load
  */
 protected function _initUserPreloads()
 {
     // return on guests
     if (!Zend_Auth::getInstance()->hasIdentity()) {
         return;
     }
     // check if cookie is ok
     if (!isset(Zend_Auth::getInstance()->getIdentity()->name) || !isset(Zend_Auth::getInstance()->getIdentity()->id)) {
         Zend_Auth::getInstance()->clearIdentity();
         return;
     }
     // load user from db
     $Profiles = new Application_Model_Profiles();
     $current_user = $Profiles->getProfile(Zend_Auth::getInstance()->getIdentity()->name, true);
     // load users meta from db
     $ProfilesMeta = new Application_Model_ProfilesMeta();
     $current_user_meta = $ProfilesMeta->getMetaValues(Zend_Auth::getInstance()->getIdentity()->id);
     if (!$current_user) {
         Zend_Auth::getInstance()->clearIdentity();
         return;
     }
     // re-login requests, when user has to re-login for some reason
     if ($current_user->relogin_request == 1) {
         $Profiles->updateField($current_user->name, 'relogin_request', 0);
         Zend_Auth::getInstance()->clearIdentity();
     }
     // set default post privacy
     Zend_Registry::set('default_privacy', $current_user->default_privacy);
     // save all profile's meta data
     Zend_Registry::set('current_user_meta', $current_user_meta);
     return;
 }
 /**
  * Activation link lands here to activate user account
  */
 public function activateAction()
 {
     $this->_helper->_layout->setLayout('layout_wide');
     // flush if already logged in
     Zend_Auth::getInstance()->clearIdentity();
     $activateaccount_form = new Application_Form_ActivateAccount();
     $this->view->activateaccount_form = $activateaccount_form;
     $key = $this->getRequest()->getParam('key', false);
     $resend_username = $this->getRequest()->getParam('resend', false);
     $Profiles = new Application_Model_Profiles();
     $ProfilesMeta = new Application_Model_ProfilesMeta();
     $userData = $Profiles->getProfileByField('activationkey', $key);
     if (!$userData || $key == 'activated') {
         // try if this is a resend
         $userData = $Profiles->getProfile($resend_username);
         if (!$userData || $userData->activationkey == 'activated') {
             $this->redirect('');
         } else {
             $resend_lock = $ProfilesMeta->getMetaValue('resend_activation_lock', $userData->id);
             $hour_lock = date('H');
             // prevent too many attempts
             if ($resend_lock && $resend_lock == $hour_lock) {
                 Application_Plugin_Alerts::info(Zend_Registry::get('Zend_Translate')->translate('Please Check your Inbox and come back after you activate your account.'), 'off');
                 $this->redirect('');
             }
             $ret = Application_Plugin_Common::sendActivationEmail($userData->email, $userData->name, $userData->activationkey);
             // email has been sent, show success message
             if ($ret) {
                 Application_Plugin_Alerts::info(Zend_Registry::get('Zend_Translate')->translate('Please Check your Inbox and come back after you activate your account.'), 'off');
                 // once per day
                 $ProfilesMeta->metaUpdate('resend_activation_lock', $hour_lock, $userData->id);
             } else {
                 // show error message
                 Application_Plugin_Alerts::error(Zend_Registry::get('Zend_Translate')->translate('Something went wrong, email was not sent.'), 'off');
             }
             $this->redirect('');
         }
     }
     $request = $this->getRequest();
     if ($request->isPost() && isset($_POST['identifier']) && $_POST['identifier'] == 'ActivateAccount') {
         if ($activateaccount_form->isValid($_POST)) {
             if ($Profiles->activateAccount($key)) {
                 // auto-login user and store identity
                 $authAdapter = Application_Plugin_Common::getAuthAdapter();
                 $authAdapter->setIdentity($userData->email)->setCredential('whatever')->setCredentialTreatment('autologin');
                 $auth = Zend_Auth::getInstance();
                 $auth->authenticate($authAdapter);
                 $identity = $authAdapter->getResultRowObject();
                 $authStorage = $auth->getStorage();
                 $authStorage->write($identity);
                 // update last login date
                 $ProfilesMeta = new Application_Model_ProfilesMeta();
                 $ProfilesMeta->metaUpdate('last_login', Application_Plugin_Common::now(), $identity->id);
                 // show welcome message
                 Application_Plugin_Alerts::success($this->view->translate('Welcome to the network.'), 'on');
                 $this->redirect('');
             }
         }
     }
 }
 /**
  * Lost password
  */
 public function submitLostPasswordForm($form)
 {
     $front = Zend_Controller_Front::getInstance();
     if ($form->isValid($_POST)) {
         $name = $form->getValue('name');
         $Profiles = new Application_Model_Profiles();
         $nameRow = $Profiles->getProfileByField('name', $name);
         // maybe user is entering email?
         $nameRow_byEmail = $Profiles->getProfileByField('email', $name);
         if ($nameRow_byEmail) {
             $nameRow = $Profiles->getProfileByField('name', $nameRow_byEmail->name);
         }
         if ($nameRow && $Profiles->isActivated($nameRow->name) && $nameRow->is_hidden == 0) {
             $resetPasswordKey = $Profiles->generateActivationKey($nameRow->email);
             $ProfilesMeta = new Application_Model_ProfilesMeta();
             $profile = $ProfilesMeta->metaUpdate('password_reset', $resetPasswordKey, $nameRow->id);
             // password recovery email
             $ret = Application_Plugin_Common::sendRecoveryEmail($nameRow->email, $name, $resetPasswordKey);
             // show info message
             if ($ret) {
                 Application_Plugin_Alerts::success(Zend_Registry::get('Zend_Translate')->translate('We have sent an email to your registered email address. Follow the instructions and you will be able to enter a new password.'), 'off');
             }
             // flush url
             Zend_Controller_Action_HelperBroker::getStaticHelper('Redirector')->gotoUrl('');
         } else {
             sleep(2);
             $form->getElement('name')->setErrors(array(Zend_Registry::get('Zend_Translate')->translate('Username does not exists')));
         }
     }
     return $form;
 }
 /**
  *
  * Edit User (admin only)
  *
  */
 public function init()
 {
     $cname = explode('_', get_class());
     $this->preInit(end($cname));
     // use template file
     $this->setDecorators(array(array('ViewScript', array('viewScript' => 'forms/AdminUser.phtml'))));
     $request = Zend_Controller_Front::getInstance()->getRequest();
     $request_profile_id = $request->getParam('id');
     // get user from database
     $Profiles = new Application_Model_Profiles();
     $ProfilesMeta = new Application_Model_ProfilesMeta();
     $profile = $Profiles->getProfileByField('id', $request_profile_id);
     $all_meta = $ProfilesMeta->getMetaValues($profile->id);
     if (isset($all_meta['bulk_notifications'])) {
         $notifications_meta = json_decode($all_meta['bulk_notifications'], true);
     }
     // fields
     $role = new Zend_Form_Element_Select('role');
     $role->setDecorators(array('ViewHelper', 'Errors'))->setMultiOptions(array('user' => 'User', 'subscriber' => 'Subscriber', 'reviewer' => 'Reviewer', 'admin' => 'Admin'))->setErrorMessages(array($this->translator->translate('User Role is requiered')))->setLabel($this->translator->translate('User Role'))->setRequired(true)->setValue($profile->role)->setAttrib('class', 'form-control');
     $profile_id = new Zend_Form_Element_Text('id');
     $profile_id->setDecorators(array('ViewHelper', 'Errors'))->setLabel($this->translator->translate('Id'))->setValue($profile->id)->setIgnore(true)->setAttrib('readonly', true)->setAttrib('class', 'form-control');
     $username_minchars = Zend_Registry::get('config')->get('username_minchars');
     $username_maxchars = Zend_Registry::get('config')->get('username_maxchars');
     // lowercase, alnum without whitespaces
     $name = new Zend_Form_Element_Text('name');
     $name->setDecorators(array('ViewHelper', 'Errors'))->setRequired(true)->addFilter('StringToLower')->addValidator('alnum', false, array('allowWhiteSpace' => false))->addValidator('stringLength', false, array($username_minchars, $username_maxchars))->setErrorMessages(array(sprintf($this->translator->translate('Please choose a valid username between %d and %d characters'), $username_minchars, $username_maxchars)))->setAttrib('class', 'form-control alnum-only')->setValue($profile->name)->setLabel($this->translator->translate('Name'));
     $email = new Zend_Form_Element_Text('email');
     $email->setDecorators(array('ViewHelper', 'Errors'))->setLabel($this->translator->translate('Email'))->setValue($profile->email)->setAttrib('class', 'form-control');
     $screenname = new Zend_Form_Element_Text('screen_name');
     $screenname->setDecorators(array('ViewHelper', 'Errors'))->addFilter('StringTrim')->setValue($profile->screen_name)->addValidator('alnum', false, array('allowWhiteSpace' => true))->addValidator('stringLength', false, array($username_minchars, $username_maxchars))->setErrorMessages(array(sprintf($this->translator->translate('Please choose a valid name between %d and %d characters'), $username_minchars, $username_maxchars)))->setLabel($this->translator->translate('Screen Name'))->setRequired(true)->setAttrib('class', 'form-control');
     $description = new Zend_Form_Element_Textarea('description');
     $description->setDecorators(array('ViewHelper', 'Errors'))->setAttrib('COLS', '')->setAttrib('ROWS', '4')->setValue(isset($all_meta['description']) ? $all_meta['description'] : '')->setLabel($this->translator->translate('Description'))->setAttrib('class', 'form-control');
     $profile_privacy = new Zend_Form_Element_Select('profile_privacy');
     $profile_privacy->setDecorators(array('ViewHelper', 'Errors'))->setMultiOptions(Zend_Registry::get('profile_privacy_all'))->setErrorMessages(array($this->translator->translate('Select profile visibility')))->setLabel($this->translator->translate('Profile visibility'))->setRequired(true)->setValue($profile->profile_privacy)->setAttrib('class', 'form-control');
     $default_privacy = new Zend_Form_Element_Select('default_privacy');
     $default_privacy->setDecorators(array('ViewHelper', 'Errors'))->setMultiOptions(Zend_Registry::get('post_privacy_array'))->setLabel($this->translator->translate('Default visibility'))->setRequired(true)->setValue($profile->default_privacy)->setAttrib('class', 'form-control');
     $language = new Zend_Form_Element_Select('language');
     $language->setDecorators(array('ViewHelper', 'Errors'))->setMultiOptions(Zend_Registry::get('languages_array'))->setLabel($this->translator->translate('Language'))->setRequired(true)->setValue($profile->language)->setAttrib('class', 'form-control');
     $birthday = new Application_Form_Element_Date('birthday');
     $birthday->setDecorators(array('ViewHelper', 'Errors'))->setLabel($this->translator->translate('Date of birth'))->setErrorMessages(array($this->translator->translate('Please enter a valid date')));
     $birthday->setYearSpan(1920, date('Y') - 1);
     if (isset($all_meta['birthday'])) {
         $timestamp = strtotime($all_meta['birthday']);
         $birthday->setValue(array('day' => date('d', $timestamp), 'month' => date('m', $timestamp), 'year' => date('Y', $timestamp)));
     }
     $password1 = new Zend_Form_Element_Password('password1');
     $password1->setDecorators(array('ViewHelper', 'Errors'))->setAttrib('autocomplete', 'off')->setLabel($this->translator->translate('New Password:'******'class', 'form-control');
     $activation = new Zend_Form_Element_Text('activationkey');
     $activation->setDecorators(array('ViewHelper', 'Errors'))->setLabel($this->translator->translate('Activation key (or "activated")'))->setValue($profile->activationkey)->setAttrib('class', 'form-control');
     $gender = new Zend_Form_Element_Select('gender');
     $gender->setDecorators(array('ViewHelper', 'Errors'))->setMultiOptions(Zend_Registry::get('genders_array'))->setErrorMessages(array($this->translator->translate('Please select something')))->setLabel($this->translator->translate('Gender'))->setRequired(true)->setValue(isset($all_meta['gender']) ? $all_meta['gender'] : '')->setAttrib('class', 'form-control');
     $online_status = new Zend_Form_Element_Select('show_online_status');
     $online_status->setDecorators(array('ViewHelper', 'Errors'))->setMultiOptions(Zend_Registry::get('onlinestatus_array'))->setErrorMessages(array($this->translator->translate('Select profile visibility')))->setLabel($this->translator->translate('Online Status'))->setRequired(true)->setValue(isset($all_meta['show_online_status']) ? $all_meta['show_online_status'] : 's')->setAttrib('class', 'form-control');
     $contact_privacy = new Zend_Form_Element_Select('contact_privacy');
     $contact_privacy->setDecorators(array('ViewHelper', 'Errors'))->setMultiOptions(Zend_Registry::get('contactprivacy_array'))->setErrorMessages(array($this->translator->translate('Please select something')))->setLabel($this->translator->translate('Who can contact me?'))->setRequired(true)->setValue(isset($all_meta['contact_privacy']) ? $all_meta['contact_privacy'] : 'e')->setAttrib('class', 'form-control');
     $location = new Zend_Form_Element_Text('location');
     $location->setDecorators(array('ViewHelper', 'Errors'))->setRequired(false)->setLabel($this->translator->translate('Location'))->setAttrib('class', 'form-control')->addFilter('StripTags')->setValue(isset($all_meta['location']) ? $all_meta['location'] : '')->setErrorMessages(array($this->translator->translate('Enter a valid location')));
     $website = new Zend_Form_Element_Text('website');
     $website->setDecorators(array('ViewHelper', 'Errors'))->setRequired(false)->setLabel($this->translator->translate('Website'))->setAttrib('class', 'form-control')->addFilter('StripTags')->setValue(isset($all_meta['website']) ? $all_meta['website'] : '')->setErrorMessages(array($this->translator->translate('Enter a valid website')));
     $badges = new Zend_Form_Element_Text('badges');
     $badges->setDecorators(array('ViewHelper', 'Errors'))->setLabel($this->translator->translate('Badges based on Glyphicon font separated by comma (e.g. "bullhorn,earphone")'))->setValue(isset($all_meta['badges']) ? $all_meta['badges'] : '')->setAttrib('class', 'form-control');
     $n1 = new Zend_Form_Element_Checkbox('notification_email_1');
     $n1->setDecorators(array('ViewHelper', 'Errors'))->setValue(isset($notifications_meta['notification_email_1']) && $notifications_meta['notification_email_1'] == 1 ? 1 : 0)->setLabel($this->translator->translate('Email when someone posts a new comment'))->setCheckedValue("1")->setUncheckedValue("0");
     $n2 = new Zend_Form_Element_Checkbox('notification_email_2');
     $n2->setDecorators(array('ViewHelper', 'Errors'))->setValue(isset($notifications_meta['notification_email_2']) && $notifications_meta['notification_email_2'] == 1 ? 1 : 0)->setLabel($this->translator->translate('Email when someone likes your post'))->setCheckedValue("1")->setUncheckedValue("0");
     $n3 = new Zend_Form_Element_Checkbox('notification_email_3');
     $n3->setDecorators(array('ViewHelper', 'Errors'))->setValue(isset($notifications_meta['notification_email_3']) && $notifications_meta['notification_email_3'] == 1 ? 1 : 0)->setLabel($this->translator->translate('Email when someone follows you'))->setCheckedValue("1")->setUncheckedValue("0");
     $n4 = new Zend_Form_Element_Checkbox('notification_email_4');
     $n4->setDecorators(array('ViewHelper', 'Errors'))->setValue(isset($notifications_meta['notification_email_4']) && $notifications_meta['notification_email_4'] == 1 ? 1 : 0)->setLabel($this->translator->translate('Email on new friends'))->setCheckedValue("1")->setUncheckedValue("0");
     $n6 = new Zend_Form_Element_Checkbox('notification_email_6');
     $n6->setDecorators(array('ViewHelper', 'Errors'))->setValue(isset($notifications_meta['notification_email_6']) && $notifications_meta['notification_email_6'] == 1 ? 1 : 0)->setLabel($this->translator->translate('Email when you lose a follower'))->setCheckedValue("1")->setUncheckedValue("0");
     $n7 = new Zend_Form_Element_Checkbox('notification_email_7');
     $n7->setDecorators(array('ViewHelper', 'Errors'))->setValue(isset($notifications_meta['notification_email_7']) && $notifications_meta['notification_email_7'] == 1 ? 1 : 0)->setLabel($this->translator->translate('Email when someone posts on your wall'))->setCheckedValue("1")->setUncheckedValue("0");
     $n8 = new Zend_Form_Element_Checkbox('notification_email_8');
     $n8->setDecorators(array('ViewHelper', 'Errors'))->setValue(isset($notifications_meta['notification_email_8']) && $notifications_meta['notification_email_8'] == 1 ? 1 : 0)->setLabel($this->translator->translate('Email when someone sends you a private message'))->setCheckedValue("1")->setUncheckedValue("0");
     $is_hidden = new Zend_Form_Element_Checkbox('is_hidden');
     $is_hidden->setDecorators(array('ViewHelper', 'Errors'))->setValue(isset($profile->is_hidden) && $profile->is_hidden == 1 ? 1 : 0)->setLabel($this->translator->translate('Hide?'))->setCheckedValue("1")->setUncheckedValue("0");
     $submit = new Zend_Form_Element_Submit('formsubmit');
     $submit->setDecorators(array('ViewHelper'))->setLabel($this->translator->translate('Save'))->setAttrib('class', 'submit btn btn-default');
     $this->addElements(array($profile_id, $role, $name, $email, $screenname, $description, $profile_privacy, $default_privacy, $language, $gender, $online_status, $contact_privacy, $location, $website, $birthday, $password1, $activation, $badges, $n1, $n2, $n3, $n4, $n6, $n7, $n8, $is_hidden, $submit));
     $this->postInit();
 }
Beispiel #15
0
 /**
  * Permanently remove all profile's associated data
  */
 public function removeAllProfilesData($profile_id)
 {
     // check if exists
     $profile = $this->getProfileByField('id', $profile_id);
     if (!$profile) {
         return false;
     }
     $Images = new Application_Model_Images();
     $Images->removeUsersImages($profile_id);
     $Albums = new Application_Model_Albums();
     $Albums->deleteAlbums($profile_id);
     $Comments = new Application_Model_Comments();
     $Comments->deleteComments($profile_id);
     $Connections = new Application_Model_Connections();
     $Connections->removeUsersConnections($profile_id);
     $Likes = new Application_Model_Likes();
     $Likes->removeUsersLikes($profile_id);
     $Notifications = new Application_Model_Notifications();
     $Notifications->removeUsersNotifications($profile_id);
     $Reports = new Application_Model_Reports();
     $Reports->removeUsersReports($profile_id);
     $Posts = new Application_Model_Posts();
     $Posts->removeUsersPosts($profile_id);
     $Messages = new Application_Model_Messages();
     $Messages->removeUsersMessages($profile_id);
     $ProfilesMeta = new Application_Model_ProfilesMeta();
     $ProfilesMeta->removeMetaForProfile($profile_id);
     return true;
 }
 /**
  * Create a page
  */
 public function createpageAction()
 {
     $this->buildMenu(true);
     $request = $this->getRequest();
     $Profiles = new Application_Model_Profiles();
     $profile_form = new Application_Form_AddPage();
     $this->view->profile_form = $profile_form;
     if ($request->isPost() && $profile_form->isValid($_POST)) {
         if ($Profiles->getProfile($profile_form->getValue('name'), true)) {
             $profile_form->getElement('name')->setErrors(array(Zend_Registry::get('Zend_Translate')->translate('This username is not available')));
             return;
         }
         $profile = $Profiles->createRow();
         $profile->owner = Zend_Auth::getInstance()->getIdentity()->id;
         $profile->name = $profile_form->getValue('name');
         $profile->screen_name = $profile_form->getValue('screen_name');
         $profile->profile_privacy = 'public';
         $Profiles->createNewPage($profile);
         $ProfilesMeta = new Application_Model_ProfilesMeta();
         $ProfilesMeta->metaUpdate('description', $profile_form->getValue('description'), $profile->id);
         Application_Plugin_Alerts::success($this->view->translate('New page created'));
         $this->redirect('editprofile/listpages');
     }
 }
 /**
  * Prepare profile for cover view
  */
 public function prepareProfile($profile)
 {
     if (Zend_Auth::getInstance()->hasIdentity()) {
         $current_user = (int) Zend_Auth::getInstance()->getIdentity()->id;
     } else {
         $current_user = 0;
     }
     $Images = new Application_Model_Images();
     $Connections = new Application_Model_Connections();
     $Reports = new Application_Model_Reports();
     $ProfilesMeta = new Application_Model_ProfilesMeta();
     $meta_values = $ProfilesMeta->getMetaValues($profile->id);
     // user's data, object style
     $this->view->profile_data = $profile;
     $this->view->profile_data->meta_values = $meta_values;
     // attach sidebar box
     Zend_Registry::get('hooks')->attach('hook_view_sidebar', 5, function () {
         echo Zend_Controller_Action_HelperBroker::getStaticHelper('viewRenderer')->view->render('/_sidebar/profileinfo.phtml');
     });
     $limit = (int) Zend_Registry::get('config')->get('sidebar_max_users');
     $is_following = $Connections->isFollowing($current_user, $profile->id);
     $is_friend = $Connections->areFriends($profile->id, $current_user);
     $is_reported = $Reports->isReported($profile->id, $profile->type);
     // @formatter:off
     // check privacy
     if (isset($profile) && (Zend_Auth::getInstance()->hasIdentity() && (Zend_Auth::getInstance()->getIdentity()->role == 'admin' || Zend_Auth::getInstance()->getIdentity()->role == 'reviewer') || Zend_Auth::getInstance()->hasIdentity() && Zend_Auth::getInstance()->getIdentity()->id == $profile->id || $profile->profile_privacy === 'friends' && $is_friend || $profile->profile_privacy === 'followers' && $is_following || $profile->profile_privacy === 'everyone' && Zend_Auth::getInstance()->hasIdentity() || $profile->profile_privacy === 'public')) {
         if ($profile->type === 'group') {
             $this->view->sidebar_members = $Connections->getFriends($profile->id, $limit, false, 'user');
             $this->view->sidebar_members_count = $Connections->getFriends($profile->id, false, true);
             // attach sidebar box
             Zend_Registry::get('hooks')->attach('hook_view_sidebar', 10, function () {
                 echo Zend_Controller_Action_HelperBroker::getStaticHelper('viewRenderer')->view->render('/_sidebar/members.phtml');
             });
             // check if secret group and this is a group owner
             if ($current_user > 0 && $current_user == $profile->owner && $profile->profile_privacy === 'friends') {
                 $Connections->mix_friends = false;
                 $this->view->sidebar_approve_members = $Connections->getFollowers($profile->id);
                 $this->view->sidebar_approve_members_count = $Connections->getFollowers($profile->id, false, true);
                 // attach sidebar box
                 Zend_Registry::get('hooks')->attach('hook_view_sidebar', 10, function () {
                     echo Zend_Controller_Action_HelperBroker::getStaticHelper('viewRenderer')->view->render('/_sidebar/approvemembers.phtml');
                 });
             }
         } elseif ($profile->type === 'user') {
             // TODO: optiomize this to a single join call
             $this->view->sidebar_followers = $Connections->getFollowers($profile->id, $limit);
             $this->view->sidebar_following = $Connections->getFollowing($profile->id, $limit);
             $this->view->sidebar_friends = $Connections->getFriends($profile->id, $limit, false, 'user');
             $this->view->sidebar_followers_count = $Connections->getFollowers($profile->id, false, true);
             $this->view->sidebar_following_count = $Connections->getFollowing($profile->id, false, true);
             $this->view->sidebar_friends_count = $Connections->getFriends($profile->id, false, true);
             $this->view->sidebar_groups = $Connections->getFriends($profile->id, $limit, false, 'group');
             $this->view->sidebar_groups_count = $Connections->getFriends($profile->id, $limit, true, 'group');
             // attach sidebar box
             Zend_Registry::get('hooks')->attach('hook_view_sidebar', 10, function () {
                 echo Zend_Controller_Action_HelperBroker::getStaticHelper('viewRenderer')->view->render('/_sidebar/followers.phtml');
                 echo Zend_Controller_Action_HelperBroker::getStaticHelper('viewRenderer')->view->render('/_sidebar/following.phtml');
                 echo Zend_Controller_Action_HelperBroker::getStaticHelper('viewRenderer')->view->render('/_sidebar/friends.phtml');
                 echo Zend_Controller_Action_HelperBroker::getStaticHelper('viewRenderer')->view->render('/_sidebar/groups.phtml');
             });
         } elseif ($profile->type === 'page') {
         }
         // put images to sidebar
         // $this->view->sidebar_images_count = $Images->getImages($profile->id, false, true);
         // $this->view->sidebar_images = $Images->getImages($profile->id, false, false, $limit);
         Zend_Registry::get('hooks')->attach('hook_view_sidebar', 10, function () {
             echo Zend_Controller_Action_HelperBroker::getStaticHelper('viewRenderer')->view->render('/_sidebar/images.phtml');
         });
     }
     // @formatter:on
     // set view params
     $this->view->user_cover = true;
     $this->view->is_following = $is_following;
     $this->view->is_friend = $is_friend;
     $this->view->is_reported = $is_reported;
     // override <head> for profile pages
     if (Zend_Registry::get('config')->get('profiles_head')) {
         $content = Zend_Registry::get('config')->get('profiles_head');
         $this->view->custom_head = Application_Plugin_Common::parseProfileTags($content, $profile);
     }
     // view perspective
     $this->view->view_perspective = 'profile_view';
     return;
 }
Beispiel #18
0
/**
 * Register with facebook
 */
function registerWithFacebook()
{
    // flush if already logged in
    Zend_Auth::getInstance()->clearIdentity();
    $session = new Zend_Session_Namespace('Default');
    $email = $session->fb_user_email;
    $avatar = $session->fb_avatar;
    // do not allow direct access - without fb_user_email inside session
    if (!$session->fb_user_email) {
        Zend_Controller_Action_HelperBroker::getStaticHelper('Redirector')->gotoUrl('');
    }
    require_once 'Form.php';
    $registerwithfacebook_form = new Addon_FacebookRegisterForm();
    $Profiles = new Application_Model_Profiles();
    if ($_SERVER['REQUEST_METHOD'] === 'POST') {
        if ($registerwithfacebook_form->isValid($_POST)) {
            $name = $registerwithfacebook_form->getValue('name');
            $user = $Profiles->createRow();
            $user->name = $name;
            $user->email = $email;
            $user->password = '';
            $user->activationkey = 'activated';
            $user->language = Zend_Registry::get('config')->get('default_language');
            $user = $Profiles->createNewUser($user, 'facebook');
            // update last login date
            $ProfilesMeta = new Application_Model_ProfilesMeta();
            $ProfilesMeta->metaUpdate('last_login', Application_Plugin_Common::now(), $user->id);
            $Storage = new Application_Model_Storage();
            $StorageAdapter = $Storage->getAdapter();
            $defaultres = 64;
            $bigres = Zend_Registry::get('config')->get('avatar_size') ? Zend_Registry::get('config')->get('avatar_size') : $defaultres;
            // get the image
            $c = new Zend_Http_Client();
            $c->setUri($avatar);
            $result = $c->request('GET');
            $img = imagecreatefromstring($result->getBody());
            // create regular avatar image, resample and store
            $imgname = 'profileimage_' . $name . '.jpg';
            imagejpeg($img, TMP_PATH . '/' . $imgname);
            Application_Plugin_ImageLib::resample(TMP_PATH . '/' . $imgname, TMP_PATH . '/' . $imgname, $defaultres, $defaultres, false);
            $new_filename = $StorageAdapter->moveFileToStorage($imgname, 'avatar');
            $Profiles->updateField($name, 'avatar', $new_filename);
            // create big avatar image, resample and store
            $imgname = 'bigprofileimage_' . $name . '.jpg';
            imagejpeg($img, TMP_PATH . '/' . $imgname);
            Application_Plugin_ImageLib::resample(TMP_PATH . '/' . $imgname, TMP_PATH . '/' . $imgname, $bigres, $bigres, false);
            $big_avatar = $StorageAdapter->moveFileToStorage($imgname, 'avatar');
            $ProfilesMeta->metaUpdate('big_avatar', $big_avatar, $user->id);
            // free img resource
            imagedestroy($img);
            // login user
            $emailAuthAdapter = Application_Plugin_Common::getEmailAuthAdapter($email);
            $auth = Zend_Auth::getInstance();
            $auth->authenticate($emailAuthAdapter);
            $identity = $emailAuthAdapter->getResultRowObject();
            $authStorage = $auth->getStorage();
            $authStorage->write($identity);
            // clear session data
            $session->fb_user_email = '';
            $session->fb_user_display_name = '';
            $session->fb_avatar = '';
            $user_id = $user->id;
            // trigger hooks
            Zend_Registry::get('hooks')->trigger('hook_firsttimelogin', $user_id);
            // show welcome message
            Application_Plugin_Alerts::success(Zend_Registry::get('Zend_Translate')->translate('Welcome to the network.'), 'on');
            Zend_Controller_Action_HelperBroker::getStaticHelper('Redirector')->gotoUrl('');
        }
    }
    echo $registerwithfacebook_form;
}
Beispiel #19
0
 /**
  * Fix posts data
  */
 public function fixData($data)
 {
     if (!is_array($data) || empty($data)) {
         return;
     }
     $all_post_ids = $all_post_authors = array();
     // find all post id's and authors
     foreach ($data as $tmp) {
         $all_post_ids[] = $tmp['post_id'];
         $all_post_authors[] = $tmp['author_id'];
     }
     // retrieve comments for these posts
     $Comments = new Application_Model_Comments();
     $post_comments = $Comments->getCommentsForResources($all_post_ids, 'post', $this->show_hidden_comments);
     // retrieve attached images for these posts
     $Images = new Application_Model_Images();
     $post_images = $Images->getPostsImages($all_post_ids);
     // retrieve likes for these posts
     $Likes = new Application_Model_Likes();
     $post_likes = $Likes->getLikesForPosts($all_post_ids, 'post');
     // retrieve authors meta data
     $ProfilesMeta = new Application_Model_ProfilesMeta();
     $profiles_meta = $ProfilesMeta->getMetaForProfiles($all_post_authors);
     // fix posts
     foreach ($data as &$post) {
         // depreciated
         $post['is_reported'] = 0;
         // blend in comments
         if (!empty($post_comments[$post['post_id']])) {
             $comments = $post_comments[$post['post_id']];
             // trigger comments hooks
             Zend_Registry::get('hooks')->trigger('hook_data_comments', $comments);
             $post['comments'] = $comments;
         }
         // blend in images
         if (!empty($post_images[$post['post_id']])) {
             $post['post_images'] = $post_images[$post['post_id']];
         }
         // blend in likes
         if (!empty($post_likes[$post['post_id']])) {
             $post['likes_count'] = $post_likes[$post['post_id']]['likes_count'];
             $post['is_liked'] = $post_likes[$post['post_id']]['is_liked'];
         } else {
             $post['likes_count'] = 0;
             $post['is_liked'] = 0;
         }
         // blend in author meta_data
         if (!empty($profiles_meta[$post['author_id']])) {
             $post['author_meta'] = $profiles_meta[$post['author_id']];
         }
         // shares
         if (isset($post['rich_content_json'])) {
             $rich_content = json_decode($post['rich_content_json']);
             if ($rich_content->type == 'share') {
                 $original_post_id = (int) $rich_content->data->post;
                 if ($original_post_id) {
                     $original_post = $this->getPosts(null, $original_post_id, false, true);
                     if ($original_post !== null) {
                         // copy from original
                         $copycat = $post;
                         $post = $original_post[0];
                         $post['copycat'] = $copycat;
                     } else {
                         // original content was removed
                         $translator = Zend_Registry::get('Zend_Translate');
                         $post['post_content'] = $translator->translate('Resource not available');
                     }
                 }
             }
         }
         // trigger post hooks
         Zend_Registry::get('hooks')->trigger('hook_data_postcontent', $post);
     }
     return $data;
 }