示例#1
0
def invoke_all(*args):
    """
   Invoke a hook in all enabled plugins that implement it.
  
   @param hook
     The name of the hook to invoke.
   @param ...
     Arguments to pass to the hook.
   @return
     An array of return values of the hook implementations. If plugins return
     arrays from their implementations, those are merged into one array.
  """
    global plugins
    args = list(args)
    hook = 'hook_%s' % args[0]
    del (args[0])
    return_ = []
    for plugin_ in implements(hook):
        if (lib_bootstrap.drupal_function_exists(hook, plugins[plugin_])):
            function = DrupyImport.getFunction(\
              plugins[plugin_], hook)
            result = php.call_user_func_array(function, args)
            if (result is not None and php.is_array(result)):
                return_ = p.array_merge_recursive(return_, result)
            elif (result is not None):
                return_.append(result)
    return return_
示例#2
0
def drupal_load(type_, name):
    """
   Includes a file with the provided type and name. This prevents
   including a theme, engine, plugin, etc., more than once.
  
   @param type
     The type of item to load (i.e. theme, theme_engine, plugin).
   @param name
     The name of the item to load.
  
   @return
     TRUE if the item is loaded or has already been loaded.
  """
    php.static(drupal_load, 'files', {})
    if (not php.isset(drupal_load.files, type)):
        drupal_load.files[type_] = {}
    if (php.isset(drupal_load.files[type_], name)):
        return True
    else:
        filename = drupal_get_filename(type_, name)
        if (filename != False):
            lib_plugin.plugins[name] = DrupyImport.import_file(filename)
            drupal_load.files[type_][name] = True
            return True
        else:
            return False
示例#3
0
文件: bootstrap.py 项目: sabren/drupy
def drupal_load(type_, name):
    """
   Includes a file with the provided type and name. This prevents
   including a theme, engine, plugin, etc., more than once.
  
   @param type
     The type of item to load (i.e. theme, theme_engine, plugin).
   @param name
     The name of the item to load.
  
   @return
     TRUE if the item is loaded or has already been loaded.
  """
    php.static(drupal_load, "files", {})
    if not php.isset(drupal_load.files, type):
        drupal_load.files[type_] = {}
    if php.isset(drupal_load.files[type_], name):
        return True
    else:
        filename = drupal_get_filename(type_, name)
        if filename != False:
            lib_plugin.plugins[name] = DrupyImport.import_file(filename)
            drupal_load.files[type_][name] = True
            return True
        else:
            return False
示例#4
0
def invoke_all(*args):
  """
   Invoke a hook in all enabled plugins that implement it.
  
   @param hook
     The name of the hook to invoke.
   @param ...
     Arguments to pass to the hook.
   @return
     An array of return values of the hook implementations. If plugins return
     arrays from their implementations, those are merged into one array.
  """
  global plugins
  args = list(args)
  hook = 'hook_%s' % args[0]
  del(args[0])
  return_ = []
  for plugin_ in implements(hook):
    if (lib_bootstrap.drupal_function_exists(hook, plugins[plugin_])):
      function = DrupyImport.getFunction(\
        plugins[plugin_], hook)
      result = php.call_user_func_array(function, args);
      if (result is not None and php.is_array(result)):
        return_ = p.array_merge_recursive(return_, result);
      elif (result is not None):
        return_.append( result );
  return return_
