Example #1
0
def drupal_page_cache_header(cache):
    """
   Set HTTP headers in preparation for a cached page response.
  
   The general approach here is that anonymous users can keep a local
   cache of the page, but must revalidate it on every request.  Then,
   they are given a '304 Not Modified' response as long as they stay
   logged out and the page has not been modified.
  """
    # Set default values:
    last_modified = php.gmdate("D, d M Y H:i:s", cache.created) + " GMT"
    etag = '"' + drupy_md5(last_modified) + '"'
    # See if the client has provided the required HTTP headers:
    if_modified_since = (
        php.stripslashes(php.SERVER["HTTP_IF_MODIFIED_SINCE"])
        if php.isset(php.SERVER, "HTTP_IF_MODIFIED_SINCE")
        else False
    )
    if_none_match = (
        php.stripslashes(php.SERVER["HTTP_IF_NONE_MATCH"]) if php.isset(php.SERVER, "HTTP_IF_NONE_MATCH") else False
    )
    if (
        if_modified_since
        and if_none_match
        and if_none_match == etag  # etag must match
        and if_modified_since == last_modified
    ):  # if-modified-since must match
        php.header(php.SERVER["SERVER_PROTOCOL"] + " 304 Not Modified")
        # All 304 responses must send an etag if the 200 response for the same
        # object contained an etag
        php.header("Etag: %(etag)s" % {"etag": etag})
        exit()
    # Send appropriate response:
    php.header("Last-Modified: %(last_modified)s" % {"last_modified": last_modified})
    php.header("Etag: %(etag)s" % {"etag": etag})
    # The following headers force validation of cache:
    php.header("Expires: Sun, 19 Nov 1978 05:00:00 GMT")
    php.header("Cache-Control: must-revalidate")
    if variable_get("page_compression", True):
        # Determine if the browser accepts gzipped data.
        if php.strpos(php.SERVER["HTTP_ACCEPT_ENCODING"], "gzip") == False and php.function_exists("gzencode"):
            # Strip the gzip php.header and run uncompress.
            cache.data = php.gzinflate(php.substr(php.substr(cache.data, 10), 0, -8))
        elif php.function_exists("gzencode"):
            php.header("Content-Encoding: gzip")
    # Send the original request's headers. We send them one after
    # another so PHP's php.header() def can deal with duplicate
    # headers.
    headers = php.explode("\n", cache.headers)
    for php.header_ in headers:
        php.header(php.header_)
    print cache.data
Example #2
0
def drupal_page_cache_header(cache):
    """
   Set HTTP headers in preparation for a cached page response.
  
   The general approach here is that anonymous users can keep a local
   cache of the page, but must revalidate it on every request.  Then,
   they are given a '304 Not Modified' response as long as they stay
   logged out and the page has not been modified.
  """
    # Set default values:
    last_modified = php.gmdate('D, d M Y H:i:s', cache.created) + ' GMT'
    etag = '"' + drupy_md5(last_modified) + '"'
    # See if the client has provided the required HTTP headers:
    if_modified_since =  (php.stripslashes(php.SERVER['HTTP_IF_MODIFIED_SINCE']) \
      if php.isset(php.SERVER, 'HTTP_IF_MODIFIED_SINCE') else False)
    if_none_match = (php.stripslashes(php.SERVER['HTTP_IF_NONE_MATCH']) \
      if php.isset(php.SERVER, 'HTTP_IF_NONE_MATCH') else False)
    if (if_modified_since and if_none_match
            and if_none_match == etag  # etag must match
            and if_modified_since
            == last_modified):  # if-modified-since must match
        php.header(php.SERVER['SERVER_PROTOCOL'] + ' 304 Not Modified')
        # All 304 responses must send an etag if the 200 response for the same
        # object contained an etag
        php.header("Etag: %(etag)s" % {'etag': etag})
        exit()
    # Send appropriate response:
    php.header("Last-Modified: %(last_modified)s" % \
      {'last_modified':last_modified})
    php.header("Etag: %(etag)s" % {'etag': etag})
    # The following headers force validation of cache:
    php.header("Expires: Sun, 19 Nov 1978 05:00:00 GMT")
    php.header("Cache-Control: must-revalidate")
    if (variable_get('page_compression', True)):
        # Determine if the browser accepts gzipped data.
        if (php.strpos(php.SERVER['HTTP_ACCEPT_ENCODING'], 'gzip') == False and \
            php.function_exists('gzencode')):
            # Strip the gzip php.header and run uncompress.
            cache.data = php.gzinflate(
                php.substr(php.substr(cache.data, 10), 0, -8))
        elif (php.function_exists('gzencode')):
            php.header('Content-Encoding: gzip')
    # Send the original request's headers. We send them one after
    # another so PHP's php.header() def can deal with duplicate
    # headers.
    headers = php.explode("\n", cache.headers)
    for php.header_ in headers:
        php.header(php.header_)
    print cache.data
