Ejemplo n.º 1
0
def drupal_init_path():
  """
   Initialize the php.GET['q'] variable to the proper normal path.
  """
  if (php.isset(php.GET, 'q') and not php.empty(php.GET['q'])):
    php.GET['q'] = drupal_get_normal_path(php.trim(php.GET['q'], '/'))
  else:
    php.GET['q'] = drupal_get_normal_path( \
      lib_bootstrap.variable_get('site_frontpage', 'node'))
Ejemplo n.º 2
0
def drupal_init_path():
    """
   Initialize the php.GET['q'] variable to the proper normal path.
  """
    if (php.isset(php.GET, 'q') and not php.empty(php.GET['q'])):
        php.GET['q'] = drupal_get_normal_path(php.trim(php.GET['q'], '/'))
    else:
        php.GET['q'] = drupal_get_normal_path( \
          lib_bootstrap.variable_get('site_frontpage', 'node'))
Ejemplo n.º 3
0
def _query(query_, debug = 0):
  """
   Helper function for db_query().
  """
  if (lib_bootstrap.variable_get('dev_query', 0)):
    usec,sec = php.explode(' ', php.microtime())
    timer = float(usec) + float(sec)
    # If devel.plugin query logging is enabled, prepend a comment 
    # with the username and calling function
    # to the SQL string. This is useful when running mysql's 
    # SHOW PROCESSLIST to learn what exact
    # code is issueing the slow query.
    bt = debug_backtrace()
    # t() may not be available yet so we don't wrap 'Anonymous'
    name = (lib_appglobals.user.name if (lib_appglobals.user.uid > 0) else \
      variable_get('anonymous', 'Anonymous'))
    # php.str_replace() to prevent SQL injection via username
    # or anonymous name.
    name = php.str_replace(['*', '/'], '', name)
    query_ = '/* ' +  name  + ' : ' . bt[2]['function'] + ' */ ' + query_
  result = DrupyMySQL.mysqli_query(lib_appglobals.active_db, query_)
  if (lib_bootstrap.variable_get('dev_query', 0)):
    query_ = bt[2]['function'] +  "\n"  + query_
    usec,sec = php.explode(' ', php.microtime())
    stop = float(usec) + float(sec)
    diff = stop - timer
    lib_appglobals.queries.append( [query_, diff] )
  if (debug):
    print '<p>query: ' +  query_  + '<br />error:' + \
      DrupyMySQL.mysqli_error(lib_appglobals.active_db) + '</p>'
  if (not DrupyMySQL.mysqli_errno(lib_appglobals.active_db)):
    return result
  else:
    # Indicate to drupal_error_handler that this is a database error.
    DB_ERROR = True
    php.trigger_error(lib_bootstrap.check_plain(\
      DrupyMySQL.mysqli_error(lib_appglobals.active_db) +  \
      "\nquery: "  + query_), php.E_USER_WARNING)
    return False
Ejemplo n.º 4
0
def _query(query_, debug=0):
    """
   Helper function for db_query().
  """
    if (lib_bootstrap.variable_get('dev_query', 0)):
        usec, sec = php.explode(' ', php.microtime())
        timer = float(usec) + float(sec)
        # If devel.plugin query logging is enabled, prepend a comment
        # with the username and calling function
        # to the SQL string. This is useful when running mysql's
        # SHOW PROCESSLIST to learn what exact
        # code is issueing the slow query.
        bt = debug_backtrace()
        # t() may not be available yet so we don't wrap 'Anonymous'
        name = (lib_appglobals.user.name if (lib_appglobals.user.uid > 0) else \
          variable_get('anonymous', 'Anonymous'))
        # php.str_replace() to prevent SQL injection via username
        # or anonymous name.
        name = php.str_replace(['*', '/'], '', name)
        query_ = '/* ' + name + ' : '.bt[2]['function'] + ' */ ' + query_
    result = DrupyMySQL.mysqli_query(lib_appglobals.active_db, query_)
    if (lib_bootstrap.variable_get('dev_query', 0)):
        query_ = bt[2]['function'] + "\n" + query_
        usec, sec = php.explode(' ', php.microtime())
        stop = float(usec) + float(sec)
        diff = stop - timer
        lib_appglobals.queries.append([query_, diff])
    if (debug):
        print '<p>query: ' +  query_  + '<br />error:' + \
          DrupyMySQL.mysqli_error(lib_appglobals.active_db) + '</p>'
    if (not DrupyMySQL.mysqli_errno(lib_appglobals.active_db)):
        return result
    else:
        # Indicate to drupal_error_handler that this is a database error.
        DB_ERROR = True
        php.trigger_error(lib_bootstrap.check_plain(\
          DrupyMySQL.mysqli_error(lib_appglobals.active_db) +  \
          "\nquery: "  + query_), php.E_USER_WARNING)
        return False
