# HG changeset patch # User Dan # Date 1195000790 18000 # Node ID 3f66ec435f087cc3ab1f1f510b3b6abdc350d356 # Parent 6eea55374f5bc36cf7f9862180e51792d8e34947 Some basic admin implemented diff -r 6eea55374f5b -r 3f66ec435f08 decir/admincp/admin_base.php --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/decir/admincp/admin_base.php Tue Nov 13 19:39:50 2007 -0500 @@ -0,0 +1,105 @@ +attachHook('base_classes_initted', ' + $paths->add_page(Array( + \'name\'=>\'Decir Administration Panel\', + \'urlname\'=>\'DecirAdmin\', + \'namespace\'=>\'Special\', + \'special\'=>0,\'visible\'=>0,\'comments_on\'=>0,\'protected\'=>1,\'delvotes\'=>0,\'delvote_ips\'=>\'\', + )); + '); + +function page_Special_DecirAdmin() +{ + global $db, $session, $paths, $template, $plugins; // Common objects + + if ( $session->user_level < USER_LEVEL_ADMIN ) + die_friendly('Access denied', '

This page is restricted access.

'); + + if ( $session->auth_level < USER_LEVEL_ADMIN ) + redirect(makeUrlNS('Special', 'Login/' . $paths->page, 'level=' . USER_LEVEL_ADMIN, true), '', '', 0); + + $session->theme = 'admin'; + $session->style = 'default'; + $template = false; + unset($GLOBALS['template']); + unset($template); + $GLOBALS['template'] = new template(); + $template =& $GLOBALS['template']; + + $template->header(); + ?> + Add or remove forums, control user permissions, and check forum statistics. + + + + + +
+

Decir configuration

