| 345 | | '${config['admin_email']}', |
| 346 | | MD5('${config['admin_password']}'), |
| 347 | | 'n.j.Y', |
| 348 | | 'Plogger Photo Feed', |
| 349 | | '${config['gallery_name']}', |
| 350 | | '${config['gallery_url']}')"; |
| 351 | | } else { |
| 352 | | $query = "UPDATE `".TABLE_PREFIX."config` SET |
| 353 | | `theme_dir` = '${config['default_theme_dir']}', |
| 354 | | `compression` = 75, |
| 355 | | `max_thumbnail_size` = 100, |
| 356 | | `max_display_size` = 500, |
| 357 | | `thumb_num` = 20, |
| 358 | | `admin_username` = '${config['admin_username']}', |
| 359 | | `admin_email` = '${config['admin_email']}', |
| 360 | | `admin_password` = MD5('${config['admin_password']}'), |
| 361 | | `date_format` = 'n.j.Y', |
| 362 | | `feed_title` = 'Plogger Photo Feed', |
| 363 | | `gallery_name` = '${config['gallery_name']}', |
| 364 | | `gallery_url` = '${config['gallery_url']}'"; |
| 365 | | } |
| 366 | | |
| 367 | | mysql_query($query) or die(mysql_error().'<br /><br />'. $query); |
| 368 | | |
| 369 | | mail($config['admin_email'],"Your new gallery","You have successfully installed your new Plogger gallery. You can manage it at ${config['gallery_url']}plog-admin Username is ${config['admin_username']} and password ${config['admin_password']}."); |
| 370 | | } |
| 371 | | |
| 372 | | function create_config_file($db_host,$db_user,$db_pass,$db_name,$ftp_host,$ftp_user,$ftp_pass,$ftp_path) { |
| 373 | | $cfg_file = "<?php\n"; |
| 374 | | $cfg_file .= '// this is the file used to connect to your database.'."\n"; |
| 375 | | $cfg_file .= '// you must change these values in order to run the gallery.'."\n"; |
| 376 | | $cfg_file .= 'define("PLOGGER_DB_HOST","'.$db_host.'");'."\n"; |
| 377 | | $cfg_file .= 'define("PLOGGER_DB_USER","'.$db_user.'");'."\n"; |
| 378 | | $cfg_file .= 'define("PLOGGER_DB_PW","'.addcslashes($db_pass, '\\$"').'");'."\n"; // escape certain password characters stored in double quotes (\) ($) (") |
| 379 | | $cfg_file .= 'define("PLOGGER_DB_NAME","'.$db_name.'");'."\n"; |
| 380 | | $cfg_file .= ''."\n"; |
| 381 | | $cfg_file .= '// define("PLOGGER_EMBEDDED",""); // 1/0 (True/False) if set will overrule automatic check'."\n"; |
| 382 | | $cfg_file .= '// define("PLOGGER_LOCALE",""); // da_DK de et fr pl ro_RO tr ...etc.'."\n"; |
| 383 | | if (ini_get('safe_mode') && function_exists('ftp_connect') && !empty($ftp_host)) { |
| 384 | | //if safe_mode enabled, write the FTP workaround information to plog-config.php with db information |
| 385 | | $cfg_file .= "\n"; |
| 386 | | $cfg_file .= '// these values are used to connect via FTP.'."\n"; |
| 387 | | $cfg_file .= 'define("PLOGGER_FTP_HOST","'.$ftp_host.'");'."\n"; |
| 388 | | $cfg_file .= 'define("PLOGGER_FTP_USER","'.$ftp_user.'");'."\n"; |
| 389 | | $cfg_file .= 'define("PLOGGER_FTP_PW","'.addcslashes($ftp_pass, '\\$"').'");'."\n"; // escape certain password characters stored in double quotes (\) ($) (") |
| 390 | | $cfg_file .= 'define("PLOGGER_FTP_PATH","'.$ftp_path.'");'."\n"; |
| 391 | | } |
| 392 | | |
| 393 | | $cfg_file .= "?>\n"; |
| 394 | | return $cfg_file; |
| 395 | | } |
| 396 | | |
| 397 | | |
| 398 | | function maybe_add_column($table,$column,$add_sql) { |
| 399 | | $sql = "DESCRIBE $table"; |
| 400 | | $res = mysql_query($sql); |
| 401 | | $found = false; |
| 402 | | while($row = mysql_fetch_array($res,MYSQL_NUM)) { |
| 403 | | if ($row[0] == $column) $found = true; |
| 404 | | } |
| 405 | | if (!$found) { |
| 406 | | mysql_query("ALTER TABLE $table ADD `$column` ". $add_sql); |
| 407 | | return "<li>Adding new field $column to database."; |
| 408 | | } else { |
| 409 | | return "<li>$column already present in database."; |
| 410 | | } |
| 411 | | } |
| 412 | | |
| 413 | | function maybe_drop_column($table,$column) { |
| 414 | | $sql = "DESCRIBE $table"; |
| 415 | | $res = mysql_query($sql); |
| 416 | | $found = false; |
| 417 | | while($row = mysql_fetch_array($res,MYSQL_NUM)) { |
| 418 | | if ($row[0] == $column) $found = true; |
| 419 | | } |
| 420 | | if ($found) { |
| 421 | | $sql = "ALTER TABLE $table DROP `$column`"; |
| 422 | | mysql_query($sql); |
| 423 | | return "<li>dropping $column"; |
| 424 | | } else { |
| 425 | | //print "$column does not exist<br/>"; |
| 426 | | } |
| 427 | | } |
| 428 | | |
| 429 | | function maybe_add_table($table,$add_sql,$options = "") { |
| 430 | | $sql = "DESCRIBE $table"; |
| 431 | | $res = mysql_query($sql); |
| 432 | | if (!$res) { |
| 433 | | $q = "CREATE table `$table` ($add_sql) $options"; |
| 434 | | mysql_query($q); |
| 435 | | if (mysql_error()) { |
| 436 | | var_dump(mysql_error()); |
| 437 | | } |
| 438 | | } else { |
| 439 | | return "<li>Table `$table` already exists, ignoring."; |
| 440 | | } |
| 441 | | } |
| 442 | | |
| 443 | | function gd_missing() { |
| 444 | | require_once(PLOGGER_DIR.'/plog-includes/lib/phpthumb/phpthumb.functions.php'); |
| 445 | | // this is copied over from phpthumb |
| 446 | | return phpthumb_functions::gd_version() < 1; |
| 447 | | } |
| 448 | | |
| 449 | | function check_requirements() { |
| 450 | | $errors = array(); |
| 451 | | if (gd_missing()) { |
| 452 | | $errors[] = "PHP GD module was not detected."; |
| 453 | | } |
| 454 | | |
| 455 | | if (!function_exists('mysql_connect')) { |
| 456 | | $errors[] = "PHP MySQL module was not detected."; |
| 457 | | } |
| 458 | | |
| 459 | | $files_to_read = array("./","./plog-admin","./plog-admin/css","./plog-admin/images","./plog-content/images","./plog-content/thumbs","./plog-content/uploads","./plog-includes","./plog-includes/lib"); |
| 460 | | foreach($files_to_read as $file){ |
| 461 | | if (!is_readable(PLOGGER_DIR . $file)){ |
| 462 | | $errors[] = "The path ".realpath(PLOGGER_DIR . $file)." (".$file.") is not readable."; |
| 463 | | } |
| 464 | | } |
| 465 | | |
| 466 | | $files_to_write = array("./","./plog-content/images","./plog-content/thumbs", "./plog-content/uploads"); |
| 467 | | foreach($files_to_write as $file){ |
| 468 | | if (!is_writable(PLOGGER_DIR . $file)){ |
| 469 | | $errors[] = 'The path '.realpath(PLOGGER_DIR . $file).' is not writable by the Web server.'; |
| 470 | | } |
| 471 | | } |
| 472 | | |
| 473 | | return $errors; |
| 474 | | } |
| 475 | | |
| 476 | | function check_mysql($host,$user,$pass,$database) { |
| 477 | | $errors = array(); |
| 478 | | if (function_exists('mysql_connect')) { |
| 479 | | $connection = @mysql_connect($host,$user,$pass); |
| 480 | | if (!$connection) { |
| 481 | | $errors[] = "Cannot connect to MySQL with the information provided. MySQL error: " |
| 482 | | . mysql_error(); |
| 483 | | } |
| 484 | | } |
| 485 | | $select = @mysql_select_db($database); |
| 486 | | if (!$select) { |
| 487 | | $errors[] = "Couldn't find the database $database. MySQL error: " . mysql_error(); |
| 488 | | |
| 489 | | } |
| 490 | | return $errors; |
| 491 | | } |
| 492 | | |
| 493 | | function check_FTP($host, $user, $pass, $path) { |
| 494 | | $errors = array(); |
| 495 | | |
| 496 | | $connection = @ftp_connect($host); |
| 497 | | if (!$connection) { |
| 498 | | $errors[] = "Couldn't connect to FTP host \"$host\". Please check your FTP Host:"; |
| 499 | | } else { |
| 500 | | $login = @ftp_login($connection, $user, $pass); |
| 501 | | if (!$login) { |
| 502 | | $errors[] = "Couldn't login to FTP host \"$host\" with username \"$user\" and password \"$pass\". Please check your FTP Username: and FTP Password:"; |
| 503 | | } else { |
| 504 | | $checkdir = @ftp_chdir($connection, $path."plog-content/images/"); // check to see if the plog-content/images/ folder is accessible |
| 505 | | if (!$checkdir) { |
| 506 | | $errors[] = "Couldn't find the Plogger 'plog-content/images/' folder along the path \"$path\". Please check your FTP Path to Plogger Base Folder (from FTP login):"; |
| 507 | | } |
| 508 | | } |
| 509 | | } |
| 510 | | @ftp_close($connection); |
| 511 | | return $errors; |
| 512 | | } |
| 513 | | |
| 514 | | function generate_password() { |
| 515 | | $src = preg_split("//","abcdefghkmnpqrstuvwxyz23456789",-1,PREG_SPLIT_NO_EMPTY); |
| 516 | | shuffle($src); |
| 517 | | return join("",array_slice($src,0,5)); |
| 518 | | } |
| 519 | | |
| 520 | | function config_writable() { |
| 521 | | $cf = PLOGGER_DIR . "plog-config.php"; |
| 522 | | if (file_exists($cf)) { |
| 523 | | return is_writable($cf); |
| 524 | | } |
| 525 | | return is_writable(PLOGGER_DIR); |
| 526 | | } |
| 527 | | |
| 528 | | function write_config($data) { |
| 529 | | $cf = PLOGGER_DIR . "plog-config.php"; |
| 530 | | $handle = fopen($cf,"w"); |
| 531 | | fwrite($handle,$data); |
| 532 | | fclose($handle); |
| 533 | | } |
| | 345 | '${config['admin_email']}', |
| | 346 | MD5('${config['admin_password']}'), |
| | 347 | 'n.j.Y', |
| | 348 | 'Plogger Photo Feed', |
| | 349 | '${config['gallery_name']}', |
| | 350 | '${config['gallery_url']}')"; |
| | 351 | } else { |
| | 352 | $query = "UPDATE `".TABLE_PREFIX."config` SET |
| | 353 | `theme_dir` = 'default', |
| | 354 | `compression` = 75, |
| | 355 | `max_thumbnail_size` = 100, |
| | 356 | `max_display_size` = 500, |
| | 357 | `thumb_num` = 20, |
| | 358 | `admin_username` = '${config['admin_username']}', |
| | 359 | `admin_email` = '${config['admin_email']}', |
| | 360 | `admin_password` = MD5('${config['admin_password']}'), |
| | 361 | `date_format` = 'n.j.Y', |
| | 362 | `feed_title` = 'Plogger Photo Feed', |
| | 363 | `gallery_name` = '${config['gallery_name']}', |
| | 364 | `gallery_url` = '${config['gallery_url']}'"; |
| | 365 | } |
| | 366 | |
| | 367 | mysql_query($query) or die(mysql_error().'<br /><br />'. $query); |
| | 368 | |
| | 369 | mail($config['admin_email'],"Your new gallery","You have successfully installed your new Plogger gallery. You can manage it at ${config['gallery_url']}plog-admin Username is ${config['admin_username']} and password ${config['admin_password']}."); |
| | 370 | } |
| | 371 | |
| | 372 | function create_config_file($db_host,$db_user,$db_pass,$db_name,$ftp_host,$ftp_user,$ftp_pass,$ftp_path) { |
| | 373 | $cfg_file = "<?php\n"; |
| | 374 | $cfg_file .= '// this is the file used to connect to your database.'."\n"; |
| | 375 | $cfg_file .= '// you must change these values in order to run the gallery.'."\n"; |
| | 376 | $cfg_file .= 'define("PLOGGER_DB_HOST","'.$db_host.'");'."\n"; |
| | 377 | $cfg_file .= 'define("PLOGGER_DB_USER","'.$db_user.'");'."\n"; |
| | 378 | $cfg_file .= 'define("PLOGGER_DB_PW","'.addcslashes($db_pass, '\\$"').'");'."\n"; // escape certain password characters stored in double quotes (\) ($) (") |
| | 379 | $cfg_file .= 'define("PLOGGER_DB_NAME","'.$db_name.'");'."\n"; |
| | 380 | $cfg_file .= ''."\n"; |
| | 381 | $cfg_file .= '// define("PLOGGER_EMBEDDED",""); // 1/0 (True/False) if set will overrule automatic check'."\n"; |
| | 382 | $cfg_file .= '// define("PLOGGER_LOCALE",""); // da_DK de et fr pl ro_RO tr ...etc.'."\n"; |
| | 383 | if (ini_get('safe_mode') && function_exists('ftp_connect') && !empty($ftp_host)) { |
| | 384 | //if safe_mode enabled, write the FTP workaround information to plog-config.php with db information |
| | 385 | $cfg_file .= "\n"; |
| | 386 | $cfg_file .= '// these values are used to connect via FTP.'."\n"; |
| | 387 | $cfg_file .= 'define("PLOGGER_FTP_HOST","'.$ftp_host.'");'."\n"; |
| | 388 | $cfg_file .= 'define("PLOGGER_FTP_USER","'.$ftp_user.'");'."\n"; |
| | 389 | $cfg_file .= 'define("PLOGGER_FTP_PW","'.addcslashes($ftp_pass, '\\$"').'");'."\n"; // escape certain password characters stored in double quotes (\) ($) (") |
| | 390 | $cfg_file .= 'define("PLOGGER_FTP_PATH","'.$ftp_path.'");'."\n"; |
| | 391 | } |
| | 392 | |
| | 393 | $cfg_file .= "?>\n"; |
| | 394 | return $cfg_file; |
| | 395 | } |
| | 396 | |
| | 397 | |
| | 398 | function maybe_add_column($table,$column,$add_sql) { |
| | 399 | $sql = "DESCRIBE $table"; |
| | 400 | $res = mysql_query($sql); |
| | 401 | $found = false; |
| | 402 | while($row = mysql_fetch_array($res,MYSQL_NUM)) { |
| | 403 | if ($row[0] == $column) $found = true; |
| | 404 | } |
| | 405 | if (!$found) { |
| | 406 | mysql_query("ALTER TABLE $table ADD `$column` ". $add_sql); |
| | 407 | return "<li>Adding new field $column to database."; |
| | 408 | } else { |
| | 409 | return "<li>$column already present in database."; |
| | 410 | } |
| | 411 | } |
| | 412 | |
| | 413 | function maybe_drop_column($table,$column) { |
| | 414 | $sql = "DESCRIBE $table"; |
| | 415 | $res = mysql_query($sql); |
| | 416 | $found = false; |
| | 417 | while($row = mysql_fetch_array($res,MYSQL_NUM)) { |
| | 418 | if ($row[0] == $column) $found = true; |
| | 419 | } |
| | 420 | if ($found) { |
| | 421 | $sql = "ALTER TABLE $table DROP `$column`"; |
| | 422 | mysql_query($sql); |
| | 423 | return "<li>dropping $column"; |
| | 424 | } else { |
| | 425 | //print "$column does not exist<br/>"; |
| | 426 | } |
| | 427 | } |
| | 428 | |
| | 429 | function maybe_add_table($table,$add_sql,$options = "") { |
| | 430 | $sql = "DESCRIBE $table"; |
| | 431 | $res = mysql_query($sql); |
| | 432 | if (!$res) { |
| | 433 | $q = "CREATE table `$table` ($add_sql) $options"; |
| | 434 | |