示例#1
0
 /**
  * Instantiates the project list
  *
  * @param GitPHP_Config $config config provider
  * @param string $file config file with git projects
  * @param boolean $legacy true if this is the legacy project config
  * @throws Exception if there was an error reading the file
  */
 public static function Instantiate($config, $file = null, $legacy = false)
 {
     $instance = null;
     $projectRoot = $config->GetValue('projectroot');
     if (!empty($file) && is_file($file) && (include $file)) {
         if (isset($git_projects)) {
             if (is_string($git_projects)) {
                 if (function_exists('simplexml_load_file') && GitPHP_ProjectListScmManager::IsSCMManager($git_projects)) {
                     $instance = new GitPHP_ProjectListScmManager($projectRoot, $git_projects);
                 } else {
                     $instance = new GitPHP_ProjectListFile($projectRoot, $git_projects);
                 }
             } else {
                 if (is_array($git_projects)) {
                     if ($legacy) {
                         $instance = new GitPHP_ProjectListArrayLegacy($projectRoot, $git_projects);
                     } else {
                         $instance = new GitPHP_ProjectListArray($projectRoot, $git_projects);
                     }
                 }
             }
         }
     }
     if (!$instance) {
         $instance = new GitPHP_ProjectListDirectory($projectRoot, $config->GetValue('exportedonly'));
     }
     $instance->SetConfig($config);
     if (isset($git_projects_settings) && !$legacy) {
         $instance->SetProjectSettings($git_projects_settings);
     }
     return $instance;
 }
示例#2
0
 /**
  * GetInstance
  *
  * Returns the singleton instance
  *
  * @access public
  * @static
  * @return mixed instance of config class
  */
 public static function GetInstance()
 {
     if (!self::$instance) {
         self::$instance = new GitPHP_Config();
     }
     return self::$instance;
 }
 /**
  * __construct
  *
  * Constructor
  *
  * @access public
  * @return Memcache object
  */
 public function __construct()
 {
     $servers = GitPHP_Config::GetInstance()->GetValue('memcache', null);
     if (!$servers || !is_array($servers) || count($servers) < 1) {
         throw new GitPHP_MessageException('No Memcache servers defined', true, 500);
     }
     if (class_exists('Memcached')) {
         $this->memcacheObj = new Memcached();
         $this->memcacheType = Smarty_CacheResource_Memcache::Memcached;
         $this->memcacheObj->addServers($servers);
     } else {
         if (class_exists('Memcache')) {
             $this->memcacheObj = new Memcache();
             $this->memcacheType = Smarty_CacheResource_Memcache::Memcache;
             foreach ($servers as $server) {
                 if (is_array($server)) {
                     $host = $server[0];
                     $port = 11211;
                     if (isset($server[1])) {
                         $port = $server[1];
                     }
                     $weight = 1;
                     if (isset($server[2])) {
                         $weight = $server[2];
                     }
                     $this->memcacheObj->addServer($host, $port, true, $weight);
                 }
             }
         } else {
             throw new GitPHP_MessageException(__('The Memcached or Memcache PHP extension is required for Memcache support'), true, 500);
         }
     }
 }
 /**
  * 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());
         }
     }
 }
 /**
  * Renders the output
  */
 public function Render()
 {
     if ($this->config->GetValue('cache') == true && $this->config->GetValue('cacheexpire') === true) {
         $this->CacheExpire();
     }
     $log = GitPHP_DebugLog::GetInstance();
     if (!$this->tpl->isCached($this->GetTemplate(), $this->GetFullCacheKey())) {
         $this->tpl->clearAllAssign();
         $log->TimerStart();
         $this->LoadCommonData();
         $log->TimerStop('Common data');
         $log->TimerStart();
         $this->LoadData();
         $log->TimerStop('Data');
     }
     if (!$this->preserveWhitespace) {
         //$this->tpl->loadFilter('output', 'trimwhitespace');
     }
     $log->TimerStart();
     $this->tpl->display($this->GetTemplate(), $this->GetFullCacheKey());
     $log->TimerStop('Render');
     $this->tpl->clearAllAssign();
     if ($this->projectList) {
         $log->Log('MemoryCache', 'Count: ' . $this->projectList->GetMemoryCache()->GetCount());
     }
     if ($log->GetEnabled()) {
         $this->tpl->assign('debuglog', $log);
         $this->tpl->display('debug.tpl');
     }
 }
 /**
  * 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);
 }
示例#7
0
 /**
  * Instantiate
  *
  * Instantiates the singleton instance
  *
  * @access private
  * @static
  * @param string $file config file with git projects
  * @param boolean $legacy true if this is the legacy project config
  * @throws Exception if there was an error reading the file
  */
 public static function Instantiate($file = null, $legacy = false)
 {
     if (self::$instance) {
         return;
     }
     if (!empty($file) && is_file($file) && (include $file)) {
         if (isset($git_projects)) {
             if (is_string($git_projects)) {
                 if (function_exists('simplexml_load_file') && GitPHP_ProjectListScmManager::IsSCMManager($git_projects)) {
                     self::$instance = new GitPHP_ProjectListScmManager($git_projects);
                 } else {
                     self::$instance = new GitPHP_ProjectListFile($git_projects);
                 }
             } else {
                 if (is_array($git_projects)) {
                     if ($legacy) {
                         self::$instance = new GitPHP_ProjectListArrayLegacy($git_projects);
                     } else {
                         self::$instance = new GitPHP_ProjectListArray($git_projects);
                     }
                 }
             }
         }
     }
     if (!self::$instance) {
         self::$instance = new GitPHP_ProjectListDirectory(GitPHP_Config::GetInstance()->GetValue('projectroot'));
     }
     if (isset($git_projects_settings) && !$legacy) {
         self::$instance->ApplySettings($git_projects_settings);
     }
 }
