Example #1
0
 /**
  * Edit a role
  */
 public function edit()
 {
     $param = array('id' => 'edit-role-form', 'model' => 'Role', 'reference' => array('id' => $this->roleId), 'fieldsets' => array('form' => array('nofieldset' => true, new HiddenInput(array('field' => 'removable', 'default' => 1, 'readonly' => true)), new TextInput(array('field' => 'name', 'maxlength' => 32, 'label' => Lang::get('roles.form-name-label'), 'required' => true)), new ColorInput(array('field' => 'color', 'label' => Lang::get('roles.form-color-label'), 'default' => '#000'))), '_submits' => array(new SubmitInput(array('name' => 'valid', 'value' => Lang::get('main.valid-button'))), new DeleteInput(array('name' => 'delete', 'value' => Lang::get('main.delete-button'), 'notDisplayed' => $this->roleId == -1)), new ButtonInput(array('name' => 'cancel', 'value' => Lang::get('main.cancel-button'), 'onclick' => 'app.dialog("close")')))), 'onsuccess' => 'app.dialog("close"); app.load(app.getUri("list-roles"), {selector : "#admin-roles-tab"});');
     foreach (Language::getAll() as $language) {
         $param['fieldsets']['form'][] = new TextInput(array('name' => "translation[{$language->tag}]", "independant" => true, 'required' => $language->tag == LANGUAGE, "label" => Lang::get("roles.role-label-label", array('lang' => $language->tag)), "default" => Lang::exists("roles.role-" . $this->roleId . "-label") ? Lang::get("roles.role-" . $this->roleId . "-label", array(), 0, $language->tag) : ''));
     }
     $form = new Form($param);
     if (!$form->submitted()) {
         return View::make(Theme::getSelected()->getView("dialogbox.tpl"), array('icon' => 'user', 'title' => Lang::get('roles.form-title'), 'page' => $form));
     } else {
         if ($form->submitted() == "delete") {
             $form->delete(Form::NO_EXIT);
             if ($key) {
                 $key->delete();
             }
             return $form->response(Form::STATUS_SUCCESS);
         } else {
             if ($form->check()) {
                 try {
                     $roleId = $form->register(Form::NO_EXIT);
                     // Create the language key for the translations of the role name
                     foreach (App::request()->getBody('translation') as $tag => $translation) {
                         Language::getByTag($tag)->saveTranslations(array('roles' => array("role-{$roleId}-label" => $translation)));
                     }
                     return $form->response(Form::STATUS_SUCCESS);
                 } catch (Exception $e) {
                     return $form->response(Form::STATUS_ERROR, DEBUG_MODE ? $e->getMessage() : "");
                 }
             }
         }
     }
 }
