Example #1
0
function git_search($projectroot, $project, $hash, $search, $searchtype, $page = 0)
{
    global $tpl, $gitphp_conf;
    $cachekey = sha1($project) . "|" . $hash . "|" . sha1($searchtype) . "|" . sha1($search) . "|" . (isset($page) ? $page : 0);
    if (!$tpl->is_cached('search.tpl', $cachekey)) {
        if (!$gitphp_conf['search']) {
            git_message("Search has been disabled", TRUE, TRUE);
            return;
        }
        if (!isset($search) || strlen($search) < 2) {
            git_message("You must enter search text of at least 2 characters", TRUE, TRUE);
            return;
        }
        if (!isset($hash)) {
            //$hash = git_read_head($projectroot . $project);
            $hash = "HEAD";
        }
        $co = git_read_commit($projectroot . $project, $hash);
        $revlist = git_read_revlist($projectroot . $project, $hash, 101, $page * 100, FALSE, FALSE, $searchtype, $search);
        if (count($revlist) < 1 || strlen($revlist[0]) < 1) {
            git_message("No matches for '" . $search . "'.", FALSE, TRUE);
            return;
        }
        $tpl->assign("hash", $hash);
        $tpl->assign("treehash", $co['tree']);
        $tpl->assign("search", $search);
        $tpl->assign("searchtype", $searchtype);
        $tpl->assign("page", $page);
        $revlistcount = count($revlist);
        $tpl->assign("revlistcount", $revlistcount);
        $tpl->assign("title", $co['title']);
        $commitlines = array();
        $commitcount = min(100, $revlistcount);
        for ($i = 0; $i < $commitcount; ++$i) {
            $commit = $revlist[$i];
            if (strlen(trim($commit)) > 0) {
                $commitline = array();
                $co2 = git_read_commit($projectroot . $project, $commit);
                $commitline["commit"] = $commit;
                $commitline["agestringage"] = $co2['age_string_age'];
                $commitline["agestringdate"] = $co2['age_string_date'];
                $commitline["authorname"] = $co2['author_name'];
                $commitline["title_short"] = $co2['title_short'];
                if (strlen($co2['title_short']) < strlen($co2['title'])) {
                    $commitline["title"] = $co2['title'];
                }
                $commitline["committree"] = $co2['tree'];
                $matches = array();
                foreach ($co2['comment'] as $comline) {
                    $hl = highlight($comline, $search, "searchmatch", GITPHP_TRIM_LENGTH);
                    if ($hl && strlen($hl) > 0) {
                        $matches[] = $hl;
                    }
                }
                $commitline["matches"] = $matches;
                $commitlines[] = $commitline;
            }
        }
        $tpl->assign("commitlines", $commitlines);
    }
    $tpl->display('search.tpl', $cachekey);
}
Example #2
0
                                case "blobdiff_plain":
                                    require_once 'include/display.git_blobdiff_plain.php';
                                    git_blobdiff_plain($gitphp_conf['projectroot'], $project, $_GET['h'], $_GET['hp'], isset($_GET['f']) ? $_GET['f'] : NULL);
                                    break;
                                case "snapshot":
                                    require_once 'include/display.git_snapshot.php';
                                    git_snapshot($gitphp_conf['projectroot'], $project, isset($_GET['h']) ? $_GET['h'] : NULL);
                                    break;
                                case "tag":
                                    require_once 'include/display.git_tag.php';
                                    git_tag($gitphp_conf['projectroot'], $project, $_GET['h']);
                                    break;
                                default:
                                    $tpl->assign("validaction", FALSE);
                                    require_once 'include/display.git_message.php';
                                    git_message("Unknown action", TRUE);
                                    break;
                            }
                        }
                    }
                }
            } else {
                require_once 'include/display.git_project_list.php';
                git_project_list($gitphp_conf['projectroot'], isset($git_projects) ? $git_projects : null, isset($_GET['o']) ? $_GET['o'] : "project");
            }
        }
    }
}
if ($gitphp_conf['debug'] && $extraoutput) {
    echo "Execution time: " . round(microtime(true) - GITPHP_START_TIME, 8) . " sec";
}
function git_search_files($projectroot, $project, $hash, $search, $page = 0)
{
    global $tpl, $gitphp_conf;
    $cachekey = sha1($project) . "|" . $hash . "|" . "filesearch" . "|" . sha1($search) . "|" . (isset($page) ? $page : 0);
    if (!$tpl->is_cached('searchfiles.tpl', $cachekey)) {
        if (!($gitphp_conf['search'] && $gitphp_conf['filesearch'])) {
            git_message("File search has been disabled", TRUE, TRUE);
            return;
        }
        if (!isset($search) || strlen($search) < 2) {
            git_message("You must enter search text of at least 2 characters", TRUE, TRUE);
            return;
        }
        if (!isset($hash)) {
            //$hash = git_read_head($projectroot . $project);
            $hash = "HEAD";
        }
        $co = git_read_commit($projectroot . $project, $hash);
        $filesearch = git_filesearch($projectroot . $project, $hash, $search, false, $page * 100, 101);
        if (count($filesearch) < 1) {
            git_message("No matches for '" . $search . "'.", FALSE, TRUE);
            return;
        }
        $tpl->assign("hash", $hash);
        $tpl->assign("treehash", $co['tree']);
        $tpl->assign("search", $search);
        $tpl->assign("searchtype", "file");
        $tpl->assign("page", $page);
        $filesearchcount = count($filesearch);
        $tpl->assign("filesearchcount", $filesearchcount);
        $tpl->assign("title", $co['title']);
        $filesearchlines = array();
        $i = 0;
        foreach ($filesearch as $file => $data) {
            $filesearchline = array();
            $filesearchline["file"] = $file;
            if (strpos($file, "/") !== false) {
                $f = basename($file);
                $d = dirname($file);
                if ($d == "/") {
                    $d = "";
                }
                $hlt = highlight($f, $search, "searchmatch");
                if ($hlt) {
                    $hlt = $d . "/" . $hlt;
                }
            } else {
                $hlt = highlight($file, $search, "searchmatch");
            }
            if ($hlt) {
                $filesearchline["filename"] = $hlt;
            } else {
                $filesearchline["filename"] = $file;
            }
            $filesearchline["hash"] = $data['hash'];
            if ($data['type'] == "tree") {
                $filesearchline["tree"] = TRUE;
            }
            if (isset($data['lines'])) {
                $matches = array();
                foreach ($data['lines'] as $line) {
                    $hlt = highlight($line, $search, "searchmatch", floor(GITPHP_TRIM_LENGTH * 1.5), true);
                    if ($hlt) {
                        $matches[] = $hlt;
                    }
                }
                if (count($matches) > 0) {
                    $filesearchline["matches"] = $matches;
                }
            }
            $filesearchlines[] = $filesearchline;
            ++$i;
            if ($i >= 100) {
                break;
            }
        }
        $tpl->assign("filesearchlines", $filesearchlines);
    }
    $tpl->display('searchfiles.tpl', $cachekey);
}