protected function setUp()
 {
     TimeZoneConfig::setSystemTimeZone();
     $this->c = new Calendar();
 }
Example #2
0
/**
* Displays user preferences
*
*/
function editpreferences()
{
    global $_TABLES, $_CONF, $LANG04, $_USER, $_GROUPS;
    $result = DB_query("SELECT noicons,willing,dfid,tzid,noboxes,maxstories,tids,aids,boxes,emailfromadmin,emailfromuser,showonline FROM {$_TABLES['userprefs']},{$_TABLES['userindex']} WHERE {$_TABLES['userindex']}.uid = {$_USER['uid']} AND {$_TABLES['userprefs']}.uid = {$_USER['uid']}");
    $A = DB_fetchArray($result);
    // 'maxstories' may be 0, in which case it will pick up the default
    // setting for the current topic or $_CONF['limitnews'] (see index.php)
    if (empty($A['maxstories'])) {
        $A['maxstories'] = 0;
    } else {
        if ($A['maxstories'] > 0) {
            if ($A['maxstories'] < $_CONF['minnews']) {
                $A['maxstories'] = $_CONF['minnews'];
            }
        }
    }
    $preferences = new Template($_CONF['path_layout'] . 'preferences');
    $preferences->set_file(array('prefs' => 'displayprefs.thtml', 'display' => 'displayblock.thtml', 'exclude' => 'excludeblock.thtml', 'digest' => 'digestblock.thtml', 'boxes' => 'boxesblock.thtml', 'comment' => 'commentblock.thtml', 'language' => 'language.thtml', 'theme' => 'theme.thtml', 'privacy' => 'privacyblock.thtml'));
    $preferences->set_var('xhtml', XHTML);
    $preferences->set_var('site_url', $_CONF['site_url']);
    $preferences->set_var('layout_url', $_CONF['layout_url']);
    $preferences->set_var('user_name', $_USER['username']);
    $preferences->set_var('lang_language', $LANG04[73]);
    $preferences->set_var('lang_theme', $LANG04[72]);
    $preferences->set_var('lang_theme_text', $LANG04[74]);
    $preferences->set_var('lang_misc_title', $LANG04[138]);
    $preferences->set_var('lang_misc_help_title', $LANG04[139]);
    $preferences->set_var('lang_misc_help', $LANG04[140]);
    $preferences->set_var('lang_noicons', $LANG04[40]);
    $preferences->set_var('lang_noicons_text', $LANG04[49]);
    $preferences->set_var('lang_noboxes', $LANG04[44]);
    $preferences->set_var('lang_noboxes_text', $LANG04[51]);
    $preferences->set_var('lang_maxstories', $LANG04[43]);
    if (strpos($LANG04[52], '%d') === false) {
        $maxtext = $LANG04[52] . ' ' . $_CONF['limitnews'];
    } else {
        $maxtext = sprintf($LANG04[52], $_CONF['limitnews']);
    }
    $preferences->set_var('lang_maxstories_text', $maxtext);
    $preferences->set_var('lang_dateformat', $LANG04[42]);
    $preferences->set_var('lang_excluded_items_title', $LANG04[137]);
    $preferences->set_var('lang_excluded_items', $LANG04[54]);
    $preferences->set_var('lang_exclude_title', $LANG04[136]);
    $preferences->set_var('lang_topics', $LANG04[48]);
    $preferences->set_var('lang_emailedtopics', $LANG04[76]);
    $preferences->set_var('lang_digest_top_header', $LANG04[131]);
    $preferences->set_var('lang_digest_help_header', $LANG04[132]);
    $preferences->set_var('lang_boxes_title', $LANG04[144]);
    $preferences->set_var('lang_boxes_help_title', $LANG04[143]);
    $preferences->set_var('lang_boxes', $LANG04[55]);
    $preferences->set_var('lang_displaymode', $LANG04[57]);
    $preferences->set_var('lang_displaymode_text', $LANG04[60]);
    $preferences->set_var('lang_sortorder', $LANG04[58]);
    $preferences->set_var('lang_sortorder_text', $LANG04[61]);
    $preferences->set_var('lang_comment_title', $LANG04[133]);
    $preferences->set_var('lang_comment_help_title', $LANG04[134]);
    $preferences->set_var('lang_comment_help', $LANG04[135]);
    $preferences->set_var('lang_commentlimit', $LANG04[59]);
    $preferences->set_var('lang_commentlimit_text', $LANG04[62]);
    $preferences->set_var('lang_privacy_title', $LANG04[141]);
    $preferences->set_var('lang_privacy_help_title', $LANG04[141]);
    $preferences->set_var('lang_privacy_help', $LANG04[142]);
    $preferences->set_var('lang_emailfromadmin', $LANG04[100]);
    $preferences->set_var('lang_emailfromadmin_text', $LANG04[101]);
    $preferences->set_var('lang_emailfromuser', $LANG04[102]);
    $preferences->set_var('lang_emailfromuser_text', $LANG04[103]);
    $preferences->set_var('lang_showonline', $LANG04[104]);
    $preferences->set_var('lang_showonline_text', $LANG04[105]);
    $preferences->set_var('lang_submit', $LANG04[9]);
    $display_name = COM_getDisplayName($_USER['uid']);
    $preferences->set_var('lang_authors_exclude', $LANG04[46]);
    $preferences->set_var('lang_boxes_exclude', $LANG04[47]);
    $preferences->set_var('start_block_display', COM_startBlock($LANG04[45] . ' ' . $display_name));
    $preferences->set_var('start_block_digest', COM_startBlock($LANG04[75] . ' ' . $display_name));
    $preferences->set_var('start_block_comment', COM_startBlock($LANG04[64] . ' ' . $display_name));
    $preferences->set_var('start_block_privacy', COM_startBlock($LANG04[99] . ' ' . $display_name));
    $preferences->set_var('end_block', COM_endBlock());
    $preferences->set_var('display_headline', $LANG04[45] . ' ' . $display_name);
    $preferences->set_var('exclude_headline', $LANG04[46] . ' ' . $display_name);
    $preferences->set_var('digest_headline', $LANG04[75] . ' ' . $display_name);
    $preferences->set_var('boxes_headline', $LANG04[47] . ' ' . $display_name);
    $preferences->set_var('comment_headline', $LANG04[64] . ' ' . $display_name);
    $preferences->set_var('privacy_headline', $LANG04[99] . ' ' . $display_name);
    // display preferences block
    if ($_CONF['allow_user_language'] == 1) {
        if (empty($_USER['language'])) {
            $userlang = $_CONF['language'];
        } else {
            $userlang = $_USER['language'];
        }
        // Get available languages
        $language = MBYTE_languageList($_CONF['default_charset']);
        $has_valid_language = count(array_keys($language, $userlang));
        if ($has_valid_language == 0) {
            // The user's preferred language is no longer available.
            // We have a problem now, since we've overwritten $_CONF['language']
            // with the user's preferred language ($_USER['language']) and
            // therefore don't know what the system's default language is.
            // So we'll try to find a similar language. If that doesn't help,
            // the dropdown will default to the first language in the list ...
            $tmp = explode('_', $userlang);
            $similarLang = $tmp[0];
        }
        $selection = '<select id="language" name="language">' . LB;
        foreach ($language as $langFile => $langName) {
            $selection .= '<option value="' . $langFile . '"';
            if ($langFile == $userlang || $has_valid_language == 0 && strpos($langFile, $similarLang) === 0) {
                $selection .= ' selected="selected"';
                $has_valid_language = 1;
            } else {
                if ($userlang == $langFile) {
                    $selection .= ' selected="selected"';
                }
            }
            $selection .= '>' . $langName . '</option>' . LB;
        }
        $selection .= '</select>';
        $preferences->set_var('language_selector', $selection);
        $preferences->parse('language_selection', 'language', true);
    } else {
        $preferences->set_var('language_selection', '');
    }
    if ($_CONF['allow_user_themes'] == 1) {
        $selection = '<select id="theme" name="theme">' . LB;
        if (empty($_USER['theme'])) {
            $usertheme = $_CONF['theme'];
        } else {
            $usertheme = $_USER['theme'];
        }
        $themeFiles = COM_getThemes();
        usort($themeFiles, 'strcasecmp');
        foreach ($themeFiles as $theme) {
            $selection .= '<option value="' . $theme . '"';
            if ($usertheme == $theme) {
                $selection .= ' selected="selected"';
            }
            $words = explode('_', $theme);
            $bwords = array();
            foreach ($words as $th) {
                if (strtolower($th[0]) == $th[0] && strtolower($th[1]) == $th[1]) {
                    $bwords[] = ucfirst($th);
                } else {
                    $bwords[] = $th;
                }
            }
            $selection .= '>' . implode(' ', $bwords) . '</option>' . LB;
        }
        $selection .= '</select>';
        $preferences->set_var('theme_selector', $selection);
        $preferences->parse('theme_selection', 'theme', true);
    } else {
        $preferences->set_var('theme_selection', '');
    }
    // Timezone
    require_once $_CONF['path_system'] . 'classes/timezoneconfig.class.php';
    $timezone = TimeZoneConfig::getUserTimeZone();
    $selection = TimeZoneConfig::getTimeZoneDropDown($timezone, array('id' => 'tzid', 'name' => 'tzid'));
    $preferences->set_var('timezone_selector', $selection);
    $preferences->set_var('lang_timezone', $LANG04[158]);
    if ($A['noicons'] == '1') {
        $preferences->set_var('noicons_checked', 'checked="checked"');
    } else {
        $preferences->set_var('noicons_checked', '');
    }
    if ($A['noboxes'] == 1) {
        $preferences->set_var('noboxes_checked', 'checked="checked"');
    } else {
        $preferences->set_var('noboxes_checked', '');
    }
    $preferences->set_var('maxstories_value', $A['maxstories']);
    $selection = '<select id="dfid" name="dfid">' . LB . COM_optionList($_TABLES['dateformats'], 'dfid,description', $A['dfid']) . '</select>';
    $preferences->set_var('dateformat_selector', $selection);
    $preferences->parse('display_block', 'display', true);
    // privacy options block
    if ($A['emailfromadmin'] == 1) {
        $preferences->set_var('emailfromadmin_checked', 'checked="checked"');
    } else {
        $preferences->set_var('emailfromadmin_checked', '');
    }
    if ($A['emailfromuser'] == 1) {
        $preferences->set_var('emailfromuser_checked', 'checked="checked"');
    } else {
        $preferences->set_var('emailfromuser_checked', '');
    }
    if ($A['showonline'] == 1) {
        $preferences->set_var('showonline_checked', 'checked="checked"');
    } else {
        $preferences->set_var('showonline_checked', '');
    }
    PLG_profileVariablesEdit($_USER['uid'], $preferences);
    $preferences->parse('privacy_block', 'privacy', true);
    // excluded items block
    $permissions = COM_getPermSQL('');
    $preferences->set_var('exclude_topic_checklist', COM_checkList($_TABLES['topics'], 'tid,topic', $permissions, $A['tids'], 'topics'));
    if ($_CONF['contributedbyline'] == 1 && $_CONF['hide_author_exclusion'] == 0) {
        $preferences->set_var('lang_authors', $LANG04[56]);
        $sql = "SELECT DISTINCT story.uid, users.username,users.fullname FROM {$_TABLES['stories']} story, {$_TABLES['users']} users WHERE story.uid = users.uid";
        if ($_CONF['show_fullname'] == 1) {
            $sql .= ' ORDER BY users.fullname';
        } else {
            $sql .= ' ORDER BY users.username';
        }
        $query = DB_query($sql);
        $nrows = DB_numRows($query);
        $authors = explode(' ', $A['aids']);
        $selauthors = '';
        for ($i = 0; $i < $nrows; $i++) {
            $B = DB_fetchArray($query);
            $selauthors .= '<option value="' . $B['uid'] . '"';
            if (in_array(sprintf('%d', $B['uid']), $authors)) {
                $selauthors .= ' selected';
            }
            $selauthors .= '>' . COM_getDisplayName($B['uid'], $B['username'], $B['fullname']) . '</option>' . LB;
        }
        if (DB_count($_TABLES['topics']) > 10) {
            $Selboxsize = intval(DB_count($_TABLES['topics']) * 1.5);
        } else {
            $Selboxsize = 15;
        }
        $preferences->set_var('exclude_author_checklist', '<select name="selauthors[]" multiple="multiple" size="' . $Selboxsize . '">' . $selauthors . '</select>');
    } else {
        $preferences->set_var('lang_authors', '');
        $preferences->set_var('exclude_author_checklist', '');
    }
    $preferences->parse('exclude_block', 'exclude', true);
    // daily digest block
    if ($_CONF['emailstories'] == 1) {
        $user_etids = DB_getItem($_TABLES['userindex'], 'etids', "uid = {$_USER['uid']}");
        if (empty($user_etids)) {
            // an empty string now means "all topics"
            $etids = USER_getAllowedTopics();
            $user_etids = implode(' ', $etids);
        } elseif ($user_etids == '-') {
            // this means "no topics"
            $user_etids = '';
        }
        $tmp = COM_checkList($_TABLES['topics'], 'tid,topic', $permissions, $user_etids, 'topics');
        $preferences->set_var('email_topic_checklist', str_replace($_TABLES['topics'], 'etids', $tmp));
        $preferences->parse('digest_block', 'digest', true);
    } else {
        $preferences->set_var('digest_block', '');
    }
    // boxes block
    $selectedblocks = '';
    if (strlen($A['boxes']) > 0) {
        $blockresult = DB_query("SELECT bid FROM {$_TABLES['blocks']} WHERE bid NOT IN (" . str_replace(' ', ',', $A['boxes']) . ")");
        for ($x = 1; $x <= DB_numRows($blockresult); $x++) {
            $row = DB_fetchArray($blockresult);
            $selectedblocks .= $row['bid'];
            if ($x != DB_numRows($blockresult)) {
                $selectedblocks .= ' ';
            }
        }
    }
    $whereblock = '';
    if (!empty($permissions)) {
        $whereblock .= $permissions . ' AND ';
    }
    $whereblock .= "((type != 'layout' AND type != 'gldefault' AND is_enabled = 1) OR " . "(type = 'gldefault' AND is_enabled = 1 AND name IN ('whats_new_block','older_stories'))) " . "ORDER BY onleft desc,blockorder,title";
    $preferences->set_var('boxes_checklist', COM_checkList($_TABLES['blocks'], 'bid,title,type', $whereblock, $selectedblocks));
    $preferences->parse('boxes_block', 'boxes', true);
    // comment preferences block
    $result = DB_query("SELECT commentmode,commentorder,commentlimit FROM {$_TABLES['usercomment']} WHERE uid = {$_USER['uid']}");
    $A = DB_fetchArray($result);
    if (empty($A['commentmode'])) {
        $A['commentmode'] = $_CONF['comment_mode'];
    }
    if (empty($A['commentorder'])) {
        $A['commentorder'] = 0;
    }
    if (empty($A['commentlimit'])) {
        $A['commentlimit'] = 100;
    }
    $selection = '<select id="commentmode" name="commentmode">';
    $selection .= COM_optionList($_TABLES['commentmodes'], 'mode,name', $A['commentmode']);
    $selection .= '</select>';
    $preferences->set_var('displaymode_selector', $selection);
    $selection = '<select id="commentorder" name="commentorder">';
    $selection .= COM_optionList($_TABLES['sortcodes'], 'code,name', $A['commentorder']);
    $selection .= '</select>';
    $preferences->set_var('sortorder_selector', $selection);
    $preferences->set_var('commentlimit_value', $A['commentlimit']);
    $preferences->parse('comment_block', 'comment', true);
    return $preferences->finish($preferences->parse('output', 'prefs'));
}
Example #3
0
/**
* This is the custom library.
*
* It is the sandbox for every Geeklog Admin to play in.
* The lib-custom.php as shipped will never contain required code,
* so it's safe to always use your own copy.
* This should hold all custom hacks to make upgrading easier.
*
*/
require_once $_CONF['path_system'] . 'lib-custom.php';
/**
* Session management library
*
*/
require_once $_CONF['path_system'] . 'lib-sessions.php';
TimeZoneConfig::setUserTimeZone();
if (COM_isAnonUser()) {
    $_USER['advanced_editor'] = $_CONF['advanced_editor'];
}
/**
* Ulf Harnhammar's kses class
*
*/
require_once $_CONF['path_system'] . 'classes/kses.class.php';
/**
* Multibyte functions
*
*/
require_once $_CONF['path_system'] . 'lib-mbyte.php';
// Set theme
$usetheme = '';
 /**
  * Provide a dropdown menu of the available timezones
  *
  * @param    string  $selected   (optional) currently selected timezone
  * @param    array   $attributes (optional) extra attributes for select tag
  * @return   string              HTML for the dropdown
  * @static
  *
  */
 public static function getTimeZoneDropDown($selected = '', $attributes = array())
 {
     $timezones = TimeZoneConfig::listAvailableTimeZones();
     $selection = '<select';
     foreach ($attributes as $name => $value) {
         $selection .= sprintf(' %s="%s"', $name, $value);
     }
     $selection .= '>' . LB;
     foreach ($timezones as $tzid => $tzdisplay) {
         $selection .= '<option value="' . $tzid . '"';
         if (!empty($selected) && $selected == $tzid) {
             $selection .= ' selected="selected"';
         }
         $selection .= ">{$tzdisplay}</option>" . LB;
     }
     $selection .= '</select>';
     return $selection;
 }
Example #5
0
/**
 * Custom validation rule for timezone
 *
 * @param string $rule String of rule name
 * @param array $ruleParams Parameter of validation
 * @return boolean Success
 *
 */
function custom_validation_timezone($rule, $ruleParams)
{
    global $_CONF;
    require_once $_CONF['path_system'] . 'classes/timezoneconfig.class.php';
    $timezones = array_flip(TimeZoneConfig::listAvailableTimeZones());
    $ret = false;
    if (isset($ruleParams[0]['timezone']) && in_array($ruleParams[0]['timezone'], $timezones)) {
        $ret = true;
    }
    return $ret;
}
Example #6
0
/**
* Helper function: Provide timezone dropdown
*
* @return   array   Array of (timezone-long-name, timezone-short-name) pairs
*
*/
function configmanager_select_timezone_helper()
{
    global $_CONF;
    require_once $_CONF['path_system'] . 'classes/timezoneconfig.class.php';
    return array_flip(TimeZoneConfig::listAvailableTimeZones());
}