Ejemplo n.º 1
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"));
         }
     }
 }
Ejemplo n.º 2
0
 /**
  * Constructor
  *
  * @param string    $message  The exception message
  * @param int       $code     The exception $code
  * @param string    $value    The exception content
  * @param Exception $previous The previous exception that throwed that one
  */
 public function __construct($message, $code, $value, $previous = null)
 {
     switch ($code) {
         case self::CONNECTION_ERROR:
             $message = "Impossible to connect to Database Server : {$value}, {$message}";
             $details = array('server' => $value);
             break;
         case self::QUERY_ERROR:
             $message = "An error was detected : {$message} in the Database Query : {$value}";
             $details = array('query' => $value);
             App::logger()->error($message);
             break;
     }
     parent::__construct($message, $details);
 }
Ejemplo n.º 3
0
 /**
  * Delete the element from the database
  *
  * @param bool   $exit    If set to true, the script will output after function execution, not depending on the result
  * @param string $success Defines the message to output if the action has been well executed
  * @param string $error   Defines the message to output if an error occured
  *
  * @return mixed The id of the deleted object
  */
 public function delete($exit = self::EXIT_JSON, $success = "", $error = "")
 {
     try {
         $this->dbaction = self::ACTION_DELETE;
         if ($this->model == self::DEFAULT_MODEL || !$this->reference) {
             throw new \Exception("The method delete of the class Form can be called only if model and reference properties are set");
         }
         if (!$this->object) {
             throw new \Exception("This object instance cannot be removed : No such object");
         }
         $id = $this->object->getPrimaryColumn();
         $this->object->delete();
         $this->addReturn(array('primary' => $this->object->{$id}, 'action' => self::ACTION_DELETE));
         $this->status = self::STATUS_SUCCESS;
         App::logger()->info('The delete action on the form ' . $this->id . ' was successflully completed');
         if ($exit) {
             App::response()->setBody($this->response(self::STATUS_SUCCESS, $success ? $success : Lang::get('form.success-delete')));
             throw new AppStopException();
         }
         return $this->object->{$id};
     } catch (DBException $e) {
         $this->status = self::STATUS_ERROR;
         App::logger()->error('An error occured while deleting the element of the form ' . $this->id . ' : ' . $e->getMessage());
         if ($exit) {
             return $this->response(self::STATUS_ERROR, DEBUG_MODE ? $e->getMessage() : ($error ? $error : Lang::get('form.error-delete')));
         }
         throw $e;
     }
 }
Ejemplo n.º 4
0
    (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) {
    App::response()->setStatus($err->getStatusCode());
    $response = array('message' => $err->getMessage(), 'details' => $err->getDetails());
    if (App::request()->getWantedType() === 'json') {
        App::response()->setContentType('json');
        App::response()->setBody($response);
    } else {
        App::response()->setBody($response['message']);
    }
} catch (AppStopException $e) {
}
// Finish the script
App::logger()->debug('end of script');
$event = new Event('process-end', array('output' => App::response()->getBody(), 'execTime' => microtime(true) - SCRIPT_START_TIME));
$event->trigger();
App::response()->setBody($event->getData('output'));
/*** Return the response to the client ***/
App::response()->end();
Ejemplo n.º 5
0
 /**
  * Load a language file
  *
  * @param string $plugin   The plugin to load
  * @param string $language The language to get the translations in
  * @param string $force    If set to true, force to reload the translations
  */
 private static function load($plugin, $language = LANGUAGE, $force = false)
 {
     if (!isset(self::$keys[$plugin][$language]) || $force || $language !== self::$usedLanguage) {
         App::logger()->debug('Reload keys for plugin ' . $plugin . ' and for language ' . $language);
         self::$keys[$plugin][$language] = array();
         $instance = new self($plugin, self::DEFAULT_LANGUAGE);
         $instance->build();
         self::$keys[$plugin][$language] = App::cache()->includeCache($instance->cacheFile);
         if ($language !== self::DEFAULT_LANGUAGE) {
             $instance = new self($plugin, $language);
             $instance->build();
             $translations = App::cache()->includeCache($instance->cacheFile);
             if (!is_array($translations)) {
                 $translations = array();
             }
             self::$keys[$plugin][$language] = array_merge(self::$keys[$plugin][$language], $translations);
         }
         self::$usedLanguage = $language;
     }
 }
Ejemplo n.º 6
0
 /**
  * Trigger the event
  */
 public function trigger()
 {
     $name = $this->getName();
     $trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 1)[0];
     App::logger()->debug('The event ' . $name . ' has been triggered from ' . $trace['file'] . ':' . $trace['line']);
     if (isset(self::$events[$name])) {
         ksort(self::$events[$name]);
         foreach (self::$events[$name] as $action) {
             $action($this);
         }
     }
 }
Ejemplo n.º 7
0
 /**
  * Redirect to another URL
  *
  * @param string $url The URL to redirect to
  */
 public function redirect($url)
 {
     App::logger()->debug('redirect to ' . $url);
     $this->header('Location', $url);
     $this->end();
 }
