Ejemplo n.º 1
0
function init($args)
{
    $name = $args['name'];
    $cp = new ConfigReader(PF_CONFIG_FILE);
    $albums = $cp->getChildren("settings/albums");
    if (!$albums) {
        error("It seems you don't have any albums. Why don't you create one.");
        return;
    }
    $location = "";
    //find our album location
    foreach ($albums as $album) {
        if ($album['attributes']['name'] == $name) {
            $location = $album['attributes']['location'];
        }
    }
    if ($location == "") {
        error("Could not find album {$name}");
        return;
    }
    //see if it exists
    if (!is_dir($_SERVER['DOCUMENT_ROOT'] . '/' . $location)) {
        error("Album directory does not exist");
        return;
    }
    $thumbnailDir = $_SERVER['DOCUMENT_ROOT'] . '/' . $location . '/' . PF_THUMBNAIL_DIR;
    //try removing the thumbnails
    if (@chdir($thumbnailDir)) {
        $pattern = array("*.jpg", "*.jpeg", "*.png");
        foreach ($pattern as $pat) {
            foreach (glob($pat) as $file) {
                if (!unlink($file)) {
                    error("Could not remove thumbnail for image {$file}");
                    return;
                }
            }
        }
    }
    //try removing thumbnails directory
    @rmdir($thumbnailDir);
    //remove from config
    $cp = new ConfigWriter(PF_CONFIG_FILE);
    if (!($cp->removeWithAttributes("settings/albums/album", "name", $name) && $cp->close())) {
        error("Could not remove album {$name}");
        return;
    }
    success("Successfully removed album {$name}");
}
Ejemplo n.º 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}");
}