Uptolike Social Share Buttons - Version 1.5.5

Version Description

  • UpToLike
  • email

  • WidgetClass name notice
  • Code refactoring
Download this release

Release Info

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

Code changes from version 1.5.4 to 1.5.5

api_functions.php DELETED
@@ -1,59 +0,0 @@
1
- <?php
2
-
3
- const HOST = 'https://uptolike.com/';
4
-
5
- /**
6
- * @param $email
7
- * @param $partnerId 'cms' for cms modules
8
- * @param $projectId 'cms'.site name
9
- *
10
- * @return bool|string 'if false - somthing wrong, if string - it's cryptkey'
11
- */
12
- function userReg($email, $partnerId, $projectId) {
13
-
14
- if ($email !== '' && $partnerId !== '' && $projectId !== '') {
15
- $url = 'https://uptolike.com/api/getCryptKeyWithUserReg.json?' . http_build_query(array('email' => $email, 'partner' => $partnerId, 'projectId' => $projectId));
16
-
17
- $jsonAnswer = file_get_contents($url);
18
- if (false !== $jsonAnswer) {
19
- $answer = json_decode($jsonAnswer);
20
- return $answer->cryptKey;
21
- } else return $jsonAnswer;
22
-
23
- } else return 'one of params is empty';
24
- }
25
-
26
- /**
27
- * @param $partnerId String'cms' for cms modules
28
- * @param $email String
29
- * @param $cryptKey String
30
- */
31
- function statIframe($partnerId, $mail, $cryptKey) {
32
- $params = array('mail' => $mail, 'partner' => $partnerId);
33
- $paramsStr = 'mail=' . $mail . '&partner=' . $partnerId;
34
- $signature = md5($paramsStr . $cryptKey);
35
- $params['signature'] = $signature;
36
- $finalUrl = 'https://uptolike.com/api/statistics.html?' . http_build_query($params);
37
-
38
- return $finalUrl;
39
- }
40
-
41
- /**
42
- * @param $mail user email
43
- * @param $partnerId 'cms' for cms sites
44
- * @param $projectId 'cms'.site_name
45
- * @param $cryptKey crypt key, received from server
46
- *
47
- * @return string
48
- */
49
- function constructorIframe($mail, $partnerId, $projectId, $cryptKey) {
50
-
51
- $params = array('mail' => $mail, 'partner' => $partnerId, 'projectId' => $projectId);
52
-
53
- $paramsStr = 'mail=' . $mail . '&partner=' . $partnerId . '&projectId=' . $projectId . $cryptKey;
54
- $signature = md5($paramsStr);
55
- $params['signature'] = $signature;
56
- $finalUrl = 'https://uptolike.com/api/constructor.html?' . http_build_query($params);
57
-
58
- return $finalUrl;
59
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
css/uptolike_style.css CHANGED
@@ -85,7 +85,6 @@ iframe#stats_iframe {
85
  }
86
 
87
  .utl_logo {
88
- background-image: url('/wp-content/plugins/uptolike-share/images/plg_icons.png');
89
  width: 50px;
90
  height: 50px;
91
  margin-left: 17px;
85
  }
86
 
