Exemplo n.º 1
0
 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;
     }
 }
/**
 * 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;
    }
}
Exemplo n.º 3
0
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;
}
/**
 * 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']);
}
Exemplo n.º 5
0
/**
 * 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;
}
Exemplo n.º 6
0
/**
 * 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;
}
Exemplo n.º 7
0
 /**
  * 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);
 }
 /**
  * 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());
 }
 /**
  * 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)));
 }
Exemplo n.º 10
0
/**
 * 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
}
 /**
  * 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;
 }
 /**
  * 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;
             }
         }
     }
 }
 /**
  * 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.');
 }
Exemplo n.º 14
0
 /**
  * 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.');
 }
Exemplo n.º 15
0
 /**
  * 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);
     }
 }
Exemplo n.º 16
0
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;
}
Exemplo n.º 17
0
/**
 * Override of theme_username().
 */
function tao_username($object)
{
    if (!empty($object->name)) {
        // Shorten the name when it is too long or it will break many tables.
        $name = drupal_strlen($object->name) > 20 ? drupal_substr($object->name, 0, 15) . '...' : $object->name;
        $name = check_plain($name);
        // Default case -- we have a real Drupal user here.
        if ($object->uid && user_access('access user profiles')) {
            return l($name, 'user/' . $object->uid, array('attributes' => array('class' => 'username', 'title' => t('View user profile.'))));
        } else {
            if (!empty($object->homepage)) {
                return l($name, $object->homepage, array('attributes' => array('class' => 'username', 'rel' => 'nofollow')));
            } else {
                return "<span class='username'>{$name}</span>";
            }
        }
    }
    return "<span class='username'>" . variable_get('anonymous', t('Anonymous')) . "</span>";
}
function shib_auth_isDebug()
{
    return variable_get('shib_auth_debug_state', FALSE) && drupal_substr($_GET['q'], 0, drupal_strlen(variable_get('shib_auth_debug_url', ''))) == variable_get('shib_auth_debug_url', '');
}
Exemplo n.º 19
0
 /**
  * Helper function to return a sanitized node title.
  */
 private static function get_node_title($node, $clip_and_decorate = FALSE)
 {
     if (isset($node)) {
         $nid = $node->id();
         if ($node_title = $node->title->value) {
             $node_title = SafeMarkup::checkPlain($node_title);
             if ($clip_and_decorate) {
                 if (drupal_strlen($node_title) > 20) {
                     $node_title = "<span title='node/{$nid}: {$node_title}'>" . drupal_substr($node_title, 0, 15) . '...</span>';
                 }
                 $node_title = '<span title="node/' . $nid . '">' . $node_title . '</span>';
             }
             return $node_title;
         } elseif ($nid) {
             return $nid;
         }
     }
     return '&mdash;';
 }
