Browse Source

Fix glossary automatic due recent Symfony2 changes

jmontoyaa 9 years ago
parent
commit
9c5ff5132b

+ 1 - 1
main/document/showinframes.php

@@ -193,7 +193,7 @@ $js_glossary_in_documents =	'
         { type:"stylesheet", id:"_fr5", src:"'.api_get_path(WEB_PATH).'web/assets/jquery-ui/themes/smoothness/jquery-ui.min.css"},
         { type:"stylesheet", id:"_fr6", src:"'.api_get_path(WEB_PATH).'web/assets/jquery-ui/themes/smoothness/theme.css"},
         { type:"script", id:"_fr2", src:"'.api_get_path(WEB_LIBRARY_JS_PATH).'jquery.highlight.js"},
-        { type:"script", id:"_fr3", src:"'.api_get_path(WEB_CODE_PATH).'glossary/glossary.js.php"}
+        { type:"script", id:"_fr3", src:"'.api_get_path(WEB_CODE_PATH).'glossary/glossary.js.php?'.api_get_cidreq().'"}
     ]
   });';
 

+ 1 - 0
main/exercice/exercise_show.php

@@ -730,6 +730,7 @@ if ($origin!='learnpath' || ($origin == 'learnpath' && isset($_GET['fb_type'])))
 	    if ($objExercise->selectPropagateNeg() == 0 && $my_total_score_temp < 0) {
 	        $my_total_score_temp = 0;
 	    }
+
         $total_score_text .= ExerciseLib::get_question_ribbon(
             $objExercise,
             $my_total_score_temp,

+ 1 - 1
main/exercice/exercise_submit.php

@@ -46,8 +46,8 @@ if ($origin == 'learnpath') {
     $showGlossary = in_array($glossaryExtraTools, array('true', 'lp', 'exercise_and_lp'));
 }
 if ($showGlossary) {
-    $htmlHeadXtra[] = '<script type="text/javascript" src="'.api_get_path(WEB_CODE_PATH).'glossary/glossary.js.php?add_ready=1"></script>';
     $htmlHeadXtra[] = '<script type="text/javascript" src="'.api_get_path(WEB_LIBRARY_JS_PATH).'jquery.highlight.js"></script>';
+    $htmlHeadXtra[] = '<script type="text/javascript" src="'.api_get_path(WEB_CODE_PATH).'glossary/glossary.js.php?add_ready=1&'.api_get_cidreq().'"></script>';
 }
 
 $htmlHeadXtra[] = api_get_js('components/jsplumb/dist/js/jsPlumb-2.0.4.js');

+ 9 - 7
main/glossary/glossary.js.php

@@ -1,16 +1,18 @@
 <?php
 /* For licensing terms, see /license.txt */
 
-//require_once '../inc/global.inc.php';
+use Chamilo\CoreBundle\Framework\Container;
 
-$tpl = new Template();
+$tpl = \Chamilo\CoreBundle\Framework\Container::getTwig();
 
-$templateName = 'glossary/glossary_auto.js.tpl';
+$templateName = 'glossary/glossary_auto.js.twig';
 if (api_get_setting('document.show_glossary_in_documents') == 'ismanual') {
-    $templateName = 'glossary/glossary_manual.js.tpl';
+    $templateName = 'glossary/glossary_manual.js.twig';
 }
 
 $addReady = isset($_GET['add_ready']) ? true : false;
-$tpl->assign('add_ready', $addReady);
-$contentTemplate = $tpl->get_template($templateName);
-$tpl->display($contentTemplate);
+$tpl->addGlobal('add_ready', $addReady);
+echo $tpl->render('@template_style/'.$templateName);
+
+// Hide headers
+Container::$legacyTemplate = 'layout_empty.html.twig';

+ 4 - 2
main/glossary/glossary_ajax_request.php

@@ -1,14 +1,14 @@
 <?php
 /* For licensing terms, see /license.txt */
 
+use Chamilo\CoreBundle\Framework\Container;
+
 /* @todo move this file in the inc/ajax/ folder */
 /**
  * Glossary ajax request code
  * @package chamilo.glossary
  */
 
-//require_once '../inc/global.inc.php';
-
 /**
  * Search a term and return description from a glossary.
  */
@@ -66,3 +66,5 @@ if (isset($_POST['glossary_id']) &&
 } else {
     echo api_xml_http_response_encode(get_lang('NoResults'));
 }
+
+Container::$legacyTemplate = 'layout_empty.html.twig';

+ 1 - 0
main/inc/lib/exercise.lib.php

@@ -3700,6 +3700,7 @@ HOTSPOT;
         }
         $ribbon .= '<h3>' . get_lang('YourTotalScore') . ":&nbsp;";
         $ribbon .= self::show_score($score, $weight, false, true);
