Changeset 265
- Timestamp:
- 03/09/08 08:57:37 (9 months ago)
- Files:
-
- prfext/README.txt (modified) (13 diffs)
- prfext/function_search.php (modified) (1 diff)
- prfext/lib.php (modified) (9 diffs)
- prfext/radioGroup.gif (added)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
prfext/README.txt
r221 r265 33 33 34 34 Four profile fields work immediately without further configuration. 35 36 *Keyword fields* 37 38 When using any fields with prfext field types, you can use the "keyword_tag" 39 parameter to make this field act like Elgg keywords - they are searchable 40 and linked in the profile display. 35 41 36 42 *Dates* … … 60 66 "required" => false, 61 67 "user_type" => "person", 68 "keyword_tag" => false 62 69 )); 63 70 … … 66 73 Regardless of the date format displayed, the date values are always 67 74 stored in the database in the ISO standard YYYY-MM-DD. 75 76 Notice in this case that keyword_tag is set to false. In this case 77 this field will not be searchable. You can also leave "keyword_tag" 78 off altogether unless you want it to be true. 68 79 69 80 *Smaller fields* … … 93 104 will encourage people to enter only a few words for their minibio. 94 105 106 $data['profile:details'][] = (object)(array( 107 "name" => __gettext("Town"), 108 "internal_name" => "town", 109 "field_type" => "profile_shorttext", 110 "description" => "", 111 "category" => __gettext("Location"), 112 "col1" => true, 113 "invisible" => false, 114 "required" => false, 115 "user_type" => "", 116 "keyword_tag" => true, 117 )); 118 119 provides a small amount of room for a town name. Notice that 120 "keyword_tag" is set to true to make this field searchable. It 121 will be linked in profiles if there are other people from 122 the same town, and people will be able to search for these towns 123 in the Elgg search box. 124 95 125 *Selects, radio buttons and checkbox groups* 96 126 97 The profile extension plugin provides a simple function, prfext_ display,127 The profile extension plugin provides a simple function, prfext_choices, 98 128 to register new display types with the Elgg profile system. You can use this 99 129 function to define selects, radio buttons and checkbox groups and then use 100 130 these new display types in your profile field descriptions. 101 131 102 The definition of pr ext_display is:103 104 prfext_ display($your_field_display_type,$prfext_display_category,$is_keyword_tag,$default_value,$options)132 The definition of prfext_display is: 133 134 prfext_choices($your_field_display_type,$prfext_display_category,$default_value,$options) 105 135 106 136 The valid prfext display categories are: … … 109 139 profile_selectg 110 140 profile_radio 141 profile_radio_group 111 142 profile_vertical_radio 112 143 profile_checkbox … … 115 146 You can find detailed examples explaining how to use these categories below. 116 147 117 *New keyword display types*118 119 The $is_keyword_tag parameter of prfext_display makes profile fields using120 this display type act like Elgg keywords - they are searchable and linked121 in the profile display.122 123 148 *Simple select example* 124 149 125 150 Here's a simple example: 126 151 127 prfext_display('sports','profile_select',true,'',array('football','golf','darts','hockey','other sport')); 128 129 This creates an Elgg display type (a select box) called "sports". It will be treated 130 as a searchable keyword tag type and has no default value. 152 prfext_choices('sports','profile_select','',array('football','golf','darts','hockey','other sport')); 153 154 This creates an Elgg display type (a select box) called "sports". It has no default value. 131 155 132 156 The values can be any phrase (including blanks) but must not include commas. The word 'null' … … 145 169 "required" => false, 146 170 "user_type" => "person", 171 "keyword_tag" => true, 147 172 )); 173 174 Notice the use of the "keyword_tag" value to make this field act like an 175 Elgg keyword tag field. 148 176 149 177 You can use the same display type multiple times - for example, you might want … … 156 184 For example: 157 185 158 prfext_display('sports','profile_select',true,'hockey',array('football','golf','darts','hockey','other sport')); 186 prfext_choices('sports','profile_select','hockey', 187 array('football','golf','darts','hockey','other sport')); 159 188 160 189 sets hockey as the default (pre-selected) value. … … 169 198 There are two forms of radio buttons: 170 199 171 prfext_display('sports','profile_radio',true,'',array('football','golf','darts','hockey','other sport')); 200 prfext_choices('sports','profile_radio','', 201 array('football','golf','darts','hockey','other sport')); 172 202 173 203 presents 5 horizontal radio buttons. 174 204 175 prfext_display('sports','profile_vertical_radio',true,'',array('football','golf','darts','hockey','other sport')); 205 prfext_choices('sports','profile_vertical_radio','', 206 array('football','golf','darts','hockey','other sport')); 176 207 177 208 presents 5 vertical radio buttons, with one option displayed per line … … 184 215 For example, 185 216 186 prfext_ display('sports','profile_radio',false,'',217 prfext_choices('sports','profile_radio','', 187 218 array( 188 219 'gb'=>'United Kingdom', … … 197 228 In the profile, the appropriate label would be displayed instead of 198 229 the internal code. This works for any of the available prfext display 199 categories listed above.230 categories defined by prfext_choices. 200 231 201 232 Display labels can be any Unicode string and can include commas, unlike 202 233 internal values. 203 234 204 Note that it is the internal values that would be used as searchable tags,205 and in this example, this profile field has $is_keyword__tag set206 to false to avoid creating potentially obscure searchable tags like 'be'.207 208 235 *Checkbox group example* 209 236 210 237 Checkbox groups allow you to return more than one value. 211 238 212 prfext_display('sports','profile_checkbox',true,'',array('football','golf','darts','hockey','other sport')); 213 214 presents a horizontal list of 5 checkboxes and users can choose any (or none) of them. 239 prfext_choices('sports','profile_checkbox','', 240 array('football','golf','darts','hockey','other sport')); 241 242 presents a horizontal list of 5 checkboxes and users can choose any 243 (or none) of them. 215 244 216 245 Similarly, 217 246 218 prfext_display('sports','profile_vertical_checkbox',true,'',array('football','golf','darts','hockey','other sport')); 247 prfext_choices('sports','profile_vertical_checkbox','', 248 array('football','golf','darts','hockey','other sport')); 219 249 220 250 returns a vertical list of 5 checkboxes, one option per line. … … 225 255 For example, 226 256 227 prfext_display('sports','profile_checkbox',true,'golf,darts,other sport',array('football','golf','darts','hockey','other sport')); 228 229 would pre-check the boxes for golf, darts and other, and leave football and 230 other sport unchecked. 257 prfext_choices('sports','profile_checkbox','golf,darts,other sport', 258 array('football','golf','darts','hockey','other sport')); 259 260 would pre-check the boxes for golf, darts and other, and leave 261 football and other sport unchecked. 262 263 *Radio groups* 264 265 You can set up a two-dimensional radio button group using the 266 profile_radio_group display category. See radioGroup.gif in this 267 directory for an image. 268 269 prfext_choices('activities','profile_radio_group','never,often,sometimes', 270 array(array('smoke','move','sleep'),array('often','sometimes','never'))); 271 272 sets up the two dimensional array of choices shown in the image. 273 The user can make zero or one choice for each line in the table. You 274 can set a default value for each row using the usual default value 275 parameter, with one value for each row (in this case, 'never,often,sometimes'). 276 277 As with other examples, you can set labels using associative arrays. In this case: 278 279 prfext_choices('activities','profile_radio_group','n,o,s', 280 array( 281 array('sm'=>'Smoke','m'=>'Move','sl'=>'Sleep'), 282 array('o'=>'Often','s'=>'Sometimes','n'=>'Never') 283 ) 284 ); 231 285 232 286 *Select with option groups* … … 246 300 Italy. 247 301 248 prfext_ display('countryregion','profile_selectg',false,'it',302 prfext_choices('countryregion','profile_selectg','it', 249 303 array( 250 304 'Northwestern Europe' => array( prfext/function_search.php
r221 r265 32 32 $field_type = $CFG->prfext_keyword_field_names[$parameter[0]]->field_type; 33 33 $field_display_name = $CFG->prfext_keyword_field_names[$parameter[0]]->field_display_name; 34 $d = $CFG->prfext_data[$field_type]; 35 $options = $d->options; 36 $display_type = $d->display_type; 37 if ($display_type == 'profile_selectg') { 38 foreach ($options as $option) { 39 if (prfext_array_is_associative($option)) { 40 foreach($option as $k => $v) { 41 if ($tag == $k) { 42 $display_value = $v; 43 break 2; 34 if (isset($CFG->prfext_data[$field_type])) { 35 $d = $CFG->prfext_data[$field_type]; 36 $options = $d->options; 37 $display_type = $d->display_type; 38 if ($display_type == 'profile_selectg') { 39 foreach ($options as $option) { 40 if (prfext_array_is_associative($option)) { 41 foreach($option as $k => $v) { 42 if ($tag == $k) { 43 $display_value = $v; 44 break 2; 45 } 44 46 } 45 47 } 46 48 } 49 } else if ($display_type == 'profile_radio_group') { 50 $rows = $options[0]; 51 $cols = $options[1]; 52 if (prfext_array_is_associative($rows)) { 53 $tp = explode(":",$tag); 54 $display_value = $rows[$tp[0]] .': '. $cols[$tp[1]]; 55 } 56 } else if (prfext_array_is_associative($options)) { 57 $display_value = $options[$tag]; 47 58 } 48 } else if (prfext_array_is_associative($options)) {49 $display_value = $options[$tag];50 59 } 51 60 prfext/lib.php
r221 r265 29 29 profile_radio, 30 30 profile_vertical_radio, 31 profile_radio_group, 31 32 profile_checkbox, 32 33 profile_vertical_checkbox, … … 68 69 foreach($data['profile:details'] as $field) { 69 70 $field_type = $field->field_type; 70 if (isset($CFG->prfext_data[$field_type]) && $CFG->prfext_data[$field_type]->is_keyword_tag) { 71 if ((isset($field->keyword_tag) && $field->keyword_tag) 72 || (isset($CFG->prfext_data[$field_type]) && isset($CFG->prfext_data[$field_type]->is_keyword_tag) 73 && $CFG->prfext_data[$field_type]->is_keyword_tag)) { 71 74 $d = new stdClass; 72 75 $d->field_type = $field_type; … … 84 87 'display_type' => $display_type, 85 88 'is_keyword_tag' => $is_keyword_tag, 89 'default_value' => $default_value, 90 'options' => $options 91 ); 92 $CFG->display_field_module[$name] = 'prfext'; 93 94 } 95 96 function prfext_choices($name,$display_type,$default_value,$options) { 97 global $CFG; 98 99 $CFG->prfext_data[$name] = (object) array( 100 'display_type' => $display_type, 86 101 'default_value' => $default_value, 87 102 'options' => $options … … 312 327 $run_result .= "<textarea name=\"".$cleanid."\" id=\"".$cleanid."\" style=\"width: 250px; height: 100px\">".htmlspecialchars(stripslashes($default_value), ENT_COMPAT, 'utf-8')."</textarea>"; 313 328 break; 329 330 case "profile_radio_group": 331 $r = rand(); 332 $form_name_prefix = 'g'.$r; 333 $rowsLen = count($options[0]); 334 $columnsLen = count($options[1]); 335 336 $run_result .= " 337 <script language=\"JavaScript\"> 338 function select_field$form_name_prefix(form){ 339 var result; 340 var contentFlag = false; 341 result = ''; 342 for(i=0;i<$rowsLen;i++) { 343 result += ','; 344 for(j=0;j<$columnsLen;j++) { 345 if (form['$form_name_prefix'+'_'+i][j].checked == true){ 346 result += form['$form_name_prefix'+'_'+i][j].value; 347 contentFlag=true; 348 } 349 } 350 } 351 352 if (!contentFlag){ 353 result = ''; 354 } 355 356 form['$cleanid'].value = result.substr(1); 357 if (form['$cleanid'].value == '') { 358 form['$cleanid'].value = 'null'; 359 } 360 } 361 </script>"; 362 363 if ($default_value) { 364 $default_array_temp = explode(",",$default_value); 365 $default_array = array(); 366 foreach($default_array_temp as $value) { 367 if (count($v2 = explode(":",$value)) > 1) { 368 $default_array[] = $v2[1]; 369 } else { 370 $default_array[] = $value; 371 } 372 } 373 } 374 375 $flagCorner = true; 376 $i = 0; 377 $rows = $options[0]; 378 $columns = $options[1]; 379 380 $run_result .= '<table width=100%>'; 381 $run_result .= '<tr><td> </td>'; 382 383 $has_labels = prfext_array_is_associative($columns); 384 385 if ($has_labels) { 386 foreach($columns as $col_k => $col_v){ 387 $run_result .= '<td>'.$col_v.'</td>'; 388 } 389 390 foreach($rows as $row_k => $row_v){ 391 $run_result .= '<tr><td>'.$row_v.'</td>'; 392 393 foreach($columns as $col_k => $col_v){ 394 $run_result .= '<td>'."<input type=\"radio\" onclick=\"select_field$form_name_prefix(this.form)\" name=\"".$form_name_prefix.'_'.$i."\" value=\"".$row_k.':'.$col_k."\" id=\"".$form_name_prefix.$i."\" "; 395 if($default_value && $col_k == $default_array[$i]){ 396 $run_result .= " checked=\"true\" "; 397 } 398 $run_result .='></input></td>'; 399 } 400 401 $i++; 402 $run_result .='</tr>'; 403 } 404 } else { 405 406 foreach($columns as $column){ 407 $run_result .= '<td>'.$column.'</td>'; 408 } 409 410 foreach($rows as $row){ 411 $run_result .= '<tr><td>'.$row.'</td>'; 412 413 foreach($columns as $column){ 414 $run_result .= '<td>'."<input type=\"radio\" onclick=\"select_field$form_name_prefix(this.form)\" name=\"".$form_name_prefix.'_'.$i."\" value=\"".$row.':'.$column."\" id=\"".$form_name_prefix.$i."\" "; 415 if($default_value && $column == $default_array[$i]){ 416 $run_result .= " checked=\"true\" "; 417 } 418 $run_result .='></input></td>'; 419 } 420 421 $i++; 422 $run_result .='</tr>'; 423 } 424 } 425 426 $run_result .=" 427 </table> 428 <input type=\"hidden\" name=\"".$cleanid."\" value=\"".$parameter[1]."\" id=\"".$cleanid."\" />"; 429 430 break; 314 431 315 432 } … … 319 436 320 437 /* 321 Note: the comment in d atalib.php for Elgg 0.9 is incorrect for the438 Note: the comment in displaylib.php for Elgg 0.9 is incorrect for the 322 439 display_output_field parameter array 323 440 … … 328 445 0 => data 329 446 1 => type of input field 330 2 => input name to display (for forms etc)331 3 => reference name (for tag fields and so on)447 2 => reference name (for tag fields and so on) 448 3 => input name to display (for forms etc) 332 449 4 => ID number (if any) 333 450 5 => Owner (if not specified, current $page_owner is assumed) … … 348 465 $value = empty($parameter[0])?$d->default_value:$parameter[0]; 349 466 $display_type = $d->display_type; 350 $is_keyword_tag = $d->is_keyword_tag;351 467 } else { 352 468 $value = $parameter[0]; 353 469 $display_type = $name; 470 } 471 if (!isset($CFG->prfext_keyword_field_names)) { 472 prfext_set_keyword_cache(); 473 } 474 475 if (isset($CFG->prfext_keyword_field_names[$parameter[2]])) { 476 $is_keyword_tag = true; 477 } else { 354 478 $is_keyword_tag = false; 355 479 } … … 430 554 break; 431 555 556 case 'profile_radio_group': 557 $final = ''; 558 $options = $d->options; 559 $rows = $options[0]; 560 $columns = $options[1]; 561 $rowsLen = count($rows); 562 $rowsValue = explode(',',$value); 563 564 $has_labels = prfext_array_is_associative($rows); 565 566 if ($has_labels) { 567 for ($i = 0; $i < $rowsLen; $i++){ 568 $rv = $rowsValue[$i]; 569 if ($rv != ''){ 570 $v = explode(':',$rv); 571 $item = $rows[$v[0]] . ' : <i>'. $columns[$v[1]] .'</i>'; 572 if ($is_keyword_tag && prfext_tag_count($rv) > 1) { 573 $item = prfext_add_tag_link($item,$name,$rv); 574 } 575 $final .= ', ' . $item; 576 } 577 } 578 } else { 579 $i = 0; 580 foreach ($rows as $option){ 581 $rv = $rowsValue[$i]; 582 if ($rv != ''){ 583 $v = explode(':',$rv); 584 $item = $option . ' : <i>'. $v[1] .'</i>'; 585 if ($is_keyword_tag && prfext_tag_count($rv) > 1) { 586 $item = prfext_add_tag_link($item,$name,$rv); 587 } 588 $final .= ', ' . $item; 589 } 590 $i++; 591 } 592 } 593 594 return substr($final,1); 595 596 break; 597 432 598 default: 433 $options = $d->options;434 if (prfext_array_is_associative($options)) {599 if (isset($d->options) && prfext_array_is_associative($d->options)) { 600 $options = $d->options; 435 601 if ($is_keyword_tag && prfext_tag_count($value) > 1) { 436 602 return prfext_add_tag_link($options[$value],$name,$value); … … 453 619 global $CFG,$page_owner; 454 620 return "<a href=\"".$CFG->wwwroot."search/index.php?".$tagtype 455 ."=".$value."&owner=".$page_owner."\" >".$text."</a> \n";621 ."=".$value."&owner=".$page_owner."\" >".$text."</a>"; 456 622 } 457 623
