[ Index ] |
|
Code source de CMS made simple 1.0.5 |
1 <?php 2 # CMS - CMS Made Simple 3 # (c)2004-6 by Ted Kulp (ted@cmsmadesimple.org) 4 # This project's homepage is: http://cmsmadesimple.org 5 # 6 # This program is free software; you can redistribute it and/or modify 7 # it under the terms of the GNU General Public License as published by 8 # the Free Software Foundation; either version 2 of the License, or 9 # (at your option) any later version. 10 # 11 # This program is distributed in the hope that it will be useful, 12 # BUT withOUT ANY WARRANTY; without even the implied warranty of 13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 # GNU General Public License for more details. 15 # You should have received a copy of the GNU General Public License 16 # along with this program; if not, write to the Free Software 17 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 # 19 #$Id$ 20 21 /** 22 * Methods for modules to do form related functions 23 * 24 * @since 1.0 25 * @package CMS 26 */ 27 28 function cms_module_CreateFormStart(&$modinstance, $id, $action='default', $returnid='', $method='post', $enctype='', $inline=false, $idsuffix='', $params = array(), $extra='') 29 { 30 global $gCms; 31 32 $formcount = 1; 33 $variables = &$gCms->variables; 34 35 if (isset($variables['formcount'])) 36 $formcount = $variables['formcount']; 37 38 if ($idsuffix == '') 39 $idsuffix = $formcount; 40 41 $goto = ($returnid==''?'moduleinterface.php':'index.php'); 42 #$goto = 'moduleinterface.php'; 43 if ($inline && $returnid != '') 44 { 45 #$goto = 'index.php?module='.$this->GetName().'&id='.$id.'&'.$id.'action='.$action; 46 #$goto = 'index.php?mact='.$this->GetName().','.$id.','.$action; 47 #$goto .= '&'.$id.'returnid='.$returnid; 48 #$goto .= '&'.$this->cms->config['query_var'].'='.$returnid; 49 } 50 $text = '<form id="'.$id.'moduleform_'.$idsuffix.'" name="'.$id.'moduleform_'.$idsuffix.'" method="'.$method.'" action="'.$goto.'"';//moduleinterface.php 51 if ($enctype != '') 52 { 53 $text .= ' enctype="'.$enctype.'"'; 54 } 55 /* 56 $text .= '><div class="hidden"><input type="hidden" name="module" value="'.$this->GetName().'" /><input type="hidden" name="id" value="'.$id.'" />'; 57 if ($action != '') 58 { 59 $text .= '<input type="hidden" name="'.$id.'action" value="'.$action.'" />'; 60 } 61 */ 62 if ($extra != '') 63 { 64 $text .= ' '.$extra; 65 } 66 $text .= '><div class="hidden"><input type="hidden" name="mact" value="'.$modinstance->GetName().','.$id.','.$action.','.($inline == true?1:0).'" />'; 67 if ($returnid != '') 68 { 69 $text .= '<input type="hidden" name="'.$id.'returnid" value="'.$returnid.'" />'; 70 if ($inline) 71 { 72 $text .= '<input type="hidden" name="'.$modinstance->cms->config['query_var'].'" value="'.$returnid.'" />'; 73 } 74 } 75 foreach ($params as $key=>$value) 76 { 77 if ($key != 'module' && $key != 'action' && $key != 'id') 78 $text .= '<input type="hidden" name="'.$id.$key.'" value="'.$value.'" />'; 79 } 80 $text .= "</div>\n"; 81 82 $formcount = $formcount + 1; 83 $variables['formcount'] = $formcount; 84 85 return $text; 86 } 87 88 function cms_module_CreateLabelForInput(&$modinstance, $id, $name, $labeltext='', $addttext='') 89 { 90 $labeltext = cms_htmlentities($labeltext); 91 $text = '<label for="'.$id.$name.'" id="'.$id.$name.'"'; 92 if ($addttext != '') 93 { 94 $text .= ' ' . $addttext; 95 } 96 $text .= '>'.$labeltext.'</label>'."\n"; 97 return $text; 98 99 } 100 101 function cms_module_CreateInputText(&$modinstance, $id, $name, $value='', $size='10', $maxlength='255', $addttext='') 102 { 103 $value = str_replace('"', '"', $value); 104 $text = '<input type="text" name="'.$id.$name.'" id="'.$id.$name.'" value="'.$value.'" size="'.$size.'" maxlength="'.$maxlength.'"'; 105 if ($addttext != '') 106 { 107 $text .= ' ' . $addttext; 108 } 109 $text .= " />\n"; 110 return $text; 111 } 112 113 function cms_module_CreateInputTextWithLabel(&$modinstance, $id, $name, $value='', $size='10', $maxlength='255', $addttext='', $label='', $labeladdtext='') 114 { 115 if ($label == '') { 116 $label = $name; 117 } 118 $text = '<label for="'.$id.$name.'" '.$labeladdtext.'>'.$label.'</label>'."\n"; 119 $text .= $modinstance->CreateInputText($id, $name, $value, $size, $maxlength, $addttext); 120 $text .= "\n"; 121 return $text; 122 } 123 124 function cms_module_CreateInputFile(&$modinstance, $id, $name, $accept='', $size='10',$addttext='') 125 { 126 $text='<input type="file" name="'.$id.$name.'" size="'.$size.'"'; 127 if ($accept != '') 128 { 129 $text .= ' accept="' . $accept.'"'; 130 } 131 if ($addttext != '') 132 { 133 $text .= ' ' . $addttext; 134 } 135 $text .= " />\n"; 136 return $text; 137 } 138 139 function cms_module_CreateInputPassword(&$modinstance, $id, $name, $value='', $size='10', $maxlength='255', $addttext='') 140 { 141 $value = str_replace('"', '"', $value); 142 $text = '<input type="password" name="'.$id.$name.'" value="'.$value.'" size="'.$size.'" maxlength="'.$maxlength.'"'; 143 if ($addttext != '') 144 { 145 $text .= ' ' . $addttext; 146 } 147 $text .= " />\n"; 148 return $text; 149 } 150 151 function cms_module_CreateInputHidden(&$modinstance, $id, $name, $value='', $addttext='') 152 { 153 $value = str_replace('"', '"', $value); 154 $text = '<input type="hidden" name="'.$id.$name.'" value="'.$value.'"'; 155 if ($addttext != '') 156 { 157 $text .= ' '.$addttext; 158 } 159 $text .= " />\n"; 160 return $text; 161 } 162 163 function cms_module_CreateInputCheckbox(&$modinstance, $id, $name, $value='', $selectedvalue='', $addttext='') 164 { 165 $text = '<input type="checkbox" name="'.$id.$name.'" value="'.$value.'"'; 166 if ($selectedvalue == $value) 167 { 168 $text .= ' ' . 'checked="checked"'; 169 } 170 if ($addttext != '') 171 { 172 $text .= ' '.$addttext; 173 } 174 $text .= " />\n"; 175 return $text; 176 } 177 178 function cms_module_CreateInputSubmit(&$modinstance, $id, $name, $value='', $addttext='', $image='', $confirmtext='') 179 { 180 global $gCms; 181 $config =& $gCms->GetConfig(); 182 183 $text = '<input name="'.$id.$name.'" value="'.$value.'" type='; 184 185 if ($image != '') 186 { 187 $text .= '"image"'; 188 $img = $config['root_url'] . '/' . $image; 189 $text .= ' src="'.$img.'"'; 190 } 191 else 192 { 193 $text .= '"submit"'; 194 } 195 if ($confirmtext != '' ) 196 { 197 $text .= 'onclick="return confirm(\''.$confirmtext.'\');"'; 198 } 199 if ($addttext != '') 200 { 201 $text .= ' '.$addttext; 202 } 203 204 $text .= ' />'; 205 206 return $text . "\n"; 207 } 208 209 function cms_module_CreateInputReset(&$modinstance, $id, $name, $value='Reset', $addttext='') 210 { 211 $text = '<input type="reset" name="'.$id.$name.'" value="'.$value.'"'; 212 if ($addttext != '') 213 { 214 $text .= ' '.$addttext; 215 } 216 $text .= ' />'; 217 return $text . "\n"; 218 } 219 220 function cms_module_CreateFileUploadInput(&$modinstance, $id, $name, $addttext='') 221 { 222 $text = '<input type="file" name="'.$id.$name.'"'; 223 if ($addttext != '') 224 { 225 $text .= ' '.$addttext; 226 } 227 $text .= ' />'; 228 return $text . "\n"; 229 } 230 231 function cms_module_CreateInputDropdown(&$modinstance, $id, $name, $items, $selectedindex, $selectedvalue, $addttext) 232 { 233 $text = '<select name="'.$id.$name.'"'; 234 if ($addttext != '') 235 { 236 $text .= ' ' . $addttext; 237 } 238 $text .= '>'; 239 $count = 0; 240 if (is_array($items) && count($items) > 0) 241 { 242 foreach ($items as $key=>$value) 243 { 244 $text .= '<option value="'.$value.'"'; 245 if ($selectedindex == $count || $selectedvalue == $value) 246 { 247 $text .= ' ' . 'selected="selected"'; 248 } 249 $text .= '>'; 250 $text .= $key; 251 $text .= '</option>'; 252 $count++; 253 } 254 } 255 $text .= '</select>'."\n"; 256 257 return $text; 258 } 259 260 function cms_module_CreateInputSelectList(&$modinstance, $id, $name, $items, $selecteditems=array(), $size=3, $addttext='', $multiple = true) 261 { 262 $text = '<select name="'.$id.$name.'"'; 263 if ($addttext != '') 264 { 265 $text .= ' ' . $addttext; 266 } 267 if( $multiple ) 268 { 269 $text .= ' multiple="multiple" '; 270 } 271 $text .= 'size="'.$size.'">'; 272 $count = 0; 273 foreach ($items as $key=>$value) 274 { 275 $text .= '<option value="'.$value.'"'; 276 if (in_array($value, $selecteditems)) 277 { 278 $text .= ' ' . 'selected="selected"'; 279 } 280 $text .= '>'; 281 $text .= $key; 282 $text .= '</option>'; 283 $count++; 284 } 285 $text .= '</select>'."\n"; 286 287 return $text; 288 } 289 290 function cms_module_CreateInputRadioGroup(&$modinstance, $id, $name, $items, $selectedvalue='', $addttext='', $delimiter='') 291 { 292 $text = ''; 293 $counter = 0; 294 foreach ($items as $key=>$value) 295 { 296 $counter = $counter + 1; 297 $text .= '<input type="radio" name="'.$id.$name.'" id="'.$id.$name.$counter.'" value="'.$value.'"'; 298 if ($addttext != '') 299 { 300 $text .= ' ' . $addttext; 301 } 302 if ($selectedvalue == $value) 303 { 304 $text .= ' ' . 'checked="checked"'; 305 } 306 $text .= ' />'; 307 $text .= '<label for="'.$id.$name.$counter.'">'.$key .'</label>' . $delimiter; 308 } 309 310 return $text; 311 } 312 313 function cms_module_CreateLink(&$modinstance, $id, $action, $returnid='', $contents='', $params=array(), $warn_message='', $onlyhref=false, $inline=false, $addttext='', $targetcontentonly=false, $prettyurl='') 314 { 315 global $gCms; 316 $config =& $gCms->GetConfig(); 317 318 $class = (isset($params['class'])?$params['class']:''); 319 320 if ($prettyurl != '' && $config['assume_mod_rewrite'] == true && $config['use_hierarchy'] == true) 321 { 322 $text = $config['root_url'] . '/' . $prettyurl . $config['page_extension']; 323 } 324 else if ($prettyurl != '' && $config['internal_pretty_urls'] == true && $config['use_hierarchy'] == true) 325 { 326 $text = $config['root_url'] . '/index.php/' . $prettyurl . $config['page_extension']; 327 } 328 else 329 { 330 $text = ''; 331 if ($targetcontentonly || ($returnid != '' && !$inline)) 332 { 333 $id = 'cntnt01'; 334 } 335 $goto = 'index.php'; 336 if ($returnid == '') 337 { 338 $goto = 'moduleinterface.php'; 339 } 340 if (!$onlyhref) 341 { 342 } 343 $text .= $config['root_url']; 344 if (!($returnid != '' && $returnid > -1)) 345 { 346 $text .= '/'.$config['admin_dir']; 347 } 348 349 #$text .= '/'.$goto.'?module='.$modinstance->GetName().'&id='.$id.'&'.$id.'action='.$action; 350 $text .= '/'.$goto.'?mact='.$modinstance->GetName().','.$id.','.$action.','.($inline == true?1:0); 351 352 foreach ($params as $key=>$value) 353 { 354 if ($key != 'module' && $key != 'action' && $key != 'id') 355 $text .= '&'.$id.$key.'='.rawurlencode($value); 356 } 357 if ($returnid != '') 358 { 359 $text .= '&'.$id.'returnid='.$returnid; 360 if ($inline) 361 { 362 $text .= '&'.$config['query_var'].'='.$returnid; 363 } 364 } 365 } 366 367 if (!$onlyhref) 368 { 369 $beginning = '<a'; 370 if ($class != '') 371 { 372 $beginning .= ' class="'.$class.'"'; 373 } 374 $beginning .= ' href="'; 375 $text = $beginning . $text . "\""; 376 if ($warn_message != '') 377 { 378 $text .= ' onclick="return confirm(\''.$warn_message.'\');"'; 379 } 380 381 if ($addttext != '') 382 { 383 $text .= ' ' . $addttext; 384 } 385 386 $text .= '>'.$contents.'</a>'; 387 } 388 return $text; 389 } 390 391 function cms_module_CreateContentLink(&$modinstance, $pageid, $contents='') 392 { 393 global $gCms; 394 $config = &$gCms->GetConfig(); 395 $text = '<a href="'; 396 if ($config["assume_mod_rewrite"]) 397 { 398 # mod_rewrite 399 $contentops =& $gCms->GetContentOperations(); 400 $alias = $contentops->GetPageAliasFromID( $pageid ); 401 if( $alias == false ) 402 { 403 return '<!-- ERROR: could not get an alias for pageid='.$pageid.'-->'; 404 } 405 else 406 { 407 $text .= $config["root_url"]."/".$alias. 408 (isset($config['page_extension'])?$config['page_extension']:'.shtml'); 409 } 410 } 411 else 412 { 413 # mod rewrite 414 $text .= $config["root_url"]."/index.php?".$config["query_var"]."=".$pageid; 415 } 416 $text .= '">'.$contents.'</a>'; 417 return $text; 418 } 419 420 function cms_module_CreateReturnLink(&$modinstance, $id, $returnid, $contents='', $params=array(), $onlyhref=false) 421 { 422 $text = ''; 423 global $gCms; 424 $config = &$gCms->GetConfig(); 425 $manager =& $gCms->GetHierarchyManager(); 426 $node =& $manager->sureGetNodeById($returnid); 427 if (isset($node)) 428 { 429 $content =& $node->GetContent(); 430 431 if (isset($content)) 432 { 433 if ($content->GetURL() != '') 434 { 435 if (!$onlyhref) 436 { 437 $text .= '<a href="'; 438 } 439 $text .= $content->GetURL(); 440 441 $count = 0; 442 foreach ($params as $key=>$value) 443 { 444 if ($count > 0) 445 { 446 if ($config["assume_mod_rewrite"] && $rewrite == true) 447 $text .= '?'; 448 else 449 $text .= '&'; 450 } 451 else 452 { 453 $text .= '&'; 454 } 455 $text .= $id.$key.'='.$value; 456 $count++; 457 } 458 if (!$onlyhref) 459 { 460 $text .= "\""; 461 $text .= '>'.$contents.'</a>'; 462 } 463 } 464 } 465 } 466 467 return $text; 468 } 469 470 function cms_module_CreateFieldsetStart(&$modinstance, $id, $name, $legend_text='', $addtext='', $addtext_legend='') 471 { 472 $text = '<fieldset '. $addtext. '>'."\n"; 473 $text .= '<legend '. $addtext_legend .'>'."\n"; 474 $text .= $legend_text; 475 $text .= '</legend>'; 476 return $text; 477 } 478 479 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Tue Apr 3 18:50:37 2007 | par Balluche grâce à PHPXref 0.7 |