示例#5
0
def list_(refresh = False, bootstrap = True, sort = False, \
    fixed_list = None):
    """
   Collect a list of all loaded plugins. During the bootstrap, return only
   vital plugins. See bootstrap.inc
  
   @param refresh
     Whether to force the plugin list to be regenerated (such as after the
     administrator has changed the system settings).
   @param bootstrap
     Whether to return the reduced set of plugins loaded in "bootstrap mode"
     for cached pages. See bootstrap.inc.
   @param sort
     By default, plugins are ordered by weight and filename,
     settings this option
     to True, plugin list will be ordered by plugin name.
   @param fixed_list
     (Optional) Override the plugin list with the given plugins.
     Stays until the
     next call with refresh = True.
   @return
     An associative array whose keys and values are the names of all loaded
     plugins.
  """
    php.static(list_, 'list_', {})
    php.static(list_, 'sorted_list')
    if (refresh or fixed_list):
        list_.sorted_list = None
        list_.list_ = {}
        if (fixed_list):
            for name, plugin in fixed_list.items():
                lib_bootstrap.drupal_get_filename('plugin', name,
                                                  plugin['filename'])
                list_.list_[name] = name
        else:
            if (bootstrap):
                result = lib_database.query(\
                  "SELECT name, filename FROM {system} " + \
                  "WHERE type = 'plugin' AND status = 1 AND " + \
                  "bootstrap = 1 ORDER BY weight ASC, filename ASC")
            else:
                result = lib_database.query(\
                  "SELECT name, filename FROM {system} " + \
                  "WHERE type = 'plugin' AND status = 1 " + \
                  "ORDER BY weight ASC, filename ASC")
            while True:
                plugin_ = lib_database.fetch_object(result)
                if (plugin_ == None or plugin_ == False):
                    break
                if (DrupyImport.exists(plugin_.filename)):
                    lib_bootstrap.drupal_get_filename('plugin', \
                      plugin_.name, plugin_.filename)
                    list_.list_[plugin_.name] = plugin_.name
    if (sort):
        if (list_.sorted_list == None):
            list_.sorted_list = plugin_list.list_
            p.ksort(list_.sorted_list)
        return list_.sorted_list
    return list_.list_
示例#6
0
def list_(refresh = False, bootstrap = True, sort = False, \
    fixed_list = None):
  """
   Collect a list of all loaded plugins. During the bootstrap, return only
   vital plugins. See bootstrap.inc
  
   @param refresh
     Whether to force the plugin list to be regenerated (such as after the
     administrator has changed the system settings).
   @param bootstrap
     Whether to return the reduced set of plugins loaded in "bootstrap mode"
     for cached pages. See bootstrap.inc.
   @param sort
     By default, plugins are ordered by weight and filename,
     settings this option
     to True, plugin list will be ordered by plugin name.
   @param fixed_list
     (Optional) Override the plugin list with the given plugins.
     Stays until the
     next call with refresh = True.
   @return
     An associative array whose keys and values are the names of all loaded
     plugins.
  """
  php.static(list_, 'list_', {})
  php.static(list_, 'sorted_list')
  if (refresh or fixed_list):
    list_.sorted_list = None
    list_.list_ = {}
    if (fixed_list):
      for name,plugin in fixed_list.items():
        lib_bootstrap.drupal_get_filename('plugin', name, plugin['filename'])
        list_.list_[name] = name
    else:
      if (bootstrap):
        result = lib_database.query(\
          "SELECT name, filename FROM {system} " + \
          "WHERE type = 'plugin' AND status = 1 AND " + \
          "bootstrap = 1 ORDER BY weight ASC, filename ASC")
      else:
        result = lib_database.query(\
          "SELECT name, filename FROM {system} " + \
          "WHERE type = 'plugin' AND status = 1 " + \
          "ORDER BY weight ASC, filename ASC")
      while True:
        plugin_ = lib_database.fetch_object(result)
        if (plugin_ == None or plugin_ == False):
          break
        if (DrupyImport.exists(plugin_.filename)):
          lib_bootstrap.drupal_get_filename('plugin', \
            plugin_.name, plugin_.filename)
          list_.list_[plugin_.name] = plugin_.name
  if (sort):
    if (list_.sorted_list == None):
      list_.sorted_list = plugin_list.list_
      p.ksort(list_.sorted_list)
    return list_.sorted_list
  return list_.list_
