OSDN Git Service

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