/** * Generate the picture and ouput it. * The second request will use the pregenerated version. */ public function generate() { if (!isset($this->user) || !isset($this->type) || !isset($this->color) || !isset($this->imgGen)) { throw new Exception("Missing some informations " . "(user, type, color or image generator)."); } $db = Config::$dbInstance; $sql = "SELECT * " . "FROM lastfm_images_cache_blob " . "WHERE user = ? AND nb_artists = ? AND type = ? AND color = ? AND layout = ?"; $values = array($this->user, $this->nbArtists, $this->type, $this->color, $this->layout); $it = $db->execQueryIterator($sql, $values); if ($line = $it->getNext()) { //Already in cache $this->result = $line['image']; } else { //First request : generate picture and store it in db //Check if the maximum number of generations is reach $sql = "SELECT count(idimage) as nbgen " . "FROM lastfm_images_cache_blob " . "WHERE user = ?"; $values = array($this->user); $it = $db->execQueryIterator($sql, $values); if ($line = $it->getNext()) { if ($line['nbgen'] >= Config::NB_GENERATION_ALLOW) { Errors::showImageMessage("You have already generate " . $line['nbgen'] . " banners." . " Wait for the next update to try a different layout."); return; } } // $crawler = new CrawlerLastFM(); $artists = $crawler->getListTopArtists($this->user, $this->type); if (count($artists) > 0) { $this->imgGen->setArtists($artists); $this->imgGen->setNbArtists($this->nbArtists); $this->imgGen->setColor($this->color); ob_start(array(&$this, 'cacheImage')); $this->imgGen->show(); ob_end_flush(); } else { //An invalid/block/empty account throw new Exception("No artist found."); } } }