Beispiel #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();
 }
 /**
  *
  * 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();
 }
 /**
  *
  * 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();
 }
 /**
  * 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('');
             }
         }
     }
 }
Beispiel #5
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;
 }
 /**
  * Custom background
  */
 public function setbackgroundpictureAction()
 {
     $Profiles = new Application_Model_Profiles();
     $ProfilesMeta = new Application_Model_ProfilesMeta();
     $request = $this->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) {
         // admin edit
         $profile_id = $request_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');
         });
     } elseif ($request_profile_id && $Profiles->getProfile($profile->name, false, true)) {
         // users pages & groups
         $this->buildMenu(true);
         $profile_id = $request_profile_id;
     } else {
         // user profile
         $this->buildMenu();
         $profile_id = Zend_Auth::getInstance()->getIdentity()->id;
     }
     $profile_name = Zend_Auth::getInstance()->getIdentity()->name;
     $form = new Application_Form_CustomBackground();
     $current_background_file = $ProfilesMeta->getMetaValue('background_file', $profile_id);
     $Storage = new Application_Model_Storage();
     $StorageAdapter = $Storage->getAdapter();
     if ($request->isPost() && $form->isValid($_POST)) {
         // file uploaded?
         if ($form->background->isUploaded()) {
             $form->background->receive();
             // must have
             $receive_path = $form->background->getFileName();
             $filename = $form->background->getValue();
             $extension = strtolower(pathinfo($receive_path, PATHINFO_EXTENSION));
             $tmp_filename = 'profileimage_' . $profile_name . '.' . $extension;
             // delete old tmp image files
             $StorageAdapter->deleteOldTmpFiles(0, 'profileimage_' . $profile_name);
             // move new file to tmp folder
             rename($receive_path, TMP_PATH . '/' . $tmp_filename);
             // check if valid image
             if (!Application_Plugin_ImageLib::isValidImage(TMP_PATH . '/' . $tmp_filename)) {
                 unlink(TMP_PATH . '/' . $tmp_filename);
                 Application_Plugin_Alerts::error($this->view->translate('Server-side error'), 'off');
                 $this->redirect();
                 return;
             }
             // delete old file
             $StorageAdapter->deleteFileFromStorage($current_background_file, 'cover');
             // move uploaded file to permanent location
             $current_background_file = $StorageAdapter->moveFileToStorage($tmp_filename, 'cover');
             // update db
             $ProfilesMeta->metaUpdate('background_file', $current_background_file, $profile_id);
         }
         $ProfilesMeta->metaUpdate('background_repeat', $form->getValue('background_repeat'), $profile_id);
         $ProfilesMeta->metaUpdate('background_scroll', $form->getValue('background_scroll'), $profile_id);
         $ProfilesMeta->metaUpdate('background_stretch', $form->getValue('background_stretch'), $profile_id);
         $ProfilesMeta->metaUpdate('background_noimage', $form->getValue('background_noimage'), $profile_id);
         Application_Plugin_Alerts::success($this->view->translate('Settings updated, please clear your browser cache'), 'off');
     }
     $this->view->image = $current_background_file ? $StorageAdapter->getStoragePath('cover') . $current_background_file : false;
     $this->view->form = $form;
     $this->view->load_colorpicker = true;
 }