-
Notifications
You must be signed in to change notification settings - Fork 22
/
git-it-write.php
93 lines (68 loc) · 2.42 KB
/
git-it-write.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
84
85
86
87
88
89
90
91
92
93
<?php
/*
Plugin Name: Git it Write
Plugin URI: https://www.aakashweb.com/wordpress-plugins/git-it-write/
Description: Publish markdown files present in a Github repository as posts to WordPress automatically
Author: Aakash Chakravarthy
Author URI: https://www.aakashweb.com/
Version: 2.0
*/
define( 'GIW_VERSION', '2.0' );
define( 'GIW_PATH', plugin_dir_path( __FILE__ ) ); // All have trailing slash
define( 'GIW_ADMIN_URL', trailingslashit( plugin_dir_url( __FILE__ ) . 'admin' ) );
final class Git_It_Write{
public static function init(){
self::includes();
}
public static function includes(){
require __DIR__ . '/vendor/autoload.php';
require_once( GIW_PATH . 'includes/utilities.php' );
require_once( GIW_PATH . 'includes/repository.php' );
require_once( GIW_PATH . 'includes/publisher.php' );
require_once( GIW_PATH . 'includes/publish-handler.php' );
require_once( GIW_PATH . 'includes/parsedown.php' );
require_once( GIW_PATH . 'includes/webhook.php' );
require_once( GIW_PATH . 'includes/shortcodes.php' );
require_once( GIW_PATH . 'admin/admin.php' );
}
public static function default_config(){
return array(
'username' => '',
'repository' => '',
'folder' => '',
'branch' => 'master',
'post_type' => '',
'post_author' => 1,
'content_template' => '%%content%%',
'last_publish' => 0
);
}
public static function default_general_settings(){
return array(
'webhook_secret' => '',
'github_username' => '',
'github_access_token' => ''
);
}
public static function allowed_file_types(){
return array(
'md'
);
}
public static function all_repositories(){
$repos_raw = get_option( 'giw_repositories', array( array() ) );
$repos = array();
$default_config = self::default_config();
foreach( $repos_raw as $id => $config ){
array_push( $repos, wp_parse_args( $config, $default_config ) );
}
return $repos;
}
public static function general_settings(){
$settings = get_option( 'giw_general_settings', array() );
$default_settings = self::default_general_settings();
return wp_parse_args( $settings, $default_settings );
}
}
Git_It_Write::init();
?>