示例#8
0
 /**
  * __construct
  *
  * Constructor
  *
  * @access public
  */
 public function __construct()
 {
     $binary = GitPHP_Config::GetInstance()->GetValue('diffbin');
     if (empty($binary)) {
         $this->binary = GitPHP_DiffExe::DefaultBinary();
     } else {
         $this->binary = $binary;
     }
 }
示例#9
0
 /**
  * __construct
  *
  * Constructor
  *
  * @param string $binary path to git binary
  * @param mixed $project project to operate on
  * @return mixed git executable class
  */
 public function __construct($project = null)
 {
     $binary = GitPHP_Config::GetInstance()->GetValue('gitbin');
     if (empty($binary)) {
         $this->binary = GitPHP_GitExe::DefaultBinary();
     } else {
         $this->binary = $binary;
     }
     $this->SetProject($project);
 }
 /**
  * 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());
                 }
             }
         }
     }
 }
 /**
  * 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));
         }
     }
 }
示例#12
0
/**
 * 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;
}
示例#13
0
 private function restUrl()
 {
     $url = "";
     // get the gitstack config file
     $configFile = GitPHP_Config::GetInstance()->GetValue('gitstacksettings', '');
     $configArray = parse_ini_file($configFile, true, INI_SCANNER_RAW);
     // build the url
     if ($configArray['protocols']['http'] == "True") {
         // http
         $url .= "http://localhost:";
         // port
         $port = $configArray['protocols']['httpport'];
         $url .= $port;
     } else {
         // https
         $url .= "https://localhost:";
         // port
         $port = $configArray['protocols']['httpsport'];
         $url .= $port;
     }
     return $url;
 }
示例#14
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';
     }
 }
 /**
  * LoadData
  *
  * Loads data for this template
  *
  * @access protected
  */
 protected function LoadData()
 {
     $head = $this->project->GetHeadCommit();
     $this->tpl->assign('head', $head);
     $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 ($this->params['file']) {
         $blob->SetPath($this->params['file']);
     }
     $blob->SetCommit($commit);
     $this->tpl->assign('blob', $blob);
     $blame = $blob->GetBlame();
     $this->tpl->assign('blame', $blob->GetBlame());
     if (isset($this->params['js']) && $this->params['js']) {
         return;
     }
     $this->tpl->assign('tree', $commit->GetTree());
     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);
                     $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);
                         $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);
                     }
                 }
             }
         }
     }
 }
