| 1 | <?php |
|---|
| 2 | /** |
|---|
| 3 | * @package Dotclear |
|---|
| 4 | * @subpackage Backend |
|---|
| 5 | * |
|---|
| 6 | * @copyright Olivier Meunier & Association Dotclear |
|---|
| 7 | * @copyright GPL-2.0-only |
|---|
| 8 | */ |
|---|
| 9 | |
|---|
| 10 | require dirname(__FILE__) . '/../inc/admin/prepend.php'; |
|---|
| 11 | |
|---|
| 12 | dcPage::checkSuper(); |
|---|
| 13 | |
|---|
| 14 | $blog_id = ''; |
|---|
| 15 | $blog_url = ''; |
|---|
| 16 | $blog_name = ''; |
|---|
| 17 | $blog_desc = ''; |
|---|
| 18 | |
|---|
| 19 | # Create a blog |
|---|
| 20 | if (!isset($_POST['id']) && (isset($_POST['create']))) { |
|---|
| 21 | $cur = $core->con->openCursor($core->prefix . 'blog'); |
|---|
| 22 | $blog_id = $cur->blog_id = $_POST['blog_id']; |
|---|
| 23 | $blog_url = $cur->blog_url = $_POST['blog_url']; |
|---|
| 24 | $blog_name = $cur->blog_name = $_POST['blog_name']; |
|---|
| 25 | $blog_desc = $cur->blog_desc = $_POST['blog_desc']; |
|---|
| 26 | |
|---|
| 27 | try |
|---|
| 28 | { |
|---|
| 29 | # --BEHAVIOR-- adminBeforeBlogCreate |
|---|
| 30 | $core->callBehavior('adminBeforeBlogCreate', $cur, $blog_id); |
|---|
| 31 | |
|---|
| 32 | $core->addBlog($cur); |
|---|
| 33 | |
|---|
| 34 | # Default settings and override some |
|---|
| 35 | $core->blogDefaults($cur->blog_id); |
|---|
| 36 | $blog_settings = new dcSettings($core, $cur->blog_id); |
|---|
| 37 | $blog_settings->addNamespace('system'); |
|---|
| 38 | $blog_settings->system->put('lang', $core->auth->getInfo('user_lang')); |
|---|
| 39 | $blog_settings->system->put('blog_timezone', $core->auth->getInfo('user_tz')); |
|---|
| 40 | |
|---|
| 41 | if (substr($blog_url, -1) == '?') { |
|---|
| 42 | $blog_settings->system->put('url_scan', 'query_string'); |
|---|
| 43 | } else { |
|---|
| 44 | $blog_settings->system->put('url_scan', 'path_info'); |
|---|
| 45 | } |
|---|
| 46 | |
|---|
| 47 | # --BEHAVIOR-- adminAfterBlogCreate |
|---|
| 48 | $core->callBehavior('adminAfterBlogCreate', $cur, $blog_id, $blog_settings); |
|---|
| 49 | dcPage::addSuccessNotice(sprintf(__('Blog "%s" successfully created'), html::escapeHTML($cur->blog_name))); |
|---|
| 50 | $core->adminurl->redirect("admin.blog", ['id' => $cur->blog_id]); |
|---|
| 51 | } catch (Exception $e) { |
|---|
| 52 | $core->error->add($e->getMessage()); |
|---|
| 53 | } |
|---|
| 54 | } |
|---|
| 55 | |
|---|
| 56 | if (!empty($_REQUEST['id'])) { |
|---|
| 57 | $edit_blog_mode = true; |
|---|
| 58 | include dirname(__FILE__) . '/blog_pref.php'; |
|---|
| 59 | } else { |
|---|
| 60 | dcPage::open(__('New blog'), dcPage::jsConfirmClose('blog-form'), |
|---|
| 61 | dcPage::breadcrumb( |
|---|
| 62 | [ |
|---|
| 63 | __('System') => '', |
|---|
| 64 | __('Blogs') => $core->adminurl->get("admin.blogs"), |
|---|
| 65 | __('New blog') => '' |
|---|
| 66 | ]) |
|---|
| 67 | ); |
|---|
| 68 | |
|---|
| 69 | echo |
|---|
| 70 | '<form action="' . $core->adminurl->get("admin.blog") . '" method="post" id="blog-form">' . |
|---|
| 71 | |
|---|
| 72 | '<div>' . $core->formNonce() . '</div>' . |
|---|
| 73 | '<p><label class="required" for="blog_id"><abbr title="' . __('Required field') . '">*</abbr> ' . __('Blog ID:') . '</label> ' . |
|---|
| 74 | form::field('blog_id', 30, 32, |
|---|
| 75 | [ |
|---|
| 76 | 'default' => html::escapeHTML($blog_id), |
|---|
| 77 | 'extra_html' => 'required placeholder="' . __('Blog ID') . '"' |
|---|
| 78 | ] |
|---|
| 79 | ) . '</p>' . |
|---|
| 80 | '<p class="form-note">' . __('At least 2 characters using letters, numbers or symbols.') . '</p> '; |
|---|
| 81 | |
|---|
| 82 | echo |
|---|
| 83 | '<p><label class="required" for="blog_name"><abbr title="' . __('Required field') . '">*</abbr> ' . __('Blog name:') . '</label> ' . |
|---|
| 84 | form::field('blog_name', 30, 255, |
|---|
| 85 | [ |
|---|
| 86 | 'default' => html::escapeHTML($blog_name), |
|---|
| 87 | 'extra_html' => 'required placeholder="' . __('Blog name') . '" lang="' . $core->auth->getInfo('user_lang') . '" ' . |
|---|
| 88 | 'spellcheck="true"' |
|---|
| 89 | ] |
|---|
| 90 | ) . '</p>' . |
|---|
| 91 | |
|---|
| 92 | '<p><label class="required" for="blog_url"><abbr title="' . __('Required field') . '">*</abbr> ' . __('Blog URL:') . '</label> ' . |
|---|
| 93 | form::url('blog_url', |
|---|
| 94 | [ |
|---|
| 95 | 'size' => 30, |
|---|
| 96 | 'default' => html::escapeHTML($blog_url), |
|---|
| 97 | 'extra_html' => 'required placeholder="' . __('Blog URL') . '"' |
|---|
| 98 | ] |
|---|
| 99 | ) . '</p>' . |
|---|
| 100 | |
|---|
| 101 | '<p class="area"><label for="blog_desc">' . __('Blog description:') . '</label> ' . |
|---|
| 102 | form::textarea('blog_desc', 60, 5, |
|---|
| 103 | [ |
|---|
| 104 | 'default' => html::escapeHTML($blog_desc), |
|---|
| 105 | 'extra_html' => 'lang="' . $core->auth->getInfo('user_lang') . '" spellcheck="true"' |
|---|
| 106 | ]) . '</p>' . |
|---|
| 107 | |
|---|
| 108 | '<p><input type="submit" accesskey="s" name="create" value="' . __('Create') . '" /></p>' . |
|---|
| 109 | '</form>'; |
|---|
| 110 | |
|---|
| 111 | dcPage::helpBlock('core_blog_new'); |
|---|
| 112 | dcPage::close(); |
|---|
| 113 | } |
|---|