Title: [211739] trunk/Websites/webkit.org
Revision
211739
Author
j...@apple.com
Date
2017-02-06 11:13:40 -0800 (Mon, 06 Feb 2017)

Log Message

Add a survey to learn how people use WebKit Nightly builds
https://bugs.webkit.org/show_bug.cgi?id=167748

Reviewed by Joseph Pecoraro.

* wp-content/themes/webkit/functions.php:
* wp-content/themes/webkit/nightly-start.php:
* wp-content/themes/webkit/nightly-survey.php: Added.
* wp-content/themes/webkit/survey.json: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/Websites/webkit.org/ChangeLog (211738 => 211739)


--- trunk/Websites/webkit.org/ChangeLog	2017-02-06 19:06:39 UTC (rev 211738)
+++ trunk/Websites/webkit.org/ChangeLog	2017-02-06 19:13:40 UTC (rev 211739)
@@ -1,3 +1,15 @@
+2017-02-06  Jon Davis  <j...@apple.com>
+
+        Add a survey to learn how people use WebKit Nightly builds
+        https://bugs.webkit.org/show_bug.cgi?id=167748
+
+        Reviewed by Joseph Pecoraro.
+
+        * wp-content/themes/webkit/functions.php:
+        * wp-content/themes/webkit/nightly-start.php:
+        * wp-content/themes/webkit/nightly-survey.php: Added.
+        * wp-content/themes/webkit/survey.json: Added.
+
 2017-01-28  Yoav Weiss  <y...@yoav.ws>
 
         Add Link Preload as an off-by-default experimental feature menu item.

Modified: trunk/Websites/webkit.org/wp-content/themes/webkit/functions.php (211738 => 211739)


--- trunk/Websites/webkit.org/wp-content/themes/webkit/functions.php	2017-02-06 19:06:39 UTC (rev 211738)
+++ trunk/Websites/webkit.org/wp-content/themes/webkit/functions.php	2017-02-06 19:13:40 UTC (rev 211739)
@@ -9,6 +9,11 @@
     register_nav_menu('sitemap', __( 'Site Map Page' ));
 } );
 
+add_action( 'wp_dashboard_setup', function () {
+    $SurveyWidget = new WebKit_Nightly_Survey();
+    $SurveyWidget->add_widget();
+});
+
 function modify_contact_methods($profile_fields) {
 
     // Add new fields
@@ -23,7 +28,7 @@
 function get_nightly_build ($type = 'builds') {
     if (!class_exists('SyncWebKitNightlyBuilds'))
         return false;
-    
+
     $WebKitBuilds = SyncWebKitNightlyBuilds::object();
     $build = $WebKitBuilds->latest($type);
     return $build;
@@ -36,7 +41,7 @@
 function get_nightly_archives ($limit) {
     if (!class_exists('SyncWebKitNightlyBuilds'))
         return array();
-    
+
     $WebKitBuilds = SyncWebKitNightlyBuilds::object();
     $builds = $WebKitBuilds->records('builds', $limit);
     return (array)$builds;
@@ -147,7 +152,7 @@
     // Transform Markdown
     $Markdown = WPCom_Markdown::get_instance();
     $foreword = wp_unslash( $Markdown->transform($foreword) );
-    
+
     $post->post_content = '<div class="foreword">' . $foreword . '</div>' . $content;
     $pages = array($post->post_content);
 });
@@ -423,4 +428,143 @@
         return self::$wp_query;
     }
 