示例#16
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));
         }
     }
 }
 /**
  * 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));
 }
示例#18
0
 /**
  * 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);
     }
 }
示例#19
0
 /** 
  * FileMime_Fileinfo
  *
  * Get the file mimetype using fileinfo
  *
  * @access private
  * @return string mimetype
  */
 private function FileMime_Fileinfo()
 {
     if (!function_exists('finfo_buffer')) {
         return '';
     }
     if (!$this->dataRead) {
         $this->ReadData();
     }
     if (!$this->data) {
         return '';
     }
     $mime = '';
     $magicdb = GitPHP_Config::GetInstance()->GetValue('magicdb', null);
     if (empty($magicdb)) {
         if (GitPHP_Util::IsWindows()) {
             $magicdb = 'C:\\wamp\\php\\extras\\magic';
         } else {
             $magicdb = '/usr/share/misc/magic';
         }
     }
     $finfo = @finfo_open(FILEINFO_MIME, $magicdb);
     if ($finfo) {
         $mime = finfo_buffer($finfo, $this->data, FILEINFO_MIME);
         if ($mime && strpos($mime, '/')) {
             if (strpos($mime, ';')) {
                 $mime = strtok($mime, ';');
             }
         }
         finfo_close($finfo);
     }
     return $mime;
 }
 /**
  * AddProject
  *
  * Add project to collection
  *
  * @access private
  */
 private function AddProject($projectPath)
 {
     try {
         $proj = new GitPHP_Project($this->projectDir, $projectPath);
         $category = trim(dirname($projectPath));
         if (!(empty($category) || strpos($category, '.') === 0)) {
             $proj->SetCategory($category);
         }
         if (!GitPHP_Config::GetInstance()->GetValue('exportedonly', false) || $proj->GetDaemonEnabled()) {
             $this->projects[$projectPath] = $proj;
         }
     } catch (Exception $e) {
         GitPHP_Log::GetInstance()->Log($e->getMessage());
     }
 }
 /**
  * Render
  *
  * Render this controller
  *
  * @access public
  */
 public function Render()
 {
     $this->LoadData();
     $cache = GitPHP_Config::GetInstance()->GetValue('cache', false);
     $cachehandle = false;
     $cachefile = '';
     if ($cache && is_dir(GITPHP_CACHE)) {
         $key = ($this->archive->GetObject() ? $this->archive->GetObject()->GetHash() : '') . '|' . (isset($this->params['path']) ? $this->params['path'] : '') . '|' . (isset($this->params['prefix']) ? $this->params['prefix'] : '');
         $cachefile = sha1($key) . '-' . $this->archive->GetFilename();
         $cachedfilepath = GITPHP_CACHE . $cachefile;
         if (file_exists($cachedfilepath)) {
             // read cached file
             $cachehandle = fopen($cachedfilepath, 'rb');
             if ($cachehandle) {
                 while (!feof($cachehandle)) {
                     print fread($cachehandle, 1048576);
                     flush();
                 }
                 fclose($cachehandle);
                 return;
             }
         }
     }
     if ($this->archive->Open()) {
         $tmpcachefile = '';
         if ($cache && !empty($cachefile)) {
             // write cached file too
             $pid = 0;
             if (function_exists('posix_getpid')) {
                 $pid = posix_getpid();
             } else {
                 $pid = rand();
             }
             $tmpcachefile = 'tmp-' . $pid . '-' . $cachefile;
             $cachehandle = fopen(GITPHP_CACHE . $tmpcachefile, 'wb');
         }
         while (($data = $this->archive->Read()) !== false) {
             print $data;
             flush();
             if ($cache && $cachehandle) {
                 fwrite($cachehandle, $data);
             }
         }
         $this->archive->Close();
         if ($cachehandle) {
             fclose($cachehandle);
             sleep(1);
             rename(GITPHP_CACHE . $tmpcachefile, GITPHP_CACHE . $cachefile);
         }
     }
 }
