PluginProbe
UpStream: a Project Management Plugin for WordPress / trunk
UpStream: a Project Management Plugin for WordPress vtrunk
trunk 1.39.0 1.39.1 1.39.2 1.39.3 2.0.7 2.1.0
upstream / includes / frontend / up-template-functions.php

up-template-functions.php in UpStream: a Project Management Plugin for WordPress trunk, at includes/frontend/up-template-functions.php

358 lines 8.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Handle templates functions
4 *
5 * @package UpStream
6 */
7
8 // Exit if accessed directly.
9 if ( ! defined( 'ABSPATH' ) ) {
10 exit;
11 }
12
13 /**
14 * Set the path to be used in the theme folder.
15 * Templates in this folder will override the plugins frontend templates.
16 */
17 function upstream_template_path() {
18 return apply_filters( 'upstream_template_path', 'upstream/' );
19 }
20
21 /**
22 * Check relevant directories for template parts.
23 * Looks in child theme first, then parent theme, then plugin.
24 *
25 * @param mixed $part Part.
26 */
27 function upstream_get_template_part( $part ) {
28 if ( $part ) {
29 $check_dirs = apply_filters(
30 'upstream_check_template_directory',
31 array(
32 trailingslashit( get_stylesheet_directory() ) . upstream_template_path(),
33 trailingslashit( get_template_directory() ) . upstream_template_path(),
34 UPSTREAM_PLUGIN_DIR . 'templates/',
35 )
36 );
37 foreach ( $check_dirs as $dir ) {
38 if ( file_exists( trailingslashit( $dir ) . $part ) ) {
39 load_template( $dir . $part );
40
41 return;
42 }
43 }
44 }
45
46 return $part;
47 }
48
49 /**
50 * Output list of the client users avatars
51 *
52 * @param mixed $id Id.
53 * @return void
54 */
55 function upstream_output_client_users( $id = null ) {
56 $users = (array) upstream_project_client_users( $id );
57 $is_after_first_item = false;
58
59 if ( count( $users ) > 0 ) : ?>
60 <ul class="list-inline">
61 <li>
62 <?php
63 foreach ( $users as $user_id ) {
64 if ( upstream_show_users_name() ) {
65 if ( $is_after_first_item ) {
66 echo ',&nbsp; ';
67 }
68
69 $is_after_first_item = true;
70 }
71
72 echo wp_kses_post( upstream_user_avatar( $user_id ) );
73 }
74 ?>
75 </li>
76 </ul>
77 <?php else : ?>
78 <span class="text-muted"><i><?php echo '(' . esc_html__( 'none', 'upstream' ) . ')'; ?></i></span>
79 <?php
80 endif;
81 }
82
83 /**
84 * Upstream Output Project Owner
85 *
86 * @param mixed $id Id.
87 * @return void
88 */
89 function upstream_output_project_owner( $id = null ) {
90 $users = array( upstream_project_owner_id( $id ) );
91
92 if ( count( $users ) > 0 ) {
93 ?>
94 <ul class="list-inline">
95 <li>
96 <?php
97 $is_after_first_item = false;
98
99 foreach ( $users as $user_id ) {
100 if ( upstream_show_users_name() ) {
101 if ( $is_after_first_item ) {
102 echo ',&nbsp;';
103 }
104
105 $is_after_first_item = true;
106 }
107
108 echo wp_kses_post( upstream_user_avatar( $user_id ) );
109 }
110 ?>
111 </li>
112 </ul>
113 <?php } else { ?>
114 <span class="text-muted"><i><?php echo esc_html( '(' . __( 'none', 'upstream' ) . ')' ); ?></i></span>
115 <?php
116 }
117 }
118
119 /**
120 * Upstream Get Project Owner
121 *
122 * @param mixed $id ID.
123 */
124 function upstream_get_project_owner( $id = null ) {
125 $users = array( upstream_project_owner_id( $id ) );
126 $text = '';
127
128 if ( count( $users ) > 0 ) {
129 $text .= '<ul class="list-inline"><li>';
130 $is_after_first_item = false;
131
132 foreach ( $users as $user_id ) {
133 if ( upstream_show_users_name() ) {
134 if ( $is_after_first_item ) {
135 $text .= ',&nbsp;';
136 }
137
138 $is_after_first_item = true;
139 }
140
141 $text .= upstream_user_avatar( $user_id );
142 }
143 $text .= '</li></ul>';
144 } else {
145 $text .= '<span class="text-muted"><i>' . esc_html( '(' . __( 'none', 'upstream' ) . ')' ) . '</i></span>';
146 }
147 return array( $users, $text );
148 }
149
150 /**
151 * Upstream Output Project Members
152 *
153 * @param mixed $id ID.
154 * @return void
155 */
156 function upstream_output_project_members( $id = null ) {
157 $users = (array) upstream_project_users( $id );
158
159 if ( count( $users ) > 0 ) {
160 ?>
161 <ul class="list-inline">
162 <li>
163 <?php
164 $is_after_first_item = false;
165
166 foreach ( $users as $user_id ) {
167 if ( upstream_show_users_name() ) {
168 if ( $is_after_first_item ) {
169 echo ',&nbsp;';
170 }
171
172 $is_after_first_item = true;
173 }
174
175 echo wp_kses_post( upstream_user_avatar( $user_id ) );
176 }
177 ?>
178 </li>
179 </ul>
180 <?php } else { ?>
181 <span class="text-muted"><i><?php echo esc_html( '(' . __( 'none', 'upstream' ) . ')' ); ?></i></span>
182 <?php
183 }
184 }
185
186 /**
187 * Upstream Get File Preview
188 *
189 * @param mixed $attachment_id Attachment Id.
190 * @param mixed $attachment_url Attachment Url.
191 * @param mixed $use_li Use Li.
192 */
193 function upstream_get_file_preview( $attachment_id, $attachment_url, $use_li = true ) {
194 $use_li = (bool) $use_li;
195 $filetype = wp_check_filetype( $attachment_url );
196 $filename = basename( $attachment_url );
197
198 $output = '';
199
200 if ( $use_li ) {
201 $output = '<li>';
202 }
203
204 if ( wp_get_attachment_image( $attachment_id, 'thumbnail' ) ) {
205 $output .= '<a target="_blank" href="' . esc_url( $attachment_url ) . '">' . wp_get_attachment_image(
206 $attachment_id,
207 array( 32, 32 ),
208 false,
209 array(
210 'title' => esc_attr( $filename ),
211 'data-toggle' => 'tooltip',
212 'data-placement' => 'top',
213 'data-fileid' => (int) $attachment_id,
214 'data-fileurl' => esc_attr( $attachment_url ),
215 'class' => 'avatar itemfile',
216 )
217 ) . '</a>';
218 } else {
219 switch ( $filetype['ext'] ) {
220 case 'pdf':
221 $icon = 'fa-file-pdf-o';
222 break;
223 case 'csv':
224 case 'xls':
225 case 'xlsx':
226 $icon = 'fa-file-excel-o';
227 break;
228 case 'doc':
229 case 'docx':
230 $icon = 'fa-file-word-o';
231 break;
232 case 'ppt':
233 case 'pptx':
234 case 'pps':
235 case 'ppsx':
236 case 'key':
237 $icon = 'fa-file-powerpoint-o';
238 break;
239 case 'zip':
240 case 'rar':
241 case 'tar':
242 $icon = 'fa-file-zip-o';
243 break;
244 case 'mp3':
245 case 'm4a':
246 case 'ogg':
247 case 'wav':
248 $icon = 'fa-file-audio-o';
249 break;
250 case 'mp4':
251 case 'm4v':
252 case 'mov':
253 case 'wmv':
254 case 'avi':
255 case 'mpg':
256 case 'ogv':
257 case '3gp':
258 case '3g2':
259 $icon = 'fa-file-video-o';
260 break;
261 default:
262 $icon = 'fa-file-text-o';
263 break;
264 };
265
266 $output = '';
267 if ( $use_li ) {
268 $output = '<li>';
269 }
270
271 $output .= '<a target="_blank" href="' . esc_url( $attachment_url ) . '"><i class="itemfile fa ' . esc_attr( $icon ) . '" data-toggle="tooltip" data-placement="top" data-fileid="' . (int) $attachment_id . '" data-fileurl="' . esc_attr( $attachment_url ) . '" title="' . esc_attr( $filename ) . '"></i></a>';
272 }
273
274 if ( $use_li ) {
275 $output .= '</li>';
276 }
277
278 return $output;
279 }
280
281 /**
282 * Upstream Output File List
283 *
284 * @param string $img_size Img Size.
285 */
286 function upstream_output_file_list( $img_size = 'thumbnail' ) {
287 // Get the list of files.
288 $files = get_post_meta( upstream_post_id(), '_upstream_project_files', true );
289 $file = array();
290
291 if ( $files ) {
292 foreach ( $files as $i => $filedata ) {
293 if ( isset( $filedata['file'] ) && isset( $filedata['file_id'] ) && '' !== $filedata['file'] ) {
294 $file[] = upstream_get_file_preview( $filedata['file_id'], $filedata['file'] );
295 }
296 }
297 }
298
299 if ( $file ) {
300 // loop through the rows.
301 $output = '<ul class="list-inline">';
302 foreach ( $file as $li ) {
303 if ( isset( $filedata['file'] ) && isset( $filedata['file_id'] ) && '' !== $filedata['file'] ) {
304 $output .= $li;
305 }
306 }
307 $output .= '</ul>';
308 } else {
309 $output = '<p>' . __( 'Currently no files', 'upstream' ) . '</p>';
310 }
311
312 return $output;
313 }
314
315 /**
316 * Upstream Frontend Output Comment
317 *
318 * @param mixed $row Row.
319 * @param mixed $row_index Row Index.
320 * @param mixed $project_id Project Id.
321 * @return void
322 */
323 function upstream_frontend_output_comment( $row, $row_index, $project_id ) {
324 ?>
325 <div class="media o-comment" id="comment-<?php echo esc_attr( $row->id ); ?>" data-id="<?php echo esc_attr( $row->id ); ?>">
326 <div class="media-left">
327 <img class="media-object o-comment__creator_profilepic" src="<?php echo esc_url( $row->created_by->avatar ); ?>"
328 alt="<?php echo esc_attr( $row->created_by->name ); ?>" width="40"/>
329 </div>
330 <div class="media-body">
331 <div class="o-comment__header">
332 <h5 class="media-heading o-comment__creator_name"><?php echo esc_html( $row->created_by->name ); ?></h5>
333 <?php if ( isset( $row->parent ) && null !== $row->parent ) : ?>
334 <div
335 class="o-comment__replier">
336 <?php
337 printf(
338 '%s <a href="#comment-%s" class="text-info" data-action="comment.go_to_reply">%s</a>',
339 esc_html__( 'In reply to', 'upstream' ),
340 esc_attr( $row->parent->id ),
341 esc_html( $row->parent->created_by->name )
342 );
343 ?>
344 </div>
345 <?php endif; ?>
346 <time datetime="<?php echo esc_attr( $row->created_at->iso_8601 ); ?>" data-delay="500" data-toggle="tooltip"
347 data-placement="top" title="<?php echo esc_attr( $row->created_at->formatted ); ?>"
348 class="o-comment__created_at"><?php echo esc_html( $row->created_at->human ); ?></time>
349 </div>
350 <div class="o-comment__content"><?php echo wp_kses_post( $row->comment ); ?></div>
351 <div class="o-comment__footer">
352 <?php do_action( 'upstream:frontend.project.discussion:comment_footer', $project_id, $row ); ?>
353 </div>
354 </div>
355 </div>
356 <?php
357 }
358