/** * Returns the data model based on the id given in the GET variable. * If the data model is not found, an HTTP exception will be raised. * @param string $id the ID of the model to be loaded * @return SBPlugin the loaded model * @throws CHttpException */ public function loadModel($id) { $model = SBPlugin::model()->findById($id); if ($model === null) { throw new CHttpException(404, 'The requested page does not exist.'); } return $model; }
public function actionGroups() { $this->pageTitle = Yii::t('CommunityBansPlugin.main', 'Ban Community Groups'); $this->breadcrumbs = array($this->pageTitle); $plugin = SBPlugin::model()->findById('CommunityBans'); $id = Yii::app()->request->getQuery('id'); if (Yii::app()->request->isAjaxRequest && !empty($id)) { $profile = new SteamProfile($id); $groups = $profile->groups; } if (!isset($groups)) { $groups = array(); } $dataProvider = new CArrayDataProvider($groups, array('keyField' => 'groupID64', 'pagination' => false, 'sort' => array('attributes' => array('groupName', 'memberCount', '*'), 'defaultOrder' => array('groupName' => CSort::SORT_ASC)))); $assetsUrl = Yii::app()->assetManager->publish($plugin->getPath('assets')); Yii::app()->clientScript->registerCssFile($assetsUrl . '/css/community-bans.css'); $this->render($plugin->getViewFile('groups'), array('plugin' => $plugin, 'dataProvider' => $dataProvider)); }
/** * Returns the enabled SourceBans plugins * * @return array the enabled SourceBans plugins */ public function getPlugins() { static $_data; if (!isset($_data)) { $_data = SBPlugin::model()->enabled()->findAll(array('index' => 'id')); } return $_data; }
/** * Finds a single plugin with the specified unique identifier. * * @param string $id the unique identifier * @return SBPlugin the plugin found. Null if none is found. */ public function findById($id) { static $_plugins; if (!isset($_plugins)) { $_plugins = SBPlugin::model()->findAll(array('index' => 'id')); } if (isset($_plugins[$id])) { return $_plugins[$id]; } return null; }
/** * Displays the 'settings' admin page */ public function actionSettings() { $this->pageTitle = Yii::t('sourcebans', 'controllers.admin.settings.title'); $this->breadcrumbs = array(Yii::t('sourcebans', 'controllers.admin.index.title') => array('admin/index'), Yii::t('sourcebans', 'controllers.admin.settings.title')); $this->menu = array(array('label' => Yii::t('sourcebans', 'controllers.admin.settings.menu.settings'), 'url' => '#settings'), array('label' => Yii::t('sourcebans', 'controllers.admin.settings.menu.plugins'), 'url' => '#plugins'), array('label' => Yii::t('sourcebans', 'controllers.admin.settings.menu.logs'), 'url' => '#logs')); $model = new SettingsForm(); // if it is ajax validation request if (isset($_POST['ajax']) && $_POST['ajax'] === 'settings-form') { echo CActiveForm::validate($model); Yii::app()->end(); } if (isset($_POST['SettingsForm'])) { $model->attributes = $_POST['SettingsForm']; if ($model->validate() && $model->save()) { $this->redirect(array('', '#' => 'settings')); } } // Find new plugins and save to database $files = CFileHelper::findFiles(Yii::getPathOfAlias('application.plugins'), array('fileTypes' => array('php'), 'level' => 1)); foreach ($files as $file) { $id = substr(pathinfo($file, PATHINFO_DIRNAME), strlen(Yii::getPathOfAlias('application.plugins')) + 1); $class = (!empty($id) ? $id . '.' : '') . pathinfo($file, PATHINFO_FILENAME); $plugin = new SBPlugin(); $plugin->class = $class; $plugin->save(); } $plugins = new CArrayDataProvider(SBPlugin::model()->findAll(), array('keyField' => 'class', 'sort' => array('attributes' => array('author', 'name', 'version', '*'), 'defaultOrder' => array('name' => CSort::SORT_ASC)))); $logs = new SBLog('search'); $logs->unsetAttributes(); // clear any default values if (isset($_GET['SBLog'])) { $logs->attributes = $_GET['SBLog']; } $this->render('settings', array('logs' => $logs, 'plugins' => $plugins, 'settings' => $model)); }