diff --git a/component/admin/config.xml b/component/admin/config.xml index d30e74b1..201d1f99 100644 --- a/component/admin/config.xml +++ b/component/admin/config.xml @@ -130,6 +130,92 @@ label="COM_LOCALISE_LABEL_LICENSE" description="COM_LOCALISE_LABEL_LICENSE_DESC" /> +
+ + + + + + + + + + + + + + + + + + +
\ No newline at end of file diff --git a/component/admin/customisedref/stable_joomla_releases.txt b/component/admin/customisedref/stable_joomla_releases.txt new file mode 100644 index 00000000..b6e5b3de --- /dev/null +++ b/component/admin/customisedref/stable_joomla_releases.txt @@ -0,0 +1,33 @@ +3.4.8 +3.4.7 +3.4.6 +3.4.5 +3.4.4 +3.4.3 +3.4.2 +3.4.1 +3.4.0 +3.3.6 +3.3.5 +3.3.4 +3.3.3 +3.3.2 +3.3.1 +3.3.0 +3.2.7 +3.2.6 +3.2.5 +3.2.3 +3.2.2 +3.2.1 +3.2.0 +3.1.6 +3.1.4 +3.1.3 +3.1.2 +3.1.1 +3.1.0 +3.0.4 +3.0.2 +3.0.1 +3.0.0 diff --git a/component/admin/develop/index.html b/component/admin/develop/index.html new file mode 100644 index 00000000..3af63015 --- /dev/null +++ b/component/admin/develop/index.html @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/component/admin/helpers/defines.php b/component/admin/helpers/defines.php index b43caf03..f4dc05ff 100644 --- a/component/admin/helpers/defines.php +++ b/component/admin/helpers/defines.php @@ -11,6 +11,7 @@ // Define constants $params = JComponentHelper::getParams('com_localise'); + define('LOCALISEPATH_SITE', JPATH_SITE); define('LOCALISEPATH_ADMINISTRATOR', JPATH_ADMINISTRATOR); define('LOCALISEPATH_INSTALLATION', JPATH_ROOT . '/' . $params->get('installation', 'installation')); diff --git a/component/admin/helpers/localise.php b/component/admin/helpers/localise.php index 30515a5a..cd515c4c 100644 --- a/component/admin/helpers/localise.php +++ b/component/admin/helpers/localise.php @@ -11,6 +11,7 @@ jimport('joomla.filesystem.folder'); jimport('joomla.filesystem.path'); +jimport("joomla.utilities.date"); /** * Localise Helper class @@ -592,7 +593,7 @@ public static function getTranslationPath($client, $tag, $filename, $storage) if (!is_file($path)) { - $path = $client == 'administrator' ? LOCALISEPATH_SITE : LOCALISEPATH_ADMINISTRATOR . "/language/$tag/$tag.$filename.ini"; + $path = $client == 'administrator' ? 'LOCALISEPATH_' . 'SITE' : 'LOCALISEPATH_' . 'ADMINISTRATOR' . "/language/$tag/$tag.$filename.ini"; } break; @@ -638,7 +639,7 @@ public static function loadLanguage($extension, $client) break; case 'plg': - $lang->load($extension, LOCALISEPATH_ADMINISTRATOR, null, false, true) + $lang->load($extension, 'LOCALISEPATH_' . 'ADMINISTRATOR', null, false, true) || $lang->load($extension, LOCALISEPATH_ADMINISTRATOR . "/components/$extension/", null, false, true); break; @@ -750,4 +751,1753 @@ public static function parseSections($filename) return $sections[$filename]; } + + /** + * Gets the files to use as source reference from Github + * + * @param array $gh_data Array with the required data + * + * @return array + * + * @since 4.11 + */ + public static function getSourceGithubfiles($gh_data = array()) + { + if (!empty($gh_data)) + { + $params = JComponentHelper::getParams('com_localise'); + $ref_tag = $params->get('reference', 'en-GB'); + $saved_ref = $params->get('customisedref', '0'); + $allow_develop = $params->get('gh_allow_develop', 0); + $gh_client = $gh_data['github_client']; + $customisedref = $saved_ref; + $last_sources = self::getLastsourcereference(); + $last_source = $last_sources[$gh_client]; + + $versions_path = JPATH_ROOT + . '/administrator/components/com_localise/customisedref/stable_joomla_releases.txt'; + + $versions_file = file_get_contents($versions_path); + $versions = preg_split("/\\r\\n|\\r|\\n/", $versions_file); + + if ($saved_ref != '0' && !in_array($customisedref, $versions)) + { + // Ensure from translations view that we have updated the last one released only when no maches. + $search_releases = self::getReleases(); + $versions_file = file_get_contents($versions_path); + $versions = preg_split("/\\r\\n|\\r|\\n/", $versions_file); + } + + $installed_version = new JVersion; + $installed_version = $installed_version->getShortVersion(); + + $core_paths['administrator'] = 'administrator/language/en-GB'; + $core_paths['site'] = 'language/en-GB'; + $core_paths['installation'] = 'installation/language/en-GB'; + + if ($saved_ref == '0') + { + // It will use core language folders. + $customisedref = "Local installed instance ($installed_version??)"; + } + else + { + // It will use language folders with other stored versions. + $custom_client_path = JPATH_ROOT . '/media/com_localise/customisedref/github/' + . $gh_data['github_client'] + . '/' + . $customisedref; + $custom_client_path = JFolder::makeSafe($custom_client_path); + } + + // If reference tag is not en-GB is not required try it + if ($ref_tag != 'en-GB' && $allow_develop == 1) + { + JFactory::getApplication()->enqueueMessage( + JText::_('COM_LOCALISE_ERROR_GETTING_UNALLOWED_CONFIGURATION'), + 'warning'); + + return false; + } + + // If not knowed Joomla version is not required try it + if ($saved_ref != '0' && !in_array($customisedref, $versions) && $allow_develop == 1) + { + JFactory::getApplication()->enqueueMessage( + JText::sprintf('COM_LOCALISE_ERROR_GITHUB_GETTING_LOCAL_INSTALLED_FILES', $customisedref), + 'warning'); + + $option = '0'; + $revert = self::setCustomisedsource($option); + $save_last = self::saveLastsourcereference($gh_data['github_client'], ''); + + return false; + } + + // If feature is disabled but last used files are disctinct to default ones + // Is required make notice that we are coming back to local installed instance version. + if ($saved_ref != '0' && !empty($last_source) && $last_source != '0' && $allow_develop == 0) + { + $customisedref = $installed_version; + + JFactory::getApplication()->enqueueMessage( + JText::sprintf('COM_LOCALISE_NOTICE_DISABLED_ALLOW_DEVELOP_WITHOUT_LOCAL_SET', + $last_source, + $installed_version, + $gh_client + ), + 'notice' + ); + + $option = '0'; + $revert = self::setCustomisedsource($option); + $save_last = self::saveLastsourcereference($gh_data['github_client'], ''); + + return true; + } + + // If not knowed Joomla version and feature is disabled is not required try it + if ($saved_ref != '0' && !in_array($customisedref, $versions) && $allow_develop == 0) + { + return false; + } + + // If configured to local installed instance there is nothing to get from Github + if ($saved_ref == '0') + { + $save_last = self::saveLastsourcereference($gh_data['github_client'], ''); + + return true; + } + + $xml_file = $custom_client_path . '/en-GB.xml'; + + // Unrequired move or update files again + if ($saved_ref != '0' && $installed_version == $last_source && JFile::exists($xml_file)) + { + return false; + } + + $gh_data['allow_develop'] = $allow_develop; + $gh_data['customisedref'] = $customisedref; + $gh_target = self::getCustomisedsource($gh_data); + $gh_paths = array(); + $gh_user = $gh_target['user']; + $gh_project = $gh_target['project']; + $gh_branch = $gh_target['branch']; + $gh_token = $params->get('gh_token', ''); + $gh_paths['administrator'] = 'administrator/language/en-GB'; + $gh_paths['site'] = 'language/en-GB'; + $gh_paths['installation'] = 'installation/language/en-GB'; + + $reference_client_path = JPATH_ROOT . '/' . $gh_paths[$gh_client]; + $reference_client_path = JFolder::makeSafe($reference_client_path); + + if (JFile::exists($xml_file)) + { + // We have done this trunk and is not required get the files from Github again. + $update_files = self::updateSourcereference($gh_client, $custom_client_path); + + if ($update_files == false) + { + return false; + } + + $save_last = self::saveLastsourcereference($gh_data['github_client'], $customisedref); + + return true; + } + + $options = new JRegistry; + + if (!empty($gh_token)) + { + $options->set('gh.token', $gh_token); + $github = new JGithub($options); + } + else + { + // Without a token runs fatal. + // $github = new JGithub; + + // Trying with a 'read only' public repositories token + // But base 64 encoded to avoid Github alarms sharing it. + $gh_token = base64_decode('MzY2NzYzM2ZkMzZmMWRkOGU5NmRiMTdjOGVjNTFiZTIyMzk4NzVmOA=='); + $options->set('gh.token', $gh_token); + $github = new JGithub($options); + } + + try + { + $repostoryfiles = $github->repositories->contents->get( + $gh_user, + $gh_project, + $gh_paths[$gh_client], + $gh_branch + ); + } + catch (Exception $e) + { + JFactory::getApplication()->enqueueMessage( + JText::_('COM_LOCALISE_ERROR_GITHUB_GETTING_REPOSITORY_FILES'), + 'warning'); + + return false; + } + + if (!JFolder::exists($custom_client_path)) + { + $create_folder = self::createFolder($gh_data, $index = 'true'); + + if ($create_folder == false) + { + return false; + } + } + + $all_files_list = self::getLanguagefileslist($custom_client_path); + $ini_files_list = self::getInifileslist($custom_client_path); + + $files_to_include = array(); + + foreach ($repostoryfiles as $repostoryfile) + { + $file_to_include = $repostoryfile->name; + $file_path = JFolder::makeSafe($custom_client_path . '/' . $file_to_include); + $reference_file_path = JFolder::makeSafe($reference_client_path . '/' . $file_to_include); + + $custom_file = $github->repositories->contents->get( + $gh_user, + $gh_project, + $repostoryfile->path, + $gh_branch + ); + + $files_to_include[] = $file_to_include; + + if (!empty($custom_file) && isset($custom_file->content)) + { + $file_to_include = $repostoryfile->name; + $file_contents = base64_decode($custom_file->content); + JFile::write($file_path, $file_contents); + + if (!JFile::exists($file_path)) + { + JFactory::getApplication()->enqueueMessage( + JText::_('COM_LOCALISE_ERROR_GITHUB_UNABLE_TO_CREATE_DEV_FILE'), + 'warning'); + + return false; + } + } + } + + if (!empty($all_files_list) && !empty($files_to_include)) + { + // For files not present yet. + $files_to_delete = array_diff($all_files_list, $files_to_include); + + if (!empty($files_to_delete)) + { + foreach ($files_to_delete as $file_to_delete) + { + if ($file_to_delete != 'index.html') + { + $file_path = JFolder::makeSafe($custom_client_path . "/" . $file_to_delete); + JFile::delete($file_path); + + if (JFile::exists($file_path)) + { + JFactory::getApplication()->enqueueMessage( + JText::_('COM_LOCALISE_ERROR_GITHUB_FILE_TO_DELETE_IS_PRESENT'), + 'warning'); + + return false; + } + } + } + } + } + + if (JFile::exists($xml_file)) + { + // We have done this trunk. + + // So we can move the customised source reference files to core client folder + $update_files = self::updateSourcereference($gh_client, $custom_client_path); + + if ($update_files == false) + { + return false; + } + + $save_last = self::saveLastsourcereference($gh_data['github_client'], $customisedref); + + JFactory::getApplication()->enqueueMessage( + JText::sprintf('COM_LOCALISE_NOTICE_GITHUB_GETS_A_SOURCE_FULL_SET', $customisedref), + 'notice'); + + return true; + } + + JFactory::getApplication()->enqueueMessage( + JText::sprintf('COM_LOCALISE_ERROR_GITHUB_UNABLE_TO_GET_A_FULL_SOURCE_SET', $customisedref), + 'warning'); + + return false; + } + + JFactory::getApplication()->enqueueMessage(JText::_('COM_LOCALISE_ERROR_GITHUB_NO_DATA_PRESENT'), 'warning'); + + return false; + } + + /** + * Gets the stable Joomla releases list. + * + * @return array + * + * @since 4.11 + */ + public static function getReleases() + { + $params = JComponentHelper::getParams('com_localise'); + $versions_path = JPATH_ROOT + . '/administrator/components/com_localise/customisedref/stable_joomla_releases.txt'; + $versions_file = file_get_contents($versions_path); + $versions = preg_split("/\\r\\n|\\r|\\n/", $versions_file); + + $gh_user = 'joomla'; + $gh_project = 'joomla-cms'; + $gh_token = $params->get('gh_token', ''); + + $options = new JRegistry; + + if (!empty($gh_token)) + { + $options->set('gh.token', $gh_token); + $github = new JGithub($options); + } + else + { + // Without a token runs fatal. + // $github = new JGithub; + + // Trying with a 'read only' public repositories token + // But base 64 encoded to avoid Github alarms sharing it. + $gh_token = base64_decode('MzY2NzYzM2ZkMzZmMWRkOGU5NmRiMTdjOGVjNTFiZTIyMzk4NzVmOA=='); + $options->set('gh.token', $gh_token); + $github = new JGithub($options); + } + + try + { + $releases = $github->repositories->get( + $gh_user, + $gh_project . '/releases' + ); + + // Allowed tricks. + // Configured to 0 the 2.5.x series are not allowed. Configured to 1 it is allowed. + $allow_25x = 1; + + foreach ($releases as $release) + { + $tag_name = $release->tag_name; + $tag_part = explode(".", $tag_name); + $undoted = str_replace('.', '', $tag_name); + $excluded = 0; + + if ($tag_part[0] == '2' && $allow_25x == '0') + { + $excluded = 1; + } + elseif ($tag_part[0] != '3' && $tag_part[0] != '2') + { + // Exclude platforms or similar stuff. + $excluded = 1; + } + + // Filtering also by "is_numeric" disable betas or similar releases. + if (!in_array($tag_name, $versions) && is_numeric($undoted) && $excluded == 0) + { + $versions[] = $tag_name; + JFactory::getApplication()->enqueueMessage( + JText::sprintf('COM_LOCALISE_NOTICE_NEW_VERSION_DETECTED', $tag_name), + 'notice'); + } + } + } + catch (Exception $e) + { + JFactory::getApplication()->enqueueMessage( + JText::_('COM_LOCALISE_ERROR_GITHUB_GETTING_RELEASES'), + 'warning'); + } + + arsort($versions); + + $versions_file = ''; + + foreach ($versions as $id => $version) + { + if (!empty($version)) + { + $versions_file .= $version . "\n"; + } + } + + JFile::write($versions_path, $versions_file); + + return $versions; + } + + /** + * Save the last en-GB source version used as reference. + * + * @param string $client The client + * + * @param string $customisedref The version number + * + * @return boolean + * + * @since 4.11 + */ + public static function saveLastsourcereference($client = '', $customisedref = '') + { + $last_reference_file = JPATH_COMPONENT_ADMINISTRATOR + . '/customisedref/' + . $client + . '_last_source_ref.txt'; + + $file_contents = $customisedref . "\n"; + + if (!JFile::write($last_reference_file, $file_contents)) + { + return false; + } + + return true; + } + + /** + * Gets the last en-GB source reference version moved to the core folders. + * + * @return array + * + * @since 4.11 + */ + public static function getLastsourcereference() + { + $last_source_reference = array(); + $last_source_reference['administrator'] = ''; + $last_source_reference['site'] = ''; + $last_source_reference['installation'] = ''; + + $clients = array('administrator', 'site', 'installation'); + + foreach ($clients as $client) + { + $last_reference_file = JPATH_COMPONENT_ADMINISTRATOR + . '/customisedref/' + . $client + . '_last_source_ref.txt'; + + if (JFile::exists($last_reference_file)) + { + $file_contents = file_get_contents($last_reference_file); + $lines = preg_split("/\\r\\n|\\r|\\n/", $file_contents); + + foreach ($lines as $line) + { + if (!empty($line)) + { + $last_source_reference[$client] = $line; + } + } + } + } + + return $last_source_reference; + } + + /** + * Gets the reference name to use at Github + * + * @param array $gh_data Array with the required data + * + * @return array + * + * @since 4.11 + */ + public static function getCustomisedsource($gh_data = array()) + { + $source_ref = $gh_data['customisedref']; + $allow_develop = $gh_data['allow_develop']; + + $sources = array(); + + // Detailing it we can handle exceptions and add other Github users or projects. + // To get the language files for a determined Joomla's version that is not present from main Github repository. + $sources['3.4.1']['user'] = 'joomla'; + $sources['3.4.1']['project'] = 'joomla-cms'; + $sources['3.4.1']['branch'] = '3.4.1'; + + if (array_key_exists($source_ref, $sources)) + { + return ($sources[$source_ref]); + } + + // For undefined REF 0 or unlisted cases due Joomla releases at Github are following a version name patern. + $sources[$source_ref]['user'] = 'joomla'; + $sources[$source_ref]['project'] = 'joomla-cms'; + $sources[$source_ref]['branch'] = $source_ref; + + return ($sources[$source_ref]); + } + + /** + * Keep updated the customised client path including only the common files present in develop. + * + * @param string $client The client + * + * @param string $custom_client_path The path where the new source reference is stored + * + * @return boolean + * + * @since 4.11 + */ + public static function updateSourcereference($client, $custom_client_path) + { + $develop_client_path = JPATH_ROOT . '/media/com_localise/develop/github/joomla-cms/en-GB/' . $client; + $develop_client_path = JFolder::makeSafe($develop_client_path); + + $custom_ini_files_list = self::getInifileslist($custom_client_path); + $last_ini_files_list = self::getInifileslist($develop_client_path); + + $files_to_exclude = array(); + + if (!JFile::exists($develop_client_path . '/en-GB.xml')) + { + JFactory::getApplication()->enqueueMessage( + JText::_('COM_LOCALISE_ERROR_GITHUB_UNABLE_TO_UPDATE_TARGET_FILES'), + 'warning'); + + return false; + } + elseif (!JFile::exists($custom_client_path . '/en-GB.xml')) + { + JFactory::getApplication()->enqueueMessage( + JText::_('COM_LOCALISE_ERROR_GITHUB_UNABLE_TO_UPDATE_SOURCE_FILES'), + 'warning'); + + return false; + } + + // This one is for files not present within last in dev yet. + // Due have no sense add old language files to translate or revise for the comming soon package. + + $files_to_exclude = array_diff($custom_ini_files_list, $last_ini_files_list); + + if (!empty($files_to_exclude)) + { + $errors = 0; + + foreach ($files_to_exclude as $file_to_delete) + { + $custom_file_path = JFolder::makeSafe($custom_client_path . "/" . $file_to_delete); + + if (!JFile::delete($custom_file_path)) + { + $errors++; + } + } + + if ($errors > 0) + { + JFactory::getApplication()->enqueueMessage( + JText::sprintf('COM_LOCALISE_ERROR_DELETING_EXTRA_SOURCE_FILES', $errors), + 'warning'); + + return false; + } + } + + return true; + } + + /** + * Keep updated the core path with the selected source files as reference (used at previous working mode). + * + * @param string $client The client + * + * @param string $custom_client_path The path where the new source reference is stored + * + * @param string $reference_client_path The path where the old source reference is stored + * + * @return boolean + * + * @since 4.11 + */ + public static function updateSourcereferencedirectly($client, $custom_client_path, $reference_client_path) + { + $develop_client_path = JPATH_ROOT . '/media/com_localise/develop/github/joomla-cms/en-GB/' . $client; + $develop_client_path = JFolder::makeSafe($develop_client_path); + + $custom_ini_files_list = self::getInifileslist($custom_client_path); + $last_ini_files_list = self::getInifileslist($develop_client_path); + + $files_to_exclude = array(); + + if (!JFile::exists($develop_client_path . '/en-GB.xml')) + { + JFactory::getApplication()->enqueueMessage( + JText::_('COM_LOCALISE_ERROR_GITHUB_UNABLE_TO_UPDATE_TARGET_FILES'), + 'warning'); + + return false; + } + elseif (!JFile::exists($custom_client_path . '/en-GB.xml')) + { + JFactory::getApplication()->enqueueMessage( + JText::_('COM_LOCALISE_ERROR_GITHUB_UNABLE_TO_UPDATE_SOURCE_FILES'), + 'warning'); + + return false; + } + + // This one is for core files not present within last in dev yet. + // Due have no sense add old language files to translate for the comming soon package. + + $files_to_exclude = array_diff($custom_ini_files_list, $last_ini_files_list); + + if (!empty($files_to_exclude)) + { + foreach ($files_to_exclude as $file_to_delete) + { + $custom_file_path = JFolder::makeSafe($custom_client_path . "/" . $file_to_delete); + $actual_file_path = JFolder::makeSafe($reference_client_path . "/" . $file_to_delete); + + JFile::delete($custom_file_path); + + // Also verify if the same file is also present in core language folder. + + if (JFile::exists($actual_file_path)) + { + JFile::delete($actual_file_path); + + JFactory::getApplication()->enqueueMessage( + JText::sprintf('COM_LOCALISE_OLD_FILE_DELETED', $file_to_delete), + 'notice'); + } + } + + // Getting the new list again + $custom_ini_files_list = self::getInifileslist($custom_client_path); + } + + $errors = 0; + + foreach ($custom_ini_files_list as $customised_source_file) + { + $source_path = $custom_client_path . '/' . $customised_source_file; + $file_contents = file_get_contents($source_path); + $target_path = $reference_client_path . '/' . $customised_source_file; + + if (!JFile::write($target_path, $file_contents)) + { + $errors++; + } + } + + if ($errors > 0) + { + JFactory::getApplication()->enqueueMessage( + JText::sprintf('COM_LOCALISE_ERROR_SAVING_FILES_AT_CORE_FOLDER', $errors), + 'warning'); + + return false; + } + + return true; + } + + /** + * Gets from zero or keept updated the files in develop to use as target reference from Github + * + * @param array $gh_data Array with the required data + * + * @return array + * + * @since 4.11 + */ + public static function getTargetgithubfiles($gh_data = array()) + { + if (!empty($gh_data)) + { + $now = new JDate; + $now = $now->toSQL(); + $params = JComponentHelper::getParams('com_localise'); + $client_to_update = 'gh_' . $gh_data['github_client'] . '_last_update'; + $last_stored_update = $params->get($client_to_update, ''); + $ref_tag = $params->get('reference', 'en-GB'); + $allow_develop = $params->get('gh_allow_develop', 0); + + if ($allow_develop == 0) + { + return false; + } + + if ($ref_tag != 'en-GB') + { + JFactory::getApplication()->enqueueMessage( + JText::_('COM_LOCALISE_ERROR_GETTING_ALLOWED_REFERENCE_TAG'), + 'warning'); + + return false; + } + + $develop_client_path = JPATH_ROOT + . '/media/com_localise/develop/github/joomla-cms/en-GB/' + . $gh_data['github_client']; + + $develop_client_path = JFolder::makeSafe($develop_client_path); + $xml_file = $develop_client_path . '/en-GB.xml'; + + if (!JFile::exists($xml_file)) + { + $get_files = 1; + } + elseif (!empty($last_stored_update)) + { + $last_update = new JDate($last_stored_update); + $last_update = $last_update->toSQL(); + $interval = $params->get('gh_updates_interval', '1') == '1' ? 24 : 1; + $interval = $last_update . " +" . $interval . " hours"; + $next_update = new JDate($interval); + $next_update = $next_update->toSQL(); + + if ($now >= $next_update) + { + $get_files = 1; + } + else + { + $get_files = 0; + } + } + else + { + $get_files = 1; + } + + if ($get_files == 0) + { + return false; + } + + $gh_paths = array(); + $gh_client = $gh_data['github_client']; + $gh_user = 'joomla'; + $gh_project = 'joomla-cms'; + $gh_branch = $params->get('gh_branch', 'master'); + $gh_token = $params->get('gh_token', ''); + $gh_paths['administrator'] = 'administrator/language/en-GB'; + $gh_paths['site'] = 'language/en-GB'; + $gh_paths['installation'] = 'installation/language/en-GB'; + + $reference_client_path = JPATH_ROOT . '/' . $gh_paths[$gh_client]; + $reference_client_path = JFolder::makeSafe($reference_client_path); + + $options = new JRegistry; + + if (!empty($gh_token)) + { + $options->set('gh.token', $gh_token); + $github = new JGithub($options); + } + else + { + // Without a token runs fatal. + // $github = new JGithub; + + // Trying with a 'read only' public repositories token + // But base 64 encoded to avoid Github alarms sharing it. + $gh_token = base64_decode('MzY2NzYzM2ZkMzZmMWRkOGU5NmRiMTdjOGVjNTFiZTIyMzk4NzVmOA=='); + $options->set('gh.token', $gh_token); + $github = new JGithub($options); + } + + try + { + $repostoryfiles = $github->repositories->contents->get( + $gh_user, + $gh_project, + $gh_paths[$gh_client], + $gh_branch + ); + } + catch (Exception $e) + { + JFactory::getApplication()->enqueueMessage( + JText::_('COM_LOCALISE_ERROR_GITHUB_GETTING_REPOSITORY_FILES'), + 'warning'); + + return false; + } + + $all_files_list = self::getLanguagefileslist($develop_client_path); + $ini_files_list = self::getInifileslist($develop_client_path); + $sha_files_list = self::getShafileslist($gh_data); + + $sha = ''; + $files_to_include = array(); + + foreach ($repostoryfiles as $repostoryfile) + { + $file_to_include = $repostoryfile->name; + $file_path = JFolder::makeSafe($develop_client_path . '/' . $file_to_include); + $reference_file_path = JFolder::makeSafe($reference_client_path . '/' . $file_to_include); + + if ( (array_key_exists($file_to_include, $sha_files_list) + && ($sha_files_list[$file_to_include] != $repostoryfile->sha)) + || empty($sha_files_list) + || !array_key_exists($file_to_include, $sha_files_list) + || !JFile::exists($file_path)) + { + $in_dev_file = $github->repositories->contents->get( + $gh_user, + $gh_project, + $repostoryfile->path, + $gh_branch + ); + } + else + { + $in_dev_file = ''; + } + + $files_to_include[] = $file_to_include; + $sha_path = JPATH_COMPONENT_ADMINISTRATOR . '/develop/gh_joomla_' . $gh_client . '_files.txt'; + $sha_path = JFolder::makeSafe($sha_path); + + if (!empty($in_dev_file) && isset($in_dev_file->content)) + { + $file_to_include = $repostoryfile->name; + $file_contents = base64_decode($in_dev_file->content); + JFile::write($file_path, $file_contents); + + if (!JFile::exists($file_path)) + { + JFactory::getApplication()->enqueueMessage( + JText::_('COM_LOCALISE_ERROR_GITHUB_UNABLE_TO_CREATE_DEV_FILE'), + 'warning'); + + return false; + } + + if (!JFile::exists($reference_file_path) + && ($gh_client == 'administrator' || $gh_client == 'site')) + { + // Adding files only present in develop to core reference location. + JFile::write($reference_file_path, $file_contents); + + if (!JFile::exists($reference_file_path)) + { + JFactory::getApplication()->enqueueMessage( + JText::_('COM_LOCALISE_ERROR_GITHUB_UNABLE_TO_ADD_NEW_FILES'), + 'warning'); + + return false; + } + + JFactory::getApplication()->enqueueMessage( + JText::_('COM_LOCALISE_NOTICE_GITHUB_FILE_ADDED'), + 'notice'); + } + } + + // Saved for each time due few times get all the github files at same time can crash. + // This one can help to remember the last one saved correctly and next time continue from there. + $sha .= $repostoryfile->name . "::" . $repostoryfile->sha . "\n"; + JFile::write($sha_path, $sha); + + if (!JFile::exists($sha_path)) + { + JFactory::getApplication()->enqueueMessage( + JText::_('COM_LOCALISE_ERROR_GITHUB_NO_SHA_FILE_PRESENT'), + 'warning'); + + return false; + } + } + + if (!empty($all_files_list) && !empty($files_to_include)) + { + // For files not present in dev yet. + $files_to_delete = array_diff($all_files_list, $files_to_include); + + if (!empty($files_to_delete)) + { + foreach ($files_to_delete as $file_to_delete) + { + if ($file_to_delete != 'index.html') + { + $file_path = JFolder::makeSafe($develop_client_path . "/" . $file_to_delete); + JFile::delete($file_path); + + if (JFile::exists($file_path)) + { + JFactory::getApplication()->enqueueMessage( + JText::sprintf('COM_LOCALISE_ERROR_GITHUB_FILE_TO_DELETE_IS_PRESENT', $file_to_delete), + 'warning'); + + return false; + } + + JFactory::getApplication()->enqueueMessage( + JText::sprintf('COM_LOCALISE_GITHUB_FILE_NOT_PRESENT_IN_DEV_YET', $file_to_delete), + 'notice'); + } + } + } + } + + if (!JFile::exists($xml_file)) + { + JFactory::getApplication()->enqueueMessage( + JText::sprintf('COM_LOCALISE_ERROR_GITHUB_UNABLE_TO_GET_A_FULL_SET', $gh_branch), + 'warning'); + + return false; + } + + self::saveLastupdate($client_to_update); + + JFactory::getApplication()->enqueueMessage( + JText::sprintf('COM_LOCALISE_NOTICE_GITHUB_GETS_A_TARGET_FULL_SET', $gh_branch), + 'notice'); + + return true; + } + + JFactory::getApplication()->enqueueMessage(JText::_('COM_LOCALISE_ERROR_GITHUB_NO_DATA_PRESENT'), 'warning'); + + return false; + } + + /** + * Gets the changes between language files versions + * + * @param array $info The data to catch grammar cases + * @param array $refsections The released reference data + * @param array $develop_sections The developed reference data + * + * @return array + * + * @since 4.11 + */ + public static function getDevelopchanges($info = array(), $refsections = array(), $develop_sections = array()) + { + if (isset($refsections['keys']) && isset($develop_sections['keys'])) + { + $istranslation = $info['istranslation']; + $keys_in_reference = array_keys($refsections['keys']); + $keys_in_develop = array_keys($develop_sections['keys']); + + // Catching new keys in develop + $developdata['extra_keys']['amount'] = 0; + $developdata['extra_keys']['keys'] = array(); + $developdata['extra_keys']['strings'] = array(); + + $extras_in_develop = array_diff($keys_in_develop, $keys_in_reference); + + if (!empty($extras_in_develop)) + { + foreach ($extras_in_develop as $extra_key) + { + $developdata['extra_keys']['amount']++; + $developdata['extra_keys']['keys'][] = $extra_key; + $developdata['extra_keys']['strings'][$extra_key] = $develop_sections['keys'][$extra_key]; + } + } + + // Catching text changes in develop + $developdata['text_changes']['amount'] = 0; + $developdata['text_changes']['revised'] = 0; + $developdata['text_changes']['unrevised'] = 0; + $developdata['text_changes']['keys'] = array(); + $developdata['text_changes']['ref_in_dev'] = array(); + $developdata['text_changes']['ref'] = array(); + $developdata['text_changes']['diff'] = array(); + + foreach ($refsections['keys'] as $key => $string) + { + if (array_key_exists($key, $develop_sections['keys'])) + { + $string_in_develop = $develop_sections['keys'][$key]; + $text_changes = self::htmlgetTextchanges($string, $string_in_develop); + + if (!empty($text_changes)) + { + if ($istranslation == 1) + { + $info['key'] = $key; + $info['source_text'] = $string; + $info['target_text'] = $string_in_develop; + $info['catch_grammar'] = 1; + $info['revised'] = 0; + + $grammar_case = self::searchRevisedvalue($info); + } + else + { + $grammar_case = '0'; + } + + if ($grammar_case == '0') + { + $developdata['text_changes']['amount']++; + $developdata['text_changes']['keys'][] = $key; + $developdata['text_changes']['ref_in_dev'][$key] = $develop_sections['keys'][$key]; + $developdata['text_changes']['ref'][$key] = $string; + $developdata['text_changes']['diff'][$key] = $text_changes; + } + } + } + } + + return $developdata; + } + + return array(); + } + + /** + * Gets the develop path if exists + * + * @param string $client The client + * @param string $refpath The data to the reference path + * + * @return string + * + * @since 4.11 + */ + public static function searchDevpath($client = '', $refpath = '') + { + $params = JComponentHelper::getParams('com_localise'); + $ref_tag = $params->get('reference', 'en-GB'); + $allow_develop = $params->get('gh_allow_develop', 0); + + $develop_client_path = JPATH_ROOT + . '/media/com_localise/develop/github/joomla-cms/en-GB/' + . $client; + + $ref_file = basename($refpath); + $develop_file_path = JFolder::makeSafe("$develop_client_path/$ref_file"); + + if (JFile::exists($develop_file_path) && $allow_develop == 1 && $ref_tag == 'en-GB') + { + $devpath = $develop_file_path; + } + else + { + $devpath = ''; + } + + return $devpath; + } + + /** + * Gets the customised source path if exists + * + * @param string $client The client + * @param string $refpath The data to the reference path + * + * @return string + * + * @since 4.11 + */ + public static function searchCustompath($client = '', $refpath = '') + { + $params = JComponentHelper::getParams('com_localise'); + $ref_tag = $params->get('reference', 'en-GB'); + $allow_develop = $params->get('gh_allow_develop', 0); + $customisedref = $params->get('customisedref', '0'); + $custom_client_path = JPATH_ROOT + . '/media/com_localise/customisedref/github/' + . $client + . '/' + . $customisedref; + + $ref_file = basename($refpath); + $custom_file_path = JFolder::makeSafe("$custom_client_path/$ref_file"); + + if (JFile::exists($custom_file_path) && $allow_develop == 1 && $ref_tag == 'en-GB' && $customisedref != 0) + { + $custom_path = $custom_file_path; + } + else + { + $custom_path = ''; + } + + return $custom_path; + } + + /** + * Allow combine the reference versions to obtain a right result editing in raw mode or saving source reference files + * When development is enabled. + * + * @param string $refpath The data to the reference path + * + * @param string $devpath The data to the develop path + * + * @return string + * + * @since 4.11 + */ + public static function combineReferences($refpath = '', $devpath = '') + { + $params = JComponentHelper::getParams('com_localise'); + $ref_tag = $params->get('reference', 'en-GB'); + $allow_develop = $params->get('gh_allow_develop', 0); + $combined_content = ''; + + if (JFile::exists($devpath) && JFile::exists($refpath) && $allow_develop == 1 && $ref_tag == 'en-GB') + { + $ref_sections = self::parseSections($refpath); + $keys_in_reference = array_keys($ref_sections['keys']); + + $stream = new JStream; + $stream->open($devpath); + $stream->seek(0); + + while (!$stream->eof()) + { + $line = $stream->gets(); + + if (preg_match('/^([A-Z][A-Z0-9_\*\-\.]*)\s*=/', $line, $matches)) + { + $key = $matches[1]; + + if (in_array($key, $keys_in_reference)) + { + $string = $ref_sections['keys'][$key]; + $combined_content .= $key . '="' . str_replace('"', '"_QQ_"', $string) . "\"\n"; + } + else + { + $combined_content .= $line; + } + } + else + { + $combined_content .= $line; + } + } + + $stream->close(); + } + + return $combined_content; + } + + /** + * Gets the list of ini files + * + * @param string $client_path The data to the client path + * + * @return array + * + * @since 4.11 + */ + public static function getInifileslist($client_path = '') + { + if (!empty($client_path)) + { + $files = JFolder::files($client_path, ".ini$"); + + return $files; + } + + return array(); + } + + /** + * Gets the list of all type of files in develop + * + * @param string $develop_client_path The data to the client path + * + * @return array + * + * @since 4.11 + */ + public static function getLanguagefileslist($develop_client_path = '') + { + if (!empty($develop_client_path)) + { + $files = JFolder::files($develop_client_path); + + return $files; + } + + return array(); + } + + /** + * Gets the stored SHA id for the files in develop. + * + * @param array $gh_data The required data. + * + * @return array + * + * @since 4.11 + */ + public static function getShafileslist($gh_data = array()) + { + $sha_files = array(); + $gh_client = $gh_data['github_client']; + $sha_path = JFolder::makeSafe(JPATH_COMPONENT_ADMINISTRATOR . '/develop/gh_joomla_' . $gh_client . '_files.txt'); + + if (JFile::exists($sha_path)) + { + $file_contents = file_get_contents($sha_path); + $lines = preg_split("/\\r\\n|\\r|\\n/", $file_contents); + + if (!empty($lines)) + { + foreach ($lines as $line) + { + if (!empty($line)) + { + list($filename, $sha) = explode('::', $line, 2); + + if (!empty($filename) && !empty($sha)) + { + $sha_files[$filename] = $sha; + } + } + } + } + } + + return $sha_files; + } + + /** + * Save the date of the last Github files update by client. + * + * @param string $client_to_update The client language files. + * + * @return bolean + * + * @since 4.11 + */ + public static function saveLastupdate($client_to_update) + { + $now = new JDate; + $now = $now->toSQL(); + $params = JComponentHelper::getParams('com_localise'); + $params->set($client_to_update, $now); + + $localise_id = JComponentHelper::getComponent('com_localise')->id; + + $table = JTable::getInstance('extension'); + $table->load($localise_id); + $table->bind(array('params' => $params->toString())); + + if (!$table->check()) + { + JFactory::getApplication()->enqueueMessage($table->getError(), 'warning'); + + return false; + } + + if (!$table->store()) + { + JFactory::getApplication()->enqueueMessage($table->getError(), 'warning'); + + return false; + } + + return true; + } + + /** + * Forces to save the customised source version to use. Option '0' returns to local installed instance. + * + * @param string $option The option value to save. + * + * @return bolean + * + * @since 4.11 + */ + public static function setCustomisedsource($option = '0') + { + $params = JComponentHelper::getParams('com_localise'); + $params->set('customisedref', $option); + + $localise_id = JComponentHelper::getComponent('com_localise')->id; + + $table = JTable::getInstance('extension'); + $table->load($localise_id); + $table->bind(array('params' => $params->toString())); + + if (!$table->check()) + { + JFactory::getApplication()->enqueueMessage($table->getError(), 'warning'); + + return false; + } + + if (!$table->store()) + { + JFactory::getApplication()->enqueueMessage($table->getError(), 'warning'); + + return false; + } + + return true; + } + + /** + * Load revised changes + * + * @param array $data The required data. + * + * @return array + * + * @since 4.11 + */ + public static function searchRevisedvalue($data) + { + $client = $data['client']; + $reftag = $data['reftag']; + $tag = $data['tag']; + $filename = $data['filename']; + $revised = $data['revised']; + $key = $data['key']; + $target_text = $data['target_text']; + $source_text = $data['source_text']; + $istranslation = $data['istranslation']; + $catch_grammar = $data['catch_grammar']; + + if (!empty($client) && !empty($reftag) && !empty($tag) && !empty($filename)) + { + try + { + $db = JFactory::getDbo(); + $query = $db->getQuery(true); + + $search_client = $db->quote($client); + $search_reftag = $db->quote($reftag); + $search_tag = $db->quote($tag); + $search_filename = $db->quote($filename); + $search_key = $db->quote($key); + $search_target_text = $db->quote($target_text); + $search_source_text = $db->quote($source_text); + + $query->select( + array ( + $db->quoteName('revised') + ) + ); + $query->from( + $db->quoteName('#__localise_revised_values') + ); + $query->where( + $db->quoteName('client') . '= ' . $search_client + ); + $query->where( + $db->quoteName('reftag') . '= ' . $search_reftag + + ); + $query->where( + $db->quoteName('tag') . '= ' . $search_tag + + ); + $query->where( + $db->quoteName('filename') . '= ' . $search_filename + ); + $query->where( + $db->quoteName('key') . '= ' . $search_key + ); + $query->where( + $db->quoteName('target_text') . '= ' . $search_target_text + ); + $query->where( + $db->quoteName('source_text') . '= ' . $search_source_text + ); + + $db->setQuery($query); + + if (!$db->query()) + { + throw new Exception($db->getErrorMsg()); + } + } + + catch (JException $e) + { + JFactory::getApplication()->enqueueMessage(JText::_('COM_LOCALISE_ERROR_SEARCHING_REVISED_VALUES'), 'warning'); + + return null; + } + + $result = $db->loadResult(); + + if (!is_null($result)) + { + return (int) $result; + } + elseif ($catch_grammar == '1') + { + return '0'; + } + else + { + if (self::saveRevisedvalue($data)) + { + return (int) $revised; + } + else + { + return null; + } + } + } + + return null; + } + + /** + * Update revised changes + * + * @param array $data The required data. + * + * @return array + * + * @since 4.11 + */ + public static function updateRevisedvalue($data) + { + $client = $data['client']; + $reftag = $data['reftag']; + $tag = $data['tag']; + $filename = $data['filename']; + $revised = $data['revised']; + $key = $data['key']; + $target_text = $data['target_text']; + $source_text = $data['source_text']; + + if (!empty($client) && !empty($reftag) && !empty($tag) && !empty($filename)) + { + try + { + $db = JFactory::getDbo(); + + $updated_client = $db->quote($client); + $updated_reftag = $db->quote($reftag); + $updated_tag = $db->quote($tag); + $updated_filename = $db->quote($filename); + $updated_revised = $db->quote($revised); + $updated_key = $db->quote($key); + $updated_target_text = $db->quote($target_text); + $updated_source_text = $db->quote($source_text); + + $query = $db->getQuery(true); + + $fields = array( + $db->quoteName('revised') . ' = ' . $updated_revised + ); + + $conditions = array( + $db->quoteName('client') . ' = ' . $updated_client, + $db->quoteName('reftag') . ' = ' . $updated_reftag, + $db->quoteName('tag') . ' = ' . $updated_tag, + $db->quoteName('filename') . ' = ' . $updated_filename, + $db->quoteName('key') . ' = ' . $updated_key, + $db->quoteName('target_text') . ' = ' . $updated_target_text, + $db->quoteName('source_text') . ' = ' . $updated_source_text + ); + + $query->update($db->quoteName('#__localise_revised_values'))->set($fields)->where($conditions); + + $db->setQuery($query); + $db->execute(); + } + + catch (JException $e) + { + JFactory::getApplication()->enqueueMessage(JText::_('COM_LOCALISE_ERROR_UPDATING_REVISED_VALUES'), 'warning'); + + return false; + } + + return true; + } + + return false; + } + + /** + * Save revised changes + * + * @param array $data The required data. + * + * @return array + * + * @since 4.11 + */ + public static function saveRevisedvalue($data) + { + $client = $data['client']; + $reftag = $data['reftag']; + $tag = $data['tag']; + $filename = $data['filename']; + $revised = $data['revised']; + $key = $data['key']; + $target_text = $data['target_text']; + $source_text = $data['source_text']; + + if (!empty($client) && !empty($reftag) && !empty($tag) && !empty($filename)) + { + try + { + $db = JFactory::getDbo(); + + $saved_client = $db->quote($client); + $saved_reftag = $db->quote($reftag); + $saved_tag = $db->quote($tag); + $saved_filename = $db->quote($filename); + $saved_revised = $db->quote($revised); + $saved_key = $db->quote($key); + $saved_target_text = $db->quote($target_text); + $saved_source_text = $db->quote($source_text); + + $query = $db->getQuery(true); + + $columns = array('client', 'reftag', 'tag', 'filename', 'revised', 'key', 'target_text', 'source_text'); + + $values = array($saved_client, $saved_reftag, $saved_tag, $saved_filename, $saved_revised, $saved_key, $saved_target_text, $saved_source_text); + + $query + ->insert($db->quoteName('#__localise_revised_values')) + ->columns($db->quoteName($columns)) + ->values(implode(',', $values)); + + $db->setQuery($query); + $db->execute(); + } + + catch (JException $e) + { + JFactory::getApplication()->enqueueMessage(JText::_('COM_LOCALISE_ERROR_SAVING_REVISED_VALUES'), 'warning'); + + return false; + } + + return true; + } + + return false; + } + + /** + * Create the required folders for develop + * + * @param array $gh_data Array with the data + * @param string $index If true, allow to create an index.html file + * + * @return bolean + * + * @since 4.11 + */ + public static function createFolder($gh_data = array(), $index = 'true') + { + $source_ref = $gh_data['customisedref']; + + if (!empty($gh_data) && isset($source_ref)) + { + $full_path = JPATH_ROOT . '/media/com_localise/customisedref/github/' + . $gh_data['github_client'] + . '/' + . $source_ref; + + $full_path = JFolder::makeSafe($full_path); + + if (!JFolder::create($full_path)) + { + } + + if (JFolder::exists($full_path)) + { + if ($index == 'true') + { + $cretate_index = self::createIndex($full_path); + + if ($cretate_index == 1) + { + return true; + } + + JFactory::getApplication()->enqueueMessage(JText::_('COM_LOCALISE_ERROR_GITHUB_UNABLE_TO_CREATE_INDEX_FILE'), 'warning'); + + return false; + } + + return true; + } + else + { + JFactory::getApplication()->enqueueMessage(JText::_('COM_LOCALISE_ERROR_GITHUB_UNABLE_TO_CREATE_FOLDERS'), 'warning'); + + return false; + } + } + + return false; + } + + /** + * Creates an index.html file within folders for develop + * + * @param string $full_path The full path. + * + * @return bolean + * + * @since 4.11 + */ + public static function createIndex($full_path = '') + { + if (!empty($full_path)) + { + $path = JFolder::makeSafe($full_path . '/index.html'); + + $index_content = ''; + + if (!JFile::exists($path)) + { + JFile::write($path, $index_content); + } + + if (!JFile::exists($path)) + { + return false; + } + else + { + return true; + } + } + + return false; + } + + /** + * Gets the text changes. + * + * @param array $old The string parts in reference. + * @param array $new The string parts in develop. + * + * @return array + * + * @since 4.11 + */ + public static function getTextchanges($old, $new) + { + $maxlen = 0; + + foreach ($old as $oindex => $ovalue) + { + $nkeys = array_keys($new, $ovalue); + + foreach ($nkeys as $nindex) + { + $matrix[$oindex][$nindex] = isset($matrix[$oindex - 1][$nindex - 1]) ? $matrix[$oindex - 1][$nindex - 1] + 1 : 1; + + if ($matrix[$oindex][$nindex] > $maxlen) + { + $maxlen = $matrix[$oindex][$nindex]; + $omax = $oindex + 1 - $maxlen; + $nmax = $nindex + 1 - $maxlen; + } + + unset ($nkeys, $nindex); + } + + unset ($oindex, $ovalue); + } + + if ($maxlen == 0) + { + return array(array ('d' => $old, 'i' => $new)); + } + + return array_merge( + self::getTextchanges( + array_slice($old, 0, $omax), + array_slice($new, 0, $nmax) + ), + array_slice($new, $nmax, $maxlen), + self::getTextchanges( + array_slice($old, $omax + $maxlen), + array_slice($new, $nmax + $maxlen) + ) + ); + } + + /** + * Gets the html text changes. + * + * @param string $old The string in reference. + * @param string $new The string in develop. + * + * @return string + * + * @since 4.11 + */ + public static function htmlgetTextchanges($old, $new) + { + $text_changes = ''; + + if ($old == $new) + { + return $text_changes; + } + + $old = str_replace(' ', 'LOCALISEDOUBLESPACES', $old); + $new = str_replace(' ', 'LOCALISEDOUBLESPACES', $new); + + $diff = self::getTextchanges(explode(' ', $old), explode(' ', $new)); + + foreach ($diff as $k) + { + if (is_array($k)) + { + $text_changes .= (!empty ($k['d'])?"LOCALISEDELSTART" + . implode(' ', $k['d']) . "LOCALISEDELSTOP ":'') + . (!empty($k['i']) ? "LOCALISEINSSTART" + . implode(' ', $k['i']) + . "LOCALISEINSSTOP " : ''); + } + else + { + $text_changes .= $k . ' '; + } + + unset ($k); + } + + $text_changes = htmlspecialchars($text_changes); + $text_changes = preg_replace('/LOCALISEINSSTART/', "", $text_changes); + $text_changes = preg_replace('/LOCALISEINSSTOP/', "", $text_changes); + $text_changes = preg_replace('/LOCALISEDELSTART/', "", $text_changes); + $text_changes = preg_replace('/LOCALISEDELSTOP/', "", $text_changes); + $double_spaces = 'XX'; + $text_changes = str_replace('LOCALISEDOUBLESPACES', $double_spaces, $text_changes); + + return $text_changes; + } } diff --git a/component/admin/language/en-GB/en-GB.com_localise.ini b/component/admin/language/en-GB/en-GB.com_localise.ini index 52753e6f..e0edf42c 100644 --- a/component/admin/language/en-GB/en-GB.com_localise.ini +++ b/component/admin/language/en-GB/en-GB.com_localise.ini @@ -280,7 +280,7 @@ COM_LOCALISE_TOOLTIP_TRANSLATIONS_ADDITIONAL_COPYRIGHT="Additional copyright::%s COM_LOCALISE_TOOLTIP_TRANSLATIONS_CLIENT_ADMINISTRATOR="Administrator translation" COM_LOCALISE_TOOLTIP_TRANSLATIONS_CLIENT_INSTALLATION="Installation translation" COM_LOCALISE_TOOLTIP_TRANSLATIONS_CLIENT_SITE="Site translation" -COM_LOCALISE_TOOLTIP_TRANSLATIONS_COMPLETE="Translation complete::%2$s unchanged
%3$s total
%4$s extra" +COM_LOCALISE_TOOLTIP_TRANSLATIONS_COMPLETE="Translation complete::
%1$s translated
%2$s unchanged
%3$s total
%4$s extra" COM_LOCALISE_TOOLTIP_TRANSLATIONS_EDIT="Edit translation" COM_LOCALISE_TOOLTIP_TRANSLATIONS_EDITRAW="Edit translation using a text editor" COM_LOCALISE_TOOLTIP_TRANSLATIONS_ERROR="Error::In file %1$s, lines %2$s" @@ -475,3 +475,84 @@ COM_LOCALISE_ERROR_EXPORT_ADAPTER="Error loading zip adapter" COM_LOCALISE_ERROR_EXPORT_ZIPCREATE="Error creating zip" COM_LOCALISE_ERROR_EXPORT_ZIPDELETE="Error deleting old zip files" COM_LOCALISE_NOTICE_EXPORT_READONLY="Package %s is readonly. You cannot export it." + +[Develop] + +COM_LOCALISE_CUSTOMIZED_REFERENCE="Joomla %s" +COM_LOCALISE_DAILY="Daily" +COM_LOCALISE_ERROR_GETTING_ALLOWED_REFERENCE_TAG="WARNING! Fetching the target en-GB reference language from the Joomla Github repository has been disabled. The feature will only work if the Reference language is set to 'English (en-GB)' in 'Localise' => 'Options'=> Global configuration tab and 'Enable development reference language' is configured to 'Yes' from 'Localise' => 'Options'=> 'en-GB reference language and development' tab." +COM_LOCALISE_ERROR_GETTING_UNALLOWED_CONFIGURATION="WARNING! Fetching the source en-GB reference language from the Joomla Github repository has been disabled. The feature will only work if the Reference language is set to 'English (en-GB)' in 'Localise' => 'Options'=> Global configuration tab and 'Enable development reference language' is configured to 'Yes' from 'Localise' => 'Options'=> 'en-GB reference language and development' tab." +COM_LOCALISE_ERROR_GITHUB_FILE_TO_DELETE_IS_PRESENT="After try to delete the file %s due is not required in develop yet, the file is still present. It have required solve the issue before continue getting files from Github." +COM_LOCALISE_ERROR_GITHUB_GETTING_LOCAL_INSTALLED_FILES="!WARNING: You can only use the local installed instance of language files as source reference.
The program can not found the Joomla %s release to get the language files from Github, and the ability to use other sets of language files as source reference now has been disabled (it is a required protection mode case).
Please, considere use a stable and already released Joomla's package." +COM_LOCALISE_ERROR_GITHUB_GETTING_RELEASES="Joomla can't connect with Github repository to get the last releases list. The already stored ones are used and maybe not be up-to-date with the last version." +COM_LOCALISE_ERROR_GITHUB_GETTING_REPOSITORY_FILES="Joomla can't connect with Github repository. Note that if it was working previously an obsolete Github token may be the main cause for the crash." +COM_LOCALISE_ERROR_GITHUB_NO_CLIENT_FOLDER_PRESENT="Joomla can't find the 'develop' directories to store the reference language files." +COM_LOCALISE_ERROR_GITHUB_NO_DATA_PRESENT="No Github data present." +COM_LOCALISE_ERROR_GITHUB_NO_SHA_FILE_PRESENT="Joomla can't find the file storing the SHA ID for language files in develop." +COM_LOCALISE_ERROR_GITHUB_UNABLE_TO_CREATE_DEV_FILE="Joomla can't create the reference language files in the 'develop' directory." +COM_LOCALISE_ERROR_GITHUB_UNABLE_TO_CREATE_NEW_FILES="Joomla can't add new language files from development to the language directory." +COM_LOCALISE_ERROR_GITHUB_UNABLE_TO_GET_A_FULL_SET="Localise is unable to get a full set of language files for this client from the selected target branch (%s). It will try to complete the download during next update." +COM_LOCALISE_ERROR_GITHUB_UNABLE_TO_GET_A_FULL_SOURCE_SET="Localise is unable to get a full set of language files for this client from the selected source version (%s). It will try to complete the download during next update." +COM_LOCALISE_ERROR_GITHUB_UNABLE_TO_UPDATE_SOURCE_FILES="The program can not update files with an empty or incomplete source reference." +COM_LOCALISE_ERROR_GITHUB_UNABLE_TO_UPDATE_TARGET_FILES="The program can not update files with an empty or incomplete target reference." +COM_LOCALISE_ERROR_SAVING_FILES_AT_CORE_FOLDER="The program have found %s issues writing Github files to the core language folder." +COM_LOCALISE_GITHUB_FILE_NOT_PRESENT_IN_DEV_YET="The target and stored en-GB reference file %s has been deleted because it is not longer used in the development branch." +COM_LOCALISE_HOURLY="Hourly" +COM_LOCALISE_LABEL_CUSTOMIZED_REF="en-GB - Source files" +COM_LOCALISE_LABEL_CUSTOMIZED_REF_DESC="You can use as source reference the en-GB language files of your Joomla installation or any other set to choose from the list. Default is 'Local installed instance'." +COM_LOCALISE_LABEL_GITHUB_ADMINISTRATOR_LAST_UPDATE="Last update - Administrator" +COM_LOCALISE_LABEL_GITHUB_ADMINISTRATOR_LAST_UPDATE_DESC="The last time administrator language files have been updated from Github to get the target en-GB reference." +COM_LOCALISE_LABEL_GITHUB_ALLOW_DEVELOP="Enable development reference language" +COM_LOCALISE_LABEL_GITHUB_ALLOW_DEVELOP_DESC="If enabled, the target en-GB reference will be fetched from Joomla Github repository. Else, the next configurable fields will be ignored." +COM_LOCALISE_LABEL_GITHUB_BRANCH="en-GB - Target files" +COM_LOCALISE_LABEL_GITHUB_BRANCH_DESC="The branch or trunk of the Joomla's repository from where you want to get the target en-GB reference language files. Default is 'master'." +COM_LOCALISE_LABEL_GITHUB_DEVELOP_TAB="en-GB reference language and development" +COM_LOCALISE_LABEL_GITHUB_DEVELOP_TAB_DESC="Important!
This feature lets fetch the en-GB reference language from the Joomla Github repository.
It allows to deal with strings modified values and not only new strings.
It will only work when 'Reference language' is set to 'English (en-GB)' in the 'Global configuration' tab.
It only handles 'en-GB' core language files." +COM_LOCALISE_LABEL_GITHUB_INSTALLATION_LAST_UPDATE="Last update - Installation" +COM_LOCALISE_LABEL_GITHUB_INSTALLATION_LAST_UPDATE_DESC="The last time installation language file has been updated from Github to get the target en-GB reference." +COM_LOCALISE_LABEL_GITHUB_SITE_LAST_UPDATE="Last update - Site" +COM_LOCALISE_LABEL_GITHUB_SITE_LAST_UPDATE_DESC="The last time site language files have been updated from Github to get the target en-GB reference." +COM_LOCALISE_LABEL_GITHUB_TOKEN="Github Token *" +COM_LOCALISE_LABEL_GITHUB_TOKEN_DESC="If left empty, a shared token will be used by default. It is rather suggested that you uses your own. Getting tokens requires a Github account. Create it from 'Personal settings' => 'Personal access tokens' and copy/paste in this field." +COM_LOCALISE_LABEL_GITHUB_UPDATES_INTERVAL="Updates interval" +COM_LOCALISE_LABEL_GITHUB_UPDATES_INTERVAL_DESC="The required time before updating again the target en-GB reference language from Jomla Github repository." +COM_LOCALISE_LOCAL_INSTALLED_INSTANCE="Local installed instance" +COM_LOCALISE_NEW_KEY_IN_DEVELOP="NEW!" +COM_LOCALISE_NOTICE_CUSTOM_EN_GB_FILE_SAVED="The en-GB reference file has been saved within this customised folder: " +COM_LOCALISE_NOTICE_DISABLED_ALLOW_DEVELOP_WITHOUT_LOCAL_SET="The language files comparison is done between %1$s and the Local installed instance (%2$s) in the %3$s client as 'Enable development reference language' is disabled." +COM_LOCALISE_NOTICE_EDIT_REFERENCE_HAS_LIMITED_USE="Edit en-GB reference files with 'development reference language' enabled has a limited use.
Now you are editing language files coming from the Joomla %s version.
Note that in this case the strings changes are not stored at core language folders due are using an specific location for each customised version." +COM_LOCALISE_NOTICE_GITHUB_GETS_A_SOURCE_FULL_SET="The source reference en-GB core files from the '%s' branch have been updated for this client." +COM_LOCALISE_NOTICE_GITHUB_GETS_A_TARGET_FULL_SET="The target reference en-GB core files from the '%s' branch have been updated for this client." +COM_LOCALISE_NOTICE_NEW_VERSION_DETECTED="Joomla %s has been added to the 'Source en-GB reference' field list." +COM_LOCALISE_OLD_FILE_DELETED="The en-GB reference file %s has been deleted as it is not longer used in next Joomla releases." +COM_LOCALISE_OPTION_TRANSLATIONS_DEVELOP_SELECT="- Select Content State -" +COM_LOCALISE_OPTION_TRANSLATIONS_DEVELOP_INCOMPLETE="Incomplete" +COM_LOCALISE_OPTION_TRANSLATIONS_DEVELOP_COMPLETE="Complete" +COM_LOCALISE_REFERENCES_REPORT_CLIENT="%1$s client is using the %2$s Joomla language files as baseline." +COM_LOCALISE_REFERENCES_REPORT_CUSTOM="Please, note that there are clients using a customized version matching your actual Joomla version:" +COM_LOCALISE_REFERENCES_REPORT_CUSTOM_NOTE="The client %s is using customized en-GB baseline reference files as source." +COM_LOCALISE_REFERENCES_REPORT_EQUAL="All clients are using the same reference language files version." +COM_LOCALISE_REFERENCES_REPORT_INSTALLED="You are working on Joomla %s version." +COM_LOCALISE_REFERENCES_REPORT_MATCH_NOTE=" It matches your Joomla version." +COM_LOCALISE_REFERENCES_REPORT_NEVER_UPDATED="The reference files for the %s client have never been updated." +COM_LOCALISE_REFERENCES_REPORT_NOT_EQUAL="Please, note that the clients are not using the same reference language files version:" +COM_LOCALISE_REFERENCES_REPORT_SOURCE="Source reference" +COM_LOCALISE_REFERENCES_REPORT_TARGET="Target reference" +COM_LOCALISE_REFERENCES_REPORT_TARGET_REFERENCE="The detected modified values or new keys are fetched from the target language files within the %s branch from the Joomla Github repository." +COM_LOCALISE_REFERENCES_REPORT_UPDATED="The reference files for the %1$s client have been updated on %2$s." +COM_LOCALISE_REFERENCES_REPORT_VERSION_NOTE="The client %1$s is using %2$s en-GB baseline reference files as source." +COM_LOCALISE_REFERENCES_REPORT_NO_DEVELOP="As "_QQ_"Enable development reference language"_QQ_" is disabled, the new keys or modified values will not be fetched from the Joomla Github repository branches.
The new keys will be fetched from the Reference installed language." +COM_LOCALISE_SLIDER_TRANSLATIONS_REFERENCES="en-GB reference versions info" +COM_LOCALISE_SOURCE_SPACER_LABEL="Source en-GB reference
* Choose the Joomla's package version to use as baseline." +COM_LOCALISE_TARGET_SPACER_LABEL="Target en-GB reference
* Choose the Joomla's branch from which to obtain the difference." +COM_LOCALISE_TEXT_TRANSLATION_TEXTCHANGED="Modified values" +COM_LOCALISE_TOOLTIP_GITHUB_CASE_1="The file has new strings or detected modified values from Github.
Translated %1$s of %2$s new strings
Revised %3$s of %4$s Modified values" +COM_LOCALISE_TOOLTIP_GITHUB_CASE_1_EN_GB="The file has new strings or detected modified values from Github.
%1$s new strings
%2$s Grammar cases of %3$s Modified values" +COM_LOCALISE_TOOLTIP_GITHUB_CASE_2="The file has new strings or detected modified values from Github.
0 new strings
Revised %1$s of %2$s Modified values" +COM_LOCALISE_TOOLTIP_GITHUB_CASE_2_EN_GB="The file has new strings or detected modified values from Github.
0 new strings
%1$s Grammar cases of %2$s Modified values" +COM_LOCALISE_TOOLTIP_GITHUB_CASE_3="The file has new strings or detected modified values from Github.
Translated %1$s of %2$s new strings
0 Modified values" +COM_LOCALISE_TOOLTIP_GITHUB_CASE_3_EN_GB="The file has new strings or detected modified values from Github.
%1$s new strings
0 Modified values" +COM_LOCALISE_TOOLTIP_TRANSLATIONS_COMPLETE_WITH_DEVELOP="Translation complete::%2$s unchanged
%3$s new strings
%4$s Modified values
%5$s total
%6$s extra" +COM_LOCALISE_TOOLTIP_TRANSLATIONS_INPROGRESS_WITH_DEVELOP="Translation in progress
%1$s translated
%2$s unchanged
%3$s new strings
%4$s Modified values
%5$s total
%6$s extra" +COM_LOCALISE_WARNING_DISABLED_ALLOW_DEVELOP_WITHOUT_LOCAL_SET="Note that the client %1$s is using a version of language files ('%2$s') different from the local installed instance ('%3$s') with 'Enable development reference language' disabled. Please, if you wanna continue with the feature disabled is suggested choose this client from the 'Location' filter to solve the issue." +COM_LOCALISE_WRONG_LINE_CONTENT="Detected a parsing error within this file. The line %1$s has not been added to the language file." diff --git a/component/admin/models/fields/develop.php b/component/admin/models/fields/develop.php new file mode 100644 index 00000000..3de0833f --- /dev/null +++ b/component/admin/models/fields/develop.php @@ -0,0 +1,62 @@ +element['onchange']) + { + $attributes .= ' onchange="' . $v . '"'; + } + + $attributes .= ' class="' . (string) $this->element['class'] . ' iconlist-16-' . $this->value . '"'; + $options = array(); + + foreach ($this->element->children() as $option) + { + $options[] = JHtml::_('select.option', $option->attributes('value'), JText::_(trim($option)), array('option.attr' => 'attributes', 'attr' => '')); + } + + $options[] = JHtml::_('select.option', 'complete', JText::sprintf('COM_LOCALISE_OPTION_TRANSLATIONS_DEVELOP_COMPLETE'), + array('option.attr' => 'attributes', 'attr' => 'class="iconlist-16-equal"') + ); + $options[] = JHtml::_('select.option', 'incomplete', JText::sprintf('COM_LOCALISE_OPTION_TRANSLATIONS_DEVELOP_INCOMPLETE'), + array('option.attr' => 'attributes', 'attr' => 'class="iconlist-16-changed"') + ); + + return $options; + } +} diff --git a/component/admin/models/fields/key.php b/component/admin/models/fields/key.php index 6b77cc81..15e764ad 100644 --- a/component/admin/models/fields/key.php +++ b/component/admin/models/fields/key.php @@ -43,9 +43,97 @@ class JFormFieldKey extends JFormField */ protected function getLabel() { - return ''; + $istranslation = (int) $this->element['istranslation']; + $status = (string) $this->element['status']; + $istextchange = (int) $this->element['istextchange']; + + if ($istextchange == '1') + { + $textchange_status = (int) $this->element['changestatus']; + $textchange_source = (string) $this->element['sourcetext']; + $textchange_target = (string) $this->element['targettext']; + $textchange_visible_id = "textchange_visible_id_" . $this->element['name']; + $textchange_hidded_id = "textchange_hidded_id_" . $this->element['name']; + $textchange_source_id = "textchange_source_id_" . $this->element['name']; + $textchange_target_id = "textchange_target_id_" . $this->element['name']; + + if ($textchange_status == '1') + { + $textchange_checked = ' checked="checked" '; + } + else + { + $textchange_checked = ''; + } + + $textchanges_onclick = "javascript:document.id( + '" . $textchange_hidded_id . "' + ) + .set( + 'value', document.getElementById('" . $textchange_visible_id . "' ).checked + );"; + + if ($istranslation == '1') + { + $title = JText::_('COM_LOCALISE_REVISED'); + } + else + { + $title = 'Grammar case'; + } + + $textchanges_checkbox = ''; + $textchanges_checkbox .= '
' . $title . 'element['name']; + $textchanges_checkbox .= '" title="' . $title . '" onclick="'; + $textchanges_checkbox .= $textchanges_onclick; + $textchanges_checkbox .= '" '; + $textchanges_checkbox .= $textchange_checked; + $textchanges_checkbox .= '>
'; + $textchanges_checkbox .= ''; + $textchanges_checkbox .= ''; + $textchanges_checkbox .= ''; + + $return = ''; + + $return .= '
'; + + return $return; + } + else + { + return ''; + } } /** @@ -56,81 +144,202 @@ protected function getLabel() protected function getInput() { // Set the class for the label. - $class = !empty($this->descText) ? 'key-label hasTooltip fltrt' : 'key-label fltrt'; + $class = !empty($this->descText) ? 'key-label hasTooltip fltrt' : 'key-label fltrt'; + $istranslation = (int) $this->element['istranslation']; + $istextchange = (int) $this->element['istextchange']; + $isextraindev = (int) $this->element['isextraindev']; + $status = (string) $this->element['status']; - // If a description is specified, use it to build a tooltip. - if (!empty($this->descText)) - { - $label = '
diff --git a/component/admin/models/forms/translations.xml b/component/admin/models/forms/translations.xml index 87e2e27b..23a4aac2 100644 --- a/component/admin/models/forms/translations.xml +++ b/component/admin/models/forms/translations.xml @@ -67,6 +67,15 @@ onchange="this.form.submit()"> +
diff --git a/component/admin/models/package.php b/component/admin/models/package.php index 7de99af4..3bd3f2fb 100644 --- a/component/admin/models/package.php +++ b/component/admin/models/package.php @@ -207,7 +207,7 @@ public function getItem($pk = null) $package->author = (string) $xml->author; $package->authoremail = (string) $xml->authoremail; $package->authorurl = (string) $xml->authorurl; - $package->url = (string) $xml->url; + $package->url = (string) $xml->url; $package->packager = (string) $xml->packager; $package->packagerurl = (string) $xml->packagerurl; $package->servername = (string) $xml->servername; diff --git a/component/admin/models/translation.php b/component/admin/models/translation.php index b2bb09de..f7a08eff 100644 --- a/component/admin/models/translation.php +++ b/component/admin/models/translation.php @@ -26,8 +26,6 @@ class LocaliseModelTranslation extends JModelAdmin protected $contents; - protected $filter_fields = array('translatedkeys', 'untranslatedkeys', 'unchangedkeys'); - /** * Method to auto-populate the model state. * @@ -171,13 +169,32 @@ public function getItem($pk = null) ? $this->getState('translation.path') : $this->getState('translation.refpath'); + $params = JComponentHelper::getParams('com_localise'); + $allow_develop = $params->get('gh_allow_develop', 0); + $gh_client = $this->getState('translation.client'); + $tag = $this->getState('translation.tag'); + $reftag = $this->getState('translation.reference'); + $refpath = $this->getState('translation.refpath'); + $istranslation = 0; + + if (!empty($tag) && $tag != $reftag) + { + $istranslation = 1; + } + $this->setState('translation.translatedkeys', array()); $this->setState('translation.untranslatedkeys', array()); $this->setState('translation.unchangedkeys', array()); + $this->setState('translation.textchangedkeys', array()); + $this->setState('translation.revisedchanges', array()); + $this->setState('translation.developdata', array()); $translatedkeys = $this->getState('translation.translatedkeys'); $untranslatedkeys = $this->getState('translation.untranslatedkeys'); $unchangedkeys = $this->getState('translation.unchangedkeys'); + $textchangedkeys = $this->getState('translation.textchangedkeys'); + $revisedchanges = $this->getState('translation.revisedchanges'); + $developdata = $this->getState('translation.developdata'); $this->item = new JObject( array @@ -193,10 +210,18 @@ public function getItem($pk = null) 'additionalcopyright' => array(), 'license' => '', 'exists' => JFile::exists($this->getState('translation.path')), + 'istranslation' => $istranslation, + 'developdata' => (array) $developdata, 'translatedkeys' => (array) $translatedkeys, 'untranslatedkeys' => (array) $untranslatedkeys, 'unchangedkeys' => (array) $unchangedkeys, + 'textchangedkeys' => (array) $textchangedkeys, + 'revisedchanges' => (array) $revisedchanges, + 'unrevised' => 0, + 'translatednews' => 0, + 'unchangednews' => 0, 'translated' => 0, + 'untranslated' => 0, 'unchanged' => 0, 'extra' => 0, 'total' => 0, @@ -208,11 +233,32 @@ public function getItem($pk = null) if (JFile::exists($path)) { - $this->item->source = file_get_contents($path); - $stream = new JStream; + $devpath = LocaliseHelper::searchDevpath($gh_client, $refpath); + $custompath = LocaliseHelper::searchCustompath($gh_client, $refpath); + + if ($istranslation == 0 && $reftag == 'en-GB') + { + if (!empty($devpath)) + { + if (!empty($custompath)) + { + $this->item->source = LocaliseHelper::combineReferences($custompath, $devpath); + } + else + { + $this->item->source = LocaliseHelper::combineReferences($path, $devpath); + } + } + } + else + { + $this->item->source = file_get_contents($path); + } + + $stream = new JStream; $stream->open($path); - $begin = $stream->read(4); - $bom = strtolower(bin2hex($begin)); + $begin = $stream->read(4); + $bom = strtolower(bin2hex($begin)); if ($bom == '0000feff') { @@ -244,7 +290,6 @@ public function getItem($pk = null) $continue = true; $lineNumber = 0; - $params = JComponentHelper::getParams('com_localise'); $isTranslationsView = JFactory::getApplication()->input->get('view') == 'translations'; while (!$stream->eof()) @@ -403,8 +448,101 @@ public function getItem($pk = null) if ($this->getState('translation.layout') != 'raw' && empty($this->item->error)) { - $sections = LocaliseHelper::parseSections($this->getState('translation.path')); - $refsections = LocaliseHelper::parseSections($this->getState('translation.refpath')); + $sections = LocaliseHelper::parseSections($this->getState('translation.path')); + + if (!empty($custompath)) + { + $refsections = LocaliseHelper::parseSections($custompath); + } + else + { + $refsections = LocaliseHelper::parseSections($this->getState('translation.refpath')); + } + + $develop_client_path = JPATH_ROOT + . '/media/com_localise/develop/github/joomla-cms/en-GB/' + . $gh_client; + $develop_client_path = JFolder::makeSafe($develop_client_path); + $ref_file = basename($this->getState('translation.refpath')); + $develop_file_path = "$develop_client_path/$ref_file"; + $new_keys = array(); + + if (JFile::exists($develop_file_path) && $allow_develop == 1 && $reftag == 'en-GB') + { + $info = array(); + $info['client'] = $gh_client; + $info['reftag'] = 'en-GB'; + $info['tag'] = 'en-GB'; + $info['filename'] = $ref_file; + $info['istranslation'] = $istranslation; + + $develop_sections = LocaliseHelper::parseSections($develop_file_path); + $developdata = LocaliseHelper::getDevelopchanges($info, $refsections, $develop_sections); + $developdata['develop_file_path'] = ''; + + if ($developdata['extra_keys']['amount'] > 0 || $developdata['text_changes']['amount'] > 0) + { + if ($developdata['extra_keys']['amount'] > 0) + { + $new_keys = $developdata['extra_keys']['keys']; + } + + if ($developdata['text_changes']['amount'] > 0) + { + $textchangedkeys = $developdata['text_changes']['keys']; + $this->item->textchangedkeys = $textchangedkeys; + $this->setState('translation.textchangedkeys', $textchangedkeys); + + $changesdata['client'] = $gh_client; + $changesdata['reftag'] = $reftag; + + if ($istranslation == 0) + { + $changesdata['tag'] = $reftag; + } + else + { + $changesdata['tag'] = $tag; + } + + $changesdata['filename'] = $ref_file; + + foreach ($textchangedkeys as $key_changed) + { + $target_text = $developdata['text_changes']['ref_in_dev'][$key_changed]; + $source_text = $developdata['text_changes']['ref'][$key_changed]; + + $changesdata['revised'] = '0'; + $changesdata['key'] = $key_changed; + $changesdata['target_text'] = $target_text; + $changesdata['source_text'] = $source_text; + $changesdata['istranslation'] = $istranslation; + $changesdata['catch_grammar'] = '0'; + + $change_status = LocaliseHelper::searchRevisedvalue($changesdata); + $revisedchanges[$key_changed] = $change_status; + + if ($change_status == 1) + { + $developdata['text_changes']['revised']++; + } + else + { + $developdata['text_changes']['unrevised']++; + } + } + + $this->item->revisedchanges = $revisedchanges; + $this->setState('translation.revisedchanges', $revisedchanges); + } + + // When develop changes are present, replace the reference keys + $refsections = $develop_sections; + + // And store the path for future calls + $developdata['develop_file_path'] = $develop_file_path; + } + } if (!empty($refsections['keys'])) { @@ -414,37 +552,70 @@ public function getItem($pk = null) if (!empty($sections['keys']) && array_key_exists($key, $sections['keys']) && $sections['keys'][$key] != '') { - if ($sections['keys'][$key] != $string) + if ($sections['keys'][$key] != $string && $istranslation == 1) { - $this->item->translated++; - $translatedkeys[] = $key; + if (array_key_exists($key, $revisedchanges) && $revisedchanges[$key] == 0) + { + $this->item->unrevised++; + $translatedkeys[] = $key; + } + elseif (in_array($key, $new_keys)) + { + $this->item->translatednews++; + $translatedkeys[] = $key; + } + else + { + $this->item->translated++; + $translatedkeys[] = $key; + } } - elseif ($this->getState('translation.path') == $this->getState('translation.refpath')) + elseif ($istranslation == 0) { + if (array_key_exists($key, $revisedchanges) && $revisedchanges[$key] == 0) + { + $this->item->unrevised++; + } + elseif (in_array($key, $new_keys)) + { + $untranslatedkeys[] = $key; + } + $this->item->translated++; } else { - $this->item->unchanged++; + if (in_array($key, $new_keys)) + { + $this->item->unchangednews++; + } + else + { + $this->item->unchanged++; + } + $unchangedkeys[] = $key; } } elseif (!array_key_exists($key, $sections['keys'])) { + $this->item->untranslated++; $untranslatedkeys[] = $key; } } } - $this->item->translatedkeys = $translatedkeys; + $this->item->translatedkeys = $translatedkeys; $this->item->untranslatedkeys = $untranslatedkeys; - $this->item->unchangedkeys = $unchangedkeys; + $this->item->unchangedkeys = $unchangedkeys; + $this->item->developdata = $developdata; $this->setState('translation.translatedkeys', $translatedkeys); $this->setState('translation.untranslatedkeys', $untranslatedkeys); $this->setState('translation.unchangedkeys', $unchangedkeys); + $this->setState('translation.developdata', $developdata); - if (!empty($sections['keys'])) + if (!empty($sections['keys']) && $istranslation == 1) { foreach ($sections['keys'] as $key => $string) { @@ -455,11 +626,13 @@ public function getItem($pk = null) } } + $done = $this->item->translated + $this->item->translatednews + $this->item->unchangednews; + $this->item->completed = $this->item->total - ? intval(100 * $this->item->translated / $this->item->total) + $this->item->unchanged / $this->item->total + ? intval(100 * $done / $this->item->total) : 100; - $this->item->complete = $this->item->complete + $this->item->complete = $this->item->complete == 1 && $this->item->untranslated == 0 && $this->item->unrevised == 0 ? 1 : ($this->item->completed == 100 ? 1 @@ -586,6 +759,13 @@ protected function preprocessForm(JForm $form, $item, $group = 'content') $app = JFactory::getApplication(); $false = false; + $have_develop = 0; + $developdata = array(); + $revisedchanges = array(); + $istranslation = ''; + $extras_amount = 0; + $text_changes_amount = 0; + // Compute all known languages static $languages = array(); jimport('joomla.language.language'); @@ -601,22 +781,87 @@ protected function preprocessForm(JForm $form, $item, $group = 'content') $form->setFieldAttribute('legend', 'translated', $item->translated, 'legend'); $form->setFieldAttribute('legend', 'untranslated', $item->total - $item->translated - $item->unchanged, 'legend'); $form->setFieldAttribute('legend', 'extra', $item->extra, 'legend'); + + $developdata = $item->developdata; + $revisedchanges = $item->revisedchanges; + $istranslation = $item->istranslation; } if ($this->getState('translation.layout') != 'raw') { - $path = $this->getState('translation.path'); - $refpath = $this->getState('translation.refpath'); - $sections = LocaliseHelper::parseSections($path); - $refsections = LocaliseHelper::parseSections($refpath); + $this->setState('translation.devpath', ''); + + if (!empty($developdata)) + { + $extras_amount = $developdata['extra_keys']['amount']; + $text_changes_amount = $developdata['text_changes']['amount']; + $refpath = $this->getState('translation.refpath'); + + $custompath = LocaliseHelper::searchCustompath($client, $refpath); + + if ($istranslation == '0') + { + if (!empty($custompath)) + { + $refpath = $custompath; + $path = $refpath; + $refsections = LocaliseHelper::parseSections($refpath); + $sections = $refsections; + } + else + { + $refpath = $this->getState('translation.refpath'); + $path = $refpath; + $refsections = LocaliseHelper::parseSections($refpath); + $sections = $refsections; + } + } + else + { + if (!empty($custompath)) + { + $refpath = $custompath; + $path = $this->getState('translation.path'); + $refsections = LocaliseHelper::parseSections($refpath); + $sections = LocaliseHelper::parseSections($path); + } + else + { + $refpath = $this->getState('translation.refpath'); + $path = $this->getState('translation.path'); + $refsections = LocaliseHelper::parseSections($refpath); + $sections = LocaliseHelper::parseSections($path); + } + } + + if ($extras_amount > 0 || $text_changes_amount > 0) + { + $have_develop = 1; + $develop_file_path = $developdata['develop_file_path']; + $develop_sections = LocaliseHelper::parseSections($develop_file_path); + $oldref = $refsections; + $refsections = $develop_sections; + $refpath = $develop_file_path; + + $this->setState('translation.devpath', $develop_file_path); + } + } + else + { + $path = $this->getState('translation.path'); + $refpath = $this->getState('translation.refpath'); + $sections = LocaliseHelper::parseSections($path); + $refsections = LocaliseHelper::parseSections($refpath); + } + $addform = new SimpleXMLElement('
'); $group = $addform->addChild('fields'); $group->addAttribute('name', 'strings'); $fieldset = $group->addChild('fieldset'); - $fieldset->addAttribute('name', 'Default'); - $fieldset->addAttribute('label', 'Default'); + $fieldset->addAttribute('name', 'JDEFAULT'); + $fieldset->addAttribute('label', 'JDEFAULT'); if (JFile::exists($refpath)) { @@ -670,9 +915,20 @@ protected function preprocessForm(JForm $form, $item, $group = 'content') $header = false; $key = $matches[1]; $field = $fieldset->addChild('field'); - $string = $refsections['keys'][$key]; - $translated = isset($sections['keys'][$key]); - $modified = $translated && $sections['keys'][$key] != $refsections['keys'][$key]; + + if ($have_develop == '1' && $istranslation == '0' && array_key_exists($key, $oldref['keys'])) + { + $string = $oldref['keys'][$key]; + $translated = isset($sections['keys'][$key]); + $modified = $translated && $sections['keys'][$key] != $oldref['keys'][$key]; + } + else + { + $string = $refsections['keys'][$key]; + $translated = isset($sections['keys'][$key]); + $modified = $translated && $sections['keys'][$key] != $refsections['keys'][$key]; + } + $status = $modified ? 'translated' : ($translated @@ -681,7 +937,47 @@ protected function preprocessForm(JForm $form, $item, $group = 'content') $default = $translated ? $sections['keys'][$key] : ''; - $label = '' . $key . '
' . htmlspecialchars($string, ENT_COMPAT, 'UTF-8'); + + $field->addAttribute('istranslation', $istranslation); + $field->addAttribute('istextchange', 0); + $field->addAttribute('isextraindev', 0); + + if ($have_develop == '1' && in_array($key, $developdata['text_changes']['keys'])) + { + $change = $developdata['text_changes']['diff'][$key]; + $sourcetext = $developdata['text_changes']['ref'][$key]; + $targettext = $developdata['text_changes']['ref_in_dev'][$key]; + + $label = '' + . $key + . '

' + . $change + . '

'; + + $field->attributes()->istextchange = 1; + $field->addAttribute('changestatus', $revisedchanges[$key]); + $field->addAttribute('sourcetext', $sourcetext); + $field->addAttribute('targettext', $targettext); + } + elseif ($have_develop == '1' && in_array($key, $developdata['extra_keys']['keys'])) + { + $label = '[' + . JText::_('COM_LOCALISE_NEW_KEY_IN_DEVELOP') + . '] ' + . $key + . '
' + . htmlspecialchars($string, ENT_COMPAT, 'UTF-8'); + + $field->attributes()->isextraindev = 1; + } + else + { + $label = '' + . $key + . '
' + . htmlspecialchars($string, ENT_COMPAT, 'UTF-8'); + } + $field->addAttribute('status', $status); $field->addAttribute('description', $string); @@ -719,7 +1015,7 @@ protected function preprocessForm(JForm $form, $item, $group = 'content') { $newstrings = true; $form->load($addform, false); - $section = 'New Strings'; + $section = 'COM_LOCALISE_TEXT_TRANSLATION_NOTINREFERENCE'; $addform = new SimpleXMLElement(''); $group = $addform->addChild('fields'); $group->addAttribute('name', 'strings'); @@ -806,11 +1102,40 @@ protected function preprocessForm(JForm $form, $item, $group = 'content') */ public function saveFile($data) { - $path = $this->getState('translation.path'); - $refpath = $this->getState('translation.refpath'); - $exists = JFile::exists($path); - $refexists = JFile::exists($refpath); - $client = $this->getState('translation.client'); + $client = $this->getState('translation.client'); + $tag = $this->getState('translation.tag'); + $reftag = $this->getState('translation.reference'); + $path = $this->getState('translation.path'); + $refpath = $this->getState('translation.refpath'); + $devpath = LocaliseHelper::searchDevpath($client, $refpath); + $custompath = LocaliseHelper::searchCustompath($client, $refpath); + $exists = JFile::exists($path); + $refexists = JFile::exists($refpath); + + if ($refexists && !empty($devpath)) + { + if ($reftag == 'en-GB' && $tag == 'en-GB' && !empty($custompath)) + { + $params = JComponentHelper::getParams('com_localise'); + $customisedref = $params->get('customisedref', '0'); + $custom_short_path = '../media/com_localise/customisedref/github/' + . $client + . '/' + . $customisedref; + + // The saved file is not using the core language folders. + $path = $custompath; + $exists = JFile::exists($path); + + $ref_file = basename($refpath); + $custom_file_path = JFolder::makeSafe("$custompath/$ref_file"); + } + elseif ($reftag == 'en-GB' && $tag != 'en-GB') + { + // It is a translation with the file in develop as reference. + $refpath = $devpath; + } + } // Set FTP credentials, if given. JClientHelper::setCredentialsFromRequest('ftp'); @@ -965,7 +1290,25 @@ public function saveFile($data) while (!$stream->eof()) { - if (preg_match('/^([A-Z][A-Z0-9_\*\-\.]*)\s*=/', $line, $matches)) + // Mounting the language file in this way will help to avoid save files with errors at the content. + + // Blank lines + if (preg_match('/^\s*$/', $line)) + { + $contents[] = "\n"; + } + // Comments lines + elseif (preg_match('/^(;.*)$/', $line, $matches)) + { + $contents[] = $matches[1] . "\n"; + } + // Section lines + elseif (preg_match('/^\[([^\]]*)\]\s*$/', $line, $matches)) + { + $contents[] = $matches[1] . "\n"; + } + // Key lines + elseif (preg_match('/^([A-Z][A-Z0-9_\*\-\.]*)\s*=/', $line, $matches)) { $key = $matches[1]; @@ -975,9 +1318,19 @@ public function saveFile($data) unset($strings[$key]); } } + // Content with EOL + elseif (preg_split("/\\r\\n|\\r|\\n/", $line)) + { + // $this->setError(JText::sprintf('COM_LOCALISE_WRONG_LINE_CONTENT', htmlspecialchars($line))); + $application = JFactory::getApplication(); + $application->enqueueMessage(JText::sprintf('COM_LOCALISE_WRONG_LINE_CONTENT', htmlspecialchars($line)), 'warning'); + } + // Wrong lines else { - $contents[] = $line; + // $this->setError(JText::sprintf('COM_LOCALISE_WRONG_LINE_CONTENT', htmlspecialchars($line))); + $application = JFactory::getApplication(); + $application->enqueueMessage(JText::sprintf('COM_LOCALISE_WRONG_LINE_CONTENT', htmlspecialchars($line)), 'warning'); } $line = $stream->gets(); @@ -1022,6 +1375,19 @@ public function saveFile($data) return false; } + elseif ($reftag == 'en-GB' && $tag == 'en-GB' && !empty($custompath)) + { + $params = JComponentHelper::getParams('com_localise'); + $customisedref = $params->get('customisedref', '0'); + $custom_short_path = '../media/com_localise/customisedref/github/' + . $client + . '/' + . $customisedref; + + JFactory::getApplication()->enqueueMessage( + JText::_('COM_LOCALISE_NOTICE_CUSTOM_EN_GB_FILE_SAVED') . $custom_short_path, + 'notice'); + } } // Remove the cache @@ -1055,6 +1421,36 @@ public function save($data) if (!empty($formData['strings'])) { $data['strings'] = $formData['strings']; + + if (!empty($formData['text_changes'])) + { + $data['text_changes'] = $formData['text_changes']; + $data['source_text_changes'] = $formData['source_text_changes']; + $data['target_text_changes'] = $formData['target_text_changes']; + + $changes_data = array(); + $changes_data['client'] = $this->getState('translation.client'); + $changes_data['reftag'] = $this->getState('translation.reference'); + $changes_data['tag'] = $this->getState('translation.tag'); + $changes_data['filename'] = basename($this->getState('translation.refpath')); +$died = ''; + + foreach ($data['text_changes'] as $key => $revised) + { + $changes_data['revised'] = "0"; + + if ($revised == '1' || $revised == 'true') + { + $changes_data['revised'] = "1"; + } + + $changes_data['key'] = $key; + $changes_data['target_text'] = $data['target_text_changes'][$key]; + $changes_data['source_text'] = $data['source_text_changes'][$key]; + + LocaliseHelper::updateRevisedvalue($changes_data); + } + } } // Special case for lib_joomla diff --git a/component/admin/models/translations.php b/component/admin/models/translations.php index f2105987..203f8380 100644 --- a/component/admin/models/translations.php +++ b/component/admin/models/translations.php @@ -87,6 +87,10 @@ protected function populateState($ordering = null, $direction = null) 'filter.tag', isset($data['select']['tag']) ? $data['select']['tag'] :'' ); + $this->setState( + 'filter.develop', + isset($data['select']['develop']) ? $data['select']['develop'] :'' + ); $params = JComponentHelper::getParams('com_localise'); $this->setState('params', $params); @@ -735,6 +739,7 @@ private function getTranslations() { $filter_client = $this->getState('filter.client'); $filter_tag = $this->getState('filter.tag'); + $filter_develop = $this->getState('filter.develop'); // Don't try to find translations if filters not set for client and language. if (empty($filter_client) || empty($filter_tag)) @@ -745,6 +750,12 @@ private function getTranslations() return $this->translations; } + $gh_data = array(); + $gh_data['github_client'] = $filter_client; + + $get_github_files = LocaliseHelper::getTargetgithubfiles($gh_data); + $get_customised_ref = LocaliseHelper::getSourceGithubfiles($gh_data); + $filter_state = $this->getState('filter.state') ? $this->getState('filter.state') : '.'; $filter_tag = $filter_tag ? ("^" . $filter_tag . "$") : '.'; @@ -789,6 +800,37 @@ private function getTranslations() if (preg_match("/$filter_state/", $state) && preg_match("/$filter_tag/", $translation->tag)) { + $developdata = $item->developdata; + $untranslateds_amount = $item->untranslated; + $translated_news = $item->translatednews; + $unchanged_news = $item->unchangednews; + $extras_amount = 0; + $unrevised_changes = 0; + $have_develop = 0; + + if (!empty($developdata)) + { + $extras_amount = $developdata['extra_keys']['amount']; + $unrevised_changes = $developdata['text_changes']['unrevised']; + } + + if (($extras_amount > 0 && $extras_amount > $translated_news + $unchanged_news) || $unrevised_changes > 0 || $untranslateds_amount > 0) + { + $have_develop = 1; + $item->complete = 0; + } + + if ($filter_develop == 'complete' && $item->complete == 0) + { + unset($this->translations[$key]); + continue; + } + elseif ($filter_develop == 'incomplete' && $item->complete) + { + unset($this->translations[$key]); + continue; + } + if (count($item->error)) { $item->state = 'error'; diff --git a/component/admin/sql/install/mysql/install.sql b/component/admin/sql/install/mysql/install.sql index fc6be3bf..4ce6b060 100644 --- a/component/admin/sql/install/mysql/install.sql +++ b/component/admin/sql/install/mysql/install.sql @@ -7,3 +7,16 @@ CREATE TABLE IF NOT EXISTS `#__localise` ( PRIMARY KEY (`id`), UNIQUE KEY `idx_path` (`path`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +CREATE TABLE IF NOT EXISTS `#__localise_revised_values` ( + `id` int(11) unsigned NOT NULL AUTO_INCREMENT, + `client` varchar(255) NOT NULL, + `reftag` varchar(6) NOT NULL, + `tag` varchar(6) NOT NULL, + `filename` varchar(255) NOT NULL, + `revised` tinyint(1) NOT NULL DEFAULT 0, + `key` varchar(255) NOT NULL, + `target_text` mediumtext NOT NULL, + `source_text` mediumtext NOT NULL, + PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; diff --git a/component/admin/sql/install/mysql/uninstall.sql b/component/admin/sql/install/mysql/uninstall.sql index ce220f40..edc3e82c 100644 --- a/component/admin/sql/install/mysql/uninstall.sql +++ b/component/admin/sql/install/mysql/uninstall.sql @@ -1,2 +1,3 @@ DROP TABLE IF EXISTS `#__localise`; -DELETE FROM `#__assets` WHERE `name` LIKE 'com_localise%'; \ No newline at end of file +DROP TABLE IF EXISTS `#__localise_revised_values`; +DELETE FROM `#__assets` WHERE `name` LIKE 'com_localise%'; diff --git a/component/admin/sql/updates/mysql/ 4.0.4-dev.sql b/component/admin/sql/updates/mysql/ 4.0.4-dev.sql new file mode 100644 index 00000000..67c2247f --- /dev/null +++ b/component/admin/sql/updates/mysql/ 4.0.4-dev.sql @@ -0,0 +1,12 @@ +CREATE TABLE IF NOT EXISTS `#__localise_revised_values` ( + `id` int(11) unsigned NOT NULL AUTO_INCREMENT, + `client` varchar(255) NOT NULL, + `reftag` varchar(6) NOT NULL, + `tag` varchar(6) NOT NULL, + `filename` varchar(255) NOT NULL, + `revised` tinyint(1) NOT NULL DEFAULT 0, + `key` varchar(255) NOT NULL, + `target_text` mediumtext NOT NULL, + `source_text` mediumtext NOT NULL, + PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; diff --git a/component/admin/sql/updates/mysql/4.0.10-dev.sql b/component/admin/sql/updates/mysql/4.0.10-dev.sql new file mode 100644 index 00000000..67c2247f --- /dev/null +++ b/component/admin/sql/updates/mysql/4.0.10-dev.sql @@ -0,0 +1,12 @@ +CREATE TABLE IF NOT EXISTS `#__localise_revised_values` ( + `id` int(11) unsigned NOT NULL AUTO_INCREMENT, + `client` varchar(255) NOT NULL, + `reftag` varchar(6) NOT NULL, + `tag` varchar(6) NOT NULL, + `filename` varchar(255) NOT NULL, + `revised` tinyint(1) NOT NULL DEFAULT 0, + `key` varchar(255) NOT NULL, + `target_text` mediumtext NOT NULL, + `source_text` mediumtext NOT NULL, + PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; diff --git a/component/admin/sql/updates/mysql/4.0.11-dev.sql b/component/admin/sql/updates/mysql/4.0.11-dev.sql new file mode 100644 index 00000000..67c2247f --- /dev/null +++ b/component/admin/sql/updates/mysql/4.0.11-dev.sql @@ -0,0 +1,12 @@ +CREATE TABLE IF NOT EXISTS `#__localise_revised_values` ( + `id` int(11) unsigned NOT NULL AUTO_INCREMENT, + `client` varchar(255) NOT NULL, + `reftag` varchar(6) NOT NULL, + `tag` varchar(6) NOT NULL, + `filename` varchar(255) NOT NULL, + `revised` tinyint(1) NOT NULL DEFAULT 0, + `key` varchar(255) NOT NULL, + `target_text` mediumtext NOT NULL, + `source_text` mediumtext NOT NULL, + PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; diff --git a/component/admin/sql/updates/mysql/4.0.12-dev.sql b/component/admin/sql/updates/mysql/4.0.12-dev.sql new file mode 100644 index 00000000..67c2247f --- /dev/null +++ b/component/admin/sql/updates/mysql/4.0.12-dev.sql @@ -0,0 +1,12 @@ +CREATE TABLE IF NOT EXISTS `#__localise_revised_values` ( + `id` int(11) unsigned NOT NULL AUTO_INCREMENT, + `client` varchar(255) NOT NULL, + `reftag` varchar(6) NOT NULL, + `tag` varchar(6) NOT NULL, + `filename` varchar(255) NOT NULL, + `revised` tinyint(1) NOT NULL DEFAULT 0, + `key` varchar(255) NOT NULL, + `target_text` mediumtext NOT NULL, + `source_text` mediumtext NOT NULL, + PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; diff --git a/component/admin/sql/updates/mysql/4.0.3-dev.sql b/component/admin/sql/updates/mysql/4.0.3-dev.sql new file mode 100644 index 00000000..67c2247f --- /dev/null +++ b/component/admin/sql/updates/mysql/4.0.3-dev.sql @@ -0,0 +1,12 @@ +CREATE TABLE IF NOT EXISTS `#__localise_revised_values` ( + `id` int(11) unsigned NOT NULL AUTO_INCREMENT, + `client` varchar(255) NOT NULL, + `reftag` varchar(6) NOT NULL, + `tag` varchar(6) NOT NULL, + `filename` varchar(255) NOT NULL, + `revised` tinyint(1) NOT NULL DEFAULT 0, + `key` varchar(255) NOT NULL, + `target_text` mediumtext NOT NULL, + `source_text` mediumtext NOT NULL, + PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; diff --git a/component/admin/sql/updates/mysql/4.0.5-dev.sql b/component/admin/sql/updates/mysql/4.0.5-dev.sql new file mode 100644 index 00000000..67c2247f --- /dev/null +++ b/component/admin/sql/updates/mysql/4.0.5-dev.sql @@ -0,0 +1,12 @@ +CREATE TABLE IF NOT EXISTS `#__localise_revised_values` ( + `id` int(11) unsigned NOT NULL AUTO_INCREMENT, + `client` varchar(255) NOT NULL, + `reftag` varchar(6) NOT NULL, + `tag` varchar(6) NOT NULL, + `filename` varchar(255) NOT NULL, + `revised` tinyint(1) NOT NULL DEFAULT 0, + `key` varchar(255) NOT NULL, + `target_text` mediumtext NOT NULL, + `source_text` mediumtext NOT NULL, + PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; diff --git a/component/admin/sql/updates/mysql/4.0.6-dev.sql b/component/admin/sql/updates/mysql/4.0.6-dev.sql new file mode 100644 index 00000000..67c2247f --- /dev/null +++ b/component/admin/sql/updates/mysql/4.0.6-dev.sql @@ -0,0 +1,12 @@ +CREATE TABLE IF NOT EXISTS `#__localise_revised_values` ( + `id` int(11) unsigned NOT NULL AUTO_INCREMENT, + `client` varchar(255) NOT NULL, + `reftag` varchar(6) NOT NULL, + `tag` varchar(6) NOT NULL, + `filename` varchar(255) NOT NULL, + `revised` tinyint(1) NOT NULL DEFAULT 0, + `key` varchar(255) NOT NULL, + `target_text` mediumtext NOT NULL, + `source_text` mediumtext NOT NULL, + PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; diff --git a/component/admin/sql/updates/mysql/4.0.7-dev.sql b/component/admin/sql/updates/mysql/4.0.7-dev.sql new file mode 100644 index 00000000..67c2247f --- /dev/null +++ b/component/admin/sql/updates/mysql/4.0.7-dev.sql @@ -0,0 +1,12 @@ +CREATE TABLE IF NOT EXISTS `#__localise_revised_values` ( + `id` int(11) unsigned NOT NULL AUTO_INCREMENT, + `client` varchar(255) NOT NULL, + `reftag` varchar(6) NOT NULL, + `tag` varchar(6) NOT NULL, + `filename` varchar(255) NOT NULL, + `revised` tinyint(1) NOT NULL DEFAULT 0, + `key` varchar(255) NOT NULL, + `target_text` mediumtext NOT NULL, + `source_text` mediumtext NOT NULL, + PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; diff --git a/component/admin/sql/updates/mysql/4.0.8-dev.sql b/component/admin/sql/updates/mysql/4.0.8-dev.sql new file mode 100644 index 00000000..67c2247f --- /dev/null +++ b/component/admin/sql/updates/mysql/4.0.8-dev.sql @@ -0,0 +1,12 @@ +CREATE TABLE IF NOT EXISTS `#__localise_revised_values` ( + `id` int(11) unsigned NOT NULL AUTO_INCREMENT, + `client` varchar(255) NOT NULL, + `reftag` varchar(6) NOT NULL, + `tag` varchar(6) NOT NULL, + `filename` varchar(255) NOT NULL, + `revised` tinyint(1) NOT NULL DEFAULT 0, + `key` varchar(255) NOT NULL, + `target_text` mediumtext NOT NULL, + `source_text` mediumtext NOT NULL, + PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; diff --git a/component/admin/sql/updates/mysql/4.0.9-dev.sql b/component/admin/sql/updates/mysql/4.0.9-dev.sql new file mode 100644 index 00000000..67c2247f --- /dev/null +++ b/component/admin/sql/updates/mysql/4.0.9-dev.sql @@ -0,0 +1,12 @@ +CREATE TABLE IF NOT EXISTS `#__localise_revised_values` ( + `id` int(11) unsigned NOT NULL AUTO_INCREMENT, + `client` varchar(255) NOT NULL, + `reftag` varchar(6) NOT NULL, + `tag` varchar(6) NOT NULL, + `filename` varchar(255) NOT NULL, + `revised` tinyint(1) NOT NULL DEFAULT 0, + `key` varchar(255) NOT NULL, + `target_text` mediumtext NOT NULL, + `source_text` mediumtext NOT NULL, + PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; diff --git a/component/admin/sql/updates/mysql/4.0.sql b/component/admin/sql/updates/mysql/4.0.sql new file mode 100644 index 00000000..67c2247f --- /dev/null +++ b/component/admin/sql/updates/mysql/4.0.sql @@ -0,0 +1,12 @@ +CREATE TABLE IF NOT EXISTS `#__localise_revised_values` ( + `id` int(11) unsigned NOT NULL AUTO_INCREMENT, + `client` varchar(255) NOT NULL, + `reftag` varchar(6) NOT NULL, + `tag` varchar(6) NOT NULL, + `filename` varchar(255) NOT NULL, + `revised` tinyint(1) NOT NULL DEFAULT 0, + `key` varchar(255) NOT NULL, + `target_text` mediumtext NOT NULL, + `source_text` mediumtext NOT NULL, + PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; diff --git a/component/admin/views/translation/tmpl/edit.php b/component/admin/views/translation/tmpl/edit.php index 9b19512d..09b7ec3e 100644 --- a/component/admin/views/translation/tmpl/edit.php +++ b/component/admin/views/translation/tmpl/edit.php @@ -27,9 +27,35 @@ $istranslation = 0; } +$params = JComponentHelper::getParams('com_localise'); +$ref_tag = $params->get('reference', 'en-GB'); +$allow_develop = $params->get('gh_allow_develop', 0); +$saved_ref = $params->get('customisedref', 0); +$source_ref = $saved_ref; +$istranslation = $this->item->istranslation; +$installed_version = new JVersion; +$installed_version = $installed_version->getShortVersion(); + + if ($saved_ref == 0) + { + $source_ref = $installed_version; + } + + if ($saved_ref != 0 && $allow_develop == 1 && $ref_tag == 'en-GB' && $istranslation == 0) + { + JFactory::getApplication()->enqueueMessage( + JText::sprintf('COM_LOCALISE_NOTICE_EDIT_REFERENCE_HAS_LIMITED_USE', $source_ref), + 'notice'); + } + $input = JFactory::getApplication()->input; $posted = $input->post->get('jform', array(), 'array'); +$has_translatedkeys = !empty($this->item->translatedkeys) ? 1 : 0; +$has_untranslatedkeys = !empty($this->item->untranslatedkeys) ? 1 : 0; +$has_unchangedkeys = !empty($this->item->unchangedkeys) ? 1 : 0; +$has_textchangedkeys = !empty($this->item->textchangedkeys) ? 1 : 0; + if (isset($posted['select']['keystatus']) && !empty($posted['select']['keystatus']) && $posted['select']['keystatus'] != 'allkeys' @@ -200,7 +226,7 @@ function translateAll()
- +
form->getFieldset('select') as $field): ?> type != "Spacer") : ?> @@ -214,7 +240,7 @@ function translateAll()
- + @@ -368,3 +394,29 @@ function translateAll()
+ diff --git a/component/admin/views/translation/tmpl/raw.php b/component/admin/views/translation/tmpl/raw.php index fbb05484..834a8c03 100644 --- a/component/admin/views/translation/tmpl/raw.php +++ b/component/admin/views/translation/tmpl/raw.php @@ -15,6 +15,27 @@ JHtml::_('behavior.keepalive'); JHTML::_('stylesheet', 'com_localise/localise.css', null, true); +$params = JComponentHelper::getParams('com_localise'); +$ref_tag = $params->get('reference', 'en-GB'); +$allow_develop = $params->get('gh_allow_develop', 0); +$saved_ref = $params->get('customisedref', 0); +$source_ref = $saved_ref; +$istranslation = $this->item->istranslation; +$installed_version = new JVersion; +$installed_version = $installed_version->getShortVersion(); + + if ($saved_ref == 0) + { + $source_ref = $installed_version; + } + + if ($saved_ref != 0 && $allow_develop == 1 && $ref_tag == 'en-GB' && $istranslation == 0) + { + JFactory::getApplication()->enqueueMessage( + JText::sprintf('COM_LOCALISE_NOTICE_EDIT_REFERENCE_HAS_LIMITED_USE', $source_ref), + 'notice'); + } + $fieldSets = $this->form->getFieldsets(); $ftpSets = $this->formftp->getFieldsets(); ?> diff --git a/component/admin/views/translations/tmpl/default.php b/component/admin/views/translations/tmpl/default.php index d673113c..a680e7bb 100644 --- a/component/admin/views/translations/tmpl/default.php +++ b/component/admin/views/translations/tmpl/default.php @@ -17,6 +17,8 @@ $listDirn = $this->escape($this->state->get('list.direction')); $saveOrder = $listOrder == 'filename'; $sortFields = $this->getSortFields(); +$params = JComponentHelper::getParams('com_localise'); +$ref_tag = $params->get('reference', 'en-GB'); ?>