Example #1
0
function general_account_prefs_form_elements($prefs)
{
    global $USER;
    require_once 'license.php';
    $elements = array();
    $elements['friendscontrol'] = array('type' => 'radio', 'defaultvalue' => $prefs->friendscontrol, 'title' => get_string('friendsdescr', 'account'), 'class' => 'mrs mls', 'options' => array('nobody' => get_string('friendsnobody', 'account'), 'auth' => get_string('friendsauth', 'account'), 'auto' => get_string('friendsauto', 'account')), 'help' => true);
    $elements['wysiwyg'] = array('type' => 'switchbox', 'defaultvalue' => get_config('wysiwyg') ? get_config('wysiwyg') == 'enable' : $prefs->wysiwyg, 'title' => get_string('wysiwygdescr', 'account'), 'help' => true, 'disabled' => get_config('wysiwyg'));
    if (get_config('licensemetadata')) {
        $elements['licensedefault'] = license_form_el_basic(null);
        $elements['licensedefault']['title'] = get_string('licensedefault', 'account');
        if ($USER->get('institutions')) {
            $elements['licensedefault']['options'][LICENSE_INSTITUTION_DEFAULT] = get_string('licensedefaultinherit', 'account');
        }
        $elements['licensedefault']['description'] = get_string('licensedefaultdescription', 'account');
        if (isset($prefs->licensedefault)) {
            $elements['licensedefault']['defaultvalue'] = $prefs->licensedefault;
        }
    }
    $elements['maildisabled'] = array('type' => 'switchbox', 'defaultvalue' => $prefs->maildisabled, 'title' => get_string('disableemail', 'account'), 'help' => true);
    $elements['messages'] = array('type' => 'radio', 'defaultvalue' => $prefs->messages, 'title' => get_string('messagesdescr', 'account'), 'options' => array('nobody' => get_string('messagesnobody', 'account'), 'friends' => get_string('messagesfriends', 'account'), 'allow' => get_string('messagesallow', 'account')), 'help' => true);
    $languages = get_languages();
    // Determine default language.
    $instlang = get_user_institution_language($USER->id, $instlanginstname);
    if (!empty($instlang) && $instlang != 'default') {
        $sitedefaultlabel = get_string('defaultlangforinstitution', 'admin', get_config_institution($instlanginstname, 'displayname')) . ' (' . $languages[$instlang] . ')';
    } else {
        $sitedefaultlabel = get_string('sitedefault', 'admin') . ' (' . $languages[get_config('lang')] . ')';
    }
    $elements['lang'] = array('type' => 'select', 'defaultvalue' => $prefs->lang, 'title' => get_string('language', 'account'), 'options' => array_merge(array('default' => $sitedefaultlabel), $languages), 'help' => true, 'ignore' => count($languages) < 2);
    $sitethemes = array();
    // Get all available standard site themes
    if (get_config('sitethemeprefs') && !in_admin_section()) {
        // get_user_accessible_themes() returns 'sitedefault' to mean fall back to the site or
        // institution theme.  This won't work for account prefs, where 'sitedefault' is just
        // a theme that doesn't exist.  So change the 'sitedefault' key to '', and the empty
        // preference will be interpreted as "No theme selected".
        $sitethemes = array_reverse(get_user_accessible_themes());
        unset($sitethemes['sitedefault']);
        $sitethemes = array_reverse($sitethemes);
    }
    // Get all user's institution themes
    $institutionthemes = array();
    if ($institutions = $USER->get('institutions')) {
        $allthemes = get_all_theme_objects();
        foreach ($institutions as $i) {
            if (empty($i->theme)) {
                $institutionthemes['sitedefault' . '/' . $i->institution] = $i->displayname . ' - ' . get_string('sitedefault', 'admin');
            } else {
                $institutionthemes[$i->theme . '/' . $i->institution] = $i->displayname . ' - ' . $allthemes[$i->theme]->displayname;
            }
        }
    }
    $themes = array_merge($sitethemes, $institutionthemes);
    natcasesort($themes);
    $currenttheme = $USER->get_themedata();
    if (!isset($currenttheme->basename)) {
        $defaulttheme = 'sitedefault';
    } else {
        $defaulttheme = $currenttheme->basename;
    }
    if (isset($currenttheme->institutionname)) {
        $defaulttheme = $defaulttheme . '/' . $currenttheme->institutionname;
    }
    if (!array_key_exists($defaulttheme, $themes)) {
        reset($themes);
        $defaulttheme = key($themes);
    }
    $elements['theme'] = array('type' => 'select', 'defaultvalue' => $defaulttheme, 'title' => get_string('theme'), 'options' => $themes, 'ignore' => count($themes) < 2, 'help' => true);
    $elements['addremovecolumns'] = array('type' => 'switchbox', 'defaultvalue' => $prefs->addremovecolumns, 'title' => get_string('showviewcolumns', 'account'), 'help' => 'true');
    // TODO: add a way for plugins (like blog!) to have account preferences
    $elements['multipleblogs'] = array('type' => 'switchbox', 'title' => get_string('enablemultipleblogs1', 'account'), 'description' => get_string('enablemultipleblogsdescription1', 'account'), 'defaultvalue' => $prefs->multipleblogs);
    if (get_config('showtagssideblock')) {
        $elements['tagssideblockmaxtags'] = array('type' => 'text', 'size' => 4, 'title' => get_string('tagssideblockmaxtags', 'account'), 'description' => get_string('tagssideblockmaxtagsdescription', 'account'), 'defaultvalue' => isset($prefs->tagssideblockmaxtags) ? $prefs->tagssideblockmaxtags : get_config('tagssideblockmaxtags'), 'rules' => array('integer' => true, 'minvalue' => 0, 'maxvalue' => 1000));
    }
    $elements['groupsideblockmaxgroups'] = array('type' => 'text', 'size' => 4, 'title' => get_string('limitto1', 'blocktype.mygroups'), 'description' => get_string('limittodescsideblock1', 'blocktype.mygroups'), 'defaultvalue' => isset($prefs->groupsideblockmaxgroups) ? $prefs->groupsideblockmaxgroups : '', 'rules' => array('regex' => '/^[0-9]*$/', 'minvalue' => 0, 'maxvalue' => 1000));
    $elements['groupsideblocksortby'] = array('type' => 'select', 'defaultvalue' => isset($prefs->groupsideblocksortby) ? $prefs->groupsideblocksortby : 'alphabetical', 'title' => get_string('sortgroups', 'blocktype.mygroups'), 'options' => array('latest' => get_string('latest', 'blocktype.mygroups'), 'earliest' => get_string('earliest', 'blocktype.mygroups'), 'alphabetical' => get_string('alphabetical', 'blocktype.mygroups')));
    if (get_config('userscanhiderealnames')) {
        $elements['hiderealname'] = array('type' => 'switchbox', 'title' => get_string('hiderealname', 'account'), 'description' => get_string('hiderealnamedescription', 'account'), 'defaultvalue' => $prefs->hiderealname);
    }
    if (get_config('homepageinfo')) {
        $elements['showhomeinfo'] = array('type' => 'switchbox', 'defaultvalue' => $prefs->showhomeinfo, 'title' => get_string('showhomeinfo2', 'account'), 'description' => get_string('showhomeinfodescription1', 'account', hsc(get_config('sitename'))), 'help' => 'true');
    }
    if (get_config('showprogressbar')) {
        $elements['showprogressbar'] = array('type' => 'switchbox', 'defaultvalue' => $prefs->showprogressbar, 'title' => get_string('showprogressbar', 'account'), 'description' => get_string('showprogressbardescription', 'account', hsc(get_config('sitename'))));
    }
    if (get_config('allowmobileuploads')) {
        $defaultvalue = array();
        $mobileuploadtoken = isset($prefs->mobileuploadtoken) ? $prefs->mobileuploadtoken : get_config('mobileuploadtoken');
        $defaultvalue = explode('|', trim($mobileuploadtoken, '|'));
        $elements['mobileuploadtoken'] = array('type' => 'multitext', 'title' => get_string('mobileuploadtoken', 'account'), 'defaultvalue' => $defaultvalue, 'help' => 'true');
    }
    if (get_config_plugin('artefact', 'file', 'resizeonuploadenable')) {
        $elements['resizeonuploaduserdefault'] = array('type' => 'switchbox', 'title' => get_string('resizeonuploaduserdefault1', 'account'), 'description' => get_string('resizeonuploaduserdefaultdescription2', 'account'), 'defaultvalue' => $prefs->resizeonuploaduserdefault);
    }
    if (get_config('userscandisabledevicedetection')) {
        $elements['devicedetection'] = array('type' => 'switchbox', 'title' => get_string('devicedetection', 'account'), 'description' => get_string('devicedetectiondescription', 'account'), 'defaultvalue' => $prefs->devicedetection);
    }
    return $elements;
}
Example #2
0
/**
 * Return a list of themes available to the specified institution
 * @param string institution the name of the institution to load themes for
 * @return array subdir => name
 * @throws SystemException if unable to read the theme directory
 */
