public function getPosts(array $user_ids, $tag = null, $name = null, $order = 'created_at')
 {
     $ids = array();
     if (!empty($tag)) {
         $tag_mapper = new Application_Model_TagMapper();
         $result = $tag_mapper->findAllByTwoColumns('content', $tag, 'type', TYPE_TAG);
         foreach ($result as $row) {
             $ids[] = $row['post_id'];
         }
     } else {
         $select = $this->getDbTable()->select();
         $select->setIntegrityCheck(false);
         $select->from("user_post", array('id'));
         if (!empty($name)) {
             $select->join('google_user', 'user_post.user_id = google_user.id', array('username'));
             $select->where('google_user.username = ?', $name);
         } else {
             $select->where('user_id IN(?)', $user_ids);
         }
         if ($order == 'created_at' || $order == '') {
             $select->order("user_post.created_at" . ' DESC');
         } elseif ($order == "hot") {
             $select->order("user_post.comment_number" . ' DESC');
         }
         $result = $this->getDbTable()->fetchAll($select);
         foreach ($result as $row) {
             $ids[] = $row['id'];
         }
     }
     return $ids;
 }
 public function postxmlAction()
 {
     $request = $this->getRequest();
     $id = $request->getParam("id");
     if (!is_numeric($id)) {
         throw new Exception("empty post id");
     }
     $post_mapper = new Application_Model_PostMapper();
     $post_info = $post_mapper->getPostInfo($id);
     $post_image_path = get_post_path($id);
     $user_id = $post_info['user_id'];
     $profile_pic = get_profile_path($user_id);
     $tag_mapper = new Application_Model_TagMapper();
     $tags = $tag_mapper->findAllByTwoColumns("post_id", $id, "type", TYPE_TAG);
     $comment_mapper = new Application_Model_CommentMapper();
     $comments = $comment_mapper->getComments($id);
     $comments_count = $comment_mapper->count($id);
     $like_mapper = new Application_Model_LikeMapper();
     $like_numbers = $like_mapper->count($id);
     $share_mapper = new Application_Model_ShareMapper();
     $shares = $share_mapper->count($id);
     $xml_text = '<?xml version="1.0" encoding="UTF-8"?>';
     $xml_text .= '<post hot="no">';
     $xml_text .= '<author>' . $post_info['author'] . '</author>';
     $xml_text .= '<proofilepic>' . $profile_pic . '</proofilepic>';
     $xml_text .= '<date>' . gmdate("Y/m/d  H:i", $post_info['date']) . '</date>';
     $xml_text .= '<updated_at>' . gmdate("Y/m/d  H:i", $post_info['updated_at']) . '</updated_at>';
     $xml_text .= '<image>' . $post_image_path . '</image>';
     $xml_text .= '<text>' . $post_info['text'] . '</text>';
     $xml_text .= '<share>' . $shares . '</share>';
     $xml_text .= '<id>' . $id . '</id>';
     $xml_text .= "<like likeNumber=" . '"' . $like_numbers . '"' . ">";
     $xml_text .= "<likers>";
     $xml_text .= "</likers>";
     $xml_text .= "</like>";
     $xml_text .= "<tag>";
     if (!empty($tags)) {
         foreach ($tags as $tag) {
             $xml_text .= "#" . $tag['content'];
         }
     }
     $xml_text .= "</tag>";
     // comments
     $comments_link = "http://plus.local/post/allcomment/id/" . $id;
     $xml_text .= '<comments commentNumber="' . $comments_count . '" allCommentsLink="' . $comments_link . '">';
     foreach ($comments as $comment) {
         $xml_text .= "<comment>";
         $xml_text .= "<text>" . $comment['content'] . "</text>";
         $xml_text .= "<image>" . get_profile_path($comment['user_id']) . "</image>";
         $xml_text .= "<date>" . gmdate("Y/m/d  H:i", $comment['created_at']) . "</date>";
         $xml_text .= "<name>" . $comment['username'] . "</name>";
         $xml_text .= "</comment>";
     }
     $xml_text .= "</comments>";
     $xml_text .= '</post>';
     header("Content-type: text/xml");
     $xml = new SimpleXMLElement($xml_text);
     echo $xml->asXML();
     exit;
 }