PromotionManager.php
3.56 KB
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
<?php if ( ! defined( 'ABSPATH' ) ) exit;
class NF_PromotionManager
{
public $promotions;
/**
* Accepts a string of location to tell let us know where in the app we are sending promotions to.
* Then will return an array of promotions to run in the location.
*/
public function __construct()
{
$this->set_promotions();
$this->maybe_remove_personal();
$this->maybe_remove_sendwp();
$this->sort_active_promotions_by_locations();
}
public function get_promotions()
{
return $this->promotions;
}
/**
* Set our promtions array to our promotions property.
*/
private function set_promotions()
{
if ( apply_filters( 'ninja_forms_disable_marketing', false ) )
{
$this->promotions = array();
} else {
$this->promotions = Ninja_Forms()->config( 'DashboardPromotions' );
}
}
/*
* Membership Checks
*
* These funcitons all check to see if the individual add-ons that make up
* our personal membership are active.
*/
private function is_layout_styles_active()
{
return class_exists( 'NF_Layouts', false );
}
private function is_conditional_logic_active()
{
return class_exists( 'NF_ConditionalLogic', false );
}
private function is_multi_part_active()
{
return class_exists( 'NF_MultiPart', false );
}
private function is_file_uploads_active()
{
return class_exists( 'NF_FU_File_Uploads', false );
}
/**
* Utilizes the helper methods above to determine if a
* a Membership is active on a site.
*/
private function is_personal_active()
{
if (
$this->is_conditional_logic_active() &&
$this->is_file_uploads_active() &&
$this->is_layout_styles_active() &&
$this->is_multi_part_active()
) {
return true;
}
return false;
}
/**************************************************************************
* Promotion Removal Methods
*
* These funcitons all check for different add-ons/products and remove
* promotions for them if they are in use.
****************************************************************************/
private function maybe_remove_sendwp()
{
if ( phpversion() < '5.6.0' ) {
$this->remove_promotion( 'sendwp' );
return;
} if ( $this->is_sendwp_active() ) {
$this->remove_promotion( 'sendwp' );
} elseif ( $this->is_ninja_mail_active() ) {
$this->remove_promotion( 'sendwp' );
}
}
private function maybe_remove_personal()
{
if ( $this->is_personal_active() ) {
$this->remove_promotion( 'personal' );
}
}
/***************************************************************************
* Helper Methods
****************************************************************************/
/**
* Pass in a promotion type to have it removed from
* the list of active promotions.
*
* @return void
*/
private function remove_promotion( $type )
{
// Loops over promotions and removes unused types of promotions.
foreach ( $this->promotions as $promotion ) {
if ( $type == $promotion[ 'type' ] ) {
unset( $this->promotions[ $promotion[ 'id' ] ] );
}
}
}
/**
* Sorts our promotions by where they will appear in app.
*
* @return void
*/
private function sort_active_promotions_by_locations()
{
$sorted_locations = array();
foreach ( $this->promotions as $promotion ) {
$sorted_locations[ $promotion[ 'location' ] ][] = $promotion;
}
$this->promotions = $sorted_locations;
}
private function is_sendwp_active()
{
if ( class_exists( '\SendWP\Mailer', FALSE ) ) {
return true;
}
return false;
}
private function is_ninja_mail_active()
{
if ( class_exists('\NinjaMail\Plugin', FALSE ) ) {
return true;
}
return false;
}
}