Esempio n. 1
0
def get_latest_deposits():
	NUMBER_OF_RECORDS = 4;
	from invenio.search_engine import perform_request_search
	ids = perform_request_search(of="id", rg=NUMBER_OF_RECORDS, sf="005", so="a")
	limit_ids = ids[:NUMBER_OF_RECORDS]

	from invenio.bibformat_engine import BibFormatObject
	bfo_list = [BibFormatObject(id) for id in limit_ids]

	from invenio.bibformat_elements import bfe_authors
	from invenio.bibformat_elements import bfe_title
	from invenio.bibformat_elements import bfe_creation_date
	
	recs = [{
		"id": bfo.recID,
		"date": bfe_creation_date.format_element(bfo),
		"author": bfe_authors.format_element(bfo),
		"title": bfe_title.format_element(bfo),
		"description": bfo.field("520__a"), 
		"category": bfo.field("980__a"), 
	} for bfo in bfo_list]
	return recs
Esempio n. 2
0
def format_element(bfo, width="50"):
    """
    Prints a full BibTeX record.

    'width' must be bigger than or equal to 30.
    This format element is an example of large element, which does
    all the formatting by itself

    @param width: the width (in number of characters) of the record
    """
    out = "@"
    width = int(width)
    if width < 30:
        width = 30

    name_width = 20
    value_width = width-name_width
    recID = bfo.control_field('001')

    #Print entry type
    import invenio.bibformat_elements.bfe_collection as bfe_collection
    collection = bfe_collection.format_element(bfo=bfo, kb="DBCOLLID2BIBTEX")
    if collection == "":
        out += "article"
    else:
        out += collection

    out += "{"

    #Print BibTeX key
    #
    #Try to have: author_name:recID
    #If author_name cannot be found, use primary_report_number
    #If primary_report_number cannot be found, use additional_report_number
    #If additional_report_number cannot be found, use title:recID
    #If title cannot be found, use only recID
    #
    #The construction of this key is inherited from old BibTeX format
    #written in EL, in old BibFormat.
    key = recID
    author = bfo.field("100__a")
    if author != "":
        key = get_name(author)+":"+recID
    else:
        author = bfo.field("700__a")
        if author != "":
            key = get_name(author)+":"+recID
        else:
            primary_report_number = bfo.field("037__a")
            if primary_report_number != "":
                key = primary_report_number
            else:
                additional_report_number = bfo.field("088__a")
                if additional_report_number != "":
                    key = primary_report_number
                else:
                    title = bfo.field("245__a")
                    if title != "":
                        key = get_name(title)+":"+recID
    out += key +","

    #Print authors
    #If author cannot be found, print a field key=recID
    import invenio.bibformat_elements.bfe_authors as bfe_authors
    authors = bfe_authors.format_element(bfo=bfo,
                                         limit="",
                                         separator=" and ",
                                         extension="",
                                         print_links="no")
    if authors == "":
        out += format_bibtex_field("key",
                                   recID,
                                   name_width,
                                   value_width)
    else:
        out += format_bibtex_field("author",
                                   authors,
                                   name_width,
                                   value_width)

    #Print editors
    import invenio.bibformat_elements.bfe_editors as bfe_editors
    editors = bfe_editors.format_element(bfo=bfo, limit="",
                                         separator=" and ",
                                         extension="",
                                         print_links="no")
    out += format_bibtex_field("editor",
                               editors,
                               name_width,
                               value_width)

    #Print title
    import invenio.bibformat_elements.bfe_title as bfe_title
    title = bfe_title.format_element(bfo=bfo, separator = ". ")
    out += format_bibtex_field("title",
                               '{' + title + '}',
                               name_width,
                               value_width)

    #Print institution
    if collection ==  "techreport":
        publication_name = bfo.field("269__b")
        out += format_bibtex_field("institution",
                                   publication_name,
                                   name_width, value_width)

    #Print organization
    if collection == "inproceedings" or collection == "proceedings":
        organization = []
        organization_1 = bfo.field("260__b")
        if organization_1 != "":
            organization.append(organization_1)
        organization_2 = bfo.field("269__b")
        if organization_2 != "":
            organization.append(organization_2)
        out += format_bibtex_field("organization",
                                   ". ".join(organization),
                                   name_width,
                                   value_width)

    #Print publisher
    if collection == "book" or \
           collection == "inproceedings" \
           or collection == "proceedings":
        publishers = []
        import invenio.bibformat_elements.bfe_publisher as bfe_publisher
        publisher = bfe_publisher.format_element(bfo=bfo)
        if publisher != "":
            publishers.append(publisher)
        publication_name = bfo.field("269__b")
        if publication_name != "":
            publishers.append(publication_name)
        imprint_publisher_name = bfo.field("933__b")
        if imprint_publisher_name != "":
            publishers.append(imprint_publisher_name)
        imprint_e_journal__publisher_name = bfo.field("934__b")
        if imprint_e_journal__publisher_name != "":
            publishers.append(imprint_e_journal__publisher_name)

        out += format_bibtex_field("publisher",
                                   ". ".join(publishers),
                                   name_width,
                                   value_width)

    #Print journal
    if collection == "article":
        journals = []
        host_title = bfo.field("773__p")
        if host_title != "":
            journals.append(host_title)
        journal = bfo.field("909C4p")
        if journal != "":
            journals.append(journal)

        out += format_bibtex_field("journal",
                                   ". ".join(journals),
                                   name_width,
                                   value_width)

    #Print school
    if collection == "phdthesis":
        university = bfo.field("502__b")

        out += format_bibtex_field("school",
                                   university,
                                   name_width,
                                   value_width)

    # Collaboration
    collaborations = []
    for collaboration in bfo.fields("710__g"):
        if collaboration not in collaborations:
            collaborations.append(collaboration)
    out += format_bibtex_field("collaboration",
                               ", ".join(collaborations),
                                   name_width,
                                   value_width)

    #Print address
    if collection == "book" or \
           collection == "inproceedings" or \
           collection == "proceedings" or \
           collection == "phdthesis" or \
           collection == "techreport":
        addresses = []
        publication_place = bfo.field("260__a")
        if publication_place != "":
            addresses.append(publication_place)
        publication_place_2 = bfo.field("269__a")
        if publication_place_2 != "":
            addresses.append(publication_place_2)
        imprint_publisher_place = bfo.field("933__a")
        if imprint_publisher_place != "":
            addresses.append(imprint_publisher_place)
        imprint_e_journal__publisher_place = bfo.field("934__a")
        if imprint_e_journal__publisher_place != "":
            addresses.append(imprint_e_journal__publisher_place)

        out += format_bibtex_field("address",
                                   ". ".join(addresses),
                                   name_width,
                                   value_width)

    #Print number
    if collection == "techreport" or \
           collection == "article":
        numbers = []
        primary_report_number = bfo.field("037__a")
        if primary_report_number != "":
            numbers.append(primary_report_number)
        additional_report_numbers = bfo.fields("088__a")
        additional_report_numbers = ". ".join(additional_report_numbers)
        if additional_report_numbers != "":
            numbers.append(additional_report_numbers)
        host_number = bfo.field("773__n")
        if host_number != "":
            numbers.append(host_number)
        number = bfo.field("909C4n")
        if number != "":
            numbers.append(number)
        out += format_bibtex_field("number",
                                   ". ".join(numbers),
                                   name_width,
                                   value_width)

    #Print volume
    if collection == "article" or \
           collection == "book":
        volumes = []
        host_volume = bfo.field("773__v")
        if host_volume != "":
            volumes.append(host_volume)
        volume = bfo.field("909C4v")
        if volume != "":
            volumes.append(volume)

        out += format_bibtex_field("volume",
                                   ". ".join(volumes),
                                   name_width,
                                   value_width)

    #Print series
    if collection == "book":
        series = bfo.field("490__a")
        out += format_bibtex_field("series",
                                   series,
                                   name_width,
                                   value_width)

    #Print pages
    if collection == "article" or \
           collection == "inproceedings":
        pages = []
        host_pages = bfo.field("773c")
        if host_pages != "":
            pages.append(host_pages)
        nb_pages = bfo.field("909C4c")
        if nb_pages != "":
            pages.append(nb_pages)
        phys_pagination = bfo.field("300__a")
        if phys_pagination != "":
            pages.append(phys_pagination)

        out += format_bibtex_field("pages",
                                   ". ".join(pages),
                                   name_width,
                                   value_width)

    #Print month
    month = get_month(bfo.field("269__c"))
    if month == "":
        month = get_month(bfo.field("260__c"))
        if month == "":
            month = get_month(bfo.field("502__c"))

    out += format_bibtex_field("month",
                               month,
                               name_width,
                               value_width)

    #Print year
    year = get_year(bfo.field("269__c"))
    if year == "":
        year = get_year(bfo.field("260__c"))
        if year == "":
            year = get_year(bfo.field("502__c"))
            if year == "":
                year = get_year(bfo.field("909C0y"))

    out += format_bibtex_field("year",
                               year,
                               name_width,
                               value_width)

    #Print note
    note = bfo.field("500__a")
    out += format_bibtex_field("note",
                               note,
                               name_width,
                               value_width)

    out +="\n}"

    return out
