Profile preview in social engine like facebook

If any one need to preview a user profile then he/she might look here.

At first I make a controller in user module. It is similar to profile view. I simply want to load this page where the viewer will be null. So I make some adjustment.
#step 1:
Create a controller just for keep it simple

class User_PreviewProfileController extends Core_Controller_Action_Standard

    public function init()
        // @todo this may not work with some of the content stuff in here, double-check
        $subject = null;
        if (!Engine_Api::_()->core()->hasSubject())
            $id = $this->_getParam('id');

            // use viewer ID if not specified
            //if( is_null($id) )
            //  $id = Engine_Api::_()->user()->getViewer()->getIdentity();

            if (null !== $id)
                $subject = Engine_Api::_()->user()->getUser($id);
                if ($subject->getIdentity())

                $subject, Engine_Api::_()->user()->getViewer(), 'view'

    public function indexAction()
        $subject = Engine_Api::_()->core()->getSubject();
        $viewer = Engine_Api::_()->user()->getViewer();
        // check if the viewer of this page is the same user
        if ($subject->isSelf($viewer))
            $viewer = Engine_Api::_()->user()->getViewer($viewer->getIdentity());

        // check public settings
        $require_check = Engine_Api::_()->getApi('settings', 'core')->core_general_profile;
        if (!$require_check && !$this->_helper->requireUser()->isValid())

        // Check enabled
        if (!$subject->enabled && !$viewer->isAdmin())
            return $this->_forward('requireauth', 'error', 'core');

        // Check block
        if ($viewer->isBlockedBy($subject) && !$viewer->isAdmin())
            return $this->_forward('requireauth', 'error', 'core');

        // Increment view count
        if (!$subject->isSelf($viewer))

        // Check to see if profile styles is allowed
        $style_perm = Engine_Api::_()->getDbtable('permissions', 'authorization')->getAllowed('user', $subject->level_id, 'style');
        if ($style_perm)
            // Get styles
            $table = Engine_Api::_()->getDbtable('styles', 'core');
            $select = $table->select()
                    ->where('type = ?', $subject->getType())
                    ->where('id = ?', $subject->getIdentity())

            $row = $table->fetchRow($select);
            if (null !== $row && !empty($row->style))

        // Render


#Step 2
router for the link

