Browse Source

Fixing code highlight see BT#8764

Julio Montoya 10 years ago
parent
commit
a6c90d1691
3 changed files with 49 additions and 20 deletions
  1. 6 2
      main/chat/chat_functions.lib.php
  2. 14 16
      main/chat/header_frame.inc.php
  3. 29 2
      main/document/showinframes.php

+ 6 - 2
main/chat/chat_functions.lib.php

@@ -143,7 +143,7 @@ function saveMessage($message, $userId, $_course, $session_id, $group_id, $previ
     }
 
     $date_now = date('Y-m-d');
-    $message = Security::remove_XSS(trim($message));
+    $message = trim($message);
     $timeNow = date('d/m/y H:i:s');
 
     if (!empty($group_id)) {
@@ -156,12 +156,16 @@ function saveMessage($message, $userId, $_course, $session_id, $group_id, $previ
 
     if (!api_is_anonymous()) {
         if (!empty($message)) {
-
             Emojione\Emojione::$imagePathPNG = api_get_path(WEB_LIBRARY_PATH).'javascript/emojione/png/';
             Emojione\Emojione::$imagePathSVG = api_get_path(WEB_LIBRARY_PATH).'javascript/emojione/svg/';
             Emojione\Emojione::$ascii = true;
+
+            // Parsing emojis
             $message = Emojione\Emojione::toImage($message);
+            // Parsing text to understand markdown (code highlight)
             $message = MarkdownExtra::defaultTransform($message);
+            // Security XSS
+            $message = Security::remove_XSS($message);
 
             if ($preview == true) {
                 return $message;

+ 14 - 16
main/chat/header_frame.inc.php

@@ -105,8 +105,9 @@ $iconNameToInclude = array(
     ':neutral_face:',
     ':no_mouth:',
     ':innocent:',
-    'alien:',
+    ':alien:',
 );
+
 foreach ($icons as $key => $icon) {
     if (in_array($key, $iconNameToInclude)) {
         $iconList[$key] = strtoupper($icon) . '.png';
@@ -129,7 +130,6 @@ header('Content-Type: text/html; charset='.api_get_system_encoding());
 <link rel="stylesheet" type="text/css" href="<?php echo api_get_path(WEB_LIBRARY_PATH); ?>javascript/jquery-textcomplete/jquery.textcomplete.css">
 <link rel="stylesheet" type="text/css" href="<?php echo api_get_path(WEB_LIBRARY_PATH); ?>javascript/emojione/css/emojione.min.css">
 <link rel="stylesheet" type="text/css" href="<?php echo api_get_path(WEB_LIBRARY_PATH); ?>javascript/emojione/css/autocomplete.css">
-
 <link rel="stylesheet" type="text/css" href="<?php echo api_get_path(WEB_LIBRARY_PATH); ?>javascript/highlight/styles/github.css">
 <?php echo api_get_js('jquery.min.js'); ?>
 <?php echo api_get_js('bootstrap/bootstrap.js'); ?>
@@ -159,14 +159,7 @@ header('Content-Type: text/html; charset='.api_get_system_encoding());
         $.emojiarea.icons = <?php echo $icons ?>;
 
         $('#preview').on('click', function() {
-            //var message = $('textarea').html();
             var params = $('#formMessage').serialize();
-            /*
-            console.log(params2);
-            var message = $('textarea').emojiarea().html()
-            console.log(message);
-            var params= 'message=' + message;
-*/
             $.ajax({
                 url: url + '&' + params,
                 success: function (data) {
@@ -186,7 +179,6 @@ header('Content-Type: text/html; charset='.api_get_system_encoding());
         });
 
         $('textarea').emojiarea({button: '#emojis'});
-
         $("textarea").textcomplete([ {
             match: /\B:([\-+\w]*)$/,
             search: function (term, callback) {
@@ -229,28 +221,33 @@ header('Content-Type: text/html; charset='.api_get_system_encoding());
 		$('#user-online-scroll').tinyscrollbar();
 	});
 
-	function play_notification() {
+	function play_notification()
+    {
 		document.getElementById('audio').play();
 	}
 
-	function updateChat(){
+	function updateChat()
+    {
 		if ('<?php echo $chat_size_old; ?>' != '<?php echo $chat_size_new; ?>') {
 			parent.chat_chat.location.href='chat_chat.php?size=<?php echo $chat_size_new.'&'.api_get_cidreq(); ?>#bottom';
 			play_notification();
 		}
 	}
 
-	function updateConnected(){
+	function updateConnected()
+    {
 		if ('<?php echo $connected_old; ?>' != '<?php echo $connected_new; ?>'){
 			parent.chat_whoisonline.location.href='chat_whoisonline.php?size=<?php echo $connected_new; ?>';
 		}
 	}
 
-	function submitHiddenForm(){
+	function submitHiddenForm()
+    {
 		document.formHidden.submit();
 	}
 
-	function eventMessage(){
+	function eventMessage()
+    {
 		<?php if (isset($chat_size) && $chat_size): ?>
 		parent.chat_hidden.document.formHidden.chat_size_old.value='<?php echo $chat_size; ?>';
 		parent.chat_chat.location.href='chat_chat.php?size=<?php echo $chat_size.'&'.api_get_cidreq(); ?>#bottom';
@@ -258,7 +255,8 @@ header('Content-Type: text/html; charset='.api_get_system_encoding());
 		document.formMessage.message.focus();
 	}
 
-	function send_message(keyEvent) {
+	function send_message(keyEvent)
+    {
 		for (prop in keyEvent) {
 			if(prop == 'which') key = keyEvent.which; else key = keyEvent.keyCode;
 		}

+ 29 - 2
main/document/showinframes.php

@@ -162,6 +162,7 @@ if ($is_courseAdmin) {
     $frameheight = 165;
 }
 $js_glossary_in_documents = '';
+
 if (api_get_setting('show_glossary_in_documents') == 'ismanual') {
     $js_glossary_in_documents = '	//	    $(document).ready(function() {
                                     $.frameReady(function() {
@@ -216,7 +217,7 @@ if (in_array(strtolower($pathinfo['extension']), $web_odf_supported_files)) {
   </script>';
     */
     $htmlHeadXtra[] = '
-    <script charset="utf-8">
+    <script>
         resizeIframe = function() {
             var bodyHeight = $("body").height();
             var topbarHeight = $("#topbar").height();
@@ -229,6 +230,26 @@ if (in_array(strtolower($pathinfo['extension']), $web_odf_supported_files)) {
     ;
 }
 
+// Activate code highlight.
+$isChatFolder = false;
+if (isset($document_data['parents']) && isset($document_data['parents'][0])) {
+    $chatFolder = $document_data['parents'][0];
+    if (isset($chatFolder['path']) && $chatFolder['path'] == '/chat_files') {
+        $isChatFolder = true;
+    }
+}
+
+if ($isChatFolder) {
+    $htmlHeadXtra[] = api_get_js('highlight/highlight.pack.js');
+    $htmlHeadXtra[] = api_get_css(
+        api_get_path(WEB_LIBRARY_PATH) . 'javascript/highlight/styles/github.css'
+    );
+    $htmlHeadXtra[] = '
+    <script>
+        hljs.initHighlightingOnLoad();
+    </script>';
+}
+
 $execute_iframe = true;
 
 if ($jplayer_supported) {
@@ -297,6 +318,7 @@ if (!$jplayer_supported && $execute_iframe) {
         window.onload = function() {
             updateContentHeight();
             '.$js_glossary_in_documents.'
+
         }
     </script>';
 }
@@ -410,6 +432,11 @@ if ($is_nanogong_available) {
 }
 
 if ($execute_iframe) {
-    echo '<iframe id="mainFrame" name="mainFrame" border="0" frameborder="0" scrolling="no" style="width:100%;" height="600" src="'.$file_url_web.'&amp;rand='.mt_rand(1, 10000).'" height="500"></iframe>';
+    if ($isChatFolder) {
+        $content = Security::remove_XSS(file_get_contents($file_url_sys));
+        echo $content;
+    } else {
+        echo '<iframe id="mainFrame" name="mainFrame" border="0" frameborder="0" scrolling="no" style="width:100%;" height="600" src="'.$file_url_web.'&amp;rand='.mt_rand(1, 10000).'" height="500"></iframe>';
+    }
 }
 Display::display_footer();