-
-
Notifications
You must be signed in to change notification settings - Fork 30
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
3931.feature allow javascript to be inserted in head-section or at bottom of page. #361
Merged
Merged
Changes from 24 commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
4b3cfef
Allow including js in head section
jladage be96cd2
Prevent KeyError getting ISiteSchema when not all records exist yet.
mauritsvanrees 9a0c1b6
Improve news snippet.
mauritsvanrees cdffe7c
Let the AnalyticsHeadViewlet inherit from the AnalyticsViewlet so we …
mauritsvanrees 105bef7
zpretty
mauritsvanrees 276c66e
Use IHtmlHeadLinks viewlet provider to assure being the last script t…
jladage 4bd740e
Fix tests
jladage f1fdfa9
Update changelog entry to refer to correct viewlet manager.
jladage 677fcca
Fix tests
jladage 70283a2
Fix tests
jladage 63e1655
Fix tests, hopefully ci likes it now.
jladage a95f03d
Improve security by filtering all but script tags.
jladage 89f8167
Black fixes
jladage 15858c3
Change import to see it that fixes the dependencies problem
jladage 222066a
Black fixes
jladage 6fa0c7d
Add lxml to install_requires
jladage 1bf6c5a
Add trailing comma to list, just to make black happy.
jladage 7bbd28a
Use try/except in case someone puts in anything other than <script>-t…
jladage 71178e4
Position script even before all other javascripts.
jladage 5880d2e
Instead of returning only script tags, it now filters base and title …
jladage fc9b432
Black and spelling fixes
jladage c240ea1
Update Changlog entry to reflect new changes.
jladage 82da269
Reduce number of xpath queries.
jladage a3f6c8a
Black code fixes
jladage c060d88
Do not filter webstats code with lxml.
mauritsvanrees a1fe14a
Merge remote-tracking branch 'origin/master' into 3931.feature
mauritsvanrees File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
Add a field ``webstats_head_js`` to the Site controlpanel and render its | ||
contents in the head section using ``IHtmlHeadLinks`` viewlet manager. | ||
See `issue 3931 <https://github.com/plone/Products.CMFPlone/issues/3931>`_: | ||
some javascript needs to be loaded at the bottom of the page, and some in the head section. | ||
Fool proofing by filering out <base>-tags, <title>-tags and rendering valid html for the | ||
remaining tags. | ||
[jladage] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<div tal:define=" | ||
webstats_head_js view/webstats_js; | ||
" | ||
tal:condition="webstats_head_js" | ||
tal:omit-tag="" | ||
> | ||
<!-- plone.analytics.head goes here --> | ||
<span tal:replace="structure webstats_head_js"></span> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -59,6 +59,7 @@ | |
"Products.ZCatalog", | ||
"setuptools", | ||
"Zope", | ||
"lxml", | ||
], | ||
extras_require=dict( | ||
test=[ | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure, if this is really necessary. We're adding JavaScript and with that we can do anything, also unwanted stuff.
Maybe it should be up to the integrator to produce valid HTML?
If we keep it, I do like that e.g.
<style>
tags and the like are allowed. This gives an easy way of quickly adding a style messing with theming.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The rational is that this is not security but more thinking about what a not so savy site manager, could fuck up :) Off course he/she should handle injecting javascript with care, like it was alway the case with that field in the control panel.
My code, because it injects in the head section (thanks to @yurj ) I got aware of the fact that we could prevent "user error" simply by filtering only script tag. A bit later I realized we can prevent double base or title tags at a low cost using lxml.
A pleasant second benefit is that with this code, even if the user makes a typo in the script, the viewlet will render valid HTML.
I'm not familar enough with the control panel code to write up a validator for this head field which would prevent adding base or title tags in the nicest possible way. Anyone would like to assist or give me some pointers?
Hope this helps to understand why it's there.