From eccf753a4abd2d75e108ebfb981d1c73bcfb274b Mon Sep 17 00:00:00 2001 From: Penny Leach Date: Sun, 18 Jun 2006 16:19:58 +1200 Subject: [PATCH] beginnings of breakfast support. main page to come ! --- include/breakfast.inc.php | 8 + include/functions_installer.inc.php | 2 + include/functions_permalinks.inc.php | 9 +- include/genpage.inc.php | 3 + include/tpl/htaccess_rewrite.tpl | 1 + index.php | 3 + lang/UTF-8/serendipity_lang_en.inc.php | 1 + lang/serendipity_lang_en.inc.php | 1 + .../admin.inc.php | 122 +++++++++++++ .../lang_en.inc.php | 4 + plugins/serendipity_plugin_breakfast/lib.php | 106 +++++++++++ .../serendipity_plugin_breakfast.php | 169 ++++++++++++++++++ serendipity_admin.php | 6 +- 13 files changed, 433 insertions(+), 2 deletions(-) create mode 100644 include/breakfast.inc.php create mode 100644 plugins/serendipity_plugin_breakfast/admin.inc.php create mode 100644 plugins/serendipity_plugin_breakfast/lang_en.inc.php create mode 100644 plugins/serendipity_plugin_breakfast/lib.php create mode 100644 plugins/serendipity_plugin_breakfast/serendipity_plugin_breakfast.php diff --git a/include/breakfast.inc.php b/include/breakfast.inc.php new file mode 100644 index 0000000..e09b4a5 --- /dev/null +++ b/include/breakfast.inc.php @@ -0,0 +1,8 @@ +assign('content_message',' +

breakfast

'); + + + + +?> diff --git a/include/functions_installer.inc.php b/include/functions_installer.inc.php index a3a06b7..2717bb3 100644 --- a/include/functions_installer.inc.php +++ b/include/functions_installer.inc.php @@ -878,6 +878,7 @@ function serendipity_installFiles($serendipity_core = '') { '{PAT_PERMALINK_CATEGORIES}', '{PAT_PERMALINK_FEEDAUTHORS}', '{PAT_ABOUT}', '{PATH_ABOUT}', + '{PAT_BREAKFAST}', '{PATH_BREAKFAST}', '{PAT_GALLERY}','{PATH_GALLERY}', ), @@ -903,6 +904,7 @@ function serendipity_installFiles($serendipity_core = '') { 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'], ), diff --git a/include/functions_permalinks.inc.php b/include/functions_permalinks.inc.php index 1124b34..712df43 100644 --- a/include/functions_permalinks.inc.php +++ b/include/functions_permalinks.inc.php @@ -234,7 +234,11 @@ function serendipity_initPermalinks() { if (!isset($serendipity['permalinkAboutPath'])) { $serendipity['permalinkAboutPath'] = 'about'; } - + + if (!isset($serendipity['permalinkBreakfastPath'])) { + $serendipity['permalinkBreakfastPath'] = 'breakfast'; + } + if (!isset($serendipity['permalinkGalleryPath'])) { $serendipity['permalinkGalleryPath'] = 'gallery'; } @@ -244,6 +248,7 @@ function serendipity_initPermalinks() { * 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']); @@ -264,6 +269,7 @@ function serendipity_initPermalinks() { * 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 . ']+'); @@ -287,6 +293,7 @@ function &serendipity_permalinkPatterns($return = false) { $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]+)@'; diff --git a/include/genpage.inc.php b/include/genpage.inc.php index 9060080..cabdf81 100644 --- a/include/genpage.inc.php +++ b/include/genpage.inc.php @@ -111,6 +111,9 @@ if ($serendipity['smarty_raw_mode']) { 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; diff --git a/include/tpl/htaccess_rewrite.tpl b/include/tpl/htaccess_rewrite.tpl index 27b259e..4c7704a 100644 --- a/include/tpl/htaccess_rewrite.tpl +++ b/include/tpl/htaccess_rewrite.tpl @@ -28,6 +28,7 @@ RewriteRule ^{PAT_CSS} {indexFile}?url=/$1 [L,QSA] 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] diff --git a/index.php b/index.php index 4cac1be..d20b6c8 100644 --- a/index.php +++ b/index.php @@ -532,6 +532,9 @@ if (preg_match(PAT_ARCHIVES, $uri, $matches) || isset($serendipity['GET']['range } 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'); diff --git a/lang/UTF-8/serendipity_lang_en.inc.php b/lang/UTF-8/serendipity_lang_en.inc.php index 27ca922..3ab9425 100644 --- a/lang/UTF-8/serendipity_lang_en.inc.php +++ b/lang/UTF-8/serendipity_lang_en.inc.php @@ -53,6 +53,7 @@ @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'); diff --git a/lang/serendipity_lang_en.inc.php b/lang/serendipity_lang_en.inc.php index 0d24c69..1f74fd7 100644 --- a/lang/serendipity_lang_en.inc.php +++ b/lang/serendipity_lang_en.inc.php @@ -53,6 +53,7 @@ @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'); diff --git a/plugins/serendipity_plugin_breakfast/admin.inc.php b/plugins/serendipity_plugin_breakfast/admin.inc.php new file mode 100644 index 0000000..15ec874 --- /dev/null +++ b/plugins/serendipity_plugin_breakfast/admin.inc.php @@ -0,0 +1,122 @@ + + + + + + + + + + + +'; + for ($i = 0; $i < 10; $i++) { + echo ' + + + + + + + + + + + + +'; + } + + +echo ' + + +
+ '.breakfast_cafe_dropdown() .' or

'.breakfast_person_dropdown($i) .' or + had '. breakfast_menu_dropdown($i) .' or
'. breakfast_scoring_dropdowns($i).'
+
+ +'; + 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 diff --git a/plugins/serendipity_plugin_breakfast/lang_en.inc.php b/plugins/serendipity_plugin_breakfast/lang_en.inc.php new file mode 100644 index 0000000..1f4e885 --- /dev/null +++ b/plugins/serendipity_plugin_breakfast/lang_en.inc.php @@ -0,0 +1,4 @@ + \ No newline at end of file diff --git a/plugins/serendipity_plugin_breakfast/lib.php b/plugins/serendipity_plugin_breakfast/lib.php new file mode 100644 index 0000000..bca5978 --- /dev/null +++ b/plugins/serendipity_plugin_breakfast/lib.php @@ -0,0 +1,106 @@ + + '; + $results = serendipity_db_query('SELECT * FROM mbg_cafe'); + foreach ($results as $r) { + $output .=''; + } + $output .= ''; + return $output; +} +function breakfast_person_dropdown($count) { + static $people; + if (empty($people)) { + $people = serendipity_db_query('SELECT * FROM mbg_person'); + } + $output = ' + '; + 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 = ' + '; + 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'].') : '; + if ($i == 3) { + $output .= '
'; + } + } + 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 diff --git a/plugins/serendipity_plugin_breakfast/serendipity_plugin_breakfast.php b/plugins/serendipity_plugin_breakfast/serendipity_plugin_breakfast.php new file mode 100644 index 0000000..ea93883 --- /dev/null +++ b/plugins/serendipity_plugin_breakfast/serendipity_plugin_breakfast.php @@ -0,0 +1,169 @@ +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 ' + + + + + + + + + + '; + $total = 0; + $totalweight = 0; + foreach ($latest['random']['scores'] as $score) { + echo ' + + '; + $total += $score['score']; + $totalweight += $score['weight']; + } + if ($totalweight != 100) { + $total = ($total/$totalweight) * 100; + } + echo ' + + + + + + + + + + + + + + + + + +
Most recent breakfast:
'.$latest['name'].' on '.date('j F Y',$latest['date']).' with '.$latest['num'].' people
'.((!empty($latest['random']['alias'])) ? $latest['random']['alias'] : $latest['random']['name']) + .' had \''.$latest['random']['meal'].'\':
'.$score['category'].':'.$score['score'].'/'.$score['weight'].'
Total'.$total.'%
The group gave:
Min:'.$latest['min'].'%
Max:'.$latest['max'].'%
Avergage:'.$latest['total'].'%
What the hell is this?
'; + 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 : */ diff --git a/serendipity_admin.php b/serendipity_admin.php index 7b97cb8..135e337 100644 --- a/serendipity_admin.php +++ b/serendipity_admin.php @@ -214,7 +214,10 @@ if (!$use_installer && $is_logged_in) { 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; @@ -381,6 +384,7 @@ if ($use_installer) { +
  • -- 2.39.5