87
  .utl_logo {
 
88
  width: 50px;
89
  height: 50px;
90
  margin-left: 17px;
readme.txt CHANGED
@@ -1,9 +1,9 @@
1
  === Uptolike Social Share Buttons ===
2
  Contributors: Uptolike Team
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.6.1
6
- Stable tag: 1.5.4
7
 
8
  Uptolike Social Share Buttons - social bookmarking widget with sharing statistics.
9
 
@@ -107,6 +107,13 @@ Answers to Frequently Asked Questions you can find at http://uptolike.ru/faq
107
  3. Traffic and sharing statistics
108
 
109
  == Changelog ==
 
 
 
 
 
 
 
110
  = 1.5.4 =
111
  * Исправлен некорректный вывод шорткода
112
 
1
  === Uptolike Social Share Buttons ===
2
  Contributors: Uptolike Team
3
+ Tags: +1, UpToLike, AddThis, social buttons, bookmark, bookmarking, like, share, share button, sharing, social bookmarking, social bookmarks, кнопки соцсетей, социальные кнопки
4
  Requires at least: 3.0.1
5
+ Tested up to: 4.7
6
+ Stable tag: 1.5.5
7
 
8
  Uptolike Social Share Buttons - social bookmarking widget with sharing statistics.
9
 
107
  3. Traffic and sharing statistics
108
 
109
  == Changelog ==
110
+ = 1.5.5 =
111
+ * Исправлен вывод UpToLike для страниц записей и статических страниц
112
+ * Добавлено удаление лишних пробелов в поле email на странице статистики
113
+ * Все ссылки в плагине исправлены на абсолютные
114
+ * Исправлен WidgetClass name notice
115
+ * Code refactoring
116
+
117
  = 1.5.4 =
118
  * Исправлен некорректный вывод шорткода
119
 
uninstall.php DELETED
@@ -1,14 +0,0 @@
1
- <?php
2
-
3
- if (!defined('WP_UNINSTALL_PLUGIN'))
4
- exit();
5
-
6
- function uptolike_delete_plugin() {
7
-
8
- delete_option('my_option_name');
9
- }
10
-
11
- uptolike_delete_plugin();
12
-
13
- ?>
14
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
uptolike_share_widget.php CHANGED
@@ -3,9 +3,9 @@
3
  * Plugin Name: UpToLike Social Share Buttons
4
  * Plugin URI: https://uptolike.com/
5
  * Description: Uptolike Social Share Buttons - social bookmarking widget with sharing statistics.
6
- * Version: 1.5.4
7
  * Requires at least: 4.1
8
- * Tested up to: 4.6.1
9
  * Author: Uptolike Team
10
  * Author URI: https://uptolike.com/
11
  *
@@ -16,3 +16,39 @@
16
 
17
  include 'widget_options.php';
18
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3
  * Plugin Name: UpToLike Social Share Buttons
4
  * Plugin URI: https://uptolike.com/
5
  * Description: Uptolike Social Share Buttons - social bookmarking widget with sharing statistics.
6
+ * Version: 1.5.5
7
  * Requires at least: 4.1
8
+ * Tested up to: 4.7
9
  * Author: Uptolike Team
10
  * Author URI: https://uptolike.com/
11
  *
16
 
17
  include 'widget_options.php';
18
 
19
+ add_filter('plugin_action_links', 'uptolike_action_links', 10, 2);
20
+
21
+ function uptolike_action_links($links, $file) {
22
+ if (false === strpos($file, basename(__FILE__))) return $links;
23
+ $links[] = '<a href="' . add_query_arg(array('page' => 'uptolike_settings'), admin_url('plugins.php')) . '">' . __('Settings') . '</a>';
24
+ return $links;
25
+ }
26
+
27
+ add_filter('plugin_row_meta', 'uptolike_description_links', 10, 4);
28
+
29
+ function uptolike_description_links($links, $file) {
30
+ if (false === strpos($file, basename(__FILE__))) return $links;
31
+ $links[] = '<a href="' . add_query_arg(array('page' => 'uptolike_settings'), admin_url('plugins.php')) . '">' . __('Settings') . '</a>';
32
+ return $links;
33
+ }
34
+
35
+ register_activation_hook( __FILE__, 'uptolike_install' );
36
+ register_uninstall_hook( __FILE__, 'uptolike_delete_plugin' );
37
+
38
+ function uptolike_delete_plugin() {
39
+ $delete = get_option('uptolike_options');
40
+ $delete['uptolike_email'] = '';
41
+ $delete['id_number'] = '';
42
+ update_option('uptolike_options', $delete);
43
+ }
44
+
45
+
46
+ function uptolike_install() {
47
+ $options = get_option('my_option_name');
48
+ if (!is_bool($options)) {
49
+ $options['uptolike_email'] = '';
50
+ $options['id_number'] = '';
51
+ update_option('uptolike_options', $options);
52
+ delete_option('my_option_name');
53
+ }
54
+ }
usb-admin.php DELETED
@@ -1,187 +0,0 @@
1
- <?php
2
-
3
- function constructorIframe($projectId, $partnerId, $mail, $cryptKey) {
4
- $params = array('mail' => $mail, 'partner' => $partnerId, 'projectId' => $projectId);
5
-
6
- $paramsStr = 'mail=' . $mail . '&partner=' . $partnerId . '&projectId=' . $projectId . $cryptKey;
7
- $signature = md5($paramsStr);
8
- $params['signature'] = $signature;
9
- if ('' !== $cryptKey) {
10
- $finalUrl = 'https://uptolike.com/api/constructor.html?' . http_build_query($params);
11
- } else $finalUrl = 'https://uptolike.com/api/constructor.html';
12
-
13
- return $finalUrl;
14
- }
15
-
16
- function statIframe($projectId, $partnerId, $mail, $cryptKey) {
17
- $params = array('mail' => $mail, 'partner' => $partnerId, 'projectId' => $projectId,
18
-
19
- );
20
- $paramsStr = 'mail=' . $mail . '&partner=' . $partnerId . '&projectId=' . $projectId;
21
- $signature = md5($paramsStr . $cryptKey);
22
- $params['signature'] = $signature;
23
- $finalUrl = 'https://uptolike.com/api/statistics.html?' . http_build_query($params);
24
-
25
- return $finalUrl;
26
- }
27
-
28
- function usb_admin_page() {
29
- $options = get_option('my_option_name');
30
-
31
- if ((isset($options['uptolike_email'])) && ('' !== $options['uptolike_email'])) {
32
- $email = $options['uptolike_email'];
33
- } else $email = get_option('admin_email');
34
- $partnerId = 'cms';
35
- $projectId = 'cms' . preg_replace('/^www\./', '', $_SERVER['HTTP_HOST']);
36
- $projectId = str_replace('.', '', $projectId);
37
- $projectId = str_replace('-', '', $projectId);
38
- $options = get_option('my_option_name');
39
- if (is_array($options) && array_key_exists('id_number', $options)) {
40
- $cryptKey = $options['id_number'];
41
- } else $cryptKey = '';
42
-
43
- ?>
44
- <script type="text/javascript">
45
- <?php include('js/main.js'); ?>
46
- </script>
47
- <style type="text/css">
48
- <?php include('css/uptolike_style.css')?>
49
- </style>
50
- <div id="uptolike_site_url" style="display: none"><?php echo get_site_url(); ?></div>
51
- <div class="wrap">
52
- <h2 class="placeholder">&nbsp;</h2>
53
-
54
- <div id="wrapper">
55
- <form id="settings_form" method="post" action="options.php">
56
- <h1>UpToLike виджет</h1>
57
-
58
- <h2 class="nav-tab-wrapper">
59
- <a class="nav-tab nav-tab-active" href="#" id="construct">
60
- Конструктор
61
- </a>
62
- <a class="nav-tab" href="#" id="stat">
63
- Статистика
64
- </a>
65
- <a class="nav-tab" href="#" id="settings">
66
- Настройки
67
- </a>
68
- </h2>
69
-
70
- <div class="wrapper-tab active" id="con_construct">
71
- <iframe id='cons_iframe' style='height: 445px;width: 100%;'
72
- data-src="<?php echo constructorIframe($projectId, $partnerId, $email, $cryptKey); ?>"></iframe>
73
- <br>
74
- <a onclick="getCode();" href="#">
75
- <button type="reset">Сохранить изменения</button>
76
- </a>
77
- </div>
78
- <div class="wrapper-tab" id="con_stat">
79
-
80
- <iframe style="width: 100%;height: 380px;" id="stats_iframe"
81
- data-src="<?php echo statIframe($projectId, $partnerId, $email, $cryptKey); ?>">
82
- </iframe>
83
-
84
- <div id="before_key_req">Введите ваш адрес электронной почты для получения
85
- ключа.
86
- </div>
87
- <div id="after_key_req">На ваш адрес электронной почты отправлен секретный ключ.
88
- Введите его в поле ниже<br/>
89
- Если письмо с ключом долго не приходит, возможно оно попало в
90
- Спам.<br/><br/>
91
- Если ключ так и не был получен напишите письмо в службу поддержки: <a
92
- href="mailto:uptolikeshare@gmail.com">uptolikeshare@gmail.com</a><br/>
93
- В письме пришлите, пожалуйста, адрес вашего сайта и адрес электронной почты,
94
- указанный в плагине.<br/>
95
- </div>
96
- <table>
97
- <tr id="email_tr">
98
- <td>Email:</td>
99
- <td><input type="text" id="uptolike_email_field"></td>
100
- </tr>
101
- <tr id="cryptkey_field">
102
- <td>Ключ:</td>
103
- <td><input type="text" id="uptolike_cryptkey"></td>
104
- </tr>
105
- <tr id="get_key_btn_field">
106
- <td></td>
107
- <td>
108
- <button id="get_key" type="button"> Получить ключ</button>
109
- </td>
110
- </tr>
111
- <tr id="bad_key_field">
112
- <td colspan="2">Введен неверный ключ! Убедитесь что вы скопировали ключ
113
- без лишних символов (пробелов и т.д.)
114
- </td>
115
- </tr>
116
- <tr id="foreignAccess_field">
117
- <td colspan="2">Данный проект принадлежит другому пользователю.
118
- Обратитесь в службу поддержки
119
- </td>
120
- </tr>
121
- <tr id="key_auth_field">
122
- <td></td>
123
- <td>
124
- <button id="auth" type="button"> Авторизация</button>
125
- </td>
126
- </tr>
127
- </table>
128
- <div>Обратная связь: <a href="mailto:uptolikeshare@gmail.com">uptolikeshare@gmail.com</a>
129
- </div>
130
- </div>
131
- <div class="wrapper-tab " id="con_settings">
132
- <div class="utl_left_block">
133
- <?php
134
- $my_settings_page = new MySettingsPage();
135
- $my_settings_page->page_init();
136
- settings_fields('my_option_group');
137
- do_settings_sections($my_settings_page->settings_page_name);
138
- ?>
139
- <input type="submit" name="submit_btn" value="Cохранить изменения">
140
- <br>
141
- </div>
142
- <div class="utl_right_block">
143
- <div class="utl_blok1">
144
- <div class="utl_blok2">
145
- <div class="utl_logo utl_i_logo">
146
- </div>
147
- </div>
148
- <div class="utl_innertext">Для вставки шорткода в .php файл шаблона
149
- нужно использовать конструкцию
150
- <br><b><i>
151
- &lt;?php echo do_shortcode("[uptolike]"); ?&gt;<br></i></b>
152
- Для вставки в режиме визуального редактора достаточно вставить<b>
153
- <i>[uptolike]</i></b>.
154
- </div>
155
- </div>
156
- <div class="utl_blok1">
157
- <div class="utl_blok2">
158
- <div class="utl_logo utl_like_logo">
159
- </div>
160
- </div>
161
- <div class="utl_innertext">Данный плагин полностью бесплатен. Мы
162
- регулярно его улучшаем и добавляем новые функции.<br>
163
- Пожалуйста, оставьте свой отзыв на <a
164
- href="https://wordpress.org/support/view/plugin-reviews/uptolike-share">данной
165
- странице</a>. Спасибо! <br>
166
- </div>
167
- </div>
168
- <div class="utl_blok1">
169
- <div class="utl_blok2">
170
- <div class="utl_logo utl_mail_logo">
171
- </div>
172
- </div>
173
- <div class="utl_innertext"><a href="http://uptolike.ru">Uptolike.ru</a>
174
- - конструктор социальных кнопок для вашего сайта с расширенным
175
- функционалом.<br>
176
- Служба поддержки: <a href="mailto:uptolikeshare@gmail.com">uptolikeshare@gmail.com</a>
177
- </div>
178
- </div>
179
- </div>
180
- </div>
181
- </form>
182
- </div>
183
- </div>
184
- <?php
185
- }
186
-
187
- usb_admin_page();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
widget_options.php CHANGED
@@ -1,18 +1,17 @@
1
  <?php
2
 
3
- class MySettingsPage {
4
  public $options;
5
  public $settings_page_name = 'uptolike_settings';
6
 
7
  public function __construct() {
8
- add_action('admin_menu', array($this, 'add_plugin_page'));
9
- add_action('admin_init', array($this, 'page_init'));
10
- $this->options = get_option('my_option_name');
11
  }
12
 
13
- public function add_plugin_page() {
14
- add_options_page('Settings Admin', 'UpToLike', 'manage_options', $this->settings_page_name, //'my-setting-admin',
15
- array($this, 'create_admin_page'));
16
  }
17
 
18
  /** creates url of iframe with statistics page from given params
@@ -22,9 +21,9 @@ class MySettingsPage {
22
  * @param $mail
23
  * @param $cryptKey
24
  *
25
- * @return stringшfr
26
  */
27
- public function statIframe($projectId, $partnerId, $mail, $cryptKey) {
28
  $params = array('mail' => $mail, 'partner' => $partnerId, 'projectId' => $projectId,
29
 
30
  );
@@ -45,7 +44,7 @@ class MySettingsPage {
45
  *
46
  * @return string
47
  */
48
- public function constructorIframe($projectId, $partnerId, $mail, $cryptKey) {
49
  $params = array('mail' => $mail, 'partner' => $partnerId, 'projectId' => $projectId);
50
 
51
  $paramsStr = 'mail=' . $mail . '&partner=' . $partnerId . '&projectId=' . $projectId . $cryptKey;
@@ -61,7 +60,7 @@ class MySettingsPage {
61
  *
62
  * @param string $current
63
  */
64
- public function ilc_admin_tabs($current = 'construct') {
65
  $tabs = array('construct' => 'Конструктор', 'stat' => 'Статистика', 'settings' => 'Настройки');
66
 
67
  echo '<div id="icon-themes" class="icon32"><br></div>';
@@ -75,8 +74,8 @@ class MySettingsPage {
75
 
76
  /** render html page with code configuration settings
77
  */
78
- public function create_admin_page() {
79
- $this->options = get_option('my_option_name');
80
  if ((isset($this->options['uptolike_email'])) && ('' !== $this->options['uptolike_email'])) {
81
  $email = $this->options['uptolike_email'];
82
  } else $email = get_option('admin_email');
@@ -84,7 +83,7 @@ class MySettingsPage {
84
  $projectId = 'cms' . preg_replace('/^www\./', '', $_SERVER['HTTP_HOST']);
85
  $projectId = str_replace('.', '', $projectId);
86
  $projectId = str_replace('-', '', $projectId);
87
- $options = get_option('my_option_name');
88
  if (is_array($options) && array_key_exists('id_number', $options)) {
89
  $cryptKey = $options['id_number'];
90
  } else $cryptKey = '';
@@ -116,7 +115,7 @@ class MySettingsPage {
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 $this->constructorIframe($projectId, $partnerId, $email, $cryptKey); ?>"></iframe>
120
  <br>
121
  <a onclick="getCode();" href="#">
122
  <button type="reset">Сохранить изменения</button>
@@ -124,7 +123,7 @@ class MySettingsPage {
124
  </div>
125
  <div class="wrapper-tab" id="con_stat">
126
  <iframe style="width: 100%;height: 380px;" id="stats_iframe"
127
- data-src="<?php echo $this->statIframe($projectId, $partnerId, $email, $cryptKey); ?>">
128
  </iframe>
129
  <div id="before_key_req">Введите ваш адрес электронной почты для получения
130
  ключа.
@@ -184,7 +183,8 @@ class MySettingsPage {
184
  <div class="utl_right_block">
185
  <div class="utl_blok1">
186
  <div class="utl_blok2">
187
- <div class="utl_logo utl_i_logo">
 
188
  </div>
189
  </div>
190
  <div class="utl_innertext">Для вставки шорткода в .php файл шаблона
@@ -197,7 +197,8 @@ class MySettingsPage {
197
  </div>
198
  <div class="utl_blok1">
199
  <div class="utl_blok2">
200
- <div class="utl_logo utl_like_logo">
 
201
  </div>
202
  </div>
203
  <div class="utl_innertext">Данный плагин полностью бесплатен. Мы
@@ -209,7 +210,8 @@ class MySettingsPage {
209
  </div>
210
  <div class="utl_blok1">
211
  <div class="utl_blok2">
212
- <div class="utl_logo utl_mail_logo">
 
213
  </div>
214
  </div>
215
  <div class="utl_innertext"><a
@@ -229,48 +231,37 @@ class MySettingsPage {
229
  <?php
230
  }
231
 
232
- public function page_init() {
233
- register_setting('my_option_group', 'my_option_name', array($this, 'sanitize'));
234
 
235
- add_settings_section('setting_section_id', 'Настройки отображения блока Uptolike', array($this, 'print_section_info'), $this->settings_page_name);
236
 
237
  add_settings_field('widget_code', 'код виджета', // Title
238
- array($this, 'widget_code_callback'), $this->settings_page_name, 'setting_section_id');
239
 
240
- add_settings_field('data_pid', 'Ключ(CryptKey)', array($this, 'id_number_callback'), $this->settings_page_name, 'setting_section_id');
241
 
242
- add_settings_field('email',
243
- 'email для регистрации', array($this, 'uptolike_email_callback'), $this->settings_page_name, 'setting_section_id');
244
 
245
- add_settings_field('on_main',
246
- 'На главной странице ', array($this, 'uptolike_on_main_callback'), $this->settings_page_name, 'setting_section_id');
247
 
248
- add_settings_field('on_page',
249
- 'На статических страницах', array($this, 'uptolike_on_page_callback'), $this->settings_page_name, 'setting_section_id');
250
 
251
- add_settings_field('on_post',
252
- 'На страницах записей', array($this, 'uptolike_on_post_callback'), $this->settings_page_name, 'setting_section_id');
253
 
254
- add_settings_field('on_archive',
255
- 'На страницах архивов', array($this, 'uptolike_on_archive_callback'), $this->settings_page_name, 'setting_section_id');
256
 
257
- add_settings_field('on_special_pages',
258
- 'На спец. страницах <p class="utl_quest"><img class="utl_quest" src="/wp-content/plugins/uptolike-share/images/quest.png"><span class="utl_quest">Отображается только боковая панель на страницах, созданных плагинами (WooCommerce, WP-Shop и т.д.)</span></p>', array($this, 'uptolike_on_special_pages_callback'), $this->settings_page_name, 'setting_section_id');
259
 
260
- add_settings_field('widget_position',
261
- 'Расположение блока', array($this, 'uptolike_widget_position_callback'), $this->settings_page_name, 'setting_section_id');
262
 
263
- add_settings_field('widget_align',
264
- 'Выравнивание блока', array($this, 'uptolike_widget_align_callback'), $this->settings_page_name, 'setting_section_id');
265
 
266
- add_settings_field('widget_mode',
267
- 'Режим работы', array($this, 'uptolike_widget_mode_callback'), $this->settings_page_name, 'setting_section_id');
268
 
269
- add_settings_field('utl_language',
270
- 'Язык', array($this, 'uptolike_utl_language_callback'), $this->settings_page_name, 'setting_section_id');
271
 
272
- add_settings_field('uptolike_json',
273
- 'настройки конструктора', array($this, 'uptolike_json_callback'), $this->settings_page_name, 'setting_section_id');
274
  }
275
 
276
  /**
@@ -278,7 +269,7 @@ class MySettingsPage {
278
  *
279
  * @param array $input Contains all settings fields as array keys
280
  */
281
- public function sanitize($input) {
282
  $new_input = array();
283
  if (isset($input['id_number'])) $new_input['id_number'] = str_replace(' ', '', $input['id_number']);
284
 
@@ -308,7 +299,7 @@ class MySettingsPage {
308
  $new_input['on_archive'] = 1;
309
  } else $new_input['on_archive'] = 0;
310
 
311
- if (isset($input['email'])) $new_input['email'] = $input['email'];
312
 
313
  if (isset($input['after_content'])) $new_input['after_content'] = $input['after_content'];
314
 
@@ -327,62 +318,62 @@ class MySettingsPage {
327
  }
328
 
329
 
330
- public function print_section_info() {
331
  }
332
 
333
- public function widget_code_callback() {
334
- printf('<textarea id="widget_code" name="my_option_name[widget_code]" >%s</textarea>', isset($this->options['widget_code']) ? esc_attr($this->options['widget_code']) : '');
335
  }
336
 
337
  /** 12536473050877
338
  * Get the settings option array and print one of its values
339
  */
340
- public function id_number_callback() {
341
- printf('<input type="text" class="id_number" name="my_option_name[id_number]" value="%s" />', isset($this->options['id_number']) ? esc_attr($this->options['id_number']) : '');
342
  }
343
 
344
  public function uptolike_email_callback() {
345
- printf('<input type="text" id="uptolike_email" name="my_option_name[uptolike_email]" value="%s" />', isset($this->options['uptolike_email']) ? esc_attr($this->options['uptolike_email']) : '');
346
  }
347
 
348
  public function uptolike_json_callback() {
349
- printf('<input type="hidden" id="uptolike_json" name="my_option_name[uptolike_json]" value="%s" />', isset($this->options['uptolike_json']) ? esc_attr($this->options['uptolike_json']) : '');
350
  }
351
 
352
  public function uptolike_partner_id_callback() {
353
- printf('<input type="text" id="uptolike_partner" name="my_option_name[uptolike_partner]" value="%s" />', isset($this->options['uptolike_partner']) ? esc_attr($this->options['uptolike_partner']) : '');
354
  }
355
 
356
  public function uptolike_project_callback() {
357
- printf('<input type="text" id="uptolike_project" name="my_option_name[uptolike_project]" value="%s" />', isset($this->options['uptolike_project']) ? esc_attr($this->options['uptolike_project']) : '');
358
  }
359
 
360
  public function uptolike_on_main_callback() {
361
- echo '<input type="checkbox" id="on_main" name="my_option_name[on_main]"';
362
  echo($this->options['on_main'] == '1' ? 'checked="checked"' : '');
363
  echo '/>';
364
  }
365
 
366
  public function uptolike_on_page_callback() {
367
- echo '<input type="checkbox" id="on_page" name="my_option_name[on_page]"';
368
  echo($this->options['on_page'] == '1' ? 'checked="checked"' : '');
369
  echo '/>';
370
  }
371
 
372
  public function uptolike_on_post_callback() {
373
- echo '<input type="checkbox" id="on_post" name="my_option_name[on_post]"';
374
  echo($this->options['on_post'] == '1' ? 'checked="checked"' : '');
375
  echo '/>';
376
  }
377
 
378
  public function uptolike_on_special_pages_callback() {
379
- echo '<input type="checkbox" id="on_special_pages" name="my_option_name[on_special_pages]"';
380
  echo($this->options['on_special_pages'] == '1' ? 'checked="checked"' : '');
381
  echo '/>';
382
  }
383
 
384
  public function uptolike_on_archive_callback() {
385
- echo '<input type="checkbox" id="on_archive" name="my_option_name[on_archive]"';
386
  echo($this->options['on_archive'] == '1' ? 'checked="checked"' : '');
387
  echo '/>';
388
  }
@@ -399,11 +390,11 @@ class MySettingsPage {
399
  $both_mode = "selected='selected'";
400
  }
401
  } else {
402
- $my_options = get_option('my_option_name');
403
- $my_options['widget_mode'] = 'plg'; // cryptkey store
404
- update_option('my_option_name', $my_options);
405
  }
406
- echo "<select id='widget_mode' name='my_option_name[widget_mode]'>
407
  <option {$plg_mode} value='plg'>Плагин</option>
408
  <option {$code_mode} value='code'>Шорткод</option>
409
  <option {$both_mode} value='both'>Плагин и шорткод</option>
@@ -422,12 +413,12 @@ class MySettingsPage {
422
  $center = "selected='selected'";
423
  }
424
  } else {
425
- $my_options = get_option('my_option_name');
426
- $my_options['widget_align'] = 'left'; // cryptkey store
427
- update_option('my_option_name', $my_options);
428
  }
429
 
430
- echo "<select id='widget_align' name='my_option_name[widget_align]'>
431
  <option {$left} value='left'>По левому краю</option>
432
  <option {$right} value='right'>По правому краю</option>
433
  <option {$center} value='center'>По центру</option>
@@ -448,19 +439,19 @@ class MySettingsPage {
448
  } else {
449
  $both = '';
450
  $bottom = "selected='selected'";
451
- $my_options = get_option('my_option_name');
452
- $my_options['widget_position'] = 'bottom'; // cryptkey store
453
- update_option('my_option_name', $my_options);
454
  }
455
  } else {
456
  $bottom = "selected='selected'";
457
  }
458
  } else {
459
- $my_options = get_option('my_option_name');
460
- $my_options['widget_position'] = 'bottom'; // cryptkey store
461
- update_option('my_option_name', $my_options);
462
  }
463
- echo "<select id='widget_position' name='my_option_name[widget_position]'>
464
  <option {$top} value='top'>Только сверху</option>
465
  <option {$bottom} value='bottom'>Только снизу</option>";
466
  if (json_decode($this->options['uptolike_json'])->orientation < 2) {
@@ -470,7 +461,7 @@ class MySettingsPage {
470
 
471
  }
472
 
473
- public function uptolike_utl_language_callback() {
474
  $ru = $en = $ua = $de = $es = $it = $pl = $lt = '';
475
  if (isset($this->options['utl_language'])) {
476
  if ($this->options['utl_language'] == 'ru') {
@@ -493,11 +484,11 @@ class MySettingsPage {
493
  $ru = "selected='selected'";
494
  }
495
  } else {
496
- $my_options = get_option('my_option_name');
497
- $my_options['utl_language'] = 'ru'; // cryptkey store
498
- update_option('my_option_name', $my_options);
499
  }
500
- echo "<select id='widget_position' name='my_option_name[utl_language]'>
501
  <option {$ru} value='ru'>Русский</option>
502
  <option {$en} value='en'>Английский</option>
503
  <option {$ua} value='ua'>Украинский</option>
@@ -510,22 +501,15 @@ class MySettingsPage {
510
  }
511
  }
512
 
513
- function get_widget_code($url = '') {
514
- $options = get_option('my_option_name');
515
  $widget_code = $options['widget_code'];
516
  $protocol = strtolower(substr($_SERVER["SERVER_PROTOCOL"], 0, strpos($_SERVER["SERVER_PROTOCOL"], '/'))) . '://';
517
  if ($url == '') {
518
  if (is_single() || is_page()) {
519
- if(json_decode($options['uptolike_json'])->orientation != 2) {
520
- $url = get_permalink();
521
- } else {
522
- if ($options['widget_mode'] == 'plg') {
523
- $url = the_permalink();
524
- } else {
525
- $url = get_permalink();
526
- }
527
- }
528
- } else $url = $protocol . $_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"];
529
  }
530
 
531
  if ($_SERVER["REQUEST_URI"] == '/' && !(json_decode($options['uptolike_json'])->orientation < 2) && !empty(json_decode($options['uptolike_json'])->orientation)) {
@@ -546,8 +530,8 @@ function get_widget_code($url = '') {
546
  return $widget_code;
547
  }
548
 
549
- function add_widget($content) {
550
- $options = get_option('my_option_name');
551
  $widget_mode = $options['widget_mode'];
552
  if (is_array($options) && (($widget_mode == 'plg') or ($widget_mode == 'both')) && array_key_exists('widget_code', $options)) {
553
  if ((!empty(json_decode($options['uptolike_json'])->orientation) && json_decode($options['uptolike_json'])->orientation < 2) || !(isset(json_decode($options['uptolike_json'])->orientation))) {
@@ -555,59 +539,70 @@ function add_widget($content) {
555
  if ($options['on_main'] == 1 && (home_url('/') == request_home_url())) {
556
  switch ($options['widget_position']) {
557
  case 'both':
558
- return get_widget_code(get_permalink()) . $content . get_widget_code(get_permalink());
559
  case 'top':
560
- return get_widget_code(get_permalink()) . $content;
561
  case 'bottom':
562
- return $content . get_widget_code(get_permalink());
563
  }
564
  } elseif ($options['on_main'] != 1 && (home_url('/') == request_home_url())) {
565
  return $content;
 
 
 
 
 
 
 
 
 
566
  }
567
  } elseif (is_page() && $options['on_page'] == 1 && (home_url('/') != request_home_url())) {
568
  switch ($options['widget_position']) {
569
  case 'both':
570
- return get_widget_code(get_permalink()) . $content . get_widget_code(get_permalink());
571
  case 'top':
572
- return get_widget_code(get_permalink()) . $content;
573
  case 'bottom':
574
- return $content . get_widget_code(get_permalink());
575
  }
576
  } elseif (is_single() && $options['on_post'] == 1 && (home_url('/') != request_home_url())) {
577
  switch ($options['widget_position']) {
578
  case 'both':
579
- return get_widget_code(get_permalink()) . $content . get_widget_code(get_permalink());
580
  case 'top':
581
- return get_widget_code(get_permalink()) . $content;
582
  case 'bottom':
583
- return $content . get_widget_code(get_permalink());
584
  }
585
  } elseif (is_archive() && $options['on_archive'] == 1 && $options['on_post'] == 1) {
586
  switch ($options['widget_position']) {
587
  case 'both':
588
- return get_widget_code(get_permalink()) . $content . get_widget_code(get_permalink());
589
  case 'top':
590
- return get_widget_code(get_permalink()) . $content;
591
  case 'bottom':
592
- return $content . get_widget_code(get_permalink());
593
  }
594
  }
595
  } else { //if vertical panel
596
  if (is_front_page() || is_home()) {
597
  if ($options['on_main'] == 1 && (home_url('/') == request_home_url())) {
598
- add_action('wp_footer', 'headeruptolike');
 
 
599
  }
600
  } elseif (is_page()) {
601
  if ($options['on_page'] == 1 && (home_url('/') != request_home_url())) {
602
- add_action('wp_footer', 'headeruptolike');
603
  }
604
  } elseif (is_single()) {
605
  if ($options['on_post'] == 1 && (home_url('/') != request_home_url())) {
606
- add_action('wp_footer', 'headeruptolike');
607
  }
608
  } elseif (is_archive()) {
609
  if ($options['on_archive'] == 1 && $options['on_post'] == 1 && (home_url('/') != request_home_url())) {
610
- add_action('wp_footer', 'headeruptolike');
611
  }
612
  }
613
  }
@@ -615,21 +610,35 @@ function add_widget($content) {
615
  return $content;
616
  }
617
 
618
- add_filter('the_content', 'add_widget', 100);
619
 
620
  function uptolike_shortcode() {
621
- $options = get_option('my_option_name');
622
  $widget_mode = $options['widget_mode'];
623
  if (($widget_mode == 'code') or ($widget_mode == 'both')) {
624
- return get_widget_code();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
625
  }
626
  return;
627
  }
628
 
629
  add_shortcode('uptolike', 'uptolike_shortcode');
630
 
631
- function my_widgetcode_notice() {
632
- $options = get_option('my_option_name');
633
  if (is_array($options) && array_key_exists('widget_code', $options)) {
634
  $widget_code = $options['widget_code'];
635
  if ($widget_code == '') {
@@ -640,26 +649,46 @@ function my_widgetcode_notice() {
640
  };
641
  }
642
 
643
- function try_reg() {
644
- include('api_functions.php');
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
645
  $domain = preg_replace('/^www\./', '', $_SERVER['HTTP_HOST']);
646
- $options = get_option('my_option_name');
647
  $email = $options['uptolike_email'];
648
- if ('' == $options['id_number']) {
649
- $reg_ans = userReg($email, 'cms', 'cms' . $domain);
650
  if (is_string($reg_ans)) {
651
- $my_options = get_option('my_option_name');
652
- $my_options['id_number'] = $reg_ans; // cryptkey store
653
- $my_options['choice'] = 'reg';
654
- update_option('my_option_name', $my_options);
655
  };
656
  update_option('regme', true);
657
  }
658
  }
659
 
660
- function my_choice_notice() {
661
- $options = get_option('my_option_name');
662
- if (is_bool($options) or (('' == $options['id_number']) and ((!array_key_exists('choice', $options)) OR ('ignore' !== $options['choice'])))) {
663
  echo "<div class='updated' style='
664
  background: #fff url(//uptolike.com/img/logo.png) no-repeat 2px;
665
  padding-left: 50px;
@@ -668,8 +697,8 @@ function my_choice_notice() {
668
  };
669
  }
670
 
671
- function set_default_code() {
672
- $options = get_option('my_option_name');
673
  if (is_bool($options)) {
674
  $options = array();
675
  }
@@ -704,28 +733,35 @@ EOD;
704
  $options['widget_mode'] = 'plg';
705
  $options['widget_align'] = 'left';
706
  $options['utl_language'] = 'ru';
707
- update_option('my_option_name', $options);
708
  }
709
 
710
- function choice_helper($choice) {
711
- $options = get_option('my_option_name');
712
  $options['choice'] = $choice;
713
- if ('ignore' == $choice) {
714
- set_default_code();
715
  }
716
- update_option('my_option_name', $options);
717
  }
718
 
719
- function usb_admin_actions() {
720
  if (current_user_can('manage_options')) {
721
  if (function_exists('add_meta_box')) {
722
- add_menu_page("UpToLike", "UpToLike", "manage_options", "UpToLike", 'my_custom_menu_page', plugins_url('uptolike-share/images/logo-small.png'));
723
  }
724
  }
725
  }
726
 
727
- function my_custom_menu_page() {
728
- include_once('usb-admin.php');
 
 
 
 
 
 
 
729
  }
730
 
731
  function request_home_url($url = '') {
@@ -748,31 +784,41 @@ function request_home_url($url = '') {
748
  return $result;
749
  }
750
 
751
- function headeruptolike() {
752
- $options = get_option('my_option_name');
753
  if ((home_url('/') == request_home_url()) && $options['on_main'] == 1) {
754
  $in_content = array(0, 1);
755
  $in_fixed_block = array(2, 3, 4, 5);
756
  $curr_value = json_decode($options['uptolike_json'])->orientation;
757
  if (in_array($curr_value, $in_content)) {
758
  } elseif (in_array($curr_value, $in_fixed_block)) {
759
- echo get_widget_code();
760
  }
761
  } elseif ((home_url('/') != request_home_url()) && ($options['on_special_pages'] == 1 || $options['on_page'] == 1)) {
762
  $in_content = array(0, 1);
763
  $in_fixed_block = array(2, 3, 4, 5);
764
  $curr_value = json_decode($options['uptolike_json'])->orientation;
765
  if (in_array($curr_value, $in_content)) {
 
 
 
 
 
 
 
 
 
 
766
  } elseif (in_array($curr_value, $in_fixed_block)) {
767
- echo get_widget_code();
768
  }
769
  }
770
  }
771
 
772
- class UptolikeWidget extends WP_Widget {
773
 
774
- function UptolikeWidget() {
775
- parent::__construct(false, 'Блок кнопок UpToLike');
776
  }
777
 
778
  function widget($args, $instance) {
@@ -786,26 +832,26 @@ class UptolikeWidget extends WP_Widget {
786
  }
787
 
788
  function uptolike_register_widgets() {
789
- register_widget('UptolikeWidget');
790
  }
791
 
792
- register_activation_hook(__FILE__, 'usb_admin_actions');
793
 
794
  add_action('widgets_init', 'uptolike_register_widgets');
795
- add_action('admin_notices', 'my_choice_notice');
796
- add_action('admin_notices', 'my_widgetcode_notice');
797
- add_action('admin_menu', 'usb_admin_actions');
798
 
799
  if (is_admin()) {
800
- $options = get_option('my_option_name');
801
  if (array_key_exists('regme', $_REQUEST)) {
802
- try_reg();
803
  }
804
  if (array_key_exists('choice', $_REQUEST)) {
805
- choice_helper($_REQUEST['choice']);
806
  }
807
- $my_settings_page = new MySettingsPage();
808
  if (is_bool($options) OR (!array_key_exists('widget_code', $options)) OR ($options['widget_code'] == '')) {
809
- set_default_code();
810
  }
811
  }
1
  <?php
2
 
3
+ class UptolikeSettingsPage {
4
  public $options;
5
  public $settings_page_name = 'uptolike_settings';
6
 
7
  public function __construct() {
8
+ add_action('admin_menu', array($this, 'uptolike_add_plugin_page'));
9
+ add_action('admin_init', array($this, 'uptolike_page_init'));
10
+ $this->options = get_option('uptolike_options');
11
  }
12
 
13
+ public function uptolike_add_plugin_page() {
14
+ add_options_page('UpToLike Settings', 'UpToLike', 'manage_options', $this->settings_page_name, array($this, 'uptolike_create_admin_page'));
 
15
  }
16
 
17
  /** creates url of iframe with statistics page from given params
21
  * @param $mail
22
  * @param $cryptKey
23
  *
24
+ * @return string
25
  */
26
+ public function uptolike_statIframe($projectId, $partnerId, $mail, $cryptKey) {
27
  $params = array('mail' => $mail, 'partner' => $partnerId, 'projectId' => $projectId,
28
 
29
  );
44
  *
45
  * @return string
46
  */
47
+ public function uptolike_constructorIframe($projectId, $partnerId, $mail, $cryptKey) {
48
  $params = array('mail' => $mail, 'partner' => $partnerId, 'projectId' => $projectId);
49
 
50
  $paramsStr = 'mail=' . $mail . '&partner=' . $partnerId . '&projectId=' . $projectId . $cryptKey;
60
  *
61
  * @param string $current
62
  */
63
+ public function uptolike_admin_tabs($current = 'construct') {
64
  $tabs = array('construct' => 'Конструктор', 'stat' => 'Статистика', 'settings' => 'Настройки');
65
 
66
  echo '<div id="icon-themes" class="icon32"><br></div>';
74
 
75
  /** render html page with code configuration settings
76
  */
77
+ public function uptolike_create_admin_page() {
78
+ $this->options = get_option('uptolike_options');
79
  if ((isset($this->options['uptolike_email'])) && ('' !== $this->options['uptolike_email'])) {
80
  $email = $this->options['uptolike_email'];
81
  } else $email = get_option('admin_email');
83
  $projectId = 'cms' . preg_replace('/^www\./', '', $_SERVER['HTTP_HOST']);
84
  $projectId = str_replace('.', '', $projectId);
85
  $projectId = str_replace('-', '', $projectId);
86
+ $options = get_option('uptolike_options');
87
  if (is_array($options) && array_key_exists('id_number', $options)) {
88
  $cryptKey = $options['id_number'];
89
  } else $cryptKey = '';
115
 
116
  <div class="wrapper-tab active" id="con_construct">
117
  <iframe id='cons_iframe' style='height: 445px;width: 100%;'
118
+ data-src="<?php echo $this->uptolike_constructorIframe($projectId, $partnerId, $email, $cryptKey); ?>"></iframe>
119
  <br>
120
  <a onclick="getCode();" href="#">
121
  <button type="reset">Сохранить изменения</button>
123
  </div>
124
  <div class="wrapper-tab" id="con_stat">
125
  <iframe style="width: 100%;height: 380px;" id="stats_iframe"
126
+ data-src="<?php echo $this->uptolike_statIframe($projectId, $partnerId, $email, $cryptKey); ?>">
127
  </iframe>
128
  <div id="before_key_req">Введите ваш адрес электронной почты для получения
129
  ключа.
183
  <div class="utl_right_block">
184
  <div class="utl_blok1">
185
  <div class="utl_blok2">
186
+ <div class="utl_logo utl_i_logo"
187
+ style="background-image: url('<?php echo plugin_dir_url(__FILE__); ?>/images/plg_icons.png')">
188
  </div>
189
  </div>
190
  <div class="utl_innertext">Для вставки шорткода в .php файл шаблона
197
  </div>
198
  <div class="utl_blok1">
199
  <div class="utl_blok2">
200
+ <div class="utl_logo utl_like_logo"
201
+ style="background-image: url('<?php echo plugin_dir_url(__FILE__); ?>/images/plg_icons.png')">
202
  </div>
203
  </div>
204
  <div class="utl_innertext">Данный плагин полностью бесплатен. Мы
210
  </div>
211
  <div class="utl_blok1">
212
  <div class="utl_blok2">
213
+ <div class="utl_logo utl_mail_logo"
214
+ style="background-image: url('<?php echo plugin_dir_url(__FILE__); ?>/images/plg_icons.png')">
215
  </div>
216
  </div>
217
  <div class="utl_innertext"><a
231
  <?php
232
  }
233
 
234
+ public function uptolike_page_init() {
235
+ register_setting('my_option_group', 'uptolike_options', array($this, 'uptolike_sanitize'));
236
 
237
+ add_settings_section('setting_section_id', 'Настройки отображения блока Uptolike', array($this, 'uptolike_print_section_info'), $this->settings_page_name);
238
 
239
  add_settings_field('widget_code', 'код виджета', // Title
240
+ array($this, 'uptolike_widget_code_callback'), $this->settings_page_name, 'setting_section_id');
241
 
242
+ add_settings_field('data_pid', 'Ключ(CryptKey)', array($this, 'uptolike_id_number_callback'), $this->settings_page_name, 'setting_section_id');
243
 
244
+ add_settings_field('email', 'email для регистрации', array($this, 'uptolike_email_callback'), $this->settings_page_name, 'setting_section_id');
 
245
 
246
+ add_settings_field('on_main', 'На главной странице ', array($this, 'uptolike_on_main_callback'), $this->settings_page_name, 'setting_section_id');
 
247
 
248
+ add_settings_field('on_page', 'На статических страницах', array($this, 'uptolike_on_page_callback'), $this->settings_page_name, 'setting_section_id');
 
249
 
250
+ add_settings_field('on_post', 'На страницах записей', array($this, 'uptolike_on_post_callback'), $this->settings_page_name, 'setting_section_id');
 
251
 
252
+ add_settings_field('on_archive', 'На страницах архивов', array($this, 'uptolike_on_archive_callback'), $this->settings_page_name, 'setting_section_id');
 
253
 
254
+ add_settings_field('on_special_pages', 'На спец. страницах <p class="utl_quest"><img class="utl_quest" src="' . plugin_dir_url(__FILE__) . '/images/quest.png"><span class="utl_quest">Отображается только боковая панель на страницах, созданных плагинами (WooCommerce, WP-Shop и т.д.)</span></p>', array($this, 'uptolike_on_special_pages_callback'), $this->settings_page_name, 'setting_section_id');
 
255
 
256
+ add_settings_field('widget_position', 'Расположение блока', array($this, 'uptolike_widget_position_callback'), $this->settings_page_name, 'setting_section_id');
 
257
 
258
+ add_settings_field('widget_align', 'Выравнивание блока', array($this, 'uptolike_widget_align_callback'), $this->settings_page_name, 'setting_section_id');
 
259
 
260
+ add_settings_field('widget_mode', 'Режим работы', array($this, 'uptolike_widget_mode_callback'), $this->settings_page_name, 'setting_section_id');
 
261
 
262
+ add_settings_field('utl_language', 'Язык', array($this, 'uptolike_language_callback'), $this->settings_page_name, 'setting_section_id');
 
263
 
264
+ add_settings_field('uptolike_json', 'настройки конструктора', array($this, 'uptolike_json_callback'), $this->settings_page_name, 'setting_section_id');
 
265
  }
266
 
267
  /**
269
  *
270
  * @param array $input Contains all settings fields as array keys
271
  */
272
+ public function uptolike_sanitize($input) {
273
  $new_input = array();
274
  if (isset($input['id_number'])) $new_input['id_number'] = str_replace(' ', '', $input['id_number']);
275
 
299
  $new_input['on_archive'] = 1;
300
  } else $new_input['on_archive'] = 0;
301
 
302
+ if (isset($input['email'])) $new_input['email'] = trim($input['email']);
303
 
304
  if (isset($input['after_content'])) $new_input['after_content'] = $input['after_content'];
305
 
318
  }
319
 
320
 
321
+ public function uptolike_print_section_info() {
322
  }
323
 
324
+ public function uptolike_widget_code_callback() {
325
+ printf('<textarea id="widget_code" name="uptolike_options[widget_code]" >%s</textarea>', isset($this->options['widget_code']) ? esc_attr($this->options['widget_code']) : '');
326
  }
327
 
328
  /** 12536473050877
329
  * Get the settings option array and print one of its values
330
  */
331
+ public function uptolike_id_number_callback() {
332
+ printf('<input type="text" class="id_number" name="uptolike_options[id_number]" value="%s" />', isset($this->options['id_number']) ? esc_attr($this->options['id_number']) : '');
333
  }
334
 
335
  public function uptolike_email_callback() {
336
+ printf('<input type="text" id="uptolike_email" name="uptolike_options[uptolike_email]" value="%s" />', isset($this->options['uptolike_email']) ? esc_attr(trim($this->options['uptolike_email'])) : '');
337
  }
338
 
339
  public function uptolike_json_callback() {
340
+ printf('<input type="hidden" id="uptolike_json" name="uptolike_options[uptolike_json]" value="%s" />', isset($this->options['uptolike_json']) ? esc_attr($this->options['uptolike_json']) : '');
341
  }
342
 
343
  public function uptolike_partner_id_callback() {
344
+ printf('<input type="text" id="uptolike_partner" name="uptolike_options[uptolike_partner]" value="%s" />', isset($this->options['uptolike_partner']) ? esc_attr($this->options['uptolike_partner']) : '');
345
  }
346
 
347
  public function uptolike_project_callback() {
348
+ printf('<input type="text" id="uptolike_project" name="uptolike_options[uptolike_project]" value="%s" />', isset($this->options['uptolike_project']) ? esc_attr($this->options['uptolike_project']) : '');
349
  }
350
 
351
  public function uptolike_on_main_callback() {
352
+ echo '<input type="checkbox" id="on_main" name="uptolike_options[on_main]"';
353
  echo($this->options['on_main'] == '1' ? 'checked="checked"' : '');
354
  echo '/>';
355
  }
356
 
357
  public function uptolike_on_page_callback() {
358
+ echo '<input type="checkbox" id="on_page" name="uptolike_options[on_page]"';
359
  echo($this->options['on_page'] == '1' ? 'checked="checked"' : '');
360
  echo '/>';
361
  }
362
 
363
  public function uptolike_on_post_callback() {
364
+ echo '<input type="checkbox" id="on_post" name="uptolike_options[on_post]"';
365
  echo($this->options['on_post'] == '1' ? 'checked="checked"' : '');
366
  echo '/>';
367
  }
368
 
369
  public function uptolike_on_special_pages_callback() {
370
+ echo '<input type="checkbox" id="on_special_pages" name="uptolike_options[on_special_pages]"';
371
  echo($this->options['on_special_pages'] == '1' ? 'checked="checked"' : '');
372
  echo '/>';
373
  }
374
 
375
  public function uptolike_on_archive_callback() {
376
+ echo '<input type="checkbox" id="on_archive" name="uptolike_options[on_archive]"';
377
  echo($this->options['on_archive'] == '1' ? 'checked="checked"' : '');
378
  echo '/>';
379
  }
390
  $both_mode = "selected='selected'";
391
  }
392
  } else {
393
+ $uptolike_options = get_option('uptolike_options');
394
+ $uptolike_options['widget_mode'] = 'plg'; // cryptkey store
395
+ update_option('uptolike_options', $uptolike_options);
396
  }
397
+ echo "<select id='widget_mode' name='uptolike_options[widget_mode]'>
398
  <option {$plg_mode} value='plg'>Плагин</option>
399
  <option {$code_mode} value='code'>Шорткод</option>
400
  <option {$both_mode} value='both'>Плагин и шорткод</option>
413
  $center = "selected='selected'";
414
  }
415
  } else {
416
+ $uptolike_options = get_option('uptolike_options');
417
+ $uptolike_options['widget_align'] = 'left'; // cryptkey store
418
+ update_option('uptolike_options', $uptolike_options);
419
  }
420
 
421
+ echo "<select id='widget_align' name='uptolike_options[widget_align]'>
422
  <option {$left} value='left'>По левому краю</option>
423
  <option {$right} value='right'>По правому краю</option>
424
  <option {$center} value='center'>По центру</option>
439
  } else {
440
  $both = '';
441
  $bottom = "selected='selected'";
442
+ $uptolike_options = get_option('uptolike_options');
443
+ $uptolike_options['widget_position'] = 'bottom'; // cryptkey store
444
+ update_option('uptolike_options', $uptolike_options);
445
  }
446
  } else {
447
  $bottom = "selected='selected'";
448
  }
449
  } else {
450
+ $uptolike_options = get_option('uptolike_options');
451
+ $uptolike_options['widget_position'] = 'bottom'; // cryptkey store
452
+ update_option('uptolike_options', $uptolike_options);
453
  }
454
+ echo "<select id='widget_position' name='uptolike_options[widget_position]'>
455
  <option {$top} value='top'>Только сверху</option>
456
  <option {$bottom} value='bottom'>Только снизу</option>";
457
  if (json_decode($this->options['uptolike_json'])->orientation < 2) {
461
 
462
  }
463
 
464
+ public function uptolike_language_callback() {
465
  $ru = $en = $ua = $de = $es = $it = $pl = $lt = '';
466
  if (isset($this->options['utl_language'])) {
467
  if ($this->options['utl_language'] == 'ru') {
484
  $ru = "selected='selected'";
485
  }
486
  } else {
487
+ $uptolike_options = get_option('uptolike_options');
488
+ $uptolike_options['utl_language'] = 'ru'; // cryptkey store
489
+ update_option('uptolike_options', $uptolike_options);
490
  }
491
+ echo "<select id='widget_position' name='uptolike_options[utl_language]'>
492
  <option {$ru} value='ru'>Русский</option>
493
  <option {$en} value='en'>Английский</option>
494
  <option {$ua} value='ua'>Украинский</option>
501
  }
502
  }
503
 
504
+ function uptolike_get_widget_code($url = '') {
505
+ $options = get_option('uptolike_options');
506
  $widget_code = $options['widget_code'];
507
  $protocol = strtolower(substr($_SERVER["SERVER_PROTOCOL"], 0, strpos($_SERVER["SERVER_PROTOCOL"], '/'))) . '://';
508
  if ($url == '') {
509
  if (is_single() || is_page()) {
510
+ $url = get_permalink();
511
+ } else
512
+ $url = $protocol . $_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"];
 
 
 
 
 
 
 
513
  }
514
 
515
  if ($_SERVER["REQUEST_URI"] == '/' && !(json_decode($options['uptolike_json'])->orientation < 2) && !empty(json_decode($options['uptolike_json'])->orientation)) {
530
  return $widget_code;
531
  }
532
 
533
+ function uptolike_add_widget($content) {
534
+ $options = get_option('uptolike_options');
535
  $widget_mode = $options['widget_mode'];
536
  if (is_array($options) && (($widget_mode == 'plg') or ($widget_mode == 'both')) && array_key_exists('widget_code', $options)) {
537
  if ((!empty(json_decode($options['uptolike_json'])->orientation) && json_decode($options['uptolike_json'])->orientation < 2) || !(isset(json_decode($options['uptolike_json'])->orientation))) {
539
  if ($options['on_main'] == 1 && (home_url('/') == request_home_url())) {
540
  switch ($options['widget_position']) {
541
  case 'both':
542
+ return uptolike_get_widget_code(get_permalink()) . $content . uptolike_get_widget_code(get_permalink());
543
  case 'top':
544
+ return uptolike_get_widget_code(get_permalink()) . $content;
545
  case 'bottom':
546
+ return $content . uptolike_get_widget_code(get_permalink());
547
  }
548
  } elseif ($options['on_main'] != 1 && (home_url('/') == request_home_url())) {
549
  return $content;
550
+ } elseif ($options['on_page'] == 1 && home_url('/') != request_home_url()) {
551
+ switch ($options['widget_position']) {
552
+ case 'both':
553
+ return uptolike_get_widget_code(get_permalink()) . $content . uptolike_get_widget_code(get_permalink());
554
+ case 'top':
555
+ return uptolike_get_widget_code(get_permalink()) . $content;
556
+ case 'bottom':
557
+ return $content . uptolike_get_widget_code(get_permalink());
558
+ }
559
  }
560
  } elseif (is_page() && $options['on_page'] == 1 && (home_url('/') != request_home_url())) {
561
  switch ($options['widget_position']) {
562
  case 'both':
563
+ return uptolike_get_widget_code(get_permalink()) . $content . uptolike_get_widget_code(get_permalink());
564
  case 'top':
565
+ return uptolike_get_widget_code(get_permalink()) . $content;
566
  case 'bottom':
567
+ return $content . uptolike_get_widget_code(get_permalink());
568
  }
569
  } elseif (is_single() && $options['on_post'] == 1 && (home_url('/') != request_home_url())) {
570
  switch ($options['widget_position']) {
571
  case 'both':
572
+ return uptolike_get_widget_code(get_permalink()) . $content . uptolike_get_widget_code(get_permalink());
573
  case 'top':
574
+ return uptolike_get_widget_code(get_permalink()) . $content;
575
  case 'bottom':
576
+ return $content . uptolike_get_widget_code(get_permalink());
577
  }
578
  } elseif (is_archive() && $options['on_archive'] == 1 && $options['on_post'] == 1) {
579
  switch ($options['widget_position']) {
580
  case 'both':
581
+ return uptolike_get_widget_code(get_permalink()) . $content . uptolike_get_widget_code(get_permalink());
582
  case 'top':
583
+ return uptolike_get_widget_code(get_permalink()) . $content;
584
  case 'bottom':
585
+ return $content . uptolike_get_widget_code(get_permalink());
586
  }
587
  }
588
  } else { //if vertical panel
589
  if (is_front_page() || is_home()) {
590
  if ($options['on_main'] == 1 && (home_url('/') == request_home_url())) {
591
+ add_action('wp_footer', 'uptolike_header');
592
+ } elseif ($options['on_page'] == 1 && home_url('/') != request_home_url()) {
593
+ add_action('wp_footer', 'uptolike_header');
594
  }
595
  } elseif (is_page()) {
596
  if ($options['on_page'] == 1 && (home_url('/') != request_home_url())) {
597
+ add_action('wp_footer', 'uptolike_header');
598
  }
599
  } elseif (is_single()) {
600
  if ($options['on_post'] == 1 && (home_url('/') != request_home_url())) {
601
+ add_action('wp_footer', 'uptolike_header');
602
  }
603
  } elseif (is_archive()) {
604
  if ($options['on_archive'] == 1 && $options['on_post'] == 1 && (home_url('/') != request_home_url())) {
605
+ add_action('wp_footer', 'uptolike_header');
606
  }
607
  }
608
  }
610
  return $content;
611
  }
612
 
613
+ add_filter('the_content', 'uptolike_add_widget', 100);
614
 
615
  function uptolike_shortcode() {
616
+ $options = get_option('uptolike_options');
617
  $widget_mode = $options['widget_mode'];
618
  if (($widget_mode == 'code') or ($widget_mode == 'both')) {
619
+ if (is_front_page() || is_home()) {
620
+ if ($options['on_main'] == 1 && (home_url('/') == request_home_url())) {
621
+ return uptolike_get_widget_code();
622
+ } elseif ($options['on_main'] != 1 && (home_url('/') == request_home_url())) {
623
+ return;
624
+ } elseif ($options['on_page'] == 1 && home_url('/') != request_home_url()) {
625
+ return uptolike_get_widget_code();
626
+ }
627
+ } elseif (is_page() && $options['on_page'] == 1 && (home_url('/') != request_home_url())) {
628
+ return uptolike_get_widget_code();
629
+ } elseif (is_single() && $options['on_post'] == 1 && (home_url('/') != request_home_url())) {
630
+ return uptolike_get_widget_code();
631
+ } elseif (is_archive() && $options['on_archive'] == 1 && $options['on_post'] == 1) {
632
+ return uptolike_get_widget_code();
633
+ }
634
  }
635
  return;
636
  }
637
 
638
  add_shortcode('uptolike', 'uptolike_shortcode');
639
 
640
+ function uptolike_widgetcode_notice() {
641
+ $options = get_option('uptolike_options');
642
  if (is_array($options) && array_key_exists('widget_code', $options)) {
643
  $widget_code = $options['widget_code'];
644
  if ($widget_code == '') {
649
  };
650
  }
651
 
652
+ /**
653
+ * @param $email
654
+ * @param $partnerId 'cms' for cms modules
655
+ * @param $projectId 'cms'.site name
656
+ *
657
+ * @return bool|string 'if false - somthing wrong, if string - it's cryptkey'
658
+ */
659
+ function uptolike_user_reg($email, $partnerId, $projectId) {
660
+
661
+ if ($email !== '' && $partnerId !== '' && $projectId !== '') {
662
+ $url = 'https://uptolike.com/api/getCryptKeyWithUserReg.json?' . http_build_query(array('email' => $email, 'partner' => $partnerId, 'projectId' => $projectId));
663
+
664
+ $jsonAnswer = file_get_contents($url);
665
+ if (false !== $jsonAnswer) {
666
+ $answer = json_decode($jsonAnswer);
667
+ return $answer->cryptKey;
668
+ } else return $jsonAnswer;
669
+
670
+ } else return 'one of params is empty';
671
+ }
672
+
673
+ function uptolike_try_reg() {
674
  $domain = preg_replace('/^www\./', '', $_SERVER['HTTP_HOST']);
675
+ $options = get_option('uptolike_options');
676
  $email = $options['uptolike_email'];
677
+ if ($options['id_number'] == '') {
678
+ $reg_ans = uptolike_user_reg($email, 'cms', 'cms' . $domain);
679
  if (is_string($reg_ans)) {
680
+ $uptolike_options = get_option('uptolike_options');
681
+ $uptolike_options['id_number'] = $reg_ans; // cryptkey store
682
+ $uptolike_options['choice'] = 'reg';
683
+ update_option('uptolike_options', $uptolike_options);
684
  };
685
  update_option('regme', true);
686
  }
687
  }
688
 
689
+ function uptolike_choice_notice() {
690
+ $options = get_option('uptolike_options');
691
+ if (is_bool($options) or ((!isset($options['id_number']) || $options['id_number'] == '') and ((!array_key_exists('choice', $options)) OR ($options['choice'] !== 'ignore')))) {
692
  echo "<div class='updated' style='
693
  background: #fff url(//uptolike.com/img/logo.png) no-repeat 2px;
694
  padding-left: 50px;
697
  };
698
  }
699
 
700
+ function uptolike_set_default_code() {
701
+ $options = get_option('uptolike_options');
702
  if (is_bool($options)) {
703
  $options = array();
704
  }
733
  $options['widget_mode'] = 'plg';
734
  $options['widget_align'] = 'left';
735
  $options['utl_language'] = 'ru';
736
+ update_option('uptolike_options', $options);
737
  }
738
 
739
+ function uptolike_choice_helper($choice) {
740
+ $options = get_option('uptolike_options');
741
  $options['choice'] = $choice;
742
+ if ($choice == 'ignore') {
743
+ uptolike_set_default_code();
744
  }
745
+ update_option('uptolike_options', $options);
746
  }
747
 
748
+ function uptolike_admin_actions() {
749
  if (current_user_can('manage_options')) {
750
  if (function_exists('add_meta_box')) {
751
+ add_menu_page("UpToLike Settings", "UpToLike", "manage_options", "uptolike_settings", 'uptolike_custom_menu_page', plugin_dir_url(__FILE__) . '/images/logo-small.png');
752
  }
753
  }
754
  }
755
 
756
+ // функция отвечает за вывод страницы настроек
757
+ function uptolike_custom_menu_page() {
758
+ $uptolike_settings_page = new UptolikeSettingsPage();
759
+ if (!isset($uptolike_settings_page)) {
760
+ wp_die(__('Plugin UpToLike has been installed incorrectly.'));
761
+ }
762
+ if (function_exists('add_plugins_page')) {
763
+ add_plugins_page('UpToLike Settings', 'UpToLike', 'manage_options', basename(__FILE__), array(&$uptolike_settings_page, 'uptolike_create_admin_page'));
764
+ }
765
  }
766
 
767
  function request_home_url($url = '') {
784
  return $result;
785
  }
786
 
787
+ function uptolike_header() {
788
+ $options = get_option('uptolike_options');
789
  if ((home_url('/') == request_home_url()) && $options['on_main'] == 1) {
790
  $in_content = array(0, 1);
791
  $in_fixed_block = array(2, 3, 4, 5);
792
  $curr_value = json_decode($options['uptolike_json'])->orientation;
793
  if (in_array($curr_value, $in_content)) {
794
  } elseif (in_array($curr_value, $in_fixed_block)) {
795
+ echo uptolike_get_widget_code();
796
  }
797
  } elseif ((home_url('/') != request_home_url()) && ($options['on_special_pages'] == 1 || $options['on_page'] == 1)) {
798
  $in_content = array(0, 1);
799
  $in_fixed_block = array(2, 3, 4, 5);
800
  $curr_value = json_decode($options['uptolike_json'])->orientation;
801
  if (in_array($curr_value, $in_content)) {
802
+ echo uptolike_get_widget_code();
803
+ } elseif (in_array($curr_value, $in_fixed_block)) {
804
+ echo uptolike_get_widget_code();
805
+ }
806
+ } elseif ((home_url('/') != request_home_url()) && ($options['on_post'] == 1)) {
807
+ $in_content = array(0, 1);
808
+ $in_fixed_block = array(2, 3, 4, 5);
809
+ $curr_value = json_decode($options['uptolike_json'])->orientation;
810
+ if (in_array($curr_value, $in_content)) {
811
+ echo uptolike_get_widget_code();
812
  } elseif (in_array($curr_value, $in_fixed_block)) {
813
+ echo uptolike_get_widget_code();
814
  }
815
  }
816
  }
817
 
818
+ class Uptolike_Widget extends WP_Widget {
819
 
820
+ function __construct() {
821
+ parent::__construct('', 'Блок кнопок UpToLike');
822
  }
823
 
824
  function widget($args, $instance) {
832
  }
833
 
834
  function uptolike_register_widgets() {
835
+ register_widget('Uptolike_Widget');
836
  }
837
 
838
+ register_activation_hook(__FILE__, 'uptolike_admin_actions');
839
 
840
  add_action('widgets_init', 'uptolike_register_widgets');
841
+ add_action('admin_notices', 'uptolike_choice_notice');
842
+ add_action('admin_notices', 'uptolike_widgetcode_notice');
843
+ add_action('admin_menu', 'uptolike_admin_actions');
844
 
845
  if (is_admin()) {
846
+ $options = get_option('uptolike_options');
847
  if (array_key_exists('regme', $_REQUEST)) {
848
+ uptolike_try_reg();
849
  }
850
  if (array_key_exists('choice', $_REQUEST)) {
851
+ uptolike_choice_helper($_REQUEST['choice']);
852
  }
853
+ $uptolike_settings_page = new UptolikeSettingsPage();
854
  if (is_bool($options) OR (!array_key_exists('widget_code', $options)) OR ($options['widget_code'] == '')) {
855
+ uptolike_set_default_code();
856
  }
857
  }