diff --git a/campcaster/src/modules/htmlUI/var/html/ui_browser.php b/campcaster/src/modules/htmlUI/var/html/ui_browser.php
index 876fe6c42..9097aeda7 100644
--- a/campcaster/src/modules/htmlUI/var/html/ui_browser.php
+++ b/campcaster/src/modules/htmlUI/var/html/ui_browser.php
@@ -410,6 +410,12 @@ if ($uiBrowser->userid) {
case "SCHEDULER.export":
$Smarty->assign('act', $action);
break;
+
+ case "twitter.settings":
+ $Smarty->assign('dynform', $uiBrowser->TWITTER->getSettingsForm());
+ $Smarty->assign('twitter', array('samplefeed' => $uiBrowser->TWITTER->getFeed()));
+ $Smarty->assign('act', $action);
+ break;
}
if ($action != 'SCHEDULER') {
diff --git a/campcaster/src/modules/htmlUI/var/html/ui_handler.php b/campcaster/src/modules/htmlUI/var/html/ui_handler.php
index 5c8e0af62..346509d75 100644
--- a/campcaster/src/modules/htmlUI/var/html/ui_handler.php
+++ b/campcaster/src/modules/htmlUI/var/html/ui_handler.php
@@ -436,6 +436,11 @@ switch ($_REQUEST['act']) {
$_SESSION = array();
die();
break;
+
+ case 'twitter.saveSettings':
+ $uiHandler->TWITTER->saveSettings();
+ $uiHandler->redirUrl = UI_BROWSER.'?act=twitter.settings';
+ break;
case NULL:
if ($uiHandler->userid) {
diff --git a/campcaster/src/modules/htmlUI/var/html/ui_twitter-cron.php b/campcaster/src/modules/htmlUI/var/html/ui_twitter-cron.php
new file mode 100644
index 000000000..48bc67cc6
--- /dev/null
+++ b/campcaster/src/modules/htmlUI/var/html/ui_twitter-cron.php
@@ -0,0 +1,22 @@
+TWITTER->getFeed()) {
+ if ($uiHandler->TWITTER->needsUpdate()) {
+ print "Prepare for update...\n";
+ if ($res = $uiHandler->TWITTER->sendFeed($feed)) {
+ print "Feed id {$res->id}\n $feed";
+ } else {
+ print "Update failed, check auth data.";
+ }
+ } else {
+ print "Update interval not reached.";
+ }
+} else {
+ print "No playlist found.";
+}
\ No newline at end of file
diff --git a/campcaster/src/modules/htmlUI/var/lib/twitter.class.php b/campcaster/src/modules/htmlUI/var/lib/twitter.class.php
new file mode 100644
index 000000000..0098bfba5
--- /dev/null
+++ b/campcaster/src/modules/htmlUI/var/lib/twitter.class.php
@@ -0,0 +1,287 @@
+publicTimeline();
+// if($res===false){
+// echo "ERROR
{if $simpleSearchForm}
{include file="library/simpleSearchForm.tpl"}
diff --git a/campcaster/src/modules/htmlUI/var/templates/menu.tpl b/campcaster/src/modules/htmlUI/var/templates/menu.tpl
index 493da973e..49dfabc1d 100644
--- a/campcaster/src/modules/htmlUI/var/templates/menu.tpl
+++ b/campcaster/src/modules/htmlUI/var/templates/menu.tpl
@@ -70,6 +70,7 @@ if (window.attachEvent) window.attachEvent("onload", sfHover);
{* if $SUBJECTS->isMemberOf('StationPrefs') *}
- ##Station Settings##
+ - ##Twitter Settings##
{* /if *}
{*if $SUBJECTS->isMemberOf('Subjects')*}
- ##User/Groups##
diff --git a/campcaster/src/modules/htmlUI/var/templates/statusbar.tpl b/campcaster/src/modules/htmlUI/var/templates/statusbar.tpl
index 09e879d3c..8f5ab0958 100644
--- a/campcaster/src/modules/htmlUI/var/templates/statusbar.tpl
+++ b/campcaster/src/modules/htmlUI/var/templates/statusbar.tpl
@@ -1,5 +1,5 @@
{assign var='_nowplaying' value=$SCHEDULER->getNowNextClip()}
-{assign var='_nextplaying' value=$SCHEDULER->getNowNextClip(1)}
+{assign var='_nextplaying' value=$SCHEDULER->getNowNextClip()}
@@ -26,15 +26,31 @@
+
-
Elapsed:
-
Remaining:
+
+ ##Elapsed:##
+
+
+
+
+ ##Remaining:##
+
+
+
+
+
+
+ ##Playlist:##
+
+
+
{/if}
-
+
{if $_nextplaying}
-
##Playing Next##:
+
##Next Clip##:
{/if}
diff --git a/campcaster/src/modules/htmlUI/var/templates/twitter/settings.tpl b/campcaster/src/modules/htmlUI/var/templates/twitter/settings.tpl
new file mode 100644
index 000000000..e318b79a1
--- /dev/null
+++ b/campcaster/src/modules/htmlUI/var/templates/twitter/settings.tpl
@@ -0,0 +1,10 @@
+
+
+
##Twitter settings##
+
+Current tweet layout (sample length: {$twitter.samplefeed|strlen}):
+
{$twitter.samplefeed}
+
+{include file="sub/dynForm_plain.tpl"}
+
+
\ No newline at end of file
diff --git a/campcaster/src/modules/htmlUI/var/ui_base.inc.php b/campcaster/src/modules/htmlUI/var/ui_base.inc.php
index 5e917e211..b39e382c6 100644
--- a/campcaster/src/modules/htmlUI/var/ui_base.inc.php
+++ b/campcaster/src/modules/htmlUI/var/ui_base.inc.php
@@ -238,7 +238,9 @@ class uiBase
'EXCHANGE' => array('class' => 'uiexchange', 'file' => 'ui_exchange.class.php'),
'TRANSFERS' => array('class' => 'uitransfers', 'file' => 'ui_transfers.class.php'),
'CALENDAR' => array('class' => 'uicalendar', 'file' => 'ui_calendar.class.php'),
- 'JSCOM' => array('class' => 'jscom', 'file' => 'ui_jscom.php')
+ array('class' => 'jscom', 'file' => 'ui_jscom.php'),
+ 'TWITTER' => array('class' => 'uitwitter', 'file' => 'ui_twitter.class.php'),
+ array('class' => 'twitter', 'file' => 'lib/twitter.class.php')
);
diff --git a/campcaster/src/modules/htmlUI/var/ui_scheduler.class.php b/campcaster/src/modules/htmlUI/var/ui_scheduler.class.php
index 908ce688e..63096e471 100644
--- a/campcaster/src/modules/htmlUI/var/ui_scheduler.class.php
+++ b/campcaster/src/modules/htmlUI/var/ui_scheduler.class.php
@@ -668,7 +668,7 @@ class uiScheduler extends uiCalendar {
* @param string $i
* @return int
*/
- private static function datetimeToTimestamp($i)
+ public static function datetimeToTimestamp($i)
{
$i = str_replace('T', ' ', $i);
$formatted = $i[0].$i[1].$i[2].$i[3].'-'.$i[4].$i[5].'-'.$i[6].$i[7].strrchr($i, ' ');
diff --git a/campcaster/src/modules/htmlUI/var/ui_twitter.class.php b/campcaster/src/modules/htmlUI/var/ui_twitter.class.php
new file mode 100644
index 000000000..1c9b03b35
--- /dev/null
+++ b/campcaster/src/modules/htmlUI/var/ui_twitter.class.php
@@ -0,0 +1,302 @@
+Base =& $uiBase;
+ }
+
+ private static function getSettingFormMask()
+ {
+ $formmask = array(
+ array(
+ 'element' => 'act',
+ 'type' => 'hidden',
+ 'constant' => 'twitter.saveSettings'
+ ),
+ array(
+ 'element' => 'twitter-is_active',
+ 'type' => 'checkbox',
+ 'label' => 'Activate posts',
+ 'isPref' => true
+ ),
+ array(
+ 'element' => 'twitter-login',
+ 'type' => 'text',
+ 'label' => 'Login / user'
+ ,
+ 'isPref' => true
+ ),
+ array(
+ 'element' => 'twitter-password',
+ 'type' => 'text',
+ 'label' => 'Login / password'
+ ,
+ 'isPref' => true
+ ),
+ array(
+ 'element' => 'twitter-prefix',
+ 'type' => 'text',
+ 'label' => 'Prefix',
+ 'isPref' => true
+ ),
+ array(
+ 'element' => 'twitter-has_tracktitle',
+ 'type' => 'checkbox',
+ 'label' => 'Track title',
+ 'isPref' => true
+ ),
+ array(
+ 'element' => 'twitter-has_trackartist',
+ 'type' => 'checkbox',
+ 'label' => 'Track artist',
+ 'isPref' => true
+ ),
+ array(
+ 'element' => 'twitter-has_playlisttitle',
+ 'type' => 'checkbox',
+ 'label' => 'Playlist title',
+ 'isPref' => true
+ ),
+ array(
+ 'element' => 'twitter-has_stationname',
+ 'type' => 'checkbox',
+ 'label' => 'Station name',
+ 'isPref' => true
+ ),
+ array(
+ 'element' => 'twitter-suffix',
+ 'type' => 'text',
+ 'label' => 'Suffix',
+ 'isPref' => true
+ ),
+ array(
+ 'element' => 'twitter-url',
+ 'type' => 'text',
+ 'label' => 'URL (optional)',
+ 'isPref' => true
+ ),
+ array(
+ 'element' => 'twitter-offset',
+ 'type' => 'select',
+ 'label' => 'Tweet what\'s...',
+ 'options' => array(
+ "0" => "playing now",
+ "3000" => "in five minutes",
+ "6000" => "in ten minutes",
+ "9000" => "in 15 minutes",
+ "1800" => "in 30 minutes",
+ "3600" => "in one hour",
+ ),
+ 'isPref' => true
+ ),
+ array(
+ 'element' => 'twitter-interval',
+ 'type' => 'select',
+ 'label' => 'Tweet every...',
+ 'options' => array(
+ "60" => "minute",
+ "180" => "three minutes",
+ "300" => "five minutes",
+ "600" => "ten minutes",
+ "900" => "15 minutes",
+ "1800" => "30 minutes",
+ "3600" => "hour",
+ "21600" => "6 hours",
+ "43200" => "24 hours",
+ ),
+ 'isPref' => true
+ ),
+ array(
+ 'element' => 'Submit',
+ 'type' => 'submit',
+ 'label' => 'Submit',
+ )
+ );
+ return $formmask;
+ }
+
+ private function getSettings()
+ {
+ static $settings;
+
+ if (is_array($settings)) {
+ return $settings;
+ }
+
+ $settings = array();
+ $mask = uiTwitter::getSettingFormMask();
+
+ foreach($mask as $key => $val) {
+ if (isset($val['isPref']) && $val['isPref']) {
+ $element = isset($val['element']) ? $val['element'] : null;
+ $p = $this->Base->gb->loadGroupPref($this->Base->sessid, 'StationPrefs', $element);
+ if (is_string($p)) {
+ $settings[$element] = $p;
+ }
+ }
+ }
+
+ return $settings;
+ }
+
+ public function getSettingsForm()
+ {
+ $mask = uiTwitter::getSettingFormMask();
+ $form = new HTML_QuickForm('twitter', UI_STANDARD_FORM_METHOD, UI_HANDLER);#
+ $settings = $this->getSettings();
+
+ foreach($mask as $key => $val) {
+ if (isset($val['isPref']) && $val['isPref']) {
+ $element = isset($val['element']) ? $val['element'] : null;
+ $p = $settings[$element];
+ if (is_string($p)) {
+ $mask[$key]['default'] = $p;
+ }
+ }
+ }
+ uiBase::parseArrayToForm($form, $mask);
+ $renderer = new HTML_QuickForm_Renderer_Array(true, true);
+ $form->accept($renderer);
+ return $renderer->toArray();
+ }
+
+ public function saveSettings()
+ {
+ if ($this->Base->_validateForm($_REQUEST, uiTwitter::getSettingFormMask()) !== TRUE) {
+ $this->Base->_retMsg('An error has occured on validating the form.');
+ return FALSE;
+ }
+
+ $mask = uiTwitter::getSettingFormMask();
+ $form = new HTML_QuickForm('twitter', UI_STANDARD_FORM_METHOD, UI_HANDLER);
+ uiBase::parseArrayToForm($form, $mask);
+ $formdata = $form->exportValues();
+
+ foreach ($mask as $key => $val) {
+ if (isset($val['isPref']) && $val['isPref']) {
+ if (!empty($formdata[$val['element']])) {
+ $result = $this->Base->gb->saveGroupPref($this->Base->sessid, 'StationPrefs', $val['element'], $formdata[$val['element']]);
+ if (PEAR::isError($result))
+ $this->_retMsg('Error while saving twitter settings.');
+ } else {
+ $this->Base->gb->delGroupPref($this->Base->sessid, 'StationPrefs', $val['element']);
+ }
+ }
+ }
+
+ $this->Base->_retMsg('Twitter settings saved.');
+ }
+
+ public function getFeed($p_withSample = false)
+ {
+ $settings = $this->getSettings();
+ $whatsplaying = $this->getWhatsplaying($settings['twitter-offset']);
+
+ if (!$p_withSample && !$whatsplaying) {
+ return;
+ }
+
+ $whatsplaying = @array_merge(
+ array(
+ "tracktitle" => "Gimme Shelter",
+ "trackartist" => "The Rolling Stones",
+ "playlisttitle" => "The Blues Hour"
+ ),
+ $whatsplaying
+ );
+
+ ////////////////////////////////////////////////////////////////////////
+ // create twitter tweet sample
+ // TWEET PREFIX
+ if (!empty($settings['twitter-prefix'])) {
+ $tweetprefix = $settings['twitter-prefix'] . " ";
+ } else {
+ $tweetprefix = "";
+ }
+ // TWEET SUFFIX
+ if (!empty($settings['twitter-suffix'])) {
+ $tweetsuffix = " " . $settings['twitter-suffix'];
+ } else {
+ $tweetsuffix = "";
+ }
+ if (!empty($settings['twitter-url'])) {
+ $tweetsuffix = $tweetsuffix . " " . self::GetTinyUrl($settings['twitter-url']);
+ }
+ // TWEET BODY
+ $tweetbody = array();
+ if ($settings['twitter-has_tracktitle']) { $tweetbody[] = $whatsplaying['tracktitle']; }
+ if ($settings['twitter-has_trackartist']) { $tweetbody[] = $whatsplaying['trackartist']; }
+ if ($settings['twitter-has_playlisttitle']) { $tweetbody[] = $whatsplaying['playlisttitle']; }
+ if ($settings['twitter-has_stationname']) { $tweetbody[] = $this->Base->STATIONPREFS['stationName']; }
+
+ $tweetbody = implode (". ",$tweetbody);
+
+ // chop body to fit if necessary
+ if ((strlen($tweetprefix) + strlen($tweetbody) + strlen($tweetsuffix)) > 140) {
+ $tweetbody = substr($tweetbody, 0, (140 - (strlen($tweetprefix) + strlen($tweetsuffix) + 3))) . "...";
+ }
+
+ $tweet = $tweetprefix . $tweetbody . $tweetsuffix;
+
+ return $tweet;
+
+ }
+
+ public function getTinyUrl($p_url)
+ {
+ $tiny = file_get_contents('http://tinyurl.com/api-create.php?url='.$p_url);
+ return $tiny;
+ }
+
+ public function getWhatsplaying($p_offset)
+ {
+ $timestamp = time() + $p_offset;
+ $xmldatetime = strftime('%Y%m%dT%H:%M:%S', $timestamp);
+
+ $pl = $this->Base->SCHEDULER->displayScheduleMethod($xmldatetime, $xmldatetime);
+
+ if (!is_array($pl) || !count($pl)) {
+ return FALSE;
+ }
+
+ $pl = current($pl);
+ // subtract difference to UTC
+ $offset = strftime('%H:%M:%S', $timestamp - uiScheduler::datetimeToTimestamp($pl['start']) - 3600 * strftime('%H', 0));
+
+ $clip = $this->Base->gb->displayPlaylistClipAtOffset($this->Base->sessid, $pl['playlistId'], $offset, $distance, $_SESSION['langid'], UI_DEFAULT_LANGID);
+
+ if (!$clip['gunid']) {
+ return FALSE;
+ }
+
+ return array(
+ 'tracktitle' => $this->Base->gb->getMetadataValue(BasicStor::IdFromGunid($clip['gunid']), UI_MDATA_KEY_TITLE, $this->Base->sessid),
+ 'trackartist' => $this->Base->gb->getMetadataValue(BasicStor::IdFromGunid($clip['gunid']), UI_MDATA_KEY_CREATOR, $this->Base->sessid),
+ 'playlisttitle' => $this->Base->gb->getMetadataValue(BasicStor::IdFromGunid($pl['playlistId']), UI_MDATA_KEY_TITLE, $this->Base->sessid),
+ );
+ }
+
+ public function sendFeed($p_feed)
+ {
+ $settings = $this->getSettings();
+
+ $twitter = new twitter();
+ $twitter->username = $settings['twitter-login'];
+ $twitter->password = $settings['twitter-password'];
+
+ $this->Base->gb->saveGroupPref($this->Base->sessid, 'StationPrefs', 'twitter-lastupdate', time());
+
+ return $twitter->update($p_feed);
+ }
+
+ public function needsUpdate()
+ {
+ $settings = $this->getSettings();
+ if (time() - $this->Base->gb->loadGroupPref($this->Base->sessid, 'StationPrefs', 'twitter-lastupdate') > $settings['twitter-interval']) {
+ return true;
+ }
+ return false;
+ }
+}
\ No newline at end of file