Ejemplo n.º 8
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));
     }
 }
Ejemplo n.º 9
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'));
         }
     }
 }
Ejemplo n.º 10
0
Archivo: DB.php Proyecto: elvyrra/hawk
 /**
  * Get the open connection, or open it if not already open.
  * This method manages master / slaves connections
  *
  * @param String $name The name of the instance
  *
  * @return DB the connected instance
  */
 public static function get($name)
 {
     if (isset(self::$instances[$name])) {
         return self::$instances[$name];
     }
     $servers = self::$servers[$name];
     foreach ($servers as $i => $server) {
         try {
             self::$instances[$name] = new self($server);
             App::logger()->debug('Connection to db ' . $name . ' successfull');
             // The connection succeed
             break;
         } catch (DBException $e) {
             $log = 'Impossible to connect to db ' . $name . ' on instance ' . $i . ' : ' . $e->getMessage();
             App::logger()->warning($log);
             // The connection failed, try to connect to the next slave
             if (!isset($servers[$i + 1])) {
                 // the last slave connection failed
                 App::logger()->error('Impossible to connect to db ' . $name . ' : ' . $e->getMessage());
                 throw $e;
             }
         }
     }
     return self::$instances[$name];
 }
Ejemplo n.º 11
0
 /**
  * Send the mail
  *
  * @throws MailException
  */
 public function send()
 {
     $this->prepareContent();
     if (!$this->mailer->send()) {
         App::logger()->error('The mail could not be sent because : ' . $this->mailer->ErrorInfo);
         throw new MailException($this->mailer->ErrorInfo);
     }
     App::logger()->info('An email was sent to ' . implode(', ', array_keys($this->mailer->getAllRecipientAddresses())));
 }
Ejemplo n.º 12
0
 /**
  * Deactive the plugin
  */
 public function deactivate()
 {
     // Deactivate the plugin
     $this->active = false;
     $model = new PluginModel(array('name' => $this->name, 'active' => 0));
     $model->update();
     try {
         $this->getInstallerInstance()->deactivate();
         App::logger()->notice('The plugin ' . $this->name . ' has been deactivated');
     } catch (\Exception $e) {
         $this->active = true;
         $model->active = 1;
         $model->update();
         App::logger()->error('En error occured while deactivating plugin ' . $this->name . ' : ' . $e->getMessage());
         throw $e;
     }
 }
Ejemplo n.º 13
0
 //or use mysql sessions
 new \sb\Session\Mysql(App::$db);

 //or use memcache sessions
 new \sb\Session\Memcache('localhost', 11211);

 </code>
*/
//session handler
if (!headers_sent()) {
    session_start();
}
/**
* ASSIGN APP's OTHER STATIC PROPERTIES HERE
* All static properties of App class, found in this directory are avaiable throughout your code in any scope.
* Remember before assigning properties they must be documented on the App class itself in App.php.  If you put the proper phpDoc
* comments on the properties of App, the code completion will be available in eclipse/zend studio
* Example include, the application cache and your database connections.
* 
 <code>
 //define the App user
 App::$user = new \sb\User();
 App::$user->uname = 'tester';
 </code>
*/
//define the application's main caching engine
App::$cache = new \sb\Cache\FileSystem();
//define the application's main logging engine
App::$logger = new \sb\Logger\FileSystem();
\sb\Application\Debugger::init();
Ejemplo n.º 14
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);
             }
         }
     }
 }
Ejemplo n.º 15
0
 /**
  * Compute the routing, and execute the controller method associated to the URI
  */
 public function route()
 {
     $path = str_replace(BASE_PATH, '', parse_url(App::request()->getUri(), PHP_URL_PATH));
     // Scan each row
     foreach ($this->routes as $route) {
         if ($route->match($path)) {
             // The URI matches with the route
             $this->currentRoute =& $route;
             // Check if the route is accessible with the current method
             if (!$route->isCallableBy(App::request()->getMethod())) {
                 throw new BadMethodException($route->url, App::request()->getMethod());
             }
             // Emit an event, saying the routing action is finished
             $event = new Event('after-routing', array('route' => $route));
             $event->trigger();
             $route = $event->getData('route');
             if (!$route->isAccessible()) {
                 // The route is not accessible
                 App::logger()->warning(sprintf('A user with the IP address %s tried to access %s without the necessary privileges', App::request()->clientIp(), App::request()->getUri()));
                 if (!App::session()->isLogged()) {
                     throw new UnauthorizedException();
                 } else {
                     throw new ForbiddenException();
                 }
             }
             // The route authentications are validated
             list($classname, $method) = explode(".", $route->action);
             // call a controller method
             $this->currentController = $classname::getInstance($route->getData());
             App::logger()->debug(sprintf('URI %s has been routed => %s::%s', App::request()->getUri(), $classname, $method));
             // Set the controller result to the HTTP response
             App::response()->setBody($this->currentController->{$method}());
             return;
         }
     }
     App::logger()->warning('The URI ' . App::request()->getUri() . ' has not been routed');
     throw new PageNotFoundException();
 }