| [ PHPXref.com ] | [ Generated: Sun Jul 20 18:53:27 2008 ] | [ myPHPNuke 1.8.8_8 ] |
| [ Index ] [ Variables ] [ Functions ] [ Classes ] [ Constants ] [ Statistics ] | ||
[Summary view] [Print] [Text view]
1 <?php 2 3 @( (bool)FALSE === strpos( $_SERVER['REQUEST_URI'], basename( __FILE__ ) ) ) OR exit( '!! ACCESS DENIED !!' ); 4 5 /* vim: set expandtab tabstop=4 shiftwidth=4: */ 6 7 // ***** BEGIN LICENSE BLOCK ( DO NOT REMOVE ) ***** 8 9 // +----------------------------------------------------------------------+ 10 // | MPN 188_8 Core -> Function Library Class | 11 // | | 12 // | -> General Function Collection | 13 // +----------------------------------------------------------------------+ 14 // | VERSION: 0.1 Alpha | 15 // +----------------------------------------------------------------------+ 16 // | LICENSE: GPL 2.0 (see docs/LICENSE_GPL) | 17 // | | 18 // | This file is part of MPN 188_8 Core. | 19 // | | 20 // | MPN 188_8 Core is free software; you can | 21 // | redistribute it and/or modify it under the terms of the GNU | 22 // | General Public License as published by the Free Software Foundation; | 23 // | either version 2 of the License, or (at your option) any | 24 // | later version. | 25 // | | 26 // | MPN 188_8 Core is distributed in the hope that it | 27 // | will be useful, but WITHOUT ANY WARRANTY; without even the implied | 28 // | warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | 29 // | See the GNU General Public License for more details. | 30 // | | 31 // | You should have received a copy of the GNU General Public License | 32 // | along with MPN 188_8 Core; if not, write to the | 33 // | | 34 // | Free Software Foundation, Inc. | 35 // | 59 Temple Place, Suite 330 | 36 // | Boston, MA 02111-1307 USA | 37 // +----------------------------------------------------------------------+ 38 // | AUTHOR(s): | 39 // | | 40 // | The Original Code is the MPN 188_8 Core. | 41 // | The Initial Developer of the Original Code is Eric Haddix. | 42 // | | 43 // | Portions created by Eric Haddix or Kiril Threndor | 44 // | <support@mpn.illearth.net> are | 45 // | Copyright (C) 2003 Eric Haddix. All Rights Reserved. | 46 // +----------------------------------------------------------------------+ 47 // | CONTRIBUTOR(s): | 48 // | | 49 // | | 50 // +----------------------------------------------------------------------+ 51 // | MODIFICATIONS: | 52 // | | 53 // | | 54 // +----------------------------------------------------------------------+ 55 // | NOTES: | 56 // | This is a collection of general functions used throughout MPN. | 57 // +----------------------------------------------------------------------+ 58 // | SUPPORT: | 59 // | WEB: http://myphpnuke.com/ | 60 // | EMAIL: support@mpn.illearth.net | 61 // +----------------------------------------------------------------------+ 62 63 /** 64 * MPN_188_8_Modules 65 * 66 * @package MPN_188_8_Core 67 * @subpackage classes 68 * @category General Functions 69 * @version $Id: core_LIB_Functions.class.php,v 1.11.2.37.4.3 2004/12/08 17:18:03 kirilt Exp $ 70 * 71 * @author Kiril Threndor <support@mpn.illearth.net> 72 * @copyright Copyright (C) 2003 Eric Haddix 73 * @license http://www.gnu.org/licenses/gpl.html GPL 2.0 74 * @support http://myphpnuke.com/ 75 * 76 * @tutorial 77 * @filesource 78 */ 79 80 // ***** END LICENSE BLOCK ( DO NOT REMOVE ) ***** 81 82 class FunctionLibrary 83 { 84 var $sitename = 'myPHPnuke Web Portal'; 85 var $dbstatus = FALSE; 86 var $install_root = NULL; 87 var $snoopy = NULL; // Nested Object 88 89 90 function FunctionLibrary() 91 { 92 global $mpnTables; 93 94 $status['dbconf'] = include_once './dbconf.php'; 95 $status['root_config'] = include_once './config.php'; 96 97 $status['core_Constants'] = include_once './core_Constants.php'; 98 99 if ( defined( '__ROOT__' ) ) { $this -> install_root = __ROOT__; } 100 101 $status['language'] = @include_once './language/lang-' . $language . '.php'; 102 103 // Connect To DB 104 105 $status['dbconn'] = $this -> dbstatus = $this -> dbConnect(); 106 107 // Define Variables 108 109 $this -> sitename = $sitename; 110 111 $status['reqvar'] = ( empty( $mpnTables ) ) 112 ? ( (bool)FALSE ) 113 : ( (bool)TRUE ); 114 115 // Check Status Array 116 117 if ( in_array( (bool)FALSE, $status ) ) 118 { 119 $msg = 'FATAL ERROR: '; 120 121 switch( TRUE ) 122 { 123 case ( (bool)FALSE === $status['dbconn'] ): 124 125 $msg .= 'Connection To Database Failed'; 126 127 break; 128 129 case ( (bool)FALSE === $status['reqvar'] ): 130 131 $msg .= 'Failed To Define Required Variables'; 132 133 break; 134 135 case ( (bool)FALSE === $status['defroot'] ): 136 137 $msg .= 'Cannot Determine Valid Domain'; 138 139 break; 140 141 default: 142 143 $msg .= 'Failed To Include Required File'; 144 145 break; 146 147 } // End Switch 148 149 exit( '<h2>' . $msg . '</h2>' ); 150 } 151 152 // Define Image Directory Paths 153 154 $sql = 'SELECT folder_id, path, uri FROM ' . $mpnTables['image_dirs']; 155 156 if ( ! @( $result = mysql_query( $sql ) ) && ! @mysql_data_seek( $result, 0 ) ) 157 { 158 exit( 'DB Error. Unable To Define Image Paths' ); 159 } 160 161 for ( $i = 1; $i <= @mysql_num_rows( $result ); $i++ ) 162 { 163 $tmp = mysql_fetch_row( $result ); 164 165 if ( $tmp[0] == 16 ) { $tmp[1] = $tmp[1] . $language . '/'; } 166 167 if ( is_null( $tmp[2] ) ) 168 { 169 define( '_IMG_AURI_' . $tmp[0] . '_', _URI_IMG_ROOT . $tmp[1] ); 170 } 171 else 172 { 173 define( '_IMG_AURI_' . $tmp[0] . '_', $tmp[2] ); 174 } 175 176 define( '_IMG_RURI_' . $tmp[0] . '_', _URI_IMG_REL_ROOT . $tmp[1] ); 177 } 178 179 @mysql_free_result( $result ); 180 181 return; 182 183 } // End Constructor 184 185 /** 186 * Connect To Database 187 * 188 * @return bool ( True On Success, False On Fail ) 189 */ 190 191 function dbConnect() 192 { 193 if ( ! @( include './admin/original/dbconfig.php' ) ) 194 { 195 return (bool)FALSE; 196 } 197 198 if ( _MPN_MYSQL_PCONNECT ) 199 { 200 @mysql_pconnect( $dbhost, $dbuname, $dbpass ); 201 } 202 else 203 { 204 @mysql_connect( $dbhost, $dbuname, $dbpass ); 205 } 206 207 if ( ! @mysql_select_db( $dbname ) ) 208 { 209 return (bool)FALSE; 210 } 211 212 unset( $dbhost, $dbuname, $dbpass, $dbname ); 213 214 return (bool)TRUE; 215 216 } // End Method dbConnect 217 218 /** 219 * Check DB Table For FullText Index Support. 220 * 221 * Note: Must be a valid table name. 222 */ 223 224 function checkFTISupport( $tbl ) 225 { 226 $sql = 'SHOW TABLE STATUS LIKE "' . $tbl . '"'; 227 228 @( $result = mysql_query( $sql ) ) 229 OR goBack( 'Query Failed' . '**' . __FILE__ . '***' . __LINE__ ); 230 231 $tmp = mysql_fetch_row( $result ); 232 233 @mysql_free_result( $result ); 234 235 return ( isset( $tmp[1] ) && $tmp[1] == 'MyISAM' ); 236 237 } // End Method checkFTISupport 238 239 /** 240 * Simply Checks A URI To See If It's Valid 241 * 242 * @param string ( $url -> Base URL To Check, ( must contain trailing slash ) ) 243 * @param string ( $fname -> Filename At Remote Site To Verify ( must be http accessible ) ) 244 * 245 * @return bool ( true on success, false on fail ) 246 */ 247 248 function resolveURI( $url, $fname ) 249 { 250 if ( @( include_once __ROOT__ . 'classes/core_Snoopy.class.php' ) ) 251 { 252 $sn = new Snoopy; 253 return @$sn -> fetch( $url . $fname ); 254 } 255 256 return; 257 258 } // End Method resolveURI 259 260 /** 261 * This Method Creates An Array Of Theme Paths 262 * 263 * @param integer ( create an array for listing in a slect form item ) 264 * 265 * @return mixed ( array on success, bool on fail ) 266 */ 267 268 function buildThemeArray( $list_it = '' ) 269 { 270 $avail_themes = NULL; 271 272 include_once './theme_functions.php'; 273 274 if ( _T_UA_VER4 ) // NN4 Theme Directory 275 { 276 $avail_themes = array( _DP_THEME_PAR_NN4 ); 277 } 278 else 279 { 280 $avail_themes = array( _DP_THEME_PAR ); 281 } 282 283 // BUILD THE PATH ARRAY 284 285 if ( ! empty( $avail_themes ) ) 286 { 287 $i = 0; // Initialize Themes Array Index 288 $j = 0; // Initialize Directory Array Index 289 290 while( $j < sizeof( $avail_themes ) ) 291 { 292 if ( ! @chdir( $avail_themes[ $j ] ) ) 293 { 294 return (bool)FALSE; 295 } 296 297 if ( $open = opendir( '.' ) ) 298 { 299 while ( ( $file = readdir( $open ) ) != FALSE ) 300 { 301 if ( ( is_dir( $file ) ) && ( $file != 'CVS' && $file != 'css' && $file != 'NN4' ) && ( ( substr( $file, 0, 1 ) ) != '.' ) ) 302 { 303 if ( ! $list_it ) // Build Directory array 304 { 305 $theme_array[ $i ] = array ( $file , $avail_themes[ $j ] . $file . '/' ); 306 } 307 else // Build Theme List Array 308 { 309 $theme_array[ $i ] = $file; 310 } 311 312 $i++; // Increment Theme Array Index 313 } 314 } 315 316 closedir( $open ); // Close The Target Directory 317 318 if ( ! @chdir( __ROOT__ ) ) // Change Back To Root 319 { 320 return (bool)FALSE; 321 } 322 } 323 324 $j++; // Increment Directory Array Index 325 } 326 327 sort( array_unique( $theme_array ) ); 328 329 return $theme_array; // Return The Created List Of Directory Links 330 } 331 332 return (bool)FALSE; 333 334 } // End Method buildThemeArray 335 336 /** 337 * Load Available Smileys Into Array 338 * 339 * @return array 340 */ 341 342 function getSmiles() 343 { 344 global $mpnTables; 345 $smile_ary = array(); 346 347 348 $sql = 'SELECT code, smile_url FROM ' . $mpnTables['smiles']; 349 $result = mysql_query( $sql ); 350 351 if ( mysql_error() == '' && (bool)FALSE != $result ) 352 { 353 while( list ( $code, $smile ) = mysql_fetch_row( $result ) ) 354 { 355 $smile_ary[ $code ] = $smile; 356 } 357 } 358 359 @mysql_free_result( $result ); 360 361 return $smile_ary; 362 363 } // End Method getSmiles 364 365 /** 366 * Check PHP Version 367 * 368 * @param string ( $version -> minimum required version ) 369 * 370 * @return bool 371 */ 372 373 function checkPHPVersion( $version ) 374 { 375 $testSplit = explode ( '.' , $version ); 376 $currentSplit = explode ( '.' , phpversion() ); 377 378 if ( $testSplit[0] < $currentSplit[0] ) { return (bool)TRUE; } 379 380 if ( $testSplit[0] == $currentSplit[0] ) 381 { 382 if ( $testSplit[1] < $currentSplit[1] ) { return (bool)TRUE; } 383 384 if ( $testSplit[1] == $currentSplit[1] ) 385 { 386 if ( $testSplit[2] <= $currentSplit[2] ) { return (bool)TRUE; } 387 } 388 } 389 390 return (bool)FALSE; 391 392 } // End Method checkPHPVersion 393 394 /** 395 * 396 * 397 * 398 */ 399 400 function checkFileUploads( $restr_scps = array() ) 401 { 402 if ( ! isset( $idx ) ) { $idx = array_keys( $_FILES ); } 403 404 if ( ! function_exists( 'cfu_recurse' ) ) 405 { 406 function cfu_recurse( $ary ) 407 { 408 foreach ( $ary AS $key => $val ) 409 { 410 if ( ! $val || $val == 0 ) 411 { 412 return $val; 413 } 414 } 415 416 return NULL; 417 } 418 } 419 420 foreach( $idx AS $key ) 421 { 422 $msg = NULL; 423 424 // Run Restricted Scripts Routine Here 425 426 if ( isset( $_FILES[ $key ]['error'] ) ) 427 { 428 $err = ( is_array( $_FILES[ $key ]['error'] ) ) ? ( cfu_recurse( $_FILES[ $key ]['error'] ) ) : ( $_FILES[ $key ]['error'] ); 429 430 if ( isset( $err ) && $err > 0 ) 431 { 432 switch( $err ) 433 { 434 case 1: 435 $msg = 'The uploaded file exceeds the upload_max_filesize directive in php.ini'; 436 break; 437 438 case 2: 439 $msg = 'The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form'; 440 break; 441 442 case 3: 443 $msg = 'The uploaded file was only partially uploaded'; 444 break; 445 446 DEFAULT: 447 $msg = 'No file was uploaded'; 448 break; 449 } 450 } 451 } 452 else 453 { 454 $err = ( is_array( $_FILES[ $key ]['size'] ) ) ? ( cfu_recurse( $_FILES[ $key ]['size'] ) ) : ( $_FILES[ $key ]['size'] ); 455 456 if ( isset( $err ) ) 457 { 458 $msg = 'No file was uploaded'; 459 } 460 } 461 462 if ( ! empty( $msg ) ) { goBack( $msg ); } 463 } 464 465 return (bool)TRUE; 466 467 } // End Method 468 469 /** 470 * Get File Content 471 * 472 * @param string ( $file -> fullly qualified path to file ( either local or remote ) 473 * @param integer ( $rettype -> how do you want the data returned ) 474 * 475 * Return Options: 476 * 477 * 1 -> Return A String 478 * 2 -> Return An Array 479 * 3 -> Dump To Screen 480 * 481 * @return mixed ( array, string, screen dump ) 482 */ 483 484 function getFileContent( $file, $rettype ) 485 { 486 $content = ''; 487 488 switch ( $rettype ) 489 { 490 case 1: // Return String 491 492 switch ( $this -> checkPHPVersion( '4.3.0' ) ) 493 { 494 case (bool)FALSE: // PHP Version < 4.3.0 495 496 if ( $fp = @fopen( $file, 'rb' ) ) 497 { 498 $content = fread( $fp, filesize( $file ) ); 499 500 fclose( $fp ); 501 } 502 503 break; 504 505 case (bool)TRUE: // PHP Version >= 4.3.0 506 507 if ( function_exists( 'file_get_contents' ) ) 508 { 509 $content = file_get_contents( $file ); 510 } 511 512 break; 513 514 } // End Nested Switch 515 516 break; 517 518 case 2: // Return Array 519 520 $content = @file( $file ); 521 522 break; 523 524 case 3: // Output To Screen 525 526 $content = @readfile( $file ); 527 528 break; 529 530 } // End Switch 531 532 return $content; 533 534 } // End Method getFileContent 535 536 /** 537 * Write Content To A File 538 * 539 * @param string ( $filename -> reference to relative path and file name ) 540 * @param string ( $mode -> write mode ) 541 * @param string ( &$data -> reference data data being written ) 542 * @param string ( $f_root -> OPT: root to file, default is install root ) 543 * @param bool ( $exists -> check if file exists before writting to it ) 544 * 545 * @return bool 546 */ 547 548 function writeFile( $filename, $mode, &$data, $f_root = NULL, $exists = FALSE ) 549 { 550 if ( empty( $f_root ) ) { $f_root = $this -> install_root; } 551 552 $filename = $f_root . $filename; 553 554 if ( $exists && is_file( $filename ) ) 555 { 556 return (bool)FALSE; 557 } 558 559 if ( is_file( $filename ) && ! is_writable( $filename ) ) 560 { 561 return (bool)FALSE; 562 } 563 564 // Check And Adjust Writing Mode Just In Case 565 566 if ( $mode == 'a' ) { $mode = 'a+b'; } 567 if ( $mode != 'a+b' && $mode != 'w+b' ) { $mode = 'w+b'; } 568 569 if ( $fp = @fopen( $filename, $mode ) ) 570 { 571 if ( is_array( $data ) ) 572 { 573 $cnt = 0; 574 $size = sizeof( $data ); 575 576 foreach( $data AS $key => $line ) 577 { 578 $cnt++; 579 580 if ( substr( $line, -2 ) !== "\n" && $cnt < $size ) 581 { 582 $line .= "\n"; 583 } 584 585 @fwrite( $fp, $line ); 586 } 587 } 588 else 589 { 590 @fwrite( $fp, $data ); 591 } 592 593 @fclose( $fp ); 594 595 return (bool)TRUE; 596 } 597 else // Can't Write To FIle 598 { 599 return (bool)FALSE; 600 } 601 602 } // End Method writeFile 603 604 /** 605 * Make A Directory 606 * 607 * @param string ( install root relative path to directory ) 608 * 609 * @return array ( array of bool results ) 610 */ 611 612 function makeDir( $dir, $perm = NULL ) 613 { 614 // REF: fixPath( $rel_path, $real_path = NULL, $web = FALSE ) 615 616 if ( __SAFEMODE__ ) { goBack( 'File Uploads Has Been Disabled Due To Server Configuration' ); } 617 618 $dir = FunctionLibrary :: fixPath( $dir ); 619 620 if ( is_dir( $dir ) ) { return; } 621 622 $oldmask = umask( 0000 ); 623 $perm = ( empty( $perm ) ) ? ( 0777 ) : ( (int)$perm ); 624 $dirpos = strrpos( substr( $dir, 0, -1 ), DIRECTORY_SEPARATOR ); 625 $parent = substr( $dir, 0, ( $dirpos + 1 ) ); 626 627 if ( ! is_dir( $parent ) ) 628 { 629 goBack( 'Directory <i>' . $parent . '</i> Does Not Exist **' . __FILE__ . '***' . __LINE__ ); 630 } 631 632 if ( ! @is_writable( $parent ) && ! @chmod( $parent, 0777 ) ) 633 { 634 goBack( 'Incorrect Permissions On Directory <i>' . $parent . '</i> **' . __FILE__ . '***' . __LINE__ ); 635 } 636 637 if ( is_integer( $perm ) ) 638 { 639 $status = @mkdir( $dir, $perm ); 640 } 641 else 642 { 643 $status = (bool)FALSE; 644 } 645 646 @umask( $oldmask ); 647 @chmod( $parent, $oldmask ); 648 649 if ( ! $status ) 650 { 651 goBack( 'Unable To Create Directory <i>' . $dir . '</i> **' . __FILE__ . '***' . __LINE__ ); 652 } 653 654 return (bool)TRUE; 655 656 } // End Method makeDir 657 658 /** 659 * Creat A Copy Of A Directory Or File 660 * 661 * @param string ( $oldname -> relative path and filename of file to copy ) 662 * @param string ( $newname -> relative path and filename of new file ) 663 * @param string ( $f_root -> OPT: root to file, default is install root ) 664 * @param string ( $dupname -> OPT: relative path and filename of the permissions file ) 665 * @param interger ( $dirperm -> OPT: permissions for directory creation ) 666 * @param bool ( $copy_dir_contents -> OPT: copy contents of directory when making a directory copy ) 667 * @param array ( $restrict_copy -> OPT: array of file names to NOT copy ) 668 * @param array ( $restrict_ext -> OPT: array of file extensions to NOT copy ) 669 * 670 * @return bool ( result of copy and chmod ) 671 */ 672 673 function makeCopy( $oldname 674 , $newname 675 , $f_root = NULL 676 , $dupname = NULL 677 , $dirperm = NULL 678 , $copy_dir_contents = FALSE 679 , $restrict_copy = NULL 680 , $restrict_ext = NULL 681 ) 682 { 683 $status = array(); 684 685 if ( empty( $f_root ) ) { $f_root = $this -> install_root; } 686 687 $oldname = $f_root . $oldname; 688 $newname = $f_root . $newname; 689 690 if ( ! empty( $dupname ) ) 691 { 692 $dupname = $f_root . $dupname; 693 } 694 695 if ( is_file( $oldname ) ) 696 { 697 if ( ! empty( $dupname ) ) 698 { 699 $perms = @fileperms( $dupname ); 700 $status['dup_copy'] = @copy( $dupname, $newname ); 701 } 702 else 703 { 704 $perms = @fileperms( $oldname ); 705 } 706 707 $status['file_copy'] = @copy( $oldname, $newname ); 708 $status['file_chmod'] = @chmod( $newname, $perms ); 709 710 return $status; 711 } 712 else if ( is_dir( $oldname ) ) 713 { 714 return $this -> makeDirCopy( $oldname, $newname, $dupname, $dirperm, $copy_dir_contents, $restrict_copy, $restrict_ext ); 715 } 716 else 717 { 718 return 'Cannot Copy File Or Directory: ' . $oldname; 719 } 720