This repository has been archived by the owner on Jan 15, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mt-wp-plugin.shortcodes.php
172 lines (148 loc) · 4.85 KB
/
mt-wp-plugin.shortcodes.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
<?php
use MT\WP\Plugin\Api\MT_Photo;
use MT\WP\Plugin\Api\MT_News;
use MT\WP\Plugin\Common\MT_QueryBuilder;
use MT\WP\Plugin\Api\MT_Photographer;
add_shortcode('mt_photo', function ($atts) {
$a = shortcode_atts(array(
'id' => '',
'width' => '200'
), $atts);
$photo = new MT_Photo($a['id']);
$item = $photo->getOne(array('id', 'path'), 'ARRAY_A');
return '<img width="'.$a['width'].'" src="bilder/'.$item['path'].'">';
});
add_shortcode('total_number_of_photos', function ($atts) {
return (new MT_Photo)->getCount();
});
add_shortcode('latest_news_date', function ($atts) {
$a = shortcode_atts(array(
'format' => '%e. %B %Y'
), $atts);
return utf8_encode(strftime($a['format'], (new MT_News())->getLatestNewsTimestamp()));
});
add_shortcode('latest_photo_date', function ($atts) {
$a = shortcode_atts(array(
'format' => '%e. %B %Y'
), $atts);
return utf8_encode(strftime($a['format'], (new MT_Photo())->getLatestPhotoDate()));
});
add_shortcode('mt_statistics', function ($atts) {
$returnString = '
<table class="horizontalLeft">
<tr>
<th>'.__('Galerie', MT_NAME).'</th>
<th>'.__('Anzahl der Bilder', MT_NAME).'</th>
</tr>
';
$tempCategoryId = 0;
$tempSubcategoryId = 0;
$query = (new MT_QueryBuilder())
->from('photo')
->select('COUNT(wp_mt_photo.id) as numPhotos')
->joinInner('gallery', true, array('id AS galleryId', 'name as galleryName'))
->joinInner('category', 'wp_mt_category.id = wp_mt_gallery.category', array('id AS categoryId', 'name AS categoryName'))
->joinLeftOuter('subcategory', 'wp_mt_subcategory.id = wp_mt_gallery.subcategory', array('id AS subcategoryId', 'name subcategoryName'))
->whereEqual('wp_mt_photo.show', 1)
->groupBy(array('categoryName', 'subcategoryName', 'galleryName'))
->orderBy(array('categoryName', 'subcategoryName', 'galleryName'));
foreach ($query->getResult() as $row) {
// Category
if ($row->categoryId != $tempCategoryId) {
$tempCategoryId = $row->categoryId;
$returnString .= '
<tr>
<td><u>'.$row->categoryName.'</u></td>
<td></td>
</tr>';
}
// Subcategory
if ($row->subcategoryId != $tempSubcategoryId) {
$tempSubcategoryId = $row->subcategoryId;
$returnString .= '
<tr>
<td> » '.$row->subcategoryName.'</td>
<td></td>
</tr>';
}
// Gallery
$returnString .= '
<tr>
<td> » <a href="'.MT_Photo::GALLERY_PATH_ABS.'/'.$row->galleryId.'">'.$row->galleryName.'</a></td>
<td>'.$row->numPhotos.'</td>
</tr>';
}
$returnString .= '</table>';
return $returnString;
});
add_shortcode('mt_recent_post', function ($atts) {
$recent_posts = wp_get_recent_posts();
$returnString = '';
foreach ($recent_posts as $recent) {
$returnString .= '<h3>'.$recent["post_title"].'</h3>'.$recent["post_content"].'<div class="postDate">Verfasst am: '.$recent["post_modified"].'</div>';
}
return $returnString;
});
add_shortcode('mt_news', function ($atts) {
$returnString = '';
$dateYear_old = '';
$dateMonth_old = '';
$dateDay_old = '';
$newsItems = MT_News::getAll(array('title', 'text', 'gallery', 'date' ), 'date DESC');
foreach ($newsItems as $item) {
// News link
if (empty($item->gallery)) {
$news_link = '../';
} else {
$news_link = MT_Photo::GALLERY_PATH_ABS.'/'.$item->gallery;
}
// Year
$dateYear = utf8_encode(strftime('%Y', $item->date));
if ($dateYear != $dateYear_old && $dateYear != date('Y', time())) {
$dateYear_old = $dateYear;
$returnString .= '
</table>
<hr>
<center><h2>' . $dateYear . '</h2></center>';
}
// Month
$dateMonth = utf8_encode(strftime('%B', $item->date));
if ($dateMonth != $dateMonth_old) {
// Beim ersten Monat <table> noch nicht beenden
if (!empty($dateMonth_old)) {
$returnString .= '</table>';
}
$dateMonth_old = $dateMonth;
$returnString .= '
<h3>' . $dateMonth . '</h3>
<table class="table_quer" cellSpacing="4" cellPadding="1">
<colgroup>
<col width="95px">
<col width="*">
</colgroup>';
}
// Day
$returnString .= '<tr>';
$dateDay = utf8_encode(strftime('%a, %d.%m.', $item->date));
if ($dateDay != $dateDay_old) {
$dateDay_old = $dateDay;
$returnString .= '<th>'. $dateDay . ':</th>';
} else {
$returnString .= '<th></th>';
}
$returnString .= '<td><a href="' . $news_link . '">' . $item->title . '</a><br>' . $item->text . '</td>
</tr>';
}
$returnString .= '</table>';
return $returnString;
});
add_shortcode('mt_photographers', function ($atts) {
$returnString = '<ul>';
$photo = new MT_Photo();
$items = MT_Photographer::getAll(array('id', 'name'), 'name');
foreach ($items as $item) {
$returnString .= '<li><a href="'.MT_Photographer::$photographersPath.$item->id.'">'.$item->name.'</a> <span class="style_grew">('.$photo->getNumPhotos($item->id).')</span></li>';
}
$returnString .= '</ul>';
return $returnString;
});