/**
  * __construct
  *
  * Constructor
  *
  * @access public
  * @return mixed controller object
  * @throws Exception on invalid project
  */
 public function __construct()
 {
     require_once GitPHP_Util::AddSlash(GitPHP_Config::GetInstance()->GetValue('smarty_prefix', 'lib/smarty/libs/')) . 'Smarty.class.php';
     $this->tpl = new Smarty();
     $this->tpl->error_reporting = E_ALL & ~E_NOTICE;
     $this->tpl->addPluginsDir(GITPHP_INCLUDEDIR . 'smartyplugins');
     if (GitPHP_Config::GetInstance()->GetValue('cache', false)) {
         $this->tpl->caching = Smarty::CACHING_LIFETIME_SAVED;
         if (GitPHP_Config::GetInstance()->HasKey('cachelifetime')) {
             $this->tpl->cache_lifetime = GitPHP_Config::GetInstance()->GetValue('cachelifetime');
         }
         $servers = GitPHP_Config::GetInstance()->GetValue('memcache', null);
         if (isset($servers) && is_array($servers) && count($servers) > 0) {
             $this->tpl->caching_type = 'memcache';
         }
     }
     if (isset($_GET['p'])) {
         $this->project = GitPHP_ProjectList::GetInstance()->GetProject(str_replace(chr(0), '', $_GET['p']));
         if (!$this->project) {
             throw new GitPHP_MessageException(sprintf(__('Invalid project %1$s'), $_GET['p']), true);
         }
     }
     if (isset($_GET['s'])) {
         $this->params['search'] = $_GET['s'];
     }
     if (isset($_GET['st'])) {
         $this->params['searchtype'] = $_GET['st'];
     }
     $this->ReadQuery();
 }
 /**
  * Recursively searches for projects
  *
  * @param string $dir directory to recurse into
  */
 private function RecurseDir($dir)
 {
     if (!(is_dir($dir) && is_readable($dir))) {
         return;
     }
     $this->Log('Search directory', $dir);
     if ($dh = opendir($dir)) {
         $trimlen = strlen(GitPHP_Util::AddSlash($this->projectRoot)) + 1;
         while (($file = readdir($dh)) !== false) {
             $fullPath = $dir . '/' . $file;
             if (strpos($file, '.') !== 0 && is_dir($fullPath)) {
                 if (is_file($fullPath . '/HEAD')) {
                     $this->Log('Found project', $fullPath);
                     $projectPath = substr($fullPath, $trimlen);
                     if (!isset($this->projects[$projectPath])) {
                         $project = $this->LoadProject($projectPath);
                         if ($project) {
                             $this->projects[$projectPath] = $project;
                             unset($project);
                         }
                     }
                 } else {
                     $this->RecurseDir($fullPath);
                 }
             } else {
                 $this->Log('Skip', $fullPath);
             }
         }
         closedir($dh);
     }
 }
 /**
  * Determines the diff mode to use
  *
  * @param string $overrideMode mode overridden by the user
  */
 protected function DiffMode($overrideMode = '')
 {
     $mode = GitPHP_Controller_DiffBase::UnifiedDiff;
     // default
     $baseurl = GitPHP_Util::BaseUrl();
     /*
      * Check cookie
      */
     if (!empty($_COOKIE[GitPHP_Controller_DiffBase::DiffModeCookie])) {
         $mode = $_COOKIE[GitPHP_Controller_DiffBase::DiffModeCookie];
     } else {
         /*
          * Create cookie to prevent browser delay
          */
         setcookie(GitPHP_Controller_DiffBase::DiffModeCookie, $mode, time() + GitPHP_Controller_DiffBase::DiffModeCookieLifetime, $baseurl);
     }
     if (!empty($overrideMode)) {
         /*
          * User is choosing a new mode
          */
         if ($overrideMode == 'sidebyside') {
             $mode = GitPHP_Controller_DiffBase::SideBySideDiff;
             setcookie(GitPHP_Controller_DiffBase::DiffModeCookie, GitPHP_Controller_DiffBase::SideBySideDiff, time() + GitPHP_Controller_DiffBase::DiffModeCookieLifetime, $baseurl);
         } else {
             if ($overrideMode == 'unified') {
                 $mode = GitPHP_Controller_DiffBase::UnifiedDiff;
                 setcookie(GitPHP_Controller_DiffBase::DiffModeCookie, GitPHP_Controller_DiffBase::UnifiedDiff, time() + GitPHP_Controller_DiffBase::DiffModeCookieLifetime, $baseurl);
             }
         }
     }
     return $mode;
 }
 /**
  * PopulateProjects
  *
  * Populates the internal list of projects
  *
  * @access protected
  * @throws Exception if file cannot be read
  */
 protected function PopulateProjects()
 {
     if (!($fp = fopen($this->projectConfig, 'r'))) {
         throw new Exception(sprintf(__('Failed to open project list file %1$s'), $this->projectConfig));
     }
     $projectRoot = GitPHP_Util::AddSlash(GitPHP_Config::GetInstance()->GetValue('projectroot'));
     while (!feof($fp) && ($line = fgets($fp))) {
         if (preg_match('/^([^\\s]+)(\\s.+)?$/', $line, $regs)) {
             if (is_file($projectRoot . $regs[1] . '/HEAD')) {
                 try {
                     $projObj = new GitPHP_Project($projectRoot, $regs[1]);
                     if (isset($regs[2]) && !empty($regs[2])) {
                         $projOwner = trim($regs[2]);
                         if (!empty($projOwner)) {
                             $projObj->SetOwner($projOwner);
                         }
                     }
                     $this->projects[$regs[1]] = $projObj;
                 } catch (Exception $e) {
                     GitPHP_Log::GetInstance()->Log($e->getMessage());
                 }
             } else {
                 GitPHP_Log::GetInstance()->Log(sprintf('%1$s is not a git project', $projectRoot . $regs[1]));
             }
         }
     }
     fclose($fp);
 }
 /**
  * Gets the object name
  *
  * @return string name
  */
 public function GetName()
 {
     if (!empty($this->path)) {
         return GitPHP_Util::BaseName($this->path);
     }
     return '';
 }
 /**
  * Constructor
  *
  * @param string $cacheDir cache dir
  * @param int $compressThreshold threshold to start compressing data at
  * @param boolean $igbinary whether to use igbinary, null to autodetect
  */
 public function __construct($cacheDir, $compressThreshold = 0, $igbinary = null)
 {
     if (file_exists($cacheDir)) {
         if (!is_dir($cacheDir)) {
             throw new Exception($cacheDir . ' exists but is not a directory');
         } else {
             if (!is_writable($cacheDir)) {
                 throw new Exception($cacheDir . ' is not writable');
             }
         }
     } else {
         if (!mkdir($cacheDir, 0777)) {
             throw new Exception($cacheDir . ' could not be created');
         }
         chmod($cacheDir, 0777);
     }
     $this->cacheDir = GitPHP_Util::AddSlash($cacheDir, true);
     if (!(is_int($compressThreshold) && $compressThreshold >= 0)) {
         throw new Exception('Invalid compression threshold');
     }
     $this->compressThreshold = $compressThreshold;
     if ($igbinary === null) {
         $this->igbinary = function_exists('igbinary_serialize');
     } else {
         if ($igbinary) {
             if (!function_exists('igbinary_serialize')) {
                 throw new Exception('Igbinary is not present');
             }
             $this->igbinary = $igbinary;
         }
     }
 }
 /**
  * PopulateProjects
  *
  * Populates the internal list of projects
  *
  * @access protected
  * @throws Exception if file cannot be read
  */
 protected function PopulateProjects()
 {
     $projectRoot = GitPHP_Util::AddSlash(GitPHP_Config::GetInstance()->GetValue('projectroot'));
     foreach ($this->projectConfig as $proj => $projData) {
         try {
             if (is_string($projData)) {
                 // Just flat array of project paths
                 $projObj = new GitPHP_Project($projectRoot, $projData);
                 $this->projects[$projData] = $projObj;
             } else {
                 if (is_array($projData)) {
                     if (is_string($proj) && !empty($proj)) {
                         // Project key pointing to data array
                         $projObj = new GitPHP_Project($projectRoot, $proj);
                         $this->projects[$proj] = $projObj;
                         $this->ApplyProjectSettings($proj, $projData);
                     } else {
                         if (isset($projData['project'])) {
                             // List of data arrays with projects inside
                             $projObj = new GitPHP_Project($projectRoot, $projData['project']);
                             $this->projects[$projData['project']] = $projObj;
                             $this->ApplyProjectSettings(null, $projData);
                         }
                     }
                 }
             }
         } catch (Exception $e) {
             GitPHP_Log::GetInstance()->Log($e->getMessage());
         }
     }
 }
 /**
  * __construct
  *
  * constructor
  *
  * @param string $projectDir directory to search
  * @throws Exception if parameter is not a directory
  * @access public
  */
 public function __construct($projectDir)
 {
     if (!is_dir($projectDir)) {
         throw new Exception(sprintf(__('%1$s is not a directory'), $projectDir));
     }
     $this->projectDir = GitPHP_Util::AddSlash($projectDir);
     parent::__construct();
 }
