function actionDefault()
 {
     // Define the date format used for testing
     $fmt = '%A, %d %B %Y';
     // Default locale is always en
     YDDebugUtil::dump(YDLocale::get(), 'Current locale:');
     YDDebugUtil::dump(strftime($fmt), 'strftime test');
     // Set the locale to English
     YDLocale::set('eng');
     YDDebugUtil::dump(YDLocale::get(), 'Current locale:');
     YDDebugUtil::dump(strftime($fmt), 'strftime test');
     // Set the locale to Dutch
     YDLocale::set('nl');
     YDDebugUtil::dump(YDLocale::get(), 'Current locale:');
     YDDebugUtil::dump(strftime($fmt), 'strftime test');
     YDDebugUtil::dump(date("l dS of F Y h:i:s A"), 'date function');
     // Set the locale to Portugese
     YDLocale::set('ptg');
     YDDebugUtil::dump(YDLocale::get(), 'Current locale:');
     YDDebugUtil::dump(strftime($fmt), 'strftime test');
     // Set the locale to Italian
     YDLocale::set('ita');
     YDDebugUtil::dump(YDLocale::get(), 'Current locale:');
     YDDebugUtil::dump(strftime($fmt), 'strftime test');
 }
function t($t)
{
    // Return empty string when param is missing
    if (empty($t)) {
        return '';
    }
    // Load the language file
    @(include_once dirname(__FILE__) . '/languages/language_' . strtolower(YDLocale::get()) . '.php');
    // Initialize the language array
    if (!isset($GLOBALS['t'])) {
        $GLOBALS['t'] = array();
    }
    // Return the right translation
    $t = strtolower($t);
    return array_key_exists($t, $GLOBALS['t']) ? $GLOBALS['t'][$t] : "%{$t}%";
}
 /**
  *  This function returns an associative array with checkboxgroups
  *
  * @param $id    	User id (when adding new group), Group id (when editing group)
  * @param $edit   	We are adding or editing
  *
  * @returns    YDForm object pointer         
  */
 function &_addFormDetails($id, $edit)
 {
     // init form
     $this->_form = new YDForm($this->_form_name);
     // if this group is not a root group we must get the parent group permissions to check the ones we can use
     $userobject = new YDCMUserobject();
     $groups = $userobject->getElements(array('ydcmgroup', 'ydcmuser'));
     $parent_id = $groups[$id]['parent_id'];
     // when adding a new group, parent of $id is the master group. when editing a group, parent is a user.. so the master group is the parent of the parent
     if ($edit == true) {
         $parent_id = $groups[$parent_id]['parent_id'];
     }
     // if parent of this group is root, parentgroup permissions are ALL (read: null), otherwise we must get permissions of that parent
     if ($parent_id == 1) {
         $parentgroup_perms = null;
     } else {
         $parentgroup_perms = $this->getPermissions($parent_id);
     }
     // if we are editing, we must get the current group permissions
     if ($edit == true) {
         $perms = $this->getPermissions($id);
     }
     // init form defaults array
     $form_defaults = array();
     // get all possible actions to compute checkboxgroups for each class
     foreach ($this->getRegisteredActions() as $class => $actions) {
         // get permission translations for each component
         YDLocale::addDirectory(YD_DIR_HOME_ADD . '/YDCMComponent/languages/' . $class);
         // init checkboxgroup options, disabled options and default values
         $chk_options = array();
         $chk_disable = array();
         $form_defaults['pclass_' . $class] = array();
         // cycle all actions of this class to get translations and default values
         foreach ($actions as $action) {
             // get actions labels
             $chk_options[$action] = $this->getActionTitle($class, $action);
             // if parentgroup is the root (id 1) or the parent group has the correspondent action, this action must be set based on current group db values
             if (is_null($parentgroup_perms) || isset($parentgroup_perms[$class][$action])) {
                 // if we are editing and the current group has this permission we must check it. if we are adding just uncheck it
                 if ($edit && isset($perms[$class][$action])) {
                     $form_defaults['pclass_' . $class][$action] = 1;
                 }
                 // otherwise the action must be unset and disabled (because, if the parent group cannot do something, this group cannot do too)
             } else {
                 $form_defaults['pclass_' . $class][$action] = 0;
                 $chk_disable[] = $action;
             }
         }
         // add checkboxgroup to form
         $checkboxgroup =& $this->_form->addElement('checkboxgroup', 'pclass_' . $class, $this->getClassTitle($class), array(), $chk_options);
         $checkboxgroup->addSelectAll(true, array('class' => 'ydcmpermission_checkbox_selall'));
         $checkboxgroup->setAttribute('class', 'ydcmpermission_checkbox');
         $checkboxgroup->setLabelAttribute('class', 'ydcmpermission_checkbox_label');
         // disable checkboxgroup options that are not valid for this group
         if (!empty($chk_disable)) {
             $this->_form->disable('pclass_' . $class, $chk_disable);
         }
     }
     // add submit button
     $this->_form->addElement('submit', '_cmdSubmit', t('save'));
     // set form defaults
     $this->_form->setDefaults($form_defaults);
     return $this->_form;
 }
 /**
  *  This function will format a timestamp using the strftime function.
  *
  *  @param  $timestamp  The timestamp to format. It can also be a date/time form object.
  *  @param  $format     The strftime format to use. You can also use the predefined options date, time and
  *                      datetime.
  *  @param  $locale     (optional) The locale to use to format the date.
  *
  *  @returns    A formatted timestamp
  *
  *  @static
  */
 function formatDate($timestamp, $format, $locale = null)
 {
     // Check if the timestamp is an object and has the getTimeStamp function
     if (is_object($timestamp) && method_exists($timestamp, 'getTimeStamp')) {
         $timestamp = $timestamp->getTimeStamp();
     }
     // Convert to an integer
     if (is_numeric($timestamp)) {
         $timestamp = intval($timestamp);
     }
     // If text, convert to number
     if (is_string($timestamp)) {
         $timestamp = strtotime($timestamp);
     }
     // If array, is a date YDForm element value
     if (is_array($timestamp)) {
         // check if timestamp exists. otherwise create it
         $hours = isset($timestamp['hours']) ? $timestamp['hours'] : 0;
         $minutes = isset($timestamp['minutes']) ? $timestamp['minutes'] : 0;
         $seconds = isset($timestamp['seconds']) ? $timestamp['seconds'] : 0;
         $month = isset($timestamp['month']) ? $timestamp['month'] : 1;
         $day = isset($timestamp['day']) ? $timestamp['day'] : 1;
         $year = isset($timestamp['year']) ? $timestamp['year'] : 1970;
         $timestamp = mktime($hours, $minutes, $seconds, $month, $day, $year);
     }
     // Check the standard formats
     if (strtolower($format) == 'date') {
         $format = '%d %B %Y';
     }
     if (strtolower($format) == 'datetime') {
         $format = '%d %B %Y %H:%M';
     }
     if (strtolower($format) == 'datetimesql') {
         $format = '%Y-%m-%d %H:%M:%S';
     }
     if (strtolower($format) == 'time') {
         $format = '%H:%M';
     }
     if (strtolower($format) == 'file') {
         $format = '%d-%m-%Y %H:%M';
     }
     // Set the new locale
     if (!is_null($locale)) {
         $currentLocale = YDLocale::get();
         YDLocale::set($locale);
     }
     // Return the formatted date
     $timestamp = strftime($format, $timestamp);
     // Reset the old locale
     if (!is_null($locale)) {
         YDLocale::set($currentLocale);
     }
     // Return the timestamp
     return $timestamp;
 }
 function actionDefault()
 {
     YDDebugUtil::dump(YDDate::now(), 'YDDate::now()');
     YDDebugUtil::dump(YDDate::nowCustom("%d"), 'YDDate::nowCustom( "%d" )');
     YDDebugUtil::dump(YDDate::nowCustom("%d %B %Y"), 'YDDate::nowCustom( "%d %B %Y" )');
     // Static validation
     YDDebugUtil::dump(YDDate::get("HUM", time()), 'YDDate::get( "HUM", time() )');
     YDDebugUtil::dump(YDDate::get("EUN_DATE", time()), 'YDDate::get( "EUN_DATE", time() )');
     YDDebugUtil::dump(YDDate::get("HUM_DATE", "2004-03-12", "ISO"), 'YDDate::get( "HUM_DATE", "2004-03-12", "ISO" )');
     YDDebugUtil::dump(YDDate::now(), 'YDDate::now()');
     YDDebugUtil::dump(YDDate::now("EUN_DATE"), 'YDDate::now( "EUN_DATE" )');
     YDDebugUtil::dump(YDDate::now("ISO_TIME"), 'YDDate::now( "ISO_TIME" )');
     YDDebugUtil::dump(YDDate::now("HUM"), 'YDDate::now( "HUM" )');
     YDDebugUtil::dump(YDDate::isValid(""), 'YDDate::isValid( "" )');
     YDDebugUtil::dump(YDDate::isValid("0000-00-00 00:00:00", "ISO"), 'YDDate::isValid( "0000-00-00 00:00:00", "ISO" )');
     YDDebugUtil::dump(YDDate::isValid("0000-00-00 00:00:00", "ISO", true, false), 'YDDate::isValid( "0000-00-00 00:00:00", "ISO", true, false )');
     YDDebugUtil::dump(YDDate::isValid("2005-5-5"), 'YDDate::isValid( "2005-5-5" )');
     YDDebugUtil::dump(YDDate::isValid("2005 5 15"), 'YDDate::isValid( "2005 5 15" )');
     YDDebugUtil::dump(YDDate::isValid("20050515", "SQL"), 'YDDate::isValid( "20050515", "SQL" )');
     YDDebugUtil::dump(YDDate::isValid("15 5 2005", "EUN"), 'YDDate::isValid( "15 5 2005", "EUN" )');
     YDDebugUtil::dump(YDDate::isValid("15 May 2005", "HUM"), 'YDDate::isValid( "15 May 2005", "HUM" )');
     YDDebugUtil::dump(YDDate::isValid("5.15.2005", "USA"), 'YDDate::isValid( "5.15.2005", "USA" )');
     YDDebugUtil::dump(YDDate::isValid("5.15.2005", "EUN"), 'YDDate::isValid( "5.15.2005", "EUN" )');
     YDDebugUtil::dump(YDDate::isValid("5.15.2005", "HUM"), 'YDDate::isValid( "5.15.2005", "HUM" )');
     YDDebugUtil::dump(YDDate::isValid("5.15.2005", "ISO"), 'YDDate::isValid( "5.15.2005", "ISO" )');
     YDDebugUtil::dump(YDDate::isValid("5.15.2005", "SQL"), 'YDDate::isValid( "5.15.2005", "SQL" )');
     $date = new YDDate();
     // Setting an empty date
     $date->set("0000-00-00 00:00:00");
     YDDebugUtil::dump($date->get(), '$date->set( "0000-00-00 00:00:00" )');
     // Setting Unix epoch
     $date->set(0);
     YDDebugUtil::dump($date->get(), '$date->set( 0 )');
     // Setting in SQL format
     $date->set("20050515", "SQL");
     YDDebugUtil::dump($date->get(), '$date->set( "20050515", "SQL" )');
     // Setting in ISO format
     $date->set("2005-5-5");
     YDDebugUtil::dump($date->get(), '$date->set( "2005-5-15" )');
     $date->set("2005 5 15");
     YDDebugUtil::dump($date->get(), '$date->set( "2005 5 15" )');
     // Setting in EUN format
     $date->set("15 5 2005", "EUN");
     YDDebugUtil::dump($date->get(), '$date->set( "15 5 2005", "EUN" )');
     // Setting in HUM format
     $date->set("15 May 2005", "HUM");
     YDDebugUtil::dump($date->get(), '$date->set( "15 May 2005", "HUM" )');
     // Setting in USA format
     $date->set("5.15.2005", "USA");
     YDDebugUtil::dump($date->get(), '$date->set( "5.15.2005", "USA" )');
     // Setting a custom format
     YDDebugUtil::dump(YDDateFormat::setString("custom format", "%a %A %b %B %d %m %Y %H %M %S %T %w"), 'YDDateFormat::setString( "custom format", "%a %A %b %B %d %m %Y %H %M %S %T %w" )');
     // Returning the date with a custom format
     YDDebugUtil::dump($date->get("custom format"), '$date->get( "custom format" )');
     // Setting the date to today
     $date->set();
     YDDebugUtil::dump($date->get(), '$date->set()');
     // Getting date info
     YDDebugUtil::dump($date->get(), '$date->get()');
     YDDebugUtil::dump($date->isToday(), '$date->isToday()');
     YDDebugUtil::dump($date->isTomorrow(), '$date->isTomorrow()');
     YDDebugUtil::dump($date->isYesterday(), '$date->isYesterday()');
     YDDebugUtil::dump($date->isCurrentHour(), '$date->isCurrentHour()');
     YDDebugUtil::dump($date->isCurrentMinute(), '$date->isCurrentMinute()');
     YDDebugUtil::dump($date->isCurrentMonth(), '$date->isCurrentMonth()');
     YDDebugUtil::dump($date->isCurrentYear(), '$date->isCurrentYear()');
     YDDebugUtil::dump($date->getDayName(), '$date->getDayName()');
     YDDebugUtil::dump($date->getDayName(true), '$date->getDayName( true )');
     YDDebugUtil::dump($date->getMonthName(), '$date->getMonthName()');
     YDDebugUtil::dump($date->getMonthName(true), '$date->getMonthName( true )');
     // Getting date info with different locale
     YDDebugUtil::dump(YDLocale::set("ptb"), 'YDLocale::set( "ptb" )');
     YDDebugUtil::dump($date->getDayName(), '$date->getDayName()');
     YDDebugUtil::dump($date->getDayName(true), '$date->getDayName( true )');
     YDDebugUtil::dump($date->getMonthName(), '$date->getMonthName()');
     YDDebugUtil::dump($date->getMonthName(true), '$date->getMonthName( true )');
     // Comparing two dates
     $date2 = $date;
     $date2->addHour(10);
     $date2->addDay(35);
     YDDebugUtil::dump($date->get(), 'Date 1');
     YDDebugUtil::dump($date2->get(), 'Date 2');
     YDDebugUtil::dump($date->getDifference($date2), 'Difference between Dates 1 and 2');
     // Adding values
     YDDebugUtil::dump($date->get(), '$date->get()');
     YDDebugUtil::dump($date->addSecond(70), '$date->addSecond( 70 )');
     YDDebugUtil::dump($date->addMinute(80), '$date->addMinute( 80 )');
     YDDebugUtil::dump($date->addHour(24), '$date->addHour( 24 )');
     YDDebugUtil::dump($date->addHour(12), '$date->addHour( 12 )');
     YDDebugUtil::dump($date->addHour(-10), '$date->addHour( -10 )');
     YDDebugUtil::dump($date->addHour(-24), '$date->addHour( -24 )');
     YDDebugUtil::dump($date->addMinute(10), '$date->addMinute( 10 )');
     YDDebugUtil::dump($date->addMinute(60), '$date->addMinute( 60 )');
     YDDebugUtil::dump($date->addMinute(120), '$date->addMinute( 120 )');
     YDDebugUtil::dump($date->addMinute(-120), '$date->addMinute( -120 )');
     YDDebugUtil::dump($date->addMinute(360), '$date->addMinute( 360 )');
     YDDebugUtil::dump($date->addSecond(10), '$date->addSecond( 10 )');
     YDDebugUtil::dump($date->addSecond(60), '$date->addSecond( 60 )');
     YDDebugUtil::dump($date->addSecond(3600), '$date->addSecond( 3600 )');
     YDDebugUtil::dump($date->addSecond(), '$date->addSecond( -10 )');
     YDDebugUtil::dump($date->addDay(40), '$date->addDay( 40 )');
     YDDebugUtil::dump($date->addDay(-3), '$date->addDay( -3 )');
     YDDebugUtil::dump($date->addMonth(1), '$date->addMonth( 1 )');
     YDDebugUtil::dump($date->addMonth(12), '$date->addMonth( 12 )');
     YDDebugUtil::dump($date->addMonth(10), '$date->addMonth( 10 )');
     YDDebugUtil::dump($date->addMonth(-4), '$date->addMonth( -4 )');
     YDDebugUtil::dump($date->addMonth(-20), '$date->addMonth( -20 )');
     YDDebugUtil::dump($date->addYear(1), '$date->addYear( 1 )');
     YDDebugUtil::dump($date->addYear(12), '$date->addYear( 12 )');
     YDDebugUtil::dump($date->addYear(10), '$date->addYear( 10 )');
     YDDebugUtil::dump($date->addYear(-4), '$date->addYear( -4 )');
     YDDebugUtil::dump($date->addYear(-20), '$date->addYear( -20 )');
     // Getting an array
     YDDebugUtil::dump($date->toArray(), '$date->toArray()');
     $date->set("1981-11-20");
     YDDebugUtil::dump($date->get(), '$date->set( "1981-11-20" )');
     YDDebugUtil::dump($date->getYearsToToday(), '$date->getYearsToToday()');
     // Should return an error
     YDDebugUtil::dump($date->set("no_date"), '$date->set( "no_date" )');
 }
