Ejemplo n.º 1
0
 /**
  * @covers Kisma\Core\Utility\Option::set
  */
 public function testSetWithArray()
 {
     $_sourceOptions = array('ThisIsCamelCase' => 'camel case', 'this_is_not_camel_case' => 'not camel case', 'one' => 'one', 'eight' => 'eight', 'zero' => 'zero');
     $_targetOptions = array();
     Option::set($_targetOptions, $_sourceOptions);
     $this->assertEquals($_sourceOptions, $_targetOptions);
 }
Ejemplo n.º 2
0
 /**
  * Record version of successfully completed component update
  *
  * @param string $name
  * @param string $version
  */
 public static function recordComponentSuccessfullyUpdated($name, $version)
 {
     try {
         Option::set(self::getNameInOptionTable($name), $version, $autoLoad = 1);
     } catch (\Exception $e) {
         // case when the option table is not yet created (before 0.2.10)
     }
 }
 /**
  * Run the migrations.
  *
  * @return void
  */
 public function up()
 {
     // import options
     $options = config('options');
     $options['version'] = config('app.version');
     $options['announcement'] = str_replace('{version}', $options['version'], $options['announcement']);
     foreach ($options as $key => $value) {
         Option::set($key, $value);
     }
     Option::save();
 }
Ejemplo n.º 4
0
 /**
  *  List all the roles
  */
 public function listRoles()
 {
     if (App::request()->getParams('setdefault')) {
         Option::set('roles.default-role', App::request()->getParams('setdefault'));
         $defaultRole = App::request()->getParams('setdefault');
     } else {
         $defaultRole = Option::get('roles.default-role');
     }
     $param = array('id' => 'roles-list', 'action' => App::router()->getUri('list-roles'), 'model' => 'Role', 'navigation' => false, 'controls' => array(array('icon' => 'plus', 'label' => Lang::get('roles.add-role-btn'), 'href' => App::router()->getUri('edit-role', array('roleId' => -1)), 'target' => 'dialog', 'class' => 'btn-success'), array('icon' => 'unlock-alt', 'label' => Lang::get('roles.edit-permissions-btn'), 'href' => App::router()->getUri('permissions'), 'target' => 'newtab')), 'fields' => array('removable' => array('field' => 'removable', 'hidden' => true), 'color' => array('field' => 'color', 'hidden' => true), 'actions' => array('independant' => true, 'display' => function ($value, $field, $line) {
         return Icon::make(array('icon' => 'pencil', 'class' => 'text-info', 'href' => App::router()->getUri('edit-role', array('roleId' => $line->id)), 'target' => 'dialog')) . Icon::make(array('icon' => 'unlock-alt', 'class' => 'text-success', 'href' => App::router()->getUri('role-permissions', array('roleId' => $line->id)), 'target' => 'newtab')) . ($line->isRemovable() ? Icon::make(array('icon' => 'close', 'class' => 'text-danger delete-role', 'data-role' => $line->id)) : '');
     }, 'search' => false, 'sort' => false), 'name' => array('independant' => true, 'label' => Lang::get('roles.list-name-label'), 'display' => function ($value, $field, $line) {
         return "<span style='color:{$line->color}'>" . Lang::get("roles.role-{$line->id}-label") . "</span>";
     }), 'default' => array('independant' => true, 'label' => Lang::get('roles.list-default-label'), 'display' => function ($value, $field, $line) use($defaultRole) {
         if ($line->id != 0) {
             $checkbox = new CheckboxInput(array('class' => 'set-default-role', 'value' => $defaultRole == $line->id, 'disabled' => $defaultRole == $line->id, 'attributes' => array('value' => $line->id)));
             return $checkbox->display();
         }
     }, 'search' => false, 'sort' => false)));
     $this->addKeysToJavaScript("roles.delete-role-confirmation");
     return View::make(Plugin::current()->getView("roles-list.tpl"), array('list' => new ItemList($param)));
 }
<?php