Beispiel #9
0
 public function testListDir()
 {
     $datadir = dirname(__FILE__) . '/resources/testdir';
     $listed = GitPHP_Util::ListDir($datadir);
     $this->assertCount(5, $listed);
     $expected = array($datadir . '/.hiddentestfile', $datadir . '/testfile1.txt', $datadir . '/testdir2/testfile2.txt', $datadir . '/testdir2/testdir4/testfile4.txt', $datadir . '/testdir3/testfile3.txt');
     $this->assertCount(0, array_diff($listed, $expected));
     $this->assertCount(0, array_diff($expected, $listed));
 }
 /**
  * Initialize controller
  */
 public function Initialize()
 {
     $this->InitializeConfig();
     $this->InitializeUserList();
     $this->InitializeGitExe();
     $this->InitializeProjectList();
     // HACK: this needs to be done early because the snapshot controller modifies the headers before opening the archive
     if (!GitPHP_Util::FunctionAllowed('popen')) {
         throw new GitPHP_DisabledFunctionException('popen');
     }
     if (isset($this->params['project'])) {
         $project = $this->projectList->GetProject($this->params['project']);
         if (!$project) {
             throw new GitPHP_InvalidProjectParameterException($this->params['project']);
         }
         if ($this->userList && $this->userList->GetCount() > 0) {
             if (!$project->UserCanAccess(!empty($_SESSION['gitphpuser']) ? $_SESSION['gitphpuser'] : null)) {
                 throw new GitPHP_UnauthorizedProjectException($this->params['project']);
             }
         }
         $this->project = $project->GetProject();
     }
     if (!$this->project) {
         throw new GitPHP_MissingProjectParameterException();
     }
     $this->preserveWhitespace = true;
     if (empty($this->params['format'])) {
         $this->params['format'] = $this->config->GetValue('compressformat');
     }
     $this->InitializeArchive();
     if ($this->config->GetValue('cache')) {
         $this->cacheDir = GITPHP_CACHEDIR . 'snapshots/';
         if (file_exists($this->cacheDir)) {
             if (!is_dir($this->cacheDir)) {
                 throw new Exception($this->cacheDir . ' exists but is not a directory');
             } else {
                 if (!is_writable($this->cacheDir)) {
                     throw new Exception($this->cacheDir . ' is not writable');
                 }
             }
         } else {
             if (!mkdir($this->cacheDir, 0777)) {
                 throw new Exception($this->cacheDir . ' could not be created');
             }
             chmod($this->cacheDir, 0777);
         }
     }
 }
 /**
  * PopulateProjects
  *
  * Populates the internal list of projects
  *
  * @access protected
  * @throws Exception if file cannot be read
  */
 protected function PopulateProjects()
 {
     $projectRoot = GitPHP_Util::AddSlash(GitPHP_Config::GetInstance()->GetValue('projectroot'));
     foreach ($this->projectConfig as $cat => $plist) {
         if (is_array($plist)) {
             foreach ($plist as $pname => $ppath) {
                 try {
                     $projObj = new GitPHP_Project($projectRoot, $ppath);
                     if ($cat != GITPHP_NO_CATEGORY) {
                         $projObj->SetCategory($cat);
                     }
                     $this->projects[$ppath] = $projObj;
                 } catch (Exception $e) {
                     GitPHP_Log::GetInstance()->Log($e->getMessage());
                 }
             }
         }
     }
 }
 /**
  * Loads data for this template
  */
 protected function LoadData()
 {
     $head = $this->GetProject()->GetHeadCommit();
     $data = null;
     if ($this->params['graphtype'] == 'commitactivity') {
         $data = array();
         $commits = explode("\n", $this->exe->Execute($this->GetProject()->GetPath(), 'rev-list', array('--format=format:"%H %ct"', $head->GetHash())));
         foreach ($commits as $commit) {
             if (preg_match('/^([0-9a-fA-F]{40}) ([0-9]+)$/', $commit, $regs)) {
                 $data[] = array('CommitEpoch' => (int) $regs[2]);
             }
         }
     } else {
         if ($this->params['graphtype'] == 'languagedist') {
             $data = array();
             include_once GITPHP_GESHIDIR . "geshi.php";
             $geshi = new GeSHi("", 'php');
             $files = explode("\n", $this->exe->Execute($this->GetProject()->GetPath(), 'ls-tree', array('-r', '--name-only', $head->GetTree()->GetHash())));
             foreach ($files as $file) {
                 $filename = GitPHP_Util::BaseName($file);
                 $lang = GitPHP_Util::GeshiFilenameToLanguage($filename);
                 if (empty($lang)) {
                     $lang = $geshi->get_language_name_from_extension(substr(strrchr($filename, '.'), 1));
                     if (empty($lang)) {
                         $lang = 'Other';
                     }
                 }
                 if (!empty($lang) && $lang !== 'Other') {
                     $fulllang = $geshi->get_language_fullname($lang);
                     if (!empty($fulllang)) {
                         $lang = $fulllang;
                     }
                 }
                 if (isset($data[$lang])) {
                     $data[$lang]++;
                 } else {
                     $data[$lang] = 1;
                 }
             }
         }
     }
     $this->tpl->assign('data', json_encode($data));
 }
 /**
  * PopulateProjects
  *
  * Populates the internal list of projects
  *
  * @access protected
  * @throws Exception if file cannot be read
  */
 protected function PopulateProjects()
 {
     $projectRoot = GitPHP_Util::AddSlash(GitPHP_Config::GetInstance()->GetValue('projectroot'));
     $use_errors = libxml_use_internal_errors(true);
     $xml = simplexml_load_file($this->projectConfig);
     libxml_clear_errors();
     libxml_use_internal_errors($use_errors);
     if (!$xml) {
         throw new Exception(sprintf('Could not load SCM manager config %1$s', $this->projectConfig));
     }
     foreach ($xml->repositories->repository as $repository) {
         if ($repository->type != 'git') {
             GitPHP_Log::GetInstance()->Log(sprintf('%1$s is not a git project', $repository->name));
             continue;
         }
         if ($repository->public != 'true') {
             GitPHP_Log::GetInstance()->Log(sprintf('%1$s is not public', $repository->name));
             continue;
         }
         $projName = trim($repository->name);
         if (empty($projName)) {
             continue;
         }
         if (is_file($projectRoot . $projName . '/HEAD')) {
             try {
                 $projObj = new GitPHP_Project($projectRoot, $projName);
                 $projOwner = trim($repository->contact);
                 if (!empty($projOwner)) {
                     $projObj->SetOwner($projOwner);
                 }
                 $projDesc = trim($repository->description);
                 if (!empty($projDesc)) {
                     $projObj->SetDescription($projDesc);
                 }
                 $this->projects[$projName] = $projObj;
             } catch (Exception $e) {
                 GitPHP_Log::GetInstance()->Log($e->getMessage());
             }
         } else {
             GitPHP_Log::GetInstance()->Log(sprintf('%1$s is not a git project', $projName));
         }
     }
 }
