Changeset 2353991
- Timestamp:
- 08/06/2020 01:44:41 PM (5 years ago)
- Location:
- siteattention/trunk
- Files:
-
- 6 edited
-
README.txt (modified) (3 diffs)
-
admin/class-siteattention-admin.php (modified) (6 diffs)
-
admin/js/siteattention-module.js (modified) (2 diffs)
-
includes/class-siteattention.php (modified) (3 diffs)
-
includes/siteattention_seo_tool.php (modified) (2 diffs)
-
siteattention.php (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
siteattention/trunk/README.txt
r2353656 r2353991 6 6 Requires at least: 4.8 7 7 Tested up to: 5.4 8 Stable tag: 3.0. 08 Stable tag: 3.0.1 9 9 License: GPLv2 or later 10 10 License URI: http://www.gnu.org/licenses/gpl-2.0.html … … 77 77 78 78 * Major rewrite of the plugin, especially with focus on the plugin settings page. 79 * The SEO Toolbar, presented to editors on page edits, is no longer visib ile when the plugin settings are not completed.79 * The SEO Toolbar, presented to editors on page edits, is no longer visible when the plugin settings are not completed. 80 80 * The SEO Toolbar no longer supports registration, this is done through the settings page 81 82 = 3.0.0 = 83 84 * Major rewrite of the plugin and redesign of plugin 85 * Added keyword search helper into SEO toolbar 86 87 = 3.0.1 = 88 89 * API updated & optimizations 81 90 82 91 == Upgrade Notice == … … 94 103 * Major rewrite of the plugin and redesign of plugin 95 104 * Added keyword search helper into SEO toolbar 105 106 = 3.0.1 = 107 108 * API updated & optimizations -
siteattention/trunk/admin/class-siteattention-admin.php
r2353656 r2353991 126 126 127 127 $current_user = wp_get_current_user(); 128 $instance_id = siteattention_get_option('iid', ''); 129 $getThreshold = $this->getThreshold($instance_id); 128 130 wp_localize_script($this->name, 'SiteAttentionInfo', [ 129 131 'user' => $current_user->ID, … … 132 134 'key' => siteattention_get_option('license_key', ''), 133 135 'post_type' => get_current_screen()->id, 134 'iid' => siteattention_get_option('iid', ''),136 'iid' => $instance_id, 135 137 'url' => get_permalink(), 136 138 'site_url' => site_url(), … … 138 140 'published' => get_post_status() === 'publish', 139 141 'apiUrl' => SiteAttention::URL, 142 'siteattention_threshold_value' => $getThreshold, 140 143 ]); 141 144 // Above - JS code for displaying the UI Toolbar on edit pages. … … 143 146 } 144 147 145 public function siteattention_rules_view() { 146 require_once 'views/siteattention_rules_view.php'; 147 } 148 /** 149 * Register the Settings page. 150 * 151 * @since 1.0.0 152 */ 153 /* public function siteattention_admin_menu() { 154 155 add_options_page( 156 __( 'SiteAttention', $this->name), 157 __( 'SiteAttention', $this->name ), 158 'manage_options', $this->name, 159 array($this, 'display_plugin_admin_page') 160 ); 161 }*/ 148 /** 149 * Get Threshold 150 * 151 * @since 1.0.0 152 * @return mixed 153 */ 154 public function getThreshold($instance_id){ 155 $response = wp_remote_post(SiteAttention::URL.'/secure/init/'.$instance_id.'/'.get_the_ID().'/wp/en_GB', array( 156 'method' => 'GET', 157 'timeout' => 15, 158 'headers' => array( 159 'X-SiteAttention' => siteattention_get_option('license_key', siteattention_get_option('key', '')) 160 ) 161 )); 162 163 if (is_wp_error($response)) 164 { 165 return SITEATTENTION_THRESHOLD; 166 } 167 168 else 169 { 170 $score_threshold = json_decode($response['body'],true); 171 return $score_threshold['data_score_threshold']; 172 } 173 } 162 174 163 175 /** … … 187 199 188 200 /** 189 * Callback function for the admin settings page.190 *191 * @since 1.0.0192 */193 public function display_plugin_admin_page(){194 195 require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/partials/siteattention-admin-display.php';196 197 wp_enqueue_script(198 $this->name,199 plugin_dir_url( __FILE__ ) . 'dist/siteattention-admin.js',200 array(),201 $this->version,202 true203 );204 205 wp_localize_script($this->name,'SiteAttentionSettingsData', [206 'version' => SiteAttention::VERSION,207 'cmsUrl' => '/siteattention/settings',208 'apiUrl' => SiteAttention::URL,209 'key' => siteattention_get_option('license_key',''),210 'iid' => siteattention_get_option('iid',''),211 'iname' => siteattention_get_option('iname', ''),212 'locked' => 0,213 ]);214 }215 216 public function siteattention_custom_metabox()217 {218 219 $screens = ['post', 'page'];220 foreach ($screens as $screen) {221 add_meta_box(222 'siteattention_metabox_id',223 'Siteattention Seo',224 [ $this, 'siteattention_metabox_html' ],225 $screen,226 'side',227 'high'228 );229 }230 }231 232 function siteattention_metabox_html($post)233 {234 $this->enqueue_styles();235 $this->enqueue_scripts();236 //echo '<a href="javascript:void(0);">aaa</a>';237 }238 239 /**240 * Syncronising post and pages with SiteAttention server241 * @param int $post_ID id of post or page being synced242 * @param object $post_after post or page object after update243 * @param object $post_before post or page object before update244 * @return [type] [description]245 */246 // SiteAttentionAbstract::contentStatusChange.247 public function admin_sync_post($post_ID,$post_after,$post_before) {248 249 if (empty(siteattention_get_option('license_key')) || empty(siteattention_get_option('iid'))) return;250 251 $published = ($post_after->post_status === 'publish' ? 1 : 0);252 253 SiteAttention::callApi('customer/instance/page/publish',[254 'published' => $published,255 'iid' => siteattention_get_option('iid'),256 'pid' => $post_ID,257 'url' => get_permalink($post_ID),258 'lang' => get_locale(),259 ]);260 }261 262 /**263 * Saves SiteAttention information into the siteattention options264 * @return [type] [description]265 */266 public function save_settings() {267 return;268 global $wp_query;//, $wpdb;269 270 if271 ( !isset($wp_query->query_vars['siteattention/settings'])272 ) return;273 274 $post = json_decode(file_get_contents('php://input'),true);275 276 if (isset($post['iid'])) siteattention_set_option('iid', $post['iid']);277 if (isset($post['iname'])) siteattention_set_option('iname', $post['iname']);278 if (isset($post['key'])) siteattention_set_option('license_key', $post['license_key']);279 if (isset($post['locked'])) siteattention_set_option('ilocked', $post['locked']);280 281 exit;282 }283 284 /**285 201 * Enables the Excerpt meta box in Page edit screen. 286 202 */ … … 323 239 delete_post_meta($_POST['post_id'],'page_keyword', $_POST['page_keyword']); 324 240 } 325 326 /**327 * Adds extra code to a registered script.328 *329 * Code will only be added if the script in already in the queue.330 * Accepts a string $data containing the Code. If two or more code blocks331 * are added to the same script $handle, they will be printed in the order332 * they were added, i.e. the latter added code can redeclare the previous.333 *334 * @since 4.5.0335 *336 * @see WP_Scripts::add_inline_script()337 *338 * @param string $handle Name of the script to add the inline script to.339 * @param string $data String containing the javascript to be added.340 * @param string $position Optional. Whether to add the inline script before the handle341 * or after. Default 'after'.342 * @return bool True on success, false on failure.343 */344 /* public function wp_add_inline_script( $handle, $data, $position = 'after' ) {345 _wp_scripts_maybe_doing_it_wrong( __FUNCTION__ );346 347 if ( false !== stripos( $data, '</script>' ) ) {348 _doing_it_wrong( __FUNCTION__, sprintf(349 __( 'Do not pass %1$s tags to %2$s.' ),350 '<code><script></code>',351 '<code>wp_add_inline_script()</code>'352 ), '4.5.0' );353 $data = trim( preg_replace( '#<script[^>]*>(.*)</script>#is', '$1', $data ) );354 }355 356 return wp_scripts()->add_inline_script( $handle, $data, $position );357 }*/358 241 } -
siteattention/trunk/admin/js/siteattention-module.js
r2353656 r2353991 662 662 * 663 663 */ 664 getThreshold()665 {666 var threshold = 50;667 var url = SiteAttentionInfo.apiUrl+'/secure/init/'+this.getIId()+'/'+this.getPid()+'/'+this.getCMS()+'/'+this.cmslang;668 this.xhr.open("GET", url, true);669 this.xhr.setRequestHeader('x-siteattention', SiteAttentionInfo.key);670 this.xhr.onreadystatechange = function() {671 if ((this.readyState == 4 && (this.status == 200 || this.status == 201))) {672 var initResponse = jQuery.parseJSON(this.responseText);673 var threshold = initResponse.data_score_threshold;674 }675 }676 return threshold;677 }678 /**679 *680 */681 664 secureRules() 682 665 { … … 701 684 var rulesResponse = jQuery.parseJSON(this.responseText); 702 685 var scorePct = rulesResponse.score_pct; 703 var threshold = 70;686 var threshold = SiteAttentionInfo.siteattention_threshold_value; 704 687 var thresholdMarginLeft = threshold - 2; 705 688 if (scorePct > threshold || scorePct == threshold) { -
siteattention/trunk/includes/class-siteattention.php
r2353656 r2353991 72 72 } 73 73 74 public static function sendPluginEvent($type){75 global $wp_version;76 $options = get_option(self::NAME);77 78 return self::callApi('record',[79 'meta' => [80 'timestamp' => date('Y-m-d H:i:s'),81 'event' => 'plugin',82 'type' => $type,83 'key' => $options['key'],84 'instance' => $options['iid'],85 'guid' => $options['guid'],86 'browser' => 'WordPress/PHP' . phpversion(),87 'cms' => 'WordPress',88 'domain' => get_site_url()89 ],90 'data' => [91 'cmsVersion' => $wp_version,92 'saVersion' => self::VERSION93 ]94 ]);95 }96 97 public static function callApi($route,$body){98 99 //URL = https://test.siteattention.com/ $route = customer/instance/page/publish100 $response = wp_remote_post(self::URL.$route, array(101 'method' => 'POST',102 'body' => json_encode($body),103 'timeout' => 15,104 'headers' => array(105 'Content-Type' => 'application/json',106 'X-SiteAttention' => siteattention_get_option('license_key', siteattention_get_option('key', '')),107 'Referer' => get_site_url() . '/siteattention-wordpress'108 )109 ));110 111 if (is_wp_error($response))112 {113 return false;114 }115 116 else117 {118 return json_decode($response['body'],true);119 }120 }121 122 123 public static function write_log( $log ){124 $content = "SiteAttention:\n";125 126 if ( is_array( $log ) || is_object( $log ) )127 {128 $content .= var_export( $log, true );129 }130 131 else132 {133 $content .= $log;134 }135 136 error_log ( $content );137 }138 139 140 74 public function run() { 141 75 $this->loader->run(); … … 190 124 $plugin_admin = new SiteAttention_Admin( self::NAME , self::VERSION ); 191 125 192 //Add metabox in post and pages193 //$this->loader->add_action('add_meta_boxes', $plugin_admin, 'siteattention_custom_metabox');194 195 126 // Add the SiteAttention styles and scripts 196 127 $this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_styles' ); … … 206 137 $this->loader->add_filter( 'plugin_action_links_siteattention/siteattention.php', $plugin_admin, 'add_settings_link' , 10 , 1 ); 207 138 208 // Syncronization hook with SiteAttention backend209 $this->loader->add_action( 'post_updated', $plugin_admin, 'admin_sync_post', 10, 3 );210 211 139 // SiteAttention settings endpoint 212 140 $this->loader->add_action( 'init', $plugin_admin, 'add_settings_route' ); 213 $this->loader->add_action( 'template_redirect', $plugin_admin, 'save_settings' );214 215 141 // Add Excerpt section to pages edit page 216 142 $this->loader->add_action( 'init', $plugin_admin, 'add_excerpt_to_pages' ); -
siteattention/trunk/includes/siteattention_seo_tool.php
r2353656 r2353991 9 9 if (empty($options['install'])) 10 10 { 11 $response = SiteAttention::sendPluginEvent('install');12 13 if14 (15 empty($options['guid']) &&16 !empty($response['data']['guid'])17 )18 {19 $options['guid'] = $response['data']['guid'];20 }21 22 11 $options['installed'] = true; 23 12 SiteAttention::saveOptions($options); 24 13 } 25 26 SiteAttention::sendPluginEvent('enable');27 14 } 28 15 29 16 30 17 function deactivate_siteattention() { 31 SiteAttention::sendPluginEvent('disable');32 18 flush_rewrite_rules(); 33 19 } 34 20 35 36 function update_siteattention() {37 SiteAttention::sendPluginEvent('update');38 }39 40 41 21 function uninstall_siteattention() { 42 SiteAttention::sendPluginEvent('uninstall');43 22 SiteAttention::resetOptions(true); 44 23 } 45 46 47 function action_upgrader_process_complete($upgrader,$options) {48 $siteattention = plugin_basename( __FILE__ );49 50 if51 (52 $options['type'] == 'plugin' &&53 $options['action'] == 'update' &&54 isset($options['plugins']) &&55 in_array($siteattention,$options['plugins'])56 )57 {58 update_siteattention();59 }60 }61 62 63 // register the hooks for activation, deactivation, install, upgrade, uninstall64 add_action( 'upgrader_process_complete', 'action_upgrader_process_complete', 20, 2 );65 register_activation_hook( __FILE__, 'activate_siteattention' );66 register_deactivation_hook( __FILE__, 'deactivate_siteattention' );67 register_uninstall_hook(__FILE__, 'uninstall_siteattention');68 24 69 25 /** … … 78 34 79 35 80 define ( 'SITEATTENTION_VERSION' , ' 2.0.0' );36 define ( 'SITEATTENTION_VERSION' , '3.0.0' ); 81 37 define ( 'SITEATTENTION_NAME' , 'SiteAttention' ); 82 38 define ( 'SITEATTENTION_URL' , SITEATTENTION_API_URL ); -
siteattention/trunk/siteattention.php
r2353656 r2353991 16 16 * Plugin Name: SiteAttention 17 17 * Description: Simple and intuitive SEO tool to help improve seach ranking. 18 * Version: 3.0. 018 * Version: 3.0.1 19 19 * Author: siteattention 20 20 * Author URI: https://siteattention.com … … 28 28 define('SITEATTENTION_DASH_URL', 'https://dashboard.siteattention.com'); 29 29 define('SITEATTENTION_PL_URL', rtrim(plugin_dir_url(__FILE__), '/')); 30 define('SITEATTENTION_THRESHOLD', 70); 30 31 define('SITEATTENTION_RENEW_URL', 'https://siteattention.com/products/getsiteattention'); 31 32 … … 561 562 require_once plugin_dir_path( __FILE__ ) . '/includes/siteattention_seo_tool.php'; 562 563 564 // register the hooks for activation, deactivation, install, uninstall 565 register_activation_hook( __FILE__, 'activate_siteattention' ); 566 register_deactivation_hook( __FILE__, 'deactivate_siteattention' ); 567 register_uninstall_hook(__FILE__, 'uninstall_siteattention');
Note: See TracChangeset
for help on using the changeset viewer.