private function updateWebDir($b) { if ($b->status) { foreach (array('script', 'style', 'graphic') as $type) { \Useful::checkFilesInDir(sprintf('%s/bites/%s/%s', ROOT, $b->name, $type), $files); foreach ($files as $s) { \Useful::copyFile(sprintf('%s/bites/%s/%s/%s', ROOT, $b->name, $type, $s), sprintf('%s/web/%s/%s', ROOT, $type, $s)); } unset($files); } } else { $active_bites = \R::$adapter->get("select * from bites where status = 1"); foreach ($active_bites as $bite) { \Useful::checkFilesInDir(\ROOT . '/bites/' . $bite['name'] . '/script', $scripts); \Useful::checkFilesInDir(\ROOT . '/bites/' . $bite['name'] . '/style', $styles); \Useful::checkFilesInDir(\ROOT . '/bites/' . $bite['name'] . '/graphic', $graphics); } foreach (array('script', 'style', 'graphic') as $type) { \Useful::checkFilesInDir(\ROOT . '/web/' . $type, $files); foreach ($files as $file) { if (!in_array($file, ${$type . 's'})) { unlink(\ROOT . '/web/' . $type . '/' . $file); } } unset($files); } } }
public function action_signup() { $this->template->menu_signup = TRUE; // Если залогинен, то перекидываем на дерево if (Auth::instance()->logged_in()) { $this->redirect(Route::url('user/id', array('user_id' => Auth::instance()->get_user()->id))); } $post = Arr::extract($this->request->post(), array('name', 'surname', 'email')); $data['errors'] = NULL; if ($this->request->method() == 'POST') { // Генерирую случайный пароль из цифр $post['password'] = Text::random('numeric', 5); try { $user = ORM::factory('User')->values($post)->save(); $user->add('roles', ORM::factory('Role', array('name' => 'login'))); $message = ' Для входа на сайт ' . $_SERVER['HTTP_HOST'] . ' используйте следующие данные:<br><br> Адрес электронной почты: ' . HTML::chars($user->email) . '<br> Пароль: ' . HTML::chars($post['password']) . '<br><br> <a href="' . URL::base(TRUE) . '">Перейти на сайт</a>'; Useful::mail($user->email, 'Регистрация LiveTex', $message, 'LiveTex'); // Авторизовываю Auth::instance()->login($user->email, $post['password'], TRUE); $this->redirect(Route::url('user/id', array('user_id' => $user->id))); } catch (ORM_Validation_Exception $e) { $data['errors'] = $e->errors('orm'); } } $data += $post; $this->template->content = View::factory('auth/signup', $data); }
public function findPath() { foreach ($this->url as $url) { if ($path = Useful::array_search_recursive('/' . APP . $url, $this->navigation_array[APP])) { return $path; } else { if ($path = Useful::array_search_recursive($url, $this->navigation_array[APP])) { return $path; } } } return false; }
public function returnField($name, $value = '') { $field = ''; foreach ($this->options as $key => $val) { $field .= sprintf('<input type="checkbox" name="%1$s[]" id="%3$s" value="%2$s" %4$s/>' . '<label for=%3$s>%5$s</label>', $name, $key, Useful::slugify($name) . '_' . Useful::slugify($key), is_array($value) && in_array((string) $key, $value) ? 'checked="checked"' : '', $val); } $class = !empty($this->error) ? ' class="error"' : ''; return array('messages' => !empty($this->custom_error) && !empty($this->error) ? $this->custom_error : $this->error, 'label' => $this->label == false ? false : sprintf('<p%s>%s</p>', $class, $this->label), 'field' => $field, 'html' => $this->html); }
/** * Creates a new CRSF token * * @return string */ private function setToken() { if (!isset($_SESSION["nibble_forms"])) { $_SESSION["nibble_forms"] = array(); } if (!isset($_SESSION["nibble_forms"]["_crsf_token"])) { $_SESSION["nibble_forms"]["_crsf_token"] = array(); } $_SESSION["nibble_forms"]["_crsf_token"][$this->name] = Useful::randomString(20); $this->addField("_crsf_token", "hidden"); $this->addData(array("_crsf_token" => $_SESSION["nibble_forms"]["_crsf_token"][$this->name])); }
<label for="email">Administrators email address:</label> <input type="text" name="email" id="email" value="<?php echo Useful::stickyText('email'); ?> " /> <label for="dbhost">Database host name</label> <input type="text" name="dbhost" id="dbhost" value="<?php echo Useful::stickyText('dbhost'); ?> " /> <label for="dbname">Database name</label> <input type="text" name="dbname" id="dbname" value="<?php echo Useful::stickyText('dbname'); ?> " /> <label for="dbuser">Database username</label> <input type="text" name="dbuser" id="dbuser" value="<?php echo Useful::stickyText('dbuser'); ?> " /> <label for="dbpass">Database password</label> <input type="text" name="dbpass" id="dbpass" value="<?php echo Useful::stickyText('dbpass'); ?> " /> <input type="submit" value="Install Nibble on my server" name="submit" /> </form> </div> </body> </html>
/* Auto loader */ function __autoload($class_name) { if (file_exists(dirname(dirname(__FILE__)) . '/class/' . $class_name . '.class.php')) { require_once dirname(dirname(__FILE__)) . '/class/' . $class_name . '.class.php'; } } /* Project environment */ define('DEV_ENV', $_SERVER['SERVER_ADDR'] == '127.0.0.1' ? true : false); /* Root definition */ define('ROOT', dirname(dirname(dirname(__FILE__)))); /* If development define the include root for html elements such as css files */ if (DEV_ENV) { $root_array = explode(DIRECTORY_SEPARATOR, ROOT); define('INC_ROOT', $root_array[count($root_array) - 1]); } Useful::setReporting(true); if (DBUSER !== '') { require ROOT . "/lib/class/rb.php"; R::setup(sprintf("%s:host=%s;dbname=%s", DBTYPE, DBHOST, DBNAME), DBUSER, DBPASS); /* If there is no bites table make it and add the bites plugin */ R::exec("show tables like 'bites'"); if (!R::$adapter->getAffectedRows()) { $item = R::dispense("bites"); $item->name = 'bites'; $item->desc = 'Bites are plugins for Nibble, “Bites” is the default module for Nibble that provides a means of enabling other Bites.'; $item->status = '1'; $item->type = '2'; $id = R::store($item); } }