function run() { echo "<pre>"; echo "ROOT=" . ROOT . "\n"; echo "NUMERIC_CONFIG=" . NUMERIC_CONFIG . "\n"; echo "app_config(app_config_path)=" . app_config('app_config_path') . "\n"; echo 'P_VERSION=' . app_config('version') . "\n"; outdebug(); }
/** * Initialize Library */ public static function init() { if (app_config('encryption_key') != '') { self::$keyStd = app_config('encryption_key'); } elseif (APP_ENV === 'development') { error_dump('Encryption key not yet set in \'' . APP_PATH . 'config/app.php\'!'); die; } }
/** * Initialize Session Library */ public static function init() { if (app_config('session', 'driver') === 'file') { if (self::$sessionDriver === null) { self::$sessionDriver = new SessionFile(); self::$sessionDriver->init(app_config('session')); } } elseif (APP_ENV === 'development') { error_dump('Session Driver \'' . app_config('session', 'driver') . '\' not avaiable.'); die; } }
/** * Initialize Database */ public static function init() { if (app_config('db', 'main', 'driver') === 'mysqli') { if (self::$dbDriver === null) { self::$dbDriver = new MySQLiDriver(app_config('db', 'main')); self::$dbDriver->connect(); } } elseif (app_config('db', 'main', 'driver') === 'sqlite') { if (self::$dbDriver === null) { self::$dbDriver = new SQLiteDriver(app_config('db', 'main')); self::$dbDriver->connect(); } } elseif (APP_ENV === 'development') { error_dump('Database Driver \'' . app_config('db', 'main', 'driver') . '\' not avaiable.'); die; } }
/** * Init Cache */ public static function init() { self::$cacheActive = app_config('cache', 'active'); self::$cacheEncrypt = app_config('cache', 'encrypt'); if (app_config('cache', 'driver') === 'file') { if (self::$cacheDriver === null) { self::$cacheDriver = new CacheFile(); self::$cacheDriver->cacheActive = self::$cacheActive; self::$cacheDriver->cacheEncrypt = self::$cacheEncrypt; } } elseif (app_config('cache', 'driver') === 'apc') { if (self::$cacheDriver === null) { self::$cacheDriver = new CacheAPC(); self::$cacheDriver->cacheActive = self::$cacheActive; self::$cacheDriver->cacheEncrypt = self::$cacheEncrypt; } } }
/** * Get application base url * * @return string */ function base_url() { $base_url = app_config('base_url'); if ($base_url !== '') { return trim($base_url, '/') . '/'; } $base_dir = explode('/', strrev(trim(__DIR__, '/'))); $arrDir = array(); if ($base_dir != null) { foreach ($base_dir as $key => $val) { $val = strrev($val); if ($val === 'public_html' || $val === 'htdocs' || $val === 'www') { break; } if ($key >= 2) { $arrDir[] = trim($val); } } } $dir = implode('/', array_reverse($arrDir)); return 'http' . (isset($_SERVER["HTTPS"]) ? $_SERVER["HTTPS"] == 'on' ? 's' : '' : '') . '://' . $_SERVER['HTTP_HOST'] . '/' . trim($dir) . '/'; }
<?php if (!is_login()) { info_page('请登录后查看'); } if (!level_check(app_config('add_level'))) { info_page('您没有权限进行此操作'); } include_once dirname(__FILE__) . '/function.php'; $data = array(); $data['ci_top_title'] = '添加' . app_config('model_name'); $width = intval(app_config('pic_width')) ? 'width:' . intval(app_config('pic_width')) . 'px;' : '90px'; $height = intval(app_config('pic_height')) ? 'height:' . intval(app_config('pic_height')) . 'px;' : '120px'; $data['pic_style'] = ' style="' . $width . $height . '" '; layout($data, 'default', 'app');
if ($titleid) { foreach ($titles as $k => $v) { if ($titleid == $k) { $where = "AND `tid` = " . $k . ""; } if ($titleid == '1') { $where = ''; } } } else { $where = ''; $titleid = '1'; } $data['titleid'] = $titleid; //时间分类 $data['days'] = app_config('days'); $date = date('Y-m-d H:i:s'); if ($day) { if ($day == '7') { $time = "AND `time` > '" . date('Y-m-d H:i:s', strtotime("{$date} -7 day")) . "'"; } elseif ($day == '365') { $time = "AND `time` > '" . date('Y-m-d H:i:s', strtotime("{$date} -365 day")) . "'"; } else { $time = "AND `time` > '" . date('Y-m-d H:i:s', strtotime("{$date} -1 day")) . "'"; } } else { $time = "AND `time` > '" . date('Y-m-d H:i:s', strtotime("{$date} -1 day")) . "'"; $day = '1'; } $data['day'] = $day; $data['inum'] = lazy_get_var("SELECT COUNT(*) FROM `app_feed_item` WHERE 1 AND `state` = '2'");
private function feedig_auto_update() { $ifeed = lazy_get_line("SELECT * FROM `u2_app` WHERE `aid` = 'ifeedig' LIMIT 1"); if ($ifeed) { $ftime = file_get_contents(dirname(__FILE__) . '/feed_auto.txt'); if ($ftime) { $time = date('Y-m-d H:i:s', time() - app_config('update_time', $ifeed['u2_folder'])); if ($time > $ftime) { $info = lazy_get_data("SELECT * FROM `app_feed`"); foreach ($info as $k => $v) { $feed = $v['feed']; $tid = $v['tid']; $id = $v['id']; $state = $v['state']; $fuid = $v['uid']; if (!empty($feed)) { $CI =& get_instance(); $CI->load->library('simplepie'); $CI->simplepie->set_feed_url($feed); $CI->simplepie->init(); $items = $CI->simplepie->get_items(); foreach ($items as $item) { $title = $item->get_title(); // $desp = $item->get_content(); // $link = $item->get_link(); $date = date('Y-m-d H:i:s', strtotime($item->get_date())); $unistring = md5($link) . $date; $itid = lazy_get_var("SELECT `tid` FROM `app_feed_item` WHERE `unistring` = '" . $unistring . "'"); if ($itid > 0) { //update $sql = "UPDATE `app_feed_item` SET `tid` = '" . intval($itid) . "',"; $sql .= " `fid` = '" . intval($id) . "', `title` = " . s($title) . ","; $sql .= "`desp` = " . s($desp) . ",`time` = " . s($date) . ", `link` = " . s($link) . ""; $sql .= "WHERE `unistring` = '" . $unistring . "' LIMIT 1 "; lazy_run_sql($sql); } else { //insert $sql = "INSERT INTO `app_feed_item` (`tid`, `fid`, `title`,"; $sql .= " `desp`, `time`, `link`, `state`, `unistring`, `admin_uid`)"; $sql .= "VALUES ('" . intval($tid) . "', '" . intval($id) . "', " . s($title) . ","; $sql .= " " . s($desp) . ", " . s($date) . " , " . s($link) . ","; $sql .= "'" . $state . "', " . s($unistring) . ", '" . intval($fuid) . "')"; lazy_run_sql($sql); } lazy_run_sql("UPDATE `app_feed` SET `time` = '" . date('Y-m-d H:i:s') . "' WHERE `id` = '" . $id . "'"); } } } file_put_contents(dirname(__FILE__) . '/feed_auto.txt', date('Y-m-d H:i:s')); } } else { file_put_contents(dirname(__FILE__) . '/feed_auto.txt', date('Y-m-d H:i:s')); } } }
<?php use lasa\web\Application; /* * home.php * @var $app lasa\web\Application */ $app = lasa\web\Application::getInstance(); $app->bind("get", function () { var_dump(Application::getInstance()->get("app.debug")); if (app_config("app.debug")) { echo "デバッグモードです"; } else { echo "デバッグモードではありません"; } echo "<hr />"; echo date("Y-m-d H:i:s"); });
include_once dirname(__FILE__) . '/function.php'; if (!is_login()) { info_page('请登录后查看'); } $id = intval(array_shift($args)); if ($id < 1) { info_page('错误的id'); } $text = urldecode(array_shift($args)); if (!$text) { info_page('错误的参数'); } $page = intval(array_shift($args)); $page = $page < 1 ? 1 : $page; $limit = 5; $start = ($page - 1) * $limit; $base = '/app/native/' . $GLOBALS['app'] . '/votepeople/' . $id . '/' . urlencode($text); $data = array(); $data['text'] = $text; $data['ci_top_title'] = '谁' . $text . '这' . app_config('model_name'); $uids = lazy_get_vars("select sql_calc_found_rows `uid` from `u2_vote` where `text` = '{$text}' and `tid` = '{$id}' and `mid` = '{$mid}' limit {$start} , {$limit}"); $all = get_count(); $page_all = ceil($all / $limit); $data['id'] = $id; if ($uids) { $data['names'] = get_name_by_uids($uids); } else { info_page('错误的参数'); } $data['pager'] = get_pager($page, $page_all, $base); layout($data, 'default', 'app');
<?php include_once dirname(__FILE__) . '/function.php'; if (!is_login()) { info_page('请登录后查看'); } $uid = format_uid(); $folder = z(array_shift($args)); $cid = intval(array_shift($args)); $mid = app_config('mid', $folder); $bind = app_config('bind', $folder); if (!isset($mid)) { info_page('没有此表!'); } if ($bind['price'] == '' || $bind['price'] <= '0') { info_page('价格错误!'); } foreach ($bind as $k => $v) { $selected[] = " `{$v}` as {$k} "; } $com = lazy_get_line("SELECT " . join(',', $selected) . " FROM `app_content_{$mid}` WHERE `id` = '" . intval($cid) . "'"); $cnum = get_count(); if ($cnum == '0') { info_page('没有此件物品!'); } $num = lazy_get_var("SELECT COUNT(*) FROM `app_shopcart` WHERE `cid` = '" . intval($cid) . "' AND `uid` = '" . intval($uid) . "'"); if ($num != '0') { lazy_run_sql("UPDATE `app_shopcart` SET `num` = `num`+1 WHERE `cid` = '" . intval($cid) . "' AND `uid` = '" . intval($uid) . "'"); } else { lazy_run_sql("INSERT INTO `app_shopcart` ( `uid`, `cid`, `name`, `desp`, `num`, `money`, `date`, `folder` ) VALUES ( '" . intval($uid) . "' , '" . intval($cid) . "' , " . s($com['title']) . " , " . s($com['desp']) . " , '1' , " . s($com['price']) . " , '" . date('Y-m-d H:i:s') . "' , " . s($folder) . " )"); }
<?php include_once dirname(__FILE__) . '/function.php'; $data['ci_top_title'] = '添加分类'; if (!is_login()) { info_page('请登录后查看'); } if (!is_admin()) { info_page('你没有权限进行操作!'); } $tname = trim(z(v('tname'))); if (empty($tname)) { info_page('分类名称不能为空!'); } $config_data['titles'] = app_config('titles'); $config_data['titles'][] = $tname; save_app_config($config_data); info_page('添加成功!', '/app/native/' . $GLOBALS['app'] . '/feed', '点击这里返回!');
include_once dirname(__FILE__) . '/function.php'; $data['ci_top_title'] = app_config('model_name'); if (!is_login()) { info_page('请登录后查看'); } $data['id'] = '1'; $data['bind'] = $bind; //print_r($field_lables); $view_type = intval(array_shift($args)); foreach ($bind as $k => $v) { $selected[] = " `{$v}` as {$k} "; } $pic_width = app_config('pic_width'); $pic_height = app_config('pic_height'); $pic_style = NULL; if (app_config('focus_pic')) { $width = $pic_width ? 'width:' . $pic_width . 'px;' : NULL; $height = $pic_height ? 'height:' . $pic_height . 'px;' : NULL; $pic_style = ' style="' . $width . $height . '" '; } $data['pic_style'] = $pic_style; $data['index_title'] = array('1' => '最新发布的', '2' => '最多点击的', '3' => '最多评论的'); $index_order = $view_type > 0 && $view_type < 4 ? $view_type : 1; switch ($index_order) { case '1': $order = "ORDER BY `id` DESC"; break; case '2': $order = "ORDER BY `hit` DESC"; break; case '3':
function action_month_stat2() { //$start_day = $this->get_param('start_day'); $js_code = <<<EOF var month_names = ['201209','201210','201211','201212','201301','201302','201303','201304','201305','201306','201307','201308','201309','201310']; var month_times = []; for(var i = 0;i<month_names.length;i++){ var y = month_names[i].substring(0,4); var m = month_names[i].substring(4,6); var t = (new Date(y+'/'+ m +'/'+'01 00:00 GMT+08:00')).getTime() /1000; month_times[i] = t; } var mapf = function() { for(var i = 0; i< month_times.length;i++){ if(this._ct>=month_times[i] && this._ct<month_times[i+1]){ // 第 i 月注册,计算一次活跃和新增 emit(month_names[i],{reg:1,active:1,ret:0}); } if(this._at>=month_times[i] && month_times[i]>this._ct){ // 注册之后的下个月开始,到最后一次活跃以内 if(i>0 && this._ct >=month_times[i-1] && this._ct < month_times[i]){ // 是上个月注册的 emit(month_names[i],{reg:0,active:1,ret:1}); }else{ // 不是上个月注册的 emit(month_names[i],{reg:0,active:1,ret:0}); } } } }; var reducef = function(day,values){ var result = {reg:0,active:0,ret:0}; values.forEach(function(value) { result.reg += value.reg; result.active += value.active; result.ret += value.ret; }); return result; } db.stat_user.drop(); db.runCommand({ mapreduce:'userlogin', map:mapf, reduce:reducef, out:'stat_user', scope:{month_times:month_times,month_names:month_names} }); var cur = db.stat_user.find(); while(cur.hasNext()){ var o = cur.next(); print(o._id,'\t',o.value.reg,'\t',o.value.active,'\t',o.value.ret); } EOF; $js_file = LOG_ROOT . '/month_stat.js'; file_put_contents($js_file, $js_code); $game = app_config("game"); $platform = app_config("platform"); $mongo_bin = "/usr/bin/mongo"; if ($game == 'ares' && $platform == 'qqandroid') { $mongo_bin = "/usr/local/app/sys/mongodb/bin/mongo"; } $config = DbConfig::$mongodbs['userlogin']; $cstr = $config['cstr']; $db = $config['db']; $cstr = str_replace('mongodb://', '', $cstr); if ($i = strpos($cstr, ',')) { $cstr = substr($cstr, 0, $i); } $cstr = $cstr . '/' . $db; $success = false; // js_code 执行时间会比较长,所以 MongoDB->execute($js_code) 的方式执行 js 代码 if (is_executable($mongo_bin)) { $command = "{$mongo_bin} {$cstr} <{$js_file} 2>&1"; echo "{$command} \n"; system($command); $success = true; } else { echo "no mongo\n"; } if ($success) { } }
function get_state_button($id) { $mid = intval(app_config('mid')); $state = app_config('model_state'); $buttons = array(); if ($state) { $text = lazy_get_var("select `text` from `u2_vote` where `uid` = '" . format_uid() . "' and `tid` = '{$id}' and `mid` = '{$mid}' limit 1 "); $app = explode('|', $state); foreach ($app as $v) { $v = trim($v); if ($v == $text) { $buttons[] = $v; } else { $buttons[] = '<input type="button" class="button" onclick="location=\'/app/native/' . $GLOBALS['app'] . '/module_vote/' . $id . '/\'+ encodeURIComponent(\'' . $v . '\')" value="' . $v . '" />'; } } } if ($buttons) { return join(' ', $buttons); } else { return NULL; } }
<?php $agio = app_config('agio'); $agio = empty($agio) || $agio > '100' || $agio < 0 ? '100' : $agio;
<?php include_once dirname(__FILE__) . '/function.php'; $data['ci_top_title'] = '修改' . app_config('model_name') . '评论'; if (!is_login()) { info_page('请登录后查看!'); } $cid = intval(array_shift($args)); $uid = format_uid(); $data['com'] = $com = lazy_get_line("SELECT sql_calc_found_rows * FROM `u2_comment` WHERE `id` = '" . intval($cid) . "' "); $num = get_count(); if ($com['uid'] != $uid) { info_page('你没有权限进行此操作!'); } if ($num == '0') { info_page('参数错误!'); } layout($data, 'default', 'app');
function rate($folder = NULL, $cid = NULL, $star = NULL) { if (!is_login()) { die(_text('system_plz_login')); } $cid = intval($cid); $star = intval($star); $mid = intval(app_config('mid', $folder)); if ($mid < 0 || $cid < 0 || $star < 0 || $star > 5) { die(_text('system_error_id')); } $uid = format_uid(); $sql = "replace into `u2_rate` (`uid` , `mid` , `cid` , `rate` , `time` )values('{$uid}','{$mid}','{$cid}','{$star}' , '" . date("Y-m-d H:i:s") . "')"; lazy_run_sql($sql); }
function snap($folder = NULL, $url = NULL, $size = NULL) { $url = $url ? base64_decode($url) : '/static/images/no_image.gif'; if (!$folder) { die('error'); } $width = app_config('pic_width', $folder) > 0 ? app_config('pic_width', $folder) : 90; $height = app_config('pic_height', $folder) > 0 ? app_config('pic_height', $folder) : 90; $size = intval($size); if ($size > 0) { $width = $size; $height = $size; } $md5 = md5($url); $web_path = "static/data/hash/snaps/" . $folder . '/' . myhashstr($md5); $path = ROOT . $web_path; $web_file = $web_path . md5($url) . $width . '_' . $height . '.gif'; $file = ROOT . $web_file; $source_file = $path . md5($url) . '.source.gif'; if (!file_exists($file)) { @MakeDir($path); if (!file_exists($source_file)) { if (!($s = snoopy_copy($url, $source_file))) { $s = copy(ROOT . 'static/images/no_image.gif', $source_file); } } if ($width == $height) { $this->load->library('icon'); $this->icon->path = $source_file; $this->icon->size = $width; $this->icon->dest = $file; $this->icon->createIcon(); } else { $this->load->library('thumbnail'); $this->thumbnail->setMaxSize($width, $height); $this->thumbnail->setImgSource($source_file); $this->thumbnail->Create($file); } } readfile($web_file); }
<?php //include_once( dirname( __FILE__ ) . '/function.php' ); $mid = app_config('mid'); if (!is_login()) { info_page('请登录后查看'); } $id = intval(array_shift($args)); $num = intval(array_shift($args)); $uid = format_uid(); $shop_line = lazy_get_line("SELECT * FROM `app_shopcart` WHERE `id` = '" . intval($id) . "' LIMIT 1"); if (!$shop_line) { die('error_id'); } if ($shop_line['uid'] != $uid) { die('error_user'); } if ($num == '0' || empty($num)) { die('0'); } else { lazy_run_sql("UPDATE `app_shopcart` SET `num` = '" . intval($num) . "' WHERE `id` = '" . intval($id) . "' AND `uid` = '" . intval($uid) . "'"); echo $num; die; }
if (!$feed || $feed == 'http://') { info_page('你提交的博客地址错误'); } if (strpos($feed, 'http://') === false) { $feed = 'http://' . $feed; } } $CI =& get_instance(); $CI->load->library('simplepie'); MakeDir(ROOT . 'static/data/cache'); $CI->simplepie->set_cache_location(ROOT . 'static/data/cache'); $CI->simplepie->set_feed_url($feed); $CI->simplepie->init(); $data['ftitle'] = $CI->simplepie->get_title(); //标题 $flink = $CI->simplepie->get_link(); //连接地址 if (!$flink) { $flink = $feed; } $data['flink'] = $flink; //delete feed lazy_run_sql("DELETE FROM `app_feed_recommend` WHERE `feed` = '" . $feed . "'"); //type list foreach (app_config('titles') as $k => $v) { $titles[$k] = $v; } unset($titles[1]); $data['fselect'] = $titles; $data['state'] = app_config('state'); layout($data, 'default', 'app');
<?php include_once dirname(__FILE__) . '/function.php'; if (!is_login()) { info_page('请登录后查看'); } $cid = intval(array_shift($args)); $uid = format_uid(); $num = lazy_get_var("SELECT `uid` FROM `app_content_{$mid}` WHERE `id` = '" . intval($cid) . "' limit 1"); if (!$num) { info_page('错误的参数'); } if ($num != $uid) { info_page('您没有权限进行此操作'); } $com = lazy_get_var("SELECT COUNT(*) FROM `u2_comment` WHERE `tid` = '" . intval($cid) . "'"); if ($com != '0') { lazy_run_sql("DELETE FROM `u2_comment` WHERE `tid` = '" . $cid . "'"); lazy_run_sql("DELETE FROM `u2_comment_vote` WHERE `tid` = '" . $cid . "'"); lazy_run_sql("DELETE FROM `u2_comment_reply` WHERE `tid` = '" . $cid . "'"); } lazy_run_sql("DELETE FROM `app_content_{$mid}` WHERE `id` = '" . intval($cid) . "'"); lazy_run_sql("DELETE FROM `u2_comment_reply` WHERE `tid` = '" . $cid . "'"); lazy_run_sql("DELETE FROM `u2_manager` WHERE `tid` = '" . intval($cid) . "' AND `u2_table` = 'app_content_{$mid}' "); lazy_run_sql("DELETE FROM `u2_rate` WHERE `cid` = '" . intval($cid) . "' AND `mid` = '{$mid}' "); info_page('成功删除' . app_config('model_name'), '/app/native/' . $GLOBALS['app'] . '/', '返回'); ?>
<?php include_once dirname(__FILE__) . '/function.php'; $data['ci_top_title'] = '悦读管理'; if (!is_login()) { info_page('请登录后查看'); } if (!is_admin()) { info_page('你没有权限进行操作!'); } //$uid = format_uid(); //分类列表 foreach (app_config('titles') as $k => $v) { $t**s[$k] = $k; $titles[$k] = $v; } $data['t**s'] = $t**s; unset($titles[1]); $data['fselect'] = $titles; $view = array_shift($args); if ($view == 'add') { $data['view'] = 'add'; } //分类ID $tnum = intval($view); if ($tnum != '0') { if (!in_array($tnum, $t**s)) { info_page('错误的分类'); } $where = "AND `tid` = '" . intval($tnum) . "'"; $data['tnum'] = $tnum;
public function database4() { $db2 = DB::getInstance(app_config('db', 'optional')); $db2->createTable('member', array(array('member_id', 'string(20) PRIMARY KEY'), array('name', 'string(50)'))); $db2->table('member')->insert(array('member_id' => 'M00001', 'name' => 'Joko Purnomo A')); $members = $db2->table('member')->get(); echo '<pre>'; print_r($members); echo '</pre>'; }