1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Activity entity class. |
5
|
|
|
* |
6
|
|
|
* @package WordPoints_BuddyPress |
7
|
|
|
* @since 1.0.0 |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* Represents a BuddyPress activity item. |
12
|
|
|
* |
13
|
|
|
* @since 1.0.0 |
14
|
|
|
*/ |
15
|
|
|
class WordPoints_BP_Entity_Activity extends WordPoints_BP_Entity { |
|
|
|
|
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* The activity type this object represents. |
19
|
|
|
* |
20
|
|
|
* Leaving this unset means that it represents any type of activity. |
21
|
|
|
* |
22
|
|
|
* @since 1.2.1 |
23
|
|
|
* |
24
|
|
|
* @var string |
25
|
|
|
*/ |
26
|
|
|
protected $bp_activity_type; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* The component that the activity this object represents is from. |
30
|
|
|
* |
31
|
|
|
* Leaving this unset means that it can be from any component. |
32
|
|
|
* |
33
|
|
|
* @since 1.2.0 |
34
|
|
|
* |
35
|
|
|
* @var string |
36
|
|
|
*/ |
37
|
|
|
protected $bp_activity_component; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @since 1.0.0 |
41
|
|
|
*/ |
42
|
|
|
protected $bp_component = 'activity'; |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @since 1.0.0 |
46
|
|
|
*/ |
47
|
|
|
protected $id_field = 'id'; |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @since 1.2.1 |
51
|
|
|
*/ |
52
|
|
|
protected $id_is_int = true; |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @since 1.0.0 |
56
|
|
|
*/ |
57
|
|
|
protected function get_entity( $id ) { |
58
|
|
|
|
59
|
|
|
$entity = new BP_Activity_Activity( $id ); |
60
|
|
|
|
61
|
|
|
// We check this instead of the ID because the ID is always set. |
62
|
|
|
// See https://buddypress.trac.wordpress.org/ticket/7394 |
63
|
|
|
if ( ! $entity->component ) { |
64
|
|
|
return false; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
return $entity; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* @since 1.0.0 |
72
|
|
|
*/ |
73
|
|
|
public function get_title() { |
74
|
|
|
return __( 'Activity', 'wordpoints-bp' ); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* @since 1.0.0 |
79
|
|
|
*/ |
80
|
|
|
protected function get_entity_human_id( $entity ) { |
81
|
|
|
|
82
|
|
|
if ( empty( $entity->content ) ) { |
83
|
|
|
return $entity->action; |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
// Back-compat for BuddyPress <2.8. |
87
|
|
|
if ( function_exists( 'bp_activity_get_excerpt_length' ) ) { |
88
|
|
|
|
89
|
|
|
$excerpt_length = bp_activity_get_excerpt_length(); |
90
|
|
|
|
91
|
|
|
} else { |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* Filters the excerpt length for the activity excerpt. |
95
|
|
|
* |
96
|
|
|
* @param int $length Character length for activity excerpts. |
97
|
|
|
*/ |
98
|
|
|
$excerpt_length = (int) apply_filters( 'bp_activity_excerpt_length', 358 ); // WPCS: prefix OK. |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
// Based on bp_get_activity_latest_update(). |
102
|
|
|
return trim( |
103
|
|
|
strip_tags( bp_create_excerpt( $entity->content, $excerpt_length ) ) |
104
|
|
|
); |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
/** |
108
|
|
|
* @since 1.2.1 |
109
|
|
|
*/ |
110
|
|
|
public function get_storage_info() { |
111
|
|
|
|
112
|
|
|
$storage_info = parent::get_storage_info(); |
113
|
|
|
|
114
|
|
|
if ( isset( $this->bp_activity_component ) ) { |
115
|
|
|
$storage_info['info']['conditions'][] = array( |
116
|
|
|
'field' => 'component', |
117
|
|
|
'value' => $this->bp_activity_component, |
118
|
|
|
); |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
if ( isset( $this->bp_activity_type ) ) { |
122
|
|
|
$storage_info['info']['conditions'][] = array( |
123
|
|
|
'field' => 'type', |
124
|
|
|
'value' => $this->bp_activity_type, |
125
|
|
|
); |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
return $storage_info; |
129
|
|
|
} |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
// EOF |
133
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.