[Phpbbkb-checkins] SF.net SVN: phpbbkb: [21] root
Status: Alpha
Brought to you by:
markthedaemon
From: <so...@us...> - 2006-11-24 00:27:20
|
Revision: 21 http://svn.sourceforge.net/phpbbkb/?rev=21&view=rev Author: softphp Date: 2006-11-23 16:27:20 -0800 (Thu, 23 Nov 2006) Log Message: ----------- Oh boy! Big commit :) List of modifications: - Added extra fields in articles table - Added support for posting articles (Not tested yet) - Added a big part of preview and edit functions.php - Added more lang variables, but didn't write them all into lang_kb.php - Added if(!defined('IN_PHPBB')) blablabla to functions.php, constants.php & ucp_class.php. (Yes i should be shot for not doing it before. - Added multiple categories support (Not tested either) Modified Paths: -------------- root/kb/constants.php root/kb/functions.php root/kb/ucp_class.php root/kb.php root/kb_install.php root/language/lang_english/lang_kb.php root/templates/subSilver/kb_article_posting.tpl Modified: root/kb/constants.php =================================================================== --- root/kb/constants.php 2006-11-23 15:32:31 UTC (rev 20) +++ root/kb/constants.php 2006-11-24 00:27:20 UTC (rev 21) @@ -18,6 +18,11 @@ * ***************************************************************************/ +if (!defined('IN_PHPBB')) +{ + die('Hacking attempt'); +} + // All constants here // DB Tables define('KB_CATEGORIES_TABLE', $table_prefix . "kb_categories"); Modified: root/kb/functions.php =================================================================== --- root/kb/functions.php 2006-11-23 15:32:31 UTC (rev 20) +++ root/kb/functions.php 2006-11-24 00:27:20 UTC (rev 21) @@ -18,6 +18,11 @@ * ***************************************************************************/ +if (!defined('IN_PHPBB')) +{ + die('Hacking attempt'); +} + // This function creates the navigation line based on a few parameters function create_navigation($type = "main", $id_ary = array()) { @@ -69,4 +74,132 @@ return; } + +function get_cats_structure() +{ + global $db; + + $cats = array(); + $sql = "SELECT * + FROM " . KB_CATEGORIES_TABLE . " + WHERE cat_main = '0' + ORDER BY cat_order"; + if( !($result = $db->sql_query($sql)) ) + { + message_die(GENERAL_ERROR, 'Could not query cats.', '', __LINE__, __FILE__, $sql); + } + + $i = 0; + while($row = $db->sql_fetchrow($result)) + { + $cats[$i] = $row; + + $sql = "SELECT * + FROM " . KB_CATEGORIES_TABLE . " + WHERE cat_main = '" . $row['cat_id'] . "' + ORDER BY cat_order"; + if( !($subcat_result = $db->sql_query($sql)) ) + { + message_die(GENERAL_ERROR, 'Could not query subcats.', '', __LINE__, __FILE__, $sql); + } + + $cats[$i]['subcats'] = array(); + while($row2 = $db->sql_fetchrow($subcat_result)) + { + $cats[$i]['subcats'][] = $row2; + } + $i++; + } + + return $cats; +} + +// These vars we need for making html safe +$html_entities_match = array('#&(?!(\#[0-9]+;))#', '#<#', '#>#', '#"#'); +$html_entities_replace = array('&', '<', '>', '"'); + +// +// Prepare an article for the database +// +function prepare_article(&$bbcode_on, &$html_on, &$smilies_on, &$error_msg, &$bbcode_uid, &$article_title, &$article_desc, &$message, &$cat_id) +{ + global $board_config, $userdata, $lang, $phpEx, $phpbb_root_path; + + // Check title + if (!empty($article_title)) + { + $article_title = htmlspecialchars(trim($article_title)); + } + else + { + $error_msg .= (!empty($error_msg)) ? '<br />' . $lang['kb_empty_article_title'] : $lang['kb_empty_article_title']; + } + + // Check message + if(!empty($message)) + { + $bbcode_uid = ($bbcode_on) ? make_bbcode_uid() : ''; + $message = prepare_message(trim($message), $html_on, $bbcode_on, $smilies_on, $bbcode_uid); + } + else + { + $error_msg .= (!empty($error_msg)) ? '<br />' . $lang['kb_empty_article'] : $lang['kb_empty_article']; + } + + // Check categories + if(!empty($cat_id) && count($cat_id) > 0) + { + $cat_id = implode(",", $cat_id); + } + else + { + $error_msg .= (!empty($error_msg)) ? '<br />' . $lang['kb_empty_cats'] : $lang['kb_empty_cats']; + + return; +} + +function prepare_message($message, $html_on, $bbcode_on, $smile_on, $bbcode_uid = 0) +{ + global $board_config, $html_entities_match, $html_entities_replace; + + // + // Clean up the message + // + $message = trim($message); + + if ($html_on) + { + // If HTML is on, we try to make it safe + // This approach is quite agressive and anything that does not look like a valid tag + // is going to get converted to HTML entities + $message = stripslashes($message); + $html_match = '#<[^\w<]*(\w+)((?:"[^"]*"|\'[^\']*\'|[^<>\'"])+)?>#'; + $matches = array(); + + $message_split = preg_split($html_match, $message); + preg_match_all($html_match, $message, $matches); + + $message = ''; + + foreach ($message_split as $part) + { + $tag = array(array_shift($matches[0]), array_shift($matches[1]), array_shift($matches[2])); + $message .= preg_replace($html_entities_match, $html_entities_replace, $part) . clean_html($tag); + } + + $message = addslashes($message); + $message = str_replace('"', '\"', $message); + } + else + { + $message = preg_replace($html_entities_match, $html_entities_replace, $message); + } + + if($bbcode_on && $bbcode_uid != '') + { + $message = bbencode_first_pass($message, $bbcode_uid); + } + + return $message; +} ?> \ No newline at end of file Modified: root/kb/ucp_class.php =================================================================== --- root/kb/ucp_class.php 2006-11-23 15:32:31 UTC (rev 20) +++ root/kb/ucp_class.php 2006-11-24 00:27:20 UTC (rev 21) @@ -18,15 +18,18 @@ * ***************************************************************************/ +if (!defined('IN_PHPBB')) +{ + die('Hacking attempt'); +} + // This contains the entire ucp class, so it's seperated from the rest of kb.php class ucp { var $action = ""; - function __construct($action, $id=0) + function generate_page($action, $id=0, $preview=false) { - global $HTTP_POST_VARS['review']; - $this->action = $action; switch($this->action) { @@ -37,11 +40,11 @@ break; case "post_article": - $this->article_form("post", false, $HTTP_POST_VARS['review']); + $this->article_form("post", false, $preview); break; case "edit_article": - $this->article_form("edit", $id, $HTTP_POST_VARS['review']); + $this->article_form("edit", $id, $preview); break; case "delete_article": @@ -62,18 +65,174 @@ } } + function generate_page_title($action) + { + global $lang; + + $title = $lang['kb_ucp']; + + switch($action) + { + case "articles": + break; + + case "comments": + break; + + case "post_article": + $title .= ": " . $lang['kb_ucp_articlepost']; + break; + + case "edit_article": + + break; + + case "delete_article": + + break; + + case "post_comment": // Only input + break; + + case "edit_comment": + break; + + case "delete_comment": + break; + + default: + break; + } + + return $title; + } + // This is for posting articles, mostly cut out of the posting.php :) function article_form($mode, $id, $review) { - global $template, $board_config, $db, $userdata; + global $template, $board_config, $db, $userdata, $lang, $phpbb_root_path, $phpEx, $HTTP_POST_VARS; - if($mode == "post") + $error_msg = ''; + + if(!empty($HTTP_POST_VARS['post'])) { + // Add the new article + // Make all the variables :) + if ( !$board_config['allow_html'] ) + { + $html_on = 0; + } + else + { + $html_on = ( !empty($HTTP_POST_VARS['disable_html']) ) ? 0 : TRUE; + } + + if ( !$board_config['allow_bbcode'] ) + { + $bbcode_on = 0; + } + else + { + $bbcode_on = ( !empty($HTTP_POST_VARS['disable_bbcode']) ) ? 0 : TRUE; + } + + if ( !$board_config['allow_smilies'] ) + { + $smilies_on = 0; + } + else + { + $smilies_on = ( !empty($HTTP_POST_VARS['disable_smilies']) ) ? 0 : TRUE; + } + + $article_desc = ( !empty($HTTP_POST_VARS['desc']) ) ? $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']; + $bbcode_uid = ''; + $cat_id = $HTTP_POST_VARS['cats']; + $attach_sig = ( !empty($HTTP_POST_VARS['attach_sig']) ) ? TRUE : 0; + + prepare_article($bbcode_on, $html_on, $smilies_on, $error_msg, $bbcode_uid, $article_title, $article_desc, $message, $cat_id); + + if ( $error_msg == '' ) + { + $current_time = time(); + + $sql = "INSERT INTO" . KB_ARTICLES_TABLE . " (article_id, cat_id, article_title, article_desc, article_author, article_authorname, article_time, article_edittime, article_hits, article_editby, article_status, enable_sig, enable_html, enable_bbode, enable_smilies, article_text) VALUES + ('', '$cat_id', '$article_title', '$article_desc', '$article_author', '$article_authorname', '$current_time', '$current_time', '0', '" . $userdata['user_id'] . "', '0', '$enable_sig', '$enable_html', '$enable_bbcode', '$enable_smilies', '$message');"; + if (!$db->sql_query($sql)) + { + message_die(GENERAL_ERROR, 'Error in adding article', '', __LINE__, __FILE__, $sql); + } + + $article_id = $db->sql_nextid(); + + $meta = '<meta http-equiv="refresh" content="3;url=' . append_sid("kb.$phpEx?pid=view_article&id=" . $article_id) . '>"'; + $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>'); + } + } + + $preview = ( !empty($HTTP_POST_VARS['preview']) ) ? true : false; + if($mode == "post" && !$preview) + { $article_title = ''; $article_text = ''; $article_desc = ''; $authorname = $userdata['username']; + $form_action = append_sid("kb.php?pid=ucp&action=post_article"); + $hidden_form_fields = ""; + $attach_sig = ( $userdata['user_id'] == ANONYMOUS ) ? 0 : $userdata['user_attachsig']; + + if ( !$board_config['allow_html'] ) + { + $html_on = 0; + } + else + { + $html_on = ( ( $userdata['user_id'] == ANONYMOUS ) ? $board_config['allow_html'] : $userdata['user_allowhtml'] ); + } + + if ( !$board_config['allow_bbcode'] ) + { + $bbcode_on = 0; + } + else + { + $bbcode_on = ( ( $userdata['user_id'] == ANONYMOUS ) ? $board_config['allow_bbcode'] : $userdata['user_allowbbcode'] ); + } + + if ( !$board_config['allow_smilies'] ) + { + $smilies_on = 0; + } + else + { + $smilies_on = ( ( $userdata['user_id'] == ANONYMOUS ) ? $board_config['allow_smilies'] : $userdata['user_allowsmile'] ); + } + + if($preview) + { + // Do funny preview stuff + } } + elseif($preview) + { + $article_title = $HTTP_POST_VARS['title']; + $article_text = $HTTP_POST_VARS['message']; + $article_desc = $HTTP_POST_VARS['desc']; + $authorname = $HTTP_POST_VARS['authorname']; + + $attach_sig = ( $HTTP_POST_VARS['enable_sig'] ) ? TRUE : 0; + + $html_on = ( $HTTP_POST_VARS['disable_html'] ) ? false : true; + $bbcode_on = ( $HTTP_POST_VARS['disable_bbcode'] ) ? false : true; + $smilies_on = ( $HTTP_POST_VARS['disable_smilies'] ) ? false : true; + + $form_action = append_sid("kb.php?pid=ucp&action=post_article"); + $hidden_form_fields = ""; + } else { $sql = "SELECT * @@ -90,12 +249,14 @@ $article_desc = $article['article_desc']; $authorname = $article['article_authorname']; - $attach_sig = ( $article['enable_sig'] && $post_info['user_sig'] != '' ) ? TRUE : 0; - $user_sig = $userdata['user_sig']; + $attach_sig = ( $article['enable_sig'] ) ? TRUE : 0; $html_on = ( $article['enable_html'] ) ? true : false; $bbcode_on = ( $article['enable_bbcode'] ) ? true : false; $smilies_on = ( $article['enable_smilies'] ) ? true : false; + + $form_action = append_sid("kb.php?pid=ucp&action=edit_article"); + $hidden_form_fields = ""; } $article_text = str_replace('<', '<', $article_text); @@ -136,6 +297,41 @@ $bbcode_status = $lang['BBCode_is_OFF']; } + // Obtain categories structure + $cats = get_cats_structure(); + + // First lets sort main cats + $s_cats = '<option value="0">-' . $lang['kb_main'] . '</option>'; + if($preview || $mode == "edit") + { + for($i = 0; $i < count($cats); $i++) + { + $s_cats .= '<option value="' . $cats[$i]['cat_id'] . '">--' . $cats[$i]['cat_title'] . '</option>'; + + // Sort subcats + for($j = 0; $j < count($cats[$i]['subcats']); $j++) + { + $s_cats .= '<option value="' . $cats[$i]['subcats'][$j]['cat_id'] . '">--' . $cats[$i]['subcats'][$j]['cat_title'] . '</option>'; + } + } + } + else + { + $var = ( $preview ) ? $HTTP_POST_VARS['cats'] : $article['cat_id']; + for($i = 0; $i < count($cats); $i++) + { + $selected = ( strstr($var, "," . $cats[$i]['cat_id'] . ",") ) ? ' selected' : ''; + $s_cats .= '<option' . $selected . ' value="' . $cats[$i]['cat_id'] . '">--' . $cats[$i]['cat_title'] . '</option>'; + + // Sort subcats + for($j = 0; $j < count($cats[$i]['subcats']); $j++) + { + $selected = ( strstr($var, "," . $cats[$i]['subcats'][$j]['cat_id'] . ",") ) ? ' selected' : ''; + $s_cats .= '<option' . $selected . ' value="' . $cats[$i]['subcats'][$j]['cat_id'] . '">--' . $cats[$i]['subcats'][$j]['cat_title'] . '</option>'; + } + } + } + // // Smilies toggle selection // @@ -149,6 +345,10 @@ $smilies_status = $lang['Smilies_are_OFF']; } + $template->set_filenames(array( + 'body' => 'kb_article_posting.tpl') + ); + // This is the template stuff we need no matter what $template->assign_vars(array( 'AUTHORNAME' => $authorname, @@ -158,14 +358,19 @@ 'BBCODE_STATUS' => sprintf($bbcode_status, '<a href="' . append_sid("faq.$phpEx?mode=bbcode") . '" target="_phpbbcode">', '</a>'), 'SMILIES_STATUS' => $smilies_status, - 'L_SUBJECT' => $lang['Subject'], - 'L_MESSAGE_BODY' => $lang['Message_body'], + 'L_POST_ARTICLE' => $lang['kb_post_article'], + 'L_AUTHORNAME' => $lang['kb_authorname'], + 'L_ARTICLE_NAME' => $lang['kb_articlename'], + 'L_ARTICLE_DESC' => $lang['kb_articledesc'], + 'L_ARTICLE_CATS' => $lang['kb_articlecats'], + 'L_ARTICLE_BODY' => $lang['kb_articletext'], + 'L_AUTHORNAME_DESC' => $lang['kb_authorname_desc'], + 'L_ARTICLEDESC_DESC' => $lang['kb_articledesc_desc'], // Funny one eh? + 'L_ARTICLECATS_DESC' => $lang['kb_articlecats_desc'], + 'L_OPTIONS' => $lang['Options'], 'L_PREVIEW' => $lang['Preview'], - 'L_SPELLCHECK' => $lang['Spellcheck'], 'L_SUBMIT' => $lang['Submit'], - 'L_CANCEL' => $lang['Cancel'], - 'L_CONFIRM_DELETE' => $lang['Confirm_delete'], 'L_DISABLE_HTML' => $lang['Disable_HTML_post'], 'L_DISABLE_BBCODE' => $lang['Disable_BBCode_post'], 'L_DISABLE_SMILIES' => $lang['Disable_Smilies_post'], @@ -212,17 +417,12 @@ 'L_BBCODE_CLOSE_TAGS' => $lang['Close_Tags'], 'L_STYLES_TIP' => $lang['Styles_tip'], - 'U_VIEWTOPIC' => ( $mode == 'reply' ) ? append_sid("viewtopic.$phpEx?" . POST_TOPIC_URL . "=$topic_id&postorder=desc") : '', - 'U_REVIEW_TOPIC' => ( $mode == 'reply' ) ? append_sid("kb.$phpEx?preview=topicreview&" . POST_TOPIC_URL . "=$topic_id") : '', - 'S_HTML_CHECKED' => ( !$html_on ) ? 'checked="checked"' : '', 'S_BBCODE_CHECKED' => ( !$bbcode_on ) ? 'checked="checked"' : '', 'S_SMILIES_CHECKED' => ( !$smilies_on ) ? 'checked="checked"' : '', 'S_SIGNATURE_CHECKED' => ( $attach_sig ) ? 'checked="checked"' : '', - 'S_NOTIFY_CHECKED' => ( $notify_user ) ? 'checked="checked"' : '', - 'S_TYPE_TOGGLE' => $topic_type_toggle, - 'S_TOPIC_ID' => $topic_id, - 'S_POST_ACTION' => append_sid("posting.$phpEx"), + 'S_POST_ACTION' => $form_action, + 'CATS_HTML' => $s_cats, 'S_HIDDEN_FORM_FIELDS' => $hidden_form_fields) ); } Modified: root/kb.php =================================================================== --- root/kb.php 2006-11-23 15:32:31 UTC (rev 20) +++ root/kb.php 2006-11-24 00:27:20 UTC (rev 21) @@ -338,8 +338,15 @@ case "ucp": $action = ( isset($HTTP_GET_VARS['action']) ) ? $HTTP_GET_VARS['action'] : ""; - $ucp = new ucp($action); + include($phpbb_root_path . "kb/ucp_class.$phpEx"); + $ucp = new ucp; + // Start Page output + $page_title = $ucp->generate_page_title($action); + include($phpbb_root_path . 'includes/page_header.'.$phpEx); + + $ucp->generate_page($action, $HTTP_GET_VARS['id'], $HTTP_GET_VARS['preview']); + // // Generate the page // Modified: root/kb_install.php =================================================================== --- root/kb_install.php 2006-11-23 15:32:31 UTC (rev 20) +++ root/kb_install.php 2006-11-24 00:27:20 UTC (rev 21) @@ -67,10 +67,15 @@ article_desc varchar(255) NOT NULL, article_author mediumint(8) UNSIGNED NOT NULL, article_authorname varchar(50) NOT NULL, + article_time int(20) UNSIGNED DEFAULT '0', article_edittime int(20) UNSIGNED DEFAULT '0', article_hits mediumint(8) UNSIGNED DEFAULT '0', article_editby mediumint(8) UNSIGNED DEFAULT '0', article_status smallint(1) UNSIGNED DEFAULT '0', + enable_sig smallint(1) UNSIGNED DEFAULT '0', + enable_html smallint(1) UNSIGNED DEFAULT '0', + enable_bbcode smallint(1) UNSIGNED DEFAULT '0', + enable_smilies smallint(1) UNSIGNED DEFAULT '0', article_text text, PRIMARY KEY (article_id), KEY cat_id (cat_id) Modified: root/language/lang_english/lang_kb.php =================================================================== --- root/language/lang_english/lang_kb.php 2006-11-23 15:32:31 UTC (rev 20) +++ root/language/lang_english/lang_kb.php 2006-11-24 00:27:20 UTC (rev 21) @@ -21,7 +21,11 @@ // Page titles $lang['kb_main'] = "KnowledgeBase Home"; $lang['kb_viewcat'] = "Viewing Category"; +$lang['kb_ucp'] = "KB User Control Panel"; +$lang['kb_ucp_articlepost'] = "Post new article"; +$lang['kb_ucp_articleedit'] = "Edit article"; +// Normal Page $lang['kb_categories'] = "KnowledgeBase Categories"; $lang['kb_articles'] = "Articles"; $lang['kb_subcats'] = "Subcategories"; @@ -31,4 +35,15 @@ $lang['kb_viewcat_subcats'] = "Subcategories in %s"; $lang['kb_last_action'] = "Last action"; $lang['kb_last_action_row'] = "Last action for this article was comitted by %s on the %s"; + +// Posting Page +$lang['kb_post_article'] = "Post New Article"; +$lang['kb_authorname'] = "Author Name"; +$lang['kb_authorname_desc'] = "This is the name that will be displayed, just leave your username there if you want, but you might wanted to change it."; +$lang['kb_articlename'] = "Article Name"; +$lang['kb_articledesc'] = "Article Description"; +$lang['kb_articlecats'] = "Article Categories"; +$lang['kb_articletext'] = "Article Content"; +$lang['kb_articledesc_desc'] = "Description of your article, max. 255 characters."; +$lang['kb_articlecats_desc'] = "Choose what categories your article will appear in, use ctrl + click for multiple."; ?> \ No newline at end of file Modified: root/templates/subSilver/kb_article_posting.tpl =================================================================== --- root/templates/subSilver/kb_article_posting.tpl 2006-11-23 15:32:31 UTC (rev 20) +++ root/templates/subSilver/kb_article_posting.tpl 2006-11-24 00:27:20 UTC (rev 21) @@ -247,26 +247,27 @@ <th class="thHead" colspan="2" height="25"><b>{L_POST_ARTICLE}</b></th> </tr> <tr> - <td class="row1"><span class="gen"><b>{L_AUTHORNAME}</b></span></td> - <td class="row2"><span class="genmed"><input type="text" class="post" tabindex="1" name="username" size="25" maxlength="25" value="{AUTHORNAME}" /> + <td class="row1"><span class="gen"><b>{L_AUTHORNAME}</b></span><br /><span class="gensmall">{L_AUTHORNAME_DESC}</span></td> + <td class="row2"><span class="genmed"><input name="authorname" type="text" class="post" id="authorname" tabindex="1" value="{AUTHORNAME}" size="25" maxlength="25" /> </span></td> </tr> <tr> <td class="row1" width="22%"><span class="gen"><b>{L_ARTICLE_NAME}</b></span></td> <td class="row2" width="78%"> <span class="gen"> - <input type="text" name="subject" size="45" maxlength="60" style="width:450px" tabindex="2" class="post" value="{ARTICLE_TITLE}" /> + <input name="title" type="text" class="post" id="title" style="width:450px" tabindex="2" value="{ARTICLE_TITLE}" size="45" maxlength="60" /> </span> </td> </tr> <tr> - <td class="row1" width="22%"><span class="gen"><b>{L_ARTICLE_DESC}</b></span></td> + <td class="row1" width="22%"><span class="gen"><b>{L_ARTICLE_DESC}</b></span><br /><span class="gensmall">{L_ARTICLEDESC_DESC}</span></td> <td class="row2" width="78%"> <span class="gen"> <textarea name="desc" cols="35" rows="5" wrap="virtual" class="post" id="desc" style="width:450px" tabindex="2">{DESC}</textarea> </span> </td> </tr> <tr> - <td class="row1" width="22%"><span class="gen"><b>{L_ARTICLE_CATS}</b></span></td> - <td class="row2" width="78%"><select name="cats" size="4" multiple="multiple" id="cats">{CATS_HTML} - </select> + <td class="row1" width="22%"><span class="gen"><b>{L_ARTICLE_CATS}</b></span><br /><span class="gensmall">{L_ARTICLECATS_DESC}</span></td> + <td class="row2" width="78%"><select name="cats" size="4" multiple="multiple" id="cats"> + {CATS_HTML} + </select> </td> </tr> <tr> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |