• R/O
  • HTTP
  • SSH
  • HTTPS

nucleus-plugins: Commit

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


Commit MetaInfo

Revision667eb980329a2ba102ee365a26a9135a98e96c2c (tree)
Time2009-02-02 14:22:51
Authorshizuki <shizuki@1ca2...>
Commitershizuki

Log Message

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

Change Summary

Incremental Difference

--- /dev/null
+++ b/NP_CustomURL/tags/NP_CustomURL.php
@@ -0,0 +1,2586 @@
1+<?php
2+
3+if (!function_exists('htmlspecialchars_decode')) {
4+ function htmlspecialchars_decode($text)
5+ {
6+ return strtr($text, array_flip(get_html_translation_table(HTML_SPECIALCHARS)));
7+ }
8+}
9+
10+if (!defined('_CUSTOMURL_TABLE_DEFINED')) {
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'));
14+}
15+
16+class NP_CustomURL extends NucleusPlugin
17+{
18+
19+ function getMinNucleusVersion()
20+ {
21+ return '322';
22+ }
23+
24+ function getName()
25+ {
26+ return 'Customized URL';
27+ }
28+
29+ function getAuthor()
30+ {
31+ return 'shizuki';
32+ }
33+
34+ function getURL()
35+ {
36+ return 'http://japan.nucleuscms.org/wiki/plugins:customurl';
37+ }
38+
39+ function getVersion()
40+ {
41+ return '0.3.6b';
42+ }
43+
44+ function getDescription()
45+ {
46+ return _DESCRIPTION;
47+ }
48+
49+ function supportsFeature($what)
50+ {
51+ switch ($what) {
52+ case 'SqlTablePrefix':
53+ return 1;
54+ case 'HelpPage':
55+ return 1;
56+ default:
57+ return 0;
58+ }
59+ }
60+
61+ function hasAdminArea()
62+ {
63+ return 1;
64+ }
65+
66+ function event_QuickMenu(&$data)
67+ {
68+ global $member;
69+ $quickLink = ($this->getOption( 'customurl_quicklink') == 'yes');
70+ $memberCheck = ($member->isLoggedIn() && $member->isAdmin());
71+ if (!$quickLink || !$memberCheck) {
72+ return;
73+ }
74+ array_push(
75+ $data['options'],
76+ array(
77+ 'title' => _ADMIN_TITLE,
78+ 'url' => $this->getAdminURL(),
79+ 'tooltip' => _QUICK_TIPS
80+ )
81+ );
82+ }
83+
84+ function getTableList()
85+ {
86+ return array(
87+ _CUSTOMURL_TABLE
88+ );
89+ }
90+
91+ function getEventList()
92+ {
93+ return array(
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+ );
116+ }
117+
118+ function install()
119+ {
120+
121+// Can't install when faster requier Nucleus Core Version
122+ $ver_min = (getNucleusVersion() < $this->getMinNucleusVersion());
123+ $pat_min = ((getNucleusVersion() == $this->getMinNucleusVersion()) &&
124+ (getNucleusPatchLevel() < $this->getMinNucleusPatchLevel()));
125+ if ($ver_min || $pat_min) {
126+ global $DIR_LIBS;
127+ // uninstall plugin again...
128+ include_once($DIR_LIBS . 'ADMIN.php');
129+ $admin = new ADMIN();
130+ $admin->deleteOnePlugin($this->getID());
131+
132+ // ...and show error
133+ $admin->error(_ERROR_NUCLEUSVERSIONREQ .
134+ $this->getMinNucleusVersion() . ' patch ' .
135+ $this->getMinNucleusPatchLevel());
136+ }
137+
138+ global $manager, $CONF;
139+// Keys initialize
140+ if (empty($CONF['ArchiveKey'])) {
141+ $CONF['ArchiveKey'] = 'archive';
142+ }
143+ if (empty($CONF['ArchivesKey'])) {
144+ $CONF['ArchivesKey'] = 'archives';
145+ }
146+ if (empty($CONF['MemberKey'])) {
147+ $CONF['MemberKey'] = 'member';
148+ }
149+ if (empty($CONF['ItemKey'])) {
150+ $CONF['ItemKey'] = 'item';
151+ }
152+ if (empty($CONF['CategoryKey'])) {
153+ $CONF['CategoryKey'] = 'category';
154+ }
155+
156+//Plugins sort
157+ $plugTable = sql_table('plugin');
158+ $myid = intval($this->getID());
159+ $res = sql_query('SELECT pid, porder FROM ' . $plugTable);
160+ while ($p = mysql_fetch_array($res)) {
161+ $updateQuery = 'UPDATE %s '
162+ . 'SET porder = %d '
163+ . 'WHERE pid = %d';
164+ if (($pid = intval($p['pid'])) == $myid) {
165+ $q = sprintf($updateQuery, $plugTable, 1, $myid);
166+ sql_query($q);
167+ } else {
168+ $porder = intval($p['porder']);
169+ $q = sprintf($updateQuery, $plugTable, $porder + 1, $pid);
170+ sql_query($q);
171+ }
172+ }
173+
174+//create plugin's options and set default value
175+ $this->createOption('customurl_archive', _OP_ARCHIVE_DIR_NAME,
176+ 'text', $CONF['ArchiveKey']);
177+ $this->createOption('customurl_archives', _OP_ARCHIVES_DIR_NAME,
178+ 'text', $CONF['ArchivesKey']);
179+ $this->createOption('customurl_member', _OP_MEMBER_DIR_NAME,
180+ 'text', $CONF['MemberKey']);
181+ $this->createOption('customurl_dfitem', _OP_DEF_ITEM_KEY,
182+ 'text', $CONF['ItemKey']);
183+ $this->createOption('customurl_dfcat', _OP_DEF_CAT_KEY,
184+ 'text', $CONF['CategoryKey']);
185+ $this->createOption('customurl_dfscat', _OP_DEF_SCAT_KEY,
186+ 'text', 'subcategory');
187+ $this->createOption('customurl_incbname', _OP_INCLUDE_CBNAME,
188+ 'yesno', 'no');
189+ $this->createOption('customurl_tabledel', _OP_TABLE_DELETE,
190+ 'yesno', 'no');
191+ $this->createOption('customurl_quicklink', _OP_QUICK_LINK,
192+ 'yesno', 'yes');
193+ $this->createOption('customurl_notfound', _OP_NOT_FOUND,
194+ 'select', '404',
195+ '404 Not Found|404|303 See Other|303');
196+ $this->createBlogOption( 'use_customurl', _OP_USE_CURL,
197+ 'yesno', 'yes');
198+ $this->createBlogOption( 'redirect_normal', _OP_RED_NORM,
199+ 'yesno', 'yes');
200+ $this->createBlogOption( 'redirect_search', _OP_RED_SEARCH,
201+ 'yesno', 'yes');
202+ $this->createBlogOption( 'customurl_bname', _OP_BLOG_PATH,
203+ 'text');
204+// $this->createItemOption( 'customurl_iname', _OP_ITEM_PATH,
205+// 'text', $CONF['ItemKey']);
206+ $this->createMemberOption( 'customurl_mname', _OP_MEMBER_PATH,
207+ 'text');
208+ $this->createCategoryOption('customurl_cname', _OP_CATEGORY_PATH,
209+ 'text');
210+
211+ //default archive directory name
212+ $this->setOption('customurl_archive', $CONF['ArchiveKey']);
213+ //default archives directory name
214+ $this->setOption('customurl_archives', $CONF['ArchivesKey']);
215+ //default member directory name
216+ $this->setOption('customurl_member', $CONF['MemberKey']);
217+ //default itemkey_template
218+ $this->setOption('customurl_dfitem', $CONF['ItemKey']);
219+ //default categorykey_template
220+ $this->setOption('customurl_dfcat', $CONF['CategoryKey']);
221+ //default subcategorykey_template
222+ $this->setOption('customurl_dfscat', 'subcategory');
223+
224+//create data table
225+ $sql = 'CREATE TABLE IF NOT EXISTS ' . _CUSTOMURL_TABLE . ' ('
226+ . ' `id` INT(11) NOT NULL AUTO_INCREMENT PRIMARY KEY, '
227+ . ' `obj_param` VARCHAR(15) NOT NULL, '
228+ . ' `obj_name` VARCHAR(128) NOT NULL, '
229+ . ' `obj_id` INT(11) NOT NULL, '
230+ . ' `obj_bid` INT(11) NOT NULL,'
231+ . ' INDEX (`obj_name`)'
232+ . ' )';
233+ sql_query($sql);
234+
235+//setting default aliases
236+ $this->_createNewPath('blog', 'blog', 'bnumber', 'bshortname');
237+ $this->_createNewPath('item', 'item', 'inumber', 'iblog');
238+ $this->_createNewPath('category', 'category', 'catid', 'cblog');
239+ $this->_createNewPath('member', 'member', 'mnumber', 'mname');
240+
241+ if ($this->pluginCheck('MultipleCategories')) {
242+ $scatTableName = 'plug_multiple_categories_sub';
243+ $this->_createNewPath('subcategory', $scatTableName, 'scatid', 'catid');
244+ }
245+
246+ }
247+
248+ function _createNewPath($type, $n_table, $id, $bids)
249+ {
250+ $tmpTable = sql_table('plug_customurl_temp');
251+ $createQuery = 'CREATE TABLE %s '
252+ . 'SELECT obj_id, obj_param '
253+ . 'FROM %s '
254+ . 'WHERE obj_param = "%s"';
255+ sql_query(sprintf($createQuery, $tmpTable, _CUSTOMURL_TABLE, $type));
256+ $TmpQuery = 'SELECT %s, %s '
257+ . 'FROM %s as ttb '
258+ . 'LEFT JOIN %s as tcu '
259+ . 'ON ttb.%s = tcu.obj_id '
260+ . 'WHERE tcu.obj_id is null';
261+ $table = sql_table($n_table);
262+ $TmpQuery = sprintf($TmpQuery, $id, $bids, $table, $tmpTable, $id);
263+ $temp = sql_query($TmpQuery);
264+ if ($temp) {
265+ while ($row = mysql_fetch_array($temp)) {
266+ switch ($type) {
267+ case 'blog':
268+ //set access by BlogshortName/
269+ $newPath = $row[$bids];
270+ $blgid = 0;
271+ break;
272+ case 'item':
273+ //set access by (itemkey_template)_itemid.html
274+ $tque = 'SELECT '
275+ . 'itime as result '
276+ . 'FROM %s '
277+ . 'WHERE inumber = %d';
278+ $tque = sprintf($tque, $table, intval($row[$id]));
279+ $itime = quickQuery($tque);
280+ list($y, $m, $d, $trush) = sscanf($itime, '%d-%d-%d %s');
281+ $param['year'] = sprintf('%04d', $y);
282+ $param['month'] = sprintf('%02d', $m);
283+ $param['day'] = sprintf('%02d', $d);
284+ $itplt = $this->getOption('customurl_dfitem');
285+ $ikey = TEMPLATE::fill($itplt, $param);
286+ $newPath = $ikey . '_' . $row[$id] . '.html';
287+ $blgid = $row[$bids];
288+ break;
289+ case 'category':
290+ //set access by (categorykey_template)_categoryid/
291+ $newPath = $this->getOption('customurl_dfcat') . '_' . $row[$id];
292+ $blgid = $row[$bids];
293+ break;
294+ case 'member':
295+ //set access by loginName.html
296+ $newPath = $row[$bids] . '.html';
297+ $blgid = 0;
298+ break;
299+ case 'subcategory':
300+ //set access by (subcategorykey_template)_subcategoryid/
301+ $newPath = $this->getOption('customurl_dfscat') . '_' . $row[$id];
302+ $blgid = $row[$bids];
303+ break;
304+ default:
305+ break;
306+ }
307+ $insertQuery = 'INSERT INTO %s '
308+ . '(obj_param, obj_id, obj_name, obj_bid) '
309+ . 'VALUES ("%s", %d, "%s", %d)';
310+ $row[$id] = intval($row[$id]);
311+ $blgid = intval($blgid);
312+ sql_query(sprintf($insertQuery, _CUSTOMURL_TABLE, $type, $row[$id], $newPath, $blgid));
313+ }
314+ }
315+ $query = 'SELECT obj_id, obj_name '
316+ . 'FROM %s '
317+ . 'WHERE obj_param = "%s"';
318+ $temp = sql_query(sprintf($query, _CUSTOMURL_TABLE, $type));
319+ while ($row = mysql_fetch_array($temp)) {
320+ $name = $row['obj_name'];
321+ $id = intval($row['obj_id']);
322+ switch ($type) {
323+ case 'blog':
324+ $this->setBlogOption($id, 'customurl_bname', $name);
325+ break;
326+ case 'category':
327+ $this->setCategoryOption($id, 'customurl_cname', $name);
328+ break;
329+ case 'member':
330+ $obj_name = substr($name, 0, -5);
331+ $this->setMemberOption($id, 'customurl_mname', $obj_name);
332+ break;
333+ default:
334+ break;
335+ }
336+ }
337+
338+ sql_query('DROP TABLE IF EXISTS ' . $tmpTable);
339+ }
340+
341+ function init()
342+ {
343+ global $admin;
344+ $language = ereg_replace( '[\\|/]', '', getLanguageName());
345+ if (file_exists($this->getDirectory() . 'language/' . $language . '.php')) {
346+ include_once($this->getDirectory() . 'language/' . $language . '.php');
347+ } else {
348+ include_once($this->getDirectory() . 'language/english.php');
349+ }
350+ }
351+
352+ function pluginCheck($pluginName)
353+ {
354+ global $manager;
355+ if (!$manager->pluginInstalled('NP_' . $pluginName)) {
356+ return;
357+ }
358+ $plugin =& $manager->getPlugin('NP_' . $pluginName);
359+ return $plugin;
360+ }
361+
362+ function unInstall()
363+ {
364+ if ($this->getOption('customurl_tabledel') == 'yes') {
365+ sql_query("DROP TABLE "._CUSTOMURL_TABLE);
366+ }
367+ $this->deleteOption('customurl_archive');
368+ $this->deleteOption('customurl_archives');
369+ $this->deleteOption('customurl_member');
370+ $this->deleteOption('customurl_dfitem');
371+ $this->deleteOption('customurl_dfcat');
372+ $this->deleteOption('customurl_dfscat');
373+ $this->deleteOption('customurl_notfound');
374+ $this->deleteOption('customurl_tabledel');
375+ $this->deleteOption('customurl_quicklink');
376+ $this->deleteBlogOption('use_customurl');
377+ $this->deleteBlogOption('redirect_normal');
378+ $this->deleteBlogOption('redirect_search');
379+ $this->deleteBlogOption('customurl_bname');
380+// $this->deleteItemOption('customurl_iname');
381+ $this->deleteMemberOption('customurl_mname');
382+ $this->deleteCategoryOption('customurl_cname');
383+ }
384+
385+ function event_ParseURL($data)
386+ {
387+ global $CONF, $manager, $curl_blogid, $blogid, $itemid, $catid;
388+ global $memberid, $archivelist, $archive, $query;
389+// initialize
390+ $info = $data['info'];
391+ $complete =& $data['complete'];
392+ if ($complete) {
393+ return;
394+ }
395+ $useCustomURL = $this->getAllBlogOptions('use_customurl');
396+
397+// Use NP_MultipleCategories ?
398+ $mcategories = $this->pluginCheck('MultipleCategories');
399+ if ($mcategories) {
400+ $mcategories->event_PreSkinParse(array());
401+ global $subcatid;
402+ if (method_exists($mcategories, 'getRequestName')) {
403+ $subrequest = $mcategories->getRequestName();
404+ } else {
405+ $subrequest = 'subcatid';
406+ }
407+ }
408+
409+// initialize and sanitize '$blogid'
410+ if (!$blogid) {
411+ if ( getVar('blogid') ) {
412+ if ( is_numeric(getVar('blogid')) ) {
413+ $blogid = intval(getVar('blogid'));
414+ } else {
415+ $blogid = intval(getBlogIDFromName(getVar('blogid')));
416+ }
417+ } elseif ($curl_blogid) {
418+ $blogid = intval($curl_blogid);
419+ } else {
420+ $blogid = $CONF['DefaultBlog'];
421+ }
422+ } else {
423+ if (is_numeric($blogid)) {
424+ $blogid = intval($blogid);
425+ } else {
426+ $blogid = intval(getBlogIDFromName($blogid));
427+ }
428+ }
429+
430+ if (!$info) {
431+ if (serverVar('PATH_INFO')) {
432+ $info = serverVar('PATH_INFO');
433+ } elseif (getNucleusVersion() < 330) {
434+ if (getVar('virtualpath')) {
435+ $info = getVar('virtualpath');
436+ }
437+ } else {
438+ return;
439+ }
440+ }
441+
442+// Sanitize 'PATH_INFO'
443+ $info = trim($info, '/');
444+ $v_path = explode("/", $info);
445+ foreach($v_path as $key => $value) {
446+ $value = urlencode($value);
447+ $value = preg_replace('|[^a-zA-Z0-9-~+_.?#=&;,/:@%]|i', '', $value);
448+ $v_path[$key] = $value;
449+ }
450+ if (phpversion() >= '4.1.0') {
451+ $_SERVER['PATH_INFO'] = implode('/', $v_path);
452+ }
453+ global $HTTP_SERVER_VARS;
454+ $HTTP_SERVER_VARS['PATH_INFO'] = implode('/', $v_path);
455+
456+// Admin area check
457+ $tmpURL = sprintf("%s%s%s", "http://", serverVar("HTTP_HOST"), serverVar("SCRIPT_NAME"));
458+ $uri = str_replace('/', '\/', $tmpURL);
459+ $plug_url = str_replace('/', '\/', $CONF['PluginURL']);
460+ $u_plugAction = (getVar('action') == 'plugin' && getVar('name'));
461+ if (strpos($uri, $plug_url) === 0 || $u_plugAction) {
462+ $UsingPlugAdmin = TRUE;
463+ }
464+
465+// redirect to other URL style
466+ $useCustomURLyes = ($useCustomURL[$blogid] == 'yes');
467+ if ($useCustomURLyes && !$UsingPlugAdmin && !$CONF['UsingAdminArea']) {
468+// Search query redirection
469+// 301 permanent ? or 302 temporary ?
470+ $queryURL = (strpos(serverVar('REQUEST_URI'), 'query=') !== FALSE);
471+ $search_q = (getVar('query') || $queryURL);
472+ $redirectSerch = ($this->getBlogOption($blogid, 'redirect_search') == 'yes');
473+ if ($redirectSerch) {
474+ if ($search_q) {
475+ $que_str = getVar('query');
476+ $que_str = htmlspecialchars($que_str);
477+ if (extension_loaded('mbstring')) {
478+ $que_str = mb_eregi_replace('/', 'ssslllaaassshhh', $que_str);
479+ $que_str = mb_eregi_replace("'", 'qqquuuooottt', $que_str);
480+ $que_str = mb_eregi_replace('&', 'aaammmppp', $que_str);
481+ } else {
482+ $que_str = eregi_replace('/', 'ssslllaaassshhh', $que_str);
483+ $que_str = eregi_replace("'", 'qqquuuooottt', $que_str);
484+ $que_str = eregi_replace('&', 'aaammmppp', $que_str);
485+ }
486+ $que_str = urlencode($que_str);
487+ $search_path = '/search/' . $que_str;
488+ $b_url = createBlogidLink($blogid);
489+ $redurl = sprintf("%s%s", $b_url, $search_path);
490+ redirect($redurl); // 302 Moved temporary
491+ exit;
492+ }
493+ }
494+ if (!$redirectSerch && $search_q) {
495+ $exLink = TRUE;
496+ }
497+
498+// redirection nomal URL to FancyURL
499+ $temp_req = explode('?', serverVar('REQUEST_URI'));
500+ $reqPath = trim(end($temp_req), '/');
501+ $indexrdf = ($reqPath == 'xml-rss1.php');
502+ $atomfeed = ($reqPath == 'atom.php');
503+ $rss2feed = ($reqPath == 'xml-rss2.php');
504+ $feeds = ($indexrdf || $atomfeed || $rss2feed);
505+ $redirectNormal = ($this->getBlogOption($blogid, 'redirect_normal') == 'yes');
506+ if ($redirectNormal && serverVar('QUERY_STRING') && !$feeds && !$exLink) {
507+ $temp = explode('&', serverVar('QUERY_STRING'));
508+ foreach ($temp as $k => $val) {
509+ if (preg_match('/^virtualpath/', $val)) {
510+ unset($temp[$k]);
511+ }
512+ }
513+ if (!empty($temp)) {
514+ $p_arr = array();
515+ foreach ($temp as $key => $value) {
516+ $p_key = explode('=', $value);
517+ switch (reset($p_key)) {
518+ case 'blogid';
519+ $p_arr[] = $CONF['BlogKey'] . '/'
520+ . intGetVar('blogid');
521+ unset($temp[$key]);
522+ break;
523+ case 'catid';
524+ $p_arr[] = $CONF['CategoryKey'] . '/'
525+ . intGetVar('catid');
526+ unset($temp[$key]);
527+ break;
528+ case $subrequest;
529+ $p_arr[] = $subrequest . '/'
530+ . intGetVar($subrequest);
531+ unset($temp[$key]);
532+ break;
533+ case 'itemid';
534+ $p_arr[] = $CONF['ItemKey'] . '/'
535+ . intGetVar('itemid');
536+ unset($temp[$key]);
537+ break;
538+ case 'memberid';
539+ $p_arr[] = $CONF['MemberKey'] . '/'
540+ . intGetVar('memberid');
541+ unset($temp[$key]);
542+ break;
543+ case 'archivelist';
544+ $p_arr[] = $CONF['ArchivesKey'] . '/'
545+ . $blogid;
546+ unset($temp[$key]);
547+ break;
548+ case 'archive';
549+ $p_arr[] = $CONF['ArchiveKey'] . '/'
550+ . $blogid . '/' . getVar('archive');
551+ unset($temp[$key]);
552+ break;
553+ default:
554+ break;
555+ }
556+ }
557+ if (!empty($temp)) {
558+ $queryTemp = '/?' . implode('&', $temp);
559+ }
560+ if (reset($p_arr)) {
561+ $b_url = createBlogidLink($blogid);
562+ $red_path = '/' . implode('/', $p_arr);
563+ if (substr($b_url, -1) == '/') {
564+ $b_url = rtrim($b_url, '/');
565+ }
566+ $redurl = sprintf("%s%s", $b_url, $red_path) . $queryTemp;
567+ // HTTP status 301 "Moved Permanentry"
568+ header('HTTP/1.1 301 Moved Permanently');
569+ header('Location: ' . $redurl);
570+ exit;
571+ }
572+ }
573+ } elseif ($redirectNormal && $feeds) {
574+ $b_url = rtrim(createBlogidLink($blogid), '/');
575+ switch ($reqPath) {
576+ case 'xml-rss1.php':
577+ $feed_code = '/index.rdf';
578+ break;
579+ case 'xml-rss2.php':
580+ $feed_code = '/rss2.xml';
581+ break;
582+ case 'atom.php':
583+ $feed_code = '/atom.xml';
584+ break;
585+ default:
586+ break;
587+ }
588+ // HTTP status 301 "Moved Permanentry"
589+ header('HTTP/1.1 301 Moved Permanently');
590+ header('Location: ' . $b_url . $feed_code);
591+ exit;
592+ }
593+ }
594+// decode path_info
595+
596+// decode unofficial Page switch '/page_2.html'
597+/* foreach($v_path as $pathName) {
598+ if (preg_match('/^page_/', $pathName)) {
599+ $temp_info = explode('page_', $pathName);
600+ $_GET['page'] = intval($temp_info[1]);
601+ $page = array_pop($v_path);
602+ }
603+ }*/
604+
605+// decode TrackBack URL shorten ver.
606+ $tail = end($v_path);
607+ if (substr($tail, -10, 10) == '.trackback') {
608+ $v_pathName = substr($tail, 0, -10);
609+ if (is_numeric($v_pathName) || substr($v_pathName, -5) == '.html') {
610+ $this->_trackback($blogid, $v_pathName);
611+ } else {
612+ $this->_trackback($blogid, $v_pathName . '.html');
613+ }
614+ return;
615+ }
616+
617+// decode other type URL
618+ $bLink = $cLink = $iLink = $exLink = FALSE;
619+ if (empty($info)) {
620+ $bLink = TRUE;
621+ }
622+ $linkObj = array (
623+ 'bid' => 0,
624+ 'name' => reset($v_path),
625+ 'linkparam' => 'blog'
626+ );
627+ $blog_id = $this->getRequestPathInfo($linkObj);
628+ if ($blog_id) {
629+ $blogid = $blog_id;
630+ $trush = array_shift($v_path);
631+ $bLink = TURE;
632+ }
633+ if ($useCustomURL[$blogid] == 'no') {
634+ return;
635+ }
636+ $i = 1;
637+ foreach($v_path as $pathName) {
638+ switch ($pathName) {
639+// decode FancyURLs and redirection to Customized URL
640+ // for blogsgetAllBlogOptions($name)
641+ case $CONF['BlogKey']:
642+ if (isset($v_path[$i]) && is_numeric($v_path[$i])) {
643+ if ($useCustomURL[intval($v_path[$i])] != 'yes') {
644+ $blogid = intval($v_path[$i]);
645+ $bLink = TRUE;
646+ } else {
647+ $redURI = createBlogidLink(intval($v_path[$i]));
648+ }
649+ }
650+ break;
651+ // for items
652+ case $CONF['ItemKey']:
653+ if (isset($v_path[$i]) && is_numeric($v_path[$i])) {
654+ if ($useCustomURL[$blogid] != 'yes') {
655+ $itemid = intval($v_path[$i]);
656+ $iLink = TRUE;
657+ } else {
658+ $redURI = createItemLink(intval($v_path[$i]));
659+ }
660+ }
661+ break;
662+ // for categories
663+ case $CONF['CategoryKey']:
664+ case 'catid':
665+ if (isset($v_path[$i]) && is_numeric($v_path[$i])) {
666+ if ($useCustomURL[$blogid] != 'yes') {
667+ $catid = intval($v_path[$i]);
668+ $cLink = TRUE;
669+ } else {
670+ $redURI = createCategoryLink(intval($v_path[$i]));
671+ }
672+ }
673+ break;
674+ // for subcategories
675+ case $subrequest:
676+ $c = $i - 2;
677+ $subCat = (isset($v_path[$i]) && is_numeric($v_path[$i]));
678+ if ($mcategories && $subCat && $i >= 3 && is_numeric($v_path[$c])) {
679+ if ($useCustomURL[$blogid] != 'yes') {
680+ $subcatid = intval($v_path[$i]);
681+ $catid = intval($v_path[$c]);
682+ $cLink = TRUE;
683+ } else {
684+ $subcat_id = intval($v_path[$i]);
685+ $catid = intval($v_path[$c]);
686+ $linkParam = array($subrequest => $subcat_id);
687+ $redURI = createCategoryLink($catid, $linkParam);
688+ }
689+ }
690+ break;
691+ // for archives
692+ case $CONF['ArchivesKey']:
693+ case $this->getOption('customurl_archives'):
694+ // FancyURL
695+ if (isset($v_path[$i]) && is_numeric($v_path[$i])) {
696+ if ($useCustomURL[intval($v_path[$i])] != 'yes') {
697+ $archivelist = intval($v_path[$i]);
698+ $blogid = $archivelist;
699+ $exLink = TRUE;
700+ } else {
701+ $redURI = createArchiveListLink(intval($v_path[$i]));
702+ }
703+ // Customized URL
704+ } elseif (isset($v_path[$i]) && strpos($v_path[$i], 'page') === FALSE) {
705+ $archivelist = $blogid;
706+ $redURI = createArchiveListLink($archivelist);
707+ } else {
708+ $archivelist = $blogid;
709+ $exLink = TRUE;
710+ }
711+ break;
712+ // for archive
713+ case $CONF['ArchiveKey']:
714+ case $this->getOption('customurl_archive'):
715+ $y = $m = $d = '';
716+ $ar = $i + 1;
717+ if (isset($v_path[$i])) {
718+ $darc = (ereg('([0-9]{4})-([0-9]{1,2})-([0-9]{1,2})', $v_path[$i]));
719+ $marc = (ereg('([0-9]{4})-([0-9]{1,2})', $v_path[$i]));
720+ $yarc = (ereg('([0-9]{4})', $v_path[$i]));
721+ $adarc = (ereg('([0-9]{4})-([0-9]{1,2})-([0-9]{1,2})', $v_path[$ar]));
722+ $amarc = (ereg('([0-9]{4})-([0-9]{1,2})', $v_path[$ar]));
723+ $ayarc = (ereg('([0-9]{4})', $v_path[$ar]));
724+ $arc = (!$darc && !$marc && !$yarc);
725+ $aarc = ($adarc || $amarc || $ayarc);
726+ $carc = ($darc || $marc || $yarc);
727+ // FancyURL
728+ if (is_numeric($v_path[$i]) && $arc && isset($v_path[$ar]) && $aarc) {
729+ sscanf($v_path[$ar], '%d-%d-%d', $y, $m, $d);
730+ if (!empty($d)) {
731+ $archive = sprintf('%04d-%02d-%02d', $y, $m, $d);
732+ } elseif (!empty($m)) {
733+ $archive = sprintf('%04d-%02d', $y, $m);
734+ } else {
735+ $archive = sprintf('%04d', $y);
736+ }
737+ if ($useCustomURL[intval($v_path[$i])] != 'yes') {
738+ $blogid = intval($v_path[$i]);
739+ $exLink = TRUE;
740+ } else {
741+ $blogid = intval($v_path[$i]);
742+ $redURI = createArchiveLink($blogid, $archive);
743+ }
744+ // Customized URL
745+ } elseif ($carc) {
746+ sscanf($v_path[$i], '%d-%d-%d', $y, $m, $d);
747+ if (!empty($d)) {
748+ $archive = sprintf('%04d-%02d-%02d', $y, $m, $d);
749+ } elseif (!empty($m)) {
750+ $archive = sprintf('%04d-%02d', $y, $m);
751+ } else {
752+ $archive = sprintf('%04d', $y);
753+ }
754+ $exLink = TRUE;
755+ } else {
756+ $redURI = createArchiveListLink($blogid);
757+ }
758+ } else {
759+ $redURI = createArchiveListLink($blogid);
760+ }
761+ break;
762+ // for member
763+ case $CONF['MemberKey']:
764+ case $this->getOption('customurl_member'):
765+ // Customized URL
766+ $customMemberURL = (substr($v_path[$i], -5, 5) == '.html');
767+ if (isset($v_path[$i]) && $customMemberURL) {
768+ $memberInfo = array(
769+ 'linkparam' => 'member',
770+ 'bid' => 0,
771+ 'name' => $v_path[$i]
772+ );
773+ $member_id = $this->getRequestPathInfo($memberInfo);
774+ $memberid = intval($member_id);
775+ $exLink = TRUE;
776+ // FancyURL
777+ } elseif (isset($v_path[$i]) && is_numeric($v_path[$i])) {
778+ if ($useCustomURL[$blogid] != 'yes') {
779+ $memberid = intval($v_path[$i]);
780+ $exLink = TRUE;
781+ } else {
782+ $redURI = createMemberLink(intval($v_path[$i]));
783+ }
784+ } else {
785+ $redURI = createBlogidLink($blogid);
786+ }
787+ break;
788+ // for tag
789+ case 'tag':
790+// if (isset($v_path[$i]) && is_string($v_path[$i])) {
791+// $_REQUEST['tag'] = $v_path[$i];
792+ $exLink = TRUE;
793+// }
794+ break;
795+ // for ExtraSkinJP
796+ case 'extra':
797+ $ExtraSkinJP = $this->pluginCheck('ExtraSkinJP');
798+ if ($ExtraSkinJP) {
799+ // under v3.2 needs this
800+ if ($CONF['DisableSite'] && !$member->isAdmin()) {
801+ header('Location: ' . $CONF['DisableSiteURL']);
802+ exit;
803+ }
804+ $extraParams = explode("/", serverVar('PATH_INFO'));
805+ array_shift ($extraParams);
806+
807+ if (isset($extraParams[1]) && preg_match("/^([1-9]+[0-9]*)(\?.*)?$/", $extraParams[1], $matches)) {
808+ $extraParams[1] = $matches[1];
809+ }
810+
811+ $ExtraSkinJP->extra_selector($extraParams);
812+ exit;
813+ }
814+ break;
815+ // for search query
816+ case 'search':
817+ $redirectSerch = ($this->getBlogOption($blogid, 'redirect_search') == 'yes');
818+ if ($redirectSerch) {
819+ $que_str = urldecode($v_path[$i]);
820+ if (extension_loaded('mbstring')) {
821+ $que_str = mb_eregi_replace('ssslllaaassshhh', '/', $que_str);
822+ $que_str = mb_eregi_replace('qqquuuooottt', "'", $que_str);
823+ $que_str = mb_eregi_replace('aaammmppp', '&', $que_str);
824+ } else {
825+ $que_str = eregi_replace('ssslllaaassshhh', '/', $que_str);
826+ $que_str = eregi_replace('qqquuuooottt', "'", $que_str);
827+ $que_str = eregi_replace('aaammmppp', '&', $que_str);
828+ }
829+ $que_str = htmlspecialchars_decode($que_str);
830+ $_GET['query'] = $que_str;
831+ $query = $que_str;
832+ $exLink = TRUE;
833+ }
834+ break;
835+ // for pageswitch
836+ case 'page':
837+// if (isset($v_path[$i]) && is_numeric($v_path[$i])) {
838+// $_GET['page'] = intval($v_path[$i]);
839+ $exLink = TRUE;
840+// }
841+ break;
842+ // for tDiarySkin
843+ case 'tdiarydate':
844+ case 'categorylist':
845+ case 'monthlimit':
846+ $tDiaryPlugin = $this->pluginCheck('tDiarySkin');
847+ if ($tDiaryPlugin && isset($v_path[$i])) {
848+ $_GET[$pathName] = $v_path[$i];
849+ $exLink = TRUE;
850+ }
851+ break;
852+ case 'special':
853+ if (isset($v_path[$i]) && is_string($v_path[$i])) {
854+ $_REQUEST['special'] = $v_path[$i];
855+ $exLink = TRUE;
856+ }
857+ break;
858+ // for trackback
859+ case 'trackback':
860+ if (isset($v_path[$i]) && is_string($v_path[$i])) {
861+ $this->_trackback($blogid, $v_path[$i]);
862+ }
863+ return;
864+ break;
865+
866+// decode Customized URL
867+ default:
868+ // initialyze
869+ $linkObj = array (
870+ 'bid' => $blogid,
871+ 'name' => $pathName
872+ );
873+ $comp = FALSE;
874+ $isItem = (substr($pathName, -5) == '.html');
875+ // category ?
876+ if (!$comp && !$cLink && !$iLink && !$isItem) {
877+ $linkObj['linkparam'] = 'category';
878+ $cat_id = $this->getRequestPathInfo($linkObj);
879+ if (!empty($cat_id)) {
880+ $catid = intval($cat_id);
881+ $cLink = TURE;
882+ $comp = TRUE;
883+ }
884+ }
885+ // subcategory ?
886+ if (!$comp && $cLink && !$iLink && $mcategories && !$isItem) {
887+ $linkObj['linkparam'] = 'subcategory';
888+ $linkObj['bid'] = $catid;
889+ $subcat_id = $this->getRequestPathInfo($linkObj);
890+ if (!empty($subcat_id)) {
891+ $_REQUEST[$subrequest] = intval($subcat_id);
892+ $subcatid = intval($subcat_id);
893+ $sc = $i;
894+ $comp = TRUE;
895+ }
896+ }
897+ // item ?
898+ if ($isItem) {
899+ $linkObj['linkparam'] = 'item';
900+ $item_id = $this->getRequestPathInfo($linkObj);
901+ if (!empty($item_id)) {
902+ $itemid = intval($item_id);
903+ $iLink = TRUE;
904+ }
905+ if (preg_match('/^page_/', $pathName)) {
906+ $iLink = TRUE;
907+ }
908+//var_dump($linkObj);
909+ }
910+ break;
911+ }
912+ if (preg_match('/^[0-9page]$/', $pathName)) {
913+ $exLink = $pathName;
914+ }
915+ $i++;
916+ }
917+
918+// FancyURL redirect to Customized URL if use it
919+// HTTP status 301 "Moved Permanentry"
920+ if ($redURI) {
921+ if (strpos(serverVar('REQUEST_URI'), '?') !== FALSE) {
922+ list($trush, $tempQueryString) = explode('?', serverVar('REQUEST_URI'), 2);
923+ }
924+ $tempQueryString = '?' . $tempQueryString;
925+ header('HTTP/1.1 301 Moved Permanently');
926+ header('Location: ' . $redURI . $tempQueryString);
927+ exit;
928+ }
929+ $feedurl = array(
930+ 'rss1.xml',
931+ 'index.rdf',
932+ 'rss2.xml',
933+ 'atom.xml',
934+ );
935+ $siteMapPlugin = $this->pluginCheck('GoogleSitemap');
936+ if (!$siteMapPlugin) {
937+ $siteMapPlugin = $this->pluginCheck('SEOSitemaps');
938+ }
939+ if ($siteMapPlugin) {
940+ $pcSitemaps = $siteMapPlugin->getAllBlogOptions('PcSitemap');
941+ foreach ($pcSitemaps as $pCsitemap) {
942+ if ($pCsitemap) {
943+ $feedurl[] = $pCsitemap;
944+ }
945+ }
946+ $mobSitemaps = $siteMapPlugin->getAllBlogOptions('MobileSitemap');
947+ foreach ($mobSitemaps as $mobSitemap) {
948+ if ($mobSitemap) {
949+ $feedurl[] = $mobSitemap;
950+ }
951+ }
952+ }
953+ $feedurl = array_unique($feedurl);
954+ $request_path = end($v_path);
955+ $feeds = in_array($request_path, $feedurl, true);
956+
957+// finish decode
958+ if (!$exLink && !$feeds) {
959+// URL Not Found
960+ if (substr(end($v_path), -5) == '.html' && !$iLink) {
961+ $notFound = TRUE;
962+ if (!empty($subcatid)) {
963+ $linkParam = array(
964+ $subrequest => $subcatid
965+ );
966+ $uri = createCategoryLink($catid, $linkParam);
967+ } elseif (!empty($catid)) {
968+ $uri = createCategoryLink($catid);
969+ } else {
970+ $uri = createBlogidLink($blogid);
971+ }
972+ } elseif (count($v_path) > $sc && !empty($subcatid) && !$iLink) {
973+ $notFound = TRUE;
974+ $linkParam = array(
975+ $subrequest => $subcatid
976+ );
977+ $uri = createCategoryLink($catid, $linkParam);
978+ } elseif (count($v_path) >= 2 && !$subcatid && !$iLink) {
979+ $notFound = TRUE;
980+ if (isset($catid)) {
981+ $uri = createCategoryLink($catid);
982+ } else {
983+ $uri = createBlogidLink($blogid);
984+ }
985+ } elseif (reset($v_path) && !$catid && !$subcatid && !$iLink) {
986+ $notFound = TRUE;
987+ $uri = createBlogidLink($blogid);
988+ } else {
989+// Found
990+// setting $CONF['Self'] for other plugins
991+ $uri = createBlogidLink($blogid);
992+ $CONF['Self'] = rtrim($uri, '/');
993+ $CONF['BlogURL'] = rtrim($uri, '/');
994+ $CONF['ItemURL'] = rtrim($uri, '/');
995+ $CONF['CategoryURL'] = rtrim($uri, '/');
996+ $CONF['ArchiveURL'] = rtrim($uri, '/');
997+ $CONF['ArchiveListURL'] = rtrim($uri, '/');
998+ $complete = TRUE;
999+ return ;
1000+ }
1001+ } else {
1002+ $uri = createBlogidLink($blogid);
1003+ $CONF['Self'] = rtrim($uri, '/');
1004+ $CONF['BlogURL'] = rtrim($uri, '/');
1005+ $CONF['ItemURL'] = rtrim($uri, '/');
1006+ $CONF['CategoryURL'] = rtrim($uri, '/');
1007+ $CONF['ArchiveURL'] = rtrim($uri, '/');
1008+ $CONF['ArchiveListURL'] = rtrim($uri, '/');
1009+ $complete = TRUE;
1010+ return ;
1011+ }
1012+// Behavior Not Found
1013+ if ($notFound) {
1014+ if (substr($uri, -1) != '/') {
1015+ $uri .= '/';
1016+ }
1017+ if ($this->getOption('customurl_notfound') == '404') {
1018+ header('HTTP/1.1 404 Not Found');
1019+ doError(_NO_SUCH_URI);
1020+ exit;
1021+ } else {
1022+ header('HTTP/1.1 303 See Other');
1023+ header('Location: ' . $uri);
1024+ exit;
1025+ }
1026+ }
1027+ }
1028+
1029+// decode 'path name' to 'id'
1030+ function getRequestPathInfo($linkObj)
1031+ {
1032+ $query = 'SELECT obj_id as result'
1033+ . ' FROM %s'
1034+ . ' WHERE obj_name = "%s"'
1035+ . ' AND obj_bid = %d'
1036+ . ' AND obj_param = "%s"';
1037+ $name = $this->quote_smart($linkObj['name']);
1038+ $bid = $this->quote_smart($linkObj['bid']);
1039+ $linkparam = $this->quote_smart($linkObj['linkparam']);
1040+ $query = sprintf($query, _CUSTOMURL_TABLE, $name, $bid, $linkparam);
1041+ $ObjID = quickQuery($query);
1042+ if (!$ObjID) {
1043+ return;
1044+ } else {
1045+ return intval($ObjID);
1046+ }
1047+ }
1048+
1049+// Receive TrackBack ping
1050+ function _trackback($bid, $path)
1051+ {
1052+ $blog_id = intval($bid);
1053+ $TrackBack = $this->pluginCheck('TrackBack');
1054+ if ($TrackBack) {
1055+ if (substr($path, -5, 5) == '.html') {
1056+ $linkObj = array (
1057+ 'linkparam' => 'item',
1058+ 'bid' => $blog_id,
1059+ 'name' => $path
1060+ );
1061+ $item_id = $this->getRequestPathInfo($linkObj);
1062+ if ($item_id) {
1063+ $tb_id = intval($item_id);
1064+ } else {
1065+ doError(_NO_SUCH_URI);
1066+ }
1067+ } else {
1068+ $tb_id = intval($path);
1069+ }
1070+
1071+ $errorMsg = $TrackBack->handlePing($tb_id);
1072+ if ($errorMsg != '') {
1073+ $TrackBack->xmlResponse($errorMsg);
1074+ } else {
1075+ $TrackBack->xmlResponse();
1076+ }
1077+ }
1078+ exit;
1079+ }
1080+
1081+ function event_GenerateURL($data)
1082+ {
1083+ global $CONF, $manager, $blogid;
1084+ if ($data['completed']) {
1085+ return;
1086+ }
1087+ if (is_numeric($blogid)) {
1088+ $blogid = intval($blogid);
1089+ } else {
1090+ $blogid = intval(getBlogIDFromName($blogid));
1091+ }
1092+ $mcategories = $this->pluginCheck('MultipleCategories');
1093+ if ($mcategories) {
1094+ if (method_exists($mcategories, 'getRequestName')) {
1095+ $mcategories->event_PreSkinParse(array());
1096+ global $subcatid;
1097+ $subrequest = $mcategories->getRequestName();
1098+ }
1099+ }
1100+ if ($subcatid) {
1101+ $subcatid = intval($subcatid);
1102+ }
1103+ $OP_ArchiveKey = $this->getOption('customurl_archive');
1104+ $OP_ArchivesKey = $this->getOption('customurl_archives');
1105+ $OP_MemberKey = $this->getOption('customurl_member');
1106+ $params = $data['params'];
1107+ $catParam = $params['extra']['catid'];
1108+ $subcatParam = $params['extra'][$subrequest];
1109+ $useCustomURL = $this->getAllBlogOptions('use_customurl');
1110+ switch ($data['type']) {
1111+ case 'item':
1112+ if (!is_numeric($params['itemid'])) {
1113+ return;
1114+ }
1115+ $item_id = intval($params['itemid']);
1116+ $bid = intval(getBlogIDFromItemID($item_id));
1117+ if ($useCustomURL[$bid] == 'no') {
1118+ return;
1119+ }
1120+ $query = 'SELECT obj_name as result '
1121+ . 'FROM %s '
1122+ . 'WHERE obj_param = "item" '
1123+ . 'AND obj_id = %d';
1124+ $path = quickQuery(sprintf($query, _CUSTOMURL_TABLE, $item_id));
1125+ if ($path) {
1126+ $objPath = $path;
1127+ } else {
1128+ if (!$this->_isValid(array('item', 'inumber', $item_id))) {
1129+ $objPath = _NOT_VALID_ITEM;
1130+ } else {
1131+ $y = $m = $d = $temp = '';
1132+ $table = sql_table('item');
1133+ $tque = 'SELECT itime as result '
1134+ . 'FROM %s '
1135+ . 'WHERE inumber = %d';
1136+ $itime = quickQuery(sprintf($tque ,$table, $item_id));
1137+ sscanf($itime,'%d-%d-%d %s', $y, $m, $d, $temp);
1138+ $defItem = $this->getOption('customurl_dfitem');
1139+ $tempParam = array(
1140+ 'year' => $Y,
1141+ 'month' => $m,
1142+ 'day' => $d
1143+ );
1144+ $ikey = TEMPLATE::fill($defItem, $tempParam);
1145+ $ipath = $ikey . '_' . $item_id;
1146+ $query = 'SELECT ititle as result '
1147+ . 'FROM %s '
1148+ . 'WHERE inumber = %d';
1149+ $query = sprintf($query, $table, $item_id);
1150+ $iname = quickQuery($query);
1151+ $this->RegistPath($item_id, $ipath, $bid, 'item', $iname, TRUE);
1152+ $objPath = $ipath . '.html';
1153+ }
1154+ }
1155+ if ($bid != $blogid) {
1156+ $burl = $this->_generateBlogLink($bid);
1157+ } else {
1158+ $burl = $this->_generateBlogLink($blogid);
1159+ }
1160+ break;
1161+ case 'member':
1162+ if (!is_numeric($params['memberid']) || $useCustomURL[$blogid] =='no') {
1163+ return;
1164+ }
1165+ $memberID = intval($params['memberid']);
1166+ $path = $this->getMemberOption($memberID, 'customurl_mname');
1167+ if ($path) {
1168+ $data['url'] = $this->_generateBlogLink($blogid) . '/'
1169+ . $OP_MemberKey . '/' . $path . '.html';
1170+ $data['completed'] = TRUE;
1171+ return;
1172+ } else {
1173+ if (!$this->_isValid(array('member', 'mnumber', $memberID))) {
1174+ $data['url'] = $this->_generateBlogLink($blogid) . '/'
1175+ . _NOT_VALID_MEMBER;
1176+ $data['completed'] = TRUE;
1177+ return;
1178+ } else {
1179+ $query = 'SELECT mname as result FROM %s'
1180+ . ' WHERE mnumber = %d';
1181+ $table = sql_table('member');
1182+ $mname = quickQuery(sprintf($query, $table, $memberID));
1183+ $this->RegistPath($memberID, $mname, 0, 'member', $mname, TRUE);
1184+ $data['url'] = $this->_generateBlogLink($blogid) . '/'
1185+ . $OP_MemberKey . '/' . $mname . '.html';
1186+ $data['completed'] = TRUE;
1187+ return;
1188+ }
1189+ }
1190+ break;
1191+ case 'category':
1192+ if (!is_numeric($params['catid'])) {
1193+ return;
1194+ }
1195+ $cat_id = intval($params['catid']);
1196+ $bid = intval(getBlogidFromCatID($cat_id));
1197+ if ($useCustomURL[$bid] == 'no') {
1198+ return;
1199+ }
1200+ $objPath = $this->_generateCategoryLink($cat_id);
1201+ if ($bid != $blogid) {
1202+ $burl = $this->_generateBlogLink($bid);
1203+ }
1204+ break;
1205+ case 'archivelist':
1206+ if ($useCustomURL[$blogid] == 'no') {
1207+ return;
1208+ }
1209+ $objPath = $OP_ArchivesKey . '/';;
1210+ $bid = intval($params['blogid']);
1211+ $burl = $this->_generateBlogLink($bid);
1212+ break;
1213+ case 'archive':
1214+ if ($useCustomURL[$blogid] == 'no') {
1215+ return;
1216+ }
1217+ sscanf($params['archive'], '%d-%d-%d', $y, $m, $d);
1218+ if ($d) {
1219+ $arc = sprintf('%04d-%02d-%02d', $y, $m, $d);
1220+ } elseif ($m) {
1221+ $arc = sprintf('%04d-%02d', $y, $m);
1222+ } else {
1223+ $arc = sprintf('%04d', $y);
1224+ }
1225+ $objPath = $OP_ArchiveKey . '/' . $arc . '/';;
1226+ $bid = intval($params['blogid']);
1227+ $burl = $this->_generateBlogLink($bid);
1228+ break;
1229+ case 'blog':
1230+ if (!is_numeric($params['blogid'])) {
1231+ return;
1232+ }
1233+ $bid = intval($params['blogid']);
1234+ $burl = $this->_generateBlogLink($bid);
1235+ break;
1236+ default:
1237+ return;
1238+ }
1239+ if (!$burl) {
1240+ $burl = $this->_generateBlogLink($blogid);
1241+ }
1242+/*
1243+ //NP_Analyze AdminArea check
1244+ $aplugin = $this->pluginCheck('Analyze');
1245+ if ($aplugin) {
1246+ $aadmin = str_replace('/', '\/', $aplugin->getAdminURL());
1247+ $p_arr = explode('/', serverVar('SCRIPT_NAME'));
1248+ $tmp = array_pop($p_arr);
1249+ $p_info = implode('\/', $p_arr);
1250+ }
1251+ if ($p_info) {
1252+ if (strpos($aadmin, $p_info)) {
1253+ $CONF['UsingAdminArea'] = TRUE;
1254+ }
1255+ }
1256+ //NP_Analyze AdminArea check end
1257+
1258+ if (getVar('virtualpath')) {
1259+ $info = preg_replace('|[^a-zA-Z0-9-~+_.?#=&;,/:@%]|i', '', getVar('virtualpath'));
1260+ } elseif (serverVar('PATH_INFO')) {
1261+ $info = preg_replace('|[^a-zA-Z0-9-~+_.?#=&;,/:@%]|i', '', serverVar('PATH_INFO'));
1262+ }
1263+ $v_path = explode('/', $info);
1264+
1265+ $feedurl = array();
1266+ $SiteMapP = $this->pluginCheck('GoogleSitemap');
1267+ if ($SiteMapP) {
1268+ $PcSitemaps = $SiteMapP->getAllBlogOptions('PcSitemap');
1269+ foreach ($PcSitemaps as $PCsitemap) {
1270+ if ($PCsitemap) {
1271+ $feedurl[] = $PCsitemap;
1272+ }
1273+ }
1274+ $MobSitemaps = $SiteMapP->getAllBlogOptions('MobileSitemap');
1275+ foreach ($MobSitemaps as $Mobsitemap) {
1276+ if ($Mobsitemap) {
1277+ $feedurl[] = $Mobsitemap;
1278+ }
1279+ }
1280+ }
1281+ $feedurl = array_unique($feedurl);
1282+ $request_path = end($v_path);
1283+ $feeds = in_array($request_path, $feedurl, true);
1284+*/
1285+
1286+ $denyPlugins = array(
1287+ 'np_analyze',
1288+ 'np_googlesitemap',
1289+ );
1290+ $tempdeb=debug_backtrace();
1291+ foreach($tempdeb as $k => $v){
1292+ $analyzePlugin = (strtolower($v['class']) == 'np_analyze');
1293+ $sitemapPlugin = (strtolower($v['class']) == 'np_googlesitemap' ||
1294+ strtolower($v['class']) == 'np_seositemaps');
1295+ if ($analyzePlugin || $sitemapPlugin) {
1296+ $denyPlugin = TRUE;
1297+ }
1298+ }
1299+
1300+// if (!$feeds && $bid != $blogid && !$CONF['UsingAdminArea']) {
1301+ if (!$denyPlugin && $bid != $blogid) {
1302+ $params['extra'] = array();
1303+ }
1304+ if ($objPath || $data['type'] == 'blog') {
1305+ $LinkURI = $this->_addLinkParams($objPath, $params['extra']);
1306+ if ($LinkURI) {
1307+ $data['url'] = $burl . '/' . $LinkURI;
1308+ } else {
1309+ $data['url'] = $burl;
1310+ }
1311+ $arcTmp = (preg_match('/' . $OP_ArchivesKey . '/', $data['url']));
1312+ $arcsTmp = (preg_match('/' . $OP_ArchiveKey . '/', $data['url']));
1313+ $isArchives = ($arcTmp || $arcsTmp);
1314+ $isItem = (substr($data['url'], -5, 5) == '.html');
1315+ $isDirectory = (substr($data['url'], -1) == '/');
1316+ $puri = parse_url($data['url']);
1317+// if (($isArchives && !$puri['query']) || (!$isItem && !$isDirectory && !$puri['query'])) {
1318+ if (!$isItem && !$isDirectory && !$puri['query']) {
1319+ $data['url'] .= '/';
1320+ }
1321+ $data['completed'] = TRUE;
1322+ if (strstr ($data['url'], '//')) {
1323+ $link = preg_replace("/([^:])\/\//", "$1/", $data['url']);
1324+ }
1325+ //$tempdeb=debug_backtrace();
1326+ foreach($tempdeb as $k => $v){
1327+ if (strtolower($v['class']) == 'np_trackback' && strtolower($v['function']) == 'gettrackbackurl') {
1328+ $tb = 1;
1329+ }
1330+ }
1331+ if ($tb == 1 && $data['type'] == 'item' && $isItem) {
1332+ $data['url'] = substr($data['url'], 0, -5);
1333+ }
1334+ return $data;
1335+ }
1336+ }
1337+
1338+ function _createSubCategoryLink($scid)
1339+ {
1340+ $scids = $this->getParents(intval($scid));
1341+ $subcatids = explode('/', $scids);
1342+ $eachPath = array();
1343+ foreach ($subcatids as $sid) {
1344+ $subcat_id = intval($sid);
1345+ $query = 'SELECT obj_name as result'
1346+ . ' FROM %s'
1347+ . ' WHERE obj_id = %d'
1348+ . ' AND obj_param = "%s"';
1349+ $query = sprintf($query, _CUSTOMURL_TABLE, $subcat_id, 'subcategory');
1350+ $path = quickQuery($query);
1351+ if ($path) {
1352+ $eachPath[] = $path;
1353+ } else {
1354+ $tempParam = array(
1355+ 'plug_multiple_categories_sub',
1356+ 'scatid',
1357+ $subcat_id
1358+ );
1359+ if (!$this->_isValid($tempParam)) {
1360+ return $url = _NOT_VALID_SUBCAT;
1361+ } else {
1362+ $scpath = $this->getOption('customurl_dfscat') . '_' . $subcat_id;
1363+ $query = 'SELECT catid as result FROM %s WHERE scatid = %d';
1364+ $query = sprintf($query, _C_SUBCAT_TABLE, $subcat_id);
1365+ $cid = quickQuery($query);
1366+ if (!$cid) {
1367+ return 'no_such_subcat=' . $subcat_id . '/';
1368+ }
1369+ $this->RegistPath($subcat_id, $scpath, $cid, 'subcategory', 'subcat_' . $subcat_id, TRUE);
1370+ $eachPath[] = $scpath;
1371+ }
1372+ }
1373+ }
1374+ $subcatPath = @implode('/', $eachPath);
1375+ return $subcatPath . '/';
1376+ }
1377+
1378+ function getParents($subid)
1379+ {
1380+ $mcatPlugin = $this->pluginCheck('MultipleCategories');
1381+ $mcatVarsion = $mcatPlugin->getVersion() * 100;
1382+ if (intval($mcatVarsion) < 40) {
1383+ return intval($subid);
1384+ }
1385+ $subcat_id = intval($subid);
1386+ $query = 'SELECT '
1387+ . 'scatid, '
1388+ . 'parentid '
1389+ . 'FROM %s '
1390+ . 'WHERE scatid = %d';
1391+ $query = sprintf($query, _C_SUBCAT_TABLE, $subcat_id);
1392+ $res = sql_query($query);
1393+ list($sid, $parent) = mysql_fetch_row($res);
1394+ if ($parent != 0) {
1395+ $r = $this->getParents($parent) . '/' . $sid;
1396+ } else {
1397+ $r = $sid;
1398+ }
1399+ return $r;
1400+ }
1401+
1402+ function _generateCategoryLink($cid)
1403+ {
1404+ global $CONF;
1405+ $cat_id = intval($cid);
1406+ $path = $this->getCategoryOption($cat_id, 'customurl_cname');
1407+ if ($path) {
1408+ return $path . '/';
1409+ } else {
1410+ $catData = array(
1411+ 'category',
1412+ 'catid',
1413+ $cat_id
1414+ );
1415+ if (!$this->_isValid($catData)) {
1416+ return $url = _NOT_VALID_CAT;
1417+ } else {
1418+ $cpath = $this->getOption('customurl_dfcat') . '_' . $cat_id;
1419+ $blog_id = intval(getBlogIDFromCatID($cat_id));
1420+ $catname = 'catid_' . $cat_id;
1421+ $this->RegistPath($cat_id, $cpath, $blog_id, 'category', $catname, TRUE);
1422+ return $cpath . '/';
1423+ }
1424+ }
1425+ }
1426+
1427+ function _generateBlogLink($bid)
1428+ {
1429+ global $manager, $CONF;
1430+ $blog_id = intval($bid);
1431+/*
1432+ if ($this->getBlogOption($blog_id, 'use_customurl') == 'no') {
1433+ $b =& $manager->getBlog($blog_id);
1434+ $burl = $b->getURL();
1435+ } else {
1436+ if ($blog_id == $CONF['DefaultBlog']) {
1437+ $burl = trim($CONF['IndexURL'], '/');
1438+ } else {
1439+ $query = 'SELECT burl as result '
1440+ . 'FROM %s '
1441+ . 'WHERE bnumber = %d';
1442+ $query = sprintf($query, sql_table('blog'), $blog_id);
1443+ $burl = quickQuery($query);
1444+ if ($burl) {
1445+ if (substr($burl, -4, 4) == '.php') {
1446+ $path = $this->getBlogOption($blog_id, 'customurl_bname');
1447+ if ($path) {
1448+ $burl = $CONF['IndexURL'] . $path;
1449+ } else {
1450+ $query = 'SELECT bshortname as result'
1451+ . ' FROM %s'
1452+ . ' WHERE bnumber = %d';
1453+ $query = sprintf($query, sql_table('blog'), $blog_id);
1454+ $bpath = quickQuery($query);
1455+ $this->RegistPath($blog_id, $bpath, 0, 'blog', $bpath, TRUE);
1456+ $burl = $CONF['IndexURL'] . $bpath;
1457+ }
1458+ $burl_update = 'UPDATE %s '
1459+ . 'SET burl = "%s" '
1460+ . 'WHERE bnumber = %d';
1461+ $burl = $this->quote_smart($burl);
1462+ $bTable = sql_table('blog');
1463+ sql_query(sprintf($burl_update, $bTable, $burl, $blog_id));
1464+ }
1465+ } else {
1466+ $burl = _NOT_VALID_BLOG;
1467+ }
1468+ }
1469+ }
1470+//*/
1471+ $param = array(
1472+ 'blog',
1473+ 'bnumber',
1474+ $blog_id
1475+ );
1476+ if (!$this->_isValid($param)) {
1477+ return _NOT_VALID_BLOG;
1478+ }
1479+ $b =& $manager->getBlog($blog_id);
1480+ $burl = $b->getURL();
1481+ if ($this->getBlogOption($blog_id, 'use_customurl') == 'yes') {
1482+ if ($blog_id == $CONF['DefaultBlog'] && $this->getOption('customurl_incbname') == 'no') {
1483+ if (empty($burl)) {
1484+ $this->_updateBlogURL($CONF['IndexURL'], $blog_id);
1485+ }
1486+ $burl = $CONF['IndexURL'];
1487+ } else {
1488+ if (empty($burl)) {
1489+ $burl = $CONF['IndexURL'];
1490+ }
1491+ if (substr($burl, -4) == '.php' || $burl == $CONF['IndexURL']) {
1492+ $path = $this->getBlogOption($blog_id, 'customurl_bname');
1493+ if ($path) {
1494+ $burl = $CONF['IndexURL'] . $path;
1495+ } else {
1496+ $query = 'SELECT bshortname as result'
1497+ . ' FROM %s'
1498+ . ' WHERE bnumber = %d';
1499+ $query = sprintf($query, sql_table('blog'), $blog_id);
1500+ $bpath = quickQuery($query);
1501+ $this->RegistPath($blog_id, $bpath, 0, 'blog', $bpath, TRUE);
1502+ $burl = $CONF['IndexURL'] . $bpath . '/';
1503+ }
1504+// $burl_update = 'UPDATE %s '
1505+// . 'SET burl = "%s" '
1506+// . 'WHERE bnumber = %d';
1507+// $burl = $this->quote_smart($burl);
1508+// $bTable = sql_table('blog');
1509+// sql_query(sprintf($burl_update, $bTable, $burl, $blog_id));
1510+ $this->_updateBlogURL($burl, $blog_id);
1511+ }
1512+ }
1513+ }
1514+
1515+ return trim($burl, '/');
1516+ }
1517+
1518+ function _updateBlogURL($burl, $blogid)
1519+ {
1520+ $blogid = intval($blogid);
1521+ $burl_update = 'UPDATE %s '
1522+ . 'SET burl = "%s" '
1523+ . 'WHERE bnumber = %d';
1524+ $burl = $this->quote_smart($burl);
1525+ $bTable = sql_table('blog');
1526+ sql_query(sprintf($burl_update, $bTable, $burl, $blogid));
1527+ }
1528+
1529+ function _addLinkParams($link, $params)
1530+ {
1531+ global $CONF, $manager, $catid;
1532+ $arcTmp = (preg_match('/' . $this->getOption('customurl_archives') . '/', $link));
1533+ $arcsTmp = (preg_match('/' . $this->getOption('customurl_archive') . '/', $link));
1534+ $isArchives = ($arcTmp || $arcsTmp);
1535+ $mcategories = $this->pluginCheck('MultipleCategories');
1536+ if ($mcategories) {
1537+ $mcategories->event_PreSkinParse(array());
1538+ global $subcatid;
1539+ if (method_exists($mcategories, 'getRequestName')) {
1540+ $subrequest = $mcategories->getRequestName();
1541+ } else {
1542+ $subrequest = 'subcatid';
1543+ }
1544+ }
1545+ if (is_array($params)) {
1546+ if ($params['archives']) {
1547+ $linkExtra = $this->getOption('customurl_archives') . '/';
1548+ unset($params['archives']);
1549+ } elseif ($params['archivelist']) {
1550+ $linkExtra = $this->getOption('customurl_archives') . '/';
1551+ unset($params['archivelist']);
1552+ } elseif ($params['archive']) {
1553+ sscanf($params['archive'], '%d-%d-%d', $y, $m, $d);
1554+ if ($d) {
1555+ $arc = sprintf('%04d-%02d-%02d', $y, $m, $d);
1556+ } elseif ($m) {
1557+ $arc = sprintf('%04d-%02d', $y, $m);
1558+ } else {
1559+ $arc = sprintf('%04d', $y);
1560+ }
1561+ $linkExtra = $this->getOption('customurl_archive') . '/' . $arc;
1562+ unset($params['archive']);
1563+ }
1564+ if ($params['blogid']) {
1565+ unset($params['blogid']);
1566+ }
1567+ $paramlink = array();
1568+ foreach ($params as $param => $value) {
1569+ switch ($param) {
1570+ case 'catid':
1571+ case $CONF['CategoryKey']:
1572+ $cid = intval($value);
1573+ $paramlink[] = $this->_generateCategoryLink($cid);
1574+ break;
1575+ case $subrequest:
1576+ if ($mcategories) {
1577+ $sid = intval($value);
1578+ $paramlink[] = $this->_createSubCategoryLink($sid);
1579+ }
1580+ break;
1581+ default:
1582+ $paramlink[] = $param . '/' . $value . '/';
1583+ break;
1584+ }
1585+ }
1586+ if (substr($link, -5, 5) == '.html' || $isArchives) {
1587+ $link = implode('', $paramlink) . $link;
1588+ } else {
1589+ $link .= implode('', $paramlink);
1590+ }
1591+ }
1592+ if ($linkExtra) {
1593+ $link .= $linkExtra;
1594+ }
1595+ if (requestVar('skinid')) {
1596+ $skinid = htmlspecialchars(requestVar('skinid'), ENT_QUOTES, _CHARSET);
1597+ if (!$link) {
1598+ $link = '?skinid=' . $skinid;
1599+ } elseif (strpos('?', $link)) {
1600+ $link .= '&amp;skinid=' . $skinid;
1601+ } else {
1602+ if (substr($link, -1) != '/' && !empty($link)) {
1603+ $link .= '/?skinid=' . $skinid;
1604+ } else {
1605+ $link .= '?skinid=' . $skinid;
1606+ }
1607+ }
1608+ }
1609+ if (strstr ($link, '//')) {
1610+ $link = preg_replace("/([^:])\/\//", "$1/", $link);
1611+ }
1612+ return $link;
1613+ }
1614+
1615+ function doSkinVar($skinType, $link_type = '', $target = '', $title = '')
1616+ {
1617+ global $blogid;
1618+ if ($skinType == 'item' && $link_type == 'trackback') {
1619+ global $itemid, $CONF;
1620+ if ($this->getBlogOption($blogid, 'use_customurl') == 'yes') {
1621+ $que = 'SELECT obj_name as result '
1622+ . 'FROM %s '
1623+ . 'WHERE obj_param = "item" '
1624+ . 'AND obj_id = %d';
1625+ $itempath = quickQuery(sprintf($que, _CUSTOMURL_TABLE, $itemid));
1626+ if ($target != 'ext') {
1627+ $uri = $CONF['BlogURL'] . '/trackback/' . $itempath;
1628+ } elseif ($target == 'ext') {
1629+// /item_123.trackback
1630+ $itempath = substr($itempath, 0, -5) . '.trackback';
1631+ $uri = $CONF['BlogURL'] . '/' . $itempath;
1632+ }
1633+ } else {
1634+ $uri = $CONF['ActionURL']
1635+ . '?action=plugin&amp;name=TrackBack&amp;tb_id=' . $itemid;
1636+ }
1637+ echo $uri;
1638+ return;
1639+ }
1640+ // $data == type / id || name / 'i'd || 'n'ame
1641+ // ex. => [(b)log / blogid [|| shortname / 'i'd || 'n'ame]]
1642+ // (c)at / catid [|| cname / 'i'd || 'n'ame]
1643+ // (s)cat / subcatid [|| sname / 'i'd || 'n'ame]
1644+ // [(i)tem /] itemid [/ 'path']
1645+ // (m)ember / mnumber [|| mname / 'i'd || 'n'ame]
1646+ //
1647+ // if second param is null, third param is id
1648+ // if param is null, generate blog link
1649+ if (!$link_type) {
1650+ $link_params = '0, b/' . intval($blogid) . '/i,'
1651+ . $target . ',' . $title;
1652+ } else {
1653+ $l_params = explode("/", $link_type);
1654+ if (count($l_params) == 1) {
1655+ $link_params = array(0, 'b/' . intval($link_type) . '/i,'
1656+ . $target . ',' . $title);
1657+ } else {
1658+ $link_params = array(0,
1659+ $link_type . ',' . $target . ',' . $title);
1660+ }
1661+ }
1662+ echo $this->URL_Callback($link_params);
1663+ }
1664+
1665+ function doTemplateVar(&$item, $link_type = '', $target = '', $title = '')
1666+ {
1667+ $item_id = intval($item->itemid);
1668+ if ($link_type == 'trackback') {
1669+ global $CONF;
1670+ $blog_id = intval(getBlogIDFromItemID($item_id));
1671+ if ($this->getBlogOption($blog_id, 'use_customurl') == 'yes') {
1672+ $que = 'SELECT obj_name as result '
1673+ . 'FROM %s '
1674+ . 'WHERE obj_param = "item" '
1675+ . 'AND obj_id = %d';
1676+ $itempath = quickQuery(sprintf($que, _CUSTOMURL_TABLE, $item_id));
1677+ if ($target != 'ext') {
1678+ $uri = $CONF['BlogURL'] . '/trackback/' . $itempath;
1679+ } elseif ($target == 'ext') {
1680+// /item_123.trackback
1681+ $itempath = substr($itempath, 0, -5) . '.trackback';
1682+ $uri = $CONF['BlogURL'] . '/' . $itempath;
1683+ }
1684+ } else {
1685+ $uri = $CONF['ActionURL']
1686+ . '?action=plugin&amp;name=TrackBack&amp;tb_id=' . $item_id;
1687+ }
1688+ echo $uri;
1689+ return;
1690+ }
1691+ if (!$link_type || $link_type == 'subcategory') {
1692+ $link_params = array(0,
1693+ 'i/' . $item_id . '/i,' . $target . ',' . $title);
1694+ } elseif ($link_type == 'path') {
1695+ $link_params = array(0,
1696+ 'i/' . $item_id . '/path,' . $target . ',' . $title);
1697+ } else {
1698+ $link_params = array(0,
1699+ $link_type . ',' . $target . ',' . $title);
1700+ }
1701+ if ($link_type == 'subcategory') {
1702+ echo $this->URL_Callback($link_params, 'scat');
1703+ } else {
1704+ echo $this->URL_Callback($link_params);
1705+ }
1706+ }
1707+
1708+ function URL_Callback($data, $scatFlag = '')
1709+ {
1710+ $l_data = explode(",", $data[1]);
1711+ $l_type = $l_data[0];
1712+ $target = $l_data[1];
1713+ $title = $l_data[2];
1714+ $item_id = intval($this->currentItem->itemid);
1715+ if (!$l_type) {
1716+ $link_params = array (
1717+ 'i',
1718+ $item_id,
1719+ 'i'
1720+ );
1721+ } else {
1722+ $link_data = explode("/", $l_type);
1723+ if (count($link_data) == 1) {
1724+ $link_params = array (
1725+ 'i',
1726+ intval($l_type),
1727+ 'i'
1728+ );
1729+ } elseif (count($link_data) == 2) {
1730+ if ($link_data[1] == 'path') {
1731+ $link_params = array (
1732+ 'i',
1733+ $link_data[0],
1734+ 'path'
1735+ );
1736+ } else {
1737+ $link_params = array (
1738+ $link_data[0],
1739+ intval($link_data[1]),
1740+ 'i'
1741+ );
1742+ }
1743+ } else {
1744+ $link_params = array (
1745+ $link_data[0],
1746+ $link_data[1],
1747+ $link_data[2]
1748+ );
1749+ }
1750+ }
1751+ $url = $this->_genarateObjectLink($link_params, $scatFlag);
1752+ if ($target) {
1753+ if ($title) {
1754+ $ObjLink = '<a href="' . htmlspecialchars($url) . '" '
1755+ . 'title="' . htmlspecialchars($title) . '">'
1756+ . htmlspecialchars($target) . '</a>';
1757+ } else {
1758+ $ObjLink = '<a href="' . htmlspecialchars($url) . '" '
1759+ . 'title="' . htmlspecialchars($target) . '">'
1760+ . htmlspecialchars($target) . '</a>';
1761+ }
1762+ } else {
1763+ $ObjLink = htmlspecialchars($url);
1764+ }
1765+ return $ObjLink;
1766+ }
1767+
1768+ function _isValid($data)
1769+ {
1770+ $query = 'SELECT * FROM %s WHERE %s = %d';
1771+ $data[2] = $this->quote_smart($data[2]);
1772+ $query = sprintf($query, sql_table($data[0]), $data[1], $data[2]);
1773+ $res = sql_query($query);
1774+ return (mysql_num_rows($res) != 0);
1775+ }
1776+
1777+ function _genarateObjectLink($data, $scatFlag = '')
1778+ {
1779+ global $CONF, $manager, $blog;
1780+ $ext = substr(serverVar('REQUEST_URI'), -4);
1781+ if ($ext == '.rdf' || $ext == '.xml') {
1782+ $CONF['URLMode'] = 'pathinfo';
1783+ }
1784+ if ($CONF['URLMode'] != 'pathinfo') {
1785+ return;
1786+ }
1787+ $query = 'SELECT %s as result FROM %s WHERE %s = "%s"';
1788+ switch ($data[0]) {
1789+ case 'b':
1790+ if ($data[2] == 'n') {
1791+ $bid = getBlogIDFromName($data[1]);
1792+ } else {
1793+ $bid = $data[1];
1794+ }
1795+ $blog_id = intval($bid);
1796+ $param = array(
1797+ 'blog',
1798+ 'bnumber',
1799+ $blog_id
1800+ );
1801+ if (!$this->_isValid($param)) {
1802+ $url = _NOT_VALID_BLOG;
1803+ } else {
1804+ $url = $this->_generateBlogLink($blog_id) . '/';
1805+ }
1806+ break;
1807+ case 'c':
1808+ if ($data[2] == 'n') {
1809+ $cid = getCatIDFromName($data[1]);
1810+ } else {
1811+ $cid = $data[1];
1812+ }
1813+ $cat_id = intval($cid);
1814+ $param = array(
1815+ 'category',
1816+ 'catid',
1817+ $cat_id
1818+ );
1819+ if (!$this->_isValid($param)) {
1820+ $url = _NOT_VALID_CAT;
1821+ } else {
1822+ $url = createCategoryLink($cat_id);
1823+ }
1824+ break;
1825+ case 's':
1826+ $mcategories = $this->pluginCheck('MultipleCategories');
1827+ if ($mcategories) {
1828+ if ($data[2] == 'n') {
1829+ $temp = $this->quote_smart($data[1]);
1830+ $sque = sprintf($query, 'scatid', _C_SUBCAT_TABLE, 'sname', $temp);
1831+ $scid = quickQuery($sque);
1832+ } else {
1833+ $scid = $data[1];
1834+ }
1835+ $sub_id = intval($scid);
1836+ $param = array(
1837+ 'plug_multiple_categories_sub',
1838+ 'scatid',
1839+ $sub_id
1840+ );
1841+ if (!$this->_isValid($param)) {
1842+ $url = _NOT_VALID_SUBCAT;
1843+ } else {
1844+ $cqe = sprintf($query, 'catid', _C_SUBCAT_TABLE, 'scatid', $sub_id);
1845+ $cid = quickQuery($cqe);
1846+ $cid = intval($cid);
1847+ if (method_exists($mcategories, "getRequestName")) {
1848+ $subrequest = $mcategories->getRequestName();
1849+ }
1850+ if (!$subrequest) {
1851+ $subrequest = 'subcatid';
1852+ }
1853+ $linkParam = array(
1854+ $subrequest => $sub_id
1855+ );
1856+ $url = createCategoryLink($cid, $linkParam);
1857+ }
1858+ }
1859+ break;
1860+ case 'i':
1861+ $param = array(
1862+ 'item',
1863+ 'inumber',
1864+ intval($data[1])
1865+ );
1866+ if (!$this->_isValid($param)) {
1867+ $url = _NOT_VALID_ITEM;
1868+ } else {
1869+ if ($scatFlag) {
1870+ global $catid, $subcatid;
1871+ if (!empty($catid)) {
1872+ $linkparams['catid'] = intval($catid);
1873+ }
1874+ if (!empty($subcatid)) {
1875+ $mcategories = $this->pluginCheck('MultipleCategories');
1876+ if ($mcategories) {
1877+ if (method_exists($mcategories, 'getRequestName')) {
1878+ $subrequest = $mcategories->getRequestName();
1879+ } else {
1880+ $subrequest = 'subcatid';
1881+ }
1882+ }
1883+ $linkparams[$subrequest] = intval($subcatid);
1884+ }
1885+ $url = createItemLink(intval($data[1]), $linkparams);
1886+ } else {
1887+ $blink = $this->_generateBlogLink(getBlogIDFromItemID(intval($data[1])));
1888+ $i_query = 'SELECT obj_name as result '
1889+ . 'FROM %s '
1890+ . 'WHERE obj_param = "item" '
1891+ . 'AND obj_id = %d';
1892+ $i_query = sprintf($i_query, _CUSTOMURL_TABLE, intval($data[1]));
1893+ $path = quickQuery($i_query);
1894+ if ($path) {
1895+ if ($data[2] == 'path') {
1896+ $url = $path;
1897+ } else {
1898+ $url = $blink . '/' . $path;
1899+ }
1900+ } else {
1901+ if ($data[2] == 'path') {
1902+ $url = $CONF['ItemKey'] . '/'
1903+ . intval($data[1]);
1904+ } else {
1905+ $url = $blink . '/' . $CONF['ItemKey'] . '/'
1906+ . intval($data[1]);
1907+ }
1908+ }
1909+ }
1910+ }
1911+ break;
1912+ case 'm':
1913+ if ($data[2] == 'n') {
1914+ $data[1] = $this->quote_smart($data[1]);
1915+ $mque = sprintf($query, 'mnumber', sql_table('member'), 'mname', $data[1]);
1916+ $mid = quickQuery($mque);
1917+ } else {
1918+ $mid = $data[1];
1919+ }
1920+ $member_id = intval($mid);
1921+ $param = array(
1922+ 'member',
1923+ 'mnumber',
1924+ $member_id
1925+ );
1926+ if (!$this->_isValid($param)) {
1927+ $url = _NOT_VALID_MEMBER;
1928+ } else {
1929+ $url = createMemberLink($member_id);
1930+ }
1931+ break;
1932+ }
1933+ return $url;
1934+ }
1935+
1936+ function event_InitSkinParse($data)
1937+ {
1938+ global $blogid, $CONF, $manager;
1939+ $feedurl = array(
1940+ 'rss1.xml',
1941+ 'index.rdf',
1942+ 'rss2.xml',
1943+ 'atom.xml',
1944+ );
1945+ $reqPaths = explode('/', serverVar('PATH_INFO'));
1946+ $reqPath = end($reqPaths);
1947+ $feeds = in_array($reqPath, $feedurl, true);
1948+ if (!$feeds) {
1949+ return;
1950+ } else {
1951+ $p_info = trim(serverVar('PATH_INFO'), '/');
1952+ $path_arr = explode('/', $p_info);
1953+ switch (end($path_arr)) {
1954+ case 'rss1.xml':
1955+ case 'index.rdf':
1956+ $skinName = 'feeds/rss10';
1957+ break;
1958+ case 'rss2.xml':
1959+ $skinName = 'feeds/rss20';
1960+ break;
1961+ case 'atom.xml':
1962+ $skinName = 'feeds/atom';
1963+ break;
1964+ }
1965+ if (SKIN::exists($skinName)) {
1966+ $skin =& SKIN::createFromName($skinName);
1967+ $data['skin']->SKIN($skin->getID());
1968+ $skinData =& $data['skin'];
1969+ $pageType = $data['type'];
1970+ if (!$CONF['DisableSite']) {
1971+ ob_start();
1972+
1973+ $skinID = $skinData->id;
1974+ $contents = $this->getSkinContent($pageType, $skinID);
1975+ $actions = SKIN::getAllowedActionsForType($pageType);
1976+ $dataArray = array(
1977+ 'skin' => &$skinData,
1978+ 'type' => $pageType,
1979+ 'contents' => &$contents
1980+ );
1981+ $manager->notify('PreSkinParse', $dataArray);
1982+ PARSER::setProperty('IncludeMode', SKIN::getIncludeMode());
1983+ PARSER::setProperty('IncludePrefix', SKIN::getIncludePrefix());
1984+ $handler =& new ACTIONS($pageType, $skinData);
1985+ $parser =& new PARSER($actions, $handler);
1986+ $handler->setParser($parser);
1987+ $handler->setSkin($skinData);
1988+ $parser->parse($contents);
1989+ $dataArray = array(
1990+ 'skin' => &$skinData,
1991+ 'type' => $pageType
1992+ );
1993+ $manager->notify('PostSkinParse', $dataArray);
1994+
1995+ $feed = ob_get_contents();
1996+
1997+ ob_end_clean();
1998+ $eTag = '"' . md5($feed) . '"';
1999+ header('Etag: ' . $eTag);
2000+ if ($eTag == serverVar('HTTP_IF_NONE_MATCH')) {
2001+ header('HTTP/1.0 304 Not Modified');
2002+ header('Content-Length: 0');
2003+ } else {
2004+ if (extension_loaded('mbstring')) {
2005+ $feed = mb_convert_encoding($feed, 'UTF-8', _CHARSET);
2006+ }
2007+ header('Content-Type: application/xml');
2008+ header('Generator: Nucleus CMS ' . $nucleus['version']);
2009+ // dump feed
2010+ echo $feed;
2011+ }
2012+ } else {
2013+ echo '<' . '?xml version="1.0" encoding="ISO-8859-1"?' . '>';
2014+?>
2015+<rss version="2.0">
2016+ <channel>
2017+ <title><?php echo htmlspecialchars($CONF['SiteName'], ENT_QUOTES)?></title>
2018+ <link><?php echo htmlspecialchars($CONF['IndexURL'], ENT_QUOTES)?></link>
2019+ <description></description>
2020+ <docs>http://backend.userland.com/rss</docs>
2021+ </channel>
2022+</rss>
2023+<?php
2024+ }
2025+ }
2026+ exit;
2027+ }
2028+ }
2029+
2030+ function getSkinContent($pageType, $skinID)
2031+ {
2032+ $skinID = intval($skinID);
2033+ $pageType = addslashes($pageType);
2034+ $query = 'SELECT scontent '
2035+ . 'FROM %s '
2036+ . 'WHERE sdesc = %d '
2037+ . 'AND stype = %d';
2038+ $query = sprintf($query, sql_table('skin'), $skinID, $pageType);
2039+ $res = sql_query($query);
2040+
2041+ if (mysql_num_rows($res) == 0) {
2042+ return '';
2043+ } else {
2044+ return mysql_result($res, 0, 0);
2045+ }
2046+ }
2047+
2048+
2049+// merge NP_RightURL
2050+ function event_PreSkinParse($data)
2051+ {
2052+ global $CONF, $manager, $blog, $catid, $itemid, $subcatid;
2053+ global $memberid;
2054+ if (!$blog) {
2055+ $b =& $manager->getBlog($CONF['DefaultBlog']);
2056+ } else {
2057+ $b =& $blog;
2058+ }
2059+ $blogurl = $b->getURL();
2060+
2061+ if (!$blogurl) {
2062+ if($blog) {
2063+ $b_tmp =& $manager->getBlog($CONF['DefaultBlog']);
2064+ $blogurl = $b_tmp->getURL();
2065+ }
2066+ if (!$blogurl) {
2067+ $blogurl = $CONF['IndexURL'];
2068+ if ($CONF['URLMode'] != 'pathinfo'){
2069+ if ($data['type'] == 'pageparser') {
2070+ $blogurl .= 'index.php';
2071+ } else {
2072+ $blogurl = $CONF['Self'];
2073+ }
2074+ }
2075+ }
2076+ }
2077+ if ($CONF['URLMode'] == 'pathinfo'){
2078+ if (substr($blogurl, -1) == '/') {
2079+ $blogurl = substr($blogurl, 0, -1);
2080+ }
2081+ }
2082+ $CONF['BlogURL'] = $blogurl;
2083+ $CONF['ItemURL'] = $blogurl;
2084+ $CONF['CategoryURL'] = $blogurl;
2085+ $CONF['ArchiveURL'] = $blogurl;
2086+ $CONF['ArchiveListURL'] = $blogurl;
2087+ $CONF['SearchURL'] = $blogurl;
2088+// $CONF['MemberURL'] = $blogurl;
2089+ }
2090+
2091+ function event_PreItem($data)
2092+ {
2093+ global $CONF, $manager;
2094+
2095+ $this->currentItem = &$data['item'];
2096+ $pattern = '/<%CustomURL\((.*)\)%>/';
2097+ $data['item']->body = preg_replace_callback($pattern, array(&$this, 'URL_Callback'), $data['item']->body);
2098+ if ($data['item']->more) {
2099+ $data['item']->more = preg_replace_callback($pattern, array(&$this, 'URL_Callback'), $data['item']->more);
2100+ }
2101+
2102+ $itemid = intval($data['item']->itemid);
2103+ $itemblog =& $manager->getBlog(getBlogIDFromItemID($itemid));
2104+ $blogurl = $itemblog->getURL();
2105+ if (!$blogurl) {
2106+ $b =& $manager->getBlog($CONF['DefaultBlog']);
2107+ if (!($blogurl = $b->getURL())) {
2108+ $blogurl = $CONF['IndexURL'];
2109+ if ($CONF['URLMode'] != 'pathinfo'){
2110+ if ($data['type'] == 'pageparser') {
2111+ $blogurl .= 'index.php';
2112+ } else {
2113+ $blogurl = $CONF['Self'];
2114+ }
2115+ }
2116+ }
2117+ }
2118+ if ($CONF['URLMode'] == 'pathinfo'){
2119+ if (substr($blogurl, -1) == '/') {
2120+ $blogurl = substr($blogurl, 0, -1);
2121+ }
2122+ }
2123+ $CONF['BlogURL'] = $blogurl;
2124+ $CONF['ItemURL'] = $blogurl;
2125+ $CONF['CategoryURL'] = $blogurl;
2126+ $CONF['ArchiveURL'] = $blogurl;
2127+ $CONF['ArchiveListURL'] = $blogurl;
2128+// $CONF['MemberURL'] = $blogurl;
2129+ }
2130+
2131+ function event_PostItem($data)
2132+ {
2133+ global $CONF, $manager, $blog;
2134+ if (!$blog) {
2135+ $b =& $manager->getBlog($CONF['DefaultBlog']);
2136+ } else {
2137+ $b =& $blog;
2138+ }
2139+ $blogurl = $b->getURL();
2140+ if (!$blogurl) {
2141+ if($blog) {
2142+ $b_tmp =& $manager->getBlog($CONF['DefaultBlog']);
2143+ $blogurl = $b_tmp->getURL();
2144+ }
2145+ if (!$blogurl) {
2146+ $blogurl = $CONF['IndexURL'];
2147+ if ($CONF['URLMode'] != 'pathinfo'){
2148+ if ($data['type'] == 'pageparser') {
2149+ $blogurl .= 'index.php';
2150+ } else {
2151+ $blogurl = $CONF['Self'];
2152+ }
2153+ }
2154+ }
2155+ }
2156+ if ($CONF['URLMode'] == 'pathinfo'){
2157+ if (substr($blogurl, -1) == '/') {
2158+ $blogurl = substr($blogurl, 0, -1);
2159+ }
2160+ }
2161+ $CONF['BlogURL'] = $blogurl;
2162+ $CONF['ItemURL'] = $blogurl;
2163+ $CONF['CategoryURL'] = $blogurl;
2164+ $CONF['ArchiveURL'] = $blogurl;
2165+ $CONF['ArchiveListURL'] = $blogurl;
2166+// $CONF['MemberURL'] = $CONF['Self'];
2167+ }
2168+// merge NP_RightURL end
2169+
2170+ function event_PostDeleteBlog ($data)
2171+ {
2172+ $query = 'DELETE FROM %s WHERE obj_id = %d AND obj_param = "%s"';
2173+ $pquery = 'DELETE FROM %s WHERE obj_bid = %d AND obj_param= "%s"';
2174+ $blogid = intval($data['blogid']);
2175+ sql_query(sprintf($query, _CUSTOMURL_TABLE, $blogid, 'blog'));
2176+ sql_query(sprintf($pquery, _CUSTOMURL_TABLE, $blogid, 'item'));
2177+ $cnmquery = 'SELECT catid FROM %s WHERE cblog = %d';
2178+ $table = sql_table('category');
2179+ $cnm = sql_query(sprintf($cnmquery, $table, $blogid));
2180+ while ($c = mysql_fetch_object($cnm)) {
2181+ $catid = intval($c->catid);
2182+ sql_query(sprintf($pquery, _CUSTOMURL_TABLE, $catid, 'subcategory'));
2183+ sql_query(sprintf($query, _CUSTOMURL_TABLE, $catid, 'category'));
2184+ }
2185+ }
2186+
2187+ function event_PostDeleteCategory ($data)
2188+ {
2189+ $query = 'DELETE FROM %s WHERE obj_id = %d AND obj_param = "%s"';
2190+ $squery = 'DELETE FROM %s WHERE obj_bid = %d AND obj_param = "%s"';
2191+ $catid = intval($data['catid']);
2192+ sql_query(sprintf($query, _CUSTOMURL_TABLE, $catid, 'category'));
2193+ sql_query(sprintf($squery, _CUSTOMURL_TABLE, $catid, 'subcategory'));
2194+ }
2195+
2196+ function event_PostDeleteItem ($data)
2197+ {
2198+ $query = 'DELETE FROM %s WHERE obj_id = %d AND obj_param = "%s"';
2199+ $itemid = intval($data['itemid']);
2200+ sql_query(sprintf($query, _CUSTOMURL_TABLE, $itemid, 'item'));
2201+ }
2202+
2203+ function event_PostDeleteMember ($data)
2204+ {
2205+ $query = 'DELETE FROM %s WHERE obj_id = %d AND obj_param = "%s"';
2206+ $memberid = intval($data['member']->id);
2207+ sql_query(sprintf($query, _CUSTOMURL_TABLE, $memberid, 'member'));
2208+ }
2209+
2210+ function event_PostAddBlog ($data)
2211+ {
2212+ $blog_id = intval($data['blog']->blogid);
2213+ $bshortname = $data['blog']->settings['bshortname'];
2214+ $this->RegistPath($blog_id, $bshortname, 0, 'blog', $bshortname, TRUE);
2215+ $this->setBlogOption($blog_id, 'customurl_bname', $bshortname);
2216+ }
2217+
2218+ function event_PostAddCategory ($data)
2219+ {
2220+ global $CONF;
2221+ $cat_id = intval($data['catid']);
2222+ if (!$data['blog']->blogid) {
2223+ $query = 'SELECT cblog as result FROM %s WHERE catid = %d';
2224+ $bid = quickQuery(sprintf($query, sql_table('category'), $cat_id));
2225+ } else {
2226+ $bid = $data['blog']->blogid;
2227+ }
2228+ if (!$data['name']) {
2229+ $query = 'SELECT cname as result FROM %s WHERE catid = %d';
2230+ $name = quickQuery(sprintf($query, sql_table('category'), $cat_id));
2231+ } else {
2232+ $name = $data['name'];
2233+ }
2234+ $bid = intval($bid);
2235+ $dfcat = $this->getOption('customurl_dfcat');
2236+ $catpsth = $dfcat . '_' . $cat_id;
2237+ $this->RegistPath($cat_id, $catpsth, $bid, 'category', $name, TRUE);
2238+ $this->setCategoryOption($cat_id, 'customurl_cname', $catpsth);
2239+ }
2240+
2241+ function event_PostAddItem ($data)
2242+ {
2243+ $item_id = intval($data['itemid']);
2244+ $tpath = requestVar('plug_custom_url_path');
2245+ $tque = 'SELECT itime as result FROM %s WHERE inumber = %d';
2246+ $itime = quickQuery(sprintf($tque, sql_table('item'), $item_id));
2247+ list($y, $m, $d, $trush) = sscanf($itime, '%d-%d-%d %s');
2248+ $param['year'] = sprintf('%04d', $y);
2249+ $param['month'] = sprintf('%02d', $m);
2250+ $param['day'] = sprintf('%02d', $d);
2251+ $ipath = TEMPLATE::fill($tpath, $param);
2252+ $query = 'SELECT ititle as result FROM %s WHERE inumber = %d';
2253+ $iname = quickQuery(sprintf($query, sql_table('item'), $item_id));
2254+ $blog_id = intval(getBlogIDFromItemID($item_id));
2255+ $this->RegistPath($item_id, $ipath, $blog_id, 'item', $iname, TRUE);
2256+ if ($this->pluginCheck('TrackBack')) {
2257+ $this->convertLocalTrackbackURL($data);
2258+ }
2259+ }
2260+
2261+ function event_PostRegister ($data)
2262+ {
2263+ $memberID = intval($data['member']->id);
2264+ $dispName = $data['member']->displayname;
2265+ $this->RegistPath($memberID, $dispName, 0, 'member', $dispName, TRUE);
2266+ $this->setMemberOption($memberID, 'customurl_mname', $dispName);
2267+ }
2268+
2269+ function event_AddItemFormExtras(&$data)
2270+ {
2271+ $this->createItemForm();
2272+ }
2273+
2274+ function event_EditItemFormExtras(&$data)
2275+ {
2276+ $this->createItemForm(intval($data['itemid']));
2277+ }
2278+
2279+ function event_PostUpdateItem($data)
2280+ {
2281+ $tpath = requestVar('plug_custom_url_path');
2282+ $item_id = intval($data['itemid']);
2283+ $tque = 'SELECT itime as result FROM %s WHERE inumber = %d';
2284+ $itime = quickQuery(sprintf($tque ,sql_table('item'), $item_id));
2285+ list($y, $m, $d, $trush) = sscanf($itime, '%d-%d-%d %s');
2286+ $param['year'] = sprintf('%04d', $y);
2287+ $param['month'] = sprintf('%02d', $m);
2288+ $param['day'] = sprintf('%02d', $d);
2289+ $ipath = TEMPLATE::fill($tpath, $param);
2290+ $query = 'SELECT ititle as result FROM %s WHERE inumber = %d';
2291+ $iname = quickQuery(sprintf($query, sql_table('item'), $item_id));
2292+ $blog_id = intval(getBlogIDFromItemID($item_id));
2293+ $this->RegistPath($item_id, $ipath, $blog_id, 'item', $iname);
2294+ if ($this->pluginCheck('TrackBack')) {
2295+ $this->convertLocalTrackbackURL($data);
2296+ }
2297+ }
2298+
2299+ function createItemForm($item_id = 0)
2300+ {
2301+ global $CONF;
2302+ if ($item_id) {
2303+ $query = 'SELECT obj_name as result'
2304+ . ' FROM %s'
2305+ . ' WHERE obj_param = "item"'
2306+ . ' AND obj_id = %d';
2307+ $item_id = intval($item_id);
2308+ $res = quickQuery(sprintf($query, _CUSTOMURL_TABLE, $item_id));
2309+ $ipath = substr($res, 0, strlen($res)-5);
2310+ } else {
2311+ $ipath = $this->getOption('customurl_dfitem');
2312+ }
2313+ echo <<<OUTPUT
2314+<h3>Custom URL</h3>
2315+<p>
2316+<label for="plug_custom_url">Custom Path:</label>
2317+<input id="plug_custom_url" name="plug_custom_url_path" value="{$ipath}" />
2318+</p>
2319+OUTPUT;
2320+ }
2321+
2322+ function event_PrePluginOptionsUpdate($data)
2323+ {
2324+ $blog_option = ($data['optionname'] == 'customurl_bname');
2325+ $cate_option = ($data['optionname'] == 'customurl_cname');
2326+ $memb_option = ($data['optionname'] == 'customurl_mname');
2327+ $arch_option = ($data['optionname'] == 'customurl_archive');
2328+ $arvs_option = ($data['optionname'] == 'customurl_archives');
2329+ $memd_option = ($data['optionname'] == 'customurl_member');
2330+ $contextid = intval($data['contextid']);
2331+ $context = $data['context'];
2332+ if ($blog_option || $cate_option || $memb_option) {
2333+ if ($context == 'member' ) {
2334+ $blogid = 0;
2335+ $query = 'SELECT mname as result FROM %s WHERE mnumber = %d';
2336+ $table = sql_table('member');
2337+ $name = quickQuery(sprintf($query, $table, $contextid));
2338+ } elseif (context == 'category') {
2339+ $blogid = getBlogIDFromCatID($contextid);
2340+ $query = 'SELECT cname as result FROM %s WHERE catid = %d';
2341+ $table = sql_table('category');
2342+ $name = quickQuery(sprintf($query, $table, $contextid));
2343+ } else {
2344+ $blogid = 0;
2345+ $query = 'SELECT bname as result FROM %s WHERE bnumber = %d';
2346+ $table = sql_table('blog');
2347+ $name = quickQuery(sprintf($query, $table, $contextid));
2348+ }
2349+ $blogid = intval($blogid);
2350+ $msg = $this->RegistPath($contextid, $data['value'], $blogid, $context, $name);
2351+ if ($msg) {
2352+ $this->error($msg);
2353+ exit;
2354+ }
2355+ } elseif ($arch_option || $arvs_option || $memd_option) {
2356+ if (!ereg("^[-_a-zA-Z0-9]+$", $data['value'])) {
2357+ $name = substr($data['optionname'], 8);
2358+ $msg = array (1, _INVALID_ERROR, $name, _INVALID_MSG);
2359+ $this->error($msg);
2360+ exit;
2361+ } else {
2362+ return;
2363+ }
2364+ }
2365+ return;
2366+ }
2367+
2368+ function event_PostMoveItem($data)
2369+ {
2370+ $query = 'UPDATE %s SET obj_bid = %d'
2371+ . ' WHERE obj_param = "%s" AND obj_id = %d';
2372+ $destblogid = intval($data['destblogid']);
2373+ $item_id = intval($data['itemid']);
2374+ sql_query(sprintf($query, _CUSTOMURL_TABLE, $destblogid, 'item', $item_id));
2375+ }
2376+
2377+ function event_PostMoveCategory($data)
2378+ {
2379+ $query = 'UPDATE %s SET obj_bid = %d'
2380+ . ' WHERE obj_param = "%s" AND obj_id = %d';
2381+ $destblogid = intval($data['destblog']->blogid);
2382+ $cat_id = intval($data['catid']);
2383+ sql_query(sprintf($query, _CUSTOMURL_TABLE, $destblogid, 'category', $cat_id));
2384+ $query = 'SELECT inumber FROM %s WHERE icat = %d';
2385+ $query = sprintf($query, sql_table('item'), $cat_id);
2386+ $items = sql_query($query);
2387+ while ($oItem = mysql_fetch_object($items)) {
2388+ $odata = array(
2389+ 'destblogid' => $destblogid,
2390+ 'itemid' => $oItem->inumber
2391+ );
2392+ $this->event_PostMoveItem($odata);
2393+ }
2394+ }
2395+
2396+ function RegistPath($objID, $path, $bid, $oParam, $name, $new = FALSE )
2397+ {
2398+ global $CONF;
2399+ switch($oParam) {
2400+ case 'item':
2401+ case 'member':
2402+ if (preg_match('/.html$/', $path))
2403+ $path = substr($path, 0, -5);
2404+ break;
2405+ case 'blog':
2406+ case 'category':
2407+ case 'subcategory':
2408+ break;
2409+ default :
2410+ return;
2411+ break;
2412+ }
2413+ $bid = intval($bid);
2414+ $objID = intval($objID);
2415+ $name = rawurlencode($name);
2416+
2417+ if ($new && $oParam == 'item') {
2418+ $tque = 'SELECT itime as result FROM %s WHERE inumber = %d';
2419+ $itime = quickQuery(sprintf($tque ,sql_table('item'), $objID));
2420+ list($y, $m, $d, $trush) = sscanf($itime, '%d-%d-%d %s');
2421+ $param['year'] = sprintf('%04d', $y);
2422+ $param['month'] = sprintf('%02d', $m);
2423+ $param['day'] = sprintf('%02d', $d);
2424+ $ikey = TEMPLATE::fill($template, $param);
2425+ if ($path == $ikey) {
2426+ $path = $ikey . '_' . $objID;
2427+ }
2428+ } elseif (!$new && strlen($path) == 0) {
2429+ $del_que = 'DELETE FROM %s WHERE obj_id = %d AND obj_param = "%s"';
2430+ sql_query(sprintf($del_que, _CUSTOMURL_TABLE, $objID, $oParam));
2431+ $msg = array (0, _DELETE_PATH, $name, _DELETE_MSG);
2432+ return $msg;
2433+ exit;
2434+ }
2435+
2436+ $dotslash = array ('.', '/');
2437+ $path = str_replace ($dotslash, '_', $path);
2438+ if (!ereg("^[-_a-zA-Z0-9]+$", $path)) {
2439+ $msg = array (1, _INVALID_ERROR, $name, _INVALID_MSG);
2440+ return $msg;
2441+ exit;
2442+ }
2443+
2444+ $tempPath = $path;
2445+ if ($oParam == 'item' || $oParam == 'member') $tempPath .= '.html';
2446+ $conf_que = 'SELECT obj_id FROM %s'
2447+ . ' WHERE obj_name = "%s"'
2448+ . ' AND obj_bid = %d'
2449+ . ' AND obj_param = "%s"'
2450+ . ' AND obj_id != %d';
2451+ $res = sql_query(sprintf($conf_que, _CUSTOMURL_TABLE, $tempPath, $bid, $oParam, $objID));
2452+ if ($res && mysql_num_rows($res)) {
2453+ $msg = array (0, _CONFLICT_ERROR, $name, _CONFLICT_MSG);
2454+ $path .= '_'.$objID;
2455+ }
2456+ if ($oParam == 'category' && !$msg) {
2457+ $conf_cat = 'SELECT obj_id FROM %s WHERE obj_name = "%s"'
2458+ . ' AND obj_param = "blog"';
2459+ $res = sql_query(sprintf($conf_cat, _CUSTOMURL_TABLE, $tempPath));
2460+ if ($res && mysql_num_rows($res)) {
2461+ $msg = array (0, _CONFLICT_ERROR, $name, _CONFLICT_MSG);
2462+ $path .= '_'.$objID;
2463+ }
2464+ }
2465+ if ($oParam == 'blog' && !$msg) {
2466+ $conf_blg = 'SELECT obj_id FROM %s WHERE obj_name = "%s"'
2467+ . ' AND obj_param = "category"';
2468+ $res = sql_query(sprintf($conf_blg, _CUSTOMURL_TABLE, $tempPath));
2469+ if ($res && mysql_num_rows($res)) {
2470+ $msg = array (0, _CONFLICT_ERROR, $name, _CONFLICT_MSG);
2471+ $path .= '_'.$objID;
2472+ }
2473+ }
2474+
2475+ $newPath = $path;
2476+ if ($oParam == 'item' || $oParam == 'member') $newPath .= '.html';
2477+ $query = 'SELECT * FROM %s WHERE obj_id = %d AND obj_param = "%s"';
2478+ $res = sql_query(sprintf($query, _CUSTOMURL_TABLE, $objID, $oParam));
2479+ $row = mysql_fetch_object($res);
2480+ $pathID = $row->id;
2481+ if ($pathID) {
2482+ $query = 'UPDATE %s SET obj_name = "%s" WHERE id = %d';
2483+ sql_query(sprintf($query, _CUSTOMURL_TABLE, $newPath, $pathID));
2484+ } else {
2485+ $query = 'INSERT INTO %s (obj_param, obj_name, obj_id, obj_bid)'
2486+ . ' VALUES ("%s", "%s", %d, %d)';
2487+ sql_query(sprintf($query, _CUSTOMURL_TABLE, $oParam, $newPath, $objID, $bid));
2488+ }
2489+ switch($oParam) {
2490+ case 'blog':
2491+ $this->setBlogOption($objID, 'customurl_bname', $path);
2492+ break;
2493+ case 'category':
2494+ $this->setCategoryOption($objID, 'customurl_cname', $path);
2495+ break;
2496+ case 'member':
2497+ $this->setMemberOption($objID, 'customurl_mname', $path);
2498+ break;
2499+ default :
2500+ break;
2501+ }
2502+ return $msg;
2503+ }
2504+
2505+ function error($msg = '')
2506+ {
2507+ global $admin;
2508+
2509+ $admin->pagehead();
2510+ echo $msg[1].' : '.$msg[2].'<br />';
2511+ echo $msg[3].'<br />';
2512+ echo '<a href="index.php" onclick="history.back()">'._BACK.'</a>';
2513+ $admin->pagefoot();
2514+ return;
2515+ }
2516+
2517+ function quote_smart($value)
2518+ {
2519+ if (get_magic_quotes_gpc()) $value = stripslashes($value);
2520+ if (!is_numeric($value)) {
2521+ $value = mysql_real_escape_string($value);
2522+ } elseif (is_numeric($value)) {
2523+ $value = intval($value);
2524+ }
2525+ return $value;
2526+ }
2527+
2528+ function convertLocalTrackbackURL($data)
2529+ {
2530+ global $manager, $CONF;
2531+ $ping_urls_count = 0;
2532+ $ping_urls = array();
2533+ $localflag = array();
2534+ $ping_url = requestVar('trackback_ping_url');
2535+ if (trim($ping_url)) {
2536+ $ping_urlsTemp = array();
2537+ $ping_urlsTemp = preg_split("/[\s,]+/", trim($ping_url));
2538+ for ($i = 0; $i < count($ping_urlsTemp); $i++) {
2539+ $ping_urls[] = trim($ping_urlsTemp[$i]);
2540+ $ping_urls_count++;
2541+ }
2542+ }
2543+ $tb_url_amount = intRequestVar('tb_url_amount');
2544+ for ($i=0; $i < $tb_url_amount; $i++) {
2545+ $tb_temp_url = requestVar('tb_url_' . $i);
2546+ if ($tb_temp_url) {
2547+ $ping_urls[$ping_urls_count] = $tb_temp_url;
2548+ $localflag[$ping_urls_count] = (requestVar('tb_url_' . $i . '_local') == 'on') ? 1 : 0;
2549+ $ping_urls_count++;
2550+ }
2551+ }
2552+ if ($ping_urls_count <= 0) {
2553+ return;
2554+ }
2555+ $blog_id = getBlogidFromItemID(intval($data['itemid']));
2556+ for ($i=0; $i < count($ping_urls); $i++) {
2557+ if($localflag[$i]) {
2558+ $tmp_url = parse_url($ping_urls[$i]);
2559+ $tmp_url['path'] = trim($tmp_url['path'], '/');
2560+ $path_arr = explode("/", $tmp_url['path']);
2561+ $tail = end($path_arr);
2562+ $linkObj = array (
2563+ 'linkparam' => 'item',
2564+ 'bid' => $blog_id,
2565+ );
2566+ if (substr($tail, -10) == '.trackback') {
2567+ $pathName = substr($tail, 0, -10);
2568+ if (substr($pathName, -5) == '.html') {
2569+ $linkObj['name'] = $pathName;
2570+ } else {
2571+ $linkObj['name'] = $pathName . '.html';
2572+ }
2573+ } else {
2574+ $linkObj['name'] = $tail;
2575+ }
2576+ $item_id = $this->getRequestPathInfo($linkObj);
2577+ if ($item_id) {
2578+ $ping_urls[$i] = $CONF['ActionURL']
2579+ . '?action=plugin&name=TrackBack&tb_id=' . $item_id;
2580+ }
2581+ }
2582+ }
2583+ $_REQUEST['trackback_ping_url'] = implode ("\n", $ping_urls);
2584+ }
2585+
2586+}
--- /dev/null
+++ b/NP_CustomURL/trunk/NP_CustomURL.php
@@ -0,0 +1,2586 @@
1+<?php
2+
3+if (!function_exists('htmlspecialchars_decode')) {
4+ function htmlspecialchars_decode($text)
5+ {
6+ return strtr($text, array_flip(get_html_translation_table(HTML_SPECIALCHARS)));
7+ }
8+}
9+
10+if (!defined('_CUSTOMURL_TABLE_DEFINED')) {
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'));
14+}
15+
16+class NP_CustomURL extends NucleusPlugin
17+{
18+
19+ function getMinNucleusVersion()
20+ {
21+ return '322';
22+ }
23+
24+ function getName()
25+ {
26+ return 'Customized URL';
27+ }
28+
29+ function getAuthor()
30+ {
31+ return 'shizuki';
32+ }
33+
34+ function getURL()
35+ {
36+ return 'http://japan.nucleuscms.org/wiki/plugins:customurl';
37+ }
38+
39+ function getVersion()
40+ {
41+ return '0.3.6b';
42+ }
43+
44+ function getDescription()
45+ {
46+ return _DESCRIPTION;
47+ }
48+
49+ function supportsFeature($what)
50+ {
51+ switch ($what) {
52+ case 'SqlTablePrefix':
53+ return 1;
54+ case 'HelpPage':
55+ return 1;
56+ default:
57+ return 0;
58+ }
59+ }
60+
61+ function hasAdminArea()
62+ {
63+ return 1;
64+ }
65+
66+ function event_QuickMenu(&$data)
67+ {
68+ global $member;
69+ $quickLink = ($this->getOption( 'customurl_quicklink') == 'yes');
70+ $memberCheck = ($member->isLoggedIn() && $member->isAdmin());
71+ if (!$quickLink || !$memberCheck) {
72+ return;
73+ }
74+ array_push(
75+ $data['options'],
76+ array(
77+ 'title' => _ADMIN_TITLE,
78+ 'url' => $this->getAdminURL(),
79+ 'tooltip' => _QUICK_TIPS
80+ )
81+ );
82+ }
83+
84+ function getTableList()
85+ {
86+ return array(
87+ _CUSTOMURL_TABLE
88+ );
89+ }
90+
91+ function getEventList()
92+ {
93+ return array(
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+ );
116+ }
117+
118+ function install()
119+ {
120+
121+// Can't install when faster requier Nucleus Core Version
122+ $ver_min = (getNucleusVersion() < $this->getMinNucleusVersion());
123+ $pat_min = ((getNucleusVersion() == $this->getMinNucleusVersion()) &&
124+ (getNucleusPatchLevel() < $this->getMinNucleusPatchLevel()));
125+ if ($ver_min || $pat_min) {
126+ global $DIR_LIBS;
127+ // uninstall plugin again...
128+ include_once($DIR_LIBS . 'ADMIN.php');
129+ $admin = new ADMIN();
130+ $admin->deleteOnePlugin($this->getID());
131+
132+ // ...and show error
133+ $admin->error(_ERROR_NUCLEUSVERSIONREQ .
134+ $this->getMinNucleusVersion() . ' patch ' .
135+ $this->getMinNucleusPatchLevel());
136+ }
137+
138+ global $manager, $CONF;
139+// Keys initialize
140+ if (empty($CONF['ArchiveKey'])) {
141+ $CONF['ArchiveKey'] = 'archive';
142+ }
143+ if (empty($CONF['ArchivesKey'])) {
144+ $CONF['ArchivesKey'] = 'archives';
145+ }
146+ if (empty($CONF['MemberKey'])) {
147+ $CONF['MemberKey'] = 'member';
148+ }
149+ if (empty($CONF['ItemKey'])) {
150+ $CONF['ItemKey'] = 'item';
151+ }
152+ if (empty($CONF['CategoryKey'])) {
153+ $CONF['CategoryKey'] = 'category';
154+ }
155+
156+//Plugins sort
157+ $plugTable = sql_table('plugin');
158+ $myid = intval($this->getID());
159+ $res = sql_query('SELECT pid, porder FROM ' . $plugTable);
160+ while ($p = mysql_fetch_array($res)) {
161+ $updateQuery = 'UPDATE %s '
162+ . 'SET porder = %d '
163+ . 'WHERE pid = %d';
164+ if (($pid = intval($p['pid'])) == $myid) {
165+ $q = sprintf($updateQuery, $plugTable, 1, $myid);
166+ sql_query($q);
167+ } else {
168+ $porder = intval($p['porder']);
169+ $q = sprintf($updateQuery, $plugTable, $porder + 1, $pid);
170+ sql_query($q);
171+ }
172+ }
173+
174+//create plugin's options and set default value
175+ $this->createOption('customurl_archive', _OP_ARCHIVE_DIR_NAME,
176+ 'text', $CONF['ArchiveKey']);
177+ $this->createOption('customurl_archives', _OP_ARCHIVES_DIR_NAME,
178+ 'text', $CONF['ArchivesKey']);
179+ $this->createOption('customurl_member', _OP_MEMBER_DIR_NAME,
180+ 'text', $CONF['MemberKey']);
181+ $this->createOption('customurl_dfitem', _OP_DEF_ITEM_KEY,
182+ 'text', $CONF['ItemKey']);
183+ $this->createOption('customurl_dfcat', _OP_DEF_CAT_KEY,
184+ 'text', $CONF['CategoryKey']);
185+ $this->createOption('customurl_dfscat', _OP_DEF_SCAT_KEY,
186+ 'text', 'subcategory');
187+ $this->createOption('customurl_incbname', _OP_INCLUDE_CBNAME,
188+ 'yesno', 'no');
189+ $this->createOption('customurl_tabledel', _OP_TABLE_DELETE,
190+ 'yesno', 'no');
191+ $this->createOption('customurl_quicklink', _OP_QUICK_LINK,
192+ 'yesno', 'yes');
193+ $this->createOption('customurl_notfound', _OP_NOT_FOUND,
194+ 'select', '404',
195+ '404 Not Found|404|303 See Other|303');
196+ $this->createBlogOption( 'use_customurl', _OP_USE_CURL,
197+ 'yesno', 'yes');
198+ $this->createBlogOption( 'redirect_normal', _OP_RED_NORM,
199+ 'yesno', 'yes');
200+ $this->createBlogOption( 'redirect_search', _OP_RED_SEARCH,
201+ 'yesno', 'yes');
202+ $this->createBlogOption( 'customurl_bname', _OP_BLOG_PATH,
203+ 'text');
204+// $this->createItemOption( 'customurl_iname', _OP_ITEM_PATH,
205+// 'text', $CONF['ItemKey']);
206+ $this->createMemberOption( 'customurl_mname', _OP_MEMBER_PATH,
207+ 'text');
208+ $this->createCategoryOption('customurl_cname', _OP_CATEGORY_PATH,
209+ 'text');
210+
211+ //default archive directory name
212+ $this->setOption('customurl_archive', $CONF['ArchiveKey']);
213+ //default archives directory name
214+ $this->setOption('customurl_archives', $CONF['ArchivesKey']);
215+ //default member directory name
216+ $this->setOption('customurl_member', $CONF['MemberKey']);
217+ //default itemkey_template
218+ $this->setOption('customurl_dfitem', $CONF['ItemKey']);
219+ //default categorykey_template
220+ $this->setOption('customurl_dfcat', $CONF['CategoryKey']);
221+ //default subcategorykey_template
222+ $this->setOption('customurl_dfscat', 'subcategory');
223+
224+//create data table
225+ $sql = 'CREATE TABLE IF NOT EXISTS ' . _CUSTOMURL_TABLE . ' ('
226+ . ' `id` INT(11) NOT NULL AUTO_INCREMENT PRIMARY KEY, '
227+ . ' `obj_param` VARCHAR(15) NOT NULL, '
228+ . ' `obj_name` VARCHAR(128) NOT NULL, '
229+ . ' `obj_id` INT(11) NOT NULL, '
230+ . ' `obj_bid` INT(11) NOT NULL,'
231+ . ' INDEX (`obj_name`)'
232+ . ' )';
233+ sql_query($sql);
234+
235+//setting default aliases
236+ $this->_createNewPath('blog', 'blog', 'bnumber', 'bshortname');
237+ $this->_createNewPath('item', 'item', 'inumber', 'iblog');
238+ $this->_createNewPath('category', 'category', 'catid', 'cblog');
239+ $this->_createNewPath('member', 'member', 'mnumber', 'mname');
240+
241+ if ($this->pluginCheck('MultipleCategories')) {
242+ $scatTableName = 'plug_multiple_categories_sub';
243+ $this->_createNewPath('subcategory', $scatTableName, 'scatid', 'catid');
244+ }
245+
246+ }
247+
248+ function _createNewPath($type, $n_table, $id, $bids)
249+ {
250+ $tmpTable = sql_table('plug_customurl_temp');
251+ $createQuery = 'CREATE TABLE %s '
252+ . 'SELECT obj_id, obj_param '
253+ . 'FROM %s '
254+ . 'WHERE obj_param = "%s"';
255+ sql_query(sprintf($createQuery, $tmpTable, _CUSTOMURL_TABLE, $type));
256+ $TmpQuery = 'SELECT %s, %s '
257+ . 'FROM %s as ttb '
258+ . 'LEFT JOIN %s as tcu '
259+ . 'ON ttb.%s = tcu.obj_id '
260+ . 'WHERE tcu.obj_id is null';
261+ $table = sql_table($n_table);
262+ $TmpQuery = sprintf($TmpQuery, $id, $bids, $table, $tmpTable, $id);
263+ $temp = sql_query($TmpQuery);
264+ if ($temp) {
265+ while ($row = mysql_fetch_array($temp)) {
266+ switch ($type) {
267+ case 'blog':
268+ //set access by BlogshortName/
269+ $newPath = $row[$bids];
270+ $blgid = 0;
271+ break;
272+ case 'item':
273+ //set access by (itemkey_template)_itemid.html
274+ $tque = 'SELECT '
275+ . 'itime as result '
276+ . 'FROM %s '
277+ . 'WHERE inumber = %d';
278+ $tque = sprintf($tque, $table, intval($row[$id]));
279+ $itime = quickQuery($tque);
280+ list($y, $m, $d, $trush) = sscanf($itime, '%d-%d-%d %s');
281+ $param['year'] = sprintf('%04d', $y);
282+ $param['month'] = sprintf('%02d', $m);
283+ $param['day'] = sprintf('%02d', $d);
284+ $itplt = $this->getOption('customurl_dfitem');
285+ $ikey = TEMPLATE::fill($itplt, $param);
286+ $newPath = $ikey . '_' . $row[$id] . '.html';
287+ $blgid = $row[$bids];
288+ break;
289+ case 'category':
290+ //set access by (categorykey_template)_categoryid/
291+ $newPath = $this->getOption('customurl_dfcat') . '_' . $row[$id];
292+ $blgid = $row[$bids];
293+ break;
294+ case 'member':
295+ //set access by loginName.html
296+ $newPath = $row[$bids] . '.html';
297+ $blgid = 0;
298+ break;
299+ case 'subcategory':
300+ //set access by (subcategorykey_template)_subcategoryid/
301+ $newPath = $this->getOption('customurl_dfscat') . '_' . $row[$id];
302+ $blgid = $row[$bids];
303+ break;
304+ default:
305+ break;
306+ }
307+ $insertQuery = 'INSERT INTO %s '
308+ . '(obj_param, obj_id, obj_name, obj_bid) '
309+ . 'VALUES ("%s", %d, "%s", %d)';
310+ $row[$id] = intval($row[$id]);
311+ $blgid = intval($blgid);
312+ sql_query(sprintf($insertQuery, _CUSTOMURL_TABLE, $type, $row[$id], $newPath, $blgid));
313+ }
314+ }
315+ $query = 'SELECT obj_id, obj_name '
316+ . 'FROM %s '
317+ . 'WHERE obj_param = "%s"';
318+ $temp = sql_query(sprintf($query, _CUSTOMURL_TABLE, $type));
319+ while ($row = mysql_fetch_array($temp)) {
320+ $name = $row['obj_name'];
321+ $id = intval($row['obj_id']);
322+ switch ($type) {
323+ case 'blog':
324+ $this->setBlogOption($id, 'customurl_bname', $name);
325+ break;
326+ case 'category':
327+ $this->setCategoryOption($id, 'customurl_cname', $name);
328+ break;
329+ case 'member':
330+ $obj_name = substr($name, 0, -5);
331+ $this->setMemberOption($id, 'customurl_mname', $obj_name);
332+ break;
333+ default:
334+ break;
335+ }
336+ }
337+
338+ sql_query('DROP TABLE IF EXISTS ' . $tmpTable);
339+ }
340+
341+ function init()
342+ {
343+ global $admin;
344+ $language = ereg_replace( '[\\|/]', '', getLanguageName());
345+ if (file_exists($this->getDirectory() . 'language/' . $language . '.php')) {
346+ include_once($this->getDirectory() . 'language/' . $language . '.php');
347+ } else {
348+ include_once($this->getDirectory() . 'language/english.php');
349+ }
350+ }
351+
352+ function pluginCheck($pluginName)
353+ {
354+ global $manager;
355+ if (!$manager->pluginInstalled('NP_' . $pluginName)) {
356+ return;
357+ }
358+ $plugin =& $manager->getPlugin('NP_' . $pluginName);
359+ return $plugin;
360+ }
361+
362+ function unInstall()
363+ {
364+ if ($this->getOption('customurl_tabledel') == 'yes') {
365+ sql_query("DROP TABLE "._CUSTOMURL_TABLE);
366+ }
367+ $this->deleteOption('customurl_archive');
368+ $this->deleteOption('customurl_archives');
369+ $this->deleteOption('customurl_member');
370+ $this->deleteOption('customurl_dfitem');
371+ $this->deleteOption('customurl_dfcat');
372+ $this->deleteOption('customurl_dfscat');
373+ $this->deleteOption('customurl_notfound');
374+ $this->deleteOption('customurl_tabledel');
375+ $this->deleteOption('customurl_quicklink');
376+ $this->deleteBlogOption('use_customurl');
377+ $this->deleteBlogOption('redirect_normal');
378+ $this->deleteBlogOption('redirect_search');
379+ $this->deleteBlogOption('customurl_bname');
380+// $this->deleteItemOption('customurl_iname');
381+ $this->deleteMemberOption('customurl_mname');
382+ $this->deleteCategoryOption('customurl_cname');
383+ }
384+
385+ function event_ParseURL($data)
386+ {
387+ global $CONF, $manager, $curl_blogid, $blogid, $itemid, $catid;
388+ global $memberid, $archivelist, $archive, $query;
389+// initialize
390+ $info = $data['info'];
391+ $complete =& $data['complete'];
392+ if ($complete) {
393+ return;
394+ }
395+ $useCustomURL = $this->getAllBlogOptions('use_customurl');
396+
397+// Use NP_MultipleCategories ?
398+ $mcategories = $this->pluginCheck('MultipleCategories');
399+ if ($mcategories) {
400+ $mcategories->event_PreSkinParse(array());
401+ global $subcatid;
402+ if (method_exists($mcategories, 'getRequestName')) {
403+ $subrequest = $mcategories->getRequestName();
404+ } else {
405+ $subrequest = 'subcatid';
406+ }
407+ }
408+
409+// initialize and sanitize '$blogid'
410+ if (!$blogid) {
411+ if ( getVar('blogid') ) {
412+ if ( is_numeric(getVar('blogid')) ) {
413+ $blogid = intval(getVar('blogid'));
414+ } else {
415+ $blogid = intval(getBlogIDFromName(getVar('blogid')));
416+ }
417+ } elseif ($curl_blogid) {
418+ $blogid = intval($curl_blogid);
419+ } else {
420+ $blogid = $CONF['DefaultBlog'];
421+ }
422+ } else {
423+ if (is_numeric($blogid)) {
424+ $blogid = intval($blogid);
425+ } else {
426+ $blogid = intval(getBlogIDFromName($blogid));
427+ }
428+ }
429+
430+ if (!$info) {
431+ if (serverVar('PATH_INFO')) {
432+ $info = serverVar('PATH_INFO');
433+ } elseif (getNucleusVersion() < 330) {
434+ if (getVar('virtualpath')) {
435+ $info = getVar('virtualpath');
436+ }
437+ } else {
438+ return;
439+ }
440+ }
441+
442+// Sanitize 'PATH_INFO'
443+ $info = trim($info, '/');
444+ $v_path = explode("/", $info);
445+ foreach($v_path as $key => $value) {
446+ $value = urlencode($value);
447+ $value = preg_replace('|[^a-zA-Z0-9-~+_.?#=&;,/:@%]|i', '', $value);
448+ $v_path[$key] = $value;
449+ }
450+ if (phpversion() >= '4.1.0') {
451+ $_SERVER['PATH_INFO'] = implode('/', $v_path);
452+ }
453+ global $HTTP_SERVER_VARS;
454+ $HTTP_SERVER_VARS['PATH_INFO'] = implode('/', $v_path);
455+
456+// Admin area check
457+ $tmpURL = sprintf("%s%s%s", "http://", serverVar("HTTP_HOST"), serverVar("SCRIPT_NAME"));
458+ $uri = str_replace('/', '\/', $tmpURL);
459+ $plug_url = str_replace('/', '\/', $CONF['PluginURL']);
460+ $u_plugAction = (getVar('action') == 'plugin' && getVar('name'));
461+ if (strpos($uri, $plug_url) === 0 || $u_plugAction) {
462+ $UsingPlugAdmin = TRUE;
463+ }
464+
465+// redirect to other URL style
466+ $useCustomURLyes = ($useCustomURL[$blogid] == 'yes');
467+ if ($useCustomURLyes && !$UsingPlugAdmin && !$CONF['UsingAdminArea']) {
468+// Search query redirection
469+// 301 permanent ? or 302 temporary ?
470+ $queryURL = (strpos(serverVar('REQUEST_URI'), 'query=') !== FALSE);
471+ $search_q = (getVar('query') || $queryURL);
472+ $redirectSerch = ($this->getBlogOption($blogid, 'redirect_search') == 'yes');
473+ if ($redirectSerch) {
474+ if ($search_q) {
475+ $que_str = getVar('query');
476+ $que_str = htmlspecialchars($que_str);
477+ if (extension_loaded('mbstring')) {
478+ $que_str = mb_eregi_replace('/', 'ssslllaaassshhh', $que_str);
479+ $que_str = mb_eregi_replace("'", 'qqquuuooottt', $que_str);
480+ $que_str = mb_eregi_replace('&', 'aaammmppp', $que_str);
481+ } else {
482+ $que_str = eregi_replace('/', 'ssslllaaassshhh', $que_str);
483+ $que_str = eregi_replace("'", 'qqquuuooottt', $que_str);
484+ $que_str = eregi_replace('&', 'aaammmppp', $que_str);
485+ }
486+ $que_str = urlencode($que_str);
487+ $search_path = '/search/' . $que_str;
488+ $b_url = createBlogidLink($blogid);
489+ $redurl = sprintf("%s%s", $b_url, $search_path);
490+ redirect($redurl); // 302 Moved temporary
491+ exit;
492+ }
493+ }
494+ if (!$redirectSerch && $search_q) {
495+ $exLink = TRUE;
496+ }
497+
498+// redirection nomal URL to FancyURL
499+ $temp_req = explode('?', serverVar('REQUEST_URI'));
500+ $reqPath = trim(end($temp_req), '/');
501+ $indexrdf = ($reqPath == 'xml-rss1.php');
502+ $atomfeed = ($reqPath == 'atom.php');
503+ $rss2feed = ($reqPath == 'xml-rss2.php');
504+ $feeds = ($indexrdf || $atomfeed || $rss2feed);
505+ $redirectNormal = ($this->getBlogOption($blogid, 'redirect_normal') == 'yes');
506+ if ($redirectNormal && serverVar('QUERY_STRING') && !$feeds && !$exLink) {
507+ $temp = explode('&', serverVar('QUERY_STRING'));
508+ foreach ($temp as $k => $val) {
509+ if (preg_match('/^virtualpath/', $val)) {
510+ unset($temp[$k]);
511+ }
512+ }
513+ if (!empty($temp)) {
514+ $p_arr = array();
515+ foreach ($temp as $key => $value) {
516+ $p_key = explode('=', $value);
517+ switch (reset($p_key)) {
518+ case 'blogid';
519+ $p_arr[] = $CONF['BlogKey'] . '/'
520+ . intGetVar('blogid');
521+ unset($temp[$key]);
522+ break;
523+ case 'catid';
524+ $p_arr[] = $CONF['CategoryKey'] . '/'
525+ . intGetVar('catid');
526+ unset($temp[$key]);
527+ break;
528+ case $subrequest;
529+ $p_arr[] = $subrequest . '/'
530+ . intGetVar($subrequest);
531+ unset($temp[$key]);
532+ break;
533+ case 'itemid';
534+ $p_arr[] = $CONF['ItemKey'] . '/'
535+ . intGetVar('itemid');
536+ unset($temp[$key]);
537+ break;
538+ case 'memberid';
539+ $p_arr[] = $CONF['MemberKey'] . '/'
540+ . intGetVar('memberid');
541+ unset($temp[$key]);
542+ break;
543+ case 'archivelist';
544+ $p_arr[] = $CONF['ArchivesKey'] . '/'
545+ . $blogid;
546+ unset($temp[$key]);
547+ break;
548+ case 'archive';
549+ $p_arr[] = $CONF['ArchiveKey'] . '/'
550+ . $blogid . '/' . getVar('archive');
551+ unset($temp[$key]);
552+ break;
553+ default:
554+ break;
555+ }
556+ }
557+ if (!empty($temp)) {
558+ $queryTemp = '/?' . implode('&', $temp);
559+ }
560+ if (reset($p_arr)) {
561+ $b_url = createBlogidLink($blogid);
562+ $red_path = '/' . implode('/', $p_arr);
563+ if (substr($b_url, -1) == '/') {
564+ $b_url = rtrim($b_url, '/');
565+ }
566+ $redurl = sprintf("%s%s", $b_url, $red_path) . $queryTemp;
567+ // HTTP status 301 "Moved Permanentry"
568+ header('HTTP/1.1 301 Moved Permanently');
569+ header('Location: ' . $redurl);
570+ exit;
571+ }
572+ }
573+ } elseif ($redirectNormal && $feeds) {
574+ $b_url = rtrim(createBlogidLink($blogid), '/');
575+ switch ($reqPath) {
576+ case 'xml-rss1.php':
577+ $feed_code = '/index.rdf';
578+ break;
579+ case 'xml-rss2.php':
580+ $feed_code = '/rss2.xml';
581+ break;
582+ case 'atom.php':
583+ $feed_code = '/atom.xml';
584+ break;
585+ default:
586+ break;
587+ }
588+ // HTTP status 301 "Moved Permanentry"
589+ header('HTTP/1.1 301 Moved Permanently');
590+ header('Location: ' . $b_url . $feed_code);
591+ exit;
592+ }
593+ }
594+// decode path_info
595+
596+// decode unofficial Page switch '/page_2.html'
597+/* foreach($v_path as $pathName) {
598+ if (preg_match('/^page_/', $pathName)) {
599+ $temp_info = explode('page_', $pathName);
600+ $_GET['page'] = intval($temp_info[1]);
601+ $page = array_pop($v_path);
602+ }
603+ }*/
604+
605+// decode TrackBack URL shorten ver.
606+ $tail = end($v_path);
607+ if (substr($tail, -10, 10) == '.trackback') {
608+ $v_pathName = substr($tail, 0, -10);
609+ if (is_numeric($v_pathName) || substr($v_pathName, -5) == '.html') {
610+ $this->_trackback($blogid, $v_pathName);
611+ } else {
612+ $this->_trackback($blogid, $v_pathName . '.html');
613+ }
614+ return;
615+ }
616+
617+// decode other type URL
618+ $bLink = $cLink = $iLink = $exLink = FALSE;
619+ if (empty($info)) {
620+ $bLink = TRUE;
621+ }
622+ $linkObj = array (
623+ 'bid' => 0,
624+ 'name' => reset($v_path),
625+ 'linkparam' => 'blog'
626+ );
627+ $blog_id = $this->getRequestPathInfo($linkObj);
628+ if ($blog_id) {
629+ $blogid = $blog_id;
630+ $trush = array_shift($v_path);
631+ $bLink = TURE;
632+ }
633+ if ($useCustomURL[$blogid] == 'no') {
634+ return;
635+ }
636+ $i = 1;
637+ foreach($v_path as $pathName) {
638+ switch ($pathName) {
639+// decode FancyURLs and redirection to Customized URL
640+ // for blogsgetAllBlogOptions($name)
641+ case $CONF['BlogKey']:
642+ if (isset($v_path[$i]) && is_numeric($v_path[$i])) {
643+ if ($useCustomURL[intval($v_path[$i])] != 'yes') {
644+ $blogid = intval($v_path[$i]);
645+ $bLink = TRUE;
646+ } else {
647+ $redURI = createBlogidLink(intval($v_path[$i]));
648+ }
649+ }
650+ break;
651+ // for items
652+ case $CONF['ItemKey']:
653+ if (isset($v_path[$i]) && is_numeric($v_path[$i])) {
654+ if ($useCustomURL[$blogid] != 'yes') {
655+ $itemid = intval($v_path[$i]);
656+ $iLink = TRUE;
657+ } else {
658+ $redURI = createItemLink(intval($v_path[$i]));
659+ }
660+ }
661+ break;
662+ // for categories
663+ case $CONF['CategoryKey']:
664+ case 'catid':
665+ if (isset($v_path[$i]) && is_numeric($v_path[$i])) {
666+ if ($useCustomURL[$blogid] != 'yes') {
667+ $catid = intval($v_path[$i]);
668+ $cLink = TRUE;
669+ } else {
670+ $redURI = createCategoryLink(intval($v_path[$i]));
671+ }
672+ }
673+ break;
674+ // for subcategories
675+ case $subrequest:
676+ $c = $i - 2;
677+ $subCat = (isset($v_path[$i]) && is_numeric($v_path[$i]));
678+ if ($mcategories && $subCat && $i >= 3 && is_numeric($v_path[$c])) {
679+ if ($useCustomURL[$blogid] != 'yes') {
680+ $subcatid = intval($v_path[$i]);
681+ $catid = intval($v_path[$c]);
682+ $cLink = TRUE;
683+ } else {
684+ $subcat_id = intval($v_path[$i]);
685+ $catid = intval($v_path[$c]);
686+ $linkParam = array($subrequest => $subcat_id);
687+ $redURI = createCategoryLink($catid, $linkParam);
688+ }
689+ }
690+ break;
691+ // for archives
692+ case $CONF['ArchivesKey']:
693+ case $this->getOption('customurl_archives'):
694+ // FancyURL
695+ if (isset($v_path[$i]) && is_numeric($v_path[$i])) {
696+ if ($useCustomURL[intval($v_path[$i])] != 'yes') {
697+ $archivelist = intval($v_path[$i]);
698+ $blogid = $archivelist;
699+ $exLink = TRUE;
700+ } else {
701+ $redURI = createArchiveListLink(intval($v_path[$i]));
702+ }
703+ // Customized URL
704+ } elseif (isset($v_path[$i]) && strpos($v_path[$i], 'page') === FALSE) {
705+ $archivelist = $blogid;
706+ $redURI = createArchiveListLink($archivelist);
707+ } else {
708+ $archivelist = $blogid;
709+ $exLink = TRUE;
710+ }
711+ break;
712+ // for archive
713+ case $CONF['ArchiveKey']:
714+ case $this->getOption('customurl_archive'):
715+ $y = $m = $d = '';
716+ $ar = $i + 1;
717+ if (isset($v_path[$i])) {
718+ $darc = (ereg('([0-9]{4})-([0-9]{1,2})-([0-9]{1,2})', $v_path[$i]));
719+ $marc = (ereg('([0-9]{4})-([0-9]{1,2})', $v_path[$i]));
720+ $yarc = (ereg('([0-9]{4})', $v_path[$i]));
721+ $adarc = (ereg('([0-9]{4})-([0-9]{1,2})-([0-9]{1,2})', $v_path[$ar]));
722+ $amarc = (ereg('([0-9]{4})-([0-9]{1,2})', $v_path[$ar]));
723+ $ayarc = (ereg('([0-9]{4})', $v_path[$ar]));
724+ $arc = (!$darc && !$marc && !$yarc);
725+ $aarc = ($adarc || $amarc || $ayarc);
726+ $carc = ($darc || $marc || $yarc);
727+ // FancyURL
728+ if (is_numeric($v_path[$i]) && $arc && isset($v_path[$ar]) && $aarc) {
729+ sscanf($v_path[$ar], '%d-%d-%d', $y, $m, $d);
730+ if (!empty($d)) {
731+ $archive = sprintf('%04d-%02d-%02d', $y, $m, $d);
732+ } elseif (!empty($m)) {
733+ $archive = sprintf('%04d-%02d', $y, $m);
734+ } else {
735+ $archive = sprintf('%04d', $y);
736+ }
737+ if ($useCustomURL[intval($v_path[$i])] != 'yes') {
738+ $blogid = intval($v_path[$i]);
739+ $exLink = TRUE;
740+ } else {
741+ $blogid = intval($v_path[$i]);
742+ $redURI = createArchiveLink($blogid, $archive);
743+ }
744+ // Customized URL
745+ } elseif ($carc) {
746+ sscanf($v_path[$i], '%d-%d-%d', $y, $m, $d);
747+ if (!empty($d)) {
748+ $archive = sprintf('%04d-%02d-%02d', $y, $m, $d);
749+ } elseif (!empty($m)) {
750+ $archive = sprintf('%04d-%02d', $y, $m);
751+ } else {
752+ $archive = sprintf('%04d', $y);
753+ }
754+ $exLink = TRUE;
755+ } else {
756+ $redURI = createArchiveListLink($blogid);
757+ }
758+ } else {
759+ $redURI = createArchiveListLink($blogid);
760+ }
761+ break;
762+ // for member
763+ case $CONF['MemberKey']:
764+ case $this->getOption('customurl_member'):
765+ // Customized URL
766+ $customMemberURL = (substr($v_path[$i], -5, 5) == '.html');
767+ if (isset($v_path[$i]) && $customMemberURL) {
768+ $memberInfo = array(
769+ 'linkparam' => 'member',
770+ 'bid' => 0,
771+ 'name' => $v_path[$i]
772+ );
773+ $member_id = $this->getRequestPathInfo($memberInfo);
774+ $memberid = intval($member_id);
775+ $exLink = TRUE;
776+ // FancyURL
777+ } elseif (isset($v_path[$i]) && is_numeric($v_path[$i])) {
778+ if ($useCustomURL[$blogid] != 'yes') {
779+ $memberid = intval($v_path[$i]);
780+ $exLink = TRUE;
781+ } else {
782+ $redURI = createMemberLink(intval($v_path[$i]));
783+ }
784+ } else {
785+ $redURI = createBlogidLink($blogid);
786+ }
787+ break;
788+ // for tag
789+ case 'tag':
790+// if (isset($v_path[$i]) && is_string($v_path[$i])) {
791+// $_REQUEST['tag'] = $v_path[$i];
792+ $exLink = TRUE;
793+// }
794+ break;
795+ // for ExtraSkinJP
796+ case 'extra':
797+ $ExtraSkinJP = $this->pluginCheck('ExtraSkinJP');
798+ if ($ExtraSkinJP) {
799+ // under v3.2 needs this
800+ if ($CONF['DisableSite'] && !$member->isAdmin()) {
801+ header('Location: ' . $CONF['DisableSiteURL']);
802+ exit;
803+ }
804+ $extraParams = explode("/", serverVar('PATH_INFO'));
805+ array_shift ($extraParams);
806+
807+ if (isset($extraParams[1]) && preg_match("/^([1-9]+[0-9]*)(\?.*)?$/", $extraParams[1], $matches)) {
808+ $extraParams[1] = $matches[1];
809+ }
810+
811+ $ExtraSkinJP->extra_selector($extraParams);
812+ exit;
813+ }
814+ break;
815+ // for search query
816+ case 'search':
817+ $redirectSerch = ($this->getBlogOption($blogid, 'redirect_search') == 'yes');
818+ if ($redirectSerch) {
819+ $que_str = urldecode($v_path[$i]);
820+ if (extension_loaded('mbstring')) {
821+ $que_str = mb_eregi_replace('ssslllaaassshhh', '/', $que_str);
822+ $que_str = mb_eregi_replace('qqquuuooottt', "'", $que_str);
823+ $que_str = mb_eregi_replace('aaammmppp', '&', $que_str);
824+ } else {
825+ $que_str = eregi_replace('ssslllaaassshhh', '/', $que_str);
826+ $que_str = eregi_replace('qqquuuooottt', "'", $que_str);
827+ $que_str = eregi_replace('aaammmppp', '&', $que_str);
828+ }
829+ $que_str = htmlspecialchars_decode($que_str);
830+ $_GET['query'] = $que_str;
831+ $query = $que_str;
832+ $exLink = TRUE;
833+ }
834+ break;
835+ // for pageswitch
836+ case 'page':
837+// if (isset($v_path[$i]) && is_numeric($v_path[$i])) {
838+// $_GET['page'] = intval($v_path[$i]);
839+ $exLink = TRUE;
840+// }
841+ break;
842+ // for tDiarySkin
843+ case 'tdiarydate':
844+ case 'categorylist':
845+ case 'monthlimit':
846+ $tDiaryPlugin = $this->pluginCheck('tDiarySkin');
847+ if ($tDiaryPlugin && isset($v_path[$i])) {
848+ $_GET[$pathName] = $v_path[$i];
849+ $exLink = TRUE;
850+ }
851+ break;
852+ case 'special':
853+ if (isset($v_path[$i]) && is_string($v_path[$i])) {
854+ $_REQUEST['special'] = $v_path[$i];
855+ $exLink = TRUE;
856+ }
857+ break;
858+ // for trackback
859+ case 'trackback':
860+ if (isset($v_path[$i]) && is_string($v_path[$i])) {
861+ $this->_trackback($blogid, $v_path[$i]);
862+ }
863+ return;
864+ break;
865+
866+// decode Customized URL
867+ default:
868+ // initialyze
869+ $linkObj = array (
870+ 'bid' => $blogid,
871+ 'name' => $pathName
872+ );
873+ $comp = FALSE;
874+ $isItem = (substr($pathName, -5) == '.html');
875+ // category ?
876+ if (!$comp && !$cLink && !$iLink && !$isItem) {
877+ $linkObj['linkparam'] = 'category';
878+ $cat_id = $this->getRequestPathInfo($linkObj);
879+ if (!empty($cat_id)) {
880+ $catid = intval($cat_id);
881+ $cLink = TURE;
882+ $comp = TRUE;
883+ }
884+ }
885+ // subcategory ?
886+ if (!$comp && $cLink && !$iLink && $mcategories && !$isItem) {
887+ $linkObj['linkparam'] = 'subcategory';
888+ $linkObj['bid'] = $catid;
889+ $subcat_id = $this->getRequestPathInfo($linkObj);
890+ if (!empty($subcat_id)) {
891+ $_REQUEST[$subrequest] = intval($subcat_id);
892+ $subcatid = intval($subcat_id);
893+ $sc = $i;
894+ $comp = TRUE;
895+ }
896+ }
897+ // item ?
898+ if ($isItem) {
899+ $linkObj['linkparam'] = 'item';
900+ $item_id = $this->getRequestPathInfo($linkObj);
901+ if (!empty($item_id)) {
902+ $itemid = intval($item_id);
903+ $iLink = TRUE;
904+ }
905+ if (preg_match('/^page_/', $pathName)) {
906+ $iLink = TRUE;
907+ }
908+//var_dump($linkObj);
909+ }
910+ break;
911+ }
912+ if (preg_match('/^[0-9page]$/', $pathName)) {
913+ $exLink = $pathName;
914+ }
915+ $i++;
916+ }
917+
918+// FancyURL redirect to Customized URL if use it
919+// HTTP status 301 "Moved Permanentry"
920+ if ($redURI) {
921+ if (strpos(serverVar('REQUEST_URI'), '?') !== FALSE) {
922+ list($trush, $tempQueryString) = explode('?', serverVar('REQUEST_URI'), 2);
923+ }
924+ $tempQueryString = '?' . $tempQueryString;
925+ header('HTTP/1.1 301 Moved Permanently');
926+ header('Location: ' . $redURI . $tempQueryString);
927+ exit;
928+ }
929+ $feedurl = array(
930+ 'rss1.xml',
931+ 'index.rdf',
932+ 'rss2.xml',
933+ 'atom.xml',
934+ );
935+ $siteMapPlugin = $this->pluginCheck('GoogleSitemap');
936+ if (!$siteMapPlugin) {
937+ $siteMapPlugin = $this->pluginCheck('SEOSitemaps');
938+ }
939+ if ($siteMapPlugin) {
940+ $pcSitemaps = $siteMapPlugin->getAllBlogOptions('PcSitemap');
941+ foreach ($pcSitemaps as $pCsitemap) {
942+ if ($pCsitemap) {
943+ $feedurl[] = $pCsitemap;
944+ }
945+ }
946+ $mobSitemaps = $siteMapPlugin->getAllBlogOptions('MobileSitemap');
947+ foreach ($mobSitemaps as $mobSitemap) {
948+ if ($mobSitemap) {
949+ $feedurl[] = $mobSitemap;
950+ }
951+ }
952+ }
953+ $feedurl = array_unique($feedurl);
954+ $request_path = end($v_path);
955+ $feeds = in_array($request_path, $feedurl, true);
956+
957+// finish decode
958+ if (!$exLink && !$feeds) {
959+// URL Not Found
960+ if (substr(end($v_path), -5) == '.html' && !$iLink) {
961+ $notFound = TRUE;
962+ if (!empty($subcatid)) {
963+ $linkParam = array(
964+ $subrequest => $subcatid
965+ );
966+ $uri = createCategoryLink($catid, $linkParam);
967+ } elseif (!empty($catid)) {
968+ $uri = createCategoryLink($catid);
969+ } else {
970+ $uri = createBlogidLink($blogid);
971+ }
972+ } elseif (count($v_path) > $sc && !empty($subcatid) && !$iLink) {
973+ $notFound = TRUE;
974+ $linkParam = array(
975+ $subrequest => $subcatid
976+ );
977+ $uri = createCategoryLink($catid, $linkParam);
978+ } elseif (count($v_path) >= 2 && !$subcatid && !$iLink) {
979+ $notFound = TRUE;
980+ if (isset($catid)) {
981+ $uri = createCategoryLink($catid);
982+ } else {
983+ $uri = createBlogidLink($blogid);
984+ }
985+ } elseif (reset($v_path) && !$catid && !$subcatid && !$iLink) {
986+ $notFound = TRUE;
987+ $uri = createBlogidLink($blogid);
988+ } else {
989+// Found
990+// setting $CONF['Self'] for other plugins
991+ $uri = createBlogidLink($blogid);
992+ $CONF['Self'] = rtrim($uri, '/');
993+ $CONF['BlogURL'] = rtrim($uri, '/');
994+ $CONF['ItemURL'] = rtrim($uri, '/');
995+ $CONF['CategoryURL'] = rtrim($uri, '/');
996+ $CONF['ArchiveURL'] = rtrim($uri, '/');
997+ $CONF['ArchiveListURL'] = rtrim($uri, '/');
998+ $complete = TRUE;
999+ return ;
1000+ }
1001+ } else {
1002+ $uri = createBlogidLink($blogid);
1003+ $CONF['Self'] = rtrim($uri, '/');
1004+ $CONF['BlogURL'] = rtrim($uri, '/');
1005+ $CONF['ItemURL'] = rtrim($uri, '/');
1006+ $CONF['CategoryURL'] = rtrim($uri, '/');
1007+ $CONF['ArchiveURL'] = rtrim($uri, '/');
1008+ $CONF['ArchiveListURL'] = rtrim($uri, '/');
1009+ $complete = TRUE;
1010+ return ;
1011+ }
1012+// Behavior Not Found
1013+ if ($notFound) {
1014+ if (substr($uri, -1) != '/') {
1015+ $uri .= '/';
1016+ }
1017+ if ($this->getOption('customurl_notfound') == '404') {
1018+ header('HTTP/1.1 404 Not Found');
1019+ doError(_NO_SUCH_URI);
1020+ exit;
1021+ } else {
1022+ header('HTTP/1.1 303 See Other');
1023+ header('Location: ' . $uri);
1024+ exit;
1025+ }
1026+ }
1027+ }
1028+
1029+// decode 'path name' to 'id'
1030+ function getRequestPathInfo($linkObj)
1031+ {
1032+ $query = 'SELECT obj_id as result'
1033+ . ' FROM %s'
1034+ . ' WHERE obj_name = "%s"'
1035+ . ' AND obj_bid = %d'
1036+ . ' AND obj_param = "%s"';
1037+ $name = $this->quote_smart($linkObj['name']);
1038+ $bid = $this->quote_smart($linkObj['bid']);
1039+ $linkparam = $this->quote_smart($linkObj['linkparam']);
1040+ $query = sprintf($query, _CUSTOMURL_TABLE, $name, $bid, $linkparam);
1041+ $ObjID = quickQuery($query);
1042+ if (!$ObjID) {
1043+ return;
1044+ } else {
1045+ return intval($ObjID);
1046+ }
1047+ }
1048+
1049+// Receive TrackBack ping
1050+ function _trackback($bid, $path)
1051+ {
1052+ $blog_id = intval($bid);
1053+ $TrackBack = $this->pluginCheck('TrackBack');
1054+ if ($TrackBack) {
1055+ if (substr($path, -5, 5) == '.html') {
1056+ $linkObj = array (
1057+ 'linkparam' => 'item',
1058+ 'bid' => $blog_id,
1059+ 'name' => $path
1060+ );
1061+ $item_id = $this->getRequestPathInfo($linkObj);
1062+ if ($item_id) {
1063+ $tb_id = intval($item_id);
1064+ } else {
1065+ doError(_NO_SUCH_URI);
1066+ }
1067+ } else {
1068+ $tb_id = intval($path);
1069+ }
1070+
1071+ $errorMsg = $TrackBack->handlePing($tb_id);
1072+ if ($errorMsg != '') {
1073+ $TrackBack->xmlResponse($errorMsg);
1074+ } else {
1075+ $TrackBack->xmlResponse();
1076+ }
1077+ }
1078+ exit;
1079+ }
1080+
1081+ function event_GenerateURL($data)
1082+ {
1083+ global $CONF, $manager, $blogid;
1084+ if ($data['completed']) {
1085+ return;
1086+ }
1087+ if (is_numeric($blogid)) {
1088+ $blogid = intval($blogid);
1089+ } else {
1090+ $blogid = intval(getBlogIDFromName($blogid));
1091+ }
1092+ $mcategories = $this->pluginCheck('MultipleCategories');
1093+ if ($mcategories) {
1094+ if (method_exists($mcategories, 'getRequestName')) {
1095+ $mcategories->event_PreSkinParse(array());
1096+ global $subcatid;
1097+ $subrequest = $mcategories->getRequestName();
1098+ }
1099+ }
1100+ if ($subcatid) {
1101+ $subcatid = intval($subcatid);
1102+ }
1103+ $OP_ArchiveKey = $this->getOption('customurl_archive');
1104+ $OP_ArchivesKey = $this->getOption('customurl_archives');
1105+ $OP_MemberKey = $this->getOption('customurl_member');
1106+ $params = $data['params'];
1107+ $catParam = $params['extra']['catid'];
1108+ $subcatParam = $params['extra'][$subrequest];
1109+ $useCustomURL = $this->getAllBlogOptions('use_customurl');
1110+ switch ($data['type']) {
1111+ case 'item':
1112+ if (!is_numeric($params['itemid'])) {
1113+ return;
1114+ }
1115+ $item_id = intval($params['itemid']);
1116+ $bid = intval(getBlogIDFromItemID($item_id));
1117+ if ($useCustomURL[$bid] == 'no') {
1118+ return;
1119+ }
1120+ $query = 'SELECT obj_name as result '
1121+ . 'FROM %s '
1122+ . 'WHERE obj_param = "item" '
1123+ . 'AND obj_id = %d';
1124+ $path = quickQuery(sprintf($query, _CUSTOMURL_TABLE, $item_id));
1125+ if ($path) {
1126+ $objPath = $path;
1127+ } else {
1128+ if (!$this->_isValid(array('item', 'inumber', $item_id))) {
1129+ $objPath = _NOT_VALID_ITEM;
1130+ } else {
1131+ $y = $m = $d = $temp = '';
1132+ $table = sql_table('item');
1133+ $tque = 'SELECT itime as result '
1134+ . 'FROM %s '
1135+ . 'WHERE inumber = %d';
1136+ $itime = quickQuery(sprintf($tque ,$table, $item_id));
1137+ sscanf($itime,'%d-%d-%d %s', $y, $m, $d, $temp);
1138+ $defItem = $this->getOption('customurl_dfitem');
1139+ $tempParam = array(
1140+ 'year' => $Y,
1141+ 'month' => $m,
1142+ 'day' => $d
1143+ );
1144+ $ikey = TEMPLATE::fill($defItem, $tempParam);
1145+ $ipath = $ikey . '_' . $item_id;
1146+ $query = 'SELECT ititle as result '
1147+ . 'FROM %s '
1148+ . 'WHERE inumber = %d';
1149+ $query = sprintf($query, $table, $item_id);
1150+ $iname = quickQuery($query);
1151+ $this->RegistPath($item_id, $ipath, $bid, 'item', $iname, TRUE);
1152+ $objPath = $ipath . '.html';
1153+ }
1154+ }
1155+ if ($bid != $blogid) {
1156+ $burl = $this->_generateBlogLink($bid);
1157+ } else {
1158+ $burl = $this->_generateBlogLink($blogid);
1159+ }
1160+ break;
1161+ case 'member':
1162+ if (!is_numeric($params['memberid']) || $useCustomURL[$blogid] =='no') {
1163+ return;
1164+ }
1165+ $memberID = intval($params['memberid']);
1166+ $path = $this->getMemberOption($memberID, 'customurl_mname');
1167+ if ($path) {
1168+ $data['url'] = $this->_generateBlogLink($blogid) . '/'
1169+ . $OP_MemberKey . '/' . $path . '.html';
1170+ $data['completed'] = TRUE;
1171+ return;
1172+ } else {
1173+ if (!$this->_isValid(array('member', 'mnumber', $memberID))) {
1174+ $data['url'] = $this->_generateBlogLink($blogid) . '/'
1175+ . _NOT_VALID_MEMBER;
1176+ $data['completed'] = TRUE;
1177+ return;
1178+ } else {
1179+ $query = 'SELECT mname as result FROM %s'
1180+ . ' WHERE mnumber = %d';
1181+ $table = sql_table('member');
1182+ $mname = quickQuery(sprintf($query, $table, $memberID));
1183+ $this->RegistPath($memberID, $mname, 0, 'member', $mname, TRUE);
1184+ $data['url'] = $this->_generateBlogLink($blogid) . '/'
1185+ . $OP_MemberKey . '/' . $mname . '.html';
1186+ $data['completed'] = TRUE;
1187+ return;
1188+ }
1189+ }
1190+ break;
1191+ case 'category':
1192+ if (!is_numeric($params['catid'])) {
1193+ return;
1194+ }
1195+ $cat_id = intval($params['catid']);
1196+ $bid = intval(getBlogidFromCatID($cat_id));
1197+ if ($useCustomURL[$bid] == 'no') {
1198+ return;
1199+ }
1200+ $objPath = $this->_generateCategoryLink($cat_id);
1201+ if ($bid != $blogid) {
1202+ $burl = $this->_generateBlogLink($bid);
1203+ }
1204+ break;
1205+ case 'archivelist':
1206+ if ($useCustomURL[$blogid] == 'no') {
1207+ return;
1208+ }
1209+ $objPath = $OP_ArchivesKey . '/';;
1210+ $bid = intval($params['blogid']);
1211+ $burl = $this->_generateBlogLink($bid);
1212+ break;
1213+ case 'archive':
1214+ if ($useCustomURL[$blogid] == 'no') {
1215+ return;
1216+ }
1217+ sscanf($params['archive'], '%d-%d-%d', $y, $m, $d);
1218+ if ($d) {
1219+ $arc = sprintf('%04d-%02d-%02d', $y, $m, $d);
1220+ } elseif ($m) {
1221+ $arc = sprintf('%04d-%02d', $y, $m);
1222+ } else {
1223+ $arc = sprintf('%04d', $y);
1224+ }
1225+ $objPath = $OP_ArchiveKey . '/' . $arc . '/';;
1226+ $bid = intval($params['blogid']);
1227+ $burl = $this->_generateBlogLink($bid);
1228+ break;
1229+ case 'blog':
1230+ if (!is_numeric($params['blogid'])) {
1231+ return;
1232+ }
1233+ $bid = intval($params['blogid']);
1234+ $burl = $this->_generateBlogLink($bid);
1235+ break;
1236+ default:
1237+ return;
1238+ }
1239+ if (!$burl) {
1240+ $burl = $this->_generateBlogLink($blogid);
1241+ }
1242+/*
1243+ //NP_Analyze AdminArea check
1244+ $aplugin = $this->pluginCheck('Analyze');
1245+ if ($aplugin) {
1246+ $aadmin = str_replace('/', '\/', $aplugin->getAdminURL());
1247+ $p_arr = explode('/', serverVar('SCRIPT_NAME'));
1248+ $tmp = array_pop($p_arr);
1249+ $p_info = implode('\/', $p_arr);
1250+ }
1251+ if ($p_info) {
1252+ if (strpos($aadmin, $p_info)) {
1253+ $CONF['UsingAdminArea'] = TRUE;
1254+ }
1255+ }
1256+ //NP_Analyze AdminArea check end
1257+
1258+ if (getVar('virtualpath')) {
1259+ $info = preg_replace('|[^a-zA-Z0-9-~+_.?#=&;,/:@%]|i', '', getVar('virtualpath'));
1260+ } elseif (serverVar('PATH_INFO')) {
1261+ $info = preg_replace('|[^a-zA-Z0-9-~+_.?#=&;,/:@%]|i', '', serverVar('PATH_INFO'));
1262+ }
1263+ $v_path = explode('/', $info);
1264+
1265+ $feedurl = array();
1266+ $SiteMapP = $this->pluginCheck('GoogleSitemap');
1267+ if ($SiteMapP) {
1268+ $PcSitemaps = $SiteMapP->getAllBlogOptions('PcSitemap');
1269+ foreach ($PcSitemaps as $PCsitemap) {
1270+ if ($PCsitemap) {
1271+ $feedurl[] = $PCsitemap;
1272+ }
1273+ }
1274+ $MobSitemaps = $SiteMapP->getAllBlogOptions('MobileSitemap');
1275+ foreach ($MobSitemaps as $Mobsitemap) {
1276+ if ($Mobsitemap) {
1277+ $feedurl[] = $Mobsitemap;
1278+ }
1279+ }
1280+ }
1281+ $feedurl = array_unique($feedurl);
1282+ $request_path = end($v_path);
1283+ $feeds = in_array($request_path, $feedurl, true);
1284+*/
1285+
1286+ $denyPlugins = array(
1287+ 'np_analyze',
1288+ 'np_googlesitemap',
1289+ );
1290+ $tempdeb=debug_backtrace();
1291+ foreach($tempdeb as $k => $v){
1292+ $analyzePlugin = (strtolower($v['class']) == 'np_analyze');
1293+ $sitemapPlugin = (strtolower($v['class']) == 'np_googlesitemap' ||
1294+ strtolower($v['class']) == 'np_seositemaps');
1295+ if ($analyzePlugin || $sitemapPlugin) {
1296+ $denyPlugin = TRUE;
1297+ }
1298+ }
1299+
1300+// if (!$feeds && $bid != $blogid && !$CONF['UsingAdminArea']) {
1301+ if (!$denyPlugin && $bid != $blogid) {
1302+ $params['extra'] = array();
1303+ }
1304+ if ($objPath || $data['type'] == 'blog') {
1305+ $LinkURI = $this->_addLinkParams($objPath, $params['extra']);
1306+ if ($LinkURI) {
1307+ $data['url'] = $burl . '/' . $LinkURI;
1308+ } else {
1309+ $data['url'] = $burl;
1310+ }
1311+ $arcTmp = (preg_match('/' . $OP_ArchivesKey . '/', $data['url']));
1312+ $arcsTmp = (preg_match('/' . $OP_ArchiveKey . '/', $data['url']));
1313+ $isArchives = ($arcTmp || $arcsTmp);
1314+ $isItem = (substr($data['url'], -5, 5) == '.html');
1315+ $isDirectory = (substr($data['url'], -1) == '/');
1316+ $puri = parse_url($data['url']);
1317+// if (($isArchives && !$puri['query']) || (!$isItem && !$isDirectory && !$puri['query'])) {
1318+ if (!$isItem && !$isDirectory && !$puri['query']) {
1319+ $data['url'] .= '/';
1320+ }
1321+ $data['completed'] = TRUE;
1322+ if (strstr ($data['url'], '//')) {
1323+ $link = preg_replace("/([^:])\/\//", "$1/", $data['url']);
1324+ }
1325+ //$tempdeb=debug_backtrace();
1326+ foreach($tempdeb as $k => $v){
1327+ if (strtolower($v['class']) == 'np_trackback' && strtolower($v['function']) == 'gettrackbackurl') {
1328+ $tb = 1;
1329+ }
1330+ }
1331+ if ($tb == 1 && $data['type'] == 'item' && $isItem) {
1332+ $data['url'] = substr($data['url'], 0, -5);
1333+ }
1334+ return $data;
1335+ }
1336+ }
1337+
1338+ function _createSubCategoryLink($scid)
1339+ {
1340+ $scids = $this->getParents(intval($scid));
1341+ $subcatids = explode('/', $scids);
1342+ $eachPath = array();
1343+ foreach ($subcatids as $sid) {
1344+ $subcat_id = intval($sid);
1345+ $query = 'SELECT obj_name as result'
1346+ . ' FROM %s'
1347+ . ' WHERE obj_id = %d'
1348+ . ' AND obj_param = "%s"';
1349+ $query = sprintf($query, _CUSTOMURL_TABLE, $subcat_id, 'subcategory');
1350+ $path = quickQuery($query);
1351+ if ($path) {
1352+ $eachPath[] = $path;
1353+ } else {
1354+ $tempParam = array(
1355+ 'plug_multiple_categories_sub',
1356+ 'scatid',
1357+ $subcat_id
1358+ );
1359+ if (!$this->_isValid($tempParam)) {
1360+ return $url = _NOT_VALID_SUBCAT;
1361+ } else {
1362+ $scpath = $this->getOption('customurl_dfscat') . '_' . $subcat_id;
1363+ $query = 'SELECT catid as result FROM %s WHERE scatid = %d';
1364+ $query = sprintf($query, _C_SUBCAT_TABLE, $subcat_id);
1365+ $cid = quickQuery($query);
1366+ if (!$cid) {
1367+ return 'no_such_subcat=' . $subcat_id . '/';
1368+ }
1369+ $this->RegistPath($subcat_id, $scpath, $cid, 'subcategory', 'subcat_' . $subcat_id, TRUE);
1370+ $eachPath[] = $scpath;
1371+ }
1372+ }
1373+ }
1374+ $subcatPath = @implode('/', $eachPath);
1375+ return $subcatPath . '/';
1376+ }
1377+
1378+ function getParents($subid)
1379+ {
1380+ $mcatPlugin = $this->pluginCheck('MultipleCategories');
1381+ $mcatVarsion = $mcatPlugin->getVersion() * 100;
1382+ if (intval($mcatVarsion) < 40) {
1383+ return intval($subid);
1384+ }
1385+ $subcat_id = intval($subid);
1386+ $query = 'SELECT '
1387+ . 'scatid, '
1388+ . 'parentid '
1389+ . 'FROM %s '
1390+ . 'WHERE scatid = %d';
1391+ $query = sprintf($query, _C_SUBCAT_TABLE, $subcat_id);
1392+ $res = sql_query($query);
1393+ list($sid, $parent) = mysql_fetch_row($res);
1394+ if ($parent != 0) {
1395+ $r = $this->getParents($parent) . '/' . $sid;
1396+ } else {
1397+ $r = $sid;
1398+ }
1399+ return $r;
1400+ }
1401+
1402+ function _generateCategoryLink($cid)
1403+ {
1404+ global $CONF;
1405+ $cat_id = intval($cid);
1406+ $path = $this->getCategoryOption($cat_id, 'customurl_cname');
1407+ if ($path) {
1408+ return $path . '/';
1409+ } else {
1410+ $catData = array(
1411+ 'category',
1412+ 'catid',
1413+ $cat_id
1414+ );
1415+ if (!$this->_isValid($catData)) {
1416+ return $url = _NOT_VALID_CAT;
1417+ } else {
1418+ $cpath = $this->getOption('customurl_dfcat') . '_' . $cat_id;
1419+ $blog_id = intval(getBlogIDFromCatID($cat_id));
1420+ $catname = 'catid_' . $cat_id;
1421+ $this->RegistPath($cat_id, $cpath, $blog_id, 'category', $catname, TRUE);
1422+ return $cpath . '/';
1423+ }
1424+ }
1425+ }
1426+
1427+ function _generateBlogLink($bid)
1428+ {
1429+ global $manager, $CONF;
1430+ $blog_id = intval($bid);
1431+/*
1432+ if ($this->getBlogOption($blog_id, 'use_customurl') == 'no') {
1433+ $b =& $manager->getBlog($blog_id);
1434+ $burl = $b->getURL();
1435+ } else {
1436+ if ($blog_id == $CONF['DefaultBlog']) {
1437+ $burl = trim($CONF['IndexURL'], '/');
1438+ } else {
1439+ $query = 'SELECT burl as result '
1440+ . 'FROM %s '
1441+ . 'WHERE bnumber = %d';
1442+ $query = sprintf($query, sql_table('blog'), $blog_id);
1443+ $burl = quickQuery($query);
1444+ if ($burl) {
1445+ if (substr($burl, -4, 4) == '.php') {
1446+ $path = $this->getBlogOption($blog_id, 'customurl_bname');
1447+ if ($path) {
1448+ $burl = $CONF['IndexURL'] . $path;
1449+ } else {
1450+ $query = 'SELECT bshortname as result'
1451+ . ' FROM %s'
1452+ . ' WHERE bnumber = %d';
1453+ $query = sprintf($query, sql_table('blog'), $blog_id);
1454+ $bpath = quickQuery($query);
1455+ $this->RegistPath($blog_id, $bpath, 0, 'blog', $bpath, TRUE);
1456+ $burl = $CONF['IndexURL'] . $bpath;
1457+ }
1458+ $burl_update = 'UPDATE %s '
1459+ . 'SET burl = "%s" '
1460+ . 'WHERE bnumber = %d';
1461+ $burl = $this->quote_smart($burl);
1462+ $bTable = sql_table('blog');
1463+ sql_query(sprintf($burl_update, $bTable, $burl, $blog_id));
1464+ }
1465+ } else {
1466+ $burl = _NOT_VALID_BLOG;
1467+ }
1468+ }
1469+ }
1470+//*/
1471+ $param = array(
1472+ 'blog',
1473+ 'bnumber',
1474+ $blog_id
1475+ );
1476+ if (!$this->_isValid($param)) {
1477+ return _NOT_VALID_BLOG;
1478+ }
1479+ $b =& $manager->getBlog($blog_id);
1480+ $burl = $b->getURL();
1481+ if ($this->getBlogOption($blog_id, 'use_customurl') == 'yes') {
1482+ if ($blog_id == $CONF['DefaultBlog'] && $this->getOption('customurl_incbname') == 'no') {
1483+ if (empty($burl)) {
1484+ $this->_updateBlogURL($CONF['IndexURL'], $blog_id);
1485+ }
1486+ $burl = $CONF['IndexURL'];
1487+ } else {
1488+ if (empty($burl)) {
1489+ $burl = $CONF['IndexURL'];
1490+ }
1491+ if (substr($burl, -4) == '.php' || $burl == $CONF['IndexURL']) {
1492+ $path = $this->getBlogOption($blog_id, 'customurl_bname');
1493+ if ($path) {
1494+ $burl = $CONF['IndexURL'] . $path;
1495+ } else {
1496+ $query = 'SELECT bshortname as result'
1497+ . ' FROM %s'
1498+ . ' WHERE bnumber = %d';
1499+ $query = sprintf($query, sql_table('blog'), $blog_id);
1500+ $bpath = quickQuery($query);
1501+ $this->RegistPath($blog_id, $bpath, 0, 'blog', $bpath, TRUE);
1502+ $burl = $CONF['IndexURL'] . $bpath . '/';
1503+ }
1504+// $burl_update = 'UPDATE %s '
1505+// . 'SET burl = "%s" '
1506+// . 'WHERE bnumber = %d';
1507+// $burl = $this->quote_smart($burl);
1508+// $bTable = sql_table('blog');
1509+// sql_query(sprintf($burl_update, $bTable, $burl, $blog_id));
1510+ $this->_updateBlogURL($burl, $blog_id);
1511+ }
1512+ }
1513+ }
1514+
1515+ return trim($burl, '/');
1516+ }
1517+
1518+ function _updateBlogURL($burl, $blogid)
1519+ {
1520+ $blogid = intval($blogid);
1521+ $burl_update = 'UPDATE %s '
1522+ . 'SET burl = "%s" '
1523+ . 'WHERE bnumber = %d';
1524+ $burl = $this->quote_smart($burl);
1525+ $bTable = sql_table('blog');
1526+ sql_query(sprintf($burl_update, $bTable, $burl, $blogid));
1527+ }
1528+
1529+ function _addLinkParams($link, $params)
1530+ {
1531+ global $CONF, $manager, $catid;
1532+ $arcTmp = (preg_match('/' . $this->getOption('customurl_archives') . '/', $link));
1533+ $arcsTmp = (preg_match('/' . $this->getOption('customurl_archive') . '/', $link));
1534+ $isArchives = ($arcTmp || $arcsTmp);
1535+ $mcategories = $this->pluginCheck('MultipleCategories');
1536+ if ($mcategories) {
1537+ $mcategories->event_PreSkinParse(array());
1538+ global $subcatid;
1539+ if (method_exists($mcategories, 'getRequestName')) {
1540+ $subrequest = $mcategories->getRequestName();
1541+ } else {
1542+ $subrequest = 'subcatid';
1543+ }
1544+ }
1545+ if (is_array($params)) {
1546+ if ($params['archives']) {
1547+ $linkExtra = $this->getOption('customurl_archives') . '/';
1548+ unset($params['archives']);
1549+ } elseif ($params['archivelist']) {
1550+ $linkExtra = $this->getOption('customurl_archives') . '/';
1551+ unset($params['archivelist']);
1552+ } elseif ($params['archive']) {
1553+ sscanf($params['archive'], '%d-%d-%d', $y, $m, $d);
1554+ if ($d) {
1555+ $arc = sprintf('%04d-%02d-%02d', $y, $m, $d);
1556+ } elseif ($m) {
1557+ $arc = sprintf('%04d-%02d', $y, $m);
1558+ } else {
1559+ $arc = sprintf('%04d', $y);
1560+ }
1561+ $linkExtra = $this->getOption('customurl_archive') . '/' . $arc;
1562+ unset($params['archive']);
1563+ }
1564+ if ($params['blogid']) {
1565+ unset($params['blogid']);
1566+ }
1567+ $paramlink = array();
1568+ foreach ($params as $param => $value) {
1569+ switch ($param) {
1570+ case 'catid':
1571+ case $CONF['CategoryKey']:
1572+ $cid = intval($value);
1573+ $paramlink[] = $this->_generateCategoryLink($cid);
1574+ break;
1575+ case $subrequest:
1576+ if ($mcategories) {
1577+ $sid = intval($value);
1578+ $paramlink[] = $this->_createSubCategoryLink($sid);
1579+ }
1580+ break;
1581+ default:
1582+ $paramlink[] = $param . '/' . $value . '/';
1583+ break;
1584+ }
1585+ }
1586+ if (substr($link, -5, 5) == '.html' || $isArchives) {
1587+ $link = implode('', $paramlink) . $link;
1588+ } else {
1589+ $link .= implode('', $paramlink);
1590+ }
1591+ }
1592+ if ($linkExtra) {
1593+ $link .= $linkExtra;
1594+ }
1595+ if (requestVar('skinid')) {
1596+ $skinid = htmlspecialchars(requestVar('skinid'), ENT_QUOTES, _CHARSET);
1597+ if (!$link) {
1598+ $link = '?skinid=' . $skinid;
1599+ } elseif (strpos('?', $link)) {
1600+ $link .= '&amp;skinid=' . $skinid;
1601+ } else {
1602+ if (substr($link, -1) != '/' && !empty($link)) {
1603+ $link .= '/?skinid=' . $skinid;
1604+ } else {
1605+ $link .= '?skinid=' . $skinid;
1606+ }
1607+ }
1608+ }
1609+ if (strstr ($link, '//')) {
1610+ $link = preg_replace("/([^:])\/\//", "$1/", $link);
1611+ }
1612+ return $link;
1613+ }
1614+
1615+ function doSkinVar($skinType, $link_type = '', $target = '', $title = '')
1616+ {
1617+ global $blogid;
1618+ if ($skinType == 'item' && $link_type == 'trackback') {
1619+ global $itemid, $CONF;
1620+ if ($this->getBlogOption($blogid, 'use_customurl') == 'yes') {
1621+ $que = 'SELECT obj_name as result '
1622+ . 'FROM %s '
1623+ . 'WHERE obj_param = "item" '
1624+ . 'AND obj_id = %d';
1625+ $itempath = quickQuery(sprintf($que, _CUSTOMURL_TABLE, $itemid));
1626+ if ($target != 'ext') {
1627+ $uri = $CONF['BlogURL'] . '/trackback/' . $itempath;
1628+ } elseif ($target == 'ext') {
1629+// /item_123.trackback
1630+ $itempath = substr($itempath, 0, -5) . '.trackback';
1631+ $uri = $CONF['BlogURL'] . '/' . $itempath;
1632+ }
1633+ } else {
1634+ $uri = $CONF['ActionURL']
1635+ . '?action=plugin&amp;name=TrackBack&amp;tb_id=' . $itemid;
1636+ }
1637+ echo $uri;
1638+ return;
1639+ }
1640+ // $data == type / id || name / 'i'd || 'n'ame
1641+ // ex. => [(b)log / blogid [|| shortname / 'i'd || 'n'ame]]
1642+ // (c)at / catid [|| cname / 'i'd || 'n'ame]
1643+ // (s)cat / subcatid [|| sname / 'i'd || 'n'ame]
1644+ // [(i)tem /] itemid [/ 'path']
1645+ // (m)ember / mnumber [|| mname / 'i'd || 'n'ame]
1646+ //
1647+ // if second param is null, third param is id
1648+ // if param is null, generate blog link
1649+ if (!$link_type) {
1650+ $link_params = '0, b/' . intval($blogid) . '/i,'
1651+ . $target . ',' . $title;
1652+ } else {
1653+ $l_params = explode("/", $link_type);
1654+ if (count($l_params) == 1) {
1655+ $link_params = array(0, 'b/' . intval($link_type) . '/i,'
1656+ . $target . ',' . $title);
1657+ } else {
1658+ $link_params = array(0,
1659+ $link_type . ',' . $target . ',' . $title);
1660+ }
1661+ }
1662+ echo $this->URL_Callback($link_params);
1663+ }
1664+
1665+ function doTemplateVar(&$item, $link_type = '', $target = '', $title = '')
1666+ {
1667+ $item_id = intval($item->itemid);
1668+ if ($link_type == 'trackback') {
1669+ global $CONF;
1670+ $blog_id = intval(getBlogIDFromItemID($item_id));
1671+ if ($this->getBlogOption($blog_id, 'use_customurl') == 'yes') {
1672+ $que = 'SELECT obj_name as result '
1673+ . 'FROM %s '
1674+ . 'WHERE obj_param = "item" '
1675+ . 'AND obj_id = %d';
1676+ $itempath = quickQuery(sprintf($que, _CUSTOMURL_TABLE, $item_id));
1677+ if ($target != 'ext') {
1678+ $uri = $CONF['BlogURL'] . '/trackback/' . $itempath;
1679+ } elseif ($target == 'ext') {
1680+// /item_123.trackback
1681+ $itempath = substr($itempath, 0, -5) . '.trackback';
1682+ $uri = $CONF['BlogURL'] . '/' . $itempath;
1683+ }
1684+ } else {
1685+ $uri = $CONF['ActionURL']
1686+ . '?action=plugin&amp;name=TrackBack&amp;tb_id=' . $item_id;
1687+ }
1688+ echo $uri;
1689+ return;
1690+ }
1691+ if (!$link_type || $link_type == 'subcategory') {
1692+ $link_params = array(0,
1693+ 'i/' . $item_id . '/i,' . $target . ',' . $title);
1694+ } elseif ($link_type == 'path') {
1695+ $link_params = array(0,
1696+ 'i/' . $item_id . '/path,' . $target . ',' . $title);
1697+ } else {
1698+ $link_params = array(0,
1699+ $link_type . ',' . $target . ',' . $title);
1700+ }
1701+ if ($link_type == 'subcategory') {
1702+ echo $this->URL_Callback($link_params, 'scat');
1703+ } else {
1704+ echo $this->URL_Callback($link_params);
1705+ }
1706+ }
1707+
1708+ function URL_Callback($data, $scatFlag = '')
1709+ {
1710+ $l_data = explode(",", $data[1]);
1711+ $l_type = $l_data[0];
1712+ $target = $l_data[1];
1713+ $title = $l_data[2];
1714+ $item_id = intval($this->currentItem->itemid);
1715+ if (!$l_type) {
1716+ $link_params = array (
1717+ 'i',
1718+ $item_id,
1719+ 'i'
1720+ );
1721+ } else {
1722+ $link_data = explode("/", $l_type);
1723+ if (count($link_data) == 1) {
1724+ $link_params = array (
1725+ 'i',
1726+ intval($l_type),
1727+ 'i'
1728+ );
1729+ } elseif (count($link_data) == 2) {
1730+ if ($link_data[1] == 'path') {
1731+ $link_params = array (
1732+ 'i',
1733+ $link_data[0],
1734+ 'path'
1735+ );
1736+ } else {
1737+ $link_params = array (
1738+ $link_data[0],
1739+ intval($link_data[1]),
1740+ 'i'
1741+ );
1742+ }
1743+ } else {
1744+ $link_params = array (
1745+ $link_data[0],
1746+ $link_data[1],
1747+ $link_data[2]
1748+ );
1749+ }
1750+ }
1751+ $url = $this->_genarateObjectLink($link_params, $scatFlag);
1752+ if ($target) {
1753+ if ($title) {
1754+ $ObjLink = '<a href="' . htmlspecialchars($url) . '" '
1755+ . 'title="' . htmlspecialchars($title) . '">'
1756+ . htmlspecialchars($target) . '</a>';
1757+ } else {
1758+ $ObjLink = '<a href="' . htmlspecialchars($url) . '" '
1759+ . 'title="' . htmlspecialchars($target) . '">'
1760+ . htmlspecialchars($target) . '</a>';
1761+ }
1762+ } else {
1763+ $ObjLink = htmlspecialchars($url);
1764+ }
1765+ return $ObjLink;
1766+ }
1767+
1768+ function _isValid($data)
1769+ {
1770+ $query = 'SELECT * FROM %s WHERE %s = %d';
1771+ $data[2] = $this->quote_smart($data[2]);
1772+ $query = sprintf($query, sql_table($data[0]), $data[1], $data[2]);
1773+ $res = sql_query($query);
1774+ return (mysql_num_rows($res) != 0);
1775+ }
1776+
1777+ function _genarateObjectLink($data, $scatFlag = '')
1778+ {
1779+ global $CONF, $manager, $blog;
1780+ $ext = substr(serverVar('REQUEST_URI'), -4);
1781+ if ($ext == '.rdf' || $ext == '.xml') {
1782+ $CONF['URLMode'] = 'pathinfo';
1783+ }
1784+ if ($CONF['URLMode'] != 'pathinfo') {
1785+ return;
1786+ }
1787+ $query = 'SELECT %s as result FROM %s WHERE %s = "%s"';
1788+ switch ($data[0]) {
1789+ case 'b':
1790+ if ($data[2] == 'n') {
1791+ $bid = getBlogIDFromName($data[1]);
1792+ } else {
1793+ $bid = $data[1];
1794+ }
1795+ $blog_id = intval($bid);
1796+ $param = array(
1797+ 'blog',
1798+ 'bnumber',
1799+ $blog_id
1800+ );
1801+ if (!$this->_isValid($param)) {
1802+ $url = _NOT_VALID_BLOG;
1803+ } else {
1804+ $url = $this->_generateBlogLink($blog_id) . '/';
1805+ }
1806+ break;
1807+ case 'c':
1808+ if ($data[2] == 'n') {
1809+ $cid = getCatIDFromName($data[1]);
1810+ } else {
1811+ $cid = $data[1];
1812+ }
1813+ $cat_id = intval($cid);
1814+ $param = array(
1815+ 'category',
1816+ 'catid',
1817+ $cat_id
1818+ );
1819+ if (!$this->_isValid($param)) {
1820+ $url = _NOT_VALID_CAT;
1821+ } else {
1822+ $url = createCategoryLink($cat_id);
1823+ }
1824+ break;
1825+ case 's':
1826+ $mcategories = $this->pluginCheck('MultipleCategories');
1827+ if ($mcategories) {
1828+ if ($data[2] == 'n') {
1829+ $temp = $this->quote_smart($data[1]);
1830+ $sque = sprintf($query, 'scatid', _C_SUBCAT_TABLE, 'sname', $temp);
1831+ $scid = quickQuery($sque);
1832+ } else {
1833+ $scid = $data[1];
1834+ }
1835+ $sub_id = intval($scid);
1836+ $param = array(
1837+ 'plug_multiple_categories_sub',
1838+ 'scatid',
1839+ $sub_id
1840+ );
1841+ if (!$this->_isValid($param)) {
1842+ $url = _NOT_VALID_SUBCAT;
1843+ } else {
1844+ $cqe = sprintf($query, 'catid', _C_SUBCAT_TABLE, 'scatid', $sub_id);
1845+ $cid = quickQuery($cqe);
1846+ $cid = intval($cid);
1847+ if (method_exists($mcategories, "getRequestName")) {
1848+ $subrequest = $mcategories->getRequestName();
1849+ }
1850+ if (!$subrequest) {
1851+ $subrequest = 'subcatid';
1852+ }
1853+ $linkParam = array(
1854+ $subrequest => $sub_id
1855+ );
1856+ $url = createCategoryLink($cid, $linkParam);
1857+ }
1858+ }
1859+ break;
1860+ case 'i':
1861+ $param = array(
1862+ 'item',
1863+ 'inumber',
1864+ intval($data[1])
1865+ );
1866+ if (!$this->_isValid($param)) {
1867+ $url = _NOT_VALID_ITEM;
1868+ } else {
1869+ if ($scatFlag) {
1870+ global $catid, $subcatid;
1871+ if (!empty($catid)) {
1872+ $linkparams['catid'] = intval($catid);
1873+ }
1874+ if (!empty($subcatid)) {
1875+ $mcategories = $this->pluginCheck('MultipleCategories');
1876+ if ($mcategories) {
1877+ if (method_exists($mcategories, 'getRequestName')) {
1878+ $subrequest = $mcategories->getRequestName();
1879+ } else {
1880+ $subrequest = 'subcatid';
1881+ }
1882+ }
1883+ $linkparams[$subrequest] = intval($subcatid);
1884+ }
1885+ $url = createItemLink(intval($data[1]), $linkparams);
1886+ } else {
1887+ $blink = $this->_generateBlogLink(getBlogIDFromItemID(intval($data[1])));
1888+ $i_query = 'SELECT obj_name as result '
1889+ . 'FROM %s '
1890+ . 'WHERE obj_param = "item" '
1891+ . 'AND obj_id = %d';
1892+ $i_query = sprintf($i_query, _CUSTOMURL_TABLE, intval($data[1]));
1893+ $path = quickQuery($i_query);
1894+ if ($path) {
1895+ if ($data[2] == 'path') {
1896+ $url = $path;
1897+ } else {
1898+ $url = $blink . '/' . $path;
1899+ }
1900+ } else {
1901+ if ($data[2] == 'path') {
1902+ $url = $CONF['ItemKey'] . '/'
1903+ . intval($data[1]);
1904+ } else {
1905+ $url = $blink . '/' . $CONF['ItemKey'] . '/'
1906+ . intval($data[1]);
1907+ }
1908+ }
1909+ }
1910+ }
1911+ break;
1912+ case 'm':
1913+ if ($data[2] == 'n') {
1914+ $data[1] = $this->quote_smart($data[1]);
1915+ $mque = sprintf($query, 'mnumber', sql_table('member'), 'mname', $data[1]);
1916+ $mid = quickQuery($mque);
1917+ } else {
1918+ $mid = $data[1];
1919+ }
1920+ $member_id = intval($mid);
1921+ $param = array(
1922+ 'member',
1923+ 'mnumber',
1924+ $member_id
1925+ );
1926+ if (!$this->_isValid($param)) {
1927+ $url = _NOT_VALID_MEMBER;
1928+ } else {
1929+ $url = createMemberLink($member_id);
1930+ }
1931+ break;
1932+ }
1933+ return $url;
1934+ }
1935+
1936+ function event_InitSkinParse($data)
1937+ {
1938+ global $blogid, $CONF, $manager;
1939+ $feedurl = array(
1940+ 'rss1.xml',
1941+ 'index.rdf',
1942+ 'rss2.xml',
1943+ 'atom.xml',
1944+ );
1945+ $reqPaths = explode('/', serverVar('PATH_INFO'));
1946+ $reqPath = end($reqPaths);
1947+ $feeds = in_array($reqPath, $feedurl, true);
1948+ if (!$feeds) {
1949+ return;
1950+ } else {
1951+ $p_info = trim(serverVar('PATH_INFO'), '/');
1952+ $path_arr = explode('/', $p_info);
1953+ switch (end($path_arr)) {
1954+ case 'rss1.xml':
1955+ case 'index.rdf':
1956+ $skinName = 'feeds/rss10';
1957+ break;
1958+ case 'rss2.xml':
1959+ $skinName = 'feeds/rss20';
1960+ break;
1961+ case 'atom.xml':
1962+ $skinName = 'feeds/atom';
1963+ break;
1964+ }
1965+ if (SKIN::exists($skinName)) {
1966+ $skin =& SKIN::createFromName($skinName);
1967+ $data['skin']->SKIN($skin->getID());
1968+ $skinData =& $data['skin'];
1969+ $pageType = $data['type'];
1970+ if (!$CONF['DisableSite']) {
1971+ ob_start();
1972+
1973+ $skinID = $skinData->id;
1974+ $contents = $this->getSkinContent($pageType, $skinID);
1975+ $actions = SKIN::getAllowedActionsForType($pageType);
1976+ $dataArray = array(
1977+ 'skin' => &$skinData,
1978+ 'type' => $pageType,
1979+ 'contents' => &$contents
1980+ );
1981+ $manager->notify('PreSkinParse', $dataArray);
1982+ PARSER::setProperty('IncludeMode', SKIN::getIncludeMode());
1983+ PARSER::setProperty('IncludePrefix', SKIN::getIncludePrefix());
1984+ $handler =& new ACTIONS($pageType, $skinData);
1985+ $parser =& new PARSER($actions, $handler);
1986+ $handler->setParser($parser);
1987+ $handler->setSkin($skinData);
1988+ $parser->parse($contents);
1989+ $dataArray = array(
1990+ 'skin' => &$skinData,
1991+ 'type' => $pageType
1992+ );
1993+ $manager->notify('PostSkinParse', $dataArray);
1994+
1995+ $feed = ob_get_contents();
1996+
1997+ ob_end_clean();
1998+ $eTag = '"' . md5($feed) . '"';
1999+ header('Etag: ' . $eTag);
2000+ if ($eTag == serverVar('HTTP_IF_NONE_MATCH')) {
2001+ header('HTTP/1.0 304 Not Modified');
2002+ header('Content-Length: 0');
2003+ } else {
2004+ if (extension_loaded('mbstring')) {
2005+ $feed = mb_convert_encoding($feed, 'UTF-8', _CHARSET);
2006+ }
2007+ header('Content-Type: application/xml');
2008+ header('Generator: Nucleus CMS ' . $nucleus['version']);
2009+ // dump feed
2010+ echo $feed;
2011+ }
2012+ } else {
2013+ echo '<' . '?xml version="1.0" encoding="ISO-8859-1"?' . '>';
2014+?>
2015+<rss version="2.0">
2016+ <channel>
2017+ <title><?php echo htmlspecialchars($CONF['SiteName'], ENT_QUOTES)?></title>
2018+ <link><?php echo htmlspecialchars($CONF['IndexURL'], ENT_QUOTES)?></link>
2019+ <description></description>
2020+ <docs>http://backend.userland.com/rss</docs>
2021+ </channel>
2022+</rss>
2023+<?php
2024+ }
2025+ }
2026+ exit;
2027+ }
2028+ }
2029+
2030+ function getSkinContent($pageType, $skinID)
2031+ {
2032+ $skinID = intval($skinID);
2033+ $pageType = addslashes($pageType);
2034+ $query = 'SELECT scontent '
2035+ . 'FROM %s '
2036+ . 'WHERE sdesc = %d '
2037+ . 'AND stype = %d';
2038+ $query = sprintf($query, sql_table('skin'), $skinID, $pageType);
2039+ $res = sql_query($query);
2040+
2041+ if (mysql_num_rows($res) == 0) {
2042+ return '';
2043+ } else {
2044+ return mysql_result($res, 0, 0);
2045+ }
2046+ }
2047+
2048+
2049+// merge NP_RightURL
2050+ function event_PreSkinParse($data)
2051+ {
2052+ global $CONF, $manager, $blog, $catid, $itemid, $subcatid;
2053+ global $memberid;
2054+ if (!$blog) {
2055+ $b =& $manager->getBlog($CONF['DefaultBlog']);
2056+ } else {
2057+ $b =& $blog;
2058+ }
2059+ $blogurl = $b->getURL();
2060+
2061+ if (!$blogurl) {
2062+ if($blog) {
2063+ $b_tmp =& $manager->getBlog($CONF['DefaultBlog']);
2064+ $blogurl = $b_tmp->getURL();
2065+ }
2066+ if (!$blogurl) {
2067+ $blogurl = $CONF['IndexURL'];
2068+ if ($CONF['URLMode'] != 'pathinfo'){
2069+ if ($data['type'] == 'pageparser') {
2070+ $blogurl .= 'index.php';
2071+ } else {
2072+ $blogurl = $CONF['Self'];
2073+ }
2074+ }
2075+ }
2076+ }
2077+ if ($CONF['URLMode'] == 'pathinfo'){
2078+ if (substr($blogurl, -1) == '/') {
2079+ $blogurl = substr($blogurl, 0, -1);
2080+ }
2081+ }
2082+ $CONF['BlogURL'] = $blogurl;
2083+ $CONF['ItemURL'] = $blogurl;
2084+ $CONF['CategoryURL'] = $blogurl;
2085+ $CONF['ArchiveURL'] = $blogurl;
2086+ $CONF['ArchiveListURL'] = $blogurl;
2087+ $CONF['SearchURL'] = $blogurl;
2088+// $CONF['MemberURL'] = $blogurl;
2089+ }
2090+
2091+ function event_PreItem($data)
2092+ {
2093+ global $CONF, $manager;
2094+
2095+ $this->currentItem = &$data['item'];
2096+ $pattern = '/<%CustomURL\((.*)\)%>/';
2097+ $data['item']->body = preg_replace_callback($pattern, array(&$this, 'URL_Callback'), $data['item']->body);
2098+ if ($data['item']->more) {
2099+ $data['item']->more = preg_replace_callback($pattern, array(&$this, 'URL_Callback'), $data['item']->more);
2100+ }
2101+
2102+ $itemid = intval($data['item']->itemid);
2103+ $itemblog =& $manager->getBlog(getBlogIDFromItemID($itemid));
2104+ $blogurl = $itemblog->getURL();
2105+ if (!$blogurl) {
2106+ $b =& $manager->getBlog($CONF['DefaultBlog']);
2107+ if (!($blogurl = $b->getURL())) {
2108+ $blogurl = $CONF['IndexURL'];
2109+ if ($CONF['URLMode'] != 'pathinfo'){
2110+ if ($data['type'] == 'pageparser') {
2111+ $blogurl .= 'index.php';
2112+ } else {
2113+ $blogurl = $CONF['Self'];
2114+ }
2115+ }
2116+ }
2117+ }
2118+ if ($CONF['URLMode'] == 'pathinfo'){
2119+ if (substr($blogurl, -1) == '/') {
2120+ $blogurl = substr($blogurl, 0, -1);
2121+ }
2122+ }
2123+ $CONF['BlogURL'] = $blogurl;
2124+ $CONF['ItemURL'] = $blogurl;
2125+ $CONF['CategoryURL'] = $blogurl;
2126+ $CONF['ArchiveURL'] = $blogurl;
2127+ $CONF['ArchiveListURL'] = $blogurl;
2128+// $CONF['MemberURL'] = $blogurl;
2129+ }
2130+
2131+ function event_PostItem($data)
2132+ {
2133+ global $CONF, $manager, $blog;
2134+ if (!$blog) {
2135+ $b =& $manager->getBlog($CONF['DefaultBlog']);
2136+ } else {
2137+ $b =& $blog;
2138+ }
2139+ $blogurl = $b->getURL();
2140+ if (!$blogurl) {
2141+ if($blog) {
2142+ $b_tmp =& $manager->getBlog($CONF['DefaultBlog']);
2143+ $blogurl = $b_tmp->getURL();
2144+ }
2145+ if (!$blogurl) {
2146+ $blogurl = $CONF['IndexURL'];
2147+ if ($CONF['URLMode'] != 'pathinfo'){
2148+ if ($data['type'] == 'pageparser') {
2149+ $blogurl .= 'index.php';
2150+ } else {
2151+ $blogurl = $CONF['Self'];
2152+ }
2153+ }
2154+ }
2155+ }
2156+ if ($CONF['URLMode'] == 'pathinfo'){
2157+ if (substr($blogurl, -1) == '/') {
2158+ $blogurl = substr($blogurl, 0, -1);
2159+ }
2160+ }
2161+ $CONF['BlogURL'] = $blogurl;
2162+ $CONF['ItemURL'] = $blogurl;
2163+ $CONF['CategoryURL'] = $blogurl;
2164+ $CONF['ArchiveURL'] = $blogurl;
2165+ $CONF['ArchiveListURL'] = $blogurl;
2166+// $CONF['MemberURL'] = $CONF['Self'];
2167+ }
2168+// merge NP_RightURL end
2169+
2170+ function event_PostDeleteBlog ($data)
2171+ {
2172+ $query = 'DELETE FROM %s WHERE obj_id = %d AND obj_param = "%s"';
2173+ $pquery = 'DELETE FROM %s WHERE obj_bid = %d AND obj_param= "%s"';
2174+ $blogid = intval($data['blogid']);
2175+ sql_query(sprintf($query, _CUSTOMURL_TABLE, $blogid, 'blog'));
2176+ sql_query(sprintf($pquery, _CUSTOMURL_TABLE, $blogid, 'item'));
2177+ $cnmquery = 'SELECT catid FROM %s WHERE cblog = %d';
2178+ $table = sql_table('category');
2179+ $cnm = sql_query(sprintf($cnmquery, $table, $blogid));
2180+ while ($c = mysql_fetch_object($cnm)) {
2181+ $catid = intval($c->catid);
2182+ sql_query(sprintf($pquery, _CUSTOMURL_TABLE, $catid, 'subcategory'));
2183+ sql_query(sprintf($query, _CUSTOMURL_TABLE, $catid, 'category'));
2184+ }
2185+ }
2186+
2187+ function event_PostDeleteCategory ($data)
2188+ {
2189+ $query = 'DELETE FROM %s WHERE obj_id = %d AND obj_param = "%s"';
2190+ $squery = 'DELETE FROM %s WHERE obj_bid = %d AND obj_param = "%s"';
2191+ $catid = intval($data['catid']);
2192+ sql_query(sprintf($query, _CUSTOMURL_TABLE, $catid, 'category'));
2193+ sql_query(sprintf($squery, _CUSTOMURL_TABLE, $catid, 'subcategory'));
2194+ }
2195+
2196+ function event_PostDeleteItem ($data)
2197+ {
2198+ $query = 'DELETE FROM %s WHERE obj_id = %d AND obj_param = "%s"';
2199+ $itemid = intval($data['itemid']);
2200+ sql_query(sprintf($query, _CUSTOMURL_TABLE, $itemid, 'item'));
2201+ }
2202+
2203+ function event_PostDeleteMember ($data)
2204+ {
2205+ $query = 'DELETE FROM %s WHERE obj_id = %d AND obj_param = "%s"';
2206+ $memberid = intval($data['member']->id);
2207+ sql_query(sprintf($query, _CUSTOMURL_TABLE, $memberid, 'member'));
2208+ }
2209+
2210+ function event_PostAddBlog ($data)
2211+ {
2212+ $blog_id = intval($data['blog']->blogid);
2213+ $bshortname = $data['blog']->settings['bshortname'];
2214+ $this->RegistPath($blog_id, $bshortname, 0, 'blog', $bshortname, TRUE);
2215+ $this->setBlogOption($blog_id, 'customurl_bname', $bshortname);
2216+ }
2217+
2218+ function event_PostAddCategory ($data)
2219+ {
2220+ global $CONF;
2221+ $cat_id = intval($data['catid']);
2222+ if (!$data['blog']->blogid) {
2223+ $query = 'SELECT cblog as result FROM %s WHERE catid = %d';
2224+ $bid = quickQuery(sprintf($query, sql_table('category'), $cat_id));
2225+ } else {
2226+ $bid = $data['blog']->blogid;
2227+ }
2228+ if (!$data['name']) {
2229+ $query = 'SELECT cname as result FROM %s WHERE catid = %d';
2230+ $name = quickQuery(sprintf($query, sql_table('category'), $cat_id));
2231+ } else {
2232+ $name = $data['name'];
2233+ }
2234+ $bid = intval($bid);
2235+ $dfcat = $this->getOption('customurl_dfcat');
2236+ $catpsth = $dfcat . '_' . $cat_id;
2237+ $this->RegistPath($cat_id, $catpsth, $bid, 'category', $name, TRUE);
2238+ $this->setCategoryOption($cat_id, 'customurl_cname', $catpsth);
2239+ }
2240+
2241+ function event_PostAddItem ($data)
2242+ {
2243+ $item_id = intval($data['itemid']);
2244+ $tpath = requestVar('plug_custom_url_path');
2245+ $tque = 'SELECT itime as result FROM %s WHERE inumber = %d';
2246+ $itime = quickQuery(sprintf($tque, sql_table('item'), $item_id));
2247+ list($y, $m, $d, $trush) = sscanf($itime, '%d-%d-%d %s');
2248+ $param['year'] = sprintf('%04d', $y);
2249+ $param['month'] = sprintf('%02d', $m);
2250+ $param['day'] = sprintf('%02d', $d);
2251+ $ipath = TEMPLATE::fill($tpath, $param);
2252+ $query = 'SELECT ititle as result FROM %s WHERE inumber = %d';
2253+ $iname = quickQuery(sprintf($query, sql_table('item'), $item_id));
2254+ $blog_id = intval(getBlogIDFromItemID($item_id));
2255+ $this->RegistPath($item_id, $ipath, $blog_id, 'item', $iname, TRUE);
2256+ if ($this->pluginCheck('TrackBack')) {
2257+ $this->convertLocalTrackbackURL($data);
2258+ }
2259+ }
2260+
2261+ function event_PostRegister ($data)
2262+ {
2263+ $memberID = intval($data['member']->id);
2264+ $dispName = $data['member']->displayname;
2265+ $this->RegistPath($memberID, $dispName, 0, 'member', $dispName, TRUE);
2266+ $this->setMemberOption($memberID, 'customurl_mname', $dispName);
2267+ }
2268+
2269+ function event_AddItemFormExtras(&$data)
2270+ {
2271+ $this->createItemForm();
2272+ }
2273+
2274+ function event_EditItemFormExtras(&$data)
2275+ {
2276+ $this->createItemForm(intval($data['itemid']));
2277+ }
2278+
2279+ function event_PostUpdateItem($data)
2280+ {
2281+ $tpath = requestVar('plug_custom_url_path');
2282+ $item_id = intval($data['itemid']);
2283+ $tque = 'SELECT itime as result FROM %s WHERE inumber = %d';
2284+ $itime = quickQuery(sprintf($tque ,sql_table('item'), $item_id));
2285+ list($y, $m, $d, $trush) = sscanf($itime, '%d-%d-%d %s');
2286+ $param['year'] = sprintf('%04d', $y);
2287+ $param['month'] = sprintf('%02d', $m);
2288+ $param['day'] = sprintf('%02d', $d);
2289+ $ipath = TEMPLATE::fill($tpath, $param);
2290+ $query = 'SELECT ititle as result FROM %s WHERE inumber = %d';
2291+ $iname = quickQuery(sprintf($query, sql_table('item'), $item_id));
2292+ $blog_id = intval(getBlogIDFromItemID($item_id));
2293+ $this->RegistPath($item_id, $ipath, $blog_id, 'item', $iname);
2294+ if ($this->pluginCheck('TrackBack')) {
2295+ $this->convertLocalTrackbackURL($data);
2296+ }
2297+ }
2298+
2299+ function createItemForm($item_id = 0)
2300+ {
2301+ global $CONF;
2302+ if ($item_id) {
2303+ $query = 'SELECT obj_name as result'
2304+ . ' FROM %s'
2305+ . ' WHERE obj_param = "item"'
2306+ . ' AND obj_id = %d';
2307+ $item_id = intval($item_id);
2308+ $res = quickQuery(sprintf($query, _CUSTOMURL_TABLE, $item_id));
2309+ $ipath = substr($res, 0, strlen($res)-5);
2310+ } else {
2311+ $ipath = $this->getOption('customurl_dfitem');
2312+ }
2313+ echo <<<OUTPUT
2314+<h3>Custom URL</h3>
2315+<p>
2316+<label for="plug_custom_url">Custom Path:</label>
2317+<input id="plug_custom_url" name="plug_custom_url_path" value="{$ipath}" />
2318+</p>
2319+OUTPUT;
2320+ }
2321+
2322+ function event_PrePluginOptionsUpdate($data)
2323+ {
2324+ $blog_option = ($data['optionname'] == 'customurl_bname');
2325+ $cate_option = ($data['optionname'] == 'customurl_cname');
2326+ $memb_option = ($data['optionname'] == 'customurl_mname');
2327+ $arch_option = ($data['optionname'] == 'customurl_archive');
2328+ $arvs_option = ($data['optionname'] == 'customurl_archives');
2329+ $memd_option = ($data['optionname'] == 'customurl_member');
2330+ $contextid = intval($data['contextid']);
2331+ $context = $data['context'];
2332+ if ($blog_option || $cate_option || $memb_option) {
2333+ if ($context == 'member' ) {
2334+ $blogid = 0;
2335+ $query = 'SELECT mname as result FROM %s WHERE mnumber = %d';
2336+ $table = sql_table('member');
2337+ $name = quickQuery(sprintf($query, $table, $contextid));
2338+ } elseif (context == 'category') {
2339+ $blogid = getBlogIDFromCatID($contextid);
2340+ $query = 'SELECT cname as result FROM %s WHERE catid = %d';
2341+ $table = sql_table('category');
2342+ $name = quickQuery(sprintf($query, $table, $contextid));
2343+ } else {
2344+ $blogid = 0;
2345+ $query = 'SELECT bname as result FROM %s WHERE bnumber = %d';
2346+ $table = sql_table('blog');
2347+ $name = quickQuery(sprintf($query, $table, $contextid));
2348+ }
2349+ $blogid = intval($blogid);
2350+ $msg = $this->RegistPath($contextid, $data['value'], $blogid, $context, $name);
2351+ if ($msg) {
2352+ $this->error($msg);
2353+ exit;
2354+ }
2355+ } elseif ($arch_option || $arvs_option || $memd_option) {
2356+ if (!ereg("^[-_a-zA-Z0-9]+$", $data['value'])) {
2357+ $name = substr($data['optionname'], 8);
2358+ $msg = array (1, _INVALID_ERROR, $name, _INVALID_MSG);
2359+ $this->error($msg);
2360+ exit;
2361+ } else {
2362+ return;
2363+ }
2364+ }
2365+ return;
2366+ }
2367+
2368+ function event_PostMoveItem($data)
2369+ {
2370+ $query = 'UPDATE %s SET obj_bid = %d'
2371+ . ' WHERE obj_param = "%s" AND obj_id = %d';
2372+ $destblogid = intval($data['destblogid']);
2373+ $item_id = intval($data['itemid']);
2374+ sql_query(sprintf($query, _CUSTOMURL_TABLE, $destblogid, 'item', $item_id));
2375+ }
2376+
2377+ function event_PostMoveCategory($data)
2378+ {
2379+ $query = 'UPDATE %s SET obj_bid = %d'
2380+ . ' WHERE obj_param = "%s" AND obj_id = %d';
2381+ $destblogid = intval($data['destblog']->blogid);
2382+ $cat_id = intval($data['catid']);
2383+ sql_query(sprintf($query, _CUSTOMURL_TABLE, $destblogid, 'category', $cat_id));
2384+ $query = 'SELECT inumber FROM %s WHERE icat = %d';
2385+ $query = sprintf($query, sql_table('item'), $cat_id);
2386+ $items = sql_query($query);
2387+ while ($oItem = mysql_fetch_object($items)) {
2388+ $odata = array(
2389+ 'destblogid' => $destblogid,
2390+ 'itemid' => $oItem->inumber
2391+ );
2392+ $this->event_PostMoveItem($odata);
2393+ }
2394+ }
2395+
2396+ function RegistPath($objID, $path, $bid, $oParam, $name, $new = FALSE )
2397+ {
2398+ global $CONF;
2399+ switch($oParam) {
2400+ case 'item':
2401+ case 'member':
2402+ if (preg_match('/.html$/', $path))
2403+ $path = substr($path, 0, -5);
2404+ break;
2405+ case 'blog':
2406+ case 'category':
2407+ case 'subcategory':
2408+ break;
2409+ default :
2410+ return;
2411+ break;
2412+ }
2413+ $bid = intval($bid);
2414+ $objID = intval($objID);
2415+ $name = rawurlencode($name);
2416+
2417+ if ($new && $oParam == 'item') {
2418+ $tque = 'SELECT itime as result FROM %s WHERE inumber = %d';
2419+ $itime = quickQuery(sprintf($tque ,sql_table('item'), $objID));
2420+ list($y, $m, $d, $trush) = sscanf($itime, '%d-%d-%d %s');
2421+ $param['year'] = sprintf('%04d', $y);
2422+ $param['month'] = sprintf('%02d', $m);
2423+ $param['day'] = sprintf('%02d', $d);
2424+ $ikey = TEMPLATE::fill($template, $param);
2425+ if ($path == $ikey) {
2426+ $path = $ikey . '_' . $objID;
2427+ }
2428+ } elseif (!$new && strlen($path) == 0) {
2429+ $del_que = 'DELETE FROM %s WHERE obj_id = %d AND obj_param = "%s"';
2430+ sql_query(sprintf($del_que, _CUSTOMURL_TABLE, $objID, $oParam));
2431+ $msg = array (0, _DELETE_PATH, $name, _DELETE_MSG);
2432+ return $msg;
2433+ exit;
2434+ }
2435+
2436+ $dotslash = array ('.', '/');
2437+ $path = str_replace ($dotslash, '_', $path);
2438+ if (!ereg("^[-_a-zA-Z0-9]+$", $path)) {
2439+ $msg = array (1, _INVALID_ERROR, $name, _INVALID_MSG);
2440+ return $msg;
2441+ exit;
2442+ }
2443+
2444+ $tempPath = $path;
2445+ if ($oParam == 'item' || $oParam == 'member') $tempPath .= '.html';
2446+ $conf_que = 'SELECT obj_id FROM %s'
2447+ . ' WHERE obj_name = "%s"'
2448+ . ' AND obj_bid = %d'
2449+ . ' AND obj_param = "%s"'
2450+ . ' AND obj_id != %d';
2451+ $res = sql_query(sprintf($conf_que, _CUSTOMURL_TABLE, $tempPath, $bid, $oParam, $objID));
2452+ if ($res && mysql_num_rows($res)) {
2453+ $msg = array (0, _CONFLICT_ERROR, $name, _CONFLICT_MSG);
2454+ $path .= '_'.$objID;
2455+ }
2456+ if ($oParam == 'category' && !$msg) {
2457+ $conf_cat = 'SELECT obj_id FROM %s WHERE obj_name = "%s"'
2458+ . ' AND obj_param = "blog"';
2459+ $res = sql_query(sprintf($conf_cat, _CUSTOMURL_TABLE, $tempPath));
2460+ if ($res && mysql_num_rows($res)) {
2461+ $msg = array (0, _CONFLICT_ERROR, $name, _CONFLICT_MSG);
2462+ $path .= '_'.$objID;
2463+ }
2464+ }
2465+ if ($oParam == 'blog' && !$msg) {
2466+ $conf_blg = 'SELECT obj_id FROM %s WHERE obj_name = "%s"'
2467+ . ' AND obj_param = "category"';
2468+ $res = sql_query(sprintf($conf_blg, _CUSTOMURL_TABLE, $tempPath));
2469+ if ($res && mysql_num_rows($res)) {
2470+ $msg = array (0, _CONFLICT_ERROR, $name, _CONFLICT_MSG);
2471+ $path .= '_'.$objID;
2472+ }
2473+ }
2474+
2475+ $newPath = $path;
2476+ if ($oParam == 'item' || $oParam == 'member') $newPath .= '.html';
2477+ $query = 'SELECT * FROM %s WHERE obj_id = %d AND obj_param = "%s"';
2478+ $res = sql_query(sprintf($query, _CUSTOMURL_TABLE, $objID, $oParam));
2479+ $row = mysql_fetch_object($res);
2480+ $pathID = $row->id;
2481+ if ($pathID) {
2482+ $query = 'UPDATE %s SET obj_name = "%s" WHERE id = %d';
2483+ sql_query(sprintf($query, _CUSTOMURL_TABLE, $newPath, $pathID));
2484+ } else {
2485+ $query = 'INSERT INTO %s (obj_param, obj_name, obj_id, obj_bid)'
2486+ . ' VALUES ("%s", "%s", %d, %d)';
2487+ sql_query(sprintf($query, _CUSTOMURL_TABLE, $oParam, $newPath, $objID, $bid));
2488+ }
2489+ switch($oParam) {
2490+ case 'blog':
2491+ $this->setBlogOption($objID, 'customurl_bname', $path);
2492+ break;
2493+ case 'category':
2494+ $this->setCategoryOption($objID, 'customurl_cname', $path);
2495+ break;
2496+ case 'member':
2497+ $this->setMemberOption($objID, 'customurl_mname', $path);
2498+ break;
2499+ default :
2500+ break;
2501+ }
2502+ return $msg;
2503+ }
2504+
2505+ function error($msg = '')
2506+ {
2507+ global $admin;
2508+
2509+ $admin->pagehead();
2510+ echo $msg[1].' : '.$msg[2].'<br />';
2511+ echo $msg[3].'<br />';
2512+ echo '<a href="index.php" onclick="history.back()">'._BACK.'</a>';
2513+ $admin->pagefoot();
2514+ return;
2515+ }
2516+
2517+ function quote_smart($value)
2518+ {
2519+ if (get_magic_quotes_gpc()) $value = stripslashes($value);
2520+ if (!is_numeric($value)) {
2521+ $value = mysql_real_escape_string($value);
2522+ } elseif (is_numeric($value)) {
2523+ $value = intval($value);
2524+ }
2525+ return $value;
2526+ }
2527+
2528+ function convertLocalTrackbackURL($data)
2529+ {
2530+ global $manager, $CONF;
2531+ $ping_urls_count = 0;
2532+ $ping_urls = array();
2533+ $localflag = array();
2534+ $ping_url = requestVar('trackback_ping_url');
2535+ if (trim($ping_url)) {
2536+ $ping_urlsTemp = array();
2537+ $ping_urlsTemp = preg_split("/[\s,]+/", trim($ping_url));
2538+ for ($i = 0; $i < count($ping_urlsTemp); $i++) {
2539+ $ping_urls[] = trim($ping_urlsTemp[$i]);
2540+ $ping_urls_count++;
2541+ }
2542+ }
2543+ $tb_url_amount = intRequestVar('tb_url_amount');
2544+ for ($i=0; $i < $tb_url_amount; $i++) {
2545+ $tb_temp_url = requestVar('tb_url_' . $i);
2546+ if ($tb_temp_url) {
2547+ $ping_urls[$ping_urls_count] = $tb_temp_url;
2548+ $localflag[$ping_urls_count] = (requestVar('tb_url_' . $i . '_local') == 'on') ? 1 : 0;
2549+ $ping_urls_count++;
2550+ }
2551+ }
2552+ if ($ping_urls_count <= 0) {
2553+ return;
2554+ }
2555+ $blog_id = getBlogidFromItemID(intval($data['itemid']));
2556+ for ($i=0; $i < count($ping_urls); $i++) {
2557+ if($localflag[$i]) {
2558+ $tmp_url = parse_url($ping_urls[$i]);
2559+ $tmp_url['path'] = trim($tmp_url['path'], '/');
2560+ $path_arr = explode("/", $tmp_url['path']);
2561+ $tail = end($path_arr);
2562+ $linkObj = array (
2563+ 'linkparam' => 'item',
2564+ 'bid' => $blog_id,
2565+ );
2566+ if (substr($tail, -10) == '.trackback') {
2567+ $pathName = substr($tail, 0, -10);
2568+ if (substr($pathName, -5) == '.html') {
2569+ $linkObj['name'] = $pathName;
2570+ } else {
2571+ $linkObj['name'] = $pathName . '.html';
2572+ }
2573+ } else {
2574+ $linkObj['name'] = $tail;
2575+ }
2576+ $item_id = $this->getRequestPathInfo($linkObj);
2577+ if ($item_id) {
2578+ $ping_urls[$i] = $CONF['ActionURL']
2579+ . '?action=plugin&name=TrackBack&tb_id=' . $item_id;
2580+ }
2581+ }
2582+ }
2583+ $_REQUEST['trackback_ping_url'] = implode ("\n", $ping_urls);
2584+ }
2585+
2586+}
--- /dev/null
+++ b/NP_Dtree/tags/NP_Dtree.php
@@ -0,0 +1,139 @@
1+<?php
2+/**
3+ *
4+ * 0.94 bug fix
5+ * add language files
6+ * configuration by option
7+ * 0.93 sec fix
8+ * subcategory link bug fix
9+ *
10+ */
11+
12+class NP_Dtree extends NucleusPlugin
13+{
14+
15+ function getName()
16+ {
17+ return 'Navigation Tree';
18+ }
19+
20+ function getAuthor()
21+ {
22+ return 'nakahara21 + shizuki';
23+ }
24+
25+ function getURL()
26+ {
27+ return 'http://nakahara21.com/';
28+ }
29+
30+ function getVersion()
31+ {
32+ return '0.94';
33+ }
34+
35+ function getDescription()
36+ {
37+ return _DTREE_DESCRIPTION; //'Show Navigation Tree. Usage: &lt;%Dtree()%&gt;';
38+ }
39+
40+ function supportsFeature($what)
41+ {
42+ switch($what){
43+ case 'SqlTablePrefix':
44+ return 1;
45+ default:
46+ return 0;
47+ }
48+ }
49+
50+ function install()
51+ {
52+ $this->createOption('folderLinks', _DTREE_DIR_LINK, 'yesno', 'yes');
53+ $this->createOption('useSelection', _DTREE_SELECTION, 'yesno', 'no');
54+ $this->createOption('useCookies', _DTREE_COOKIE, 'yesno', 'no');
55+ $this->createOption('useLines', _DTREE_LINE, 'yesno', 'yes');
56+ $this->createOption('useIcons', _DTREE_ICON, 'yesno', 'yes');
57+ $this->createOption('useStatusText', _DTREE_ST_TEXT, 'yesno', 'no');
58+ $this->createOption('closeSameLevel', _DTREE_CL_SLEVEL, 'yesno', 'no');
59+ $this->createOption('inOrder', _DTREE_IN_ORDER, 'yesno', 'no');
60+ }
61+
62+ function init()
63+ {
64+ global $admin;
65+ $language = ereg_replace( '[\\|/]', '', getLanguageName());
66+ if (file_exists($this->getDirectory().'language/'.$language.'.php')) {
67+ include_once($this->getDirectory().'language/'.$language.'.php');
68+ }else {
69+ include_once($this->getDirectory().'language/english.php');
70+ }
71+ }
72+
73+ function doSkinVar($skinType, $itemid = 0)
74+ {
75+ global $blogid, $catid, $subcatid;
76+ $adminURL = htmlspecialchars($this->getAdminURL(), ENT_QUOTES, _CHARSET);
77+ if (is_numeric($blogid)) {
78+ $blogid = intval($blogid);
79+ } else {
80+ $id = getBlogIDFromName($blogid);
81+ $blogid = intval($id);
82+ }
83+ $itemid = intval($itemid);
84+ $catid = intval($catid);
85+ $subcatid = intval($subcatid);
86+
87+// $randomID = 'tree' . uniqid(rand());
88+ $randomID = 'tree' . preg_replace('|[^0-9a-f]|i', '', uniqid(rand()));
89+
90+ echo '<script type="text/javascript" src="' . $adminURL . 'dtree.php"></script>' . "\n";
91+
92+ if ($skinType == 'template') {
93+ $data = '<script type="text/javascript"' . ' src="' . $adminURL
94+ . 'dtreedata.php?'
95+ . 'o=' . $randomID . 'a'
96+ . '&amp;'
97+ . 'bid=' . $blogid
98+ . '&amp;'
99+ . 'id=' . $itemid
100+ . '"></script>' . "\n";
101+ echo $data;
102+ $data = '<a href="javascript: ' . $randomID . 'a.openAll();">' . _DTREE_OPENALL . '</a>' . "\n"
103+ . ' | ' . "\n"
104+ . '<a href="javascript: ' . $randomID . 'a.closeAll();">' . _DTREE_CLOSEALL . '</a>' . "\n";
105+ echo $data;
106+ return;
107+ }
108+
109+ $eq = '';
110+ if (!empty($catid)) {
111+ } $eq .= '&amp;cid=' . $catid;
112+ if (!empty($subcatid)) {
113+ $eq .= '&amp;sid=' . $subcatid;
114+ }
115+
116+ $data = '<script type="text/javascript" src="' . $adminURL
117+ . 'dtreedata.php?'
118+ . 'o=' . $randomID . 'd'
119+ . '&amp;'
120+ . 'bid=' . $blogid . $eq . '">'
121+ . '</script>';
122+ echo $data;
123+ $data = '<a href="javascript: ' . $randomID . 'd.openAll();">' . _DTREE_OPENALL . '</a>' . "\n"
124+ . ' | ' . "\n"
125+ . '<a href="javascript: ' . $randomID . 'd.closeAll();">' . _DTREE_CLOSEALL . '</a>' . "\n";
126+ echo $data;
127+/* if (!(intRequestVar('page') > 0) !$catid && !$subcatid) {
128+ echo '<script type="text/javascript">' . $randomID . 'd.openAll();</script>';
129+ }*/
130+
131+ }
132+
133+ function doTemplateVar(&$item)
134+ {
135+ $this->doSkinVar('template', $item->itemid);
136+ }
137+
138+}
139+?>
\ No newline at end of file
--- /dev/null
+++ b/NP_Dtree/trunk/NP_Dtree.php
@@ -0,0 +1,139 @@
1+<?php
2+/**
3+ *
4+ * 0.94 bug fix
5+ * add language files
6+ * configuration by option
7+ * 0.93 sec fix
8+ * subcategory link bug fix
9+ *
10+ */
11+
12+class NP_Dtree extends NucleusPlugin
13+{
14+
15+ function getName()
16+ {
17+ return 'Navigation Tree';
18+ }
19+
20+ function getAuthor()
21+ {
22+ return 'nakahara21 + shizuki';
23+ }
24+
25+ function getURL()
26+ {
27+ return 'http://nakahara21.com/';
28+ }
29+
30+ function getVersion()
31+ {
32+ return '0.94';
33+ }
34+
35+ function getDescription()
36+ {
37+ return _DTREE_DESCRIPTION; //'Show Navigation Tree. Usage: &lt;%Dtree()%&gt;';
38+ }
39+
40+ function supportsFeature($what)
41+ {
42+ switch($what){
43+ case 'SqlTablePrefix':
44+ return 1;
45+ default:
46+ return 0;
47+ }
48+ }
49+
50+ function install()
51+ {
52+ $this->createOption('folderLinks', _DTREE_DIR_LINK, 'yesno', 'yes');
53+ $this->createOption('useSelection', _DTREE_SELECTION, 'yesno', 'no');
54+ $this->createOption('useCookies', _DTREE_COOKIE, 'yesno', 'no');
55+ $this->createOption('useLines', _DTREE_LINE, 'yesno', 'yes');
56+ $this->createOption('useIcons', _DTREE_ICON, 'yesno', 'yes');
57+ $this->createOption('useStatusText', _DTREE_ST_TEXT, 'yesno', 'no');
58+ $this->createOption('closeSameLevel', _DTREE_CL_SLEVEL, 'yesno', 'no');
59+ $this->createOption('inOrder', _DTREE_IN_ORDER, 'yesno', 'no');
60+ }
61+
62+ function init()
63+ {
64+ global $admin;
65+ $language = ereg_replace( '[\\|/]', '', getLanguageName());
66+ if (file_exists($this->getDirectory().'language/'.$language.'.php')) {
67+ include_once($this->getDirectory().'language/'.$language.'.php');
68+ }else {
69+ include_once($this->getDirectory().'language/english.php');
70+ }
71+ }
72+
73+ function doSkinVar($skinType, $itemid = 0)
74+ {
75+ global $blogid, $catid, $subcatid;
76+ $adminURL = htmlspecialchars($this->getAdminURL(), ENT_QUOTES, _CHARSET);
77+ if (is_numeric($blogid)) {
78+ $blogid = intval($blogid);
79+ } else {
80+ $id = getBlogIDFromName($blogid);
81+ $blogid = intval($id);
82+ }
83+ $itemid = intval($itemid);
84+ $catid = intval($catid);
85+ $subcatid = intval($subcatid);
86+
87+// $randomID = 'tree' . uniqid(rand());
88+ $randomID = 'tree' . preg_replace('|[^0-9a-f]|i', '', uniqid(rand()));
89+
90+ echo '<script type="text/javascript" src="' . $adminURL . 'dtree.php"></script>' . "\n";
91+
92+ if ($skinType == 'template') {
93+ $data = '<script type="text/javascript"' . ' src="' . $adminURL
94+ . 'dtreedata.php?'
95+ . 'o=' . $randomID . 'a'
96+ . '&amp;'
97+ . 'bid=' . $blogid
98+ . '&amp;'
99+ . 'id=' . $itemid
100+ . '"></script>' . "\n";
101+ echo $data;
102+ $data = '<a href="javascript: ' . $randomID . 'a.openAll();">' . _DTREE_OPENALL . '</a>' . "\n"
103+ . ' | ' . "\n"
104+ . '<a href="javascript: ' . $randomID . 'a.closeAll();">' . _DTREE_CLOSEALL . '</a>' . "\n";
105+ echo $data;
106+ return;
107+ }
108+
109+ $eq = '';
110+ if (!empty($catid)) {
111+ } $eq .= '&amp;cid=' . $catid;
112+ if (!empty($subcatid)) {
113+ $eq .= '&amp;sid=' . $subcatid;
114+ }
115+
116+ $data = '<script type="text/javascript" src="' . $adminURL
117+ . 'dtreedata.php?'
118+ . 'o=' . $randomID . 'd'
119+ . '&amp;'
120+ . 'bid=' . $blogid . $eq . '">'
121+ . '</script>';
122+ echo $data;
123+ $data = '<a href="javascript: ' . $randomID . 'd.openAll();">' . _DTREE_OPENALL . '</a>' . "\n"
124+ . ' | ' . "\n"
125+ . '<a href="javascript: ' . $randomID . 'd.closeAll();">' . _DTREE_CLOSEALL . '</a>' . "\n";
126+ echo $data;
127+/* if (!(intRequestVar('page') > 0) !$catid && !$subcatid) {
128+ echo '<script type="text/javascript">' . $randomID . 'd.openAll();</script>';
129+ }*/
130+
131+ }
132+
133+ function doTemplateVar(&$item)
134+ {
135+ $this->doSkinVar('template', $item->itemid);
136+ }
137+
138+}
139+?>
\ No newline at end of file
--- /dev/null
+++ b/NP_EzComment2/tags/NP_EzComment2.php
@@ -0,0 +1,984 @@
1+<?php
2+/**
3+ * SHOW Comment Form/List PLUG-IN FOR NucleusCMS
4+ * PHP versions 5
5+ *
6+ * This program is free software; you can redistribute it and/or
7+ * modify it under the terms of the GNU General Public License
8+ * as published by the Free Software Foundation; either version 2
9+ * of the License, or (at your option) any later version.
10+ * (see nucleus/documentation/index.html#license for more info)
11+ *
12+ * @author shizuki
13+ * @copyright 2008 shizuki
14+ * @license http://www.gnu.org/licenses/gpl.txt GNU GENERAL PUBLIC LICENSE Version 2, June 1991
15+ * @version $Date$ $Revision: 1.13 $
16+ * @link http://japan.nucleuscms.org/wiki/plugins:ezcomment2
17+ * @since File available since Release 1.0
18+ */
19+
20+/**
21+ * version history
22+ *
23+ * $Log: not supported by cvs2svn $
24+ * Revision 1.12 2008/07/09 03:54:07 shizuki
25+ * *** empty log message ***
26+ *
27+ * Revision 1.11 2008/07/09 03:54:04 shizuki
28+ * *Fix header info URL:showblogs -> ezcomment2
29+ *
30+ * * Revision 1.10 2008/07/08 16:14:57 shizuki
31+ * *Bug fix event_PreComment
32+ * *Correspondence preparations of NP_LatestWritebacks
33+ *
34+ * Revision 1.9 2008/07/08 15:14:27 shizuki
35+ * * Corresponds to event_PreComment.
36+ * * Fix typo.
37+ * * RC2
38+ *
39+ * Revision 1.8 2008/07/07 15:42:54 shizuki
40+ * * The experimental society PHP Version: 5.2.6/MySQL Server Version (client): (5.1.25-rc-log 5.1.25-rc).
41+ * * The normal movement is confirmed.
42+ * * The SQL correction/behavior when installing, is changed a little.
43+ * * event_PostDeleteCommnent addition * It's corrected when being off login time and secret mode-lessly, so as not to take out a check box.
44+ * * NP_OpenId is indispensable in the present.
45+ * * NP_znSpecialTemplateParts is indispensable.
46+ * * It's expected to add the setting which will establish a password at the time of contribution without NP_OpenId and make it hidden from now on.
47+ * * It's RC edition, so please cooperate in the one with the environment.
48+ *
49+ * Revision 1.7 2008/07/07 10:24:00 shizuki
50+ * * Still, the human sacrifice test version.
51+ * * A template was separated for for index pages and item page.
52+ * * Subdivision of the showComment() function.
53+ * * It's changed so as not to fly to an indication part for indication in case of and OpenID of anything but the first item of an index page.
54+ * * A profile change part besides the first item of an index page is being adjusted.
55+ */
56+
57+class NP_EzComment2 extends NucleusPlugin
58+{
59+ // {{{ properties
60+
61+ /**
62+ * The calling number of times by the index page.
63+ *
64+ * @var integer
65+ */
66+ var $numcalled;
67+
68+ /**
69+ * OpenID authentication module.
70+ *
71+ * @var object
72+ */
73+ var $authOpenID;
74+
75+ /**
76+ * Flag of the case that one is invoker.
77+ *
78+ * @var boolean
79+ */
80+ var $callFlg;
81+
82+ // }}}
83+ // {{{ getName()
84+
85+ /**
86+ * Plugin Name
87+ *
88+ * @return string
89+ */
90+ function getName()
91+ {
92+ return 'Ez Comment II';
93+ }
94+
95+ // }}}
96+ // {{{ getAuthor()
97+
98+ /**
99+ * Author Name
100+ *
101+ * @return string
102+ */
103+ function getAuthor()
104+ {
105+ return 'shizuki';
106+ }
107+
108+ // }}}
109+ // {{{ getURL()
110+
111+ /**
112+ * I get a plug-in, the address of the possible site or author's mail address.
113+ *
114+ * @return string
115+ */
116+ function getURL()
117+ {
118+ return 'http://japan.nucleuscms.org/wiki/plugins:ezcomment2';
119+ }
120+
121+ // }}}
122+ // {{{ getPluginDep()
123+
124+ /**
125+ * Plugin Dependency.
126+ *
127+ * @return array
128+ */
129+ function getPluginDep()
130+ {
131+ return array(
132+ 'NP_OpenId',
133+ 'NP_znSpecialTemplateParts',
134+ );
135+ }
136+
137+ // }}}
138+ // {{{ getVersion()
139+
140+ /**
141+ * Plugin Version.
142+ *
143+ * @return string
144+ */
145+ function getVersion()
146+ {
147+ return '$Date$ $Revision: 1.13 $';
148+ }
149+
150+ // }}}
151+ // {{{ getDescription()
152+
153+ /**
154+ * Plugin Description
155+ *
156+ * @return string
157+ */
158+ function getDescription()
159+ {
160+ return _NP_EZCOMMENT2_DESC;
161+ }
162+
163+ // }}}
164+ // {{{ supportsFeature($what)
165+
166+ /**
167+ * Supports Nucleus Feature
168+ *
169+ * @param string
170+ * @return boolean
171+ */
172+ function supportsFeature($what)
173+ {
174+ switch ($what) {
175+ case 'SqlTablePrefix':
176+ return 1;
177+ default:
178+ return 0;
179+ }
180+ }
181+
182+ // }}}
183+ // {{{ getEventList()
184+
185+ /**
186+ * List of feature event
187+ *
188+ * @return array
189+ */
190+ function getEventList()
191+ {
192+ global $manager;
193+ return array(
194+ 'FormExtra',
195+ 'PostAddComment',
196+ 'PostDeleteComment',
197+ 'PreComment',
198+ );
199+ }
200+
201+ // }}}
202+ // {{{ getTableList()
203+
204+ /**
205+ * Database tables for plugin used
206+ *
207+ * @return array
208+ **/
209+ function getTableList()
210+ {
211+ return array(
212+ sql_table('plug_ezcomment2'),
213+ );
214+ }
215+
216+ // }}}
217+ // {{{ install()
218+
219+ /**
220+ * Install function
221+ *
222+ * @return void.
223+ */
224+ function install()
225+ {
226+ if (!TEMPLATE::exists('EzCommentTemplate')) {
227+ global $DIR_LIBS;
228+ include_once($DIR_LIBS . 'skinie.php');
229+ $importer = new SKINIMPORT();
230+ $importer->reset();
231+ $template = $this->getDirectory() . 'skinbackup.xml';
232+ if (!@file_exists($template)) {
233+ $aErrors[] = 'Unable to import ' . $template . ' : file does not exist';
234+ continue;
235+ }
236+ $error = $importer->readFile($template);
237+ if ($error) {
238+ $aErrors[] = 'Unable to import ' . $template . ' : ' . $error;
239+ continue;
240+ }
241+ $error = $importer->writeToDatabase(1);
242+ if ($error) {
243+ $aErrors[] = 'Unable to import ' . $template . ' : ' . $error;
244+ continue;
245+ }
246+ if ($aErrors) {
247+ $message = implode("<br />\n", $aErrors);
248+ doError($message);
249+ }
250+ }
251+ $this->createBlogOption('secret', _NP_EZCOMMENT2_OP_SECRETMODE, 'yesno', 'yes');
252+ $this->createBlogOption('secComment', _NP_EZCOMMENT2_OP_SUBSTIUTION, 'text', _NP_EZCOMMENT2_OP_SUBSTIUTION_VAL);
253+ $this->createBlogOption('secLabel', _NP_EZCOMMENT2_OP_CHECKLABEL, 'text', _NP_EZCOMMENT2_OP_CHECKLABEL_VAL);
254+ $this->createOption('tabledel', _NP_EZCOMMENT2_OP_DROPTABLE, 'yesno', 'yes');
255+ $sql = 'CREATE TABLE IF NOT EXISTS %s ('
256+ . '`comid` int(11) NOT NULL, '
257+ . '`secflg` tinyint(1) NULL, '
258+ . '`module` varchar(15) NULL, '
259+ . '`userID` varchar(255) NULL, '
260+ . 'PRIMARY KEY(`comid`) );';
261+ sql_query(sprintf($sql, sql_table('plug_ezcomment2')));
262+ $this->updateTable();
263+ }
264+
265+ // }}}
266+ // {{{ uninstall()
267+
268+ /**
269+ * Un Install function
270+ *
271+ * @return void.
272+ */
273+ function uninstall()
274+ {
275+ if ($this->getOption('tabledel') == 'yes')
276+ sql_query('DROP TABLE '.sql_table('plug_ezcomment2'));
277+ }
278+
279+ // }}}
280+ // {{{ init()
281+
282+ /**
283+ * Initialize
284+ *
285+ * @return void.
286+ */
287+ function init()
288+ {
289+ $this->languageInclude();
290+ $this->numcalled = 0;
291+ $this->callFlg = false;
292+ global $manager;
293+ if ($manager->pluginInstalled('NP_OpenId') && !$this->authOpenID) {
294+ $this->authOpenID = $manager->getPlugin('NP_OpenId');
295+ }
296+ }
297+
298+ // }}}
299+ // {{{ event_PostAddComment($data)
300+
301+ /**
302+ * After adding a comment to the database.
303+ *
304+ * @param array
305+ * commentid integer
306+ * comment array
307+ * spamcheck array
308+ * @return void.
309+ */
310+ function event_PostAddComment($data)
311+ {
312+ global $member;
313+ switch (true) {
314+ case $member->isLoggedin():
315+ $userID = '"' . $member->getID() . '"';
316+ $module = '"Nucleus"';
317+ break;
318+ case ($this->authOpenID && $this->authOpenID->isLoggedin()):
319+ $userID = '"' . $this->authOpenID->loggedinUser['identity'] . '"';
320+ $module = '"OpenID"';
321+ break;
322+ default:
323+ $userID = 'NULL';
324+ $module = 'NULL';
325+ break;
326+ }
327+ if (postVar('EzComment2_Secret')) {
328+ $secCheck = 1;
329+ } else {
330+ $secCheck = 'NULL';
331+ }
332+ $sql = 'INSERT INTO ' . sql_table('plug_ezcomment2')
333+ . ' (`comid`, `secflg`, `module`, `userID`) VALUES (%d, %d, %s, %s)';
334+ sql_query(sprintf($sql, $data['commentid'], $secCheck, $module, $userID));
335+ }
336+
337+ // }}}
338+ // {{{ event_PostDeleteComment($data)
339+
340+ /**
341+ * After a comment has been deleted from the database.
342+ *
343+ * @param array
344+ * commentid integer
345+ * @return void.
346+ */
347+ function event_PostDeleteComment($data)
348+ {
349+ $sql = 'DELETE FROM ' . sql_table('plug_ezcomment2')
350+ . ' WHERE `comid` = %d LIMIT 1';
351+ sql_query(sprintf($sql, $data['commentid']));
352+ }
353+
354+ // }}}
355+ // {{{ event_FormExtra(&$data)
356+
357+ /**
358+ * Inside one of the comment, membermail or account activation forms.
359+ *
360+ * @param array
361+ * type string
362+ * @return void.
363+ */
364+ function event_FormExtra(&$data)
365+ {
366+ global $member, $blogid;
367+ $this->numcalled++;
368+ if ($blogid && $this->getBlogOption($blogid, 'secret') == 'yes' &&
369+ ($member->isLoggedin() || ($this->authOpenID && $this->authOpenID->isLoggedin()))) {
370+ echo '<br /><input type="checkbox" value="1" name="EzComment2_Secret" id="EzComment2_Secret_' . $this->numcalled . '" />';
371+ echo '<label for="EzComment2_Secret_' . $this->numcalled . '">'.$this->getBlogOption($bid, 'secLabel').'</label><br />';
372+ }
373+ if ($this->authOpenID) {
374+ $this->plugOpenIDdoSkinVar($this->commentSkinType, $this->commentItemId);
375+ }
376+ }
377+
378+ // }}}
379+ // {{{ event_PreComment(&$data)
380+
381+ /**
382+ * Inside one of the comment, membermail or account activation forms.
383+ *
384+ * @param array
385+ * comment array
386+ * @return void.
387+ */
388+ function event_PreComment(&$data)
389+ {
390+ if ($this->callFlg) return;
391+ $sql = 'SELECT secflg, userID FROM ' . sql_table('plug_ezcomment2')
392+ . ' WHERE comid = ' . intval($data['comment']['commentid']);
393+ $res = sql_query($sql);
394+ $flg = mysql_fetch_assoc($res);
395+ if (!$flg['secflg']) return;
396+ $data['comment']['identity'] = $flg['userID'];
397+ global $manager, $member;
398+ $bid = intval($data['comment']['blogid']);
399+ $b = $manager->getBlog($bid);
400+ $judge = $this->setSecretJudge($bid, $member, $b);
401+ $data['comment'] = $this->JudgementCommentSecrets($data['comment'], $judge);
402+// print_r($data);
403+ }
404+
405+ // }}}
406+ // {{{ doTemplateVar()
407+
408+ /**
409+ * Basically the same as doSkinVar,
410+ * but this time for calls of the <%plugin(...)%>-var in templates (item header/body/footer and dateheader/footer).
411+ *
412+ * @param object item object(refarence)
413+ * @param string
414+ * @param string
415+ * @param string
416+ * @param string
417+ * @param string
418+ * @return void.
419+ */
420+ function doTemplateVar(&$item,
421+ $showType = '',
422+ $showMode = '5/1/1',
423+ $destinationurl = '',
424+ $formTemplate = 'EzCommentTemplate',
425+ $listTemplate = 'EzCommentTemplate')
426+ {
427+ $this->doSkinVar('template', $showType, $showMode, $destinationurl, $formTemplate, $listTemplate, $item);
428+ }
429+
430+ // }}}
431+ // {{{ doSkinVar()
432+
433+ /**
434+ * When plugins are called using the <%plugin(...)%>-skinvar, this method will be called.
435+ *
436+ * @param string
437+ * @param string
438+ * @param string
439+ * @param string
440+ * @param string
441+ * @param string
442+ * @param object item object(refarence)
443+ * @return void.
444+ */
445+ function doSkinVar($skinType,
446+ $showType = '',
447+ $showMode = '5/1/1',
448+ $destinationurl = '',
449+ $formTemplate = 'EzCommentTemplate',
450+ $listTemplate = 'EzCommentTemplate',
451+ &$commentItem = '')
452+ {
453+ if ($skinType != 'item' && $skinType != 'template') return;
454+ global $manager, $member, $itemid;
455+ if (!$commentItem && $itemid) {
456+ $commentItem = $manager->getItem($itemid, 0, 0);
457+ if (is_array($commentItem)) {
458+ $commentItem = (object)$commentItem;
459+ }
460+ }
461+ if (!$commentItem || $commentItem->closed) {
462+ echo _ERROR_ITEMCLOSED;
463+ return 0;
464+ }
465+
466+ if (is_numeric($showType) || strpos($showType, '/') !== false) $showMode = $showType;
467+ if ($showType != 'list' && $showType != 'form') {
468+ $showType = '';
469+ }
470+ if (!$showMode) {
471+ $showMode = '5/1/1';
472+ }
473+ list($maxToShow, $sortOrder, $commentOrder) = explode('/', $showMode);
474+ if (!$maxToShow) $maxToShow = 5;
475+ if (!$sortOrder) $sortOrder = 1;
476+ if ($commentOrder > 0) {
477+ $commentOrder = true;
478+ } else {
479+ $commentOrder = false;
480+ }
481+ if (!$formTemplate) $formTemplate = 'EzCommentTemplate';
482+ if (!$listTemplate) $listTemplate = 'EzCommentTemplate';
483+
484+ switch ($showType) {
485+ case 'list':
486+ $listTemplate = TEMPLATE::read($listTemplate);
487+ $this->showComment($commentItem, $listTemplate, $maxToShow, $commentOrder, $skinType);
488+ break;
489+ case 'form':
490+ $formTemplate = TEMPLATE::read($formTemplate);
491+ $this->showForm($commentItem, $formTemplate, $destinationurl, $skinType);
492+ break;
493+ default:
494+ $listTemplate = TEMPLATE::read($listTemplate);
495+ $formTemplate = TEMPLATE::read($formTemplate);
496+ if ($sortOrder) {
497+ $this->showComment($commentItem, $listTemplate, $maxToShow, $commentOrder, $skinType);
498+ $this->showForm($commentItem, $formTemplate, $destinationurl, $skinType);
499+ } else {
500+ $this->showForm($commentItem, $formTemplate, $destinationurl, $skinType);
501+ $this->showComment($commentItem, $listTemplate, $maxToShow, $commentOrder, $skinType);
502+ }
503+ break;
504+ }
505+ }
506+
507+ // }}}
508+ // {{{ languageInclude()
509+
510+ /**
511+ * Include language file
512+ *
513+ * @return void.
514+ */
515+ function languageInclude()
516+ {
517+ $language = ereg_replace( '[\\|/]', '', getLanguageName());
518+ if (file_exists($this->getDirectory() . 'language/' . $language . '.php')) {
519+ include_once($this->getDirectory() . 'language/' . $language . '.php');
520+ } else {
521+ include_once($this->getDirectory() . 'language/english.php');
522+ }
523+ }
524+
525+ // }}}
526+ // {{{ updateTable()
527+
528+ /**
529+ * Update database table
530+ *
531+ * @return void.
532+ */
533+ function updateTable()
534+ {
535+ $sql = 'SELECT c.cnumber as cid FROM ' . sql_table('comment') . ' as c '
536+ . 'LEFT JOIN ' . sql_table('plug_ezcomment2') . ' as s '
537+ . 'ON c.cnumber=s.comid WHERE s.comid IS NULL';
538+ $res = sql_query($sql);
539+ $sql = 'INSERT INTO ' . sql_table('plug_ezcomment2') . '(`comid`) VALUES (%d)';
540+ while ($cid = mysql_fetch_assoc($res)) {
541+ sql_query(sprintf($sql, $cid['cid']));
542+ }
543+ }
544+
545+ // }}}
546+ // {{{ plugOpenIDdoSkinVar()
547+
548+ /**
549+ * Overwride NP_OpenId's doSkinVar()
550+ *
551+ * @param string
552+ * @param integer
553+ * @return void.
554+ */
555+ function plugOpenIDdoSkinVar($skinType, $iid = 0)
556+ {
557+ global $CONF, $manager, $member;
558+ if ($member->isLoggedIn()) return;
559+ $authOpenID = $this->authOpenID;
560+ if (!$authOpenID) return;
561+ $externalauth = array ( 'source' => $authOpenID->getName() );
562+ $manager->notify('ExternalAuth', array ('externalauth' => &$externalauth));
563+ if (isset($externalauth['result']) && $externalauth['result'] == true) return;
564+ $templateEngine = $authOpenID->_getTemplateEngine();
565+ $aVars = array();
566+ $aVars['PluginURL'] = $CONF['PluginURL'];
567+ if ($authOpenID->isLoggedin()) {
568+ // Loggedin
569+ if ($skinType == 'template') {
570+ require_once 'cles/Template.php';
571+ $templateDirectory = rtrim($this->getDirectory(), '/');
572+ $templateEngine =& new cles_Template($templateDirectory);
573+ $templateEngine->defaultLang = 'english';
574+ $aVars['itemid'] = intval($iid);
575+ }
576+ $nowURL = 'http://' . serverVar("HTTP_HOST")
577+ . serverVar("REQUEST_URI");
578+ $aVars['url'] = $authOpenID->getAdminURL() . 'rd.php?action=rd'
579+ . '&url=' . urlencode($nowURL);
580+ $aVars['nick'] = $authOpenID->loggedinUser['nick'];
581+ $aVars['email'] = $authOpenID->loggedinUser['email'];
582+ $aVars['ts'] = $authOpenID->loggedinUser['ts'];
583+ $aVars['identity'] = $authOpenID->loggedinUser['identity'];
584+ $aVars['visible'] = $aVars['nick'] ? 'false' : 'true' ;
585+ $actionUrl = parse_url($CONF['ActionURL']);
586+ $aVars['updateUrl'] = $actionUrl['path'];
587+ if ($skinType == 'item' || ($skinType == 'template' && $this->numcalled == 0)) {
588+ echo $templateEngine->fetchAndFill('yui', $aVars, 'np_openid');
589+ echo $templateEngine->fetchAndFill('form', $aVars, 'np_openid');
590+ }
591+ echo $templateEngine->fetchAndFill('loggedin', $aVars, 'np_openid');
592+ } elseif (!$authOpenID->isLoggedin()) {
593+ // Not loggedin
594+ $aVars['url'] = $authOpenID->getAdminURL() . 'rd.php?action=doauth'
595+ . '&return_url=' . urlencode(createItemLink(intval($iid)));
596+ echo $templateEngine->fetchAndFill('notloggedin', $aVars, 'np_openid');
597+ }
598+ }
599+
600+ // }}}
601+ // {{{ checkDestinationurl($destinationurl)
602+
603+ /**
604+ * Destinationurl check
605+ *
606+ * @param string
607+ * @return string
608+ */
609+ function checkDestinationurl($destinationurl, $iid, $cid = 0, $scid = 0)
610+ {
611+ if (stristr($destinationurl, 'action.php') || empty($destinationurl)) {
612+ if (stristr($destinationurl, 'action.php')) {
613+ $logMessage = 'actionurl is not longer a parameter on commentform skinvars.'
614+ . ' Moved to be a global setting instead.';
615+ ACTIONLOG::add(WARNING, $logMessage);
616+ }
617+ if ($cid) {
618+ $linkparams['catid'] = intval($cid);
619+ }
620+ global $manager;
621+ if ($manager->pluginInstalled('NP_MultipleCategories') && $scid) {
622+ $linkparams['subcatid'] = intval($scid);
623+ }
624+ $destinationurl = createItemLink(intval($iid), $linkparams);
625+ } else {
626+ $destinationurl = preg_replace('|[^a-z0-9-~+_.?#=&;,/:@%]|i', '', $destinationurl);
627+ }
628+ return $destinationurl;
629+ }
630+
631+ // }}}
632+ // {{{ getCommentatorInfo()
633+
634+ /**
635+ * Get commentator info.
636+ *
637+ * @return array
638+ */
639+ function getCommentatorInfo()
640+ {
641+ global $CONF;
642+ $user = cookieVar($CONF['CookiePrefix'] .'comment_user');
643+ if (!$user) {
644+ $user = postVar('user');
645+ }
646+ $userid = cookieVar($CONF['CookiePrefix'] .'comment_userid');
647+ if (!$userid) {
648+ $userid = postVar('userid');
649+ }
650+ $email = cookieVar($CONF['CookiePrefix'] .'comment_email');
651+ if (!$email) {
652+ $email = postVar('email');
653+ }
654+ $body = postVar('body');
655+ return array(
656+ $user,
657+ $userid,
658+ $email,
659+ $body
660+ );
661+ }
662+ // {{{ showForm()
663+
664+ /**
665+ * Show comment form
666+ *
667+ * @param object
668+ * @param string
669+ * @param string
670+ * @param string
671+ * @return void.
672+ */
673+ function showForm($commentItem, $template, $destinationurl, $skinType)
674+ {
675+ global $CONF, $manager, $member, $catid, $subcatid;
676+ $bid = getBlogIDFromItemID($commentItem->itemid);
677+ $b =& $manager->getBlog($bid);
678+ $b->readSettings();
679+ if (!$member->isLoggedIn() && !$b->commentsEnabled()) {
680+ return;
681+ }
682+ $destinationurl = $this->checkDestinationurl($destinationurl, $commentItem->itemid, $catid, $subcatid);
683+ list($user, $userid, $email, $body) = $this->getCommentatorInfo();
684+
685+ $checked = cookieVar($CONF['CookiePrefix'] .'comment_user') ? 'checked="checked" ' : '';
686+
687+ $formdata = array(
688+ 'self' => $this->_hsc(serverVar('REQUEST_URI')),
689+ 'destinationurl' => $this->_hsc($destinationurl),
690+ 'actionurl' => $this->_hsc($CONF['ActionURL']),
691+ 'itemid' => intval($commentItem->itemid),
692+ 'user' => $this->_hsc($user),
693+ 'userid' => $this->_hsc($userid),
694+ 'email' => $this->_hsc($email),
695+ 'body' => $this->_hsc($body),
696+// 'membername' => $this->_hsc($membername),
697+ 'rememberchecked' => $checked
698+ );
699+ if ($skinType == 'item') {
700+ $formFlg = '_ITM';
701+ } else {
702+ $formFlg = '_IDX';
703+ }
704+ if ($member && $member->isLoggedIn()) {
705+ $formType = 'FORM_LOGGEDIN' . $formFlg;
706+ $loginMember = $member->createFromID($member->getID());
707+ $formdata['membername'] = $this->_hsc($loginMember->getDisplayName());
708+ } else {
709+ $formType = 'FORM_NOTLOGGEDIN' . $formFlg;
710+ }
711+ if ($this->authOpenID && ($skinType == 'item' || $this->numcalled == 0)) {
712+ $this->plugOpenIDdoSkinVar($skinType, intval($commentItem->itemid));
713+ }
714+ $this->commentItemId = intval($commentItem->itemid);
715+ $this->commentSkinType = $skinType;
716+ $contents = $template[$formType];
717+ include_once($this->getDirectory() . 'EzCommentActions.php');
718+ $formAction =& new EzCommentFormActions($commentItem, $formdata, $loginMember);
719+ $parser =& new PARSER($formAction->getAllowedActions(), $formAction);
720+ $parser->parse(&$contents);
721+ }
722+
723+ // }}}
724+ // {{{ showComment()
725+
726+ /**
727+ * Show comments
728+ *
729+ * @param object
730+ * @param string
731+ * @param string
732+ * @param string
733+ * @param string
734+ * @return void.
735+ */
736+ function showComment($commentItem, $template, $maxToShow, $commentOrder, $skinType)
737+ {
738+ global $manager, $member;
739+ $bid = getBlogIDFromItemID($commentItem->itemid);
740+ $b =& $manager->getBlog($bid);
741+ if (!$b->commentsEnabled()) return;
742+ if (!$maxToShow) {
743+ $maxToShow = $b->getMaxComments();
744+ }
745+ $itemActions =& new ITEMACTIONS($b);
746+ $itemActions->setCurrentItem($commentItem);
747+ $commentObj =& new COMMENTS($commentItem->itemid);
748+ $commentObj->setItemActions($itemActions);
749+ $commentObj->commentcount = $commentObj->amountComments();
750+ // create parser object & action handler
751+ include_once($this->getDirectory() . 'EzCommentActions.php');
752+ $actions =& new EzCommentActions($commentObj);
753+ $parser =& new PARSER($actions->getAllowedActions(), $actions);
754+ $actions->setTemplate($template);
755+ $actions->setParser($parser);
756+ if ($commentObj->commentcount == 0) {
757+ $parser->parse($template['COMMENTS_NONE']);
758+ return 0;
759+ }
760+ $actions->setPostnum($commentObj->commentcount);
761+ if ($maxToShow && $maxToShow < $commentObj->commentcount && $commentOrder) {
762+ $startnum = $commentObj->commentcount - $maxToShow;
763+ } else {
764+ $startnum = 0;
765+ }
766+ $comments = $this->getComments($commentOrder, intval($commentItem->itemid), $maxToShow, $startnum);
767+ $viewnum = mysql_num_rows($comments);
768+ $actions->setViewnum($viewnum);
769+ if ($this->getBlogOption($bid, 'secret') == 'yes') {
770+ $judge = $this->setSecretJudge($bid, $member, $b);
771+ }
772+
773+ $templateType = '';
774+ if ($skinType == 'template') $templateType = '_IDX';
775+ $blogURL = $b->getURL();
776+ $substitution = $this->getBlogOption($bid, 'secComment');
777+ $this->callFlg = true;
778+ $parser->parse($template['COMMENTS_HEADER' . $templateType]);
779+
780+ while ($comment = mysql_fetch_assoc($comments)) {
781+ $comment['timestamp'] = strtotime($comment['ctime']);
782+ if ($judge && $comment['secret']) {
783+ $comment = $this->JudgementCommentSecrets($comment, $judge);
784+ }
785+ $actions->setCurrentComment($comment);
786+ $manager->notify('PreComment', array('comment' => &$comment));
787+ $parser->parse($template['COMMENTS_BODY' . $templateType]);
788+ $manager->notify('PostComment', array('comment' => &$comment));
789+ }
790+
791+ $parser->parse($template['COMMENTS_FOOTER' . $templateType]);
792+
793+ mysql_free_result($comments);
794+
795+ }
796+
797+ // }}}
798+ // {{{ setSecretJudge($bid)
799+
800+ /**
801+ * Setting for judgment of whether it's a comment of a secret.
802+ *
803+ * @param intgre
804+ * @param object
805+ * @param object
806+ * @return array
807+ */
808+ function setSecretJudge($bid, $member, $b)
809+ {
810+ $memberLoggedin = $member->isLoggedin();
811+ $loginUser = $member->getID();
812+ $blogAdmin = $member->blogAdminRights($bid);
813+ $blogURL = $b->getURL();
814+ $substitution = $this->getBlogOption($bid, 'secComment');
815+ if ($this->authOpenID) {
816+ $openIDLoggedin = $this->authOpenID->isLoggedin();
817+ $openIDUser = $this->authOpenID->loggedinUser['identity'];
818+ }
819+ return array(
820+ 'memberLoggedin' => $memberLoggedin,
821+ 'loginUser' => $loginUser,
822+ 'blogAdmin' => $blogAdmin,
823+ 'blogURL' => $blogURL,
824+ 'substitution' => $substitution,
825+ 'openIDLoggedin' => $openIDLoggedin,
826+ 'openIDUser' => $openIDUser,
827+ );
828+ }
829+
830+ // }}}
831+ // {{{ JudgementCommentSecrets($comment, $judge)
832+
833+ /**
834+ * Comment is secret ?
835+ *
836+ * @param array
837+ * @param array
838+ * @param string
839+ * @param string
840+ * @return array
841+ */
842+ function JudgementCommentSecrets($comment, $judge)
843+ {
844+/* if ($judge['memberLoggedin']) {
845+ echo 'member';
846+ if ($judge['loginUser'] == intval($comment['identity'])) {
847+ echo 'commentator';
848+ } elseif ($judge['blogAdmin']) {
849+ echo 'admin';
850+ }
851+ } elseif ($judge['openIDLoggedin']) {
852+// echo 'openid / ';
853+ echo $judge['openIDUser'].' / ';
854+ echo $comment['identity'].' / ';
855+ echo "honnnin";
856+ }*/
857+ if (!(($judge['memberLoggedin'] && ($judge['loginUser'] == intval($comment['identity']) || $judge['blogAdmin'])) ||
858+ ($judge['openIDLoggedin'] && $judge['openIDUser'] == $comment['identity']))) {
859+ $this->changeCommentSet($comment, $judge);
860+ }
861+ return $comment;
862+ }
863+
864+ // }}}
865+ // {{{ changeCommentSet($comment, $blogURL, $substitution)
866+
867+ /**
868+ * Change secret comment contents
869+ *
870+ * @param array
871+ * @param string
872+ * @param string
873+ * @return array
874+ */
875+ function changeCommentSet(&$comment, $judge)
876+ {
877+ global $manager;
878+ $comment['body'] = $judge['substitution'];
879+ $comment['short'] = $judge['substitution'];
880+ $comment['excerpt'] = $judge['substitution'];
881+ $comment['userid'] = $judge['blogURL'];
882+ $comment['memberid'] = 0;
883+ $comment['user'] = '#';
884+ $comment['useremail'] = '#';
885+ $comment['userwebsite'] = '#';
886+ $comment['email'] = '#';
887+ $comment['userlinkraw'] = '#';
888+ $comment['userlink'] = '#';
889+ $comment['host'] = '127.0.0.1';
890+ $comment['ip'] = '127.0.0.1';
891+ if ($manager->pluginInstalled('NP_LatestWritebacks')) {
892+ $comment['commentbody'] = $judge['substitution'];
893+ $comment['commentator'] = '#';
894+ }
895+ return $comment;
896+ }
897+ // {{{ getComments($comment, $judge)
898+
899+ /**
900+ * Change in the comment contents.
901+ *
902+ * @param boolean
903+ * @param integre
904+ * @param integre
905+ * @param integre
906+ * @return resouce
907+ */
908+ function getComments($commentOrder, $iid, $maxToShow, $startnum)
909+ {
910+ $order = ($commentOrder) ? "DESC" : "ASC";
911+ $query = 'SELECT '
912+ . 'c.citem as itemid, '
913+ . 'c.cnumber as commentid, '
914+ . 'c.cbody as body, '
915+ . 'c.cuser as user, '
916+ . 'c.cmail as userid, '
917+ . 'c.cemail as email, '
918+ . 'c.cmember as memberid, '
919+ . 'c.ctime, '
920+ . 'c.chost as host, '
921+ . 'c.cip as ip, '
922+ . 'c.cblog as blogid, '
923+ . 's.comid as cid, '
924+ . 's.secflg as secret, '
925+ . 's.module as modname, '
926+ . 's.userID as identity '
927+ . ' FROM ' . sql_table('comment') . ' as c '
928+ . ' LEFT OUTER JOIN ' . sql_table('plug_ezcomment2') . ' as s '
929+ . ' ON c.cnumber = s.comid '
930+ . ' WHERE c.citem = ' . intval($iid)
931+ . ' ORDER BY c.ctime '
932+ . $order;
933+ if ($maxToShow) {
934+ if ($order == "DESC") {
935+ $query .=' LIMIT ' . intval($maxToShow);
936+ } else {
937+ $query .=' LIMIT ' . intval($startnum) . ',' . intval($maxToShow);
938+ }
939+ }
940+ return sql_query($query);
941+
942+ }
943+
944+ // }}}
945+ // {{{ getTemplateParts()
946+
947+ /**
948+ * Comment form/list template via NP_znSpecialTemplateParts
949+ *
950+ * @return array
951+ */
952+ function getTemplateParts()
953+ {
954+ $this->languageInclude();
955+ return array(
956+ 'FORM_LOGGEDIN_IDX' => _NP_EZCOMMENT2_FORM_LOGGEDIN_IDX,
957+ 'FORM_NOTLOGGEDIN_IDX' => _NP_EZCOMMENT2_FORM_NOTLOGGEDIN_IDX,
958+ 'FORM_LOGGEDIN_ITM' => _NP_EZCOMMENT2_FORM_LOGGEDIN_ITM,
959+ 'FORM_NOTLOGGEDIN_ITM' => _NP_EZCOMMENT2_FORM_NOTLOGGEDIN_ITM,
960+ 'COMMENTS_BODY_IDX' => _NP_EZCOMMENT2_COMMENTS_BODY_IDX,
961+ 'COMMENTS_FOOTER_IDX' => _NP_EZCOMMENT2_COMMENTS_FOOTER_IDX,
962+ 'COMMENTS_HEADER_IDX' => _NP_EZCOMMENT2_COMMENTS_HEADER_IDX,
963+ );
964+ }
965+
966+ // }}}
967+ // {{{ _hsc()
968+
969+ /**
970+ * HTML entity
971+ *
972+ * @param string
973+ * @return string
974+ */
975+ function _hsc($str)
976+ {
977+ return htmlspecialchars($str, ENT_QUOTES, _CHARSET);
978+ }
979+ // }}}
980+
981+}
982+
983+
984+
--- /dev/null
+++ b/NP_EzComment2/trunk/NP_EzComment2.php
@@ -0,0 +1,984 @@
1+<?php
2+/**
3+ * SHOW Comment Form/List PLUG-IN FOR NucleusCMS
4+ * PHP versions 5
5+ *
6+ * This program is free software; you can redistribute it and/or
7+ * modify it under the terms of the GNU General Public License
8+ * as published by the Free Software Foundation; either version 2
9+ * of the License, or (at your option) any later version.
10+ * (see nucleus/documentation/index.html#license for more info)
11+ *
12+ * @author shizuki
13+ * @copyright 2008 shizuki
14+ * @license http://www.gnu.org/licenses/gpl.txt GNU GENERAL PUBLIC LICENSE Version 2, June 1991
15+ * @version $Date$ $Revision: 1.13 $
16+ * @link http://japan.nucleuscms.org/wiki/plugins:ezcomment2
17+ * @since File available since Release 1.0
18+ */
19+
20+/**
21+ * version history
22+ *
23+ * $Log: not supported by cvs2svn $
24+ * Revision 1.12 2008/07/09 03:54:07 shizuki
25+ * *** empty log message ***
26+ *
27+ * Revision 1.11 2008/07/09 03:54:04 shizuki
28+ * *Fix header info URL:showblogs -> ezcomment2
29+ *
30+ * * Revision 1.10 2008/07/08 16:14:57 shizuki
31+ * *Bug fix event_PreComment
32+ * *Correspondence preparations of NP_LatestWritebacks
33+ *
34+ * Revision 1.9 2008/07/08 15:14:27 shizuki
35+ * * Corresponds to event_PreComment.
36+ * * Fix typo.
37+ * * RC2
38+ *
39+ * Revision 1.8 2008/07/07 15:42:54 shizuki
40+ * * The experimental society PHP Version: 5.2.6/MySQL Server Version (client): (5.1.25-rc-log 5.1.25-rc).
41+ * * The normal movement is confirmed.
42+ * * The SQL correction/behavior when installing, is changed a little.
43+ * * event_PostDeleteCommnent addition * It's corrected when being off login time and secret mode-lessly, so as not to take out a check box.
44+ * * NP_OpenId is indispensable in the present.
45+ * * NP_znSpecialTemplateParts is indispensable.
46+ * * It's expected to add the setting which will establish a password at the time of contribution without NP_OpenId and make it hidden from now on.
47+ * * It's RC edition, so please cooperate in the one with the environment.
48+ *
49+ * Revision 1.7 2008/07/07 10:24:00 shizuki
50+ * * Still, the human sacrifice test version.
51+ * * A template was separated for for index pages and item page.
52+ * * Subdivision of the showComment() function.
53+ * * It's changed so as not to fly to an indication part for indication in case of and OpenID of anything but the first item of an index page.
54+ * * A profile change part besides the first item of an index page is being adjusted.
55+ */
56+
57+class NP_EzComment2 extends NucleusPlugin
58+{
59+ // {{{ properties
60+
61+ /**
62+ * The calling number of times by the index page.
63+ *
64+ * @var integer
65+ */
66+ var $numcalled;
67+
68+ /**
69+ * OpenID authentication module.
70+ *
71+ * @var object
72+ */
73+ var $authOpenID;
74+
75+ /**
76+ * Flag of the case that one is invoker.
77+ *
78+ * @var boolean
79+ */
80+ var $callFlg;
81+
82+ // }}}
83+ // {{{ getName()
84+
85+ /**
86+ * Plugin Name
87+ *
88+ * @return string
89+ */
90+ function getName()
91+ {
92+ return 'Ez Comment II';
93+ }
94+
95+ // }}}
96+ // {{{ getAuthor()
97+
98+ /**
99+ * Author Name
100+ *
101+ * @return string
102+ */
103+ function getAuthor()
104+ {
105+ return 'shizuki';
106+ }
107+
108+ // }}}
109+ // {{{ getURL()
110+
111+ /**
112+ * I get a plug-in, the address of the possible site or author's mail address.
113+ *
114+ * @return string
115+ */
116+ function getURL()
117+ {
118+ return 'http://japan.nucleuscms.org/wiki/plugins:ezcomment2';
119+ }
120+
121+ // }}}
122+ // {{{ getPluginDep()
123+
124+ /**
125+ * Plugin Dependency.
126+ *
127+ * @return array
128+ */
129+ function getPluginDep()
130+ {
131+ return array(
132+ 'NP_OpenId',
133+ 'NP_znSpecialTemplateParts',
134+ );
135+ }
136+
137+ // }}}
138+ // {{{ getVersion()
139+
140+ /**
141+ * Plugin Version.
142+ *
143+ * @return string
144+ */
145+ function getVersion()
146+ {
147+ return '$Date$ $Revision: 1.13 $';
148+ }
149+
150+ // }}}
151+ // {{{ getDescription()
152+
153+ /**
154+ * Plugin Description
155+ *
156+ * @return string
157+ */
158+ function getDescription()
159+ {
160+ return _NP_EZCOMMENT2_DESC;
161+ }
162+
163+ // }}}
164+ // {{{ supportsFeature($what)
165+
166+ /**
167+ * Supports Nucleus Feature
168+ *
169+ * @param string
170+ * @return boolean
171+ */
172+ function supportsFeature($what)
173+ {
174+ switch ($what) {
175+ case 'SqlTablePrefix':
176+ return 1;
177+ default:
178+ return 0;
179+ }
180+ }
181+
182+ // }}}
183+ // {{{ getEventList()
184+
185+ /**
186+ * List of feature event
187+ *
188+ * @return array
189+ */
190+ function getEventList()
191+ {
192+ global $manager;
193+ return array(
194+ 'FormExtra',
195+ 'PostAddComment',
196+ 'PostDeleteComment',
197+ 'PreComment',
198+ );
199+ }
200+
201+ // }}}
202+ // {{{ getTableList()
203+
204+ /**
205+ * Database tables for plugin used
206+ *
207+ * @return array
208+ **/
209+ function getTableList()
210+ {
211+ return array(
212+ sql_table('plug_ezcomment2'),
213+ );
214+ }
215+
216+ // }}}
217+ // {{{ install()
218+
219+ /**
220+ * Install function
221+ *
222+ * @return void.
223+ */
224+ function install()
225+ {
226+ if (!TEMPLATE::exists('EzCommentTemplate')) {
227+ global $DIR_LIBS;
228+ include_once($DIR_LIBS . 'skinie.php');
229+ $importer = new SKINIMPORT();
230+ $importer->reset();
231+ $template = $this->getDirectory() . 'skinbackup.xml';
232+ if (!@file_exists($template)) {
233+ $aErrors[] = 'Unable to import ' . $template . ' : file does not exist';
234+ continue;
235+ }
236+ $error = $importer->readFile($template);
237+ if ($error) {
238+ $aErrors[] = 'Unable to import ' . $template . ' : ' . $error;
239+ continue;
240+ }
241+ $error = $importer->writeToDatabase(1);
242+ if ($error) {
243+ $aErrors[] = 'Unable to import ' . $template . ' : ' . $error;
244+ continue;
245+ }
246+ if ($aErrors) {
247+ $message = implode("<br />\n", $aErrors);
248+ doError($message);
249+ }
250+ }
251+ $this->createBlogOption('secret', _NP_EZCOMMENT2_OP_SECRETMODE, 'yesno', 'yes');
252+ $this->createBlogOption('secComment', _NP_EZCOMMENT2_OP_SUBSTIUTION, 'text', _NP_EZCOMMENT2_OP_SUBSTIUTION_VAL);
253+ $this->createBlogOption('secLabel', _NP_EZCOMMENT2_OP_CHECKLABEL, 'text', _NP_EZCOMMENT2_OP_CHECKLABEL_VAL);
254+ $this->createOption('tabledel', _NP_EZCOMMENT2_OP_DROPTABLE, 'yesno', 'yes');
255+ $sql = 'CREATE TABLE IF NOT EXISTS %s ('
256+ . '`comid` int(11) NOT NULL, '
257+ . '`secflg` tinyint(1) NULL, '
258+ . '`module` varchar(15) NULL, '
259+ . '`userID` varchar(255) NULL, '
260+ . 'PRIMARY KEY(`comid`) );';
261+ sql_query(sprintf($sql, sql_table('plug_ezcomment2')));
262+ $this->updateTable();
263+ }
264+
265+ // }}}
266+ // {{{ uninstall()
267+
268+ /**
269+ * Un Install function
270+ *
271+ * @return void.
272+ */
273+ function uninstall()
274+ {
275+ if ($this->getOption('tabledel') == 'yes')
276+ sql_query('DROP TABLE '.sql_table('plug_ezcomment2'));
277+ }
278+
279+ // }}}
280+ // {{{ init()
281+
282+ /**
283+ * Initialize
284+ *
285+ * @return void.
286+ */
287+ function init()
288+ {
289+ $this->languageInclude();
290+ $this->numcalled = 0;
291+ $this->callFlg = false;
292+ global $manager;
293+ if ($manager->pluginInstalled('NP_OpenId') && !$this->authOpenID) {
294+ $this->authOpenID = $manager->getPlugin('NP_OpenId');
295+ }
296+ }
297+
298+ // }}}
299+ // {{{ event_PostAddComment($data)
300+
301+ /**
302+ * After adding a comment to the database.
303+ *
304+ * @param array
305+ * commentid integer
306+ * comment array
307+ * spamcheck array
308+ * @return void.
309+ */
310+ function event_PostAddComment($data)
311+ {
312+ global $member;
313+ switch (true) {
314+ case $member->isLoggedin():
315+ $userID = '"' . $member->getID() . '"';
316+ $module = '"Nucleus"';
317+ break;
318+ case ($this->authOpenID && $this->authOpenID->isLoggedin()):
319+ $userID = '"' . $this->authOpenID->loggedinUser['identity'] . '"';
320+ $module = '"OpenID"';
321+ break;
322+ default:
323+ $userID = 'NULL';
324+ $module = 'NULL';
325+ break;
326+ }
327+ if (postVar('EzComment2_Secret')) {
328+ $secCheck = 1;
329+ } else {
330+ $secCheck = 'NULL';
331+ }
332+ $sql = 'INSERT INTO ' . sql_table('plug_ezcomment2')
333+ . ' (`comid`, `secflg`, `module`, `userID`) VALUES (%d, %d, %s, %s)';
334+ sql_query(sprintf($sql, $data['commentid'], $secCheck, $module, $userID));
335+ }
336+
337+ // }}}
338+ // {{{ event_PostDeleteComment($data)
339+
340+ /**
341+ * After a comment has been deleted from the database.
342+ *
343+ * @param array
344+ * commentid integer
345+ * @return void.
346+ */
347+ function event_PostDeleteComment($data)
348+ {
349+ $sql = 'DELETE FROM ' . sql_table('plug_ezcomment2')
350+ . ' WHERE `comid` = %d LIMIT 1';
351+ sql_query(sprintf($sql, $data['commentid']));
352+ }
353+
354+ // }}}
355+ // {{{ event_FormExtra(&$data)
356+
357+ /**
358+ * Inside one of the comment, membermail or account activation forms.
359+ *
360+ * @param array
361+ * type string
362+ * @return void.
363+ */
364+ function event_FormExtra(&$data)
365+ {
366+ global $member, $blogid;
367+ $this->numcalled++;
368+ if ($blogid && $this->getBlogOption($blogid, 'secret') == 'yes' &&
369+ ($member->isLoggedin() || ($this->authOpenID && $this->authOpenID->isLoggedin()))) {
370+ echo '<br /><input type="checkbox" value="1" name="EzComment2_Secret" id="EzComment2_Secret_' . $this->numcalled . '" />';
371+ echo '<label for="EzComment2_Secret_' . $this->numcalled . '">'.$this->getBlogOption($bid, 'secLabel').'</label><br />';
372+ }
373+ if ($this->authOpenID) {
374+ $this->plugOpenIDdoSkinVar($this->commentSkinType, $this->commentItemId);
375+ }
376+ }
377+
378+ // }}}
379+ // {{{ event_PreComment(&$data)
380+
381+ /**
382+ * Inside one of the comment, membermail or account activation forms.
383+ *
384+ * @param array
385+ * comment array
386+ * @return void.
387+ */
388+ function event_PreComment(&$data)
389+ {
390+ if ($this->callFlg) return;
391+ $sql = 'SELECT secflg, userID FROM ' . sql_table('plug_ezcomment2')
392+ . ' WHERE comid = ' . intval($data['comment']['commentid']);
393+ $res = sql_query($sql);
394+ $flg = mysql_fetch_assoc($res);
395+ if (!$flg['secflg']) return;
396+ $data['comment']['identity'] = $flg['userID'];
397+ global $manager, $member;
398+ $bid = intval($data['comment']['blogid']);
399+ $b = $manager->getBlog($bid);
400+ $judge = $this->setSecretJudge($bid, $member, $b);
401+ $data['comment'] = $this->JudgementCommentSecrets($data['comment'], $judge);
402+// print_r($data);
403+ }
404+
405+ // }}}
406+ // {{{ doTemplateVar()
407+
408+ /**
409+ * Basically the same as doSkinVar,
410+ * but this time for calls of the <%plugin(...)%>-var in templates (item header/body/footer and dateheader/footer).
411+ *
412+ * @param object item object(refarence)
413+ * @param string
414+ * @param string
415+ * @param string
416+ * @param string
417+ * @param string
418+ * @return void.
419+ */
420+ function doTemplateVar(&$item,
421+ $showType = '',
422+ $showMode = '5/1/1',
423+ $destinationurl = '',
424+ $formTemplate = 'EzCommentTemplate',
425+ $listTemplate = 'EzCommentTemplate')
426+ {
427+ $this->doSkinVar('template', $showType, $showMode, $destinationurl, $formTemplate, $listTemplate, $item);
428+ }
429+
430+ // }}}
431+ // {{{ doSkinVar()
432+
433+ /**
434+ * When plugins are called using the <%plugin(...)%>-skinvar, this method will be called.
435+ *
436+ * @param string
437+ * @param string
438+ * @param string
439+ * @param string
440+ * @param string
441+ * @param string
442+ * @param object item object(refarence)
443+ * @return void.
444+ */
445+ function doSkinVar($skinType,
446+ $showType = '',
447+ $showMode = '5/1/1',
448+ $destinationurl = '',
449+ $formTemplate = 'EzCommentTemplate',
450+ $listTemplate = 'EzCommentTemplate',
451+ &$commentItem = '')
452+ {
453+ if ($skinType != 'item' && $skinType != 'template') return;
454+ global $manager, $member, $itemid;
455+ if (!$commentItem && $itemid) {
456+ $commentItem = $manager->getItem($itemid, 0, 0);
457+ if (is_array($commentItem)) {
458+ $commentItem = (object)$commentItem;
459+ }
460+ }
461+ if (!$commentItem || $commentItem->closed) {
462+ echo _ERROR_ITEMCLOSED;
463+ return 0;
464+ }
465+
466+ if (is_numeric($showType) || strpos($showType, '/') !== false) $showMode = $showType;
467+ if ($showType != 'list' && $showType != 'form') {
468+ $showType = '';
469+ }
470+ if (!$showMode) {
471+ $showMode = '5/1/1';
472+ }
473+ list($maxToShow, $sortOrder, $commentOrder) = explode('/', $showMode);
474+ if (!$maxToShow) $maxToShow = 5;
475+ if (!$sortOrder) $sortOrder = 1;
476+ if ($commentOrder > 0) {
477+ $commentOrder = true;
478+ } else {
479+ $commentOrder = false;
480+ }
481+ if (!$formTemplate) $formTemplate = 'EzCommentTemplate';
482+ if (!$listTemplate) $listTemplate = 'EzCommentTemplate';
483+
484+ switch ($showType) {
485+ case 'list':
486+ $listTemplate = TEMPLATE::read($listTemplate);
487+ $this->showComment($commentItem, $listTemplate, $maxToShow, $commentOrder, $skinType);
488+ break;
489+ case 'form':
490+ $formTemplate = TEMPLATE::read($formTemplate);
491+ $this->showForm($commentItem, $formTemplate, $destinationurl, $skinType);
492+ break;
493+ default:
494+ $listTemplate = TEMPLATE::read($listTemplate);
495+ $formTemplate = TEMPLATE::read($formTemplate);
496+ if ($sortOrder) {
497+ $this->showComment($commentItem, $listTemplate, $maxToShow, $commentOrder, $skinType);
498+ $this->showForm($commentItem, $formTemplate, $destinationurl, $skinType);
499+ } else {
500+ $this->showForm($commentItem, $formTemplate, $destinationurl, $skinType);
501+ $this->showComment($commentItem, $listTemplate, $maxToShow, $commentOrder, $skinType);
502+ }
503+ break;
504+ }
505+ }
506+
507+ // }}}
508+ // {{{ languageInclude()
509+
510+ /**
511+ * Include language file
512+ *
513+ * @return void.
514+ */
515+ function languageInclude()
516+ {
517+ $language = ereg_replace( '[\\|/]', '', getLanguageName());
518+ if (file_exists($this->getDirectory() . 'language/' . $language . '.php')) {
519+ include_once($this->getDirectory() . 'language/' . $language . '.php');
520+ } else {
521+ include_once($this->getDirectory() . 'language/english.php');
522+ }
523+ }
524+
525+ // }}}
526+ // {{{ updateTable()
527+
528+ /**
529+ * Update database table
530+ *
531+ * @return void.
532+ */
533+ function updateTable()
534+ {
535+ $sql = 'SELECT c.cnumber as cid FROM ' . sql_table('comment') . ' as c '
536+ . 'LEFT JOIN ' . sql_table('plug_ezcomment2') . ' as s '
537+ . 'ON c.cnumber=s.comid WHERE s.comid IS NULL';
538+ $res = sql_query($sql);
539+ $sql = 'INSERT INTO ' . sql_table('plug_ezcomment2') . '(`comid`) VALUES (%d)';
540+ while ($cid = mysql_fetch_assoc($res)) {
541+ sql_query(sprintf($sql, $cid['cid']));
542+ }
543+ }
544+
545+ // }}}
546+ // {{{ plugOpenIDdoSkinVar()
547+
548+ /**
549+ * Overwride NP_OpenId's doSkinVar()
550+ *
551+ * @param string
552+ * @param integer
553+ * @return void.
554+ */
555+ function plugOpenIDdoSkinVar($skinType, $iid = 0)
556+ {
557+ global $CONF, $manager, $member;
558+ if ($member->isLoggedIn()) return;
559+ $authOpenID = $this->authOpenID;
560+ if (!$authOpenID) return;
561+ $externalauth = array ( 'source' => $authOpenID->getName() );
562+ $manager->notify('ExternalAuth', array ('externalauth' => &$externalauth));
563+ if (isset($externalauth['result']) && $externalauth['result'] == true) return;
564+ $templateEngine = $authOpenID->_getTemplateEngine();
565+ $aVars = array();
566+ $aVars['PluginURL'] = $CONF['PluginURL'];
567+ if ($authOpenID->isLoggedin()) {
568+ // Loggedin
569+ if ($skinType == 'template') {
570+ require_once 'cles/Template.php';
571+ $templateDirectory = rtrim($this->getDirectory(), '/');
572+ $templateEngine =& new cles_Template($templateDirectory);
573+ $templateEngine->defaultLang = 'english';
574+ $aVars['itemid'] = intval($iid);
575+ }
576+ $nowURL = 'http://' . serverVar("HTTP_HOST")
577+ . serverVar("REQUEST_URI");
578+ $aVars['url'] = $authOpenID->getAdminURL() . 'rd.php?action=rd'
579+ . '&url=' . urlencode($nowURL);
580+ $aVars['nick'] = $authOpenID->loggedinUser['nick'];
581+ $aVars['email'] = $authOpenID->loggedinUser['email'];
582+ $aVars['ts'] = $authOpenID->loggedinUser['ts'];
583+ $aVars['identity'] = $authOpenID->loggedinUser['identity'];
584+ $aVars['visible'] = $aVars['nick'] ? 'false' : 'true' ;
585+ $actionUrl = parse_url($CONF['ActionURL']);
586+ $aVars['updateUrl'] = $actionUrl['path'];
587+ if ($skinType == 'item' || ($skinType == 'template' && $this->numcalled == 0)) {
588+ echo $templateEngine->fetchAndFill('yui', $aVars, 'np_openid');
589+ echo $templateEngine->fetchAndFill('form', $aVars, 'np_openid');
590+ }
591+ echo $templateEngine->fetchAndFill('loggedin', $aVars, 'np_openid');
592+ } elseif (!$authOpenID->isLoggedin()) {
593+ // Not loggedin
594+ $aVars['url'] = $authOpenID->getAdminURL() . 'rd.php?action=doauth'
595+ . '&return_url=' . urlencode(createItemLink(intval($iid)));
596+ echo $templateEngine->fetchAndFill('notloggedin', $aVars, 'np_openid');
597+ }
598+ }
599+
600+ // }}}
601+ // {{{ checkDestinationurl($destinationurl)
602+
603+ /**
604+ * Destinationurl check
605+ *
606+ * @param string
607+ * @return string
608+ */
609+ function checkDestinationurl($destinationurl, $iid, $cid = 0, $scid = 0)
610+ {
611+ if (stristr($destinationurl, 'action.php') || empty($destinationurl)) {
612+ if (stristr($destinationurl, 'action.php')) {
613+ $logMessage = 'actionurl is not longer a parameter on commentform skinvars.'
614+ . ' Moved to be a global setting instead.';
615+ ACTIONLOG::add(WARNING, $logMessage);
616+ }
617+ if ($cid) {
618+ $linkparams['catid'] = intval($cid);
619+ }
620+ global $manager;
621+ if ($manager->pluginInstalled('NP_MultipleCategories') && $scid) {
622+ $linkparams['subcatid'] = intval($scid);
623+ }
624+ $destinationurl = createItemLink(intval($iid), $linkparams);
625+ } else {
626+ $destinationurl = preg_replace('|[^a-z0-9-~+_.?#=&;,/:@%]|i', '', $destinationurl);
627+ }
628+ return $destinationurl;
629+ }
630+
631+ // }}}
632+ // {{{ getCommentatorInfo()
633+
634+ /**
635+ * Get commentator info.
636+ *
637+ * @return array
638+ */
639+ function getCommentatorInfo()
640+ {
641+ global $CONF;
642+ $user = cookieVar($CONF['CookiePrefix'] .'comment_user');
643+ if (!$user) {
644+ $user = postVar('user');
645+ }
646+ $userid = cookieVar($CONF['CookiePrefix'] .'comment_userid');
647+ if (!$userid) {
648+ $userid = postVar('userid');
649+ }
650+ $email = cookieVar($CONF['CookiePrefix'] .'comment_email');
651+ if (!$email) {
652+ $email = postVar('email');
653+ }
654+ $body = postVar('body');
655+ return array(
656+ $user,
657+ $userid,
658+ $email,
659+ $body
660+ );
661+ }
662+ // {{{ showForm()
663+
664+ /**
665+ * Show comment form
666+ *
667+ * @param object
668+ * @param string
669+ * @param string
670+ * @param string
671+ * @return void.
672+ */
673+ function showForm($commentItem, $template, $destinationurl, $skinType)
674+ {
675+ global $CONF, $manager, $member, $catid, $subcatid;
676+ $bid = getBlogIDFromItemID($commentItem->itemid);
677+ $b =& $manager->getBlog($bid);
678+ $b->readSettings();
679+ if (!$member->isLoggedIn() && !$b->commentsEnabled()) {
680+ return;
681+ }
682+ $destinationurl = $this->checkDestinationurl($destinationurl, $commentItem->itemid, $catid, $subcatid);
683+ list($user, $userid, $email, $body) = $this->getCommentatorInfo();
684+
685+ $checked = cookieVar($CONF['CookiePrefix'] .'comment_user') ? 'checked="checked" ' : '';
686+
687+ $formdata = array(
688+ 'self' => $this->_hsc(serverVar('REQUEST_URI')),
689+ 'destinationurl' => $this->_hsc($destinationurl),
690+ 'actionurl' => $this->_hsc($CONF['ActionURL']),
691+ 'itemid' => intval($commentItem->itemid),
692+ 'user' => $this->_hsc($user),
693+ 'userid' => $this->_hsc($userid),
694+ 'email' => $this->_hsc($email),
695+ 'body' => $this->_hsc($body),
696+// 'membername' => $this->_hsc($membername),
697+ 'rememberchecked' => $checked
698+ );
699+ if ($skinType == 'item') {
700+ $formFlg = '_ITM';
701+ } else {
702+ $formFlg = '_IDX';
703+ }
704+ if ($member && $member->isLoggedIn()) {
705+ $formType = 'FORM_LOGGEDIN' . $formFlg;
706+ $loginMember = $member->createFromID($member->getID());
707+ $formdata['membername'] = $this->_hsc($loginMember->getDisplayName());
708+ } else {
709+ $formType = 'FORM_NOTLOGGEDIN' . $formFlg;
710+ }
711+ if ($this->authOpenID && ($skinType == 'item' || $this->numcalled == 0)) {
712+ $this->plugOpenIDdoSkinVar($skinType, intval($commentItem->itemid));
713+ }
714+ $this->commentItemId = intval($commentItem->itemid);
715+ $this->commentSkinType = $skinType;
716+ $contents = $template[$formType];
717+ include_once($this->getDirectory() . 'EzCommentActions.php');
718+ $formAction =& new EzCommentFormActions($commentItem, $formdata, $loginMember);
719+ $parser =& new PARSER($formAction->getAllowedActions(), $formAction);
720+ $parser->parse(&$contents);
721+ }
722+
723+ // }}}
724+ // {{{ showComment()
725+
726+ /**
727+ * Show comments
728+ *
729+ * @param object
730+ * @param string
731+ * @param string
732+ * @param string
733+ * @param string
734+ * @return void.
735+ */
736+ function showComment($commentItem, $template, $maxToShow, $commentOrder, $skinType)
737+ {
738+ global $manager, $member;
739+ $bid = getBlogIDFromItemID($commentItem->itemid);
740+ $b =& $manager->getBlog($bid);
741+ if (!$b->commentsEnabled()) return;
742+ if (!$maxToShow) {
743+ $maxToShow = $b->getMaxComments();
744+ }
745+ $itemActions =& new ITEMACTIONS($b);
746+ $itemActions->setCurrentItem($commentItem);
747+ $commentObj =& new COMMENTS($commentItem->itemid);
748+ $commentObj->setItemActions($itemActions);
749+ $commentObj->commentcount = $commentObj->amountComments();
750+ // create parser object & action handler
751+ include_once($this->getDirectory() . 'EzCommentActions.php');
752+ $actions =& new EzCommentActions($commentObj);
753+ $parser =& new PARSER($actions->getAllowedActions(), $actions);
754+ $actions->setTemplate($template);
755+ $actions->setParser($parser);
756+ if ($commentObj->commentcount == 0) {
757+ $parser->parse($template['COMMENTS_NONE']);
758+ return 0;
759+ }
760+ $actions->setPostnum($commentObj->commentcount);
761+ if ($maxToShow && $maxToShow < $commentObj->commentcount && $commentOrder) {
762+ $startnum = $commentObj->commentcount - $maxToShow;
763+ } else {
764+ $startnum = 0;
765+ }
766+ $comments = $this->getComments($commentOrder, intval($commentItem->itemid), $maxToShow, $startnum);
767+ $viewnum = mysql_num_rows($comments);
768+ $actions->setViewnum($viewnum);
769+ if ($this->getBlogOption($bid, 'secret') == 'yes') {
770+ $judge = $this->setSecretJudge($bid, $member, $b);
771+ }
772+
773+ $templateType = '';
774+ if ($skinType == 'template') $templateType = '_IDX';
775+ $blogURL = $b->getURL();
776+ $substitution = $this->getBlogOption($bid, 'secComment');
777+ $this->callFlg = true;
778+ $parser->parse($template['COMMENTS_HEADER' . $templateType]);
779+
780+ while ($comment = mysql_fetch_assoc($comments)) {
781+ $comment['timestamp'] = strtotime($comment['ctime']);
782+ if ($judge && $comment['secret']) {
783+ $comment = $this->JudgementCommentSecrets($comment, $judge);
784+ }
785+ $actions->setCurrentComment($comment);
786+ $manager->notify('PreComment', array('comment' => &$comment));
787+ $parser->parse($template['COMMENTS_BODY' . $templateType]);
788+ $manager->notify('PostComment', array('comment' => &$comment));
789+ }
790+
791+ $parser->parse($template['COMMENTS_FOOTER' . $templateType]);
792+
793+ mysql_free_result($comments);
794+
795+ }
796+
797+ // }}}
798+ // {{{ setSecretJudge($bid)
799+
800+ /**
801+ * Setting for judgment of whether it's a comment of a secret.
802+ *
803+ * @param intgre
804+ * @param object
805+ * @param object
806+ * @return array
807+ */
808+ function setSecretJudge($bid, $member, $b)
809+ {
810+ $memberLoggedin = $member->isLoggedin();
811+ $loginUser = $member->getID();
812+ $blogAdmin = $member->blogAdminRights($bid);
813+ $blogURL = $b->getURL();
814+ $substitution = $this->getBlogOption($bid, 'secComment');
815+ if ($this->authOpenID) {
816+ $openIDLoggedin = $this->authOpenID->isLoggedin();
817+ $openIDUser = $this->authOpenID->loggedinUser['identity'];
818+ }
819+ return array(
820+ 'memberLoggedin' => $memberLoggedin,
821+ 'loginUser' => $loginUser,
822+ 'blogAdmin' => $blogAdmin,
823+ 'blogURL' => $blogURL,
824+ 'substitution' => $substitution,
825+ 'openIDLoggedin' => $openIDLoggedin,
826+ 'openIDUser' => $openIDUser,
827+ );
828+ }
829+
830+ // }}}
831+ // {{{ JudgementCommentSecrets($comment, $judge)
832+
833+ /**
834+ * Comment is secret ?
835+ *
836+ * @param array
837+ * @param array
838+ * @param string
839+ * @param string
840+ * @return array
841+ */
842+ function JudgementCommentSecrets($comment, $judge)
843+ {
844+/* if ($judge['memberLoggedin']) {
845+ echo 'member';
846+ if ($judge['loginUser'] == intval($comment['identity'])) {
847+ echo 'commentator';
848+ } elseif ($judge['blogAdmin']) {
849+ echo 'admin';
850+ }
851+ } elseif ($judge['openIDLoggedin']) {
852+// echo 'openid / ';
853+ echo $judge['openIDUser'].' / ';
854+ echo $comment['identity'].' / ';
855+ echo "honnnin";
856+ }*/
857+ if (!(($judge['memberLoggedin'] && ($judge['loginUser'] == intval($comment['identity']) || $judge['blogAdmin'])) ||
858+ ($judge['openIDLoggedin'] && $judge['openIDUser'] == $comment['identity']))) {
859+ $this->changeCommentSet($comment, $judge);
860+ }
861+ return $comment;
862+ }
863+
864+ // }}}
865+ // {{{ changeCommentSet($comment, $blogURL, $substitution)
866+
867+ /**
868+ * Change secret comment contents
869+ *
870+ * @param array
871+ * @param string
872+ * @param string
873+ * @return array
874+ */
875+ function changeCommentSet(&$comment, $judge)
876+ {
877+ global $manager;
878+ $comment['body'] = $judge['substitution'];
879+ $comment['short'] = $judge['substitution'];
880+ $comment['excerpt'] = $judge['substitution'];
881+ $comment['userid'] = $judge['blogURL'];
882+ $comment['memberid'] = 0;
883+ $comment['user'] = '#';
884+ $comment['useremail'] = '#';
885+ $comment['userwebsite'] = '#';
886+ $comment['email'] = '#';
887+ $comment['userlinkraw'] = '#';
888+ $comment['userlink'] = '#';
889+ $comment['host'] = '127.0.0.1';
890+ $comment['ip'] = '127.0.0.1';
891+ if ($manager->pluginInstalled('NP_LatestWritebacks')) {
892+ $comment['commentbody'] = $judge['substitution'];
893+ $comment['commentator'] = '#';
894+ }
895+ return $comment;
896+ }
897+ // {{{ getComments($comment, $judge)
898+
899+ /**
900+ * Change in the comment contents.
901+ *
902+ * @param boolean
903+ * @param integre
904+ * @param integre
905+ * @param integre
906+ * @return resouce
907+ */
908+ function getComments($commentOrder, $iid, $maxToShow, $startnum)
909+ {
910+ $order = ($commentOrder) ? "DESC" : "ASC";
911+ $query = 'SELECT '
912+ . 'c.citem as itemid, '
913+ . 'c.cnumber as commentid, '
914+ . 'c.cbody as body, '
915+ . 'c.cuser as user, '
916+ . 'c.cmail as userid, '
917+ . 'c.cemail as email, '
918+ . 'c.cmember as memberid, '
919+ . 'c.ctime, '
920+ . 'c.chost as host, '
921+ . 'c.cip as ip, '
922+ . 'c.cblog as blogid, '
923+ . 's.comid as cid, '
924+ . 's.secflg as secret, '
925+ . 's.module as modname, '
926+ . 's.userID as identity '
927+ . ' FROM ' . sql_table('comment') . ' as c '
928+ . ' LEFT OUTER JOIN ' . sql_table('plug_ezcomment2') . ' as s '
929+ . ' ON c.cnumber = s.comid '
930+ . ' WHERE c.citem = ' . intval($iid)
931+ . ' ORDER BY c.ctime '
932+ . $order;
933+ if ($maxToShow) {
934+ if ($order == "DESC") {
935+ $query .=' LIMIT ' . intval($maxToShow);
936+ } else {
937+ $query .=' LIMIT ' . intval($startnum) . ',' . intval($maxToShow);
938+ }
939+ }
940+ return sql_query($query);
941+
942+ }
943+
944+ // }}}
945+ // {{{ getTemplateParts()
946+
947+ /**
948+ * Comment form/list template via NP_znSpecialTemplateParts
949+ *
950+ * @return array
951+ */
952+ function getTemplateParts()
953+ {
954+ $this->languageInclude();
955+ return array(
956+ 'FORM_LOGGEDIN_IDX' => _NP_EZCOMMENT2_FORM_LOGGEDIN_IDX,
957+ 'FORM_NOTLOGGEDIN_IDX' => _NP_EZCOMMENT2_FORM_NOTLOGGEDIN_IDX,
958+ 'FORM_LOGGEDIN_ITM' => _NP_EZCOMMENT2_FORM_LOGGEDIN_ITM,
959+ 'FORM_NOTLOGGEDIN_ITM' => _NP_EZCOMMENT2_FORM_NOTLOGGEDIN_ITM,
960+ 'COMMENTS_BODY_IDX' => _NP_EZCOMMENT2_COMMENTS_BODY_IDX,
961+ 'COMMENTS_FOOTER_IDX' => _NP_EZCOMMENT2_COMMENTS_FOOTER_IDX,
962+ 'COMMENTS_HEADER_IDX' => _NP_EZCOMMENT2_COMMENTS_HEADER_IDX,
963+ );
964+ }
965+
966+ // }}}
967+ // {{{ _hsc()
968+
969+ /**
970+ * HTML entity
971+ *
972+ * @param string
973+ * @return string
974+ */
975+ function _hsc($str)
976+ {
977+ return htmlspecialchars($str, ENT_QUOTES, _CHARSET);
978+ }
979+ // }}}
980+
981+}
982+
983+
984+
--- /dev/null
+++ b/NP_ItemNaviEX/tags/NP_ItemNaviEX.php
@@ -0,0 +1,582 @@
1+<?php
2+/**
3+ *
4+ * BreadCrumbsList PLUG-IN FOR NucleusCMS
5+ * PHP versions 4 and 5
6+ *
7+ * This program is free software; you can redistribute it and/or
8+ * modify it under the terms of the GNU General Public License
9+ * as published by the Free Software Foundation; either version 2
10+ * of the License, or (at your option) any later version.
11+ * (see nucleus/documentation/index.html#license for more info)
12+ *
13+ * @author Original Author nakahara21
14+ * @copyright 2005-2006 nakahara21
15+ * @license http://www.gnu.org/licenses/gpl.txt GNU GENERAL PUBLIC LICENSE Version 2, June 1991
16+ * @version 0.992
17+ * @link http://japan.nucleuscms.org/wiki/plugins:itemnaviex
18+ *
19+ * 0.993 Henceforth to template
20+ * 0.992 display mode '0' fix
21+ * 0.991 add sub-blog home mode
22+ * 0.99 sec fix
23+ *
24+ **************************************************************************
25+ *
26+ * THESE PLUG-INS ARE DEDICATED TO ALL THOSE NucleusCMS USERS
27+ * WHO FIGHT CORRUPTION AND IRRATIONAL IN EVERY DAY OF THEIR LIVES.
28+ *
29+ **************************************************************************/
30+
31+class NP_ItemNaviEX extends NucleusPlugin
32+{
33+ function getName()
34+ {
35+ return 'Navigation Bar';
36+ }
37+
38+ function getAuthor()
39+ {
40+ return 'nakahara21 + shizuki';
41+ }
42+
43+ function getURL()
44+ {
45+ return 'http://japan.nucleuscms.org/wiki/plugins:itemnaviex';
46+ }
47+
48+ function getVersion()
49+ {
50+ return '0.993';
51+ }
52+
53+ function getDescription()
54+ {
55+ // include language file for this plugin
56+ $language = ereg_replace( '[\\|/]', '', getLanguageName());
57+ if (file_exists($this->getDirectory() . $language . '.php')) {
58+ include_once($this->getDirectory() . $language . '.php');
59+ } else {
60+ include_once($this->getDirectory() . 'english.php');
61+ }
62+ $description = _NP_INEX_DESC;
63+// $description = 'Add link to prev item and next item. '
64+// . 'Usage: &lt;%ItemNaviEX%&gt; or &lt;%ItemNaviEX(0)%&gt;'
65+// . ' or &lt;%ItemNaviEX(1)%&gt; or &lt;%ItemNaviEX(2)%&gt;';
66+ return $description;
67+ }
68+
69+ function supportsFeature($what)
70+ {
71+ switch ($what) {
72+ case 'SqlTablePrefix':
73+ return 1;
74+ default:
75+ return 0;
76+ }
77+ }
78+
79+ function scanEndKey($array)
80+ {
81+ $keys = array_keys($array);
82+ rsort($keys);
83+ return $keys[0];
84+ }
85+
86+ function createNaviLink($unitArray)
87+ {
88+ if ($unitArray[1]) {
89+ $tempLink = '<a href="' . htmlspecialchars($unitArray[1], ENT_QUOTES, _CHARSET) . '">'
90+ . htmlspecialchars($unitArray[0], ENT_QUOTES, _CHARSET) . '</a>';
91+ } else {
92+ $tempLink = htmlspecialchars($unitArray[0], ENT_QUOTES, _CHARSET);
93+ }
94+ return $tempLink;
95+ }
96+
97+ function checkParent()
98+ {
99+ global $manager;
100+// if ($manager->pluginInstalled('NP_MultipleCategories')) {
101+// $mplugin =& $manager->getPlugin('NP_MultipleCategories');
102+// if (method_exists($mplugin,"getRequestName")) {
103+ $query = 'SHOW FIELDS FROM ' . sql_table('plug_multiple_categories_sub');
104+ $res = sql_query($query);
105+ while ($co = mysql_fetch_assoc($res)) {
106+ if ($co['Field'] == 'parentid') {
107+ return TRUE;
108+ }
109+ }
110+// }
111+// }
112+ }
113+
114+ function doSkinVar($skinType, $showHome = 1)
115+ {
116+ global $manager, $CONF, $blog, $itemid, $itemidprev, $itemidnext;
117+ global $catid, $subcatid, $archive, $archiveprev, $archivenext, $param;
118+
119+// sanitize
120+ $y = $m = $d = '';
121+ $itemid = intval($itemid);
122+ $catid = intval($catid);
123+ $subcatid = intval($subcatid);
124+ $itemidprev = intval($itemidprev);
125+ $itemidnext = intval($itemidnext);
126+ if (isset($archive)) {
127+ sscanf($archive,'%d-%d-%d', $y, $m, $d);
128+ if ($y && $m && !empty($d)) {
129+ $archive = sprintf('%04d-%02d-%02d', $y, $m, $d);
130+ } elseif ($y && $m && empty($d)) {
131+ $archive = sprintf('%04d-%02d', $y, $m);
132+ }
133+ }
134+ if (isset($archiveprev)) {
135+ sscanf($archiveprev,'%d-%d-%d', $y, $m, $d);
136+ if ($y && $m && !empty($d)) {
137+ $archiveprev = sprintf('%04d-%02d-%02d', $y, $m, $d);
138+ } elseif ($y && $m && empty($d)) {
139+ $archiveprev = sprintf('%04d-%02d', $y, $m);
140+ }
141+ }
142+ if (isset($archiveprev)) {
143+ sscanf($archiveprev,'%d-%d-%d', $y, $m, $d);
144+ if ($y && $m && !empty($d)) {
145+ $archiveprev = sprintf('%04d-%02d-%02d', $y, $m, $d);
146+ } elseif ($y && $m && empty($d)) {
147+ $archiveprev = sprintf('%04d-%02d', $y, $m);
148+ }
149+ }
150+ if ($showHome == '') {
151+ $showHome = 1;
152+ } else {
153+ $showHome = intval($showHome);
154+ }
155+
156+ if ($catid) {
157+ $blogid = getBlogIDFromCatID($catid);
158+ $b =& $manager->getBlog($blogid);
159+ } elseif ($blog) {
160+ $b =& $blog;
161+ } else {
162+ $b =& $manager->getBlog($CONF['DefaultBlog']);
163+ }
164+ $blogid = intval($b->getID());
165+
166+ $abuf = '';
167+ $mtable = '';
168+ $where .= ' and i.iblog=' . $blogid;
169+ if (!empty($catid)) {
170+ if ($manager->pluginInstalled('NP_MultipleCategories')) {
171+ $where .= ' and ((i.inumber = p.item_id'
172+ . ' and (p.categories REGEXP "(^|,)' . $catid . '(,|$)"'
173+ . ' or i.icat = ' . $catid . '))'
174+ . ' or (i.icat = ' . $catid
175+ . ' and p.item_id IS NULL))';
176+ $mtable = ' LEFT JOIN ' . sql_table('plug_multiple_categories') . ' as p'
177+ . ' ON i.inumber = p.item_id';
178+ $mplugin =& $manager->getPlugin('NP_MultipleCategories');
179+ if ($subcatid && method_exists($mplugin, 'getRequestName')) {
180+//family
181+ if ($this->checkParent()) {
182+ $Children = array();
183+ $Children = explode('/', $subcatid . $this->getChildren($subcatid));
184+ }
185+ if ($Children[1]) {
186+ for ($i=0;$i<count($Children);$i++) {
187+ $temp_whr[] = ' p.subcategories REGEXP "(^|,)' . intval($Children[$i]) . '(,|$)" ';
188+ }
189+ $where .= ' and ';
190+ $where .= ' ( ';
191+ $where .= join(' or ', $temp_whr);
192+ $where .= ' )';
193+ }else{
194+ $where .= ' and p.subcategories REGEXP "(^|,)' . $subcatid . '(,|$)"';
195+ }
196+//family end
197+ }
198+ } else {
199+ $where .= ' and i.icat=' . $catid;
200+ }
201+ }
202+ $naviUnit = array();
203+ $subNaviUnit = array();
204+ $this->linkparams = array();
205+ $nextLabel = $this->getOption('PNNextLabel');
206+ $prevLabel = $this->getOption('PNPrevLabel');
207+//store Home =====================================
208+//*// comment out this block when HOME is sub-blog top
209+ if ($showHome == 1) {
210+// $defBlogid =intval($CONF['DefaultBlog']);
211+ $tempBlog =& $manager->getBlog(intval($CONF['DefaultBlog']));
212+ $naviUnit[] = array(
213+ 0 => 'Home',
214+// 1 => createBlogidLink($defBlogid),
215+ 1 => $tempBlog->getURL(),
216+ 2 => createArchiveListLink($blogid)
217+ );
218+ }
219+//*/
220+//store Blog =====================================
221+ if ($showHome == 1 && ($blogid <> $CONF['DefaultBlog'])) {
222+ $naviUnit[] = array(
223+ 0 => getBlogNameFromID($blogid),
224+ 1 => createBlogidLink($blogid),
225+ 2 => createArchiveListLink($blogid)
226+ );
227+ } elseif ($showHome >= 2 || ($showHome == 0 && ($catid || $itemid))) {
228+ $naviUnit[] = array(
229+ 0 => 'Home', // when HOME is sub-blog top
230+ 1 => createBlogidLink($blogid), // when HOME is sub-blog top
231+ 2 => createArchiveListLink($blogid)
232+ );
233+ }
234+
235+//store Category =====================================
236+ if (!empty($catid)) {
237+ $this->linkparams['catid'] = $catid;
238+ $naviUnit[] = array(
239+ 0 => $b->getCategoryName($catid),
240+ 1 => createCategoryLink($catid),
241+// 1 => createBlogidLink($blogid, $this->linkparams),
242+ 2 => createArchiveListLink($blogid, $this->linkparams)
243+ );
244+ }
245+
246+//store subCategory =====================================
247+ if (!empty($subcatid)) {
248+ if ($manager->pluginInstalled('NP_MultipleCategories')) {
249+ $mplugin =& $manager->getPlugin('NP_MultipleCategories');
250+ if (method_exists($mplugin, 'getRequestName')) {
251+ $subrequest = $mplugin->getRequestName(array());
252+ $this->linkparams[$subrequest] = $subcatid;
253+ if ($this->checkParent()) {
254+ $tog = $this->getParenta($subcatid, $blogid);
255+ for ($i=0; $i<count($this->r); $i++) {
256+ $naviUnit[] = $this->r[$i];
257+ }
258+ $naviUnit[] = $tog;
259+ } else {
260+ $naviUnit[] = array(
261+ 0 => $mplugin->_getScatNameFromID($subcatid),
262+ 1 => createCategoryLink($catid, array($subrequest => $subcatid)),
263+// 1 => createCategoryLink($catid, array('subcatid' => $subcatid)),
264+// 1 => createBlogidLink($blogid, $this->linkparams),
265+ 2 => createArchiveListLink($blogid, $this->linkparams)
266+ );
267+ }
268+ }
269+ }
270+ }
271+
272+//store Page ===================================== todo How to get PageNo. ? ...cookie...
273+ if (intRequestVar('page') != 0) {
274+ $naviUnit[] = array(
275+ 0 => 'Page.' . intRequestVar('page'),
276+ 2 => createArchiveListLink($blogid, $this->linkparams)
277+ );
278+ }
279+
280+//store Item =====================================
281+ if ($skinType == 'item') {
282+ $item =& $manager->getItem($itemid, 0, 0);
283+ $naviUnit[] = array(
284+ 0 => $item['title']
285+ );
286+
287+ $query = 'SELECT i.ititle, i.inumber'
288+ . ' FROM ' . sql_table('item') . ' as i' . $mtable
289+ . ' WHERE i.idraft = 0'
290+ . " and i.itime < '" . $item['itime'] . "' " . $where
291+ . ' ORDER BY i.itime DESC';
292+ $res = sql_query($query);
293+ if ($ares = mysql_fetch_row($res)) {
294+ $alink = createItemLink($ares[1], $this->linkparams);
295+ $subNaviUnit[1] = '<a href="'
296+ . htmlspecialchars($alink, ENT_QUOTES, _CHARSET)
297+ . '" rel="prev"> ' . $prevLabel . ' '
298+ . shorten($ares[0], 14, '...')
299+ . '</a>';
300+ }
301+
302+ $query = 'SELECT i.ititle, i.inumber'
303+ . ' FROM ' . sql_table('item') . ' as i' . $mtable
304+ . ' WHERE i.idraft = 0'
305+ . " and i.itime > '" . $item['itime'] . "' " . $where
306+ . ' ORDER BY i.itime ASC';
307+ $res = sql_query($query);
308+ if ($ares = mysql_fetch_row($res)) {
309+ $alink = createItemLink($ares[1], $this->linkparams);
310+ $subNaviUnit[2] = '<a href="'
311+ . htmlspecialchars($alink, ENT_QUOTES, _CHARSET)
312+ . '" rel="next"> '
313+ . shorten($ares[0], 14, '...')
314+ . ' ' . $nextLabel . '</a>';
315+ }
316+
317+ }
318+
319+//store ArchiveList =====================================
320+ if ($skinType == 'archivelist' || $skinType == 'archive') {
321+ $naviUnit[] = array(
322+ 0 => $this->getOption('archivelinkLabel'),
323+// 0 => 'ArchiveList',
324+ 1 => createArchiveListLink($blogid, $this->linkparams)
325+ );
326+ }
327+
328+ if ($skinType == 'archive') {
329+ sscanf($archive,'%d-%d-%d', $y, $m, $d);
330+//store ArchiveMonth
331+ $archiveMonth = $y . '-' . $m;
332+ $naviUnit[] = array(
333+ 0 => $archiveMonth,
334+ 1 => createArchiveLink($blogid, $archiveMonth, $this->linkparams)
335+ );
336+ if (empty($d)) {
337+ $timestamp_start = mktime(0, 0, 0, $m, 1, $y);
338+ $timestamp_end = mktime(0, 0, 0, $m+1, 1, $y);
339+ $date_str = 'SUBSTRING(i.itime, 1, 7)';
340+ } else {
341+ $timestamp_start = mktime(0, 0, 0, $m, $d, $y);
342+ $timestamp_end = mktime(0, 0, 0, $m, $d+1, $y);
343+ $date_str = 'SUBSTRING(i.itime, 1, 10)';
344+//store ArchiveDay
345+ $naviUnit[] = array(
346+ 0 => $y . '-' . $m . '-' . $d,
347+ 1 => createArchiveLink($blogid, $archive, $this->linkparams)
348+ );
349+ }
350+
351+//=============================
352+ $query = 'SELECT ' . $date_str . ' as Date'
353+ . ' FROM ' . sql_table('item') . ' as i' . $mtable
354+ . ' WHERE i.idraft = 0'
355+ . ' and i.itime < ' . mysqldate($timestamp_start) . $where
356+ . ' GROUP BY Date'
357+ . ' ORDER BY i.itime DESC';
358+ $res = sql_query($query);
359+ if ($ares = mysql_fetch_row($res)) {
360+// $prev_date = $ares[0];
361+ sscanf($ares[0], '%d-%d-%d', $y, $m, $d);
362+ if (empty($d)) {
363+ $prev_date = sprintf('%04d-%02d', $y, $m);
364+ } else {
365+ $prev_date = sprintf('%04d-%02d-%02d', $y, $m, $d);
366+ }
367+ $prev_alink = createArchiveLink($blogid, $prev_date, $this->linkparams);
368+ $subNaviUnit[1] = '<a href="'
369+ . htmlspecialchars($prev_alink, ENT_QUOTES, _CHARSET)
370+ . '" class="prevlink" rel="prev">'
371+ . ' ' . $prevLabel . ' '
372+ . htmlspecialchars($prev_date, ENT_QUOTES, _CHARSET)
373+ . '</a>';
374+// $abuf .= '<a href="'.$prev_alink.'" class="prevlink" rel="prev">'.$prev_date.'</a>';
375+// } else {
376+// $today_link = createBlogidLink($b->getID(), $this->linkparams);
377+// $abuf .= ' ( <a href="'.$today_link.'">Today</a> )';
378+ }
379+ $abuf .= ' | <strong>' . htmlspecialchars($archive, ENT_QUOTES, _CHARSET) . '</strong> ';
380+//=============================
381+ $query = 'SELECT ' . $date_str . ' as Date'
382+ . ' FROM ' . sql_table('item') . ' as i' . $mtable
383+ . ' WHERE i.idraft = 0'
384+ . ' and i.itime < ' . mysqldate($b->getCorrectTime())
385+ . ' and i.itime >= ' . mysqldate($timestamp_end) . $where
386+ . ' GROUP BY Date'
387+ . ' ORDER BY i.itime ASC';
388+ $res = sql_query($query);
389+ if ($ares = mysql_fetch_row($res)) {
390+// $next_date = $ares[0];
391+ sscanf($ares[0],'%d-%d-%d', $y, $m, $d);
392+ if (empty($d)) {
393+ $next_date = sprintf('%04d-%02d', $y, $m);
394+ } else {
395+ $next_date = sprintf('%04d-%02d-%02d', $y, $m, $d);
396+ }
397+ $next_alink = createArchiveLink($blogid, $next_date, $this->linkparams);
398+ $subNaviUnit[2] = '<a href="'
399+ . htmlspecialchars($next_alink, ENT_QUOTES, _CHARSET)
400+ . '" class="nextlink" rel="next">'
401+ . htmlspecialchars($next_date, ENT_QUOTES, _CHARSET)
402+ . ' ' . $nextLabel . '</a>';
403+// $a2buf = ' | <a href="'.$next_alink.'" class="nextlink" rel="next">'.$next_date.'</a>';
404+// } else {
405+// $today_link = createBlogidLink($b->getID(), $this->linkparams);
406+// $a2buf .= ' | ( <a href="'.$today_link.'">Today</a> )';
407+ }
408+ }
409+//============================= // end of archive(s)
410+
411+// Print subNavi
412+// todo Henceforth to template
413+// echo ' <div style="text-align: center;">';
414+// echo ' <span style="text-align:right;">';
415+// echo ' <span class="prevnextnavi">';
416+ $endKey = $this->scanEndKey($naviUnit);
417+// if ($skinType != 'archivelist' && $skinType != 'archive' && $skinType != 'item') {
418+// echo '<a href="' . $naviUnit[$endKey][2] . '">&raquo; ArchiveList</a>';
419+// }
420+// echo @join(' :: ', $subNaviUnit);
421+// echo '</div>';
422+// echo '</span>';
423+///
424+
425+/*
426+<%subnavi%> --> prev. and next link
427+<%archivedata%> --> ArchiveList link
428+*/
429+
430+ $subNaviData['subnavi'] = implode($this->getOption('PNSeparator'), $subNaviUnit);
431+ if ($skinType != 'archivelist' && $skinType != 'archive' && $skinType != 'item') {
432+ if (!empty($naviUnit)) {
433+ $subNaviData['archivedata'] .= '<a href="'
434+ . $naviUnit[$endKey][2]
435+ . '">' . $this->getOption('archivelinkLabel') . '</a>';
436+ }
437+ }
438+ $subnaviTemplate = $this->getOption('subnaviTemplate');
439+ $navigateData['subnaviblock'] = TEMPLATE::fill($subnaviTemplate, $subNaviData);
440+// echo TEMPLATE::fill($subnaviTemplate, $subNaviData);
441+//*/
442+// Print mainNavi
443+ unset($naviUnit[$endKey][1]);
444+ $naviVar = array_map(array(&$this, 'createNaviLink'), $naviUnit);
445+
446+// echo '<span class="breadcrumbslist">', @join(' &gt; ', $naviVar);
447+
448+ $topicPathData['topicpath'] = implode($this->getOption('topicPathSeparator'), $naviVar);
449+
450+//add Taginfo =====================================
451+// display selected TAGs whith link mod by shizuki
452+ if ($manager->pluginInstalled('NP_TagEX')) {
453+// if (requestVar('tag')) {
454+ $tagPlugin =& $manager->getPlugin('NP_TagEX');
455+ $requestT = $tagPlugin->getNoDecodeQuery('tag');
456+ if (!empty($requestT)) {
457+ $requestTarray = $tagPlugin->splitRequestTags($requestT);
458+ $reqAND = array_map(array(&$tagPlugin, "_rawdecode"), $requestTarray['and']);
459+ if ($requestTarray['or']) {
460+ $reqOR = array_map(array(&$tagPlugin, "_rawdecode"), $requestTarray['or']);
461+ }
462+ if ($reqOR) {
463+ $reqTags = array_merge($reqAND, $reqOR);
464+ } else {
465+ $reqTags = $reqAND;
466+ }
467+ for ($i=0;$i<count($reqTags);$i++) {
468+ $tag = trim($reqTags[$i]);
469+ $taglist[$i] = '<a href="' . $tagPlugin->creatTagLink($tag, 0) . '">'
470+ . htmlspecialchars($tag, ENT_QUOTES, _CHARSET) . '</a>';
471+ }
472+// echo ' <small style="font-family:Tahoma;">';
473+// echo ' (Tag for "'.$tagPlugin->_rawdecode(requestVar('tag')).'")';
474+// echo ' (Tag for "' . @join(' / ', $taglist) . '")';
475+// echo '</small>';
476+/*
477+<%tags%> --> selected TAGs with own link
478+*/
479+ $tagsData['tags'] = implode(' / ', $taglist);
480+ $tagListTemplate = $this->getOption('tagListTemplate');
481+ $topicPathData['taglist'] = TEMPLATE::fill($tagListTemplate, $tagsData);
482+//*/
483+ }
484+ }
485+/*
486+<%topicpath%> --> topicpath
487+<%taglist%> --> selected TAG list
488+*/
489+ $topicPathTemplate = $this->getOption('topicPathTemplate');
490+ $navigateData['topicpathblock'] = TEMPLATE::fill($topicPathTemplate, $topicPathData);
491+// echo TEMPLATE::fill($topicPathTemplate, $topicPathData);
492+ $navigateBlockTemplate = $this->getOption('ItemNaviTemplate');
493+/*
494+<%subnaviblock%>
495+<%topicpathblock%>
496+*/
497+ echo TEMPLATE::fill($navigateBlockTemplate, $navigateData);
498+//*/
499+// echo '</span>';
500+
501+ }
502+
503+ function getParenta($subcat_id, $blogid=0)
504+ {
505+ $subcat_id = intval($subcat_id);
506+ $blogid = intval($blogid);
507+ $r = array();
508+ $que = 'SELECT scatid, parentid, sname, catid FROM %s WHERE scatid = %d';
509+ $que = sprintf($que, sql_table('plug_multiple_categories_sub'), $subcat_id);
510+ $res = sql_query($que);
511+ list ($sid, $parent, $sname, $cat_id) = mysql_fetch_row($res);
512+ if (intval($parent) != 0) {
513+ $this->r[] = $this->getParenta(intval($parent), $blogid);
514+ $this->linkparams[subcatid] = $sid;
515+ $r = array(
516+ 0 => $sname,
517+ 1 => createBlogidLink($blogid, $this->linkparams),
518+ 2 => createArchiveListLink($blogid, $this->linkparams)
519+ );
520+ } else {
521+ $this->linkparams[subcatid] = $sid;
522+ $r = array(
523+ 0 => $sname,
524+ 1 => createBlogidLink($blogid, $this->linkparams),
525+ 2 => createArchiveListLink($blogid, $this->linkparams)
526+ );
527+ }
528+ return $r;
529+ }
530+
531+ function getParent($subcat_id)
532+ {
533+ $subcat_id = intval($subcat_id);
534+ $que = 'SELECT scatid, parentid, sname FROM %s WHERE scatid = %d';
535+ $que = sprintf($que, sql_table('plug_multiple_categories_sub'), $subcat_id);
536+ $res = sql_query($que);
537+ list ($sid, $parent, $sname) = mysql_fetch_row($res);
538+ if (intval($parent) != 0) {
539+ $r = $this->getParent(intval($parent)) . " -> <a href=$subcat_id>$sname</a>";
540+ } else {
541+ $r = "<a href=$subcat_id>" . htmlspecialchars($sname) . "</a>";
542+ }
543+ return $r;
544+ }
545+
546+ function getChildren($subcat_id)
547+ {
548+ $subcat_id = intval($subcat_id);
549+ $que = 'SELECT scatid, parentid, sname FROM %s WHERE parentid = %d';
550+ $que = sprintf($que, sql_table('plug_multiple_categories_sub'), $subcat_id);
551+ $res = sql_query($que);
552+ while ($so = mysql_fetch_object($res)) {
553+ $r .= $this->getChildren($so->scatid) . '/' . intval($so->scatid);
554+ }
555+ return $r;
556+ }
557+
558+ function install()
559+ {
560+ // include language file for this plugin
561+ $language = ereg_replace( '[\\|/]', '', getLanguageName());
562+ if (file_exists($this->getDirectory() . $language . '.php')) {
563+ include_once($this->getDirectory() . $language . '.php');
564+ } else {
565+ include_once($this->getDirectory() . 'english.php');
566+ }
567+ $sub = '<div style="text-align:right;"><%archivedata%><%subnavi%></div>';
568+ $path = '<div style="text-align:left;"><%topicpath%><%taglist%></div>';
569+ $tags = ' (Selected TAG(s) : <small style="font-family:Tahoma;"><%tags%></small>)';
570+ $navi = '<div class="itemnaviex"><%subnaviblock%><%topicpathblock%></div>';
571+ $this->createOption('subnaviTemplate', _INEXOP_SUB, 'text', $sub);
572+ $this->createOption('PNSeparator', _INEXOP_PNSP, 'tect', ' :: ');
573+ $this->createOption('PNNextLabel', _INEXOP_PNNX, 'tect', '&raquo;');
574+ $this->createOption('PNPrevLabel', _INEXOP_PNPR, 'tect', '&laquo;');
575+ $this->createOption('topicPathTemplate', _INEXOP_PATH, 'text', $path);
576+ $this->createOption('topicPathSeparator', _INEXOP_PSEP, 'text', ' &gt; ');
577+ $this->createOption('tagListTemplate', _INEXOP_TAGS, 'text', $tags);
578+ $this->createOption('ItemNaviTemplate', _INEXOP_NAVI, 'text', $navi);
579+ $this->createOption('archivelinkLabel', _INEXOP_ALBL, 'text', '&raquo; ArchiveList');
580+ }
581+
582+}
--- /dev/null
+++ b/NP_ItemNaviEX/trunk/NP_ItemNaviEX.php
@@ -0,0 +1,582 @@
1+<?php
2+/**
3+ *
4+ * BreadCrumbsList PLUG-IN FOR NucleusCMS
5+ * PHP versions 4 and 5
6+ *
7+ * This program is free software; you can redistribute it and/or
8+ * modify it under the terms of the GNU General Public License
9+ * as published by the Free Software Foundation; either version 2
10+ * of the License, or (at your option) any later version.
11+ * (see nucleus/documentation/index.html#license for more info)
12+ *
13+ * @author Original Author nakahara21
14+ * @copyright 2005-2006 nakahara21
15+ * @license http://www.gnu.org/licenses/gpl.txt GNU GENERAL PUBLIC LICENSE Version 2, June 1991
16+ * @version 0.992
17+ * @link http://japan.nucleuscms.org/wiki/plugins:itemnaviex
18+ *
19+ * 0.993 Henceforth to template
20+ * 0.992 display mode '0' fix
21+ * 0.991 add sub-blog home mode
22+ * 0.99 sec fix
23+ *
24+ **************************************************************************
25+ *
26+ * THESE PLUG-INS ARE DEDICATED TO ALL THOSE NucleusCMS USERS
27+ * WHO FIGHT CORRUPTION AND IRRATIONAL IN EVERY DAY OF THEIR LIVES.
28+ *
29+ **************************************************************************/
30+
31+class NP_ItemNaviEX extends NucleusPlugin
32+{
33+ function getName()
34+ {
35+ return 'Navigation Bar';
36+ }
37+
38+ function getAuthor()
39+ {
40+ return 'nakahara21 + shizuki';
41+ }
42+
43+ function getURL()
44+ {
45+ return 'http://japan.nucleuscms.org/wiki/plugins:itemnaviex';
46+ }
47+
48+ function getVersion()
49+ {
50+ return '0.993';
51+ }
52+
53+ function getDescription()
54+ {
55+ // include language file for this plugin
56+ $language = ereg_replace( '[\\|/]', '', getLanguageName());
57+ if (file_exists($this->getDirectory() . $language . '.php')) {
58+ include_once($this->getDirectory() . $language . '.php');
59+ } else {
60+ include_once($this->getDirectory() . 'english.php');
61+ }
62+ $description = _NP_INEX_DESC;
63+// $description = 'Add link to prev item and next item. '
64+// . 'Usage: &lt;%ItemNaviEX%&gt; or &lt;%ItemNaviEX(0)%&gt;'
65+// . ' or &lt;%ItemNaviEX(1)%&gt; or &lt;%ItemNaviEX(2)%&gt;';
66+ return $description;
67+ }
68+
69+ function supportsFeature($what)
70+ {
71+ switch ($what) {
72+ case 'SqlTablePrefix':
73+ return 1;
74+ default:
75+ return 0;
76+ }
77+ }
78+
79+ function scanEndKey($array)
80+ {
81+ $keys = array_keys($array);
82+ rsort($keys);
83+ return $keys[0];
84+ }
85+
86+ function createNaviLink($unitArray)
87+ {
88+ if ($unitArray[1]) {
89+ $tempLink = '<a href="' . htmlspecialchars($unitArray[1], ENT_QUOTES, _CHARSET) . '">'
90+ . htmlspecialchars($unitArray[0], ENT_QUOTES, _CHARSET) . '</a>';
91+ } else {
92+ $tempLink = htmlspecialchars($unitArray[0], ENT_QUOTES, _CHARSET);
93+ }
94+ return $tempLink;
95+ }
96+
97+ function checkParent()
98+ {
99+ global $manager;
100+// if ($manager->pluginInstalled('NP_MultipleCategories')) {
101+// $mplugin =& $manager->getPlugin('NP_MultipleCategories');
102+// if (method_exists($mplugin,"getRequestName")) {
103+ $query = 'SHOW FIELDS FROM ' . sql_table('plug_multiple_categories_sub');
104+ $res = sql_query($query);
105+ while ($co = mysql_fetch_assoc($res)) {
106+ if ($co['Field'] == 'parentid') {
107+ return TRUE;
108+ }
109+ }
110+// }
111+// }
112+ }
113+
114+ function doSkinVar($skinType, $showHome = 1)
115+ {
116+ global $manager, $CONF, $blog, $itemid, $itemidprev, $itemidnext;
117+ global $catid, $subcatid, $archive, $archiveprev, $archivenext, $param;
118+
119+// sanitize
120+ $y = $m = $d = '';
121+ $itemid = intval($itemid);
122+ $catid = intval($catid);
123+ $subcatid = intval($subcatid);
124+ $itemidprev = intval($itemidprev);
125+ $itemidnext = intval($itemidnext);
126+ if (isset($archive)) {
127+ sscanf($archive,'%d-%d-%d', $y, $m, $d);
128+ if ($y && $m && !empty($d)) {
129+ $archive = sprintf('%04d-%02d-%02d', $y, $m, $d);
130+ } elseif ($y && $m && empty($d)) {
131+ $archive = sprintf('%04d-%02d', $y, $m);
132+ }
133+ }
134+ if (isset($archiveprev)) {
135+ sscanf($archiveprev,'%d-%d-%d', $y, $m, $d);
136+ if ($y && $m && !empty($d)) {
137+ $archiveprev = sprintf('%04d-%02d-%02d', $y, $m, $d);
138+ } elseif ($y && $m && empty($d)) {
139+ $archiveprev = sprintf('%04d-%02d', $y, $m);
140+ }
141+ }
142+ if (isset($archiveprev)) {
143+ sscanf($archiveprev,'%d-%d-%d', $y, $m, $d);
144+ if ($y && $m && !empty($d)) {
145+ $archiveprev = sprintf('%04d-%02d-%02d', $y, $m, $d);
146+ } elseif ($y && $m && empty($d)) {
147+ $archiveprev = sprintf('%04d-%02d', $y, $m);
148+ }
149+ }
150+ if ($showHome == '') {
151+ $showHome = 1;
152+ } else {
153+ $showHome = intval($showHome);
154+ }
155+
156+ if ($catid) {
157+ $blogid = getBlogIDFromCatID($catid);
158+ $b =& $manager->getBlog($blogid);
159+ } elseif ($blog) {
160+ $b =& $blog;
161+ } else {
162+ $b =& $manager->getBlog($CONF['DefaultBlog']);
163+ }
164+ $blogid = intval($b->getID());
165+
166+ $abuf = '';
167+ $mtable = '';
168+ $where .= ' and i.iblog=' . $blogid;
169+ if (!empty($catid)) {
170+ if ($manager->pluginInstalled('NP_MultipleCategories')) {
171+ $where .= ' and ((i.inumber = p.item_id'
172+ . ' and (p.categories REGEXP "(^|,)' . $catid . '(,|$)"'
173+ . ' or i.icat = ' . $catid . '))'
174+ . ' or (i.icat = ' . $catid
175+ . ' and p.item_id IS NULL))';
176+ $mtable = ' LEFT JOIN ' . sql_table('plug_multiple_categories') . ' as p'
177+ . ' ON i.inumber = p.item_id';
178+ $mplugin =& $manager->getPlugin('NP_MultipleCategories');
179+ if ($subcatid && method_exists($mplugin, 'getRequestName')) {
180+//family
181+ if ($this->checkParent()) {
182+ $Children = array();
183+ $Children = explode('/', $subcatid . $this->getChildren($subcatid));
184+ }
185+ if ($Children[1]) {
186+ for ($i=0;$i<count($Children);$i++) {
187+ $temp_whr[] = ' p.subcategories REGEXP "(^|,)' . intval($Children[$i]) . '(,|$)" ';
188+ }
189+ $where .= ' and ';
190+ $where .= ' ( ';
191+ $where .= join(' or ', $temp_whr);
192+ $where .= ' )';
193+ }else{
194+ $where .= ' and p.subcategories REGEXP "(^|,)' . $subcatid . '(,|$)"';
195+ }
196+//family end
197+ }
198+ } else {
199+ $where .= ' and i.icat=' . $catid;
200+ }
201+ }
202+ $naviUnit = array();
203+ $subNaviUnit = array();
204+ $this->linkparams = array();
205+ $nextLabel = $this->getOption('PNNextLabel');
206+ $prevLabel = $this->getOption('PNPrevLabel');
207+//store Home =====================================
208+//*// comment out this block when HOME is sub-blog top
209+ if ($showHome == 1) {
210+// $defBlogid =intval($CONF['DefaultBlog']);
211+ $tempBlog =& $manager->getBlog(intval($CONF['DefaultBlog']));
212+ $naviUnit[] = array(
213+ 0 => 'Home',
214+// 1 => createBlogidLink($defBlogid),
215+ 1 => $tempBlog->getURL(),
216+ 2 => createArchiveListLink($blogid)
217+ );
218+ }
219+//*/
220+//store Blog =====================================
221+ if ($showHome == 1 && ($blogid <> $CONF['DefaultBlog'])) {
222+ $naviUnit[] = array(
223+ 0 => getBlogNameFromID($blogid),
224+ 1 => createBlogidLink($blogid),
225+ 2 => createArchiveListLink($blogid)
226+ );
227+ } elseif ($showHome >= 2 || ($showHome == 0 && ($catid || $itemid))) {
228+ $naviUnit[] = array(
229+ 0 => 'Home', // when HOME is sub-blog top
230+ 1 => createBlogidLink($blogid), // when HOME is sub-blog top
231+ 2 => createArchiveListLink($blogid)
232+ );
233+ }
234+
235+//store Category =====================================
236+ if (!empty($catid)) {
237+ $this->linkparams['catid'] = $catid;
238+ $naviUnit[] = array(
239+ 0 => $b->getCategoryName($catid),
240+ 1 => createCategoryLink($catid),
241+// 1 => createBlogidLink($blogid, $this->linkparams),
242+ 2 => createArchiveListLink($blogid, $this->linkparams)
243+ );
244+ }
245+
246+//store subCategory =====================================
247+ if (!empty($subcatid)) {
248+ if ($manager->pluginInstalled('NP_MultipleCategories')) {
249+ $mplugin =& $manager->getPlugin('NP_MultipleCategories');
250+ if (method_exists($mplugin, 'getRequestName')) {
251+ $subrequest = $mplugin->getRequestName(array());
252+ $this->linkparams[$subrequest] = $subcatid;
253+ if ($this->checkParent()) {
254+ $tog = $this->getParenta($subcatid, $blogid);
255+ for ($i=0; $i<count($this->r); $i++) {
256+ $naviUnit[] = $this->r[$i];
257+ }
258+ $naviUnit[] = $tog;
259+ } else {
260+ $naviUnit[] = array(
261+ 0 => $mplugin->_getScatNameFromID($subcatid),
262+ 1 => createCategoryLink($catid, array($subrequest => $subcatid)),
263+// 1 => createCategoryLink($catid, array('subcatid' => $subcatid)),
264+// 1 => createBlogidLink($blogid, $this->linkparams),
265+ 2 => createArchiveListLink($blogid, $this->linkparams)
266+ );
267+ }
268+ }
269+ }
270+ }
271+
272+//store Page ===================================== todo How to get PageNo. ? ...cookie...
273+ if (intRequestVar('page') != 0) {
274+ $naviUnit[] = array(
275+ 0 => 'Page.' . intRequestVar('page'),
276+ 2 => createArchiveListLink($blogid, $this->linkparams)
277+ );
278+ }
279+
280+//store Item =====================================
281+ if ($skinType == 'item') {
282+ $item =& $manager->getItem($itemid, 0, 0);
283+ $naviUnit[] = array(
284+ 0 => $item['title']
285+ );
286+
287+ $query = 'SELECT i.ititle, i.inumber'
288+ . ' FROM ' . sql_table('item') . ' as i' . $mtable
289+ . ' WHERE i.idraft = 0'
290+ . " and i.itime < '" . $item['itime'] . "' " . $where
291+ . ' ORDER BY i.itime DESC';
292+ $res = sql_query($query);
293+ if ($ares = mysql_fetch_row($res)) {
294+ $alink = createItemLink($ares[1], $this->linkparams);
295+ $subNaviUnit[1] = '<a href="'
296+ . htmlspecialchars($alink, ENT_QUOTES, _CHARSET)
297+ . '" rel="prev"> ' . $prevLabel . ' '
298+ . shorten($ares[0], 14, '...')
299+ . '</a>';
300+ }
301+
302+ $query = 'SELECT i.ititle, i.inumber'
303+ . ' FROM ' . sql_table('item') . ' as i' . $mtable
304+ . ' WHERE i.idraft = 0'
305+ . " and i.itime > '" . $item['itime'] . "' " . $where
306+ . ' ORDER BY i.itime ASC';
307+ $res = sql_query($query);
308+ if ($ares = mysql_fetch_row($res)) {
309+ $alink = createItemLink($ares[1], $this->linkparams);
310+ $subNaviUnit[2] = '<a href="'
311+ . htmlspecialchars($alink, ENT_QUOTES, _CHARSET)
312+ . '" rel="next"> '
313+ . shorten($ares[0], 14, '...')
314+ . ' ' . $nextLabel . '</a>';
315+ }
316+
317+ }
318+
319+//store ArchiveList =====================================
320+ if ($skinType == 'archivelist' || $skinType == 'archive') {
321+ $naviUnit[] = array(
322+ 0 => $this->getOption('archivelinkLabel'),
323+// 0 => 'ArchiveList',
324+ 1 => createArchiveListLink($blogid, $this->linkparams)
325+ );
326+ }
327+
328+ if ($skinType == 'archive') {
329+ sscanf($archive,'%d-%d-%d', $y, $m, $d);
330+//store ArchiveMonth
331+ $archiveMonth = $y . '-' . $m;
332+ $naviUnit[] = array(
333+ 0 => $archiveMonth,
334+ 1 => createArchiveLink($blogid, $archiveMonth, $this->linkparams)
335+ );
336+ if (empty($d)) {
337+ $timestamp_start = mktime(0, 0, 0, $m, 1, $y);
338+ $timestamp_end = mktime(0, 0, 0, $m+1, 1, $y);
339+ $date_str = 'SUBSTRING(i.itime, 1, 7)';
340+ } else {
341+ $timestamp_start = mktime(0, 0, 0, $m, $d, $y);
342+ $timestamp_end = mktime(0, 0, 0, $m, $d+1, $y);
343+ $date_str = 'SUBSTRING(i.itime, 1, 10)';
344+//store ArchiveDay
345+ $naviUnit[] = array(
346+ 0 => $y . '-' . $m . '-' . $d,
347+ 1 => createArchiveLink($blogid, $archive, $this->linkparams)
348+ );
349+ }
350+
351+//=============================
352+ $query = 'SELECT ' . $date_str . ' as Date'
353+ . ' FROM ' . sql_table('item') . ' as i' . $mtable
354+ . ' WHERE i.idraft = 0'
355+ . ' and i.itime < ' . mysqldate($timestamp_start) . $where
356+ . ' GROUP BY Date'
357+ . ' ORDER BY i.itime DESC';
358+ $res = sql_query($query);
359+ if ($ares = mysql_fetch_row($res)) {
360+// $prev_date = $ares[0];
361+ sscanf($ares[0], '%d-%d-%d', $y, $m, $d);
362+ if (empty($d)) {
363+ $prev_date = sprintf('%04d-%02d', $y, $m);
364+ } else {
365+ $prev_date = sprintf('%04d-%02d-%02d', $y, $m, $d);
366+ }
367+ $prev_alink = createArchiveLink($blogid, $prev_date, $this->linkparams);
368+ $subNaviUnit[1] = '<a href="'
369+ . htmlspecialchars($prev_alink, ENT_QUOTES, _CHARSET)
370+ . '" class="prevlink" rel="prev">'
371+ . ' ' . $prevLabel . ' '
372+ . htmlspecialchars($prev_date, ENT_QUOTES, _CHARSET)
373+ . '</a>';
374+// $abuf .= '<a href="'.$prev_alink.'" class="prevlink" rel="prev">'.$prev_date.'</a>';
375+// } else {
376+// $today_link = createBlogidLink($b->getID(), $this->linkparams);
377+// $abuf .= ' ( <a href="'.$today_link.'">Today</a> )';
378+ }
379+ $abuf .= ' | <strong>' . htmlspecialchars($archive, ENT_QUOTES, _CHARSET) . '</strong> ';
380+//=============================
381+ $query = 'SELECT ' . $date_str . ' as Date'
382+ . ' FROM ' . sql_table('item') . ' as i' . $mtable
383+ . ' WHERE i.idraft = 0'
384+ . ' and i.itime < ' . mysqldate($b->getCorrectTime())
385+ . ' and i.itime >= ' . mysqldate($timestamp_end) . $where
386+ . ' GROUP BY Date'
387+ . ' ORDER BY i.itime ASC';
388+ $res = sql_query($query);
389+ if ($ares = mysql_fetch_row($res)) {
390+// $next_date = $ares[0];
391+ sscanf($ares[0],'%d-%d-%d', $y, $m, $d);
392+ if (empty($d)) {
393+ $next_date = sprintf('%04d-%02d', $y, $m);
394+ } else {
395+ $next_date = sprintf('%04d-%02d-%02d', $y, $m, $d);
396+ }
397+ $next_alink = createArchiveLink($blogid, $next_date, $this->linkparams);
398+ $subNaviUnit[2] = '<a href="'
399+ . htmlspecialchars($next_alink, ENT_QUOTES, _CHARSET)
400+ . '" class="nextlink" rel="next">'
401+ . htmlspecialchars($next_date, ENT_QUOTES, _CHARSET)
402+ . ' ' . $nextLabel . '</a>';
403+// $a2buf = ' | <a href="'.$next_alink.'" class="nextlink" rel="next">'.$next_date.'</a>';
404+// } else {
405+// $today_link = createBlogidLink($b->getID(), $this->linkparams);
406+// $a2buf .= ' | ( <a href="'.$today_link.'">Today</a> )';
407+ }
408+ }
409+//============================= // end of archive(s)
410+
411+// Print subNavi
412+// todo Henceforth to template
413+// echo ' <div style="text-align: center;">';
414+// echo ' <span style="text-align:right;">';
415+// echo ' <span class="prevnextnavi">';
416+ $endKey = $this->scanEndKey($naviUnit);
417+// if ($skinType != 'archivelist' && $skinType != 'archive' && $skinType != 'item') {
418+// echo '<a href="' . $naviUnit[$endKey][2] . '">&raquo; ArchiveList</a>';
419+// }
420+// echo @join(' :: ', $subNaviUnit);
421+// echo '</div>';
422+// echo '</span>';
423+///
424+
425+/*
426+<%subnavi%> --> prev. and next link
427+<%archivedata%> --> ArchiveList link
428+*/
429+
430+ $subNaviData['subnavi'] = implode($this->getOption('PNSeparator'), $subNaviUnit);
431+ if ($skinType != 'archivelist' && $skinType != 'archive' && $skinType != 'item') {
432+ if (!empty($naviUnit)) {
433+ $subNaviData['archivedata'] .= '<a href="'
434+ . $naviUnit[$endKey][2]
435+ . '">' . $this->getOption('archivelinkLabel') . '</a>';
436+ }
437+ }
438+ $subnaviTemplate = $this->getOption('subnaviTemplate');
439+ $navigateData['subnaviblock'] = TEMPLATE::fill($subnaviTemplate, $subNaviData);
440+// echo TEMPLATE::fill($subnaviTemplate, $subNaviData);
441+//*/
442+// Print mainNavi
443+ unset($naviUnit[$endKey][1]);
444+ $naviVar = array_map(array(&$this, 'createNaviLink'), $naviUnit);
445+
446+// echo '<span class="breadcrumbslist">', @join(' &gt; ', $naviVar);
447+
448+ $topicPathData['topicpath'] = implode($this->getOption('topicPathSeparator'), $naviVar);
449+
450+//add Taginfo =====================================
451+// display selected TAGs whith link mod by shizuki
452+ if ($manager->pluginInstalled('NP_TagEX')) {
453+// if (requestVar('tag')) {
454+ $tagPlugin =& $manager->getPlugin('NP_TagEX');
455+ $requestT = $tagPlugin->getNoDecodeQuery('tag');
456+ if (!empty($requestT)) {
457+ $requestTarray = $tagPlugin->splitRequestTags($requestT);
458+ $reqAND = array_map(array(&$tagPlugin, "_rawdecode"), $requestTarray['and']);
459+ if ($requestTarray['or']) {
460+ $reqOR = array_map(array(&$tagPlugin, "_rawdecode"), $requestTarray['or']);
461+ }
462+ if ($reqOR) {
463+ $reqTags = array_merge($reqAND, $reqOR);
464+ } else {
465+ $reqTags = $reqAND;
466+ }
467+ for ($i=0;$i<count($reqTags);$i++) {
468+ $tag = trim($reqTags[$i]);
469+ $taglist[$i] = '<a href="' . $tagPlugin->creatTagLink($tag, 0) . '">'
470+ . htmlspecialchars($tag, ENT_QUOTES, _CHARSET) . '</a>';
471+ }
472+// echo ' <small style="font-family:Tahoma;">';
473+// echo ' (Tag for "'.$tagPlugin->_rawdecode(requestVar('tag')).'")';
474+// echo ' (Tag for "' . @join(' / ', $taglist) . '")';
475+// echo '</small>';
476+/*
477+<%tags%> --> selected TAGs with own link
478+*/
479+ $tagsData['tags'] = implode(' / ', $taglist);
480+ $tagListTemplate = $this->getOption('tagListTemplate');
481+ $topicPathData['taglist'] = TEMPLATE::fill($tagListTemplate, $tagsData);
482+//*/
483+ }
484+ }
485+/*
486+<%topicpath%> --> topicpath
487+<%taglist%> --> selected TAG list
488+*/
489+ $topicPathTemplate = $this->getOption('topicPathTemplate');
490+ $navigateData['topicpathblock'] = TEMPLATE::fill($topicPathTemplate, $topicPathData);
491+// echo TEMPLATE::fill($topicPathTemplate, $topicPathData);
492+ $navigateBlockTemplate = $this->getOption('ItemNaviTemplate');
493+/*
494+<%subnaviblock%>
495+<%topicpathblock%>
496+*/
497+ echo TEMPLATE::fill($navigateBlockTemplate, $navigateData);
498+//*/
499+// echo '</span>';
500+
501+ }
502+
503+ function getParenta($subcat_id, $blogid=0)
504+ {
505+ $subcat_id = intval($subcat_id);
506+ $blogid = intval($blogid);
507+ $r = array();
508+ $que = 'SELECT scatid, parentid, sname, catid FROM %s WHERE scatid = %d';
509+ $que = sprintf($que, sql_table('plug_multiple_categories_sub'), $subcat_id);
510+ $res = sql_query($que);
511+ list ($sid, $parent, $sname, $cat_id) = mysql_fetch_row($res);
512+ if (intval($parent) != 0) {
513+ $this->r[] = $this->getParenta(intval($parent), $blogid);
514+ $this->linkparams[subcatid] = $sid;
515+ $r = array(
516+ 0 => $sname,
517+ 1 => createBlogidLink($blogid, $this->linkparams),
518+ 2 => createArchiveListLink($blogid, $this->linkparams)
519+ );
520+ } else {
521+ $this->linkparams[subcatid] = $sid;
522+ $r = array(
523+ 0 => $sname,
524+ 1 => createBlogidLink($blogid, $this->linkparams),
525+ 2 => createArchiveListLink($blogid, $this->linkparams)
526+ );
527+ }
528+ return $r;
529+ }
530+
531+ function getParent($subcat_id)
532+ {
533+ $subcat_id = intval($subcat_id);
534+ $que = 'SELECT scatid, parentid, sname FROM %s WHERE scatid = %d';
535+ $que = sprintf($que, sql_table('plug_multiple_categories_sub'), $subcat_id);
536+ $res = sql_query($que);
537+ list ($sid, $parent, $sname) = mysql_fetch_row($res);
538+ if (intval($parent) != 0) {
539+ $r = $this->getParent(intval($parent)) . " -> <a href=$subcat_id>$sname</a>";
540+ } else {
541+ $r = "<a href=$subcat_id>" . htmlspecialchars($sname) . "</a>";
542+ }
543+ return $r;
544+ }
545+
546+ function getChildren($subcat_id)
547+ {
548+ $subcat_id = intval($subcat_id);
549+ $que = 'SELECT scatid, parentid, sname FROM %s WHERE parentid = %d';
550+ $que = sprintf($que, sql_table('plug_multiple_categories_sub'), $subcat_id);
551+ $res = sql_query($que);
552+ while ($so = mysql_fetch_object($res)) {
553+ $r .= $this->getChildren($so->scatid) . '/' . intval($so->scatid);
554+ }
555+ return $r;
556+ }
557+
558+ function install()
559+ {
560+ // include language file for this plugin
561+ $language = ereg_replace( '[\\|/]', '', getLanguageName());
562+ if (file_exists($this->getDirectory() . $language . '.php')) {
563+ include_once($this->getDirectory() . $language . '.php');
564+ } else {
565+ include_once($this->getDirectory() . 'english.php');
566+ }
567+ $sub = '<div style="text-align:right;"><%archivedata%><%subnavi%></div>';
568+ $path = '<div style="text-align:left;"><%topicpath%><%taglist%></div>';
569+ $tags = ' (Selected TAG(s) : <small style="font-family:Tahoma;"><%tags%></small>)';
570+ $navi = '<div class="itemnaviex"><%subnaviblock%><%topicpathblock%></div>';
571+ $this->createOption('subnaviTemplate', _INEXOP_SUB, 'text', $sub);
572+ $this->createOption('PNSeparator', _INEXOP_PNSP, 'tect', ' :: ');
573+ $this->createOption('PNNextLabel', _INEXOP_PNNX, 'tect', '&raquo;');
574+ $this->createOption('PNPrevLabel', _INEXOP_PNPR, 'tect', '&laquo;');
575+ $this->createOption('topicPathTemplate', _INEXOP_PATH, 'text', $path);
576+ $this->createOption('topicPathSeparator', _INEXOP_PSEP, 'text', ' &gt; ');
577+ $this->createOption('tagListTemplate', _INEXOP_TAGS, 'text', $tags);
578+ $this->createOption('ItemNaviTemplate', _INEXOP_NAVI, 'text', $navi);
579+ $this->createOption('archivelinkLabel', _INEXOP_ALBL, 'text', '&raquo; ArchiveList');
580+ }
581+
582+}
--- /dev/null
+++ b/NP_LatestWritebacks/tags/NP_LatestWritebacks.php
@@ -0,0 +1,347 @@
1+<?php
2+class NP_LatestWritebacks extends NucleusPlugin
3+{
4+
5+ function supportsFeature($what)
6+ {
7+ switch ($what) {
8+ case 'SqlTablePrefix':
9+ return 1;
10+ default:
11+ return 0;
12+ }
13+ }
14+
15+// function getEventList()
16+// {
17+// return array();
18+// }
19+
20+ function getName()
21+ {
22+ return 'Latest Writebacks';
23+ }
24+
25+ function getAuthor()
26+ {
27+ return 'nakahara21 + Fujisaki + kimitake + shizuki';
28+ }
29+
30+ function getURL()
31+ {
32+ return 'http://nakahara21.com/';
33+ }
34+
35+ function getVersion()
36+ {
37+ return '1.6';
38+ }
39+
40+ function getDescription()
41+ {
42+ // include language file for this plugin
43+ $language = ereg_replace( '[\\|/]', '', getLanguageName());
44+ if (file_exists($this->getDirectory() . $language . '.php')) {
45+ include_once($this->getDirectory() . $language . '.php');
46+ } else {
47+ include_once($this->getDirectory() . 'english.php');
48+ }
49+ $description = _NP_LRWITEBACKS_DESC;
50+// $description = 'This plugin can be used to display the last few comments'
51+// . 'and Trackbacks.<br />'
52+// . 'Usage:&lt;%LatestWritebacks(10,current,all)%&gt;';
53+ return $description;
54+ }
55+
56+ function install()
57+ {
58+ // include language file for this plugin
59+ $language = ereg_replace( '[\\|/]', '', getLanguageName());
60+ if (file_exists($this->getDirectory() . $language . '.php')) {
61+ include_once($this->getDirectory() . $language . '.php');
62+ } else {
63+ include_once($this->getDirectory() . 'english.php');
64+ }
65+ $this->createOption('timelocale', _NP_LRWITEBACKS_TZLOC, 'text', 'ja_JP.' . _CHARSET);
66+ $this->createOption('cmdateformat', _NP_LRWITEBACKS_CDFMT, 'text', '%Y-%m-%d %H:%M:%S');
67+ $this->createOption('tbdateformat', _NP_LRWITEBACKS_TEFMT, 'text', '%m-%d');
68+ $this->createOption('cmlisthead', _NP_LRWITEBACKS_CHEAD, 'textarea', '<ul class="nobullets">');
69