/**
 * scripturl smarty function
 *
 * @param array $params function parameters
 * @param mixed $smarty smarty object
 * @return string script url
 */
function smarty_function_scripturl($params, &$smarty)
{
    if (GitPHP_Config::GetInstance()->HasKey('self')) {
        $selfurl = GitPHP_Config::GetInstance()->GetValue('self');
        if (!empty($selfurl)) {
            if (substr($selfurl, -4) != '.php') {
                $selfurl = GitPHP_Util::AddSlash($selfurl);
            }
            return $selfurl;
        }
    }
    if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') {
        $scriptstr = 'https://';
    } else {
        $scriptstr = 'http://';
    }
    $scriptstr .= $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'];
    return $scriptstr;
}
 /**
  * Loads the ref list for a ref type
  *
  * @param GitPHP_RefList $refList ref list
  * @param string $type ref type
  * @return array array of refs
  */
 protected function GetRefs(GitPHP_RefList $refList, $type)
 {
     if (!$refList) {
         return;
     }
     if (empty($type)) {
         return;
     }
     if (GitPHP_DebugLog::GetInstance()->GetEnabled()) {
         $autotimer = new GitPHP_DebugAutoLog();
     }
     $refs = array();
     $prefix = 'refs/' . $type;
     $fullPath = $refList->GetProject()->GetPath() . '/' . $prefix;
     $fullPathLen = strlen($fullPath) + 1;
     /* loose files */
     $refFiles = GitPHP_Util::ListDir($fullPath);
     for ($i = 0; $i < count($refFiles); ++$i) {
         $ref = substr($refFiles[$i], $fullPathLen);
         if (empty($ref) || isset($refs[$ref])) {
             continue;
         }
         $hash = trim(file_get_contents($refFiles[$i]));
         if (preg_match('/^[0-9A-Fa-f]{40}$/', $hash)) {
             $refs[$ref] = $hash;
         }
     }
     /* packed refs */
     if (file_exists($refList->GetProject()->GetPath() . '/packed-refs')) {
         $packedRefs = explode("\n", file_get_contents($refList->GetProject()->GetPath() . '/packed-refs'));
         foreach ($packedRefs as $ref) {
             if (preg_match('/^([0-9A-Fa-f]{40}) refs\\/' . $type . '\\/(.+)$/', $ref, $regs)) {
                 if (!isset($refs[$regs[2]])) {
                     $refs[$regs[2]] = $regs[1];
                 }
             }
         }
     }
     return $refs;
 }
 /**
  * Loads a project
  *
  * @param string $proj project
  * @return GitPHP_Project project object
  */
 protected function LoadProject($proj)
 {
     if (!$this->fileRead) {
         $this->ReadFile();
     }
     $found = false;
     $owner = null;
     foreach ($this->fileContents as $lineData) {
         if (isset($lineData['project']) && $lineData['project'] == $proj) {
             $projectRoot = GitPHP_Util::AddSlash($this->projectRoot);
             if (is_file($projectRoot . $proj . '/HEAD')) {
                 $found = true;
                 if (isset($lineData['owner'])) {
                     $owner = $lineData['owner'];
                 }
             } else {
                 $this->Log('Invalid project', $projectRoot . $proj);
             }
             break;
         }
     }
     if (!$found) {
         return null;
     }
     $projectObj = new GitPHP_Project($this->projectRoot, $proj);
     $this->ApplyGlobalConfig($projectObj);
     $this->ApplyGitConfig($projectObj);
     if (!empty($owner)) {
         $projectObj->SetOwner($owner);
     }
     if ($this->projectSettings && isset($this->projectSettings[$proj])) {
         $this->ApplyProjectSettings($projectObj, $this->projectSettings[$proj]);
     }
     $this->InjectProjectDependencies($projectObj);
     return $projectObj;
 }
 /**
  * Loads common data used by all templates
  */
 private function LoadCommonData()
 {
     global $gitphp_version, $gitphp_appstring;
     $this->tpl->assign('version', $gitphp_version);
     $stylesheet = $this->config->GetValue('stylesheet');
     if ($stylesheet == 'gitphp.css') {
         // backwards compatibility
         $stylesheet = 'gitphpskin.css';
     }
     $this->tpl->assign('stylesheet', preg_replace('/\\.css$/', '', $stylesheet));
     $this->tpl->assign('javascript', $this->config->GetValue('javascript'));
     $this->tpl->assign('googlejs', $this->config->GetValue('googlejs'));
     if ($this->config->HasKey('title')) {
         $this->tpl->assign('pagetitle', $this->config->GetValue('title'));
     } else {
         $this->tpl->assign('pagetitle', $gitphp_appstring);
     }
     if ($this->config->HasKey('homelink')) {
         $this->tpl->assign('homelink', $this->config->GetValue('homelink'));
     } else {
         if ($this->resource) {
             $this->tpl->assign('homelink', $this->resource->translate('projects'));
         } else {
             $this->tpl->assign('homelink', 'projects');
         }
     }
     $this->tpl->assign('action', $this->GetName());
     $this->tpl->assign('actionlocal', $this->GetName(true));
     if ($this->project) {
         $this->tpl->assign('project', $this->GetProject());
     }
     if ($this->config->GetValue('search')) {
         $this->tpl->assign('enablesearch', true);
     }
     if ($this->config->GetValue('filesearch')) {
         $this->tpl->assign('filesearch', true);
     }
     if (isset($this->params['search'])) {
         $this->tpl->assign('search', $this->params['search']);
     }
     if (isset($this->params['searchtype'])) {
         $this->tpl->assign('searchtype', $this->params['searchtype']);
     }
     if ($this->resource) {
         $this->tpl->assign('currentlocale', $this->resource->GetLocale());
         $this->tpl->assign('currentprimarylocale', $this->resource->GetPrimaryLocale());
         $this->tpl->assign('resource', $this->resource);
     } else {
         $this->tpl->assign('currentlocale', 'en_US');
         $this->tpl->assign('currentprimarylocale', 'en');
     }
     $this->tpl->assign('supportedlocales', GitPHP_Resource::SupportedLocales(true));
     if ($this->config->GetValue('graphs')) {
         $this->tpl->assign('enablegraphs', true);
     }
     $this->tpl->assign('baseurl', GitPHP_Util::BaseUrl());
     $requesturl = $_SERVER['REQUEST_URI'];
     $querypos = strpos($requesturl, '?');
     if ($querypos !== false) {
         $requesturl = substr($requesturl, 0, $querypos);
     }
     $this->tpl->assign('requesturl', $requesturl);
     if ($this->router) {
         $this->router->SetCleanUrl($this->config->GetValue('cleanurl') ? true : false);
         $this->router->SetAbbreviate($this->config->GetValue('abbreviateurl') ? true : false);
         if ($this->config->GetValue('self')) {
             $this->router->SetBaseUrl($this->config->GetValue('self'));
         }
         $this->tpl->assign('router', $this->router);
     }
     $getvars = array();
     if (isset($_SERVER['QUERY_STRING'])) {
         $getvars = explode('&', $_SERVER['QUERY_STRING']);
     }
     $getvarsmapped = array();
     foreach ($getvars as $varstr) {
         $eqpos = strpos($varstr, '=');
         if ($eqpos > 0) {
             $var = substr($varstr, 0, $eqpos);
             $val = substr($varstr, $eqpos + 1);
             if (!(empty($var) || empty($val) || $var == 'q')) {
                 $getvarsmapped[$var] = urldecode($val);
             }
         }
     }
     $this->tpl->assign('requestvars', $getvarsmapped);
     $this->tpl->assign('snapshotformats', GitPHP_Archive::SupportedFormats());
     if ($this->userList && $this->userList->GetCount() > 0) {
         $this->tpl->assign('loginenabled', true);
         if (!empty($_SESSION['gitphpuser'])) {
             $user = $this->userList->GetUser($_SESSION['gitphpuser']);
             if ($user) {
                 $this->tpl->assign('loggedinuser', $user->GetUsername());
             }
         }
     }
     if ($this->log && $this->log->GetEnabled()) {
         $this->tpl->assign('debug', true);
     }
 }
 /**
  * Loads data for this template
  */
 protected function LoadData()
 {
     $head = $this->GetProject()->GetHeadCommit();
     $this->tpl->assign('head', $head);
     $commit = $this->GetProject()->GetCommit($this->params['hashbase']);
     $this->tpl->assign('commit', $commit);
     if (!isset($this->params['hash']) && isset($this->params['file'])) {
         $this->params['hash'] = $commit->GetTree()->PathToHash($this->params['file']);
         if (empty($this->params['hash'])) {
             throw new GitPHP_FileNotFoundException($this->params['file']);
         }
     }
     $blob = $this->GetProject()->GetObjectManager()->GetBlob($this->params['hash']);
     if ($this->params['file']) {
         $blob->SetPath($this->params['file']);
     }
     $blob->SetCommit($commit);
     $this->tpl->assign('blob', $blob);
     $blame = new GitPHP_FileBlame($this->GetProject(), $commit, $this->params['file'], $this->exe);
     $this->tpl->assign('blame', $blame->GetBlame());
     if (isset($this->params['output']) && $this->params['output'] == 'js') {
         return;
     }
     $this->tpl->assign('tree', $commit->GetTree());
     if ($this->config->GetValue('geshi')) {
         include_once GITPHP_GESHIDIR . "geshi.php";
         if (class_exists('GeSHi')) {
             $geshi = new GeSHi("", 'php');
             if ($geshi) {
                 $lang = GitPHP_Util::GeshiFilenameToLanguage($blob->GetName());
                 if (empty($lang)) {
                     $lang = $geshi->get_language_name_from_extension(substr(strrchr($blob->GetName(), '.'), 1));
                 }
                 if (!empty($lang)) {
                     $geshi->enable_classes();
                     $geshi->enable_strict_mode(GESHI_MAYBE);
                     $geshi->set_source($blob->GetData());
                     $geshi->set_language($lang);
                     $geshi->set_header_type(GESHI_HEADER_PRE_TABLE);
                     $geshi->enable_line_numbers(GESHI_NORMAL_LINE_NUMBERS);
                     $output = $geshi->parse_code();
                     $bodystart = strpos($output, '<td');
                     $bodyend = strrpos($output, '</tr>');
                     if ($bodystart !== false && $bodyend !== false) {
                         $geshihead = substr($output, 0, $bodystart);
                         $geshifoot = substr($output, $bodyend);
                         $geshibody = substr($output, $bodystart, $bodyend - $bodystart);
                         $this->tpl->assign('geshihead', $geshihead);
                         $this->tpl->assign('geshibody', $geshibody);
                         $this->tpl->assign('geshifoot', $geshifoot);
                         $this->tpl->assign('geshicss', $geshi->get_stylesheet());
                         $this->tpl->assign('geshi', true);
                     }
                 }
             }
         }
     }
 }
 /**
  * Loads data for this template
  */
 protected function LoadData()
 {
     $commit = $this->GetProject()->GetCommit($this->params['hashbase']);
     $this->tpl->assign('commit', $commit);
     $tree = $commit->GetTree();
     $this->tpl->assign('tree', $commit->GetTree());
     if (!isset($this->params['hash']) && isset($this->params['file'])) {
         $this->params['hash'] = $tree->PathToHash($this->params['file']);
         if (empty($this->params['hash'])) {
             throw new GitPHP_FileNotFoundException($this->params['file']);
         }
     }
     $blob = $this->GetProject()->GetObjectManager()->GetBlob($this->params['hash']);
     if (!empty($this->params['file'])) {
         $blob->SetPath($this->params['file']);
     }
     $blob->SetCommit($commit);
     $this->tpl->assign('blob', $blob);
     if ($this->Plain()) {
         return;
     }
     $head = $this->GetProject()->GetHeadCommit();
     $this->tpl->assign('head', $head);
     if ($this->config->GetValue('filemimetype')) {
         $mimeReader = new GitPHP_FileMimeTypeReader($blob, $this->GetMimeStrategy());
         $mimetype = $mimeReader->GetMimeType(true);
         if ($mimetype == 'image') {
             $this->tpl->assign('datatag', true);
             $this->tpl->assign('mime', $mimeReader->GetMimeType());
             $this->tpl->assign('data', base64_encode($blob->GetData()));
             return;
         }
     }
     if ($this->config->GetValue('geshi')) {
         include_once GITPHP_GESHIDIR . "geshi.php";
         if (class_exists('GeSHi')) {
             $geshi = new GeSHi("", 'php');
             if ($geshi) {
                 $lang = GitPHP_Util::GeshiFilenameToLanguage($blob->GetName());
                 if (empty($lang)) {
                     $lang = $geshi->get_language_name_from_extension(substr(strrchr($blob->GetName(), '.'), 1));
                 }
                 if (!empty($lang)) {
                     $geshi->enable_classes();
                     $geshi->enable_strict_mode(GESHI_MAYBE);
                     $geshi->set_source($blob->GetData());
                     $geshi->set_language($lang);
                     $geshi->set_header_type(GESHI_HEADER_PRE_TABLE);
                     $geshi->enable_line_numbers(GESHI_NORMAL_LINE_NUMBERS);
                     $geshi->set_overall_id('blobData');
                     $this->tpl->assign('geshiout', $geshi->parse_code());
                     $this->tpl->assign('geshicss', $geshi->get_stylesheet());
                     $this->tpl->assign('geshi', true);
                     return;
                 }
             }
         }
     }
     $this->tpl->assign('bloblines', $blob->GetData(true));
 }
