#!c:\euphoria\bin\eui.exe -- #!/home/euphoria/bin/exu without warning -- warnings mess up CGI output without type_check -- with profile -- profile(0) include hirestime.e -- not including this should generate warnings when using HRT_ procedures include std/text.e include std/datetime.e include registration.e include messaging.e as messaging include cgi.e -- for change history, see SVN Revision History register_code("index.esp",{2009,9,2,0,0}) -- included for a general timing of block processing and page processing HRT_start("index.esp") -------------------------------------------------- -----------------------BBCMF SYSTEM FILES--------- /* initialize the database system from an ini file can't store information about the database system in the database as there's no way to get it out at the start! */ add_routine("index.esp") include db_api.e include system_mods.e -- get the database and email functionality modules HRT_start("blocks modules") include blocks_modules.e -- for including custom block types (block_type callbacks()) include blocks_manager.e include blocks_process.e HRT_stop("blocks modules") HRT_start("other modules") include actions.e include session_map.e -- handle sessions include dbmanager.e -- manipulate databases include plugins.e include ajax.e -- allow Ajax functionality include metatags.e -- metatag management include styles.e include bbcmf_site.e include query_db.e include otc.e include content.e include cookies.e include logging.e include scripting.e HRT_stop("other modules") cgiparse() -- prepare all CGI variables (from cgi.e) process_cookies() -- from cookies.e process_session() -- from session.e -------------------------------------------------- -----------------------BBCMF USER ADD-ONS--------- include custom_code.e -- include user made modules procedure main() sequence theHead , HtmlType , ContentType , DocType , theBody , vcontent , action , redirect , ptname , ajax , externalScripts , inlineScripts , internalCSS , target , otc atom bid object SITE_ACTIVE , pt HRT_start("main") add_routine("main") theBody = "" theHead = "" redirect = "" ContentType = "Content-type: " & site_var("content_type",1) & "; charset=" & site_var("charset",1) & "\n\n" DocType = site_var("doctype",1) & "\n\n" HtmlType = site_var("html_type",1) if length(HtmlType) = 0 then HtmlType = "" end if -- we assume that if a fatal error has been posted, it is because the database could not be accessed -- for the site_var() calls above. Therefore, display an error message. This should allow use of an -- "Error Page" template file if messaging:fatal_error() then puts(1,"Content-type: text/html; charset=utf-8\n\n") puts(1,"") puts(1, HtmlType & "\n
" & "For some reason, the database could not be accessed. Please wait a few minutes and try again.
" -- & geterr(,1) & "" & "\n" ) else pt = get_key_value("page") -- requested page (rethink. is this necessary? can't page be derived from requested block?) vcontent = get_key_value("content") -- requested content block action = get_key_value("action") -- to determine action to take, if any ajax = get_key_value("ajax") -- is this an ajax call? otc = get_key_value("otc") -- is this a One Time Code? if length(otc) > 0 then process_otc( otc ) end if if sequence(pt) and length(pt) = 0 then -- if no page is specified, use default pt = site_var("primary_page") end if if atom(pt) then pt = sprint(pt) end if -- site can get set to inactive by admin, so... SITE_ACTIVE = find(site_var("site_active"),{1,"1"}) SITE_ACTIVE = SITE_ACTIVE or is_admin() -- site is always active for admin or equal(vcontent,"login_form") -- allows admin to get log in screen or (equal(action,"login")) -- allows admin to log in or (equal(action,"logout")) -- allows admin to log out if SITE_ACTIVE and equal(ajax,"true") then do_ajax() else if SITE_ACTIVE then if length(action) > 0 then -- process any actions first process_action( action ) end if -- if the action reset the content... if length(vcontent) = 0 then vcontent = get_content() end if if match("redirect:",vcontent) then vcontent = vcontent[10..$] if length(vcontent) = 0 then vcontent = block_page_primary_block_name( pt ) end if target = get_target() if length(target) > 0 then target = "#" & target end if redirect = "" vcontent = "please_wait" end if if length(vcontent) = 0 then -- the action could have set_content() if length(get_content()) = 0 then -- this is where invalid block_page ids are caught... so do we need valid_page() below?! if logged_in() then vcontent = site_var("logged_in_home") else vcontent = block_page_primary_block_name( pt ) end if if length(vcontent) = 0 then pt = sprint( site_var("primary_page") ) vcontent = block_page_primary_block_name( pt ) end if else vcontent = get_content() end if end if else pt = site_var("primary_page") vcontent = site_var("maintenance_message_block") end if if not block_exists( vcontent ) then logfile_ts("(" & REMOTE_ADDR & ")\t'" & vcontent & "' requested but does not exist.","content_request_errors.log") err("Content '" & vcontent & "' does not exist. A report has been submitted to the webmaster.",0) if logged_in() then vcontent = site_var("logged_in_home") else vcontent = site_var("logged_out_home") end if end if set_content( vcontent ) if loginRequired( vcontent ) and not logged_in() then if SITE_ACTIVE then vcontent = site_var("logged_out_home") if length(vcontent) = 0 then err("Site Variable 'logged_out_home' not set!") end if set_content( vcontent ) else set_content( site_var("maintenance_message_block") ) end if end if load_theme_styles() -- loads theme styles setPageTemplate(pt) ptname = getPageTemplateName() bid = get_block_id( upper( get_content() ) ) HRT_start("blocks") theBody = process_blocks(pt,bid) -- '0' is optional and default HRT_stop("blocks") -- THIS IS WHERE YOU SET THE COOKIES!!! -- prior functions/procedures should have been using -- add_cookie("item","data",[expire date string]) to add their own cookies set_cookies() --show_cookies() externalScripts = get_ext_scripts() inlineScripts = get_inline_scripts() internalCSS = get_internal_styles() theHead = "\n