Exemplo n.º 20
0
 /**
  * Generates and then verifies some user events.
  */
 private function doUser()
 {
     // Set user variables.
     $name = $this->randomMachineName();
     $pass = user_password();
     // Add a user using the form to generate an add user event (which is not
     // triggered by drupalCreateUser).
     $edit = array();
     $edit['name'] = $name;
     $edit['mail'] = $name . '@example.com';
     $edit['pass[pass1]'] = $pass;
     $edit['pass[pass2]'] = $pass;
     $edit['status'] = 1;
     $this->drupalPostForm('admin/people/create', $edit, t('Create new account'));
     $this->assertResponse(200);
     // Retrieve the user object.
     $user = user_load_by_name($name);
     $this->assertTrue($user != NULL, format_string('User @name was loaded', array('@name' => $name)));
     // pass_raw property is needed by drupalLogin.
     $user->pass_raw = $pass;
     // Login user.
     $this->drupalLogin($user);
     // Logout user.
     $this->drupalLogout();
     // Fetch the row IDs in watchdog that relate to the user.
     $result = db_query('SELECT wid FROM {watchdog} WHERE uid = :uid', array(':uid' => $user->id()));
     foreach ($result as $row) {
         $ids[] = $row->wid;
     }
     $count_before = isset($ids) ? count($ids) : 0;
     $this->assertTrue($count_before > 0, format_string('DBLog contains @count records for @name', array('@count' => $count_before, '@name' => $user->getUsername())));
     // Login the admin user.
     $this->drupalLogin($this->big_user);
     // Delete the user created at the start of this test.
     // We need to POST here to invoke batch_process() in the internal browser.
     $this->drupalPostForm('user/' . $user->id() . '/cancel', array('user_cancel_method' => 'user_cancel_reassign'), t('Cancel account'));
     // View the database log report.
     $this->drupalGet('admin/reports/dblog');
     $this->assertResponse(200);
     // Verify that the expected events were recorded.
     // Add user.
     // Default display includes name and email address; if too long, the email
     // address is replaced by three periods.
     $this->assertLogMessage(t('New user: %name %email.', array('%name' => $name, '%email' => '<' . $user->getEmail() . '>')), 'DBLog event was recorded: [add user]');
     // Login user.
     $this->assertLogMessage(t('Session opened for %name.', array('%name' => $name)), 'DBLog event was recorded: [login user]');
     // Logout user.
     $this->assertLogMessage(t('Session closed for %name.', array('%name' => $name)), 'DBLog event was recorded: [logout user]');
     // Delete user.
     $message = t('Deleted user: %name %email.', array('%name' => $name, '%email' => '<' . $user->getEmail() . '>'));
     $message_text = truncate_utf8(Xss::filter($message, array()), 56, TRUE, TRUE);
     // Verify that the full message displays on the details page.
     $link = FALSE;
     if ($links = $this->xpath('//a[text()="' . html_entity_decode($message_text) . '"]')) {
         // Found link with the message text.
         $links = array_shift($links);
         foreach ($links->attributes() as $attr => $value) {
             if ($attr == 'href') {
                 // Extract link to details page.
                 $link = drupal_substr($value, strpos($value, 'admin/reports/dblog/event/'));
                 $this->drupalGet($link);
                 // Check for full message text on the details page.
                 $this->assertRaw($message, 'DBLog event details was found: [delete user]');
                 break;
             }
         }
     }
     $this->assertTrue($link, 'DBLog event was recorded: [delete user]');
     // Visit random URL (to generate page not found event).
     $not_found_url = $this->randomMachineName(60);
     $this->drupalGet($not_found_url);
     $this->assertResponse(404);
     // View the database log page-not-found report page.
     $this->drupalGet('admin/reports/page-not-found');
     $this->assertResponse(200);
     // Check that full-length URL displayed.
     $this->assertText($not_found_url, 'DBLog event was recorded: [page not found]');
 }
Exemplo n.º 21
0
/**
 *
 * @param $value
 * @param int $length
 * @param bool $elipse
 * @param bool $words
 * @return string
 */
