From 70a22b9ae937a41902a9b609450df7727da5e2c6 Mon Sep 17 00:00:00 2001 From: Robert Sesek Date: Sun, 10 Jul 2005 02:56:57 +0000 Subject: [PATCH] r282: - created includes/class_xml_language.php which will handle language impex - languages now use XML for import/export; master language already works --- docs/lang_file_import.php | 29 ++-- docs/lang_file_master.php | 183 ------------------------- docs/lang_file_master.xml | 166 +++++++++++++++++++++++ docs/phrasetools.php | 17 +-- includes/class_xml_language.php | 230 ++++++++++++++++++++++++++++++++ 5 files changed, 410 insertions(+), 215 deletions(-) delete mode 100755 docs/lang_file_master.php create mode 100755 docs/lang_file_master.xml create mode 100644 includes/class_xml_language.php diff --git a/docs/lang_file_import.php b/docs/lang_file_import.php index 94708fd..beda6c1 100644 --- a/docs/lang_file_import.php +++ b/docs/lang_file_import.php @@ -1,6 +1,6 @@ query("TRUNCATE TABLE " . TABLE_PREFIX . "phrase"); + require_once('./includes/class_xml_language.php'); + $lang = new XML_Language(); - $sql = " - INSERT INTO " . TABLE_PREFIX . "phrase - (varname, phrasetext, imported) - VALUES"; + $lang->path = './docs/lang_file_master.xml'; + $lang->load(); + $lang->parse(); + $query = $lang->build(); - - require('./docs/lang_file_master.php'); - - foreach ($language AS $varname => $phrase) + if ($query) { - $sqlbits[] = " - ('" . $bugsys->escape($varname) . "', '" . $bugsys->escape($phrase) . "', " . time() . ")"; + $db->query("TRUNCATE TABLE " . TABLE_PREFIX . "phrase"); + $db->query($query); + echo 'language file imported...'; } - - $sql .= implode(',', $sqlbits); - - echo "
$sql
"; - - $db->query($sql); } ?> \ No newline at end of file diff --git a/docs/lang_file_master.php b/docs/lang_file_master.php deleted file mode 100755 index 1ff20df..0000000 --- a/docs/lang_file_master.php +++ /dev/null @@ -1,183 +0,0 @@ - 'Action', - 'additional_bug_fields' => 'Additional Bug Fields', - 'add_component' => 'Add Component', - 'add_new_field' => 'Add New Bug Field', - 'add_new_priority' => 'Add New Priority', - 'add_new_product' => 'Add New Product', - 'add_new_resolution' => 'Add New Resolution', - 'add_new_severity' => 'Add New Severity', - 'add_new_status' => 'Add New Status', - 'add_new_usergroup' => 'Add New Usergroup', - 'add_new_version' => 'Add New Version', - 'add_product' => 'Add Product', - 'add_version' => 'Add Version', - 'administration_x' => 'Administration - %1$s', - 'bugstrike_login' => 'BugStrike Login', - 'cant_delete_default_usergroup' => 'You can\'t delete a default usergroup.', - 'confirm' => 'Confirm', - 'confirm_delete_priority' => 'Are you sure you want to delete this priority? Doing so will revert all bugs to the default priority (which is set in the options panel)?', - 'confirm_delete_product' => 'Are you sure you want to delete this product and all of it\'s sub-versions and components (as well as any bugs contained within those groups)?', - 'confirm_delete_resolution' => 'Are you sure you want to delete this resolution? Doing so will revert all bugs to the default resolution (which is set in the options panel)?', - 'confirm_delete_severity' => 'Are you sure you want to delete this severity? Doing so will revert all bugs to the default severity (which is set in the options panel)?', - 'confirm_delete_status' => 'Are you sure you want to delete this status? Doing so will revert all bugs to the default status (which is set in the options panel)?', - 'confirm_delete_usergroup' => 'Are you sure you want to delete this usergroup? All users in this group will be set back to the default registered usergroup (id: 2).', - 'confirm_delete_version' => 'Are you sure you want to delete this version? Doing so will do x to the bugs with this version.', - 'delete_wraplink' => '[Delete]', - 'edit_field' => 'Edit Field', - 'edit_priority' => 'Edit Priority', - 'edit_priority_title' => 'Edit Priority - %1$s (priorityid: %2$s)', - 'edit_product' => 'Edit Product', - 'edit_product_title' => 'Edit Product - %1$s', - 'edit_resolution' => 'Edit Resolution', - 'edit_resolution_title' => 'Edit Resolution - %1$s (resolutionid: %2$s)', - 'edit_severity' => 'Edit Severity', - 'edit_severity_title' => 'Edit Severity - %1$s (severityid: %2$s)', - 'edit_status' => 'Edit Status', - 'edit_status_title' => 'Edit Status - %1$s (statusid: %2$s)', - 'edit_usergroup' => 'Edit Usergroup', - 'edit_version' => 'Edit Version', - 'edit_version_title' => 'Edit Version - %1$s', - 'edit_wraplink' => '[Edit]', - 'email' => 'Email', - 'error' => 'Error', - 'error_invalid_id' => 'That is an invalid ID.', - 'error_no_permission' => 'You do not have permission to access this page. If you think that this is an error, please contact an administrator.', - 'field_x_is_required' => 'The field titled "%1$s" is a required field.', - 'fill_in_version_number' => 'Please fill in a version number.', - 'global_versions' => 'Global Versions', - 'go' => 'Go', - 'go_back_and_fill_both_fields' => 'Please go back and fill in both fields.', - 'guest' => 'Guest', - 'invalid_admin_session_terminated' => 'Invalid admin session has been terminated.', - 'login' => 'Login', - 'log_kill_attachment' => 'Removed attachment #%1$s', - 'log_mark_obsoletes' => 'Marking other attachments obsolete', - 'log_new_attachment' => 'Uploaded new attachment "%1$s" (attachmentid: %2$s)', - 'log_new_attachment_comment' => 'Created comment #%2$s', - 'log_new_comment' => 'Added comment (commentid: #%1$s)', - 'log_update_attachment' => 'Updated attachment #%1$s', - 'log_update_bug' => 'Updated bug', - 'log_update_comment' => 'Updated comment #%1$s', - 'new_priority' => 'New Priority', - 'new_resolution' => 'New Resolution', - 'new_severity' => 'New Severity', - 'new_status' => 'New Status', - 'new_usergroup' => 'New Usergroup', - 'no' => 'No', - 'number_of_users' => 'Number of Users', - 'password' => 'Password', - 'permissions_canadminbugs' => 'Can Administer Bug Reports', - 'permissions_canadminfields' => 'Can Administer Additional Bug Fields', - 'permissions_canadmingroups' => 'Can Administer Usergroups', - 'permissions_canadminpanel' => 'Can Access Control Panel', - 'permissions_canadmintools' => 'Can Administer Settings / Maintenance Tools', - 'permissions_canadminusers' => 'Can Administer Users', - 'permissions_canadminversions' => 'Can Administer Products / Components / Versions', - 'permissions_canassign' => 'Can Assign Bugs', - 'permissions_canbeassignedto' => 'Can Be Assigned Bugs', - 'permissions_canchangestatus' => 'Can Change Status', - 'permissions_caneditattach' => 'Can Manage All Attachments', - 'permissions_caneditinfo' => 'Can Edit Bug Information', - 'permissions_caneditothers' => 'Can Edit Others\' Bugs', - 'permissions_caneditown' => 'Can Edit Own Bugs', - 'permissions_cangetattach' => 'Can View Attachments', - 'permissions_canpostcomments' => 'Can Post Comments', - 'permissions_canputattach' => 'Can Upload/Edit Own Attachments', - 'permissions_cansearch' => 'Can Search Bugs', - 'permissions_cansubmitbugs' => 'Can Submit Bugs', - 'permissions_cansubscribe' => 'Can Subscribe to Bugs', - 'permissions_canviewbugs' => 'Can View Bugs', - 'permissions_canviewhidden' => 'Can View Hidden Bugs and Comments', - 'permissions_canvote' => 'Can Vote on Polls', - 'permissions_group_admin' => 'Administrator Permissions', - 'permissions_group_general' => 'General Permissions', - 'permissions_group_moderation' => 'Moderation/Managment Permissions', - 'permissions_group_posting' => 'Posting/Submitting Permissions', - 'priority_display_order' => 'Display Order
The order in which the priorities are displayed. The higher the number, the lower down in the list it is.
', - 'priority_manager' => 'Priority Manager', - 'priority_title' => 'Priority Title
The title of this priority flag (eg: `Slated for Development` or `Address Now`)
', - 'products_and_versions' => 'Products and Versions', - 'products_versions' => 'Products / Versions', - 'product_description' => 'Description
A short description of this product.
', - 'product_display_order' => 'Display Order
The order in which the products are displayed.
', - 'product_shortname' => 'Short Name
The name that can be used to submit email reports. This should be unique.
', - 'product_title' => 'Title', - 'redirect' => 'Redirect', - 'reset' => 'Reset', - 'resolution_display_order' => 'Display Order
The order in which the resolutions are displayed. The higher the number, the lower down in the list it is.
', - 'resolution_manager' => 'Resolution Manager', - 'resolution_title' => 'Resolution Title
The title of this resolution flag (eg: `Fixed` or `Bogus`)
', - 'save_display_order' => 'Save Display Order', - 'settinggroup_general' => 'General Options', - 'settinggroup_reporting' => 'Bug Reporting Options', - 'settinggroup_untouchables' => 'Untouchables', - 'setting_allowhtml_desc' => 'Set this to yes if you want to allow users to post raw HTML in their bug reports. This is very dangerous and it is not recommended.', - 'setting_allowhtml_title' => 'Allow HTML in Bug Reports', - 'setting_allownewreg_desc' => 'Can unregistered users be allowed to create accounts.', - 'setting_allownewreg_title' => 'Allow New Registrations', - 'setting_dateformat_desc' => 'Set the date format used for bug report and comment information. This is based on PHP\'s date() function.', - 'setting_dateformat_title' => 'Date Format', - 'setting_defaultassign_desc' => 'This is the default developer new bugs will be assigned to. If a user does not have permisssion to assign bugs, this will be the default. If you don\'t want any default assignment, leave this as Not Selected.', - 'setting_defaultassign_title' => 'Default Bug Assignment', - 'setting_defaultcomment_desc' => 'If you wish to set a template for entering the initial comment of a bug report, then you may specify this here. However, the template will only take effect on the initial report/comment. Note: the template cannot be forced on the user as there is no way to validate it.', - 'setting_defaultcomment_title' => 'Default Comment Text', - 'setting_defaultpriority_desc' => 'The default priority that will be selected when creating a new bug report. Depending on your permission setup, the user may not be able to set this in a new report so this will act as the value.', - 'setting_defaultpriority_title' => 'Default Priority', - 'setting_defaultresolve_desc' => 'This is the default bug resolution. If a user is not able to change this field, setting this will act as the default value.', - 'setting_defaultresolve_title' => 'Default Resolution', - 'setting_defaultseverity_desc' => 'The default severity that is selected when creating a new bug report.', - 'setting_defaultseverity_title' => 'Default Severity', - 'setting_defaultstatus_desc' => 'The default default that is selected when creating a new bug report. If a user can not assign a status, this will be the one inserted into the database.', - 'setting_defaultstatus_title' => 'Default Status', - 'setting_moderatenewusers_desc' => 'All new users will have to be approved by the administration before being able to have normal user rights.', - 'setting_moderatenewusers_title' => 'Moderate New Users', - 'setting_sendwelcomemail_desc' => 'Setting this option to yes will send all new users, after they\'ve been verified, a welcoming email.', - 'setting_sendwelcomemail_title' => 'Send New Use Welcome Email', - 'setting_trackertitle_desc' => 'The global name of the bug tracker. Example: Iris Studios Bug Tracker', - 'setting_trackertitle_title' => 'Tracker Title', - 'setting_trackerversion_desc' => 'Do not touch this!', - 'setting_trackerversion_title' => 'Tracker Version Number', - 'setting_verifyemail_desc' => 'Setting this to yes will force all new users to verify their account with an email activation link.', - 'setting_verifyemail_title' => 'Require Activation Email', - 'setting_webmasteremail_desc' => 'The email address from which emails will be sent out.', - 'setting_webmasteremail_title' => 'Webmaster Email Address', - 'severity_display_order' => 'Display Order
The order in which the severities are displayed. The higher the number, the lower down in the list it is.
', - 'severity_title' => 'Severity Title
The title of this severity flag (eg: `Major` or `Critical`)
', - 'status_color' => 'Status Colour
The colour of the status. This will be displayed on bug listings page to make viewing easier. Note: you must enter the # sign if you are using HEX values.
', - 'status_display_order' => 'Display Order
The order in which the statuses ar displayed.
', - 'status_title' => 'Status Title
The title of this status flag (eg: `Confirmed` or `Closed (Fixed)`)
', - 'submit' => 'Submit', - 'usergroup' => 'Usergroup', - 'usergroup_close_markup' => 'Closing Tag Markup
Place all closed HTML tags that will close any open HTML tags entered above.
', - 'usergroup_details' => 'Usergroup Details', - 'usergroup_display_title' => 'Display Title
This is the title that others will be able to see when comments are posted.
', - 'usergroup_manager' => 'Usergroup Manager', - 'usergroup_open_markup' => 'Opening Tag Markup
Place all open HTML tags here that will be wrapped around the username.
', - 'usergroup_permission_settings' => 'Permission Settings', - 'usergroup_title' => 'Usergroup Title', - 'version_display_order' => 'Display Order
The order in which the versions are displayed.
', - 'version_title' => 'Version Number
This is the version string for this product.
', - 'wait_to_be_redirected' => 'Please wait to be redirected. If you are not redirected in a few seconds, click here.', - 'yes' => 'Yes' -); - -/*=====================================================================*\ -|| ################################################################### -|| # $HeadURL$ -|| # $Id$ -|| ################################################################### -\*=====================================================================*/ -?> \ No newline at end of file diff --git a/docs/lang_file_master.xml b/docs/lang_file_master.xml new file mode 100755 index 0000000..57e3e02 --- /dev/null +++ b/docs/lang_file_master.xml @@ -0,0 +1,166 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + The order in which the priorities are displayed. The higher the number, the lower down in the list it is.]]> + + The title of this priority flag (eg: `Slated for Development` or `Address Now`)]]> + + + A short description of this product.]]> + The order in which the products are displayed.]]> + The name that can be used to submit email reports. This should be unique.]]> + + + + The order in which the resolutions are displayed. The higher the number, the lower down in the list it is.]]> + + The title of this resolution flag (eg: `Fixed` or `Bogus`)]]> + + + + + yes if you want to allow users to post raw HTML in their bug reports. This is very dangerous and it is not recommended.]]> + + + + + + Not Selected.]]> + + + + + + + + + + + + + + yes will send all new users, after they've been verified, a welcoming email.]]> + + + + + + + + + + The order in which the severities are displayed. The higher the number, the lower down in the list it is.]]> + The title of this severity flag (eg: `Major` or `Critical`)]]> + The colour of the status. This will be displayed on bug listings page to make viewing easier. Note: you must enter the # sign if you are using HEX values.]]> + The order in which the statuses ar displayed.]]> + The title of this status flag (eg: `Confirmed` or `Closed (Fixed)`)]]> + + + Place all closed HTML tags that will close any open HTML tags entered above.]]> + + This is the title that others will be able to see when comments are posted.]]> + + Place all open HTML tags here that will be wrapped around the username.]]> + + + The order in which the versions are displayed.]]> + This is the version string for this product.]]> + here.]]> + + \ No newline at end of file diff --git a/docs/phrasetools.php b/docs/phrasetools.php index 5cae4c3..9c250f9 100644 --- a/docs/phrasetools.php +++ b/docs/phrasetools.php @@ -196,21 +196,10 @@ if ($_REQUEST['do'] == 'search') if ($_REQUEST['do'] == 'export') { - $output = " -\$language = array("; - - $phrases = $db->query("SELECT * FROM " . TABLE_PREFIX . "phrase ORDER BY varname"); - while ($phrase = $db->fetch_array($phrases)) - { - $phrase['phrasetext'] = str_replace("'", "\'", $phrase['phrasetext']); - $phrasebits[] = "\n\t'$phrase[varname]' => '$phrase[phrasetext]'"; - } + require_once('./includes/class_xml_language.php'); + $lang = new XML_Language(); + $output = $lang->export(-1); - $output .= implode(',', $phrasebits); - - $output .= " -);\n"; - $output = $bugsys->sanitize($output); echo <<path) AND empty($this->xmldata)) + { + return false; + } + + if (!empty($this->path)) + { + if (($fdata = @file_get_contents($this->path)) !== false) + { + $this->xmldata = $fdata; + return true; + } + else + { + return false; + } + } + else + { + return true; + } + } + + // ------------------------------------------------------------------- + // -- Parses the XML data + // ------------------------------------------------------------------- + function parse() + { + global $bugsys; + + if (empty($this->xmldata)) + { + return false; + } + + $this->phrases = array(); + $this->languageinfo = array(); + + if (!$bugsys->is_loaded('xml')) + { + $bugsys->load('xml'); + } + + $data = $bugsys->xml->parse($this->xmldata); + + foreach ($data AS $tag) + { + if ($tag['tagname'] == 'language') + { + $this->languageinfo = $tag['attributes']; + if ($this->languageinfo['MASTER'] == 'MASTER') + { + $this->master = true; + unset($this->languageinfo['MASTER']); + } + } + else if ($tag['tagname'] == 'phrase') + { + $this->phrases[ $tag['attributes']['name'] ] = $tag['data']; + } + } + } + + // ------------------------------------------------------------------- + // -- Returns a query that creates a language + // ------------------------------------------------------------------- + function language() + { + global $bugsys; + + $query = " + INSERT INTO " . TABLE_PREFIX . "language + (title, languagecode, charset, direction, default, userselect) + VALUES + ('" . $bugsys->escape($this->languageinfo['title']) . "', + '" . $bugsys->escape($this->languageinfo['languagecode']) . "', + '" . $bugsys->escape($this->languageinfo['charset']) . "', + '" . $bugsys->escape($this->languageinfo['direction']) . "', 0, 0 + )"; + + return $query; + } + + // ------------------------------------------------------------------- + // -- Constructs the MySQL query to insert phrases + // ------------------------------------------------------------------- + function build() + { + global $bugsys; + + if ($this->master) + { + $query = " + INSERT INTO " . TABLE_PREFIX . "phrase + (varname, phrasetext, imported) + VALUES"; + + foreach ($this->phrases AS $name => $text) + { + $querybuild[] = " + ('" . $bugsys->escape($name) . "', '" . $bugsys->escape($text) . "', " . time() . ")"; + } + + $query .= implode(',', $querybuild); + } + else + { + if (!$this->languageid) + { + return false; + } + + $query = " + INSERT INTO " . TABLE_PREFIX . "locale + (languageid, varname, phrasetext) + VALUES"; + + foreach ($this->phrases AS $name => $text) + { + $querybuild[] = " + ({$this->languageid}, '" . $bugsys->escape($name) . "', '" . $bugsys->escape($text) . "')"; + } + + $query .= implode(',', $querybuild); + } + + return $query; + } + + // ------------------------------------------------------------------- + // -- Constructs XML data for export + // ------------------------------------------------------------------- + function export($languageid) + { + global $bugsys; + + // attributes for the root tag + $attrs = array(); + + if ($languageid != -1) + { + $language = $bugsys->db->query_first("SELECT * FROM " . TABLE_PREFIX . "language WHERE languageid = " . intval($languageid)); + if (!$language) + { + return false; + } + + $attrs['title'] = $language['title']; + $attrs['languagecode'] = $language['languagecode']; + $attrs['charset'] = $language['charset']; + $attrs['direction'] = $language['direction']; + + $phrasefetch = $bugsys->db->query("SELECT * FROM " . TABLE_PREFIX . "locale WHERE languageid = $language[languageid] ORDER BY varname ASC"); + while ($phrase = $bugsys->db->fetch_array($phrasefetch)) + { + $phrases["$phrase[varname]"] = $phrase['phrasetext']; + } + $bugsys->db->free_result($phrasefetch); + } + else + { + $attrs['MASTER'] = 'MASTER'; + + $phrasefetch = $bugsys->db->query("SELECT * FROM " . TABLE_PREFIX . "phrase ORDER BY varname ASC"); + while ($phrase = $bugsys->db->fetch_array($phrasefetch)) + { + $phrases["$phrase[varname]"] = $phrase['phrasetext']; + } + $bugsys->db->free_result($phrasefetch); + } + + // construct the top notice + $xmlout = (($languageid == -1) ? '' . "\n" . '' : '') . "\n\n"; + + // construct the root tag + foreach ($attrs AS $name => $value) + { + $outattrs[] = $name . '="' . $bugsys->escape($value) . '"'; + } + $xmlout .= '\n"; + + // construct the phrases + foreach ($phrases AS $varname => $text) + { + $xmlout .= "\tescape($varname) . "\">\n"; + } + + // construct the end root tag + $xmlout .= ''; + + // all finished + return $xmlout; + } +} + +/*=====================================================================*\ +|| ################################################################### +|| # $HeadURL$ +|| # $Id$ +|| ################################################################### +\*=====================================================================*/ +?> \ No newline at end of file -- 2.43.5