4 // 0.80: Fixed bug (by nakahara21)
5 // 0.72: Internationalize.
7 // 0.71: Fixed security issue.
10 class NP_UpdateTime extends NucleusPlugin
19 return 'nakahara21 + shizuki';
24 return 'http://nakahara21.com';
32 function getDescription()
34 return _UPDATETIME_DESCRIPTION;
37 function supportsFeature($what)
40 case 'SqlTablePrefix':
47 function getTableList()
50 sql_table('plugin_rectime')
54 function getEventList()
64 $query = 'CREATE TABLE IF NOT EXISTS ' . sql_table('plugin_rectime') . ' ('
65 . ' up_id INT(11) not null,'
66 . ' updatetime DATETIME,'
67 . ' PRIMARY KEY (up_id)'
70 $this->createOption('DefautMode', _UPDATETIME_DEFAULT_MODE, 'select', '1', _UPDATETIME_DEFAULT_MODE_VALUE);
71 $this->createOption('BeforeTime', _UPDATETIME_BEFORE_TIME, 'text', _UPDATETIME_BEFORE_TIME_VALUE);
72 $this->createOption('AfterTime', _UPDATETIME_AFTER_TIME, 'text', _UPDATETIME_AFTER_TIME_VALUE);
73 $this->createOption('Locale', _UPDATETIME_DATE_LOCALE, 'text', 'ja_JP.' . _CHARSET);
74 $this->createOption('DateFormat', _UPDATETIME_DATE_FORMAT, 'text', '%Y-%m-%d %H:%M:%S');
75 $this->createOption('sLists', _UPDATETIME_S_LISTS, 'text', '<ul class="nobullets">');
76 $this->createOption('eLists', _UPDATETIME_E_LISTS, 'text', '</ul>');
77 $this->createOption('sItems', _UPDATETIME_S_ITEMS, 'text', '<li>');
78 $this->createOption('eItems', _UPDATETIME_E_ITEMS, 'text', '</li>');
79 $this->createOption('uninstFlag', _UPDATETIME_UNINST_FLAG, 'yesno', 'no');
84 if ($this->getOption('uninstFlag') == 'yes') {
85 sql_query ('DROP TABLE IF EXISTS ' . sql_table('plugin_rectime'));
91 $language = ereg_replace( '[\\|/]', '', getLanguageName());
92 if (file_exists($this->getDirectory() . $language . '.php')) {
93 include_once($this->getDirectory() . $language . '.php');
95 include_once($this->getDirectory() . 'english.php');
97 $this->defMode = intval($this->getOption('DefautMode'));
98 if ($this->defMode > 2) {
103 function event_EditItemFormExtras($data)
105 $checkedFlag[$this->defMode] = ' checked="checked"';
106 $updateMode = _UPDATETIME_MODE;
107 $updateOver = _UPDATETIME_OVERWRITE;
108 $recordOnly = _UPDATETIME_RECORDEONLY;
109 $noAction = _UPDATETIME_NOACTION;
110 $printData = '<h3 id="np_updatetime_ares" style="margin-bottom:0;">' . $updateMode . "</h3>\n"
111 . '<input type="radio" name="updatetime" value="2" id="updatetime_2"' . $checkedFlag[2] . ' />'
112 . '<label for="updatetime_2">' . $updateOver . "</label><br />\n"
113 . '<input type="radio" name="updatetime" value="1" id="updatetime_1"' . $checkedFlag[1] . ' />'
114 . '<label for="updatetime_1">' . $recordOnly . "</label><br />\n"
115 . '<input type="radio" name="updatetime" value="0" id="updatetime_0"' . $checkedFlag[0] . ' />'
116 . '<label for="updatetime_0">' . $noAction . "</label><br />\n";
120 function event_PreUpdateItem($data)
122 $recd = intRequestVar('updatetime');
126 if (postVar('actiontype') == 'adddraft') {
130 $updatetime = mysqldate($data['blog']->getCorrectTime());
132 $upQuery = 'UPDATE ' . sql_table('item')
133 . ' SET itime = ' . $updatetime
134 . ' WHERE inumber = ' . intval($data['itemid']);
135 $upTimeQue = 'SELECT itime as result '
136 . 'FROM ' . sql_table('item')
137 . ' WHERE inumber=' . intval($data['itemid']);
138 $tmpTimeQue = 'SELECT updatetime as result '
139 . 'FROM ' . sql_table('plugin_rectime')
140 . ' WHERE up_id = ' . intval($data['itemid']);
141 $updatetime = '"' . quickQuery($upTimeQue) . '"';
142 $tmptime = '"' . quickQuery($tmpTimeQue) . '"';
143 if ($tmptime > $updatetime) {
144 $updatetime = $tmptime;
148 $delQuery = 'DELETE FROM ' . sql_table('plugin_rectime')
149 . ' WHERE up_id = ' . intval($data['itemid']);
150 sql_query($delQuery);
151 $query = 'INSERT INTO ' . sql_table('plugin_rectime')
152 . ' (up_id, updatetime) '
154 . ' (' . intval($data['itemid']) . ', ' . $updatetime . ')';
155 $res = sql_query($query);
156 if (strpos($res, 'mySQL')) {
157 return '<p>Could not save data: ' . $res;
162 function doSkinVar($skinType, $maxtoshow = 5, $bmode = 'current')
164 global $manager, $CONF, $blogid;
165 if (is_numeric($blogid)) {
166 $blogid = intval($blogid);
168 $blogid = gttBlogIDFromName($blogid);
171 $blogid = $CONF['DefaultBlog'];
174 $b =& $manager->getBlog($blogid);
175 $this->defaultBlogURL = $b->getURL() ;
176 if (!$this->defaultBlogURL) {
177 $this->defaultBlogURL = $CONF['IndexURL'];
180 if ($maxtoshow == '') {
187 echo $this->getOption('sLists') . "\n";
189 . ' r.up_id as up_id, '
190 . ' IF(INTERVAL(r.updatetime, i.itime), UNIX_TIMESTAMP(r.updatetime), UNIX_TIMESTAMP(i.itime)) as utime '
192 . sql_table('plugin_rectime') . ' as r, '
193 . sql_table('item') . ' as i '
195 . ' r.up_id=i.inumber';
196 if ($bmode != 'all') {
197 $query .= ' and i.iblog=' . intval($blogid);
199 $query .= ' ORDER BY utime DESC'
200 . ' LIMIT 0, ' . intval($maxtoshow);
201 $res = sql_query($query);
202 while ($row = mysql_fetch_object($res)) {
203 $item =& $manager->getItem($row->up_id, 0, 0);
205 $itemlink = $this->createGlobalItemLink($item['itemid']);
206 $itemtitle = strip_tags($item['title']);
207 $itemtitle = shorten($itemtitle,26,'..');
208 $itemdate = date('m/d H:i',$row->utime);
210 $printData = $this->getOption('sItems') . "\n"
211 . '<a href="' . $itemlink . '">'
212 . htmlspecialchars($itemtitle, ENT_QUOTES, _CHARSET)
213 .'</a> <small>' . $itemdate . "</small>\n"
214 . $this->getOption('eItems') . "\n";
219 echo $this->getOption('eLists');
222 function doTemplateVar(&$item)
224 setlocale(LC_TIME, $this->getOption('Locale'));
227 . ' UNIX_TIMESTAMP(r.updatetime) as updatetime,'
228 . ' UNIX_TIMESTAMP(i.itime) as itemtime '
230 . sql_table('plugin_rectime') . ' as r, '
231 . sql_table('item') . ' as i '
233 . ' r.up_id = ' . intval($item->itemid)
234 . ' and r.up_id = i.inumber';
235 $res = sql_query($query);
236 if ($row = mysql_fetch_assoc($res)) {
237 // $data['utime'] = date($this->getOption('DateFormat'), $row['updatetime']);
238 $data['utime'] = strftime($this->getOption('DateFormat'), $row['updatetime']);
239 if ($row['updatetime'] > $row['itemtime']) {
240 echo TEMPLATE::fill($this->getOption('AfterTime'), $data);
241 } elseif ($row['updatetime'] < $row['itemtime']) {
242 echo TEMPLATE::fill($this->getOption('BeforeTime'), $data);
247 function createGlobalItemLink($itemid, $extra = '')
249 global $CONF, $manager;
250 /* if ($CONF['URLMode'] == 'pathinfo') {
251 $link = $CONF['ItemURL'] . '/item/' . $itemid;
253 $blogid = getBlogIDFromItemID($itemid);
254 $b_tmp =& $manager->getBlog($blogid);
255 $blogurl = $b_tmp->getURL() ;
257 $blogurl = $this->defaultBlogURL;
259 if(substr($blogurl, -4) != '.php'){
260 if(substr($blogurl, -1) != '/')
262 $blogurl .= 'index.php';
264 $link = $blogurl . '?itemid=' . $itemid;
266 return addLinkParams($link, $extra);*/
267 $blogid = getBlogIDFromItemID($itemid);
268 $b_tmp =& $manager->getBlog($blogid);
269 $blogurl = $b_tmp->getURL() ;
271 $blogurl = $this->defaultBlogURL;
273 if (substr($blogurl, -4) != '.php') {
274 if(substr($blogurl, -1) != '/')
276 $blogurl .= 'index.php';
278 if (($CONF['URLMode'] == 'pathinfo') && (substr($blogurl, -4) == '.php')) {
279 $originalURLMode = $CONF['URLMode'];
280 $CONF['URLMode'] = 'normal';
282 $originalItemURL = $CONF['ItemURL'];
283 $CONF['ItemURL'] = $blogurl;
284 $link = createItemLink($itemid, $extra);
285 $CONF['ItemURL'] = $originalItemURL;
286 if ($CONF['URLMode'] <> $originalURLMode) {
287 $CONF['URLMode'] = $originalURLMode;