+}
+
+class WebKit_Nightly_Survey {
+
+    const COOKIE_PREFIX = 'webkitnightlysurvey_';
+    const DATA_SETTING_NAME = 'webkit_nightly_survey_data';
+    const SURVEY_FILENAME = 'survey.json';
+
+    public function add_widget() {
+
+        wp_add_dashboard_widget(
+            'webkit_nightly_survey_results', // Widget slug
+            'WebKit Nightly Survey Results', // Title
+            array($this, 'display_widget')   // Display function
+        );
+
+        if (isset($_GET['wksurvey']) && $_GET['wksurvey'] == 'download')
+            $this->download() && exit;
+
+    }
+
+    public function display_widget() {
+        $data = ""
+        $styles = "
+            <style>
+            .survey_table .question {
+                text-align: left;
+            }
+            .survey_table .score {
+                font-size: 15px;
+                min-width: 30px;
+                text-align: right;
+                vertical-align: top;
+                padding-right: 10px;
+            }
+            .survey_table .others {
+                font-style: italic;
+            }
+            </style>
+        ";
+
+        $response_limit = 10;
+        $table = '';
+        foreach ($data as $question => $responses) {
+            $question_row = '<tr><th colspan="2" class="question">' . $question . '</th></tr>';
+            $response_rows = '';
+            arsort($responses);
+            $response_count = 0;
+            $total_responses = count($responses);
+            foreach ($responses as $response => $votes) {
+                $response_rows .= '<tr><td class="score">' . intval($votes) . '</td><td class="response">' . stripslashes($response) . '</td></tr>';
+                if ( ++$response_count >= $response_limit && $response_count < $total_responses) {
+                    $response_rows .= '<tr><td class="score others">' . intval($total_responses - $response_limit) . '</td><td class="response others">more "other" responses</td></tr>';
+                    break;
+                }
+            }
+            $table .= $question_row . $response_rows;
+        }
+        echo $styles;
+        echo '<table class="survey_table">' . $table . '</table>';
+        echo '<p class="textright"><a class="button button-primary" href="" . add_query_arg('wksurvey','download',admin_url()) . '">Download Results as CSV</a></p>';
+    }
+
+    private function download() {
+        $data = ""
+        $table = '';
+
+        header('Content-type: text/csv; charset=UTF-8');
+        header('Content-Disposition: attachment; filename="webkit_nightly_survey.csv"');
+        header('Content-Description: Delivered by webkit.org');
+        header('Cache-Control: maxage=1');
+        header('Pragma: public');
+
+        foreach ($data as $question => $responses) {
+            $question_row = 'Score,' . $question . "\n";
+            $response_rows = '';
+            arsort($responses);
+            foreach ($responses as $response => $votes) {
+                $response_rows .= intval($votes) . ',' . stripslashes($response) . "\n";
+            }
+            $table .= $question_row . $response_rows . "\n";
+        }
+        echo $table;
+
+        exit;
+    }
+
+    public function process() {
+        if ( empty($_POST) ) return;
+
+        if ( ! wp_verify_nonce($_POST['_nonce'], self::SURVEY_FILENAME) )
+            wp_die('Invalid WebKit Nightly Survey submission.');
+
+        $score = $data = ""
+        $Survey = self::survey();
+        foreach ($Survey as $id => $SurveyQuestion) {
+            if ( ! isset($score[ $SurveyQuestion->question ]) )
+                $score[ $SurveyQuestion->question ] = array();
+            $response = $_POST['questions'][ $id ];
+            $answer = empty($SurveyQuestion->responses[ $response ]) ? $response : $SurveyQuestion->responses[ $response ];
+            if ($answer == 'Other:')
+                $answer = $_POST['other'][ $id ];
+            $score[ $SurveyQuestion->question ][ $answer ]++;
+        }
+
+        if ($data ="" false) {
+            $deprecated = null;
+            $autoload = 'no';
+            add_option($option, $score, $deprecated, $autoload);
+        } else update_option($option, $score);
+
+        $httponly = false;
+        $secure = false;
+        setcookie(self::cookie_name(), 1, time() + YEAR_IN_SECONDS, '/', WP_HOST, $secure, $httponly );
+        $_COOKIE[ self::cookie_name() ] = 1;
+    }
+
+    public static function responded() {
+        return isset($_COOKIE[ self::cookie_name() ]);
+    }
+
+    private static function cookie_name() {
+        return self::COOKIE_PREFIX . COOKIEHASH;
+    }
+
+    public static function survey_file() {
+        return dirname(__FILE__) . '/' . self::SURVEY_FILENAME;
+    }
+
+    public static function form_nonce() {
+        return '<input type="hidden" name="_nonce" value="' . wp_create_nonce( self::SURVEY_FILENAME ) . '">';
+    }
+
+    public static function survey () {
+        $survey_json = file_get_contents(self::survey_file());
+        $Decoded = json_decode($survey_json);
+        return isset($Decoded->survey) ? $Decoded->survey : array();
+    }
+
 }
\ No newline at end of file

Modified: trunk/Websites/webkit.org/wp-content/themes/webkit/nightly-start.php (211738 => 211739)


