Exemplo n.º 1
0
 public function initService()
 {
     $this->modularityService = LuLu::getService('modularity');
     $this->rbacService = LuLu::getService('rbac');
     $this->taxonomyService = LuLu::getService('taxonomy');
     $this->menuService = LuLu::getService('menu');
 }
Exemplo n.º 2
0
 public function setTheme()
 {
     $currentTheme = LuLu::getAppParam('adminTheme');
     $moduleId = LuLu::$app->controller->module->id;
     $config = ['pathMap' => ['@app/views' => ['@static/admin/' . $currentTheme . '/views'], '@source/modules/' . $moduleId . '/admin/views' => ['@static/admin/' . $currentTheme . '/modules/' . $moduleId]], 'baseUrl' => '@static/admin/' . $currentTheme];
     $this->theme = new Theme($config);
 }
Exemplo n.º 3
0
 public function loadActiveModules($isAdmin)
 {
     $moduleManager = LuLu::getService('modularityService');
     
     $this->activeModules = $moduleManager->getActiveModules($isAdmin);
     
     $module = $isAdmin ? 'AdminModule' : 'HomeModule';
     foreach ($this->activeModules as $m)
     {
         $moduleId = $m['id'];
         $moduleDir = $m['dir'];
         $ModuleClassName = $m['dir_class'];
         
         $this->setModule($moduleId, [
             'class' => 'source\modules\\' . $moduleDir . '\\' . $module
         ]);
         
         
         $serviceFile= LuLu::getAlias('@source').'\modules\\' .$moduleDir.'\\'.$ModuleClassName.'Service.php';
         
         if(FileHelper::exist($serviceFile))
         {
             $serviceClass = 'source\modules\\' .$moduleDir.'\\'.$ModuleClassName.'Service.php';
             $serviceInstance = new $serviceClass();
             $this->set($serviceInstance->getServiceId(), $serviceInstance);
         }
     }
 }
Exemplo n.º 4
0
 public function init()
 {
     parent::init();
     $this->modularityService = LuLu::getService('modularity');
     $this->rbacService = LuLu::getService('rbac');
     $this->taxonomyService = LuLu::getService('taxonomy');
 }
Exemplo n.º 5
0
 public function beforeAction($action)
 {
     if (!parent::beforeAction($action)) {
         return false;
     }
     //检查不需要登录的action uniqueID,如 site/login, site/captcha
     if (in_array($action->uniqueID, $this->ignoreLogin())) {
         return parent::beforeAction($action);
     }
     if (\Yii::$app->user->isGuest) {
         LuLu::go(['/site/login']);
     }
     if (!$this->rbacService->checkPermission('manager_admin')) {
         return $this->showMessage();
     }
     //return parent::beforeAction($action);
     if (in_array($action->uniqueID, $this->ingorePermission())) {
         return parent::beforeAction($action);
     }
     if (!$this->rbacService->checkPermission()) {
         return $this->showMessage();
     } else {
         return parent::beforeAction($action);
     }
 }
Exemplo n.º 6
0
 public function handleRequest($request)
 {
     if (empty($this->catchAll)) {
         list($route, $params) = $request->resolve();
     } else {
         $route = $this->catchAll[0];
         $params = array_splice($this->catchAll, 1);
     }
     try {
         LuLu::trace("Route requested: '{$route}'", __METHOD__);
         $this->requestedRoute = $route;
         $actionsResult = $this->runAction($route, $params);
         $result = $actionsResult instanceof ActionResult ? $actionsResult->result : $actionsResult;
         if ($result instanceof \yii\web\Response) {
             return $result;
         } else {
             $response = $this->getResponse();
             if ($result !== null) {
                 $response->data = $result;
             }
             return $response;
         }
     } catch (InvalidRouteException $e) {
         throw new NotFoundHttpException(Yii::t('yii', 'Page not found.'), $e->getCode(), $e);
     }
 }
