-
Notifications
You must be signed in to change notification settings - Fork 8
/
single-software.php
350 lines (253 loc) · 12.5 KB
/
single-software.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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
<?php
/**
* Details of a specific software package
*/
if ( ! class_exists( 'bit51_software_page' ) ) {
class bit51_software_page {
private
$spage,
$spages,
$sfaq;
function __construct() {
global $software_pages, $post;
$this->spages = $software_pages;
$this->spage = get_query_var( 'spage' );
$this->sfaq = get_field( 'faq_question' );
//process subpages if necessary
if ( ! empty( $this->spage ) ) {
switch( $this->spage ) {
case 'changelog':
if ( strlen( get_post_meta( $post->ID, '_bit51_changelog', true ) ) <= 1 ) {
if ( strlen( get_post_meta( $post->ID, '_bit51_changelog_url', true ) ) > 1 ) {
wp_redirect( get_post_meta( $post->ID, '_bit51_changelog_url', true ), 301 );
} else {
$this->bit51_notfound();
}
}
break;
case 'donate':
if ( strlen( get_post_meta( $post->ID, '_bit51_donate', true ) ) <= 1 ) {
if ( strlen( get_post_meta( $post->ID, '_bit51_donate_url', true ) ) > 1 ) {
wp_redirect( get_post_meta( $post->ID, '_bit51_donate_url', true ), 301 );
} else {
$this->bit51_notfound();
}
}
break;
case 'faq':
if ( ! is_array( $this->sfaq ) || sizeof( $this->sfaq ) < 1 ) {
$this->bit51_notfound();
}
break;
case 'support':
if ( strlen( get_post_meta( $post->ID, '_bit51_support', true ) ) <= 1 ) {
if ( strlen( get_post_meta( $post->ID, '_bit51_support_url', true ) ) > 1 ) {
wp_redirect( get_post_meta( $post->ID, '_bit51_support_url', true ), 301 );
} else {
$this->bit51_notfound();
}
}
break;
}
//Include Advanced Custom Fields Repeater
add_action( 'acf/register_fields', array( $this, 'bit51_register_fields' ) );
/** Customize the post title **/
remove_action( 'genesis_post_title', 'genesis_do_post_title' );
add_action( 'genesis_post_title', array( $this, 'bit51_do_post_title' ) );
/** Customize the breadcrumb **/
add_filter( 'genesis_single_crumb', array( $this, 'bit51_add_blog_crumb' ), 10, 2 );
add_filter( 'genesis_archive_crumb', array( $this, 'bit51_add_blog_crumb' ), 10, 2 );
}
/** Remove the post info function */
remove_action( 'genesis_entry_header', 'genesis_post_info', 12 );
/** Remove the author box on single posts */
remove_action( 'genesis_after_entry', 'genesis_do_author_box_single' );
/** Remove the post meta function */
remove_action( 'genesis_entry_footer', 'genesis_post_meta' );
/** Remove the comments template */
remove_action( 'genesis_after_entry', 'genesis_get_comments_template' );
/** Customize the content */
remove_action( 'genesis_entry_content', 'genesis_do_post_content' );
add_action( 'genesis_entry_content', array( $this, 'bit51_content' ) );
/** Execute Genesis **/
genesis();
}
/**
* Registers Advanced Custom Fields Repeater Integration
* @return void
*/
function bit51_register_fields() {
include_once( 'acf-repeater/repeater.php' );
}
/**
* Replace the page title for subpages
* @return null|void Null on failure void on success
*/
function bit51_do_post_title() {
$title = apply_filters( 'genesis_post_title_text', get_the_title() );
if ( 0 == strlen( $title ) )
return;
$title = sprintf( '<h1 class="entry-title">%s - %s</h1>', $title, $this->spages[$this->spage] );
echo apply_filters( 'genesis_post_title_output', $title . "\n" );
}
/**
* Add breadcrumb level for subpages
* @param string $crumb existing breadvrumbs
* @param array $args breadcrumb arguments
* @return string sting with new breadcrumb
*/
function bit51_add_blog_crumb( $crumb, $args ) {
global $post;
return '<a href="' . get_bloginfo( 'url' ) . '/software/" title="View all Software">Software</a> / <a href="' . get_permalink( $post->ID ) . '" title="">' . get_the_title( $post->ID ) . '</a> / ' . $this->spages[$this->spage];
}
/**
* Display page and subpage content
* @return void
*/
function bit51_content() {
global $post, $bit51_utilities;
$paypal = get_post_meta( $post->ID, '_bit51_paypal', true );
if ( ! empty( $this->spage ) ) {
if ( strlen( $paypal ) > 1 ) {
echo '<div class="software-paypal">';
echo 'Have you found this software useful? Please help support it\'s continued development with a donation of $20, $50, or even $100.';
echo '<form action="https://www.paypal.com/cgi-bin/webscr" method="post"><input type="hidden" name="cmd" value="_s-xclick"><input type="hidden" name="hosted_button_id" value="' . $paypal . '"><input type="image" src="https://www.paypalobjects.com/en_US/i/btn/btn_donateCC_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!"><img alt="" border="0" src="https://www.paypalobjects.com/en_US/i/scr/pixel.gif" width="1" height="1"></form>';
echo '<p class="recurring">You can even <a href="' . ( ( strlen( get_post_meta( $post->ID, '_bit51_donate_url', true ) ) > 1 ) ? get_post_meta( $post->ID, '_bit51_donate_url', true ) : ( get_bloginfo( 'url' ) . '/donate' ) ) . '">make a recurring donation.</a></p>';
echo '<p>Short on funds?</p>';
echo '<ul>';
echo '<li><a href="' . get_post_meta( $post->ID, '_bit51_meta_url', true ) . '" target="_blank">Rate ' . get_the_title( $post->ID ) . ' 5★\'s</a></li>';
echo '<li>Talk about it on your site and link back to <a href="' . get_permalink( $post->ID ) . '" target="_blank">this page.</a></li>';
echo '<li><a href="http://twitter.com/home?status=' . urlencode( 'I use ' . get_the_title( $post->ID ) . ' by @Bit51 and you should too - ' . get_permalink( $post->ID ) ) . '" target="_blank">Tweet about it.</a></li>';
echo '</ul>';
echo '</div>';
}
switch ( $this->spage ) {
case 'changelog':
echo '<div class="software-description">';
echo apply_filters( 'the_content', get_post_meta( $post->ID, '_bit51_changelog', true ) );
echo '<div class="clear"></div>';
echo '</div>';
break;
case 'donate':
echo '<div class="software-description">';
echo apply_filters( 'the_content', get_post_meta( $post->ID, '_bit51_donate', true ) );
echo '<div class="clear"></div>';
echo '</div>';
break;
case 'faq':
echo '<div class="software-description software-faq">';
echo '<ul>';
foreach ( $this->sfaq as $faq ) {
echo '<li class="faq">';
echo '<h2>' . $faq['question'] . '</h2>';
echo $faq['answer'];
echo '</li>';
}
echo '</ul>';
echo '<div class="clear"></div>';
echo '</div>';
break;
case 'support':
echo '<div class="software-description">';
echo apply_filters( 'the_content', get_post_meta( $post->ID, '_bit51_support', true ) );
echo '<div class="clear"></div>';
echo '</div>';
break;
default:
echo '<div class="software-description">';
echo '<p>' . __( 'That page could not be found', 'bit51' ) . '</p>';
echo '<div class="clear"></div>';
echo '</div>';
break;
}
} else {
//Get the plugin meta information
$meta = $bit51_utilities->get_plugin_data( $post->ID );
// display plugin meta information
echo '<div id="software-meta">';
if( $meta != false ) {
echo '<div class="software-meta-table">';
echo '<div class="leftcol">Version:</div>';
echo '<div class="software-version rightcol">';
echo $meta['Version'];
echo '</div>';
echo '<div class="leftcol">Downloads:</div>';
echo '<div class="software-downloads rightcol">';
echo number_format( substr( $meta['Downloads'], 14 ) );
echo '</div>';
echo '<div class="leftcol">Rating:</div>';
echo '<div class="software-rating rightcol" itemprop="aggregateRating" itemscope itemtype="http://schema.org/AggregateRating">';
echo '<div class="rating-stars">';
echo '<div class="rating" style="width: ' . ( $meta['Rating'] / 5 ) * 100 . '%;">';
echo '<meta itemprop="ratingValue" content="' . $meta['Rating'] . '">';
echo '<meta itemprop="reviewCount" content="' . $meta['Votes'] . '">';
echo '</div>';
echo '</div>';
echo '(' . $meta['Rating'] . '/5)';
echo '</div>';
if ( strlen( $meta['Votes'] ) > 1 ) {
echo '<div class="leftcol"># of Ratings:</div>';
echo '<div class="software-votes rightcol">';
echo $meta['Votes'];
echo '</div>';
}
echo '</div>';
}
echo '<div class="software-links">';
echo '<a class="software-download btn" href="' . get_post_meta( $post->ID, '_bit51_download_url', true ) . '" title="Download ' . get_the_title() . '" target="_blank" >Download</a>';
if ( is_array( $this->sfaq ) && sizeof( $this->sfaq ) >= 1 ) {
echo '<a class="software-faq btn" href="' . get_permalink( $post->ID ) . 'faq" title="FAQ ' . get_the_title() . '" >FAQ</a>';
}
if ( strlen( get_post_meta( $post->ID, '_bit51_support', true ) ) > 1 ) {
echo '<a class="software-support btn" href="' . get_permalink( $post->ID ) . 'support" title="' . get_the_title() . ' - Support" >Support</a>';
} elseif( strlen( get_post_meta( $post->ID, '_bit51_support_url', true ) ) > 1 ) {
echo '<a class="software-support btn" href="' . get_post_meta( $post->ID, '_bit51_support_url', true ) . '" title="' . get_the_title() . ' - Support" >Support</a>';
}
if ( strlen( get_post_meta( $post->ID, '_bit51_changelog', true ) ) > 1 ) {
echo '<a class="software-changelog btn" href="' . get_permalink( $post->ID ) . 'changelog" title="' . get_the_title() . ' - Changelog" >Changelog</a>';
} elseif( strlen( get_post_meta( $post->ID, '_bit51_changelog_url', true ) ) > 1 ) {
echo '<a class="software-changelog btn" href="' . get_post_meta( $post->ID, '_bit51_changelog_url', true ) . '" title="' . get_the_title() . ' - Changelog" >Changelog</a>';
}
if ( strlen( get_post_meta( $post->ID, '_bit51_donate', true ) ) > 1 ) {
echo '<a class="software-donate btn" href="' . get_permalink( $post->ID ) . 'donate" title="' . get_the_title() . ' - Donate" >Donate</a>';
} elseif( strlen( get_post_meta( $post->ID, '_bit51_donate_url', true ) ) > 1 ) {
echo '<a class="software-donate btn" href="' . get_post_meta( $post->ID, '_bit51_donate_url', true ) . '" title="' . get_the_title() . ' - Donate" >Donate</a>';
}
echo '</div>';
echo '</div>';
if ( strlen( $paypal ) > 1 ) {
echo '<div class="software-paypal">';
echo 'Have you found this software useful? Please help support it\'s continued development with a donation of $20, $50, or even $100.';
echo '<form action="https://www.paypal.com/cgi-bin/webscr" method="post"><input type="hidden" name="cmd" value="_s-xclick"><input type="hidden" name="hosted_button_id" value="' . $paypal . '"><input type="image" src="https://www.paypalobjects.com/en_US/i/btn/btn_donateCC_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!"><img alt="" border="0" src="https://www.paypalobjects.com/en_US/i/scr/pixel.gif" width="1" height="1"></form>';
echo '<p class="recurring">You can even <a href="' . ( ( strlen( get_post_meta( $post->ID, '_bit51_donate_url', true ) ) > 1 ) ? get_post_meta( $post->ID, '_bit51_donate_url', true ) : ( get_bloginfo( 'url' ) . '/donate' ) ) . '">make a recurring donation.</a></p>';
echo '<p>Short on funds?</p>';
echo '<ul>';
echo '<li><a href="' . get_post_meta( $post->ID, '_bit51_meta_url', true ) . '" target="_blank">Rate ' . get_the_title( $post->ID ) . ' 5★\'s</a></li>';
echo '<li>Talk about it on your site and link back to <a href="' . get_permalink( $post->ID ) . '" target="_blank">this page.</a></li>';
echo '<li><a href="http://twitter.com/home?status=' . urlencode( 'I use ' . get_the_title( $post->ID ) . ' by @Bit51 and you should too - ' . get_permalink( $post->ID ) ) . '" target="_blank">Tweet about it.</a></li>';
echo '</ul>';
echo '</div>';
}
// Display the content, if the content editor has content
if( $post->post_content !== '' ) {
echo '<div class="software-description">';
the_content();
echo '<div class="clear"></div>';
echo '</div>';
}
}
}
/**
* Sets proper 404 error when subpage not found
* @return void
*/
function bit51_notfound() {
global $wp_query;
$wp_query->set_404();
status_header( 404 );
get_template_part( 404 );
exit();
}
}
}
new bit51_software_page();