function _potx_process_file2($file_path, $strip_prefix = 0, $save_callback = '_potx_save_string', $version_callback = '_potx_save_version', $api_version = POTX_API_6) { global $_potx_tokens, $_potx_lookup; // Figure out the basename and extension to select extraction method. $basename = basename($file_path); $name_parts = pathinfo($basename); // Always grab the CVS version number from the code $code = file_get_contents($file_path); $file_name = $strip_prefix > 0 ? substr($file_path, $strip_prefix) : $file_path; _potx_find_version_number($code, $file_name, $version_callback); // Extract raw PHP language tokens. $raw_tokens = token_get_all($code); unset($code); // Remove whitespace and possible HTML (the later in templates for example), // count line numbers so we can include them in the output. $_potx_tokens = array(); $_potx_lookup = array(); $token_number = 0; $line_number = 1; foreach ($raw_tokens as $token) { if (!is_array($token) || $token[0] != T_WHITESPACE && $token[0] != T_INLINE_HTML) { if (is_array($token)) { $token[] = $line_number; // Fill array for finding token offsets quickly. $src_tokens = array('_t'); if ($token[0] == T_STRING || $token[0] == T_VARIABLE && in_array($token[1], $src_tokens)) { if (!isset($_potx_lookup[$token[1]])) { $_potx_lookup[$token[1]] = array(); } $_potx_lookup[$token[1]][] = $token_number; } } $_potx_tokens[] = $token; $token_number++; } // Collect line numbers. if (is_array($token)) { $line_number += count(explode("\n", $token[1])) - 1; } else { $line_number += count(explode("\n", $token)) - 1; } } unset($raw_tokens); // Drupal 7 onwards supports context on t(). if (!empty($src_tokens)) { foreach ($src_tokens as $tk) { _potx_find_t_calls_with_context($file_name, $save_callback, $tk); } } }
/** * Process a file and put extracted information to the given parameters. * * @param $file_path * Complete path to file to process. * @param $strip_prefix * An integer denoting the number of chars to strip from filepath for output. * @param $save_callback * Callback function to use to save the collected strings. * @param $version_callback * Callback function to use to save collected version numbers. * @param $default_domain * Default domain to be used if one can't be found. */ function _potx_process_file($file_path, $strip_prefix = 0, $save_callback = '_potx_save_string', $version_callback = '_potx_save_version', $default_domain = '') { global $_potx_tokens, $_potx_lookup; // Always grab the CVS version number from the code $code = file_get_contents($file_path); $file_name = $strip_prefix > 0 ? substr($file_path, $strip_prefix) : $file_path; _potx_find_version_number($code, $file_name, $version_callback); // Extract raw PHP language tokens. $raw_tokens = token_get_all($code); unset($code); // Remove whitespace and possible HTML (the later in templates for example), // count line numbers so we can include them in the output. $_potx_tokens = array(); $_potx_lookup = array(); $token_number = 0; $line_number = 1; // Fill array for finding token offsets quickly. $src_tokens = array('__', 'esc_attr__', 'esc_html__', '_e', 'esc_attr_e', 'esc_html_e', '_x', 'esc_attr_x', 'esc_html_x', '_ex', '_n', '_nx'); foreach ($raw_tokens as $token) { if (!is_array($token) || $token[0] != T_WHITESPACE && $token[0] != T_INLINE_HTML) { if (is_array($token)) { $token[] = $line_number; if ($token[0] == T_STRING || $token[0] == T_VARIABLE && in_array($token[1], $src_tokens)) { if (!isset($_potx_lookup[$token[1]])) { $_potx_lookup[$token[1]] = array(); } $_potx_lookup[$token[1]][] = $token_number; } } $_potx_tokens[] = $token; $token_number++; } // Collect line numbers. if (is_array($token)) { $line_number += count(explode("\n", $token[1])) - 1; } else { $line_number += count(explode("\n", $token)) - 1; } } unset($raw_tokens); if (!empty($src_tokens)) { foreach ($src_tokens as $tk) { _potx_find_t_calls_with_context($file_name, $save_callback, $tk, $default_domain); } } }