Ejemplo n.º 1
0
    def test_convert_good_cvsdate(self):
        """dateutils - conversion of good CVS dates"""
        # here we have to use '$' + 'Date...' here, otherwise the CVS
        # commit would erase this time format to put commit date:
        datecvs = "$" + "Date: 2006/09/21 10:07:22 $"
        datestruct_beginning_expected = (2006, 9, 21, 10, 7, 22)
        self.assertEqual(dateutils.convert_datecvs_to_datestruct(datecvs)[:6],
                         datestruct_beginning_expected)

        # here we have to use '$' + 'Date...' here, otherwise the CVS
        # commit would erase this time format to put commit date:
        datecvs = "$" + "Id: dateutils_tests.py,v 1.6 2007/02/14 18:33:02 tibor Exp $"
        datestruct_beginning_expected = (2007, 2, 14, 18, 33, 02)
        self.assertEqual(dateutils.convert_datecvs_to_datestruct(datecvs)[:6],
                         datestruct_beginning_expected)
Ejemplo n.º 2
0
    def tmpl_pagefooter(self, req, **kwargs):
        """Creates a page footer

           Parameters:

          - 'ln' *string* - The language to display

          - 'lastupdated' *string* - when the page was last updated

          - 'pagefooteradd' *string* - additional page footer HTML code

           Output:

          - HTML code of the page headers
        """
        ctx = dict(ln=CFG_SITE_LANG, lastupdated=None, pagefooteradd=None)
        ctx.update(kwargs)
        lastupdated = ctx.get('lastupdated')
        if lastupdated and lastupdated != '$Date$':
            if lastupdated.startswith("$Date: ") or lastupdated.startswith(
                    "$Id: "):
                ctx['lastupdated'] = convert_datecvs_to_datestruct(lastupdated)

        return render_template_to_string("legacy_page.html",
                                         no_pagebody=True,
                                         no_pageheader=True,
                                         **ctx).encode('utf8')
Ejemplo n.º 3
0
 def test_convert_bad_cvsdate(self):
     """dateutils - conversion of bad CVS dates"""
     # here we have to use '$' + 'Date...' here, otherwise the CVS
     # commit would erase this time format to put commit date:
     datecvs = "$" + "Date: 2006/AA/21 10:07:22 $"
     datestruct_beginning_expected = (0, 0, 0, 0, 0, 0)
     self.assertEqual(dateutils.convert_datecvs_to_datestruct(datecvs)[:6],
                      datestruct_beginning_expected)
Ejemplo n.º 4
0
    def test_convert_good_cvsdate(self):
        """dateutils - conversion of good CVS dates"""
        # here we have to use '$' + 'Date...' here, otherwise the CVS
        # commit would erase this time format to put commit date:
        datecvs = "$" + "Date: 2006/09/21 10:07:22 $"
        datestruct_beginning_expected = (2006, 9, 21, 10, 7, 22)
        self.assertEqual(
            dateutils.convert_datecvs_to_datestruct(datecvs)[:6],
            datestruct_beginning_expected)

        # here we have to use '$' + 'Date...' here, otherwise the CVS
        # commit would erase this time format to put commit date:
        datecvs = "$" + "Id: dateutils_tests.py,v 1.6 2007/02/14 18:33:02 tibor Exp $"
        datestruct_beginning_expected = (2007, 2, 14, 18, 33, 02)
        self.assertEqual(
            dateutils.convert_datecvs_to_datestruct(datecvs)[:6],
            datestruct_beginning_expected)
Ejemplo n.º 5
0
 def test_convert_bad_cvsdate(self):
     """dateutils - conversion of bad CVS dates"""
     # here we have to use '$' + 'Date...' here, otherwise the CVS
     # commit would erase this time format to put commit date:
     datecvs = "$" + "Date: 2006/AA/21 10:07:22 $"
     datestruct_beginning_expected = (0, 0, 0, 0, 0, 0)
     self.assertEqual(
         dateutils.convert_datecvs_to_datestruct(datecvs)[:6],
         datestruct_beginning_expected)
    def tmpl_pagefooter(self, req=None, ln=CFG_SITE_LANG, lastupdated=None,
                        pagefooteradd=""):
        """Creates a page footer

        Parameters:

        - 'ln' *string* - The language to display

        - 'lastupdated' *string* - when the page was last updated

        - 'pagefooteradd' *string* - additional page footer HTML code

        Output:

        - HTML code of the page headers
        """

        # load the right message language
        _ = gettext_set_language(ln)

        if lastupdated and lastupdated != '$Date$':
            if lastupdated.startswith("$Date: ") or \
            lastupdated.startswith("$Id: "):
                lastupdated = convert_datestruct_to_dategui(\
                                 convert_datecvs_to_datestruct(lastupdated),
                                 ln=ln)
            msg_lastupdated = _("Last updated") + ": " + lastupdated
        else:
            msg_lastupdated = ""

        out = """
<div class="pagefooter">
%(pagefooteradd)s
<!-- replaced page footer -->
 <div class="pagefooterstripeleft">
  %(sitename)s&nbsp;::&nbsp;<a class="footer" href="%(siteurl)s/?ln=%(ln)s">%(msg_search)s</a>&nbsp;::&nbsp;<a class="footer" href="%(siteurl)s/help/%(langlink)s">%(msg_help)s</a>
  <br />
  %(msg_poweredby)s <a class="footer" href="http://cdsware.cern.ch/">Invenio</a> v%(version)s
  <br />
  %(msg_maintainedby)s <a class="footer" href="mailto:%(sitesupportemail)s">%(sitesupportemail)s</a>
  <br />
  %(msg_lastupdated)s
 </div>
 <div class="pagefooterstriperight">
  %(languagebox)s
 </div>
<!-- replaced page footer -->
</div>
</body>
</html>
        """ % {
          'siteurl' : CFG_SITE_URL,
          'sitesecureurl' : CFG_SITE_SECURE_URL,
          'ln' : ln,
          'langlink': '?ln=' + ln,

          'sitename' : CFG_SITE_NAME_INTL.get(ln, CFG_SITE_NAME),
          'sitesupportemail' : '*****@*****.**',

          'msg_search' : _("Search"),
          'msg_help' : _("Help"),

          'msg_poweredby' : _("Powered by"),
          'msg_maintainedby' : _("Problems/Questions to"),

          'msg_lastupdated' : msg_lastupdated,
          'languagebox' : self.tmpl_language_selection_box(req, ln),
          'version' : self.trim_version(CFG_VERSION),

          'pagefooteradd' : pagefooteradd,

          }
        return out