--- trunk/Websites/webkit.org/wp-content/themes/webkit/nightly-start.php	2017-02-06 19:06:39 UTC (rev 211738)
+++ trunk/Websites/webkit.org/wp-content/themes/webkit/nightly-start.php	2017-02-06 19:13:40 UTC (rev 211739)
@@ -89,7 +89,7 @@
     width: calc(33.33% - 10px);
     border-radius: 0.3rem;
     padding: 1rem;
-    transition: opacity 300ms linear, background-color 500ms ease; /* ease-out-exponential */
+    transition: opacity 300ms linear, background-color 500ms ease, transform 300ms ease; /* ease-out-exponential */
     opacity: 0.5;
 }
 
@@ -96,6 +96,7 @@
 #nightly ul li:hover {
     background: rgba(255, 255, 255, 0.1);
     opacity: 1;
+    transform: scale(1.05);
 }
 
 #nightly ul li .icon {
@@ -137,6 +138,46 @@
     padding-left: 0;
 }
 
+#nightly h3 {
+    position: relative;
+    width: 100%;
+    background-color: #202020;
+    color: #ffffff;
+    border-radius: 0.3rem;
+    padding: 3rem;
+    font-weight: 500;
+    font-size: 3rem;
+    text-align: left;
+    box-sizing: border-box;
+    transition: opacity 300ms ease, transform 300ms ease;
+}
+
+#nightly h3:hover {
+    transform: scale(1.05);
+}
+
+#nightly h3 .icon {
+    width: 7rem;
+    margin: 0rem 2rem;
+    display: block;
+    float: left;
+}
+
+#nightly h3 > a {
+    text-decoration: none;
+    display: block;
+    position: absolute;
+    font-size: 0;
+    top: 0;
+    left: 0;
+    width: 100%;
+    height: 100%;
+    font-size: 0;
+    z-index: 1;
+}
+
+<?php if (WebKit_Nightly_Survey::responded()): ?>#nightly h3 { display: none; }<?php endif; ?>
+
 #icons-sprite {
     display: none;
 }

Added: trunk/Websites/webkit.org/wp-content/themes/webkit/nightly-survey.php (0 => 211739)


