Example #1
0
 public static function text($database, $type, $function, $line, $text = '')
 {
     # Check dependencies
     Module::dependencies(isset($database, $type, $function, $line, $text));
     # Get time
     $sysstamp = time();
     # Save in database
     $query = Database::prepare($database, "INSERT INTO ? (time, type, function, line, text) VALUES ('?', '?', '?', '?', '?')", array(LYCHEE_TABLE_LOG, $sysstamp, $type, $function, $line, $text));
     $result = $database->query($query);
     if (!$result) {
         return false;
     }
     return true;
 }
Example #2
0
File: Log.php Project: rssc/Lychee
 public static function text($database, $type, $function, $line, $text = '')
 {
     # Check dependencies
     Module::dependencies(isset($database, $type, $function, $line, $text));
     # Get time
     $sysstamp = time();
     # Save in database
     $stmt = $database->prepare("INSERT INTO " . LYCHEE_TABLE_LOG . " (time, type, function, line, text) VALUES (?, ?, ?, ?, ?)");
     $result = $stmt->execute(array($sysstamp, $type, $function, $line, $text));
     if (!$result) {
         return false;
     }
     return true;
 }
Example #3
0
 private function getPhotoArchive()
 {
     Module::dependencies(isset($_GET['photoID']));
     $photo = new Photo($this->database, $this->plugins, null, $_GET['photoID']);
     $photo->getArchive();
 }
Example #4
0
 static function prepare($database, $query, $data)
 {
     # Check dependencies
     Module::dependencies(isset($database, $query, $data));
     # Count the number of placeholders and compare it with the number of arguments
     # If it doesn't match, calculate the difference and skip this number of placeholders before starting the replacement
     # This avoids problems with placeholders in user-input
     # $skip = Number of placeholders which need to be skipped
     $skip = 0;
     $num = array('placeholder' => substr_count($query, '?'), 'data' => count($data));
     if ($num['data'] - $num['placeholder'] < 0) {
         Log::notice($database, __METHOD__, __LINE__, 'Could not completely prepare query. Query has more placeholders than values.');
     }
     foreach ($data as $value) {
         # Escape
         $value = mysqli_real_escape_string($database, $value);
         # Recalculate number of placeholders
         $num['placeholder'] = substr_count($query, '?');
         # Calculate number of skips
         if ($num['placeholder'] > $num['data']) {
             $skip = $num['placeholder'] - $num['data'];
         }
         if ($skip > 0) {
             # Need to skip $skip placeholders, because the user input contained placeholders
             # Calculate a substring which does not contain the user placeholders
             # 1 or -1 is the length of the placeholder (placeholder = ?)
             $pos = -1;
             for ($i = $skip; $i > 0; $i--) {
                 $pos = strpos($query, '?', $pos + 1);
             }
             $pos++;
             $temp = substr($query, 0, $pos);
             # First part of $query
             $query = substr($query, $pos);
             # Last part of $query
         }
         # Replace
         $query = preg_replace('/\\?/', $value, $query, 1);
         if ($skip > 0) {
             # Reassemble the parts of $query
             $query = $temp . $query;
         }
         # Reset skip
         $skip = 0;
         # Decrease number of data elements
         $num['data']--;
     }
     return $query;
 }
Example #5
0
 private function getPhotoArchive()
 {
     Module::dependencies(isset($_GET['photoID'], $_GET['password']));
     $photo = new Photo($this->database, $this->plugins, null, $_GET['photoID']);
     $pgP = $photo->getPublic($_GET['password']);
     # Photo Download
     if ($pgP === 2) {
         # Photo Public
         $photo->getArchive();
     } else {
         # Photo Private
         exit('Warning: Photo private or password incorrect!');
     }
 }
Example #6
0
 private function dbCreateConfig()
 {
     Module::dependencies(isset($_POST['dbHost'], $_POST['dbUser'], $_POST['dbPassword'], $_POST['dbName'], $_POST['dbTablePrefix']));
     echo Database::createConfig($_POST['dbHost'], $_POST['dbUser'], $_POST['dbPassword'], $_POST['dbName'], $_POST['dbTablePrefix']);
 }
