예제 #1
0
 /**
  * Display the parameter
  *
  * @return string The HTML result to display
  */
 public function __toString()
 {
     if ($this->notDisplayed) {
         return '';
     }
     return View::make(Theme::getSelected()->getView(Form::VIEWS_DIR . 'form-fieldset.tpl'), array('fieldset' => $this));
 }
예제 #2
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() : "");
                 }
             }
         }
     }
 }
예제 #3
0
 /**
  * Display the tab
  *
  * @param array $data The data to inject in the view
  *
  * @return string The generated HTML
  */
 public static function make($data)
 {
     if (is_array($data['page']) && isset($data['page']['content'])) {
         $data['page'] = $data['page']['content'];
     }
     return parent::make(Theme::getSelected()->getView('tabs-layout/tabs-no-sidebar.tpl'), $data);
 }
예제 #4
0
 /**
  * Display the input
  *
  * @return string The dislayed HTML
  */
 public function display()
 {
     if (!empty($this->notDisplayed)) {
         return '';
     }
     $param = get_object_vars($this);
     $param["class"] .= " form-button";
     if (empty($param['icon']) && isset(self::$defaultIcons[$this->name])) {
         $param['icon'] = self::$defaultIcons[$this->name];
     }
     $param = array_filter($param, function ($v) {
         return !empty($v);
     });
     if (!isset($param['label'])) {
         $param['label'] = $this->value;
     }
     $param['type'] = static::TYPE;
     if (!empty($param['href'])) {
         $param['data-href'] = $param['href'];
         unset($param['href']);
     }
     if (!empty($param['target'])) {
         $param['data-target'] = $param['target'];
         unset($param['target']);
     }
     $param = array_intersect_key($param, array_flip(array('id', 'class', 'icon', 'label', 'type', 'name', 'onclick', 'style', 'data-href', 'data-target', 'title')));
     $param = array_merge($param, $this->attributes);
     /*** Set the attribute and text to the span inside the button ***/
     return View::make(Theme::getSelected()->getView('button.tpl'), array('class' => isset($param['class']) ? $param['class'] : '', 'param' => $param, 'icon' => isset($param['icon']) ? $param['icon'] : '', 'label' => isset($param['label']) ? $param['label'] : '', 'textStyle' => isset($param['textStyle']) ? $param['textStyle'] : ''));
 }
예제 #5
0
 /**
  * Display the tab
  *
  * @param array $data The data to inject in the view
  *
  * @return string The generated HTML
  */
 public static function make($data)
 {
     if (!isset($data['sidebar']['class'])) {
         $data['sidebar']['class'] = 'col-md-3 col-lg-2';
     }
     if (!isset($data['page']['class'])) {
         $data['page']['class'] = 'col-md-9 col-lg-10';
     }
     return parent::make(Theme::getSelected()->getView('tabs-layout/tabs-sidebar-left.tpl'), $data);
 }
예제 #6
0
파일: Panel.php 프로젝트: elvyrra/hawk
 /**
  * Display the panem
  *
  * @param array $data The data to inject in the view
  *
  * @return string The generated HTML
  */
 public static function make($data)
 {
     if (empty($data['id'])) {
         $data['id'] = uniqid();
     }
     if (empty($data['type'])) {
         $data['type'] = 'info';
     }
     return parent::make(Theme::getSelected()->getView('panel.tpl'), $data);
 }
예제 #7
0
파일: Icon.php 프로젝트: elvyrra/hawk
 /**
  * Display the icon
  *
  * @param array $data The data to inject in the view
  *
  * @return string The generated HTML
  */
 public static function make($data)
 {
     if (!isset($data['size'])) {
         $data['size'] = '';
     }
     if (!isset($data['class'])) {
         $data['class'] = '';
     }
     $data['param'] = $data;
     unset($data['param']['size'], $data['param']['class'], $data['param']['icon']);
     return parent::make(Theme::getSelected()->getView('icon.tpl'), $data);
 }
예제 #8
0
파일: Tabs.php 프로젝트: elvyrra/hawk
 /**
  * Display the tabset
  *
  * @param array $data The data to inject in the view
  *
  * @return string The generated HTML
  */
 public static function make($data)
 {
     if (empty($data['id'])) {
         $data['id'] = uniqid();
     }
     foreach ($data['tabs'] as $i => &$tab) {
         if (empty($tab['id'])) {
             $tab['id'] = uniqid();
         }
         if (empty($data['selected'])) {
             $data['selected'] = $i;
         }
     }
     return parent::make(Theme::getSelected()->getView('tabs.tpl'), $data);
 }
