This repository has been archived by the owner on Jul 8, 2018. It is now read-only.
forked from lingz/gazelle
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunctions.php
311 lines (276 loc) · 9.61 KB
/
functions.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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
<?php
function gridster() {
$query = gridster_query();
$max_row = 0; ?>
<div data-root='<?php echo site_url(); ?>' class="gridster">
<div id="grid-buttons" class="row">
<div class="col-6">
<button id="btn-save" type="button" class="btn btn-primary btn-block">Save Grid</button>
</div>
<div class="col-6">
<button id="btn-preview" type="button" class="btn btn-success btn-block">Go To Preview</button>
</div>
</div>
<ul>
<?php
$params = current_issue(gridlock_future(array_merge(get_option("gridlock_grid_query"), array('orderby' => 'date', 'order' => 'DESC', "post_status" => "publish", "tag__not_in" => get_term_by("name", "pick", "post_tag")->term_id))));
$gridster_query = new WP_Query($params);
while ( $gridster_query->have_posts() ) : $gridster_query->the_post();
if (get_post_meta( get_the_ID(), "_gridlock", true) > 1) {
$gridlock = explode(".", get_post_meta( get_the_ID(), "_gridlock", true));
$index = $gridlock[1][0];
$span = $gridlock[1][1];
$row = $gridlock[0]; ?>
<li data-row="<?php echo $row ?>" data-col="<?php echo $index ?>" data-sizex="<?php echo $span ?>" data-sizey="1" data-post_id=<?php the_ID(); ?>>
<div class="gridster-box">
<div class="row gridster-title">
<?php the_title(); ?>
</div>
<div class="row">
<button type="button" class="btn btn-info btn-block toggle-btn">Toggle Size</button>
</div>
<div class="row">
<button type="button" class="btn btn-danger btn-block remove-btn">Remove</button>
</div>
</div>
</li>
<?php }
endwhile;
?>
</ul>
</div>
<?php
}
function ungridded_posts() {
$params = current_issue(gridlock_future(array_merge(get_option("gridlock_grid_query"), array('orderby' => 'date', 'order' => 'DESC', "post_status" => "publish", "tag__not_in" => get_term_by("name", "pick", "post_tag")->term_id))));
$unassigned = new WP_Query($params);
echo "<ul id='ungridded' class='list-unstyled'>";
while ( $unassigned->have_posts() ) : $unassigned->the_post();
$gridlock_meta = get_post_meta(get_the_ID(), "_gridlock", true);
if (!isset($gridlock_meta) || $gridlock_meta < 1) {
echo "<li><a href='#' data-post_id=" . get_the_ID() . " class='text-primary'>+" . get_the_title() . "</a></li>";
}
endwhile;
echo "</ul>";
}
function _exclude_meta_key_in_posts_where( $where ) {
global $wpdb;
return $where . " AND $wpdb->posts.ID NOT IN ( SELECT DISTINCT post_id FROM $wpdb->postmeta WHERE meta_key = '_gridlock' AND meta_value > '' )";
}
function gazelle_set_post_views($postID) {
$count_key = 'gazelle_views_count';
$count = get_post_meta($postID, $count_key, true);
if ($count == '') {
$count = 0;
}
update_post_meta($postID, $count_key, ++$count);
}
remove_action( 'wp_head', 'adjacent_posts_rel_link_wp_head', 10, 0);
function gazelle_track_post_views ($post_Id) {
if (!is_single() ) return;
if ( empty ($post_id) ) {
global $post;
$post_id = $post->ID;
}
gazelle_set_post_views($post_id);
}
add_action( 'wp_head', 'gazelle_track_post_views');
function colorbox ($categoryname) { ?>
<div class="colorbox colorbox-<?php echo strtolower($categoryname); ?>">
</div>
<?php }
function get_cat() {
$categories = get_the_category();
if (!empty($categories)) {
return $categories[0]->cat_name;
} else {
return '';
}
}
function top_articles() {
global $authordata;
echo "<ul>";
$popular = new WP_Query(active_issue(array_merge(get_option("gridlock_query"), array('posts_per_page' => 5, 'orderby' => 'meta_value_num', 'meta_key' => 'gazelle_views_count', 'order' => 'DESC', "post_status" => "publish", ))));
while ( $popular->have_posts() ) : $popular->the_post();
echo "<li class='list-unstyled row row-" . strtolower(get_cat()) . "'>";
echo '<a href="' . get_permalink() . '">' . '<h6>' . get_the_title() . '</h6>' . '</a>';
echo colorbox(get_cat());
echo '<small class="text-muted">';
coauthors_posts_links(", ", " and ");
echo "</small>";
echo "</li>";
endwhile;
echo "</ul>";
}
function archive_list() {
$args = array(
'orderby' => "slug",
'order' => "DESC",
'exclude' => get_option("exclude_issues")
);
$terms = get_terms("issue", $args);
$count = 0;
?>
<div id="archives" class="container">
<?php usort($terms, "issues_sort"); ?>
<?php foreach ($terms as $term) { ?>
<?php if($count % 3 == 0) { ?>
<div class="row">
<?php } ?>
<div class="col-12 col-sm-4">
<div class="issue-container">
<a href='<?php echo site_url() . '/issue/' . $term->slug ?>'
title='View all posts in <?php echo $term->name ?>'>
<h3><?php echo $term->name ?></h3>
</a>
<h4 class="text-muted"><?php echo $term->description; ?></h4>
</div>
</div>
<?php if(++$count % 3 == 0) { ?>
</div>
<?php } ?>
<?php } ?>
</div>
<?php
}
add_shortcode('archives', 'archive_list');
function make_side_image($atts, $content) {
extract( shortcode_atts( array(
"image" => "#",
"direction" => "left",
), $atts, "image"));
return "<img src='{$image}' class='side-image {$direction}'>";
}
add_shortcode("side-image", "make_side_image");
function make_tooltip($atts, $content) {
extract( shortcode_atts( array(
"tooltip" => "",
"href" => "#"
), $atts, "tooltip"));
return "<a class='tooltip-link' href='{$href}' data-toggle='tooltip' title='{$tooltip}'>{$content}</a>"
. "<script>$('.tooltip-link').tooltip();</script>";
}
add_shortcode('tooltip', 'make_tooltip');
function blockquote_image($atts, $content) {
extract( shortcode_atts( array(
"image" => "#"
), $atts, "image"));
return "<div class='blockquote-image' style='background-image:url({$image})'>{$content}</div>";
}
add_shortcode('blockquote_image', 'blockquote_image');
function make_slideshow($atts, $content) {
$slides = explode(";", $content);
$slideCount = count($slides);
$firstCaption = false;
$pattern = "/^\[(.+)\]\((.+)\)/";
$matches = array();
?>
<div class="wp-caption alignnone slideshow-container">
<div class="slideshow full-width">
<div class="scroller">
<ul>
<?php
foreach ($slides as $slide) {
preg_match($pattern, $slide, $matches);
if (!count($matches)) continue;
$caption = $matches[1];
$imgLink = $matches[2];
if (!$firstCaption) $firstCaption = $caption;
echo '<li class="item">';
?>
<div style="background-image: url(<?php echo $imgLink; ?>)" class="image"><?php echo $caption; ?></div>
<?php
echo '</li>';
}
?>
</ul>
</div>
<div class="left carousel-control">
<a class="icon-prev"></a>
</div>
<div class="right carousel-control">
<a class="icon-next"></a>
</div>
</div>
<p class="caption wp-caption-text">
<?php echo $firstCaption; ?>
</p>
</div>
</div>
<script src="<?php echo get_stylesheet_directory_uri(); ?>/javascripts/slideshow.js?v=1" type="text/javascript"></script>
<?php
}
add_shortcode('slideshow', 'make_slideshow');
function big_image($atts, $content) {
return "<div class='big-image'> $content </div>";
}
add_shortcode('big_image', 'big_image');
add_filter('manage_posts_columns', 'my_columns');
function my_columns($columns) {
$columns['views'] = 'Views';
return $columns;
}
function add_video_embed_note($html, $url, $attr) {
return '<div class="video-container">' . $html . '</div>';
}
add_filter('embed_oembed_html', 'add_video_embed_note', 10, 3);
add_action('manage_posts_custom_column', 'my_show_columns');
function my_show_columns($name) {
global $post;
switch ($name) {
case 'views':
$views = get_post_meta($post->ID, 'gazelle_views_count', true);
echo $views;
}
}
function issues_sort($a, $b) {
"sorting";
return ((int) $a->slug < (int) $b->slug);
}
add_image_size("mt_profile_img", 500, 500, false);
// we don't want the default avatar anywhere
add_filter( 'mpp_avatar_override', '__return_true' );
// allow html in author page
remove_filter('pre_user_description', 'wp_filter_kses');
//Infinite scroll
function gazelle_infinitepaginate(){
$issuenum = $_POST["issue_num"];
$category = $_POST['category'];
$infinite_posts = new WP_Query(array_merge(array("issue" => $issuenum, "category_name" => $category), get_option("gridlock_query")) );
include(locate_template('ifscroll_loop.php'));
exit;
}
add_action('wp_ajax_infinite_scroll', 'gazelle_infinitepaginate');
add_action('wp_ajax_nopriv_infinite_scroll', 'gazelle_infinitepaginate');
// Remove old Jquery
add_action('wp_enqueue_scripts', 'no_more_jquery');
function no_more_jquery(){
wp_deregister_script('jquery');
}
//Author page shortcode
function gzl_bio($atts) {
extract(shortcode_atts(array(
'username' => 'Unknown Author',
'role' => 'Staff',
), $atts));
$user = get_user_by('login',$username);
$name = $user->display_name;
$description = $user->description;
$id = $user->ID;
$x = mt_profile_img($id, array(
'echo' => false )
);
return '<div class="row profile profile-' . $id . '">
<div class="col-md-5">
' . (($x) ? $x : get_avatar($id, 200)) . '
</div>
<div class="col-md-7">
<h3>' . $name . '</h3>
<h4>' . $role . '</h4>
<p>' . $description . '</p>
<a href="http://www.thegazelle.org/contact/?user=' . $id . '">Send email</a>
</div>
</div>';
}
add_shortcode('gzl_bio', 'gzl_bio');
?>