From: <vb...@us...> - 2002-09-03 22:30:12
|
Update of /cvsroot/webnotes/webnotes/core In directory usw-pr-cvs1:/tmp/cvs-serv21009/core Modified Files: api.php config_inc.php php_api.php Added Files: access_api.php config_api.php constants_inc.php database_api.php html_api.php lang_api.php note_api.php page_api.php string_api.php Log Message: - Split api.php into multiple APIs. - Merged lang_api.php over from Mantis. - Merged config_api.php over from Mantis. - Minor changes with the docs. --- NEW FILE: access_api.php --- <?php # phpWebNotes - a php based note addition system # Copyright (C) 2000 Kenzaburo Ito - ke...@30... # 2002 Webnotes Team - web...@so... # This program is distributed under the terms and conditions of the GPL # See the files README and LICENSE for details # -------------------------------------------------------- # $Id: access_api.php,v 1.1 2002/09/03 22:30:06 vboctor Exp $ # -------------------------------------------------------- ### -------------------- function password_match( $p_test_password, $p_password ) { $salt = substr( $p_password, 0, 2 ); if ( crypt( $p_test_password, $salt ) == $p_password ) { return true; } else { return false; } } ### -------------------- function create_random_password( $p_email ) { mt_srand( time() ); $t_val = mt_rand( 0, mt_getrandmax() ) + mt_rand( 0, mt_getrandmax() ); return substr( crypt( md5( $p_email.$t_val ) ), 0, 12 ); } ### -------------------- function is_moderator() { global $g_string_cookie_val, $g_phpWN_user_table, $g_hostname, $g_db_username, $g_db_password, $g_database_name; $query = "SELECT COUNT(*) FROM $g_phpWN_user_table WHERE cookie_string='$g_string_cookie_val'"; $result = db_query( $query ); $count = db_result( $result, 0, 0 ); return $count; } ### -------------------- ### checks to see that a user is logged in ### if the user is and the account is enabled then let them pass ### otherwise redirect them to the login page function login_cookie_check( $p_redirect_url="" ) { global $g_string_cookie_val, $g_login_page, $g_logout, $g_hostname, $g_db_username, $g_db_password, $g_database_name, $g_phpWN_user_table; ### @@@@@ DISABLE FOR NOW return; ### if logged in if ( isset( $g_string_cookie_val ) ) { if ( empty( $g_string_cookie_val ) ) { header( "Location: $g_login_page" ); exit; } ### go to redirect if ( !empty( $p_redirect_url ) ) { header( "Location: $p_redirect_url" ); exit; } ### continue with current page else { return; } } ### not logged in else { header( "Location: $g_login_page" ); exit; } } ### -------------------- ?> --- NEW FILE: config_api.php --- <?php # phpWebNotes - a php based note addition system # Copyright (C) 2000 Kenzaburo Ito - ke...@30... # 2002 Mantis Team - man...@so... # 2002 Webnotes Team - web...@so... # This program is distributed under the terms and conditions of the GPL # See the files README and LICENSE for details # -------------------------------------------------------- # $Id: config_api.php,v 1.1 2002/09/03 22:30:06 vboctor Exp $ # -------------------------------------------------------- ########################################################################### # Configuration API ########################################################################### # ------------------ # Retrieves the value of a config option # This function will return one of (in order of preference): # 1. The user-defined value (if set) # 2. The default value (if known) # 3. The value passed as the second parameter of the function function config_get( $p_option, $p_default=null ) { # ------ global variable implementation ------ # this function implements getting configuration # from our current global variable scheme. This # interface should remain constant but we could # call out to other functions or replace this code # to use a DB or some other method if ( isset( $GLOBALS['g_'.$p_option] ) ) { return $GLOBALS['g_'.$p_option]; } else { # unless we were allowing for the option not to exist by passing # a default, trigger a NOTICE if ( null == $p_default ) { error_parameters($p_option); trigger_error( ERROR_CONFIG_OPT_NOT_FOUND, NOTICE ); } return $p_default; } } # ------------------ # Returns true if the specified config option exists (ie. a # value or default can be found), false otherwise function config_is_set( $p_option ) { if ( isset( $GLOBALS['g_'.$p_option] ) ) { return true; } else { return false; } } # ------------------ # Sets the value of the given config option to the given value # If the config option does not exist, an ERROR is triggered function config_set( $p_option, $p_value ) { if ( ! isset( $GLOBALS['g_'.$p_option] ) ) { trigger_error( ERROR_CONFIG_OPT_NOT_FOUND, ERROR ); } $GLOBALS['g_'.$p_option] = $p_value; return true; } # ------------------ # Checks if an obsolete configuration variable is still in use. If so, an error # will be generated and the script will exit. This is called from login_page.php and # admin_check.php. function config_obsolete($var, $replace) { if ( config_is_set( $var ) ) { echo '$g_' . $var . ' is now obsolete'; if ($replace != '') { echo ', please use $g_' . $replace; } exit; } } ?> --- NEW FILE: constants_inc.php --- <?php # phpWebNotes - a php based note addition system # Copyright (C) 2000 Kenzaburo Ito - ke...@30... # 2002 Webnotes Team - web...@so... # This program is distributed under the terms and conditions of the GPL # See the files README and LICENSE for details # -------------------------------------------------------- # $Id: constants_inc.php,v 1.1 2002/09/03 22:30:07 vboctor Exp $ # -------------------------------------------------------- ########################################################################### ### CONSTANTS ### ########################################################################### define( 'ON', 1 ); define( 'OFF', 0 ); ?> --- NEW FILE: database_api.php --- <?php # phpWebNotes - a php based note addition system # Copyright (C) 2000 Kenzaburo Ito - ke...@30... # 2002 Webnotes Team - web...@so... # This program is distributed under the terms and conditions of the GPL # See the files README and LICENSE for details # -------------------------------------------------------- # $Id: database_api.php,v 1.1 2002/09/03 22:30:07 vboctor Exp $ # -------------------------------------------------------- ########################################################################### # Database : MYSQL for now ########################################################################### ### -------------------- # connect to database function db_connect($p_hostname="localhost", $p_username="root", $p_password="", $p_database="webnotes", $p_port=3306 ) { $t_result = mysql_connect( $p_hostname.":".$p_port, $p_username, $p_password ); $t_result = mysql_select_db( $p_database ); ### Temproary error handling if ( !$t_result ) { echo "ERROR: FAILED CONNECTION TO DATABASE"; exit; } } ### -------------------- # persistent connect to database function db_pconnect($p_hostname="localhost", $p_username="root", $p_password="", $p_database="webnotes", $p_port=3306 ) { $t_result = mysql_pconnect( $p_hostname.":".$p_port, $p_username, $p_password ); $t_result = mysql_select_db( $p_database ); ### Temproary error handling if ( !$t_result ) { echo "ERROR: FAILED CONNECTION TO DATABASE"; exit; } } ### -------------------- # execute query, requires connection to be opened, # goes to error page if error occurs # Use this when you don't want to handler an error yourself function db_query( $p_query ) { $t_result = mysql_query( $p_query ); if ( !$t_result ) { echo "ERROR: FAILED QUERY: ".$p_query; exit; } else { return $t_result; } } ### -------------------- function db_select_db( $p_db_name ) { return mysql_select_db( $p_db_name ); } ### -------------------- function db_num_rows( $p_result ) { return mysql_num_rows( $p_result ); } ### -------------------- function db_fetch_array( $p_result ) { return mysql_fetch_array( $p_result ); } ### -------------------- function db_result( $p_result, $p_index1=0, $p_index2=0 ) { if ( $p_result && ( db_num_rows( $p_result ) > 0 ) ) { return mysql_result( $p_result, $p_index1, $p_index2 ); } else { return false; } } ### -------------------- function db_close() { $t_result = mysql_close(); } ### -------------------- ########################################################################### ### CODE TO EXECUTE ### ########################################################################### db_connect( $g_hostname, $g_db_username, $g_db_password, $g_database_name ); ?> --- NEW FILE: html_api.php --- <?php # phpWebNotes - a php based note addition system # Copyright (C) 2000 Kenzaburo Ito - ke...@30... # 2002 Webnotes Team - web...@so... # This program is distributed under the terms and conditions of the GPL # See the files README and LICENSE for details # -------------------------------------------------------- # $Id: html_api.php,v 1.1 2002/09/03 22:30:07 vboctor Exp $ # -------------------------------------------------------- ### -------------------- function print_html_top() { echo '<html>'; } ### -------------------- function print_head_top() { echo '<head>'; } ### -------------------- function print_title( $p_title ) { echo "<title>$p_title</title>"; } ### -------------------- function print_css( $p_css="" ) { if ( !empty( $p_css ) && file_exists( $p_css ) ) { include( $p_css ); } } ### -------------------- function print_meta_redirect( $p_url, $p_time ) { echo "<meta http-equiv=\"Refresh\" content=\"$p_time;URL=$p_url\">"; } ### -------------------- function print_head_bottom() { echo '</head>'; } ### -------------------- function print_body_top() { echo '<body>'; } ### -------------------- function print_header( $p_title="" ) { echo "<h3>$p_title</h3>"; } ### -------------------- function print_top_page( $p_page ) { if ( !empty( $p_page ) && file_exists( $p_page ) ) { include( $p_page ); } } ### -------------------- function print_bottom_page( $p_page ) { if ( !empty( $p_page ) && file_exists( $p_page ) ) { include( $p_page ); } } ### -------------------- function print_footer( $p_file ) { global $g_string_cookie_val, $g_webmaster_email; echo '<hr size=1 />'; print_phpWebNotes_version(); echo '<address>Copyright (c) 2000-2002</address>'; echo '<address><a href=\"mailto:$g_webmaster_email\">$g_webmaster_email</a></address>'; } ### -------------------- function print_body_bottom() { echo '</body>'; } ### -------------------- function print_html_bottom() { echo '</html>'; } ### -------------------- ########################################################################### # HTML Appearance Helper API ########################################################################### ### -------------------- ### checks to see whether we need to be displaying the version number function print_phpWebNotes_version() { global $g_phpWebNotes_version, $g_show_version; if ( ON == $g_show_version ) { echo "<em>phpWebNotes - $g_phpWebNotes_version</em>"; } } ### -------------------- function print_admin_menu() { global $g_admin_page, $g_logout, $s_admin_link, $s_logout_link; echo '<div align="center">'; echo "<a href=\"$g_admin_page\">$s_admin_link</a> | "; echo "<a href=\"$g_logout\">$s_logout_link</a>"; echo '<br />'; } ?> --- NEW FILE: lang_api.php --- <?php # phpWebNotes - a php based note addition system # Copyright (C) 2000 Kenzaburo Ito - ke...@30... # 2002 Mantis Team - man...@so... # 2002 Webnotes Team - web...@so... # This program is distributed under the terms and conditions of the GPL # See the files README and LICENSE for details # -------------------------------------------------------- # $Id: lang_api.php,v 1.1 2002/09/03 22:30:07 vboctor Exp $ # -------------------------------------------------------- ### -------------------- # Retrieves an internationalized string # This function will return one of (in order of preference): # 1. The string in the current user's preferred language (if defined) # 2. The string in English function lang_get( $p_string ) { # note in the current implementation we always return the same value # because we don't have a concept of falling back on a language. The # language files actually *contain* English strings if none has been # defined in the correct language if ( isset( $GLOBALS['s_'.$p_string] ) ) { return $GLOBALS['s_'.$p_string]; } else { trigger_error( ERROR_LANG_STRING_NOT_FOUND, WARNING ); return ''; } } ?> --- NEW FILE: note_api.php --- <?php # phpWebNotes - a php based note addition system # Copyright (C) 2000 Kenzaburo Ito - ke...@30... # 2002 Webnotes Team - web...@so... # This program is distributed under the terms and conditions of the GPL # See the files README and LICENSE for details # -------------------------------------------------------- # $Id: note_api.php,v 1.1 2002/09/03 22:30:07 vboctor Exp $ # -------------------------------------------------------- ### -------------------- function queue_count() { global $g_phpWN_note_table; $query = "SELECT COUNT(*) FROM $g_phpWN_note_table WHERE visible='0'"; $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; $p_email = addslashes( htmlspecialchars( $p_email ) ); $p_note = addslashes( nl2br( htmlspecialchars( $p_note ) ) ); $query = "INSERT INTO $g_phpWN_note_table ( id, page_id, email, ip, date_submitted, note ) VALUES ( null, '$p_page_id', '$p_email', '$p_REMOTE_ADDR', NOW(), '$p_note' )"; return db_query( $query ); } ### -------------------- function delete_note( $p_id ) { global $g_phpWN_note_table; $query = "DELETE FROM $g_phpWN_note_table WHERE id='$p_id'"; $result = db_query( $query ); } ### -------------------- function update_note( $p_id, $p_email, $p_note ) { global $g_phpWN_note_table; $p_email = addslashes( htmlspecialchars( $p_email ) ); $p_note = addslashes( nl2br( htmlspecialchars( $p_note ) ) ); $query = "UPDATE $g_phpWN_note_table SET email='$p_email', note='$p_note' WHERE id='$p_id'"; $result = db_query( $query ); } ### -------------------- function accept_note( $p_id ) { global $g_phpWN_note_table; $query = "UPDATE $g_phpWN_note_table SET visible='1' WHERE id='$p_id'"; $result = db_query( $query ); } ### -------------------- function decline_note( $p_id ) { global $g_phpWN_note_table; $query = "DELETE FROM $g_phpWN_note_table WHERE id='$p_id'"; $result = db_query( $query ); } ### -------------------- function print_notes( $p_page_name ) { global $g_hostname, $g_db_username, $g_db_password, $g_database_name, $g_table_border_color, $g_primary_dark_color, $g_primary_light_color, $g_white_color, $g_phpWN_note_table, $g_phpWN_page_table, $p_note_order; $query = "SELECT * FROM $g_phpWN_page_table p, $g_phpWN_note_table n WHERE p.page='$p_page_name' AND n.page_id=p.id AND n.visible='1' ORDER BY n.date_submitted $p_note_order"; $result = db_query( $query ); $entry_count = db_num_rows( $result ); if ( $entry_count>0 ) { for ($i=0;$i<$entry_count;$i++) { $row = db_fetch_array( $result ); extract( $row, EXTR_PREFIX_ALL, "v" ); $v_email = stripslashes( $v_email ); $v_note = string_preserve_spaces( stripslashes( $v_note ) ); $date = date( "M, d Y H:i", sql_to_unix_time( $v_date_submitted ) ); PRINT "<tr bgcolor=\"$g_primary_dark_color\">"; PRINT "<td>"; PRINT " <i><a href=\"mailto:$v_email\">$v_email</a></i> - $v_date_submitted"; PRINT "</td>"; PRINT "</tr>"; PRINT "<tr bgcolor=$g_primary_light_color>"; PRINT "<td>"; echo $v_note; PRINT "</td>"; PRINT "</tr>"; PRINT "<tr bgcolor=\"$g_white_color\" height=\"2\">"; PRINT "<td>"; PRINT "</td>"; PRINT "</tr>"; } } } ### -------------------- ?> --- NEW FILE: page_api.php --- <?php # phpWebNotes - a php based note addition system # Copyright (C) 2000 Kenzaburo Ito - ke...@30... # 2002 Webnotes Team - web...@so... # This program is distributed under the terms and conditions of the GPL # See the files README and LICENSE for details # -------------------------------------------------------- # $Id: page_api.php,v 1.1 2002/09/03 22:30:07 vboctor Exp $ # -------------------------------------------------------- ### -------------------- function get_page_id( $p_file ) { global $g_hostname, $g_db_username, $g_db_password, $g_database_name, $g_phpWN_page_table; $query = "SELECT id FROM $g_phpWN_page_table WHERE page='$p_file'"; $result = db_query( $query ); if ( db_num_rows( $result) > 0 ) { return db_result( $result, 0, 0 ); } else { return ""; } } ### -------------------- function get_page_name( $p_id ) { global $g_hostname, $g_db_username, $g_db_password, $g_database_name, $g_phpWN_page_table; $query = "SELECT page FROM $g_phpWN_page_table WHERE id='$p_id'"; $result = db_query( $query ); if ( db_num_rows( $result) > 0 ) { return db_result( $result, 0, 0 ); } else { return ""; } } ### -------------------- ### Allows for path navigation to choose base dir function print_dirs( $p_path ) { global $g_admin_index_files; $handle = opendir( $p_path ); while ( $file = readdir( $handle ) ) { if ( is_dir( $p_path."/".$file )&&( $file!="." ) ) { if ($file=="..") { $t_path = dirname( $p_path ); PRINT "<a href=\"$g_admin_index_files?f_dir=$t_path\">$file</a><br />"; } else { PRINT "<a href=\"$g_admin_index_files?f_dir=$p_path/$file\">$file</a><br />"; } } } } ### -------------------- function add_file( $p_page_name ) { global $g_phpWN_page_table; $query = "SELECT COUNT(*) FROM $g_phpWN_page_table WHERE page='$p_page_name'"; $result = db_query( $query ); $count = db_result( $result, 0, 0 ); if ( $count == 1 ) { return 0; } $query = "INSERT INTO $g_phpWN_page_table ( id, date_indexed, page ) VALUES (null, NOW(), '$p_page_name' )"; $result = db_query( $query ); return $result; } ### -------------------- function index_files( $path="" ) { $dir_count = 0; $file_count = 0; $dir = array(); $xfile = array(); $handle = opendir( $path ); while ( $file = readdir( $handle ) ) { if ($file==".") {continue;} if ($file=="..") {continue;} if ( is_dir( $path.$file ) ) { $dir[$dir_count] = $file; $dir_count++; } else { $xfile[$file_count] = $file; $file_count++; } } closedir( $handle ); sort( $dir ); sort( $xfile ); for ($i=0;$i<$file_count;$i++) { if ( !is_dir( $path.$xfile[$i] ) ) { if ( add_file( $path.$xfile[$i] ) ) { PRINT "$path$xfile[$i]<br>"; } } } for ($i=0;$i<$dir_count;$i++) { if ( $dir[$i]=="." ) continue; if ( $dir[$i]==".." ) continue; index_files( $path.$dir[$i]."/" ); } } ### -------------------- ?> --- NEW FILE: string_api.php --- <?php # phpWebNotes - a php based note addition system # Copyright (C) 2000 Kenzaburo Ito - ke...@30... # 2002 Webnotes Team - web...@so... # This program is distributed under the terms and conditions of the GPL # See the files README and LICENSE for details # -------------------------------------------------------- # $Id: string_api.php,v 1.1 2002/09/03 22:30:07 vboctor Exp $ # -------------------------------------------------------- ### -------------------- function string_safe( $p_string ) { return addslashes( nl2br( $p_string ) ); } ### -------------------- function string_unsafe( $p_string ) { return stripslashes( $p_string ); } ### -------------------- function string_display( $p_string ) { return htmlspecialchars(stripslashes( $p_string )); } ### -------------------- function string_display_with_br( $p_string ) { return str_replace( "<br>", "<br>", htmlspecialchars(stripslashes( $p_string ))); } ### -------------------- function string_edit( $p_string ) { return str_replace( "<br>", "", stripslashes( $p_string ) ); } ### -------------------- # return just the URL portion of the file path function string_get_url( $p_page ) { global $DOCUMENT_ROOT; return substr( $p_page, strlen($DOCUMENT_ROOT), strlen($p_page)); } ### -------------------- function string_preserve_spaces( $p_string ) { $p_string = str_replace( "\t", " ", $p_string ); return str_replace( " ", " ", $p_string ); } ### -------------------- ?> Index: api.php =================================================================== RCS file: /cvsroot/webnotes/webnotes/core/api.php,v retrieving revision 1.8 retrieving revision 1.9 diff -u -d -r1.8 -r1.9 --- api.php 3 Sep 2002 06:59:08 -0000 1.8 +++ api.php 3 Sep 2002 22:30:06 -0000 1.9 @@ -8,8 +8,7 @@ # -------------------------------------------------------- # $Id$ # -------------------------------------------------------- -?> -<? + ########################################################################### ### INCLUDES ### ########################################################################### @@ -27,6 +26,7 @@ # The $g_ext can not be used before the custom config is included. require_once( $t_path_core . 'php_api.php' ); + require_once( $t_path_core . 'constants_inc.php' ); require_once( $t_path_core . 'config_inc.php' ); $t_custom_config = $t_path_core . 'custom_config_inc.php'; @@ -35,177 +35,24 @@ } $t_path_lang = $t_path_main . 'lang' . DIRECTORY_SEPARATOR; - require_once( $t_path_lang . 'strings_' . $g_language . $g_ext ); - - ########################################################################### - ### FUNCTIONS ### - ########################################################################### - - ########################################################################### - # Database : MYSQL for now - ########################################################################### - ### -------------------- - # connect to database - function db_connect($p_hostname="localhost", $p_username="root", - $p_password="", $p_database="webnotes", - $p_port=3306 ) { - - $t_result = mysql_connect( $p_hostname.":".$p_port, - $p_username, $p_password ); - $t_result = mysql_select_db( $p_database ); - - ### Temproary error handling - if ( !$t_result ) { - echo "ERROR: FAILED CONNECTION TO DATABASE"; - exit; - } - } - ### -------------------- - # persistent connect to database - function db_pconnect($p_hostname="localhost", $p_username="root", - $p_password="", $p_database="webnotes", - $p_port=3306 ) { - - $t_result = mysql_pconnect( $p_hostname.":".$p_port, - $p_username, $p_password ); - $t_result = mysql_select_db( $p_database ); - - ### Temproary error handling - if ( !$t_result ) { - echo "ERROR: FAILED CONNECTION TO DATABASE"; - exit; - } + require_once( $t_path_lang . 'strings_english' . $g_ext ); + if( $g_language != 'english') { + require_once( $t_path_lang . 'strings_' . $g_language . $g_ext ); } - ### -------------------- - # execute query, requires connection to be opened, - # goes to error page if error occurs - # Use this when you don't want to handler an error yourself - function db_query( $p_query ) { - $t_result = mysql_query( $p_query ); - if ( !$t_result ) { - echo "ERROR: FAILED QUERY: ".$p_query; - exit; - } - else { - return $t_result; - } - } - ### -------------------- - function db_select_db( $p_db_name ) { - return mysql_select_db( $p_db_name ); - } - ### -------------------- - function db_num_rows( $p_result ) { - return mysql_num_rows( $p_result ); - } - ### -------------------- - function db_fetch_array( $p_result ) { - return mysql_fetch_array( $p_result ); - } - ### -------------------- - function db_result( $p_result, $p_index1=0, $p_index2=0 ) { - if ( $p_result && ( db_num_rows( $p_result ) > 0 ) ) { - return mysql_result( $p_result, $p_index1, $p_index2 ); - } - else { - return false; - } - } - ### -------------------- - function db_close() { - $t_result = mysql_close(); - } - ### -------------------- - ########################################################################### - # Core HTML API - ########################################################################### - ### -------------------- - function print_html_top() { - PRINT "<html>"; - } - ### -------------------- - function print_head_top() { - PRINT "<head>"; - } - ### -------------------- - function print_title( $p_title ) { - PRINT "<title>$p_title</title>"; - } - ### -------------------- - function print_css( $p_css="" ) { - if ( !empty( $p_css ) && file_exists( $p_css ) ) { - include( $p_css ); - } - } - ### -------------------- - function print_meta_redirect( $p_url, $p_time ) { - PRINT "<meta http-equiv=\"Refresh\" content=\"$p_time;URL=$p_url\">"; - } - ### -------------------- - function print_head_bottom() { - PRINT "</head>"; - } - ### -------------------- - function print_body_top() { - PRINT "<body>"; - } - ### -------------------- - function print_header( $p_title="" ) { - PRINT "<h3>$p_title</h3>"; - } - ### -------------------- - function print_top_page( $p_page ) { - if ( !empty( $p_page ) && file_exists( $p_page ) ) { - include( $p_page ); - } - } - ### -------------------- - function print_bottom_page( $p_page ) { - if ( !empty( $p_page ) && file_exists( $p_page ) ) { - include( $p_page ); - } - } - ### -------------------- - function print_footer( $p_file ) { - global $g_string_cookie_val, $g_webmaster_email; + require_once( $t_path_core . 'lang_api.php' ); + require_once( $t_path_core . 'config_api.php' ); + require_once( $t_path_core . 'database_api.php' ); + require_once( $t_path_core . 'note_api.php' ); + require_once( $t_path_core . 'string_api.php' ); + require_once( $t_path_core . 'access_api.php' ); + require_once( $t_path_core . 'page_api.php' ); + require_once( $t_path_core . 'html_api.php' ); - PRINT "<hr size=1 />"; - print_phpWebNotes_version(); - PRINT "<address>Copyright (c) 2000-2002</address>"; - PRINT "<address><a href=\"mailto:$g_webmaster_email\">$g_webmaster_email</a></address>"; - } - ### -------------------- - function print_body_bottom() { - PRINT "</body>"; - } - ### -------------------- - function print_html_bottom() { - PRINT "</html>"; - } - ### -------------------- ########################################################################### - # HTML Appearance Helper API + ### FUNCTIONS ### ########################################################################### - ### -------------------- - ### checks to see whether we need to be displaying the version number - function print_phpWebNotes_version() { - global $g_phpWebNotes_version, $g_show_version; - if ( $g_show_version==1 ) { - PRINT "<em>phpWebNotes - $g_phpWebNotes_version</em>"; - } - } - ### -------------------- - function print_admin_menu() { - global $g_admin_page, $g_logout, - $s_admin_link, $s_logout_link; - - PRINT "<div align=\"center\">"; - PRINT "<a href=\"$g_admin_page\">$s_admin_link</a> | "; - PRINT "<a href=\"$g_logout\">$s_logout_link</a>"; - PRINT "<br />"; - } ########################################################################### # Print API ########################################################################### @@ -249,79 +96,6 @@ PRINT "</div>"; } ### -------------------- - function print_notes( $p_page_name ) { - global $g_hostname, $g_db_username, $g_db_password, $g_database_name, - $g_table_border_color, $g_primary_dark_color, - $g_primary_light_color, $g_white_color, - $g_phpWN_note_table, $g_phpWN_page_table, - $p_note_order; - - $query = "SELECT * - FROM $g_phpWN_page_table p, - $g_phpWN_note_table n - WHERE p.page='$p_page_name' AND n.page_id=p.id AND n.visible='1' - ORDER BY n.date_submitted $p_note_order"; - - $result = db_query( $query ); - $entry_count = db_num_rows( $result ); - if ( $entry_count>0 ) { - for ($i=0;$i<$entry_count;$i++) { - $row = db_fetch_array( $result ); - extract( $row, EXTR_PREFIX_ALL, "v" ); - $v_email = stripslashes( $v_email ); - $v_note = string_preserve_spaces( stripslashes( $v_note ) ); - $date = date( "M, d Y H:i", sql_to_unix_time( $v_date_submitted ) ); - - PRINT "<tr bgcolor=\"$g_primary_dark_color\">"; - PRINT "<td>"; - PRINT " <i><a href=\"mailto:$v_email\">$v_email</a></i> - $v_date_submitted"; - PRINT "</td>"; - PRINT "</tr>"; - PRINT "<tr bgcolor=$g_primary_light_color>"; - PRINT "<td>"; - echo $v_note; - PRINT "</td>"; - PRINT "</tr>"; - PRINT "<tr bgcolor=\"$g_white_color\" height=\"2\">"; - PRINT "<td>"; - PRINT "</td>"; - PRINT "</tr>"; - } - } - } - ### -------------------- - function get_page_id( $p_file ) { - global $g_hostname, $g_db_username, $g_db_password, $g_database_name, - $g_phpWN_page_table; - - $query = "SELECT id - FROM $g_phpWN_page_table - WHERE page='$p_file'"; - $result = db_query( $query ); - if ( db_num_rows( $result) > 0 ) { - return db_result( $result, 0, 0 ); - } - else { - return ""; - } - } - ### -------------------- - function get_page_name( $p_id ) { - global $g_hostname, $g_db_username, $g_db_password, $g_database_name, - $g_phpWN_page_table; - - $query = "SELECT page - FROM $g_phpWN_page_table - WHERE id='$p_id'"; - $result = db_query( $query ); - if ( db_num_rows( $result) > 0 ) { - return db_result( $result, 0, 0 ); - } - else { - return ""; - } - } - ### -------------------- ########################################################################### # Date API ########################################################################### @@ -336,138 +110,9 @@ } ### -------------------- ########################################################################### - # String API - ########################################################################### - ### -------------------- - function string_safe( $p_string ) { - return addslashes( nl2br( $p_string ) ); - } - ### -------------------- - function string_unsafe( $p_string ) { - return stripslashes( $p_string ); - } - ### -------------------- - function string_display( $p_string ) { - return htmlspecialchars(stripslashes( $p_string )); - } - ### -------------------- - function string_display_with_br( $p_string ) { - return str_replace( "<br>", "<br>", htmlspecialchars(stripslashes( $p_string ))); - } - ### -------------------- - function string_edit( $p_string ) { - return str_replace( "<br>", "", stripslashes( $p_string ) ); - } - ### -------------------- - # return just the URL portion of the file path - function string_get_url( $p_page ) { - global $DOCUMENT_ROOT; - - return substr( $p_page, strlen($DOCUMENT_ROOT), strlen($p_page)); - } - ### -------------------- - function string_preserve_spaces( $p_string ) { - $p_string = str_replace( "\t", " ", $p_string ); - return str_replace( " ", " ", $p_string ); - } - ### -------------------- - ########################################################################### - ### Authentication API ### - ########################################################################### - ### -------------------- - function password_match( $p_test_password, $p_password ) { - $salt = substr( $p_password, 0, 2 ); - if ( crypt( $p_test_password, $salt ) == $p_password ) { - return true; - } - else { - return false; - } - } - ### -------------------- - function create_random_password( $p_email ) { - mt_srand( time() ); - $t_val = mt_rand( 0, mt_getrandmax() ) + mt_rand( 0, mt_getrandmax() ); - return substr( crypt( md5( $p_email.$t_val ) ), 0, 12 ); - } - ### -------------------- - function is_moderator() { - global $g_string_cookie_val, $g_phpWN_user_table, - $g_hostname, $g_db_username, $g_db_password, $g_database_name; - - $query = "SELECT COUNT(*) - FROM $g_phpWN_user_table - WHERE cookie_string='$g_string_cookie_val'"; - $result = db_query( $query ); - $count = db_result( $result, 0, 0 ); - - return $count; - } - ### -------------------- - ### checks to see that a user is logged in - ### if the user is and the account is enabled then let them pass - ### otherwise redirect them to the login page - function login_cookie_check( $p_redirect_url="" ) { - global $g_string_cookie_val, - $g_login_page, $g_logout, - $g_hostname, $g_db_username, $g_db_password, $g_database_name, - $g_phpWN_user_table; - - ### @@@@@ DISABLE FOR NOW - return; - - ### if logged in - if ( isset( $g_string_cookie_val ) ) { - if ( empty( $g_string_cookie_val ) ) { - header( "Location: $g_login_page" ); - exit; - } - - ### go to redirect - if ( !empty( $p_redirect_url ) ) { - header( "Location: $p_redirect_url" ); - exit; - } - ### continue with current page - else { - return; - } - } - ### not logged in - else { - header( "Location: $g_login_page" ); - exit; - } - } - ### -------------------- - ########################################################################### ### Function API ### ########################################################################### ### -------------------- - function note_add( $p_page_id, $p_email, $p_REMOTE_ADDR, $p_note ) { - global $g_phpWN_note_table; - - $p_email = addslashes( htmlspecialchars( $p_email ) ); - $p_note = addslashes( nl2br( htmlspecialchars( $p_note ) ) ); - $query = "INSERT - INTO $g_phpWN_note_table - ( id, page_id, email, ip, date_submitted, note ) - VALUES - ( null, '$p_page_id', '$p_email', '$p_REMOTE_ADDR', NOW(), '$p_note' )"; - return db_query( $query ); - - } - ### -------------------- - function queue_count() { - global $g_phpWN_note_table; - - $query = "SELECT COUNT(*) - FROM $g_phpWN_note_table - WHERE visible='0'"; - $result = db_query( $query ); - return db_result( $result, 0, 0 ); - } - ### -------------------- function get_user_info_arr( $p_string_cookie_val ) { global $g_phpWN_user_table; @@ -560,42 +205,6 @@ } } ### -------------------- - function delete_note( $p_id ) { - global $g_phpWN_note_table; - - $query = "DELETE FROM $g_phpWN_note_table - WHERE id='$p_id'"; - $result = db_query( $query ); - } - ### -------------------- - function update_note( $p_id, $p_email, $p_note ) { - global $g_phpWN_note_table; - - $p_email = addslashes( htmlspecialchars( $p_email ) ); - $p_note = addslashes( nl2br( htmlspecialchars( $p_note ) ) ); - $query = "UPDATE $g_phpWN_note_table - SET email='$p_email', note='$p_note' - WHERE id='$p_id'"; - $result = db_query( $query ); - } - ### -------------------- - function accept_note( $p_id ) { - global $g_phpWN_note_table; - - $query = "UPDATE $g_phpWN_note_table - SET visible='1' - WHERE id='$p_id'"; - $result = db_query( $query ); - } - ### -------------------- - function decline_note( $p_id ) { - global $g_phpWN_note_table; - - $query = "DELETE FROM $g_phpWN_note_table - WHERE id='$p_id'"; - $result = db_query( $query ); - } - ### -------------------- function select_queued_notes_arr() { global $g_phpWN_note_table, $g_phpWN_page_table; @@ -606,90 +215,6 @@ $result = db_query( $query ); return db_fetch_array( $result ); } - ### -------------------- - ### Allows for path navigation to choose base dir - function print_dirs( $p_path ) { - global $g_admin_index_files; - - $handle = opendir( $p_path ); - while ( $file = readdir( $handle ) ) { - if ( is_dir( $p_path."/".$file )&&( $file!="." ) ) { - if ($file=="..") { - $t_path = dirname( $p_path ); - PRINT "<a href=\"$g_admin_index_files?f_dir=$t_path\">$file</a><br />"; - } else { - PRINT "<a href=\"$g_admin_index_files?f_dir=$p_path/$file\">$file</a><br />"; - } - } - } - } - ### -------------------- - function add_file( $p_page_name ) { - global $g_phpWN_page_table; - - $query = "SELECT COUNT(*) - FROM $g_phpWN_page_table - WHERE page='$p_page_name'"; - $result = db_query( $query ); - $count = db_result( $result, 0, 0 ); - if ( $count == 1 ) { - return 0; - } - - $query = "INSERT INTO - $g_phpWN_page_table - ( id, date_indexed, page ) - VALUES - (null, NOW(), '$p_page_name' )"; - $result = db_query( $query ); - return $result; - } - ### -------------------- - function index_files( $path="" ) { - $dir_count = 0; - $file_count = 0; - - $dir = array(); - $xfile = array(); - - $handle = opendir( $path ); - while ( $file = readdir( $handle ) ) { - if ($file==".") {continue;} - if ($file=="..") {continue;} - if ( is_dir( $path.$file ) ) { - $dir[$dir_count] = $file; - $dir_count++; - } else { - $xfile[$file_count] = $file; - $file_count++; - - } - } - closedir( $handle ); - sort( $dir ); - sort( $xfile ); - - for ($i=0;$i<$file_count;$i++) { - if ( !is_dir( $path.$xfile[$i] ) ) { - if ( add_file( $path.$xfile[$i] ) ) { - PRINT "$path$xfile[$i]<br>"; - } - } - } - - for ($i=0;$i<$dir_count;$i++) { - if ( $dir[$i]=="." ) continue; - if ( $dir[$i]==".." ) continue; - index_files( $path.$dir[$i]."/" ); - } - } - ### -------------------- - - ########################################################################### - ### CODE TO EXECUTE ### - ########################################################################### - - db_connect( $g_hostname, $g_db_username, $g_db_password, $g_database_name ); ########################################################################### ### END ### Index: config_inc.php =================================================================== RCS file: /cvsroot/webnotes/webnotes/core/config_inc.php,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- config_inc.php 3 Sep 2002 00:40:50 -0000 1.2 +++ config_inc.php 3 Sep 2002 22:30:07 -0000 1.3 @@ -8,8 +8,7 @@ # -------------------------------------------------------- # $Id$ # -------------------------------------------------------- -?> -<? + ########################### # CONFIGURATION SETTINGS ########################### @@ -47,7 +46,7 @@ $g_cookie_time_length = 30000000; # 1 year ### Display phpWebNotes version on pages - $g_show_version = 1; + $g_show_version = ON; $g_window_title = 'phpWebNotes'; $g_page_title = 'phpWebNotes'; Index: php_api.php =================================================================== RCS file: /cvsroot/webnotes/webnotes/core/php_api.php,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- php_api.php 3 Sep 2002 00:40:50 -0000 1.2 +++ php_api.php 3 Sep 2002 22:30:07 -0000 1.3 @@ -1,6 +1,7 @@ <?php # phpWebNotes - a php based note addition system # Copyright (C) 2000 Kenzaburo Ito - ke...@30... + # 2002 Mantis Team - man...@so... # 2002 Webnotes Team - web...@so... # This program is distributed under the terms and conditions of the GPL # See the files README and LICENSE for details |