public function share($user_id, $post_id)
 {
     $post_mapper = new Application_Model_PostMapper();
     $user_mapper = new Application_Model_UserMapper();
     $shared_post = $post_mapper->find($post_id);
     $user = $user_mapper->find($shared_post['user_id']);
     $share_elm = $this->findByTwoColumns('user_id', $user_id, 'post_id', $post_id);
     $db = Zend_Registry::get('db');
     if (empty($share_elm)) {
         $sql = "insert into post_share VALUES(" . $user_id . "," . $post_id . ");";
         $db->query($sql);
         $post_model = new Application_Model_Post();
         $username = $user['username'];
         $post_model->_fields['user_id'] = get_user_id();
         $post_model->_fields['content'] = "The Post originally shared by {$username}: \n" . $shared_post['content'];
         $post_model->_fields['comment_number'] = 0;
         $post_model->_fields['is_reported'] = 0;
         $post_model->_fields['updated_at'] = time();
         $new_id = $post_mapper->save($post_model);
         $path = APPLICATION_PATH . "/../public/post_pic/" . "{$post_id}.png";
         $path2 = APPLICATION_PATH . "/../public/post_pic/{$new_id}.png";
         copy($path, $path2);
         return true;
     }
     return false;
 }
Example #2
0
 public function readAction()
 {
     //Instance du Mapper
     $userMapper = new Application_Model_UserMapper();
     //Find
     $user = $userMapper->find($this->getRequest()->getParam('id'));
     //Envoie des données à la vue
     $this->view->user = $user;
 }
 public function homeAction()
 {
     $request = $this->getRequest();
     $this->view->isAdmin = is_admin();
     $name = $request->getParam("name");
     $order = $request->getParam('order');
     $tag = $request->getParam('tag');
     $xml_loc = "http://plus.local/post/getposts";
     if (!empty($tag)) {
         $xml_loc .= "/tag/{$tag}";
     } elseif (!empty($name)) {
         $xml_loc .= "/name/{$name}";
     } elseif (!empty($order)) {
         $xml_loc .= "/order/{$order}";
     }
     $this->view->xml = $xml_loc;
     $user_mapper = new Application_Model_UserMapper();
     $user = $user_mapper->find(get_user_id());
     $this->view->username = $user['username'];
 }
 public function activateAction()
 {
     if (!$this->getRequest()->getParam('activation_key')) {
         return $this->_redirect('/');
     }
     // check if the activation key is valid
     $user_activation_mapper = new Application_Model_UserActivationMapper();
     $user_activation = $user_activation_mapper->findByActivation_key($this->getRequest()->getParam('activation_key'));
     if ($user_activation) {
         $user_activation = $user_activation[0];
         /**
          * Check if the activation key has not expired (24 hours have not
          * passed)
          */
         $now = date('Y-m-d H:i:s');
         $time_elapsed = abs(strtotime($now) - strtotime($user_activation->getCreated()));
         $time_elapsed = (int) ($time_elapsed / 86400);
         if ($time_elapsed) {
             /**
              * Redirect the user back to the confirmation page to generate a
              * fresh activation key
              */
             return $this->_redirect('/registration/confirm/id' . $user_activation->getUser_id());
         }
         // Check if the user associated with the activation key exists
         $user_mapper = new Application_Model_UserMapper();
         $user = $user_mapper->find($user_activation->getUser_id());
         if (!$user) {
             $user_activation_mapper->delete($user_activation->getId());
             return $this->_redirect('/');
         }
         // Activate the account and delete the obsolete activation key
         $user->setActive(1);
         $user_mapper->save($user);
         $user_activation_mapper->delete($user_activation->getId());
     } else {
         return $this->_redirect('/');
     }
 }