Example #6
0
<?php

// initialize the Yellow Duck Framework
include_once dirname(__FILE__) . '/../../YDFramework2/YDF2_init.php';
YDInclude('YDDatabase.php');
YDInclude('YDUrl.php');
// BASIC CONFIGURATION: set YDDatabase instance connection
YDDatabase::registerInstance('default', 'mysql', 'xpto', 'root', '', 'localhost');
// BASIC CONFIGURATION: set portal language. Currently you can use 'en' and 'pt'.
YDLocale::set('en');
// set admin template path
YDConfig::set('YDCMTEMPLATES_ADMIN_PATH', dirname(__FILE__) . '/backend/templates');
YDConfig::set('YDCMTEMPLATES_ADMIN_URL', YDUrl::makeLinkAbsolute('./templates'));
 /**
  *  This function will format a timestamp using the strftime function.
  *
  *  @param  $timestamp  The timestamp to format. It can also be a date/time form object.
  *  @param  $format     The strftime format to use. You can also use the predefined options date, time and 
  *                      datetime.
  *  @param  $locale     (optional) The locale to use to format the date.
  *
  *  @returns    A formatted timestamp
  *
  *  @static
  */
 function formatDate($timestamp, $format, $locale = null)
 {
     // Check if the timestamp is an object and has the getTimeStamp function
     if (is_object($timestamp) && method_exists($timestamp, 'getTimeStamp')) {
         $timestamp = $timestamp->getTimeStamp();
     }
     // Convert to an integer
     if (is_numeric($timestamp)) {
         $timestamp = intval($timestamp);
     }
     // If text, convert to number
     if (is_string($timestamp)) {
         $timestamp = strtotime($timestamp);
     }
     // Check the standard formats
     if (strtolower($format) == 'date') {
         $format = '%d %B %Y';
     }
     if (strtolower($format) == 'datetime') {
         $format = '%d %B %Y %H:%M';
     }
     if (strtolower($format) == 'time') {
         $format = '%H:%M';
     }
     // Set the new locale
     if (!is_null($locale)) {
         $currentLocale = YDLocale::get();
         YDLocale::set($locale);
     }
     // Return the formatted date
     $timestamp = strftime($format, $timestamp);
     // Reset the old locale
     if (!is_null($locale)) {
         YDLocale::set($currentLocale);
     }
     // Return the timestamp
     return $timestamp;
 }
        but WITHOUT ANY WARRANTY; without even the implied warranty of
        MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
        Lesser General Public License for more details.
    You should have received a copy of the GNU Lesser General Public
        License along with this library; if not, write to the Free Software
        Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
