Uptolike Social Share Buttons - Version 1.3.4

Version Description

  • Bug fix
Download this release

Release Info

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

Version 1.3.4

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,164 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 ('#settings' == hsh) {
68
+ // $('.nav-tab-wrapper a').removeClass('nav-tab-active');
69
+ // $('a.nav-tab#settings').addClass('nav-tab-active');
70
+ // $('.wrapper-tab').removeClass('active');
71
+ // $('#con_settings').addClass('active');
72
+ // }
73
+
74
+ // else
75
+ if (('#reg' == hsh) || ('#enter' == hsh)) {
76
+
77
+ $('.nav-tab-wrapper a').removeClass('nav-tab-active');
78
+ $('a.nav-tab#stat').addClass('nav-tab-active');
79
+ $('.wrapper-tab').removeClass('active');
80
+ $('#con_stat').addClass('active');
81
+
82
+ if ('#reg' == hsh) {
83
+ $('.reg_btn').show();
84
+ $('.reg_block').show();
85
+ $('.enter_btn').hide();
86
+ $('.enter_block').hide();
87
+ }
88
+ if ('#enter' == hsh) {
89
+ $('.reg_btn').hide();
90
+ $('.reg_block').hide();
91
+ $('.enter_btn').show();
92
+ $('.enter_block').show();
93
+ }
94
+ }
95
+ }
96
+
97
+ window.onhashchange = function() {
98
+ hashChange();
99
+ }
100
+
101
+ jQuery(document).ready(function () {
102
+ $ = jQuery;
103
+
104
+ $('input.id_number').css('width','520px');//fix
105
+ $('.uptolike_email').val($('#uptolike_email').val())//init fields with hidden value (server email)
106
+ $('.enter_block input.id_number').attr('value', $('table input.id_number').val());
107
+
108
+ $('div.enter_block').hide();
109
+ $('div.reg_block').hide();
110
+
111
+ $('.reg_btn').click(function(){
112
+ $('.reg_block').toggle('fast');
113
+ $('.enter_btn').toggle('fast');
114
+ })
115
+
116
+ $('.enter_btn').click(function(){
117
+ $('.enter_block').toggle('fast');
118
+ $('.reg_btn').toggle('fast');
119
+ })
120
+
121
+ $('.reg_block button').click(function(){
122
+ my_email = $('.reg_block .uptolike_email').val();
123
+ regMe(my_email);
124
+ })
125
+
126
+ $('.enter_block button').click(function(){
127
+ my_email = $('.enter_block input.uptolike_email').val();
128
+ my_key = $('.enter_block input.id_number').val();
129
+ $('table input.id_number').attr('value',my_key);
130
+ $('table input#uptolike_email').attr('value',my_email);
131
+ $('#settings_form').submit();
132
+ })
133
+
134
+ //if unregged user
135
+ if ($('.id_number').val() == '') {
136
+ $('#uptolike_email').after('<button type="button" onclick="regMe();">Зарегистрироваться</button>');
137
+ json = $('input#uptolike_json').val();
138
+ initConstr(json);
139
+ }
140
+ $('#widget_code').parent().parent().attr('style', 'display:none');
141
+ $('#uptolike_json').parent().parent().attr('style', 'display:none')
142
+ $('table .id_number').parent().parent().attr('style', 'display:none')
143
+ $('#uptolike_email').parent().parent().attr('style', 'display:none')
144
+
145
+ $('.nav-tab-wrapper a').click(function (e) {
146
+ e.preventDefault();
147
+ var click_id = $(this).attr('id');
148
+ if (click_id != $('.nav-tab-wrapper a.nav-tab-active').attr('id')) {
149
+ $('.nav-tab-wrapper a').removeClass('nav-tab-active');
150
+ $(this).addClass('nav-tab-active');
151
+ $('.wrapper-tab').removeClass('active');
152
+ $('#con_' + click_id).addClass('active');
153
+ }
154
+ });
155
+
156
+ hashChange();
157
+ $.getScript( "http://uptolike.com/api/getsession.json" )
158
+ .done(function( script, textStatus ) {
159
+ $('iframe#cons_iframe').attr('src',$('iframe#cons_iframe').attr('data-src'));
160
+ $('iframe#stats_iframe').attr('src',$('iframe#stats_iframe').attr('data-src'));
161
+ });
162
+
163
+ });
164
+
readme.txt ADDED
@@ -0,0 +1,120 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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.3.4
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.3.4 =
70
+ * Bug fix
71
+
72
+ = 1.3.3 =
73
+ * Enhancement
74
+
75
+ = 1.3.2 =
76
+ * Bug fix
77
+
78
+ = 1.3.1 =
79
+ * Enahncement: widget area
80
+
81
+ = 1.3.0 =
82
+ * Bug fix
83
+
84
+ = 1.2.9 =
85
+ * Bug Fix: minor changes
86
+
87
+ = 1.2.8 =
88
+ * Enhancement: new settings
89
+ * Bug Fix
90
+
91
+ = 1.2.7 =
92
+ * Bug Fix: minor bug fixes
93
+
94
+ = 1.2.6 =
95
+ * Enhancement: new feature - on archive
96
+
97
+ = 1.2.5 =
98
+ * Bug fix: minor bugs with short tag option
99
+
100
+ = 1.2.4 =
101
+ * Enhancement: new feature - on static page
102
+ * Enhancement: security
103
+ * Bug fix
104
+
105
+ = 1.2.3 =
106
+ * Bug fix: show on main
107
+
108
+ = 1.2.2 =
109
+ * Enhancement: cut spaces in cryptkey field
110
+ * Enhancement: feedback link
111
+ * Enhancement: access to plugins by top menu item
112
+
113
+ = 1.2.1 =
114
+ * Bug Fix: minor bug fixes
115
+
116
+ = 1.2.0 =
117
+ * Enhancement: user registration.
118
+
119
+ = 1.0.0 =
120
+ * 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.3.4
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,176 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+
4
+
5
+ function constructorIframe($projectId, $partnerId, $mail, $cryptKey)
6
+ {
7
+
8
+ $params = array('mail' => $mail,
9
+ 'partner' => $partnerId,
10
+ 'projectId' => $projectId);
11
+
12
+ $paramsStr = 'mail=' . $mail . '&partner=' . $partnerId . '&projectId=' . $projectId . $cryptKey;
13
+ $signature = md5($paramsStr);
14
+ $params['signature'] = $signature;
15
+ if ('' !== $cryptKey) {
16
+ $finalUrl = 'https://uptolike.com/api/constructor.html?' . http_build_query($params);
17
+ } else $finalUrl = 'https://uptolike.com/api/constructor.html';
18
+
19
+
20
+ return $finalUrl;
21
+ }
22
+
23
+ function statIframe($projectId, $partnerId, $mail, $cryptKey)
24
+ {
25
+ $params = array(
26
+ 'mail' => $mail,
27
+ 'partner' => $partnerId,
28
+ 'projectId' => $projectId,
29
+
30
+ );
31
+ $paramsStr = 'mail=' . $mail . '&partner=' . $partnerId . '&projectId=' . $projectId;
32
+ $signature = md5($paramsStr . $cryptKey);
33
+ $params['signature'] = $signature;
34
+ $finalUrl = 'https://uptolike.com/api/statistics.html?' . http_build_query($params);
35
+
36
+ return $finalUrl;
37
+ }
38
+
39
+ function usb_admin_page()
40
+ {
41
+
42
+ $options = get_option('my_option_name');
43
+
44
+ if ((isset($options['uptolike_email'])) && ('' !== $options['uptolike_email'])) {
45
+ $email = $options['uptolike_email'];
46
+ } else $email = get_option('admin_email');
47
+ $partnerId = 'cms';
48
+ $projectId = 'cms' . preg_replace('/^www\./', '', $_SERVER['HTTP_HOST']);
49
+ $projectId = str_replace('.', '', $projectId);
50
+ $projectId = str_replace('-', '', $projectId);
51
+ $options = get_option('my_option_name');
52
+ if (is_array($options) && array_key_exists('id_number', $options)) {
53
+ $cryptKey = $options['id_number'];
54
+ } else $cryptKey = '';
55
+ /* $this->options = get_option('my_option_name');
56
+
57
+ if ((isset($this->options['uptolike_email'])) && ('' !== $this->options['uptolike_email'])) {
58
+ $email = $this->options['uptolike_email'];
59
+ } else $email = get_option('admin_email');
60
+ $partnerId = 'cms';
61
+ $projectId = 'cms' . preg_replace('/^www\./', '', $_SERVER['HTTP_HOST']);l
62
+ $projectId = str_replace('.','',$projectId);
63
+ $projectId = str_replace('-','',$projectId);
64
+ $options = get_option('my_option_name');
65
+ if (is_array($options) && array_key_exists('id_number', $options)) {
66
+ $cryptKey = $options['id_number'];
67
+ } else $cryptKey = '';
68
+ */
69
+ ?>
70
+ <script type="text/javascript">
71
+ <?php include('main.js'); ?>
72
+ </script>
73
+ <style type="text/css">
74
+ h2.placeholder {
75
+ font-size: 1px;
76
+ padding: 1px;
77
+ margin: 0px;
78
+ height: 2px;
79
+ }
80
+
81
+ div.wrapper-tab {
82
+ display: none;
83
+ }
84
+
85
+ div.wrapper-tab.active {
86
+ display: block;
87
+ width: 100%;
88
+ }
89
+
90
+ input#id_number {
91
+ width: 520px;
92
+ }
93
+ </style>
94
+ <div class="wrap">
95
+ <h2 class="placeholder">&nbsp;</h2>
96
+
97
+ <div id="wrapper">
98
+ <form id="settings_form" method="post" action="options.php">
99
+ <H1> UpToLike виджет</H1>
100
+
101
+ <h2 class="nav-tab-wrapper">
102
+ <a class="nav-tab nav-tab-active" href="#" id="construct">
103
+ Конструктор
104
+ </a>
105
+ <a class="nav-tab" href="#" id="stat">
106
+ Статистика
107
+ </a>
108
+
109
+ <a class="nav-tab" href="#" id="settings">
110
+ Настройки
111
+ </a>
112
+ </h2>
113
+
114
+ <div class="wrapper-tab active" id="con_construct">
115
+ <iframe id='cons_iframe' style='height: 445px;width: 100%;'
116
+ data-src="<?php echo constructorIframe($projectId, $partnerId, $email, $cryptKey); ?>"></iframe>
117
+ <br>
118
+ <a onclick="getCode();" href="#">
119
+ <button type="reset">Сохранить изменения</button>
120
+ </a>
121
+ </div>
122
+ <div class="wrapper-tab" id="con_stat">
123
+ <?php if (('' == $partnerId) OR ('' == $email) OR ('' == $cryptKey)) {
124
+
125
+ ?>
126
+ <h2>Статистика</h2>
127
+ <p>Для просмотра статистики необходимо ввести ваш секретный ключ </p>
128
+ <?php } else { ?>
129
+ <!-- <?php print_r(array($partnerId, $email, $cryptKey)); ?> -->
130
+ <iframe style="width: 100%;height: 380px;" id="stats_iframe"
131
+ data-src="<?php echo statIframe($projectId, $partnerId, $email, $cryptKey); ?>">
132
+ </iframe> <?php
133
+ } ?>
134
+ <button class="reg_btn" type="button">Запросить секретный ключ</button>
135
+ <br/>
136
+
137
+ <div class="reg_block">
138
+ <label>Email<input type="text" class="uptolike_email"></label><br/>
139
+ <button type="button" class="button-primary">Отправить ключ на email</button>
140
+ <br/>
141
+ </div>
142
+ <button class="enter_btn" type="button">Авторизация</button>
143
+ <br/>
144
+
145
+ <div class="enter_block">
146
+ <label>Email<input type="text" class="uptolike_email"></label><br/>
147
+ <label>Ключ<input type="text" class="id_number"></label><br/>
148
+ <button type="button" class="button-primary">Сохранить</button>
149
+ <br/>
150
+ </div>
151
+ </div>
152
+
153
+ <div class="wrapper-tab " id="con_settings">
154
+ <?php
155
+ $my_settings_page = new MySettingsPage();
156
+ $my_settings_page->page_init();
157
+ settings_fields('my_option_group');
158
+ do_settings_sections($my_settings_page->settings_page_name);
159
+ ?>
160
+
161
+ <input type="submit" name="submit_btn" value="Cохранить изменения">
162
+
163
+ <br>
164
+ "Данный плагин полностью бесплатен. Мы регулярно его улучшаем и добавляем новые функции.<br>
165
+ Пожалуйста, <a href="https://wordpress.org/support/view/plugin-reviews/uptolike-share">оставьте свой отзыв на данной странице</a>. Спасибо! <br>
166
+
167
+ </div>
168
+
169
+
170
+ </form>
171
+ </div>
172
+ </div>
173
+ <?php
174
+ }
175
+
176
+ usb_admin_page();
widget_options.php ADDED
@@ -0,0 +1,751 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+
4
+ class MySettingsPage
5
+ {
6
+
7
+ public $options;
8
+ public $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
+ $this->options = get_option('my_option_name');
14
+ }
15
+
16
+
17
+ public function add_plugin_page()
18
+ {
19
+ add_options_page(
20
+ 'Settings Admin',
21
+ 'UpToLike',
22
+ 'manage_options',
23
+ $this->settings_page_name, //'my-setting-admin',
24
+ array($this, 'create_admin_page')
25
+ );
26
+ }
27
+
28
+ /** creates url of iframe with statistics page from given params
29
+ *
30
+ * @param $projectId
31
+ * @param $partnerId
32
+ * @param $mail
33
+ * @param $cryptKey
34
+ * @return stringшfr
35
+ */
36
+ public function statIframe($projectId, $partnerId, $mail, $cryptKey)
37
+ {
38
+ $params = array(
39
+ 'mail' => $mail,
40
+ 'partner' => $partnerId,
41
+ 'projectId' => $projectId,
42
+
43
+ );
44
+ $paramsStr = 'mail=' . $mail . '&partner=' . $partnerId. '&projectId=' . $projectId;
45
+ $signature = md5($paramsStr . $cryptKey);
46
+ $params['signature'] = $signature;
47
+ $finalUrl = 'https://uptolike.com/api/statistics.html?' . http_build_query($params);
48
+
49
+ return $finalUrl;
50
+ }
51
+
52
+ /** create url of iframe with constructor from given params
53
+ * @param $projectId
54
+ * @param $partnerId
55
+ * @param $mail
56
+ * @param $cryptKey
57
+ * @return string
58
+ */
59
+ public function constructorIframe($projectId, $partnerId, $mail, $cryptKey)
60
+ {
61
+
62
+ $params = array('mail' => $mail,
63
+ 'partner' => $partnerId,
64
+ 'projectId' => $projectId);
65
+
66
+ $paramsStr = 'mail=' . $mail . '&partner=' . $partnerId . '&projectId=' . $projectId . $cryptKey;
67
+ $signature = md5($paramsStr);
68
+ $params['signature'] = $signature;
69
+ if ('' !== $cryptKey) {
70
+ $finalUrl = 'https://uptolike.com/api/constructor.html?' . http_build_query($params);
71
+ } else $finalUrl = 'https://uptolike.com/api/constructor.html';
72
+
73
+
74
+ return $finalUrl;
75
+ }
76
+
77
+
78
+ /** returns tabs html code. May be replace by proper html code
79
+ * @param string $current
80
+ */
81
+ public function ilc_admin_tabs($current = 'construct')
82
+ {
83
+ $tabs = array('construct' => 'Конструктор',
84
+ 'stat' => 'Статистика',
85
+ 'settings' => 'Настройки');
86
+
87
+ echo '<div id="icon-themes" class="icon32"><br></div>';
88
+ echo '<h2 class="nav-tab-wrapper">';
89
+ foreach ($tabs as $tab => $name) {
90
+ $class = ($tab == $current) ? ' nav-tab-active' : '';
91
+ echo "<a class='nav-tab$class' href='#' id=" . $tab . " ref='?page=" . $this->settings_page_name . "&tab=$tab'>$name</a>";
92
+
93
+ }
94
+ echo '</h2>';
95
+ }
96
+
97
+ /** render html page with code configuration settings
98
+ *
99
+ */
100
+ public function create_admin_page()
101
+ {
102
+ $this->options = get_option('my_option_name');
103
+
104
+ if ((isset($this->options['uptolike_email'])) && ('' !== $this->options['uptolike_email'])) {
105
+ $email = $this->options['uptolike_email'];
106
+ } else $email = get_option('admin_email');
107
+ $partnerId = 'cms';
108
+ $projectId = 'cms' . preg_replace('/^www\./', '', $_SERVER['HTTP_HOST']);
109
+ $projectId = str_replace('.','',$projectId);
110
+ $projectId = str_replace('-','',$projectId);
111
+ $options = get_option('my_option_name');
112
+ if (is_array($options) && array_key_exists('id_number', $options)) {
113
+ $cryptKey = $options['id_number'];
114
+ } else $cryptKey = '';
115
+ ?>
116
+ <script type="text/javascript">
117
+ <?php include('main.js'); ?>
118
+ </script>
119
+ <style type="text/css">
120
+ h2.placeholder {
121
+ font-size: 1px;
122
+ padding: 1px;
123
+ margin: 0px;
124
+ height: 2px;
125
+ }
126
+
127
+ div.wrapper-tab {
128
+ display: none;
129
+ }
130
+
131
+ div.wrapper-tab.active {
132
+ display: block;
133
+ width: 100%;
134
+ }
135
+
136
+ input#id_number {
137
+ width: 520px;
138
+ }
139
+ </style>
140
+ <div class="wrap">
141
+ <h2 class="placeholder">&nbsp;</h2>
142
+ <div id="wrapper">
143
+ <form id="settings_form" method="post" action="options.php">
144
+ <H1> UpToLike виджет</H1>
145
+ <h2 class="nav-tab-wrapper">
146
+ <a class="nav-tab nav-tab-active" href="#" id="construct">
147
+ Конструктор
148
+ </a>
149
+ <a class="nav-tab" href="#" id="stat">
150
+ Статистика
151
+ </a>
152
+
153
+ <a class="nav-tab" href="#" id="settings">
154
+ Настройки
155
+ </a>
156
+ </h2>
157
+ <div class="wrapper-tab active" id="con_construct">
158
+ <iframe id='cons_iframe' style='height: 445px;width: 100%;' data-src="<?php echo $this->constructorIframe($projectId, $partnerId, $email, $cryptKey); ?>"></iframe>
159
+ <br>
160
+ <a onclick="getCode();" href="#">
161
+ <button type="reset">Сохранить изменения</button>
162
+ </a>
163
+ </div>
164
+ <div class="wrapper-tab" id="con_stat">
165
+ <?php if (('' == $partnerId) OR ('' == $email) OR ('' == $cryptKey)) {
166
+
167
+ ?>
168
+ <h2>Статистика</h2>
169
+ <p>Для просмотра статистики необходимо ввести ваш секретный ключ </p>
170
+ <?php } else { ?>
171
+ <!-- <?php print_r(array($partnerId,$email, $cryptKey)); ?> -->
172
+ <iframe style="width: 100%;height: 380px;" id="stats_iframe" data-src="<?php echo $this->statIframe($projectId, $partnerId, $email, $cryptKey); ?>">
173
+ </iframe> <?php
174
+ } ?>
175
+ <button class="reg_btn" type="button">Запросить секретный ключ</button><br/>
176
+ <div class="reg_block">
177
+ <label>Email<input type="text" class="uptolike_email"></label><br/>
178
+ <button type="button" class="button-primary">Отправить ключ на email</button><br/>
179
+ </div>
180
+ <button class="enter_btn" type="button">Авторизация</button><br/>
181
+ <div class="enter_block" >
182
+ <label>Email<input type="text" class="uptolike_email"></label><br/>
183
+ <label>Ключ<input type="text" class="id_number"></label><br/>
184
+ <button type="button" class="button-primary">Сохранить</button><br/>
185
+ </div>
186
+ </div>
187
+ <div class="wrapper-tab" id="con_settings">
188
+ <?php
189
+ settings_fields('my_option_group');
190
+ do_settings_sections($this->settings_page_name);
191
+ ?>
192
+ <input type="submit" name="submit_btn" value="Cохранить изменения">
193
+ <br>
194
+ "Данный плагин полностью бесплатен. Мы регулярно его улучшаем и добавляем новые функции.<br>
195
+ Пожалуйста, <a href="https://wordpress.org/support/view/plugin-reviews/uptolike-share">оставьте свой отзыв на данной странице</a>. Спасибо! <br>
196
+
197
+ </div>
198
+
199
+ </form>
200
+ </div>
201
+ </div>
202
+ <?php
203
+ }
204
+
205
+ public function page_init()
206
+ {
207
+ register_setting(
208
+ 'my_option_group', // Option group
209
+ 'my_option_name', // Option name
210
+ array($this, 'sanitize') // Sanitize
211
+ );
212
+
213
+ add_settings_section(
214
+ 'setting_section_id', // ID
215
+ 'Настройки виджета', // Title
216
+ array($this, 'print_section_info'), // Callback
217
+ $this->settings_page_name//'my-setting-admin' // Page
218
+ );
219
+
220
+ add_settings_field(
221
+ 'widget_code', // ID
222
+ 'код виджета', // Title
223
+ array($this, 'widget_code_callback'), // Callback
224
+ $this->settings_page_name, //'my-setting-admin', // Page
225
+ 'setting_section_id' // Section
226
+ );
227
+
228
+ add_settings_field(
229
+ 'data_pid', // ID
230
+ 'Ключ(CryptKey)', // Title
231
+ array($this, 'id_number_callback'), // Callback
232
+ $this->settings_page_name, //'my-setting-admin', // Page
233
+ 'setting_section_id' // Section
234
+ );
235
+
236
+ add_settings_field(
237
+ 'email', //ID
238
+ 'email для регистрации',
239
+ array($this, 'uptolike_email_callback'),
240
+ $this->settings_page_name, //'my-setting-admin',
241
+ 'setting_section_id'
242
+ );
243
+
244
+ add_settings_field(
245
+ 'on_main_static', //ID
246
+ 'Располагать на главной странице в фиксированном блоке',
247
+ array($this, 'uptolike_on_main_static_callback'),
248
+ $this->settings_page_name, //'my-setting-admin',
249
+ 'setting_section_id'
250
+ );
251
+
252
+ add_settings_field(
253
+ 'on_main', //ID
254
+ 'Располагать блок на главной странице с материалом',
255
+ array($this, 'uptolike_on_main_callback'),
256
+ $this->settings_page_name, //'my-setting-admin',
257
+ 'setting_section_id'
258
+ );
259
+
260
+ add_settings_field(
261
+ 'on_page', //ID
262
+ 'Располагать блок на статических страницах',
263
+ array($this, 'uptolike_on_page_callback'),
264
+ $this->settings_page_name, //'my-setting-admin',
265
+ 'setting_section_id'
266
+ );
267
+
268
+ add_settings_field(
269
+ 'on_archive', //ID
270
+ 'Убрать кнопки в анонсах постов',
271
+ array($this, 'uptolike_on_archive_callback'),
272
+ $this->settings_page_name, //'my-setting-admin',
273
+ 'setting_section_id'
274
+ );
275
+ add_settings_field(
276
+ 'widget_position', //ID
277
+ 'Расположение блока на странице с материалом',
278
+ array($this, 'uptolike_widget_position_callback'),
279
+ $this->settings_page_name, //'my-setting-admin',
280
+ 'setting_section_id'
281
+ );
282
+
283
+ add_settings_field(
284
+ 'feedback', //ID
285
+ 'Обратная связь',
286
+ array($this, 'uptolike_feedback_callback'),
287
+ $this->settings_page_name, //'my-setting-admin',
288
+ 'setting_section_id'
289
+ );
290
+
291
+
292
+ add_settings_field(
293
+ 'uptolike_json', //ID
294
+ 'настройки конструктора',
295
+ array($this, 'uptolike_json_callback'),
296
+ $this->settings_page_name, //'my-setting-admin',
297
+ 'setting_section_id'
298
+ );
299
+ }
300
+
301
+ /**
302
+ * Sanitize each setting field as needed
303
+ *
304
+ * @param array $input Contains all settings fields as array keys
305
+ */
306
+ public function sanitize($input)
307
+ {
308
+ $new_input = array();
309
+ if (isset($input['id_number']))
310
+ $new_input['id_number'] = str_replace(' ','',$input['id_number']);
311
+
312
+ if (isset($input['widget_code']))
313
+ $new_input['widget_code'] = $input['widget_code'];
314
+
315
+ if (isset($input['uptolike_email']))
316
+ $new_input['uptolike_email'] = $input['uptolike_email'];
317
+
318
+ if (isset($input['before_content']))
319
+ $new_input['before_content'] = $input['before_content'];
320
+
321
+ if (isset($input['on_main_static'])) {
322
+ $new_input['on_main_static'] = 1;
323
+ } else $new_input['on_main_static'] = 0;
324
+
325
+ if (isset($input['on_main'])) {
326
+ $new_input['on_main'] = 1;
327
+ } else $new_input['on_main'] = 0;
328
+
329
+ if (isset($input['on_page'])) {
330
+ $new_input['on_page'] = 1;
331
+ } else $new_input['on_page'] = 0;
332
+
333
+ if (isset($input['on_archive'])) {
334
+ $new_input['on_archive'] = 1;
335
+ } else $new_input['on_archive'] = 0;
336
+
337
+ if (isset($input['email']))
338
+ $new_input['email'] = $input['email'];
339
+
340
+ if (isset($input['after_content']))
341
+ $new_input['after_content'] = $input['after_content'];
342
+
343
+ if (isset($input['widget_position']))
344
+ $new_input['widget_position'] = $input['widget_position'];
345
+
346
+ if (isset($input['uptolike_json']))
347
+ $new_input['uptolike_json'] = $input['uptolike_json'];
348
+
349
+ return $new_input;
350
+ }
351
+
352
+
353
+ public function print_section_info()
354
+ {
355
+ //print 'Enter your settings below:';
356
+ }
357
+
358
+ public function widget_code_callback()
359
+ {
360
+ printf(
361
+ '<textarea id="widget_code" name="my_option_name[widget_code]" >%s</textarea>',
362
+ isset($this->options['widget_code']) ? esc_attr($this->options['widget_code']) : ''
363
+ );
364
+ }
365
+
366
+ /** 12536473050877
367
+ * Get the settings option array and print one of its values
368
+ */
369
+ public function id_number_callback()
370
+ {
371
+ printf(
372
+ '<input type="text" class="id_number" name="my_option_name[id_number]" value="%s" />',
373
+ isset($this->options['id_number']) ? esc_attr($this->options['id_number']) : ''
374
+ );
375
+ }
376
+
377
+ public function uptolike_email_callback()
378
+ {
379
+ printf(
380
+ '<input type="text" id="uptolike_email" name="my_option_name[uptolike_email]" value="%s" />',
381
+ isset($this->options['uptolike_email']) ? esc_attr($this->options['uptolike_email']) : get_option('admin_email')
382
+ );
383
+ }
384
+
385
+ public function uptolike_json_callback()
386
+ {
387
+ printf(
388
+ '<input type="hidden" id="uptolike_json" name="my_option_name[uptolike_json]" value="%s" />',
389
+ isset($this->options['uptolike_json']) ? esc_attr($this->options['uptolike_json']) : ''
390
+ );
391
+ }
392
+
393
+ public function uptolike_partner_id_callback()
394
+ {
395
+ printf(
396
+ '<input type="text" id="uptolike_partner" name="my_option_name[uptolike_partner]" value="%s" />',
397
+ isset($this->options['uptolike_partner']) ? esc_attr($this->options['uptolike_partner']) : ''
398
+ );
399
+ }
400
+
401
+ public function uptolike_feedback_callback()
402
+ {
403
+ echo '<a href="mailto:support@uptolike.com" target="_top"> support@uptolike.com</a>';
404
+ }
405
+
406
+ public function uptolike_project_callback()
407
+ {
408
+ printf(
409
+ '<input type="text" id="uptolike_project" name="my_option_name[uptolike_project]" value="%s" />',
410
+ isset($this->options['uptolike_project']) ? esc_attr($this->options['uptolike_project']) : ''
411
+ );
412
+ }
413
+
414
+ public function uptolike_on_main_static_callback()
415
+ {
416
+ echo '<input type="checkbox" id="on_main_static" name="my_option_name[on_main_static]"';
417
+ echo ($this->options['on_main_static'] == '1' ? 'checked="checked"' : ''); echo ' />';
418
+
419
+ }
420
+
421
+ public function uptolike_on_main_callback()
422
+ {
423
+ echo '<input type="checkbox" id="on_main" name="my_option_name[on_main]"';
424
+ echo ($this->options['on_main'] == '1' ? 'checked="checked"' : ''); echo ' />';
425
+
426
+ }
427
+ public function uptolike_on_page_callback()
428
+ {
429
+ echo '<input type="checkbox" id="on_page" name="my_option_name[on_page]"';
430
+ echo ($this->options['on_page'] == '1' ? 'checked="checked"' : ''); echo ' />';
431
+
432
+ }
433
+ public function uptolike_on_archive_callback()
434
+ {
435
+ echo '<input type="checkbox" id="on_archive" name="my_option_name[on_archive]"';
436
+ echo ($this->options['on_archive'] == '1' ? 'checked="checked"' : ''); echo ' />';
437
+
438
+ }
439
+
440
+ public function uptolike_widget_position_callback()
441
+ {
442
+ $top = $bottom = $both = $default = '';
443
+
444
+ if (isset($this->options['widget_position'])) {
445
+ if ('top' == $this->options['widget_position']) {
446
+ $top = "selected='selected'";
447
+ } elseif ('bottom' == $this->options['widget_position']) {
448
+ $bottom = "selected='selected'";
449
+ } elseif ('both' == $this->options['widget_position']) {
450
+ $both = "selected='selected'";
451
+ } else {
452
+ $bottom = "selected='selected'";
453
+ }
454
+ } else {
455
+ $my_options = get_option('my_option_name');
456
+ $my_options['widget_position'] = 'bottom'; // cryptkey store
457
+ update_option('my_option_name', $my_options);
458
+ }
459
+ $default = "selected='selected'";
460
+ echo "<select id='widget_position' name='my_option_name[widget_position]'>
461
+ <option {$top} value='top'>Только сверху</option>
462
+ <option {$bottom} value='bottom'>Только снизу</option>
463
+ <option {$both} value='both'>Сверху и снизу</option>
464
+ </select>";
465
+
466
+ }
467
+
468
+ }
469
+
470
+ function get_widget_code() {
471
+ $options = get_option('my_option_name');
472
+ $widget_code = $options['widget_code'];
473
+ $url = get_permalink();
474
+ $domain = preg_replace('/^www\./', '', $_SERVER['HTTP_HOST']);
475
+ $domain = str_replace('-','',$domain);
476
+ $data_pid = 'cms' . str_replace('.', '', $domain);
477
+
478
+ $widget_code = str_replace('data-pid="-1"','data-pid="' . $data_pid . '"',$widget_code);
479
+ $widget_code = str_replace('data-pid=""','data-pid="' . $data_pid . '"',$widget_code);
480
+ $widget_code = str_replace('div data', 'div data-url="' . $url . '" data', $widget_code);
481
+
482
+ return $widget_code;
483
+
484
+ }
485
+
486
+ function add_widget($content)
487
+ {
488
+ //print_r($options = get_option('my_option_name'));
489
+ //return $content;
490
+
491
+ $options = get_option('my_option_name');
492
+ if (is_array($options) && array_key_exists('widget_code', $options)) {
493
+
494
+ //$widget_code_before = $widget_code_after = '';
495
+ $widget_code = get_widget_code();
496
+
497
+ if (is_page()) {//это страница
498
+ if ($options['on_page'] == 1) {
499
+ switch ($options['widget_position']) {
500
+ case 'both':
501
+ return $widget_code.$content.$widget_code;
502
+ case 'top':
503
+ return $widget_code.$content;
504
+ case 'bottom':
505
+ return $content.$widget_code;
506
+ }
507
+ } else return $content;
508
+ } elseif (is_archive()) {
509
+ if ($options['on_archive'] == 0) {
510
+ switch ($options['widget_position']) {
511
+ case 'both':
512
+ return $widget_code.$content.$widget_code;
513
+ case 'top':
514
+ return $widget_code.$content;
515
+ case 'bottom':
516
+ return $content.$widget_code;
517
+ }
518
+ } else return $content;
519
+ } elseif (is_front_page()) {
520
+ if ($options['on_main'] == 1) {
521
+ switch ($options['widget_position']) {
522
+ case 'both':
523
+ return $widget_code.$content.$widget_code;
524
+ case 'top':
525
+ return $widget_code.$content;
526
+ case 'bottom':
527
+ return $content.$widget_code;
528
+ }
529
+ } else return $content;
530
+ } else {
531
+ switch ($options['widget_position']) {
532
+ case 'both':
533
+ return $widget_code.$content.$widget_code;
534
+ case 'top':
535
+ return $widget_code.$content;
536
+ case 'bottom':
537
+ return $content.$widget_code;
538
+ }
539
+ };
540
+
541
+ } else {
542
+ return $content;
543
+ }
544
+ }
545
+
546
+ add_filter('the_content', 'add_widget', 100);
547
+
548
+
549
+ function uptolike_shortcode( $atts ){
550
+
551
+ return add_widget("");
552
+ }
553
+ add_shortcode( 'uptolike', 'uptolike_shortcode' );
554
+
555
+ function my_widgetcode_notice()
556
+ {
557
+ $options = get_option('my_option_name');
558
+ if (is_array($options) && array_key_exists('widget_code', $options)) {
559
+ $widget_code = $options['widget_code'];
560
+ if ('' == $widget_code) {
561
+ echo " <div class='updated'>
562
+ <p>В настройках UpToLike 'Конструктор' выберите тип виджета и нажмите 'Сохранить'</p>
563
+ </div>";
564
+ }
565
+ };
566
+ }
567
+
568
+ function logger($str)
569
+ {
570
+ file_put_contents(WP_PLUGIN_DIR . '/uptolike/log.txt', date(DATE_RFC822) . $str . PHP_EOL, FILE_APPEND | LOCK_EX);
571
+ }
572
+
573
+ function try_reg()
574
+ {
575
+ include('api_functions.php');
576
+ $domain = preg_replace('/^www\./', '', $_SERVER['HTTP_HOST']);
577
+ $options = get_option('my_option_name');
578
+ $email = $options['uptolike_email'];
579
+ if ('' == $options['id_number']) {
580
+ $reg_ans = userReg($email, 'cms', 'cms' . $domain);
581
+ if (is_string($reg_ans)) {
582
+ $my_options = get_option('my_option_name');
583
+ $my_options['id_number'] = $reg_ans; // cryptkey store
584
+ $my_options['choice'] = 'reg';
585
+ update_option('my_option_name', $my_options);
586
+ };
587
+ update_option('reg_try', true);
588
+ }
589
+ }
590
+
591
+ function my_choice_notice()
592
+ {
593
+ $options = get_option('my_option_name');
594
+ if (is_bool($options) or (('' == $options['id_number']) and ((!array_key_exists('choice', $options)) OR ('ignore' !== $options['choice'])))) {
595
+ echo "<div class='updated'>
596
+ <div><img style='
597
+ float: left;
598
+ height: 38px;
599
+ margin-left: -9px;
600
+ margin-right: 5px;
601
+ ' src='//uptolike.ru/img/logo.png'>
602
+ </div>
603
+ Кнопки успешно установлены! <br>Для просмотра статистики необходимо:
604
+ <a href='options-general.php?page=uptolike_settings#enter'>Ввести полученный ключ</a>
605
+ | <a href='options-general.php?page=uptolike_settings#reg'>Запросить ключ</a>
606
+ | <a href='options-general.php?page=uptolike_settings&choice=ignore'>Скрыть</a> </div>";
607
+
608
+
609
+ };
610
+ }
611
+
612
+ function set_default_code()
613
+ {
614
+ $options = get_option('my_option_name');
615
+ if (is_bool($options)) {
616
+ $options = array();
617
+ }
618
+ $data_url = 'cms' . $_SERVER['HTTP_HOST'];
619
+ $data_pid = 'cms' . str_replace('.', '', preg_replace('/^www\./', '', $_SERVER['HTTP_HOST']));
620
+ $code = <<<EOD
621
+ <script type="text/javascript">(function (w, doc) {
622
+ if (!w.__utlWdgt) {
623
+ w.__utlWdgt = true;
624
+ var d = doc, s = d.createElement('script'), g = 'getElementsByTagName';
625
+ s.type = 'text/javascript';
626
+ s.charset = 'UTF-8';
627
+ s.async = true;
628
+ s.src = ('https:' == w.location.protocol ? 'https' : 'http') + '://w.uptolike.com/widgets/v1/uptolike.js';
629
+ var h = d[g]('body')[0];
630
+ h.appendChild(s);
631
+ }
632
+ })(window, document);
633
+ </script>
634
+ <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">
635
+ </div>
636
+ EOD;
637
+
638
+ $code = str_replace('data-pid', 'data-pid="' . $data_pid . '"', $code);
639
+
640
+ $code = str_replace('data-url', 'data-url="' . $data_url . '"', $code);
641
+ $options['widget_code'] = $code;
642
+ $options['on_main_static'] = 1;
643
+ $options['on_main'] = 1;
644
+ $options['on_page'] = 0;
645
+ $options['on_archive'] = 1;
646
+ $options['widget_position'] = 'bottom';
647
+
648
+ update_option('my_option_name', $options);
649
+ }
650
+
651
+ function choice_helper($choice)
652
+ {
653
+ $options = get_option('my_option_name');
654
+ $options['choice'] = $choice;
655
+ if ('ignore' == $choice) {
656
+ set_default_code();
657
+ }
658
+ update_option('my_option_name', $options);
659
+ }
660
+
661
+
662
+
663
+ function usb_admin_actions()
664
+ {
665
+
666
+ if ( current_user_can('manage_options') ) {
667
+ if (function_exists('add_meta_box')) {
668
+
669
+ add_menu_page("UpToLike", "UpToLike", "manage_options", "UpToLike", 'my_custom_menu_page', plugins_url('uptolike-share/logo-small.png'));
670
+ }
671
+
672
+
673
+ }
674
+ }
675
+
676
+ function my_custom_menu_page(){
677
+ include_once( 'usb-admin.php' );
678
+ }
679
+
680
+ function headeruptolike(){
681
+ $options = get_option('my_option_name');
682
+ if (!(is_bool($options))){
683
+ if ($options['on_main_static'] == 1) {
684
+ echo get_widget_code();
685
+ }
686
+ }
687
+
688
+
689
+ }
690
+
691
+ class UptolikeWidget extends WP_Widget {
692
+
693
+ function UptolikeWidget() {
694
+ // Instantiate the parent object
695
+ parent::__construct( false, 'Блок кнопок UpToLike' );
696
+ }
697
+
698
+ function widget( $args, $instance ) {
699
+ echo get_widget_code();
700
+ //echo 'uptolike widget';
701
+ // Widget outputo
702
+ }
703
+
704
+ function update( $new_instance, $old_instance ) {
705
+ // Save widget options
706
+ }
707
+
708
+ function form( $instance ) {
709
+ // Output admin widget options form
710
+ }
711
+ }
712
+
713
+ function uptolike_register_widgets() {
714
+ register_widget( 'UptolikeWidget' );
715
+ }
716
+
717
+
718
+
719
+ register_activation_hook(__FILE__,'usb_admin_actions');
720
+ register_deactivation_hook(__FILE__,'usb_admin_actions_remove');
721
+
722
+ add_action( 'widgets_init', 'uptolike_register_widgets' );
723
+
724
+ add_action('wp_footer', 'headeruptolike', 1);
725
+
726
+
727
+
728
+ add_action('admin_notices', 'my_choice_notice');
729
+ add_action('admin_notices', 'my_widgetcode_notice');
730
+ add_action('admin_menu', 'usb_admin_actions');
731
+
732
+
733
+
734
+ $options = get_option('my_option_name');
735
+
736
+ if (is_admin()) {
737
+ $options = get_option('my_option_name');
738
+
739
+ if (array_key_exists('regme', $_REQUEST)) {
740
+ try_reg();
741
+ }
742
+ if (array_key_exists('choice', $_REQUEST)) {
743
+ choice_helper($_REQUEST['choice']);
744
+ }
745
+
746
+ $my_settings_page = new MySettingsPage();
747
+ if (is_bool($options) OR (!array_key_exists('widget_code', $options)) OR ('' == $options['widget_code'])) {
748
+ set_default_code();
749
+ }
750
+
751
+ }