Ejemplo n.º 7
0
    def tmpl_pagefooter(self, req=None, ln=CFG_SITE_LANG, lastupdated=None, pagefooteradd=""):
        """Creates a page footer

           Parameters:

          - 'ln' *string* - The language to display

          - 'lastupdated' *string* - when the page was last updated

          - 'pagefooteradd' *string* - additional page footer HTML code

           Output:

          - HTML code of the page headers
        """

        # load the right message language
        _ = gettext_set_language(ln)

        if lastupdated and lastupdated != "$Date$":
            if lastupdated.startswith("$Date: ") or lastupdated.startswith("$Id: "):
                lastupdated = convert_datestruct_to_dategui(convert_datecvs_to_datestruct(lastupdated), ln=ln)
            msg_lastupdated = _("Last updated") + ": " + lastupdated
        else:
            msg_lastupdated = ""

        out = """
<div class="pagefooter">
%(pagefooteradd)s
<!-- replaced page footer -->
 <div class="pagefooterstripeleft">
  %(sitename)s&nbsp;::&nbsp;<a class="footer" href="%(siteurl)s/?ln=%(ln)s">%(msg_search)s</a>&nbsp;::&nbsp;<a class="footer" href="%(siteurl)s/submit?ln=%(ln)s">%(msg_submit)s</a>&nbsp;::&nbsp;<a class="footer" href="%(sitesecureurl)s/youraccount/display?ln=%(ln)s">%(msg_personalize)s</a>&nbsp;::&nbsp;<a class="footer" href="%(siteurl)s/help/%(langlink)s">%(msg_help)s</a>
  <br />
  %(msg_poweredby)s <a class="footer" href="http://invenio-software.org/">Invenio</a> v%(version)s
  <br />
  %(msg_maintainedby)s <a class="footer" href="mailto:%(sitesupportemail)s">%(sitesupportemail)s</a>
  <br />
  %(msg_lastupdated)s
 </div>
 <div class="pagefooterstriperight">
  %(languagebox)s
 </div>
<!-- replaced page footer -->
</div>
</body>
</html>
        """ % {
            "siteurl": CFG_SITE_URL,
            "sitesecureurl": CFG_SITE_SECURE_URL,
            "ln": ln,
            "langlink": "?ln=" + ln,
            "sitename": CFG_SITE_NAME_INTL.get(ln, CFG_SITE_NAME),
            "sitesupportemail": CFG_SITE_SUPPORT_EMAIL,
            "msg_search": _("Search"),
            "msg_submit": _("Submit"),
            "msg_personalize": _("Personalize"),
            "msg_help": _("Help"),
            "msg_poweredby": _("Powered by"),
            "msg_maintainedby": _("Maintained by"),
            "msg_lastupdated": msg_lastupdated,
            "languagebox": self.tmpl_language_selection_box(req, ln),
            "version": CFG_VERSION,
            "pagefooteradd": pagefooteradd,
        }
        return out
Ejemplo n.º 8
0
    def tmpl_pagefooter(self,
                        req=None,
                        ln=CFG_SITE_LANG,
                        lastupdated=None,
                        pagefooteradd=""):
        """Creates a page footer

           Parameters:

          - 'ln' *string* - The language to display

          - 'lastupdated' *string* - when the page was last updated

          - 'pagefooteradd' *string* - additional page footer HTML code

           Output:

          - HTML code of the page headers
        """

        # load the right message language
        _ = gettext_set_language(ln)

        if lastupdated and lastupdated != '$Date$':
            if lastupdated.startswith("$Date: ") or \
            lastupdated.startswith("$Id: "):
                lastupdated = convert_datestruct_to_dategui(\
                                 convert_datecvs_to_datestruct(lastupdated),
                                 ln=ln)
            msg_lastupdated = _("Last updated") + ": " + lastupdated
        else:
            msg_lastupdated = ""

        out = """
<div class="pagefooter">
%(pagefooteradd)s
<!-- replaced page footer -->
 <div class="pagefooterstripeleft">
  %(sitename)s&nbsp;::&nbsp;<a class="footer" href="%(siteurl)s/?ln=%(ln)s">%(msg_search)s</a>&nbsp;::&nbsp;<a class="footer" href="%(siteurl)s/submit?ln=%(ln)s">%(msg_submit)s</a>&nbsp;::&nbsp;<a class="footer" href="%(sitesecureurl)s/youraccount/display?ln=%(ln)s">%(msg_personalize)s</a>&nbsp;::&nbsp;<a class="footer" href="%(siteurl)s/help/%(langlink)s">%(msg_help)s</a>
  <br />
  %(msg_poweredby)s <a class="footer" href="http://invenio-software.org/">Invenio</a> v%(version)s
  <br />
  %(msg_maintainedby)s <a class="footer" href="mailto:%(sitesupportemail)s">%(sitesupportemail)s</a>
  <br />
  %(msg_lastupdated)s
 </div>
 <div class="pagefooterstriperight">
  %(languagebox)s
 </div>
<!-- replaced page footer -->
</div>
</body>
</html>
        """ % {
            'siteurl': CFG_SITE_URL,
            'sitesecureurl': CFG_SITE_SECURE_URL,
            'ln': ln,
            'langlink': '?ln=' + ln,
            'sitename': CFG_SITE_NAME_INTL.get(ln, CFG_SITE_NAME),
            'sitesupportemail': CFG_SITE_SUPPORT_EMAIL,
            'msg_search': _("Search"),
            'msg_submit': _("Submit"),
            'msg_personalize': _("Personalize"),
            'msg_help': _("Help"),
            'msg_poweredby': _("Powered by"),
            'msg_maintainedby': _("Maintained by"),
            'msg_lastupdated': msg_lastupdated,
            'languagebox': self.tmpl_language_selection_box(req, ln),
            'version': CFG_VERSION,
            'pagefooteradd': pagefooteradd,
        }
        return out
Ejemplo n.º 9
0
    def tmpl_pagefooter(self, req=None, ln=CFG_SITE_LANG, lastupdated=None,
                        pagefooteradd=""):
        """Creates a page footer

           Parameters:

          - 'ln' *string* - The language to display

          - 'lastupdated' *string* - when the page was last updated

          - 'pagefooteradd' *string* - additional page footer HTML code

           Output:

          - HTML code of the page headers
        """
        try:
            from invenio.config import CFG_PIWIK
            tracking_code = """<!-- Piwik -->
                                <script type='text/javascript'>
                                  var _paq = _paq || [];
                                  _paq.push(['trackPageView']);
                                  _paq.push(['enableLinkTracking']);
                                  (function() {{
                                    var u='//piwik.tind.io/';
                                    _paq.push(['setTrackerUrl', u+'piwik.php']);
                                    _paq.push(['setSiteId', {0}]);
                                    var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
                                    g.type='text/javascript'; g.async=true; g.defer=true; g.src=u+'piwik.js'; s.parentNode.insertBefore(g,s);
                                  }})();
                                </script>
                                <noscript><p><img src='//piwik.tind.io/piwik.php?idsite={0}' style='border:0;' alt='' /></p></noscript>
                               <!-- End Piwik Code -->""".format(CFG_PIWIK)


        except:
            tracking_code = ""
        # load the right message language
        _ = gettext_set_language(ln)

        if lastupdated and lastupdated != '$Date$':
            if lastupdated.startswith("$Date: ") or \
            lastupdated.startswith("$Id: "):
                lastupdated = convert_datestruct_to_dategui(\
                                 convert_datecvs_to_datestruct(lastupdated),
                                 ln=ln)
            msg_lastupdated = _("Last updated") + ": " + lastupdated
        else:
            msg_lastupdated = ""

        out = """
<div class="pagefooter">
%(pagefooteradd)s
<!-- replaced page footer -->
 <div class="pagefooterstripeleft">
  %(sitename)s&nbsp;::&nbsp;<a class="footer" href="%(siteurl)s/?ln=%(ln)s">%(msg_search)s</a>&nbsp;::&nbsp;<a class="footer" href="%(siteurl)s/submit?ln=%(ln)s">%(msg_submit)s</a>&nbsp;::&nbsp;<a class="footer" href="%(sitesecureurl)s/youraccount/display?ln=%(ln)s">%(msg_personalize)s</a>&nbsp;::&nbsp;<a class="footer" href="%(siteurl)s/help/%(langlink)s">%(msg_help)s</a>
  <br />
  %(msg_poweredby)s <a class="footer" href="http://invenio-software.org/">Invenio</a> v%(version)s
  <br />
  %(msg_maintainedby)s <a class="footer" href="mailto:%(sitesupportemail)s">%(sitesupportemail)s</a>
  <br />
  %(msg_lastupdated)s
 </div>
 <div class="pagefooterstriperight">
  %(languagebox)s
 </div>
  %(tracking_code)s
<!-- replaced page footer -->
</div>
</body>
</html>
        """ % {
          'siteurl': CFG_BASE_URL,
          'sitesecureurl': CFG_SITE_SECURE_URL,
          'ln': ln,
          'langlink': '?ln=' + ln,

          'sitename': CFG_SITE_NAME_INTL.get(ln, CFG_SITE_NAME),
          'sitesupportemail': CFG_SITE_SUPPORT_EMAIL,

          'msg_search': _("Search"),
          'msg_submit': _("Submit"),
          'msg_personalize': _("Personalize"),
          'msg_help': _("Help"),

          'msg_poweredby': _("Powered by"),
          'msg_maintainedby': _("Maintained by"),

          'msg_lastupdated': msg_lastupdated,
          'languagebox': self.tmpl_language_selection_box(req, ln),
          'version': CFG_VERSION,

          'pagefooteradd': pagefooteradd,
          'tracking_code': tracking_code,
        }
        return out
