[ Index ] |
|
Code source de GeekLog 1.4.1 |
1 <?php 2 3 /* Reminder: always indent with 4 spaces (no tabs). */ 4 // +---------------------------------------------------------------------------+ 5 // | Geeklog 1.4 | 6 // +---------------------------------------------------------------------------+ 7 // | lib-custom.php | 8 // | | 9 // | Your very own custom Geeklog library. | 10 // | | 11 // | This is the file where you should put all of your custom code. When | 12 // | possible you should not alter lib-common.php but, instead, put code here. | 13 // | This will make upgrading to future versions of Geeklog easier for you | 14 // | because you will always be guaranteed that the Geeklog developers will | 15 // | NOT add required code to this file. | 16 // | | 17 // | NOTE: we have already gone through the trouble of making sure that we | 18 // | always include this file when lib-common.php is included some place so | 19 // | you will have access to lib-common.php. It follows then that you should | 20 // | not include lib-common.php in this file. | 21 // | | 22 // +---------------------------------------------------------------------------+ 23 // | Copyright (C) 2000-2006 by the following authors: | 24 // | | 25 // | Authors: Tony Bibbs - tony AT tonybibbs DOT com | 26 // | Blaine Lang - blaine AT portalparts DOT com | 27 // | Dirk Haun - dirk AT haun-online DOT de | 28 // +---------------------------------------------------------------------------+ 29 // | | 30 // | This program is free software; you can redistribute it and/or | 31 // | modify it under the terms of the GNU General Public License | 32 // | as published by the Free Software Foundation; either version 2 | 33 // | of the License, or (at your option) any later version. | 34 // | | 35 // | This program is distributed in the hope that it will be useful, | 36 // | but WITHOUT ANY WARRANTY; without even the implied warranty of | 37 // | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 38 // | GNU General Public License for more details. | 39 // | | 40 // | You should have received a copy of the GNU General Public License | 41 // | along with this program; if not, write to the Free Software Foundation, | 42 // | Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | 43 // | | 44 // +---------------------------------------------------------------------------+ 45 // 46 // $Id: lib-custom.php,v 1.36 2006/12/14 05:19:58 blaine Exp $ 47 48 if (strpos ($_SERVER['PHP_SELF'], 'lib-custom.php') !== false) { 49 die ('This file can not be used on its own!'); 50 } 51 52 // You can use this global variable to print useful messages to the errorlog 53 // using COM_errorLog(). To see an example of how to do this, look in 54 // lib-common.php and see how $_COM_VERBOSE was used throughout the code 55 $_CST_VERBOSE = false; 56 57 /** 58 * Sample PHP Block function 59 * 60 * this is a sample function used by a PHP block. This will show the rights that 61 * a user has in the "What you have access to" block. 62 * 63 */ 64 function phpblock_showrights() 65 { 66 global $_RIGHTS, $_CST_VERBOSE; 67 68 if ($_CST_VERBOSE) { 69 COM_errorLog('**** Inside phpblock_showrights in lib-custom.php ****', 1); 70 } 71 72 $retval .= ' '; 73 74 for ($i = 0; $i < count($_RIGHTS); $i++) { 75 $retval .= '<li>' . $_RIGHTS[$i] . '</li>' . LB; 76 } 77 78 if ($_CST_VERBOSE) { 79 COM_errorLog('**** Leaving phpblock_showrights in lib-custom.php ****', 1); 80 } 81 82 return $retval; 83 } 84 85 86 /** 87 * Include any code in this function that will be called by the internal CRON API 88 * The interval between runs is determined by $_CONF['cron_schedule_interval'] 89 */ 90 function CUSTOM_runScheduledTask() { 91 92 } 93 94 95 /** 96 * Example of custom function that can be used to handle a login error. 97 * Only active with custom registration mode enabled 98 * Used if you have a custom front page and need to trap and reformat any error messages 99 * This example redirects to the front page with a extra passed variable plus the message 100 * Note: Message could be a string but in this case maps to $MESSAGE[81] as a default - edit in language file 101 */ 102 function CUSTOM_loginErrorHandler($msg='') { 103 global $_CONF,$MESSAGE; 104 105 if ($msg > 0) { 106 $msg = $msg; 107 } elseif ($msg == '') { 108 $msg = 81; 109 } 110 $retval = COM_refresh($_CONF['site_url'] .'/index.php?mode=loginfail&msg='.$msg); 111 echo $retval; 112 exit; 113 } 114 115 116 /** 117 * Include any code in this function to add custom template variables. 118 * Initially, this function is only called in the COM_siteHeader function to set 119 * header.thtml variables 120 */ 121 function CUSTOM_templateSetVars ($templatename, &$template) 122 { 123 if ($templatename == 'header') { 124 // define a {hello_world} variable which displays "Hello, world!" 125 $template->set_var ('hello_world', 'Hello, world!'); 126 } 127 } 128 129 130 /* Sample Custom Member Functions to create and update Custom Membership registration and profile 131 132 Note1: Enable CustomRegistration Feature in config.php 133 $_CONF['custom_registration'] = true; // Set to true if you have custom code 134 135 Note2: This example requires a template file called memberdetail.thtml to be 136 located under the theme_dir/custom directory. 137 Sample is provided under /system with the distribution. 138 139 Functions have been provided that are called from the Core Geeklog user and admin functions 140 - This works with User Moderation as well 141 - Admin will see the new registration info when checking a member's profile only 142 - All other users will see the standard User profile with the optional extended custom information 143 - Customization requires changes to a few of the core template files to add {customfields} variables 144 - See notes below in the custom function about the template changes 145 */ 146 147 /* Create any new records in additional tables you may have added */ 148 /* Update any fields in the core GL tables for this user as needed */ 149 /* Called when user is first created */ 150 function CUSTOM_userCreate ($uid) 151 { 152 global $_CONF, $_TABLES; 153 154 // Ensure all data is prepared correctly before inserts, quotes may need to 155 // be escaped with addslashes() 156 $email = ''; 157 if (isset ($_POST['email'])) { 158 $email = COM_applyFilter ($_POST['email']); 159 $email = addslashes ($email); 160 } 161 162 $homepage = ''; 163 if (isset ($_POST['homepage'])) { 164 $homepage = COM_applyFilter ($_POST['homepage']); 165 $homepage = addslashes ($homepage); 166 } 167 168 $fullname = ''; 169 if (isset ($_POST['fullname'])) { 170 // COM_applyFilter would strip special characters, e.g. quotes, so 171 // we only strip HTML 172 $fullname = strip_tags ($_POST['fullname']); 173 $fullname = addslashes ($fullname); 174 } 175 176 // Note: In this case, we can trust the $uid variable to contain the new 177 // account's uid. 178 DB_query("UPDATE {$_TABLES['users']} SET email = '$email', homepage = '$homepage', fullname = '$fullname' WHERE uid = $uid"); 179 180 return true; 181 } 182 183 // Delete any records from custom tables you may have used 184 function CUSTOM_userDelete($uid) 185 { 186 return true; 187 } 188 189 /* Called from users.php - when user is displaying a member profile. 190 * This function can now return any extra fields that need to be shown. 191 * Output is then replaced in {customfields} -- This variable needs to be added 192 * to your templates 193 * Template: path_layout/users/profile/profile.thtml 194 */ 195 function CUSTOM_userDisplay($uid) 196 { 197 global $_CONF, $_TABLES; 198 199 $var = "Value from custom table"; 200 $retval .= '<tr> 201 <td align="right"><b>Custom Fields:</b></td> 202 <td>' . $var .'</td> 203 </tr>'; 204 205 return $retval; 206 } 207 208 209 /* Function called when editing user profile. */ 210 /* Called from usersettings.php - when user is eding their own profile */ 211 /* and from admin/user.php when admin is editing a member profile */ 212 /* This function can now return any extra fields that need to be shown for editing */ 213 /* Output is then replaced in {customfields} -- This variable needs to be added to your templates */ 214 /* User: path_layout/preferences/profile.thtml and Admin: path_layout/admin/user/edituser.thtml */ 215 216 /* This example shows adding the Cookie Timeout setting and extra text field */ 217 /* As noted: You need to add the {customfields} template variable. */ 218 /* For the edituser.thtml - maybe it would be added about the {group_edit} variable. */ 219 220 function CUSTOM_userEdit($uid) 221 { 222 global $_CONF, $_TABLES; 223 224 $var = "Value from custom table"; 225 $cookietimeout = DB_getitem($_TABLES['users'], 'cookietimeout', $uid); 226 $selection = '<select name="cooktime">' . LB; 227 $selection .= COM_optionList ($_TABLES['cookiecodes'], 'cc_value,cc_descr', $cookietimeout, 0); 228 $selection .= '</select>'; 229 $retval .= '<tr> 230 <td align="right">Remember user for:</td> 231 <td>' . $selection .'</td> 232 </tr>'; 233 $retval .= '<tr> 234 <td align="right"><b>Custom Fields:</b></td> 235 <td><input type="text" name="custom1" size="50" value="' . $var .'"></td> 236 </tr>'; 237 $retval .= '<tr><td colspan="2"><hr></td></tr>'; 238 239 return $retval; 240 } 241 242 /* Function called when saving the user profile. */ 243 /* This function can now update any extra fields */ 244 function CUSTOM_userSave($uid) 245 { 246 global $_CONF, $_TABLES; 247 248 $cooktime = 0; 249 if (isset ($_POST['cooktime'])) { 250 $cooktime = COM_applyFilter ($_POST['cooktime'], true); 251 if ($cooktime < 0) { 252 $cooktime = 0; 253 } 254 255 DB_query("UPDATE {$_TABLES['users']} SET cookietimeout = $cooktime WHERE uid = $uid"); 256 } 257 } 258 259 260 /** 261 * Main Form used for Custom membership when member is registering 262 * 263 * Note: Requires a file custom/memberdetail.thtml in every theme that is 264 * installed on the site! 265 * 266 * @param string $msg an error message to display or the word 'new' 267 * @return string HTML for the registration form 268 * 269 */ 270 function CUSTOM_userForm ($msg = '') 271 { 272 global $_CONF, $_TABLES, $LANG04; 273 274 if (!empty ($msg) && ($msg != 'new')) { 275 $retval .= COM_startBlock($LANG04[21]) . $msg . COM_endBlock(); 276 } 277 278 $post_url = $_CONF['site_url'] . '/users.php'; 279 $postmode = 'create'; 280 $submitbutton = '<input type="submit" value="Register Now!">'; 281 $message = "<blockquote style=\"padding-top:10px;\"><b>Please complete the application below. Once you have completed the application, click the Register Now! button and the application will be processed immediately.</b></blockquote>"; 282 283 $user_templates = new Template ($_CONF['path_layout'] . 'custom'); 284 $user_templates->set_file('memberdetail', 'memberdetail.thtml'); 285 $user_templates->set_var('site_url', $_CONF['site_url']); 286 $user_templates->set_var('layout_url', $_CONF['layout_url']); 287 $user_templates->set_var('post_url', $post_url); 288 $user_templates->set_var('startblock', COM_startBlock("Custom Registration Example")); 289 $user_templates->set_var('message', $message); 290 291 $user_templates->set_var('USERNAME', $LANG04[2]); 292 $user_templates->set_var('USERNAME_HELP', "Name to be used when accessing this site"); 293 $username = ''; 294 if (isset ($_POST['username'])) { 295 $username = COM_applyFilter ($_POST['username']); 296 } 297 $user_templates->set_var('username', $username); 298 299 $user_templates->set_var('EMAIL', $LANG04[5]); 300 $user_templates->set_var('EMAIL_HELP', $LANG04[33]); 301 $email = ''; 302 if (isset ($_POST['email'])) { 303 $email = COM_applyFilter ($_POST['email']); 304 } 305 $user_templates->set_var('email', $email); 306 307 $user_templates->set_var('EMAIL_CONF', $LANG04[124]); 308 $user_templates->set_var('EMAIL_CONF_HELP', $LANG04[126]); 309 $email_conf = ''; 310 if (isset ($_POST['email_conf'])) { 311 $email_conf = COM_applyFilter ($_POST['email_conf']); 312 } 313 $user_templates->set_var('email_conf', $email_conf); 314 315 $user_templates->set_var('FULLNAME', $LANG04[3]); 316 $user_templates->set_var('FULLNAME_HELP', $LANG04[34]); 317 $fullname = ''; 318 if (isset ($_POST['fullname'])) { 319 $fullname = strip_tags ($_POST['fullname']); 320 } 321 $user_templates->set_var('fullname', $fullname); 322 323 $user_templates->set_var('user_id', $user); 324 $user_templates->set_var('postmode', $postmode); 325 $user_templates->set_var('submitbutton', $submitbutton); 326 $user_templates->set_var('endblock', COM_endBlock()); 327 $user_templates->parse('output', 'memberdetail'); 328 $retval .= $user_templates->finish($user_templates->get_var('output')); 329 330 return $retval; 331 } 332 333 /** 334 * Check if it's okay to create a new user. 335 * 336 * Geeklog is about to create a new user with the given username and email 337 * address. This is the custom code's last chance to prevent that, 338 * e.g. to check if all required data has been entered. 339 * 340 * @param string $username username that Geeklog would use for the new user* @param string $email email address of that user 341 * @return string an error message or an empty string for "OK" 342 * 343 */ 344 function CUSTOM_userCheck ($username, $email) 345 { 346 $msg = ''; 347 348 // Example, check that the full name has been entered 349 // and complain if it's missing 350 if (empty ($_POST['fullname'])) { 351 $msg = 'Please enter your full name!'; 352 } 353 354 return $msg; 355 } 356 357 358 /** 359 * Custom function to retrieve and return a formatted list of blocks 360 * Can be used when calling COM_siteHeader or COM_siteFooter 361 * 362 * Example: 363 * 1: Setup an array of blocks to display 364 * 2: Call COM_siteHeader or COM_siteFooter 365 * 366 * $myblocks = array( 'site_menu', 'site_news', 'poll_block' ); 367 * 368 * COM_siteHeader( array( 'CUSTOM_showBlocks', $myblocks )) ; 369 * COM_siteFooter( true, array( 'CUSTOM_showBlocks', $myblocks )); 370 * 371 * @param array $showblocks An array of block names to retrieve and format 372 * @return string Formated HTML containing site footer and optionally right blocks 373 */ 374 function CUSTOM_showBlocks($showblocks) 375 { 376 global $_CONF, $_USER, $_TABLES; 377 378 $retval = ''; 379 if( !isset( $_USER['noboxes'] )) { 380 if( !empty( $_USER['uid'] )) { 381 $noboxes = DB_getItem( $_TABLES['userindex'], 'noboxes', "uid = {$_USER['uid']}" ); 382 } else { 383 $noboxes = 0; 384 } 385 } else { 386 $noboxes = $_USER['noboxes']; 387 } 388 389 foreach($showblocks as $block) { 390 $sql = "SELECT bid, name,type,title,content,rdfurl,phpblockfn,help,allow_autotags FROM {$_TABLES['blocks']} WHERE name='$block'"; 391 $result = DB_query($sql); 392 if (DB_numRows($result) == 1) { 393 $A = DB_fetchArray($result); 394 $retval .= COM_formatBlock($A,$noboxes); 395 } 396 } 397 398 return $retval; 399 } 400 401 402 /** 403 * This is an example of a custom email function. When this function is NOT 404 * commented out, Geeklog would send all emails through this function 405 * instead of sending them through COM_mail in lib-common.php. 406 * 407 * This is basically a re-implementation of the way emails were sent 408 * prior to Geeklog 1.3.9 (Geeklog uses PEAR::Mail as of version 1.3.9). 409 * 410 */ 411 /* 412 function CUSTOM_mail($to, $subject, $message, $from = '', $html = false, $priority = 0) 413 { 414 global $_CONF, $LANG_CHARSET; 415 416 if (empty ($LANG_CHARSET)) { 417 $charset = $_CONF['default_charset']; 418 if (empty ($charset)) { 419 $charset = 'iso-8859-1'; 420 } 421 } else { 422 $charset = $LANG_CHARSET; 423 } 424 425 if (empty ($from)) { 426 $from = $_CONF['site_name'] . ' <' . $_CONF['site_mail'] . '>'; 427 } 428 429 $headers = 'From: ' . $from . "\r\n" 430 . 'X-Mailer: Geeklog ' . VERSION . "\r\n"; 431 432 if ($priority > 0) { 433 $headers .= 'X-Priority: ' . $priority . "\r\n"; 434 } 435 436 if ($html) { 437 $headers .= "Content-Type: text/html; charset={$charset}\r\n" 438 . 'Content-Transfer-Encoding: 8bit'; 439 } else { 440 $headers .= "Content-Type: text/plain; charset={$charset}"; 441 } 442 443 return mail ($to, $subject, $message, $headers); 444 } 445 */ 446 447 /** 448 * This is an example of a function that returns menu entries to be used for 449 * the 'custom' entry in $_CONF['menu_elements'] (see config.php). 450 * 451 */ 452 /* 453 function CUSTOM_menuEntries () 454 { 455 global $_CONF, $_USER; 456 457 $myentries = array (); 458 459 // Sample link #1: Link to Gallery 460 $myentries[] = array ('url' => $_CONF['site_url'] . '/gallery/', 461 'label' => 'Gallery'); 462 463 // Sample link #2: Link to the Personal Calendar - only visible for 464 // logged-in users 465 if (!empty ($_USER['uid']) && ($_USER['uid'] > 1)) { 466 $myentries[] = array ('url' => $_CONF['site_url'] 467 . '/calendar/index.php?mode=personal', 468 'label' => 'My Calendar'); 469 } 470 471 return $myentries; 472 } 473 */ 474 475 /** 476 * This is an example of an error handler override. This will be used in 477 * place of COM_handleError if the user is not in the Root group. Really, 478 * this should only be used to display some nice pretty "site error" html. 479 * Though you could try and notify the sysadmin, and log the error, as this 480 * example will show. The function is commented out for saftey. 481 */ 482 /* 483 function CUSTOM_handleError($errno, $errstr, $errfile, $errline, $errcontext) 484 { 485 global $_CONF; 486 if( is_array($_CONF) && function_exists('COM_mail')) 487 { 488 COM_mail($_CONF['site_mail'], $_CONF['site_name'].' Error Handler', 489 "An error has occurred: $errno $errstr @ $errline of $errfile"); 490 COM_errorLog("Error Handler: $errno $errstr @ $errline of $errfile"); 491 } 492 echo(" 493 <html> 494 <head> 495 <title>{$_CONF['site_name']} - An error occurred.</title> 496 <style type=\"text/css\"> 497 body,html {height: 100%; width: 100%;} 498 body{ border: 0px; padding: 0px; 499 background-color: white; 500 color: black; 501 } 502 div { margin-left: auto; margin-right: auto; 503 margin-top: auto; margin-bottom: auto; 504 border: solid thin blue; width: 400px; 505 padding: 5px; text-align: center; 506 } 507 h1 { color: blue;} 508 </style> 509 </head> 510 <body> 511 <div> 512 <h1>An Error Has Occurred.</h1> 513 <p>Unfortunatley, the action you performed has caused an 514 error. The site administrator has been informed. If you 515 try again later, the issue may have been fixed.</p> 516 </div> 517 </body> 518 </html> 519 "); 520 exit; 521 } 522 */ 523 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Wed Nov 21 12:27:40 2007 | par Balluche grâce à PHPXref 0.7 |
![]() |