Friday, June 13, 2014

[Liferay] Permission Checker : Setting a portlet to be available for Admin only..

In last post, we got all the sites, but everyone can access what we have in front end if we don't take care of Permissions. 

Permission checker comes into the picture.. 


PermissionChecker permissionChecker = PermissionThreadLocal.getPermissionChecker(); 
Boolean isUserAdmin =permissionChecker.isOmniadmin();
if(permissionChecker.isOmniadmin()){
          // Do what you want.. no user other than admin can see this.
}
Imports..
com.liferay.portal.security.permission.PermissionThreadLocal
com.liferay.portal.security.permission.PermissionChecker


That's all we need. 

Enjoy. Now you have all the sites.

Thursday, June 12, 2014

[Liferay] Get all the sites in Liferay

Its time I start posting about Liferay.. :)

Most of the times we need very small things.. code that can help us getting data from liferay.. its all there already, but we are not aware most often..

I had to load all groups/sites in a dropdown and then select one to extract some content from the document library of that group. So to make it easier, and clean It was better to provide a list of all sites to Admin and let Admin decide which one to be selected.

To get all the groups we can simply use.
List<Group> groups = GroupLocalServiceUtil.getGroups(0, GroupLocalServiceUtil.getGroupsCount());

But to get only sites we need.. to use search method.
List<Group> groups = GroupLocalServiceUtil.search(PortalUtil.getCompanyId(renderRequest), null, null,null, QueryUtil.ALL_POS, QueryUtil.ALL_POS);

Imports are..
com.liferay.portal.kernel.dao.orm.QueryUtil
com.liferay.portal.util.PortalUtil
com.liferay.portal.model.Group
com.liferay.portal.service.GroupLocalServiceUtil

Thats it.. :)

Friday, April 26, 2013

How to enable php short tags with .htaccess or with php.ini

Sometimes when we don't have access to modify configurations on server like in php.ini file and we still need to enable short tags for our php code. We can do it by .htaccess file. If you have not created any .htaccess file yet, create one in root directory of your website and add
php_value short_open_tag 1
That's it for .htaccess file.

Now if you want to enable that using php.ini and if you can...

just set
short_open_tag=On 
in php.ini at server and you are done.. :D

Enjoy!!
-Ravi Kumar Gupta 

Sunday, March 10, 2013

Invert Colors in Paint: Is it Gone? No... :)

Invert colors in new paint is not gone.. just select the part where you want to invert colors and then right click on it.. select invert colors.. :D

Wednesday, March 6, 2013

Check if Email is Valid using PHP

Hello Friends,

Sometimes when you need to check if email is valid or not in your code... just use this function..

function isValidEmail($email) {
    return preg_match("/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$/", $email);
}

Enjoy!!

Ravi Kumar Gupta aka D'Maverick

Thursday, July 19, 2012

Remove all alpha-numeric characters from a phone number

Hi Friends,

To remove all alpha-numeric characters from a phone number.. in php simple one line code..


$phoneStr = "+91-23223-24232";

$phone = preg_replace('/\D+/', '', $phoneStr  );


resulted phone number will be plain number like 912322324232


Enjoy!!!
Ravi