echo $form->handle(function ($form) use($page, $tpl) { if (!empty($_POST['github'])) { if (github_is_zip($_POST['github'])) { ZipInstaller::clean(); // Retrieve zip file $info = ZipInstaller::fetch($_POST['github']); if (!$info) { ZipInstaller::clean(); $form->failed = array('zip-install'); $page->installer_error = ZipInstaller::$error; return false; } // Import from Zip $res = ZipInstaller::install($info); if (!$res) { ZipInstaller::clean(); $form->failed = array('zip-install'); $page->installer_error = ZipInstaller::$error; return false; } // Zip successfully installed ZipInstaller::clean(); $page->title = __('Install completed'); echo $tpl->render('designer/installed', $res); } else { // Import from Github $res = GithubInstaller::install($_POST['github']); if (!$res) { $form->failed = array('github-install'); $page->installer_error = GithubInstaller::$error; return false; } // App/theme successfully installed $page->title = __('Install completed'); echo $tpl->render('designer/installed', $res); } } elseif (is_uploaded_file($_FILES['zipfile']['tmp_name'])) { ZipInstaller::clean(); // Import from Zip $res = ZipInstaller::install($_FILES['zipfile']); if (!$res) { ZipInstaller::clean(); $form->failed = array('zip-install'); $page->installer_error = ZipInstaller::$error; return false; } // Zip successfully installed ZipInstaller::clean(); $page->title = __('Install completed'); echo $tpl->render('designer/installed', $res); } else { $form->failed = array('other'); return false; } });
<?php /** * Add a new language to the list, including its name, * code, locale, character set, and fallback. */ $this->require_acl('admin', 'translator'); $page->layout = 'admin'; $page->title = __('Add language'); $form = new Form('post', $this); require_once 'apps/translator/lib/Functions.php'; echo $form->handle(function ($form) { // Add to lang/languages.php $_POST['code'] = strtolower($_POST['code']); $_POST['locale'] = strtolower($_POST['locale']); if (!empty($_POST['locale'])) { $lang = $_POST['code'] . '_' . $_POST['locale']; } else { $lang = $_POST['code']; } $i18n = $form->controller->i18n(); $i18n->languages[$lang] = array('name' => $_POST['name'], 'code' => $_POST['code'], 'locale' => $_POST['locale'], 'charset' => $_POST['charset'], 'fallback' => $_POST['fallback'], 'default' => 'Off', 'date_format' => $_POST['date_format'], 'short_format' => $_POST['short_format'], 'time_format' => $_POST['time_format']); uasort($i18n->languages, 'translator_sort_languages'); if (!Ini::write($i18n->languages, 'lang/languages.php')) { return false; } $form->controller->add_notification(__('Language added.')); $form->controller->redirect('/translator/index'); });
echo $form->handle(function ($form) use($page) { $_POST['resources'] = isset($_POST['resources']) ? $_POST['resources'] : array(); foreach ($_POST['resources'] as $key => $on) { $_POST['resources'][$key] = true; } // convert the resources for saving if (!isset($_POST['resources']['default'])) { $_POST['resources']['default'] = false; } else { $resources = User::acl()->resources(); foreach ($resources as $resource => $label) { if (isset($_POST['resources'][$resource])) { unset($resources[$resource]); } else { $resources[$resource] = false; } } $resources['default'] = true; $_POST['resources'] = $resources; } // save the file $acl = User::acl(); unset($acl->rules[$_GET['role']]); unset($acl->rules[$_POST['name']]); $acl->add_role($_POST['name'], $_POST['resources']['default']); foreach ($_POST['resources'] as $resource => $allow) { if ($allow) { $acl->allow($_POST['name'], $resource); } else { $acl->deny($_POST['name'], $resource); } } if (!Ini::write($acl->rules, conf('Paths', 'access_control_list'))) { $form->controller->add_notification(__('Unable to save the file.')); return false; } $form->controller->add_notification(__('Role saved.')); $form->controller->redirect('/user/roles'); });
} $form = new Form('post', $this); $page->title = __('Sign Up'); echo $form->handle(function ($form) use($page, $tpl) { $date = gmdate('Y-m-d H:i:s'); $verifier = md5(uniqid(mt_rand(), 1)); $u = new User(array('name' => $_POST['name'], 'email' => $_POST['email'], 'password' => User::encrypt_pass($_POST['password']), 'expires' => $date, 'type' => 'member', 'signed_up' => $date, 'updated' => $date, 'userdata' => json_encode(array('verifier' => $verifier)))); $u->put(); Versions::add($u); if (!$u->error) { // Create customer and account $customer = new saasy\Customer(array('name' => $_POST['customer_name'], 'subdomain' => $_POST['subdomain'], 'level' => 1)); $customer->put(); $acct = new saasy\Account(array('user' => $u->id, 'customer' => $customer->id, 'type' => 'owner', 'enabled' => 1)); $acct->put(); try { Mailer::send(array('to' => array($_POST['email'], $_POST['name']), 'subject' => __('Please confirm your email address'), 'text' => $tpl->render('saasy/email/verification', array('verifier' => $verifier, 'email' => $_POST['email'], 'name' => $_POST['name'], 'domain' => $customer->domain())))); } catch (Exception $e) { @error_log('Email failed (saasy/signup): ' . $e->getMessage()); $u->userdata = array(); $u->put(); } $_POST['username'] = $_POST['email']; User::require_login(); $form->controller->redirect($form->controller->is_https() ? 'https://' . $customer->domain() . '/' : 'http://' . $customer->domain() . '/'); } @error_log('Error creating profile: ' . $u->error); $page->title = __('An Error Occurred'); echo '<p>' . __('Please try again later.') . '</p>'; echo '<p><a href="/">' . __('Back') . '</a></p>'; });
echo $form->handle(function ($form) { // Update lang/languages.php $_POST['code'] = strtolower($_POST['code']); $_POST['locale'] = strtolower($_POST['locale']); if (!empty($_POST['locale'])) { $lang = $_POST['code'] . '_' . $_POST['locale']; } else { $lang = $_POST['code']; } global $i18n; if ($lang !== $_GET['lang']) { // Language has changed ids if (isset($i18n->languages[$lang])) { // Language already exists $form->failed = array('dupe'); return false; } $i18n->languages[$lang] = $i18n->languages[$_GET['lang']]; unset($i18n->languages[$_GET['lang']]); rename('lang/' . $_GET['lang'] . '.php', 'lang/' . $lang . '.php'); } $i18n->languages[$lang]['name'] = $_POST['name']; $i18n->languages[$lang]['code'] = $_POST['code']; $i18n->languages[$lang]['locale'] = $_POST['locale']; $i18n->languages[$lang]['charset'] = $_POST['charset']; $i18n->languages[$lang]['fallback'] = $_POST['fallback']; $i18n->languages[$lang]['date_format'] = $_POST['date_format']; $i18n->languages[$lang]['short_format'] = $_POST['short_format']; $i18n->languages[$lang]['time_format'] = $_POST['time_format']; uasort($i18n->languages, 'translator_sort_languages'); if (!Ini::write($i18n->languages, 'lang/languages.php')) { return false; } $form->controller->add_notification(i18n_get('Language updated.')); $form->controller->redirect('/translator/index'); });
echo $form->handle(function ($form) use($u, $page) { if (user\Rules::email_in_use($_POST['email'], User::val('id'))) { $form->failed[] = 'email-in-use'; return false; } $u->name = $_POST['name']; $u->email = $_POST['email']; if (!empty($_POST['password'])) { $u->password = User::encrypt_pass($_POST['password']); } $u->about = $_POST['about']; $u->phone = $_POST['phone']; $u->address = $_POST['address']; $u->address2 = $_POST['address2']; $u->city = $_POST['city']; $u->state = $_POST['state']; $u->country = $_POST['country']; $u->zip = $_POST['zip']; $u->title = $_POST['title']; $u->company = $_POST['company']; $u->website = $_POST['website']; if (isset($_FILES['photo']) && is_uploaded_file($_FILES['photo']['tmp_name'])) { $tmp_file = 'cache/.' . basename($_FILES['photo']['name']); $old_file = $u->photo; if (move_uploaded_file($_FILES['photo']['tmp_name'], $tmp_file)) { if (preg_match('/\\.jpe?g$/i', $tmp_file)) { Image::reorient($tmp_file); } $u->photo = Image::resize($tmp_file, Appconf::user('User', 'photo_width'), Appconf::user('User', 'photo_height')); if (strpos($u->photo, '#') !== false) { error_log('Error processing photo: ' . $u->photo); $u->photo = $old_file; } elseif (!empty($old_file) && $old_file !== $u->photo && file_exists($old_file)) { unlink($old_file); } unlink($tmp_file); } } $u->put(); Versions::add($u); if (!$u->error) { $page->title = __('Profile Updated'); echo '<p><a href="/user">' . __('Continue') . '</a></p>'; return; } @error_log('Error updating profile (#' . $u->id . '): ' . $u->error); $page->title = __('An Error Occurred'); echo '<p>' . __('Please try again later.') . '</p>'; echo '<p><a href="/user">' . __('Back') . '</a></p>'; });
<?php /** * Global site settings manager. */ // keep unauthorized users out $this->require_acl('admin', 'settings'); // set the layout and page title $page->layout = 'admin'; $page->title = __('Site Settings'); // create the form $form = new Form('post', $this); // set the form data from the global conf() settings, since they've already // been rewritten with the Appconf::storyteller() ones in bootstrap.php $form->data = array('site_name' => conf('General', 'site_name'), 'site_domain' => conf('General', 'site_domain') ? conf('General', 'site_domain') : $_SERVER['HTTP_HOST'], 'email_from' => conf('General', 'email_from'), 'timezone' => conf('General', 'timezone'), 'google_analytics_id' => conf('General', 'google_analytics_id')); echo $form->handle(function ($form) { // merge the new values into the settings $merged = Appconf::merge('admin', array('Site Settings' => array('site_name' => $_POST['site_name'], 'site_domain' => $_POST['site_domain'], 'email_from' => $_POST['email_from'], 'timezone' => $_POST['timezone'], 'google_analytics_id' => $_POST['google_analytics_id']))); // save the settings to disk if (!Ini::write($merged, 'conf/app.admin.' . ELEFANT_ENV . '.php')) { printf('<p>%s</p>', __('Unable to save changes. Check your permissions and try again.')); return; } // redirect to the main admin page with a notification $form->controller->add_notification(__('Settings saved.')); $form->controller->redirect('/'); });
<?php /** * This is the settings form for the blog app. */ $this->require_admin(); $page->layout = 'admin'; $page->title = __('Blog Settings'); $form = new Form('post', $this); $form->data = array('title' => $appconf['Blog']['title'], 'layout' => $appconf['Blog']['layout'], 'post_layout' => $appconf['Blog']['post_layout'], 'comments' => $appconf['Blog']['comments'], 'preview_chars' => $appconf['Blog']['preview_chars'], 'post_format' => $appconf['Blog']['post_format'], 'post_footer' => $appconf['Blog']['post_footer'], 'show_related_posts' => $appconf['Blog']['show_related_posts'], 'disqus_shortname' => $appconf['Blog']['disqus_shortname'], 'social_twitter' => $appconf['Social Buttons']['twitter'], 'social_facebook' => $appconf['Social Buttons']['facebook'], 'social_google' => $appconf['Social Buttons']['google']); echo $form->handle(function ($form) { $merged = Appconf::merge('blog', array('Blog' => array('title' => $_POST['title'], 'layout' => $_POST['layout'], 'post_layout' => $_POST['post_layout'], 'preview_chars' => !empty($_POST['preview_chars']) ? (int) $_POST['preview_chars'] : false, 'post_format' => $_POST['post_format'], 'post_footer' => $_POST['post_footer'], 'comments' => $_POST['comments'] === 'none' ? false : $_POST['comments'], 'show_related_posts' => $_POST['show_related_posts'] === 'yes' ? true : false, 'disqus_shortname' => $_POST['disqus_shortname']), 'Social Buttons' => array('twitter' => $_POST['social_twitter'] === 'yes' ? true : false, 'facebook' => $_POST['social_facebook'] === 'yes' ? true : false, 'google' => $_POST['social_google'] === 'yes' ? true : false))); if (!Ini::write($merged, 'conf/app.blog.' . ELEFANT_ENV . '.php')) { printf('<p>%s</p>', __('Unable to save changes. Check your folder permissions and try again.')); return; } $form->controller->run('navigation/hook/edit', array('page' => 'blog', 'id' => 'blog', 'title' => $_POST['title'])); $form->controller->add_notification(__('Settings saved.')); $form->controller->redirect('/blog/admin'); });
echo $form->handle(function ($form) use($page, $customer, $acct) { // update user/acct \User::val('name', $_POST['name']); \User::val('email', $_POST['email']); if (!empty($_POST['new_pass'])) { \User::val('password', \User::encrypt_pass($_POST['new_pass'])); } \User::save(); if (is_uploaded_file($_FILES['photo']['tmp_name'])) { $acct->save_photo($_FILES['photo']); } if ($acct->type === 'owner') { // update customer too $customer->name = $_POST['customer_name']; if ($customer->subdomain !== $_POST['subdomain']) { $customer->subdomain = $_POST['subdomain']; $domain_has_changed = true; } else { $domain_has_changed = false; } if (!$customer->put()) { return false; } if (is_uploaded_file($_FILES['customer_logo']['tmp_name'])) { $customer->save_logo($_FILES['customer_logo']); } if ($domain_has_changed) { echo \View::render('saasy/account_redirect', array('redirect' => $form->controller->is_https() ? 'https://' . $customer->subdomain . '.' . App::base_domain() . '/' : 'http://' . $customer->subdomain . '.' . App::base_domain() . '/')); return; } } \Notifier::add_notice(__('Your settings have been updated.')); $form->controller->redirect(App::href() . '/account'); });
<?php // keep unauthorized users out $this->require_admin(); // set the layout and page title $page->layout = 'admin'; $page->title = __('Files - Settings'); // create the form $form = new Form('post', $this); // set the form data from the app settings $form->data = array('aviary_key' => Appconf::filemanager('General', 'aviary_key')); echo $form->handle(function ($form) { // merge the new values into the settings $merged = Appconf::merge('filemanager', array('General' => array('aviary_key' => $_POST['aviary_key']))); // save the settings to disk if (!Ini::write($merged, 'conf/app.filemanager.' . ELEFANT_ENV . '.php')) { printf('<p>%s</p>', __('Unable to save changes. Check your permissions and try again.')); return; } // redirect to the main admin page with a notification $form->controller->add_notification(__('Settings saved.')); $form->controller->redirect('/filemanager/index'); });
<?php /** * Edits plain text files in the file manager. */ $this->require_admin(); if (!isset($_GET['file'])) { $this->add_notification(__('No file specified.')); $this->redirect('/filemanager/index'); } if (!FileManager::verify_file($_GET['file'])) { $this->add_notification(__('Invalid file.')); $this->redirect('/filemanager/index'); } $form = new Form('post', $this); $root = conf('Paths', 'filemanager_path') . '/'; $form->root = $root; $form->data = array('body' => file_get_contents($root . $_GET['file'])); $page->title = __('Edit file') . ': ' . basename($_GET['file']); $page->layout = 'admin'; echo $form->handle(function ($form) { if (!file_put_contents($form->root . $_GET['file'], $_POST['body'])) { $form->controller->add_notification(__('Unable to write to the file. Please check your folder permissions and try again.')); return false; } $form->controller->add_notification(__('File saved.')); $form->controller->redirect('/filemanager/index'); });
$form = new Form('post', $this); $appconf['User']['login_methods'] = is_array($appconf['User']['login_methods']) ? $appconf['User']['login_methods'] : array(); $form->data = array('facebook_app_id' => $appconf['Facebook']['application_id'], 'facebook_app_secret' => $appconf['Facebook']['application_secret'], 'twitter_id' => $appconf['Twitter']['twitter_id'], 'twitter_key' => $appconf['Twitter']['consumer_key'], 'twitter_secret' => $appconf['Twitter']['consumer_secret'], 'twitter_access_token' => $appconf['Twitter']['access_token'], 'twitter_access_token_secret' => $appconf['Twitter']['access_token_secret'], 'login_openid' => in_array('openid', $appconf['User']['login_methods']), 'login_google' => in_array('google', $appconf['User']['login_methods']), 'login_facebook' => in_array('facebook', $appconf['User']['login_methods']), 'login_twitter' => in_array('twitter', $appconf['User']['login_methods']), 'login_persona' => in_array('persona', $appconf['User']['login_methods']), 'default_role' => $appconf['User']['default_role'], 'roles' => array_keys(User::acl()->rules)); echo $form->handle(function ($form) { $login_methods = array(); if ($_POST['login_openid'] === 'yes') { $login_methods[] = 'openid'; } if ($_POST['login_google'] === 'yes') { $login_methods[] = 'google'; } if ($_POST['login_facebook'] === 'yes') { $login_methods[] = 'facebook'; } if ($_POST['login_twitter'] === 'yes') { $login_methods[] = 'twitter'; } if ($_POST['login_persona'] === 'yes') { $login_methods[] = 'persona'; } if (count($login_methods) === 0) { $login_methods = false; } $merged = Appconf::merge('user', array('User' => array('login_methods' => $login_methods, 'default_role' => $_POST['default_role']), 'Facebook' => array('application_id' => $_POST['facebook_app_id'], 'application_secret' => $_POST['facebook_app_secret']), 'Twitter' => array('twitter_id' => $_POST['twitter_id'], 'consumer_key' => $_POST['twitter_key'], 'consumer_secret' => $_POST['twitter_secret'], 'access_token' => $_POST['twitter_access_token'], 'access_token_secret' => $_POST['twitter_access_token_secret']))); if (!Ini::write($merged, 'conf/app.user.' . ELEFANT_ENV . '.php')) { printf('<p>%s</p>', __('Unable to save changes. Check your folder permissions and try again.')); return; } $form->controller->add_notification(__('Settings saved.')); $form->controller->redirect('/user/admin'); });