解决joomla把标签最短文本长度限定为3的问题

Posted 岬淢箫声

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了解决joomla把标签最短文本长度限定为3的问题相关的知识,希望对你有一定的参考价值。

对于中文环境来说,把标签文本最小长度限制为3是不合理的。因为中文是双音节词语,比拉丁文等西方国家语言简短,大量的有实际意义的词汇的文本长度为2。然而Joomla不支持配置它。经过调试,我发现它的代码把标签最小长度写在代码中限定死了。代码位于libraries\\cms\\html文件夹下tag.php文件里,第168行:

<?php
/**
 * @package     Joomla.Libraries
 * @subpackage  HTML
 *
 * @copyright   Copyright (C) 2005 - 2018 Open Source Matters, Inc. All rights reserved.
 * @license     GNU General Public License version 2 or later; see LICENSE.txt
 */

defined('JPATH_PLATFORM') or die;

use Joomla\\Utilities\\ArrayHelper;

/**
 * Utility class for tags
 *
 * @since  3.1
 */
abstract class JHtmlTag

	/**
	 * Cached array of the tag items.
	 *
	 * @var    array
	 * @since  3.1
	 */
	protected static $items = array();

	/**
	 * Returns an array of tags.
	 *
	 * @param   array  $config  An array of configuration options. By default, only
	 *                          published and unpublished categories are returned.
	 *
	 * @return  array
	 *
	 * @since   3.1
	 */
	public static function options($config = array('filter.published' => array(0, 1)))
	
		$hash = md5(serialize($config));

		if (!isset(static::$items[$hash]))
		
			$config = (array) $config;
			$db = JFactory::getDbo();
			$query = $db->getQuery(true)
				->select('a.id, a.title, a.level')
				->from('#__tags AS a')
				->where('a.parent_id > 0');

			// Filter on the published state
			if (isset($config['filter.published']))
			
				if (is_numeric($config['filter.published']))
				
					$query->where('a.published = ' . (int) $config['filter.published']);
				
				elseif (is_array($config['filter.published']))
				
					$config['filter.published'] = ArrayHelper::toInteger($config['filter.published']);
					$query->where('a.published IN (' . implode(',', $config['filter.published']) . ')');
				
			

			// Filter on the language
			if (isset($config['filter.language']))
			
				if (is_string($config['filter.language']))
				
					$query->where('a.language = ' . $db->quote($config['filter.language']));
				
				elseif (is_array($config['filter.language']))
				
					foreach ($config['filter.language'] as &$language)
					
						$language = $db->quote($language);
					

					$query->where('a.language IN (' . implode(',', $config['filter.language']) . ')');
				
			

			$query->order('a.lft');

			$db->setQuery($query);
			$items = $db->loadObjectList();

			// Assemble the list options.
			static::$items[$hash] = array();

			foreach ($items as &$item)
			
				$repeat = ($item->level - 1 >= 0) ? $item->level - 1 : 0;
				$item->title = str_repeat('- ', $repeat) . $item->title;
				static::$items[$hash][] = JHtml::_('select.option', $item->id, $item->title);
			
		

		return static::$items[$hash];
	

	/**
	 * Returns an array of tags.
	 *
	 * @param   array  $config  An array of configuration options. By default, only published and unpublished tags are returned.
	 *
	 * @return  array  Tag data
	 *
	 * @since   3.1
	 */
	public static function tags($config = array('filter.published' => array(0, 1)))
	
		$hash = md5(serialize($config));
		$config = (array) $config;
		$db = JFactory::getDbo();
		$query = $db->getQuery(true)
			->select('a.id, a.title, a.level, a.parent_id')
			->from('#__tags AS a')
			->where('a.parent_id > 0');

		// Filter on the published state
		if (isset($config['filter.published']))
		
			if (is_numeric($config['filter.published']))
			
				$query->where('a.published = ' . (int) $config['filter.published']);
			
			elseif (is_array($config['filter.published']))
			
				$config['filter.published'] = ArrayHelper::toInteger($config['filter.published']);
				$query->where('a.published IN (' . implode(',', $config['filter.published']) . ')');
			
		

		$query->order('a.lft');

		$db->setQuery($query);
		$items = $db->loadObjectList();

		// Assemble the list options.
		static::$items[$hash] = array();

		foreach ($items as &$item)
		
			$repeat = ($item->level - 1 >= 0) ? $item->level - 1 : 0;
			$item->title = str_repeat('- ', $repeat) . $item->title;
			static::$items[$hash][] = JHtml::_('select.option', $item->id, $item->title);
		

		return static::$items[$hash];
	

	/**
	 * This is just a proxy for the formbehavior.ajaxchosen method
	 *
	 * @param   string   $selector     DOM id of the tag field
	 * @param   boolean  $allowCustom  Flag to allow custom values
	 *
	 * @return  void
	 *
	 * @since   3.1
	 */
	public static function ajaxfield($selector = '#jform_tags', $allowCustom = true)
	
		// Get the component parameters
		$params = JComponentHelper::getParams('com_tags');
		$minTermLength = (int) $params->get('min_term_length', 3);

		$displayData = array(
			'minTermLength' => $minTermLength,
			'selector'      => $selector,
			'allowCustom'   => JFactory::getUser()->authorise('core.create', 'com_tags') ? $allowCustom : false,
		);

		JLayoutHelper::render('joomla.html.tag', $displayData);

		return;
	

