4 // 0.72: Internationalize.
6 // 0.71: Fixed security issue.
9 class NP_UpdateTime extends NucleusPlugin
18 return 'nakahara21 + shizuki';
23 return 'http://nakahara21.com';
31 function getDescription()
33 return _UPDATETIME_DESCRIPTION;
36 function supportsFeature($what)
39 case 'SqlTablePrefix':
46 function getTableList()
49 sql_table('plugin_rectime')
53 function getEventList()
63 $query = 'CREATE TABLE IF NOT EXISTS ' . sql_table('plugin_rectime') . ' ('
64 . ' up_id INT(11) not null,'
65 . ' updatetime DATETIME,'
66 . ' PRIMARY KEY (up_id)'
69 $this->createOption('DefautMode', _UPDATETIME_DEFAULT_MODE, 'select', '1', _UPDATETIME_DEFAULT_MODE_VALUE);
70 $this->createOption('BeforeTime', _UPDATETIME_BEFORE_TIME, 'text', _UPDATETIME_BEFORE_TIME_VALUE);
71 $this->createOption('AfterTime', _UPDATETIME_AFTER_TIME, 'text', _UPDATETIME_AFTER_TIME_VALUE);
72 $this->createOption('DateFormat', _UPDATETIME_DATE_FORMAT, 'text', 'Y-m-d H:i:s');
73 $this->createOption('sLists', _UPDATETIME_S_LISTS, 'text', '<ul class="nobullets">');
74 $this->createOption('eLists', _UPDATETIME_E_LISTS, 'text', '</ul>');
75 $this->createOption('sItems', _UPDATETIME_S_ITEMS, 'text', '<li>');
76 $this->createOption('eItems', _UPDATETIME_E_ITEMS, 'text', '</li>');
77 $this->createOption('uninstFlag', _UPDATETIME_UNINST_FLAG, 'yesno', 'no');
82 if ($this->getOption('uninstFlag') == 'yes') {
83 sql_query ('DROP TABLE IF EXISTS ' . sql_table('plugin_rectime'));
89 $language = ereg_replace( '[\\|/]', '', getLanguageName());
90 if (file_exists($this->getDirectory() . $language . '.php')) {
91 include_once($this->getDirectory() . $language . '.php');
93 include_once($this->getDirectory() . 'english.php');
95 $this->defMode = intval($this->getOption('DefautMode'));
96 if ($this->defMode > 2) {
101 function event_EditItemFormExtras($data)
103 $checkedFlag[$this->defMode] = ' checked="checked"';
104 $updateMode = _UPDATETIME_MODE;
105 $updateOver = _UPDATETIME_OVERWRITE;
106 $recordOnly = _UPDATETIME_RECORDEONLY;
107 $noAction = _UPDATETIME_NOACTION;
108 $printData = '<h3 style="margin-bottom:0;">' . $updateMode . "</h3>\n"
109 . '<input type="radio" name="updatetime" value="2" id="updatetime_2"' . $checkedFlag[2] . ' />'
110 . '<label for="updatetime_2">' . $updateOverwrite . "</label><br />\n"
111 . '<input type="radio" name="updatetime" value="1" id="updatetime_1"' . $checkedFlag[1] . ' />'
112 . '<label for="updatetime_1">' . $recordOnly . "</label><br />\n"
113 . '<input type="radio" name="updatetime" value="0" id="updatetime_0"' . $checkedFlag[0] . ' />'
114 . '<label for="updatetime_0">' . $noAction . "</label><br />\n";
118 function event_PreUpdateItem($data)
120 $recd = intRequestVar('updatetime');
124 if (postVar('actiontype') == 'adddraft') {
128 $updatetime = mysqldate($data['blog']->getCorrectTime());
130 $upTimeQue = 'SELECT itime as result '
131 . 'FROM ' . sql_table('item')
132 . ' WHERE inumber=' . intval($data['itemid']);
133 $tmpTimeQue = 'SELECT updatetime as result '
134 . 'FROM ' . sql_table('plugin_rectime')
135 . ' WHERE up_id = ' . intval($data['itemid']);
136 $updatetime = '"' . quickQuery($upTimeQue) . '"';
137 $tmptime = '"' . quickQuery($tmpTimeQue) . '"';
138 $upQuery = 'UPDATE ' . sql_table('item')
139 . ' SET itime = ' . $updatetime
140 . ' WHERE inumber = ' . intval($data['itemid']);
141 if ($tmptime > $updatetime) {
142 $updatetime = $tmptime;
146 $delQuery = 'DELETE FROM ' . sql_table('plugin_rectime')
147 . ' WHERE up_id = ' . intval($data['itemid']);
148 sql_query($delQuery);
149 $query = 'INSERT INTO ' . sql_table('plugin_rectime')
150 . ' (up_id, updatetime) '
152 . ' (' . intval($data['itemid']) . ', "' . $updatetime . '")';
153 $res = sql_query($query);
154 if (strpos($res, 'mySQL')) {
155 return '<p>Could not save data: ' . $res;
160 function doSkinVar($skinType, $maxtoshow = 5, $bmode = 'current')
162 global $manager, $CONF, $blogid;
163 if (is_numeric($blogid)) {
164 $blogid = intval($blogid);
166 $blogid = gttBlogIDFromName($blogid);
169 $blogid = $CONF['DefaultBlog'];
172 $b =& $manager->getBlog($blogid);
173 $this->defaultBlogURL = $b->getURL() ;
174 if (!$this->defaultBlogURL) {
175 $this->defaultBlogURL = $CONF['IndexURL'];
178 if ($maxtoshow == '') {
185 echo $this->getOption('sLists') . "\n";
187 . ' r.up_id as up_id, '
188 . ' IF(INTERVAL(r.updatetime, i.itime), UNIX_TIMESTAMP(r.updatetime), UNIX_TIMESTAMP(i.itime)) as utime '
190 . sql_table('plugin_rectime') . ' as r, '
191 . sql_table('item') . ' as i '
193 . ' r.up_id=i.inumber';
194 if ($bmode != 'all') {
195 $query .= ' and i.iblog=' . intval($blogid);
197 $query .= ' ORDER BY utime DESC'
198 . ' LIMIT 0, ' . intval($maxtoshow);
199 $res = sql_query($query);
200 while ($row = mysql_fetch_object($res)) {
201 $item =& $manager->getItem($row->up_id, 0, 0);
203 $itemlink = $this->createGlobalItemLink($item['itemid']);
204 $itemtitle = strip_tags($item['title']);
205 $itemtitle = shorten($itemtitle,26,'..');
206 $itemdate = date('m/d H:i',$row->utime);
208 $printData = $this->getOption('sItems') . "\n"
209 . '<a href="' . $itemlink . '">'
210 . htmlspecialchars($itemtitle, ENT_QUOTES, _CHARSET)
211 .'</a> <small>' . $itemdate . "</small>\n"
212 . $this->getOption('eItems') . "\n";
217 echo $this->getOption('eLists');
220 function doTemplateVar(&$item)
224 . ' UNIX_TIMESTAMP(r.updatetime) as updatetime,'
225 . ' UNIX_TIMESTAMP(i.itime) as itemtime '
227 . sql_table('plugin_rectime') . ' as r, '
228 . sql_table('item') . ' as i '
230 . ' r.up_id = ' . intval($item->itemid)
231 . ' and r.up_id = i.inumber';
232 $res = sql_query($query);
233 if ($row = mysql_fetch_assoc($res)) {
234 $data['utime'] = date($this->getOption('DateFormat'), $row['updatetime']);
235 if ($row['updatetime'] > $row['itemtime']) {
236 echo TEMPLATE::fill($this->getOption('AfterTime'), $data);
237 } elseif ($row['updatetime'] < $row['itemtime']) {
238 echo TEMPLATE::fill($this->getOption('BeforeTime'), $data);
243 function createGlobalItemLink($itemid, $extra = '')
245 global $CONF, $manager;
246 /* if ($CONF['URLMode'] == 'pathinfo') {
247 $link = $CONF['ItemURL'] . '/item/' . $itemid;
249 $blogid = getBlogIDFromItemID($itemid);
250 $b_tmp =& $manager->getBlog($blogid);
251 $blogurl = $b_tmp->getURL() ;
253 $blogurl = $this->defaultBlogURL;
255 if(substr($blogurl, -4) != '.php'){
256 if(substr($blogurl, -1) != '/')
258 $blogurl .= 'index.php';
260 $link = $blogurl . '?itemid=' . $itemid;
262 return addLinkParams($link, $extra);*/
263 $blogid = getBlogIDFromItemID($itemid);
264 $b_tmp =& $manager->getBlog($blogid);
265 $blogurl = $b_tmp->getURL() ;
267 $blogurl = $this->defaultBlogURL;
269 if (substr($blogurl, -4) != '.php') {
270 if(substr($blogurl, -1) != '/')
272 $blogurl .= 'index.php';
274 if (($CONF['URLMode'] == 'pathinfo') && (substr($blogurl, -4) == '.php')) {
275 $originalURLMode = $CONF['URLMode'];
276 $CONF['URLMode'] = 'normal';
278 $originalItemURL = $CONF['ItemURL'];
279 $CONF['ItemURL'] = $blogurl;
280 $link = createItemLink($itemid, $extra);
281 $CONF['ItemURL'] = $originalItemURL;
282 if ($CONF['URLMode'] <> $originalURLMode) {
283 $CONF['URLMode'] = $originalURLMode;