Skip to content
This repository was archived by the owner on Jan 5, 2023. It is now read-only.

Commit 84e4bb4

Browse files
committed
add a posts plugin
1 parent 7098ae9 commit 84e4bb4

File tree

3 files changed

+153
-0
lines changed

3 files changed

+153
-0
lines changed

posts/card.tpl

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<div class="card h-100">
2+
{img}
3+
<div class="card-body">
4+
<h5 class="card-title">{title}</h5>
5+
{text}
6+
</div>
7+
<div class="card-footer">
8+
<a href="{href}" class="btn btn-primary">{btn_read_more}</a>
9+
</div>
10+
</div>

posts/index.php

+122
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
<?php
2+
3+
/**
4+
* Plugin: show the most recent entries from fc_posts
5+
* Version: Version: 0.1
6+
* Requirement: flatCore 2.0.+
7+
* License: GPL-3.0 License
8+
*
9+
* type -> m = message, i = image, f = file, g = gallery, e = event, v = video, l = link
10+
* limit -> number of posts (default = 3)
11+
* [plugin=posts]type=m-i-f&limit=6[/plugin] display 6 posts of type message, image and file
12+
* [plugin=posts]type=e[/plugin] display 3 posts from type event
13+
*
14+
* Note: You should not mix post type event with other types. This would end up with unexpected results in the sorting.
15+
*/
16+
17+
18+
$plugin = array();
19+
$plugin['title'] = 'Posts Plugin';
20+
$plugin['description'] = '<p>show the most recent posts</p>';
21+
$plugin['version'] = '1.0';
22+
$plugin['author'] = 'flatCore.org';
23+
24+
if(FC_SOURCE == 'frontend') {
25+
26+
global $db_posts;
27+
global $languagePack;
28+
global $lang;
29+
30+
$time_string_now = time();
31+
32+
$set_type = '';
33+
34+
if($type != '') {
35+
$set_type = explode("-",$type);
36+
} else {
37+
$set_type = array("m");
38+
}
39+
40+
if($limit == '') {
41+
$limit = 3;
42+
} else {
43+
$limit = (int) $limit;
44+
}
45+
46+
if($type == 'e') {
47+
48+
$posts = $db_posts->select("fc_posts", "*",[
49+
"AND" => [
50+
"OR" => [
51+
"post_type" => $set_type
52+
],
53+
"post_lang" => $languagePack,
54+
"post_status" => 1,
55+
"post_releasedate[<]" => $time_string_now,
56+
"post_event_startdate[>]" => $time_string_now
57+
],
58+
59+
"ORDER" => ["post_event_startdate" => "ASC"],
60+
"LIMIT" => $limit,
61+
62+
63+
]);
64+
65+
66+
} else {
67+
68+
$posts = $db_posts->select("fc_posts", "*",[
69+
"AND" => [
70+
"OR" => [
71+
"post_type" => $set_type
72+
],
73+
"post_lang" => $languagePack,
74+
"post_status" => 1,
75+
"post_releasedate[<]" => $time_string_now
76+
],
77+
78+
"ORDER" => ["post_releasedate" => "DESC"],
79+
"LIMIT" => $limit
80+
]);
81+
82+
}
83+
84+
85+
$cnt_posts = count($posts);
86+
87+
if($cnt_posts < 1) {
88+
echo '<div class="alert alert-info my-3">No matches.</div>';
89+
}
90+
91+
$card_tpl = file_get_contents('content/plugins/posts/card.tpl');
92+
93+
echo '<div class="row row-cols-1 row-cols-md-3 g-4 my-3">';
94+
for($i=0;$i<$cnt_posts;$i++) {
95+
96+
$post_image = explode('<->', $posts[$i]['post_images']);
97+
if($post_image[1] != '') {
98+
$img = '<img src="'.$post_image[1].'" class="card-img-top" alt="">';
99+
} else {
100+
$img = '';
101+
}
102+
103+
$href = parse_url($posts[$i]['post_rss_url'], PHP_URL_PATH);
104+
105+
$teaser = strip_tags(html_entity_decode($posts[$i]['post_teaser']));
106+
$teaser = implode(' ', array_slice(explode(' ', $teaser), 0, 25));
107+
$teaser .= ' <small><em>(...)</em></small>';
108+
$this_post = $card_tpl;
109+
$this_post = str_replace('{title}', $posts[$i]['post_title'], $this_post);
110+
$this_post = str_replace('{text}', $teaser, $this_post);
111+
$this_post = str_replace('{img}', $img, $this_post);
112+
$this_post = str_replace('{href}', $href, $this_post);
113+
$this_post = str_replace('{btn_read_more}', $lang['btn_read_more'], $this_post);
114+
115+
echo '<div class="col">';
116+
echo $this_post;
117+
echo '</div>';
118+
}
119+
echo '</div>';
120+
121+
}
122+
?>