/**
 * @Author: printempw
 * @Date:   2016-08-27 18:21:04
 * @Last Modified by:   printempw
 * @Last Modified time: 2016-08-27 18:21:15
 */
if (Option::get('update_source') == "github") {
    Option::set('update_source', 'nyavm');
}
Option::set('version', '3.0.4');
Ejemplo n.º 6
0
 /**
  * Auto generated seed file
  *
  * @return void
  */
 public function run()
 {
     o::set('option.version', '2.0.0');
 }
Ejemplo n.º 7
0
 /**
  * @param int    $which
  * @param string $what
  *
  * @return Markup
  */
 public function setDelimiter($which, $what)
 {
     Option::set(static::$_delimiters, $which, $what);
     return $this;
 }
Ejemplo n.º 8
0
 /**
  * Display and treat application settings
  */
 public function settings()
 {
     $languages = array_map(function ($language) {
         return $language->label;
     }, Language::getAll('tag'));
     $roleObjects = Role::getListByExample(new DBExample(array('id' => array('$ne' => 0))), 'id');
     $roles = array();
     foreach ($roleObjects as $role) {
         $roles[$role->id] = Lang::get("roles.role-{$role->id}-label");
     }
     $items = MenuItem::getAvailableItems();
     $menuItems = array();
     foreach ($items as $item) {
         if ($item->action && !preg_match('/^(javascript\\:|#)/', $item->action) && (!$item->target || $item->target == 'newtab')) {
             if ($item->label === 'user.username') {
                 $item->label = App::session()->getUser()->username;
             }
             $menuItems[$item->action] = $item->label;
         } else {
             foreach ($item->visibleItems as $subitem) {
                 if ($item->label === 'user.username') {
                     $item->label = App::session()->getUser()->username;
                 }
                 if (!preg_match('/^(javascript\\:|#)/', $subitem->action) && (!$subitem->target || $subitem->target == 'newtab')) {
                     $menuItems[$subitem->action] = $item->label . " &gt; " . $subitem->label;
                 }
             }
         }
     }
     $api = new HawkApi();
     try {
         $updates = $api->getCoreAvailableUpdates();
     } catch (\Hawk\HawkApiException $e) {
         $updates = array();
     }
     $param = array('id' => 'settings-form', 'upload' => true, 'fieldsets' => array('main' => array(new TextInput(array('name' => 'main_sitename', 'required' => true, 'default' => Option::get('main.sitename'), 'label' => Lang::get('admin.settings-sitename-label'))), new SelectInput(array('name' => 'main_language', 'required' => true, 'options' => $languages, 'default' => Option::get('main.language'), 'label' => Lang::get('admin.settings-language-label'))), new SelectInput(array('name' => 'main_timezone', 'required' => true, 'options' => array_combine(\DateTimeZone::listIdentifiers(), \DateTimeZone::listIdentifiers()), 'default' => Option::get('main.timezone'), 'label' => Lang::get('admin.settings-timezone-label'))), new SelectInput(array('name' => 'main_currency', 'required' => true, 'options' => array('EUR' => 'Euro (€)', 'USD' => 'US Dollar ($)'), 'default' => Option::get('main.currency'), 'label' => Lang::get('admin.settings-currency-label'))), new FileInput(array('name' => 'logo', 'label' => Lang::get('admin.settings-logo-label'), 'after' => Option::get('main.logo') ? '<img src="' . Plugin::get('main')->getUserfilesUrl(Option::get('main.logo')) . '" class="settings-logo-preview" />' : '', 'maxSize' => 200000, 'extensions' => array('gif', 'png', 'jpg', 'jpeg'))), new FileInput(array('name' => 'favicon', 'label' => Lang::get('admin.settings-favicon-label'), 'after' => Option::get('main.favicon') ? '<img src="' . Plugin::get('main')->getUserfilesUrl(Option::get('main.favicon')) . '" class="settings-favicon-preview" />' : '', 'maxSize' => 20000, 'extensions' => array('gif', 'png', 'jpg', 'jpeg', 'ico')))), 'referencing' => call_user_func(function () use($languages) {
         $inputs = array();
         foreach ($languages as $tag => $language) {
             $inputs[] = new TextInput(array('name' => 'main_page-title-' . $tag, 'default' => Option::get('main.page-title-' . $tag)));
             $inputs[] = new TextareaInput(array('name' => 'main_page-description-' . $tag, 'default' => Option::get('main.page-description-' . $tag)));
             $inputs[] = new TextInput(array('name' => 'main_page-keywords-' . $tag, 'default' => Option::get('main.page-keywords-' . $tag)));
         }
         return $inputs;
     }), 'home' => array(new RadioInput(array('name' => 'main_home-page-type', 'options' => array('default' => Lang::get('admin.settings-home-page-type-default'), 'custom' => Lang::get('admin.settings-home-page-type-custom'), 'page' => Lang::get('admin.settings-home-page-type-page')), 'default' => Option::get('main.home-page-type') ? Option::get('main.home-page-type') : 'default', 'label' => Lang::get('admin.settings-home-page-type-label'), 'layout' => 'vertical', 'attributes' => array('e-value' => 'homePage.type'))), new WysiwygInput(array('name' => 'main_home-page-html', 'id' => 'home-page-html', 'label' => Lang::get('admin.settings-home-page-html-label'), 'default' => Option::get('main.home-page-html'))), new SelectInput(array('name' => 'main_home-page-item', 'id' => 'home-page-item', 'label' => Lang::get('admin.settings-home-page-item-label'), 'options' => $menuItems, 'value' => Option::get('main.home-page-item'))), new CheckboxInput(array('name' => 'main_open-last-tabs', 'label' => Lang::get('admin.settings-open-last-tabs'), 'default' => Option::get('main.open-last-tabs'), 'dataType' => 'int'))), 'users' => array(new RadioInput(array('name' => 'main_allow-guest', 'options' => array(0 => Lang::get('main.no-txt'), 1 => Lang::get('main.yes-txt')), 'default' => Option::get('main.allow-guest') ? Option::get('main.allow-guest') : 0, 'label' => Lang::get('admin.settings-allow-guest-label'))), new RadioInput(array('name' => 'main_open-register', 'options' => array(0 => Lang::get('admin.settings-open-register-off'), 1 => Lang::get('admin.settings-open-register-on')), 'layout' => 'vertical', 'label' => Lang::get('admin.settings-open-registers-label'), 'default' => Option::get('main.open-register') ? Option::get('main.open-register') : 0, 'attributes' => array('e-value' => 'register.open'))), new CheckboxInput(array('name' => 'main_confirm-register-email', 'label' => Lang::get('admin.settings-confirm-email-label'), 'default' => Option::get('main.confirm-register-email'), 'dataType' => 'int', 'attributes' => array('e-value' => 'register.checkEmail'))), new WysiwygInput(array('name' => 'main_confirm-email-content', 'id' => 'settings-confirm-email-content-input', 'default' => Option::get('main.confirm-email-content'), 'label' => Lang::get('admin.settings-confirm-email-content-label'), 'labelWidth' => 'auto')), new CheckboxInput(array('name' => 'main_confirm-register-terms', 'label' => Lang::get('admin.settings-confirm-terms-label'), 'default' => Option::get('main.confirm-register-terms'), 'dataType' => 'int', 'labelWidth' => 'auto', 'attributes' => array('e-value' => 'register.checkTerms'))), new WysiwygInput(array('name' => 'main_terms', 'id' => 'settings-terms-input', 'label' => Lang::get('admin.settings-terms-label'), 'labelWidth' => 'auto', 'default' => Option::get('main.terms'))), new SelectInput(array('name' => 'roles_default-role', 'label' => Lang::get('admin.settings-default-role-label'), 'options' => $roles, 'default' => Option::get('roles.default-role')))), 'email' => array(new EmailInput(array('name' => 'main_mailer-from', 'default' => Option::get('main.mailer-from') ? Option::get('main.mailer-from') : App::session()->getUser()->email, 'label' => Lang::get('admin.settings-mailer-from-label'))), new TextInput(array('name' => 'main_mailer-from-name', 'default' => Option::get('main.mailer-from-name') ? Option::get('main.mailer-from-name') : App::session()->getUser()->getDisplayName(), 'label' => Lang::get('admin.settings-mailer-from-name-label'))), new SelectInput(array('name' => 'main_mailer-type', 'default' => Option::get('main.mailer-type'), 'options' => array('mail' => Lang::get('admin.settings-mailer-type-mail-value'), 'smtp' => Lang::get('admin.settings-mailer-type-smtp-value'), 'pop3' => Lang::get('admin.settings-mailer-type-pop3-value')), 'label' => Lang::get('admin.settings-mailer-type-label'), 'attributes' => array('e-value' => 'mail.type'))), new TextInput(array('name' => 'main_mailer-host', 'default' => Option::get('main.mailer-host'), 'label' => Lang::get('admin.settings-mailer-host-label'))), new IntegerInput(array('name' => 'main_mailer-port', 'default' => Option::get('main.mailer-port'), 'label' => Lang::get('admin.settings-mailer-port-label'), 'size' => 4)), new TextInput(array('name' => 'main_mailer-username', 'default' => Option::get('main.mailer-username'), 'label' => Lang::get('admin.settings-mailer-username-label'))), new PasswordInput(array('name' => 'main_mailer-password', 'encrypt' => 'Crypto::aes256Encode', 'decrypt' => 'Crypto::aes256Decode', 'default' => Option::get('main.mailer-password'), 'label' => Lang::get('admin.settings-mailer-password-label'))), new SelectInput(array('name' => 'main_smtp-secured', 'options' => array('' => Lang::get('main.no-txt'), 'ssl' => 'SSL', 'tsl' => 'TSL'), 'label' => Lang::get('admin.settings-smtp-secured-label')))), '_submits' => array(empty($updates) ? new HtmlInput(array('value' => '<span class="btn btn-success">' . Lang::get('admin.hawk-version-up-to-date', array('version' => HAWK_VERSION)) . '</span>')) : new ButtonInput(array('name' => 'update-hawk', 'value' => Lang::get('admin.update-page-update-hawk-btn', array('version' => end($updates)['version'])), 'icon' => 'refresh', 'id' => 'update-hawk-btn', 'attributes' => array('e-click' => 'function(){ updateHawk("' . end($updates)['version'] . '"); }'), 'class' => 'btn-warning')), new SubmitInput(array('name' => 'save', 'value' => Lang::get('main.valid-button'), 'class' => 'pull-right')))));
     $form = new Form($param);
     if (!$form->submitted()) {
         // Display the form
         $this->addCss(Plugin::current()->getCssUrl('settings.less'));
         $page = View::make(Plugin::current()->getView('settings.tpl'), array('form' => $form, 'languages' => $languages));
         $this->addKeysToJavaScript('admin.update-page-confirm-update-hawk');
         $this->addJavaScript(Plugin::current()->getJsUrl('settings.js'));
         return NoSidebarTab::make(array('icon' => 'cogs', 'title' => Lang::get('admin.settings-page-name'), 'description' => Lang::get('admin.settings-page-description'), 'page' => $page));
     } else {
         // treat the form
         try {
             if ($form->check()) {
                 // register scalar values
                 foreach ($form->inputs as $name => $field) {
                     if (!$field instanceof \Hawk\FileInput && !$field instanceof \Hawk\ButtonInput && !$field instanceof \Hawk\HtmlInput) {
                         $value = $field->dbvalue();
                         if ($value === null) {
                             $value = '0';
                         }
                         $optionName = str_replace('_', '.', $name);
                         App::logger()->error("Option name =" . $optionName . 'X');
                         App::logger()->error("basename=" . $value . 'X');
                         Option::set($optionName, $value);
                     } elseif ($field instanceof \Hawk\FileInput) {
                         $upload = Upload::getInstance($name);
                         if ($upload) {
                             try {
                                 $file = $upload->getFile();
                                 $dir = Plugin::get('main')->getPublicUserfilesDir();
                                 if (!is_dir($dir)) {
                                     mkdir($dir, 0755);
                                 }
                                 if ($name == 'favicon') {
                                     $basename = uniqid() . '.ico';
                                     $generator = new \PHPICO($file->tmpFile, array(array(16, 16), array(32, 32), array(48, 48), array(64, 64)));
                                     $generator->save_ico($dir . $basename);
                                 } else {
                                     $basename = uniqid() . '.' . $file->extension;
                                     $upload->move($file, $dir, $basename);
                                 }
                                 // remove the old image
                                 @unlink($dir . Option::get("main.{$name}"));
                                 App::logger()->error("Option name = " . $name);
                                 App::logger()->error("main.{$name}");
                                 App::logger()->error("basename=" . $basename);
                                 Option::set("main.{$name}", $basename);
                             } catch (ImageException $e) {
                                 $form->error($name, Lang::get('form.image-format'));
                                 throw $e;
                             }
                         }
                     }
                 }
                 // Register the favicon
                 App::logger()->info('The options of the application has been updated by ' . App::session()->getUser()->username);
                 return $form->response(Form::STATUS_SUCCESS, Lang::get('admin.settings-save-success'));
             }
         } catch (Exception $e) {
             App::logger()->error('An error occured while updating application options');
             return $form->response(Form::STATUS_ERROR, DEBUG_MODE ? $e->getMessage() : Lang::get('admin.settings-save-error'));
         }
     }
 }
 /**
  * @param string $key
  * @param $value
  */
 public static function set($key, $value)
 {
     Option::set(self::$key . '.' . $key, $value);
 }