+
    + $link_text ) + { + if ( strpos($page_id, '|') ) + { + $namesp = substr($page_id, 0, strpos($page_id, '|')); + $page_id = substr($page_id, strpos($page_id, '|') + 1); + } + else + { + $namesp = 'Admin'; + } + $link_text = htmlspecialchars($link_text); + if ( $namesp == 'Admin' ) + { + $url = makeUrlNS('Special', 'DecirAdmin', 'module=' . $paths->nslist[$namesp] . $page_id, true); + } + else + { + $url = makeUrlNS($namesp, $page_id); + } + echo '
  • $link_text
  • "; + } + ?> +
+
+ nslist['Admin'] . 'DecirIndex'; + list($page_id, $namespace) = RenderMan::strToPageID($module); + $page = new PageProcessor($page_id, $namespace); + $page->send(); + ?> +
+ footer(); +} + +?> diff -r 6eea55374f5b -r 3f66ec435f08 decir/admincp/admin_forums.php --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/decir/admincp/admin_forums.php Tue Nov 13 19:39:50 2007 -0500 @@ -0,0 +1,429 @@ +auth_level < USER_LEVEL_ADMIN || $session->user_level < USER_LEVEL_ADMIN ) + { + echo '

Error: Not authenticated

It looks like your administration session is invalid or you are not authorized to access this administration page. Please re-authenticate to continue.

'; + return; + } + + $show_main_menu = true; + + if ( isset($_POST['act']) ) + { + switch ( $_POST['act'] ) + { + case "create": + case "create_finish": + + // Do we have any categories yet? + $q = $db->sql_query('SELECT forum_id, forum_name FROM ' . table_prefix . 'decir_forums WHERE forum_type = ' . FORUM_CATEGORY . ';'); + if ( !$q ) + $db->_die('Decir admin_forums.php retrieving category count'); + $need_category = ( $db->numrows() < 1 ); + $cats = array(); + if ( !$need_category ) + { + while ( list($cat_id, $cat_name) = $db->fetchrow_num() ) + { + $cats[ $cat_id ] = $cat_name; + } + } + + $db->free_result(); + + if ( $_POST['act'] == 'create_finish' ) + { + $errors = array(); + $forum_type = intval($_POST['forum_type']); + if ( $forum_type != FORUM_FORUM && $forum_type != FORUM_CATEGORY ) + $errors[] = 'Invalid forum type. X.X'; + $forum_name = trim($_POST['forum_name']); + if ( empty($forum_name) ) + $errors[] = 'Please enter a name for this forum.'; + $forum_desc = ''; + $forum_parent = 0; + if ( $forum_type == FORUM_FORUM ) + { + $forum_desc = trim($_POST['forum_desc']); + if ( empty($forum_desc) ) + $errors[] = 'Please enter a description for this forum.'; + $forum_parent = intval($_POST['forum_parent']); + if ( !isset($cats[$forum_parent]) ) + $errors[] = 'Invalid parent category'; + } + if ( count($errors) > 0 ) + { + // Errors encountered - bounce form back to the user + $show_main_menu = false; + $form = new Decir_Admin_SmartForm_Forum(DECIR_ADMIN_MODE_CREATE); + $form->forum_name = $forum_name; + $form->forum_desc = $forum_desc; + $form->forum_type = $forum_type; + $form->need_category = $need_category; + $form->category_list = $cats; + echo $form->html(); + break; + } + // All checks passed. Create forum. + $forum_name_db = $db->escape($forum_name); + $forum_desc_db = $db->escape($forum_desc); + $sql = 'INSERT INTO ' . table_prefix . "decir_forums(forum_name, forum_desc, forum_type, parent, num_topics, num_posts) VALUES\n" + . " ( '$forum_name_db', '$forum_desc_db', $forum_type, $forum_parent, 0, 0 );"; + if ( $db->sql_query($sql) ) + { + $forum_name = htmlspecialchars($forum_name); + $type = ( $forum_type == FORUM_FORUM ) ? 'forum' : 'category'; + echo "
The {$type} \"{$forum_name}\" has been created successfully.
"; + } + break; + } + // Create a smartform + $show_main_menu = false; + $form = new Decir_Admin_SmartForm_Forum(DECIR_ADMIN_MODE_CREATE); + $form->need_category = $need_category; + $form->category_list = $cats; + echo $form->html(); + break; + } + } + + if ( $show_main_menu ) + { + // Display the main forum admin interface + $form_url = makeUrlNS('Special', 'DecirAdmin', "module={$paths->nslist['Admin']}DecirForums", true); + echo "
"; + echo '
+ + + + '; + // Select and display all forums + $q = $db->sql_unbuffered_query('SELECT forum_id, forum_name, forum_type FROM ' . table_prefix . 'decir_forums ORDER BY ( forum_type = ' . FORUM_CATEGORY . ' ) DESC, forum_order;'); + + if ( !$q ) + $db->_die('Decir admin_forums.php selecting main forum datum'); + + if ( $row = $db->fetchrow() ) + { + do + { + } + while ( $row = $db->fetchrow() ); + } + else + { + echo ''; + } + + // Create forum button + echo ' + + '; + + echo '
Forum administration
There are no forums on this board.
+ +
+
'; + echo "
"; + } +} + +/** + * Smart form for creating and editing Decir forums. + * @package Decir + * @subpackage Administration + * @copyright 2007 Dan Fuhry + * @license GPL + */ + +class Decir_Admin_SmartForm_Forum +{ + + /** + * Whether we are creating or editing a forum. + * @var int + */ + + var $form_mode; + + /** + * The name of the forum - only used in edit mode. + * @var string + */ + + var $forum_name = ''; + + /** + * The description of the forum - only used in edit mode. + * @var string + */ + + var $forum_desc = ''; + + /** + * The type of entry this is (forum or category) + * @var int + */ + + var $forum_type = -1; + + /** + * Track if we need to make the user create a category as opposed to a forum. + * @var bool + */ + + var $need_category = false; + + /** + * The list of categories on the site. + * @var array + */ + + var $category_list = array(); + + /** + * Instance ID for javascripting + * @var string + */ + + var $instance_id; + + /** + * Constructor + * @param int Form type - should be DECIR_ADMIN_MODE_CREATE or DECIR_ADMIN_MODE_EDIT + */ + + function __construct($form_mode) + { + global $db, $session, $paths, $template, $plugins; // Common objects + $form_mode = intval($form_mode); + if ( $form_mode != DECIR_ADMIN_MODE_CREATE && $form_mode != DECIR_ADMIN_MODE_EDIT ) + die('Syntax error: $form_mode to Decir_Admin_SmartForm_Forum::__construct should be DECIR_ADMIN_MODE_CREATE or DECIR_ADMIN_MODE_EDIT.'); + + $this->form_mode = $form_mode; + $this->instance_id = $session->dss_rand(); + } + + /** + * PHP4 compatibility constructor. + * @see Decir_Admin_SmartForm_Forum::__construct + */ + + function Decir_Admin_SmartForm_Forum($form_type) + { + $this->__construct($form_type); + } + + /** + * Render the form into HTML. + * @return string + */ + + function html() + { + global $db, $session, $paths, $template, $plugins; // Common objects + $f_f = FORUM_FORUM; + $f_c = FORUM_CATEGORY; + $tpl_code = << + + + +
+ +
+ + + + + + + + + + + + + + +
+ + Create new forum + + Edit forum {FORUM_NAME} + +
+ Forum type: + + + +
+ Forum description: + + +
+
+ + +
style="display: none;" > + + + + + + + + + + + +
+ Category options +
+ Stub + + Stub +
+ + +
+
+ + + +
+ + + +
+ There aren't any categories on this site yet. You need to create at least one category before you can create a forum. +
+ + + +
+ + + + + + + + + + + + + + + +
+ Forum options +
+ Forum description: + + +
+ Create in category: + + +
+ + +
+
+ + + +
+ + +
+ + +EOF; + $parser = $template->makeParserText($tpl_code); + + $category_list = ''; + foreach ( $this->category_list as $cat_id => $cat_name ) + { + $cat_id = intval($cat_id); + $cat_name = htmlspecialchars($cat_name); + $category_list .= "\n "; + } + + // FIXME: these should really call addslashes and htmlspecialchars + + $parser->assign_vars(array( + 'INSTANCE_ID' => $this->instance_id, + 'FORUM_NAME' => htmlspecialchars($this->forum_name), + 'FORUM_DESC' => htmlspecialchars($this->forum_desc), + 'FORM_ACTION' => makeUrlNS('Special', 'DecirAdmin', 'module=' . $paths->nslist['Admin'] . 'DecirForums', true), + 'TYPE_FORUM' => FORUM_FORUM, + 'TYPE_CATEGORY' => FORUM_CATEGORY, + 'CATEGORY_LIST' => $category_list + )); + $parser->assign_bool(array( + 'mode_is_create' => ( $this->form_mode == DECIR_ADMIN_MODE_CREATE ), + 'show_opts_category' => ( $this->form_mode == DECIR_ADMIN_MODE_CREATE ? true : $this->forum_type == FORUM_CATEGORY ), + 'show_opts_forum' => ( $this->form_mode == DECIR_ADMIN_MODE_CREATE ? true : $this->forum_type == FORUM_FORUM ), + 'type_is_forum' => ( $this->forum_type != FORUM_CATEGORY ), + 'need_category' => ( $this->form_mode == DECIR_ADMIN_MODE_CREATE && $this->need_category ) + )); + + return $parser->run(); + } + +} + +?> diff -r 6eea55374f5b -r 3f66ec435f08 decir/admincp/admin_index.php --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/decir/admincp/admin_index.php Tue Nov 13 19:39:50 2007 -0500 @@ -0,0 +1,95 @@ +auth_level < USER_LEVEL_ADMIN || $session->user_level < USER_LEVEL_ADMIN ) + { + echo '

Error: Not authenticated

It looks like your administration session is invalid or you are not authorized to access this administration page. Please re-authenticate to continue.

'; + return; + } + + // + // Obtain forum statistics + // + + // Number of users + $q = $db->sql_query('SELECT COUNT(user_id)-1 AS num_users FROM ' . table_prefix . 'users;'); + if ( !$q ) + $db->_die(); + + $row = $db->fetchrow(); + $db->free_result(); + $num_users = $row['num_users']; + + // Number of posts + $q = $db->sql_query('SELECT COUNT(post_id) AS num_posts FROM ' . table_prefix . 'decir_posts;'); + if ( !$q ) + $db->_die(); + + $row = $db->fetchrow(); + $db->free_result(); + $num_posts = $row['num_posts']; + + // Board start date + $date = intval( getConfig('decir_install_date') ); + if ( !$date ) + { + $date = time(); + setConfig('decir_install_date', $date); + } + $start_date = date('F d, Y h:i a', $date); + + // Average posts per day + $board_age_days = round( ( time() / ( 60*60*24 ) ) - ( $date / ( 60*60*24 ) ) ); + if ( $board_age_days < 1 ) + { + $avg_posts = $num_posts; + } + else + { + $avg_posts = $num_posts / $board_age_days; + } + + echo '

Administration home

'; + echo '

Thank you for choosing Decir as your forum solution. From this panel you can control every aspect of your forum\'s behavior and appearance. If you need support + for Decir, you can visit the Enano support forums.

'; + echo '

Board statistics

'; + echo "
+ + + + + + + + + + + + + + + + + + +
Board statistics
Number of users:{$num_users}Number of posts:{$num_posts}
Board started:{$start_date} ({$board_age_days} days ago)Average posts per day:{$avg_posts}
+
"; +} + +?> diff -r 6eea55374f5b -r 3f66ec435f08 decir/constants.php --- a/decir/constants.php Wed Oct 24 18:30:03 2007 -0400 +++ b/decir/constants.php Tue Nov 13 19:39:50 2007 -0500 @@ -22,4 +22,7 @@ define('TOPIC_STICKY', 4); define('TOPIC_ANNOUNCE', 5); +define('DECIR_ADMIN_MODE_CREATE', 1); +define('DECIR_ADMIN_MODE_EDIT', 2); + ?> diff -r 6eea55374f5b -r 3f66ec435f08 decir/edit.php --- a/decir/edit.php Wed Oct 24 18:30:03 2007 -0400 +++ b/decir/edit.php Tue Nov 13 19:39:50 2007 -0500 @@ -164,6 +164,7 @@ footer(); ?> diff -r 6eea55374f5b -r 3f66ec435f08 decir/forum_index.php --- a/decir/forum_index.php Wed Oct 24 18:30:03 2007 -0400 +++ b/decir/forum_index.php Tue Nov 13 19:39:50 2007 -0500 @@ -48,6 +48,11 @@ { case FORUM_FORUM: $color = ( $row['user_level'] >= USER_LEVEL_ADMIN ) ? 'AA0000' : ( ( $row['user_level'] >= USER_LEVEL_MOD ) ? '00AA00' : '0000AA' ); + $last_post_info = ( $row['last_post_id'] ) ? + '' . $row['topic_title'] . '
+ ' . date('d M Y h:i a', $row['timestamp']) . '
+ by ' . $row['username'] . '' : + '<No posts>'; // Forum echo '<icon>' . $row['forum_name'] . '
' . $row['forum_desc'].' @@ -55,9 +60,7 @@ ' . $row['num_posts'] . ' - ' . $row['topic_title'] . '
- ' . date('d M Y h:i a', $row['timestamp']) . '
- by ' . $row['username'] . ' + ' . $last_post_info . '
'; @@ -82,6 +85,7 @@ echo ' '; +decir_show_footers(); $template->footer(); ?> diff -r 6eea55374f5b -r 3f66ec435f08 decir/functions.php --- a/decir/functions.php Wed Oct 24 18:30:03 2007 -0400 +++ b/decir/functions.php Tue Nov 13 19:39:50 2007 -0500 @@ -396,4 +396,17 @@ return true; } +/** + * Shows the administration link on the foot of the page. + */ + +function decir_show_footers() +{ + global $db, $session, $paths, $template, $plugins; // Common objects + if ( $session->user_level >= USER_LEVEL_ADMIN ) + { + echo '

Administration control panel

'; + } +} + ?> diff -r 6eea55374f5b -r 3f66ec435f08 decir/install.php --- a/decir/install.php Wed Oct 24 18:30:03 2007 -0400 +++ b/decir/install.php Tue Nov 13 19:39:50 2007 -0500 @@ -20,6 +20,62 @@ exit; } +function install_decir() +{ + global $db, $session, $paths, $template, $plugins; // Common objects + if ( $session->auth_level < USER_LEVEL_ADMIN ) + die('Snotty son of a b**** you are being today...'); + + // Build an array of queries + $schema = @file_get_contents( DECIR_ROOT . '/install.sql' ); + if ( !$schema ) + { + echo '
Decir installation error: can\'t load schema file
'; + return false; + } + + // Variables + $schema = str_replace('{{TABLE_PREFIX}}', table_prefix, $schema); + + $schema = explode("\n", $schema); + + foreach ( $schema as $i => $sql ) + { + $query =& $schema[$i]; + $t = trim($query); + if ( empty($t) || preg_match('/^(\#|--)/i', $t) ) + { + unset($schema[$i]); + unset($query); + } + } + + $schema = array_values($schema); + $schema = implode("\n", $schema); + $schema = explode(";\n", $schema); + + foreach ( $schema as $i => $sql ) + { + $query =& $schema[$i]; + if ( substr($query, ( strlen($query) - 1 ), 1 ) != ';' ) + { + $query .= ';'; + } + } + + foreach ( $schema as $sql ) + { + $q = $db->sql_query($sql); + if ( !$q ) + { + echo '
Decir installation failed: ' . $db->get_error() . '
'; + return false; + } + } + + return true; +} + if ( $v = getConfig('decir_version') ) { $mode = 'upgrade'; @@ -32,30 +88,46 @@ $page = ( isset($_POST['step']) && in_array($_POST['step'], array('welcome', 'install', 'finish')) ) ? $_POST['step'] : 'welcome'; -$template->header(); - -switch($page) +if ( $page == 'finish' ) +{ + require('forum_index.php'); +} +else { - case 'welcome': - ?> -

Welcome to Decir, the Enano bulletin board suite.

-

Before you can use your forum, we'll need to run a few database queries to get the forum set up.

-
- - -
- -
- - -
- header(); + + switch($page) + { + case 'welcome': + ?> +

Welcome to Decir, the Enano bulletin board suite.

+

Before you can use your forum, we'll need to run a few database queries to get the forum set up.

+
+ + +
+ +

Decir has been successfully installed.

+
+ + +
+ footer(); + } -$template->footer(); - diff -r 6eea55374f5b -r 3f66ec435f08 decir/install.sql --- a/decir/install.sql Wed Oct 24 18:30:03 2007 -0400 +++ b/decir/install.sql Tue Nov 13 19:39:50 2007 -0500 @@ -1,4 +1,4 @@ -CREATE TABLE decir_forums( +CREATE TABLE {{TABLE_PREFIX}}decir_forums( forum_id int(12) unsigned NOT NULL auto_increment, forum_type tinyint(2) unsigned NOT NULL DEFAULT 1, forum_name varchar(255) NOT NULL, @@ -13,7 +13,7 @@ forum_extra text, PRIMARY KEY ( forum_id ) ); -CREATE TABLE decir_topics( +CREATE TABLE {{TABLE_PREFIX}}decir_topics( topic_id int(15) unsigned NOT NULL auto_increment, forum_id int(12) unsigned NOT NULL, topic_title varchar(255) NOT NULL, @@ -26,9 +26,11 @@ topic_deleted tinyint(1) NOT NULL DEFAULT 0, topic_deletor int(12) DEFAULT NULL, topic_delete_reason varchar(255) DEFAULT NULL, + num_views bigint(21) UNSIGNED NOT NULL DEFAULT 0, + last_post bigint(18) UNSIGNED NOT NULL, PRIMARY KEY ( topic_id ) ); -CREATE TABLE decir_posts( +CREATE TABLE {{TABLE_PREFIX}}decir_posts( post_id bigint(18) unsigned NOT NULL auto_increment, topic_id bigint(15) unsigned NOT NULL, poster_id int(12) unsigned NOT NULL, @@ -41,13 +43,13 @@ post_deleted tinyint(1) NOT NULL DEFAULT 0, PRIMARY KEY ( post_id ) ); -CREATE TABLE decir_posts_text( +CREATE TABLE {{TABLE_PREFIX}}decir_posts_text( post_id bigint(18) unsigned NOT NULL, post_text longtext NOT NULL, bbcode_uid varchar(10) NOT NULL, PRIMARY KEY ( post_id ) ); -CREATE TABLE decir_hits( +CREATE TABLE {{TABLE_PREFIX}}decir_hits( hit_id bigint(21) unsigned NOT NULL auto_increment, user_id int(12) unsigned NOT NULL DEFAULT 1, topic_id bigint(15) unsigned NOT NULL, diff -r 6eea55374f5b -r 3f66ec435f08 decir/posting.php --- a/decir/posting.php Wed Oct 24 18:30:03 2007 -0400 +++ b/decir/posting.php Tue Nov 13 19:39:50 2007 -0500 @@ -317,6 +317,7 @@ echo ''; echo ''; +decir_show_footers(); $template->footer(); ?> diff -r 6eea55374f5b -r 3f66ec435f08 decir/viewforum.php --- a/decir/viewforum.php Wed Oct 24 18:30:03 2007 -0400 +++ b/decir/viewforum.php Tue Nov 13 19:39:50 2007 -0500 @@ -22,7 +22,8 @@ if(empty($fid)) { echo '

Invalid forum ID

'; - $template->footer(); + decir_show_footers(); +$template->footer(); return; } @@ -123,6 +124,7 @@ echo '

Post new topic

'; } +decir_show_footers(); $template->footer(); ?> diff -r 6eea55374f5b -r 3f66ec435f08 decir/viewtopic.php --- a/decir/viewtopic.php Wed Oct 24 18:30:03 2007 -0400 +++ b/decir/viewtopic.php Tue Nov 13 19:39:50 2007 -0500 @@ -11,7 +11,7 @@ * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for details. */ - + require('common.php'); require('bbcode.php'); require('functions_viewtopic.php'); @@ -27,7 +27,8 @@ { $template->header(); echo '

Invalid topic ID

'; - $template->footer(); + decir_show_footers(); +$template->footer(); return; } @@ -48,7 +49,8 @@ { $template->header(); echo '

Invalid topic ID

'; - $template->footer(); + decir_show_footers(); +$template->footer(); return; } } @@ -192,6 +194,7 @@ $q = $db->sql_query('INSERT INTO '.table_prefix."decir_hits(user_id, topic_id, timestamp) VALUES($session->user_id, $tid, $time);"); $q = $db->sql_query('UPDATE '.table_prefix."decir_topics SET num_views = num_views + 1 WHERE topic_id = $tid;"); +decir_show_footers(); $template->footer(); ?> diff -r 6eea55374f5b -r 3f66ec435f08 plugins/Decir.php --- a/plugins/Decir.php Wed Oct 24 18:30:03 2007 -0400 +++ b/plugins/Decir.php Tue Nov 13 19:39:50 2007 -0500 @@ -33,6 +33,8 @@ )); '); +require( DECIR_ROOT . '/admincp/admin_base.php' ); + function decir_early_init(&$paths, &$session) { $paths->addAdminNode('Decir forum configuration', 'General settings', 'DecirGeneral'); @@ -52,6 +54,7 @@ if ( getConfig('decir_version') != ENANO_DECIR_VERSION || isset($_POST['do_install_finish']) ) { + chdir(DECIR_ROOT); require(DECIR_ROOT . '/install.php'); return false; } @@ -84,10 +87,4 @@ } -function page_Admin_DecirGeneral() -{ - global $db, $session, $paths, $template, $plugins; if($session->auth_level < USER_LEVEL_ADMIN || $session->user_level < USER_LEVEL_ADMIN) { header('Location: '.makeUrl($paths->nslist['Special'].'Administration'.urlSeparator.'noheaders')); die('Hacking attempt'); } - echo 'Hello world!'; -} - ?>