コード例 #1
0
ファイル: macro.py プロジェクト: pombredanne/trachacks
    def produce_html(self, context, url, kwargs={}):
        attr = dict()
        attr['data'] = context.href.chrome('mindmap', 'visorFreemind.swf')
        attr['width'] = kwargs.pop('width', self.default_width)
        attr['height'] = kwargs.pop('height', self.default_height)
        try:
            int(attr['height'])
        except:
            pass
        else:
            attr['height'] += "px"
        try:
            int(attr['width'])
        except:
            pass
        else:
            attr['width'] += "px"

        flashvars = dict(
            [[k.strip(), v.strip()]
             for k, v in [kv.split('=') for kv in self.default_flashvars]])
        try:
            flashvars.update([[k.strip(), v.strip()] for k, v in [
                kv.split('=')
                for kv in kwargs['flashvars'].strip("\"'").split('|')
            ]])
        except:
            pass
        flashvars['initLoadFile'] = url

        css = ''
        if 'border' in kwargs:
            border = kwargs['border'].strip("\"'").replace(';', '')
            if border == "1":
                border = "solid"
            elif border == "0":
                border = "none"
            css = 'border: ' + border

        if self.resizable and (
            ('resizable' not in kwargs and self.default_resizable)
                or kwargs.get('resizable', 'false').lower() == "true"):
            class_ = "resizablemindmap mindmap"
        else:
            class_ = "mindmap"

        return tag.div(
            tag.object(tag.param(name="quality", value="high"),
                       tag.param(name="bgcolor", value="#ffffff"),
                       tag.param(name="flashvars",
                                 value=Markup("&".join([
                                     "=".join([k, unicode(v)])
                                     for k, v in flashvars.iteritems()
                                 ]))),
                       type="application/x-shockwave-flash",
                       **attr),
            class_=class_,
            style=Markup(css),
        )
コード例 #2
0
ファイル: macro.py プロジェクト: nyuhuhuu/trachacks
    def produce_html(self, context, url, kwargs={}):
        attr = dict()
        attr['data']   = context.href.chrome('mindmap','visorFreemind.swf')
        attr['width']  = kwargs.pop('width',self.default_width)
        attr['height'] = kwargs.pop('height',self.default_height)
        try:
          int( attr['height'] )
        except:
          pass
        else:
          attr['height'] += "px"
        try:
          int( attr['width'] )
        except:
          pass
        else:
          attr['width'] += "px"

        flashvars = dict([ [k.strip(),v.strip()] for k,v in [ kv.split('=') for kv in self.default_flashvars]])
        try:
          flashvars.update([ [k.strip(),v.strip()] for k,v in [kv.split('=') for kv in kwargs['flashvars'].strip("\"'").split('|') ] ])
        except:
          pass
        flashvars['initLoadFile'] = url

        css  = ''
        if 'border' in kwargs:
          border = kwargs['border'].strip("\"'").replace(';','')
          if border == "1":
            border = "solid"
          elif border == "0":
            border = "none"
          css = 'border: ' + border

        if self.resizable and ( ('resizable' not in kwargs and self.default_resizable) or kwargs.get('resizable','false').lower() == "true" ):
          class_ = "resizablemindmap mindmap"
        else:
          class_ = "mindmap"

        return tag.div(
            tag.object(
                tag.param( name="quality", value="high" ),
                tag.param( name="bgcolor", value="#ffffff" ),
                tag.param( name="flashvars", value= Markup("&".join([ "=".join([k,unicode(v)]) for k,v in flashvars.iteritems() ]) )),
                type   = "application/x-shockwave-flash",
                **attr
            ),
            class_=class_,
            style=Markup(css),
        )
コード例 #3
0
def embed_vimeo(scheme, netloc, path, query, style):
    parts = filter(None, path.split('/'))
    path = '/moogaloop.swf?clip_id=%s&server=vimeo.com&'\
           'show_title=1&show_byline=1&'\
           'show_portrait=0&color=&fullscreen=1' % parts[0]
    url = urlunparse((scheme, netloc, path, '', '', ''))
    return tag.object(
        tag.param(name='movie', value=url),
        tag.param(name='allowfullscreen', value='true'),
        tag.param(name='allowscriptaccess', value='always'),
        tag.embed(
            src=url,
            type=SWF_MIME_TYPE,
            allowfullscreen='true',
            allowscriptaccess='always',
            width=style['width'],
            height=style['height']
        ),
        style=xform_style(style)
    )