示例#22
0
    $auth->authenticate();
    /*
     * Project list
     */
    if (file_exists(GITPHP_CONFIGDIR . 'projects.conf.php')) {
        GitPHP_ProjectList::Instantiate(GITPHP_CONFIGDIR . 'projects.conf.php', false);
    } else {
        GitPHP_ProjectList::Instantiate(GITPHP_CONFIGDIR . 'gitphp.conf.php', true);
    }
    $controller = GitPHP_Controller::GetController(isset($_GET['a']) ? $_GET['a'] : null);
    if ($controller) {
        $controller->RenderHeaders();
        $controller->Render();
    }
} catch (Exception $e) {
    if (GitPHP_Config::GetInstance()->GetValue('debug', false)) {
        throw $e;
    }
    if (!GitPHP_Resource::Instantiated()) {
        /*
         * In case an error was thrown before instantiating
         * the resource manager
         */
        GitPHP_Resource::Instantiate('en_US');
    }
    require_once GITPHP_CONTROLLERDIR . 'Controller_Message.class.php';
    $controller = new GitPHP_Controller_Message();
    $controller->SetParam('message', $e->getMessage());
    if ($e instanceof GitPHP_MessageException) {
        $controller->SetParam('error', $e->Error);
        $controller->SetParam('statuscode', $e->StatusCode);
示例#23
0
 /**
  * __construct
  *
  * Constructor
  *
  * @access public
  * @return Log object
  */
 public function __construct()
 {
     $this->startTime = microtime(true);
     $this->startMem = memory_get_usage();
     $this->enabled = GitPHP_Config::GetInstance()->GetValue('debug', false);
     $this->benchmark = GitPHP_Config::GetInstance()->GetValue('benchmark', false);
 }
 /**
  * ReadQuery
  *
  * Read query into parameters
  *
  * @access protected
  */
 protected function ReadQuery()
 {
     if (!isset($this->params['searchtype'])) {
         $this->params['searchtype'] = GITPHP_SEARCH_COMMIT;
     }
     if ($this->params['searchtype'] == GITPHP_SEARCH_FILE) {
         if (!GitPHP_Config::GetInstance()->GetValue('filesearch', true)) {
             throw new GitPHP_MessageException(__('File search has been disabled'), true);
         }
     }
     if (!isset($this->params['search']) || strlen($this->params['search']) < 2) {
         throw new GitPHP_MessageException(sprintf(__n('You must enter search text of at least %1$d character', 'You must enter search text of at least %1$d characters', 2), 2), true);
     }
     if (isset($_GET['h'])) {
         $this->params['hash'] = $_GET['h'];
     } else {
         $this->params['hash'] = 'HEAD';
     }
     if (isset($_GET['pg'])) {
         $this->params['page'] = $_GET['pg'];
     } else {
         $this->params['page'] = 0;
     }
 }
示例#25
0
 /**
  * Render
  *
  * Renders the output
  *
  * @access public
  */
 public function Render()
 {
     if (GitPHP_Config::GetInstance()->GetValue('cache', false) == true && GitPHP_Config::GetInstance()->GetValue('cacheexpire', true) === true) {
         $this->CacheExpire();
     }
     if (!$this->tpl->isCached($this->GetTemplate(), $this->GetFullCacheKey())) {
         $this->tpl->clearAllAssign();
         $this->LoadCommonData();
         $this->LoadData();
     }
     if (!$this->preserveWhitespace) {
         $this->tpl->loadFilter('output', 'trimwhitespace');
     }
     $this->tpl->display($this->GetTemplate(), $this->GetFullCacheKey());
 }
示例#26
0
 /**
  * Read
  *
  * Read a chunk of the archive data
  *
  * @access public
  * @param int $size size of data to read
  * @return string archive data
  */
 public function Read($size = 1048576)
 {
     if (!$this->handle) {
         return false;
     }
     if (feof($this->handle)) {
         return false;
     }
     $data = fread($this->handle, $size);
     if ($this->format == GITPHP_COMPRESS_BZ2) {
         $data = bzcompress($data, GitPHP_Config::GetInstance()->GetValue('compresslevel', 4));
     }
     return $data;
 }
示例#27
0
 /**
  * AbbreviateHashRaw
  *
  * Abbreviates a hash using raw git objects
  *
  * @param string $hash hash to abbreviate
  * @return string abbreviated hash
  */
 private function AbbreviateHashRaw($hash)
 {
     $abbrevLen = GITPHP_ABBREV_HASH_MIN;
     if ($this->GetConfig()->HasValue('core.abbrev')) {
         $abbrevLen = max(4, min($this->GetConfig()->GetValue('core.abbrev'), 40));
     }
     $prefix = substr($hash, 0, $abbrevLen);
     if (!GitPHP_Config::GetInstance()->GetValue('uniqueabbrev', false)) {
         return $prefix;
     }
     $hashMap = array();
     $matches = $this->FindHashObjects($prefix);
     foreach ($matches as $matchingHash) {
         $hashMap[$matchingHash] = 1;
     }
     if (!$this->packsRead) {
         $this->ReadPacks();
     }
     foreach ($this->packs as $pack) {
         $matches = $pack->FindHashes($prefix);
         foreach ($matches as $matchingHash) {
             $hashMap[$matchingHash] = 1;
         }
     }
     if (count($hashMap) == 0) {
         return $hash;
     }
     if (count($hashMap) == 1) {
         return $prefix;
     }
     for ($len = $abbrevLen + 1; $len < 40; $len++) {
         $prefix = substr($hash, 0, $len);
         foreach ($hashMap as $matchingHash => $val) {
             if (substr_compare($matchingHash, $prefix, 0, $len) !== 0) {
                 unset($hashMap[$matchingHash]);
             }
         }
         if (count($hashMap) == 1) {
             return $prefix;
         }
     }
     return $hash;
 }
示例#28
0
 /**
  * SupportedLocales
  *
  * Gets the list of supported locales and their languages
  *
  * @access public
  * @static
  * @return array list of locales mapped to languages
  */
 public static function SupportedLocales()
 {
     $locales = array();
     $locales['en_US'] = GitPHP_Resource::LocaleToName('en_US');
     if ($dh = opendir(GITPHP_LOCALEDIR)) {
         while (($file = readdir($dh)) !== false) {
             $fullPath = GITPHP_LOCALEDIR . '/' . $file;
             if (strpos($file, '.') !== 0 && is_dir($fullPath) && is_file($fullPath . '/gitphp.mo')) {
                 if ($file == 'zz_Debug') {
                     $conf = GitPHP_Config::GetInstance();
                     if ($conf) {
                         if (!$conf->GetValue('debug', false)) {
                             continue;
                         }
                     }
                 }
                 $locales[$file] = GitPHP_Resource::LocaleToName($file);
             }
         }
     }
     return $locales;
 }