Пример #1
0
    def render_GET(self, request=None):
        log.debug("render_GET")
        data = {}
        try:
            if 'lom_general_title_string1' in request.args.keys():
                self.package.lom.genForm('lom', self.package.lom, data)
            elif 'lomes_general_title_string1' in request.args.keys():
                self.package.lom.genForm('lomes', self.package.lomEs, data)
            else:
                for key in request.args.keys():
                    if key != "_dc":
                        obj, name = self.fieldId2obj(key)
                        if key in self.imgFieldNames:
                            if getattr(obj, name):
                                data[key] = getattr(obj, name).basename()
                        else:
                            data[key] = getattr(obj, name)
                            if name=='docType':              
                                common.setExportDocType(getattr(obj,name))

        except Exception as e:
            log.exception(e)
            return json.dumps({'success': False, 'errorMessage': _("Failed to get properties")})
        return json.dumps({'success': True, 'data': data})
Пример #2
0
    def render(self, pages):
        """
        Returns an XHTML string rendering this page.
        """
        old_dT = common.getExportDocType()
        common.setExportDocType('HTML5')
        dT = common.getExportDocType()
        lb = "\n"  # Line breaks
        sectionTag = "div"
        articleTag = "div"
        headerTag = "div"
        if dT == "HTML5":
            sectionTag = "section"
            articleTag = "article"
            headerTag = "header"
        html = common.docType()
        lenguaje = G.application.config.locale
        if self.node.package.lang != "":
            lenguaje = self.node.package.lang
        html += u"<html lang=\"" + lenguaje + "\" xml:lang=\"" + lenguaje + "\" xmlns=\"http://www.w3.org/1999/xhtml\">" + lb
        html += u"<head>" + lb
        html += u"<title>"
        if self.node.id == '0':
            if self.node.package.title != '':
                html += escape(self.node.package.title)
            else:
                html += escape(self.node.titleLong)
        else:
            if self.node.package.title != '':
                html += escape(self.node.titleLong) + " | " + escape(
                    self.node.package.title)
            else:
                html += escape(self.node.titleLong)
        html += u" </title>" + lb
        html += u'<meta charset="utf-8" />' + lb
        if dT != "HTML5" and self.node.package.lang != "":
            html += '<meta http-equiv="content-language" content="' + lenguaje + '" />' + lb
        if self.node.package.author != "":
            html += '<meta name="author" content="' + escape(
                self.node.package.author, True) + '" />' + lb
        html += common.getLicenseMetadata(self.node.package.license)
        html += '<meta name="generator" content="eXeLearning ' + release + ' - exelearning.net" />' + lb
        if self.node.id == '0':
            if self.node.package.description != "":
                html += '<meta name="description" content="' + escape(
                    self.node.package.description, True) + '" />' + lb
        html += u"<link rel=\"stylesheet\" type=\"text/css\" href=\"base.css\" />" + lb
        if common.hasWikipediaIdevice(self.node):
            html += u"<link rel=\"stylesheet\" type=\"text/css\" href=\"exe_wikipedia.css\" />" + lb
        if common.hasGalleryIdevice(self.node):
            html += u"<link rel=\"stylesheet\" type=\"text/css\" href=\"exe_lightbox.css\" />" + lb
        if common.hasFX(self.node):
            html += u"<link rel=\"stylesheet\" type=\"text/css\" href=\"exe_effects.css\" />" + lb
        if common.hasSH(self.node):
            html += u"<link rel=\"stylesheet\" type=\"text/css\" href=\"exe_highlighter.css\" />" + lb
        if common.hasGames(self.node):
            html += u"<link rel=\"stylesheet\" type=\"text/css\" href=\"exe_games.css\" />" + lb
        if common.hasABCMusic(self.node):
            html += u"<link rel=\"stylesheet\" type=\"text/css\" href=\"exe_abcmusic.css\" />" + lb
        html += u"<link rel=\"stylesheet\" type=\"text/css\" href=\"content.css\" />" + lb
        if dT == "HTML5" or common.nodeHasMediaelement(self.node):
            html += u'<!--[if lt IE 9]><script type="text/javascript" src="exe_html5.js"></script><![endif]-->' + lb
        style = G.application.config.styleStore.getStyle(
            self.node.package.style)

        # jQuery
        if style.hasValidConfig:
            if style.get_jquery() == True:
                html += u'<script type="text/javascript" src="exe_jquery.js"></script>' + lb
            else:
                html += u'<script type="text/javascript" src="' + style.get_jquery(
                ) + '"></script>' + lb
        else:
            html += u'<script type="text/javascript" src="exe_jquery.js"></script>' + lb

        if common.hasGalleryIdevice(self.node):
            html += u'<script type="text/javascript" src="exe_lightbox.js"></script>' + lb
        if common.hasFX(self.node):
            html += u'<script type="text/javascript" src="exe_effects.js"></script>' + lb
        if common.hasSH(self.node):
            html += u'<script type="text/javascript" src="exe_highlighter.js"></script>' + lb
        html += u'<script type="text/javascript" src="common_i18n.js"></script>' + lb
        if common.hasGames(self.node):
            html += u'<script type="text/javascript" src="exe_games.js"></script>' + lb
        if common.hasABCMusic(self.node):
            html += u'<script type="text/javascript" src="exe_abcmusic.js"></script>' + lb
        html += u'<script type="text/javascript" src="common.js"></script>' + lb

        html += common.printJavaScriptIdevicesScripts('export', self)

        if common.hasMagnifier(self.node):
            html += u'<script type="text/javascript" src="mojomagnify.js"></script>' + lb
        # Some styles might have their own JavaScript files (see their config.xml file)
        if style.hasValidConfig:
            html += style.get_extra_head()
        html += common.getExtraHeadContent(self.node.package)
        html += u"</head>" + lb
        html += u'<body class="exe-epub3" id="exe-node-' + self.node.id + '">' + lb
        html += u"<div id=\"outer\">" + lb
        html += u"<" + sectionTag + " id=\"main\">" + lb
        html += u"<" + headerTag + " id=\"nodeDecoration\">"
        html += u"<div id=\"headerContent\">"
        html += u'<h1 id=\"nodeTitle\">'
        html += escape(self.node.titleLong)
        html += u'</h1>'
        html += u'</div>'
        html += u"</" + headerTag + ">" + lb

        self.node.exportType = 'epub'

        for idevice in self.node.idevices:
            if idevice.klass != 'NotaIdevice':
                e = " em_iDevice"
                if unicode(idevice.emphasis) == '0':
                    e = ""
                html += u'<' + articleTag + ' class="iDevice_wrapper %s%s" id="id%s">%s' % (
                    idevice.klass, e, idevice.id, lb)
                block = g_blockFactory.createBlock(None, idevice)
                if not block:
                    log.critical("Unable to render iDevice.")
                    raise Error("Unable to render iDevice.")
                if hasattr(idevice, "isQuiz"):
                    html += htmlentitydecode(block.renderJavascriptForWeb())
                if idevice.title != "Forum Discussion":
                    html += htmlentitydecode(
                        self.processInternalLinks(
                            block.renderView(self.node.package.style)))
                html += u'</' + articleTag + '>' + lb  # iDevice div

        html += u"</" + sectionTag + ">" + lb  # /#main

        if self.node.package.get_addPagination():
            html += "<p class='pagination page-counter'>" + c_(
                'Page %s of %s') % ('<strong>' + str(
                    pages.index(self)) + '</strong>', '<strong>' + str(
                        (len(pages) - 1)) + '</strong>') + "</p>" + lb

        html += self.renderLicense()
        html += unicode(
            BeautifulSoup(self.renderFooter(),
                          convertEntities=BeautifulSoup.XHTML_ENTITIES))
        html += u"</div>" + lb  # /#outer
        if style.hasValidConfig:
            html += style.get_extra_body()
        html += u'</body></html>'
        html = html.encode('utf8')
        # JR: Eliminamos los atributos de las ecuaciones
        aux = re.compile("exe_math_latex=\"[^\"]*\"")
        html = aux.sub("", html)
        aux = re.compile("exe_math_size=\"[^\"]*\"")
        html = aux.sub("", html)
        # JR: Cambio el & en los enlaces del glosario
        html = html.replace("&concept", "&amp;concept")
        # Remove "resources/" from data="resources/ and the url param
        html = html.replace("video/quicktime\" data=\"resources/",
                            "video/quicktime\" data=\"")
        html = html.replace("application/x-mplayer2\" data=\"resources/",
                            "application/x-mplayer2\" data=\"")
        html = html.replace("audio/x-pn-realaudio-plugin\" data=\"resources/",
                            "audio/x-pn-realaudio-plugin\" data=\"")
        html = html.replace("<param name=\"url\" value=\"resources/",
                            "<param name=\"url\" value=\"")

        common.setExportDocType(old_dT)
        return html
