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;
 }
 public function editAction()
 {
     $request = $this->getRequest();
     $post_id = $request->getParam("id");
     if (empty($post_id)) {
         throw new Exception("empty post_id");
     }
     $post_mapper = new Application_Model_PostMapper();
     $post = $post_mapper->find($post_id);
     if (empty($post)) {
         throw new Exception("empty post");
     }
     $this->view->post = $post;
     $user_id = get_user_id();
     if ($post['user_id'] != $user_id) {
         throw new Exception("Not Authorized");
     }
     $tag_mapper = new Application_Model_TagMapper();
     $tags1 = $tag_mapper->findAllByColumn('post_id', $post_id);
     $tag_array = array();
     foreach ($tags1 as $tag) {
         $tag_content = "#" . $tag['content'];
         $tag_array[] = $tag_content;
     }
     $this->view->tags = $tag_array;
     if ($request->isPost()) {
         $content = $request->getParam("content");
         $pieces = explode("#", $content);
         $post_content = $pieces[0];
         $tags = array();
         for ($i = 1; $i < sizeof($pieces); $i++) {
             $tags[] = $pieces[$i];
         }
         $post_model = new Application_Model_Post();
         $post_model->_fields['id'] = $post_id;
         $post_model->_fields['updated_at'] = time();
         $post_model->_fields['created_at'] = $post['created_at'];
         $post_model->_fields['content'] = $post_content;
         $post_model->_fields['user_id'] = $user_id;
         $post_model->_fields['is_reported'] = 0;
         $post_mapper = new Application_Model_PostMapper();
         $post_id = $post_mapper->save($post_model);
         $tag_mapper = new Application_Model_TagMapper();
         foreach ($tags1 as $tag1) {
             $tag_mapper->delete($tag1['id']);
         }
         foreach ($tags as $tag) {
             $comment_model = new Application_Model_Tag();
             $comment_model->_fields['content'] = $tag;
             $comment_model->_fields['post_id'] = $post_id;
             $comment_model->_fields['type'] = TYPE_TAG;
             $tag_mapper->save($comment_model);
         }
         if (isset($_FILES['post_pic'])) {
             if (is_uploaded_file($_FILES['post_pic']['tmp_name'])) {
                 if (!move_uploaded_file($_FILES['post_pic']['tmp_name'], APPLICATION_PATH . "/../public/post_pic/" . $post_id . '.png')) {
                     throw new Exception("error in moving file");
                 }
             }
         }
         $this->_redirect("/post/home");
     }
 }