此外在administrator\\components\\com_tags文件夹下config.xml文件中发现配置节第181行也有长度的文字描述:

<?xml version="1.0" encoding="utf-8"?>
<config>
	<fieldset
		name="taglist"
		label="COM_TAGS_CONFIG_TAG_SETTINGS_LABEL"
		description="COM_TAGS_CONFIG_TAG_SETTINGS_DESC">

		<field
			name="tag_layout"
			type="componentlayout"
			label="COM_TAGS_CONFIG_TAGGED_ITEMS_FIELD_LAYOUT_LABEL"
			description="COM_TAGS_CONFIG_TAGGED_ITEMS_FIELD_LAYOUT_DESC"
			menuitems="true"
			extension="com_tags"
			view="tag"
		/>

		<field
			name="save_history"
			type="radio"
			label="JGLOBAL_SAVE_HISTORY_OPTIONS_LABEL"
			description="JGLOBAL_SAVE_HISTORY_OPTIONS_DESC"
			class="btn-group btn-group-yesno"
			default="0"
			>
			<option value="1">JYES</option>
			<option value="0">JNO</option>
		</field>

		<field
			name="history_limit"
			type="number"
			label="JGLOBAL_HISTORY_LIMIT_OPTIONS_LABEL"
			description="JGLOBAL_HISTORY_LIMIT_OPTIONS_DESC"
			filter="integer"
			default="5"
			showon="save_history:1"
		/>

		<field 
			name="show_tag_title" 
			type="radio"
			label="COM_TAGS_SHOW_TAG_TITLE_LABEL"
			description="COM_TAGS_SHOW_TAG_TITLE_DESC"
			class="btn-group btn-group-yesno"
			default="0"
			>
			<option value="1">JSHOW</option>
			<option value="0">JHIDE</option>
		</field>

		<field 
			name="tag_list_show_tag_image" 
			type="radio"
			label="COM_TAGS_SHOW_TAG_IMAGE_LABEL"
			description="COM_TAGS_SHOW_TAG_IMAGE_DESC"
			class="btn-group btn-group-yesno"
			default="1"
			>
			<option value="1">JSHOW</option>
			<option value="0">JHIDE</option>
		</field>

		<field 
			name="tag_list_show_tag_description" 
			type="radio" 
			label="COM_TAGS_SHOW_TAG_DESCRIPTION_LABEL"
			description="COM_TAGS_SHOW_TAG_DESCRIPTION_DESC"
			class="btn-group btn-group-yesno"
			default="1"
			>
			<option value="1">JSHOW</option>
			<option value="0">JHIDE</option>
		</field>

		<field 
			name="tag_list_image" 
			type="media"
			label="COM_TAGS_TAG_LIST_MEDIA_LABEL"
			description="COM_TAGS_TAG_LIST_MEDIA_DESC"
		/>
	
		<field 
			name="tag_list_orderby"
			type="list"
			label="JGLOBAL_FIELD_FIELD_ORDERING_LABEL"
			description="JGLOBAL_FIELD_FIELD_ORDERING_DESC"
			default="title"
			>
			<option value="c.core_title">JGLOBAL_TITLE</option>
			<option value="match_count">COM_TAGS_MATCH_COUNT</option>
			<option value="c.core_created_time">JGLOBAL_CREATED_DATE</option>
			<option value="c.core_modified_time">JGLOBAL_MODIFIED_DATE</option>
			<option value="c.core_publish_up">JGLOBAL_PUBLISHED_DATE</option>
		</field>

		<field 
			name="tag_list_orderby_direction" 
			type="radio" 
			label="JGLOBAL_ORDER_DIRECTION_LABEL"
			description="JGLOBAL_ORDER_DIRECTION_DESC"
			class="btn-group btn-group-yesno"
			default="ASC"
			>
			<option value="ASC">JGLOBAL_ORDER_ASCENDING</option>
			<option value="DESC">JGLOBAL_ORDER_DESCENDING</option>
		</field>

		<field 
			name="show_headings" 
			type="radio"
			label="COM_TAGS_TAG_LIST_SHOW_HEADINGS_LABEL"
			description="COM_TAGS_TAG_LIST_SHOW_HEADINGS_DESC"
			class="btn-group btn-group-yesno"
			default="1"			
			>
			<option value="1">JSHOW</option>
			<option value="0">JHIDE</option>
		</field>

		<field 
			name="tag_list_show_date"
			type="list"
			label="COM_TAGS_TAG_LIST_SHOW_DATE_DESC"
			description="COM_TAGS_TAG_LIST_SHOW_DATE_LABEL"
			default="0"
			>
			<option value="0">JHIDE</option>
			<option value="created">JGLOBAL_CREATED</option>
			<option value="modified">JGLOBAL_MODIFIED</option>
			<option value="published">JPUBLISHED</option>
		</field>

		<field 
			name="tag_list_show_item_image" 
			type="radio" 
			label="COM_TAGS_SHOW_ITEM_IMAGE_LABEL"
			description="COM_TAGS_SHOW_ITEM_IMAGE_DESC"
			class="btn-group btn-group-yesno"
			default="1"
			>
			<option value="1">JSHOW</option>
			<option value="0">JHIDE</option>
		</field>
		
		<field 
			name="tag_list_show_item_description" 
			type="radio"
			label="COM_TAGS_TAG_LIST_SHOW_ITEM_DESCRIPTION_LABEL"
			description="COM_TAGS_TAG_LIST_SHOW_ITEM_DESCRIPTION_DESC"
			class="btn-group btn-group-yesno"
			>
			<option value="1">JSHOW</option>
			<option value="0">JHIDE</option>
		</field>
		
		<field
			name="tag_list_item_maximum_characters"
			type="number"
			label="COM_TAGS_LIST_MAX_CHARACTERS_LABEL"
			description="COM_TAGS_LIST_MAX_CHARACTERS_DESC"
			filter="integer"
			showon="tag_list_show_item_description:1"
		/>

	</fieldset>
	
	<fieldset
		name="tagselection"
		label="COM_TAGS_CONFIG_SELECTION_SETTINGS_LABEL"
		description="COM_TAGS_CONFIG_SELECTION_SETTINGS_DESC">

		<field
			name="min_term_length"
			type="integer"
			label="COM_TAGS_CONFIG_TAG_MIN_LENGTH_LABEL"
			description="COM_TAGS_CONFIG_TAG_MIN_LENGTH_DESC"
			first="1"
			last="1"
			step="1"
			default="3"
		/>

		<field 
			name="return_any_or_all" 
			type="radio" 
			label="COM_TAGS_SEARCH_TYPE_LABEL"
			description="COM_TAGS_SEARCH_TYPE_DESC"
			class="btn-group btn-group-yesno"
			default="1"
			>
			<option value="1">COM_TAGS_ANY</option>
			<option value="0">COM_TAGS_ALL</option>
		</field>
		
		<field 
			name="include_children" 
			type="radio" 
			label="COM_TAGS_INCLUDE_CHILDREN_LABEL"
			description="COM_TAGS_INCLUDE_CHILDREN_DESC"
			class="btn-group btn-group-yesno"
			default="0"
			>
			<option value="1">COM_TAGS_INCLUDE</option>
			<option value="0">COM_TAGS_EXCLUDE</option>
		</field>
		
		<field
			name="maximum"
			type="number"
			label="COM_TAGS_LIST_MAX_LABEL"
			description="COM_TAGS_LIST_MAX_DESC"
			default="200"
			filter="integer"
		/>
		
		<field 
			name="tag_list_language_filter"
			type="contentlanguage"
			label="COM_TAGS_FIELD_LANGUAGE_FILTER_LABEL"
			description="COM_TAGS_FIELD_LANGUAGE_FILTER_DESC"
			default="all"
			>
			<option value="all">JALL</option>
			<option value="current_language">JCURRENT</option>
		</field>
		
	</fieldset>	

	<fieldset
		name="alltags"
		label="COM_TAGS_CONFIG_ALL_TAGS_SETTINGS_LABEL"
		description="COM_TAGS_CONFIG_ALL_TAGS_SETTINGS_DESC">

		<field
			name="tags_layout" 
			type="componentlayout"
			label="COM_TAGS_CONFIG_ALL_TAGS_FIELD_LAYOUT_LABEL"
			description="COM_TAGS_CONFIG_ALL_TAGS_FIELD_LAYOUT_DESC"
			menuitems="true"
			extension="com_tags"
			view="tags"
		/>

		<field 
			name="all_tags_orderby"
			type="list"
			label="JGLOBAL_FIELD_FIELD_ORDERING_LABEL"
			description="JGLOBAL_FIELD_FIELD_ORDERING_DESC"
			default="title"
			>
			<option value="title">JGLOBAL_TITLE</option>
			<option value="hits">JGLOBAL_HITS</option>
			<option value="created_time">JGLOBAL_CREATED_DATE</option>
			<option value="modified_time">JGLOBAL_MODIFIED_DATE</option>
			<option value="publish_up">JGLOBAL_PUBLISHED_DATE</option>
		</field>

		<field 
			name="all_tags_orderby_direction" 
			type="radio"
			label="JGLOBAL_ORDER_DIRECTION_LABEL"
			description="JGLOBAL_ORDER_DIRECTION_DESC"
			class="btn-group btn-group-yesno"
			default="ASC"
			>
			<option value="ASC">JGLOBAL_ORDER_ASCENDING</option>
			<option value="DESC">JGLOBAL_ORDER_DESCENDING</option>
		</field>

		<field 
			name="all_tags_show_tag_image" 
			type="radio" 
			label="COM_TAGS_SHOW_ITEM_IMAGE_LABEL"
			description="COM_TAGS_SHOW_ITEM_IMAGE_DESC"
			class="btn-group btn-group-yesno"
			default="1"
			>
			<option value="1">JSHOW</option>
			<option value="0">JHIDE</option>
		</field>

		<field 
			name="all_tags_show_tag_descripion" 
			type="radio" 
			label="COM_TAGS_SHOW_ITEM_DESCRIPTION_LABEL"
			description="COM_TAGS_SHOW_ITEM_DESCRIPTION_DESC"
			class="btn-group btn-group-yesno"
			default="1"
			>
			<option value="1">JSHOW</option>
			<option value="0">JHIDE</option>
		</field>
		
		<field
			name="all_tags_tag_maximum_characters"
			type="number"
			label="COM_TAGS_LIST_MAX_CHARACTERS_LABEL"
			description="COM_TAGS_LIST_MAX_CHARACTERS_DESC"
			filter="integer"
			showon="all_tags_show_tag_descripion:1"
		/>
		
		<field 
			name="all_tags_show_tag_hits" 
			type="radio" 
			label="JGLOBAL_HITS"
			description="COM_TAGS_FIELD_CONFIG_HITS_DESC"
			class="btn-group btn-group-yesno"
			default="0"
			>
			<option value="1">JSHOW</option>
			<option value="0">JHIDE</option>
		</field>

	</fieldset>

	<fieldset
		name="shared"
		label="COM_TAGS_CONFIG_SHARED_SETTINGS_LABEL"
		description="COM_TAGS_CONFIG_SHARED_SETTINGS_DESC">
		
		<field
			name="filter_field"
			type="radio"
			label="JGLOBAL_FILTER_FIELD_LABEL"
			description="JGLOBAL_FILTER_FIELD_DESC"
			class="btn-group btn-group-yesno"
			default="1"
			>
			<option value="1">JSHOW</option>
			<option value="0">JHIDE</option>
		</field>

		<field 
			name="show_pagination_limit" 
			type="radio"
			label="JGLOBAL_DISPLAY_SELECT_LABEL"
			description="JGLOBAL_DISPLAY_SELECT_DESC"
			default="1"
			class="btn-group btn-group-yesno"
			>
			<option value="1">JSHOW</option>
			<option value="0">JHIDE</option>
		</field>
		
		<field 
			name="show_pagination" 
			type="list"
			label="JGLOBAL_PAGINATION_LABEL"
			description="JGLOBAL_PAGINATION_DESC"
			default="2"
			>
			<option value="1">JSHOW</option>
			<option value="0">JHIDE</option>
			<option value="2">JGLOBAL_AUTO</option>
		</field>

		<field
			name="show_pagination_results"
			type="radio"
			label="JGLOBAL_PAGINATION_RESULTS_LABEL"
			description="JGLOBAL_PAGINATION_RESULTS_DESC"
			class="btn-group btn-group-yesno"
			default="1"
			showon="show_pagination:1,2"
			>
			<option value="1">JSHOW</option>
			<option value="0">JHIDE</option>
		</field>
		
	</fieldset>
	
	<fieldset
		name="data_entry"
		label="COM_TAGS_CONFIG_DATA_ENTRY_SETTINGS_LABEL"
		description="COM_TAGS_CONFIG_DATA_ENTRY_SETTINGS_DESC">
		
		<field 
			name="tag_field_ajax_mode" 
			type="radio" 
			label="COM_TAGS_TAG_FIELD_MODE_LABEL"
			description="COM_TAGS_TAG_FIELD_MODE_DESC"
			class="btn-group btn-group-yesno"
			default="1"
			>
			<option value="1">COM_TAGS_TAG_FIELD_MODE_AJAX</option>
			<option value="0">COM_TAGS_TAG_FIELD_MODE_NESTED</option>
		</field>

	</fieldset>
	
	<fieldset 
		name="integration"
		label="JGLOBAL_INTEGRATION_LABEL"
		description="COM_TAGS_CONFIG_INTEGRATION_SETTINGS_DESC"
	>

		<field
			name="show_feed_link"
			type="radio"
			label="JGLOBAL_SHOW_FEED_LINK_LABEL"
			description="JGLOBAL_SHOW_FEED_LINK_DESC"
			class="btn-group btn-group-yesno"
			default="1"
			>
			<option value="1">JSHOW</option>
			<option value="0">JHIDE</option>
		</field>

	</fieldset>

	<fieldset
		name="permissions"
		label="JCONFIG_PERMISSIONS_LABEL"
		description="JCONFIG_PERMISSIONS_DESC"
		>

		<field
			name="rules"
			type="rules"
			label="JCONFIG_PERMISSIONS_LABEL"
			filter="rules"
			validate="rules"
			component="com_tags"
			section="component"
		/>
	</fieldset>
</config>

把以上两个代码位置的3改为1就可以了。


以上是关于解决joomla把标签最短文本长度限定为3的问题的主要内容,如果未能解决你的问题,请参考以下文章

[算法]需要排序的最短子数组长度

joomla 3中的语言切换器不显示标志

最短编辑距离问题理解

限定文本框输入长度和类型

Swift - UILabel 自动调整为文本长度

Addition Chains