apiKey = '3aaf174e570b19f41b4f52f0df9becad'; $this->cacheFileName = 'json.cache.playingNow.txt'; $this->cacheUpdateMin = 80; } public function get_data($page) { if (!file_exists($this->cacheFileName) || filemtime($this->cacheFileName) + ($this->cacheUpdateMin * 60) < time()) { $url = 'https://api.themoviedb.org/3/movie/now_playing?api_key='.$this->apiKey.'&language=es-ES&page='.$page; $curl = curl_init($url); curl_setopt($curl, CURLOPT_HTTPHEADER, array('Accept: application/json')); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); $data = curl_exec($curl); $datasearch = json_decode($data, true); curl_close($curl); file_put_contents($this->cacheFileName, $data); if (!empty($datasearch)) return $datasearch['results']; else return null; } else { $datasearch = json_decode(file_get_contents($this->cacheFileName), true); if (!empty($datasearch)) return $datasearch['results']; else return null; } } public static function slugify($text, string $divider = '-') { $text = preg_replace('~[^\pL\d]+~u', $divider, $text); $text = iconv('utf-8', 'us-ascii//TRANSLIT', $text); $text = preg_replace('~[^-\w]+~', '', $text); $text = trim($text, $divider); $text = preg_replace('~-+~', $divider, $text); $text = strtolower($text); if (empty($text)) return 'n-a'; return $text; } } ?>

Estrenos recientes