コード例 #4
0
ファイル: macro.py プロジェクト: iwege/MovieMacro
 def expand_macro(self, formatter, name, content):
     args, kwargs = parse_args(content, strict=True)
     kwargs = string_keys(kwargs)
     
     if len(args) >= 1:
         url = args[0]
     elif len(args) == 0:
         raise TracError('URL to a movie at least required.')
     
     embed_count = getattr(formatter, EMBED_COUNT, 0)
     embed_count += 1
     setattr(formatter, EMBED_COUNT, embed_count)
     
     flowplayer_embedded = getattr(formatter, FLOWPLAYER_EMBEDDED, False)
     
     url = get_absolute_url(formatter.href.base, url)
     src = get_absolute_url(formatter.href.base, kwargs.pop('splash','htdocs://movie/movie/img/black.jpg'))
     
     scheme, netloc, path, params, query, fragment = urlparse(url)
     
     try:
         style_dict = xform_style(kwargs.get('style', ''))
     except:
         raise TracError('Double check the `style` argument.')
     
     style = {
         'display': 'block',
         'border': style_dict.get('border', 'none'),
         'margin': style_dict.get('margin', '0 auto'),
         'clear': 'both'
     }
     
     if netloc == 'www.youtube.com' or netloc == 'www.youtube-nocookie.com':
         query_dict = xform_query(query)
         video = query_dict.get('v')
         
         url = urlunparse((scheme, netloc, '/v/%s' % video, '', '', ''))
         
         width = kwargs.pop('width', style_dict.get('width', '425px'))
         height = kwargs.pop('height', style_dict.get('height', '344px'))
         
         style.update({
             'width': width,
             'height': height,
         })
         
         return tag.object(tag.param(name='movie', value=url),
                           tag.param(name='allowFullScreen', value='true'),
                           tag.embed(src=url, type='application/x-shockwave-flash', allowfullscreen='true', width=width, height=height),
                           style=xform_style(style))
     
     if netloc == 'video.google.com':
         query_dict = xform_query(query)
         query_dict['hl'] = 'en'
         query_dict['fs'] = 'true'
         
         query = xform_query(query_dict)
         
         url = urlunparse((scheme, netloc, '/googleplayer.swf', '', query, ''))
         
         width = kwargs.pop('width', style_dict.get('width', '400px'))
         height = kwargs.pop('height', style_dict.get('height', '326px'))
         
         style.update({
             'width': width,
             'height': height,
         })
         
         return tag.embed(src=url,
                          allowFullScreen='true',
                          allowScriptAccess='always',
                          type='application/x-shockwave-flash',
                          style=xform_style(style))
     
     if netloc == 'www.metacafe.com':
         parts = path.split('/')
         try:
             path = '/fplayer/%s/%s.swf' % (parts[2], parts[3])
         except:
             raise TracError("Non-standard URL, don't know how to process it, file a ticket please.")
         
         url = urlunparse((scheme, netloc, path, '', '', ''))
         
         width = kwargs.pop('width', style_dict.get('width', '400px'))
         height = kwargs.pop('height', style_dict.get('height', '345px'))
         
         style.update({
             'width': width,
             'height': height,
         })
         
         return tag.embed(src=url,
                          wmode='transparent',
                          pluginspage='http://www.macromedia.com/go/getflashplayer',
                          type='application/x-shockwave-flash',
                          style=xform_style(style))
     
     # Requested by Zach, #4188.
     if netloc in ('vimeo.com', 'www.vimeo.com'):
         parts = path.split('/')
         
         while '' in parts:
             parts.remove('')
         
         path = '/moogaloop.swf?clip_id=%s&server=vimeo.com&show_title=1&show_byline=1&show_portrait=0&color=&fullscreen=1' % parts[0]
         url = urlunparse((scheme, netloc, path, '', '', ''))
         
         width = kwargs.pop('width', style_dict.get('width', '640px'))
         height = kwargs.pop('height', style_dict.get('height', '401px'))
         
         style.update({
             'width': width,
             'height': height,
         })
         
         return tag.object(tag.param(name='movie', value=url),
                           tag.param(name='allowfullscreen', value='true'),
                           tag.param(name='allowscriptaccess', value='always'),
                           tag.embed(src=url, type='application/x-shockwave-flash', allowfullscreen='true', allowscriptaccess='always', width=width, height=height),
                           style=xform_style(style))
     
     # Local movies.
     tags = []
     
     if not flowplayer_embedded:
         add_script(formatter.req, 'movie/js/flowplayer.min.js')
         add_script(formatter.req, 'movie/js/flowplayer.embed.min.js')
         add_script(formatter.req, 'movie/js/flashembed.min.js')
         
         script = '''
             $(function() {
                 $f("a.flowplayer","%s");
             });
         ''' % get_absolute_url(formatter.href.base, 'htdocs://movie/movie/swf/flowplayer.swf')
         
         tags.append(tag.script(script))
         
         setattr(formatter, FLOWPLAYER_EMBEDDED, True)
     
     width = kwargs.pop('width', style_dict.get('width', '320px'))
     height = kwargs.pop('height', style_dict.get('height', '320px'))
     
     style.update({
         'width': width,
         'height': height,
     })
     
     if kwargs.pop('clear', None) == 'none':
         style.pop('clear')
     
     kwargs = {'style': xform_style(style)}
     
     tags.append(tag.a(tag.img(src=src, **kwargs), class_='flowplayer', href=url, **kwargs))
     
     return ''.join([str(i) for i in tags])
