Dotclear

source: admin/post.php @ 1319:32528cac0405

Revision 1319:32528cac0405, 6.6 KB checked in by Dsls, 12 years ago (diff)

Continuing with twig -> post.php

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 dcFieldText('post_password','',array(
133               "maxlength" => 32,
134               "label" => __('Entry password:'))))
135     ->addField(
136          new dcFieldText('post_url','',array(
137               "maxlength" => 255,
138               "label" => __('Basename:'))))
139     ->addField(
140          new dcFieldHidden ('id',''))
141;
142# Get entry informations
143if (!empty($_REQUEST['id']))
144{
145     $params['post_id'] = $_REQUEST['id'];
146     
147     $post = $core->blog->getPosts($params);
148     
149     if ($post->isEmpty())
150     {
151          $core->error->add(__('This entry does not exist.'));
152          $can_view_page = false;
153     }
154     else
155     {
156          $form->id = $post_id = $post->post_id;
157          $form->cat_id = $post->cat_id;
158          $form->post_dt = date('Y-m-d H:i',strtotime($post->post_dt));
159          $form->post_format = $post->post_format;
160          $form->post_password = $post->post_password;
161          $form->post_url = $post->post_url;
162          $form->post_lang = $post->post_lang;
163          $form->post_title = $post->post_title;
164          $form->post_excerpt = $post->post_excerpt;
165          $form->post_excerpt_xhtml = $post->post_excerpt_xhtml;
166          $form->post_content = $post->post_content;
167          $form->post_content_xhtml = $post->post_content_xhtml;
168          $form->post_notes = $post->post_notes;
169          $form->post_status = $post->post_status;
170          $form->post_selected = (boolean) $post->post_selected;
171          $form->post_open_comment = (boolean) $post->post_open_comment;
172          $form->post_open_tb = (boolean) $post->post_open_tb;
173          $form->can_edit_post = $post->isEditable();
174          $form->can_delete= $post->isDeletable();
175          $page_title = __('Edit entry');
176
177     }
178}
179if ($post_id) {
180     $_ctx->post_id = $post->post_id;
181
182     $_ctx->preview_url =
183          $core->blog->url.$core->url->getURLFor('preview',$core->auth->userID().'/'.
184          http::browserUID(DC_MASTER_KEY.$core->auth->userID().$core->auth->getInfo('user_pwd')).
185          '/'.$post->post_url);
186         
187     
188     $form_comment = new dcForm($core,'add-comment','post.php');
189     $form_comment
190          ->addField(
191               new dcFieldText('comment_author','', array(
192                    'maxlength'         => 255,
193                    'required'     => true,
194                    'label'        => __('Name:'))))
195          ->addField(
196               new dcFieldText('comment_email','', array(
197                    'maxlength'         => 255,
198                    'required'     => true,
199                    'label'        => __('Email:'))))
200          ->addField(
201               new dcFieldText('comment_site','', array(
202                    'maxlength'         => 255,
203                    'label'        => __('Web site:'))))
204          ->addField(
205               new dcFieldTextArea('comment_content','', array(
206                    'required'     => true,
207                    'label'        => __('Comment:'))))
208          ->addField(
209               new dcFieldSubmit('add',__('Save'),array(
210                    'action' => 'addComment')))
211          ;
212
213     
214}
215
216$form->setup();
217
218/* DISPLAY
219-------------------------------------------------------- */
220$default_tab = 'edit-entry';
221if (!$can_edit_post) {
222     $default_tab = '';
223}
224if (!empty($_GET['co'])) {
225     $default_tab = 'comments';
226}
227
228$_ctx
229     ->fillPageTitle(html::escapeHTML($core->blog->name))
230     ->fillPageTitle(__('Entries'),'posts.php')
231     ->fillPageTitle($page_title)
232     ->default_tab = $default_tab;
233
234$core->tpl->display('post.html.twig');
235?>
Note: See TracBrowser for help on using the repository browser.

Sites map