Example #3
0
def get_t():
    """
   Return the name of the localisation function. Use in code that needs to
   run both during installation and normal operation.
  """
    php.static(get_t, 't')
    if (get_t.t == None):
        get_t.t = ('st' if php.function_exists('install_main') else 't')
    return get_t.t
Example #4
0
def get_t():
    """
   Return the name of the localisation function. Use in code that needs to
   run both during installation and normal operation.
  """
    php.static(get_t, "t")
    if get_t.t == None:
        get_t.t = "st" if php.function_exists("install_main") else "t"
    return get_t.t
Example #5
0
def drupal_get_title():
  """
   Get the title of the current page, for display on
   the page and in the title bar.
  
   @return
     The current page's title.
  """
  title = drupal_set_title();
  # during a bootstrap, menu.inc is not included
  # and thus we cannot provide a title
  if (title == None and php.function_exists('menu_get_active_title')):
    title = check_plain(menu_get_active_title());
  return title;
Example #6
0
def drupal_get_title():
    """
   Get the title of the current page, for display on
   the page and in the title bar.
  
   @return
     The current page's title.
  """
    title = drupal_set_title()
    # during a bootstrap, menu.inc is not included
    # and thus we cannot provide a title
    if (title == None and php.function_exists('menu_get_active_title')):
        title = check_plain(menu_get_active_title())
    return title
Example #7
0
def hook(plugin_, hook_):
  """
   Determine whether a plugin implements a hook.
  
   @param plugin
     The name of the plugin (without the .plugin extension).
   @param hook
     The name of the hook (e.g. "help" or "menu").
   @return
     True if the plugin is both installed and enabled, and the hook is
     implemented in that plugin.
  """
  global plugins
  function = hook_;
  if (lib_bootstrap.MAINTENANCE_MODE is True):
    return php.function_exists(function, plugins[plugin_])
  else:
    return lib_bootstrap.drupal_function_exists(function, plugins[plugin_]);
Example #8
0
def hook(plugin_, hook_):
    """
   Determine whether a plugin implements a hook.
  
   @param plugin
     The name of the plugin (without the .plugin extension).
   @param hook
     The name of the hook (e.g. "help" or "menu").
   @return
     True if the plugin is both installed and enabled, and the hook is
     implemented in that plugin.
  """
    global plugins
    function = hook_
    if (lib_bootstrap.MAINTENANCE_MODE is True):
        return php.function_exists(function, plugins[plugin_])
    else:
        return lib_bootstrap.drupal_function_exists(function, plugins[plugin_])
Example #9
0
def drupal_function_exists(function, scope=None):
    """
   Confirm that a function is available.
  
   If the function is already available, this function does nothing.
   If the function is not available, it tries to load the file where the
   function lives. If the file is not available, it returns False, so that it
   can be used as a drop-in replacement for php.function_exists().
   
   DRUPY(BC): This function needs to be heavily modified
  
   @param function
     The name of the function to check or load.
   @param scope
     Scope to check
   @return
     True if the function is now available, False otherwise.
  """
    # We arent using the registry, so lets just return a simple function_exists
    return php.function_exists(function, scope)
Example #10
0
def drupal_function_exists(function, scope=None):
    """
   Confirm that a function is available.
  
   If the function is already available, this function does nothing.
   If the function is not available, it tries to load the file where the
   function lives. If the file is not available, it returns False, so that it
   can be used as a drop-in replacement for php.function_exists().
   
   DRUPY(BC): This function needs to be heavily modified
  
   @param function
     The name of the function to check or load.
   @param scope
     Scope to check
   @return
     True if the function is now available, False otherwise.
  """
    # We arent using the registry, so lets just return a simple function_exists
    return php.function_exists(function, scope)
Example #11
0
def drupal_get_normal_path(path, path_language = ''):
  """
   Given a path alias, return the internal path it represents.
  
   @param path
     A Drupal path alias.
   @param path_language
     An optional language code to look up the path in.
  
   @return
     The internal path represented by the alias, or the original alias if no
     internal path was found.
  """
  result = path;
  src = drupal_lookup_path('source', path, path_language);
  if (src):
    result = src;
  if (php.function_exists('custom_url_rewrite_inbound')):
    # Modules may alter the inbound request path by reference.
    custom_url_rewrite_inbound(result, path, path_language);
  return result;
Example #12
0
def drupal_get_normal_path(path, path_language=''):
    """
   Given a path alias, return the internal path it represents.
  
   @param path
     A Drupal path alias.
   @param path_language
     An optional language code to look up the path in.
  
   @return
     The internal path represented by the alias, or the original alias if no
     internal path was found.
  """
    result = path
    src = drupal_lookup_path('source', path, path_language)
    if (src):
        result = src
    if (php.function_exists('custom_url_rewrite_inbound')):
        # Modules may alter the inbound request path by reference.
        custom_url_rewrite_inbound(result, path, path_language)
    return result