diff --git a/modulekit.php b/modulekit.php index 52af002a..168eb2e7 100644 --- a/modulekit.php +++ b/modulekit.php @@ -16,6 +16,7 @@ $include = array( 'src/ip-location.php', 'src/wikipedia.php', 'src/ImageLoader.php', + 'src/RepositoryBase.php', 'src/RepositoryDir.php', 'src/RepositoryGit.php', 'src/repositories.php', diff --git a/src/RepositoryBase.php b/src/RepositoryBase.php new file mode 100644 index 00000000..1ec18876 --- /dev/null +++ b/src/RepositoryBase.php @@ -0,0 +1,32 @@ +def = $def; + $this->path = $def['path']; + } + + function timestamp () { + return null; + } + + function info () { + $ret = array(); + + foreach (array('name') as $k) { + if (array_key_exists($k, $this->def)) { + $ret[$k] = $this->def[$k]; + } + } + + $ret['timestamp'] = Date(DATE_ISO8601, $this->timestamp()); + + return $ret; + } + + function data () { + $data = array( + 'categories' => array(), + 'timestamp' => Date(DATE_ISO8601, $this->timestamp()), + ); + } +} diff --git a/src/RepositoryDir.php b/src/RepositoryDir.php index 1e436718..afda1937 100644 --- a/src/RepositoryDir.php +++ b/src/RepositoryDir.php @@ -1,24 +1,5 @@ def = $def; - $this->path = $def['path']; - } - - function info () { - $ret = array(); - - foreach (array('name') as $k) { - if (array_key_exists($k, $this->def)) { - $ret[$k] = $this->def[$k]; - } - } - - $ret['timestamp'] = Date(DATE_ISO8601, $this->timestamp()); - - return $ret; - } - +class RepositoryDir extends RepositoryBase { function timestamp () { $ts = 0; $d = opendir($this->path); @@ -34,10 +15,7 @@ class RepositoryDir { } function data () { - $data = array( - 'categories' => array(), - 'timestamp' => Date(DATE_ISO8601, $this->timestamp()), - ); + $data = parent::data(); $d = opendir($this->path); while ($f = readdir($d)) { diff --git a/src/RepositoryGit.php b/src/RepositoryGit.php index 10f67eac..3d4f0f70 100644 --- a/src/RepositoryGit.php +++ b/src/RepositoryGit.php @@ -1,24 +1,5 @@ def = $def; - $this->path = $def['path']; - } - - function info () { - $ret = array(); - - foreach (array('name') as $k) { - if (array_key_exists($k, $this->def)) { - $ret[$k] = $this->def[$k]; - } - } - - $ret['timestamp'] = Date(DATE_ISO8601, $this->timestamp()); - - return $ret; - } - +class RepositoryGit extends RepositoryBase { function timestamp () { $ts = (int)shell_exec("cd " . escapeShellArg($this->path) . "; git log -1 --pretty=format:%ct"); @@ -26,10 +7,7 @@ class RepositoryGit { } function data () { - $data = array( - 'categories' => array(), - 'timestamp' => Date(DATE_ISO8601, $this->timestamp()), - ); + $data = parent::data(); $d = popen("cd " . escapeShellArg($this->path) . "; git ls-tree HEAD", "r"); while ($r = fgets($d)) {