Пример #1
0
 protected static function get_data($groupid)
 {
     global $USER;
     if (!defined('GROUP')) {
         define('GROUP', $groupid);
     }
     // get the currently requested group
     $group = group_current_group();
     $group->ctime = strftime(get_string('strftimedate'), $group->ctime);
     // if the user isn't logged in an the group isn't public don't show anything
     if (!is_logged_in() && !$group->public) {
         throw new AccessDeniedException();
     }
     // find the group administrators
     $group->admins = get_column_sql("SELECT \"member\"\n            FROM {group_member}\n            WHERE \"group\" = ?\n            AND \"role\" = 'admin'", array($group->id));
     $role = group_user_access($group->id);
     $group->role = $role;
     // logged in user can do stuff
     if (is_logged_in()) {
         $afterjoin = param_variable('next', 'view');
         if ($role) {
             if ($role == 'admin') {
                 $group->membershiptype = 'admin';
                 $group->requests = count_records('group_member_request', 'group', $group->id);
             } else {
                 $group->membershiptype = 'member';
             }
             $group->canleave = group_user_can_leave($group->id);
         } else {
             if ($group->jointype == 'invite' and $invite = get_record('group_member_invite', 'group', $group->id, 'member', $USER->get('id'))) {
                 $group->membershiptype = 'invite';
                 $group->invite = group_get_accept_form('invite', $group->id, $afterjoin);
             } else {
                 if ($group->jointype == 'request' and $request = get_record('group_member_request', 'group', $group->id, 'member', $USER->get('id'))) {
                     $group->membershiptype = 'request';
                 } else {
                     if ($group->jointype == 'open') {
                         $group->groupjoin = group_get_join_form('joingroup', $group->id, $afterjoin);
                     }
                 }
             }
         }
     }
     $group->settingsdescription = group_display_settings($group);
     if (get_config('allowgroupcategories')) {
         $group->categorytitle = $group->category ? get_field('group_category', 'title', 'id', $group->category) : '';
     }
     $filecounts = ArtefactTypeFileBase::count_user_files(null, $group->id, null);
     return array('group' => $group, 'filecounts' => $filecounts);
 }
Пример #2
0
 protected static function get_data($groupid)
 {
     global $USER;
     if (!defined('GROUP')) {
         define('GROUP', $groupid);
     }
     // get the currently requested group
     $group = group_current_group();
     $group->ctime = format_date($group->ctime, 'strftimedate');
     // if the user isn't logged in an the group isn't public don't show anything
     if (!is_logged_in() && !$group->public) {
         throw new AccessDeniedException();
     }
     return group_get_groupinfo_data($group);
 }
/**
 *
 * @package    mahara
 * @subpackage dwoo
 * @author     Catalyst IT Ltd
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL version 3 or later
 * @copyright  For copyright information on Mahara, please see the README file distributed with this software.
 *
 */
function Dwoo_Plugin_loadgroupquota(Dwoo $dwoo)
{
    $group = group_current_group();
    $quota = $group->quota;
    $quotaused = $group->quotaused;
    if ($quota >= 1048576) {
        $quota_message = get_string('quotausagegroup', 'mahara', sprintf('%0.1fMB', $group->quotaused / 1048576), sprintf('%0.1fMB', $quota / 1048567));
    } else {
        if ($quota >= 1024) {
            $quota_message = get_string('quotausagegroup', 'mahara', sprintf('%0.1fKB', $group->quotaused / 1024), sprintf('%0.1fKB', $quota / 1024));
        } else {
            $quota_message = get_string('quotausagegroup', 'mahara', sprintf('%d bytes', $group->quotaused), sprintf('%d bytes', $quota));
        }
    }
    $dwoo->assignInScope($quota_message, 'GROUPQUOTA_MESSAGE');
    if ($quota == 0) {
        $dwoo->assignInScope(100, 'GROUPQUOTA_PERCENTAGE');
    } else {
        $dwoo->assignInScope(round($quotaused / $quota * 100), 'GROUPQUOTA_PERCENTAGE');
    }
}
Пример #4
0
 public static function render_instance(BlockInstance $instance, $editing = false)
 {
     global $USER;
     if ($instance->get_view()->get('owner') == "0") {
         return '';
     }
     $configdata = $instance->get('configdata');
     $rows = isset($configdata['rows']) ? $configdata['rows'] : 1;
     $columns = isset($configdata['columns']) ? $configdata['columns'] : 6;
     $order = isset($configdata['order']) ? $configdata['order'] : 'latest';
     $numtoshow = isset($configdata['numtoshow']) ? $configdata['numtoshow'] : $rows * $columns;
     $groupid = $instance->get_view()->get('group');
     // If the group has hidden membership, display nothing
     $usergroups = $USER->get('grouproles');
     $group = defined('GROUP') && $groupid == GROUP ? group_current_group() : get_record('group', 'id', $groupid);
     if ($group->hidemembersfrommembers && (!isset($usergroups[$groupid]) || $usergroups[$groupid] != 'admin')) {
         return '';
     }
     if ($group->hidemembers && !isset($usergroups[$groupid])) {
         return '';
     }
     require_once 'searchlib.php';
     $groupmembers = get_group_user_search_results($groupid, '', 0, $numtoshow, '', $order);
     if ($groupmembers['count']) {
         $smarty = smarty_core();
         $smarty->assign_by_ref('groupmembers', $groupmembers['data']);
         $groupmembers['tablerows'] = $smarty->fetch('blocktype:groupmembers:row.tpl');
     } else {
         $groupmembers = false;
     }
     $show_all = array('url' => get_config('wwwroot') . 'group/members.php?id=' . $groupid, 'message' => get_string('show_all', 'blocktype.groupmembers'));
     $smarty = smarty_core();
     $smarty->assign('groupmembers', $groupmembers);
     $smarty->assign('show_all', $show_all);
     return $smarty->fetch('blocktype:groupmembers:groupmembers.tpl');
 }
Пример #5
0
/**
 * This function creates a Smarty object and sets it up for use within our
 * podclass app, setting up some variables.
 *
 * The variables that it sets up are:
 *
 * - WWWROOT: The base url for the Mahara system
 * - USER: The user object
 * - JAVASCRIPT: A list of javascript files to include in the header.  This
 *   list is passed into this function (see below).
 * - HEADERS: An array of any further headers to set.  Each header is just
 *   straight HTML (see below).
 * - PUBLIC: Set true if this page is a public page
 * - MAINNAV: Array defining the main navigation
 *
 * @param $javascript A list of javascript includes.  Each include should be just
 *                    the name of a file, and reside in js/{filename}
 * @param $headers    A list of additional headers.  These are to be specified as
 *                    actual HTML.
 * @param $strings    A list of language strings required by the javascript code.
 * @return Smarty
 */
