--- /dev/null
+<?php
+$serendipity['smarty']->assign('content_message','
+<h3 class="serendipity_date">breakfast</h3>');
+
+
+
+
+?>
'{PAT_PERMALINK_CATEGORIES}',
'{PAT_PERMALINK_FEEDAUTHORS}',
'{PAT_ABOUT}', '{PATH_ABOUT}',
+ '{PAT_BREAKFAST}', '{PATH_BREAKFAST}',
'{PAT_GALLERY}','{PATH_GALLERY}',
),
trim($PAT['PERMALINK_CATEGORIES'], '@/i'),
trim($PAT['PERMALINK_FEEDAUTHORS'], '@/i'),
trim($PAT['ABOUT'], '@/i'), $serendipity['permalinkAboutPath'],
+ trim($PAT['BREAKFAST'], '@/i'), $serendipity['permalinkBreakfastPath'],
trim($PAT['GALLERY'],'@/i'), $serendipity['permalinkGalleryPath'],
),
if (!isset($serendipity['permalinkAboutPath'])) {
$serendipity['permalinkAboutPath'] = 'about';
}
-
+
+ if (!isset($serendipity['permalinkBreakfastPath'])) {
+ $serendipity['permalinkBreakfastPath'] = 'breakfast';
+ }
+
if (!isset($serendipity['permalinkGalleryPath'])) {
$serendipity['permalinkGalleryPath'] = 'gallery';
}
* backwards URL compatibility
*/
@define('PATH_ABOUT', $serendipity['permalinkAboutPath']);
+ @define('PATH_BREAKFAST', $serendipity['permalinkBreakfastPath']);
@define('PATH_GALLERY', $serendipity['permalinkGalleryPath']);
@define('PATH_ARCHIVES', $serendipity['permalinkArchivesPath']);
@define('PATH_ARCHIVE', $serendipity['permalinkArchivePath']);
* function serendipity_installFiles().
*/
@define('PAT_ABOUT', '@/'.PATH_ABOUT.'/?@');
+ @define('PAT_BREAKFAST', '@/'.PATH_BREAKFAST.'/?@');
@define('PAT_GALLERY','@/'.PATH_GALLERY.'/(.*)@');
@define('PAT_FILENAME', '0-9a-z\.\_!;,\+\-\%');
@define('PAT_FILENAME_MATCH', '[' . PAT_FILENAME . ']+');
$PAT = array();
$PAT['ABOUT'] = '@/' . $serendipity['permalinkAboutPath'];
+ $PAT['BREAKFAST'] = '@/' . $serendipity['permalinkBreakfastPath'];
$PAT['GALLERY'] = '@/' . $serendipity['permalinkGalleryPath'];
$PAT['UNSUBSCRIBE'] = '@/' . $serendipity['permalinkUnsubscribePath'].'/(.*)/([0-9]+)@';
$PAT['APPROVE'] = '@/' . $serendipity['permalinkApprovePath'].'/(.*)/(.*)/([0-9]+)@';
case 'about':
include_once(S9Y_INCLUDE_PATH.'include/about.inc.php');
break;
+ case 'breakfast':
+ include_once(S9Y_INCLUDE_PATH.'include/breakfast.inc.php');
+ break;
case 'gallery':
include_once(S9Y_INCLUDE_PATH.'include/gallery.inc.php');
break;
RewriteRule ^index\.(html?|php.+) {indexFile}?url=index.html [L,QSA]
RewriteRule ^htmlarea/(.*) htmlarea/$1 [L,QSA]
RewriteRule ^{PAT_ABOUT} {indexFile}?url=/{PAT_ABOUT}/ [L,QSA]
+RewriteRule ^{PAT_BREAKFAST} {indexFile}?url=/{PAT_BREAKFAST}/ [L,QSA]
RewriteRule (.*\.html?) {indexFile}?url=/$1 [L,QSA]
<Files *.tpl.php>
} else if (preg_match(PAT_ABOUT, $uri, $matches)) {
$serendipity['GET']['action'] = 'about';
include_once(S9Y_INCLUDE_PATH . 'include/genpage.inc.php');
+} else if (preg_match(PAT_BREAKFAST, $uri, $matches)) {
+ $serendipity['GET']['action'] = 'breakfast';
+ include_once(S9Y_INCLUDE_PATH . 'include/genpage.inc.php');
} else if (preg_match(PAT_GALLERY, $uri, $matches)) {
$serendipity['GET']['action'] = 'gallery';
include_once(S9Y_INCLUDE_PATH . 'include/genpage.inc.php');
@define('NEW_ENTRY', 'New Entry');
@define('EDIT_ENTRIES', 'Edit Entries');
@define('CATEGORIES', 'Categories');
+@define('BREAKFAST', 'Breakfast');
@define('WARNING_THIS_BLAHBLAH', "WARNING:\\nThis may take a long time if there are many images without thumbnails.");
@define('CREATE_THUMBS', 'Rebuild Thumbs');
@define('MANAGE_IMAGES', 'Manage Images');
@define('NEW_ENTRY', 'New Entry');
@define('EDIT_ENTRIES', 'Edit Entries');
@define('CATEGORIES', 'Categories');
+@define('BREAKFAST', 'Breakfast');
@define('WARNING_THIS_BLAHBLAH', "WARNING:\\nThis may take a long time if there are many images without thumbnails.");
@define('CREATE_THUMBS', 'Rebuild Thumbs');
@define('MANAGE_IMAGES', 'Manage Images');
--- /dev/null
+<?
+if (IN_serendipity !== true) {
+ die ("Don't hack!");
+}
+
+require_once(dirname(__FILE__).'/lib.php');
+
+switch ($serendipity['GET']['adminAction']) {
+
+ case 'new':
+ echo '
+ <form action="?" method="get">
+ <input type="hidden" name="serendipity[action]" value="admin" />
+ <input type="hidden" name="serendipity[adminModule]" value="breakfast" />
+ <input type="hidden" name="serendipity[adminAction]" value="save" />
+ <table>
+ <tr>
+ <td><input type="text" name="date" value="'.date('Y-m-d') .'" />
+ '.breakfast_cafe_dropdown() .' or <input type="text" name="cafe_free" /></td>
+ </tr>
+ <tr>
+ <td><textarea name="comment" rows="4" cols="70"></textarea></td>
+ </tr>
+';
+ for ($i = 0; $i < 10; $i++) {
+ echo '
+ <tr>
+ <td><hr /></td>
+ </tr>
+ <tr>
+ <td>'.breakfast_person_dropdown($i) .' or <input type="text" name="person_free'.$i.'" />
+ had '. breakfast_menu_dropdown($i) .' or <input type="text" name="meal_free'.$i.'" /></td>
+ </tr>
+ <tr>
+ <td>'. breakfast_scoring_dropdowns($i).'</td>
+ </tr>
+ <tr>
+ <td><input type="text" name="comment'.$i.'" size="70" /></td>
+ </tr>
+';
+ }
+
+
+echo '
+ <tr>
+ <td><input type="submit" value="Save" />
+ </tr>
+ </table>
+ </form>
+';
+ break;
+ case 'save':
+ // get the categories, we need these
+ $categories = serendipity_db_query('SELECT * FROM mbg_category');
+ // cafe first..
+ if (!empty($_GET['cafe_free'])) {
+ $sql = 'INSERT INTO mbg_cafe (name) values (\''.$_GET['cafe_free'].'\')';
+ serendipity_db_query($sql);
+ $cafeid = serendipity_db_insert_id();
+ } else {
+ $cafeid = $_GET['cafe'];
+ }
+
+ $date = strtotime($_GET['date']);
+
+ // make an event.
+ serendipity_db_query('INSERT INTO mbg_event (date,cafe'.((!empty($_GET['comment'])) ? ',comment' : '').')
+ VALUES ('.$date.','.$cafeid.((!empty($_GET['comment'])) ? ',\''.$_GET['comment'].'\'' : '').')');
+ $eventid = serendipity_db_insert_id();
+
+ for ($i = 0; $i < 10; $i++) {
+ // person, meal, then scores.
+ if (empty($_GET['person'.$i]) && empty($_GET['person_free'.$i])) {
+ continue;
+ }
+ // new people first
+ if (!empty($_GET['person_free'.$i])) {
+ // look for an alias
+ $sql = 'INSERT INTO mbg_person (name';
+ $values = ' VALUES (\'';
+ if (preg_match('/([a-zA-Z0-9]*)\s\(([^\)]*)\)/',$_GET['person_free'.$i],$matches)) {
+ $sql .= ',alias';
+ $values .= $matches[1].'\',\''.$matches[2];
+ } else {
+ $values .= $_GET['person_free'.$i];
+ }
+ $sql .= ') '.$values.'\') ';
+ serendipity_db_query($sql);
+ $personid = serendipity_db_insert_id();
+ } else {
+ $personid = $_GET['person'.$i];
+ }
+ if (!empty($_GET['meal_free'.$i])) {
+ $sql = 'INSERT INTO mbg_meal (cafe, name) VALUES ('.$cafeid.',\''.$_GET['meal_free'.$i].'\');';
+ serendipity_db_query($sql);
+ $mealid = serendipity_db_insert_id();
+ } else {
+ $mealid = $_GET['meal'.$i];
+ }
+ // now we can make an attendee... then just score to go
+ $sql = "INSERT INTO mbg_attendee (event,person,ate,comment) VALUES ($eventid,$personid,$mealid,".
+ ((!empty($_GET['comment'.$i])) ? "'".$_GET['comment'.$i]."'" : 'null')
+ .')';
+ serendipity_db_query($sql);
+ $attendee = serendipity_db_insert_id();
+ foreach ($categories as $cat) {
+ //score-catid-$i
+ if (!empty($_GET['score-'.$cat['id'].'-'.$i])) {
+ $score = $_GET['score-'.$cat['id'].'-'.$i];
+ $sql = "INSERT INTO mbg_score (attendee, category, score) VALUES ($attendee,".$cat['id'].",$score)";
+ serendipity_db_query($sql);
+ }
+ }
+ echo 'Saved!';
+ }
+
+ break;
+}
+
+
+
+?>
\ No newline at end of file
--- /dev/null
+<?php
+define('PLUGIN_BREAKFAST_TITLE','mbg');
+define('PLUGIN_BREAKFAST_DESC','mbg breakfast');
+?>
\ No newline at end of file
--- /dev/null
+<?
+if (IN_serendipity !== true) {
+ die ("Don't hack!");
+}
+
+
+function breaKfast_cafe_dropdown() {
+ $output = '
+ <select name="cafe">
+ <option value="0">-- Cafe --</option>';
+ $results = serendipity_db_query('SELECT * FROM mbg_cafe');
+ foreach ($results as $r) {
+ $output .='<option value="'.$r['id'].'">'.$r['name'].'</option>';
+ }
+ $output .= '</select>';
+ return $output;
+}
+function breakfast_person_dropdown($count) {
+ static $people;
+ if (empty($people)) {
+ $people = serendipity_db_query('SELECT * FROM mbg_person');
+ }
+ $output = '
+ <select name="person'.$count.'">
+ <option value="0">-- Person --</option>';
+ foreach ($people as $person) {
+ $output .= '<option value="'.$person['id'].'">'.$person['name'].((!empty($person['alias'])) ? '('.$person['alias'].')' : '').'</option>';
+ }
+ $output .= '</select>';
+ return $output;
+}
+function breakfast_menu_dropdown($count) {
+ static $menu;
+ if (empty($menu)) {
+ $menu = serendipity_db_query('SELECT m.id,m.name,c.name as cafe FROM mbg_meal m LEFT JOIN mbg_cafe c ON m.cafe = c.id');
+ }
+ $output = '
+ <select name="meal'.$count.'">
+ <option value="0">-- Meal --</option>';
+ foreach ($menu as $item) {
+ $output .= '<option value="'.$item['id'].'">'.((!empty($item['cafe'])) ? '('.$item['cafe'].')' : '').$item['name'].'</option>';
+ }
+ $output .= '</select>';
+ return $output;
+}
+function breakfast_scoring_dropdowns($count) {
+ static $categories;
+ if (empty($categories)) {
+ $categories = serendipity_db_query('SELECT * FROM mbg_category');
+ }
+ $output = '';
+ foreach ($categories as $i => $c) {
+ $output .= $c['category'].' ('.$c['weight'].') : <input size="2" maxlength="2" type="text" name="score-'.$c['id'].'-'.$count.'" /> ';
+ if ($i == 3) {
+ $output .= '<br />';
+ }
+ }
+ return $output;
+
+}
+
+function breakfast_get_latest() {
+ $sql = 'SELECT c.name, e.date, e.id as event, count(a.id) as num FROM mbg_cafe c
+ JOIN mbg_event e ON e.cafe = c.id
+ JOIN mbg_attendee a ON a.event = e.id GROUP BY a.event';
+ if (!$latest = serendipity_db_query($sql,true)) {
+ return false;
+ }
+ $sql = 'SELECT p.name,p.alias,m.name as meal, a.id FROM mbg_attendee a JOIN mbg_person p ON a.person = p.id JOIN mbg_meal m ON a.ate = m.id
+ WHERE a.event = '.$latest['event'].' ORDER BY rand() LIMIT 1';
+ $latest['random'] = serendipity_db_query($sql,true);
+ $sql = 'SELECT s.score,c.weight,c.category FROM mbg_score s JOIN mbg_category c ON s.category = c.id WHERE s.attendee = '.$latest['random']['id'];
+ $latest['random']['scores'] = serendipity_db_query($sql);
+ $sql = 'SELECT sum(s.score) as score, sum(c.weight) as weight FROM mbg_score s
+ JOIN mbg_category c ON s.category = c.id
+ JOIN mbg_attendee a ON s.attendee = a.id WHERE a.event = '.$latest['event'].' GROUP BY s.attendee';
+ $totals = serendipity_db_query($sql);
+ $num = 0;
+ $grandtotal = 0;
+ $min = 100;
+ $max = 0;
+ $thistotal = 0;
+ foreach ($totals as $total) {
+ if ($total['weight'] != 100) {
+ $thistotal = (($total['score']/$total['weight']) * 100);
+ $grandtotal += $thistotal;
+ }
+ else {
+ $grandtotal += $total['score'];
+ $thistotal = $total['score'];
+ }
+ $num++;
+ if ($thistotal < $min) {
+ $min = $thistotal;
+ }
+ if ($thistotal > $max) {
+ $max = $thistotal;
+ }
+ }
+ $latest['total'] = $grandtotal/$num;
+ $latest['min'] = $min;
+ $latest['max'] = $max;
+ return $latest;
+}
+
+?>
\ No newline at end of file
--- /dev/null
+<?php
+
+require_once(dirname(__FILE__) . '/lang_en.inc.php');
+require_once(dirname(__FILE__) . '/lib.php');
+
+class serendipity_plugin_breakfast extends serendipity_plugin
+{
+ var $tags = array();
+ var $title = PLUGIN_BREAKFAST_TITLE;
+
+ function introspect(&$propbag)
+ {
+ global $serendipity;
+
+ $propbag->add('name', PLUGIN_BREAKFAST_TITLE);
+ $propbag->add('description', PLUGIN_BREAKFAST_DESC);
+ $propbag->add('stackable', false);
+ $propbag->add('author', 'Penny Leach');
+ $propbag->add('requirements', array(
+ 'serendipity' => '0.8',
+ 'smarty' => '2.6.7',
+ 'php' => '4.1.0'
+ ));
+ $propbag->add('version', '1.0');
+ $propbag->add('plugin_hooks', array());
+ }
+
+ function introspect_config_item($name, &$propbag)
+ {
+ return true;
+ }
+
+ function generate_content(&$title) {
+ if (!$latest = breakfast_get_latest()) {
+ return false;
+ }
+ $title = $this->title;
+ echo '
+<table>
+ <tr>
+ <td colspan="2" nowrap="nowrap"><b>Most recent breakfast:</b></td>
+ </tr>
+ <tr>
+ <td colspan="2">'.$latest['name'].' on '.date('j F Y',$latest['date']).' with '.$latest['num'].' people</td>
+ </tr>
+ <tr>
+ <td colspan="2"><b>'.((!empty($latest['random']['alias'])) ? $latest['random']['alias'] : $latest['random']['name'])
+ .' had \''.$latest['random']['meal'].'\':</b></td>
+ </tr>';
+ $total = 0;
+ $totalweight = 0;
+ foreach ($latest['random']['scores'] as $score) {
+ echo ' <tr>
+ <td>'.$score['category'].':</td><td>'.$score['score'].'/'.$score['weight'].'</td>
+ </tr>';
+ $total += $score['score'];
+ $totalweight += $score['weight'];
+ }
+ if ($totalweight != 100) {
+ $total = ($total/$totalweight) * 100;
+ }
+ echo ' <tr>
+ <td>Total</td><td>'.$total.'%</td>
+ </tr>
+ <tr>
+ <td colspan="2"><b>The group gave:</td>
+ </tr>
+ <tr>
+ <td>Min:</td><td>'.$latest['min'].'%</td>
+ </tr>
+ <tr>
+ <td>Max:</td><td>'.$latest['max'].'%</td>
+ </tr>
+ <tr>
+ <td>Avergage:</td><td>'.$latest['total'].'%</td>
+ </tr>
+ <tr>
+ <td nowrap="nowrap" colspan="2"><a href="/breakfast/">What the hell is this?</a></td>
+ </tr>
+</table>';
+ return;
+ }
+
+ function tableCreated() {
+ global $serendipity;
+
+ $q = "select count(id) from mbg_category";
+ $row = serendipity_db_query($q, true, 'num');
+
+ if (!is_numeric($row[0])) { // if the response we got back was an SQL error.. :P
+ return false;
+ } else {
+ return true;
+ }
+ }
+
+ function install() {
+ global $serendipity;
+
+ if (!serendipity_plugin_breakfast::tableCreated()) {
+ $qs = $this->getcreatesql();
+ foreach ($qs as $q) {
+ $result = serendipity_db_schema_import($q);
+ }
+ serendipity_db_query('INSERT INTO mbg_category (category, weight) VALUES (\'Eggs\',10);');
+ serendipity_db_query('INSERT INTO mbg_category (category, weight) VALUES (\'Meat\',10);');
+ serendipity_db_query('INSERT INTO mbg_category (category, weight) VALUES (\'Hygiene\',10);');
+ serendipity_db_query('INSERT INTO mbg_category (category, weight) VALUES (\'Atmosphere\',10);');
+ serendipity_db_query('INSERT INTO mbg_category (category, weight) VALUES (\'Food overall\',20);');
+ serendipity_db_query('INSERT INTO mbg_category (category, weight) VALUES (\'Coffee\',20);');
+ serendipity_db_query('INSERT INTO mbg_category (category, weight) VALUES (\'Service\',20);');
+ }
+ return true;
+ }
+
+ function getcreatesql() {
+ return array(
+ 'CREATE TABLE mbg_cafe (
+ id int(10) not null auto_increment,
+ name varchar(50) not null,
+ address varchar(100),
+ url varchar(100),
+ PRIMARY KEY (id)
+);',
+ 'CREATE TABLE mbg_meal (
+ id int(10) not null auto_increment,
+ cafe int(10),
+ name varchar(50),
+ PRIMARY KEY (id)
+);',
+ 'CREATE TABLE mbg_person (
+ id int(10) not null auto_increment,
+ name varchar(50) not null,
+ alias varchar(100),
+ PRIMARY KEY (id)
+);',
+ 'CREATE TABLE mbg_event (
+ id int(10) not null auto_increment,
+ date int(10) not null,
+ cafe int(10) not null,
+ comment text,
+ PRIMARY KEY (id)
+);',
+ 'CREATE TABLE mbg_attendee (
+ id int(10) not null auto_increment,
+ event int(10) not null,
+ person int(10) not null,
+ ate int(10) not null,
+ comment text,
+ PRIMARY KEY (id)
+);',
+ 'CREATE TABLE mbg_category (
+ id int(10) not null auto_increment,
+ category varchar(20) not null,
+ weight int(2),
+ PRIMARY KEY (id)
+);',
+ 'CREATE TABLE mbg_score (
+ id int(10) not null auto_increment,
+ attendee int(10) not null,
+ category int (10) not null,
+ score int(2) not null,
+ PRIMARY KEY (id)
+);',
+ );
+ }
+}
+
+/* vim: set sts=4 ts=4 expandtab : */
case 'logout':
echo LOGGEDOUT;
break;
-
+ case 'breakfast':
+ include S9Y_INCLUDE_PATH . 'plugins/serendipity_plugin_breakfast/admin.inc.php';
+ break;
+
default:
include S9Y_INCLUDE_PATH . 'include/admin/overview.inc.php';
break;
<?php if (serendipity_checkPermission('adminCategories')) { ?>
<li class="serendipitySideBarMenuLink serendipitySideBarMenuEntryLinks"><a href="serendipity_admin.php?serendipity[adminModule]=category&serendipity[adminAction]=view"><?php echo CATEGORIES; ?></a></li>
<?php } ?>
+ <li><a href="serendipity_admin.php?serendipity[adminModule]=breakfast&serendipity[adminAction]=new"><?php echo BREAKFAST; ?></a></li>
<?php if (serendipity_checkPermission('adminEntries') || serendipity_checkPermission('adminEntriesPlugins')) { ?>
<?php if ($serendipity['no_create'] !== true) serendipity_plugin_api::hook_event('backend_sidebar_entries', $serendipity); ?>
<?php } ?>