Example #2
0
 /**
  * Install the application
  */
 public function settings()
 {
     $form = new Form(array('id' => 'install-settings-form', 'labelWidth' => '30em', 'fieldsets' => array('global' => array('legend' => Lang::get('install.settings-global-legend', null, null, $this->language), new TextInput(array('name' => 'title', 'required' => true, 'label' => Lang::get('install.settings-title-label', null, null, $this->language), 'default' => DEFAULT_HTML_TITLE)), new TextInput(array('name' => 'rooturl', 'required' => true, 'label' => Lang::get('install.settings-rooturl-label', null, null, $this->language), 'placeholder' => 'http://', 'default' => getenv('REQUEST_SCHEME') . '://' . getenv('SERVER_NAME'))), new SelectInput(array('name' => 'timezone', 'required' => true, 'options' => array_combine(\DateTimeZone::listIdentifiers(), \DateTimeZone::listIdentifiers()), 'default' => DEFAULT_TIMEZONE, 'label' => Lang::get('install.settings-timezone-label')))), 'database' => array('legend' => Lang::get('install.settings-database-legend', null, null, $this->language), new TextInput(array('name' => 'db[host]', 'required' => true, 'label' => Lang::get('install.settings-db-host-label', null, null, $this->language), 'default' => 'localhost')), new TextInput(array('name' => 'db[username]', 'required' => true, 'label' => Lang::get('install.settings-db-username-label', null, null, $this->language))), new PasswordInput(array('name' => 'db[password]', 'required' => true, 'label' => Lang::get('install.settings-db-password-label', null, null, $this->language), 'pattern' => '/^.*$/')), new TextInput(array('name' => 'db[dbname]', 'required' => true, 'pattern' => '/^\\w+$/', 'label' => Lang::get('install.settings-db-dbname-label', null, null, $this->language))), new TextInput(array('name' => 'db[prefix]', 'default' => 'Hawk', 'pattern' => '/^\\w+$/', 'label' => Lang::get('install.settings-db-prefix-label', null, null, $this->language)))), 'admin' => array('legend' => Lang::get('install.settings-admin-legend', null, null, $this->language), new TextInput(array('name' => 'admin[login]', 'required' => true, 'pattern' => '/^\\w+$/', 'label' => Lang::get('install.settings-admin-login-label', null, null, $this->language))), new EmailInput(array('name' => 'admin[email]', 'required' => true, 'label' => Lang::get('install.settings-admin-email-label', null, null, $this->language))), new PasswordInput(array('name' => 'admin[password]', 'required' => true, 'label' => Lang::get('install.settings-admin-password-label', null, null, $this->language))), new PasswordInput(array('name' => 'admin[passagain]', 'required' => true, 'compare' => 'admin[password]', 'label' => Lang::get('install.settings-admin-passagain-label', null, null, $this->language)))), '_submits' => array(new SubmitInput(array('name' => 'valid', 'value' => Lang::get('install.install-button', null, null, $this->language), 'icon' => 'cog')))), 'onsuccess' => 'location.href = data.rooturl;'));
     if (!$form->submitted()) {
         // Display the form
         $body = View::make(Plugin::current()->getView('settings.tpl'), array('form' => $form));
         return \Hawk\Plugins\Main\MainController::getInstance()->index($body);
     } else {
         // Make the installation
         if ($form->check()) {
             /**
              * Generate Crypto constants
              */
             $salt = Crypto::generateKey(24);
             $key = Crypto::generateKey(32);
             $iv = Crypto::generateKey(16);
             $configMode = 'prod';
             /**
              * Create the database and it tables
              */
             $tmpfile = tempnam(sys_get_temp_dir(), '');
             DB::add('tmp', array(array('host' => $form->getData('db[host]'), 'username' => $form->getData('db[username]'), 'password' => $form->getData('db[password]'))));
             try {
                 DB::get('tmp');
             } catch (DBException $e) {
                 return $form->response(Form::STATUS_ERROR, Lang::get('install.install-connection-error'));
             }
             try {
                 $param = array('{{ $dbname }}' => $form->getData('db[dbname]'), '{{ $prefix }}' => $form->getData('db[prefix]'), '{{ $language }}' => $this->language, '{{ $timezone }}' => $form->getData('timezone'), '{{ $title }}' => Db::get('tmp')->quote($form->getData('title')), '{{ $email }}' => Db::get('tmp')->quote($form->getData('admin[email]')), '{{ $login }}' => Db::get('tmp')->quote($form->getData('admin[login]')), '{{ $password }}' => Db::get('tmp')->quote(Crypto::saltHash($form->getData('admin[password]'), $salt)), '{{ $ip }}' => Db::get('tmp')->quote(App::request()->clientIp()));
                 $sql = strtr(file_get_contents(Plugin::current()->getRootDir() . 'templates/install.sql.tpl'), $param);
                 // file_put_contents($tmpfile, $sql);
                 Db::get('tmp')->query($sql);
                 /**
                  * Create the config file
                  */
                 $param = array('{{ $salt }}' => addcslashes($salt, "'"), '{{ $key }}' => addcslashes($key, "'"), '{{ $iv }}' => addcslashes($iv, "'"), '{{ $configMode }}' => $configMode, '{{ $rooturl }}' => $form->getData('rooturl'), '{{ $host }}' => $form->getData('db[host]'), '{{ $username }}' => $form->getData('db[username]'), '{{ $password }}' => $form->getData('db[password]'), '{{ $dbname }}' => $form->getData('db[dbname]'), '{{ $prefix }}' => $form->getData('db[prefix]'), '{{ $sessionEngine }}' => $form->getData('session'), '{{ $version }}' => $form->getData('version'));
                 $config = strtr(file_get_contents(Plugin::current()->getRootDir() . 'templates/config.php.tpl'), $param);
                 file_put_contents(INCLUDES_DIR . 'config.php', $config);
                 /**
                  * Create etc/dev.php
                  */
                 App::fs()->copy(Plugin::current()->getRootDir() . 'templates/etc-dev.php', ETC_DIR . 'dev.php');
                 /**
                  * Create etc/prod.php
                  */
                 App::fs()->copy(Plugin::current()->getRootDir() . 'templates/etc-prod.php', ETC_DIR . 'prod.php');
                 $form->addReturn('rooturl', $form->getData('rooturl'));
                 return $form->response(Form::STATUS_SUCCESS, Lang::get('install.install-success'));
             } catch (\Exception $e) {
                 return $form->response(Form::STATUS_ERROR, Lang::get('install.install-error'));
             }
         }
     }
 }