Beispiel #20
0
 /**
  * Gets the project as a filename/url friendly slug
  *
  * @return string the slug
  */
 public function GetSlug()
 {
     $project = $this->project;
     if (substr($project, -4) == '.git') {
         $project = substr($project, 0, -4);
     }
     return GitPHP_Util::MakeSlug($project);
 }
 /**
  * Applies global config settings to a project
  *
  * @param GitPHP_Project $project project
  */
 protected function ApplyGlobalConfig($project)
 {
     if (!$project) {
         return;
     }
     if (!$this->config) {
         return;
     }
     if ($this->config->GetValue('cloneurl')) {
         $project->SetCloneUrl(GitPHP_Util::AddSlash($this->config->GetValue('cloneurl'), false) . $project->GetProject());
     }
     if ($this->config->GetValue('pushurl')) {
         $project->SetPushUrl(GitPHP_Util::AddSlash($this->config->GetValue('pushurl'), false) . $project->GetProject());
     }
     if ($this->config->GetValue('bugpattern')) {
         $project->SetBugPattern($this->config->GetValue('bugpattern'));
     }
     if ($this->config->GetValue('bugurl')) {
         $project->SetBugUrl($this->config->GetValue('bugurl'));
     }
     if ($this->config->HasKey('compat')) {
         $project->SetCompat($this->config->GetValue('compat'));
     }
     if ($this->config->HasKey('uniqueabbrev')) {
         $project->SetUniqueAbbreviation($this->config->GetValue('uniqueabbrev'));
     }
     if ($this->config->GetValue('abbreviateurl')) {
         $project->SetUniqueAbbreviation(true);
     }
 }