Ejemplo n.º 10
0
    def tmpl_pagefooter(self, req=None, ln=CFG_SITE_LANG, lastupdated=None,
                        pagefooteradd=""):
        """Creates a page footer

        Parameters:

        - 'ln' *string* - The language to display

        - 'lastupdated' *string* - when the page was last updated

        - 'pagefooteradd' *string* - additional page footer HTML code

        Output:

        - HTML code of the page headers
        """
        from invenio.search_engine import guess_primary_collection_of_a_record

        # load the right message language
        _ = gettext_set_language(ln)

        if lastupdated and lastupdated != '$Date$':
            if lastupdated.startswith("$Date: ") or \
            lastupdated.startswith("$Id: "):
                lastupdated = convert_datestruct_to_dategui(\
                                 convert_datecvs_to_datestruct(lastupdated),
                                 ln=ln)
            msg_lastupdated = _("Last updated") + ": " + lastupdated
        else:
            msg_lastupdated = ""

        # Prepare Piwik custom variables if we are in a detailed record page

        custom_variables = ""
        record_collection = ""
        page_type = ""

        parsed_uri = urlparse(req.unparsed_uri)

        # HACK: I know it's horrible code. :-(
        record_page_match = re.match("^/record/(?P<recid>[0-9]+)(/(?P<page_type>.+)?)?$", parsed_uri.path)
        if record_page_match:
            record_collection = guess_primary_collection_of_a_record(record_page_match.group('recid'))
            page_type = record_page_match.group('page_type') or 'detailed'
        if re.match("^/search/?$", parsed_uri.path):
            cc = parse_qs(parsed_uri.query).get('cc', [CFG_SITE_NAME])
            record_collection = cc.pop()
        collection_page_match = re.match("^/$|^/collection/(?P<collection>.+)/?$", parsed_uri.path)
        if collection_page_match:
            record_collection = collection_page_match.groupdict().get('collection', CFG_SITE_NAME)
        if record_collection:
            custom_variables = """\
_paq.push(['setCustomVariable',
          1, // Index, the number from 1 to 5 where this custom variable name is stored
          "Collection", // Name, the name of the variable
          %(collection_name)s, // Value
          "page" // Scope of the custom variable
          ]);
          """ % {
                'collection_name': js_escape(record_collection)
            }

        if page_type:
            custom_variables += """\
_paq.push(['setCustomVariable',
          2,
          "Type",
          %(page_type)s,
          "page"
          ]);
_paq.push(['setCustomVariable',
          3,
          "CollectionType",
          %(page_collection_type)s,
          "page"
          ]);
          """ % {
                'page_type': js_escape(page_type),
                'page_collection_type': js_escape(record_collection + page_type)
            }

        out = """\
<div class="pagefooter">
%(pagefooteradd)s
<!-- replaced page footer -->
 <div class="pagefooterstripeleft">
  %(sitename)s&nbsp;::&nbsp;<a class="footer" href="%(siteurl)s/?ln=%(ln)s">%(msg_search)s</a>&nbsp;::&nbsp;
  <a class="footer" href="%(siteurl)s/help/%(langlink)s">%(msg_help)s</a>&nbsp;::&nbsp;
  <a class="footer" href="%(siteurl)s/info/general/terms-of-use">%(msg_terms)s</a>&nbsp;::&nbsp;
  <a class="footer" href="%(siteurl)s/info/general/privacy-policy">%(msg_privacy)s</a>
  <br />
  %(msg_poweredby)s <a class="footer" href="http://invenio-software.org/">Invenio</a> v%(version)s
  <br />
  %(msg_maintainedby)s <a class="footer" href="mailto:%(sitesupportemail)s">%(sitesupportemail)s</a>
  <br />
  %(msg_lastupdated)s
 </div>
 <div class="pagefooterstriperight">
  %(languagebox)s
 </div>
<!-- replaced page footer -->
</div>
""" % {
          'siteurl' : CFG_BASE_URL,
          'sitesecureurl' : CFG_SITE_SECURE_URL,
          'ln' : ln,
          'langlink': '?ln=' + ln,

          'sitename' : CFG_SITE_NAME_INTL.get(ln, CFG_SITE_NAME),
          'sitesupportemail' : '*****@*****.**',

          'msg_search' : _("Search"),
          'msg_help' : _("Help"),

          'msg_terms': _("Terms of use"),
          'msg_privacy': _("Privacy policy"),

          'msg_poweredby' : _("Powered by"),
          'msg_maintainedby' : _("Problems/Questions to"),

          'msg_lastupdated' : msg_lastupdated,
          'languagebox' : self.tmpl_language_selection_box(req, ln),
          'version' : self.trim_version(CFG_VERSION),

          'pagefooteradd' : pagefooteradd,
          }
        if not isUserAdmin(collect_user_info(req)):
            out += """\
<!-- Piwik -->
<script type="text/javascript">
  try {
    var _paq = _paq || [];
    _paq.push(['trackPageView']);
    _paq.push(['enableLinkTracking']);
    (function() {
        var u="//piwik.inspirehep.net/";
        _paq.push(['setTrackerUrl', u+'piwik.php']);
        _paq.push(['setSiteId', 8]);
        %(custom_variables)s
        var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
        g.type='text/javascript'; g.async=true; g.defer=true; g.src=u+'piwik.js'; s.parentNode.insertBefore(g,s);
    })();}
    catch(err) {
        (function() {
            var img = document.createElement('img');
            img.src = '//piwik.inspirehep.net/piwik.php?idsite=8&amp;rec=1&amp;bots=1';
            document.body.appendChild(img);
    })();
    }
</script>
<noscript><p><img src="//piwik.inspirehep.net/piwik.php?idsite=8&amp;rec=1&amp;bots=1" style="border:0;" alt="" /></p></noscript>
<!-- End Piwik Code -->
""" % {'custom_variables': custom_variables}

        out += """\
</body>
</html>
"""
        return out
