OSDN Git Service

2.0.3 jp8.2
[nucleus-jp/nucleus-plugins.git] / trunk / NP_TrackBack / trackback / index.php
1 <?php
2
3         $strRel = '../../../'; 
4         include($strRel . 'config.php');
5         include($DIR_LIBS . 'PLUGINADMIN.php');
6         include('template.php');
7         
8         
9         // Send out Content-type
10         sendContentType('application/xhtml+xml', 'admin-trackback', _CHARSET);  
11
12         $oPluginAdmin = new PluginAdmin('TrackBack');
13
14         if (!($member->isLoggedIn() && $member->isAdmin()))
15         {
16                 $oPluginAdmin->start();
17                 echo '<p>' . _ERROR_DISALLOWED . '</p>';
18                 $oPluginAdmin->end();
19                 exit;
20         }
21         
22         // Actions
23         $action = requestVar('action');
24         $aActionsNotToCheck = array(
25                 '',
26         );
27         if (!in_array($action, $aActionsNotToCheck)) {
28                 if (!$manager->checkTicket()) doError(_ERROR_BADTICKET);
29         }
30         $oPluginAdmin->start();
31         
32 //modify start+++++++++
33                 $plug =& $oPluginAdmin->plugin;
34                 $tableVersion = $plug->checkTableVersion();
35
36                 // include language file for this plugin 
37                 $language = ereg_replace( '[\\|/]', '', getLanguageName()); 
38                 if (file_exists($plug->getDirectory().'language/'.$language.'.php')) 
39                         include_once($plug->getDirectory().'language/'.$language.'.php'); 
40                 else 
41                         include_once($plug->getDirectory().'language/'.'english.php');
42 //modify end+++++++++
43
44         $mTemplate = new Trackback_Template();
45         $mTemplate->set ('CONF', $CONF);
46         $mTemplate->set ('plugid', $plug->getID());
47         $mTemplate->set ('plugindirurl', $oPluginAdmin->plugin->getAdminURL());
48         $mTemplate->template('templates/menu.html');
49         echo $mTemplate->fetch();
50
51         $oTemplate = new Trackback_Template();
52         $oTemplate->set ('CONF', $CONF);
53         $oTemplate->set ('plugindirurl', $oPluginAdmin->plugin->getAdminURL());
54         $oTemplate->set ('ticket', $manager->_generateTicket());
55         \r       $ajaxEnabled = ($oPluginAdmin->plugin->getOption('ajaxEnabled') == 'yes') ? true : false;
56         $oTemplate->set ('ajaxEnabled', $ajaxEnabled);
57
58         switch($action) {
59
60 //modify start+++++++++
61                 case 'tableUpgrade':
62                         mysql_query("
63                                 CREATE TABLE IF NOT EXISTS
64                                         ".sql_table('plugin_tb_lookup')."
65                                 (
66                                         `link`      TEXT            NOT NULL, 
67                                         `url`       TEXT            NOT NULL, 
68                                         `title`     TEXT, 
69                                         
70                                         PRIMARY KEY (`link` (100))
71                                 )
72                         ");
73                         echo $q = "ALTER TABLE ".sql_table('plugin_tb')."
74                                  ADD `block` TINYINT( 4 ) NOT NULL AFTER `url` ,
75                                  ADD `spam` TINYINT( 4 ) NOT NULL AFTER `block` ,
76                                  ADD `link` TINYINT( 4 ) NOT NULL AFTER `spam` ,
77                                  CHANGE `url` `url` TEXT NOT NULL,
78                                  CHANGE `title` `title` TEXT NOT NULL,
79                                  CHANGE `excerpt` `excerpt` TEXT NOT NULL,
80                                  CHANGE `blog_name` `blog_name` TEXT NOT NULL,
81                                  DROP PRIMARY KEY,
82                                  ADD `id` INT( 11 ) NOT NULL AUTO_INCREMENT PRIMARY KEY FIRST ;";
83                         $res = @mysql_query($q);
84                         if (!$res){
85                                 echo 'Could not alter table: ' . mysql_error();
86                         }else{
87                                 $tableVersion = 1;
88                                 $oTemplate->template('templates/updatetablefinished.html');
89                         }
90                         @mysql_query('ALTER TABLE `' . sql_table('plugin_tb') . '` ADD INDEX `tb_id_block_timestamp_idx` ( `tb_id`, `block`, `timestamp` DESC )');
91                         break;
92 //modify end+++++++++
93
94                 case 'block':
95                         $tb = intRequestVar('tb');
96
97                         $res = mysql_query ("
98                                 UPDATE
99                                         ".sql_table('plugin_tb')."
100                                 SET
101                                         block = 1
102                                 WHERE
103                                         id = '".$tb."'
104                         ");
105
106                         $action = requestVar('next');
107                         break;
108                 case 'blocked_clear':
109                         $res = mysql_query ("DELETE FROM ".sql_table('plugin_tb')." WHERE block = 1");
110                         $action = requestVar('next');
111                         break;
112                         
113                 case 'blocked_spamclear':
114                         $res = mysql_query ("DELETE FROM ".sql_table('plugin_tb')." WHERE block = 1 and spam = 1");
115                         $action = requestVar('next');
116                         break;
117
118                 case 'unblock':
119                         $tb = intRequestVar('tb');
120
121                         $res = mysql_query ("
122                                 UPDATE
123                                         ".sql_table('plugin_tb')."
124                                 SET
125                                         block = 0
126                                 WHERE
127                                         id = '".$tb."'
128                         ");
129
130                         $action = requestVar('next');
131                         break;
132
133                 case 'delete':
134                         $tb = intRequestVar('tb');
135
136                         $res = mysql_query ("
137                                 DELETE FROM
138                                         ".sql_table('plugin_tb')."
139                                 WHERE
140                                         id = '".$tb."'
141                         ");
142
143                         $action = requestVar('next');
144                         break;
145
146                 case 'sendping':
147                         $title     = requestVar('title');
148                         $url       = requestVar('url');
149                         $excerpt   = requestVar('excerpt');
150                         $blog_name = requestVar('blog_name');
151                         $ping_url  = requestVar('ping_url');            
152
153                         // No charset conversion needs to be done here, because
154                         // the charset used to receive the info is used to send
155                         // it...
156
157                         if ($ping_url) {
158                                 $error = $oPluginAdmin->plugin->sendPing(0, $title, $url, $excerpt, $blog_name, $ping_url);
159                                 
160                                 if ($error) {
161                                         echo '<b>TrackBack Error:' . $error . '</b>';
162                                 }
163                         }               
164                         
165                         $action = requestVar('next');
166                         break;
167                 case 'ping':
168                         $id  = intRequestVar('id');
169                         
170                         $usePathInfo = ($CONF['URLMode'] == 'pathinfo');
171                         if ($usePathInfo)
172                         @ include($strRel . 'fancyurls.config.php');
173                         
174                         global $manager;
175                         $itemData = $manager->getItem($id, 0, 0);
176                         
177                         if(is_array($itemData)){
178                                 $blog =& $manager->getBlog($itemData['blogid']);
179                                 $CONF['ItemURL'] = ($usePathInfo)? preg_replace('/\/$/', '', $blog->getURL()): $blog->getURL();
180                                 $itemData['url'] = createItemLink($id);
181                                 $itemData['excerpt'] = shorten(strip_tags($itemData['body'].$itemData['more']), 250, '...');
182                                 $itemData['blogname'] = $blog->getName();
183                         }else{
184                                 $itemData = array();
185                                 $itemData['url'] = $CONF['IndexURL'];
186                                 $itemData['blogname'] = $CONF['SiteName'];
187                         }
188                         $oTemplate->set('item', $itemData);
189                         
190                         $oTemplate->template('templates/ping.html');
191                         break;                  
192         }
193
194         // Pages 
195         switch($action) {
196                 
197                 case 'help':
198                         $oTemplate->template('help.html');                      
199                         break;
200
201                 case 'ping':
202                         $oTemplate->template('templates/ping.html');                    
203                         break;
204
205                 case 'blocked':
206                 case 'all':     
207                         $rres = mysql_query ("
208                                 SELECT
209                                         COUNT(*) AS count
210                                 FROM
211                                         ".sql_table('plugin_tb')." AS t,
212                                         ".sql_table('item')." AS i
213                                 WHERE
214                                         t.tb_id = i.inumber AND
215                                         t.block = " . (( $action == 'all') ? 0 : 1) );                          
216                                                 
217                         if ($row = mysql_fetch_array($rres))
218                                 $count = $row['count'];
219                         else
220                                 $count = 0;
221                         $oTemplate->set('count', $count);
222
223                         if($ajaxEnabled){
224                                 if( $action == 'all') 
225                                         $oTemplate->template('templates/all_ajax.html');
226                                 else                    
227                                         $oTemplate->template('templates/blocked_ajax.html');
228                         } else {\r                               $start  = intRequestVar('start') ? intRequestVar('start') : 0;
229                                 $amount = intRequestVar('amount') ? intRequestVar('amount') : 25;
230
231                                 $rres = mysql_query ("
232                                         SELECT
233                                         i.ititle AS story,
234                                         i.inumber AS story_id,
235                                         t.id AS id,
236                                         t.title AS title,
237                                         t.blog_name AS blog_name,
238                                         t.excerpt AS excerpt,
239                                         t.url AS url,
240                                         UNIX_TIMESTAMP(t.timestamp) AS timestamp,
241                                         t.spam AS spam,
242                                         t.link AS link
243                                         FROM
244                                         ".sql_table('plugin_tb')." AS t,
245                                         ".sql_table('item')." AS i
246                                         WHERE
247                                         t.tb_id = i.inumber AND
248                                         t.block = " . (( $action == 'all') ? 0 : 1) ."
249                                         ORDER BY
250                                         timestamp DESC
251                                         LIMIT
252                                         ".$start.",".$amount);                          
253                                 
254                                 $items = array();
255                                 
256                                 while ($rrow = mysql_fetch_array($rres)){
257                                         $rrow['title']          = $oPluginAdmin->plugin->_cut_string($rrow['title'], 50);
258                                         $rrow['title']          = $oPluginAdmin->plugin->_strip_controlchar($rrow['title']);
259                                         $rrow['title']          = htmlspecialchars($rrow['title']);
260                                         
261                                         $rrow['blog_name']      = $oPluginAdmin->plugin->_cut_string($rrow['blog_name'], 50);
262                                         $rrow['blog_name']      = $oPluginAdmin->plugin->_strip_controlchar($rrow['blog_name']);
263                                         $rrow['blog_name']      = htmlspecialchars($rrow['blog_name']);
264                                         
265                                         $rrow['excerpt']        = $oPluginAdmin->plugin->_cut_string($rrow['excerpt'], 800);
266                                         $rrow['excerpt']        = $oPluginAdmin->plugin->_strip_controlchar($rrow['excerpt']);
267                                         $rrow['excerpt']        = htmlspecialchars($rrow['excerpt']);
268                                         
269                                         $rrow['url']            = htmlspecialchars($rrow['url'], ENT_QUOTES);
270                                         $rrow['timestamp']              = htmlspecialchars($rrow['timestamp'], ENT_QUOTES);
271                                         
272                                         $blog = & $manager->getBlog(getBlogIDFromItemID($item['itemid']));
273                                         $rrow['story_url'] = $oPluginAdmin->plugin->_createItemLink($rrow['story_id'], $blog);
274                                         $rrow['story'] = htmlspecialchars(strip_tags($rrow['story']), ENT_QUOTES);
275                                         
276                                         $items[] = $rrow;
277                                 }
278                                 
279                                 $oTemplate->set('amount', $amount);
280                                 $oTemplate->set('start', $start);
281                                 $oTemplate->set('items', $items);
282                                 
283                                 if( $action == 'all') 
284                                         $oTemplate->template('templates/all.html');
285                                 else                    
286                                         $oTemplate->template('templates/blocked.html');
287                         }
288                         break;
289                         
290                 case 'list':
291                         $id     = requestVar('id');
292                         $start  = intRequestVar('start') ? intRequestVar('start') : 0;
293                         $amount = intRequestVar('amount') ? intRequestVar('amount') : 25;
294
295                         $ires = mysql_query ("
296                                 SELECT
297                                         ititle,
298                                         inumber
299                                 FROM
300                                         ".sql_table('item')."
301                                 WHERE
302                                         inumber = '".$id."'
303                         ");
304                         
305                         if ($irow = mysql_fetch_array($ires))
306                         {
307                                 $story['id']    = $id;
308                                 $story['title'] = $irow['ititle'];
309
310                                 $rres = mysql_query ("
311                                         SELECT
312                                                 COUNT(*) AS count
313                                         FROM
314                                                 ".sql_table('plugin_tb')." AS t
315                                         WHERE
316                                                 t.tb_id = '".$id."' AND
317                                                 t.block = 0
318                                 ");                             
319                                                         
320                                 if ($row = mysql_fetch_array($rres))
321                                         $count = $row['count'];
322                                 else
323                                         $count = 0;
324                                         
325                                 $rres = mysql_query ("
326                                         SELECT
327                                                 t.id AS id,
328                                                 t.title AS title,
329                                                 t.blog_name AS blog_name,
330                                                 t.excerpt AS excerpt,
331                                                 t.url AS url,
332                                         UNIX_TIMESTAMP(t.timestamp) AS timestamp
333                                         FROM
334                                                 ".sql_table('plugin_tb')." AS t
335                                         WHERE
336                                                 t.tb_id = '".$id."' AND
337                                                 t.block = 0
338                                         ORDER BY
339                                                 timestamp DESC
340                                         LIMIT
341                                                 ".$start.",".$amount."
342                                 ");                             
343                                 
344                                 $items = array();
345         
346                                 while ($rrow = mysql_fetch_array($rres))
347                                 {
348                                         $rrow['title']          = $oPluginAdmin->plugin->_cut_string($rrow['title'], 50);
349                                         $rrow['title']          = $oPluginAdmin->plugin->_strip_controlchar($rrow['title']);
350                                         $rrow['title']          = htmlspecialchars($rrow['title']);
351 //                                      $rrow['title']          = _CHARSET == 'UTF-8' ? $rrow['title'] : $oPluginAdmin->plugin->_utf8_to_entities($rrow['title']);
352         
353                                         $rrow['blog_name']      = $oPluginAdmin->plugin->_cut_string($rrow['blog_name'], 50);
354                                         $rrow['blog_name']      = $oPluginAdmin->plugin->_strip_controlchar($rrow['blog_name']);
355                                         $rrow['blog_name']      = htmlspecialchars($rrow['blog_name']);
356 //                                      $rrow['blog_name']      = _CHARSET == 'UTF-8' ? $rrow['blog_name'] : $oPluginAdmin->plugin->_utf8_to_entities($rrow['blog_name']);
357         
358                                         $rrow['excerpt']        = $oPluginAdmin->plugin->_cut_string($rrow['excerpt'], 800);
359                                         $rrow['excerpt']        = $oPluginAdmin->plugin->_strip_controlchar($rrow['excerpt']);
360                                         $rrow['excerpt']        = htmlspecialchars($rrow['excerpt']);
361 //                                      $rrow['excerpt']        = _CHARSET == 'UTF-8' ? $rrow['excerpt'] : $oPluginAdmin->plugin->_utf8_to_entities($rrow['excerpt']);
362         
363                                         $rrow['url']            = htmlspecialchars($rrow['url'], ENT_QUOTES);
364                                         $rrow['story'] = htmlspecialchars(strip_tags($rrow['story']), ENT_QUOTES);
365                                         $items[] = $rrow;
366                                 }
367                                 
368                                 $oTemplate->set ('amount', $amount);
369                                 $oTemplate->set ('count', $count);
370                                 $oTemplate->set ('start', $start);
371                                 $oTemplate->set ('items', $items);
372                                 $oTemplate->set ('story', $story);
373                                 $oTemplate->template('templates/list.html');                    
374                         }
375                         
376                         break;
377                                                         
378                 
379                 case 'index':
380                         $bres = mysql_query ("
381                                 SELECT
382                                         bnumber AS bnumber,
383                                         bname AS bname,
384                                         burl AS burl
385                                 FROM
386                                         ".sql_table('blog')."
387                                 ORDER BY
388                                         bname
389                         ");
390                         
391                         $blogs = array();
392                         
393                         while ($brow = mysql_fetch_array($bres))
394                         {
395                                 $ires = mysql_query ("
396                                         SELECT
397                                                 i.inumber AS inumber,
398                                             i.ititle AS ititle,
399                                             COUNT(*) AS total
400                                         FROM
401                                                 ".sql_table('item')." AS i,
402                                                 ".sql_table('plugin_tb')." AS t
403                                         WHERE
404                                                 i.iblog = ".$brow['bnumber']." AND
405                                                 t.tb_id = i.inumber AND
406                                                 t.block = 0
407                                         GROUP BY
408                                                 i.inumber
409                     ORDER BY
410                         i.inumber DESC
411                                 ");                             
412
413                                 $items = array();
414
415                                 while ($irow = mysql_fetch_array($ires))
416                                 {
417                                         $items[] = $irow;
418                                 }
419
420                                 $brow['items'] = $items;
421                                 $blogs[] = $brow;
422                         }
423
424                         $oTemplate->set ('blogs', $blogs);
425                         $oTemplate->template('templates/index.html');
426                         break;
427
428                 default:
429                         //modify start+++++++++
430                         if(!$tableVersion){
431                                 $oTemplate->template('templates/updatetable.html');
432                         }
433                         //modify end+++++++++
434                         break;
435         }
436
437         // Create the admin area page
438         echo $oTemplate->fetch();
439         
440         echo '<div align="right">Powered by <a href="http://www.famfamfam.com/lab/icons/silk/">Silk icon</a></div>';
441         $oPluginAdmin->end();   
442