Example #5
0
 public function resetPasswordAction()
 {
     if (!$this->getRequest()->getParam('password_reset_key')) {
         return $this->_redirect('/auth/forgot-password');
     }
     // check if the reset key is valid
     $password_reset_mapper = new Application_Model_PasswordResetMapper();
     $password_reset = $password_reset_mapper->findByPassword_reset_key($this->getRequest()->getParam('password_reset_key'));
     if ($password_reset) {
         $password_reset = $password_reset[0];
         /**
          * Check if the activation key has not expired (24 hours have not
          * passed)
          */
         $now = date('Y-m-d H:i:s');
         $time_elapsed = abs(strtotime($now) - strtotime($password_reset->getCreated()));
         $time_elapsed = (int) ($time_elapsed / 86400);
         if ($time_elapsed) {
             /**
              * Redirect the user back to the form to generate a fresh reset
              * key
              */
             return $this->_redirect('/auth/forgot-password');
         }
         // check if the user associated with the reset key exists
         $user_mapper = new Application_Model_UserMapper();
         $user = $user_mapper->find($password_reset->getUser_id());
         if (!$user) {
             $password_reset_mapper->delete($password_reset->getId());
             return $this->_redirect('/');
         }
         // process the form
         $form = new Application_Form_PasswordReset();
         if ($this->getRequest()->isPost() && $form->isValid($_POST)) {
             if ($form->getValue('password') == $form->getValue('password_confirm')) {
                 // Hash the password with a random salt
                 $user->setPassword_salt(mcrypt_create_iv(64));
                 $user->setPassword_hash(hash('sha256', $user->getPassword_salt() . $form->getValue('password')));
                 // Save the new password
                 $user_mapper->save($user);
                 $password_reset_mapper->delete($password_reset->getId());
                 print 'Your password has been successfully reset.';
             } else {
                 print "The password was not confirmed.";
                 $form->password_reset_key->setValue($this->getRequest()->getParam('password_reset_key'));
                 $this->view->form = $form;
             }
         } else {
             $form->password_reset_key->setValue($this->getRequest()->getParam('password_reset_key'));
             $this->view->form = $form;
         }
     } else {
         return $this->_redirect('/');
     }
 }
 public function editAction()
 {
     $request = $this->getRequest();
     $user_id = get_user_id();
     $user_mapper = new Application_Model_UserMapper();
     $user = $user_mapper->find($user_id);
     $this->view->user = $user;
     if ($request->isPost()) {
         $username = $request->getParam("username");
         $password = $request->getParam("password");
         $about = $request->getParam("about");
         $place = $request->getParam('place');
         if (strlen($username) < 4) {
             $this->_redirect("/user/edit");
         }
         $user_model = new Application_Model_User();
         $user_model->_fields['id'] = $user_id;
         $user_model->_fields['username'] = $username;
         $user_model->_fields['about'] = $about;
         $user_model->_fields['place'] = $place;
         $user_model->_fields['password'] = $password;
         $user_mapper->save($user_model);
         if (isset($_FILES['profile_pic'])) {
             if (is_uploaded_file($_FILES['profile_pic']['tmp_name'])) {
                 if (!move_uploaded_file($_FILES['profile_pic']['tmp_name'], APPLICATION_PATH . "/../public/profile_pic/" . $user_id . '.png')) {
                     $this->_redirect("/user/edit");
                 }
             }
         }
         if (isset($_FILES['cover_pic'])) {
             if (!is_uploaded_file($_FILES['cover_pic']['tmp_name'])) {
                 $this->_redirect("/profile/profile");
             }
             if (!move_uploaded_file($_FILES['cover_pic']['tmp_name'], APPLICATION_PATH . "/../public/cover_pic/" . $user_id . '.png')) {
                 $this->_redirect("/user/edit");
             }
         }
         $this->_redirect("/profile/profile");
     }
 }
 public function viewxmlAction()
 {
     $request = $this->getRequest();
     $user_id = get_user_id();
     $follower_mapper = new Application_Model_FollowMapper();
     $friends = $follower_mapper->findAllByColumn('follower_id', $user_id);
     $user_mapper = new Application_Model_UserMapper();
     $persons = array();
     foreach ($friends as $friend) {
         $friends_of_friend = $follower_mapper->findAllByColumn('followed_id', $friend['followed_id']);
         foreach ($friends_of_friend as $ff) {
             $person_id = $ff['follower_id'];
             $image = get_profile_path($person_id);
             $person = $user_mapper->find($person_id);
             $name = $person['username'];
             $about = $person['about'];
             $matual = $user_mapper->find($friend['followed_id']);
             $matual_name = $matual['username'];
             if ($name != get_username()) {
                 $f = $follower_mapper->findAllByTwoColumns('followed_id', $ff['follower_id'], 'follower_id', get_user_id());
                 if (empty($f)) {
                     $persons[] = array('image' => $image, 'name' => $name, 'about' => $about, 'matual_friend' => $matual_name);
                 }
             }
         }
     }
     $note = '<?xml version="1.0" encoding="UTF-8"?>';
     $note .= "<people>";
     foreach ($persons as $item) {
         $note .= "<person>";
         $note .= "<image>";
         $note .= $item['image'];
         $note .= "</image>";
         $note .= "<name>";
         $note .= $item['name'];
         $note .= "</name>";
         $note .= "<about>";
         $note .= $item['about'];
         $note .= "</about>";
         $note .= "<matualFriend>";
         $note .= $item['matual_friend'];
         $note .= "</matualFriend>";
         $note .= "</person>";
     }
     $note .= "</people>";
     header("Content-type: text/xml");
     $xml = new SimpleXMLElement($note);
     echo $xml->asXML();
     exit;
 }