Uptolike Social Share Buttons - Version 1.2.5

Version Description

  • Bug fix: minor bugs with short tag option
Download this release

Release Info

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

Version 1.2.5

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
+ /**
2
+ * Created by root on 02.06.14.
3
+ */
4
+
5
+ var onmessage = function (e) {
6
+ if ('ready' == e.data.action ){
7
+ json = jQuery('input#uptolike_json').val();
8
+ initConstr(json);
9
+ }
10
+ if (('json' in e.data) && ('code' in e.data)) {
11
+ $('input#uptolike_json').val(e.data.json);
12
+ $('#widget_code').val(e.data.code);
13
+ jQuery('#settings_form').submit();
14
+ }
15
+ if (e.data.url.indexOf('constructor.html', 0) != -1) {
16
+ document.getElementById("cons_iframe").style.height = e.data.size + 'px';
17
+ }
18
+ if (e.data.url.indexOf('statistics.html', 0) != -1) {
19
+ document.getElementById("stats_iframe").style.height = e.data.size + 'px';
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');//TODO dafuq? fixit
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
+ //если юзер не зареган
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,92 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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.5
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.5 =
70
+ * Bug fix: minor bugs with short tag option
71
+
72
+ = 1.2.4 =
73
+ * Enhancement: new feature - on static page
74
+ * Enhancement: security
75
+ * Bug fix
76
+
77
+ = 1.2.3 =
78
+ * Bug fix: show on main
79
+
80
+ = 1.2.2 =
81
+ * Enhancement: cut spaces in cryptkey field
82
+ * Enhancement: feedback link
83
+ * Enhancement: access to plugins by top menu item
84
+
85
+ = 1.2.1 =
86
+ * Bug Fix: minor bug fixes
87
+
88
+ = 1.2.0 =
89
+ * Enhancement: user registration.
90
+
91
+ = 1.0.0 =
92
+ * 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.5
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,215 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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><select id="widget_position" name="my_option_name[widget_position]">
189
+ <option value="top">Только сверху</option>
190
+ <option selected="selected" value="bottom">Только снизу</option>
191
+ <option value="both">Сверху и снизу</option>
192
+ </select></td>
193
+ </tr>
194
+ <tr>
195
+ <th scope="row">Обратная связь</th>
196
+ <td><a href="mailto:support@uptolike.com" target="_top"> support@uptolike.com</a></td>
197
+ </tr>
198
+ <tr style="display:none">
199
+ <th scope="row">настройки конструктора</th>
200
+ <td><input type="hidden" id="uptolike_json" name="my_option_name[uptolike_json]" value="">
201
+ </td>
202
+ </tr>
203
+ </tbody>
204
+ </table>
205
+ <input type="submit" name="submit_btn" value="Cохранить изменения">
206
+ </div>
207
+
208
+
209
+ </form>
210
+ </div>
211
+ </div>
212
+ <?php
213
+ }
214
+
215
+ usb_admin_page();
widget_options.php ADDED
@@ -0,0 +1,662 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ </div>
193
+
194
+ </form>
195
+ </div>
196
+ </div>
197
+ <?php
198
+ }
199
+
200
+ public function page_init()
201
+ {
202
+ register_setting(
203
+ 'my_option_group', // Option group
204
+ 'my_option_name', // Option name
205
+ array($this, 'sanitize') // Sanitize
206
+ );
207
+
208
+ add_settings_section(
209
+ 'setting_section_id', // ID
210
+ 'Настройки виджета', // Title
211
+ array($this, 'print_section_info'), // Callback
212
+ $this->settings_page_name//'my-setting-admin' // Page
213
+ );
214
+
215
+ add_settings_field(
216
+ 'widget_code', // ID
217
+ 'код виджета', // Title
218
+ array($this, 'widget_code_callback'), // Callback
219
+ $this->settings_page_name, //'my-setting-admin', // Page
220
+ 'setting_section_id' // Section
221
+ );
222
+
223
+ add_settings_field(
224
+ 'data_pid', // ID
225
+ 'Ключ(CryptKey)', // Title
226
+ array($this, 'id_number_callback'), // Callback
227
+ $this->settings_page_name, //'my-setting-admin', // Page
228
+ 'setting_section_id' // Section
229
+ );
230
+
231
+ add_settings_field(
232
+ 'email', //ID
233
+ 'email для регистрации',
234
+ array($this, 'uptolike_email_callback'),
235
+ $this->settings_page_name, //'my-setting-admin',
236
+ 'setting_section_id'
237
+ );
238
+
239
+ add_settings_field(
240
+ 'on_main', //ID
241
+ 'Располагать блок11 на главной странице',
242
+ array($this, 'uptolike_on_main_callback'),
243
+ $this->settings_page_name, //'my-setting-admin',
244
+ 'setting_section_id'
245
+ );
246
+
247
+ add_settings_field(
248
+ 'on_page', //ID
249
+ 'Располагать блок на статических страницах',
250
+ array($this, 'uptolike_on_page_callback'),
251
+ $this->settings_page_name, //'my-setting-admin',
252
+ 'setting_section_id'
253
+ );
254
+
255
+ add_settings_field(
256
+ 'widget_position', //ID
257
+ 'Расположение виджета',
258
+ array($this, 'uptolike_widget_position_callback'),
259
+ $this->settings_page_name, //'my-setting-admin',
260
+ 'setting_section_id'
261
+ );
262
+
263
+ add_settings_field(
264
+ 'feedback', //ID
265
+ 'Обратная связь',
266
+ array($this, 'uptolike_feedback_callback'),
267
+ $this->settings_page_name, //'my-setting-admin',
268
+ 'setting_section_id'
269
+ );
270
+
271
+
272
+ add_settings_field(
273
+ 'uptolike_json', //ID
274
+ 'настройки конструктора',
275
+ array($this, 'uptolike_json_callback'),
276
+ $this->settings_page_name, //'my-setting-admin',
277
+ 'setting_section_id'
278
+ );
279
+ }
280
+
281
+ /**
282
+ * Sanitize each setting field as needed
283
+ *
284
+ * @param array $input Contains all settings fields as array keys
285
+ */
286
+ public function sanitize($input)
287
+ {
288
+ $new_input = array();
289
+ if (isset($input['id_number']))
290
+ $new_input['id_number'] = str_replace(' ','',$input['id_number']);
291
+
292
+ if (isset($input['widget_code']))
293
+ $new_input['widget_code'] = $input['widget_code'];
294
+
295
+ if (isset($input['uptolike_email']))
296
+ $new_input['uptolike_email'] = $input['uptolike_email'];
297
+
298
+ if (isset($input['before_content']))
299
+ $new_input['before_content'] = $input['before_content'];
300
+
301
+ if (isset($input['on_main'])) {
302
+ $new_input['on_main'] = 1;
303
+ } else $new_input['on_main'] = 0;
304
+
305
+ if (isset($input['on_page'])) {
306
+ $new_input['on_page'] = 1;
307
+ } else $new_input['on_page'] = 0;
308
+
309
+ if (isset($input['email']))
310
+ $new_input['email'] = $input['email'];
311
+
312
+ if (isset($input['after_content']))
313
+ $new_input['after_content'] = $input['after_content'];
314
+
315
+ if (isset($input['widget_position']))
316
+ $new_input['widget_position'] = $input['widget_position'];
317
+
318
+ if (isset($input['uptolike_json']))
319
+ $new_input['uptolike_json'] = $input['uptolike_json'];
320
+
321
+ return $new_input;
322
+ }
323
+
324
+
325
+ public function print_section_info()
326
+ {
327
+ //print 'Enter your settings below:';
328
+ }
329
+
330
+ public function widget_code_callback()
331
+ {
332
+ printf(
333
+ '<textarea id="widget_code" name="my_option_name[widget_code]" >%s</textarea>',
334
+ isset($this->options['widget_code']) ? esc_attr($this->options['widget_code']) : ''
335
+ );
336
+ }
337
+
338
+ /** 12536473050877
339
+ * Get the settings option array and print one of its values
340
+ */
341
+ public function id_number_callback()
342
+ {
343
+ printf(
344
+ '<input type="text" class="id_number" name="my_option_name[id_number]" value="%s" />',
345
+ isset($this->options['id_number']) ? esc_attr($this->options['id_number']) : ''
346
+ );
347
+ }
348
+
349
+ public function uptolike_email_callback()
350
+ {
351
+ printf(
352
+ '<input type="text" id="uptolike_email" name="my_option_name[uptolike_email]" value="%s" />',
353
+ isset($this->options['uptolike_email']) ? esc_attr($this->options['uptolike_email']) : get_option('admin_email')
354
+ );
355
+ }
356
+
357
+ public function uptolike_json_callback()
358
+ {
359
+ printf(
360
+ '<input type="hidden" id="uptolike_json" name="my_option_name[uptolike_json]" value="%s" />',
361
+ isset($this->options['uptolike_json']) ? esc_attr($this->options['uptolike_json']) : ''
362
+ );
363
+ }
364
+
365
+ public function uptolike_partner_id_callback()
366
+ {
367
+ printf(
368
+ '<input type="text" id="uptolike_partner" name="my_option_name[uptolike_partner]" value="%s" />',
369
+ isset($this->options['uptolike_partner']) ? esc_attr($this->options['uptolike_partner']) : ''
370
+ );
371
+ }
372
+
373
+ public function uptolike_feedback_callback()
374
+ {
375
+ echo '<a href="mailto:support@uptolike.com" target="_top"> support@uptolike.com</a>';
376
+ }
377
+
378
+ public function uptolike_project_callback()
379
+ {
380
+ printf(
381
+ '<input type="text" id="uptolike_project" name="my_option_name[uptolike_project]" value="%s" />',
382
+ isset($this->options['uptolike_project']) ? esc_attr($this->options['uptolike_project']) : ''
383
+ );
384
+ }
385
+
386
+ public function uptolike_on_main_callback()
387
+ {
388
+ echo '<input type="checkbox" id="on_main" name="my_option_name[on_main]"';
389
+ echo ($this->options['on_main'] == '1' ? 'checked="checked"' : ''); echo ' />';
390
+
391
+ }
392
+ public function uptolike_on_page_callback()
393
+ {
394
+ echo '<input type="checkbox" id="on_page" name="my_option_name[on_page]"';
395
+ echo ($this->options['on_page'] == '1' ? 'checked="checked"' : ''); echo ' />';
396
+
397
+ }
398
+
399
+
400
+ public function uptolike_widget_position_callback()
401
+ {
402
+ $top = $bottom = $both = $default = '';
403
+
404
+ if (isset($this->options['widget_position'])) {
405
+ if ('top' == $this->options['widget_position']) {
406
+ $top = "selected='selected'";
407
+ } elseif ('bottom' == $this->options['widget_position']) {
408
+ $bottom = "selected='selected'";
409
+ } elseif ('both' == $this->options['widget_position']) {
410
+ $both = "selected='selected'";
411
+ } else {
412
+ $bottom = "selected='selected'";
413
+ }
414
+ } else {
415
+ $my_options = get_option('my_option_name');
416
+ $my_options['widget_position'] = 'bottom'; // cryptkey store
417
+ update_option('my_option_name', $my_options);
418
+ }
419
+ $default = "selected='selected'";
420
+ echo "<select id='widget_position' name='my_option_name[widget_position]'>
421
+ <option {$top} value='top'>Только сверху</option>
422
+ <option {$bottom} value='bottom'>Только снизу</option>
423
+ <option {$both} value='both'>Сверху и снизу</option>
424
+ </select>";
425
+
426
+ }
427
+
428
+ }
429
+
430
+
431
+ function add_widget($content)
432
+ {
433
+ //print_r($options = get_option('my_option_name'));
434
+ //return $content;
435
+
436
+ $options = get_option('my_option_name');
437
+ if (is_array($options) && array_key_exists('widget_code', $options)) {
438
+ $widget_code = $options['widget_code'];
439
+ $url = get_permalink();
440
+ $domain = preg_replace('/^www\./', '', $_SERVER['HTTP_HOST']);
441
+ $data_pid = 'cms' . str_replace('.', '', $domain);
442
+
443
+ $widget_code = str_replace('data-pid="-1"','data-pid="' . $data_pid . '"',$widget_code);
444
+ $widget_code = str_replace('data-pid=""','data-pid="' . $data_pid . '"',$widget_code);
445
+ $widget_code = str_replace('div data', 'div data-url="' . $url . '" data', $widget_code);
446
+ $widget_code_before = $widget_code_after = '';
447
+
448
+ if (is_page()) {//это страница
449
+ if ($options['on_page'] == 1) {
450
+ switch ($options['widget_position']) {
451
+ case 'both':
452
+ return $widget_code.$content.$widget_code;
453
+ case 'top':
454
+ return $widget_code.$content;
455
+ case 'bottom':
456
+ return $content.$widget_code;
457
+ }
458
+ } else return $content;
459
+ } elseif (is_front_page()) {
460
+ if ($options['on_main'] == 1) {
461
+ switch ($options['widget_position']) {
462
+ case 'both':
463
+ return $widget_code.$content.$widget_code;
464
+ case 'top':
465
+ return $widget_code.$content;
466
+ case 'bottom':
467
+ return $content.$widget_code;
468
+ }
469
+ } else return $content;
470
+ } else {
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
+ };
480
+
481
+ } else {
482
+ return $content;
483
+ }
484
+ }
485
+
486
+ add_filter('the_content', 'add_widget', 100);
487
+
488
+
489
+ function uptolike_shortcode( $atts ){
490
+
491
+ return add_widget("");
492
+ }
493
+ add_shortcode( 'uptolike', 'uptolike_shortcode' );
494
+
495
+ function my_widgetcode_notice()
496
+ {
497
+ $options = get_option('my_option_name');
498
+ if (is_array($options) && array_key_exists('widget_code', $options)) {
499
+ $widget_code = $options['widget_code'];
500
+ if ('' == $widget_code) {
501
+ echo " <div class='updated'>
502
+ <p>В настройках UpToLike 'Конструктор' выберите тип виджета и нажмите 'Сохранить'</p>
503
+ </div>";
504
+ }
505
+ };
506
+ }
507
+
508
+ function logger($str)
509
+ {
510
+ file_put_contents(WP_PLUGIN_DIR . '/uptolike/log.txt', date(DATE_RFC822) . $str . PHP_EOL, FILE_APPEND | LOCK_EX);
511
+ }
512
+
513
+ function try_reg()
514
+ {
515
+ include('api_functions.php');
516
+ $domain = preg_replace('/^www\./', '', $_SERVER['HTTP_HOST']);
517
+ $options = get_option('my_option_name');
518
+ $email = $options['uptolike_email'];
519
+ if ('' == $options['id_number']) {
520
+ $reg_ans = userReg($email, 'cms', 'cms' . $domain);
521
+ if (is_string($reg_ans)) {
522
+ $my_options = get_option('my_option_name');
523
+ $my_options['id_number'] = $reg_ans; // cryptkey store
524
+ $my_options['choice'] = 'reg';
525
+ update_option('my_option_name', $my_options);
526
+ };
527
+ update_option('reg_try', true);
528
+ }
529
+ }
530
+
531
+ function my_choice_notice()
532
+ {
533
+ $options = get_option('my_option_name');
534
+ if (is_bool($options) or (('' == $options['id_number']) and ((!array_key_exists('choice', $options)) OR ('ignore' !== $options['choice'])))) {
535
+ echo "<div class='updated'>
536
+ <div><img style='
537
+ float: left;
538
+ height: 38px;
539
+ margin-left: -9px;
540
+ margin-right: 5px;
541
+ ' src='//uptolike.ru/img/logo.png'>
542
+ </div>
543
+ Кнопки успешно установлены! <br>Для просмотра статистики необходимо:
544
+ <a href='options-general.php?page=uptolike_settings#enter'>Ввести полученный ключ</a>
545
+ | <a href='options-general.php?page=uptolike_settings#reg'>Запросить ключ</a>
546
+ | <a href='options-general.php?page=uptolike_settings&choice=ignore'>Скрыть</a> </div>";
547
+
548
+
549
+ };
550
+ }
551
+
552
+ function set_default_code()
553
+ {
554
+ $options = get_option('my_option_name');
555
+ if (is_bool($options)) {
556
+ $options = array();
557
+ }
558
+ $data_url = 'cms' . $_SERVER['HTTP_HOST'];
559
+ $data_pid = 'cms' . str_replace('.', '', preg_replace('/^www\./', '', $_SERVER['HTTP_HOST']));
560
+ $code = <<<EOD
561
+ <script type="text/javascript">(function (w, doc) {
562
+ if (!w.__utlWdgt) {
563
+ w.__utlWdgt = true;
564
+ var d = doc, s = d.createElement('script'), g = 'getElementsByTagName';
565
+ s.type = 'text/javascript';
566
+ s.charset = 'UTF-8';
567
+ s.async = true;
568
+ s.src = ('https:' == w.location.protocol ? 'https' : 'http') + '://w.uptolike.com/widgets/v1/uptolike.js';
569
+ var h = d[g]('body')[0];
570
+ h.appendChild(s);
571
+ }
572
+ })(window, document);
573
+ </script>
574
+ <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">
575
+ </div>
576
+ EOD;
577
+
578
+ $code = str_replace('data-pid', 'data-pid="' . $data_pid . '"', $code);
579
+
580
+ $code = str_replace('data-url', 'data-url="' . $data_url . '"', $code);
581
+ $options['widget_code'] = $code;
582
+ $options['on_main'] = 1;
583
+ $options['on_page'] = 0;
584
+ $options['widget_position'] = 'bottom';
585
+
586
+ update_option('my_option_name', $options);
587
+ }
588
+
589
+ function choice_helper($choice)
590
+ {
591
+ $options = get_option('my_option_name');
592
+ $options['choice'] = $choice;
593
+ if ('ignore' == $choice) {
594
+ set_default_code();
595
+ }
596
+ update_option('my_option_name', $options);
597
+ }
598
+
599
+ /*function usb_admin_bar() {
600
+ global $wp_admin_bar;
601
+
602
+ echo 'run usb admin bar';
603
+ //Add a link called at the top admin bar
604
+ $wp_admin_bar->add_node(array(
605
+ 'id' => 'UpToLike',
606
+ 'title' => 'UpToLike',
607
+ 'href' => admin_url( 'options-general.php?page=uptolike_settings', 'http' )
608
+ ));
609
+
610
+ }
611
+ */
612
+
613
+ function usb_admin_actions()
614
+ {
615
+ //echo 'run usb_admin_actions';
616
+ if ( current_user_can('manage_options') ) {
617
+ if (function_exists('add_meta_box')) {
618
+
619
+ add_menu_page("UpToLike", "UpToLike", "manage_options", "UpToLike", 'my_custom_menu_page', plugins_url('uptolike-share/logo-small.png'));
620
+ } else {
621
+ // add_submenu_page("index.php", "UpToLike", "UpToLike", "manage_options", "UpToLike", "uptolike_settings", 'http://uptolike.com/favicon.ico');
622
+ } // end if addmeta box
623
+ if (get_option( OPTION_NAME_ENABLE_ADMIN_MENU, 'false' ) == 'true' ){
624
+ add_action( 'wp_before_admin_bar_render', 'usb_admin_bar' );
625
+ }
626
+
627
+ //wpo_detectDBType();
628
+ //wpo_PluginOptionsSetDefaults();
629
+ //wpo_cron_activate();
630
+ }
631
+ }
632
+
633
+ function my_custom_menu_page(){
634
+ include_once( 'usb-admin.php' );
635
+ }
636
+
637
+ register_activation_hook(__FILE__,'usb_admin_actions');
638
+ register_deactivation_hook(__FILE__,'usb_admin_actions_remove');
639
+
640
+ add_action('admin_notices', 'my_choice_notice');
641
+ add_action('admin_notices', 'my_widgetcode_notice');
642
+ add_action('admin_menu', 'usb_admin_actions');
643
+ //add_action( 'wp_before_admin_bar_render', 'wpo_admin_bar' );
644
+
645
+ $options = get_option('my_option_name');
646
+
647
+ if (is_admin()) {
648
+ $options = get_option('my_option_name');
649
+
650
+ if (array_key_exists('regme', $_REQUEST)) {
651
+ try_reg();
652
+ }
653
+ if (array_key_exists('choice', $_REQUEST)) {
654
+ choice_helper($_REQUEST['choice']);
655
+ }
656
+
657
+ $my_settings_page = new MySettingsPage();
658
+ if (is_bool($options) OR (!array_key_exists('widget_code', $options)) OR ('' == $options['widget_code'])) {
659
+ set_default_code();
660
+ }
661
+
662
+ }