From 7eb055141bae63b85cef93e5d6f67e3016219d7b Mon Sep 17 00:00:00 2001 From: Starla Insigna Date: Sat, 13 Dec 2008 10:01:56 -0500 Subject: Optimized posting Previously, Four Island posted a blog, and then searched through the table looking for it so it could retrieve its ID. Now, the "mysql_insert_id()" function is used instead. --- includes/functions.php | 9 ++++----- pages/admin.php | 21 +++++++++------------ 2 files changed, 13 insertions(+), 17 deletions(-) diff --git a/includes/functions.php b/includes/functions.php index d8d1bc4..7f85f96 100755 --- a/includes/functions.php +++ b/includes/functions.php @@ -118,11 +118,8 @@ function postBlogPost($title,$author,$tags,$content) $inspost = "INSERT INTO updates (title,slug,author,text) VALUES (\"" . $title . "\",\"" . $slug . "\",\"" . $author . "\",\"" . addslashes($content) . "\")"; $inspost2 = mysql_query($inspost); - $getpost = "SELECT * FROM updates WHERE slug = \"" . $slug . "\""; - $getpost2 = mysql_query($getpost); - $getpost3 = mysql_fetch_array($getpost2); - - addTags($getpost3['id'], $tags); + $id = mysql_insert_id(); + addTags($id, $tags); $upconf = "UPDATE config SET value = \"" . date('md') . "\" WHERE name = \"lastUpdate\""; $upconf2 = mysql_query($upconf); @@ -161,6 +158,8 @@ function postBlogPost($title,$author,$tags,$content) $msg = new xmlrpcmsg("weblogUpdates.ping", array( new xmlrpcval('Four Island', 'string'), new xmlrpcval('http://fourisland.com/', 'string'))); $client->send($msg); + + return $id; } function recalcPop($id) diff --git a/pages/admin.php b/pages/admin.php index b21948c..aff21cf 100755 --- a/pages/admin.php +++ b/pages/admin.php @@ -44,24 +44,21 @@ if (isLoggedIn()) $insdraft = "INSERT INTO drafts (title,author,text,slug) VALUES (\"" . addslashes($_POST['title']) . "\",\"" . sess_get('uname') . "\",\"" . addslashes($_POST['text']) . "\",\"" . generateSlug($_POST['title'],'updates') . "\")"; $insdraft2 = mysql_query($insdraft); - $getdraft = "SELECT * FROM drafts ORDER BY id DESC LIMIT 0,1"; - $getdraft2 = mysql_query($getdraft); - $getdraft3 = mysql_fetch_array($getdraft2); - - addTags($getdraft3['id'], $tags, 'draft'); + $id = mysql_insert_id(); + addTags($id, $tags, 'draft'); $template = new FITemplate('admin/draftSuccess'); - $template->add('ID', $getdraft3['id']); + $template->add('ID', $id); } else if ($_POST['type'] == 'instant') { - postBlogPost($_POST['title'], sess_get('uname'), $tags, $_POST['text']); + $id = postBlogPost($_POST['title'], sess_get('uname'), $tags, $_POST['text']); - $getpost = "SELECT * FROM updates ORDER BY id DESC LIMIT 0,1"; + $getpost = "SELECT * FROM updates WHERE id = " . $id; $getpost2 = mysql_query($getpost); $getpost3 = mysql_fetch_array($getpost2); $template = new FITemplate('admin/postSuccess'); - $template->add('ID', $getpost3['id']); + $template->add('ID', $id); $template->add('CODED', $getpost3['slug']); } else { if ($_POST['type'] == 'normal') @@ -143,17 +140,17 @@ if (isLoggedIn()) $template->add('ID', $_GET['id']); } else if ($_POST['type'] == 'instant') { - postBlogPost($_POST['title'], sess_get('uname'), $tags, $_POST['text']); + $id = postBlogPost($_POST['title'], sess_get('uname'), $tags, $_POST['text']); $deldraft = "DELETE FROM drafts WHERE id = " . $_GET['id']; $deldraft2 = mysql_query($deldraft); - $getpost = "SELECT * FROM updates ORDER BY id DESC LIMIT 0,1"; + $getpost = "SELECT * FROM updates WHERE id = " . $id; $getpost2 = mysql_query($getpost); $getpost3 = mysql_fetch_array($getpost2); $template = new FITemplate('admin/postSuccess'); - $template->add('ID', $getpost3['id']); + $template->add('ID', $id); $template->add('CODED', $getpost3['slug']); } else { if ($_POST['type'] == 'normal') -- cgit 1.4.1