Пример #1
0
 /**
  * If this remote is a local paste, then we'll get the repository object
  * returned
  *
  * @return Repository Repository object or NULL
  */
 public function getLocalRepository()
 {
     if (!file_exists($this->arConfig['url'] . '/config')) {
         return null;
     }
     $dir = basename($this->arConfig['url']);
     if (substr($dir, -4) != '.git') {
         //phorks are bare repositories "123.git"
         return null;
     }
     $repo = new Repository();
     $repo->loadById(substr($dir, 0, -4));
     return $repo;
 }
Пример #2
0
 /**
  * Search for a given term and return repositories that contain it
  * in their description, file names or file content
  *
  * @param string  $term    Search term
  * @param integer $page    Page of search results, starting with 0
  * @param integer $perPage Number of results per page
  *
  * @return Search_Result Search result object
  */
 public function search($term, $page = 0, $perPage = 10)
 {
     $r = new Database_Adapter_Elasticsearch_HTTPRequest($this->searchInstance . 'repo/_search', \HTTP_Request2::METHOD_GET);
     $r->setBody(json_encode((object) array('from' => $page * $perPage, 'size' => $perPage, 'query' => (object) array('bool' => (object) array('should' => array((object) array('query_string' => (object) array('query' => $term, 'default_operator' => 'AND')), (object) array('has_child' => (object) array('type' => 'file', 'query' => (object) array('query_string' => (object) array('query' => $term, 'default_operator' => 'AND'))))))))));
     $httpRes = $r->send();
     $jRes = json_decode($httpRes->getBody());
     if (isset($jRes->error)) {
         throw new Exception('Search exception: ' . $jRes->error, $jRes->status);
     }
     $sres = new Search_Result();
     $sres->results = $jRes->hits->total;
     $sres->page = $page;
     $sres->perPage = $perPage;
     foreach ($jRes->hits->hits as $hit) {
         $r = new Repository();
         //FIXME: error handling. what about deleted repos?
         $r->loadById($hit->_source->id);
         $sres->repos[] = $r;
     }
     return $sres;
 }
Пример #3
0
 /**
  * Get a list of repository objects
  *
  * @param integer $page    Page number, beginning with 0, or "last"
  * @param integer $perPage Number of repositories per page
  *
  * @return array Array of Repositories first, number of repositories second
  */
 public function getList($page = 0, $perPage = 10)
 {
     chdir($this->gitDir);
     $dirs = glob('*.git', GLOB_ONLYDIR);
     sort($dirs, SORT_NUMERIC);
     if ($page === 'last') {
         //always show the last 10
         $page = intval(count($dirs) / $perPage);
         $start = count($dirs) - $perPage;
         if ($start < 0) {
             $start = 0;
         }
         $some = array_slice($dirs, $start, $perPage);
     } else {
         $some = array_slice($dirs, $page * $perPage, $perPage);
     }
     $repos = array();
     foreach ($some as $oneDir) {
         $r = new Repository();
         $r->loadById(substr($oneDir, 0, -4));
         $repos[] = $r;
     }
     return array($repos, count($dirs), $page);
 }
Пример #4
0
 /**
  * Convert an array of git urls to local URLs if possible and serialize them
  * into a simple array.
  *
  * @param array $arGitUrls Array of array of urls. Main key is the title of
  *                         the URL array.
  *
  * @return array Key is the git clone URL, value the title of the remote
  */
 protected function localizeGitUrls($arGitUrls)
 {
     $pub = $pri = null;
     if (isset($GLOBALS['phorkie']['cfg']['git']['public'])) {
         $pub = $GLOBALS['phorkie']['cfg']['git']['public'];
     }
     if (isset($GLOBALS['phorkie']['cfg']['git']['private'])) {
         $pri = $GLOBALS['phorkie']['cfg']['git']['private'];
     }
     $arRemoteCloneUrls = array();
     foreach ($arGitUrls as $remoteTitle => $arUrls) {
         foreach ($arUrls as $remoteCloneUrl) {
             if ($pub !== null && substr($remoteCloneUrl, 0, strlen($pub)) == $pub && substr($remoteCloneUrl, -4) == '.git') {
                 $id = substr($remoteCloneUrl, strlen($pub), -4);
                 $repo = new Repository();
                 try {
                     $repo->loadById($id);
                     $arRemoteCloneUrls[$repo->gitDir] = $remoteTitle;
                 } catch (Exception $e) {
                 }
             } else {
                 if ($pri !== null && substr($remoteCloneUrl, 0, strlen($pri)) == $pri && substr($remoteCloneUrl, -4) == '.git') {
                     $id = substr($remoteCloneUrl, strlen($pri), -4);
                     $repo = new Repository();
                     try {
                         $repo->loadById($id);
                         $arRemoteCloneUrls[$repo->gitDir] = $remoteTitle;
                     } catch (Exception $e) {
                     }
                 } else {
                     $arRemoteCloneUrls[$remoteCloneUrl] = $remoteTitle;
                 }
             }
         }
     }
     return $arRemoteCloneUrls;
 }
Пример #5
0
    }
}
if (!isset($_GET['maxheight'])) {
    $maxHeight = 900;
} else {
    $maxHeight = (int) $_GET['maxheight'];
    if ($maxHeight <= 100) {
        header('HTTP/1.0 400 Bad Request');
        echo "maxheight parameter too small\n";
        exit(1);
    }
}
$parts = explode('/', $_GET['url']);
$id = end($parts);
$repo = new Repository();
$repo->loadById($id);
if ($format == 'json') {
    $data = new \stdClass();
} else {
    $data = new \SimpleXMLElement('<?xml version="1.0" encoding="utf-8" standalone="yes"?>' . '<oembed/>');
}
$data->type = 'rich';
$data->version = '1.0';
$data->provider_name = 'phorkie';
$data->provider_url = Tools::fullUrl();
$data->title = $repo->getTitle();
$author = $repo->getOwner();
$data->author_name = $author['name'];
$data->cache_age = 86400;
$data->width = $maxWidth;
$data->height = $maxHeight;