Plugin Directory

Changeset 2478167


Ignore:
Timestamp:
02/20/2021 06:13:19 PM (5 years ago)
Author:
concertedaction
Message:

v1.3.0: Automatic Sync Updates and Logging

Location:
wp-action-network
Files:
2 edited
3 copied

Legend:

Unmodified
Added
Removed
  • wp-action-network/tags/1.3.0/actionnetwork.php

    r2477998 r2478167  
    22/*
    33 * @package ActionNetwork
    4  * @version 1.2.2
     4 * @version 1.3.0
    55 *
    66 * Plugin Name: Action Network
     
    99 * Text Domain: actionnetwork
    1010 * Domain Path: /languages
    11  * Version: 1.2.2
     11 * Version: 1.3.0
    1212 * License: GPLv3
    1313 * Author URI: http://concertedaction.consulting
     
    3434 */
    3535global $actionnetwork_version;
    36 $actionnetwork_version = '1.2.1';
     36$actionnetwork_version = '1.3.0';
    3737global $actionnetwork_db_version;
    3838$actionnetwork_db_version = '1.0.7';
     
    617617add_action( 'admin_menu', 'actionnetwork_admin_menu' );
    618618
     619
     620function create_sync_log(){
     621    global $wpdb;
     622
     623    $charset_collate = $wpdb->get_charset_collate();
     624    $table_name = $wpdb->prefix . 'actionnetwork_cron_log';
     625    $sql = "CREATE TABLE $table_name (
     626      id mediumint(9) NOT NULL AUTO_INCREMENT,
     627      time datetime DEFAULT '0000-00-00 00:00:00' NOT NULL,
     628      inserted text NOT NULL,
     629      updated text NOT NULL,
     630      new_only text NOT NULL,
     631      PRIMARY KEY  (id)
     632    ) $charset_collate;";
     633   
     634    require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
     635    dbDelta( $sql );
     636
     637    // $wpdb->insert(
     638    //  $table_name,
     639    //  array(
     640    //      'time' => current_time( 'mysql' )
     641    //  )
     642    // );
     643}
     644
     645function update_cron_log($inserted,$updated,$new_only){
     646    global $wpdb;
     647    $table_name = $wpdb->prefix . 'actionnetwork_cron_log';
     648    $wpdb->insert(
     649        $table_name,
     650        array(
     651            'time' => current_time( 'mysql' ),
     652            'inserted'=>$inserted,
     653            'updated'=>$updated,
     654            'new_only'=>$new_only
     655        )
     656    );
     657}
     658
     659
    619660/**
    620661 * Update sync daily via cron
    621662 */
    622663function actionnetwork_cron_sync() {
     664
     665    create_sync_log();
     666
    623667
    624668    // initiate a background process by making a call to the "ajax" URL
     
    636680        'queue_action' => 'init',
    637681        'token' => $token,
     682        'cron_func'=>1
    638683    );
    639684    $args = array( 'body' => $body, 'timeout' => 1 );
     
    653698    // check token
    654699    $token = isset($_REQUEST['token']) ? $_REQUEST['token'] : 'no token';
     700    $cron_func = isset($_REQUEST['cron_func']) ? $_REQUEST['cron_func'] : 0;
    655701    $stored_token = get_option( 'actionnetwork_ajax_token', '' );
    656702    if ($token != $stored_token) { wp_die(); }
     
    663709    $status = get_option( 'actionnetwork_queue_status', 'empty' );
    664710   
     711    if($cron_func==1){
     712        update_cron_log($inserted,$updated,$new_only);
     713    }
    665714    // error_log( "actionnetwork_process_queue called with the following _REQUEST args:\n\n" . print_r( $_REQUEST, 1) . "\n\nqueue_action: $queue_action\nstatus:$status\n\n", 0 );
    666715
     
    10071056                    $text_settings
    10081057                </a>
     1058                <a href="$admin_url#actionnetwork-cron-updates">Cron Updates</a>
    10091059            </h2>
    10101060           
     
    13591409                    <?php _e('Settings', 'actionnetwork'); ?>
    13601410                </a>
    1361 
     1411               
     1412                <a href="#actionnetwork-cron-updates" class="nav-tab<?php echo ($tab == 'cron-updates') ? ' nav-tab-active' : ''; ?>">Cron Updates</a>
     1413               
    13621414                <a href="#actionnetwork-about" class="nav-tab<?php echo ($tab == 'about') ? ' nav-tab-active' : ''; ?>">
    13631415                    <?php _e('About', 'actionnetwork'); ?>
     
    14711523           
    14721524            <?php /* options settings */ ?>
     1525            <div class="actionnetwork-admin-tab<?php echo ($tab == 'cron-updates') ? ' actionnetwork-admin-tab-active' : ''; ?>" id="actionnetwork-cron-updates">
     1526                    <h2>Cron Updates</h2>
     1527                    <?php global $wpdb;
     1528
     1529                    $table_name = $wpdb->prefix . "actionnetwork_cron_log";
     1530                    if($wpdb->get_var("SHOW TABLES LIKE '$table_name'") == $table_name):
     1531                        $user = $wpdb->get_results( "SELECT * FROM $table_name" );
     1532                        if(count($user)!=0):
     1533                    ?>
     1534                    <table cellpadding="10" border="1">
     1535                        <tr>
     1536                        <th>id</th>
     1537                        <th>time</th>
     1538                        <th>inserted</th>
     1539                        <th>updated</th>
     1540                        <th>new_only</th>
     1541                        </tr>
     1542                        <?php foreach ($user as $row){ ?>                       
     1543                        <tr>
     1544                            <th><label for="gender"><?php echo $row->id ?></label></th>
     1545                            <td><?php echo $row->time ?></td>
     1546                            <td><?php echo $row->inserted ?></td>
     1547                            <td><?php echo $row->updated ?></td>
     1548                            <td><?php echo $row->new_only ?></td>
     1549                        </tr>
     1550                        <?php } ?>                 
     1551                    </table>
     1552                    <?php
     1553                    else:
     1554                        echo '<h3>No Logs</h3>';
     1555                    endif; 
     1556                else:
     1557                        echo '<h3>No Logs</h3>';   
     1558                    endif;
     1559                    ?>
     1560            </div>
    14731561            <div class="actionnetwork-admin-tab<?php echo ($tab == 'settings') ? ' actionnetwork-admin-tab-active' : ''; ?>" id="actionnetwork-settings">
    14741562                <h2><?php _e('Plugin Settings', 'actionnetwork'); ?></h2>
     
    17371825
    17381826}
     1827
     1828function actionnetwork_register_blocks() {
     1829
     1830    // Check if Gutenberg is active.
     1831    if ( ! function_exists( 'register_block_type' ) ) {
     1832        return;
     1833    }
     1834
     1835    // Add block script.
     1836    wp_register_script(
     1837        'embed-action-network',
     1838        plugins_url( 'blocks/block.js', __FILE__ ),
     1839        [ 'wp-blocks', 'wp-element', 'wp-editor' ],
     1840        filemtime( plugin_dir_path( __FILE__ ) . 'blocks/block.js' )
     1841    );
     1842
     1843    // Add block style.
     1844    wp_register_style(
     1845        'embed-action-network',
     1846        plugins_url( 'blocks/block.css', __FILE__ ),
     1847        [],
     1848        filemtime( plugin_dir_path( __FILE__ ) . 'blocks/block.css' )
     1849    );
     1850
     1851    wp_localize_script('embed-action-network', 'WPURLS', array( 'siteurl' => get_option('siteurl') ));
     1852
     1853    // Register block script and style.
     1854    register_block_type( 'actionnetwork/embed-action-network', [
     1855        'style' => 'embed-action-network', // Loads both on editor and frontend.
     1856        'editor_script' => 'embed-action-network', // Loads only on editor.
     1857    ] );
     1858}
     1859
     1860add_action( 'init', 'actionnetwork_register_blocks' );
     1861
     1862add_action( 'wp_ajax_nopriv_getActionNetworks', 'get_action_networks' );
     1863add_action( 'wp_ajax_getActionNetworks', 'get_action_networks' );
     1864
     1865if ( ! function_exists( 'get_action_networks' ) ) {
     1866    function get_action_networks() {
     1867        global $wpdb;
     1868
     1869        $results        = $wpdb->get_results ( "SELECT * FROM {$wpdb->prefix}actionnetwork WHERE enabled = '1'" );
     1870        $results_array  = array();
     1871
     1872        if( !empty($results) ){
     1873            foreach( $results as $result ){
     1874                $results_array[] = array(
     1875                    'id'    =>  $result->wp_id,
     1876                    'title' =>  $result->title
     1877                );
     1878            }
     1879        }
     1880
     1881        $result = json_encode( $results_array );
     1882
     1883        echo $result;
     1884        wp_die();
     1885    }
     1886}
  • wp-action-network/tags/1.3.0/readme.txt

    r2477998 r2478167  
    44Requires at least: 4.6
    55Tested up to: 5.6.1
    6 Stable tag: 1.2.2
     6Stable tag: 1.3.0
    77License: GPLv3 or later
    88License URI: https://www.gnu.org/licenses/gpl.html
     
    4444== Changelog ==
    4545
     46= 1.3.0 =
     47
     48* Updated automatic syncing of data from Action Network.
     49* Added record of sync results.
     50
    4651= 1.2.2 =
    47 Revert of SVN issue.
     52
     53* Revert of SVN issue.
    4854
    4955= 1.2.1 =
  • wp-action-network/trunk/actionnetwork.php

    r2477998 r2478167  
    22/*
    33 * @package ActionNetwork
    4  * @version 1.2.2
     4 * @version 1.3.0
    55 *
    66 * Plugin Name: Action Network
     
    99 * Text Domain: actionnetwork
    1010 * Domain Path: /languages
    11  * Version: 1.2.2
     11 * Version: 1.3.0
    1212 * License: GPLv3
    1313 * Author URI: http://concertedaction.consulting
     
    3434 */
    3535global $actionnetwork_version;
    36 $actionnetwork_version = '1.2.1';
     36$actionnetwork_version = '1.3.0';
    3737global $actionnetwork_db_version;
    3838$actionnetwork_db_version = '1.0.7';
     
    617617add_action( 'admin_menu', 'actionnetwork_admin_menu' );
    618618
     619
     620function create_sync_log(){
     621    global $wpdb;
     622
     623    $charset_collate = $wpdb->get_charset_collate();
     624    $table_name = $wpdb->prefix . 'actionnetwork_cron_log';
     625    $sql = "CREATE TABLE $table_name (
     626      id mediumint(9) NOT NULL AUTO_INCREMENT,
     627      time datetime DEFAULT '0000-00-00 00:00:00' NOT NULL,
     628      inserted text NOT NULL,
     629      updated text NOT NULL,
     630      new_only text NOT NULL,
     631      PRIMARY KEY  (id)
     632    ) $charset_collate;";
     633   
     634    require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
     635    dbDelta( $sql );
     636
     637    // $wpdb->insert(
     638    //  $table_name,
     639    //  array(
     640    //      'time' => current_time( 'mysql' )
     641    //  )
     642    // );
     643}
     644
     645function update_cron_log($inserted,$updated,$new_only){
     646    global $wpdb;
     647    $table_name = $wpdb->prefix . 'actionnetwork_cron_log';
     648    $wpdb->insert(
     649        $table_name,
     650        array(
     651            'time' => current_time( 'mysql' ),
     652            'inserted'=>$inserted,
     653            'updated'=>$updated,
     654            'new_only'=>$new_only
     655        )
     656    );
     657}
     658
     659
    619660/**
    620661 * Update sync daily via cron
    621662 */
    622663function actionnetwork_cron_sync() {
     664
     665    create_sync_log();
     666
    623667
    624668    // initiate a background process by making a call to the "ajax" URL
     
    636680        'queue_action' => 'init',
    637681        'token' => $token,
     682        'cron_func'=>1
    638683    );
    639684    $args = array( 'body' => $body, 'timeout' => 1 );
     
    653698    // check token
    654699    $token = isset($_REQUEST['token']) ? $_REQUEST['token'] : 'no token';
     700    $cron_func = isset($_REQUEST['cron_func']) ? $_REQUEST['cron_func'] : 0;
    655701    $stored_token = get_option( 'actionnetwork_ajax_token', '' );
    656702    if ($token != $stored_token) { wp_die(); }
     
    663709    $status = get_option( 'actionnetwork_queue_status', 'empty' );
    664710   
     711    if($cron_func==1){
     712        update_cron_log($inserted,$updated,$new_only);
     713    }
    665714    // error_log( "actionnetwork_process_queue called with the following _REQUEST args:\n\n" . print_r( $_REQUEST, 1) . "\n\nqueue_action: $queue_action\nstatus:$status\n\n", 0 );
    666715
     
    10071056                    $text_settings
    10081057                </a>
     1058                <a href="$admin_url#actionnetwork-cron-updates">Cron Updates</a>
    10091059            </h2>
    10101060           
     
    13591409                    <?php _e('Settings', 'actionnetwork'); ?>
    13601410                </a>
    1361 
     1411               
     1412                <a href="#actionnetwork-cron-updates" class="nav-tab<?php echo ($tab == 'cron-updates') ? ' nav-tab-active' : ''; ?>">Cron Updates</a>
     1413               
    13621414                <a href="#actionnetwork-about" class="nav-tab<?php echo ($tab == 'about') ? ' nav-tab-active' : ''; ?>">
    13631415                    <?php _e('About', 'actionnetwork'); ?>
     
    14711523           
    14721524            <?php /* options settings */ ?>
     1525            <div class="actionnetwork-admin-tab<?php echo ($tab == 'cron-updates') ? ' actionnetwork-admin-tab-active' : ''; ?>" id="actionnetwork-cron-updates">
     1526                    <h2>Cron Updates</h2>
     1527                    <?php global $wpdb;
     1528
     1529                    $table_name = $wpdb->prefix . "actionnetwork_cron_log";
     1530                    if($wpdb->get_var("SHOW TABLES LIKE '$table_name'") == $table_name):
     1531                        $user = $wpdb->get_results( "SELECT * FROM $table_name" );
     1532                        if(count($user)!=0):
     1533                    ?>
     1534                    <table cellpadding="10" border="1">
     1535                        <tr>
     1536                        <th>id</th>
     1537                        <th>time</th>
     1538                        <th>inserted</th>
     1539                        <th>updated</th>
     1540                        <th>new_only</th>
     1541                        </tr>
     1542                        <?php foreach ($user as $row){ ?>                       
     1543                        <tr>
     1544                            <th><label for="gender"><?php echo $row->id ?></label></th>
     1545                            <td><?php echo $row->time ?></td>
     1546                            <td><?php echo $row->inserted ?></td>
     1547                            <td><?php echo $row->updated ?></td>
     1548                            <td><?php echo $row->new_only ?></td>
     1549                        </tr>
     1550                        <?php } ?>                 
     1551                    </table>
     1552                    <?php
     1553                    else:
     1554                        echo '<h3>No Logs</h3>';
     1555                    endif; 
     1556                else:
     1557                        echo '<h3>No Logs</h3>';   
     1558                    endif;
     1559                    ?>
     1560            </div>
    14731561            <div class="actionnetwork-admin-tab<?php echo ($tab == 'settings') ? ' actionnetwork-admin-tab-active' : ''; ?>" id="actionnetwork-settings">
    14741562                <h2><?php _e('Plugin Settings', 'actionnetwork'); ?></h2>
     
    17371825
    17381826}
     1827
     1828function actionnetwork_register_blocks() {
     1829
     1830    // Check if Gutenberg is active.
     1831    if ( ! function_exists( 'register_block_type' ) ) {
     1832        return;
     1833    }
     1834
     1835    // Add block script.
     1836    wp_register_script(
     1837        'embed-action-network',
     1838        plugins_url( 'blocks/block.js', __FILE__ ),
     1839        [ 'wp-blocks', 'wp-element', 'wp-editor' ],
     1840        filemtime( plugin_dir_path( __FILE__ ) . 'blocks/block.js' )
     1841    );
     1842
     1843    // Add block style.
     1844    wp_register_style(
     1845        'embed-action-network',
     1846        plugins_url( 'blocks/block.css', __FILE__ ),
     1847        [],
     1848        filemtime( plugin_dir_path( __FILE__ ) . 'blocks/block.css' )
     1849    );
     1850
     1851    wp_localize_script('embed-action-network', 'WPURLS', array( 'siteurl' => get_option('siteurl') ));
     1852
     1853    // Register block script and style.
     1854    register_block_type( 'actionnetwork/embed-action-network', [
     1855        'style' => 'embed-action-network', // Loads both on editor and frontend.
     1856        'editor_script' => 'embed-action-network', // Loads only on editor.
     1857    ] );
     1858}
     1859
     1860add_action( 'init', 'actionnetwork_register_blocks' );
     1861
     1862add_action( 'wp_ajax_nopriv_getActionNetworks', 'get_action_networks' );
     1863add_action( 'wp_ajax_getActionNetworks', 'get_action_networks' );
     1864
     1865if ( ! function_exists( 'get_action_networks' ) ) {
     1866    function get_action_networks() {
     1867        global $wpdb;
     1868
     1869        $results        = $wpdb->get_results ( "SELECT * FROM {$wpdb->prefix}actionnetwork WHERE enabled = '1'" );
     1870        $results_array  = array();
     1871
     1872        if( !empty($results) ){
     1873            foreach( $results as $result ){
     1874                $results_array[] = array(
     1875                    'id'    =>  $result->wp_id,
     1876                    'title' =>  $result->title
     1877                );
     1878            }
     1879        }
     1880
     1881        $result = json_encode( $results_array );
     1882
     1883        echo $result;
     1884        wp_die();
     1885    }
     1886}
  • wp-action-network/trunk/readme.txt

    r2477998 r2478167  
    44Requires at least: 4.6
    55Tested up to: 5.6.1
    6 Stable tag: 1.2.2
     6Stable tag: 1.3.0
    77License: GPLv3 or later
    88License URI: https://www.gnu.org/licenses/gpl.html
     
    4444== Changelog ==
    4545
     46= 1.3.0 =
     47
     48* Updated automatic syncing of data from Action Network.
     49* Added record of sync results.
     50
    4651= 1.2.2 =
    47 Revert of SVN issue.
     52
     53* Revert of SVN issue.
    4854
    4955= 1.2.1 =
Note: See TracChangeset for help on using the changeset viewer.