Ejemplo n.º 1
0
/**
 * Clean up string found in JavaScript source code. Only from Drupal 6.
 */
function _potx_parse_js_string($string)
{
    return _potx_format_quoted_string(implode('', preg_split('~(?<!\\\\)[\'"]\\s*\\+\\s*[\'"]~s', $string)));
}
Ejemplo n.º 2
0
/**
 * Helper to find the value for 'context' on t() and format_plural().
 *
 * @param $tf
 *   Start position of the original function.
 * @param $ti
 *   Start position where we should search from.
 * @param $file
 *   Full path name of file parsed.
 * @param function_name
 *   The name of the function to look for. Either 'format_plural' or 't'
 *   given that Drupal 7 only supports context on these.
 */
function _potx_find_context($tf, $ti, $file, $function_name)
{
    global $_potx_tokens;
    // Start from after the comma and skip the possible arguments for the function
    // so we can look for the context.
    if (($ti = _potx_skip_args($ti)) && $_potx_tokens[$ti] == ',') {
        // Now we actually might have some definition for a context. The $options
        // argument is coming up, which might have a key for context.
        echo "TI:" . $ti . "\n";
        list($com, $arr, $par) = array($_potx_tokens[$ti], $_potx_tokens[$ti + 1], $_potx_tokens[$ti + 2]);
        if ($com == ',' && $arr[1] == 'array' && $par == '(') {
            $nesting = 0;
            $ti += 3;
            // Go through to either the end of the array or to the key definition of
            // context on the same nesting level.
            while (!(is_array($_potx_tokens[$ti]) && in_array($_potx_tokens[$ti][1], array('"context"', "'context'")) && $_potx_tokens[$ti][0] == T_CONSTANT_ENCAPSED_STRING && $nesting == 0 || $_potx_tokens[$ti] == ')' && $nesting == -1)) {
                $ti++;
                if (!is_array($_potx_tokens[$ti])) {
                    if ($_potx_tokens[$ti] == ')') {
                        $nesting--;
                    }
                    if ($_potx_tokens[$ti] == '(') {
                        $nesting++;
                    }
                }
            }
            if ($nesting == 0) {
                // Found the 'context' key on the top level of the $options array.
                list($arw, $str) = array($_potx_tokens[$ti + 1], $_potx_tokens[$ti + 2]);
                if (is_array($arw) && $arw[1] == '=>' && is_array($str) && $str[0] == T_CONSTANT_ENCAPSED_STRING) {
                    return _potx_format_quoted_string($str[1]);
                } else {
                    list($type, $string, $line) = $_potx_tokens[$ti];
                    // @todo: fix error reference.
                    _potx_marker_error($file, $line, $function_name, $tf, potx_t('The context element in the options array argument to @function() should be a literal string. There should be no variables, concatenation, constants or other non-literal strings there.', array('@function' => $function_name)), 'http://drupal.org/node/322732');
                    // Return with error.
                    return POTX_CONTEXT_ERROR;
                }
            } else {
                // Did not found 'context' key in $options array.
                return POTX_CONTEXT_NONE;
            }
        }
    }
    // After skipping args, we did not find a comma to look for $options.
    return POTX_CONTEXT_NONE;
}