Changeset 1414:ce67e9c592b7
- Timestamp:
- 08/16/13 15:48:37 (12 years ago)
- Branch:
- twig
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
admin/index.php
r1413 r1414 304 304 } 305 305 306 $_ctx-> fillPageTitle(__('Dashboard'));306 $_ctx->setBreadCrumb(__('Dashboard').' : '.html::escapeHTML($core->blog->name), false); 307 307 $core->tpl->display('index.html.twig'); 308 308 ?> -
admin/js/_post.js
r1280 r1414 127 127 fn: function() { excerptTb.switchMode(formatField.value); }, 128 128 cookie: 'dcx_post_excerpt', 129 hide: $('#post_excerpt').val() == '' 129 hide: $('#post_excerpt').val() == '', 130 legend_click: true 130 131 }); 131 132 -
admin/plugin.php
r1413 r1414 90 90 # No plugin or content found 91 91 if (!$has_content) { 92 $_ctx-> fillPageTitle(__('Plugin not found'));92 $_ctx->setBreadcrumb(__('Plugin not found')); 93 93 $_ctx->addError(__('The plugin you reached does not exist or does not have an admin page.')); 94 94 $core->tpl->display('plugin.html.twig'); -
admin/post.php
r1413 r1414 15 15 dcPage::check('usage,contentadmin'); 16 16 17 function savePost($form) { 18 global $_ctx; 19 $_ctx->setAlert('save'); 20 21 } 22 23 function deletePost($form) { 24 print_r($form); exit; 17 class PostActions 18 { 19 public static function savePost($form) { 20 global $_ctx, $core; 21 try { 22 $form->check($_ctx); 23 $_ctx->setAlert('save'); 24 $form->cat_id = (integer) $form->cat_id; 25 26 if (!empty($form->post_dt)) { 27 try 28 { 29 $post_dt = strtotime($form->post_dt); 30 if ($post_dt == false || $post_dt == -1) { 31 $bad_dt = true; 32 throw new Exception(__('Invalid publication date')); 33 } 34 $form->post_dt = date('Y-m-d H:i',$post_dt); 35 } 36 catch (Exception $e) 37 { 38 $core->error->add($e->getMessage()); 39 } 40 } 41 $post_excerpt = $form->post_excerpt; 42 $post_content = $form->post_content; 43 $post_excerpt_xhtml = ''; 44 $post_content_xhtml = ''; 45 $core->blog->setPostContent( 46 $form->id,$form->post_format,$form->post_lang, 47 $post_excerpt,$post_excerpt_xhtml,$post_content,$post_content_xhtml 48 ); 49 $form->post_excerpt = $post_excerpt; 50 $form->post_content = $post_content; 51 $form->post_excerpt_xhtml = $post_excerpt_xhtml; 52 $form->post_content_xhtml = $post_content_xhtml; 53 54 $cur = $core->con->openCursor($core->prefix.'post'); 55 56 $cur->post_title = $form->post_title; 57 $cur->cat_id = $form->cat_id ? $form->cat_id : null; 58 $cur->post_dt = $form->post_dt ? date('Y-m-d H:i:00',strtotime($form->post_dt)) : ''; 59 $cur->post_format = $form->post_format; 60 $cur->post_password = $form->post_password; 61 $cur->post_lang = $form->post_lang; 62 $cur->post_title = $form->post_title; 63 $cur->post_excerpt = $form->post_excerpt; 64 $cur->post_excerpt_xhtml = $form->post_excerpt_xhtml; 65 $cur->post_content = $form->post_content; 66 $cur->post_content_xhtml = $form->post_content_xhtml; 67 $cur->post_notes = $form->post_notes; 68 $cur->post_status = $form->post_status; 69 $cur->post_selected = (integer) $form->post_selected; 70 $cur->post_open_comment = (integer) $form->post_open_comment; 71 $cur->post_open_tb = (integer) $form->post_open_tb; 72 73 if (!empty($form->post_url)) { 74 $cur->post_url = $form->post_url; 75 } 76 77 # Update post 78 if ($form->id) 79 { 80 # --BEHAVIOR-- adminBeforePostUpdate 81 $core->callBehavior('adminBeforePostUpdate',$cur,$form->id); 82 83 $core->blog->updPost($form->id,$cur); 84 85 # --BEHAVIOR-- adminAfterPostUpdate 86 $core->callBehavior('adminAfterPostUpdate',$cur,$form->id); 87 88 http::redirect('post.php?id='.$form->id.'&upd=1'); 89 } 90 else 91 { 92 $cur->user_id = $core->auth->userID(); 93 # --BEHAVIOR-- adminBeforePostCreate 94 $core->callBehavior('adminBeforePostCreate',$cur); 95 96 $return_id = $core->blog->addPost($cur); 97 98 # --BEHAVIOR-- adminAfterPostCreate 99 $core->callBehavior('adminAfterPostCreate',$cur,$return_id); 100 101 http::redirect('post.php?id='.$return_id.'&crea=1'); 102 } 103 104 } catch (Exception $e) { 105 $ctx->setError($e->getMessage()); 106 } 107 } 108 function deletePost($form) { 109 echo $form->id->getValue(); exit; 110 } 25 111 } 26 112 27 113 $page_title = __('New entry'); 28 114 $post_id=''; 29 115 $can_view_page = true; 30 116 $can_edit_post = $core->auth->check('usage,contentadmin',$core->blog->id); … … 67 153 $rs = $core->blog->getLangs(array('order'=>'asc')); 68 154 $all_langs = l10n::getISOcodes(0,1); 69 $lang_combo = array('' => '', __('Most used') => array(), __('Available') => l10n::getISOcodes( 1,1));155 $lang_combo = array('' => '', __('Most used') => array(), __('Available') => l10n::getISOcodes(0,1)); 70 156 while ($rs->fetch()) { 71 157 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]]);158 $lang_combo[__('Most used')][$rs->post_lang] = $all_langs[$rs->post_lang]; 159 unset($lang_combo[__('Available')][$rs->post_lang]); 74 160 } else { 75 $lang_combo[__('Most used')][$rs->post_lang] = $ rs->post_lang;161 $lang_combo[__('Most used')][$rs->post_lang] = $all_langs[$rs->post_lang]; 76 162 } 77 163 } … … 83 169 ->addField( 84 170 new dcFieldText('post_title','', array( 85 ' size' => 20,171 'maxlength' => 255, 86 172 'required' => true, 87 173 'label' => __('Title')))) … … 100 186 ->addField( 101 187 new dcFieldSubmit('save',__('Save'),array( 102 'action' => 'savePost')))188 'action' => array('PostActions','savePost')))) 103 189 ->addField( 104 190 new dcFieldSubmit('delete',__('Delete'),array( … … 124 210 "label" => __('Accept trackbacks')))) 125 211 ->addField( 126 new dcFieldCheckbox ('post_selected', false,array(212 new dcFieldCheckbox ('post_selected',array(1=>false),array( 127 213 "label" => __('Selected entry')))) 128 214 ->addField( … … 225 311 $default_tab = 'comments'; 226 312 } 227 313 $page_title_edit = __('Edit entry'); 228 314 $_ctx 229 ->fillPageTitle(html::escapeHTML($core->blog->name)) 230 ->fillPageTitle(__('Entries'),'posts.php') 231 ->fillPageTitle($page_title) 315 ->setBreadCrumb( 316 array( 317 html::escapeHTML($core->blog->name) => '', 318 __('Entries') => 'posts.php', 319 ($post_id ? $page_title_edit : $page_title) => '' 320 )) 232 321 ->default_tab = $default_tab; 233 322 -
admin/posts.php
r1413 r1414 187 187 188 188 $_ctx 189 -> fillPageTitle(__('Entries'),'posts.php');189 ->setBreadCrumb(array(__('Entries') => 'posts.php')); 190 190 191 191 -
inc/admin/class.dc.admincontext.php
r1319 r1414 354 354 355 355 /** 356 Fill the page title356 Add a section to the breadcrumb 357 357 358 358 $title can be: … … 365 365 @return object self 366 366 */ 367 public function fillPageTitle($title,$url='') 368 { 369 if (is_bool($title)) { 370 $this->protected_globals['page_global'] = $title; 371 } 372 elseif (null === $title) { 373 $this->protected_globals['page_global'] = false; 374 $this->protected_globals['page_title'] = array(); 375 } 376 else { 377 $this->protected_globals['page_title'][] = array( 378 'title' => $title, 379 'link' => $url 380 ); 367 public function appendBreadCrumbItem($title,$url='',$class='') 368 { 369 $this->protected_globals['page_title'][] = array( 370 'title' => $title, 371 'link' => $url, 372 'class' => $class 373 ); 374 } 375 376 /** 377 Fill the page title 378 379 $title can be: 380 a string for page title part or 381 TRUE to add blog name at the begining of title or 382 NULL to empty/reset title 383 384 @param mixed $title A title part 385 @param boolean $url Link of the title part 386 @return object self 387 */ 388 public function setBreadCrumb($breadcrumb, $with_home_link=true) 389 { 390 if ($with_home_link) { 391 $this->appendBreadCrumbItem('<img src="style/dashboard.png" alt="" />','index.php','go_home'); 392 } else { 393 $this->appendBreadCrumbItem('<img src="style/dashboard-alt.png" alt="" />'.$breadcrumb); 394 return $this; 395 } 396 if (is_array($breadcrumb)) { 397 foreach ($breadcrumb as $title => $bc) { 398 $this->appendBreadCrumbItem($title,$bc); 399 } 400 } else { 401 $this->appendBreadcrumbItem($breadcrumb); 381 402 } 382 403 return $this; -
inc/admin/class.dc.form.php
r1319 r1414 277 277 public function renderField($name,$attributes=array(),$extra=array()) 278 278 { 279 $field = $this->currentForm-> $name;279 $field = $this->currentForm->getField($name); 280 280 if ($field) { 281 281 $attr = $field->getAttributes($attributes); … … 396 396 /** @var array(dcField) list of form errors */ 397 397 protected $errors; 398 398 /** @var array() list of form properties */ 399 protected $properties; 400 401 399 402 /** 400 403 * Class constructor … … 420 423 $this->hiddenfields = array(); 421 424 $this->errors = array(); 425 $this->properties = array(); 422 426 if ($method == 'POST') { 423 427 $this->addNonce(); … … 425 429 } 426 430 431 432 /** 433 * setProperty - sets form property 434 * 435 * @param string $name the property name. 436 * @param mixed $value the property value. 437 * 438 * @access public 439 */ 440 public function setProperty($prop,$value) { 441 $this->properties[$prop]=$value; 442 } 443 444 /** 445 * getProperty - gets form property 446 * 447 * @param string $name the property name. 448 * 449 * @return mixed the property value, null if no property found. 450 * @access public 451 */ 452 public function getProperty($prop) { 453 if (isset($this->properties[$prop])) { 454 return $this->properties[$prop]; 455 } else { 456 return null; 457 } 458 } 427 459 /** 428 460 * addTemplate - Adds a template file to enrich form fields … … 532 564 } 533 565 566 /** 567 * getField - retrieves a field form form 568 * 569 * @param string the field name 570 * 571 * @access public 572 * 573 * @return dcForm the requested field 574 */ 575 public function getField($name) { 576 if (isset($this->fields[$name])) { 577 return $this->fields[$name]; 578 } else { 579 return null; 580 } 581 } 582 534 583 /** 535 584 * removeField - removes a field … … 634 683 public function __get($name) 635 684 { 636 return isset($this->fields[$name]) ? 637 $this->fields[$name] : null; 685 if (isset($this->fields[$name])) { 686 $f = $this->fields[$name]; 687 if ($f->isMultiple()) { 688 return $f->getValues(); 689 } else { 690 return $f->getValue(); 691 } 692 } else { 693 return $this->getProperty($name); 694 } 638 695 } 639 696 … … 650 707 { 651 708 if (isset($this->fields[$name])) { 652 $this->fields[$name]->setValue($value); 653 } 654 } 655 656 /* public function isSubmitted() 657 { 658 $from = $this->method == 'POST' ? $_POST : $_GET; 659 } 660 */ 709 $f = $this->fields[$name]; 710 if ($f->isMultiple()) { 711 $this->fields[$name]->setValues($value); 712 } else { 713 $this->fields[$name]->setValue($value); 714 } 715 } else { 716 $this->setProperty($name,$value); 717 } 718 } 661 719 662 720 /** … … 667 725 protected function setupFields() { 668 726 $from = $this->method == 'POST' ? $_POST : $_GET; 669 foreach ($this->fields as $f) { 670 $f->setup($from); 727 if (!empty($from)) { 728 foreach ($this->fields as $f) { 729 $f->setup($from); 730 } 671 731 } 672 732 } … … 680 740 */ 681 741 protected function handleActions($submitted) { 742 $hasActions = false; 682 743 foreach ($submitted as $f) { 683 744 $action = $f->getAction(); 684 745 if ($action != NULL) { 746 if (!$hasActions) { 747 $this->core->callBehavior('coreBeforeFormSubmit',$this); 748 } 749 $hasActions = true; 685 750 $ret = call_user_func($action,$this); 686 751 } 752 } 753 if ($hasActions) { 754 $this->core->callBehavior('coreAfterFormSubmit',$this); 687 755 } 688 756 } … … 706 774 707 775 /** 776 * isSubmitted - returns whether form has been submitted or not 777 * 778 * @access public 779 * 780 * @return boolean true if the form has been submitted. 781 */ 782 public function isSubmitted() { 783 foreach ($this->submitfields as $f) { 784 if ($f->isDefined()) { 785 return true; 786 } 787 } 788 return false; 789 } 790 791 /** 708 792 * setup - sets up the form, given the parameters given to the page 709 793 * should be called after fields have been defined. … … 726 810 * @access public 727 811 */ 728 public function check() 729 { 812 public function check(dcAdminContext $ctx) 813 { 814 $valid = true; 730 815 foreach ($this->fields as $f) { 731 816 try { … … 733 818 } 734 819 catch (InvalidFieldException $e) { 735 $this->errors[] = $e->getMessage(); 820 $valid = false; 821 $ctx->addError($e->getMessage()); 736 822 } 823 } 824 if (!$valid) { 825 throw new InvalidFieldException ("Some fields are missing"); 737 826 } 738 827 } … … 796 885 797 886 /** 887 * defines whether a field is multiple or not 888 * 889 * @param boolean true if the field is multiple 890 * 891 * @access public 892 */ 893 public function setMultiple($m=true) { 894 $this->multiple = $m; 895 } 896 897 /** 898 * Returns whether can have multiple values or not 899 * 900 * @return boolean true if the field has multiple values 901 * 902 * @access public 903 */ 904 public function isMultiple($m=true) { 905 return $this->multiple; 906 } 907 908 /** 798 909 * setNID - defines fiels name & id 799 910 * … … 905 1016 abstract public function getWidgetBlock(); 906 1017 1018 public function isEmpty() { 1019 return (count($this->values) == 0) || empty($this->values[0]); 1020 } 907 1021 908 1022 /** … … 977 1091 public function check() 978 1092 { 979 if (!$this->defined && $this->options['mandatory']) { 980 throw new InvalidFieldException(sprintf( 981 'Field "%s" is mandatory', 982 $this->attributes['label']) 983 ); 1093 if (isset($this->options ['required']) && $this->options['required']) { 1094 if (!$this->defined || $this->isEmpty()) { 1095 throw new InvalidFieldException(sprintf( 1096 'Field "%s" is mandatory', 1097 $this->options['label']) 1098 ); 1099 } 984 1100 } 985 1101 } … … 1088 1204 class dcFieldCheckbox extends dcField 1089 1205 { 1206 protected $checked; 1207 1208 public function __construct($name,$values,$options=array()) 1209 { 1210 $val = array(); 1211 if (!is_array($values)) { 1212 $values = array("1" => !empty($values)); 1213 } 1214 $this->checked = $values; 1215 parent::__construct($name,array_keys($values),$options); 1216 } 1217 1218 /** 1219 * setValue - sets field value 1220 * 1221 * @param mixed $value field value. 1222 * @param int $offset value offset to define (default 0). 1223 * 1224 * @access public 1225 */ 1226 public function setValue($value,$offset=0) { 1227 $this->checked[$this->values[0]] = $value; 1228 } 1229 1230 public function getValue($offset=0) { 1231 $val = parent::getValue($offset); 1232 if (isset($this->checked[$val])) { 1233 return $this->checked[$val]?$val:false; 1234 } else { 1235 return false; 1236 } 1237 } 1238 1239 public function getAttributes($options) 1240 { 1241 $a = parent::getAttributes($options); 1242 1243 $val = $a['value']; 1244 if (isset($this->checked[$val]) && $this->checked[$val]) { 1245 $a['checked']='checked'; 1246 } 1247 return $a; 1248 } 1249 1250 public function setup($from) 1251 { 1252 $values = $this->parseValues($from); 1253 foreach ($this->checked as $k=>&$v) { 1254 $v=false; 1255 } 1256 foreach ($values as $v) { 1257 $this->checked[$v] = true; 1258 } 1259 $this->setValues(array_keys($this->checked)); 1260 } 1261 1090 1262 public function getWidgetBlock() 1091 1263 { … … 1094 1266 1095 1267 public function getDefaultValue() { 1096 return 0;1268 return false; 1097 1269 } 1098 1270 } … … 1139 1311 { 1140 1312 protected $combo; 1313 protected $combo_values; 1141 1314 1142 1315 public function __construct($name,$value,$combo,$options=array()) 1143 1316 { 1144 1317 $this->combo = $combo; 1318 $this->combo_values = $combo; 1319 foreach ($combo as $k=>$v) { 1320 if (is_array($v)) { 1321 unset($this->combo_values[$k]); 1322 $this->combo_values = array_merge($v,$this->combo_values); 1323 } 1324 } 1145 1325 parent::__construct($name,$value,$options); 1146 1326 } … … 1161 1341 } 1162 1342 foreach ($values as &$v) { 1163 if (!isset($this->combo[$v])) 1164 $v = $this->getDefaultValue(); 1343 if (!isset($this->combo_values[$v])) { 1344 $v = $this->getDefaultValue(); 1345 } 1165 1346 } 1166 1347 return $values; -
inc/admin/default-templates/forms/form_layout.html.twig
r1319 r1414 57 57 {% block field_attr %} 58 58 {% spaceless %} 59 {% if id %}id="{{id}}"{% endif %} name="{{name}}" {% if read_only %} disabled="disabled"{% endif %}{ % if required %} required="required"{% endif %}{% if maxlength %} maxlength="{{ maxlength}}"{% endif %}{% if pattern %} pattern="{{ pattern }}"{% endif %}59 {% if id %}id="{{id}}"{% endif %} name="{{name}}" {% if read_only %} disabled="disabled"{% endif %}{#{% if required %} required="required"{% endif %}#}{% if maxlength %} maxlength="{{ maxlength }}"{% endif %}{% if checked %} checked="{{ checked }}"{% endif %}{% if pattern %} pattern="{{ pattern }}"{% endif %} 60 60 {% for attrname,attrvalue in attr %}{{attrname}}="{{attrvalue}}" {% endfor %} 61 61 {% endspaceless %} -
inc/admin/default-templates/layout.html.twig
r1319 r1414 5 5 {% block header %} 6 6 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> 7 <title>{% block title %}{ % for part in page_title %}{{ part.title }} - {% endfor %}{% if current_blog.name is not empty %}{{current_blog.name}} - {% endif %}{{vendor_name}} - {{version}}{% endblock %}</title>7 <title>{% block title %}{{ (page_title|last).title|striptags }} - {% if current_blog.name is not empty %}{{current_blog.name}} - {% endif %}{{vendor_name}} - {{version}}{% endblock %}</title> 8 8 <meta name="ROBOTS" content="NOARCHIVE,NOINDEX,NOFOLLOW" /> 9 9 <meta name="GOOGLEBOT" content="NOSNIPPET" /> … … 59 59 {% endif %} 60 60 <h2> 61 { %- if not page_global %}{{current_blog.name}} › {% endif %}61 {#{%- if not page_global %}{{current_blog.name}} › {% endif %}#} 62 62 {%- for part in page_title %} 63 63 {%- if loop.last %}<span class="page-title">{% endif %} 64 {%- if part.link is not empty %}<a href="{{ part.link }}" >{{ part.title }}</a>{% else %}{{ part.title }}{% endif %}65 {%- if loop.last %}</span>{% else %} ›{% endif %}64 {%- if part.link is not empty %}<a href="{{ part.link }}"{% if part.class is not empty %} class="{{part.class}}"{% endif %}>{{ part.title }}</a>{% else %}{{ part.title }}{% endif %} 65 {%- if loop.last %}</span>{% else %} {% if loop.index0 == 1 %} : {% else %} › {% endif %}{% endif %} 66 66 {%- endfor -%} 67 67 </h2> -
plugins/aboutConfig/index.php
r1315 r1414 143 143 } 144 144 $_ctx->default_tab = !empty($_GET['part']) && $_GET['part'] == 'global' ? 'global' : 'local'; 145 $_ctx-> fillPageTitle('about:config');145 $_ctx->setBreadCrumb('about:config'); 146 146 $core->tpl->display('@aboutConfig/index.html.twig'); 147 147 ?>
Note: See TracChangeset
for help on using the changeset viewer.