Changeset 2889963
- Timestamp:
- 03/30/2023 08:41:07 AM (2 years ago)
- Location:
- native-ads-adnow/trunk
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
native-ads-adnow/trunk/README.txt
r1743357 r2889963 1 === Adnow Plugin===2 Contributors: Adnow 1 === Adnow Native Widget === 2 Contributors: Adnow 3 3 Tags: native ads, ad network, monetization, advertising 4 4 Requires at least: 3.0 5 Tested up to: 4. 86 Stable tag: 1.0. 45 Tested up to: 4.7 6 Stable tag: 1.0.2 7 7 License: GNU General Public License v3.0 8 8 License URI: http://www.gnu.org/licenses/gpl-3.0.txt … … 13 13 == Description == 14 14 This plugin enables WordPress users to easily integrate Adnow's native ads widgets on their site. 15 Generate high income on your website by showing native ads with high CTR to your visitors. 15 Generate high income on your website by showing native ads with high CTR to your visitors. 16 16 17 17 == Installation == … … 21 21 2. Activate the plugin through the 'Plugins' menu in WordPress. 22 22 23 You will find 'Adnow plugin' menu in your WordPress admin panel.23 You will find 'Adnow Native Widget' menu in your WordPress admin panel. 24 24 For basic usage, you can also have a look at the plugin homepage. 25 25 … … 29 29 30 30 == Frequently Asked Questions == 31 = How do I use Ad Now Plugin? =31 = How do I use Adnow Native Widget? = 32 32 You must first contact us here at AdNow and we will get you started by setting up your account and providing you with your 'Publisher ID' and your 'Widgets ID'. After that all you need to do is download the plugin and get started. 33 33 … … 52 52 5. Go to your profile settings (1) in the profile menu and click "WordPress plugin" (2). 53 53 6. Select your website with the WordPress plugin (1). The token value will appear in the "Token" field. Select it and copy it to the Clipboard (2). 54 7. In the WordPress Sidebar, click "Adnow plugin" (1). Paste the token value from the Clipboard into the "Token" field (2). Click "Save Changes"54 7. In the WordPress Sidebar, click "Adnow Native Widget" (1). Paste the token value from the Clipboard into the "Token" field (2). Click "Save Changes" 55 55 8. When you save the token, the plugin configuration screen will display the information about your Adnow.com account. Antiadblock settings and statistics will also be displayed. 56 56 9. By default, Antiadblock is on. 57 10. Too choose the location of the ad unit, click "Manage Places" (1). Alternatively, select "Adnow Plugin. Edit place "(2) from the Sidebar.57 10. Too choose the location of the ad unit, click "Manage Places" (1). Alternatively, select "Adnow Native Widget. Edit place "(2) from the Sidebar. 58 58 11. A new window will open. You can select a page category (1) at the top of the screen and then adjust the location of the ad widget (2). 59 59 12. Select the widget you need from the drop-down list (1). Click "Preview" to see the widget (2) … … 62 62 63 63 == Changelog == 64 = 1.0.4 =65 * Adding new areas for advertising66 = 1.0.3 =67 * Reduction in the number of calls to the server68 64 = 1.0.2 = 69 65 * Added compatibility with the plugin WP Super Cache -
native-ads-adnow/trunk/admin/class-adnow-widget-admin.php
r1678166 r2889963 1 1 <?php 2 3 // define('API_URL', 'http://host.docker.internal:8080/wp_aadb.php'); 4 define('API_URL', 'https://wp_plug.adnow.com/wp_aadb.php'); 5 2 6 class Adnow_Widget_Admin { 3 7 private $plugin_name; 4 8 public $token; 5 9 public $message_error = ''; 10 public $json; 6 11 public $widgets; 7 12 private $option_name = 'Adnow_Widget'; … … 13 18 $this->token = false; 14 19 $this->json = ''; 20 $options_token = get_option( $this->option_name . '_key' ); 21 if(!empty($options_token)){ 22 $json = $this->apiCall($options_token); 23 $widgets_val = json_decode($json, true); 24 if($widgets_val["validate"] === false){ 25 $this->message_error = 'You have entered an invalid token!'; 26 } 27 $this->token = $options_token; 28 } 15 29 } 30 31 private function apiCall($token) { 32 $params = array( 33 'token=' . $token, 34 'validate=1' 35 ); 36 $url = API_URL . '?' . implode('&', $params); 37 38 set_error_handler(array($this, 'warning_handler'), E_WARNING); 39 $json = file_get_contents($url); 40 restore_error_handler(); 41 42 return $json; 43 } 16 44 17 45 public function enqueue_styles() { … … 42 70 43 71 public function display_options_page() { 44 $this->get_json();45 72 include_once 'partials/adnow-widget-admin-display.php'; 46 73 } 47 74 48 public function register_setting() { 75 public function register_setting() { 49 76 add_settings_section( 50 77 $this->option_name . '_general', … … 53 80 $this->plugin_name 54 81 ); 55 82 56 83 add_settings_section( 57 84 $this->option_name . '_head_account_key', … … 59 86 array(), 60 87 $this->plugin_name 61 ); 88 ); 62 89 63 90 add_settings_section( … … 80 107 } 81 108 82 public function get_json() {83 $options_token = get_option( $this->option_name . '_key' );84 if(!empty($options_token)){85 86 $request = wp_remote_get('http://wp_plug.adnow.com/wp_aadb.php?token='.$options_token);87 if ( ! is_wp_error( $request ) || wp_remote_retrieve_response_code( $request ) === 200 ){88 $this->json = wp_remote_retrieve_body( $request );89 } else{90 set_error_handler(array($this, "warning_handler"), E_WARNING);91 $this->json = file_get_contents('http://wp_plug.adnow.com/wp_aadb.php?token='.$options_token);92 restore_error_handler();93 }94 95 $widgets_val = json_decode($this->json, true);96 if(!empty($widgets_val["msg"])){97 $this->message_error = $widgets_val["msg"];98 }99 $this->token = $options_token;100 }101 }102 103 109 public function Adnow_Widget_general_cb() { 104 110 if($this->token !== false){ 111 $this->json = $this->apiCall($this->token); 105 112 $this->widgets = json_decode($this->json, true); 106 113 $account_id = !empty($this->widgets['account']['id']) ? $this->widgets['account']['id'] : ''; … … 118 125 <?php else: ?> 119 126 <input class="checkbox" autocomplete="off" type="hidden" name="<?php echo esc_html($this->option_name) . '_turn' ?>" id="<?php echo esc_html($this->option_name) . '_turn' ?>" value="before"><br> 120 127 121 128 <?php endif; ?> 122 129 </div> … … 147 154 if($this->token !== false and $this->message_error == ''){ 148 155 $impressions = !empty($this->widgets['impressions']) ? $this->widgets['impressions'] : 0; 149 $impressions = number_format($impressions, 0, '', ' '); 156 $impressions = number_format($impressions, 0, '', ' '); 150 157 } ?> 151 158 <?php if($this->token !== false and $this->message_error == '') : ?> … … 161 168 } 162 169 163 public function warning_handler($errno, $errstr) { 164 $this->message_error = 'Problem retrieving data from the server! ';170 public function warning_handler($errno, $errstr) { 171 $this->message_error = 'Problem retrieving data from the server! ' . $errstr; 165 172 } 166 173 } -
native-ads-adnow/trunk/admin/partials/adnow-widget-setting-display.php
r1678166 r2889963 14 14 if(!empty($token)){ 15 15 $json = ''; 16 $request = wp_remote_get('http://wp_plug.adnow.com/wp_aadb.php?token='.$token); 17 if ( ! is_wp_error( $request ) || wp_remote_retrieve_response_code( $request ) === 200 ){ 18 $json = wp_remote_retrieve_body( $request ); 19 } else{ 20 set_error_handler(array($this, "warning_handler"), E_WARNING); 21 $json = file_get_contents('http://wp_plug.adnow.com/wp_aadb.php?token='.$token); 22 restore_error_handler(); 23 } 24 16 set_error_handler("warning_handler", E_WARNING); 17 $json = file_get_contents(API_URL . '?token='.$token.'&validate=1'); 18 echo $json; 19 restore_error_handler(); 25 20 $widgets = json_decode($json, true); 26 21 } else{ 27 $widgets[" success"] = false;22 $widgets["validate"] = false; 28 23 } 29 24 30 function warning_handler($errno, $errstr) { 25 function warning_handler($errno, $errstr) { 31 26 return false; 32 27 } 33 28 34 if($widgets[" success"] !== false){35 $edit_area = new Adnow_Widget_Area; 29 if($widgets["validate"] !== false){ 30 $edit_area = new Adnow_Widget_Area; 36 31 $url = !empty($_GET['url']) ? sanitize_text_field($_GET['url']) : home_url(); 37 32 }else{ -
native-ads-adnow/trunk/adnow-widget.php
r1743357 r2889963 10 10 * 11 11 * @link https://adnow.com 12 * @since 1.0.412 * @since 2.0.1 13 13 * @package adnow_widget 14 14 * 15 15 * @wordpress-plugin 16 * Plugin Name: Adnow Plugin16 * Plugin Name: Adnow Native Widget 17 17 * Plugin URI: https://adnow.com/wordpress-plugin 18 18 * Description: Adding a widget to your website Adnow 19 * Version: 1.0.419 * Version: 2.0.1 20 20 * Author: Adnow 21 21 * Author URI: https://adnow.com -
native-ads-adnow/trunk/includes/class-adnow-widget.php
r1743357 r2889963 67 67 * @since 1.0.0 68 68 */ 69 public function __construct() 70 { 69 public function __construct() { 70 71 71 $this->plugin_name = 'adnow-widget'; 72 72 $this->version = '1.0.2'; 73 73 74 $this->load_dependencies(); 74 75 $this->set_locale(); … … 95 96 * @access private 96 97 */ 97 private function load_dependencies() 98 { 98 private function load_dependencies() { 99 99 100 100 /** … … 130 130 131 131 $this->loader = new Adnow_Widget_Loader(); 132 132 133 } 133 134 … … 141 142 * @access private 142 143 */ 143 private function set_locale() 144 { 144 private function set_locale() { 145 145 146 $plugin_i18n = new Adnow_Widget_i18n(); 146 147 $plugin_i18n->set_domain( $this->get_plugin_name() ); 147 148 148 149 $this->loader->add_action( 'plugins_loaded', $plugin_i18n, 'load_plugin_textdomain' ); 150 149 151 } 150 152 … … 156 158 * @access private 157 159 */ 158 private function define_admin_hooks() 159 { 160 private function define_admin_hooks() { 161 160 162 $plugin_admin = new Adnow_Widget_Admin( $this->get_plugin_name(), $this->get_version() ); 161 163 162 164 $this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_styles' ); 163 165 $this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_scripts' ); 164 166 165 167 $this->loader->add_action( 'admin_menu', $plugin_admin, 'add_options_page' ); 166 168 $this->loader->add_action( 'admin_menu' , $plugin_admin, 'make_menu' ); … … 177 179 * @access private 178 180 */ 179 private function define_public_hooks() 180 { 181 private function define_public_hooks() { 182 181 183 $plugin_public = new Adnow_Widget_Public( $this->get_plugin_name(), $this->get_version() ); 182 184 … … 191 193 * @since 1.0.0 192 194 */ 193 public function run() 194 { 195 public function run() { 195 196 $this->loader->run(); 196 197 } 197 198 198 public function add_areas() 199 { 199 public function add_areas() { 200 200 $plugin_area = new Adnow_Widget_Add_Area; 201 201 $this->loader->add_action( 'admin_bar_menu', $plugin_area, 'modify_admin_bar', 999 ); … … 208 208 $this->loader->add_filter('the_content', $plugin_area, 'content_before_area'); 209 209 $this->loader->add_filter('the_excerpt', $plugin_area, 'excerpt_after_area'); 210 $this->loader->add_filter('widget_text_content', $plugin_area, 'widget_text_content_area'); 211 $this->loader->add_filter('widget_custom_html_content', $plugin_area, 'widget_custom_html_content_area'); 212 $this->loader->add_action( 'get_footer', $plugin_area, 'get_footer_area' ); 213 $this->loader->add_action( 'wp_footer', $plugin_area, 'wp_footer_area' ); 214 210 //$this->loader->add_filter('get_the_archive_title', $plugin_area, 'get_the_archive_title_area'); 211 //$this->loader->add_action( 'loop_start', $plugin_area, 'loop_start_area' ); 212 //$this->loader->add_action( 'loop_end', $plugin_area, 'loop_end_area' ); 213 //$this->loader->add_action( 'wp_footer', $plugin_area, 'wp_footer_area' ); 215 214 $plugin_area->empty_povt(); 216 215 $this->loader->add_action( 'wp_footer', $plugin_area, 'add_obhod' ); 217 216 } 218 217 218 219 219 /** 220 220 * The name of the plugin used to uniquely identify it within the context of … … 224 224 * @return string The name of the plugin. 225 225 */ 226 public function get_plugin_name() 227 { 226 public function get_plugin_name() { 228 227 return $this->plugin_name; 229 228 } … … 235 234 * @return Adnow_Widget_Loader Orchestrates the hooks of the plugin. 236 235 */ 237 public function get_loader() 238 { 236 public function get_loader() { 239 237 return $this->loader; 240 238 } … … 246 244 * @return string The version number of the plugin. 247 245 */ 248 public function get_version() 249 { 246 public function get_version() { 250 247 return $this->version; 251 248 } -
native-ads-adnow/trunk/public/class-adnow-widget-add-area.php
r1743357 r2889963 1 1 <?php 2 2 class Adnow_Widget_Add_Area { 3 4 3 public $page_plugin; 5 6 public $widgets; 7 4 public $widgets = array(); 8 5 public $aabd; 9 10 6 public $select_widgets; 11 12 7 public $page_type_all; 13 14 8 public $page_area_all; 15 16 9 public $request_uri; 17 18 10 public $operation_all; 19 20 11 private $option_name = 'Adnow_Widget'; 21 12 22 public function __construct() 23 13 14 public function __construct(){ 24 15 global $wpdb; 25 26 16 $this->page_plugin = $this->getPluginStatus(); 27 28 $this->widgets = array(); 29 30 $this->select_widgets = array(); 17 $this->loadWidgets(); 31 18 32 19 $this->operation_all = array('remove', 'close', 'preview', 'save'); 33 34 20 $this->page_type_all = array('post', 'page', 'main', 'category', 'archive', 'search'); 35 36 $this->page_area_all = array( 37 'wp_head', 38 'wp_footer', 39 'get_footer', 40 'loop_start', 41 'loop_end', 42 'comment_form_before', 43 'comment_form_after', 44 'dynamic_sidebar_before', 45 'dynamic_sidebar_after', 46 'content_after', 47 'content_before', 48 'the_excerpt', 49 'widget_text_content', 50 'widget_title', 51 'widget_custom_html_content' 52 ); 53 21 $this->page_area_all = array('wp_head','wp_footer','loop_start','loop_end','comment_form_before','comment_form_after','dynamic_sidebar_before','dynamic_sidebar_after','content_after','content_before','the_excerpt'); 22 54 23 $request = $_SERVER["REQUEST_URI"]; 55 56 if (! empty($request)) { 24 if(!empty($request)){ 57 25 $this->request_uri = esc_url($request); 58 } else{26 }else{ 59 27 $this->request_uri = '/'; 60 28 } … … 62 30 $post_operation = !empty($_POST['operation']) ? sanitize_text_field($_POST['operation']) : false; 63 31 64 if (! empty($post_operation) && in_array($post_operation, $this->operation_all)) { 65 66 if (! empty($_POST['widget_id']) && ! empty($_POST['action_area']) && ! empty($_POST['type_post'])) { 32 if(!empty($post_operation) and in_array($post_operation, $this->operation_all)){ 33 if(!empty($_POST['widget_id']) and !empty($_POST['action_area']) and !empty($_POST['type_post'])){ 67 34 $id_area_post = true; 68 35 $post_widget_id = intval($_POST['widget_id']); 69 70 if (! $post_widget_id) { 36 if(!$post_widget_id){ 71 37 $id_area_post = false; 72 38 } 73 74 39 $post_action_area = sanitize_text_field($_POST['action_area']); 75 76 if (! in_array($post_action_area, $this->page_area_all)) { 40 if(!in_array($post_action_area, $this->page_area_all)){ 77 41 $id_area_post = false; 78 42 } 79 80 43 $post_type_post =sanitize_text_field($_POST['type_post']); 81 82 if (! in_array($post_type_post, $this->page_type_all)) { 44 if(!in_array($post_type_post, $this->page_type_all)){ 83 45 $id_area_post = false; 84 46 } 85 86 } else { 47 }else{ 87 48 $id_area_post = false; 88 49 } … … 93 54 switch ($post_operation) { 94 55 case 'remove': 95 if (! empty($id_area_post)){56 if(!empty($id_area_post)){ 96 57 $this->remove_ad($post_action_area, $post_type_post, $post_widget_id); 97 58 } … … 99 60 100 61 case 'close': 101 if (! empty($id_area_post)){62 if(!empty($id_area_post)){ 102 63 $this->remove_ad($post_action_area, $post_type_post, $post_widget_id, '-preview-adnow'); 103 64 } … … 105 66 106 67 case 'preview': 107 if (! empty($id_area_post)){108 $ this->add_widget_array($post_widget_id, $post_action_area, $post_type_post);68 if(!empty($id_area_post)){ 69 $id_widget = $this->add_widget_array($post_widget_id, $post_action_area, $post_type_post); 109 70 } 110 71 break; … … 112 73 case 'save': 113 74 $previews = $wpdb->get_col($wpdb->prepare("SELECT option_name FROM $wpdb->options WHERE option_name LIKE %s", '%-preview-adnow%')); 114 115 75 foreach ($previews as $key => $double) { 116 $ wpdb->query( $wpdb->prepare("UPDATE $wpdb->options SET option_name = REPLACE (option_name, '-preview-adnow', '') WHERE option_name = %s", sanitize_text_field($double)));76 $updates = $wpdb->query( $wpdb->prepare("UPDATE $wpdb->options SET option_name = REPLACE (option_name, '-preview-adnow', '') WHERE option_name = %s", sanitize_text_field($double))); 117 77 } 118 119 78 $plugin_status = $this->getPluginStatus(); 120 121 if (! empty($plugin_status)) { 122 $wpdb->delete($wpdb->options, array( 'option_name' => 'edit_area')); 79 if(!empty($plugin_status)){ 80 $del = $wpdb->delete($wpdb->options, array( 'option_name' => 'edit_area')); 123 81 } 124 82 break; … … 126 84 } 127 85 128 private function getPluginStatus() 129 { 86 private function getPluginStatus(){ 130 87 global $wpdb; 131 132 88 $edit_area = $wpdb->get_row($wpdb->prepare("SELECT option_value FROM $wpdb->options WHERE option_name = %s", 'edit_area')); 133 134 return (! empty($edit_area)) ? true : false; 135 } 136 137 private function addHeadPanel() 138 { 139 global $wpdb; 140 141 $type_post = $this->getTypePage(); 142 $nal_ad = $wpdb->get_row($wpdb->prepare("SELECT count(*) as cnt FROM $wpdb->options WHERE option_value LIKE %s AND option_name = %s", '%' . $type_post . '-%', 'obhod')); 143 144 if ($this->getPluginStatus() === false && $nal_ad->cnt == 0) { 145 $this->widgets = array(); 146 } else { 147 $token = get_option( $this->option_name . '_key' ); 148 $request = wp_remote_get('http://wp_plug.adnow.com/wp_aadb.php?token=' . $token); 149 150 if ( ! is_wp_error( $request ) || wp_remote_retrieve_response_code( $request ) === 200 ) { 151 $json = wp_remote_retrieve_body( $request ); 152 } else { 153 set_error_handler( array($this, "warning_handler"), E_WARNING ); 154 155 $json = file_get_contents('http://wp_plug.adnow.com/wp_aadb.php?token=' . $token); 156 157 restore_error_handler(); 158 } 159 160 if (! empty($json)) { 161 $widgets = json_decode($json, true); 162 163 if (! empty($widgets['widget'])) { 164 $this->widgets = $widgets['widget']; 165 $this->aabd = $widgets['aadb']; 166 167 if (is_array($this->widgets)) { 168 169 foreach ($this->widgets as $key => $value) { 170 $this->select_widgets[$key] = $value['title']; 171 } 172 } 173 } else { 174 $this->widgets = array(); 175 } 176 } 177 } 178 89 if(!empty($edit_area)){ 90 return true; 91 }else{ 92 return false; 93 } 94 } 95 96 private function loadWidgets() { 97 $token = get_option( $this->option_name . '_key' ); 98 set_error_handler(array($this, "warning_handler"), E_WARNING); 99 $json = file_get_contents(API_URL . '?token=' . $token); 100 restore_error_handler(); 101 if(!empty($json)){ 102 $widgets = json_decode($json, true); 103 if(!empty($widgets['widget'])){ 104 $this->widgets = $widgets['widget']; 105 $this->aabd = $widgets['aadb']; 106 if(is_array($this->widgets)){ 107 foreach ($this->widgets as $key => $value) { 108 $this->select_widgets[$key] = $value['title']; 109 } 110 } 111 }else{ 112 $this->widgets = array(); 113 } 114 } 115 } 116 117 private function addHeadPanel(){ 179 118 $headpanel = ''; 180 181 if ($this->is_user_role('administrator') && $this->getPluginStatus() === true) { 182 119 if($this->is_user_role('administrator') and $this->getPluginStatus() === true ){ 183 120 $headpanel .= '<div_adnblock class="header_fix_top head_panel"> 184 121 <div_adnblock class="container_top"> … … 189 126 <div_adnblock class="adn_pages"> 190 127 <div_adnblock class="adn_name">Site Pages</div_adnblock>'; 191 192 128 foreach ($this->page_type_all as $type) { 193 129 $headpanel .= $this->get_home_page($type); 194 130 } 195 196 131 $headpanel .= '</div_adnblock> 197 132 </div_adnblock> … … 203 138 </div_adnblock>'; 204 139 } 205 206 140 return $headpanel; 207 141 } 208 142 209 private function getRecheck($action_area) 210 { 143 private function getRecheck($action_area){ 211 144 global $wpdb; 212 213 145 $type_post = $this->getTypePage(); 214 215 $count_add_page = $wpdb->get_row($wpdb->prepare("SELECT option_value FROM $wpdb->options WHERE option_name = %s", $action_area . '_add_' . $type_post)); 216 217 if (! isset($count_add_page)) { 218 $wpdb->query( $wpdb->prepare( "INSERT INTO $wpdb->options ( option_name, option_value, autoload ) VALUES ( %s, %s, %s )", $action_area . '_add_' . $type_post, 'yes', 'no' ) ); 219 } 220 146 $count_add_page = $wpdb->get_row($wpdb->prepare("SELECT option_value FROM $wpdb->options WHERE option_name = %s", $action_area.'_add_'.$type_post)); 147 148 if(!isset($count_add_page)){ 149 $inc = $wpdb->query( $wpdb->prepare( "INSERT INTO $wpdb->options ( option_name, option_value, autoload ) VALUES ( %s, %s, %s )", $action_area.'_add_'.$type_post, 'yes', 'no' ) ); 150 } 221 151 return $count_add_page; 222 152 } 223 153 224 private function getCode($action_area, $size='big') 225 { 154 private function getCode($action_area, $size='big'){ 226 155 global $wpdb; 227 228 156 $adnblock = ''; 229 230 157 $type_post = $this->getTypePage(); 231 232 $vision = $wpdb->get_row($wpdb->prepare("SELECT option_value FROM $wpdb->options WHERE option_name = %s", $action_area . '-' . $type_post)); 233 234 $vision_preview = $wpdb->get_row($wpdb->prepare("SELECT option_value FROM $wpdb->options WHERE option_name = %s", $action_area . '-' . $type_post . '-preview-adnow')); 235 236 if (! empty($vision)) { 158 $vision = $wpdb->get_row($wpdb->prepare("SELECT option_value FROM $wpdb->options WHERE option_name = %s", $action_area.'-'.$type_post)); 159 $vision_preview = $wpdb->get_row($wpdb->prepare("SELECT option_value FROM $wpdb->options WHERE option_name = %s", $action_area.'-'.$type_post.'-preview-adnow')); 160 if(!empty($vision)){ 237 161 $vision_arr = esc_html($vision->option_value); 238 239 if (! empty($this->widgets[$vision_arr])) { 162 if(!empty($this->widgets[$vision_arr])){ 240 163 241 164 $adnblock = ' 242 <adnblock class="top_index_block_adnow" id="' . $action_area . '"> 243 <form id="form_' . $action_area . '" method="post" action="' . $this->request_uri . '#' . $action_area . '">'; 244 245 if ($this->is_user_role('administrator') && $this->getPluginStatus() === true) { 246 $adnblock .= '<input name="widget_id" type="hidden" value="' . $vision_arr . '"> 247 <input name="action_area" type="hidden" value="' . $action_area . '"> 248 <input name="type_post" type="hidden" value="' . $type_post . '"> 165 <adnblock class="top_index_block_adnow" id="'.$action_area.'"> 166 <form id="form_'.$action_area.'" method="post" action="'.$this->request_uri.'#'.$action_area.'">'; 167 if($this->is_user_role('administrator') and $this->getPluginStatus() === true ){ 168 $adnblock .= '<input name="widget_id" type="hidden" value="'.$vision_arr.'"> 169 <input name="action_area" type="hidden" value="'.$action_area.'"> 170 <input name="type_post" type="hidden" value="'.$type_post.'"> 249 171 <input name="operation" type="hidden" value="remove"> 250 <button_adnblock onclick="document.getElementById(\'form_' . $action_area .'\').submit()" class="add_widget_plus_content">172 <button_adnblock onclick="document.getElementById(\'form_'.$action_area.'\').submit()" class="add_widget_plus_content"> 251 173 <span_adnblock class="remove_widget">Remove widgets</span_adnblock> 252 <span_adnblock class="id_title_widget"><strong>' . esc_html($this->select_widgets[$vision_arr]) . '</strong> (ID:' . $vision_arr . ')</span_adnblock> 253 </button_adnblock>'; 174 <span_adnblock class="id_title_widget"><strong>'.esc_html($this->select_widgets[$vision_arr]).'</strong> (ID:'.$vision_arr.')</span_adnblock> 175 </button_adnblock> 176 '; 254 177 } 255 256 178 $adnblock .= ' 257 <div class="prev" data-widget="' . $vision_arr . '">' . base64_decode($this->widgets[$vision_arr]['code']) .'</div>179 <div class="prev" data-widget="'.$vision_arr.'">'.base64_decode($this->widgets[$vision_arr]['code']).'</div> 258 180 </form> 259 181 </adnblock>'; 260 182 } 261 } elseif (! empty($vision_preview)){183 } elseif(!empty($vision_preview)){ 262 184 $vision_arr = esc_html($vision_preview->option_value); 263 264 if (! empty($this->widgets[$vision_arr])) { 265 266 if ($this->is_user_role('administrator') && $this->getPluginStatus() === true) { 185 if(!empty($this->widgets[$vision_arr])){ 186 if($this->is_user_role('administrator') and $this->getPluginStatus() === true ){ 267 187 $adnblock = ' 268 <adnblock class="top_index_block_adnow" id="' . $action_area .'">269 <form id="form_' . $action_area . '" method="post" action="' . $this->request_uri . '#' . $action_area .'">';270 $adnblock .= '<input name="widget_id" type="hidden" value="' . $vision_arr .'">271 <input name="action_area" type="hidden" value="' . $action_area .'">272 <input name="type_post" type="hidden" value="' . $type_post .'">188 <adnblock class="top_index_block_adnow" id="'.$action_area.'"> 189 <form id="form_'.$action_area.'" method="post" action="'.$this->request_uri.'#'.$action_area.'">'; 190 $adnblock .= '<input name="widget_id" type="hidden" value="'.$vision_arr.'"> 191 <input name="action_area" type="hidden" value="'.$action_area.'"> 192 <input name="type_post" type="hidden" value="'.$type_post.'"> 273 193 <input name="operation" type="hidden" value="close"> 274 <button_adnblock onclick="document.getElementById(\'form_' . $action_area .'\').submit()" class="add_widget_plus_content">194 <button_adnblock onclick="document.getElementById(\'form_'.$action_area.'\').submit()" class="add_widget_plus_content"> 275 195 <span_adnblock class="remove_widget close_prev">Close view widget</span_adnblock> 276 <span_adnblock class="id_title_widget"><strong>' . esc_html($this->select_widgets[$vision_arr]) . '</strong> (ID:' . $vision_arr .')</span_adnblock>196 <span_adnblock class="id_title_widget"><strong>'.esc_html($this->select_widgets[$vision_arr]).'</strong> (ID:'.$vision_arr.')</span_adnblock> 277 197 </button_adnblock> 278 198 '; 279 199 $adnblock .= ' 280 <div class="prev view_prev" data-widget="' . $vision_arr . '">' . base64_decode($this->widgets[$vision_arr]['code']) .'</div>200 <div class="prev view_prev" data-widget="'.$vision_arr.'">'.base64_decode($this->widgets[$vision_arr]['code']).'</div> 281 201 </form> 282 202 </adnblock>'; 283 203 } 284 204 } 285 } else 286 if ($this->is_user_role('administrator') and $this->getPluginStatus() === true){205 } else{ 206 if($this->is_user_role('administrator') and $this->getPluginStatus() === true ){ 287 207 $select_in = $wpdb->get_row($wpdb->prepare("SELECT option_value FROM $wpdb->options WHERE option_name = %s", 'obhod')); 288 208 289 $ids = ! empty($select_in->option_value) ? explode(",", $select_in->option_value) : array(); 209 $ids_all = array(); 210 $ids = !empty($select_in->option_value) ? explode(",", $select_in->option_value) : array(); 290 211 $ids = array_diff($ids, array('')); 291 212 292 213 $adnblock = ' 293 <adnblock class="top_index_block_adnow" id="' . $action_area .'">294 <form id="form_' . $action_area . '" method="post" action="' . $this->request_uri . '#' . $action_area .'">295 <div_adnblock class="adnow_widget_block adn_' . $size .'">214 <adnblock class="top_index_block_adnow" id="'.$action_area.'"> 215 <form id="form_'.$action_area.'" method="post" action="'.$this->request_uri.'#'.$action_area.'"> 216 <div_adnblock class="adnow_widget_block adn_'.$size.'"> 296 217 <div_adnblock class="adn_name">Place widgets here</div_adnblock> 297 218 <div_adnblock class="adn_form"> 298 219 <select name="widget_id" onfocus="this.parentNode.parentNode.classList.add(\'focused\');" onblur="this.parentNode.parentNode.classList.remove(\'focused\');"><option></option>'; 299 300 foreach ($this->select_widgets as $key => $value) { 301 302 if (! in_array($type_post . '-' . $key, $ids)) { 303 $adnblock .= '<option value="' . $key . '">' . $value . '</option>'; 304 } 305 } 306 307 $adnblock .= ' 220 foreach ($this->select_widgets as $key => $value) { 221 if(!in_array($type_post.'-'.$key, $ids)){ 222 $adnblock .= '<option value="'.$key.'">'.$value.'</option>'; 223 } 224 } 225 $adnblock .= ' 308 226 </select> 309 <input name="action_area" type="hidden" value="' . $action_area .'">310 <input name="type_post" type="hidden" value="' . $type_post .'">227 <input name="action_area" type="hidden" value="'.$action_area.'"> 228 <input name="type_post" type="hidden" value="'.$type_post.'"> 311 229 <input name="operation" type="hidden" value="preview"> 312 <button_adnblock onclick="document.getElementById(\'form_' . $action_area .'\').submit()" class="adn_submit add_widget_plus_content">Preview</button_adnblock>230 <button_adnblock onclick="document.getElementById(\'form_'.$action_area.'\').submit()" class="adn_submit add_widget_plus_content">Preview</button_adnblock> 313 231 </div_adnblock> 314 232 </div_adnblock> … … 317 235 } 318 236 } 319 320 237 return $adnblock; 321 238 } 322 239 323 private function getTypePage() 324 { 325 if (is_front_page()) { 240 private function getTypePage(){ 241 if(is_front_page()){ 326 242 $type_post = 'main'; 327 } elseif (is_search()){243 } elseif(is_search()){ 328 244 $type_post = 'search'; 329 } elseif (is_page()){245 } elseif(is_page()){ 330 246 $type_post = 'page'; 331 } elseif (is_single()){247 } elseif(is_single()){ 332 248 $type_post = 'post'; 333 } elseif (is_category()){249 } elseif(is_category()){ 334 250 $type_post = 'category'; 335 } elseif (is_archive()){251 } elseif(is_archive()){ 336 252 $type_post = 'archive'; 337 } else 253 } else{ 338 254 $type_post = 'other'; 339 255 } 340 341 return $type_post; 342 } 343 344 private function get_home_page($param) 345 { 256 return $type_post; 257 } 258 259 private function get_home_page($param){ 346 260 global $wpdb; 347 348 global $cache_page_secret;349 350 261 $type_post_active = $this->getTypePage(); 351 262 $type_page = $param; … … 353 264 354 265 $home_page = home_url(); 355 356 if (! empty($param)) { 357 266 if(!empty($param)){ 358 267 switch ($param) { 359 268 case 'page': 360 $post_guid = $wpdb->get_col($wpdb->prepare("SELECT id FROM $wpdb->posts WHERE post_status = %s AND post_type = %s ORDER BY id DESC LIMIT 1", 'publish', 'page')); 361 $home_page = !empty($post_guid[0]) ? get_site_url() . '/?p=' . $post_guid[0] : get_site_url() .'/';269 $post_guid = $wpdb->get_col($wpdb->prepare("SELECT id FROM $wpdb->posts WHERE post_status = %s AND post_type = %s ORDER BY id DESC LIMIT 1", 'publish', 'page')); 270 $home_page = !empty($post_guid[0]) ? get_site_url().'/?p='.$post_guid[0] : get_site_url().'/'; 362 271 break; 363 272 364 273 case 'post': 365 $post_guid = $wpdb->get_col($wpdb->prepare("SELECT id FROM $wpdb->posts WHERE post_status = %s AND post_type = %s ORDER BY id DESC LIMIT 1", 'publish', 'post')); 366 $home_page = !empty($post_guid[0]) ? get_site_url() . '/?p=' . $post_guid[0] : get_site_url() .'/';274 $post_guid = $wpdb->get_col($wpdb->prepare("SELECT id FROM $wpdb->posts WHERE post_status = %s AND post_type = %s ORDER BY id DESC LIMIT 1", 'publish', 'post')); 275 $home_page = !empty($post_guid[0]) ? get_site_url().'/?p='.$post_guid[0] : get_site_url().'/'; 367 276 break; 368 277 369 278 case 'attachment': 370 $post_guid = $wpdb->get_col($wpdb->prepare("SELECT id FROM $wpdb->posts WHERE post_status = %s AND post_type = %s ORDER BY id DESC LIMIT 1", 'publish', 'attachment')); 371 $home_page = !empty($post_guid[0]) ? get_site_url() . '/?p=' . $post_guid[0] : get_site_url() .'/';279 $post_guid = $wpdb->get_col($wpdb->prepare("SELECT id FROM $wpdb->posts WHERE post_status = %s AND post_type = %s ORDER BY id DESC LIMIT 1", 'publish', 'attachment')); 280 $home_page = !empty($post_guid[0]) ? get_site_url().'/?p='.$post_guid[0] : get_site_url().'/'; 372 281 break; 373 282 … … 388 297 389 298 case 'search': 390 $home_page = home_url() . '/?s=search';299 $home_page = home_url().'/?s=+'; 391 300 break; 392 301 } 393 302 } 394 303 395 if (! empty($cache_page_secret)) { 304 global $cache_page_secret; 305 if(!empty($cache_page_secret)){ 396 306 $home_page = add_query_arg( 'donotcachepage', $cache_page_secret, $home_page ); 397 307 } 398 308 399 return '<a class="adn_button ' . $adv_active . '" href="' . esc_url($home_page) . '">' . ucfirst($type_page) .'</a>';309 return '<a class="adn_button '.$adv_active.'" href="'.esc_url($home_page).'">'.ucfirst($type_page).'</a>'; 400 310 } 401 311 402 private function add_widget_array($id_widget, $action_area, $type_post) 403 { 312 private function add_widget_array($id_widget, $action_area, $type_post){ 404 313 global $wpdb; 405 406 $backup = $wpdb->get_col($wpdb->prepare("SELECT option_name FROM $wpdb->options WHERE option_name = %s", $action_area . '-' . $type_post . '-preview-adnow')); 407 408 if (count($backup) == 0) { 409 $inc = $wpdb->query( $wpdb->prepare( "INSERT INTO $wpdb->options ( option_name, option_value, autoload ) VALUES ( %s, %s, %s )", $action_area . '-' . $type_post . '-preview-adnow', $id_widget, 'no' ) ); 410 411 $this->obhod($type_post . '-' . $id_widget, 'add'); 412 } 413 314 $backup = $wpdb->get_col($wpdb->prepare("SELECT option_name FROM $wpdb->options WHERE option_name = %s", $action_area.'-'.$type_post.'-preview-adnow')); 315 if(count($backup)==0){ 316 $inc = $wpdb->query( $wpdb->prepare( "INSERT INTO $wpdb->options ( option_name, option_value, autoload ) VALUES ( %s, %s, %s )", $action_area.'-'.$type_post.'-preview-adnow', $id_widget, 'no' ) ); 317 318 $this->obhod($type_post.'-'.$id_widget, 'add'); 319 } 414 320 return $inc; 321 415 322 } 416 323 417 private function obhod($id_widget, $action) 418 { 324 private function obhod($id_widget, $action){ 419 325 global $wpdb; 420 421 326 $obhod = $wpdb->get_col($wpdb->prepare("SELECT option_name FROM $wpdb->options WHERE option_name = %s", 'obhod')); 422 423 if (count($obhod) == 0) { 424 $wpdb->query($wpdb->prepare("INSERT INTO $wpdb->options ( option_name, option_value, autoload ) VALUES ( %s, %s, %s )", 'obhod', '', 'no')); 425 } 426 327 if(count($obhod)==0){ 328 $add_ob = $wpdb->query($wpdb->prepare("INSERT INTO $wpdb->options ( option_name, option_value, autoload ) VALUES ( %s, %s, %s )", 'obhod', '', 'no')); 329 } 427 330 switch ($action) { 428 331 case 'add': 429 $wpdb->query($wpdb->prepare("UPDATE $wpdb->options SET option_value = CONCAT(option_value, %s) WHERE option_name='obhod'", $id_widget .','));332 $wpdb->query($wpdb->prepare("UPDATE $wpdb->options SET option_value = CONCAT(option_value, %s) WHERE option_name='obhod'", $id_widget.',')); 430 333 break; 431 334 432 335 case 'remove': 433 $wpdb->query($wpdb->prepare("UPDATE $wpdb->options SET option_value = REPLACE(option_value, %s, '') WHERE option_name='obhod'", $id_widget .','));336 $wpdb->query($wpdb->prepare("UPDATE $wpdb->options SET option_value = REPLACE(option_value, %s, '') WHERE option_name='obhod'", $id_widget.',')); 434 337 break; 435 338 } 436 339 } 437 340 438 private function remove_ad($action_area, $type_post, $id_widget, $preview = '') 439 { 341 private function remove_ad($action_area, $type_post, $id_widget, $preview=''){ 440 342 global $wpdb; 441 343 442 $nal = $wpdb->get_col($wpdb->prepare("SELECT option_name FROM $wpdb->options WHERE option_name = %s", $action_area . '-' . $type_post .$preview));443 444 if (! empty($nal)){445 $ wpdb->delete($wpdb->options, array( 'option_name' => $action_area . '-' . $type_post .$preview));446 $this->obhod($type_post . '-' .$id_widget, 'remove');344 $nal = $wpdb->get_col($wpdb->prepare("SELECT option_name FROM $wpdb->options WHERE option_name = %s", $action_area.'-'.$type_post.$preview)); 345 346 if(!empty($nal)){ 347 $del = $wpdb->delete($wpdb->options, array( 'option_name' => $action_area.'-'.$type_post.$preview)); 348 $this->obhod($type_post.'-'.$id_widget, 'remove'); 447 349 } 448 350 } 449 351 450 352 451 public function wp_head_area() 452 { 353 public function wp_head_area() { 453 354 echo $this->addHeadPanel(); 454 355 } 455 356 456 public function wp_footer_area() 457 { 357 public function wp_footer_area() { 458 358 echo $this->getCode('wp_footer'); 459 359 } 460 360 461 public function get_footer_area() 462 { 463 echo $this->getCode('get_footer'); 464 } 465 466 public function loop_start_area() 467 { 361 public function loop_start_area() { 468 362 $recheck = $this->getRecheck('loop_start'); 469 470 if (! isset($recheck)) { 363 if(!isset($recheck)){ 471 364 echo $this->getCode('loop_start'); 472 365 } 473 366 } 474 367 475 public function loop_end_area() 476 { 368 public function loop_end_area() { 477 369 $recheck = $this->getRecheck('loop_end'); 478 479 if (! isset($recheck)) { 370 if(!isset($recheck)){ 480 371 echo $this->getCode('loop_end'); 481 372 } 482 373 } 483 374 484 public function comment_form_before_area() 485 { 375 public function comment_form_before_area() { 486 376 echo $this->getCode('comment_form_before'); 487 377 } 488 489 public function comment_form_after_area() 490 { 378 379 public function comment_form_after_area() { 491 380 echo $this->getCode('comment_form_after'); 492 381 } 493 494 public function dynamic_sidebar_before_area() 495 { 382 383 public function dynamic_sidebar_before_area() { 496 384 $recheck = $this->getRecheck('dynamic_sidebar_before'); 497 498 if (! isset($recheck)) { 385 if(!isset($recheck)){ 499 386 echo $this->getCode('dynamic_sidebar_before', 'small'); 500 387 } 501 } 502 503 public function dynamic_sidebar_after_area() 504 { 388 } 389 390 public function dynamic_sidebar_after_area() { 505 391 $recheck = $this->getRecheck('dynamic_sidebar_after'); 506 507 if (! isset($recheck)) { 392 if(!isset($recheck)){ 508 393 echo $this->getCode('dynamic_sidebar_after', 'small'); 509 394 } 510 395 } 511 512 public function content_after_area($content) 513 { 396 397 public function content_after_area($content) { 514 398 $recheck = $this->getRecheck('content_after'); 515 516 if (! isset($recheck)) { 399 if(!isset($recheck)){ 517 400 $adnblock = $this->getCode('content_after'); 518 $content = $content . $adnblock; 519 } 520 401 $content = $content.$adnblock; 402 } 521 403 return $content; 522 404 } 523 405 524 /* 525 * 526 */ 527 public function content_before_area($content) 528 { 406 public function content_before_area($content) { 529 407 $recheck = $this->getRecheck('content_before'); 530 531 if (! isset($recheck)) { 408 if(!isset($recheck)){ 532 409 $adnblock = $this->getCode('content_before'); 533 $content = $adnblock . $content; 534 } 535 410 $content = $adnblock.$content; 411 } 536 412 return $content; 537 413 } 538 414 539 /* 540 * Content of the displayed post excerpt (for the first post) 541 */ 542 public function excerpt_after_area($content) 543 { 415 public function excerpt_after_area($content) { 544 416 $recheck = $this->getRecheck('the_excerpt'); 545 546 if (! isset($recheck)) { 417 if(!isset($recheck)){ 547 418 $adnblock = $this->getCode('the_excerpt'); 548 $content = $content . $adnblock; 549 } 550 419 $content = $content.$adnblock; 420 } 551 421 return $content; 552 422 } 553 423 554 /* 555 * Content of the Custom HTML widget 556 */ 557 public function widget_custom_html_content_area($content) 558 { 559 $recheck = $this->getRecheck('widget_custom_html_content'); 560 561 if (! isset($recheck)) { 562 $adnblock = $this->getCode('widget_custom_html_content'); 563 $content = $content . $adnblock; 564 } 565 424 public function get_the_archive_title_area($content) { 425 $adnblock = $this->getCode('get_the_archive_title'); 426 $content = $content.$adnblock; 566 427 return $content; 567 428 } 568 429 569 /* 570 * Content of the Text widget 571 */ 572 public function widget_text_content_area($content) 573 { 574 $recheck = $this->getRecheck('widget_text_content'); 575 576 if (! isset($recheck)) { 577 $adnblock = $this->getCode('widget_text_content'); 578 $content = $content . $adnblock; 579 } 580 581 return $content; 582 } 583 584 585 586 public function is_user_role($role, $user_id = null) 587 { 588 $user = is_numeric($user_id) ? get_userdata($user_id) : wp_get_current_user(); 589 590 if (! $user) { 591 return false; 592 } 593 594 return in_array($role, (array) $user->roles); 430 public function is_user_role( $role, $user_id = null ) { 431 $user = is_numeric( $user_id ) ? get_userdata( $user_id ) : wp_get_current_user(); 432 433 if( ! $user ) 434 return false; 435 436 return in_array( $role, (array) $user->roles ); 595 437 } 596 438 597 439 public function empty_povt() { 598 599 440 global $wpdb; 600 441 601 442 foreach ($this->page_area_all as $key => $row) { 602 603 443 foreach ($this->page_type_all as $add) { 604 $wpdb->delete($wpdb->options, array( 'option_name' => $row . '_add_' .$add));444 $wpdb->delete($wpdb->options, array( 'option_name' => $row.'_add_'.$add)); 605 445 } 606 446 } 607 447 } 608 448 609 public function add_obhod() 610 { 449 public function add_obhod() { 611 450 $options_turn = get_option( $this->option_name . '_turn' ); 612 613 if (! empty($options_turn)) { 614 615 if (! empty($this->aabd)) { 451 if(!empty($options_turn)){ 452 if(!empty($this->aabd)){ 616 453 echo base64_decode($this->aabd); 617 454 } … … 619 456 } 620 457 621 622 public function modify_admin_bar( $wp_admin_bar ) 623 { 624 $args = array( 625 'id' => 'edit_place', 626 'title' => 'Edit place Adnow', 627 'href' => admin_url() . 'admin.php?page=edit_place&url=' . $this->request_uri, 628 'meta' => array( 'class' => 'my-toolbar-page' ) 629 ); 630 631 $wp_admin_bar->add_node( $args ); 632 } 633 634 public function warning_handler($errno, $errstr) 635 { 458 public function modify_admin_bar( $wp_admin_bar ) { 459 $token = get_option( $this->option_name . '_key' ); 460 set_error_handler(array($this, "warning_handler"), E_WARNING); 461 $json = file_get_contents(API_URL . '?token=' . $token . '&validate=1'); 462 restore_error_handler(); 463 $widgets = json_decode($json, true); 464 if($widgets["validate"] !== false and $this->getPluginStatus() !== true){ 465 $args = array( 466 'id' => 'edit_place', 467 'title' => 'Edit place Adnow', 468 'href' => admin_url().'admin.php?page=edit_place&url='.$this->request_uri, 469 'meta' => array( 'class' => 'my-toolbar-page' ) 470 ); 471 }else{ 472 $args = array( 473 'id' => 'adnow_widget', 474 'title' => 'Adnow Native Widget', 475 'href' => admin_url().'admin.php?page=adnow-widget', 476 'meta' => array( 'class' => 'my-toolbar-page' ) 477 ); 478 } 479 $wp_admin_bar->add_node( $args ); 480 } 481 482 public function warning_handler($errno, $errstr) { 636 483 return false; 637 484 }
Note: See TracChangeset
for help on using the changeset viewer.