diff --git a/campcaster/src/modules/htmlUI/etc/Makefile.in b/campcaster/src/modules/htmlUI/etc/Makefile.in index f6454b1f1..26f42c5a3 100644 --- a/campcaster/src/modules/htmlUI/etc/Makefile.in +++ b/campcaster/src/modules/htmlUI/etc/Makefile.in @@ -158,6 +158,7 @@ install: configure_apache ${MKDIR} ${USR_VAR_DIR}/Campcaster/htmlUI/var/templates/system ${MKDIR} ${USR_VAR_DIR}/Campcaster/htmlUI/var/templates/playlist ${MKDIR} ${USR_VAR_DIR}/Campcaster/htmlUI/var/templates/subjects + ${MKDIR} ${USR_VAR_DIR}/Campcaster/htmlUI/var/install ${CP} ${VAR_DIR}/redirect.php ${USR_VAR_DIR}/Campcaster/index.php ${CP} ${VAR_DIR}/redirect.php ${USR_VAR_DIR}/Campcaster/htmlUI/index.php @@ -212,7 +213,7 @@ install: configure_apache ${CP} ${VAR_DIR}/templates/subjects/*.tpl \ ${USR_VAR_DIR}/Campcaster/htmlUI/var/templates/subjects - ${MKDIR} ${USR_VAR_DIR}/Campcaster/htmlUI/var/templates_c + ${CP} ${VAR_DIR}/install/install.php ${USR_VAR_DIR}/Campcaster/htmlUI/var/install/ chgrp ${APACHE_GROUP} ${USR_VAR_DIR}/Campcaster/htmlUI/var/templates_c chgrp ${APACHE_GROUP} ${USR_VAR_DIR}/Campcaster/htmlUI/var/html/img @@ -224,6 +225,8 @@ install: configure_apache ${RM} ${WWW_DOCROOT}/campcaster ln -sf ${USR_VAR_DIR}/Campcaster ${WWW_DOCROOT}/campcaster + + -cd var/install && php -q install.php configure_apache: ifeq (@CONFIGURE_APACHE@,yes) diff --git a/campcaster/src/modules/htmlUI/var/html/ui_twitter-cron.php b/campcaster/src/modules/htmlUI/var/html/ui_twitter-cron.php deleted file mode 100644 index 48bc67cc6..000000000 --- a/campcaster/src/modules/htmlUI/var/html/ui_twitter-cron.php +++ /dev/null @@ -1,22 +0,0 @@ -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/html/ui_twitterCron.php b/campcaster/src/modules/htmlUI/var/html/ui_twitterCron.php new file mode 100644 index 000000000..ccd80f7cd --- /dev/null +++ b/campcaster/src/modules/htmlUI/var/html/ui_twitterCron.php @@ -0,0 +1,37 @@ +init(); + +if (is_array($argv)) { + define('CRON_DEBUG', array_search('debug', $argv)); +} else { + define('CRON_DEBUG', true); + print '
'; +} + +$uiHandler->sessid = $_COOKIE[$CC_CONFIG['authCookieName']] = Alib::Login('scheduler', 'change_me'); + +if (!$uiHandler->sessid) { + print "Alib::Login failed\n"; + exit(1); +} + + +if ($uiHandler->TWITTER->needsUpdate()) { + if ($feed = $uiHandler->TWITTER->getFeed()) { + if (CRON_DEBUG) print "Prepare for update...\n"; + if ($res = $uiHandler->TWITTER->sendFeed($feed)) { + if (CRON_DEBUG) print "Post with feed id: {$res->id}\nContent: $feed"; + } else { + print "Update failed, check auth data.\n"; + exit(1); + } + } else { + if (CRON_DEBUG) print "No playlist found at offset time.\n"; + } +} else { + if (CRON_DEBUG) print "Update interval not reached.\n"; +} \ No newline at end of file diff --git a/campcaster/src/modules/htmlUI/var/install/install.php b/campcaster/src/modules/htmlUI/var/install/install.php new file mode 100644 index 000000000..895f5ae8b --- /dev/null +++ b/campcaster/src/modules/htmlUI/var/install/install.php @@ -0,0 +1,36 @@ +openCrontab('write'); +if ($access != 'write') { + do { + $r = $cron->forceWriteable(); + } while ($r); +} + +foreach ($cron->ct->getByType(CRON_CMD) as $line) { + if (preg_match('/ui_twitterCron\.php/', $line['command'])) { + $cron->closeCrontab(); + echo " * Twitter cron job already exists.\n"; + exit; + } +} +echo " * Adding twitter cron job..."; +$cron->ct->addCron('*', '*', '*', '*', '*', $command); +$cron->closeCrontab(); +echo "Done\n"; +?> diff --git a/campcaster/src/modules/htmlUI/var/lib/twitter.class.php b/campcaster/src/modules/htmlUI/var/lib/twitter.class.php index 0098bfba5..092c57967 100644 --- a/campcaster/src/modules/htmlUI/var/lib/twitter.class.php +++ b/campcaster/src/modules/htmlUI/var/lib/twitter.class.php @@ -259,7 +259,7 @@ class twitter{ if($this->username !== false && $this->password !== false) curl_setopt($ch, CURLOPT_USERPWD, $this->username.':'.$this->password); - curl_setopt($ch, CURLOPT_VERBOSE, 1); + curl_setopt($ch, CURLOPT_VERBOSE, 0); curl_setopt($ch, CURLOPT_NOBODY, 0); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_USERAGENT, $this->user_agent); diff --git a/campcaster/src/modules/htmlUI/var/ui_conf.php b/campcaster/src/modules/htmlUI/var/ui_conf.php index 2df935105..9171573a0 100644 --- a/campcaster/src/modules/htmlUI/var/ui_conf.php +++ b/campcaster/src/modules/htmlUI/var/ui_conf.php @@ -114,7 +114,7 @@ define('UI_PL_ELEM_FADEOUT', 'fadeOut'); define('UI_BACKUPTOKEN_KEY', 'backupToken'); define('UI_RESTORETOKEN_KEY', 'restoreToken'); -require_once('../../../storageServer/var/conf.php'); +require_once(dirname(__FILE__).'/../../storageServer/var/conf.php'); define('UI_VERSION', CAMPCASTER_VERSION); define('UI_VERSION_FULLNAME', 'Campcaster '.UI_VERSION); define('UI_COPYRIGHT_DATE', CAMPCASTER_COPYRIGHT_DATE); @@ -151,7 +151,7 @@ $CC_CONFIG = array_merge($CC_CONFIG, ); require_once(dirname(__FILE__).'/ui_base.inc.php'); -require_once('../../../storageServer/var/GreenBox.php'); +require_once(dirname(__FILE__).'/../../storageServer/var/GreenBox.php'); require_once(dirname(__FILE__).'/formmask/generic.inc.php'); require_once('DB.php'); diff --git a/campcaster/src/modules/htmlUI/var/ui_twitter.class.php b/campcaster/src/modules/htmlUI/var/ui_twitter.class.php index 833cbccd8..29ef2a3f0 100644 --- a/campcaster/src/modules/htmlUI/var/ui_twitter.class.php +++ b/campcaster/src/modules/htmlUI/var/ui_twitter.class.php @@ -1,10 +1,20 @@ Base =& $uiBase; + $this->loadSettings(); } private static function getSettingFormMask() @@ -156,40 +166,30 @@ class uiTwitter { return $formmask; } - private function getSettings() + private function loadSettings() { - static $settings; - - if (is_array($settings)) { - return $settings; - } - - $settings = array(); $mask = uiTwitter::getSettingFormMask(); foreach($mask as $key => $val) { - if (isset($val['isPref']) && $val['isPref'] && !$val['hiddenPref']) { + 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; + $this->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']) { + if (isset($val['isPref']) && $val['isPref'] && !$val['hiddenPref']) { $element = isset($val['element']) ? $val['element'] : null; - $p = $settings[$element]; + $p = $this->settings[$element]; if (is_string($p)) { $mask[$key]['default'] = $p; } @@ -219,7 +219,7 @@ class uiTwitter { $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 { + } elseif (!$val['hiddenPref']) { $this->Base->gb->delGroupPref($this->Base->sessid, 'StationPrefs', $val['element']); } } @@ -229,9 +229,7 @@ class uiTwitter { } public function getFeed($p_useSampledata = false) - { - $settings = $this->getSettings(); - + { if ($p_useSampledata) { $whatsplaying = array( "tracktitle" => "Gimme Shelter", @@ -239,7 +237,7 @@ class uiTwitter { "playlisttitle" => "The Blues Hour" ); } else { - $whatsplaying = $this->getWhatsplaying($settings['twitter-offset']); + $whatsplaying = $this->getWhatsplaying($this->settings['twitter-offset']); } if (!$whatsplaying) { @@ -249,26 +247,26 @@ class uiTwitter { //////////////////////////////////////////////////////////////////////// // create twitter tweet sample // TWEET PREFIX - if (!empty($settings['twitter-prefix'])) { - $tweetprefix = $settings['twitter-prefix'] . " "; + if (!empty($this->settings['twitter-prefix'])) { + $tweetprefix = $this->settings['twitter-prefix'] . " "; } else { $tweetprefix = ""; } // TWEET SUFFIX - if (!empty($settings['twitter-suffix'])) { - $tweetsuffix = " " . $settings['twitter-suffix']; + if (!empty($this->settings['twitter-suffix'])) { + $tweetsuffix = " " . $this->settings['twitter-suffix']; } else { $tweetsuffix = ""; } - if (!empty($settings['twitter-url'])) { - $tweetsuffix = $tweetsuffix . " " . self::GetTinyUrl($settings['twitter-url']); + if (!empty($this->settings['twitter-url'])) { + $tweetsuffix = $tweetsuffix . " " . self::GetTinyUrl($this->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']; } + if ($this->settings['twitter-has_tracktitle']) { $tweetbody[] = $whatsplaying['tracktitle']; } + if ($this->settings['twitter-has_trackartist']) { $tweetbody[] = $whatsplaying['trackartist']; } + if ($this->settings['twitter-has_playlisttitle']) { $tweetbody[] = $whatsplaying['playlisttitle']; } + if ($this->settings['twitter-has_stationname']) { $tweetbody[] = $this->Base->STATIONPREFS['stationName']; } $tweetbody = implode (". ",$tweetbody); @@ -319,23 +317,20 @@ class uiTwitter { public function sendFeed($p_feed) { - $settings = $this->getSettings(); - $twitter = new twitter(); - $twitter->username = $settings['twitter-login']; - $twitter->password = $settings['twitter-password']; + $twitter->username = $this->settings['twitter-login']; + $twitter->password = $this->settings['twitter-password']; - if ($twitter->update($p_feed)) { + if ($res = $twitter->update($p_feed)) { $this->Base->gb->saveGroupPref($this->Base->sessid, 'StationPrefs', 'twitter-lastupdate', time()); - return true; + return $res; } return false; } public function needsUpdate() { - $settings = $this->getSettings(); - if (time() - $this->Base->gb->loadGroupPref($this->Base->sessid, 'StationPrefs', 'twitter-lastupdate') > $settings['twitter-interval']) { + if (time() - $this->Base->gb->loadGroupPref($this->Base->sessid, 'StationPrefs', 'twitter-lastupdate') + $this->runtime > $this->settings['twitter-interval']) { return true; } return false;