• R/O
  • HTTP
  • SSH
  • HTTPS

nucleus-plugins: Commit

Nucleus CMS日本語版用プラグインのうち、日本語版開発者がサポートしているもの


Commit MetaInfo

Revision88a3753657ee759f6ab2ee877a448e73b8afa470 (tree)
Time2006-11-29 14:53:32
Authorshizuki <shizuki@1ca2...>
Commitershizuki

Log Message

fix linkParamArr is empty

git-svn-id: https://svn.sourceforge.jp/svnroot/nucleus-jp/plugin@500 1ca29b6e-896d-4ea0-84a5-967f57386b96

Change Summary

Incremental Difference

--- a/trunk/NP_CustomURL/NP_CustomURL.php
+++ b/trunk/NP_CustomURL/NP_CustomURL.php
@@ -1,2419 +1,5 @@
11 <?php
22
3-if (!function_exists('sql_table')) {
4- function sql_table($name)
5- {
6- return 'nucleus_' . $name;
7- }
8-}
9-
10-if (!function_exists('htmlspecialchars_decode')) {
11- function htmlspecialchars_decode($text)
12- {
13- return strtr($text, array_flip(get_html_translation_table(HTML_SPECIALCHARS)));
14- }
15-}
16-
17-if (!defined('_CUSTOMURL_TABLE_DEFINED')) {
18- define('_CUSTOMURL_TABLE_DEFINED', 1);
19- define('_CUSTOMURL_TABLE', sql_table('plug_customurl'));
20- define('_C_SUBCAT_TABLE', sql_table('plug_multiple_categories_sub'));
21-}
22-
23-class NP_CustomURL extends NucleusPlugin
24- {
25-
26- function getMinNucleusVersion()
27- {
28- return '322';
29- }
30-
31- function getName()
32- {
33- return 'Customized URL';
34- }
35-
36- function getAuthor()
37- {
38- return 'shizuki';
39- }
40-
41- function getURL()
42- {
43- return 'http://shizuki.kinezumi.net/NucleusCMS/Plugins/NP_CustomURL/NP_CustomURL.html';
44- }
45-
46- function getVersion()
47- {
48- return '0.3.2c';
49- }
50-
51- function getDescription()
52- {
53- return _DESCRIPTION;
54- }
55-
56- function supportsFeature($what)
57- {
58- switch($what) {
59- case 'SqlTablePrefix':
60- return 1;
61- case 'HelpPage':
62- return 1;
63- default:
64- return 0;
65- }
66- }
67-
68- function hasAdminArea()
69- {
70- return 1;
71- }
72-
73- function event_QuickMenu(&$data)
74- {
75- global $member;
76- $quickLink = ($this->getOption( 'customurl_quicklink') == 'yes');
77- $memberCheck = ($member->isLoggedIn() && $member->isAdmin());
78- if (!$quickLink || !$memberCheck) {
79- return;
80- }
81- array_push(
82- $data['options'],
83- array(
84- 'title' => _ADMIN_TITLE,
85- 'url' => $this->getAdminURL(),
86- 'tooltip' => _QUICK_TIPS
87- )
88- );
89- }
90-
91- function getTableList()
92- {
93- return array(
94- _CUSTOMURL_TABLE
95- );
96- }
97-
98- function getEventList()
99- {
100- return array(
101- 'QuickMenu',
102-// 'AdminPrePageHead',
103- 'ParseURL',
104- 'GenerateURL',
105- 'PostAddBlog',
106- 'PostAddItem',
107- 'PostUpdateItem',
108- 'PostRegister',
109- 'PostAddCategory',
110- 'PostDeleteBlog',
111- 'PostDeleteItem',
112- 'PostDeleteMember',
113- 'PostDeleteCategory',
114- 'PrePluginOptionsUpdate',
115- 'PreItem',
116- 'PostItem',
117- 'PreSkinParse',
118- 'AddItemFormExtras',
119- 'EditItemFormExtras',
120- 'PostMoveCategory',
121- 'PostMoveItem',
122-// 'PreSendContentType',
123- 'InitSkinParse',
124- );
125- }
126-
127-// function event_AdminPrePageHead($data)
128-// {
129-// if ($data['action'] == 'pluginhelp' && intGetVar('plugid') == $this->getID()) {
130-// $data['extrahead'] = '<link rel="stylesheet" title="NP_CustomURL HELP"'
131-// . ' type="text/css"'
132-// . "\n"
133-// . "\t\t\t"
134-// . ' href="' . $this->getAdminURL()
135-// . 'helpstyle.css" />' . "\n";
136-// }
137-// }
138-
139- function install()
140- {
141- global $manager, $CONF;
142-// Keys initialize
143- if (empty($CONF['ArchiveKey'])) {
144- $CONF['ArchiveKey'] = 'archive';
145- }
146- if (empty($CONF['ArchivesKey'])) {
147- $CONF['ArchivesKey'] = 'archives';
148- }
149- if (empty($CONF['MemberKey'])) {
150- $CONF['MemberKey'] = 'member';
151- }
152- if (empty($CONF['ItemKey'])) {
153- $CONF['ItemKey'] = 'item';
154- }
155- if (empty($CONF['CategoryKey'])) {
156- $CONF['CategoryKey'] = 'category';
157- }
158-
159-//Plugins sort
160- $myid = intval($this->getID());
161- $res = sql_query('SELECT pid, porder FROM '.sql_table('plugin'));
162- while($p = mysql_fetch_array($res)) {
163- $updateQuery = 'UPDATE %s SET porder = %d WHERE pid = %d';
164- if (intval($p['pid']) == $myid) {
165- sql_query(sprintf($updateQuery, sql_table('plugin'), 1, $myid));
166- } else {
167- sql_query(sprintf($updateQuery, sql_table('plugin'), $p['porder']+1, $p['pid']));
168- }
169- }
170-
171-//create plugin's options and set default value
172- $this->createOption('customurl_archive', _OP_ARCHIVE_DIR_NAME,
173- 'text', $CONF['ArchiveKey']);
174- $this->createOption('customurl_archives', _OP_ARCHIVES_DIR_NAME,
175- 'text', $CONF['ArchivesKey']);
176- $this->createOption('customurl_member', _OP_MEMBER_DIR_NAME,
177- 'text', $CONF['MemberKey']);
178- $this->createOption('customurl_dfitem', _OP_DEF_ITEM_KEY,
179- 'text', $CONF['ItemKey']);
180- $this->createOption('customurl_dfcat', _OP_DEF_CAT_KEY,
181- 'text', $CONF['CategoryKey']);
182- $this->createOption('customurl_dfscat', _OP_DEF_SCAT_KEY,
183- 'text', 'subcategory');
184- $this->createOption('customurl_tabledel', _OP_TABLE_DELETE,
185- 'yesno', 'no');
186- $this->createOption('customurl_quicklink', _OP_QUICK_LINK,
187- 'yesno', 'yes');
188- $this->createOption('customurl_notfound', _OP_NOT_FOUND,
189- 'select', '404',
190- '404 Not Found|404|303 See Other|303');
191- $this->createBlogOption( 'use_customurl', _OP_USE_CURL,
192- 'yesno', 'yes');
193- $this->createBlogOption( 'redirect_normal', _OP_RED_NORM,
194- 'yesno', 'yes');
195- $this->createBlogOption( 'redirect_search', _OP_RED_SEARCH,
196- 'yesno', 'yes');
197- $this->createBlogOption( 'customurl_bname', _OP_BLOG_PATH,
198- 'text');
199-// $this->createItemOption( 'customurl_iname', _OP_ITEM_PATH,
200-// 'text', $CONF['ItemKey']);
201- $this->createMemberOption( 'customurl_mname', _OP_MEMBER_PATH,
202- 'text');
203- $this->createCategoryOption('customurl_cname', _OP_CATEGORY_PATH,
204- 'text');
205-
206- //default archive directory name
207- $this->setOption('customurl_archive', $CONF['ArchiveKey']);
208- //default archives directory name
209- $this->setOption('customurl_archives', $CONF['ArchivesKey']);
210- //default member directory name
211- $this->setOption('customurl_member', $CONF['MemberKey']);
212- //default itemkey_template
213- $this->setOption('customurl_dfitem', $CONF['ItemKey']);
214- //default categorykey_template
215- $this->setOption('customurl_dfcat', $CONF['CategoryKey']);
216- //default subcategorykey_template
217- $this->setOption('customurl_dfscat', 'subcategory');
218-
219-//create data table
220- $sql = 'CREATE TABLE IF NOT EXISTS ' . _CUSTOMURL_TABLE . ' ('
221- . ' `id` INT(11) NOT NULL AUTO_INCREMENT PRIMARY KEY, '
222- . ' `obj_param` VARCHAR(15) NOT NULL, '
223- . ' `obj_name` VARCHAR(128) NOT NULL, '
224- . ' `obj_id` INT(11) NOT NULL, '
225- . ' `obj_bid` INT(11) NOT NULL,'
226- . ' INDEX (`obj_name`)'
227- . ' )';
228- sql_query($sql);
229-
230-//setting default aliases
231- $this->_createNewPath('blog', 'blog', 'bnumber', 'bshortname');
232- $this->_createNewPath('item', 'item', 'inumber', 'iblog');
233- $this->_createNewPath('category', 'category', 'catid', 'cblog');
234- $this->_createNewPath('member', 'member', 'mnumber', 'mname');
235-
236- if ($this->pluginCheck('MultipleCategories')) {
237- $this->_createNewPath('subcategory', 'plug_multiple_categories_sub', 'scatid', 'catid');
238- }
239-
240- }
241-
242- function _createNewPath($type, $n_table, $id, $bids)
243- {
244- $tmpTable = sql_table('plug_customurl_temp');
245- $createQuery = 'CREATE TABLE %s SELECT obj_id, obj_param FROM %s'
246- . ' WHERE obj_param = "%s"';
247- sql_query(sprintf($createQuery, $tmpTable, _CUSTOMURL_TABLE, $type));
248- $TmpQuery = 'SELECT %s, %s FROM %s LEFT JOIN %s ON %s.%s = %s.obj_id'
249- . ' WHERE %s.obj_id is null';
250- $table = sql_table($n_table);
251- $temp = sql_query(sprintf($TmpQuery, $id, $bids, $table, $tmpTable, $table, $id, $tmpTable, $tmpTable));
252- if ($temp) {
253- while ($row=mysql_fetch_array($temp)) {
254- switch ($type) {
255- case 'blog':
256- //set access by BlogshortName/
257- $newPath = $row[$bids];
258- $blgid = 0;
259- break;
260- case 'item':
261- //set access by (itemkey_template)_itemid.html
262- $tque = 'SELECT itime as result FROM %s WHERE inumber = %d';
263- $itime = quickQuery( sprintf($tque ,sql_table('item'), intval($row[$id]) ) );
264- $y = $m = $d = '';
265- sscanf($itime,'%d-%d-%d %s',$y,$m,$d,$temp);
266- $ikey = TEMPLATE::fill($this->getOption('customurl_dfitem'),
267- array ('year' => $y,
268- 'month' => $m,
269- 'day' => $d)
270- );
271- $newPath = $ikey . '_' . $row[$id] . '.html';
272- $blgid = $row[$bids];
273- break;
274- case 'category':
275- //set access by (categorykey_template)_categoryid/
276- $newPath = $this->getOption('customurl_dfcat') . '_' . $row[$id];
277- $blgid = $row[$bids];
278- break;
279- case 'member':
280- //set access by loginName.html
281- $newPath = $row[$bids] . '.html';
282- $blgid = 0;
283- break;
284- case 'subcategory':
285- //set access by (subcategorykey_template)_subcategoryid/
286- $newPath = $this->getOption('customurl_dfscat') . '_' . $row[$id];
287- $blgid = $row[$bids];
288- break;
289- default:
290- break;
291- }
292- $insertQuery = 'INSERT INTO %s (obj_param, obj_id, obj_name, obj_bid)'
293- . ' VALUES ("%s", %d, "%s", %d)';
294- $row[$id] = intval($row[$id]);
295- $blgid = intval($blgid);
296- sql_query(sprintf($insertQuery, _CUSTOMURL_TABLE, $type, $row[$id], $newPath, $blgid));
297- }
298- }
299- $query = 'SELECT obj_id, obj_name FROM %s WHERE obj_param = "%s"';
300- $temp = sql_query(sprintf($query, _CUSTOMURL_TABLE, $type));
301- while ($row = mysql_fetch_array($temp)) {
302- $name = $row['obj_name'];
303- $id = intval($row['obj_id']);
304- switch ($type) {
305- case 'blog':
306- $this->setBlogOption($id, 'customurl_bname', $name);
307- break;
308- case 'category':
309- $this->setCategoryOption($id, 'customurl_cname', $name);
310- break;
311- case 'member':
312- $obj_name = substr($name, 0, -5);
313- $this->setMemberOption($id, 'customurl_mname', $obj_name);
314- break;
315- default:
316- break;
317- }
318- }
319-
320- sql_query('DROP TABLE IF EXISTS ' . $tmpTable);
321- }
322-
323- function init()
324- {
325- global $admin;
326- $language = ereg_replace( '[\\|/]', '', getLanguageName());
327- if (file_exists($this->getDirectory() . 'language/' . $language . '.php')) {
328- include_once($this->getDirectory() . 'language/' . $language . '.php');
329- } else {
330- include_once($this->getDirectory() . 'language/english.php');
331- }
332- }
333-
334- function pluginCheck($pluginName)
335- {
336- global $manager;
337- if (!$manager->pluginInstalled('NP_' . $pluginName)) {
338- return;
339- }
340- $plugin =& $manager->getPlugin('NP_' . $pluginName);
341- return $plugin;
342- }
343-
344- function unInstall()
345- {
346- if ($this->getOption('customurl_tabledel') == 'yes') {
347- sql_query("DROP TABLE "._CUSTOMURL_TABLE);
348- }
349- $this->deleteOption('customurl_archive');
350- $this->deleteOption('customurl_archives');
351- $this->deleteOption('customurl_member');
352- $this->deleteOption('customurl_dfitem');
353- $this->deleteOption('customurl_dfcat');
354- $this->deleteOption('customurl_dfscat');
355- $this->deleteOption('customurl_notfound');
356- $this->deleteOption('customurl_tabledel');
357- $this->deleteOption('customurl_quicklink');
358- $this->deleteBlogOption('use_customurl');
359- $this->deleteBlogOption('redirect_normal');
360- $this->deleteBlogOption('redirect_search');
361- $this->deleteBlogOption('customurl_bname');
362-// $this->deleteItemOption('customurl_iname');
363- $this->deleteMemberOption('customurl_mname');
364- $this->deleteCategoryOption('customurl_cname');
365- }
366-
367- function event_ParseURL($data)
368- {
369- global $CONF, $manager, $curl_blogid, $blogid, $itemid, $catid;
370- global $memberid, $archivelist, $archive, $query;
371-// initialize
372- $info = $data['info'];
373- $complete =& $data['complete'];
374- if ($complete) return;
375- $useCustomURL = $this->getAllBlogOptions('use_customurl');
376-
377-// Use NP_MultipleCategories ?
378- $mcategories = $this->pluginCheck('MultipleCategories');
379- if ($mcategories) {
380- if (method_exists($mcategories, "getRequestName")) {
381- $mcategories->event_PreSkinParse(array());
382- global $subcatid;
383- $subrequest = $mcategories->getRequestName();
384- }
385- }
386- if (!$subrequest) {
387- $subrequest = 'subcatid';
388- }
389-
390-// initialize and sanitize '$blogid'
391- if (!$blogid) {
392- if ( getVar('blogid') ) {
393- if ( is_numeric(getVar('blogid')) ) {
394- $blogid = intval(getVar('blogid'));
395- } else {
396- $blogid = intval(getBlogIDFromName(getVar('blogid')));
397- }
398- } elseif ($curl_blogid) {
399- $blogid = intval($curl_blogid);
400- } else {
401- $blogid = $CONF['DefaultBlog'];
402- }
403- } else {
404- if (is_numeric($blogid)) {
405- $blogid = intval($blogid);
406- } else {
407- $blogid = intval(getBlogIDFromName($blogid));
408- }
409- }
410-
411- if (!$info) {
412- if (serverVar('PATH_INFO')) {
413- $info = serverVar('PATH_INFO');
414- } elseif (getNucleusVersion() < 330) {
415- if (getVar('virtualpath')) {
416- $info = getVar('virtualpath');
417- }
418- } else {
419- return;
420- }
421- }
422-
423-// Sanitize 'PATH_INFO'
424- $info = trim($info, '/');
425- $v_path = explode("/", $info);
426- foreach($v_path as $key => $value) {
427- $value = urlencode($value);
428- $value = preg_replace('|[^a-zA-Z0-9-~+_.?#=&;,/:@%]|i', '', $value);
429- $v_path[$key] = $value;
430- }
431- if (phpversion() >= '4.1.0') {
432- $_SERVER['PATH_INFO'] = implode('/', $v_path);
433- }
434- global $HTTP_SERVER_VARS;
435- $HTTP_SERVER_VARS['PATH_INFO'] = implode('/', $v_path);
436-
437-// Admin area check
438- $tmpURL = sprintf("%s%s%s", "http://", serverVar("HTTP_HOST"), serverVar("SCRIPT_NAME"));
439- $uri = str_replace('/', '\/', $tmpURL);
440- $plug_url = str_replace('/', '\/', $CONF['PluginURL']);
441- $u_plugAction = (getVar('action') == 'plugin' && getVar('name'));
442- if (strpos($uri, $plug_url) === 0 || $u_plugAction) {
443- $UsingPlugAdmin = TRUE;
444- }
445-
446-// redirect to other URL style
447- $useCustomURLyes = ($useCustomURL[$blogid] == 'yes');
448- if ($useCustomURLyes && !$UsingPlugAdmin && !$CONF['UsingAdminArea']) {
449-// Search query redirection
450-// 301 permanent ? or 302 temporary ?
451- $queryURL = (strpos(serverVar('REQUEST_URI'), 'query=') !== FALSE);
452- $search_q = (getVar('query') || $queryURL);
453- $redirectSerch = ($this->getBlogOption($blogid, 'redirect_search') == 'yes');
454- if ($redirectSerch) {
455- if ($search_q) {
456- $que_str = getVar('query');
457- $que_str = htmlspecialchars($que_str);
458- $que_str = mb_eregi_replace('/', 'ssslllaaassshhh', $que_str);
459- $que_str = mb_eregi_replace("'", 'qqquuuooottt', $que_str);
460- $que_str = mb_eregi_replace('&', 'aaammmppp', $que_str);
461- $que_str = urlencode($que_str);
462- $search_path = '/search/' . $que_str;
463- $b_url = createBlogidLink($blogid);
464- $redurl = sprintf("%s%s", $b_url, $search_path);
465- redirect($redurl); // 302 Moved temporary
466- exit;
467- }
468- }
469- if (!$redirectSerch && $search_q) {
470- $exLink = TRUE;
471- }
472-
473-// redirection nomal URL to FancyURL
474- $temp_req = explode('?', serverVar('REQUEST_URI'));
475- $reqPath = trim(end($temp_req), '/');
476- $indexrdf = ($reqPath == 'xml-rss1.php');
477- $atomfeed = ($reqPath == 'atom.php');
478- $rss2feed = ($reqPath == 'xml-rss2.php');
479- $feeds = ($indexrdf || $atomfeed || $rss2feed);
480- $redirectNormal = ($this->getBlogOption($blogid, 'redirect_normal') == 'yes');
481- if ($redirectNormal && serverVar('QUERY_STRING') && !$feeds && !$exLink) {
482- $temp = explode('&', serverVar('QUERY_STRING'));
483- foreach ($temp as $k => $val) {
484- if (preg_match('/^virtualpath/', $val)) {
485- unset($temp[$k]);
486- }
487- }
488- if (!empty($temp)) {
489- $p_arr = array();
490- foreach ($temp as $key => $value) {
491- $p_key = explode('=', $value);
492- switch (reset($p_key)) {
493- case 'blogid';
494- $p_arr[] = $CONF['BlogKey'] . '/'
495- . intGetVar('blogid');
496- unset($temp[$key]);
497- break;
498- case 'catid';
499- $p_arr[] = $CONF['CategoryKey'] . '/'
500- . intGetVar('catid');
501- unset($temp[$key]);
502- break;
503- case $subrequest;
504- $p_arr[] = $subrequest . '/'
505- . intGetVar($subrequest);
506- unset($temp[$key]);
507- break;
508- case 'itemid';
509- $p_arr[] = $CONF['ItemKey'] . '/'
510- . intGetVar('itemid');
511- unset($temp[$key]);
512- break;
513- case 'memberid';
514- $p_arr[] = $CONF['MemberKey'] . '/'
515- . intGetVar('memberid');
516- unset($temp[$key]);
517- break;
518- case 'archivelist';
519- $p_arr[] = $CONF['ArchivesKey'] . '/'
520- . $blogid;
521- unset($temp[$key]);
522- break;
523- case 'archive';
524- $p_arr[] = $CONF['ArchiveKey'] . '/'
525- . $blogid . '/' . getVar('archive');
526- unset($temp[$key]);
527- break;
528- default:
529- break;
530- }
531- }
532- if (reset($p_arr)) {
533- $b_url = createBlogidLink($blogid);
534- $red_path = '/' . implode('/', $p_arr);
535- if (substr($b_url, -1) == '/') {
536- $b_url = rtrim($b_url, '/');
537- }
538- $redurl = sprintf("%s%s", $b_url, $red_path);
539- // HTTP status 301 "Moved Permanentry"
540- header( "HTTP/1.1 301 Moved Permanently" );
541- header('Location: ' . $redurl);
542- exit;
543- }
544- }
545- } elseif ($redirectNormal && $feeds) {
546- $b_url = rtrim(createBlogidLink($blogid), '/');
547- switch ($reqPath) {
548- case 'xml-rss1.php':
549- $feed_code = '/index.rdf';
550- break;
551- case 'xml-rss2.php':
552- $feed_code = '/rss2.xml';
553- break;
554- case 'atom.php':
555- $feed_code = '/atom.xml';
556- break;
557- default:
558- break;
559- }
560- // HTTP status 301 "Moved Permanentry"
561- header('HTTP/1.1 301 Moved Permanently');
562- header('Location: ' . $b_url . $feed_code);
563- exit;
564- }
565- }
566-// decode path_info
567-
568-// decode unofficial Page switch '/page_2.html'
569- foreach($v_path as $pathName) {
570- if (preg_match('/^page_/', $pathName)) {
571- $temp_info = explode('page_', $pathName);
572- $_GET['page'] = intval($temp_info[1]);
573- $page = array_pop($v_path);
574- }
575- }
576-
577-// decode TrackBack URL shorten ver.
578- $tail = end($v_path);
579- if (substr($tail, -10, 10) == '.trackback') {
580- $v_pathName = substr($tail, 0, -10);
581-// echo $v_pathName;
582- if (is_numeric($v_pathName)) {
583- $this->_trackback($blogid, $v_pathName);
584- } else {
585- $this->_trackback($blogid, $v_pathName . '.html');
586- }
587- return;
588- }
589-
590-// decode other type URL
591- $bLink = $cLink = $iLink = $exLink = FALSE;
592- if (empty($info)) {
593- $bLink = TRUE;
594- }
595- $linkObj = array (
596- 'bid' => 0,
597- 'name' => reset($v_path),
598- 'linkparam' => 'blog'
599- );
600- $blog_id = $this->getRequestPathInfo($linkObj);
601- if ($blog_id) {
602- $blogid = $blog_id;
603- $trush = array_shift($v_path);
604- $bLink = TURE;
605- }
606- if ($useCustomURL[$blogid] == 'no') {
607- return;
608- }
609- $i = 1;
610- foreach($v_path as $pathName) {
611- switch ($pathName) {
612-// decode FancyURLs and redirection to Customized URL
613- // for blogsgetAllBlogOptions($name)
614- case $CONF['BlogKey']:
615- if (isset($v_path[$i]) && is_numeric($v_path[$i])) {
616- if ($useCustomURL[intval($v_path[$i])] != 'yes') {
617- $blogid = intval($v_path[$i]);
618- $bLink = TRUE;
619- } else {
620- $redURI = createBlogidLink(intval($v_path[$i]));
621- }
622- }
623- break;
624- // for items
625- case $CONF['ItemKey']:
626- if (isset($v_path[$i]) && is_numeric($v_path[$i])) {
627- if ($useCustomURL[$blogid] != 'yes') {
628- $itemid = intval($v_path[$i]);
629- $iLink = TRUE;
630- } else {
631- $redURI = createItemLink(intval($v_path[$i]));
632- }
633- }
634- break;
635- // for categories
636- case $CONF['CategoryKey']:
637- case 'catid':
638- if (isset($v_path[$i]) && is_numeric($v_path[$i])) {
639- if ($useCustomURL[$blogid] != 'yes') {
640- $catid = intval($v_path[$i]);
641- $cLink = TRUE;
642- } else {
643- $redURI = createCategoryLink(intval($v_path[$i]));
644- }
645- }
646- break;
647- // for subcategories
648- case $subrequest:
649- $c = $i - 2;
650- $subCat = (isset($v_path[$i]) && is_numeric($v_path[$i]));
651- if ($mcategories && $subCat && $i >= 3 && is_numeric($v_path[$c])) {
652- if ($useCustomURL[$blogid] != 'yes') {
653- $subcatid = intval($v_path[$i]);
654- $catid = intval($v_path[$c]);
655- $cLink = TRUE;
656- } else {
657- $subcat_id = intval($v_path[$i]);
658- $catid = intval($v_path[$c]);
659- $linkParam = array($subrequest => $subcat_id);
660- $redURI = createCategoryLink($catid, $linkParam);
661- }
662- }
663- break;
664- // for archives
665- case $CONF['ArchivesKey']:
666- case $this->getOption('customurl_archives'):
667- // FancyURL
668- if (isset($v_path[$i]) && is_numeric($v_path[$i])) {
669- if ($useCustomURL[intval($v_path[$i])] != 'yes') {
670- $archivelist = intval($v_path[$i]);
671- $blogid = $archivelist;
672- $exLink = TRUE;
673- } else {
674- $redURI = createArchiveListLink(intval($v_path[$i]));
675- }
676- // Customized URL
677- } elseif (isset($v_path[$i])) {
678- $archivelist = $blogid;
679- $redURI = createArchiveListLink($archivelist);
680- } else {
681- $archivelist = $blogid;
682- $exLink = TRUE;
683- }
684- break;
685- // for archive
686- case $CONF['ArchiveKey']:
687- case $this->getOption('customurl_archive'):
688- $y = $m = $d = '';
689- $ar = $i + 1;
690- if (isset($v_path[$i])) {
691- $darc = (ereg('([0-9]{4})-([0-9]{1,2})-([0-9]{1,2})', $v_path[$i]));
692- $marc = (ereg('([0-9]{4})-([0-9]{1,2})', $v_path[$i]));
693- $yarc = (ereg('([0-9]{4})', $v_path[$i]));
694- $adarc = (ereg('([0-9]{4})-([0-9]{1,2})-([0-9]{1,2})', $v_path[$ar]));
695- $amarc = (ereg('([0-9]{4})-([0-9]{1,2})', $v_path[$ar]));
696- $ayarc = (ereg('([0-9]{4})', $v_path[$ar]));
697- $arc = (!$darc && !$marc && !$yarc);
698- $aarc = ($adarc || $amarc || $ayarc);
699- $carc = ($darc || $marc || $yarc);
700- // FancyURL
701-// if (is_numeric($v_path[$i]) && !$darc && !$marc && !$yarc && isset($v_path[$ar]) && ($adarc || $amarc || $ayarc)) {
702- if (is_numeric($v_path[$i]) && $arc && isset($v_path[$ar]) && $aarc) {
703- sscanf($v_path[$ar], '%d-%d-%d', $y, $m, $d);
704- if (!empty($d)) {
705- $archive = sprintf('%04d-%02d-%02d', $y, $m, $d);
706- } elseif (!empty($m)) {
707- $archive = sprintf('%04d-%02d', $y, $m);
708- } else {
709- $archive = sprintf('%04d', $y);
710- }
711- if ($useCustomURL[intval($v_path[$i])] != 'yes') {
712- $blogid = intval($v_path[$i]);
713- $exLink = TRUE;
714- } else {
715- $blogid = intval($v_path[$i]);
716- $redURI = createArchiveLink($blogid, $archive);
717- }
718- // Customized URL
719-// } elseif ($darc || $marc || $yarc) {
720- } elseif ($carc) {
721- sscanf($v_path[$i], '%d-%d-%d', $y, $m, $d);
722- if (isset($d)) {
723- $archive = sprintf('%04d-%02d-%02d', $y, $m, $d);
724- } elseif (!empty($m)) {
725- $archive = sprintf('%04d-%02d', $y, $m);
726- } else {
727- $archive = sprintf('%04d', $y);
728- }
729- $exLink = TRUE;
730- } else {
731- $redURI = createArchiveListLink($blogid);
732- }
733- } else {
734- $redURI = createArchiveListLink($blogid);
735- }
736- break;
737- // for member
738- case $CONF['MemberKey']:
739- case $this->getOption('customurl_member'):
740- // Customized URL
741- $customMemberURL = (substr($v_path[$i], -5, 5) == '.html');
742- if (isset($v_path[$i]) && $customMemberURL) {
743- $memberInfo = array('linkparam' => 'member',
744- 'bid' => 0,
745- 'name' => $v_path[$i]);
746- $member_id = $this->getRequestPathInfo($memberInfo);
747- $memberid = intval($member_id);
748- $exLink = TRUE;
749- // FancyURL
750- } elseif (isset($v_path[$i]) && is_numeric($v_path[$i])) {
751- if ($useCustomURL[$blogid] != 'yes') {
752- $memberid = intval($v_path[$i]);
753- $exLink = TRUE;
754- } else {
755- $redURI = createMemberLink(intval($v_path[$i]));
756- }
757- } else {
758- $redURI = createBlogidLink($blogid);
759- }
760- break;
761- // for tag
762- case 'tag':
763- if (isset($v_path[$i]) && is_string($v_path[$i])) {
764- $_REQUEST['tag'] = $v_path[$i];
765- $exLink = TRUE;
766- }
767- break;
768- // for ExtraSkinJP
769- case 'extra':
770- $ExtraSkinJP = $this->pluginCheck('ExtraSkinJP');
771- if ($ExtraSkinJP) {
772- // under v3.2 needs this
773- if ($CONF['DisableSite'] && !$member->isAdmin()) {
774- header('Location: ' . $CONF['DisableSiteURL']);
775- exit;
776- }
777- $extraParams = explode("/", serverVar('PATH_INFO'));
778- array_shift ($extraParams);
779-
780- if (isset($extraParams[1]) && preg_match("/^([1-9]+[0-9]*)(\?.*)?$/", $extraParams[1], $matches)) {
781- $extraParams[1] = $matches[1];
782- }
783-
784- $ExtraSkinJP->extra_selector($extraParams);
785- exit;
786- }
787- break;
788- // for search query
789- case 'search':
790- $redirectSerch = ($this->getBlogOption($blogid, 'redirect_search') == 'yes');
791- if ($redirectSerch) {
792- $que_str = urldecode($v_path[$i]);
793- $que_str = mb_eregi_replace('ssslllaaassshhh', '/', $que_str);
794- $que_str = mb_eregi_replace('qqquuuooottt', "'", $que_str);
795- $que_str = mb_eregi_replace('aaammmppp', '&', $que_str);
796- $que_str = htmlspecialchars_decode($que_str);
797- $_GET['query'] = $que_str;
798- $query = $que_str;
799- $exLink = TRUE;
800- }
801- break;
802- // for pageswitch
803- case 'page':
804- if (isset($v_path[$i]) && is_numeric($v_path[$i])) {
805- $_GET['page'] = intval($v_path[$i]);
806- $exLink = TRUE;
807- }
808- break;
809- // for tDiarySkin
810- case 'tdiarydate':
811- case 'categorylist':
812- case 'monthlimit':
813- $tDiaryPlugin = $this->pluginCheck('tDiarySkin');
814- if ($tDiaryPlugin && isset($v_path[$i])) {
815-// sscanf($v_path[$i], '%d-%d', $m, $d);
816-// $linkDate = sprintf('%02d-%02d', $m, $d);
817-// $_GET['linkdate'] = $linkDate;
818- $_GET[$pathName] = $v_path[$i];
819- $exLink = TRUE;
820- }
821- break;
822- // for trackback
823- case 'trackback':
824- if (isset($v_path[$i]) && is_string($v_path[$i])) {
825- $this->_trackback($blogid, $v_path[$i]);
826- }
827- return;
828- break;
829-
830-// decode Customized URL
831- default:
832- // initialyze
833- $linkObj = array ('bid' => $blogid,
834- 'name' => $pathName
835- );
836- $comp = FALSE;
837- $isItem = (substr($pathName, -5) == '.html');
838- // category ?
839- if (!$comp && !$cLink && !$iLink && !$isItem) {
840- $linkObj['linkparam'] = 'category';
841- $cat_id = $this->getRequestPathInfo($linkObj);
842- if (!empty($cat_id)) {
843- $catid = intval($cat_id);
844- $cLink = TURE;
845- $comp = TRUE;
846- }
847- }
848- // subcategory ?
849- if (!$comp && $cLink && !$iLink && $mcategories && !$isItem) {
850- $linkObj['linkparam'] = 'subcategory';
851- $linkObj['bid'] = $catid;
852- $subcat_id = $this->getRequestPathInfo($linkObj);
853- if (!empty($subcat_id)) {
854- $_REQUEST[$subrequest] = intval($subcat_id);
855- $subcatid = intval($subcat_id);
856- $sc = $i;
857- $comp = TRUE;
858- }
859- }
860- // item ?
861- if ($isItem) {
862- $linkObj['linkparam'] = 'item';
863- $item_id = $this->getRequestPathInfo($linkObj);
864- if (!empty($item_id)) {
865- $itemid = intval($item_id);
866- $iLink = TRUE;
867- }
868- }
869- break;
870- }
871- if (preg_match('/^[0-9page]$/', $pathName)) {
872- $exLink = $pathName;
873- }
874- $i++;
875- }
876-
877-// FancyURL redirect to Customized URL if use it
878-// HTTP status 301 "Moved Permanentry"
879- if ($redURI) {
880- header('HTTP/1.1 301 Moved Permanently');
881- header('Location: ' . $redURI);
882- exit;
883- }
884-
885- $feedurl = array(
886- 'rss1.xml',
887- 'index.rdf',
888- 'rss2.xml',
889- 'atom.xml',
890- );
891- $siteMapPlugin = $this->pluginCheck('GoogleSitemap');
892- if ($siteMapPlugin) {
893- $pcSitemaps = $siteMapPlugin->getAllBlogOptions('PcSitemap');
894- foreach ($pcSitemaps as $pCsitemap) {
895- if ($pCsitemap) {
896- $feedurl[] = $pCsitemap;
897- }
898- }
899- $mobSitemaps = $siteMapPlugin->getAllBlogOptions('MobileSitemap');
900- foreach ($mobSitemaps as $mobSitemap) {
901- if ($mobSitemap) {
902- $feedurl[] = $mobSitemap;
903- }
904- }
905- }
906- $feedurl = array_unique($feedurl);
907- $request_path = end($v_path);
908- $feeds = in_array($request_path, $feedurl, true);
909-
910-// finish decode
911- if (!$exLink && !$feeds) {
912-// URL Not Found
913- if (substr(end($v_path), -5) == '.html' && !$iLink) {
914- $notFound = TRUE;
915- if (!empty($subcatid)) {
916- $linkParam = array($subrequest => $subcatid);
917- $uri = createCategoryLink($catid, $linkParam);
918- } elseif (!empty($catid)) {
919- $uri = createCategoryLink($catid);
920- } else {
921- $uri = createBlogidLink($blogid);
922- }
923- } elseif (count($v_path) > $sc && !empty($subcatid) && !$iLink) {
924- $notFound = TRUE;
925- $linkParam = array($subrequest => $subcatid);
926- $uri = createCategoryLink($catid, $linkParam);
927- } elseif (count($v_path) >= 2 && !$subcatid && !$iLink) {
928- $notFound = TRUE;
929- if (isset($catid)) {
930- $uri = createCategoryLink($catid);
931- } else {
932- $uri = createBlogidLink($blogid);
933- }
934- } elseif (reset($v_path) && !$catid && !$subcatid && !$iLink) {
935- $notFound = TRUE;
936- $uri = createBlogidLink($blogid);
937- } else {
938-// Found
939-// setting $CONF['Self'] for other plugins
940- $uri = createBlogidLink($blogid);
941- $CONF['Self'] = rtrim($uri, '/');
942- $complete = TRUE;
943- return ;
944- }
945- } else {
946- $uri = createBlogidLink($blogid);
947- $CONF['Self'] = rtrim($uri, '/');
948- $complete = TRUE;
949- return ;
950- }
951-// Behavior Not Found
952- if ($notFound) {
953- if (substr($uri, -1) != '/') $uri .= '/';
954- if ($this->getOption('customurl_notfound') == '404') {
955- header('HTTP/1.1 404 Not Found');
956- doError(_NO_SUCH_URI);
957- exit;
958- } else {
959- header('HTTP/1.1 303 See Other');
960- header('Location: ' . $uri);
961- exit;
962- }
963- }
964- }
965-
966-// decode 'path name' to 'id'
967- function getRequestPathInfo($linkObj)
968- {
969- $query = 'SELECT obj_id as result FROM %s'
970- . ' WHERE obj_name = "%s"'
971- . ' AND obj_bid = %d AND obj_param = "%s"';
972- $name = $this->quote_smart($linkObj['name']);
973- $bid = $this->quote_smart($linkObj['bid']);
974- $linkparam = $this->quote_smart($linkObj['linkparam']);
975- $ObjID = quickQuery(sprintf($query, _CUSTOMURL_TABLE, $name, $bid, $linkparam));
976- if (!$ObjID) {
977- return;
978- } else {
979- return intval($ObjID);
980- }
981- }
982-
983-// Receive TrackBack ping
984- function _trackback($bid, $path)
985- {
986- $blog_id = intval($bid);
987- $TrackBack = $this->pluginCheck('TrackBack');
988- if ($TrackBack) {
989- if (substr($path, -5, 5) == '.html') {
990- $linkObj = array ('linkparam' => 'item',
991- 'bid' => $blog_id,
992- 'name' => $path);
993- $item_id = $this->getRequestPathInfo($linkObj);
994- if ($item_id) {
995- $tb_id = intval($item_id);
996- } else {
997- doError(_NO_SUCH_URI);
998- }
999- } else {
1000- $tb_id = intval($path);
1001- }
1002-
1003- $errorMsg = $TrackBack->handlePing($tb_id);
1004- if ($errorMsg != '') {
1005- $TrackBack->xmlResponse($errorMsg);
1006- } else {
1007- $TrackBack->xmlResponse();
1008- }
1009- }
1010- exit;
1011- }
1012-
1013- function event_GenerateURL($data)
1014- {
1015- global $CONF, $manager, $blogid;
1016- if ($data['completed']) {
1017- return;
1018- }
1019-
1020- if (is_numeric($blogid)) {
1021- $blogid = intval($blogid);
1022- } else {
1023- $blogid = intval(getBlogIDFromName($blogid));
1024- }
1025- $mcategories = $this->pluginCheck('MultipleCategories');
1026- if ($mcategories) {
1027- if (method_exists($mcategories, 'getRequestName')) {
1028- $mcategories->event_PreSkinParse(array());
1029- global $subcatid;
1030- $subrequest = $mcategories->getRequestName();
1031- }
1032- }
1033- if ($subcatid) {
1034- $subcatid = intval($subcatid);
1035- }
1036- $OP_ArchiveKey = $this->getOption('customurl_archive');
1037- $OP_ArchivesKey = $this->getOption('customurl_archives');
1038- $OP_MemberKey = $this->getOption('customurl_member');
1039- $params = $data['params'];
1040- $catParam = $params['extra']['catid'];
1041-// echo $catParam;
1042- $subcatParam = $params['extra'][$subrequest];
1043- $useCustomURL = $this->getAllBlogOptions('use_customurl');
1044- switch ($data['type']) {
1045- case 'item':
1046- if (!is_numeric($params['itemid'])) {
1047- return;
1048- }
1049- $item_id = intval($params['itemid']);
1050- $bid = intval(getBlogIDFromItemID($item_id));
1051- if ($useCustomURL[$bid] == 'no') {
1052- return;
1053- }
1054- $query = 'SELECT obj_name as result FROM %s'
1055- . ' WHERE obj_param = "item" AND obj_id = %d';
1056- $path = quickQuery(sprintf($query, _CUSTOMURL_TABLE, $item_id));
1057- if ($path) {
1058- $objPath = $path;
1059- } else {
1060- if (!$this->_isValid(array('item', 'inumber', $item_id))) {
1061- $objPath = _NOT_VALID_ITEM;
1062- } else {
1063- $y = $m = $d = $temp = '';
1064- $table = sql_table('item');
1065- $tque = 'SELECT itime as result FROM %s'
1066- . ' WHERE inumber = %d';
1067- $itime = quickQuery(sprintf($tque ,$table, $item_id));
1068- sscanf($itime,'%d-%d-%d %s', $y, $m, $d, $temp);
1069- $defItem = $this->getOption('customurl_dfitem');
1070- $tempParam = array('year' => $Y,
1071- 'month' => $m,
1072- 'day' => $d);
1073- $ikey = TEMPLATE::fill($defItem, $tempParam);
1074- $ipath = $ikey . '_' . $item_id;
1075- $query = 'SELECT ititle as result FROM %s'
1076- . ' WHERE inumber = %d';
1077- $iname = quickQuery(sprintf($query, $table, $item_id));
1078- $this->RegistPath($item_id, $ipath, $bid, 'item', $iname, TRUE);
1079- $objPath = $ipath . '.html';
1080- }
1081- }
1082-// if ($catParam && $subcatid && !$subcatParam) {
1083-// $params['extra'][$subrequest] = $subcatid;
1084-// }
1085- if ($bid != $blogid) {
1086- $burl = $this->_generateBlogLink($bid);
1087- } else {
1088- $burl = $this->_generateBlogLink($blogid);
1089- }
1090- break;
1091- case 'member':
1092- if (!is_numeric($params['memberid']) || $useCustomURL[$blogid] =='no') {
1093- return;
1094- }
1095- $memberID = intval($params['memberid']);
1096- $path = $this->getMemberOption($memberID, 'customurl_mname');
1097- if ($path) {
1098- $data['url'] = $this->_generateBlogLink($blogid) . '/'
1099- . $OP_MemberKey . '/' . $path . '.html';
1100- $data['completed'] = TRUE;
1101- return;
1102- } else {
1103- if (!$this->_isValid(array('member', 'mnumber', $memberID))) {
1104- $data['url'] = $this->_generateBlogLink($blogid) . '/'
1105- . _NOT_VALID_MEMBER;
1106- $data['completed'] = TRUE;
1107- return;
1108- } else {
1109- $query = 'SELECT mname as result FROM %s'
1110- . ' WHERE mnumber = %d';
1111- $table = sql_table('member');
1112- $mname = quickQuery(sprintf($query, $table, $memberID));
1113- $this->RegistPath($memberID, $mname, 0, 'member', $mname, TRUE);
1114- $data['url'] = $this->_generateBlogLink($blogid) . '/'
1115- . $OP_MemberKey . '/' . $mname . '.html';
1116- $data['completed'] = TRUE;
1117- return;
1118- }
1119- }
1120- break;
1121- case 'category':
1122- if (!is_numeric($params['catid'])) {
1123- return;
1124- }
1125- $cat_id = intval($params['catid']);
1126- $bid = intval(getBlogidFromCatID($cat_id));
1127- if ($useCustomURL[$bid] == 'no') {
1128- return;
1129- }
1130- $objPath = $this->_generateCategoryLink($cat_id);
1131- if ($bid != $blogid) {
1132- $burl = $this->_generateBlogLink($bid);
1133- }
1134- break;
1135- case 'archivelist':
1136- if ($useCustomURL[$blogid] == 'no') {
1137- return;
1138- }
1139- $objPath = $OP_ArchivesKey . '/';
1140- $bid = $blogid;
1141-// if ($catParam && $subcatid && !$subcatParam) {
1142-// $params['extra'][$subrequest] = $subcatid;
1143-// }
1144- break;
1145- case 'archive':
1146- if ($useCustomURL[$blogid] == 'no') {
1147- return;
1148- }
1149- sscanf($params['archive'], '%d-%d-%d', $y, $m, $d);
1150- if ($d) {
1151- $arc = sprintf('%04d-%02d-%02d', $y, $m, $d);
1152- } elseif ($m) {
1153- $arc = sprintf('%04d-%02d', $y, $m);
1154- } else {
1155- $arc = sprintf('%04d', $y);
1156- }
1157- $objPath = $OP_ArchiveKey . '/' . $arc . '/';
1158- $bid = $blogid;
1159-// if ($catParam && $subcatid && !$subcatParam) {
1160-// $params['extra'][$subrequest] = $subcatid;
1161-// }
1162- break;
1163- case 'blog':
1164- if (!is_numeric($params['blogid'])) {
1165- return;
1166- }
1167- $bid = intval($params['blogid']);
1168- $burl = $this->_generateBlogLink($bid);
1169- break;
1170- default:
1171- return;
1172- }
1173- if (!$burl) {
1174- $burl = $this->_generateBlogLink($blogid);
1175- }
1176-
1177- //NP_Analyze AdminArea check
1178- $aplugin = $this->pluginCheck('Analyze');
1179- if ($aplugin) {
1180- $aadmin = str_replace('/', '\/', $aplugin->getAdminURL());
1181- $p_arr = explode('/', serverVar('SCRIPT_NAME'));
1182- $tmp = array_pop($p_arr);
1183- $p_info = implode('\/', $p_arr);
1184- }
1185- if ($p_info) {
1186- if (strpos($aadmin, $p_info)) {
1187- $CONF['UsingAdminArea'] = TRUE;
1188- }
1189- }
1190- //NP_Analyze AdminArea check end
1191-
1192- if (getVar('virtualpath')) {
1193- $info = preg_replace('|[^a-zA-Z0-9-~+_.?#=&;,/:@%]|i', '', getVar('virtualpath'));
1194- } elseif (serverVar('PATH_INFO')) {
1195- $info = preg_replace('|[^a-zA-Z0-9-~+_.?#=&;,/:@%]|i', '', serverVar('PATH_INFO'));
1196- }
1197- $v_path = explode('/', $info);
1198-
1199- $feedurl = array();
1200- $SiteMapP = $this->pluginCheck('GoogleSitemap');
1201- if ($SiteMapP) {
1202- $PcSitemaps = $SiteMapP->getAllBlogOptions('PcSitemap');
1203- foreach ($PcSitemaps as $PCsitemap) {
1204- if ($PCsitemap) {
1205- $feedurl[] = $PCsitemap;
1206- }
1207- }
1208- $MobSitemaps = $SiteMapP->getAllBlogOptions('MobileSitemap');
1209- foreach ($MobSitemaps as $Mobsitemap) {
1210- if ($Mobsitemap) {
1211- $feedurl[] = $Mobsitemap;
1212- }
1213- }
1214- }
1215- $feedurl = array_unique($feedurl);
1216- $request_path = end($v_path);
1217- $feeds = in_array($request_path, $feedurl, true);
1218-
1219- if (!$feeds && $bid != $blogid && !$CONF['UsingAdminArea']) {
1220- $params['extra'] = array();
1221- }
1222- if ($objPath || $data['type'] == 'blog') {
1223- $LinkURI = $this->_addLinkParams($objPath, $params['extra']);
1224- if ($LinkURI) {
1225- $data['url'] = $burl . '/' . $LinkURI;
1226- } else {
1227- $data['url'] = $burl;
1228- }
1229- $arcTmp = (preg_match('/' . $OP_ArchivesKey . '/', $data['url']));
1230- $arcsTmp = (preg_match('/' . $OP_ArchiveKey . '/', $data['url']));
1231- $isArchives = ($arcTmp || $arcsTmp);
1232- $isItem = (substr($data['url'], -5, 5) == '.html');
1233- $isDirectory = (substr($data['url'], -1) == '/');
1234- $puri = parse_url($data['url']);
1235- if ($isArchives && !$isItem && !$isDirectory && !$puri['query']) {
1236- $data['url'] .= '/';
1237- }
1238- $data['completed'] = TRUE;
1239- if (strstr ($data['url'], '//')) {
1240- $link = preg_replace("/([^:])\/\//", "$1/", $data['url']);
1241- }
1242- return $data;
1243- }
1244- }
1245-
1246- function _createSubCategoryLink($scid)
1247- {
1248- $scids = $this->getParents(intval($scid));
1249- $subcatids = explode('/', $scids);
1250- $eachPath = array();
1251- foreach ($subcatids as $sid) {
1252- $subcat_id = intval($sid);
1253- $query = 'SELECT obj_name as result FROM %s'
1254- . ' WHERE obj_id = %d AND obj_param = "%s"';
1255- $path = quickQuery(sprintf($query, _CUSTOMURL_TABLE, $subcat_id, 'subcategory'));
1256- if ($path) {
1257- $eachPath[] = $path;
1258- } else {
1259- $tempParam = array('plug_multiple_categories_sub',
1260- 'scatid',
1261- $subcat_id);
1262- if (!$this->_isValid($tempParam)) {
1263- return $url = _NOT_VALID_SUBCAT;
1264- } else {
1265- $scpath = $this->getOption('customurl_dfscat') . '_' . $subcat_id;
1266- $query = 'SELECT catid as result FROM %s WHERE scatid = %d';
1267- $cid= quickQuery(sprintf($query, _C_SUBCAT_TABLE, $subcat_id));
1268- if (!$cid) return 'no_such_subcat=' . $subcat_id . '/';
1269- $this->RegistPath($subcat_id, $scpath, $cid, 'subcategory', 'subcat_' . $subcat_id, TRUE);
1270- $eachPath[] = $scpath;
1271- }
1272- }
1273- }
1274- $subcatPath = @join('/', $eachPath);
1275- return $subcatPath . '/';
1276- }
1277-
1278- function getParents($subid)
1279- {
1280- $subcat_id = intval($subid);
1281- $query = 'SELECT scatid, parentid FROM %s WHERE scatid = %d';
1282- $res = sql_query(sprintf($query, _C_SUBCAT_TABLE, $subcat_id));
1283- list($sid, $parent) = mysql_fetch_row($res);
1284- if ($parent != 0) {
1285- $r = $this->getParents($parent) . '/' . $sid;
1286- } else {
1287- $r = $sid;
1288- }
1289- return $r;
1290- }
1291-
1292- function _generateCategoryLink($cid)
1293- {
1294- global $CONF;
1295- $cat_id = intval($cid);
1296- $path = $this->getCategoryOption($cat_id, 'customurl_cname');
1297- if ($path) {
1298- return $path . '/';
1299- } else {
1300- if (!$this->_isValid(array('category', 'catid', $cat_id))) {
1301- return $url = _NOT_VALID_CAT;
1302- } else {
1303- $cpath = $this->getOption('customurl_dfcat') . '_' . $cat_id;
1304- $blog_id = intval(getBlogIDFromCatID($cat_id));
1305- $catname = 'catid_' . $cat_id;
1306- $this->RegistPath($cat_id, $cpath, $blog_id, 'category', $catname, TRUE);
1307- return $cpath . '/';
1308- }
1309- }
1310- }
1311-
1312- function _generateBlogLink($bid)
1313- {
1314- global $manager, $CONF;
1315- $blog_id = intval($bid);
1316- if ($this->getBlogOption($blog_id, 'use_customurl') == 'no') {
1317- $b =& $manager->getBlog($blog_id);
1318- $burl = $b->getURL();
1319- } else {
1320- if ($blog_id == $CONF['DefaultBlog']) {
1321- $burl = trim($CONF['IndexURL'], '/');
1322- } else {
1323- $query = 'SELECT burl as result FROM %s WHERE bnumber = %d';
1324- $burl = quickQuery(sprintf($query, sql_table('blog'), $blog_id));
1325- if ($burl) {
1326- if (substr($burl, -4, 4) == '.php') {
1327- $path = $this->getBlogOption($blog_id, 'customurl_bname');
1328- if ($path) {
1329- $burl = $CONF['IndexURL'] . $path;
1330- } else {
1331- $query = 'SELECT bshortname as result FROM %s'
1332- . ' WHERE bnumber = %d';
1333- $bpath = quickQuery(sprintf($query, sql_table('blog'), $blog_id));
1334- $this->RegistPath($blog_id, $bpath, 0, 'blog', $bpath, TRUE);
1335- $burl = $CONF['IndexURL'] . $bpath;
1336- }
1337- $burl_update = 'UPDATE %s SET burl = "%s" WHERE bnumber = %d';
1338- sql_query(sprintf($burl_update, sql_table('blog'), $this->quote_smart($burl), $blog_id));
1339- }
1340- } else {
1341- $burl = _NOT_VALID_BLOG;
1342- }
1343- }
1344- }
1345- return trim($burl, '/');
1346- }
1347-
1348- function _addLinkParams($link, $params)
1349- {
1350- global $CONF, $manager, $catid;
1351- $arcTmp = (preg_match('/' . $this->getOption('customurl_archives') . '/', $link));
1352- $arcsTmp = (preg_match('/' . $this->getOption('customurl_archive') . '/', $link));
1353- $isArchives = ($arcTmp || $arcsTmp);
1354- $mcategories = $this->pluginCheck('MultipleCategories');
1355- if ($mcategories) {
1356- if (method_exists($mcategories,"getRequestName")) {
1357- $mcategories->event_PreSkinParse(array());
1358- global $subcatid;
1359- $subrequest = $mcategories->getRequestName();
1360- } else {
1361- $subrequest = 'subcatid';
1362- }
1363- }
1364- if (is_array($params)) {
1365- if ($params['archives']) {
1366- $linkExtra = $this->getOption('customurl_archives') . '/';
1367- unset($params['archives']);
1368- } elseif ($params['archivelist']) {
1369- $linkExtra = $this->getOption('customurl_archives') . '/';
1370- unset($params['archivelist']);
1371- } elseif ($params['archive']) {
1372- sscanf($params['archive'], '%d-%d-%d', $y, $m, $d);
1373- if ($d) {
1374- $arc = sprintf('%04d-%02d-%02d', $y, $m, $d);
1375- } elseif ($m) {
1376- $arc = sprintf('%04d-%02d', $y, $m);
1377- } else {
1378- $arc = sprintf('%04d', $y);
1379- }
1380- $linkExtra = $this->getOption('customurl_archive') . '/' . $arc;
1381- unset($params['archive']);
1382- }
1383- $paramlink = array();
1384- foreach ($params as $param => $value) {
1385- switch ($param) {
1386- case 'catid':
1387- case $CONF['CategoryKey']:
1388- $paramlink[] = $this->_generateCategoryLink(intval($value));
1389- break;
1390- case $subrequest:
1391- if ($mcategories) {
1392- $paramlink[] = $this->_createSubCategoryLink(intval($value));
1393- }
1394- break;
1395- default:
1396- $paramlink[] = $param . '/' . $value . '/';
1397- break;
1398- }
1399- }
1400-// $tagparam = (preg_match('/^tag\//', $link));
1401- if (substr($link, -5, 5) == '.html' || $isArchives) {
1402-// $link = $catlink . $sublink . $link;
1403- $link = implode('', $paramlink) . $link;
1404- } else {
1405-// $link .= $catlink . $sublink;
1406- $link .= implode('', $paramlink);
1407- }
1408- }
1409-// if ($params['tag']) {
1410-// $link .= 'tag/' . $params['tag'] . '/';
1411-// }
1412- if ($linkExtra) {
1413- $link .= $linkExtra;
1414- }
1415- if (requestVar('skinid')) {
1416- if (strpos('?', $link)) {
1417- $link .= '&amp;skinid=' . htmlspecialchars(requestVar('skinid'));
1418- } else {
1419- if (substr($link, -1) != '/' && !empty($link)) {
1420- $link .= '/?skinid=' . htmlspecialchars(requestVar('skinid'));
1421- } else {
1422- $link .= '?skinid=' . htmlspecialchars(requestVar('skinid'));
1423- }
1424- }
1425- }
1426- if (strstr ($link, '//')) {
1427- $link = preg_replace("/([^:])\/\//", "$1/", $link);
1428- }
1429- return $link;
1430- }
1431-
1432- function _convertAlphabettoXHTMLCharacterEntity($text) //add shizuki
1433- {
1434- $alphabetKey = array (
1435- '/',
1436- '@',
1437- 'A',
1438- 'B',
1439- 'C',
1440- 'D',
1441- 'E',
1442- 'F',
1443- 'G',
1444- 'H',
1445- 'I',
1446- 'J',
1447- 'K',
1448- 'L',
1449- 'M',
1450- 'N',
1451- 'O',
1452- 'P',
1453- 'Q',
1454- 'R',
1455- 'S',
1456- 'T',
1457- 'U',
1458- 'V',
1459- 'W',
1460- 'X',
1461- 'Y',
1462- 'Z',
1463- 'a',
1464- 'b',
1465- 'c',
1466- 'd',
1467- 'e',
1468- 'f',
1469- 'g',
1470- 'h',
1471- 'i',
1472- 'j',
1473- 'k',
1474- 'l',
1475- 'm',
1476- 'n',
1477- 'o',
1478- 'p',
1479- 'q',
1480- 'r',
1481- 's',
1482- 't',
1483- 'u',
1484- 'v',
1485- 'w',
1486- 'x',
1487- 'y',
1488- 'z',
1489- '&&'
1490- );
1491- $alphabetVal = array (
1492- '&#47;',
1493- '&#64;',
1494- '&#65;',
1495- '&#66;',
1496- '&#67;',
1497- '&#68;',
1498- '&#69;',
1499- '&#70;',
1500- '&#71;',
1501- '&#72;',
1502- '&#73;',
1503- '&#74;',
1504- '&#75;',
1505- '&#76;',
1506- '&#77;',
1507- '&#78;',
1508- '&#79;',
1509- '&#80;',
1510- '&#81;',
1511- '&#82;',
1512- '&#83;',
1513- '&#84;',
1514- '&#85;',
1515- '&#86;',
1516- '&#87;',
1517- '&#88;',
1518- '&#89;',
1519- '&#90;',
1520- '&#97;',
1521- '&#98;',
1522- '&#99;',
1523- '&#100;',
1524- '&#101;',
1525- '&#102;',
1526- '&#103;',
1527- '&#104;',
1528- '&#105;',
1529- '&#106;',
1530- '&#107;',
1531- '&#108;',
1532- '&#109;',
1533- '&#110;',
1534- '&#111;',
1535- '&#112;',
1536- '&#113;',
1537- '&#114;',
1538- '&#115;',
1539- '&#116;',
1540- '&#117;',
1541- '&#118;',
1542- '&#119;',
1543- '&#120;',
1544- '&#121;',
1545- '&#122;',
1546- '&#65286;&'
1547- );
1548- $retData = str_replace($alphabetKey, $alphabetVal, $text);
1549- return $retData;
1550- }
1551-
1552- function doSkinVar($skinType, $link_type = '', $target = '', $title = '')
1553- {
1554- global $blogid;
1555- if ($skinType == 'item' && $link_type == 'trackback') {
1556- global $itemid, $CONF;
1557- if ($this->getBlogOption($blogid, 'use_customurl') == 'yes') {
1558- $que = 'SELECT obj_name as result FROM %s'
1559- . ' WHERE obj_param = "item" AND obj_id = %d';
1560- $itempath = quickQuery(sprintf($que, _CUSTOMURL_TABLE, $itemid));
1561- $uri = $CONF['BlogURL'] . '/trackback/' . $itempath;
1562-// /item_123.trackback
1563-// $itempath = substr($itempath, 0, -5) . '.trackback';
1564-// $uri = $CONF['BlogURL'] . '/' . $itempath;
1565- } else {
1566- $uri = $CONF['ActionURL']
1567- . '?action=plugin&amp;name=TrackBack&amp;tb_id=' . $itemid;
1568- }
1569- echo $this->_convertAlphabettoXHTMLCharacterEntity($uri);
1570- return;
1571- }
1572- // $data == type / id || name / 'i'd || 'n'ame
1573- // ex. => [(b)log / blogid [|| shortname / 'i'd || 'n'ame]]
1574- // (c)at / catid [|| cname / 'i'd || 'n'ame]
1575- // (s)cat / subcatid [|| sname / 'i'd || 'n'ame]
1576- // [(i)tem /] itemid [/ 'path']
1577- // (m)ember / mnumber [|| mname / 'i'd || 'n'ame]
1578- //
1579- // if second param is null, third param is id
1580- // if param is null, generate blog link
1581- if (!$link_type) {
1582- $link_params = '0, b/' . intval($blogid) . '/i,'
1583- . $target . ',' . $title;
1584- } else {
1585- $l_params = explode("/", $link_type);
1586- if (count($l_params) == 1) {
1587- $link_params = array(0, 'b/' . intval($link_type) . '/i,'
1588- . $target . ',' . $title);
1589- } else {
1590- $link_params = array(0,
1591- $link_type . ',' . $target . ',' . $title);
1592- }
1593- }
1594- echo $this->URL_Callback($link_params);
1595- }
1596-
1597- function doTemplateVar(&$item, $link_type = '', $target = '', $title = '')
1598- {
1599- $item_id = intval($item->itemid);
1600- if ($link_type == 'trackback') {
1601- global $CONF;
1602- $blog_id = intval(getBlogIDFromItemID($item_id));
1603- if ($this->getBlogOption($blog_id, 'use_customurl') == 'yes') {
1604- $que = 'SELECT obj_name as result FROM %s'
1605- . ' WHERE obj_param = "item" AND obj_id = %d';
1606- $itempath = quickQuery(sprintf($que, _CUSTOMURL_TABLE, $item_id));
1607- $uri = $CONF['BlogURL'] . '/trackback/' . $itempath;
1608-// /item_123.trackback
1609-// $itempath = substr($itempath, 0, -5) . '.trackback';
1610-// $uri = $CONF['BlogURL'] . '/' . $itempath;
1611- } else {
1612- $uri = $CONF['ActionURL']
1613- . '?action=plugin&amp;name=TrackBack&amp;tb_id=' . $item_id;
1614- }
1615- echo $this->_convertAlphabettoXHTMLCharacterEntity($uri);
1616- return;
1617- }
1618- if (!$link_type) {
1619- $link_params = array(0,
1620- 'i/' . $item_id . '/i,' . $target . ',' . $title);
1621- } elseif ($link_type == 'path') {
1622- $link_params = array(0,
1623- 'i/' . $item_id . '/path,' . $target . ',' . $title);
1624- } else {
1625- $link_params = array(0,
1626- $link_type . ',' . $target . ',' . $title);
1627- }
1628- echo $this->URL_Callback($link_params);
1629- }
1630-
1631- function URL_Callback($data)
1632- {
1633- $l_data = explode(",", $data[1]);
1634- $l_type = $l_data[0];
1635- $target = $l_data[1];
1636- $title = $l_data[2];
1637- $item_id = intval($this->currentItem->itemid);
1638- if (!$l_type) {
1639- $link_params = array ('i',
1640- $item_id,
1641- 'i');
1642- } else {
1643- $link_data = explode("/", $l_type);
1644- if (count($link_data) == 1) {
1645- $link_params = array ('i',
1646- intval($l_type),
1647- 'i');
1648- } elseif (count($link_data) == 2) {
1649- if ($link_data[1] == 'path') {
1650- $link_params = array ('i',
1651- $link_data[0],
1652- 'path');
1653- } else {
1654- $link_params = array ($link_data[0],
1655- intval($link_data[1]),
1656- 'i');
1657- }
1658- } else {
1659- $link_params = array ($link_data[0],
1660- $link_data[1],
1661- $link_data[2]);
1662- }
1663- }
1664- $url = $this->_genarateObjectLink($link_params);
1665- if ($target) {
1666- if ($title) {
1667- $ObjLink = '<a href="' . htmlspecialchars($url) . '" '
1668- . 'title="' . htmlspecialchars($title) . '">'
1669- . htmlspecialchars($target) . '</a>';
1670- } else {
1671- $ObjLink = '<a href="' . htmlspecialchars($url) . '" '
1672- . 'title="' . htmlspecialchars($target) . '">'
1673- . htmlspecialchars($target) . '</a>';
1674- }
1675- } else {
1676- $ObjLink = htmlspecialchars($url);
1677- }
1678- return $ObjLink;
1679- }
1680-
1681- function _isValid($data)
1682- {
1683- $query = 'SELECT * FROM %s WHERE %s = %d';
1684- $data[2] = $this->quote_smart($data[2]);
1685- $res = sql_query(sprintf($query, sql_table($data[0]), $data[1], $data[2]));
1686- return (mysql_num_rows($res) != 0);
1687- }
1688-
1689- function _genarateObjectLink($data)
1690- {
1691- global $CONF, $manager, $blog;
1692- $ext = substr(serverVar('REQUEST_URI'), -4);
1693- if ($ext == '.rdf' || $ext == '.xml') {
1694- $CONF['URLMode'] = 'pathinfo';
1695- }
1696- if ($CONF['URLMode'] != 'pathinfo') {
1697- return;
1698- }
1699- $query = 'SELECT %s as result FROM %s WHERE %s = "%s"';
1700- switch ($data[0]) {
1701- case 'b':
1702- if ($data[2] == 'n') {
1703- $bid = getBlogIDFromName($data[1]);
1704- } else {
1705- $bid = $data[1];
1706- }
1707- $blog_id = intval($bid);
1708- $param = array('blog',
1709- 'bnumber',
1710- $blog_id);
1711- if (!$this->_isValid($param)) {
1712- $url = _NOT_VALID_BLOG;
1713- } else {
1714- $url = $this->_generateBlogLink($blog_id) . '/';
1715- }
1716- break;
1717- case 'c':
1718- if ($data[2] == 'n') {
1719- $cid = getCatIDFromName($data[1]);
1720- } else {
1721- $cid = $data[1];
1722- }
1723- $cat_id = intval($cid);
1724- $param = array('category',
1725- 'catid',
1726- $cat_id);
1727- if (!$this->_isValid($param)) {
1728- $url = _NOT_VALID_CAT;
1729- } else {
1730-// $bid = intval(getBlogIDFromCatID($cat_id));
1731-// $blink = $this->_generateBlogLink(intval($bid));
1732-// $url = $blink . '/' . $this->_generateCategoryLink($cat_id, '');
1733- $url = createCategoryLink($cat_id);
1734- }
1735- break;
1736- case 's':
1737- $mcategories = $this->pluginCheck('MultipleCategories');
1738- if ($mcategories) {
1739- if (method_exists($mcategories, "getRequestName")) {
1740- if ($data[2] == 'n') {
1741- $temp = $this->quote_smart($data[1]);
1742- $scid = quickQuery(sprintf($query, 'scatid', _C_SUBCAT_TABLE, 'sname', $temp));
1743- } else {
1744- $scid = $data[1];
1745- }
1746- $sub_id = intval($scid);
1747- $param = array('plug_multiple_categories_sub',
1748- 'scatid',
1749- $sub_id);
1750- if (!$this->_isValid($param)) {
1751- $url = _NOT_VALID_SUBCAT;
1752- } else {
1753- $cid = quickQuery(sprintf($query, 'catid', _C_SUBCAT_TABLE, 'scatid', $sub_id));
1754- $cid = intval($cid);
1755- $subrequest = $mcategories->getRequestName();
1756- if (!$subrequest) {
1757- $subrequest = 'subcatid';
1758- }
1759- $linkParam = array($subrequest => $sub_id);
1760- $url = createCategoryLink($cid, $linkParam);
1761- }
1762- }
1763- }
1764- break;
1765- case 'i':
1766- $param = array('item',
1767- 'inumber',
1768- intval($data[1]));
1769- if (!$this->_isValid($param)) {
1770- $url = _NOT_VALID_ITEM;
1771- } else {
1772- $blink = $this->_generateBlogLink(getBlogIDFromItemID(intval($data[1])));
1773- $i_query = 'SELECT obj_name as result FROM %s'
1774- . ' WHERE obj_param = "item" AND obj_id = %d';
1775- $path = quickQuery(sprintf($i_query, _CUSTOMURL_TABLE, intval($data[1])));
1776- if ($path) {
1777- if ($data[2] == 'path') {
1778- $url = $path;
1779- } else {
1780- $url = $blink . '/' . $path;
1781- }
1782- } else {
1783- if ($data[2] == 'path') {
1784- $url = $CONF['ItemKey'] . '/'
1785- . intval($data[1]);
1786- } else {
1787- $url = $blink . '/' . $CONF['ItemKey'] . '/'
1788- . intval($data[1]);
1789- }
1790- }
1791- }
1792- break;
1793- case 'm':
1794- if ($data[2] == 'n') {
1795- $data[1] = $this->quote_smart($data[1]);
1796- $mid = quickQuery(sprintf($query, 'mnumber', sql_table('member'), 'mname', $data[1]));
1797- } else {
1798- $mid = $data[1];
1799- }
1800- $member_id = intval($mid);
1801- $param = array('member',
1802- 'mnumber',
1803- $member_id);
1804- if (!$this->_isValid($param)) {
1805- $url = _NOT_VALID_MEMBER;
1806- } else {
1807- $url = createMemberLink($member_id);
1808- }
1809- break;
1810- }
1811- return $url;
1812- }
1813-
1814-/* function event_PreSendContentType($data)
1815- {
1816- global $blogid, $CONF;
1817-
1818- $ext = substr(serverVar('REQUEST_URI'), -4);
1819- if ($ext == '.rdf' || $ext == '.xml') {
1820- $p_info = trim(serverVar('PATH_INFO'), '/');
1821- $path_arr = explode('/', $p_info);
1822- switch (end($path_arr)) {
1823- case 'rss1.xml':
1824- case 'index.rdf':
1825- case 'rss2.xml':
1826- case 'atom.xml':
1827- $data['contentType'] = 'application/xml';
1828- break;
1829- default:
1830- break;
1831- }
1832- }
1833- }*/
1834-
1835- function event_InitSkinParse($data)
1836- {
1837- global $blogid, $CONF, $manager;
1838- $feedurl = array(
1839- 'rss1.xml',
1840- 'index.rdf',
1841- 'rss2.xml',
1842- 'atom.xml',
1843- );
1844- $reqPaths = explode('/', serverVar('PATH_INFO'));
1845- $reqPath = end($reqPaths);
1846- $feeds = in_array($reqPath, $feedurl, true);
1847- if (!$feeds) {
1848- return;
1849- } else {
1850- $p_info = trim(serverVar('PATH_INFO'), '/');
1851- $path_arr = explode('/', $p_info);
1852- switch (end($path_arr)) {
1853- case 'rss1.xml':
1854- case 'index.rdf':
1855- $skinName = 'feeds/rss10';
1856- break;
1857- case 'rss2.xml':
1858- $skinName = 'feeds/rss20';
1859- break;
1860- case 'atom.xml':
1861- $skinName = 'feeds/atom';
1862- break;
1863- }
1864- if (SKIN::exists($skinName)) {
1865- $skin =& SKIN::createFromName($skinName);
1866- $data['skin']->SKIN($skin->getID());
1867- $skinData =& $data['skin'];
1868- $pageType = $data['type'];
1869- if (!$CONF['DisableSite']) {
1870- ob_start();
1871-
1872- $skinID = $skinData->id;
1873- $contents = $this->getSkinContent($pageType, $skinID);
1874- $actions = SKIN::getAllowedActionsForType($pageType);
1875- $dataArray = array('skin' => &$skinData,
1876- 'type' => $pageType,
1877- 'contents' => &$contents);
1878- $manager->notify('PreSkinParse', $dataArray);
1879- PARSER::setProperty('IncludeMode', SKIN::getIncludeMode());
1880- PARSER::setProperty('IncludePrefix', SKIN::getIncludePrefix());
1881- $handler =& new ACTIONS($pageType, $skinData);
1882- $parser =& new PARSER($actions, $handler);
1883- $handler->setParser($parser);
1884- $handler->setSkin($skinData);
1885- $parser->parse($contents);
1886- $dataArray = array('skin' => &$skinData,
1887- 'type' => $pageType);
1888- $manager->notify('PostSkinParse', $dataArray);
1889-
1890- $feed = ob_get_contents();
1891-
1892- ob_end_clean();
1893- $eTag = '"' . md5($feed) . '"';
1894- header('Etag: ' . $eTag);
1895- if ($eTag == serverVar('HTTP_IF_NONE_MATCH')) {
1896- header("HTTP/1.0 304 Not Modified");
1897- header('Content-Length: 0');
1898- } else {
1899- $feed = mb_convert_encoding($feed, 'UTF-8', _CHARSET);
1900- header("Content-Type: application/xml");
1901- header('Generator: Nucleus CMS ' . $nucleus['version']);
1902- // dump feed
1903- echo $feed;
1904- }
1905- } else {
1906- echo '<' . '?xml version="1.0" encoding="ISO-8859-1"?' . '>';
1907-?>
1908-<rss version="2.0">
1909- <channel>
1910- <title><?php echo htmlspecialchars($CONF['SiteName'])?></title>
1911- <link><?php echo htmlspecialchars($CONF['IndexURL'])?></link>
1912- <description></description>
1913- <docs>http://backend.userland.com/rss</docs>
1914- </channel>
1915-</rss>
1916-<?php
1917- }
1918- }
1919- exit;
1920- }
1921- }
1922-
1923- function getSkinContent($pageType, $skinID)
1924- {
1925- $skinID = intval($skinID);
1926- $pageType = addslashes($pageType);
1927- $query = 'SELECT scontent FROM %s WHERE sdesc = %d AND stype = %d';
1928- $res = sql_query(sprintf($query, sql_table('skin'), $skinID, $pageType));
1929-
1930- if (mysql_num_rows($res) == 0)
1931- return '';
1932- else
1933- return mysql_result($res, 0, 0);
1934- }
1935-
1936-
1937-// merge NP_RightURL
1938- function event_PreSkinParse($data)
1939- {
1940- global $CONF, $manager, $blog, $catid, $itemid, $subcatid;
1941- global $memberid;
1942- if (!$blog) {
1943- $b =& $manager->getBlog($CONF['DefaultBlog']);
1944- } else {
1945- $b =& $blog;
1946- }
1947- $blogurl = $b->getURL();
1948-
1949- if (!$blogurl) {
1950- if($blog) {
1951- $b_tmp =& $manager->getBlog($CONF['DefaultBlog']);
1952- $blogurl = $b_tmp->getURL();
1953- }
1954- if (!$blogurl) {
1955- $blogurl = $CONF['IndexURL'];
1956- if ($CONF['URLMode'] != 'pathinfo'){
1957- if ($data['type'] == 'pageparser') {
1958- $blogurl .= 'index.php';
1959- } else {
1960- $blogurl = $CONF['Self'];
1961- }
1962- }
1963- }
1964- }
1965- if ($CONF['URLMode'] == 'pathinfo'){
1966- if (substr($blogurl, -1) == '/') {
1967- $blogurl = substr($blogurl, 0, -1);
1968- }
1969- }
1970- $CONF['BlogURL'] = $blogurl;
1971- $CONF['ItemURL'] = $blogurl;
1972- $CONF['CategoryURL'] = $blogurl;
1973- $CONF['ArchiveURL'] = $blogurl;
1974- $CONF['ArchiveListURL'] = $blogurl;
1975- $CONF['SearchURL'] = $blogurl;
1976-// $CONF['MemberURL'] = $blogurl;
1977- }
1978-
1979- function event_PreItem($data)
1980- {
1981- global $CONF, $manager;
1982-
1983- $this->currentItem = &$data['item'];
1984- $pattern = '/<%CustomURL\((.*)\)%>/';
1985- $data['item']->body = preg_replace_callback($pattern, array(&$this, 'URL_Callback'), $data['item']->body);
1986- if ($data['item']->more) {
1987- $data['item']->more = preg_replace_callback($pattern, array(&$this, 'URL_Callback'), $data['item']->more);
1988- }
1989-
1990- $itemid = intval($data['item']->itemid);
1991- $itemblog =& $manager->getBlog(getBlogIDFromItemID($itemid));
1992- $blogurl = $itemblog->getURL();
1993- if (!$blogurl) {
1994- $b =& $manager->getBlog($CONF['DefaultBlog']);
1995- if (!($blogurl = $b->getURL())) {
1996- $blogurl = $CONF['IndexURL'];
1997- if ($CONF['URLMode'] != 'pathinfo'){
1998- if ($data['type'] == 'pageparser') {
1999- $blogurl .= 'index.php';
2000- } else {
2001- $blogurl = $CONF['Self'];
2002- }
2003- }
2004- }
2005- }
2006- if ($CONF['URLMode'] == 'pathinfo'){
2007- if (substr($blogurl, -1) == '/') {
2008- $blogurl = substr($blogurl, 0, -1);
2009- }
2010- }
2011- $CONF['BlogURL'] = $blogurl;
2012- $CONF['ItemURL'] = $blogurl;
2013- $CONF['CategoryURL'] = $blogurl;
2014- $CONF['ArchiveURL'] = $blogurl;
2015- $CONF['ArchiveListURL'] = $blogurl;
2016-// $CONF['MemberURL'] = $blogurl;
2017- }
2018-
2019- function event_PostItem($data)
2020- {
2021- global $CONF, $manager, $blog;
2022- if (!$blog) {
2023- $b =& $manager->getBlog($CONF['DefaultBlog']);
2024- } else {
2025- $b =& $blog;
2026- }
2027- $blogurl = $b->getURL();
2028- if (!$blogurl) {
2029- if($blog) {
2030- $b_tmp =& $manager->getBlog($CONF['DefaultBlog']);
2031- $blogurl = $b_tmp->getURL();
2032- }
2033- if (!$blogurl) {
2034- $blogurl = $CONF['IndexURL'];
2035- if ($CONF['URLMode'] != 'pathinfo'){
2036- if ($data['type'] == 'pageparser') {
2037- $blogurl .= 'index.php';
2038- } else {
2039- $blogurl = $CONF['Self'];
2040- }
2041- }
2042- }
2043- }
2044- if ($CONF['URLMode'] == 'pathinfo'){
2045- if (substr($blogurl, -1) == '/') {
2046- $blogurl = substr($blogurl, 0, -1);
2047- }
2048- }
2049- $CONF['BlogURL'] = $blogurl;
2050- $CONF['ItemURL'] = $blogurl;
2051- $CONF['CategoryURL'] = $blogurl;
2052- $CONF['ArchiveURL'] = $blogurl;
2053- $CONF['ArchiveListURL'] = $blogurl;
2054-// $CONF['MemberURL'] = $CONF['Self'];
2055- }
2056-// merge NP_RightURL end
2057-
2058- function event_PostDeleteBlog ($data)
2059- {
2060- $query = 'DELETE FROM %s WHERE obj_id = %d AND obj_param = "%s"';
2061- $pquery = 'DELETE FROM %s WHERE obj_bid = %d AND obj_param= "%s"';
2062- $blogid = intval($data['blogid']);
2063- sql_query(sprintf($query, _CUSTOMURL_TABLE, $blogid, 'blog'));
2064- sql_query(sprintf($pquery, _CUSTOMURL_TABLE, $blogid, 'item'));
2065- $cnmquery = 'SELECT catid FROM %s WHERE cblog = %d';
2066- $table = sql_table('category');
2067- $cnm = sql_query(sprintf($cnmquery, $table, $blogid));
2068- while ($c = mysql_fetch_object($cnm)) {
2069- $catid = intval($c->catid);
2070- sql_query(sprintf($pquery, _CUSTOMURL_TABLE, $catid, 'subcategory'));
2071- sql_query(sprintf($query, _CUSTOMURL_TABLE, $catid, 'category'));
2072- }
2073- }
2074-
2075- function event_PostDeleteCategory ($data)
2076- {
2077- $query = 'DELETE FROM %s WHERE obj_id = %d AND obj_param = "%s"';
2078- $squery = 'DELETE FROM %s WHERE obj_bid = %d AND obj_param = "%s"';
2079- $catid = intval($data['catid']);
2080- sql_query(sprintf($query, _CUSTOMURL_TABLE, $catid, 'category'));
2081- sql_query(sprintf($squery, _CUSTOMURL_TABLE, $catid, 'subcategory'));
2082- }
2083-
2084- function event_PostDeleteItem ($data)
2085- {
2086- $query = 'DELETE FROM %s WHERE obj_id = %d AND obj_param = "%s"';
2087- $itemid = intval($data['itemid']);
2088- sql_query(sprintf($query, _CUSTOMURL_TABLE, $itemid, 'item'));
2089- }
2090-
2091- function event_PostDeleteMember ($data)
2092- {
2093- $query = 'DELETE FROM %s WHERE obj_id = %d AND obj_param = "%s"';
2094- $memberid = intval($data['member']->id);
2095- sql_query(sprintf($query, _CUSTOMURL_TABLE, $memberid, 'member'));
2096- }
2097-
2098- function event_PostAddBlog ($data)
2099- {
2100- $blog_id = intval($data['blog']->blogid);
2101- $bshortname = $data['blog']->settings['bshortname'];
2102- $this->RegistPath($blog_id, $bshortname, 0, 'blog', $bshortname, TRUE);
2103- $this->setBlogOption($blog_id, 'customurl_bname', $bshortname);
2104- }
2105-
2106- function event_PostAddCategory ($data)
2107- {
2108- global $CONF;
2109- $cat_id = intval($data['catid']);
2110- if (!$data['blog']->blogid) {
2111- $query = 'SELECT cblog as result FROM %s WHERE catid = %d';
2112- $bid = quickQuery(sprintf($query, sql_table('category'), $cat_id));
2113- } else {
2114- $bid = $data['blog']->blogid;
2115- }
2116- if (!$data['name']) {
2117- $query = 'SELECT cname as result FROM %s WHERE catid = %d';
2118- $name = quickQuery(sprintf($query, sql_table('category'), $cat_id));
2119- } else {
2120- $name = $data['name'];
2121- }
2122- $bid = intval($bid);
2123- $dfcat = $this->getOption('customurl_dfcat');
2124- $catpsth = $dfcat . '_' . $cat_id;
2125- $this->RegistPath($cat_id, $catpsth, $bid, 'category', $name, TRUE);
2126- $this->setCategoryOption($cat_id, 'customurl_cname', $catpsth);
2127- }
2128-
2129- function event_PostAddItem ($data)
2130- {
2131- $item_id = intval($data['itemid']);
2132-// $item_id = $data['itemid'];
2133- $tpath = requestVar('plug_custom_url_path');
2134- $tque = 'SELECT itime as result FROM %s WHERE inumber = %d';
2135- $itime = quickQuery(sprintf($tque, sql_table('item'), $item_id));
2136- echo 'itemid='.$item_id.'<br>idate='.$itime;
2137- $y = $m = $d = $temp = '';
2138- sscanf($itime, '%d-%d-%d %s', $y, $m, $d, $temp);
2139- $param = array ('year' => $y,
2140- 'month' => $m,
2141- 'day' => $d);
2142- $ipath = TEMPLATE::fill($tpath, $param);
2143- $query = 'SELECT ititle as result FROM %s WHERE inumber = %d';
2144- $iname = quickQuery(sprintf($query, sql_table('item'), $item_id));
2145- $blog_id = intval(getBlogIDFromItemID($item_id));
2146- $this->RegistPath($item_id, $ipath, $blog_id, 'item', $iname, TRUE);
2147- }
2148-
2149- function event_PostRegister ($data)
2150- {
2151- $memberID = intval($data['member']->id);
2152- $dispName = $data['member']->displayname;
2153- $this->RegistPath($memberID, $dispName, 0, 'member', $dispName, TRUE);
2154- $this->setMemberOption($memberID, 'customurl_mname', $dispName);
2155- }
2156-
2157- function event_AddItemFormExtras(&$data)
2158- {
2159- $this->createItemForm();
2160- }
2161-
2162- function event_EditItemFormExtras(&$data)
2163- {
2164- $this->createItemForm(intval($data['itemid']));
2165- }
2166-
2167- function event_PostUpdateItem($data)
2168- {
2169- $tpath = requestVar('plug_custom_url_path');
2170- $item_id = intval($data['itemid']);
2171- $tque = 'SELECT itime as result FROM %s WHERE inumber = %d';
2172- $itime = quickQuery(sprintf($tque ,sql_table('item'), $item_id));
2173-// $itimestamp = strtotime($itime);
2174-// $tt = explode(',', date('Y,m,d', $itimestamp));
2175- $y = $m = $d = $temp = '';
2176- sscanf($itime, '%d-%d-%d %s', $y, $m, $d, $temp);
2177- $param = array ('year' => $y,
2178- 'month' => $m,
2179- 'day' => $d);
2180- $ipath = TEMPLATE::fill($tpath, $param);
2181- $query = 'SELECT ititle as result FROM %s WHERE inumber = %d';
2182- $iname = quickQuery(sprintf($query, sql_table('item'), $item_id));
2183- $blog_id = intval(getBlogIDFromItemID($item_id));
2184- $this->RegistPath($item_id, $ipath, $blog_id, 'item', $iname);
2185- }
2186-
2187- function createItemForm($item_id = 0)
2188- {
2189- global $CONF;
2190- if ($item_id) {
2191- $query = 'SELECT obj_name as result FROM %s'
2192- . ' WHERE obj_param = "item" AND obj_id = %d';
2193- $item_id = intval($item_id);
2194- $res = quickQuery(sprintf($query, _CUSTOMURL_TABLE, $item_id));
2195- $ipath = substr($res, 0, strlen($res)-5);
2196- } else {
2197- $ipath = $this->getOption('customurl_dfitem');
2198- }
2199- echo <<<OUTPUT
2200-<h3>Custom URL</h3>
2201-<p>
2202-<label for="plug_custom_url">Custom Path:</label>
2203-<input id="plug_custom_url" name="plug_custom_url_path" value="{$ipath}" />
2204-</p>
2205-OUTPUT;
2206- }
2207-
2208- function event_PrePluginOptionsUpdate($data)
2209- {
2210- $blog_option = ($data['optionname'] == 'customurl_bname');
2211- $cate_option = ($data['optionname'] == 'customurl_cname');
2212- $memb_option = ($data['optionname'] == 'customurl_mname');
2213- $arch_option = ($data['optionname'] == 'customurl_archive');
2214- $arvs_option = ($data['optionname'] == 'customurl_archives');
2215- $memd_option = ($data['optionname'] == 'customurl_member');
2216- $contextid = intval($data['contextid']);
2217- $context = $data['context'];
2218- if ($blog_option || $cate_option || $memb_option) {
2219- if ($context == 'member' ) {
2220- $blogid = 0;
2221- $query = 'SELECT mname as result FROM %s WHERE mnumber = %d';
2222- $table = sql_table('member');
2223- $name = quickQuery(sprintf($query, $table, $contextid));
2224- } elseif (context == 'category') {
2225- $blogid = getBlogIDFromCatID($contextid);
2226- $query = 'SELECT cname as result FROM %s WHERE catid = %d';
2227- $table = sql_table('category');
2228- $name = quickQuery(sprintf($query, $table, $contextid));
2229- } else {
2230- $blogid = 0;
2231- $query = 'SELECT bname as result FROM %s WHERE bnumber = %d';
2232- $table = sql_table('blog');
2233- $name = quickQuery(sprintf($query, $table, $contextid));
2234- }
2235- $blogid = intval($blogid);
2236- $msg = $this->RegistPath($contextid, $data['value'], $blogid, $context, $name);
2237- if ($msg) {
2238- $this->error($msg);
2239- exit;
2240- }
2241- } elseif ($arch_option || $arvs_option || $memd_option) {
2242- if (!ereg("^[-_a-zA-Z0-9]+$", $data['value'])) {
2243- $name = substr($data['optionname'], 8);
2244- $msg = array (1, _INVALID_ERROR, $name, _INVALID_MSG);
2245- $this->error($msg);
2246- exit;
2247- } else {
2248- return;
2249- }
2250- }
2251- return;
2252- }
2253-
2254- function event_PostMoveItem($data)
2255- {
2256- $query = 'UPDATE %s SET obj_bid = %d'
2257- . ' WHERE obj_param = "%s" AND obj_id = %d';
2258- $destblogid = intval($data['destblogid']);
2259- $item_id = intval($data['itemid']);
2260- sql_query(sprintf($query, _CUSTOMURL_TABLE, $destblogid, 'item', $item_id));
2261- }
2262-
2263- function event_PostMoveCategory($data)
2264- {
2265- $query = 'UPDATE %s SET obj_bid = %d'
2266- . ' WHERE obj_param = "%s" AND obj_id = %d';
2267- $destblogid = intval($data['destblog']->blogid);
2268- $cat_id = intval($data['catid']);
2269- sql_query(sprintf($query, _CUSTOMURL_TABLE, $destblogid, 'category', $cat_id));
2270- }
2271-
2272- function RegistPath($objID, $path, $bid, $oParam, $name, $new = FALSE )
2273- {
2274- global $CONF;
2275- switch($oParam) {
2276- case 'item':
2277- case 'member':
2278- if (preg_match('/.html$/', $path))
2279- $path = substr($path, 0, -5);
2280- break;
2281- case 'blog':
2282- case 'category':
2283- case 'subcategory':
2284- break;
2285- default :
2286- return;
2287- break;
2288- }
2289- $bid = intval($bid);
2290- $objID = intval($objID);
2291- $name = rawurlencode($name);
2292-
2293- if ($new && $oParam == 'item') {
2294- $tque = 'SELECT itime as result FROM %s WHERE inumber = %d';
2295- $itime = quickQuery(sprintf($tque ,sql_table('item'), $objID));
2296-// $itimestamp = strtotime($itime);
2297-// $tt = explode(',', date('Y,m,d', $itimestamp));
2298- $y = $m = $d = $temp = '';
2299- sscanf($itime, '%d-%d-%d %s', $y, $m, $d, $temp);
2300- $template = $this->getOption('customurl_dfitem');
2301- $param = array ('year' => $y,
2302- 'month' => $m,
2303- 'day' => $d);
2304- $ikey = TEMPLATE::fill($template, $param);
2305- if ($path == $ikey) {
2306- $path = $ikey . '_' . $objID;
2307- }
2308- } elseif (!$new && strlen($path) == 0) {
2309- $del_que = 'DELETE FROM %s WHERE obj_id = %d AND obj_param = "%s"';
2310- sql_query(sprintf($del_que, _CUSTOMURL_TABLE, $objID, $oParam));
2311- $msg = array (0, _DELETE_PATH, $name, _DELETE_MSG);
2312- return $msg;
2313- exit;
2314- }
2315-
2316- $dotslash = array ('.', '/');
2317- $path = str_replace ($dotslash, '_', $path);
2318- if (!ereg("^[-_a-zA-Z0-9]+$", $path)) {
2319- $msg = array (1, _INVALID_ERROR, $name, _INVALID_MSG);
2320- return $msg;
2321- exit;
2322- }
2323-
2324- $tempPath = $path;
2325- if ($oParam == 'item' || $oParam == 'member') $tempPath .= '.html';
2326- $conf_que = 'SELECT obj_id FROM %s'
2327- . ' WHERE obj_name = "%s"'
2328- . ' AND obj_bid = %d'
2329- . ' AND obj_param = "%s"'
2330- . ' AND obj_id != %d';
2331- $res = sql_query(sprintf($conf_que, _CUSTOMURL_TABLE, $tempPath, $bid, $oParam, $objID));
2332- if ($res && mysql_num_rows($res)) {
2333- $msg = array (0, _CONFLICT_ERROR, $name, _CONFLICT_MSG);
2334- $path .= '_'.$objID;
2335- }
2336- if ($oParam == 'category' && !$msg) {
2337- $conf_cat = 'SELECT obj_id FROM %s WHERE obj_name = "%s"'
2338- . ' AND obj_param = "blog"';
2339- $res = sql_query(sprintf($conf_cat, _CUSTOMURL_TABLE, $tempPath));
2340- if ($res && mysql_num_rows($res)) {
2341- $msg = array (0, _CONFLICT_ERROR, $name, _CONFLICT_MSG);
2342- $path .= '_'.$objID;
2343- }
2344- }
2345- if ($oParam == 'blog' && !$msg) {
2346- $conf_blg = 'SELECT obj_id FROM %s WHERE obj_name = "%s"'
2347- . ' AND obj_param = "category"';
2348- $res = sql_query(sprintf($conf_blg, _CUSTOMURL_TABLE, $tempPath));
2349- if ($res && mysql_num_rows($res)) {
2350- $msg = array (0, _CONFLICT_ERROR, $name, _CONFLICT_MSG);
2351- $path .= '_'.$objID;
2352- }
2353- }
2354-
2355- $newPath = $path;
2356- if ($oParam == 'item' || $oParam == 'member') $newPath .= '.html';
2357- $query = 'SELECT * FROM %s WHERE obj_id = %d AND obj_param = "%s"';
2358- $res = sql_query(sprintf($query, _CUSTOMURL_TABLE, $objID, $oParam));
2359- $row = mysql_fetch_object($res);
2360- $pathID = $row->id;
2361- if ($pathID) {
2362- $query = 'UPDATE %s SET obj_name = "%s" WHERE id = %d';
2363- sql_query(sprintf($query, _CUSTOMURL_TABLE, $newPath, $pathID));
2364- } else {
2365- $query = 'INSERT INTO %s (obj_param, obj_name, obj_id, obj_bid)'
2366- . ' VALUES ("%s", "%s", %d, %d)';
2367- sql_query(sprintf($query, _CUSTOMURL_TABLE, $oParam, $newPath, $objID, $bid));
2368- }
2369- switch($oParam) {
2370- case 'blog':
2371- $this->setBlogOption($objID, 'customurl_bname', $path);
2372- break;
2373- case 'category':
2374- $this->setCategoryOption($objID, 'customurl_cname', $path);
2375- break;
2376- case 'member':
2377- $this->setMemberOption($objID, 'customurl_mname', $path);
2378- break;
2379- default :
2380- break;
2381- }
2382- return $msg;
2383- }
2384-
2385- function error($msg = '')
2386- {
2387- global $admin;
2388-
2389- $admin->pagehead();
2390- echo $msg[1].' : '.$msg[2].'<br />';
2391- echo $msg[3].'<br />';
2392- echo '<a href="index.php" onclick="history.back()">'._BACK.'</a>';
2393- $admin->pagefoot();
2394- return;
2395- }
2396-
2397- function quote_smart($value)
2398- {
2399- if (get_magic_quotes_gpc()) $value = stripslashes($value);
2400- if (!is_numeric($value)) {
2401- $value = mysql_real_escape_string($value);
2402- } elseif (is_numeric($value)) {
2403- $value = intval($value);
2404- }
2405- return $value;
2406- }
2407-}
2408-?><?php
2409-
2410-if (!function_exists('sql_table')) {
2411- function sql_table($name)
2412- {
2413- return 'nucleus_' . $name;
2414- }
2415-}
2416-
24173 if (!function_exists('htmlspecialchars_decode')) {
24184 function htmlspecialchars_decode($text)
24195 {
@@ -2422,13 +8,13 @@ if (!function_exists('htmlspecialchars_decode')) {
24228 }
24239
242410 if (!defined('_CUSTOMURL_TABLE_DEFINED')) {
2425- define('_CUSTOMURL_TABLE_DEFINED', 1);
2426- define('_CUSTOMURL_TABLE', sql_table('plug_customurl'));
2427- define('_C_SUBCAT_TABLE', sql_table('plug_multiple_categories_sub'));
11+ define('_CUSTOMURL_TABLE_DEFINED', 1);
12+ define('_CUSTOMURL_TABLE', sql_table('plug_customurl'));
13+ define('_C_SUBCAT_TABLE', sql_table('plug_multiple_categories_sub'));
242814 }
242915
243016 class NP_CustomURL extends NucleusPlugin
2431- {
17+{
243218
243319 function getMinNucleusVersion()
243420 {
@@ -2447,12 +33,12 @@ class NP_CustomURL extends NucleusPlugin
244733
244834 function getURL()
244935 {
2450- return 'http://shizuki.kinezumi.net/NucleusCMS/Plugins/NP_CustomURL/NP_CustomURL.html';
36+ return 'http://japan.nucleuscms.org/wiki/plugins:customurl';
245137 }
245238
245339 function getVersion()
245440 {
2455- return '0.3.2c';
41+ return '0.3.2e';
245642 }
245743
245844 function getDescription()
@@ -2462,7 +48,7 @@ class NP_CustomURL extends NucleusPlugin
246248
246349 function supportsFeature($what)
246450 {
2465- switch($what) {
51+ switch ($what) {
246652 case 'SqlTablePrefix':
246753 return 1;
246854 case 'HelpPage':
@@ -2488,9 +74,9 @@ class NP_CustomURL extends NucleusPlugin
248874 array_push(
248975 $data['options'],
249076 array(
2491- 'title' => _ADMIN_TITLE,
2492- 'url' => $this->getAdminURL(),
2493- 'tooltip' => _QUICK_TIPS
77+ 'title' => _ADMIN_TITLE,
78+ 'url' => $this->getAdminURL(),
79+ 'tooltip' => _QUICK_TIPS
249480 )
249581 );
249682 }
@@ -2498,51 +84,37 @@ class NP_CustomURL extends NucleusPlugin
249884 function getTableList()
249985 {
250086 return array(
2501- _CUSTOMURL_TABLE
2502- );
87+ _CUSTOMURL_TABLE
88+ );
250389 }
250490
250591 function getEventList()
250692 {
250793 return array(
2508- 'QuickMenu',
2509-// 'AdminPrePageHead',
2510- 'ParseURL',
2511- 'GenerateURL',
2512- 'PostAddBlog',
2513- 'PostAddItem',
2514- 'PostUpdateItem',
2515- 'PostRegister',
2516- 'PostAddCategory',
2517- 'PostDeleteBlog',
2518- 'PostDeleteItem',
2519- 'PostDeleteMember',
2520- 'PostDeleteCategory',
2521- 'PrePluginOptionsUpdate',
2522- 'PreItem',
2523- 'PostItem',
2524- 'PreSkinParse',
2525- 'AddItemFormExtras',
2526- 'EditItemFormExtras',
2527- 'PostMoveCategory',
2528- 'PostMoveItem',
2529-// 'PreSendContentType',
2530- 'InitSkinParse',
2531- );
94+ 'QuickMenu',
95+ 'ParseURL',
96+ 'GenerateURL',
97+ 'PostAddBlog',
98+ 'PostAddItem',
99+ 'PostUpdateItem',
100+ 'PostRegister',
101+ 'PostAddCategory',
102+ 'PostDeleteBlog',
103+ 'PostDeleteItem',
104+ 'PostDeleteMember',
105+ 'PostDeleteCategory',
106+ 'PrePluginOptionsUpdate',
107+ 'PreItem',
108+ 'PostItem',
109+ 'PreSkinParse',
110+ 'AddItemFormExtras',
111+ 'EditItemFormExtras',
112+ 'PostMoveCategory',
113+ 'PostMoveItem',
114+ 'InitSkinParse',
115+ );
2532116 }
2533117
2534-// function event_AdminPrePageHead($data)
2535-// {
2536-// if ($data['action'] == 'pluginhelp' && intGetVar('plugid') == $this->getID()) {
2537-// $data['extrahead'] = '<link rel="stylesheet" title="NP_CustomURL HELP"'
2538-// . ' type="text/css"'
2539-// . "\n"
2540-// . "\t\t\t"
2541-// . ' href="' . $this->getAdminURL()
2542-// . 'helpstyle.css" />' . "\n";
2543-// }
2544-// }
2545-
2546118 function install()
2547119 {
2548120 global $manager, $CONF;
@@ -2564,64 +136,70 @@ class NP_CustomURL extends NucleusPlugin
2564136 }
2565137
2566138 //Plugins sort
2567- $myid = intval($this->getID());
2568- $res = sql_query('SELECT pid, porder FROM '.sql_table('plugin'));
2569- while($p = mysql_fetch_array($res)) {
2570- $updateQuery = 'UPDATE %s SET porder = %d WHERE pid = %d';
2571- if (intval($p['pid']) == $myid) {
2572- sql_query(sprintf($updateQuery, sql_table('plugin'), 1, $myid));
139+ $plugTable = sql_table('plugin');
140+ $myid = intval($this->getID());
141+ $res = sql_query('SELECT pid, porder FROM ' . $plugTable);
142+ while ($p = mysql_fetch_array($res)) {
143+ $updateQuery = 'UPDATE %s '
144+ . 'SET porder = %d '
145+ . 'WHERE pid = %d';
146+ if (($pid = intval($p['pid'])) == $myid) {
147+ $q = sprintf($updateQuery, $plugTable, 1, $myid);
148+ sql_query($q);
2573149 } else {
2574- sql_query(sprintf($updateQuery, sql_table('plugin'), $p['porder']+1, $p['pid']));
150+ $porder = intval($p['porder']);
151+ $q = sprintf($updateQuery, $plugTable, $porder + 1, $pid);
152+ sql_query($q);
2575153 }
2576154 }
2577155
2578156 //create plugin's options and set default value
2579- $this->createOption('customurl_archive', _OP_ARCHIVE_DIR_NAME,
2580- 'text', $CONF['ArchiveKey']);
2581- $this->createOption('customurl_archives', _OP_ARCHIVES_DIR_NAME,
2582- 'text', $CONF['ArchivesKey']);
2583- $this->createOption('customurl_member', _OP_MEMBER_DIR_NAME,
2584- 'text', $CONF['MemberKey']);
2585- $this->createOption('customurl_dfitem', _OP_DEF_ITEM_KEY,
2586- 'text', $CONF['ItemKey']);
2587- $this->createOption('customurl_dfcat', _OP_DEF_CAT_KEY,
2588- 'text', $CONF['CategoryKey']);
2589- $this->createOption('customurl_dfscat', _OP_DEF_SCAT_KEY,
2590- 'text', 'subcategory');
2591- $this->createOption('customurl_tabledel', _OP_TABLE_DELETE,
2592- 'yesno', 'no');
2593- $this->createOption('customurl_quicklink', _OP_QUICK_LINK,
2594- 'yesno', 'yes');
2595- $this->createOption('customurl_notfound', _OP_NOT_FOUND,
2596- 'select', '404',
157+ $this->createOption('customurl_archive', _OP_ARCHIVE_DIR_NAME,
158+ 'text', $CONF['ArchiveKey']);
159+ $this->createOption('customurl_archives', _OP_ARCHIVES_DIR_NAME,
160+ 'text', $CONF['ArchivesKey']);
161+ $this->createOption('customurl_member', _OP_MEMBER_DIR_NAME,
162+ 'text', $CONF['MemberKey']);
163+ $this->createOption('customurl_dfitem', _OP_DEF_ITEM_KEY,
164+ 'text', $CONF['ItemKey']);
165+ $this->createOption('customurl_dfcat', _OP_DEF_CAT_KEY,
166+ 'text', $CONF['CategoryKey']);
167+ $this->createOption('customurl_dfscat', _OP_DEF_SCAT_KEY,
168+ 'text', 'subcategory');
169+ $this->createOption('customurl_tabledel', _OP_TABLE_DELETE,
170+ 'yesno', 'no');
171+ $this->createOption('customurl_quicklink', _OP_QUICK_LINK,
172+ 'yesno', 'yes');
173+ $this->createOption('customurl_notfound', _OP_NOT_FOUND,
174+ 'select', '404',
2597175 '404 Not Found|404|303 See Other|303');
2598- $this->createBlogOption( 'use_customurl', _OP_USE_CURL,
2599- 'yesno', 'yes');
2600- $this->createBlogOption( 'redirect_normal', _OP_RED_NORM,
2601- 'yesno', 'yes');
2602- $this->createBlogOption( 'redirect_search', _OP_RED_SEARCH,
2603- 'yesno', 'yes');
2604- $this->createBlogOption( 'customurl_bname', _OP_BLOG_PATH,
176+ $this->createBlogOption( 'use_customurl', _OP_USE_CURL,
177+ 'yesno', 'yes');
178+ $this->createBlogOption( 'redirect_normal', _OP_RED_NORM,
179+ 'yesno', 'yes');
180+ $this->createBlogOption( 'redirect_search', _OP_RED_SEARCH,
181+ 'yesno', 'yes');
182+ $this->createBlogOption( 'customurl_bname', _OP_BLOG_PATH,
2605183 'text');
2606-// $this->createItemOption( 'customurl_iname', _OP_ITEM_PATH,
2607-// 'text', $CONF['ItemKey']);
2608- $this->createMemberOption( 'customurl_mname', _OP_MEMBER_PATH,
184+// $this->createItemOption( 'customurl_iname', _OP_ITEM_PATH,
185+// 'text', $CONF['ItemKey']);
186+ $this->createMemberOption( 'customurl_mname', _OP_MEMBER_PATH,
2609187 'text');
2610- $this->createCategoryOption('customurl_cname', _OP_CATEGORY_PATH,
188+ $this->createCategoryOption('customurl_cname', _OP_CATEGORY_PATH,
2611189 'text');
2612190
2613191 //default archive directory name
2614- $this->setOption('customurl_archive', $CONF['ArchiveKey']);
192+ $this->setOption('customurl_archive', $CONF['ArchiveKey']);
2615193 //default archives directory name
2616- $this->setOption('customurl_archives', $CONF['ArchivesKey']);
194+ $this->setOption('customurl_archives', $CONF['ArchivesKey']);
2617195 //default member directory name
2618- $this->setOption('customurl_member', $CONF['MemberKey']);
196+ $this->setOption('customurl_member', $CONF['MemberKey']);
2619197 //default itemkey_template
2620- $this->setOption('customurl_dfitem', $CONF['ItemKey']);
198+ $this->setOption('customurl_dfitem', $CONF['ItemKey']);
2621199 //default categorykey_template
2622- $this->setOption('customurl_dfcat', $CONF['CategoryKey']);
200+ $this->setOption('customurl_dfcat', $CONF['CategoryKey']);
2623201 //default subcategorykey_template
2624- $this->setOption('customurl_dfscat', 'subcategory');
202+ $this->setOption('customurl_dfscat', 'subcategory');
2625203
2626204 //create data table
2627205 $sql = 'CREATE TABLE IF NOT EXISTS ' . _CUSTOMURL_TABLE . ' ('
@@ -2635,76 +213,92 @@ class NP_CustomURL extends NucleusPlugin
2635213 sql_query($sql);
2636214
2637215 //setting default aliases
2638- $this->_createNewPath('blog', 'blog', 'bnumber', 'bshortname');
2639- $this->_createNewPath('item', 'item', 'inumber', 'iblog');
2640- $this->_createNewPath('category', 'category', 'catid', 'cblog');
2641- $this->_createNewPath('member', 'member', 'mnumber', 'mname');
216+ $this->_createNewPath('blog', 'blog', 'bnumber', 'bshortname');
217+ $this->_createNewPath('item', 'item', 'inumber', 'iblog');
218+ $this->_createNewPath('category', 'category', 'catid', 'cblog');
219+ $this->_createNewPath('member', 'member', 'mnumber', 'mname');
2642220
2643221 if ($this->pluginCheck('MultipleCategories')) {
2644- $this->_createNewPath('subcategory', 'plug_multiple_categories_sub', 'scatid', 'catid');
222+ $scatTableName = 'plug_multiple_categories_sub';
223+ $this->_createNewPath('subcategory', $scatTableName, 'scatid', 'catid');
2645224 }
2646225
2647226 }
2648227
2649228 function _createNewPath($type, $n_table, $id, $bids)
2650229 {
2651- $tmpTable = sql_table('plug_customurl_temp');
2652- $createQuery = 'CREATE TABLE %s SELECT obj_id, obj_param FROM %s'
2653- . ' WHERE obj_param = "%s"';
230+ $tmpTable = sql_table('plug_customurl_temp');
231+ $createQuery = 'CREATE TABLE %s '
232+ . 'SELECT obj_id, obj_param '
233+ . 'FROM %s '
234+ . 'WHERE obj_param = "%s"';
2654235 sql_query(sprintf($createQuery, $tmpTable, _CUSTOMURL_TABLE, $type));
2655- $TmpQuery = 'SELECT %s, %s FROM %s LEFT JOIN %s ON %s.%s = %s.obj_id'
2656- . ' WHERE %s.obj_id is null';
2657- $table = sql_table($n_table);
2658- $temp = sql_query(sprintf($TmpQuery, $id, $bids, $table, $tmpTable, $table, $id, $tmpTable, $tmpTable));
236+ $TmpQuery = 'SELECT %s, %s '
237+ . 'FROM %s as ttb'
238+ . 'LEFT JOIN %s as tcu'
239+ . 'ON ttb.%s = tcu.obj_id '
240+ . 'WHERE tcu.obj_id is null';
241+ $table = sql_table($n_table);
242+ $TmpQuery = sprintf($TmpQuery, $id, $bids, $table, $tmpTable, $id);
243+ $temp = sql_query($TmpQuery);
2659244 if ($temp) {
2660245 while ($row=mysql_fetch_array($temp)) {
2661246 switch ($type) {
2662247 case 'blog':
2663248 //set access by BlogshortName/
2664249 $newPath = $row[$bids];
2665- $blgid = 0;
250+ $blgid = 0;
2666251 break;
2667252 case 'item':
2668253 //set access by (itemkey_template)_itemid.html
2669- $tque = 'SELECT itime as result FROM %s WHERE inumber = %d';
2670- $itime = quickQuery( sprintf($tque ,sql_table('item'), intval($row[$id]) ) );
2671- $y = $m = $d = '';
2672- sscanf($itime,'%d-%d-%d %s',$y,$m,$d,$temp);
2673- $ikey = TEMPLATE::fill($this->getOption('customurl_dfitem'),
2674- array ('year' => $y,
2675- 'month' => $m,
2676- 'day' => $d)
2677- );
254+ $tque = 'SELECT '
255+ . 'itime as result '
256+ . 'FROM %s '
257+ . 'WHERE inumber = %d';
258+ $tque = sprintf($tque, $table, intval($row[$id]));
259+ $itime = quickQuery($tque);
260+ $y = $m = $d = $temp = '';
261+ sscanf($itime, '%d-%d-%d %s', $y, $m, $d, $temp);
262+ $itime = array(
263+ 'year' => $y,
264+ 'month' => $m,
265+ 'day' => $d
266+ );
267+ $itplt = $this->getOption('customurl_dfitem');
268+ $ikey = TEMPLATE::fill($itplt, $itime);
2678269 $newPath = $ikey . '_' . $row[$id] . '.html';
2679- $blgid = $row[$bids];
270+ $blgid = $row[$bids];
2680271 break;
2681272 case 'category':
2682273 //set access by (categorykey_template)_categoryid/
2683274 $newPath = $this->getOption('customurl_dfcat') . '_' . $row[$id];
2684- $blgid = $row[$bids];
275+ $blgid = $row[$bids];
2685276 break;
2686277 case 'member':
2687278 //set access by loginName.html
2688279 $newPath = $row[$bids] . '.html';
2689- $blgid = 0;
280+ $blgid = 0;
2690281 break;
2691282 case 'subcategory':
2692283 //set access by (subcategorykey_template)_subcategoryid/
2693284 $newPath = $this->getOption('customurl_dfscat') . '_' . $row[$id];
2694- $blgid = $row[$bids];
285+ $blgid = $row[$bids];
2695286 break;
2696287 default:
2697288 break;
2698289 }
2699- $insertQuery = 'INSERT INTO %s (obj_param, obj_id, obj_name, obj_bid)'
2700- . ' VALUES ("%s", %d, "%s", %d)';
2701- $row[$id] = intval($row[$id]);
2702- $blgid = intval($blgid);
290+ $insertQuery = 'INSERT INTO %s '
291+ . '(obj_param, obj_id, obj_name, obj_bid) '
292+ . 'VALUES ("%s", %d, "%s", %d)';
293+ $row[$id] = intval($row[$id]);
294+ $blgid = intval($blgid);
2703295 sql_query(sprintf($insertQuery, _CUSTOMURL_TABLE, $type, $row[$id], $newPath, $blgid));
2704296 }
2705297 }
2706- $query = 'SELECT obj_id, obj_name FROM %s WHERE obj_param = "%s"';
2707- $temp = sql_query(sprintf($query, _CUSTOMURL_TABLE, $type));
298+ $query = 'SELECT obj_id, obj_name '
299+ . 'FROM %s '
300+ . 'WHERE obj_param = "%s"';
301+ $temp = sql_query(sprintf($query, _CUSTOMURL_TABLE, $type));
2708302 while ($row = mysql_fetch_array($temp)) {
2709303 $name = $row['obj_name'];
2710304 $id = intval($row['obj_id']);
@@ -2778,21 +372,22 @@ class NP_CustomURL extends NucleusPlugin
2778372 // initialize
2779373 $info = $data['info'];
2780374 $complete =& $data['complete'];
2781- if ($complete) return;
375+ if ($complete) {
376+ return;
377+ }
2782378 $useCustomURL = $this->getAllBlogOptions('use_customurl');
2783379
2784380 // Use NP_MultipleCategories ?
2785- $mcategories = $this->pluginCheck('MultipleCategories');
381+ $mcategories = $this->pluginCheck('MultipleCategories');
2786382 if ($mcategories) {
2787- if (method_exists($mcategories, "getRequestName")) {
2788- $mcategories->event_PreSkinParse(array());
2789- global $subcatid;
383+ $mcategories->event_PreSkinParse(array());
384+ global $subcatid;
385+ if (method_exists($mcategories, 'getRequestName')) {
2790386 $subrequest = $mcategories->getRequestName();
387+ } else {
388+ $subrequest = 'subcatid';
2791389 }
2792390 }
2793- if (!$subrequest) {
2794- $subrequest = 'subcatid';
2795- }
2796391
2797392 // initialize and sanitize '$blogid'
2798393 if (!$blogid) {
@@ -2828,7 +423,7 @@ class NP_CustomURL extends NucleusPlugin
2828423 }
2829424
2830425 // Sanitize 'PATH_INFO'
2831- $info = trim($info, '/');
426+ $info = trim($info, '/');
2832427 $v_path = explode("/", $info);
2833428 foreach($v_path as $key => $value) {
2834429 $value = urlencode($value);
@@ -2842,9 +437,9 @@ class NP_CustomURL extends NucleusPlugin
2842437 $HTTP_SERVER_VARS['PATH_INFO'] = implode('/', $v_path);
2843438
2844439 // Admin area check
2845- $tmpURL = sprintf("%s%s%s", "http://", serverVar("HTTP_HOST"), serverVar("SCRIPT_NAME"));
2846- $uri = str_replace('/', '\/', $tmpURL);
2847- $plug_url = str_replace('/', '\/', $CONF['PluginURL']);
440+ $tmpURL = sprintf("%s%s%s", "http://", serverVar("HTTP_HOST"), serverVar("SCRIPT_NAME"));
441+ $uri = str_replace('/', '\/', $tmpURL);
442+ $plug_url = str_replace('/', '\/', $CONF['PluginURL']);
2848443 $u_plugAction = (getVar('action') == 'plugin' && getVar('name'));
2849444 if (strpos($uri, $plug_url) === 0 || $u_plugAction) {
2850445 $UsingPlugAdmin = TRUE;
@@ -2860,15 +455,15 @@ class NP_CustomURL extends NucleusPlugin
2860455 $redirectSerch = ($this->getBlogOption($blogid, 'redirect_search') == 'yes');
2861456 if ($redirectSerch) {
2862457 if ($search_q) {
2863- $que_str = getVar('query');
2864- $que_str = htmlspecialchars($que_str);
2865- $que_str = mb_eregi_replace('/', 'ssslllaaassshhh', $que_str);
2866- $que_str = mb_eregi_replace("'", 'qqquuuooottt', $que_str);
2867- $que_str = mb_eregi_replace('&', 'aaammmppp', $que_str);
2868- $que_str = urlencode($que_str);
458+ $que_str = getVar('query');
459+ $que_str = htmlspecialchars($que_str);
460+ $que_str = mb_eregi_replace('/', 'ssslllaaassshhh', $que_str);
461+ $que_str = mb_eregi_replace("'", 'qqquuuooottt', $que_str);
462+ $que_str = mb_eregi_replace('&', 'aaammmppp', $que_str);
463+ $que_str = urlencode($que_str);
2869464 $search_path = '/search/' . $que_str;
2870- $b_url = createBlogidLink($blogid);
2871- $redurl = sprintf("%s%s", $b_url, $search_path);
465+ $b_url = createBlogidLink($blogid);
466+ $redurl = sprintf("%s%s", $b_url, $search_path);
2872467 redirect($redurl); // 302 Moved temporary
2873468 exit;
2874469 }
@@ -2878,12 +473,12 @@ class NP_CustomURL extends NucleusPlugin
2878473 }
2879474
2880475 // redirection nomal URL to FancyURL
2881- $temp_req = explode('?', serverVar('REQUEST_URI'));
2882- $reqPath = trim(end($temp_req), '/');
2883- $indexrdf = ($reqPath == 'xml-rss1.php');
2884- $atomfeed = ($reqPath == 'atom.php');
2885- $rss2feed = ($reqPath == 'xml-rss2.php');
2886- $feeds = ($indexrdf || $atomfeed || $rss2feed);
476+ $temp_req = explode('?', serverVar('REQUEST_URI'));
477+ $reqPath = trim(end($temp_req), '/');
478+ $indexrdf = ($reqPath == 'xml-rss1.php');
479+ $atomfeed = ($reqPath == 'atom.php');
480+ $rss2feed = ($reqPath == 'xml-rss2.php');
481+ $feeds = ($indexrdf || $atomfeed || $rss2feed);
2887482 $redirectNormal = ($this->getBlogOption($blogid, 'redirect_normal') == 'yes');
2888483 if ($redirectNormal && serverVar('QUERY_STRING') && !$feeds && !$exLink) {
2889484 $temp = explode('&', serverVar('QUERY_STRING'));
@@ -2937,14 +532,14 @@ class NP_CustomURL extends NucleusPlugin
2937532 }
2938533 }
2939534 if (reset($p_arr)) {
2940- $b_url = createBlogidLink($blogid);
535+ $b_url = createBlogidLink($blogid);
2941536 $red_path = '/' . implode('/', $p_arr);
2942537 if (substr($b_url, -1) == '/') {
2943538 $b_url = rtrim($b_url, '/');
2944539 }
2945540 $redurl = sprintf("%s%s", $b_url, $red_path);
2946541 // HTTP status 301 "Moved Permanentry"
2947- header( "HTTP/1.1 301 Moved Permanently" );
542+ header('HTTP/1.1 301 Moved Permanently');
2948543 header('Location: ' . $redurl);
2949544 exit;
2950545 }
@@ -2975,9 +570,9 @@ class NP_CustomURL extends NucleusPlugin
2975570 // decode unofficial Page switch '/page_2.html'
2976571 foreach($v_path as $pathName) {
2977572 if (preg_match('/^page_/', $pathName)) {
2978- $temp_info = explode('page_', $pathName);
573+ $temp_info = explode('page_', $pathName);
2979574 $_GET['page'] = intval($temp_info[1]);
2980- $page = array_pop($v_path);
575+ $page = array_pop($v_path);
2981576 }
2982577 }
2983578
@@ -2986,7 +581,7 @@ class NP_CustomURL extends NucleusPlugin
2986581 if (substr($tail, -10, 10) == '.trackback') {
2987582 $v_pathName = substr($tail, 0, -10);
2988583 // echo $v_pathName;
2989- if (is_numeric($v_pathName)) {
584+ if (is_numeric($v_pathName) || substr($v_pathName, -5) == '.html') {
2990585 $this->_trackback($blogid, $v_pathName);
2991586 } else {
2992587 $this->_trackback($blogid, $v_pathName . '.html');
@@ -3000,15 +595,15 @@ class NP_CustomURL extends NucleusPlugin
3000595 $bLink = TRUE;
3001596 }
3002597 $linkObj = array (
3003- 'bid' => 0,
3004- 'name' => reset($v_path),
3005- 'linkparam' => 'blog'
3006- );
598+ 'bid' => 0,
599+ 'name' => reset($v_path),
600+ 'linkparam' => 'blog'
601+ );
3007602 $blog_id = $this->getRequestPathInfo($linkObj);
3008603 if ($blog_id) {
3009604 $blogid = $blog_id;
3010- $trush = array_shift($v_path);
3011- $bLink = TURE;
605+ $trush = array_shift($v_path);
606+ $bLink = TURE;
3012607 }
3013608 if ($useCustomURL[$blogid] == 'no') {
3014609 return;
@@ -3022,7 +617,7 @@ class NP_CustomURL extends NucleusPlugin
3022617 if (isset($v_path[$i]) && is_numeric($v_path[$i])) {
3023618 if ($useCustomURL[intval($v_path[$i])] != 'yes') {
3024619 $blogid = intval($v_path[$i]);
3025- $bLink = TRUE;
620+ $bLink = TRUE;
3026621 } else {
3027622 $redURI = createBlogidLink(intval($v_path[$i]));
3028623 }
@@ -3033,7 +628,7 @@ class NP_CustomURL extends NucleusPlugin
3033628 if (isset($v_path[$i]) && is_numeric($v_path[$i])) {
3034629 if ($useCustomURL[$blogid] != 'yes') {
3035630 $itemid = intval($v_path[$i]);
3036- $iLink = TRUE;
631+ $iLink = TRUE;
3037632 } else {
3038633 $redURI = createItemLink(intval($v_path[$i]));
3039634 }
@@ -3044,8 +639,8 @@ class NP_CustomURL extends NucleusPlugin
3044639 case 'catid':
3045640 if (isset($v_path[$i]) && is_numeric($v_path[$i])) {
3046641 if ($useCustomURL[$blogid] != 'yes') {
3047- $catid = intval($v_path[$i]);
3048- $cLink = TRUE;
642+ $catid = intval($v_path[$i]);
643+ $cLink = TRUE;
3049644 } else {
3050645 $redURI = createCategoryLink(intval($v_path[$i]));
3051646 }
@@ -3057,14 +652,14 @@ class NP_CustomURL extends NucleusPlugin
3057652 $subCat = (isset($v_path[$i]) && is_numeric($v_path[$i]));
3058653 if ($mcategories && $subCat && $i >= 3 && is_numeric($v_path[$c])) {
3059654 if ($useCustomURL[$blogid] != 'yes') {
3060- $subcatid = intval($v_path[$i]);
3061- $catid = intval($v_path[$c]);
3062- $cLink = TRUE;
655+ $subcatid = intval($v_path[$i]);
656+ $catid = intval($v_path[$c]);
657+ $cLink = TRUE;
3063658 } else {
3064659 $subcat_id = intval($v_path[$i]);
3065660 $catid = intval($v_path[$c]);
3066661 $linkParam = array($subrequest => $subcat_id);
3067- $redURI = createCategoryLink($catid, $linkParam);
662+ $redURI = createCategoryLink($catid, $linkParam);
3068663 }
3069664 }
3070665 break;
@@ -3075,18 +670,18 @@ class NP_CustomURL extends NucleusPlugin
3075670 if (isset($v_path[$i]) && is_numeric($v_path[$i])) {
3076671 if ($useCustomURL[intval($v_path[$i])] != 'yes') {
3077672 $archivelist = intval($v_path[$i]);
3078- $blogid = $archivelist;
3079- $exLink = TRUE;
673+ $blogid = $archivelist;
674+ $exLink = TRUE;
3080675 } else {
3081- $redURI = createArchiveListLink(intval($v_path[$i]));
676+ $redURI = createArchiveListLink(intval($v_path[$i]));
3082677 }
3083678 // Customized URL
3084679 } elseif (isset($v_path[$i])) {
3085680 $archivelist = $blogid;
3086- $redURI = createArchiveListLink($archivelist);
681+ $redURI = createArchiveListLink($archivelist);
3087682 } else {
3088683 $archivelist = $blogid;
3089- $exLink = TRUE;
684+ $exLink = TRUE;
3090685 }
3091686 break;
3092687 // for archive
@@ -3111,9 +706,9 @@ class NP_CustomURL extends NucleusPlugin
3111706 if (!empty($d)) {
3112707 $archive = sprintf('%04d-%02d-%02d', $y, $m, $d);
3113708 } elseif (!empty($m)) {
3114- $archive = sprintf('%04d-%02d', $y, $m);
709+ $archive = sprintf('%04d-%02d', $y, $m);
3115710 } else {
3116- $archive = sprintf('%04d', $y);
711+ $archive = sprintf('%04d', $y);
3117712 }
3118713 if ($useCustomURL[intval($v_path[$i])] != 'yes') {
3119714 $blogid = intval($v_path[$i]);
@@ -3126,12 +721,12 @@ class NP_CustomURL extends NucleusPlugin
3126721 // } elseif ($darc || $marc || $yarc) {
3127722 } elseif ($carc) {
3128723 sscanf($v_path[$i], '%d-%d-%d', $y, $m, $d);
3129- if (isset($d)) {
724+ if (!empty($d)) {
3130725 $archive = sprintf('%04d-%02d-%02d', $y, $m, $d);
3131726 } elseif (!empty($m)) {
3132- $archive = sprintf('%04d-%02d', $y, $m);
727+ $archive = sprintf('%04d-%02d', $y, $m);
3133728 } else {
3134- $archive = sprintf('%04d', $y);
729+ $archive = sprintf('%04d', $y);
3135730 }
3136731 $exLink = TRUE;
3137732 } else {
@@ -3147,12 +742,14 @@ class NP_CustomURL extends NucleusPlugin
3147742 // Customized URL
3148743 $customMemberURL = (substr($v_path[$i], -5, 5) == '.html');
3149744 if (isset($v_path[$i]) && $customMemberURL) {
3150- $memberInfo = array('linkparam' => 'member',
3151- 'bid' => 0,
3152- 'name' => $v_path[$i]);
3153- $member_id = $this->getRequestPathInfo($memberInfo);
3154- $memberid = intval($member_id);
3155- $exLink = TRUE;
745+ $memberInfo = array(
746+ 'linkparam' => 'member',
747+ 'bid' => 0,
748+ 'name' => $v_path[$i]
749+ );
750+ $member_id = $this->getRequestPathInfo($memberInfo);
751+ $memberid = intval($member_id);
752+ $exLink = TRUE;
3156753 // FancyURL
3157754 } elseif (isset($v_path[$i]) && is_numeric($v_path[$i])) {
3158755 if ($useCustomURL[$blogid] != 'yes') {
@@ -3169,7 +766,7 @@ class NP_CustomURL extends NucleusPlugin
3169766 case 'tag':
3170767 if (isset($v_path[$i]) && is_string($v_path[$i])) {
3171768 $_REQUEST['tag'] = $v_path[$i];
3172- $exLink = TRUE;
769+ $exLink = TRUE;
3173770 }
3174771 break;
3175772 // for ExtraSkinJP
@@ -3196,21 +793,21 @@ class NP_CustomURL extends NucleusPlugin
3196793 case 'search':
3197794 $redirectSerch = ($this->getBlogOption($blogid, 'redirect_search') == 'yes');
3198795 if ($redirectSerch) {
3199- $que_str = urldecode($v_path[$i]);
3200- $que_str = mb_eregi_replace('ssslllaaassshhh', '/', $que_str);
3201- $que_str = mb_eregi_replace('qqquuuooottt', "'", $que_str);
3202- $que_str = mb_eregi_replace('aaammmppp', '&', $que_str);
3203- $que_str = htmlspecialchars_decode($que_str);
796+ $que_str = urldecode($v_path[$i]);
797+ $que_str = mb_eregi_replace('ssslllaaassshhh', '/', $que_str);
798+ $que_str = mb_eregi_replace('qqquuuooottt', "'", $que_str);
799+ $que_str = mb_eregi_replace('aaammmppp', '&', $que_str);
800+ $que_str = htmlspecialchars_decode($que_str);
3204801 $_GET['query'] = $que_str;
3205- $query = $que_str;
3206- $exLink = TRUE;
802+ $query = $que_str;
803+ $exLink = TRUE;
3207804 }
3208805 break;
3209806 // for pageswitch
3210807 case 'page':
3211808 if (isset($v_path[$i]) && is_numeric($v_path[$i])) {
3212809 $_GET['page'] = intval($v_path[$i]);
3213- $exLink = TRUE;
810+ $exLink = TRUE;
3214811 }
3215812 break;
3216813 // for tDiarySkin
@@ -3219,11 +816,8 @@ class NP_CustomURL extends NucleusPlugin
3219816 case 'monthlimit':
3220817 $tDiaryPlugin = $this->pluginCheck('tDiarySkin');
3221818 if ($tDiaryPlugin && isset($v_path[$i])) {
3222-// sscanf($v_path[$i], '%d-%d', $m, $d);
3223-// $linkDate = sprintf('%02d-%02d', $m, $d);
3224-// $_GET['linkdate'] = $linkDate;
3225819 $_GET[$pathName] = $v_path[$i];
3226- $exLink = TRUE;
820+ $exLink = TRUE;
3227821 }
3228822 break;
3229823 // for trackback
@@ -3237,15 +831,16 @@ class NP_CustomURL extends NucleusPlugin
3237831 // decode Customized URL
3238832 default:
3239833 // initialyze
3240- $linkObj = array ('bid' => $blogid,
834+ $linkObj = array (
835+ 'bid' => $blogid,
3241836 'name' => $pathName
3242837 );
3243- $comp = FALSE;
838+ $comp = FALSE;
3244839 $isItem = (substr($pathName, -5) == '.html');
3245840 // category ?
3246841 if (!$comp && !$cLink && !$iLink && !$isItem) {
3247842 $linkObj['linkparam'] = 'category';
3248- $cat_id = $this->getRequestPathInfo($linkObj);
843+ $cat_id = $this->getRequestPathInfo($linkObj);
3249844 if (!empty($cat_id)) {
3250845 $catid = intval($cat_id);
3251846 $cLink = TURE;
@@ -3256,18 +851,18 @@ class NP_CustomURL extends NucleusPlugin
3256851 if (!$comp && $cLink && !$iLink && $mcategories && !$isItem) {
3257852 $linkObj['linkparam'] = 'subcategory';
3258853 $linkObj['bid'] = $catid;
3259- $subcat_id = $this->getRequestPathInfo($linkObj);
854+ $subcat_id = $this->getRequestPathInfo($linkObj);
3260855 if (!empty($subcat_id)) {
3261856 $_REQUEST[$subrequest] = intval($subcat_id);
3262- $subcatid = intval($subcat_id);
3263- $sc = $i;
3264- $comp = TRUE;
857+ $subcatid = intval($subcat_id);
858+ $sc = $i;
859+ $comp = TRUE;
3265860 }
3266861 }
3267862 // item ?
3268863 if ($isItem) {
3269864 $linkObj['linkparam'] = 'item';
3270- $item_id = $this->getRequestPathInfo($linkObj);
865+ $item_id = $this->getRequestPathInfo($linkObj);
3271866 if (!empty($item_id)) {
3272867 $itemid = intval($item_id);
3273868 $iLink = TRUE;
@@ -3290,10 +885,10 @@ class NP_CustomURL extends NucleusPlugin
3290885 }
3291886
3292887 $feedurl = array(
3293- 'rss1.xml',
3294- 'index.rdf',
3295- 'rss2.xml',
3296- 'atom.xml',
888+ 'rss1.xml',
889+ 'index.rdf',
890+ 'rss2.xml',
891+ 'atom.xml',
3297892 );
3298893 $siteMapPlugin = $this->pluginCheck('GoogleSitemap');
3299894 if ($siteMapPlugin) {
@@ -3310,9 +905,9 @@ class NP_CustomURL extends NucleusPlugin
3310905 }
3311906 }
3312907 }
3313- $feedurl = array_unique($feedurl);
908+ $feedurl = array_unique($feedurl);
3314909 $request_path = end($v_path);
3315- $feeds = in_array($request_path, $feedurl, true);
910+ $feeds = in_array($request_path, $feedurl, true);
3316911
3317912 // finish decode
3318913 if (!$exLink && !$feeds) {
@@ -3320,17 +915,21 @@ class NP_CustomURL extends NucleusPlugin
3320915 if (substr(end($v_path), -5) == '.html' && !$iLink) {
3321916 $notFound = TRUE;
3322917 if (!empty($subcatid)) {
3323- $linkParam = array($subrequest => $subcatid);
3324- $uri = createCategoryLink($catid, $linkParam);
918+ $linkParam = array(
919+ $subrequest => $subcatid
920+ );
921+ $uri = createCategoryLink($catid, $linkParam);
3325922 } elseif (!empty($catid)) {
3326923 $uri = createCategoryLink($catid);
3327924 } else {
3328925 $uri = createBlogidLink($blogid);
3329926 }
3330927 } elseif (count($v_path) > $sc && !empty($subcatid) && !$iLink) {
3331- $notFound = TRUE;
3332- $linkParam = array($subrequest => $subcatid);
3333- $uri = createCategoryLink($catid, $linkParam);
928+ $notFound = TRUE;
929+ $linkParam = array(
930+ $subrequest => $subcatid
931+ );
932+ $uri = createCategoryLink($catid, $linkParam);
3334933 } elseif (count($v_path) >= 2 && !$subcatid && !$iLink) {
3335934 $notFound = TRUE;
3336935 if (isset($catid)) {
@@ -3340,24 +939,26 @@ class NP_CustomURL extends NucleusPlugin
3340939 }
3341940 } elseif (reset($v_path) && !$catid && !$subcatid && !$iLink) {
3342941 $notFound = TRUE;
3343- $uri = createBlogidLink($blogid);
942+ $uri = createBlogidLink($blogid);
3344943 } else {
3345944 // Found
3346945 // setting $CONF['Self'] for other plugins
3347- $uri = createBlogidLink($blogid);
946+ $uri = createBlogidLink($blogid);
3348947 $CONF['Self'] = rtrim($uri, '/');
3349- $complete = TRUE;
948+ $complete = TRUE;
3350949 return ;
3351950 }
3352951 } else {
3353- $uri = createBlogidLink($blogid);
952+ $uri = createBlogidLink($blogid);
3354953 $CONF['Self'] = rtrim($uri, '/');
3355- $complete = TRUE;
954+ $complete = TRUE;
3356955 return ;
3357956 }
3358957 // Behavior Not Found
3359958 if ($notFound) {
3360- if (substr($uri, -1) != '/') $uri .= '/';
959+ if (substr($uri, -1) != '/') {
960+ $uri .= '/';
961+ }
3361962 if ($this->getOption('customurl_notfound') == '404') {
3362963 header('HTTP/1.1 404 Not Found');
3363964 doError(_NO_SUCH_URI);
@@ -3373,13 +974,16 @@ class NP_CustomURL extends NucleusPlugin
3373974 // decode 'path name' to 'id'
3374975 function getRequestPathInfo($linkObj)
3375976 {
3376- $query = 'SELECT obj_id as result FROM %s'
3377- . ' WHERE obj_name = "%s"'
3378- . ' AND obj_bid = %d AND obj_param = "%s"';
977+ $query = 'SELECT obj_id as result'
978+ . ' FROM %s'
979+ . ' WHERE obj_name = "%s"'
980+ . ' AND obj_bid = %d'
981+ . ' AND obj_param = "%s"';
3379982 $name = $this->quote_smart($linkObj['name']);
3380983 $bid = $this->quote_smart($linkObj['bid']);
3381984 $linkparam = $this->quote_smart($linkObj['linkparam']);
3382- $ObjID = quickQuery(sprintf($query, _CUSTOMURL_TABLE, $name, $bid, $linkparam));
985+ $query = sprintf($query, _CUSTOMURL_TABLE, $name, $bid, $linkparam);
986+ $ObjID = quickQuery($query);
3383987 if (!$ObjID) {
3384988 return;
3385989 } else {
@@ -3390,13 +994,15 @@ class NP_CustomURL extends NucleusPlugin
3390994 // Receive TrackBack ping
3391995 function _trackback($bid, $path)
3392996 {
3393- $blog_id = intval($bid);
997+ $blog_id = intval($bid);
3394998 $TrackBack = $this->pluginCheck('TrackBack');
3395999 if ($TrackBack) {
33961000 if (substr($path, -5, 5) == '.html') {
3397- $linkObj = array ('linkparam' => 'item',
3398- 'bid' => $blog_id,
3399- 'name' => $path);
1001+ $linkObj = array (
1002+ 'linkparam' => 'item',
1003+ 'bid' => $blog_id,
1004+ 'name' => $path
1005+ );
34001006 $item_id = $this->getRequestPathInfo($linkObj);
34011007 if ($item_id) {
34021008 $tb_id = intval($item_id);
@@ -3454,13 +1060,15 @@ class NP_CustomURL extends NucleusPlugin
34541060 return;
34551061 }
34561062 $item_id = intval($params['itemid']);
3457- $bid = intval(getBlogIDFromItemID($item_id));
1063+ $bid = intval(getBlogIDFromItemID($item_id));
34581064 if ($useCustomURL[$bid] == 'no') {
34591065 return;
34601066 }
3461- $query = 'SELECT obj_name as result FROM %s'
3462- . ' WHERE obj_param = "item" AND obj_id = %d';
3463- $path = quickQuery(sprintf($query, _CUSTOMURL_TABLE, $item_id));
1067+ $query = 'SELECT obj_name as result '
1068+ . 'FROM %s '
1069+ . 'WHERE obj_param = "item" '
1070+ . 'AND obj_id = %d';
1071+ $path = quickQuery(sprintf($query, _CUSTOMURL_TABLE, $item_id));
34641072 if ($path) {
34651073 $objPath = $path;
34661074 } else {
@@ -3468,22 +1076,27 @@ class NP_CustomURL extends NucleusPlugin
34681076 $objPath = _NOT_VALID_ITEM;
34691077 } else {
34701078 $y = $m = $d = $temp = '';
3471- $table = sql_table('item');
3472- $tque = 'SELECT itime as result FROM %s'
3473- . ' WHERE inumber = %d';
3474- $itime = quickQuery(sprintf($tque ,$table, $item_id));
1079+ $table = sql_table('item');
1080+ $tque = 'SELECT itime as result '
1081+ . 'FROM %s '
1082+ . 'WHERE inumber = %d';
1083+ $itime = quickQuery(sprintf($tque ,$table, $item_id));
34751084 sscanf($itime,'%d-%d-%d %s', $y, $m, $d, $temp);
34761085 $defItem = $this->getOption('customurl_dfitem');
3477- $tempParam = array('year' => $Y,
1086+ $tempParam = array(
1087+ 'year' => $Y,
34781088 'month' => $m,
3479- 'day' => $d);
3480- $ikey = TEMPLATE::fill($defItem, $tempParam);
3481- $ipath = $ikey . '_' . $item_id;
3482- $query = 'SELECT ititle as result FROM %s'
3483- . ' WHERE inumber = %d';
3484- $iname = quickQuery(sprintf($query, $table, $item_id));
1089+ 'day' => $d
1090+ );
1091+ $ikey = TEMPLATE::fill($defItem, $tempParam);
1092+ $ipath = $ikey . '_' . $item_id;
1093+ $query = 'SELECT ititle as result '
1094+ . 'FROM %s '
1095+ . 'WHERE inumber = %d';
1096+ $query = sprintf($query, $table, $item_id);
1097+ $iname = quickQuery($query);
34851098 $this->RegistPath($item_id, $ipath, $bid, 'item', $iname, TRUE);
3486- $objPath = $ipath . '.html';
1099+ $objPath = $ipath . '.html';
34871100 }
34881101 }
34891102 // if ($catParam && $subcatid && !$subcatParam) {
@@ -3557,12 +1170,12 @@ class NP_CustomURL extends NucleusPlugin
35571170 if ($d) {
35581171 $arc = sprintf('%04d-%02d-%02d', $y, $m, $d);
35591172 } elseif ($m) {
3560- $arc = sprintf('%04d-%02d', $y, $m);
1173+ $arc = sprintf('%04d-%02d', $y, $m);
35611174 } else {
3562- $arc = sprintf('%04d', $y);
1175+ $arc = sprintf('%04d', $y);
35631176 }
35641177 $objPath = $OP_ArchiveKey . '/' . $arc . '/';
3565- $bid = $blogid;
1178+ $bid = $blogid;
35661179 // if ($catParam && $subcatid && !$subcatParam) {
35671180 // $params['extra'][$subrequest] = $subcatid;
35681181 // }
@@ -3571,7 +1184,7 @@ class NP_CustomURL extends NucleusPlugin
35711184 if (!is_numeric($params['blogid'])) {
35721185 return;
35731186 }
3574- $bid = intval($params['blogid']);
1187+ $bid = intval($params['blogid']);
35751188 $burl = $this->_generateBlogLink($bid);
35761189 break;
35771190 default:
@@ -3603,7 +1216,7 @@ class NP_CustomURL extends NucleusPlugin
36031216 }
36041217 $v_path = explode('/', $info);
36051218
3606- $feedurl = array();
1219+ $feedurl = array();
36071220 $SiteMapP = $this->pluginCheck('GoogleSitemap');
36081221 if ($SiteMapP) {
36091222 $PcSitemaps = $SiteMapP->getAllBlogOptions('PcSitemap');
@@ -3633,12 +1246,12 @@ class NP_CustomURL extends NucleusPlugin
36331246 } else {
36341247 $data['url'] = $burl;
36351248 }
3636- $arcTmp = (preg_match('/' . $OP_ArchivesKey . '/', $data['url']));
3637- $arcsTmp = (preg_match('/' . $OP_ArchiveKey . '/', $data['url']));
3638- $isArchives = ($arcTmp || $arcsTmp);
3639- $isItem = (substr($data['url'], -5, 5) == '.html');
1249+ $arcTmp = (preg_match('/' . $OP_ArchivesKey . '/', $data['url']));
1250+ $arcsTmp = (preg_match('/' . $OP_ArchiveKey . '/', $data['url']));
1251+ $isArchives = ($arcTmp || $arcsTmp);
1252+ $isItem = (substr($data['url'], -5, 5) == '.html');
36401253 $isDirectory = (substr($data['url'], -1) == '/');
3641- $puri = parse_url($data['url']);
1254+ $puri = parse_url($data['url']);
36421255 if ($isArchives && !$isItem && !$isDirectory && !$puri['query']) {
36431256 $data['url'] .= '/';
36441257 }
@@ -3652,41 +1265,54 @@ class NP_CustomURL extends NucleusPlugin
36521265
36531266 function _createSubCategoryLink($scid)
36541267 {
3655- $scids = $this->getParents(intval($scid));
1268+ $scids = $this->getParents(intval($scid));
36561269 $subcatids = explode('/', $scids);
3657- $eachPath = array();
1270+ $eachPath = array();
36581271 foreach ($subcatids as $sid) {
36591272 $subcat_id = intval($sid);
3660- $query = 'SELECT obj_name as result FROM %s'
3661- . ' WHERE obj_id = %d AND obj_param = "%s"';
3662- $path = quickQuery(sprintf($query, _CUSTOMURL_TABLE, $subcat_id, 'subcategory'));
1273+ $query = 'SELECT obj_name as result'
1274+ . ' FROM %s'
1275+ . ' WHERE obj_id = %d'
1276+ . ' AND obj_param = "%s"';
1277+ $query = sprintf($query, _CUSTOMURL_TABLE, $subcat_id, 'subcategory');
1278+ $path = quickQuery($query);
36631279 if ($path) {
36641280 $eachPath[] = $path;
36651281 } else {
3666- $tempParam = array('plug_multiple_categories_sub',
1282+ $tempParam = array(
1283+ 'plug_multiple_categories_sub',
36671284 'scatid',
3668- $subcat_id);
1285+ $subcat_id
1286+ );
36691287 if (!$this->_isValid($tempParam)) {
36701288 return $url = _NOT_VALID_SUBCAT;
36711289 } else {
36721290 $scpath = $this->getOption('customurl_dfscat') . '_' . $subcat_id;
3673- $query = 'SELECT catid as result FROM %s WHERE scatid = %d';
3674- $cid= quickQuery(sprintf($query, _C_SUBCAT_TABLE, $subcat_id));
3675- if (!$cid) return 'no_such_subcat=' . $subcat_id . '/';
1291+ $query = 'SELECT catid as result FROM %s WHERE scatid = %d';
1292+ $query = sprintf($query, _C_SUBCAT_TABLE, $subcat_id);
1293+ $cid = quickQuery($query);
1294+ if (!$cid) {
1295+ return 'no_such_subcat=' . $subcat_id . '/';
1296+ }
36761297 $this->RegistPath($subcat_id, $scpath, $cid, 'subcategory', 'subcat_' . $subcat_id, TRUE);
36771298 $eachPath[] = $scpath;
36781299 }
36791300 }
36801301 }
3681- $subcatPath = @join('/', $eachPath);
1302+ $subcatPath = @implode('/', $eachPath);
36821303 return $subcatPath . '/';
36831304 }
36841305
36851306 function getParents($subid)
36861307 {
3687- $subcat_id = intval($subid);
3688- $query = 'SELECT scatid, parentid FROM %s WHERE scatid = %d';
3689- $res = sql_query(sprintf($query, _C_SUBCAT_TABLE, $subcat_id));
1308+ $subcat_id = intval($subid);
1309+ $query = 'SELECT '
1310+ . 'scatid, '
1311+ . 'parentid '
1312+ . 'FROM %s '
1313+ . 'WHERE scatid = %d';
1314+ $query = sprintf($query, _C_SUBCAT_TABLE, $subcat_id);
1315+ $res = sql_query($query);
36901316 list($sid, $parent) = mysql_fetch_row($res);
36911317 if ($parent != 0) {
36921318 $r = $this->getParents($parent) . '/' . $sid;
@@ -3700,11 +1326,16 @@ class NP_CustomURL extends NucleusPlugin
37001326 {
37011327 global $CONF;
37021328 $cat_id = intval($cid);
3703- $path = $this->getCategoryOption($cat_id, 'customurl_cname');
1329+ $path = $this->getCategoryOption($cat_id, 'customurl_cname');
37041330 if ($path) {
37051331 return $path . '/';
37061332 } else {
3707- if (!$this->_isValid(array('category', 'catid', $cat_id))) {
1333+ $catData = array(
1334+ 'category',
1335+ 'catid',
1336+ $cat_id
1337+ );
1338+ if (!$this->_isValid($catData)) {
37081339 return $url = _NOT_VALID_CAT;
37091340 } else {
37101341 $cpath = $this->getOption('customurl_dfcat') . '_' . $cat_id;
@@ -3721,28 +1352,37 @@ class NP_CustomURL extends NucleusPlugin
37211352 global $manager, $CONF;
37221353 $blog_id = intval($bid);
37231354 if ($this->getBlogOption($blog_id, 'use_customurl') == 'no') {
3724- $b =& $manager->getBlog($blog_id);
3725- $burl = $b->getURL();
1355+ $b =& $manager->getBlog($blog_id);
1356+ $burl = $b->getURL();
37261357 } else {
37271358 if ($blog_id == $CONF['DefaultBlog']) {
37281359 $burl = trim($CONF['IndexURL'], '/');
37291360 } else {
3730- $query = 'SELECT burl as result FROM %s WHERE bnumber = %d';
3731- $burl = quickQuery(sprintf($query, sql_table('blog'), $blog_id));
1361+ $query = 'SELECT burl as result '
1362+ . 'FROM %s '
1363+ . 'WHERE bnumber = %d';
1364+ $query = sprintf($query, sql_table('blog'), $blog_id);
1365+ $burl = quickQuery($query);
37321366 if ($burl) {
37331367 if (substr($burl, -4, 4) == '.php') {
37341368 $path = $this->getBlogOption($blog_id, 'customurl_bname');
37351369 if ($path) {
37361370 $burl = $CONF['IndexURL'] . $path;
37371371 } else {
3738- $query = 'SELECT bshortname as result FROM %s'
1372+ $query = 'SELECT bshortname as result'
1373+ . ' FROM %s'
37391374 . ' WHERE bnumber = %d';
3740- $bpath = quickQuery(sprintf($query, sql_table('blog'), $blog_id));
1375+ $query = sprintf($query, sql_table('blog'), $blog_id);
1376+ $bpath = quickQuery($query);
37411377 $this->RegistPath($blog_id, $bpath, 0, 'blog', $bpath, TRUE);
3742- $burl = $CONF['IndexURL'] . $bpath;
1378+ $burl = $CONF['IndexURL'] . $bpath;
37431379 }
3744- $burl_update = 'UPDATE %s SET burl = "%s" WHERE bnumber = %d';
3745- sql_query(sprintf($burl_update, sql_table('blog'), $this->quote_smart($burl), $blog_id));
1380+ $burl_update = 'UPDATE %s '
1381+ . 'SET burl = "%s" '
1382+ . 'WHERE bnumber = %d';
1383+ $burl = $this->quote_smart($burl);
1384+ $bTable = sql_table('blog');
1385+ sql_query(sprintf($burl_update, $bTable, $burl, $blog_id));
37461386 }
37471387 } else {
37481388 $burl = _NOT_VALID_BLOG;
@@ -3760,9 +1400,9 @@ class NP_CustomURL extends NucleusPlugin
37601400 $isArchives = ($arcTmp || $arcsTmp);
37611401 $mcategories = $this->pluginCheck('MultipleCategories');
37621402 if ($mcategories) {
3763- if (method_exists($mcategories,"getRequestName")) {
3764- $mcategories->event_PreSkinParse(array());
3765- global $subcatid;
1403+ $mcategories->event_PreSkinParse(array());
1404+ global $subcatid;
1405+ if (method_exists($mcategories, 'getRequestName')) {
37661406 $subrequest = $mcategories->getRequestName();
37671407 } else {
37681408 $subrequest = 'subcatid';
@@ -3780,23 +1420,28 @@ class NP_CustomURL extends NucleusPlugin
37801420 if ($d) {
37811421 $arc = sprintf('%04d-%02d-%02d', $y, $m, $d);
37821422 } elseif ($m) {
3783- $arc = sprintf('%04d-%02d', $y, $m);
1423+ $arc = sprintf('%04d-%02d', $y, $m);
37841424 } else {
3785- $arc = sprintf('%04d', $y);
1425+ $arc = sprintf('%04d', $y);
37861426 }
37871427 $linkExtra = $this->getOption('customurl_archive') . '/' . $arc;
37881428 unset($params['archive']);
37891429 }
1430+ if ($params['blogid']) {
1431+ unset($params['blogid']);
1432+ }
37901433 $paramlink = array();
37911434 foreach ($params as $param => $value) {
37921435 switch ($param) {
37931436 case 'catid':
37941437 case $CONF['CategoryKey']:
3795- $paramlink[] = $this->_generateCategoryLink(intval($value));
1438+ $cid = intval($value);
1439+ $paramlink[] = $this->_generateCategoryLink($cid);
37961440 break;
37971441 case $subrequest:
37981442 if ($mcategories) {
3799- $paramlink[] = $this->_createSubCategoryLink(intval($value));
1443+ $sid = intval($value);
1444+ $paramlink[] = $this->_createSubCategoryLink($sid);
38001445 }
38011446 break;
38021447 default:
@@ -3820,13 +1465,16 @@ class NP_CustomURL extends NucleusPlugin
38201465 $link .= $linkExtra;
38211466 }
38221467 if (requestVar('skinid')) {
3823- if (strpos('?', $link)) {
3824- $link .= '&amp;skinid=' . htmlspecialchars(requestVar('skinid'));
1468+ $skinid = htmlspecialchars(requestVar('skinid'), ENT_QUOTES, _CHARSET);
1469+ if (!$link) {
1470+ $link = '?skinid=' . $skinid;
1471+ } elseif (strpos('?', $link)) {
1472+ $link .= '&amp;skinid=' . $skinid;
38251473 } else {
38261474 if (substr($link, -1) != '/' && !empty($link)) {
3827- $link .= '/?skinid=' . htmlspecialchars(requestVar('skinid'));
1475+ $link .= '/?skinid=' . $skinid;
38281476 } else {
3829- $link .= '?skinid=' . htmlspecialchars(requestVar('skinid'));
1477+ $link .= '?skinid=' . $skinid;
38301478 }
38311479 }
38321480 }
@@ -3839,117 +1487,34 @@ class NP_CustomURL extends NucleusPlugin
38391487 function _convertAlphabettoXHTMLCharacterEntity($text) //add shizuki
38401488 {
38411489 $alphabetKey = array (
3842- '/',
3843- '@',
3844- 'A',
3845- 'B',
3846- 'C',
3847- 'D',
3848- 'E',
3849- 'F',
3850- 'G',
3851- 'H',
3852- 'I',
3853- 'J',
3854- 'K',
3855- 'L',
3856- 'M',
3857- 'N',
3858- 'O',
3859- 'P',
3860- 'Q',
3861- 'R',
3862- 'S',
3863- 'T',
3864- 'U',
3865- 'V',
3866- 'W',
3867- 'X',
3868- 'Y',
1490+ '/', '@',
1491+ 'A', 'B', 'C', 'D', 'E',
1492+ 'F', 'G', 'H', 'I', 'J',
1493+ 'K', 'L', 'M', 'N', 'O',
1494+ 'P', 'Q', 'R', 'S', 'T',
1495+ 'U', 'V', 'W', 'X', 'Y',
38691496 'Z',
3870- 'a',
3871- 'b',
3872- 'c',
3873- 'd',
3874- 'e',
3875- 'f',
3876- 'g',
3877- 'h',
3878- 'i',
3879- 'j',
3880- 'k',
3881- 'l',
3882- 'm',
3883- 'n',
3884- 'o',
3885- 'p',
3886- 'q',
3887- 'r',
3888- 's',
3889- 't',
3890- 'u',
3891- 'v',
3892- 'w',
3893- 'x',
3894- 'y',
1497+ 'a', 'b', 'c', 'd', 'e',
1498+ 'f', 'g', 'h', 'i', 'j',
1499+ 'k', 'l', 'm', 'n', 'o',
1500+ 'p', 'q', 'r', 's', 't',
1501+ 'u', 'v', 'w', 'x', 'y',
38951502 'z',
38961503 '&&'
38971504 );
38981505 $alphabetVal = array (
3899- '&#47;',
3900- '&#64;',
3901- '&#65;',
3902- '&#66;',
3903- '&#67;',
3904- '&#68;',
3905- '&#69;',
3906- '&#70;',
3907- '&#71;',
3908- '&#72;',
3909- '&#73;',
3910- '&#74;',
3911- '&#75;',
3912- '&#76;',
3913- '&#77;',
3914- '&#78;',
3915- '&#79;',
3916- '&#80;',
3917- '&#81;',
3918- '&#82;',
3919- '&#83;',
3920- '&#84;',
3921- '&#85;',
3922- '&#86;',
3923- '&#87;',
3924- '&#88;',
3925- '&#89;',
3926- '&#90;',
3927- '&#97;',
3928- '&#98;',
1506+ '&#47;', '&#64;', '&#65;', '&#66;', '&#67;',
1507+ '&#68;', '&#69;', '&#70;', '&#71;', '&#72;',
1508+ '&#73;', '&#74;', '&#75;', '&#76;', '&#77;',
1509+ '&#78;', '&#79;', '&#80;', '&#81;', '&#82;',
1510+ '&#83;', '&#84;', '&#85;', '&#86;', '&#87;',
1511+ '&#88;', '&#89;', '&#90;', '&#97;', '&#98;',
39291512 '&#99;',
3930- '&#100;',
3931- '&#101;',
3932- '&#102;',
3933- '&#103;',
3934- '&#104;',
3935- '&#105;',
3936- '&#106;',
3937- '&#107;',
3938- '&#108;',
3939- '&#109;',
3940- '&#110;',
3941- '&#111;',
3942- '&#112;',
3943- '&#113;',
3944- '&#114;',
3945- '&#115;',
3946- '&#116;',
3947- '&#117;',
3948- '&#118;',
3949- '&#119;',
3950- '&#120;',
3951- '&#121;',
3952- '&#122;',
1513+ '&#100;', '&#101;', '&#102;', '&#103;', '&#104;',
1514+ '&#105;', '&#106;', '&#107;', '&#108;', '&#109;',
1515+ '&#110;', '&#111;', '&#112;', '&#113;', '&#114;',
1516+ '&#115;', '&#116;', '&#117;', '&#118;', '&#119;',
1517+ '&#120;', '&#121;', '&#122;',
39531518 '&#65286;&'
39541519 );
39551520 $retData = str_replace($alphabetKey, $alphabetVal, $text);
@@ -3962,13 +1527,18 @@ class NP_CustomURL extends NucleusPlugin
39621527 if ($skinType == 'item' && $link_type == 'trackback') {
39631528 global $itemid, $CONF;
39641529 if ($this->getBlogOption($blogid, 'use_customurl') == 'yes') {
3965- $que = 'SELECT obj_name as result FROM %s'
3966- . ' WHERE obj_param = "item" AND obj_id = %d';
1530+ $que = 'SELECT obj_name as result '
1531+ . 'FROM %s '
1532+ . 'WHERE obj_param = "item" '
1533+ . 'AND obj_id = %d';
39671534 $itempath = quickQuery(sprintf($que, _CUSTOMURL_TABLE, $itemid));
3968- $uri = $CONF['BlogURL'] . '/trackback/' . $itempath;
1535+ if ($target != 'ext') {
1536+ $uri = $CONF['BlogURL'] . '/trackback/' . $itempath;
1537+ } elseif ($target == 'ext') {
39691538 // /item_123.trackback
3970-// $itempath = substr($itempath, 0, -5) . '.trackback';
3971-// $uri = $CONF['BlogURL'] . '/' . $itempath;
1539+ $itempath = substr($itempath, 0, -5) . '.trackback';
1540+ $uri = $CONF['BlogURL'] . '/' . $itempath;
1541+ }
39721542 } else {
39731543 $uri = $CONF['ActionURL']
39741544 . '?action=plugin&amp;name=TrackBack&amp;tb_id=' . $itemid;
@@ -4008,13 +1578,18 @@ class NP_CustomURL extends NucleusPlugin
40081578 global $CONF;
40091579 $blog_id = intval(getBlogIDFromItemID($item_id));
40101580 if ($this->getBlogOption($blog_id, 'use_customurl') == 'yes') {
4011- $que = 'SELECT obj_name as result FROM %s'
4012- . ' WHERE obj_param = "item" AND obj_id = %d';
1581+ $que = 'SELECT obj_name as result '
1582+ . 'FROM %s '
1583+ . 'WHERE obj_param = "item" '
1584+ . 'AND obj_id = %d';
40131585 $itempath = quickQuery(sprintf($que, _CUSTOMURL_TABLE, $item_id));
4014- $uri = $CONF['BlogURL'] . '/trackback/' . $itempath;
1586+ if ($target != 'ext') {
1587+ $uri = $CONF['BlogURL'] . '/trackback/' . $itempath;
1588+ } elseif ($target == 'ext') {
40151589 // /item_123.trackback
4016-// $itempath = substr($itempath, 0, -5) . '.trackback';
4017-// $uri = $CONF['BlogURL'] . '/' . $itempath;
1590+ $itempath = substr($itempath, 0, -5) . '.trackback';
1591+ $uri = $CONF['BlogURL'] . '/' . $itempath;
1592+ }
40181593 } else {
40191594 $uri = $CONF['ActionURL']
40201595 . '?action=plugin&amp;name=TrackBack&amp;tb_id=' . $item_id;
@@ -4037,35 +1612,45 @@ class NP_CustomURL extends NucleusPlugin
40371612
40381613 function URL_Callback($data)
40391614 {
4040- $l_data = explode(",", $data[1]);
4041- $l_type = $l_data[0];
4042- $target = $l_data[1];
4043- $title = $l_data[2];
4044- $item_id = intval($this->currentItem->itemid);
1615+ $l_data = explode(",", $data[1]);
1616+ $l_type = $l_data[0];
1617+ $target = $l_data[1];
1618+ $title = $l_data[2];
1619+ $item_id = intval($this->currentItem->itemid);
40451620 if (!$l_type) {
4046- $link_params = array ('i',
1621+ $link_params = array (
1622+ 'i',
40471623 $item_id,
4048- 'i');
1624+ 'i'
1625+ );
40491626 } else {
40501627 $link_data = explode("/", $l_type);
40511628 if (count($link_data) == 1) {
4052- $link_params = array ('i',
1629+ $link_params = array (
1630+ 'i',
40531631 intval($l_type),
4054- 'i');
1632+ 'i'
1633+ );
40551634 } elseif (count($link_data) == 2) {
40561635 if ($link_data[1] == 'path') {
4057- $link_params = array ('i',
1636+ $link_params = array (
1637+ 'i',
40581638 $link_data[0],
4059- 'path');
1639+ 'path'
1640+ );
40601641 } else {
4061- $link_params = array ($link_data[0],
1642+ $link_params = array (
1643+ $link_data[0],
40621644 intval($link_data[1]),
4063- 'i');
1645+ 'i'
1646+ );
40641647 }
40651648 } else {
4066- $link_params = array ($link_data[0],
1649+ $link_params = array (
1650+ $link_data[0],
40671651 $link_data[1],
4068- $link_data[2]);
1652+ $link_data[2]
1653+ );
40691654 }
40701655 }
40711656 $url = $this->_genarateObjectLink($link_params);
@@ -4087,9 +1672,10 @@ class NP_CustomURL extends NucleusPlugin
40871672
40881673 function _isValid($data)
40891674 {
4090- $query = 'SELECT * FROM %s WHERE %s = %d';
1675+ $query = 'SELECT * FROM %s WHERE %s = %d';
40911676 $data[2] = $this->quote_smart($data[2]);
4092- $res = sql_query(sprintf($query, sql_table($data[0]), $data[1], $data[2]));
1677+ $query = sprintf($query, sql_table($data[0]), $data[1], $data[2]);
1678+ $res = sql_query($query);
40931679 return (mysql_num_rows($res) != 0);
40941680 }
40951681
@@ -4098,7 +1684,7 @@ class NP_CustomURL extends NucleusPlugin
40981684 global $CONF, $manager, $blog;
40991685 $ext = substr(serverVar('REQUEST_URI'), -4);
41001686 if ($ext == '.rdf' || $ext == '.xml') {
4101- $CONF['URLMode'] = 'pathinfo';
1687+ $CONF['URLMode'] = 'pathinfo';
41021688 }
41031689 if ($CONF['URLMode'] != 'pathinfo') {
41041690 return;
@@ -4112,9 +1698,11 @@ class NP_CustomURL extends NucleusPlugin
41121698 $bid = $data[1];
41131699 }
41141700 $blog_id = intval($bid);
4115- $param = array('blog',
4116- 'bnumber',
4117- $blog_id);
1701+ $param = array(
1702+ 'blog',
1703+ 'bnumber',
1704+ $blog_id
1705+ );
41181706 if (!$this->_isValid($param)) {
41191707 $url = _NOT_VALID_BLOG;
41201708 } else {
@@ -4128,9 +1716,11 @@ class NP_CustomURL extends NucleusPlugin
41281716 $cid = $data[1];
41291717 }
41301718 $cat_id = intval($cid);
4131- $param = array('category',
1719+ $param = array(
1720+ 'category',
41321721 'catid',
4133- $cat_id);
1722+ $cat_id
1723+ );
41341724 if (!$this->_isValid($param)) {
41351725 $url = _NOT_VALID_CAT;
41361726 } else {
@@ -4146,40 +1736,51 @@ class NP_CustomURL extends NucleusPlugin
41461736 if (method_exists($mcategories, "getRequestName")) {
41471737 if ($data[2] == 'n') {
41481738 $temp = $this->quote_smart($data[1]);
4149- $scid = quickQuery(sprintf($query, 'scatid', _C_SUBCAT_TABLE, 'sname', $temp));
1739+ $sque = sprintf($query, 'scatid', _C_SUBCAT_TABLE, 'sname', $temp);
1740+ $scid = quickQuery($sque);
41501741 } else {
41511742 $scid = $data[1];
41521743 }
41531744 $sub_id = intval($scid);
4154- $param = array('plug_multiple_categories_sub',
4155- 'scatid',
4156- $sub_id);
1745+ $param = array(
1746+ 'plug_multiple_categories_sub',
1747+ 'scatid',
1748+ $sub_id
1749+ );
41571750 if (!$this->_isValid($param)) {
41581751 $url = _NOT_VALID_SUBCAT;
41591752 } else {
4160- $cid = quickQuery(sprintf($query, 'catid', _C_SUBCAT_TABLE, 'scatid', $sub_id));
4161- $cid = intval($cid);
1753+ $cqe = sprintf($query, 'catid', _C_SUBCAT_TABLE, 'scatid', $sub_id);
1754+ $cid = quickQuery($cqe);
1755+ $cid = intval($cid);
41621756 $subrequest = $mcategories->getRequestName();
41631757 if (!$subrequest) {
41641758 $subrequest = 'subcatid';
41651759 }
4166- $linkParam = array($subrequest => $sub_id);
4167- $url = createCategoryLink($cid, $linkParam);
1760+ $linkParam = array(
1761+ $subrequest => $sub_id
1762+ );
1763+ $url = createCategoryLink($cid, $linkParam);
41681764 }
41691765 }
41701766 }
41711767 break;
41721768 case 'i':
4173- $param = array('item',
1769+ $param = array(
1770+ 'item',
41741771 'inumber',
4175- intval($data[1]));
1772+ intval($data[1])
1773+ );
41761774 if (!$this->_isValid($param)) {
41771775 $url = _NOT_VALID_ITEM;
41781776 } else {
41791777 $blink = $this->_generateBlogLink(getBlogIDFromItemID(intval($data[1])));
4180- $i_query = 'SELECT obj_name as result FROM %s'
4181- . ' WHERE obj_param = "item" AND obj_id = %d';
4182- $path = quickQuery(sprintf($i_query, _CUSTOMURL_TABLE, intval($data[1])));
1778+ $i_query = 'SELECT obj_name as result '
1779+ . 'FROM %s '
1780+ . 'WHERE obj_param = "item" '
1781+ . 'AND obj_id = %d';
1782+ $i_query = sprintf($i_query, _CUSTOMURL_TABLE, intval($data[1]));
1783+ $path = quickQuery($i_query);
41831784 if ($path) {
41841785 if ($data[2] == 'path') {
41851786 $url = $path;
@@ -4200,14 +1801,17 @@ class NP_CustomURL extends NucleusPlugin
42001801 case 'm':
42011802 if ($data[2] == 'n') {
42021803 $data[1] = $this->quote_smart($data[1]);
4203- $mid = quickQuery(sprintf($query, 'mnumber', sql_table('member'), 'mname', $data[1]));
1804+ $mque = sprintf($query, 'mnumber', sql_table('member'), 'mname', $data[1]);
1805+ $mid = quickQuery($mque);
42041806 } else {
42051807 $mid = $data[1];
42061808 }
42071809 $member_id = intval($mid);
4208- $param = array('member',
1810+ $param = array(
1811+ 'member',
42091812 'mnumber',
4210- $member_id);
1813+ $member_id
1814+ );
42111815 if (!$this->_isValid($param)) {
42121816 $url = _NOT_VALID_MEMBER;
42131817 } else {
@@ -4218,35 +1822,14 @@ class NP_CustomURL extends NucleusPlugin
42181822 return $url;
42191823 }
42201824
4221-/* function event_PreSendContentType($data)
4222- {
4223- global $blogid, $CONF;
4224-
4225- $ext = substr(serverVar('REQUEST_URI'), -4);
4226- if ($ext == '.rdf' || $ext == '.xml') {
4227- $p_info = trim(serverVar('PATH_INFO'), '/');
4228- $path_arr = explode('/', $p_info);
4229- switch (end($path_arr)) {
4230- case 'rss1.xml':
4231- case 'index.rdf':
4232- case 'rss2.xml':
4233- case 'atom.xml':
4234- $data['contentType'] = 'application/xml';
4235- break;
4236- default:
4237- break;
4238- }
4239- }
4240- }*/
4241-
42421825 function event_InitSkinParse($data)
42431826 {
4244- global $blogid, $CONF, $manager;
1827+ global $blogid, $CONF, $manager, $nucleus;
42451828 $feedurl = array(
4246- 'rss1.xml',
4247- 'index.rdf',
4248- 'rss2.xml',
4249- 'atom.xml',
1829+ 'rss1.xml',
1830+ 'index.rdf',
1831+ 'rss2.xml',
1832+ 'atom.xml',
42501833 );
42511834 $reqPaths = explode('/', serverVar('PATH_INFO'));
42521835 $reqPath = end($reqPaths);
@@ -4279,9 +1862,11 @@ class NP_CustomURL extends NucleusPlugin
42791862 $skinID = $skinData->id;
42801863 $contents = $this->getSkinContent($pageType, $skinID);
42811864 $actions = SKIN::getAllowedActionsForType($pageType);
4282- $dataArray = array('skin' => &$skinData,
1865+ $dataArray = array(
1866+ 'skin' => &$skinData,
42831867 'type' => $pageType,
4284- 'contents' => &$contents);
1868+ 'contents' => &$contents
1869+ );
42851870 $manager->notify('PreSkinParse', $dataArray);
42861871 PARSER::setProperty('IncludeMode', SKIN::getIncludeMode());
42871872 PARSER::setProperty('IncludePrefix', SKIN::getIncludePrefix());
@@ -4290,8 +1875,10 @@ class NP_CustomURL extends NucleusPlugin
42901875 $handler->setParser($parser);
42911876 $handler->setSkin($skinData);
42921877 $parser->parse($contents);
4293- $dataArray = array('skin' => &$skinData,
4294- 'type' => $pageType);
1878+ $dataArray = array(
1879+ 'skin' => &$skinData,
1880+ 'type' => $pageType
1881+ );
42951882 $manager->notify('PostSkinParse', $dataArray);
42961883
42971884 $feed = ob_get_contents();
@@ -4300,11 +1887,11 @@ class NP_CustomURL extends NucleusPlugin
43001887 $eTag = '"' . md5($feed) . '"';
43011888 header('Etag: ' . $eTag);
43021889 if ($eTag == serverVar('HTTP_IF_NONE_MATCH')) {
4303- header("HTTP/1.0 304 Not Modified");
1890+ header('HTTP/1.0 304 Not Modified');
43041891 header('Content-Length: 0');
43051892 } else {
43061893 $feed = mb_convert_encoding($feed, 'UTF-8', _CHARSET);
4307- header("Content-Type: application/xml");
1894+ header('Content-Type: application/xml');
43081895 header('Generator: Nucleus CMS ' . $nucleus['version']);
43091896 // dump feed
43101897 echo $feed;
@@ -4314,8 +1901,8 @@ class NP_CustomURL extends NucleusPlugin
43141901 ?>
43151902 <rss version="2.0">
43161903 <channel>
4317- <title><?php echo htmlspecialchars($CONF['SiteName'])?></title>
4318- <link><?php echo htmlspecialchars($CONF['IndexURL'])?></link>
1904+ <title><?php echo htmlspecialchars($CONF['SiteName'], ENT_QUOTES)?></title>
1905+ <link><?php echo htmlspecialchars($CONF['IndexURL'], ENT_QUOTES)?></link>
43191906 <description></description>
43201907 <docs>http://backend.userland.com/rss</docs>
43211908 </channel>
@@ -4331,13 +1918,18 @@ class NP_CustomURL extends NucleusPlugin
43311918 {
43321919 $skinID = intval($skinID);
43331920 $pageType = addslashes($pageType);
4334- $query = 'SELECT scontent FROM %s WHERE sdesc = %d AND stype = %d';
4335- $res = sql_query(sprintf($query, sql_table('skin'), $skinID, $pageType));
4336-
4337- if (mysql_num_rows($res) == 0)
1921+ $query = 'SELECT scontent '
1922+ . 'FROM %s '
1923+ . 'WHERE sdesc = %d '
1924+ . 'AND stype = %d';
1925+ $query = sprintf($query, sql_table('skin'), $skinID, $pageType);
1926+ $res = sql_query($query);
1927+
1928+ if (mysql_num_rows($res) == 0) {
43381929 return '';
4339- else
1930+ } else {
43401931 return mysql_result($res, 0, 0);
1932+ }
43411933 }
43421934
43431935
@@ -4355,8 +1947,8 @@ class NP_CustomURL extends NucleusPlugin
43551947
43561948 if (!$blogurl) {
43571949 if($blog) {
4358- $b_tmp =& $manager->getBlog($CONF['DefaultBlog']);
4359- $blogurl = $b_tmp->getURL();
1950+ $b_tmp =& $manager->getBlog($CONF['DefaultBlog']);
1951+ $blogurl = $b_tmp->getURL();
43601952 }
43611953 if (!$blogurl) {
43621954 $blogurl = $CONF['IndexURL'];
@@ -4364,7 +1956,7 @@ class NP_CustomURL extends NucleusPlugin
43641956 if ($data['type'] == 'pageparser') {
43651957 $blogurl .= 'index.php';
43661958 } else {
4367- $blogurl = $CONF['Self'];
1959+ $blogurl = $CONF['Self'];
43681960 }
43691961 }
43701962 }
@@ -4394,9 +1986,9 @@ class NP_CustomURL extends NucleusPlugin
43941986 $data['item']->more = preg_replace_callback($pattern, array(&$this, 'URL_Callback'), $data['item']->more);
43951987 }
43961988
4397- $itemid = intval($data['item']->itemid);
1989+ $itemid = intval($data['item']->itemid);
43981990 $itemblog =& $manager->getBlog(getBlogIDFromItemID($itemid));
4399- $blogurl = $itemblog->getURL();
1991+ $blogurl = $itemblog->getURL();
44001992 if (!$blogurl) {
44011993 $b =& $manager->getBlog($CONF['DefaultBlog']);
44021994 if (!($blogurl = $b->getURL())) {
@@ -4405,7 +1997,7 @@ class NP_CustomURL extends NucleusPlugin
44051997 if ($data['type'] == 'pageparser') {
44061998 $blogurl .= 'index.php';
44071999 } else {
4408- $blogurl = $CONF['Self'];
2000+ $blogurl = $CONF['Self'];
44092001 }
44102002 }
44112003 }
@@ -4434,8 +2026,8 @@ class NP_CustomURL extends NucleusPlugin
44342026 $blogurl = $b->getURL();
44352027 if (!$blogurl) {
44362028 if($blog) {
4437- $b_tmp =& $manager->getBlog($CONF['DefaultBlog']);
4438- $blogurl = $b_tmp->getURL();
2029+ $b_tmp =& $manager->getBlog($CONF['DefaultBlog']);
2030+ $blogurl = $b_tmp->getURL();
44392031 }
44402032 if (!$blogurl) {
44412033 $blogurl = $CONF['IndexURL'];
@@ -4443,7 +2035,7 @@ class NP_CustomURL extends NucleusPlugin
44432035 if ($data['type'] == 'pageparser') {
44442036 $blogurl .= 'index.php';
44452037 } else {
4446- $blogurl = $CONF['Self'];
2038+ $blogurl = $CONF['Self'];
44472039 }
44482040 }
44492041 }
@@ -4464,14 +2056,14 @@ class NP_CustomURL extends NucleusPlugin
44642056
44652057 function event_PostDeleteBlog ($data)
44662058 {
4467- $query = 'DELETE FROM %s WHERE obj_id = %d AND obj_param = "%s"';
4468- $pquery = 'DELETE FROM %s WHERE obj_bid = %d AND obj_param= "%s"';
4469- $blogid = intval($data['blogid']);
2059+ $query = 'DELETE FROM %s WHERE obj_id = %d AND obj_param = "%s"';
2060+ $pquery = 'DELETE FROM %s WHERE obj_bid = %d AND obj_param= "%s"';
2061+ $blogid = intval($data['blogid']);
44702062 sql_query(sprintf($query, _CUSTOMURL_TABLE, $blogid, 'blog'));
44712063 sql_query(sprintf($pquery, _CUSTOMURL_TABLE, $blogid, 'item'));
44722064 $cnmquery = 'SELECT catid FROM %s WHERE cblog = %d';
4473- $table = sql_table('category');
4474- $cnm = sql_query(sprintf($cnmquery, $table, $blogid));
2065+ $table = sql_table('category');
2066+ $cnm = sql_query(sprintf($cnmquery, $table, $blogid));
44752067 while ($c = mysql_fetch_object($cnm)) {
44762068 $catid = intval($c->catid);
44772069 sql_query(sprintf($pquery, _CUSTOMURL_TABLE, $catid, 'subcategory'));
@@ -4490,14 +2082,14 @@ class NP_CustomURL extends NucleusPlugin
44902082
44912083 function event_PostDeleteItem ($data)
44922084 {
4493- $query = 'DELETE FROM %s WHERE obj_id = %d AND obj_param = "%s"';
2085+ $query = 'DELETE FROM %s WHERE obj_id = %d AND obj_param = "%s"';
44942086 $itemid = intval($data['itemid']);
44952087 sql_query(sprintf($query, _CUSTOMURL_TABLE, $itemid, 'item'));
44962088 }
44972089
44982090 function event_PostDeleteMember ($data)
44992091 {
4500- $query = 'DELETE FROM %s WHERE obj_id = %d AND obj_param = "%s"';
2092+ $query = 'DELETE FROM %s WHERE obj_id = %d AND obj_param = "%s"';
45012093 $memberid = intval($data['member']->id);
45022094 sql_query(sprintf($query, _CUSTOMURL_TABLE, $memberid, 'member'));
45032095 }
@@ -4516,13 +2108,13 @@ class NP_CustomURL extends NucleusPlugin
45162108 $cat_id = intval($data['catid']);
45172109 if (!$data['blog']->blogid) {
45182110 $query = 'SELECT cblog as result FROM %s WHERE catid = %d';
4519- $bid = quickQuery(sprintf($query, sql_table('category'), $cat_id));
2111+ $bid = quickQuery(sprintf($query, sql_table('category'), $cat_id));
45202112 } else {
45212113 $bid = $data['blog']->blogid;
45222114 }
45232115 if (!$data['name']) {
45242116 $query = 'SELECT cname as result FROM %s WHERE catid = %d';
4525- $name = quickQuery(sprintf($query, sql_table('category'), $cat_id));
2117+ $name = quickQuery(sprintf($query, sql_table('category'), $cat_id));
45262118 } else {
45272119 $name = $data['name'];
45282120 }
@@ -4537,18 +2129,19 @@ class NP_CustomURL extends NucleusPlugin
45372129 {
45382130 $item_id = intval($data['itemid']);
45392131 // $item_id = $data['itemid'];
4540- $tpath = requestVar('plug_custom_url_path');
4541- $tque = 'SELECT itime as result FROM %s WHERE inumber = %d';
4542- $itime = quickQuery(sprintf($tque, sql_table('item'), $item_id));
4543- echo 'itemid='.$item_id.'<br>idate='.$itime;
2132+ $tpath = requestVar('plug_custom_url_path');
2133+ $tque = 'SELECT itime as result FROM %s WHERE inumber = %d';
2134+ $itime = quickQuery(sprintf($tque, sql_table('item'), $item_id));
45442135 $y = $m = $d = $temp = '';
45452136 sscanf($itime, '%d-%d-%d %s', $y, $m, $d, $temp);
4546- $param = array ('year' => $y,
2137+ $param = array (
2138+ 'year' => $y,
45472139 'month' => $m,
4548- 'day' => $d);
4549- $ipath = TEMPLATE::fill($tpath, $param);
4550- $query = 'SELECT ititle as result FROM %s WHERE inumber = %d';
4551- $iname = quickQuery(sprintf($query, sql_table('item'), $item_id));
2140+ 'day' => $d
2141+ );
2142+ $ipath = TEMPLATE::fill($tpath, $param);
2143+ $query = 'SELECT ititle as result FROM %s WHERE inumber = %d';
2144+ $iname = quickQuery(sprintf($query, sql_table('item'), $item_id));
45522145 $blog_id = intval(getBlogIDFromItemID($item_id));
45532146 $this->RegistPath($item_id, $ipath, $blog_id, 'item', $iname, TRUE);
45542147 }
@@ -4573,20 +2166,22 @@ class NP_CustomURL extends NucleusPlugin
45732166
45742167 function event_PostUpdateItem($data)
45752168 {
4576- $tpath = requestVar('plug_custom_url_path');
2169+ $tpath = requestVar('plug_custom_url_path');
45772170 $item_id = intval($data['itemid']);
4578- $tque = 'SELECT itime as result FROM %s WHERE inumber = %d';
4579- $itime = quickQuery(sprintf($tque ,sql_table('item'), $item_id));
2171+ $tque = 'SELECT itime as result FROM %s WHERE inumber = %d';
2172+ $itime = quickQuery(sprintf($tque ,sql_table('item'), $item_id));
45802173 // $itimestamp = strtotime($itime);
45812174 // $tt = explode(',', date('Y,m,d', $itimestamp));
45822175 $y = $m = $d = $temp = '';
45832176 sscanf($itime, '%d-%d-%d %s', $y, $m, $d, $temp);
4584- $param = array ('year' => $y,
4585- 'month' => $m,
4586- 'day' => $d);
4587- $ipath = TEMPLATE::fill($tpath, $param);
4588- $query = 'SELECT ititle as result FROM %s WHERE inumber = %d';
4589- $iname = quickQuery(sprintf($query, sql_table('item'), $item_id));
2177+ $param = array (
2178+ 'year' => $y,
2179+ 'month' => $m,
2180+ 'day' => $d
2181+ );
2182+ $ipath = TEMPLATE::fill($tpath, $param);
2183+ $query = 'SELECT ititle as result FROM %s WHERE inumber = %d';
2184+ $iname = quickQuery(sprintf($query, sql_table('item'), $item_id));
45902185 $blog_id = intval(getBlogIDFromItemID($item_id));
45912186 $this->RegistPath($item_id, $ipath, $blog_id, 'item', $iname);
45922187 }
@@ -4595,13 +2190,15 @@ class NP_CustomURL extends NucleusPlugin
45952190 {
45962191 global $CONF;
45972192 if ($item_id) {
4598- $query = 'SELECT obj_name as result FROM %s'
4599- . ' WHERE obj_param = "item" AND obj_id = %d';
2193+ $query = 'SELECT obj_name as result'
2194+ . ' FROM %s'
2195+ . ' WHERE obj_param = "item"'
2196+ . ' AND obj_id = %d';
46002197 $item_id = intval($item_id);
4601- $res = quickQuery(sprintf($query, _CUSTOMURL_TABLE, $item_id));
4602- $ipath = substr($res, 0, strlen($res)-5);
2198+ $res = quickQuery(sprintf($query, _CUSTOMURL_TABLE, $item_id));
2199+ $ipath = substr($res, 0, strlen($res)-5);
46032200 } else {
4604- $ipath = $this->getOption('customurl_dfitem');
2201+ $ipath = $this->getOption('customurl_dfitem');
46052202 }
46062203 echo <<<OUTPUT
46072204 <h3>Custom URL</h3>
@@ -4648,7 +2245,7 @@ OUTPUT;
46482245 } elseif ($arch_option || $arvs_option || $memd_option) {
46492246 if (!ereg("^[-_a-zA-Z0-9]+$", $data['value'])) {
46502247 $name = substr($data['optionname'], 8);
4651- $msg = array (1, _INVALID_ERROR, $name, _INVALID_MSG);
2248+ $msg = array (1, _INVALID_ERROR, $name, _INVALID_MSG);
46522249 $this->error($msg);
46532250 exit;
46542251 } else {
@@ -4705,9 +2302,11 @@ OUTPUT;
47052302 $y = $m = $d = $temp = '';
47062303 sscanf($itime, '%d-%d-%d %s', $y, $m, $d, $temp);
47072304 $template = $this->getOption('customurl_dfitem');
4708- $param = array ('year' => $y,
2305+ $param = array (
2306+ 'year' => $y,
47092307 'month' => $m,
4710- 'day' => $d);
2308+ 'day' => $d
2309+ );
47112310 $ikey = TEMPLATE::fill($template, $param);
47122311 if ($path == $ikey) {
47132312 $path = $ikey . '_' . $objID;
@@ -4732,9 +2331,9 @@ OUTPUT;
47322331 if ($oParam == 'item' || $oParam == 'member') $tempPath .= '.html';
47332332 $conf_que = 'SELECT obj_id FROM %s'
47342333 . ' WHERE obj_name = "%s"'
4735- . ' AND obj_bid = %d'
4736- . ' AND obj_param = "%s"'
4737- . ' AND obj_id != %d';
2334+ . ' AND obj_bid = %d'
2335+ . ' AND obj_param = "%s"'
2336+ . ' AND obj_id != %d';
47382337 $res = sql_query(sprintf($conf_que, _CUSTOMURL_TABLE, $tempPath, $bid, $oParam, $objID));
47392338 if ($res && mysql_num_rows($res)) {
47402339 $msg = array (0, _CONFLICT_ERROR, $name, _CONFLICT_MSG);
Show on old repository browser