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}."); }
function init($args) { $pass = $args['newPassword']; $cp = new ConfigWriter(PF_CONFIG_FILE); $cp->add("settings/password", md5($pass), TRUE); if (!$cp->close()) { error("Password not changed. Configuration file could not be opened."); return; } success("Password successfully changed"); }
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}"); }
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}"); }
} //check for gd and dom xml extensions if (!extension_loaded('dom')) { error("The DOM extension is not loaded. It is needed for Pixelframe to run"); $allDone = FALSE; } if (!extension_loaded('gd')) { error("The GD extension is not loaded. It is needed for Pixelframe to run"); $allDone = FALSE; } //generate default stuff if needed if (file_exists(PF_CONFIG_FILE)) { if ($allDone) { success(GOOD_TO_GO); } } else { $conf = new ConfigWriter(PF_CONFIG_FILE); $conf->add("settings/password", md5(PF_DEFAULT_PASSWORD)); if (!$conf->close()) { error("Could not write to file " . PF_CONFIG_FILE); $allDone = FALSE; } else { if ($allDone) { success("Wrote " . PF_NAME . " settings."); success(GOOD_TO_GO); } } } ?> </div> </body>