本文整理汇总了Python中lib.drupy.DrupyPHP.empty方法的典型用法代码示例。如果您正苦于以下问题:Python DrupyPHP.empty方法的具体用法?Python DrupyPHP.empty怎么用?Python DrupyPHP.empty使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类lib.drupy.DrupyPHP
的用法示例。
在下文中一共展示了DrupyPHP.empty方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _create_field_sql
# 需要导入模块: from lib.drupy import DrupyPHP [as 别名]
# 或者: from lib.drupy.DrupyPHP import empty [as 别名]
def _create_field_sql(name, spec):
"""
Create an SQL string for a field to be used in table creation or alteration.
Before passing a field out of a schema definition into this function it has
to be processed by _db_process_field().
@param name
Name of the field.
@param spec
The field specification, as per the schema data structure format.
"""
sql = "`" + name + "` " . spec['mysql_type']
if (php.isset(spec, 'length')):
sql += '(' + spec['length'] + ')'
elif (php.isset(spec, 'precision') and php.isset(spec, 'scale')):
sql += '(' + spec['precision'] + ', ' + spec['scale'] + ')'
if (not php.empty(spec['unsigned'])):
sql += ' unsigned'
if (not php.empty(spec['not None'])):
sql += ' NOT None'
if (not php.empty(spec['auto_increment'])):
sql += ' auto_increment'
if (php.isset(spec, 'default')):
if (is_string(spec['default'])):
spec['default'] = "'" + spec['default'] + "'"
sql += ' DEFAULT ' + spec['default']
if (php.empty(spec['not None']) and not php.isset(spec, 'default')):
sql += ' DEFAULT None'
return sql
示例2: theme_preprocess_page
# 需要导入模块: from lib.drupy import DrupyPHP [as 别名]
# 或者: from lib.drupy.DrupyPHP import empty [as 别名]
def theme_preprocess_page(vars_):
"""
Override or insert variables into the page template.
"""
php.Reference.check(vars_)
vars_['tabs2'] = menu_secondary_local_tasks()
vars_['primary_nav'] = (lib_theme.theme('links', \
vars_['main_menu'], {'class' : 'links main-menu'}) if \
php.isset(vars_, 'main_menu') else False)
vars_['secondary_nav'] = (lib_theme.theme('links', \
vars_['secondary_menu'], \
{'class' : 'links secondary-menu'}) if \
php.isset(vars_, 'secondary_menu') else False)
vars_['ie_styles'] = get_ie_styles()
# Prepare header
site_fields = []
if (not php.empty(vars_['site_name'])):
site_fields.append( check_plain(vars_['site_name']) )
if (not php.empty(vars_['site_slogan'])):
site_fields.append( check_plain(vars_['site_slogan']) )
vars_['site_title'] = php.implode(' ', site_fields)
if (not php.empty(site_fields)):
site_fields[0] = '<span>' + site_fields[0] + '</span>'
vars_['site_html'] = php.implode(' ', site_fields)
# Hook into color.module
if (lib_plugin.exists('color')):
lib_plugin.plugins['color']._page_alter(vars_)
示例3: _create_keys_sql
# 需要导入模块: from lib.drupy import DrupyPHP [as 别名]
# 或者: from lib.drupy.DrupyPHP import empty [as 别名]
def _create_keys_sql(spec):
keys = {}
if (not php.empty(spec['primary key'])):
keys.append( 'PRIMARY KEY (' + \
_db_create_key_sql(spec['primary key']) + ')' )
if (not php.empty(spec['unique keys'])):
for key,fields in spec['unique keys'].items():
keys.append( 'UNIQUE KEY ' + key + \
' (' + _db_create_key_sql(fields) + ')' )
if (not php.empty(spec['indexes'])):
for index,fields in spec['indexes'].items():
keys.append( 'INDEX ' + index + ' (' + \
_db_create_key_sql(fields) + ')' )
return keys
示例4: rewrite_sql
# 需要导入模块: from lib.drupy import DrupyPHP [as 别名]
# 或者: from lib.drupy.DrupyPHP import empty [as 别名]
def rewrite_sql(query, primary_table = 'n', primary_field = 'nid', args = []):
join_, where, distinct = _rewrite_sql(query, primary_table, \
primary_field, args)
if (distinct):
query = distinct_field(primary_table, primary_field, query)
if (not php.empty(where) or not php.empty(join_)):
pattern = \
'{ ' + \
' # Beginning of the string ' + \
' ^ ' + \
' ((?P<anonymous_view> ' + \
' # Everything within this set of parentheses ' + \
' # is named "anonymous view ' + \
' (?: ' + \
' # anything not parentheses ' + \
' [^()]++ ' + \
' | ' + \
' # an open parenthesis, more anonymous view and ' + \
' # finally a close parenthesis. ' + \
' \( (?P>anonymous_view) \) ' + \
' )* ' + \
' )[^()]+WHERE) ' + \
'}X'
matches = []
php.preg_match(pattern, query, matches)
if (where):
n = php.strlen(matches[1])
second_part = php.substr(query, n)
first_part = php.substr(matches[1], 0, n - 5) + \
" join WHERE where AND ( "
# PHP 4 does not support strrpos for strings. We emulate it.
haystack_reverse = php.strrev(second_part)
# No need to use strrev on the needle, we supply GROUP, ORDER, LIMIT
# reversed.
for needle_reverse in ('PUORG', 'REDRO', 'TIMIL'):
pos = php.strpos(haystack_reverse, needle_reverse)
if (pos != False):
# All needles are five characters long.
pos += 5
break
if (pos == False):
query = first_part + second_part + ')'
else:
query = first_part + substr(second_part, 0, -pos) + ')' + \
php.substr(second_part, -pos)
else:
query = matches[1] + " join " + \
php.substr(query, php.strlen(matches[1]))
return query
示例5: drupal_get_messages
# 需要导入模块: from lib.drupy import DrupyPHP [as 别名]
# 或者: from lib.drupy.DrupyPHP import empty [as 别名]
def drupal_get_messages(type=None, clear_queue=True):
"""
Return all messages that have been set.
@param type
(optional) Only return messages of this type.
@param clear_queue
(optional) Set to FALSE if you do not want to clear the messages queue
@return
An associative array, the key is the message type, the value an array
of messages. If the type parameter is passed, you get only that type,
or an empty array if there are no such messages. If type is not passed,
all message types are returned, or an empty array if none exist.
"""
messages = drupal_set_message()
if not php.empty("messages"):
if type != None and type != False:
if clear_queue:
del (php.SESSION["messages"][type])
if php.isset(messages, type):
return {type: messages[type]}
else:
if clear_queue:
del (php.SESSION["messages"])
return messages
return {}
示例6: create_table_sql
# 需要导入模块: from lib.drupy import DrupyPHP [as 别名]
# 或者: from lib.drupy.DrupyPHP import empty [as 别名]
def create_table_sql(name, table):
"""
Generate SQL to create a new table from a Drupal schema definition.
@param name
The name of the table to create.
@param table
A Schema API table definition array.
@return
An array of SQL statements to create the table.
"""
if (php.empty(table['mysql_suffix'])):
table['mysql_suffix'] = "/*not 40100 DEFAULT CHARACTER SET UTF8 */"
sql = "CREATE TABLE {" + name + "} (\n"
# Add the SQL statement for each field.
for field_name,field in table['fields'].items():
sql += _db_create_field_sql(field_name, _db_process_field(field)) + ", \n"
# Process keys & indexes.
keys = _db_create_keys_sql(table)
if (php.count(keys)):
sql += php.implode(", \n", keys) + ", \n"
# Remove the last comma and space.
sql = php.substr(sql, 0, -3) + "\n) "
sql += table['mysql_suffix']
return array(sql)
示例7: ip_address
# 需要导入模块: from lib.drupy import DrupyPHP [as 别名]
# 或者: from lib.drupy.DrupyPHP import empty [as 别名]
def ip_address(reset=False):
"""
If Drupal is behind a reverse proxy, we use the X-Forwarded-For header
instead of $_SERVER['REMOTE_ADDR'], which would be the IP address of
the proxy server, and not the client's. If Drupal is run in a cluster
we use the X-Cluster-Client-Ip header instead.
@param $reset
Reset the current IP address saved in static.
@return
IP address of client machine, adjusted for reverse proxy and/or cluster
environments.
"""
php.static(ip_address, "ip_address")
if ip_address.ip_address is None or reset:
ip_address.ip_address = php.SERVER["REMOTE_ADDR"]
if variable_get("reverse_proxy", 0):
if php.array_key_exists("HTTP_X_FORWARDED_FOR", php.SERVER):
# If an array of known reverse proxy IPs is provided, then trust
# the XFF header if request really comes from one of them.
reverse_proxy_addresses = variable_get("reverse_proxy_addresses", tuple())
if not php.empty(reverse_proxy_addresses) and php.in_array(
ip_address.ip_address, reverse_proxy_addresses, True
):
# If there are several arguments, we need to check the most
# recently added one, i.e. the last one.
ip_address.ip_address = php.array_pop(php.explode(",", php.SERVER["HTTP_X_FORWARDED_FOR"]))
# When Drupal is run in a cluster environment,
# REMOTE_ADDR contains the IP
# address of a server in the cluster, while the IP address
# of the client is
# stored in HTTP_X_CLUSTER_CLIENT_IP.
if php.array_key_exists("HTTP_X_CLUSTER_CLIENT_IP", php.SERVER):
ip_address.ip_address = php.SERVER["HTTP_X_CLUSTER_CLIENT_IP"]
return ip_address.ip_address
示例8: disable
# 需要导入模块: from lib.drupy import DrupyPHP [as 别名]
# 或者: from lib.drupy.DrupyPHP import empty [as 别名]
def disable(plugin_list_):
"""
Disable a given set of plugins.
@param plugin_list
An array of plugin names.
"""
invoke_plugins = []
for plugin_ in plugin_list_:
if (plugin_exists(plugin_)):
# Check if node_access table needs rebuilding.
if (not node_access_needs_rebuild() and plugin_hook(plugin_, \
'node_grants')):
node_access_needs_rebuild(True)
plugin_load_install(plugin_)
plugin_invoke(plugin_, 'disable')
db_query(\
"UPDATE {system} SET status = %d " + \
"WHERE type = '%s' AND name = '%s'", 0, 'plugin', plugin_)
invoke_plugins.append(plugin)
if (not php.empty(invoke_plugins)):
# Refresh the plugin list to exclude the disabled plugins.
plugin_list(True, False)
# Force to regenerate the stored list of hook implementations.
registry_rebuild()
# If there remains no more node_access plugin, rebuilding will be
# straightforward, we can do it right now.
if (node_access_needs_rebuild() and \
php.count(plugin_implements('node_grants')) == 0):
node_access_rebuild()
示例9: enable
# 需要导入模块: from lib.drupy import DrupyPHP [as 别名]
# 或者: from lib.drupy.DrupyPHP import empty [as 别名]
def enable(plugin_list_):
"""
Enable a given list of plugins.
@param plugin_list
An array of plugin names.
"""
invoke_plugins = []
for plugin_ in plugin_list_:
existing = db_fetch_object(db_query(\
"SELECT status FROM {system} " + \
"WHERE type = '%s' AND name = '%s'", 'plugin', plugin))
if (existing.status == 0):
plugin_load_install(plugin_)
db_query(\
"UPDATE {system} SET status = %d " + \
"WHERE type = '%s' AND name = '%s'", 1, 'plugin', plugin_)
drupal_load('plugin', plugin_)
invoke_plugins.append( plugin )
if (not php.empty(invoke_plugins)):
# Refresh the plugin list to include the new enabled plugin.
plugin_list(True, False)
# Force to regenerate the stored list of hook implementations.
registry_rebuild()
for plugin_ in invoke_plugins:
plugin_invoke(plugin_, 'enable')
# Check if node_access table needs rebuilding.
# We check for the existence of node_access_needs_rebuild() since
# at install time, plugin_enable() could be called while node.plugin
# is not enabled yet.
if (drupal_function_exists('node_access_needs_rebuild') and \
not node_access_needs_rebuild() and \
plugin_hook(plugin_, 'node_grants')):
node_access_needs_rebuild(True)
示例10: cell
# 需要导入模块: from lib.drupy import DrupyPHP [as 别名]
# 或者: from lib.drupy.DrupyPHP import empty [as 别名]
def cell(cell, header, ts, i):
"""
Format a table cell.
Adds a class attribute to all cells in the currently active column.
@param cell
The cell to format.
@param header
An array of column headers in the format described in theme_table().
@param ts
The current table sort context as returned from hook_init().
@param i
The index of the cell's table column.
@return
A properly formatted cell, ready for _theme_table_cell().
"""
if (php.isset(header[i]['data']) and header[i]['data'] == ts['name'] and
not php.empty(header[i]['field'])):
if php.is_array(cell):
if php.isset(cell['class']):
cell['class'] += ' active'
else:
cell['class'] = 'active'
else:
cell = {'data': cell, 'class': 'active'}
return cell
示例11: url_rewrite
# 需要导入模块: from lib.drupy import DrupyPHP [as 别名]
# 或者: from lib.drupy.DrupyPHP import empty [as 别名]
def url_rewrite(path, options):
"""
Rewrite URL's with language based prefix. Parameters are the same
as those of the url() function.
"""
# Only modify relative (insite) URLs.
if (not options['external']):
# Language can be passed as an option, or we go for current language.
if (not php.isset(options, 'language')):
options['language'] = lib_appglobals.language
lang_type = variable_get('language_negotiation', \
lib_bootstrap.LANGUAGE_NEGOTIATION_NONE)
if lang_type == lib_bootstrap.LANGUAGE_NEGOTIATION_NONE:
# No language dependent path allowed in this mode.
del(options['language'])
return
elif lang_type == lib_bootstrap.LANGUAGE_NEGOTIATION_DOMAIN:
if (options['language'].domain):
# Ask for an absolute URL with our modified base_url.
options['absolute'] = True
options['base_url'] = options['language'].domain
return
elif lang_type == lib_bootstrap.LANGUAGE_NEGOTIATION_PATH_DEFAULT:
default = language_default()
if (options['language'].language == default.language):
return
if lang_type == lib_bootstrap.LANGUAGE_NEGOTIATION_PATH:
if (not php.empty(options['language'].prefix)):
options['prefix'] = options['language'].prefix + '/'
return
示例12: rebuild_cache
# 需要导入模块: from lib.drupy import DrupyPHP [as 别名]
# 或者: from lib.drupy.DrupyPHP import empty [as 别名]
def rebuild_cache():
"""
Rebuild the database cache of plugin files.
@return
The array of filesystem objects used to rebuild the cache.
"""
# Get current list of plugins
files = drupal_system_listing('\.plugin$', 'plugins', 'name', 0)
# Extract current files from database.
system_get_files_database(files, 'plugin')
ksort(files)
# Set defaults for plugin info
defaults = {
'dependencies' : [],
'dependents' : [],
'description' : '',
'version' : None,
'php' : DRUPAL_MINIMUM_PHP,
}
for filename,file in files.items():
# Look for the info file.
file.info = drupal_parse_info_file(php.dirname(file.filename) + '/' + \
file.name + '.info')
# Skip plugins that don't provide info.
if (php.empty(file.info)):
del(files[filename])
continue
# Merge in defaults and save.
files[filename].info = file.info + defaults
# Invoke hook_system_info_alter() to give installed plugins a chance to
# modify the data in the .info files if necessary.
drupal_alter('system_info', files[filename].info, files[filename])
# Log the critical hooks implemented by this plugin.
bootstrap = 0
for hook in bootstrap_hooks():
if (plugin_hook(file.name, hook)):
bootstrap = 1
break
# Update the contents of the system table:
if (php.isset(file, 'status') or (php.isset(file, 'old_filename') and \
file.old_filename != file.filename)):
db_query(\
"UPDATE {system} SET info = '%s', name = '%s', " + \
"filename = '%s', bootstrap = %d WHERE filename = '%s'", \
php.serialize(files[filename].info), file.name, \
file.filename, bootstrap, file.old_filename)
else:
# This is a new plugin.
files[filename].status = 0
db_query(\
"INSERT INTO {system} (name, info, type, " + \
"filename, status, bootstrap) VALUES " + \
"('%s', '%s', '%s', '%s', %d, %d)", \
file.name, php.serialize(files[filename].info), \
'plugin', file.filename, 0, bootstrap)
files = _plugin_build_dependencies(files)
return files
示例13: drupal_init_path
# 需要导入模块: from lib.drupy import DrupyPHP [as 别名]
# 或者: from lib.drupy.DrupyPHP import empty [as 别名]
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'))
示例14: drupal_unpack
# 需要导入模块: from lib.drupy import DrupyPHP [as 别名]
# 或者: from lib.drupy.DrupyPHP import empty [as 别名]
def drupal_unpack(obj, field="data"):
"""
Unserializes and appends elements from a serialized string.
@param obj
The object to which the elements are appended.
@param field
The attribute of obj whose value should be unserialized.
"""
if hasattr(obj, field) and not php.empty(getattr(obj, field)):
data = php.unserialize(getattr(obj, field))
else:
data = None
if hasattr(obj, field) and not php.empty(data):
for key, value in data.items():
if not php.isset(obj, key):
setattr(obj, key, value)
return obj
示例15: initialize
# 需要导入模块: from lib.drupy import DrupyPHP [as 别名]
# 或者: from lib.drupy.DrupyPHP import empty [as 别名]
def initialize():
"""
Choose a language for the page, based on language negotiation settings.
"""
# Configured presentation language mode.
mode = variable_get('language_negotiation', \
lib_bootstrap.LANGUAGE_NEGOTIATION_NONE)
# Get a list of enabled languages.
languages = lib_bootstrap.language_list('enabled')
languages = languages[1]
if mode == lib_bootstrap.LANGUAGE_NEGOTIATION_NONE:
return language_default()
elif mode == lib_bootstrap.LANGUAGE_NEGOTIATION_DOMAIN:
for language in languages:
parts = php.parse_url(language.domain)
if (not php.empty(parts['host']) and \
(php.SERVER['php.SERVER_NAME'] == parts['host'])):
return language
return language_default()
elif mode == lib_bootstrap.LANGUAGE_NEGOTIATION_PATH_DEFAULT or \
mode == lib_bootstrap.LANGUAGE_NEGOTIATION_PATH:
# _GET['q'] might not be available at this time, because
# path initialization runs after the language bootstrap phase.
args = (php.explode('/', _GET['q']) if php.isset(_GET, 'q') else [])
prefix = php.array_shift(args)
# Search prefix within enabled languages.
for language in languages:
if (not php.empty(language.prefix) and language.prefix == prefix):
# Rebuild php.GET['q'] with the language removed.
php.GET['q'] = php.implode('/', args)
return language
if (mode == LANGUAGE_NEGOTIATION_PATH_DEFAULT):
# If we did not found the language by prefix, choose the default.
return language_default()
# User language.
if (lib_appglobals.user.uid and \
php.isset(languages[lib_appglobals.user.language])):
return languages[lib_appglobals.user.language]
# Browser accept-language parsing.
language = language_from_browser()
if (language):
return language
# Fall back on the default if everything else fails.
return language_default()