Plugin Directory

Changeset 1311664


Ignore:
Timestamp:
12/18/2015 02:16:15 PM (10 years ago)
Author:
Pixelwelt
Message:

notification service added and global setting for ab testing sample size

Location:
octavius-rocks/trunk
Files:
1 added
7 edited

Legend:

Unmodified
Added
Removed
  • octavius-rocks/trunk/admin/class-octavius-ajax.php

    r1246523 r1311664  
    7272        wp_send_json(array('success' => true, "result" => $result));
    7373    }
    74    
     74
    7575    public function get_ab_posts_not_chosen(){
    7676        $post_ids = array();
    77                
     77
    7878        //get all posts that have no chosen variant
    7979        $args = array(
    80             'meta_query' => array(
    81                 array(
    82                  'key' => '_octavius_rocks_variant',
    83                  'compare' => 'NOT EXISTS'
    84                 ),
    85             )
    86         );
     80      'posts_per_page' => -1,
     81      'date_query' => array( //this is the date when rendering was tracked
     82            array(
     83                'after'    => array(
     84                    'year'  => 2015,
     85                    'month' => 10,
     86                    'day' => 9
     87                ),
     88                'inclusive' => true,
     89            ),
     90        ),
     91        'meta_query' => array(
     92        array(
     93         'key' => '_octavius_rocks_variant',
     94         'compare' => 'NOT EXISTS'
     95        ),
     96        'post_type' => 'post',
     97        'post_status' => 'publish',
     98        )
     99    );
    87100        // The Query
    88101        $the_query = new WP_Query( $args );
     
    96109        /* Restore original Post Data */
    97110        wp_reset_postdata();
    98        
     111
    99112        wp_send_json($post_ids);
    100113    }
     
    148161                }
    149162            }
    150            
     163
    151164        }
    152165        wp_send_json(array('success' => true, "result" => $result));
     
    163176        }
    164177        /**
    165          * save or delete post meta 
     178         * save or delete post meta
    166179         */
    167180        $pid = intval($_POST["pid"]);
     
    169182        $success = $this->variants->set_variant($pid, $slug);
    170183        /**
    171          * 
     184         *
    172185         */
    173186        wp_send_json(array('success' => $success, "result" => array($pid,$slug)));
  • octavius-rocks/trunk/admin/class-octavius-client-settings.php

    r1281156 r1311664  
    5959     */
    6060    private function render_server_settings(){
    61         // TODO tab for server settings
     61        //tab for server settings
    6262        $api_key_id = "ph_octavius_api_key";
    6363        $server_id = "ph_octavius_server";
     
    122122            $this->variants->save($values);
    123123        }
     124        $sample_size_key = 'octavius_rocks_sample_size';
     125        if(isset($_POST[$sample_size_key])){
     126            update_option($sample_size_key, intval($_POST[$sample_size_key]) );
     127        }
     128        $ab_email_key = 'octavius_rocks_ab_email';
     129        if(isset($_POST[$ab_email_key])){
     130            update_option($ab_email_key, trim($_POST[$ab_email_key]) );
     131        }
    124132        /**
    125133         * render settings page
     
    127135        $ab_enabled = $this->variants->enabled();
    128136        $all = $this->variants->get();
     137        $ab_email = get_option($ab_email_key, '');
     138        $sample_size = get_option($sample_size_key, '');
    129139        require dirname(__FILE__)."/partials/octavius-settings-ab.php";
    130140    }
  • octavius-rocks/trunk/admin/js/octavius-dashboard.js

    r1281237 r1311664  
    1818        var oc = null;
    1919
    20         var theDate = new Date('09-10-2015');//daten when rendered was tracked on zett TODO
    21 
    2220        this.init = function(octavius){
    2321            oc = octavius;
     
    3432             */
    3533            socket.on('update_ab_top_reports', function(data){
     34            console.log(data);
    3635                if(data.error){ //if no results found
    3736                    $results_ab.empty();
     
    5049                    ids_map[content_id] = result;
    5150
     51                }
     52                if(content_ids.length < 1){
     53                $results_ab.empty();
     54                    $loading_ab.css("visibility", "hidden");
     55                $results_ab.append("<tr><td colspan='3'>Derzeit sind keine Testergebnisse verfügbar.</td></tr>");
     56                return;
    5257                }
    5358                // get infos from wordpress instance
     
    6166                        $loading_ab.css("visibility", "hidden");
    6267                        var countListItems = 0;
     68                        if(!_data.success){
     69                            $results_ab.append("<tr><td colspan='3'>Fehler: Die Beitrags-IDs konnten nicht zugeordnet werden.</td></tr>");
     70                            return;
     71                        };
    6372                        for( var i = 0; i < _data.result.length; i++){
    6473                            var result = _data.result[i];
    65                             var releaseDate = new Date(result.date);
    66                             if(theDate > releaseDate) continue; //cannot calculate signigicance for old posts
    6774                            var ob = ids_map[result.content_id];
    6875                            if(ob.significance.error) continue; //hide results with not calculatable significance
  • octavius-rocks/trunk/admin/partials/octavius-dashboard-ab.php

    r1281223 r1311664  
    1 <input type="hidden" id="octavius-rocks-ab-limit" value="<?php echo $limit; ?>" />
     1<input type="hidden" id="octavius-rocks-ab-limit" value="<?php echo get_option('octavius_rocks_sample_size', 500); ?>" />
    22<div id="octavius-rocks-ab-button-template" style="visibility: hidden"><?php echo submit_button(__("Use variant"), "small"); ?></div>
    33<table class="wp-list-table widefat fixed striped">
  • octavius-rocks/trunk/admin/partials/octavius-settings-ab.php

    r1236313 r1311664  
    11<form method="post" action="<?php echo $_SERVER["PHP_SELF"]; ?>?page=octavius-rocks&amp;tab=ab">
    2    
     2
    33    <h2>Settings</h2>
    44    <table class="form-table">
     
    99                    <td><input type="checkbox" id="octavius_rocks_ab_enabled" value="1"
    1010                    <?php if($ab_enabled) echo "checked='checked'"; ?>
    11                     name="octavius_rocks_ab_enabled"> <?php 
     11                    name="octavius_rocks_ab_enabled"> <?php
    1212                    if($ab_enabled) {
    13                         echo __("Enabled"); 
     13                        echo __("Enabled");
    1414                    } else {
    1515                        echo __("Disabled");
     
    2020        </tbody>
    2121    </table>
    22    
     22
    2323    <h2>Variants</h2>
    2424    <?php
     
    5454        </tbody>
    5555    </table>
     56
     57    <h2>Testgröße</h2>
     58    <table class="form-table">
     59        <tbody>
     60            <tr>
     61                <td scope="row"><input class="form-text" name="octavius_rocks_sample_size" type="text" value="<?php echo $sample_size; ?>"><br>
     62                <small><?php echo __("Mindestanzahl Klicks insgesamt (Default 500)."); ?></small>
     63                </td>
     64            </tr>
     65        </tbody>
     66    </table>
     67
     68    <h2>Notifications</h2>
     69    <table class="form-table">
     70        <tbody>
     71            <tr>
     72                <td scope="row"><?php echo __("Send Notifications to:"); ?> <input class="form-text" name="octavius_rocks_ab_email" type="text" value="<?php echo $ab_email; ?>"><br/>
     73                <small><?php echo __("Leave empty for no notification. (Please notify your admin to enable the cronjob for notifications.) "); ?></small>
     74                </td>
     75            </tr>
     76        </tbody>
     77    </table>
     78
    5679    <?php
    5780    else:
     
    5982    <p><?php echo __("Enable A/B Tests to see more options"); ?></p>
    6083    <?php
    61     endif; 
     84    endif;
    6285    ?>
    63    
     86
     87
     88
    6489
    6590    <?php submit_button("Save"); ?>
  • octavius-rocks/trunk/octavius-client.php

    r1281237 r1311664  
    2323
    2424/**
    25  * The code that runs during plugin activation.
    26  * This action is documented in includes/class-octavius-client-activator.php
     25 * Dirty hack
     26 * by jk because zett #152
    2727 */
    28 function activate_octavius_client() {
    29     require_once plugin_dir_path( __FILE__ ) . 'includes/class-octavius-client-activator.php';
    30     Octavius_Client_Activator::activate();
     28function analyze_ab_results(){
     29  //check if email can be sent
     30  $email = get_option('octavius_rocks_ab_email', '');
     31  if(!isset($email) || $email == null || $email == "" || !filter_var($email, FILTER_VALIDATE_EMAIL)){
     32    return;
     33  }
     34
     35  $content_ids = join(',', get_posts_with_not_chosen_variant());
     36  $limit = get_option('octavius_rocks_sample_size', 500);
     37  $api_key = get_option('ph_octavius_api_key');
     38  //send request to server
     39  $resp = json_decode(file_get_contents(get_option('ph_octavius_server', '')."/json/".$api_key."/ab_top_reports/".$limit."/".$content_ids));
     40  $results = $resp->result;
     41
     42  //write mail
     43  $text = "<html><head><title>Neue Octavius Ergebnisse</title></head><body>Hallo,<br><br>"."es gibt signifikante Testergebnisse für folgende Artikel: <br>";
     44
     45  $num_results = 0;
     46  foreach($results as $result){
     47    if(!isset($result->significance->error)) {
     48      $text .= "<a href='".get_the_permalink($result->content_id)."'>".get_the_title($result->content_id)."</a><br>";
     49      $num_results++;
     50    }
     51  }
     52
     53  //check if there are results to be sent
     54  if($num_results < 1){
     55    return;
     56  }
     57
     58  $text .= "<br>Besuche das <a href='ze.tt/wp-admin/'>ze.tt-Dashboard</a> um die Variante festzulegen. <br><br>"."Viele Grüße,<br>"."<em>Octavius</em></body></html>";
     59
     60  $headers = 'From: Octavius <no-response@octavius.rocks>' . PHP_EOL .
     61    'X-Mailer: PHP/' . phpversion() .
     62    'MIME-Version: 1.0' . "\r\n" .
     63    'Content-type: text/html; charset=iso-8859-1' . "\r\n";
     64
     65  mail($email, 'Neue Octavius Ergebnisse', $text, $headers);
    3166}
     67/**
     68 * duplicate from admin_ajax class
     69 * by jk because zett #152
     70 */
     71function get_posts_with_not_chosen_variant(){
     72$post_ids = array();
    3273
    33 /**
    34  * The code that runs during plugin deactivation.
    35  * This action is documented in includes/class-octavius-client-deactivator.php
    36  */
    37 function deactivate_octavius_client() {
    38     require_once plugin_dir_path( __FILE__ ) . 'includes/class-octavius-client-deactivator.php';
    39     Octavius_Client_Deactivator::deactivate();
     74//get all posts that have no chosen variant
     75$args = array(
     76  'posts_per_page' => -1,
     77  'date_query' => array(
     78        array(
     79            'after'    => array(
     80                'year'   => 2015,
     81                'month'  => 10,
     82                'day'    => 9
     83            ),
     84            'inclusive' => true,
     85        ),
     86    ),
     87    'meta_query' => array(
     88    array(
     89     'key' => '_octavius_rocks_variant',
     90     'compare' => 'NOT EXISTS'
     91    ),
     92    'post_type' => 'post',
     93    'post_status' => 'publish',
     94    )
     95);
     96// The Query
     97$the_query = new WP_Query( $args );
     98// The Loop
     99if ( $the_query->have_posts() ) {
     100    while ( $the_query->have_posts() ) {
     101        $the_query->the_post();
     102        array_push($post_ids, get_the_ID());
     103    }
    40104}
     105/* Restore original Post Data */
     106wp_reset_postdata();
    41107
    42 register_activation_hook( __FILE__, 'activate_octavius_client' );
    43 register_deactivation_hook( __FILE__, 'deactivate_octavius_client' );
     108return $post_ids;
     109
     110}
    44111
    45112/**
  • octavius-rocks/trunk/readme.txt

    r1281237 r1311664  
    55Requires at least: 4.0
    66Tested up to: 4.3
    7 Stable tag: 1.3.9
     7Stable tag: 1.3.10
    88License: GPLv2 or later
    99License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    3333
    3434== Changelog ==
     35
     36= 1.3.10 =
     37 * Added functionality for notification service and global sample size setting.
    3538
    3639= 1.3.9 =
Note: See TracChangeset for help on using the changeset viewer.