PluginProbe
Goftino / trunk
Goftino vtrunk
trunk 1.7.0
goftino / goftino.php

goftino.php in Goftino trunk, at goftino.php

195 lines 7.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * Plugin Name: Goftino
5 * Author: Ali Rahimi
6 * Plugin URI: https://www.goftino.com
7 * Description: افزونه گفتینو | با کاربران خود آنلاین صحبت کنید ، پشتیبانی کنید و از فروش بیشتر لذت ببرید
8 * Version: 1.8
9 *
10 * Text Domain: goftino
11 * Domain Path: /
12 */
13 if (!defined('ABSPATH')) {
14 die("Error!");
15 }
16
17 load_plugin_textdomain('goftino');
18 define("GOFTINO_IMG_URL", plugin_dir_url(__FILE__) . "/img/");
19 register_activation_hook(__FILE__, 'goftinoInstall');
20 register_uninstall_hook(__FILE__, 'goftinoDelete');
21
22 function menu_goftino() {
23 load_plugin_textdomain('goftino');
24 add_menu_page(__('گفتینو', 'goftino'), __('گفتینو', 'goftino'), 'manage_options', basename(__FILE__), 'goftinoPreferences', GOFTINO_IMG_URL . "logo-m.png");
25 }
26 add_action('admin_menu', 'menu_goftino');
27 function goftino_validate($a) {
28 return $a;
29 }
30 add_action('admin_init', 'goftino_register_settings');
31 function goftino_register_settings() {
32 register_setting('goftino_widget_type', 'goftino_widget_type', 'goftino_validate');
33 register_setting('goftino_send_userdata', 'goftino_send_userdata', 'goftino_validate');
34 register_setting('goftino_widget_id', 'goftino_widget_id', 'goftino_validate');
35 }
36 add_action('admin_post_wp_save_goftino', 'wp_save_goftino');
37 add_action('admin_post_nopriv_wp_save_goftino', 'wp_save_goftino');
38 add_action('wp_footer', 'goftinoAppend', 100000);
39
40 function goftinoInstall() {
41 return goftino::getInstance()->install();
42 }
43 function goftinoDelete() {
44 return goftino::getInstance()->delete();
45 }
46 function goftinoAppend() {
47 echo goftino::getInstance()->append(goftino::getInstance()->getId(),goftino::getInstance()->getData(),goftino::getInstance()->getWidgetType());
48 }
49 function goftinoPreferences() {
50 if (isset($_POST["widget_id"]) || isset($_POST["send_userdata"])) {
51 goftino::getInstance()->save();
52 }
53 load_plugin_textdomain('goftino');
54 echo goftino::getInstance()->render();
55 }
56 function wp_save_goftino() {
57 $goftinoError = null;
58 $wt='default';
59 if (trim($_POST['submit']) !== '' && wp_verify_nonce( $_POST['_wpnonce'], 'goftino_nonce'.get_current_user_id())) {
60 $g_id = trim(sanitize_text_field($_POST['widget_id']));
61 if ($g_id !== '') {
62 if ($_POST['send_userdata'] == 1) {$dt='1';}else{$dt='0';}
63 if ($_POST['widget_type'] == 'fast') {$wt='fast';}elseif($_POST['widget_type'] == 'pagespeed'){$wt='pagespeed';}
64 if (preg_match("/^[0-9a-zA-Z]{6}$/", $g_id)) {
65 if (get_option('goftino_widget_id') !== false) {
66 update_option('goftino_widget_id', $g_id);
67 update_option('goftino_send_userdata', $dt);
68 update_option('goftino_widget_type', $wt);
69 } else {
70 add_option('goftino_widget_id', $g_id, null, 'no');
71 add_option('goftino_send_userdata', $dt, null, 'no');
72 add_option('goftino_widget_type', $wt, null, 'no');
73 }
74 $goftino = goftino::getInstance();
75 $goftino->install();
76 // Clear WP Rocket Cache if needed
77 if (function_exists("rocket_clean_domain")) {
78 rocket_clean_domain();
79 }
80 // Clear WP Super Cache if needed
81 if (function_exists("wp_cache_clean_cache")) {
82 global $file_prefix;
83 wp_cache_clean_cache($file_prefix, true);
84 }
85
86 } else {
87 $goftinoError = "شناسه نا�
88 عتبر است.";
89 }
90 } else {
91 $goftinoError = "شناسه ن�
92 ی تواند خالی باشد.";
93 }
94 set_transient('error_goftino', $goftinoError);
95 }
96 wp_redirect($_SERVER['HTTP_REFERER']);
97 exit();
98 }
99
100 class goftino {
101 protected static $instance;
102
103 private function __construct()
104 {
105 $this->widget_type = get_option('goftino_widget_type');
106 $this->send_userdata = get_option('goftino_send_userdata');
107 $this->widget_id = get_option('goftino_widget_id');
108 }
109
110 private $widget_id = '';
111 private $widget_type = '';
112 private $send_userdata = '';
113
114 public static function getInstance()
115 {
116 if (is_null(self::$instance)) {
117 self::$instance = new goftino();
118 }
119 return self::$instance;
120 }
121 public function install()
122 {
123 if (!$this->widget_id) {
124 if (($out = get_option('goftino_widget_id')) !== false) {
125 $this->widget_id = $out;
126 }
127 }
128 $this->save();
129 }
130 public function delete()
131 {
132 delete_transient('error_goftino');
133 if (get_option('goftino_widget_id') !== false) {
134 delete_option('goftino_widget_id');
135 delete_option('goftino_send_userdata');
136 delete_option('goftino_widget_type');
137 }
138 }
139
140 public function getId()
141 {
142 return $this->widget_id;
143 }
144 public function getData()
145 {
146 return $this->send_userdata;
147 }
148 public function getWidgetType()
149 {
150 return $this->widget_type;
151 }
152 public function render()
153 {
154 $widget_id = $this->widget_id;
155 $send_userdata = $this->send_userdata;
156 $widget_type = $this->widget_type;
157 require_once "setting.php";
158 }
159 public function append($widget_id = false, $send_userdata = 0,$widget_type='default')
160 {
161 if ($widget_id) {
162
163 echo '<script type="text/javascript" data-goftinoplugin="1">';
164 if ($widget_type==='pagespeed') {
165 echo '["keydown","touchmove","touchstart","mouseover"].forEach(function(v){window.addEventListener(v,function(){if(!window.isGoftinoAdded){window.isGoftinoAdded=1;var i="'.$widget_id.'",d=document,g=d.createElement("script"),s="https://www.goftino.com/widget/"+i,l=localStorage.getItem("goftino_"+i);g.type="text/javascript",g.async=!0,g.src=l?s+"?o="+l:s;d.getElementsByTagName("head")[0].appendChild(g);}})});';
166 }elseif ($widget_type==='fast'){
167 echo '!function(){var i="'.$widget_id.'",d=document,g=d.createElement("script"),s="https://www.goftino.com/widget/"+i,l=localStorage.getItem("goftino_"+i);g.type="text/javascript",g.async=!0,g.src=l?s+"?o="+l:s;d.getElementsByTagName("head")[0].appendChild(g);}();';
168 }else{
169 echo '!function(){var a=window,d=document,u="https://www.goftino.com/",h=d.getElementsByTagName("head")[0];function p(q){var k=d.createElement("link");k.href =q,k.rel="preconnect";h.appendChild(k);}p(u);p(u.replace("www","cdn"));function g(){var g=d.createElement("script"),i="'.$widget_id.'",s=u+"widget/"+i,l=localStorage.getItem("goftino_"+i);g.async=!0,g.src=l?s+"?o="+l:s;h.appendChild(g);}"complete"===d.readyState?g():a.attachEvent?a.attachEvent("onload",g):a.addEventListener("load",g,!1);}();';
170 }
171
172 if ($send_userdata > 0 && is_user_logged_in()) {
173 $user = wp_get_current_user();
174 $full_name = trim( $user->first_name .' ' . $user->last_name );
175
176 echo "
177 window.addEventListener('goftino_ready', function () { Goftino.setUser({
178 email: '" . $user->user_email . "',
179 name: '" . esc_js($full_name ? $full_name : $user->display_name) . "'
180 });});
181 ";
182 }
183 echo '</script>';
184 }
185 }
186
187 public function save() {
188 update_option('goftino_widget_id', $this->widget_id);
189 update_option('goftino_send_userdata', $this->send_userdata);
190 update_option('goftino_widget_type', $this->widget_type);
191 }
192
193 }
194
195