Esempio n. 1
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();
 }
 /**
  * Add post submit
  */
 public function submitAddPostForm($form)
 {
     $Profiles = new Application_Model_Profiles();
     $current_user_id = Zend_Auth::getInstance()->getIdentity()->id;
     // default user wall
     $profile = Zend_Auth::getInstance()->getIdentity();
     // writing on other user wall?
     if ($this->request->getParam('name')) {
         $profile = $Profiles->getProfile($this->request->getParam('name'));
     }
     if (!$this->canPostHere($current_user_id, $profile->type, $profile->id, $profile->owner)) {
         return false;
     }
     // submit?
     if (isset($_POST['identifier']) && $_POST['identifier'] == 'AddPost' && $form->isValid($_POST)) {
         $content = $form->getValue('content');
         $content = Application_Plugin_Common::preparePost($content);
         $Posts = new Application_Model_Posts();
         // save received filename to session form_unique_key
         $form_unique_key = (int) $_POST['form_unique_key'];
         $attached_files = @glob(TMP_PATH . '/post_' . Zend_Auth::getInstance()->getIdentity()->name . '_' . $form_unique_key . '*');
         if ($this->show_privacy) {
             $Posts->addPost($content, $profile->id, Zend_Registry::get('default_privacy'), $attached_files);
         } else {
             // most restrictive, for groups and pages privacy is controlled when fetching posts
             $Posts->addPost($content, $profile->id, 'friends', $attached_files);
         }
         // flush content
         $form->getElement('content')->setValue('');
         $redirector = Zend_Controller_Action_HelperBroker::getStaticHelper('Redirector');
         $redirector->gotoUrl($this->callbackurl);
     }
     return $form;
 }
 /**
  *
  * Change password form
  *
  */
 public function init()
 {
     $cname = explode('_', get_class());
     $this->preInit(end($cname));
     // use template file
     $this->setDecorators(array(array('ViewScript', array('viewScript' => 'forms/ChangePassword.phtml'))));
     $Profiles = new Application_Model_Profiles();
     // fields
     $password_old = new Zend_Form_Element_Password('passwordold');
     $password_old->setDecorators(array('ViewHelper', 'Errors'))->setAttrib('autocomplete', 'off')->setRequired(true)->setErrorMessages(array($this->translator->translate('Password is required')))->setLabel($this->translator->translate('Old Password:'******'class', 'form-control');
     // check if blank password (facebook-registered user) and remove old password field if so
     if (Zend_Auth::getInstance()->hasIdentity()) {
         $profile = $Profiles->getProfile(Zend_Auth::getInstance()->getIdentity()->name);
         if ($profile->password == '') {
             $password_old->setAttrib('class', 'hidden');
             $password_old->setRequired(false);
             $password_old->setLabel('');
         }
     }
     $password1 = new Zend_Form_Element_Password('password1');
     $password1->setDecorators(array('ViewHelper', 'Errors'))->setAttrib('autocomplete', 'off')->setRequired(true)->addValidator('StringLength', false, array(5))->setErrorMessages(array($this->translator->translate('Min 5 characters')))->setLabel($this->translator->translate('New Password:'******'class', 'form-control');
     $password2 = new Zend_Form_Element_Password('password2');
     $password2->setDecorators(array('ViewHelper', 'Errors'))->setAttrib('autocomplete', 'off')->setRequired(true)->addValidator('Identical', false, array('token' => 'password1'))->setErrorMessages(array($this->translator->translate('The passwords do not match')))->setLabel($this->translator->translate('Confirm Password:'******'class', 'form-control');
     $submit = new Zend_Form_Element_Submit('changepass');
     $submit->setDecorators(array('ViewHelper'))->setLabel($this->translator->translate('Change Password'))->setAttrib('class', 'submit btn btn-default');
     $this->addElements(array($password_old, $password1, $password2, $submit));
     $this->postInit();
 }
 public function init()
 {
     $Profiles = new Application_Model_Profiles();
     $Connections = new Application_Model_Connections();
     $name = $this->getRequest()->getParam('name');
     $this->profile = $Profiles->getProfile($name);
     // check privacy
     if ($this->profile) {
         if (Zend_Auth::getInstance()->hasIdentity()) {
             $current_user_id = Zend_Auth::getInstance()->getIdentity()->id;
             $current_user_role = Zend_Auth::getInstance()->getIdentity()->role;
         } elseif (Zend_Registry::get('config')->get('allow_guests') || $this->profile->type == 'page') {
             $current_user_id = 0;
             $current_user_role = 'guest';
         } else {
             $this->redirect('');
         }
         // @formatter:off
         if ($this->profile->profile_privacy == 'public' || $this->profile->profile_privacy == 'everyone' && $current_user_id > 0 || ($current_user_role == 'admin' || $current_user_role == 'reviewer') || $current_user_id == $this->profile->id || $this->profile->profile_privacy == 'followers' && $Connections->isFollowing($current_user_id, $this->profile->id) || $this->profile->profile_privacy == 'friends' && $Connections->areFriends($current_user_id, $this->profile->id)) {
             // ok, has privileges
         } else {
             // user doesn't have privileges to view this profile
             $this->forward('private');
         }
         // @formatter:on
     }
 }
 /**
  * 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);
 }
 /**
  * Accept / Remove group membership
  */
 public function membershipAction()
 {
     $user_name = $this->getRequest()->getParam('name');
     $group_name = $this->getRequest()->getParam('group');
     $action = $this->getRequest()->getParam('do');
     $Connections = new Application_Model_Connections();
     $Profiles = new Application_Model_Profiles();
     // get user
     $user_profile = $Profiles->getProfile($user_name);
     // get group and check ownership
     $group_profile = $Profiles->getProfile($group_name, false, true);
     if (!$group_profile || !$user_profile) {
         $this->redirect('');
     }
     if ($action == 'join') {
         $Connections->acceptGroupMembership($user_profile->id, $group_profile->id);
     } else {
         $Connections->rejectGroupMembership($user_profile->id, $group_profile->id);
     }
     // reload to group page
     $this->redirect($group_name);
 }
Esempio n. 7
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();
 }
 /**
  *
  * 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();
 }
Esempio n. 9
0
 /**
  * Follow user toggle
  */
 public function toggleFollowed($name)
 {
     if (!Zend_Auth::getInstance()->hasIdentity()) {
         return null;
     }
     $Profiles = new Application_Model_Profiles();
     $Notifications = new Application_Model_Notifications();
     $translator = Zend_Registry::get('Zend_Translate');
     $user_id = Zend_Auth::getInstance()->getIdentity()->id;
     $follow_profile = $Profiles->getProfile($name);
     // no or bad profile
     if (!$follow_profile || !isset($follow_profile->id)) {
         return;
     }
     if ($follow_profile->type === 'page') {
         return;
     }
     $is_group = $follow_profile->type === 'group' ? true : false;
     $follow_id = $follow_profile->id;
     if ($this->isFollowing($user_id, $follow_id)) {
         if ($is_group) {
             // delete mutual connection
             $ret = $this->removeConnections($follow_id, $user_id);
             if ($ret == 2) {
                 Application_Plugin_Alerts::info(sprintf($translator->translate('You have left the group %s'), $follow_profile->screen_name));
             } else {
                 Application_Plugin_Alerts::info($translator->translate('You request has been canceled'));
             }
         } else {
             $Notifications->pushNotification(array($follow_id), 6, 'profile', $user_id);
             $this->delete(array('follow_id = ?' => (int) $follow_id, 'user_id = ?' => (int) $user_id));
             Application_Plugin_Alerts::info(sprintf($translator->translate('You have stopped following %s'), $follow_profile->screen_name));
         }
         return;
     } else {
         if ($is_group) {
             $data = array('user_id' => $user_id, 'follow_id' => $follow_id, 'created_on' => Application_Plugin_Common::now());
             $ret = $this->insert($data);
             if ($follow_profile->profile_privacy === 'friends' && $follow_profile->owner != $user_id) {
                 // admin will have to confirm this
                 Application_Plugin_Alerts::success(sprintf($translator->translate('Your request to join this group has been sent to %s'), $follow_profile->screen_name));
                 // notify group admin that new user has requested membership
                 $Notifications->pushNotification(array($follow_profile->owner), 12, 'profile', $follow_id);
             } else {
                 // join the group by adding mutual follow
                 $data = array('user_id' => $follow_id, 'follow_id' => $user_id, 'created_on' => Application_Plugin_Common::now());
                 $this->insert($data);
                 Application_Plugin_Alerts::success(sprintf($translator->translate('You have joined the group %s'), $follow_profile->screen_name));
             }
         } else {
             $data = array('user_id' => $user_id, 'follow_id' => $follow_id, 'created_on' => Application_Plugin_Common::now());
             $this->insert($data);
             if ($this->areFriends($user_id, $follow_id)) {
                 // follow, areFriends
                 // are friends now, notify user
                 $Notifications->pushNotification(array($follow_id), 4, 'profile', $user_id);
                 if ($is_group) {
                     Application_Plugin_Alerts::success(sprintf($translator->translate('You have joined the group %s'), $follow_profile->screen_name));
                 } else {
                     Application_Plugin_Alerts::success(sprintf($translator->translate('You are now friends with %s'), $follow_profile->screen_name));
                 }
                 return;
             }
             // new follower, notify user
             $Notifications->pushNotification(array($follow_id), 3, 'profile', $user_id);
             Application_Plugin_Alerts::success(sprintf($translator->translate('You are now following %s'), $follow_profile->screen_name));
         }
         // follow
         return;
     }
     return false;
 }
 /**
  * Change cover picture
  */
 public function setcoverpictureAction()
 {
     $request = $this->getRequest();
     $profile_name = $request->getParam('name', null);
     $Profiles = new Application_Model_Profiles();
     $profile = $Profiles->getProfile($profile_name, true, true);
     if (!$profile) {
         $this->redirect('');
     }
     if (!isset($this->view->sidebar_nav_menu)) {
         $this->view->sidebar_editprofile = $profile;
         Zend_Registry::get('hooks')->attach('hook_view_sidebar', 5, function () {
             echo Zend_Controller_Action_HelperBroker::getStaticHelper('viewRenderer')->view->render('/_sidebar/editprofile.phtml');
         });
     }
     $coverpicture_form = new Application_Form_CoverPicture();
     $this->view->cover = $profile->cover;
     $this->view->coverpicture_form = $coverpicture_form;
     // image processing helper
     $this->_helper->imageProcessing('cover', $profile->name, $coverpicture_form, 'coverfile');
 }
Esempio n. 11
0
 /**
  * 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;
 }
Esempio n. 12
0
 /**
  * Remove all messages: curent_user -> single_user
  */
 public function removeAllMessagesWithUser($username)
 {
     $Profiles = new Application_Model_Profiles();
     $user = $Profiles->getProfile($username);
     if (!$user) {
         return false;
     }
     $current_user_id = (int) Zend_Auth::getInstance()->getIdentity()->id;
     $with_user_id = (int) $user->id;
     $sql = "\r\n\t\t\tUPDATE messages\r\n\t\t\tSET is_hidden = 2 | is_hidden\r\n\t\t\tWHERE \r\n\t\t\t(from_user_id = {$with_user_id} AND to_user_id = {$current_user_id})\r\n\t\t\t";
     $this->getAdapter()->query($sql);
     $sql = "\r\n\t\tUPDATE messages\r\n\t\tSET is_hidden = 4 | is_hidden\r\n\t\tWHERE\r\n\t\t(from_user_id = {$current_user_id} AND to_user_id = {$with_user_id})\r\n\t\t";
     $this->getAdapter()->query($sql);
     return true;
 }
 /**
  * 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('');
             }
         }
     }
 }
Esempio n. 14
0
        $profile = $Profiles->getProfile($match[2]);
        if ($profile && $profile->type == 'user') {
            $Notifications = new Application_Model_Notifications();
            $Notifications->pushNotification(array($profile->id), 1001, 'post', $post_id);
        }
    }, $content);
});
// push comment mention notifications
$this->attach('hook_data_aftersavecomment', 10, function ($data) {
    $comment_id = $data['comment_id'];
    $Comments = new Application_Model_Comments();
    $comment = $Comments->getComment($comment_id);
    $content = $data['content'];
    $users = preg_replace_callback("/(^|[\t\r\n\\s])@(\\w+)/u", function ($match) use($comment_id) {
        $Profiles = new Application_Model_Profiles();
        $profile = $Profiles->getProfile($match[2]);
        if ($profile && $profile->type == 'user') {
            $Notifications = new Application_Model_Notifications();
            $Notifications->pushNotification(array($profile->id), 1001, 'comment', $comment_id);
        }
    }, $content);
});
// notifications
$this->attach('hook_data_notificationsfix', 10, function (&$data) {
    $baseURL = Application_Plugin_Common::getFullBaseUrl();
    $transl = Zend_Registry::get('Zend_Translate');
    foreach ($data as &$row) {
        // user mentioned inside post/comment
        if ($row['notification_type'] == 1001) {
            $row['do_send_email'] = false;
            if ($row['commented_post_id']) {
 /**
  * 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');
     }
 }