本文整理汇总了Python中lib.drupy.DrupyPHP.isset方法的典型用法代码示例。如果您正苦于以下问题:Python DrupyPHP.isset方法的具体用法?Python DrupyPHP.isset怎么用?Python DrupyPHP.isset使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类lib.drupy.DrupyPHP
的用法示例。
在下文中一共展示了DrupyPHP.isset方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: drupal_set_message
# 需要导入模块: from lib.drupy import DrupyPHP [as 别名]
# 或者: from lib.drupy.DrupyPHP import isset [as 别名]
def drupal_set_message(message=None, type="status", repeat=True):
"""
Set a message which reflects the status of the performed operation.
If the def is called with no arguments, this def returns all set
messages without clearing them.
@param message
The message should begin with a capital letter and always ends with a
period '.'.
@param type
The type of the message. One of the following values are possible:
- 'status'
- 'warning'
- 'error'
@param repeat
If this is FALSE and the message is already set, then the message won't
be repeated.
"""
if message:
if not php.isset(php.SESSION, "messages"):
php.SESSION["messages"] = {}
if not php.isset(php.SESSION["messages"], type):
php.SESSION["messages"][type] = []
if repeat or not php.in_array(message, php.SESSION["messages"][type]):
php.SESSION["messages"][type].append(message)
# messages not set when DB connection fails
return php.SESSION["messages"] if php.isset(php.SESSION, "messages") else None
示例2: connect
# 需要导入模块: from lib.drupy import DrupyPHP [as 别名]
# 或者: from lib.drupy.DrupyPHP import isset [as 别名]
def connect(url):
"""
Initialise a database connection.
Note that mysqli does not support persistent connections.
"""
# Check if MySQLi support is present in PHP
url = php.parse_url(url, 3306)
# Decode url-encoded information in the db connection string
url['user'] = php.urldecode(url['user'])
# Test if database url has a password.
url['pass'] = (php.urldecode(url['pass']) if php.isset(url, 'pass') else '')
url['host'] = php.urldecode(url['host'])
url['path'] = php.urldecode(url['path'])
if (not php.isset(url, 'port')):
url['port'] = None
connection = DrupyMySQL.mysqli_real_connect(\
url['host'], url['user'], url['pass'], php.substr(url['path'], 1), \
url['port'], '', DrupyMySQL.MYSQLI_CLIENT_FOUND_ROWS)
if (DrupyMySQL.mysqli_connect_errno() > 0):
_db_error_page(DrupyMySQL.mysqli_connect_error())
# Force UTF-8.
DrupyMySQL.mysqli_query(connection, 'SET NAMES "utf8"')
# Require ANSI mode to improve SQL portability.
DrupyMySQL.mysqli_query(connection, "SET php.SESSION sql_mode='ANSI'")
return connection
示例3: arg
# 需要导入模块: from lib.drupy import DrupyPHP [as 别名]
# 或者: from lib.drupy.DrupyPHP import isset [as 别名]
def arg(index = None, path = None):
"""
Return a component of the current Drupal path.
When viewing a page at the path "admin/build/types", for example, arg(0)
would return "admin", arg(1) would return "content", and arg(2) would return
"types".
Avoid use of this function where possible, as resulting code is hard to read.
Instead, attempt to use named arguments in menu callback functions. See the
explanation in menu.inc for how to construct callbacks that take arguments.
@param index
The index of the component, where each component is separated by a '/'
(forward-slash), and where the first component has an index of 0 (zero).
@return
The component specified by index, or NULL if the specified component was
not found.
"""
php.static(arg, 'arguments', {})
if (path is None):
path = php.GET['q'];
if (not php.isset(arg.arguments, path)):
arg.arguments[path] = php.explode('/', path);
if (index is None):
return arg.arguments[path];
if (php.isset(arg.arguments[path], index)):
return arg.arguments[path][index];
示例4: drupal_load
# 需要导入模块: from lib.drupy import DrupyPHP [as 别名]
# 或者: from lib.drupy.DrupyPHP import isset [as 别名]
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
示例5: cell
# 需要导入模块: from lib.drupy import DrupyPHP [as 别名]
# 或者: from lib.drupy.DrupyPHP import isset [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
示例6: _create_field_sql
# 需要导入模块: from lib.drupy import DrupyPHP [as 别名]
# 或者: from lib.drupy.DrupyPHP import isset [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
示例7: theme_preprocess_page
# 需要导入模块: from lib.drupy import DrupyPHP [as 别名]
# 或者: from lib.drupy.DrupyPHP import isset [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_)
示例8: rebuild_cache
# 需要导入模块: from lib.drupy import DrupyPHP [as 别名]
# 或者: from lib.drupy.DrupyPHP import isset [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
示例9: drupal_initialize_variables
# 需要导入模块: from lib.drupy import DrupyPHP [as 别名]
# 或者: from lib.drupy.DrupyPHP import isset [as 别名]
def drupal_initialize_variables():
"""
Initialize variables needed for the rest of the execution.
"""
if not php.isset(php.SERVER, "HTTP_REFERER"):
php.SERVER["HTTP_REFERER"] = ""
if not php.isset(php.SERVER, "SERVER_PROTOCOL") or (
php.SERVER["SERVER_PROTOCOL"] != "HTTP/1.0" and php.SERVER["SERVER_PROTOCOL"] != "HTTP/1.1"
):
php.SERVER["SERVER_PROTOCOL"] = "HTTP/1.0"
示例10: drupal_page_cache_header
# 需要导入模块: from lib.drupy import DrupyPHP [as 别名]
# 或者: from lib.drupy.DrupyPHP import isset [as 别名]
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
示例11: install_page
# 需要导入模块: from lib.drupy import DrupyPHP [as 别名]
# 或者: from lib.drupy.DrupyPHP import isset [as 别名]
def install_page(content):
"""
Generate a themed installation page.
Note: this function is not themeable.
@param content
The page content to show.
"""
drupal_set_header('Content-Type: text/html; charset=utf-8')
# Assign content.
variables['content'] = content
# Delay setting the message variable so it can be processed below.
variables['show_messages'] = False
# The maintenance preprocess function is recycled here.
template_preprocess_maintenance_page(variables)
# Special handling of error messages
messages = drupal_set_message()
if (php.isset(messages, 'error')):
title = (st('The following errors must be resolved before you can ' + \
'continue the installation process') if \
(php.count(messages['error']) > 1) else \
st('The following error must be resolved before you can ' + \
'continue the installation process'))
variables['messages'] += '<h3>' + title + ':</h3>'
variables['messages'] += theme('status_messages', 'error')
variables['content'] += '<p>' + st('Please check the error ' + \
'messages and <a href="not url">try again</a>.', \
{'not url' : request_uri()}) + '</p>'
# Special handling of warning messages
if (php.isset(messages, 'warning')):
title = (st('The following installation warnings should be ' + \
'carefully reviewed') if \
(php.count(messages['warning']) > 1) else \
st('The following installation warning should be carefully reviewed'))
variables['messages'] += '<h4>' + title + ':</h4>'
variables['messages'] += theme('status_messages', 'warning')
# Special handling of status messages
if (php.isset(messages, 'status')):
title = (st('The following installation warnings should be ' + \
'carefully reviewed, but in most cases may be safely ignored') if \
(php.count(messages['status']) > 1) else st('The following ' + \
'installation warning should be carefully reviewed, but in ' + \
'most cases may be safely ignored'))
variables['messages'] += '<h4>' + title + ':</h4>'
variables['messages'] += theme('status_messages', 'status')
# This was called as a theme hook (not template), so we need to
# fix path_to_theme() for the template, to point at the actual
# theme rather than system plugin as owner of the hook.
lib_appglobals.theme_path = 'themes/garland'
return theme_render_template('themes/garland/maintenance-page.tpl.py', \
variables)
示例12: request_uri
# 需要导入模块: from lib.drupy import DrupyPHP [as 别名]
# 或者: from lib.drupy.DrupyPHP import isset [as 别名]
def request_uri():
"""
Since php.SERVER['php.REQUEST_URI'] is only available on Apache, we
generate an equivalent using other environment variables.
"""
if php.isset(php.SERVER, "REQUEST_URI"):
uri = php.SERVER["REQUEST_URI"]
else:
if php.isset(php.SERVER, "argv"):
uri = php.SERVER["SCRIPT_NAME"] + "?" + php.SERVER["argv"][0]
elif php.isset(php.SERVER, "QUERY_STRING"):
uri = php.SERVER["SCRIPT_NAME"] + "?" + php.SERVER["QUERY_STRING"]
else:
uri = php.SERVER["SCRIPT_NAME"]
return uri
示例13: url_rewrite
# 需要导入模块: from lib.drupy import DrupyPHP [as 别名]
# 或者: from lib.drupy.DrupyPHP import isset [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
示例14: drupal_get_messages
# 需要导入模块: from lib.drupy import DrupyPHP [as 别名]
# 或者: from lib.drupy.DrupyPHP import isset [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 {}
示例15: timer_read
# 需要导入模块: from lib.drupy import DrupyPHP [as 别名]
# 或者: from lib.drupy.DrupyPHP import isset [as 别名]
def timer_read(name):
"""
Read the current timer value without stopping the timer.
@param name
The name of the timer.
@return
The current timer value in ms.
"""
if php.isset(lib_appglobals.timers[name], "start"):
(usec, sec) = php.explode(" ", php.microtime())
stop = float(usec) + float(sec)
diff = round((stop - lib_appglobals.timers[name]["start"]) * 1000, 2)
if php.isset(lib_appglobals.timers[name], "time"):
diff += lib_appglobals.timers[name]["time"]
return diff