本文整理汇总了PHP中drupal_strlen函数的典型用法代码示例。如果您正苦于以下问题:PHP drupal_strlen函数的具体用法?PHP drupal_strlen怎么用?PHP drupal_strlen使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了drupal_strlen函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: quickdrupal_username
/**
* Override theme_username() function.
* Removes the text '(not verified)' for anonymous users.
*/
function quickdrupal_username($object)
{
if ($object->uid && $object->name) {
if (drupal_strlen($object->name) > 20) {
$name = drupal_substr($object->name, 0, 15) . '...';
} else {
$name = $object->name;
}
if (user_access('access user profiles')) {
$output = l($name, 'user/' . $object->uid, array('attributes' => array('title' => t('View user profile.'))));
} else {
$output = check_plain($name);
}
} else {
if ($object->name) {
if (!empty($object->homepage)) {
$output = l($object->name, $object->homepage, array('attributes' => array('rel' => 'nofollow')));
} else {
$output = check_plain($object->name);
}
} else {
$output = check_plain(variable_get('anonymous', t('Anonymous')));
}
}
return $output;
}
示例2: cvs_to_versioncontrol_project_update_2
/**
* Convert project repository data.
*/
function cvs_to_versioncontrol_project_update_2()
{
// This determines how many projects will be processed in each batch run. A reasonable
// default has been chosen, but you may want to tweak depending on your setup.
$limit = 100;
// Multi-part update
if (!isset($_SESSION['cvs_to_versioncontrol_project_update_2'])) {
$_SESSION['cvs_to_versioncontrol_project_update_2'] = 0;
$_SESSION['cvs_to_versioncontrol_project_update_2_max'] = db_result(db_query("SELECT COUNT(*) FROM {cvs_projects}"));
}
// Pull the next batch of users.
$projects = db_query_range("SELECT p.nid, p.rid, p.directory, r.modules FROM {cvs_projects} p INNER JOIN {cvs_repositories} r ON p.rid = r.rid ORDER BY p.nid", $_SESSION['cvs_to_versioncontrol_project_update_2'], $limit);
// Loop through each project.
while ($project = db_fetch_object($projects)) {
// Add the repo module, and chop off the trailing slash.
$directory = '/' . trim($project->modules) . drupal_substr($project->directory, 0, drupal_strlen($project->directory) - 1);
db_query("INSERT INTO {versioncontrol_project_projects} (nid, repo_id, directory) VALUES (%d, %d, '%s')", $project->nid, $project->rid, $directory);
$_SESSION['cvs_to_versioncontrol_project_update_2']++;
}
if ($_SESSION['cvs_to_versioncontrol_project_update_2'] >= $_SESSION['cvs_to_versioncontrol_project_update_2_max']) {
$count = $_SESSION['cvs_to_versioncontrol_project_update_2_max'];
unset($_SESSION['cvs_to_versioncontrol_project_update_2']);
unset($_SESSION['cvs_to_versioncontrol_project_update_2_max']);
return array(array('success' => TRUE, 'query' => t('Converted @count project repository entries.', array('@count' => $count))));
}
return array('#finished' => $_SESSION['cvs_to_versioncontrol_project_update_2'] / $_SESSION['cvs_to_versioncontrol_project_update_2_max']);
}
示例3: ideal_payment_api_transreq_call
/**
* Calls a transaction request
*/
function ideal_payment_api_transreq_call($order)
{
//Get user ID
global $user;
if ($user) {
$user_id = $user->uid;
}
$path_module = drupal_get_path('module', 'ideal_payment_api');
require_once $path_module . '/lib/iDEALConnector.php';
$iDEALConnector = new iDEALConnector();
$order['description'] = check_plain($order['description']);
if (drupal_strlen($order['description']) > 32) {
//@TODO: run this trough a general error handler.
$order['description_orig'] = $order['description'];
$order['description'] = drupal_substr($order['description'], 0, 32);
watchdog('ideal_api', t('iDEAL decription too long. Changed from %orig to %shortened', array('%orig' => $order['description_orig'], '%shortened' => $order['description'])));
}
//issuerid is min. 4 chars, add leading 0's
$order['issuer_id'] = str_pad($order['issuer_id'], 4, '0', STR_PAD_LEFT);
//Send TransactionRequest
$response = $iDEALConnector->RequestTransaction($order['issuer_id'], $order['order_id'], $order['amount'], $order['description'], $order['order_id'], $iDEALConnector->config['EXPIRATIONPERIOD'], $iDEALConnector->config['MERCHANTRETURNURL']);
if (!$response->errCode) {
return $response;
} else {
watchdog('ideal_api', $response->errCode . ': ' . $response->errMsg, NULL, WATCHDOG_ERROR);
return $response;
}
}
示例4: set_media_vars
function set_media_vars($node, $identifier = "") {
$title = $node->title;
if (drupal_strlen($identifier))
$link = "/ia/details/". $identifier;
else
$link = "/node/". $node->nid;
$mediaurl = $node->field_default_file[0]['value'];
if (!drupal_strlen($mediaurl)) { // get it from attachments
$cnt = 0;
foreach ($node->files as $file) {
$cnt++;
if (count($node->files) == 1)
$mediaurl = $file->filepath; // if only one file, use it
elseif (strpos($file->description, "/original/") !== FALSE) {
$mediaurl = $file->filepath; // found original tag
break;
}
elseif (strpos($filename, "_files.xml") || strpos($filename, "_meta.xml") )
$mediaurl = $file->filepath; // avoid _meta.xml and _files.xml files
elseif ($cnt == 1)
$mediaurl = $file->filepath; // always use the first file if no other hint
}
}
if ((strpos($mediaurl, "internetarchive/") !== FALSE) && (strpos($mediaurl, "http://") !== 0))
$mediaurl = str_replace("internetarchive/", "http://www.archive.org/download/", $mediaurl);
return array('mediaurl' => $mediaurl, 'title' => $title, 'link' => $link);
}
示例5: phptemplate_username
function phptemplate_username($object)
{
if ($object->uid && $object->name) {
// Shorten the name when it is too long or it will break many tables.
if (arg(0) == 'user' or 'groups') {
$name = $object->name;
} else {
if (drupal_strlen($object->name) > 20) {
$name = drupal_substr($object->name, 0, 15) . '...';
} else {
$name = $object->name;
}
}
if (user_access('access user profiles')) {
$output = l($name, 'user/' . $object->uid, array('title' => t('View user profile.')));
} else {
$output = check_plain($name);
}
} else {
if ($object->name) {
// Sometimes modules display content composed by people who are
// not registered members of the site (e.g. mailing list or news
// aggregator modules). This clause enables modules to display
// the true author of the content.
if ($object->homepage) {
$output = l($object->name, $object->homepage, array('class' => 'anonymous', 'title' => t('not verified')));
} else {
$output = '<span class="anonymous" title="' . t('not verified') . '">' . check_plain($object->name) . '</span>';
}
} else {
$output = variable_get('anonymous', t('Anonymous'));
}
}
return $output;
}
示例6: _membership_entity_token_clean_string
/**
* Apply advanced options to a generated member id string.
*/
function _membership_entity_token_clean_string($string, $settings)
{
// Remove all HTML tags from the string.
$return = strip_tags(decode_entities($string));
// Get rid of words that are on the ignore list
$ignore_words = $settings['ignore_words'];
$ignore_words_regex = preg_replace(array('/^[,\\s]+|[,\\s]+$/', '/[,\\s]+/'), array('', '\\b|\\b'), $ignore_words);
if ($ignore_words_regex) {
$ignore_words_regex = '/\\b' . $ignore_words_regex . '\\b/i';
$words_removed = preg_replace($ignore_words_regex, '', $return);
if (drupal_strlen(trim($words_removed)) > 0) {
$return = $words_removed;
}
}
// Replace whitespace with the separator.
$return = _membership_entity_token_clean_separator($return, $settings['separator']);
// Convert to lower or upper case.
if ($settings['case'] == 'lower') {
$return = drupal_strtolower($return);
} else {
if ($settings['case'] == 'upper') {
$return = drupal_strtoupper($return);
}
}
// Shorten to maxlength.
if (!empty($settings['maxlength'])) {
$return = truncate_utf8($return, $settings['maxlength']);
}
return $return;
}
示例7: createConsumer
/**
* @see LdapAuthorizationConsumerAbstract::createConsumer
*/
public function createConsumer($consumer_id, $consumer)
{
$roles_by_consumer_id = $this->existingRolesByRoleName();
$existing_role = isset($roles_by_consumer_id[$consumer_id]) ? $roles_by_consumer_id[$consumer_id] : FALSE;
if ($existing_role) {
return FALSE;
// role exists
} elseif (drupal_strlen($consumer_id) > 63) {
watchdog('ldap_authorization_drupal_role', 'Tried to create drupal role
with name of over 63 characters (%group_name). Please correct your
drupal ldap_authorization settings', array('%group_name' => $consumer_id));
return FALSE;
}
$new_role = new stdClass();
$new_role->name = empty($consumer['value']) ? $consumer_id : $consumer['value'];
if (!($status = user_role_save($new_role))) {
// if role is not created, remove from array to user object doesn't have it stored as granted
watchdog('user', 'failed to create drupal role %role in ldap_authorizations module', array('%role' => $new_role->name));
return FALSE;
} else {
$roles_by_consumer_id = $this->existingRolesByRoleName(TRUE);
// flush existingRolesByRoleName cache after creating new role
watchdog('user', 'created drupal role %role in ldap_authorizations module', array('%role' => $new_role->name));
}
return TRUE;
}
示例8: update
/**
* Updates a text
*
* @param int $nid ["path","0"]
* The nid of the text to update
* @param object $text ["data"]
* The text object
* @return object
*
* @Access(callback='DocuWalkTextResource::access', args={'update'}, appendArgs=true)
*/
public static function update($nid, $text)
{
$attr = array('body');
$node = node_load($nid);
// Transfer attributes from
foreach ($attr as $name) {
if (isset($text->{$name})) {
$node->{$name} = $text->{$name};
}
}
$text->title = drupal_substr($text->body, 0, min(drupal_strlen($text->body), 40));
node_save($node);
return (object) array('nid' => $node->nid, 'uri' => services_resource_uri(array('docuwalk-text', $node->nid)), 'url' => url('node/' . $node->nid, array('absolute' => TRUE)));
}
示例9: hook_server
/**
* Acts on requests to the server defined in hook_server_info().
*
* This is the main entry point to your server implementation.
* Need to get some more description about the best way to implement
* servers.
*/
function hook_server()
{
$endpoint_path = services_get_server_info('endpoint_path', 'services/rest');
$canonical_path = trim(drupal_substr($_GET['q'], drupal_strlen($endpoint_path)), '/');
$canonical_path = explode('/', $_GET['q']);
$endpoint_path_count = count(explode('/', $endpoint_path));
for ($x = 0; $x < $endpoint_path_count; $x++) {
array_shift($canonical_path);
}
$canonical_path = implode('/', $canonical_path);
if (empty($canonical_path)) {
return '';
}
//Handle server based on $canonical_path
}
示例10: testSearchSimplifyUnicode
/**
* Tests that all Unicode characters simplify correctly.
*/
function testSearchSimplifyUnicode()
{
// This test uses a file that was constructed so that the even lines are
// boundary characters, and the odd lines are valid word characters. (It
// was generated as a sequence of all the Unicode characters, and then the
// boundary chararacters (punctuation, spaces, etc.) were split off into
// their own lines). So the even-numbered lines should simplify to nothing,
// and the odd-numbered lines we need to split into shorter chunks and
// verify that simplification doesn't lose any characters.
$input = file_get_contents(DRUPAL_ROOT . '/core/modules/search/tests/UnicodeTest.txt');
$basestrings = explode(chr(10), $input);
$strings = array();
foreach ($basestrings as $key => $string) {
if ($key % 2) {
// Even line - should simplify down to a space.
$simplified = search_simplify($string);
$this->assertIdentical($simplified, ' ', "Line {$key} is excluded from the index");
} else {
// Odd line, should be word characters.
// Split this into 30-character chunks, so we don't run into limits
// of truncation in search_simplify().
$start = 0;
while ($start < drupal_strlen($string)) {
$newstr = drupal_substr($string, $start, 30);
// Special case: leading zeros are removed from numeric strings,
// and there's one string in this file that is numbers starting with
// zero, so prepend a 1 on that string.
if (preg_match('/^[0-9]+$/', $newstr)) {
$newstr = '1' . $newstr;
}
$strings[] = $newstr;
$start += 30;
}
}
}
foreach ($strings as $key => $string) {
$simplified = search_simplify($string);
$this->assertTrue(drupal_strlen($simplified) >= drupal_strlen($string), "Nothing is removed from string {$key}.");
}
// Test the low-numbered ASCII control characters separately. They are not
// in the text file because they are problematic for diff, especially \0.
$string = '';
for ($i = 0; $i < 32; $i++) {
$string .= chr($i);
}
$this->assertIdentical(' ', search_simplify($string), 'Search simplify works for ASCII control characters.');
}
示例11: list_build_row
/**
* Build a row based on the item.
*
* By default all of the rows are placed into a table by the render
* method, so this is building up a row suitable for theme('table').
* This doesn't have to be true if you override both.
*/
function list_build_row($item, &$form_state, $operations)
{
// Set up sorting
$name = $item->{$this->plugin['export']['key']};
$schema = ctools_export_get_schema($this->plugin['schema']);
// Load Custom Formatters engines.
$engines = module_invoke_all('custom_formatters_engine_info');
// Hide Formatters using missing engines.
if (!isset($engines[$item->mode])) {
unset($this->row);
return;
}
// Note: $item->{$schema['export']['export type string']} should have already been set up by export.inc so
// we can use it safely.
switch ($form_state['values']['order']) {
case 'disabled':
$this->sorts[$name] = empty($item->disabled) . $name;
break;
case 'title':
$this->sorts[$name] = $item->{$this->plugin['export']['admin_title']};
break;
case 'name':
$this->sorts[$name] = $name;
break;
case 'storage':
$this->sorts[$name] = $item->{$schema['export']['export type string']} . $name;
break;
}
$this->rows[$name]['data'] = array();
$this->rows[$name]['class'] = !empty($item->disabled) ? array('ctools-export-ui-disabled') : array('ctools-export-ui-enabled');
// If we have an admin title, make it the first row.
if (!empty($this->plugin['export']['admin_title'])) {
$this->rows[$name]['data'][] = array('data' => check_plain($item->{$this->plugin['export']['admin_title']}), 'class' => array('ctools-export-ui-title'));
}
$this->rows[$name]['data'][] = array('data' => check_plain($name), 'class' => array('ctools-export-ui-name'));
$this->rows[$name]['data'][] = array('data' => check_plain($engines[$item->mode]['label']), 'class' => array('ctools-export-ui-format'));
$this->rows[$name]['data'][] = array('data' => !empty($item->fapi) && drupal_strlen($item->fapi) > 17 ? t('Yes') : t('No'), 'class' => array('ctools-export-ui-fapi'));
$this->rows[$name]['data'][] = array('data' => check_plain($item->{$schema['export']['export type string']}), 'class' => array('ctools-export-ui-storage'));
$ops = theme('links__ctools_dropbutton', array('links' => $operations, 'attributes' => array('class' => array('links', 'inline'))));
$this->rows[$name]['data'][] = array('data' => $ops, 'class' => array('ctools-export-ui-operations'));
// Add an automatic mouseover of the description if one exists.
if (!empty($this->plugin['export']['admin_description'])) {
$this->rows[$name]['title'] = $item->{$this->plugin['export']['admin_description']};
}
}
示例12: validate
/**
* {@inheritdoc}
*/
public function validate($name, Constraint $constraint)
{
if (!$name) {
$this->context->addViolation($constraint->emptyMessage);
return;
}
if (substr($name, 0, 1) == ' ') {
$this->context->addViolation($constraint->spaceBeginMessage);
}
if (substr($name, -1) == ' ') {
$this->context->addViolation($constraint->spaceEndMessage);
}
if (strpos($name, ' ') !== FALSE) {
$this->context->addViolation($constraint->multipleSpacesMessage);
}
if (preg_match('/[^\\x{80}-\\x{F7} a-z0-9@_.\'-]/i', $name) || preg_match('/[\\x{80}-\\x{A0}' . '\\x{AD}' . '\\x{2000}-\\x{200F}' . '\\x{2028}-\\x{202F}' . '\\x{205F}-\\x{206F}' . '\\x{FEFF}' . '\\x{FF01}-\\x{FF60}' . '\\x{FFF9}-\\x{FFFD}' . '\\x{0}-\\x{1F}]/u', $name)) {
$this->context->addViolation($constraint->illegalMessage);
}
if (drupal_strlen($name) > USERNAME_MAX_LENGTH) {
$this->context->addViolation($constraint->tooLongMessage, array('%name' => $name, '%max' => USERNAME_MAX_LENGTH));
}
}
示例13: log
/**
* Log last request, if logging is enabled.
*
* @param ...
* A variable number of arguments, whose values will be redacted.
*/
private function log()
{
if ($this->logging) {
timer_stop('openruth_net');
if ($this->log_timestamp) {
$time = round(microtime(TRUE) - $this->log_timestamp, 2);
$this->log_timestamp = NULL;
}
$sensitive = func_get_args();
// For some reason PHP doesn't have array_flatten, and this is the
// shortest alternative.
$replace_values = array();
foreach (new RecursiveIteratorIterator(new RecursiveArrayIterator($sensitive)) as $value) {
$replace_values['>' . $value . '<'] = '>' . drupal_substr(md5($value . self::$salt), 0, drupal_strlen($value)) . '<';
}
if (isset($time)) {
watchdog('openruth', 'Sending request (@seconds sec): @xml', array('@xml' => strtr($this->client->__getLastRequest(), $replace_values), '@seconds' => $time), WATCHDOG_DEBUG);
} else {
watchdog('openruth', 'Sending request: @xml', array('@xml' => strtr($this->client->__getLastRequest(), $replace_values)), WATCHDOG_DEBUG);
}
watchdog('openruth', 'Response: @xml', array('@xml' => strtr($this->client->__getLastResponse(), $replace_values)), WATCHDOG_DEBUG);
}
}
示例14: ninesixtyrobots_username
function ninesixtyrobots_username($object)
{
if ($object->uid && $object->name && module_exists('profile')) {
profile_load_profile($object);
if (!empty($object->profile_real_name)) {
$object->name = $object->profile_real_name;
}
// Shorten the name when it is too long or it will break many tables.
if (drupal_strlen($object->name) > 20) {
$name = drupal_substr($object->name, 0, 15) . '...';
} else {
$name = $object->name;
}
if (user_access('access user profiles')) {
$output = l($name, 'user/' . $object->uid, array('attributes' => array('title' => t('View user profile.'))));
} else {
$output = check_plain($name);
}
} else {
if ($object->name) {
// Sometimes modules display content composed by people who are
// not registered members of the site (e.g. mailing list or news
// aggregator modules). This clause enables modules to display
// the true author of the content.
if (!empty($object->homepage)) {
$output = l($object->name, $object->homepage, array('attributes' => array('rel' => 'nofollow')));
} else {
$output = check_plain($object->name);
}
$output .= ' (' . t('not verified') . ')';
} else {
$output = variable_get('anonymous', t('Anonymous'));
}
}
return $output;
}
示例15: createConsumers
/**
* extends createConsumer method of base class
*
* creates of drupal roles may be mixed case. drupal doesn't
* differentiate, so case is ignored in comparing, but preserved
* for the actual created role name saved.
*
* **/
public function createConsumers($roles_to_create)
{
// 1. determins difference between existing drupal roles and ones that are requested to be created
$existing_roles_lower_case = array_keys($this->availableConsumerIDs());
$roles_to_create_lcase = array_unique(array_diff(array_keys($roles_to_create), $existing_roles_lower_case));
// 2. create each role that is needed
foreach ($roles_to_create_lcase as $i => $role_name_lowercase) {
$role_name = $roles_to_create[$role_name_lowercase];
if (drupal_strlen($role_name_lowercase) > 63) {
watchdog('ldap_authorization_drupal_role', 'Tried to create drupal role with name of over 63 characters (%group_name). Please correct your drupal ldap_authorization settings', array('%group_name' => $role_name_lowercase));
continue;
}
$role = new stdClass();
$role->name = $role_name;
if (!($status = user_role_save($role))) {
// if role is not created, remove from array to user object doesn't have it stored as granted
watchdog('user', 'failed to create drupal role %role in ldap_authorizations module', array('%role' => $role->name));
} else {
$created[] = $role->name;
watchdog('user', 'created drupal role %role in ldap_authorizations module', array('%role' => $role->name));
}
}
// 3. return all existing user roles and flush cache of consumer ids.
$refreshed_available_consumer_ids = $this->availableConsumerIDs(TRUE);
if ($this->detailedWatchdogLog) {
$watchdog_tokens = array('%roles_to_create' => join(", ", $roles_to_create_lcase));
$watchdog_tokens = array('%existing_roles' => join(", ", $existing_roles_lower_case));
$watchdog_tokens = array('%refreshed_available_consumer_ids' => join(", ", array_keys($refreshed_available_consumer_ids)));
watchdog('ldap_authorization', 'LdapAuthorizationConsumerDrupalRole.createConsumers()
roles to create: %roles_to_create;
existing roles: %existing_roles;
available roles after createConsumers call: %refreshed_available_consumer_ids;', $watchdog_tokens, WATCHDOG_DEBUG);
}
return $refreshed_available_consumer_ids;
// return actual roles that exist, in case of failure
}