function get_institution_themes($institution)
{
    static $institutionthemes = array();
    if (!isset($institutionthemes[$institution])) {
        $themes = get_all_theme_objects();
        $r = array();
        foreach ($themes as $subdir => $theme) {
            if (empty($theme->institutions) || !is_array($theme->institutions) || in_array($institution, $theme->institutions)) {
                $r[$subdir] = isset($theme->displayname) ? $theme->displayname : $subdir;
            }
        }
        $institutionthemes[$institution] = $r;
    }
    return $institutionthemes[$institution];
}
Example #3
0
function file_cleanup_old_cached_files()
{
    global $THEME;
    $dirs = array('', '/profileicons');
    foreach (get_all_theme_objects() as $basename => $theme) {
        $dirs[] = '/profileicons/no_userphoto/' . $basename;
    }
    foreach ($dirs as $dir) {
        $basedir = get_config('dataroot') . 'artefact/file' . $dir . '/resized/';
        if (!check_dir_exists($basedir, false)) {
            continue;
        }
        $mintime = time() - 12 * 7 * 24 * 60 * 60;
        // delete caches older than 12 weeks
        // Cached files are stored in a three tier md5sum layout
        // The actual files are stored in the third directory
        // This loops through all three directories, then checks the files for age
        // It cleans up any empty directories on the way down again
        $iter1 = new DirectoryIterator($basedir);
        foreach ($iter1 as $dir1) {
            if ($dir1->isDot()) {
                continue;
            }
            $dir1path = $dir1->getPath() . '/' . $dir1->getFilename();
            $iter2 = new DirectoryIterator($dir1path);
            foreach ($iter2 as $dir2) {
                if ($dir2->isDot()) {
                    continue;
                }
                $dir2path = $dir2->getPath() . '/' . $dir2->getFilename();
                $iter3 = new DirectoryIterator($dir2path);
                foreach ($iter3 as $dir3) {
                    if ($dir3->isDot()) {
                        continue;
                    }
                    $dir3path = $dir3->getPath() . '/' . $dir3->getFilename();
                    $fileiter = new DirectoryIterator($dir3path);
                    foreach ($fileiter as $file) {
                        if ($file->isFile() && $file->getCTime() < $mintime) {
                            unlink($file->getPath() . '/' . $file->getFilename());
                        }
                    }
                    if (sizeof(scandir($dir3path)) <= 2) {
                        // first 2 entries are . and ..
                        rmdir($dir3path);
                    }
                }
                if (sizeof(scandir($dir2path)) <= 2) {
                    // first 2 entries are . and ..
                    rmdir($dir2path);
                }
            }
            if (sizeof(scandir($dir1path)) <= 2) {
                // first 2 entries are . and ..
                rmdir($dir1path);
            }
        }
    }
}