Example #3
0
 /**
  * Display the main page of the permission settings
  */
 public function index()
 {
     $permissionGroups = Permission::getAllGroupByPlugin();
     $example = isset($this->roleId) ? array('roleId' => $this->roleId) : array();
     $data = RolePermission::getListByExample(new DBExample($example));
     $values = array();
     foreach ($data as $value) {
         $values[$value->permissionId][$value->roleId] = $value->value;
     }
     $roles = isset($this->roleId) ? array(Role::getById($this->roleId)) : Role::getAll(null, array(), array(), true);
     $param = array('id' => 'permissions-form', 'fieldsets' => array('form' => array(), '_submits' => array(new SubmitInput(array('name' => 'valid', 'value' => Lang::get('main.valid-button'))))));
     foreach ($roles as $role) {
         foreach ($permissionGroups as $group => $permissions) {
             if (Plugin::get($group)) {
                 foreach ($permissions as $permission) {
                     if ($role->id == Role::ADMIN_ROLE_ID) {
                         $default = 1;
                     } elseif (isset($values[$permission->id][$role->id])) {
                         $default = $values[$permission->id][$role->id];
                     } else {
                         $default = 0;
                     }
                     $param['fieldsets']['form'][] = new CheckboxInput(array('name' => "permission-{$permission->id}-{$role->id}", 'disabled' => $role->id == Role::ADMIN_ROLE_ID || $role->id == Role::GUEST_ROLE_ID && !$permission->availableForGuests, 'default' => $default, 'class' => $permission->id == Permission::ALL_PRIVILEGES_ID ? 'select-all' : '', 'nl' => false));
                 }
             }
         }
     }
     $form = new Form($param);
     if (!$form->submitted()) {
         $page = View::make(Plugin::current()->getView("permissions.tpl"), array('permissions' => $permissionGroups, 'fields' => $form->inputs, 'roles' => $roles));
         return NoSidebarTab::make(array('icon' => 'unlock-alt', 'title' => Lang::get('permissions.page-title'), 'page' => $form->wrap($page)));
     } else {
         try {
             foreach ($form->inputs as $name => $field) {
                 if (preg_match('/^permission\\-(\\d+)\\-(\\d+)$/', $name, $match)) {
                     $permissionId = $match[1];
                     $roleId = $match[2];
                     $value = App::request()->getBody($name) ? 1 : 0;
                     if ($roleId != Role::ADMIN_ROLE_ID && !($roleId == Role::GUEST_ROLE_ID && !$permission->availableForGuests)) {
                         $permission = new RolePermission();
                         $permission->set(array('roleId' => $roleId, 'permissionId' => $permissionId, 'value' => $value));
                         $permission->save();
                     }
                 }
             }
             App::logger()->info('Permissions were succesfully updated');
             return $form->response(Form::STATUS_SUCCESS, Lang::get("roles.permissions-update-success"));
         } catch (Exception $e) {
             App::logger()->error('An error occured while updating permissions');
             return $form->response(Form::STATUS_ERROR, DEBUG_MODE ? $e->getMessage() : Lang::get("roles.permissions-update-error"));
         }
     }
 }
Example #4
0
 /**
  * Customize the menu
  */
 public function index()
 {
     $items = MenuItem::getAll();
     $form = new Form(array('id' => 'set-menus-form', 'action' => App::router()->getUri('set-menu'), 'inputs' => array(new HiddenInput(array('name' => 'data', 'default' => json_encode($items, JSON_NUMERIC_CHECK), 'attributes' => array('e-value' => 'JSON.stringify(items.valueOf())'))), new SubmitInput(array('name' => 'valid', 'value' => Lang::get('main.valid-button')))), 'onsuccess' => 'app.refreshMenu()'));
     if (!$form->submitted()) {
         $this->addKeysToJavaScript($this->_plugin . '.plugins-advert-menu-changed');
         return View::make(Plugin::current()->getView('sort-main-menu.tpl'), array('form' => $form));
     } else {
         try {
             $items = MenuItem::getAll('id');
             $data = json_decode($form->getData('data'), true);
             foreach ($data as $line) {
                 $item = $items[$line['id']];
                 $item->set(array('active' => $line['active'], 'parentId' => $line['parentId'], 'order' => $line['order']));
                 $item->save();
             }
             return $form->response(Form::STATUS_SUCCESS, Lang::get($this->_plugin . '.sort-menu-success'));
         } catch (Exception $e) {
             return $form->response(Form::STATUS_ERROR, DEBUG_MODE ? $e->getMessage() : Lang::get($this->_plugin . '.sort-menu-error'));
         }
     }
 }