예제 #9
0
파일: Accordion.php 프로젝트: elvyrra/hawk
 /**
  * Display the accordion
  *
  * @param array $data The data to inject in the view
  *
  * @return string The generated HTML
  */
 public static function make($data)
 {
     if (empty($data['id'])) {
         $data['id'] = uniqid();
     }
     foreach ($data['panels'] as $i => &$panel) {
         if (empty($panel['id'])) {
             $panel['id'] = uniqid();
         }
         if (empty($data['selected'])) {
             $data['selected'] = $i;
         }
     }
     return parent::make(Theme::getSelected()->getView('accordion.tpl'), $data);
 }
예제 #10
0
 /**
  * Create or edit an user
  */
 public function edit()
 {
     $roles = array_map(function ($role) {
         return $role->getLabel();
     }, Role::getAll('id'));
     $user = User::getByUsername($this->username);
     $param = array('id' => 'user-form', 'upload' => true, 'model' => 'User', 'reference' => array('username' => $this->username), 'fieldsets' => array('general' => array('nofieldset' => true, new TextInput(array('name' => 'username', 'required' => true, 'unique' => true, 'readonly' => $user && $user->id !== App::session()->getUser()->id, 'insert' => !$user || $user->id === App::session()->getUser()->id, 'label' => Lang::get($this->_plugin . '.user-form-username-label'))), new EmailInput(array('name' => 'email', 'required' => true, 'unique' => true, 'readonly' => $user && $user->id !== App::session()->getUser()->id, 'insert' => !$user || $user->id !== App::session()->getUser()->id, 'label' => Lang::get($this->_plugin . '.user-form-email-label'))), new CheckboxInput(array('name' => 'active', 'label' => Lang::get($this->_plugin . '.user-form-active-label'))), new SelectInput(array('name' => 'roleId', 'options' => $roles, 'label' => Lang::get($this->_plugin . '.user-form-roleId-label'))), $user ? null : new PasswordInput(array('name' => 'password', 'required' => true, 'label' => Lang::get($this->_plugin . '.user-form-password-label'), 'encrypt' => array('Hawk\\Crypto', 'saltHash'))), $user ? null : new PasswordInput(array('name' => 'passagain', 'label' => Lang::get($this->_plugin . '.user-form-passagain-label'), 'required' => true, 'compare' => 'password', 'independant' => true)), new HiddenInput(array('name' => 'createTime', 'default' => time()))), '_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' => !($user && $user->isRemovable()))), new ButtonInput(array('name' => 'cancel', 'value' => Lang::get('main.cancel-button'), 'onclick' => 'app.dialog("close")')))), 'onsuccess' => 'app.dialog("close"); app.lists["admin-users-list"].refresh();');
     $form = new Form($param);
     if (!$form->submitted()) {
         return View::make(Theme::getSelected()->getView("dialogbox.tpl"), array('page' => $form, 'title' => Lang::get($this->_plugin . '.user-form-title'), 'icon' => 'user'));
     } else {
         if ($form->submitted() == "delete") {
             $this->remove();
         } else {
             if ($form->check()) {
                 return $form->register();
             }
         }
     }
 }
예제 #11
0
 /**
  * Display the widget
  *
  * @return string The generated HTML
  */
 public function display()
 {
     $form = new Form(array('id' => 'search-themes-form', 'method' => 'get', 'action' => App::router()->getUri('search-themes'), 'inputs' => array(new TextInput(array('name' => 'search', 'required' => true, 'default' => App::request()->getParams('search'), 'placeholder' => Lang::get('admin.search-theme-form-search-label'))), new SubmitInput(array('name' => 'valid', 'value' => Lang::get('admin.search-theme-form-submit-btn'), 'icon' => 'search')))));
     return View::make(Theme::getSelected()->getView('box.tpl'), array('content' => $form, 'title' => Lang::get('admin.search-theme-form-title'), 'icon' => 'search'));
 }
예제 #12
0
파일: ItemList.php 프로젝트: elvyrra/hawk
 /**
  * Get the list views files
  */
 private function getViews()
 {
     if (empty($this->tpl)) {
         $this->tpl = Theme::getSelected()->getView('item-list/container.tpl');
     }
     if (empty($this->navigationBarTpl)) {
         $this->navigationBarTpl = Theme::getSelected()->getView('item-list/navigation-bar.tpl');
     }
     if (empty($this->listTpl)) {
         $this->listTpl = Theme::getSelected()->getView('item-list/list.tpl');
     }
     if (empty($this->resultTpl)) {
         $this->resultTpl = Theme::getSelected()->getView('item-list/result.tpl');
     }
 }