Beispiel #22
0
 /**
  * __construct
  *
  * Constructor
  *
  * @access public
  */
 public function __construct()
 {
     $this->dir = GitPHP_Util::AddSlash(GitPHP_Config::GetInstance()->GetValue('gittmp'));
     if (empty($this->dir)) {
         $this->dir = GitPHP_TmpDir::SystemTmpDir();
     }
     if (empty($this->dir)) {
         throw new Exception(__('No tmpdir defined'));
     }
     if (file_exists($this->dir)) {
         if (is_dir($this->dir)) {
             if (!is_writeable($this->dir)) {
                 throw new Exception(sprintf(__('Specified tmpdir %1$s is not writable'), $this->dir));
             }
         } else {
             throw new Exception(sprintf(__('Specified tmpdir %1$s is not a directory'), $this->dir));
         }
     } else {
         if (!mkdir($this->dir, 0700)) {
             throw new Exception(sprintf(__('Could not create tmpdir %1$s'), $this->dir));
         }
     }
 }
Beispiel #23
0
 /**
  * Get the base install url (without index)
  *
  * @param boolean $full true to return full url (include protocol and hostname)
  * @return string base url
  */
 public static function BaseUrl($full = false)
 {
     $baseurl = $_SERVER['SCRIPT_NAME'];
     if (substr_compare($baseurl, 'index.php', -9) === 0) {
         $baseurl = dirname($baseurl);
     }
     if ($full) {
         $baseurl = $_SERVER['HTTP_HOST'] . $baseurl;
         if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') {
             $baseurl = 'https://' . $baseurl;
         } else {
             $baseurl = 'http://' . $baseurl;
         }
     }
     if (GitPHP_Util::IsWindows()) {
         $baseurl = rtrim($baseurl, "\\");
     }
     return rtrim($baseurl, "/");
 }
 /**
  * LoadData
  *
  * Loads data for this template
  *
  * @access protected
  */
 protected function LoadData()
 {
     $commit = $this->project->GetCommit($this->params['hashbase']);
     $this->tpl->assign('commit', $commit);
     if (!isset($this->params['hash']) && isset($this->params['file'])) {
         $this->params['hash'] = $commit->PathToHash($this->params['file']);
     }
     $blob = $this->project->GetBlob($this->params['hash']);
     if (!empty($this->params['file'])) {
         $blob->SetPath($this->params['file']);
     }
     $blob->SetCommit($commit);
     $this->tpl->assign('blob', $blob);
     if (isset($this->params['plain']) && $this->params['plain']) {
         return;
     }
     $head = $this->project->GetHeadCommit();
     $this->tpl->assign('head', $head);
     $this->tpl->assign('tree', $commit->GetTree());
     if (GitPHP_Config::GetInstance()->GetValue('filemimetype', true)) {
         $mime = $blob->FileMime();
         if ($mime) {
             $mimetype = strtok($mime, '/');
             if ($mimetype == 'image') {
                 $this->tpl->assign('datatag', true);
                 $this->tpl->assign('mime', $mime);
                 $this->tpl->assign('data', base64_encode($blob->GetData()));
                 return;
             }
         }
     }
     if (GitPHP_Config::GetInstance()->GetValue('geshi', true)) {
         include_once GitPHP_Util::AddSlash(GitPHP_Config::GetInstance()->GetValue('geshiroot', 'lib/geshi/')) . "geshi.php";
         if (class_exists('GeSHi')) {
             $geshi = new GeSHi("", 'php');
             if ($geshi) {
                 $lang = $geshi->get_language_name_from_extension(substr(strrchr($blob->GetName(), '.'), 1));
                 if (!empty($lang)) {
                     $geshi->enable_classes();
                     $geshi->enable_strict_mode(GESHI_MAYBE);
                     $geshi->set_source($blob->GetData());
                     $geshi->set_language($lang);
                     $geshi->set_header_type(GESHI_HEADER_PRE_TABLE);
                     $geshi->enable_line_numbers(GESHI_NORMAL_LINE_NUMBERS);
                     $geshi->set_overall_id('blobData');
                     $this->tpl->assign('geshiout', $geshi->parse_code());
                     $this->tpl->assign('geshicss', $geshi->get_stylesheet());
                     $this->tpl->assign('geshi', true);
                     return;
                 }
             }
         }
     }
     $this->tpl->assign('bloblines', $blob->GetData(true));
 }
