· 7 years ago · Nov 29, 2018, 11:00 AM
1<?php
2
3
4class Rational_Meta_Box
5{
6 private $screens = array('ads');
7 private $fields = array(
8 array('id' => 'sora_textarea', 'label' => 'Ad Code', 'type' => 'textarea')
9 );
10
11 /**
12 * Class construct method. Adds actions to their respective WordPress hooks.
13 */
14 public function __construct()
15 {
16 add_action('add_meta_boxes', array($this, 'add_meta_boxes'));
17 add_action('save_post', array($this, 'save_post'));
18 }
19
20 /**
21 * Hooks into WordPress' add_meta_boxes function.
22 * Goes through screens (post types) and adds the meta box.
23 */
24 public function add_meta_boxes()
25 {
26 foreach ($this->screens as $screen) {
27 add_meta_box('insert-ad-code', __('Insert Ad Code', 'rational-metabox'), array($this, 'add_meta_box_callback'), $screen, 'advanced', 'default');
28 }
29 }
30
31 /**
32 * Generates the HTML for the meta box
33 *
34 * @param object $post WordPress post object
35 */
36 public function add_meta_box_callback($post)
37 {
38 wp_nonce_field('insert_ad_code_data', 'insert_ad_code_nonce');
39 $this->generate_fields($post);
40 }
41
42 /**
43 * Generates the field's HTML for the meta box.
44 */
45 public function generate_fields($post)
46 {
47 $output = '';
48
49 foreach ($this->fields as $field) {
50 $label = '<label for="' . $field['id'] . '">' . $field['label'] . '</label>';
51 $db_value = get_post_meta($post->ID, 'insert_ad_code_' . $field['id'], true);
52
53 switch ($field['type']) {
54 case 'textarea':
55 $input = sprintf('<textarea class="large-text" id="%s" name="%s" rows="5">%s</textarea>', $field['id'], $field['id'], $db_value);
56 break;
57 }
58
59 $input = (, $field['type'] !== 'color' ? 'class="regular-text"' : '', $field['id'], $field['id'], $field['type'], $db_value);
60 $output .= $this->row_format($label, $input);
61 }
62
63 echo '<table class="form-table"><tbody>' . $output . '</tbody></table>';
64 }
65
66 /**
67 * Generates the HTML for table rows.
68 */
69 public function row_format($label, $input)
70 {
71 return sprintf('<tr><th scope="row">%s</th><td>%s</td></tr>', $label, $input);
72 }
73
74 /**
75 * Hooks into WordPress' save_post function
76 */
77 public function save_post($post_id)
78 {
79 if (!isset($_POST['insert_ad_code_nonce'])) {
80 return $post_id;
81 }
82
83 $nonce = $_POST['insert_ad_code_nonce'];
84
85 if (!wp_verify_nonce($nonce, 'insert_ad_code_data')) {
86 return $post_id;
87 }
88
89 if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
90 return $post_id;
91 }
92
93 foreach ($this->fields as $field) {
94 if (isset($_POST[$field['id']])) {
95 switch ($field['type']) {
96 case 'email':
97 $_POST[$field['id']] = sanitize_email($_POST[$field['id']]);
98 break;
99
100 case 'text':
101 $_POST[$field['id']] = sanitize_text_field($_POST[$field['id']]);
102 break;
103 }
104
105 update_post_meta($post_id, 'insert_ad_code_' . $field['id'], $_POST[$field['id']]);
106 }
107 else if ($field['type'] === 'checkbox') {
108 update_post_meta($post_id, 'insert_ad_code_' . $field['id'], '0');
109 }
110 }
111 }
112}
113
114function sora_ads()
115{
116 $labels = array('name' => _x('Ads', 'Post Type General Name', 'text_domain'), 'singular_name' => _x('Ads', 'Post Type Singular Name', 'text_domain'), 'menu_name' => __('Ads', 'text_domain'), 'name_admin_bar' => __('Ads', 'text_domain'), 'archives' => __('Ads Archives', 'text_domain'), 'parent_item_colon' => __('Parent Ads:', 'text_domain'), 'all_items' => __('All Ads', 'text_domain'), 'add_new_item' => __('Add New Ads', 'text_domain'), 'add_new' => __('Add New', 'text_domain'), 'new_item' => __('New Ads', 'text_domain'), 'edit_item' => __('Edit Ads', 'text_domain'), 'update_item' => __('Update Ads', 'text_domain'), 'view_item' => __('View Ads', 'text_domain'), 'search_items' => __('Search Ads', 'text_domain'), 'not_found' => __('Not found', 'text_domain'), 'not_found_in_trash' => __('Not found in Trash', 'text_domain'), 'featured_image' => __('Featured Image', 'text_domain'), 'set_featured_image' => __('Set featured image', 'text_domain'), 'remove_featured_image' => __('Remove featured image', 'text_domain'), 'use_featured_image' => __('Use as featured image', 'text_domain'), 'insert_into_item' => __('Insert into ads', 'text_domain'), 'uploaded_to_this_item' => __('Uploaded to this ads', 'text_domain'), 'items_list' => __('Adss list', 'text_domain'), 'items_list_navigation' => __('Adss list navigation', 'text_domain'), 'filter_items_list' => __('Filter ads list', 'text_domain'));
117 $args = array(
118 'label' => __('Ads', 'text_domain'),
119 'description' => __('Ads Management', 'text_domain'),
120 'labels' => $labels,
121 'supports' => array('title'),
122 'hierarchical' => false,
123 'public' => true,
124 'show_ui' => true,
125 'show_in_menu' => false,
126 'menu_position' => 5,
127 'show_in_admin_bar' => true,
128 'show_in_nav_menus' => true,
129 'can_export' => true,
130 'has_archive' => true,
131 'exclude_from_search' => false,
132 'publicly_queryable' => true,
133 'rewrite' => false,
134 'capability_type' => 'post'
135 );
136 register_post_type('Ads', $args);
137}
138
139function soralink_settings_link($actions, $file)
140{
141 if (false !== strpos($file, 'soralink')) {
142 $actions['settings'] = '<a href="admin.php?page=soralink_configuration">Configuration</a>';
143 }
144
145 return $actions;
146}
147
148function soralink_menu()
149{
150 add_menu_page('SoraLink Plugin Settings', 'SoraLink', 'administrator', 'soralink_configuration', 'soralink_configuration', 'dashicons-editor-code', 81);
151 add_submenu_page('soralink_configuration', 'SoraLink Configuration', 'Configuration', 'administrator', 'soralink_configuration', 'soralink_configuration');
152 add_submenu_page('soralink_configuration', 'Generate Link', 'Generate Link', 'administrator', 'soralink_generate', 'soralink_generate');
153 add_submenu_page('soralink_configuration', __('Bottom Ads', 'bottom-ads'), __('Bottom Ads', 'bottom-ads'), 'manage_options', 'edit.php?post_type=ads');
154 add_submenu_page('soralink_configuration', 'SoraLink Setup', 'Setup', 'administrator', 'soralink_setup', 'soralink_setup');
155 $submenu['soralink_configuration'][0][0] = 'Dashboard';
156 add_action('admin_init', 'register_soralink_settings');
157}
158
159function register_soralink_settings()
160{
161 register_setting('soralink-settings', 'soralinkkey');
162 register_setting('soralink-settings', 'soralinkkeycache');
163 register_setting('soralink-settings', 'secretkeyserver');
164 register_setting('soralink-settings', 'ads_top');
165 register_setting('soralink-settings', 'ads_content');
166 register_setting('soralink-settings', 'start_date');
167 register_setting('soralink-settings', 'end_date');
168 register_setting('soralink-settings', 'countdown');
169 register_setting('soralink-settings', 'countdowntop');
170 register_setting('soralink-settings', 'singlecountdown');
171}
172
173function soralink_configuration()
174{
175
176 function renderLicenseForm($errorMsg = NULL)
177 {
178 echo ' <div class="update-nag notice" style="display: block;">';
179 echo $errorMsg;
180 echo '</div>' . "\n" . ' <form class="form" method="post" action="options.php">' . "\n" . ' ';
181 settings_fields('soralink-settings');
182 echo ' ';
183 do_settings_sections('soralink-settings');
184 echo ' <input type="text" name="soralinkkey" class="regular-text" value="';
185 echo esc_attr(get_option('soralinkkey'));
186 echo '" placeholder="Insert valid license..." />' . "\n" . ' ';
187 submit_button();
188 echo ' </form>' . "\n";
189 }
190 echo '<style>' . "\n" . '.wrap {' . "\n" . ' padding: 10px 20px;' . "\n" . ' order: 1px solid #e5e5e5;' . "\n" . ' -webkit-box-shadow: 0 1px 1px rgba(0,0,0,.04);' . "\n" . ' box-shadow: 0 1px 1px rgba(0,0,0,.04);' . "\n" . ' background: #fff;' . "\n" . '}' . "\n" . '.wrap h1 {' . "\n" . ' margin: -10px -20px;' . "\n" . ' margin-bottom: 10px;' . "\n" . ' padding: 10px 20px;' . "\n" . ' font-size: 17px;' . "\n" . ' font-weight: bold;' . "\n" . ' background: #F7F7F7;' . "\n" . ' border-bottom: 1px solid #EFEFEF;' . "\n" . '}' . "\n" . '</style>' . "\n" . '<div class="wrap">' . "\n" . '<h1>SoraLink Configuration</h1>' . "\n";
191 $license_key = get_option('soralinkkey');
192
193
194 echo "\n" . '<form method="post" action="options.php">' . "\n" . ' ';
195 settings_fields('soralink-settings');
196 echo ' ';
197 do_settings_sections('soralink-settings');
198 echo ' <table class="form-table">' . "\n" . ' <tr valign="top">' . "\n" . ' <th scope="row">License</th>' . "\n" . ' <td><input type="text" name="soralinkkey" class="regular-text" value="';
199 echo esc_attr(get_option('soralinkkey'));
200 echo '" placeholder="Insert valid license..." /></td>' . "\n" . ' </tr>' . "\n" . ' <tr valign="top">' . "\n" . ' <th scope="row">Secret Key</th>' . "\n" . ' <td><input type="text" name="secretkeyserver" class="regular-text" value="';
201 echo esc_attr(get_option('secretkeyserver'));
202 echo '" placeholder="Insert your secret key..." /></td>' . "\n" . ' </tr>' . "\n" . ' <tr valign="top">' . "\n" . ' <th scope="row">Ads Top</th>' . "\n" . ' <td><textarea type="text/javascript" name="ads_top" rows="10" cols="50" value="';
203 echo esc_attr(get_option('ads_top'));
204 echo '" class="large-text code" placeholder="Place your ads code here. Recommended size 728x90">';
205 echo esc_attr(get_option('ads_top'));
206 echo '</textarea></td>' . "\n" . ' </tr>' . "\n" . ' <tr valign="top">' . "\n" . ' <th scope="row">Ads Content</th>' . "\n" . ' <td><textarea type="text/javascript" name="ads_content" rows="10" cols="50" value="';
207 echo esc_attr(get_option('ads_content'));
208 echo '" class="large-text code" placeholder="Place your ads code here. Recommended responsive size or 300x250">';
209 echo esc_attr(get_option('ads_content'));
210 echo '</textarea></td>' . "\n" . ' </tr>' . "\n" . ' <tr valign="top">' . "\n" . ' <th scope="row">Hide Ads by Range Date</th>' . "\n" . ' <td><input type="number" name="start_date" min="0" class="small-text" value="';
211 echo esc_attr(get_option('start_date'));
212 echo '" placeholder="start" />' . "\n\t" . '<label for="range">until</label>' . "\n\t" . '<input type="number" name="end_date" min="0" class="small-text" value="';
213 echo esc_attr(get_option('end_date'));
214 echo '" placeholder="end" />' . "\n\t" . '</td>' . "\n" . ' </tr>' . "\n" . ' <tr valign="top">' . "\n" . ' <th scope="row">Countdown Top</th>' . "\n" . ' <td><input type="number" name="countdowntop" min="1" class="small-text" value="';
215 echo esc_attr(get_option('countdowntop'));
216 echo '" /></td>' . "\n" . ' </tr>' . "\n" . ' <tr valign="top">' . "\n" . ' <th scope="row">Countdown Bottom</th>' . "\n" . ' <td><input type="number" name="countdown" class="small-text" value="';
217 echo esc_attr(get_option('countdown'));
218 echo '" /></td>' . "\n" . ' </tr>' . "\n" . ' <tr valign="top">' . "\n" . ' <th scope="row">Countdown Single</th>' . "\n" . ' <td><input type="number" name="singlecountdown" min="0" class="small-text" value="';
219 echo esc_attr(get_option('singlecountdown'));
220 echo '" /></td>' . "\n" . ' </tr>' . "\n" . ' </table> ' . "\n" . ' ';
221 submit_button();
222 echo "\n" . '</form>' . "\n" . '</div>' . "\n";
223}
224
225function soralink_generate()
226{
227 echo '<script language="javascript">' . "\n" . 'function select_all(obj) {' . "\n" . ' var text_val=eval(obj);' . "\n" . ' text_val.focus();' . "\n" . ' text_val.select();' . "\n" . ' if (!document.all) return; // IE only' . "\n" . ' r = text_val.createTextRange();' . "\n" . ' r.execCommand(\'copy\');' . "\n" . '}' . "\n" . 'function generatelink()' . "\n" . '{' . "\n" . 'var Base64={_keyStr:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",encode:function(e){var t="";var n,r,i,s,o,u,a;var f=0;e=Base64._utf8_encode(e);while(f<e.length){n=e.charCodeAt(f++);r=e.charCodeAt(f++);i=e.charCodeAt(f++);s=n>>2;o=(n&3)<<4|r>>4;u=(r&15)<<2|i>>6;a=i&63;if(isNaN(r)){u=a=64}else if(isNaN(i)){a=64}t=t+this._keyStr.charAt(s)+this._keyStr.charAt(o)+this._keyStr.charAt(u)+this._keyStr.charAt(a)}return t},decode:function(e){var t="";var n,r,i;var s,o,u,a;var f=0;e=e.replace(/[^A-Za-z0-9\\+\\/\\=]/g,"");while(f<e.length){s=this._keyStr.indexOf(e.charAt(f++));o=this._keyStr.indexOf(e.charAt(f++));u=this._keyStr.indexOf(e.charAt(f++));a=this._keyStr.indexOf(e.charAt(f++));n=s<<2|o>>4;r=(o&15)<<4|u>>2;i=(u&3)<<6|a;t=t+String.fromCharCode(n);if(u!=64){t=t+String.fromCharCode(r)}if(a!=64){t=t+String.fromCharCode(i)}}t=Base64._utf8_decode(t);return t},_utf8_encode:function(e){e=e.replace(/\\r\\n/g,"\\n");var t="";for(var n=0;n<e.length;n++){var r=e.charCodeAt(n);if(r<128){t+=String.fromCharCode(r)}else if(r>127&&r<2048){t+=String.fromCharCode(r>>6|192);t+=String.fromCharCode(r&63|128)}else{t+=String.fromCharCode(r>>12|224);t+=String.fromCharCode(r>>6&63|128);t+=String.fromCharCode(r&63|128)}}return t},_utf8_decode:function(e){var t="";var n=0;var r=c1=c2=0;while(n<e.length){r=e.charCodeAt(n);if(r<128){t+=String.fromCharCode(r);n++}else if(r>191&&r<224){c2=e.charCodeAt(n+1);t+=String.fromCharCode((r&31)<<6|c2&63);n+=2}else{c2=e.charCodeAt(n+1);c3=e.charCodeAt(n+2);t+=String.fromCharCode((r&15)<<12|(c2&63)<<6|c3&63);n+=3}}return t}}' . "\n" . 'generate=document.glink.generate.value;' . "\n" . 'encodedString = Base64.encode(generate);' . "\n" . 'document.glink.result.value=\'';
228 echo get_site_url();
229 echo '/?r=\'+encodedString+\'#landing\';' . "\n" . '}' . "\n" . '</script>' . "\n" . '<div class="wrap">' . "\n" . '<h1>Generate Link</h1>' . "\n" . '<form name="glink">' . "\n" . ' <table class="form-table">' . "\n" . ' <tr valign="top">' . "\n" . ' <th scope="row">Generate</th>' . "\n" . ' <td>' . "\n" . ' ' . "\t" . '<input type="url" name="generate" class="regular-text" size="60" placeholder="Insert url here..." />' . "\n" . ' ' . "\t" . '<input type="button" name="go" id="submit" class="button button-primary" value="Go" onclick="generatelink()">' . "\n" . ' </td>' . "\n" . ' </tr>' . "\n" . ' <tr valign="top">' . "\n" . ' <th scope="row">Result</th>' . "\n" . ' <td>' . "\n" . ' ' . "\t" . '<input type="text" name="result" class="large-text" placeholder="result generate link" onclick="select_all(this)" readonly/>' . "\n" . ' </td>' . "\n" . ' </tr>' . "\n" . ' </table>' . "\n" . ' </form>' . "\n" . '</div>' . "\n";
230}
231
232function soralink_setup()
233{
234 echo '<div class="wrap">' . "\n" . '<script type="text/javascript">' . "\n" . ' function select_all(obj) {' . "\n" . ' var text_val=eval(obj);' . "\n" . ' text_val.focus();' . "\n" . ' text_val.select();' . "\n" . ' if (!document.all) return; // IE only' . "\n" . ' r = text_val.createTextRange();' . "\n" . ' r.execCommand(\'copy\');' . "\n" . ' }' . "\n" . '</script>' . "\n" . '<h1>SoraLink Setup</h1>' . "\n" . '<h2>Installation</h2>' . "\n" . 'Place this code <b>after</b> <?php get_header(); ?> in index.php theme.<br>' . "\n" . '<input type="text" class="large-text code" value="<?php if(function_exists(\'humancheck_sora\')){humancheck_sora(\'Human Verification\',1);} ?>" onclick="select_all(this)" readonly /><br><br>' . "\n" . 'Place this code <b>after</b> <?php get_header(); ?> in single.php theme.<br>' . "\n" . '<input type="text" class="large-text code" value="<?php if(function_exists(\'start_sora\')){start_sora();} ?>" onclick="select_all(this)" readonly /><br><br>' . "\n" . 'Place this code <b>before</b> <?php get_footer(); ?> in single.php theme.<br>' . "\n" . '<input type="text" class="large-text code" value="<?php if(function_exists(\'end_sora\')){end_sora();} ?>" onclick="select_all(this)" readonly /><br><br>' . "\n" . 'Place this code <b>after</b> <?php get_header(); ?> in single.php theme <b>(if using single button)</b>.<br>' . "\n" . '<input type="text" class="large-text code" value="<?php if(function_exists(\'single_sora\')){single_sora();} ?>" onclick="select_all(this)" readonly /><br><br>' . "\n" . '<h2>Autolink Script</h2>' . "\n" . 'use this script if <b>SoraLink Client</b> not working<br><br>' . "\n" . '<textarea type="text/javascript" class="large-text code" rows="7" cols="50" onclick="select_all(this)" readonly>' . "\n" . '<script type="text/javascript" src="';
235 echo get_site_url();
236 echo '/wp-content/plugins/soralink/assets/js/sora.php"></script>' . "\n" . '<script type="text/javascript">' . "\n" . 'protected_links = "";' . "\n" . 'auto_safelink();' . "\n" . '</script></textarea><br/>' . "\n" . '<br/>' . "\n" . '</div>' . "\n";
237}
238
239ini_set('display_errors', false);
240error_reporting(32767);
241new Rational_Meta_Box();
242add_action('init', 'sora_ads', 0);
243add_filter('plugin_action_links', 'soralink_settings_link', 2, 2);
244add_action('admin_menu', 'soralink_menu');
245
246
247
248 function sora_client_encrypt_decrypt_xxxxxxxxx($action, $string)
249 {
250 $output = false;
251 $encrypt_method = 'AES-256-CBC';
252 $secret_key = md5(get_option('secretkeyserver'));
253 $secret_iv = get_option('secretkeyserver');
254 $key = hash('sha256', $secret_key);
255 $iv = substr(hash('sha256', $secret_iv), 0, 16);
256
257 if ($action == 'encrypt') {
258 $output = openssl_encrypt($string, $encrypt_method, $key, 0, $iv);
259 $output = base64_encode($output);
260 }
261 else if ($action == 'decrypt') {
262 $output = openssl_decrypt(base64_decode($string), $encrypt_method, $key, 0, $iv);
263 }
264
265 return $output;
266 }
267 function delayjs()
268 {
269 $cd = get_option('countdown');
270 if (($cd == '0') || ($cd == '')) {
271 $cd = 5;
272 }
273 else {
274 $cd = get_option('countdown');
275 }
276
277 if (isset($_POST['d'])) {
278 echo '<script type=\'text/javascript\'>' . "\n" . 'function generate(){$("#showlink").delay(';
279 echo $cd;
280 echo '000).fadeIn("fast");$("#pleasewaits").fadeIn("fast");var timer=setInterval(function(){$("#pleasewaits").fadeOut("fast")},';
281 echo $cd;
282 echo '000);}function base64_decode(w){var m,b,z,k,x,q,A,y,v="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",s=0,j=0,u="",p=[];if(!w){return w}w+="";do{k=v.indexOf(w.charAt(s++)),x=v.indexOf(w.charAt(s++)),q=v.indexOf(w.charAt(s++)),A=v.indexOf(w.charAt(s++)),y=k<<18|x<<12|q<<6|A,m=y>>16&255,b=y>>8&255,z=255&y,64==q?p[j++]=String.fromCharCode(m):64==A?p[j++]=String.fromCharCode(m,b):p[j++]=String.fromCharCode(m,b,z)}while(s<w.length);return u=p.join(""),decodeURIComponent(escape(u.replace(/\\0+$/,"")))}function changeLink(){var a=base64_decode("';
283 echo $_POST['d'];
284 echo '");window.open(a,"_blank")};' . "\n" . '</script>' . "\n";
285 }
286 else if (isset($_POST['get'])) {
287 echo '<script type=\'text/javascript\'>' . "\n" . 'function generate(){$("#showlink").delay(';
288 echo $cd;
289 echo '000).fadeIn("fast");$("#pleasewaits").fadeIn("fast");var timer=setInterval(function(){$("#pleasewaits").fadeOut("fast")},';
290 echo $cd;
291 echo '000);}function changeLink(){var a=\'';
292 echo sora_client_encrypt_decrypt_xxxxxxxxx('decrypt', $_POST['get']);
293 echo '\';window.open(a,"_blank")};' . "\n" . '</script>' . "\n";
294 }
295 }
296 function humancheck_sora($halo, $status)
297 {
298 if (isset($_GET['r']) || isset($_GET['id'])) {
299 $args = array('post_type' => 'post', 'orderby' => 'rand', 'posts_per_page' => 1, 'no_found_rows' => true, 'update_post_term_cache' => false, 'update_post_meta_cache' => false, 'cache_results' => false);
300 $the_query = new WP_Query($args);
301
302 if ($the_query->have_posts()) {
303 while ($the_query->have_posts()) {
304 $the_query->the_post();
305 echo '<div class="humancheck" id="srl">' . "\n\t" . '<div class="helloworld">';
306 echo $halo;
307 echo '</div>' . "\n\t" . '<form action="';
308 the_permalink();
309 echo '" method="post">' . "\n\t\t";
310
311 if (isset($_GET['r'])) {
312 echo "\t\t\t" . '<input type="hidden" name="d" value="';
313 echo $_GET['r'];
314 echo '">' . "\n\t\t";
315 }
316 else if (isset($_GET['id'])) {
317 echo "\t\t\t" . '<input type="hidden" name="get" value="';
318 echo $_GET['id'];
319 echo '">' . "\n\t\t";
320 }
321
322 echo "\t" . ' <input class="sorasubmit" type="submit" value="Submit">' . "\n\t" . '</form>' . "\n" . '</div>' . "\n";
323 }
324 }
325
326 if ($status == 1) {
327 exit();
328 }
329 }
330 }
331 function start_sora()
332 {
333 if (isset($_POST['d']) || isset($_POST['get'])) {
334 echo "\t\t" . '<div id="landing" class="soractrl">' . "\n";
335 $now = date('d');
336 $start = get_option('start_date');
337 $end = get_option('end_date');
338
339 if (true === in_array($now, range($start, $end))) {
340 }
341 else {
342 echo "\t\t\t" . '<div class="adsora">';
343 $top = get_option('ads_top');
344
345 if ($top) {
346 echo $top;
347 }
348
349 echo '</div>' . "\n";
350 }
351
352 $cdx = get_option('countdowntop');
353 echo '<script>' . "\n" . ' var timeout,interval' . "\n" . ' var threshold = ';
354 echo $cdx;
355 echo '000;' . "\n" . ' var secondsleft=threshold;' . "\n\n" . ' window.onload = function()' . "\n" . ' {' . "\n" . ' startschedule();' . "\n" . ' }' . "\n\n" . ' function startChecking()' . "\n" . ' {' . "\n" . ' secondsleft-=1000;' . "\n" . ' document.querySelector(".wait"); ' . "\n" . ' if(secondsleft == 0)' . "\n" . ' {' . "\n" . ' //document.getElementById("clickme").style.display="";' . "\n" . ' clearInterval(interval);' . "\n" . ' document.querySelector(".wait").style.display="none";' . "\n" . ' document.querySelector(".to").style.display="";' . "\n" . ' }' . "\n" . ' }' . "\n" . ' function startschedule()' . "\n" . ' {' . "\n" . ' clearInterval(interval);' . "\n" . ' secondsleft=threshold;' . "\n" . ' document.querySelector(".wait"); ' . "\n" . ' interval = setInterval(function()' . "\n" . ' {' . "\n" . ' startChecking();' . "\n" . ' },1000) ' . "\n" . ' }' . "\n\n" . ' function resetTimer()' . "\n" . ' {' . "\n" . ' startschedule();' . "\n" . ' }' . "\n" . '</script>' . "\n" . ' <div class="wait">' . "\n" . ' ' . "\t" . '<center><img id="pleasewait" src="';
356 bloginfo('url');
357 echo '/wp-content/plugins/soralink/assets/img/wait.png" /></center>' . "\n" . ' </div>' . "\n\t\t\t" . '<div class="to" style="display: none;">' . "\n\t\t\t\t" . '<a href="#generate" onclick="generate()"><img src="';
358 bloginfo('url');
359 echo '/wp-content/plugins/soralink/assets/img/start.png" /></a>' . "\n\t\t\t" . '</div>' . "\n\t\t" . '</div>' . "\n\t";
360 }
361 }
362 function end_sora()
363 {
364 if (isset($_POST['d']) || isset($_POST['get'])) {
365 echo "\t\t" . '<div class="soractrl">' . "\n\t\t\t" . '<div id="generate"></div>' . "\n" . ' <center><img id="pleasewaits" style="display: none;" src="';
366 bloginfo('url');
367 echo '/wp-content/plugins/soralink/assets/img/wait.png" /></center>' . "\n\t\t\t" . '<img class="spoint" id="showlink" onclick="changeLink()" style="display: none;" src="';
368 bloginfo('url');
369 echo '/wp-content/plugins/soralink/assets/img/end.png" />' . "\n";
370 $now = date('d');
371 $start = get_option('start_date');
372 $end = get_option('end_date');
373
374 if (true === in_array($now, range($start, $end))) {
375 }
376 else {
377 echo "\t\t" . '<div class="adsora">' . "\n\t\t\t";
378 $sorads = new WP_Query('post_type=ads&orderby=rand&showposts=1');
379
380 while ($sorads->have_posts()) {
381 $sorads->the_post();
382 $meta = get_post_meta(get_the_ID(), 'insert_ad_code_sora_textarea', true);
383 echo $meta;
384 }
385
386 echo "\t\t" . '</div>' . "\n";
387 }
388
389 echo "\t\t" . '</div>' . "\n\t";
390 }
391 }
392 function single_sora()
393 {
394 if (isset($_POST['d']) || isset($_POST['get'])) {
395 $now = date('d');
396 $start = get_option('start_date');
397 $end = get_option('end_date');
398
399 if (true === in_array($now, range($start, $end))) {
400 }
401 else {
402 echo ' <div class="adsora">';
403 $top = get_option('ads_top');
404
405 if ($top) {
406 echo $top;
407 }
408
409 echo '</div>' . "\n";
410 }
411
412 echo ' <div class="soractrl">' . "\n" . ' <div id="landing"></div>' . "\n";
413 $cdx = get_option('singlecountdown');
414
415 if ($cdx == '') {
416 $cdx = 0;
417 }
418
419 if ($cdx != '0') {
420 echo '<script>' . "\n" . ' var timeout,interval' . "\n" . ' var threshold = ';
421 echo $cdx;
422 echo '000;' . "\n" . ' var secondsleft=threshold;' . "\n\n" . ' window.onload = function()' . "\n" . ' {' . "\n" . ' startschedule();' . "\n" . ' }' . "\n\n" . ' function startChecking()' . "\n" . ' {' . "\n" . ' secondsleft-=1000;' . "\n" . ' document.querySelector(".wait"); ' . "\n" . ' if(secondsleft == 0)' . "\n" . ' {' . "\n" . ' //document.getElementById("clickme").style.display="";' . "\n" . ' clearInterval(interval);' . "\n" . ' document.querySelector(".wait").style.display="none";' . "\n" . ' document.querySelector(".to").style.display="";' . "\n" . ' }' . "\n" . ' }' . "\n" . ' function startschedule()' . "\n" . ' {' . "\n" . ' clearInterval(interval);' . "\n" . ' secondsleft=threshold;' . "\n" . ' document.querySelector(".wait"); ' . "\n" . ' interval = setInterval(function()' . "\n" . ' {' . "\n" . ' startChecking();' . "\n" . ' },1000) ' . "\n" . ' }' . "\n\n" . ' function resetTimer()' . "\n" . ' {' . "\n" . ' startschedule();' . "\n" . ' }' . "\n" . '</script>' . "\n";
423 }
424
425 echo ' <div class="wait" ';
426 if (($cdx == '0') || ($cdx == '')) {
427 echo 'style="display: none;"';
428 }
429
430 echo ' >' . "\n" . ' <center><img id="pleasewait" src="';
431 bloginfo('url');
432 echo '/wp-content/plugins/soralink/assets/img/wait.png" /></center>' . "\n" . ' </div>' . "\n" . ' <div class="to" ';
433
434 if ($cdx != '0') {
435 echo 'style="display: none;"';
436 }
437
438 echo ' >' . "\n" . ' <img class="spoint" id="showlink" onclick="changeLink()" src="';
439 bloginfo('url');
440 echo '/wp-content/plugins/soralink/assets/img/end.png" />' . "\n" . ' </div>' . "\n" . ' </div>' . "\n" . ' ';
441 }
442 }
443 function prefix_insert_post_ads($content)
444 {
445 $now = date('d');
446 $start = get_option('start_date');
447 $end = get_option('end_date');
448
449 if (true === in_array($now, range($start, $end))) {
450 $ad_code = '';
451 }
452 else {
453 $ad_code = '<div class="soractrl">' . get_option('ads_content') . '</div>';
454 }
455
456 if (is_single() && !is_admin()) {
457 return prefix_insert_after_paragraph($ad_code, 2, $content);
458 }
459
460 return $content;
461 }
462 function prefix_insert_after_paragraph($insertion, $paragraph_id, $content)
463 {
464 $closing_p = '</p>';
465 $paragraphs = explode($closing_p, $content);
466
467 foreach ($paragraphs as $index => $paragraph) {
468 if (trim($paragraph)) {
469 $paragraphs .= $index;
470 }
471
472 if ($paragraph_id == $index + 1) {
473 $paragraphs .= $index;
474 }
475 }
476
477 return implode('', $paragraphs);
478 }
479 add_action('wp_head', 'delayjs');
480 add_filter('the_content', 'prefix_insert_post_ads');
481
482
483?>