本文整理汇总了PHP中drupal_substr函数的典型用法代码示例。如果您正苦于以下问题:PHP drupal_substr函数的具体用法?PHP drupal_substr怎么用?PHP drupal_substr使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了drupal_substr函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: authenticate
public function authenticate(&$message, $mailbox)
{
// Check and parse messageid for parameters. URL will be encoded.
$force_user_lookup = FALSE;
$identifier = _mailcomment_get_signature(rawurldecode($message['body_html']));
// Failed to find signature in body -- replicate mailhandler functionality to find node->threading
if (!$identifier) {
if (!empty($message['header']->references)) {
// we want the final element in references header, watching out for white space
$identifier = drupal_substr(strrchr($message['header']->references, '<'), 0);
} elseif (!empty($message['header']->in_reply_to)) {
// Some MUAs send more info in this header.
$identifier = str_replace(strstr($message['header']->in_reply_to, '>'), '>', $message['header']->in_reply_to);
}
if (isset($identifier)) {
$identifier = rtrim(ltrim($identifier, '<'), '>');
$force_user_lookup = TRUE;
}
}
$params = mailcomment_check_messageparams($identifier);
if ($force_user_lookup) {
// get uid from email address because we are using the header information to load the params
// these contain the uid of the person who's post you are responding to
$sender = $message['header']->from[0]->mailbox . '@' . $message['header']->from[0]->host;
$params['uid'] = user_load(array('mail' => $sender))->uid;
}
if ($params['uid']) {
$account = user_load($params['uid']);
$message['authenticated_uid'] = $account->uid;
} else {
$message['authenticated_uid'] = 0;
}
}
示例2: 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;
}
}
示例3: 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;
}
示例4: 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']);
}
示例5: 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;
}
示例6: ourmedia3_user_login_block
/**
* Theme override for user edit form.
*
* The function is named themename_formid.
*
* function Ourmedia3_user_profile_form($form) {
*/
function ourmedia3_user_login_block($form) {
$output = '';
// Print out the $form array to see all the elements we are working with.
//$output .= dsm($form);
// Once I know which part of the array I'm after we can change it.
// Make sure you call a drupal_render() on the entire $form to make sure you
// still output all of the elements (particularly hidden ones needed
// for the form to function properly.)
// print_r($form);
$output .= drupal_render($form);
$pos_form_id_start = strpos($output, "name=\"form_build_id\" id=\"form-") + 25;
$pos_form_id_end = strpos($output, "\"", $pos_form_id_start);
$pos_form_id = drupal_substr($output, $pos_form_id_start, $pos_form_id_end - $pos_form_id_start);
$output = "<div id=\"signInDivider\">";
$output .= "<input type=\"text\" maxlength=\"60\" name=\"name\" id=\"edit-name\" size=\"15\" value=\"\" tabindex=\"1\" class=\"form-text required signIn\" />\n";
$output .= "<input type=\"password\" name=\"pass\" id=\"edit-pass\" maxlength=\"60\" size=\"15\" tabindex=\"2\" class=\"form-text required signIn\" />\n";
$output .= "<input type=\"submit\" name=\"op\" id=\"edit-submit\" value=\"Log in\" tabindex=\"3\" class=\"form-submit button signIn\" />";
$output .= "</div>";
$output .= "<div id=\"register\"><a href=\"/user/register\"><input type=\"button\" name=\"\" value=\"Register\" class=\"button\"></a></div>";
$output .= "<input type=\"hidden\" name=\"form_build_id\" id=\"$pos_form_id\" value=\"$pos_form_id\" />";
$output .= "<input type=\"hidden\" name=\"form_id\" id=\"edit-user-login-block\" value=\"user_login_block\" />";
return $output;
}
示例7: parseHeader
/**
* Parse header.
*
* @param type $content
* @return type
*/
function parseHeader($content)
{
$info = curl_getinfo($this->curlHandle);
$header = drupal_substr($content, 0, $info['header_size']);
$header = str_replace("HTTP/1.1 100 Continue\r\n\r\n", '', $header);
$status = strtok($header, "\r\n");
$code = $info['http_code'];
$body = unserialize(drupal_substr($content, $info['header_size'], drupal_strlen($content) - $info['header_size']));
return array($info, $header, $status, $code, $body);
}
示例8: __construct
/**
* Constructs a ChecklistapiChecklist object.
*
* @param array $definition
* A checklist definition, as returned by checklistapi_get_checklist_info().
*/
public function __construct(array $definition)
{
foreach (element_children($definition) as $group_key) {
$this->totalItems += count(element_children($definition[$group_key]));
$this->items[$group_key] = $definition[$group_key];
unset($definition[$group_key]);
}
foreach ($definition as $property_key => $value) {
$property_name = checklistapi_strtolowercamel(drupal_substr($property_key, 1));
$this->{$property_name} = $value;
}
$this->savedProgress = variable_get($this->getSavedProgressVariableName(), array());
}
示例9: 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)));
}
示例10: 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
}
示例11: filterBody
/**
* Filter the body field to remove previous reply.
*
* We use code in mailcomment and then add additional filters of our own.
*
* @param $text
* @return string
*/
protected function filterBody($text, $html = FALSE)
{
if ($html) {
$text = preg_replace('/<!--(.|\\s)*?-->/s', '', $text);
}
$delimiters = array("<blockquote.+?cite=.+?>.+?<\\/blockquote>");
// NOTE the "s" option to allow . to include newlines
$expression = '/(' . implode('|', $delimiters) . ')/s';
if (preg_match($expression, $text, $matches, PREG_OFFSET_CAPTURE)) {
$text = trim(drupal_substr($text, 0, $matches[0][1]));
} else {
// If we didn't process it, then let mailcomment do it.
$text = _mailcomment_filter_aggressive($text);
}
return $text;
}
示例12: process
/**
* Parse and process commands.
*/
function process(&$message, $source)
{
if (!empty($this->commands)) {
foreach ($this->commands as $key => $value) {
if (drupal_substr($value, 0, 1) == '[' && drupal_substr($value, -1, 1) == ']') {
// Strip brackets.
$value = rtrim(ltrim($value, '['), ']');
$value = explode(',', $value);
}
$key = drupal_strtolower(str_replace(' ', '_', $key));
if (!empty($key)) {
$message[$key] = $value;
}
}
}
}
示例13: 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.');
}
示例14: testUserAutocomplete
/**
* Tests access to user autocompletion and verify the correct results.
*/
function testUserAutocomplete()
{
// Check access from unprivileged user, should be denied.
$this->drupalLogin($this->unprivileged_user);
$username = $this->unprivileged_user->getUsername();
$this->drupalGet('user/autocomplete', array('query' => array('q' => $username[0])));
$this->assertResponse(403, 'Autocompletion access denied to user without permission.');
// Check access from privileged user.
$this->drupalLogout();
$this->drupalLogin($this->privileged_user);
$this->drupalGet('user/autocomplete', array('query' => array('q' => $username[0])));
$this->assertResponse(200, 'Autocompletion access allowed.');
// Using first letter of the user's name, make sure the user's full name is in the results.
$this->assertRaw($this->unprivileged_user->getUsername(), 'User name found in autocompletion results.');
$anonymous_name = $this->randomString() . '<script>alert();</script>';
\Drupal::config('user.settings')->set('anonymous', $anonymous_name)->save();
// Test that anonymous username is in the result when requested and escaped
// with \Drupal\Component\Utility\String::checkPlain().
$users = $this->drupalGetJSON('user/autocomplete/anonymous', array('query' => array('q' => drupal_substr($anonymous_name, 0, 4))));
$this->assertEqual(String::checkPlain($anonymous_name), $users[0]['label'], 'The anonymous name found in autocompletion results.');
$users = $this->drupalGetJSON('user/autocomplete', array('query' => array('q' => drupal_substr($anonymous_name, 0, 4))));
$this->assertTrue(empty($users), 'The anonymous name not found in autocompletion results without enabling anonymous username.');
}
示例15: 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);
}
}