function tfd_truncate_text($value, $length = 300, $elipse = TRUE, $words = TRUE)
{
    $value = tfd_render($value);
    if (drupal_strlen($value) > $length) {
        $value = drupal_substr($value, 0, $length);
        if ($words) {
            $regex = "(.*)\\b.+";
            if (function_exists('mb_ereg')) {
                mb_regex_encoding('UTF-8');
                $found = mb_ereg($regex, $value, $matches);
            } else {
                $found = preg_match("/{$regex}/us", $value, $matches);
            }
            if ($found) {
                $value = $matches[1];
            }
        }
        // Remove scraps of HTML entities from the end of a strings
        $value = rtrim(preg_replace('/(?:<(?!.+>)|&(?!.+;)).*$/us', '', $value));
        if ($elipse) {
            $value .= ' ' . t('...');
        }
    }
    return $value;
}
Exemplo n.º 22
0
 /**
  * Provide the default summary for options in the views UI.
  *
  * This output is returned as an array.
  */
 public function optionsSummary(&$categories, &$options)
 {
     $categories = array('title' => array('title' => t('Title'), 'column' => 'first'), 'format' => array('title' => t('Format'), 'column' => 'first'), 'filters' => array('title' => t('Filters'), 'column' => 'first'), 'fields' => array('title' => t('Fields'), 'column' => 'first'), 'pager' => array('title' => t('Pager'), 'column' => 'second'), 'exposed' => array('title' => t('Exposed form'), 'column' => 'third', 'build' => array('#weight' => 1)), 'access' => array('title' => '', 'column' => 'second', 'build' => array('#weight' => -5)), 'other' => array('title' => t('Other'), 'column' => 'third', 'build' => array('#weight' => 2)));
     if ($this->display['id'] != 'default') {
         $options['display_id'] = array('category' => 'other', 'title' => t('Machine Name'), 'value' => !empty($this->display['new_id']) ? String::checkPlain($this->display['new_id']) : String::checkPlain($this->display['id']), 'desc' => t('Change the machine name of this display.'));
     }
     $display_comment = String::checkPlain(drupal_substr($this->getOption('display_comment'), 0, 10));
     $options['display_comment'] = array('category' => 'other', 'title' => t('Administrative comment'), 'value' => !empty($display_comment) ? $display_comment : t('None'), 'desc' => t('Comment or document this display.'));
     $title = strip_tags($this->getOption('title'));
     if (!$title) {
         $title = t('None');
     }
     $options['title'] = array('category' => 'title', 'title' => t('Title'), 'value' => views_ui_truncate($title, 32), 'desc' => t('Change the title that this display will use.'));
     $style_plugin_instance = $this->getPlugin('style');
     $style_summary = empty($style_plugin_instance->definition['title']) ? t('Missing style plugin') : $style_plugin_instance->summaryTitle();
     $style_title = empty($style_plugin_instance->definition['title']) ? t('Missing style plugin') : $style_plugin_instance->pluginTitle();
     $options['style'] = array('category' => 'format', 'title' => t('Format'), 'value' => $style_title, 'setting' => $style_summary, 'desc' => t('Change the way content is formatted.'));
     // This adds a 'Settings' link to the style_options setting if the style has options.
     if ($style_plugin_instance->usesOptions()) {
         $options['style']['links']['style_options'] = t('Change settings for this format');
     }
     if ($style_plugin_instance->usesRowPlugin()) {
         $row_plugin_instance = $this->getPlugin('row');
         $row_summary = empty($row_plugin_instance->definition['title']) ? t('Missing row plugin') : $row_plugin_instance->summaryTitle();
         $row_title = empty($row_plugin_instance->definition['title']) ? t('Missing row plugin') : $row_plugin_instance->pluginTitle();
         $options['row'] = array('category' => 'format', 'title' => t('Show'), 'value' => $row_title, 'setting' => $row_summary, 'desc' => t('Change the way each row in the view is styled.'));
         // This adds a 'Settings' link to the row_options setting if the row style has options.
         if ($row_plugin_instance->usesOptions()) {
             $options['row']['links']['row_options'] = t('Change settings for this style');
         }
     }
     if ($this->usesAJAX()) {
         $options['use_ajax'] = array('category' => 'other', 'title' => t('Use AJAX'), 'value' => $this->getOption('use_ajax') ? t('Yes') : t('No'), 'desc' => t('Change whether or not this display will use AJAX.'));
     }
     if ($this->usesAttachments()) {
         $options['hide_attachment_summary'] = array('category' => 'other', 'title' => t('Hide attachments in summary'), 'value' => $this->getOption('hide_attachment_summary') ? t('Yes') : t('No'), 'desc' => t('Change whether or not to display attachments when displaying a contextual filter summary.'));
     }
     if (!isset($this->definition['contextual links locations']) || !empty($this->definition['contextual links locations'])) {
         $options['show_admin_links'] = array('category' => 'other', 'title' => t('Contextual links'), 'value' => $this->getOption('show_admin_links') ? t('Shown') : t('Hidden'), 'desc' => t('Change whether or not to display contextual links for this view.'));
     }
     $pager_plugin = $this->getPlugin('pager');
     if (!$pager_plugin) {
         // default to the no pager plugin.
         $pager_plugin = Views::pluginManager('pager')->createInstance('none');
     }
     $pager_str = $pager_plugin->summaryTitle();
     $options['pager'] = array('category' => 'pager', 'title' => t('Use pager'), 'value' => $pager_plugin->pluginTitle(), 'setting' => $pager_str, 'desc' => t("Change this display's pager setting."));
     // If pagers aren't allowed, change the text of the item:
     if (!$this->usesPager()) {
         $options['pager']['title'] = t('Items to display');
     }
     if ($pager_plugin->usesOptions()) {
         $options['pager']['links']['pager_options'] = t('Change settings for this pager type.');
     }
     if ($this->usesMore()) {
         $options['use_more'] = array('category' => 'pager', 'title' => t('More link'), 'value' => $this->getOption('use_more') ? t('Yes') : t('No'), 'desc' => t('Specify whether this display will provide a "more" link.'));
     }
     $this->view->initQuery();
     if ($this->view->query->getAggregationInfo()) {
         $options['group_by'] = array('category' => 'other', 'title' => t('Use aggregation'), 'value' => $this->getOption('group_by') ? t('Yes') : t('No'), 'desc' => t('Allow grouping and aggregation (calculation) of fields.'));
     }
     $options['query'] = array('category' => 'other', 'title' => t('Query settings'), 'value' => t('Settings'), 'desc' => t('Allow to set some advanced settings for the query plugin'));
     $languages = array('***CURRENT_LANGUAGE***' => t("Current user's language"), '***DEFAULT_LANGUAGE***' => t("Default site language"), LanguageInterface::LANGCODE_NOT_SPECIFIED => t('Language neutral'));
     if (\Drupal::moduleHandler()->moduleExists('language')) {
         $languages = array_merge($languages, language_list());
     }
     $options['field_langcode'] = array('category' => 'other', 'title' => t('Field Language'), 'value' => $languages[$this->getOption('field_langcode')], 'desc' => t('All fields which support translations will be displayed in the selected language.'));
     $access_plugin = $this->getPlugin('access');
     if (!$access_plugin) {
         // default to the no access control plugin.
         $access_plugin = Views::pluginManager('access')->createInstance('none');
     }
     $access_str = $access_plugin->summaryTitle();
     $options['access'] = array('category' => 'access', 'title' => t('Access'), 'value' => $access_plugin->pluginTitle(), 'setting' => $access_str, 'desc' => t('Specify access control type for this display.'));
     if ($access_plugin->usesOptions()) {
         $options['access']['links']['access_options'] = t('Change settings for this access type.');
     }
     $cache_plugin = $this->getPlugin('cache');
     if (!$cache_plugin) {
         // default to the no cache control plugin.
         $cache_plugin = Views::pluginManager('cache')->createInstance('none');
     }
     $cache_str = $cache_plugin->summaryTitle();
     $options['cache'] = array('category' => 'other', 'title' => t('Caching'), 'value' => $cache_plugin->pluginTitle(), 'setting' => $cache_str, 'desc' => t('Specify caching type for this display.'));
     if ($cache_plugin->usesOptions()) {
         $options['cache']['links']['cache_options'] = t('Change settings for this caching type.');
     }
     if ($access_plugin->usesOptions()) {
         $options['access']['links']['access_options'] = t('Change settings for this access type.');
     }
     if ($this->usesLinkDisplay()) {
         $link_display_option = $this->getOption('link_display');
         $link_display = $this->t('None');
         if ($link_display_option == 'custom_url') {
             $link_display = $this->t('Custom URL');
         } elseif (!empty($link_display_option)) {
             $display_id = $this->getLinkDisplay();
             $displays = $this->view->storage->get('display');
             if (!empty($displays[$display_id])) {
                 $link_display = String::checkPlain($displays[$display_id]['display_title']);
             }
         }
         $options['link_display'] = array('category' => 'pager', 'title' => t('Link display'), 'value' => $link_display, 'desc' => t('Specify which display or custom url this display will link to.'));
     }
     if ($this->usesExposedFormInBlock()) {
         $options['exposed_block'] = array('category' => 'exposed', 'title' => t('Exposed form in block'), 'value' => $this->getOption('exposed_block') ? t('Yes') : t('No'), 'desc' => t('Allow the exposed form to appear in a block instead of the view.'));
     }
     $exposed_form_plugin = $this->getPlugin('exposed_form');
     if (!$exposed_form_plugin) {
         // default to the no cache control plugin.
         $exposed_form_plugin = Views::pluginManager('exposed_form')->createInstance('basic');
     }
     $exposed_form_str = $exposed_form_plugin->summaryTitle();
     $options['exposed_form'] = array('category' => 'exposed', 'title' => t('Exposed form style'), 'value' => $exposed_form_plugin->pluginTitle(), 'setting' => $exposed_form_str, 'desc' => t('Select the kind of exposed filter to use.'));
     if ($exposed_form_plugin->usesOptions()) {
         $options['exposed_form']['links']['exposed_form_options'] = t('Exposed form settings for this exposed form style.');
     }
     $css_class = String::checkPlain(trim($this->getOption('css_class')));
     if (!$css_class) {
         $css_class = t('None');
     }
     $options['css_class'] = array('category' => 'other', 'title' => t('CSS class'), 'value' => $css_class, 'desc' => t('Change the CSS class name(s) that will be added to this display.'));
     foreach ($this->extender as $extender) {
         $extender->optionsSummary($categories, $options);
     }
 }
