Changeset 550 for trunk/plog-admin/includes/install-functions.php
- Timestamp:
- 06/30/08 13:45:19 (4 years ago)
- Location:
- trunk/plog-admin
- Files:
-
- 1 added
- 1 copied
- 1 moved
-
. (moved) (moved from trunk/admin)
-
includes (added)
-
includes/install-functions.php (copied) (copied from trunk/lib/plogger/install_functions.php) (11 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/plog-admin/includes/install-functions.php
r546 r550 1 1 <?php 2 require_once(PLOGGER_DIR . 'admin/plog-admin-functions.php'); 3 @include(PLOGGER_DIR . 'plog-config.php'); 2 if (!defined('PLOGGER_DIR')) { 3 return false; 4 } 5 require_once(PLOGGER_DIR.'plog-admin/plog-admin-functions.php'); 6 @include(PLOGGER_DIR.'plog-config.php'); 4 7 5 8 function do_install($form) { 6 9 $form = array_map('stripslashes',$form); 7 10 $form = array_map('trim',$form); 8 11 9 12 $errors = check_requirements(); 10 13 if (sizeof($errors) > 0) { … … 43 46 $errors[] = 'Please enter the MySQL password.'; 44 47 } 45 48 46 49 if (empty($form['db_name'])) { 47 50 $errors[] = 'Please enter the MySQL database name.'; 48 51 } 49 52 50 53 if (empty($form['gallery_name'])) { 51 54 $errors[] = 'Please enter the name for your gallery.'; 52 55 } 53 56 54 57 if (empty($form['admin_email'])) { 55 58 $errors[] = 'Please enter your e-mail address.'; 56 59 } 57 60 58 61 if (ini_get('safe_mode') && function_exists('ftp_connect')) { 59 62 //if safe_mode enabled, check the FTP information form inputs … … 67 70 68 71 if (empty($form['ftp_pass'])) { 69 $errors[] = 'Please enter the FTP password.';70 } 71 72 $errors[] = 'Please enter the FTP password.'; 73 } 74 72 75 if (!empty($form['ftp_path'])) { 73 76 if (substr($form['ftp_path'],0,1)!="/"){ … … 98 101 $password = generate_password(); 99 102 $_SESSION["install_values"] = array( 100 "gallery_name" => $form["gallery_name"],101 "admin_email" => $form["admin_email"],102 "admin_password" => $password,103 "admin_username" => "admin"103 "gallery_name" => $form["gallery_name"], 104 "admin_email" => $form["admin_email"], 105 "admin_password" => $password, 106 "admin_username" => "admin" 104 107 ); 105 108 106 109 if (ini_get('safe_mode') && function_exists('ftp_connect')) { 107 110 $conf = create_config_file($form['db_host'],$form['db_user'],$form['db_pass'],$form['db_name'],$form['ftp_host'],$form['ftp_user'],$form['ftp_pass'],$form['ftp_path']); … … 117 120 $_SESSION["plogger_config"] = $conf; 118 121 } 119 require(PLOGGER_DIR . ' lib/plogger/form_setup_complete.php');122 require(PLOGGER_DIR . 'plog-admin/includes/install-form-setup-complete.php'); 120 123 return true; 121 124 } … … 126 129 $form['db_host'] = 'localhost'; 127 130 } 128 if (empty($form['ftp_host'])) {131 if (empty($form['ftp_host'])) { 129 132 $form['ftp_host'] = 'localhost'; 130 133 } … … 136 139 } 137 140 } 138 require(PLOGGER_DIR . ' lib/plogger/form_setup.php');141 require(PLOGGER_DIR . 'plog-admin/includes/install-form-setup.php'); 139 142 } 140 143 … … 152 155 153 156 maybe_add_table( 154 TABLE_PREFIX . 'collections'155 ,"`name` varchar(128) NOT NULL default '',156 `description` varchar(255) NOT NULL default '',157 `path` varchar(255) NOT NULL default '',158 `id` int(11) NOT NULL auto_increment,159 `thumbnail_id` int(11) NOT NULL DEFAULT '0',160 PRIMARY KEY (id)"161 ,"Type=MyISAM $default_charset");162 163 164 maybe_add_table( 165 TABLE_PREFIX . 'albums'166 ," `name` varchar(128) NOT NULL default '',167 `id` int(11) NOT NULL auto_increment,168 `description` varchar(255) NOT NULL default '',169 `path` varchar(255) NOT NULL default '',170 `parent_id` int(11) NOT NULL default '0',171 `thumbnail_id` int(11) NOT NULL default '0',172 PRIMARY KEY (id),173 INDEX pid_idx (parent_id)"174 ," Type=MyISAM $default_charset");175 176 maybe_add_table( 177 TABLE_PREFIX . 'pictures'178 ,"`path` varchar(255) NOT NULL default '',179 `parent_album` int(11) NOT NULL default '0',180 `parent_collection` int(11) NOT NULL default '0',181 `caption` mediumtext NOT NULL,182 `description` text NOT NULL,183 `id` int(11) NOT NULL auto_increment,184 `date_modified` timestamp(14) NOT NULL,185 `date_submitted` timestamp(14) NOT NULL,186 `EXIF_date_taken` varchar(64) NOT NULL default '',187 `EXIF_camera` varchar(64) NOT NULL default '',188 `EXIF_shutterspeed` varchar(64) NOT NULL default '',189 `EXIF_focallength` varchar(64) NOT NULL default '',190 `EXIF_flash` varchar(64) NOT NULL default '',191 `EXIF_aperture` varchar(64) NOT NULL default '',192 `allow_comments` int(11) NOT NULL default '1',193 PRIMARY KEY (id),194 INDEX pa_idx (parent_album),195 INDEX pc_idx (parent_collection)"196 ,"Type=MyISAM $default_charset");197 198 maybe_add_table( 199 TABLE_PREFIX . 'comments'200 ,"`id` int(11) NOT NULL auto_increment,201 `parent_id` int(11) NOT NULL default '0',202 `author` varchar(64) NOT NULL default '',203 `email` varchar(64) NOT NULL default '',204 `url` varchar(64) NOT NULL default '',205 `date` datetime NOT NULL,206 `comment` longtext NOT NULL,207 `ip` char(64),208 `approved` tinyint default '1',209 PRIMARY KEY (id),210 INDEX pid_idx (parent_id),211 INDEX approved_idx (approved)"212 ,"Type=MyISAM $default_charset");213 214 maybe_add_table( 215 TABLE_PREFIX . 'config'216 ,"`max_thumbnail_size` int(11) NOT NULL default '0',217 `max_display_size` int(11) NOT NULL default '0',218 `thumb_num` int(11) NOT NULL default '0',219 `admin_username` varchar(64) NOT NULL default '',220 `admin_password` varchar(64) NOT NULL default '',221 `admin_email` varchar(50) NOT NULL default '',222 `date_format` varchar(64) NOT NULL default '',223 `compression` int(11) NOT NULL default '75',224 `default_sortby` varchar(20) NOT NULL default '',225 `default_sortdir` varchar(5) NOT NULL default '',226 `album_sortby` varchar(20) NOT NULL default '',227 `album_sortdir` varchar(5) NOT NULL default '',228 `collection_sortby` varchar(20) NOT NULL default '',229 `collection_sortdir` varchar(5) NOT NULL default '',230 `gallery_name` varchar(255) NOT NULL default '',231 `allow_dl` smallint(1) NOT NULL default '0',232 `allow_comments` smallint(1) NOT NULL default '1',233 `allow_print` smallint(1) NOT NULL default '1',234 `truncate` int(11) NOT NULL default '12',235 `square_thumbs` tinyint default 1,236 `feed_num_entries` int(15) NOT NULL default '15',237 `rss_thumbsize` int(11) NOT NULL default '400',238 `feed_title` text NOT NULL,239 `use_mod_rewrite` tinyint NOT NULL default '0',240 `gallery_url` varchar(255) NOT NULL default '',241 `comments_notify` tinyint NOT NULL default '1',242 `comments_moderate` tinyint NOT NULL default '0',243 `feed_language` varchar(255) NOT NULL default 'en-us',244 `theme_dir` varchar(128) NOT NULL default '',245 `thumb_nav_range` int(11) NOT NULL default '0',246 `enable_thumb_nav` tinyint default '0',247 `allow_fullpic` tinyint default '1'"248 ,"Type=MyISAM $default_charset");249 250 maybe_add_table( 251 TABLE_PREFIX . 'thumbnail_config'252 ,"`id` int(10) unsigned NOT NULL auto_increment,253 `update_timestamp` int(10) unsigned default NULL,254 `max_size` int(10) unsigned default NULL,255 `disabled` tinyint default 0,256 PRIMARY KEY (`id`)");257 258 maybe_add_table( 259 TABLE_PREFIX . 'tag2picture'260 ,"`tag_id` bigint(20) unsigned NOT NULL default '0',261 `picture_id` bigint(20) unsigned NOT NULL default '0',262 `tagdate` datetime default NULL,263 KEY `tag_id` (`tag_id`),264 KEY `picture_id` (`picture_id`)"265 ,"Type=MyISAM $default_charset");266 267 maybe_add_table( 268 TABLE_PREFIX . 'tags'269 ,"`id` bigint(20) unsigned NOT NULL auto_increment,270 `tag` char(50) NOT NULL default '',271 `tagdate` datetime NOT NULL default '0000-00-00 00:00:00',272 `urlified` char(50) NOT NULL default '',273 PRIMARY KEY (`id`),274 UNIQUE `tag` (`tag`),275 UNIQUE `urlified` (`urlified`)"276 ,"Type=MyISAM $default_charset");157 TABLE_PREFIX . 'collections' 158 ,"`name` varchar(128) NOT NULL default '', 159 `description` varchar(255) NOT NULL default '', 160 `path` varchar(255) NOT NULL default '', 161 `id` int(11) NOT NULL auto_increment, 162 `thumbnail_id` int(11) NOT NULL DEFAULT '0', 163 PRIMARY KEY (id)" 164 ,"Type=MyISAM $default_charset"); 165 166 167 maybe_add_table( 168 TABLE_PREFIX . 'albums' 169 ," `name` varchar(128) NOT NULL default '', 170 `id` int(11) NOT NULL auto_increment, 171 `description` varchar(255) NOT NULL default '', 172 `path` varchar(255) NOT NULL default '', 173 `parent_id` int(11) NOT NULL default '0', 174 `thumbnail_id` int(11) NOT NULL default '0', 175 PRIMARY KEY (id), 176 INDEX pid_idx (parent_id)" 177 ," Type=MyISAM $default_charset"); 178 179 maybe_add_table( 180 TABLE_PREFIX . 'pictures' 181 ,"`path` varchar(255) NOT NULL default '', 182 `parent_album` int(11) NOT NULL default '0', 183 `parent_collection` int(11) NOT NULL default '0', 184 `caption` mediumtext NOT NULL, 185 `description` text NOT NULL, 186 `id` int(11) NOT NULL auto_increment, 187 `date_modified` timestamp(14) NOT NULL, 188 `date_submitted` timestamp(14) NOT NULL, 189 `EXIF_date_taken` varchar(64) NOT NULL default '', 190 `EXIF_camera` varchar(64) NOT NULL default '', 191 `EXIF_shutterspeed` varchar(64) NOT NULL default '', 192 `EXIF_focallength` varchar(64) NOT NULL default '', 193 `EXIF_flash` varchar(64) NOT NULL default '', 194 `EXIF_aperture` varchar(64) NOT NULL default '', 195 `allow_comments` int(11) NOT NULL default '1', 196 PRIMARY KEY (id), 197 INDEX pa_idx (parent_album), 198 INDEX pc_idx (parent_collection)" 199 ,"Type=MyISAM $default_charset"); 200 201 maybe_add_table( 202 TABLE_PREFIX . 'comments' 203 ,"`id` int(11) NOT NULL auto_increment, 204 `parent_id` int(11) NOT NULL default '0', 205 `author` varchar(64) NOT NULL default '', 206 `email` varchar(64) NOT NULL default '', 207 `url` varchar(64) NOT NULL default '', 208 `date` datetime NOT NULL, 209 `comment` longtext NOT NULL, 210 `ip` char(64), 211 `approved` tinyint default '1', 212 PRIMARY KEY (id), 213 INDEX pid_idx (parent_id), 214 INDEX approved_idx (approved)" 215 ,"Type=MyISAM $default_charset"); 216 217 maybe_add_table( 218 TABLE_PREFIX . 'config' 219 ,"`max_thumbnail_size` int(11) NOT NULL default '0', 220 `max_display_size` int(11) NOT NULL default '0', 221 `thumb_num` int(11) NOT NULL default '0', 222 `admin_username` varchar(64) NOT NULL default '', 223 `admin_password` varchar(64) NOT NULL default '', 224 `admin_email` varchar(50) NOT NULL default '', 225 `date_format` varchar(64) NOT NULL default '', 226 `compression` int(11) NOT NULL default '75', 227 `default_sortby` varchar(20) NOT NULL default '', 228 `default_sortdir` varchar(5) NOT NULL default '', 229 `album_sortby` varchar(20) NOT NULL default '', 230 `album_sortdir` varchar(5) NOT NULL default '', 231 `collection_sortby` varchar(20) NOT NULL default '', 232 `collection_sortdir` varchar(5) NOT NULL default '', 233 `gallery_name` varchar(255) NOT NULL default '', 234 `allow_dl` smallint(1) NOT NULL default '0', 235 `allow_comments` smallint(1) NOT NULL default '1', 236 `allow_print` smallint(1) NOT NULL default '1', 237 `truncate` int(11) NOT NULL default '12', 238 `square_thumbs` tinyint default 1, 239 `feed_num_entries` int(15) NOT NULL default '15', 240 `rss_thumbsize` int(11) NOT NULL default '400', 241 `feed_title` text NOT NULL, 242 `use_mod_rewrite` tinyint NOT NULL default '0', 243 `gallery_url` varchar(255) NOT NULL default '', 244 `comments_notify` tinyint NOT NULL default '1', 245 `comments_moderate` tinyint NOT NULL default '0', 246 `feed_language` varchar(255) NOT NULL default 'en-us', 247 `theme_dir` varchar(128) NOT NULL default '', 248 `thumb_nav_range` int(11) NOT NULL default '0', 249 `enable_thumb_nav` tinyint default '0', 250 `allow_fullpic` tinyint default '1'" 251 ,"Type=MyISAM $default_charset"); 252 253 maybe_add_table( 254 TABLE_PREFIX . 'thumbnail_config' 255 ,"`id` int(10) unsigned NOT NULL auto_increment, 256 `update_timestamp` int(10) unsigned default NULL, 257 `max_size` int(10) unsigned default NULL, 258 `disabled` tinyint default 0, 259 PRIMARY KEY (`id`)"); 260 261 maybe_add_table( 262 TABLE_PREFIX . 'tag2picture' 263 ,"`tag_id` bigint(20) unsigned NOT NULL default '0', 264 `picture_id` bigint(20) unsigned NOT NULL default '0', 265 `tagdate` datetime default NULL, 266 KEY `tag_id` (`tag_id`), 267 KEY `picture_id` (`picture_id`)" 268 ,"Type=MyISAM $default_charset"); 269 270 maybe_add_table( 271 TABLE_PREFIX . 'tags' 272 ,"`id` bigint(20) unsigned NOT NULL auto_increment, 273 `tag` char(50) NOT NULL default '', 274 `tagdate` datetime NOT NULL default '0000-00-00 00:00:00', 275 `urlified` char(50) NOT NULL default '', 276 PRIMARY KEY (`id`), 277 UNIQUE `tag` (`tag`), 278 UNIQUE `urlified` (`urlified`)" 279 ,"Type=MyISAM $default_charset"); 277 280 278 281 } … … 283 286 284 287 $thumbnail_sizes = array( 285 THUMB_SMALL => 100,286 THUMB_LARGE => 500,287 THUMB_RSS => 400,288 THUMB_NAV => 60288 THUMB_SMALL => 100, 289 THUMB_LARGE => 500, 290 THUMB_RSS => 400, 291 THUMB_NAV => 60 289 292 ); 290 293 291 294 foreach($thumbnail_sizes as $key => $size) { 292 295 $sql = "INSERT INTO `".TABLE_PREFIX."thumbnail_config` (id,update_timestamp,max_size) 293 VALUES('$key','$long_ago','$size')";296 VALUES('$key','$long_ago','$size')"; 294 297 mysql_query($sql); 295 298 } 296 299 297 $config['default_theme_dir'] = PLOGGER_DIR . 'themes/default/'; 298 $config['baseurl'] = "http://".$_SERVER["SERVER_NAME"]. substr($_SERVER["PHP_SELF"],0,strrpos($_SERVER["PHP_SELF"],"/")) . "/"; 300 $config['default_theme_dir'] = PLOGGER_DIR . 'plog-content/themes/default/'; 301 $config['gallery_url'] = "http://".$_SERVER["SERVER_NAME"]. dirname(dirname($_SERVER["PHP_SELF"])); 302 // verify that gallery URL contains a trailing slash. if not, add one. 303 if ($config['gallery_url']{strlen($config['gallery_url'])-1} != '/'){ 304 $config['gallery_url'] .= '/'; 305 } 306 // verify that the gallery URL begins with 'http://' for mod_rewrite 301 redirects 307 if (strpos($config['gallery_url'], 'http://') === false){ 308 $config['gallery_url'] = 'http://'.$config['gallery_url']; 309 } 310 // verify that the gallery URL has a 'www.' for mod_rewrite 301 redirects 311 if (strpos($config['gallery_url'], "www.") === false){ 312 $config['gallery_url'] = str_replace("http://", "http://www.", $config['gallery_url']); 313 } 299 314 $config['admin_username'] = 'admin'; 300 315 $config['admin_password'] = $form['admin_password']; 301 316 $config['admin_email'] = $form['admin_email']; 302 317 $config['gallery_name'] = $form['gallery_name']; 303 318 304 319 $config = array_map('mysql_real_escape_string',$config); 305 320 306 321 $row_exist = mysql_query("SELECT * FROM `".TABLE_PREFIX."config`"); 307 322 $row_exist_num = mysql_num_rows($row_exist); … … 309 324 if ($row_exist_num == 0) { 310 325 $query = "INSERT INTO `".TABLE_PREFIX."config` 311 (`theme_dir`,312 `compression`,313 `max_thumbnail_size`,314 `max_display_size`,315 `thumb_num`,316 `admin_username`,317 `admin_email`,318 `admin_password`,319 `date_format`,320 `feed_title`,321 `gallery_name`,322 `gallery_url`)326 (`theme_dir`, 327 `compression`, 328 `max_thumbnail_size`, 329 `max_display_size`, 330 `thumb_num`, 331 `admin_username`, 332 `admin_email`, 333 `admin_password`, 334 `date_format`, 335 `feed_title`, 336 `gallery_name`, 337 `gallery_url`) 323 338 VALUES 324 ('${config['default_theme_dir']}',339 ('${config['default_theme_dir']}', 325 340 75, 326 341 100, … … 328 343 20, 329 344 '${config['admin_username']}', 330 '${config['admin_email']}',331 MD5('${config['admin_password']}'),332 'n.j.Y',333 'Plogger Photo Feed',334 '${config['gallery_name']}',335 '${config['baseurl']}')";336 } else {337 $query = "UPDATE `".TABLE_PREFIX."config` SET338 `theme_dir` = '${config['default_theme_dir']}',339 `compression` = 75,340 `max_thumbnail_size` = 100,341 `max_display_size` = 500,342 `thumb_num` = 20,343 `admin_username` = '${config['admin_username']}',344 `admin_email` = '${config['admin_email']}',345 `admin_password` = MD5('${config['admin_password']}'),346 `date_format` = 'n.j.Y',347 `feed_title` = 'Plogger Photo Feed',348 `gallery_name` = '${config['gallery_name']}',349 `gallery_url` = '${config['baseurl']}'";350 }351 352 mysql_query($query) or die(mysql_error().'<br /><br />'. $query);353 354 mail($config['admin_email'],"Your new gallery","You have successfully installed your new Plogger gallery. You can manage it at ${config['baseurl']}admin Username is ${config['admin_username']} and password ${config['admin_password']}.");355 }356 357 function create_config_file($db_host,$db_user,$db_pass,$db_name,$ftp_host,$ftp_user,$ftp_pass,$ftp_path) {358 $cfg_file = "<?php\n";359 $cfg_file .= '// this is the file used to connect to your database.'."\n";360 $cfg_file .= '// you must change these values in order to run the gallery.'."\n";361 $cfg_file .= 'define("PLOGGER_DB_HOST","'.$db_host.'");'."\n";362 $cfg_file .= 'define("PLOGGER_DB_USER","'.$db_user.'");'."\n";363 $cfg_file .= 'define("PLOGGER_DB_PW","'.addcslashes($db_pass, '\\$"').'");'."\n"; // escape certain password characters stored in double quotes (\) ($) (")364 $cfg_file .= 'define("PLOGGER_DB_NAME","'.$db_name.'");'."\n";365 $cfg_file .= ''."\n";366 $cfg_file .= '// define("PLOGGER_EMBEDDED",""); // 1/0 (True/False) if set will overrule automatic check'."\n";367 $cfg_file .= '// define("PLOGGER_LOCALE",""); // da_DK de et fr pl ro_RO tr ...etc.'."\n";368 if (ini_get('safe_mode') && function_exists('ftp_connect') && !empty($ftp_host)) {369 //if safe_mode enabled, write the FTP workaround information to plog-config.php with db information370 $cfg_file .= "\n";371 $cfg_file .= '// these values are used to connect via FTP.'."\n";372 $cfg_file .= 'define("PLOGGER_FTP_HOST","'.$ftp_host.'");'."\n";373 $cfg_file .= 'define("PLOGGER_FTP_USER","'.$ftp_user.'");'."\n";374 $cfg_file .= 'define("PLOGGER_FTP_PW","'.addcslashes($ftp_pass, '\\$"').'");'."\n"; // escape certain password characters stored in double quotes (\) ($) (")375 $cfg_file .= 'define("PLOGGER_FTP_PATH","'.$ftp_path.'");'."\n";376 }377 378 $cfg_file .= "?>\n";379 return $cfg_file;380 }381 382 383 function maybe_add_column($table,$column,$add_sql) {384 $sql = "DESCRIBE $table";385 $res = mysql_query($sql);386 $found = false;387 while($row = mysql_fetch_array($res,MYSQL_NUM)) {388 if ($row[0] == $column) $found = true;389 }390 if (!$found) {391 mysql_query("ALTER TABLE $table ADD `$column` ". $add_sql);392 return "<li>Adding new field $column to database.";393 } else {394 return "<li>$column already present in database.";395 }396 }397 398 function maybe_drop_column($table,$column) {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 $sql = "ALTER TABLE $table DROP `$column`";407 mysql_query($sql);408 return "<li>dropping $column";409 } else {410 //print "$column does not exist<br/>";411 }412 }413 414 function maybe_add_table($table,$add_sql,$options = "") {415 $sql = "DESCRIBE $table";416 $res = mysql_query($sql);417 if (!$res) {418 $q = "CREATE table `$table` ($add_sql) $options";419 mysql_query($q);420 if (mysql_error()) {421 var_dump(mysql_error());422 }423 } else {424 return "<li>Table `$table` already exists, ignoring.";425 }426 }427 428 function gd_missing() {429 require_once(dirname(__FILE__) . '/../../lib/phpthumb/phpthumb.functions.php');430 // this is copied over from phpthumb431 return phpthumb_functions::gd_version() < 1;432 }433 434 function check_requirements() {435 $errors = array();436 if (gd_missing()) {437 $errors[] = "PHP GD module was not detected.";438 }439 440 if (!function_exists('mysql_connect')) {441 $errors[] = "PHP MySQL module was not detected.";442 }443 444 $files_to_read = array("./","./admin","./css","./images","./lib","./thumbs","./uploads");445 foreach($files_to_read as $file){446 if (!is_readable(PLOGGER_DIR . $file)){447 $errors[] = "The path ".realpath(PLOGGER_DIR . $file)." (".$file.") is not readable.";448 }449 }450 451 $files_to_write = array("./","./thumbs","./images", "./uploads");452 foreach($files_to_write as $file){453 if (!is_writable(PLOGGER_DIR . $file)){454 $errors[] = 'The path '.realpath(PLOGGER_DIR . $file).' is not writable by the Web server.';455 }456 }457 458 return $errors;459 }460 461 function check_mysql($host,$user,$pass,$database) {462 $errors = array();463 if (function_exists('mysql_connect')) {464 $connection = @mysql_connect($host,$user,$pass);465 if (!$connection) {466 $errors[] = "Cannot connect to MySQL with the information provided. MySQL error: "467 . mysql_error();468 }469 }470 $select = @mysql_select_db($database);471 if (!$select) {472 $errors[] = "Couldn't find the database $database. MySQL error: " . mysql_error();473 474 }475 return $errors;476 }477 478 function check_FTP($host, $user, $pass, $path) {479 $errors = array();480 481 $connection = @ftp_connect($host);482 if (!$connection) {483 $errors[] = "Couldn't connect to FTP host \"$host\". Please check your FTP Host:";484 } else {485 $login = @ftp_login($connection, $user, $pass);486 if (!$login) {487 $errors[] = "Couldn't login to FTP host \"$host\" with username \"$user\" and password \"$pass\". Please check your FTP Username: and FTP Password:";488 } else {489 $checkdir = @ftp_chdir($connection, $path."images/"); // check to see if theimages/ folder is accessible490 if (!$checkdir) {491 $errors[] = "Couldn't find the Plogger images\folder along the path \"$path\". Please check your FTP Path to Plogger Base Folder (from FTP login):";492 }493 }494 }495 @ftp_close($connection);496 return $errors;497 }498 499 function generate_password() {500 $src = preg_split("//","abcdefghkmnpqrstuvwxyz23456789",-1,PREG_SPLIT_NO_EMPTY);501 shuffle($src);502 return join("",array_slice($src,0,5));503 }504 505 function config_writable() {506 $cf = PLOGGER_DIR . "plog-config.php";507 if (file_exists($cf)) {508 return is_writable($cf);509 }510 return is_writable(PLOGGER_DIR);511 } 512 513 function write_config($data) {514 $cf = PLOGGER_DIR . "plog-config.php";515 $handle = fopen($cf,"w");516 fwrite($handle,$data);517 fclose($handle);518 }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 } 519 534 520 535 ?>
Note: See TracChangeset
for help on using the changeset viewer.
