Changeset 3124 for trunk


Ignore:
Timestamp:
01/03/11 16:35:48 (9 years ago)
Author:
jukka
Message:

Enabled embedding for Google Docs, Spreadsheets, Drawings and Presentations.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/FieldsWidgets.py

    r3114 r3124  
    11121112        try: 
    11131113            parsetuple=urlparse(code) 
    1114             return parsetuple[0]=='http' 
     1114            return parsetuple[0]=='http' or parsetuple[0]=='https' 
    11151115        except TypeError: 
    11161116            return False 
    11171117        return False 
     1118 
     1119    def isGoogleDocs(self, chapter): 
     1120        """ OEmbed doesn't recognize google docs, but we can fill them in manually """ 
     1121        def _getParam(query, key): 
     1122            query_list=query.split('&') 
     1123            for pair in query_list: 
     1124                k,v = pair.split('=') 
     1125                if k==key: 
     1126                    return v 
     1127            return '' 
     1128        code=chapter['embed'] 
     1129        try: 
     1130            adscheme, network, path, params, query, frag = urlparse(code) 
     1131        except TypeError: 
     1132            return '' 
     1133        if network=='docs.google.com' or (network.startswith('docs') and network.endswith('.google.com')):  
     1134            try: 
     1135                docid='' 
     1136                path_list=path.split('/') 
     1137                if 'present' in path_list: # https://docs.google.com/present/view?id=d-----------n 
     1138                    docid=_getParam(query,'id')                     
     1139                    if docid: 
     1140                        return '<iframe src="https://docs.google.com/present/embed?id=%s" frameborder="0" width="700" height="559"></iframe>' % docid                    
     1141                elif 'drawings' in path_list: # https://docs.google.com/drawings/pub?id=12---------------------Z6U&w=960&h=720 
     1142                    docid=_getParam(query,'id') 
     1143                    try: 
     1144                        w=int(_getParam(query, 'w') or 960) 
     1145                        h=int(_getParam(query, 'h') or 720) 
     1146                    except ValueError: 
     1147                        w=960 
     1148                        h=720                                                                 
     1149                    if docid:                         
     1150                        return '<img src="https://docs.google.com/drawings/pub?id=%s&amp;w=%s&amp;h=%s">' % (docid, w,h)                    
     1151                elif 'Doc' in path_list: # https://docs.google.com/Doc?docid=0Acv---------------------mZA&hl=en 
     1152                    docid=_getParam(query,'docid') 
     1153                elif 'd' in path_list: # https://docs.google.com/document/d/1k----------------2ttA0AnSurA/edit?hl=en&authkey=CJ----D 
     1154                    docid=path_list[2] 
     1155                elif 'pub' in path_list: # https://docs.google.com/document/pub?id=1k---------------------------SurA 
     1156                    docid=_getParam(query,'id')                     
     1157            except IndexError: 
     1158                return '' 
     1159            if docid: 
     1160                return '<iframe src="https://docs.google.com/document/pub?id=%s&amp;embedded=true" width="760" height="564"></iframe>' % docid 
     1161        elif network=='spreadsheets.google.com' or (network.startswith('spreadsheets') and network.endswith('.google.com')): 
     1162            path_list=path.split('/') 
     1163            if 'viewform' in path_list: 
     1164                docid=_getParam(query, 'formkey')      
     1165                return '<iframe src="https://spreadsheets.google.com/embeddedform?formkey=%s" width="760" height="564" frameborder="0" marginheight="0" marginwidth="0">Loading...</iframe>' % docid 
     1166            elif 'gform' in path_list: 
     1167                docid=_getParam(query, 'key')      
     1168                return '<iframe src="https://spreadsheets.google.com/embeddedform?formkey=%s" width="760" height="564" frameborder="0" marginheight="0" marginwidth="0">Loading...</iframe>' % docid                 
     1169            else: 
     1170                docid=_getParam(query, 'key')      
     1171                return "<iframe width='760' height='564' frameborder='0' src='https://spreadsheets.google.com/pub?key=%s&amp;output=html&amp;widget=true'></iframe>" % docid 
     1172        return '' 
    11181173 
    11191174    def getLength(self, piece): 
  • trunk/skins/lemill/widget_chapter.pt

    r3098 r3124  
    4343<metal:view_embed_block define-macro="view_embed_block"> 
    4444<div class="embed_content" tal:define="oembed python:field.isOEmbedChapter(chapter)"> 
    45 <tal:oembed condition="oembed"> 
    46 <a href="" tal:attributes="href chapter/embed" class="oembed" content="chapter/embed">Embedded content</a> 
    47 </tal:oembed> 
     45<tal:oembed condition="oembed"><tal:googledocs tal:define="gcode python:field.isGoogleDocs(chapter)"><tal:do_google condition="gcode" replace="structure gcode" /> 
     46<a href="" tal:condition="not:gcode" tal:attributes="href chapter/embed" class="oembed" content="chapter/embed">Embedded content</a> 
     47</tal:googledocs></tal:oembed> 
    4848<tal:old_embed condition="not:oembed" replace="structure chapter/embed | python:''" /></div> 
    4949</metal:view_embed_block> 
     
    203203<metal:edit_view_embed_block define-macro="edit_view_embed_block"> 
    204204<div class="embed_content" tal:define="oembed python:field.isOEmbedChapter(chapter)"> 
    205 <tal:oembed condition="oembed"> 
    206 <a href="" tal:attributes="href chapter/embed" class="oembed" content="chapter/embed">Embedded content</a> 
    207 </tal:oembed> 
     205<tal:oembed condition="oembed"><tal:googledocs tal:define="gcode python:field.isGoogleDocs(chapter)"><tal:do_google condition="gcode" replace="structure gcode" /> 
     206<a href="" tal:condition="not:gcode" tal:attributes="href chapter/embed" class="oembed" content="chapter/embed">Embedded content</a> 
     207</tal:googledocs></tal:oembed> 
    208208<tal:old_embed condition="not:oembed" replace="structure chapter/embed | python:''" /></div> 
    209209</metal:edit_view_embed_block> 
     210 
    210211 
    211212<!-- edit macros, called from Main edit macro for chapter that is open to editing --> 
     
    235236<p> 
    236237<input type="text" style="width:60%" id="embed_field" name="embed_field" tal:attributes="value python:test(oembed, chapter['embed'], '')" /> 
    237 <input type="button" value="Test embedding" i18n:attributes="value python:Test embedding" onclick="$('#embed_test').oembed($('#embed_field').val());$('#old_embed').html('');" /></p> 
     238<input type="button" value="Test embedding" i18n:attributes="value python:'Test embedding'" onclick="$('#embed_test').oembed($('#embed_field').val());$('#old_embed').html('');" /></p> 
     239<div class="formHelp" i18n:translate="embed_google_notice">The test button doesn't work with Google embeds. Save this section to view the embedding. Embedding is enabled for Google Documents, Spreadsheets, Presentations and Drawings. Please use the link to published page given in sharing options (the one that begins with 'http://' or 'https://') instead of suggested embed code (the one that begins with '&lt;iframe '). </div>       
     240 
    238241<div id="embed_test"> 
    239242<a href="" tal:attributes="href chapter/embed" class="oembed" tal:condition="oembed" tal:content="chapter/embed">Embedded content</a></div>     
Note: See TracChangeset for help on using the changeset viewer.