Skip to content

Commit d41c45e

Browse files
committed
Image Filter
1 parent 61efa5a commit d41c45e

File tree

4 files changed

+60
-17
lines changed

4 files changed

+60
-17
lines changed

readme.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,7 @@ This project is licensed under the GPL3 License.
278278
* Feature: Between Filter
279279
* Feature: Toot Content Filter
280280
* Feature: Date Filter
281+
* Feature: Image Filter
281282

282283
### 0.4 "Cassie Lang"
283284

tootpress_blog.php

Lines changed: 38 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -95,27 +95,49 @@ function tootpress_paint_image($tootid){
9595
}
9696

9797
$image_html.='">';
98-
$image_html.='<img ';
99-
$image_html.='src="';
100-
$image_html.=tootpress_get_url_image_directory();
101-
$image_html.=$toot_image[$i]['attachment_file'];
102-
$image_html.='" ';
103-
$image_html.='alt="';
104-
$image_html.=$toot_image[$i]['attachment_description'];
105-
//$image_html.='" ';
106-
//$image_html.='width="';
107-
//$image_html.=$toot_image[0]['attachment_width'];
108-
//$image_html.='" ';
109-
//$image_html.='height="';
110-
//$image_html.=$toot_image[0]['attachment_height'];
111-
$image_html.='" />';
98+
$image_html.=tootpress_create_image_tag($toot_image[$i]['attachment_file'],$toot_image[$i]['attachment_description'],$amount_of_images,($i+1));
11299
$image_html.='</div>';
113100

114101
}
115102

116103
return $image_html;
117104
}
118105

106+
/**
107+
* Create the Image Tag
108+
*
109+
* @since 0.5
110+
*
111+
* @param string Image File Name
112+
* @param string Image Description
113+
* @param int Amount of Images
114+
* @param int Image Number
115+
* @return string Image Tag
116+
*/
117+
118+
function tootpress_create_image_tag($filename, $description, $amount_of_images, $image_number) {
119+
120+
$image_tag='<img ';
121+
$image_tag.='src="';
122+
$image_tag.=tootpress_get_url_image_directory();
123+
$image_tag.=$filename;
124+
$image_tag.='" ';
125+
$image_tag.='alt="';
126+
$image_tag.=$description;
127+
//$image_tag.='" ';
128+
//$image_tag.='width="';
129+
//$image_tag.=$toot_image[0]['attachment_width'];
130+
//$image_tag.='" ';
131+
//$image_tag.='height="';
132+
//$image_html.=$toot_image[0]['attachment_height'];
133+
$image_tag.='" />';
134+
135+
$image_tag=tootpress_image_filter_apply($image_tag,$amount_of_images,$image_number);
136+
137+
return $image_tag;
138+
139+
}
140+
119141
/**
120142
* Creates the Elephant
121143
*
@@ -157,7 +179,7 @@ function tootpress_paint_elephant( $instance, $account, $mastodon_id, $backlink)
157179
*
158180
* @since 0.5
159181
*
160-
* @param string Date (Format: )
182+
* @param string Date
161183
* @return string html
162184
*/
163185

@@ -179,7 +201,7 @@ function tootpress_paint_date($date) {
179201

180202
}
181203

182-
$date_html.='<div class="toot-date"><p>'.esc_html($date).'</p></div>';
204+
$date_html='<div class="toot-date"><p>'.esc_html($date).'</p></div>';
183205
return $date_html;
184206

185207
}

tootpress_hooks.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,4 +214,24 @@ function tootpress_date_filter_apply($date) {
214214
return $date;
215215
}
216216

217+
/**
218+
* Image Filter
219+
*
220+
* This filter can be used to manipulate image tags
221+
*
222+
* @since 0.5
223+
*
224+
* @param string Image Tag
225+
* @param int Amount of Images
226+
* @param int Image Number
227+
* @return string Filtered Image Tag
228+
*/
229+
230+
function tootpress_image_filter_apply($img_tag,$amount_of_images,$image_number) {
231+
232+
$img_tag=apply_filters( 'tootpress_image_filter', $img_tag, $amount_of_images, $image_number);
233+
234+
return $img_tag;
235+
}
236+
217237
?>

tootpress_plugin.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ function tootpress_escaping_allowed_html() {
8787
'img' => array(
8888
'src' => array(),
8989
'alt' => array(),
90+
'class' => array(),
9091
),
9192
'br' => array(),
9293
'strong' => array(),
@@ -97,7 +98,6 @@ function tootpress_escaping_allowed_html() {
9798
'class' => array(),
9899
'href' => array(),
99100
'rel' => array(),
100-
'target' => array(),
101101
),
102102
);
103103
}

0 commit comments

Comments
 (0)