Beispiel #1
0
/**
 * Process $p_string, looking for bugnote ID references and creating bug view
 * links for them.
 *
 * Returns the processed string.
 *
 * If $p_include_anchor is true, include the href tag, otherwise just insert
 * the URL
 *
 * The bugnote tag ('~' by default) must be at the beginning of the string or
 * preceeded by a character that is not a letter, a number or an underscore
 *
 * if $p_include_anchor = false, $p_fqdn is ignored and assumed to true.
 * @param string  $p_string         String to be processed.
 * @param boolean $p_include_anchor Whether to include the href tag or just the URL.
 * @param boolean $p_detail_info    Whether to include more detailed information (e.g. title attribute / project) in the returned string.
 * @param boolean $p_fqdn           Whether to return an absolute or relative link.
 * @return string
 */
function string_process_bugnote_link($p_string, $p_include_anchor = true, $p_detail_info = true, $p_fqdn = false)
{
    static $s_bugnote_link_callback = array();
    $t_tag = config_get('bugnote_link_tag');
    # bail if the link tag is blank
    if ('' == $t_tag || $p_string == '') {
        return $p_string;
    }
    if (!isset($s_bugnote_link_callback[$p_include_anchor][$p_detail_info][$p_fqdn])) {
        if ($p_include_anchor) {
            $s_bugnote_link_callback[$p_include_anchor][$p_detail_info][$p_fqdn] = function ($p_array) use($p_detail_info, $p_fqdn) {
                global $g_project_override;
                if (bugnote_exists((int) $p_array[2])) {
                    $t_bug_id = bugnote_get_field((int) $p_array[2], 'bug_id');
                    if (bug_exists($t_bug_id)) {
                        $g_project_override = bug_get_field($t_bug_id, 'project_id');
                        if (access_compare_level(user_get_access_level(auth_get_current_user_id(), bug_get_field($t_bug_id, 'project_id')), config_get('private_bugnote_threshold')) || bugnote_get_field((int) $p_array[2], 'reporter_id') == auth_get_current_user_id() || bugnote_get_field((int) $p_array[2], 'view_state') == VS_PUBLIC) {
                            $g_project_override = null;
                            return $p_array[1] . string_get_bugnote_view_link($t_bug_id, (int) $p_array[2], (bool) $p_detail_info, (bool) $p_fqdn);
                        }
                        $g_project_override = null;
                    }
                }
                return $p_array[0];
            };
            # end of bugnote link callback closure
        } else {
            $s_bugnote_link_callback[$p_include_anchor][$p_detail_info][$p_fqdn] = function ($p_array) {
                $t_bug_id = bugnote_get_field((int) $p_array[2], 'bug_id');
                if ($t_bug_id && bug_exists($t_bug_id)) {
                    return $p_array[1] . string_get_bugnote_view_url_with_fqdn($t_bug_id, (int) $p_array[2]);
                } else {
                    return $p_array[0];
                }
            };
            # end of bugnote link callback closure
        }
    }
    $p_string = preg_replace_callback('/(^|[^\\w])' . preg_quote($t_tag, '/') . '(\\d+)\\b/', $s_bugnote_link_callback[$p_include_anchor][$p_detail_info][$p_fqdn], $p_string);
    return $p_string;
}
Beispiel #2
0
function string_process_bugnote_link($p_string, $p_include_anchor = true, $p_detail_info = true, $p_fqdn = false)
{
    $t_tag = config_get('bugnote_link_tag');
    # bail if the link tag is blank
    if ('' == $t_tag) {
        return $p_string;
    }
    preg_match_all('/(^|.+?)(?:(?<=^|\\W)' . preg_quote($t_tag) . '(\\d+)|$)/s', $p_string, $t_matches, PREG_SET_ORDER);
    $t_result = '';
    if ($p_include_anchor) {
        foreach ($t_matches as $t_match) {
            $t_result .= $t_match[1];
            if (isset($t_match[2])) {
                $t_bugnote_id = $t_match[2];
                if (bugnote_exists($t_bugnote_id)) {
                    $t_bug_id = bugnote_get_field($t_bugnote_id, 'bug_id');
                    if (bug_exists($t_bug_id)) {
                        $t_result .= string_get_bugnote_view_link($t_bug_id, $t_bugnote_id, null, $p_detail_info, $p_fqdn);
                    } else {
                        $t_result .= $t_bugnote_id;
                    }
                }
            }
        }
    } else {
        foreach ($t_matches as $t_match) {
            $t_result .= $t_match[1];
            if (isset($t_match[2])) {
                $t_bugnote_id = $t_match[2];
                $t_bug_id = bugnote_get_field($t_bugnote_id, 'bug_id');
                # We might as well create the link here even if the bug
                #  doesn't exist.  In the case above we don't want to do
                #  the summary lookup on a non-existant bug.  But here, we
                #  can create the link and by the time it is clicked on, the
                #  bug may exist.
                $t_result .= string_get_bugnote_view_url_with_fqdn($t_bug_id, $t_bugnote_id, null);
            }
        }
    }
    return $t_result;
}