From: <vb...@us...> - 2002-09-19 04:15:50
|
Update of /cvsroot/webnotes/webnotes/core In directory usw-pr-cvs1:/tmp/cvs-serv24424/core Modified Files: config_defaults_inc.php constants_inc.php link_api.php note_api.php page_api.php Log Message: - page_delete_notes() was not executing the query and hence leaving orphan notes. - Added some extra actions for viewing / moderation. - Added visibility states as constants. - Implemented note_accept(), note_pending(), note_decline(), note_archive(), note_delete() and note_pack_deleted(). - Changed some $g_ with config_get(). - Enhanced link_api to support custom captions. For example, the caption may be an image, text, or whatever. - Initial structure to be used for inline moderation. - View notes with different visibility levels based on the access levels. Index: config_defaults_inc.php =================================================================== RCS file: /cvsroot/webnotes/webnotes/core/config_defaults_inc.php,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- config_defaults_inc.php 18 Sep 2002 12:33:31 -0000 1.3 +++ config_defaults_inc.php 19 Sep 2002 04:15:48 -0000 1.4 @@ -136,12 +136,19 @@ # specified set of access levels ($g_access_sets), then it should be set to # NOBODY. $g_access_levels = array( - ACTION_NOTES_VIEW => ANONYMOUS, - ACTION_NOTES_SUBMIT => ANONYMOUS, + ACTION_NOTES_VIEW_PENDING => MODERATOR, + ACTION_NOTES_VIEW_ACCEPTED => EVERYBODY, + ACTION_NOTES_VIEW_DECLINED => MODERATOR, + ACTION_NOTES_VIEW_ARCHIVED => MODERATOR, + ACTION_NOTES_VIEW_DELETED => ADMINISTRATOR, + ACTION_NOTES_SUBMIT => EVERYBODY, + ACTION_NOTES_ADD => MODERATOR, ACTION_NOTES_EDIT => MODERATOR, ACTION_NOTES_EDIT_OWN => REGISTERED, ACTION_NOTES_DELETE_OWN => REGISTERED, ACTION_NOTES_MODERATE => MODERATOR, + ACTION_NOTES_PACK_DELETED => NOBODY, + ACTION_NOTES_PACK_DECLINED => MODERATOR, ACTION_USERS_MANAGE => ADMINISTRATOR, ACTION_USERS_ADD => ADMINISTRATOR, ACTION_USERS_EDIT => ADMINISTRATOR, @@ -154,21 +161,9 @@ # This array specified for each action, the user types that can perform it. # This is more flexible than specifying a threshold. This is only used when # the threshold is set to NOBODY for the specified action. - $g_access_sets = array( - ACTION_NOTES_VIEW => array(), - ACTION_NOTES_SUBMIT => array(), - ACTION_NOTES_EDIT => array(), - ACTION_NOTES_EDIT_OWN => array(), - ACTION_NOTES_DELETE_OWN => array(), - ACTION_NOTES_MODERATE => array(), - ACTION_USERS_MANAGE => array(), - ACTION_USERS_ADD => array(), - ACTION_USERS_EDIT => array(), - ACTION_USERS_EDIT_OWN => array(), - ACTION_USERS_DELETE => array(), - ACTION_PAGES_MANAGE => array(), - ACTION_PAGES_ADD => array(), - ACTION_PAGES_DELETE => array() ); + # Added one example below (although this could have been done by setting + # the threshold to ADMINISTRATOR. + $g_access_sets = array( ACTION_NOTES_PACK_DELETED => array( ADMINISTRATOR ) ); ################### # EMAIL SETTINGS Index: constants_inc.php =================================================================== RCS file: /cvsroot/webnotes/webnotes/core/constants_inc.php,v retrieving revision 1.6 retrieving revision 1.7 diff -u -d -r1.6 -r1.7 --- constants_inc.php 18 Sep 2002 12:33:31 -0000 1.6 +++ constants_inc.php 19 Sep 2002 04:15:48 -0000 1.7 @@ -14,33 +14,55 @@ define( 'ON', 1 ); define( 'OFF', 0 ); - + # Authentication Types define( 'AUTH_PLAIN', 0 ); define( 'AUTH_CRYPT', 1 ); define( 'AUTH_MD5', 2 ); - # User Levels + # User Levels (these are saved in the db) define( 'NOBODY', 100 ); # to disable an action completely (no user has access level 100) define( 'ADMINISTRATOR', 90 ); define( 'MODERATOR', 70 ); define( 'REGISTERED', 40 ); define( 'ANONYMOUS', 10 ); + define( 'EVERYBODY', 0 ); # Actions - define( 'ACTION_NOTES_VIEW', 1 ); - define( 'ACTION_NOTES_SUBMIT', 2 ); - define( 'ACTION_NOTES_EDIT', 3 ); - define( 'ACTION_NOTES_EDIT_OWN', 4 ); - define( 'ACTION_NOTES_DELETE', 5 ); - define( 'ACTION_NOTES_DELETE_OWN', 6 ); - define( 'ACTION_NOTES_MODERATE', 7 ); + define( 'ACTION_NOTES_VIEW_PENDING', 0 ); + define( 'ACTION_NOTES_VIEW_ACCEPTED', 1 ); + define( 'ACTION_NOTES_VIEW_DECLINED', 2 ); + define( 'ACTION_NOTES_VIEW_ARCHIVED', 3 ); + define( 'ACTION_NOTES_VIEW_DELETED', 4 ); + define( 'ACTION_NOTES_SUBMIT', 10 ); # add as pending + define( 'ACTION_NOTES_ADD', 11 ); # add as accepted + define( 'ACTION_NOTES_EDIT', 20 ); + define( 'ACTION_NOTES_EDIT_OWN', 21 ); + define( 'ACTION_NOTES_DELETE', 30 ); + define( 'ACTION_NOTES_DELETE_OWN', 31 ); + define( 'ACTION_NOTES_MODERATE', 40 ); + define( 'ACTION_NOTES_MODERATE_PENDING', 41 ); + define( 'ACTION_NOTES_MODERATE_ACCEPTED', 42 ); + define( 'ACTION_NOTES_MODERATE_DECLINED', 43 ); + define( 'ACTION_NOTES_MODERATE_ARCHIVED', 44 ); + define( 'ACTION_NOTES_MODERATE_DELETED', 45 ); + define( 'ACTION_NOTES_PACK_DELETED', 50 ); + define( 'ACTION_NOTES_PACK_DECLINED', 51 ); + define( 'ACTION_USERS_MANAGE', 101 ); define( 'ACTION_USERS_ADD', 102 ); define( 'ACTION_USERS_EDIT', 103 ); define( 'ACTION_USERS_EDIT_OWN', 104 ); define( 'ACTION_USERS_DELETE', 105 ); + define( 'ACTION_PAGES_MANAGE', 201 ); define( 'ACTION_PAGES_ADD', 202 ); define( 'ACTION_PAGES_DELETE', 203 ); + + # Note Visible States (these are saved in the db) + define( 'NOTE_VISIBLE_PENDING', 0 ); + define( 'NOTE_VISIBLE_ACCEPTED', 1 ); + define( 'NOTE_VISIBLE_DECLINED', 2 ); + define( 'NOTE_VISIBLE_ARCHIVED', 3 ); + define( 'NOTE_VISIBLE_DELETED', 4 ); ?> Index: link_api.php =================================================================== RCS file: /cvsroot/webnotes/webnotes/core/link_api.php,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- link_api.php 11 Sep 2002 09:49:54 -0000 1.3 +++ link_api.php 19 Sep 2002 04:15:48 -0000 1.4 @@ -13,34 +13,51 @@ ########################################################################### ### -------------------- - function link_note_action( $p_note_id, $p_action, $p_url, $p_link_active = true ) { - $t_caption = lang_get( 'action_' . $p_action ); + function link_note_action( $p_note_id, $p_action, $p_url, $p_link_active = true, $p_caption = null ) { + if ( null === $p_caption ) { + $t_caption = lang_get( 'action_' . $p_action ); + $t_before = '[ '; + $t_after = ' ]'; + } else { + $t_caption = $p_caption; + $t_before = $t_after = ''; + } + $c_note_id = db_prepare_int( $p_note_id ); $c_action = urlencode( $p_action ); $c_url = urlencode( $p_url ); $t_action = config_get( 'web_directory') . 'action.php'; - + if ( $p_link_active ) { - return "[ <a href=\"$t_action?f_action=$c_action&f_note_id=$c_note_id&f_url=$c_url\">$t_caption</a> ]"; + $t_link = "$t_action?f_action=$c_action&f_note_id=$c_note_id&f_url=$c_url"; + return $t_before . "<a href=\"$t_link\">$t_caption</a>" . $t_after; } else { - return "[ $t_caption ]"; + return $t_before . $t_caption . $t_after; } } ### -------------------- # $p_page = $p_page_id if action is unindex # $p_page = $p_page_name if action is index - function link_page_action( $p_page, $p_action, $p_url, $p_link_active = true ) { - $t_caption = lang_get( 'action_' . $p_action ); + function link_page_action( $p_page, $p_action, $p_url, $p_link_active = true, $p_caption = null ) { + if ( null === $p_caption ) { + $t_caption = lang_get( 'action_' . $p_action ); + $t_before = '[ '; + $t_after = ' ]'; + } else { + $t_caption = $p_caption; + $t_before = $t_after = ''; + } - $c_page_id = urlencode( $p_page ); + $c_page_id = urlencode( $p_page ); $c_action = urlencode( $p_action ); $c_url = urlencode( $p_url ); - $t_action = config_get( 'web_directory') . 'action.php'; + $t_action = config_get( 'web_directory' ) . 'action.php'; if ( $p_link_active ) { - return "[ <a href=\"$t_action?f_action=$c_action&f_page_id=$c_page_id&f_url=$c_url\">$t_caption</a> ]"; + $t_link = "$t_action?f_action=$c_action&f_page_id=$c_page_id&f_url=$c_url"; + return $t_before . "<a href=\"$t_link\">$t_caption</a>" . $t_after; } else { - return "[ $t_caption ]"; + return $t_before . "$t_caption" . $t_after; } } ?> Index: note_api.php =================================================================== RCS file: /cvsroot/webnotes/webnotes/core/note_api.php,v retrieving revision 1.16 retrieving revision 1.17 diff -u -d -r1.16 -r1.17 --- note_api.php 15 Sep 2002 02:25:58 -0000 1.16 +++ note_api.php 19 Sep 2002 04:15:48 -0000 1.17 @@ -9,25 +9,24 @@ # -------------------------------------------------------- ### -------------------- + # allow an array of visibilities as a parameter function note_queue_count() { - global $g_phpWN_note_table, $g_phpWN_page_table; - # the reason of including the page is to avoid counting orphan # notes. $query = "SELECT COUNT(*) - FROM $g_phpWN_note_table n, $g_phpWN_page_table p - WHERE visible='0' AND n.page_id = p.id"; + FROM " . config_get( 'phpWN_note_table' ) . " n, + " . config_get( 'phpWN_page_table' ) . " p + WHERE n.page_id = p.id AND + visible='" . NOTE_VISIBLE_PENDING . "'"; $result = db_query( $query ); return db_result( $result, 0, 0 ); } ### -------------------- function note_add( $p_page_id, $p_email, $p_remote_addr, $p_note ) { - global $g_phpWN_note_table; - if ( ON == config_get('auto_accept_notes') ) { - $t_visible = 1; + $t_visible = NOTE_VISIBLE_ACCEPTED; } else { - $t_visible = 0; + $t_visible = NOTE_VISIBLE_PENDING; } $c_page_id = db_prepare_int( $p_page_id ); @@ -35,70 +34,69 @@ $c_note = db_prepare_string( $p_note ); $c_remote_address = db_prepare_string( $p_remote_addr ); - $query = "INSERT - INTO $g_phpWN_note_table + $query = "INSERT INTO " . config_get( 'phpWN_note_table' ) . " ( id, page_id, email, ip, date_submitted, note, visible ) VALUES ( null, '$c_page_id', '$c_email', '$c_remote_address', NOW(), '$c_note', '$t_visible' )"; return db_query( $query ); } ### -------------------- - function note_delete( $p_id ) { - global $g_phpWN_note_table; - + function note_update_visiblity( $p_id, $p_visibility ) { $c_id = db_prepare_int( $p_id ); + $c_visibility = db_prepare_int( $p_visibility ); - $query = "DELETE FROM $g_phpWN_note_table - WHERE id='$c_id'"; + $query = "UPDATE " . config_get( 'phpWN_note_table' ) . " + SET visible='$c_visibility' + WHERE id='$c_id' LIMIT 1"; $result = db_query( $query ); } ### -------------------- - function note_update( $p_id, $p_email, $p_note ) { - global $g_phpWN_note_table; - - $c_id = db_prepare_int( $p_id ); - $c_email = db_prepare_string( $p_email ); - $c_note = db_prepare_string( $p_note ); - - $query = "UPDATE $g_phpWN_note_table - SET email='$c_email', note='$c_note' - WHERE id='$c_id'"; - $result = db_query( $query ); + # Put back as pending if approved by default. + function note_pending( $p_id ) { + note_update_visibility( $p_id, NOTE_VISIBLE_PENDING ); } ### -------------------- function note_accept( $p_id ) { - global $g_phpWN_note_table; - - $c_id = db_prepare_int( $p_id ); - $query = "UPDATE $g_phpWN_note_table - SET visible='1' - WHERE id='$c_id'"; - $result = db_query( $query ); + note_update_visibility( $p_id, NOTE_VISIBLE_ACCEPTED ); } ### -------------------- function note_decline( $p_id ) { - global $g_phpWN_note_table; - - $c_id = db_prepare_int( $p_id ); - $query = "DELETE FROM $g_phpWN_note_table - WHERE id='$c_id'"; - $result = db_query( $query ); + note_update_visibility( $p_id, NOTE_VISIBLE_DECLINED ); } ### -------------------- function note_archive( $p_id ) { + note_update_visibility( $p_id, NOTE_VISIBLE_ARCHIVED ); } ### -------------------- - function note_print_all( $p_page_name, $p_url ) { - global $g_phpWN_note_table, $g_phpWN_page_table, - $g_note_order; + function note_delete( $p_id ) { + note_update_visibility( $p_id, NOTE_VISIBLE_DELETED ); + } + ### -------------------- + function note_pack_deleted() { + $query = "DELETE FROM " . config_get( 'phpWN_note_table' ) . " + WHERE visible='" . NOTE_VISIBLE_DELETED ."'"; + $result = db_query( $query ); + } + ### -------------------- + function note_update( $p_id, $p_email, $p_note ) { + $c_id = db_prepare_int( $p_id ); + $c_email = db_prepare_string( $p_email ); + $c_note = db_prepare_string( $p_note ); + $query = "UPDATE " . config_get( 'phpWN_note_table' ) . " + SET email='$c_email', note='$c_note' + WHERE id='$c_id' LIMIT 1"; + $result = db_query( $query ); + } + ### -------------------- + function note_print_all( $p_page_name, $p_url ) { $c_page_name = db_prepare_string( $p_page_name ); $query = "SELECT * - FROM $g_phpWN_page_table p, - $g_phpWN_note_table n - WHERE p.page='$c_page_name' AND n.page_id=p.id AND n.visible='1' - ORDER BY n.date_submitted $g_note_order"; + FROM " . config_get( 'phpWN_page_table' ) . " p, + " . config_get( 'phpWN_note_table' ) . " n + WHERE p.page='$c_page_name' AND n.page_id=p.id + ORDER BY n.date_submitted " . config_get( 'note_order' ); $result = db_query( $query ); $entry_count = db_num_rows( $result ); @@ -106,6 +104,27 @@ $row = db_fetch_array( $result ); extract( $row, EXTR_PREFIX_ALL, 'v' ); + if ( ( NOTE_VISIBLE_PENDING === $v_visible ) && ( access_check_action( ACTION_NOTES_VIEW_PENDING ) === false ) ) { + continue; + } + + if ( ( NOTE_VISIBLE_ACCEPTED === $v_visible ) && ( access_check_action( ACTION_NOTES_VIEW_ACCEPTED ) === false ) ) { + continue; + } + + if ( ( NOTE_VISIBLE_DECLINED === $v_visible ) && ( access_check_action( ACTION_NOTES_VIEW_DECLINED ) === false ) ) { + continue; + } + + if ( ( NOTE_VISIBLE_ARCHIVED === $v_visible ) && ( access_check_action( ACTION_NOTES_VIEW_ARCHIVED ) === false ) ) { + continue; + } + + if ( ( NOTE_VISIBLE_DELETED === $v_visible ) && ( access_check_action( ACTION_NOTES_VIEW_DELETED ) === false ) ) { + continue; + } + + $info['visible'] = $v_visible; $info['id'] = $v_id; $info['email'] = $v_email; $info['note'] = string_add_note_links( $p_url, string_preserve_spaces( string_disable_html( $v_note ) ) ); @@ -118,15 +137,16 @@ } } ### -------------------- + # @@@@ Should be obsolete soon! function note_queue( $p_only_one = true ) { - global $g_phpWN_note_table, $g_phpWN_page_table; - $query = "SELECT n.id as note_id, n.*, p.page - FROM $g_phpWN_note_table n, $g_phpWN_page_table p - WHERE n.visible='0' AND n.page_id=p.id"; - + FROM " . config_get( 'phpWN_note_table' ) . " n, + " . config_get( 'phpWN_page_table' ) . " p + WHERE n.visible='" . NOTE_VISIBLE_PENDING . "' + AND n.page_id=p.id"; + if ( $p_only_one ) { - $query .= ' LIMIT 1'; + $query .= ' LIMIT 1'; } else { $query .= ' ORDER BY p.page, n.date_submitted'; } @@ -138,14 +158,13 @@ global $g_primary_light_color, $g_primary_dark_color, $g_white_color, $g_header_color, $g_admin_manage_notes, - $g_phpWN_note_table, $s_date, $s_email, $s_ip, $s_note, $s_delete_button, $s_update_button; $c_page_id = db_prepare_int( $p_page_id ); $query = "SELECT * - FROM $g_phpWN_note_table + FROM " . config_get( 'phpWN_note_table' ) . " WHERE page_id='$c_page_id' ORDER BY date_submitted"; $result = db_query( $query ); @@ -215,9 +234,7 @@ $t_page_id = page_get_id( $p_file ); if ( !page_valid_id( $t_page_id ) ) { - global $g_auto_index_pages; - - if ( ON === $g_auto_index_pages ) { + if ( ON === config_get( 'auto_index_pages' ) ) { if ( page_add( $p_file ) ) { print_web_notes( $p_file, $p_url ); return; Index: page_api.php =================================================================== RCS file: /cvsroot/webnotes/webnotes/core/page_api.php,v retrieving revision 1.9 retrieving revision 1.10 diff -u -d -r1.9 -r1.10 --- page_api.php 11 Sep 2002 09:49:54 -0000 1.9 +++ page_api.php 19 Sep 2002 04:15:48 -0000 1.10 @@ -10,12 +10,10 @@ ### -------------------- function page_get_id( $p_file ) { - global $g_phpWN_page_table; - $c_file = db_prepare_string( $p_file ); $query = "SELECT id - FROM $g_phpWN_page_table + FROM " . config_get( 'phpWN_page_table' ) . " WHERE page='$c_file' LIMIT 1"; @@ -36,36 +34,30 @@ } ### -------------------- function page_visible_notes_count( $p_page_id ) { - global $g_phpWN_note_table; - $c_page_id = db_prepare_int( $p_page_id ); $query = "SELECT COUNT(*) - FROM $g_phpWN_note_table - WHERE page_id=$c_page_id AND visible=1"; + FROM " . config_get( 'phpWN_note_table' ) . " + WHERE page_id='$c_page_id' AND visible='" . NOTE_VISIBLE_ACCEPTED . "'"; $result = db_query( $query ); return db_result( $result, 0, 0 ); } ### -------------------- function page_notes_count( $p_page_id ) { - global $g_phpWN_note_table; - $c_page_id = db_prepare_int( $p_page_id ); $query = "SELECT COUNT(*) - FROM $g_phpWN_note_table - WHERE page_id=$c_page_id"; + FROM " . config_get( 'phpWN_note_table' ) . " + WHERE page_id='$c_page_id'"; $result = db_query( $query ); return db_result( $result, 0, 0 ); } ### -------------------- function page_get_name( $p_page_id ) { - global $g_phpWN_page_table; - $c_page_id = db_prepare_int( $p_page_id ); $query = "SELECT page - FROM $g_phpWN_page_table + FROM " . config_get( 'phpWN_page_table' ) . " WHERE id='$c_page_id' LIMIT 1"; @@ -124,12 +116,9 @@ return 0; } - global $g_phpWN_page_table; - $c_page_name = db_prepare_string( $p_page_name ); - $query = "INSERT INTO - $g_phpWN_page_table + $query = "INSERT INTO " . config_get( 'phpWN_page_table' ) . " ( id, date_indexed, page ) VALUES ( null, NOW(), '$c_page_name' )"; @@ -174,30 +163,28 @@ } ### -------------------- function page_delete_notes( $p_page_id ) { - global $g_phpWN_note_table; - $c_page_id = db_prepare_int( $p_page_id ); - $query = "DELETE FROM $g_phpWN_note_table + $query = "DELETE FROM " . config_get( 'phpWN_note_table' ) . " WHERE page_id='$c_page_id'"; + $result = db_query( $query ); + return true; } ### -------------------- function page_delete( $p_page_id ) { - global $g_phpWN_page_table; + if ( !page_delete_notes( $p_page_id ) ) { + return false; + } $c_page_id = db_prepare_int( $p_page_id ); - $query = "DELETE FROM $g_phpWN_page_table + $query = "DELETE FROM " . config_get( 'phpWN_page_table' ) . " WHERE id='$c_page_id' LIMIT 1"; $result = db_query( $query ); - - if ( !page_delete_notes( $p_page_id ) ) { - return false; - }; return true; } |