Example #1
0
function init($args)
{
    $name = $args['name'];
    $location = $args['location'];
    //check if album already exists
    $cp = new ConfigReader(PF_CONFIG_FILE);
    $albums = $cp->getChildren("settings/albums");
    if ($albums) {
        foreach ($albums as $album) {
            if ($album['attributes']['name'] == $name) {
                error("Album {$name} already exists!");
                return;
            }
        }
    }
    define("ALBUM_DIR", realpath($_SERVER['DOCUMENT_ROOT'] . '/' . $location));
    //check if it exists
    if (!is_dir(ALBUM_DIR)) {
        error("It seems like the directory {$location} does not exist.");
        return;
    }
    //check if directory writeable
    if (!is_writeable(ALBUM_DIR)) {
        error("Could not create album. Could not write to {$location}." . ALBUM_DIR);
        return;
    }
    //get a list of photos (jpg/png)
    //generate thumbnails
    chdir(ALBUM_DIR);
    //try to make thumbnail directory
    if (!is_dir(PF_THUMBNAIL_DIR)) {
        if (!mkdir(PF_THUMBNAIL_DIR)) {
            error("Could not create thumbnails directory in {$location}");
            return;
        }
    }
    //generate thumbnails
    //it seems glob cannot take multiple patterns
    $pattern = array("*.jpg", "*.jpeg", "*.png");
    foreach ($pattern as $pat) {
        foreach (glob($pat) as $file) {
            if (!makeThumbnail($file, PF_THUMBNAIL_DIR . $file)) {
                error("Could not create thumbnail for image {$file}");
                return;
            }
        }
    }
    //add album to config file
    $cp = new ConfigWriter(PF_CONFIG_FILE);
    $attributes = array("name" => $name, "location" => str_replace($_SERVER['DOCUMENT_ROOT'], "", ALBUM_DIR), "theme" => PF_DEFAULT_THEME);
    $cp->addWithAttributes('settings/albums/album', $attributes, "");
    if (!$cp->close()) {
        error("Could not write to configuration file");
    }
    success("Successfully created album {$name} in {$location}.");
}
Example #2
0
function init($args)
{
    $albumName = $args['albumName'];
    $theme = $args['theme'];
    $location = "";
    //read, delete, write
    $cpr = new ConfigReader(PF_CONFIG_FILE);
    $albums = $cpr->getChildren('settings/albums');
    if (!$albums) {
        error("It seems you don't have any albums");
        return;
    }
    $found = FALSE;
    foreach ($albums as $album) {
        if ($album['attributes']['name'] == $albumName) {
            $found = TRUE;
            $location = $album['attributes']['location'];
            break;
        }
    }
    if (!$found) {
        error("The album {$albumName} was not found");
        return;
    }
    $cpr = new ConfigWriter(PF_CONFIG_FILE);
    if (!$cpr->removeWithAttributes('settings/albums/album', 'name', $albumName)) {
        error("Could not change theme for {$albumName}");
        return;
    }
    $attrs = array("name" => $albumName, "location" => $location, "theme" => $theme);
    $cpr->addWithAttributes('settings/albums/album', $attrs, "");
    if (!$cpr->close()) {
        error("Could not write to configuration file");
        return;
    }
    success("Successfully changed theme for {$albumName} to {$theme}");
}