plugins:customurl:customurl_code

NP_CustomURL.phpのソースコード

<?php
 
if (!function_exists('sql_table')) {
	function sql_table($name)
	{
		return 'nucleus_' . $name;
	}
}
 
if (!function_exists('htmlspecialchars_decode')) {
	function htmlspecialchars_decode($text)
	{
		return strtr($text, array_flip(get_html_translation_table(HTML_SPECIALCHARS)));
	}
}
 
if (!defined('_CUSTOMURL_TABLE_DEFINED')) {
	define('_CUSTOMURL_TABLE_DEFINED',	1);
	define('_CUSTOMURL_TABLE',	sql_table('plug_customurl'));
	define('_C_SUBCAT_TABLE',	sql_table('plug_multiple_categories_sub'));
}
 
class NP_CustomURL extends NucleusPlugin
 {
 
	function getMinNucleusVersion()
	{
		return '322';
	}
 
	function getName()
	{
		return 'Customized URL';
	}
 
	function getAuthor()
	{
		return 'shizuki';
	}
 
	function getURL()
	{
		return 'http://shizuki.kinezumi.net/NucleusCMS/Plugins/NP_CustomURL/NP_CustomURL.html';
	}
 
	function getVersion()
	{
		return '0.3.2c';
	}
 
	function getDescription()
	{
		return _DESCRIPTION;
	}
 
	function supportsFeature($what)
	{
		switch($what) {
			case 'SqlTablePrefix':
				return 1;
			case 'HelpPage':
				return 1;
			default:
				return 0;
		}
	}
 
	function hasAdminArea()
	{
		return 1;
	}
 
	function event_QuickMenu(&$data)
	{
		global $member;
		$quickLink   = ($this->getOption( 'customurl_quicklink') == 'yes');
		$memberCheck = ($member->isLoggedIn() && $member->isAdmin());
		if (!$quickLink || !$memberCheck) {
			return;
		}
		array_push(
			$data['options'],
			array(
				'title'		=> _ADMIN_TITLE,
				'url'		=> $this->getAdminURL(),
				'tooltip'	=> _QUICK_TIPS
			)
		);
	}
 
	function getTableList()
	{
		return	array(
			_CUSTOMURL_TABLE
		);
	}
 
	function getEventList()
	{
		return	array(
			'QuickMenu',
//			'AdminPrePageHead',
			'ParseURL',
			'GenerateURL',
			'PostAddBlog',
			'PostAddItem',
			'PostUpdateItem',
			'PostRegister',
			'PostAddCategory',
			'PostDeleteBlog',
			'PostDeleteItem',
			'PostDeleteMember',
			'PostDeleteCategory',
			'PrePluginOptionsUpdate',
			'PreItem',
			'PostItem',
			'PreSkinParse',
			'AddItemFormExtras',
			'EditItemFormExtras',
			'PostMoveCategory',
			'PostMoveItem',
//			'PreSendContentType',
			'InitSkinParse',
		);
	}
 
//	function event_AdminPrePageHead($data)
//	{
//		if ($data['action'] == 'pluginhelp' && intGetVar('plugid') == $this->getID()) {
//			$data['extrahead'] = '<link rel="stylesheet" title="NP_CustomURL HELP"'
//								. ' type="text/css"'
//								. "\n"
//								. "\t\t\t"
//								. ' href="' . $this->getAdminURL()
//								. 'helpstyle.css" />' . "\n";
//		}
//	}
 
	function install()
	{
		global $manager, $CONF;
// Keys initialize
		if (empty($CONF['ArchiveKey'])) {
			$CONF['ArchiveKey'] = 'archive';
		}
		if (empty($CONF['ArchivesKey'])) {
			$CONF['ArchivesKey'] = 'archives';
		}
		if (empty($CONF['MemberKey'])) {
			$CONF['MemberKey'] = 'member';
		}
		if (empty($CONF['ItemKey'])) {
			$CONF['ItemKey'] = 'item';
		}
		if (empty($CONF['CategoryKey'])) {
			$CONF['CategoryKey'] = 'category';
		}
 
//Plugins sort
		$myid = intval($this->getID());
		$res = sql_query('SELECT pid, porder FROM '.sql_table('plugin'));
		while($p = mysql_fetch_array($res)) {
			$updateQuery = 'UPDATE %s SET porder = %d WHERE pid = %d';
			if (intval($p['pid']) == $myid) {
				sql_query(sprintf($updateQuery, sql_table('plugin'), 1, $myid));
			} else {
				sql_query(sprintf($updateQuery, sql_table('plugin'), $p['porder']+1, $p['pid']));
			}
		}
 
//create plugin's options and set default value
		$this->createOption('customurl_archive',	_OP_ARCHIVE_DIR_NAME,
							'text',		$CONF['ArchiveKey']);
		$this->createOption('customurl_archives',	_OP_ARCHIVES_DIR_NAME,
							'text',		$CONF['ArchivesKey']);
		$this->createOption('customurl_member',		_OP_MEMBER_DIR_NAME,
							'text',		$CONF['MemberKey']);
		$this->createOption('customurl_dfitem',		_OP_DEF_ITEM_KEY,
							'text',		$CONF['ItemKey']);
		$this->createOption('customurl_dfcat',		_OP_DEF_CAT_KEY,
							'text',		$CONF['CategoryKey']);
		$this->createOption('customurl_dfscat',		_OP_DEF_SCAT_KEY,
							'text',		'subcategory');
		$this->createOption('customurl_tabledel',	_OP_TABLE_DELETE,
							'yesno',	'no');
		$this->createOption('customurl_quicklink',	_OP_QUICK_LINK,
							'yesno',	'yes');
		$this->createOption('customurl_notfound',	_OP_NOT_FOUND,
							'select',	'404',
							'404 Not Found|404|303 See Other|303');
		$this->createBlogOption(	'use_customurl',	_OP_USE_CURL,
									'yesno',	'yes');
		$this->createBlogOption(	'redirect_normal',	_OP_RED_NORM,
									'yesno',	'yes');
		$this->createBlogOption(	'redirect_search',	_OP_RED_SEARCH,
									'yesno',	'yes');
		$this->createBlogOption(	'customurl_bname',	_OP_BLOG_PATH,
									'text');
//		$this->createItemOption(	'customurl_iname',	_OP_ITEM_PATH,
//									'text',		$CONF['ItemKey']);
		$this->createMemberOption(	'customurl_mname',	_OP_MEMBER_PATH,
									'text');
		$this->createCategoryOption('customurl_cname',	_OP_CATEGORY_PATH,
									'text');
 
		//default archive directory name
		$this->setOption('customurl_archive',	$CONF['ArchiveKey']);
		//default archives directory name
		$this->setOption('customurl_archives',	$CONF['ArchivesKey']);
		//default member directory name
		$this->setOption('customurl_member',	$CONF['MemberKey']);
		//default itemkey_template
		$this->setOption('customurl_dfitem',	$CONF['ItemKey']);
		//default categorykey_template
		$this->setOption('customurl_dfcat',		$CONF['CategoryKey']);
		//default subcategorykey_template
		$this->setOption('customurl_dfscat',	'subcategory');
 
//create data table
		$sql = 'CREATE TABLE IF NOT EXISTS ' . _CUSTOMURL_TABLE . ' ('
			 . ' `id` INT(11) NOT NULL AUTO_INCREMENT PRIMARY KEY, '
			 . ' `obj_param` VARCHAR(15) NOT NULL, '
			 . ' `obj_name` VARCHAR(128) NOT NULL, '
			 . ' `obj_id` INT(11) NOT NULL, '
			 . ' `obj_bid` INT(11) NOT NULL,'
			 . ' INDEX (`obj_name`)'
			 . ' )';
		sql_query($sql);
 
//setting default aliases
		$this->_createNewPath('blog',		'blog',		'bnumber',	'bshortname');
		$this->_createNewPath('item',		'item',		'inumber',	'iblog');
		$this->_createNewPath('category',	'category',	'catid',	'cblog');
		$this->_createNewPath('member',		'member',	'mnumber',	'mname');
 
		if ($this->pluginCheck('MultipleCategories')) {
			$this->_createNewPath('subcategory', 'plug_multiple_categories_sub', 'scatid', 'catid');
		}
 
	}
 
	function _createNewPath($type, $n_table, $id, $bids)
	{
		$tmpTable = sql_table('plug_customurl_temp');
		$createQuery = 'CREATE TABLE %s SELECT obj_id, obj_param FROM %s'
					 . ' WHERE obj_param = "%s"';
		sql_query(sprintf($createQuery, $tmpTable, _CUSTOMURL_TABLE, $type));
		$TmpQuery    = 'SELECT %s, %s FROM %s LEFT JOIN %s ON %s.%s = %s.obj_id'
					 . ' WHERE %s.obj_id is null';
		$table = sql_table($n_table);
		$temp = sql_query(sprintf($TmpQuery, $id, $bids, $table, $tmpTable, $table, $id, $tmpTable, $tmpTable));
		if ($temp) {
			while ($row=mysql_fetch_array($temp)) {
				switch ($type) {
					case 'blog':
						//set access by BlogshortName/
						$newPath = $row[$bids];
						$blgid = 0;
					break;
					case 'item':
						//set access by (itemkey_template)_itemid.html
						$tque = 'SELECT itime as result FROM %s WHERE inumber = %d';
						$itime = quickQuery( sprintf($tque ,sql_table('item'), intval($row[$id]) ) );
						$y = $m = $d = '';
						sscanf($itime,'%d-%d-%d %s',$y,$m,$d,$temp);
						$ikey = TEMPLATE::fill($this->getOption('customurl_dfitem'),
												array ('year' => $y,
														'month' => $m,
														'day' => $d)
											  );
						$newPath = $ikey . '_' . $row[$id] . '.html';
						$blgid = $row[$bids];
					break;
					case 'category':
						//set access by (categorykey_template)_categoryid/
						$newPath = $this->getOption('customurl_dfcat') . '_' . $row[$id];
						$blgid = $row[$bids];
					break;
					case 'member':
						//set access by loginName.html
						$newPath = $row[$bids] . '.html';
						$blgid = 0;
					break;
					case 'subcategory':
						//set access by (subcategorykey_template)_subcategoryid/
						$newPath = $this->getOption('customurl_dfscat') . '_' . $row[$id];
						$blgid = $row[$bids];
					break;
					default:
					break;
				}
				$insertQuery = 'INSERT INTO %s (obj_param, obj_id, obj_name, obj_bid)'
							 . ' VALUES ("%s", %d, "%s", %d)';
				$row[$id] = intval($row[$id]);
				$blgid    = intval($blgid);
				sql_query(sprintf($insertQuery, _CUSTOMURL_TABLE, $type, $row[$id], $newPath, $blgid));
			}
		}
		$query = 'SELECT obj_id, obj_name FROM %s WHERE obj_param = "%s"';
		$temp = sql_query(sprintf($query, _CUSTOMURL_TABLE, $type));
		while ($row = mysql_fetch_array($temp)) {
			$name = $row['obj_name'];
			$id   = intval($row['obj_id']);
			switch ($type) {
				case 'blog':
					$this->setBlogOption($id, 'customurl_bname', $name);
				break;
				case 'category':
					$this->setCategoryOption($id, 'customurl_cname', $name);
				break;
				case 'member':
					$obj_name = substr($name, 0, -5);
					$this->setMemberOption($id, 'customurl_mname', $obj_name);
				break;
				default:
				break;
			}
		}
 
		sql_query('DROP TABLE IF EXISTS ' . $tmpTable);
	}
 
	function init()
	{
		global $admin;
		$language = ereg_replace( '[\\|/]', '', getLanguageName());
		if (file_exists($this->getDirectory() . 'language/' . $language . '.php')) {
			include_once($this->getDirectory() . 'language/' . $language . '.php');
		} else {
			include_once($this->getDirectory() . 'language/english.php');
		}
	}
 
	function pluginCheck($pluginName)
	{
		global $manager;
		if (!$manager->pluginInstalled('NP_' . $pluginName)) {
			return;
		}
		$plugin =& $manager->getPlugin('NP_' . $pluginName);
		return $plugin;
	}
 
	function unInstall()
	{
		if ($this->getOption('customurl_tabledel') == 'yes') {
			sql_query("DROP TABLE "._CUSTOMURL_TABLE);
		}
		$this->deleteOption('customurl_archive');
		$this->deleteOption('customurl_archives');
		$this->deleteOption('customurl_member');
		$this->deleteOption('customurl_dfitem');
		$this->deleteOption('customurl_dfcat');
		$this->deleteOption('customurl_dfscat');
		$this->deleteOption('customurl_notfound');
		$this->deleteOption('customurl_tabledel');
		$this->deleteOption('customurl_quicklink');
		$this->deleteBlogOption('use_customurl');
		$this->deleteBlogOption('redirect_normal');
		$this->deleteBlogOption('redirect_search');
		$this->deleteBlogOption('customurl_bname');
//		$this->deleteItemOption('customurl_iname');
		$this->deleteMemberOption('customurl_mname');
		$this->deleteCategoryOption('customurl_cname');
	}
 
	function event_ParseURL($data)
	{
		global $CONF, $manager, $curl_blogid, $blogid, $itemid, $catid;
		global $memberid, $archivelist, $archive, $query;
// initialize
		$info     =  $data['info'];
		$complete =& $data['complete'];
		if ($complete) return;
		$useCustomURL = $this->getAllBlogOptions('use_customurl');
 
// Use NP_MultipleCategories ?
		$mcategories = $this->pluginCheck('MultipleCategories');
		if ($mcategories) {
			if (method_exists($mcategories, "getRequestName")) {
				$mcategories->event_PreSkinParse(array());
				global $subcatid;
				$subrequest = $mcategories->getRequestName();
			}
		}
		if (!$subrequest) {
			$subrequest = 'subcatid';
		}
 
// initialize and sanitize '$blogid'
		if (!$blogid) {
			if ( getVar('blogid') ) {
				if ( is_numeric(getVar('blogid')) ) {
					$blogid = intval(getVar('blogid'));
				} else {
					$blogid = intval(getBlogIDFromName(getVar('blogid')));
				}
			} elseif ($curl_blogid) {
				$blogid = intval($curl_blogid);
			} else {
				$blogid = $CONF['DefaultBlog'];
			}
		} else {
			if (is_numeric($blogid)) {
				$blogid = intval($blogid);
			} else {
				$blogid = intval(getBlogIDFromName($blogid));
			}
		}
 
		if (!$info) {
			if (serverVar('PATH_INFO')) {
				$info = serverVar('PATH_INFO');
			} elseif (getNucleusVersion() < 330) {
				if (getVar('virtualpath')) {
					$info = getVar('virtualpath');
				}
			} else {
				return;
			}
		}
 
// Sanitize 'PATH_INFO'
		$info = trim($info, '/');
		$v_path = explode("/", $info);
		foreach($v_path as $key => $value) {
			$value = urlencode($value);
			$value = preg_replace('|[^a-zA-Z0-9-~+_.?#=&;,/:@%]|i', '', $value);
			$v_path[$key] = $value;
		}
		if (phpversion() >= '4.1.0') {
			$_SERVER['PATH_INFO'] = implode('/', $v_path);
		}
		global $HTTP_SERVER_VARS;
		$HTTP_SERVER_VARS['PATH_INFO'] = implode('/', $v_path);
 
// Admin area check
		$tmpURL = sprintf("%s%s%s", "http://", serverVar("HTTP_HOST"), serverVar("SCRIPT_NAME"));
		$uri = str_replace('/', '\/', $tmpURL);
		$plug_url = str_replace('/', '\/', $CONF['PluginURL']);
		$u_plugAction = (getVar('action') == 'plugin' && getVar('name'));
		if (strpos($uri, $plug_url) === 0 || $u_plugAction) {
			$UsingPlugAdmin = TRUE;
		}
 
// redirect to other URL style
		$useCustomURLyes = ($useCustomURL[$blogid] == 'yes');
		if ($useCustomURLyes && !$UsingPlugAdmin && !$CONF['UsingAdminArea']) {
// Search query redirection
// 301 permanent ? or 302 temporary ?
			$queryURL = (strpos(serverVar('REQUEST_URI'), 'query=') !== FALSE);
			$search_q = (getVar('query') || $queryURL);
			$redirectSerch = ($this->getBlogOption($blogid, 'redirect_search') == 'yes');
			if ($redirectSerch) {
				if ($search_q) {
					$que_str = getVar('query');
					$que_str = htmlspecialchars($que_str);
					$que_str = mb_eregi_replace('/', 'ssslllaaassshhh', $que_str);
					$que_str = mb_eregi_replace("'", 'qqquuuooottt', $que_str);
					$que_str = mb_eregi_replace('&', 'aaammmppp', $que_str);
					$que_str = urlencode($que_str);
					$search_path = '/search/' . $que_str;
					$b_url = createBlogidLink($blogid);
					$redurl = sprintf("%s%s", $b_url, $search_path);
					redirect($redurl); // 302 Moved temporary
					exit;
				}
			}
			if (!$redirectSerch && $search_q) {
				$exLink = TRUE;
			}
 
// redirection nomal URL to FancyURL
			$temp_req = explode('?', serverVar('REQUEST_URI'));
			$reqPath  = trim(end($temp_req), '/');
			$indexrdf = ($reqPath == 'xml-rss1.php');
			$atomfeed = ($reqPath == 'atom.php');
			$rss2feed = ($reqPath == 'xml-rss2.php');
			$feeds    = ($indexrdf || $atomfeed || $rss2feed);
			$redirectNormal = ($this->getBlogOption($blogid, 'redirect_normal') == 'yes');
			if ($redirectNormal && serverVar('QUERY_STRING') && !$feeds && !$exLink) {
				$temp = explode('&', serverVar('QUERY_STRING'));
				foreach ($temp as $k => $val) {
					if (preg_match('/^virtualpath/', $val)) {
						unset($temp[$k]);
					}
				}
				if (!empty($temp)) {
					$p_arr = array();
					foreach ($temp as $key => $value) {
						$p_key = explode('=', $value);
						switch (reset($p_key)) {
							case 'blogid';
								$p_arr[] = $CONF['BlogKey'] . '/'
										 . intGetVar('blogid');
								unset($temp[$key]);
								break;
							case 'catid';
								$p_arr[] = $CONF['CategoryKey'] . '/'
										 . intGetVar('catid');
								unset($temp[$key]);
								break;
							case $subrequest;
								$p_arr[] = $subrequest . '/'
										 . intGetVar($subrequest);
								unset($temp[$key]);
								break;
							case 'itemid';
								$p_arr[] = $CONF['ItemKey'] . '/'
										 . intGetVar('itemid');
								unset($temp[$key]);
								break;
							case 'memberid';
								$p_arr[] = $CONF['MemberKey'] . '/'
										 . intGetVar('memberid');
								unset($temp[$key]);
								break;
							case 'archivelist';
								$p_arr[] = $CONF['ArchivesKey'] . '/'
										 . $blogid;
								unset($temp[$key]);
								break;
							case 'archive';
								$p_arr[] = $CONF['ArchiveKey'] . '/'
										 . $blogid . '/' . getVar('archive');
								unset($temp[$key]);
								break;
							default:
								break;
						}
					}
					if (reset($p_arr)) {
						$b_url = createBlogidLink($blogid);
						$red_path = '/' . implode('/', $p_arr);
						if (substr($b_url, -1) == '/') {
							$b_url = rtrim($b_url, '/');
						}
						$redurl = sprintf("%s%s", $b_url, $red_path);
						// HTTP status 301 "Moved Permanentry"
						header( "HTTP/1.1 301 Moved Permanently" );
						header('Location: ' . $redurl);
						exit;
					}
				}
			} elseif ($redirectNormal && $feeds) {
				$b_url = rtrim(createBlogidLink($blogid), '/');
				switch ($reqPath) {
					case 'xml-rss1.php':
						$feed_code = '/index.rdf';
						break;
					case 'xml-rss2.php':
						$feed_code = '/rss2.xml';
						break;
					case 'atom.php':
						$feed_code = '/atom.xml';
						break;
					default:
						break;
				}
				// HTTP status 301 "Moved Permanentry"
				header('HTTP/1.1 301 Moved Permanently');
				header('Location: ' . $b_url . $feed_code);
				exit;
			}
		}
// decode path_info
 
// decode unofficial Page switch '/page_2.html'
		foreach($v_path as $pathName) {
			if (preg_match('/^page_/', $pathName)) {
				$temp_info = explode('page_', $pathName);
				$_GET['page'] = intval($temp_info[1]);
				$page = array_pop($v_path);
			}
		}
 
// decode TrackBack URL shorten ver.
		$tail = end($v_path);
		if (substr($tail, -10, 10) == '.trackback') {
			$v_pathName = substr($tail, 0, -10);
//			echo $v_pathName;
			if (is_numeric($v_pathName)) {
				$this->_trackback($blogid, $v_pathName);
			} else {
				$this->_trackback($blogid, $v_pathName . '.html');
			}
			return;
		}
 
// decode other type URL
		$bLink = $cLink = $iLink = $exLink = FALSE;
		if (empty($info)) {
			$bLink = TRUE;
		}
		$linkObj = array (
			'bid' => 0,
			'name' => reset($v_path),
			'linkparam' => 'blog'
		);
		$blog_id = $this->getRequestPathInfo($linkObj);
		if ($blog_id) {
			$blogid = $blog_id;
			$trush = array_shift($v_path);
			$bLink = TURE;
		}
		if ($useCustomURL[$blogid] == 'no') {
			return;
		}
		$i = 1;
		foreach($v_path as $pathName) {
			switch ($pathName) {
// decode FancyURLs and redirection to Customized URL
				// for blogsgetAllBlogOptions($name)
				case $CONF['BlogKey']:
					if (isset($v_path[$i]) && is_numeric($v_path[$i])) {
						if ($useCustomURL[intval($v_path[$i])] != 'yes') {
							$blogid = intval($v_path[$i]);
							$bLink = TRUE;
						} else {
							$redURI = createBlogidLink(intval($v_path[$i]));
						}
					}
				break;
				// for items
				case $CONF['ItemKey']:
					if (isset($v_path[$i]) && is_numeric($v_path[$i])) {
						if ($useCustomURL[$blogid] != 'yes') {
							$itemid = intval($v_path[$i]);
							$iLink = TRUE;
						} else {
							$redURI = createItemLink(intval($v_path[$i]));
						}
					}
				break;
				// for categories
				case $CONF['CategoryKey']:
				case 'catid':
					if (isset($v_path[$i]) && is_numeric($v_path[$i])) {
						if ($useCustomURL[$blogid] != 'yes') {
							$catid = intval($v_path[$i]);
							$cLink = TRUE;
						} else {
							$redURI = createCategoryLink(intval($v_path[$i]));
						}
					}
				break;
				// for subcategories
				case $subrequest:
					$c = $i - 2;
					$subCat = (isset($v_path[$i]) && is_numeric($v_path[$i]));
					if ($mcategories && $subCat && $i >= 3 && is_numeric($v_path[$c])) {
						if ($useCustomURL[$blogid] != 'yes') {
							$subcatid = intval($v_path[$i]);
							$catid    = intval($v_path[$c]);
							$cLink    = TRUE;
						} else {
							$subcat_id = intval($v_path[$i]);
							$catid     = intval($v_path[$c]);
							$linkParam = array($subrequest => $subcat_id);
							$redURI   = createCategoryLink($catid, $linkParam);
						}
					}
				break;
				// for archives
				case $CONF['ArchivesKey']:
				case $this->getOption('customurl_archives'):
				// FancyURL
					if (isset($v_path[$i]) && is_numeric($v_path[$i])) {
						if ($useCustomURL[intval($v_path[$i])] != 'yes') {
							$archivelist = intval($v_path[$i]);
							$blogid = $archivelist;
							$exLink = TRUE;
						} else {
							$redURI = createArchiveListLink(intval($v_path[$i]));
						}
				// Customized URL
					} elseif (isset($v_path[$i])) {
						$archivelist = $blogid;
						$redURI = createArchiveListLink($archivelist);
					} else {
						$archivelist = $blogid;
						$exLink = TRUE;
					}
				break;
				// for archive
				case $CONF['ArchiveKey']:
				case $this->getOption('customurl_archive'):
					$y = $m = $d = '';
					$ar = $i + 1;
					if (isset($v_path[$i])) {
						$darc  = (ereg('([0-9]{4})-([0-9]{1,2})-([0-9]{1,2})', $v_path[$i]));
						$marc  = (ereg('([0-9]{4})-([0-9]{1,2})', $v_path[$i]));
						$yarc  = (ereg('([0-9]{4})', $v_path[$i]));
						$adarc = (ereg('([0-9]{4})-([0-9]{1,2})-([0-9]{1,2})', $v_path[$ar]));
						$amarc = (ereg('([0-9]{4})-([0-9]{1,2})', $v_path[$ar]));
						$ayarc = (ereg('([0-9]{4})', $v_path[$ar]));
						$arc   = (!$darc && !$marc && !$yarc);
						$aarc  = ($adarc || $amarc || $ayarc);
						$carc  = ($darc || $marc || $yarc);
				// FancyURL
//						if (is_numeric($v_path[$i]) && !$darc && !$marc && !$yarc && isset($v_path[$ar]) && ($adarc || $amarc || $ayarc)) {
						if (is_numeric($v_path[$i]) && $arc && isset($v_path[$ar]) && $aarc) {
								sscanf($v_path[$ar], '%d-%d-%d', $y, $m, $d);
							if (!empty($d)) {
								$archive = sprintf('%04d-%02d-%02d', $y, $m, $d);
							} elseif (!empty($m)) {
								$archive = sprintf('%04d-%02d', $y, $m);
							} else {
								$archive = sprintf('%04d', $y);
							}
							if ($useCustomURL[intval($v_path[$i])] != 'yes') {
								$blogid = intval($v_path[$i]);
								$exLink = TRUE;
							} else {
								$blogid = intval($v_path[$i]);
								$redURI = createArchiveLink($blogid, $archive);
							}
				// Customized URL
//						} elseif ($darc || $marc || $yarc) {
						} elseif ($carc) {
							sscanf($v_path[$i], '%d-%d-%d', $y, $m, $d);
							if (isset($d)) {
								$archive = sprintf('%04d-%02d-%02d', $y, $m, $d);
							} elseif (!empty($m)) {
								$archive = sprintf('%04d-%02d', $y, $m);
							} else {
								$archive = sprintf('%04d', $y);
							}
							$exLink = TRUE;
						} else {
							$redURI = createArchiveListLink($blogid);
						}
					} else {
						$redURI = createArchiveListLink($blogid);
					}
				break;
				// for member
				case $CONF['MemberKey']:
				case $this->getOption('customurl_member'):
				// Customized URL
					$customMemberURL = (substr($v_path[$i], -5, 5) == '.html');
					if (isset($v_path[$i]) && $customMemberURL) {
						$memberInfo = array('linkparam' => 'member',
											'bid' => 0,
											'name' => $v_path[$i]);
						$member_id = $this->getRequestPathInfo($memberInfo);
						$memberid = intval($member_id);
						$exLink = TRUE;
				// FancyURL
					} elseif (isset($v_path[$i]) && is_numeric($v_path[$i])) {
						if ($useCustomURL[$blogid] != 'yes') {
							$memberid = intval($v_path[$i]);
							$exLink   = TRUE;
						} else {
							$redURI = createMemberLink(intval($v_path[$i]));
						}
					} else {
						$redURI = createBlogidLink($blogid);
					}
				break;
				// for tag
				case 'tag':
					if (isset($v_path[$i]) && is_string($v_path[$i])) {
						$_REQUEST['tag'] = $v_path[$i];
						$exLink = TRUE;
					}
				break;
				// for ExtraSkinJP
				case 'extra':
					$ExtraSkinJP = $this->pluginCheck('ExtraSkinJP');
					if ($ExtraSkinJP) {
						// under v3.2 needs this
						if ($CONF['DisableSite'] && !$member->isAdmin()) {
							header('Location: ' . $CONF['DisableSiteURL']);
							exit;
						}
						$extraParams = explode("/", serverVar('PATH_INFO'));
						array_shift ($extraParams);
 
					if (isset($extraParams[1]) && preg_match("/^([1-9]+[0-9]*)(\?.*)?$/", $extraParams[1], $matches)) {
						$extraParams[1] = $matches[1];
					}
 
						$ExtraSkinJP->extra_selector($extraParams);
						exit;
					}
				break;
				// for search query
				case 'search':
					$redirectSerch = ($this->getBlogOption($blogid, 'redirect_search') == 'yes');
					if ($redirectSerch) {
						$que_str = urldecode($v_path[$i]);
						$que_str = mb_eregi_replace('ssslllaaassshhh', '/', $que_str);
						$que_str = mb_eregi_replace('qqquuuooottt',    "'", $que_str);
						$que_str = mb_eregi_replace('aaammmppp',       '&', $que_str);
						$que_str = htmlspecialchars_decode($que_str);
						$_GET['query'] = $que_str;
						$query  = $que_str;
						$exLink = TRUE;
					}
				break;
				// for pageswitch
				case 'page':
					if (isset($v_path[$i]) && is_numeric($v_path[$i])) {
						$_GET['page'] = intval($v_path[$i]);
						$exLink = TRUE;
					}
				break;
				// for tDiarySkin
				case 'tdiarydate':
				case 'categorylist':
				case 'monthlimit':
					$tDiaryPlugin = $this->pluginCheck('tDiarySkin');
					if ($tDiaryPlugin && isset($v_path[$i])) {
//						sscanf($v_path[$i], '%d-%d', $m, $d);
//						$linkDate = sprintf('%02d-%02d', $m, $d);
//						$_GET['linkdate'] = $linkDate;
						$_GET[$pathName] = $v_path[$i];
						$exLink = TRUE;
					}
				break;
				// for trackback
				case 'trackback':
					if (isset($v_path[$i]) && is_string($v_path[$i])) {
						$this->_trackback($blogid, $v_path[$i]);
					}
					return;
				break;
 
// decode Customized URL
				default:
				// initialyze
					$linkObj = array ('bid' => $blogid,
									  'name' => $pathName
									 );
					$comp = FALSE;
					$isItem = (substr($pathName, -5) == '.html');
				// category ?
					if (!$comp && !$cLink && !$iLink && !$isItem) {
						$linkObj['linkparam'] = 'category';
						$cat_id = $this->getRequestPathInfo($linkObj);
						if (!empty($cat_id)) {
							$catid = intval($cat_id);
							$cLink = TURE;
							$comp  = TRUE;
						}
					}
				// subcategory ?
					if (!$comp && $cLink && !$iLink && $mcategories && !$isItem) {
						$linkObj['linkparam'] = 'subcategory';
						$linkObj['bid']       = $catid;
						<