This repository has been archived by the owner on Jul 16, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Themes.php
83 lines (74 loc) · 2.21 KB
/
Themes.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
<?php
require __DIR__ . '/Doc.php';
/**
* Base themes for your application.
* ->listThemes() List suggested themes.
* ->downloadTheme() Clone git repository.
*/
class Themes extends Doc
{
private $github = [
'BlackrockDigital' => [
'exclude' => [
'BlackrockDigital/startbootstrap',
'BlackrockDigital/startbootstrap-clean-blog-jekyll',
'BlackrockDigital/startbootstrap-freelancer-jekyll',
]
],
/*
'myAccount' => [
'exclude' => [
'myAccount/repo',
],
],
'myAccount' => [
'include' => [
'myAccount/repo',
],
],
'myAccount',
*/
];
function __construct()
{
$this->config();
}
/**
* List suggested themes.
*
* @return Array [user/repository] => description
*/
public function listThemes()
{
$themes = [];
foreach ($this->github as $user => $repos) {
$curl = new Curl\Curl;
$curl->get('https://api.github.com/users/' . $user . '/repos?per_page=100');
$curl->close();
if ($curl->error)
return 'Curl error: ' . $this->curl->error_code;
foreach (json_decode($curl->response, true) as $theme)
if (
(isset($repos['exclude']) && !in_array($theme['full_name'], $repos['exclude']))
||
(isset($repos['include']) && in_array($theme['full_name'], $repos['include']))
||
(!isset($repos['exclude']) && !isset($repos['include']))
)
$themes[$theme['full_name']] = $theme['description'];
}
return $themes;
}
/**
* Download any Github repository to the themes folder.
*
* @param String $author Github author
* @param String $repo Github repository
* @param String $branch Repository branch
*/
public function downloadTheme($author, $repo, $branch = 'master')
{
$git = new GitDownload($this->config['source_themes']);
$git->clone($author, $repo, 'master');
}
}