Ejemplo n.º 5
0
def get(cid, table = 'cache'):
  """
   Return data from the persistent cache. Data may be stored as either plain 
   text or as serialized data. cache_get will automatically return 
   unserialized objects and arrays.
  
   @param cid
     The cache ID of the data to retrieve.
   @param table
     The table table to store the data in.
     Valid core values are 'cache_filter',
     'cache_menu', 'cache_page', or 'cache' for the default cache.
   @return The cache or FALSE on failure.
  """
  # Garbage collection necessary when enforcing a minimum cache lifetime
  cache_flush = lib_bootstrap.variable_get('cache_flush', 0);
  if (cache_flush and (cache_flush + \
      variable_get('cache_lifetime', 0) <= REQUEST_TIME)):
    # Reset the variable immediately to prevent a meltdown in heavy
    # load situations.
    variable_set('cache_flush', 0);
    # Time to php.flush old cache data
    lib_database.query(\
      "DELETE FROM {" + table + "} WHERE expire != %d AND expire <= %d", \
      CACHE_PERMANENT, cache_flush);
  cache = lib_database.fetch_object(lib_database.query(\
    "SELECT data, created, headers, expire, serialized " + \
    "FROM {" + table + "} WHERE cid = '%s'", cid));
  if (php.isset(cache, 'data')):
    # If the data is permanent or we're not enforcing a minimum cache lifetime
    # always return the cached data.
    if (cache.expire == CACHE_PERMANENT or not \
        variable_get('cache_lifetime', 0)):
      if (cache.serialized):
        cache.data = php.unserialize(cache.data);
    # If enforcing a minimum cache lifetime, validate that the data is
    # currently valid for this user before we return it by making sure the
    # cache entry was created before the timestamp in the current session's
    # cache timer. The cache variable is loaded into the user object by
    # _sess_read() in session.inc.
    else:
      if (lib_appglobals.user.cache > cache.created):
        # This cache data is too old and thus not valid for us, ignore it.
        return False;
      else:
        if (cache.serialized):
          cache.data = php.unserialize(cache.data);
    return cache;
  return False;
Ejemplo n.º 6
0
def get(cid, table='cache'):
    """
   Return data from the persistent cache. Data may be stored as either plain 
   text or as serialized data. cache_get will automatically return 
   unserialized objects and arrays.
  
   @param cid
     The cache ID of the data to retrieve.
   @param table
     The table table to store the data in.
     Valid core values are 'cache_filter',
     'cache_menu', 'cache_page', or 'cache' for the default cache.
   @return The cache or FALSE on failure.
  """
    # Garbage collection necessary when enforcing a minimum cache lifetime
    cache_flush = lib_bootstrap.variable_get('cache_flush', 0)
    if (cache_flush and (cache_flush + \
        variable_get('cache_lifetime', 0) <= REQUEST_TIME)):
        # Reset the variable immediately to prevent a meltdown in heavy
        # load situations.
        variable_set('cache_flush', 0)
        # Time to php.flush old cache data
        lib_database.query(\
          "DELETE FROM {" + table + "} WHERE expire != %d AND expire <= %d", \
          CACHE_PERMANENT, cache_flush)
    cache = lib_database.fetch_object(lib_database.query(\
      "SELECT data, created, headers, expire, serialized " + \
      "FROM {" + table + "} WHERE cid = '%s'", cid))
    if (php.isset(cache, 'data')):
        # If the data is permanent or we're not enforcing a minimum cache lifetime
        # always return the cached data.
        if (cache.expire == CACHE_PERMANENT or not \
            variable_get('cache_lifetime', 0)):
            if (cache.serialized):
                cache.data = php.unserialize(cache.data)
        # If enforcing a minimum cache lifetime, validate that the data is
        # currently valid for this user before we return it by making sure the
        # cache entry was created before the timestamp in the current session's
        # cache timer. The cache variable is loaded into the user object by
        # _sess_read() in session.inc.
        else:
            if (lib_appglobals.user.cache > cache.created):
                # This cache data is too old and thus not valid for us, ignore it.
                return False
            else:
                if (cache.serialized):
                    cache.data = php.unserialize(cache.data)
        return cache
    return False