public function wGetList() { $prefix = configure::read('site.prefix'); $res = nforum_cache_read('weather_day'); $w = explode("|", (string) $res); if (!is_array($w) || count((array) $w) != 3) { return $this->_error('该应用数据错误'); } $res = ""; $color = array("red", "blue", "green"); foreach ($w as $k => $v) { $res .= '<ul><li style="height:40px;line-height:18px;padding-bottom:3px;border-bottom:1px solid #dce9f5">'; $img = explode("#", $v); $content = explode("&", $img[0]); if (!isset($img[1]) || !isset($content[1])) { return $this->_error('该应用数据错误'); } $date = $content[0]; $content = $content[1]; $img = $img[1]; if (isset($img[1])) { $res .= '<img src="' . $prefix . '/img/app/weather/' . $img[1] . '.png" style="float:right"/>'; } $res .= '<img src="' . $prefix . '/img/app/weather/' . $img[0] . '.png" style="float:right;"/>'; $res .= '<div style="color:' . $color[$k] . ';padding-top:5px">'; $res .= $date . '<br />' . $content . '</div>'; $res .= "</li></ul>"; } return array("s" => parent::$S_FREE, "v" => array(array("text" => $res, "url" => ""))); }
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'))"; }
public function index() { $this->css[] = "xwidget.css"; $this->css['plugin']['vote'][] = "vote.css"; $this->js['plugin']['vote'][] = "vote.js"; $this->cache(false); @($category = $this->params['url']['c']); $u = User::getInstance(); $time = time(); $yes = $time - 86400; $search = ''; if (isset($this->params['url']['s'])) { $search = trim(rawurldecode($this->params['url']['s'])); $search = nforum_iconv('utf-8', $this->encoding, $search); if ('' != $search) { App::import('Sanitize'); $this->set('search', Sanitize::html($search)); $search = addslashes($search); $search = " and (uid like '%{$search}%' or subject like '%{$search}%' or `desc` like '%{$search}%')"; } } switch ($category) { case 'hot': $title = "热门投票"; $sql = "select * from pl_vote where status=1 and end>{$yes} {$search} order by num desc, vid desc"; break; case 'list': @($user = $this->params['url']['u']); if ($u->userid != $user) { try { $user = User::getInstance($user); } catch (UserNullException $e) { $this->error(ECode::$USER_NOID); } } else { $user = $u; } $title = $user->userid == $u->userid ? "我的投票" : "{$user->userid}的投票"; $this->set("vote_user", $user->userid); $sql = "select * from pl_vote where status=1 and uid='{$user->userid}' {$search} order by vid desc"; break; case 'all': $title = "全部投票"; $sql = "select * from pl_vote where status=1 {$search} order by vid desc"; break; case 'join': $this->requestLogin(); $title = "我参与的投票"; $sql = "select * from pl_vote where status=1 and vid in (select vid from pl_vote_result where uid='{$u->userid}') {$search} order by vid desc"; break; case 'del': if (!$u->isAdmin()) { $this->error('你无权查看此类投票'); } $title = "已删除的投票"; $sql = "select * from pl_vote where status=0 {$search} order by vid desc"; break; default: $title = "最新投票"; $category = "new"; $sql = "select * from pl_vote where status=1 and end>{$yes} {$search} order by vid desc"; } $list = new VoteList($sql); App::import("vendor", "inc/pagination"); $page = new Pagination($list, 10); $p = isset($this->params['url']['p']) ? $this->params['url']['p'] : 1; $res = $page->getPage($p); if (count($res) == 0) { $info = false; } else { $info = array(); App::import('Sanitize'); foreach ($res as $v) { $info[] = array("vid" => $v->vid, "title" => Sanitize::html($v->subject), "start" => date("Y-m-d H:i:s", $v->start), "end" => date("Y-m-d", $v->end), "num" => $v->num, "isEnd" => $v->isEnd(), "isDel" => $v->isDeleted(), "admin" => $u->userid === $v->uid || $u->isAdmin(), "uid" => $v->uid); } } $query = $this->params['url']; unset($query['url']); unset($query['p']); unset($query['ext']); foreach ($query as $k => &$v) { $v = $k . '=' . rawurlencode($v); } $query[] = "p=%page%"; $link = "{$this->base}/vote?" . join("&", $query); $pageBar = $page->getPageBar($p, $link); $this->set("pageBar", $pageBar); $this->set("totalNum", $list->getTotalNum()); $this->set("info", $info); $this->set("category", $category); $this->set("voteTitle", $title); $this->notice[] = array("url" => "", "text" => $title); /* right rank*/ $week = nforum_cache_read("vote_week"); $month = nforum_cache_read("vote_month"); $year = nforum_cache_read("vote_year"); $this->set("week", $week); $this->set("month", $month); $this->set("year", $year); /* right rank end*/ }
public function wGetList() { if (!in_array("vote", Configure::read("plugins.install"))) { return $this->_error("该应用已停用"); } App::import('Sanitize'); $ret = array(); $db = DB::getInstance(); //new $res = $db->all("select vid,subject,num from pl_vote where status=1 order by vid desc limit 10"); $list = array(); foreach ($res as $v) { $list[] = array("text" => Sanitize::html($v['subject']) . "(<font color=\"red\">{$v['num']}</font>)", "url" => "/vote/view/{$v['vid']}"); } if (empty($list)) { $ret[] = array("t" => "最新投票", "v" => array("s" => parent::$S_LINE, "v" => array(array("text" => "暂无任何投票", "url" => "")))); } else { $ret[] = array("t" => "最新投票", "v" => array("s" => parent::$S_LINE, "v" => $list)); } //hot $yes = time() - 86400; $res = $db->all("select vid,subject,num from pl_vote where status=1 and end>{$yes} order by num desc, vid desc limit 10"); $list = array(); foreach ($res as $v) { $list[] = array("text" => Sanitize::html($v['subject']) . "(<font color=\"red\">{$v['num']}</font>)", "url" => "/vote/view/{$v['vid']}"); } if (empty($list)) { $ret[] = array("t" => "最热门", "v" => array("s" => parent::$S_LINE, "v" => array(array("text" => "暂无任何投票", "url" => "")))); } else { $ret[] = array("t" => "最热门", "v" => array("s" => parent::$S_LINE, "v" => $list)); } /* $votes = nforum_cache_read("vote_week"); if($votes === false){ $list = array(array("text" => "应用数据错误", "url" => "")); }else{ $list = array(); foreach($votes as $v){ $list[] = array("text"=>Sanitize::html($v['subject'])."(<font color=\"red\">{$v['num']}</font>)", "url"=>"/vote/view/{$v['vid']}"); } if(empty($list)) $list = array(array("text" => "暂无任何投票", "url" => "")); } $ret[] = array("t"=>"周热门", "v"=>array("s"=>parent::$S_LINE, "v"=>$list)); */ $votes = nforum_cache_read("vote_month"); if ($votes === false) { $list = array(array("text" => "应用数据错误", "url" => "")); } else { $list = array(); foreach ($votes as $v) { $list[] = array("text" => Sanitize::html($v['subject']) . "(<font color=\"red\">{$v['num']}</font>)", "url" => "/vote/view/{$v['vid']}"); } if (empty($list)) { $list = array(array("text" => "暂无任何投票", "url" => "")); } } $ret[] = array("t" => "月热门", "v" => array("s" => parent::$S_LINE, "v" => $list)); /* $votes = nforum_cache_read("vote_year"); if($votes === false){ $list = array(array("text" => "应用数据错误", "url" => "")); }else{ $list = array(); foreach($votes as $v){ $list[] = array("text"=>Sanitize::html($v['subject'])."(<font color=\"red\">{$v['num']}</font>)", "url"=>"/vote/view/{$v['vid']}"); } if(empty($list)) $list = array(array("text" => "暂无任何投票", "url" => "")); } $ret[] = array("t"=>"年热门", "v"=>array("s"=>parent::$S_LINE, "v"=>$list)); */ return $ret; }
/** * @override method */ public function beforeRender() { if (!$this->html) { //there is three ajax_st status //1:success //0:fail $data = $this->get('no_html_data'); if (null === $data) { $data = array(); } //use no_ajax_info param to ignore ajax info, //sometimes data may be a array if (!isset($data['ajax_st']) && null === $this->get('no_ajax_info')) { $data['ajax_st'] = 1; $data['ajax_code'] = isset($data['ajax_code']) ? $data['ajax_code'] : ECode::$SYS_AJAXOK; $data['ajax_msg'] = ECode::msg($data['ajax_code']); //code may be a string,check msg == code to set default code if ($data['ajax_msg'] == strval($data['ajax_code'])) { $data['ajax_code'] = ECode::$SYS_AJAXOK; } $this->set('no_html_data', $data); } return; } $site = Configure::read("site"); try { $u = User::getInstance(); $uid = $u->userid; $admin = $u->isAdmin(); $reg = $u->isReg(); } catch (UserNullException $e) { $uid = 'guest'; $admin = false; $reg = false; } //handle js & css $this->_initAsset(); //add pack js&css $asset_pack = nforum_cache_read('asset_pack'); if (is_array($asset_pack) && ($this->front || $this->spider)) { $this->set('js', array_merge(array('js/' . $asset_pack['js']), $this->get('js'))); $this->set('css', array_merge(array('css/' . $asset_pack['css']), $this->get('css'))); } //handle title $title = $site['name']; if (!empty($this->title)) { $title = $this->title; } else { if (isset($this->notice[0]) && $this->path != $site['home']) { $title .= "-" . $this->notice[0]["text"]; } else { $title .= "-" . $site['desc']; } } //handle notice if ($this->path != $site['home']) { $this->notice = array_merge(array(array("url" => $site['home'], "text" => $site['name'])), $this->notice); } /* handle jsr start*/ if (!$this->spider) { if ($this->front) { $site = Configure::read("site"); $cookie = Configure::read("cookie"); $jsr = Configure::read("jsr"); $jsr['iframe'] = $jsr['iframe'] ? 'true' : 'false'; $jsr['domain'] = preg_replace('/^https?:\\/\\//', '', $site['domain']); $jsr['cookie_domain'] = $cookie['domain']; $jsr['base'] = $this->base; $jsr['prefix'] = $cookie['prefix']; $jsr['home'] = $site['home']; $jsr['static'] = $site['static']; $jsr['protocol'] = $site['ssl'] ? 'https://' : 'http://'; App::import("vendor", "inc/json"); $jsr = 'var sys_merge=' . BYRJSON::encode($jsr); $this->jsr = array_merge(array($jsr), $this->jsr); $syn = Configure::read('ubb.syntax'); if (Configure::read('ubb.parse') && !empty($syn)) { $this->set('js', array_merge($this->get('js'), array($syn . '/scripts/shCore.js', $syn . '/scripts/shAutoloader.js'))); } } else { $tmp = array(); foreach ($this->notice as $v) { $tmp[] = '<a href="' . (empty($v['url']) ? 'javascript:void(0)' : $this->base . $v['url']) . '">' . $v['text'] . '</a>'; } $tmp = join(' >> ', $tmp); $this->jsr[] = <<<EOT \$('#notice_nav').html('{$tmp}');\$.setTitle('{$title}'); EOT; $syn = Configure::read('ubb.syntax'); if (Configure::read('ubb.parse') && !empty($syn) && $this->get('hasSyn') !== false) { $this->set('syntax', $syn); } } } /* handle jsr end*/ //basic variables $arr = array('base' => $this->base, 'islogin' => $this->ByrSession->isLogin, 'id' => $uid, 'isAdmin' => $admin, 'isReg' => $reg, 'notice' => $this->notice, 'webTitle' => $title, 'webTotal' => Forum::getOnlineNum(), 'webUser' => Forum::getOnlineUserNum(), 'webGuest' => Forum::getOnlineGuestNum(), 'encoding' => $this->encoding, 'domain' => $site['domain'], 'static' => $site['static'], 'siteName' => $site['name'], 'keywords' => $site['keywords'], 'description' => $site['description'], 'home' => $site['home'], 'preindex' => $site['preIndex'], 'front' => $this->front, 'spider' => $this->spider, 'jsr' => $this->jsr); $this->set($arr); }
private function _cache_read($name, $modify) { $this->_time = (array) nforum_cache_read("rss_time"); if (isset($this->_time[$name]) && $this->_time[$name] >= $modify && false !== ($rss = nforum_cache_read('rss_' . $name))) { echo $rss; $this->_stop(); } }