Ejemplo n.º 11
0
    def tmpl_pagefooter(self,
                        req=None,
                        ln=CFG_SITE_LANG,
                        lastupdated=None,
                        pagefooteradd=""):
        """Creates a page footer

        Parameters:

        - 'ln' *string* - The language to display

        - 'lastupdated' *string* - when the page was last updated

        - 'pagefooteradd' *string* - additional page footer HTML code

        Output:

        - HTML code of the page headers
        """
        from invenio.search_engine import guess_primary_collection_of_a_record

        # load the right message language
        _ = gettext_set_language(ln)

        if lastupdated and lastupdated != '$Date$':
            if lastupdated.startswith("$Date: ") or \
            lastupdated.startswith("$Id: "):
                lastupdated = convert_datestruct_to_dategui(\
                                 convert_datecvs_to_datestruct(lastupdated),
                                 ln=ln)
            msg_lastupdated = _("Last updated") + ": " + lastupdated
        else:
            msg_lastupdated = ""

        # Prepare Piwik custom variables if we are in a detailed record page
        record_page_re = re.compile(
            "^/record/(?P<recid>[0-9]+)/?(?P<page_type>.*)")

        custom_variables = ""

        record_page_match = record_page_re.match(req.uri)
        if record_page_match:
            record_collection = guess_primary_collection_of_a_record(
                record_page_match.group('recid'))
            custom_variables = """
_paq.push(['setCustomVariable',
          1, // Index, the number from 1 to 5 where this custom variable name is stored
          "Collection", // Name, the name of the variable
          "%(collection_name)s", // Value
          "page" // Scope of the custom variable
          ]);
          """ % {
                'collection_name': record_collection
            }

            if record_page_match.group('page_type'):
                custom_variables += """
_paq.push(['setCustomVariable',
          2,
          "Type",
          "%(page_type)s",
          "page"
          ]);
_paq.push(['setCustomVariable',
          3,
          "CollectionType",
          "%(page_collection_type)s",
          "page"
          ]);
          """ % {
                    'page_type':
                    record_page_match.group('page_type'),
                    'page_collection_type':
                    record_collection + record_page_match.group('page_type')
                }

        out = """
<div class="pagefooter">
%(pagefooteradd)s
<!-- replaced page footer -->
 <div class="pagefooterstripeleft">
  %(sitename)s&nbsp;::&nbsp;<a class="footer" href="%(siteurl)s/?ln=%(ln)s">%(msg_search)s</a>&nbsp;::&nbsp;
  <a class="footer" href="%(siteurl)s/help/%(langlink)s">%(msg_help)s</a>&nbsp;::&nbsp;
  <a class="footer" href="%(siteurl)s/info/general/terms-of-use">%(msg_terms)s</a>&nbsp;::&nbsp;
  <a class="footer" href="%(siteurl)s/info/general/privacy-policy">%(msg_privacy)s</a>
  <br />
  %(msg_poweredby)s <a class="footer" href="http://invenio-software.org/">Invenio</a> v%(version)s
  <br />
  %(msg_maintainedby)s <a class="footer" href="mailto:%(sitesupportemail)s">%(sitesupportemail)s</a>
  <br />
  %(msg_lastupdated)s
 </div>
 <div class="pagefooterstriperight">
  %(languagebox)s
 </div>
<!-- replaced page footer -->
</div>
<!-- Piwik -->
 <script type="text/javascript">
 var _paq = _paq || [];
 (function(){ var u=(("https:" == document.location.protocol) ? "https://inspirehep.net/piwik/" : "http://inspirehep.net/piwik/");
 _paq.push(['setSiteId', '8']);
 %(custom_variables)s
 _paq.push(['setTrackerUrl', u+'piwik.php']);
 _paq.push(['trackPageView']);
 _paq.push(['enableLinkTracking']);
 var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0]; g.type='text/javascript'; g.defer=true; g.async=true; g.src=u+'piwik.js';
 s.parentNode.insertBefore(g,s); })();
  </script>
  <noscript><p><img src="http://inspirehep.net/piwik/piwik.php?idsite=8" style="border:0" alt="" /></p></noscript>
  <!-- End Piwik Code -->
</body>
</html>
        """ % {
            'siteurl': CFG_BASE_URL,
            'sitesecureurl': CFG_SITE_SECURE_URL,
            'ln': ln,
            'langlink': '?ln=' + ln,
            'sitename': CFG_SITE_NAME_INTL.get(ln, CFG_SITE_NAME),
            'sitesupportemail': '*****@*****.**',
            'msg_search': _("Search"),
            'msg_help': _("Help"),
            'msg_terms': _("Terms of use"),
            'msg_privacy': _("Privacy policy"),
            'msg_poweredby': _("Powered by"),
            'msg_maintainedby': _("Problems/Questions to"),
            'msg_lastupdated': msg_lastupdated,
            'languagebox': self.tmpl_language_selection_box(req, ln),
            'version': self.trim_version(CFG_VERSION),
            'pagefooteradd': pagefooteradd,
            'custom_variables': custom_variables
        }
        return out
    def tmpl_pagefooter(self, req=None, ln=CFG_SITE_LANG, lastupdated=None,
                        pagefooteradd=""):
        """Creates a page footer

        Parameters:

        - 'ln' *string* - The language to display

        - 'lastupdated' *string* - when the page was last updated

        - 'pagefooteradd' *string* - additional page footer HTML code

        Output:

        - HTML code of the page headers
        """
        from invenio.search_engine import guess_primary_collection_of_a_record

        # load the right message language
        _ = gettext_set_language(ln)

        if lastupdated and lastupdated != '$Date$':
            if lastupdated.startswith("$Date: ") or \
            lastupdated.startswith("$Id: "):
                lastupdated = convert_datestruct_to_dategui(\
                                 convert_datecvs_to_datestruct(lastupdated),
                                 ln=ln)
            msg_lastupdated = _("Last updated") + ": " + lastupdated
        else:
            msg_lastupdated = ""

        # Prepare Piwik custom variables if we are in a detailed record page
        record_page_re = re.compile("^/record/(?P<recid>[0-9]+)/?(?P<page_type>.*)")

        custom_variables = ""

        record_page_match = record_page_re.match(req.uri)
        if record_page_match:
          record_collection = guess_primary_collection_of_a_record(record_page_match.group('recid'))
          custom_variables = """
_paq.push(['setCustomVariable',
          1, // Index, the number from 1 to 5 where this custom variable name is stored
          "Collection", // Name, the name of the variable
          "%(collection_name)s", // Value
          "page" // Scope of the custom variable
          ]);
          """ % {
            'collection_name': record_collection
          }

          if record_page_match.group('page_type'):
            custom_variables += """
_paq.push(['setCustomVariable',
          2,
          "Type",
          "%(page_type)s",
          "page"
          ]);
_paq.push(['setCustomVariable',
          3,
          "CollectionType",
          "%(page_collection_type)s",
          "page"
          ]);
          """ % {
            'page_type': record_page_match.group('page_type'),
            'page_collection_type': record_collection + record_page_match.group('page_type')
          }

        out = """
<div class="pagefooter">
%(pagefooteradd)s
<!-- replaced page footer -->
 <div class="pagefooterstripeleft">
  %(sitename)s&nbsp;::&nbsp;<a class="footer" href="%(siteurl)s/?ln=%(ln)s">%(msg_search)s</a>&nbsp;::&nbsp;
  <a class="footer" href="%(siteurl)s/help/%(langlink)s">%(msg_help)s</a>&nbsp;::&nbsp;
  <a class="footer" href="%(siteurl)s/info/general/terms-of-use">%(msg_terms)s</a>&nbsp;::&nbsp;
  <a class="footer" href="%(siteurl)s/info/general/privacy-policy">%(msg_privacy)s</a>
  <br />
  %(msg_poweredby)s <a class="footer" href="http://invenio-software.org/">Invenio</a> v%(version)s
  <br />
  %(msg_maintainedby)s <a class="footer" href="mailto:%(sitesupportemail)s">%(sitesupportemail)s</a>
  <br />
  %(msg_lastupdated)s
 </div>
 <div class="pagefooterstriperight">
  %(languagebox)s
 </div>
<!-- replaced page footer -->
</div>
<!-- Piwik -->
 <script type="text/javascript">
 var _paq = _paq || [];
 (function(){ var u=(("https:" == document.location.protocol) ? "https://inspirehep.net/piwik/" : "http://inspirehep.net/piwik/");
 _paq.push(['setSiteId', '8']);
 %(custom_variables)s
 _paq.push(['setTrackerUrl', u+'piwik.php']);
 _paq.push(['trackPageView']);
 _paq.push(['enableLinkTracking']);
 var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0]; g.type='text/javascript'; g.defer=true; g.async=true; g.src=u+'piwik.js';
 s.parentNode.insertBefore(g,s); })();
  </script>
  <noscript><p><img src="http://inspirehep.net/piwik/piwik.php?idsite=8" style="border:0" alt="" /></p></noscript>
  <!-- End Piwik Code -->
</body>
</html>
        """ % {
          'siteurl' : CFG_BASE_URL,
          'sitesecureurl' : CFG_SITE_SECURE_URL,
          'ln' : ln,
          'langlink': '?ln=' + ln,

          'sitename' : CFG_SITE_NAME_INTL.get(ln, CFG_SITE_NAME),
          'sitesupportemail' : '*****@*****.**',

          'msg_search' : _("Search"),
          'msg_help' : _("Help"),

          'msg_terms': _("Terms of use"),
          'msg_privacy': _("Privacy policy"),

          'msg_poweredby' : _("Powered by"),
          'msg_maintainedby' : _("Problems/Questions to"),

          'msg_lastupdated' : msg_lastupdated,
          'languagebox' : self.tmpl_language_selection_box(req, ln),
          'version' : self.trim_version(CFG_VERSION),

          'pagefooteradd' : pagefooteradd,
          'custom_variables': custom_variables
          }
        return out
    def tmpl_pagefooter(self, req=None, ln=CFG_SITE_LANG, lastupdated=None,
                        pagefooteradd=""):
        """Creates a page footer

           Parameters:

          - 'ln' *string* - The language to display

          - 'lastupdated' *string* - when the page was last updated

          - 'pagefooteradd' *string* - additional page footer HTML code

           Output:

          - HTML code of the page headers
        """

        # load the right message language
        _ = gettext_set_language(ln)

        if lastupdated and lastupdated != '$Date$':
            if lastupdated.startswith("$Date: ") or \
            lastupdated.startswith("$Id: "):
                lastupdated = convert_datestruct_to_dategui(\
                                 convert_datecvs_to_datestruct(lastupdated),
                                 ln=ln)
            msg_lastupdated = _("Last updated") + ": " + lastupdated
        else:
            msg_lastupdated = ""

        out = """
<div class="pagefooter">
%(pagefooteradd)s
<!-- replaced page footer -->
 <div class="pagefooterstripeleft" style="padding-top: 10px;">
  <img style="margin-left: 10px; margin-right: 10px; float: left;" alt="fp7-capacities" src="/img/fp7_sm.png" height="46" width="60">
  <img style="margin-right: 10px; margin-top: 5px; float: left;" alt="e_infrastructures" src="/img/einfra_sm.png" height="33" width="90">
  <div style="float: left; margin-bottom: 10px;">
  %(sitename)s&nbsp;::&nbsp;<a class="footer" href="%(siteurl)s/?ln=%(ln)s">%(msg_search)s</a>&nbsp;::&nbsp;<a class="footer" href="%(siteurl)s/submit?ln=%(ln)s">%(msg_submit)s</a>&nbsp;::&nbsp;<a class="footer" href="%(sitesecureurl)s/youraccount/display?ln=%(ln)s">%(msg_personalize)s</a>&nbsp;::&nbsp;<a class="footer" href="%(siteurl)s/help/%(langlink)s">%(msg_help)s</a>
  <br />
  %(msg_poweredby)s <a class="footer" href="http://invenio-software.org/">Invenio</a> v%(version)s
  <br />
  %(msg_maintainedby)s <a class="footer" href="mailto:%(sitesupportemail)s">%(sitesupportemail)s</a>
  <br />
  %(msg_lastupdated)s
  </div>
 </div>
 <div class="pagefooterstriperight">
  %(languagebox)s
 </div>
<!-- replaced page footer -->
</div>
<!-- Piwik -->
<script type="text/javascript">
var pkBaseURL = (("https:" == document.location.protocol) ? "https://analytics.openaire.eu/" : "http://analytics.openaire.eu/");
document.write(unescape("%%3Cscript src='" + pkBaseURL + "piwik.js' type='text/javascript'%%3E%%3C/script%%3E"));
</script><script type="text/javascript">
try {
var piwikTracker = Piwik.getTracker(pkBaseURL + "piwik.php", 2);
piwikTracker.trackPageView();
piwikTracker.enableLinkTracking();
} catch( err ) {}
</script><noscript><p><img src="https://analytics.openaire.eu/piwik.php?idsite=2" style="border:0" alt="" /></p></noscript>
<!-- End Piwik Tag -->
</body>
</html>
        """ % {
          'siteurl' : CFG_SITE_URL,
          'sitesecureurl' : CFG_SITE_SECURE_URL,
          'ln' : ln,
          'langlink': '?ln=' + ln,

          'sitename' : CFG_SITE_NAME_INTL.get(ln, CFG_SITE_NAME),
          'sitesupportemail' : CFG_SITE_SUPPORT_EMAIL,

          'msg_search' : _("Search"),
          'msg_submit' : _("Submit"),
          'msg_personalize' : _("Personalize"),
          'msg_help' : _("Help"),

          'msg_poweredby' : _("Powered by"),
          'msg_maintainedby' : _("Maintained by"),

          'msg_lastupdated' : msg_lastupdated,
          'languagebox' : self.tmpl_language_selection_box(req, ln),
          'version' : CFG_VERSION,

          'pagefooteradd' : pagefooteradd,

        }
        return out
