File: URLTool.py

package info (click to toggle)
zope-cmfplone 2.5.1-4etch3
  • links: PTS
  • area: main
  • in suites: etch
  • size: 7,752 kB
  • ctags: 5,237
  • sloc: python: 28,264; xml: 3,723; php: 129; makefile: 99; sh: 2
file content (36 lines) | stat: -rw-r--r-- 1,427 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
from Products.CMFCore.URLTool import URLTool as BaseTool
from Products.CMFPlone import ToolNames
from AccessControl import ClassSecurityInfo
from Globals import InitializeClass
from Products.CMFPlone.PloneBaseTool import PloneBaseTool

from urlparse import urlparse

class URLTool(PloneBaseTool, BaseTool):

    meta_type = ToolNames.URLTool
    security = ClassSecurityInfo()
    toolicon = 'skins/plone_images/link_icon.gif'

    __implements__ = (PloneBaseTool.__implements__, BaseTool.__implements__, )

    security.declarePublic('isURLInPortal')
    def isURLInPortal(self, url):
        """ Check if a given url is on the same host and contains the portal
            path.  Used to ensure that login forms can determine relevant
            referrers (i.e. in portal).  Also return true for relative urls,
            though techincally they may not be part of the portal, it's a good
            guess (just like assuming https://portal is in the same portal as
            http://portal).
        """
        p_url = self()
        p_host_path = urlparse(p_url)[0:3]
        url_host_path = urlparse(url)[0:3]
        # check for urls without protocol (i.e. relative urls), or urls with
        # the same host and path.
        return (p_host_path[1] == url_host_path[1] and
          url_host_path[2].startswith(p_host_path[2])) or not url_host_path[0]

URLTool.__doc__ = BaseTool.__doc__

InitializeClass(URLTool)