Update of /cvsroot/mantisbt/mantisbt/core In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv19009/core Modified Files: Tag: EXP_TEMPLATE access_api.php bug_api.php custom_field_api.php html_api.php Added Files: Tag: EXP_TEMPLATE class.smartyML.php class.smartySkin.php template_api.php Log Message: initial checkin of Smarty based templates --- NEW FILE: template_api.php --- <?php # Mantis - a php based bugtracking system # Copyright (C) 2000 - 2002 Kenzaburo Ito - ke...@30... # Copyright (C) 2002 - 2006 Mantis Team - man...@li... # This program is distributed under the terms and conditions of the GPL # See the README and LICENSE files for details # -------------------------------------------------------- # $Id: template_api.php,v 1.1.2.1 2006/04/30 19:00:46 thraxisp Exp $ # -------------------------------------------------------- $t_path = config_get('core_path'); define('SMARTY_DIR', $t_path . 'smarty/'); require_once(SMARTY_DIR."Smarty.class.php"); require_once($t_path . "class.smartySkin.php"); require_once($t_path . "class.smartyML.php"); function template_init( $p_template_name ) { $t_lang = 'en'; // lang_get_current? $d_page = new smartyML( $p_template_name, $t_lang ); // set template search path $t_path = config_get('absolute_path'); $t_theme = config_get('theme', '' ); $d_page->compile_dir = $t_path . "themes_c/"; $d_page->register_skin( 'classic', $t_path . "themes/classic" ); if ( $t_theme != '' ) { $d_page->register_skin( $t_theme, $t_path . "themes/" . $t_theme ); } $t_css_file = $d_page->getFilePath( "default.css" ); if ( "" != $t_css_file ) { $d_page->assign( 'css_url', preg_replace( "?" . $t_path . "?", "", $t_css_file ) ); } else { $d_page->assign( 'css_url', config_get( 'css_include_file' ) ); } // remove later $d_page->debugging = 1; $d_page->debug_tpl = $t_path . "themes/classic/debug.tpl"; // config based assigns $d_page->assign( 'display', template_get_display() ); $d_page->assign( 'login', html_get_login_info() ); return $d_page; } function template_show_fields( $p_project=ALL_PROJECTS, $p_user=ALL_USERS) { $t_show = array(); $t_all_fields = array( 'id', 'project_id', 'reporter_id', 'handler_id', 'priority', 'severity', 'reproducibility', 'status', 'resolution', 'projection', 'category', 'date_submitted', 'last_updated', 'eta', 'os', 'os_build', 'os_version', 'platform', 'version', 'fixed_in_version', 'build', 'profile_id', 'view_state', 'summary', 'sponsorship_total', 'sticky', 'description', 'steps_to_reproduce', 'additional_information', 'bugnote', 'history', 'buglist', 'bug_reminder', 'handler', 'attachments' ); $t_hide = config_get('hide_fields', ''); $t_hide_array = explode(',', $t_hide); $t_show_fields = array(); foreach( $t_all_fields as $t_field ) { if( in_array( $t_field, $t_hide_array ) ) { $t_show_fields[$t_field] = false; } else { $t_show_fields[$t_field] = true; } } if ( $t_show_fields['version'] ) { // override product version $t_show_fields['version'] = ( ON == config_get( 'show_product_version' ) ) || ( ( AUTO == config_get( 'show_product_version' ) ) && ( count( version_get_all_rows( $p_project ) ) > 0 ) ); } $t_show_fields['relationship'] = ( ON == config_get('enable_relationship') ); return $t_show_fields; } function template_get_display() { global $g_allow_browser_cache; $t_display = array ( 'row_style' => array( 'row-1', 'row-2') ); // config based display parameters $t_display['browser_cache'] = $g_allow_browser_cache; $t_display['rss_feed_url'] = config_get( 'rss_feed_url', '' ); if ( ON == config_get( 'use_javascript' ) ) { $t_display['javascript_files'] = array( "javascript/common.js" ); $t_display['javascripts'] = array( ); } $t_display['page_title'] = string_display( config_get( 'page_title', '' ) ); $t_display['page_top'] = config_get( 'top_include_page' ); if ( is_page_name( 'login_page' ) ) { $t_display['top_align'] = 'center'; } else { $t_display['top_align'] = 'left'; } if ( ON == config_get( 'show_version' ) ) { $t_display['version'] = config_get( 'mantis_version' ); } else { $t_display['version'] = ''; } if ( ! is_page_name( 'login_page.php' ) && !current_user_is_anonymous() ) { $t_display['webmaster'] = config_get( 'webmaster_email' ); } else { $t_display['webmaster'] = ''; } $t_display['rss_url'] = rss_get_issues_feed_url(); return $t_display; } ?> Index: access_api.php =================================================================== RCS file: /cvsroot/mantisbt/mantisbt/core/access_api.php,v retrieving revision 1.43 retrieving revision 1.43.16.1 diff -u -d -r1.43 -r1.43.16.1 --- access_api.php 12 May 2005 16:04:09 -0000 1.43 +++ access_api.php 30 Apr 2006 19:00:45 -0000 1.43.16.1 @@ -459,4 +459,28 @@ return config_get( 'update_bug_status_threshold' ); } } + + # -------------------- + # update the field array passed in with inaccessible fields by project + function access_hide_bug_fields( $p_field_list, $p_bug_id ) { + foreach( $p_field_list as $t_field=>$t_show ) { + if ( $t_show ) { + switch ( $t_field ) { + case 'history': + case 'handler': + if ( !access_has_bug_level( config_get( 'view_' . $t_field . '_threshold' ), $p_bug_id ) ) { + $p_field_list[$t_field] = false; + } + break; + case 'attachments': + if ( !( bug_get_field( $p_bug_id, 'reporter_id' ) == auth_get_current_user_id() ) && + !access_has_bug_level( config_get( 'view_attachments_threshold' ), $p_bug_id ) ) { + $p_field_list[$t_field] = false; + } + + } + } + } + } + ?> Index: custom_field_api.php =================================================================== RCS file: /cvsroot/mantisbt/mantisbt/core/custom_field_api.php,v retrieving revision 1.58 retrieving revision 1.58.2.1 diff -u -d -r1.58 -r1.58.2.1 --- custom_field_api.php 19 Apr 2006 00:45:46 -0000 1.58 +++ custom_field_api.php 30 Apr 2006 19:00:46 -0000 1.58.2.1 @@ -863,6 +863,23 @@ # -------------------- # Gets the sequence number for the specified custom field for the specified # project. Returns false in case of error. + function custom_field_get_bug_values( $p_bug_id, $p_project_id ) { + $t_custom_fields_values = array(); + $t_related_custom_field_ids = custom_field_get_linked_ids( $p_project_id ); + foreach( $t_related_custom_field_ids as $t_id ) { + if ( !custom_field_has_read_access( $t_id, $p_bug_id ) ) { + continue; + } # has read access + + $t_def = custom_field_get_definition( $t_id ); + $t_custom_fields_values[$t_def['name']] = string_custom_field_value( $t_def, $t_id, $p_bug_id ); + } # foreach + return $t_custom_fields_values; + } + + # -------------------- + # Gets the sequence number for the specified custom field for the specified + # project. Returns false in case of error. function custom_field_get_sequence( $p_field_id, $p_project_id ) { $c_field_id = db_prepare_int( $p_field_id ); $c_project_id = db_prepare_int( $p_project_id ); --- NEW FILE: class.smartyML.php --- (This appears to be a binary file; contents omitted.) --- NEW FILE: class.smartySkin.php --- <?php /* original file posted at http://www.sjhannah.com/blog/?p=22 by Steve Hannah modified for inclusion in Mantis by Glenn Henshaw */ class SkinTool extends Smarty { /** * Array of registered skins.. */ var $skins = array(); /** * Overrides smarty method. This will place compiled version of the template * in a subfolder of the compile_dir named after the skin where the template * resides. If this subfolder does not exist, it is created. * * @param string $resource_name * @return string results of {@link _get_auto_filename()} */ function _get_compile_path($resource_name) { $params = array('resource_name'=>$resource_name, 'resource_base_path' => $this->template_dir); $name = $this->_parse_resource_name($params); $template_dir = dirname($params['resource_name']); $skin = $this->skins[$template_dir]; if ( strlen($skin) > 0 and preg_match('/^[0-9a-zA-Z_]+$/', $skin) ){ $compile_dir = $this->compile_dir.'/'.$skin; if ( !file_exists($compile_dir) ){ mkdir($compile_dir); } if ( !file_exists($compile_dir) ){ trigger_error("Failed to create compile directory '$compile_dir'", E_USER_ERROR); } } else { $compile_dir = $this->compile_dir; } return $this->_get_auto_filename($compile_dir, $resource_name, $this->_compile_id) . '.php'; } /** * Registers a skin to be used as the default skin. This skin is added to * the top of the stack so it has the highest priority. If a template is * requested and this skin does not contain that template, then the SkinTool * will check the next skin in the stack. And so on... * * @param $name The name of the skin * @param $template_dir The directory to the templates for this skin. */ function register_skin( $name, $template_dir){ if ( !is_array($this->template_dir) ){ if ( strlen($this->template_dir) > 0 ){ $this->template_dir = array($this->template_dir); } else { $this->template_dir = array(); } } array_unshift($this->template_dir, $template_dir); $this->skins[$template_dir] = $name; } } ?> Index: html_api.php =================================================================== RCS file: /cvsroot/mantisbt/mantisbt/core/html_api.php,v retrieving revision 1.191 retrieving revision 1.191.2.1 diff -u -d -r1.191 -r1.191.2.1 --- html_api.php 23 Apr 2006 12:32:59 -0000 1.191 +++ html_api.php 30 Apr 2006 19:00:46 -0000 1.191.2.1 @@ -68,8 +68,10 @@ # null: means no feed (default). function html_set_rss_link( $p_rss_feed_url ) { - global $g_rss_feed_url; - $g_rss_feed_url = $p_rss_feed_url; + if ( OFF != config_get( 'rss_enabled' ) ) { + global $g_rss_feed_url; + $g_rss_feed_url = $p_rss_feed_url; + } } # -------------------- @@ -193,20 +195,24 @@ } # -------------------- - # (4) Print the window title - function html_title( $p_page_title = null ) { + # (4) get the window title + function html_get_title( $p_page_title = null ) { $t_title = config_get( 'window_title' ); - echo "\t", '<title>'; if ( 0 == strlen( $p_page_title ) ) { - echo string_display( $t_title ); + return string_display( $t_title ); } else { if ( 0 == strlen( $t_title ) ) { - echo $p_page_title; + return $p_page_title; } else { - echo $p_page_title . ' - ' . string_display( $t_title ); + return $p_page_title . ' - ' . string_display( $t_title ); } } - echo '</title>', "\n"; + } + + # -------------------- + # (4) Print the window title + function html_title( $p_page_title = null ) { + echo "\t", '<title>' . html_get_title( $p_page_title ) . '</title>', "\n"; } # -------------------- @@ -290,6 +296,26 @@ echo '</div>'; } } + # -------------------- + # (11) Print the user's account information + # Also print the select box where users can switch projects + function html_get_login_info() { + $t_login['username'] = current_user_get_field( 'username' ); + $t_login['access_level'] = get_enum_element( 'access_levels', current_user_get_access_level() ); + $t_login['realname'] = current_user_get_field( 'realname' ); + $t_login['anonymous'] = current_user_is_anonymous(); + if ( !php_version_at_least( '4.1.0' ) ) { + global $_SERVER; + } + $t_return_page = $_SERVER['PHP_SELF']; + if ( isset( $_SERVER['QUERY_STRING'] ) ) { + $t_return_page .= '?' . $_SERVER['QUERY_STRING']; + } + $t_login['return_page'] = string_url( $t_return_page ); + $t_login['signup'] = config_get( 'allow_signup' ); + return $t_login; + } + # -------------------- # (11) Print the user's account information @@ -344,10 +370,13 @@ } PRINT '<input type="submit" class="button-small" value="' . lang_get( 'switch' ) . '" />'; - # Link to RSS issues feed for the selected project, including authentication details. - PRINT '<a href="' . rss_get_issues_feed_url() . '">'; - PRINT '<img src="images/rss.gif" alt="' . lang_get( 'rss' ) . '" style="border-style: none; margin: 5px; vertical-align: middle;" />'; - PRINT '</a>'; + if ( OFF != config_get( 'rss_enabled' ) ) { + # Link to RSS issues feed for the selected project, including authentication details. + PRINT '<a href="' . rss_get_issues_feed_url() . '">'; + PRINT '<img src="images/rss.gif" alt="' . lang_get( 'rss' ) . '" style="border-style: none; margin: 5px; vertical-align: middle;" />'; + PRINT '</a>'; + } + PRINT '</form>'; PRINT '</td>'; PRINT '</tr>'; @@ -471,99 +500,114 @@ return $t_options; } + #--------------------- + # get the content of the form to jump to a bug + function print_get_jump_bug_form() { + $t_form = '<form method="post" action="jump_to_bug.php">'; + + if ( ON == config_get( 'use_javascript' ) ) { + $t_bug_label = lang_get( 'issue_id' ); + $t_form .= "<input type=\"text\" name=\"bug_id\" size=\"10\" class=\"small\" value=\"$t_bug_label\" onfocus=\"if (this.value == '$t_bug_label') this.value = ''\" onblur=\"if (this.value == '') this.value = '$t_bug_label'\" /> "; + } else { + $t_form .= "<input type=\"text\" name=\"bug_id\" size=\"10\" class=\"small\" /> "; + } + + $t_form .= '<input type="submit" class="button-small" value="' . lang_get( 'jump' ) . '" /> '; + $t_form .= '</form>'; + return $t_form; + } + # -------------------- - # Print the main menu - function print_menu() { + # gets the links for the main menu + function print_get_main_menu() { + $t_menu_options = array(); if ( auth_is_user_authenticated() ) { $t_protected = current_user_get_field( 'protected' ); - PRINT '<table class="width100" cellspacing="0">'; - PRINT '<tr>'; - PRINT '<td class="menu">'; - $t_menu_options = array(); - # Main Page - $t_menu_options[] = '<a href="main_page.php">' . lang_get( 'main_link' ) . '</a>'; + # Main Page + $t_menu_options['main_link'] = "main_page.php"; - # My View - $t_menu_options[] = '<a href="my_view_page.php">' . lang_get( 'my_view_link' ) . '</a>'; + # My View + $t_menu_options['my_view_link'] = "my_view_page.php"; - # View Bugs - $t_menu_options[] = '<a href="view_all_bug_page.php">' . lang_get( 'view_bugs_link' ) . '</a>'; + # View Bugs + $t_menu_options['view_bugs_link'] = "view_all_bug_page.php"; - # Report Bugs - if ( access_has_project_level( config_get( 'report_bug_threshold' ) ) ) { - $t_menu_options[] = string_get_bug_report_link(); - } + # Report Bugs + if ( access_has_project_level( config_get( 'report_bug_threshold' ) ) ) { + $t_menu_options['report_bug_link'] = string_get_bug_report_url(); + } - # Changelog Page - if ( access_has_project_level( config_get( 'view_changelog_threshold' ) ) ) { - $t_menu_options[] = '<a href="changelog_page.php">' . lang_get( 'changelog_link' ) . '</a>'; - } + # Changelog Page + if ( access_has_project_level( config_get( 'view_changelog_threshold' ) ) ) { + $t_menu_options['changelog_link'] = "changelog_page.php"; + } - # Summary Page - if ( access_has_project_level( config_get( 'view_summary_threshold' ) ) ) { - $t_menu_options[] = '<a href="summary_page.php">' . lang_get( 'summary_link' ) . '</a>'; - } + # Summary Page + if ( access_has_project_level( config_get( 'view_summary_threshold' ) ) ) { + $t_menu_options['summary_link'] = "summary_page.php"; + } - # Project Documentation Page - if( ON == config_get( 'enable_project_documentation' ) ) { - $t_menu_options[] = '<a href="proj_doc_page.php">' . lang_get( 'docs_link' ) . '</a>'; - } + # Project Documentation Page + if( ON == config_get( 'enable_project_documentation' ) ) { + $t_menu_options['docs_link'] = "proj_doc_page.php"; + } - # Manage Users (admins) or Manage Project (managers) or Manage Custom Fields - $t_show_access = min( config_get( 'manage_project_threshold' ), config_get( 'manage_custom_fields_threshold' ), ADMINISTRATOR ); - if ( access_has_global_level( $t_show_access) || access_has_any_project( $t_show_access ) ) { - $t_current_project = helper_get_current_project(); - if ( access_has_project_level( ADMINISTRATOR, $t_current_project ) ) { - $t_link = 'manage_user_page.php'; + # Manage Users (admins) or Manage Project (managers) or Manage Custom Fields + $t_show_access = min( config_get( 'manage_project_threshold' ), config_get( 'manage_custom_fields_threshold' ), ADMINISTRATOR ); + if ( access_has_global_level( $t_show_access) || access_has_any_project( $t_show_access ) ) { + $t_current_project = helper_get_current_project(); + if ( access_has_project_level( ADMINISTRATOR, $t_current_project ) ) { + $t_link = 'manage_user_page.php'; + } else { + if ( access_has_project_level( config_get( 'manage_project_threshold' ), $t_current_project ) + && ( $t_current_project <> ALL_PROJECTS ) ) { + $t_link = 'manage_proj_edit_page.php?project_id=' . $t_current_project; } else { - if ( access_has_project_level( config_get( 'manage_project_threshold' ), $t_current_project ) - && ( $t_current_project <> ALL_PROJECTS ) ) { - $t_link = 'manage_proj_edit_page.php?project_id=' . $t_current_project; - } else { - $t_link = 'manage_proj_page.php'; - } + $t_link = 'manage_proj_page.php'; } - $t_menu_options[] = "<a href=\"$t_link\">" . lang_get( 'manage_link' ) . '</a>'; } + $t_menu_options['manage_link'] = $t_link; + } - # News Page - if ( access_has_project_level( config_get( 'manage_news_threshold' ) ) ) { - # Admin can edit news for All Projects (site-wide) - if ( ( ALL_PROJECTS != helper_get_current_project() ) || ( access_has_project_level( ADMINISTRATOR ) ) ) { - $t_menu_options[] = '<a href="news_menu_page.php">' . lang_get( 'edit_news_link' ) . '</a>'; - } else { - $t_menu_options[] = '<a href="login_select_proj_page.php">' . lang_get( 'edit_news_link' ) . '</a>'; - } + # News Page + if ( access_has_project_level( config_get( 'manage_news_threshold' ) ) ) { + # Admin can edit news for All Projects (site-wide) + if ( ( ALL_PROJECTS != helper_get_current_project() ) || ( access_has_project_level( ADMINISTRATOR ) ) ) { + $t_menu_options['edit_news_link'] = "news_menu_page.php"; + } else { + $t_menu_options['edit_news_link'] = "login_select_proj_page.php"; } + } - # Account Page (only show accounts that are NOT protected) - if ( OFF == $t_protected ) { - $t_menu_options[] = '<a href="account_page.php">' . lang_get( 'account_link' ) . '</a>'; - } + # Account Page (only show accounts that are NOT protected) + if ( OFF == $t_protected ) { + $t_menu_options['account_link'] = "account_page.php"; + } - # Add custom options - $t_custom_options = prepare_custom_menu_options( 'main_menu_custom_options' ); - $t_menu_options = array_merge( $t_menu_options, $t_custom_options ); + # Add custom options + $t_custom_options = prepare_custom_menu_options( 'main_menu_custom_options' ); + $t_menu_options = array_merge( $t_menu_options, $t_custom_options ); - # Logout (no if anonymously logged in) - if ( !current_user_is_anonymous() ) { - $t_menu_options[] = '<a href="logout_page.php">' . lang_get( 'logout_link' ) . '</a>'; - } - PRINT implode( $t_menu_options, ' | ' ); + # Logout (no if anonymously logged in) + if ( !current_user_is_anonymous() ) { + $t_menu_options['logout_link'] = "logout_page.php"; + } + } + return $t_menu_options; + } + + # -------------------- + # Print the main menu + function print_menu() { + if ( auth_is_user_authenticated() ) { + PRINT '<table class="width100" cellspacing="0">'; + PRINT '<tr>'; + PRINT '<td class="menu">'; + PRINT implode( print_get_main_menu(), ' | ' ); PRINT '</td>'; PRINT '<td class="right" style="white-space: nowrap;">'; - PRINT '<form method="post" action="jump_to_bug.php">'; - - if ( ON == config_get( 'use_javascript' ) ) { - $t_bug_label = lang_get( 'issue_id' ); - PRINT "<input type=\"text\" name=\"bug_id\" size=\"10\" class=\"small\" value=\"$t_bug_label\" onfocus=\"if (this.value == '$t_bug_label') this.value = ''\" onblur=\"if (this.value == '') this.value = '$t_bug_label'\" /> "; - } else { - PRINT "<input type=\"text\" name=\"bug_id\" size=\"10\" class=\"small\" /> "; - } - - PRINT '<input type="submit" class="button-small" value="' . lang_get( 'jump' ) . '" /> '; - PRINT '</form>'; + PRINT print_get_jump_bug_form(); PRINT '</td>'; PRINT '</tr>'; PRINT '</table>'; Index: bug_api.php =================================================================== RCS file: /cvsroot/mantisbt/mantisbt/core/bug_api.php,v retrieving revision 1.100 retrieving revision 1.100.2.1 diff -u -d -r1.100 -r1.100.2.1 --- bug_api.php 18 Apr 2006 00:43:03 -0000 1.100 +++ bug_api.php 30 Apr 2006 19:00:45 -0000 1.100.2.1 @@ -28,6 +28,7 @@ # Bug Data Structure Definition #=================================== class BugData { + var $id = 0; var $project_id = null; var $reporter_id = 0; var $handler_id = 0; @@ -52,6 +53,7 @@ var $summary = ''; var $sponsorship_total = 0; var $sticky = 0; + var $c_fields = array(); // accessible custom fields # omitted: # var $bug_text_id @@ -64,6 +66,56 @@ #internal helper objects var $_stats = null; + + // return a string to display a bug field + function display( $p_field ) { + switch ( $p_field ) { + case 'id': + return bug_format_id( $this->id ); + break; + case 'category': + $t_project_name = string_display( project_get_field( $this->project_id, 'name' ) ); + return "[$t_project_name] $this->category"; + break; + case 'severity': + case 'reproducibility': + case 'view_state': + case 'priority': + case 'resolution': + case 'status': + case 'eta': + case 'projection': + return get_enum_element( $p_field, $this->$p_field ); + break; + case 'date_submitted': + case 'last_updated'; + return print_date( config_get( 'normal_date_format' ), $this->$p_field ); + break; + case 'platform': + case 'os': + case 'os_build': + case 'build': + return $this->$p_field; + break; + case 'summary': + case 'description': + case 'steps_to_reproduce': + case 'additional_information': + return string_display( $this->$p_field ); + break; + case 'status_color': + return get_status_color( $this->status ); + break; + case 'reporter_id': + case 'handler_id': + return print_user_with_subject( $this->$p_field, $this->id ); + break; + default: + return 'unknown field ' . $p_field; + break; + } + + } } #=================================== @@ -910,6 +962,7 @@ $t_bug_data->$var = $row[$var]; } } + $t_bug_data->c_fields = custom_field_get_bug_values( $p_bug_id, $t_bug_data->project_id ); return $t_bug_data; } |