Ejemplo n.º 14
0
    def tmpl_pagefooter(self,
                        req=None,
                        ln=CFG_SITE_LANG,
                        lastupdated=None,
                        pagefooteradd=""):
        """Creates a page footer

        Parameters:

        - 'ln' *string* - The language to display

        - 'lastupdated' *string* - when the page was last updated

        - 'pagefooteradd' *string* - additional page footer HTML code

        Output:

        - HTML code of the page headers
        """
        from invenio.search_engine import guess_primary_collection_of_a_record

        # load the right message language
        _ = gettext_set_language(ln)

        if lastupdated and lastupdated != '$Date$':
            if lastupdated.startswith("$Date: ") or \
            lastupdated.startswith("$Id: "):
                lastupdated = convert_datestruct_to_dategui(\
                                 convert_datecvs_to_datestruct(lastupdated),
                                 ln=ln)
            msg_lastupdated = _("Last updated") + ": " + lastupdated
        else:
            msg_lastupdated = ""

        # Prepare Piwik custom variables if we are in a detailed record page

        custom_variables = ""
        record_collection = ""
        page_type = ""

        parsed_uri = urlparse(req.unparsed_uri)

        # HACK: I know it's horrible code. :-(
        record_page_match = re.match(
            "^/record/(?P<recid>[0-9]+)(/(?P<page_type>.+)?)?$",
            parsed_uri.path)
        if record_page_match:
            record_collection = guess_primary_collection_of_a_record(
                record_page_match.group('recid'))
            page_type = record_page_match.group('page_type') or 'detailed'
        if re.match("^/search/?$", parsed_uri.path):
            cc = parse_qs(parsed_uri.query).get('cc', [CFG_SITE_NAME])
            record_collection = cc.pop()
        collection_page_match = re.match(
            "^/$|^/collection/(?P<collection>.+)/?$", parsed_uri.path)
        if collection_page_match:
            record_collection = collection_page_match.groupdict().get(
                'collection', CFG_SITE_NAME)
        if record_collection:
            custom_variables = """\
_paq.push(['setCustomVariable',
          1, // Index, the number from 1 to 5 where this custom variable name is stored
          "Collection", // Name, the name of the variable
          %(collection_name)s, // Value
          "page" // Scope of the custom variable
          ]);
          """ % {
                'collection_name': js_escape(record_collection)
            }

        if page_type:
            custom_variables += """\
_paq.push(['setCustomVariable',
          2,
          "Type",
          %(page_type)s,
          "page"
          ]);
_paq.push(['setCustomVariable',
          3,
          "CollectionType",
          %(page_collection_type)s,
          "page"
          ]);
          """ % {
                'page_type': js_escape(page_type),
                'page_collection_type':
                js_escape(record_collection + page_type)
            }

        out = """\
<div class="pagefooter">
%(pagefooteradd)s
<!-- replaced page footer -->
 <div class="pagefooterstripeleft">
  %(sitename)s&nbsp;::&nbsp;<a class="footer" href="%(siteurl)s/?ln=%(ln)s">%(msg_search)s</a>&nbsp;::&nbsp;
  <a class="footer" href="%(siteurl)s/help/%(langlink)s">%(msg_help)s</a>&nbsp;::&nbsp;
  <a class="footer" href="%(siteurl)s/info/general/terms-of-use">%(msg_terms)s</a>&nbsp;::&nbsp;
  <a class="footer" href="%(siteurl)s/info/general/privacy-policy">%(msg_privacy)s</a>
  <br />
  %(msg_poweredby)s <a class="footer" href="http://invenio-software.org/">Invenio</a> v%(version)s
  <br />
  %(msg_maintainedby)s <a class="footer" href="mailto:%(sitesupportemail)s">%(sitesupportemail)s</a>
  <br />
  %(msg_lastupdated)s
 </div>
 <div class="pagefooterstriperight">
  %(languagebox)s
 </div>
<!-- replaced page footer -->
</div>
""" % {
            'siteurl': CFG_BASE_URL,
            'sitesecureurl': CFG_SITE_SECURE_URL,
            'ln': ln,
            'langlink': '?ln=' + ln,
            'sitename': CFG_SITE_NAME_INTL.get(ln, CFG_SITE_NAME),
            'sitesupportemail': '*****@*****.**',
            'msg_search': _("Search"),
            'msg_help': _("Help"),
            'msg_terms': _("Terms of use"),
            'msg_privacy': _("Privacy policy"),
            'msg_poweredby': _("Powered by"),
            'msg_maintainedby': _("Problems/Questions to"),
            'msg_lastupdated': msg_lastupdated,
            'languagebox': self.tmpl_language_selection_box(req, ln),
            'version': self.trim_version(CFG_VERSION),
            'pagefooteradd': pagefooteradd,
        }
        if not isUserAdmin(collect_user_info(req)):
            out += """\
<!-- Piwik -->
<script type="text/javascript">
  try {
    var _paq = _paq || [];
    _paq.push(['trackPageView']);
    _paq.push(['enableLinkTracking']);
    (function() {
        var u="//piwik.inspirehep.net/";
        _paq.push(['setTrackerUrl', u+'piwik.php']);
        _paq.push(['setSiteId', 8]);
        %(custom_variables)s
        var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
        g.type='text/javascript'; g.async=true; g.defer=true; g.src=u+'piwik.js'; s.parentNode.insertBefore(g,s);
    })();}
    catch(err) {
        (function() {
            var img = document.createElement('img');
            img.src = '//piwik.inspirehep.net/piwik.php?idsite=8&amp;rec=1&amp;bots=1';
            document.body.appendChild(img);
    })();
    }
</script>
<noscript><p><img src="//piwik.inspirehep.net/piwik.php?idsite=8&amp;rec=1&amp;bots=1" style="border:0;" alt="" /></p></noscript>
<!-- End Piwik Code -->
""" % {
                'custom_variables': custom_variables
            }

        out += """\
</body>
</html>
"""
        return out