Example #5
0
 /**
  * Create a custom theme
  */
 public function create()
 {
     $form = new Form(array('id' => 'create-theme-form', 'labelWidth' => '20em', 'fieldsets' => array('form' => array(new TextInput(array('name' => 'name', 'required' => true, 'pattern' => '/^[\\w\\-]+$/', 'label' => Lang::get($this->_plugin . '.theme-create-name-label'))), new TextInput(array('name' => 'title', 'required' => true, 'label' => Lang::get($this->_plugin . '.theme-create-title-label'))), new SelectInput(array('name' => 'extends', 'invitation' => '-', 'options' => array_map(function ($theme) {
         return $theme->getTitle();
     }, Theme::getAll()), 'label' => Lang::get($this->_plugin . '.theme-create-extends-label'))), new TextInput(array('name' => 'version', 'required' => true, 'pattern' => '/^(\\d+\\.){2,3}\\d+$/', 'label' => Lang::get($this->_plugin . '.theme-create-version-label'), 'default' => '0.0.1')), new TextInput(array('name' => 'author', 'label' => Lang::get($this->_plugin . '.theme-create-author-label')))), 'submits' => array(new SubmitInput(array('name' => 'valid', 'value' => Lang::get('main.valid-button'))), new ButtonInput(array('name' => 'cancel', 'value' => Lang::get('main.cancel-button'), 'onclick' => 'app.dialog("close")')))), 'onsuccess' => 'app.dialog("close"); app.load(app.getUri("available-themes"), { selector : $("#admin-themes-select-tab")} );'));
     if (!$form->submitted()) {
         // Display the form
         return View::make(Theme::getSelected()->getView('dialogbox.tpl'), array('title' => Lang::get($this->_plugin . '.theme-create-title'), 'icon' => 'picture-o', 'page' => $form));
     } else {
         if ($form->check()) {
             $dir = THEMES_DIR . $form->getData('name') . '/';
             if (is_dir($dir)) {
                 $form->error('name', Lang::get($this->_plugin . '.theme-create-name-already-exists-error'));
                 return $form->response(Form::STATUS_CHECK_ERROR, Lang::get($this->_plugin . '.theme-create-name-already-exists-error'));
             }
             // The theme can be created
             try {
                 // Create the main directory
                 if (!mkdir($dir)) {
                     throw new \Exception('Impossible to create the directory ' . $dir);
                 }
                 // Create the directory views
                 if (!mkdir($dir . 'views')) {
                     throw new \Exception('Impossible to create the directory ' . $dir . 'views');
                 }
                 // Get the parent theme
                 $parent = null;
                 if ($form->getData('extends')) {
                     $parent = Theme::get($form->getData('extends'));
                 }
                 // Create the file manifest.json
                 $conf = array('title' => $form->getData('title'), 'version' => $form->getData('version'), 'author' => $form->getData('author'));
                 if ($parent) {
                     $conf['extends'] = $parent->getName();
                 }
                 if (file_put_contents($dir . Theme::MANIFEST_BASENAME, json_encode($conf, JSON_PRETTY_PRINT)) === false) {
                     throw new \Exception('Impossible to create the file ' . $dir . Theme::MANIFEST_BASENAME);
                 }
                 $theme = Theme::get($form->getData('name'));
                 if ($parent) {
                     // The theme extends another one, make a copy of the parent theme except manifest.json and views
                     foreach (glob($parent->getRootDir() . '*') as $element) {
                         if (!in_array(basename($element), array(Theme::MANIFEST_BASENAME, 'views'))) {
                             App::fs()->copy($element, $theme->getRootDir());
                         }
                     }
                 } else {
                     // Create the directory less
                     if (!mkdir($dir . 'less')) {
                         throw new \Exception('Impossible to create the directory ' . $dir . 'less');
                     }
                     // Create the file theme.less
                     if (!touch($theme->getBaseLessFile())) {
                         throw new \Exception('Impossible to create the file ' . $theme->getBaseLessFile());
                     }
                 }
                 return $form->response(Form::STATUS_SUCCESS, Lang::get($this->_plugin . '.theme-create-success'));
             } catch (\Exception $e) {
                 if (is_dir($dir)) {
                     App::fs()->remove($dir);
                 }
                 return $form->response(Form::STATUS_ERROR, DEBUG_MODE ? $e->getMessage() : Lang::get($this->_plugin . '.theme-create-error'));
             }
         }
     }
 }
