Developer's FAQ

Created by: Stephan Borg, 01 Jul 2005 (10:10 UTC)
Last modified: 23 Aug 2007 (10:42 UTC)

How to test a user is logged in?

By sylvie
Tuesday, May 02, 2006
In php:
if( $gBitUser->isRegistered() )
In smarty:
{if $gBitUser->isRegistered()}

In smarty, how to do a link to another package?

By sylvie
Tuesday, May 02, 2006

In Smarty, how do I check what browser is being used?

By Stephan Borg
Friday, July 01, 2005
Here is a code sample for your .tpl:


<?php
{if $gBitLoc.browser.client eq 'mz' or $gBitLoc.browser.client eq 'ie'}
    
This browser is IE or Mozilla based!
{/if}
?>


the end.

How do I create a LibertyContent Class?

By Stephan Borg
Thursday, December 29, 2005
Your best bet to creating a LibertyContent class, is to copy the SamplePackage, BitSample.php file and modify accordingly.

The best approach is to:
  • Modify the verify() function first, making sure each and every field is validated correctly.
  • Modify the store() function, ensuring data is stored in the table correctly.
  • Modify the load() function
  • Modify the getList() function
  • Modify the expunge() function

Can I use strtotime() and strftime()?

By Stephan Borg
Thursday, December 29, 2005
We have implement locale timezone formatting using BitDate() class.

For easy access, always use:

<?php
$gBitSystem
->mServerTimestamp->strtotime(...);

and

$gBitSystem->mServerTimestamp->strftime(...);

as 
straight replacements.
?>


Inside Smarty templates, use the:

<?php
{$timestamp|bit_short_datetime}
?>


Other formats are:
  • bit_date_format
  • bit_long_datetime
  • bit_short_date
  • bit_short_time
  • bit_long_date
  • bit_long_time
  • bit_short_datetime

Can I use strtotime() and strftime()?

By Stephan Borg
Thursday, December 29, 2005
We have implement locale timezone formatting using BitDate() class.

For easy access, always use:

<?php
$gBitSystem
->mServerTimestamp->strtotime(...);

and

$gBitSystem->mServerTimestamp->strftime(...);

as 
straight replacements.
?>


Inside Smarty templates, use the:

<?php
{$timestamp|bit_short_datetime}
?>


Other formats are:
  • bit_date_format
  • bit_long_datetime
  • bit_short_date
  • bit_short_time
  • bit_long_date
  • bit_long_time
  • bit_short_datetime

How do I check in Smarty, if Liberty content is in HTML?

By Stephan Borg
Friday, July 01, 2005

<?php
{if $gContent->mInfo.format_guid == 'bithtml'}
    
This is HTML content!
{/if}
?>

How do I check for a preference setting in Smarty?

By Stephan Borg
Friday, July 01, 2005

<?php
{if $gBitSystemPrefs.tinymce_ask eq 'y'}
    
This setting is 'yes'!
{else}
    
This setting is 'no'!
{/if}
?>

How do I add an Administration menu to a package?

By Stephan Borg
Friday, July 01, 2005
Well...
First you need a package/admin/admin_package_inc.php file, which will look something like this:
{code}<?php
$formTinyMCEFeatures = array(
"tinymce_ask" => array(
'label' => 'WYSIWYG confirmation',
'note' => 'Ask before using the WYSIWYG editor tinymce when clicking on a textarea. If you disable this feature, we strongly suggest you enable HTML content format as the only content format and also disable quicktags.',
'page' => '',
),
);
$smarty->assign( 'formTinyMCEFea…

How do I check if the current user has a permission?

By Stephan Borg
Friday, July 01, 2005

<?php
if ($gBitUser->hasPermission('bit_p_admin_cms')) {
    
This user has permission!
}
?>


NOTE: if you want to exit and display an error message if they don't have permission, then:

<?php
$gBitSystem
->verifyPermission'bit_p_view' );
?>

This displays a standard "You do not have permission!" error message.