-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathclink-template.php
151 lines (105 loc) · 3.51 KB
/
clink-template.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
<?php
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
$post_id = $post->ID;
$clink_url = get_post_meta($post_id, 'clink_url', true);
$clink_countdown_option = get_option('clink_countdown_option'); // global redirect link countdown option
$clink_post_countdown = get_post_meta($post_id, 'clink_post_countdown', true); // single post redirect link countdown option
/**
* If Clink URL defined
*/
if( $clink_url != '' ):
/**
* Count Clink URL clicks
*/
function clink_clicks() {
global $post_id;
$clicks_key = 'clink_clicks';
$clicks = get_post_meta($post_id, $clicks_key, true);
$newc_clicks = $clicks + 1;
update_post_meta($post_id, $clicks_key, $newc_clicks);
}
clink_clicks();
/**
* Generate Clink countdown page when is needed
*/
function clink_page_generator(){
global $clink_url;
global $post_id;
$clink_powered_by_text = get_option('clink_powered_by_text');
$clink_countdown_duration = get_option('clink_countdown_duration');
if( !is_numeric( $clink_countdown_duration ) or empty( $clink_countdown_duration ) ) {
$clink_countdown_duration = 10;
}
?>
<!DOCTYPE html>
<html>
<head>
<?php
echo '<title>' . get_the_title( $post_id ) . ' - ' . get_bloginfo('name') . '</title>';
echo '<meta name="robots" content="noindex,nofollow"/>';
wp_head();
echo "<script>
var countdown_duration =" . $clink_countdown_duration . ";
var redirect_target_url ='" . $clink_url . "';
</script>";
?>
</head>
<body <?php body_class(get_bloginfo( 'language' )); ?> <?php if ( is_rtl() ){ echo 'dir="rtl"'; } ?>>
<div class="clink-page">
<div class="container">
<div class="clink-box">
<p><?php _e('You will redirect to the destination link In a moment','aryan-themes') ?></p>
<div id="countdown"></div>
<p class="problem"><?php printf( __( 'If the page does not redirect automatically, click on <a href="%s">this link</a>', 'aryan-themes' ) , $clink_url ); ?></p>
</div>
</div>
<?php if( $clink_powered_by_text === "1" ){
echo '<div class="aryan-themes"><p>';
printf( __( 'Powered By <a href="%s">Aryan Themes</a>', 'aryan-themes' ) , 'http://aryanthemes.com' );
echo '</p></div>';
} ?>
</div>
</body>
</html>
<?php }
/**
* Decide how to redirect to the Clink URL
*/
if( $clink_post_countdown === '1' or $clink_post_countdown === '0' ){
/**
* If Clink post countdown set
*/
if( $clink_post_countdown === '1' ){
/**
* If Clink post countdown set to on
*/
clink_page_generator();
}elseif( $clink_post_countdown === '0' ){
/**
* If Clink post countdown set to off
*/
wp_redirect( $clink_url, 301 );
}
}elseif( $clink_countdown_option === '1' ){
/**
* If Global Clink countdown option set to on
*/
clink_page_generator();
}elseif( $clink_countdown_option === '0' ){
/**
* If Global Clink countdown option set to off
*/
wp_redirect( $clink_url, 301 );
}else{
/**
* If Clink post countdown option and Global Clink countdown option have no value or a wrong value
*/
wp_die( __( '<strong>Clink:</strong> An error occurred.', 'aryan-themes') , '', array( 'response' => 404, 'back_link' => true ) );
}
else:
/**
* If Clink URL not defined
*/
wp_die( __( '<strong>Clink:</strong> An error occurred.', 'aryan-themes') , '', array( 'response' => 404, 'back_link' => true ) );
endif;
?>