主页

@return string
760449
public function actionMain()
    {
        switch (yii::$app->getDb()->driverName) {
            case "mysql":
                $dbInfo = 'MySQL ' . (new Query())->select('version()')->one()['version()'];
                break;
            case "pgsql":
                $dbInfo = (new Query())->select('version()')->one()['version'];
                break;
            default:
                $dbInfo = "Unknown";
        }
        $info = [
            'OPERATING_ENVIRONMENT' => PHP_OS . ' ' . $_SERVER['SERVER_SOFTWARE'],
            'PHP_RUN_MODE' => php_sapi_name(),
            'DB_INFO' => $dbInfo,
            'PROGRAM_VERSION' => "1.0",
            'UPLOAD_MAX_FILESIZE' => ini_get('upload_max_filesize'),
            'MAX_EXECUTION_TIME' => ini_get('max_execution_time') . "s"
        ];
        $obj = new ServerInfo();
        $serverInfo = $obj->getinfo();
        error_reporting(E_ALL);
        $status = [
            'DISK_SPACE' => [
                'NUM' => ceil( $serverInfo['diskTotal'] - $serverInfo['freeSpace'] ) . 'G' . ' / ' . ceil($serverInfo['diskTotal']) . 'G',
                'PERCENTAGE' => (floatval($serverInfo['diskTotal']) != 0) ? round(($serverInfo['diskTotal'] - $serverInfo['freeSpace']) / $serverInfo['diskTotal'] * 100, 2) : 0,
            ],
            'MEM' => [
                'NUM' => $serverInfo["UsedMemory"] . ' / ' . $serverInfo['TotalMemory'],
                'PERCENTAGE' => $serverInfo["memPercent"],
            ],
            'REAL_MEM' => [
                'NUM' => $serverInfo["memRealUsed"] . "(Cached {$serverInfo['CachedMemory']})" . ' / ' . $serverInfo['TotalMemory'],
                'PERCENTAGE' => $serverInfo['memRealPercent'] . '%',
            ],
        ];
        $temp = [
            'ARTICLE' => ArticleModel::find()->where(['type' => ArticleModel::ARTICLE])->count('id'),
            'COMMENT' => Comment::find()->count('id'),
            'USER' => User::find()->count('id'),
            'FRIEND_LINK' => FriendlyLink::find()->count('id'),
        ];
        $statics = [
            'ARTICLE' => [
                $temp['ARTICLE'],
                $temp['ARTICLE'] == 0 ? 0 :
                number_format(ArticleModel::find()->where([
                        'between',
                        'created_at',
                        strtotime(date('Y-m-01')),
                        strtotime(date('Y-m-01 23:59:59') . " +1 month -1 day")
                    ])->count('id') / $temp['ARTICLE'] * 100, 2)
            ],
            'COMMENT' => [
                $temp['COMMENT'],
                $temp['COMMENT'] == 0 ? 0 :
                number_format(Comment::find()->where([
                        'between',
                        'created_at',
                        strtotime(date('Y-m-d 00:00:00')),
                        time()
                    ])->count('id') / $temp['COMMENT'] * 100, 2)
            ],
            'USER' => [
                $temp['USER'],
                $temp['USER'] == 0 ? 0 :
                number_format(User::find()->where([
                        'between',
                        'created_at',
                        strtotime(date('Y-m-01')),
                        strtotime(date('Y-m-01 23:59:59') . " +1 month -1 day")
                    ])->count('id') / $temp['USER'] * 100, 2)
            ],
            'FRIEND_LINK' => [
                $temp['FRIEND_LINK'],
                $temp['FRIEND_LINK'] == 0 ? 0 :
                number_format(FriendlyLink::find()->where([
                        'between',
                        'created_at',
                        strtotime(date('Y-m-01')),
                        strtotime(date('Y-m-01 23:59:59') . " +1 month -1 day")
                    ])->count('id') / $temp['FRIEND_LINK'] * 100, 2)
            ],
        ];
        $comments = BackendComment::getRecentComments(6);
        return $this->render('main', [
            'info' => $info,
            'status' => $status,
            'statics' => $statics,
            'comments' => $comments,
        ]);
    }
