public function exec($key) { //匿名函数 if ($this->route[$key]['callback'] instanceof Closure) { //反射分析闭包 $reflectionFunction = new \ReflectionFunction($this->route[$key]['callback']); $gets = $this->route[$key]['get']; $args = []; foreach ($reflectionFunction->getParameters() as $k => $p) { if (isset($gets[$p->name])) { //如果GET变量中存在则将GET变量值赋予,也就是说GET优先级高 $args[$p->name] = $gets[$p->name]; } else { //如果类型为类时分析类 if ($dependency = $p->getClass()) { $args[$p->name] = App::build($dependency->name); } else { //普通参数时获取默认值 $args[$p->name] = App::resolveNonClass($p); } } } echo $reflectionFunction->invokeArgs($args); } else { //设置控制器与方法 $_GET[c('http.url_var')] = $this->route[$key]['callback']; Controller::run($this->route[$key]['get']); } }
public function test_c() { $GLOBALS['config']['unittest'] = 'ing'; $this->assertEqual(c('unittest'), 'ing'); unset($GLOBALS['config']['unittest']); $this->assertFalse(c('unittest')); }
public function yudingcarlist($table, $rows) { $dt = $this->date; $dtobj = c('date'); $db = m('careserve'); for ($i = 0; $i < 5; $i++) { if ($i > 0) { $dt = $dtobj->adddate($dt, 'd', 1); } foreach ($rows as $k => $rs) { $carid = $rs['id']; $arr = $db->getall("`carid`='{$carid}' and `status` in(0,1) and `startdt`<='{$dt} 23:59:59' and `enddt`>='{$dt} 00:00:00' order by `startdt` asc", '`usename`,`status`,`startdt`,`enddt`'); $str = ''; foreach ($arr as $k1 => $rs1) { $stz = '<font color=blue>待审核</font>'; if ($rs1['status'] == 1) { $stz = '<font color=green>已审核</font>'; } $str .= '' . $rs1['usename'] . '使用(' . $stz . ')<br>' . substr($rs1['startdt'], 5, 11) . '→' . substr($rs1['enddt'], 5, 11) . '<br>'; } $rows[$k]['dt' . $i . ''] = $str; } } return array('rows' => $rows); }
public static function run($routeArgs = []) { self::$routeArgs = $routeArgs; //URL结构处理 $param = array_filter(explode('/', Request::get(c('http.url_var')))); switch (count($param)) { case 2: array_unshift($param, c('http.default_module')); break; case 1: array_unshift($param, c('http.default_controller')); array_unshift($param, c('http.default_module')); break; case 0: array_unshift($param, c('http.default_action')); array_unshift($param, c('http.default_controller')); array_unshift($param, c('http.default_module')); break; } Request::set('get.' . c('http.url_var'), implode('/', $param)); $param[1] = preg_replace_callback('/_([a-z])/', function ($matches) { return ucfirst($matches[1]); }, $param[1]); define('MODULE', $param[0]); define('CONTROLLER', ucfirst($param[1])); define('ACTION', $param[2]); define('MODULE_PATH', ROOT_PATH . '/' . c('app.path') . '/' . MODULE); define('VIEW_PATH', MODULE_PATH . '/' . 'view'); define('__VIEW__', __ROOT__ . '/' . c('app.path') . '/' . MODULE . '/view'); self::action(); }
function buy($number, $uid = NULL) { $uid = format_uid($uid); $money = intval(c('invite_price')) * $number; $key = c('invite_use_gold') ? 'gold' : 'g'; $this->db->select($key)->from('app_ihome_user')->where('uid', $uid)->limit(1); $now = lazy_get_var(); if ($now < $money) { return false; } $sql = "UPDATE app_ihome_user SET {$key} = {$key} - {$money} WHERE uid = '{$uid}'"; lazy_run_sql($sql); $data = array(); $data['u2_uid'] = $uid; $data['u2_is_use'] = '0'; $data['u2_is_copied'] = '0'; $data['u2_date'] = date("Y-m-d"); while ($number > 0) { do { $icode = newpassword(); $check = $this->count_invite_code($icode); } while ($check); $data['u2_invite_code'] = $icode; $this->db->insert('u2_invite', $data); $number--; } return true; }
public function bootstrap() { $this->constant(); //加载服务配置项 $servers = (require __DIR__ . '/service.php'); $config = (require ROOT_PATH . '/system/config/service.php'); $servers['providers'] = array_merge($config['providers'], $servers['providers']); $servers['facades'] = array_merge($config['facades'], $servers['facades']); $this->servers = $servers; //自动加载系统服务 Loader::register([$this, 'autoload']); //绑定核心服务提供者 $this->bindServiceProvider(); //添加初始实例 $this->instance('App', $this); //设置外观类APP属性 ServiceFacade::setFacadeApplication($this); //启动服务 $this->boot(); //定义错误/异常处理 Error::bootstrap(); //命令行模式 IS_CLI and die(Cli::bootstrap()); //导入类库别名 Loader::addMap(c('app.alias')); //自动加载文件 Loader::autoloadFile(); //开启会话 Session::start(); //执行全局中间件 Middleware::globals(); //解析路由 Route::dispatch(); }
public function generate($number, $value, $delimiter = ";") { if (!intval($number) && !intval($value)) { return false; } for ($i = 0; $i < $number; $i++) { //$code=rand(10000, 99999).rand(10000, 99999); $code = sprintf("%010d", mt_rand()); $codeLength = $this->table->header[1][2]; while (strlen($code) < $codeLength) { $code .= rand(0, 9); } $newId = $this->table->add(array('code' => $code, 'value' => $value, 'activated' => 0)); if (!$newId) { $number++; if ($number - 5 > $n) { echo "Too much collisions."; $this->response->success = false; return; } } else { $this->response->data[] = sprintf("%010d", $newId) . $delimiter . $code; } } c("Successfully generated {$number} codes with value {$value}."); $this->response->success = true; }
function get_data($sql, $db = NULL) { if ($db == NULL) { if (c('on_sae')) { $db = db2(); } else { $db = db(); } } $GLOBALS['LZ_LAST_SQL'] = $sql; $data = array(); $i = 0; $result = mysql_query($sql, $db); if (mysql_errno() != 0) { echo mysql_error() . ' ' . $sql; } while ($Array = mysql_fetch_array($result, MYSQL_ASSOC)) { $data[$i++] = $Array; } if (mysql_errno() != 0) { echo mysql_error() . ' ' . $sql; } mysql_free_result($result); if (count($data) > 0) { return $data; } else { return false; } }
public function xiangAjax() { $mid = $this->get('mid'); $rs = m('work')->getone("`id`='{$mid}'"); $dtc = c('date'); $zt = $rs['state']; $zts = $rs['state']; if ($zt == '执行中') { $zt = '<font color=#ff6600>' . $zt . '</font>'; } if ($zt == '已完成') { $zt = '<font color=green>' . $zt . '</font>'; } if (!$this->isempt($rs['enddt']) && ($zts == '待执行' || $zts == '执行中')) { $sjla = $dtc->diffstr($this->now, $rs['enddt'], 'd天H时i分', 1); $sjsj = $dtc->datediff('i', $rs['enddt'], $this->now); if ($sjsj > 0) { $zt .= '<font color=red>超' . $sjla . '</font>'; } } $rs['zt'] = $zt; $rs['logarr'] = m('workbg')->getall("mid='{$mid}' order by id desc", '`state`,`explain`,`optdt`,`optname`'); $isbg = 0; if ($this->contain(',' . $rs['distid'] . ',', ',' . $this->adminid . ',')) { $isbg = 1; } $rs['isbg'] = $isbg; $this->showreturn($rs); }
private function page_load() { $this->classDbHelper = new DbHelper("pg_gameclass"); if (isset($_POST['addgame'])) { if (isset($_POST['gameName']) && isset($_POST['urlColor']) && isset($_POST['gameRank']) && isset($_POST['gameUrl']) && isset($_POST['gameClass'])) { $this->gameDbHelper = new DbHelper("pg_gamelink"); $gameName = mysql_escape_string($_POST['gameName']); $urlColor = mysql_escape_string($_POST['urlColor']); $gameRank = mysql_escape_string($_POST['gameRank']); $gameUrl = mysql_escape_string($_POST['gameUrl']); $gameClass = mysql_escape_string($_POST['gameClass']); $firstword = mysql_escape_string(substr(c($gameName), 0, 1)); if ($this->gameDbHelper->insert('gamename,color,rank,gameUrl,classid,firstword', "'{$gameName}','{$urlColor}','{$gameRank}','{$gameUrl}','{$gameClass}','{$firstword}'")) { $this->js = "<script>GotoOtherPage('AjaxGameList.php?id=" . $_POST['gameClass'] . "','操作成功!')</script>"; } else { echo "<script>alert('添加失败,请重试');</script>"; } } } if (isset($_POST['addclass'])) { if (isset($_POST['className']) && isset($_POST['classRank'])) { $className = mysql_escape_string($_POST['className']); $classRank = mysql_escape_string($_POST['classRank']); if ($this->classDbHelper->insert('className,rank', "'{$className}','{$classRank}'")) { $this->js = "<script>GotoOtherPage('AjaxGameManage.php','操作成功!')</script>"; } else { echo "<script>alert('添加失败,请重试');</script>"; } } } $this->classList = $this->classDbHelper->get_many("id>0 order by rank desc"); }
/** * Override the default dashboard page with the new stats one. */ public function gdn_dispatcher_beforeDispatch_handler($Sender) { $Enabled = c('Garden.Analytics.Enabled', true); if ($Enabled && !Gdn::pluginManager()->hasNewMethod('SettingsController', 'Index')) { Gdn::pluginManager()->registerNewMethod('VanillaStatsPlugin', 'StatsDashboard', 'SettingsController', 'Index'); } }
public function jisanstatela($table, $rows) { $dta = c('date', true); foreach ($rows as $k => $rs) { $dt = explode(' ', $rs['optdt']); $jg = $dta->datediff('d', $dt[0], $this->date); $str = ''; if ($jg == 0) { $str = '今天'; } else { if ($jg == 1) { $str = '昨天'; } else { if ($jg == 2) { $str = '前天'; } else { if ($jg < 15) { $str = '' . $jg . '天前'; } else { $str = '更早'; } } } } $rows[$k]['temp_atype'] = $str; $rows[$k]['xuhao'] = $k + 1; $rows[$k]['optdt'] = $dta->stringdt($rs['optdt']); } if (count($rows) == 0) { $rows[] = array('mess' => '<div style=font-size:16px;height:40px;line-height:35px>无提醒</div>', 'xuhao' => ''); } return array('wdcount' => m($table)->rows("uid='{$this->adminid}' and `status`=0"), 'rows' => $rows); }
function loadComponents() { $components = func_get_args(); foreach ($components as $compo) { require_once c("components") . $compo; } }
public function importAjax() { $import = c('PHPExcelReader', true); $cdt = c('date', true); $rows = $import->reader(); $db = m('admin'); $dbs = m('dept'); $oi = 0; $sort = (int) $db->getmou('max(`sort`)', '`id`>0') + 1; foreach ($rows as $k => $rs) { $arr = array('user' => $rs['A'], 'name' => $rs['B'], 'gender' => $rs['C'], 'ranking' => $rs['D'], 'deptname' => $rs['E'], 'mobile' => $rs['F'], 'email' => $rs['G'], 'workdate' => substr($rs['H'], 1, -1), 'type' => '1', 'state' => '2', 'status' => '1', 'pass' => md5('123456'), 'optdt' => $this->now, 'adddt' => $this->now, 'optid' => $this->adminid, 'optname' => $this->adminname, 'sort' => $sort + $oi); if (!$this->isempt($arr['user']) && !$this->isempt($arr['name'])) { if (!$cdt->isdate($arr['workdate'])) { $arr['workdate'] = ''; } $msg = $this->isexiset($arr['user'], $arr['name']); $deptid = (int) $dbs->getmou('id', "`name`='" . $arr['deptname'] . "'"); if ($deptid == 0) { $arr['deptname'] = ''; } $arr['deptid'] = $deptid; if ($msg == '') { $oi++; $db->insert($arr); } } } $this->backmsg('', '成功导入' . $oi . '条,记得更新数据'); }
protected function _initialize() { $this->user_session = session('user'); $this->assign('user_session', $this->user_session); $this->config = d('Config')->get_config(); $this->config['now_city'] = 2035; $this->assign('config', $this->config); c('config', $this->config); $levelDb = m('User_level'); $tmparr = $levelDb->where('22=22')->order('id ASC')->select(); $levelarr = array(); if ($tmparr) { foreach ($tmparr as $vv) { $levelarr[$vv['level']] = $vv; } } $this->user_level = $levelarr; unset($tmparr); unset($levelarr); $this->assign('levelarr', $this->user_level); $this->common_url['group_category_all'] = c('config.site_url') . '/category/all/all'; $this->static_path = $this->config['site_url'] . '/tpl/Static/' . c('DEFAULT_THEME') . '/'; $this->static_public = $this->config['site_url'] . '/static/'; $this->assign('static_path', $this->static_path); $this->assign('static_public', $this->static_public); $this->assign($this->common_url); }
function curl_post_ssl($url, $vars, $second = 30, $aHeader = array()) { $ch = curl_init(); //超时时间 curl_setopt($ch, CURLOPT_TIMEOUT, $second); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //这里设置代理,如果有的话 curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); //cert 与 key 分别属于两个.pem文件 //请确保您的libcurl版本是否支持双向认证,版本高于7.20.1 curl_setopt($ch, CURLOPT_SSLCERT, c('weixin.apiclient_cert')); curl_setopt($ch, CURLOPT_SSLKEY, c('weixin.apiclient_key')); curl_setopt($ch, CURLOPT_CAINFO, c('weixin.rootca')); if (count($aHeader) >= 1) { curl_setopt($ch, CURLOPT_HTTPHEADER, $aHeader); } curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $vars); $data = curl_exec($ch); if ($data) { curl_close($ch); return $data; } else { curl_close($ch); return false; } }
public function pluginController_quoteMention_create($sender, $discussionID, $commentID, $username) { $sender->deliveryMethod(DELIVERY_METHOD_JSON); $user = Gdn::userModel()->getByUsername($username); $discussionModel = new DiscussionModel(); $discussion = $discussionModel->getID($discussionID); if (!$user || !$discussion) { throw notFoundException(); } // Make sure this endpoint can't be used to snoop around. $sender->permission('Vanilla.Discussions.View', true, 'Category', $discussion->PermissionCategoryID); // Find the previous comment of the mentioned user in this discussion. $item = Gdn::sql()->getWhere('Comment', ['DiscussionID' => $discussion->DiscussionID, 'InsertUserID' => $user->UserID, 'CommentID <' => $commentID], 'CommentID', 'desc', 1)->firstRow(); // The items ID in the DOM used for highlighting. if ($item) { $target = '#Comment_' . $item->CommentID; // The mentioned user might be the discussion creator. } elseif ($discussion->InsertUserID == $user->UserID) { $item = $discussion; $target = '#Discussion_' . $item->DiscussionID; } if (!$item) { // A success response code always means that a comment was found. $sender->statusCode(404); } $sender->renderData($item ? ['html' => nl2br(sliceString(Gdn_Format::plainText($item->Body, $item->Format), c('QuoteMention.MaxLength', 400))), 'target' => $target] : []); }
public function b() { $a = function () { c(function () use($d, $e) { }); }; }
public function getPersona(Procedure &$pro, int $personaid) { $p = Persona::persistence(); $persona = $pro->declare_var('per', new RowType($p)); $pro->select($p->id, $p->nombre, $p->apellido)->from($p)->where(c($p->id = $personaid))->into($persona); return $persona; }
/** * Calculate the user's default photo url. * * @param array|object $user The user to examine. * @param array $options An array of options. * - Size: The size of the photo. * @return string Returns the vanillicon url for the user. */ function userPhotoDefaultUrl($user, $options = array()) { static $iconSize = null, $type = null; if ($iconSize === null) { $thumbSize = c('Garden.Thumbnail.Size'); $iconSize = $thumbSize <= 50 ? 50 : 100; } if ($type === null) { $type = c('Plugins.Vanillicon.Type'); } $size = val('Size', $options, $iconSize); $email = val('Email', $user); if (!$email) { $email = val('UserID', $user, 100); } $hash = md5($email); $px = substr($hash, 0, 1); switch ($type) { case 'v2': $photoUrl = "//w{$px}.vanillicon.com/v2/{$hash}.svg"; break; default: $photoUrl = "//w{$px}.vanillicon.com/{$hash}_{$size}.png"; break; } return $photoUrl; }
/** * Filter provided HTML through htmlLawed and return the result. * * @param string $html String of HTML to filter. * @return string Returns the filtered HTML. */ public function format($html) { $attributes = c('Garden.Html.BlockedAttributes', 'on*'); $config = ['anti_link_spam' => ['`.`', ''], 'balance' => 1, 'cdata' => 3, 'comment' => 1, 'css_expression' => 1, 'deny_attribute' => $attributes, 'direct_list_nest' => 1, 'elements' => '*-applet-form-input-textarea-iframe-script-style-embed-object-select-option-button-fieldset-optgroup-legend', 'keep_bad' => 0, 'schemes' => 'classid:clsid; href: aim, feed, file, ftp, gopher, http, https, irc, mailto, news, nntp, sftp, ssh, telnet; style: nil; *:file, http, https', 'unique_ids' => 1, 'valid_xhtml' => 0]; // Turn embedded videos into simple links (legacy workaround) $html = Gdn_Format::unembedContent($html); // We check the flag within Gdn_Format to see // if htmLawed should place rel="nofollow" links // within output or not. // A plugin can set this flag (for example). // The default is to show rel="nofollow" on all links. if (Gdn_Format::$DisplayNoFollow) { // display rel="nofollow" on all links. $config['anti_link_spam'] = ['`.`', '']; } else { // never display rel="nofollow" $config['anti_link_spam'] = ['', '']; } // Deny all class and style attributes. // A lot of damage can be done by hackers with these attributes. $config['deny_attribute'] .= ',style,class'; // Block some IDs so you can't break Javascript $GLOBALS['hl_Ids'] = ['Bookmarks' => 1, 'CommentForm' => 1, 'Content' => 1, 'Definitions' => 1, 'DiscussionForm' => 1, 'Foot' => 1, 'Form_Comment' => 1, 'Form_User_Password' => 1, 'Form_User_SignIn' => 1, 'Head' => 1, 'HighlightColor' => 1, 'InformMessageStack' => 1, 'Menu' => 1, 'PagerMore' => 1, 'Panel' => 1, 'Status' => 1]; $spec = 'object=-classid-type, -codebase; embed=type(oneof=application/x-shockwave-flash); '; // Define elements allowed to have a `class`. $spec .= implode(',', $this->classedElements); // Whitelist classes we allow. $spec .= '=class(oneof=' . implode('|', $this->allowedClasses) . '); '; return Htmlawed::filter($html, $config, $spec); }
public function pagesetAction() { $setid = $this->get('setid'); $rs = m('flow_set')->getone("`id`='{$setid}'"); if (!$rs) { exit('sorry!'); } $this->smartydata['rs'] = $rs; $this->title = $rs['name'] . '_页面设置'; $table = $rs['table']; $farr = c('edit')->getfield($table, 1); $fleft = array(); $fleft[] = array('base_name', '申请人'); $fleft[] = array('base_deptname', '申请部门'); $fleft[] = array('base_sericnum', '单号'); foreach ($farr as $k => $rs1) { $fleft[] = array($k, $rs1['name']); } $fleft[] = array('file_content', '相关文件'); $this->smartydata['fleft'] = $fleft; $path = '' . ROOT_PATH . '/webrock/flow/applyview/page/page_' . $rs['num'] . '.html'; $content = ''; if (file_exists($path)) { $content = file_get_contents($path); } $this->smartydata['content'] = $content; }
function callback() { $o = new SaeTOAuthV2(c('weibo_akey'), c('weibo_skey')); if (isset($_REQUEST['code'])) { $keys = array(); $keys['code'] = $_REQUEST['code']; $keys['redirect_uri'] = 'http://' . c('site_domain') . '/?c=weibo&a=callback'; try { $token = $o->getAccessToken('code', $keys); } catch (OAuthException $e) { } $_SESSION['weibo_token'] = $token; // get user info $c = new SaeTClientV2(c('weibo_akey'), c('weibo_skey'), atoken()); $info = $c->show_user_by_id(wbuid()); if (strlen($info['name']) < 1) { return info_page('登入失败,请去吃点零食后重试'); } $_SESSION['weibo_uid'] = $info['name']; $_SESSION['uname'] = $info['name']; $_SESSION['avatar'] = $info['profile_image_url']; //print_r( $_SESSION ); header("Location: /?a=index"); } }
public function getmontlistAjax() { $enddt = $this->get('enddt'); $dt = $this->get('startdt'); $uid = $this->get('uid'); $dtc = c('date', true); $jg = $dtc->datediff('d', $dt, $enddt); $dtaa1 = strtotime($this->date); $dbw = m('schedule'); $arr = array(); for ($i = 0; $i <= $jg; $i++) { if ($i > 0) { $dt = $dtc->adddate($dt, 'd', 1); } $dtaa2 = strtotime($dt); $s = ''; $col = ''; $rows = $dbw->getdtarr($dt, $uid); foreach ($rows as $a => $ars) { $s .= '' . ($a + 1) . '.' . $ars['title'] . '<br>'; } if ($dtaa2 == $dtaa1) { } else { if ($dtaa2 < $dtaa1) { $col = '#888888'; } else { $col = '#888888'; } } $arr[$i + 1] = array('str' => '<font color="' . $col . '">' . $s . '</font>'); } echo json_encode($arr); }
public function __construct($config = array()) { $this->set_error(0); if (!($this->config = $config)) { $this->config['on'] = c("ftp_open"); $this->config['host'] = c("ftp_server"); $this->config['ssl'] = c("ftp_ssl_state"); $this->config['port'] = c("ftp_port"); $this->config['username'] = c("ftp_username"); $this->config['password'] = c("ftp_password"); $this->config['pasv'] = c("ftp_pasv"); $this->config['attachdir'] = c("ftp_attach_dir"); $this->config['attachurl'] = c("ftp_access_url"); $this->config['timeout'] = c("ftp_timeout"); } $this->enabled = FALSE; if (empty($this->config['on']) || empty($this->config['host'])) { $this->set_error(self::FTP_ERR_CONFIG_OFF); } else { $this->func = $this->config['ssl'] && function_exists("ftp_ssl_connect") ? "ftp_ssl_connect" : "ftp_connect"; if ($this->func == "ftp_connect" && !function_exists("ftp_connect")) { $this->set_error(self::FTP_ERR_SERVER_DISABLED); } else { $this->config['host'] = NcFtp::clear($this->config['host']); $this->config['port'] = intval($this->config['port']); $this->config['ssl'] = intval($this->config['ssl']); $this->config['host'] = NcFtp::clear($this->config['host']); $this->config['password'] = $this->config['password']; $this->config['timeout'] = intval($this->config['timeout']); $this->enabled = TRUE; } } }
protected function contentother() { $headstr = 'address,发送地点@items,所属项目@startdt,发生日期@moneys,金额@explain,说明'; $rows = m('fininfos')->getall("`mid`='{$this->id}' order by `sort`"); $arr[] = array('fields' => 'hdhhd', 'fields_style' => '', 'name' => '报销明细', 'data' => c('html')->createrows($rows, $headstr)); return $arr; }
/** * * * @param $Sender */ public function roleController_afterRolesInfo_handler($Sender) { if (!Gdn::session()->checkPermission('Garden.Settings.Manage')) { return; } ?> <div class="row form-group"> <div class="label-wrap-wide"> <div class="label"><?php echo t('Enable Private Communities'); ?> </div> <div class="info"><?php echo t('Once enabled, only members will see inside your community.'); ?> </div> </div> <div class="input-wrap-right"> <span id="private-community-toggle"> <?php if (c('Garden.PrivateCommunity', false)) { echo wrap(anchor('<div class="toggle-well"></div><div class="toggle-slider"></div>', 'settings/privatecommunity/on/' . Gdn::session()->TransientKey()), 'span', array('class' => "toggle-wrap toggle-wrap-on")); } else { echo wrap(anchor('<div class="toggle-well"></div><div class="toggle-slider"></div>', 'settings/privatecommunity/off/' . Gdn::session()->TransientKey()), 'span', array('class' => "toggle-wrap toggle-wrap-off")); } ?> </span> </div> </div> <?php }
/** * Class constructor. Defines the related database table name. */ public function __construct() { $dbUser = c('VWP.Database.User', c('Database.User')); $dbPassword = c('VWP.Database.Password', $dbUser === c('Database.User') ? c('Database.Password') : ''); $dbName = c('VWP.Database.Name', c('Database.Name')); $dbPrefix = c('VWP.Database.Prefix', 'wp_'); $this->Database = new Gdn_Database(array('Engine' => 'MySQL', 'Host' => c('Database.Host'), 'User' => $dbUser, 'Password' => $dbPassword, 'Name' => $dbName, 'DatabasePrefix' => $dbPrefix)); // Check if a database connection could be made try { $this->Database->connection(); } catch (Exception $e) { // The VWP database connection settings are not correct throw new Gdn_ErrorException(T('VWP: A database connection could not be made.' . ' Make sure the VWP database settings are correct.')); return; } $this->SQL = $this->Database->SQL(); $this->Validation = new Gdn_Validation(); $this->Name = 'posts'; $this->PrimaryKey = 'ID'; // Check if valid WordPress database if (!in_array('wp_options', $this->SQL->fetchTables(true))) { // The table is not a valid WordPress database throw new Gdn_ErrorException(T('VWP: A database connection was made successfully,' . ' but the database is not a valid WordPress database')); } }
public function discussionController_beforeCommentDisplay_handler($sender, $args) { // Find the previous comment. if (!$this->previous) { $this->previous = $args['Discussion']; if ($sender->data('Page', 1) != 1) { $this->previous = $sender->CommentModel->get($sender->DiscussionID, 1, $sender->Offset - 1)->firstRow(); } } // Calculate the date difference. $date = new DateTime($args['Comment']->DateInserted); $gap = $date->diff(new DateTime($this->previous->DateInserted))->days; $this->previous = $args['Comment']; if ($gap < c('TimeGap.MinDays', 7) - 1) { return; } elseif ($gap < 30) { $gap = sprintf(t('%s days later'), (int) $gap); $class = 'Days'; } elseif ($gap < 60) { $gap = t('1 month later'); $class = 'Month'; } elseif ($gap < 365) { $gap = sprintf(t('%s months later'), (int) ($gap / 30)); $class = 'Months'; } elseif ($gap < 720) { $gap = t('1 year later'); $class = 'Year'; } else { $gap = sprintf(t('%s years later'), (int) ($gap / 365)); $class = 'Years'; } echo wrap($gap, 'li', ['class' => 'TimeGap ' . $class]); }
protected function setDatabaseConfig() { //加载.env配置 if (is_file('.env')) { $config = []; foreach (file('.env') as $file) { $data = explode('=', $file); if (count($data) == 2) { $config[trim($data[0])] = trim($data[1]); } } c('database.host', $config['DB_HOST']); c('database.user', $config['DB_USER']); c('database.password', $config['DB_PASSWORD']); c('database.database', $config['DB_DATABASE']); } //将公共数据库配置合并到 write 与 read 中 $config = \Config::getExtName('database', ['write', 'read']); if (empty($config['write'])) { $config['write'][] = \Config::getExtName('database', ['write', 'read']); } if (empty($config['read'])) { $config['read'][] = \Config::getExtName('database', ['write', 'read']); } c('database', $config); }