Esempio n. 3
0
def format_element(bfo, width="50"):
    """
    Prints a full BibTeX record.

    'width' must be bigger than or equal to 30.
    This format element is an example of large element, which does
    all the formatting by itself

    @param width: the width (in number of characters) of the record
    """
    out = "@"
    width = int(width)
    if width < 30:
        width = 30

    name_width = 20
    value_width = width - name_width
    recID = bfo.control_field('001')

    #Print entry type
    import invenio.bibformat_elements.bfe_collection as bfe_collection
    collection = bfe_collection.format_element(bfo=bfo, kb="DBCOLLID2BIBTEX")
    if collection == "":
        out += "article"
    else:
        out += collection

    out += "{"

    #Print BibTeX key
    #
    #Try to have: author_name:recID
    #If author_name cannot be found, use primary_report_number
    #If primary_report_number cannot be found, use additional_report_number
    #If additional_report_number cannot be found, use title:recID
    #If title cannot be found, use only recID
    #
    #The construction of this key is inherited from old BibTeX format
    #written in EL, in old BibFormat.
    key = recID
    author = bfo.field("100__a")
    if author != "":
        key = get_name(author) + ":" + recID
    else:
        author = bfo.field("700__a")
        if author != "":
            key = get_name(author) + ":" + recID
        else:
            primary_report_number = bfo.field("037__a")
            if primary_report_number != "":
                key = primary_report_number
            else:
                additional_report_number = bfo.field("088__a")
                if additional_report_number != "":
                    key = primary_report_number
                else:
                    title = bfo.field("245__a")
                    if title != "":
                        key = get_name(title) + ":" + recID
    out += key + ","

    #Print authors
    #If author cannot be found, print a field key=recID
    import invenio.bibformat_elements.bfe_authors as bfe_authors
    authors = bfe_authors.format_element(bfo=bfo,
                                         limit="",
                                         separator=" and ",
                                         extension="",
                                         print_links="no")
    if authors == "":
        out += format_bibtex_field("key", recID, name_width, value_width)
    else:
        out += format_bibtex_field("author", authors, name_width, value_width)

    #Print editors
    import invenio.bibformat_elements.bfe_editors as bfe_editors
    editors = bfe_editors.format_element(bfo=bfo,
                                         limit="",
                                         separator=" and ",
                                         extension="",
                                         print_links="no")
    out += format_bibtex_field("editor", editors, name_width, value_width)

    #Print title
    import invenio.bibformat_elements.bfe_title as bfe_title
    title = bfe_title.format_element(bfo=bfo, separator=". ")
    out += format_bibtex_field("title", '{' + title + '}', name_width,
                               value_width)

    #Print institution
    if collection == "techreport":
        publication_name = bfo.field("269__b")
        out += format_bibtex_field("institution", publication_name, name_width,
                                   value_width)

    #Print organization
    if collection == "inproceedings" or collection == "proceedings":
        organization = []
        organization_1 = bfo.field("260__b")
        if organization_1 != "":
            organization.append(organization_1)
        organization_2 = bfo.field("269__b")
        if organization_2 != "":
            organization.append(organization_2)
        out += format_bibtex_field("organization", ". ".join(organization),
                                   name_width, value_width)

    #Print publisher
    if collection == "book" or \
           collection == "inproceedings" \
           or collection == "proceedings":
        publishers = []
        import invenio.bibformat_elements.bfe_publisher as bfe_publisher
        publisher = bfe_publisher.format_element(bfo=bfo)
        if publisher != "":
            publishers.append(publisher)
        publication_name = bfo.field("269__b")
        if publication_name != "":
            publishers.append(publication_name)
        imprint_publisher_name = bfo.field("933__b")
        if imprint_publisher_name != "":
            publishers.append(imprint_publisher_name)
        imprint_e_journal__publisher_name = bfo.field("934__b")
        if imprint_e_journal__publisher_name != "":
            publishers.append(imprint_e_journal__publisher_name)

        out += format_bibtex_field("publisher", ". ".join(publishers),
                                   name_width, value_width)

    #Print journal
    if collection == "article":
        journals = []
        host_title = bfo.field("773__p")
        if host_title != "":
            journals.append(host_title)
        journal = bfo.field("909C4p")
        if journal != "":
            journals.append(journal)

        out += format_bibtex_field("journal", ". ".join(journals), name_width,
                                   value_width)

    #Print school
    if collection == "phdthesis":
        university = bfo.field("502__b")

        out += format_bibtex_field("school", university, name_width,
                                   value_width)

    # Collaboration
    collaborations = []
    for collaboration in bfo.fields("710__g"):
        if collaboration not in collaborations:
            collaborations.append(collaboration)
    out += format_bibtex_field("collaboration", ", ".join(collaborations),
                               name_width, value_width)

    #Print address
    if collection == "book" or \
           collection == "inproceedings" or \
           collection == "proceedings" or \
           collection == "phdthesis" or \
           collection == "techreport":
        addresses = []
        publication_place = bfo.field("260__a")
        if publication_place != "":
            addresses.append(publication_place)
        publication_place_2 = bfo.field("269__a")
        if publication_place_2 != "":
            addresses.append(publication_place_2)
        imprint_publisher_place = bfo.field("933__a")
        if imprint_publisher_place != "":
            addresses.append(imprint_publisher_place)
        imprint_e_journal__publisher_place = bfo.field("934__a")
        if imprint_e_journal__publisher_place != "":
            addresses.append(imprint_e_journal__publisher_place)

        out += format_bibtex_field("address", ". ".join(addresses), name_width,
                                   value_width)

    #Print number
    if collection == "techreport" or \
           collection == "article":
        numbers = []
        primary_report_number = bfo.field("037__a")
        if primary_report_number != "":
            numbers.append(primary_report_number)
        additional_report_numbers = bfo.fields("088__a")
        additional_report_numbers = ". ".join(additional_report_numbers)
        if additional_report_numbers != "":
            numbers.append(additional_report_numbers)
        host_number = bfo.field("773__n")
        if host_number != "":
            numbers.append(host_number)
        number = bfo.field("909C4n")
        if number != "":
            numbers.append(number)
        out += format_bibtex_field("number", ". ".join(numbers), name_width,
                                   value_width)

    #Print volume
    if collection == "article" or \
           collection == "book":
        volumes = []
        host_volume = bfo.field("773__v")
        if host_volume != "":
            volumes.append(host_volume)
        volume = bfo.field("909C4v")
        if volume != "":
            volumes.append(volume)

        out += format_bibtex_field("volume", ". ".join(volumes), name_width,
                                   value_width)

    #Print series
    if collection == "book":
        series = bfo.field("490__a")
        out += format_bibtex_field("series", series, name_width, value_width)

    #Print pages
    if collection == "article" or \
           collection == "inproceedings":
        pages = []
        host_pages = bfo.field("773c")
        if host_pages != "":
            pages.append(host_pages)
        nb_pages = bfo.field("909C4c")
        if nb_pages != "":
            pages.append(nb_pages)
        phys_pagination = bfo.field("300__a")
        if phys_pagination != "":
            pages.append(phys_pagination)

        out += format_bibtex_field("pages", ". ".join(pages), name_width,
                                   value_width)

    #Print month
    month = get_month(bfo.field("269__c"))
    if month == "":
        month = get_month(bfo.field("260__c"))
        if month == "":
            month = get_month(bfo.field("502__c"))

    out += format_bibtex_field("month", month, name_width, value_width)

    #Print year
    year = get_year(bfo.field("269__c"))
    if year == "":
        year = get_year(bfo.field("260__c"))
        if year == "":
            year = get_year(bfo.field("502__c"))
            if year == "":
                year = get_year(bfo.field("909C0y"))

    out += format_bibtex_field("year", year, name_width, value_width)

    #Print note
    note = bfo.field("500__a")
    out += format_bibtex_field("note", note, name_width, value_width)

    out += "\n}"

    return out
