2 class NP_LatestWritebacks extends NucleusPlugin
5 function supportsFeature($what)
15 // function getEventList()
22 return 'Latest Writebacks';
27 return 'nakahara21 + Fujisaki + kimitake + shizuki';
32 return 'http://nakahara21.com/';
40 function getDescription()
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');
47 include_once($this->getDirectory() . 'english.php');
49 $description = _NP_LRWITEBACKS_DESC;
50 // $description = 'This plugin can be used to display the last few comments'
51 // . 'and Trackbacks.<br />'
52 // . 'Usage:<%LatestWritebacks(10,current,all)%>';
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');
63 include_once($this->getDirectory() . 'english.php');
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 $this->createOption('cmttemplate', _NP_LRWITEBACKS_CBODY, 'textarea',
70 '<li>♣<a href="<%itemlink%>#c<%commentid%>"><%commentdate%>|<%commentator%>><%commentbody%></a></li>');
71 $this->createOption('cmlistfoot', _NP_LRWITEBACKS_CFOOT, 'textarea', '</ul>');
72 $this->createOption('tblisthead', _NP_LRWITEBACKS_THEAD, 'textarea', '<ul class="nobullets">');
73 $this->createOption('tbktemplate', _NP_LRWITEBACKS_TBODY, 'textarea',
74 '<li>…<a href="<%itemlink%>#trackback"><%tbdate%>|<%blogname%> ping: "<%entrytitle%>"</a></li>');
75 $this->createOption('tblistfoot', _NP_LRWITEBACKS_TFOOT, 'textarea', '</ul>');
77 Comment list template sample
79 <ol class="recent-comment">
81 <li><a href="<%itemlink%>#c<%commentid%>" title="<%commentbody%>"><%commentator%>(<%commentday%>)</a></li>
85 TrackBack list template sample
87 <ol class="recent-trackback">
89 <li><a href="<%itemlink%>#tb<%tbid%>" title="<%expect%>"><%blogname%> : <%entrytitle%>(<%tbday%>)</a></li>
95 function pluginCheck($pluginName)
98 if (!$manager->pluginInstalled('NP_' . $pluginName)) {
101 $plugin =& $manager->getPlugin('NP_' . $pluginName);
105 function doSkinVar($skinType,
106 $numberOfWritebacks = 5,
109 $numberOfCharacters = 60,
110 $numberOfTitleCharacters = 40,
113 global $manager, $CONF, $blog;
115 if (!is_numeric($numberOfWritebacks)) {
116 $filter = $numberOfWritebacks;
117 $numberOfWritebacks = 5; // defaults to 5
119 $b =& $manager->getBlog($CONF['DefaultBlog']);
120 $this->defaultblogurl = $b->getURL() ;
121 if (!$this->defaultblogurl)
122 $this->defaultblogurl = $CONF['IndexURL'] ;
126 $blogid = $b->getID(); //for select
128 $filter = trim($filter);
129 if($filter == 'current'){
130 $filter = 'cblog = ' . $blogid;
131 } elseif (strstr($filter, '=')) {
132 $filter = str_replace('=', '', $filter);
133 $filter = ' cblog IN(' . str_replace('/', ',', $filter) . ')';
134 } elseif (strstr($filter, '<>')) {
135 $filter = str_replace('<>', '', $filter);
136 $filter = ' cblog <> ' . str_replace('/', ' AND cblog <> ', $filter);
139 setlocale(LC_TIME, $this->getOption('timelocale'));
142 if ($TBorCm != 't') {
145 . ' c.cnumber as commentid,'
146 . ' c.cuser as commentator,'
147 . ' c.cbody as commentbody,'
148 . ' c.citem as itemid,'
149 . ' c.cmember as memberid,'
150 // . ' c.ctime as commentdate,'
151 . ' SUBSTRING(c.ctime, 6, 5) as commentday,'
152 . ' UNIX_TIMESTAMP(c.ctime) as ctimest';
153 if ($EzComment2 = $this->pluginCheck('EzComment2')) {
154 if (method_exists($EzComment2, 'getTemplateParts')) {
155 $query .= ', s.comid as cid, '
156 . 's.secflg as secret, '
157 . 's.module as modname, '
158 . 's.userID as identity ';
159 $join = ' LEFT OUTER JOIN ' . sql_table('plug_ezcomment2') . ' as s '
160 . ' ON c.cnumber = s.comid ';
164 $query .= ' FROM ' . sql_table('comment') .' as c ' . $join;
166 $query .= ' WHERE ' . $filter;
168 $query .= ' ORDER by c.ctime DESC LIMIT 0, ' . $numberOfWritebacks;
170 $comments = sql_query($query);
172 if (mysql_num_rows($comments)) {
173 while ($row = mysql_fetch_object($comments)) {
174 $content = (array)$row;
175 $tempBody = strip_tags($content['commentbody']);
176 $tempBody = htmlspecialchars($tempBody, ENT_QUOTES);
177 $tempBody = shorten($tempBody, $numberOfCharacters, $toadd);
178 $tempBody = htmlspecialchars(htmlspecialchars_decode($tempBody), ENT_QUOTES);
179 $tempBody = str_replace("\r\n", ' ', $tempBody);
180 $content['commentdate'] = strftime($this->getOption('cmdateformat'), $content['ctimest']);
181 $content['commentbody'] = str_replace("&amp;", '&', $tempBody);
182 if (!empty($row->memberid)) {
184 $mem->readFromID(intval($row->memberid));
185 $content['commentator'] = $mem->getRealName();
188 $bid = intval(getBlogIDFromItemID(intval($comment['itemid'])));
189 if ($EzComment2->getBlogOption($bid, 'secret') == 'yes') {
190 $b = $manager->getBlog($bid);
192 $judge = $EzComment2->setSecretJudge($bid, $member, $b);
195 if ($judge && $content['secret']) {
196 $content = $EzComment2->JudgementCommentSecrets($content, $judge);
199 /* $cid = $row->cnumber;
201 $ctst = date("y-m-d H:i",$ct);
202 $text = strip_tags($row->cbody);
203 $text = htmlspecialchars($text, ENT_QUOTES);
204 $ctext = shorten($text,$numberOfCharacters,$toadd);
206 if (!$row->cmember) $myname = $row->cuser;
209 $mem->readFromID(intval($row->cmember));
210 $myname = $mem->getRealName();
213 // $itemlink = $this->_createItemLink($row->citem, '');
214 // $arr_res[$ct] = "<li>♣<a href=\"".$itemlink."#c".$cid."\">$ctst|".$myname.">".$ctext."</a></li>" ;
215 $itemlink = $this->_createItemLink($content['itemid']);
216 $content['itemlink'] = $itemlink;
217 $arr_res[$content['ctimest']] = TEMPLATE::fill($this->getOption('cmttemplate'), $content);
222 //=========================
224 if ($manager->pluginInstalled('NP_TrackBack') && $TBorCm != 'c') {
227 . ' t.title as entrytitle,'
228 . ' t.excerpt as expect,'
230 . ' t.tb_id as trackbackid,'
231 . ' t.blog_name as blogname,'
232 . ' t.timestamp as tbdate,'
233 . ' SUBSTRING(t.timestamp, 6, 5) as tbday,'
234 . ' UNIX_TIMESTAMP(t.timestamp) as ttimest'
235 . ' FROM ' . sql_table('plugin_tb') . ' t,'
236 . sql_table('item') . ' i'
237 . ' WHERE t.tb_id = i.inumber';
238 if ($this->checkTBVersion()) {
239 $query .= ' and t.block = 0';
242 $tfilter = str_replace('cblog', 'i.iblog', $filter);
243 $query .= ' and ' . $tfilter;
245 $query .= ' ORDER by t.timestamp DESC LIMIT 0, ' . $numberOfWritebacks;
247 $comments = mysql_query($query);
249 if (mysql_num_rows($comments)) {
250 while ($row = mysql_fetch_object($comments)) {
251 $content = (array)$row;
252 $entrytitle = strip_tags($content['entrytitle']);
253 $entrytitle = htmlspecialchars($entrytitle, ENT_QUOTES);
254 $entrytitle = shorten($entrytitle, $numberOfCharacters, $toadd);
255 $entrytitle = htmlspecialchars($entrytitle, ENT_QUOTES);
256 $content['entrytitle'] = $entrytitle;
257 $content['expect'] = str_replace("\r\n", ' ', $content['expect']);
258 $blogname = htmlspecialchars($content['blogname'], ENT_QUOTES);
259 $content['blogname'] = $blogname;
260 $content['tbdate'] = strftime($this->getOption('tbdateformat'), $content['ttimest']);
262 /* $title = strip_tags($row->title);
263 $title = htmlspecialchars($title, ENT_QUOTES);
264 $ctitle = shorten($title,$numberOfCharacters,$toadd);
265 $blogname = htmlspecialchars($row->blog_name, ENT_QUOTES);
266 $tbtime = $row->ttimest;
267 $ttst = date("y-m-d H:i",$tbtime);*/
269 // $itemlink = $this->_createItemLink($row->tb_id, '');
270 // $arr_res[$tbtime] = '<li>…<a href="'.$itemlink.'#trackback">'.$ttst.'|'.$blogname.' ping: "'.$ctitle.'"</a></li>';
271 $itemlink = $this->_createItemLink($content['trackbackid']);
272 $content['itemlink'] = $itemlink;
273 $arr_res[$content['ttimest']] = TEMPLATE::fill($this->getOption('tbktemplate'), $content);
277 //=========================
279 $ress = array_values($arr_res);
280 $show_rescnt = min(intval($numberOfWritebacks), count($arr_res));
284 $head = $this->getOption('cmlisthead');
285 $foot = $this->getOption('cmlistfoot');
288 $head = $this->getOption('tblisthead');
289 $foot = $this->getOption('tblistfoot');
292 $head = ' <ul class="nobullets"> ';
296 // echo ' <ul class="nobullets"> ';
298 for ($j=0; $j < $show_rescnt; $j++) {
299 echo $ress[$j] . "\n";
305 function checkTBVersion()
307 $res = sql_query('SHOW FIELDS FROM ' . sql_table('plugin_tb') );
308 $fieldnames = array();
309 while ($co = mysql_fetch_assoc($res)) {
310 $fieldnames[] = $co['Field'];
312 if (in_array('block', $fieldnames)) {
319 function _createItemLink($itemid)
321 global $CONF, $manager, $blog;
323 $blogid = getBlogIDFromItemID($itemid);
324 $b =& $manager->getBlog($blogid);
325 $blogurl = $b->getURL();
329 $b_tmp =& $manager->getBlog($CONF['DefaultBlog']);
330 $blogurl = $b_tmp->getURL();
333 $blogurl = $CONF['IndexURL'];
334 if ($CONF['URLMode'] != 'pathinfo') {
335 $blogurl = $CONF['Self'];
339 if ($CONF['URLMode'] == 'pathinfo') {
340 $blogurl = preg_replace('/\/$/', '', $blogurl);
342 $CONF['ItemURL'] = $blogurl;
344 return createItemLink($itemid);