Programatically filter web content by scope in Liferay 6.2.GA2 - liferay

Updating to have more info:
Is there any way to programatically select all the web content from global scope or currently selected site scope.
I want to do this in velocity template "portal_normal.vm". I wrote "$themeDisplay.getScopeGroupId().toString()" to get group id.
I have 2 sites/communities and I have assigned one user to each of them. One site is default liferay site which has default liferay user.Other site is my custom site and has my own user. When I try to login with each of them ,I always get group id of liferay site.Is there any other method I need to use to get site of current logged in user?

You must allow the usage of ServiceLocator in your Velocity templates. In your portal-ext.properties set the following:
journal.template.velocity.restricted.variables=
If you already have these keys set, just remove serviceLocator from the list.
Using serviceLocator we can load GroupLocalServiceUtil and JournalArticleLocalServiceUtil. Its very simple to obtain all the sites WebContent:
#set ($journal_article_local_service = $serviceLocator.findService("com.liferay.portal.service.JournalArticleLocalService"))
#set ($journal_articles = $journal_article_local_service.getArticles($theme_display.getScopeGroupId()))
To get all the ones in the global scope:
For the global group:
#set ($group_local_service = $serviceLocator.findService("com.liferay.portal.service.GroupLocalService"))
#set ($global_group = $group_local_service.getGroup($theme_display.getCompanyId(), "Global"))
#set ($journal_article_local_service = $serviceLocator.findService("com.liferay.portal.service.JournalArticleLocalService"))
#set ($journal_articles = $journal_article_local_service.getArticles($global_group.getGroupId()))

Related

How to create single page application in liferay 7?

Can anyone share some detailed info on how to create a Single Page Application (SPA) in Liferay 7 using SennaJS.
I could't found any documentation on How to create SPA in Liferay 7.
It comes by default, except if you unset the following property:
javascript.single.page.application.enabled=true
BTW, it is rather annoying in dev instances, as it takes a while to load pages in the first access, sometimes you even need to reload the page. Also, be aware, in some especial cases, some applications might break, normally due to code that counts with page reloads to function properly.
you can even create it in 6.2 by using the following code.
// initializing senna
var app = new senna.App();
// Set links selector for navigations
app.setLinkSelector(".senna-link");
// set basic path of liferay site
app.setBasePath('/web/spa-demo/');
// Id of DOM element which will be replaced from
// next page request
// using content div - default in liferay theme
app.addSurfaces('content');
// define routes for all the navigation links
// route link = Base path + page link
app.addRoutes([
new senna.Route('home', senna.HtmlScreen),
new senna.Route('second', senna.HtmlScreen),
new senna.Route('third', senna.HtmlScreen),
]);
Thing which you need to take care of, if it is SPA, then all the events need to be bound first i.e. delegate as there is not going to be page refresh.
i.e things like document.getReady is only going to be called once.
Whatever the portlet you are going to create and deploy with Liferay SDK/Workspace OR any compatible liferay plugin it will be SPA by default.
No need to do any coding on top of it.

How do I configure an existing website or create a new one in WiX?

I'm creating a wix installer to install multiple web applications, I give the user the option to select an existing website or create a new one. So far, I have implemented the user interface and queried the IIS for the existing websites, but the problem is that I don't know how to configure these two options. I tried using conditional components where I check for a property I set in a custom action but the issue with this scenario is that I end up placing the website element inside a component which I don't want to do in case the user chose an existing website(to avoid it from getting deleted on uninstall)..I found solutions on the web for installing to an existing website or creating a new one but never the both..Can anyone help me with this?
You can create Custom action for that and set the result of it to wix property.
string result ;
session["RESULT"] = result;
then in your wxs :
<Custom Action="InstallWebsite" After='InstallFinalize'>NOT Install AND (<![CDATA[RESULT<>"Existing"]]>)</Custom>
You can create Custom action for that and set the result of it to wix property.
string result ;
session["RESULT"] = result;
then in your wxs :

export liferay user group to OpenLDAP