Beispiel #25
0
 /**
  * FileMime_File
  *
  * Get the file mimetype using file command
  *
  * @access private
  * @return string mimetype
  */
 private function FileMime_File()
 {
     if (GitPHP_Util::IsWindows()) {
         return '';
     }
     if (!$this->dataRead) {
         $this->ReadData();
     }
     if (!$this->data) {
         return '';
     }
     $descspec = array(0 => array('pipe', 'r'), 1 => array('pipe', 'w'));
     $proc = proc_open('file -b --mime -', $descspec, $pipes);
     if (is_resource($proc)) {
         fwrite($pipes[0], $this->data);
         fclose($pipes[0]);
         $mime = stream_get_contents($pipes[1]);
         fclose($pipes[1]);
         proc_close($proc);
         if ($mime && strpos($mime, '/')) {
             if (strpos($mime, ';')) {
                 $mime = strtok($mime, ';');
             }
             return $mime;
         }
     }
     return '';
 }
 /**
  * Gets whether this mimetype strategy is valid
  *
  * @return bool true if valid
  */
 public function Valid()
 {
     return !GitPHP_Util::IsWindows();
 }
Beispiel #27
0
 /**
  * GetFilename
  *
  * Gets the filename for this archive
  *
  * @access public
  * @return string filename
  */
 public function GetFilename()
 {
     if (!empty($this->fileName)) {
         return $this->fileName;
     }
     $fname = $this->GetProject()->GetSlug();
     if (!empty($this->path)) {
         $fname .= '-' . GitPHP_Util::MakeSlug($this->path);
     }
     $fname .= '.' . $this->GetExtension();
     return $fname;
 }