readme.md

+21
Original file line numberDiff line numberDiff line change
@@ -10,45 +10,66 @@ This repository contains a few useful plugins for the [flatCore Content Manageme
1010
* [downloader - download button for uploaded images](#downloader)
1111
* [form - another simple form](#form)
1212
* [imglinks - gallery from uploaded images](#imglinks)
13+
* [posts - Show the most recent posts](#posts)
1314
* [video.js - embed uploaded videos](#video)
1415
* [youtube - embed a youtube video](#youtube)
1516

1617

1718
### ajaxform
1819
This is a simple ajax contact form. This form will be sent to your E-Mail Adress from preferences (ACP - System - E-Mail). If you have SMTP Settings (content/config_smtp.php) it will use this automatically.
20+
1921
```[plugin=ajaxform][/plugin]```
2022

2123
### bs-carousel
2224
Create Bootstrap Carousel. Filter uploaded images by keyword and order by priority.
25+
2326
```[plugin=bs-carousel.php]key=keyword[/plugin]```
2427

2528
### bs-modal
2629
Create Bootstrap Modal. Get the contents (Text and Title) from a Snippet.
30+
2731
```[plugin=bs-modal.php]fcs=snippet[/plugin]```
2832

2933
### bs-tabs
3034
Create Bootstrap Tabs. Get the contents (Text, Title and Permalink-Name) from Snippets.
35+
3136
```[plugin=bs-tabs.php]key=word[/plugin]```
3237

3338
### captcha
3439
This Plugin is not ready to use. You can use this Captcha in your Forms. Include the file captcha_calc.php for Math-Based Captcha or captcha_img.php for Image-Based Captcha. An example will appear soon. Includet font: [Ubuntu Mono](https://design.ubuntu.com/font/) distributed under an [open licence](http://www.ubuntu.com/legal/terms-and-policies/font-licence).
3540

3641
### downloader
3742
This Plugin creates a simple Download Button. The download file must be in the /content/images/ directory.
43+
3844
```[plugin=downloader.php]f=filename[/plugin]```
3945

4046
### form
4147
Just another contact form. The Requests are sent to the contact data stored in the settings.
48+
4249
```[plugin=form.php][/plugin]```
4350

4451
### imglinks
4552
This Plugin generates a gallery from your Images. It find your uploaded images by the given keyword.
53+
4654
```[plugin=imglinks.php]key=keyword[/plugin]```
4755

56+
### posts
57+
Show the most recent entries from fc_posts. You can filter the posts by type and limit the number of posts to show. *Note:* You should not mix post type event with other types. This would end up with unexpected results in the sorting.
58+
59+
Display 6 posts of type message, image and file
60+
61+
```[plugin=posts]type=m-i-f&limit=6[/plugin]```
62+
63+
Display the next three upcoming events
64+
65+
```[plugin=posts]type=e[/plugin]```
66+
4867
### video
4968
Include a Video Player using video.js. You have to upload your Video in /content/files/ and a preview image in /content/images/.
69+
5070
```[plugin=video.js.php]v=myvideo[/plugin]```
5171

5272
### youtube
5373
This plugin embeds a youtube video.
74+
5475
```[plugin=youtube.php]v=VIDEOID[/plugin]```

0 commit comments

Comments
 (0)