Ejemplo n.º 15
0
    def tmpl_pagefooter(self, req=None, ln=CFG_SITE_LANG, lastupdated=None,
                        pagefooteradd=""):
        """Creates a page footer

           Parameters:

          - 'ln' *string* - The language to display

          - 'lastupdated' *string* - when the page was last updated

          - 'pagefooteradd' *string* - additional page footer HTML code

           Output:

          - HTML code of the page headers
        """

        # load the right message language
        _ = gettext_set_language(ln)

        if lastupdated and lastupdated != '$Date$':
            if lastupdated.startswith("$Date: ") or \
            lastupdated.startswith("$Id: "):
                lastupdated = convert_datestruct_to_dategui(\
                                 convert_datecvs_to_datestruct(lastupdated),
                                 ln=ln)
            msg_lastupdated = _("Last updated") + ": " + lastupdated
        else:
            msg_lastupdated = ""

        out = """
<div class="pagefooter">
%(pagefooteradd)s
<!-- replaced page footer -->
 <div class="pagefooterstripeleft">
 <!--
  %(sitename)s&nbsp;::&nbsp;<a class="footer" href="%(siteurl)s/?ln=%(ln)s">%(msg_search)s</a>&nbsp;::&nbsp;<a class="footer" href="%(siteurl)s/submit?ln=%(ln)s">%(msg_submit)s</a>&nbsp;::&nbsp;<a class="footer" href="%(sitesecureurl)s/youraccount/display?ln=%(ln)s">%(msg_personalize)s</a>&nbsp;::&nbsp;<a class="footer" href="%(siteurl)s/help/%(langlink)s">%(msg_help)s</a>
  <br />-->
  %(msg_poweredby)s <a class="footer" href="http://invenio-software.org/">Invenio</a> v%(version)s
  <br />
  %(msg_maintainedby)s <a class="footer" href="mailto:%(sitesupportemail)s">%(sitesupportemail)s</a>
  <br />
  %(msg_lastupdated)s
 </div>
 <div class="pagefooterstriperight">
 <p><em>
 Articles in the SCOAP3 repository are released under a <a target="_blank" rel="license" href="http://creativecommons.org/licenses/by/3.0/"><strong>CC-BY</strong></a> license. Metadata are provided by the corresponding publishers and released under the <a target="_blank"  rel="license"
     href="http://creativecommons.org/publicdomain/zero/1.0/">
    <strong>CC0</strong>
  </a> waiver.
 </em></p>
  %(languagebox)s
 </div>
<!-- replaced page footer -->
</div>
<!-- Piwik -->
<script type="text/javascript">
  var _paq = _paq || [];
  _paq.push(["trackPageView"]);
  _paq.push(["enableLinkTracking"]);

  (function() {
    var u=(("https:" == document.location.protocol) ? "https" : "http") + "://cds-piwik.cern.ch/";
    _paq.push(["setTrackerUrl", u+"piwik.php"]);
    _paq.push(["setSiteId", "10"]);
    var d=document, g=d.createElement("script"), s=d.getElementsByTagName("script")[0]; g.type="text/javascript";
    g.defer=true; g.async=true; g.src=u+"piwik.js"; s.parentNode.insertBefore(g,s);
  })();
</script>
<noscript>
<!-- Piwik Image Tracker -->
<img src="https://cds-piwik.cern.ch/piwik.php?idsite=10&amp;rec=1" style="border:0" alt="" />
<!-- End Piwik -->
</noscript>
<!-- End Piwik Code -->

</body>
</html>
        """ % {
          'siteurl': CFG_BASE_URL,
          'sitesecureurl': CFG_SITE_SECURE_URL,
          'ln': ln,
          'langlink': '?ln=' + ln,

          'sitename': CFG_SITE_NAME_INTL.get(ln, CFG_SITE_NAME),
          'sitesupportemail': CFG_SITE_SUPPORT_EMAIL,

          'msg_search': _("Search"),
          'msg_submit': _("Submit"),
          'msg_personalize': _("Personalize"),
          'msg_help': _("Help"),

          'msg_poweredby': _("Powered by"),
          'msg_maintainedby': _("Maintained by"),

          'msg_lastupdated': msg_lastupdated,
          'languagebox': self.tmpl_language_selection_box(req, ln),
          'version': CFG_VERSION,

          'pagefooteradd': pagefooteradd,
        }
        return out
