+ private function json_to_xml($html, $json_match_expr, $rootName) {
+ // pre-process, convert json to XML
+ $ret = preg_match($json_match_expr, $html, $matches);
+ if ($ret !== 1) {
+ trigger_error("Cannot match expression: $json_match_expr\n", E_USER_ERROR);
+ return NULL;
+ }
+
+ $data = json_decode($matches[1]);
+ if (!$data) {
+ return NULL;
+ }
+
+ $serializer_options = array (
+ 'addDecl' => TRUE,
+ 'encoding' => "UTF-8",
+ 'indent' => ' ',
+ 'rootName' => $rootName,
+ );
+
+ $serializer = new XML_Serializer($serializer_options);
+
+ $status = $serializer->serialize($data);
+ if (PEAR::isError($status)) {
+ trigger_error($status->getMessage(), E_USER_ERROR);
+ return NULL;
+ }
+
+ return $serializer->getSerializedData();
+ }
+
+ private function get_xml_instagram_com($html) {
+ return $this->json_to_xml($html, '/window._sharedData = (.*);/', 'instagram');
+ }
+
+ private function preprocess_html_facebook_com($html) {
+ $html = str_replace('<!--', '', $html);
+ $html = str_replace('-->', '', $html);
+ return $html;
+ }
+
+ private function html_to_xml($html, $host) {