/** * @brief 에디터 컴포넌트가 별도의 고유 코드를 이용한다면 그 코드를 html로 변경하여 주는 method **/ function transHTML($xml_obj) { $script_path = getScriptPath() . 'modules/editor/components/code_highlighter/syntaxhighlighter/scripts/'; $code_type = ucfirst($xml_obj->attrs->code_type); $option_title = ' title="' . $xml_obj->attrs->title . '"'; $option_first_line = $xml_obj->attrs->first_line; $option_collapse = $xml_obj->attrs->collapse; $option_nogutter = $xml_obj->attrs->nogutter; $option_highlight = $xml_obj->attrs->highlight; $option[] = 'brush:' . strtolower($code_type); if (in_array($option_collapse, array('true', 'checked', 'Y'))) { $option[] = 'collapse:true'; } if (in_array($option_nogutter, array('true', 'checked', 'Y'))) { $option[] = 'gutter:false'; } if ($option_highlight) { $option[] = 'highlight:[' . $option_highlight . ']'; } if ($option_first_line > 1) { $option[] = 'first-line:' . $option_first_line; } $body = $xml_obj->body; $body = strip_tags($body, '<br>'); $body = preg_replace("/(<br\\s*\\/?>)(\n|\r)*/i", "\n", $body); $body = strip_tags($body); $body = str_replace(' ', ' ', $body); if (!$GLOBALS['_called_editor_component_code_highlighter_']) { $GLOBALS['_called_editor_component_code_highlighter_'] = true; foreach ($this->brushes as $item) { $brush[] = '"' . $item[2] . ' ' . $script_path . 'shBrush' . $item[1] . '.js"'; } $sh_js_code[] = '<script type="text/javascript">'; $sh_js_code[] = 'window.SyntaxHighlighter.autoloader('; $sh_js_code[] = implode(',' . PHP_EOL, $brush); $sh_js_code[] = ');'; $sh_js_code[] = 'window.SyntaxHighlighter.config.bloggerMode = true;'; $sh_js_code[] = 'window.SyntaxHighlighter.all();'; $sh_js_code[] = '</script>'; if (!$this->theme) { $this->theme = 'Default'; } $theme_file = $this->component_path . 'syntaxhighlighter/styles/shCore' . $this->theme . '.css'; if (!file_exists($theme_file)) { $theme_file = $this->component_path . 'syntaxhighlighter/styles/shCoreDjango.css'; } Context::set('script_path', $script_path); Context::addHtmlFooter(implode(PHP_EOL, $sh_js_code)); Context::addCSSFile($theme_file); Context::addJsFile($script_path . 'shCore.js'); Context::addJsFile($script_path . 'shAutoloader.js'); } $output = sprintf('<pre class="%s" %s>%s</pre>', implode(';', $option), $option_title, $body); return $output; }
/** * Return after removing an argument on the requested URL * * @param string $ssl_mode SSL mode * @param string $domain Domain * @retrun string converted URL */ function getRequestUri($ssl_mode = FOLLOW_REQUEST_SSL, $domain = null) { static $url = array(); // Check HTTP Request if (!isset($_SERVER['SERVER_PROTOCOL'])) { return; } if (self::get('_use_ssl') == 'always') { $ssl_mode = ENFORCE_SSL; } if ($domain) { $domain_key = md5($domain); } else { $domain_key = 'default'; } if (isset($url[$ssl_mode][$domain_key])) { return $url[$ssl_mode][$domain_key]; } $current_use_ssl = $_SERVER['HTTPS'] == 'on'; switch ($ssl_mode) { case FOLLOW_REQUEST_SSL: $use_ssl = $current_use_ssl; break; case ENFORCE_SSL: $use_ssl = TRUE; break; case RELEASE_SSL: $use_ssl = FALSE; break; } if ($domain) { $target_url = trim($domain); if (substr_compare($target_url, '/', -1) !== 0) { $target_url .= '/'; } } else { $target_url = $_SERVER['HTTP_HOST'] . getScriptPath(); } $url_info = parse_url('http://' . $target_url); if ($current_use_ssl != $use_ssl) { unset($url_info['port']); } if ($use_ssl) { $port = self::get('_https_port'); if ($port && $port != 443) { $url_info['port'] = $port; } elseif ($url_info['port'] == 443) { unset($url_info['port']); } } else { $port = self::get('_http_port'); if ($port && $port != 80) { $url_info['port'] = $port; } elseif ($url_info['port'] == 80) { unset($url_info['port']); } } $url[$ssl_mode][$domain_key] = sprintf('%s://%s%s%s', $use_ssl ? 'https' : $url_info['scheme'], $url_info['host'], $url_info['port'] && $url_info['port'] != 80 ? ':' . $url_info['port'] : '', $url_info['path']); return $url[$ssl_mode][$domain_key]; }
/** * Handle launch and/or set up the LTI session and global variables * * Make sure we have the values we need in the LTI session * This routine will not start a session if none exists. It will * die is there if no session_name() (PHPSESSID) cookie or * parameter. No need to create any fresh sessions here. * * @param $needed (optional, mixed) Indicates which of * the data structures are * needed. If this is omitted, * this assumes that CONTEXT, LINK, and USER data are required. * If LTIX::NONE is present, then none of the three are rquired. * If some combination of the three are needed, this accepts * an array of the LTIX::CONTEXT, LTIX: LINK, and LTIX::USER * can be passed in. * */ public static function requireData($needed = self::ALL) { global $CFG, $USER, $CONTEXT, $LINK; if ($needed == self::NONE) { $needed = array(); } if ($needed == self::ALL) { $needed = array(self::CONTEXT, self::LINK, self::USER); } if (is_string($needed)) { $needed = array($needed); } // Check if we are processing an LTI launch. If so, handle it self::launchCheck(); // Check to see if the session already exists. $sess = session_name(); if (ini_get('session.use_cookies') != '0') { if (!isset($_COOKIE[$sess])) { send403(); die_with_error_log("Missing session cookie - please re-launch"); } } else { // non-cookie session if (isset($_POST[$sess]) || isset($_GET[$sess])) { // We tried to set a session.. } else { if ($_SERVER['REQUEST_METHOD'] == 'POST') { send403(); die_with_error_log('Missing ' . $sess . ' from POST data'); } else { send403(); die_with_error_log('This tool should be launched from a learning system using LTI'); } } } // Start a session if it has not been started.. if (session_id() == "") { session_start(); // Should reassociate } // This happens from time to time when someone closes and reopens a laptop // Or their computer goes to sleep and wakes back up hours later. // So it is just a warning - nothing much we can do except tell them. if (!isset($_SESSION['lti'])) { // $debug = safe_var_dump($_SESSION); // error_log($debug); send403(); error_log('Session expired - please re-launch ' . session_id()); die('Session expired - please re-launch'); // with error_log } // Check the referrer... $trusted = checkReferer() || checkCSRF(); // Check to see if we switched browsers or IP addresses // TODO: Change these to warnings once we get more data if (!$trusted && isset($_SESSION['HTTP_USER_AGENT'])) { if (!isset($_SERVER['HTTP_USER_AGENT']) || $_SESSION['HTTP_USER_AGENT'] != $_SERVER['HTTP_USER_AGENT']) { send403(); die_with_error_log("Session has expired", " " . session_id() . " HTTP_USER_AGENT " . $_SESSION['HTTP_USER_AGENT'] . ' ::: ' . isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : 'Empty user agent', 'DIE:'); } } // We only check the first three octets as some systems wander throught the addresses on // class C - Perhaps it is even NAT - who knows - but we forgive those on the same Class C if (!$trusted && isset($_SESSION['REMOTE_ADDR']) && isset($_SERVER['REMOTE_ADDR'])) { $sess_pieces = explode('.', $_SESSION['REMOTE_ADDR']); $serv_pieces = explode('.', $_SERVER['REMOTE_ADDR']); if (count($sess_pieces) == 4 && count($serv_pieces) == 4) { if ($sess_pieces[0] != $serv_pieces[0] || $sess_pieces[1] != $serv_pieces[1] || $sess_pieces[2] != $serv_pieces[2]) { send403(); die_with_error_log('Session address has expired', " " . session_id() . " REMOTE_ADDR " . $_SESSION['REMOTE_ADDR'] . ' ' . $_SERVER['REMOTE_ADDR'], 'DIE:'); } } } // Check to see if the user has navigated to a new place in the hierarchy if (isset($_SESSION['script_path']) && getScriptPath() != 'core/blob' && strpos(getScriptPath(), $_SESSION['script_path']) !== 0) { send403(); die_with_error_log('Improper navigation detected', " " . session_id() . " script_path " . $_SESSION['script_path'] . ' / ' . getScriptPath(), 'DIE:'); } $LTI = $_SESSION['lti']; if (is_array($needed)) { foreach ($needed as $feature) { if (isset($LTI[$feature])) { continue; } die_with_error_log("This tool requires an LTI launch parameter:" . $feature); } } // Check to see if the session needs to be extended due to this request checkHeartBeat(); // Restart the number of continuous heartbeats $_SESSION['HEARTBEAT_COUNT'] = 0; // Populate the $USER $CONTEXT and $LINK objects if (isset($LTI['user_id']) && !is_object($USER)) { $USER = new \Tsugi\Core\User(); $USER->id = $LTI['user_id']; if (isset($LTI['user_email'])) { $USER->email = $LTI['user_email']; } if (isset($LTI['user_displayname'])) { $USER->displayname = $LTI['user_displayname']; $pieces = explode(' ', $USER->displayname); if (count($pieces) > 0) { $USER->firstname = $pieces[0]; } if (count($pieces) > 1) { $USER->lastname = $pieces[count($pieces) - 1]; } } $USER->instructor = isset($LTI['role']) && $LTI['role'] != 0; } if (isset($LTI['context_id']) && !is_object($CONTEXT)) { $CONTEXT = new \Tsugi\Core\Context(); $CONTEXT->id = $LTI['context_id']; if (isset($LTI['context_title'])) { $CONTEXT->title = $LTI['context_title']; } } if (isset($LTI['link_id']) && !is_object($LINK)) { $LINK = new \Tsugi\Core\Link(); $LINK->id = $LTI['link_id']; if (isset($LTI['grade'])) { $LINK->grade = $LTI['grade']; } if (isset($LTI['link_title'])) { $LINK->title = $LTI['link_title']; } if (isset($LTI['result_id'])) { $LINK->result_id = $LTI['result_id']; } } // Return the LTI structure return $LTI; }
/** * Get abstract file url * * @deprecated * @param string $file file path * @return string Converted file path */ function getAbsFileUrl($file) { $file = self::normalizeFilePath($file); $script_path = getScriptPath(); if (strpos($file, './') === 0) { $file = $script_path . substr($file, 2); } elseif (strpos($file, '../') === 0) { $file = self::normalizeFilePath($script_path . $file); } return $file; }
/** * constructor * @return void */ public function __construct() { $this->xe_path = rtrim(getScriptPath(), '/'); $this->compiled_path = _XE_PATH_ . $this->compiled_path; }
/** * Get absolute file url * * @param string $path Path to get absolute url * @return string Absolute url */ function _getAbsFileUrl($path) { $path = $this->_normalizeFilePath($path); $script_path = getScriptPath(); if (strpos($path, './') === 0) { if ($script_path == '/' || $script_path == '\\') { $path = '/' . substr($path, 2); } else { $path = $script_path . substr($path, 2); } } else { if (strpos($file, '../') === 0) { $path = $this->_normalizeFilePath($script_path . $path); } } return $path; }
/** * @brief 요청이 들어온 URL에서 argument를 제거하여 return **/ function getRequestUri($ssl_mode = FOLLOW_REQUEST_SSL, $domain = null) { static $url = array(); // HTTP Request가 아니면 패스 if (!isset($_SERVER['SERVER_PROTOCOL'])) { return; } if (Context::get('_use_ssl') == "always") { $ssl_mode = ENFORCE_SSL; } if ($domain) { $domain_key = md5($domain); } else { $domain_key = 'default'; } if (isset($url[$ssl_mode][$domain_key])) { return $url[$ssl_mode][$domain_key]; } switch ($ssl_mode) { case FOLLOW_REQUEST_SSL: if ($_SERVER['HTTPS'] == 'on') { $use_ssl = true; } else { $use_ssl = false; } break; case ENFORCE_SSL: $use_ssl = true; break; case RELEASE_SSL: $use_ssl = false; break; } if ($domain) { $target_url = trim($domain); if (substr($target_url, -1) != '/') { $target_url .= '/'; } } else { $target_url = $_SERVER['HTTP_HOST'] . getScriptPath(); } $url_info = parse_url('http://' . $target_url); if ($use_ssl) { if (Context::get("_https_port") && Context::get("_https_port") != 443) { $url_info['port'] = Context::get("_https_port"); } else { unset($url_info['port']); } } else { if (Context::get("_http_port") && Context::get("_http_port") != 80) { $url_info['port'] = Context::get("_http_port"); } elseif ($url_info['port'] == 80) { unset($url_info['port']); } } $url[$ssl_mode][$domain_key] = sprintf("%s://%s%s%s", $use_ssl ? 'https' : $url_info['scheme'], $url_info['host'], $url_info['port'] && $url_info['port'] != 80 ? ':' . $url_info['port'] : '', $url_info['path']); return $url[$ssl_mode][$domain_key]; }