Changeset 1053:96e69ef76fc9
- Timestamp:
- 12/03/12 14:29:47 (13 years ago)
- Branch:
- twig
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
admin/post.php
r1014 r1053 14 14 15 15 dcPage::check('usage,contentadmin'); 16 17 function savePost($form) { 18 global $core; 19 $core->page->getContext()->setMessage('save'); 20 21 } 22 23 function deletePost($form) { 24 print_r($form); exit; 25 } 26 16 27 $page_title = __('New entry'); 17 28 … … 36 47 $categories = $core->blog->getCategories(array('post_type'=>'post')); 37 48 while ($categories->fetch()) { 38 $categories_combo[ ] = new formSelectOption(39 str_repeat(' ',$categories->level-1). ($categories->level-1 == 0 ? '' : '• ').html::escapeHTML($categories->cat_title),40 $categories->cat_id41 );49 $categories_combo[$categories->cat_id] = 50 str_repeat(' ',$categories->level-1). 51 ($categories->level-1 == 0 ? '' : '• '). 52 html::escapeHTML($categories->cat_title); 42 53 } 43 54 } catch (Exception $e) { } … … 68 79 unset($rs); 69 80 70 71 72 81 $form = new dcForm($core,'post','post.php'); 73 82 $form … … 90 99 'label' => __("Notes")))) 91 100 ->addField( 92 new dcFieldSubmit('save',__('Save'),array())) 101 new dcFieldSubmit('save',__('Save'),array( 102 'action' => 'savePost'))) 93 103 ->addField( 94 new dcFieldSubmit('delete',__('Delete'),array())) 104 new dcFieldSubmit('delete',__('Delete'),array( 105 'action' => 'deletePost'))) 95 106 ->addField( 96 107 new dcFieldCombo('post_status',$core->auth->getInfo('user_post_status'),$status_combo,array( … … 118 129 new dcFieldCombo ('post_lang',$core->auth->getInfo('user_lang'),$lang_combo, array( 119 130 "label" => __('Entry lang:')))) 131 ->addField( 132 new dcFieldHidden ('id','')) 120 133 ; 121 122 123 134 # Get entry informations 124 135 if (!empty($_REQUEST['id'])) … … 135 146 else 136 147 { 137 $form-> post_id = $post->post_id;148 $form->id = $post->post_id; 138 149 $form->cat_id = $post->cat_id; 139 150 $form->post_dt = date('Y-m-d H:i',strtotime($post->post_dt)); … … 144 155 $form->post_title = $post->post_title; 145 156 $form->post_excerpt = $post->post_excerpt; 146 $ post_excerpt_xhtml = $post->post_excerpt_xhtml;157 $form->post_excerpt_xhtml = $post->post_excerpt_xhtml; 147 158 $form->post_content = $post->post_content; 148 $ post_content_xhtml = $post->post_content_xhtml;159 $form->post_content_xhtml = $post->post_content_xhtml; 149 160 $form->post_notes = $post->post_notes; 150 161 $form->post_status = $post->post_status; … … 152 163 $form->post_open_comment = (boolean) $post->post_open_comment; 153 164 $form->post_open_tb = (boolean) $post->post_open_tb; 165 $form->can_edit_post = $post->isEditable(); 166 $form->can_delete= $post->isDeletable(); 154 167 155 $page_title = __('Edit entry');156 157 $can_edit_post = $post->isEditable();158 $can_delete= $post->isDeletable();159 160 $next_rs = $core->blog->getNextPost($post,1);161 $prev_rs = $core->blog->getNextPost($post,-1);162 163 if ($next_rs !== null) {164 $next_link = sprintf($post_link,$next_rs->post_id,165 html::escapeHTML($next_rs->post_title),__('next entry').' »');166 $next_headlink = sprintf($post_headlink,'next',167 html::escapeHTML($next_rs->post_title),$next_rs->post_id);168 }169 170 if ($prev_rs !== null) {171 $prev_link = sprintf($post_link,$prev_rs->post_id,172 html::escapeHTML($prev_rs->post_title),'« '.__('previous entry'));173 $prev_headlink = sprintf($post_headlink,'previous',174 html::escapeHTML($prev_rs->post_title),$prev_rs->post_id);175 }176 177 try {178 $core->media = new dcMedia($core);179 } catch (Exception $e) {}180 168 } 181 169 } 182 170 183 # Format excerpt and content 184 if (!empty($_POST) && $can_edit_post) 185 { 186 $post_format = $_POST['post_format']; 187 $post_excerpt = $_POST['post_excerpt']; 188 $post_content = $_POST['post_content']; 189 190 $post_title = $_POST['post_title']; 191 192 $cat_id = (integer) $_POST['cat_id']; 193 194 if (isset($_POST['post_status'])) { 195 $post_status = (integer) $_POST['post_status']; 196 } 197 198 if (empty($_POST['post_dt'])) { 199 $post_dt = ''; 200 } else { 201 $post_dt = strtotime($_POST['post_dt']); 202 $post_dt = date('Y-m-d H:i',$post_dt); 203 } 204 205 $post_open_comment = !empty($_POST['post_open_comment']); 206 $post_open_tb = !empty($_POST['post_open_tb']); 207 $post_selected = !empty($_POST['post_selected']); 208 $post_lang = $_POST['post_lang']; 209 $post_password = !empty($_POST['post_password']) ? $_POST['post_password'] : null; 210 211 $post_notes = $_POST['post_notes']; 212 213 if (isset($_POST['post_url'])) { 214 $post_url = $_POST['post_url']; 215 } 216 217 $core->blog->setPostContent( 218 $post_id,$post_format,$post_lang, 219 $post_excerpt,$post_excerpt_xhtml,$post_content,$post_content_xhtml 220 ); 221 } 171 $form->setup(); 222 172 223 # Create or update post224 if (!empty($_POST) && !empty($_POST['save']) && $can_edit_post)225 {226 $cur = $core->con->openCursor($core->prefix.'post');227 228 $cur->post_title = $post_title;229 $cur->cat_id = ($cat_id ? $cat_id : null);230 $cur->post_dt = $post_dt ? date('Y-m-d H:i:00',strtotime($post_dt)) : '';231 $cur->post_format = $post_format;232 $cur->post_password = $post_password;233 $cur->post_lang = $post_lang;234 $cur->post_title = $post_title;235 $cur->post_excerpt = $post_excerpt;236 $cur->post_excerpt_xhtml = $post_excerpt_xhtml;237 $cur->post_content = $post_content;238 $cur->post_content_xhtml = $post_content_xhtml;239 $cur->post_notes = $post_notes;240 $cur->post_status = $post_status;241 $cur->post_selected = (integer) $post_selected;242 $cur->post_open_comment = (integer) $post_open_comment;243 $cur->post_open_tb = (integer) $post_open_tb;244 245 if (isset($_POST['post_url'])) {246 $cur->post_url = $post_url;247 }248 249 # Update post250 if ($post_id)251 {252 try253 {254 # --BEHAVIOR-- adminBeforePostUpdate255 $core->callBehavior('adminBeforePostUpdate',$cur,$post_id);256 257 $core->blog->updPost($post_id,$cur);258 259 # --BEHAVIOR-- adminAfterPostUpdate260 $core->callBehavior('adminAfterPostUpdate',$cur,$post_id);261 262 http::redirect('post.php?id='.$post_id.'&upd=1');263 }264 catch (Exception $e)265 {266 $core->error->add($e->getMessage());267 }268 }269 else270 {271 $cur->user_id = $core->auth->userID();272 273 try274 {275 # --BEHAVIOR-- adminBeforePostCreate276 $core->callBehavior('adminBeforePostCreate',$cur);277 278 $return_id = $core->blog->addPost($cur);279 280 # --BEHAVIOR-- adminAfterPostCreate281 $core->callBehavior('adminAfterPostCreate',$cur,$return_id);282 283 http::redirect('post.php?id='.$return_id.'&crea=1');284 }285 catch (Exception $e)286 {287 $core->error->add($e->getMessage());288 }289 }290 }291 292 if (!empty($_POST['delete']) && $can_delete)293 {294 try {295 # --BEHAVIOR-- adminBeforePostDelete296 $core->callBehavior('adminBeforePostDelete',$post_id);297 $core->blog->delPost($post_id);298 http::redirect('posts.php');299 } catch (Exception $e) {300 $core->error->add($e->getMessage());301 }302 }303 173 304 174 /* DISPLAY … … 323 193 echo $core->page->render('post.html.twig',array( 324 194 'edit_size'=> $core->auth->getOption('edit_size'))); 195 196 325 197 ?> -
inc/admin/class.dc.admincontext.php
r1014 r1053 6 6 protected $js_var; 7 7 protected $head; 8 protected $globals; 8 9 9 10 protected $core; … … 16 17 $this->jsCommon(); 17 18 $this->blogs = array(); 19 $this->globals = array(); 18 20 if ($this->core->auth->blog_count > 1 && $this->core->auth->blog_count < 20) { 19 21 $rs_blogs = $core->getBlogs(array('order'=>'LOWER(blog_name)','limit'=>20)); … … 110 112 } 111 113 public function getGlobals() { 112 return array();114 return $this->globals; 113 115 } 114 116 public function getName() { 115 117 return 'AdminPage'; 116 118 } 119 120 public function setMessage($message) { 121 $this->globals['page_message'] = $message; 122 return $this; 123 } 124 125 public function addError($error) { 126 if (!isset($this->globals['page_errors'])) 127 $this->globals['page_errors']=array(); 128 $this->globals['page_errors'][] = $error; 129 return $this; 130 } 131 117 132 public function getFilters() 118 133 { -
inc/admin/class.dc.form.php
r1014 r1053 20 20 $this->getAttribute('name')."');\n") 21 21 ->subcompile($this->getNode('body')) 22 ->write("\$context['dc_form']->renderHiddenWidgets();\n") 22 23 ->write("\$context['dc_form']->endForm();\n") 23 24 ; … … 101 102 public function renderWidget($name,$attributes=array()) { 102 103 $field = $this->currentForm->$name; 103 if ($field) 104 echo $this->template->renderBlock( 105 $field->getWidgetBlock(), 106 array_merge($field->getAttributes(),array('attr'=>$attributes)), 107 $this->blocks); 108 104 if ($field) { 105 echo $this->template->renderBlock( 106 $field->getWidgetBlock(), 107 array_merge($field->getAttributes(),array('attr'=>$attributes)), 108 $this->blocks); 109 } 110 } 111 112 public function renderHiddenWidgets() { 113 foreach ($this->currentForm->getHiddenFields() as $h) { 114 $this->renderWidget($h->getName()); 115 } 109 116 } 110 117 … … 132 139 } 133 140 141 class InvalidFieldException extends Exception { 142 } 143 134 144 135 145 class dcForm { … … 138 148 protected $action; 139 149 protected $fields; 140 150 protected $method; 151 protected $submitfields; 152 protected $hiddenfields; 153 protected $errors; 154 155 private function addNonce() { 156 $this->addField(new dcFieldHidden(array('xd_check'), $this->core->getNonce())); 157 } 158 141 159 public function __construct($core,$name,$action, $method='POST') { 142 160 $this->core = $core; … … 146 164 $this->fields = array(); 147 165 $this->core->page->getExtension('dc_form')->addForm($this); 166 $this->submitfields = array(); 167 $this->hiddenfields = array(); 168 $this->errors = array(); 169 if ($method == 'POST') { 170 $this->addNonce(); 171 } 148 172 } 149 173 … … 152 176 } 153 177 178 public function getErrors() { 179 return $this->errors; 180 } 181 154 182 public function addField(dcField $f) { 183 184 if ($f instanceof dcFieldAction) { 185 $this->submitfields[$f->getName()]=$f; 186 } 187 if ($f instanceof dcFieldHidden) { 188 $this->hiddenfields[$f->getName()]=$f; 189 } 190 155 191 $this->fields[$f->getName()]=$f; 156 192 return $this; … … 184 220 } 185 221 222 public function isSubmitted() { 223 $from = ($this->method == 'POST')?$_POST:$_GET; 224 echo "form fields :\n"; 225 } 226 227 public function setup() { 228 $from = ($this->method=='POST')?$_POST:$_GET; 229 foreach ($this->fields as $f) { 230 $f->setup($from); 231 } 232 foreach ($this->submitfields as $f) { 233 if ($f->isDefined()) { 234 $ret = call_user_func ($f->getAction(),$this); 235 return; 236 } 237 } 238 } 239 240 public function check() { 241 foreach ($this->fields as $f) { 242 try { 243 $f->check(); 244 } catch (InvalidFieldException $e) { 245 $this->errors[]=$e->getMessage(); 246 } 247 } 248 } 249 250 public function getHiddenFields() { 251 return $this->hiddenfields; 252 } 253 186 254 } 187 255 … … 191 259 protected $value; 192 260 protected $id; 261 protected $defined; 193 262 194 263 protected function getNID($nid) { … … 208 277 $this->attributes['id'] = $this->id; 209 278 $this->attributes['value'] = $this->value; 279 $this->defined = false; 210 280 211 281 } … … 227 297 228 298 public function check() { 229 230 } 299 if (!$this->defined && $this->attributes['defined']) { 300 throw new InvalidFieldException(sprintf('Field "%s" is mandatory'),$this->attributes['label']); 301 } 302 303 } 304 305 public function setup($from) { 306 if (isset($from[$this->id])) { 307 $this->value = $from[$this->id]; 308 $this->defined = true; 309 } 310 } 311 312 public function isDefined() { 313 return $this->defined; 314 } 315 231 316 } 232 317 … … 264 349 } 265 350 266 class dcFieldSubmit extends dcField { 351 abstract class dcFieldAction extends dcField { 352 protected $action; 353 public function __construct($name, $value, $attributes = array()) { 354 parent::__construct($name, $value, $attributes); 355 if (isset($attributes['action'])) { 356 $this->action = $attributes['action']; 357 } 358 } 359 public function getAction() { 360 return $this->action; 361 } 362 } 363 364 class dcFieldSubmit extends dcFieldAction { 267 365 268 366 public function getWidgetBlock() { -
inc/admin/default-templates/layout.html.twig
r993 r1053 40 40 {% block content %} 41 41 <h2>Mon premier blog › <span class="page-title"></span></h2> 42 {% endblock %} 42 {% if page_message is not empty %} 43 <p class="message">{{page_message}}</p> 44 {% endif %} 45 {% if page_errors is not empty %} 46 <div class="error"> 47 <p><strong>Errors :</strong></p> 48 <ul> 49 {% for error in page_errors %} 50 <li>{{error}}</li> 51 {% endfor %} 52 </ul> 53 </div> 54 {% endif %} 55 {% endblock %} 56 43 57 </div> 44 58 </div>
Note: See TracChangeset
for help on using the changeset viewer.