// User - Specific Profile Preview
        'user_preview_profile' => array(
            'route' => 'preview/profile/:id/*',
            'defaults' => array(
                'module' => 'user',
                'controller' => 'preview-profile',
                'action' => 'index'

#step 3
create page for the link

INSERT INTO `engine4_core_pages` (`name`, `displayname`, `url`, `title`, `description`, `keywords`, `custom`, `fragment`, `layout`, `levels`, `provides`, `view_count`) VALUES
('user_preview-profile_index', 'Preview Member Profile', NULL, 'Preview Member Profile', 'This is a member''s preview profile.', '', 0, 0, '', NULL, 'subject=user', 0);

#step 4
Now create content of the page

INSERT INTO `engine4_core_content` (`content_id`, `page_id`, `type`, `name`, `parent_content_id`, `order`, `params`, `attribs`) VALUES
(609, 18, 'container', 'main', NULL, 2, '[""]', NULL),
(610, 18, 'container', 'left', 609, 4, '[""]', NULL),
(611, 18, 'container', 'middle', 609, 6, '[""]', NULL),

Note: Here content_id for main remain empty when you create main
for other put main content_id as parent_content_id

And then do same as member profile does.

#step 5
Slight change to your getViewer model function

// Viewer

     * Gets the current viewer instance using the authentication storage
     * @return User_Model_User
    public function getViewer($id = null)
        if (null === $this->_viewer)
            $identity = $this->getAuth()->getIdentity();
            $this->_viewer = $this->_getUser($identity);
        elseif($this->getAuth()->getIdentity() == $id)
            $this->_viewer = $this->_getUser(null);

        return $this->_viewer;

#step 6
Now create a new menu in user home menu

INSERT INTO `engine4_core_menuitems` (`name`, `module`, `label`, `plugin`, `params`, `menu`, `submenu`, `enabled`, `custom`, `order`) VALUES
('user_home_preview', 'user', 'Preview My Profile', 'User_Plugin_Menus', '{"route":"user_preview_profile","icon":"application/modules/User/externals/images/links/profile.png"}', 'user_home', '', 1, 0, 22);

#step 7
create a initialization function for the menu in user core

public function onMenuInitialize_UserHomePreview($row)
    $viewer = Engine_Api::_()->user()->getViewer();
    if( $viewer->getIdentity() ) {
      return array(
        'label' => $row->label,
        'icon' => $row->params['icon'],
        'route' => 'user_preview_profile',
        'params' => array(
          'id' => $viewer->getIdentity()
    return false;

That’s it. Have fun!


Tagged: , ,

37 thoughts on “Profile preview in social engine like facebook

  1. Asif December 11, 2012 at 3:36 pm Reply

    hy i am Asif Mirza from Pakistan i work in socialengine and zend i want to write articles for your blog.

  2. Pat April 2, 2013 at 11:56 pm Reply

    We’re a bunch of volunteers and opening a new scheme in our community. Your website provided us with useful info to work on. You’ve done a formidable task and our whole neighborhood will be thankful to you.

  3. Chi April 16, 2013 at 1:54 am Reply

    I am truly happy to read this web site posts which includes plenty of useful facts, thanks for providing such data.

  4. Sheila April 16, 2013 at 5:56 am Reply

    Thanks for the auspicious writeup. It in fact was once a entertainment account it. Glance advanced to far delivered agreeable from you! By the way, how can we keep in touch?

  5. Theodore April 16, 2013 at 1:50 pm Reply

    Awesome post.

  6. Fay April 17, 2013 at 3:25 am Reply

    I read this post fully on the topic of the difference of newest and previous technologies, it’s remarkable article.

  7. Latanya April 18, 2013 at 12:16 am Reply

    I’m amazed, I have to admit. Rarely do I come across a blog that’s equally educative and engaging, and let me tell you, you’ve hit the nail on the head. The problem is something that not enough people are speaking intelligently about. I’m very happy I came across this in my search for something relating to this.

  8. Cassie April 18, 2013 at 12:34 am Reply

    Hi there friends, how is all, and what you wish for to say regarding this piece of writing, in my view its truly amazing for me.

  9. Verena April 21, 2013 at 12:23 am Reply

    I read this article completely concerning the difference of hottest and earlier technologies, it’s awesome article.

  10. Irvin April 25, 2013 at 2:57 pm Reply

    Hello there! I know this is somewhat off topic but I was wondering which blog platform are you using for this website? I’m getting tired of WordPress because I’ve had problems with hackers and I’m looking at options for another platform. I would be awesome if you could point me in the direction of a good platform.

  11. Gilda April 29, 2013 at 4:42 pm Reply

    Hi there I am so grateful I found your weblog, I really found you by accident, while I was researching on Digg for something else, Nonetheless I am here now and would just like to say thank you for a remarkable post and a all round enjoyable blog (I also love the theme/design), I don’t have time to read through it all at the minute but I have saved it and also added in your RSS feeds, so when I have time I will be back to read more, Please do keep up the fantastic jo.

  12. Steffen May 10, 2013 at 9:43 pm Reply

    I am really impressed with your writing skills as well as with the layout in your blog. Is this a paid theme or did you modify it your self? Anyway keep up the nice quality writing, it’s rare to see a nice blog like this one these days..

  13. Arden May 14, 2013 at 5:31 am Reply

    I really like it whenever people get together and share views. Great blog, keep it up!

  14. Rosalyn May 14, 2013 at 1:19 pm Reply

    Hey! This is kind of off topic but I need some help from an established blog. Is it very hard to set up your own blog? I’m not very techincal but I can figure things out pretty fast. I’m thinking about creating my own but I’m not sure where to begin. Do you have any tips or suggestions? Thanks

  15. Pearlene May 16, 2013 at 8:55 pm Reply

    Definitely believe that which you said. Your favorite reason appeared to be at the net the easiest thing to remember of. I say to you, I certainly get annoyed whilst folks consider worries that they plainly don’t recognise about. You controlled to hit the nail upon the highest as neatly as outlined out the whole thing without having side effect , other folks could take a signal. Will probably be back to get more. Thanks

  16. Patrick May 17, 2013 at 7:40 pm Reply

    Hi, yes this paragraph is truly nice and I have learned lot of things from it concerning blogging. thanks.

  17. Annmarie May 17, 2013 at 9:33 pm Reply

    An outstanding share! I’ve just forwarded this onto a friend who has been conducting a little research on this. And he actually bought me breakfast simply because I found it for him… lol. So allow me to reword this…. Thank YOU for the meal!! But yeah, thanks for spending some time to talk about this issue here on your internet site.

  18. Rodrigo May 18, 2013 at 2:41 am Reply

    I’m really impressed along with your writing talents and also with the layout on your weblog. Is that this a paid subject or did you modify it yourself? Either way keep up the nice high quality writing, it is uncommon to look a great blog like this one nowadays..

  19. Cindy May 18, 2013 at 2:46 am Reply

    Simply want to say your article is as astounding. The clarity in your publish is simply excellent and that i can suppose you are knowledgeable in this subject. Well along with your permission allow me to grasp your RSS feed to keep updated with coming near near post. Thanks 1,000,000 and please keep up the gratifying work.

  20. Raymond May 19, 2013 at 7:10 pm Reply

    This is very attention-grabbing, You are an excessively skilled blogger. I have joined your rss feed and look forward to in search of extra of your fantastic post. Additionally, I have shared your website in my social networks

  21. Ernesto May 20, 2013 at 11:08 pm Reply

    What’s up to all, how is everything, I think every one is getting more from this web page, and your views are pleasant designed for new people.

  22. Jami May 20, 2013 at 11:43 pm Reply

    Oh my goodness! Amazing article dude! Thank you, However I am encountering issues with your RSS. I don’t know the reason why I cannot join it. Is there anybody else getting similar RSS issues? Anybody who knows the answer can you kindly respond? Thanx!!

  23. Yukiko May 21, 2013 at 3:48 pm Reply

    Thank you for some other informative web site. The place else may I get that kind of info written in such an ideal way? I’ve a venture that I am simply now operating on, and I’ve been at the look out for such info.

  24. Jacki May 24, 2013 at 12:26 am Reply

    Thanks on your marvelous posting! I actually enjoyed reading it, you may be a great author. I will ensure that I bookmark your blog and may come back down the road. I want to encourage one to continue your great posts, have a nice holiday weekend!

  25. Mickey May 24, 2013 at 1:23 am Reply

    What i don’t understood is in truth how you’re not really a lot more neatly-preferred than you may be right now. You’re so intelligent. You realize thus significantly relating to this matter, produced me in my opinion consider it from numerous varied angles. Its like women and men aren’t fascinated until it’s one thing to do with Girl gaga! Your personal stuffs great. Always take care of it up!

  26. Rod May 24, 2013 at 3:29 am Reply

    I always used to read paragraph in news papers but now as I am a user of internet thus from now I am using net for articles, thanks to web.

  27. Madelaine May 24, 2013 at 4:16 am Reply

    This paragraph gives clear idea in favor of the new viewers of blogging, that actually how to do blogging and site-building.

  28. Jackie May 24, 2013 at 6:55 am Reply

    It’s awesome to pay a visit this site and reading the views of all friends on the topic of this piece of writing, while I am also zealous of getting knowledge.

  29. Shona May 28, 2013 at 1:44 pm Reply

    Hello, yes this piece of writing is in fact pleasant and I have learned lot of things from it on the topic of blogging. thanks.

  30. Charles June 6, 2013 at 5:38 pm Reply

    Thanks for sharing your thoughts about %meta_keyword%. Regards

  31. Nigel June 11, 2013 at 1:04 pm Reply

    Good replies in return of this query with solid arguments and describing everything on the topic of that.

  32. Earnest June 23, 2013 at 8:10 pm Reply

    Hi! Someone in my Facebook group shared this website with us so I came to check it out. I’m definitely enjoying the information. I’m book-marking and will be tweeting this to my followers! Great blog and outstanding design.

  33. Kattie July 26, 2013 at 8:33 pm Reply

    Hi there to all, how is all, I think every one is getting more from this website, and your views are good in support of new visitors.

  34. Luella July 27, 2013 at 2:33 am Reply

    I do accept as true with all the ideas you’ve offered to your post. They are very convincing and can definitely work. Still, the posts are too short for beginners. May you please lengthen them a bit from next time? Thank you for the post.

  35. Jamaal August 7, 2013 at 7:16 am Reply

    This is very interesting, You are an overly skilled blogger. I’ve joined your rss feed and look ahead to seeking extra of your wonderful post. Also, I’ve shared your website in my social networks

  36. Bryce September 24, 2013 at 6:30 am Reply

    wonderful points altogether, you just won a new reader. What could you recommend about your publish that you simply made a few days in the past? Any positive?

  37. Hildegard March 14, 2014 at 6:05 pm Reply

    whoah this blog is wonderful i really like studying your articles. Keep up the good work! You know, a lot of persons are hunting round for this information, you can help them greatly.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: