Changeset 1152:fbd922f6ed09
- Timestamp:
- 04/02/13 13:05:04 (12 years ago)
- Branch:
- twig
- Files:
-
- 4 added
- 7 edited
- 2 moved
Legend:
- Unmodified
- Added
- Removed
-
admin/posts.php
r1147 r1152 126 126 127 127 128 class month ComboFilter extends comboFilter{128 class monthdcFilterCombo extends dcFilterCombo { 129 129 public function applyFilter($params) { 130 130 $month=$this->avalues['values'][0]; … … 138 138 139 139 $filterSet 140 ->addFilter(new comboFilter( 141 'users',__('Author'), __('Author'), 'user_id', $users_combo)) 142 ->addFilter(new comboFilter( 140 ->addFilter(new dcFilterRichCombo( 141 'users',__('Author'), __('Author'), 'user_id', $users_combo,array( 142 'multiple' => true))) 143 ->addFilter(new dcFilterRichCombo( 143 144 'category',__('Category'), __('Category'), 'cat_id', $categories_combo)) 144 ->addFilter(new comboFilter(145 ->addFilter(new dcFilterRichCombo( 145 146 'post_status',__('Status'), __('Status'), 'post_status', $status_combo)) 146 ->addFilter(new comboFilter(147 ->addFilter(new dcFilterRichCombo( 147 148 'lang',__('Lang'), __('Lang'), 'post_lang', $lang_combo)) 148 ->addFilter(new booleanFilter(149 ->addFilter(new dcFilterCombo( 149 150 'selected',__('Selected'), __('The post : '),'post_selected', $selected_combo)) 150 ->addFilter(new month ComboFilter(151 ->addFilter(new monthdcFilterCombo( 151 152 'month',__('Month'),__('Month'), 'post_month', $dt_m_combo,array('singleval' => 1))) 152 ->addFilter(new textFilter(153 ->addFilter(new dcFilterText( 153 154 'search',__('Contains'),__('The entry contains'), 'search',20,255)); 154 155 156 157 158 $lposts = new dcItemList ($core,array('lposts','form-entries'),'posts_actions.php'); 159 $lposts->addTemplate('posts_cols.html.twig'); 160 161 $lposts->setFilterSet($filterSet); 162 163 $lposts 164 ->addColumn(new dcColumn('title',__('Title'),'post_title')) 165 ->addColumn(new dcColumn('cat',__('Category'),'cat_title')) 166 ->addColumn(new dcColumn('date',__('Date'),'post_date')) 167 ->addColumn(new dcColumn('datetime',__('Date and Time'),'post_date')) 168 ->addColumn(new dcColumn('author',__('Author'),'post_author')) 169 ->addColumn(new dcColumn('status',__('Status'),'post_status')); 170 171 172 $lposts->setup(); 155 173 $filterSet->setup(); 156 174 … … 159 177 $params=new ArrayObject(); 160 178 $filterSet->applyFilters($params); 179 $posts = $core->blog->getPosts($params); 180 $lposts->setEntries($posts); 161 181 $_ctx->filters = '['.print_r($params->getArrayCopy(),true).']'; 162 182 -
inc/admin/class.dc.filter.php
r1148 r1152 14 14 15 15 16 class dcFilterSetExtension extends Twig_Extension {17 private $filtersets;18 19 public function __construct($core)20 {21 $this->core = $core;22 $this->tpl = 'formfilter_layout.html.twig';23 }24 25 public function initRuntime(Twig_Environment $environment)26 {27 $this->core->tpl->getExtension('dc_form')->addTemplate($this->tpl);28 }29 30 31 public function getFunctions()32 {33 return array(34 'filterset' => new Twig_Function_Method(35 $this,36 'renderFilterSet',37 array(38 'is_safe' => array('html'),39 'needs_context' => true40 )));41 }42 43 44 45 public function renderFilterSet($context,$name,$attributes=array())46 {47 $context['filtersetname']=$name;48 echo $this->core->tpl->getExtension('dc_form')->renderBlock(49 'filterset',50 $context51 );52 }53 54 55 public function getName()56 {57 return 'dc_filterset';58 }59 60 }61 62 63 16 class dcFilterSet extends dcForm { 64 17 protected $filters; /// <b>array</b> lists of currently applied filters 18 protected $static_filters; 19 protected $all_filters; 65 20 protected $form_prefix; /// <b>string</b> displayed form prefix 66 21 protected $action; /// <b>string</b> form action page … … 69 24 protected $core; 70 25 26 public static function __init__($env) { 27 $env->getExtension('dc_form')->addTemplate('@forms/formfilter_layout.html.twig'); 28 $env->addFunction( 29 new Twig_SimpleFunction( 30 'filterset', 31 'dcFilterSet::renderFilterSet', 32 array( 33 'is_safe' => array('html'), 34 'needs_context' => true, 35 'needs_environment' => true 36 ))); 37 } 38 39 public static function renderFilterSet($env,$context,$name,$attributes=array()) 40 { 41 $context['filtersetname']=$name; 42 echo $env->getExtension('dc_form')->renderWidget( 43 'filterset', 44 $context 45 ); 46 } 71 47 /** 72 48 Inits dcFilterSet object … … 78 54 $this->form_prefix=$form_prefix; 79 55 $this->filters = new ArrayObject(); 56 $this->static_filters = new ArrayObject(); 57 $this->all_filters = new ArrayObject(); 80 58 $this->action = $action; 81 59 $this->filtered = false; … … 87 65 $form_combo = array(); 88 66 $form_combo['-'] = ''; 67 foreach ($this->all_filters as $filter) { 68 $filter->init(); 69 } 89 70 foreach ($this->filters as $filter) { 90 $filter->init();91 71 $form_combo[$filter->id]=$filter->name; 92 72 } … … 110 90 ; 111 91 $this->setupFields(); 112 $submitted = $this->getSubmittedFields();113 92 /* Use cases : 114 93 (1) $_POST not empty for formfilter fields : … … 130 109 $tmp = substr($k,strlen($this->form_prefix)); 131 110 $count = preg_match($allowed_actions,$tmp,$match); 132 echo $action;133 111 if ($count==1) { 134 112 $action = $match[1]; … … 137 115 } 138 116 } 117 139 118 if ($action !== false) { 140 119 // Use case (1) 141 120 if ($action != 'clear_filters' && $action != 'reset') { 142 $this->setupEditFilters($ _POST);121 $this->setupEditFilters($this->all_filters,$_POST); 143 122 if ($action == 'add'){ 144 if (isset($_POST[$p.'add_filter']) 145 && isset($this->filters[$_POST[$p.'add_filter']])) { 146 $this->filters[$_POST[$p.'add_filter']]->add(); 123 $fname = $p.'add_filter'; 124 if (isset($_POST[$fname]) 125 && isset($this->filters[$_POST[$fname]])) { 126 $this->filters[$_POST[$fname]]->add(); 147 127 } 148 128 } elseif (strpos($action,'del_') === 0) { 149 129 $count = preg_match('#del_(.+)_([0-9]+)#',$action,$match); 150 echo "action=".$action;151 130 if (($count == 1) && isset($this->filters[$match[1]])) { 152 131 $this->filters[$match[1]]->remove($match[2]); 153 echo "remove";154 132 } 155 133 } elseif ($action=="apply") { … … 165 143 if (isset($_POST[$p."query"])) { 166 144 parse_str($_POST[$p."query"],$out); 167 $this->setupAppliedFilters($ out);145 $this->setupAppliedFilters($this->all_filters,$out); 168 146 if ($action == 'reset') { 169 $this->setupEditFilters($out); 147 $this->setupEditFilters($this->all_filters,$out); 148 } elseif ($action == 'clear_filters') { 149 $this->setupEditFilters($this->static_filters,$out); 150 foreach ($this->filters as $f) { 151 $f->cleanup(); 152 } 170 153 } 171 154 } … … 184 167 $get = new ArrayObject(array_merge($this->loadFilters(),$get)); 185 168 } 186 $this->setupEditFilters($get); 187 $this->setupAppliedFilters($get); 188 } 189 $queryParams = $this->getListedFilters(); 169 $this->setupEditFilters($this->all_filters,$get); 170 171 $this->setupAppliedFilters($this->all_filters,$get); 172 } 173 foreach ($this->static_filters as $f) { 174 if (!$f->isEnabled()) { 175 $f->add(); 176 } 177 } 178 $queryParams = $this->getAppliedFilters(); 190 179 $this->addField( 191 180 new dcFieldHidden($this->form_prefix.'query', … … 224 213 @param form_data <b>array</b> form values (usually $_GET or $_POST) 225 214 */ 226 protected function setupEditFilters ($f orm_data) {215 protected function setupEditFilters ($filters,$form_data) { 227 216 $this->hideform = true; 228 foreach ($ this->filters as $filter) {217 foreach ($filters as $filter) { 229 218 $filter->setupFields ($form_data); 230 219 } 231 220 } 232 protected function setupAppliedFilters ($f orm_data) {233 foreach ($ this->filters as $filter) {221 protected function setupAppliedFilters ($filters,$form_data) { 222 foreach ($filters as $filter) { 234 223 $filter->setupAppliedFilter ($form_data); 235 224 } … … 251 240 } 252 241 } 242 foreach ($this->static_filters as $f) { 243 $f->serialize($arr); 244 } 253 245 return $arr; 254 246 } … … 261 253 $filter->setFormPrefix($this->form_prefix); 262 254 $filter->setFilterSet($this); 263 $this->filters[$filter->id] = $filter; 255 $this->all_filters[$filter->id] = $filter; 256 if ($filter->isStatic()) { 257 $this->static_filters[$filter->id] = $filter; 258 } else { 259 $this->filters[$filter->id] = $filter; 260 } 264 261 return $this; 265 262 } 263 266 264 public function getContext() { 267 265 $fcontext = new ArrayObject(); 266 $sfcontext = new ArrayObject(); 268 267 foreach ($this->filters as $f) { 269 268 if($f->isEnabled()) { … … 271 270 } 272 271 } 272 foreach ($this->static_filters as $f) { 273 $f->appendEditLines ($sfcontext); 274 } 273 275 return array( 274 276 'active_filters' => $fcontext, 277 'static_filters' => $sfcontext, 275 278 'prefix'=>$this->form_prefix); 276 279 } 277 280 278 protected function get ListedFilters() {281 protected function getAppliedFilters() { 279 282 $arr = new ArrayObject(); 280 foreach ($this-> filters as $f) {281 if ($f->is Enabled())283 foreach ($this->all_filters as $f) { 284 if ($f->isApplied()) 282 285 $f->updateAppliedValues($arr); 283 286 } … … 292 295 */ 293 296 public function applyFilters($params) { 294 foreach ($this-> filters as $filter) {297 foreach ($this->all_filters as $filter) { 295 298 if ($filter->isApplied()) { 296 299 $filter->applyFilter($params); … … 318 321 public $name; ///<b>string</b> filter name 319 322 public $desc; ///<b>string</b> field description 323 public $filter_id; ///<b>string</b> field id (global to the page) 320 324 protected $request_param; ///<b>string</b> resulting parameter array key 321 protected $enabled; ///<b>string</b> true if filter is enabled 322 protected $fields; ///<b>array</b> currently edited values 325 protected $field; ///<b>array</b> currently edited values 323 326 protected $avalues; ///<b>array</b> currently applied values 324 public $filter_id; ///<b>string</b> field id (global to the page) 325 326 public function __construct ($id,$name,$desc,$request_param) { 327 $this->id = $id; 328 $this->name=$name; 329 $this->desc = $desc; 330 $this->request_param = $request_param; 331 $this->enabled=false; 332 $this->avalues = array(); 333 $this->filter_id = $this->id; 334 $this->fields = array(); 335 } 336 337 public function setupFields($data) { 338 $val = $this->parseData($data); 339 $pos=0; 340 foreach($val['values'] as $v) { 341 $this->addField($pos,$v); 342 $pos++; 343 } 344 $this->enabled = ($pos> 0); 345 }// abstract public function setupFields($data); 346 347 348 public function init() { 327 protected $static; 328 protected $options; 329 protected $multiple; 330 331 public function __construct ($id,$name,$desc,$request_param,$options=array()) { 332 $this->id = $id; 333 $this->name =$name; 334 $this->desc = $desc; 335 $this->request_param = $request_param; 336 $this->avalues = array(); 337 $this->filter_id = $this->id; 338 $this->static = false; 339 $this->multiple = false; 340 $this->options = $options; 341 if (isset($options['static']) && $options['static']) { 342 $this->static = true; 343 } 344 if (isset($options['multiple']) && $options['multiple']) { 345 $this->multiple = true; 346 } 349 347 } 350 348 … … 357 355 */ 358 356 protected function parseData($data) { 359 $count=0; 360 $arr = array(); 361 while (isset($data[$this->getFieldId($count)])) { 362 $arr[] = $data[$this->getFieldId($count)]; 363 $count++; 364 } 357 $arr = $this->field->parseValues($data); 365 358 return array('values' => $arr); 366 359 } 367 360 361 public function isStatic() { 362 return $this->static; 363 } 364 365 public function setupFields($data) { 366 $this->field->setup($data); 367 } 368 369 370 public function init() { 371 } 372 373 public function cleanup() { 374 $this->field->setValues(array()); 375 } 376 368 377 public function setupAppliedFilter($data) { 369 378 $this->avalues = $this->parseData($data); … … 371 380 372 381 public function updateAppliedValues($arr) { 373 foreach ($this->avalues['values'] as $k=>$v) { 374 $arr[$this->getFieldID($k)]=$v; 375 } 382 $arr[$this->filter_id] = $this->avalues['values']; 376 383 } 377 384 … … 396 403 397 404 /** 398 Get a field id399 400 @param pos <b>integer</b> position of field, in case of multiple field (0 if only 1 field set, default value)401 @return <b>string</b> The field ID402 */403 protected function getFieldId($pos=0) {404 if ($pos == 0) {405 return $this->filter_id;406 } else {407 return $this->filter_id.'_'.$pos;408 }409 }410 411 412 /**413 405 Tells whether the filter is enabled or not 414 406 … … 416 408 */ 417 409 public function isEnabled() { 418 return $this->enabled;419 } 420 421 protected abstract function add Field($pos,$value=NULL);410 return count($this->field) != 0; 411 } 412 413 protected abstract function addValue($value=NULL); 422 414 423 415 /** … … 425 417 */ 426 418 public function add() { 427 $this->addField(count($this->fields)); 428 $this->enabled = true; 419 if (count($this->field) > 1 && !$this->multiple) 420 return; 421 $this->addValue(); 429 422 } 430 423 … … 433 426 */ 434 427 public function remove($pos) { 435 if (isset($this->fields[$pos])) { 436 $this->filterset->removeField($this->fields[$pos]); 437 array_splice($this->fields,$pos,1); 438 for ($cur=$pos; $cur<count($this->fields);$cur++) { 439 $this->filterset->renameField($this->fields[$cur],$this->getFieldID($cur)); 440 } 441 $this->enabled = (count($this->fields)!=0); 428 $values = $this->field->getValues(); 429 if (isset($values[$pos])) { 430 $this->field->delValue($pos); 442 431 } 443 432 … … 447 436 448 437 public function appendEditLines($ctx) { 449 foreach ($this->field sas $cur => $f) {438 foreach ($this->field->getValues() as $cur => $f) { 450 439 $line = new ArrayObject(); 451 440 $line['lineclass'] = $this->id; … … 465 454 466 455 public function serialize($arr) { 467 for ($cur=0; $cur < count($this->fields); $cur++) { 468 $arr[$this->getFieldId($cur)]=$this->fields[$cur]->getValue(); 456 if (count($this->fields) == 1) { 457 $arr[$this->filter_id]=$this->field->getValue(); 458 } else { 459 $arr[$this->filter_id]=$this->field->getValues(); 469 460 } 470 461 } … … 492 483 493 484 485 486 class dcFilterText extends dcFilter { 487 488 public function init() { 489 $this->field = new dcFieldText( 490 $this->filter_id, 491 NULL); 492 $this->filterset->addField($this->field); 493 $this->multiple = false; 494 } 495 496 497 public function appendSingleLine($line,$pos) { 498 $line['ffield'] = $this->field->getName(); 499 if ($this->static) { 500 $line['display_inline'] = true; 501 } 502 503 if ($pos == 0) { 504 $line['fwidget']='filter_text'; 505 $line['desc']=$this->desc; 506 }; 507 } 508 509 protected function addValue($value=NULL) { 510 if ($value === NULL) { 511 $value = ''; 512 } 513 $this->field->addValue($value); 514 } 515 516 public function applyFilter($params) { 517 $params[$this->request_param]=$this->avalues['values'][0]; 518 } 519 520 } 494 521 /** 495 522 @ingroup DC_CORE … … 499 526 Handle combo filter on admin side. Can be single or multi-valued 500 527 */ 501 class comboFilter extends dcFilter { 502 protected $options; 528 class dcFilterCombo extends dcFilter { 529 protected $combo; 530 531 public function __construct($id,$name,$desc,$request_param,$combo,$options=array()) { 532 parent::__construct($id,$name,$desc,$request_param,$options); 533 $this->combo = $combo; 534 } 535 public function init() { 536 $this->field = new dcFieldCombo( 537 $this->filter_id, 538 NULL, 539 $this->combo); 540 $this->filterset->addField($this->field); 541 } 542 543 protected function addValue($value=NULL) { 544 if ($value === NULL) { 545 $value = current($this->combo); 546 } 547 $this->field->addValue($value); 548 } 549 550 public function appendSingleLine($line,$pos) { 551 if ($this->static) { 552 $line['display_inline'] = true; 553 } 554 $line['ffield'] = $this->field->getName(); 555 $line['foffset'] = $pos; 556 if ($pos == 0) { 557 $line['fwidget']='filter_combo'; 558 $line['desc']=$this->desc; 559 } else { 560 $line['fwidget']='filter_combo_cont'; 561 }; 562 } 563 564 public function applyFilter($params) { 565 $attr = $this->request_param; 566 if ($this->multiple) 567 $params[$attr]=$this->avalues['values']; 568 else 569 $params[$attr]=$this->avalues['values'][0]; 570 } 571 572 } 573 574 /** 575 @ingroup DC_CORE 576 @nosubgrouping 577 @brief abstract filter class. 578 579 Handle combo filter on admin side. Can be single or multi-valued 580 */ 581 class dcFilterRichCombo extends dcFilterCombo { 503 582 protected $verb; 504 protected $extra;505 506 public function __construct($id,$name,$desc,$request_param,$options,$extra=array()) {507 parent::__construct($id,$name,$desc,$request_param);508 $this->options = $options;509 $this->extra = $extra;510 }511 583 512 584 public function init() { … … 519 591 'isnot'=>__('is not')) 520 592 ); 593 $this->filterset->addField($this->verb); 521 594 } 522 595 523 596 protected function parseData($data) { 524 597 $val = parent::parseData($data); 525 $val['verb'] = $this->verb->parseValue($data); 598 $v = $this->verb->parseValues($data); 599 if (isset($v[0]) && $v[0] === 'isnot') 600 $val['verb'] = 'isnot'; 601 else 602 $val['verb'] ='is'; 526 603 return $val; 527 604 } 528 605 529 protected function addField($pos,$value=NULL) {530 if ($value === NULL) {531 $value = current($this->options);532 }533 $f = new dcFieldCombo(534 $this->getFieldID($pos),535 $value,536 $this->options);537 $this->filterset->addField($f);538 $this->fields[]=$f;539 }540 541 606 public function setupFields($data) { 542 /*$val = $this->parseData($data);543 $this->verb->setup($data);544 $pos=0;545 foreach($val['values'] as $v) {546 $this->addField($pos,$v);547 }548 $this->enabled = (count($this->fields) != 0);*/549 607 parent::setupFields($data); 550 608 $this->verb->setup($data); 551 $this->filterset->addField($this->verb);552 } 609 } 610 553 611 public function updateAppliedValues($arr) { 554 612 parent::updateAppliedValues($arr); 555 if ($this->enabled) { 556 $arr[$this->verb->getName()] = $this->verb->getValue(); 557 } 558 } 559 public function add() { 560 if (isset($this->extra['singleval']) && (count($this->fields) > 0)) 561 return; 562 parent::add(); 613 $arr['verb'] = $this->verb->getValue(); 563 614 } 564 615 565 616 public function appendSingleLine($line,$pos) { 566 $f = $this->fields[$pos]; 567 $line['ffield'] = $f->getName(); 568 617 parent::appendSingleLine($line,$pos); 569 618 if ($pos == 0) { 570 $line['fwidget']='filter_combo';571 619 $line['fverb'] = $this->verb->getName(); 572 $line['desc']=$this->desc; 573 } else { 574 $line['fwidget']='filter_combo_cont'; 575 }; 620 $line['fwidget']='filter_richcombo'; 621 } 576 622 } 577 623 … … 582 628 583 629 public function applyFilter($params) { 630 parent::applyFilter($params); 584 631 $attr = $this->request_param; 585 632 if ($this->avalues['verb'] != "is") { 586 633 $params[$attr."_not"] = true; 587 634 } 588 if (isset($this->extra['singleval']))589 $params[$attr]=$this->avalues['values'][0];590 else591 $params[$attr]=$this->avalues['values'];592 635 } 593 636 594 637 } 595 638 596 class booleanFilter extends dcFilter { 597 protected $options; 598 protected $verb; 599 600 public function __construct($id,$name,$desc,$request_param,$options) { 601 parent::__construct($id,$name,$desc,$request_param); 602 $this->options = $options; 603 } 604 605 606 607 public function appendSingleLine($line,$pos) { 608 $f = $this->fields[$pos]; 609 $line['ffield'] = $f->getName(); 610 611 if ($pos == 0) { 612 $line['fwidget']='filter_boolean'; 613 $line['desc']=$this->desc; 614 }; 615 } 616 617 protected function addField($pos,$value=NULL) { 618 if (count($this->fields)>0) 619 return; 620 if ($value === NULL) { 621 $value = 1; 622 } 623 $f = new dcFieldCombo( 624 $this->getFieldID($pos), 625 $value, 626 $this->options); 627 $this->filterset->addField($f); 628 $this->fields[]=$f; 629 } 630 631 public function applyFilter($params) { 632 $params[$this->request_param]=$this->avalues['values'][0]; 633 } 634 635 } 636 637 class textFilter extends dcFilter { 638 protected $options; 639 protected $verb; 640 641 public function __construct($id,$name,$desc,$request_param,$options) { 642 parent::__construct($id,$name,$desc,$request_param); 643 $this->options = $options; 644 } 645 646 public function setupFields($data) { 647 $val = $this->parseData($data); 648 foreach($val['values'] as $k=>$v) { 649 $this->addField($k,$v); 650 } 651 $this->enabled = (count($this->fields) != 0); 652 } 653 654 public function appendSingleLine($line,$pos) { 655 $f = $this->fields[$pos]; 656 $line['ffield'] = $f->getName(); 657 658 if ($pos == 0) { 659 $line['fwidget']='filter_boolean'; 660 $line['desc']=$this->desc; 661 }; 662 } 663 664 protected function addField($pos,$value=NULL) { 665 if (count($this->fields)>0) 666 return; 667 if ($value === NULL) { 668 $value = ''; 669 } 670 $f = new dcFieldText( 671 $this->getFieldID($pos), 672 $value); 673 $this->filterset->addField($f); 674 $this->fields[]=$f; 675 } 676 677 public function applyFilter($params) { 678 $params[$this->request_param]=$this->avalues['values'][0]; 679 } 680 681 } 682 639 640 641 dcFilterSet::__init__($GLOBALS['core']->tpl); 683 642 ?> -
inc/admin/class.dc.form.php
r1147 r1152 90 90 { 91 91 $this->core = $core; 92 $this->tpl = 'form_layout.html.twig';92 $this->tpl = array('@forms/form_layout.html.twig'); 93 93 $this->forms = array(); 94 $this->blocks = array(); 94 95 $this->currentForm = null; 95 96 } … … 98 99 { 99 100 $this->twig = $environment; 100 $this->template = $this->twig->loadTemplate($this->tpl); 101 $this->blocks = $this->template->getBlocks(); 101 $this->twig->getLoader()->addPath(dirname(__FILE__).'/default-templates/forms','forms'); 102 foreach ($this->tpl as $tpl) { 103 $this->template = $this->twig->loadTemplate($tpl); 104 $this->blocks = array_merge($this->blocks,$this->template->getBlocks()); 105 } 102 106 } 103 107 104 108 public function addTemplate($tpl) { 105 $t = $this->twig->loadTemplate($tpl); 106 $this->blocks = array_merge($this->blocks,$t->getBlocks()); 109 $this->tpl[]=$tpl; 110 if (isset($this->twig)) { 111 $this->template = $this->twig->loadTemplate($tpl); 112 $this->blocks = array_merge($this->blocks,$this->template->getBlocks()); 113 } 107 114 } 108 115 … … 115 122 { 116 123 return array( 117 'form_field' => new Twig_Function_Method(118 $this,119 'renderWidget',124 new Twig_SimpleFunction( 125 'widget', 126 array($this,'renderWidget'), 120 127 array('is_safe' => array('html')) 121 128 ), 122 '_form_is_choice_group' => new Twig_Function_Method(123 $this,124 'isChoiceGroup',129 new Twig_SimpleFunction( 130 'haswidget', 131 array($this,'hasWidget'), 125 132 array('is_safe' => array('html')) 126 133 ), 127 '_form_is_choice_selected' => new Twig_Function_Method( 128 $this, 129 'isChoiceSelected', 134 new Twig_SimpleFunction( 135 'form_field', 136 array($this,'renderField'), 137 array('is_safe' => array('html')) 138 ), 139 new Twig_SimpleFunction( 140 '_form_is_choice_group', 141 array($this,'isChoiceGroup'), 142 array('is_safe' => array('html')) 143 ), 144 new Twig_SimpleFunction( 145 '_form_is_choice_selected', 146 array($this,'isChoiceSelected'), 130 147 array('is_safe' => array('html')) 131 148 ) … … 148 165 } 149 166 150 public function renderBlock($name,$attr) { 167 public function hasWidget($name) { 168 return isset($this->blocks[$name]); 169 } 170 public function renderWidget($name,$attr) { 171 if (!isset($this->blocks[$name])) 172 return ''; 151 173 echo $this->template->renderBlock( 152 174 $name, … … 160 182 } 161 183 162 public function render Widget($name,$attributes=array(),$extra=array())184 public function renderField($name,$attributes=array(),$extra=array()) 163 185 { 164 186 $field = $this->currentForm->$name; 165 187 if ($field) { 166 $attr = $field->getAttributes( );188 $attr = $field->getAttributes($attributes); 167 189 if (isset($attr['attr'])) { 168 190 $attr['attr'] = array_merge($attr['attr'],$attributes); … … 170 192 $attr['attr'] = $attributes; 171 193 } 172 $this->render Block(194 $this->renderWidget( 173 195 $field->getWidgetBlock(), 174 196 array_merge( … … 183 205 { 184 206 foreach ($this->currentForm->getHiddenFields() as $h) { 185 $this->render Widget($h->getName());207 $this->renderField($h->getName()); 186 208 } 187 209 } … … 240 262 protected $errors; 241 263 264 public function addTemplate($t) { 265 $this->core->tpl->getExtension('dc_form')->addTemplate($t); 266 } 242 267 243 268 /** … … 355 380 $this->fields[$newname] = $field; 356 381 } 357 //print_r($this->fields);358 382 } 359 383 public function begin() … … 386 410 { 387 411 if (isset($this->fields[$name])) { 388 $this->fields[$name]->set Attribute('value',$value);412 $this->fields[$name]->setValue($value); 389 413 } 390 414 } … … 449 473 * Template form field 450 474 */ 451 abstract class dcField 452 { 453 protected $ attributes;475 abstract class dcField implements Countable 476 { 477 protected $options; 454 478 protected $name; 455 protected $value ;479 protected $values; 456 480 protected $id; 481 protected $multiple; 457 482 protected $defined; 458 483 … … 468 493 } 469 494 470 public function __construct($name,$value ,$attributes=array())495 public function __construct($name,$values,$options=array()) 471 496 { 472 497 $this->setNID($name); 473 $this->attributes = $attributes; 474 $this->setValue($value); 475 $this->attributes['name'] = $this->name; 476 $this->attributes['id'] = $this->id; 498 $this->options = new ArrayObject($options); 499 if ($values === NULL){ 500 $values = array(); 501 } 502 $this->setValues($values); 477 503 $this->defined = false; 478 } 479 480 public function setValue($value) { 481 $this->value = $value; 482 $this->attributes['value'] = $this->value; 483 } 484 485 public function getValue() { 486 return $this->value; 504 $this->multiple = (isset($options['multiple']) && $options['multiple']); 505 506 } 507 508 public function setValue($value,$offset=0) { 509 $this->values[$offset] = $value; 510 } 511 512 public function setValues($values) { 513 if (is_array($values)) { 514 $this->values = $values; 515 } elseif ($values !== NULL) { 516 $this->values = array($values); 517 } 518 519 } 520 521 public function getValues() { 522 return $this->values; 523 } 524 525 public function getValue($offset=0) { 526 if (isset($this->values[$offset])) { 527 return $this->values[$offset]; 528 } 529 } 530 531 public function addValue($value) { 532 $this->values[] = $value; 533 } 534 public function delValue($offset) { 535 if (isset($this->values[$offset])) { 536 array_splice($this->values,$offset,1); 537 } 538 } 539 540 public function count() { 541 return count($this->values); 487 542 } 488 543 489 544 public function __toString() 490 545 { 491 return $this->value;546 return join(',',$this->values); 492 547 } 493 548 494 549 abstract public function getWidgetBlock(); 495 550 496 public function setAttribute($name,$value) 497 { 498 $this->attributes[$name] = $value; 499 } 500 501 public function getAttributes() 502 { 503 return $this->attributes; 504 } 505 551 public function getAttributes($options) 552 { 553 $offset = isset($options['offset']) ? $options['offset'] : 0; 554 555 $attr = $this->options->getArrayCopy(); 556 if (isset($this->values[$offset])) { 557 $attr['value'] = $this->values[$offset]; 558 } else { 559 $attr['value'] = $this->getDefaultValue(); 560 } 561 if ($offset==0) { 562 $attr['id']=$this->id; 563 } 564 $attr['name'] = $this->name; 565 if ($this->multiple) { 566 $attr['name'] = $attr['name'].'[]'; 567 } 568 return $attr; 569 } 570 571 public function getDefaultValue() { 572 return ''; 573 } 574 506 575 public function getName() 507 576 { 508 577 return $this->name; 509 578 } 579 510 580 public function setName($name) { 511 581 $this->setNID($name); 512 $this->attributes['name'] = $this->name;513 $this->attributes['id'] = $this->id;514 582 } 515 583 516 584 public function check() 517 585 { 518 if (!$this->defined && $this-> attributes['defined']) {586 if (!$this->defined && $this->options['mandatory']) { 519 587 throw new InvalidFieldException(sprintf( 520 588 'Field "%s" is mandatory', … … 524 592 } 525 593 526 public function parseValue($from) { 527 if (isset($from[$this->id])) { 528 return $from[$this->id]; 529 } 530 return null; 594 public function parseValues($from) { 595 if (isset($from[$this->name])) { 596 $n = $from[$this->name]; 597 if (!is_array($n)) { 598 $n = array($n); 599 } 600 return $n; 601 } 602 return array(); 531 603 } 532 604 533 605 public function setup($from) 534 606 { 535 $value = $this->parseValue($from);536 if ( $value !== null) {537 $this->setValue ($value);607 $values = $this->parseValues($from); 608 if (count($values)) { 609 $this->setValues($values); 538 610 $this->defined = true; 539 611 } … … 546 618 } 547 619 620 548 621 /** 549 622 * Template form field of type "password" … … 599 672 return "field_checkbox"; 600 673 } 674 675 public function getDefaultValue() { 676 return 0; 677 } 601 678 } 602 679 … … 607 684 { 608 685 protected $action; 609 610 public function __construct($name,$value ,$attributes=array())611 { 612 parent::__construct($name,$value ,$attributes);613 614 if (isset($ attributes['action'])) {615 $this->action = $ attributes['action'];686 687 public function __construct($name,$values,$options=array()) 688 { 689 parent::__construct($name,$values,$options); 690 691 if (isset($options['action'])) { 692 $this->action = $options['action']; 616 693 } else { 617 694 $this->action = NULL; 618 695 } 619 696 } 620 697 621 698 public function getAction() 622 699 { … … 641 718 class dcFieldCombo extends dcField 642 719 { 643 protected $options; 644 645 public function __construct($name,$value,$options,$attributes=array()) 646 { 647 $this->options = $options; 648 parent::__construct($name,$value,$attributes); 649 $this->attributes['options']=$options; 720 protected $combo; 721 722 public function __construct($name,$value,$combo,$options=array()) 723 { 724 $this->combo = $combo; 725 parent::__construct($name,$value,$options); 650 726 } 651 727 … … 655 731 } 656 732 657 public function parseValue($from) { 658 659 $v = parent::parseValue($from); 660 if (!isset($this->options[$v])) { 661 return $this->value; 662 } else { 663 return $v; 664 } 665 } 666 } 733 public function getDefaultValue() { 734 return current($this->combo); 735 } 736 737 public function parseValues($from) { 738 $values = parent::parseValues($from); 739 if (!is_array($values)) { 740 $values = array($values); 741 } 742 foreach ($values as &$v) { 743 if (!isset($this->combo[$v])) 744 $v = $this->getDefaultValue(); 745 } 746 return $values; 747 } 748 749 public function getAttributes($options) { 750 $attr = parent::getAttributes($options); 751 $attr['options'] = $this->combo; 752 return $attr; 753 } 754 } 755 667 756 ?> -
inc/admin/default-templates/forms/form_layout.html.twig
r1148 r1152 48 48 49 49 {% block field_checkbox %} 50 {% spaceless %} 50 {% set type = type|default('checkbox') %} 51 {% set nestedlabel = true %} 52 {% set labelclass = "classic" %} 53 {{ block('field_input') }} 54 {#{% spaceless %} 55 51 56 {% if label is not empty %} 52 57 <label for="{{name}}" class="classic"> … … 56 61 {{ label }}</label> 57 62 {% endif %} 58 {% endspaceless %} 63 {% endspaceless %}#} 59 64 {% endblock field_checkbox %} 60 65 … … 105 110 {% if label is not empty %} 106 111 {% if required is not empty %} 107 {% set labelclass = labelclass +" required" %}112 {% set labelclass = labelclass ~ " required" %} 108 113 {% endif %} 109 114 <label for="{{name}}" {% if labelclass is not empty %}class="{{labelclass}}"{% endif %} {% if required is not empty %}<abbr title="{{__('Required field')}}">*</abbr>{% else %}>{% endif %} {{label}} -
inc/admin/default-templates/forms/formfilter_layout.html.twig
r1147 r1152 31 31 </div> 32 32 <div class="col30"> 33 {% for f in fenv.static_filters %} 34 {{block(f.fwidget)}} 35 {% endfor %} 33 36 </div> 34 37 <p class="clear margintop"></p> … … 50 53 51 54 {% block filter_combo %} 55 {% if f.display_inline is defined -%} 56 <p id='{{f.filter_id}}'>{{form_field(f.ffield,{},{'label':f.desc,'nestedlabel': true, 'labelclass':'classic' })}}</p> 57 {%- else -%} 58 <td id='{{f.filter_id}}' title='{{f.desc}}' class="filter-title" colspan="2">{{f.desc}} : </td> 59 <td >{{ form_field(f.ffield) }}</td> 60 {%- endif %} 61 {% endblock %} 62 63 {% block filter_combo_cont %} 64 {% if f.display_inline is defined -%} 65 <p id='{{filter_id}}'>{{form_field(f.ffield,{'label':__('or :')})}}</p> 66 {%- else -%} 67 <td id='{{filter_id}}' colspan="2">{{ __('or :') }} </td><td>{{ form_field(f.ffield) }}</td> 68 {%- endif %} 69 {% endblock %} 70 71 72 {% block filter_richcombo %} 52 73 <td id='{{filterd_id}}' title='{{f.desc}}' class="filter-title">{{f.desc}} : </td> 53 74 <td>{{ form_field(f.fverb)}}</td> … … 55 76 {% endblock %} 56 77 57 {% block filter_combo_cont %}58 <td id='{{filter_id}}' colspan="2">{{ __('or :') }} </td><td>{{ form_field(f.ffield) }}</td>59 {% endblock %}60 78 61 79 {% block filter_boolean %} … … 64 82 {% endblock %} 65 83 84 {% block filter_text %} 85 {% if f.display_inline is defined -%} 86 <p id='{{filter_id}}'>{{form_field(f.ffield,{},{'label':f.desc,'nestedlabel': true, 'labelclass':'classic' })}}</p> 87 {%- else -%} 88 <td id='{{filterd_id}}' title='{{f.desc}}' class="filter-title" colspan="2">{{f.desc}}</td> 89 <td>{{ form_field(f.ffield) }}</td> 90 {% endif %} 91 {% endblock %} 66 92 67 {% block entrieslist %}68 {% if entries %}69 <table class="maximal clear">70 <thead>71 <tr>72 {% for h in columns %}73 93 74 {% endfor %}75 </tr>76 </thead>77 78 {% else %}79 <p>{{ __('No entries') }}</p>80 {% endif %}81 82 {% endblock %} -
inc/admin/default-templates/posts.html.twig
r1147 r1152 7 7 {{ js.modal }} 8 8 {{ js.meta_editor }} 9 <script type="text/javascript" src="{{theme_url}}js/_post.js"></script> 9 <script type="text/javascript" src="{{theme_url}}js/_posts_list.js"></script> 10 <script type="text/javascript" src="{{theme_url}}js/filters.js"></script> 10 11 {{ js.confirm_close(['entry-form','comment-form']) }} 11 12 {{ js.page_tabs(default_tab) }} … … 18 19 {% endblock %} 19 20 21 22 20 23 {% block content %} 21 24 {{ parent() }} … … 25 28 <p> Applied filters : {{filters}} </p> 26 29 27 28 30 {{ listitems('lposts')}} 29 31 30 32 {% endblock %} -
inc/core/class.dc.blog.php
r1052 r1152 805 805 806 806 if (!empty($params['user_id'])) { 807 $strReq .= "AND U.user_id = '".$this->con->escape($params['user_id'])."'";807 $strReq .= "AND U.user_id ".$this->con->in($params['user_id'])." "; 808 808 } 809 809 -
inc/core/class.dc.core.php
r1147 r1152 96 96 $this->addFormater('xhtml', create_function('$s','return $s;')); 97 97 $this->addFormater('wiki', array($this,'wikiTransform')); 98 99 98 $this->loadTemplateEnvironment(); 100 99 } … … 129 128 $core->tpl->getLoader()->prependPath('PATH_TO/MY_THEME'); 130 129 */ 131 protected function loadTemplateEnvironment() 132 { 133 # If cache dir is writable, use it. 130 public function loadTemplateEnvironment() 131 { 134 132 $cache_dir = path::real(DC_TPL_CACHE.'/twtpl',false); 135 133 if (!is_dir($cache_dir)) { … … 155 153 ); 156 154 $this->tpl->addExtension(new dcFormExtension($this)); 157 $this->tpl->addExtension(new dcFilterSetExtension($this));158 155 $this->tpl->addExtension(new dcTabExtension($this)); 159 156 } -
inc/prepend.php
r1149 r1152 68 68 $__autoload['dcFormExtension'] = dirname(__FILE__).'/admin/class.dc.form.php'; 69 69 $__autoload['dcTabExtension'] = dirname(__FILE__).'/admin/class.dc.tab.php'; 70 $__autoload['dcFilterSetExtension'] = dirname(__FILE__).'/admin/class.dc.filter.php'; 70 $__autoload['dcItemList'] = dirname(__FILE__).'/admin/class.dc.list.php'; 71 72 foreach (array('dcFilterSet', 'dcFilter','dcFilterCombo','dcFilterText','dcFilterBoolean') as $c) { 73 $__autoload[$c] = dirname(__FILE__).'/admin/class.dc.filter.php'; 74 } 71 75 72 76 # Clearbricks extensions
Note: See TracChangeset
for help on using the changeset viewer.