You're welcome.
I've now modified the code to accept individual images.
You can identify images to be in fixed positions in one of two ways:
(1) You can use a comma-separated list of images to be in fixed positions via the $fixed array at the top of the script.
(2) You can mark images to be in fixed positions within JuiceboxBuilder-Pro by adding the following code anywhere within an image title.
<span class="fixed"></span>The script just looks for the term 'fixed' and the code added to the image title will not be visible in the gallery itself.
You can use either of these methods (or a combination of both at the same time).
<?php
header('Content-Type: application/xml');
$filename = 'config.xml';
$fixed = array(1, 2, 3, 8, 11, 12);
if (is_file($filename)) {
$dom_doc = new DOMDocument('1.0', 'UTF-8');
$dom_doc->load($filename);
$settings_tags = $dom_doc->getElementsByTagName('juiceboxgallery');
$settings_tag = $settings_tags->item(0);
if (!is_null($settings_tag)) {
$new_dom_doc = new DOMDocument('1.0', 'UTF-8');
$new_dom_doc->formatOutput = true;
$new_settings_tag = $new_dom_doc->createElement('juiceboxgallery');
$values = array();
foreach ($settings_tag->attributes as $attribute) {
$name = $attribute->nodeName;
$value = $attribute->nodeValue;
$values[$name] = $value;
}
foreach ($values as $key=>$value) {
$new_settings_tag->setAttribute($key, $value);
}
$images = $settings_tag->getElementsByTagName('image');
$marked = array();
$all = array();
for ($i = 0; $i < $images->length; $i++) {
$image = $images->item($i);
$title = $image->getElementsByTagName('title');
$text = $title->item(0);
if (!is_null($text)) {
if (stripos($text->nodeValue, 'fixed') !== false) {
$marked[] = $i + 1;
}
}
$all[] = $image;
}
$remainder = $all;
$clean = array_values(array_unique(array_merge($fixed, $marked)));
for ($i = 0; $i < count($clean); $i++) {
$key = intval($clean[$i]) - 1;
unset($remainder[$key]);
}
shuffle($remainder);
$counter = 0;
for ($i = 0; $i < count($all); $i++) {
$image = in_array($i + 1, $clean) ? $all[$i] : $remainder[$counter++];
$node = $new_dom_doc->importNode($image, true);
$new_settings_tag->appendChild($node);
}
$new_dom_doc->appendChild($new_settings_tag);
echo $new_dom_doc->saveXML();
}
}
?>