Exemplo n.º 7
0
 public function actionIndex()
 {
     $query = Content::leftJoinWith('takonomy');
     $locals = LuLu::getPagedRows($query, ['orderBy' => 'created_at desc', 'pageSize' => 6]);
     $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => 5]]);
     $locals['dataProvider'] = $dataProvider;
     return $this->render('index', $locals);
 }
Exemplo n.º 8
0
 /**
  * Lists all Permission models.
  * @return mixed
  */
 public function actionIndex()
 {
     $categoryId = LuLu::getGetValue('category_id');
     //$searchModel = new PermissionSearch();
     $query = Permission::find();
     $query->andFilterWhere(['category_id' => $categoryId]);
     $dataProvider = $dataProvider = $this->getDataProvider($query);
     return $this->render('index', ['dataProvider' => $dataProvider]);
 }
Exemplo n.º 9
0
 /**
  * 
  * @param string $where
  * @param string $orderBy
  * @param number $pageSize
  * @param array $options
  * --recommend
  * --headline
  * --sticky
  * --flag
  * --is_pic
  * --content_type
  * --page
  * --taxonomy:array or number
  * 
  * @return array:['rows','pager']
  */
 public static function getPagedContents($where = null, $orderBy = null, $pageSize = 10, $options = [])
 {
     $query = self::buildContentQuery($where, $options);
     $query->joinWith('taxonomy', true, 'LEFT JOIN');
     $page = isset($options['page']) ? $options['page'] : null;
     $orderBy = empty($orderBy) ? 'created_at desc' : $orderBy;
     $locals = LuLu::getPagedRows($query, ['page' => $page, 'pageSize' => $pageSize, 'orderBy' => $orderBy]);
     return $locals;
 }
Exemplo n.º 10
0
 public static function exist($path)
 {
     if (is_array($path))
     {
         $path = self::buildPath($path);
     }
     LuLu::info($path);
     return file_exists($path);
 }
Exemplo n.º 11
0
 public function __get($name)
 {
     $dot = strpos($name, 'Service');
     if ($dot > 0) {
         $serviceName = substr($name, 0, $dot);
         return LuLu::getService($serviceName);
     }
     return parent::__get($name);
 }
Exemplo n.º 12
0
 public static function clearCachedData($id)
 {
     $fragment = self::findOne(['id' => $id]);
     if ($fragment === null) {
         return;
     }
     $cacheKey = self::CachePrefix . $fragment->code;
     LuLu::deleteCache($cacheKey);
 }
Exemplo n.º 13
0
 private function loadAllModules()
 {
     if ($this->allModules !== null) {
         return $this->allModules;
     }
     $this->allModules = [];
     $moduleRootPath = LuLu::getAlias('@source') . '/modules';
     if ($moduleRootDir = @dir($moduleRootPath)) {
         while (($moduleFolder = $moduleRootDir->read()) !== false) {
             $modulePath = $moduleRootPath . '/' . $moduleFolder;
             if (preg_match('|^\\.+$|', $moduleFolder) || !is_dir($modulePath)) {
                 continue;
             }
             if ($moduleDir = @dir($modulePath)) {
                 $moduleClassName = ucwords($moduleFolder);
                 $class = null;
                 $instance = null;
                 $has_admin = false;
                 $has_home = false;
                 while (($item = $moduleDir->read()) !== false) {
                     $itemPath = $moduleRootPath . '/' . $moduleFolder . '/' . $item;
                     if (preg_match('|^\\.+$|', $item) || is_dir($itemPath)) {
                         continue;
                     }
                     if ($item === $moduleClassName . 'Info.php') {
                         $class = 'source\\modules\\' . $moduleFolder . '\\' . $moduleClassName . 'Info';
                     }
                     if ($item === 'AdminModule.php') {
                         $has_admin = true;
                     }
                     if ($item === 'HomeModule.php') {
                         $has_home = true;
                     }
                 }
                 if ($class !== null) {
                     try {
                         // $moduleObj = LuLu::createObject($class);
                         $instance = new $class();
                         if (empty($instance->id)) {
                             $instance->id = $moduleFolder;
                         }
                         if (empty($instance->name)) {
                             $instance->name = $moduleFolder;
                         }
                     } catch (Exception $e) {
                         // $instance=$e;
                     }
                 }
                 if ($instance !== null) {
                     $this->allModules[$instance->id] = ['id' => $instance->id, 'dir' => $moduleFolder, 'dir_class' => $moduleClassName, 'class' => $class, 'instance' => $instance, 'can_install' => true, 'can_uninstall' => true, 'has_admin' => $has_admin, 'has_home' => $has_home, 'can_active_admin' => false, 'can_active_home' => false];
                 }
             }
         }
     }
     return $this->allModules;
 }
