Uptolike Social Share Buttons - Version 1.2.7

Version Description

  • Bug Fix: minor bug fixes
Download this release

Release Info

Developer na1vez
Plugin Icon 128x128 Uptolike Social Share Buttons
Version 1.2.7
Comparing to
See all releases

Version 1.2.7

api_functions.php ADDED
@@ -0,0 +1,68 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ const HOST = 'http://uptolike.com/';
4
+
5
+ /**
6
+ * @param $email
7
+ * @param $partnerId 'cms' for cms modules
8
+ * @param $projectId 'cms'.site name
9
+ * @return bool|string 'if false - somthing wrong, if string - it's cryptkey'
10
+ */
11
+ function userReg($email, $partnerId, $projectId){
12
+
13
+ if ($email !== '' && $partnerId !== '' && $projectId !== '') {
14
+ $url = 'http://uptolike.com/api/getCryptKeyWithUserReg.json?'.http_build_query(array(
15
+ 'email' => $email,
16
+ 'partner' => $partnerId,
17
+ 'projectId' => $projectId));
18
+
19
+ $jsonAnswer = file_get_contents($url);
20
+ if (false !== $jsonAnswer) {
21
+ $answer = json_decode($jsonAnswer);
22
+ return $answer->cryptKey;
23
+ } else return $jsonAnswer;
24
+
25
+ } else return 'one of params is empty';
26
+ }
27
+
28
+ /**
29
+ * @param $partnerId String'cms' for cms modules
30
+ * @param $email String
31
+ * @param $cryptKey String
32
+ */
33
+ function statIframe($partnerId, $mail, $cryptKey) {
34
+ $params = array(
35
+ 'mail' => $mail,
36
+ 'partner' => $partnerId
37
+ );
38
+ $paramsStr = 'mail='.$mail.'&partner='.$partnerId;
39
+ $signature = md5($paramsStr.$cryptKey);
40
+ $params['signature'] = $signature;
41
+ $finalUrl = 'http://uptolike.com/api/statistics.html?'.http_build_query($params);
42
+
43
+ return $finalUrl;
44
+ }
45
+
46
+ /**
47
+ * @param $mail user email
48
+ * @param $partnerId 'cms' for cms sites
49
+ * @param $projectId 'cms'.site_name
50
+ * @param $cryptKey crypt key, received from server
51
+ * @return string
52
+ */
53
+ function constructorIframe($mail, $partnerId, $projectId, $cryptKey) {
54
+
55
+ $params = array ('mail' => $mail,
56
+ 'partner' => $partnerId,
57
+ 'projectId' => $projectId);
58
+
59
+ $paramsStr = 'mail='.$mail.'&partner='.$partnerId.'&projectId='.$projectId.$cryptKey;
60
+ //echo http_build_query($params).$cryptKey;
61
+ $signature = md5($paramsStr);
62
+ $params['signature'] = $signature;
63
+ $finalUrl = 'http://uptolike.com/api/constructor.html?'.http_build_query($params);
64
+
65
+ return $finalUrl;
66
+ }
67
+
68
+
logo-small.png ADDED
Binary file
main.js ADDED
@@ -0,0 +1,156 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ var onmessage = function (e) {
2
+
3
+ if (e.data !== null && typeof e.data === 'object') {
4
+ if ('ready' == e.data.action ){
5
+ json = jQuery('input#uptolike_json').val();
6
+ initConstr(json);
7
+ }
8
+ if (('json' in e.data) && ('code' in e.data)) {
9
+ $('input#uptolike_json').val(e.data.json);
10
+ $('#widget_code').val(e.data.code);
11
+ jQuery('#settings_form').submit();
12
+ }
13
+ if (e.data.url.indexOf('constructor.html', 0) != -1) {
14
+ document.getElementById("cons_iframe").style.height = e.data.size + 'px';
15
+ }
16
+ if (e.data.url.indexOf('statistics.html', 0) != -1) {
17
+ document.getElementById("stats_iframe").style.height = e.data.size + 'px';
18
+ }
19
+
20
+ }
21
+ };
22
+
23
+ if (typeof window.addEventListener != 'undefined') {
24
+ window.addEventListener('message', onmessage, false);
25
+ } else if (typeof window.attachEvent != 'undefined') {
26
+ window.attachEvent('onmessage', onmessage);
27
+ }
28
+ var getCode = function () {
29
+ var win = document.getElementById("cons_iframe").contentWindow;
30
+ win.postMessage({action: 'getCode'}, "*");
31
+ };
32
+ function initConstr(jsonStr) {
33
+ var win = document.getElementById("cons_iframe").contentWindow;
34
+ if ('' !== jsonStr) {
35
+ win.postMessage({action: 'initialize', json: jsonStr}, "*");
36
+ }
37
+
38
+ }
39
+
40
+
41
+ function regMe(my_mail) {
42
+ str = jQuery.param({ email: my_mail,
43
+ partner: 'cms',
44
+ projectId: 'cms' + document.location.host.replace( new RegExp("^www.","gim"),"").replace(/\-/g, '').replace(/\./g, ''),
45
+ url:document.location.host.replace( new RegExp("^www.","gim"),"")})
46
+ dataURL = "http://uptolike.com/api/getCryptKeyWithUserReg.json";
47
+ jQuery.getJSON(dataURL + "?" + str + "&callback=?", {}, function (result) {
48
+ var jsonString = JSON.stringify(result);
49
+ var result = JSON.parse(jsonString);
50
+ if ('ALREADY_EXISTS' == result.statusCode) {
51
+ alert('Пользователь с таким email уже зарегистрирован, обратитесь в службу поддержки.');
52
+ } else if ('MAIL_SENDED' == result.statusCode) {
53
+ alert('Ключ отправлен вам на email. Теперь необходимо ввести его в поле ниже.');
54
+ $('.reg_block').toggle('fast');
55
+ $('.reg_btn').toggle('fast');
56
+ $('.enter_btn').toggle('fast');
57
+ $('.enter_block').toggle('fast');
58
+
59
+ } else if ('ILLEGAL_ARGUMENTS' == result.statusCode) {
60
+ alert('Email указан неверно.')
61
+ }
62
+ });
63
+ }
64
+
65
+ function hashChange(){
66
+ var hsh = document.location.hash
67
+ if (('#reg' == hsh) || ('#enter' == hsh)) {
68
+
69
+ $('.nav-tab-wrapper a').removeClass('nav-tab-active');
70
+ $('a.nav-tab#stat').addClass('nav-tab-active');
71
+ $('.wrapper-tab').removeClass('active');
72
+ $('#con_stat').addClass('active');
73
+
74
+ if ('#reg' == hsh) {
75
+ $('.reg_btn').show();
76
+ $('.reg_block').show();
77
+ $('.enter_btn').hide();
78
+ $('.enter_block').hide();
79
+ }
80
+ if ('#enter' == hsh) {
81
+ $('.reg_btn').hide();
82
+ $('.reg_block').hide();
83
+ $('.enter_btn').show();
84
+ $('.enter_block').show();
85
+ }
86
+ }
87
+ }
88
+
89
+ window.onhashchange = function() {
90
+ hashChange();
91
+ }
92
+
93
+ jQuery(document).ready(function () {
94
+ $ = jQuery;
95
+
96
+ $('input.id_number').css('width','520px');//fix
97
+ $('.uptolike_email').val($('#uptolike_email').val())//init fields with hidden value (server email)
98
+ $('.enter_block input.id_number').attr('value', $('table input.id_number').val());
99
+
100
+ $('div.enter_block').hide();
101
+ $('div.reg_block').hide();
102
+
103
+ $('.reg_btn').click(function(){
104
+ $('.reg_block').toggle('fast');
105
+ $('.enter_btn').toggle('fast');
106
+ })
107
+
108
+ $('.enter_btn').click(function(){
109
+ $('.enter_block').toggle('fast');
110
+ $('.reg_btn').toggle('fast');
111
+ })
112
+
113
+ $('.reg_block button').click(function(){
114
+ my_email = $('.reg_block .uptolike_email').val();
115
+ regMe(my_email);
116
+ })
117
+
118
+ $('.enter_block button').click(function(){
119
+ my_email = $('.enter_block input.uptolike_email').val();
120
+ my_key = $('.enter_block input.id_number').val();
121
+ $('table input.id_number').attr('value',my_key);
122
+ $('table input#uptolike_email').attr('value',my_email);
123
+ $('#settings_form').submit();
124
+ })
125
+
126
+ //if unregged user
127
+ if ($('.id_number').val() == '') {
128
+ $('#uptolike_email').after('<button type="button" onclick="regMe();">Зарегистрироваться</button>');
129
+ json = $('input#uptolike_json').val();
130
+ initConstr(json);
131
+ }
132
+ $('#widget_code').parent().parent().attr('style', 'display:none');
133
+ $('#uptolike_json').parent().parent().attr('style', 'display:none')
134
+ $('table .id_number').parent().parent().attr('style', 'display:none')
135
+ $('#uptolike_email').parent().parent().attr('style', 'display:none')
136
+
137
+ $('.nav-tab-wrapper a').click(function (e) {
138
+ e.preventDefault();
139
+ var click_id = $(this).attr('id');
140
+ if (click_id != $('.nav-tab-wrapper a.nav-tab-active').attr('id')) {
141
+ $('.nav-tab-wrapper a').removeClass('nav-tab-active');
142
+ $(this).addClass('nav-tab-active');
143
+ $('.wrapper-tab').removeClass('active');
144
+ $('#con_' + click_id).addClass('active');
145
+ }
146
+ });
147
+
148
+ hashChange();
149
+ $.getScript( "http://uptolike.com/api/getsession.json" )
150
+ .done(function( script, textStatus ) {
151
+ $('iframe#cons_iframe').attr('src',$('iframe#cons_iframe').attr('data-src'));
152
+ $('iframe#stats_iframe').attr('src',$('iframe#stats_iframe').attr('data-src'));
153
+ });
154
+
155
+ });
156
+
readme.txt ADDED
@@ -0,0 +1,98 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ === Uptolike Share Buttons ===
2
+ Contributors: na1vez
3
+ Tags: +1, UpToLike, AddThis, social buttons, bookmark, bookmarking, like, share, share button, sharing, social bookmarking, social bookmarks, social buttons
4
+ Requires at least: 3.0.1
5
+ Tested up to: 4.0
6
+ Stable tag: 1.2.7
7
+
8
+ Uptolike Share Buttons - social bookmarking widget with sharing statistics.
9
+
10
+ == Description ==
11
+ **What Can You Do With UpToLike Share Buttons?**
12
+
13
+ * Create custom buttons that will visually appeal to users
14
+ * Easily manage social activity online
15
+ * Increase online engagement through Shares and Likes
16
+ * Attract new visitors from social networks
17
+ * Collect and analyze the social activity of users
18
+ * Adjust content strategy based on analytics
19
+
20
+ UpToLike is a single interface from which you can manage the appearance and efficiency of social buttons on your site, as well as collect and analyze statistics on
21
+ likes, shares, returns, new users, sources of social traffic, and more.
22
+
23
+ **Which social networks does UpToLike Share Buttons support?**
24
+
25
+ UpToLike is compatible with 25 popular social networking sites. It supports the following functions: Bookmark, Print, Email, Follow, etc.
26
+
27
+ **Unique Functions of UpToLike Share Buttons**
28
+
29
+ * Customization of social buttons:
30
+
31
+ 1. 3 different shapes
32
+ 2. 6 sizes
33
+ 3. Hover effect (increase, clockwise rotation)
34
+ 4. 11 button styles
35
+ 5. Button background
36
+ 6. Text color
37
+ 7. Text size of the counter
38
+
39
+ * Social Media Following
40
+ * Automatic text selection: the system gives you the option to share a highlighted piece of text on a social network
41
+
42
+ * Gathering unique statistics of social media activity
43
+
44
+ **What statistics does UpToLike collect?**
45
+
46
+ * Number of Likes and Shares on site during the selected period
47
+ * Number of users attracted because of Likes and Shares
48
+ * Separation of traffic on social networks
49
+ * Per-page site activity: how many Likes and Shares for each individual page, and how many new visitors came to each page
50
+
51
+
52
+ == Installation ==
53
+ 1. Go to Plugins -> Add New
54
+ 2. Search for Uptolike
55
+ 3. Install the plugin called \\\"Uptolike Share Buttons\\\" and activate it
56
+ 4. Adjust your settings
57
+ 5. Request and fill the secret key field, if you want to receive the statistics
58
+ 6. Enjoy!
59
+
60
+ == Frequently Asked Questions ==
61
+ Answers to Frequently Asked Questions you can find at http://uptolike.ru/faq
62
+
63
+ == Screenshots ==
64
+ 1. Customizing sharing buttons
65
+ 2. Buttons appearance
66
+ 3. Traffic and sharing statistics
67
+
68
+ == Changelog ==
69
+ = 1.2.7 =
70
+ * Bug Fix: minor bug fixes
71
+
72
+ = 1.2.6 =
73
+ * Enhancement: new feature - on archive
74
+
75
+ = 1.2.5 =
76
+ * Bug fix: minor bugs with short tag option
77
+
78
+ = 1.2.4 =
79
+ * Enhancement: new feature - on static page
80
+ * Enhancement: security
81
+ * Bug fix
82
+
83
+ = 1.2.3 =
84
+ * Bug fix: show on main
85
+
86
+ = 1.2.2 =
87
+ * Enhancement: cut spaces in cryptkey field
88
+ * Enhancement: feedback link
89
+ * Enhancement: access to plugins by top menu item
90
+
91
+ = 1.2.1 =
92
+ * Bug Fix: minor bug fixes
93
+
94
+ = 1.2.0 =
95
+ * Enhancement: user registration.
96
+
97
+ = 1.0.0 =
98
+ * Initial release
reg_sample.html ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title></title>
5
+ </head>
6
+ <body>
7
+
8
+ </body>
9
+ </html>
screenshot-1.png ADDED
Binary file
screenshot-2.png ADDED
Binary file
screenshot-3.png ADDED
Binary file
test.html ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <script type="text/javascript">(function (w, doc) {
2
+ if (!w.__utlWdgt) {
3
+ w.__utlWdgt = true;
4
+ var d = doc, s = d.createElement('script'), g = 'getElementsByTagName';
5
+ s.type = 'text/javascript';
6
+ s.charset = 'UTF-8';
7
+ s.async = true;
8
+ s.src = ('https:' == w.location.protocol ? 'https' : 'http') + '://w.uptolike.com/widgets/v1/uptolike.js';
9
+ var h = d[g]('body')[0];
10
+ h.appendChild(s);
11
+ }
12
+ })(window, document);
13
+ </script>
14
+ <div data-url data-background-alpha="0.0" data-orientation="horizontal" data-text-color="000000" data-share-shape="round-rectangle" data-buttons-color="ff9300" data-sn-ids="fb.tw.ok.vk.gp.mr." data-counter-background-color="ffffff" data-share-counter-size="11" data-share-size="30" data-background-color="ededed" data-share-counter-type="common" data-pid data-counter-background-alpha="1.0" data-share-style="1" data-mode="share" data-following-enable="false" data-like-text-enable="false" data-selection-enable="true" data-icon-color="ffffff" class="uptolike-buttons">
15
+ </div>
uptolike_share_widget.php ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ Plugin Name: UpToLike Share Buttons
4
+ Plugin URI: http://uptolike.ru/
5
+ Description: Uptolike Share Buttons - social bookmarking widget with sharing statistics.
6
+ Version: 1.2.7
7
+ Author URI: http://uptolike.ru/
8
+ */
9
+
10
+
11
+ // Creating the widget
12
+
13
+ include 'widget_options.php';
uptolike_style.css ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+
3
+ .id_number {
4
+ width: 520px;
5
+ }
6
+
7
+ h2.placeholder {
8
+ font-size: 1px;
9
+ padding: 1px;
10
+ margin: 0px;
11
+ height: 2px;
12
+ }
13
+
14
+ div.wrapper-tab {
15
+ display: none;
16
+ }
17
+
18
+ div.wrapper-tab.active {
19
+ display: block;
20
+ width: 100%;
21
+ }
22
+
usb-admin.php ADDED
@@ -0,0 +1,225 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ function constructorIframe($projectId, $partnerId, $mail, $cryptKey)
3
+ {
4
+
5
+ $params = array('mail' => $mail,
6
+ 'partner' => $partnerId,
7
+ 'projectId' => $projectId);
8
+
9
+ $paramsStr = 'mail=' . $mail . '&partner=' . $partnerId . '&projectId=' . $projectId . $cryptKey;
10
+ $signature = md5($paramsStr);
11
+ $params['signature'] = $signature;
12
+ if ('' !== $cryptKey) {
13
+ $finalUrl = 'https://uptolike.com/api/constructor.html?' . http_build_query($params);
14
+ } else $finalUrl = 'https://uptolike.com/api/constructor.html';
15
+
16
+
17
+ return $finalUrl;
18
+ }
19
+
20
+ function statIframe($projectId, $partnerId, $mail, $cryptKey)
21
+ {
22
+ $params = array(
23
+ 'mail' => $mail,
24
+ 'partner' => $partnerId,
25
+ 'projectId' => $projectId,
26
+
27
+ );
28
+ $paramsStr = 'mail=' . $mail . '&partner=' . $partnerId . '&projectId=' . $projectId;
29
+ $signature = md5($paramsStr . $cryptKey);
30
+ $params['signature'] = $signature;
31
+ $finalUrl = 'https://uptolike.com/api/statistics.html?' . http_build_query($params);
32
+
33
+ return $finalUrl;
34
+ }
35
+
36
+ function usb_admin_page()
37
+ {
38
+
39
+ $options = get_option('my_option_name');
40
+
41
+ if ((isset($options['uptolike_email'])) && ('' !== $options['uptolike_email'])) {
42
+ $email = $options['uptolike_email'];
43
+ } else $email = get_option('admin_email');
44
+ $partnerId = 'cms';
45
+ $projectId = 'cms' . preg_replace('/^www\./', '', $_SERVER['HTTP_HOST']);
46
+ $projectId = str_replace('.', '', $projectId);
47
+ $projectId = str_replace('-', '', $projectId);
48
+ $options = get_option('my_option_name');
49
+ if (is_array($options) && array_key_exists('id_number', $options)) {
50
+ $cryptKey = $options['id_number'];
51
+ } else $cryptKey = '';
52
+ /* $this->options = get_option('my_option_name');
53
+
54
+ if ((isset($this->options['uptolike_email'])) && ('' !== $this->options['uptolike_email'])) {
55
+ $email = $this->options['uptolike_email'];
56
+ } else $email = get_option('admin_email');
57
+ $partnerId = 'cms';
58
+ $projectId = 'cms' . preg_replace('/^www\./', '', $_SERVER['HTTP_HOST']);l
59
+ $projectId = str_replace('.','',$projectId);
60
+ $projectId = str_replace('-','',$projectId);
61
+ $options = get_option('my_option_name');
62
+ if (is_array($options) && array_key_exists('id_number', $options)) {
63
+ $cryptKey = $options['id_number'];
64
+ } else $cryptKey = '';
65
+ */
66
+ ?>
67
+ <script type="text/javascript">
68
+ <?php include('main.js'); ?>
69
+ </script>
70
+ <style type="text/css">
71
+ h2.placeholder {
72
+ font-size: 1px;
73
+ padding: 1px;
74
+ margin: 0px;
75
+ height: 2px;
76
+ }
77
+
78
+ div.wrapper-tab {
79
+ display: none;
80
+ }
81
+
82
+ div.wrapper-tab.active {
83
+ display: block;
84
+ width: 100%;
85
+ }
86
+
87
+ input#id_number {
88
+ width: 520px;
89
+ }
90
+ </style>
91
+ <div class="wrap">
92
+ <h2 class="placeholder">&nbsp;</h2>
93
+
94
+ <div id="wrapper">
95
+ <form id="settings_form" method="post" action="options.php">
96
+ <H1> UpToLike виджет</H1>
97
+
98
+ <h2 class="nav-tab-wrapper">
99
+ <a class="nav-tab nav-tab-active" href="#" id="construct">
100
+ Конструктор
101
+ </a>
102
+ <a class="nav-tab" href="#" id="stat">
103
+ Статистика
104
+ </a>
105
+
106
+ <a class="nav-tab" href="#" id="settings">
107
+ Настройки
108
+ </a>
109
+ </h2>
110
+
111
+ <div class="wrapper-tab active" id="con_construct">
112
+ <iframe id='cons_iframe' style='height: 445px;width: 100%;'
113
+ data-src="<?php echo constructorIframe($projectId, $partnerId, $email, $cryptKey); ?>"></iframe>
114
+ <br>
115
+ <a onclick="getCode();" href="#">
116
+ <button type="reset">Сохранить изменения</button>
117
+ </a>
118
+ </div>
119
+ <div class="wrapper-tab" id="con_stat">
120
+ <?php if (('' == $partnerId) OR ('' == $email) OR ('' == $cryptKey)) {
121
+
122
+ ?>
123
+ <h2>Статистика</h2>
124
+ <p>Для просмотра статистики необходимо ввести ваш секретный ключ </p>
125
+ <?php } else { ?>
126
+ <!-- <?php print_r(array($partnerId, $email, $cryptKey)); ?> -->
127
+ <iframe style="width: 100%;height: 380px;" id="stats_iframe"
128
+ data-src="<?php echo statIframe($projectId, $partnerId, $email, $cryptKey); ?>">
129
+ </iframe> <?php
130
+ } ?>
131
+ <button class="reg_btn" type="button">Запросить секретный ключ</button>
132
+ <br/>
133
+
134
+ <div class="reg_block">
135
+ <label>Email<input type="text" class="uptolike_email"></label><br/>
136
+ <button type="button" class="button-primary">Отправить ключ на email</button>
137
+ <br/>
138
+ </div>
139
+ <button class="enter_btn" type="button">Авторизация</button>
140
+ <br/>
141
+
142
+ <div class="enter_block">
143
+ <label>Email<input type="text" class="uptolike_email"></label><br/>
144
+ <label>Ключ<input type="text" class="id_number"></label><br/>
145
+ <button type="button" class="button-primary">Сохранить</button>
146
+ <br/>
147
+ </div>
148
+ </div>
149
+
150
+ <div class="wrapper-tab " id="con_settings">
151
+ <input type="hidden" name="option_page" value="my_option_group"><input type="hidden" name="action"
152
+ value="update"><input
153
+ type="hidden" id="_wpnonce" name="_wpnonce" value="cac4f73a65"><input type="hidden"
154
+ name="_wp_http_referer"
155
+ value="/wp-admin/options-general.php?page=uptolike_settings">
156
+
157
+ <h3>Настройки виджета</h3>
158
+ <table class="form-table">
159
+ <tbody>
160
+ <tr style="display:none">
161
+ <th scope="row">код виджета</th>
162
+ <td><textarea id="widget_code" name="my_option_name[widget_code]"></textarea></td>
163
+ </tr>
164
+ <tr style="display:none">
165
+ <th scope="row">Ключ(CryptKey)</th>
166
+ <td><input type="text" class="id_number" name="my_option_name[id_number]" value=""
167
+ style="width: 520px;"></td>
168
+ </tr>
169
+ <tr style="display:none">
170
+ <th scope="row">email для регистрации</th>
171
+ <td><input type="text" id="uptolike_email" name="my_option_name[uptolike_email]"
172
+ value="">
173
+ <button type="button" onclick="regMe();">Зарегистрироваться</button>
174
+ </td>
175
+ </tr>
176
+ <tr>
177
+ <th scope="row">Располагать блок на главной странице</th>
178
+ <td><input type="checkbox" id="on_main" name="my_option_name[on_main]" checked="checked">
179
+ </td>
180
+ </tr>
181
+ <tr>
182
+ <th scope="row">Располагать блок на статических страницах</th>
183
+ <td><input type="checkbox" id="on_page" name="my_option_name[on_page]" checked="checked">
184
+ </td>
185
+ </tr>
186
+ <tr>
187
+ <th scope="row">Убрать кнопки в анонсах постов</th>
188
+ <td><input type="checkbox" id="on_page" name="my_option_name[on_page]" checked="checked">
189
+ </td>
190
+ </tr>
191
+ <tr>
192
+ <th scope="row">Расположение виджета</th>
193
+ <td><select id="widget_position" name="my_option_name[widget_position]">
194
+ <option value="top">Только сверху</option>
195
+ <option selected="selected" value="bottom">Только снизу</option>
196
+ <option value="both">Сверху и снизу</option>
197
+ </select></td>
198
+ </tr>
199
+ <tr>
200
+ <th scope="row">Обратная связь</th>
201
+ <td><a href="mailto:support@uptolike.com" target="_top"> support@uptolike.com</a></td>
202
+ </tr>
203
+ <tr style="display:none">
204
+ <th scope="row">настройки конструктора</th>
205
+ <td><input type="hidden" id="uptolike_json" name="my_option_name[uptolike_json]" value="">
206
+ </td>
207
+ </tr>
208
+ </tbody>
209
+ </table>
210
+ <input type="submit" name="submit_btn" value="Cохранить изменения">
211
+
212
+ <br>
213
+ "Данный плагин полностью бесплатен. Мы регулярно его улучшаем и добавляем новые функции.<br>
214
+ Пожалуйста, <a href="https://wordpress.org/support/view/plugin-reviews/uptolike-share">оставьте свой отзыв на данной странице</a>. Спасибо! <br>
215
+
216
+ </div>
217
+
218
+
219
+ </form>
220
+ </div>
221
+ </div>
222
+ <?php
223
+ }
224
+
225
+ usb_admin_page();
widget_options.php ADDED
@@ -0,0 +1,691 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+
4
+ class MySettingsPage
5
+ {
6
+
7
+ private $options;
8
+ private $settings_page_name = 'uptolike_settings';
9
+ public function __construct()
10
+ {
11
+ add_action('admin_menu', array($this, 'add_plugin_page'));
12
+ add_action('admin_init', array($this, 'page_init'));
13
+ }
14
+
15
+
16
+ public function add_plugin_page()
17
+ {
18
+ add_options_page(
19
+ 'Settings Admin',
20
+ 'UpToLike',
21
+ 'manage_options',
22
+ $this->settings_page_name, //'my-setting-admin',
23
+ array($this, 'create_admin_page')
24
+ );
25
+ }
26
+
27
+ /** creates url of iframe with statistics page from given params
28
+ *
29
+ * @param $projectId
30
+ * @param $partnerId
31
+ * @param $mail
32
+ * @param $cryptKey
33
+ * @return stringшfr
34
+ */
35
+ public function statIframe($projectId, $partnerId, $mail, $cryptKey)
36
+ {
37
+ $params = array(
38
+ 'mail' => $mail,
39
+ 'partner' => $partnerId,
40
+ 'projectId' => $projectId,
41
+
42
+ );
43
+ $paramsStr = 'mail=' . $mail . '&partner=' . $partnerId. '&projectId=' . $projectId;
44
+ $signature = md5($paramsStr . $cryptKey);
45
+ $params['signature'] = $signature;
46
+ $finalUrl = 'https://uptolike.com/api/statistics.html?' . http_build_query($params);
47
+
48
+ return $finalUrl;
49
+ }
50
+
51
+ /** create url of iframe with constructor from given params
52
+ * @param $projectId
53
+ * @param $partnerId
54
+ * @param $mail
55
+ * @param $cryptKey
56
+ * @return string
57
+ */
58
+ public function constructorIframe($projectId, $partnerId, $mail, $cryptKey)
59
+ {
60
+
61
+ $params = array('mail' => $mail,
62
+ 'partner' => $partnerId,
63
+ 'projectId' => $projectId);
64
+
65
+ $paramsStr = 'mail=' . $mail . '&partner=' . $partnerId . '&projectId=' . $projectId . $cryptKey;
66
+ $signature = md5($paramsStr);
67
+ $params['signature'] = $signature;
68
+ if ('' !== $cryptKey) {
69
+ $finalUrl = 'https://uptolike.com/api/constructor.html?' . http_build_query($params);
70
+ } else $finalUrl = 'https://uptolike.com/api/constructor.html';
71
+
72
+
73
+ return $finalUrl;
74
+ }
75
+
76
+
77
+ /** returns tabs html code. May be replace by proper html code
78
+ * @param string $current
79
+ */
80
+ public function ilc_admin_tabs($current = 'construct')
81
+ {
82
+ $tabs = array('construct' => 'Конструктор',
83
+ 'stat' => 'Статистика',
84
+ 'settings' => 'Настройки');
85
+
86
+ echo '<div id="icon-themes" class="icon32"><br></div>';
87
+ echo '<h2 class="nav-tab-wrapper">';
88
+ foreach ($tabs as $tab => $name) {
89
+ $class = ($tab == $current) ? ' nav-tab-active' : '';
90
+ echo "<a class='nav-tab$class' href='#' id=" . $tab . " ref='?page=" . $this->settings_page_name . "&tab=$tab'>$name</a>";
91
+
92
+ }
93
+ echo '</h2>';
94
+ }
95
+
96
+ /** render html page with code configuration settings
97
+ *
98
+ */
99
+ public function create_admin_page()
100
+ {
101
+ $this->options = get_option('my_option_name');
102
+
103
+ if ((isset($this->options['uptolike_email'])) && ('' !== $this->options['uptolike_email'])) {
104
+ $email = $this->options['uptolike_email'];
105
+ } else $email = get_option('admin_email');
106
+ $partnerId = 'cms';
107
+ $projectId = 'cms' . preg_replace('/^www\./', '', $_SERVER['HTTP_HOST']);
108
+ $projectId = str_replace('.','',$projectId);
109
+ $projectId = str_replace('-','',$projectId);
110
+ $options = get_option('my_option_name');
111
+ if (is_array($options) && array_key_exists('id_number', $options)) {
112
+ $cryptKey = $options['id_number'];
113
+ } else $cryptKey = '';
114
+ ?>
115
+ <script type="text/javascript">
116
+ <?php include('main.js'); ?>
117
+ </script>
118
+ <style type="text/css">
119
+ h2.placeholder {
120
+ font-size: 1px;
121
+ padding: 1px;
122
+ margin: 0px;
123
+ height: 2px;
124
+ }
125
+
126
+ div.wrapper-tab {
127
+ display: none;
128
+ }
129
+
130
+ div.wrapper-tab.active {
131
+ display: block;
132
+ width: 100%;
133
+ }
134
+
135
+ input#id_number {
136
+ width: 520px;
137
+ }
138
+ </style>
139
+ <div class="wrap">
140
+ <h2 class="placeholder">&nbsp;</h2>
141
+ <div id="wrapper">
142
+ <form id="settings_form" method="post" action="options.php">
143
+ <H1> UpToLike виджет</H1>
144
+ <h2 class="nav-tab-wrapper">
145
+ <a class="nav-tab nav-tab-active" href="#" id="construct">
146
+ Конструктор
147
+ </a>
148
+ <a class="nav-tab" href="#" id="stat">
149
+ Статистика
150
+ </a>
151
+
152
+ <a class="nav-tab" href="#" id="settings">
153
+ Настройки
154
+ </a>
155
+ </h2>
156
+ <div class="wrapper-tab active" id="con_construct">
157
+ <iframe id='cons_iframe' style='height: 445px;width: 100%;' data-src="<?php echo $this->constructorIframe($projectId, $partnerId, $email, $cryptKey); ?>"></iframe>
158
+ <br>
159
+ <a onclick="getCode();" href="#">
160
+ <button type="reset">Сохранить изменения</button>
161
+ </a>
162
+ </div>
163
+ <div class="wrapper-tab" id="con_stat">
164
+ <?php if (('' == $partnerId) OR ('' == $email) OR ('' == $cryptKey)) {
165
+
166
+ ?>
167
+ <h2>Статистика</h2>
168
+ <p>Для просмотра статистики необходимо ввести ваш секретный ключ </p>
169
+ <?php } else { ?>
170
+ <!-- <?php print_r(array($partnerId,$email, $cryptKey)); ?> -->
171
+ <iframe style="width: 100%;height: 380px;" id="stats_iframe" data-src="<?php echo $this->statIframe($projectId, $partnerId, $email, $cryptKey); ?>">
172
+ </iframe> <?php
173
+ } ?>
174
+ <button class="reg_btn" type="button">Запросить секретный ключ</button><br/>
175
+ <div class="reg_block">
176
+ <label>Email<input type="text" class="uptolike_email"></label><br/>
177
+ <button type="button" class="button-primary">Отправить ключ на email</button><br/>
178
+ </div>
179
+ <button class="enter_btn" type="button">Авторизация</button><br/>
180
+ <div class="enter_block" >
181
+ <label>Email<input type="text" class="uptolike_email"></label><br/>
182
+ <label>Ключ<input type="text" class="id_number"></label><br/>
183
+ <button type="button" class="button-primary">Сохранить</button><br/>
184
+ </div>
185
+ </div>
186
+ <div class="wrapper-tab" id="con_settings">
187
+ <?php
188
+ settings_fields('my_option_group');
189
+ do_settings_sections($this->settings_page_name);
190
+ ?>
191
+ <input type="submit" name="submit_btn" value="Cохранить изменения">
192
+ <br>
193
+ "Данный плагин полностью бесплатен. Мы регулярно его улучшаем и добавляем новые функции.<br>
194
+ Пожалуйста, <a href="https://wordpress.org/support/view/plugin-reviews/uptolike-share">оставьте свой отзыв на данной странице</a>. Спасибо! <br>
195
+
196
+ </div>
197
+
198
+ </form>
199
+ </div>
200
+ </div>
201
+ <?php
202
+ }
203
+
204
+ public function page_init()
205
+ {
206
+ register_setting(
207
+ 'my_option_group', // Option group
208
+ 'my_option_name', // Option name
209
+ array($this, 'sanitize') // Sanitize
210
+ );
211
+
212
+ add_settings_section(
213
+ 'setting_section_id', // ID
214
+ 'Настройки виджета', // Title
215
+ array($this, 'print_section_info'), // Callback
216
+ $this->settings_page_name//'my-setting-admin' // Page
217
+ );
218
+
219
+ add_settings_field(
220
+ 'widget_code', // ID
221
+ 'код виджета', // Title
222
+ array($this, 'widget_code_callback'), // Callback
223
+ $this->settings_page_name, //'my-setting-admin', // Page
224
+ 'setting_section_id' // Section
225
+ );
226
+
227
+ add_settings_field(
228
+ 'data_pid', // ID
229
+ 'Ключ(CryptKey)', // Title
230
+ array($this, 'id_number_callback'), // Callback
231
+ $this->settings_page_name, //'my-setting-admin', // Page
232
+ 'setting_section_id' // Section
233
+ );
234
+
235
+ add_settings_field(
236
+ 'email', //ID
237
+ 'email для регистрации',
238
+ array($this, 'uptolike_email_callback'),
239
+ $this->settings_page_name, //'my-setting-admin',
240
+ 'setting_section_id'
241
+ );
242
+
243
+ add_settings_field(
244
+ 'on_main', //ID
245
+ 'Располагать блок на главной странице',
246
+ array($this, 'uptolike_on_main_callback'),
247
+ $this->settings_page_name, //'my-setting-admin',
248
+ 'setting_section_id'
249
+ );
250
+
251
+ add_settings_field(
252
+ 'on_page', //ID
253
+ 'Располагать блок на статических страницах',
254
+ array($this, 'uptolike_on_page_callback'),
255
+ $this->settings_page_name, //'my-setting-admin',
256
+ 'setting_section_id'
257
+ );
258
+
259
+ add_settings_field(
260
+ 'on_archive', //ID
261
+ 'Убрать кнопки в анонсах постов',
262
+ array($this, 'uptolike_on_archive_callback'),
263
+ $this->settings_page_name, //'my-setting-admin',
264
+ 'setting_section_id'
265
+ );
266
+ add_settings_field(
267
+ 'widget_position', //ID
268
+ 'Расположение виджета',
269
+ array($this, 'uptolike_widget_position_callback'),
270
+ $this->settings_page_name, //'my-setting-admin',
271
+ 'setting_section_id'
272
+ );
273
+
274
+ add_settings_field(
275
+ 'feedback', //ID
276
+ 'Обратная связь',
277
+ array($this, 'uptolike_feedback_callback'),
278
+ $this->settings_page_name, //'my-setting-admin',
279
+ 'setting_section_id'
280
+ );
281
+
282
+
283
+ add_settings_field(
284
+ 'uptolike_json', //ID
285
+ 'настройки конструктора',
286
+ array($this, 'uptolike_json_callback'),
287
+ $this->settings_page_name, //'my-setting-admin',
288
+ 'setting_section_id'
289
+ );
290
+ }
291
+
292
+ /**
293
+ * Sanitize each setting field as needed
294
+ *
295
+ * @param array $input Contains all settings fields as array keys
296
+ */
297
+ public function sanitize($input)
298
+ {
299
+ $new_input = array();
300
+ if (isset($input['id_number']))
301
+ $new_input['id_number'] = str_replace(' ','',$input['id_number']);
302
+
303
+ if (isset($input['widget_code']))
304
+ $new_input['widget_code'] = $input['widget_code'];
305
+
306
+ if (isset($input['uptolike_email']))
307
+ $new_input['uptolike_email'] = $input['uptolike_email'];
308
+
309
+ if (isset($input['before_content']))
310
+ $new_input['before_content'] = $input['before_content'];
311
+
312
+ if (isset($input['on_main'])) {
313
+ $new_input['on_main'] = 1;
314
+ } else $new_input['on_main'] = 0;
315
+
316
+ if (isset($input['on_page'])) {
317
+ $new_input['on_page'] = 1;
318
+ } else $new_input['on_page'] = 0;
319
+
320
+ if (isset($input['on_archive'])) {
321
+ $new_input['on_archive'] = 1;
322
+ } else $new_input['on_archive'] = 0;
323
+
324
+ if (isset($input['email']))
325
+ $new_input['email'] = $input['email'];
326
+
327
+ if (isset($input['after_content']))
328
+ $new_input['after_content'] = $input['after_content'];
329
+
330
+ if (isset($input['widget_position']))
331
+ $new_input['widget_position'] = $input['widget_position'];
332
+
333
+ if (isset($input['uptolike_json']))
334
+ $new_input['uptolike_json'] = $input['uptolike_json'];
335
+
336
+ return $new_input;
337
+ }
338
+
339
+
340
+ public function print_section_info()
341
+ {
342
+ //print 'Enter your settings below:';
343
+ }
344
+
345
+ public function widget_code_callback()
346
+ {
347
+ printf(
348
+ '<textarea id="widget_code" name="my_option_name[widget_code]" >%s</textarea>',
349
+ isset($this->options['widget_code']) ? esc_attr($this->options['widget_code']) : ''
350
+ );
351
+ }
352
+
353
+ /** 12536473050877
354
+ * Get the settings option array and print one of its values
355
+ */
356
+ public function id_number_callback()
357
+ {
358
+ printf(
359
+ '<input type="text" class="id_number" name="my_option_name[id_number]" value="%s" />',
360
+ isset($this->options['id_number']) ? esc_attr($this->options['id_number']) : ''
361
+ );
362
+ }
363
+
364
+ public function uptolike_email_callback()
365
+ {
366
+ printf(
367
+ '<input type="text" id="uptolike_email" name="my_option_name[uptolike_email]" value="%s" />',
368
+ isset($this->options['uptolike_email']) ? esc_attr($this->options['uptolike_email']) : get_option('admin_email')
369
+ );
370
+ }
371
+
372
+ public function uptolike_json_callback()
373
+ {
374
+ printf(
375
+ '<input type="hidden" id="uptolike_json" name="my_option_name[uptolike_json]" value="%s" />',
376
+ isset($this->options['uptolike_json']) ? esc_attr($this->options['uptolike_json']) : ''
377
+ );
378
+ }
379
+
380
+ public function uptolike_partner_id_callback()
381
+ {
382
+ printf(
383
+ '<input type="text" id="uptolike_partner" name="my_option_name[uptolike_partner]" value="%s" />',
384
+ isset($this->options['uptolike_partner']) ? esc_attr($this->options['uptolike_partner']) : ''
385
+ );
386
+ }
387
+
388
+ public function uptolike_feedback_callback()
389
+ {
390
+ echo '<a href="mailto:support@uptolike.com" target="_top"> support@uptolike.com</a>';
391
+ }
392
+
393
+ public function uptolike_project_callback()
394
+ {
395
+ printf(
396
+ '<input type="text" id="uptolike_project" name="my_option_name[uptolike_project]" value="%s" />',
397
+ isset($this->options['uptolike_project']) ? esc_attr($this->options['uptolike_project']) : ''
398
+ );
399
+ }
400
+
401
+ public function uptolike_on_main_callback()
402
+ {
403
+ echo '<input type="checkbox" id="on_main" name="my_option_name[on_main]"';
404
+ echo ($this->options['on_main'] == '1' ? 'checked="checked"' : ''); echo ' />';
405
+
406
+ }
407
+ public function uptolike_on_page_callback()
408
+ {
409
+ echo '<input type="checkbox" id="on_page" name="my_option_name[on_page]"';
410
+ echo ($this->options['on_page'] == '1' ? 'checked="checked"' : ''); echo ' />';
411
+
412
+ }
413
+ public function uptolike_on_archive_callback()
414
+ {
415
+ echo '<input type="checkbox" id="on_archive" name="my_option_name[on_archive]"';
416
+ echo ($this->options['on_archive'] == '1' ? 'checked="checked"' : ''); echo ' />';
417
+
418
+ }
419
+
420
+ public function uptolike_widget_position_callback()
421
+ {
422
+ $top = $bottom = $both = $default = '';
423
+
424
+ if (isset($this->options['widget_position'])) {
425
+ if ('top' == $this->options['widget_position']) {
426
+ $top = "selected='selected'";
427
+ } elseif ('bottom' == $this->options['widget_position']) {
428
+ $bottom = "selected='selected'";
429
+ } elseif ('both' == $this->options['widget_position']) {
430
+ $both = "selected='selected'";
431
+ } else {
432
+ $bottom = "selected='selected'";
433
+ }
434
+ } else {
435
+ $my_options = get_option('my_option_name');
436
+ $my_options['widget_position'] = 'bottom'; // cryptkey store
437
+ update_option('my_option_name', $my_options);
438
+ }
439
+ $default = "selected='selected'";
440
+ echo "<select id='widget_position' name='my_option_name[widget_position]'>
441
+ <option {$top} value='top'>Только сверху</option>
442
+ <option {$bottom} value='bottom'>Только снизу</option>
443
+ <option {$both} value='both'>Сверху и снизу</option>
444
+ </select>";
445
+
446
+ }
447
+
448
+ }
449
+
450
+
451
+ function add_widget($content)
452
+ {
453
+ //print_r($options = get_option('my_option_name'));
454
+ //return $content;
455
+
456
+ $options = get_option('my_option_name');
457
+ if (is_array($options) && array_key_exists('widget_code', $options)) {
458
+ $widget_code = $options['widget_code'];
459
+ $url = get_permalink();
460
+ $domain = preg_replace('/^www\./', '', $_SERVER['HTTP_HOST']);
461
+ $domain = str_replace('-','',$domain);
462
+ $data_pid = 'cms' . str_replace('.', '', $domain);
463
+
464
+ $widget_code = str_replace('data-pid="-1"','data-pid="' . $data_pid . '"',$widget_code);
465
+ $widget_code = str_replace('data-pid=""','data-pid="' . $data_pid . '"',$widget_code);
466
+ $widget_code = str_replace('div data', 'div data-url="' . $url . '" data', $widget_code);
467
+ $widget_code_before = $widget_code_after = '';
468
+
469
+ if (is_page()) {//это страница
470
+ if ($options['on_page'] == 1) {
471
+ switch ($options['widget_position']) {
472
+ case 'both':
473
+ return $widget_code.$content.$widget_code;
474
+ case 'top':
475
+ return $widget_code.$content;
476
+ case 'bottom':
477
+ return $content.$widget_code;
478
+ }
479
+ } else return $content;
480
+ } elseif (is_archive()) {
481
+ if ($options['on_archive'] == 0) {
482
+ switch ($options['widget_position']) {
483
+ case 'both':
484
+ return $widget_code.$content.$widget_code;
485
+ case 'top':
486
+ return $widget_code.$content;
487
+ case 'bottom':
488
+ return $content.$widget_code;
489
+ }
490
+ } else return $content;
491
+ } elseif (is_front_page()) {
492
+ if ($options['on_main'] == 1) {
493
+ switch ($options['widget_position']) {
494
+ case 'both':
495
+ return $widget_code.$content.$widget_code;
496
+ case 'top':
497
+ return $widget_code.$content;
498
+ case 'bottom':
499
+ return $content.$widget_code;
500
+ }
501
+ } else return $content;
502
+ } else {
503
+ switch ($options['widget_position']) {
504
+ case 'both':
505
+ return $widget_code.$content.$widget_code;
506
+ case 'top':
507
+ return $widget_code.$content;
508
+ case 'bottom':
509
+ return $content.$widget_code;
510
+ }
511
+ };
512
+
513
+ } else {
514
+ return $content;
515
+ }
516
+ }
517
+
518
+ add_filter('the_content', 'add_widget', 100);
519
+
520
+
521
+ function uptolike_shortcode( $atts ){
522
+
523
+ return add_widget("");
524
+ }
525
+ add_shortcode( 'uptolike', 'uptolike_shortcode' );
526
+
527
+ function my_widgetcode_notice()
528
+ {
529
+ $options = get_option('my_option_name');
530
+ if (is_array($options) && array_key_exists('widget_code', $options)) {
531
+ $widget_code = $options['widget_code'];
532
+ if ('' == $widget_code) {
533
+ echo " <div class='updated'>
534
+ <p>В настройках UpToLike 'Конструктор' выберите тип виджета и нажмите 'Сохранить'</p>
535
+ </div>";
536
+ }
537
+ };
538
+ }
539
+
540
+ function logger($str)
541
+ {
542
+ file_put_contents(WP_PLUGIN_DIR . '/uptolike/log.txt', date(DATE_RFC822) . $str . PHP_EOL, FILE_APPEND | LOCK_EX);
543
+ }
544
+
545
+ function try_reg()
546
+ {
547
+ include('api_functions.php');
548
+ $domain = preg_replace('/^www\./', '', $_SERVER['HTTP_HOST']);
549
+ $options = get_option('my_option_name');
550
+ $email = $options['uptolike_email'];
551
+ if ('' == $options['id_number']) {
552
+ $reg_ans = userReg($email, 'cms', 'cms' . $domain);
553
+ if (is_string($reg_ans)) {
554
+ $my_options = get_option('my_option_name');
555
+ $my_options['id_number'] = $reg_ans; // cryptkey store
556
+ $my_options['choice'] = 'reg';
557
+ update_option('my_option_name', $my_options);
558
+ };
559
+ update_option('reg_try', true);
560
+ }
561
+ }
562
+
563
+ function my_choice_notice()
564
+ {
565
+ $options = get_option('my_option_name');
566
+ if (is_bool($options) or (('' == $options['id_number']) and ((!array_key_exists('choice', $options)) OR ('ignore' !== $options['choice'])))) {
567
+ echo "<div class='updated'>
568
+ <div><img style='
569
+ float: left;
570
+ height: 38px;
571
+ margin-left: -9px;
572
+ margin-right: 5px;
573
+ ' src='//uptolike.ru/img/logo.png'>
574
+ </div>
575
+ Кнопки успешно установлены! <br>Для просмотра статистики необходимо:
576
+ <a href='options-general.php?page=uptolike_settings#enter'>Ввести полученный ключ</a>
577
+ | <a href='options-general.php?page=uptolike_settings#reg'>Запросить ключ</a>
578
+ | <a href='options-general.php?page=uptolike_settings&choice=ignore'>Скрыть</a> </div>";
579
+
580
+
581
+ };
582
+ }
583
+
584
+ function set_default_code()
585
+ {
586
+ $options = get_option('my_option_name');
587
+ if (is_bool($options)) {
588
+ $options = array();
589
+ }
590
+ $data_url = 'cms' . $_SERVER['HTTP_HOST'];
591
+ $data_pid = 'cms' . str_replace('.', '', preg_replace('/^www\./', '', $_SERVER['HTTP_HOST']));
592
+ $code = <<<EOD
593
+ <script type="text/javascript">(function (w, doc) {
594
+ if (!w.__utlWdgt) {
595
+ w.__utlWdgt = true;
596
+ var d = doc, s = d.createElement('script'), g = 'getElementsByTagName';
597
+ s.type = 'text/javascript';
598
+ s.charset = 'UTF-8';
599
+ s.async = true;
600
+ s.src = ('https:' == w.location.protocol ? 'https' : 'http') + '://w.uptolike.com/widgets/v1/uptolike.js';
601
+ var h = d[g]('body')[0];
602
+ h.appendChild(s);
603
+ }
604
+ })(window, document);
605
+ </script>
606
+ <div data-url data-background-alpha="0.0" data-orientation="horizontal" data-text-color="000000" data-share-shape="round-rectangle" data-buttons-color="ff9300" data-sn-ids="fb.tw.ok.vk.gp.mr." data-counter-background-color="ffffff" data-share-counter-size="11" data-share-size="30" data-background-color="ededed" data-share-counter-type="common" data-pid data-counter-background-alpha="1.0" data-share-style="1" data-mode="share" data-following-enable="false" data-like-text-enable="false" data-selection-enable="true" data-icon-color="ffffff" class="uptolike-buttons">
607
+ </div>
608
+ EOD;
609
+
610
+ $code = str_replace('data-pid', 'data-pid="' . $data_pid . '"', $code);
611
+
612
+ $code = str_replace('data-url', 'data-url="' . $data_url . '"', $code);
613
+ $options['widget_code'] = $code;
614
+ $options['on_main'] = 1;
615
+ $options['on_page'] = 0;
616
+ $options['on_archive'] = 1;
617
+ $options['widget_position'] = 'bottom';
618
+
619
+ update_option('my_option_name', $options);
620
+ }
621
+
622
+ function choice_helper($choice)
623
+ {
624
+ $options = get_option('my_option_name');
625
+ $options['choice'] = $choice;
626
+ if ('ignore' == $choice) {
627
+ set_default_code();
628
+ }
629
+ update_option('my_option_name', $options);
630
+ }
631
+
632
+ /*function usb_admin_bar() {
633
+ global $wp_admin_bar;
634
+
635
+ echo 'run usb admin bar';
636
+ //Add a link called at the top admin bar
637
+ $wp_admin_bar->add_node(array(
638
+ 'id' => 'UpToLike',
639
+ 'title' => 'UpToLike',
640
+ 'href' => admin_url( 'options-general.php?page=uptolike_settings', 'http' )
641
+ ));
642
+
643
+ }
644
+ */
645
+
646
+ function usb_admin_actions()
647
+ {
648
+
649
+ if ( current_user_can('manage_options') ) {
650
+ if (function_exists('add_meta_box')) {
651
+
652
+ add_menu_page("UpToLike", "UpToLike", "manage_options", "UpToLike", 'my_custom_menu_page', plugins_url('uptolike-share/logo-small.png'));
653
+ } else {
654
+
655
+ }
656
+ if (get_option( OPTION_NAME_ENABLE_ADMIN_MENU, 'false' ) == 'true' ){
657
+ add_action( 'wp_before_admin_bar_render', 'usb_admin_bar' );
658
+ }
659
+
660
+ }
661
+ }
662
+
663
+ function my_custom_menu_page(){
664
+ include_once( 'usb-admin.php' );
665
+ }
666
+
667
+ register_activation_hook(__FILE__,'usb_admin_actions');
668
+ register_deactivation_hook(__FILE__,'usb_admin_actions_remove');
669
+
670
+ add_action('admin_notices', 'my_choice_notice');
671
+ add_action('admin_notices', 'my_widgetcode_notice');
672
+ add_action('admin_menu', 'usb_admin_actions');
673
+
674
+ $options = get_option('my_option_name');
675
+
676
+ if (is_admin()) {
677
+ $options = get_option('my_option_name');
678
+
679
+ if (array_key_exists('regme', $_REQUEST)) {
680
+ try_reg();
681
+ }
682
+ if (array_key_exists('choice', $_REQUEST)) {
683
+ choice_helper($_REQUEST['choice']);
684
+ }
685
+
686
+ $my_settings_page = new MySettingsPage();
687
+ if (is_bool($options) OR (!array_key_exists('widget_code', $options)) OR ('' == $options['widget_code'])) {
688
+ set_default_code();
689
+ }
690
+
691
+ }