예제 #13
0
 /**
  * Display the widget
  *
  * @return string The generated HTML
  */
 public function display()
 {
     $filters = $this->getFilters();
     $form = new Form(array('id' => 'user-filter-form', 'fieldsets' => array('form' => array(new RadioInput(array('name' => 'status', 'labelWidth' => '100%', 'label' => Lang::get('admin.user-filter-status-label'), 'layout' => 'vertical', 'value' => isset($filters['status']) ? $filters['status'] : -1, 'options' => array('-1' => Lang::get('admin.user-filter-status-all'), '1' => Lang::get('admin.user-filter-status-active'), '0' => Lang::get('admin.user-filter-status-inactive'))))))));
     return View::make(Theme::getSelected()->getView("box.tpl"), array('content' => $form, 'title' => Lang::get('admin.user-filter-legend'), 'icon' => 'filter'));
 }
예제 #14
0
 /**
  * Handle an non catched exception
  *
  * @param Exception $e The throwed exception
  */
 public function exception($e)
 {
     $param = array('level' => 'danger', 'icon' => 'excalamation-circle', 'title' => get_class($e), 'message' => $e->getMessage(), 'trace' => $e->getTrace());
     App::logger()->error($e->getMessage());
     if (App::request()->getWantedType() === "json") {
         throw new InternalErrorException($e->getMessage());
     } else {
         throw new InternalErrorException(View::make(Theme::getSelected()->getView('error.tpl'), $param));
     }
 }
예제 #15
0
 /**
  * Get the displayed value
  *
  * @param array $lineIndex The index of the line in the list results to display
  *
  * @return string The HTML result to display
  */
 public function displayCell($lineIndex)
 {
     $line = $this->list->results[$lineIndex];
     $name = $this->name;
     $cell = new \StdClass();
     foreach (self::$callableProperties as $prop) {
         if (!is_null($this->{$prop}) && is_callable($this->{$prop})) {
             $func = $this->{$prop};
             $cell->{$prop} = $func(isset($line->{$name}) ? $line->{$name} : null, $this, $line);
         } else {
             $cell->{$prop} = $this->{$prop};
         }
     }
     // Compute the cell content
     if (isset($cell->display)) {
         $cell->content = $cell->display;
     } else {
         $cell->content = isset($line->{$name}) ? $line->{$name} : '';
     }
     // Add a unit to the displayed value
     if ($cell->unit && !$cell->content) {
         $cell->content .= ' ' . $cell->unit;
     }
     return View::make(Theme::getSelected()->getView('item-list/result-cell.tpl'), array('cell' => $cell, 'field' => $this));
 }
예제 #16
0
 /**
  * Display the widget
  *
  * @return string The generated HTML
  */
 public function display()
 {
     return View::make(Theme::getSelected()->getView("box.tpl"), array('title' => Lang::get('admin.theme-add-title'), 'icon' => 'plus', 'content' => $this->form));
 }
예제 #17
0
파일: Form.php 프로젝트: elvyrra/hawk
 /**
  * Display the form
  *
  * @return string The HTML result of form displaying
  */
 public function display()
 {
     try {
         if (empty($this->fieldsets)) {
             // Generate a fake fieldset, to keep the same engine for forms that have fieldsets or not
             $this->addFieldset(new FormFieldset($this, ''));
             foreach ($this->inputs as $name => $input) {
                 $this->fieldsets['']->inputs[$name] =& $input;
             }
         }
         // Generate the form content
         $content = View::make(Theme::getSelected()->getView(Form::VIEWS_DIR . 'form-content.tpl'), array('form' => $this, 'column' => 0));
         // Wrap the content with the form tag
         return $this->wrap($content);
     } catch (\Exception $e) {
         App::errorHandler()->exception($e);
     }
 }
예제 #18
0
파일: Dialogbox.php 프로젝트: elvyrra/hawk
 /**
  * Display the dialogbox
  *
  * @param array $data The data to inject in the view
  *
  * @return string The generated HTML
  */
 public static function make($data)
 {
     return parent::make(Theme::getSelected()->getView('dialogbox.tpl'), $data);
 }
예제 #19
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'));
             }
         }
     }
 }
예제 #20
0
파일: Mail.php 프로젝트: elvyrra/hawk
 /**
  * Prepare the content to send in the email
  */
 private function prepareContent()
 {
     if ($this->useDefaultTemplate) {
         // Create the email content
         $cssVariables = Theme::getSelected()->getEditableVariables();
         $values = Theme::getSelected()->getVariablesCustomValues();
         $css = array();
         foreach ($cssVariables as $var) {
             $css[$var['name']] = isset($values[$var['name']]) ? $values[$var['name']] : $var['default'];
         }
         // Format the email
         $emailHtml = View::make(Theme::getSelected()->getView('email.tpl'), array('css' => $css, 'title' => $this->title, 'content' => $this->content, 'logo' => Option::get('main.logo') ? Plugin::get('main')->getUserfilesUrl(Option::get('main.logo')) : Plugin::get('main')->getStaticUrl('img/hawk-logo.png')));
         $this->html($emailHtml);
     }
 }
