setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); } catch (PDOException $e) { /* If there is an error an exception is thrown */ echo 'Connection failed
'; echo 'Error number: ' . $e->getCode() . '
'; echo 'Error message: ' . $e->getMessage() . '
'; die(); } function get_dir_info($dir) { global $pdo; $sql = 'SELECT * FROM dirs WHERE path = :dir'; $values = array( ':dir' => $dir ); try { $res = $pdo->prepare($sql); $res->execute($values); } catch (PDOException $e) { echo 'Query error: ' . $e->getMessage(); die(); } if(!($row = $res->fetch(PDO::FETCH_ASSOC))) { return null; } return $row; } function get_dir_list() { global $pdo; $dir = []; $query = 'SELECT * FROM dirs ORDER BY date DESC'; try { $res = $pdo->query($query); } catch (PDOException $e) { echo 'Query error: ' . $e->getMessage(); die(); } while ($row = $res->fetch(PDO::FETCH_ASSOC)) { if ($row['hidden']) continue; $dir[] = $row; } return $dir; } function get_dir_count($dir) { global $pdo; $sql = 'SELECT id FROM dirs WHERE path = :dir'; $values = array( ':dir' => $dir ); try { $res = $pdo->prepare($sql); $res->execute($values); } catch (PDOException $e) { echo 'Query error: ' . $e->getMessage(); die(); } if(!($row = $res->fetch(PDO::FETCH_ASSOC))) { return 0; } $dirid = $row['id']; $sql = 'SELECT count(*) AS count FROM images WHERE dir = :dirid'; $values = array( ':dirid' => $dirid ); try { $res = $pdo->prepare($sql); $res->execute($values); } catch (PDOException $e) { echo 'Query error: ' . $e->getMessage(); die(); } if(!($row = $res->fetch(PDO::FETCH_ASSOC))) { return 0; } return $row['count']; } function update_dir_count($dirpath, $count) { global $pdo; $sql = 'UPDATE dirs SET count = :count WHERE path = :path'; $values = array( ':path' => $dirpath, ':count' => $count, ); try { $res = $pdo->prepare($sql); return $res->execute($values); } catch (PDOException $e) { echo 'Query error: ' . $e->getMessage(); die(); } } function get_dir_images($dir, $mode = '') { global $pdo; $images = []; $sql = 'SELECT images.id, images.name, images.comment, images.views, images.likes, images.tags, images.path, dirs.name AS dir_name, dirs.comment AS dir_comment, dirs.views AS dir_views, dirs.likes AS dir_likes, dirs.tags AS dir_tags, dirs.path AS dir_path FROM images INNER JOIN dirs ON dirs.id=images.dir WHERE dirs.path = :path ORDER BY images.date ASC, images.path ASC'; $values = array( ':path' => $dir ); try { $res = $pdo->prepare($sql); $res->execute($values); } catch (PDOException $e) { echo 'Query error: ' . $e->getMessage(); die(); } while ($row = $res->fetch(PDO::FETCH_ASSOC)) { if ($mode == 'viewcomments') { if (count_comments($row['id'], 'image') == 0) continue; } $images[] = $row; $dirname = $row['dir_name']; // probably should do this only once } return $images; } function make_dir_path($dir) { global $config; return $config['basepath'] . '/' . $dir['path'] . '/'; } function create_db_dir($path, $name, $comment, $tags, $date) { global $pdo; $sql = 'INSERT INTO dirs (name, comment, tags, path, date, lastmodified) VALUES (:name, :comment, :tags, :path, :date, :currentdate)'; $values = array( ':name' => $name, ':comment' => $comment, ':tags' => $tags, ':path' => $path, ':date' => $date, ':currentdate' => time() ); try { $res = $pdo->prepare($sql); return $res->execute($values); } catch (PDOException $e) { echo 'Query error: ' . $e->getMessage(); die(); } } function update_db_dir($path, $name, $comment, $tags, $date) { global $pdo; $sql = 'UPDATE dirs SET name = :name, comment = :comment, tags = :tags, date = :date, lastmodified = :currentdate WHERE path = :path'; $values = array( ':name' => $name, ':comment' => $comment, ':tags' => $tags, ':path' => $path, ':date' => $date, ':currentdate' => time() ); try { $res = $pdo->prepare($sql); return $res->execute($values); } catch (PDOException $e) { echo 'Query error: ' . $e->getMessage(); die(); } } function add_db_image($dirid, $name, $comment, $tags, $path, $date) { global $pdo; $sql = 'INSERT INTO images (dir, name, comment, tags, path, date, lastmodified) VALUES (:dirid, :name, :comment, :tags, :path, :date, :currentdate)'; $values = array( ':dirid' => $dirid, ':name' => $name, ':comment' => $comment, ':tags' => $tags, ':path' => $path, ':date' => $date, ':currentdate' => time() ); try { $res = $pdo->prepare($sql); return $res->execute($values); } catch (PDOException $e) { echo 'Query error: ' . $e->getMessage(); die(); } } ?>