Пример #3
0
    def render(self):
        """
        Returns an XHTML string rendering this page.
        """
        old_dT = common.getExportDocType()
        common.setExportDocType("HTML5")
        dT = common.getExportDocType()
        lb = "\n"  # Line breaks
        sectionTag = "div"
        articleTag = "div"
        headerTag = "div"
        if dT == "HTML5":
            sectionTag = "section"
            articleTag = "article"
            headerTag = "header"
        html = common.docType()
        lenguaje = G.application.config.locale
        if self.node.package.lang != "":
            lenguaje = self.node.package.lang
        html += u'<html lang="' + lenguaje + '" xml:lang="' + lenguaje + '" xmlns="http://www.w3.org/1999/xhtml">' + lb
        html += u"<head>" + lb
        html += u"<title>"
        if self.node.id == "0":
            if self.node.package.title != "":
                html += escape(self.node.package.title)
            else:
                html += escape(self.node.titleLong)
        else:
            if self.node.package.title != "":
                html += escape(self.node.titleLong) + " | " + escape(self.node.package.title)
            else:
                html += escape(self.node.titleLong)
        html += u" </title>" + lb
        html += u'<meta charset="utf-8" />' + lb
        if dT != "HTML5" and self.node.package.lang != "":
            html += '<meta http-equiv="content-language" content="' + lenguaje + '" />' + lb
        if self.node.package.author != "":
            html += '<meta name="author" content="' + escape(self.node.package.author, True) + '" />' + lb
        html += common.getLicenseMetadata(self.node.package.license)
        html += '<meta name="generator" content="eXeLearning ' + release + ' - exelearning.net" />' + lb
        if self.node.id == "0":
            if self.node.package.description != "":
                html += '<meta name="description" content="' + escape(self.node.package.description, True) + '" />' + lb
        html += u'<link rel="stylesheet" type="text/css" href="base.css" />' + lb
        if common.hasWikipediaIdevice(self.node):
            html += u'<link rel="stylesheet" type="text/css" href="exe_wikipedia.css" />' + lb
        if common.hasGalleryIdevice(self.node):
            html += u'<link rel="stylesheet" type="text/css" href="exe_lightbox.css" />' + lb
        if common.hasFX(self.node):
            html += u'<link rel="stylesheet" type="text/css" href="exe_effects.css" />' + lb
        if common.hasSH(self.node):
            html += u'<link rel="stylesheet" type="text/css" href="exe_highlighter.css" />' + lb
        if common.hasGames(self.node):
            html += u'<link rel="stylesheet" type="text/css" href="exe_games.css" />' + lb
        html += u'<link rel="stylesheet" type="text/css" href="content.css" />' + lb
        if dT == "HTML5" or common.nodeHasMediaelement(self.node):
            html += u'<!--[if lt IE 9]><script type="text/javascript" src="exe_html5.js"></script><![endif]-->' + lb
        style = G.application.config.styleStore.getStyle(self.node.package.style)

        # jQuery
        if style.hasValidConfig:
            if style.get_jquery() == True:
                html += u'<script type="text/javascript" src="exe_jquery.js"></script>' + lb
            else:
                html += u'<script type="text/javascript" src="' + style.get_jquery() + '"></script>' + lb
        else:
            html += u'<script type="text/javascript" src="exe_jquery.js"></script>' + lb

        if common.hasGalleryIdevice(self.node):
            html += u'<script type="text/javascript" src="exe_lightbox.js"></script>' + lb
        if common.hasFX(self.node):
            html += u'<script type="text/javascript" src="exe_effects.js"></script>' + lb
        if common.hasSH(self.node):
            html += u'<script type="text/javascript" src="exe_highlighter.js"></script>' + lb
        html += common.getJavaScriptStrings() + lb
        if common.hasGames(self.node):
            # The games require additional strings
            html += common.getGamesJavaScriptStrings() + lb
            html += u'<script type="text/javascript" src="exe_games.js"></script>' + lb
        html += u'<script type="text/javascript" src="common.js"></script>' + lb
        if common.hasMagnifier(self.node):
            html += u'<script type="text/javascript" src="mojomagnify.js"></script>' + lb
        # Some styles might have their own JavaScript files (see their config.xml file)
        if style.hasValidConfig:
            html += style.get_extra_head()
        html += u"</head>" + lb
        html += u'<body class="exe-epub3"><script type="text/javascript">document.body.className+=" js"</script>' + lb
        html += u'<div id="outer">' + lb
        html += u"<" + sectionTag + ' id="main">' + lb
        html += u"<" + headerTag + ' id="nodeDecoration">'
        html += u'<div id="headerContent">'
        html += u'<h1 id="nodeTitle">'
        html += escape(self.node.titleLong)
        html += u"</h1>"
        html += u"</div>"
        html += u"</" + headerTag + ">" + lb

        self.node.exportType = "epub"

        for idevice in self.node.idevices:
            if idevice.klass != "NotaIdevice":
                e = " em_iDevice"
                if unicode(idevice.emphasis) == "0":
                    e = ""
                html += (
                    u"<"
                    + articleTag
                    + ' class="iDevice_wrapper %s%s" id="id%s">%s' % (idevice.klass, e, idevice.id, lb)
                )
                block = g_blockFactory.createBlock(None, idevice)
                if not block:
                    log.critical("Unable to render iDevice.")
                    raise Error("Unable to render iDevice.")
                if hasattr(idevice, "isQuiz"):
                    html += htmlentitydecode(block.renderJavascriptForWeb())
                if idevice.title != "Forum Discussion":
                    html += htmlentitydecode(self.processInternalLinks(block.renderView(self.node.package.style)))
                html += u"</" + articleTag + ">" + lb  # iDevice div

        html += u"</" + sectionTag + ">" + lb  # /#main
        html += self.renderLicense()
        html += unicode(BeautifulSoup(self.renderFooter(), convertEntities=BeautifulSoup.XHTML_ENTITIES))
        html += u"</div>" + lb  # /#outer
        if style.hasValidConfig:
            html += style.get_extra_body()
        html += u"</body></html>"
        html = html.encode("utf8")
        # JR: Eliminamos los atributos de las ecuaciones
        aux = re.compile('exe_math_latex="[^"]*"')
        html = aux.sub("", html)
        aux = re.compile('exe_math_size="[^"]*"')
        html = aux.sub("", html)
        # JR: Cambio el & en los enlaces del glosario
        html = html.replace("&concept", "&amp;concept")
        # Remove "resources/" from data="resources/ and the url param
        html = html.replace('video/quicktime" data="resources/', 'video/quicktime" data="')
        html = html.replace('application/x-mplayer2" data="resources/', 'application/x-mplayer2" data="')
        html = html.replace('audio/x-pn-realaudio-plugin" data="resources/', 'audio/x-pn-realaudio-plugin" data="')
        html = html.replace('<param name="url" value="resources/', '<param name="url" value="')

        common.setExportDocType(old_dT)
        return html
