[Phpbbkb-checkins] SF.net SVN: phpbbkb: [25] root
Status: Alpha
Brought to you by:
markthedaemon
From: <so...@us...> - 2006-11-27 15:50:12
|
Revision: 25 http://svn.sourceforge.net/phpbbkb/?rev=25&view=rev Author: softphp Date: 2006-11-27 07:50:04 -0800 (Mon, 27 Nov 2006) Log Message: ----------- - Edit article now works as intended - Added navigation to the 2 ucp pages - Started on view article. Modified Paths: -------------- root/kb/functions.php root/kb/ucp_class.php root/kb.php root/kb_install.php Modified: root/kb/functions.php =================================================================== --- root/kb/functions.php 2006-11-26 02:49:26 UTC (rev 24) +++ root/kb/functions.php 2006-11-27 15:50:04 UTC (rev 25) @@ -32,6 +32,19 @@ { case "ucp": // Different kind of subcategories + switch($id_ary) + { + case "post_article": + $navigation = '<span class="nav"> <a href="' . append_sid('kb.' . $phpEx) . '" class="nav">' . $lang['kb_main'] . '</a> -> <a class="nav" href="' . append_sid('kb.' . $phpEx . '?pid=ucp&action=post_article') . '">' . $lang['kb_ucp_articlepost'] .'</a></span>'; + break; + + case "edit_article": + $navigation = '<span class="nav"> <a href="' . append_sid('kb.' . $phpEx) . '" class="nav">' . $lang['kb_main'] . '</a> -> <a class="nav" href="' . append_sid('kb.' . $phpEx . '?pid=ucp&action=edit_article') . '">' . $lang['kb_ucp_articleedit'] .'</a></span>'; + break; + + default: + break; + } break; case "viewcat": Modified: root/kb/ucp_class.php =================================================================== --- root/kb/ucp_class.php 2006-11-26 02:49:26 UTC (rev 24) +++ root/kb/ucp_class.php 2006-11-27 15:50:04 UTC (rev 25) @@ -29,6 +29,8 @@ var $action = ""; var $html_entities_match = array('#&(?!(\#[0-9]+;))#', '#<#', '#>#', '#"#'); var $html_entities_replace = array('&', '<', '>', '"'); + var $unhtml_specialchars_match = array('#>#', '#<#', '#"#', '#&#'); + var $unhtml_specialchars_replace = array('>', '<', '"', '&'); function generate_page($action, $id=0, $preview=false) { @@ -86,7 +88,7 @@ break; case "edit_article": - + $title .= ": " . $lang['kb_ucp_articleedit']; break; case "delete_article": @@ -119,6 +121,32 @@ if(!empty($HTTP_POST_VARS['post'])) { + if($mode == 'edit') + { + // Let's get the old article data + $article_id = ( !empty($HTTP_POST_VARS['id']) ) ? $HTTP_POST_VARS['id'] : false; + + $sql = "SELECT * + FROM " . KB_ARTICLES_TABLE . " + WHERE article_id = '$id'"; + if (!$result = $db->sql_query($sql)) + { + message_die(GENERAL_ERROR, 'Error while retrieving old article data.', '', __LINE__, __FILE__, $sql); + } + + $article = $db->sql_fetchrow($result); + + // if user editing set status = 0, else set status = old status :) + if($userdata['user_id'] == $article_author) + { + $article_status = "0"; + } + else + { + $article_status = $article['article_status']; + } + } + // Add the new article // Make all the variables :) if ( !$board_config['allow_html'] ) @@ -151,8 +179,8 @@ $article_desc = ( !empty($HTTP_POST_VARS['desc']) ) ? trim($HTTP_POST_VARS['desc']) : ''; $article_title = ( !empty($HTTP_POST_VARS['title']) ) ? trim($HTTP_POST_VARS['title']) : ''; $message = ( !empty($HTTP_POST_VARS['message']) ) ? $HTTP_POST_VARS['message'] : ''; - $article_author = $userdata['user_id']; - $article_authorname = ( empty($HTTP_POST_VARS['authorname']) ) ? $userdata['username'] : $HTTP_POST_VARS['authorname']; + $article_author = ($mode == 'edit') ? $article['article_author'] : $userdata['user_id']; + $article_authorname = ( $mode == 'edit' ) ? ( ( empty($HTTP_POST_VARS['authorname']) ) ? $article['article_authorname'] : $HTTP_POST_VARS['authorname'] ) : ( ( empty($HTTP_POST_VARS['authorname']) ) ? $userdata['username'] : $HTTP_POST_VARS['authorname'] ); $bbcode_uid = ''; $cat_id = $HTTP_POST_VARS['cats']; $attach_sig = ( !empty($HTTP_POST_VARS['attach_sig']) ) ? 1 : 0; @@ -162,35 +190,91 @@ if ( $error_msg == '' ) { $current_time = time(); - - $sql = "INSERT INTO " . KB_ARTICLES_TABLE . " (article_id, article_title, article_desc, article_author, article_authorname, article_time, article_edittime, article_hits, article_editby, article_status, enable_sig, enable_html, enable_bbcode, enable_smilies, article_text) VALUES - ('', '$article_title', '$article_desc', '$article_author', '$article_authorname', '$current_time', '$current_time', '0', '" . $userdata['user_id'] . "', '0', '$attach_sig', '$html_on', '$bbcode_on', '$smilies_on', '$message');"; - if (!$db->sql_query($sql)) + + if($mode == 'post') { - message_die(GENERAL_ERROR, 'Error in adding article', '', __LINE__, __FILE__, $sql); + $sql = "INSERT INTO " . KB_ARTICLES_TABLE . " (article_id, article_title, article_desc, article_author, article_authorname, article_time, article_edittime, article_hits, article_editby, article_status, bbcode_uid, enable_sig, enable_html, enable_bbcode, enable_smilies, article_text) VALUES + ('', '$article_title', '$article_desc', '$article_author', '$article_authorname', '$current_time', '$current_time', '0', '" . $userdata['user_id'] . "', '0', '$bbcode_uid', '$attach_sig', '$html_on', '$bbcode_on', '$smilies_on', '$message');"; + if (!$db->sql_query($sql)) + { + message_die(GENERAL_ERROR, 'Error in adding article', '', __LINE__, __FILE__, $sql); + } + + $article_id = $db->sql_nextid(); + // Now make the categories + foreach($cat_id as $i => $cat) + { + $sql = "INSERT INTO " . KB_ARTICLECATS_TABLE . " VALUES ('$article_id', '$cat');\n"; + $sql2 = "UPDATE " . KB_CATEGORIES_TABLE . " SET cat_articles = cat_articles + 1 WHERE cat_id = '$cat';\n"; + + if (!$db->sql_query($sql)) + { + message_die(GENERAL_ERROR, 'Error in adding articles categories.', '', __LINE__, __FILE__, $sql); + } + + if (!$db->sql_query($sql2)) + { + message_die(GENERAL_ERROR, 'Error in adding updating categories articles count.', '', __LINE__, __FILE__, $sql); + } + } + + $meta = '<meta http-equiv="refresh" content="3;url=' . append_sid('kb.' . $phpEx . '?pid=view_article&id=' . $article_id) . '>"'; + $return_message = $lang['kb_added'] . '<br /><br />' . sprintf($lang['kb_click_view_article'], '<a href="' . append_sid('kb.' . phpEx . '?pid=view_article&id=' . $article_id) . '">', '</a>') . '<br /><br />' . sprintf($lang['kb_click_return_ucp'], '<a href="' . append_sid('kb.' . $phpEx . '?pid=ucp') . '">', '</a>'); } - - $article_id = $db->sql_nextid(); - // Now make the categories - foreach($cat_id as $i => $cat) + else { - $sql = "INSERT INTO " . KB_ARTICLECATS_TABLE . " VALUES ('$article_id', '$cat');\n"; - $sql2 = "UPDATE " . KB_CATEGORIES_TABLE . " SET cat_articles = cat_articles + 1 WHERE cat_id = '$cat';\n"; + if(!$article_id) + { + message_die(GENERAL_ERROR, 'No article to edit.'); + } + // First update the article table + $sql = "UPDATE " . KB_ARTICLES_TABLE . " + SET article_title = '$article_title', + article_desc = '$article_desc', + article_author = '$article_author', + article_authorname = '$article_authorname', + article_edittime = '$current_time', + article_editby = '" . $userdata['user_id'] . "', + article_status = '$article_status', + enable_sig = '$attach_sig', + enable_html = '$html_on', + enable_bbcode = '$bbcode_on', + enable_smilies = '$smilies_on', + article_text = '$message';"; + if (!$db->sql_query($sql)) { - message_die(GENERAL_ERROR, 'Error in adding articles categories.', '', __LINE__, __FILE__, $sql); + message_die(GENERAL_ERROR, 'Error in editing article', '', __LINE__, __FILE__, $sql); } - if (!$db->sql_query($sql2)) + // Now delete all articlecats + $sql = "DELETE FROM " . KB_ARTICLECATS_TABLE . " WHERE article_id = '$article_id'"; + + if (!$db->sql_query($sql)) { - message_die(GENERAL_ERROR, 'Error in adding updating categories articles count.', '', __LINE__, __FILE__, $sql); + message_die(GENERAL_ERROR, 'Error in deleting articlecat entries.', '', __LINE__, __FILE__, $sql); } + + // Last add them again doing the loop + foreach($cat_id as $i => $cat) + { + $sql = "INSERT INTO " . KB_ARTICLECATS_TABLE . " VALUES ('$article_id', '$cat');\n"; + $sql2 = "UPDATE " . KB_CATEGORIES_TABLE . " SET cat_articles = cat_articles + 1 WHERE cat_id = '$cat';\n"; + + if (!$db->sql_query($sql)) + { + message_die(GENERAL_ERROR, 'Error in adding articles categories.', '', __LINE__, __FILE__, $sql); + } + + if (!$db->sql_query($sql2)) + { + message_die(GENERAL_ERROR, 'Error in adding updating categories articles count.', '', __LINE__, __FILE__, $sql); + } + } + + // Message here somewhere } - - $meta = '<meta http-equiv="refresh" content="3;url=' . append_sid('kb.' . $phpEx . '?pid=view_article&id=' . $article_id) . '>"'; - $return_message = $lang['kb_added'] . '<br /><br />' . sprintf($lang['kb_click_view_article'], '<a href="' . append_sid('kb.' . phpEx . '?pid=view_article&id=' . $article_id) . '">', '</a>') . '<br /><br />' . sprintf($lang['kb_click_return_ucp'], '<a href="' . append_sid('kb.' . $phpEx . '?pid=ucp') . '">', '</a>'); - return; } } @@ -252,16 +336,7 @@ $smilies_on = ( $HTTP_POST_VARS['disable_smilies'] ) ? false : true; $form_action = append_sid("kb.php?pid=ucp&action=post_article"); - - if($mode == "edit") - { - $hidden_form_fields = ""; - } - else - { - $hidden_form_fields = ""; - } - + $hidden_form_fields = ""; if($error_msg != "") { $template->set_filenames(array( @@ -288,7 +363,14 @@ message_die(GENERAL_ERROR, 'Could not query article data.', '', __LINE__, __FILE__, $sql); } - $article = $db->sql_fetchrow($result); + if($db->sql_numrows($result) == 1) + { + $article = $db->sql_fetchrow($result); + } + else + { + message_die(GENERAL_ERROR, "Article does not exist."); + } // Now make an array over the cats $sql = "SELECT cat_id @@ -317,9 +399,14 @@ $smilies_on = ( $article['enable_smilies'] ) ? true : false; $form_action = append_sid("kb.php?pid=ucp&action=edit_article"); - $hidden_form_fields = ""; + $hidden_form_fields = '<input type="hidden" name="id" value="' . $id . '" />'; } + if ( $article['bbcode_uid'] != '' ) + { + $article_text = preg_replace('/\:(([a-z0-9]:)?)' . $article['bbcode_uid'] . '/s', '', $article_text); + } + $article_text = str_replace('<', '<', $article_text); $article_text = str_replace('>', '>', $article_text); $article_text = str_replace('<br />', "\n", $article_text); @@ -423,6 +510,8 @@ 'body' => 'kb_article_posting.tpl') ); + create_navigation("ucp", $this->action); + // This is the template stuff we need no matter what $template->assign_vars(array( 'AUTHORNAME' => $authorname, @@ -550,7 +639,7 @@ function prepare_message($message, $html_on, $bbcode_on, $smile_on, $bbcode_uid = 0) { - global $board_config, $html_entities_match, $html_entities_replace; + global $board_config, $phpEx; // // Clean up the message @@ -571,6 +660,9 @@ $message = ''; + // Include functions_post for clean_html + include($phpbb_root_path . "includes/functions_post." . $phpEx); + foreach ($message_split as $part) { $tag = array(array_shift($matches[0]), array_shift($matches[1]), array_shift($matches[2])); @@ -592,5 +684,10 @@ return $message; } + + function unprepare_message($message) + { + return preg_replace($this->unhtml_specialchars_match, $this->unhtml_specialchars_replace, $message); + } } ?> \ No newline at end of file Modified: root/kb.php =================================================================== --- root/kb.php 2006-11-26 02:49:26 UTC (rev 24) +++ root/kb.php 2006-11-27 15:50:04 UTC (rev 25) @@ -334,7 +334,7 @@ 'ARTICLE_AUTHOR' => $author, 'ARTICLE_HITS' => $articles[$i]['article_hits'], 'ARTICLE_LAST_ACTION' => $last_action, - 'U_VIEW_ARTICLE' => append_sid("kb." . $phpEx . "?pid=viewarticle&cid=" . $cat_id . "&id=" . $articles[$i]['article_id'])) + 'U_VIEW_ARTICLE' => append_sid("kb." . $phpEx . "?pid=view_article&cid=" . $cat_id . "&id=" . $articles[$i]['article_id'])) ); } } @@ -348,6 +348,22 @@ break; case "view_article": + $cid = ( empty($HTTP_GET_VARS['cid']) ) ? false : $HTTP_GET_VARS['cid']; + $id = ( empty($HTTP_GET_VARS['cid']) ) ? false : $HTTP_GET_VARS['id']; + + if(!$cid || !$id) + { + message_die(GENERAL_ERROR, 'Not enough arguments defined. Please make sure both id and cat id is defined.'); + } + + $sql = "SELECT * + FROM " . KB_ARTICLES_TABLE . " + WHERE article_id = '$id'"; + if( !($result = $db->sql_query($sql)) ) + { + message_die(GENERAL_ERROR, 'Could not query article info', '', __LINE__, __FILE__, $sql); + } + break; case "ucp": Modified: root/kb_install.php =================================================================== --- root/kb_install.php 2006-11-26 02:49:26 UTC (rev 24) +++ root/kb_install.php 2006-11-27 15:50:04 UTC (rev 25) @@ -71,6 +71,7 @@ article_hits mediumint(8) UNSIGNED DEFAULT '0', article_editby mediumint(8) UNSIGNED DEFAULT '0', article_status smallint(1) UNSIGNED DEFAULT '0', + bbcode_uid varcharr(10) NOT NULL, enable_sig smallint(1) UNSIGNED DEFAULT '0', enable_html smallint(1) UNSIGNED DEFAULT '0', enable_bbcode smallint(1) UNSIGNED DEFAULT '0', This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |