<commit_before><?php

const FEATURED_FOLDER_ID = 1;
const LATEST_ALBUM_ID = 0;
const LATEST_ALBUM_NAME = "latest";
const IMAGES_PER_PAGE = 12;
const GALLERY_ROOT = "http://jbrowne.me.uk/art/";
const THUMBNAIL_URL = GALLERY_ROOT . "thumbs/";
const IMAGE_URL = GALLERY_ROOT . "images/";
const ICON_URL = GALLERY_ROOT . "icons/";

const DEFAULT_ALBUM_NAME_QUERY = "_default";
const DEFAULT_ALBUM_NAME = "featured";

// Relative to the file that includes this one
require "lib/framework.gallery.php";

class ApiModule {

  private $db = NULL;
  private $galleryAlbumCache = null;

  //============================================================================
  // Constructor.
  //============================================================================
  public function __construct($db) {
    $this->db = $db;

    $this->galleryAlbumCache = new GalleryAlbumList($this->db);
  }

  //============================================================================
  // Main entry point.
  //============================================================================
  public function handleResponse() {
    if (isset($_GET["images"])) {
      $this->generateAlbumComponentImageData();
      return;
    }

    if (isset($_GET["albumData"])) {
      if (isset($_GET["all"])) {
        $this->generateAlbumListAlbumData();
        return;
      }

      $this->generateAlbumComponentAlbumData();
      return;
    }

    if (isset($_GET["imageData"])) {
      $this->generateImageComponentData();
      return;
    }

    ResponseHelpers::respondNotFound();
  }

  //============================================================================
  // Generates the data containing information about a specified image.
  //============================================================================
  private function generateImageComponentData() {
    $requestedImage = RequestHelpers::getNumericValue("imageId", -1);
    if ($requestedImage < 1) {
      ResponseHelpers::respondNotFound();
      return;
    }

    $image = GalleryImageList::getImageById($this->db, $requestedImage);
    if ($image === NULL) {
      ResponseHelpers::respondNotFound();
      return;
    }

    $imageData = $this->generateImageInfo($image);
    ResponseHelpers::outputWithJsonHeader($imageData);
  }

  //============================================================================
  // Generates the data containing all the images in a specified album.
  //============================================================================
  private function generateAlbumComponentImageData() {
    $page = RequestHelpers::getNumericValue("page", 1);
    $requestedPage = $page - 1;
    if ($requestedPage < 0) {
      $requestedPage = 0;
    }

    $requestedName = RequestHelpers::getRawValue("albumName");
    if (is_null($requestedName)) {
      ResponseHelpers::respondNotFound();
      return;
    }

    $numberImagesToLoad = RequestHelpers::getNumericValue("count", IMAGES_PER_PAGE);
    if ($numberImagesToLoad <= 0) {
      $numberImagesToLoad = IMAGES_PER_PAGE;
    }

    $requestedAlbumId = LATEST_ALBUM_ID;
    if ($requestedName !== LATEST_ALBUM_NAME) {
      if ($requestedName === DEFAULT_ALBUM_NAME_QUERY) {
        $requestedName = DEFAULT_ALBUM_NAME;
      }

      // Look up album - returns null if it doesn't exist.
      $currentAlbum = GalleryAlbumList::getAlbumByName($this->db, $requestedName);
      if ($currentAlbum === NULL) {
        respondNotFound();
        return;
      }

      $requestedAlbumId = $currentAlbum->getId();
    }

    $galleryImages = new GalleryImageList($this->db, $numberImagesToLoad, $requestedPage, $requestedAlbumId);
    $output = array();

    foreach ($galleryImages as $image) {
      $output[] = $this->generateImageInfo($image);
    }

    ResponseHelpers::outputWithJsonHeader($output);
  }

  //
  // Creates a JSON-serializable key-value pair encompassing the album name & title.
  //
  private function generateAlbumNameTitlePair($album) {
    return array(
      "name"  => $album->getName(),
      "title" =>$album->getTitle()
    );
  }<commit_msg>Fix call to missing method in backend<commit_after><?php

const FEATURED_FOLDER_ID = 1;
const LATEST_ALBUM_ID = 0;
const LATEST_ALBUM_NAME = "latest";
const IMAGES_PER_PAGE = 12;
const GALLERY_ROOT = "http://jbrowne.me.uk/art/";
const THUMBNAIL_URL = GALLERY_ROOT . "thumbs/";
const IMAGE_URL = GALLERY_ROOT . "images/";
const ICON_URL = GALLERY_ROOT . "icons/";

const DEFAULT_ALBUM_NAME_QUERY = "_default";
const DEFAULT_ALBUM_NAME = "featured";

// Relative to the file that includes this one
require "lib/framework.gallery.php";

class ApiModule {

  private $db = NULL;
  private $galleryAlbumCache = null;

  //============================================================================
  // Constructor.
  //============================================================================
  public function __construct($db) {
    $this->db = $db;

    $this->galleryAlbumCache = new GalleryAlbumList($this->db);
  }

  //============================================================================
  // Main entry point.
  //============================================================================
  public function handleResponse() {
    if (isset($_GET["images"])) {
      $this->generateAlbumComponentImageData();
      return;
    }

    if (isset($_GET["albumData"])) {
      if (isset($_GET["all"])) {
        $this->generateAlbumListAlbumData();
        return;
      }

      $this->generateAlbumComponentAlbumData();
      return;
    }

    if (isset($_GET["imageData"])) {
      $this->generateImageComponentData();
      return;
    }

    ResponseHelpers::respondNotFound();
  }

  //============================================================================
  // Generates the data containing information about a specified image.
  //============================================================================
  private function generateImageComponentData() {
    $requestedImage = RequestHelpers::getNumericValue("imageId", -1);
    if ($requestedImage < 1) {
      ResponseHelpers::respondNotFound();
      return;
    }

    $image = GalleryImageList::getImageById($this->db, $requestedImage);
    if ($image === NULL) {
      ResponseHelpers::respondNotFound();
      return;
    }

    $imageData = $this->generateImageInfo($image);
    ResponseHelpers::outputWithJsonHeader($imageData);
  }

  //============================================================================
  // Generates the data containing all the images in a specified album.
  //============================================================================
  private function generateAlbumComponentImageData() {
    $page = RequestHelpers::getNumericValue("page", 1);
    $requestedPage = $page - 1;
    if ($requestedPage < 0) {
      $requestedPage = 0;
    }

    $requestedName = RequestHelpers::getRawValue("albumName");
    if (is_null($requestedName)) {
      ResponseHelpers::respondNotFound();
      return;
    }

    $numberImagesToLoad = RequestHelpers::getNumericValue("count", IMAGES_PER_PAGE);
    if ($numberImagesToLoad <= 0) {
      $numberImagesToLoad = IMAGES_PER_PAGE;
    }

    $requestedAlbumId = LATEST_ALBUM_ID;
    if ($requestedName !== LATEST_ALBUM_NAME) {
      if ($requestedName === DEFAULT_ALBUM_NAME_QUERY) {
        $requestedName = DEFAULT_ALBUM_NAME;
      }

      // Look up album - returns null if it doesn't exist.
      $currentAlbum = GalleryAlbumList::getAlbumByName($this->db, $requestedName);
      if ($currentAlbum === NULL) {
        ResponseHelpers::respondNotFound();
        return;
      }

      $requestedAlbumId = $currentAlbum->getId();
    }

    $galleryImages = new GalleryImageList($this->db, $numberImagesToLoad, $requestedPage, $requestedAlbumId);
    $output = array();

    foreach ($galleryImages as $image) {
      $output[] = $this->generateImageInfo($image);
    }

    ResponseHelpers::outputWithJsonHeader($output);
  }

  //
  // Creates a JSON-serializable key-value pair encompassing the album name & title.
  //
  private function generateAlbumNameTitlePair($album) {
    return array(
      "name"  => $album->getName(),
      "title" =>$album->getTitle()
    );
  }
{'fraction_non_alphanumeric': 0.26252577944922967, 'fraction_numerical': 0.0026689312143637024, 'mean_word_length': 4.042201834862385, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 37, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2996066', 'n_tokens_mistral': 2352, 'n_tokens_neox': 2215, 'n_words': 440}