Example #6
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 . " > " . $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'));
         }
     }
 }
Example #7
0
 /**
  * Edit a profile question
  */
 public function edit()
 {
     $q = ProfileQuestion::getByName($this->name);
     $roles = Role::getAll();
     // Get roles associate to this ProfileQuestion in json parameters
     if ($q) {
         $attributesRoles = $q->getRoles();
     } else {
         $attributesRoles = array();
     }
     $allowedTypes = ProfileQuestion::$allowedTypes;
     $param = array('id' => 'profile-question-form', 'model' => 'ProfileQuestion', 'reference' => array('name' => $this->name), 'labelWidth' => '200px', 'fieldsets' => array('general' => array('legend' => Lang::get($this->_plugin . '.profile-question-form-general-legend'), new TextInput(array('name' => 'name', 'unique' => true, 'maxlength' => 32, 'label' => Lang::get($this->_plugin . '.profile-question-form-name-label') . ' ' . Lang::get($this->_plugin . '.profile-question-form-name-description'), 'required' => true)), new SelectInput(array('name' => 'type', 'required' => true, 'options' => array_combine($allowedTypes, array_map(function ($type) {
         return Lang::get($this->_plugin . '.profile-question-form-type-' . $type);
     }, $allowedTypes)), 'label' => Lang::get($this->_plugin . '.profile-question-form-type-label'), 'attributes' => array('e-value' => 'type'))), new CheckboxInput(array('name' => 'displayInRegister', 'label' => Lang::get($this->_plugin . '.profile-question-form-displayInRegister-label'))), new CheckboxInput(array('name' => 'displayInProfile', 'label' => Lang::get($this->_plugin . '.profile-question-form-displayInProfile-label'))), new HiddenInput(array('name' => 'editable', 'value' => 1))), 'parameters' => array('legend' => Lang::get($this->_plugin . '.profile-question-form-parameters-legend'), new ObjectInput(array('name' => 'parameters', 'id' => 'question-form-parameters', 'hidden' => true, 'attributes' => array('e-value' => 'parameters'))), new CheckboxInput(array('name' => 'required', 'independant' => true, 'label' => Lang::get($this->_plugin . '.profile-question-form-required-label'), 'attributes' => array('e-value' => "required"))), new CheckboxInput(array('name' => 'readonly', 'independant' => true, 'label' => Lang::get($this->_plugin . '.profile-question-form-readonly-label'), 'attributes' => array('e-value' => "readonly"))), new DatetimeInput(array('name' => 'minDate', 'independant' => true, 'label' => Lang::get($this->_plugin . '.profile-question-form-minDate-label'), 'attributes' => array('e-value' => "minDate"))), new DatetimeInput(array('name' => 'maxDate', 'independant' => true, 'label' => Lang::get($this->_plugin . '.profile-question-form-maxDate-label'), 'attributes' => array('e-value' => "maxDate"))), new HtmlInput(array('name' => 'parameters-description', 'value' => '<p class="alert alert-info">' . Icon::make(array('icon' => 'exclamation-circle')) . Lang::get($this->_plugin . '.profile-question-form-translation-description') . '</p>')), new TextInput(array('name' => 'label', 'required' => true, 'independant' => true, 'label' => Lang::get($this->_plugin . '.profile-question-form-label-label'), 'default' => $this->name != '_new' ? Lang::get($this->_plugin . '.profile-question-' . $this->name . '-label') : '')), new TextareaInput(array('name' => 'options', 'independant' => true, 'required' => App::request()->getBody('type') == 'select' || App::request()->getBody('type') == 'radio', 'label' => Lang::get($this->_plugin . '.profile-question-form-options-label') . '<br />' . Lang::get($this->_plugin . '.profile-question-form-options-description'), 'labelClass' => 'required', 'attributes' => array('e-value' => "options"), 'cols' => 20, 'rows' => 10))), '_submits' => array(new SubmitInput(array('name' => 'valid', 'value' => Lang::get('main.valid-button'))), new DeleteInput(array('name' => 'delete', 'value' => Lang::get('main.delete-button'), 'notDisplayed' => $this->name == '_new')), new ButtonInput(array('name' => 'cancel', 'value' => Lang::get('main.cancel-button'), 'onclick' => 'app.dialog("close")')))), 'onsuccess' => 'app.dialog("close"); app.load(app.getUri("profile-questions"), {selector : "#admin-questions-tab"})');
     $form = new Form($param);
     if (!$form->submitted()) {
         $this->addJavaScript($this->getPlugin()->getJsUrl('question-form.js'));
         $content = View::make(Plugin::current()->getView("question-form.tpl"), array('form' => $form));
         return View::make(Theme::getSelected()->getView("dialogbox.tpl"), array('title' => Lang::get($this->_plugin . ".users-questions-title"), 'icon' => 'file-word-o', 'page' => $content));
     } else {
         if ($form->submitted() == "delete") {
             $this->delete();
             return $form->response(Form::STATUS_SUCCESS);
         } else {
             if ($form->check()) {
                 $form->register(Form::NO_EXIT);
                 Language::current()->saveTranslations(array('admin' => array('profile-question-' . $form->getData("name") . '-label' => App::request()->getBody('label'))));
                 // Create the lang options
                 if ($form->inputs['options']->required) {
                     $keys = array('admin' => array());
                     foreach (explode(PHP_EOL, $form->getData("options")) as $i => $option) {
                         if (!empty($option)) {
                             $keys['admin']['profile-question-' . $form->getData("name") . '-option-' . $i] = trim($option);
                         }
                     }
                     Language::current()->saveTranslations($keys);
                 }
                 return $form->response(Form::STATUS_SUCCESS);
             }
         }
     }
 }
