/
prelauncher.php
216 lines (161 loc) · 5.58 KB
/
prelauncher.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
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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
<?php
/*
Plugin Name: Prelauncher
Plugin URI: http://prelauncher.info/docs/wordpress
Description: a plugin which allows to integrate Prelauncher (pre-launch website builder which helps new online store owners to easily build a viral pre-launch website and start referral prelaunch campaign) with Wordpress website.
Version: 1.0.3
Author: Artem Efremov
Author URI: https://ru.linkedin.com/in/efremovartyom
License: GPL2
*/
require_once dirname( __FILE__ ) . '/includes/prelauncher-settings.php';
$prelaunchr_admin = new PrelauncherSettings();
register_activation_hook( __FILE__ , "loadAPI" );
register_activation_hook( __FILE__ , array($prelaunchr_admin, 'activate' ) );
register_deactivation_hook( __FILE__ , array($prelaunchr_admin, 'deactivate' ) );
function setMetaTags(){
$ds = \Prelauncher\Constructor::metaTags();
echo $ds;
}
if ( ! class_exists( 'Prelauncher' ) ) :
class Prelauncher {
public $version = '1.0.3';
public $plugin_name = 'prelauncher';
public $companyID = null;
public $token = null;
/*
Unique identificator of subscriber
*/
public $clientID = null;
public $page_id = null;
public $add_scripts = false;
public $body = null;
/*
Associated array with company's ID and private API key
*/
public $credentials = null;
protected static $_self = null;
/*
Initialization
*/
public function __construct() {
$this->define_constants();
$this->load_dependencies();
$this->loadAPI();
$this->setCredentials();
$this->setup_hooks();
}
/*
Authenticate API calls to Prelauncher.info
*/
public function setCredentials(){
$this->credentials = get_option('prelauncher-credentials');
\Prelauncher\Settings::configure($this->credentials['company_id'], $this->credentials["private_key"]);
}
public function setup_hooks() {
add_action( 'the_posts', array( $this, 'check_for_shortcode' ) );
add_filter( "page_template",array ( $this, "get_prelauncher_template") ) ;
add_action( 'wp_enqueue_scripts', array($this, 'prelauncher_enqueue_scripts'));
}
public function load_dependencies(){
require_once(dirname( __FILE__ ) . "/lib/httpful/bootstrap.php");
require_once(dirname( __FILE__ ) . "/lib/restful/bootstrap.php");
require_once(dirname( __FILE__ ) . "/lib/prelauncher/bootstrap.php");
}
public function loadAPI(){
\Httpful\Bootstrap::init();
\RESTful\Bootstrap::init();
\Prelauncher\Bootstrap::init();
}
/*
Request HTML code of referral page
*/
public function uploadReferPage(){
$ds = \Prelauncher\Constructor::referPage();
return $ds->clients->html_version;
}
/*
Request HTML code of landing page
*/
public function uploadLandingPage(){
$ds = \Prelauncher\Constructor::landingPage();
return $ds->clients->html_version;
}
public function get_prelauncher_template($page_template){
if ( $this->add_scripts ) {
$page_template = dirname( __FILE__ ) . '/templates/index.php';
}
return $page_template;
}
public function check_for_shortcode( $posts ) {
if ( empty( $posts ) )
return $posts;
foreach ( $posts as $post ) {
if ( false !== stripos( $post->post_content, '[prelauncher' ) ) {
add_shortcode( 'prelauncher', array($this, 'prelauncher_shortcode'));
$this->add_scripts = true;
$this->page_id = $post->ID;
break;
}
}
if ($this->add_scripts)
add_action('wp_head', "setMetaTags");
return $posts;
}
public function check_theme_support() {
if ( current_theme_supports('prelauncher') && get_option('page_on_front') ) {
$this->add_scripts = true;
}
}
public static function instance() {
if ( is_null( self::$_self ) ) {
self::$_self = new self();
}
return self::$_self;
}
public function define_constants() {
define( 'PRELAUNCHER_VERSION', $this->get_version() );
define( 'PRELAUNCHER_PLUGIN_PATH', untrailingslashit( plugin_dir_path( __FILE__ ) ) );
define( 'PRELAUNCHER_TEMPLATE_PATH', PRELAUNCHER_PLUGIN_PATH . '/templates/');
define( 'PRELAUNCHER_PLUGIN_BASENAME', plugin_basename( __FILE__ ) );
}
public function get_version() {
return $this->version;
}
public function prelauncher_enqueue_scripts() {
if ( $this->add_scripts ) {
wp_enqueue_style('bootstrap', plugins_url( '/assets/stylesheets/bootstrap.min.css' , __FILE__ ), array(), "3.3.5");
wp_enqueue_style('prelauncher', plugins_url( '/assets/stylesheets/prelauncher.css' , __FILE__ ), array(), PRELAUNCHER_VERSION);
wp_enqueue_style('prelauncher-fonts', plugins_url('/assets/stylesheets/fonts.css' , __FILE__ ), array(), PRELAUNCHER_VERSION);
wp_enqueue_style('font-awesome', plugins_url( '/assets/stylesheets/font-awesome.min.css' , __FILE__ ), array(), "4.4.0");
wp_enqueue_script('prelauncher-api', plugins_url( '/assets/javascripts/prelauncher.js' , __FILE__ ), array('jquery'), PRELAUNCHER_VERSION);
}
}
public function prelauncher_get_template_part( $slug , $name = null ) {
if ( empty( $slug ) ) {
return;
}
$name = (string) $name;
if ( '' !== $name ) {
$template = "{$slug}-{$name}.php";
} else {
$template = "{$slug}.php";
}
load_template( PRELAUNCHER_TEMPLATE_PATH . $template );
}
function prelauncher_shortcode( $atts, $content = '' ){
if (empty($_GET["uid"])){
$this->prelauncher_get_template_part( 'prelauncher', 'landing' );
} else {
$this->clientID = $_GET["uid"];
$this->prelauncher_get_template_part( 'prelauncher', 'refer' );
}
return ob_get_clean();
}
}
endif;
function Prelauncher() {
return Prelauncher::instance();
}
$Prelauncher = Prelauncher();
?>