public function getpostsAction()
 {
     $request = $this->getRequest();
     $order = $request->getParam('order');
     $tag = $request->getParam('tag');
     $name = $request->getParam('name');
     $user_id = get_user_id();
     $user_ids = array();
     $user_ids[] = $user_id;
     $follow_mapper = new Application_Model_FollowMapper();
     $friends = $follow_mapper->findAllByColumn('follower_id', $user_id);
     if (!empty($friends)) {
         foreach ($friends as $friend) {
             $user_ids[] = $friend['followed_id'];
         }
     }
     $post_mapper = new Application_Model_PostMapper();
     $posts_ids = $post_mapper->getPosts($user_ids, $tag, $name, $order);
     $xml_text = '<?xml version="1.0" encoding="UTF-8"?>';
     $xml_text .= '<posts>';
     foreach ($posts_ids as $post_id) {
         $xml_text .= '<post>' . "http://plus.local/post/postxml/id/" . $post_id . "</post>";
     }
     $xml_text .= '</posts>';
     header("Content-type: text/xml");
     $xml = new SimpleXMLElement($xml_text);
     echo $xml->asXML();
     exit;
 }
 public function searchAction()
 {
     $request = $this->getRequest();
     $name = $request->getParam("username");
     if (empty($name)) {
         $this->_redirect("post/home");
     }
     $user_mapper = new Application_Model_UserMapper();
     $followed = $user_mapper->findByColumn("username", $name);
     if (empty($followed)) {
         $this->_redirect("post/home");
     }
     $followed_id = $followed["id"];
     $follower_id = get_user_id();
     $follow_mapper = new Application_Model_FollowMapper();
     $follow_mapper->InsertFollower($follower_id, $followed_id);
     $this->_redirect("post/home");
 }
 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;
 }