-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathhelpers.php
127 lines (108 loc) · 2.34 KB
/
helpers.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
<?php if ( ! defined( 'FW' ) ) {
die( 'Forbidden' );
}
/**
* Get all course lessons
*
* @param int $post_id
*
* @return WP_Post[]
*/
function fw_ext_learning_get_course_lessons( $post_id ) {
/**
* @var FW_Extension_Learning $learning
*/
$learning = fw()->extensions->get( 'learning' );
if ( ! $learning->is_course( $post_id ) ) {
return array();
}
return get_posts( array(
'post_type' => $learning->get_lesson_post_type(),
'posts_per_page' => 300,
'post_parent' => $post_id,
'order' => 'ASC'
) );
}
/**
* Get previous lesson
*
* @param int $post_id
*
* @return WP_Post|null
*/
function fw_ext_learning_get_previous_lesson( $post_id = null ) {
/**
* @var FW_Extension_Learning $learning
*/
$learning = fw()->extensions->get( 'learning' );
return $learning->get_previous_lesson( $post_id );
}
/**
* Get next lesson
*
* @param int $post_id
*
* @return WP_Post|null
*/
function fw_ext_learning_get_next_lesson( $post_id = null ) {
/**
* @var FW_Extension_Learning $learning
*/
$learning = fw()->extensions->get( 'learning' );
return $learning->get_next_lesson( $post_id );
}
/**
* Converts lesson post format into FontAwesome font class
*
* @param int $post_id
*
* @return string
*/
function fw_ext_learning_get_lesson_type( $post_id ) {
/**
* @var FW_Extension_Learning $learning
*/
$learning = fw()->extensions->get( 'learning' );
if ( ! $learning->is_lesson( $post_id ) ) {
return array();
}
$format = get_post_format( $post_id );
switch ( $format ) {
case 'image' :
$type = 'fa-image';
break;
case 'video' :
$type = 'fa-play';
break;
case 'audio' :
$type = 'fa-music';
break;
default :
$type = 'fa-book';
}
return $type;
}
/**
* Returns first n words from string
*
* @param string $string
* @param int $count
* @param string $suffix
*
* @return string
*/
function fw_ext_learning_get_words( $string = '', $count = 10, $suffix = '' ) {
if ( empty( $string ) || ! is_string( $string ) ) {
return '';
}
$string = strip_shortcodes( strip_tags( $string ) );
$count = ( (int) $count == 0 ) ? 10 : (int) $count;
if ( str_word_count( $string ) < $count ) {
if ( strlen( $string ) == 0 ) {
return '';
}
return $string . $suffix;
}
$string = implode( ' ', array_slice( explode( ' ', $string ), 0, $count ) );
return $string . $suffix;
}