diff --git a/app/extensions/PHPemTwitterAPI/assets/tweet.twig b/app/extensions/PHPemTwitterAPI/assets/tweet.twig new file mode 100644 index 0000000..1af04ea --- /dev/null +++ b/app/extensions/PHPemTwitterAPI/assets/tweet.twig @@ -0,0 +1,11 @@ +
  • + {% if retweeted_status is empty %} +

    {{ text|striptags('')|raw }}

    + by {{ user.name }} + {{ __("at") }} {{ created_at|date("g:sa") }} {{ __("on") }} {{ created_at|date("jS F Y") }} + {% else %} +

    {{ __("Retweet") }}{{ retweeted_status.text|striptags('')|raw }}

    + by {{ retweeted_status.user.name }} + {{ __("at") }} {{ retweeted_status.created_at|date("g:sa") }} {{ __("on") }} {{ retweeted_status.created_at|date("jS F Y") }} + {% endif %} +
  • \ No newline at end of file diff --git a/app/extensions/PHPemTwitterAPI/config.yml.dist b/app/extensions/PHPemTwitterAPI/config.yml.dist new file mode 100644 index 0000000..fe08b01 --- /dev/null +++ b/app/extensions/PHPemTwitterAPI/config.yml.dist @@ -0,0 +1,10 @@ +template: + tweet: assets/tweet.twig + +auth: + consumer: + key: SomeConsumerKey + secret: SomeConsumerSecret + access: + token: SomeAccessToken + secret: SomeAccessTokenSecret \ No newline at end of file diff --git a/app/extensions/PHPemTwitterAPI/extension.php b/app/extensions/PHPemTwitterAPI/extension.php new file mode 100644 index 0000000..3d4beec --- /dev/null +++ b/app/extensions/PHPemTwitterAPI/extension.php @@ -0,0 +1,127 @@ + "PHPemTwitterAPI", + 'description' => "Twitter API integration for the PHPem website", + 'author' => "Jack Bentley (Viva IT)", + 'link' => "http://www.vivait.co.uk", + 'version' => "1.0", + 'required_bolt_version' => "1.5", + 'highest_bolt_version' => "2.0", + 'type' => "Twig function", + 'first_releasedate' => "0000-00-00", + 'latest_releasedate' => "0000-00-00", + 'allow_in_user_content' => true, + ); + + return $data; + } + + public function initialize() + { + $this->app['twig.loader.filesystem']->addPath(__DIR__); + + $this->addTwigFunction('latestTweets', 'latestTweets'); + } + + public function latestTweets($user, $amount = 1) + { + + $api = new \tmhOAuth([ + 'consumer_key' => $this->config['auth']['consumer']['key'], + 'consumer_secret' => $this->config['auth']['consumer']['secret'], + 'token' => $this->config['auth']['access']['token'], + 'secret' => $this->config['auth']['access']['secret'], + //'bearer' => 'YOUR_OAUTH2_TOKEN', + 'user_agent' => 'PHPem Website', + ]); + + $api->apponly_request([ + 'url' => $api->url('1.1/statuses/user_timeline'), + 'without_bearer' => true, + 'params' => [ + 'screen_name' => $user, + 'count' => $amount, + ] + ]); + + $response = json_decode($api->response['response'], true); + + $output = ''; + + foreach($response as $tweet) { + $this->embedTweetLinks($tweet); + + if(isset($tweet['retweeted_status'])) + $this->embedTweetLinks($tweet['retweeted_status']); + + $output .= $this->app['render']->render($this->config['template']['tweet'], $tweet); + } + + return new \Twig_Markup($output, 'UTF-8'); + } + + private function embedTweetLinks(&$tweet) { + $tweet['text'] = htmlentities($tweet['text']); + if(isset($tweet['entities']['user_mentions'])) { + foreach(array_reverse($tweet['entities']['user_mentions']) as $entity) { + $tweet['text'] = substr_replace( + $tweet['text'], + '' + . substr($tweet['text'], $entity['indices'][0], $entity['indices'][1] - $entity['indices'][0]) + . '', + $entity['indices'][0], $entity['indices'][1] - $entity['indices'][0] + ); + } + } + + if(isset($tweet['entities']['hashtags'])) { + foreach(array_reverse($tweet['entities']['hashtags']) as $entity) { + $tweet['text'] = str_replace( + '#' . $entity['text'], + '' + . '#' . $entity['text'] + . '', + $tweet['text'] + ); + } + } + + if(isset($tweet['entities']['media'])) { + foreach(array_reverse($tweet['entities']['media']) as $entity) { + $tweet['text'] = str_replace( + $entity['url'], + '' + . $entity['display_url'] + . '', + $tweet['text'] + ); + } + } + + if(isset($tweet['entities']['urls'])) { + foreach(array_reverse($tweet['entities']['urls']) as $entity) { + $tweet['text'] = str_replace( + $entity['url'], + '' + . $entity['display_url'] + . '', + $tweet['text'] + ); + } + } + } +} \ No newline at end of file diff --git a/theme/phpem/README.md b/theme/phpem/README.md deleted file mode 100644 index b58b397..0000000 --- a/theme/phpem/README.md +++ /dev/null @@ -1,28 +0,0 @@ -base-2014 -========= - -This is the "base-2014" theme for Bolt. It is built with Foundation 5 and Sass, but you can use it -as-is. - -To install manually, go to `theme/` and do a checkout: - - git clone https://github.com/bolt/base-2014.git - -Set `theme: base-2014` in your `app/config/config.yml`, and you're good to go! - -If you wish to modify this theme using Sass, be sure to install the 'Foundation' -bower module, and start your favorite Sass parser, for example 'grunt': - -``` -bower install -npm install -grunt watch -``` - -If you could use some pointers to get started with node, grunt and bower in -combination with Foundation, I recommend these links: - - - http://24ways.org/2013/grunt-is-not-weird-and-hard/ - - http://foundation.zurb.com/docs/sass.html - - http://webdesign.tutsplus.com/tutorials/foundations-sassy-styles-explained--webdesign-15549 - - http://blog.teamtreehouse.com/getting-started-bower diff --git a/theme/phpem/index.twig b/theme/phpem/index.twig index 31eb8cb..51846af 100644 --- a/theme/phpem/index.twig +++ b/theme/phpem/index.twig @@ -44,20 +44,9 @@

    {{ __("Tweets") }}

    - Follow @PHPem + Follow @PHPem