コード例 #5
0
    def expand_macro(self, formatter, name, content):
        args, kwargs = parse_args(content, strict=True)
        kwargs = string_keys(kwargs)

        if len(args) >= 1:
            url = args[0]
        elif len(args) == 0:
            raise TracError('URL to a movie at least required.')

        embed_count = getattr(formatter, EMBED_COUNT, 0)
        embed_count += 1
        setattr(formatter, EMBED_COUNT, embed_count)

        flowplayer_embedded = getattr(formatter, FLOWPLAYER_EMBEDDED, False)

        url = self._get_absolute_url(formatter.req, url)
        src = self._get_absolute_url(
            formatter.req, kwargs.pop('splash',
                                      'htdocs://movie/img/black.jpg'))

        scheme, netloc, path, params, query, fragment = urlparse(url)

        try:
            style_dict = xform_style(kwargs.get('style', ''))
        except:
            raise TracError('Double check the `style` argument.')

        style = {
            'display': 'block',
            'border': style_dict.get('border', 'none'),
            'margin': style_dict.get('margin', '0 auto'),
            'clear': 'both'
        }

        if netloc == 'www.youtube.com' or netloc == 'www.youtube-nocookie.com':
            query_dict = xform_query(query)
            video = query_dict.get('v')

            url = urlunparse((scheme, netloc, '/v/%s' % video, '', '', ''))

            width = kwargs.pop('width', style_dict.get('width', '425px'))
            height = kwargs.pop('height', style_dict.get('height', '344px'))

            style.update({
                'width': width,
                'height': height,
            })

            return tag.object(tag.param(name='movie', value=url),
                              tag.param(name='allowFullScreen', value='true'),
                              tag.embed(src=url,
                                        type='application/x-shockwave-flash',
                                        allowfullscreen='true',
                                        width=width,
                                        height=height),
                              style=xform_style(style))

        if netloc == 'video.google.com':
            query_dict = xform_query(query)
            query_dict['hl'] = 'en'
            query_dict['fs'] = 'true'

            query = xform_query(query_dict)

            url = urlunparse(
                (scheme, netloc, '/googleplayer.swf', '', query, ''))

            width = kwargs.pop('width', style_dict.get('width', '400px'))
            height = kwargs.pop('height', style_dict.get('height', '326px'))

            style.update({
                'width': width,
                'height': height,
            })

            return tag.embed(src=url,
                             allowFullScreen='true',
                             allowScriptAccess='always',
                             type='application/x-shockwave-flash',
                             style=xform_style(style))

        if netloc == 'www.metacafe.com':
            parts = path.split('/')
            try:
                path = '/fplayer/%s/%s.swf' % (parts[2], parts[3])
            except:
                raise TracError(
                    "Non-standard URL, don't know how to process it, file a ticket please."
                )

            url = urlunparse((scheme, netloc, path, '', '', ''))

            width = kwargs.pop('width', style_dict.get('width', '400px'))
            height = kwargs.pop('height', style_dict.get('height', '345px'))

            style.update({
                'width': width,
                'height': height,
            })

            return tag.embed(
                src=url,
                wmode='transparent',
                pluginspage='http://www.macromedia.com/go/getflashplayer',
                type='application/x-shockwave-flash',
                style=xform_style(style))

        # Requested by Zach, #4188.
        if netloc in ('vimeo.com', 'www.vimeo.com'):
            parts = path.split('/')

            while '' in parts:
                parts.remove('')

            path = '/moogaloop.swf?clip_id=%s&server=vimeo.com&show_title=1&show_byline=1&show_portrait=0&color=&fullscreen=1' % parts[
                0]
            url = urlunparse((scheme, netloc, path, '', '', ''))

            width = kwargs.pop('width', style_dict.get('width', '640px'))
            height = kwargs.pop('height', style_dict.get('height', '401px'))

            style.update({
                'width': width,
                'height': height,
            })

            return tag.object(tag.param(name='movie', value=url),
                              tag.param(name='allowfullscreen', value='true'),
                              tag.param(name='allowscriptaccess',
                                        value='always'),
                              tag.embed(src=url,
                                        type='application/x-shockwave-flash',
                                        allowfullscreen='true',
                                        allowscriptaccess='always',
                                        width=width,
                                        height=height),
                              style=xform_style(style))

        # Local movies.
        tags = []

        if not flowplayer_embedded:
            add_script(formatter.req, 'movie/js/flashembed.min.js')
            add_script(formatter.req, 'movie/js/flow.embed.js')

            script = '''
                $(function() {
                
                    $("a.flowplayer").flowembed("%s",  {initialScale:'scale'});
                });
            ''' % self._get_absolute_url(
                formatter.req, 'htdocs://movie/swf/FlowPlayerDark.swf')

            tags.append(tag.script(script))

            setattr(formatter, FLOWPLAYER_EMBEDDED, True)

        width = kwargs.pop('width', style_dict.get('width', '320px'))
        height = kwargs.pop('height', style_dict.get('height', '320px'))

        style.update({
            'width': width,
            'height': height,
        })

        if kwargs.pop('clear', None) == 'none':
            style.pop('clear')

        kwargs = {'style': xform_style(style)}

        tags.append(
            tag.a(tag.img(src=src, **kwargs),
                  class_='flowplayer',
                  href=url,
                  **kwargs))

        return ''.join([str(i) for i in tags])