Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Stian Sigvartsen
Removing chat bar using custom theme or hook
August 21, 2011 1:34 PM
Answer

Stian Sigvartsen

Rank: Regular Member

Posts: 103

Join Date: August 27, 2010

Recent Posts

Hi

I was considering posting this to the "Custom Theme Development" forum category, but I think this is more development centric, and may include the use of a hook. I don't know...

What I would like to do is implement some kind of plug-in which when associated with a particular page, removes the rendering of the "chat bar" you see on the classic theme. I have been experimenting with a custom theme for this, and I have only been successful in removing the "chat bar" by removing the rendering of all portlet content.

I've also tried overriding (by editing _diff/templates/init_custom.vm in my theme) the Velocity variable $is_signed_in with a new value of "false". I thought this might work because chat bar isn't shown when not logged in. But it didn't. If I print the value of $is_signed_in out into the page response, it shows the value "false" as desired, but the chat bar is still rendering, and the dock bar still shows the logged in user's ID.

I've also tried the same by overriding the $USER_ID and $USER Velocity variables with empty string values. No luck.

Finally, I've tried implementing a hook which overrides the mentioned Velocity variables by invoking request.setAttribute("is_signed_in", "false") and request.removeAttribute("is_signed_in") (etc.) in a service hook bound to servlet.service.events.pre in portal.properties. This too did not work.

Any help would be greatly appreciated!

-Stian
Bijan Vakili
RE: Removing chat bar using custom theme or hook
August 21, 2011 3:56 PM
Answer

Bijan Vakili

Rank: Expert

Posts: 354

Join Date: March 10, 2009

Recent Posts

Stian,

How about modifying the chat portlet to add a preference property for controlling the visibility?

Let me know should you need help doing this.

Thanks.
Hitoshi Ozawa
RE: Removing chat bar using custom theme or hook
August 21, 2011 4:14 PM
Answer

Hitoshi Ozawa

Rank: Liferay Legend

Posts: 7949

Join Date: March 23, 2010

Recent Posts

Can't you just change the height of the chat portlet to 0px;?
BTW, if you want to put conditions, you'll have to change the css dynamically.

.chat-bar {
background: url(<%= request.getContextPath() %>/images/btm-dock_bg.png);
border: 1px 1px 1px 0 solid #b5b5b5;
bottom: 0;
height: 0px;
left: 15px;
position: fixed;
right: 15px;
z-index: 1000;
}
Victor Zorin
RE: Removing chat bar using custom theme or hook
August 22, 2011 5:09 AM
Answer

Victor Zorin

Rank: Liferay Legend

Posts: 1177

Join Date: April 14, 2008

Recent Posts

Probably the best place to do switching of chat display is within view.jsp of chat-portlet application, have a look at line somewhere at the top of this file:
<c:if test="<%= themeDisplay.isSignedIn() && !(BrowserSnifferUtil.isIe(request) && (BrowserSnifferUtil.getMajorVersion(request) < 7)) %>">

add your own switch, e.g.
1<% boolean displayFlag = true;
2System.out.println("attr=" + request.getAttribute("displayChatFlag"));
3if(request.getAttribute("displayChatFlag") != null && ((String)request.getAttribute("displayChatFlag")).compareTo("true") == 0)
4{
5  displayFlag = true;
6}
7%>
8<c:if test="<%= displayFlag && themeDisplay.isSignedIn() && !(BrowserSnifferUtil.isIe(request) && (BrowserSnifferUtil.getMajorVersion(request) < 7)) %>">

How do you derive your displayFlag is up to you.
Stian Sigvartsen
RE: Removing chat bar using custom theme or hook
August 25, 2011 6:03 PM
Answer

Stian Sigvartsen

Rank: Regular Member

Posts: 103

Join Date: August 27, 2010

Recent Posts

Many thanks for the very helpful replies. The Liferay community is indeed very strong! emoticon

I would prefer to achieve the removal of the chat bar without modifying the code of one of the chat portlet because this I believe would require me to potentially reapply the modification every time Liferay is upgraded. Please correct if I'm wrong!

I'd also prefer not to hide the chat portlet using CSS because of adaptive technologies. These would still read out the chat portlet content to the user, which is undesirable.

I'm currently looking at using a NestedPorlet containing all the portlets that otherwise would have been on the page. I've discovered that if I use the generated URL for the "any website" sharing feature on the NestedPortlet, then that achieves the rendering result I was after for the page. i.e. no chat bar and no content other than that generated by the portlets. Though I'm puzzled as to why, when you click on a link within one of the nested portlets whilst sharing (as widget) the NestedPortlet, Liferay 6.0.6 CE re-rendering only the content of that particular portlet rather than the NestedPortlet and all its nested portlets.

-Stian
Hitoshi Ozawa
RE: Removing chat bar using custom theme or hook
August 25, 2011 6:29 PM
Answer

Hitoshi Ozawa

Rank: Liferay Legend

Posts: 7949

Join Date: March 23, 2010

Recent Posts

I would prefer to achieve the removal of the chat bar without modifying the code of one of the chat portlet because this I believe would require me to potentially reapply the modification every time Liferay is upgraded. Please correct if I'm wrong!


If it just the jsp file that's going to be modified, you can just create a hook. A hook is just a war file. When you upgrade Liferay, you can just redeploy the war file.

If you need to modify some java codes, you may need to create an ext plugin. Ext plugin is dependent of the version/release that's you're using and there may be a need to re-modify the codes.
Jelmer Kuperus
RE: Removing chat bar using custom theme or hook
August 26, 2011 2:02 AM
Answer

Jelmer Kuperus

Rank: Liferay Legend

