Uptolike Social Share Buttons - Version 1.2.2

Version Description

  • Enhancement: cut spaces in cryptkey field
  • Enhancement: feedback link
  • Enhancement: access to plugins by top menu item
Download this release

Release Info

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

Version 1.2.2

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
+
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,81 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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: 3.9.2
6
+ Stable tag: 1.2.2
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.2 =
70
+ * Enhancement: cut spaces in cryptkey field
71
+ * Enhancement: feedback link
72
+ * Enhancement: access to plugins by top menu item
73
+
74
+ = 1.2.1 =
75
+ * Bug Fix: minor bug fixes
76
+
77
+ = 1.2.0 =
78
+ * Enhancement: user registration.
79
+
80
+ = 1.0.0 =
81
+ * 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
+ <?
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.2
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,216 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Created by PhpStorm.
4
+ * User: root
5
+ * Date: 18.08.14
6
+ * Time: 12:15
7
+ */
8
+ function constructorIframe($projectId, $partnerId, $mail, $cryptKey)
9
+ {
10
+
11
+ $params = array('mail' => $mail,
12
+ 'partner' => $partnerId,
13
+ 'projectId' => $projectId);
14
+
15
+ $paramsStr = 'mail=' . $mail . '&partner=' . $partnerId . '&projectId=' . $projectId . $cryptKey;
16
+ $signature = md5($paramsStr);
17
+ $params['signature'] = $signature;
18
+ if ('' !== $cryptKey) {
19
+ $finalUrl = 'http://uptolike.com/api/constructor.html?' . http_build_query($params);
20
+ } else $finalUrl = 'http://uptolike.com/api/constructor.html';
21
+
22
+
23
+ return $finalUrl;
24
+ }
25
+
26
+ function statIframe($projectId, $partnerId, $mail, $cryptKey)
27
+ {
28
+ $params = array(
29
+ 'mail' => $mail,
30
+ 'partner' => $partnerId,
31
+ 'projectId' => $projectId,
32
+
33
+ );
34
+ $paramsStr = 'mail=' . $mail . '&partner=' . $partnerId . '&projectId=' . $projectId;
35
+ $signature = md5($paramsStr . $cryptKey);
36
+ $params['signature'] = $signature;
37
+ $finalUrl = 'http://uptolike.com/api/statistics.html?' . http_build_query($params);
38
+
39
+ return $finalUrl;
40
+ }
41
+
42
+ function usb_admin_page()
43
+ {
44
+
45
+ $options = get_option('my_option_name');
46
+
47
+ if ((isset($options['uptolike_email'])) && ('' !== $options['uptolike_email'])) {
48
+ $email = $options['uptolike_email'];
49
+ } else $email = get_settings('admin_email');
50
+ $partnerId = 'cms';
51
+ $projectId = 'cms' . preg_replace('/^www\./', '', $_SERVER['HTTP_HOST']);
52
+ $projectId = str_replace('.', '', $projectId);
53
+ $projectId = str_replace('-', '', $projectId);
54
+ $options = get_option('my_option_name');
55
+ if (is_array($options) && array_key_exists('id_number', $options)) {
56
+ $cryptKey = $options['id_number'];
57
+ } else $cryptKey = '';
58
+ /* $this->options = get_option('my_option_name');
59
+
60
+ if ((isset($this->options['uptolike_email'])) && ('' !== $this->options['uptolike_email'])) {
61
+ $email = $this->options['uptolike_email'];
62
+ } else $email = get_settings('admin_email');
63
+ $partnerId = 'cms';
64
+ $projectId = 'cms' . preg_replace('/^www\./', '', $_SERVER['HTTP_HOST']);l
65
+ $projectId = str_replace('.','',$projectId);
66
+ $projectId = str_replace('-','',$projectId);
67
+ $options = get_option('my_option_name');
68
+ if (is_array($options) && array_key_exists('id_number', $options)) {
69
+ $cryptKey = $options['id_number'];
70
+ } else $cryptKey = '';
71
+ */
72
+ ?>
73
+ <script type="text/javascript">
74
+ <? include('main.js'); ?>
75
+ </script>
76
+ <style type="text/css">
77
+ h2.placeholder {
78
+ font-size: 1px;
79
+ padding: 1px;
80
+ margin: 0px;
81
+ height: 2px;
82
+ }
83
+
84
+ div.wrapper-tab {
85
+ display: none;
86
+ }
87
+
88
+ div.wrapper-tab.active {
89
+ display: block;
90
+ width: 100%;
91
+ }
92
+
93
+ input#id_number {
94
+ width: 520px;
95
+ }
96
+ </style>
97
+ <div class="wrap">
98
+ <h2 class="placeholder">&nbsp;</h2>
99
+
100
+ <div id="wrapper">
101
+ <form id="settings_form" method="post" action="options.php">
102
+ <H1> UpToLike виджет</H1>
103
+
104
+ <h2 class="nav-tab-wrapper">
105
+ <a class="nav-tab nav-tab-active" href="#" id="construct">
106
+ Конструктор
107
+ </a>
108
+ <a class="nav-tab" href="#" id="stat">
109
+ Статистика
110
+ </a>
111
+
112
+ <a class="nav-tab" href="#" id="settings">
113
+ Настройки
114
+ </a>
115
+ </h2>
116
+
117
+ <div class="wrapper-tab active" id="con_construct">
118
+ <iframe id='cons_iframe' style='height: 445px;width: 100%;'
119
+ data-src="<?php echo constructorIframe($projectId, $partnerId, $email, $cryptKey); ?>"></iframe>
120
+ <br>
121
+ <a onclick="getCode();" href="#">
122
+ <button type="reset">Сохранить изменения</button>
123
+ </a>
124
+ </div>
125
+ <div class="wrapper-tab" id="con_stat">
126
+ <? if (('' == $partnerId) OR ('' == $email) OR ('' == $cryptKey)) {
127
+
128
+ ?>
129
+ <h2>Статистика</h2>
130
+ <p>Для просмотра статистики необходимо ввести ваш секретный ключ </p>
131
+ <? } else { ?>
132
+ <!-- <?php print_r(array($partnerId, $email, $cryptKey)); ?> -->
133
+ <iframe style="width: 100%;height: 380px;" id="stats_iframe"
134
+ data-src="<?php echo statIframe($projectId, $partnerId, $email, $cryptKey); ?>">
135
+ </iframe> <?
136
+ } ?>
137
+ <button class="reg_btn" type="button">Запросить секретный ключ</button>
138
+ <br/>
139
+
140
+ <div class="reg_block">
141
+ <label>Email<input type="text" class="uptolike_email"></label><br/>
142
+ <button type="button" class="button-primary">Отправить ключ на email</button>
143
+ <br/>
144
+ </div>
145
+ <button class="enter_btn" type="button">Авторизация</button>
146
+ <br/>
147
+
148
+ <div class="enter_block">
149
+ <label>Email<input type="text" class="uptolike_email"></label><br/>
150
+ <label>Ключ<input type="text" class="id_number"></label><br/>
151
+ <button type="button" class="button-primary">Сохранить</button>
152
+ <br/>
153
+ </div>
154
+ </div>
155
+
156
+ <div class="wrapper-tab " id="con_settings">
157
+ <input type="hidden" name="option_page" value="my_option_group"><input type="hidden" name="action"
158
+ value="update"><input
159
+ type="hidden" id="_wpnonce" name="_wpnonce" value="cac4f73a65"><input type="hidden"
160
+ name="_wp_http_referer"
161
+ value="/wp-admin/options-general.php?page=uptolike_settings">
162
+
163
+ <h3>Настройки виджета</h3>
164
+ <table class="form-table">
165
+ <tbody>
166
+ <tr style="display:none">
167
+ <th scope="row">код виджета</th>
168
+ <td><textarea id="widget_code" name="my_option_name[widget_code]"></textarea></td>
169
+ </tr>
170
+ <tr style="display:none">
171
+ <th scope="row">Ключ(CryptKey)</th>
172
+ <td><input type="text" class="id_number" name="my_option_name[id_number]" value=""
173
+ style="width: 520px;"></td>
174
+ </tr>
175
+ <tr style="display:none">
176
+ <th scope="row">email для регистрации</th>
177
+ <td><input type="text" id="uptolike_email" name="my_option_name[uptolike_email]"
178
+ value="">
179
+ <button type="button" onclick="regMe();">Зарегистрироваться</button>
180
+ </td>
181
+ </tr>
182
+ <tr>
183
+ <th scope="row">Располагать блок на главной странице</th>
184
+ <td><input type="checkbox" id="on_main" name="my_option_name[on_main]" checked="checked">
185
+ </td>
186
+ </tr>
187
+ <tr>
188
+ <th scope="row">Расположение виджета</th>
189
+ <td><select id="widget_position" name="my_option_name[widget_position]">
190
+ <option value="top">Только сверху</option>
191
+ <option selected="selected" value="bottom">Только снизу</option>
192
+ <option value="both">Сверху и снизу</option>
193
+ </select></td>
194
+ </tr>
195
+ <tr>
196
+ <th scope="row">Обратная связь</th>
197
+ <td><a href="mailto:support@uptolike.com" target="_top"> support@uptolike.com</a></td>
198
+ </tr>
199
+ <tr style="display:none">
200
+ <th scope="row">настройки конструктора</th>
201
+ <td><input type="hidden" id="uptolike_json" name="my_option_name[uptolike_json]" value="">
202
+ </td>
203
+ </tr>
204
+ </tbody>
205
+ </table>
206
+ <input type="submit" name="submit_btn" value="Cохранить изменения">
207
+ </div>
208
+
209
+
210
+ </form>
211
+ </div>
212
+ </div>
213
+ <?php
214
+ }
215
+
216
+ usb_admin_page();
widget_options.php ADDED
@@ -0,0 +1,624 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 = 'http://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 = 'http://uptolike.com/api/constructor.html?' . http_build_query($params);
70
+ } else $finalUrl = 'http://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_settings('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
+ <? 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
+ <? if (('' == $partnerId) OR ('' == $email) OR ('' == $cryptKey)) {
165
+
166
+ ?>
167
+ <h2>Статистика</h2>
168
+ <p>Для просмотра статистики необходимо ввести ваш секретный ключ </p>
169
+ <? } 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> <?
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
+ 'Располагать блок на главной странице',
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
+ 'widget_position', //ID
249
+ 'Расположение виджета',
250
+ array($this, 'uptolike_widget_position_callback'),
251
+ $this->settings_page_name, //'my-setting-admin',
252
+ 'setting_section_id'
253
+ );
254
+
255
+ add_settings_field(
256
+ 'feedback', //ID
257
+ 'Обратная связь',
258
+ array($this, 'uptolike_feedback_callback'),
259
+ $this->settings_page_name, //'my-setting-admin',
260
+ 'setting_section_id'
261
+ );
262
+
263
+
264
+ add_settings_field(
265
+ 'uptolike_json', //ID
266
+ 'настройки конструктора',
267
+ array($this, 'uptolike_json_callback'),
268
+ $this->settings_page_name, //'my-setting-admin',
269
+ 'setting_section_id'
270
+ );
271
+ }
272
+
273
+ /**
274
+ * Sanitize each setting field as needed
275
+ *
276
+ * @param array $input Contains all settings fields as array keys
277
+ */
278
+ public function sanitize($input)
279
+ {
280
+ $new_input = array();
281
+ if (isset($input['id_number']))
282
+ $new_input['id_number'] = str_replace(' ','',$input['id_number']);
283
+
284
+ if (isset($input['widget_code']))
285
+ $new_input['widget_code'] = $input['widget_code'];
286
+
287
+ if (isset($input['uptolike_email']))
288
+ $new_input['uptolike_email'] = $input['uptolike_email'];
289
+
290
+ if (isset($input['before_content']))
291
+ $new_input['before_content'] = $input['before_content'];
292
+
293
+ if (isset($input['on_main'])) {
294
+ $new_input['on_main'] = true;
295
+
296
+ } else $new_input['on_main'] = false;
297
+
298
+ if (isset($input['email']))
299
+ $new_input['email'] = $input['email'];
300
+
301
+ if (isset($input['after_content']))
302
+ $new_input['after_content'] = $input['after_content'];
303
+
304
+ if (isset($input['widget_position']))
305
+ $new_input['widget_position'] = $input['widget_position'];
306
+
307
+ if (isset($input['uptolike_json']))
308
+ $new_input['uptolike_json'] = $input['uptolike_json'];
309
+
310
+ return $new_input;
311
+ }
312
+
313
+
314
+ public function print_section_info()
315
+ {
316
+ //print 'Enter your settings below:';
317
+ }
318
+
319
+ public function widget_code_callback()
320
+ {
321
+ printf(
322
+ '<textarea id="widget_code" name="my_option_name[widget_code]" >%s</textarea>',
323
+ isset($this->options['widget_code']) ? esc_attr($this->options['widget_code']) : ''
324
+ );
325
+ }
326
+
327
+ /** 12536473050877
328
+ * Get the settings option array and print one of its values
329
+ */
330
+ public function id_number_callback()
331
+ {
332
+ printf(
333
+ '<input type="text" class="id_number" name="my_option_name[id_number]" value="%s" />',
334
+ isset($this->options['id_number']) ? esc_attr($this->options['id_number']) : ''
335
+ );
336
+ }
337
+
338
+ public function uptolike_email_callback()
339
+ {
340
+ printf(
341
+ '<input type="text" id="uptolike_email" name="my_option_name[uptolike_email]" value="%s" />',
342
+ isset($this->options['uptolike_email']) ? esc_attr($this->options['uptolike_email']) : get_settings('admin_email')
343
+ );
344
+ }
345
+
346
+ public function uptolike_json_callback()
347
+ {
348
+ printf(
349
+ '<input type="hidden" id="uptolike_json" name="my_option_name[uptolike_json]" value="%s" />',
350
+ isset($this->options['uptolike_json']) ? esc_attr($this->options['uptolike_json']) : ''
351
+ );
352
+ }
353
+
354
+ public function uptolike_partner_id_callback()
355
+ {
356
+ printf(
357
+ '<input type="text" id="uptolike_partner" name="my_option_name[uptolike_partner]" value="%s" />',
358
+ isset($this->options['uptolike_partner']) ? esc_attr($this->options['uptolike_partner']) : ''
359
+ );
360
+ }
361
+
362
+ public function uptolike_feedback_callback()
363
+ {
364
+ echo '<a href="mailto:support@uptolike.com" target="_top"> support@uptolike.com</a>';
365
+ }
366
+
367
+ public function uptolike_project_callback()
368
+ {
369
+ printf(
370
+ '<input type="text" id="uptolike_project" name="my_option_name[uptolike_project]" value="%s" />',
371
+ isset($this->options['uptolike_project']) ? esc_attr($this->options['uptolike_project']) : ''
372
+ );
373
+ }
374
+
375
+ public function uptolike_on_main_callback()
376
+ {
377
+ echo '<input type="checkbox" id="on_main" name="my_option_name[on_main]"';
378
+ echo ($this->options['on_main'] == true ? 'checked="checked"' : ''); echo ' />';
379
+
380
+ }
381
+
382
+
383
+ public function uptolike_widget_position_callback()
384
+ {
385
+ $top = $bottom = $both = $default = '';
386
+
387
+ if (isset($this->options['widget_position'])) {
388
+ if ('top' == $this->options['widget_position']) {
389
+ $top = "selected='selected'";
390
+ } elseif ('bottom' == $this->options['widget_position']) {
391
+ $bottom = "selected='selected'";
392
+ } elseif ('both' == $this->options['widget_position']) {
393
+ $both = "selected='selected'";
394
+ } else {
395
+ $bottom = "selected='selected'";
396
+ }
397
+ } else {
398
+ $my_options = get_option('my_option_name');
399
+ $my_options['widget_position'] = 'bottom'; // cryptkey store
400
+ update_option('my_option_name', $my_options);
401
+ }
402
+ $default = "selected='selected'";
403
+ echo "<select id='widget_position' name='my_option_name[widget_position]'>
404
+ <option {$top} value='top'>Только сверху</option>
405
+ <option {$bottom} value='bottom'>Только снизу</option>
406
+ <option {$both} value='both'>Сверху и снизу</option>
407
+ </select>";
408
+
409
+ }
410
+
411
+ }
412
+
413
+
414
+ function add_widget($content)
415
+ {
416
+
417
+ $options = get_option('my_option_name');
418
+ if (is_array($options) && array_key_exists('widget_code', $options)) {
419
+ $widget_code = $options['widget_code'];
420
+ $url = get_permalink();
421
+
422
+ //fixing bad data-pid
423
+ $domain = preg_replace('/^www\./', '', $_SERVER['HTTP_HOST']);
424
+ $data_pid = 'cms' . str_replace('.', '', $domain);
425
+
426
+ $widget_code = str_replace('data-pid="-1"','data-pid="' . $data_pid . '"',$widget_code);
427
+ $widget_code = str_replace('data-pid=""','data-pid="' . $data_pid . '"',$widget_code);
428
+ $widget_code = str_replace('div data', 'div data-url="' . $url . '" data', $widget_code);
429
+ $widget_code_before = $widget_code_after = '';
430
+
431
+ if ((!is_single() && array_key_exists('on_main', $options) && $options['on_main']) or is_single()) {
432
+ switch ($options['widget_position']) {
433
+ case 'both':
434
+ $widget_code_before = $widget_code_after = $widget_code;
435
+ break;
436
+ case 'top':
437
+ $widget_code_before = $widget_code;
438
+ break;
439
+ case 'bottom':
440
+ $widget_code_after = $widget_code;
441
+ break;
442
+ }
443
+ return $widget_code_before.$content.$widget_code_after;
444
+ }
445
+ } else {
446
+ return $content;
447
+ }
448
+ }
449
+
450
+ add_filter('the_content', 'add_widget', 100);
451
+
452
+
453
+ function uptolike_shortcode( $atts ){
454
+
455
+ return add_widget("");
456
+ }
457
+ add_shortcode( 'uptolike', 'uptolike_shortcode' );
458
+
459
+ function my_widgetcode_notice()
460
+ {
461
+ $options = get_option('my_option_name');
462
+ if (is_array($options) && array_key_exists('widget_code', $options)) {
463
+ $widget_code = $options['widget_code'];
464
+ if ('' == $widget_code) {
465
+ echo " <div class='updated'>
466
+ <p>В настройках UpToLike 'Конструктор' выберите тип виджета и нажмите 'Сохранить'</p>
467
+ </div>";
468
+ }
469
+ };
470
+ }
471
+
472
+ function logger($str)
473
+ {
474
+ file_put_contents(WP_PLUGIN_DIR . '/uptolike/log.txt', date(DATE_RFC822) . $str . PHP_EOL, FILE_APPEND | LOCK_EX);
475
+ }
476
+
477
+ function try_reg()
478
+ {
479
+ include('api_functions.php');
480
+ $domain = preg_replace('/^www\./', '', $_SERVER['HTTP_HOST']);
481
+ $options = get_option('my_option_name');
482
+ $email = $options['uptolike_email'];
483
+ if ('' == $options['id_number']) {
484
+ $reg_ans = userReg($email, 'cms', 'cms' . $domain);
485
+ if (is_string($reg_ans)) {
486
+ $my_options = get_option('my_option_name');
487
+ $my_options['id_number'] = $reg_ans; // cryptkey store
488
+ $my_options['choice'] = 'reg';
489
+ update_option('my_option_name', $my_options);
490
+ };
491
+ update_option('reg_try', true);
492
+ }
493
+ }
494
+
495
+ function my_choice_notice()
496
+ {
497
+ $options = get_option('my_option_name');
498
+ if (is_bool($options) or (('' == $options['id_number']) and ((!array_key_exists('choice', $options)) OR ('ignore' !== $options['choice'])))) {
499
+ echo "<div class='updated'>
500
+ <div><img style='
501
+ float: left;
502
+ height: 38px;
503
+ margin-left: -9px;
504
+ margin-right: 5px;
505
+ ' src='//uptolike.ru/img/logo.png'>
506
+ </div>
507
+ Кнопки успешно установлены! <br>Для просмотра статистики необходимо:
508
+ <a href='options-general.php?page=uptolike_settings#enter'>Ввести полученный ключ</a>
509
+ | <a href='options-general.php?page=uptolike_settings#reg'>Запросить ключ</a>
510
+ | <a href='options-general.php?page=uptolike_settings&choice=ignore'>Скрыть</a> </div>";
511
+
512
+
513
+ };
514
+ }
515
+
516
+ function set_default_code()
517
+ {
518
+ $options = get_option('my_option_name');
519
+ if (is_bool($options)) {
520
+ $options = array();
521
+ }
522
+ $data_url = 'cms' . $_SERVER['HTTP_HOST'];
523
+ $data_pid = 'cms' . str_replace('.', '', preg_replace('/^www\./', '', $_SERVER['HTTP_HOST']));
524
+ $code = <<<EOD
525
+ <script type="text/javascript">(function (w, doc) {
526
+ if (!w.__utlWdgt) {
527
+ w.__utlWdgt = true;
528
+ var d = doc, s = d.createElement('script'), g = 'getElementsByTagName';
529
+ s.type = 'text/javascript';
530
+ s.charset = 'UTF-8';
531
+ s.async = true;
532
+ s.src = ('https:' == w.location.protocol ? 'https' : 'http') + '://w.uptolike.com/widgets/v1/uptolike.js';
533
+ var h = d[g]('body')[0];
534
+ h.appendChild(s);
535
+ }
536
+ })(window, document);
537
+ </script>
538
+ <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">
539
+ </div>
540
+ EOD;
541
+
542
+ $code = str_replace('data-pid', 'data-pid="' . $data_pid . '"', $code);
543
+
544
+ $code = str_replace('data-url', 'data-url="' . $data_url . '"', $code);
545
+ $options['widget_code'] = $code;
546
+ $options['on_main'] = true;
547
+ $options['widget_position'] = 'bottom';
548
+
549
+ update_option('my_option_name', $options);
550
+ }
551
+
552
+ function choice_helper($choice)
553
+ {
554
+ $options = get_option('my_option_name');
555
+ $options['choice'] = $choice;
556
+ if ('ignore' == $choice) {
557
+ set_default_code();
558
+ }
559
+ update_option('my_option_name', $options);
560
+ }
561
+
562
+ /*function usb_admin_bar() {
563
+ global $wp_admin_bar;
564
+
565
+ echo 'run usb admin bar';
566
+ //Add a link called at the top admin bar
567
+ $wp_admin_bar->add_node(array(
568
+ 'id' => 'UpToLike',
569
+ 'title' => 'UpToLike',
570
+ 'href' => admin_url( 'options-general.php?page=uptolike_settings', 'http' )
571
+ ));
572
+
573
+ }
574
+ */
575
+
576
+ function usb_admin_actions()
577
+ {
578
+ //echo 'run usb_admin_actions';
579
+ if ( current_user_can('manage_options') ) {
580
+ if (function_exists('add_meta_box')) {
581
+ add_menu_page("UpToLike", "UpToLike", "manage_options", "UpToLike", 'my_custom_menu_page', 'http://uptolike.com/favicon.ico');
582
+ } else {
583
+ // add_submenu_page("index.php", "UpToLike", "UpToLike", "manage_options", "UpToLike", "uptolike_settings", 'http://uptolike.com/favicon.ico');
584
+ } // end if addmeta box
585
+ if (get_option( OPTION_NAME_ENABLE_ADMIN_MENU, 'false' ) == 'true' ){
586
+ add_action( 'wp_before_admin_bar_render', 'usb_admin_bar' );
587
+ }
588
+
589
+ //wpo_detectDBType();
590
+ //wpo_PluginOptionsSetDefaults();
591
+ //wpo_cron_activate();
592
+ }
593
+ }
594
+
595
+ function my_custom_menu_page(){
596
+ include_once( 'usb-admin.php' );
597
+ }
598
+
599
+ register_activation_hook(__FILE__,'usb_admin_actions');
600
+ register_deactivation_hook(__FILE__,'usb_admin_actions_remove');
601
+
602
+ add_action('admin_notices', 'my_choice_notice');
603
+ add_action('admin_notices', 'my_widgetcode_notice');
604
+ add_action('admin_menu', 'usb_admin_actions');
605
+ //add_action( 'wp_before_admin_bar_render', 'wpo_admin_bar' );
606
+
607
+ $options = get_option('my_option_name');
608
+
609
+ if (is_admin()) {
610
+ $options = get_option('my_option_name');
611
+
612
+ if (array_key_exists('regme', $_REQUEST)) {
613
+ try_reg();
614
+ }
615
+ if (array_key_exists('choice', $_REQUEST)) {
616
+ choice_helper($_REQUEST['choice']);
617
+ }
618
+
619
+ $my_settings_page = new MySettingsPage();
620
+ if (is_bool($options) OR (!array_key_exists('widget_code', $options)) OR ('' == $options['widget_code'])) {
621
+ set_default_code();
622
+ }
623
+
624
+ }