Example #8
0
 /**
  * Create a new plugin structure
  */
 public function create()
 {
     $form = new Form(array('id' => 'new-plugin-form', 'labelWidth' => '20em', 'fieldsets' => array('form' => array(new HtmlInput(array('name' => 'intro', 'value' => '<div class="alert alert-info">' . Lang::get($this->_plugin . '.new-plugin-intro') . '</div>')), new TextInput(array('name' => 'name', 'required' => true, 'pattern' => '/^[\\w\\-]+$/', 'label' => Lang::get($this->_plugin . '.new-plugin-name-label'))), new TextInput(array('name' => 'title', 'required' => true, 'label' => Lang::get($this->_plugin . '.new-plugin-title-label'))), new TextareaInput(array('name' => 'description', 'label' => Lang::get($this->_plugin . '.new-plugin-description-label'))), new TextInput(array('name' => 'version', 'required' => true, 'pattern' => '/^(\\d+\\.){2,3}\\d+$/', 'label' => Lang::get($this->_plugin . '.new-plugin-version-label'), 'default' => '0.0.1')), new TextInput(array('name' => 'author', 'label' => Lang::get($this->_plugin . '.new-plugin-author-label')))), 'submits' => array(new SubmitInput(array('name' => 'valid', 'value' => Lang::get('main.valid-button'))), new ButtonInput(array('name' => 'cancel', 'value' => Lang::get('main.cancel-button'), 'onclick' => 'app.dialog("close")')))), 'onsuccess' => 'app.dialog("close"); app.load(app.getUri("manage-plugins"));'));
     if (!$form->submitted()) {
         // Display the form
         return View::make(Theme::getSelected()->getView('dialogbox.tpl'), array('title' => Lang::get($this->_plugin . '.new-plugin-title'), 'icon' => 'plug', 'page' => $form));
     } else {
         // Create the plugin
         if ($form->check()) {
             if (in_array($form->getData('name'), Plugin::$forbiddenNames)) {
                 $message = Lang::get($this->_plugin . '.new-plugin-forbidden-name', array('forbidden' => implode(', ', Plugin::$forbiddenNames)));
                 $form->error('name', $message);
                 return $form->response(Form::STATUS_CHECK_ERROR, $message);
             }
             $namespace = Plugin::getNamespaceByName($form->getData('name'));
             // Check the plugin does not exists
             foreach (Plugin::getAll(false) as $plugin) {
                 if ($namespace === $plugin->getNamespace()) {
                     // A plugin with the same name already exists
                     $form->error('name', Lang::get($this->_plugin . '.new-plugin-already-exists-error'));
                     return $form->response(Form::STATUS_CHECK_ERROR, Lang::get($this->_plugin . '.new-plugin-already-exists-error'));
                 }
             }
             // The plugin can be created
             $dir = PLUGINS_DIR . $form->getData('name') . '/';
             try {
                 // Create the directories structure
                 if (!mkdir($dir)) {
                     throw new \Exception('Impossible to create the directory ' . $dir);
                 }
                 foreach (array('controllers', 'models', 'lib', 'lang', 'views', 'static', 'static/less', 'static/js', 'static/img', 'widgets') as $subdir) {
                     if (!mkdir($dir . $subdir, 0755, true)) {
                         throw new \Exception('Impossible to create the directory ' . $dir . $subdir);
                     }
                 }
                 // Create the file manifest.json
                 $conf = array('title' => $form->getData('title'), 'description' => $form->getData('description'), 'version' => $form->getData('version'), 'author' => $form->getData('author'), 'dependencies' => array());
                 if (file_put_contents($dir . Plugin::MANIFEST_BASENAME, json_encode($conf, JSON_PRETTY_PRINT)) === false) {
                     throw new \Exception('Impossible to create the file ' . Plugin::MANIFEST_BASENAME);
                 }
                 $plugin = Plugin::get($form->getData('name'));
                 $namespace = $plugin->getNamespace();
                 // Create the file start.php
                 $start = str_replace(array('{{ $namespace }}', '{{ $name }}'), array($namespace, $plugin->getName()), file_get_contents(Plugin::current()->getRootDir() . 'templates/start.tpl'));
                 if (file_put_contents($dir . 'start.php', $start) === false) {
                     throw new \Exceptio('Impossible to create the file start.php');
                 }
                 // Create the file Installer.php
                 $installer = str_replace(array('{{ $namespace }}', '{{ $name }}'), array($namespace, $plugin->getName()), file_get_contents(Plugin::current()->getRootDir() . 'templates/installer.tpl'));
                 if (file_put_contents($dir . 'Installer.php', $installer) === false) {
                     throw new \Exception('Impossible to create the file classes/Installer.php');
                 }
                 // Create the file BaseController.php
                 $controller = str_replace('{{ $namespace }}', $namespace, file_get_contents(Plugin::current()->getRootDir() . 'templates/base-controller.tpl'));
                 if (file_put_contents($dir . 'controllers/BaseController.php', $controller) === false) {
                     throw new \Exception('Impossible to create the file controllers/BaseController.php');
                 }
                 // Create the language file
                 $language = file_get_contents(Plugin::current()->getRootDir() . 'templates/lang.tpl');
                 if (file_put_contents($dir . 'lang/' . $plugin->getName() . '.en.lang', $language) === false) {
                     throw new \Exception('Impossible to create the file lang/' . $plugin->getName() . '.en.lang');
                 }
                 // Create the README file
                 if (touch($dir . 'README.md') === false) {
                     throw new \Exception('Impossible to create the README file');
                 }
                 return $form->response(Form::STATUS_SUCCESS, Lang::get($this->_plugin . '.new-plugin-success'));
             } catch (\Exception $e) {
                 if (is_dir($dir)) {
                     App::fs()->remove($dir);
                 }
                 return $form->response(Form::STATUS_ERROR, DEBUG_MODE ? $e->getMessage() : Lang::get($this->_plugin . '.new-plugin-error'));
             }
         }
     }
 }