Ejemplo n.º 10
0
 /**
  *
  */
 public function set_opt($i_key, $i_value)
 {
     return Option::set(get_called_class(), $this->id, $i_key, $i_value);
 }
Ejemplo n.º 11
0
 /**
  * Set customized variables values
  *
  * @param array $values The values to set
  */
 public function setVariablesCustomValues($values)
 {
     foreach ($values as $key => $value) {
         $varname = 'custom-value-' . $key;
         Option::set('theme-' . $this->name . '.' . $varname, $value);
     }
 }
<?php

/**
 * @Author: printempw
 * @Date:   2016-11-18 16:25:35
 * @Last Modified by:   printempw
 * @Last Modified time: 2016-12-11 22:42:31
 */
Option::set('update_source', config('option')['update_source']);
Option::set('version', '3.2');
return ['v3.2 新加入了插件系统,支持的插件请去程序发布帖查看'];
 /**
  * Handle ajax request from /admin/users
  *
  * @param  Request $request
  * @return void
  */
 public function userAjaxHandler(Request $request, UserRepository $users)
 {
     $action = $request->input('action');
     if ($action == "color") {
         $this->validate($request, ['color_scheme' => 'required']);
         $color_scheme = str_replace('_', '-', $request->input('color_scheme'));
         \Option::set('color_scheme', $color_scheme);
         return json('修改配色成功', 0);
     }
     $user = $users->get($request->input('uid'));
     // current user
     $cur_user = $users->get(session('uid'));
     if (!$user) {
         return json('用户不存在', 1);
     }
     if ($action == "email") {
         $this->validate($request, ['email' => 'required|email']);
         if ($user->setEmail($request->input('email'))) {
             return json('邮箱修改成功', 0);
         }
     } elseif ($action == "nickname") {
         $this->validate($request, ['nickname' => 'required|nickname']);
         if ($user->setNickName($request->input('nickname'))) {
             return json('昵称已成功设置为 ' . $request->input('nickname'), 0);
         }
     } elseif ($action == "password") {
         $this->validate($request, ['password' => 'required|min:8|max:16']);
         if ($user->changePasswd($request->input('password'))) {
             return json('密码修改成功', 0);
         }
     } elseif ($action == "score") {
         $this->validate($request, ['score' => 'required|integer']);
         if ($user->setScore($request->input('score'))) {
             return json('积分修改成功', 0);
         }
     } elseif ($action == "ban") {
         if ($user->getPermission() == User::ADMIN) {
             if ($cur_user->getPermission() != User::SUPER_ADMIN) {
                 return json('非超级管理员无法封禁普通管理员');
             }
         } elseif ($user->getPermission() == User::SUPER_ADMIN) {
             return json('超级管理员无法被封禁');
         }
         $permission = $user->getPermission() == User::BANNED ? User::NORMAL : User::BANNED;
         if ($user->setPermission($permission)) {
             return json(['errno' => 0, 'msg' => '账号已被' . ($permission == User::BANNED ? '封禁' : '解封'), 'permission' => $user->getPermission()]);
         }
     } elseif ($action == "admin") {
         if ($cur_user->getPermission() != User::SUPER_ADMIN) {
             return json('非超级管理员无法进行此操作');
         }
         if ($user->getPermission() == User::SUPER_ADMIN) {
             return json('超级管理员无法被解除');
         }
         $permission = $user->getPermission() == User::ADMIN ? User::NORMAL : User::ADMIN;
         if ($user->setPermission($permission)) {
             return json(['errno' => 0, 'msg' => '账号已被' . ($permission == User::ADMIN ? '设为' : '解除') . '管理员', 'permission' => $user->getPermission()]);
         }
     } elseif ($action == "delete") {
         if ($user->delete()) {
             return json('账号已被成功删除', 0);
         }
     } else {
         return json('非法参数', 1);
     }
 }
