Title: [198937] trunk/Websites/webkit.org
Revision
198937
Author
[email protected]
Date
2016-03-31 20:15:07 -0700 (Thu, 31 Mar 2016)

Log Message

Show tweets by @webkit in the Twitter tile on webkit.org
https://bugs.webkit.org/show_bug.cgi?id=156093

Reviewed by Timothy Hatcher.

* wp-content/plugins/tweet-listener.php: Added.
* wp-content/themes/webkit/widgets/twitter.php:

Modified Paths

Added Paths

Diff

Modified: trunk/Websites/webkit.org/ChangeLog (198936 => 198937)


--- trunk/Websites/webkit.org/ChangeLog	2016-04-01 01:54:47 UTC (rev 198936)
+++ trunk/Websites/webkit.org/ChangeLog	2016-04-01 03:15:07 UTC (rev 198937)
@@ -1,5 +1,15 @@
 2016-03-31  Jon Davis  <[email protected]>
 
+        Show tweets by @webkit in the Twitter tile on webkit.org
+        https://bugs.webkit.org/show_bug.cgi?id=156093
+
+        Reviewed by Timothy Hatcher.
+
+        * wp-content/plugins/tweet-listener.php: Added.
+        * wp-content/themes/webkit/widgets/twitter.php:
+
+2016-03-31  Jon Davis  <[email protected]>
+
         Fix download links for desktops with small resolutions
         https://bugs.webkit.org/show_bug.cgi?id=156081
 

Added: trunk/Websites/webkit.org/wp-content/plugins/tweet-listener.php (0 => 198937)


--- trunk/Websites/webkit.org/wp-content/plugins/tweet-listener.php	                        (rev 0)
+++ trunk/Websites/webkit.org/wp-content/plugins/tweet-listener.php	2016-04-01 03:15:07 UTC (rev 198937)
@@ -0,0 +1,71 @@
+<?php
+/*
+Plugin Name: Tweet Listener
+Description: Listens for Tweets from @webkit
+Version:     1.0
+Author:      Jonathan Davis
+Author URI:  http://webkit.org
+*/
+
+TweetListener::object();
+
+class TweetListener {
+
+    private static $object = null;
+    
+    const AUTH_TOKEN = TWITTER_LISTENER_AUTH;
+    const DATA_KEY = 'recent_tweet';
+
+    public static function object() {
+        if (self::$object === null)
+            self::$object = new self();
+        return self::$object;
+    }
+
+    private function __construct() {
+        add_action('wp_ajax_nopriv_tweet', array($this, 'listen'));
+        add_action('wp_ajax_tweet', array($this, 'listen'));
+    }
+
+    public function listen() {
+        
+        $defaults = array(
+            'text' => '', 
+            'username' => '@webkit',
+            'link' => '',
+            'created' => '',
+            'embed' => ''
+        );
+        $data = "" $_POST);
+
+        update_option(self::DATA_KEY, $data);
+        wp_die();
+    }
+    
+    public function tweet() {
+        $data = ""
+        
+        // Setup compatible Tweet structure
+
+        $Tweet = new StdClass();
+        $Tweet->id = substr($data->link, strrpos($data->link, '/') + 1);
+        $Tweet->text = $data->text;
+
+        $Tweet->entities = new StdClass();
+        $Tweet->entities->urls = array();
+        $Tweet->entities->media = array();
+
+        // Search for embedded images
+        if ( preg_match_all('/<a href="" stripslashes($data->embed), $matches, PREG_SET_ORDER) ) {
+            foreach ($matches as $embedlink) {
+                $URL = "" StdClass();
+                $URL->expanded_url = $URL->display_url = $URL->url =""
+                $URL->display_url = str_replace(array('https://','http://'), '', $URL->display_url);
+                $Tweet->entities->urls[] = $URL;
+            }
+        }
+        
+        return $Tweet;
+    }
+
+} // end class TweetListener
\ No newline at end of file

Modified: trunk/Websites/webkit.org/wp-content/themes/webkit/widgets/twitter.php (198936 => 198937)


--- trunk/Websites/webkit.org/wp-content/themes/webkit/widgets/twitter.php	2016-04-01 01:54:47 UTC (rev 198936)
+++ trunk/Websites/webkit.org/wp-content/themes/webkit/widgets/twitter.php	2016-04-01 03:15:07 UTC (rev 198937)
@@ -111,6 +111,13 @@
 
     function tweet () {
 
+        // Prefer pushed tweet
+        if ( class_exists('TweetListener') ) {
+            $TweetListener = TweetListener::object();
+            return $TweetListener->tweet();
+        }
+
+        // Poll for tweet
         if ( false !== ( $cached = get_transient(self::CACHEKEY) ) )
             return json_decode($cached);
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to