Exemplo n.º 23
0
 /**
  * Test taxonomy_term_load_multiple_by_name().
  */
 function testTaxonomyGetTermByName()
 {
     $term = $this->createTerm($this->vocabulary);
     // Load the term with the exact name.
     $terms = taxonomy_term_load_multiple_by_name($term->getName());
     $this->assertTrue(isset($terms[$term->id()]), 'Term loaded using exact name.');
     // Load the term with space concatenated.
     $terms = taxonomy_term_load_multiple_by_name('  ' . $term->getName() . '   ');
     $this->assertTrue(isset($terms[$term->id()]), 'Term loaded with extra whitespace.');
     // Load the term with name uppercased.
     $terms = taxonomy_term_load_multiple_by_name(strtoupper($term->getName()));
     $this->assertTrue(isset($terms[$term->id()]), 'Term loaded with uppercased name.');
     // Load the term with name lowercased.
     $terms = taxonomy_term_load_multiple_by_name(strtolower($term->getName()));
     $this->assertTrue(isset($terms[$term->id()]), 'Term loaded with lowercased name.');
     // Try to load an invalid term name.
     $terms = taxonomy_term_load_multiple_by_name('Banana');
     $this->assertFalse($terms, 'No term loaded with an invalid name.');
     // Try to load the term using a substring of the name.
     $terms = taxonomy_term_load_multiple_by_name(drupal_substr($term->getName(), 2), 'No term loaded with a substring of the name.');
     $this->assertFalse($terms);
     // Create a new term in a different vocabulary with the same name.
     $new_vocabulary = $this->createVocabulary();
     $new_term = entity_create('taxonomy_term', array('name' => $term->getName(), 'vid' => $new_vocabulary->id()));
     $new_term->save();
     // Load multiple terms with the same name.
     $terms = taxonomy_term_load_multiple_by_name($term->getName());
     $this->assertEqual(count($terms), 2, 'Two terms loaded with the same name.');
     // Load single term when restricted to one vocabulary.
     $terms = taxonomy_term_load_multiple_by_name($term->getName(), $this->vocabulary->id());
     $this->assertEqual(count($terms), 1, 'One term loaded when restricted by vocabulary.');
     $this->assertTrue(isset($terms[$term->id()]), 'Term loaded using exact name and vocabulary machine name.');
     // Create a new term with another name.
     $term2 = $this->createTerm($this->vocabulary);
     // Try to load a term by name that doesn't exist in this vocabulary but
     // exists in another vocabulary.
     $terms = taxonomy_term_load_multiple_by_name($term2->getName(), $new_vocabulary->id());
     $this->assertFalse($terms, 'Invalid term name restricted by vocabulary machine name not loaded.');
     // Try to load terms filtering by a non-existing vocabulary.
     $terms = taxonomy_term_load_multiple_by_name($term2->getName(), 'non_existing_vocabulary');
     $this->assertEqual(count($terms), 0, 'No terms loaded when restricted by a non-existing vocabulary.');
 }