function smarty($javascript = array(), $headers = array(), $pagestrings = array(), $extraconfig = array())
{
    global $USER, $SESSION, $THEME;
    if (!is_array($headers)) {
        $headers = array();
    }
    if (!is_array($pagestrings)) {
        $pagestrings = array();
    }
    if (!is_array($extraconfig)) {
        $extraconfig = array();
    }
    $SIDEBLOCKS = array();
    $smarty = smarty_core();
    $wwwroot = get_config('wwwroot');
    // NOTE: not using jswwwroot - it seems to wreck image paths if you
    // drag them around the wysiwyg editor
    $jswwwroot = json_encode($wwwroot);
    $theme_list = array();
    if (function_exists('pieform_get_headdata')) {
        $headers = array_merge($headers, pieform_get_headdata());
    }
    // Insert the appropriate javascript tags
    $javascript_array = array();
    $jsroot = $wwwroot . 'js/';
    $langdirection = get_string('thisdirection', 'langconfig');
    // TinyMCE must be included first for some reason we're not sure about
    $checkarray = array(&$javascript, &$headers);
    $found_tinymce = false;
    foreach ($checkarray as &$check) {
        if (($key = array_search('tinymce', $check)) !== false || ($key = array_search('tinytinymce', $check)) !== false) {
            if (!$found_tinymce) {
                $found_tinymce = $check[$key];
                $javascript_array[] = $jsroot . 'tinymce/tiny_mce.js';
                $content_css = json_encode($THEME->get_url('style/tinymce.css'));
                $language = substr(current_language(), 0, 2);
                $extrasetup = isset($extraconfig['tinymcesetup']) ? $extraconfig['tinymcesetup'] : '';
                $adv_buttons = array("bold,italic,underline,separator,justifyleft,justifycenter,justifyright,justifyfull,separator,bullist,numlist,separator,link,unlink,separator,code,fullscreen", "bold,italic,underline,strikethrough,separator,forecolor,backcolor,separator,justifyleft,justifycenter,justifyright,justifyfull,separator,hr,emotions,image,iespell,cleanup,separator,link,unlink,separator,code", "bullist,numlist,separator,tablecontrols,separator,cut,copy,paste,pasteword", "fontselect,separator,fontsizeselect,separator,formatselect");
                // For right-to-left langs, reverse button order & align controls right.
                $tinymce_langdir = $langdirection == 'rtl' ? 'rtl' : 'ltr';
                $toolbar_align = 'left';
                if ($check[$key] == 'tinymce') {
                    $tinymce_config = <<<EOF
    mode: "none",
    theme: "advanced",
    plugins: "table,emotions,iespell,inlinepopups,paste",
    theme_advanced_buttons1 : "{$adv_buttons[1]}",
    theme_advanced_buttons2 : "{$adv_buttons[2]}",
    theme_advanced_buttons3 : "{$adv_buttons[3]}",
    theme_advanced_toolbar_location : "top",
    theme_advanced_toolbar_align : "{$toolbar_align}",
    //width: '512',
EOF;
                } else {
                    $tinymce_config = <<<EOF
    mode: "textareas",
    editor_selector: 'tinywysiwyg',
    theme: "advanced",
    plugins: "fullscreen,inlinepopups",
    theme_advanced_buttons1 : "{$adv_buttons[0]}",
    theme_advanced_buttons2 : "",
    theme_advanced_buttons3 : "",
    theme_advanced_toolbar_location : "top",
    theme_advanced_toolbar_align : "{$toolbar_align}",
    fullscreen_new_window: true,
    fullscreen_settings: {
        theme: "advanced",
        plugins: "table,emotions,iespell,inlinepopups,paste",
        theme_advanced_buttons1 : "{$adv_buttons[1]}",
        theme_advanced_buttons2 : "{$adv_buttons[2]}",
        theme_advanced_buttons3 : "{$adv_buttons[3]}"
    },
EOF;
                }
                $headers[] = <<<EOF
<script type="text/javascript">
tinyMCE.init({
    button_tile_map: true,
    {$tinymce_config}
    extended_valid_elements : "object[width|height|classid|codebase],param[name|value],embed[src|type|width|height|flashvars|wmode],script[src,type,language],+ul[id|type|compact]",
    urlconverter_callback : "custom_urlconvert",
    language: '{$language}',
    directionality: "{$tinymce_langdir}",
    content_css : {$content_css},
    //document_base_url: {$jswwwroot},
    remove_script_host: false,
    relative_urls: false,
    setup: function(ed) {
        ed.onInit.add(function(ed) {
            if (typeof(editor_to_focus) == 'string' && ed.editorId == editor_to_focus) {
                ed.focus();
            }
        });
        {$extrasetup}
    }
});
function custom_urlconvert (u, n, e) {
  // Don't convert the url on the skype status buttons.
  if (u.indexOf('skype:') == 0) {
      return u;
  }
  var t = tinyMCE.activeEditor, s = t.settings;

  // Don't convert link href since thats the CSS files that gets loaded into the editor also skip local file URLs
  if (!s.convert_urls || (e && e.nodeName == 'LINK') || u.indexOf('file:') === 0)
      return u;

  // Convert to relative
  if (s.relative_urls)
      return t.documentBaseURI.toRelative(u);

  // Convert to absolute
  u = t.documentBaseURI.toAbsolute(u, s.remove_script_host);

  return u;
}
</script>

EOF;
                unset($check[$key]);
            } else {
                if ($check[$key] != $found_tinymce) {
                    log_warn('Two differently configured tinyMCE instances have been asked for on this page! This is not possible');
                }
                unset($check[$key]);
            }
        }
    }
    if (get_config('developermode') & DEVMODE_UNPACKEDJS) {
        $javascript_array[] = $jsroot . 'MochiKit/MochiKit.js';
        $javascript_array[] = $jsroot . 'MochiKit/Position.js';
        $javascript_array[] = $jsroot . 'MochiKit/Color.js';
        $javascript_array[] = $jsroot . 'MochiKit/Visual.js';
        $javascript_array[] = $jsroot . 'MochiKit/DragAndDrop.js';
        $javascript_array[] = $jsroot . 'MochiKit/Format.js';
    } else {
        $javascript_array[] = $jsroot . 'MochiKit/Packed.js';
    }
    $javascript_array[] = $jsroot . 'keyboardNavigation.js';
    $strings = array();
    foreach ($pagestrings as $k => $v) {
        if (is_array($v)) {
            foreach ($v as $tag) {
                $strings[$tag] = get_raw_string($tag, $k);
            }
        } else {
            $strings[$k] = get_raw_string($k, $v);
        }
    }
    $jsstrings = jsstrings();
    $themepaths = themepaths();
    foreach ($javascript as $jsfile) {
        // For now, if there's no path in the js file, assume it's in
        // $jsroot and append '.js' to the name.  Later we may want to
        // ensure all smarty() calls include the full path to the js
        // file, with the proper extension.
        if (strpos($jsfile, '/') === false) {
            $javascript_array[] = $jsroot . $jsfile . '.js';
            if (isset($jsstrings[$jsfile])) {
                foreach ($jsstrings[$jsfile] as $section => $tags) {
                    foreach ($tags as $tag) {
                        $strings[$tag] = get_raw_string($tag, $section);
                    }
                }
            }
            if (isset($themepaths[$jsfile])) {
                foreach ($themepaths[$jsfile] as $themepath) {
                    $theme_list[$themepath] = $THEME->get_url($themepath);
                }
            }
        } else {
            // A .js file with a fully specified path
            $javascript_array[] = $wwwroot . $jsfile;
            // If $jsfile is from a plugin (i.e. plugintype/pluginname/js/foo.js)
            // Then get js strings from static function jsstrings in plugintype/pluginname/lib.php
            $bits = explode('/', $jsfile);
            if (count($bits) == 4) {
                safe_require($bits[0], $bits[1]);
                $pluginclass = generate_class_name($bits[0], $bits[1]);
                $name = substr($bits[3], 0, strpos($bits[3], '.js'));
                if (is_callable(array($pluginclass, 'jsstrings'))) {
                    $tempstrings = call_static_method($pluginclass, 'jsstrings', $name);
                    foreach ($tempstrings as $section => $tags) {
                        foreach ($tags as $tag) {
                            $strings[$tag] = get_raw_string($tag, $section);
                        }
                    }
                }
                if (is_callable(array($pluginclass, 'jshelp'))) {
                    $tempstrings = call_static_method($pluginclass, 'jshelp', $name);
                    foreach ($tempstrings as $section => $tags) {
                        foreach ($tags as $tag) {
                            $strings[$tag . '.help'] = get_help_icon($bits[0], $bits[1], null, null, null, $tag);
                        }
                    }
                }
                if (is_callable(array($pluginclass, 'themepaths'))) {
                    $tmpthemepaths = call_static_method($pluginclass, 'themepaths', $name);
                    foreach ($tmpthemepaths as $themepath) {
                        $theme_list[$themepath] = $THEME->get_url($themepath);
                    }
                }
            }
        }
    }
    $javascript_array[] = $jsroot . 'mahara.js';
    if (get_config('developermode') & DEVMODE_DEBUGJS) {
        $javascript_array[] = $jsroot . 'debug.js';
    }
    foreach ($jsstrings['mahara'] as $section => $tags) {
        foreach ($tags as $tag) {
            $strings[$tag] = get_raw_string($tag, $section);
        }
    }
    if (isset($extraconfig['themepaths']) && is_array($extraconfig['themepaths'])) {
        foreach ($extraconfig['themepaths'] as $themepath) {
            $theme_list[$themepath] = $THEME->get_url($themepath);
        }
    }
    $stringjs = '<script type="text/javascript">';
    $stringjs .= 'var strings = ' . json_encode($strings) . ';';
    $stringjs .= '</script>';
    // stylesheet set up - if we're in a plugin also get its stylesheet
    $stylesheets = array_reverse(array_values($THEME->get_url('style/style.css', true)));
    if (defined('SECTION_PLUGINTYPE') && defined('SECTION_PLUGINNAME') && SECTION_PLUGINTYPE != 'core') {
        if ($pluginsheets = $THEME->get_url('style/style.css', true, SECTION_PLUGINTYPE . '/' . SECTION_PLUGINNAME)) {
            $stylesheets = array_merge($stylesheets, array_reverse($pluginsheets));
        }
    }
    if (defined('ADMIN') || defined('INSTITUTIONALADMIN')) {
        if ($adminsheets = $THEME->get_url('style/admin.css', true)) {
            $stylesheets = array_merge($stylesheets, array_reverse($adminsheets));
        }
    }
    if (get_config('developermode') & DEVMODE_DEBUGCSS) {
        $stylesheets[] = get_config('wwwroot') . 'theme/debug.css';
    }
    // look for extra stylesheets
    if (isset($extraconfig['stylesheets']) && is_array($extraconfig['stylesheets'])) {
        foreach ($extraconfig['stylesheets'] as $extrasheet) {
            if ($sheets = $THEME->get_url($extrasheet, true)) {
                $stylesheets = array_merge($stylesheets, array_reverse(array_values($sheets)));
            }
        }
    }
    // Include rtl.css for right-to-left langs
    if ($langdirection == 'rtl') {
        $smarty->assign('LANGDIRECTION', 'rtl');
        if ($rtlsheets = $THEME->get_url('style/rtl.css', true)) {
            $stylesheets = array_merge($stylesheets, array_reverse($rtlsheets));
        }
    }
    $smarty->assign('STRINGJS', $stringjs);
    $smarty->assign('STYLESHEETLIST', $stylesheets);
    if (!empty($theme_list)) {
        // this gets assigned in smarty_core, but do it again here if it's changed locally
        $smarty->assign('THEMELIST', json_encode(array_merge((array) json_decode($smarty->get_template_vars('THEMELIST')), $theme_list)));
    }
    $sitename = get_config('sitename');
    if (!$sitename) {
        $sitename = 'Mahara';
    }
    $smarty->assign('sitename', $sitename);
    if (defined('TITLE')) {
        $smarty->assign('PAGETITLE', TITLE . ' - ' . $sitename);
        $smarty->assign('heading', TITLE);
    } else {
        $smarty->assign('PAGETITLE', $sitename);
    }
    if (defined('PUBLIC')) {
        $smarty->assign('PUBLIC', true);
    }
    if (defined('ADMIN')) {
        $smarty->assign('ADMIN', true);
    }
    if (defined('INSTITUTIONALADMIN')) {
        $smarty->assign('INSTITUTIONALADMIN', true);
    }
    $smarty->assign('LOGGEDIN', $USER->is_logged_in());
    if ($USER->is_logged_in()) {
        global $SELECTEDSUBNAV;
        // It's evil, but rightnav & mainnav stuff are now in different templates.
        $smarty->assign('MAINNAV', main_nav());
        $smarty->assign('RIGHTNAV', right_nav());
        $smarty->assign('SELECTEDSUBNAV', $SELECTEDSUBNAV);
    } else {
        $smarty->assign('sitedefaultlang', get_string('sitedefault', 'admin') . ' (' . get_string_from_language(get_config('lang'), 'thislanguage') . ')');
        $smarty->assign('LANGUAGES', get_languages());
    }
    $smarty->assign('FOOTERMENU', footer_menu());
    $smarty->assign_by_ref('USER', $USER);
    $smarty->assign('SESSKEY', $USER->get('sesskey'));
    $smarty->assign_by_ref('JAVASCRIPT', $javascript_array);
    $smarty->assign_by_ref('HEADERS', $headers);
    $siteclosedforupgrade = get_config('siteclosed');
    if ($siteclosedforupgrade && get_config('disablelogin')) {
        $smarty->assign('SITECLOSED', 'logindisabled');
    } else {
        if ($siteclosedforupgrade || get_config('siteclosedbyadmin')) {
            $smarty->assign('SITECLOSED', 'loginallowed');
        }
    }
    if (!isset($extraconfig['pagehelp']) || $extraconfig['pagehelp'] !== false and $help = has_page_help()) {
        $smarty->assign('PAGEHELPNAME', $help[0]);
        $smarty->assign('PAGEHELPICON', $help[1]);
    }
    if (defined('GROUP')) {
        require_once 'group.php';
        $group = group_current_group();
        $smarty->assign('GROUP', $group);
        $smarty->assign('SUBPAGENAV', group_get_menu_tabs());
        $smarty->assign('PAGEHEADING', $group->name);
    }
    // ---------- sideblock stuff ----------
    $sidebars = !isset($extraconfig['sidebars']) || $extraconfig['sidebars'] !== false;
    if ($sidebars && !defined('INSTALLER') && (!defined('MENUITEM') || substr(MENUITEM, 0, 5) != 'admin')) {
        if (get_config('installed') && !defined('ADMIN') && !defined('INSTITUTIONALADMIN')) {
            $data = site_menu();
            if (!empty($data)) {
                $smarty->assign('SITEMENU', site_menu());
                $SIDEBLOCKS[] = array('name' => 'linksandresources', 'weight' => 10, 'data' => $data);
            }
        }
        if ($USER->is_logged_in() && defined('MENUITEM') && substr(MENUITEM, 0, 11) == 'myportfolio') {
            if (get_config('showselfsearchsideblock')) {
                $SIDEBLOCKS[] = array('name' => 'selfsearch', 'weight' => 0, 'data' => array());
            }
            if (get_config('showtagssideblock')) {
                $SIDEBLOCKS[] = array('name' => 'tags', 'id' => 'sb-tags', 'weight' => 0, 'data' => tags_sideblock());
            }
        }
        if ($USER->is_logged_in() && !defined('ADMIN') && !defined('INSTITUTIONALADMIN')) {
            $SIDEBLOCKS[] = array('name' => 'profile', 'id' => 'sb-profile', 'weight' => -20, 'data' => profile_sideblock());
            if (get_config('showonlineuserssideblock')) {
                $SIDEBLOCKS[] = array('name' => 'onlineusers', 'id' => 'sb-onlineusers', 'weight' => -10, 'data' => onlineusers_sideblock());
            }
        }
        if (defined('GROUP')) {
            $SIDEBLOCKS[] = array('name' => 'group', 'id' => 'sb-groupnav', 'weight' => -10, 'data' => group_sideblock());
        }
        if (!$USER->is_logged_in() && !(get_config('siteclosed') && get_config('disablelogin'))) {
            $SIDEBLOCKS[] = array('name' => 'login', 'weight' => -10, 'id' => 'sb-loginbox', 'data' => array('loginform' => auth_generate_login_form()));
        }
        if (get_config('enablenetworking')) {
            require_once get_config('docroot') . 'api/xmlrpc/lib.php';
            if ($USER->is_logged_in() && ($ssopeers = get_service_providers($USER->authinstance))) {
                $SIDEBLOCKS[] = array('name' => 'ssopeers', 'weight' => 1, 'data' => $ssopeers);
            }
        }
        if (isset($extraconfig['sideblocks']) && is_array($extraconfig['sideblocks'])) {
            foreach ($extraconfig['sideblocks'] as $sideblock) {
                $SIDEBLOCKS[] = $sideblock;
            }
        }
        usort($SIDEBLOCKS, create_function('$a,$b', 'if ($a["weight"] == $b["weight"]) return 0; return ($a["weight"] < $b["weight"]) ? -1 : 1;'));
        // Place all sideblocks on the right. If this structure is munged
        // appropriately, you can put blocks on the left. In future versions of
        // Mahara, we'll make it easy to do this.
        $SIDEBLOCKS = array('left' => array(), 'right' => $SIDEBLOCKS);
        $smarty->assign('userauthinstance', $SESSION->get('authinstance'));
        $smarty->assign('MNETUSER', $SESSION->get('mnetuser'));
        $smarty->assign('SIDEBLOCKS', $SIDEBLOCKS);
        $smarty->assign('SIDEBARS', $sidebars);
    }
    if ($USER->get('parentuser')) {
        $smarty->assign('USERMASQUERADING', true);
        $smarty->assign('masqueradedetails', get_string('youaremasqueradingas', 'mahara', display_name($USER)));
        $smarty->assign('becomeyouagain', ' <a href="' . hsc($wwwroot) . 'admin/users/changeuser.php?restore=1">' . get_string('becomeadminagain', 'admin', hsc($USER->get('parentuser')->name)) . '</a>');
    }
    return $smarty;
}
Пример #6
0
/**
 * This function creates a Smarty object and sets it up for use within our
 * podclass app, setting up some variables.
 *
 * WARNING: If you are using pieforms, set them up BEFORE calling this function.
 *
 * The variables that it sets up are:
 *
 * - WWWROOT: The base url for the Mahara system
 * - USER: The user object
 * - JAVASCRIPT: A list of javascript files to include in the header.  This
 *   list is passed into this function (see below).
 * - HEADERS: An array of any further headers to set.  Each header is just
 *   straight HTML (see below).
 * - PUBLIC: Set true if this page is a public page
 * - MAINNAV: Array defining the main navigation
 *
 * @param $javascript A list of javascript includes.  Each include should be just
 *                    the name of a file, and reside in js/{filename}
 * @param $headers    A list of additional headers.  These are to be specified as
 *                    actual HTML.
 * @param $strings    A list of language strings required by the javascript code.
 * @return Smarty
 */
