mirror of
https://github.com/Pathduck/gallery3.git
synced 2026-07-22 15:53:50 -04:00
Squashed commit of the following: commitf2336a5aaaAuthor: Chad Parry <github@chad.parry.org> Date: Wed May 18 21:56:10 2011 -0600 Behave reasonably if the image cannot be resized. commite06b20738dAuthor: Chad Parry <github@chad.parry.org> Date: Wed May 18 21:10:08 2011 -0600 Adding an image representing a broken thumbnail. This image was derived from the equivalent Gallery2 icon. It uses the same washed-out gray color scheme as the Gallery3 missing_movie icon. commit4e3964527bAuthor: Chad Parry <github@chad.parry.org> Date: Wed May 18 20:30:28 2011 -0600 Initialize legal file arrays correctly. commite9862d8fbcAuthor: Chad Parry <github@chad.parry.org> Date: Wed May 18 20:20:19 2011 -0600 Correction for the merge conflict markers I accidentally committed. commit5e62d327a8Author: Chad Parry <github@chad.parry.org> Date: Wed May 18 20:17:36 2011 -0600 Expand the legal_file events to include separate photo and movie events, and to support MIME types. commitf0bfd1fef0Merge:72f3fc4db73413Author: Chad Parry <github@chad.parry.org> Date: Wed May 18 19:49:25 2011 -0600 Merge branch 'master' of https://github.com/gallery/gallery3 into rawphoto Conflicts: modules/gallery/helpers/system.php modules/gallery/tests/System_Helper_Test.php commitdb734130c5Author: Automatic Build Number Updater <bharat+gallery3_build_number_updater@menalto.com> Date: Mon May 16 21:38:07 2011 -0700 Automated update of .build_number to 153 for branch master Last update:9aeb824aa1(1 commits ago) commit8549ba30caAuthor: Chad Kieffer <ckieffer@gmail.com> Date: Mon May 16 22:37:09 2011 -0600 Stop IE 9 album grid craziness. Thanks floridave. Fixes #1430. commit9aeb824aa1Author: Automatic Build Number Updater <bharat+gallery3_build_number_updater@menalto.com> Date: Sun May 8 11:43:38 2011 -0700 Automated update of .build_number to 152 for branch master Last update:7c80e6ef84(1 commits ago) commit57f7e42a12Author: Bharat Mediratta <bharat@menalto.com> Date: Sun May 8 11:42:40 2011 -0700 Add the item id to the print_proxy line so that we have a little more info about what the original was, and extend the timeout to 90 days from 10. Fixes #1733. commit7c80e6ef84Author: Automatic Build Number Updater <bharat+gallery3_build_number_updater@menalto.com> Date: Fri May 6 11:48:43 2011 -0700 Automated update of .build_number to 151 for branch master Last update:5d09cbff04(1 commits ago) commit80dda6f64fMerge:5d09cbf46da011Author: Bharat Mediratta <bharat@menalto.com> Date: Fri May 6 11:48:13 2011 -0700 Merge pull request #52 from chadparry/tempnam Fixes #1732 commit5d09cbff04Author: Automatic Build Number Updater <bharat+gallery3_build_number_updater@menalto.com> Date: Thu May 5 21:53:39 2011 -0700 Automated update of .build_number to 150 for branch master Last update:011eaa6480(1 commits ago) commitd5a31ceedeAuthor: Tim Almdal <tnalmdal@shaw.ca> Date: Thu May 5 21:53:10 2011 -0700 Fix for ticket 1275. Do the same checking as Kohana uses and don't worry about calling the utf8_encode routine. Corrected the error messages and also added a check to insure the XML Parser extension is loaded as we still need the utf8_encode function from it. commit011eaa6480Author: Automatic Build Number Updater <bharat+gallery3_build_number_updater@menalto.com> Date: Thu May 5 14:53:06 2011 -0700 Automated update of .build_number to 149 for branch master Last update:05ecfda36b(1 commits ago) commit5bae21864fAuthor: Bharat Mediratta <bharat@menalto.com> Date: Thu May 5 14:52:47 2011 -0700 Follow-on to6f916e49d5-- don't make database calls if Gallery isn't installed, else we fail to bounce the user to the installer on fresh packages. #1637. commit46da011bf6Author: Chad Parry <github@chad.parry.org> Date: Wed May 4 17:51:00 2011 -0600 Remove a newline I accidentally introduced. commit5c6c71ffcdMerge:d2331bf05ecfdaAuthor: Chad Parry <github@chad.parry.org> Date: Wed May 4 17:49:42 2011 -0600 Merge branch 'master' into tempnam commitd2331bf434Author: Chad Parry <github@chad.parry.org> Date: Wed May 4 17:48:25 2011 -0600 Simplified the temp_filename implementation and removed the mocks. commit72f3fc46f6Author: Chad Parry <github@chad.parry.org> Date: Wed May 4 17:22:15 2011 -0600 Avoid "self::" because Kohana can't override it. commit05ecfda36bAuthor: Automatic Build Number Updater <bharat+gallery3_build_number_updater@menalto.com> Date: Mon May 2 21:38:50 2011 -0700 Automated update of .build_number to 148 for branch master Last update:97400b7815(2 commits ago) commit229bfc5c7cAuthor: Bharat Mediratta <bharat@menalto.com> Date: Mon May 2 21:37:04 2011 -0700 Track and redirect core.DownloadItem requests properly. This can happen if the G2 was imported with rewrite on, so the g2_url in the g2_map table has a shortened url, but then rewrite is disabled and the .htaccess mod_rewrite rules are sending over a &g2_view=core.DownloadItem request. Fixes #1728. commit68370b92f5Author: Bharat Mediratta <bharat@menalto.com> Date: Mon May 2 21:36:17 2011 -0700 Map the G2 album highlight thumbnail derivative id to the G3 album's thumbnail. Fixes #1729. commit13dbd3515bMerge:f0f094c97400b7Author: Chad Parry <github@chad.parry.org> Date: Sat Apr 30 20:33:02 2011 -0600 Merge branch 'master' of https://github.com/gallery/gallery3 into rawphoto commitf0f094c3f7Author: Chad Parry <github@chad.parry.org> Date: Sat Apr 30 20:22:49 2011 -0600 Explain the conditional rename in item::save() with a comment. commit1b3a6b85c1Author: Chad Parry <github@chad.parry.org> Date: Sat Apr 30 18:29:34 2011 -0600 Improve the comment explaining why the data_file extension is important. commitc3e8c1e3b5Author: Chad Parry <github@chad.parry.org> Date: Sat Apr 30 18:12:56 2011 -0600 The data_file field is public, so we don't need to supply an accessor method. commit0e844766baAuthor: Chad Parry <github@chad.parry.org> Date: Sat Apr 30 16:40:55 2011 -0600 Change the signature of system::tempnam to something more appropriate for Gallery. commit5c9a3b3f39Author: Chad Parry <github@chad.parry.org> Date: Sat Apr 23 21:19:47 2011 -0600 Create a tempnam substitute that safely creates files with a given extension. commit2375a02e2cAuthor: Chad Parry <github@chad.parry.org> Date: Sat Apr 30 16:40:55 2011 -0600 Change the signature of system::tempnam to something more appropriate for Gallery. commita8ca9dcf9eAuthor: Chad Parry <github@chad.parry.org> Date: Sat Apr 30 16:10:06 2011 -0600 Change the name of the extensions helper to legal_file. commit7e61a01a96Author: Chad Parry <github@chad.parry.org> Date: Sat Apr 30 16:08:49 2011 -0600 Change the name of the extensions helper to legal_file. commit4c2b2ebd3fAuthor: Chad Parry <github@chad.parry.org> Date: Wed Apr 27 20:52:35 2011 -0600 Remove a newline at the end of the file that I accidentally introduced. commit6d564f185eMerge:7ff485f4060640Author: Chad Parry <github@chad.parry.org> Date: Wed Apr 27 20:35:58 2011 -0600 Merge branch 'master' of https://github.com/gallery/gallery3 into rawphoto commit7ff485fa48Author: Chad Parry <github@chad.parry.org> Date: Wed Apr 27 20:29:06 2011 -0600 Move the extensions helpers out of the Kohana system directory and into their own Gallery Extensions class. commit26585fed03Merge:809567fc8f90e8Author: Chad Parry <github@chad.parry.org> Date: Sun Apr 24 08:28:39 2011 -0600 Merge branch 'master' of https://github.com/gallery/gallery3 into rawphoto commit809567f128Author: Chad Parry <github@chad.parry.org> Date: Sun Apr 24 08:10:04 2011 -0600 Expose the data file field. commitfcb06bf175Author: Chad Parry <github@chad.parry.org> Date: Sun Apr 24 00:45:12 2011 -0600 Don't assign to the item->name field if the name is unchanged, because the save method will crash. commitc6ef706d70Author: Chad Parry <github@chad.parry.org> Date: Sat Apr 23 22:55:59 2011 -0600 Preserve old data files long enough for them to be available to event handlers. commit0d6a3a3cfcAuthor: Chad Parry <github@chad.parry.org> Date: Sat Apr 23 21:19:47 2011 -0600 Create a tempnam substitute that safely creates files with a given extension. commite149cf7238Author: Chad Parry <github@chad.parry.org> Date: Sat Apr 23 16:39:25 2011 -0600 Support data files that change their extension and MIME type. commit6702104f57Author: Chad Parry <github@chad.parry.org> Date: Sat Apr 23 16:35:00 2011 -0600 Resolve an infinite recursion that happens when the path caches are updated during saving. commit944cb72eeaMerge:567522b5af74d4Author: Chad Parry <github@chad.parry.org> Date: Fri Apr 22 14:10:42 2011 -0600 Merge remote branch 'origin/master' into rawphoto commit567522bfa0Author: Chad Parry <github@chad.parry.org> Date: Thu Apr 21 20:12:32 2011 -0600 Add an event for when a new graphics toolkit is chosen. commit31ba081b79Author: Chad Parry <github@chad.parry.org> Date: Thu Apr 21 02:06:53 2011 -0600 Add an event that will collect all valid filename extensions.
269 lines
9.0 KiB
PHP
269 lines
9.0 KiB
PHP
<?php defined("SYSPATH") or die("No direct script access.");
|
|
/**
|
|
* Gallery - a web based photo album viewer and editor
|
|
* Copyright (C) 2000-2011 Bharat Mediratta
|
|
*
|
|
* This program is free software; you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License as published by
|
|
* the Free Software Foundation; either version 2 of the License, or (at
|
|
* your option) any later version.
|
|
*
|
|
* This program is distributed in the hope that it will be useful, but
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
* General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License
|
|
* along with this program; if not, write to the Free Software
|
|
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
|
|
*/
|
|
|
|
class installer {
|
|
static $mysqli;
|
|
|
|
static function already_installed() {
|
|
return file_exists(VARPATH . "database.php");
|
|
}
|
|
|
|
static function var_writable() {
|
|
if (is_writable(VARPATH)) {
|
|
return true;
|
|
}
|
|
|
|
if (@mkdir(VARPATH)) {
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
static function create_database_config($config) {
|
|
$db_config_file = VARPATH . "database.php";
|
|
ob_start();
|
|
extract($config);
|
|
include(DOCROOT . "installer/database_config.php");
|
|
$output = ob_get_clean();
|
|
return file_put_contents($db_config_file, $output) !== false;
|
|
}
|
|
|
|
static function unpack_var() {
|
|
if (!file_exists(VARPATH)) {
|
|
mkdir(VARPATH);
|
|
chmod(VARPATH, 0777);
|
|
}
|
|
|
|
include(DOCROOT . "installer/init_var.php");
|
|
return true;
|
|
}
|
|
|
|
static function unpack_sql($config) {
|
|
$prefix = $config["prefix"];
|
|
$buf = null;
|
|
foreach (file(DOCROOT . "installer/install.sql") as $line) {
|
|
$buf .= trim($line);
|
|
if (preg_match("/;$/", $buf)) {
|
|
if (!mysql_query(self::prepend_prefix($prefix, $buf))) {
|
|
return false;
|
|
}
|
|
$buf = "";
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
|
|
static function connect($config) {
|
|
// We know that we have either mysql or mysqli. By default we use mysql functions, so if
|
|
// they're not defined then do the simplest thing which will work: remap them to their mysqli
|
|
// counterparts.
|
|
if (!function_exists("mysql_query")) {
|
|
function mysql_connect($host, $user, $pass) {
|
|
list ($host, $port) = explode(":", $host . ":");
|
|
installer::$mysqli = new mysqli($host, $user, $pass, $port);
|
|
// http://php.net/manual/en/mysqli.connect.php says to use mysqli_connect_error() instead of
|
|
// $mysqli->connect_error because of bugs before PHP 5.2.9
|
|
$error = mysqli_connect_error();
|
|
return empty($error);
|
|
}
|
|
function mysql_query($query) {
|
|
return installer::$mysqli->query($query);
|
|
}
|
|
function mysql_num_rows($result) {
|
|
return $result->num_rows;
|
|
}
|
|
function mysql_error() {
|
|
return installer::$mysqli->error;
|
|
}
|
|
function mysql_select_db($db) {
|
|
return installer::$mysqli->select_db($db);
|
|
}
|
|
}
|
|
|
|
$host = empty($config["port"]) ? $config['host'] : "{$config['host']}:{$config['port']}";
|
|
return @mysql_connect($host, $config["user"], $config["password"]);
|
|
}
|
|
|
|
static function select_db($config) {
|
|
if (mysql_select_db($config["dbname"])) {
|
|
return true;
|
|
}
|
|
|
|
return mysql_query("CREATE DATABASE `{$config['dbname']}`") &&
|
|
mysql_select_db($config["dbname"]);
|
|
}
|
|
|
|
static function verify_mysql_version($config) {
|
|
return version_compare(installer::mysql_version($config), "5.0.0", ">=");
|
|
}
|
|
|
|
static function mysql_version($config) {
|
|
$result = mysql_query("SHOW VARIABLES WHERE variable_name = \"version\"");
|
|
$row = mysql_fetch_object($result);
|
|
return $row->Value;
|
|
}
|
|
|
|
static function db_empty($config) {
|
|
$query = "SHOW TABLES LIKE '{$config['prefix']}items'";
|
|
$results = mysql_query($query);
|
|
if ($results === false) {
|
|
$msg = mysql_error();
|
|
return $msg;
|
|
}
|
|
return mysql_num_rows($results) === 0;
|
|
}
|
|
|
|
static function create_admin($config) {
|
|
$salt = "";
|
|
for ($i = 0; $i < 4; $i++) {
|
|
$char = mt_rand(48, 109);
|
|
$char += ($char > 90) ? 13 : ($char > 57) ? 7 : 0;
|
|
$salt .= chr($char);
|
|
}
|
|
$password = substr(md5(time() . mt_rand()), 0, 6);
|
|
// Escape backslash in preparation for our UPDATE statement.
|
|
$hashed_password = str_replace("\\", "\\\\", $salt . md5($salt . $password));
|
|
$sql = self::prepend_prefix($config["prefix"],
|
|
"UPDATE {users} SET `password` = '$hashed_password' WHERE `id` = 2");
|
|
if (mysql_query($sql)) {
|
|
} else {
|
|
throw new Exception(mysql_error());
|
|
}
|
|
|
|
return array("admin", $password);
|
|
}
|
|
|
|
static function create_admin_session($config) {
|
|
$session_id = md5(time() . mt_rand());
|
|
$user_agent = $_SERVER["HTTP_USER_AGENT"];
|
|
$user_agent_len = strlen($user_agent);
|
|
$now = time();
|
|
$data = "session_id|s:32:\"$session_id\"";
|
|
$data .= ";user_agent|s:{$user_agent_len}:\"$user_agent\"";
|
|
$data .= ";user|i:2";
|
|
$data .= ";after_install|i:1";
|
|
$data .= ";last_activity|i:$now";
|
|
$data = base64_encode($data);
|
|
$sql = "INSERT INTO {sessions}(`session_id`, `last_activity`, `data`) " .
|
|
"VALUES('$session_id', $now, '$data')";
|
|
$sql = self::prepend_prefix($config["prefix"], $sql);
|
|
if (mysql_query($sql)) {
|
|
setcookie("g3sid", $session_id, 0, "/", "", false, false);
|
|
} else {
|
|
throw new Exception(mysql_error());
|
|
}
|
|
}
|
|
|
|
static function create_private_key($config) {
|
|
$key = md5(uniqid(mt_rand(), true)) . md5(uniqid(mt_rand(), true));
|
|
$sql = self::prepend_prefix($config["prefix"],
|
|
"INSERT INTO {vars} VALUES(NULL, 'gallery', 'private_key', '$key')");
|
|
if (mysql_query($sql)) {
|
|
} else {
|
|
throw new Exception(mysql_error());
|
|
}
|
|
}
|
|
|
|
static function prepend_prefix($prefix, $sql) {
|
|
return preg_replace("#{([a-zA-Z0-9_]+)}#", "{$prefix}$1", $sql);
|
|
}
|
|
|
|
static function check_environment() {
|
|
if (!function_exists("mysql_query") && !function_exists("mysqli_set_charset")) {
|
|
$errors[] = "Gallery 3 requires a MySQL database, but PHP doesn't have either the <a href=\"http://php.net/mysql\">MySQL</a> or the <a href=\"http://php.net/mysqli\">MySQLi</a> extension.";
|
|
}
|
|
|
|
if (!preg_match("/^.$/u", "ñ")) {
|
|
$errors[] = "PHP is missing <a href=\"http://php.net/pcre\">Perl-Compatible Regular Expression</a> with UTF-8 support.";
|
|
} else if (!preg_match("/^\pL$/u", "ñ")) {
|
|
$errors[] = "PHP is missing <a href=\"http://php.net/pcre\">Perl-Compatible Regular Expression</a> with Unicode support.";
|
|
}
|
|
|
|
if (!(function_exists("spl_autoload_register"))) {
|
|
$errors[] = "PHP is missing <a href=\"http://php.net/spl\">Standard PHP Library (SPL)</a> support";
|
|
}
|
|
|
|
if (!(class_exists("ReflectionClass"))) {
|
|
$errors[] = "PHP is missing <a href=\"http://php.net/reflection\">reflection</a> support";
|
|
}
|
|
|
|
if (!(function_exists("filter_list"))) {
|
|
$errors[] = "PHP is missing the <a href=\"http://php.net/filter\">filter extension</a>";
|
|
}
|
|
|
|
if (!(extension_loaded("iconv"))) {
|
|
$errors[] = "PHP is missing the <a href=\"http://php.net/iconv\">iconv extension</a>";
|
|
}
|
|
|
|
if (!(extension_loaded("xml"))) {
|
|
$errors[] = "PHP is missing the <a href=\"http://php.net/xml\">XML Parser extension</a>";
|
|
}
|
|
|
|
if (!(extension_loaded("simplexml"))) {
|
|
$errors[] = "PHP is missing the <a href=\"http://php.net/simplexml\">SimpleXML extension</a>";
|
|
}
|
|
|
|
if (!extension_loaded("mbstring")) {
|
|
$errors[] = "PHP is missing the <a href=\"http://php.net/mbstring\">mbstring extension</a>";
|
|
} else if (ini_get("mbstring.func_overload") & MB_OVERLOAD_STRING) {
|
|
$errors[] = "The <a href=\"http://php.net/mbstring\">mbstring extension</a> is overloading PHP's native string functions. Please disable it.";
|
|
}
|
|
|
|
if (!function_exists("json_encode")) {
|
|
$errors[] = "PHP is missing the <a href=\"http://php.net/manual/en/book.json.php\">JavaScript Object Notation (JSON) extension</a>. Please install it.";
|
|
}
|
|
|
|
if (!ini_get("short_open_tag")) {
|
|
$errors[] = "Gallery requires <a href=\"http://php.net/manual/en/ini.core.php\">short_open_tag</a> to be on. Please enable it in your php.ini.";
|
|
}
|
|
|
|
if (!function_exists("ctype_alpha")) {
|
|
$errors[] = "Gallery requires the <a href=\"http://php.net/manual/en/book.ctype.php\">PHP Ctype</a> extension. Please install it.";
|
|
}
|
|
|
|
if (self::ini_get_bool("safe_mode")) {
|
|
$errors[] = "Gallery cannot function when PHP is in <a href=\"http://php.net/manual/en/features.safe-mode.php\">Safe Mode</a>. Please disable safe mode.";
|
|
}
|
|
|
|
return @$errors;
|
|
}
|
|
|
|
/**
|
|
* Convert any possible boolean ini value to true/false.
|
|
* On = on = 1 = true
|
|
* Off = off = 0 = false
|
|
*/
|
|
static function ini_get_bool($varname) {
|
|
$value = ini_get($varname);
|
|
|
|
if (!strcasecmp("on", $value) || $value == 1 || $value === true) {
|
|
return true;
|
|
}
|
|
|
|
if (!strcasecmp("off", $value) || $value == 0 || $value === false) {
|
|
return false;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
}
|