Ejemplo n.º 16
0
def transform(webdoc_source, verbose=0, req=None, languages=CFG_SITE_LANGS):
    """
    Transform a WebDoc into html

    This is made through a serie of transformations, mainly substitutions.

    Parameters:

      - webdoc_source   :  *string* the WebDoc input to transform to HTML
    """
    parameters = {}  # Will store values for specified parameters, such

    # as 'Title' for <!-- WebDoc-Page-Title: Title -->

    def get_param_and_remove(match):
        """
        Analyses 'match', get the parameter and return empty string to
        remove it.

        Called by substitution in 'transform(...)', used to collection
        parameters such as <!-- WebDoc-Page-Title: Title -->

        @param match: a match object corresponding to the special tag
        that must be interpreted
        """
        tag = match.group("tag")
        value = match.group("value")
        parameters[tag] = value
        return ''

    def translate(match):
        """
        Translate matching values
        """
        word = match.group("word")
        translated_word = _(word)
        return translated_word

    # 1 step
    ## First filter, used to remove comments
    ## and <protect> tags
    uncommented_webdoc = ''
    for line in webdoc_source.splitlines(True):
        if not line.strip().startswith('#'):
            uncommented_webdoc += line
    webdoc_source = uncommented_webdoc.replace('<protect>', '')
    webdoc_source = webdoc_source.replace('</protect>', '')

    html_texts = {}
    # Language dependent filters
    for ln in languages:
        _ = gettext_set_language(ln)

        # Check if translation is really needed
        ## Just a quick check. Might trigger false negative, but it is
        ## ok.
        if ln != CFG_SITE_LANG and \
           translation_pattern.search(webdoc_source) is None and \
           pattern_lang_link_current.search(webdoc_source) is None and \
           pattern_lang_current.search(webdoc_source) is None and \
           '<%s>' % ln not in webdoc_source and \
           ('_(') not in webdoc_source:
            continue

        # 2 step
        ## Filter used to translate string in _(..)_
        localized_webdoc = translation_pattern.sub(translate, webdoc_source)

        # 3 step
        ## Print current language 'en', 'fr', .. instead of
        ## <lang:current /> tags and '?ln=en', '?ln=fr', .. instead of
        ## <lang:link />
        localized_webdoc = pattern_lang_link_current.sub(
            '?ln=' + ln, localized_webdoc)
        localized_webdoc = pattern_lang_current.sub(ln, localized_webdoc)

        # 4 step
        ## Filter out languages
        localized_webdoc = filter_languages(localized_webdoc, ln, defined_tags)

        # 5 Step
        ## Replace defined tags with their value from config file
        ## Eg. replace <CFG_SITE_URL> with 'http://cdsweb.cern.ch/':
        for defined_tag, value in defined_tags.iteritems():
            if defined_tag.upper() == '<CFG_SITE_NAME_INTL>':
                localized_webdoc = localized_webdoc.replace(defined_tag, \
                                                            value.get(ln, value['en']))
            else:
                localized_webdoc = localized_webdoc.replace(defined_tag, value)

        # 6 step
        ## Get the parameters defined in HTML comments, like
        ## <!-- WebDoc-Page-Title: My Title -->
        localized_body = localized_webdoc
        for tag, pattern in pattern_tags.iteritems():
            localized_body = pattern.sub(get_param_and_remove, localized_body)

        out = localized_body

        # Pre-process date
        last_updated = parameters.get('WebDoc-Page-Revision', '')
        last_updated = convert_datecvs_to_datestruct(last_updated)
        last_updated = convert_datestruct_to_datetext(last_updated)

        html_texts[ln] = (ln, out, parameters.get('WebDoc-Page-Title'),
                          parameters.get('WebDoc-Page-Keywords'),
                          parameters.get('WebDoc-Page-Navtrail'), last_updated,
                          parameters.get('WebDoc-Page-Description'))

    # Remove duplicates
    filtered_html_texts = []
    if html_texts.has_key(CFG_SITE_LANG):
        filtered_html_texts = [(html_text[0], \
                                (html_text[1] != html_texts[CFG_SITE_LANG][1] and html_text[1]) or None, \
                                (html_text[2] != html_texts[CFG_SITE_LANG][2] and html_text[2]) or None, \
                                (html_text[3] != html_texts[CFG_SITE_LANG][3] and html_text[3]) or None, \
                                (html_text[4] != html_texts[CFG_SITE_LANG][4] and html_text[4]) or None, \
                                (html_text[5] != html_texts[CFG_SITE_LANG][5] and html_text[5]) or None, \
                                (html_text[6] != html_texts[CFG_SITE_LANG][6] and html_text[6]) or None)
                               for html_text in html_texts.values() \
                               if html_text[0] != CFG_SITE_LANG]
        filtered_html_texts.append(html_texts[CFG_SITE_LANG])
    else:
        filtered_html_texts = html_texts.values()

    return filtered_html_texts