Exemplo n.º 24
0
 protected function parseDrupalSettings($html)
 {
     $startToken = 'drupalSettings = ';
     $endToken = '}';
     $start = strpos($html, $startToken) + strlen($startToken);
     $end = strrpos($html, $endToken);
     $json = drupal_substr($html, $start, $end - $start + 1);
     $parsed_settings = Json::decode($json);
     return $parsed_settings;
 }
Exemplo n.º 25
0
/**
 * Override the username theme function so that it returns a display name
 * rather than the unique Drupal auth name
 */
function phptemplate_username($object)
{
    if ($object->uid && $object->name) {
        // Show the profile name in general, not the username
        $name = user_load($object->uid)->boincuser_name;
        // Shorten the name when it is too long or it will break many tables.
        if (drupal_strlen($name) > 20) {
            $name = drupal_substr($name, 0, 15) . '...';
        }
        if (user_access('access user profiles')) {
            $output = l($name, 'account/' . $object->uid, array('attributes' => array('title' => bts('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 .= ' (' . bts('not verified') . ')';
        } else {
            $output = check_plain(variable_get('anonymous', bts('Anonymous')));
        }
    }
    return $output;
}
Exemplo n.º 26
0
 /**
  * Loads the configuration object from the DataStore.
  *
  * @param $file_content
  *   Optional. The content to load directly.
  * @param $source
  *   Optional. An optional path to load the configuration.
  */
 public function load($file_content = NULL, $source = NULL)
 {
     if (empty($this->loaded)) {
         $this->loaded = TRUE;
         if (empty($file_content)) {
             $dir = $source ? $source : ConfigurationManagement::getStream();
             if (!file_exists($dir . '/' . $this->filename)) {
                 $this->data = NULL;
             } else {
                 $file_content = drupal_substr(file_get_contents($dir . '/' . $this->filename), 6);
             }
         }
         if (!empty($file_content)) {
             $this->import($file_content);
         }
     }
     return $this;
 }
 /**
  * Fetch UID for a message in a POP mailbox.
  *
  * Taken from PHP.net.
  */
 function fetch_uid($mailbox, $msg_number)
 {
     extract($mailbox->settings);
     $retval = 0;
     $fp = fsockopen($domain, $port);
     if ($fp > 0) {
         $buf = fgets($fp, 1024);
         fwrite($fp, "USER {$name}\r\n");
         $buf = fgets($fp, 1024);
         fwrite($fp, "PASS {$pass}\r\n");
         $buf = fgets($fp, 1024);
         fwrite($fp, "UIDL {$msg_number}\r\n");
         $retval = fgets($fp, 1024);
         fwrite($fp, "QUIT\r\n");
         $buf = fgets($fp, 1024);
         fclose($fp);
     }
     return drupal_substr($retval, 6, 30);
 }
Exemplo n.º 28
0
    $blogObject['blog_content'] = preg_replace('/\\012/', '<br/>', linkifyYouTubeURLs($blogObject['blog_content']));
    $blogObject['blog_content'] = replace_hyperlink($blogObject['blog_content']);
}
?>

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<title><?php 
echo isset($blogObject['blog_title']) && $blogObject['blog_title'] != '' ? $blogObject['blog_title'] : drupal_substr(str_replace('"', '\\"', preg_replace('/^.+:/', '', $clean_cotent)), 0, 45);
?>
</title>
<meta name="description" content="<?php 
echo drupal_substr(str_replace('"', '\\"', $clean_cotent), 0, 200);
?>
"/>
<script src="<?php 
echo $domain_name;
?>
jquery/jquery-1.11.0.min.js" type="text/javascript"></script>
<link href="<?php 
echo $domain_name;
?>
json-plugs/css/ios_main.css" rel="stylesheet" type="text/css" />
<link rel="stylesheet" href="<?php 
echo $domain_name;
?>
fancybox/source/jquery.fancybox.css" type="text/css" media="screen"/>
<script type="text/javascript" src="<?php 
Exemplo n.º 29
0
 /**
  * Trims the field down to the specified length.
  *
  * @param array $alter
  *   The alter array of options to use.
  *     - max_length: Maximum length of the string, the rest gets truncated.
  *     - word_boundary: Trim only on a word boundary.
  *     - ellipsis: Show an ellipsis (…) at the end of the trimmed string.
  *     - html: Make sure that the html is correct.
  *
  * @param string $value
  *   The string which should be trimmed.
  *
  * @return string
  *   The trimmed string.
  */
 public static function trimText($alter, $value)
 {
     if (drupal_strlen($value) > $alter['max_length']) {
         $value = drupal_substr($value, 0, $alter['max_length']);
         if (!empty($alter['word_boundary'])) {
             $regex = "(.*)\\b.+";
             if (function_exists('mb_ereg')) {
                 mb_regex_encoding('UTF-8');
                 $found = mb_ereg($regex, $value, $matches);
             } else {
                 $found = preg_match("/{$regex}/us", $value, $matches);
             }
             if ($found) {
                 $value = $matches[1];
             }
         }
         // Remove scraps of HTML entities from the end of a strings
         $value = rtrim(preg_replace('/(?:<(?!.+>)|&(?!.+;)).*$/us', '', $value));
         if (!empty($alter['ellipsis'])) {
             $value .= t('…');
         }
     }
     if (!empty($alter['html'])) {
         $value = Html::normalize($value);
     }
     return $value;
 }
Exemplo n.º 30
0
 /**
  * Merge chunk segments between tag delimiters.
  */
 function process_chunk($chunk)
 {
     $processed = array();
     $j = 0;
     foreach ($chunk as $i => $piece) {
         $next = isset($chunk[$i + 1]) ? $chunk[$i + 1] : NULL;
         if (!isset($processed[$j])) {
             $processed[$j] = '';
         }
         if (strpos($piece, '<') === 0 && drupal_substr($piece, drupal_strlen($piece) - 1) === '>') {
             $processed[$j] = $piece;
             $j++;
         } elseif (isset($next) && strpos($next, '<') === 0 && drupal_substr($next, drupal_strlen($next) - 1) === '>') {
             $processed[$j] .= $piece;
             $j++;
         } else {
             $processed[$j] .= $piece;
         }
     }
     return $processed;
 }