Exemplo n.º 14
0
 public function actionIndex()
 {
     $query = Content::leftJoinWith('takonomy');
     $locals = LuLu::getPagedRows($query, [
         'orderBy' => 'created_at desc', 
         'pageSize' => 6
     ]);
     
     return $this->render('index', $locals);
 }
Exemplo n.º 15
0
 /**
  * 内容页
  * @param unknown $id
  * @return \yii\base\string
  */
 public function actionDetail($id)
 {
     Content::updateAllCounters(['view_count' => 1], ['id' => $id]);
     $locals = $this->getDetail($id);
     $taxonomyModel = $this->taxonomyService->getTaxonomyById($locals['model']['taxonomy_id']);
     LuLu::setViewParam(['taxonomyModel' => $taxonomyModel]);
     $locals['taxonomyModel'] = $taxonomyModel;
     $vars = $this->getDetailVars($locals['taxonomyModel'], $locals['model']);
     $this->layout = $vars['layout'];
     return $this->render($vars['view'], $locals);
 }
Exemplo n.º 16
0
 public function actionList()
 {
     $takonomy = LuLu::getGetValue('takonomy');
     $takonomyModel = Takonomy::getOneOrDefault($takonomy);
     $query = Content::find();
     $query->where(['content_type' => $this->content_type]);
     $query->andFilterWhere(['takonomy_id' => $takonomy]);
     $locals = LuLu::getPagedRows($query, ['orderBy' => 'created_at desc', 'pageSize' => 10]);
     $locals['takonomyModel'] = $takonomyModel;
     return $this->render('list_default', $locals);
 }
Exemplo n.º 17
0
 public function init()
 {
     parent::init();
     $this->getView()->on(BaseView::EVENT_BEGIN_PAGE, [$this, 'beginPage']);
     $this->getView()->on(BaseView::EVENT_BEGIN_BODY, [$this, 'beginBody']);
     $this->getView()->on(BaseView::EVENT_BEFORE_RENDER, [$this, 'beforeRender']);
     $this->getView()->on(BaseView::EVENT_AFTER_RENDER, [$this, 'afterRender']);
     $this->getView()->on(BaseView::EVENT_END_BODY, [$this, 'endBody']);
     $this->getView()->on(BaseView::EVENT_END_PAGE, [$this, 'endPage']);
     $this->getView()->on(BaseView::EVENT_AFTER_PAGE, [$this, 'afterPage']);
     LuLu::getResponse()->on(Response::EVENT_AFTER_SEND, [$this, 'afterResponse']);
 }
Exemplo n.º 18
0
 public static function AddBatchItems($role, $permissions)
 {
     self::deleteAll(['role' => $role]);
     LuLu::deleteCache(RbacService::CachePrefix . $role);
     foreach ($permissions as $key => $value) {
         $newRelation = new Relation();
         $newRelation->role = $role;
         $newRelation->permission = $key;
         $newRelation->value = is_string($value) ? $value : implode(',', $value);
         $newRelation->save();
     }
 }
Exemplo n.º 19
0
 /**
  * Lists all Relation models.
  * @return mixed
  */
 public function actionIndex($role)
 {
     if (\Yii::$app->request->isPost) {
         $selectedPermissions = LuLu::getPostValue('Permission');
         Relation::AddBatchItems($role, $selectedPermissions);
         return $this->redirect(['index', 'role' => $role]);
     }
     $allPermissions = Permission::getAllPermissionsGroupedByCategory();
     $rolePermissions = Relation::find()->select(['permission', 'value'])->where(['role' => $role])->indexBy('permission')->all();
     $categories = Permission::getCategoryItems();
     $role = Role::findOne(['id' => $role]);
     return $this->render('index', ['rolePermissions' => $rolePermissions, 'allPermissions' => $allPermissions, 'categories' => $categories, 'role' => $role]);
 }