65687
public static function referer()
    {
        //$protocol = ($_SERVER['SERVER_PORT'] == '443') ? 'https://' : 'http://';
        $protocol = $_SERVER['REQUEST_SCHEME'] . '://';
        
        if ( isset($_SERVER['HTTP_REFERER']) ) {
            // 来路
            $direct = $_SERVER['HTTP_REFERER'];
        } else if ( isset($_SERVER['HTTP_X_FORWARDED_SERVER']) ) {
            // 代理地址
            $direct = $protocol . $_SERVER['HTTP_X_FORWARDED_SERVER'];
        } else {
            // 默认
            $direct = $protocol . $_SERVER['SERVER_NAME'];
        }

        return $direct;
    }
89977
private function getMdContent()
    {
        $tables = $this->initTablesData();
        $content = "## 数据字典\n";
        foreach ($tables as $table){
            $content .= $this->tableName($table);
        }
        $content .= "\n";
        foreach ($tables as $key => $table){
            $content .= $this->tableDetail($key, $table);
        }
        return $content;
    }
551793
public static function GetPdoParamList () {
		return [
			//数値
			'INTEGER'			=> \PDO::PARAM_INT,
			'NUMERIC'			=> \PDO::PARAM_STR,
			'REAL'				=> \PDO::PARAM_STR,
			//文字・文字列
			'TEXT'				=> \PDO::PARAM_STR,
			//バイナリ
			'NONE'				=> \PDO::PARAM_LOB,
		];
	}
447510
private function resolveMysqlOrPostgresqlParameters()
    {
        /** @var IConfig $config */
        $config = $this->di->getShared('config');

        //判断是否主从
        $isMaster = (bool)$config->get($this->getName() . '.is_master', true);
        if ($isMaster) {
            $normalParameters = [
                'host' => '',
                'dbname' => '',
                'username' => '',
                'password' => '',
                'port' => '',
                'charset' => 'UTF8'
            ];
            $parameters = array_intersect_key($config->get($this->getName()), $normalParameters);

        } else {
            $connections = $config->get($this->getName() . '.connections');
            if (!is_array($connections)) {
                throw new \InvalidArgumentException(
                    sprintf('Invalid %s parameters. It must be array.', $this->getName() . '.connections')
                );
            }
            $connections = array_shift($connections);
            $parameters = array_rand($connections);
        }

        if (!is_array($parameters)) {
            throw new \InvalidArgumentException(
                sprintf('invalid %s parameters.', $this->getName())
            );
        }
        if (!isset($parameters['host']) || !$parameters['host']) {
            throw new \InvalidArgumentException('host is not set.');
        }
        if (!isset($parameters['dbname']) || !$parameters['dbname']) {
            throw new \InvalidArgumentException('database name is not set.');
        }
        if (!isset($parameters['username']) || !$parameters['username']) {
            throw new \InvalidArgumentException('database name is not set.');
        }
        if (!isset($parameters['password']) || !$parameters['password']) {
            throw new \InvalidArgumentException('database name is not set.');
        }
        if (!isset($parameters['port']) || !$parameters['port']) {
            $parameters['port'] = 3306;
        }
        if (!Validator::port($parameters['port'])) {
            throw new \InvalidArgumentException(
                sprintf('invalid memcache port: %s', $parameters['port'])
            );
        }
        //设置编码
        if (!isset($parameters['charset'])) {
            $parameters['charset'] = 'UTF8';
        }
        $parameters['options'][\PDO::MYSQL_ATTR_INIT_COMMAND] = sprintf('SET NAMES \'%s\'', $parameters['charset']);
        unset($parameters['charset']);
        return $parameters;
    }
275689
public function getTableField() {
        #不是全表名是添加表前缀
        if (!empty($this->fields)) {
            return $this->fields;
        }
        $name = C('sql', "table") . '.' . $this->table;
        #字段缓存
        if (!DEBUG && F($name, '[get]', 'temp/field')) {
            $data = F($name, '[get]', 'temp/field');
        } else {
            $sql = "show columns from " . $this->table;
            if (!$result = $this->query($sql)) {
                return FALSE;
            }
            $data = [];
            foreach ($result as $res) {
                $f['field']          = $res['Field'];
                $f['type']           = $res['Type'];
                $f['null']           = $res['Null'];
                $f['key']            = ($res['Key'] == "PRI" && $res['Extra']) || $res['Key'] == "PRI";
                $f['default']        = $res['Default'];
                $f['extra']          = $res['Extra'];
                $data[$res['Field']] = $f;
            }
            DEBUG || F($name, $data, 'temp/field');
        }
        return $this->fields = $data;
    }
