public function main() { App::import('vendor', 'inc/packer'); $js_pack = Configure::read("Asset.filter.js"); $time = date('YmdHis', time()); $p = new Packer(); $js_out = $css_out = ''; //delete old file $old = nforum_cache_read('asset_pack'); if (is_array($old)) { @unlink(APP . 'www/js/' . $old['js']); @unlink(APP . 'www/css/' . $old['css']); } /* handle js*/ $js = array('jquery-1.7.2.min.js', 'jquery-ui-1.8.20.min.js', 'jquery-ui-timepicker-addon.js', 'underscore-min.js', 'backbone-min.js', 'plupload.min.js', 'jquery.tools.min.js', 'jquery.placeholder.min.js', 'jquery.cookie.js', 'jquery.simpletree.js', 'jquery.jplayer.min.js', 'jquery.xslider.min.js', 'forum.config.js', 'forum.lib.js', 'forum.xwidget.js', 'forum.xubb.js', 'forum.keyboard.js'); foreach ($js as $v) { $js_out .= $js_pack && !strstr($v, 'min.js') ? $p->pack(APP . 'www/js/' . $v, 'js', false) : file_get_contents(APP . 'www/js/' . $v); } $js_file = 'pack_' . $this->_hash($js_out) . '.js'; file_put_contents(APP . 'www/js/' . $js_file, $js_out); /* handle js end */ /* handle css */ $css = array('common.css', 'jquery-ui-1.8.20.css', 'jplayer.blue.monday.css', 'ansi.css', 'ubb.css', 'keyboard.css'); foreach ($css as $v) { $css_out .= $p->pack(APP . 'www/css/' . $v, 'css', false); } $css_file = 'pack_' . $this->_hash($css_out) . '.css'; file_put_contents(APP . 'www/css/' . $css_file, $css_out); /* handle css end */ $asset = array('js' => $js_file, 'css' => $css_file); nforum_cache_write('asset_pack', $asset); }
public function index() { $this->css[] = "xwidget.css"; $this->notice = array(array("url" => Configure::read("site.notice.url"), "text" => Configure::read("site.notice.text"))); App::import('Sanitize'); App::import('vendor', 'model/widget'); $u = User::getInstance(); $ret = $w = array(); $ret = Widget::wGet($u); if (empty($ret)) { $this->set("widget", array()); return; } $persistent = Configure::read("widget.persistent"); if ($persistent) { $time = (array) nforum_cache_read("widget_time"); $update = false; } $w = array_fill(1, $u->getCustom("userdefine1", 31) == 1 ? 3 : 2, array()); foreach ($ret as $v) { $w[$v['col']][$v['row']] = $v; if ($persistent) { try { $ww = Widget::getInstance($v['name']); if (!$ww->wHasPerm(User::getInstance())) { $ww = new EWidget('你无权访问此应用'); $html = Widget::html($ww->wGetList()); } else { if (strpos($v['name'], "favor-") === 0) { $html = Widget::html($ww->wGetList()); } else { if (!isset($time[$v['name']]) || $time[$v['name']] < $ww->wGetTime() || false === ($html = nforum_cache_read("widget_" . $v['name']))) { $time[$v['name']] = $ww->wGetTime(); $html = Widget::html($ww->wGetList()); nforum_cache_write("widget_" . $v['name'], $html); $update = true; } } } } catch (WidgetNullException $e) { $ww = new EWidget(); //if persistent,it will not check wiget time and will not update widget_time. $html = Widget::html($ww->wGetList()); } $w[$v['col']][$v['row']]['content'] = $html; } } if ($persistent && $update) { nforum_cache_write("widget_time", $time); } foreach ($w as &$v) { ksort($v); } $this->set("widget", $w); $this->jsr[] = 'SYS.widget.persistent=' . ($persistent ? 'true' : 'false'); $this->jsr[] = "xWidget.init(SESSION.get('is_login'), SESSION.get('id'))"; }
function main() { $db = DB::getInstance(); $week = strtotime(date("Y-m-d", time() - 86400 * 7)); $sql = "select vid,subject,num from pl_vote where start>{$week} and status=1 order by num desc,vid desc limit 10"; $res = $db->all($sql); nforum_cache_write("vote_week", $res); $week = strtotime(date("Y-m-01", time())); $sql = "select vid,subject,num from pl_vote where start>{$week} and status=1 order by num desc,vid desc limit 10"; $res = $db->all($sql); nforum_cache_write("vote_month", $res); $week = strtotime(date("Y-01-01", time())); $sql = "select vid,subject,num from pl_vote where start>{$week} and status=1 order by num desc,vid desc limit 10"; $res = $db->all($sql); nforum_cache_write("vote_year", $res); }
public function main() { $week = array("日", "一", "二", "三", "四", "五", "六"); $date[] = "周" . $week[intval(date("w"))]; $date[] = "周" . $week[intval(date("w", time() + 24 * 60 * 60))]; $date[] = "周" . $week[intval(date("w", time() + 2 * 24 * 60 * 60))]; $file = "http://php.weather.sina.com.cn/xml.php?city=%B1%B1%BE%A9&password=DJOYnieT8234jlsK&day="; $res = ""; for ($j = 0; $j <= 2; $j++) { $data = file_get_contents($file . $j); $xml_parser = xml_parser_create(); xml_parser_set_option($xml_parser, XML_OPTION_CASE_FOLDING, 0); xml_parser_set_option($xml_parser, XML_OPTION_SKIP_WHITE, 1); xml_parse_into_struct($xml_parser, $data, $vals); xml_parser_free($xml_parser); //print_r($vals); $encoding = Configure::read("App.encoding"); for ($i = 0; $i <= count($vals) - 1; $i++) { if ($vals[$i]['tag'] == "status1" && $vals[$i]['type'] == "complete") { $curStatB = nforum_iconv("utf-8", $encoding, $vals[$i]['value']); } if ($vals[$i]['tag'] == "status2" && $vals[$i]['type'] == "complete") { $curStatE = nforum_iconv("utf-8", $encoding, $vals[$i]['value']); } if ($vals[$i]['tag'] == "temperature1" && $vals[$i]['type'] == "complete") { $curTemp1 = $vals[$i]['value']; } if ($vals[$i]['tag'] == "temperature2" && $vals[$i]['type'] == "complete") { $curTemp2 = $vals[$i]['value']; } if ($vals[$i]['tag'] == "power1" && $vals[$i]['type'] == "complete") { $curWind1 = nforum_iconv("utf-8", $encoding, $vals[$i]['value']); } if ($vals[$i]['tag'] == "power2" && $vals[$i]['type'] == "complete") { $curWind2 = nforum_iconv("utf-8", $encoding, $vals[$i]['value']); } if ($vals[$i]['tag'] == "zwx_l" && $vals[$i]['type'] == "complete") { $zwx = nforum_iconv("utf-8", $encoding, $vals[$i]['value']); } if ($vals[$i]['tag'] == "Weather" && $vals[$i]['type'] == "open") { $curDate = ""; $curStatB = ""; $curStatE = ""; $curTemp1 = ""; $curTemp2 = ""; $img = ""; $curWind1 = ""; $curWind2 = ""; $zwx = ""; } if ($vals[$i]['tag'] == "Weather" && $vals[$i]['type'] == "close") { $img = $this->st2img($curStatB); if ($curStatB != $curStatE) { $curStatB .= "转" . $curStatE; $img .= "" . $this->st2img($curStatE); } if ($curWind1 != $curWind2) { $curWind1 .= "至" . $curWind2 . "级"; } else { $curWind1 .= "级"; } $res .= "|" . $date[$j] . " " . $curStatB . " " . $curTemp1 . "℃-" . $curTemp2 . "℃" . "&风力:" . $curWind1 . (empty($zwx) ? "" : " 紫外线:" . $zwx) . "#" . $img; } } } nforum_cache_write('weather_day', substr($res, 1)); }
private function _cache_write($name, $modify, $content) { nforum_cache_write('rss_' . $name, $content); $this->_time[$name] = $modify; nforum_cache_write('rss_time', $this->_time); }