You are here

function potx_status in Translation template extractor 6.2

Same name and namespace in other branches
  1. 8 potx.inc \potx_status()
  2. 6.3 potx.inc \potx_status()
  3. 7.3 potx.inc \potx_status()
  4. 7 potx.inc \potx_status()
  5. 7.2 potx.inc \potx_status()

Status notification function.

Parameters

$op: Operation to perform or type of message text.

  • set: sets the reporting mode to $value use one of the POTX_STATUS_* constants as $value
  • get: returns the list of error messages recorded if $value is true, it also clears the internal message cache
  • error: sends an error message in $value with optional $file and $line
  • status: sends a status message in $value

$value: Value depending on $op.

$file: Name of file the error message is related to.

$line: Number of line the error message is related to.

$excerpt: Excerpt of the code in question, if available.

$docs_url: URL to the guidelines to follow to fix the problem.

7 calls to potx_status()
potx-cli.php in ./potx-cli.php
potx_coder_review in ./potx.module
Callback implementation for coder review of one file.
potx_select_form_submit in ./potx.module
Generate translation template or translation file for the requested component.
_potx_find_menu_hook in ./potx.inc
List of menu item titles. Only for Drupal 6.
_potx_find_perm_hook in ./potx.inc
Detect permission names from the hook_perm() implementations. Note that this will get confused with a similar pattern in a comment, and with dynamic permissions, which need to be accounted for.

... See full list

File

./potx.inc, line 595
Extraction API used by the web and command line interface.

Code

function potx_status($op, $value = NULL, $file = NULL, $line = NULL, $excerpt = NULL, $docs_url = NULL) {
  static $mode = POTX_STATUS_CLI;
  static $messages = array();
  switch ($op) {
    case 'set':

      // Setting the reporting mode.
      $mode = $value;
      return;
    case 'get':

      // Getting the errors. Optionally deleting the messages.
      $errors = $messages;
      if (!empty($value)) {
        $messages = array();
      }
      return $errors;
    case 'error':
    case 'status':

      // Location information is required in 3 of the four possible reporting
      // modes as part of the error message. The structured mode needs the
      // file, line and excerpt info separately, not in the text.
      $location_info = '';
      if ($mode != POTX_STATUS_STRUCTURED && isset($file)) {
        if (isset($line)) {
          if (isset($excerpt)) {
            $location_info = t('At %excerpt in %file on line %line.', array(
              '%excerpt' => $excerpt,
              '%file' => $file,
              '%line' => $line,
            ));
          }
          else {
            $location_info = t('In %file on line %line.', array(
              '%file' => $file,
              '%line' => $line,
            ));
          }
        }
        else {
          if (isset($excerpt)) {
            $location_info = t('At %excerpt in %file.', array(
              '%excerpt' => $excerpt,
              '%file' => $file,
            ));
          }
          else {
            $location_info = t('In %file.', array(
              '%file' => $file,
            ));
          }
        }
      }

      // Documentation helpers are provided as readable text in most modes.
      $read_more = '';
      if ($mode != POTX_STATUS_STRUCTURED && isset($docs_url)) {
        $read_more = $mode == POTX_STATUS_CLI ? t('Read more at @url', array(
          '@url' => $docs_url,
        )) : t('Read more at <a href="@url">@url</a>', array(
          '@url' => $docs_url,
        ));
      }

      // Error message or progress text to display.
      switch ($mode) {
        case POTX_STATUS_MESSAGE:
          drupal_set_message(join(' ', array(
            $value,
            $location_info,
            $read_more,
          )), $op);
          break;
        case POTX_STATUS_CLI:
          fwrite($op == 'error' ? STDERR : STDOUT, join("\n", array(
            $value,
            $location_info,
            $read_more,
          )) . "\n\n");
          break;
        case POTX_STATUS_SILENT:
          if ($op == 'error') {
            $messages[] = join(' ', array(
              $value,
              $location_info,
              $read_more,
            ));
          }
          break;
        case POTX_STATUS_STRUCTURED:
          if ($op == 'error') {
            $messages[] = array(
              $value,
              $file,
              $line,
              $excerpt,
              $docs_url,
            );
          }
          break;
      }
      return;
  }
}