Dotclear

source: admin/post.php @ 1315:220e119ae6c8

Revision 1315:220e119ae6c8, 5.4 KB checked in by Dsls, 11 years ago (diff)

Merge with default

Line 
1<?php
2# -- BEGIN LICENSE BLOCK ---------------------------------------
3#
4# This file is part of Dotclear 2.
5#
6# Copyright (c) 2003-2011 Olivier Meunier & Association Dotclear
7# Licensed under the GPL version 2.0 license.
8# See LICENSE file or
9# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
10#
11# -- END LICENSE BLOCK -----------------------------------------
12
13require dirname(__FILE__).'/../inc/admin/prepend.php';
14
15dcPage::check('usage,contentadmin');
16
17function savePost($form) {
18     global $_ctx;
19     $_ctx->setAlert('save');
20
21}
22
23function deletePost($form) {
24     print_r($form); exit;
25}
26
27$page_title = __('New entry');
28
29$can_view_page = true;
30$can_edit_post = $core->auth->check('usage,contentadmin',$core->blog->id);
31$can_publish = $core->auth->check('publish,contentadmin',$core->blog->id);
32$can_delete = false;
33
34$post_headlink = '<link rel="%s" title="%s" href="post.php?id=%s" />';
35$post_link = '<a href="post.php?id=%s" title="%s">%s</a>';
36
37$next_link = $prev_link = $next_headlink = $prev_headlink = null;
38
39# If user can't publish
40if (!$can_publish) {
41     $form->post_status = -2;
42}
43
44# Getting categories
45$categories_combo = array('&nbsp;' => '');
46try {
47     $categories = $core->blog->getCategories(array('post_type'=>'post'));
48     while ($categories->fetch()) {
49          $categories_combo[$categories->cat_id] = 
50               str_repeat('&nbsp;&nbsp;',$categories->level-1).
51               ($categories->level-1 == 0 ? '' : '&bull; ').
52               html::escapeHTML($categories->cat_title);
53     }
54} catch (Exception $e) { }
55
56# Status combo
57foreach ($core->blog->getAllPostStatus() as $k => $v) {
58     $status_combo[$k] = $v;
59}
60
61# Formaters combo
62foreach ($core->getFormaters() as $v) {
63     $formaters_combo[$v] = $v;
64}
65
66# Languages combo
67$rs = $core->blog->getLangs(array('order'=>'asc'));
68$all_langs = l10n::getISOcodes(0,1);
69$lang_combo = array('' => '', __('Most used') => array(), __('Available') => l10n::getISOcodes(1,1));
70while ($rs->fetch()) {
71     if (isset($all_langs[$rs->post_lang])) {
72          $lang_combo[__('Most used')][$all_langs[$rs->post_lang]] = $rs->post_lang;
73          unset($lang_combo[__('Available')][$all_langs[$rs->post_lang]]);
74     } else {
75          $lang_combo[__('Most used')][$rs->post_lang] = $rs->post_lang;
76     }
77}
78unset($all_langs);
79unset($rs);
80
81$form = new dcForm($core,'post','post.php');
82$form
83     ->addField(
84          new dcFieldText('post_title','', array(
85               'size'         => 20,
86               'required'     => true,
87               'label'        => __('Title'))))
88     ->addField(
89          new dcFieldTextArea('post_excerpt','', array(
90               'cols'         => 50,
91               'rows'         => 5,
92               'label'        => __("Excerpt:"))))
93     ->addField(
94          new dcFieldTextArea('post_content','', array(
95               'required'     => true,
96               'label'        => __("Content:"))))
97     ->addField(
98          new dcFieldTextArea('post_notes','', array(
99               'label'        => __("Notes"))))
100     ->addField(
101          new dcFieldSubmit('save',__('Save'),array(
102               'action' => 'savePost')))
103     ->addField(
104          new dcFieldSubmit('delete',__('Delete'),array(
105               'action' => 'deletePost')))
106     ->addField(
107          new dcFieldCombo('post_status',$core->auth->getInfo('user_post_status'),$status_combo,array(
108               'disabled' => !$can_publish,
109               'label' => __('Entry status:'))))
110     ->addField(
111          new dcFieldCombo('cat_id','',$categories_combo,array(
112               "label" => __('Category:'))))
113     ->addField(
114          new dcFieldText('post_dt','',array(
115               "label" => __('Published on:'))))
116     ->addField(
117          new dcFieldCombo('post_format',$core->auth->getOption('post_format'),$formaters_combo,array(
118               "label" => __('Text formating:'))))
119     ->addField(
120          new dcFieldCheckbox ('post_open_comment',$core->blog->settings->system->allow_comments,array(
121               "label" => __('Accept comments'))))
122     ->addField(
123          new dcFieldCheckbox ('post_open_tb',$core->blog->settings->system->allow_trackbacks,array(
124               "label" => __('Accept trackbacks'))))
125     ->addField(
126          new dcFieldCheckbox ('post_selected',false,array(
127               "label" => __('Selected entry'))))
128     ->addField(
129          new dcFieldCombo ('post_lang',$core->auth->getInfo('user_lang'),$lang_combo, array(
130               "label" => __('Entry lang:'))))
131     ->addField(
132          new dcFieldHidden ('id',''))
133;
134# Get entry informations
135if (!empty($_REQUEST['id']))
136{
137     $params['post_id'] = $_REQUEST['id'];
138     
139     $post = $core->blog->getPosts($params);
140     
141     if ($post->isEmpty())
142     {
143          $core->error->add(__('This entry does not exist.'));
144          $can_view_page = false;
145     }
146     else
147     {
148          $form->id = $post->post_id;
149          $form->cat_id = $post->cat_id;
150          $form->post_dt = date('Y-m-d H:i',strtotime($post->post_dt));
151          $form->post_format = $post->post_format;
152          $form->post_password = $post->post_password;
153          $form->post_url = $post->post_url;
154          $form->post_lang = $post->post_lang;
155          $form->post_title = $post->post_title;
156          $form->post_excerpt = $post->post_excerpt;
157          $form->post_excerpt_xhtml = $post->post_excerpt_xhtml;
158          $form->post_content = $post->post_content;
159          $form->post_content_xhtml = $post->post_content_xhtml;
160          $form->post_notes = $post->post_notes;
161          $form->post_status = $post->post_status;
162          $form->post_selected = (boolean) $post->post_selected;
163          $form->post_open_comment = (boolean) $post->post_open_comment;
164          $form->post_open_tb = (boolean) $post->post_open_tb;
165          $form->can_edit_post = $post->isEditable();
166          $form->can_delete= $post->isDeletable();
167         
168     }
169}
170
171$form->setup();
172
173/* DISPLAY
174-------------------------------------------------------- */
175$default_tab = 'edit-entry';
176if (!$can_edit_post) {
177     $default_tab = '';
178}
179if (!empty($_GET['co'])) {
180     $default_tab = 'comments';
181}
182
183$_ctx
184     ->fillPageTitle(__('Entries'),'posts.php')
185     ->fillPageTitle($page_title)
186     ->default_tab = $default_tab;
187
188$core->tpl->display('post.html.twig');
189?>
Note: See TracBrowser for help on using the repository browser.

Sites map