Пример #4
0
    def loadSettings(self):
        """
        Loads the settings from the exe.conf file.
        Overrides the defaults set in __init__
        """
        # Set up the parser so that if a certain value is not in the config
        # file, it will use the value from our default values
        def defVal(dummy, option):
            """If something is not in the config file, just use the default in
            'self'"""
            return getattr(self, option)
        self.configParser.defaultValue = defVal
        self.upgradeFile()
        # System Section
        if self.configParser.has_section('system'):
            system = self.configParser.system

            
            self.port           = int(system.port)
            self.browser        = None if system.browser == u"None" else system.browser
            
            
            if not G.application.portable:
                self.dataDir        = Path(system.dataDir)
                self.configDir      = Path(system.configDir)
                self.webDir         = Path(system.webDir)
                self.stylesDir      = Path(self.configDir)/'style'
                self.jsDir          = Path(system.jsDir)
            else:
                self.stylesDir      = Path(self.webDir/'style').abspath()
            
            self.assumeMediaPlugins = False;
            if self.configParser.has_option('system', \
                    'assumeMediaPlugins'):
               value = system.assumeMediaPlugins.strip().lower()
               if value == "1" or value == "yes" or value == "true" or \
                   value == "on":
                       self.assumeMediaPlugins = True;

        # If the dataDir points to some other dir, fix it
        if not self.dataDir.isdir():
            self.dataDir = tempfile.gettempdir()
        # make the webDir absolute, to hide path joins of relative paths
        self.webDir = self.webDir.expand().abspath()
        # If the configDir doesn't exist (as it may be a default setting with a
        # new installation) create it
        if not self.configDir.exists():
            self.configDir.mkdir()
		
        if not G.application.standalone: 
             #FM: Copy styles         
            if not os.path.exists(self.stylesDir) or not os.listdir(self.stylesDir):
                self.copyStyles() 
            else:
                self.updateStyles()                      
        else:
            if G.application.portable:
                if os.name == 'posix': 
                    self.stylesDir      = Path(self.webDir/'..'/'..'/'..'/'style')
                else: 
                    self.stylesDir      = Path(self.webDir/'..'/'style')
                if not os.path.exists(self.stylesDir) or not os.listdir(self.stylesDir): 
                    self.copyStyles()
            else:
                self.stylesDir     = Path(self.webDir/'style').abspath()
            
               
        # Get the list of recently opened projects
        self.recentProjects = []
        if self.configParser.has_section('recent_projects'):
            recentProjectsSection = self.configParser.recent_projects
            # recentProjectsSection.items() is in the wrong order, keys are alright.
            # Sorting list by key before adding to self.recentProjects, to avoid wrong ordering
            # in Recent Projects menu list
            recentProjectsItems = recentProjectsSection.items();
            recentProjectsItems.sort()
            for key, path in recentProjectsItems:
                self.recentProjects.append(path)
                
        # Load the list of "hidden" iDevices
        self.hiddeniDevices = []
        if self.configParser.has_section('idevices'):
            idevicesSection = self.configParser.idevices
            for key,value in idevicesSection.items():
                # emulate standard library's getboolean()
                value = value.strip().lower()
                if value == "0" or value == "no" or value == "false" or \
                        value == "off":
                    self.hiddeniDevices.append(key.lower())

        #self.deprecatediDevices = [ "flash with text", "flash movie", ...]
        # and UN-Load from the list of "deprecated" iDevices
        if self.configParser.has_section('deprecated'):
            deprecatedSection = self.configParser.deprecated
            for key,value in deprecatedSection.items():
                # emulate standard library's getboolean()
                value = value.strip().lower()
                if value == "1" or value == "yes" or value == "true" or \
                        value == "on":
                    if key.lower() in self.deprecatediDevices:
                        self.deprecatediDevices.remove(key.lower())

        # Load the "user" section
        if self.configParser.has_section('user'):
            if self.configParser.user.has_option('editorMode'):
                self.editorMode = self.configParser.user.editorMode
            if self.configParser.user.has_option('docType'):
                self.docType = self.configParser.user.docType
                common.setExportDocType(self.configParser.user.docType)
            if self.configParser.user.has_option('defaultStyle'):
                self.defaultStyle= self.configParser.user.defaultStyle
            if self.configParser.user.has_option('styleSecureMode'):
                self.styleSecureMode= self.configParser.user.styleSecureMode
            if self.configParser.user.has_option('internalAnchors'):
                self.internalAnchors = self.configParser.user.internalAnchors
            if self.configParser.user.has_option('lastDir'):
                self.lastDir = self.configParser.user.lastDir
            if self.configParser.user.has_option('showPreferencesOnStart'):
                self.showPreferencesOnStart = self.configParser.user.showPreferencesOnStart
            if self.configParser.user.has_option('showIdevicesGrouped'):
                self.showIdevicesGrouped = self.configParser.user.showIdevicesGrouped
            if self.configParser.user.has_option('locale'):
                self.locale = self.configParser.user.locale
                return
        self.locale = chooseDefaultLocale(self.localeDir)
