Plugin Directory

Changeset 2353991


Ignore:
Timestamp:
08/06/2020 01:44:41 PM (5 years ago)
Author:
siteattention
Message:

rewrite major update plugin in version 3.0.1

Location:
siteattention/trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • siteattention/trunk/README.txt

    r2353656 r2353991  
    66Requires at least: 4.8
    77Tested up to: 5.4
    8 Stable tag: 3.0.0
     8Stable tag: 3.0.1
    99License: GPLv2 or later
    1010License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    7777
    7878* 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 visibile 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.
    8080* 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
    8190
    8291== Upgrade Notice ==
     
    94103* Major rewrite of the plugin and redesign of plugin
    95104* 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  
    126126
    127127        $current_user = wp_get_current_user();
     128        $instance_id = siteattention_get_option('iid', '');
     129        $getThreshold = $this->getThreshold($instance_id);
    128130        wp_localize_script($this->name, 'SiteAttentionInfo', [
    129131            'user' => $current_user->ID,
     
    132134            'key' => siteattention_get_option('license_key', ''),
    133135            'post_type' => get_current_screen()->id,
    134             'iid' => siteattention_get_option('iid', ''),
     136            'iid' => $instance_id,
    135137            'url' => get_permalink(),
    136138            'site_url' => site_url(),
     
    138140            'published' => get_post_status() === 'publish',
    139141            'apiUrl' => SiteAttention::URL,
     142            'siteattention_threshold_value' => $getThreshold,
    140143        ]);
    141144        // Above - JS code for displaying the UI Toolbar on edit pages.
     
    143146    }
    144147
    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    }
    162174
    163175    /**
     
    187199
    188200    /**
    189      * Callback function for the admin settings page.
    190      *
    191      * @since    1.0.0
    192      */
    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             true
    203         );
    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 server
    241      * @param  int $post_ID     id of post or page being synced
    242      * @param  object $post_after  post or page object after update
    243      * @param  object $post_before post or page object before update
    244      * @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 options
    264      * @return [type] [description]
    265      */
    266     public function save_settings() {
    267         return;
    268         global $wp_query;//, $wpdb;
    269 
    270         if
    271         (   !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     /**
    285201     * Enables the Excerpt meta box in Page edit screen.
    286202     */
     
    323239        delete_post_meta($_POST['post_id'],'page_keyword', $_POST['page_keyword']);
    324240    }
    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 blocks
    331       * are added to the same script $handle, they will be printed in the order
    332       * they were added, i.e. the latter added code can redeclare the previous.
    333       *
    334       * @since 4.5.0
    335       *
    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 handle
    341       *                         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>&lt;script&gt;</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     }*/
    358241}
  • siteattention/trunk/admin/js/siteattention-module.js

    r2353656 r2353991  
    662662         *
    663663         */
    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          */
    681664        secureRules()
    682665        {
     
    701684                    var rulesResponse = jQuery.parseJSON(this.responseText);
    702685                    var scorePct = rulesResponse.score_pct;
    703                     var threshold = 70;
     686                    var threshold = SiteAttentionInfo.siteattention_threshold_value;
    704687                    var thresholdMarginLeft = threshold - 2;
    705688                    if (scorePct > threshold || scorePct == threshold) {
  • siteattention/trunk/includes/class-siteattention.php

    r2353656 r2353991  
    7272    }
    7373
    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::VERSION
    93             ]
    94         ]);
    95     }
    96 
    97     public static function callApi($route,$body){
    98 
    99         //URL = https://test.siteattention.com/ $route = customer/instance/page/publish
    100         $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         else
    117         {
    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         else
    132         {
    133             $content .= $log;
    134         }
    135 
    136         error_log ( $content );
    137     }
    138 
    139 
    14074    public function run() {
    14175        $this->loader->run();
     
    190124        $plugin_admin = new SiteAttention_Admin( self::NAME , self::VERSION );
    191125
    192         //Add metabox in post and pages
    193         //$this->loader->add_action('add_meta_boxes', $plugin_admin, 'siteattention_custom_metabox');
    194 
    195126        // Add the SiteAttention styles and scripts
    196127        $this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_styles' );
     
    206137        $this->loader->add_filter( 'plugin_action_links_siteattention/siteattention.php', $plugin_admin, 'add_settings_link' , 10 , 1 );
    207138
    208         // Syncronization hook with SiteAttention backend
    209         $this->loader->add_action( 'post_updated', $plugin_admin, 'admin_sync_post', 10, 3 );
    210 
    211139        // SiteAttention settings endpoint
    212140        $this->loader->add_action( 'init', $plugin_admin, 'add_settings_route' );
    213         $this->loader->add_action( 'template_redirect', $plugin_admin, 'save_settings' );
    214 
    215141        // Add Excerpt section to pages edit page
    216142        $this->loader->add_action( 'init', $plugin_admin, 'add_excerpt_to_pages' );
  • siteattention/trunk/includes/siteattention_seo_tool.php

    r2353656 r2353991  
    99    if (empty($options['install']))
    1010    {
    11         $response = SiteAttention::sendPluginEvent('install');
    12 
    13         if
    14         (
    15             empty($options['guid']) &&
    16             !empty($response['data']['guid'])
    17         )
    18         {
    19             $options['guid'] = $response['data']['guid'];
    20         }
    21 
    2211        $options['installed'] = true;
    2312        SiteAttention::saveOptions($options);
    2413    }
    25 
    26     SiteAttention::sendPluginEvent('enable');
    2714}
    2815
    2916
    3017function deactivate_siteattention() {
    31     SiteAttention::sendPluginEvent('disable');
    3218    flush_rewrite_rules();
    3319}
    3420
    35 
    36 function update_siteattention() {
    37     SiteAttention::sendPluginEvent('update');
    38 }
    39 
    40 
    4121function uninstall_siteattention() {
    42     SiteAttention::sendPluginEvent('uninstall');
    4322    SiteAttention::resetOptions(true);
    4423}
    45 
    46 
    47 function action_upgrader_process_complete($upgrader,$options) {
    48     $siteattention = plugin_basename( __FILE__ );
    49 
    50     if
    51     (
    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, uninstall
    64 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');
    6824
    6925/**
     
    7834
    7935
    80 define ( 'SITEATTENTION_VERSION' , '2.0.0' );
     36define ( 'SITEATTENTION_VERSION' , '3.0.0' );
    8137define ( 'SITEATTENTION_NAME' , 'SiteAttention' );
    8238define ( 'SITEATTENTION_URL' , SITEATTENTION_API_URL );
  • siteattention/trunk/siteattention.php

    r2353656 r2353991  
    1616 * Plugin Name:       SiteAttention
    1717 * Description:       Simple and intuitive SEO tool to help improve seach ranking.
    18  * Version:           3.0.0
     18 * Version:           3.0.1
    1919 * Author:            siteattention
    2020 * Author URI:        https://siteattention.com
     
    2828define('SITEATTENTION_DASH_URL', 'https://dashboard.siteattention.com');
    2929define('SITEATTENTION_PL_URL', rtrim(plugin_dir_url(__FILE__), '/'));
     30define('SITEATTENTION_THRESHOLD', 70);
    3031define('SITEATTENTION_RENEW_URL', 'https://siteattention.com/products/getsiteattention');
    3132
     
    561562require_once plugin_dir_path( __FILE__ ) . '/includes/siteattention_seo_tool.php';
    562563
     564// register the hooks for activation, deactivation, install, uninstall
     565register_activation_hook( __FILE__, 'activate_siteattention' );
     566register_deactivation_hook( __FILE__, 'deactivate_siteattention' );
     567register_uninstall_hook(__FILE__, 'uninstall_siteattention');
Note: See TracChangeset for help on using the changeset viewer.