示例#7
0
def invoke(plugin_, hook_, *args):
  """
   Invoke a hook in a particular plugin.
  
   @param plugin
     The name of the plugin (without the .plugin extension).
   @param hook
     The name of the hook to invoke.
   @param ...
     Arguments to pass to the hook implementation.
   @return
     The return value of the hook implementation.
  """
  if (hook(plugin_, hook_)):
    function_name = 'hook_' + hook_
    function = DrupyImport.getFunction(plugins[plugin_], function_name)
    return php.call_user_func_array(function, args)
示例#8
0
def invoke(plugin_, hook_, *args):
    """
   Invoke a hook in a particular plugin.
  
   @param plugin
     The name of the plugin (without the .plugin extension).
   @param hook
     The name of the hook to invoke.
   @param ...
     Arguments to pass to the hook implementation.
   @return
     The return value of the hook implementation.
  """
    if (hook(plugin_, hook_)):
        function_name = 'hook_' + hook_
        function = DrupyImport.getFunction(plugins[plugin_], function_name)
        return php.call_user_func_array(function, args)
示例#9
0
out_plugins_html = php.htmlspecialchars(out_plugins)

out_themes = php.print_r(lib_theme.processors, True)
out_themes_html = php.htmlspecialchars(out_themes)

out_users = php.print_r(lib_database.query(\
  'SELECT * FROM users WHERE users.uid > 0'), True)
out_users_html = php.htmlspecialchars(out_users)

out_vars = php.print_r(vars(), True)
out_vars = re.sub('[a-zA-Z0-9_\.-]+@.+?\.[a-zA-Z]+', '********', out_vars)
out_vars = re.sub('[a-zA-Z0-9]{32}', \
                  '********************************', out_vars)
out_vars = php.htmlspecialchars(out_vars)

out_mods = php.print_r(DrupyImport.modules(), True)
out_mods = php.htmlspecialchars(out_mods)

#
# Executed from Web
#
if php.SERVER['WEB']:
  print "<?xml version='1.0' encoding='UTF-8'?>"
  print "<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' " + \
    "'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'>"
  print "<html xmlns='http://www.w3.org/1999/xhtml'>"
  print "<head>"
  print "<title>Drupy: Drupal in Python</title>"
  print "<meta http-equiv='Content-Type' content='text/html; charset=UTF-8' />"
  print "<meta name='revised' content='DrupyStatus, %s' />" % revised
  print "</head>"
示例#10
0
def hook_init(template):
  file = php.dirname(template.filename) + '/template.py'
  if (php.file_exists(file)):
    lib_theme.processors['template'] = DrupyImport.import_file(file)
示例#11
0
out_plugins_html = php.htmlspecialchars(out_plugins)

out_themes = php.print_r(lib_theme.processors, True)
out_themes_html = php.htmlspecialchars(out_themes)

out_users = php.print_r(lib_database.query(\
  'SELECT * FROM users WHERE users.uid > 0'), True)
out_users_html = php.htmlspecialchars(out_users)

out_vars = php.print_r(vars(), True)
out_vars = re.sub('[a-zA-Z0-9_\.-]+@.+?\.[a-zA-Z]+', '********', out_vars)
out_vars = re.sub('[a-zA-Z0-9]{32}', \
                  '********************************', out_vars)
out_vars = php.htmlspecialchars(out_vars)

out_mods = php.print_r(DrupyImport.modules(), True)
out_mods = php.htmlspecialchars(out_mods)

#
# Executed from Web
#
if php.SERVER['WEB']:
    print "<?xml version='1.0' encoding='UTF-8'?>"
    print "<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' " + \
      "'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'>"
    print "<html xmlns='http://www.w3.org/1999/xhtml'>"
    print "<head>"
    print "<title>Drupy: Drupal in Python</title>"
    print "<meta http-equiv='Content-Type' content='text/html; charset=UTF-8' />"
    print "<meta name='revised' content='DrupyStatus, %s' />" % revised
    print "</head>"