Example #9
0
 /**
  * Change the current user password
  */
 public function changePassword()
 {
     $params = array('id' => 'update-password-form', 'fieldsets' => array('form' => array(new PasswordInput(array('name' => 'current-password', 'label' => Lang::get($this->_plugin . '.update-password-current-password-label'), 'required' => true)), new PasswordInput(array('name' => 'new-password', 'required' => true, 'label' => Lang::get($this->_plugin . '.update-password-new-password-label'))), new PasswordInput(array('name' => 'password-confirm', 'required' => true, 'label' => Lang::get($this->_plugin . '.update-password-new-password-confirm-label'), 'compare' => 'new-password'))), '_submits' => array(new SubmitInput(array('name' => 'valid', 'value' => Lang::get($this->_plugin . '.valid-button'))), new ButtonInput(array('name' => 'cancel', 'value' => Lang::get($this->_plugin . '.cancel-button'), 'onclick' => 'app.dialog("close")')))), 'onsuccess' => 'app.dialog("close")');
     $form = new Form($params);
     if (!$form->submitted()) {
         return View::make(Theme::getSelected()->getView("dialogbox.tpl"), array('title' => Lang::get($this->_plugin . '.update-password-title'), 'icon' => 'lock', 'page' => $form));
     } else {
         if ($form->check()) {
             $me = Session::getUser();
             if ($me->password != Crypto::saltHash($form->getData('current-password'))) {
                 return $form->response(Form::STATUS_ERROR, Lang::get($this->_plugin . '.update-password-bad-current-password'));
             }
             try {
                 $me->set('password', Crypto::saltHash($form->getData('new-password')));
                 $me->save();
                 return $form->response(Form::STATUS_SUCCESS, Lang::get($this->_plugin . '.update-password-success'));
             } catch (Exception $e) {
                 return $form->response(Form::STATUS_ERROR, DEBUG_MODE ? $e->getMessage() : Lang::get($this->_plugin . '.update-password-error'));
             }
         }
     }
 }
