Permalink
Browse files

0.5.0

  • Loading branch information...
2 parents 237c518 + 0d3896f commit 0ea5c2b42859e38176064f59388d078afa0280e2 zhang peng committed Dec 1, 2011
Showing with 2 additions and 218 deletions.
  1. +2 −0 .gitignore
  2. +0 −144 auto-tag-slug.php
  3. BIN languages/auto-tag-slug-zh_CN.mo
  4. +0 −74 readme.txt
View
@@ -0,0 +1,2 @@
+*.swp
+*~
View
@@ -1,144 +0,0 @@
-<?php
-/*
-Plugin Name: Auto Tag Slug
-Plugin URI: http://www.grick.net/1125
-Description: Automatically generate English Words or Chinese Pinyin slug for your tags, especially helpful for non-English country users.
-Version: 0.5.0
-Author: grick
-Author URI: http://www.grick.net
-License: GPL2
-Text Domain: auto-tag-slug
- */
-
-require_once('admin_page.php');
-require_once ('class.Chinese.php');
-require_once('ms_translator.php');
-
-$ats_options = get_option('ats_options');
-
-function ats_pinyin($array) {
- global $ats_options;
- $table_dir = dirname(__FILE__).'/config/';
- $result_array = array();
- $array_slice = array_chunk($array, 1000);
- foreach ($array_slice as $array_1000) {
- foreach ($array_1000 as &$tag_slug) {
- $tag_slug = str_replace('|', '', $tag_slug);
- }
- $str = join('|', $array_1000);
- $encoding = ($ats_options['cnlang'] == 'Traditional Chinese') ? 'BIG5' : 'GB2312';
- $chs = new Chinese('UTF8', $encoding, $str, $table_dir);
- $str = $chs->ConvertIT();
- $chs = new Chinese($encoding, 'PinYin', $str, $table_dir);
- $long_str = $chs->ConvertIT();
- $items = explode('|', $long_str);
- foreach ($items as &$item) {
- $pinyin_array = explode(' ', trim($item));
- $str = '';
- // Exclude sigleton letter
- foreach ($pinyin_array as &$pinyin)
- {
- if ( strlen($pinyin) > 1 ) :
- $pinyin .= '-';
- elseif ( $pinyin == ' ' ) :
- $pinyin = '-';
- endif;
- }
- $str = join('', $pinyin_array);
- // Remove illegal character and last '-'
- $str = preg_replace('/-$/', '', preg_replace('/[^a-z0-9-]/i', '', $str));
- $item = strtolower($str);
- }
- }
- return $items;
-}
-
-function ats_slug_used_by_other_tag($current_tag, $slug) {
- $term_row[] = get_term_by('slug', $slug, 'post_tag');
- if ($term_row[0]) :
- return ($current_tag->term_id != $term_row[0]->term_id);
- else :
- return false;
- endif;
-}
-
-function ats_convert_tags($tags) {
- global $ats_options;
- $engine = $ats_options['engine'];
- $tags_array = array();
- foreach($tags as $tag){
- // HINT: wp don't use urlencode to create new slug
- $tags_array[] = urldecode($tag->slug);
- }
- if ($engine == 'english') :
- $converted_tags = ats_bing_translate($ats_options['bing_key'], $tags_array);
- elseif ($engine == 'pinyin') :
- $converted_tags = ats_pinyin($tags_array);
- else :
- $converted_tags = $tags_array;
- endif;
-
- $num = 0;
- $i = 0;
- foreach ($tags as $tag)
- {
- if ( preg_match('/[^a-z0-9- ]/', $tag->slug) && !empty($converted_tags[$i]) ) {
- // Check if slug is used by other tag
- // HINT: Tag may be used by self, when update excuse
- $j = 2;
- $new_slug = $converted_tags[$i];
- while ( ats_slug_used_by_other_tag($tag, $new_slug) )
- {
- $new_slug = $converted_tags[$i] .'-'. $j;
- $j += 1;
- }
- if ($new_slug) {
- wp_update_term($tag->term_id, 'post_tag', array('slug' => $new_slug));
- $num += 1;
- }
- }
- $i += 1;
- }
- return $num;
-}
-
-function ats_convert($post_ID) {
- $tags = wp_get_post_tags($post_ID);
- return ats_convert_tags($tags);
-}
-
-function ats_convert_all() {
- $tags = get_terms('post_tag');
- return ats_convert_tags($tags);
-}
-
-function ats_recover_all() {
- $tags = get_terms('post_tag');
- $num = 0;
- foreach ($tags as $tag) {
- // FIXME: handle dulplicate slug
- wp_update_term($tag->term_id, 'post_tag', array('slug' => sanitize_title($tag->name) ) );
- $num += 1;
- }
- return $num;
-}
-
-function ats_test() {
- ats_convert('1172') ;
- //print_r( ats_convert('1172') );
- print_r(wp_get_post_tags('1172'));
-}
-
-// Make sure we don't expose any info if called directly
-if ( !function_exists( 'add_action' ) ) {
- _e("Hi there! I'm just a plugin, not much I can do when called directly.");
- exit;
-}
-
-if ( !wp_is_post_revision( $post_ID ) && $ats_options['switch'] ) {
- add_action('save_post', 'ats_convert');
- add_action('admin_notices', 'ats_api_warning');
- //add_action( 'admin_notices', 'ats_test' );
-}
-
-?>
Binary file not shown.
View
@@ -1,74 +0,0 @@
-=== Plugin Name ===
-Contributors: grick
-Tags: tag, tags, slug, URL, rewrite, Bing, permarlink, SEO, 标签, 别名
-Requires at least: 2.7.0
-Tested up to: 3.2.1
-Stable tag: 0.5.0
-
-Generate URL-friendly tag slug. Especially useful for non-English speaking country users.
-
-== Description ==
-
-This plugin will convert post tags slug to Pinyin or English words.
-
-For example, you may have tag URL like this: www\.abc.com/tag/`%e4%bd%a0%e5%a5%bd`
-
-With this plugin, you can convert all of them to the following format:
-
-* www\.abc.com/tag/`ni-hao`
-* www\.abc.com/tag/`hello`
-
-These URL have better looks and should be more Search Engine friendly.
-
-= Main Feature =
-
-* One click to convert all post tags slug
-* Select "Pin Yin" or "English" for slug format
-* Convert post tags slug automatically when new post save or update
-* Reset all tags slug to default
-
-= 中文指南 =
-
-* 插件名称:WordPress 标签别名转换(Auto Tag Slug)
-* 插件描述:此插件能够自动修改系统标签别名至拼音或英语单词格式。
-* 适用对象:中文版或其他非英语系国家用户
-* 当前版本:0.5.0
-
-= 插件简介 =
-
-此插件的初衷是为了解决 IIS6 上经过 Rewrite 的 tag 的解析问题,使用后可以将 WordPress 标签原生的 urlencode 格式转换为汉语拼音或者英语单词。
-
-* 原来的 URL:www\.abc.com/tag/`%e4%bd%a0%e5%a5%bd`
-* 拼音转换后的 URL:www\.abc.com/tag/`ni-hao`
-* 英语单词转换后的 URL:www\.abc.com/tag/`hello`
-
-= 主要功能 =
-
-* 支持日志发布或更新时自动转换标签别名
-* 支持一键转换全部标签功能
-* 支持恢复原有格式
-
-
-
-
-== Installation ==
-
-1. Upload `auto-tag-slug` to the `/wp-content/plugins/` directory
-2. Activate the plugin through the 'Plugins' menu in WordPress
-
-== Frequently Asked Questions ==
-
-= Why use this plugin? =
-
-If you are non English country user, This plugin can make beautiful url for your tags.It is also able to solve some rewrite problem on IIS6.
-
-== Screenshots ==
-
-1. Screen shot
-2. 设置截图
-
-== Changelog ==
-
-= 0.5.0 =
-Initial release.
-

0 comments on commit 0ea5c2b

Please sign in to comment.