+
         $ribbon .= '</h3>';
         $ribbon .= '</div>';
         if ($check_pass_percentage) {

+ 1 - 1
main/newscorm/scorm_api.php

@@ -2067,7 +2067,7 @@ function attach_glossary_into_scorm(type) {
     my_protocol = location.protocol;
     my_pathname=location.pathname;
     work_path = my_pathname.substr(0,my_pathname.indexOf('/courses/'));
-    var ajaxRequestUrl = '<?php echo api_get_path(WEB_CODE_PATH).'glossary/glossary_ajax_request.php'; ?>';
+    var ajaxRequestUrl = '<?php echo api_get_path(WEB_CODE_PATH).'glossary/glossary_ajax_request.php?'.api_get_cidreq(); ?>';
 
     if (type == 'automatic') {
         $.ajax({

+ 0 - 100
main/template/default/glossary/glossary_auto.js.tpl

@@ -1,100 +0,0 @@
-{% if add_ready %}
-$(document).ready(function() {
-    $(window).load(function () {
-{% endif %}
-
-        var my_text = $(".glossary-content").html();
-        var ajaxRequestUrl = "{{ _p.web }}main/glossary/glossary_ajax_request.php";
-        var imageSource = "{{ _p.web }}main/inc/lib/javascript/indicator.gif";
-        var indicatorImage ='<img src="' + imageSource + '" />';
-
-        $.ajax({
-            contentType: "application/x-www-form-urlencoded",
-            beforeSend: function(content_object) {},
-            type: "POST",
-            url: ajaxRequestUrl,
-            data: "glossary_data=true",
-            success: function(datas) {
-                if (datas.length==0) {
-                    return false;
-                }
-                // glossary terms
-                data_terms=datas.split("[|.|_|.|-|.|]");
-                var complex_array = new Array();
-                var cp_complex_array = new Array();
-                for(i=0;i<data_terms.length;i++) {
-                    specific_terms=data_terms[i].split("__|__|");
-                    var real_term = specific_terms[1]; // glossary term
-                    var real_code = specific_terms[0]; // glossary id
-                    complex_array[real_code] = real_term;
-                    cp_complex_array[real_code] = real_term;
-                }
-
-                complex_array.reverse();
-
-                for (var my_index in complex_array) {
-                    n = complex_array[my_index];
-                    if (n == null) {
-                        n = '';
-                    } else {
-                        for (var cp_my_index in cp_complex_array) {
-                            cp_data = cp_complex_array[cp_my_index];
-                            if (cp_data == null) {
-                                cp_data = '';
-                            } else {
-                                if (cp_data == n) {
-                                    my_index = cp_my_index;
-                                }
-                            }
-                        }
-                        $('body').removeHighlight().highlight(n, my_index);
-                    }
-                }
-
-                var complex_array = new Array();
-                //mouse on click
-                $("body").on("click", ".glossary-ajax", function(e) {
-                    random_id = Math.round(Math.random()*100);
-                    div_show_id = "div_show_id";
-                    div_content_id = "div_content_id";
-
-                    $(this).append("<div id="+div_show_id+"><div id="+div_content_id+">&nbsp;</div></div>");
-                    var $target = $(this);
-
-                    //$("#"+div_show_id).dialog("destroy");
-                    $("#"+div_show_id).dialog({
-                        autoOpen: false,
-                        width: 600,
-                        height: 200,
-                        position:  { my: 'left top', at: 'right top', of: $target },
-                        close: function(){
-                            $("div#"+div_show_id).remove();
-                            $("div#"+div_content_id).remove();
-                        }
-                    });
-
-                    notebook_id = $(this).attr("name");
-                    data_notebook = notebook_id.split("link");
-                    my_glossary_id = data_notebook[1];
-
-                    $.ajax({
-                        contentType: "application/x-www-form-urlencoded",
-                        beforeSend: function(content_object) {
-                            $("div#"+div_content_id).html(indicatorImage);
-                        },
-                        type: "POST",
-                        url: ajaxRequestUrl,
-                        data: "glossary_id="+my_glossary_id,
-                        success: function(datas) {
-                            $("div#"+div_content_id).html(datas);
-                            $("#"+div_show_id).dialog("open");
-                        }
-                    });
-                });
-            }
-        });
-{% if add_ready %}
-    });
-});
-
-{% endif %}

+ 1 - 1
src/Chamilo/CoreBundle/Controller/LegacyController.php

@@ -54,7 +54,7 @@ class LegacyController extends ToolBaseController
         Container::$dataDir = $this->container->get('kernel')->getDataDir();
         Container::$courseDir = $this->container->get('kernel')->getDataDir();
         //Container::$configDir = $this->container->get('kernel')->getConfigDir();
-        $this->container->get('twig')->addGlobal('show_header', true);
+        $this->container->get('twig')->addGlobal('api_get_cidreq', api_get_cidreq());
 
         //$breadcrumb = $this->container->get('chamilo_core.block.breadcrumb');
 

+ 28 - 28
src/Chamilo/CoreBundle/Resources/public/js/jquery.highlight.js

@@ -1,30 +1,30 @@
 /*
-highlight v3
+ highlight v3
 
-Highlights arbitrary terms.
-<http://johannburkard.de/blog/programming/javascript/highlight-javascript-text-higlighting-jquery-plugin.html>
-MIT license.
+ Highlights arbitrary terms.
+ <http://johannburkard.de/blog/programming/javascript/highlight-javascript-text-higlighting-jquery-plugin.html>
+ MIT license.
 
-Johann Burkard <http://johannburkard.de> <mailto:jb@eaio.com>
-Julio Montoya <gugli100@gmail.com> fixes for the Glossary tool to strict search 
+ Johann Burkard <http://johannburkard.de> <mailto:jb@eaio.com>
+ Julio Montoya <gugli100@gmail.com> fixes for the Glossary tool to strict search
 
-*/
+ */
 
 jQuery.fn.highlight = function(pat,real_code) {
-	
+
 	function innerHighlight(node, pat) {
-		var skip = 0; 
+		var skip = 0;
 		if (node.nodeType == 3 ) {
 			// Highlight all coincidences
 			//var pos = node.data.toUpperCase().indexOf(pat);
-			
+
 			//Highlight strict, exact words
-            var SearchRegExp = new RegExp("(\\b|\\B)"+pat+"(\\b|\\B)","gi");
+			var SearchRegExp = new RegExp("(\\b|\\B)"+pat+"(\\b|\\B)","gi");
 			var pos = node.nodeValue.search(SearchRegExp);
-			
+
 			if (pos >= 0 ) {
 				var spannode = document.createElement('a');
-				spannode.className = 'glossary-ajax';			
+				spannode.className = 'glossary-ajax';
 				spannode.style.color = '#084B8A';
 				spannode.style.fontWeight='100';
 				spannode.style.textDecoration = 'none';
@@ -35,7 +35,7 @@ jQuery.fn.highlight = function(pat,real_code) {
 				if (MatchRegExp == null) {
 					MatchRegExp = new Array();
 				}
-			
+
 				if (MatchRegExp.length > 0 && node.nodeValue[pat.length+1] != '') {
 					var middlebit = node.splitText(pos);
 					var endbit = middlebit.splitText(pat.length);
@@ -43,31 +43,31 @@ jQuery.fn.highlight = function(pat,real_code) {
 						var middleclone = middlebit.cloneNode(true);
 						spannode.appendChild(middleclone);
 						middlebit.parentNode.replaceChild(spannode, middlebit);
-					}  	
+					}
 				}
 				skip = 1;
 			}
-		} else if (node.nodeType == 1 && node.childNodes && !/(script|style)/i.test(node.tagName)) {		
-			for (var i = 0; i <node.childNodes.length ; ++i) {				
-				i += innerHighlight(node.childNodes[i], pat);					
-		   	}
+		} else if (node.nodeType == 1 && node.childNodes && !/(script|style)/i.test(node.tagName)) {
+			for (var i = 0; i <node.childNodes.length ; ++i) {
+				i += innerHighlight(node.childNodes[i], pat);
+			}
 		}
-	  return skip;
-	}		
-	
+		return skip;
+	}
+
 	return this.each(function() {
-		innerHighlight(this, pat.toUpperCase());	
+		innerHighlight(this, pat.toUpperCase());
 	});
-	
+
 };
-	
+
 jQuery.fn.removeHighlight = function() {
 	return this.find("a.highlight").each(function() {
 		this.parentNode.firstChild.nodeName;
 		with (this.parentNode) {
-	   		replaceChild(this.firstChild, this);
-	   		normalize();
-	  	}
+			replaceChild(this.firstChild, this);
+			normalize();
+		}
 	}).end();
 
 };

+ 110 - 0
src/Chamilo/CoreBundle/Resources/views/default/glossary/glossary_auto.js.twig

@@ -0,0 +1,110 @@
+{% block content %}
+{% if add_ready %}
+$(document).ready(function() {
+    $(window).load(function () {
+{% endif %}
+
+    var my_text = $(".glossary-content").html();
+    var ajaxRequestUrl = "{{ url('web.main') }}glossary/glossary_ajax_request.php?{{ api_get_cidreq }}";
+    var imageSource = "{{ asset('bundles/chamilocore/js/indicator.gif') }}";
+    var indicatorImage ='<img src="' + imageSource + '" />';
+
+    $.ajax({
+        contentType: "application/x-www-form-urlencoded",
+        beforeSend: function(content_object) {},
+        type: "POST",
+        url: ajaxRequestUrl,
+        data: "glossary_data=true",
+        success: function(datas) {
+            if (datas.length==0) {
+                return false;
+            }
+            // glossary terms
+            data_terms = datas.split("[|.|_|.|-|.|]");
+
+            var complex_array = [];
+            var cp_complex_array = [];
+
+            for (i=0; i < data_terms.length; i++) {
+                specific_terms = data_terms[i].split("__|__|");
+                var real_term = specific_terms[1]; // glossary term
+                var real_code = specific_terms[0]; // glossary id
+                complex_array[real_code] = real_term.trim();
+                cp_complex_array[real_code] = real_term.trim();
+            }
+
+            for (var my_index in complex_array) {
+                n = complex_array[my_index];
+                if (n == null) {
+                    n = '';
+                } else {
+                    for (var cp_my_index in cp_complex_array) {
+
+                        cp_data = cp_complex_array[cp_my_index];
+
+                        if (cp_data == null) {
+                            cp_data = '';
+                        } else {
+                            if (cp_data == n) {
+                                my_index = cp_my_index;
+                            }
+                        }
+                    }
+
+                    var my_index = parseInt(my_index);
+
+
+                    if ($.isNumeric(my_index)) {
+                        $('body').removeHighlight().highlight(n, my_index);
+                    }
+                }
+            }
+
+            var complex_array = new Array();
+            //mouse on click
+            $("body").on("click", ".glossary-ajax", function(e) {
+                random_id = Math.round(Math.random()*100);
+                div_show_id = "div_show_id";
+                div_content_id = "div_content_id";
+
+                $(this).append("<div id="+div_show_id+"><div id="+div_content_id+">&nbsp;</div></div>");
+                var $target = $(this);
+
+                //$("#"+div_show_id).dialog("destroy");
+                $("#"+div_show_id).dialog({
+                    autoOpen: false,
+                    width: 600,
+                    height: 200,
+                    position:  { my: 'left top', at: 'right top', of: $target },
+                    close: function(){
+                        $("div#"+div_show_id).remove();
+                        $("div#"+div_content_id).remove();
+                    }
+                });
+
+                notebook_id = $(this).attr("name");
+                data_notebook = notebook_id.split("link");
+                my_glossary_id = data_notebook[1];
+
+                $.ajax({
+                    contentType: "application/x-www-form-urlencoded",
+                    beforeSend: function(content_object) {
+                        $("div#"+div_content_id).html(indicatorImage);
+                    },
+                    type: "POST",
+                    url: ajaxRequestUrl,
+                    data: "glossary_id="+my_glossary_id,
+                    success: function(datas) {
+                        $("div#"+div_content_id).html(datas);
+                        $("#"+div_show_id).dialog("open");
+                    }
+                });
+            });
+        }
+    });
+{% if add_ready %}
+    });
+});
+
+{% endif %}
+{% endblock %}

+ 17 - 15
main/template/default/glossary/glossary_manual.js.tpl → src/Chamilo/CoreBundle/Resources/views/default/glossary/glossary_manual.js.twig

@@ -1,5 +1,6 @@
-var ajaxRequestUrl = "{{ _p.web }}main/glossary/glossary_ajax_request.php";
-var imageSource = "{{ _p.web_main }}" + "inc/lib/javascript/indicator.gif";
+{% block content %}
+var ajaxRequestUrl = "{{ url('web.main') }}glossary/glossary_ajax_request.php?{{ api_get_cidreq }}";
+var imageSource = "{{ asset('bundles/chamilocore/js/indicator.gif') }}";
 var indicatorImage ='<img src="' + imageSource + '" />';
 
 {% if add_ready %}
@@ -28,21 +29,22 @@ $(document).ready(function() {
             }
         });
         var indicator =
-                $.ajax({
-                    contentType: "application/x-www-form-urlencoded",
-                    beforeSend: function(result) {
-                        $("div#"+div_content_id).html(indicatorImage);
-                    },
-                    type: "POST",
-                    url: ajaxRequestUrl,
-                    data: "glossary_name="+is_glossary_name,
-                    success: function(data) {
-                        $("div#"+div_content_id).html(data);
-                        $("#"+div_show_id).dialog("open");
-                    }
-                });
+        $.ajax({
+            contentType: "application/x-www-form-urlencoded",
+            beforeSend: function(result) {
+                $("div#"+div_content_id).html(indicatorImage);
+            },
+            type: "POST",
+            url: ajaxRequestUrl,
+            data: "glossary_name="+is_glossary_name,
+            success: function(data) {
+                $("div#"+div_content_id).html(data);
+                $("#"+div_show_id).dialog("open");
+            }
+        });
     });
 
 {% if add_ready %}
 });
 {% endif %}
