-
Notifications
You must be signed in to change notification settings - Fork 63
/
feedwordpressboilerplatereformatter.class.php
128 lines (118 loc) · 3.29 KB
/
feedwordpressboilerplatereformatter.class.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
<?php
/**
* class FeedWordPressBoilerplateReformatter: processes shortcodes in Boilerplate / Credits
* settings text from Syndication > Posts & Links > Boilerplate / Credits
*
* @author C. Johnson <[email protected]>
*
* @see feedwordpressboilerplatereformatter.shortcode.functions.php
*
* @version 2020.0120
*/
class FeedWordPressBoilerplateReformatter {
var $id, $element;
public function __construct ($id = NULL, $element = 'post') {
$this->id = $id;
$this->element = $element;
}
function shortcode_methods () {
return array(
'source' => 'source_link',
'source-name' => 'source_name',
'source-url' => 'source_url',
'original-link' => 'original_link',
'original-url' => 'original_url',
'author' => 'source_author_link',
'author-name' => 'source_author',
'feed-setting' => 'source_setting',
);
}
function do_shortcode ($template) {
$codes = $this->shortcode_methods();
// Register shortcodes relative to this object/post ID/element.
foreach ($codes as $code => $method) :
add_shortcode($code, array($this, $method));
endforeach;
$template = do_shortcode($template);
// Unregister shortcodes.
foreach ($codes as $code => $method) :
remove_shortcode($code);
endforeach;
return $template;
}
function source_name ($atts) {
$param = shortcode_atts(array(
'original' => NULL,
), $atts);
return get_syndication_source($param['original'], $this->id);
}
function source_url ($atts) {
$param = shortcode_atts(array(
'original' => NULL,
), $atts);
return get_syndication_source_link($param['original'], $this->id);
}
function source_link ($atts) {
$arg0 = (( is_array($atts) and isset($atts[0]) ) ? strtolower($atts[0]) : '' );
switch ($arg0) :
case '-name' :
$ret = $this->source_name($atts);
break;
case '-url' :
$ret = $this->source_url($atts);
break;
default :
/** @var array Never used. */
$param = shortcode_atts(
array(
'original' => NULL,
),
$atts );
if ('title' == $this->element) :
$ret = $this->source_name( $atts );
else :
$ret = '<a href="'.htmlspecialchars($this->source_url($atts)).'">'.htmlspecialchars($this->source_name($atts)).'</a>';
endif;
endswitch;
return $ret;
}
function source_setting ($atts) {
$param = shortcode_atts(array(
'key' => NULL,
), $atts);
return get_feed_meta($param['key'], $this->id);
}
function original_link ($atts, $text) {
$url = $this->original_url($atts);
return '<a href="'.esc_url($url).'">'.do_shortcode($text).'</a>';
}
function original_url ($atts) {
return get_syndication_permalink($this->id);
}
function source_author ($atts) {
return get_the_author();
}
function source_author_link ($atts) {
$arg0 = (( is_array($atts) and isset($atts[0]) ) ? strtolower($atts[0]) : '' );
switch ($arg0) :
case '-name' :
$ret = $this->source_author($atts);
break;
default :
global $authordata; // Janky.
if ('title' == $this->element) :
$ret = $this->source_author($atts);
else :
$ret = get_the_author();
$url = get_author_posts_url((int) $authordata->ID, (int) $authordata->user_nicename);
if ($url) :
$ret = '<a href="'.$url.'" '
.'title="Read other posts by '.esc_html($authordata->display_name).'">'
.$ret
.'</a>';
endif;
endif;
endswitch;
return $ret;
}
}