Exemplo n.º 1
0
        def set_(self, value):
            valid = dict(self.transform.get_parameter_value('valid_tags'))
            stripped = set(value)
            for v in XHTML_TAGS:
                if v in stripped:
                    if v in valid:
                        del valid[v]
                else:
                    valid[v] = VALID_TAGS.get(v, 1)

            # Nasty tags must never be valid
            for v in self.nasty_tags:
                if v in valid:
                    del valid[v]
            self._settransform(valid_tags=valid)
            # Set kupu attribute for backwards compatibility
            if self.kupu_tool is not None:
                self.kupu_tool.set_stripped_tags(value)
Exemplo n.º 2
0
        def set_(self, value):
            valid = dict(self.transform.get_parameter_value('valid_tags'))
            stripped = set(value)
            for v in XHTML_TAGS:
                if v in stripped:
                    if v in valid:
                        del valid[v]
                else:
                    valid[v] = VALID_TAGS.get(v, 1)

            # Nasty tags must never be valid
            for v in self.nasty_tags:
                if v in valid:
                    del valid[v]
            self._settransform(valid_tags=valid)
            # Set kupu attribute for backwards compatibility
            if self.kupu_tool is not None:
                self.kupu_tool.set_stripped_tags(value)
Exemplo n.º 3
0
    def handleSave(self, action):  # NOQA
        data, errors = self.extractData()
        if errors:
            self.status = self.formErrorsMessage
            return

        # Save in portal tools
        safe_html = getattr(
            getToolByName(self.context, 'portal_transforms'),
            'safe_html',
            None)

        nasty_tags = data['nasty_tags']
        custom_tags = data['custom_tags']
        stripped_tags = data['stripped_tags']

        valid = safe_html._config['valid_tags']

        # start with removing tags that do not belong in valid tags
        for value in nasty_tags + stripped_tags:
            if value in valid:
                del valid[value]
        # add in custom tags
        for custom in custom_tags:
            if value not in valid:
                valid[custom] = 1
        # then, check if something was previously prevented but is no longer
        for tag in set(VALID_TAGS.keys()) - set(valid.keys()):
            if tag not in nasty_tags and tag not in stripped_tags:
                valid[tag] = VALID_TAGS[tag]

        # nasty tags are simple, just set the value here
        nasty_value = {}
        for tag in nasty_tags:
            nasty_value[tag] = NASTY_TAGS.get(tag, VALID_TAGS.get(tag, 1))
        safe_html._config['nasty_tags'] = nasty_value

        disable_filtering = int(data['disable_filtering'])
        if disable_filtering != safe_html._config['disable_transform']:
            safe_html._config['disable_transform'] = disable_filtering

        for attr in ('stripped_combinations', 'class_blacklist', 'stripped_attributes',
                     'style_whitelist'):
            value = data[attr]
            if value is None:
                if attr == 'stripped_combinations':
                    value = {}
                else:
                    value = []
            if value != safe_html._config[attr]:
                safe_html._config[attr] = value

        # always reload the transform
        safe_html._p_changed = True
        safe_html.reload()

        self.applyChanges(data)
        IStatusMessage(self.request).addStatusMessage(
            _(u"Changes saved."),
            "info")
        self.request.response.redirect(self.request.getURL())
Exemplo n.º 4
0
    def handleSave(self, action):  # NOQA
        data, errors = self.extractData()
        if errors:
            self.status = self.formErrorsMessage
            return

        # Save in portal tools
        safe_html = getattr(getToolByName(self.context, 'portal_transforms'),
                            'safe_html', None)

        nasty_tags = data['nasty_tags']
        custom_tags = data['custom_tags']
        stripped_tags = data['stripped_tags']

        valid = safe_html._config['valid_tags']

        # start with removing tags that do not belong in valid tags
        for value in nasty_tags + stripped_tags:
            if value in valid:
                del valid[value]
        # add in custom tags
        for custom in custom_tags:
            if value not in valid:
                valid[custom] = 1
        # then, check if something was previously prevented but is no longer
        for tag in set(VALID_TAGS.keys()) - set(valid.keys()):
            if tag not in nasty_tags and tag not in stripped_tags:
                valid[tag] = VALID_TAGS[tag]

        # nasty tags are simple, just set the value here
        nasty_value = {}
        for tag in nasty_tags:
            nasty_value[tag] = NASTY_TAGS.get(tag, VALID_TAGS.get(tag, 1))
        safe_html._config['nasty_tags'] = nasty_value

        disable_filtering = int(data['disable_filtering'])
        if disable_filtering != safe_html._config['disable_transform']:
            safe_html._config['disable_transform'] = disable_filtering

        for attr in ('stripped_combinations', 'class_blacklist',
                     'stripped_attributes', 'style_whitelist'):
            value = data[attr]
            if value is None:
                if attr == 'stripped_combinations':
                    value = {}
                else:
                    value = []
            if value != safe_html._config[attr]:
                safe_html._config[attr] = value

        # always reload the transform
        safe_html._p_changed = True
        safe_html.reload()

        self.applyChanges(data)
        IStatusMessage(self.request).addStatusMessage(_(u"Changes saved."),
                                                      "info")
        IStatusMessage(self.request).addStatusMessage(
            _(u"HTML generation is heavily cached across Plone. You may "
              u"have to edit existing content or restart your server to see "
              u"the changes."), "warning")
        self.request.response.redirect(self.request.getURL())