Esempio n. 4
0
def format_element(bfo, only_public_records=1):
    """
    Return a small bookmark element to share record on social.cern.ch

    @param only_public_records: if set to 1 (the default), prints the box only
        if the record is public (i.e. if it belongs to the root colletion and is
        accessible to the world).
    """

    if int(only_public_records) and not record_public_p(bfo.recID):
        return ""

    # Reuse bfe_title element to get the record's title
    title = bfe_title.format_element(bfo)

    url = '%(siteurl)s/%(record)s/%(recid)s' % \
          {'recid': bfo.recID,
           'record': CFG_SITE_RECORD,
           'siteurl': CFG_SITE_URL}

    bookmark_template = """
<style type="text/css">
    /* Some styling for the button */
    a.social-button{
        background: #fff;
        border: 1px solid #ddd;
        float: left;
        font-size: 12px;
        line-height: 14px;
        padding: 2px;
        text-decoration: none;
    }
    .social-button img{
        float: left;
        margin-right: 5px;
    }
    .social-button:hover{
        background: #ddd;
        border: 1px solid #bbb;
        text-decoration: none;
    }
    .social-header {
        margin: 0 auto;
    }
    .social-text {
        margin: 10px auto;
    }
    .social-remarks {
        margin: 5px auto;
    }
    .social-send {
        width: 50%%;
        left: 25%%;
    }
</style>
<link rel="stylesheet" href="/img/overlay.css" type="text/css" />
<script src="/js/overlay.min.js" type="text/javascript"></script>
<script type="text/javascript" src="%(siteurl)s/js/SP.RequestExecutor.js"></script>
<script type="text/javascript">// <![CDATA[

    ///////////////////////////// SOCIAL INTEGRATION FUNCTIONS ///////////////

    //Taken from https://espace2013.cern.ch/webservices-help/webauthoring/AdvancedAuthoring/Pages/IntegrateSocial_API.aspx

    function successHandler(data){
        console.log("Success");
        console.log(arguments);
        console.log(JSON.parse(data));
    }

    function errorHandler(){
        console.log("Error");
        console.log(arguments);
    }

    function postOnSocial(message){
        //Write into social, first get the formDigest value that will be used on the callback 'postMessage' function
        executeRestCall(formDigestUrl, "POST", null, postMessage, errorHandler, message);
      }

    function postMessage(data, message){
        //Get the Digest token from the RestCall
        var result = JSON.parse(data);
        var formDigest = result.d.GetContextWebInformation.FormDigestValue;
        var xhr = createCORSRequest("POST", myFeedManagerEndpoint + "my/Feed/Post");
        xhr.onload = function () {
          if(this.status == 200){
            // If the operation succeeds... than the feed has been updated.
            // Display success message in the magnific popup
            $('.social-header').width('110').text('Message posted !');
            $('.social-text').remove();
            $('.social-send').disabled = false
            $('.social-send').text('Close');
            $('.social-remarks').remove();
            // Unbind 'send' event and bind 'close' event to the button
            $(document).off('click', '.social-send');
            $('.social-send').click( function() {
                $('.mfp-close').click();
            });
          } else {    // We sent the request correctly but there has been a problem
            // Display error message in the magnific popup
            $('.social-header').width('100').text('Error !');
            $('.social-text').remove();
            $('.social-send').disabled = false
            $('.social-send').text('Close');
            $('.social-remarks').text('Please reload the page and try again (make sure you are logged in on social.cern.ch)')
            // Unbind 'send' event and bind 'close' event to the button
            $(document).off('click', '.social-send');
            $('.social-send').click( function() {
                $('.mfp-close').click();
            });
          }
        };
        //Set variables on the request object
        xhr.withCredentials = true;
        xhr.setRequestHeader("X-RequestDigest", formDigest);
        xhr.setRequestHeader("content-type", "application/json; charset=utf-8; odata=verbose");
        // Creating the data for the post
        // Those 6 backslashes below are to generate 2 backslashes in the REST request
        var data =  " { 'restCreationData':{ " +
            "   '__metadata':{ 'type':'SP.Social.SocialRestPostCreationData'}, " +
            "   'ID': null, " +
            "   'creationData':{ " +
            "       '__metadata':{'type':'SP.Social.SocialPostCreationData' }, " +
            "       'ContentItems':{ " +
            "           'results': [ " +
            "           { " +
            "               '__metadata' : {'type':'SP.Social.SocialDataItem' }, " +
            "           'Text':'%(record_url)s'," +
            "           'Uri':'%(record_url)s'," +
            "           'ItemType':'1'" +
            "           }, " +
            "           { " +
            "               '__metadata' : {'type':'SP.Social.SocialDataItem' }, " +
            "           'AccountName':'CERN\\\\\\\\cdssocial'," +
            "           'ItemType':'0'" +
            "           } " +
            "               ] " +
            "       }, " +
            "       'ContentText': '" + message + "', " +
            "       'UpdateStatusText':false " +
            "   } " +
            " }}";

        xhr.send(data);     // Uploads the message
    }

    // This function authenticate the User on Social (transparently to the User)
    function authenticateOnSocial(inputFunction){
        var executor = new SP.RequestExecutor(requestExecutorSite);
        executor.executeAsync({
          url: formDigestUrl,
          method: "GET",
          headers: {
            "Accept": "application/json; odata=verbose",
            "Access-Control-Allow-Origin": "*",
          },
          dataType: "json",
          error: function (xhr, ajaxOptions, thrownError) {
            // This function will be executed always. It is not an actual 'error' situation.
            try{
              // After the authentication completes we use the function passed in input, that will contain the calls for any other function on Social
              if(inputFunction !== null && inputFunction !== undefined){
                inputFunction();
              }
            }catch(e){ console.log("Error: input function parameter in the authentication function is not valid."); return; }
          },
        }); //End of executor.executeAsync
    }

    function createCORSRequest(method, url) {
        var xhr = new XMLHttpRequest();
        if ("withCredentials" in xhr) {
          // Check if the XMLHttpRequest object has a "withCredentials" property.
          // "withCredentials" only exists on XMLHTTPRequest2 objects.
          xhr.open(method, url, true);
        } else if (typeof XDomainRequest != "undefined") {
        // Otherwise, check if XDomainRequest.
        // XDomainRequest only exists in IE, and is IE's way of making CORS requests.
        xhr = new XDomainRequest();
        xhr.open(method, url);
        } else {
          // Otherwise, CORS is not supported by the browser.
          xhr = null;
        }
        if(xhr !== null){   // if the CORS is supported...
          xhr.withCredentials = true;
          xhr.setRequestHeader("accept", "application/json; odata=verbose");
        }
        return xhr;
    }

    function executeRestCall(url, method, data, onSucc, onError, extra) {
        var xhr = createCORSRequest(method, url);
        if (!xhr) {
            console.log('CORS not supported');
            throw new Error('CORS not supported');
        }
        else{
            xhr.onload = function () {
                onSucc(xhr.responseText, extra);    // passing the parameters and the results of the RESTcall to the 'onSucc' pointed function
            };

            xhr.onerror = onError;
            if (data !== null && data !== undefined && data !== ''){
                xhr.send(data);
            }else{
                xhr.send();
            }
        }
    }

    ///////////////////////////// END OF SOCIAL INTEGRATION FUNCTIONS ////////

    // Initial config variables for social.cern.ch
    // var socialUrl = "https://social-dev.cern.ch";
    var socialUrl = "https://social.cern.ch";
    var requestExecutorSite = socialUrl + "/_layouts/15/AppWebProxy.aspx";
    var myFeedManagerEndpoint = socialUrl + "/_api/social.feed/";
    var formDigestUrl = socialUrl + "/_api/contextinfo";
    jQuery.support.cors = true;         // Used for createCORSRequest()

    function createMagnificPopup() {
        $('.social-button').magnificPopup({
            items:{
                src:'<div class="social-popup overlay-white oc-content overlay-white-500">\
                        <h3 class="social-header">The following message will be posted:</h3>\
                        <textarea class="social-text">%(title)s %(record_url)s via @CDS Social</textarea>\
                        <div class="social-remarks"><span>Please make sure that you have an account on social.cern.ch !</span></div>\
                        <button type="buton" class="social-send">Post !</button>\
                    </div>',
                type: 'inline'
            }
        });
        // $.click won't work, because .social-send button is created dynamically
        // de-attach other callbacks first
        $(document).off('click', '.social-send');
        $(document).on('click', '.social-send', function(){
            // Replace the record's url and @CDS Social with placeholders
            var message = $('.social-text').val()
            var newMessage = message.replace('%(record_url)s', '{0}')
            var newMessage = newMessage.replace('@CDS Social', '@{1}')
            // Disable the button and put a loader image inside
            $('.social-send').disabled = true
            $('.social-send').html('<img src="../img/loading.gif" style="background: none repeat scroll 0%% 0%% transparent;"/>')
            authenticateOnSocial(function(){
                postOnSocial(newMessage);
            });
        });
    }

    jQuery( document ).ready(function() {
        // Determine if user is logged in or not based on the existence of
        // either 'cern-account' class or 'cern-signout'
        if($('.cern-account').length) {
            // User NOT logged in
            $('.social-button').click(function(){
                alert('You have to be signed in to do this!');
            });
        } else if($('.cern-signout').length) {
            // User logged in
            $('.social-button').click(function(){
                createMagnificPopup();
            });
            // attach the magnific popup now
            createMagnificPopup();
        } else {
            $('.social-button').click(function(){
                alert('There was an error, please reload the page and try again.\
                    If the error still occurs, please contact [email protected]');
            });
        }
    });

// ]]>
</script>

    <a href="javascript:void(0)" class="social-button">
        <img src="/img/social-logo.png">
        Share on social.cern.ch
    </a>
    """ % {
        'siteurl': CFG_SITE_URL,
        'record_url': url,
        'title': title.replace("'", "\\'")
    }

    return bookmark_template