Permalink
Browse files

First commit of former twitter.ncsu.edu code

  • Loading branch information...
1 parent 0369e76 commit 2a62d0bdbd267b2dee6dfc329e8c8371720cbf87 @jfaustin committed Sep 28, 2010
View
@@ -0,0 +1,5 @@
+/.buildpath
+/.gitignore
+/.project
+/cache/*
+!.gitignore
View
@@ -0,0 +1,74 @@
+http://twitter.ncsu.edu
+
+NC State University
+ * Outreach Technology (http://ot.ncsu.edu)
+ * Web Communications (http://www.ncsu.edu)
+ * Contact twitter@ncsu.edu for additional assistance.
+
+
+The contents of this package are released under the following license:
+
+=================================================
+
+This license is governed by United States copyright law, and with respect to matters
+of tort, contract, and other causes of action it is governed by North Carolina law,
+without regard to North Carolina choice of law provisions. The forum for any dispute
+resolution shall be in Wake County, North Carolina.
+
+Redistribution and use in source and binary forms, with or without modification, are
+permitted provided that the following conditions are met:
+
+1. Redistributions of source code must retain the above copyright notice, this list
+ of conditions and the following disclaimer.
+
+2. Redistributions in binary form must reproduce the above copyright notice, this
+ list of conditions and the following disclaimer in the documentation and/or other
+ materials provided with the distribution.
+
+3. The name of the author may not be used to endorse or promote products derived from
+ this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
+WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
+AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE
+LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+=================================================
+
+Notes
+
+* This code is based on Zend Framework version 1.10.6. All applicable licenses to Zend
+ Framework still apply.
+
+* While not required, we would prefer that you state where the code used to create
+ your site came from. Our contact information is at the top of this document.
+
+
+Installation
+
+* Extract the download into a web accessible directory on your webserver
+
+* Bring up your web browser and go to http://[wherever-you-installed-this-at]/install
+
+* The install script will take you the rest of the way through.
+
+* 3 main pages are provied
+ - index.php: Shows all the tweets for the account you setup
+ - orgs.php: Shows all the accounts you are following
+ - feed.php: Provides an RSS feed of all the tweets for the account you setup
+
+
+Known Issues
+
+* On some systems running PHP 5.3+ there seems to be a delay on writing information to the
+ config.php file. The information will get written on the first request, but the installer
+ sometimes does not recognize this. It typically takes 3-5 seconds to it to realize the
+ necessary actions have been taken. A simple refresh of the installer page will make the
+ installer kick in.
+
+Any additional questions should be sent to twitter@ncsu.edu.
View
No changes.
View
@@ -0,0 +1,4 @@
+<?php
+require_once 'inc/Tweetgater/Display.php';
+
+Tweetgater_Display::feed();
@@ -0,0 +1,140 @@
+<?php
+
+set_include_path(realpath(dirname(__FILE__) . '/../'));
+
+require_once 'Tweetgater/Twitter.php';
+
+/**
+ * Does all interaction with the twitter API for the NCSU twitter page
+ *
+ * @author jfaustin
+ *
+ */
+class Tweetgater_Display
+{
+ public static function timeline($page = 1)
+ {
+ $ncsu = new Tweetgater_Twitter();
+
+ $error = '';
+
+ try {
+ $timeline = $ncsu->getTimeline($page);
+ } catch (Exception $e) {
+ $error = $e->getMessage();
+ }
+
+ $ret = '';
+
+ if ($error == '') {
+ foreach ($timeline as $t) {
+ $ret .= '<div class="tweet">'
+ . ' <div class="avatar">'
+ . ' <img src="' . $t['user-profile_image_url'] . '" alt="' . $t['user-name'] . '" width="48" height="48" />'
+ . ' </div>'
+ . ' <div class="text">'
+ . ' <a class="username" href="http://twitter.com/' . $t['user-screen_name'] . '">' . $t['user-screen_name'] . '</a> ' . $t['text']
+ . ' </div>'
+ . ' <div class="origination"> ' . $t['elapsed_time'] . ' from ' . $t['source']
+ . (($t['in_reply_to_screen_name'] != '') ? ' <a class="user" href="http://www.twitter.com/' . $t['in_reply_to_screen_name'] . '/status/' . $t['in_reply_to_status_id'] . '">in reply to ' . $t['in_reply_to_screen_name'] . '</a>' : '')
+ . ' </div>'
+ . ' <div style="clear:both;"></div>'
+ . '</div>'
+ ;
+ }
+
+ $ret .= '<br /><br />'
+ . '<a class="twitterButton" href="index.php?page=' . ($page + 1) . '">More...</a>'
+ ;
+ } else {
+ $ret = $error;
+ }
+
+ return $ret;
+ }
+
+ public static function accounts()
+ {
+
+ $ncsu = new Tweetgater_Twitter();
+
+ $error = '';
+ try {
+ $friends = $ncsu->getFriends();
+ } catch (Exception $e) {
+ $error = $e->getMessage();
+ }
+
+ $ret = '';
+
+ if ($error == '') {
+ $ret = '<h2 class="tweetHeader">' . count($friends) . ' Organizations are Tweeting</h2>';
+
+ $i = 0;
+ foreach ($friends as $f) {
+ $ret .= '<div class="tweet friend ' . (($i % 2 == 0) ? 'row1' : 'row2') . '">'
+ . ' <div class="avatar"><img src="' . $f['profile_image_url'] . '" alt="' . $f['name'] . '" width="48" height="48" /></div>'
+ . ' <div class="text">'
+ . ' <span class="name">' . $f['name'] . '</span><br />'
+ . (($f['description'] != '') ? $f['description'] . '<br />' : '')
+ . ' <a class="follow" href="http://twitter.com/' . $f['screen_name'] . '">Follow @' . $f['screen_name'] . '</a>'
+ . ' </div>'
+ . ' <div style="clear:both;"></div>'
+ . '</div>'
+ ;
+
+ $i++;
+ }
+ } else {
+ $ret = $error;
+ }
+
+ return $ret;
+ }
+
+ public static function feed()
+ {
+ $ncsu = new Tweetgater_Twitter();
+
+ $down = false;
+ try {
+ $timeline = $ncsu->getTimeline();
+ } catch (Exception $e) {
+ $down = true;
+ }
+
+ $config = $ncsu->getConfigFile();
+
+ $fa = array();
+
+ $fa['title'] = $config->feed->title;
+ $fa['link'] = $config->site->url. '/feed.php';
+ $fa['charset'] = 'UTF-8';
+ $fa['author'] = $config->feed->title;
+
+ $entries = array();
+
+ if (!$down) {
+ foreach ($timeline as $t) {
+
+ $temp = array();
+
+ $temp['title'] = 'Tweet by @' . $t['user-screen_name'];
+ $temp['link'] = 'http://www.twitter.com/' . $t['user-screen_name'] . '/status/' . $t['id'];
+ $temp['description'] = $t['text'] . '<br /><br />Follow @<a href="http://www.twitter.com/' . $t['user-screen_name'] . '">' . $t['user-screen_name'] . '</a>';
+ $temp['lastUpdate'] = strtotime($t['created_at']);
+
+ $entries[] = $temp;
+ }
+ }
+
+ $fa['entries'] = $entries;
+
+ // importing a rss feed from an array
+ $rssFeed = Zend_Feed::importArray($fa, 'rss');
+
+
+ // send http headers and dump the feed
+ $rssFeed->send();
+ }
+}
@@ -0,0 +1,167 @@
+<?php
+set_include_path(realpath(dirname(__FILE__) . '/../'));
+
+class Tweetgater_Installer
+{
+ const ZF_REQUIREMENT = '1.10.6';
+
+ protected $_writable = array(
+ '../config',
+ '../cache',
+ );
+
+ public function __construct()
+ {
+ if (is_file('../inc/Zend/Loader/Autoloader.php')) {
+ require_once '../inc/Zend/Loader/Autoloader.php';
+ $loader = Zend_Loader_Autoloader::getInstance();
+ $loader->setFallbackAutoloader(true);
+ }
+ }
+
+ public function checkZendFramework()
+ {
+ if (!is_dir('../inc/Zend')) {
+ return 'Zend Framework library not found in /inc/Zend';
+ }
+
+ require_once '../inc/Zend/Version.php';
+
+ $versionCompare = Zend_Version::compareVersion(self::ZF_REQUIREMENT);
+
+ if ($versionCompare == 1) {
+ return 'Zend Framework library you are using is older than the recommended version of ' . self::ZF_REQUIREMENT;
+ } elseif ($versionCompare == -1) {
+ return 'Zend Framework library you are using is newer than the recommended version of ' . self::ZF_REQUIREMENT;
+ }
+
+ return true;
+ }
+
+ public function checkWritable()
+ {
+ $result = array();
+
+ foreach ($this->_writable as $w) {
+ $result[$w] = is_writable($w);
+ }
+
+ return $result;
+ }
+
+ public function createConfigFile()
+ {
+ $filepath = Tweetgater_Twitter::getConfigFilePath();
+ $source = str_replace('config.php', 'config.default.php', $filepath);
+
+ $ret = '';
+ if (is_file($filepath)) {
+ $ret = 'File exists, checking writability....<br />';
+ } else {
+
+ if (!copy($source, $filepath)) {
+ throw new Exception('Can not copy config.default.php to config.php. You should do this manually.');
+ }
+
+ chmod($filepath, 0766);
+
+ $ret = 'Creating file config.php<br />';
+ }
+
+ if (is_writable($filepath)) {
+ $ret .= 'File is writable<br />';
+ } else {
+ if (!chmod($filepath, 0766)) {
+ throw new Exception('Can not make config file writable');
+ }
+
+ $ret .= 'Modifying file for writing<br />';
+ }
+
+ return $ret;
+ }
+
+ public function verifyOptions()
+ {
+ $config = Tweetgater_Twitter::getConfigFile();
+
+ if ($config->site->url == '' || $config->feed->title == '' || $config->feed->author == '') {
+ return false;
+ }
+
+ return true;
+ }
+
+ public function writeOptions($url, $feedTitle, $feedAuthor)
+ {
+ $config = Tweetgater_Twitter::getConfigFile(true);
+
+ $config->site->url = $url;
+ $config->feed->title = $feedTitle;
+ $config->feed->author = $feedAuthor;
+
+ $writer = new Zend_Config_Writer_Array(array('config' => $config, 'filename' => Tweetgater_Twitter::getConfigFilePath()));
+
+ $writer->write();
+ }
+
+ public function getProbableUrl()
+ {
+ $baseUrl = substr($_SERVER['PHP_SELF'], 0, strpos($_SERVER['PHP_SELF'], '/install'));
+
+ $s = empty($_SERVER["HTTPS"]) ? '' : ($_SERVER["HTTPS"] == "on") ? "s" : "";
+ $protocol = substr(strtolower($_SERVER["SERVER_PROTOCOL"]), 0, strpos(strtolower($_SERVER["SERVER_PROTOCOL"]), "/")) . $s;
+ $port = ($_SERVER["SERVER_PORT"] == "80") ? "" : (":".$_SERVER["SERVER_PORT"]);
+ $url = $protocol . "://" . $_SERVER['SERVER_NAME'] . $port . $baseUrl;
+
+ return $url;
+ }
+
+ public function verifyTwitterAppRegistration()
+ {
+ $config = Tweetgater_Twitter::getConfigFile();
+
+ if ($config->oauth->consumerKey == '' || $config->oauth->consumerSecret == '') {
+ return false;
+ }
+
+ return true;
+
+ }
+
+ public function verifyTwitterAccountToken()
+ {
+ $config = Tweetgater_Twitter::getConfigFile();
+
+ if ($config->oauth->token == '') {
+ return false;
+ }
+
+ return true;
+ }
+
+ public function writeOauthAppInfo($consumerKey, $consumerSecret)
+ {
+ $config = Tweetgater_Twitter::getConfigFile(true);
+
+ $config->oauth->consumerKey = $consumerKey;
+ $config->oauth->consumerSecret = $consumerSecret;
+
+ $writer = new Zend_Config_Writer_Array(array('config' => $config, 'filename' => Tweetgater_Twitter::getConfigFilePath()));
+
+ $writer->write();
+ }
+
+ public function writeOauthToken($token, $tokenSecret)
+ {
+ $config = Tweetgater_Twitter::getConfigFile(true);
+
+ $config->oauth->token = $token;
+ $config->oauth->tokenSecret = $tokenSecret;
+
+ $writer = new Zend_Config_Writer_Array(array('config' => $config, 'filename' => Tweetgater_Twitter::getConfigFilePath()));
+
+ $writer->write();
+ }
+
+}
Oops, something went wrong.

0 comments on commit 2a62d0b

Please sign in to comment.