load->library('Feed'); $this->load->helper('file'); $this->load->helper('xml'); } public function index() { $files = get_filenames($this->rutaDiaria, true); foreach ($files as $file) { $entrada = file_get_contents($file); $xml = new SimpleXMLElement($entrada); $deletedEntrys = $xml->children('at', true); $result1 = $xml->entry->children('cac-place-ext', true); $result2 = $xml->entry->children('cac-place-ext', true)->ContractFolderStatus->children('cac-place-ext', true); $result3 = $xml->entry->children('cac-place-ext', true)->ContractFolderStatus->children('cac', true); $result4 = $xml->entry->children('cac-place-ext', true)->ContractFolderStatus->children('cbc', true); } } private function downloadProcess() { $fileName = basename(URL_DIARIA); $this->downloadFile($fileName, URL_DIARIA, $this->rutaDiaria); $archivoAtom = $this->getFile($this->rutaDiaria . $fileName); $nuevoAtomAttrNext = $this->readNextAttribute($archivoAtom); while ($nuevoAtomAttrNext !== "") { $fileName = basename($nuevoAtomAttrNext); $this->downloadFile($fileName, $nuevoAtomAttrNext, $this->rutaDiaria); $archivoAtom = $this->getFile($this->rutaDiaria . $fileName); $nuevoAtomAttrNext = $this->readNextAttribute($archivoAtom); } } private function getFile($url = URL_DIARIA) { $feed = implode(file($url)); $xml = simplexml_load_string($feed); $json = json_encode($xml); $array = json_decode($json, true); return $array; } private function readNextAttribute($archivo) { $enlace = ""; foreach ($archivo['link'] as $row) { $attrNext = $row['@attributes']['rel']; $attrHref = $row['@attributes']['href']; if ($attrNext === "next") { $enlace = $attrHref; } } return $enlace; } private function newFolder($rutaFinal) { $result = false; if (!is_dir($rutaFinal)) { $result = mkdir($rutaFinal); } return $result; } private function downloadFile($fileName, $url, $ruta) { if (file_put_contents($ruta . $fileName, file_get_contents($url))) { return true; } else { return false; } } }