// Check if the framework is loaded
if (!defined('YD_FW_NAME')) {
    die('Yellow Duck Framework is not loaded.');
}
// set components path
YDConfig::set('YD_DBOBJECT_PATH', YD_DIR_HOME_ADD . '/YDCMComponent', false);
// add translations directory
YDLocale::addDirectory(dirname(__FILE__) . '/languages/');
YDLocale::addDirectory(dirname(__FILE__) . '/languages/YDCMUser/');
YDConfig::set('YDCMTEMPLATES_ADMIN_EXT', '/shot.png', false);
// add YDF libs needed by this class
YDInclude('YDDatabaseObject.php');
YDInclude('YDValidateRules.php');
YDInclude('YDUtil.php');
YDInclude('YDResult.php');
// add YDCM libs
YDInclude('YDCMLanguages.php');
YDInclude('YDCMTemplates.php');
YDInclude('YDCMUserobject.php');
// user class
class YDCMUser extends YDDatabaseObject
{
    function YDCMUser()
    {
<?php

// Standard include
include_once dirname(__FILE__) . '/../../YDFramework2/YDF2_init.php';
// Include server compatibility support (useful if this server don't support gettext)
YDIncludeCompatibility();
// Includes
YDInclude('YDRequest.php');
YDInclude('YDTemplate.php');
// set locale: you can use 'en', 'pt' and 'fr' and use gettext engine with 'test' filenames inside 'locale' language directory
YDLocale::set('pt', 'test', dirname(__FILE__) . '/locale/');
// Class definition
class index extends YDRequest
{
    function index()
    {
        $this->YDRequest();
        $this->tpl = new YDTemplate();
    }
    // Default action
    function actionDefault()
    {
        $this->tpl->assign('var', 'variable');
        $this->tpl->display();
    }
}
// Process the request
YDInclude('YDF2_process.php');
require_once 'includes/config.php';
// Include the Yellow Duck Framework
require_once YD_INIT_FILE;
// Include the classes needed on all pages
YDInclude('YDForm.php');
YDInclude('YDRequest.php');
YDInclude('YDTemplate.php');
require_once 'includes/page.class.php';
require_once 'includes/users.class.php';
// Define the constants we want to override for the Framework
//YDConfig::set( 'YD_DEBUG', 1 );
YDLocale::set(LOCALE);
// Show all errors including notification of unset variables
error_reporting(E_ALL);
// Include the language file
include_once dirname(__FILE__) . '/languages/language_' . strtolower(YDLocale::get()) . '.php';
//	    /**
//     * The t function used for translations
//     * @param t Code of the word to translate
//     * @return t corresponding string for the current locale
//     *
//     * For the moment the code must be in form module.word.or.more
//     * Every thing is currently in one file, could evolve if required
//     */
//    function t( $t ) {
//
//        // Return empty string when param is missing
//        if ( empty( $t ) ) {
//            return '';
//        }
//
 /**
  *	This function adds a new directory
  *
  *	@param	$dir       Directory to add
  */
 function addDirectory($dir)
 {
     if (!isset($GLOBALS['YD_LANGUAGES_DIRECTORIES'])) {
         $GLOBALS['YD_LANGUAGES_DIRECTORIES'] = array();
     }
     $GLOBALS['YD_LANGUAGES_DIRECTORIES'][] = $dir;
     if (!isset($GLOBALS['t'])) {
         $GLOBALS['t'] = array();
     }
     // just try to include language file
     @(include_once $dir . '/' . YDLocale::get() . '.php');
 }
 /**
  *  This function return node attributes
  *
  *  @returns    An array with all attributes
  */
 function getNode()
 {
     // delete previous stored values
     $this->resetAll();
     // define our id to find
     $this->content_id = $this->_id;
     $this->language_id = YDLocale::get();
     $this->limit(1);
     // find node
     $this->findAll();
     // parse html
     if (isset($this->html)) {
         $this->html = htmlentities($this->html);
     }
     if (isset($this->xhtml)) {
         $this->xhtml = htmlentities($this->xhtml);
     }
     // return node attributes without relation prefixs
     return $this->getValues(false, false, false, false);
 }