[Phpbbkb-checkins] SF.net SVN: phpbbkb: [23] root
Status: Alpha
Brought to you by:
markthedaemon
|
From: <so...@us...> - 2006-11-24 14:46:51
|
Revision: 23
http://svn.sourceforge.net/phpbbkb/?rev=23&view=rev
Author: softphp
Date: 2006-11-24 06:46:46 -0800 (Fri, 24 Nov 2006)
Log Message:
-----------
- Added a lot of missing lang vars
- Finished correcting the errors Mark pointed out
- Posting articles now works, not completely though
TODO:
- Make cat_articles go one up when you create an article
- Code support for edit article & preview article
NOTE:
- Still no permissions at all
Modified Paths:
--------------
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/functions.php
===================================================================
--- root/kb/functions.php 2006-11-24 03:21:02 UTC (rev 22)
+++ root/kb/functions.php 2006-11-24 14:46:46 UTC (rev 23)
@@ -37,7 +37,7 @@
case "viewcat":
// View category
// id = $cat_id::$cat_name
- $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=view_cat&id='. $id_ary[0]) . '">' . $id_ary[1] .'</a></span>';
+ $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=view_cat&id='. $id_ary[0]) . '">' . $id_ary[1] .'</a></span>';
break;
case "viewsubcat":
@@ -51,7 +51,7 @@
message_die(GENERAL_ERROR, 'Could not query cat name.', '', __LINE__, __FILE__, $sql);
}
$maincat = $db->sql_fetchrow($result);
- $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=view_cat&id=' . $id_ary[2]) . '">' . $maincat['cat_title'] .'</a> -> <a class="nav" href="' . append_sid('kb.'.$phpEx.'?pid=view_cat&id=' . $id_ary[0]) . '">' . $id_ary[1] .'</a></span>';
+ $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=view_cat&id=' . $id_ary[2]) . '">' . $maincat['cat_title'] .'</a> -> <a class="nav" href="' . append_sid('kb.' . $phpEx.'?pid=view_cat&id=' . $id_ary[0]) . '">' . $id_ary[1] .'</a></span>';
break;
case "viewarticle":
@@ -64,7 +64,7 @@
case "main":
default:
- $navigation = '<span class="nav"> <a href="' . append_sid('kb.'.$phpEx) . '" class="nav">' . $lang['kb_main'] . '</a></span>';
+ $navigation = '<span class="nav"> <a href="' . append_sid('kb.' . $phpEx) . '" class="nav">' . $lang['kb_main'] . '</a></span>';
break;
}
@@ -117,7 +117,7 @@
// These vars we need for making html safe
$html_entities_match = array('#&(?!(\#[0-9]+;))#', '#<#', '#>#', '#"#');
$html_entities_replace = array('&', '<', '>', '"');
-
+/*
//
// Prepare an article for the database
//
@@ -126,6 +126,7 @@
global $board_config, $userdata, $lang, $phpEx, $phpbb_root_path;
// Check title
+ $article_title = "BLABLA";
if (!empty($article_title))
{
$article_title = htmlspecialchars(trim($article_title));
@@ -146,9 +147,20 @@
$error_msg .= (!empty($error_msg)) ? '<br />' . $lang['kb_empty_article'] : $lang['kb_empty_article'];
}
+ // Check Desc
+ if (!empty($article_desc))
+ {
+ $article_desc = htmlspecialchars(trim($article_desc));
+ }
+ else
+ {
+ $error_msg .= (!empty($error_msg)) ? '<br />' . $lang['kb_empty_article_desc'] : $lang['kb_empty_article_desc'];
+ }
+
// Check categories
- if(!empty($cat_id) && count($cat_id) > 0)
+ if(is_array($cat_id))
{
+ print_r($cat_id);
$cat_id = implode(",", $cat_id);
}
else
@@ -202,4 +214,5 @@
return $message;
}
+*/
?>
\ No newline at end of file
Modified: root/kb/ucp_class.php
===================================================================
--- root/kb/ucp_class.php 2006-11-24 03:21:02 UTC (rev 22)
+++ root/kb/ucp_class.php 2006-11-24 14:46:46 UTC (rev 23)
@@ -27,6 +27,8 @@
class ucp
{
var $action = "";
+ var $html_entities_match = array('#&(?!(\#[0-9]+;))#', '#<#', '#>#', '#"#');
+ var $html_entities_replace = array('&', '<', '>', '"');
function generate_page($action, $id=0, $preview=false)
{
@@ -113,6 +115,7 @@
global $template, $board_config, $db, $userdata, $lang, $phpbb_root_path, $phpEx, $HTTP_POST_VARS;
$error_msg = '';
+ $user_sig = $userdata['user_sig'];
if(!empty($HTTP_POST_VARS['post']))
{
@@ -124,7 +127,7 @@
}
else
{
- $html_on = ( !empty($HTTP_POST_VARS['disable_html']) ) ? 0 : TRUE;
+ $html_on = ( !empty($HTTP_POST_VARS['disable_html']) ) ? 0 : 1;
}
if ( !$board_config['allow_bbcode'] )
@@ -133,7 +136,7 @@
}
else
{
- $bbcode_on = ( !empty($HTTP_POST_VARS['disable_bbcode']) ) ? 0 : TRUE;
+ $bbcode_on = ( !empty($HTTP_POST_VARS['disable_bbcode']) ) ? 0 : 1;
}
if ( !$board_config['allow_smilies'] )
@@ -142,26 +145,26 @@
}
else
{
- $smilies_on = ( !empty($HTTP_POST_VARS['disable_smilies']) ) ? 0 : TRUE;
+ $smilies_on = ( !empty($HTTP_POST_VARS['disable_smilies']) ) ? 0 : 1;
}
- $article_desc = ( !empty($HTTP_POST_VARS['desc']) ) ? $HTTP_POST_VARS['desc'] : '';
+ $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'];
$bbcode_uid = '';
$cat_id = $HTTP_POST_VARS['cats'];
- $attach_sig = ( !empty($HTTP_POST_VARS['attach_sig']) ) ? TRUE : 0;
+ $attach_sig = ( !empty($HTTP_POST_VARS['attach_sig']) ) ? 1 : 0;
- prepare_article($bbcode_on, $html_on, $smilies_on, $error_msg, $bbcode_uid, $article_title, $article_desc, $message, $cat_id);
-
+ $this->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');";
+ $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_bbcode, enable_smilies, article_text) VALUES
+ ('', '$cat_id', '$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))
{
message_die(GENERAL_ERROR, 'Error in adding article', '', __LINE__, __FILE__, $sql);
@@ -169,19 +172,21 @@
$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>');
+ $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;
}
}
$preview = ( !empty($HTTP_POST_VARS['preview']) ) ? true : false;
- if($mode == "post" && !$preview)
+ if($mode == "post" && !$preview && $error_msg == '')
{
$article_title = '';
$article_text = '';
$article_desc = '';
$authorname = $userdata['username'];
- $form_action = append_sid('kb.'.$phpEx.'?pid=ucp&action=post_article');
+ $form_action = append_sid('kb.' . $phpEx . '?pid=ucp&action=post_article');
$hidden_form_fields = "";
$attach_sig = ( $userdata['user_id'] == ANONYMOUS ) ? 0 : $userdata['user_attachsig'];
@@ -217,7 +222,7 @@
// Do funny preview stuff
}
}
- elseif($preview)
+ elseif($preview || $error_msg != '')
{
$article_title = $HTTP_POST_VARS['title'];
$article_text = $HTTP_POST_VARS['message'];
@@ -230,8 +235,19 @@
$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");
+ $form_action = append_sid("kb.php?pid=ucp&action=post_article");
$hidden_form_fields = "";
+
+ if($error_msg != "")
+ {
+ $template->set_filenames(array(
+ 'reg_header' => 'error_body.tpl')
+ );
+ $template->assign_vars(array(
+ 'ERROR_MESSAGE' => $error_msg)
+ );
+ $template->assign_var_from_handle('ERROR_BOX', 'reg_header');
+ }
}
else
{
@@ -255,7 +271,7 @@
$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");
+ $form_action = append_sid("kb.php?pid=ucp&action=edit_article");
$hidden_form_fields = "";
}
@@ -354,8 +370,9 @@
'AUTHORNAME' => $authorname,
'ARTICLE_TITLE' => $article_title,
'ARTICLE' => $article_text,
+ 'DESC' => $article_desc,
'HTML_STATUS' => $html_status,
- 'BBCODE_STATUS' => sprintf($bbcode_status, '<a href="' . append_sid("faq.$phpEx?mode=bbcode") . '" target="_phpbbcode">', '</a>'),
+ 'BBCODE_STATUS' => sprintf($bbcode_status, '<a href="' . append_sid("faq." . $phpEx . "?mode=bbcode") . '" target="_phpbbcode">', '</a>'),
'SMILIES_STATUS' => $smilies_status,
'L_POST_ARTICLE' => $lang['kb_post_article'],
@@ -426,5 +443,100 @@
'S_HIDDEN_FORM_FIELDS' => $hidden_form_fields)
);
}
+
+ //
+ // 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 = $this->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 Desc
+ if (!empty($article_desc))
+ {
+ $article_desc = htmlspecialchars(trim($article_desc));
+ }
+ else
+ {
+ $error_msg .= (!empty($error_msg)) ? '<br />' . $lang['kb_empty_article_desc'] : $lang['kb_empty_article_desc'];
+ }
+
+ // Check categories
+ if(is_array($cat_id))
+ {
+ $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($this->html_entities_match, $this->html_entities_replace, $part) . clean_html($tag);
+ }
+
+ $message = addslashes($message);
+ $message = str_replace('"', '\"', $message);
+ }
+ else
+ {
+ $message = preg_replace($this->html_entities_match, $this->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.php
===================================================================
--- root/kb.php 2006-11-24 03:21:02 UTC (rev 22)
+++ root/kb.php 2006-11-24 14:46:46 UTC (rev 23)
@@ -23,6 +23,7 @@
include($phpbb_root_path . 'common.' . $phpEx);
include($phpbb_root_path . 'kb/constants.' . $phpEx); // Added these two files, yes i could just add the 10-15 lines it will end with in
include($phpbb_root_path . 'kb/functions.' . $phpEx); // the existing files, but this makes it a lot easier to install/uninstall.
+include($phpbb_root_path . 'includes/bbcode.'.$phpEx);
//
// Start session management
@@ -71,7 +72,7 @@
// Start Page output
$page_title = $lang['kb_main'];
- include($phpbb_root_path . 'includes/page_header.'.$phpEx);
+ include($phpbb_root_path . 'includes/page_header.' . $phpEx);
create_navigation();
$template->set_filenames(array(
@@ -92,7 +93,7 @@
'CAT_TITLE' => $catrows[$i]['cat_title'],
'CAT_DESC' => $catrows[$i]['cat_desc'],
'CAT_ARTICLES' => $catrows[$i]['cat_articles'],
- 'U_VIEWCAT' => append_sid("kb.$phpEx?pid=view_cat&id=" . $catrows[$i]['cat_id']),
+ 'U_VIEWCAT' => append_sid("kb." . $phpEx . "?pid=view_cat&id=" . $catrows[$i]['cat_id']),
'L_SUBCATS' => $lang['kb_subcats'],
'FORUM_FOLDER_IMG' => $images['forum']) // Stolen :D
);
@@ -124,7 +125,7 @@
$k = $j + 1;
$subcat_comma = ( isset($subcats[$k]) ) ? ", " : ".";
$template->assign_block_vars('catrow.subcatrow', array(
- 'U_SUBCAT' => append_sid("kb.$phpEx?pid=view_cat&id=" . $subcats[$j]['cat_id']),
+ 'U_SUBCAT' => append_sid("kb." . $phpEx . "?pid=view_cat&id=" . $subcats[$j]['cat_id']),
'SUBCAT_TITLE' => $subcats[$j]['cat_title'],
'SUBCAT_COMMA' => $subcat_comma)
);
@@ -270,7 +271,7 @@
'CAT_TITLE' => $subcats[$i]['cat_title'],
'CAT_DESC' => $subcats[$i]['cat_desc'],
'CAT_ARTICLES' => $subcats[$i]['cat_articles'],
- 'U_VIEWCAT' => append_sid("kb.$phpEx?pid=view_cat&id=" . $subcats[$i]['cat_id']),
+ 'U_VIEWCAT' => append_sid("kb." . $phpEx . "?pid=view_cat&id=" . $subcats[$i]['cat_id']),
'FORUM_FOLDER_IMG' => $images['forum']) // Stolen :D
);
}
@@ -300,7 +301,7 @@
{
$authorname = $articles[$i]['article_authorname'];
}
- $author = "<a href=\"profile.php?mode=viewprofile&u=" . $articles[$i]['article_author'] . "\">$authorname</a>";
+ $author = "<a href=\"profile.php?mode=viewprofile&u=" . $articles[$i]['article_author'] . "\">$authorname</a>";
$sql = "SELECT username
FROM " . USERS_TABLE . "
@@ -311,7 +312,7 @@
}
$user = $db->sql_fetchrow($result);
- $last_action = sprintf($lang['kb_last_action_row'], "<a href=\"profile.php?mode=viewprofile&u=" . $articles[$i]['article_editby'] . "\">" . $user['username'] . "</a>", create_date($board_config['default_dateformat'], $articles[$i]['article_edittime'], $board_config['board_timezone']));
+ $last_action = sprintf($lang['kb_last_action_row'], "<a href=\"profile.php?mode=viewprofile&u=" . $articles[$i]['article_editby'] . "\">" . $user['username'] . "</a>", create_date($board_config['default_dateformat'], $articles[$i]['article_edittime'], $board_config['board_timezone']));
$template->assign_block_vars('switch_articles.articlerow', array(
'TOPIC_FOLDER_IMG' => $images['folder'],
@@ -320,7 +321,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=viewarticle&cid=" . $cat_id . "&id=" . $articles[$i]['article_id']))
);
}
}
@@ -338,12 +339,12 @@
case "ucp":
$action = ( isset($HTTP_GET_VARS['action']) ) ? $HTTP_GET_VARS['action'] : "";
- include($phpbb_root_path . "kb/ucp_class.$phpEx");
+ 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);
+ include($phpbb_root_path . 'includes/page_header.' . $phpEx);
$ucp->generate_page($action, $HTTP_GET_VARS['id'], $HTTP_GET_VARS['preview']);
Modified: root/kb_install.php
===================================================================
--- root/kb_install.php 2006-11-24 03:21:02 UTC (rev 22)
+++ root/kb_install.php 2006-11-24 14:46:46 UTC (rev 23)
@@ -62,7 +62,7 @@
$sql[] = "CREATE TABLE " . $table_prefix . "kb_articles (
article_id mediumint(8) UNSIGNED NOT NULL auto_increment,
- cat_id mediumint(8) UNSIGNED DEFAULT '0',
+ cat_id varcharr(20) NOT NULL,
article_title varchar(100) NOT NULL,
article_desc varchar(255) NOT NULL,
article_author mediumint(8) UNSIGNED NOT NULL,
Modified: root/language/lang_english/lang_kb.php
===================================================================
--- root/language/lang_english/lang_kb.php 2006-11-24 03:21:02 UTC (rev 22)
+++ root/language/lang_english/lang_kb.php 2006-11-24 14:46:46 UTC (rev 23)
@@ -46,4 +46,11 @@
$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.";
+$lang['kb_empty_article'] = "The article content you have submitted was empty.";
+$lang['kb_empty_article_title'] = "The article title you submitted was empty.";
+$lang['kb_empty_cats'] = "The article you submitted had no category defined.";
+$lang['kb_empty_article_desc'] = "The article has to contain an article description.";
+$lang['kb_added'] = "Your article has been submitted and is awaiting approval.";
+$lang['kb_click_view_article'] = "Click %here% to view you article."; // Change this later on, they can't view the article yet.
+$lang['kb_click_return_ucp'] = "Click %here% to go back to the user control panel";
?>
\ No newline at end of file
Modified: root/templates/subSilver/kb_article_posting.tpl
===================================================================
--- root/templates/subSilver/kb_article_posting.tpl 2006-11-24 03:21:02 UTC (rev 22)
+++ root/templates/subSilver/kb_article_posting.tpl 2006-11-24 14:46:46 UTC (rev 23)
@@ -265,7 +265,7 @@
</tr>
<tr>
<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">
+ <td class="row2" width="78%"><select name="cats[]" size="4" multiple="multiple" id="cats">
{CATS_HTML}
</select>
</td>
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|