function smarty($javascript = array(), $headers = array(), $pagestrings = array(), $extraconfig = array())
{
    global $USER, $SESSION, $THEME, $HEADDATA, $langselectform;
    if (!is_array($headers)) {
        $headers = array();
    }
    if (!is_array($pagestrings)) {
        $pagestrings = array();
    }
    if (!is_array($extraconfig)) {
        $extraconfig = array();
    }
    $sideblocks = array();
    // Some things like die_info() will try and create a smarty() call when we are already in one, which causes
    // language_select_form() to throw headdata error as it is called twice.
    if (!isset($langselectform)) {
        $langselectform = language_select_form();
    }
    $smarty = smarty_core();
    $wwwroot = get_config('wwwroot');
    // NOTE: not using jswwwroot - it seems to wreck image paths if you
    // drag them around the wysiwyg editor
    $jswwwroot = json_encode($wwwroot);
    // Workaround for $cfg->cleanurlusersubdomains.
    // When cleanurlusersubdomains is on, ajax requests might come from somewhere other than
    // the wwwroot.  To avoid cross-domain requests, set a js variable when this page is on a
    // different subdomain, and let the ajax wrapper function sendjsonrequest rewrite its url
    // if necessary.
    if (get_config('cleanurls') && get_config('cleanurlusersubdomains')) {
        if ($requesthost = get_requested_host_name()) {
            $wwwrootparts = parse_url($wwwroot);
            if ($wwwrootparts['host'] != $requesthost) {
                $fakewwwroot = $wwwrootparts['scheme'] . '://' . $requesthost . '/';
                $headers[] = '<script type="application/javascript">var fakewwwroot = ' . json_encode($fakewwwroot) . ';</script>';
            }
        }
    }
    $theme_list = array();
    $adminsection = in_admin_section();
    if (function_exists('pieform_get_headdata')) {
        $headers = array_merge($headers, pieform_get_headdata());
        if (!defined('PIEFORM_GOT_HEADDATA')) {
            define('PIEFORM_GOT_HEADDATA', 1);
        }
    }
    // Define the stylesheets array early so that javascript modules can add extras
    $stylesheets = array();
    // Insert the appropriate javascript tags
    $javascript_array = array();
    $jsroot = $wwwroot . 'js/';
    $langdirection = get_string('thisdirection', 'langconfig');
    // Make jQuery accessible with $j (Mochikit has $)
    $javascript_array[] = $jsroot . 'jquery/jquery.js';
    $javascript_array[] = $jsroot . 'jquery/deprecated_jquery.js';
    $headers[] = '<script type="application/javascript">$j=jQuery;</script>';
    // If necessary, load MathJax configuration
    if (get_config('mathjax')) {
        $headers[] = '<script type="application/javascript">' . get_config('mathjaxconfig') . '</script>';
    }
    // TinyMCE must be included first for some reason we're not sure about
    //
    // Note: we do not display tinyMCE for mobile devices
    // as it doesn't work on some of them and can
    // disable the editing of a textarea field
    if ($SESSION->get('handheld_device') == false) {
        $checkarray = array(&$javascript, &$headers);
        $found_tinymce = false;
        foreach ($checkarray as &$check) {
            if (($key = array_search('tinymce', $check)) !== false || ($key = array_search('tinytinymce', $check)) !== false) {
                if (!$found_tinymce) {
                    $found_tinymce = $check[$key];
                    $javascript_array[] = $wwwroot . 'artefact/file/js/filebrowser.js';
                    $javascript_array[] = $jsroot . 'tinymce/tinymce.js';
                    $stylesheets = array_merge($stylesheets, array_reverse(array_values($THEME->get_url('style/tinymceskin.css', true))));
                    $content_css = json_encode($THEME->get_url('style/tinymce.css'));
                    $language = current_language();
                    $language = substr($language, 0, substr_count($language, '_') > 0 ? 5 : 2);
                    if ($language != 'en' && !file_exists(get_config('docroot') . 'js/tinymce/langs/' . $language . '.js')) {
                        // In case the language file exists as a string with both lower and upper case, eg fr_FR we test for this
                        $language = substr($language, 0, 2) . '_' . strtoupper(substr($language, 0, 2));
                        if (!file_exists(get_config('docroot') . 'js/tinymce/langs/' . $language . '.js')) {
                            // In case we fail to find a language of 5 chars, eg pt_BR (Portugese, Brazil) we try the 'parent' pt (Portugese)
                            $language = substr($language, 0, 2);
                            if ($language != 'en' && !file_exists(get_config('docroot') . 'js/tinymce/langs/' . $language . '.js')) {
                                $language = 'en';
                            }
                        }
                    }
                    $extrasetup = isset($extraconfig['tinymcesetup']) ? $extraconfig['tinymcesetup'] : '';
                    $extramceconfig = isset($extraconfig['tinymceconfig']) ? $extraconfig['tinymceconfig'] : '';
                    // Check whether to make the spellchecker available
                    if (get_config('tinymcespellcheckerengine')) {
                        $spellchecker = ',spellchecker';
                        $spellchecker_toolbar = '| spellchecker';
                        $spellchecker_config = "gecko_spellcheck : false, spellchecker_rpc_url : \"{$jsroot}tinymce/plugins/spellchecker/spellchecker.php\",";
                    } else {
                        $spellchecker = $spellchecker_toolbar = '';
                        $spellchecker_config = 'gecko_spellcheck : true,';
                    }
                    $mathslate = get_config('mathjax') ? 'mathslate' : '';
                    $mathslateplugin = !empty($mathslate) ? ',' . $mathslate : '';
                    $toolbar = array(null, '"toolbar_toggle | formatselect | bold italic | bullist numlist | link unlink | imagebrowser | undo redo"', '"underline strikethrough subscript superscript | alignleft aligncenter alignright alignjustify | outdent indent | forecolor backcolor | ltr rtl | fullscreen"', '"fontselect | fontsizeselect | emoticons nonbreaking charmap ' . $mathslate . ' ' . $spellchecker_toolbar . ' | table | removeformat pastetext | code"');
                    // For right-to-left langs, reverse button order & align controls right.
                    $tinymce_langdir = $langdirection == 'rtl' ? 'rtl' : 'ltr';
                    $toolbar_align = 'left';
                    // Language strings required for TinyMCE
                    $pagestrings['mahara'] = isset($pagestrings['mahara']) ? $pagestrings['mahara'] : array();
                    $pagestrings['mahara'][] = 'attachedimage';
                    if ($check[$key] == 'tinymce') {
                        $tinymceconfig = <<<EOF
    theme: "modern",
    plugins: "tooltoggle,textcolor,visualblocks,wordcount,link,imagebrowser,table,emoticons{$spellchecker},paste,code,fullscreen,directionality,searchreplace,nonbreaking,charmap{$mathslateplugin}",
    skin: 'light',
    toolbar1: {$toolbar[1]},
    toolbar2: {$toolbar[2]},
    toolbar3: {$toolbar[3]},
    menubar: false,
    fix_list_elements: true,
    image_advtab: true,
    {$spellchecker_config}
EOF;
                    } else {
                        $tinymceconfig = <<<EOF
    selector: "textarea.tinywysiwyg",
    theme: "modern",
    skin: 'light',
    plugins: "fullscreen,autoresize",
    toolbar: {$toolbar[0]},
EOF;
                    }
                    $headers[] = <<<EOF
<script type="application/javascript">
tinyMCE.init({
    {$tinymceconfig}
    schema: 'html4',
    extended_valid_elements : "object[width|height|classid|codebase],param[name|value],embed[src|type|width|height|flashvars|wmode],script[src,type,language],+ul[id|type|compact],iframe[src|width|height|align|title|class|type|frameborder|allowfullscreen]",
    urlconverter_callback : "custom_urlconvert",
    language: '{$language}',
    directionality: "{$tinymce_langdir}",
    content_css : {$content_css},
    remove_script_host: false,
    relative_urls: false,
    {$extramceconfig}
    setup: function(ed) {
        ed.on('init', function(ed) {
            if (typeof(editor_to_focus) == 'string' && ed.editorId == editor_to_focus) {
                ed.focus();
            }
        });
        ed.on('LoadContent', function(e) {
            // Hide all the 2nd/3rd row menu buttons
            jQuery('.mce-toolbar.mce-first').siblings().toggleClass('hidden');
            // The tinymce fullscreen mode does not work properly in a transformed container div
            // such as div.vertcentre
            // and IE doesn't like a preset z-index
            // This work-around will remove/add classes: .vertcenter .configure .blockinstane
            // of the configure block div
            // when toggling fullscreen
            jQuery('div[aria-label="Fullscreen"]').on('click', function(e) {
                jQuery('div#configureblock').toggleClass('vertcentre');
                jQuery('div#configureblock').toggleClass('blockinstance');
                jQuery('div#configureblock').toggleClass('configure');
            });
        });
        {$extrasetup}
    }
});

function imageBrowserConfigSuccess(form, data) {
    // handle updates to file browser
    // final form submission handled by tinymce plugin
    if (data.formelementsuccess) {
        eval(data.formelementsuccess + '(form, data)');
        return;
    }
}

function imageBrowserConfigError(form, data) {
    if (data.formelementerror) {
        eval(data.formelementerror + '(form, data)');
        return;
    }
}

function custom_urlconvert (u, n, e) {
    // Don't convert the url on the skype status buttons.
    if (u.indexOf('skype:') == 0) {
      return u;
    }
    var t = tinyMCE.activeEditor, s = t.settings;

    // Don't convert link href since thats the CSS files that gets loaded into the editor also skip local file URLs
    if (!s.convert_urls || (e && e.nodeName == 'LINK') || u.indexOf('file:') === 0)
      return u;

    // Convert to relative
    if (s.relative_urls)
      return t.documentBaseURI.toRelative(u);

    // Convert to absolute
    u = t.documentBaseURI.toAbsolute(u, s.remove_script_host);

    return u;
}
</script>

EOF;
                    unset($check[$key]);
                } else {
                    if ($check[$key] != $found_tinymce) {
                        log_warn('Two differently configured tinyMCE instances have been asked for on this page! This is not possible');
                    }
                    unset($check[$key]);
                }
            }
            // If any page adds jquery explicitly, remove it from the list
            if (($key = array_search('jquery', $check)) !== false) {
                unset($check[$key]);
            }
        }
    } else {
        if (($key = array_search('tinymce', $javascript)) !== false || ($key = array_search('tinytinymce', $javascript)) !== false) {
            unset($javascript[$key]);
        }
        if (($key = array_search('tinymce', $headers)) !== false || ($key = array_search('tinytinymce', $headers)) !== false) {
            unset($headers[$key]);
        }
    }
    if (get_config('developermode') & DEVMODE_UNPACKEDJS) {
        $javascript_array[] = $jsroot . 'MochiKit/MochiKit.js';
        $javascript_array[] = $jsroot . 'MochiKit/Position.js';
        $javascript_array[] = $jsroot . 'MochiKit/Color.js';
        $javascript_array[] = $jsroot . 'MochiKit/Visual.js';
        $javascript_array[] = $jsroot . 'MochiKit/DragAndDrop.js';
        $javascript_array[] = $jsroot . 'MochiKit/Format.js';
    } else {
        $javascript_array[] = $jsroot . 'MochiKit/Packed.js';
    }
    $javascript_array[] = $jsroot . 'keyboardNavigation.js';
    //If necessary, load MathJax path
    if (get_config('mathjax')) {
        $javascript_array[] = get_config('mathjaxpath');
    }
    $strings = array();
    foreach ($pagestrings as $k => $v) {
        if (is_array($v)) {
            foreach ($v as $tag) {
                $strings[$tag] = get_raw_string($tag, $k);
            }
        } else {
            $strings[$k] = get_raw_string($k, $v);
        }
    }
    $jsstrings = jsstrings();
    $themepaths = themepaths();
    foreach ($javascript as $jsfile) {
        // For now, if there's no path in the js file, assume it's in
        // $jsroot and append '.js' to the name.  Later we may want to
        // ensure all smarty() calls include the full path to the js
        // file, with the proper extension.
        if (strpos($jsfile, '/') === false) {
            $javascript_array[] = $jsroot . $jsfile . '.js';
            if (isset($jsstrings[$jsfile])) {
                foreach ($jsstrings[$jsfile] as $section => $tags) {
                    foreach ($tags as $tag) {
                        $strings[$tag] = get_raw_string($tag, $section);
                    }
                }
            }
            if (isset($themepaths[$jsfile])) {
                foreach ($themepaths[$jsfile] as $themepath) {
                    $theme_list[$themepath] = $THEME->get_url($themepath);
                }
            }
        } else {
            if (stripos($jsfile, 'http://') === false && stripos($jsfile, 'https://') === false) {
                // A local .js file with a fully specified path
                $javascript_array[] = $wwwroot . $jsfile;
                // If $jsfile is from a plugin or plugin's block, i.e.:
                // - plugintype/pluginname/js/foo.js
                // - plugintype/pluginname/blocktype/pluginname/js/foo.js
                // Then get js strings from static function jsstrings in:
                // - plugintype/pluginname/lib.php, or
                // - plugintype/pluginname/blocktype/pluginname/lib.php
                $bits = explode('/', $jsfile);
                $pluginname = false;
                $plugintype = false;
                $jsfilename = false;
                if (count($bits) == 4 && $bits[2] == 'js' && in_array($bits[0], plugin_types())) {
                    $plugintype = $bits[0];
                    $pluginname = $bits[1];
                    $jsfilename = $bits[3];
                }
                if (count($bits) == 6 && $bits[0] == 'artefact' && $bits[2] == 'blocktype' && $bits[4] == 'js') {
                    $plugintype = 'blocktype';
                    $pluginname = $bits[3];
                    $jsfilename = $bits[5];
                }
                if ($pluginname) {
                    safe_require($plugintype, $pluginname);
                    $pluginclass = generate_class_name($plugintype, $pluginname);
                    $name = substr($jsfilename, 0, strpos($jsfilename, '.js'));
                    if (is_callable(array($pluginclass, 'jsstrings'))) {
                        $tempstrings = call_static_method($pluginclass, 'jsstrings', $name);
                        foreach ($tempstrings as $section => $tags) {
                            foreach ($tags as $tag) {
                                $strings[$tag] = get_raw_string($tag, $section);
                            }
                        }
                    }
                    if (is_callable(array($pluginclass, 'jshelp'))) {
                        $tempstrings = call_static_method($pluginclass, 'jshelp', $name);
                        foreach ($tempstrings as $section => $tags) {
                            foreach ($tags as $tag) {
                                $strings[$tag . '.help'] = get_help_icon($plugintype, $pluginname, null, null, null, $tag);
                            }
                        }
                    }
                    if (is_callable(array($pluginclass, 'themepaths'))) {
                        $tmpthemepaths = call_static_method($pluginclass, 'themepaths', $name);
                        foreach ($tmpthemepaths as $themepath) {
                            $theme_list[$themepath] = $THEME->get_url($themepath);
                        }
                    }
                }
            } else {
                // A remote .js file
                $javascript_array[] = $jsfile;
            }
        }
    }
    $javascript_array[] = $jsroot . 'mahara.js';
    $javascript_array[] = $jsroot . 'formchangechecker.js';
    if (get_config('developermode') & DEVMODE_DEBUGJS) {
        $javascript_array[] = $jsroot . 'debug.js';
    }
    foreach ($jsstrings['mahara'] as $section => $tags) {
        foreach ($tags as $tag) {
            $strings[$tag] = get_raw_string($tag, $section);
        }
    }
    if (isset($extraconfig['themepaths']) && is_array($extraconfig['themepaths'])) {
        foreach ($extraconfig['themepaths'] as $themepath) {
            $theme_list[$themepath] = $THEME->get_url($themepath);
        }
    }
    $stringjs = '<script type="application/javascript">';
    $stringjs .= 'var strings = ' . json_encode($strings) . ';';
    $stringjs .= "\nfunction plural(n) { return " . get_raw_string('pluralrule', 'langconfig') . "; }\n";
    $stringjs .= '</script>';
    // Allow us to set the HTML lang attribute
    $smarty->assign('LANGUAGE', substr(current_language(), 0, 2));
    $smarty->assign('STRINGJS', $stringjs);
    $stylesheets = get_stylesheets_for_current_page($stylesheets, $extraconfig);
    $smarty->assign('STYLESHEETLIST', $stylesheets);
    if (!empty($theme_list)) {
        // this gets assigned in smarty_core, but do it again here if it's changed locally
        $smarty->assign('THEMELIST', json_encode(array_merge((array) json_decode($smarty->get_template_vars('THEMELIST')), $theme_list)));
    }
    $dropdownmenu = get_config('dropdownmenu');
    // disable drop-downs if overridden at institution level
    $sitethemeprefs = get_config('sitethemeprefs');
    $institutions = $USER->institutions;
    if (!empty($institutions)) {
        foreach ($institutions as $i) {
            if (!empty($sitethemeprefs)) {
                if (!empty($USER->accountprefs['theme']) && $USER->accountprefs['theme'] == $THEME->basename . '/' . $i->institution) {
                    $dropdownmenu = $i->dropdownmenu;
                }
            } else {
                if (!empty($USER->accountprefs['theme']) && $USER->accountprefs['theme'] == $THEME->basename . '/' . $i->institution || empty($USER->accountprefs) && $i->theme == $THEME->basename && $USER->institutiontheme->institutionname == $i->institution) {
                    $dropdownmenu = $i->dropdownmenu;
                }
            }
        }
    }
    // and/or disable drop-downs if a handheld device detected
    $dropdownmenu = $SESSION->get('handheld_device') ? false : $dropdownmenu;
    if ($dropdownmenu) {
        $smarty->assign('DROPDOWNMENU', $dropdownmenu);
        $javascript_array[] = $jsroot . 'dropdown-nav.js';
    }
    $smarty->assign('MOBILE', $SESSION->get('mobile'));
    $smarty->assign('HANDHELD_DEVICE', $SESSION->get('handheld_device'));
    $sitename = get_config('sitename');
    if (!$sitename) {
        $sitename = 'Mahara';
    }
    $smarty->assign('sitename', $sitename);
    $sitelogo = $THEME->header_logo();
    $sitelogo = append_version_number($sitelogo);
    $smarty->assign('sitelogo', $sitelogo);
    $smarty->assign('sitelogo4facebook', $THEME->facebook_logo());
    $smarty->assign('sitedescription4facebook', get_string('facebookdescription', 'mahara'));
    if (defined('TITLE')) {
        $smarty->assign('PAGETITLE', TITLE . ' - ' . $sitename);
        $smarty->assign('heading', TITLE);
    } else {
        $smarty->assign('PAGETITLE', $sitename);
    }
    $smarty->assign('PRODUCTIONMODE', get_config('productionmode'));
    if (function_exists('local_header_top_content')) {
        $sitetop = (isset($sitetop) ? $sitetop : '') . local_header_top_content();
    }
    if (isset($sitetop)) {
        $smarty->assign('SITETOP', $sitetop);
    }
    if (defined('PUBLIC')) {
        $smarty->assign('PUBLIC', true);
    }
    if (defined('ADMIN')) {
        $smarty->assign('ADMIN', true);
    }
    if (defined('INSTITUTIONALADMIN')) {
        $smarty->assign('INSTITUTIONALADMIN', true);
    }
    if (defined('STAFF')) {
        $smarty->assign('STAFF', true);
    }
    if (defined('INSTITUTIONALSTAFF')) {
        $smarty->assign('INSTITUTIONALSTAFF', true);
    }
    $smarty->assign('LOGGEDIN', $USER->is_logged_in());
    $publicsearchallowed = false;
    $searchplugin = get_config('searchplugin');
    if ($searchplugin) {
        safe_require('search', $searchplugin);
        $publicsearchallowed = call_static_method(generate_class_name('search', $searchplugin), 'publicform_allowed') && get_config('publicsearchallowed');
    }
    $smarty->assign('publicsearchallowed', $publicsearchallowed);
    if ($USER->is_logged_in()) {
        global $SELECTEDSUBNAV;
        // It's evil, but rightnav & mainnav stuff are now in different templates.
        $smarty->assign('MAINNAV', main_nav());
        $mainnavsubnav = $SELECTEDSUBNAV;
        $smarty->assign('RIGHTNAV', right_nav());
        if (!$mainnavsubnav && $dropdownmenu) {
            // In drop-down navigation, the submenu is only usable if its parent is one of the top-level menu
            // items.  But if the submenu comes from something in right_nav (settings), it's unreachable.
            // Turning the submenu into SUBPAGENAV group-style tabs makes it usable.
            $smarty->assign('SUBPAGENAV', $SELECTEDSUBNAV);
        } else {
            $smarty->assign('SELECTEDSUBNAV', $SELECTEDSUBNAV);
        }
    } else {
        $smarty->assign('languageform', $langselectform);
    }
    $smarty->assign('FOOTERMENU', footer_menu());
    $smarty->assign_by_ref('USER', $USER);
    $smarty->assign('SESSKEY', $USER->get('sesskey'));
    $smarty->assign('CC_ENABLED', get_config('cookieconsent_enabled'));
    $javascript_array = append_version_number($javascript_array);
    $smarty->assign_by_ref('JAVASCRIPT', $javascript_array);
    $smarty->assign('RELEASE', get_config('release'));
    $smarty->assign('SERIES', get_config('series'));
    $smarty->assign('CACHEVERSION', get_config('cacheversion'));
    $siteclosedforupgrade = get_config('siteclosed');
    if ($siteclosedforupgrade && get_config('disablelogin')) {
        $smarty->assign('SITECLOSED', 'logindisabled');
    } else {
        if ($siteclosedforupgrade || get_config('siteclosedbyadmin')) {
            $smarty->assign('SITECLOSED', 'loginallowed');
        }
    }
    if (!isset($extraconfig['pagehelp']) || $extraconfig['pagehelp'] !== false and $help = has_page_help()) {
        $smarty->assign('PAGEHELPNAME', $help[0]);
        $smarty->assign('PAGEHELPICON', $help[1]);
    }
    if (defined('GROUP')) {
        require_once 'group.php';
        if ($group = group_current_group()) {
            $smarty->assign('GROUP', $group);
            if (!defined('NOGROUPMENU')) {
                $smarty->assign('SUBPAGENAV', group_get_menu_tabs());
                $smarty->assign('PAGEHEADING', $group->name);
            }
        }
    }
    // ---------- sideblock stuff ----------
    $sidebars = !isset($extraconfig['sidebars']) || $extraconfig['sidebars'] !== false;
    if ($sidebars && !defined('INSTALLER') && (!defined('MENUITEM') || substr(MENUITEM, 0, 5) != 'admin')) {
        if (get_config('installed') && !$adminsection) {
            $data = site_menu();
            if (!empty($data)) {
                $smarty->assign('SITEMENU', site_menu());
                $sideblocks[] = array('name' => 'linksandresources', 'weight' => 10, 'data' => $data);
            }
        }
        if ($USER->is_logged_in() && defined('MENUITEM') && (substr(MENUITEM, 0, 11) == 'myportfolio' || substr(MENUITEM, 0, 7) == 'content')) {
            if (get_config('showselfsearchsideblock')) {
                $sideblocks[] = array('name' => 'selfsearch', 'weight' => 0, 'data' => array());
            }
            if (get_config('showtagssideblock')) {
                $sideblocks[] = array('name' => 'tags', 'id' => 'sb-tags', 'weight' => 0, 'data' => tags_sideblock());
            }
        }
        if ($USER->is_logged_in() && !$adminsection) {
            $sideblocks[] = array('name' => 'profile', 'id' => 'sb-profile', 'class' => 'user-panel', 'weight' => -20, 'data' => profile_sideblock());
            $showusers = 2;
            $institutions = $USER->institutions;
            if (!empty($institutions)) {
                $showusers = 0;
                foreach ($institutions as $i) {
                    if ($i->showonlineusers == 2) {
                        $showusers = 2;
                        break;
                    }
                    if ($i->showonlineusers == 1) {
                        $showusers = 1;
                    }
                }
            }
            if (get_config('showonlineuserssideblock') && $showusers > 0) {
                $sideblocks[] = array('name' => 'onlineusers', 'id' => 'sb-onlineusers', 'weight' => -10, 'data' => onlineusers_sideblock());
            }
            if (get_config('showprogressbar') && $USER->get_account_preference('showprogressbar')) {
                $sideblocks[] = array('name' => 'progressbar', 'id' => 'sb-progressbar', 'class' => 'progressbar', 'weight' => -8, 'data' => progressbar_sideblock());
            }
        }
        if ($USER->is_logged_in() && $adminsection && defined('SECTION_PAGE') && SECTION_PAGE == 'progressbar') {
            $sideblocks[] = array('name' => 'progressbar', 'id' => 'sb-progressbar', 'class' => 'progressbar', 'weight' => -8, 'data' => progressbar_sideblock(true));
        }
        $isloginblockvisible = !$USER->is_logged_in() && !(get_config('siteclosed') && get_config('disablelogin')) && get_config('showloginsideblock');
        if ($isloginblockvisible) {
            $sideblocks[] = array('name' => 'login', 'weight' => -10, 'id' => 'sb-loginbox', 'data' => array('loginform' => auth_generate_login_form()));
        }
        if (get_config('enablenetworking')) {
            require_once get_config('docroot') . 'api/xmlrpc/lib.php';
            if ($USER->is_logged_in() && ($ssopeers = get_service_providers($USER->authinstance))) {
                $sideblocks[] = array('name' => 'ssopeers', 'weight' => 1, 'data' => $ssopeers);
            }
        }
        if (isset($extraconfig['sideblocks']) && is_array($extraconfig['sideblocks'])) {
            foreach ($extraconfig['sideblocks'] as $sideblock) {
                $sideblocks[] = $sideblock;
            }
        }
        // local_sideblocks_update allows sites to customise the sideblocks by munging the $sideblocks array.
        if (function_exists('local_sideblocks_update')) {
            local_sideblocks_update($sideblocks);
        }
        usort($sideblocks, create_function('$a,$b', 'if ($a["weight"] == $b["weight"]) return 0; return ($a["weight"] < $b["weight"]) ? -1 : 1;'));
        // Place all sideblocks on the right. If this structure is munged
        // appropriately, you can put blocks on the left. In future versions of
        // Mahara, we'll make it easy to do this.
        $sidebars = $sidebars && !empty($sideblocks);
        $sideblocks = array('left' => array(), 'right' => $sideblocks);
        $smarty->assign('userauthinstance', $SESSION->get('authinstance'));
        $smarty->assign('MNETUSER', $SESSION->get('mnetuser'));
        $smarty->assign('SIDEBLOCKS', $sideblocks);
        $smarty->assign('SIDEBARS', $sidebars);
    }
    if (is_array($HEADDATA) && !empty($HEADDATA)) {
        $headers = array_merge($HEADDATA, $headers);
    }
    $smarty->assign_by_ref('HEADERS', $headers);
    if ($USER->get('parentuser')) {
        $smarty->assign('USERMASQUERADING', true);
        $smarty->assign('masqueradedetails', get_string('youaremasqueradingas', 'mahara', display_name($USER)));
        $smarty->assign('becomeyoulink', hsc($wwwroot) . 'admin/users/changeuser.php?restore=1');
        $smarty->assign('becomeyouagain', get_string('becomeadminagain', 'admin', hsc($USER->get('parentuser')->name)));
    }
    // Define additional html content
    if (get_config('installed')) {
        $additionalhtmlitems = array('ADDITIONALHTMLHEAD' => get_config('additionalhtmlhead'), 'ADDITIONALHTMLTOPOFBODY' => get_config('additionalhtmltopofbody'), 'ADDITIONALHTMLFOOTER' => get_config('additionalhtmlfooter'));
        if ($additionalhtmlitems) {
            foreach ($additionalhtmlitems as $name => $content) {
                $smarty->assign($name, $content);
            }
        }
    }
    // If Cookie Consent is enabled, than define conent
    if (get_config('cookieconsent_enabled')) {
        require_once 'cookieconsent.php';
        $smarty->assign('COOKIECONSENTCODE', get_cookieconsent_code());
    }
    return $smarty;
}
Пример #7
0
/**
 * Returns a datastructure describing the tabs that appear on a group page
 *
 * @param object $group Database record of group to get tabs for
 * @return array
 */
