/** * Gets the current theme for the album */ function getCurrentTheme($albumName) { $cp = new ConfigReader(PF_CONFIG_FILE); $albums = $cp->getChildren("settings/albums"); foreach($albums as $album) { if($album['attributes']['name'] == $albumName) { return $album['attributes']['theme']; } } }
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) { $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}"); }
<!---Albums--> <h3 id="album-header">Albums</h3> <div id="add-album-div"> <a href="" id="add-album-link">Add an Album</a> </div> <h4>Select an Album below to change its settings:</h4> <p id="no-albums-message">It seems you don't have any albums yet. Click on "Add an Album" above to add one.</p> <?php include_once "../scripts/pf_constants.php"; include_once PF_SCRIPTS_DIR . "pf_configparser.php"; $cp = new ConfigReader(PF_CONFIG_FILE); $albums = $cp->getChildren("settings/albums"); print '<ul id="album-list">'; if ($albums) { foreach ($albums as $album) { print '<li>' . $album['attributes']['name'] . '</li>'; } } print '</ul>'; ?> <h3 id="password-header">Change password</h3> <div id="password-div"> <form action="" id="password-change-form"> <div>