/** * @param AJXP_Node $node * @param array $shares * @param bool $clearIfEmpty */ public function getSharesFromMeta($node, &$shares, $clearIfEmpty = false) { $meta = $this->getNodeMeta($node); // NEW FORMAT if (isset($meta["shares"])) { $shares = array(); $update = false; foreach ($meta["shares"] as $hashOrRepoId => $shareData) { $type = $shareData["type"]; if (is_array($type)) { $shareData["type"] = $type[0]; } if (!$clearIfEmpty || $this->shareStore->shareExists($shareData["type"], $hashOrRepoId)) { $shares[$hashOrRepoId] = $shareData; } else { $update = true; } } if ($update && !count($shares)) { $this->clearNodeMeta($node); } return; } // OLD FORMAT if (isset($meta["minisite"])) { $type = "minisite"; } else { $type = "detect"; } $els = array(); if (is_string($meta["element"])) { $els[] = $meta["element"]; } else { if (is_array($meta["element"])) { $els = $meta["element"]; } } if ($clearIfEmpty) { $update = false; $shares = array(); foreach ($els as $hashOrRepoId => $additionalData) { if (is_string($additionalData)) { $hashOrRepoId = $additionalData; $additionalData = array(); } if ($type == "detect") { if (ConfService::getRepositoryById($hashOrRepoId) != null) { $type = "repository"; } else { $type = "file"; } } if ($this->shareStore->shareExists($type, $hashOrRepoId)) { $shares[$hashOrRepoId] = array_merge($additionalData, array("type" => $type)); } else { $update = true; } } if ($update && !count($shares)) { $this->clearNodeMeta($node); } } else { $shares = $els; } }