/** * 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; }
/** * 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; }