Exemplo n.º 20
0
 public function getMessagePrefix($message)
 {
     if ($this->prefix !== null) {
         return call_user_func($this->prefix, $message);
     }
     $ip = Utility::getIp();
     $userID = LuLu::getIdentity()->username;
     if (empty($userID)) {
         return "[{$ip}]";
     } else {
         return "[{$ip}]<br/>[{$userID}]";
     }
 }
Exemplo n.º 21
0
 public function execute($role, $permission, $params = [])
 {
     $actionId = isset($params['actionId']) ? $params['actionId'] : LuLu::getApp()->requestedAction->id;
     $actions = $permission['value'];
     if (in_array($actionId, $actions)) {
         return true;
     }
     $method = LuLu::getApp()->request->method;
     $method = strtolower($method);
     if (in_array($actionId . ':' . $method, $actions)) {
         return true;
     }
     return false;
 }
Exemplo n.º 22
0
 public function actionList($taxonomy = -1)
 {
     $query = Content::find();
     $query->where(['content_type' => $this->content_type]);
     if ($taxonomy !== -1) {
         $query->andFilterWhere(['taxonomy_id' => $taxonomy]);
     }
     $taxonomyModel = $this->taxonomyService->getTaxonomyById($taxonomy);
     $vars = $this->getListVars($taxonomyModel);
     $locals = LuLu::getPagedRows($query, ['orderBy' => 'created_at desc', 'pageSize' => $vars['pageSize']]);
     $locals['taxonomyModel'] = $taxonomyModel;
     LuLu::setViewParam(['taxonomyModel' => $taxonomyModel]);
     $this->layout = $vars['layout'];
     return $this->render($vars['view'], $locals);
 }
Exemplo n.º 23
0
 public function actionIndex()
 {
     $taxonomy = LuLu::getGetValue('taxonomy');
     $query = Content::find();
     $query->where(['content_type' => $this->content_type]);
     $query->andFilterWhere(['taxonomy_id' => $taxonomy]);
     if ($taxonomy === null) {
         $taxonomyModel = Taxonomy::findOne(['id' => $taxonomy]);
     } else {
         $taxonomyModel = ['id' => null, 'name' => '所有'];
     }
     $locals = LuLu::getPagedRows($query, ['orderBy' => 'created_at desc', 'pageSize' => 10]);
     $locals['taxonomyModel'] = $taxonomyModel;
     return $this->render('index', $locals);
 }
Exemplo n.º 24
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Category::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     $this->type = LuLu::getGetValue('type');
     $query->andWhere(['type' => $this->type]);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'description', $this->description]);
     return $dataProvider;
 }
Exemplo n.º 25
0
 public function actionIndex()
 {
     $model = new CacheForm();
     if (LuLu::$app->request->isPost && $model->load(LuLu::$app->request->post())) {
         if ($model->cache) {
             LuLu::flushCache();
             LuLu::$app->schemaCache->flush();
         }
         if ($model->asset) {
             $assetDir = LuLu::getAlias('@statics/assets');
             FileHelper::removeDirectoryContent($assetDir);
         }
         return $this->redirect(['index']);
     }
     return $this->render('index', ['model' => $model]);
 }
Exemplo n.º 26
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Permission::find();
     $query->orderBy('id asc,sort_num desc');
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     $this->category_id = LuLu::getGetValue('category');
     $query->andWhere(['category_id' => $this->category_id]);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['category_id' => $this->category_id, 'form' => $this->form]);
     $query->andFilterWhere(['like', 'id', $this->id])->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'description', $this->description]);
     return $dataProvider;
 }
