| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
namespace Jet_Form_Builder\Classes\Http; |
| 5 |
|
| 6 |
use Jet_Form_Builder\Addons\Manager; |
| 7 |
use Jet_Form_Builder\Classes\Theme\Theme_Info; |
| 8 |
|
| 9 |
// If this file is called directly, abort. |
| 10 |
if ( ! defined( 'WPINC' ) ) { |
| 11 |
die; |
| 12 |
} |
| 13 |
|
| 14 |
class Utm_Url { |
| 15 |
|
| 16 |
private $source = ''; |
| 17 |
private $medium = ''; |
| 18 |
private $campaign = ''; |
| 19 |
private $content = ''; |
| 20 |
|
| 21 |
public function __construct( string $source = '' ) { |
| 22 |
if ( $source ) { |
| 23 |
$this->set_source( $source ); |
| 24 |
} |
| 25 |
} |
| 26 |
|
| 27 |
public function add_query( string $url ): string { |
| 28 |
return add_query_arg( |
| 29 |
iterator_to_array( $this->generate_args() ), |
| 30 |
$url |
| 31 |
); |
| 32 |
} |
| 33 |
|
| 34 |
|
| 35 |
public function get_license_and_theme( bool $check_license = false ): string { |
| 36 |
$page = jet_fb_current_page(); |
| 37 |
if ( ! $page ) { |
| 38 |
$author_slug = ( new Theme_Info() )->author_slug(); |
| 39 |
} else { |
| 40 |
$author_slug = $page->theme()->author_slug(); |
| 41 |
} |
| 42 |
$license = $check_license |
| 43 |
? jet_form_builder()->addons_manager->get_slug() |
| 44 |
: Manager::NOT_ACTIVE; |
| 45 |
|
| 46 |
return "$license/$author_slug"; |
| 47 |
} |
| 48 |
|
| 49 |
private function generate_args(): \Generator { |
| 50 |
if ( $this->source ) { |
| 51 |
yield 'utm_source' => rawurlencode( $this->source ); |
| 52 |
} |
| 53 |
|
| 54 |
if ( $this->get_medium() ) { |
| 55 |
yield 'utm_medium' => rawurlencode( $this->get_medium() ); |
| 56 |
} |
| 57 |
|
| 58 |
if ( $this->campaign ) { |
| 59 |
yield 'utm_campaign' => rawurlencode( $this->campaign ); |
| 60 |
} |
| 61 |
|
| 62 |
if ( $this->content ) { |
| 63 |
yield 'utm_content' => rawurlencode( $this->content ); |
| 64 |
} |
| 65 |
} |
| 66 |
|
| 67 |
public function set_campaign( string $campaign ): Utm_Url { |
| 68 |
$this->campaign = $campaign; |
| 69 |
|
| 70 |
return $this; |
| 71 |
} |
| 72 |
|
| 73 |
public function set_source( string $source ): Utm_Url { |
| 74 |
$this->source = $source; |
| 75 |
|
| 76 |
return $this; |
| 77 |
} |
| 78 |
|
| 79 |
/** |
| 80 |
* @param string $content |
| 81 |
*/ |
| 82 |
public function set_content( string $content ) { |
| 83 |
$this->content = $content; |
| 84 |
} |
| 85 |
|
| 86 |
/** |
| 87 |
* @param string $medium |
| 88 |
*/ |
| 89 |
public function set_medium( string $medium ) { |
| 90 |
$this->medium = $medium; |
| 91 |
} |
| 92 |
|
| 93 |
public function get_medium(): string { |
| 94 |
if ( ! $this->medium ) { |
| 95 |
$this->medium = $this->get_license_and_theme(); |
| 96 |
} |
| 97 |
|
| 98 |
return $this->medium; |
| 99 |
} |
| 100 |
|
| 101 |
|
| 102 |
} |
| 103 |
|