<?php

/**
 * @Author: printempw
 * @Date:   2016-09-28 22:43:44
 * @Last Modified by:   printempw
 * @Last Modified time: 2016-09-28 22:55:29
 */
Option::set('version', '3.1.1');
return ['如果你是从 v3.0.x 升级上来的,请进行下列操作:', '把 /textures 文件夹移动至 /storage 文件夹中', '删除 /config/routes.php,不然会出现奇怪的问题', '重新复制一份 .env.example,并适当修改其中的配置(尤其注意 PWD_METHOD 要和以前一样,否则将无法登录)'];
Ejemplo n.º 15
0
 public function testWithoutGroupPrefix()
 {
     ////
     Option::set('admin.name', 'loki');
     Option::set('admin.age', '24');
     $value = Option::get('admin.name');
     $this->assertEquals('loki', $value);
     ////
     $values = Option::getGroup('admin');
     $this->assertEquals('loki', array_get($values, 'admin.name'));
     $this->assertEquals('24', array_get($values, 'admin.age'));
     ////
     $values = Option::getGroup('admin', false);
     $this->assertEquals('loki', array_get($values, 'name'));
     $this->assertEquals('24', array_get($values, 'age'));
 }
Ejemplo n.º 16
0
 /**
  * @param array $contents
  */
 public function __construct($contents = array())
 {
     Option::set($contents, 'type', static::LDAP);
     parent::__construct($contents);
 }
 public function save()
 {
     Option::set(self::TIMETABLE_OPTION_STRING, serialize($this->timetable));
 }
Ejemplo n.º 18
0
 /**
  * Delete a language
  */
 public function deleteLanguage()
 {
     try {
         $language = Language::getByTag($this->tag);
         if (Option::get('main.language') == $this->tag) {
             // Set a new default language
             $newDefault = Language::getAllActive()[0];
             Option::set('main.language', $newDefault->tag);
         }
         $language->delete();
         App::logger()->info('The language ' . $this->tag . ' has been removed');
     } catch (Exception $e) {
         App::logger()->error('An error occured while removing the language ' . $this->tag . ' : ' . $e->getMessage());
     }
 }