277495
public function getPdo()
    {
        // 分析查询表达式
        $options = $this->parseExpress();
        // 生成查询SQL
        $sql = $this->builder->select($options);
        // 获取参数绑定
        $bind = $this->getBind();
        if ($options['fetch_sql']) {
            // 获取实际执行的SQL语句
            return $this->connection->getRealSql($sql, $bind);
        }
        // 执行查询操作
        return $this->query($sql, $bind, $options['master'], true);
    }
86901
public function getPHP() {

        $result = '';

        // The type
        switch ($this->getType()) {
            case XMLDB_KEY_PRIMARY:
                $result .= 'XMLDB_KEY_PRIMARY' . ', ';
                break;
            case XMLDB_KEY_UNIQUE:
                $result .= 'XMLDB_KEY_UNIQUE' . ', ';
                break;
            case XMLDB_KEY_FOREIGN:
                $result .= 'XMLDB_KEY_FOREIGN' . ', ';
                break;
            case XMLDB_KEY_FOREIGN_UNIQUE:
                $result .= 'XMLDB_KEY_FOREIGN_UNIQUE' . ', ';
                break;
        }
        // The fields
        $keyfields = $this->getFields();
        if (!empty($keyfields)) {
            $result .= "['".  implode("', '", $keyfields) . "']";
        } else {
            $result .= 'null';
        }
        // The FKs attributes
        if ($this->getType() == XMLDB_KEY_FOREIGN ||
            $this->getType() == XMLDB_KEY_FOREIGN_UNIQUE) {
            // The reftable
            $reftable = $this->getRefTable();
            if (!empty($reftable)) {
                $result .= ", '" . $reftable . "', ";
            } else {
                $result .= 'null, ';
            }
            // The reffields
            $reffields = $this->getRefFields();
            if (!empty($reffields)) {
                $result .= "['".  implode("', '", $reffields) . "']";
            } else {
                $result .= 'null';
            }
        }
        // Return result
        return $result;
    }
58647
public function getLink()
    {
        // Step1 查找出链接
        $link = wei()->navLink()->findId($this->request['id'], $this->request);

        // Step2 验证链接对应的菜单,是否属于当前app
        wei()->nav()->curApp()->findOneById($link['navId']);

        // Step3 如果设置了父链接,检查父链接是否属于当前应用
        if ($link['parentId']) {
            $parentLink = $link->getParentLink();
            wei()->nav()->curApp()->findOneById($parentLink['navId']);
        }

        return $link;
    }
758627
public function getTable()
    {
        if ($this->_sql['from']) {
            $table = $this->_sql['from'];
        } else {
            $table = $this->table;
        }
        /**
         * 处理子查询问题
         * 子查询使用()包裹
         */
        if (strpos($table, ')') !== false && strpos($table, '(') !== false) {
            return $table;
        }
        $table = $this->prefix . $table;
        return $this->formatTable($table);
    }
1367331
protected function categoryMenus()
    {
        $menus = [];
        $categories = $this->getCategories();
        foreach ($categories as $key => $label) {
            $menus[$key] = [
                'label' => $label,
                'items' => array_key_exists($key, $this->defaultCateMenus) ? $this->defaultCateMenus[$key] : []
            ];
        }

        $class = $this->moduleModelClass;
        foreach ($class::models() as $model) { // 安装的扩展模块(开启后台功能)
            if (!$model['admin'] || !array_key_exists($model['category'], $categories)) {
                continue;
            }
            $menus[$model['category']]['items'][] = [
                'label' => $model['name'],
                'url' => ModuleHelper::getAdminHomeUrl($model['id'])
            ];
        }

        return $menus;
    }
