| 1 |
<?php |
| 2 |
/** |
| 3 |
* Extension Abstract |
| 4 |
* |
| 5 |
* @package NotificationX\Extensions |
| 6 |
*/ |
| 7 |
|
| 8 |
namespace NotificationX\Types; |
| 9 |
|
| 10 |
use NotificationX\Core\Rules; |
| 11 |
use NotificationX\Types\Traits\Conversions as TraitsConversions; |
| 12 |
use NotificationX\Extensions\GlobalFields; |
| 13 |
use NotificationX\GetInstance; |
| 14 |
use NotificationX\Modules; |
| 15 |
use NotificationX\NotificationX; |
| 16 |
|
| 17 |
/** |
| 18 |
* Extension Abstract for all Extension. |
| 19 |
* @method static Conversions get_instance($args = null) |
| 20 |
*/ |
| 21 |
class Conversions extends Types { |
| 22 |
/** |
| 23 |
* Instance of Admin |
| 24 |
* |
| 25 |
* @var Admin |
| 26 |
*/ |
| 27 |
use GetInstance; |
| 28 |
use TraitsConversions; |
| 29 |
|
| 30 |
// colored_themes |
| 31 |
public $priority = 5; |
| 32 |
public $themes = []; |
| 33 |
public $module = [ |
| 34 |
'modules_edd', |
| 35 |
'modules_custom_notification', |
| 36 |
'modules_zapier', |
| 37 |
'modules_bitintegration', |
| 38 |
'modules_freemius', |
| 39 |
'modules_envato', |
| 40 |
]; |
| 41 |
|
| 42 |
public $conversions_count = array('conversions_conv-theme-seven', 'conversions_conv-theme-eight', 'conversions_conv-theme-nine','woocommerce_sales_conv-theme-seven', 'woocommerce_sales_conv-theme-eight', 'woocommerce_sales_conv-theme-nine'); |
| 43 |
public $map_dependency = []; |
| 44 |
|
| 45 |
|
| 46 |
public $default_source = 'woocommerce'; |
| 47 |
public $default_theme = 'conversions_theme-one'; |
| 48 |
public $default_res_theme = 'conversions_res-theme-one'; |
| 49 |
public $link_type = 'product_page'; |
| 50 |
|
| 51 |
/** |
| 52 |
* Initially Invoked when initialized. |
| 53 |
*/ |
| 54 |
public function __construct(){ |
| 55 |
parent::__construct(); |
| 56 |
$this->id = 'conversions'; |
| 57 |
} |
| 58 |
|
| 59 |
public function init() |
| 60 |
{ |
| 61 |
parent::init(); |
| 62 |
$this->title = __('Sales Notification', 'notificationx'); |
| 63 |
// nx_colored_themes |
| 64 |
$common_fields = [ |
| 65 |
'first_param' => 'tag_name', |
| 66 |
'custom_first_param' => __('Someone' , 'notificationx'), |
| 67 |
'second_param' => __('just purchased', 'notificationx'), |
| 68 |
'third_param' => 'tag_product_title', |
| 69 |
'custom_third_param' => __('Anonymous Product', 'notificationx'), |
| 70 |
'fourth_param' => 'tag_time', |
| 71 |
'custom_fourth_param' => __( 'Some time ago', 'notificationx' ), |
| 72 |
]; |
| 73 |
$this->themes = [ |
| 74 |
'theme-one' => [ |
| 75 |
'source' => NOTIFICATIONX_ADMIN_URL . 'images/extensions/themes/nx-conv-theme-2.jpg', |
| 76 |
'image_shape' => 'square', |
| 77 |
'template' => $common_fields, |
| 78 |
], |
| 79 |
'theme-two' => [ |
| 80 |
'source' => NOTIFICATIONX_ADMIN_URL . 'images/extensions/themes/nx-conv-theme-1.jpg', |
| 81 |
'image_shape' => 'square', |
| 82 |
'template' => $common_fields, |
| 83 |
], |
| 84 |
'theme-three' => [ |
| 85 |
'source' => NOTIFICATIONX_ADMIN_URL . 'images/extensions/themes/nx-conv-theme-3.jpg', |
| 86 |
'image_shape' => 'square', |
| 87 |
'template' => $common_fields, |
| 88 |
], |
| 89 |
'theme-five' => array( |
| 90 |
'source' => NOTIFICATIONX_ADMIN_URL . 'images/extensions/themes/pro/nx-conv-theme-five.png', |
| 91 |
'image_shape' => 'circle', |
| 92 |
'template' => $common_fields, |
| 93 |
), |
| 94 |
'theme-four' => array( |
| 95 |
'is_pro' => true, |
| 96 |
'source' => NOTIFICATIONX_ADMIN_URL . 'images/extensions/themes/pro/nx-conv-theme-four.png', |
| 97 |
'image_shape' => 'circle', |
| 98 |
'template' => $common_fields, |
| 99 |
), |
| 100 |
// @todo pro map theme |
| 101 |
'conv-theme-six' => array( |
| 102 |
'is_pro' => true, |
| 103 |
'source' => NOTIFICATIONX_ADMIN_URL . 'images/extensions/themes/pro/nx-conv-theme-6.jpg', |
| 104 |
'image_shape' => 'circle', |
| 105 |
), |
| 106 |
// @todo pro map theme |
| 107 |
'maps_theme' => array( |
| 108 |
'is_pro' => true, |
| 109 |
'source' => NOTIFICATIONX_ADMIN_URL . 'images/extensions/themes/pro/maps-theme.png', |
| 110 |
'image_shape' => 'square', |
| 111 |
'show_notification_image' => 'maps_image', |
| 112 |
), |
| 113 |
'conv-theme-ten' => array( |
| 114 |
'is_pro' => true, |
| 115 |
'source' => NOTIFICATIONX_ADMIN_URL . 'images/extensions/themes/nx-conv-theme-4.png', |
| 116 |
'image_shape' => 'rounded', |
| 117 |
'defaults' => [ |
| 118 |
'link_button' => true, |
| 119 |
'link_button_text' => __( 'Buy Now','notificationx' ), |
| 120 |
], |
| 121 |
'template' => $common_fields, |
| 122 |
), |
| 123 |
'conv-theme-eleven' => array( |
| 124 |
'is_pro' => true, |
| 125 |
'source' => NOTIFICATIONX_ADMIN_URL . 'images/extensions/themes/nx-conv-theme-5.png', |
| 126 |
'image_shape' => 'rounded', |
| 127 |
'defaults' => [ |
| 128 |
'link_button' => true, |
| 129 |
'link_button_text' => __( 'Buy Now','notificationx' ), |
| 130 |
], |
| 131 |
'template' => $common_fields, |
| 132 |
), |
| 133 |
'conv-theme-seven' => array( |
| 134 |
'is_pro' => true, |
| 135 |
'source' => NOTIFICATIONX_ADMIN_URL . 'images/extensions/themes/pro/nx-conv-theme-7.png', |
| 136 |
'image_shape' => 'rounded', |
| 137 |
), |
| 138 |
'conv-theme-eight' => array( |
| 139 |
'is_pro' => true, |
| 140 |
'source' => NOTIFICATIONX_ADMIN_URL . 'images/extensions/themes/pro/nx-conv-theme-8.png', |
| 141 |
'image_shape' => 'circle', |
| 142 |
|
| 143 |
), |
| 144 |
'conv-theme-nine' => array( |
| 145 |
'is_pro' => true, |
| 146 |
'source' => NOTIFICATIONX_ADMIN_URL . 'images/extensions/themes/pro/nx-conv-theme-9.png', |
| 147 |
'image_shape' => 'rounded', |
| 148 |
), |
| 149 |
]; |
| 150 |
$this->res_themes = [ |
| 151 |
'res-theme-one' => [ |
| 152 |
'source' => NOTIFICATIONX_ADMIN_URL . 'images/extensions/themes/res_conv/nx-conv-res-theme-1.png', |
| 153 |
'_template' => 'woo_template_new', |
| 154 |
'is_pro' => true, |
| 155 |
], |
| 156 |
'res-theme-two' => [ |
| 157 |
'source' => NOTIFICATIONX_ADMIN_URL . 'images/extensions/themes/res_conv/nx-conv-res-theme-2.png', |
| 158 |
'_template' => 'woo_template_new', |
| 159 |
'is_pro' => true, |
| 160 |
], |
| 161 |
'res-theme-three' => [ |
| 162 |
'source' => NOTIFICATIONX_ADMIN_URL . 'images/extensions/themes/res_conv/nx-conv-res-theme-3.png', |
| 163 |
'_template' => 'woo_template_new', |
| 164 |
'is_pro' => true, |
| 165 |
], |
| 166 |
'res-theme-four' => [ |
| 167 |
'source' => NOTIFICATIONX_ADMIN_URL . 'images/extensions/themes/res_conv/nx-conv-res-theme-4.png', |
| 168 |
'_template' => 'woo_template_new', |
| 169 |
'is_pro' => true, |
| 170 |
], |
| 171 |
'res-theme-five' => [ |
| 172 |
'source' => NOTIFICATIONX_ADMIN_URL . 'images/extensions/themes/res_conv/nx-conv-res-theme-5.png', |
| 173 |
'_template' => 'maps_template_new', |
| 174 |
'is_pro' => true, |
| 175 |
], |
| 176 |
'res-theme-six' => [ |
| 177 |
'source' => NOTIFICATIONX_ADMIN_URL . 'images/extensions/themes/res_conv/nx-conv-res-theme-6.png', |
| 178 |
'_template' => 'maps_template_new', |
| 179 |
'is_pro' => true, |
| 180 |
], |
| 181 |
'res-theme-seven' => [ |
| 182 |
'source' => NOTIFICATIONX_ADMIN_URL . 'images/extensions/themes/res_conv/nx-conv-res-theme-7.png', |
| 183 |
'_template' => 'woo_template_new', |
| 184 |
'is_pro' => true, |
| 185 |
], |
| 186 |
'res-theme-eight' => [ |
| 187 |
'source' => NOTIFICATIONX_ADMIN_URL . 'images/extensions/themes/res_conv/nx-conv-res-theme-8.png', |
| 188 |
'_template' => 'woo_template_new', |
| 189 |
'is_pro' => true, |
| 190 |
], |
| 191 |
'res-theme-nine' => [ |
| 192 |
'source' => NOTIFICATIONX_ADMIN_URL . 'images/extensions/themes/res_conv/nx-conv-res-theme-9.png', |
| 193 |
'_template' => 'woo_template_sales_count', |
| 194 |
'is_pro' => true, |
| 195 |
], |
| 196 |
'res-theme-ten' => [ |
| 197 |
'source' => NOTIFICATIONX_ADMIN_URL . 'images/extensions/themes/res_conv/nx-conv-res-theme-10.png', |
| 198 |
'_template' => 'woo_template_sales_count', |
| 199 |
'is_pro' => true, |
| 200 |
], |
| 201 |
'res-theme-eleven' => [ |
| 202 |
'source' => NOTIFICATIONX_ADMIN_URL . 'images/extensions/themes/res_conv/nx-conv-res-theme-11.png', |
| 203 |
'_template' => 'woo_template_sales_count', |
| 204 |
'is_pro' => true, |
| 205 |
], |
| 206 |
]; |
| 207 |
$this->templates = [ |
| 208 |
'woo_template_new' => [ |
| 209 |
'first_param' => GlobalFields::get_instance()->common_name_fields(), |
| 210 |
'third_param' => [ |
| 211 |
'tag_product_title' => __('Product Title', 'notificationx'), |
| 212 |
], |
| 213 |
'fourth_param' => [ |
| 214 |
'tag_time' => __('Definite Time', 'notificationx'), |
| 215 |
], |
| 216 |
'_themes' => [ |
| 217 |
'conversions_theme-one', |
| 218 |
'conversions_theme-two', |
| 219 |
'conversions_theme-three', |
| 220 |
'conversions_theme-four', |
| 221 |
'conversions_theme-five', |
| 222 |
'conversions_conv-theme-ten', |
| 223 |
'conversions_conv-theme-eleven', |
| 224 |
'woocommerce_sales_theme-one', |
| 225 |
'woocommerce_sales_theme-two', |
| 226 |
'woocommerce_sales_theme-three', |
| 227 |
'woocommerce_sales_theme-four', |
| 228 |
'woocommerce_sales_theme-five', |
| 229 |
'woocommerce_sales_conv-theme-ten', |
| 230 |
'woocommerce_sales_conv-theme-eleven', |
| 231 |
] |
| 232 |
], |
| 233 |
'woo_template_sales_count' => [ |
| 234 |
'first_param' => GlobalFields::get_instance()->common_name_fields(), |
| 235 |
'third_param' => [ |
| 236 |
'tag_product_title' => __('Product Title', 'notificationx'), |
| 237 |
], |
| 238 |
'fourth_param' => [ |
| 239 |
// 'tag_time' => __('Definite Time', 'notificationx'), |
| 240 |
], |
| 241 |
'_themes' => [ |
| 242 |
'conversions_conv-theme-six', |
| 243 |
'conversions_conv-theme-seven', |
| 244 |
'conversions_conv-theme-eight', |
| 245 |
'conversions_conv-theme-nine', |
| 246 |
'woocommerce_sales_conv-theme-six', |
| 247 |
'woocommerce_sales_conv-theme-seven', |
| 248 |
'woocommerce_sales_conv-theme-eight', |
| 249 |
'woocommerce_sales_conv-theme-nine', |
| 250 |
] |
| 251 |
], |
| 252 |
]; |
| 253 |
} |
| 254 |
|
| 255 |
/** |
| 256 |
* Hooked to nx_before_metabox_load action. |
| 257 |
* |
| 258 |
* @return void |
| 259 |
*/ |
| 260 |
public function init_fields() { |
| 261 |
parent::init_fields(); |
| 262 |
} |
| 263 |
|
| 264 |
/** |
| 265 |
* @todo remove in the future. |
| 266 |
* |
| 267 |
* @param [type] $data |
| 268 |
* @param [type] $settings |
| 269 |
* @return void |
| 270 |
*/ |
| 271 |
public function nx_can_entry($return, $entry, $settings){ |
| 272 |
if(!($this->_excludes_product($entry['data'], $settings) && $this->_show_purchaseof($entry['data'], $settings))){ |
| 273 |
return false; |
| 274 |
} |
| 275 |
|
| 276 |
return $return; |
| 277 |
} |
| 278 |
|
| 279 |
/** |
| 280 |
* @todo remove in the future. |
| 281 |
* |
| 282 |
* @param [type] $data |
| 283 |
* @param [type] $settings |
| 284 |
* @return void |
| 285 |
*/ |
| 286 |
public function show_exclude_product( $data, $settings ){ |
| 287 |
$new_data = []; |
| 288 |
|
| 289 |
if( ! empty( $data ) ) { |
| 290 |
foreach( $data as $key => $product ) { |
| 291 |
if( $this->_excludes_product($product, $settings) && $this->_show_purchaseof($product, $settings) ) { |
| 292 |
$new_data[ $key ] = $product; |
| 293 |
} |
| 294 |
} |
| 295 |
} |
| 296 |
|
| 297 |
return $new_data; |
| 298 |
|
| 299 |
} |
| 300 |
|
| 301 |
public function _excludes_product( $product, $settings ){ |
| 302 |
if( empty( $settings['product_exclude_by'] ) || $settings['product_exclude_by'] === 'none' ) { |
| 303 |
return true; |
| 304 |
} |
| 305 |
|
| 306 |
$product_category_list = []; |
| 307 |
|
| 308 |
$product_id = $product['product_id']; |
| 309 |
if( $settings['product_exclude_by'] == 'product_category' ) { |
| 310 |
$term = 'product_cat'; |
| 311 |
if($settings['source'] == 'edd' || $settings['source'] == 'edd_inline'){ |
| 312 |
$term = 'download_category'; |
| 313 |
} |
| 314 |
$product_categories = get_the_terms( $product_id, $term ); |
| 315 |
if( ! is_wp_error( $product_categories ) ) { |
| 316 |
foreach( $product_categories as $category ) { |
| 317 |
$product_category_list[] = $category->slug; |
| 318 |
} |
| 319 |
} |
| 320 |
|
| 321 |
$product_category_count = count( $product_category_list ); |
| 322 |
$array_diff = array_diff( $product_category_list, $settings['exclude_categories'] ); |
| 323 |
$array_diff_count = count( $array_diff ); |
| 324 |
|
| 325 |
if( ! ( $array_diff_count < $product_category_count ) ) { |
| 326 |
return true; |
| 327 |
} |
| 328 |
$product_category_list = []; |
| 329 |
} |
| 330 |
if( $settings['product_exclude_by'] == 'manual_selection' ) { |
| 331 |
if( isset($settings['exclude_products']) && is_array($settings['exclude_products']) && ! in_array( $product_id, $settings['exclude_products'] ) ) { |
| 332 |
return true; |
| 333 |
} |
| 334 |
} |
| 335 |
|
| 336 |
return false; |
| 337 |
|
| 338 |
} |
| 339 |
|
| 340 |
|
| 341 |
public function _show_purchaseof( $product, $settings ){ |
| 342 |
if( empty( $settings['product_control'] ) || $settings['product_control'] === 'none' ) { |
| 343 |
return true; |
| 344 |
} |
| 345 |
|
| 346 |
$product_category_list = []; |
| 347 |
|
| 348 |
$product_id = $product['product_id']; |
| 349 |
if( $settings['product_control'] == 'product_category' ) { |
| 350 |
$term = 'product_cat'; |
| 351 |
if($settings['source'] == 'edd' || $settings['source'] == 'edd_inline'){ |
| 352 |
$term = 'download_category'; |
| 353 |
} |
| 354 |
$product_categories = get_the_terms( $product_id, $term ); |
| 355 |
if(is_array($product_categories) && ! is_wp_error( $product_categories ) ) { |
| 356 |
foreach( $product_categories as $category ) { |
| 357 |
$product_category_list[] = $category->slug; |
| 358 |
} |
| 359 |
} |
| 360 |
|
| 361 |
$product_category_count = count( $product_category_list ); |
| 362 |
$array_diff = array_diff( $product_category_list, $settings['category_list'] ); |
| 363 |
$array_diff_count = count( $array_diff ); |
| 364 |
|
| 365 |
if( $array_diff_count < $product_category_count ) { |
| 366 |
return true; |
| 367 |
} |
| 368 |
|
| 369 |
} |
| 370 |
if( $settings['product_control'] == 'manual_selection' ) { |
| 371 |
if( in_array( $product_id, $settings['product_list'] ) ) { |
| 372 |
return true; |
| 373 |
} |
| 374 |
} |
| 375 |
|
| 376 |
return false; |
| 377 |
} |
| 378 |
|
| 379 |
} |
| 380 |
|