+{% endblock %}

+ 3 - 3
src/Chamilo/CoreBundle/Resources/views/layout_empty.html.twig

@@ -1,6 +1,6 @@
 {% autoescape false %}
-    {% block content %}
-    {{ content }}
-    {% endblock %}
+{% block content %}
+{{ content }}
+{% endblock %}
 {% endautoescape %}
 

+ 12 - 2
src/Chamilo/CoreBundle/Settings/DocumentSettingsSchema.php

@@ -31,7 +31,7 @@ class DocumentSettingsSchema implements SchemaInterface
                     'upload_extensions_replace_by' => '',
                     'permissions_for_new_directories' => '',
                     'permissions_for_new_files' => '',
-                    'show_glossary_in_documents' => '',
+                    'show_glossary_in_documents' => 'none',
                     'students_download_folders' => '',
                     'users_copy_files' => '',
                     'pdf_export_watermark_enable' => '',
@@ -85,7 +85,17 @@ class DocumentSettingsSchema implements SchemaInterface
             ->add('upload_extensions_replace_by', 'textarea')
             ->add('permissions_for_new_directories')
             ->add('permissions_for_new_files')
-            ->add('show_glossary_in_documents', 'yes_no')
+            ->add(
+                'show_glossary_in_documents',
+                'choice',
+                [
+                    'choices' => [
+                        'none' => 'none',
+                        'ismanual' => 'ismanual',
+                        'isautomatic' => 'isautomatic',
+                    ]
+                ]
+            )
             ->add('students_download_folders', 'yes_no')
             ->add('users_copy_files', 'yes_no')
             ->add('pdf_export_watermark_enable', 'yes_no')

+ 2 - 1
src/Chamilo/CoreBundle/Twig/Extension/ChamiloExtension.php

@@ -25,7 +25,8 @@ class ChamiloExtension extends \Twig_Extension
      */
     public function getFunctions()
     {
-        return array();
+        return array(
+        );
     }
 
     /**