Posts: 1192

Join Date: March 10, 2010

Recent Posts

The chat portlet is not a built-in portlet though, you have to add it as a seperate war. Afaik hooks cannot change files in external war files. So overriding it's view.jsp is out of the question

The correct (tm) solution here, i think would be to hook html/portal/layout/view/portlet.jsp. There you find

 1
 2<c:if test="<%= !themeDisplay.isFacebook() && !themeDisplay.isStateExclusive() && !themeDisplay.isStatePopUp() && !themeDisplay.isWidget() %>">
 3
 4    <%
 5    for (String portletId : PropsValues.LAYOUT_STATIC_PORTLETS_ALL) {
 6        if (PortletLocalServiceUtil.hasPortlet(company.getCompanyId(), portletId)) {
 7    %>
 8
 9            <liferay-portlet:runtime portletName="<%= portletId %>" />
10
11    <%
12        }
13    }
14    %>
15
16</c:if>


You can easily add your own condtions there
Hitoshi Ozawa
RE: Removing chat bar using custom theme or hook
August 26, 2011 5:18 AM
Answer

Hitoshi Ozawa

Rank: Liferay Legend

Posts: 7949

Join Date: March 23, 2010

Recent Posts

Right you are jelmer. Can't create a hook nor an ext plugin for external war.
Stian Sigvartsen
RE: Removing chat bar using custom theme or hook
August 31, 2011 1:17 AM
Answer

Stian Sigvartsen

Rank: Regular Member

Posts: 103

Join Date: August 27, 2010

Recent Posts

Thanks Jelmer

I did as you suggested and overwrote the portlet.jsp using a hook adding my own condition which checks for a request parameter. It works really well when I request the page, but when I click on any link on the page (possibly a link in a portlet) the request parameter isn't persisted. This of course is no big surprise, but obviously something I need to fix!

I guess that when Liferay 6.1 is released I could do this using a ServletFilter style hook to rewrite URLs in the portal response.

I'm currently investigating using a service hook for "servlet.service.events.pre" and a decorator pattern on the HttpServletResponse to attempt to do this. Is there an easier way though?

-Stian
Jelmer Kuperus
RE: Removing chat bar using custom theme or hook
August 31, 2011 1:31 AM
Answer

Jelmer Kuperus

Rank: Liferay Legend

Posts: 1192

Join Date: March 10, 2010

Recent Posts

Hey Stian, what is it exactly you are trying to do? Based on your original post I assumed that you wanted remove the chat portlet on specific pages. Not based on the presence of a request parameter. If that's still the case why dont you do a check based on the url
Stian Sigvartsen
RE: Removing chat bar using custom theme or hook
August 31, 2011 3:29 AM
Answer

Stian Sigvartsen

Rank: Regular Member

Posts: 103

Join Date: August 27, 2010

Recent Posts

I'd like to create a theme (or similar, possibly a hook), which when associated with a particular page (most likely applied to all pages of a particular community) has the following characterisics:
  1. The page should be embeddable which means that only the content of portlets themselves and their layout is rendered. This should enable the page to be displayed inline in another site using an iFrame, so the "embed" requirement needs to be determined via content of the URL request (parameters, path parts, cookies etc.) It's important that no URLs requested via clicks in the iFrame embedded page causes the page to render without the embedding mode.
  2. If you navigate to the page normally, you notice no change in render behaviour / functionality. i.e. the chat bar is there and so is any of the theme's other various header/footer content. This allows logged in users with appropriate permissions to manipulate the page in the usual way (add portlets, change layout etc.)


I thought using a new request parameter would be the most reliable way to set the "embed" feature on/off because Liferay uses the URL path parts for important features I don't want to meddle. Also, it makes achieving characteristic 2 easy because the absence of the parameter (i.e. the normal operation of the portal) could be evaluated as you don't want to embed.

p.s. I have been investigating using NestedPortlet shared as a widget. Unfortunately, there appears to be a bug in that whenever you click a hyperlink in any of the portlets within the NestedPortlet widget, the widget re-renders with only that particular portlet.

-Stian
Jelmer Kuperus
RE: Removing chat bar using custom theme or hook
August 31, 2011 5:38 AM
Answer

Jelmer Kuperus

Rank: Liferay Legend

Posts: 1192

Join Date: March 10, 2010

Recent Posts

Oh dear, that does sounds rather non trivial

Disabling the chat bar based on the selected theme should be easy to do from the jsp hook you already created. Thats a matter of doing something like

1if (PortletKeys.CHAT.equals(portletId) && "your_theme_id".equals(themeDisplay.getThemeId())) {
2    return;
3}


So if you only wanted to use this site from within the iframe you would be done now.

But basically you are saying that you want to use the same site with different themes, depending on context

Apply a minimal theme when the site is loaded via an iframe
Apply the regular theme when the site is accessed directly

That's fairly tricky. Your best bet would be to write a service pre action that based on some condition dynamically selects a theme. This post gives you a hint on how to do this : http://www.liferay.com/community/forums/-/message_boards/message/1056358

Probably the easiest condition to check for would be to use a different host name per theme. Say mysite.com for the regular site and iframe.mysite.com for the site you load in the iframe.

But all this is rather non trivial so I would carefully weigh any alternatives
Mohamed Rizwanuzaman
RE: Removing chat bar using custom theme or hook
October 10, 2012 11:20 PM
Answer

Mohamed Rizwanuzaman

Rank: New Member

Posts: 20

Join Date: December 16, 2009

Recent Posts

Thanks Jelmer,

your post help me out to create hook for disabling the chat portlet for particular community. Nice work.

Regards,
Rizwan