diff --git a/components/options.php b/components/options.php index 2462dd48d8522426389cbe3741058c9aa8c3cec5..d4724263d1b802632cf1c108dfb787c9ff77a990 100644 --- a/components/options.php +++ b/components/options.php @@ -169,6 +169,28 @@ function updateHackergotchi($fileDetails) { return FALSE; } +function changeBlogFeed($type, $feed, $syndicate) { + global $sucsDB, $session, $smarty; + if ($type == "sucs") { + $feed="http://sucs.org/blog/feed/atom/".$session->username; + } + + if ($syndicate=="on") { + $syndicate = "t"; + } else { + $syndicate = "f"; + } + + if ($sucsDB->Execute("UPDATE members SET blogfeed=?,syndicateblog=? WHERE username=?", + array($feed, $syndicate, $session->username)) == FALSE) { + return FALSE; + } + + //fixme: ensure sanity(/validity?) of provided uris to avoid screwing up planet's config + include("planetconfig.php"); + return TRUE; +} + function updateRenew() { global $sucsDB, $session, $error; global $paydate; @@ -209,6 +231,7 @@ if ($session->loggedin === TRUE) { $sucsDB = NewADOConnection('postgres8'); $sucsDB->Connect('dbname='.$sucsdbname); $sucsDB->SetFetchMode(ADODB_FETCH_ASSOC); +// $sucsDB->debug = true; $newGuestNetMAC = getGuestNetMAC(); @@ -243,6 +266,11 @@ if ($session->loggedin === TRUE) { message_flash('Hackergotchi Cleared'); } break; + case 'changeblogfeed' : + if (changeBlogFeed($_POST['blogtype'], $_POST['bloguri'], $_POST['syndicateblog'])){ + message_flash("Blog Feed Updated"); + } + break; case 'renew' : if (updateRenew()) { message_flash('Account renewed'); @@ -260,7 +288,6 @@ if ($session->loggedin === TRUE) { $member = $sucsDB->GetRow("select * from members left join member_type on members.type=member_type.id where username='".$session->username."'"); - $smarty->assign('member', $member); $smarty->assign('paydate', $paydate); if(($currentGuestNetMAC = $sucsDB->GetOne('SELECT * FROM guestnet WHERE uid=?', array((int)$member['uid']))) !== FALSE) { @@ -274,6 +301,28 @@ if ($session->loggedin === TRUE) { } +// connect to Blog DB to see if user has a SUCS blog + require_once("/usr/share/adodb/adodb.inc.php"); + $BlogDB = NewADOConnection('postgres8'); + $BlogDB->Connect('dbname=blogs'); + $BlogDB->SetFetchMode(ADODB_FETCH_ASSOC); + require_once('../lib/blog/validation.lib.php'); + if (blogger($session->username)) { + $smarty->assign("sucsblogger", TRUE); + $feed="http://sucs.org/blog/feed/atom/".$session->username; + if ($member['blogfeed'] == $feed) { + $smarty->assign("sucsblogfeed", TRUE); + } + } + + // change postgresql boolean to PHP boolean + if ($member['syndicateblog'] == 't') { + $member['syndicateblog'] = true; + } else { + $member['syndicateblog'] = false; + } + $smarty->assign('member', $member); + } $smarty->assign('url', $component['path']); diff --git a/components/planetconfig.php b/components/planetconfig.php new file mode 100644 index 0000000000000000000000000000000000000000..b3e1f50da62ff30f718ef7b4855155fcf2b2109d --- /dev/null +++ b/components/planetconfig.php @@ -0,0 +1,38 @@ +<?php +// component to dynamically generate a configuration file for the Planet feed aggregator + +global $base; + +// where to put the generated config file? +$outputfile = $base."lib/venus/sucs/generatedconfig.ini"; + +// Where Planet should output its generated files to +$planetoutputdir = $base."htdocs/planet"; + +$sucsdbname = "sucs"; +$hackergotchipath = "/var/www/sucssite/htdocs/pictures/people/"; + +// open connection to sucs database +$sucsDB = NewADOConnection('postgres8'); +$sucsDB->Connect('dbname='.$sucsdbname); +$sucsDB->SetFetchMode(ADODB_FETCH_ASSOC); + +// fetch blogroll +$blogroll = $sucsDB->GetAll("SELECT username, blogfeed AS feeduri FROM members WHERE syndicateblog=TRUE"); + +// figure out whether each user has a hackergotchi picture +foreach($blogroll as &$blog) { + if (is_file($hackergotchipath.$blog['username'].".png")) { + $blog['hackergotchi'] = TRUE; + } else { + $blog['hackergotchi'] = FALSE; + } +} + +$smarty->assign("blogroll", $blogroll); +$smarty->assign("planetoutputdir", $planetoutputdir); +$config = $smarty->fetch("planetconfig.tpl"); +file_put_contents($outputfile, $config); + + +?> diff --git a/templates/options.tpl b/templates/options.tpl index a9af61c8fabed91afa272b9fce9f3024bd86e060..b638d1798f2e1a8ceecb298128e3980994733f61 100644 --- a/templates/options.tpl +++ b/templates/options.tpl @@ -166,6 +166,42 @@ {/if} </fieldset> </form> + <form method="post" action="{$baseurl}{$path}"> + <input type="hidden" name="action" value="changeblogfeed" /> + <fieldset> + <legend>Blog Feed</legend> + +{* if the member has a SUCS blog, offer this *} +{if $sucsblogger} + <div class="row"> + <label for="blogtype">My SUCS Blog:</label> + <span class="textinput"> + <input type="radio" name="blogtype" value="sucs" {if $sucsblogfeed}checked="checked"{/if} /> + </span> + </div> +{/if} + <div class="row"> + <label for="bloguri">RSS/Atom feed:</label> + <span class="textinput"> + {if $sucsblogger} + <input type="radio" name="blogtype" value="custom" {if not $sucsblogfeed}checked="checked"{/if} /> + {/if} + <input type="text" name="bloguri" id="bloguri" style="width:90%;" value="{$member.blogfeed}" /> + </span> + </div> + <div class="row"> + <label for="syndicateblog">Display on Planet SUCS:</label> + <span class="textinput"> + <input type="checkbox" name="syndicateblog" id="syndicateblog" {if $member.syndicateblog}checked="checked"{/if} /> + </span> + </div> + <div class="row"> + <input type="submit" value="Change" /> + </div> + + + </fieldset> + </form> {if ($member.type == 1 || $member.type == 2) && $member.paid != $paydate} <form method="post" action="{$baseurl}{$path}"> diff --git a/templates/planetconfig.tpl b/templates/planetconfig.tpl new file mode 100644 index 0000000000000000000000000000000000000000..dda353fb3c1c26171cf57fae702cf4941d3a9f9d --- /dev/null +++ b/templates/planetconfig.tpl @@ -0,0 +1,67 @@ +# Planet configuration file + +[Planet] +name = Planet SUCS +link = http://www.sucs.org/planet +owner_name = SUCS Admin +owner_email = admin@sucs.org + +# cache_directory: Where cached feeds are stored +# new_feed_items: Number of items to take from new feeds +# log_level: One of DEBUG, INFO, WARNING, ERROR or CRITICAL +# feed_timeout: number of seconds to wait for any given feed +cache_directory = cache +new_feed_items = 2 +log_level = ERROR +feed_timeout = 20 + +# template_files: Space-separated list of output template files +template_files = sucs/Planet.txt.tmpl sucs/atom.xml.tmpl sucs/rss20.xml.tmpl sucs/rss10.xml.tmpl sucs/opml.xml.tmpl sucs/foafroll.xml.tmpl + +output_dir = {$planetoutputdir} +items_per_page = 50 +days_per_page = 0 +date_format = %b %d, %Y at %I:%M %p +new_date_format = %B %d, %Y +encoding = utf-8 +# locale = C + +# To define a different value for a particular template you may create +# a section with the same name as the template file's filename (as given +# in template_files). + +# If non-zero, all feeds which have not been updated in the indicated +# number of days will be marked as inactive +activity_threshold = 0 + +# Options placed in the [DEFAULT] section provide defaults for the feed +# sections. Placing a default here means you only need to override the +# special cases later. +#[DEFAULT] +# Hackergotchi default size. +# If we want to put a face alongside a feed, and it's this size, we +# can omit these variables. +#facewidth = 65 +#faceheight = 85 + +# Any other section defines a feed to subscribe to. The section title +# (in the []s) is the URI of the feed itself. A section can also be +# have any of the following options: +# +# name: Name of the feed (defaults to the title found in the feed) + + +#blogroll pulled from the database +{foreach from=$blogroll item=blog} +[{$blog.feeduri}] +name = {$blog.username} +{if $blog.hackergotchi} +face = {$blog.username}.png +{/if} + +{/foreach} + +#static entries + +#[http://sucs.org/blog/feed/atom/vote] +#name = Election 2008