예제 #21
0
 /**
  * Display the widget
  *
  * @return string The generated HTML
  */
 public function display()
 {
     return View::make(Theme::getSelected()->getView("box.tpl"), array('title' => Lang::get('language.filter-filters-legend'), 'icon' => 'filter', 'content' => $this->form));
 }
예제 #22
0
파일: Plugin.php 프로젝트: elvyrra/hawk
 /**
  * Return the full path of a view in the plugin
  *
  * @param string $view The basename of the view file to get in the plugin
  *
  * @return string The full path of the view file
  */
 public function getView($view)
 {
     // Check if the view is overriden in the current theme
     $file = Theme::getSelected()->getView('plugins/' . $this->name . '/' . $view);
     if (is_file($file)) {
         // The view is overriden in the theme
         return $file;
     }
     // The view is not overriden in the view
     return $this->getViewsDir() . $view;
 }
예제 #23
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'));
             }
         }
     }
 }
예제 #24
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'));
             }
         }
     }
 }
예제 #25
0
파일: index.php 프로젝트: elvyrra/hawk
    define('SCRIPT_START_TIME', microtime(true));
    define('ROOT_DIR', __DIR__ . '/');
    define('INCLUDES_DIR', ROOT_DIR . 'includes/');
    include ROOT_DIR . 'start.php';
    App::logger()->debug('script has been Initialized');
    (new Event('process-start'))->trigger();
    /*** Initialize the plugins ***/
    $plugins = App::conf()->has('db') ? Plugin::getActivePlugins() : array(Plugin::get('main'), Plugin::get('install'));
    foreach ($plugins as $plugin) {
        if (is_file($plugin->getStartFile())) {
            include $plugin->getStartFile();
        }
    }
    /*** Initialize the theme ***/
    if (is_file(Theme::getSelected()->getStartFile())) {
        include Theme::getSelected()->getStartFile();
    }
    (new Event('before-routing'))->trigger();
    /*** Execute action just after routing ***/
    Event::on('after-routing', function ($event) {
        $route = $event->getData('route');
        if (!App::conf()->has('db') && App::request()->getUri() == App::router()->getUri('index')) {
            // The application is not installed yet
            App::logger()->notice('Hawk is not installed yet, redirect to install process page');
            App::response()->redirectToAction('install');
            return;
        }
    });
    /*** Compute the routage ***/
    App::router()->route();
} catch (HTTPException $err) {
예제 #26
0
 /**
  * Clear the cache and reload the whole page
  */
 public function clearCache()
 {
     Event::unbind('process-end');
     // Clear the directoty cache
     foreach (glob(CACHE_DIR . '*') as $elt) {
         App::fs()->remove($elt);
     }
     // Clear the directory of the theme
     foreach (glob(Theme::getSelected()->getStaticDir() . '*') as $element) {
         if (basename($element) != 'userfiles') {
             App::fs()->remove($element);
         }
     }
     App::response()->redirectToAction('index');
 }
예제 #27
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);
             }
         }
     }
 }
예제 #28
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);
             }
         }
     }
 }
예제 #29
0
 /**
  * Display the widget
  *
  * @return string The generated HTML
  */
 public function display()
 {
     $form = LanguageController::getInstance()->keyForm();
     return View::make(Theme::getSelected()->getView("box.tpl"), array('title' => Lang::get('language.key-form-add-title'), 'icon' => 'font', 'content' => $form));
 }
예제 #30
0
파일: FormInput.php 프로젝트: elvyrra/hawk
 /**
  * Display the input (alias method)
  *
  * @return string the HTML result of the input displaying
  */
 public function display()
 {
     try {
         $theme = Theme::getSelected();
         if ($this->name == $this->errorAt) {
             unset($this->errorAt);
         }
         $inputLabel = $this->label ? View::make($theme->getView(Form::VIEWS_DIR . 'form-input-label.tpl'), array('input' => $this)) : '';
         $inputDisplay = View::make($this->tpl, array('input' => $this));
         return View::make($theme->getView(Form::VIEWS_DIR . 'form-input-block.tpl'), array('input' => $this, 'inputLabel' => $inputLabel, 'inputDisplay' => $inputDisplay));
     } catch (\Exception $e) {
         App::errorHandler()->exception($e);
     }
 }