1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Admin Page Framework Loader |
4
|
|
|
* |
5
|
|
|
* Demonstrates the usage of Admin Page Framework. |
6
|
|
|
* |
7
|
|
|
* http://admin-page-framework.michaeluno.jp/ |
8
|
|
|
* Copyright (c) 2013-2022, Michael Uno; Licensed GPLv2 |
9
|
|
|
* |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* Adds a tab of the set page to the loader plugin. |
14
|
|
|
* |
15
|
|
|
* @since 3.5.0 |
16
|
|
|
* @since 3.5.3 Extends `AdminPageFrameworkLoader_AdminPage_Tab_ReadMeBase`. |
17
|
|
|
* @extends AdminPageFrameworkLoader_AdminPage_Tab_ReadMeBase |
18
|
|
|
*/ |
19
|
|
|
class AdminPageFrameworkLoader_AdminPageWelcome_Welcome extends AdminPageFrameworkLoader_AdminPage_Tab_ReadMeBase { |
20
|
|
|
|
21
|
|
|
public function replyToLoadTab( $oFactory ) { |
22
|
|
|
|
23
|
|
|
add_action( "style_{$this->sPageSlug}_{$this->sTabSlug}", array( $this, 'replyToAddInlineCSS' ) ); |
24
|
|
|
|
25
|
|
|
$oFactory->addSettingSections( |
26
|
|
|
$this->sPageSlug, // the target page slug |
27
|
|
|
array( |
28
|
|
|
'tab_slug' => $this->sTabSlug, |
29
|
|
|
'section_id' => $this->sTabSlug, |
30
|
|
|
'section_tab_slug' => 'welcome', |
31
|
|
|
'title' => __( "What's New", 'admin-page-framework-loader' ), // ' |
32
|
|
|
'content' => $this->_getReadmeContents( |
33
|
|
|
AdminPageFrameworkLoader_Registry::$sDirPath . '/asset/text/about.txt', |
34
|
|
|
'', // TOC title |
35
|
|
|
array( 'New Features' ) // section |
36
|
|
|
) |
37
|
|
|
), |
38
|
|
|
array( |
39
|
|
|
'tab_slug' => $this->sTabSlug, |
40
|
|
|
'section_tab_slug' => $this->sTabSlug, |
41
|
|
|
'section_id' => 'getting_started', |
42
|
|
|
'title' => __( "Getting Started", 'admin-page-framework-loader' ), // ' |
43
|
|
|
'content' => $this->_getReadmeContents( |
44
|
|
|
AdminPageFrameworkLoader_Registry::$sDirPath . '/asset/text/about.txt', |
45
|
|
|
"<h3>" . __( 'Contents', 'admin-page-framework-loader' ) . "</h3>", |
46
|
|
|
array( 'Getting Started', 'Tutorials' ) |
47
|
|
|
), |
48
|
|
|
), |
49
|
|
|
array( |
50
|
|
|
'tab_slug' => $this->sTabSlug, |
51
|
|
|
'section_tab_slug' => $this->sTabSlug, |
52
|
|
|
'section_id' => 'change_log', |
53
|
|
|
'title' => __( "Change Log", 'admin-page-framework-loader' ), // ' |
54
|
|
|
'content' => $this->_getChangeLog(), |
|
|
|
|
55
|
|
|
) |
56
|
|
|
); |
57
|
|
|
|
58
|
|
|
new GitHubCustomFieldType( 'admin_page_framework' ); |
59
|
|
|
|
60
|
|
|
$oFactory->addSettingSections( |
61
|
|
|
$this->sPageSlug, // the target page slug |
62
|
|
|
array( |
63
|
|
|
'section_id' => 'credit', |
64
|
|
|
'tab_slug' => $this->sTabSlug, |
65
|
|
|
'section_tab_slug' => $this->sTabSlug, |
66
|
|
|
'title' => __( 'Credit', 'admin-page-framework-loader' ), |
67
|
|
|
// 'description' => __( 'Admin Page Framework uses GitHub.', 'admin-page-framework-loader' ), |
68
|
|
|
) |
69
|
|
|
); |
70
|
|
|
$oFactory->addSettingFields( |
71
|
|
|
'credit', // the target section id |
72
|
|
|
array( |
73
|
|
|
'field_id' => '_message', |
74
|
|
|
'type' => '_message', |
75
|
|
|
'show_title_column' => false, |
76
|
|
|
'content' => "<p class='about-description'>" |
77
|
|
|
. __( 'Admin Page Framework is created by the following contributors.', 'admin-page-framework-loader' ) |
78
|
|
|
. "</p>" |
79
|
|
|
), |
80
|
|
|
array( |
81
|
|
|
'field_id' => '_contributors', |
82
|
|
|
'type' => '_contributors', |
83
|
|
|
'show_title_column' => false, |
84
|
|
|
'content' => $this->_getContributors(), |
85
|
|
|
), |
86
|
|
|
array( |
87
|
|
|
'field_id' => 'github_star', |
88
|
|
|
'type' => 'github', |
89
|
|
|
'user_name' => 'michaeluno', // the GitHub account ID |
90
|
|
|
'button_type' => 'star', // either of the followings: follow, star, watch, fork, issue |
91
|
|
|
'count' => false, |
92
|
|
|
'repository' => 'admin-page-framework', |
93
|
|
|
'size' => 'mega', |
94
|
|
|
'attributes' => array( |
95
|
|
|
'data-text' => ' ' . AdminPageFramework_Registry::NAME . ' ' . AdminPageFramework_Registry::getVersion() . ' ', |
96
|
|
|
// 'data-icon' => 'octicon-mark-github', |
97
|
|
|
), |
98
|
|
|
'description' => __( 'Star the repository and get Involved!', 'admin-page-framework-loader' ), |
99
|
|
|
'show_title_column' => false, |
100
|
|
|
) |
101
|
|
|
); |
102
|
|
|
|
103
|
|
|
} |
104
|
|
|
/** |
105
|
|
|
* |
106
|
|
|
* @since 3.5.0 |
107
|
|
|
* @return void |
108
|
|
|
*/ |
109
|
|
|
public function replyToAddInlineCSS( $sCSSRules ) { |
110
|
|
|
return $sCSSRules |
|
|
|
|
111
|
|
|
. ".changelog h4 { |
112
|
|
|
/* margin: 0; */ |
113
|
|
|
} |
114
|
|
|
.form-table td p { |
115
|
|
|
margin: 1em 0; |
116
|
|
|
} |
117
|
|
|
.admin-page-framework-section-tab h4 { |
118
|
|
|
padding: 10px 16px 12px; |
119
|
|
|
font-size: 1.6em; |
120
|
|
|
font-weight: 400; |
121
|
|
|
} |
122
|
|
|
.admin-page-framework-content .toc ul li { |
123
|
|
|
margin-left: 2em; |
124
|
|
|
} |
125
|
|
|
.admin-page-framework-content ul li { |
126
|
|
|
margin-left: 0; |
127
|
|
|
}"; |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
/** |
131
|
|
|
* Retrieves contents of a change log section of a readme file. |
132
|
|
|
* @since 3.6.1 |
133
|
|
|
* @return void |
134
|
|
|
*/ |
135
|
|
|
private function _getChangeLog( $sSection='Changelog' ) { |
136
|
|
|
|
137
|
|
|
$_aReplacements = array( |
138
|
|
|
'%PLUGIN_DIR_URL%' => AdminPageFrameworkLoader_Registry::getPluginURL(), |
139
|
|
|
'%WP_ADMIN_URL%' => admin_url(), |
140
|
|
|
); |
141
|
|
|
$_oWPReadmeParser = new AdminPageFramework_WPReadmeParser( |
142
|
|
|
AdminPageFrameworkLoader_Registry::$sDirPath . '/readme.txt', |
143
|
|
|
$_aReplacements |
144
|
|
|
); |
145
|
|
|
$_sChangeLog = $_oWPReadmeParser->getSection( $sSection ); |
146
|
|
|
$_oWPReadmeParser = new AdminPageFramework_WPReadmeParser( |
147
|
|
|
AdminPageFrameworkLoader_Registry::$sDirPath . '/changelog.md', |
148
|
|
|
$_aReplacements |
149
|
|
|
); |
150
|
|
|
$_sChangeLog .= $_oWPReadmeParser->getSection( $sSection ); |
151
|
|
|
|
152
|
|
|
$_sChangeLog = $_sChangeLog |
153
|
|
|
? $_sChangeLog |
154
|
|
|
: '<p>' . __( 'No valid changlog was found.', 'admin-page-framework-loader' ) . '</p>'; |
155
|
|
|
return "<div class='changelog'>" |
|
|
|
|
156
|
|
|
. $_sChangeLog |
157
|
|
|
. "</div>"; |
158
|
|
|
|
159
|
|
|
} |
160
|
|
|
|
161
|
|
|
// public function replyToDoTab() { |
162
|
|
|
|
163
|
|
|
// echo $this->_getReadmeContents( |
164
|
|
|
// AdminPageFrameworkLoader_Registry::$sDirPath . '/asset/text/about.txt', |
165
|
|
|
// '', // TOC title |
166
|
|
|
// array( 'New Features' ) // section |
167
|
|
|
// ); |
168
|
|
|
|
169
|
|
|
// } |
170
|
|
|
|
171
|
|
|
|
172
|
|
|
/** |
173
|
|
|
* Render Contributors List |
174
|
|
|
* |
175
|
|
|
* @since 3.5.0 |
176
|
|
|
* @return string An HTML formatted list of all the contributors of Admin Page Framework. |
177
|
|
|
*/ |
178
|
|
|
private function _getContributors() { |
179
|
|
|
|
180
|
|
|
$_aContributors = $this->_getContributorsFromGitHub( 'https://api.github.com/repos/michaeluno/admin-page-framework' ); |
181
|
|
|
if ( empty( $_aContributors ) ) { |
182
|
|
|
return ''; |
183
|
|
|
} |
184
|
|
|
|
185
|
|
|
$_aOutput = array(); |
186
|
|
|
foreach ( $_aContributors as $_oContributor ) { |
187
|
|
|
$_aOutput[] = '<li class="wp-person">'; |
188
|
|
|
$_aOutput[] .= sprintf( '<a href="%s" title="%s">', |
189
|
|
|
esc_url( 'https://github.com/' . $_oContributor->login ), |
190
|
|
|
esc_html( sprintf( __( 'View %s', 'admin-page-framework-loader' ), $_oContributor->login ) ) |
191
|
|
|
); |
192
|
|
|
$_aOutput[] .= sprintf( '<img src="%s" width="64" height="64" class="gravatar" alt="%s" />', esc_url( $_oContributor->avatar_url ), esc_html( $_oContributor->login ) ); |
193
|
|
|
$_aOutput[] .= '</a>'; |
194
|
|
|
$_aOutput[] .= sprintf( '<a class="web" href="%s">%s</a>', esc_url( 'https://github.com/' . $_oContributor->login ), esc_html( $_oContributor->login ) ); |
195
|
|
|
$_aOutput[] .= '</a>'; |
196
|
|
|
$_aOutput[] .= '</li>'; |
197
|
|
|
} |
198
|
|
|
|
199
|
|
|
return '<ul class="wp-people-group">' |
200
|
|
|
. implode( PHP_EOL, $_aOutput ) |
201
|
|
|
. '</ul>'; |
202
|
|
|
|
203
|
|
|
} |
204
|
|
|
|
205
|
|
|
/** |
206
|
|
|
* Retrieve a list of contributors from GitHub. |
207
|
|
|
* |
208
|
|
|
* @access private |
209
|
|
|
* @since 3.5.0 |
210
|
|
|
* @return array A list of contributors |
211
|
|
|
*/ |
212
|
|
|
private function _getContributorsFromGitHub( $sRepositoryURL ) { |
213
|
|
|
|
214
|
|
|
$_aContributors = get_transient( 'apfl_contributors' ); |
215
|
|
|
|
216
|
|
|
if ( false !== $_aContributors ) { |
217
|
|
|
return $_aContributors; |
218
|
|
|
} |
219
|
|
|
|
220
|
|
|
$_mResponse = wp_remote_get( $sRepositoryURL . '/contributors', array( 'sslverify' => false ) ); |
221
|
|
|
|
222
|
|
|
if ( is_wp_error( $_mResponse ) || 200 != wp_remote_retrieve_response_code( $_mResponse ) ) { |
223
|
|
|
return array(); |
224
|
|
|
} |
225
|
|
|
|
226
|
|
|
$_aContributors = json_decode( wp_remote_retrieve_body( $_mResponse ) ); |
227
|
|
|
|
228
|
|
|
if ( ! is_array( $_aContributors ) ) |
229
|
|
|
return array(); |
230
|
|
|
|
231
|
|
|
set_transient( 'apfl_contributors', $_aContributors, 3600 ); |
232
|
|
|
|
233
|
|
|
return $_aContributors; |
234
|
|
|
} |
235
|
|
|
|
236
|
|
|
} |
237
|
|
|
|
238
|
|
|
|
This check looks for function or method calls that always return null and whose return value is used.
The method
getObject()
can return nothing but null, so it makes no sense to use the return value.The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.