--- trunk/Websites/webkit.org/wp-content/themes/webkit/nightly-survey.php	                        (rev 0)
+++ trunk/Websites/webkit.org/wp-content/themes/webkit/nightly-survey.php	2017-02-06 19:13:40 UTC (rev 211739)
@@ -0,0 +1,190 @@
+<?php
+/**
+ * Template Name: Nightly Survey
+ **/
+
+$Survey = new WebKit_Nightly_Survey();
+$Survey->process();
+
+get_header();
+?>
+    <style>
+        body {
+            background: #333333;
+        }
+
+        header {
+            border-bottom-color: transparent;
+        }
+
+        #nightly {
+            margin: 6rem auto;
+            color: #ffffff;
+        }
+
+        #nightly h1 {
+            text-align: center;
+            margin-bottom: 3rem;
+            margin-top: 0;
+            color: #ffffff;
+            font-weight: 100;
+            font-size: 9rem;
+            line-height: 9rem;
+        }
+
+        #nightly .bodycopy > p:first-child {
+            color: #FFD15E;
+            font-size: 3rem;
+            line-height: 50vh;
+            font-weight: 200;
+            text-align: center;
+        }
+
+        
+        #nightly .bodycopy {
+            max-width: 64rem;
+        }
+
+        #nightly ul {
+            width: 100%;
+            margin-top: 3rem;
+            padding-left: 0;
+        }
+
+        #nightly ul li {
+            display: block;
+            margin: 0 3rem;
+            position: relative;
+            vertical-align: top;
+            box-sizing: border-box;
+            overflow: hidden;
+            min-height: 62px;
+            perspective: 500px;
+        }
+
+        #nightly input[type=text] {
+            display: inline-block;
+            vertical-align: baseline;
+            margin-left: 1rem;
+            margin-bottom: 0;
+            backface-visibility: hidden;
+            transform: rotateX( 90deg );
+            transition: transform 500ms ease;
+            visibility: hidden;
+        }
+
+        #nightly input[type=radio] {
+            margin-top: 0;
+            vertical-align: middle;
+            transition: opacity 500ms ease;
+        }
+
+        #nightly input[type=radio]:checked ~ input[type=text] {
+            transform: rotateX( 0deg );
+            visibility: visible;
+        }
+
+        #nightly input[type=radio]:checked,
+        #nightly input[type=radio]:checked + span {
+            opacity: 1;
+            color: #ffffff;
+        }
+
+        #nightly input[type=radio] + span {
+            color: #878787;
+            transition: color 500ms ease;
+        }
+
+        #nightly input[type=submit] {
+            padding: 1rem 3rem;
+        }
+
+        #nightly label {
+            box-sizing: border-box;
+            display: inline-block;
+            border-radius: 0.3rem;
+            padding: 1rem 3rem 1rem 5rem;
+            transition: background-color 500ms ease;
+            cursor: pointer;
+            text-indent: -2.4rem;
+        }
+
+        #nightly ul label:hover {
+            background: rgba(255, 255, 255, 0.1);
+            opacity: 1;
+        }
+
+        #nightly code {
+            background-color: rgba(242, 242, 242, 0.1);
+            border-color: rgba(230, 230, 230, 0.1);
+            color: #999999;
+        }
+
+        #nightly h5 {
+            text-align: center;
+            font-weight: normal;
+            font-size: 1.8rem;
+        }
+        
+        #nightly .pagination .page-numbers {
+            background-color: rgba(255, 255, 255, 0.1);
+            color: #ffffff;
+        }
+
+        #nightly .pagination .page-numbers:hover {
+            background-color: rgba(255, 255, 255, 1);
+            color: #08c;
+        }
+
+        hr {
+            border-color: #777777;
+        }
+
+        #footer-nav a {
+            color: #999999;
+        }
+
+    </style>
+
+    <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
+
+        <article class="page" id="nightly">
+            
+            <h1><?php the_title(); ?></h1>
+            
+            <div class="bodycopy">
+                <?php if (WebKit_Nightly_Survey::responded()): ?>
+                    <?php the_content(''); ?>
+                    <nav class="navigation pagination">
+                        <a href="" class="page-numbers next-post">Return<span>to the WebKit Start Page</span></a>
+                    </nav>
+                <?php else: ?>
+                <form name="webkit-nightly-survey" action="" method="POST">
+                <?php
+                echo WebKit_Nightly_Survey::form_nonce();
+                
+                $Survey = WebKit_Nightly_Survey::survey();
+                foreach ($Survey as $id => $SurveyQuestion) {
+                    echo "<h3>$SurveyQuestion->question</h3>";
+                    
+                    echo "<ul>";
+                    foreach ($SurveyQuestion->responses as $value => $response) {
+                        echo '<li><label><input type="radio" name="questions[' . $id . ']" value="' . $value . '" required> <span>' . $response . '</span>';
+                        if ($response == "Other:") {
+                            echo '<input type="text" name="other[' . $id . ']" maxlength="144">';
+                        }
+                        echo '</label></li>';
+                    }
+                    echo "</ul>";
+                }
+                ?>
+                <p class="alignright"><input type="submit" name="Submit" value="Submit" class="submit-button"></p>
+                </form>
+                <?php endif;?>
+            </div>
+            
+        </article>
+
+    <?php endwhile; endif; ?>
+
+<?php get_footer(); ?>
\ No newline at end of file

Added: trunk/Websites/webkit.org/wp-content/themes/webkit/survey.json (0 => 211739)


--- trunk/Websites/webkit.org/wp-content/themes/webkit/survey.json	                        (rev 0)
+++ trunk/Websites/webkit.org/wp-content/themes/webkit/survey.json	2017-02-06 19:13:40 UTC (rev 211739)
@@ -0,0 +1,33 @@
+{
+    "survey":[
+        {
+            "question":"How often do you use WebKit Nightly builds?",
+            "responses":[
+                "It’s my default browser",
+                "Once a day",
+                "Once or twice a week",
+                "Maybe once a month"
+            ]
+        },
+        {
+            "question":"How do you use WebKit Nightly builds?",
+            "responses":[
+                "Testing and verifying bugs or fixes for the WebKit team",
+                "Testing new features to provide feedback to the WebKit team",
+                "Finding new bugs in WebKit",
+                "Finding new features in WebKit",
+                "Other:"
+            ]
+        },
+        {
+            "question":"What type of development work do you do?",
+            "responses":[
+                "I'm a WebKit developer",
+                "I'm a web developer",
+                "I contribute to Web Standards",
+                "I do iOS development",
+                "Other:"
+            ]
+        }
+    ]
+}
\ No newline at end of file
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to