|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Theme helper functions. |
|
4
|
|
|
* |
|
5
|
|
|
* @package WordPress_GitHub_SYnc |
|
6
|
|
|
*/ |
|
7
|
|
|
|
|
8
|
|
|
/** |
|
9
|
|
|
* Returns the HTML markup to view the current post on GitHub. |
|
10
|
|
|
* |
|
11
|
|
|
* @return string |
|
12
|
|
|
*/ |
|
13
|
|
|
function get_the_github_view_link() { |
|
14
|
1 |
|
return '<a href="' . get_the_github_view_url() . '">' . apply_filters( 'wpghs_view_link_text', 'View this post on GitHub.' ) . '</a>'; |
|
|
|
|
|
|
15
|
|
|
} |
|
16
|
|
|
add_shortcode( 'get_the_github_view_link', 'get_the_github_view_link' ); |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* Returns the URL to view the current post on GitHub. |
|
20
|
|
|
* |
|
21
|
|
|
* @return string |
|
22
|
|
|
*/ |
|
23
|
2 |
|
function get_the_github_view_url() { |
|
24
|
|
|
$wpghs_post = new WordPress_GitHub_Sync_Post( get_the_ID(), WordPress_GitHub_Sync::$instance->api() ); |
|
|
|
|
|
|
25
|
2 |
|
|
|
26
|
|
|
return $wpghs_post->github_view_url(); |
|
|
|
|
|
|
27
|
|
|
} |
|
28
|
|
|
add_shortcode( 'get_the_github_view_url', 'get_the_github_view_url' ); |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* Returns the HTML markup to edit the current post on GitHub. |
|
32
|
|
|
* |
|
33
|
|
|
* @return string |
|
34
|
1 |
|
*/ |
|
35
|
|
|
function get_the_github_edit_link() { |
|
36
|
|
|
return '<a href="' . get_the_github_edit_url() . '">' . apply_filters( 'wpghs_edit_link_text', 'Edit this post on GitHub.' ) . '</a>'; |
|
|
|
|
|
|
37
|
|
|
} |
|
38
|
|
|
add_shortcode( 'get_the_github_edit_link', 'get_the_github_edit_link' ); |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* Returns the URL to edit the current post on GitHub. |
|
42
|
|
|
* |
|
43
|
2 |
|
* @return string |
|
44
|
|
|
*/ |
|
45
|
2 |
|
function get_the_github_edit_url() { |
|
46
|
|
|
$wpghs_post = new WordPress_GitHub_Sync_Post( get_the_ID(), WordPress_GitHub_Sync::$instance->api() ); |
|
|
|
|
|
|
47
|
|
|
|
|
48
|
|
|
return $wpghs_post->github_edit_url(); |
|
|
|
|
|
|
49
|
|
|
} |
|
50
|
|
|
add_shortcode( 'get_the_github_edit_url', 'get_the_github_edit_url' ); |
|
51
|
|
|
|
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* EXAMPLE FROM https://codex.wordpress.org/Shortcode_API |
|
55
|
|
|
* // [bartag foo="foo-value"] |
|
56
|
|
|
* function bartag_func( $atts ) { |
|
57
|
|
|
* $a = shortcode_atts( array( |
|
58
|
|
|
* 'foo' => 'something', |
|
59
|
|
|
* 'bar' => 'something else', |
|
60
|
|
|
* ), $atts ); |
|
61
|
|
|
* |
|
62
|
|
|
* return "foo = {$a['foo']}"; |
|
63
|
|
|
* } |
|
64
|
|
|
* add_shortcode( 'bartag', 'bartag_func' ); |
|
65
|
|
|
*/ |
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* Function with attributes |
|
69
|
|
|
* - type: 'link' (default) to return a HTML anchor tag with text, or 'url' for bare URL. |
|
70
|
|
|
* - target: 'view' (default) or 'edit' to return the respective link/url. |
|
71
|
|
|
* - text: text to be included in the link. Ignored if type='url'. |
|
72
|
|
|
* |
|
73
|
|
|
* Returns either a HTML formatted anchor tag or the bare URL of the current post on GitHub. |
|
74
|
|
|
* |
|
75
|
|
|
* @return string |
|
76
|
|
|
*/ |
|
77
|
|
|
function write_wpghs_link( $atts ) { |
|
78
|
|
|
|
|
79
|
|
|
extract(shortcode_atts(array( |
|
|
|
|
|
|
80
|
|
|
"type" => 'link', |
|
|
|
|
|
|
81
|
|
|
"target" => 'view', |
|
|
|
|
|
|
82
|
|
|
"text" => '' |
|
|
|
|
|
|
83
|
|
|
), $atts)); |
|
|
|
|
|
|
84
|
|
|
|
|
85
|
|
|
$output = ''; |
|
|
|
|
|
|
86
|
|
|
|
|
87
|
|
|
switch($target) { |
|
|
|
|
|
|
88
|
|
View Code Duplication |
case 'view': |
|
|
|
|
|
|
89
|
|
|
$getter = get_the_github_view_url(); |
|
|
|
|
|
|
90
|
|
|
if(!empty($text)) { |
|
|
|
|
|
|
91
|
|
|
$linktext = $text; |
|
|
|
|
|
|
92
|
|
|
} else { |
|
93
|
|
|
$linktext = 'View this post on GitHub'; |
|
|
|
|
|
|
94
|
|
|
} |
|
95
|
|
|
break; |
|
96
|
|
View Code Duplication |
case 'edit': |
|
|
|
|
|
|
97
|
|
|
$getter = get_the_github_edit_url(); |
|
|
|
|
|
|
98
|
|
|
if(!empty($text)) { |
|
|
|
|
|
|
99
|
|
|
$linktext = $text; |
|
|
|
|
|
|
100
|
|
|
} else { |
|
101
|
|
|
$linktext = 'Edit this post on GitHub'; |
|
|
|
|
|
|
102
|
|
|
} |
|
103
|
|
|
break; |
|
104
|
|
|
default: |
|
|
|
|
|
|
105
|
|
|
$getter = get_the_github_view_url(); |
|
|
|
|
|
|
106
|
|
|
$linktext = 'View this post on GitHub'; |
|
|
|
|
|
|
107
|
|
|
break; |
|
108
|
|
|
} |
|
|
|
|
|
|
109
|
|
|
|
|
110
|
|
|
switch($type) { |
|
|
|
|
|
|
111
|
|
|
case 'link': |
|
|
|
|
|
|
112
|
|
|
$output .= '<a href="' . $getter . '">' . $linktext . '</a>'; |
|
|
|
|
|
|
113
|
|
|
break; |
|
114
|
|
|
case 'url': |
|
115
|
|
|
$output .= $getter; |
|
116
|
|
|
break; |
|
117
|
|
|
default: |
|
118
|
|
|
$output .= '<a href="' . $getter . '">' . $linktext . '</a>'; |
|
119
|
|
|
break; |
|
120
|
|
|
} |
|
|
|
|
|
|
121
|
|
|
|
|
122
|
|
|
return $output; |
|
|
|
|
|
|
123
|
|
|
|
|
124
|
|
|
} |
|
125
|
|
|
add_shortcode( 'wpghs', 'write_wpghs_link' ); |
|
126
|
|
|
|