Exemplo n.º 27
0
 private function loadAllModules()
 {
     $ret = [];
     $moduleRootPath = LuLu::getAlias('@source') . '/modules';
     if ($moduleRootDir = @dir($moduleRootPath)) {
         while (($moduleFile = $moduleRootDir->read()) !== false) {
             $modulePath = $moduleRootPath . '/' . $moduleFile;
             if (preg_match('|^\\.+$|', $moduleFile) || !is_dir($modulePath)) {
                 continue;
             }
             if ($moduleDir = @dir($modulePath)) {
                 $moduleInfo = str_replace(' ', '', ucwords(implode(' ', explode('-', $moduleFile))));
                 $class = null;
                 $instance = null;
                 $can_active_admin = null;
                 $can_active_home = null;
                 while (($item = $moduleDir->read()) !== false) {
                     $itemPath = $moduleRootPath . '/' . $moduleFile . '/' . $item;
                     if (preg_match('|^\\.+$|', $item) || is_dir($itemPath)) {
                         continue;
                     }
                     if ($item === $moduleInfo . 'Module.php') {
                         $class = 'source\\modules\\' . $moduleFile . '\\' . $moduleInfo . 'Module';
                     }
                 }
                 if ($class !== null) {
                     try {
                         // $moduleObj = LuLu::createObject($class);
                         $instance = new $class();
                         if (empty($instance->name)) {
                             $instance->name = $moduleFile;
                         }
                     } catch (Exception $e) {
                         // $instance=$e;
                     }
                 }
                 $ret[$moduleFile] = ['id' => $moduleFile, 'class' => $class, 'instance' => $instance, 'can_install' => true, 'can_uninstall' => true, 'can_active_admin' => false, 'can_active_home' => false];
             }
         }
     }
     return $ret;
 }
Exemplo n.º 28
0
 public function actionRole($user)
 {
     $userRoles = Assignment::find()->select('role')->where(['user' => $user])->indexBy('role')->all();
     if (\Yii::$app->request->isPost) {
         $selectedRoles = LuLu::getPostValue('roles', []);
         Assignment::deleteAll(['and', 'user=\'' . $user . '\'', ['not in', 'role', $selectedRoles]]);
         foreach ($selectedRoles as $selectedRole) {
             if ($userRoles != null && isset($userRoles[$selectedRole])) {
                 continue;
             }
             $newAssignment = new Assignment();
             $newAssignment->user = $user;
             $newAssignment->role = $selectedRole;
             $newAssignment->save();
         }
         return $this->redirect(['role', 'user' => $user]);
     }
     $allRoles = Role::findAll();
     return $this->render('role', ['userRoles' => $userRoles, 'allRoles' => $allRoles]);
 }
Exemplo n.º 29
0
 /**
  * Lists all Relation models.
  * @return mixed
  */
 public function actionIndex($role)
 {
     $rolePermissions = Relation::find()->select(['permission', 'value'])->where(['role' => $role])->indexBy('permission')->all();
     if (\Yii::$app->request->isPost) {
         var_dump(LuLu::getPostValue('Permission'));
         $selectedPermissions = LuLu::getPostValue('Permission');
         $keys = array_keys($selectedPermissions);
         Relation::deleteAll(['role' => $role]);
         foreach ($selectedPermissions as $key => $value) {
             $newRelation = new Relation();
             $newRelation->role = $role;
             $newRelation->permission = $key;
             $newRelation->value = is_string($value) ? $value : implode(',', $value);
             $newRelation->save();
         }
         return $this->redirect(['index', 'role' => $role]);
     }
     $allPermissions = Permission::findAll();
     return $this->render('index', ['rolePermissions' => $rolePermissions, 'allPermissions' => $allPermissions]);
 }
Exemplo n.º 30
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Fragment1Data::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->fragment_id = LuLu::getGetValue('fid');
     $query->andFilterWhere(['fragment_id' => $this->fragment_id]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     //         $query->andFilterWhere([
     //             'id' => $this->id,
     //             'fragment_id' => $this->fragment_id,
     //             'sort_num' => $this->sort_num,
     //             'status' => $this->status,
     //         ]);
     $query->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'content', $this->content]);
     return $dataProvider;
 }