Beispiel #28
0
 /**
  * CreateSmarty
  *
  * Instantiates Smarty cache
  *
  * @access private
  */
 private function CreateSmarty()
 {
     if ($this->tpl) {
         return;
     }
     require_once GitPHP_Util::AddSlash(GitPHP_Config::GetInstance()->GetValue('smarty_prefix', 'lib/smarty/libs/')) . 'Smarty.class.php';
     $this->tpl = new Smarty();
     $this->tpl->addPluginsDir(GITPHP_INCLUDEDIR . 'smartyplugins');
     $this->tpl->caching = Smarty::CACHING_LIFETIME_SAVED;
     $servers = GitPHP_Config::GetInstance()->GetValue('memcache', null);
     if (isset($servers) && is_array($servers) && count($servers) > 0) {
         $this->tpl->caching_type = 'memcache';
     }
 }
Beispiel #29
0
 /**
  * GetPushUrl
  *
  * Gets the push URL for this repository, if specified
  *
  * @access public
  * @return string push url
  */
 public function GetPushUrl()
 {
     if ($this->pushUrl !== null) {
         return $this->pushUrl;
     }
     if ($this->GetConfig()->HasValue('gitphp.pushurl')) {
         return $this->GetConfig()->GetValue('gitphp.pushurl');
     }
     $pushurl = GitPHP_Util::AddSlash(GitPHP_Config::GetInstance()->GetValue('pushurl', ''), false);
     if (!empty($pushurl)) {
         $pushurl .= $this->project;
     }
     return $pushurl;
 }
Beispiel #30
0
 /**
  * DefaultBinary
  *
  * Gets the default binary for the platform
  *
  * @access public
  * @static
  * @return string binary
  */
 public static function DefaultBinary()
 {
     if (GitPHP_Util::IsWindows()) {
         // windows
         if (GitPHP_Util::Is64Bit()) {
             // match x86_64 and x64 (64 bit)
             // C:\Program Files (x86)\Git\bin\git.exe
             return 'C:\\Progra~2\\Git\\bin\\git.exe';
         } else {
             // 32 bit
             // C:\Program Files\Git\bin\git.exe
             return 'C:\\Progra~1\\Git\\bin\\git.exe';
         }
     } else {
         // *nix, just use PATH
         return 'git';
     }
 }