I configured liferay-portal-6.2-ce-ga4 with OpenLDAP. Users are imported into OpenLDAP from liferay. But User group of liferay are not exported into OpenLDAP. Here is my portal-ext.properties:
ldap.factory.initial=com.sun.jndi.ldap.LdapCtxFactory
ldap.server.name=ldapadmin
ldap.auth.enabled=true
ldap.import.enabled=true
ldap.export.enabled=true
ldap.import.on.startup=true
ldap.export.on.startup=true
ldap.export.method.0=group
ldap.export.method.0=user
ldap.password.policy.enabled=true
ldap.base.provider.url.0=ldap://localhost:389
ldap.base.dn.0=dc=test,dc=com
ldap.security.principal.0=cn=admin,dc=test,dc=com
ldap.security.credentials.0=secret
ldap.auth.search.filter.0=(mail=#email_address#)
ldap.import.user.search.filter.0=(objectClass=inetOrgPerson)
ldap.user.mappings.0=userId=uid\nscreenName=cn\nemailAddress=mail\npassword=userPassword\nfirstName=givenName\nlastName=sn
ldap.import.group.search.filter.0=(objectClass=posixGroup)
ldap.group.mappings.0=groupName=cn\ndescription=description\nuser=memberUid
ldap.users.dn.0=ou=people,dc=test,dc=com
ldap.groups.dn.0=ou=groups,dc=test,dc=com
ldap.user.default.object.classes.0=inetOrgPerson, top
ldap.group.default.object.classes.0=posixGroup, top, groupOfUniqueNames,organizationalUnit
I have checked by clicking on 'Test LDAP Groups' button I can see around 5 groups which are created in OpenLDAP using OpenLDAP GUI but can't see any group which i create in liferay. Its not exporting User Groups its only exporting users. Please give some solution for this.
I think the keys you use on your portal-ext.properties file are wrong.
In the documentation we can read:
#
# Settings for exporting users from the portal to LDAP. This allows a user
# to modify his first name, last name, etc. in the portal and have that
# change pushed to the LDAP server. This setting is not used unless the
# property "ldap.auth.enabled" is set to true.
#
ldap.export.enabled=false
#
# Set this to true if groups and their associations should be exported from
# the portal to LDAP. This setting is not used unless the property
# "ldap.auth.enabled" is set to true.
#
ldap.export.group.enabled=true
So you should use:
ldap.export.enabled=true
ldap.export.group.enabled=true

Register/ Login/ Membership module in Orchard

I can't figure out how to add Register/Login functionality to a site in Orchard. Is there a Membership module or some configuration I need to enable?
EDIT: What I had in mind were modules along the lines of these that extend the existing User model with registration/profile functionality:
Extended Registration module: http://extendedregistration.codeplex.com/
Orchard Profile module: http://orchardprofile.codeplex.com/
It's under settings/users in the admin ui.
In the Dashboard scroll down to Settings and select Users.
Make sure "Users can create new accounts on the site" is checked and click "Save".
Once this is done log out.
Then click log in, and bellow your username and password field there will be a small text with a blue link to Register.
You don't actually need the extended registration and profile for this. Those are for adding additional information to the registration form.
This can also be done programmatically:
var registrationSettings = _services.WorkContext.CurrentSite.As<RegistrationSettingsPart>();
registrationSettings.UsersCanRegister = true;
However this will not work if you're doing it from Migrations because you won't be able to use WorkContext.
For migrations you can use IRepository for RegistrationSettingsPartRecord:
RegistrationSettingsPartRecord currentSetting = _registrationSettingRepository.Table.First();
currentSetting.UsersCanRegister = true;
_registrationSettingRepository.Update(currentSetting);
However this will no longer work as of Orchard version 1.8 as the record no longer exists. As of 1.8 one way I know of would be using ISiteService:
var site = _siteService.GetSiteSettings();
var regsettings = site.As<RegistrationSettingsPart>();
regsettings.UsersCanRegister = true;

Is it possible to add Bamboo Web Parts to a web part page programmatically in SharePoint?

Can't find much information on how to do this at all - how can I add in a web part and then configure the settings for it?
Here's a code snippet that will do that for you. In this example, I put a Content Editor Web Part on the page and set the content of it programmatically. If you want to find out what properties your web part has, you can manually put it on a page and export it. Examine the exported file for the property names.
In your case, must must reference the 3rd party DLL, and use the name on the desired web part instead of the ContentEditorWebPart. You can find out the name by either using the Object Browser or Reflector.
SPFile spPageFile = web.GetFile(targetFilePath);
using (SPLimitedWebPartManager theMan = spPageFile.GetLimitedWebPartManager(PersonalizationScope.Shared))
{
ContentEditorWebPart cewp = new ContentEditorWebPart();
cewp.ChromeType = PartChromeType.None;
XmlDocument xmlDoc = new XmlDocument();
XmlElement xmlEl = xmlDoc.CreateElement("NewCEWP");
xmlEl.InnerText = string.Format(#"<h2>Blah blah blah...</h2>");
cewp.Content = xmlEl;
theMan.AddWebPart(cewp, "Main", 0);
theMan.SaveChanges(wp);
}
Hope this helps.
Load the page you want to add the web part to via object model.
Get the SPLimitedWebPartManager for this page.
Add the web part you want via the AddWebPart() method.
If your web part uses the normal web part configuration then you can access the settings via the web parts properties.

Resources