Пример #5
0
    def loadSettings(self):
        """
        Loads the settings from the exe.conf file.
        Overrides the defaults set in __init__
        """
        # Set up the parser so that if a certain value is not in the config
        # file, it will use the value from our default values
        def defVal(dummy, option):
            """If something is not in the config file, just use the default in
            'self'"""
            return getattr(self, option)
        self.configParser.defaultValue = defVal
        self.upgradeFile()
        # System Section
        if self.configParser.has_section('system'):
            system = self.configParser.system

            self.port           = int(system.port)
            self.browser        = None if system.browser == u"None" else system.browser
            self.stylesRepository = system.stylesRepository

            if not G.application.portable:
                self.dataDir        = Path(system.dataDir)
                self.configDir      = Path(system.configDir)
                self.webDir         = Path(system.webDir)
                self.stylesDir      = Path(self.configDir)/'style'
                self.jsDir          = Path(system.jsDir)
            else:
                self.stylesDir      = Path(self.webDir/'style').abspath()

            self.assumeMediaPlugins = False
            if self.configParser.has_option('system', 'assumeMediaPlugins'):
                value = system.assumeMediaPlugins.strip().lower()
                if value == "1" or value == "yes" or value == "true" or value == "on":
                    self.assumeMediaPlugins = True

        # If the dataDir points to some other dir, fix it
        if not self.dataDir.isdir():
            self.dataDir = tempfile.gettempdir()
        # make the webDir absolute, to hide path joins of relative paths
        self.webDir = self.webDir.expand().abspath()
        # If the configDir doesn't exist (as it may be a default setting with a
        # new installation) create it
        if not self.configDir.exists():
            self.configDir.mkdir()

        if not G.application.standalone:
            # FM: Copy styles
            if not os.path.exists(self.stylesDir) or not os.listdir(self.stylesDir):
                self.copyStyles()
            else:
                self.updateStyles()
        else:
            if G.application.portable:
                if os.name == 'posix':
                    self.stylesDir = Path(self.webDir/'..'/'..'/'..'/'style')
                else:
                    self.stylesDir = Path(self.webDir/'..'/'style')
                if not os.path.exists(self.stylesDir) or not os.listdir(self.stylesDir):
                    self.copyStyles()
            else:
                self.stylesDir = Path(self.webDir/'style').abspath()

        # Get the list of recently opened projects
        self.recentProjects = []
        if self.configParser.has_section('recent_projects'):
            recentProjectsSection = self.configParser.recent_projects
            # recentProjectsSection.items() is in the wrong order, keys are alright.
            # Sorting list by key before adding to self.recentProjects, to avoid wrong ordering
            # in Recent Projects menu list
            recentProjectsItems = recentProjectsSection.items()
            recentProjectsItems.sort()
            for key, path in recentProjectsItems:
                self.recentProjects.append(path)

        # Load the list of "hidden" iDevices
        self.hiddeniDevices = []
        if self.configParser.has_section('idevices'):
            idevicesSection = self.configParser.idevices
            for key, value in idevicesSection.items():
                # emulate standard library's getboolean()
                value = value.strip().lower()
                if value == "0" or value == "no" or value == "false" or \
                        value == "off":
                    self.hiddeniDevices.append(key.lower())

        # self.deprecatediDevices = [ "flash with text", "flash movie", ...]
        # and UN-Load from the list of "deprecated" iDevices
        if self.configParser.has_section('deprecated'):
            deprecatedSection = self.configParser.deprecated
            for key, value in deprecatedSection.items():
                # emulate standard library's getboolean()
                value = value.strip().lower()
                if value == "1" or value == "yes" or value == "true" or \
                        value == "on":
                    if key.lower() in self.deprecatediDevices:
                        self.deprecatediDevices.remove(key.lower())

        # Load the "user" section
        if self.configParser.has_section('user'):
            if self.configParser.user.has_option('editorMode'):
                self.editorMode = self.configParser.user.editorMode
            if self.configParser.user.has_option('editorVersion'):
                self.editorVersion = self.configParser.user.editorVersion
            if self.configParser.user.has_option('docType'):
                self.docType = self.configParser.user.docType
                common.setExportDocType(self.configParser.user.docType)
            if self.configParser.user.has_option('defaultStyle'):
                self.defaultStyle = self.configParser.user.defaultStyle
            if self.configParser.user.has_option('styleSecureMode'):
                self.styleSecureMode = self.configParser.user.styleSecureMode
            if self.configParser.user.has_option('internalAnchors'):
                self.internalAnchors = self.configParser.user.internalAnchors
            if self.configParser.user.has_option('lastDir'):
                self.lastDir = self.configParser.user.lastDir
            if self.configParser.user.has_option('showPreferencesOnStart'):
                self.showPreferencesOnStart = self.configParser.user.showPreferencesOnStart
            if self.configParser.user.has_option('showIdevicesGrouped'):
                self.showIdevicesGrouped = self.configParser.user.showIdevicesGrouped
            if self.configParser.user.has_option('locale'):
                self.locale = self.configParser.user.locale
            if self.configParser.user.has_option('defaultLicense'):
                self.defaultLicense = self.configParser.user.defaultLicense
