public static function updateImageCacheFor(&$blog, $entryId = false) { if (!empty($blog['entry'])) { foreach ($blog['entry'] as $eId => $e) { if ((string) $eId == '@attributes') { continue; } if (!$entryId || !empty($e['id']['value']) && $entryId == $e['id']['value']) { $mediaFiles = array(); if (!empty($e['mediafolder']['value'])) { $mediaFiles = BertaEditor::gatherMediaFilesIn($e['mediafolder']['value']); } //var_dump($mediaFiles); if ($mediaFiles) { $entryCache =& $blog['entry'][$eId]['mediaCacheData']; if (!count($entryCache) || empty($entryCache['file'])) { // if the media cache is empty, create a fresh array $mediaCacheData = array('file' => array()); if (isset($blog['entry'][$eId]['mediaCacheData'])) { $mediaCacheData = array_merge($blog['entry'][$eId]['mediaCacheData'], $mediaCacheData); } $blog['entry'][$eId]['mediaCacheData'] = $mediaCacheData; $entryCache =& $blog['entry'][$eId]['mediaCacheData']; foreach ($mediaFiles as $im) { $attr = array('type' => $im['type'], 'src' => $im['src']); if (!empty($im['poster_frame'])) { $attr['poster_frame'] = $im['poster_frame']; } if (!empty($im['width'])) { $attr['width'] = $im['width']; } if (!empty($im['height'])) { $attr['height'] = $im['height']; } $entryCache['file'][] = array('value' => '', '@attributes' => $attr); } // if moving from an older version of XML unset($entryCache['images']); unset($entryCache['videos']); //echo "\n\n-----\n\n"; var_dump($entryCache); } else { Array_XML::makeListIfNotList($entryCache['file']); //echo "\n\n-----\n\n"; var_dump($entryCache); // first check if all items in cache are still inside the folder foreach ($entryCache['file'] as $cacheIndex => $cacheIm) { // try to find the entry among the files in the folder $foundIndex = false; foreach ($mediaFiles as $i => $im) { // *** compatibility with versions <= 0.5.5b $isFromOldVersion = empty($cacheIm['@attributes']['src']); $srcFromCache = $isFromOldVersion ? $cacheIm['value'] : $cacheIm['@attributes']['src']; // if image found in cache, update cache entry if ($srcFromCache == $im['src']) { $foundIndex = true; $entry = array('@attributes' => array()); if (!$isFromOldVersion) { $entry['value'] = !empty($cacheIm['value']) ? $cacheIm['value'] : ''; } if (!empty($cacheIm['@attributes'])) { $entry['@attributes'] = $cacheIm['@attributes']; } $entry['@attributes']['src'] = $im['src']; $entry['@attributes']['type'] = $im['type']; if (!empty($im['poster_frame'])) { $entry['@attributes']['poster_frame'] = $im['poster_frame']; } if (!empty($im['width'])) { $entry['@attributes']['width'] = $im['width']; } if (!empty($im['height'])) { $entry['@attributes']['height'] = $im['height']; } $entryCache['file'][$cacheIndex] = $entry; unset($mediaFiles[$i]); break; } } // if the file was not found in the folder, delete the entry if (!$foundIndex) { unset($entryCache['file'][$cacheIndex]); } } // loop through the rest of real files and add them to cache foreach ($mediaFiles as $im) { $attr = array('type' => $im['type'], 'src' => $im['src']); if (!empty($im['poster_frame'])) { $attr['poster_frame'] = $im['poster_frame']; } if (!empty($im['width'])) { $attr['width'] = $im['width']; } if (!empty($im['height'])) { $attr['height'] = $im['height']; } $entryCache['file'][] = array('value' => '', '@attributes' => $attr); } //echo "\n\n-----\n\n"; var_dump($entryCache); // compact arrays $entryCache['file'] = array_values($entryCache['file']); // if moving from an older version of XML unset($entryCache['images']); unset($entryCache['videos']); //echo "\n\n-----\n\n"; var_dump($entryCache); } } else { $mediaCacheData = array('file' => array()); if (isset($blog['entry'][$eId]['mediaCacheData'])) { $mediaCacheData = array_merge($blog['entry'][$eId]['mediaCacheData'], $mediaCacheData); } $blog['entry'][$eId]['mediaCacheData'] = $mediaCacheData; } } } } }