function group_get_menu_tabs()
{
    static $menu;
    $group = group_current_group();
    if (!$group) {
        return null;
    }
    $role = group_user_access($group->id);
    $menu = array('info' => array('path' => 'groups/info', 'url' => group_homepage_url($group, false), 'title' => get_string('About', 'group'), 'weight' => 20));
    if (group_can_list_members($group, $role)) {
        $menu['members'] = array('path' => 'groups/members', 'url' => 'group/members.php?id=' . $group->id, 'title' => get_string('Members', 'group'), 'weight' => 30);
    }
    if ($interactionplugins = plugins_installed('interaction')) {
        foreach ($interactionplugins as $plugin) {
            safe_require('interaction', $plugin->name);
            $plugin_menu = call_static_method(generate_class_name('interaction', $plugin->name), 'group_menu_items', $group);
            $menu = array_merge($menu, $plugin_menu);
        }
    }
    $menu['views'] = array('path' => 'groups/views', 'url' => 'view/groupviews.php?group=' . $group->id, 'title' => get_string('Views', 'group'), 'weight' => 50);
    $menu['collections'] = array('path' => 'groups/collections', 'url' => 'collection/index.php?group=' . $group->id, 'title' => get_string('Collections', 'group'), 'weight' => 60);
    if (group_role_can_edit_views($group, $role)) {
        $menu['share'] = array('path' => 'groups/share', 'url' => 'group/shareviews.php?group=' . $group->id, 'title' => get_string('share', 'view'), 'weight' => 70);
    }
    if ($role) {
        safe_require('grouptype', $group->grouptype);
        $artefactplugins = call_static_method('GroupType' . $group->grouptype, 'get_group_artefact_plugins');
        if ($plugins = plugins_installed('artefact')) {
            foreach ($plugins as &$plugin) {
                if (!in_array($plugin->name, $artefactplugins)) {
                    continue;
                }
                safe_require('artefact', $plugin->name);
                $plugin_menu = call_static_method(generate_class_name('artefact', $plugin->name), 'group_tabs', $group->id);
                $menu = array_merge($menu, $plugin_menu);
            }
        }
    }
    if (group_role_can_access_report($group, $role)) {
        $menu['report'] = array('path' => 'groups/report', 'url' => 'group/report.php?group=' . $group->id, 'title' => get_string('report', 'group'), 'weight' => 70);
    }
    if (defined('MENUITEM')) {
        $key = substr(MENUITEM, strlen('groups/'));
        if ($key && isset($menu[$key])) {
            $menu[$key]['selected'] = true;
        }
    }
    return $menu;
}
Пример #8
0
 public static function bulk_delete($artefactids)
 {
     global $USER;
     require_once 'group.php';
     if (empty($artefactids)) {
         return;
     }
     $idstr = join(',', array_map('intval', $artefactids));
     db_begin();
     // Get the size of all the files we're about to delete that belong to
     // the user.
     if ($group = group_current_group()) {
         $totalsize = get_field_sql('
             SELECT SUM(size)
             FROM {artefact_file_files} f JOIN {artefact} a ON f.artefact = a.id
             WHERE a.group = ? AND f.artefact IN (' . $idstr . ')', array($group->id));
     } else {
         $totalsize = get_field_sql('
             SELECT SUM(size)
             FROM {artefact_file_files} f JOIN {artefact} a ON f.artefact = a.id
             WHERE a.owner = ? AND f.artefact IN (' . $idstr . ')', array($USER->get('id')));
     }
     // Get all fileids so that we can delete the files on disk
     $filetodeleteids = get_column_sql('
         SELECT fileid
         FROM {artefact_file_files} aff1
         WHERE artefact IN (' . $idstr . ')
         GROUP BY fileid
         HAVING COUNT(aff1.artefact) IN
            (SELECT COUNT(aff2.artefact)
             FROM {artefact_file_files} aff2
             WHERE aff1.fileid = aff2.fileid)', null);
     // The current rule is that file deletion should be logged in the artefact_log table
     // only for group-owned files.  To save time we will be slightly naughty here and
     // log deletion for all these files if at least one is group-owned.
     $log = (bool) count_records_select('artefact', 'id IN (' . $idstr . ') AND "group" IS NOT NULL');
     delete_records_select('artefact_attachment', 'attachment IN (' . $idstr . ')');
     delete_records_select('artefact_file_files', 'artefact IN (' . $idstr . ')');
     parent::bulk_delete($artefactids, $log);
     foreach ($filetodeleteids as $filetodeleteid) {
         $file = get_config('dataroot') . self::get_file_directory($filetodeleteid) . '/' . $filetodeleteid;
         if (is_file($file)) {
             unlink($file);
         }
     }
     if ($totalsize) {
         if ($group) {
             group_quota_remove($group->id, $totalsize);
         } else {
             $USER->quota_remove($totalsize);
             $USER->commit();
         }
     }
     db_commit();
 }
Пример #9
0
/**
 * This function creates a Smarty object and sets it up for use within our
 * podclass app, setting up some variables.
 *
 * The variables that it sets up are:
 *
 * - WWWROOT: The base url for the Mahara system
 * - USER: The user object
 * - JAVASCRIPT: A list of javascript files to include in the header.  This
 *   list is passed into this function (see below).
 * - HEADERS: An array of any further headers to set.  Each header is just
 *   straight HTML (see below).
 * - PUBLIC: Set true if this page is a public page
 * - MAINNAV: Array defining the main navigation
 *
 * @param $javascript A list of javascript includes.  Each include should be just
 *                    the name of a file, and reside in js/{filename}
 * @param $headers    A list of additional headers.  These are to be specified as
 *                    actual HTML.
 * @param $strings    A list of language strings required by the javascript code.
 * @return Smarty
 */
function smarty($javascript = array(), $headers = array(), $pagestrings = array(), $extraconfig = array())
{
    global $USER, $SESSION, $THEME, $HEADDATA;
    if (!is_array($headers)) {
        $headers = array();
    }
    if (!is_array($pagestrings)) {
        $pagestrings = array();
    }
    if (!is_array($extraconfig)) {
        $extraconfig = array();
    }
    $SIDEBLOCKS = array();
    $langselectform = language_select_form();
    $smarty = smarty_core();
    $wwwroot = get_config('wwwroot');
    // NOTE: not using jswwwroot - it seems to wreck image paths if you
    // drag them around the wysiwyg editor
    $jswwwroot = json_encode($wwwroot);
    // Workaround for $cfg->cleanurlusersubdomains.
    // When cleanurlusersubdomains is on, ajax requests might come from somewhere other than
    // the wwwroot.  To avoid cross-domain requests, set a js variable when this page is on a
    // different subdomain, and let the ajax wrapper function sendjsonrequest rewrite its url
    // if necessary.
    if (get_config('cleanurls') && get_config('cleanurlusersubdomains')) {
        if ($requesthost = get_requested_host_name()) {
            $wwwrootparts = parse_url($wwwroot);
            if ($wwwrootparts['host'] != $requesthost) {
                $fakewwwroot = $wwwrootparts['scheme'] . '://' . $requesthost . '/';
                $headers[] = '<script type="text/javascript">var fakewwwroot = ' . json_encode($fakewwwroot) . ';</script>';
            }
        }
    }
    $theme_list = array();
    if (function_exists('pieform_get_headdata')) {
        $headers = array_merge($headers, pieform_get_headdata());
        if (!defined('PIEFORM_GOT_HEADDATA')) {
            define('PIEFORM_GOT_HEADDATA', 1);
        }
    }
    // Insert the appropriate javascript tags
    $javascript_array = array();
    $jsroot = $wwwroot . 'js/';
    $langdirection = get_string('thisdirection', 'langconfig');
    // TinyMCE must be included first for some reason we're not sure about
    //
    // Note: we do not display tinyMCE for mobile devices
    // as it doesn't work on some of them and can
    // disable the editing of a textarea field
    if ($SESSION->get('handheld_device') == false) {
        $checkarray = array(&$javascript, &$headers);
        $found_tinymce = false;
        foreach ($checkarray as &$check) {
            if (($key = array_search('tinymce', $check)) !== false || ($key = array_search('tinytinymce', $check)) !== false) {
                if (!$found_tinymce) {
                    $found_tinymce = $check[$key];
                    $javascript_array[] = $jsroot . 'tinymce/tiny_mce.js';
                    $content_css = json_encode($THEME->get_url('style/tinymce.css'));
                    $language = substr(current_language(), 0, 2);
                    if ($language != 'en' && !file_exists(get_config('docroot') . 'js/tinymce/langs/' . $language . '.js')) {
                        $language = 'en';
                    }
                    $extrasetup = isset($extraconfig['tinymcesetup']) ? $extraconfig['tinymcesetup'] : '';
                    // OVERWRITE 1: replacement, changed from:
                    // $adv_buttons = array(
                    //    "undo,redo,separator,bold,italic,underline,separator,justifyleft,justifycenter,justifyright,justifyfull,separator,bullist,numlist,separator,link,unlink,separator,code,fullscreen",
                    //    "bold,italic,underline,strikethrough,separator,forecolor,backcolor,separator,justifyleft,justifycenter,justifyright,justifyfull,separator,hr,emotions,image,spellchecker,cleanup,separator,link,unlink,separator,code,fullscreen",
                    //    "undo,redo,separator,bullist,numlist,separator,tablecontrols,separator,cut,copy,paste,pasteword",
                    //    "fontselect,separator,fontsizeselect,separator,formatselect",
                    //);
                    // to:
                    $adv_buttons = array("undo,redo,separator,bold,italic,underline,separator,justifyleft,justifycenter,justifyright,justifyfull,separator,bullist,numlist,separator,link,unlink,separator,code,fullscreen", "bold,italic,underline,strikethrough,separator,forecolor,backcolor,separator,justifyleft,justifycenter,justifyright,justifyfull,separator,hr,emotions,image,media,gcrcloudstorage,spellchecker,cleanup,separator,link,unlink,separator,code,fullscreen", "undo,redo,separator,bullist,numlist,separator,tablecontrols,separator,cut,copy,paste,pasteword,tinyautosave", "fontselect,separator,fontsizeselect,separator,formatselect");
                    // END OVERWRITE 1
                    // For right-to-left langs, reverse button order & align controls right.
                    $tinymce_langdir = $langdirection == 'rtl' ? 'rtl' : 'ltr';
                    $toolbar_align = 'left';
                    // OVERWRITE 2: replacement, changed from:
                    /*if ($check[$key] == 'tinymce') {
                                        $spellchecker_rpc = $jsroot.'tinymce/plugins/spellchecker/rpc.php';
                                        $tinymce_config = <<<EOF
                        mode: "none",
                        theme: "advanced",
                        plugins: "table,emotions,spellchecker,inlinepopups,paste,fullscreen",
                        theme_advanced_buttons1 : "{$adv_buttons[1]}",
                        theme_advanced_buttons2 : "{$adv_buttons[2]}",
                        theme_advanced_buttons3 : "{$adv_buttons[3]}",
                        theme_advanced_toolbar_location : "top",
                        theme_advanced_toolbar_align : "{$toolbar_align}",
                        fix_list_elements: true,
                        spellchecker_rpc_url : "{$spellchecker_rpc}",
                        //width: '512',
                    EOF;
                                    }
                                    else {
                                        $tinymce_config = <<<EOF
                        mode: "textareas",
                        editor_selector: 'tinywysiwyg',
                        theme: "advanced",
                        plugins: "fullscreen,inlinepopups,autoresize",
                        theme_advanced_buttons1 : "{$adv_buttons[0]}",
                        theme_advanced_buttons2 : "",
                        theme_advanced_buttons3 : "",
                        theme_advanced_toolbar_location : "top",
                        theme_advanced_toolbar_align : "{$toolbar_align}",
                        fullscreen_new_window: true,
                        fullscreen_settings: {
                            theme: "advanced",
                            plugins: "table,emotions,iespell,inlinepopups,paste,fullscreen",
                            theme_advanced_buttons1 : "{$adv_buttons[1]}",
                            theme_advanced_buttons2 : "{$adv_buttons[2]}",
                            theme_advanced_buttons3 : "{$adv_buttons[3]}"
                        },
                    EOF;
                                    }
                    
                                    $headers[] = <<<EOF
                    <script type="text/javascript">
                    tinyMCE.init({
                        button_tile_map: true,
                        {$tinymce_config}
                        extended_valid_elements : "object[width|height|classid|codebase],param[name|value],embed[src|type|width|height|flashvars|wmode],script[src,type,language],+ul[id|type|compact],iframe[src|width|height|align|title|class|type|frameborder|allowfullscreen]",
                        urlconverter_callback : "custom_urlconvert",
                        language: '{$language}',
                        directionality: "{$tinymce_langdir}",
                        content_css : {$content_css},
                        //document_base_url: {$jswwwroot},
                        remove_script_host: false,
                        relative_urls: false,
                        setup: function(ed) {
                            ed.onInit.add(function(ed) {
                                if (typeof(editor_to_focus) == 'string' && ed.editorId == editor_to_focus) {
                                    ed.focus();
                                }
                            });
                            {$extrasetup}
                        }
                    });
                    function custom_urlconvert (u, n, e) {
                      // Don't convert the url on the skype status buttons.
                      if (u.indexOf('skype:') == 0) {
                          return u;
                      }
                      var t = tinyMCE.activeEditor, s = t.settings;
                    
                      // Don't convert link href since thats the CSS files that gets loaded into the editor also skip local file URLs
                      if (!s.convert_urls || (e && e.nodeName == 'LINK') || u.indexOf('file:') === 0)
                          return u;
                    
                      // Convert to relative
                      if (s.relative_urls)
                          return t.documentBaseURI.toRelative(u);
                    
                      // Convert to absolute
                      u = t.documentBaseURI.toAbsolute(u, s.remove_script_host);
                    
                      return u;
                    }
                    </script>
                    
                    EOF;
                                     */
                    //to:
                    if ($check[$key] == 'tinymce') {
                        $tinymce_config = <<<EOF
    mode: "none",
    theme: "advanced",
    plugins: "table,emotions,spellchecker,inlinepopups,paste,gcrcloudstorage,media,tinyautosave",
    theme_advanced_buttons1 : "{$adv_buttons[1]}",
    theme_advanced_buttons2 : "{$adv_buttons[2]}",
    theme_advanced_buttons3 : "{$adv_buttons[3]}",
    theme_advanced_toolbar_location : "top",
    theme_advanced_toolbar_align : "{$toolbar_align}",
    //width: '512',
EOF;
                    } else {
                        $tinymce_config = <<<EOF
    mode: "textareas",
    editor_selector: 'tinywysiwyg',
    theme: "advanced",
    plugins: "fullscreen,inlinepopups,autoresize,gcrcloudstorage,media,tinyautosave",
    theme_advanced_buttons1 : "{$adv_buttons[0]}",
    theme_advanced_buttons2 : "",
    theme_advanced_buttons3 : "",
    theme_advanced_toolbar_location : "top",
    theme_advanced_toolbar_align : "{$toolbar_align}",
    fullscreen_new_window: true,
    fullscreen_settings: {
        theme: "advanced",
        plugins: "table,emotions,iespell,inlinepopups,paste,gcrcloudstorage,fullscreen,tinyautosave",
        theme_advanced_buttons1 : "{$adv_buttons[1]}",
        theme_advanced_buttons2 : "{$adv_buttons[2]}",
        theme_advanced_buttons3 : "{$adv_buttons[3]}"
    },
EOF;
                    }
                    $headers[] = <<<EOF
<script type="text/javascript">
tinyMCE.init({
    button_tile_map: true,
    {$tinymce_config}
    extended_valid_elements : "video[width|height|id|controls|preload],source[src|type],object[width|height|classid|codebase],param[name|value],embed[src|type|width|height|flashvars|wmode],script[src,type,language],+ul[id|type|compact],iframe[src|width|height|align|title|class|type|frameborder|allowfullscreen]",
    urlconverter_callback : "custom_urlconvert",
    language: '{$language}',
    directionality: "{$tinymce_langdir}",
    content_css : {$content_css},
    //document_base_url: {$jswwwroot},
    remove_script_host: false,
    relative_urls: false,
    setup: function(ed) {
        ed.onInit.add(function(ed) {
            if (typeof(editor_to_focus) == 'string' && ed.editorId == editor_to_focus) {
                ed.focus();
            }
        });
        {$extrasetup}
    }
});    
                 
function custom_urlconvert (u, n, e) {
  // Don't convert the url on the skype status buttons.
  if (u.indexOf('skype:') == 0) {
      return u;
  }
  var t = tinyMCE.activeEditor, s = t.settings;

  // Don't convert link href since thats the CSS files that gets loaded into the editor also skip local file URLs
  if (!s.convert_urls || (e && e.nodeName == 'LINK') || u.indexOf('file:') === 0)
      return u;

  // Convert to relative
  if (s.relative_urls)
      return t.documentBaseURI.toRelative(u);

  // Convert to absolute
  u = t.documentBaseURI.toAbsolute(u, s.remove_script_host);

  return u;
}
</script>

EOF;
                    // END OVERWRITE 2
                    unset($check[$key]);
                } else {
                    if ($check[$key] != $found_tinymce) {
                        log_warn('Two differently configured tinyMCE instances have been asked for on this page! This is not possible');
                    }
                    unset($check[$key]);
                }
            }
            // If any page adds jquery explicitly, remove it from the list
            if (($key = array_search('jquery', $check)) !== false) {
                unset($check[$key]);
            }
        }
    } else {
        if (($key = array_search('tinymce', $javascript)) !== false || ($key = array_search('tinytinymce', $javascript)) !== false) {
            unset($javascript[$key]);
        }
        if (($key = array_search('tinymce', $headers)) !== false || ($key = array_search('tinytinymce', $headers)) !== false) {
            unset($headers[$key]);
        }
    }
    // Make jQuery accessible with $j (Mochikit has $)
    $javascript_array[] = $jsroot . 'jquery/jquery.js';
    $headers[] = '<script type="text/javascript">$j=jQuery;</script>';
    if (get_config('developermode') & DEVMODE_UNPACKEDJS) {
        $javascript_array[] = $jsroot . 'MochiKit/MochiKit.js';
        $javascript_array[] = $jsroot . 'MochiKit/Position.js';
        $javascript_array[] = $jsroot . 'MochiKit/Color.js';
        $javascript_array[] = $jsroot . 'MochiKit/Visual.js';
        $javascript_array[] = $jsroot . 'MochiKit/DragAndDrop.js';
        $javascript_array[] = $jsroot . 'MochiKit/Format.js';
    } else {
        $javascript_array[] = $jsroot . 'MochiKit/Packed.js';
    }
    $javascript_array[] = $jsroot . 'keyboardNavigation.js';
    $strings = array();
    foreach ($pagestrings as $k => $v) {
        if (is_array($v)) {
            foreach ($v as $tag) {
                $strings[$tag] = get_raw_string($tag, $k);
            }
        } else {
            $strings[$k] = get_raw_string($k, $v);
        }
    }
    $jsstrings = jsstrings();
    $themepaths = themepaths();
    foreach ($javascript as $jsfile) {
        // For now, if there's no path in the js file, assume it's in
        // $jsroot and append '.js' to the name.  Later we may want to
        // ensure all smarty() calls include the full path to the js
        // file, with the proper extension.
        if (strpos($jsfile, '/') === false) {
            $javascript_array[] = $jsroot . $jsfile . '.js';
            if (isset($jsstrings[$jsfile])) {
                foreach ($jsstrings[$jsfile] as $section => $tags) {
                    foreach ($tags as $tag) {
                        $strings[$tag] = get_raw_string($tag, $section);
                    }
                }
            }
            if (isset($themepaths[$jsfile])) {
                foreach ($themepaths[$jsfile] as $themepath) {
                    $theme_list[$themepath] = $THEME->get_url($themepath);
                }
            }
        } else {
            if (strpos($jsfile, 'http://') === false) {
                // A local .js file with a fully specified path
                $javascript_array[] = $wwwroot . $jsfile;
                // If $jsfile is from a plugin (i.e. plugintype/pluginname/js/foo.js)
                // Then get js strings from static function jsstrings in plugintype/pluginname/lib.php
                $bits = explode('/', $jsfile);
                if (count($bits) == 4) {
                    safe_require($bits[0], $bits[1]);
                    $pluginclass = generate_class_name($bits[0], $bits[1]);
                    $name = substr($bits[3], 0, strpos($bits[3], '.js'));
                    if (is_callable(array($pluginclass, 'jsstrings'))) {
                        $tempstrings = call_static_method($pluginclass, 'jsstrings', $name);
                        foreach ($tempstrings as $section => $tags) {
                            foreach ($tags as $tag) {
                                $strings[$tag] = get_raw_string($tag, $section);
                            }
                        }
                    }
                    if (is_callable(array($pluginclass, 'jshelp'))) {
                        $tempstrings = call_static_method($pluginclass, 'jshelp', $name);
                        foreach ($tempstrings as $section => $tags) {
                            foreach ($tags as $tag) {
                                $strings[$tag . '.help'] = get_help_icon($bits[0], $bits[1], null, null, null, $tag);
                            }
                        }
                    }
                    if (is_callable(array($pluginclass, 'themepaths'))) {
                        $tmpthemepaths = call_static_method($pluginclass, 'themepaths', $name);
                        foreach ($tmpthemepaths as $themepath) {
                            $theme_list[$themepath] = $THEME->get_url($themepath);
                        }
                    }
                }
            } else {
                // A remote .js file
                $javascript_array[] = $jsfile;
            }
        }
    }
    $javascript_array[] = $jsroot . 'mahara.js';
    $javascript_array[] = $jsroot . 'formchangechecker.js';
    if (get_config('developermode') & DEVMODE_DEBUGJS) {
        $javascript_array[] = $jsroot . 'debug.js';
    }
    foreach ($jsstrings['mahara'] as $section => $tags) {
        foreach ($tags as $tag) {
            $strings[$tag] = get_raw_string($tag, $section);
        }
    }
    if (isset($extraconfig['themepaths']) && is_array($extraconfig['themepaths'])) {
        foreach ($extraconfig['themepaths'] as $themepath) {
            $theme_list[$themepath] = $THEME->get_url($themepath);
        }
    }
    $stringjs = '<script type="text/javascript">';
    $stringjs .= 'var strings = ' . json_encode($strings) . ';';
    $stringjs .= "\nfunction plural(n) { return " . get_raw_string('pluralrule', 'langconfig') . "; }\n";
    $stringjs .= '</script>';
    // stylesheet set up - if we're in a plugin also get its stylesheet
    $stylesheets = array_reverse(array_values($THEME->get_url('style/style.css', true)));
    if (defined('SECTION_PLUGINTYPE') && defined('SECTION_PLUGINNAME') && SECTION_PLUGINTYPE != 'core') {
        if ($pluginsheets = $THEME->get_url('style/style.css', true, SECTION_PLUGINTYPE . '/' . SECTION_PLUGINNAME)) {
            $stylesheets = array_merge($stylesheets, array_reverse($pluginsheets));
        }
    }
    if ($adminsection = in_admin_section()) {
        if ($adminsheets = $THEME->get_url('style/admin.css', true)) {
            $stylesheets = array_merge($stylesheets, array_reverse($adminsheets));
        }
    }
    if (get_config('developermode') & DEVMODE_DEBUGCSS) {
        $stylesheets[] = get_config('wwwroot') . 'theme/debug.css';
    }
    // look for extra stylesheets
    if (isset($extraconfig['stylesheets']) && is_array($extraconfig['stylesheets'])) {
        foreach ($extraconfig['stylesheets'] as $extrasheet) {
            if ($sheets = $THEME->get_url($extrasheet, true)) {
                $stylesheets = array_merge($stylesheets, array_reverse(array_values($sheets)));
            }
        }
    }
    if ($sheets = $THEME->additional_stylesheets()) {
        $stylesheets = array_merge($stylesheets, $sheets);
    }
    // Give the skin a chance to affect the page
    if (!empty($extraconfig['skin'])) {
        require_once get_config('docroot') . '/lib/skin.php';
        $skinobj = new Skin($extraconfig['skin']['skinid']);
        $viewid = isset($extraconfig['skin']['viewid']) ? $extraconfig['skin']['viewid'] : null;
        $stylesheets = array_merge($stylesheets, $skinobj->get_stylesheets($viewid));
    }
    // Include rtl.css for right-to-left langs
    if ($langdirection == 'rtl') {
        $smarty->assign('LANGDIRECTION', 'rtl');
        if ($rtlsheets = $THEME->get_url('style/rtl.css', true)) {
            $stylesheets = array_merge($stylesheets, array_reverse($rtlsheets));
        }
    }
    $smarty->assign('STRINGJS', $stringjs);
    $stylesheets = append_version_number($stylesheets);
    $smarty->assign('STYLESHEETLIST', $stylesheets);
    if (!empty($theme_list)) {
        // this gets assigned in smarty_core, but do it again here if it's changed locally
        $smarty->assign('THEMELIST', json_encode(array_merge((array) json_decode($smarty->get_template_vars('THEMELIST')), $theme_list)));
    }
    $dropdownmenu = get_config('dropdownmenu');
    // disable drop-downs if overridden at institution level
    $sitethemeprefs = get_config('sitethemeprefs');
    $institutions = $USER->institutions;
    if (!empty($institutions)) {
        foreach ($institutions as $i) {
            if (!empty($sitethemeprefs)) {
                if (!empty($USER->accountprefs['theme']) && $USER->accountprefs['theme'] == $THEME->basename . '/' . $i->institution) {
                    $dropdownmenu = $i->dropdownmenu;
                }
            } else {
                if (!empty($USER->accountprefs['theme']) && $USER->accountprefs['theme'] == $THEME->basename . '/' . $i->institution || empty($USER->accountprefs) && $i->theme == $THEME->basename && $USER->institutiontheme->institutionname == $i->institution) {
                    $dropdownmenu = $i->dropdownmenu;
                }
            }
        }
    }
    // and/or disable drop-downs if a handheld device detected
    $dropdownmenu = $SESSION->get('handheld_device') ? false : $dropdownmenu;
    if ($dropdownmenu) {
        $smarty->assign('DROPDOWNMENU', $dropdownmenu);
    }
    $smarty->assign('MOBILE', $SESSION->get('mobile'));
    $smarty->assign('HANDHELD_DEVICE', $SESSION->get('handheld_device'));
    $sitename = get_config('sitename');
    if (!$sitename) {
        $sitename = 'Mahara';
    }
    $smarty->assign('sitename', $sitename);
    $smarty->assign('sitelogo', $THEME->header_logo());
    $smarty->assign('sitelogo4facebook', $THEME->facebook_logo());
    $smarty->assign('sitedescription4facebook', get_string('facebookdescription', 'mahara'));
    if (defined('TITLE')) {
        $smarty->assign('PAGETITLE', TITLE . ' - ' . $sitename);
        $smarty->assign('heading', TITLE);
    } else {
        $smarty->assign('PAGETITLE', $sitename);
    }
    $smarty->assign('PRODUCTIONMODE', get_config('productionmode'));
    if (function_exists('local_header_top_content')) {
        $sitetop = (isset($sitetop) ? $sitetop : '') . local_header_top_content();
    }
    if (isset($sitetop)) {
        $smarty->assign('SITETOP', $sitetop);
    }
    if (defined('PUBLIC')) {
        $smarty->assign('PUBLIC', true);
    }
    if (defined('ADMIN')) {
        $smarty->assign('ADMIN', true);
    }
    if (defined('INSTITUTIONALADMIN')) {
        $smarty->assign('INSTITUTIONALADMIN', true);
    }
    if (defined('STAFF')) {
        $smarty->assign('STAFF', true);
    }
    if (defined('INSTITUTIONALSTAFF')) {
        $smarty->assign('INSTITUTIONALSTAFF', true);
    }
    $smarty->assign('LOGGEDIN', $USER->is_logged_in());
    if ($USER->is_logged_in()) {
        global $SELECTEDSUBNAV;
        // It's evil, but rightnav & mainnav stuff are now in different templates.
        $smarty->assign('MAINNAV', main_nav());
        $mainnavsubnav = $SELECTEDSUBNAV;
        $smarty->assign('RIGHTNAV', right_nav());
        if (!$mainnavsubnav && $dropdownmenu) {
            // In drop-down navigation, the submenu is only usable if its parent is one of the top-level menu
            // items.  But if the submenu comes from something in right_nav (settings), it's unreachable.
            // Turning the submenu into SUBPAGENAV group-style tabs makes it usable.
            $smarty->assign('SUBPAGENAV', $SELECTEDSUBNAV);
        } else {
            $smarty->assign('SELECTEDSUBNAV', $SELECTEDSUBNAV);
        }
    } else {
        $smarty->assign('languageform', $langselectform);
    }
    $smarty->assign('FOOTERMENU', footer_menu());
    $smarty->assign_by_ref('USER', $USER);
    $smarty->assign('SESSKEY', $USER->get('sesskey'));
    $javascript_array = append_version_number($javascript_array);
    $smarty->assign_by_ref('JAVASCRIPT', $javascript_array);
    $smarty->assign('RELEASE', get_config('release'));
    $siteclosedforupgrade = get_config('siteclosed');
    if ($siteclosedforupgrade && get_config('disablelogin')) {
        $smarty->assign('SITECLOSED', 'logindisabled');
    } else {
        if ($siteclosedforupgrade || get_config('siteclosedbyadmin')) {
            $smarty->assign('SITECLOSED', 'loginallowed');
        }
    }
    if (!isset($extraconfig['pagehelp']) || $extraconfig['pagehelp'] !== false and $help = has_page_help()) {
        $smarty->assign('PAGEHELPNAME', $help[0]);
        $smarty->assign('PAGEHELPICON', $help[1]);
    }
    if (defined('GROUP')) {
        require_once 'group.php';
        if ($group = group_current_group()) {
            $smarty->assign('GROUP', $group);
            if (!defined('NOGROUPMENU')) {
                $smarty->assign('SUBPAGENAV', group_get_menu_tabs());
                $smarty->assign('PAGEHEADING', $group->name);
            }
        }
    }
    // ---------- sideblock stuff ----------
    $sidebars = !isset($extraconfig['sidebars']) || $extraconfig['sidebars'] !== false;
    if ($sidebars && !defined('INSTALLER') && (!defined('MENUITEM') || substr(MENUITEM, 0, 5) != 'admin')) {
        if (get_config('installed') && !$adminsection) {
            $data = site_menu();
            if (!empty($data)) {
                $smarty->assign('SITEMENU', site_menu());
                $SIDEBLOCKS[] = array('name' => 'linksandresources', 'weight' => 10, 'data' => $data);
            }
        }
        if ($USER->is_logged_in() && defined('MENUITEM') && (substr(MENUITEM, 0, 11) == 'myportfolio' || substr(MENUITEM, 0, 7) == 'content')) {
            if (get_config('showselfsearchsideblock')) {
                $SIDEBLOCKS[] = array('name' => 'selfsearch', 'weight' => 0, 'data' => array());
            }
            if (get_config('showtagssideblock')) {
                $SIDEBLOCKS[] = array('name' => 'tags', 'id' => 'sb-tags', 'weight' => 0, 'data' => tags_sideblock());
            }
        }
        if ($USER->is_logged_in() && !$adminsection) {
            $SIDEBLOCKS[] = array('name' => 'profile', 'id' => 'sb-profile', 'weight' => -20, 'data' => profile_sideblock());
            $showusers = 2;
            $institutions = $USER->institutions;
            if (!empty($institutions)) {
                $showusers = 0;
                foreach ($institutions as $i) {
                    if ($i->showonlineusers == 2) {
                        $showusers = 2;
                        break;
                    }
                    if ($i->showonlineusers == 1) {
                        $showusers = 1;
                    }
                }
            }
            if (get_config('showonlineuserssideblock') && $showusers > 0) {
                $SIDEBLOCKS[] = array('name' => 'onlineusers', 'id' => 'sb-onlineusers', 'weight' => -10, 'data' => onlineusers_sideblock());
            }
        }
        if (defined('GROUP')) {
            $SIDEBLOCKS[] = array('name' => 'group', 'id' => 'sb-groupnav', 'weight' => -10, 'data' => group_sideblock());
        }
        if (!$USER->is_logged_in() && !(get_config('siteclosed') && get_config('disablelogin'))) {
            $SIDEBLOCKS[] = array('name' => 'login', 'weight' => -10, 'id' => 'sb-loginbox', 'data' => array('loginform' => auth_generate_login_form()));
        }
        if (get_config('enablenetworking')) {
            require_once get_config('docroot') . 'api/xmlrpc/lib.php';
            if ($USER->is_logged_in() && ($ssopeers = get_service_providers($USER->authinstance))) {
                $SIDEBLOCKS[] = array('name' => 'ssopeers', 'weight' => 1, 'data' => $ssopeers);
            }
        }
        if (isset($extraconfig['sideblocks']) && is_array($extraconfig['sideblocks'])) {
            foreach ($extraconfig['sideblocks'] as $sideblock) {
                $SIDEBLOCKS[] = $sideblock;
            }
        }
        usort($SIDEBLOCKS, create_function('$a,$b', 'if ($a["weight"] == $b["weight"]) return 0; return ($a["weight"] < $b["weight"]) ? -1 : 1;'));
        // Place all sideblocks on the right. If this structure is munged
        // appropriately, you can put blocks on the left. In future versions of
        // Mahara, we'll make it easy to do this.
        $sidebars = $sidebars && !empty($SIDEBLOCKS);
        $SIDEBLOCKS = array('left' => array(), 'right' => $SIDEBLOCKS);
        $smarty->assign('userauthinstance', $SESSION->get('authinstance'));
        $smarty->assign('MNETUSER', $SESSION->get('mnetuser'));
        $smarty->assign('SIDEBLOCKS', $SIDEBLOCKS);
        $smarty->assign('SIDEBARS', $sidebars);
    }
    if (is_array($HEADDATA) && !empty($HEADDATA)) {
        $headers = array_merge($HEADDATA, $headers);
    }
    $smarty->assign_by_ref('HEADERS', $headers);
    if ($USER->get('parentuser')) {
        $smarty->assign('USERMASQUERADING', true);
        $smarty->assign('masqueradedetails', get_string('youaremasqueradingas', 'mahara', display_name($USER)));
        $smarty->assign('becomeyouagain', ' <a href="' . hsc($wwwroot) . 'admin/users/changeuser.php?restore=1">' . get_string('becomeadminagain', 'admin', hsc($USER->get('parentuser')->name)) . '</a>');
    }
    // Define additional html content
    if (get_config('installed')) {
        $additionalhtmlitems = array('ADDITIONALHTMLHEAD' => get_config('additionalhtmlhead'), 'ADDITIONALHTMLTOPOFBODY' => get_config('additionalhtmltopofbody'), 'ADDITIONALHTMLFOOTER' => get_config('additionalhtmlfooter'));
        if ($additionalhtmlitems) {
            foreach ($additionalhtmlitems as $name => $content) {
                $smarty->assign($name, $content);
            }
        }
    }
    return $smarty;
}
Пример #10
0
/**
 * Returns a datastructure describing the tabs that appear on a group page
 *
 * @param object $group Database record of group to get tabs for
 * @return array
 */
function group_get_menu_tabs()
{
    static $menu;
    $group = group_current_group();
    if (!$group) {
        return null;
    }
    $role = group_user_access($group->id);
    $menu = array('info' => array('path' => 'groups/info', 'url' => group_homepage_url($group, false), 'title' => get_string('About', 'group'), 'weight' => 20));
    if (group_can_list_members($group, $role)) {
        $menu['members'] = array('path' => 'groups/members', 'url' => 'group/members.php?id=' . $group->id, 'title' => get_string('Members', 'group'), 'weight' => 30);
    }
    if ($interactionplugins = plugins_installed('interaction')) {
        foreach ($interactionplugins as $plugin) {
            safe_require('interaction', $plugin->name);
            $plugin_menu = call_static_method(generate_class_name('interaction', $plugin->name), 'group_menu_items', $group);
            $menu = array_merge($menu, $plugin_menu);
        }
    }
    $menu['subnav'] = array('class' => 'group');
    $menu['views'] = array('path' => 'groups/views', 'url' => 'view/groupviews.php?group=' . $group->id, 'title' => get_string('Views', 'group'), 'weight' => 50);
    $menu['collections'] = array('path' => 'groups/collections', 'url' => 'collection/index.php?group=' . $group->id, 'title' => get_string('Collections', 'group'), 'weight' => 60);
    if (group_role_can_edit_views($group, $role)) {
        $menu['share'] = array('path' => 'groups/share', 'url' => 'group/shareviews.php?group=' . $group->id, 'title' => get_string('share', 'view'), 'weight' => 70);
    }
    if ($role) {
        safe_require('grouptype', $group->grouptype);
        $artefactplugins = call_static_method('GroupType' . $group->grouptype, 'get_group_artefact_plugins');
        if ($plugins = plugins_installed('artefact')) {
            foreach ($plugins as &$plugin) {
                if (!in_array($plugin->name, $artefactplugins)) {
                    continue;
                }
                safe_require('artefact', $plugin->name);
                $plugin_menu = call_static_method(generate_class_name('artefact', $plugin->name), 'group_tabs', $group->id);
                $menu = array_merge($menu, $plugin_menu);
            }
        }
    }
    if (group_role_can_access_report($group, $role)) {
        $menu['report'] = array('path' => 'groups/report', 'url' => 'group/report.php?group=' . $group->id, 'title' => get_string('report', 'group'), 'weight' => 70);
    }
    if (defined('MENUITEM')) {
        $key = substr(MENUITEM, strlen('groups/'));
        if ($key && isset($menu[$key])) {
            $menu[$key]['selected'] = true;
        }
    }
    // Sort the menu items by weight
    uasort($menu, function ($a, $b) {
        // Only items with a "weight" component need to get sorted. Ones without weight can go first.
        if (!array_key_exists('weight', $a)) {
            return -1;
        }
        if (!array_key_exists('weight', $b)) {
            return 1;
        }
        $aweight = $a['weight'];
        $bweight = $b['weight'];
        if ($aweight == $bweight) {
            return 0;
        }
        return $aweight < $bweight ? -1 : 1;
    });
    return $menu;
}
Пример #11
0
function pieform_element_filebrowser_delete(Pieform $form, $element, $artefact)
{
    global $USER;
    $institution = $form->get_property('institution');
    $group = $form->get_property('group');
    try {
        $artefact = artefact_instance_from_id($artefact);
    } catch (ArtefactNotFoundException $e) {
        $parentfolder = $element['folder'] ? $element['folder'] : null;
        $result = array('error' => true, 'message' => get_string('deletingfailed', 'artefact.file'), 'newlist' => pieform_element_filebrowser_build_filelist($form, $element, $parentfolder));
        return $result;
    }
    if (!$USER->can_edit_artefact($artefact)) {
        return array('error' => true, 'message' => get_string('nodeletepermission', 'mahara'));
    }
    if (!$artefact->can_be_deleted()) {
        return array('error' => true, 'message' => get_string('cantbedeleted', 'mahara'));
    }
    $parentfolder = $artefact->get('parent');
    // Remove the skin background and update the skin thumbs
    require_once get_config('libroot') . 'skin.php';
    Skin::remove_background($artefact->get('id'));
    $artefact->delete();
    $result = array('error' => false, 'deleted' => true, 'artefacttype' => $artefact->get('artefacttype'), 'message' => get_string('filethingdeleted', 'artefact.file', get_string($artefact->get('artefacttype'), 'artefact.file') . ' ' . $artefact->get('title')), 'maxuploadsize' => display_size(get_max_upload_size(!$institution && !$group)), 'newlist' => pieform_element_filebrowser_build_filelist($form, $element, $parentfolder));
    if (defined('GROUP')) {
        $group = group_current_group();
        $result['quota'] = $group->quota;
        $result['quotaused'] = $group->quotaused;
    } else {
        $result['quota'] = $USER->get('quota');
        $result['quotaused'] = $USER->get('quotaused');
    }
    return $result;
}
Пример #12
0
define('SECTION_PLUGINTYPE', 'artefact');
define('SECTION_PLUGINNAME', 'internal');
define('SECTION_PAGE', 'notes');
define('TITLE', get_string('Notes', 'artefact.internal'));
$offset = param_integer('offset', 0);
$limit = param_integer('limit', 10);
$baseurl = get_config('wwwroot') . 'artefact/internal/notes.php';
$params = array();
if ($group = param_integer('group', null)) {
    define('MENUITEM', 'groups');
    define('GROUP', $group);
    require_once 'group.php';
    if (!group_user_can_edit_views($group, $USER->get('id'))) {
        throw new AccessDeniedException(get_string('accessdenied', 'error'));
    }
    $groupobj = group_current_group();
    $pageheading = get_string('notesfor', 'artefact.internal', $groupobj->name);
    $where = '"group" = ?';
    $values = array($group);
    $params['group'] = $group;
} else {
    if ($institution = param_alpha('institution', null)) {
        if ($institution == 'mahara') {
            define('ADMIN', 1);
            define('MENUITEM', 'configsite');
            $pageheading = get_string('Notes', 'artefact.internal');
        } else {
            define('INSTITUTIONALADMIN', 1);
            define('MENUITEM', 'manageinstitutions');
            require_once 'institution.php';
            $institutionobj = new Institution($institution);
Пример #13
0
/**
 * creates the group sideblock
 */
function group_sideblock()
{
    require_once 'group.php';
    $data['group'] = group_current_group();
    if (!$data['group']) {
        return null;
    }
    $data['menu'] = group_get_menu_tabs();
    // @todo either: remove this if interactions become group
    // artefacts, or: do this in interaction/lib.php if we leave them
    // as interactions
    $data['forums'] = get_records_select_array('interaction_instance', '"group" = ? AND deleted = ? AND plugin = ?', array(GROUP, 0, 'forum'), 'ctime', 'id, plugin, title');
    if (!$data['forums']) {
        $data['forums'] = array();
    } else {
        safe_require('interaction', 'forum');
        $data['forums'] = PluginInteractionForum::sideblock_sort($data['forums']);
    }
    return $data;
}
Пример #14
0
 public function render_exception()
 {
     global $USER, $SESSION;
     if (defined('GROUP') && $USER->is_logged_in()) {
         $roles = $USER->get('grouproles');
         if (!isset($roles[GROUP])) {
             $group = group_current_group();
             if ($group->jointype == 'open' || $group->jointype == 'invite' && get_record('group_member_invite', 'group', GROUP, 'member', $USER->get('id'))) {
                 $SESSION->add_error_msg(get_string('notmembermayjoin', 'group', $group->name));
                 $next = substr($_SERVER['REQUEST_URI'], strlen(get_mahara_install_subdirectory()) - 1);
                 redirect(get_config('wwwroot') . 'group/view.php?id=' . GROUP . '&next=' . urlencode($next));
             }
             if ($group->jointype == 'request' && !get_record('group_member_request', 'group', GROUP, 'member', $USER->get('id'))) {
                 $SESSION->add_error_msg(get_string('notamember', 'group'));
                 redirect(get_config('wwwroot') . 'group/requestjoin.php?id=' . GROUP . '&returnto=view');
             }
         }
     }
     header("HTTP/1.0 403 Forbidden", true);
     return parent::render_exception();
 }
Пример #15
0
 protected static function get_data($groupid)
 {
     global $USER;
     if (!defined('GROUP')) {
         define('GROUP', $groupid);
     }
     // get the currently requested group
     $group = group_current_group();
     $role = group_user_access($group->id);
     if ($role) {
         // For group members, display a list of views that others have
         // shared to the group
         $data['sharedviews'] = View::get_sharedviews_data(null, 0, $group->id);
         if (group_user_can_assess_submitted_views($group->id, $USER->get('id'))) {
             // Display a list of views submitted to the group
             $data['allsubmittedviews'] = View::get_submitted_views($group->id);
         }
     }
     if (group_allows_submission($group->grouptype) && ($userviewdata = View::get_user_views())) {
         // A user can submit more than one view to the same group, but no view can be
         // submitted to more than one group.
         // Display a list of views this user has submitted to this group, and a submission
         // form containing drop-down of their unsubmitted views.
         $data['mysubmittedviews'] = View::get_submitted_views($group->id, $USER->get('id'));
         if (!empty($data['mysubmittedviews'])) {
             foreach ($data['mysubmittedviews'] as &$v) {
                 $url = get_config('wwwroot') . 'view/view.php?id=' . $v['id'];
                 if ($v['submittedtime']) {
                     $v['strsubmitted'] = get_string('youhavesubmittedon', 'view', $url, $v['title'], format_date($v['submittedtime']));
                 } else {
                     $v['strsubmitted'] = get_string('youhavesubmitted', 'view', $url, $v['title']);
                 }
             }
         }
         $data['group_view_submission_form'] = group_view_submission_form($group->id, $userviewdata);
     }
     $data['group'] = $group;
     return $data;
 }
Пример #16
0
 protected static function get_data($groupid, $editing = false)
 {
     global $USER;
     if (!defined('GROUP')) {
         define('GROUP', $groupid);
     }
     // get the currently requested group
     $group = group_current_group();
     $role = group_user_access($group->id);
     $bi = group_get_homepage_view_groupview_block($group->id);
     $configdata = $bi->get('configdata');
     if (!isset($configdata['sortsubmittedby']) || $configdata['sortsubmittedby'] == PluginBlocktypeGroupViews::SORTBY_TITLE) {
         $sortsubmittedby = 'c.name, v.title';
     } else {
         $sortsubmittedby = 'c.submittedtime DESC, v.submittedtime DESC';
     }
     if ($role) {
         $limit = isset($configdata['count']) ? intval($configdata['count']) : 5;
         $limit = $limit > 0 ? $limit : 5;
         // Get all views created in the group
         // Sortorder: Group homepage should be first, then sort by sortorder
         $sort = array(array('column' => "type='grouphomepage'", 'desc' => true));
         // Find out what order to sort them by (default is titles)
         if (!isset($configdata['sortgroupviewsby']) || $configdata['sortgroupviewsby'] == PluginBlocktypeGroupViews::SORTBY_TITLE) {
             $sort[] = array('column' => 'title');
         } else {
             $sort[] = array('column' => 'mtime', 'desc' => true);
         }
         $data['groupviews'] = View::view_search(null, null, (object) array('group' => $group->id), null, $limit, 0, true, $sort);
         foreach ($data['groupviews']->data as &$view) {
             if (!$editing && isset($view['template']) && $view['template']) {
                 $view['form'] = pieform(create_view_form(null, null, $view['id']));
             }
         }
         // Find out what order to sort them by (default is titles)
         if (!isset($configdata['sortsharedviewsby']) || $configdata['sortsharedviewsby'] == PluginBlocktypeGroupViews::SORTBY_TITLE) {
             $sortsharedviewsby = 'v.title';
             $sortsharedcollectionsby = array(array('column' => 'c.name'));
         } else {
             $sortsharedviewsby = 'v.mtime DESC';
             $sortsharedcollectionsby = array(array('column' => 'GREATEST(c.mtime, (SELECT MAX(v.mtime) FROM {view} v INNER JOIN {collection_view} cv ON v.id=cv.view WHERE cv.collection=c.id))', 'desc' => true));
         }
         // For group members, display a list of views that others have
         // shared to the group
         if (empty($configdata['showsharedviews'])) {
             $data['sharedviews'] = (object) array('data' => array(), 'count' => 0, 'limit' => $limit, 'offset' => 0);
         } else {
             $data['sharedviews'] = View::get_sharedviews_data($limit, 0, $group->id, $configdata['showsharedviews'] == 2 ? false : true, $sortsharedviewsby);
             foreach ($data['sharedviews']->data as &$view) {
                 if (!$editing && isset($view['template']) && $view['template']) {
                     $view['form'] = pieform(create_view_form($group, null, $view->id));
                 }
             }
         }
         if (empty($configdata['showsharedcollections'])) {
             $data['sharedcollections'] = (object) array('data' => array(), 'count' => 0, 'limit' => $limit, 'offset' => 0);
         } else {
             $data['sharedcollections'] = View::get_sharedcollections_data($limit, 0, $group->id, $configdata['showsharedcollections'] == 2 ? false : true, $sortsharedcollectionsby);
         }
         if (group_user_can_assess_submitted_views($group->id, $USER->get('id'))) {
             // Display a list of views submitted to the group
             list($collections, $views) = View::get_views_and_collections(null, null, null, null, false, $group->id, $sortsubmittedby);
             $allsubmitted = array_merge(array_values($collections), array_values($views));
             $data['allsubmitted'] = array('data' => array_slice($allsubmitted, 0, $limit), 'count' => count($allsubmitted), 'limit' => $limit, 'offset' => 0);
         }
     }
     if ($group->submittableto) {
         require_once 'pieforms/pieform.php';
         // A user can submit more than one view to the same group, but no view can be
         // submitted to more than one group.
         // Display a list of views this user has submitted to this group, and a submission
         // form containing drop-down of their unsubmitted views.
         list($collections, $views) = View::get_views_and_collections($USER->get('id'), null, null, null, false, $group->id, $sortsubmittedby);
         $data['mysubmitted'] = array_merge(array_values($collections), array_values($views));
         // Only render the submission form in viewing mode
         if (!$editing) {
             $data['group_view_submission_form'] = group_view_submission_form($group->id);
         }
     }
     $data['group'] = $group;
     return $data;
 }
Пример #17
0
 public function render_exception()
 {
     global $USER, $SESSION;
     if (defined('GROUP') && $USER->is_logged_in()) {
         $roles = $USER->get('grouproles');
         if (!isset($roles[GROUP])) {
             $group = group_current_group();
             if ($group->jointype == 'open' || get_record('group_member_invite', 'group', GROUP, 'member', $USER->get('id'))) {
                 $message = get_string('notmembermayjoin', 'group', $group->name);
                 // Error code equals 1 if we have objection=1 in url
                 if ($this->getCode() == '1') {
                     $message .= ' ' . get_string('accessdeniedobjection', 'error');
                 }
                 $SESSION->add_error_msg($message);
                 $next = substr($_SERVER['REQUEST_URI'], strlen(get_mahara_install_subdirectory()) - 1);
                 $goto = group_homepage_url($group);
                 $goto .= (strpos($goto, '?') ? '&' : '?') . 'next=' . urlencode($next);
                 redirect($goto);
             }
             if ($group->request && !get_record('group_member_request', 'group', GROUP, 'member', $USER->get('id'))) {
                 $SESSION->add_error_msg(get_string('notamember', 'group'));
                 redirect(get_config('wwwroot') . 'group/requestjoin.php?id=' . GROUP . '&returnto=view');
             }
         }
     }
     header("HTTP/1.0 403 Forbidden", true);
     return parent::render_exception();
 }
Пример #18
0
 protected static function get_data($groupid, $editing = false)
 {
     global $USER;
     if (!defined('GROUP')) {
         define('GROUP', $groupid);
     }
     // get the currently requested group
     $group = group_current_group();
     $role = group_user_access($group->id);
     if ($role) {
         $bi = group_get_homepage_view_groupview_block($group->id);
         $configdata = $bi->get('configdata');
         $limit = isset($configdata['count']) ? intval($configdata['count']) : 5;
         $limit = $limit > 0 ? $limit : 5;
         // Get all views created in the group
         $sort = array(array('column' => 'type=\'grouphomepage\'', 'desc' => true));
         $data['groupviews'] = View::view_search(null, null, (object) array('group' => $group->id), null, $limit, 0, true, $sort);
         foreach ($data['groupviews']->data as &$view) {
             if (!$editing && isset($view['template']) && $view['template']) {
                 $view['form'] = pieform(create_view_form(null, null, $view['id']));
             }
         }
         // For group members, display a list of views that others have
         // shared to the group
         $data['sharedviews'] = View::get_sharedviews_data($limit, 0, $group->id);
         foreach ($data['sharedviews']->data as &$view) {
             if (!$editing && isset($view['template']) && $view['template']) {
                 $view['form'] = pieform(create_view_form($group, null, $view->id));
             }
         }
         $data['sharedcollections'] = View::get_sharedcollections_data($limit, 0, $group->id);
         if (group_user_can_assess_submitted_views($group->id, $USER->get('id'))) {
             // Display a list of views submitted to the group
             list($collections, $views) = View::get_views_and_collections(null, null, null, null, false, $group->id);
             $allsubmitted = array_merge(array_values($collections), array_values($views));
             $data['allsubmitted'] = array('data' => array_slice($allsubmitted, 0, $limit), 'count' => count($allsubmitted), 'limit' => $limit, 'offset' => 0);
         }
     }
     if ($group->submittableto) {
         require_once 'pieforms/pieform.php';
         // A user can submit more than one view to the same group, but no view can be
         // submitted to more than one group.
         // Display a list of views this user has submitted to this group, and a submission
         // form containing drop-down of their unsubmitted views.
         list($collections, $views) = View::get_views_and_collections($USER->get('id'), null, null, null, false, $group->id);
         $data['mysubmitted'] = array_merge(array_values($collections), array_values($views));
         // Only render the submission form in viewing mode
         if (!$editing) {
             $data['group_view_submission_form'] = group_view_submission_form($group->id);
         }
     }
     $data['group'] = $group;
     return $data;
 }
Пример #19
0
    $id = param_integer('id');
    $collection = new Collection($id);
    $owner = $collection->get('owner');
    $groupid = $collection->get('group');
    $institutionname = $collection->get('institution');
    define('SUBTITLE', $collection->get('name') . ': ' . get_string('edittitleanddesc', 'collection'));
}
if ($collection->is_submitted()) {
    $submitinfo = $collection->submitted_to();
    throw new AccessDeniedException(get_string('canteditsubmitted', 'collection', $submitinfo->name));
}
$urlparams = array();
if (!empty($groupid)) {
    define('MENUITEM', 'groups/collections');
    define('GROUP', $groupid);
    $group = group_current_group();
    define('TITLE', $group->name . ' - ' . get_string('editcollection', 'collection'));
    $urlparams['group'] = $groupid;
} else {
    if (!empty($institutionname)) {
        if ($institutionname == 'mahara') {
            define('ADMIN', 1);
            define('MENUITEM', 'configsite/collections');
        } else {
            define('INSTITUTIONALADMIN', 1);
            define('MENUITEM', 'manageinstitutions/institutioncollections');
        }
        define('TITLE', get_string('editcollection', 'collection'));
        $urlparams['institution'] = $institutionname;
    } else {
        define('MENUITEM', 'myportfolio/collection');
Пример #20
0
 /** Code copied from blocktype::groupviews **/
 public static function get_data($groupid, $offset = 0, $limit = 20)
 {
     global $USER;
     $texttitletrim = 20;
     $items2 = null;
     if (!defined('GROUP')) {
         define('GROUP', $groupid);
     }
     // get the currently requested group
     $group = group_current_group();
     $role = group_user_access($group->id);
     if ($role) {
         // For group members, display a list of views that others have shared to the group
         // Params for get_sharedviews_data is $limit=0,$offset=0, $groupid
         $data['sharedviews'] = View::get_sharedviews_data($limit, $offset, $group->id);
         /*
         foreach ($data['sharedviews']->data as &$view) {
         	if (isset($view['template']) && $view['template']) {
         		$view['form'] = pieform(create_view_form($group, null, $view->id));
         	}				
                     }
         */
         //the array that is returned from View::get_sharedviews_data($limit, $offset, $group->id)
         //contains a few other things but we just wanted to focus on sharedviews
         //the foreach below will loop through all views shared with the group
         foreach ($data['sharedviews'] as $aView) {
             if (is_array($aView)) {
                 //20140909 JW sort the array returned by View::get_sharedviews_data($limit, $offset, $group->id)
                 //by ctime, this requires the query within get_sharedviews_data to have ctime in its select string
                 $aView = self::array_msort($aView, array('ctime' => SORT_DESC));
                 //the foreach below will loop through all the properties for a view (returned by get_data method) and assigns them to the required variables
                 foreach ($aView as $aViewProperty) {
                     //get the view
                     $viewID = $aViewProperty['id'];
                     //the page shared
                     $fullurl = $aViewProperty['fullurl'];
                     //full url of the page shared
                     $viewTitle = str_shorten_text($aViewProperty['displaytitle'], $texttitletrim, true);
                     //view's title
                     //get the owner of the view
                     $viewOwnerName = $aViewProperty['user']->firstname . " " . $aViewProperty['user']->lastname;
                     //owner of the view's name
                     $userobj = new User();
                     $userobj->find_by_id($aViewProperty['user']->id);
                     $profileurl = profile_url($userobj);
                     //owner of the view's proflie page
                     $avatarurl = profile_icon_url($aViewProperty['user']->id, 50, 50);
                     //owner of the view's profile picture
                     //get the artefact id of an image in the view
                     $theView = new View($aViewProperty['id']);
                     //create the view
                     $artefactInView = $theView->get_artefact_metadata();
                     //get all artefacts in the view
                     foreach ($artefactInView as $anArtefact) {
                         //for each artefact
                         if ($anArtefact->artefacttype == 'image') {
                             $artefactID = $anArtefact->id;
                             //if it is an image artefact assign the id and break the loop
                             break;
                         }
                         //20150331 JW added that if page contains a folder with images (galleries count as folders)
                         //it will pull an image from that folder and use it as the cover
                         if ($anArtefact->artefacttype == 'folder') {
                             $query = "SELECT id FROM {artefact} where parent = ? AND artefacttype = 'image'";
                             $imagesInAFolder = get_records_sql_array($query, array($anArtefact->id));
                             //only assign the id of an image if the folder contains at least 1 image
                             if (!empty($imagesInAFolder)) {
                                 $artefactID = $imagesInAFolder[0]->id;
                                 break;
                             }
                         }
                         //20140903 JW if there are no images on the page then set to artefactID to 0
                         //this way, when display each page, instead of a blank box it will show a place holder image
                         $artefactID = 0;
                     }
                     //the items variable below requires the contents array to be in this format
                     $contents['photos'][] = array("image" => array("id" => $artefactID, "view" => $viewID), "type" => "photo", "page" => array("url" => $fullurl, "title" => $viewTitle), "owner" => array("name" => $viewOwnerName, "profileurl" => $profileurl, "avatarurl" => $avatarurl));
                 }
             }
         }
         //20150723 JW added the if statement to check if $content is set, if not then skip
         if (isset($contents)) {
             $items2 = array('count' => $data['sharedviews']->count, 'data' => $contents, 'offset' => $offset, 'limit' => $limit);
         }
     }
     //$data['group'] = $group;
     return $items2;
 }