From a930e827048acf17d04a6af06c1616a72dee714a Mon Sep 17 00:00:00 2001 From: Starla Insigna Date: Sun, 7 Dec 2008 16:45:24 -0500 Subject: Added support for a variable amount of tags Previously, the blogging engine only allowed for three tags per post, and it also stored each in seperate fields. Now, all tags are stored in one field and there can be more than three. The only functionality that has been removed because of this is that now, on archive pages, tags are not shown next to the current month's posts as they used to be, because the Four Island templating system does not yet support sub-blocks of sub-blocks. --- pages/admin.php | 64 +++++++++++++++++++++++++++++++------------------------ pages/blog.php | 18 ++++++++-------- pages/welcome.php | 9 +++++--- 3 files changed, 51 insertions(+), 40 deletions(-) (limited to 'pages') diff --git a/pages/admin.php b/pages/admin.php index 8534d91..56542f9 100755 --- a/pages/admin.php +++ b/pages/admin.php @@ -37,9 +37,11 @@ if (isLoggedIn()) { $template = new FITemplate('admin/write'); } else { + $tags = mysql_real_escape_string(serialize(explode(',', $_POST['tags']))); + if ($_POST['type'] == 'draft') { - $insdraft = "INSERT INTO drafts (title,author,text,tag1,tag2,tag3,slug) VALUES (\"" . addslashes($_POST['title']) . "\",\"" . sess_get('uname') . "\",\"" . addslashes($_POST['text']) . "\",\"" . $_POST['tag1'] . "\",\"" . $_POST['tag2'] . "\",\"" . $_POST['tag3'] . "\",\"" . generateSlug($_POST['title'],'updates') . "\")"; + $insdraft = "INSERT INTO drafts (title,author,text,tags,slug) VALUES (\"" . addslashes($_POST['title']) . "\",\"" . sess_get('uname') . "\",\"" . addslashes($_POST['text']) . "\",\"" . $tags . "\",\"" . generateSlug($_POST['title'],'updates') . "\")"; $insdraft2 = mysql_query($insdraft); $getdraft = "SELECT * FROM drafts ORDER BY id DESC LIMIT 0,1"; @@ -50,7 +52,7 @@ if (isLoggedIn()) $template->add('ID', $getdraft3['id']); } else if ($_POST['type'] == 'instant') { - postBlogPost($_POST['title'], sess_get('uname'), $_POST['tag1'], $_POST['tag2'], $_POST['tag3'], $_POST['text']); + postBlogPost($_POST['title'], sess_get('uname'), $tags, $_POST['text']); $getpost = "SELECT * FROM updates ORDER BY id DESC LIMIT 0,1"; $getpost2 = mysql_query($getpost); @@ -86,7 +88,7 @@ if (isLoggedIn()) generateError(404); } - $inspending = "INSERT INTO pending (id,title,author,text,tag1,tag2,tag3,slug) VALUES (" . $id . ",\"" . addslashes($_POST['title']) . "\",\"" . sess_get('uname') . "\",\"" . addslashes($_POST['text']) . "\",\"" . $_POST['tag1'] . "\",\"" . $_POST['tag2'] . "\",\"" . $_POST['tag3'] . "\",\"" . generateSlug($_POST['title'],'updates') . "\")"; + $inspending = "INSERT INTO pending (id,title,author,text,tags,slug) VALUES (" . $id . ",\"" . addslashes($_POST['title']) . "\",\"" . sess_get('uname') . "\",\"" . addslashes($_POST['text']) . "\",\"" . $tags . "\",\"" . generateSlug($_POST['title'],'updates') . "\")"; $inspending2 = mysql_query($inspending); $template = new FITemplate('admin/pendingSuccess'); @@ -120,21 +122,21 @@ if (isLoggedIn()) $template = new FITemplate('admin/editDraft'); $template->add('ID', $_GET['id']); $template->add('TEXT', $getdraft3['text']); - $template->add('TAG1', $getdraft3['tag1']); - $template->add('TAG2', $getdraft3['tag2']); - $template->add('TAG3', $getdraft3['tag3']); + $template->add('TAGS', implode(',', unserialize($getdraft3['tags']))); $template->add('TITLE', $getdraft3['title']); } else { + $tags = mysql_real_escape_string(serialize(explode(',', $_POST['tags']))); + if ($_POST['type'] == 'draft') { - $setdraft = "UPDATE drafts SET title = \"" . addslashes($_POST['title']) . "\", text = \"" . addslashes($_POST['text']) . "\", tag1 = \"" . $_POST['tag1'] . "\", tag2 = \"" . $_POST['tag2'] . "\", tag3 = \"" . $_POST['tag3'] . "\" WHERE id = " . $_GET['id']; + $setdraft = "UPDATE drafts SET title = \"" . addslashes($_POST['title']) . "\", text = \"" . addslashes($_POST['text']) . "\", tags = \"" . $tags . "\" WHERE id = " . $_GET['id']; $setdraft2 = mysql_query($setdraft); $template = new FITemplate('admin/draftSuccess'); $template->add('ID', $_GET['id']); } else if ($_POST['type'] == 'instant') { - postBlogPost($_POST['title'], sess_get('uname'), $_POST['tag1'], $_POST['tag2'], $_POST['tag3'], $_POST['text']); + postBlogPost($_POST['title'], sess_get('uname'), $tags, $_POST['text']); $deldraft = "DELETE FROM drafts WHERE id = " . $_GET['id']; $deldraft2 = mysql_query($deldraft); @@ -173,7 +175,7 @@ if (isLoggedIn()) generateError(404); } - $inspending = "INSERT INTO pending (id,title,author,text,tag1,tag2,tag3,slug) VALUES (" . $id . ",\"" . addslashes($_POST['title']) . "\",\"" . sess_get('uname') . "\",\"" . addslashes($_POST['text']) . "\",\"" . $_POST['tag1'] . "\",\"" . $_POST['tag2'] . "\",\"" . $_POST['tag3'] . "\",\"" . generateSlug($_POST['title'],'updates') . "\")"; + $inspending = "INSERT INTO pending (id,title,author,text,tags,slug) VALUES (" . $id . ",\"" . addslashes($_POST['title']) . "\",\"" . sess_get('uname') . "\",\"" . addslashes($_POST['text']) . "\",\"" . $tags . "\",\"" . generateSlug($_POST['title'],'updates') . "\")"; $inspending2 = mysql_query($inspending); $deldraft = "DELETE FROM drafts WHERE id = " . $_GET['id']; @@ -221,7 +223,7 @@ if (isLoggedIn()) { $template = new FITemplate('post'); $template->adds_block('INTERNAL',array('exi'=>1)); - $template->adds_block('POST', array( 'ID' => $getdraft3['id'], + $template->add_ref(0, 'POST', array( 'ID' => $getdraft3['id'], 'YEARID' => ((date('Y')-2006) % 4), 'DATE' => date('F dS Y \a\\t g:i:s a'), 'MONTH' => date('M'), @@ -229,11 +231,14 @@ if (isLoggedIn()) 'CODED' => $getdraft3['slug'], 'TITLE' => $getdraft3['title'], 'AUTHOR' => $getdraft3['author'], - 'TAG1' => $getdraft3['tag1'], - 'TAG2' => $getdraft3['tag2'], - 'TAG3' => $getdraft3['tag3'], 'RATING' => 0, - 'TEXT' => parseBBCode($getdraft3['text']))); + 'TEXT' => parseBBCode($getdraft3['text']))); + + $tags = unserialize($getdraft3['tags']); + foreach ($tags as $tag) + { + $template->adds_ref_sub(0, 'TAGS', array('TAG' => $tag)); + } } else { $template = new FITemplate('msg'); $template->add('BACK', 'the previous page'); @@ -266,12 +271,12 @@ if (isLoggedIn()) $template = new FITemplate('admin/editPending'); $template->add('ID', $_GET['id']); $template->add('TEXT', $getpending3['text']); - $template->add('TAG1', $getpending3['tag1']); - $template->add('TAG2', $getpending3['tag2']); - $template->add('TAG3', $getpending3['tag3']); + $template->add('TAGS', implode(',', unserialize($getdraft3['tags']))); $template->add('TITLE', $getpending3['title']); } else { - $setpending = "UPDATE pending SET title = \"" . addslashes($_POST['title']) . "\", text = \"" . addslashes($_POST['text']) . "\", tag1 = \"" . $_POST['tag1'] . "\", tag2 = \"" . $_POST['tag2'] . "\", tag3 = \"" . $_POST['tag3'] . "\" WHERE id = " . $_GET['id']; + $tags = mysql_real_escape_string(serialize(explode(',', $_POST['tags']))); + + $setpending = "UPDATE pending SET title = \"" . addslashes($_POST['title']) . "\", text = \"" . addslashes($_POST['text']) . "\", tags = \"" . $tags . "\" WHERE id = " . $_GET['id']; $setpending2 = mysql_query($setpending); $template = new FITemplate('admin/pendingSuccess'); @@ -315,7 +320,7 @@ if (isLoggedIn()) { $template = new FITemplate('post'); $template->adds_block('INTERNAL',array('exi'=>1)); - $template->adds_block('POST', array( 'ID' => $getpending3['id'], + $template->add_ref(0, 'POST', array( 'ID' => $getpending3['id'], 'YEARID' => ((date('Y')-2006) % 4), 'DATE' => date('F dS Y \a\\t g:i:s a'), 'MONTH' => date('M'), @@ -323,11 +328,14 @@ if (isLoggedIn()) 'CODED' => $getpending3['slug'], 'TITLE' => $getpending3['title'], 'AUTHOR' => $getpending3['author'], - 'TAG1' => $getpending3['tag1'], - 'TAG2' => $getpending3['tag2'], - 'TAG3' => $getpending3['tag3'], 'RATING' => 0, 'TEXT' => parseBBCode($getpending3['text']))); + + $tags = unserialize($getpending3['tags']); + foreach ($tags as $tag) + { + $template->adds_ref_sub(0, 'TAGS', array('TAG' => $tag)); + } } else { $template = new FITemplate('msg'); $template->add('BACK', 'the previous page'); @@ -376,10 +384,10 @@ if (isLoggedIn()) $delpending = "DELETE FROM pending WHERE id = " . $_GET['id'] . " OR id = " . $otherPending['id']; $delpending2 = mysql_query($delpending); - $inspending = "INSERT INTO pending (id, title, author, text, tag1, tag2, tag3, slug) VALUES (" . $_GET['id'] . ",\"" . $otherPending['title'] . "\",\"" . $otherPending['author'] . "\",\"" . $otherPending['text'] . "\",\"" . $otherPending['tag1'] . "\",\"" . $otherPending['tag2'] . "\",\"" . $otherPending['tag3'] . "\",\"" . $otherPending['slug'] . "\")"; + $inspending = "INSERT INTO pending (id, title, author, text, tags, slug) VALUES (" . $_GET['id'] . ",\"" . $otherPending['title'] . "\",\"" . $otherPending['author'] . "\",\"" . $otherPending['text'] . "\",\"" . $otherPending['tags'] . "\",\"" . $otherPending['slug'] . "\")"; $inspending2 = mysql_query($inspending); - $ins2pending = "INSERT INTO pending (id, title, author, text, tag1, tag2, tag3, slug) VALUES (" . $otherPending['id'] . ",\"" . $getpending3['title'] . "\",\"" . $getpending3['author'] . "\",\"" . $getpending3['text'] . "\",\"" . $getpending3['tag1'] . "\",\"" . $getpending3['tag2'] . "\",\"" . $getpending3['tag3'] . "\",\"" . $getpending3['slug'] . "\")"; + $ins2pending = "INSERT INTO pending (id, title, author, text, tags, slug) VALUES (" . $otherPending['id'] . ",\"" . $getpending3['title'] . "\",\"" . $getpending3['author'] . "\",\"" . $getpending3['text'] . "\",\"" . $getpending3['tags'] . "\",\"" . $getpending3['slug'] . "\")"; $ins2pending2 = mysql_query($ins2pending); $template = new FITemplate('admin/managePending'); @@ -428,12 +436,12 @@ if (isLoggedIn()) $template = new FITemplate('admin/editPost'); $template->add('ID', $_GET['id']); $template->add('TEXT', $getpost3['text']); - $template->add('TAG1', $getpost3['tag1']); - $template->add('TAG2', $getpost3['tag2']); - $template->add('TAG3', $getpost3['tag3']); + $template->add('TAGS', implode(',', unserialize($getpost3['tags']))); $template->add('TITLE', $getpost3['title']); } else { - $setpost = "UPDATE updates SET title = \"" . addslashes($_POST['title']) . "\", text = \"" . addslashes($_POST['text']) . "\", tag1 = \"" . $_POST['tag1'] . "\", tag2 = \"" . $_POST['tag2'] . "\", tag3 = \"" . $_POST['tag3'] . "\" WHERE id = " . $_GET['id']; + $tags = mysql_real_escape_string(serialize(explode(',', $_POST['tags']))); + + $setpost = "UPDATE updates SET title = \"" . addslashes($_POST['title']) . "\", text = \"" . addslashes($_POST['text']) . "\", tags = \"" . $tags . "\" WHERE id = " . $_GET['id']; $setpost2 = mysql_query($setpost); $template = new FITemplate('admin/postSuccess'); diff --git a/pages/blog.php b/pages/blog.php index bb47755..c3f656b 100755 --- a/pages/blog.php +++ b/pages/blog.php @@ -63,7 +63,7 @@ if (isset($_GET['post'])) 'TITLE' => $getnext3['title'])); } - $template->adds_block('POST', array( 'ID' => $getpost3['id'], + $template->add_ref(0, 'POST', array( 'ID' => $getpost3['id'], 'YEARID' => ((date('Y',strtotime($getpost3['pubDate']))-2006) % 4), 'DATE' => date('F dS Y \a\\t g:i:s a',strtotime($getpost3['pubDate'])), 'MONTH' => date('M',strtotime($getpost3['pubDate'])), @@ -71,12 +71,15 @@ if (isset($_GET['post'])) 'CODED' => $getpost3['slug'], 'TITLE' => $getpost3['title'], 'AUTHOR' => $getpost3['author'], - 'TAG1' => $getpost3['tag1'], - 'TAG2' => $getpost3['tag2'], - 'TAG3' => $getpost3['tag3'], 'RATING' => $getpost3['rating'], 'TEXT' => parseBBCode($getpost3['text']))); + $tags = unserialize($getpost3['tags']); + foreach ($tags as $tag) + { + $template->adds_ref_sub(0, 'TAGS', array('TAG' => $tag)); + } + $template->display(); $page_id = 'updates-' . $getpost3['id']; include('includes/comments.php'); @@ -123,7 +126,7 @@ if (isset($_GET['post'])) } elseif (isset($_GET['tag'])) { $title = 'Tag: ' . $_GET['tag'] . ' - Blog Archive'; - $getposts = "SELECT * FROM updates WHERE tag1 = \"" . $_GET['tag'] . "\" OR tag2 = \"" . $_GET['tag'] . "\" OR tag3 = \"" . $_GET['tag'] . "\" ORDER BY id DESC"; + $getposts = "SELECT * FROM updates WHERE tags LIKE '%s:" . strlen($_GET['tag']) . ":\"" . $_GET['tag'] . "\"%' ORDER BY id DESC"; } else { $title = 'Blog Archive'; $getposts = "SELECT * FROM updates ORDER BY id DESC"; @@ -181,10 +184,7 @@ if (isset($_GET['post'])) 'DAY' => date('d',strtotime($getposts3[$i]['pubDate'])), 'AUTHOR' => $getposts3[$i]['author'], 'PLURALCOMMENT' => (isset($plural) ? $plural : ''), - 'COMMENTS' => $comText, - 'TAG1' => $getposts3[$i]['tag1'], - 'TAG2' => $getposts3[$i]['tag2'], - 'TAG3' => $getposts3[$i]['tag3'])); + 'COMMENTS' => $comText)); } else { $template->adds_ref_sub($curID, 'SMALL',array( 'DATE' => date('m-d-Y',strtotime($getposts3[$i]['pubDate'])), 'CODED' => $getposts3[$i]['slug'], diff --git a/pages/welcome.php b/pages/welcome.php index 24fd7ad..e267381 100755 --- a/pages/welcome.php +++ b/pages/welcome.php @@ -65,14 +65,17 @@ while ($getpost3 = mysql_fetch_array($getpost2)) 'CODED' => $getpost3['slug'], 'TITLE' => $getpost3['title'], 'AUTHOR' => $getpost3['author'], - 'TAG1' => $getpost3['tag1'], - 'TAG2' => $getpost3['tag2'], - 'TAG3' => $getpost3['tag3'], 'PLURALCOMMENT' => (isset($plural) ? $plural : ''), 'COMMENTS' => $comText, 'RATING' => $getpost3['rating'], 'TEXT' => parseBBCode($getpost3['text']))); + $tags = unserialize($getpost3['tags']); + foreach ($tags as $tag) + { + $template->adds_ref_sub($curID, 'TAGS', array('TAG' => $tag)); + } + $curID++; } -- cgit 1.4.1