Example #7
0
 static function createTables($database, $type = 'mysql')
 {
     # Check dependencies
     Module::dependencies(isset($database));
     # Create log
     $result = $database->query('SELECT * FROM ' . LYCHEE_TABLE_LOG . ' LIMIT 0');
     if ($result === FALSE) {
         # Read file
         $file = __DIR__ . '/../database/log_table_' . $type . '.sql';
         $query = @file_get_contents($file);
         if (!isset($query) || $query === false) {
             return false;
         }
         # Create table
         # Replace table prefix in query loaded from file (native parametrization of identifiers not supported in PDO)
         $query = str_replace("_PREFIX_", LYCHEE_TABLE_PREFIX, $query);
         $result = $database->exec($query);
         if ($result === FALSE) {
             error_log(print_r($database->errorInfo(), TRUE));
             return false;
         }
     }
     # Create settings
     $result = $database->query('SELECT * FROM ' . LYCHEE_TABLE_SETTINGS . ' LIMIT 0');
     if ($result === FALSE) {
         # Read file
         $file = __DIR__ . '/../database/settings_table_' . $type . '.sql';
         $query = @file_get_contents($file);
         if (!isset($query) || $query === false) {
             Log::error($database, __METHOD__, __LINE__, 'Could not load query for lychee_settings');
             return false;
         }
         # Create table
         # Replace table prefix in query loaded from file (native parametrization of identifiers not supported in PDO)
         $query = str_replace("_PREFIX_", LYCHEE_TABLE_PREFIX, $query);
         $result = $database->exec($query);
         if ($result === FALSE) {
             Log::error($database, __METHOD__, __LINE__, print_r($database->errorInfo(), TRUE));
             return false;
         }
         Log::notice($database, __METHOD__, __LINE__, "Created settings table.");
         # Read file
         $file = __DIR__ . '/../database/settings_content_' . $type . '.sql';
         $query = @file_get_contents($file);
         if (!isset($query) || $query === false) {
             Log::error($database, __METHOD__, __LINE__, 'Could not load content-query for lychee_settings');
             return false;
         }
         # Add content
         $query = str_replace("_PREFIX_", LYCHEE_TABLE_PREFIX, $query);
         $result = $database->exec($query);
         if ($result === FALSE) {
             Log::error($database, __METHOD__, __LINE__, "Could not create settings table: " . print_r($database->errorInfo(), TRUE));
             return false;
         }
         Log::notice($database, __METHOD__, __LINE__, "Added content to settings table.");
         # Generate identifier
         $identifier = md5(microtime(true));
         $stmt = $database->prepare("UPDATE " . LYCHEE_TABLE_SETTINGS . " SET value = ? WHERE key = 'identifier'");
         if (!$stmt) {
             Log::error($database, __METHOD__, __LINE__, "Could not prepare statement: " . print_r($database->errorInfo(), TRUE));
             return false;
         }
         $result = $stmt->execute(array($identifier));
         if ($result === FALSE) {
             Log::error($database, __METHOD__, __LINE__, print_r($stmt->errorInfo(), TRUE));
             return false;
         }
     }
     # Create albums
     $result = $database->query('SELECT * FROM ' . LYCHEE_TABLE_ALBUMS . ' LIMIT 0');
     if ($result === FALSE) {
         # Read file
         $file = __DIR__ . '/../database/albums_table_' . $type . '.sql';
         $query = @file_get_contents($file);
         if (!isset($query) || $query === false) {
             Log::error($database, __METHOD__, __LINE__, 'Could not load query for lychee_albums');
             return false;
         }
         # Create table
         # Replace table prefix in query loaded from file (native parametrization of identifiers not supported in PDO)
         $query = str_replace("_PREFIX_", LYCHEE_TABLE_PREFIX, $query);
         $result = $database->exec($query);
         if ($result === FALSE) {
             Log::error($database, __METHOD__, __LINE__, print_r($database->errorInfo(), TRUE));
             return false;
         }
     }
     # Create photos
     $result = $database->query('SELECT * FROM ' . LYCHEE_TABLE_PHOTOS . ' LIMIT 0');
     if ($result === FALSE) {
         # Read file
         $file = __DIR__ . '/../database/photos_table_' . $type . '.sql';
         $query = @file_get_contents($file);
         if (!isset($query) || $query === false) {
             Log::error($database, __METHOD__, __LINE__, 'Could not load query for lychee_photos');
             return false;
         }
         # Create table
         # Replace table prefix in query loaded from file (native parametrization of identifiers not supported in PDO)
         $query = str_replace("_PREFIX_", LYCHEE_TABLE_PREFIX, $query);
         $result = $database->exec($query);
         if ($result === FALSE) {
             Log::error($database, __METHOD__, __LINE__, print_r($database->errorInfo(), TRUE));
             return false;
         }
     }
     return true;
 }
Example #8
0
 private function getPhotoArchive()
 {
     Module::dependencies(isset($_GET['photoID']));
     $photo = new Photo(null, $_GET['photoID']);
     $photo->getArchive();
 }