Ejemplo n.º 17
0
def transform(webdoc_source, verbose=0, req=None, languages=CFG_SITE_LANGS):
    """
    Transform a WebDoc into html

    This is made through a serie of transformations, mainly substitutions.

    Parameters:

      - webdoc_source   :  *string* the WebDoc input to transform to HTML
    """
    parameters = {} # Will store values for specified parameters, such
                    # as 'Title' for <!-- WebDoc-Page-Title: Title -->

    def get_param_and_remove(match):
        """
        Analyses 'match', get the parameter and return empty string to
        remove it.

        Called by substitution in 'transform(...)', used to collection
        parameters such as <!-- WebDoc-Page-Title: Title -->

        @param match: a match object corresponding to the special tag
        that must be interpreted
        """
        tag = match.group("tag")
        value = match.group("value")
        parameters[tag] = value
        return ''

    def translate(match):
        """
        Translate matching values
        """
        word = match.group("word")
        translated_word = _(word)
        return translated_word

    # 1 step
    ## First filter, used to remove comments
    ## and <protect> tags
    uncommented_webdoc = ''
    for line in webdoc_source.splitlines(True):
        if not line.strip().startswith('#'):
            uncommented_webdoc += line
    webdoc_source = uncommented_webdoc.replace('<protect>', '')
    webdoc_source = webdoc_source.replace('</protect>', '')

    html_texts = {}
    # Language dependent filters
    for ln in languages:
        _ = gettext_set_language(ln)

        # Check if translation is really needed
        ## Just a quick check. Might trigger false negative, but it is
        ## ok.
        if ln != CFG_SITE_LANG and \
           translation_pattern.search(webdoc_source) is None and \
           pattern_lang_link_current.search(webdoc_source) is None and \
           pattern_lang_current.search(webdoc_source) is None and \
           '<%s>' % ln not in webdoc_source and \
           ('_(') not in webdoc_source:
            continue

        # 2 step
        ## Filter used to translate string in _(..)_
        localized_webdoc = translation_pattern.sub(translate, webdoc_source)

        # 3 step
        ## Print current language 'en', 'fr', .. instead of
        ## <lang:current /> tags and '?ln=en', '?ln=fr', .. instead of
        ## <lang:link /> if ln is not default language
        if ln != CFG_SITE_LANG:
            localized_webdoc = pattern_lang_link_current.sub('?ln=' + ln,
                                                             localized_webdoc)
        else:
            localized_webdoc = pattern_lang_link_current.sub('',
                                                             localized_webdoc)
        localized_webdoc = pattern_lang_current.sub(ln, localized_webdoc)

        # 4 step
        ## Filter out languages
        localized_webdoc = filter_languages(localized_webdoc, ln, defined_tags)

        # 5 Step
        ## Replace defined tags with their value from config file
        ## Eg. replace <CFG_SITE_URL> with 'http://cdsweb.cern.ch/':
        for defined_tag, value in defined_tags.iteritems():
            if defined_tag.upper() == '<CFG_SITE_NAME_INTL>':
                localized_webdoc = localized_webdoc.replace(defined_tag, \
                                                            value.get(ln, value['en']))
            else:
                localized_webdoc = localized_webdoc.replace(defined_tag, value)

        # 6 step
        ## Get the parameters defined in HTML comments, like
        ## <!-- WebDoc-Page-Title: My Title -->
        localized_body = localized_webdoc
        for tag, pattern in pattern_tags.iteritems():
            localized_body = pattern.sub(get_param_and_remove, localized_body)

        out = localized_body

        # Pre-process date
        last_updated = parameters.get('WebDoc-Page-Revision', '')
        last_updated = convert_datecvs_to_datestruct(last_updated)
        last_updated = convert_datestruct_to_datetext(last_updated)

        html_texts[ln] = (ln,
                          out,
                          parameters.get('WebDoc-Page-Title'),
                          parameters.get('WebDoc-Page-Keywords'),
                          parameters.get('WebDoc-Page-Navtrail'),
                          last_updated,
                          parameters.get('WebDoc-Page-Description'))

    # Remove duplicates
    filtered_html_texts = []
    if html_texts.has_key(CFG_SITE_LANG):
        filtered_html_texts = [(html_text[0], \
                                (html_text[1] != html_texts[CFG_SITE_LANG][1] and html_text[1]) or None, \
                                (html_text[2] != html_texts[CFG_SITE_LANG][2] and html_text[2]) or None, \
                                (html_text[3] != html_texts[CFG_SITE_LANG][3] and html_text[3]) or None, \
                                (html_text[4] != html_texts[CFG_SITE_LANG][4] and html_text[4]) or None, \
                                (html_text[5] != html_texts[CFG_SITE_LANG][5] and html_text[5]) or None, \
                                (html_text[6] != html_texts[CFG_SITE_LANG][6] and html_text[6]) or None)
                               for html_text in html_texts.values() \
                               if html_text[0] != CFG_SITE_LANG]
        filtered_html_texts.append(html_texts[CFG_SITE_LANG])
    else:
        filtered_html_texts = html_texts.values()

    return filtered_html_texts
Ejemplo n.º 18
0
    def tmpl_pagefooter(self,
                        req=None,
                        ln=CFG_SITE_LANG,
                        lastupdated=None,
                        pagefooteradd=""):
        """Creates a page footer

           Parameters:

          - 'ln' *string* - The language to display

          - 'lastupdated' *string* - when the page was last updated

          - 'pagefooteradd' *string* - additional page footer HTML code

           Output:

          - HTML code of the page headers
        """

        # load the right message language
        _ = gettext_set_language(ln)

        if lastupdated and lastupdated != '$Date$':
            if lastupdated.startswith("$Date: ") or \
            lastupdated.startswith("$Id: "):
                lastupdated = convert_datestruct_to_dategui(\
                                 convert_datecvs_to_datestruct(lastupdated),
                                 ln=ln)
            msg_lastupdated = _("Last updated") + ": " + lastupdated
        else:
            msg_lastupdated = ""

        out = """
<div class="pagefooter">
%(pagefooteradd)s
<!-- replaced page footer -->
 <div class="pagefooterstripeleft">
 <!--
  %(sitename)s&nbsp;::&nbsp;<a class="footer" href="%(siteurl)s/?ln=%(ln)s">%(msg_search)s</a>&nbsp;::&nbsp;<a class="footer" href="%(siteurl)s/submit?ln=%(ln)s">%(msg_submit)s</a>&nbsp;::&nbsp;<a class="footer" href="%(sitesecureurl)s/youraccount/display?ln=%(ln)s">%(msg_personalize)s</a>&nbsp;::&nbsp;<a class="footer" href="%(siteurl)s/help/%(langlink)s">%(msg_help)s</a>
  <br />-->
  %(msg_poweredby)s <a class="footer" href="http://invenio-software.org/">Invenio</a> v%(version)s
  <br />
  %(msg_maintainedby)s <a class="footer" href="mailto:%(sitesupportemail)s">%(sitesupportemail)s</a>
  <br />
  %(msg_lastupdated)s
 </div>
 <div class="pagefooterstriperight">
 <p><em>
 Articles in the SCOAP3 repository are released under a <a target="_blank" rel="license" href="http://creativecommons.org/licenses/by/3.0/"><strong>CC-BY</strong></a> license. Metadata are provided by the corresponding publishers and released under the <a target="_blank"  rel="license"
     href="http://creativecommons.org/publicdomain/zero/1.0/">
    <strong>CC0</strong>
  </a> waiver.
 </em></p>
  %(languagebox)s
 </div>
<!-- replaced page footer -->
</div>
<!-- Piwik -->
<script type="text/javascript">
  var _paq = _paq || [];
  _paq.push(["trackPageView"]);
  _paq.push(["enableLinkTracking"]);

  (function() {
    var u=(("https:" == document.location.protocol) ? "https" : "http") + "://cds-piwik.cern.ch/";
    _paq.push(["setTrackerUrl", u+"piwik.php"]);
    _paq.push(["setSiteId", "10"]);
    var d=document, g=d.createElement("script"), s=d.getElementsByTagName("script")[0]; g.type="text/javascript";
    g.defer=true; g.async=true; g.src=u+"piwik.js"; s.parentNode.insertBefore(g,s);
  })();
</script>
<noscript>
<!-- Piwik Image Tracker -->
<img src="https://cds-piwik.cern.ch/piwik.php?idsite=10&amp;rec=1" style="border:0" alt="" />
<!-- End Piwik -->
</noscript>
<!-- End Piwik Code -->

</body>
</html>
        """ % {
            'siteurl': CFG_BASE_URL,
            'sitesecureurl': CFG_SITE_SECURE_URL,
            'ln': ln,
            'langlink': '?ln=' + ln,
            'sitename': CFG_SITE_NAME_INTL.get(ln, CFG_SITE_NAME),
            'sitesupportemail': CFG_SITE_SUPPORT_EMAIL,
            'msg_search': _("Search"),
            'msg_submit': _("Submit"),
            'msg_personalize': _("Personalize"),
            'msg_help': _("Help"),
            'msg_poweredby': _("Powered by"),
            'msg_maintainedby': _("Maintained by"),
            'msg_lastupdated': msg_lastupdated,
            'languagebox': self.tmpl_language_selection_box(req, ln),
            'version': CFG_VERSION,
            'pagefooteradd': pagefooteradd,
        }
        return out