285053
public function flush() {
        // 缓存不存在则查询数据表信息
        $this->db->setModel($this->name);
        $fields =   $this->db->getFields($this->getTableName());
        if(!$fields) { // 无法获取字段信息
            return false;
        }
        $this->fields   =   array_keys($fields);
        unset($this->fields['_pk']);
        foreach ($fields as $key=>$val){
            // 记录字段类型
            $type[$key]     =   $val['type'];
            if($val['primary']) {
                  // 增加复合主键支持
                if (isset($this->fields['_pk']) && $this->fields['_pk'] != null) {
                    if (is_string($this->fields['_pk'])) {
                        $this->pk   =   array($this->fields['_pk']);
                        $this->fields['_pk']   =   $this->pk;
                    }
                    $this->pk[]   =   $key;
                    $this->fields['_pk'][]   =   $key;
                } else {
                    $this->pk   =   $key;
                    $this->fields['_pk']   =   $key;
                }
                if($val['autoinc']) $this->autoinc   =   true;
            }
        }
        // 记录字段类型信息
        $this->fields['_type'] =  $type;

        // 2008-3-7 增加缓存开关控制
        if(C('DB_FIELDS_CACHE')){
            // 永久缓存数据表信息
            $db   =  $this->dbName?:C('DB_NAME');
            F('_fields/'.strtolower($db.'.'.$this->tablePrefix.$this->name),$this->fields);
        }
    }
884834
public function parse() {
        $result = [];
        foreach ($this->routingTable as $key => $route) {
            $this->params = [];
            $route['regx'] = preg_replace_callback(
                "/%([^%]+)%/",
                [$this, 'match'],
                preg_quote(str_replace(['[', ']', ':'], ['%', '%', ' '], $route['url']))//$route['url']
            );

            /** 处理斜线 */
            $route['regx'] = rtrim($route['regx'], '/');
            $route['regx'] = '|^' . $route['regx'] . '[/]?$|';

            $route['format'] = preg_replace("/\[([^\]]+)\]/", "%s", $route['url']);//$route['url']
            $route['params'] = $this->params;

            $result[$key] = $route;
        }

        return $result;
    }
1369783
public function renderNav()
    {
        $adminNavId = $this->getAdminNavId();
        $categories = $this->getCategories();

        // 高亮当前页面对应的父菜单
        foreach ($categories as $id => &$category) {
            if (($adminNavId && $adminNavId == $id)
                || $this->isInCategories($category)
            ) {
                $category['active'] = true;
                $this->curSubCategories = $category['navs'];
                break;
            }
        }

        // 默认显示第一个菜单
        if (!$this->curSubCategories && $categories) {
            reset($categories);
            $key = key($categories);
            $categories[$key]['active'] = true;
            $this->curSubCategories = $categories[$key]['navs'];
        }

        return $this->view->render('@admin/admin/nav.php', get_defined_vars());
    }
415857
public function getDbFields(){
        if(isset($this->options['table'])) {// 动态指定表名
            if(is_array($this->options['table'])){
                $table  =   key($this->options['table']);
            }else{
                $table  =   $this->options['table'];
                if(strpos($table,')')){
                    // 子查询
                    return false;
                }
            }
            $fields     =   $this->db->getFields($table);
            return  $fields ? array_keys($fields) : false;
        }
        if($this->fields) {
            $fields     =  $this->fields;
            unset($fields['_type'],$fields['_pk']);
            return $fields;
        }
        return false;
    }
682898
public function getPathinfo()
    {
        //pathinfo已经被重写过
        if ($this->_pathinfo !== null) {
            return $this->_pathinfo;
        }
        $pathinfo = $this->get('PATH_INFO');
        if (!$pathinfo) {
            //兼容模式
            $vitex = Vitex::getInstance();
            if ($vitex->getConfig('router.compatible')) {
                $pathinfo = isset($_GET['u']) ? $_GET['u'] : '';
            }
        }
        return $pathinfo;
    }
274260
public function getquery()
      {
            $query = \Grace\Req\Environment::getInstance()->all()['query'];
            $_p = array();
            $_query = explode('&', $query);
            foreach($_query as $k=>$value){
                  //存在=号
                  $p = explode('=', $value);
                  if(!empty($p[0])){
                        $_p[$p[0]] = isset($p[1])?$p[1]:'';
                  }
            }
            return $_p;       //获得通过querystring 分析出来的参数
      }