OSDN Git Service

72aed7007d53b974c3f371749babca66a895430d
[nucleus-jp/nucleus-plugins.git] / trunk / NP_CustomURL / customurl / index.php
1 <?php
2 //
3 //      URL configuration plugin "NP_CustomURL" ADMIN page
4 //
5
6         // if your 'plugin' directory is not in the default location,
7         // edit this variable to point to your site directory
8         // (where config.php is)
9         $strRel = '../../../';
10
11         include($strRel . 'config.php');
12         include($DIR_LIBS . 'PLUGINADMIN.php');
13
14         // create the admin area page
15         $oPluginAdmin = new PluginAdmin('CustomURL');
16         $language     = ereg_replace( '[\\|/]', '', getLanguageName());
17         if (file_exists($oPluginAdmin->plugin->getDirectory() . 'language/' . $language . '.php')) {
18                 include_once($oPluginAdmin->plugin->getDirectory() . 'language/' . $language . '.php');
19         } else {
20                 include_once($oPluginAdmin->plugin->getDirectory() . 'language/english.php');
21         }
22
23         if (!($member->isLoggedIn() && $member->isAdmin())) {
24                 ACTIONLOG::add(WARNING, _ACTIONLOG_DISALLOWED . serverVar('REQUEST_URI'));
25                 $myAdmin->error(_ERROR_DISALLOWED);
26         }
27
28 class CustomURL_ADMIN
29 {
30
31         function CustomURL_ADMIN()
32         {
33                 global $manager, $CONF, $oPluginAdmin;
34                 $this->plugin   =& $oPluginAdmin->plugin;
35                 $this->name     =  $this->plugin->getName();
36                 $this->pluginid =  $this->plugin->getID();
37                 $this->adminurl =  $this->plugin->getAdminURL();
38                 $this->editurl  =  $CONF['adminURL'];
39                 $this->pediturl =  $CONF['adminURL']
40                                                 . 'index.php?action=pluginoptions&amp;plugid='
41                                                 . $this->pluginid;
42                 $this->table    =  sql_table('plug_customurl');
43                 $this->uScat    =  ($manager->pluginInstalled('NP_MultipleCategories') == TRUE);
44                 if ($manager->pluginInstalled('NP_MultipleCategories')) {
45                         $mplugin =& $manager->getPlugin('NP_MultipleCategories');
46                         if (method_exists($mplugin, 'getRequestName')) {
47                                 $this->mcadmin = $mplugin->getAdminURL();
48                                 global $subcatid;
49                         }
50                 }
51
52         }
53
54         function action($action)
55         {
56                 global $manager;
57                 $methodName         = 'action_' . $action;
58                 $this->actions      = strtolower($action);
59                 $aActionsNotToCheck = array(
60                                                                         'blogview',
61                                                                         'categoryview',
62                                                                         'memberview',
63                                                                         'itemview',
64                                                                         'pathupdate',
65                                                                    );
66                 if (!in_array($this->actions, $aActionsNotToCheck)) {
67                         if (!$manager->checkTicket()) {
68                                 $this->error(_ERROR_BADTICKET);
69                         }
70                 }
71
72                 if (method_exists($this, $methodName)) {
73                         call_user_func(array(&$this, $methodName));
74                 } else {
75                         $this->error(_BADACTION . " ($action)");
76                 }
77         }
78
79         function disallow()
80         {
81
82                 ACTIONLOG::add(WARNING, _ACTIONLOG_DISALLOWED . serverVar('REQUEST_URI'));
83                 $msg = array (0, _ERROR_DISALLOWED, '***', _DISALLOWED_MSG);
84                 $this->error($msg);
85         }
86
87         function error($msg = '')
88         {
89                 global $oPluginAdmin;
90
91                 $oPluginAdmin->start();
92                 $printData = $msg[1] . 'name : ' . $msg[2] . '<br />'
93                                    . $msg[3] . '<br />'
94                                    . '<a href="' . $this->adminurl . 'index.php" onclick="history.back()">'
95                                    . _BACK . '</a>';
96                 echo $printData;
97                 $oPluginAdmin->end();
98                 unset($printData);
99                 exit;
100         }
101
102         function action_blogview($msg = '')
103         {
104                 global $CONF, $oPluginAdmin;
105
106                 $oPluginAdmin->start();
107                 $printData = '<h2><a id="pagetop">'._ADMIN_AREA_TITLE.'</a></h2>'
108                                    . '<ul style="list-style:none;">'
109                                    . '  <li>'
110                                    . '    <a href="' . $this->pediturl . '">'
111                                    . _OPTION_SETTING
112                                    . '    </a>'
113                                    . '  </li>'
114                                    . '  <li>'
115                                    . '    <a href="' . $this->adminurl . 'index.php?action=memberview">'
116                                    . _FOR_MEMBER_SETTING
117                                    . '    </a>'
118                                    . '  </li>'
119                                    . '</ul>'
120                                    . '<p>' . $this->_hsc($msg);
121                 echo $printData;
122                 unset($printData);
123                 $this->print_tablehead(_BLOG_LIST_TITLE, _LISTS_ACTIONS);
124                 $query = 'SELECT %s,%s,%s FROM %s';
125                 $query = sprintf($query, bname, bnumber, bshortname, sql_table('blog'));
126                 $res   = sql_query($query);
127                 while ($b = mysql_fetch_object($res)) {
128 //                      $forCatURI  = $this->adminurl . 'index.php?action=goCategory&amp;blogid=' . $b->bnumber;
129                         $forCatURI  = $this->adminurl . 'index.php?action=categoryview&amp;blogid=' . $b->bnumber;
130 //                      $forItemURI = $this->adminurl . 'index.php?action=goItem&amp;blogid=' . $b->bnumber;
131                         $forItemURI = $this->adminurl . 'index.php?action=itemview&amp;blogid=' . $b->bnumber;
132                         $bPath      = $this->_hsc($this->plugin->getBlogOption($b->bnumber, 'customurl_bname'));
133                         $data = array (
134                                'oid'          => intval($b->bnumber),
135                                'obd'          => 0,
136                                'opr'          => 'blog',
137                                'name'         => $this->_hsc($b->bname),
138                                'ret'          => 'blogview',
139                                'ed_URL'       => $this->editurl . 'index.php?action=blogsettings'
140                                                           .  '&amp;blogid=' . intval($b->bnumber),
141                                'desc'         => '[<a href="' . $forItemURI . '" style="font-size:x-small;">'
142                                               .  _FOR_ITEMS_SETTING
143                                               .  '</a>]'
144                                               .  '&nbsp;'
145                                               .  '[<a href="' . $forCatURI . '" style="font-size:x-small;">'
146                                               .  _FOR_CATEGORY_SETTING
147                                               .  '</a>]',
148                                'path'         => $bPath,
149                                'setting_text' => _BLOG_SETTING
150                                                   );
151                         $this->print_tablerow($data);
152                 }
153                         echo '</tbody></table>';
154                 echo '</p>';
155                 unset($query);
156                 $oPluginAdmin->end();
157         }
158
159         function action_categoryview($bid = '', $msg = '')
160         {
161                 global $CONF, $oPluginAdmin;
162                 if (empty($bid)) {
163                         if (getVar('blogid')) {
164                                 $bid = intGetVar('blogid');
165                         } else {
166                                 $bid = intval($CONF['DefaultBlog']);
167                         }
168                 } else {
169                         $bid = intval($bid);
170                 }
171                 $bname = $this->_hsc(getBlognameFromID($bid));
172
173                 $oPluginAdmin->start();
174                 $printData = '<h2><a id="pagetop">'._ADMIN_AREA_TITLE.'</a></h2>'
175                                    . '<ul style="list-style:none;">'
176                                    . '  <li>'
177                                    . '    <a href="' . $this->pediturl . '">'
178                                    . _OPTION_SETTING
179                                    . '    </a>'
180                                    . '  </li>'
181                                    . '  <li>'
182                                    . '    <a href="' . $this->adminurl . 'index.php?action=blogview">'
183                                    . _FOR_BLOG_SETTING
184                                    . '    </a>'
185                                    . '  </li>'
186                                    . '  <li>'
187 //                                 . '    <a href="' . $this->adminurl . 'index.php?action=goItem&amp;blogid=' . $bid . '">'
188                                    . '    <a href="' . $this->adminurl . 'index.php?action=itemview&amp;blogid=' . $bid . '">'
189                                    ._FOR_ITEMS_SETTING
190                                    . '    </a>'
191                                    . '  </li>'
192                                    . '  <li>'
193                                    . '    <a href="' . $this->adminurl . 'index.php?action=memberview">'
194                                    . _FOR_MEMBER_SETTING
195                                    . '    </a>'
196                                    . '  </li>'
197                                    . '</ul>'
198                                    . '<p>' . $this->_hsc($msg)
199                                    . '<h3 style="padding-left: 0px">' . $bname . '</h3>';
200                 echo $printData;
201                 unset($printData);
202                 $this->print_tablehead(_LISTS_CAT_NAME, _LISTS_DESC);
203                 $query = 'SELECT catid, cname, cdesc FROM %s WHERE cblog = %d';
204                 $query = sprintf($query, sql_table('category'), $bid);
205                 $cnm   = sql_query($query);
206                 while ($c = mysql_fetch_object($cnm)) {
207                         $cPath = $this->_hsc($this->plugin->getCategoryOption($c->catid, 'customurl_cname'));
208                         $data  = array (
209                                                         'oid'    => intval($c->catid),
210                                                         'obd'    => $bid,
211                                                                 'opr'    => 'category',
212                                                         'name'   => $this->_hsc($c->cname),
213                                                         'ret'    => 'catoverview',
214                                                         'ed_URL' => $this->editurl
215                                                                          .  'index.php?action=categoryedit'
216                                                                          .  '&amp;blogid=' . $bid
217                                                                          .  '&amp;catid=' . intval($c->catid),
218                                                         'desc'   => $this->_hsc($c->cdesc),
219                                                         'path'   => $cPath
220                                                    );
221                         $this->print_tablerow($data);
222                         if ($this->uScat) {
223                                 $query = 'SELECT scatid, sname, sdesc FROM %s WHERE catid = %d';
224                                 $query = sprintf($query, sql_table('plug_multiple_categories_sub'), intval($c->catid));
225                                 $scnm  = sql_query($query);
226                                 while ($sc = mysql_fetch_object($scnm)) {
227                                         $query = 'SELECT obj_name '
228                                                    . 'FROM %s '
229                                                    . 'WHERE obj_param = "subcategory" '
230                                                    . 'AND   obj_bid = %d '
231                                                    . 'AND   obj_id = %d';
232                                         $query = sprintf($query, $this->table, intval($c->catid), intval($sc->scatid));
233                                         $scpt  = sql_query($query);
234                                         $scp   = mysql_fetch_object($scpt);
235                                         $data  = array (
236                                                                         'oid'    => intval($sc->scatid),
237                                                                         'obd'    => intval($c->catid),
238                                                                         'opr'    => 'subcategory',
239                                                                         'name'   => '&raquo;' . $this->_hsc($sc->sname),
240                                                                         'ret'    => 'catoverview',
241                                                                         'ed_URL' => $this->mcadmin
242                                                                                          .  'index.php?action=scatedit'
243                                                                                          .  '&amp;catid=' . intval($c->catid)
244                                                                                          .  '&amp;scatid=' . intval($sc->scatid),
245                                                                         'desc'   => $this->_hsc($sc->sdesc),
246                                                                         'path'   => $this->_hsc($scp->obj_name)
247                                                                    );
248                                         $this->print_tablerow($data);
249                                 }
250                         }
251                 }
252                 echo '</tbody></table>';
253                 echo '<a href="' . $this->adminurl . 'index.php" onclick="history.back()">' . _BACK . '</a>';
254                 echo '</p>';
255                 unset($query);
256                 $oPluginAdmin->end();
257         }
258
259         function action_memberview($msg = '')
260         {
261                 global $CONF, $oPluginAdmin;
262
263                 $oPluginAdmin->start();
264                 $printData = '<h2>' . _ADMIN_AREA_TITLE . '</h2>'
265                                    . '<ul style="list-style:none;">'
266                                    . '  <li>'
267                                    . '    <a href="' . $this->pediturl . '">'
268                                    . _OPTION_SETTING
269                                    . '    </a>'
270                                    . '  </li>'
271                                    . '  <li>'
272                                    . '    <a href="' . $this->adminurl . 'index.php?action=blogview">'
273                                    . _FOR_BLOG_SETTING
274                                    . '    </a>'
275                                    . '  </li>'
276                                    . '</ul>'
277                                    . '<p>' . $this->_hsc($msg);
278                 echo $printData;
279                 unset($printData);
280                 $this->print_tablehead(_LOGIN_NAME, _MEMBERS_REALNAME);
281                 $query = 'SELECT %s,%s,%s FROM %s';
282                 $query = sprintf($query, mname, mnumber, mrealname, sql_table('member'));
283                 $res   = sql_query($query);
284                 while ($m = mysql_fetch_object($res)) {
285                         $mPpath = $this->_hsc($this->plugin->getMemberOption($m->mnumber, 'customurl_mname'));
286                         $data  = array (
287                                                     'oid'    => intval($m->mnumber),
288                                                     'obd'    => 0,
289                                                     'opr'    => 'member',
290                                                     'name'   => $this->_hsc($m->mname),
291                                                     'ret'    => 'memberview',
292                                                     'ed_URL' => $this->editurl
293                                                                          .  'index.php?action=memberedit'
294                                                                          .  '&amp;memberid=' . intval($m->mnumber),
295                                                     'desc'   => $this->_hsc($m->mrealname),
296                                                     'path'   => $mPath
297                                                    );
298                         $this->print_tablerow($data);
299                 }
300                 echo '</tbody></table></p>';
301                 unset($query);
302                 $oPluginAdmin->end();
303         }
304
305         function action_itemview($bid = 0, $msg = '') {
306                 global $CONF, $oPluginAdmin;
307
308                 if (empty($bid)) {
309                         if (getVar('blogid')) {
310                                 $bid = intGetVar('blogid');
311                         } else {
312                                 $bid = intval($CONF['DefaultBlog']);
313                         }
314                 } else {
315                         $bid = intval($bid);
316                 }
317                 $oPluginAdmin->start();
318                 $printData = '<h2>'._ADMIN_AREA_TITLE.'</h2>'
319                                    . '<ul style="list-style:none;">'
320                                    . '  <li>'
321                                    . '    <a href="' . $this->pediturl . '">'
322                                    . _OPTION_SETTING
323                                    . '    </a>'
324                                    . '  </li>'
325                                    . '  <li>'
326                                    . '    <a href="' . $this->adminurl . 'index.php?action=blogview">'
327                                    . _FOR_BLOG_SETTING
328                                    . '    </a>'
329                                    . '  </li>'
330                                    . '  <li>'
331 //                                 . '    <a href="' . $this->adminurl . 'index.php?action=goCategory&amp;blogid=' . $bid . '">'
332                                    . '    <a href="' . $this->adminurl . 'index.php?action=categoryview&amp;blogid=' . $bid . '">'
333                                    . _FOR_CATEGORY_SETTING
334                                    . '    </a>'
335                                    . '  </li>'
336                                    . '  <li>'
337                                    . '    <a href="' . $this->adminurl . 'index.php?action=memberview">'
338                                    . _FOR_MEMBER_SETTING
339                                    . '    </a>'
340                                    . '  </li>'
341                                    . '</ul>'
342                                    . '<p><h3>' . $this->_hsc($msg) . '</h3>';
343                 echo $printData;
344                 unset($printData);
345                 $this->print_tablehead(_LISTS_TITLE, _LISTS_ITEM_DESC);
346                 $query = 'SELECT %s,%s,%s FROM %s WHERE iblog = %d ORDER BY itime DESC';
347                 $query = sprintf($query, ititle, inumber, ibody, sql_table('item'), $bid);
348                 $res   = sql_query($query);
349                 while ($i = mysql_fetch_object($res)) {
350                         $query    = 'SELECT obj_name as result FROM %s WHERE obj_param = "item" AND obj_id = %d';
351                         $query    = sprintf($query, sql_table('plug_customurl'), intval($i->inumber));
352                         $temp_res = quickQuery($query);
353                         $ipath    = $this->_hsc(substr($temp_res, 0, -5));
354                         $data     = array (
355                                                            'oid'    => intval($i->inumber),
356                                                            'obd'    => $bid,
357                                                            'opr'    => 'item',
358                                                            'name'   => $this->_hsc($i->ititle),
359                                                            'ret'    => 'itemview',
360                                                            'ed_URL' => $this->editurl
361                                                                                 .  'index.php?action=itemedit'
362                                                                                 .  '&amp;itemid=' . intval($i->inumber),
363 //                                                         'desc'   => $this->_hsc(mb_substr(strip_tags($i->ibody), 0, 80)),
364                                                            'path'   => $ipath
365                                         );
366                         if (extension_loaded('mbstring')) {
367                                 $data['desc'] = $this->_hsc(mb_substr(strip_tags($i->ibody), 0, 80));
368                         } else {
369                                 $this->_hsc(substr(strip_tags($i->ibody), 0, 80));
370                         }
371                         $this->print_tablerow($data);
372                 }
373                 echo '</tbody></table></p>';
374                 unset($query);
375                 $oPluginAdmin->end();
376         }
377
378         function print_tablehead($o_name, $o_desc)
379         {
380                 global $oPluginAdmin;
381
382                 $NAME   = $o_name;
383                 $DESC   = $o_desc;
384                 $PATH   = _LISTS_PATH;
385                 $ACTION = _LISTS_ACTIONS;
386 echo <<< TABLE_HEAD
387         <table>
388                 <thead>
389                         <tr>
390                                 <th>{$NAME}</th>
391                                 <th>{$DESC}</th>
392                                 <th style="width:180px;">{$PATH}</th>
393                                 <th style="width:80px;">{$ACTION}</th>
394                         </tr>
395                 </thead>
396                 <tbody>
397 TABLE_HEAD;
398         }
399
400         function print_tablerow($data)
401         {
402                 global $oPluginAdmin, $manager;
403
404                 $updateText = _SETTINGS_UPDATE_BTN;
405                 $edit       = _EDIT;
406 echo <<< TBODY
407                         <tr onmouseover="focusRow(this);" onmouseout="blurRow(this);">
408                                 <form method="post" action="{$this->adminurl}index.php" />
409                                 <input type="hidden" name="action" value="pathupdate" />
410                                 <input type="hidden" name="oid" value="{$data['oid']}" />
411                                 <input type="hidden" name="obd" value="{$data['obd']}" />
412                                 <input type="hidden" name="opr" value="{$data['opr']}" />
413                                 <input type="hidden" name="name" value="{$data['name']}" />
414                                 <input type="hidden" name="ret" value="{$data['ret']}" />
415 TBODY;
416                 $manager->addTicketHidden();
417 echo <<< TBODY
418                                 <td>{$data['name']}&nbsp;&nbsp;
419                                         <a href="{$data['ed_URL']}" style="font-size:xx-small;">[{$edit}]</a>
420                                 </td>
421                                 <td>{$data['desc']}</td>
422                                 <td><input type="text" name="path" size="32" value="{$data['path']}"/></td>
423                                 <td><input type="submit" name="update" value="{$updateText}" /></td>
424                                 </form>
425                         </tr>
426 TBODY;
427         }
428
429         function action_pathupdate() {
430                 global $oPluginAdmin;
431
432                 $o_oid   = intRequestVar('oid');
433                 $o_bid   = intRequestVar('obd');
434                 $o_param = requestVar('opr');
435                 $o_name  = requestVar('name');
436                 $newPath = requestVar('path');
437                 $action  = requestVar('ret');
438
439                 $msg = $this->plugin->RegistPath($o_oid, $newPath, $o_bid, $o_param, $o_name);
440                 if ($msg) {
441                         $this->error($msg);
442                         if ($msg[0] != 0) {
443                                 return;
444                                 exit;
445                         }
446                 }
447                 $mesage = _UPDATE_SUCCESS;
448                 switch($action) {
449                         case 'catoverview':
450                                 if ($o_param == 'subcategory') {
451                                         $bid = getBlogIDFromCatID($o_bid);
452                                 } else {
453                                         $bid = $o_bid;
454                                 }
455                                 $this->action_categoryview($bid, _UPDATE_SUCCESS);
456                         break;
457                         case 'memberview':
458                                 $this->action_memberview(_UPDATE_SUCCESS);
459                         break;
460                         case 'blogview':
461                                 $this->action_blogview(_UPDATE_SUCCESS);
462                         break;
463                         case 'itemview':
464                                 $this->action_itemview($o_bid, _UPDATE_SUCCESS);
465                         break;
466                         default:
467                                 echo _UPDATE_SUCCESS;
468                         break;
469                 }
470                 return;
471         }
472
473         function action_goItem() {
474                 global $oPluginAdmin;
475
476                 $bid = getVar('blogid');
477                 $this->action_itemview($bid);
478         }
479
480         function action_goCategory() {
481                 global $oPluginAdmin;
482
483                 $bid = getVar('blogid');
484                 $this->action_categoryview($bid);
485         }
486
487         function _hsc($str)
488         {
489                 return htmlspecialchars($str, ENT_QUOTES, _CHARSET);
490         }
491
492 }
493
494 $myAdmin = new CustomURL_ADMIN();
495
496 if (requestVar('action')) {
497         $myAdmin->action(requestVar('action'));
498 } else {
499         $myAdmin->action('blogview');
500 }
501