-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtootpress_blog.php
184 lines (142 loc) · 3.79 KB
/
tootpress_blog.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
<?php
/**
* Blog
*
* @package TootPress
* @since 0.1
*/
// Security: Stops code execution if WordPress is not loaded
if (!defined('ABSPATH')) { exit; }
/**
* Creates the Toot Markup
*
* @since 0.1
*
* @param int Mastodon ID
* @param date Toot Date
* @param string Toot Content
* @param int Media Flag
* @param string Mastodon Instance
* @param string Mastodon Account
* @param int Backlink Flag
* @return string html
*/
function tootpress_paint_toot( $mastodon_id, $date, $content, $media , $instance, $account, $backlink)
{
$toot_html='';
// Toot ID as HTML Comment
$toot_html.='<!-- Toot ID '.$mastodon_id.'-->';
// Toot Start
$toot_html.='<div class="tootpress-toot"/>';
// Toot Elephant
$toot_html.=tootpress_paint_elephant( $instance, $account, $mastodon_id,$backlink);
// Toot Date
if(tootpress_is_language_german()) {
$date=tootpress_convert_mysqldate_to_german_format($date);
} else {
$date=tootpress_convert_mysqldate_to_international_format($date);
}
$toot_html.='<div class="toot-date"><p>'.esc_html($date).'</p></div>';
// Toot Content
$content=tootpress_remove_target_blank($content);
$toot_html.='<div class="toot-content">'.wp_kses($content, tootpress_escaping_allowed_html() ).'</div>';
// Toot Image
if($media){
$toot_html.=wp_kses(tootpress_paint_image($mastodon_id), tootpress_escaping_allowed_html() );
}
// Toot End
$toot_html.='</div>';
return $toot_html;
}
/**
* Creates the Image Markup
*
* @since 0.1
*
* @param int Toot ID
* @return string html
*/
function tootpress_paint_image($tootid){
// Get Images from Database
$toot_image=array();
$toot_image=tootpress_get_media_from_database($tootid);
$image_html='';
// Amount of Images
$amount_of_images=sizeof($toot_image);
for($i=0;$i<$amount_of_images;$i++) {
// Image Content
$image_html.='<div class="toot-image ';
// Classes
if($amount_of_images>1) {
// Galleries
$image_html.='toot-image-gallery ';
$image_html.='toot-image-gallery-'.$amount_of_images.' ';
$image_html.='toot-image-'.($i+1);
} else {
// Single Images
$image_html.='toot-image-single ';
}
$image_html.='">';
$image_html.='<img ';
$image_html.='src="';
$image_html.=tootpress_get_url_image_directory();
$image_html.=$toot_image[$i]['attachment_file'];
$image_html.='" ';
$image_html.='alt="';
$image_html.=$toot_image[$i]['attachment_description'];
//$image_html.='" ';
//$image_html.='width="';
//$image_html.=$toot_image[0]['attachment_width'];
//$image_html.='" ';
//$image_html.='height="';
//$image_html.=$toot_image[0]['attachment_height'];
$image_html.='" />';
$image_html.='</div>';
}
return $image_html;
}
/**
* Creates the Elephant
*
* @since 0.3
*
* @param string Mastodon Instance
* @param string Mastodon Account
* @param int Mastodon Toot ID
* @param int Backlink Option
* @return string html
*/
function tootpress_paint_elephant( $instance, $account, $mastodon_id, $backlink) {
$elephant_html='';
$url='https://'.$instance.'/@'.$account.'/'.$mastodon_id;
if($backlink) {
$elephant_html.='<a href="';
$elephant_html.=esc_url($url);
$elephant_html.='" class="toot-backlink"/>';
}
// The Elephant
$elephant_html.='<img class="tootpress-toot-symbol" src="'.esc_url(plugins_url()).'/tootpress/tootpress_toot.png" alt="Toot Symbol" width="35" height="37"/>';
if($backlink) {
$elephant_html.='</a>';
}
return $elephant_html;
}
/**
* Creates the Preamble
*
* @since 0.4
*
* @param int TootPress Current Page
* @return string html
*/
function tootpress_paint_preamble($tootpress_current_page) {
$preamble='';
if($tootpress_current_page==1) {
$preamble.=tootpress_preamble_filter_apply($preamble);
if($preamble) {
$preamble='<div class="tootpress-preamble">'.$preamble.'</div>';
}
}
return $preamble;
}
?>