Same name and namespace in other branches
  1. 4.7.x includes/locale.inc \_locale_string_seek()
  2. 5.x includes/locale.inc \_locale_string_seek()

Perform a string search and display results in a table

File

includes/locale.inc, line 1013
Admin-related functions for locale.module.

Code

function _locale_string_seek() {

  // We have at least one criterion to match
  if ($query = _locale_string_seek_query()) {
    $join = "SELECT s.source, s.location, s.lid, t.translation, t.locale FROM {locales_source} s INNER JOIN {locales_target} t ON s.lid = t.lid ";

    // Compute LIKE section
    switch ($query->searchin) {
      case 'translated':
        $where = "WHERE (t.translation LIKE '%" . db_escape_string($query->string) . "%' AND t.translation != '')";
        $orderby = "ORDER BY t.translation";
        break;
      case 'untranslated':
        $where = "WHERE (s.source LIKE '%" . db_escape_string($query->string) . "%' AND t.translation = '')";
        $orderby = "ORDER BY s.source";
        break;
      case 'all':
      default:
        $where = "WHERE (s.source LIKE '%" . db_escape_string($query->string) . "%' OR t.translation LIKE '%" . db_escape_string($query->string) . "%')";
        $orderby = '';
        break;
    }
    switch ($query->language) {

      // Force search in source strings
      case "en":
        $sql = $join . " WHERE s.source LIKE '%" . db_escape_string($query->string) . "%' ORDER BY s.source";
        break;

      // Search in all languages
      case "all":
        $sql = "{$join} {$where} {$orderby}";
        break;

      // Some different language
      default:
        $sql = "{$join} {$where} AND t.locale = '" . db_escape_string($query->language) . "' {$orderby}";
    }
    $result = pager_query($sql, 50);
    $header = array(
      t('String'),
      t('Locales'),
      array(
        'data' => t('Operations'),
        'colspan' => '2',
      ),
    );
    $arr = array();
    while ($locale = db_fetch_object($result)) {
      $arr[$locale->lid]['locales'][$locale->locale] = $locale->translation;
      $arr[$locale->lid]['location'] = $locale->location;
      $arr[$locale->lid]['source'] = $locale->source;
    }
    foreach ($arr as $lid => $value) {
      $source = htmlspecialchars($value['source']);
      $rows[] = array(
        array(
          'data' => (strlen($source) > 150 ? substr($source, 0, 150) . '...' : $source) . '<br /><small>' . $value['location'] . '</small>',
        ),
        array(
          'data' => _locale_string_language_list($value['locales']),
          'align' => 'center',
        ),
        array(
          'data' => l(t('edit'), "admin/locale/string/edit/{$lid}"),
          'nowrap' => 'nowrap',
        ),
        array(
          'data' => l(t('delete'), "admin/locale/string/delete/{$lid}"),
          'nowrap' => 'nowrap',
        ),
      );
    }
    $request = array();
    if (count($query)) {
      foreach ($query as $key => $value) {
        $request[$key] = is_array($value) ? implode(',', $value) : $value;
      }
    }
    if ($pager = theme('pager', NULL, 50, 0, $request)) {
      $rows[] = array(
        array(
          'data' => "{$pager}",
          'colspan' => '5',
        ),
      );
    }
    $output .= theme('table', $header, $rows);
  }
  return $output;
}