You are here

function _tweet_process in Tweet 5.2

Same name and namespace in other branches
  1. 6.4 tweet.module \_tweet_process()
  2. 6.2 tweet.module \_tweet_process()
  3. 6.3 tweet.module \_tweet_process()
  4. 7.4 tweet.module \_tweet_process()

Determines what will be in the tweet itself.

Parameters

$format: A string containing the text of the tweet before it gets processed.

$tokens: An associative array where keys represent text that will be replaced by their value in $format.

Return value

The URL-ready tweet text.

See also

_tweet_to_twitter()

1 call to _tweet_process()
_tweet_to_twitter in ./tweet.module
Creates a link to post a URL and optionally title to twitter. Uses the current page by default.

File

./tweet.module, line 148
Builds links to post pages to twitter.

Code

function _tweet_process($format = '', $tokens = array()) {
  if (!$format) {
    $format = variable_get('tweet_format', '[url] [title]');
  }
  foreach ($tokens as $search => $replace) {
    $format = str_ireplace($search, $replace, $format);
  }
  $format = drupal_urlencode($format);

  //The #, &, and / characters get double-encoded by drupal_urlencode, but they must appear single-encoded for Twitter to recognize them.

  //Spaces are manually encoded to plus signs for clarity of whitespace at the end of the tweet.
  $format = str_replace(array(
    '%2523',
    '%2526',
    '%252F',
    '%20',
  ), array(
    '%23',
    '%26',
    '%2F',
    '+',
  ), $format);
  return $format;
}