Example #10
0
 /**
  * Import translation files
  */
 public function import()
 {
     $param = array('id' => 'language-import-form', 'upload' => true, 'fieldsets' => array('form' => array('nofieldset' => true, new HtmlInput(array('value' => Lang::get('language.import-file-description'))), new FileInput(array('name' => 'files[]', 'independant' => true, 'multiple' => true, 'required' => true, 'label' => Lang::get('language.lang-form-import-label')))), '_submits' => array(new SubmitInput(array('name' => 'import', 'icon' => 'upload', 'value' => Lang::get('main.import-button'))), new ButtonInput(array('name' => 'cancel', 'value' => Lang::get('main.cancel-button'), 'onclick' => 'app.dialog("close")')))), 'onsuccess' => 'app.dialog("close"); app.lists["language-key-list"].refresh()');
     $form = new Form($param);
     if (!$form->submitted()) {
         return View::make(Theme::getSelected()->getView('dialogbox.tpl'), array('icon' => 'flag', 'title' => Lang::get('language.import-form-title'), 'page' => $form));
     } else {
         if ($form->check()) {
             try {
                 $files = App::request()->getFiles('files');
                 foreach ($files['name'] as $i => $filename) {
                     // Check the filename is correct
                     if (!preg_match('/^([\\w\\-]+)\\.([a-z]{2})\\.lang$/', $filename, $matches)) {
                         throw new Exception(Lang::get('language.import-file-name-error'));
                     }
                     list($m, $plugin, $lang) = $matches;
                     // Check the content of the file is valid
                     $tmpfile = $files['tmp_name'][$i];
                     if (($translations = parse_ini_file($tmpfile)) === false) {
                         throw new Exception(Lang::get('language.import-file-format-error'));
                     }
                     Language::getByTag($lang)->saveTranslations(array($plugin => $translations));
                     unlink($tmpfile);
                 }
                 App::logger()->info('Language files were successfully imported');
                 return $form->response(Form::STATUS_SUCCESS);
             } catch (Exception $e) {
                 App::logger()->error('An error occured whiel importing language files : ' . $e->getMessage());
                 $form->error('files[]', $e->getMessage());
                 return $form->response(Form::STATUS_CHECK_ERROR);
             }
         }
     }
 }
Example #11
0
 /**
  * Display and treat the form to reset the user's password
  */
 public function resetPassword()
 {
     $form = new Form(array('id' => 'reset-password-form', 'fieldsets' => array('form' => array(new TextInput(array('name' => 'code', 'required' => true, 'label' => Lang::get($this->_plugin . '.reset-pwd-form-code-label'))), new PasswordInput(array('name' => 'password', 'required' => true, 'label' => Lang::get($this->_plugin . '.reset-pwd-form-password-label'), 'encrypt' => array('\\Hawk\\Crypto', 'saltHash'))), new PasswordInput(array('name' => 'confirmation', 'required' => true, 'compare' => 'password', 'label' => Lang::get($this->_plugin . '.reset-pwd-form-confirmation-label')))), 'submits' => array(new SubmitInput(array('name' => 'valid', 'label' => Lang::get($this->_plugin . '.valid-button'))), new ButtonInput(array('name' => 'cancel', 'label' => Lang::get($this->_plugin . '.cancel-button'), 'href' => App::router()->getUri('login'), 'target' => 'dialog')))), 'onsuccess' => 'app.dialog(app.getUri("login"));'));
     if (!$form->submitted()) {
         return Dialogbox::make(array('title' => Lang::get($this->_plugin . '.reset-pwd-form-title'), 'icon' => 'lock-alt', 'page' => $form));
     } else {
         if ($form->check()) {
             // Check the verficiation code
             if ($form->getData('code') !== Crypto::aes256Decode(App::session()->getData('forgottenPassword.code'))) {
                 $form->error('code', Lang::get($this->_plugin . '.reset-pwd-form-bad-verification-code'));
                 return $form->response(Form::STATUS_CHECK_ERROR);
             }
             try {
                 $user = User::getByEmail(App::session()->getData('forgottenPassword.email'));
                 if ($user) {
                     $user->set('password', $form->inputs['password']->dbvalue());
                     $user->save();
                 } else {
                     return $form->response(Form::STATUS_ERROR, App::session()->getData('forgottenPassword.email'));
                 }
                 return $form->response(Form::STATUS_SUCCESS, Lang::get($this->_plugin . '.reset-pwd-form-success'));
             } catch (\Exception $e) {
                 return $form->response(Form::STATUS_ERROR, Lang::get($this->_plugin . '.reset-pwd-form-error'));
             }
         }
     }
 }