· 7 years ago · Nov 29, 2018, 10:46 AM
1<?php
2/**
3 * @ langw
4 * @ fb.me/otaku.kreasy
5 *
6 **/
7
8
9
10class Rational_Meta_Box
11{
12 private $screens = array('ads');
13 private $fields = array(
14 array('id' => 'sora_textarea', 'label' => 'Ad Code', 'type' => 'textarea')
15 );
16
17 /**
18 * Class construct method. Adds actions to their respective WordPress hooks.
19 */
20 public function __construct()
21 {
22 add_action('add_meta_boxes', array($this, 'add_meta_boxes'));
23 add_action('save_post', array($this, 'save_post'));
24 }
25
26 /**
27 * Hooks into WordPress' add_meta_boxes function.
28 * Goes through screens (post types) and adds the meta box.
29 */
30 public function add_meta_boxes()
31 {
32 foreach ($this->screens as $screen) {
33 add_meta_box('insert-ad-code', __('Insert Ad Code', 'rational-metabox'), array($this, 'add_meta_box_callback'), $screen, 'advanced', 'default');
34 }
35 }
36
37 /**
38 * Generates the HTML for the meta box
39 *
40 * @param object $post WordPress post object
41 */
42 public function add_meta_box_callback($post)
43 {
44 wp_nonce_field('insert_ad_code_data', 'insert_ad_code_nonce');
45 $this->generate_fields($post);
46 }
47
48 /**
49 * Generates the field's HTML for the meta box.
50 */
51 public function generate_fields($post)
52 {
53 $output = '';
54
55 foreach ($this->fields as $field) {
56 $label = '<label for="' . $field['id'] . '">' . $field['label'] . '</label>';
57 $db_value = get_post_meta($post->ID, 'insert_ad_code_' . $field['id'], true);
58
59 switch ($field['type']) {
60 case 'textarea':
61 $input = sprintf('<textarea class="large-text" id="%s" name="%s" rows="5">%s</textarea>', $field['id'], $field['id'], $db_value);
62 break;
63 }
64
65 $input = ($field['type'] !== 'color' ? 'class="regular-text"' : '', $field['id'], $field['id'], $field['type'], $db_value);
66 $output .= $this->row_format($label, $input);
67 }
68
69 echo '<table class="form-table"><tbody>' . $output . '</tbody></table>';
70 }
71
72 /**
73 * Generates the HTML for table rows.
74 */
75 public function row_format($label, $input)
76 {
77 return sprintf('<tr><th scope="row">%s</th><td>%s</td></tr>', $label, $input);
78 }
79
80 /**
81 * Hooks into WordPress' save_post function
82 */
83 public function save_post($post_id)
84 {
85 if (!isset($_POST['insert_ad_code_nonce'])) {
86 return $post_id;
87 }
88
89 $nonce = $_POST['insert_ad_code_nonce'];
90
91 if (!wp_verify_nonce($nonce, 'insert_ad_code_data')) {
92 return $post_id;
93 }
94
95 if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
96 return $post_id;
97 }
98
99 foreach ($this->fields as $field) {
100 if (isset($_POST[$field['id']])) {
101 switch ($field['type']) {
102 case 'email':
103 $_POST[$field['id']] = sanitize_email($_POST[$field['id']]);
104 break;
105
106 case 'text':
107 $_POST[$field['id']] = sanitize_text_field($_POST[$field['id']]);
108 break;
109 }
110
111 update_post_meta($post_id, 'insert_ad_code_' . $field['id'], $_POST[$field['id']]);
112 }
113 else if ($field['type'] === 'checkbox') {
114 update_post_meta($post_id, 'insert_ad_code_' . $field['id'], '0');
115 }
116 }
117 }
118}
119
120function sora_ads()
121{
122 $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'));
123 $args = array(
124 'label' => __('Ads', 'text_domain'),
125 'description' => __('Ads Management', 'text_domain'),
126 'labels' => $labels,
127 'supports' => array('title'),
128 'hierarchical' => false,
129 'public' => true,
130 'show_ui' => true,
131 'show_in_menu' => false,
132 'menu_position' => 5,
133 'show_in_admin_bar' => true,
134 'show_in_nav_menus' => true,
135 'can_export' => true,
136 'has_archive' => true,
137 'exclude_from_search' => false,
138 'publicly_queryable' => true,
139 'rewrite' => false,
140 'capability_type' => 'post'
141 );
142 register_post_type('Ads', $args);
143}
144
145function soralink_settings_link($actions, $file)
146{
147 if (false !== strpos($file, 'soralink')) {
148 $actions['settings'] = '<a href="admin.php?page=soralink_configuration">Configuration</a>';
149 }
150
151 return $actions;
152}
153
154function soralink_menu()
155{
156 add_menu_page('SoraLink Plugin Settings', 'SoraLink', 'administrator', 'soralink_configuration', 'soralink_configuration', 'dashicons-editor-code', 81);
157 add_submenu_page('soralink_configuration', 'SoraLink Configuration', 'Configuration', 'administrator', 'soralink_configuration', 'soralink_configuration');
158 add_submenu_page('soralink_configuration', 'Generate Link', 'Generate Link', 'administrator', 'soralink_generate', 'soralink_generate');
159 add_submenu_page('soralink_configuration', __('Bottom Ads', 'bottom-ads'), __('Bottom Ads', 'bottom-ads'), 'manage_options', 'edit.php?post_type=ads');
160 add_submenu_page('soralink_configuration', 'SoraLink Setup', 'Setup', 'administrator', 'soralink_setup', 'soralink_setup');
161 $submenu['soralink_configuration'][0][0] = 'Dashboard';
162 add_action('admin_init', 'register_soralink_settings');
163}
164
165function register_soralink_settings()
166{
167 register_setting('soralink-settings', 'soralinkkey');
168 register_setting('soralink-settings', 'soralinkkeycache');
169 register_setting('soralink-settings', 'secretkeyserver');
170 register_setting('soralink-settings', 'ads_top');
171 register_setting('soralink-settings', 'ads_content');
172 register_setting('soralink-settings', 'start_date');
173 register_setting('soralink-settings', 'end_date');
174 register_setting('soralink-settings', 'countdown');
175 register_setting('soralink-settings', 'countdowntop');
176 register_setting('soralink-settings', 'singlecountdown');
177}
178
179function soralink_configuration()
180{
181
182 function renderLicenseForm($errorMsg = NULL)
183 {
184 echo ' <div class="update-nag notice" style="display: block;">';
185 echo $errorMsg;
186 echo '</div>' . "\n" . ' <form class="form" method="post" action="options.php">' . "\n" . ' ';
187 settings_fields('soralink-settings');
188 echo ' ';
189 do_settings_sections('soralink-settings');
190 echo ' <input type="text" name="soralinkkey" class="regular-text" value="';
191 echo esc_attr(get_option('soralinkkey'));
192 echo '" placeholder="Insert valid license..." />' . "\n" . ' ';
193 submit_button();
194 echo ' </form>' . "\n";
195 }
196 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";
197 $license_key = get_option('soralinkkey');
198
199
200 echo "\n" . '<form method="post" action="options.php">' . "\n" . ' ';
201 settings_fields('soralink-settings');
202 echo ' ';
203 do_settings_sections('soralink-settings');
204 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="';
205 echo esc_attr(get_option('soralinkkey'));
206 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="';
207 echo esc_attr(get_option('secretkeyserver'));
208 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="';
209 echo esc_attr(get_option('ads_top'));
210 echo '" class="large-text code" placeholder="Place your ads code here. Recommended size 728x90">';
211 echo esc_attr(get_option('ads_top'));
212 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="';
213 echo esc_attr(get_option('ads_content'));
214 echo '" class="large-text code" placeholder="Place your ads code here. Recommended responsive size or 300x250">';
215 echo esc_attr(get_option('ads_content'));
216 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="';
217 echo esc_attr(get_option('start_date'));
218 echo '" placeholder="start" />' . "\n\t" . '<label for="range">until</label>' . "\n\t" . '<input type="number" name="end_date" min="0" class="small-text" value="';
219 echo esc_attr(get_option('end_date'));
220 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="';
221 echo esc_attr(get_option('countdowntop'));
222 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="';
223 echo esc_attr(get_option('countdown'));
224 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="';
225 echo esc_attr(get_option('singlecountdown'));
226 echo '" /></td>' . "\n" . ' </tr>' . "\n" . ' </table> ' . "\n" . ' ';
227 submit_button();
228 echo "\n" . '</form>' . "\n" . '</div>' . "\n";
229}
230
231function soralink_generate()
232{
233 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=\'';
234 echo get_site_url();
235 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";
236}
237
238function soralink_setup()
239{
240 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="';
241 echo get_site_url();
242 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";
243}
244
245new Rational_Meta_Box();
246add_action('init', 'sora_ads', 0);
247add_filter('plugin_action_links', 'soralink_settings_link', 2, 2);
248add_action('admin_menu', 'soralink_menu');
249$soralinkkey = get_option('soralinkkey');
250$license_key = get_option('soralinkkey');
251$activation_cache = get_option('soralinkkeycache');
252
253
254
255 function sora_client_encrypt_decrypt_xxxxxxxxx($action, $string)
256 {
257 $output = false;
258 $encrypt_method = 'AES-256-CBC';
259 $secret_key = md5(get_option('secretkeyserver'));
260 $secret_iv = get_option('secretkeyserver');
261 $key = hash('sha256', $secret_key);
262 $iv = substr(hash('sha256', $secret_iv), 0, 16);
263
264 if ($action == 'encrypt') {
265 $output = openssl_encrypt($string, $encrypt_method, $key, 0, $iv);
266 $output = base64_encode($output);
267 }
268 else if ($action == 'decrypt') {
269 $output = openssl_decrypt(base64_decode($string), $encrypt_method, $key, 0, $iv);
270 }
271
272 return $output;
273 }
274 function delayjs()
275 {
276 $cd = get_option('countdown');
277 if (($cd == '0') || ($cd == '')) {
278 $cd = 5;
279 }
280 else {
281 $cd = get_option('countdown');
282 }
283
284 if (isset($_POST['d'])) {
285 echo '<script type=\'text/javascript\'>' . "\n" . 'function generate(){$("#showlink").delay(';
286 echo $cd;
287 echo '000).fadeIn("fast");$("#pleasewaits").fadeIn("fast");var timer=setInterval(function(){$("#pleasewaits").fadeOut("fast")},';
288 echo $cd;
289 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("';
290 echo $_POST['d'];
291 echo '");window.open(a,"_blank")};' . "\n" . '</script>' . "\n";
292 }
293 else if (isset($_POST['get'])) {
294 echo '<script type=\'text/javascript\'>' . "\n" . 'function generate(){$("#showlink").delay(';
295 echo $cd;
296 echo '000).fadeIn("fast");$("#pleasewaits").fadeIn("fast");var timer=setInterval(function(){$("#pleasewaits").fadeOut("fast")},';
297 echo $cd;
298 echo '000);}function changeLink(){var a=\'';
299 echo sora_client_encrypt_decrypt_xxxxxxxxx('decrypt', $_POST['get']);
300 echo '\';window.open(a,"_blank")};' . "\n" . '</script>' . "\n";
301 }
302 }
303 function humancheck_sora($halo, $status)
304 {
305 if (isset($_GET['r']) || isset($_GET['id'])) {
306 $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);
307 $the_query = new WP_Query($args);
308
309 if ($the_query->have_posts()) {
310 while ($the_query->have_posts()) {
311 $the_query->the_post();
312 echo '<div class="humancheck" id="srl">' . "\n\t" . '<div class="helloworld">';
313 echo $halo;
314 echo '</div>' . "\n\t" . '<form action="';
315 the_permalink();
316 echo '" method="post">' . "\n\t\t";
317
318 if (isset($_GET['r'])) {
319 echo "\t\t\t" . '<input type="hidden" name="d" value="';
320 echo $_GET['r'];
321 echo '">' . "\n\t\t";
322 }
323 else if (isset($_GET['id'])) {
324 echo "\t\t\t" . '<input type="hidden" name="get" value="';
325 echo $_GET['id'];
326 echo '">' . "\n\t\t";
327 }
328
329 echo "\t" . ' <input class="sorasubmit" type="submit" value="Submit">' . "\n\t" . '</form>' . "\n" . '</div>' . "\n";
330 }
331 }
332
333 if ($status == 1) {
334 exit();
335 }
336 }
337 }
338 function start_sora()
339 {
340 if (isset($_POST['d']) || isset($_POST['get'])) {
341 echo "\t\t" . '<div id="landing" class="soractrl">' . "\n";
342 $now = date('d');
343 $start = get_option('start_date');
344 $end = get_option('end_date');
345
346 if (true === in_array($now, range($start, $end))) {
347 }
348 else {
349 echo "\t\t\t" . '<div class="adsora">';
350 $top = get_option('ads_top');
351
352 if ($top) {
353 echo $top;
354 }
355
356 echo '</div>' . "\n";
357 }
358
359 $cdx = get_option('countdowntop');
360 echo '<script>' . "\n" . ' var timeout,interval' . "\n" . ' var threshold = ';
361 echo $cdx;
362 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="';
363 bloginfo('url');
364 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="';
365 bloginfo('url');
366 echo '/wp-content/plugins/soralink/assets/img/start.png" /></a>' . "\n\t\t\t" . '</div>' . "\n\t\t" . '</div>' . "\n\t";
367 }
368 }
369 function end_sora()
370 {
371 if (isset($_POST['d']) || isset($_POST['get'])) {
372 echo "\t\t" . '<div class="soractrl">' . "\n\t\t\t" . '<div id="generate"></div>' . "\n" . ' <center><img id="pleasewaits" style="display: none;" src="';
373 bloginfo('url');
374 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="';
375 bloginfo('url');
376 echo '/wp-content/plugins/soralink/assets/img/end.png" />' . "\n";
377 $now = date('d');
378 $start = get_option('start_date');
379 $end = get_option('end_date');
380
381 if (true === in_array($now, range($start, $end))) {
382 }
383 else {
384 echo "\t\t" . '<div class="adsora">' . "\n\t\t\t";
385 $sorads = new WP_Query('post_type=ads&orderby=rand&showposts=1');
386
387 while ($sorads->have_posts()) {
388 $sorads->the_post();
389 $meta = get_post_meta(get_the_ID(), 'insert_ad_code_sora_textarea', true);
390 echo $meta;
391 }
392
393 echo "\t\t" . '</div>' . "\n";
394 }
395
396 echo "\t\t" . '</div>' . "\n\t";
397 }
398 }
399 function single_sora()
400 {
401 if (isset($_POST['d']) || isset($_POST['get'])) {
402 $now = date('d');
403 $start = get_option('start_date');
404 $end = get_option('end_date');
405
406 if (true === in_array($now, range($start, $end))) {
407 }
408 else {
409 echo ' <div class="adsora">';
410 $top = get_option('ads_top');
411
412 if ($top) {
413 echo $top;
414 }
415
416 echo '</div>' . "\n";
417 }
418
419 echo ' <div class="soractrl">' . "\n" . ' <div id="landing"></div>' . "\n";
420 $cdx = get_option('singlecountdown');
421
422 if ($cdx == '') {
423 $cdx = 0;
424 }
425
426 if ($cdx != '0') {
427 echo '<script>' . "\n" . ' var timeout,interval' . "\n" . ' var threshold = ';
428 echo $cdx;
429 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";
430 }
431
432 echo ' <div class="wait" ';
433 if (($cdx == '0') || ($cdx == '')) {
434 echo 'style="display: none;"';
435 }
436
437 echo ' >' . "\n" . ' <center><img id="pleasewait" src="';
438 bloginfo('url');
439 echo '/wp-content/plugins/soralink/assets/img/wait.png" /></center>' . "\n" . ' </div>' . "\n" . ' <div class="to" ';
440
441 if ($cdx != '0') {
442 echo 'style="display: none;"';
443 }
444
445 echo ' >' . "\n" . ' <img class="spoint" id="showlink" onclick="changeLink()" src="';
446 bloginfo('url');
447 echo '/wp-content/plugins/soralink/assets/img/end.png" />' . "\n" . ' </div>' . "\n" . ' </div>' . "\n" . ' ';
448 }
449 }
450 function prefix_insert_post_ads($content)
451 {
452 $now = date('d');
453 $start = get_option('start_date');
454 $end = get_option('end_date');
455
456 if (true === in_array($now, range($start, $end))) {
457 $ad_code = '';
458 }
459 else {
460 $ad_code = '<div class="soractrl">' . get_option('ads_content') . '</div>';
461 }
462
463 if (is_single() && !is_admin()) {
464 return prefix_insert_after_paragraph($ad_code, 2, $content);
465 }
466
467 return $content;
468 }
469 function prefix_insert_after_paragraph($insertion, $paragraph_id, $content)
470 {
471 $closing_p = '</p>';
472 $paragraphs = explode($closing_p, $content);
473
474 foreach ($paragraphs as $index => $paragraph) {
475 if (trim($paragraph)) {
476 $paragraphs .= $index;
477 }
478
479 if ($paragraph_id == $index + 1) {
480 $paragraphs .= $index;
481 }
482 }
483
484 return implode('', $paragraphs);
485 }
486 add_action('wp_head', 'delayjs');
487 add_filter('the_content', 'prefix_insert_post_ads');
488
489
490?>