Пример #6
0
    def render(self, pages):
        """
        Returns an XHTML string rendering this page.
        """
        old_dT = common.getExportDocType()
        common.setExportDocType('HTML5')
        dT = common.getExportDocType()
        lb = "\n"  # Line breaks
        sectionTag = "div"
        articleTag = "div"
        headerTag = "div"
        if dT == "HTML5":
            sectionTag = "section"
            articleTag = "article"
            headerTag = "header"
        html = common.docType()
        lenguaje = G.application.config.locale
        if self.node.package.lang != "":
            lenguaje = self.node.package.lang
        html += u"<html lang=\"" + lenguaje + "\" xml:lang=\"" + lenguaje + "\" xmlns=\"http://www.w3.org/1999/xhtml\">" + lb
        html += u"<head>" + lb
        html += u"<title>"
        if self.node.id == '0':
            if self.node.package.title != '':
                html += escape(self.node.package.title)
            else:
                html += escape(self.node.titleLong)
        else:
            if self.node.package.title != '':
                html += escape(self.node.titleLong) + " | " + escape(self.node.package.title)
            else:
                html += escape(self.node.titleLong)
        html += u" </title>" + lb
        html += u'<meta charset="utf-8" />' + lb
        if dT != "HTML5" and self.node.package.lang != "":
            html += '<meta http-equiv="content-language" content="' + lenguaje + '" />' + lb
        if self.node.package.author != "":
            html += '<meta name="author" content="' + escape(self.node.package.author, True) + '" />' + lb
        html += common.getLicenseMetadata(self.node.package.license)
        html += '<meta name="generator" content="eXeLearning ' + release + ' - exelearning.net" />' + lb
        if self.node.id == '0':
            if self.node.package.description != "":
                html += '<meta name="description" content="' + escape(self.node.package.description, True) + '" />' + lb
        html += u"<link rel=\"stylesheet\" type=\"text/css\" href=\"base.css\" />" + lb
        if common.hasWikipediaIdevice(self.node):
            html += u"<link rel=\"stylesheet\" type=\"text/css\" href=\"exe_wikipedia.css\" />" + lb
        if common.hasGalleryIdevice(self.node):
            html += u"<link rel=\"stylesheet\" type=\"text/css\" href=\"exe_lightbox.css\" />" + lb
        if common.hasFX(self.node):
            html += u"<link rel=\"stylesheet\" type=\"text/css\" href=\"exe_effects.css\" />" + lb
        if common.hasSH(self.node):
            html += u"<link rel=\"stylesheet\" type=\"text/css\" href=\"exe_highlighter.css\" />" + lb
        if common.hasGames(self.node):
            html += u"<link rel=\"stylesheet\" type=\"text/css\" href=\"exe_games.css\" />" + lb
        if common.hasABCMusic(self.node):
            html += u"<link rel=\"stylesheet\" type=\"text/css\" href=\"exe_abcmusic.css\" />" + lb
        html += u"<link rel=\"stylesheet\" type=\"text/css\" href=\"content.css\" />" + lb
        if dT == "HTML5" or common.nodeHasMediaelement(self.node):
            html += u'<!--[if lt IE 9]><script type="text/javascript" src="exe_html5.js"></script><![endif]-->' + lb
        style = G.application.config.styleStore.getStyle(self.node.package.style)

        # jQuery
        if style.hasValidConfig:
            if style.get_jquery() == True:
                html += u'<script type="text/javascript" src="exe_jquery.js"></script>' + lb
            else:
                html += u'<script type="text/javascript" src="' + style.get_jquery() + '"></script>' + lb
        else:
            html += u'<script type="text/javascript" src="exe_jquery.js"></script>' + lb

        if common.hasGalleryIdevice(self.node):
            html += u'<script type="text/javascript" src="exe_lightbox.js"></script>' + lb
        if common.hasFX(self.node):
            html += u'<script type="text/javascript" src="exe_effects.js"></script>' + lb
        if common.hasSH(self.node):
            html += u'<script type="text/javascript" src="exe_highlighter.js"></script>' + lb
        html += u'<script type="text/javascript" src="common_i18n.js"></script>' + lb
        if common.hasGames(self.node):
            html += u'<script type="text/javascript" src="exe_games.js"></script>' + lb
        if common.hasABCMusic(self.node):
            html += u'<script type="text/javascript" src="exe_abcmusic.js"></script>' + lb
        html += u'<script type="text/javascript" src="common.js"></script>' + lb

        html += common.printJavaScriptIdevicesScripts('export', self)

        if common.hasMagnifier(self.node):
            html += u'<script type="text/javascript" src="mojomagnify.js"></script>' + lb
        # Some styles might have their own JavaScript files (see their config.xml file)
        if style.hasValidConfig:
            html += style.get_extra_head()
        html += common.getExtraHeadContent(self.node.package)
        html += u"</head>" + lb
        html += u'<body class="exe-epub3" id="exe-node-'+self.node.id+'">' + lb
        html += u"<div id=\"outer\">" + lb
        html += u"<" + sectionTag + " id=\"main\">" + lb
        html += u"<" + headerTag + " id=\"nodeDecoration\">"
        html += u"<div id=\"headerContent\">"
        html += u'<h1 id=\"nodeTitle\">'
        html += escape(self.node.titleLong)
        html += u'</h1>'
        html += u'</div>'
        html += u"</" + headerTag + ">" + lb

        self.node.exportType = 'epub'

        for idevice in self.node.idevices:
            if idevice.klass != 'NotaIdevice':
                e = " em_iDevice"
                if unicode(idevice.emphasis) == '0':
                    e = ""
                html += u'<' + articleTag + ' class="iDevice_wrapper %s%s" id="id%s">%s' % (idevice.klass, e, idevice.id, lb)
                block = g_blockFactory.createBlock(None, idevice)
                if not block:
                    log.critical("Unable to render iDevice.")
                    raise Error("Unable to render iDevice.")
                if hasattr(idevice, "isQuiz"):
                    html += htmlentitydecode(block.renderJavascriptForWeb())
                if idevice.title != "Forum Discussion":
                    html += htmlentitydecode(self.processInternalLinks(
                        block.renderView(self.node.package.style)))
                html += u'</' + articleTag + '>' + lb  # iDevice div

            html = re.sub("(<iframe[^>]*)(src=\"//)", "\g<1>src=\"https://", html)

        html += u"</" + sectionTag + ">" + lb  # /#main

        if self.node.package.get_addPagination():
            html += "<p class='pagination page-counter'>" + c_('Page %s of %s') % ('<strong>'+str(pages.index(self))+'</strong>','<strong>'+str((len(pages) -1))+'</strong>')+ "</p>"+lb

        html += self.renderLicense()
        html += unicode(BeautifulSoup(self.renderFooter()))
        html += u"</div>" + lb  # /#outer
        if style.hasValidConfig:
            html += style.get_extra_body()
        html += u'</body></html>'
        html = html.encode('utf8')
        # JR: Eliminamos los atributos de las ecuaciones
        aux = re.compile("exe_math_latex=\"[^\"]*\"")
        html = aux.sub("", html)
        aux = re.compile("exe_math_size=\"[^\"]*\"")
        html = aux.sub("", html)
        # JR: Cambio el & en los enlaces del glosario
        html = html.replace("&concept", "&amp;concept")
        # Remove "resources/" from data="resources/ and the url param
        html = html.replace("video/quicktime\" data=\"resources/", "video/quicktime\" data=\"")
        html = html.replace("application/x-mplayer2\" data=\"resources/", "application/x-mplayer2\" data=\"")
        html = html.replace("audio/x-pn-realaudio-plugin\" data=\"resources/", "audio/x-pn-realaudio-plugin\" data=\"")
        html = html.replace("<param name=\"url\" value=\"resources/", "<param name=\"url\" value=\"")

        common.setExportDocType(old_dT)
        return html